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,25 +1,25 @@
|
|
|
1
|
-
# Examples
|
|
2
|
-
|
|
3
|
-
Example code for shortcutxl SDK and extensions.
|
|
4
|
-
|
|
5
|
-
## Directories
|
|
6
|
-
|
|
7
|
-
### [sdk/](sdk/)
|
|
8
|
-
Programmatic usage via `createAgentSession()`. Shows how to customize models, prompts, tools, extensions, and session management.
|
|
9
|
-
|
|
10
|
-
### [extensions/](extensions/)
|
|
11
|
-
Example extensions demonstrating:
|
|
12
|
-
- Lifecycle event handlers (tool interception, safety gates, context modifications)
|
|
13
|
-
- Custom tools (todo lists, questions, subagents, output truncation)
|
|
14
|
-
- Commands and keyboard shortcuts
|
|
15
|
-
- Custom UI (footers, headers, editors, overlays)
|
|
16
|
-
- Git integration (checkpoints, auto-commit)
|
|
17
|
-
- System prompt modifications and custom compaction
|
|
18
|
-
- External integrations (SSH, file watchers, system theme sync)
|
|
19
|
-
- Custom providers (Anthropic with custom streaming, GitLab Duo)
|
|
20
|
-
|
|
21
|
-
## Documentation
|
|
22
|
-
|
|
23
|
-
- [SDK Reference](sdk/README.md)
|
|
24
|
-
- [Extensions Documentation](../docs/extensions.md)
|
|
25
|
-
- [Skills Documentation](../docs/skills.md)
|
|
1
|
+
# Examples
|
|
2
|
+
|
|
3
|
+
Example code for shortcutxl SDK and extensions.
|
|
4
|
+
|
|
5
|
+
## Directories
|
|
6
|
+
|
|
7
|
+
### [sdk/](sdk/)
|
|
8
|
+
Programmatic usage via `createAgentSession()`. Shows how to customize models, prompts, tools, extensions, and session management.
|
|
9
|
+
|
|
10
|
+
### [extensions/](extensions/)
|
|
11
|
+
Example extensions demonstrating:
|
|
12
|
+
- Lifecycle event handlers (tool interception, safety gates, context modifications)
|
|
13
|
+
- Custom tools (todo lists, questions, subagents, output truncation)
|
|
14
|
+
- Commands and keyboard shortcuts
|
|
15
|
+
- Custom UI (footers, headers, editors, overlays)
|
|
16
|
+
- Git integration (checkpoints, auto-commit)
|
|
17
|
+
- System prompt modifications and custom compaction
|
|
18
|
+
- External integrations (SSH, file watchers, system theme sync)
|
|
19
|
+
- Custom providers (Anthropic with custom streaming, GitLab Duo)
|
|
20
|
+
|
|
21
|
+
## Documentation
|
|
22
|
+
|
|
23
|
+
- [SDK Reference](sdk/README.md)
|
|
24
|
+
- [Extensions Documentation](../docs/extensions.md)
|
|
25
|
+
- [Skills Documentation](../docs/skills.md)
|
|
@@ -1,205 +1,205 @@
|
|
|
1
|
-
# Extension Examples
|
|
2
|
-
|
|
3
|
-
Example extensions for shortcutxl.
|
|
4
|
-
|
|
5
|
-
## Usage
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
# Load an extension with --extension flag
|
|
9
|
-
shortcut --extension examples/extensions/permission-gate.ts
|
|
10
|
-
|
|
11
|
-
# Or copy to extensions directory for auto-discovery
|
|
12
|
-
cp permission-gate.ts ~/.shortcut/agent/extensions/
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
## Examples
|
|
16
|
-
|
|
17
|
-
### Lifecycle & Safety
|
|
18
|
-
|
|
19
|
-
| Extension | Description |
|
|
20
|
-
|-----------|-------------|
|
|
21
|
-
| `permission-gate.ts` | Prompts for confirmation before dangerous bash commands (rm -rf, sudo, etc.) |
|
|
22
|
-
| `protected-paths.ts` | Blocks writes to protected paths (.env, .git/, node_modules/) |
|
|
23
|
-
| `confirm-destructive.ts` | Confirms before destructive session actions (clear, switch, fork) |
|
|
24
|
-
| `dirty-repo-guard.ts` | Prevents session changes with uncommitted git changes |
|
|
25
|
-
| `sandbox/` | OS-level sandboxing using `@anthropic-ai/sandbox-runtime` with per-project config |
|
|
26
|
-
|
|
27
|
-
### Custom Tools
|
|
28
|
-
|
|
29
|
-
| Extension | Description |
|
|
30
|
-
|-----------|-------------|
|
|
31
|
-
| `todo.ts` | Todo list tool + `/todos` command with custom rendering and state persistence |
|
|
32
|
-
| `hello.ts` | Minimal custom tool example |
|
|
33
|
-
| `question.ts` | Demonstrates `ctx.ui.select()` for asking the user questions with custom UI |
|
|
34
|
-
| `questionnaire.ts` | Multi-question input with tab bar navigation between questions |
|
|
35
|
-
| `tool-override.ts` | Override built-in tools (e.g., add logging/access control to `read`) |
|
|
36
|
-
| `dynamic-tools.ts` | Register tools after startup (`session_start`) and at runtime via command, with prompt snippets and tool-specific prompt guidelines |
|
|
37
|
-
| `built-in-tool-renderer.ts` | Custom compact rendering for built-in tools (read, bash, edit, write) while keeping original behavior |
|
|
38
|
-
| `minimal-mode.ts` | Override built-in tool rendering for minimal display (only tool calls, no output in collapsed mode) |
|
|
39
|
-
| `truncated-tool.ts` | Wraps ripgrep with proper output truncation (50KB/2000 lines) |
|
|
40
|
-
| `antigravity-image-gen.ts` | Generate images via Google Antigravity with optional save-to-disk modes |
|
|
41
|
-
| `ssh.ts` | Delegate all tools to a remote machine via SSH using pluggable operations |
|
|
42
|
-
| `subagent/` | Delegate tasks to specialized subagents with isolated context windows |
|
|
43
|
-
|
|
44
|
-
### Commands & UI
|
|
45
|
-
|
|
46
|
-
| Extension | Description |
|
|
47
|
-
|-----------|-------------|
|
|
48
|
-
| `preset.ts` | Named presets for model, thinking level, tools, and instructions via `--preset` flag and `/preset` command |
|
|
49
|
-
| `plan-mode/` | Claude Code-style plan mode for read-only exploration with `/plan` command and step tracking |
|
|
50
|
-
| `tools.ts` | Interactive `/tools` command to enable/disable tools with session persistence |
|
|
51
|
-
| `handoff.ts` | Transfer context to a new focused session via `/handoff <goal>` |
|
|
52
|
-
| `qna.ts` | Extracts questions from last response into editor via `ctx.ui.setEditorText()` |
|
|
53
|
-
| `status-line.ts` | Shows turn progress in footer via `ctx.ui.setStatus()` with themed colors |
|
|
54
|
-
| `widget-placement.ts` | Shows widgets above and below the editor via `ctx.ui.setWidget()` placement |
|
|
55
|
-
| `model-status.ts` | Shows model changes in status bar via `model_select` hook |
|
|
56
|
-
| `snake.ts` | Snake game with custom UI, keyboard handling, and session persistence |
|
|
57
|
-
| `send-user-message.ts` | Demonstrates `shortcut.sendUserMessage()` for sending user messages from extensions |
|
|
58
|
-
| `timed-confirm.ts` | Demonstrates AbortSignal for auto-dismissing `ctx.ui.confirm()` and `ctx.ui.select()` dialogs |
|
|
59
|
-
| `rpc-demo.ts` | Exercises all RPC-supported extension UI methods; pair with [`examples/rpc-extension-ui.ts`](../rpc-extension-ui.ts) |
|
|
60
|
-
| `modal-editor.ts` | Custom vim-like modal editor via `ctx.ui.setEditorComponent()` |
|
|
61
|
-
| `rainbow-editor.ts` | Animated rainbow text effect via custom editor |
|
|
62
|
-
| `notify.ts` | Desktop notifications via OSC 777 when agent finishes (Ghostty, iTerm2, WezTerm) |
|
|
63
|
-
| `titlebar-spinner.ts` | Braille spinner animation in terminal title while the agent is working |
|
|
64
|
-
| `summarize.ts` | Summarize conversation with GPT-5.2 and show in transient UI |
|
|
65
|
-
| `custom-footer.ts` | Custom footer with git branch and token stats via `ctx.ui.setFooter()` |
|
|
66
|
-
| `custom-header.ts` | Custom header via `ctx.ui.setHeader()` |
|
|
67
|
-
| `overlay-test.ts` | Test overlay compositing with inline text inputs and edge cases |
|
|
68
|
-
| `overlay-qa-tests.ts` | Comprehensive overlay QA tests: anchors, margins, stacking, overflow, animation |
|
|
69
|
-
| `doom-overlay/` | DOOM game running as an overlay at 35 FPS (demonstrates real-time game rendering) |
|
|
70
|
-
| `shutdown-command.ts` | Adds `/quit` command demonstrating `ctx.shutdown()` |
|
|
71
|
-
| `reload-runtime.ts` | Adds `/reload-runtime` and `reload_runtime` tool showing safe reload flow |
|
|
72
|
-
| `interactive-shell.ts` | Run interactive commands (vim, htop) with full terminal via `user_bash` hook |
|
|
73
|
-
| `inline-bash.ts` | Expands `!{command}` patterns in prompts via `input` event transformation |
|
|
74
|
-
|
|
75
|
-
### Git Integration
|
|
76
|
-
|
|
77
|
-
| Extension | Description |
|
|
78
|
-
|-----------|-------------|
|
|
79
|
-
| `git-checkpoint.ts` | Creates git stash checkpoints at each turn for code restoration on fork |
|
|
80
|
-
| `auto-commit-on-exit.ts` | Auto-commits on exit using last assistant message for commit message |
|
|
81
|
-
|
|
82
|
-
### System Prompt & Compaction
|
|
83
|
-
|
|
84
|
-
| Extension | Description |
|
|
85
|
-
|-----------|-------------|
|
|
86
|
-
| `pirate.ts` | Demonstrates `systemPromptAppend` to dynamically modify system prompt |
|
|
87
|
-
| `claude-rules.ts` | Scans `.claude/rules/` folder and lists rules in system prompt |
|
|
88
|
-
| `custom-compaction.ts` | Custom compaction that summarizes entire conversation |
|
|
89
|
-
| `trigger-compact.ts` | Triggers compaction when context usage exceeds 100k tokens and adds `/trigger-compact` command |
|
|
90
|
-
|
|
91
|
-
### System Integration
|
|
92
|
-
|
|
93
|
-
| Extension | Description |
|
|
94
|
-
|-----------|-------------|
|
|
95
|
-
| `mac-system-theme.ts` | Syncs Shortcut theme with macOS dark/light mode |
|
|
96
|
-
|
|
97
|
-
### Resources
|
|
98
|
-
|
|
99
|
-
| Extension | Description |
|
|
100
|
-
|-----------|-------------|
|
|
101
|
-
| `dynamic-resources/` | Loads skills, prompts, and themes using `resources_discover` |
|
|
102
|
-
|
|
103
|
-
### Messages & Communication
|
|
104
|
-
|
|
105
|
-
| Extension | Description |
|
|
106
|
-
|-----------|-------------|
|
|
107
|
-
| `message-renderer.ts` | Custom message rendering with colors and expandable details via `registerMessageRenderer` |
|
|
108
|
-
| `event-bus.ts` | Inter-extension communication via `shortcut.events` |
|
|
109
|
-
|
|
110
|
-
### Session Metadata
|
|
111
|
-
|
|
112
|
-
| Extension | Description |
|
|
113
|
-
|-----------|-------------|
|
|
114
|
-
| `session-name.ts` | Name sessions for the session selector via `setSessionName` |
|
|
115
|
-
| `bookmark.ts` | Bookmark entries with labels for `/tree` navigation via `setLabel` |
|
|
116
|
-
|
|
117
|
-
### Custom Providers
|
|
118
|
-
|
|
119
|
-
| Extension | Description |
|
|
120
|
-
|-----------|-------------|
|
|
121
|
-
| `custom-provider-anthropic/` | Custom Anthropic provider with OAuth support and custom streaming implementation |
|
|
122
|
-
| `custom-provider-gitlab-duo/` | GitLab Duo provider using shortcutxl's built-in Anthropic/OpenAI streaming via proxy |
|
|
123
|
-
| `custom-provider-qwen-cli/` | Qwen CLI provider with OAuth device flow and OpenAI-compatible models |
|
|
124
|
-
|
|
125
|
-
### External Dependencies
|
|
126
|
-
|
|
127
|
-
| Extension | Description |
|
|
128
|
-
|-----------|-------------|
|
|
129
|
-
| `with-deps/` | Extension with its own package.json and dependencies (demonstrates jiti module resolution) |
|
|
130
|
-
| `file-trigger.ts` | Watches a trigger file and injects contents into conversation |
|
|
131
|
-
|
|
132
|
-
## Writing Extensions
|
|
133
|
-
|
|
134
|
-
See [docs/extensions.md](../../docs/extensions.md) for full documentation.
|
|
135
|
-
|
|
136
|
-
```typescript
|
|
137
|
-
import type { ExtensionAPI } from "shortcutxl";
|
|
138
|
-
import { Type } from "@sinclair/typebox";
|
|
139
|
-
|
|
140
|
-
export default function (shortcut: ExtensionAPI) {
|
|
141
|
-
// Subscribe to lifecycle events
|
|
142
|
-
shortcut.on("tool_call", async (event, ctx) => {
|
|
143
|
-
if (event.toolName === "bash" && event.input.command?.includes("rm -rf")) {
|
|
144
|
-
const ok = await ctx.ui.confirm("Dangerous!", "Allow rm -rf?");
|
|
145
|
-
if (!ok) return { block: true, reason: "Blocked by user" };
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
// Register custom tools
|
|
150
|
-
shortcut.registerTool({
|
|
151
|
-
name: "greet",
|
|
152
|
-
label: "Greeting",
|
|
153
|
-
description: "Generate a greeting",
|
|
154
|
-
parameters: Type.Object({
|
|
155
|
-
name: Type.String({ description: "Name to greet" }),
|
|
156
|
-
}),
|
|
157
|
-
async execute(toolCallId, params, onUpdate, ctx, signal) {
|
|
158
|
-
return {
|
|
159
|
-
content: [{ type: "text", text: `Hello, ${params.name}!` }],
|
|
160
|
-
details: {},
|
|
161
|
-
};
|
|
162
|
-
},
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
// Register commands
|
|
166
|
-
shortcut.registerCommand("hello", {
|
|
167
|
-
description: "Say hello",
|
|
168
|
-
handler: async (args, ctx) => {
|
|
169
|
-
ctx.ui.notify("Hello!", "info");
|
|
170
|
-
},
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
```
|
|
174
|
-
|
|
175
|
-
## Key Patterns
|
|
176
|
-
|
|
177
|
-
**Use StringEnum for string parameters** (required for Google API compatibility):
|
|
178
|
-
```typescript
|
|
179
|
-
import { StringEnum } from "shortcutxl";
|
|
180
|
-
|
|
181
|
-
// Good
|
|
182
|
-
action: StringEnum(["list", "add"] as const)
|
|
183
|
-
|
|
184
|
-
// Bad - doesn't work with Google
|
|
185
|
-
action: Type.Union([Type.Literal("list"), Type.Literal("add")])
|
|
186
|
-
```
|
|
187
|
-
|
|
188
|
-
**State persistence via details:**
|
|
189
|
-
```typescript
|
|
190
|
-
// Store state in tool result details for proper forking support
|
|
191
|
-
return {
|
|
192
|
-
content: [{ type: "text", text: "Done" }],
|
|
193
|
-
details: { todos: [...todos], nextId }, // Persisted in session
|
|
194
|
-
};
|
|
195
|
-
|
|
196
|
-
// Reconstruct on session events
|
|
197
|
-
shortcut.on("session_start", async (_event, ctx) => {
|
|
198
|
-
for (const entry of ctx.sessionManager.getBranch()) {
|
|
199
|
-
if (entry.type === "message" && entry.message.toolName === "my_tool") {
|
|
200
|
-
const details = entry.message.details;
|
|
201
|
-
// Reconstruct state from details
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
});
|
|
205
|
-
```
|
|
1
|
+
# Extension Examples
|
|
2
|
+
|
|
3
|
+
Example extensions for shortcutxl.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
# Load an extension with --extension flag
|
|
9
|
+
shortcut --extension examples/extensions/permission-gate.ts
|
|
10
|
+
|
|
11
|
+
# Or copy to extensions directory for auto-discovery
|
|
12
|
+
cp permission-gate.ts ~/.shortcut/agent/extensions/
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Examples
|
|
16
|
+
|
|
17
|
+
### Lifecycle & Safety
|
|
18
|
+
|
|
19
|
+
| Extension | Description |
|
|
20
|
+
|-----------|-------------|
|
|
21
|
+
| `permission-gate.ts` | Prompts for confirmation before dangerous bash commands (rm -rf, sudo, etc.) |
|
|
22
|
+
| `protected-paths.ts` | Blocks writes to protected paths (.env, .git/, node_modules/) |
|
|
23
|
+
| `confirm-destructive.ts` | Confirms before destructive session actions (clear, switch, fork) |
|
|
24
|
+
| `dirty-repo-guard.ts` | Prevents session changes with uncommitted git changes |
|
|
25
|
+
| `sandbox/` | OS-level sandboxing using `@anthropic-ai/sandbox-runtime` with per-project config |
|
|
26
|
+
|
|
27
|
+
### Custom Tools
|
|
28
|
+
|
|
29
|
+
| Extension | Description |
|
|
30
|
+
|-----------|-------------|
|
|
31
|
+
| `todo.ts` | Todo list tool + `/todos` command with custom rendering and state persistence |
|
|
32
|
+
| `hello.ts` | Minimal custom tool example |
|
|
33
|
+
| `question.ts` | Demonstrates `ctx.ui.select()` for asking the user questions with custom UI |
|
|
34
|
+
| `questionnaire.ts` | Multi-question input with tab bar navigation between questions |
|
|
35
|
+
| `tool-override.ts` | Override built-in tools (e.g., add logging/access control to `read`) |
|
|
36
|
+
| `dynamic-tools.ts` | Register tools after startup (`session_start`) and at runtime via command, with prompt snippets and tool-specific prompt guidelines |
|
|
37
|
+
| `built-in-tool-renderer.ts` | Custom compact rendering for built-in tools (read, bash, edit, write) while keeping original behavior |
|
|
38
|
+
| `minimal-mode.ts` | Override built-in tool rendering for minimal display (only tool calls, no output in collapsed mode) |
|
|
39
|
+
| `truncated-tool.ts` | Wraps ripgrep with proper output truncation (50KB/2000 lines) |
|
|
40
|
+
| `antigravity-image-gen.ts` | Generate images via Google Antigravity with optional save-to-disk modes |
|
|
41
|
+
| `ssh.ts` | Delegate all tools to a remote machine via SSH using pluggable operations |
|
|
42
|
+
| `subagent/` | Delegate tasks to specialized subagents with isolated context windows |
|
|
43
|
+
|
|
44
|
+
### Commands & UI
|
|
45
|
+
|
|
46
|
+
| Extension | Description |
|
|
47
|
+
|-----------|-------------|
|
|
48
|
+
| `preset.ts` | Named presets for model, thinking level, tools, and instructions via `--preset` flag and `/preset` command |
|
|
49
|
+
| `plan-mode/` | Claude Code-style plan mode for read-only exploration with `/plan` command and step tracking |
|
|
50
|
+
| `tools.ts` | Interactive `/tools` command to enable/disable tools with session persistence |
|
|
51
|
+
| `handoff.ts` | Transfer context to a new focused session via `/handoff <goal>` |
|
|
52
|
+
| `qna.ts` | Extracts questions from last response into editor via `ctx.ui.setEditorText()` |
|
|
53
|
+
| `status-line.ts` | Shows turn progress in footer via `ctx.ui.setStatus()` with themed colors |
|
|
54
|
+
| `widget-placement.ts` | Shows widgets above and below the editor via `ctx.ui.setWidget()` placement |
|
|
55
|
+
| `model-status.ts` | Shows model changes in status bar via `model_select` hook |
|
|
56
|
+
| `snake.ts` | Snake game with custom UI, keyboard handling, and session persistence |
|
|
57
|
+
| `send-user-message.ts` | Demonstrates `shortcut.sendUserMessage()` for sending user messages from extensions |
|
|
58
|
+
| `timed-confirm.ts` | Demonstrates AbortSignal for auto-dismissing `ctx.ui.confirm()` and `ctx.ui.select()` dialogs |
|
|
59
|
+
| `rpc-demo.ts` | Exercises all RPC-supported extension UI methods; pair with [`examples/rpc-extension-ui.ts`](../rpc-extension-ui.ts) |
|
|
60
|
+
| `modal-editor.ts` | Custom vim-like modal editor via `ctx.ui.setEditorComponent()` |
|
|
61
|
+
| `rainbow-editor.ts` | Animated rainbow text effect via custom editor |
|
|
62
|
+
| `notify.ts` | Desktop notifications via OSC 777 when agent finishes (Ghostty, iTerm2, WezTerm) |
|
|
63
|
+
| `titlebar-spinner.ts` | Braille spinner animation in terminal title while the agent is working |
|
|
64
|
+
| `summarize.ts` | Summarize conversation with GPT-5.2 and show in transient UI |
|
|
65
|
+
| `custom-footer.ts` | Custom footer with git branch and token stats via `ctx.ui.setFooter()` |
|
|
66
|
+
| `custom-header.ts` | Custom header via `ctx.ui.setHeader()` |
|
|
67
|
+
| `overlay-test.ts` | Test overlay compositing with inline text inputs and edge cases |
|
|
68
|
+
| `overlay-qa-tests.ts` | Comprehensive overlay QA tests: anchors, margins, stacking, overflow, animation |
|
|
69
|
+
| `doom-overlay/` | DOOM game running as an overlay at 35 FPS (demonstrates real-time game rendering) |
|
|
70
|
+
| `shutdown-command.ts` | Adds `/quit` command demonstrating `ctx.shutdown()` |
|
|
71
|
+
| `reload-runtime.ts` | Adds `/reload-runtime` and `reload_runtime` tool showing safe reload flow |
|
|
72
|
+
| `interactive-shell.ts` | Run interactive commands (vim, htop) with full terminal via `user_bash` hook |
|
|
73
|
+
| `inline-bash.ts` | Expands `!{command}` patterns in prompts via `input` event transformation |
|
|
74
|
+
|
|
75
|
+
### Git Integration
|
|
76
|
+
|
|
77
|
+
| Extension | Description |
|
|
78
|
+
|-----------|-------------|
|
|
79
|
+
| `git-checkpoint.ts` | Creates git stash checkpoints at each turn for code restoration on fork |
|
|
80
|
+
| `auto-commit-on-exit.ts` | Auto-commits on exit using last assistant message for commit message |
|
|
81
|
+
|
|
82
|
+
### System Prompt & Compaction
|
|
83
|
+
|
|
84
|
+
| Extension | Description |
|
|
85
|
+
|-----------|-------------|
|
|
86
|
+
| `pirate.ts` | Demonstrates `systemPromptAppend` to dynamically modify system prompt |
|
|
87
|
+
| `claude-rules.ts` | Scans `.claude/rules/` folder and lists rules in system prompt |
|
|
88
|
+
| `custom-compaction.ts` | Custom compaction that summarizes entire conversation |
|
|
89
|
+
| `trigger-compact.ts` | Triggers compaction when context usage exceeds 100k tokens and adds `/trigger-compact` command |
|
|
90
|
+
|
|
91
|
+
### System Integration
|
|
92
|
+
|
|
93
|
+
| Extension | Description |
|
|
94
|
+
|-----------|-------------|
|
|
95
|
+
| `mac-system-theme.ts` | Syncs Shortcut theme with macOS dark/light mode |
|
|
96
|
+
|
|
97
|
+
### Resources
|
|
98
|
+
|
|
99
|
+
| Extension | Description |
|
|
100
|
+
|-----------|-------------|
|
|
101
|
+
| `dynamic-resources/` | Loads skills, prompts, and themes using `resources_discover` |
|
|
102
|
+
|
|
103
|
+
### Messages & Communication
|
|
104
|
+
|
|
105
|
+
| Extension | Description |
|
|
106
|
+
|-----------|-------------|
|
|
107
|
+
| `message-renderer.ts` | Custom message rendering with colors and expandable details via `registerMessageRenderer` |
|
|
108
|
+
| `event-bus.ts` | Inter-extension communication via `shortcut.events` |
|
|
109
|
+
|
|
110
|
+
### Session Metadata
|
|
111
|
+
|
|
112
|
+
| Extension | Description |
|
|
113
|
+
|-----------|-------------|
|
|
114
|
+
| `session-name.ts` | Name sessions for the session selector via `setSessionName` |
|
|
115
|
+
| `bookmark.ts` | Bookmark entries with labels for `/tree` navigation via `setLabel` |
|
|
116
|
+
|
|
117
|
+
### Custom Providers
|
|
118
|
+
|
|
119
|
+
| Extension | Description |
|
|
120
|
+
|-----------|-------------|
|
|
121
|
+
| `custom-provider-anthropic/` | Custom Anthropic provider with OAuth support and custom streaming implementation |
|
|
122
|
+
| `custom-provider-gitlab-duo/` | GitLab Duo provider using shortcutxl's built-in Anthropic/OpenAI streaming via proxy |
|
|
123
|
+
| `custom-provider-qwen-cli/` | Qwen CLI provider with OAuth device flow and OpenAI-compatible models |
|
|
124
|
+
|
|
125
|
+
### External Dependencies
|
|
126
|
+
|
|
127
|
+
| Extension | Description |
|
|
128
|
+
|-----------|-------------|
|
|
129
|
+
| `with-deps/` | Extension with its own package.json and dependencies (demonstrates jiti module resolution) |
|
|
130
|
+
| `file-trigger.ts` | Watches a trigger file and injects contents into conversation |
|
|
131
|
+
|
|
132
|
+
## Writing Extensions
|
|
133
|
+
|
|
134
|
+
See [docs/extensions.md](../../docs/extensions.md) for full documentation.
|
|
135
|
+
|
|
136
|
+
```typescript
|
|
137
|
+
import type { ExtensionAPI } from "shortcutxl";
|
|
138
|
+
import { Type } from "@sinclair/typebox";
|
|
139
|
+
|
|
140
|
+
export default function (shortcut: ExtensionAPI) {
|
|
141
|
+
// Subscribe to lifecycle events
|
|
142
|
+
shortcut.on("tool_call", async (event, ctx) => {
|
|
143
|
+
if (event.toolName === "bash" && event.input.command?.includes("rm -rf")) {
|
|
144
|
+
const ok = await ctx.ui.confirm("Dangerous!", "Allow rm -rf?");
|
|
145
|
+
if (!ok) return { block: true, reason: "Blocked by user" };
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
// Register custom tools
|
|
150
|
+
shortcut.registerTool({
|
|
151
|
+
name: "greet",
|
|
152
|
+
label: "Greeting",
|
|
153
|
+
description: "Generate a greeting",
|
|
154
|
+
parameters: Type.Object({
|
|
155
|
+
name: Type.String({ description: "Name to greet" }),
|
|
156
|
+
}),
|
|
157
|
+
async execute(toolCallId, params, onUpdate, ctx, signal) {
|
|
158
|
+
return {
|
|
159
|
+
content: [{ type: "text", text: `Hello, ${params.name}!` }],
|
|
160
|
+
details: {},
|
|
161
|
+
};
|
|
162
|
+
},
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
// Register commands
|
|
166
|
+
shortcut.registerCommand("hello", {
|
|
167
|
+
description: "Say hello",
|
|
168
|
+
handler: async (args, ctx) => {
|
|
169
|
+
ctx.ui.notify("Hello!", "info");
|
|
170
|
+
},
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
## Key Patterns
|
|
176
|
+
|
|
177
|
+
**Use StringEnum for string parameters** (required for Google API compatibility):
|
|
178
|
+
```typescript
|
|
179
|
+
import { StringEnum } from "shortcutxl";
|
|
180
|
+
|
|
181
|
+
// Good
|
|
182
|
+
action: StringEnum(["list", "add"] as const)
|
|
183
|
+
|
|
184
|
+
// Bad - doesn't work with Google
|
|
185
|
+
action: Type.Union([Type.Literal("list"), Type.Literal("add")])
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
**State persistence via details:**
|
|
189
|
+
```typescript
|
|
190
|
+
// Store state in tool result details for proper forking support
|
|
191
|
+
return {
|
|
192
|
+
content: [{ type: "text", text: "Done" }],
|
|
193
|
+
details: { todos: [...todos], nextId }, // Persisted in session
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
// Reconstruct on session events
|
|
197
|
+
shortcut.on("session_start", async (_event, ctx) => {
|
|
198
|
+
for (const entry of ctx.sessionManager.getBranch()) {
|
|
199
|
+
if (entry.type === "message" && entry.message.toolName === "my_tool") {
|
|
200
|
+
const details = entry.message.details;
|
|
201
|
+
// Reconstruct state from details
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
```
|