claude-threads 0.15.0 → 0.16.2
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.
- package/CHANGELOG.md +28 -0
- package/README.md +5 -5
- package/dist/index.js +20397 -387
- package/dist/mcp/permission-server.js +34039 -139
- package/package.json +14 -18
- package/dist/changelog.d.ts +0 -20
- package/dist/changelog.js +0 -134
- package/dist/claude/cli.d.ts +0 -50
- package/dist/claude/cli.js +0 -181
- package/dist/config/migration.d.ts +0 -45
- package/dist/config/migration.js +0 -35
- package/dist/config.d.ts +0 -21
- package/dist/config.js +0 -7
- package/dist/git/worktree.d.ts +0 -46
- package/dist/git/worktree.js +0 -228
- package/dist/index.d.ts +0 -2
- package/dist/logo.d.ts +0 -14
- package/dist/logo.js +0 -41
- package/dist/mattermost/api.d.ts +0 -85
- package/dist/mattermost/api.js +0 -124
- package/dist/mattermost/api.test.d.ts +0 -1
- package/dist/mattermost/api.test.js +0 -319
- package/dist/mcp/permission-server.d.ts +0 -2
- package/dist/onboarding.d.ts +0 -1
- package/dist/onboarding.js +0 -318
- package/dist/persistence/session-store.d.ts +0 -71
- package/dist/persistence/session-store.js +0 -152
- package/dist/platform/client.d.ts +0 -140
- package/dist/platform/client.js +0 -1
- package/dist/platform/formatter.d.ts +0 -74
- package/dist/platform/formatter.js +0 -1
- package/dist/platform/index.d.ts +0 -11
- package/dist/platform/index.js +0 -8
- package/dist/platform/mattermost/client.d.ts +0 -70
- package/dist/platform/mattermost/client.js +0 -404
- package/dist/platform/mattermost/formatter.d.ts +0 -20
- package/dist/platform/mattermost/formatter.js +0 -46
- package/dist/platform/mattermost/permission-api.d.ts +0 -10
- package/dist/platform/mattermost/permission-api.js +0 -139
- package/dist/platform/mattermost/types.d.ts +0 -71
- package/dist/platform/mattermost/types.js +0 -1
- package/dist/platform/permission-api-factory.d.ts +0 -11
- package/dist/platform/permission-api-factory.js +0 -21
- package/dist/platform/permission-api.d.ts +0 -67
- package/dist/platform/permission-api.js +0 -8
- package/dist/platform/types.d.ts +0 -70
- package/dist/platform/types.js +0 -7
- package/dist/session/commands.d.ts +0 -52
- package/dist/session/commands.js +0 -323
- package/dist/session/events.d.ts +0 -25
- package/dist/session/events.js +0 -368
- package/dist/session/index.d.ts +0 -7
- package/dist/session/index.js +0 -6
- package/dist/session/lifecycle.d.ts +0 -70
- package/dist/session/lifecycle.js +0 -456
- package/dist/session/manager.d.ts +0 -96
- package/dist/session/manager.js +0 -537
- package/dist/session/reactions.d.ts +0 -25
- package/dist/session/reactions.js +0 -151
- package/dist/session/streaming.d.ts +0 -47
- package/dist/session/streaming.js +0 -152
- package/dist/session/types.d.ts +0 -78
- package/dist/session/types.js +0 -9
- package/dist/session/worktree.d.ts +0 -56
- package/dist/session/worktree.js +0 -339
- package/dist/update-notifier.d.ts +0 -3
- package/dist/update-notifier.js +0 -41
- package/dist/utils/emoji.d.ts +0 -43
- package/dist/utils/emoji.js +0 -65
- package/dist/utils/emoji.test.d.ts +0 -1
- package/dist/utils/emoji.test.js +0 -131
- package/dist/utils/logger.d.ts +0 -34
- package/dist/utils/logger.js +0 -42
- package/dist/utils/logger.test.d.ts +0 -1
- package/dist/utils/logger.test.js +0 -121
- package/dist/utils/tool-formatter.d.ts +0 -53
- package/dist/utils/tool-formatter.js +0 -252
- package/dist/utils/tool-formatter.test.d.ts +0 -1
- package/dist/utils/tool-formatter.test.js +0 -372
|
@@ -1,372 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
|
2
|
-
import { shortenPath, parseMcpToolName, formatToolUse, formatToolForPermission, } from './tool-formatter.js';
|
|
3
|
-
// Mock formatter for tests - uses standard markdown syntax
|
|
4
|
-
const formatter = {
|
|
5
|
-
formatBold: (text) => `**${text}**`,
|
|
6
|
-
formatItalic: (text) => `_${text}_`,
|
|
7
|
-
formatCode: (text) => `\`${text}\``,
|
|
8
|
-
formatCodeBlock: (code, language) => language ? `\`\`\`${language}\n${code}\n\`\`\`` : `\`\`\`\n${code}\n\`\`\``,
|
|
9
|
-
formatUserMention: (username) => `@${username}`,
|
|
10
|
-
formatLink: (text, url) => `[${text}](${url})`,
|
|
11
|
-
formatListItem: (text) => `- ${text}`,
|
|
12
|
-
formatNumberedListItem: (num, text) => `${num}. ${text}`,
|
|
13
|
-
formatBlockquote: (text) => `> ${text}`,
|
|
14
|
-
formatHorizontalRule: () => '---',
|
|
15
|
-
formatHeading: (text, level) => `${'#'.repeat(level)} ${text}`,
|
|
16
|
-
escapeText: (text) => text,
|
|
17
|
-
};
|
|
18
|
-
describe('shortenPath', () => {
|
|
19
|
-
const originalHome = process.env.HOME;
|
|
20
|
-
beforeEach(() => {
|
|
21
|
-
process.env.HOME = '/Users/testuser';
|
|
22
|
-
});
|
|
23
|
-
afterEach(() => {
|
|
24
|
-
process.env.HOME = originalHome;
|
|
25
|
-
});
|
|
26
|
-
it('replaces home directory with ~', () => {
|
|
27
|
-
expect(shortenPath('/Users/testuser/projects/file.ts')).toBe('~/projects/file.ts');
|
|
28
|
-
});
|
|
29
|
-
it('leaves paths not under home unchanged', () => {
|
|
30
|
-
expect(shortenPath('/var/log/file.log')).toBe('/var/log/file.log');
|
|
31
|
-
});
|
|
32
|
-
it('handles empty path', () => {
|
|
33
|
-
expect(shortenPath('')).toBe('');
|
|
34
|
-
});
|
|
35
|
-
it('uses provided homeDir over env', () => {
|
|
36
|
-
expect(shortenPath('/custom/home/file.ts', '/custom/home')).toBe('~/file.ts');
|
|
37
|
-
});
|
|
38
|
-
it('handles path equal to home', () => {
|
|
39
|
-
expect(shortenPath('/Users/testuser')).toBe('~');
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
describe('parseMcpToolName', () => {
|
|
43
|
-
it('parses valid MCP tool names', () => {
|
|
44
|
-
expect(parseMcpToolName('mcp__server__tool')).toEqual({
|
|
45
|
-
server: 'server',
|
|
46
|
-
tool: 'tool',
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
it('handles tool names with underscores', () => {
|
|
50
|
-
expect(parseMcpToolName('mcp__my-server__my_complex__tool')).toEqual({
|
|
51
|
-
server: 'my-server',
|
|
52
|
-
tool: 'my_complex__tool',
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
it('returns null for non-MCP tools', () => {
|
|
56
|
-
expect(parseMcpToolName('Read')).toBeNull();
|
|
57
|
-
expect(parseMcpToolName('Write')).toBeNull();
|
|
58
|
-
expect(parseMcpToolName('Bash')).toBeNull();
|
|
59
|
-
});
|
|
60
|
-
it('returns null for invalid MCP format', () => {
|
|
61
|
-
expect(parseMcpToolName('mcp__')).toBeNull();
|
|
62
|
-
expect(parseMcpToolName('mcp__server')).toBeNull();
|
|
63
|
-
});
|
|
64
|
-
it('handles claude-in-chrome tools', () => {
|
|
65
|
-
expect(parseMcpToolName('mcp__claude-in-chrome__computer')).toEqual({
|
|
66
|
-
server: 'claude-in-chrome',
|
|
67
|
-
tool: 'computer',
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
describe('formatToolUse', () => {
|
|
72
|
-
const originalHome = process.env.HOME;
|
|
73
|
-
beforeEach(() => {
|
|
74
|
-
process.env.HOME = '/Users/testuser';
|
|
75
|
-
});
|
|
76
|
-
afterEach(() => {
|
|
77
|
-
process.env.HOME = originalHome;
|
|
78
|
-
});
|
|
79
|
-
describe('Read tool', () => {
|
|
80
|
-
it('formats Read with file path', () => {
|
|
81
|
-
const result = formatToolUse('Read', {
|
|
82
|
-
file_path: '/Users/testuser/file.ts',
|
|
83
|
-
}, formatter);
|
|
84
|
-
expect(result).toBe('📄 **Read** `~/file.ts`');
|
|
85
|
-
});
|
|
86
|
-
it('shows full path when not under home', () => {
|
|
87
|
-
const result = formatToolUse('Read', { file_path: '/var/log/app.log' }, formatter);
|
|
88
|
-
expect(result).toBe('📄 **Read** `/var/log/app.log`');
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
describe('Edit tool', () => {
|
|
92
|
-
it('formats Edit without diff in non-detailed mode', () => {
|
|
93
|
-
const result = formatToolUse('Edit', {
|
|
94
|
-
file_path: '/Users/testuser/file.ts',
|
|
95
|
-
old_string: 'old',
|
|
96
|
-
new_string: 'new',
|
|
97
|
-
}, formatter);
|
|
98
|
-
expect(result).toBe('✏️ **Edit** `~/file.ts`');
|
|
99
|
-
});
|
|
100
|
-
it('formats Edit with diff in detailed mode', () => {
|
|
101
|
-
const result = formatToolUse('Edit', {
|
|
102
|
-
file_path: '/Users/testuser/file.ts',
|
|
103
|
-
old_string: 'old line',
|
|
104
|
-
new_string: 'new line',
|
|
105
|
-
}, formatter, { detailed: true });
|
|
106
|
-
expect(result).toContain('✏️ **Edit** `~/file.ts`');
|
|
107
|
-
expect(result).toContain('```diff');
|
|
108
|
-
expect(result).toContain('- old line');
|
|
109
|
-
expect(result).toContain('+ new line');
|
|
110
|
-
});
|
|
111
|
-
it('truncates long diffs', () => {
|
|
112
|
-
const oldLines = Array(30).fill('old line').join('\n');
|
|
113
|
-
const newLines = Array(30).fill('new line').join('\n');
|
|
114
|
-
const result = formatToolUse('Edit', {
|
|
115
|
-
file_path: '/Users/testuser/file.ts',
|
|
116
|
-
old_string: oldLines,
|
|
117
|
-
new_string: newLines,
|
|
118
|
-
}, formatter, { detailed: true, maxPreviewLines: 10 });
|
|
119
|
-
expect(result).toContain('more lines');
|
|
120
|
-
});
|
|
121
|
-
});
|
|
122
|
-
describe('Write tool', () => {
|
|
123
|
-
it('formats Write without preview in non-detailed mode', () => {
|
|
124
|
-
const result = formatToolUse('Write', {
|
|
125
|
-
file_path: '/Users/testuser/file.ts',
|
|
126
|
-
content: 'hello world',
|
|
127
|
-
}, formatter);
|
|
128
|
-
expect(result).toBe('📝 **Write** `~/file.ts`');
|
|
129
|
-
});
|
|
130
|
-
it('formats Write with preview in detailed mode', () => {
|
|
131
|
-
const result = formatToolUse('Write', {
|
|
132
|
-
file_path: '/Users/testuser/file.ts',
|
|
133
|
-
content: 'line 1\nline 2\nline 3',
|
|
134
|
-
}, formatter, { detailed: true });
|
|
135
|
-
expect(result).toContain('📝 **Write** `~/file.ts`');
|
|
136
|
-
expect(result).toContain('_(3 lines)_');
|
|
137
|
-
expect(result).toContain('line 1');
|
|
138
|
-
});
|
|
139
|
-
it('truncates long content previews', () => {
|
|
140
|
-
const content = Array(20).fill('line').join('\n');
|
|
141
|
-
const result = formatToolUse('Write', {
|
|
142
|
-
file_path: '/Users/testuser/file.ts',
|
|
143
|
-
content,
|
|
144
|
-
}, formatter, { detailed: true });
|
|
145
|
-
expect(result).toContain('more lines');
|
|
146
|
-
});
|
|
147
|
-
});
|
|
148
|
-
describe('Bash tool', () => {
|
|
149
|
-
it('formats short commands', () => {
|
|
150
|
-
const result = formatToolUse('Bash', { command: 'ls -la' }, formatter);
|
|
151
|
-
expect(result).toBe('💻 **Bash** `ls -la`');
|
|
152
|
-
});
|
|
153
|
-
it('truncates long commands', () => {
|
|
154
|
-
const longCmd = 'x'.repeat(100);
|
|
155
|
-
const result = formatToolUse('Bash', { command: longCmd }, formatter);
|
|
156
|
-
expect(result).not.toBeNull();
|
|
157
|
-
expect(result).toContain('...');
|
|
158
|
-
expect(result.length).toBeLessThan(120);
|
|
159
|
-
});
|
|
160
|
-
it('respects custom maxCommandLength', () => {
|
|
161
|
-
const result = formatToolUse('Bash', { command: '1234567890' }, formatter, { maxCommandLength: 5 });
|
|
162
|
-
expect(result).toBe('💻 **Bash** `12345...`');
|
|
163
|
-
});
|
|
164
|
-
});
|
|
165
|
-
describe('Other tools', () => {
|
|
166
|
-
it('formats Glob', () => {
|
|
167
|
-
const result = formatToolUse('Glob', { pattern: '**/*.ts' }, formatter);
|
|
168
|
-
expect(result).toBe('🔍 **Glob** `**/*.ts`');
|
|
169
|
-
});
|
|
170
|
-
it('formats Grep', () => {
|
|
171
|
-
const result = formatToolUse('Grep', { pattern: 'TODO' }, formatter);
|
|
172
|
-
expect(result).toBe('🔎 **Grep** `TODO`');
|
|
173
|
-
});
|
|
174
|
-
it('formats EnterPlanMode', () => {
|
|
175
|
-
const result = formatToolUse('EnterPlanMode', {}, formatter);
|
|
176
|
-
expect(result).toBe('📋 **Planning...**');
|
|
177
|
-
});
|
|
178
|
-
it('formats WebFetch', () => {
|
|
179
|
-
const result = formatToolUse('WebFetch', {
|
|
180
|
-
url: 'https://example.com/page',
|
|
181
|
-
}, formatter);
|
|
182
|
-
expect(result).toBe('🌐 **Fetching** `https://example.com/page`');
|
|
183
|
-
});
|
|
184
|
-
it('formats WebSearch', () => {
|
|
185
|
-
const result = formatToolUse('WebSearch', { query: 'typescript guide' }, formatter);
|
|
186
|
-
expect(result).toBe('🔍 **Searching** `typescript guide`');
|
|
187
|
-
});
|
|
188
|
-
});
|
|
189
|
-
describe('Tools that return null', () => {
|
|
190
|
-
it('returns null for Task', () => {
|
|
191
|
-
expect(formatToolUse('Task', {}, formatter)).toBeNull();
|
|
192
|
-
});
|
|
193
|
-
it('returns null for ExitPlanMode', () => {
|
|
194
|
-
expect(formatToolUse('ExitPlanMode', {}, formatter)).toBeNull();
|
|
195
|
-
});
|
|
196
|
-
it('returns null for AskUserQuestion', () => {
|
|
197
|
-
expect(formatToolUse('AskUserQuestion', {}, formatter)).toBeNull();
|
|
198
|
-
});
|
|
199
|
-
it('returns null for TodoWrite', () => {
|
|
200
|
-
expect(formatToolUse('TodoWrite', {}, formatter)).toBeNull();
|
|
201
|
-
});
|
|
202
|
-
});
|
|
203
|
-
describe('MCP tools', () => {
|
|
204
|
-
it('formats MCP tools', () => {
|
|
205
|
-
const result = formatToolUse('mcp__myserver__mytool', { arg: 'value' }, formatter);
|
|
206
|
-
expect(result).toBe('🔌 **mytool** _(myserver)_');
|
|
207
|
-
});
|
|
208
|
-
it('formats MCP tools with underscores in name', () => {
|
|
209
|
-
const result = formatToolUse('mcp__my_server__my_tool', { arg: 'value' }, formatter);
|
|
210
|
-
expect(result).toBe('🔌 **my_tool** _(my_server)_');
|
|
211
|
-
});
|
|
212
|
-
});
|
|
213
|
-
describe('Claude in Chrome tools', () => {
|
|
214
|
-
it('formats computer screenshot action', () => {
|
|
215
|
-
const result = formatToolUse('mcp__claude-in-chrome__computer', { action: 'screenshot' }, formatter);
|
|
216
|
-
expect(result).toBe('🌐 **Chrome**[computer] `screenshot`');
|
|
217
|
-
});
|
|
218
|
-
it('formats computer click actions with coordinates', () => {
|
|
219
|
-
const result = formatToolUse('mcp__claude-in-chrome__computer', {
|
|
220
|
-
action: 'left_click',
|
|
221
|
-
coordinate: [100, 200],
|
|
222
|
-
}, formatter);
|
|
223
|
-
expect(result).toBe('🌐 **Chrome**[computer] `left_click at (100, 200)`');
|
|
224
|
-
});
|
|
225
|
-
it('formats computer type action', () => {
|
|
226
|
-
const result = formatToolUse('mcp__claude-in-chrome__computer', {
|
|
227
|
-
action: 'type',
|
|
228
|
-
text: 'hello world',
|
|
229
|
-
}, formatter);
|
|
230
|
-
expect(result).toBe('🌐 **Chrome**[computer] `type "hello world"`');
|
|
231
|
-
});
|
|
232
|
-
it('truncates long type text', () => {
|
|
233
|
-
const result = formatToolUse('mcp__claude-in-chrome__computer', {
|
|
234
|
-
action: 'type',
|
|
235
|
-
text: 'this is a very long text that should be truncated',
|
|
236
|
-
}, formatter);
|
|
237
|
-
expect(result).toContain('...');
|
|
238
|
-
});
|
|
239
|
-
it('formats computer key action', () => {
|
|
240
|
-
const result = formatToolUse('mcp__claude-in-chrome__computer', {
|
|
241
|
-
action: 'key',
|
|
242
|
-
text: 'Enter',
|
|
243
|
-
}, formatter);
|
|
244
|
-
expect(result).toBe('🌐 **Chrome**[computer] `key Enter`');
|
|
245
|
-
});
|
|
246
|
-
it('formats computer scroll action', () => {
|
|
247
|
-
const result = formatToolUse('mcp__claude-in-chrome__computer', {
|
|
248
|
-
action: 'scroll',
|
|
249
|
-
scroll_direction: 'up',
|
|
250
|
-
}, formatter);
|
|
251
|
-
expect(result).toBe('🌐 **Chrome**[computer] `scroll up`');
|
|
252
|
-
});
|
|
253
|
-
it('formats computer wait action', () => {
|
|
254
|
-
const result = formatToolUse('mcp__claude-in-chrome__computer', {
|
|
255
|
-
action: 'wait',
|
|
256
|
-
duration: 2,
|
|
257
|
-
}, formatter);
|
|
258
|
-
expect(result).toBe('🌐 **Chrome**[computer] `wait 2s`');
|
|
259
|
-
});
|
|
260
|
-
it('formats navigate tool', () => {
|
|
261
|
-
const result = formatToolUse('mcp__claude-in-chrome__navigate', {
|
|
262
|
-
url: 'https://example.com/page',
|
|
263
|
-
}, formatter);
|
|
264
|
-
expect(result).toBe('🌐 **Chrome**[navigate] `https://example.com/page`');
|
|
265
|
-
});
|
|
266
|
-
it('truncates long URLs in navigate', () => {
|
|
267
|
-
const result = formatToolUse('mcp__claude-in-chrome__navigate', {
|
|
268
|
-
url: 'https://example.com/' + 'x'.repeat(100),
|
|
269
|
-
}, formatter);
|
|
270
|
-
expect(result).toContain('...');
|
|
271
|
-
});
|
|
272
|
-
it('formats tabs_context_mcp tool', () => {
|
|
273
|
-
const result = formatToolUse('mcp__claude-in-chrome__tabs_context_mcp', {}, formatter);
|
|
274
|
-
expect(result).toBe('🌐 **Chrome**[tabs] reading context');
|
|
275
|
-
});
|
|
276
|
-
it('formats tabs_create_mcp tool', () => {
|
|
277
|
-
const result = formatToolUse('mcp__claude-in-chrome__tabs_create_mcp', {}, formatter);
|
|
278
|
-
expect(result).toBe('🌐 **Chrome**[tabs] creating new tab');
|
|
279
|
-
});
|
|
280
|
-
it('formats read_page tool', () => {
|
|
281
|
-
const result = formatToolUse('mcp__claude-in-chrome__read_page', {}, formatter);
|
|
282
|
-
expect(result).toBe('🌐 **Chrome**[read_page] accessibility tree');
|
|
283
|
-
});
|
|
284
|
-
it('formats read_page tool with interactive filter', () => {
|
|
285
|
-
const result = formatToolUse('mcp__claude-in-chrome__read_page', {
|
|
286
|
-
filter: 'interactive',
|
|
287
|
-
}, formatter);
|
|
288
|
-
expect(result).toBe('🌐 **Chrome**[read_page] interactive elements');
|
|
289
|
-
});
|
|
290
|
-
it('formats find tool', () => {
|
|
291
|
-
const result = formatToolUse('mcp__claude-in-chrome__find', {
|
|
292
|
-
query: 'login button',
|
|
293
|
-
}, formatter);
|
|
294
|
-
expect(result).toBe('🌐 **Chrome**[find] `login button`');
|
|
295
|
-
});
|
|
296
|
-
it('formats form_input tool', () => {
|
|
297
|
-
const result = formatToolUse('mcp__claude-in-chrome__form_input', {
|
|
298
|
-
ref: 'ref_1',
|
|
299
|
-
value: 'test',
|
|
300
|
-
}, formatter);
|
|
301
|
-
expect(result).toBe('🌐 **Chrome**[form_input] setting value');
|
|
302
|
-
});
|
|
303
|
-
it('formats get_page_text tool', () => {
|
|
304
|
-
const result = formatToolUse('mcp__claude-in-chrome__get_page_text', {}, formatter);
|
|
305
|
-
expect(result).toBe('🌐 **Chrome**[get_page_text] extracting content');
|
|
306
|
-
});
|
|
307
|
-
it('formats javascript_tool', () => {
|
|
308
|
-
const result = formatToolUse('mcp__claude-in-chrome__javascript_tool', {
|
|
309
|
-
text: 'document.title',
|
|
310
|
-
}, formatter);
|
|
311
|
-
expect(result).toBe('🌐 **Chrome**[javascript] executing script');
|
|
312
|
-
});
|
|
313
|
-
it('formats gif_creator tool', () => {
|
|
314
|
-
const result = formatToolUse('mcp__claude-in-chrome__gif_creator', {
|
|
315
|
-
action: 'start_recording',
|
|
316
|
-
}, formatter);
|
|
317
|
-
expect(result).toBe('🌐 **Chrome**[gif] start_recording');
|
|
318
|
-
});
|
|
319
|
-
it('formats unknown Chrome tools', () => {
|
|
320
|
-
const result = formatToolUse('mcp__claude-in-chrome__new_tool', {}, formatter);
|
|
321
|
-
expect(result).toBe('🌐 **Chrome**[new_tool]');
|
|
322
|
-
});
|
|
323
|
-
});
|
|
324
|
-
describe('Unknown tools', () => {
|
|
325
|
-
it('formats unknown tools with bullet', () => {
|
|
326
|
-
const result = formatToolUse('CustomTool', {}, formatter);
|
|
327
|
-
expect(result).toBe('● **CustomTool**');
|
|
328
|
-
});
|
|
329
|
-
});
|
|
330
|
-
});
|
|
331
|
-
describe('formatToolForPermission', () => {
|
|
332
|
-
const originalHome = process.env.HOME;
|
|
333
|
-
beforeEach(() => {
|
|
334
|
-
process.env.HOME = '/Users/testuser';
|
|
335
|
-
});
|
|
336
|
-
afterEach(() => {
|
|
337
|
-
process.env.HOME = originalHome;
|
|
338
|
-
});
|
|
339
|
-
it('formats Read tool', () => {
|
|
340
|
-
const result = formatToolForPermission('Read', {
|
|
341
|
-
file_path: '/Users/testuser/file.ts',
|
|
342
|
-
}, formatter);
|
|
343
|
-
expect(result).toBe('📄 **Read** `~/file.ts`');
|
|
344
|
-
});
|
|
345
|
-
it('formats Write tool', () => {
|
|
346
|
-
const result = formatToolForPermission('Write', {
|
|
347
|
-
file_path: '/Users/testuser/file.ts',
|
|
348
|
-
}, formatter);
|
|
349
|
-
expect(result).toBe('📝 **Write** `~/file.ts`');
|
|
350
|
-
});
|
|
351
|
-
it('formats Edit tool', () => {
|
|
352
|
-
const result = formatToolForPermission('Edit', {
|
|
353
|
-
file_path: '/Users/testuser/file.ts',
|
|
354
|
-
}, formatter);
|
|
355
|
-
expect(result).toBe('✏️ **Edit** `~/file.ts`');
|
|
356
|
-
});
|
|
357
|
-
it('formats Bash with longer truncation limit (100 chars)', () => {
|
|
358
|
-
const cmd = 'x'.repeat(100);
|
|
359
|
-
const result = formatToolForPermission('Bash', { command: cmd }, formatter);
|
|
360
|
-
// Should truncate at 100
|
|
361
|
-
expect(result).toContain('...');
|
|
362
|
-
expect(result.length).toBeLessThan(150);
|
|
363
|
-
});
|
|
364
|
-
it('formats MCP tools', () => {
|
|
365
|
-
const result = formatToolForPermission('mcp__server__tool', {}, formatter);
|
|
366
|
-
expect(result).toBe('🔌 **tool** _(server)_');
|
|
367
|
-
});
|
|
368
|
-
it('formats unknown tools', () => {
|
|
369
|
-
const result = formatToolForPermission('CustomTool', {}, formatter);
|
|
370
|
-
expect(result).toBe('● **CustomTool**');
|
|
371
|
-
});
|
|
372
|
-
});
|