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,22 +1,22 @@
1
- /**
2
- * Minimal SDK Usage
3
- *
4
- * Uses all defaults: discovers skills, extensions, tools, context files
5
- * from cwd and ~/.shortcut/agent. Model chosen from settings or first available.
6
- */
7
-
8
- import { createAgentSession } from 'shortcutxl';
9
-
10
- const { session } = await createAgentSession();
11
-
12
- session.subscribe((event) => {
13
- if (event.type === 'message_update' && event.assistantMessageEvent.type === 'text_delta') {
14
- process.stdout.write(event.assistantMessageEvent.delta);
15
- }
16
- });
17
-
18
- await session.prompt('What files are in the current directory?');
19
- session.state.messages.forEach((msg) => {
20
- console.log(msg);
21
- });
22
- console.log();
1
+ /**
2
+ * Minimal SDK Usage
3
+ *
4
+ * Uses all defaults: discovers skills, extensions, tools, context files
5
+ * from cwd and ~/.shortcut/agent. Model chosen from settings or first available.
6
+ */
7
+
8
+ import { createAgentSession } from 'shortcutxl';
9
+
10
+ const { session } = await createAgentSession();
11
+
12
+ session.subscribe((event) => {
13
+ if (event.type === 'message_update' && event.assistantMessageEvent.type === 'text_delta') {
14
+ process.stdout.write(event.assistantMessageEvent.delta);
15
+ }
16
+ });
17
+
18
+ await session.prompt('What files are in the current directory?');
19
+ session.state.messages.forEach((msg) => {
20
+ console.log(msg);
21
+ });
22
+ console.log();
@@ -1,48 +1,48 @@
1
- /**
2
- * Custom Model Selection
3
- *
4
- * Shows how to select a specific model and thinking level.
5
- */
6
-
7
- import { AuthStorage, createAgentSession, getModel, ModelRegistry } from 'shortcutxl';
8
-
9
- // Set up auth storage and model registry
10
- const authStorage = AuthStorage.create();
11
- const modelRegistry = new ModelRegistry(authStorage);
12
-
13
- // Option 1: Find a specific built-in model by provider/id
14
- const opus = getModel('anthropic', 'claude-opus-4-5');
15
- if (opus) {
16
- console.log(`Found model: ${opus.provider}/${opus.id}`);
17
- }
18
-
19
- // Option 2: Find model via registry (includes custom models from models.json)
20
- const customModel = modelRegistry.find('my-provider', 'my-model');
21
- if (customModel) {
22
- console.log(`Found custom model: ${customModel.provider}/${customModel.id}`);
23
- }
24
-
25
- // Option 3: Pick from available models (have valid API keys)
26
- const available = await modelRegistry.getAvailable();
27
- console.log(
28
- 'Available models:',
29
- available.map((m) => `${m.provider}/${m.id}`)
30
- );
31
-
32
- if (available.length > 0) {
33
- const { session } = await createAgentSession({
34
- model: available[0],
35
- thinkingLevel: 'medium', // off, low, medium, high
36
- authStorage,
37
- modelRegistry
38
- });
39
-
40
- session.subscribe((event) => {
41
- if (event.type === 'message_update' && event.assistantMessageEvent.type === 'text_delta') {
42
- process.stdout.write(event.assistantMessageEvent.delta);
43
- }
44
- });
45
-
46
- await session.prompt('Say hello in one sentence.');
47
- console.log();
48
- }
1
+ /**
2
+ * Custom Model Selection
3
+ *
4
+ * Shows how to select a specific model and thinking level.
5
+ */
6
+
7
+ import { AuthStorage, createAgentSession, getModel, ModelRegistry } from 'shortcutxl';
8
+
9
+ // Set up auth storage and model registry
10
+ const authStorage = AuthStorage.create();
11
+ const modelRegistry = new ModelRegistry(authStorage);
12
+
13
+ // Option 1: Find a specific built-in model by provider/id
14
+ const opus = getModel('anthropic', 'claude-opus-4-5');
15
+ if (opus) {
16
+ console.log(`Found model: ${opus.provider}/${opus.id}`);
17
+ }
18
+
19
+ // Option 2: Find model via registry (includes custom models from models.json)
20
+ const customModel = modelRegistry.find('my-provider', 'my-model');
21
+ if (customModel) {
22
+ console.log(`Found custom model: ${customModel.provider}/${customModel.id}`);
23
+ }
24
+
25
+ // Option 3: Pick from available models (have valid API keys)
26
+ const available = await modelRegistry.getAvailable();
27
+ console.log(
28
+ 'Available models:',
29
+ available.map((m) => `${m.provider}/${m.id}`)
30
+ );
31
+
32
+ if (available.length > 0) {
33
+ const { session } = await createAgentSession({
34
+ model: available[0],
35
+ thinkingLevel: 'medium', // off, low, medium, high
36
+ authStorage,
37
+ modelRegistry
38
+ });
39
+
40
+ session.subscribe((event) => {
41
+ if (event.type === 'message_update' && event.assistantMessageEvent.type === 'text_delta') {
42
+ process.stdout.write(event.assistantMessageEvent.delta);
43
+ }
44
+ });
45
+
46
+ await session.prompt('Say hello in one sentence.');
47
+ console.log();
48
+ }
@@ -1,55 +1,55 @@
1
- /**
2
- * Custom System Prompt
3
- *
4
- * Shows how to replace or modify the default system prompt.
5
- */
6
-
7
- import { createAgentSession, DefaultResourceLoader, SessionManager } from 'shortcutxl';
8
-
9
- // Option 1: Replace prompt entirely
10
- const loader1 = new DefaultResourceLoader({
11
- systemPromptOverride: () => `You are a helpful assistant that speaks like a pirate.
12
- Always end responses with "Arrr!"`,
13
- // Needed to avoid DefaultResourceLoader appending APPEND_SYSTEM.md from ~/.shortcut/agent or <cwd>/.shortcut.
14
- appendSystemPromptOverride: () => []
15
- });
16
- await loader1.reload();
17
-
18
- const { session: session1 } = await createAgentSession({
19
- resourceLoader: loader1,
20
- sessionManager: SessionManager.inMemory()
21
- });
22
-
23
- session1.subscribe((event) => {
24
- if (event.type === 'message_update' && event.assistantMessageEvent.type === 'text_delta') {
25
- process.stdout.write(event.assistantMessageEvent.delta);
26
- }
27
- });
28
-
29
- console.log('=== Replace prompt ===');
30
- await session1.prompt('What is 2 + 2?');
31
- console.log('\n');
32
-
33
- // Option 2: Append instructions to the default prompt
34
- const loader2 = new DefaultResourceLoader({
35
- appendSystemPromptOverride: (base) => [
36
- ...base,
37
- '## Additional Instructions\n- Always be concise\n- Use bullet points when listing things'
38
- ]
39
- });
40
- await loader2.reload();
41
-
42
- const { session: session2 } = await createAgentSession({
43
- resourceLoader: loader2,
44
- sessionManager: SessionManager.inMemory()
45
- });
46
-
47
- session2.subscribe((event) => {
48
- if (event.type === 'message_update' && event.assistantMessageEvent.type === 'text_delta') {
49
- process.stdout.write(event.assistantMessageEvent.delta);
50
- }
51
- });
52
-
53
- console.log('=== Modify prompt ===');
54
- await session2.prompt('List 3 benefits of TypeScript.');
55
- console.log();
1
+ /**
2
+ * Custom System Prompt
3
+ *
4
+ * Shows how to replace or modify the default system prompt.
5
+ */
6
+
7
+ import { createAgentSession, DefaultResourceLoader, SessionManager } from 'shortcutxl';
8
+
9
+ // Option 1: Replace prompt entirely
10
+ const loader1 = new DefaultResourceLoader({
11
+ systemPromptOverride: () => `You are a helpful assistant that speaks like a pirate.
12
+ Always end responses with "Arrr!"`,
13
+ // Needed to avoid DefaultResourceLoader appending APPEND_SYSTEM.md from ~/.shortcut/agent or <cwd>/.shortcut.
14
+ appendSystemPromptOverride: () => []
15
+ });
16
+ await loader1.reload();
17
+
18
+ const { session: session1 } = await createAgentSession({
19
+ resourceLoader: loader1,
20
+ sessionManager: SessionManager.inMemory()
21
+ });
22
+
23
+ session1.subscribe((event) => {
24
+ if (event.type === 'message_update' && event.assistantMessageEvent.type === 'text_delta') {
25
+ process.stdout.write(event.assistantMessageEvent.delta);
26
+ }
27
+ });
28
+
29
+ console.log('=== Replace prompt ===');
30
+ await session1.prompt('What is 2 + 2?');
31
+ console.log('\n');
32
+
33
+ // Option 2: Append instructions to the default prompt
34
+ const loader2 = new DefaultResourceLoader({
35
+ appendSystemPromptOverride: (base) => [
36
+ ...base,
37
+ '## Additional Instructions\n- Always be concise\n- Use bullet points when listing things'
38
+ ]
39
+ });
40
+ await loader2.reload();
41
+
42
+ const { session: session2 } = await createAgentSession({
43
+ resourceLoader: loader2,
44
+ sessionManager: SessionManager.inMemory()
45
+ });
46
+
47
+ session2.subscribe((event) => {
48
+ if (event.type === 'message_update' && event.assistantMessageEvent.type === 'text_delta') {
49
+ process.stdout.write(event.assistantMessageEvent.delta);
50
+ }
51
+ });
52
+
53
+ console.log('=== Modify prompt ===');
54
+ await session2.prompt('List 3 benefits of TypeScript.');
55
+ console.log();
@@ -1,53 +1,53 @@
1
- /**
2
- * Skills Configuration
3
- *
4
- * Skills provide specialized instructions loaded into the system prompt.
5
- * Discover, filter, merge, or replace them.
6
- */
7
-
8
- import {
9
- createAgentSession,
10
- DefaultResourceLoader,
11
- SessionManager,
12
- type Skill
13
- } from 'shortcutxl';
14
-
15
- // Or define custom skills inline
16
- const customSkill: Skill = {
17
- name: 'my-skill',
18
- description: 'Custom project instructions',
19
- filePath: '/virtual/SKILL.md',
20
- baseDir: '/virtual',
21
- source: 'path',
22
- disableModelInvocation: false
23
- };
24
-
25
- const loader = new DefaultResourceLoader({
26
- skillsOverride: (current) => {
27
- const filteredSkills = current.skills.filter(
28
- (s) => s.name.includes('browser') || s.name.includes('search')
29
- );
30
- return {
31
- skills: [...filteredSkills, customSkill],
32
- diagnostics: current.diagnostics
33
- };
34
- }
35
- });
36
- await loader.reload();
37
-
38
- // Discover all skills from cwd/.shortcut/skills, ~/.shortcut/agent/skills, etc.
39
- const { skills: allSkills, diagnostics } = loader.getSkills();
40
- console.log(
41
- 'Discovered skills:',
42
- allSkills.map((s) => s.name)
43
- );
44
- if (diagnostics.length > 0) {
45
- console.log('Warnings:', diagnostics);
46
- }
47
-
48
- await createAgentSession({
49
- resourceLoader: loader,
50
- sessionManager: SessionManager.inMemory()
51
- });
52
-
53
- console.log('Session created with filtered skills');
1
+ /**
2
+ * Skills Configuration
3
+ *
4
+ * Skills provide specialized instructions loaded into the system prompt.
5
+ * Discover, filter, merge, or replace them.
6
+ */
7
+
8
+ import {
9
+ createAgentSession,
10
+ DefaultResourceLoader,
11
+ SessionManager,
12
+ type Skill
13
+ } from 'shortcutxl';
14
+
15
+ // Or define custom skills inline
16
+ const customSkill: Skill = {
17
+ name: 'my-skill',
18
+ description: 'Custom project instructions',
19
+ filePath: '/virtual/SKILL.md',
20
+ baseDir: '/virtual',
21
+ source: 'path',
22
+ disableModelInvocation: false
23
+ };
24
+
25
+ const loader = new DefaultResourceLoader({
26
+ skillsOverride: (current) => {
27
+ const filteredSkills = current.skills.filter(
28
+ (s) => s.name.includes('browser') || s.name.includes('search')
29
+ );
30
+ return {
31
+ skills: [...filteredSkills, customSkill],
32
+ diagnostics: current.diagnostics
33
+ };
34
+ }
35
+ });
36
+ await loader.reload();
37
+
38
+ // Discover all skills from cwd/.shortcut/skills, ~/.shortcut/agent/skills, etc.
39
+ const { skills: allSkills, diagnostics } = loader.getSkills();
40
+ console.log(
41
+ 'Discovered skills:',
42
+ allSkills.map((s) => s.name)
43
+ );
44
+ if (diagnostics.length > 0) {
45
+ console.log('Warnings:', diagnostics);
46
+ }
47
+
48
+ await createAgentSession({
49
+ resourceLoader: loader,
50
+ sessionManager: SessionManager.inMemory()
51
+ });
52
+
53
+ console.log('Session created with filtered skills');
@@ -1,56 +1,56 @@
1
- /**
2
- * Tools Configuration
3
- *
4
- * Use built-in tool sets or individual tools.
5
- *
6
- * IMPORTANT: When using a custom `cwd`, you must use the tool factory functions
7
- * (createCodingTools, createReadOnlyTools, createReadTool, etc.) to ensure
8
- * tools resolve paths relative to your cwd, not process.cwd().
9
- *
10
- * For custom tools, see 06-extensions.ts - custom tools are now registered
11
- * via the extensions system using shortcut.registerTool().
12
- */
13
-
14
- import {
15
- bashTool,
16
- createAgentSession,
17
- createBashTool,
18
- createCodingTools,
19
- createGrepTool,
20
- createReadTool,
21
- grepTool,
22
- readOnlyTools,
23
- readTool,
24
- SessionManager
25
- } from 'shortcutxl';
26
-
27
- // Read-only mode (no edit/write) - uses process.cwd()
28
- await createAgentSession({
29
- tools: readOnlyTools,
30
- sessionManager: SessionManager.inMemory()
31
- });
32
- console.log('Read-only session created');
33
-
34
- // Custom tool selection - uses process.cwd()
35
- await createAgentSession({
36
- tools: [readTool, bashTool, grepTool],
37
- sessionManager: SessionManager.inMemory()
38
- });
39
- console.log('Custom tools session created');
40
-
41
- // With custom cwd - MUST use factory functions!
42
- const customCwd = '/path/to/project';
43
- await createAgentSession({
44
- cwd: customCwd,
45
- tools: createCodingTools(customCwd), // Tools resolve paths relative to customCwd
46
- sessionManager: SessionManager.inMemory()
47
- });
48
- console.log('Custom cwd session created');
49
-
50
- // Or pick specific tools for custom cwd
51
- await createAgentSession({
52
- cwd: customCwd,
53
- tools: [createReadTool(customCwd), createBashTool(customCwd), createGrepTool(customCwd)],
54
- sessionManager: SessionManager.inMemory()
55
- });
56
- console.log('Specific tools with custom cwd session created');
1
+ /**
2
+ * Tools Configuration
3
+ *
4
+ * Use built-in tool sets or individual tools.
5
+ *
6
+ * IMPORTANT: When using a custom `cwd`, you must use the tool factory functions
7
+ * (createCodingTools, createReadOnlyTools, createReadTool, etc.) to ensure
8
+ * tools resolve paths relative to your cwd, not process.cwd().
9
+ *
10
+ * For custom tools, see 06-extensions.ts - custom tools are now registered
11
+ * via the extensions system using shortcut.registerTool().
12
+ */
13
+
14
+ import {
15
+ bashTool,
16
+ createAgentSession,
17
+ createBashTool,
18
+ createCodingTools,
19
+ createGrepTool,
20
+ createReadTool,
21
+ grepTool,
22
+ readOnlyTools,
23
+ readTool,
24
+ SessionManager
25
+ } from 'shortcutxl';
26
+
27
+ // Read-only mode (no edit/write) - uses process.cwd()
28
+ await createAgentSession({
29
+ tools: readOnlyTools,
30
+ sessionManager: SessionManager.inMemory()
31
+ });
32
+ console.log('Read-only session created');
33
+
34
+ // Custom tool selection - uses process.cwd()
35
+ await createAgentSession({
36
+ tools: [readTool, bashTool, grepTool],
37
+ sessionManager: SessionManager.inMemory()
38
+ });
39
+ console.log('Custom tools session created');
40
+
41
+ // With custom cwd - MUST use factory functions!
42
+ const customCwd = '/path/to/project';
43
+ await createAgentSession({
44
+ cwd: customCwd,
45
+ tools: createCodingTools(customCwd), // Tools resolve paths relative to customCwd
46
+ sessionManager: SessionManager.inMemory()
47
+ });
48
+ console.log('Custom cwd session created');
49
+
50
+ // Or pick specific tools for custom cwd
51
+ await createAgentSession({
52
+ cwd: customCwd,
53
+ tools: [createReadTool(customCwd), createBashTool(customCwd), createGrepTool(customCwd)],
54
+ sessionManager: SessionManager.inMemory()
55
+ });
56
+ console.log('Specific tools with custom cwd session created');
@@ -1,88 +1,88 @@
1
- /**
2
- * Extensions Configuration
3
- *
4
- * Extensions intercept agent events and can register custom tools.
5
- * They provide a unified system for extensions, custom tools, commands, and more.
6
- *
7
- * By default, extension files are discovered from:
8
- * - ~/.shortcut/agent/extensions/
9
- * - <cwd>/.shortcut/extensions/
10
- * - Paths specified in settings.json "extensions" array
11
- *
12
- * An extension is a TypeScript file that exports a default function:
13
- * export default function (shortcut: ExtensionAPI) { ... }
14
- */
15
-
16
- import { createAgentSession, DefaultResourceLoader, SessionManager } from 'shortcutxl';
17
-
18
- // Extensions are discovered automatically from standard locations.
19
- // You can also add paths via settings.json or DefaultResourceLoader options.
20
-
21
- const resourceLoader = new DefaultResourceLoader({
22
- additionalExtensionPaths: ['./my-logging-extension.ts', './my-safety-extension.ts'],
23
- extensionFactories: [
24
- (shortcut) => {
25
- shortcut.on('agent_start', () => {
26
- console.log('[Inline Extension] Agent starting');
27
- });
28
- }
29
- ]
30
- });
31
- await resourceLoader.reload();
32
-
33
- const { session } = await createAgentSession({
34
- resourceLoader,
35
- sessionManager: SessionManager.inMemory()
36
- });
37
-
38
- session.subscribe((event) => {
39
- if (event.type === 'message_update' && event.assistantMessageEvent.type === 'text_delta') {
40
- process.stdout.write(event.assistantMessageEvent.delta);
41
- }
42
- });
43
-
44
- await session.prompt('List files in the current directory.');
45
- console.log();
46
-
47
- // Example extension file (./my-logging-extension.ts):
48
- /*
49
- import type { ExtensionAPI } from "shortcutxl";
50
-
51
- export default function (shortcut: ExtensionAPI) {
52
- shortcut.on("agent_start", async () => {
53
- console.log("[Extension] Agent starting");
54
- });
55
-
56
- shortcut.on("tool_call", async (event) => {
57
- console.log(\`[Extension] Tool: \${event.toolName}\`);
58
- // Return { block: true, reason: "..." } to block execution
59
- return undefined;
60
- });
61
-
62
- shortcut.on("agent_end", async (event) => {
63
- console.log(\`[Extension] Done, \${event.messages.length} messages\`);
64
- });
65
-
66
- // Register a custom tool
67
- shortcut.registerTool({
68
- name: "my_tool",
69
- label: "My Tool",
70
- description: "Does something useful",
71
- parameters: Type.Object({
72
- input: Type.String(),
73
- }),
74
- execute: async (_toolCallId, params, _signal, _onUpdate, _ctx) => ({
75
- content: [{ type: "text", text: \`Processed: \${params.input}\` }],
76
- details: {},
77
- }),
78
- });
79
-
80
- // Register a command
81
- shortcut.registerCommand("mycommand", {
82
- description: "Do something",
83
- handler: async (args, ctx) => {
84
- ctx.ui.notify(\`Command executed with: \${args}\`);
85
- },
86
- });
87
- }
88
- */
1
+ /**
2
+ * Extensions Configuration
3
+ *
4
+ * Extensions intercept agent events and can register custom tools.
5
+ * They provide a unified system for extensions, custom tools, commands, and more.
6
+ *
7
+ * By default, extension files are discovered from:
8
+ * - ~/.shortcut/agent/extensions/
9
+ * - <cwd>/.shortcut/extensions/
10
+ * - Paths specified in settings.json "extensions" array
11
+ *
12
+ * An extension is a TypeScript file that exports a default function:
13
+ * export default function (shortcut: ExtensionAPI) { ... }
14
+ */
15
+
16
+ import { createAgentSession, DefaultResourceLoader, SessionManager } from 'shortcutxl';
17
+
18
+ // Extensions are discovered automatically from standard locations.
19
+ // You can also add paths via settings.json or DefaultResourceLoader options.
20
+
21
+ const resourceLoader = new DefaultResourceLoader({
22
+ additionalExtensionPaths: ['./my-logging-extension.ts', './my-safety-extension.ts'],
23
+ extensionFactories: [
24
+ (shortcut) => {
25
+ shortcut.on('agent_start', () => {
26
+ console.log('[Inline Extension] Agent starting');
27
+ });
28
+ }
29
+ ]
30
+ });
31
+ await resourceLoader.reload();
32
+
33
+ const { session } = await createAgentSession({
34
+ resourceLoader,
35
+ sessionManager: SessionManager.inMemory()
36
+ });
37
+
38
+ session.subscribe((event) => {
39
+ if (event.type === 'message_update' && event.assistantMessageEvent.type === 'text_delta') {
40
+ process.stdout.write(event.assistantMessageEvent.delta);
41
+ }
42
+ });
43
+
44
+ await session.prompt('List files in the current directory.');
45
+ console.log();
46
+
47
+ // Example extension file (./my-logging-extension.ts):
48
+ /*
49
+ import type { ExtensionAPI } from "shortcutxl";
50
+
51
+ export default function (shortcut: ExtensionAPI) {
52
+ shortcut.on("agent_start", async () => {
53
+ console.log("[Extension] Agent starting");
54
+ });
55
+
56
+ shortcut.on("tool_call", async (event) => {
57
+ console.log(\`[Extension] Tool: \${event.toolName}\`);
58
+ // Return { block: true, reason: "..." } to block execution
59
+ return undefined;
60
+ });
61
+
62
+ shortcut.on("agent_end", async (event) => {
63
+ console.log(\`[Extension] Done, \${event.messages.length} messages\`);
64
+ });
65
+
66
+ // Register a custom tool
67
+ shortcut.registerTool({
68
+ name: "my_tool",
69
+ label: "My Tool",
70
+ description: "Does something useful",
71
+ parameters: Type.Object({
72
+ input: Type.String(),
73
+ }),
74
+ execute: async (_toolCallId, params, _signal, _onUpdate, _ctx) => ({
75
+ content: [{ type: "text", text: \`Processed: \${params.input}\` }],
76
+ details: {},
77
+ }),
78
+ });
79
+
80
+ // Register a command
81
+ shortcut.registerCommand("mycommand", {
82
+ description: "Do something",
83
+ handler: async (args, ctx) => {
84
+ ctx.ui.notify(\`Command executed with: \${args}\`);
85
+ },
86
+ });
87
+ }
88
+ */