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,314 +1,314 @@
1
- /**
2
- * Todo Extension - Demonstrates state management via session entries
3
- *
4
- * This extension:
5
- * - Registers a `todo` tool for the LLM to manage todos
6
- * - Registers a `/todos` command for users to view the list
7
- *
8
- * State is stored in tool result details (not external files), which allows
9
- * proper branching - when you branch, the todo state is automatically
10
- * correct for that point in history.
11
- */
12
-
13
- import { Type } from '@sinclair/typebox';
14
- import type { ExtensionAPI, ExtensionContext, Theme } from 'shortcutxl';
15
- import { matchesKey, StringEnum, Text, truncateToWidth } from 'shortcutxl';
16
-
17
- interface Todo {
18
- id: number;
19
- text: string;
20
- done: boolean;
21
- }
22
-
23
- interface TodoDetails {
24
- action: 'list' | 'add' | 'toggle' | 'clear';
25
- todos: Todo[];
26
- nextId: number;
27
- error?: string;
28
- }
29
-
30
- const TodoParams = Type.Object({
31
- action: StringEnum(['list', 'add', 'toggle', 'clear'] as const),
32
- text: Type.Optional(Type.String({ description: 'Todo text (for add)' })),
33
- id: Type.Optional(Type.Number({ description: 'Todo ID (for toggle)' }))
34
- });
35
-
36
- /**
37
- * UI component for the /todos command
38
- */
39
- class TodoListComponent {
40
- private todos: Todo[];
41
- private theme: Theme;
42
- private onClose: () => void;
43
- private cachedWidth?: number;
44
- private cachedLines?: string[];
45
-
46
- constructor(todos: Todo[], theme: Theme, onClose: () => void) {
47
- this.todos = todos;
48
- this.theme = theme;
49
- this.onClose = onClose;
50
- }
51
-
52
- handleInput(data: string): void {
53
- if (matchesKey(data, 'escape') || matchesKey(data, 'ctrl+c')) {
54
- this.onClose();
55
- }
56
- }
57
-
58
- render(width: number): string[] {
59
- if (this.cachedLines && this.cachedWidth === width) {
60
- return this.cachedLines;
61
- }
62
-
63
- const lines: string[] = [];
64
- const th = this.theme;
65
-
66
- lines.push('');
67
- const title = th.fg('accent', ' Todos ');
68
- const headerLine =
69
- th.fg('borderMuted', '─'.repeat(3)) +
70
- title +
71
- th.fg('borderMuted', '─'.repeat(Math.max(0, width - 10)));
72
- lines.push(truncateToWidth(headerLine, width));
73
- lines.push('');
74
-
75
- if (this.todos.length === 0) {
76
- lines.push(
77
- truncateToWidth(` ${th.fg('dim', 'No todos yet. Ask the agent to add some!')}`, width)
78
- );
79
- } else {
80
- const done = this.todos.filter((t) => t.done).length;
81
- const total = this.todos.length;
82
- lines.push(truncateToWidth(` ${th.fg('muted', `${done}/${total} completed`)}`, width));
83
- lines.push('');
84
-
85
- for (const todo of this.todos) {
86
- const check = todo.done ? th.fg('success', '✓') : th.fg('dim', '○');
87
- const id = th.fg('accent', `#${todo.id}`);
88
- const text = todo.done ? th.fg('dim', todo.text) : th.fg('text', todo.text);
89
- lines.push(truncateToWidth(` ${check} ${id} ${text}`, width));
90
- }
91
- }
92
-
93
- lines.push('');
94
- lines.push(truncateToWidth(` ${th.fg('dim', 'Press Escape to close')}`, width));
95
- lines.push('');
96
-
97
- this.cachedWidth = width;
98
- this.cachedLines = lines;
99
- return lines;
100
- }
101
-
102
- invalidate(): void {
103
- this.cachedWidth = undefined;
104
- this.cachedLines = undefined;
105
- }
106
- }
107
-
108
- export default function (shortcut: ExtensionAPI) {
109
- // In-memory state (reconstructed from session on load)
110
- let todos: Todo[] = [];
111
- let nextId = 1;
112
-
113
- /**
114
- * Reconstruct state from session entries.
115
- * Scans tool results for this tool and applies them in order.
116
- */
117
- const reconstructState = (ctx: ExtensionContext) => {
118
- todos = [];
119
- nextId = 1;
120
-
121
- for (const entry of ctx.sessionManager.getBranch()) {
122
- if (entry.type !== 'message') continue;
123
- const msg = entry.message;
124
- if (msg.role !== 'toolResult' || msg.toolName !== 'todo') continue;
125
-
126
- const details = msg.details as TodoDetails | undefined;
127
- if (details) {
128
- todos = details.todos;
129
- nextId = details.nextId;
130
- }
131
- }
132
- };
133
-
134
- // Reconstruct state on session events
135
- shortcut.on('session_start', async (_event, ctx) => reconstructState(ctx));
136
- shortcut.on('session_switch', async (_event, ctx) => reconstructState(ctx));
137
- shortcut.on('session_fork', async (_event, ctx) => reconstructState(ctx));
138
- shortcut.on('session_tree', async (_event, ctx) => reconstructState(ctx));
139
-
140
- // Register the todo tool for the LLM
141
- shortcut.registerTool({
142
- name: 'todo',
143
- label: 'Todo',
144
- description: 'Manage a todo list. Actions: list, add (text), toggle (id), clear',
145
- parameters: TodoParams,
146
-
147
- async execute(_toolCallId, params, _signal, _onUpdate, _ctx) {
148
- switch (params.action) {
149
- case 'list':
150
- return {
151
- content: [
152
- {
153
- type: 'text',
154
- text: todos.length
155
- ? todos.map((t) => `[${t.done ? 'x' : ' '}] #${t.id}: ${t.text}`).join('\n')
156
- : 'No todos'
157
- }
158
- ],
159
- details: { action: 'list', todos: [...todos], nextId } as TodoDetails
160
- };
161
-
162
- case 'add': {
163
- if (!params.text) {
164
- return {
165
- content: [{ type: 'text', text: 'Error: text required for add' }],
166
- details: {
167
- action: 'add',
168
- todos: [...todos],
169
- nextId,
170
- error: 'text required'
171
- } as TodoDetails
172
- };
173
- }
174
- const newTodo: Todo = { id: nextId++, text: params.text, done: false };
175
- todos.push(newTodo);
176
- return {
177
- content: [{ type: 'text', text: `Added todo #${newTodo.id}: ${newTodo.text}` }],
178
- details: { action: 'add', todos: [...todos], nextId } as TodoDetails
179
- };
180
- }
181
-
182
- case 'toggle': {
183
- if (params.id === undefined) {
184
- return {
185
- content: [{ type: 'text', text: 'Error: id required for toggle' }],
186
- details: {
187
- action: 'toggle',
188
- todos: [...todos],
189
- nextId,
190
- error: 'id required'
191
- } as TodoDetails
192
- };
193
- }
194
- const todo = todos.find((t) => t.id === params.id);
195
- if (!todo) {
196
- return {
197
- content: [{ type: 'text', text: `Todo #${params.id} not found` }],
198
- details: {
199
- action: 'toggle',
200
- todos: [...todos],
201
- nextId,
202
- error: `#${params.id} not found`
203
- } as TodoDetails
204
- };
205
- }
206
- todo.done = !todo.done;
207
- return {
208
- content: [
209
- { type: 'text', text: `Todo #${todo.id} ${todo.done ? 'completed' : 'uncompleted'}` }
210
- ],
211
- details: { action: 'toggle', todos: [...todos], nextId } as TodoDetails
212
- };
213
- }
214
-
215
- case 'clear': {
216
- const count = todos.length;
217
- todos = [];
218
- nextId = 1;
219
- return {
220
- content: [{ type: 'text', text: `Cleared ${count} todos` }],
221
- details: { action: 'clear', todos: [], nextId: 1 } as TodoDetails
222
- };
223
- }
224
-
225
- default:
226
- return {
227
- content: [{ type: 'text', text: `Unknown action: ${params.action}` }],
228
- details: {
229
- action: 'list',
230
- todos: [...todos],
231
- nextId,
232
- error: `unknown action: ${params.action}`
233
- } as TodoDetails
234
- };
235
- }
236
- },
237
-
238
- renderCall(args, theme) {
239
- let text = theme.fg('toolTitle', theme.bold('todo ')) + theme.fg('muted', args.action);
240
- if (args.text) text += ` ${theme.fg('dim', `"${args.text}"`)}`;
241
- if (args.id !== undefined) text += ` ${theme.fg('accent', `#${args.id}`)}`;
242
- return new Text(text, 0, 0);
243
- },
244
-
245
- renderResult(result, { expanded }, theme) {
246
- const details = result.details as TodoDetails | undefined;
247
- if (!details) {
248
- const text = result.content[0];
249
- return new Text(text?.type === 'text' ? text.text : '', 0, 0);
250
- }
251
-
252
- if (details.error) {
253
- return new Text(theme.fg('error', `Error: ${details.error}`), 0, 0);
254
- }
255
-
256
- const todoList = details.todos;
257
-
258
- switch (details.action) {
259
- case 'list': {
260
- if (todoList.length === 0) {
261
- return new Text(theme.fg('dim', 'No todos'), 0, 0);
262
- }
263
- let listText = theme.fg('muted', `${todoList.length} todo(s):`);
264
- const display = expanded ? todoList : todoList.slice(0, 5);
265
- for (const t of display) {
266
- const check = t.done ? theme.fg('success', '✓') : theme.fg('dim', '○');
267
- const itemText = t.done ? theme.fg('dim', t.text) : theme.fg('muted', t.text);
268
- listText += `\n${check} ${theme.fg('accent', `#${t.id}`)} ${itemText}`;
269
- }
270
- if (!expanded && todoList.length > 5) {
271
- listText += `\n${theme.fg('dim', `... ${todoList.length - 5} more`)}`;
272
- }
273
- return new Text(listText, 0, 0);
274
- }
275
-
276
- case 'add': {
277
- const added = todoList[todoList.length - 1];
278
- return new Text(
279
- theme.fg('success', '✓ Added ') +
280
- theme.fg('accent', `#${added.id}`) +
281
- ' ' +
282
- theme.fg('muted', added.text),
283
- 0,
284
- 0
285
- );
286
- }
287
-
288
- case 'toggle': {
289
- const text = result.content[0];
290
- const msg = text?.type === 'text' ? text.text : '';
291
- return new Text(theme.fg('success', '✓ ') + theme.fg('muted', msg), 0, 0);
292
- }
293
-
294
- case 'clear':
295
- return new Text(theme.fg('success', '✓ ') + theme.fg('muted', 'Cleared all todos'), 0, 0);
296
- }
297
- }
298
- });
299
-
300
- // Register the /todos command for users
301
- shortcut.registerCommand('todos', {
302
- description: 'Show all todos on the current branch',
303
- handler: async (_args, ctx) => {
304
- if (!ctx.hasUI) {
305
- ctx.ui.notify('/todos requires interactive mode', 'error');
306
- return;
307
- }
308
-
309
- await ctx.ui.custom<void>((_tui, theme, _kb, done) => {
310
- return new TodoListComponent(todos, theme, () => done());
311
- });
312
- }
313
- });
314
- }
1
+ /**
2
+ * Todo Extension - Demonstrates state management via session entries
3
+ *
4
+ * This extension:
5
+ * - Registers a `todo` tool for the LLM to manage todos
6
+ * - Registers a `/todos` command for users to view the list
7
+ *
8
+ * State is stored in tool result details (not external files), which allows
9
+ * proper branching - when you branch, the todo state is automatically
10
+ * correct for that point in history.
11
+ */
12
+
13
+ import { Type } from '@sinclair/typebox';
14
+ import type { ExtensionAPI, ExtensionContext, Theme } from 'shortcutxl';
15
+ import { matchesKey, StringEnum, Text, truncateToWidth } from 'shortcutxl';
16
+
17
+ interface Todo {
18
+ id: number;
19
+ text: string;
20
+ done: boolean;
21
+ }
22
+
23
+ interface TodoDetails {
24
+ action: 'list' | 'add' | 'toggle' | 'clear';
25
+ todos: Todo[];
26
+ nextId: number;
27
+ error?: string;
28
+ }
29
+
30
+ const TodoParams = Type.Object({
31
+ action: StringEnum(['list', 'add', 'toggle', 'clear'] as const),
32
+ text: Type.Optional(Type.String({ description: 'Todo text (for add)' })),
33
+ id: Type.Optional(Type.Number({ description: 'Todo ID (for toggle)' }))
34
+ });
35
+
36
+ /**
37
+ * UI component for the /todos command
38
+ */
39
+ class TodoListComponent {
40
+ private todos: Todo[];
41
+ private theme: Theme;
42
+ private onClose: () => void;
43
+ private cachedWidth?: number;
44
+ private cachedLines?: string[];
45
+
46
+ constructor(todos: Todo[], theme: Theme, onClose: () => void) {
47
+ this.todos = todos;
48
+ this.theme = theme;
49
+ this.onClose = onClose;
50
+ }
51
+
52
+ handleInput(data: string): void {
53
+ if (matchesKey(data, 'escape') || matchesKey(data, 'ctrl+c')) {
54
+ this.onClose();
55
+ }
56
+ }
57
+
58
+ render(width: number): string[] {
59
+ if (this.cachedLines && this.cachedWidth === width) {
60
+ return this.cachedLines;
61
+ }
62
+
63
+ const lines: string[] = [];
64
+ const th = this.theme;
65
+
66
+ lines.push('');
67
+ const title = th.fg('accent', ' Todos ');
68
+ const headerLine =
69
+ th.fg('borderMuted', '─'.repeat(3)) +
70
+ title +
71
+ th.fg('borderMuted', '─'.repeat(Math.max(0, width - 10)));
72
+ lines.push(truncateToWidth(headerLine, width));
73
+ lines.push('');
74
+
75
+ if (this.todos.length === 0) {
76
+ lines.push(
77
+ truncateToWidth(` ${th.fg('dim', 'No todos yet. Ask the agent to add some!')}`, width)
78
+ );
79
+ } else {
80
+ const done = this.todos.filter((t) => t.done).length;
81
+ const total = this.todos.length;
82
+ lines.push(truncateToWidth(` ${th.fg('muted', `${done}/${total} completed`)}`, width));
83
+ lines.push('');
84
+
85
+ for (const todo of this.todos) {
86
+ const check = todo.done ? th.fg('success', '✓') : th.fg('dim', '○');
87
+ const id = th.fg('accent', `#${todo.id}`);
88
+ const text = todo.done ? th.fg('dim', todo.text) : th.fg('text', todo.text);
89
+ lines.push(truncateToWidth(` ${check} ${id} ${text}`, width));
90
+ }
91
+ }
92
+
93
+ lines.push('');
94
+ lines.push(truncateToWidth(` ${th.fg('dim', 'Press Escape to close')}`, width));
95
+ lines.push('');
96
+
97
+ this.cachedWidth = width;
98
+ this.cachedLines = lines;
99
+ return lines;
100
+ }
101
+
102
+ invalidate(): void {
103
+ this.cachedWidth = undefined;
104
+ this.cachedLines = undefined;
105
+ }
106
+ }
107
+
108
+ export default function (shortcut: ExtensionAPI) {
109
+ // In-memory state (reconstructed from session on load)
110
+ let todos: Todo[] = [];
111
+ let nextId = 1;
112
+
113
+ /**
114
+ * Reconstruct state from session entries.
115
+ * Scans tool results for this tool and applies them in order.
116
+ */
117
+ const reconstructState = (ctx: ExtensionContext) => {
118
+ todos = [];
119
+ nextId = 1;
120
+
121
+ for (const entry of ctx.sessionManager.getBranch()) {
122
+ if (entry.type !== 'message') continue;
123
+ const msg = entry.message;
124
+ if (msg.role !== 'toolResult' || msg.toolName !== 'todo') continue;
125
+
126
+ const details = msg.details as TodoDetails | undefined;
127
+ if (details) {
128
+ todos = details.todos;
129
+ nextId = details.nextId;
130
+ }
131
+ }
132
+ };
133
+
134
+ // Reconstruct state on session events
135
+ shortcut.on('session_start', async (_event, ctx) => reconstructState(ctx));
136
+ shortcut.on('session_switch', async (_event, ctx) => reconstructState(ctx));
137
+ shortcut.on('session_fork', async (_event, ctx) => reconstructState(ctx));
138
+ shortcut.on('session_tree', async (_event, ctx) => reconstructState(ctx));
139
+
140
+ // Register the todo tool for the LLM
141
+ shortcut.registerTool({
142
+ name: 'todo',
143
+ label: 'Todo',
144
+ description: 'Manage a todo list. Actions: list, add (text), toggle (id), clear',
145
+ parameters: TodoParams,
146
+
147
+ async execute(_toolCallId, params, _signal, _onUpdate, _ctx) {
148
+ switch (params.action) {
149
+ case 'list':
150
+ return {
151
+ content: [
152
+ {
153
+ type: 'text',
154
+ text: todos.length
155
+ ? todos.map((t) => `[${t.done ? 'x' : ' '}] #${t.id}: ${t.text}`).join('\n')
156
+ : 'No todos'
157
+ }
158
+ ],
159
+ details: { action: 'list', todos: [...todos], nextId } as TodoDetails
160
+ };
161
+
162
+ case 'add': {
163
+ if (!params.text) {
164
+ return {
165
+ content: [{ type: 'text', text: 'Error: text required for add' }],
166
+ details: {
167
+ action: 'add',
168
+ todos: [...todos],
169
+ nextId,
170
+ error: 'text required'
171
+ } as TodoDetails
172
+ };
173
+ }
174
+ const newTodo: Todo = { id: nextId++, text: params.text, done: false };
175
+ todos.push(newTodo);
176
+ return {
177
+ content: [{ type: 'text', text: `Added todo #${newTodo.id}: ${newTodo.text}` }],
178
+ details: { action: 'add', todos: [...todos], nextId } as TodoDetails
179
+ };
180
+ }
181
+
182
+ case 'toggle': {
183
+ if (params.id === undefined) {
184
+ return {
185
+ content: [{ type: 'text', text: 'Error: id required for toggle' }],
186
+ details: {
187
+ action: 'toggle',
188
+ todos: [...todos],
189
+ nextId,
190
+ error: 'id required'
191
+ } as TodoDetails
192
+ };
193
+ }
194
+ const todo = todos.find((t) => t.id === params.id);
195
+ if (!todo) {
196
+ return {
197
+ content: [{ type: 'text', text: `Todo #${params.id} not found` }],
198
+ details: {
199
+ action: 'toggle',
200
+ todos: [...todos],
201
+ nextId,
202
+ error: `#${params.id} not found`
203
+ } as TodoDetails
204
+ };
205
+ }
206
+ todo.done = !todo.done;
207
+ return {
208
+ content: [
209
+ { type: 'text', text: `Todo #${todo.id} ${todo.done ? 'completed' : 'uncompleted'}` }
210
+ ],
211
+ details: { action: 'toggle', todos: [...todos], nextId } as TodoDetails
212
+ };
213
+ }
214
+
215
+ case 'clear': {
216
+ const count = todos.length;
217
+ todos = [];
218
+ nextId = 1;
219
+ return {
220
+ content: [{ type: 'text', text: `Cleared ${count} todos` }],
221
+ details: { action: 'clear', todos: [], nextId: 1 } as TodoDetails
222
+ };
223
+ }
224
+
225
+ default:
226
+ return {
227
+ content: [{ type: 'text', text: `Unknown action: ${params.action}` }],
228
+ details: {
229
+ action: 'list',
230
+ todos: [...todos],
231
+ nextId,
232
+ error: `unknown action: ${params.action}`
233
+ } as TodoDetails
234
+ };
235
+ }
236
+ },
237
+
238
+ renderCall(args, theme) {
239
+ let text = theme.fg('toolTitle', theme.bold('todo ')) + theme.fg('muted', args.action);
240
+ if (args.text) text += ` ${theme.fg('dim', `"${args.text}"`)}`;
241
+ if (args.id !== undefined) text += ` ${theme.fg('accent', `#${args.id}`)}`;
242
+ return new Text(text, 0, 0);
243
+ },
244
+
245
+ renderResult(result, { expanded }, theme) {
246
+ const details = result.details as TodoDetails | undefined;
247
+ if (!details) {
248
+ const text = result.content[0];
249
+ return new Text(text?.type === 'text' ? text.text : '', 0, 0);
250
+ }
251
+
252
+ if (details.error) {
253
+ return new Text(theme.fg('error', `Error: ${details.error}`), 0, 0);
254
+ }
255
+
256
+ const todoList = details.todos;
257
+
258
+ switch (details.action) {
259
+ case 'list': {
260
+ if (todoList.length === 0) {
261
+ return new Text(theme.fg('dim', 'No todos'), 0, 0);
262
+ }
263
+ let listText = theme.fg('muted', `${todoList.length} todo(s):`);
264
+ const display = expanded ? todoList : todoList.slice(0, 5);
265
+ for (const t of display) {
266
+ const check = t.done ? theme.fg('success', '✓') : theme.fg('dim', '○');
267
+ const itemText = t.done ? theme.fg('dim', t.text) : theme.fg('muted', t.text);
268
+ listText += `\n${check} ${theme.fg('accent', `#${t.id}`)} ${itemText}`;
269
+ }
270
+ if (!expanded && todoList.length > 5) {
271
+ listText += `\n${theme.fg('dim', `... ${todoList.length - 5} more`)}`;
272
+ }
273
+ return new Text(listText, 0, 0);
274
+ }
275
+
276
+ case 'add': {
277
+ const added = todoList[todoList.length - 1];
278
+ return new Text(
279
+ theme.fg('success', '✓ Added ') +
280
+ theme.fg('accent', `#${added.id}`) +
281
+ ' ' +
282
+ theme.fg('muted', added.text),
283
+ 0,
284
+ 0
285
+ );
286
+ }
287
+
288
+ case 'toggle': {
289
+ const text = result.content[0];
290
+ const msg = text?.type === 'text' ? text.text : '';
291
+ return new Text(theme.fg('success', '✓ ') + theme.fg('muted', msg), 0, 0);
292
+ }
293
+
294
+ case 'clear':
295
+ return new Text(theme.fg('success', '✓ ') + theme.fg('muted', 'Cleared all todos'), 0, 0);
296
+ }
297
+ }
298
+ });
299
+
300
+ // Register the /todos command for users
301
+ shortcut.registerCommand('todos', {
302
+ description: 'Show all todos on the current branch',
303
+ handler: async (_args, ctx) => {
304
+ if (!ctx.hasUI) {
305
+ ctx.ui.notify('/todos requires interactive mode', 'error');
306
+ return;
307
+ }
308
+
309
+ await ctx.ui.custom<void>((_tui, theme, _kb, done) => {
310
+ return new TodoListComponent(todos, theme, () => done());
311
+ });
312
+ }
313
+ });
314
+ }