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,233 +1,233 @@
1
- /**
2
- * SSH Remote Execution Example
3
- *
4
- * Demonstrates delegating tool operations to a remote machine via SSH.
5
- * When --ssh is provided, read/write/edit/bash run on the remote.
6
- *
7
- * Usage:
8
- * shortcut -e ./ssh.ts --ssh user@host
9
- * shortcut -e ./ssh.ts --ssh user@host:/remote/path
10
- *
11
- * Requirements:
12
- * - SSH key-based auth (no password prompts)
13
- * - bash on remote
14
- */
15
-
16
- import { spawn } from 'node:child_process';
17
- import type { ExtensionAPI } from 'shortcutxl';
18
- import {
19
- type BashOperations,
20
- createBashTool,
21
- createEditTool,
22
- createReadTool,
23
- createWriteTool,
24
- type EditOperations,
25
- type ReadOperations,
26
- type WriteOperations
27
- } from 'shortcutxl';
28
-
29
- function sshExec(remote: string, command: string): Promise<Buffer> {
30
- return new Promise((resolve, reject) => {
31
- const child = spawn('ssh', [remote, command], { stdio: ['ignore', 'pipe', 'pipe'] });
32
- const chunks: Buffer[] = [];
33
- const errChunks: Buffer[] = [];
34
- child.stdout.on('data', (data) => chunks.push(data));
35
- child.stderr.on('data', (data) => errChunks.push(data));
36
- child.on('error', reject);
37
- child.on('close', (code) => {
38
- if (code !== 0) {
39
- reject(new Error(`SSH failed (${code}): ${Buffer.concat(errChunks).toString()}`));
40
- } else {
41
- resolve(Buffer.concat(chunks));
42
- }
43
- });
44
- });
45
- }
46
-
47
- function createRemoteReadOps(remote: string, remoteCwd: string, localCwd: string): ReadOperations {
48
- const toRemote = (p: string) => p.replace(localCwd, remoteCwd);
49
- return {
50
- readFile: (p) => sshExec(remote, `cat ${JSON.stringify(toRemote(p))}`),
51
- access: (p) => sshExec(remote, `test -r ${JSON.stringify(toRemote(p))}`).then(() => {}),
52
- detectImageMimeType: async (p) => {
53
- try {
54
- const r = await sshExec(remote, `file --mime-type -b ${JSON.stringify(toRemote(p))}`);
55
- const m = r.toString().trim();
56
- return ['image/jpeg', 'image/png', 'image/gif', 'image/webp'].includes(m) ? m : null;
57
- } catch {
58
- return null;
59
- }
60
- }
61
- };
62
- }
63
-
64
- function createRemoteWriteOps(
65
- remote: string,
66
- remoteCwd: string,
67
- localCwd: string
68
- ): WriteOperations {
69
- const toRemote = (p: string) => p.replace(localCwd, remoteCwd);
70
- return {
71
- writeFile: async (p, content) => {
72
- const b64 = Buffer.from(content).toString('base64');
73
- await sshExec(
74
- remote,
75
- `echo ${JSON.stringify(b64)} | base64 -d > ${JSON.stringify(toRemote(p))}`
76
- );
77
- },
78
- mkdir: (dir) => sshExec(remote, `mkdir -p ${JSON.stringify(toRemote(dir))}`).then(() => {})
79
- };
80
- }
81
-
82
- function createRemoteEditOps(remote: string, remoteCwd: string, localCwd: string): EditOperations {
83
- const r = createRemoteReadOps(remote, remoteCwd, localCwd);
84
- const w = createRemoteWriteOps(remote, remoteCwd, localCwd);
85
- return { readFile: r.readFile, access: r.access, writeFile: w.writeFile };
86
- }
87
-
88
- function createRemoteBashOps(remote: string, remoteCwd: string, localCwd: string): BashOperations {
89
- const toRemote = (p: string) => p.replace(localCwd, remoteCwd);
90
- return {
91
- exec: (command, cwd, { onData, signal, timeout }) =>
92
- new Promise((resolve, reject) => {
93
- const cmd = `cd ${JSON.stringify(toRemote(cwd))} && ${command}`;
94
- const child = spawn('ssh', [remote, cmd], { stdio: ['ignore', 'pipe', 'pipe'] });
95
- let timedOut = false;
96
- const timer = timeout
97
- ? setTimeout(() => {
98
- timedOut = true;
99
- child.kill();
100
- }, timeout * 1000)
101
- : undefined;
102
- child.stdout.on('data', onData);
103
- child.stderr.on('data', onData);
104
- child.on('error', (e) => {
105
- if (timer) clearTimeout(timer);
106
- reject(e);
107
- });
108
- const onAbort = () => child.kill();
109
- signal?.addEventListener('abort', onAbort, { once: true });
110
- child.on('close', (code) => {
111
- if (timer) clearTimeout(timer);
112
- signal?.removeEventListener('abort', onAbort);
113
- if (signal?.aborted) reject(new Error('aborted'));
114
- else if (timedOut) reject(new Error(`timeout:${timeout}`));
115
- else resolve({ exitCode: code });
116
- });
117
- })
118
- };
119
- }
120
-
121
- export default function (shortcut: ExtensionAPI) {
122
- shortcut.registerFlag('ssh', {
123
- description: 'SSH remote: user@host or user@host:/path',
124
- type: 'string'
125
- });
126
-
127
- const localCwd = process.cwd();
128
- const localRead = createReadTool(localCwd);
129
- const localWrite = createWriteTool(localCwd);
130
- const localEdit = createEditTool(localCwd);
131
- const localBash = createBashTool(localCwd);
132
-
133
- // Resolved lazily on session_start (CLI flags not available during factory)
134
- let resolvedSsh: { remote: string; remoteCwd: string } | null = null;
135
-
136
- const getSsh = () => resolvedSsh;
137
-
138
- shortcut.registerTool({
139
- ...localRead,
140
- async execute(id, params, signal, onUpdate, _ctx) {
141
- const ssh = getSsh();
142
- if (ssh) {
143
- const tool = createReadTool(localCwd, {
144
- operations: createRemoteReadOps(ssh.remote, ssh.remoteCwd, localCwd)
145
- });
146
- return tool.execute(id, params, signal, onUpdate);
147
- }
148
- return localRead.execute(id, params, signal, onUpdate);
149
- }
150
- });
151
-
152
- shortcut.registerTool({
153
- ...localWrite,
154
- async execute(id, params, signal, onUpdate, _ctx) {
155
- const ssh = getSsh();
156
- if (ssh) {
157
- const tool = createWriteTool(localCwd, {
158
- operations: createRemoteWriteOps(ssh.remote, ssh.remoteCwd, localCwd)
159
- });
160
- return tool.execute(id, params, signal, onUpdate);
161
- }
162
- return localWrite.execute(id, params, signal, onUpdate);
163
- }
164
- });
165
-
166
- shortcut.registerTool({
167
- ...localEdit,
168
- async execute(id, params, signal, onUpdate, _ctx) {
169
- const ssh = getSsh();
170
- if (ssh) {
171
- const tool = createEditTool(localCwd, {
172
- operations: createRemoteEditOps(ssh.remote, ssh.remoteCwd, localCwd)
173
- });
174
- return tool.execute(id, params, signal, onUpdate);
175
- }
176
- return localEdit.execute(id, params, signal, onUpdate);
177
- }
178
- });
179
-
180
- shortcut.registerTool({
181
- ...localBash,
182
- async execute(id, params, signal, onUpdate, _ctx) {
183
- const ssh = getSsh();
184
- if (ssh) {
185
- const tool = createBashTool(localCwd, {
186
- operations: createRemoteBashOps(ssh.remote, ssh.remoteCwd, localCwd)
187
- });
188
- return tool.execute(id, params, signal, onUpdate);
189
- }
190
- return localBash.execute(id, params, signal, onUpdate);
191
- }
192
- });
193
-
194
- shortcut.on('session_start', async (_event, ctx) => {
195
- // Resolve SSH config now that CLI flags are available
196
- const arg = shortcut.getFlag('ssh') as string | undefined;
197
- if (arg) {
198
- if (arg.includes(':')) {
199
- const [remote, path] = arg.split(':');
200
- resolvedSsh = { remote, remoteCwd: path };
201
- } else {
202
- // No path given, evaluate pwd on remote
203
- const remote = arg;
204
- const pwd = (await sshExec(remote, 'pwd')).toString().trim();
205
- resolvedSsh = { remote, remoteCwd: pwd };
206
- }
207
- ctx.ui.setStatus(
208
- 'ssh',
209
- ctx.ui.theme.fg('accent', `SSH: ${resolvedSsh.remote}:${resolvedSsh.remoteCwd}`)
210
- );
211
- ctx.ui.notify(`SSH mode: ${resolvedSsh.remote}:${resolvedSsh.remoteCwd}`, 'info');
212
- }
213
- });
214
-
215
- // Handle user ! commands via SSH
216
- shortcut.on('user_bash', (_event) => {
217
- const ssh = getSsh();
218
- if (!ssh) return; // No SSH, use local execution
219
- return { operations: createRemoteBashOps(ssh.remote, ssh.remoteCwd, localCwd) };
220
- });
221
-
222
- // Replace local cwd with remote cwd in system prompt
223
- shortcut.on('before_agent_start', async (event) => {
224
- const ssh = getSsh();
225
- if (ssh) {
226
- const modified = event.systemPrompt.replace(
227
- `Current working directory: ${localCwd}`,
228
- `Current working directory: ${ssh.remoteCwd} (via SSH: ${ssh.remote})`
229
- );
230
- return { systemPrompt: modified };
231
- }
232
- });
233
- }
1
+ /**
2
+ * SSH Remote Execution Example
3
+ *
4
+ * Demonstrates delegating tool operations to a remote machine via SSH.
5
+ * When --ssh is provided, read/write/edit/bash run on the remote.
6
+ *
7
+ * Usage:
8
+ * shortcut -e ./ssh.ts --ssh user@host
9
+ * shortcut -e ./ssh.ts --ssh user@host:/remote/path
10
+ *
11
+ * Requirements:
12
+ * - SSH key-based auth (no password prompts)
13
+ * - bash on remote
14
+ */
15
+
16
+ import { spawn } from 'node:child_process';
17
+ import type { ExtensionAPI } from 'shortcutxl';
18
+ import {
19
+ type BashOperations,
20
+ createBashTool,
21
+ createEditTool,
22
+ createReadTool,
23
+ createWriteTool,
24
+ type EditOperations,
25
+ type ReadOperations,
26
+ type WriteOperations
27
+ } from 'shortcutxl';
28
+
29
+ function sshExec(remote: string, command: string): Promise<Buffer> {
30
+ return new Promise((resolve, reject) => {
31
+ const child = spawn('ssh', [remote, command], { stdio: ['ignore', 'pipe', 'pipe'] });
32
+ const chunks: Buffer[] = [];
33
+ const errChunks: Buffer[] = [];
34
+ child.stdout.on('data', (data) => chunks.push(data));
35
+ child.stderr.on('data', (data) => errChunks.push(data));
36
+ child.on('error', reject);
37
+ child.on('close', (code) => {
38
+ if (code !== 0) {
39
+ reject(new Error(`SSH failed (${code}): ${Buffer.concat(errChunks).toString()}`));
40
+ } else {
41
+ resolve(Buffer.concat(chunks));
42
+ }
43
+ });
44
+ });
45
+ }
46
+
47
+ function createRemoteReadOps(remote: string, remoteCwd: string, localCwd: string): ReadOperations {
48
+ const toRemote = (p: string) => p.replace(localCwd, remoteCwd);
49
+ return {
50
+ readFile: (p) => sshExec(remote, `cat ${JSON.stringify(toRemote(p))}`),
51
+ access: (p) => sshExec(remote, `test -r ${JSON.stringify(toRemote(p))}`).then(() => {}),
52
+ detectImageMimeType: async (p) => {
53
+ try {
54
+ const r = await sshExec(remote, `file --mime-type -b ${JSON.stringify(toRemote(p))}`);
55
+ const m = r.toString().trim();
56
+ return ['image/jpeg', 'image/png', 'image/gif', 'image/webp'].includes(m) ? m : null;
57
+ } catch {
58
+ return null;
59
+ }
60
+ }
61
+ };
62
+ }
63
+
64
+ function createRemoteWriteOps(
65
+ remote: string,
66
+ remoteCwd: string,
67
+ localCwd: string
68
+ ): WriteOperations {
69
+ const toRemote = (p: string) => p.replace(localCwd, remoteCwd);
70
+ return {
71
+ writeFile: async (p, content) => {
72
+ const b64 = Buffer.from(content).toString('base64');
73
+ await sshExec(
74
+ remote,
75
+ `echo ${JSON.stringify(b64)} | base64 -d > ${JSON.stringify(toRemote(p))}`
76
+ );
77
+ },
78
+ mkdir: (dir) => sshExec(remote, `mkdir -p ${JSON.stringify(toRemote(dir))}`).then(() => {})
79
+ };
80
+ }
81
+
82
+ function createRemoteEditOps(remote: string, remoteCwd: string, localCwd: string): EditOperations {
83
+ const r = createRemoteReadOps(remote, remoteCwd, localCwd);
84
+ const w = createRemoteWriteOps(remote, remoteCwd, localCwd);
85
+ return { readFile: r.readFile, access: r.access, writeFile: w.writeFile };
86
+ }
87
+
88
+ function createRemoteBashOps(remote: string, remoteCwd: string, localCwd: string): BashOperations {
89
+ const toRemote = (p: string) => p.replace(localCwd, remoteCwd);
90
+ return {
91
+ exec: (command, cwd, { onData, signal, timeout }) =>
92
+ new Promise((resolve, reject) => {
93
+ const cmd = `cd ${JSON.stringify(toRemote(cwd))} && ${command}`;
94
+ const child = spawn('ssh', [remote, cmd], { stdio: ['ignore', 'pipe', 'pipe'] });
95
+ let timedOut = false;
96
+ const timer = timeout
97
+ ? setTimeout(() => {
98
+ timedOut = true;
99
+ child.kill();
100
+ }, timeout * 1000)
101
+ : undefined;
102
+ child.stdout.on('data', onData);
103
+ child.stderr.on('data', onData);
104
+ child.on('error', (e) => {
105
+ if (timer) clearTimeout(timer);
106
+ reject(e);
107
+ });
108
+ const onAbort = () => child.kill();
109
+ signal?.addEventListener('abort', onAbort, { once: true });
110
+ child.on('close', (code) => {
111
+ if (timer) clearTimeout(timer);
112
+ signal?.removeEventListener('abort', onAbort);
113
+ if (signal?.aborted) reject(new Error('aborted'));
114
+ else if (timedOut) reject(new Error(`timeout:${timeout}`));
115
+ else resolve({ exitCode: code });
116
+ });
117
+ })
118
+ };
119
+ }
120
+
121
+ export default function (shortcut: ExtensionAPI) {
122
+ shortcut.registerFlag('ssh', {
123
+ description: 'SSH remote: user@host or user@host:/path',
124
+ type: 'string'
125
+ });
126
+
127
+ const localCwd = process.cwd();
128
+ const localRead = createReadTool(localCwd);
129
+ const localWrite = createWriteTool(localCwd);
130
+ const localEdit = createEditTool(localCwd);
131
+ const localBash = createBashTool(localCwd);
132
+
133
+ // Resolved lazily on session_start (CLI flags not available during factory)
134
+ let resolvedSsh: { remote: string; remoteCwd: string } | null = null;
135
+
136
+ const getSsh = () => resolvedSsh;
137
+
138
+ shortcut.registerTool({
139
+ ...localRead,
140
+ async execute(id, params, signal, onUpdate, _ctx) {
141
+ const ssh = getSsh();
142
+ if (ssh) {
143
+ const tool = createReadTool(localCwd, {
144
+ operations: createRemoteReadOps(ssh.remote, ssh.remoteCwd, localCwd)
145
+ });
146
+ return tool.execute(id, params, signal, onUpdate);
147
+ }
148
+ return localRead.execute(id, params, signal, onUpdate);
149
+ }
150
+ });
151
+
152
+ shortcut.registerTool({
153
+ ...localWrite,
154
+ async execute(id, params, signal, onUpdate, _ctx) {
155
+ const ssh = getSsh();
156
+ if (ssh) {
157
+ const tool = createWriteTool(localCwd, {
158
+ operations: createRemoteWriteOps(ssh.remote, ssh.remoteCwd, localCwd)
159
+ });
160
+ return tool.execute(id, params, signal, onUpdate);
161
+ }
162
+ return localWrite.execute(id, params, signal, onUpdate);
163
+ }
164
+ });
165
+
166
+ shortcut.registerTool({
167
+ ...localEdit,
168
+ async execute(id, params, signal, onUpdate, _ctx) {
169
+ const ssh = getSsh();
170
+ if (ssh) {
171
+ const tool = createEditTool(localCwd, {
172
+ operations: createRemoteEditOps(ssh.remote, ssh.remoteCwd, localCwd)
173
+ });
174
+ return tool.execute(id, params, signal, onUpdate);
175
+ }
176
+ return localEdit.execute(id, params, signal, onUpdate);
177
+ }
178
+ });
179
+
180
+ shortcut.registerTool({
181
+ ...localBash,
182
+ async execute(id, params, signal, onUpdate, _ctx) {
183
+ const ssh = getSsh();
184
+ if (ssh) {
185
+ const tool = createBashTool(localCwd, {
186
+ operations: createRemoteBashOps(ssh.remote, ssh.remoteCwd, localCwd)
187
+ });
188
+ return tool.execute(id, params, signal, onUpdate);
189
+ }
190
+ return localBash.execute(id, params, signal, onUpdate);
191
+ }
192
+ });
193
+
194
+ shortcut.on('session_start', async (_event, ctx) => {
195
+ // Resolve SSH config now that CLI flags are available
196
+ const arg = shortcut.getFlag('ssh') as string | undefined;
197
+ if (arg) {
198
+ if (arg.includes(':')) {
199
+ const [remote, path] = arg.split(':');
200
+ resolvedSsh = { remote, remoteCwd: path };
201
+ } else {
202
+ // No path given, evaluate pwd on remote
203
+ const remote = arg;
204
+ const pwd = (await sshExec(remote, 'pwd')).toString().trim();
205
+ resolvedSsh = { remote, remoteCwd: pwd };
206
+ }
207
+ ctx.ui.setStatus(
208
+ 'ssh',
209
+ ctx.ui.theme.fg('accent', `SSH: ${resolvedSsh.remote}:${resolvedSsh.remoteCwd}`)
210
+ );
211
+ ctx.ui.notify(`SSH mode: ${resolvedSsh.remote}:${resolvedSsh.remoteCwd}`, 'info');
212
+ }
213
+ });
214
+
215
+ // Handle user ! commands via SSH
216
+ shortcut.on('user_bash', (_event) => {
217
+ const ssh = getSsh();
218
+ if (!ssh) return; // No SSH, use local execution
219
+ return { operations: createRemoteBashOps(ssh.remote, ssh.remoteCwd, localCwd) };
220
+ });
221
+
222
+ // Replace local cwd with remote cwd in system prompt
223
+ shortcut.on('before_agent_start', async (event) => {
224
+ const ssh = getSsh();
225
+ if (ssh) {
226
+ const modified = event.systemPrompt.replace(
227
+ `Current working directory: ${localCwd}`,
228
+ `Current working directory: ${ssh.remoteCwd} (via SSH: ${ssh.remote})`
229
+ );
230
+ return { systemPrompt: modified };
231
+ }
232
+ });
233
+ }
@@ -1,40 +1,40 @@
1
- /**
2
- * Status Line Extension
3
- *
4
- * Demonstrates ctx.ui.setStatus() for displaying persistent status text in the footer.
5
- * Shows turn progress with themed colors.
6
- */
7
-
8
- import type { ExtensionAPI } from 'shortcutxl';
9
-
10
- export default function (shortcut: ExtensionAPI) {
11
- let turnCount = 0;
12
-
13
- shortcut.on('session_start', async (_event, ctx) => {
14
- const theme = ctx.ui.theme;
15
- ctx.ui.setStatus('status-demo', theme.fg('dim', 'Ready'));
16
- });
17
-
18
- shortcut.on('turn_start', async (_event, ctx) => {
19
- turnCount++;
20
- const theme = ctx.ui.theme;
21
- const spinner = theme.fg('accent', '●');
22
- const text = theme.fg('dim', ` Turn ${turnCount}...`);
23
- ctx.ui.setStatus('status-demo', spinner + text);
24
- });
25
-
26
- shortcut.on('turn_end', async (_event, ctx) => {
27
- const theme = ctx.ui.theme;
28
- const check = theme.fg('success', '✓');
29
- const text = theme.fg('dim', ` Turn ${turnCount} complete`);
30
- ctx.ui.setStatus('status-demo', check + text);
31
- });
32
-
33
- shortcut.on('session_switch', async (event, ctx) => {
34
- if (event.reason === 'new') {
35
- turnCount = 0;
36
- const theme = ctx.ui.theme;
37
- ctx.ui.setStatus('status-demo', theme.fg('dim', 'Ready'));
38
- }
39
- });
40
- }
1
+ /**
2
+ * Status Line Extension
3
+ *
4
+ * Demonstrates ctx.ui.setStatus() for displaying persistent status text in the footer.
5
+ * Shows turn progress with themed colors.
6
+ */
7
+
8
+ import type { ExtensionAPI } from 'shortcutxl';
9
+
10
+ export default function (shortcut: ExtensionAPI) {
11
+ let turnCount = 0;
12
+
13
+ shortcut.on('session_start', async (_event, ctx) => {
14
+ const theme = ctx.ui.theme;
15
+ ctx.ui.setStatus('status-demo', theme.fg('dim', 'Ready'));
16
+ });
17
+
18
+ shortcut.on('turn_start', async (_event, ctx) => {
19
+ turnCount++;
20
+ const theme = ctx.ui.theme;
21
+ const spinner = theme.fg('accent', '●');
22
+ const text = theme.fg('dim', ` Turn ${turnCount}...`);
23
+ ctx.ui.setStatus('status-demo', spinner + text);
24
+ });
25
+
26
+ shortcut.on('turn_end', async (_event, ctx) => {
27
+ const theme = ctx.ui.theme;
28
+ const check = theme.fg('success', '✓');
29
+ const text = theme.fg('dim', ` Turn ${turnCount} complete`);
30
+ ctx.ui.setStatus('status-demo', check + text);
31
+ });
32
+
33
+ shortcut.on('session_switch', async (event, ctx) => {
34
+ if (event.reason === 'new') {
35
+ turnCount = 0;
36
+ const theme = ctx.ui.theme;
37
+ ctx.ui.setStatus('status-demo', theme.fg('dim', 'Ready'));
38
+ }
39
+ });
40
+ }