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.
- package/README.md +26 -26
- package/agent-docs/README.md +397 -397
- package/agent-docs/docs/compaction.md +390 -390
- package/agent-docs/docs/custom-provider.md +580 -580
- package/agent-docs/docs/extensions.md +1971 -1971
- package/agent-docs/docs/packages.md +209 -209
- package/agent-docs/docs/rpc.md +1317 -1317
- package/agent-docs/docs/sdk.md +962 -962
- package/agent-docs/docs/session.md +412 -412
- package/agent-docs/docs/termux.md +127 -127
- package/agent-docs/docs/tui.md +887 -887
- package/agent-docs/examples/README.md +25 -25
- package/agent-docs/examples/extensions/README.md +205 -205
- package/agent-docs/examples/extensions/antigravity-image-gen.ts +447 -447
- package/agent-docs/examples/extensions/auto-commit-on-exit.ts +49 -49
- package/agent-docs/examples/extensions/bash-spawn-hook.ts +30 -30
- package/agent-docs/examples/extensions/bookmark.ts +50 -50
- package/agent-docs/examples/extensions/built-in-tool-renderer.ts +256 -256
- package/agent-docs/examples/extensions/claude-rules.ts +86 -86
- package/agent-docs/examples/extensions/commands.ts +75 -75
- package/agent-docs/examples/extensions/confirm-destructive.ts +59 -59
- package/agent-docs/examples/extensions/custom-compaction.ts +126 -126
- package/agent-docs/examples/extensions/custom-footer.ts +63 -63
- package/agent-docs/examples/extensions/custom-header.ts +73 -73
- package/agent-docs/examples/extensions/custom-provider-anthropic/index.ts +660 -660
- package/agent-docs/examples/extensions/custom-provider-gitlab-duo/index.ts +362 -362
- package/agent-docs/examples/extensions/custom-provider-gitlab-duo/test.ts +88 -88
- package/agent-docs/examples/extensions/custom-provider-qwen-cli/index.ts +349 -349
- package/agent-docs/examples/extensions/dirty-repo-guard.ts +56 -56
- package/agent-docs/examples/extensions/doom-overlay/doom-component.ts +133 -133
- package/agent-docs/examples/extensions/doom-overlay/doom-keys.ts +108 -108
- package/agent-docs/examples/extensions/doom-overlay/index.ts +74 -74
- package/agent-docs/examples/extensions/dynamic-resources/index.ts +15 -15
- package/agent-docs/examples/extensions/dynamic-tools.ts +77 -77
- package/agent-docs/examples/extensions/event-bus.ts +43 -43
- package/agent-docs/examples/extensions/file-trigger.ts +41 -41
- package/agent-docs/examples/extensions/git-checkpoint.ts +53 -53
- package/agent-docs/examples/extensions/handoff.ts +155 -155
- package/agent-docs/examples/extensions/hello.ts +25 -25
- package/agent-docs/examples/extensions/inline-bash.ts +94 -94
- package/agent-docs/examples/extensions/input-transform.ts +43 -43
- package/agent-docs/examples/extensions/interactive-shell.ts +209 -209
- package/agent-docs/examples/extensions/mac-system-theme.ts +47 -47
- package/agent-docs/examples/extensions/message-renderer.ts +59 -59
- package/agent-docs/examples/extensions/minimal-mode.ts +430 -430
- package/agent-docs/examples/extensions/modal-editor.ts +90 -90
- package/agent-docs/examples/extensions/model-status.ts +31 -31
- package/agent-docs/examples/extensions/notify.ts +55 -55
- package/agent-docs/examples/extensions/overlay-qa-tests.ts +936 -936
- package/agent-docs/examples/extensions/overlay-test.ts +159 -159
- package/agent-docs/examples/extensions/permission-gate.ts +37 -37
- package/agent-docs/examples/extensions/pirate.ts +47 -47
- package/agent-docs/examples/extensions/plan-mode/index.ts +363 -363
- package/agent-docs/examples/extensions/preset.ts +418 -418
- package/agent-docs/examples/extensions/protected-paths.ts +30 -30
- package/agent-docs/examples/extensions/qna.ts +122 -122
- package/agent-docs/examples/extensions/question.ts +278 -278
- package/agent-docs/examples/extensions/questionnaire.ts +440 -440
- package/agent-docs/examples/extensions/rainbow-editor.ts +90 -90
- package/agent-docs/examples/extensions/reload-runtime.ts +37 -37
- package/agent-docs/examples/extensions/rpc-demo.ts +124 -124
- package/agent-docs/examples/extensions/sandbox/index.ts +324 -324
- package/agent-docs/examples/extensions/send-user-message.ts +97 -97
- package/agent-docs/examples/extensions/session-name.ts +27 -27
- package/agent-docs/examples/extensions/shutdown-command.ts +69 -69
- package/agent-docs/examples/extensions/snake.ts +343 -343
- package/agent-docs/examples/extensions/space-invaders.ts +566 -566
- package/agent-docs/examples/extensions/ssh.ts +233 -233
- package/agent-docs/examples/extensions/status-line.ts +40 -40
- package/agent-docs/examples/extensions/subagent/agents.ts +130 -130
- package/agent-docs/examples/extensions/subagent/index.ts +1068 -1068
- package/agent-docs/examples/extensions/summarize.ts +206 -206
- package/agent-docs/examples/extensions/system-prompt-header.ts +17 -17
- package/agent-docs/examples/extensions/timed-confirm.ts +72 -72
- package/agent-docs/examples/extensions/titlebar-spinner.ts +58 -58
- package/agent-docs/examples/extensions/todo.ts +314 -314
- package/agent-docs/examples/extensions/tool-override.ts +146 -146
- package/agent-docs/examples/extensions/tools.ts +145 -145
- package/agent-docs/examples/extensions/trigger-compact.ts +40 -40
- package/agent-docs/examples/extensions/truncated-tool.ts +194 -194
- package/agent-docs/examples/extensions/widget-placement.ts +17 -17
- package/agent-docs/examples/extensions/with-deps/index.ts +37 -37
- package/agent-docs/examples/rpc-extension-ui.ts +654 -654
- package/agent-docs/examples/sdk/01-minimal.ts +22 -22
- package/agent-docs/examples/sdk/02-custom-model.ts +48 -48
- package/agent-docs/examples/sdk/03-custom-prompt.ts +55 -55
- package/agent-docs/examples/sdk/04-skills.ts +53 -53
- package/agent-docs/examples/sdk/05-tools.ts +56 -56
- package/agent-docs/examples/sdk/06-extensions.ts +88 -88
- package/agent-docs/examples/sdk/07-context-files.ts +40 -40
- package/agent-docs/examples/sdk/08-prompt-templates.ts +47 -47
- package/agent-docs/examples/sdk/09-api-keys-and-oauth.ts +48 -48
- package/agent-docs/examples/sdk/10-settings.ts +54 -54
- package/agent-docs/examples/sdk/11-sessions.ts +48 -48
- package/agent-docs/examples/sdk/12-full-control.ts +82 -82
- package/agent-docs/examples/sdk/README.md +144 -144
- package/agent-docs/xll-spec.md +110 -110
- package/dist/core/auth-storage.js +21 -2
- package/package.json +1 -1
- package/xll/ShortcutXL.xll +0 -0
- package/xll/modules/debug_render.py +272 -272
- package/xll/modules/gameboy.py +241 -241
- package/xll/modules/pong.py +188 -188
- package/xll/modules/shortcut_xl/_diff_highlight.py +176 -0
- package/xll/modules/shortcut_xl/_log.py +12 -12
- package/xll/modules/shortcut_xl/_registry.py +44 -44
- package/xll/modules/stocks.py +100 -100
- /package/skills/{com-advanced-api → COM-advanced-api}/SKILL.md +0 -0
- /package/skills/{com-advanced-api → COM-advanced-api}/excel-type-library.py +0 -0
- /package/skills/{com-advanced-api → COM-advanced-api}/office-type-library.py +0 -0
|
@@ -1,97 +1,97 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Send User Message Example
|
|
3
|
-
*
|
|
4
|
-
* Demonstrates shortcut.sendUserMessage() for sending user messages from extensions.
|
|
5
|
-
* Unlike shortcut.sendMessage() which sends custom messages, sendUserMessage() sends
|
|
6
|
-
* actual user messages that appear in the conversation as if typed by the user.
|
|
7
|
-
*
|
|
8
|
-
* Usage:
|
|
9
|
-
* /ask What is 2+2? - Sends a user message (always triggers a turn)
|
|
10
|
-
* /steer Focus on X - Sends while streaming with steer delivery
|
|
11
|
-
* /followup And then? - Sends while streaming with followUp delivery
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
import type { ExtensionAPI } from 'shortcutxl';
|
|
15
|
-
|
|
16
|
-
export default function (shortcut: ExtensionAPI) {
|
|
17
|
-
// Simple command that sends a user message
|
|
18
|
-
shortcut.registerCommand('ask', {
|
|
19
|
-
description: 'Send a user message to the agent',
|
|
20
|
-
handler: async (args, ctx) => {
|
|
21
|
-
if (!args.trim()) {
|
|
22
|
-
ctx.ui.notify('Usage: /ask <message>', 'warning');
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// sendUserMessage always triggers a turn when not streaming
|
|
27
|
-
// If streaming, it will throw (no deliverAs specified)
|
|
28
|
-
if (!ctx.isIdle()) {
|
|
29
|
-
ctx.ui.notify('Agent is busy. Use /steer or /followup instead.', 'warning');
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
shortcut.sendUserMessage(args);
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
// Command that steers the agent mid-conversation
|
|
38
|
-
shortcut.registerCommand('steer', {
|
|
39
|
-
description: 'Send a steering message (interrupts current processing)',
|
|
40
|
-
handler: async (args, ctx) => {
|
|
41
|
-
if (!args.trim()) {
|
|
42
|
-
ctx.ui.notify('Usage: /steer <message>', 'warning');
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
if (ctx.isIdle()) {
|
|
47
|
-
// Not streaming, just send normally
|
|
48
|
-
shortcut.sendUserMessage(args);
|
|
49
|
-
} else {
|
|
50
|
-
// Streaming - use steer to interrupt
|
|
51
|
-
shortcut.sendUserMessage(args, { deliverAs: 'steer' });
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
// Command that queues a follow-up message
|
|
57
|
-
shortcut.registerCommand('followup', {
|
|
58
|
-
description: 'Queue a follow-up message (waits for current processing)',
|
|
59
|
-
handler: async (args, ctx) => {
|
|
60
|
-
if (!args.trim()) {
|
|
61
|
-
ctx.ui.notify('Usage: /followup <message>', 'warning');
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
if (ctx.isIdle()) {
|
|
66
|
-
// Not streaming, just send normally
|
|
67
|
-
shortcut.sendUserMessage(args);
|
|
68
|
-
} else {
|
|
69
|
-
// Streaming - queue as follow-up
|
|
70
|
-
shortcut.sendUserMessage(args, { deliverAs: 'followUp' });
|
|
71
|
-
ctx.ui.notify('Follow-up queued', 'info');
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
// Example with content array (text + images would go here)
|
|
77
|
-
shortcut.registerCommand('askwith', {
|
|
78
|
-
description: 'Send a user message with structured content',
|
|
79
|
-
handler: async (args, ctx) => {
|
|
80
|
-
if (!args.trim()) {
|
|
81
|
-
ctx.ui.notify('Usage: /askwith <message>', 'warning');
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
if (!ctx.isIdle()) {
|
|
86
|
-
ctx.ui.notify('Agent is busy', 'warning');
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// sendUserMessage accepts string or (TextContent | ImageContent)[]
|
|
91
|
-
shortcut.sendUserMessage([
|
|
92
|
-
{ type: 'text', text: `User request: ${args}` },
|
|
93
|
-
{ type: 'text', text: 'Please respond concisely.' }
|
|
94
|
-
]);
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Send User Message Example
|
|
3
|
+
*
|
|
4
|
+
* Demonstrates shortcut.sendUserMessage() for sending user messages from extensions.
|
|
5
|
+
* Unlike shortcut.sendMessage() which sends custom messages, sendUserMessage() sends
|
|
6
|
+
* actual user messages that appear in the conversation as if typed by the user.
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* /ask What is 2+2? - Sends a user message (always triggers a turn)
|
|
10
|
+
* /steer Focus on X - Sends while streaming with steer delivery
|
|
11
|
+
* /followup And then? - Sends while streaming with followUp delivery
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import type { ExtensionAPI } from 'shortcutxl';
|
|
15
|
+
|
|
16
|
+
export default function (shortcut: ExtensionAPI) {
|
|
17
|
+
// Simple command that sends a user message
|
|
18
|
+
shortcut.registerCommand('ask', {
|
|
19
|
+
description: 'Send a user message to the agent',
|
|
20
|
+
handler: async (args, ctx) => {
|
|
21
|
+
if (!args.trim()) {
|
|
22
|
+
ctx.ui.notify('Usage: /ask <message>', 'warning');
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// sendUserMessage always triggers a turn when not streaming
|
|
27
|
+
// If streaming, it will throw (no deliverAs specified)
|
|
28
|
+
if (!ctx.isIdle()) {
|
|
29
|
+
ctx.ui.notify('Agent is busy. Use /steer or /followup instead.', 'warning');
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
shortcut.sendUserMessage(args);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
// Command that steers the agent mid-conversation
|
|
38
|
+
shortcut.registerCommand('steer', {
|
|
39
|
+
description: 'Send a steering message (interrupts current processing)',
|
|
40
|
+
handler: async (args, ctx) => {
|
|
41
|
+
if (!args.trim()) {
|
|
42
|
+
ctx.ui.notify('Usage: /steer <message>', 'warning');
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (ctx.isIdle()) {
|
|
47
|
+
// Not streaming, just send normally
|
|
48
|
+
shortcut.sendUserMessage(args);
|
|
49
|
+
} else {
|
|
50
|
+
// Streaming - use steer to interrupt
|
|
51
|
+
shortcut.sendUserMessage(args, { deliverAs: 'steer' });
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
// Command that queues a follow-up message
|
|
57
|
+
shortcut.registerCommand('followup', {
|
|
58
|
+
description: 'Queue a follow-up message (waits for current processing)',
|
|
59
|
+
handler: async (args, ctx) => {
|
|
60
|
+
if (!args.trim()) {
|
|
61
|
+
ctx.ui.notify('Usage: /followup <message>', 'warning');
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (ctx.isIdle()) {
|
|
66
|
+
// Not streaming, just send normally
|
|
67
|
+
shortcut.sendUserMessage(args);
|
|
68
|
+
} else {
|
|
69
|
+
// Streaming - queue as follow-up
|
|
70
|
+
shortcut.sendUserMessage(args, { deliverAs: 'followUp' });
|
|
71
|
+
ctx.ui.notify('Follow-up queued', 'info');
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
// Example with content array (text + images would go here)
|
|
77
|
+
shortcut.registerCommand('askwith', {
|
|
78
|
+
description: 'Send a user message with structured content',
|
|
79
|
+
handler: async (args, ctx) => {
|
|
80
|
+
if (!args.trim()) {
|
|
81
|
+
ctx.ui.notify('Usage: /askwith <message>', 'warning');
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (!ctx.isIdle()) {
|
|
86
|
+
ctx.ui.notify('Agent is busy', 'warning');
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// sendUserMessage accepts string or (TextContent | ImageContent)[]
|
|
91
|
+
shortcut.sendUserMessage([
|
|
92
|
+
{ type: 'text', text: `User request: ${args}` },
|
|
93
|
+
{ type: 'text', text: 'Please respond concisely.' }
|
|
94
|
+
]);
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
}
|
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Session naming example.
|
|
3
|
-
*
|
|
4
|
-
* Shows setSessionName/getSessionName to give sessions friendly names
|
|
5
|
-
* that appear in the session selector instead of the first message.
|
|
6
|
-
*
|
|
7
|
-
* Usage: /session-name [name] - set or show session name
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import type { ExtensionAPI } from 'shortcutxl';
|
|
11
|
-
|
|
12
|
-
export default function (shortcut: ExtensionAPI) {
|
|
13
|
-
shortcut.registerCommand('session-name', {
|
|
14
|
-
description: 'Set or show session name (usage: /session-name [new name])',
|
|
15
|
-
handler: async (args, ctx) => {
|
|
16
|
-
const name = args.trim();
|
|
17
|
-
|
|
18
|
-
if (name) {
|
|
19
|
-
shortcut.setSessionName(name);
|
|
20
|
-
ctx.ui.notify(`Session named: ${name}`, 'info');
|
|
21
|
-
} else {
|
|
22
|
-
const current = shortcut.getSessionName();
|
|
23
|
-
ctx.ui.notify(current ? `Session: ${current}` : 'No session name set', 'info');
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Session naming example.
|
|
3
|
+
*
|
|
4
|
+
* Shows setSessionName/getSessionName to give sessions friendly names
|
|
5
|
+
* that appear in the session selector instead of the first message.
|
|
6
|
+
*
|
|
7
|
+
* Usage: /session-name [name] - set or show session name
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { ExtensionAPI } from 'shortcutxl';
|
|
11
|
+
|
|
12
|
+
export default function (shortcut: ExtensionAPI) {
|
|
13
|
+
shortcut.registerCommand('session-name', {
|
|
14
|
+
description: 'Set or show session name (usage: /session-name [new name])',
|
|
15
|
+
handler: async (args, ctx) => {
|
|
16
|
+
const name = args.trim();
|
|
17
|
+
|
|
18
|
+
if (name) {
|
|
19
|
+
shortcut.setSessionName(name);
|
|
20
|
+
ctx.ui.notify(`Session named: ${name}`, 'info');
|
|
21
|
+
} else {
|
|
22
|
+
const current = shortcut.getSessionName();
|
|
23
|
+
ctx.ui.notify(current ? `Session: ${current}` : 'No session name set', 'info');
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}
|
|
@@ -1,69 +1,69 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shutdown Command Extension
|
|
3
|
-
*
|
|
4
|
-
* Adds a /quit command that allows extensions to trigger clean shutdown.
|
|
5
|
-
* Demonstrates how extensions can use ctx.shutdown() to exit shortcut cleanly.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { Type } from '@sinclair/typebox';
|
|
9
|
-
import type { ExtensionAPI } from 'shortcutxl';
|
|
10
|
-
|
|
11
|
-
export default function (shortcut: ExtensionAPI) {
|
|
12
|
-
// Register a /quit command that cleanly exits shortcut
|
|
13
|
-
shortcut.registerCommand('quit', {
|
|
14
|
-
description: 'Exit shortcut cleanly',
|
|
15
|
-
handler: async (_args, ctx) => {
|
|
16
|
-
ctx.shutdown();
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
// You can also create a tool that shuts down after completing work
|
|
21
|
-
shortcut.registerTool({
|
|
22
|
-
name: 'finish_and_exit',
|
|
23
|
-
label: 'Finish and Exit',
|
|
24
|
-
description: 'Complete a task and exit shortcut',
|
|
25
|
-
parameters: Type.Object({}),
|
|
26
|
-
async execute(_toolCallId, _params, _signal, _onUpdate, ctx) {
|
|
27
|
-
// Do any final work here...
|
|
28
|
-
// Request graceful shutdown (deferred until agent is idle)
|
|
29
|
-
ctx.shutdown();
|
|
30
|
-
|
|
31
|
-
// This return is sent to the LLM before shutdown occurs
|
|
32
|
-
return {
|
|
33
|
-
content: [{ type: 'text', text: 'Shutdown requested. Exiting after this response.' }],
|
|
34
|
-
details: {}
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
// You could also create a more complex tool with parameters
|
|
40
|
-
shortcut.registerTool({
|
|
41
|
-
name: 'deploy_and_exit',
|
|
42
|
-
label: 'Deploy and Exit',
|
|
43
|
-
description: 'Deploy the application and exit shortcut',
|
|
44
|
-
parameters: Type.Object({
|
|
45
|
-
environment: Type.String({ description: 'Target environment (e.g., production, staging)' })
|
|
46
|
-
}),
|
|
47
|
-
async execute(_toolCallId, params, _signal, onUpdate, ctx) {
|
|
48
|
-
onUpdate?.({
|
|
49
|
-
content: [{ type: 'text', text: `Deploying to ${params.environment}...` }],
|
|
50
|
-
details: {}
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
// Example deployment logic
|
|
54
|
-
// const result = await shortcut.exec("npm", ["run", "deploy", params.environment], { signal });
|
|
55
|
-
|
|
56
|
-
// On success, request graceful shutdown
|
|
57
|
-
onUpdate?.({
|
|
58
|
-
content: [{ type: 'text', text: 'Deployment complete, exiting...' }],
|
|
59
|
-
details: {}
|
|
60
|
-
});
|
|
61
|
-
ctx.shutdown();
|
|
62
|
-
|
|
63
|
-
return {
|
|
64
|
-
content: [{ type: 'text', text: 'Done! Shutdown requested.' }],
|
|
65
|
-
details: { environment: params.environment }
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Shutdown Command Extension
|
|
3
|
+
*
|
|
4
|
+
* Adds a /quit command that allows extensions to trigger clean shutdown.
|
|
5
|
+
* Demonstrates how extensions can use ctx.shutdown() to exit shortcut cleanly.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { Type } from '@sinclair/typebox';
|
|
9
|
+
import type { ExtensionAPI } from 'shortcutxl';
|
|
10
|
+
|
|
11
|
+
export default function (shortcut: ExtensionAPI) {
|
|
12
|
+
// Register a /quit command that cleanly exits shortcut
|
|
13
|
+
shortcut.registerCommand('quit', {
|
|
14
|
+
description: 'Exit shortcut cleanly',
|
|
15
|
+
handler: async (_args, ctx) => {
|
|
16
|
+
ctx.shutdown();
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
// You can also create a tool that shuts down after completing work
|
|
21
|
+
shortcut.registerTool({
|
|
22
|
+
name: 'finish_and_exit',
|
|
23
|
+
label: 'Finish and Exit',
|
|
24
|
+
description: 'Complete a task and exit shortcut',
|
|
25
|
+
parameters: Type.Object({}),
|
|
26
|
+
async execute(_toolCallId, _params, _signal, _onUpdate, ctx) {
|
|
27
|
+
// Do any final work here...
|
|
28
|
+
// Request graceful shutdown (deferred until agent is idle)
|
|
29
|
+
ctx.shutdown();
|
|
30
|
+
|
|
31
|
+
// This return is sent to the LLM before shutdown occurs
|
|
32
|
+
return {
|
|
33
|
+
content: [{ type: 'text', text: 'Shutdown requested. Exiting after this response.' }],
|
|
34
|
+
details: {}
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
// You could also create a more complex tool with parameters
|
|
40
|
+
shortcut.registerTool({
|
|
41
|
+
name: 'deploy_and_exit',
|
|
42
|
+
label: 'Deploy and Exit',
|
|
43
|
+
description: 'Deploy the application and exit shortcut',
|
|
44
|
+
parameters: Type.Object({
|
|
45
|
+
environment: Type.String({ description: 'Target environment (e.g., production, staging)' })
|
|
46
|
+
}),
|
|
47
|
+
async execute(_toolCallId, params, _signal, onUpdate, ctx) {
|
|
48
|
+
onUpdate?.({
|
|
49
|
+
content: [{ type: 'text', text: `Deploying to ${params.environment}...` }],
|
|
50
|
+
details: {}
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
// Example deployment logic
|
|
54
|
+
// const result = await shortcut.exec("npm", ["run", "deploy", params.environment], { signal });
|
|
55
|
+
|
|
56
|
+
// On success, request graceful shutdown
|
|
57
|
+
onUpdate?.({
|
|
58
|
+
content: [{ type: 'text', text: 'Deployment complete, exiting...' }],
|
|
59
|
+
details: {}
|
|
60
|
+
});
|
|
61
|
+
ctx.shutdown();
|
|
62
|
+
|
|
63
|
+
return {
|
|
64
|
+
content: [{ type: 'text', text: 'Done! Shutdown requested.' }],
|
|
65
|
+
details: { environment: params.environment }
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|