@causyne/agent 1.20.54 → 1.20.55

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.
@@ -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
  }
@@ -0,0 +1,191 @@
1
+ // Curated tool display — what a tool call looks like to a human.
2
+ //
3
+ // The renderer used to print raw argument JSON, so a file write showed as
4
+ //
5
+ // fs_write {"path":"/Users/example/Projects/site/index.html","content":"<!DOC…
6
+ //
7
+ // which buries the one thing that matters (WHICH file) behind the one thing
8
+ // that does not (the entire payload). Every tool here declares a verb and the
9
+ // single detail worth reading; paths are shortened to `~`, credential-shaped
10
+ // values are masked, and anything unmapped falls back to a generic summary so a
11
+ // newly added tool can never render broken.
12
+ //
13
+ // Pure TypeScript over src/tui/text.js. No dependency, no shell.
14
+
15
+ import { shortenHome, safeDisplay } from './text.js';
16
+
17
+ export interface ToolDisplayResult {
18
+ verb: string;
19
+ detail: string;
20
+ }
21
+
22
+ export type ToolDisplayHandler = (args: Record<string, unknown>) => ToolDisplayResult;
23
+
24
+ /**
25
+ * Pull the first present field, as a string.
26
+ * Tools disagree about what to call their path argument — that inconsistency is
27
+ * documented in sandbox.js PATH_ARGUMENTS and is the reason this exists.
28
+ */
29
+ function firstString(args: Record<string, unknown>, keys: readonly string[]): string {
30
+ for (const key of keys) {
31
+ const value = args[key];
32
+ if (typeof value === 'string' && value.length > 0) return value;
33
+ }
34
+ return '';
35
+ }
36
+
37
+ /** Path detail: the filename, with just enough parent to disambiguate. */
38
+ function pathDetail(value: unknown, { full = false }: { full?: boolean } = {}): string {
39
+ if (!value) return '';
40
+ const shortened = shortenHome(String(value));
41
+ if (full) return shortened;
42
+
43
+ const parts = shortened.split(/[/\\]/).filter(Boolean);
44
+ if (parts.length <= 2) return shortened;
45
+ return `${parts[parts.length - 2]}/${parts[parts.length - 1]}`;
46
+ }
47
+
48
+ function hostOf(url: unknown): string {
49
+ try {
50
+ const parsed = new URL(String(url));
51
+ return parsed.hostname + (parsed.pathname !== '/' ? parsed.pathname : '');
52
+ } catch {
53
+ return String(url ?? '');
54
+ }
55
+ }
56
+
57
+ function editDetail(args: Record<string, unknown>, listKey: string): string {
58
+ const path = pathDetail(firstString(args, ['path', 'file_path']));
59
+ const list = args[listKey];
60
+ const edits = Array.isArray(list) ? list.length : 0;
61
+ return edits > 1 ? `${path} (${edits} edits)` : path;
62
+ }
63
+
64
+ function countDetail(list: unknown, noun: string): string {
65
+ const count = Array.isArray(list) ? list.length : 0;
66
+ return `${count} ${noun}${count === 1 ? '' : 's'}`;
67
+ }
68
+
69
+ const TOOL_DISPLAY = new Map<string, ToolDisplayHandler>([
70
+ ['fs_read', (a) => ({ verb: 'read', detail: pathDetail(firstString(a, ['path', 'file_path', 'target'])) })],
71
+ ['read_file', (a) => ({ verb: 'read', detail: pathDetail(firstString(a, ['path', 'file_path', 'target'])) })],
72
+ ['view_file', (a) => ({ verb: 'read', detail: pathDetail(firstString(a, ['path', 'file_path', 'target'])) })],
73
+
74
+ ['fs_write', (a) => ({ verb: 'write', detail: pathDetail(firstString(a, ['path', 'file_path', 'target'])) })],
75
+ ['write_file', (a) => ({ verb: 'write', detail: pathDetail(firstString(a, ['path', 'file_path', 'target'])) })],
76
+ ['create_file', (a) => ({ verb: 'write', detail: pathDetail(firstString(a, ['path', 'file_path', 'target'])) })],
77
+
78
+ ['fs_edit', (a) => ({ verb: 'edit', detail: editDetail(a, 'edits') })],
79
+ ['edit_file', (a) => ({ verb: 'edit', detail: editDetail(a, 'edits') })],
80
+ ['MultiEdit', (a) => ({ verb: 'edit', detail: editDetail(a, 'edits') })],
81
+ ['fs_delete', (a) => ({ verb: 'delete', detail: pathDetail(firstString(a, ['path']), { full: true }) })],
82
+ ['fs_move', (a) => ({ verb: 'move', detail: `${pathDetail(a['source'])} → ${pathDetail(a['destination'])}` })],
83
+ ['fs_list', (a) => ({ verb: 'list', detail: pathDetail(firstString(a, ['path', 'directory']), { full: true }) })],
84
+ ['fs_find', (a) => ({ verb: 'find', detail: firstString(a, ['pattern', 'query', 'name']) })],
85
+ ['fs_search', (a) => ({ verb: 'search', detail: firstString(a, ['query', 'pattern']) })],
86
+
87
+ ['sysRun', (a) => ({ verb: 'run', detail: firstString(a, ['command', 'cmd', 'detail']) })],
88
+ ['run_command', (a) => ({ verb: 'run', detail: firstString(a, ['command', 'cmd', 'detail']) })],
89
+ ['bash', (a) => ({ verb: 'run', detail: firstString(a, ['command', 'cmd', 'detail']) })],
90
+ ['terminal', (a) => ({ verb: 'run', detail: firstString(a, ['command', 'cmd', 'detail']) })],
91
+ ['execute', (a) => ({ verb: 'run', detail: firstString(a, ['command', 'cmd', 'detail']) })],
92
+ ['sh', (a) => ({ verb: 'run', detail: firstString(a, ['command', 'cmd', 'detail']) })],
93
+ ['zsh', (a) => ({ verb: 'run', detail: firstString(a, ['command', 'cmd', 'detail']) })],
94
+ ['sysRunBg', (a) => ({ verb: 'run bg', detail: firstString(a, ['command', 'cmd']) })],
95
+ ['terminal_persistent_shell', (a) => ({ verb: 'shell', detail: firstString(a, ['command', 'input']) })],
96
+ ['proc_term', (a) => ({ verb: 'kill', detail: firstString(a, ['pid', 'name']) })],
97
+ ['process_list', () => ({ verb: 'list', detail: 'processes' })],
98
+
99
+ ['gitOp', (a) => ({ verb: 'git', detail: firstString(a, ['command', 'action', 'operation']) })],
100
+ ['web_fetch', (a) => ({ verb: 'fetch', detail: hostOf(a['url']) })],
101
+ ['web_search', (a) => ({ verb: 'search', detail: firstString(a, ['query', 'q']) })],
102
+ ['browser_act', (a) => ({ verb: 'browse', detail: firstString(a, ['url', 'action']) })],
103
+ ['screenshot', (a) => ({ verb: 'capture', detail: firstString(a, ['target', 'url']) || 'screen' })],
104
+
105
+ ['code_search_ripgrep', (a) => ({ verb: 'grep', detail: firstString(a, ['query', 'pattern']) })],
106
+ ['codebase_search', (a) => ({ verb: 'search', detail: firstString(a, ['query']) })],
107
+ ['code_verify_syntax', (a) => ({ verb: 'verify', detail: pathDetail(firstString(a, ['path', 'file_path', 'detail'])) })],
108
+ ['verify', (a) => ({ verb: 'verify', detail: pathDetail(firstString(a, ['path', 'file_path', 'detail'])) })],
109
+
110
+ ['memory_write', (a) => ({ verb: 'remember', detail: firstString(a, ['fact', 'key', 'project']) })],
111
+ ['update_plan', (a) => ({ verb: 'plan', detail: countDetail(a['plan'], 'step') })],
112
+ ['tool_search', (a) => ({ verb: 'discover', detail: firstString(a, ['query', 'description']) })],
113
+ ['fs_read_skill', (a) => ({ verb: 'skill', detail: firstString(a, ['id', 'skillId', 'domain']) })],
114
+
115
+ ['manage_local_dependencies', (a) => ({ verb: 'provision', detail: `${String(a['action'] || '')} ${String(a['group'] || a['package'] || '')}`.trim() })]
116
+ ]);
117
+
118
+ /**
119
+ * Generic fallback for any tool without a curated entry.
120
+ *
121
+ * Ordered so the field that actually carries meaning shows first — the same
122
+ * ordering the approval prompt uses, for the same reason.
123
+ */
124
+ const FALLBACK_KEYS = [
125
+ 'command', 'path', 'file_path', 'source', 'url', 'query', 'action',
126
+ 'name', 'pattern', 'directory', 'target'
127
+ ] as const;
128
+
129
+ function fallbackDisplay(toolName: string, args: Record<string, unknown>): ToolDisplayResult {
130
+ const detail = firstString(args, FALLBACK_KEYS);
131
+ if (detail) return { verb: '', detail: shortenHome(detail) };
132
+
133
+ try {
134
+ const compact = JSON.stringify(args);
135
+ if (compact && compact !== '{}') return { verb: '', detail: compact };
136
+ } catch { /* circular or unserialisable: nothing useful to show */ }
137
+ return { verb: '', detail: '' };
138
+ }
139
+
140
+ /**
141
+ * Resolve a tool call to `{ verb, detail }` fit for one terminal row.
142
+ *
143
+ * Never throws: a display helper must not be able to break the transcript.
144
+ */
145
+ export function describeTool(toolName?: string, args?: Record<string, unknown> | null): ToolDisplayResult {
146
+ const safeArgs = args && typeof args === 'object' ? args : {};
147
+ const safeName = typeof toolName === 'string' ? toolName : '';
148
+ let display: ToolDisplayResult;
149
+
150
+ try {
151
+ const curated = TOOL_DISPLAY.get(safeName);
152
+ display = curated ? curated(safeArgs) : fallbackDisplay(safeName, safeArgs);
153
+ } catch {
154
+ display = fallbackDisplay(safeName, safeArgs);
155
+ }
156
+
157
+ return {
158
+ verb: safeDisplay(display.verb || ''),
159
+ // Untrusted: an argument can carry escapes or a credential the model echoed.
160
+ detail: safeDisplay(display.detail || '').replace(/\s+/g, ' ').trim()
161
+ };
162
+ }
163
+
164
+ /** True when a curated entry exists — used by tests and by /help style output. */
165
+ export function hasCuratedDisplay(toolName: string): boolean {
166
+ return TOOL_DISPLAY.has(toolName);
167
+ }
168
+
169
+ /**
170
+ * Multi-line detail for an approval prompt, where the user needs more than one
171
+ * row. Reuses the same ordering and the same redaction.
172
+ */
173
+ export function describeToolForApproval(args?: Record<string, unknown> | null): string[] {
174
+ const safeArgs = args && typeof args === 'object' ? args : {};
175
+ const lines: string[] = [];
176
+
177
+ for (const key of FALLBACK_KEYS) {
178
+ const value = safeArgs[key];
179
+ if (typeof value !== 'string' || value.length === 0) continue;
180
+ lines.push(`${key}: ${safeDisplay(shortenHome(value))}`);
181
+ if (lines.length >= 4) break;
182
+ }
183
+
184
+ if (lines.length === 0) {
185
+ try {
186
+ const compact = JSON.stringify(safeArgs);
187
+ if (compact && compact !== '{}') lines.push(safeDisplay(compact));
188
+ } catch { /* nothing showable */ }
189
+ }
190
+ return lines;
191
+ }