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,74 +1,74 @@
1
- /**
2
- * DOOM Overlay Demo - Play DOOM as an overlay
3
- *
4
- * Usage: shortcut --extension ./examples/extensions/doom-overlay
5
- *
6
- * Commands:
7
- * /doom-overlay - Play DOOM in an overlay (Q to pause/exit)
8
- *
9
- * This demonstrates that overlays can handle real-time game rendering at 35 FPS.
10
- */
11
-
12
- import type { ExtensionAPI } from 'shortcutxl';
13
- import { DoomOverlayComponent } from './doom-component.js';
14
- import { DoomEngine } from './doom-engine.js';
15
- import { ensureWadFile } from './wad-finder.js';
16
-
17
- // Persistent engine instance - survives between invocations
18
- let activeEngine: DoomEngine | null = null;
19
- let activeWadPath: string | null = null;
20
-
21
- export default function (shortcut: ExtensionAPI) {
22
- shortcut.registerCommand('doom-overlay', {
23
- description: 'Play DOOM as an overlay. Q to pause and exit.',
24
-
25
- handler: async (args, ctx) => {
26
- if (!ctx.hasUI) {
27
- ctx.ui.notify('DOOM requires interactive mode', 'error');
28
- return;
29
- }
30
-
31
- // Auto-download WAD if not present
32
- ctx.ui.notify('Loading DOOM...', 'info');
33
- const wad = args?.trim() ? args.trim() : await ensureWadFile();
34
-
35
- if (!wad) {
36
- ctx.ui.notify('Failed to download DOOM WAD file. Check your internet connection.', 'error');
37
- return;
38
- }
39
-
40
- try {
41
- // Reuse existing engine if same WAD, otherwise create new
42
- let isResume = false;
43
- if (activeEngine && activeWadPath === wad) {
44
- ctx.ui.notify('Resuming DOOM...', 'info');
45
- isResume = true;
46
- } else {
47
- ctx.ui.notify(`Loading DOOM from ${wad}...`, 'info');
48
- activeEngine = new DoomEngine(wad);
49
- await activeEngine.init();
50
- activeWadPath = wad;
51
- }
52
-
53
- await ctx.ui.custom(
54
- (tui, _theme, _keybindings, done) => {
55
- return new DoomOverlayComponent(tui, activeEngine!, () => done(undefined), isResume);
56
- },
57
- {
58
- overlay: true,
59
- overlayOptions: {
60
- width: '75%',
61
- maxHeight: '95%',
62
- anchor: 'center',
63
- margin: { top: 1 }
64
- }
65
- }
66
- );
67
- } catch (error) {
68
- ctx.ui.notify(`Failed to load DOOM: ${error}`, 'error');
69
- activeEngine = null;
70
- activeWadPath = null;
71
- }
72
- }
73
- });
74
- }
1
+ /**
2
+ * DOOM Overlay Demo - Play DOOM as an overlay
3
+ *
4
+ * Usage: shortcut --extension ./examples/extensions/doom-overlay
5
+ *
6
+ * Commands:
7
+ * /doom-overlay - Play DOOM in an overlay (Q to pause/exit)
8
+ *
9
+ * This demonstrates that overlays can handle real-time game rendering at 35 FPS.
10
+ */
11
+
12
+ import type { ExtensionAPI } from 'shortcutxl';
13
+ import { DoomOverlayComponent } from './doom-component.js';
14
+ import { DoomEngine } from './doom-engine.js';
15
+ import { ensureWadFile } from './wad-finder.js';
16
+
17
+ // Persistent engine instance - survives between invocations
18
+ let activeEngine: DoomEngine | null = null;
19
+ let activeWadPath: string | null = null;
20
+
21
+ export default function (shortcut: ExtensionAPI) {
22
+ shortcut.registerCommand('doom-overlay', {
23
+ description: 'Play DOOM as an overlay. Q to pause and exit.',
24
+
25
+ handler: async (args, ctx) => {
26
+ if (!ctx.hasUI) {
27
+ ctx.ui.notify('DOOM requires interactive mode', 'error');
28
+ return;
29
+ }
30
+
31
+ // Auto-download WAD if not present
32
+ ctx.ui.notify('Loading DOOM...', 'info');
33
+ const wad = args?.trim() ? args.trim() : await ensureWadFile();
34
+
35
+ if (!wad) {
36
+ ctx.ui.notify('Failed to download DOOM WAD file. Check your internet connection.', 'error');
37
+ return;
38
+ }
39
+
40
+ try {
41
+ // Reuse existing engine if same WAD, otherwise create new
42
+ let isResume = false;
43
+ if (activeEngine && activeWadPath === wad) {
44
+ ctx.ui.notify('Resuming DOOM...', 'info');
45
+ isResume = true;
46
+ } else {
47
+ ctx.ui.notify(`Loading DOOM from ${wad}...`, 'info');
48
+ activeEngine = new DoomEngine(wad);
49
+ await activeEngine.init();
50
+ activeWadPath = wad;
51
+ }
52
+
53
+ await ctx.ui.custom(
54
+ (tui, _theme, _keybindings, done) => {
55
+ return new DoomOverlayComponent(tui, activeEngine!, () => done(undefined), isResume);
56
+ },
57
+ {
58
+ overlay: true,
59
+ overlayOptions: {
60
+ width: '75%',
61
+ maxHeight: '95%',
62
+ anchor: 'center',
63
+ margin: { top: 1 }
64
+ }
65
+ }
66
+ );
67
+ } catch (error) {
68
+ ctx.ui.notify(`Failed to load DOOM: ${error}`, 'error');
69
+ activeEngine = null;
70
+ activeWadPath = null;
71
+ }
72
+ }
73
+ });
74
+ }
@@ -1,15 +1,15 @@
1
- import { dirname, join } from 'node:path';
2
- import { fileURLToPath } from 'node:url';
3
- import type { ExtensionAPI } from 'shortcutxl';
4
-
5
- const baseDir = dirname(fileURLToPath(import.meta.url));
6
-
7
- export default function (shortcut: ExtensionAPI) {
8
- shortcut.on('resources_discover', () => {
9
- return {
10
- skillPaths: [join(baseDir, 'SKILL.md')],
11
- promptPaths: [join(baseDir, 'dynamic.md')],
12
- themePaths: [join(baseDir, 'dynamic.json')]
13
- };
14
- });
15
- }
1
+ import { dirname, join } from 'node:path';
2
+ import { fileURLToPath } from 'node:url';
3
+ import type { ExtensionAPI } from 'shortcutxl';
4
+
5
+ const baseDir = dirname(fileURLToPath(import.meta.url));
6
+
7
+ export default function (shortcut: ExtensionAPI) {
8
+ shortcut.on('resources_discover', () => {
9
+ return {
10
+ skillPaths: [join(baseDir, 'SKILL.md')],
11
+ promptPaths: [join(baseDir, 'dynamic.md')],
12
+ themePaths: [join(baseDir, 'dynamic.json')]
13
+ };
14
+ });
15
+ }
@@ -1,77 +1,77 @@
1
- /**
2
- * Dynamic Tools Extension
3
- *
4
- * Demonstrates registering tools after session initialization.
5
- *
6
- * - Registers one tool during session_start
7
- * - Registers additional tools at runtime via /add-echo-tool <name>
8
- */
9
-
10
- import { Type } from '@sinclair/typebox';
11
- import type { ExtensionAPI } from 'shortcutxl';
12
-
13
- const ECHO_PARAMS = Type.Object({
14
- message: Type.String({ description: 'Message to echo' })
15
- });
16
-
17
- function normalizeToolName(input: string): string | undefined {
18
- const trimmed = input.trim().toLowerCase();
19
- if (!trimmed) return undefined;
20
- if (!/^[a-z0-9_]+$/.test(trimmed)) return undefined;
21
- return trimmed;
22
- }
23
-
24
- export default function dynamicToolsExtension(shortcut: ExtensionAPI) {
25
- const registeredToolNames = new Set<string>();
26
-
27
- const registerEchoTool = (name: string, label: string, prefix: string): boolean => {
28
- if (registeredToolNames.has(name)) {
29
- return false;
30
- }
31
-
32
- registeredToolNames.add(name);
33
- shortcut.registerTool({
34
- name,
35
- label,
36
- description: `Echo a message with prefix: ${prefix}`,
37
- promptSnippet: `Echo back user-provided text with ${prefix.trim()} prefix`,
38
- promptGuidelines: ['Use this tool when the user asks for exact echo output.'],
39
- parameters: ECHO_PARAMS,
40
- async execute(_toolCallId, params) {
41
- return {
42
- content: [{ type: 'text', text: `${prefix}${params.message}` }],
43
- details: { tool: name, prefix }
44
- };
45
- }
46
- });
47
-
48
- return true;
49
- };
50
-
51
- shortcut.on('session_start', (_event, ctx) => {
52
- registerEchoTool('echo_session', 'Echo Session', '[session] ');
53
- ctx.ui.notify('Registered dynamic tool: echo_session', 'info');
54
- });
55
-
56
- shortcut.registerCommand('add-echo-tool', {
57
- description: 'Register a new echo tool dynamically: /add-echo-tool <tool_name>',
58
- handler: async (args, ctx) => {
59
- const toolName = normalizeToolName(args);
60
- if (!toolName) {
61
- ctx.ui.notify(
62
- 'Usage: /add-echo-tool <tool_name> (lowercase, numbers, underscores)',
63
- 'warning'
64
- );
65
- return;
66
- }
67
-
68
- const created = registerEchoTool(toolName, `Echo ${toolName}`, `[${toolName}] `);
69
- if (!created) {
70
- ctx.ui.notify(`Tool already registered: ${toolName}`, 'warning');
71
- return;
72
- }
73
-
74
- ctx.ui.notify(`Registered dynamic tool: ${toolName}`, 'info');
75
- }
76
- });
77
- }
1
+ /**
2
+ * Dynamic Tools Extension
3
+ *
4
+ * Demonstrates registering tools after session initialization.
5
+ *
6
+ * - Registers one tool during session_start
7
+ * - Registers additional tools at runtime via /add-echo-tool <name>
8
+ */
9
+
10
+ import { Type } from '@sinclair/typebox';
11
+ import type { ExtensionAPI } from 'shortcutxl';
12
+
13
+ const ECHO_PARAMS = Type.Object({
14
+ message: Type.String({ description: 'Message to echo' })
15
+ });
16
+
17
+ function normalizeToolName(input: string): string | undefined {
18
+ const trimmed = input.trim().toLowerCase();
19
+ if (!trimmed) return undefined;
20
+ if (!/^[a-z0-9_]+$/.test(trimmed)) return undefined;
21
+ return trimmed;
22
+ }
23
+
24
+ export default function dynamicToolsExtension(shortcut: ExtensionAPI) {
25
+ const registeredToolNames = new Set<string>();
26
+
27
+ const registerEchoTool = (name: string, label: string, prefix: string): boolean => {
28
+ if (registeredToolNames.has(name)) {
29
+ return false;
30
+ }
31
+
32
+ registeredToolNames.add(name);
33
+ shortcut.registerTool({
34
+ name,
35
+ label,
36
+ description: `Echo a message with prefix: ${prefix}`,
37
+ promptSnippet: `Echo back user-provided text with ${prefix.trim()} prefix`,
38
+ promptGuidelines: ['Use this tool when the user asks for exact echo output.'],
39
+ parameters: ECHO_PARAMS,
40
+ async execute(_toolCallId, params) {
41
+ return {
42
+ content: [{ type: 'text', text: `${prefix}${params.message}` }],
43
+ details: { tool: name, prefix }
44
+ };
45
+ }
46
+ });
47
+
48
+ return true;
49
+ };
50
+
51
+ shortcut.on('session_start', (_event, ctx) => {
52
+ registerEchoTool('echo_session', 'Echo Session', '[session] ');
53
+ ctx.ui.notify('Registered dynamic tool: echo_session', 'info');
54
+ });
55
+
56
+ shortcut.registerCommand('add-echo-tool', {
57
+ description: 'Register a new echo tool dynamically: /add-echo-tool <tool_name>',
58
+ handler: async (args, ctx) => {
59
+ const toolName = normalizeToolName(args);
60
+ if (!toolName) {
61
+ ctx.ui.notify(
62
+ 'Usage: /add-echo-tool <tool_name> (lowercase, numbers, underscores)',
63
+ 'warning'
64
+ );
65
+ return;
66
+ }
67
+
68
+ const created = registerEchoTool(toolName, `Echo ${toolName}`, `[${toolName}] `);
69
+ if (!created) {
70
+ ctx.ui.notify(`Tool already registered: ${toolName}`, 'warning');
71
+ return;
72
+ }
73
+
74
+ ctx.ui.notify(`Registered dynamic tool: ${toolName}`, 'info');
75
+ }
76
+ });
77
+ }
@@ -1,43 +1,43 @@
1
- /**
2
- * Inter-extension event bus example.
3
- *
4
- * Shows shortcut.events for communication between extensions. One extension
5
- * can emit events that other extensions listen to.
6
- *
7
- * Usage: /emit [event-name] [data] - emit an event on the bus
8
- */
9
-
10
- import type { ExtensionAPI, ExtensionContext } from 'shortcutxl';
11
-
12
- export default function (shortcut: ExtensionAPI) {
13
- // Store ctx for use in event handler
14
- let currentCtx: ExtensionContext | undefined;
15
-
16
- shortcut.on('session_start', async (_event, ctx) => {
17
- currentCtx = ctx;
18
- });
19
-
20
- // Listen for events from other extensions
21
- shortcut.events.on('my:notification', (data) => {
22
- const { message, from } = data as { message: string; from: string };
23
- currentCtx?.ui.notify(`Event from ${from}: ${message}`, 'info');
24
- });
25
-
26
- // Command to emit events (emits "my:notification" which the listener above receives)
27
- shortcut.registerCommand('emit', {
28
- description: 'Emit my:notification event (usage: /emit message)',
29
- handler: async (args, _ctx) => {
30
- const message = args.trim() || 'hello';
31
- shortcut.events.emit('my:notification', { message, from: '/emit command' });
32
- // Listener above will show the notification
33
- }
34
- });
35
-
36
- // Example: emit on session start
37
- shortcut.on('session_start', async () => {
38
- shortcut.events.emit('my:notification', {
39
- message: 'Session started',
40
- from: 'event-bus-example'
41
- });
42
- });
43
- }
1
+ /**
2
+ * Inter-extension event bus example.
3
+ *
4
+ * Shows shortcut.events for communication between extensions. One extension
5
+ * can emit events that other extensions listen to.
6
+ *
7
+ * Usage: /emit [event-name] [data] - emit an event on the bus
8
+ */
9
+
10
+ import type { ExtensionAPI, ExtensionContext } from 'shortcutxl';
11
+
12
+ export default function (shortcut: ExtensionAPI) {
13
+ // Store ctx for use in event handler
14
+ let currentCtx: ExtensionContext | undefined;
15
+
16
+ shortcut.on('session_start', async (_event, ctx) => {
17
+ currentCtx = ctx;
18
+ });
19
+
20
+ // Listen for events from other extensions
21
+ shortcut.events.on('my:notification', (data) => {
22
+ const { message, from } = data as { message: string; from: string };
23
+ currentCtx?.ui.notify(`Event from ${from}: ${message}`, 'info');
24
+ });
25
+
26
+ // Command to emit events (emits "my:notification" which the listener above receives)
27
+ shortcut.registerCommand('emit', {
28
+ description: 'Emit my:notification event (usage: /emit message)',
29
+ handler: async (args, _ctx) => {
30
+ const message = args.trim() || 'hello';
31
+ shortcut.events.emit('my:notification', { message, from: '/emit command' });
32
+ // Listener above will show the notification
33
+ }
34
+ });
35
+
36
+ // Example: emit on session start
37
+ shortcut.on('session_start', async () => {
38
+ shortcut.events.emit('my:notification', {
39
+ message: 'Session started',
40
+ from: 'event-bus-example'
41
+ });
42
+ });
43
+ }
@@ -1,41 +1,41 @@
1
- /**
2
- * File Trigger Extension
3
- *
4
- * Watches a trigger file and injects its contents into the conversation.
5
- * Useful for external systems to send messages to the agent.
6
- *
7
- * Usage:
8
- * echo "Run the tests" > /tmp/agent-trigger.txt
9
- */
10
-
11
- import * as fs from 'node:fs';
12
- import type { ExtensionAPI } from 'shortcutxl';
13
-
14
- export default function (shortcut: ExtensionAPI) {
15
- shortcut.on('session_start', async (_event, ctx) => {
16
- const triggerFile = '/tmp/agent-trigger.txt';
17
-
18
- fs.watch(triggerFile, () => {
19
- try {
20
- const content = fs.readFileSync(triggerFile, 'utf-8').trim();
21
- if (content) {
22
- shortcut.sendMessage(
23
- {
24
- customType: 'file-trigger',
25
- content: `External trigger: ${content}`,
26
- display: true
27
- },
28
- { triggerTurn: true } // triggerTurn - get LLM to respond
29
- );
30
- fs.writeFileSync(triggerFile, ''); // Clear after reading
31
- }
32
- } catch {
33
- // File might not exist yet
34
- }
35
- });
36
-
37
- if (ctx.hasUI) {
38
- ctx.ui.notify(`Watching ${triggerFile}`, 'info');
39
- }
40
- });
41
- }
1
+ /**
2
+ * File Trigger Extension
3
+ *
4
+ * Watches a trigger file and injects its contents into the conversation.
5
+ * Useful for external systems to send messages to the agent.
6
+ *
7
+ * Usage:
8
+ * echo "Run the tests" > /tmp/agent-trigger.txt
9
+ */
10
+
11
+ import * as fs from 'node:fs';
12
+ import type { ExtensionAPI } from 'shortcutxl';
13
+
14
+ export default function (shortcut: ExtensionAPI) {
15
+ shortcut.on('session_start', async (_event, ctx) => {
16
+ const triggerFile = '/tmp/agent-trigger.txt';
17
+
18
+ fs.watch(triggerFile, () => {
19
+ try {
20
+ const content = fs.readFileSync(triggerFile, 'utf-8').trim();
21
+ if (content) {
22
+ shortcut.sendMessage(
23
+ {
24
+ customType: 'file-trigger',
25
+ content: `External trigger: ${content}`,
26
+ display: true
27
+ },
28
+ { triggerTurn: true } // triggerTurn - get LLM to respond
29
+ );
30
+ fs.writeFileSync(triggerFile, ''); // Clear after reading
31
+ }
32
+ } catch {
33
+ // File might not exist yet
34
+ }
35
+ });
36
+
37
+ if (ctx.hasUI) {
38
+ ctx.ui.notify(`Watching ${triggerFile}`, 'info');
39
+ }
40
+ });
41
+ }
@@ -1,53 +1,53 @@
1
- /**
2
- * Git Checkpoint Extension
3
- *
4
- * Creates git stash checkpoints at each turn so /fork can restore code state.
5
- * When forking, offers to restore code to that point in history.
6
- */
7
-
8
- import type { ExtensionAPI } from 'shortcutxl';
9
-
10
- export default function (shortcut: ExtensionAPI) {
11
- const checkpoints = new Map<string, string>();
12
- let currentEntryId: string | undefined;
13
-
14
- // Track the current entry ID when user messages are saved
15
- shortcut.on('tool_result', async (_event, ctx) => {
16
- const leaf = ctx.sessionManager.getLeafEntry();
17
- if (leaf) currentEntryId = leaf.id;
18
- });
19
-
20
- shortcut.on('turn_start', async () => {
21
- // Create a git stash entry before LLM makes changes
22
- const { stdout } = await shortcut.exec('git', ['stash', 'create']);
23
- const ref = stdout.trim();
24
- if (ref && currentEntryId) {
25
- checkpoints.set(currentEntryId, ref);
26
- }
27
- });
28
-
29
- shortcut.on('session_before_fork', async (event, ctx) => {
30
- const ref = checkpoints.get(event.entryId);
31
- if (!ref) return;
32
-
33
- if (!ctx.hasUI) {
34
- // In non-interactive mode, don't restore automatically
35
- return;
36
- }
37
-
38
- const choice = await ctx.ui.select('Restore code state?', [
39
- 'Yes, restore code to that point',
40
- 'No, keep current code'
41
- ]);
42
-
43
- if (choice?.startsWith('Yes')) {
44
- await shortcut.exec('git', ['stash', 'apply', ref]);
45
- ctx.ui.notify('Code restored to checkpoint', 'info');
46
- }
47
- });
48
-
49
- shortcut.on('agent_end', async () => {
50
- // Clear checkpoints after agent completes
51
- checkpoints.clear();
52
- });
53
- }
1
+ /**
2
+ * Git Checkpoint Extension
3
+ *
4
+ * Creates git stash checkpoints at each turn so /fork can restore code state.
5
+ * When forking, offers to restore code to that point in history.
6
+ */
7
+
8
+ import type { ExtensionAPI } from 'shortcutxl';
9
+
10
+ export default function (shortcut: ExtensionAPI) {
11
+ const checkpoints = new Map<string, string>();
12
+ let currentEntryId: string | undefined;
13
+
14
+ // Track the current entry ID when user messages are saved
15
+ shortcut.on('tool_result', async (_event, ctx) => {
16
+ const leaf = ctx.sessionManager.getLeafEntry();
17
+ if (leaf) currentEntryId = leaf.id;
18
+ });
19
+
20
+ shortcut.on('turn_start', async () => {
21
+ // Create a git stash entry before LLM makes changes
22
+ const { stdout } = await shortcut.exec('git', ['stash', 'create']);
23
+ const ref = stdout.trim();
24
+ if (ref && currentEntryId) {
25
+ checkpoints.set(currentEntryId, ref);
26
+ }
27
+ });
28
+
29
+ shortcut.on('session_before_fork', async (event, ctx) => {
30
+ const ref = checkpoints.get(event.entryId);
31
+ if (!ref) return;
32
+
33
+ if (!ctx.hasUI) {
34
+ // In non-interactive mode, don't restore automatically
35
+ return;
36
+ }
37
+
38
+ const choice = await ctx.ui.select('Restore code state?', [
39
+ 'Yes, restore code to that point',
40
+ 'No, keep current code'
41
+ ]);
42
+
43
+ if (choice?.startsWith('Yes')) {
44
+ await shortcut.exec('git', ['stash', 'apply', ref]);
45
+ ctx.ui.notify('Code restored to checkpoint', 'info');
46
+ }
47
+ });
48
+
49
+ shortcut.on('agent_end', async () => {
50
+ // Clear checkpoints after agent completes
51
+ checkpoints.clear();
52
+ });
53
+ }