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,90 +1,90 @@
1
- /**
2
- * Rainbow Editor - highlights "ultrathink" with animated shine effect
3
- *
4
- * Usage: shortcut --extension ./examples/extensions/rainbow-editor.ts
5
- */
6
-
7
- import { CustomEditor, type ExtensionAPI } from 'shortcutxl';
8
-
9
- // Base colors (coral → yellow → green → teal → blue → purple → pink)
10
- const COLORS: [number, number, number][] = [
11
- [233, 137, 115], // coral
12
- [228, 186, 103], // yellow
13
- [141, 192, 122], // green
14
- [102, 194, 179], // teal
15
- [121, 157, 207], // blue
16
- [157, 134, 195], // purple
17
- [206, 130, 172] // pink
18
- ];
19
- const RESET = '\x1b[0m';
20
-
21
- function brighten(rgb: [number, number, number], factor: number): string {
22
- const [r, g, b] = rgb.map((c) => Math.round(c + (255 - c) * factor));
23
- return `\x1b[38;2;${r};${g};${b}m`;
24
- }
25
-
26
- function colorize(text: string, shinePos: number): string {
27
- return (
28
- [...text]
29
- .map((c, i) => {
30
- const baseColor = COLORS[i % COLORS.length]!;
31
- // 3-letter shine: center bright, adjacent dimmer
32
- let factor = 0;
33
- if (shinePos >= 0) {
34
- const dist = Math.abs(i - shinePos);
35
- if (dist === 0) factor = 0.7;
36
- else if (dist === 1) factor = 0.35;
37
- }
38
- return `${brighten(baseColor, factor)}${c}`;
39
- })
40
- .join('') + RESET
41
- );
42
- }
43
-
44
- class RainbowEditor extends CustomEditor {
45
- private animationTimer?: ReturnType<typeof setInterval>;
46
- private frame = 0;
47
-
48
- private hasUltrathink(): boolean {
49
- return /ultrathink/i.test(this.getText());
50
- }
51
-
52
- private startAnimation(): void {
53
- if (this.animationTimer) return;
54
- this.animationTimer = setInterval(() => {
55
- this.frame++;
56
- this.tui.requestRender();
57
- }, 60);
58
- }
59
-
60
- private stopAnimation(): void {
61
- if (this.animationTimer) {
62
- clearInterval(this.animationTimer);
63
- this.animationTimer = undefined;
64
- }
65
- }
66
-
67
- handleInput(data: string): void {
68
- super.handleInput(data);
69
- if (this.hasUltrathink()) {
70
- this.startAnimation();
71
- } else {
72
- this.stopAnimation();
73
- }
74
- }
75
-
76
- render(width: number): string[] {
77
- // Cycle: 10 shine positions + 10 pause frames
78
- const cycle = this.frame % 20;
79
- const shinePos = cycle < 10 ? cycle : -1; // -1 means no shine (pause)
80
- return super
81
- .render(width)
82
- .map((line) => line.replace(/ultrathink/gi, (m) => colorize(m, shinePos)));
83
- }
84
- }
85
-
86
- export default function (shortcut: ExtensionAPI) {
87
- shortcut.on('session_start', (_event, ctx) => {
88
- ctx.ui.setEditorComponent((tui, theme, kb) => new RainbowEditor(tui, theme, kb));
89
- });
90
- }
1
+ /**
2
+ * Rainbow Editor - highlights "ultrathink" with animated shine effect
3
+ *
4
+ * Usage: shortcut --extension ./examples/extensions/rainbow-editor.ts
5
+ */
6
+
7
+ import { CustomEditor, type ExtensionAPI } from 'shortcutxl';
8
+
9
+ // Base colors (coral → yellow → green → teal → blue → purple → pink)
10
+ const COLORS: [number, number, number][] = [
11
+ [233, 137, 115], // coral
12
+ [228, 186, 103], // yellow
13
+ [141, 192, 122], // green
14
+ [102, 194, 179], // teal
15
+ [121, 157, 207], // blue
16
+ [157, 134, 195], // purple
17
+ [206, 130, 172] // pink
18
+ ];
19
+ const RESET = '\x1b[0m';
20
+
21
+ function brighten(rgb: [number, number, number], factor: number): string {
22
+ const [r, g, b] = rgb.map((c) => Math.round(c + (255 - c) * factor));
23
+ return `\x1b[38;2;${r};${g};${b}m`;
24
+ }
25
+
26
+ function colorize(text: string, shinePos: number): string {
27
+ return (
28
+ [...text]
29
+ .map((c, i) => {
30
+ const baseColor = COLORS[i % COLORS.length]!;
31
+ // 3-letter shine: center bright, adjacent dimmer
32
+ let factor = 0;
33
+ if (shinePos >= 0) {
34
+ const dist = Math.abs(i - shinePos);
35
+ if (dist === 0) factor = 0.7;
36
+ else if (dist === 1) factor = 0.35;
37
+ }
38
+ return `${brighten(baseColor, factor)}${c}`;
39
+ })
40
+ .join('') + RESET
41
+ );
42
+ }
43
+
44
+ class RainbowEditor extends CustomEditor {
45
+ private animationTimer?: ReturnType<typeof setInterval>;
46
+ private frame = 0;
47
+
48
+ private hasUltrathink(): boolean {
49
+ return /ultrathink/i.test(this.getText());
50
+ }
51
+
52
+ private startAnimation(): void {
53
+ if (this.animationTimer) return;
54
+ this.animationTimer = setInterval(() => {
55
+ this.frame++;
56
+ this.tui.requestRender();
57
+ }, 60);
58
+ }
59
+
60
+ private stopAnimation(): void {
61
+ if (this.animationTimer) {
62
+ clearInterval(this.animationTimer);
63
+ this.animationTimer = undefined;
64
+ }
65
+ }
66
+
67
+ handleInput(data: string): void {
68
+ super.handleInput(data);
69
+ if (this.hasUltrathink()) {
70
+ this.startAnimation();
71
+ } else {
72
+ this.stopAnimation();
73
+ }
74
+ }
75
+
76
+ render(width: number): string[] {
77
+ // Cycle: 10 shine positions + 10 pause frames
78
+ const cycle = this.frame % 20;
79
+ const shinePos = cycle < 10 ? cycle : -1; // -1 means no shine (pause)
80
+ return super
81
+ .render(width)
82
+ .map((line) => line.replace(/ultrathink/gi, (m) => colorize(m, shinePos)));
83
+ }
84
+ }
85
+
86
+ export default function (shortcut: ExtensionAPI) {
87
+ shortcut.on('session_start', (_event, ctx) => {
88
+ ctx.ui.setEditorComponent((tui, theme, kb) => new RainbowEditor(tui, theme, kb));
89
+ });
90
+ }
@@ -1,37 +1,37 @@
1
- /**
2
- * Reload Runtime Extension
3
- *
4
- * Demonstrates ctx.reload() from ExtensionCommandContext and an LLM-callable
5
- * tool that queues a follow-up command to trigger reload.
6
- */
7
-
8
- import { Type } from '@sinclair/typebox';
9
- import type { ExtensionAPI } from 'shortcutxl';
10
-
11
- export default function (shortcut: ExtensionAPI) {
12
- // Command entrypoint for reload.
13
- // Treat reload as terminal for this handler.
14
- shortcut.registerCommand('reload-runtime', {
15
- description: 'Reload extensions, skills, prompts, and themes',
16
- handler: async (_args, ctx) => {
17
- await ctx.reload();
18
- return;
19
- }
20
- });
21
-
22
- // LLM-callable tool. Tools get ExtensionContext, so they cannot call ctx.reload() directly.
23
- // Instead, queue a follow-up user command that executes the command above.
24
- shortcut.registerTool({
25
- name: 'reload_runtime',
26
- label: 'Reload Runtime',
27
- description: 'Reload extensions, skills, prompts, and themes',
28
- parameters: Type.Object({}),
29
- async execute() {
30
- shortcut.sendUserMessage('/reload-runtime', { deliverAs: 'followUp' });
31
- return {
32
- content: [{ type: 'text', text: 'Queued /reload-runtime as a follow-up command.' }],
33
- details: {}
34
- };
35
- }
36
- });
37
- }
1
+ /**
2
+ * Reload Runtime Extension
3
+ *
4
+ * Demonstrates ctx.reload() from ExtensionCommandContext and an LLM-callable
5
+ * tool that queues a follow-up command to trigger reload.
6
+ */
7
+
8
+ import { Type } from '@sinclair/typebox';
9
+ import type { ExtensionAPI } from 'shortcutxl';
10
+
11
+ export default function (shortcut: ExtensionAPI) {
12
+ // Command entrypoint for reload.
13
+ // Treat reload as terminal for this handler.
14
+ shortcut.registerCommand('reload-runtime', {
15
+ description: 'Reload extensions, skills, prompts, and themes',
16
+ handler: async (_args, ctx) => {
17
+ await ctx.reload();
18
+ return;
19
+ }
20
+ });
21
+
22
+ // LLM-callable tool. Tools get ExtensionContext, so they cannot call ctx.reload() directly.
23
+ // Instead, queue a follow-up user command that executes the command above.
24
+ shortcut.registerTool({
25
+ name: 'reload_runtime',
26
+ label: 'Reload Runtime',
27
+ description: 'Reload extensions, skills, prompts, and themes',
28
+ parameters: Type.Object({}),
29
+ async execute() {
30
+ shortcut.sendUserMessage('/reload-runtime', { deliverAs: 'followUp' });
31
+ return {
32
+ content: [{ type: 'text', text: 'Queued /reload-runtime as a follow-up command.' }],
33
+ details: {}
34
+ };
35
+ }
36
+ });
37
+ }
@@ -1,124 +1,124 @@
1
- /**
2
- * RPC Extension UI Demo
3
- *
4
- * Purpose-built extension that exercises all RPC-supported extension UI methods.
5
- * Designed to be loaded alongside the rpc-extension-ui-example.ts script to
6
- * demonstrate the full extension UI protocol.
7
- *
8
- * UI methods exercised:
9
- * - select() - on tool_call for dangerous bash commands
10
- * - confirm() - on session_before_switch
11
- * - input() - via /rpc-input command
12
- * - editor() - via /rpc-editor command
13
- * - notify() - after each dialog completes
14
- * - setStatus() - on turn_start/turn_end
15
- * - setWidget() - on session_start
16
- * - setTitle() - on session_start and session_switch
17
- * - setEditorText() - via /rpc-prefill command
18
- */
19
-
20
- import type { ExtensionAPI } from 'shortcutxl';
21
-
22
- export default function (shortcut: ExtensionAPI) {
23
- let turnCount = 0;
24
-
25
- // -- setTitle, setWidget, setStatus on session lifecycle --
26
-
27
- shortcut.on('session_start', async (_event, ctx) => {
28
- ctx.ui.setTitle('shortcut RPC Demo');
29
- ctx.ui.setWidget('rpc-demo', ['--- RPC Extension UI Demo ---', 'Loaded and ready.']);
30
- ctx.ui.setStatus('rpc-demo', `Turns: ${turnCount}`);
31
- });
32
-
33
- shortcut.on('session_switch', async (_event, ctx) => {
34
- turnCount = 0;
35
- ctx.ui.setTitle('shortcut RPC Demo (new session)');
36
- ctx.ui.setStatus('rpc-demo', `Turns: ${turnCount}`);
37
- });
38
-
39
- // -- setStatus on turn lifecycle --
40
-
41
- shortcut.on('turn_start', async (_event, ctx) => {
42
- turnCount++;
43
- ctx.ui.setStatus('rpc-demo', `Turn ${turnCount} running...`);
44
- });
45
-
46
- shortcut.on('turn_end', async (_event, ctx) => {
47
- ctx.ui.setStatus('rpc-demo', `Turn ${turnCount} done`);
48
- });
49
-
50
- // -- select on dangerous tool calls --
51
-
52
- shortcut.on('tool_call', async (event, ctx) => {
53
- if (event.toolName !== 'bash') return undefined;
54
-
55
- const command = event.input.command as string;
56
- const isDangerous = /\brm\s+(-rf?|--recursive)/i.test(command) || /\bsudo\b/i.test(command);
57
-
58
- if (isDangerous) {
59
- if (!ctx.hasUI) {
60
- return { block: true, reason: 'Dangerous command blocked (no UI)' };
61
- }
62
-
63
- const choice = await ctx.ui.select(`Dangerous command: ${command}`, ['Allow', 'Block']);
64
- if (choice !== 'Allow') {
65
- ctx.ui.notify('Command blocked by user', 'warning');
66
- return { block: true, reason: 'Blocked by user' };
67
- }
68
- ctx.ui.notify('Command allowed', 'info');
69
- }
70
-
71
- return undefined;
72
- });
73
-
74
- // -- confirm on session clear --
75
-
76
- shortcut.on('session_before_switch', async (event, ctx) => {
77
- if (event.reason !== 'new') return;
78
- if (!ctx.hasUI) return;
79
-
80
- const confirmed = await ctx.ui.confirm('Clear session?', 'All messages will be lost.');
81
- if (!confirmed) {
82
- ctx.ui.notify('Clear cancelled', 'info');
83
- return { cancel: true };
84
- }
85
- });
86
-
87
- // -- input via command --
88
-
89
- shortcut.registerCommand('rpc-input', {
90
- description: 'Prompt for text input (demonstrates ctx.ui.input in RPC)',
91
- handler: async (_args, ctx) => {
92
- const value = await ctx.ui.input('Enter a value', 'type something...');
93
- if (value) {
94
- ctx.ui.notify(`You entered: ${value}`, 'info');
95
- } else {
96
- ctx.ui.notify('Input cancelled', 'info');
97
- }
98
- }
99
- });
100
-
101
- // -- editor via command --
102
-
103
- shortcut.registerCommand('rpc-editor', {
104
- description: 'Open multi-line editor (demonstrates ctx.ui.editor in RPC)',
105
- handler: async (_args, ctx) => {
106
- const text = await ctx.ui.editor('Edit some text', 'Line 1\nLine 2\nLine 3');
107
- if (text) {
108
- ctx.ui.notify(`Editor submitted (${text.split('\n').length} lines)`, 'info');
109
- } else {
110
- ctx.ui.notify('Editor cancelled', 'info');
111
- }
112
- }
113
- });
114
-
115
- // -- setEditorText via command --
116
-
117
- shortcut.registerCommand('rpc-prefill', {
118
- description: 'Prefill the input editor (demonstrates ctx.ui.setEditorText in RPC)',
119
- handler: async (_args, ctx) => {
120
- ctx.ui.setEditorText('This text was set by the rpc-demo extension.');
121
- ctx.ui.notify('Editor prefilled', 'info');
122
- }
123
- });
124
- }
1
+ /**
2
+ * RPC Extension UI Demo
3
+ *
4
+ * Purpose-built extension that exercises all RPC-supported extension UI methods.
5
+ * Designed to be loaded alongside the rpc-extension-ui-example.ts script to
6
+ * demonstrate the full extension UI protocol.
7
+ *
8
+ * UI methods exercised:
9
+ * - select() - on tool_call for dangerous bash commands
10
+ * - confirm() - on session_before_switch
11
+ * - input() - via /rpc-input command
12
+ * - editor() - via /rpc-editor command
13
+ * - notify() - after each dialog completes
14
+ * - setStatus() - on turn_start/turn_end
15
+ * - setWidget() - on session_start
16
+ * - setTitle() - on session_start and session_switch
17
+ * - setEditorText() - via /rpc-prefill command
18
+ */
19
+
20
+ import type { ExtensionAPI } from 'shortcutxl';
21
+
22
+ export default function (shortcut: ExtensionAPI) {
23
+ let turnCount = 0;
24
+
25
+ // -- setTitle, setWidget, setStatus on session lifecycle --
26
+
27
+ shortcut.on('session_start', async (_event, ctx) => {
28
+ ctx.ui.setTitle('shortcut RPC Demo');
29
+ ctx.ui.setWidget('rpc-demo', ['--- RPC Extension UI Demo ---', 'Loaded and ready.']);
30
+ ctx.ui.setStatus('rpc-demo', `Turns: ${turnCount}`);
31
+ });
32
+
33
+ shortcut.on('session_switch', async (_event, ctx) => {
34
+ turnCount = 0;
35
+ ctx.ui.setTitle('shortcut RPC Demo (new session)');
36
+ ctx.ui.setStatus('rpc-demo', `Turns: ${turnCount}`);
37
+ });
38
+
39
+ // -- setStatus on turn lifecycle --
40
+
41
+ shortcut.on('turn_start', async (_event, ctx) => {
42
+ turnCount++;
43
+ ctx.ui.setStatus('rpc-demo', `Turn ${turnCount} running...`);
44
+ });
45
+
46
+ shortcut.on('turn_end', async (_event, ctx) => {
47
+ ctx.ui.setStatus('rpc-demo', `Turn ${turnCount} done`);
48
+ });
49
+
50
+ // -- select on dangerous tool calls --
51
+
52
+ shortcut.on('tool_call', async (event, ctx) => {
53
+ if (event.toolName !== 'bash') return undefined;
54
+
55
+ const command = event.input.command as string;
56
+ const isDangerous = /\brm\s+(-rf?|--recursive)/i.test(command) || /\bsudo\b/i.test(command);
57
+
58
+ if (isDangerous) {
59
+ if (!ctx.hasUI) {
60
+ return { block: true, reason: 'Dangerous command blocked (no UI)' };
61
+ }
62
+
63
+ const choice = await ctx.ui.select(`Dangerous command: ${command}`, ['Allow', 'Block']);
64
+ if (choice !== 'Allow') {
65
+ ctx.ui.notify('Command blocked by user', 'warning');
66
+ return { block: true, reason: 'Blocked by user' };
67
+ }
68
+ ctx.ui.notify('Command allowed', 'info');
69
+ }
70
+
71
+ return undefined;
72
+ });
73
+
74
+ // -- confirm on session clear --
75
+
76
+ shortcut.on('session_before_switch', async (event, ctx) => {
77
+ if (event.reason !== 'new') return;
78
+ if (!ctx.hasUI) return;
79
+
80
+ const confirmed = await ctx.ui.confirm('Clear session?', 'All messages will be lost.');
81
+ if (!confirmed) {
82
+ ctx.ui.notify('Clear cancelled', 'info');
83
+ return { cancel: true };
84
+ }
85
+ });
86
+
87
+ // -- input via command --
88
+
89
+ shortcut.registerCommand('rpc-input', {
90
+ description: 'Prompt for text input (demonstrates ctx.ui.input in RPC)',
91
+ handler: async (_args, ctx) => {
92
+ const value = await ctx.ui.input('Enter a value', 'type something...');
93
+ if (value) {
94
+ ctx.ui.notify(`You entered: ${value}`, 'info');
95
+ } else {
96
+ ctx.ui.notify('Input cancelled', 'info');
97
+ }
98
+ }
99
+ });
100
+
101
+ // -- editor via command --
102
+
103
+ shortcut.registerCommand('rpc-editor', {
104
+ description: 'Open multi-line editor (demonstrates ctx.ui.editor in RPC)',
105
+ handler: async (_args, ctx) => {
106
+ const text = await ctx.ui.editor('Edit some text', 'Line 1\nLine 2\nLine 3');
107
+ if (text) {
108
+ ctx.ui.notify(`Editor submitted (${text.split('\n').length} lines)`, 'info');
109
+ } else {
110
+ ctx.ui.notify('Editor cancelled', 'info');
111
+ }
112
+ }
113
+ });
114
+
115
+ // -- setEditorText via command --
116
+
117
+ shortcut.registerCommand('rpc-prefill', {
118
+ description: 'Prefill the input editor (demonstrates ctx.ui.setEditorText in RPC)',
119
+ handler: async (_args, ctx) => {
120
+ ctx.ui.setEditorText('This text was set by the rpc-demo extension.');
121
+ ctx.ui.notify('Editor prefilled', 'info');
122
+ }
123
+ });
124
+ }