Shows tool rows, collapsed groups, spinner, turn duration and small hints in plain Thai; /thai toggles

One long session of building Claude Code mods on Windows 11, written up honestly: what shipped, what I tried and threw away, and why. Most mod repos only show the finished screenshot. This one also keeps the failures, because they say more about the mod API than the wins do.
Status: experimental, day one. Built on Claude Code 2.1.291 and still loading on 2.1.292. Tested on one machine: Windows 11, Windows Terminal 1.24, Cascadia Code, a cream background (
#F2F0DA), 134 columns, fullscreen mode. The mod API is new and may change under you. Issues welcome.
| Piece | Status | One-line lesson |
|---|---|---|
| fuel-bar | in daily use | The engine gives you context, auto-compact threshold and rate limits for free after every turn. No polling, no tokens. |
| thai-mode | in daily use | You can re-render tool rows, groups, spinner and turn duration. You cannot touch the prompt box. |
| task-band | new, day two | The engine tells a mod when an agent ends right away, but shell/monitor/workflow ends only reach it at the next tool call while Claude is busy. And there is no progress % for anything. |
| paste-peek | new, day three | The mod API can draw images only through the kitty protocol, which Windows Terminal lacks. A tiny native window beside the terminal does the job, and Claude Code already saves each pasted image to disk before you send. |
| Matrix intro | in daily use | A sequential intro always leaves a blank gap. Run it in parallel and stop on a file Claude writes before its first frame. |
| Safe updater | in daily use | Auto-update on Windows can leave claude.exe as a 500-byte stub. Stage, verify, then rename-and-swap. |
| Right-side pane + widgets | dropped | The dock frame belongs to the engine, and Thai text breaks in the Windows Terminal grid with every font I tried. |
| project-band above the prompt | dropped | Engine notifications render between your band and the prompt, and you cannot intercept them. |
| matrix-rain as a mod | dropped | session.start fires after the first frame. Too late for a loading screen. |
| Rounded prompt box | not possible | The prompt input is not a render site. |
| Context Router, prismantis | declined | Already built in / clashes with thai-mode and adds tokens per prompt. |

Two lines under the prompt:
T77 │ Opus 5.5 · medium │ ━━━━━━──── 53.7% 519.3k/1M │ 5h 26.0% (1h57m) · 7D 47.0% (3d) turn · model · effort · gauge to the auto-compact point (not to the raw window) · 5-hour and 7-day quota with time to reset.PROJECT · ✦ 24.2° night rain 39% · worked 4:32 hr, plus the latest mod toast on the right for 8 seconds.Why I built it: I was using ccusage statusline, and on a 1M-context model it showed context above 100% (147% on my screen). The engine already knows the right numbers.
How it works:
session.measure fires after every turn with context.tokens, context.window and rateLimits[] (five_hour, seven_day, each with percentUsed and resetsAt). session.usage({ breakdown: 'summary' }) adds autoCompactThreshold. Zero tokens, no process spawned.turn.step carries the current effort.PromptHint render site. If you return two lines, the engine keeps its own mode pill (⏵⏵ auto mode on) on the first line and indents the second by the pill's width. I tried drawing my own pill. The engine's pill stays anyway, so I gave up and kept theirs.ipwho.is for a rough location, then api.open-meteo.com. No keys, cached 30 min. This sends your IP to ipwho.is. Delete loadWeather if you don't want that.ui.toast can be intercepted (return { value: undefined }), so mod toasts land at the end of line 2 instead of popping over the transcript.dependencies: ["thai-mode"] in plugin.json lets fuel-bar read thai-mode's state and translate the hint itself. Two mods never fight over the same render site.Colors are hand-picked for a light cream background. On a dark theme you'll want to change the C palette in register.tsx.

Rewrites, with a built-in dictionary (no model calls):
ToolUse): Read → อ่านไฟล์, Bash → รันคำสั่ง, and MCP tools as service · Thai verbToolResult): "read 120 lines (40–159 of 300)", "added 4 · removed 1 lines", with the diff still drawn by the engine's Code componentToolGroup): กำลังเขียน 1 ไฟล์ · แก้ 1 ไฟล์ · รัน 1 คำสั่ง…requesting / thinking / responding / tool-input / tool-use)ctrl+b hint/thai toggles it, and the choice persists in $.store.
Things I learned:
Edit gets folded into a ToolGroup, so your nice single-row rendering mostly shows up only in ctrl+o.
A framed band above the prompt (AbovePrompt) titled "งานเบื้องหลัง" (background work). Each running subagent, Workflow, background shell and Monitor gets one chip with its own gauge, 3 per page:
What the API gives you (build 2.1.292):
agent.spawn answers with an agentId. Its end is turn.complete carrying that agentId, and it arrives immediately. Workflow agents come through agent.spawn too, with e.workflow.runId.backgroundTaskId. Monitor and Workflow results carry taskId (Workflow also runId and workflowName).prompt.submit with origin.kind === 'task-notification', with <task-id> and <status> in the text. When Claude is idle that is instant. While a turn runs it waits for the next tool-call boundary (I measured 4.3 s late).await next(e).Things that bit me:
Box takes borderStyle but has no border title. Laying a position: "absolute" title over the border line shifted the whole screen sideways and left it garbled until a resize forced a full redraw. The frame is now three plain Text rows sized to bodyColumns (the engine draws [-] at the far right of the band).
Windows only. Experimental, day one. Claude Code shows a pasted image as [Image #1] and nothing else, so you can't tell whether you attached the right screenshot until Claude answers. paste-peek opens a small strip in the bottom-right corner of your Windows Terminal window with a thumbnail of every [Image #N] in your draft:
[Image #2] from the draft and #2 leaves the strip. Send the message and the strip closes.Alt+V pastes and for files dragged onto the terminal.Why a separate window: the mod API has an Image element, but the engine draws it only through the kitty graphics protocol, which Windows Terminal doesn't speak, so you just get the alt text. I also tried a Raster of half-block characters (▀, two pixels per cell). It works everywhere, but a 6-row thumbnail is about 21×12 pixels, which is too blurry to tell screenshots apart.
How it works:
$.prompt.read()) every 250 ms and writes the list of [Image #N] numbers to a small state file in %TEMP%.peek.exe (C#, WinForms, about 475 lines in native/peek.cs). The exe watches the state file with a FileSystemWatcher and closes itself when the file goes empty, which the mod does on submit.%TEMP%\claude\<project-slug>\<session-id>\images\<N>.<ext> as soon as you paste or drop it, before you send. This is undocumented and may change in a future version. Claude Code skips this when transcript saving is off (for example a session started from inside another Claude session, which shows a "Transcript saving is off" notice), and the strip then says "no preview". My first build read the clipboard instead, and a dragged file then showed whatever image was last copied.EVENT_SYSTEM_FOREGROUND and location changes. No polling.Measured on my laptop: about 24 MB private memory and 0% CPU while the strip is open, nothing at all while there are no images, and the strip appears in about 0.2 s.
No binary in this repo. On first use the mod compiles native/peek.cs with the C# compiler that ships with Windows (%WINDIR%\Microsoft.NET\Framework64\v4.0.30319\csc.exe, .NET Framework 4.x) into %LOCALAPPDATA%\paste-peek\. That takes about a second, once.
Options (/config): label language (en / th), theme (dark / light), and the distance from the window's bottom and right edges. The default bottom distance clears a two-line footer. Raise it if the strip covers your prompt.
Tested end to end in a fresh session: first-use compile, dark theme, English labels, a pasted image showing in the strip. Not handled yet: more than one terminal tab in the same window (the strip follows the window, not the tab), and terminals other than Windows Terminal.

Katakana rain in ink-on-cream with the folder name decoding in the middle, shown while Claude Code loads (about 4.7 s on this laptop). It is not a mod. It is a tiny C# exe started by the launcher.
The path there was three failures:
claude. However long the intro runs, you still get a blank or log-only screen between the intro ending and Claude's first frame.session.start fires after Claude has drawn its first screen. The rain lands on top of Claude, and in fullscreen mode Ctrl+L does not clear it.What works:
claude-launcher.cmd does start "" /b matrix-intro.exe and then call claude at the same moment. The rain shows within ~0.7 s.numStartups in <CLAUDE_CONFIG_DIR>\.claude.json every 120 ms. Claude bumps it 0.4–0.7 s before drawing its first frame, which is the "ready" signal. Hard cap: 20 s.cls, but only if the intro actually ran (it drops a marker file).-p, --version, --help and subcommands. CLAUDE_MATRIX_INTRO=0 disables it.Batch trap: claude installed by npm is claude.cmd. If you write claude %* instead of call claude %* in a .cmd, nothing after that line ever runs.
Half-width katakana take exactly one cell in Windows Terminal with Cascadia Code, so the columns line up.
Build it with the C# compiler that ships with Windows:
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe /nologo /optimize+ /codepage:65001 windows\matrix-intro.cs
On this machine, Claude Code's own auto-update repeatedly left node_modules\@anthropic-ai\claude-code\bin\claude.exe as a ~500-byte stub ("This version of claude.exe is not compatible…"), or failed with "claude.exe in use" while another session was open. Its warning also showed up in the middle of the screen:

windows/claude-update-safe.ps1:
npm view @anthropic-ai/claude-code version.--version.claude.exe.old-<timestamp> (Windows allows renaming a running exe, not overwriting it), then moves the new one in. Open sessions keep running the old file. New sessions get the new one..old-* files on the next run, and logs to %LOCALAPPDATA%\claude-update-safe\claude-update.log.Set "env": { "DISABLE_AUTOUPDATER": "1" } in settings.json so the built-in updater stops fighting it. matrix-intro.exe launches the script hidden at every start if it sits in the same folder.
This only applies to the global npm install. The native installer manages its own versioned folders.
Right-side pane with widgets (project name, a 3-tab reminder list, weather, other open sessions). Inspired by paneline and flightdeck. It worked technically (Pane render site with fullscreen: true), but:
เ ปิด). I tried Noto Sans Thai, Leelawadee, Tahoma, Tlwg Mono and Tlwg Typo. None fixed it. This is a WT grid limit, not a font problem.viewport.columns in PromptHint is the transcript width, not the full window./pane.project-band above the prompt (AbovePrompt, one line: project · weather · time worked). It looked good until Claude Code showed its own notice (Auto-update failed …). Engine notices render between AbovePrompt and the prompt, and they are standing warnings, not ui.toast, so a mod can't catch them. I merged the band into fuel-bar's second line instead.
matrix-rain as a mod. See the intro section: session.start is too late.
Rounded prompt box. I mocked it in a browser first. That was a mistake, because the prompt input is not one of the render sites, so a mod can't change it. A custom theme can recolor the border (promptBorder) but not reshape it.
CLAUDE.md from parent folders, and @path imports work.ToolUse, ToolGroup and TurnDuration (the same sites as thai-mode), and its diagramHints adds about 190 tokens to every prompt.The HUD in one popular mod's demo video (LIFE / LEVEL / XP bars across the top) is rendered with Revideo in its demo/ folder. The README says as much: "Nothing in it is captured". It isn't something the mod draws in your terminal. Before you promise someone a feature you saw in a GIF, grep the mod's hooks/ folder.
Mockups in a browser lie about fonts, colors and cell widths. What I used instead:
wt -w new <file.cmd>. Start-Process with arguments quotes the whole command line and fails with 0x80070002.CASCADIA_HOSTING_WINDOW_CLASS. Capture it with PrintWindow(hwnd, dc, 2) after SetProcessDPIAware(). That works even when the window is behind another one. CopyFromScreen only sees what's visible.SendInput + KEYEVENTF_UNICODE. SendKeys follows the active keyboard layout: with Thai active, /exit arrives as /59.claude plugin marketplace add <path-to-clone>\mods
claude plugin install fuel-bar@field-notes-mods --scope user
claude plugin install thai-mode@field-notes-mods --scope user
claude plugin install task-band@field-notes-mods --scope user
claude plugin install paste-peek@field-notes-mods --scope user
Plugins are read from that folder in place: edit a file, then run /reload-plugins. claude plugin test <folder> runs the tests (fuel-bar 7, thai-mode 5, task-band 13, paste-peek 4).
For the intro: compile windows/matrix-intro.cs, then put matrix-intro.exe, claude-update-safe.ps1 and claude-launcher.cmd in one folder on your PATH.
บันทึกการทำ mod ให้ Claude Code บน Windows ในหนึ่งวัน ทั้งชิ้นที่ใช้จริงและชิ้นที่ลองแล้วทิ้ง
/thai ใช้สลับเปิด/ปิด[Image #N] ที่วางหรือลากมาไว้ในข้อความ ก่อนกดส่ง คลิกเพื่อขยาย ลบ [Image #N] แล้วรูปหายจากกรอบ กดส่งแล้วกรอบปิดเอง ซ่อนเมื่อสลับไปหน้าต่างอื่น ใช้ RAM ประมาณ 24 MB เฉพาะตอนมีรูปแนบ ไม่แนบไฟล์ exe ไว้ใน repo แต่จะคอมไพล์จากโค้ดต้นฉบับตอนใช้ครั้งแรกnumStartups เพิ่ม ถ้ารันเรียงกันจะมีจอว่างเสมอclaude.exe เหลือไฟล์ 500 ไบต์ ใช้วิธีติดตั้งแยกไว้ก่อน ตรวจว่าใช้ได้ แล้วค่อยเปลี่ยนชื่อสลับไฟล์session.start มาช้ากว่าจอแรกถ้าใช้ Windows Terminal กับภาษาไทย ให้เตรียมใจไว้ว่าสระบนและวรรณยุกต์จะกินช่องของตัวเอง ฟอนต์แก้ไม่ได้
MIT
hooks/register.tsx 109 lines1import { atom, read, update } from 'claude-code'
2import type { EngineInterface, Register } from 'claude-code'
3
4import { groupLine, resultView, SPINNER_WORD, thaiDuration, thaiProgressHint, toolRow } from './thai'
5
6const enabled = atom({ plugin: 'thai-mode', key: 'enabled' } as const, true)
7
8const C = {
9 text: '#2d2a24',
10 dim: '#6b675e',
11 green: '#3f8a3a',
12 red: '#b8322b',
13 running: '#a8a497',
14}
15
16let cwd: string | undefined
17
18async function isOn($: EngineInterface): Promise<boolean> {
19 return read($, enabled)
20}
21
22export const register: Register = on => {
23 on('session.start', async ($, e, next) => {
24 const result = await next(e)
25 await $.command.register({ name: 'thai', description: 'thai-mode: สลับเปิด/ปิดการแสดงผลภาษาไทย' })
26 cwd = await $.session.cwd()
27 const stored = await $.store.get('enabled')
28 if (typeof stored === 'boolean') await update($, enabled, () => stored)
29 return result
30 })
31
32 on('command.run', { command: 'thai' }, async $ => {
33 const now = !(await read($, enabled))
34 await update($, enabled, () => now)
35 await $.store.set('enabled', now)
36 return { text: now ? 'Thai Mode: เปิด' : 'Thai Mode: ปิด (กลับเป็นภาษาอังกฤษ)' }
37 })
38
39 on('ui.render', { component: 'ToolUse' }, async ($, e, next) => {
40 if (!(await isOn($))) return next(e)
41 const row = toolRow(e.props.tool, e.props.input, cwd)
42 if (!row) return next(e)
43 const dot = e.props.isRunning ? C.running : e.props.isErrored || e.props.isInterrupted ? C.red : C.green
44 const { Box, Text } = $.ui.resolve(e)
45 return (
46 <Box flexDirection="row">
47 <Text color={dot}>● </Text>
48 <Text color={C.text}>
49 {row.label}
50 </Text>
51 {row.arg ? <Text color={C.text}> {row.arg}</Text> : null}
52 {e.props.isInterrupted ? <Text color={C.dim}> · ถูกหยุด</Text> : null}
53 </Box>
54 )
55 })
56
57 on('ui.render', { component: 'ToolResult' }, async ($, e, next) => {
58 if (e.props.isErrored || !(await isOn($))) return next(e)
59 const view = resultView(e.props.tool, e.props.output)
60 if (!view) return next(e)
61 const { Box, Text, Code } = $.ui.resolve(e)
62 return (
63 <Box flexDirection="column">
64 <Text color={C.dim}> ⎿ {view.summary}</Text>
65 {view.diff ? (
66 <Box paddingLeft={5}>
67 <Code source={view.diff} format="diff" path={view.path} />
68 </Box>
69 ) : null}
70 </Box>
71 )
72 })
73
74 on('ui.render', { component: 'ToolGroup' }, async ($, e, next) => {
75 if (e.props.isExpanded || !(await isOn($))) return next(e)
76 const calls = e.props.calls
77 const dot = calls.some(c => c.isErrored) ? C.red : e.props.isActive ? C.running : C.green
78 const { Box, Text } = $.ui.resolve(e)
79 return (
80 <Box flexDirection="row">
81 <Text color={dot}>● </Text>
82 <Text color={C.text}>{groupLine(calls, e.props.isActive)}</Text>
83 <Text color={C.dim}> (ctrl+o ดูทั้งหมด)</Text>
84 </Box>
85 )
86 })
87
88 on('ui.render', { component: 'Spinner' }, async ($, e, next) => {
89 if (!(await isOn($))) return next(e)
90 const word = SPINNER_WORD[e.props.mode]
91 return word ? next({ ...e, props: { ...e.props, word } }) : next(e)
92 })
93
94 on('ui.render', { component: 'TurnDuration' }, async ($, e, next) => {
95 if (!(await isOn($))) return next(e)
96 const { Box, Text } = $.ui.resolve(e)
97 return (
98 <Box marginTop={1}>
99 <Text color={C.dim}>✻ เสร็จใน {thaiDuration(e.props.durationMs)}</Text>
100 </Box>
101 )
102 })
103
104 on('ui.render', { component: 'ToolProgress' }, async ($, e, next) => {
105 if (!(await isOn($))) return next(e)
106 return next({ ...e, props: { ...e.props, hint: thaiProgressHint(e.props.hint) } })
107 })
108}
109hooks/thai.ts 301 lines1export type Row = { label: string; arg: string }
2
3const MCP_SERVICE: Record<string, string> = {
4 github: 'GitHub',
5 'chrome-devtools': 'Chrome',
6 'claude-in-chrome': 'Chrome',
7 gmail: 'Gmail',
8 claude_ai_gmail: 'Gmail',
9 'google-calendar': 'Calendar',
10 stripe: 'Stripe',
11 memory: 'Memory',
12 sentry: 'Sentry',
13 claude_ai_claude_docs: 'Claude Docs',
14 'cloudflare-docs': 'Cloudflare Docs',
15 'connect-apps': 'Connect Apps',
16 shadcn: 'shadcn',
17 time: 'Time',
18 'sequential-thinking': 'Thinking',
19 a11y: 'A11y',
20}
21
22const VERB: Record<string, string> = {
23 search: 'ค้นหา',
24 list: 'ดูรายการ',
25 get: 'ดู',
26 read: 'อ่าน',
27 fetch: 'ดึง',
28 create: 'สร้าง',
29 add: 'เพิ่ม',
30 update: 'แก้',
31 edit: 'แก้',
32 modify: 'แก้',
33 delete: 'ลบ',
34 remove: 'ลบ',
35 trash: 'ทิ้ง',
36 take: 'ถ่าย',
37 navigate: 'เปิดหน้า',
38 open: 'เปิด',
39 close: 'ปิด',
40 click: 'คลิก',
41 fill: 'กรอก',
42 type: 'พิมพ์',
43 press: 'กด',
44 hover: 'ชี้',
45 drag: 'ลาก',
46 select: 'เลือก',
47 send: 'ส่ง',
48 reply: 'ตอบ',
49 forward: 'ส่งต่อ',
50 query: 'ค้นข้อมูล',
51 execute: 'รัน',
52 run: 'รัน',
53 write: 'เขียน',
54 push: 'push',
55 merge: 'merge',
56 upload: 'อัปโหลด',
57 download: 'ดาวน์โหลด',
58 evaluate: 'รันสคริปต์',
59 resize: 'ปรับขนาด',
60 emulate: 'จำลอง',
61 wait: 'รอ',
62 mark: 'ทำเครื่องหมาย',
63 label: 'ติดป้าย',
64 save: 'บันทึก',
65 set: 'ตั้งค่า',
66 authenticate: 'เข้าสู่ระบบ',
67 respond: 'ตอบรับ',
68 analyze: 'วิเคราะห์',
69 lighthouse: 'ตรวจ Lighthouse',
70 performance: 'วัดความเร็ว',
71}
72
73const ARTIFACT_ACTION: Record<string, string> = {
74 publish: 'เผยแพร่หน้าเว็บ',
75 read: 'อ่านหน้าเว็บ',
76 list: 'ดูรายการหน้าเว็บ',
77 delete: 'ลบหน้าเว็บ',
78 open: 'เปิดหน้าเว็บ',
79 quickstart: 'เตรียมสร้างหน้าเว็บ',
80 pin: 'ปักหมุดหน้าเว็บ',
81 unpin: 'เลิกปักหมุดหน้าเว็บ',
82}
83
84const str = (v: unknown): string => (typeof v === 'string' ? v : '')
85const obj = (v: unknown): Record<string, unknown> => (v && typeof v === 'object' ? (v as Record<string, unknown>) : {})
86
87export function firstLine(s: string, max = 80): string {
88 const line = (s.split(/\r?\n/)[0] ?? '').trim()
89 const more = s.includes('\n') ? ' …' : ''
90 return line.length > max ? `${line.slice(0, max - 1)}…` : line + more
91}
92
93export function shortPath(p: string, cwd?: string): string {
94 let s = p.replace(/\\/g, '/')
95 if (cwd) {
96 const c = cwd.replace(/\\/g, '/').replace(/\/$/, '')
97 if (s.toLowerCase().startsWith(`${c.toLowerCase()}/`)) s = s.slice(c.length + 1)
98 }
99 const parts = s.split('/')
100 return parts.length > 4 ? `…/${parts.slice(-3).join('/')}` : s
101}
102
103export function mcpRow(tool: string, input: unknown): Row | undefined {
104 const m = tool.match(/^mcp__(.+?)__(.+)$/)
105 if (!m || !m[1] || !m[2]) return undefined
106 const key = m[1].toLowerCase()
107 const service = MCP_SERVICE[key] ?? m[1].replace(/^claude_ai_/i, '').replace(/[_-]+/g, ' ')
108 const words = m[2].split(/[_-]+/).filter(Boolean)
109 const verb = words[0] ? VERB[words[0].toLowerCase()] : undefined
110 const rest = words.slice(1).join(' ')
111 const action = verb ? `${verb}${rest ? ` ${rest}` : ''}` : words.join(' ')
112 const i = obj(input)
113 const hint = str(i.query) || str(i.url) || str(i.q) || str(i.name) || ''
114 return { label: `${service} · ${action}`, arg: hint ? `"${firstLine(hint, 50)}"` : '' }
115}
116
117export function toolRow(tool: string, input: unknown, cwd?: string): Row | undefined {
118 const i = obj(input)
119 const path = (k = 'file_path') => shortPath(str(i[k]), cwd)
120 switch (tool) {
121 case 'Read':
122 return { label: 'อ่านไฟล์', arg: path() }
123 case 'Write':
124 return { label: 'เขียนไฟล์', arg: path() }
125 case 'Edit':
126 return { label: 'แก้ไฟล์', arg: path() }
127 case 'NotebookEdit':
128 return { label: 'แก้ notebook', arg: path('notebook_path') }
129 case 'Grep': {
130 const where = str(i.path) ? ` ใน ${shortPath(str(i.path), cwd)}` : ''
131 return { label: 'ค้นหาคำ', arg: `"${firstLine(str(i.pattern), 50)}"${where}` }
132 }
133 case 'Glob':
134 return { label: 'หาไฟล์', arg: `${str(i.pattern)}${str(i.path) ? ` ใน ${shortPath(str(i.path), cwd)}` : ''}` }
135 case 'Bash':
136 case 'PowerShell':
137 return { label: 'รันคำสั่ง', arg: firstLine(str(i.command)) }
138 case 'WebSearch':
139 return { label: 'ค้นเว็บ', arg: `"${firstLine(str(i.query), 60)}"` }
140 case 'WebFetch':
141 return { label: 'เปิดเว็บ', arg: firstLine(str(i.url), 70) }
142 case 'Agent':
143 case 'Task':
144 return { label: 'ส่งผู้ช่วยไปทำ', arg: firstLine(str(i.description), 60) }
145 case 'Skill':
146 return { label: 'ใช้สกิล', arg: str(i.skill) }
147 case 'ToolSearch':
148 return { label: 'โหลดเครื่องมือ', arg: firstLine(str(i.query), 60) }
149 case 'TodoWrite':
150 return { label: 'อัปเดตรายการงาน', arg: '' }
151 case 'AskUserQuestion':
152 return { label: 'ถามคุณ', arg: '' }
153 case 'ScheduleWakeup':
154 return { label: 'ตั้งเวลาปลุก', arg: '' }
155 case 'Monitor':
156 return { label: 'เฝ้าดู', arg: firstLine(str(i.command) || str(i.description), 60) }
157 case 'SendUserFile':
158 return { label: 'ส่งไฟล์ให้คุณ', arg: '' }
159 case 'Artifact': {
160 const action = str(i.action) || 'publish'
161 return { label: ARTIFACT_ACTION[action] ?? `Artifact · ${action}`, arg: str(i.file_path) ? shortPath(str(i.file_path), cwd) : '' }
162 }
163 default:
164 return mcpRow(tool, input)
165 }
166}
167
168export function thaiDuration(ms: number): string {
169 const total = Math.max(0, Math.round(ms / 1000))
170 const h = Math.floor(total / 3600)
171 const m = Math.floor((total % 3600) / 60)
172 const s = total % 60
173 if (h > 0) return m > 0 ? `${h} ชั่วโมง ${m} นาที` : `${h} ชั่วโมง`
174 if (m > 0) return s > 0 ? `${m} นาที ${s} วินาที` : `${m} นาที`
175 return `${s} วินาที`
176}
177
178const shortDuration = (ms: number) => {
179 const s = Math.round(ms / 1000)
180 return s >= 60 ? `${Math.floor(s / 60)} นาที ${s % 60} วิ` : `${s} วิ`
181}
182
183const kTokens = (n: number) => (n >= 1000 ? `${(n / 1000).toFixed(1)}k` : `${n}`)
184
185export function patchSource(patches: unknown): { source: string; added: number; removed: number } {
186 let added = 0
187 let removed = 0
188 const hunks: string[] = []
189 for (const p of Array.isArray(patches) ? patches : []) {
190 const h = obj(p)
191 const lines = Array.isArray(h.lines) ? (h.lines as unknown[]).map(String) : []
192 for (const l of lines) {
193 if (l.startsWith('+')) added++
194 else if (l.startsWith('-')) removed++
195 }
196 hunks.push(`@@ -${h.oldStart},${h.oldLines} +${h.newStart},${h.newLines} @@`, ...lines)
197 }
198 return { source: hunks.join('\n'), added, removed }
199}
200
201export type ResultView = { summary: string; diff?: string; path?: string }
202
203export function resultView(tool: string, output: unknown): ResultView | undefined {
204 const o = obj(output)
205 switch (tool) {
206 case 'Read': {
207 if (o.type === 'image') return { summary: 'อ่านรูปภาพ' }
208 const f = obj(o.file)
209 const n = Number(f.numLines ?? 0)
210 const total = Number(f.totalLines ?? n)
211 const start = Number(f.startLine ?? 1)
212 if (o.type !== 'text') return undefined
213 return { summary: n < total ? `อ่าน ${n} บรรทัด (บรรทัด ${start}–${start + n - 1} จาก ${total})` : `อ่าน ${n} บรรทัด` }
214 }
215 case 'Grep': {
216 const files = Number(o.numFiles ?? 0)
217 if (o.mode === 'content') {
218 const lines = Number(o.numLines ?? 0)
219 return { summary: lines ? `เจอ ${lines} บรรทัด` : 'ไม่เจอ' }
220 }
221 if (o.mode === 'count') return { summary: `เจอ ${Number(o.numMatches ?? 0)} จุด ใน ${files} ไฟล์` }
222 return { summary: files ? `เจอใน ${files} ไฟล์` : 'ไม่เจอ' }
223 }
224 case 'Glob': {
225 const n = Number(o.numFiles ?? 0)
226 return { summary: n ? `เจอ ${n} ไฟล์${o.truncated ? ' (แสดงไม่หมด)' : ''}` : 'ไม่เจอไฟล์' }
227 }
228 case 'Write': {
229 if (o.type === 'create') {
230 const body = str(o.content).replace(/\r?\n$/, '')
231 const n = body ? body.split(/\r?\n/).length : 0
232 return { summary: `สร้างไฟล์ใหม่ ${n} บรรทัด` }
233 }
234 const d = patchSource(o.structuredPatch)
235 return { summary: `เขียนทับ · เพิ่ม ${d.added} · ลบ ${d.removed} บรรทัด`, diff: d.source || undefined, path: str(o.filePath) }
236 }
237 case 'Edit': {
238 const d = patchSource(o.structuredPatch)
239 return { summary: `เพิ่ม ${d.added} · ลบ ${d.removed} บรรทัด`, diff: d.source || undefined, path: str(o.filePath) }
240 }
241 case 'WebSearch': {
242 const n = Number(o.searchCount ?? 1)
243 const sec = Math.round(Number(o.durationSeconds ?? 0))
244 return { summary: `ค้น ${n} ครั้ง ใช้เวลา ${sec} วิ` }
245 }
246 case 'WebFetch': {
247 const kb = Math.max(1, Math.round(Number(o.bytes ?? 0) / 1024))
248 return { summary: `ได้ข้อมูล ${kb} KB (${o.code ?? '?'} ${str(o.codeText)})`.trim() }
249 }
250 case 'Agent':
251 case 'Task': {
252 if (o.totalToolUseCount === undefined) return undefined
253 return {
254 summary: `เสร็จ (ใช้เครื่องมือ ${o.totalToolUseCount} ครั้ง · ${kTokens(Number(o.totalTokens ?? 0))} token · ${shortDuration(Number(o.totalDurationMs ?? 0))})`,
255 }
256 }
257 default:
258 return undefined
259 }
260}
261
262const GROUP_NOUN: Record<string, [string, string]> = {
263 Read: ['อ่าน', 'ไฟล์'],
264 Grep: ['ค้นหา', 'คำ'],
265 Glob: ['หาไฟล์', 'ครั้ง'],
266 Bash: ['รัน', 'คำสั่ง'],
267 PowerShell: ['รัน', 'คำสั่ง'],
268 WebSearch: ['ค้นเว็บ', 'ครั้ง'],
269 WebFetch: ['เปิดเว็บ', 'หน้า'],
270 Edit: ['แก้', 'ไฟล์'],
271 Write: ['เขียน', 'ไฟล์'],
272}
273
274export function groupLine(calls: ReadonlyArray<{ tool: string }>, isActive: boolean): string {
275 const counts = new Map<string, number>()
276 for (const c of calls) {
277 const noun = GROUP_NOUN[c.tool]
278 const r = noun ? undefined : mcpRow(c.tool, {})
279 const key = noun ? `${noun[0]}|${noun[1]}` : `${r ? r.label : c.tool}|ครั้ง`
280 counts.set(key, (counts.get(key) ?? 0) + 1)
281 }
282 const parts = [...counts].map(([key, n]) => {
283 const [verb, unit] = key.split('|')
284 return `${verb} ${n} ${unit}`
285 })
286 const text = parts.join(' · ')
287 return isActive ? `กำลัง${text}…` : text
288}
289
290export const SPINNER_WORD: Record<string, string> = {
291 requesting: 'กำลังส่งคำขอ',
292 thinking: 'กำลังคิด',
293 responding: 'กำลังตอบ',
294 'tool-input': 'กำลังเตรียมคำสั่ง',
295 'tool-use': 'กำลังใช้เครื่องมือ',
296}
297
298export function thaiProgressHint(hint: string): string {
299 return hint.replace(/to run in background/i, 'ให้ทำเบื้องหลัง')
300}
301types/index.d.ts 8 lines1export type ThaiModeEnabled = boolean
2
3declare module 'claude-code' {
4 interface PluginState {
5 'thai-mode': { enabled: ThaiModeEnabled }
6 }
7}
8