@causyne/agent 1.20.54 → 1.20.60

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,222 @@
1
+ // The line that tells the user what is happening to their money and their time.
2
+ //
3
+ // While a turn ran, the chat printed one thing:
4
+ //
5
+ // ⠋ Thinking…
6
+ //
7
+ // and that was the entire signal for what could be a four-minute, forty-step,
8
+ // several-dollar run. The user could not see elapsed time, which model was
9
+ // spending, how many steps had gone by, how many tokens the turn had burned, or
10
+ // what was left. All of those numbers were already in memory — the loop broadcasts
11
+ // `usage_update` on every response and the config carries the model — and none of
12
+ // it was shown.
13
+ //
14
+ // The line degrades by DROPPING SEGMENTS, right to left, until it fits. A narrow
15
+ // terminal loses the cost before it loses the elapsed time, and loses the
16
+ // elapsed time before it loses the message. It never wraps, because a wrapping
17
+ // spinner leaves debris every tick.
18
+ //
19
+ // Pure TypeScript over ./theme.js and ./text.js. No dependency, no shell.
20
+
21
+ // @ts-expect-error theme.js has no TypeScript declaration yet.
22
+ import { paint, dim, GLYPHS } from './theme.js';
23
+ import { truncate, visibleWidth, safeDisplay, shortenHome } from './text.js';
24
+ import { contextMeter } from './block.js';
25
+ import { CHARS_PER_TOKEN } from '../contextManager.js';
26
+
27
+ /** 1234 -> "1.2k", 1234567 -> "1.2M". Token counts are read, not summed. */
28
+ export function compactCount(value: unknown): string {
29
+ const n = Number(value) || 0;
30
+ if (n < 1000) return String(Math.round(n));
31
+ if (n < 1000000) return `${(n / 1000).toFixed(n < 10000 ? 1 : 0)}k`;
32
+ return `${(n / 1000000).toFixed(1)}M`;
33
+ }
34
+
35
+ /**
36
+ * Money, at the precision the number deserves.
37
+ *
38
+ * Sub-cent runs printed as "$0.00" read as free, which is how a user learns not
39
+ * to look at the cost at all.
40
+ */
41
+ export function formatCost(value: unknown): string {
42
+ const n = Number(value) || 0;
43
+ if (n <= 0) return '$0';
44
+ if (n < 0.01) return `$${n.toFixed(4)}`;
45
+ if (n < 1) return `$${n.toFixed(3)}`;
46
+ return `$${n.toFixed(2)}`;
47
+ }
48
+
49
+ export function formatElapsed(ms: number): string {
50
+ const total = Math.max(0, Math.round(ms / 1000));
51
+ if (total < 60) return `${(ms / 1000).toFixed(1)}s`;
52
+ const minutes = Math.floor(total / 60);
53
+ const seconds = total % 60;
54
+ if (minutes < 60) return `${minutes}m${String(seconds).padStart(2, '0')}s`;
55
+ return `${Math.floor(minutes / 60)}h${String(minutes % 60).padStart(2, '0')}m`;
56
+ }
57
+
58
+ /** Strip a provider prefix so "anthropic/claude-opus-5" reads as the model. */
59
+ function shortModel(model: unknown): string {
60
+ const name = String(model || '').split('/').pop() || '';
61
+ return name.length > 22 ? name.slice(0, 21) + GLYPHS.ellipsis : name;
62
+ }
63
+
64
+ export interface StatusLineSessionInfo {
65
+ model?: string | undefined;
66
+ provider?: string | undefined;
67
+ tier?: string | undefined;
68
+ cwd?: string | undefined;
69
+ contextLimit?: number | string | undefined;
70
+ contextChars?: number | string | undefined;
71
+ }
72
+
73
+ export interface StatusLineRenderOptions {
74
+ message?: string | undefined;
75
+ elapsedMs?: number | undefined;
76
+ steps?: number | undefined;
77
+ width?: number | undefined;
78
+ spinnerFrame?: string | undefined;
79
+ }
80
+
81
+ export interface StatusLineIdleOptions {
82
+ width?: number | undefined;
83
+ hint?: string | undefined;
84
+ }
85
+
86
+ export class StatusLine {
87
+ model = '';
88
+ provider = '';
89
+ tier = '';
90
+ cwd = '';
91
+ // Both in CHARACTERS — the unit the window is actually budgeted in.
92
+ contextLimit = 0;
93
+ contextChars = 0;
94
+
95
+ turnTokens = 0;
96
+ turnCost = 0;
97
+ cachedTokens = 0;
98
+
99
+ constructor() {
100
+ this.reset();
101
+ }
102
+
103
+ /** Session-lifetime facts, set once from the same info as the header. */
104
+ setSession(info: StatusLineSessionInfo = {}): this {
105
+ if (info.model !== undefined) this.model = shortModel(info.model);
106
+ if (info.provider !== undefined) this.provider = info.provider ? String(info.provider) : '';
107
+ if (info.tier !== undefined) this.tier = info.tier ? String(info.tier) : '';
108
+ if (info.cwd !== undefined) this.cwd = info.cwd ? String(info.cwd) : '';
109
+ if (Number(info.contextLimit) > 0) this.contextLimit = Number(info.contextLimit);
110
+ if (Number(info.contextChars) > 0) this.contextChars = Number(info.contextChars);
111
+ return this;
112
+ }
113
+
114
+ /** Per-turn counters. */
115
+ reset(): this {
116
+ this.turnTokens = 0;
117
+ this.turnCost = 0;
118
+ this.cachedTokens = 0;
119
+ // Note: Do NOT reset this.contextChars to 0 here. Context window usage
120
+ // belongs to the whole conversation, not just a single active turn.
121
+ return this;
122
+ }
123
+
124
+ /**
125
+ * The idle footer: where you are, and how much context is left.
126
+ */
127
+ renderIdle({ width = 80, hint = '' }: StatusLineIdleOptions = {}): string {
128
+ const budget = Math.max(10, width - 1);
129
+ const meter = contextMeter(
130
+ Math.round(this.contextChars / CHARS_PER_TOKEN),
131
+ Math.round(this.contextLimit / CHARS_PER_TOKEN)
132
+ );
133
+ const segments: string[] = [];
134
+ if (meter) segments.push(meter);
135
+ if (hint) segments.push(hint);
136
+
137
+ const separator = ` ${GLYPHS.dot} `;
138
+ const kept = segments.slice();
139
+ let tail = kept.join(separator);
140
+ while (kept.length > 1 && visibleWidth(tail) > Math.floor(budget / 2)) {
141
+ kept.pop();
142
+ tail = kept.join(separator);
143
+ }
144
+ if (visibleWidth(tail) > budget) tail = '';
145
+
146
+ const room = tail ? Math.max(0, budget - visibleWidth(tail) - visibleWidth(separator)) : budget;
147
+ const where = this.cwd ? truncate(shortenHome(this.cwd), room, GLYPHS.ellipsis) : '';
148
+ const left = dim(where);
149
+ if (!tail) return left;
150
+
151
+ const gap = Math.max(
152
+ visibleWidth(separator),
153
+ width - 1 - visibleWidth(left) - visibleWidth(tail)
154
+ );
155
+ return `${left}${' '.repeat(gap)}${dim(tail)}`;
156
+ }
157
+
158
+ /**
159
+ * Consume a `usage_update` frame.
160
+ */
161
+ onUsage(msg: Record<string, unknown> = {}): this {
162
+ this.turnTokens = Number(msg.taskTokens) || Number(msg.usedTokens) || this.turnTokens;
163
+ if (Number(msg.contextChars) > 0) this.contextChars = Number(msg.contextChars);
164
+ if (Number(msg.contextLimitChars) > 0) this.contextLimit = Number(msg.contextLimitChars);
165
+ const responseCost = Number(msg.costUsd) || 0;
166
+ const taskCost = Number(msg.taskCostUsd) || 0;
167
+ this.turnCost = taskCost > 0 ? taskCost : this.turnCost + responseCost;
168
+ this.cachedTokens = Number(msg.cachedTokens) || 0;
169
+ return this;
170
+ }
171
+
172
+ /**
173
+ * Build the line.
174
+ */
175
+ render({ message = '', elapsedMs = 0, steps = 0, width = 80, spinnerFrame = '' }: StatusLineRenderOptions = {}): string {
176
+ const head = spinnerFrame ? `${paint('accent', spinnerFrame)} ` : '';
177
+ const budget = Math.max(10, width - visibleWidth(head) - 1);
178
+
179
+ const segments: string[] = [];
180
+ if (elapsedMs > 0) segments.push(formatElapsed(elapsedMs));
181
+ if (steps > 0) segments.push(`step ${steps}`);
182
+ if (this.turnTokens > 0) segments.push(`${compactCount(this.turnTokens)} tok`);
183
+ if (this.turnCost > 0) segments.push(formatCost(this.turnCost));
184
+ if (this.cachedTokens > 0) segments.push(`${compactCount(this.cachedTokens)} cached`);
185
+ if (this.model) segments.push(this.model);
186
+
187
+ const separator = ` ${GLYPHS.dot} `;
188
+ const text = safeDisplay(message);
189
+
190
+ const kept = segments.slice();
191
+ const wanted = Math.min(visibleWidth(text), Math.max(18, Math.floor(budget / 2)));
192
+ while (kept.length > 0) {
193
+ const tail = kept.join(separator);
194
+ if (visibleWidth(tail) + separator.length + wanted <= budget) break;
195
+ kept.pop();
196
+ }
197
+
198
+ const tail = kept.length > 0 ? kept.join(separator) : '';
199
+ const messageBudget = tail
200
+ ? Math.max(1, budget - visibleWidth(tail) - separator.length)
201
+ : budget;
202
+ const body = truncate(text, messageBudget, GLYPHS.ellipsis);
203
+
204
+ const left = `${head}${paint('muted', body)}`;
205
+ if (!tail) return left;
206
+
207
+ const gap = Math.max(
208
+ visibleWidth(separator),
209
+ width - 1 - visibleWidth(left) - visibleWidth(tail)
210
+ );
211
+ return `${left}${' '.repeat(gap)}${dim(tail)}`;
212
+ }
213
+
214
+ /**
215
+ * The non-TTY form: no spinner, no elapsed clock, printed once.
216
+ */
217
+ renderStatic(message: string, width = 80): string {
218
+ const parts = [safeDisplay(message)];
219
+ if (this.model) parts.push(this.model);
220
+ return truncate(`${GLYPHS.dot} ${parts.join(` ${GLYPHS.dot} `)}`, width, GLYPHS.ellipsis);
221
+ }
222
+ }
@@ -83,11 +83,11 @@ export function renderCollapsedThinkingBadge(options, totalLines) {
83
83
  const { activeLabel, completedLabel } = resolveActivityLabels(options);
84
84
  if (isStreaming) {
85
85
  const timePart = durationText ? ` · ${durationText}` : '';
86
- return ` ${paint('warn', arrow)} ${bold(paint('warn', activeLabel))}${dim(timePart)} ${dim('· click to expand')}`;
86
+ return `${paint('warn', arrow)} ${bold(paint('warn', activeLabel))}${dim(timePart)} ${dim('· click to expand')}`;
87
87
  }
88
88
  const timePart = durationText ? ` for ${durationText}` : '';
89
89
  const lineWord = totalLines === 1 ? 'line' : 'lines';
90
- return ` ${paint('muted', arrow)} ${dim(`${completedLabel}${timePart}`)} ${dim(`(${totalLines} ${lineWord})`)} ${dim('· click to expand')}`;
90
+ return `${paint('muted', arrow)} ${dim(`${completedLabel}${timePart}`)} ${dim(`(${totalLines} ${lineWord})`)} ${dim('· click to expand')}`;
91
91
  }
92
92
  /**
93
93
  * Builds the top, bottom, and side frame borders for the thinking box.
@@ -92,12 +92,12 @@ export function renderCollapsedThinkingBadge(
92
92
 
93
93
  if (isStreaming) {
94
94
  const timePart = durationText ? ` · ${durationText}` : '';
95
- return ` ${paint('warn', arrow)} ${bold(paint('warn', activeLabel))}${dim(timePart)} ${dim('· click to expand')}`;
95
+ return `${paint('warn', arrow)} ${bold(paint('warn', activeLabel))}${dim(timePart)} ${dim('· click to expand')}`;
96
96
  }
97
97
 
98
98
  const timePart = durationText ? ` for ${durationText}` : '';
99
99
  const lineWord = totalLines === 1 ? 'line' : 'lines';
100
- return ` ${paint('muted', arrow)} ${dim(`${completedLabel}${timePart}`)} ${dim(`(${totalLines} ${lineWord})`)} ${dim('· click to expand')}`;
100
+ return `${paint('muted', arrow)} ${dim(`${completedLabel}${timePart}`)} ${dim(`(${totalLines} ${lineWord})`)} ${dim('· click to expand')}`;
101
101
  }
102
102
 
103
103
  /**
@@ -10,96 +10,93 @@
10
10
  // values are masked, and anything unmapped falls back to a generic summary so a
11
11
  // newly added tool can never render broken.
12
12
  //
13
- // Pure JS over src/tui/text.js. No dependency, no shell.
14
-
13
+ // Pure TypeScript over src/tui/text.js. No dependency, no shell.
15
14
  import { shortenHome, safeDisplay } from './text.js';
16
-
17
15
  /**
18
16
  * Pull the first present field, as a string.
19
17
  * Tools disagree about what to call their path argument — that inconsistency is
20
18
  * documented in sandbox.js PATH_ARGUMENTS and is the reason this exists.
21
19
  */
22
20
  function firstString(args, keys) {
23
- for (const key of keys) {
24
- const value = args[key];
25
- if (typeof value === 'string' && value.length > 0) return value;
26
- }
27
- return '';
21
+ for (const key of keys) {
22
+ const value = args[key];
23
+ if (typeof value === 'string' && value.length > 0)
24
+ return value;
25
+ }
26
+ return '';
28
27
  }
29
-
30
- function basename(pathish) {
31
- const cleaned = String(pathish).replace(/[/\\]+$/, '');
32
- const parts = cleaned.split(/[/\\]/);
33
- return parts[parts.length - 1] || cleaned;
34
- }
35
-
36
28
  /** Path detail: the filename, with just enough parent to disambiguate. */
37
29
  function pathDetail(value, { full = false } = {}) {
38
- if (!value) return '';
39
- const shortened = shortenHome(value);
40
- if (full) return shortened;
41
-
42
- const parts = shortened.split(/[/\\]/).filter(Boolean);
43
- if (parts.length <= 2) return shortened;
44
- return `${parts[parts.length - 2]}/${parts[parts.length - 1]}`;
30
+ if (!value)
31
+ return '';
32
+ const shortened = shortenHome(String(value));
33
+ if (full)
34
+ return shortened;
35
+ const parts = shortened.split(/[/\\]/).filter(Boolean);
36
+ if (parts.length <= 2)
37
+ return shortened;
38
+ return `${parts[parts.length - 2]}/${parts[parts.length - 1]}`;
45
39
  }
46
-
47
40
  function hostOf(url) {
48
- try {
49
- const parsed = new URL(url);
50
- return parsed.hostname + (parsed.pathname !== '/' ? parsed.pathname : '');
51
- } catch (e) {
52
- return String(url);
53
- }
41
+ try {
42
+ const parsed = new URL(String(url));
43
+ return parsed.hostname + (parsed.pathname !== '/' ? parsed.pathname : '');
44
+ }
45
+ catch {
46
+ return String(url ?? '');
47
+ }
54
48
  }
55
-
56
-
57
- const TOOL_DISPLAY = new Map([
58
- ['fs_read', (a) => ({ verb: 'read', detail: pathDetail(firstString(a, ['path', 'file_path'])) })],
59
- ['fs_write', (a) => ({ verb: 'write', detail: pathDetail(firstString(a, ['path', 'file_path'])) })],
60
- ['fs_edit', (a) => ({ verb: 'edit', detail: editDetail(a, 'edits') })],
61
- ['MultiEdit', (a) => ({ verb: 'edit', detail: editDetail(a, 'edits') })],
62
- ['fs_delete', (a) => ({ verb: 'delete', detail: pathDetail(firstString(a, ['path']), { full: true }) })],
63
- ['fs_move', (a) => ({ verb: 'move', detail: `${pathDetail(a.source)} → ${pathDetail(a.destination)}` })],
64
- ['fs_list', (a) => ({ verb: 'list', detail: pathDetail(firstString(a, ['path', 'directory']), { full: true }) })],
65
- ['fs_find', (a) => ({ verb: 'find', detail: firstString(a, ['pattern', 'query', 'name']) })],
66
- ['fs_search', (a) => ({ verb: 'search', detail: firstString(a, ['query', 'pattern']) })],
67
-
68
- ['sysRun', (a) => ({ verb: 'run', detail: a.command })],
69
- ['sysRunBg', (a) => ({ verb: 'run bg', detail: a.command })],
70
- ['terminal_persistent_shell', (a) => ({ verb: 'shell', detail: firstString(a, ['command', 'input']) })],
71
- ['proc_term', (a) => ({ verb: 'kill', detail: firstString(a, ['pid', 'name']) })],
72
- ['process_list', () => ({ verb: 'list', detail: 'processes' })],
73
-
74
- ['gitOp', (a) => ({ verb: 'git', detail: firstString(a, ['command', 'action', 'operation']) })],
75
- ['web_fetch', (a) => ({ verb: 'fetch', detail: hostOf(a.url) })],
76
- ['web_search', (a) => ({ verb: 'search', detail: firstString(a, ['query', 'q']) })],
77
- ['browser_act', (a) => ({ verb: 'browse', detail: firstString(a, ['url', 'action']) })],
78
- ['screenshot', (a) => ({ verb: 'capture', detail: firstString(a, ['target', 'url']) || 'screen' })],
79
-
80
- ['code_search_ripgrep', (a) => ({ verb: 'grep', detail: firstString(a, ['query', 'pattern']) })],
81
- ['codebase_search', (a) => ({ verb: 'search', detail: firstString(a, ['query']) })],
82
- ['code_verify_syntax', (a) => ({ verb: 'verify', detail: pathDetail(firstString(a, ['path', 'file_path'])) })],
83
-
84
- ['memory_write', (a) => ({ verb: 'remember', detail: firstString(a, ['fact', 'key', 'project']) })],
85
- ['update_plan', (a) => ({ verb: 'plan', detail: countDetail(a.plan, 'step') })],
86
- ['tool_search', (a) => ({ verb: 'discover', detail: firstString(a, ['query', 'description']) })],
87
- ['fs_read_skill', (a) => ({ verb: 'skill', detail: firstString(a, ['id', 'skillId', 'domain']) })],
88
-
89
- ['manage_local_dependencies', (a) => ({ verb: 'provision', detail: `${a.action || ''} ${a.group || a.package || ''}`.trim() })]
90
- ]);
91
-
92
49
  function editDetail(args, listKey) {
93
- const path = pathDetail(firstString(args, ['path', 'file_path']));
94
- const edits = Array.isArray(args[listKey]) ? args[listKey].length : 0;
95
- return edits > 1 ? `${path} (${edits} edits)` : path;
50
+ const path = pathDetail(firstString(args, ['path', 'file_path']));
51
+ const list = args[listKey];
52
+ const edits = Array.isArray(list) ? list.length : 0;
53
+ return edits > 1 ? `${path} (${edits} edits)` : path;
96
54
  }
97
-
98
55
  function countDetail(list, noun) {
99
- const count = Array.isArray(list) ? list.length : 0;
100
- return `${count} ${noun}${count === 1 ? '' : 's'}`;
56
+ const count = Array.isArray(list) ? list.length : 0;
57
+ return `${count} ${noun}${count === 1 ? '' : 's'}`;
101
58
  }
102
-
59
+ const TOOL_DISPLAY = new Map([
60
+ ['fs_read', (a) => ({ verb: 'read', detail: pathDetail(firstString(a, ['path', 'file_path', 'target'])) })],
61
+ ['read_file', (a) => ({ verb: 'read', detail: pathDetail(firstString(a, ['path', 'file_path', 'target'])) })],
62
+ ['view_file', (a) => ({ verb: 'read', detail: pathDetail(firstString(a, ['path', 'file_path', 'target'])) })],
63
+ ['fs_write', (a) => ({ verb: 'write', detail: pathDetail(firstString(a, ['path', 'file_path', 'target'])) })],
64
+ ['write_file', (a) => ({ verb: 'write', detail: pathDetail(firstString(a, ['path', 'file_path', 'target'])) })],
65
+ ['create_file', (a) => ({ verb: 'write', detail: pathDetail(firstString(a, ['path', 'file_path', 'target'])) })],
66
+ ['fs_edit', (a) => ({ verb: 'edit', detail: editDetail(a, 'edits') })],
67
+ ['edit_file', (a) => ({ verb: 'edit', detail: editDetail(a, 'edits') })],
68
+ ['MultiEdit', (a) => ({ verb: 'edit', detail: editDetail(a, 'edits') })],
69
+ ['fs_delete', (a) => ({ verb: 'delete', detail: pathDetail(firstString(a, ['path']), { full: true }) })],
70
+ ['fs_move', (a) => ({ verb: 'move', detail: `${pathDetail(a['source'])} → ${pathDetail(a['destination'])}` })],
71
+ ['fs_list', (a) => ({ verb: 'list', detail: pathDetail(firstString(a, ['path', 'directory']), { full: true }) })],
72
+ ['fs_find', (a) => ({ verb: 'find', detail: firstString(a, ['pattern', 'query', 'name']) })],
73
+ ['fs_search', (a) => ({ verb: 'search', detail: firstString(a, ['query', 'pattern']) })],
74
+ ['sysRun', (a) => ({ verb: 'run', detail: firstString(a, ['command', 'cmd', 'detail']) })],
75
+ ['run_command', (a) => ({ verb: 'run', detail: firstString(a, ['command', 'cmd', 'detail']) })],
76
+ ['bash', (a) => ({ verb: 'run', detail: firstString(a, ['command', 'cmd', 'detail']) })],
77
+ ['terminal', (a) => ({ verb: 'run', detail: firstString(a, ['command', 'cmd', 'detail']) })],
78
+ ['execute', (a) => ({ verb: 'run', detail: firstString(a, ['command', 'cmd', 'detail']) })],
79
+ ['sh', (a) => ({ verb: 'run', detail: firstString(a, ['command', 'cmd', 'detail']) })],
80
+ ['zsh', (a) => ({ verb: 'run', detail: firstString(a, ['command', 'cmd', 'detail']) })],
81
+ ['sysRunBg', (a) => ({ verb: 'run bg', detail: firstString(a, ['command', 'cmd']) })],
82
+ ['terminal_persistent_shell', (a) => ({ verb: 'shell', detail: firstString(a, ['command', 'input']) })],
83
+ ['proc_term', (a) => ({ verb: 'kill', detail: firstString(a, ['pid', 'name']) })],
84
+ ['process_list', () => ({ verb: 'list', detail: 'processes' })],
85
+ ['gitOp', (a) => ({ verb: 'git', detail: firstString(a, ['command', 'action', 'operation']) })],
86
+ ['web_fetch', (a) => ({ verb: 'fetch', detail: hostOf(a['url']) })],
87
+ ['web_search', (a) => ({ verb: 'search', detail: firstString(a, ['query', 'q']) })],
88
+ ['browser_act', (a) => ({ verb: 'browse', detail: firstString(a, ['url', 'action']) })],
89
+ ['screenshot', (a) => ({ verb: 'capture', detail: firstString(a, ['target', 'url']) || 'screen' })],
90
+ ['code_search_ripgrep', (a) => ({ verb: 'grep', detail: firstString(a, ['query', 'pattern']) })],
91
+ ['codebase_search', (a) => ({ verb: 'search', detail: firstString(a, ['query']) })],
92
+ ['code_verify_syntax', (a) => ({ verb: 'verify', detail: pathDetail(firstString(a, ['path', 'file_path', 'detail'])) })],
93
+ ['verify', (a) => ({ verb: 'verify', detail: pathDetail(firstString(a, ['path', 'file_path', 'detail'])) })],
94
+ ['memory_write', (a) => ({ verb: 'remember', detail: firstString(a, ['fact', 'key', 'project']) })],
95
+ ['update_plan', (a) => ({ verb: 'plan', detail: countDetail(a['plan'], 'step') })],
96
+ ['tool_search', (a) => ({ verb: 'discover', detail: firstString(a, ['query', 'description']) })],
97
+ ['fs_read_skill', (a) => ({ verb: 'skill', detail: firstString(a, ['id', 'skillId', 'domain']) })],
98
+ ['manage_local_dependencies', (a) => ({ verb: 'provision', detail: `${String(a['action'] || '')} ${String(a['group'] || a['package'] || '')}`.trim() })]
99
+ ]);
103
100
  /**
104
101
  * Generic fallback for any tool without a curated entry.
105
102
  *
@@ -107,69 +104,69 @@ function countDetail(list, noun) {
107
104
  * ordering the approval prompt uses, for the same reason.
108
105
  */
109
106
  const FALLBACK_KEYS = [
110
- 'command', 'path', 'file_path', 'source', 'url', 'query', 'action',
111
- 'name', 'pattern', 'directory', 'target'
107
+ 'command', 'path', 'file_path', 'source', 'url', 'query', 'action',
108
+ 'name', 'pattern', 'directory', 'target'
112
109
  ];
113
-
114
110
  function fallbackDisplay(toolName, args) {
115
- const detail = firstString(args, FALLBACK_KEYS);
116
- if (detail) return { verb: '', detail: shortenHome(detail) };
117
-
118
- try {
119
- const compact = JSON.stringify(args);
120
- if (compact && compact !== '{}') return { verb: '', detail: compact };
121
- } catch (e) { /* circular or unserialisable: nothing useful to show */ }
122
- return { verb: '', detail: '' };
111
+ const detail = firstString(args, FALLBACK_KEYS);
112
+ if (detail)
113
+ return { verb: '', detail: shortenHome(detail) };
114
+ try {
115
+ const compact = JSON.stringify(args);
116
+ if (compact && compact !== '{}')
117
+ return { verb: '', detail: compact };
118
+ }
119
+ catch { /* circular or unserialisable: nothing useful to show */ }
120
+ return { verb: '', detail: '' };
123
121
  }
124
-
125
122
  /**
126
123
  * Resolve a tool call to `{ verb, detail }` fit for one terminal row.
127
124
  *
128
125
  * Never throws: a display helper must not be able to break the transcript.
129
126
  */
130
127
  export function describeTool(toolName, args) {
131
- const safeArgs = args && typeof args === 'object' ? args : {};
132
- let display;
133
-
134
- try {
135
- const curated = TOOL_DISPLAY.get(toolName);
136
- display = curated ? curated(safeArgs) : fallbackDisplay(toolName, safeArgs);
137
- } catch (e) {
138
- display = fallbackDisplay(toolName, safeArgs);
139
- }
140
-
141
- return {
142
- verb: safeDisplay(display.verb || ''),
143
- // Untrusted: an argument can carry escapes or a credential the model echoed.
144
- detail: safeDisplay(display.detail || '').replace(/\s+/g, ' ').trim()
145
- };
128
+ const safeArgs = args && typeof args === 'object' ? args : {};
129
+ const safeName = typeof toolName === 'string' ? toolName : '';
130
+ let display;
131
+ try {
132
+ const curated = TOOL_DISPLAY.get(safeName);
133
+ display = curated ? curated(safeArgs) : fallbackDisplay(safeName, safeArgs);
134
+ }
135
+ catch {
136
+ display = fallbackDisplay(safeName, safeArgs);
137
+ }
138
+ return {
139
+ verb: safeDisplay(display.verb || ''),
140
+ // Untrusted: an argument can carry escapes or a credential the model echoed.
141
+ detail: safeDisplay(display.detail || '').replace(/\s+/g, ' ').trim()
142
+ };
146
143
  }
147
-
148
144
  /** True when a curated entry exists — used by tests and by /help style output. */
149
145
  export function hasCuratedDisplay(toolName) {
150
- return TOOL_DISPLAY.has(toolName);
146
+ return TOOL_DISPLAY.has(toolName);
151
147
  }
152
-
153
148
  /**
154
149
  * Multi-line detail for an approval prompt, where the user needs more than one
155
150
  * row. Reuses the same ordering and the same redaction.
156
151
  */
157
152
  export function describeToolForApproval(args) {
158
- const safeArgs = args && typeof args === 'object' ? args : {};
159
- const lines = [];
160
-
161
- for (const key of FALLBACK_KEYS) {
162
- const value = safeArgs[key];
163
- if (typeof value !== 'string' || value.length === 0) continue;
164
- lines.push(`${key}: ${safeDisplay(shortenHome(value))}`);
165
- if (lines.length >= 4) break;
166
- }
167
-
168
- if (lines.length === 0) {
169
- try {
170
- const compact = JSON.stringify(safeArgs);
171
- if (compact && compact !== '{}') lines.push(safeDisplay(compact));
172
- } catch (e) { /* nothing showable */ }
173
- }
174
- return lines;
153
+ const safeArgs = args && typeof args === 'object' ? args : {};
154
+ const lines = [];
155
+ for (const key of FALLBACK_KEYS) {
156
+ const value = safeArgs[key];
157
+ if (typeof value !== 'string' || value.length === 0)
158
+ continue;
159
+ lines.push(`${key}: ${safeDisplay(shortenHome(value))}`);
160
+ if (lines.length >= 4)
161
+ break;
162
+ }
163
+ if (lines.length === 0) {
164
+ try {
165
+ const compact = JSON.stringify(safeArgs);
166
+ if (compact && compact !== '{}')
167
+ lines.push(safeDisplay(compact));
168
+ }
169
+ catch { /* nothing showable */ }
170
+ }
171
+ return lines;
175
172
  }