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,324 +1,324 @@
1
- /**
2
- * Sandbox Extension - OS-level sandboxing for bash commands
3
- *
4
- * Uses @anthropic-ai/sandbox-runtime to enforce filesystem and network
5
- * restrictions on bash commands at the OS level (sandbox-exec on macOS,
6
- * bubblewrap on Linux).
7
- *
8
- * Config files (merged, project takes precedence):
9
- * - ~/.shortcut/agent/sandbox.json (global)
10
- * - <cwd>/.shortcut/sandbox.json (project-local)
11
- *
12
- * Example .shortcut/sandbox.json:
13
- * ```json
14
- * {
15
- * "enabled": true,
16
- * "network": {
17
- * "allowedDomains": ["github.com", "*.github.com"],
18
- * "deniedDomains": []
19
- * },
20
- * "filesystem": {
21
- * "denyRead": ["~/.ssh", "~/.aws"],
22
- * "allowWrite": [".", "/tmp"],
23
- * "denyWrite": [".env"]
24
- * }
25
- * }
26
- * ```
27
- *
28
- * Usage:
29
- * - `shortcut -e ./sandbox` - sandbox enabled with default/config settings
30
- * - `shortcut -e ./sandbox --no-sandbox` - disable sandboxing
31
- * - `/sandbox` - show current sandbox configuration
32
- *
33
- * Setup:
34
- * 1. Copy sandbox/ directory to ~/.shortcut/agent/extensions/
35
- * 2. Run `npm install` in ~/.shortcut/agent/extensions/sandbox/
36
- *
37
- * Linux also requires: bubblewrap, socat, ripgrep
38
- */
39
-
40
- import { SandboxManager, type SandboxRuntimeConfig } from '@anthropic-ai/sandbox-runtime';
41
- import { spawn } from 'node:child_process';
42
- import { existsSync, readFileSync } from 'node:fs';
43
- import { homedir } from 'node:os';
44
- import { join } from 'node:path';
45
- import type { ExtensionAPI } from 'shortcutxl';
46
- import { type BashOperations, createBashTool } from 'shortcutxl';
47
-
48
- interface SandboxConfig extends SandboxRuntimeConfig {
49
- enabled?: boolean;
50
- }
51
-
52
- const DEFAULT_CONFIG: SandboxConfig = {
53
- enabled: true,
54
- network: {
55
- allowedDomains: [
56
- 'npmjs.org',
57
- '*.npmjs.org',
58
- 'registry.npmjs.org',
59
- 'registry.yarnpkg.com',
60
- 'pypi.org',
61
- '*.pypi.org',
62
- 'github.com',
63
- '*.github.com',
64
- 'api.github.com',
65
- 'raw.githubusercontent.com'
66
- ],
67
- deniedDomains: []
68
- },
69
- filesystem: {
70
- denyRead: ['~/.ssh', '~/.aws', '~/.gnupg'],
71
- allowWrite: ['.', '/tmp'],
72
- denyWrite: ['.env', '.env.*', '*.pem', '*.key']
73
- }
74
- };
75
-
76
- function loadConfig(cwd: string): SandboxConfig {
77
- const projectConfigPath = join(cwd, '.shortcut', 'sandbox.json');
78
- const globalConfigPath = join(homedir(), '.shortcut', 'agent', 'sandbox.json');
79
-
80
- let globalConfig: Partial<SandboxConfig> = {};
81
- let projectConfig: Partial<SandboxConfig> = {};
82
-
83
- if (existsSync(globalConfigPath)) {
84
- try {
85
- globalConfig = JSON.parse(readFileSync(globalConfigPath, 'utf-8'));
86
- } catch (e) {
87
- console.error(`Warning: Could not parse ${globalConfigPath}: ${e}`);
88
- }
89
- }
90
-
91
- if (existsSync(projectConfigPath)) {
92
- try {
93
- projectConfig = JSON.parse(readFileSync(projectConfigPath, 'utf-8'));
94
- } catch (e) {
95
- console.error(`Warning: Could not parse ${projectConfigPath}: ${e}`);
96
- }
97
- }
98
-
99
- return deepMerge(deepMerge(DEFAULT_CONFIG, globalConfig), projectConfig);
100
- }
101
-
102
- function deepMerge(base: SandboxConfig, overrides: Partial<SandboxConfig>): SandboxConfig {
103
- const result: SandboxConfig = { ...base };
104
-
105
- if (overrides.enabled !== undefined) result.enabled = overrides.enabled;
106
- if (overrides.network) {
107
- result.network = { ...base.network, ...overrides.network };
108
- }
109
- if (overrides.filesystem) {
110
- result.filesystem = { ...base.filesystem, ...overrides.filesystem };
111
- }
112
-
113
- const extOverrides = overrides as {
114
- ignoreViolations?: Record<string, string[]>;
115
- enableWeakerNestedSandbox?: boolean;
116
- };
117
- const extResult = result as {
118
- ignoreViolations?: Record<string, string[]>;
119
- enableWeakerNestedSandbox?: boolean;
120
- };
121
-
122
- if (extOverrides.ignoreViolations) {
123
- extResult.ignoreViolations = extOverrides.ignoreViolations;
124
- }
125
- if (extOverrides.enableWeakerNestedSandbox !== undefined) {
126
- extResult.enableWeakerNestedSandbox = extOverrides.enableWeakerNestedSandbox;
127
- }
128
-
129
- return result;
130
- }
131
-
132
- function createSandboxedBashOps(): BashOperations {
133
- return {
134
- async exec(command, cwd, { onData, signal, timeout }) {
135
- if (!existsSync(cwd)) {
136
- throw new Error(`Working directory does not exist: ${cwd}`);
137
- }
138
-
139
- const wrappedCommand = await SandboxManager.wrapWithSandbox(command);
140
-
141
- return new Promise((resolve, reject) => {
142
- const child = spawn('bash', ['-c', wrappedCommand], {
143
- cwd,
144
- detached: true,
145
- stdio: ['ignore', 'pipe', 'pipe']
146
- });
147
-
148
- let timedOut = false;
149
- let timeoutHandle: NodeJS.Timeout | undefined;
150
-
151
- if (timeout !== undefined && timeout > 0) {
152
- timeoutHandle = setTimeout(() => {
153
- timedOut = true;
154
- if (child.pid) {
155
- try {
156
- process.kill(-child.pid, 'SIGKILL');
157
- } catch {
158
- child.kill('SIGKILL');
159
- }
160
- }
161
- }, timeout * 1000);
162
- }
163
-
164
- child.stdout?.on('data', onData);
165
- child.stderr?.on('data', onData);
166
-
167
- child.on('error', (err) => {
168
- if (timeoutHandle) clearTimeout(timeoutHandle);
169
- reject(err);
170
- });
171
-
172
- const onAbort = () => {
173
- if (child.pid) {
174
- try {
175
- process.kill(-child.pid, 'SIGKILL');
176
- } catch {
177
- child.kill('SIGKILL');
178
- }
179
- }
180
- };
181
-
182
- signal?.addEventListener('abort', onAbort, { once: true });
183
-
184
- child.on('close', (code) => {
185
- if (timeoutHandle) clearTimeout(timeoutHandle);
186
- signal?.removeEventListener('abort', onAbort);
187
-
188
- if (signal?.aborted) {
189
- reject(new Error('aborted'));
190
- } else if (timedOut) {
191
- reject(new Error(`timeout:${timeout}`));
192
- } else {
193
- resolve({ exitCode: code });
194
- }
195
- });
196
- });
197
- }
198
- };
199
- }
200
-
201
- export default function (shortcut: ExtensionAPI) {
202
- shortcut.registerFlag('no-sandbox', {
203
- description: 'Disable OS-level sandboxing for bash commands',
204
- type: 'boolean',
205
- default: false
206
- });
207
-
208
- const localCwd = process.cwd();
209
- const localBash = createBashTool(localCwd);
210
-
211
- let sandboxEnabled = false;
212
- let sandboxInitialized = false;
213
-
214
- shortcut.registerTool({
215
- ...localBash,
216
- label: 'bash (sandboxed)',
217
- async execute(id, params, signal, onUpdate, _ctx) {
218
- if (!sandboxEnabled || !sandboxInitialized) {
219
- return localBash.execute(id, params, signal, onUpdate);
220
- }
221
-
222
- const sandboxedBash = createBashTool(localCwd, {
223
- operations: createSandboxedBashOps()
224
- });
225
- return sandboxedBash.execute(id, params, signal, onUpdate);
226
- }
227
- });
228
-
229
- shortcut.on('user_bash', () => {
230
- if (!sandboxEnabled || !sandboxInitialized) return;
231
- return { operations: createSandboxedBashOps() };
232
- });
233
-
234
- shortcut.on('session_start', async (_event, ctx) => {
235
- const noSandbox = shortcut.getFlag('no-sandbox') as boolean;
236
-
237
- if (noSandbox) {
238
- sandboxEnabled = false;
239
- ctx.ui.notify('Sandbox disabled via --no-sandbox', 'warning');
240
- return;
241
- }
242
-
243
- const config = loadConfig(ctx.cwd);
244
-
245
- if (!config.enabled) {
246
- sandboxEnabled = false;
247
- ctx.ui.notify('Sandbox disabled via config', 'info');
248
- return;
249
- }
250
-
251
- const platform = process.platform;
252
- if (platform !== 'darwin' && platform !== 'linux') {
253
- sandboxEnabled = false;
254
- ctx.ui.notify(`Sandbox not supported on ${platform}`, 'warning');
255
- return;
256
- }
257
-
258
- try {
259
- const configExt = config as unknown as {
260
- ignoreViolations?: Record<string, string[]>;
261
- enableWeakerNestedSandbox?: boolean;
262
- };
263
-
264
- await SandboxManager.initialize({
265
- network: config.network,
266
- filesystem: config.filesystem,
267
- ignoreViolations: configExt.ignoreViolations,
268
- enableWeakerNestedSandbox: configExt.enableWeakerNestedSandbox
269
- });
270
-
271
- sandboxEnabled = true;
272
- sandboxInitialized = true;
273
-
274
- const networkCount = config.network?.allowedDomains?.length ?? 0;
275
- const writeCount = config.filesystem?.allowWrite?.length ?? 0;
276
- ctx.ui.setStatus(
277
- 'sandbox',
278
- ctx.ui.theme.fg('accent', `🔒 Sandbox: ${networkCount} domains, ${writeCount} write paths`)
279
- );
280
- ctx.ui.notify('Sandbox initialized', 'info');
281
- } catch (err) {
282
- sandboxEnabled = false;
283
- ctx.ui.notify(
284
- `Sandbox initialization failed: ${err instanceof Error ? err.message : err}`,
285
- 'error'
286
- );
287
- }
288
- });
289
-
290
- shortcut.on('session_shutdown', async () => {
291
- if (sandboxInitialized) {
292
- try {
293
- await SandboxManager.reset();
294
- } catch {
295
- // Ignore cleanup errors
296
- }
297
- }
298
- });
299
-
300
- shortcut.registerCommand('sandbox', {
301
- description: 'Show sandbox configuration',
302
- handler: async (_args, ctx) => {
303
- if (!sandboxEnabled) {
304
- ctx.ui.notify('Sandbox is disabled', 'info');
305
- return;
306
- }
307
-
308
- const config = loadConfig(ctx.cwd);
309
- const lines = [
310
- 'Sandbox Configuration:',
311
- '',
312
- 'Network:',
313
- ` Allowed: ${config.network?.allowedDomains?.join(', ') || '(none)'}`,
314
- ` Denied: ${config.network?.deniedDomains?.join(', ') || '(none)'}`,
315
- '',
316
- 'Filesystem:',
317
- ` Deny Read: ${config.filesystem?.denyRead?.join(', ') || '(none)'}`,
318
- ` Allow Write: ${config.filesystem?.allowWrite?.join(', ') || '(none)'}`,
319
- ` Deny Write: ${config.filesystem?.denyWrite?.join(', ') || '(none)'}`
320
- ];
321
- ctx.ui.notify(lines.join('\n'), 'info');
322
- }
323
- });
324
- }
1
+ /**
2
+ * Sandbox Extension - OS-level sandboxing for bash commands
3
+ *
4
+ * Uses @anthropic-ai/sandbox-runtime to enforce filesystem and network
5
+ * restrictions on bash commands at the OS level (sandbox-exec on macOS,
6
+ * bubblewrap on Linux).
7
+ *
8
+ * Config files (merged, project takes precedence):
9
+ * - ~/.shortcut/agent/sandbox.json (global)
10
+ * - <cwd>/.shortcut/sandbox.json (project-local)
11
+ *
12
+ * Example .shortcut/sandbox.json:
13
+ * ```json
14
+ * {
15
+ * "enabled": true,
16
+ * "network": {
17
+ * "allowedDomains": ["github.com", "*.github.com"],
18
+ * "deniedDomains": []
19
+ * },
20
+ * "filesystem": {
21
+ * "denyRead": ["~/.ssh", "~/.aws"],
22
+ * "allowWrite": [".", "/tmp"],
23
+ * "denyWrite": [".env"]
24
+ * }
25
+ * }
26
+ * ```
27
+ *
28
+ * Usage:
29
+ * - `shortcut -e ./sandbox` - sandbox enabled with default/config settings
30
+ * - `shortcut -e ./sandbox --no-sandbox` - disable sandboxing
31
+ * - `/sandbox` - show current sandbox configuration
32
+ *
33
+ * Setup:
34
+ * 1. Copy sandbox/ directory to ~/.shortcut/agent/extensions/
35
+ * 2. Run `npm install` in ~/.shortcut/agent/extensions/sandbox/
36
+ *
37
+ * Linux also requires: bubblewrap, socat, ripgrep
38
+ */
39
+
40
+ import { SandboxManager, type SandboxRuntimeConfig } from '@anthropic-ai/sandbox-runtime';
41
+ import { spawn } from 'node:child_process';
42
+ import { existsSync, readFileSync } from 'node:fs';
43
+ import { homedir } from 'node:os';
44
+ import { join } from 'node:path';
45
+ import type { ExtensionAPI } from 'shortcutxl';
46
+ import { type BashOperations, createBashTool } from 'shortcutxl';
47
+
48
+ interface SandboxConfig extends SandboxRuntimeConfig {
49
+ enabled?: boolean;
50
+ }
51
+
52
+ const DEFAULT_CONFIG: SandboxConfig = {
53
+ enabled: true,
54
+ network: {
55
+ allowedDomains: [
56
+ 'npmjs.org',
57
+ '*.npmjs.org',
58
+ 'registry.npmjs.org',
59
+ 'registry.yarnpkg.com',
60
+ 'pypi.org',
61
+ '*.pypi.org',
62
+ 'github.com',
63
+ '*.github.com',
64
+ 'api.github.com',
65
+ 'raw.githubusercontent.com'
66
+ ],
67
+ deniedDomains: []
68
+ },
69
+ filesystem: {
70
+ denyRead: ['~/.ssh', '~/.aws', '~/.gnupg'],
71
+ allowWrite: ['.', '/tmp'],
72
+ denyWrite: ['.env', '.env.*', '*.pem', '*.key']
73
+ }
74
+ };
75
+
76
+ function loadConfig(cwd: string): SandboxConfig {
77
+ const projectConfigPath = join(cwd, '.shortcut', 'sandbox.json');
78
+ const globalConfigPath = join(homedir(), '.shortcut', 'agent', 'sandbox.json');
79
+
80
+ let globalConfig: Partial<SandboxConfig> = {};
81
+ let projectConfig: Partial<SandboxConfig> = {};
82
+
83
+ if (existsSync(globalConfigPath)) {
84
+ try {
85
+ globalConfig = JSON.parse(readFileSync(globalConfigPath, 'utf-8'));
86
+ } catch (e) {
87
+ console.error(`Warning: Could not parse ${globalConfigPath}: ${e}`);
88
+ }
89
+ }
90
+
91
+ if (existsSync(projectConfigPath)) {
92
+ try {
93
+ projectConfig = JSON.parse(readFileSync(projectConfigPath, 'utf-8'));
94
+ } catch (e) {
95
+ console.error(`Warning: Could not parse ${projectConfigPath}: ${e}`);
96
+ }
97
+ }
98
+
99
+ return deepMerge(deepMerge(DEFAULT_CONFIG, globalConfig), projectConfig);
100
+ }
101
+
102
+ function deepMerge(base: SandboxConfig, overrides: Partial<SandboxConfig>): SandboxConfig {
103
+ const result: SandboxConfig = { ...base };
104
+
105
+ if (overrides.enabled !== undefined) result.enabled = overrides.enabled;
106
+ if (overrides.network) {
107
+ result.network = { ...base.network, ...overrides.network };
108
+ }
109
+ if (overrides.filesystem) {
110
+ result.filesystem = { ...base.filesystem, ...overrides.filesystem };
111
+ }
112
+
113
+ const extOverrides = overrides as {
114
+ ignoreViolations?: Record<string, string[]>;
115
+ enableWeakerNestedSandbox?: boolean;
116
+ };
117
+ const extResult = result as {
118
+ ignoreViolations?: Record<string, string[]>;
119
+ enableWeakerNestedSandbox?: boolean;
120
+ };
121
+
122
+ if (extOverrides.ignoreViolations) {
123
+ extResult.ignoreViolations = extOverrides.ignoreViolations;
124
+ }
125
+ if (extOverrides.enableWeakerNestedSandbox !== undefined) {
126
+ extResult.enableWeakerNestedSandbox = extOverrides.enableWeakerNestedSandbox;
127
+ }
128
+
129
+ return result;
130
+ }
131
+
132
+ function createSandboxedBashOps(): BashOperations {
133
+ return {
134
+ async exec(command, cwd, { onData, signal, timeout }) {
135
+ if (!existsSync(cwd)) {
136
+ throw new Error(`Working directory does not exist: ${cwd}`);
137
+ }
138
+
139
+ const wrappedCommand = await SandboxManager.wrapWithSandbox(command);
140
+
141
+ return new Promise((resolve, reject) => {
142
+ const child = spawn('bash', ['-c', wrappedCommand], {
143
+ cwd,
144
+ detached: true,
145
+ stdio: ['ignore', 'pipe', 'pipe']
146
+ });
147
+
148
+ let timedOut = false;
149
+ let timeoutHandle: NodeJS.Timeout | undefined;
150
+
151
+ if (timeout !== undefined && timeout > 0) {
152
+ timeoutHandle = setTimeout(() => {
153
+ timedOut = true;
154
+ if (child.pid) {
155
+ try {
156
+ process.kill(-child.pid, 'SIGKILL');
157
+ } catch {
158
+ child.kill('SIGKILL');
159
+ }
160
+ }
161
+ }, timeout * 1000);
162
+ }
163
+
164
+ child.stdout?.on('data', onData);
165
+ child.stderr?.on('data', onData);
166
+
167
+ child.on('error', (err) => {
168
+ if (timeoutHandle) clearTimeout(timeoutHandle);
169
+ reject(err);
170
+ });
171
+
172
+ const onAbort = () => {
173
+ if (child.pid) {
174
+ try {
175
+ process.kill(-child.pid, 'SIGKILL');
176
+ } catch {
177
+ child.kill('SIGKILL');
178
+ }
179
+ }
180
+ };
181
+
182
+ signal?.addEventListener('abort', onAbort, { once: true });
183
+
184
+ child.on('close', (code) => {
185
+ if (timeoutHandle) clearTimeout(timeoutHandle);
186
+ signal?.removeEventListener('abort', onAbort);
187
+
188
+ if (signal?.aborted) {
189
+ reject(new Error('aborted'));
190
+ } else if (timedOut) {
191
+ reject(new Error(`timeout:${timeout}`));
192
+ } else {
193
+ resolve({ exitCode: code });
194
+ }
195
+ });
196
+ });
197
+ }
198
+ };
199
+ }
200
+
201
+ export default function (shortcut: ExtensionAPI) {
202
+ shortcut.registerFlag('no-sandbox', {
203
+ description: 'Disable OS-level sandboxing for bash commands',
204
+ type: 'boolean',
205
+ default: false
206
+ });
207
+
208
+ const localCwd = process.cwd();
209
+ const localBash = createBashTool(localCwd);
210
+
211
+ let sandboxEnabled = false;
212
+ let sandboxInitialized = false;
213
+
214
+ shortcut.registerTool({
215
+ ...localBash,
216
+ label: 'bash (sandboxed)',
217
+ async execute(id, params, signal, onUpdate, _ctx) {
218
+ if (!sandboxEnabled || !sandboxInitialized) {
219
+ return localBash.execute(id, params, signal, onUpdate);
220
+ }
221
+
222
+ const sandboxedBash = createBashTool(localCwd, {
223
+ operations: createSandboxedBashOps()
224
+ });
225
+ return sandboxedBash.execute(id, params, signal, onUpdate);
226
+ }
227
+ });
228
+
229
+ shortcut.on('user_bash', () => {
230
+ if (!sandboxEnabled || !sandboxInitialized) return;
231
+ return { operations: createSandboxedBashOps() };
232
+ });
233
+
234
+ shortcut.on('session_start', async (_event, ctx) => {
235
+ const noSandbox = shortcut.getFlag('no-sandbox') as boolean;
236
+
237
+ if (noSandbox) {
238
+ sandboxEnabled = false;
239
+ ctx.ui.notify('Sandbox disabled via --no-sandbox', 'warning');
240
+ return;
241
+ }
242
+
243
+ const config = loadConfig(ctx.cwd);
244
+
245
+ if (!config.enabled) {
246
+ sandboxEnabled = false;
247
+ ctx.ui.notify('Sandbox disabled via config', 'info');
248
+ return;
249
+ }
250
+
251
+ const platform = process.platform;
252
+ if (platform !== 'darwin' && platform !== 'linux') {
253
+ sandboxEnabled = false;
254
+ ctx.ui.notify(`Sandbox not supported on ${platform}`, 'warning');
255
+ return;
256
+ }
257
+
258
+ try {
259
+ const configExt = config as unknown as {
260
+ ignoreViolations?: Record<string, string[]>;
261
+ enableWeakerNestedSandbox?: boolean;
262
+ };
263
+
264
+ await SandboxManager.initialize({
265
+ network: config.network,
266
+ filesystem: config.filesystem,
267
+ ignoreViolations: configExt.ignoreViolations,
268
+ enableWeakerNestedSandbox: configExt.enableWeakerNestedSandbox
269
+ });
270
+
271
+ sandboxEnabled = true;
272
+ sandboxInitialized = true;
273
+
274
+ const networkCount = config.network?.allowedDomains?.length ?? 0;
275
+ const writeCount = config.filesystem?.allowWrite?.length ?? 0;
276
+ ctx.ui.setStatus(
277
+ 'sandbox',
278
+ ctx.ui.theme.fg('accent', `🔒 Sandbox: ${networkCount} domains, ${writeCount} write paths`)
279
+ );
280
+ ctx.ui.notify('Sandbox initialized', 'info');
281
+ } catch (err) {
282
+ sandboxEnabled = false;
283
+ ctx.ui.notify(
284
+ `Sandbox initialization failed: ${err instanceof Error ? err.message : err}`,
285
+ 'error'
286
+ );
287
+ }
288
+ });
289
+
290
+ shortcut.on('session_shutdown', async () => {
291
+ if (sandboxInitialized) {
292
+ try {
293
+ await SandboxManager.reset();
294
+ } catch {
295
+ // Ignore cleanup errors
296
+ }
297
+ }
298
+ });
299
+
300
+ shortcut.registerCommand('sandbox', {
301
+ description: 'Show sandbox configuration',
302
+ handler: async (_args, ctx) => {
303
+ if (!sandboxEnabled) {
304
+ ctx.ui.notify('Sandbox is disabled', 'info');
305
+ return;
306
+ }
307
+
308
+ const config = loadConfig(ctx.cwd);
309
+ const lines = [
310
+ 'Sandbox Configuration:',
311
+ '',
312
+ 'Network:',
313
+ ` Allowed: ${config.network?.allowedDomains?.join(', ') || '(none)'}`,
314
+ ` Denied: ${config.network?.deniedDomains?.join(', ') || '(none)'}`,
315
+ '',
316
+ 'Filesystem:',
317
+ ` Deny Read: ${config.filesystem?.denyRead?.join(', ') || '(none)'}`,
318
+ ` Allow Write: ${config.filesystem?.allowWrite?.join(', ') || '(none)'}`,
319
+ ` Deny Write: ${config.filesystem?.denyWrite?.join(', ') || '(none)'}`
320
+ ];
321
+ ctx.ui.notify(lines.join('\n'), 'info');
322
+ }
323
+ });
324
+ }