shortcutxl 0.2.12 → 0.2.13

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.
Files changed (110) hide show
  1. package/README.md +26 -26
  2. package/agent-docs/README.md +397 -397
  3. package/agent-docs/docs/compaction.md +390 -390
  4. package/agent-docs/docs/custom-provider.md +580 -580
  5. package/agent-docs/docs/extensions.md +1971 -1971
  6. package/agent-docs/docs/packages.md +209 -209
  7. package/agent-docs/docs/rpc.md +1317 -1317
  8. package/agent-docs/docs/sdk.md +962 -962
  9. package/agent-docs/docs/session.md +412 -412
  10. package/agent-docs/docs/termux.md +127 -127
  11. package/agent-docs/docs/tui.md +887 -887
  12. package/agent-docs/examples/README.md +25 -25
  13. package/agent-docs/examples/extensions/README.md +205 -205
  14. package/agent-docs/examples/extensions/antigravity-image-gen.ts +447 -447
  15. package/agent-docs/examples/extensions/auto-commit-on-exit.ts +49 -49
  16. package/agent-docs/examples/extensions/bash-spawn-hook.ts +30 -30
  17. package/agent-docs/examples/extensions/bookmark.ts +50 -50
  18. package/agent-docs/examples/extensions/built-in-tool-renderer.ts +256 -256
  19. package/agent-docs/examples/extensions/claude-rules.ts +86 -86
  20. package/agent-docs/examples/extensions/commands.ts +75 -75
  21. package/agent-docs/examples/extensions/confirm-destructive.ts +59 -59
  22. package/agent-docs/examples/extensions/custom-compaction.ts +126 -126
  23. package/agent-docs/examples/extensions/custom-footer.ts +63 -63
  24. package/agent-docs/examples/extensions/custom-header.ts +73 -73
  25. package/agent-docs/examples/extensions/custom-provider-anthropic/index.ts +660 -660
  26. package/agent-docs/examples/extensions/custom-provider-gitlab-duo/index.ts +362 -362
  27. package/agent-docs/examples/extensions/custom-provider-gitlab-duo/test.ts +88 -88
  28. package/agent-docs/examples/extensions/custom-provider-qwen-cli/index.ts +349 -349
  29. package/agent-docs/examples/extensions/dirty-repo-guard.ts +56 -56
  30. package/agent-docs/examples/extensions/doom-overlay/doom-component.ts +133 -133
  31. package/agent-docs/examples/extensions/doom-overlay/doom-keys.ts +108 -108
  32. package/agent-docs/examples/extensions/doom-overlay/index.ts +74 -74
  33. package/agent-docs/examples/extensions/dynamic-resources/index.ts +15 -15
  34. package/agent-docs/examples/extensions/dynamic-tools.ts +77 -77
  35. package/agent-docs/examples/extensions/event-bus.ts +43 -43
  36. package/agent-docs/examples/extensions/file-trigger.ts +41 -41
  37. package/agent-docs/examples/extensions/git-checkpoint.ts +53 -53
  38. package/agent-docs/examples/extensions/handoff.ts +155 -155
  39. package/agent-docs/examples/extensions/hello.ts +25 -25
  40. package/agent-docs/examples/extensions/inline-bash.ts +94 -94
  41. package/agent-docs/examples/extensions/input-transform.ts +43 -43
  42. package/agent-docs/examples/extensions/interactive-shell.ts +209 -209
  43. package/agent-docs/examples/extensions/mac-system-theme.ts +47 -47
  44. package/agent-docs/examples/extensions/message-renderer.ts +59 -59
  45. package/agent-docs/examples/extensions/minimal-mode.ts +430 -430
  46. package/agent-docs/examples/extensions/modal-editor.ts +90 -90
  47. package/agent-docs/examples/extensions/model-status.ts +31 -31
  48. package/agent-docs/examples/extensions/notify.ts +55 -55
  49. package/agent-docs/examples/extensions/overlay-qa-tests.ts +936 -936
  50. package/agent-docs/examples/extensions/overlay-test.ts +159 -159
  51. package/agent-docs/examples/extensions/permission-gate.ts +37 -37
  52. package/agent-docs/examples/extensions/pirate.ts +47 -47
  53. package/agent-docs/examples/extensions/plan-mode/index.ts +363 -363
  54. package/agent-docs/examples/extensions/preset.ts +418 -418
  55. package/agent-docs/examples/extensions/protected-paths.ts +30 -30
  56. package/agent-docs/examples/extensions/qna.ts +122 -122
  57. package/agent-docs/examples/extensions/question.ts +278 -278
  58. package/agent-docs/examples/extensions/questionnaire.ts +440 -440
  59. package/agent-docs/examples/extensions/rainbow-editor.ts +90 -90
  60. package/agent-docs/examples/extensions/reload-runtime.ts +37 -37
  61. package/agent-docs/examples/extensions/rpc-demo.ts +124 -124
  62. package/agent-docs/examples/extensions/sandbox/index.ts +324 -324
  63. package/agent-docs/examples/extensions/send-user-message.ts +97 -97
  64. package/agent-docs/examples/extensions/session-name.ts +27 -27
  65. package/agent-docs/examples/extensions/shutdown-command.ts +69 -69
  66. package/agent-docs/examples/extensions/snake.ts +343 -343
  67. package/agent-docs/examples/extensions/space-invaders.ts +566 -566
  68. package/agent-docs/examples/extensions/ssh.ts +233 -233
  69. package/agent-docs/examples/extensions/status-line.ts +40 -40
  70. package/agent-docs/examples/extensions/subagent/agents.ts +130 -130
  71. package/agent-docs/examples/extensions/subagent/index.ts +1068 -1068
  72. package/agent-docs/examples/extensions/summarize.ts +206 -206
  73. package/agent-docs/examples/extensions/system-prompt-header.ts +17 -17
  74. package/agent-docs/examples/extensions/timed-confirm.ts +72 -72
  75. package/agent-docs/examples/extensions/titlebar-spinner.ts +58 -58
  76. package/agent-docs/examples/extensions/todo.ts +314 -314
  77. package/agent-docs/examples/extensions/tool-override.ts +146 -146
  78. package/agent-docs/examples/extensions/tools.ts +145 -145
  79. package/agent-docs/examples/extensions/trigger-compact.ts +40 -40
  80. package/agent-docs/examples/extensions/truncated-tool.ts +194 -194
  81. package/agent-docs/examples/extensions/widget-placement.ts +17 -17
  82. package/agent-docs/examples/extensions/with-deps/index.ts +37 -37
  83. package/agent-docs/examples/rpc-extension-ui.ts +654 -654
  84. package/agent-docs/examples/sdk/01-minimal.ts +22 -22
  85. package/agent-docs/examples/sdk/02-custom-model.ts +48 -48
  86. package/agent-docs/examples/sdk/03-custom-prompt.ts +55 -55
  87. package/agent-docs/examples/sdk/04-skills.ts +53 -53
  88. package/agent-docs/examples/sdk/05-tools.ts +56 -56
  89. package/agent-docs/examples/sdk/06-extensions.ts +88 -88
  90. package/agent-docs/examples/sdk/07-context-files.ts +40 -40
  91. package/agent-docs/examples/sdk/08-prompt-templates.ts +47 -47
  92. package/agent-docs/examples/sdk/09-api-keys-and-oauth.ts +48 -48
  93. package/agent-docs/examples/sdk/10-settings.ts +54 -54
  94. package/agent-docs/examples/sdk/11-sessions.ts +48 -48
  95. package/agent-docs/examples/sdk/12-full-control.ts +82 -82
  96. package/agent-docs/examples/sdk/README.md +144 -144
  97. package/agent-docs/xll-spec.md +110 -110
  98. package/dist/core/auth-storage.js +21 -2
  99. package/package.json +1 -1
  100. package/xll/ShortcutXL.xll +0 -0
  101. package/xll/modules/debug_render.py +272 -272
  102. package/xll/modules/gameboy.py +241 -241
  103. package/xll/modules/pong.py +188 -188
  104. package/xll/modules/shortcut_xl/_diff_highlight.py +176 -0
  105. package/xll/modules/shortcut_xl/_log.py +12 -12
  106. package/xll/modules/shortcut_xl/_registry.py +44 -44
  107. package/xll/modules/stocks.py +100 -100
  108. /package/skills/{com-advanced-api → COM-advanced-api}/SKILL.md +0 -0
  109. /package/skills/{com-advanced-api → COM-advanced-api}/excel-type-library.py +0 -0
  110. /package/skills/{com-advanced-api → COM-advanced-api}/office-type-library.py +0 -0
@@ -1,430 +1,430 @@
1
- /**
2
- * Minimal Mode Example - Demonstrates a "minimal" tool display mode
3
- *
4
- * This extension overrides built-in tools to provide custom rendering:
5
- * - Collapsed mode: Only shows the tool call (command/path), no output
6
- * - Expanded mode: Shows full output like the built-in renderers
7
- *
8
- * This demonstrates how a "minimal mode" could work, where ctrl+o cycles through:
9
- * - Standard: Shows truncated output (current default)
10
- * - Expanded: Shows full output (current expanded)
11
- * - Minimal: Shows only tool call, no output (this extension's collapsed mode)
12
- *
13
- * Usage:
14
- * shortcut -e ./minimal-mode.ts
15
- *
16
- * Then use ctrl+o to toggle between minimal (collapsed) and full (expanded) views.
17
- */
18
-
19
- import { homedir } from 'os';
20
- import type { ExtensionAPI } from 'shortcutxl';
21
- import {
22
- createBashTool,
23
- createEditTool,
24
- createFindTool,
25
- createGrepTool,
26
- createLsTool,
27
- createReadTool,
28
- createWriteTool,
29
- Text
30
- } from 'shortcutxl';
31
-
32
- /**
33
- * Shorten a path by replacing home directory with ~
34
- */
35
- function shortenPath(path: string): string {
36
- const home = homedir();
37
- if (path.startsWith(home)) {
38
- return `~${path.slice(home.length)}`;
39
- }
40
- return path;
41
- }
42
-
43
- // Cache for built-in tools by cwd
44
- const toolCache = new Map<string, ReturnType<typeof createBuiltInTools>>();
45
-
46
- function createBuiltInTools(cwd: string) {
47
- return {
48
- read: createReadTool(cwd),
49
- bash: createBashTool(cwd),
50
- edit: createEditTool(cwd),
51
- write: createWriteTool(cwd),
52
- find: createFindTool(cwd),
53
- grep: createGrepTool(cwd),
54
- ls: createLsTool(cwd)
55
- };
56
- }
57
-
58
- function getBuiltInTools(cwd: string) {
59
- let tools = toolCache.get(cwd);
60
- if (!tools) {
61
- tools = createBuiltInTools(cwd);
62
- toolCache.set(cwd, tools);
63
- }
64
- return tools;
65
- }
66
-
67
- export default function (shortcut: ExtensionAPI) {
68
- // =========================================================================
69
- // Read Tool
70
- // =========================================================================
71
- shortcut.registerTool({
72
- name: 'read',
73
- label: 'read',
74
- description:
75
- 'Read the contents of a file. Supports text files and images (jpg, png, gif, webp). Images are sent as attachments. For text files, output is truncated to 2000 lines or 50KB (whichever is hit first). Use offset/limit for large files.',
76
- parameters: getBuiltInTools(process.cwd()).read.parameters,
77
-
78
- async execute(toolCallId, params, signal, onUpdate, ctx) {
79
- const tools = getBuiltInTools(ctx.cwd);
80
- return tools.read.execute(toolCallId, params, signal, onUpdate);
81
- },
82
-
83
- renderCall(args, theme) {
84
- const path = shortenPath(args.path || '');
85
- let pathDisplay = path ? theme.fg('accent', path) : theme.fg('toolOutput', '...');
86
-
87
- // Show line range if specified
88
- if (args.offset !== undefined || args.limit !== undefined) {
89
- const startLine = args.offset ?? 1;
90
- const endLine = args.limit !== undefined ? startLine + args.limit - 1 : '';
91
- pathDisplay += theme.fg('warning', `:${startLine}${endLine ? `-${endLine}` : ''}`);
92
- }
93
-
94
- return new Text(`${theme.fg('toolTitle', theme.bold('read'))} ${pathDisplay}`, 0, 0);
95
- },
96
-
97
- renderResult(result, { expanded }, theme) {
98
- // Minimal mode: show nothing in collapsed state
99
- if (!expanded) {
100
- return new Text('', 0, 0);
101
- }
102
-
103
- // Expanded mode: show full output
104
- const textContent = result.content.find((c) => c.type === 'text');
105
- if (!textContent || textContent.type !== 'text') {
106
- return new Text('', 0, 0);
107
- }
108
-
109
- const lines = textContent.text.split('\n');
110
- const output = lines.map((line) => theme.fg('toolOutput', line)).join('\n');
111
- return new Text(`\n${output}`, 0, 0);
112
- }
113
- });
114
-
115
- // =========================================================================
116
- // Bash Tool
117
- // =========================================================================
118
- shortcut.registerTool({
119
- name: 'bash',
120
- label: 'bash',
121
- description:
122
- 'Execute a bash command in the current working directory. Returns stdout and stderr. Output is truncated to last 2000 lines or 50KB (whichever is hit first).',
123
- parameters: getBuiltInTools(process.cwd()).bash.parameters,
124
-
125
- async execute(toolCallId, params, signal, onUpdate, ctx) {
126
- const tools = getBuiltInTools(ctx.cwd);
127
- return tools.bash.execute(toolCallId, params, signal, onUpdate);
128
- },
129
-
130
- renderCall(args, theme) {
131
- const command = args.command || '...';
132
- const timeout = args.timeout as number | undefined;
133
- const timeoutSuffix = timeout ? theme.fg('muted', ` (timeout ${timeout}s)`) : '';
134
-
135
- return new Text(theme.fg('toolTitle', theme.bold(`$ ${command}`)) + timeoutSuffix, 0, 0);
136
- },
137
-
138
- renderResult(result, { expanded }, theme) {
139
- // Minimal mode: show nothing in collapsed state
140
- if (!expanded) {
141
- return new Text('', 0, 0);
142
- }
143
-
144
- // Expanded mode: show full output
145
- const textContent = result.content.find((c) => c.type === 'text');
146
- if (!textContent || textContent.type !== 'text') {
147
- return new Text('', 0, 0);
148
- }
149
-
150
- const output = textContent.text
151
- .trim()
152
- .split('\n')
153
- .map((line) => theme.fg('toolOutput', line))
154
- .join('\n');
155
-
156
- if (!output) {
157
- return new Text('', 0, 0);
158
- }
159
-
160
- return new Text(`\n${output}`, 0, 0);
161
- }
162
- });
163
-
164
- // =========================================================================
165
- // Write Tool
166
- // =========================================================================
167
- shortcut.registerTool({
168
- name: 'write',
169
- label: 'write',
170
- description:
171
- "Write content to a file. Creates the file if it doesn't exist, overwrites if it does. Automatically creates parent directories.",
172
- parameters: getBuiltInTools(process.cwd()).write.parameters,
173
-
174
- async execute(toolCallId, params, signal, onUpdate, ctx) {
175
- const tools = getBuiltInTools(ctx.cwd);
176
- return tools.write.execute(toolCallId, params, signal, onUpdate);
177
- },
178
-
179
- renderCall(args, theme) {
180
- const path = shortenPath(args.path || '');
181
- const pathDisplay = path ? theme.fg('accent', path) : theme.fg('toolOutput', '...');
182
- const lineCount = args.content ? args.content.split('\n').length : 0;
183
- const lineInfo = lineCount > 0 ? theme.fg('muted', ` (${lineCount} lines)`) : '';
184
-
185
- return new Text(
186
- `${theme.fg('toolTitle', theme.bold('write'))} ${pathDisplay}${lineInfo}`,
187
- 0,
188
- 0
189
- );
190
- },
191
-
192
- renderResult(result, { expanded }, theme) {
193
- // Minimal mode: show nothing (file was written)
194
- if (!expanded) {
195
- return new Text('', 0, 0);
196
- }
197
-
198
- // Expanded mode: show error if any
199
- if (result.content.some((c) => c.type === 'text' && c.text)) {
200
- const textContent = result.content.find((c) => c.type === 'text');
201
- if (textContent?.type === 'text' && textContent.text) {
202
- return new Text(`\n${theme.fg('error', textContent.text)}`, 0, 0);
203
- }
204
- }
205
-
206
- return new Text('', 0, 0);
207
- }
208
- });
209
-
210
- // =========================================================================
211
- // Edit Tool
212
- // =========================================================================
213
- shortcut.registerTool({
214
- name: 'edit',
215
- label: 'edit',
216
- description:
217
- 'Edit a file by replacing exact text. The oldText must match exactly (including whitespace). Use this for precise, surgical edits.',
218
- parameters: getBuiltInTools(process.cwd()).edit.parameters,
219
-
220
- async execute(toolCallId, params, signal, onUpdate, ctx) {
221
- const tools = getBuiltInTools(ctx.cwd);
222
- return tools.edit.execute(toolCallId, params, signal, onUpdate);
223
- },
224
-
225
- renderCall(args, theme) {
226
- const path = shortenPath(args.path || '');
227
- const pathDisplay = path ? theme.fg('accent', path) : theme.fg('toolOutput', '...');
228
-
229
- return new Text(`${theme.fg('toolTitle', theme.bold('edit'))} ${pathDisplay}`, 0, 0);
230
- },
231
-
232
- renderResult(result, { expanded }, theme) {
233
- // Minimal mode: show nothing in collapsed state
234
- if (!expanded) {
235
- return new Text('', 0, 0);
236
- }
237
-
238
- // Expanded mode: show diff or error
239
- const textContent = result.content.find((c) => c.type === 'text');
240
- if (!textContent || textContent.type !== 'text') {
241
- return new Text('', 0, 0);
242
- }
243
-
244
- // For errors, show the error message
245
- const text = textContent.text;
246
- if (text.includes('Error') || text.includes('error')) {
247
- return new Text(`\n${theme.fg('error', text)}`, 0, 0);
248
- }
249
-
250
- // Otherwise show the text (would be nice to show actual diff here)
251
- return new Text(`\n${theme.fg('toolOutput', text)}`, 0, 0);
252
- }
253
- });
254
-
255
- // =========================================================================
256
- // Find Tool
257
- // =========================================================================
258
- shortcut.registerTool({
259
- name: 'find',
260
- label: 'find',
261
- description:
262
- 'Find files by name pattern (glob). Searches recursively from the specified path. Output limited to 200 results.',
263
- parameters: getBuiltInTools(process.cwd()).find.parameters,
264
-
265
- async execute(toolCallId, params, signal, onUpdate, ctx) {
266
- const tools = getBuiltInTools(ctx.cwd);
267
- return tools.find.execute(toolCallId, params, signal, onUpdate);
268
- },
269
-
270
- renderCall(args, theme) {
271
- const pattern = args.pattern || '';
272
- const path = shortenPath(args.path || '.');
273
- const limit = args.limit;
274
-
275
- let text = `${theme.fg('toolTitle', theme.bold('find'))} ${theme.fg('accent', pattern)}`;
276
- text += theme.fg('toolOutput', ` in ${path}`);
277
- if (limit !== undefined) {
278
- text += theme.fg('toolOutput', ` (limit ${limit})`);
279
- }
280
-
281
- return new Text(text, 0, 0);
282
- },
283
-
284
- renderResult(result, { expanded }, theme) {
285
- if (!expanded) {
286
- // Minimal: just show count
287
- const textContent = result.content.find((c) => c.type === 'text');
288
- if (textContent?.type === 'text') {
289
- const count = textContent.text.trim().split('\n').filter(Boolean).length;
290
- if (count > 0) {
291
- return new Text(theme.fg('muted', ` → ${count} files`), 0, 0);
292
- }
293
- }
294
- return new Text('', 0, 0);
295
- }
296
-
297
- // Expanded: show full results
298
- const textContent = result.content.find((c) => c.type === 'text');
299
- if (!textContent || textContent.type !== 'text') {
300
- return new Text('', 0, 0);
301
- }
302
-
303
- const output = textContent.text
304
- .trim()
305
- .split('\n')
306
- .map((line) => theme.fg('toolOutput', line))
307
- .join('\n');
308
-
309
- return new Text(`\n${output}`, 0, 0);
310
- }
311
- });
312
-
313
- // =========================================================================
314
- // Grep Tool
315
- // =========================================================================
316
- shortcut.registerTool({
317
- name: 'grep',
318
- label: 'grep',
319
- description:
320
- 'Search file contents by regex pattern. Uses ripgrep for fast searching. Output limited to 200 matches.',
321
- parameters: getBuiltInTools(process.cwd()).grep.parameters,
322
-
323
- async execute(toolCallId, params, signal, onUpdate, ctx) {
324
- const tools = getBuiltInTools(ctx.cwd);
325
- return tools.grep.execute(toolCallId, params, signal, onUpdate);
326
- },
327
-
328
- renderCall(args, theme) {
329
- const pattern = args.pattern || '';
330
- const path = shortenPath(args.path || '.');
331
- const glob = args.glob;
332
- const limit = args.limit;
333
-
334
- let text = `${theme.fg('toolTitle', theme.bold('grep'))} ${theme.fg('accent', `/${pattern}/`)}`;
335
- text += theme.fg('toolOutput', ` in ${path}`);
336
- if (glob) {
337
- text += theme.fg('toolOutput', ` (${glob})`);
338
- }
339
- if (limit !== undefined) {
340
- text += theme.fg('toolOutput', ` limit ${limit}`);
341
- }
342
-
343
- return new Text(text, 0, 0);
344
- },
345
-
346
- renderResult(result, { expanded }, theme) {
347
- if (!expanded) {
348
- // Minimal: just show match count
349
- const textContent = result.content.find((c) => c.type === 'text');
350
- if (textContent?.type === 'text') {
351
- const count = textContent.text.trim().split('\n').filter(Boolean).length;
352
- if (count > 0) {
353
- return new Text(theme.fg('muted', ` → ${count} matches`), 0, 0);
354
- }
355
- }
356
- return new Text('', 0, 0);
357
- }
358
-
359
- // Expanded: show full results
360
- const textContent = result.content.find((c) => c.type === 'text');
361
- if (!textContent || textContent.type !== 'text') {
362
- return new Text('', 0, 0);
363
- }
364
-
365
- const output = textContent.text
366
- .trim()
367
- .split('\n')
368
- .map((line) => theme.fg('toolOutput', line))
369
- .join('\n');
370
-
371
- return new Text(`\n${output}`, 0, 0);
372
- }
373
- });
374
-
375
- // =========================================================================
376
- // Ls Tool
377
- // =========================================================================
378
- shortcut.registerTool({
379
- name: 'ls',
380
- label: 'ls',
381
- description:
382
- 'List directory contents with file sizes. Shows files and directories with their sizes. Output limited to 500 entries.',
383
- parameters: getBuiltInTools(process.cwd()).ls.parameters,
384
-
385
- async execute(toolCallId, params, signal, onUpdate, ctx) {
386
- const tools = getBuiltInTools(ctx.cwd);
387
- return tools.ls.execute(toolCallId, params, signal, onUpdate);
388
- },
389
-
390
- renderCall(args, theme) {
391
- const path = shortenPath(args.path || '.');
392
- const limit = args.limit;
393
-
394
- let text = `${theme.fg('toolTitle', theme.bold('ls'))} ${theme.fg('accent', path)}`;
395
- if (limit !== undefined) {
396
- text += theme.fg('toolOutput', ` (limit ${limit})`);
397
- }
398
-
399
- return new Text(text, 0, 0);
400
- },
401
-
402
- renderResult(result, { expanded }, theme) {
403
- if (!expanded) {
404
- // Minimal: just show entry count
405
- const textContent = result.content.find((c) => c.type === 'text');
406
- if (textContent?.type === 'text') {
407
- const count = textContent.text.trim().split('\n').filter(Boolean).length;
408
- if (count > 0) {
409
- return new Text(theme.fg('muted', ` → ${count} entries`), 0, 0);
410
- }
411
- }
412
- return new Text('', 0, 0);
413
- }
414
-
415
- // Expanded: show full listing
416
- const textContent = result.content.find((c) => c.type === 'text');
417
- if (!textContent || textContent.type !== 'text') {
418
- return new Text('', 0, 0);
419
- }
420
-
421
- const output = textContent.text
422
- .trim()
423
- .split('\n')
424
- .map((line) => theme.fg('toolOutput', line))
425
- .join('\n');
426
-
427
- return new Text(`\n${output}`, 0, 0);
428
- }
429
- });
430
- }
1
+ /**
2
+ * Minimal Mode Example - Demonstrates a "minimal" tool display mode
3
+ *
4
+ * This extension overrides built-in tools to provide custom rendering:
5
+ * - Collapsed mode: Only shows the tool call (command/path), no output
6
+ * - Expanded mode: Shows full output like the built-in renderers
7
+ *
8
+ * This demonstrates how a "minimal mode" could work, where ctrl+o cycles through:
9
+ * - Standard: Shows truncated output (current default)
10
+ * - Expanded: Shows full output (current expanded)
11
+ * - Minimal: Shows only tool call, no output (this extension's collapsed mode)
12
+ *
13
+ * Usage:
14
+ * shortcut -e ./minimal-mode.ts
15
+ *
16
+ * Then use ctrl+o to toggle between minimal (collapsed) and full (expanded) views.
17
+ */
18
+
19
+ import { homedir } from 'os';
20
+ import type { ExtensionAPI } from 'shortcutxl';
21
+ import {
22
+ createBashTool,
23
+ createEditTool,
24
+ createFindTool,
25
+ createGrepTool,
26
+ createLsTool,
27
+ createReadTool,
28
+ createWriteTool,
29
+ Text
30
+ } from 'shortcutxl';
31
+
32
+ /**
33
+ * Shorten a path by replacing home directory with ~
34
+ */
35
+ function shortenPath(path: string): string {
36
+ const home = homedir();
37
+ if (path.startsWith(home)) {
38
+ return `~${path.slice(home.length)}`;
39
+ }
40
+ return path;
41
+ }
42
+
43
+ // Cache for built-in tools by cwd
44
+ const toolCache = new Map<string, ReturnType<typeof createBuiltInTools>>();
45
+
46
+ function createBuiltInTools(cwd: string) {
47
+ return {
48
+ read: createReadTool(cwd),
49
+ bash: createBashTool(cwd),
50
+ edit: createEditTool(cwd),
51
+ write: createWriteTool(cwd),
52
+ find: createFindTool(cwd),
53
+ grep: createGrepTool(cwd),
54
+ ls: createLsTool(cwd)
55
+ };
56
+ }
57
+
58
+ function getBuiltInTools(cwd: string) {
59
+ let tools = toolCache.get(cwd);
60
+ if (!tools) {
61
+ tools = createBuiltInTools(cwd);
62
+ toolCache.set(cwd, tools);
63
+ }
64
+ return tools;
65
+ }
66
+
67
+ export default function (shortcut: ExtensionAPI) {
68
+ // =========================================================================
69
+ // Read Tool
70
+ // =========================================================================
71
+ shortcut.registerTool({
72
+ name: 'read',
73
+ label: 'read',
74
+ description:
75
+ 'Read the contents of a file. Supports text files and images (jpg, png, gif, webp). Images are sent as attachments. For text files, output is truncated to 2000 lines or 50KB (whichever is hit first). Use offset/limit for large files.',
76
+ parameters: getBuiltInTools(process.cwd()).read.parameters,
77
+
78
+ async execute(toolCallId, params, signal, onUpdate, ctx) {
79
+ const tools = getBuiltInTools(ctx.cwd);
80
+ return tools.read.execute(toolCallId, params, signal, onUpdate);
81
+ },
82
+
83
+ renderCall(args, theme) {
84
+ const path = shortenPath(args.path || '');
85
+ let pathDisplay = path ? theme.fg('accent', path) : theme.fg('toolOutput', '...');
86
+
87
+ // Show line range if specified
88
+ if (args.offset !== undefined || args.limit !== undefined) {
89
+ const startLine = args.offset ?? 1;
90
+ const endLine = args.limit !== undefined ? startLine + args.limit - 1 : '';
91
+ pathDisplay += theme.fg('warning', `:${startLine}${endLine ? `-${endLine}` : ''}`);
92
+ }
93
+
94
+ return new Text(`${theme.fg('toolTitle', theme.bold('read'))} ${pathDisplay}`, 0, 0);
95
+ },
96
+
97
+ renderResult(result, { expanded }, theme) {
98
+ // Minimal mode: show nothing in collapsed state
99
+ if (!expanded) {
100
+ return new Text('', 0, 0);
101
+ }
102
+
103
+ // Expanded mode: show full output
104
+ const textContent = result.content.find((c) => c.type === 'text');
105
+ if (!textContent || textContent.type !== 'text') {
106
+ return new Text('', 0, 0);
107
+ }
108
+
109
+ const lines = textContent.text.split('\n');
110
+ const output = lines.map((line) => theme.fg('toolOutput', line)).join('\n');
111
+ return new Text(`\n${output}`, 0, 0);
112
+ }
113
+ });
114
+
115
+ // =========================================================================
116
+ // Bash Tool
117
+ // =========================================================================
118
+ shortcut.registerTool({
119
+ name: 'bash',
120
+ label: 'bash',
121
+ description:
122
+ 'Execute a bash command in the current working directory. Returns stdout and stderr. Output is truncated to last 2000 lines or 50KB (whichever is hit first).',
123
+ parameters: getBuiltInTools(process.cwd()).bash.parameters,
124
+
125
+ async execute(toolCallId, params, signal, onUpdate, ctx) {
126
+ const tools = getBuiltInTools(ctx.cwd);
127
+ return tools.bash.execute(toolCallId, params, signal, onUpdate);
128
+ },
129
+
130
+ renderCall(args, theme) {
131
+ const command = args.command || '...';
132
+ const timeout = args.timeout as number | undefined;
133
+ const timeoutSuffix = timeout ? theme.fg('muted', ` (timeout ${timeout}s)`) : '';
134
+
135
+ return new Text(theme.fg('toolTitle', theme.bold(`$ ${command}`)) + timeoutSuffix, 0, 0);
136
+ },
137
+
138
+ renderResult(result, { expanded }, theme) {
139
+ // Minimal mode: show nothing in collapsed state
140
+ if (!expanded) {
141
+ return new Text('', 0, 0);
142
+ }
143
+
144
+ // Expanded mode: show full output
145
+ const textContent = result.content.find((c) => c.type === 'text');
146
+ if (!textContent || textContent.type !== 'text') {
147
+ return new Text('', 0, 0);
148
+ }
149
+
150
+ const output = textContent.text
151
+ .trim()
152
+ .split('\n')
153
+ .map((line) => theme.fg('toolOutput', line))
154
+ .join('\n');
155
+
156
+ if (!output) {
157
+ return new Text('', 0, 0);
158
+ }
159
+
160
+ return new Text(`\n${output}`, 0, 0);
161
+ }
162
+ });
163
+
164
+ // =========================================================================
165
+ // Write Tool
166
+ // =========================================================================
167
+ shortcut.registerTool({
168
+ name: 'write',
169
+ label: 'write',
170
+ description:
171
+ "Write content to a file. Creates the file if it doesn't exist, overwrites if it does. Automatically creates parent directories.",
172
+ parameters: getBuiltInTools(process.cwd()).write.parameters,
173
+
174
+ async execute(toolCallId, params, signal, onUpdate, ctx) {
175
+ const tools = getBuiltInTools(ctx.cwd);
176
+ return tools.write.execute(toolCallId, params, signal, onUpdate);
177
+ },
178
+
179
+ renderCall(args, theme) {
180
+ const path = shortenPath(args.path || '');
181
+ const pathDisplay = path ? theme.fg('accent', path) : theme.fg('toolOutput', '...');
182
+ const lineCount = args.content ? args.content.split('\n').length : 0;
183
+ const lineInfo = lineCount > 0 ? theme.fg('muted', ` (${lineCount} lines)`) : '';
184
+
185
+ return new Text(
186
+ `${theme.fg('toolTitle', theme.bold('write'))} ${pathDisplay}${lineInfo}`,
187
+ 0,
188
+ 0
189
+ );
190
+ },
191
+
192
+ renderResult(result, { expanded }, theme) {
193
+ // Minimal mode: show nothing (file was written)
194
+ if (!expanded) {
195
+ return new Text('', 0, 0);
196
+ }
197
+
198
+ // Expanded mode: show error if any
199
+ if (result.content.some((c) => c.type === 'text' && c.text)) {
200
+ const textContent = result.content.find((c) => c.type === 'text');
201
+ if (textContent?.type === 'text' && textContent.text) {
202
+ return new Text(`\n${theme.fg('error', textContent.text)}`, 0, 0);
203
+ }
204
+ }
205
+
206
+ return new Text('', 0, 0);
207
+ }
208
+ });
209
+
210
+ // =========================================================================
211
+ // Edit Tool
212
+ // =========================================================================
213
+ shortcut.registerTool({
214
+ name: 'edit',
215
+ label: 'edit',
216
+ description:
217
+ 'Edit a file by replacing exact text. The oldText must match exactly (including whitespace). Use this for precise, surgical edits.',
218
+ parameters: getBuiltInTools(process.cwd()).edit.parameters,
219
+
220
+ async execute(toolCallId, params, signal, onUpdate, ctx) {
221
+ const tools = getBuiltInTools(ctx.cwd);
222
+ return tools.edit.execute(toolCallId, params, signal, onUpdate);
223
+ },
224
+
225
+ renderCall(args, theme) {
226
+ const path = shortenPath(args.path || '');
227
+ const pathDisplay = path ? theme.fg('accent', path) : theme.fg('toolOutput', '...');
228
+
229
+ return new Text(`${theme.fg('toolTitle', theme.bold('edit'))} ${pathDisplay}`, 0, 0);
230
+ },
231
+
232
+ renderResult(result, { expanded }, theme) {
233
+ // Minimal mode: show nothing in collapsed state
234
+ if (!expanded) {
235
+ return new Text('', 0, 0);
236
+ }
237
+
238
+ // Expanded mode: show diff or error
239
+ const textContent = result.content.find((c) => c.type === 'text');
240
+ if (!textContent || textContent.type !== 'text') {
241
+ return new Text('', 0, 0);
242
+ }
243
+
244
+ // For errors, show the error message
245
+ const text = textContent.text;
246
+ if (text.includes('Error') || text.includes('error')) {
247
+ return new Text(`\n${theme.fg('error', text)}`, 0, 0);
248
+ }
249
+
250
+ // Otherwise show the text (would be nice to show actual diff here)
251
+ return new Text(`\n${theme.fg('toolOutput', text)}`, 0, 0);
252
+ }
253
+ });
254
+
255
+ // =========================================================================
256
+ // Find Tool
257
+ // =========================================================================
258
+ shortcut.registerTool({
259
+ name: 'find',
260
+ label: 'find',
261
+ description:
262
+ 'Find files by name pattern (glob). Searches recursively from the specified path. Output limited to 200 results.',
263
+ parameters: getBuiltInTools(process.cwd()).find.parameters,
264
+
265
+ async execute(toolCallId, params, signal, onUpdate, ctx) {
266
+ const tools = getBuiltInTools(ctx.cwd);
267
+ return tools.find.execute(toolCallId, params, signal, onUpdate);
268
+ },
269
+
270
+ renderCall(args, theme) {
271
+ const pattern = args.pattern || '';
272
+ const path = shortenPath(args.path || '.');
273
+ const limit = args.limit;
274
+
275
+ let text = `${theme.fg('toolTitle', theme.bold('find'))} ${theme.fg('accent', pattern)}`;
276
+ text += theme.fg('toolOutput', ` in ${path}`);
277
+ if (limit !== undefined) {
278
+ text += theme.fg('toolOutput', ` (limit ${limit})`);
279
+ }
280
+
281
+ return new Text(text, 0, 0);
282
+ },
283
+
284
+ renderResult(result, { expanded }, theme) {
285
+ if (!expanded) {
286
+ // Minimal: just show count
287
+ const textContent = result.content.find((c) => c.type === 'text');
288
+ if (textContent?.type === 'text') {
289
+ const count = textContent.text.trim().split('\n').filter(Boolean).length;
290
+ if (count > 0) {
291
+ return new Text(theme.fg('muted', ` → ${count} files`), 0, 0);
292
+ }
293
+ }
294
+ return new Text('', 0, 0);
295
+ }
296
+
297
+ // Expanded: show full results
298
+ const textContent = result.content.find((c) => c.type === 'text');
299
+ if (!textContent || textContent.type !== 'text') {
300
+ return new Text('', 0, 0);
301
+ }
302
+
303
+ const output = textContent.text
304
+ .trim()
305
+ .split('\n')
306
+ .map((line) => theme.fg('toolOutput', line))
307
+ .join('\n');
308
+
309
+ return new Text(`\n${output}`, 0, 0);
310
+ }
311
+ });
312
+
313
+ // =========================================================================
314
+ // Grep Tool
315
+ // =========================================================================
316
+ shortcut.registerTool({
317
+ name: 'grep',
318
+ label: 'grep',
319
+ description:
320
+ 'Search file contents by regex pattern. Uses ripgrep for fast searching. Output limited to 200 matches.',
321
+ parameters: getBuiltInTools(process.cwd()).grep.parameters,
322
+
323
+ async execute(toolCallId, params, signal, onUpdate, ctx) {
324
+ const tools = getBuiltInTools(ctx.cwd);
325
+ return tools.grep.execute(toolCallId, params, signal, onUpdate);
326
+ },
327
+
328
+ renderCall(args, theme) {
329
+ const pattern = args.pattern || '';
330
+ const path = shortenPath(args.path || '.');
331
+ const glob = args.glob;
332
+ const limit = args.limit;
333
+
334
+ let text = `${theme.fg('toolTitle', theme.bold('grep'))} ${theme.fg('accent', `/${pattern}/`)}`;
335
+ text += theme.fg('toolOutput', ` in ${path}`);
336
+ if (glob) {
337
+ text += theme.fg('toolOutput', ` (${glob})`);
338
+ }
339
+ if (limit !== undefined) {
340
+ text += theme.fg('toolOutput', ` limit ${limit}`);
341
+ }
342
+
343
+ return new Text(text, 0, 0);
344
+ },
345
+
346
+ renderResult(result, { expanded }, theme) {
347
+ if (!expanded) {
348
+ // Minimal: just show match count
349
+ const textContent = result.content.find((c) => c.type === 'text');
350
+ if (textContent?.type === 'text') {
351
+ const count = textContent.text.trim().split('\n').filter(Boolean).length;
352
+ if (count > 0) {
353
+ return new Text(theme.fg('muted', ` → ${count} matches`), 0, 0);
354
+ }
355
+ }
356
+ return new Text('', 0, 0);
357
+ }
358
+
359
+ // Expanded: show full results
360
+ const textContent = result.content.find((c) => c.type === 'text');
361
+ if (!textContent || textContent.type !== 'text') {
362
+ return new Text('', 0, 0);
363
+ }
364
+
365
+ const output = textContent.text
366
+ .trim()
367
+ .split('\n')
368
+ .map((line) => theme.fg('toolOutput', line))
369
+ .join('\n');
370
+
371
+ return new Text(`\n${output}`, 0, 0);
372
+ }
373
+ });
374
+
375
+ // =========================================================================
376
+ // Ls Tool
377
+ // =========================================================================
378
+ shortcut.registerTool({
379
+ name: 'ls',
380
+ label: 'ls',
381
+ description:
382
+ 'List directory contents with file sizes. Shows files and directories with their sizes. Output limited to 500 entries.',
383
+ parameters: getBuiltInTools(process.cwd()).ls.parameters,
384
+
385
+ async execute(toolCallId, params, signal, onUpdate, ctx) {
386
+ const tools = getBuiltInTools(ctx.cwd);
387
+ return tools.ls.execute(toolCallId, params, signal, onUpdate);
388
+ },
389
+
390
+ renderCall(args, theme) {
391
+ const path = shortenPath(args.path || '.');
392
+ const limit = args.limit;
393
+
394
+ let text = `${theme.fg('toolTitle', theme.bold('ls'))} ${theme.fg('accent', path)}`;
395
+ if (limit !== undefined) {
396
+ text += theme.fg('toolOutput', ` (limit ${limit})`);
397
+ }
398
+
399
+ return new Text(text, 0, 0);
400
+ },
401
+
402
+ renderResult(result, { expanded }, theme) {
403
+ if (!expanded) {
404
+ // Minimal: just show entry count
405
+ const textContent = result.content.find((c) => c.type === 'text');
406
+ if (textContent?.type === 'text') {
407
+ const count = textContent.text.trim().split('\n').filter(Boolean).length;
408
+ if (count > 0) {
409
+ return new Text(theme.fg('muted', ` → ${count} entries`), 0, 0);
410
+ }
411
+ }
412
+ return new Text('', 0, 0);
413
+ }
414
+
415
+ // Expanded: show full listing
416
+ const textContent = result.content.find((c) => c.type === 'text');
417
+ if (!textContent || textContent.type !== 'text') {
418
+ return new Text('', 0, 0);
419
+ }
420
+
421
+ const output = textContent.text
422
+ .trim()
423
+ .split('\n')
424
+ .map((line) => theme.fg('toolOutput', line))
425
+ .join('\n');
426
+
427
+ return new Text(`\n${output}`, 0, 0);
428
+ }
429
+ });
430
+ }