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,86 +1,86 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Claude Rules Extension
|
|
3
|
-
*
|
|
4
|
-
* Scans the project's .claude/rules/ folder for rule files and lists them
|
|
5
|
-
* in the system prompt. The agent can then use the read tool to load
|
|
6
|
-
* specific rules when needed.
|
|
7
|
-
*
|
|
8
|
-
* Best practices for .claude/rules/:
|
|
9
|
-
* - Keep rules focused: Each file should cover one topic (e.g., testing.md, api-design.md)
|
|
10
|
-
* - Use descriptive filenames: The filename should indicate what the rules cover
|
|
11
|
-
* - Use conditional rules sparingly: Only add paths frontmatter when rules truly apply to specific file types
|
|
12
|
-
* - Organize with subdirectories: Group related rules (e.g., frontend/, backend/)
|
|
13
|
-
*
|
|
14
|
-
* Usage:
|
|
15
|
-
* 1. Copy this file to ~/.shortcut/agent/extensions/ or your project's .shortcut/extensions/
|
|
16
|
-
* 2. Create .claude/rules/ folder in your project root
|
|
17
|
-
* 3. Add .md files with your rules
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
import * as fs from 'node:fs';
|
|
21
|
-
import * as path from 'node:path';
|
|
22
|
-
import type { ExtensionAPI } from 'shortcutxl';
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Recursively find all .md files in a directory
|
|
26
|
-
*/
|
|
27
|
-
function findMarkdownFiles(dir: string, basePath: string = ''): string[] {
|
|
28
|
-
const results: string[] = [];
|
|
29
|
-
|
|
30
|
-
if (!fs.existsSync(dir)) {
|
|
31
|
-
return results;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
35
|
-
|
|
36
|
-
for (const entry of entries) {
|
|
37
|
-
const relativePath = basePath ? `${basePath}/${entry.name}` : entry.name;
|
|
38
|
-
|
|
39
|
-
if (entry.isDirectory()) {
|
|
40
|
-
results.push(...findMarkdownFiles(path.join(dir, entry.name), relativePath));
|
|
41
|
-
} else if (entry.isFile() && entry.name.endsWith('.md')) {
|
|
42
|
-
results.push(relativePath);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return results;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export default function claudeRulesExtension(shortcut: ExtensionAPI) {
|
|
50
|
-
let ruleFiles: string[] = [];
|
|
51
|
-
let rulesDir: string = '';
|
|
52
|
-
|
|
53
|
-
// Scan for rules on session start
|
|
54
|
-
shortcut.on('session_start', async (_event, ctx) => {
|
|
55
|
-
rulesDir = path.join(ctx.cwd, '.claude', 'rules');
|
|
56
|
-
ruleFiles = findMarkdownFiles(rulesDir);
|
|
57
|
-
|
|
58
|
-
if (ruleFiles.length > 0) {
|
|
59
|
-
ctx.ui.notify(`Found ${ruleFiles.length} rule(s) in .claude/rules/`, 'info');
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
// Append available rules to system prompt
|
|
64
|
-
shortcut.on('before_agent_start', async (event) => {
|
|
65
|
-
if (ruleFiles.length === 0) {
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const rulesList = ruleFiles.map((f) => `- .claude/rules/${f}`).join('\n');
|
|
70
|
-
|
|
71
|
-
return {
|
|
72
|
-
systemPrompt:
|
|
73
|
-
event.systemPrompt +
|
|
74
|
-
`
|
|
75
|
-
|
|
76
|
-
## Project Rules
|
|
77
|
-
|
|
78
|
-
The following project rules are available in .claude/rules/:
|
|
79
|
-
|
|
80
|
-
${rulesList}
|
|
81
|
-
|
|
82
|
-
When working on tasks related to these rules, use the read tool to load the relevant rule files for guidance.
|
|
83
|
-
`
|
|
84
|
-
};
|
|
85
|
-
});
|
|
86
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Claude Rules Extension
|
|
3
|
+
*
|
|
4
|
+
* Scans the project's .claude/rules/ folder for rule files and lists them
|
|
5
|
+
* in the system prompt. The agent can then use the read tool to load
|
|
6
|
+
* specific rules when needed.
|
|
7
|
+
*
|
|
8
|
+
* Best practices for .claude/rules/:
|
|
9
|
+
* - Keep rules focused: Each file should cover one topic (e.g., testing.md, api-design.md)
|
|
10
|
+
* - Use descriptive filenames: The filename should indicate what the rules cover
|
|
11
|
+
* - Use conditional rules sparingly: Only add paths frontmatter when rules truly apply to specific file types
|
|
12
|
+
* - Organize with subdirectories: Group related rules (e.g., frontend/, backend/)
|
|
13
|
+
*
|
|
14
|
+
* Usage:
|
|
15
|
+
* 1. Copy this file to ~/.shortcut/agent/extensions/ or your project's .shortcut/extensions/
|
|
16
|
+
* 2. Create .claude/rules/ folder in your project root
|
|
17
|
+
* 3. Add .md files with your rules
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import * as fs from 'node:fs';
|
|
21
|
+
import * as path from 'node:path';
|
|
22
|
+
import type { ExtensionAPI } from 'shortcutxl';
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Recursively find all .md files in a directory
|
|
26
|
+
*/
|
|
27
|
+
function findMarkdownFiles(dir: string, basePath: string = ''): string[] {
|
|
28
|
+
const results: string[] = [];
|
|
29
|
+
|
|
30
|
+
if (!fs.existsSync(dir)) {
|
|
31
|
+
return results;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
35
|
+
|
|
36
|
+
for (const entry of entries) {
|
|
37
|
+
const relativePath = basePath ? `${basePath}/${entry.name}` : entry.name;
|
|
38
|
+
|
|
39
|
+
if (entry.isDirectory()) {
|
|
40
|
+
results.push(...findMarkdownFiles(path.join(dir, entry.name), relativePath));
|
|
41
|
+
} else if (entry.isFile() && entry.name.endsWith('.md')) {
|
|
42
|
+
results.push(relativePath);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return results;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export default function claudeRulesExtension(shortcut: ExtensionAPI) {
|
|
50
|
+
let ruleFiles: string[] = [];
|
|
51
|
+
let rulesDir: string = '';
|
|
52
|
+
|
|
53
|
+
// Scan for rules on session start
|
|
54
|
+
shortcut.on('session_start', async (_event, ctx) => {
|
|
55
|
+
rulesDir = path.join(ctx.cwd, '.claude', 'rules');
|
|
56
|
+
ruleFiles = findMarkdownFiles(rulesDir);
|
|
57
|
+
|
|
58
|
+
if (ruleFiles.length > 0) {
|
|
59
|
+
ctx.ui.notify(`Found ${ruleFiles.length} rule(s) in .claude/rules/`, 'info');
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
// Append available rules to system prompt
|
|
64
|
+
shortcut.on('before_agent_start', async (event) => {
|
|
65
|
+
if (ruleFiles.length === 0) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const rulesList = ruleFiles.map((f) => `- .claude/rules/${f}`).join('\n');
|
|
70
|
+
|
|
71
|
+
return {
|
|
72
|
+
systemPrompt:
|
|
73
|
+
event.systemPrompt +
|
|
74
|
+
`
|
|
75
|
+
|
|
76
|
+
## Project Rules
|
|
77
|
+
|
|
78
|
+
The following project rules are available in .claude/rules/:
|
|
79
|
+
|
|
80
|
+
${rulesList}
|
|
81
|
+
|
|
82
|
+
When working on tasks related to these rules, use the read tool to load the relevant rule files for guidance.
|
|
83
|
+
`
|
|
84
|
+
};
|
|
85
|
+
});
|
|
86
|
+
}
|
|
@@ -1,75 +1,75 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Commands Extension
|
|
3
|
-
*
|
|
4
|
-
* Demonstrates the shortcut.getCommands() API by providing a /commands command
|
|
5
|
-
* that lists all available slash commands in the current session.
|
|
6
|
-
*
|
|
7
|
-
* Usage:
|
|
8
|
-
* 1. Copy this file to ~/.shortcut/agent/extensions/ or your project's .shortcut/extensions/
|
|
9
|
-
* 2. Use /commands to see available commands
|
|
10
|
-
* 3. Use /commands extensions to filter by source
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import type { ExtensionAPI, SlashCommandInfo } from 'shortcutxl';
|
|
14
|
-
|
|
15
|
-
export default function commandsExtension(shortcut: ExtensionAPI) {
|
|
16
|
-
shortcut.registerCommand('commands', {
|
|
17
|
-
description: 'List available slash commands',
|
|
18
|
-
getArgumentCompletions: (prefix) => {
|
|
19
|
-
const sources = ['extension', 'prompt', 'skill'];
|
|
20
|
-
const filtered = sources.filter((s) => s.startsWith(prefix));
|
|
21
|
-
return filtered.length > 0 ? filtered.map((s) => ({ value: s, label: s })) : null;
|
|
22
|
-
},
|
|
23
|
-
handler: async (args, ctx) => {
|
|
24
|
-
const commands = shortcut.getCommands();
|
|
25
|
-
const sourceFilter = args.trim() as 'extension' | 'prompt' | 'skill' | '';
|
|
26
|
-
|
|
27
|
-
// Filter by source if specified
|
|
28
|
-
const filtered = sourceFilter ? commands.filter((c) => c.source === sourceFilter) : commands;
|
|
29
|
-
|
|
30
|
-
if (filtered.length === 0) {
|
|
31
|
-
ctx.ui.notify(
|
|
32
|
-
sourceFilter ? `No ${sourceFilter} commands found` : 'No commands found',
|
|
33
|
-
'info'
|
|
34
|
-
);
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// Build selection items grouped by source
|
|
39
|
-
const formatCommand = (cmd: SlashCommandInfo): string => {
|
|
40
|
-
const desc = cmd.description ? ` - ${cmd.description}` : '';
|
|
41
|
-
return `/${cmd.name}${desc}`;
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
const items: string[] = [];
|
|
45
|
-
const sources: Array<{ key: 'extension' | 'prompt' | 'skill'; label: string }> = [
|
|
46
|
-
{ key: 'extension', label: 'Extensions' },
|
|
47
|
-
{ key: 'prompt', label: 'Prompts' },
|
|
48
|
-
{ key: 'skill', label: 'Skills' }
|
|
49
|
-
];
|
|
50
|
-
|
|
51
|
-
for (const { key, label } of sources) {
|
|
52
|
-
const cmds = filtered.filter((c) => c.source === key);
|
|
53
|
-
if (cmds.length > 0) {
|
|
54
|
-
items.push(`--- ${label} ---`);
|
|
55
|
-
items.push(...cmds.map(formatCommand));
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// Show in a selector (user can scroll and see all commands)
|
|
60
|
-
const selected = await ctx.ui.select('Available Commands', items);
|
|
61
|
-
|
|
62
|
-
// If user selected a command (not a header), offer to show its path
|
|
63
|
-
if (selected && !selected.startsWith('---')) {
|
|
64
|
-
const cmdName = selected.split(' - ')[0].slice(1); // Remove leading /
|
|
65
|
-
const cmd = commands.find((c) => c.name === cmdName);
|
|
66
|
-
if (cmd?.path) {
|
|
67
|
-
const showPath = await ctx.ui.confirm(cmd.name, `View source path?\n${cmd.path}`);
|
|
68
|
-
if (showPath) {
|
|
69
|
-
ctx.ui.notify(cmd.path, 'info');
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Commands Extension
|
|
3
|
+
*
|
|
4
|
+
* Demonstrates the shortcut.getCommands() API by providing a /commands command
|
|
5
|
+
* that lists all available slash commands in the current session.
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* 1. Copy this file to ~/.shortcut/agent/extensions/ or your project's .shortcut/extensions/
|
|
9
|
+
* 2. Use /commands to see available commands
|
|
10
|
+
* 3. Use /commands extensions to filter by source
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import type { ExtensionAPI, SlashCommandInfo } from 'shortcutxl';
|
|
14
|
+
|
|
15
|
+
export default function commandsExtension(shortcut: ExtensionAPI) {
|
|
16
|
+
shortcut.registerCommand('commands', {
|
|
17
|
+
description: 'List available slash commands',
|
|
18
|
+
getArgumentCompletions: (prefix) => {
|
|
19
|
+
const sources = ['extension', 'prompt', 'skill'];
|
|
20
|
+
const filtered = sources.filter((s) => s.startsWith(prefix));
|
|
21
|
+
return filtered.length > 0 ? filtered.map((s) => ({ value: s, label: s })) : null;
|
|
22
|
+
},
|
|
23
|
+
handler: async (args, ctx) => {
|
|
24
|
+
const commands = shortcut.getCommands();
|
|
25
|
+
const sourceFilter = args.trim() as 'extension' | 'prompt' | 'skill' | '';
|
|
26
|
+
|
|
27
|
+
// Filter by source if specified
|
|
28
|
+
const filtered = sourceFilter ? commands.filter((c) => c.source === sourceFilter) : commands;
|
|
29
|
+
|
|
30
|
+
if (filtered.length === 0) {
|
|
31
|
+
ctx.ui.notify(
|
|
32
|
+
sourceFilter ? `No ${sourceFilter} commands found` : 'No commands found',
|
|
33
|
+
'info'
|
|
34
|
+
);
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Build selection items grouped by source
|
|
39
|
+
const formatCommand = (cmd: SlashCommandInfo): string => {
|
|
40
|
+
const desc = cmd.description ? ` - ${cmd.description}` : '';
|
|
41
|
+
return `/${cmd.name}${desc}`;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const items: string[] = [];
|
|
45
|
+
const sources: Array<{ key: 'extension' | 'prompt' | 'skill'; label: string }> = [
|
|
46
|
+
{ key: 'extension', label: 'Extensions' },
|
|
47
|
+
{ key: 'prompt', label: 'Prompts' },
|
|
48
|
+
{ key: 'skill', label: 'Skills' }
|
|
49
|
+
];
|
|
50
|
+
|
|
51
|
+
for (const { key, label } of sources) {
|
|
52
|
+
const cmds = filtered.filter((c) => c.source === key);
|
|
53
|
+
if (cmds.length > 0) {
|
|
54
|
+
items.push(`--- ${label} ---`);
|
|
55
|
+
items.push(...cmds.map(formatCommand));
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Show in a selector (user can scroll and see all commands)
|
|
60
|
+
const selected = await ctx.ui.select('Available Commands', items);
|
|
61
|
+
|
|
62
|
+
// If user selected a command (not a header), offer to show its path
|
|
63
|
+
if (selected && !selected.startsWith('---')) {
|
|
64
|
+
const cmdName = selected.split(' - ')[0].slice(1); // Remove leading /
|
|
65
|
+
const cmd = commands.find((c) => c.name === cmdName);
|
|
66
|
+
if (cmd?.path) {
|
|
67
|
+
const showPath = await ctx.ui.confirm(cmd.name, `View source path?\n${cmd.path}`);
|
|
68
|
+
if (showPath) {
|
|
69
|
+
ctx.ui.notify(cmd.path, 'info');
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
}
|
|
@@ -1,59 +1,59 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Confirm Destructive Actions Extension
|
|
3
|
-
*
|
|
4
|
-
* Prompts for confirmation before destructive session actions (clear, switch, branch).
|
|
5
|
-
* Demonstrates how to cancel session events using the before_* events.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import type { ExtensionAPI, SessionBeforeSwitchEvent, SessionMessageEntry } from 'shortcutxl';
|
|
9
|
-
|
|
10
|
-
export default function (shortcut: ExtensionAPI) {
|
|
11
|
-
shortcut.on('session_before_switch', async (event: SessionBeforeSwitchEvent, ctx) => {
|
|
12
|
-
if (!ctx.hasUI) return;
|
|
13
|
-
|
|
14
|
-
if (event.reason === 'new') {
|
|
15
|
-
const confirmed = await ctx.ui.confirm(
|
|
16
|
-
'Clear session?',
|
|
17
|
-
'This will delete all messages in the current session.'
|
|
18
|
-
);
|
|
19
|
-
|
|
20
|
-
if (!confirmed) {
|
|
21
|
-
ctx.ui.notify('Clear cancelled', 'info');
|
|
22
|
-
return { cancel: true };
|
|
23
|
-
}
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// reason === "resume" - check if there are unsaved changes (messages since last assistant response)
|
|
28
|
-
const entries = ctx.sessionManager.getEntries();
|
|
29
|
-
const hasUnsavedWork = entries.some(
|
|
30
|
-
(e): e is SessionMessageEntry => e.type === 'message' && e.message.role === 'user'
|
|
31
|
-
);
|
|
32
|
-
|
|
33
|
-
if (hasUnsavedWork) {
|
|
34
|
-
const confirmed = await ctx.ui.confirm(
|
|
35
|
-
'Switch session?',
|
|
36
|
-
'You have messages in the current session. Switch anyway?'
|
|
37
|
-
);
|
|
38
|
-
|
|
39
|
-
if (!confirmed) {
|
|
40
|
-
ctx.ui.notify('Switch cancelled', 'info');
|
|
41
|
-
return { cancel: true };
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
shortcut.on('session_before_fork', async (event, ctx) => {
|
|
47
|
-
if (!ctx.hasUI) return;
|
|
48
|
-
|
|
49
|
-
const choice = await ctx.ui.select(`Fork from entry ${event.entryId.slice(0, 8)}?`, [
|
|
50
|
-
'Yes, create fork',
|
|
51
|
-
'No, stay in current session'
|
|
52
|
-
]);
|
|
53
|
-
|
|
54
|
-
if (choice !== 'Yes, create fork') {
|
|
55
|
-
ctx.ui.notify('Fork cancelled', 'info');
|
|
56
|
-
return { cancel: true };
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Confirm Destructive Actions Extension
|
|
3
|
+
*
|
|
4
|
+
* Prompts for confirmation before destructive session actions (clear, switch, branch).
|
|
5
|
+
* Demonstrates how to cancel session events using the before_* events.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { ExtensionAPI, SessionBeforeSwitchEvent, SessionMessageEntry } from 'shortcutxl';
|
|
9
|
+
|
|
10
|
+
export default function (shortcut: ExtensionAPI) {
|
|
11
|
+
shortcut.on('session_before_switch', async (event: SessionBeforeSwitchEvent, ctx) => {
|
|
12
|
+
if (!ctx.hasUI) return;
|
|
13
|
+
|
|
14
|
+
if (event.reason === 'new') {
|
|
15
|
+
const confirmed = await ctx.ui.confirm(
|
|
16
|
+
'Clear session?',
|
|
17
|
+
'This will delete all messages in the current session.'
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
if (!confirmed) {
|
|
21
|
+
ctx.ui.notify('Clear cancelled', 'info');
|
|
22
|
+
return { cancel: true };
|
|
23
|
+
}
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// reason === "resume" - check if there are unsaved changes (messages since last assistant response)
|
|
28
|
+
const entries = ctx.sessionManager.getEntries();
|
|
29
|
+
const hasUnsavedWork = entries.some(
|
|
30
|
+
(e): e is SessionMessageEntry => e.type === 'message' && e.message.role === 'user'
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
if (hasUnsavedWork) {
|
|
34
|
+
const confirmed = await ctx.ui.confirm(
|
|
35
|
+
'Switch session?',
|
|
36
|
+
'You have messages in the current session. Switch anyway?'
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
if (!confirmed) {
|
|
40
|
+
ctx.ui.notify('Switch cancelled', 'info');
|
|
41
|
+
return { cancel: true };
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
shortcut.on('session_before_fork', async (event, ctx) => {
|
|
47
|
+
if (!ctx.hasUI) return;
|
|
48
|
+
|
|
49
|
+
const choice = await ctx.ui.select(`Fork from entry ${event.entryId.slice(0, 8)}?`, [
|
|
50
|
+
'Yes, create fork',
|
|
51
|
+
'No, stay in current session'
|
|
52
|
+
]);
|
|
53
|
+
|
|
54
|
+
if (choice !== 'Yes, create fork') {
|
|
55
|
+
ctx.ui.notify('Fork cancelled', 'info');
|
|
56
|
+
return { cancel: true };
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|