@bastani/atomic 0.8.28-alpha.1 → 0.8.28-alpha.2
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/CHANGELOG.md +53 -0
- package/README.md +120 -118
- package/dist/builtin/intercom/package.json +1 -1
- package/dist/builtin/mcp/package.json +1 -1
- package/dist/builtin/subagents/package.json +1 -1
- package/dist/builtin/web-access/package.json +1 -1
- package/dist/builtin/workflows/CHANGELOG.md +8 -0
- package/dist/builtin/workflows/builtin/open-claude-design.ts +150 -13
- package/dist/builtin/workflows/package.json +1 -1
- package/dist/builtin/workflows/src/tui/chat-surface.ts +32 -33
- package/dist/builtin/workflows/src/tui/run-detail.ts +11 -4
- package/dist/builtin/workflows/src/tui/status-list.ts +32 -2
- package/dist/cli/args.d.ts +4 -0
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +35 -0
- package/dist/cli/args.js.map +1 -1
- package/dist/cli/project-trust.d.ts +10 -0
- package/dist/cli/project-trust.d.ts.map +1 -0
- package/dist/cli/project-trust.js +36 -0
- package/dist/cli/project-trust.js.map +1 -0
- package/dist/cli/startup-ui.d.ts +7 -0
- package/dist/cli/startup-ui.d.ts.map +1 -0
- package/dist/cli/startup-ui.js +57 -0
- package/dist/cli/startup-ui.js.map +1 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +24 -3
- package/dist/config.js.map +1 -1
- package/dist/core/agent-session-runtime.d.ts +3 -1
- package/dist/core/agent-session-runtime.d.ts.map +1 -1
- package/dist/core/agent-session-runtime.js +1 -0
- package/dist/core/agent-session-runtime.js.map +1 -1
- package/dist/core/agent-session-services.d.ts +2 -1
- package/dist/core/agent-session-services.d.ts.map +1 -1
- package/dist/core/agent-session-services.js +2 -2
- package/dist/core/agent-session-services.js.map +1 -1
- package/dist/core/agent-session.d.ts +5 -1
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +58 -20
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/auth-storage.d.ts.map +1 -1
- package/dist/core/auth-storage.js +4 -3
- package/dist/core/auth-storage.js.map +1 -1
- package/dist/core/compaction/branch-summarization.d.ts +3 -1
- package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
- package/dist/core/compaction/branch-summarization.js +9 -3
- package/dist/core/compaction/branch-summarization.js.map +1 -1
- package/dist/core/compaction/compaction.d.ts.map +1 -1
- package/dist/core/compaction/compaction.js +18 -24
- package/dist/core/compaction/compaction.js.map +1 -1
- package/dist/core/compaction/utils.d.ts +1 -1
- package/dist/core/compaction/utils.d.ts.map +1 -1
- package/dist/core/compaction/utils.js +1 -1
- package/dist/core/compaction/utils.js.map +1 -1
- package/dist/core/experimental.d.ts +2 -0
- package/dist/core/experimental.d.ts.map +1 -0
- package/dist/core/experimental.js +5 -0
- package/dist/core/experimental.js.map +1 -0
- package/dist/core/export-html/template.js +19 -6
- package/dist/core/extensions/index.d.ts +1 -1
- package/dist/core/extensions/index.d.ts.map +1 -1
- package/dist/core/extensions/index.js.map +1 -1
- package/dist/core/extensions/loader.d.ts +1 -1
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js +6 -4
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/runner.d.ts +11 -4
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +53 -3
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/types.d.ts +34 -4
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/footer-data-provider.d.ts +2 -0
- package/dist/core/footer-data-provider.d.ts.map +1 -1
- package/dist/core/footer-data-provider.js +27 -1
- package/dist/core/footer-data-provider.js.map +1 -1
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +1 -0
- package/dist/core/index.js.map +1 -1
- package/dist/core/model-registry.d.ts.map +1 -1
- package/dist/core/model-registry.js +64 -7
- package/dist/core/model-registry.js.map +1 -1
- package/dist/core/model-resolver.d.ts.map +1 -1
- package/dist/core/model-resolver.js +1 -0
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/output-guard.d.ts +1 -0
- package/dist/core/output-guard.d.ts.map +1 -1
- package/dist/core/output-guard.js +52 -22
- package/dist/core/output-guard.js.map +1 -1
- package/dist/core/package-manager.d.ts +1 -0
- package/dist/core/package-manager.d.ts.map +1 -1
- package/dist/core/package-manager.js +20 -8
- package/dist/core/package-manager.js.map +1 -1
- package/dist/core/project-trust.d.ts +15 -0
- package/dist/core/project-trust.d.ts.map +1 -0
- package/dist/core/project-trust.js +58 -0
- package/dist/core/project-trust.js.map +1 -0
- package/dist/core/prompt-templates.d.ts +5 -4
- package/dist/core/prompt-templates.d.ts.map +1 -1
- package/dist/core/prompt-templates.js +30 -29
- package/dist/core/prompt-templates.js.map +1 -1
- package/dist/core/provider-attribution.d.ts +4 -0
- package/dist/core/provider-attribution.d.ts.map +1 -0
- package/dist/core/provider-attribution.js +73 -0
- package/dist/core/provider-attribution.js.map +1 -0
- package/dist/core/provider-display-names.d.ts.map +1 -1
- package/dist/core/provider-display-names.js +3 -0
- package/dist/core/provider-display-names.js.map +1 -1
- package/dist/core/resolve-config-value.d.ts +9 -1
- package/dist/core/resolve-config-value.d.ts.map +1 -1
- package/dist/core/resolve-config-value.js +134 -11
- package/dist/core/resolve-config-value.js.map +1 -1
- package/dist/core/resource-loader.d.ts +12 -2
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +108 -18
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +12 -42
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/session-manager.d.ts +6 -7
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +99 -35
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/settings-manager.d.ts +15 -2
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +69 -10
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/slash-commands.d.ts.map +1 -1
- package/dist/core/slash-commands.js +1 -0
- package/dist/core/slash-commands.js.map +1 -1
- package/dist/core/system-prompt.d.ts.map +1 -1
- package/dist/core/system-prompt.js +0 -3
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +2 -1
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/edit.d.ts.map +1 -1
- package/dist/core/tools/edit.js +7 -10
- package/dist/core/tools/edit.js.map +1 -1
- package/dist/core/tools/find.d.ts.map +1 -1
- package/dist/core/tools/find.js +1 -1
- package/dist/core/tools/find.js.map +1 -1
- package/dist/core/tools/grep.d.ts.map +1 -1
- package/dist/core/tools/grep.js +1 -1
- package/dist/core/tools/grep.js.map +1 -1
- package/dist/core/tools/ls.d.ts.map +1 -1
- package/dist/core/tools/ls.js +1 -1
- package/dist/core/tools/ls.js.map +1 -1
- package/dist/core/tools/oversized-tool-result.d.ts +53 -0
- package/dist/core/tools/oversized-tool-result.d.ts.map +1 -0
- package/dist/core/tools/oversized-tool-result.js +206 -0
- package/dist/core/tools/oversized-tool-result.js.map +1 -0
- package/dist/core/tools/read.d.ts +12 -0
- package/dist/core/tools/read.d.ts.map +1 -1
- package/dist/core/tools/read.js +99 -34
- package/dist/core/tools/read.js.map +1 -1
- package/dist/core/tools/render-utils.d.ts +6 -0
- package/dist/core/tools/render-utils.d.ts.map +1 -1
- package/dist/core/tools/render-utils.js +17 -1
- package/dist/core/tools/render-utils.js.map +1 -1
- package/dist/core/tools/tool-definition-wrapper.d.ts +6 -0
- package/dist/core/tools/tool-definition-wrapper.d.ts.map +1 -1
- package/dist/core/tools/tool-definition-wrapper.js +2 -0
- package/dist/core/tools/tool-definition-wrapper.js.map +1 -1
- package/dist/core/tools/tool-limits.d.ts +25 -0
- package/dist/core/tools/tool-limits.d.ts.map +1 -0
- package/dist/core/tools/tool-limits.js +25 -0
- package/dist/core/tools/tool-limits.js.map +1 -0
- package/dist/core/tools/write.d.ts.map +1 -1
- package/dist/core/tools/write.js +1 -1
- package/dist/core/tools/write.js.map +1 -1
- package/dist/core/trust-manager.d.ts +31 -0
- package/dist/core/trust-manager.d.ts.map +1 -0
- package/dist/core/trust-manager.js +196 -0
- package/dist/core/trust-manager.js.map +1 -0
- package/dist/index.d.ts +9 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +142 -30
- package/dist/main.js.map +1 -1
- package/dist/migrations.d.ts +3 -1
- package/dist/migrations.d.ts.map +1 -1
- package/dist/migrations.js +325 -7
- package/dist/migrations.js.map +1 -1
- package/dist/modes/index.d.ts +1 -1
- package/dist/modes/index.d.ts.map +1 -1
- package/dist/modes/index.js.map +1 -1
- package/dist/modes/interactive/components/bash-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/bash-execution.js +2 -2
- package/dist/modes/interactive/components/bash-execution.js.map +1 -1
- package/dist/modes/interactive/components/footer.d.ts.map +1 -1
- package/dist/modes/interactive/components/footer.js +6 -0
- package/dist/modes/interactive/components/footer.js.map +1 -1
- package/dist/modes/interactive/components/index.d.ts +1 -0
- package/dist/modes/interactive/components/index.d.ts.map +1 -1
- package/dist/modes/interactive/components/index.js +1 -0
- package/dist/modes/interactive/components/index.js.map +1 -1
- package/dist/modes/interactive/components/login-dialog.d.ts +1 -1
- package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -1
- package/dist/modes/interactive/components/login-dialog.js +9 -16
- package/dist/modes/interactive/components/login-dialog.js.map +1 -1
- package/dist/modes/interactive/components/settings-selector.d.ts +3 -1
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector.js +20 -0
- package/dist/modes/interactive/components/settings-selector.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +22 -0
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/components/trust-selector.d.ts +23 -0
- package/dist/modes/interactive/components/trust-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/trust-selector.js +85 -0
- package/dist/modes/interactive/components/trust-selector.js.map +1 -0
- package/dist/modes/interactive/components/user-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/user-message.js +1 -1
- package/dist/modes/interactive/components/user-message.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +9 -0
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +130 -9
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
- package/dist/modes/interactive/theme/theme.js +10 -0
- package/dist/modes/interactive/theme/theme.js.map +1 -1
- package/dist/modes/print-mode.d.ts.map +1 -1
- package/dist/modes/print-mode.js +1 -0
- package/dist/modes/print-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-client.d.ts +3 -0
- package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-client.js +50 -6
- package/dist/modes/rpc/rpc-client.js.map +1 -1
- package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-mode.js +23 -4
- package/dist/modes/rpc/rpc-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-types.d.ts +1 -0
- package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-types.js.map +1 -1
- package/dist/package-manager-cli.d.ts +6 -2
- package/dist/package-manager-cli.d.ts.map +1 -1
- package/dist/package-manager-cli.js +104 -10
- package/dist/package-manager-cli.js.map +1 -1
- package/dist/utils/changelog.d.ts +1 -0
- package/dist/utils/changelog.d.ts.map +1 -1
- package/dist/utils/changelog.js +72 -0
- package/dist/utils/changelog.js.map +1 -1
- package/dist/utils/deprecation.d.ts +4 -0
- package/dist/utils/deprecation.d.ts.map +1 -0
- package/dist/utils/deprecation.js +13 -0
- package/dist/utils/deprecation.js.map +1 -0
- package/dist/utils/git.d.ts.map +1 -1
- package/dist/utils/git.js +54 -22
- package/dist/utils/git.js.map +1 -1
- package/dist/utils/json.d.ts +3 -0
- package/dist/utils/json.d.ts.map +1 -0
- package/dist/utils/json.js +7 -0
- package/dist/utils/json.js.map +1 -0
- package/dist/utils/open-browser.d.ts +9 -0
- package/dist/utils/open-browser.d.ts.map +1 -0
- package/dist/utils/open-browser.js +22 -0
- package/dist/utils/open-browser.js.map +1 -0
- package/docs/containerization.md +111 -0
- package/docs/custom-provider.md +9 -9
- package/docs/development.md +1 -1
- package/docs/docs.json +2 -0
- package/docs/extensions.md +40 -4
- package/docs/index.md +2 -0
- package/docs/models.md +10 -10
- package/docs/packages.md +1 -1
- package/docs/prompt-templates.md +9 -2
- package/docs/providers.md +18 -5
- package/docs/quickstart.md +1 -0
- package/docs/rpc.md +3 -2
- package/docs/sdk.md +5 -0
- package/docs/security.md +56 -0
- package/docs/session-format.md +2 -2
- package/docs/sessions.md +8 -0
- package/docs/settings.md +21 -4
- package/docs/skills.md +1 -1
- package/docs/terminal-setup.md +44 -2
- package/docs/themes.md +1 -1
- package/docs/tmux.md +4 -2
- package/docs/tui.md +14 -5
- package/docs/usage.md +17 -3
- package/examples/README.md +1 -1
- package/examples/extensions/README.md +8 -5
- package/examples/extensions/bash-spawn-hook.ts +1 -1
- package/examples/extensions/built-in-tool-renderer.ts +1 -1
- package/examples/extensions/claude-rules.ts +1 -1
- package/examples/extensions/commands.ts +1 -1
- package/examples/extensions/custom-header.ts +1 -1
- package/examples/extensions/custom-provider-anthropic/index.ts +3 -3
- package/examples/extensions/custom-provider-anthropic/package-lock.json +4 -4
- package/examples/extensions/custom-provider-anthropic/package.json +6 -6
- package/examples/extensions/custom-provider-gitlab-duo/index.ts +55 -4
- package/examples/extensions/custom-provider-gitlab-duo/package.json +3 -3
- package/examples/extensions/doom-overlay/README.md +1 -1
- package/examples/extensions/doom-overlay/index.ts +2 -2
- package/examples/extensions/git-merge-and-resolve.ts +115 -0
- package/examples/extensions/gondolin/index.ts +523 -0
- package/examples/extensions/gondolin/package-lock.json +185 -0
- package/examples/extensions/gondolin/package.json +19 -0
- package/examples/extensions/handoff.ts +1 -1
- package/examples/extensions/hidden-thinking-label.ts +1 -1
- package/examples/extensions/inline-bash.ts +2 -2
- package/examples/extensions/input-transform-streaming.ts +39 -0
- package/examples/extensions/input-transform.ts +3 -3
- package/examples/extensions/interactive-shell.ts +2 -2
- package/examples/extensions/mac-system-theme.ts +2 -2
- package/examples/extensions/minimal-mode.ts +1 -1
- package/examples/extensions/modal-editor.ts +1 -1
- package/examples/extensions/model-status.ts +1 -1
- package/examples/extensions/overlay-qa-tests.ts +198 -179
- package/examples/extensions/overlay-test.ts +1 -1
- package/examples/extensions/pirate.ts +1 -1
- package/examples/extensions/preset.ts +14 -12
- package/examples/extensions/project-trust.ts +64 -0
- package/examples/extensions/prompt-customizer.ts +1 -1
- package/examples/extensions/qna.ts +1 -1
- package/examples/extensions/question.ts +1 -1
- package/examples/extensions/questionnaire.ts +1 -1
- package/examples/extensions/rainbow-editor.ts +1 -1
- package/examples/extensions/sandbox/index.ts +16 -14
- package/examples/extensions/sandbox/package-lock.json +90 -90
- package/examples/extensions/sandbox/package.json +17 -17
- package/examples/extensions/snake.ts +1 -1
- package/examples/extensions/space-invaders.ts +1 -1
- package/examples/extensions/ssh.ts +2 -2
- package/examples/extensions/subagent/README.md +13 -13
- package/examples/extensions/subagent/agents.ts +4 -2
- package/examples/extensions/subagent/index.ts +6 -6
- package/examples/extensions/summarize.ts +1 -1
- package/examples/extensions/tic-tac-toe.ts +1 -1
- package/examples/extensions/titlebar-spinner.ts +1 -1
- package/examples/extensions/todo.ts +1 -1
- package/examples/extensions/tool-override.ts +1 -1
- package/examples/extensions/tools.ts +6 -1
- package/examples/extensions/with-deps/package-lock.json +4 -4
- package/examples/extensions/with-deps/package.json +7 -7
- package/examples/extensions/working-indicator.ts +4 -4
- package/examples/extensions/working-message-test.ts +1 -1
- package/examples/sdk/01-minimal.ts +1 -1
- package/examples/sdk/03-custom-prompt.ts +1 -1
- package/examples/sdk/04-skills.ts +1 -1
- package/examples/sdk/06-extensions.ts +2 -2
- package/examples/sdk/08-prompt-templates.ts +1 -1
- package/examples/sdk/09-api-keys-and-oauth.ts +2 -2
- package/examples/sdk/README.md +2 -2
- package/package.json +4 -4
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Merge and Resolve
|
|
3
|
+
*
|
|
4
|
+
* Keeps the working branch up to date with its upstream tracking ref.
|
|
5
|
+
* After each agent turn, fetches and merges. Clean merges complete
|
|
6
|
+
* silently. When conflicts arise, the working tree is left dirty and
|
|
7
|
+
* the agent receives a follow-up message listing each conflict block
|
|
8
|
+
* with file, line range, and ours/theirs sections so it can resolve them.
|
|
9
|
+
* Also re-sends unresolved conflicts from a previous incomplete merge.
|
|
10
|
+
*
|
|
11
|
+
* Start Atomic with this extension:
|
|
12
|
+
* atomic -e ./examples/extensions/git-merge-and-resolve.ts
|
|
13
|
+
*/
|
|
14
|
+
import { createReadStream } from "node:fs";
|
|
15
|
+
import { join } from "node:path";
|
|
16
|
+
import { createInterface } from "node:readline";
|
|
17
|
+
import type { ExtensionAPI } from "@bastani/atomic";
|
|
18
|
+
|
|
19
|
+
interface ConflictBlock {
|
|
20
|
+
file: string;
|
|
21
|
+
startLine: number;
|
|
22
|
+
separatorLine: number;
|
|
23
|
+
endLine: number;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Parse conflict markers from working tree files with unmerged paths. */
|
|
27
|
+
async function findConflicts(pi: ExtensionAPI, cwd: string): Promise<ConflictBlock[]> {
|
|
28
|
+
const { stdout, code } = await pi.exec("git", ["diff", "--name-only", "--diff-filter=U"]);
|
|
29
|
+
if (code !== 0 || !stdout.trim()) return [];
|
|
30
|
+
|
|
31
|
+
const blocks: ConflictBlock[] = [];
|
|
32
|
+
for (const file of stdout.trim().split("\n")) {
|
|
33
|
+
try {
|
|
34
|
+
const rl = createInterface({ input: createReadStream(join(cwd, file), "utf-8") });
|
|
35
|
+
let lineNo = 0;
|
|
36
|
+
let blockStart: number | undefined;
|
|
37
|
+
let separatorLine: number | undefined;
|
|
38
|
+
for await (const line of rl) {
|
|
39
|
+
lineNo++;
|
|
40
|
+
if (line.startsWith("<<<<<<<")) {
|
|
41
|
+
blockStart = lineNo;
|
|
42
|
+
separatorLine = undefined;
|
|
43
|
+
} else if (line.startsWith("=======") && blockStart !== undefined) {
|
|
44
|
+
separatorLine = lineNo;
|
|
45
|
+
} else if (line.startsWith(">>>>>>>") && blockStart !== undefined && separatorLine !== undefined) {
|
|
46
|
+
blocks.push({ file, startLine: blockStart, separatorLine, endLine: lineNo });
|
|
47
|
+
blockStart = undefined;
|
|
48
|
+
separatorLine = undefined;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
} catch {}
|
|
52
|
+
}
|
|
53
|
+
return blocks;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function formatRange(start: number, end: number): string {
|
|
57
|
+
if (start > end) return "empty";
|
|
58
|
+
if (start === end) return `${start}`;
|
|
59
|
+
return `${start}-${end}`;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function formatConflicts(ref: string, blocks: ConflictBlock[]): string {
|
|
63
|
+
const lines = [`Merged ${ref} with conflicts:`, ""];
|
|
64
|
+
for (const b of blocks) {
|
|
65
|
+
const ours = formatRange(b.startLine + 1, b.separatorLine - 1);
|
|
66
|
+
const theirs = formatRange(b.separatorLine + 1, b.endLine - 1);
|
|
67
|
+
lines.push(` ${b.file}:${b.startLine}-${b.endLine} (ours ${ours}, theirs ${theirs})`);
|
|
68
|
+
}
|
|
69
|
+
lines.push("", "Resolve these conflicts.");
|
|
70
|
+
return lines.join("\n");
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export default function (pi: ExtensionAPI) {
|
|
74
|
+
pi.on("agent_end", async (_event, ctx) => {
|
|
75
|
+
const { code: revParseCode } = await pi.exec("git", ["rev-parse", "--git-dir"]);
|
|
76
|
+
if (revParseCode !== 0) return;
|
|
77
|
+
|
|
78
|
+
let ref = "MERGE_HEAD";
|
|
79
|
+
|
|
80
|
+
// If not already in a merge, attempt one
|
|
81
|
+
const { code: mergeHeadCode } = await pi.exec("git", ["rev-parse", "MERGE_HEAD"]);
|
|
82
|
+
if (mergeHeadCode !== 0) {
|
|
83
|
+
// Only attempt a new merge if the working tree is clean
|
|
84
|
+
const { stdout: status } = await pi.exec("git", ["status", "--porcelain"]);
|
|
85
|
+
if (status.trim()) return;
|
|
86
|
+
|
|
87
|
+
const { stdout: upstream, code: upstreamCode } = await pi.exec("git", [
|
|
88
|
+
"rev-parse",
|
|
89
|
+
"--abbrev-ref",
|
|
90
|
+
"--symbolic-full-name",
|
|
91
|
+
"@{u}",
|
|
92
|
+
]);
|
|
93
|
+
if (upstreamCode !== 0) return;
|
|
94
|
+
|
|
95
|
+
ref = upstream.trim();
|
|
96
|
+
const remote = ref.split("/")[0];
|
|
97
|
+
ctx.ui.notify(`git-merge-and-resolve: fetching ${remote}, merging ${ref}`, "info");
|
|
98
|
+
|
|
99
|
+
const { code: fetchCode, stderr: fetchErr } = await pi.exec("git", ["fetch", remote]);
|
|
100
|
+
if (fetchCode !== 0) {
|
|
101
|
+
ctx.ui.notify(`git-merge-and-resolve: fetch failed: ${fetchErr.trim()}`, "warning");
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const { code: mergeCode } = await pi.exec("git", ["merge", "--no-ff", ref]);
|
|
106
|
+
if (mergeCode === 0) return;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Either we just merged with conflicts, or we were already in an unfinished merge
|
|
110
|
+
const conflicts = await findConflicts(pi, ctx.cwd);
|
|
111
|
+
if (conflicts.length === 0) return;
|
|
112
|
+
|
|
113
|
+
pi.sendUserMessage(formatConflicts(ref, conflicts), { deliverAs: "followUp" });
|
|
114
|
+
});
|
|
115
|
+
}
|
|
@@ -0,0 +1,523 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gondolin Tool Routing Example
|
|
3
|
+
*
|
|
4
|
+
* Runs Atomic's built-in tools inside a local Gondolin micro-VM. The host working
|
|
5
|
+
* directory is mounted at /workspace in the guest. File changes under
|
|
6
|
+
* /workspace write through to the host; other guest filesystem changes are
|
|
7
|
+
* isolated to the VM.
|
|
8
|
+
*
|
|
9
|
+
* Setup:
|
|
10
|
+
* cd packages/coding-agent/examples/extensions/gondolin
|
|
11
|
+
* npm install --ignore-scripts
|
|
12
|
+
*
|
|
13
|
+
* Usage:
|
|
14
|
+
* cd /path/to/project
|
|
15
|
+
* atomic -e /path/to/atomic/packages/coding-agent/examples/extensions/gondolin
|
|
16
|
+
*
|
|
17
|
+
* Requirements:
|
|
18
|
+
* - Node.js >= 23.6.0 for @earendil-works/gondolin
|
|
19
|
+
* - QEMU installed (for example, `brew install qemu` on macOS)
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
import path from "node:path";
|
|
23
|
+
import { RealFSProvider, VM } from "@earendil-works/gondolin";
|
|
24
|
+
import type { ExtensionAPI, ExtensionContext } from "@bastani/atomic";
|
|
25
|
+
import {
|
|
26
|
+
type BashOperations,
|
|
27
|
+
createBashTool,
|
|
28
|
+
createEditTool,
|
|
29
|
+
createFindTool,
|
|
30
|
+
createGrepTool,
|
|
31
|
+
createLsTool,
|
|
32
|
+
createReadTool,
|
|
33
|
+
createWriteTool,
|
|
34
|
+
DEFAULT_MAX_BYTES,
|
|
35
|
+
type EditOperations,
|
|
36
|
+
type FindOperations,
|
|
37
|
+
formatSize,
|
|
38
|
+
type GrepToolDetails,
|
|
39
|
+
type GrepToolInput,
|
|
40
|
+
type LsOperations,
|
|
41
|
+
type ReadOperations,
|
|
42
|
+
truncateHead,
|
|
43
|
+
truncateLine,
|
|
44
|
+
type WriteOperations,
|
|
45
|
+
} from "@bastani/atomic";
|
|
46
|
+
|
|
47
|
+
const GUEST_WORKSPACE = "/workspace";
|
|
48
|
+
const DEFAULT_GREP_LIMIT = 100;
|
|
49
|
+
|
|
50
|
+
type TextToolResult<TDetails> = {
|
|
51
|
+
content: Array<{ type: "text"; text: string }>;
|
|
52
|
+
details: TDetails | undefined;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
function stripAtPrefix(value: string): string {
|
|
56
|
+
return value.startsWith("@") ? value.slice(1) : value;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function toPosix(value: string): string {
|
|
60
|
+
return value.split(path.sep).join(path.posix.sep);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function isInsideHostPath(root: string, value: string): boolean {
|
|
64
|
+
const relativePath = path.relative(root, value);
|
|
65
|
+
return relativePath === "" || (!relativePath.startsWith("..") && !path.isAbsolute(relativePath));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function hostPathToGuest(localCwd: string, hostPath: string): string {
|
|
69
|
+
const relativePath = path.relative(localCwd, hostPath);
|
|
70
|
+
if (!isInsideHostPath(localCwd, hostPath)) return toPosix(hostPath);
|
|
71
|
+
return relativePath ? path.posix.join(GUEST_WORKSPACE, toPosix(relativePath)) : GUEST_WORKSPACE;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function toGuestPath(localCwd: string, inputPath: string): string {
|
|
75
|
+
const trimmed = stripAtPrefix(inputPath.trim());
|
|
76
|
+
if (!trimmed) return GUEST_WORKSPACE;
|
|
77
|
+
if (path.isAbsolute(trimmed)) {
|
|
78
|
+
if (isInsideHostPath(localCwd, trimmed)) return hostPathToGuest(localCwd, trimmed);
|
|
79
|
+
return path.posix.resolve("/", toPosix(trimmed));
|
|
80
|
+
}
|
|
81
|
+
return path.posix.resolve(GUEST_WORKSPACE, toPosix(trimmed));
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function createGondolinReadOps(vm: VM, localCwd: string): ReadOperations {
|
|
85
|
+
return {
|
|
86
|
+
readFile: async (filePath) => vm.fs.readFile(toGuestPath(localCwd, filePath)),
|
|
87
|
+
access: async (filePath) => {
|
|
88
|
+
await vm.fs.access(toGuestPath(localCwd, filePath));
|
|
89
|
+
},
|
|
90
|
+
detectImageMimeType: async (filePath) => {
|
|
91
|
+
const ext = path.posix.extname(toGuestPath(localCwd, filePath)).toLowerCase();
|
|
92
|
+
if (ext === ".png") return "image/png";
|
|
93
|
+
if (ext === ".jpg" || ext === ".jpeg") return "image/jpeg";
|
|
94
|
+
if (ext === ".gif") return "image/gif";
|
|
95
|
+
if (ext === ".webp") return "image/webp";
|
|
96
|
+
return null;
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function createGondolinWriteOps(vm: VM, localCwd: string): WriteOperations {
|
|
102
|
+
return {
|
|
103
|
+
writeFile: async (filePath, content) => {
|
|
104
|
+
await vm.fs.writeFile(toGuestPath(localCwd, filePath), content, { encoding: "utf8" });
|
|
105
|
+
},
|
|
106
|
+
mkdir: async (dirPath) => {
|
|
107
|
+
await vm.fs.mkdir(toGuestPath(localCwd, dirPath), { recursive: true });
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function createGondolinEditOps(vm: VM, localCwd: string): EditOperations {
|
|
113
|
+
const readOps = createGondolinReadOps(vm, localCwd);
|
|
114
|
+
const writeOps = createGondolinWriteOps(vm, localCwd);
|
|
115
|
+
return {
|
|
116
|
+
readFile: readOps.readFile,
|
|
117
|
+
writeFile: writeOps.writeFile,
|
|
118
|
+
access: readOps.access,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function createGondolinLsOps(vm: VM, localCwd: string): LsOperations {
|
|
123
|
+
return {
|
|
124
|
+
exists: async (filePath) => {
|
|
125
|
+
try {
|
|
126
|
+
await vm.fs.access(toGuestPath(localCwd, filePath));
|
|
127
|
+
return true;
|
|
128
|
+
} catch {
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
},
|
|
132
|
+
stat: async (filePath) => vm.fs.stat(toGuestPath(localCwd, filePath)),
|
|
133
|
+
readdir: async (dirPath) => vm.fs.listDir(toGuestPath(localCwd, dirPath)),
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
async function walkGuestFiles(
|
|
138
|
+
vm: VM,
|
|
139
|
+
root: string,
|
|
140
|
+
visit: (guestPath: string, relativePath: string) => Promise<boolean>,
|
|
141
|
+
signal?: AbortSignal,
|
|
142
|
+
): Promise<boolean> {
|
|
143
|
+
if (signal?.aborted) throw new Error("Operation aborted");
|
|
144
|
+
const stat = await vm.fs.stat(root, { signal });
|
|
145
|
+
if (!stat.isDirectory()) return visit(root, path.posix.basename(root));
|
|
146
|
+
|
|
147
|
+
const walkDirectory = async (dir: string, relativeDir: string): Promise<boolean> => {
|
|
148
|
+
if (signal?.aborted) throw new Error("Operation aborted");
|
|
149
|
+
const entries = await vm.fs.listDir(dir, { signal });
|
|
150
|
+
for (const entry of entries) {
|
|
151
|
+
if (entry === ".git" || entry === "node_modules") continue;
|
|
152
|
+
const guestPath = path.posix.join(dir, entry);
|
|
153
|
+
const relativePath = relativeDir ? path.posix.join(relativeDir, entry) : entry;
|
|
154
|
+
let entryStat: Awaited<ReturnType<VM["fs"]["stat"]>>;
|
|
155
|
+
try {
|
|
156
|
+
entryStat = await vm.fs.stat(guestPath, { signal });
|
|
157
|
+
} catch {
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
if (entryStat.isDirectory()) {
|
|
161
|
+
if (!(await walkDirectory(guestPath, relativePath))) return false;
|
|
162
|
+
} else if (!(await visit(guestPath, relativePath))) {
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return true;
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
return walkDirectory(root, "");
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function matchesToolGlob(relativePath: string, pattern: string): boolean {
|
|
173
|
+
const normalizedPattern = toPosix(pattern);
|
|
174
|
+
if (normalizedPattern.includes("/")) {
|
|
175
|
+
return (
|
|
176
|
+
path.posix.matchesGlob(relativePath, normalizedPattern) ||
|
|
177
|
+
path.posix.matchesGlob(relativePath, `**/${normalizedPattern}`)
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
return path.posix.matchesGlob(path.posix.basename(relativePath), normalizedPattern);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function createGondolinFindOps(vm: VM, localCwd: string): FindOperations {
|
|
184
|
+
return {
|
|
185
|
+
exists: async (filePath) => {
|
|
186
|
+
try {
|
|
187
|
+
await vm.fs.access(toGuestPath(localCwd, filePath));
|
|
188
|
+
return true;
|
|
189
|
+
} catch {
|
|
190
|
+
return false;
|
|
191
|
+
}
|
|
192
|
+
},
|
|
193
|
+
glob: async (pattern, cwd, options) => {
|
|
194
|
+
const root = toGuestPath(localCwd, cwd);
|
|
195
|
+
const results: string[] = [];
|
|
196
|
+
await walkGuestFiles(vm, root, async (guestPath, relativePath) => {
|
|
197
|
+
if (results.length >= options.limit) return false;
|
|
198
|
+
if (matchesToolGlob(relativePath, pattern)) results.push(guestPath);
|
|
199
|
+
return results.length < options.limit;
|
|
200
|
+
});
|
|
201
|
+
return results;
|
|
202
|
+
},
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function createLineMatcher(pattern: string, literal: boolean | undefined, ignoreCase: boolean | undefined) {
|
|
207
|
+
if (literal) {
|
|
208
|
+
const needle = ignoreCase ? pattern.toLowerCase() : pattern;
|
|
209
|
+
return (line: string) => (ignoreCase ? line.toLowerCase() : line).includes(needle);
|
|
210
|
+
}
|
|
211
|
+
const regex = new RegExp(pattern, ignoreCase ? "i" : undefined);
|
|
212
|
+
return (line: string) => regex.test(line);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
function appendGrepBlock(params: {
|
|
216
|
+
outputLines: string[];
|
|
217
|
+
lines: string[];
|
|
218
|
+
relativePath: string;
|
|
219
|
+
lineIndex: number;
|
|
220
|
+
contextLines: number;
|
|
221
|
+
}): boolean {
|
|
222
|
+
let linesTruncated = false;
|
|
223
|
+
const start = params.contextLines > 0 ? Math.max(0, params.lineIndex - params.contextLines) : params.lineIndex;
|
|
224
|
+
const end =
|
|
225
|
+
params.contextLines > 0
|
|
226
|
+
? Math.min(params.lines.length - 1, params.lineIndex + params.contextLines)
|
|
227
|
+
: params.lineIndex;
|
|
228
|
+
|
|
229
|
+
for (let index = start; index <= end; index++) {
|
|
230
|
+
const rawLine = params.lines[index] ?? "";
|
|
231
|
+
const { text, wasTruncated } = truncateLine(rawLine.replace(/\r/g, ""));
|
|
232
|
+
if (wasTruncated) linesTruncated = true;
|
|
233
|
+
const separator = index === params.lineIndex ? ":" : "-";
|
|
234
|
+
params.outputLines.push(`${params.relativePath}${separator}${index + 1}${separator} ${text}`);
|
|
235
|
+
}
|
|
236
|
+
return linesTruncated;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
async function executeGondolinGrep(
|
|
240
|
+
vm: VM,
|
|
241
|
+
localCwd: string,
|
|
242
|
+
params: GrepToolInput,
|
|
243
|
+
signal?: AbortSignal,
|
|
244
|
+
): Promise<TextToolResult<GrepToolDetails>> {
|
|
245
|
+
const root = toGuestPath(localCwd, params.path ?? ".");
|
|
246
|
+
const rootStat = await vm.fs.stat(root, { signal });
|
|
247
|
+
const rootIsDirectory = rootStat.isDirectory();
|
|
248
|
+
const matcher = createLineMatcher(params.pattern, params.literal, params.ignoreCase);
|
|
249
|
+
const contextLines = params.context && params.context > 0 ? params.context : 0;
|
|
250
|
+
const effectiveLimit = Math.max(1, params.limit ?? DEFAULT_GREP_LIMIT);
|
|
251
|
+
const outputLines: string[] = [];
|
|
252
|
+
const details: GrepToolDetails = {};
|
|
253
|
+
let matchCount = 0;
|
|
254
|
+
let matchLimitReached = false;
|
|
255
|
+
let linesTruncated = false;
|
|
256
|
+
|
|
257
|
+
await walkGuestFiles(
|
|
258
|
+
vm,
|
|
259
|
+
root,
|
|
260
|
+
async (guestPath, relativePath) => {
|
|
261
|
+
if (matchCount >= effectiveLimit) return false;
|
|
262
|
+
if (params.glob && !matchesToolGlob(relativePath, params.glob)) return true;
|
|
263
|
+
let content: string;
|
|
264
|
+
try {
|
|
265
|
+
content = await vm.fs.readFile(guestPath, { encoding: "utf8", signal });
|
|
266
|
+
} catch {
|
|
267
|
+
return true;
|
|
268
|
+
}
|
|
269
|
+
const lines = content.replace(/\r\n/g, "\n").replace(/\r/g, "\n").split("\n");
|
|
270
|
+
const displayPath = rootIsDirectory ? relativePath : path.posix.basename(guestPath);
|
|
271
|
+
for (let index = 0; index < lines.length; index++) {
|
|
272
|
+
if (signal?.aborted) throw new Error("Operation aborted");
|
|
273
|
+
if (!matcher(lines[index] ?? "")) continue;
|
|
274
|
+
matchCount++;
|
|
275
|
+
if (appendGrepBlock({ outputLines, lines, relativePath: displayPath, lineIndex: index, contextLines })) {
|
|
276
|
+
linesTruncated = true;
|
|
277
|
+
}
|
|
278
|
+
if (matchCount >= effectiveLimit) {
|
|
279
|
+
matchLimitReached = true;
|
|
280
|
+
return false;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
return true;
|
|
284
|
+
},
|
|
285
|
+
signal,
|
|
286
|
+
);
|
|
287
|
+
|
|
288
|
+
if (matchCount === 0) return { content: [{ type: "text", text: "No matches found" }], details: undefined };
|
|
289
|
+
|
|
290
|
+
const rawOutput = outputLines.join("\n");
|
|
291
|
+
const truncation = truncateHead(rawOutput, { maxLines: Number.MAX_SAFE_INTEGER });
|
|
292
|
+
const notices: string[] = [];
|
|
293
|
+
let output = truncation.content;
|
|
294
|
+
|
|
295
|
+
if (matchLimitReached) {
|
|
296
|
+
details.matchLimitReached = effectiveLimit;
|
|
297
|
+
notices.push(`${effectiveLimit} matches limit reached`);
|
|
298
|
+
}
|
|
299
|
+
if (linesTruncated) {
|
|
300
|
+
details.linesTruncated = true;
|
|
301
|
+
notices.push("long lines truncated");
|
|
302
|
+
}
|
|
303
|
+
if (truncation.truncated) {
|
|
304
|
+
details.truncation = truncation;
|
|
305
|
+
notices.push(`${formatSize(DEFAULT_MAX_BYTES)} limit reached`);
|
|
306
|
+
}
|
|
307
|
+
if (notices.length > 0) output += `\n\n[${notices.join(". ")}]`;
|
|
308
|
+
|
|
309
|
+
return {
|
|
310
|
+
content: [{ type: "text", text: output }],
|
|
311
|
+
details: Object.keys(details).length > 0 ? details : undefined,
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
function createGondolinBashOps(vm: VM, localCwd: string, shellPath: string): BashOperations {
|
|
316
|
+
return {
|
|
317
|
+
exec: async (command, cwd, { onData, signal, timeout }) => {
|
|
318
|
+
if (signal?.aborted) throw new Error("aborted");
|
|
319
|
+
const guestCwd = toGuestPath(localCwd, cwd);
|
|
320
|
+
const controller = new AbortController();
|
|
321
|
+
const onAbort = () => controller.abort();
|
|
322
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
323
|
+
|
|
324
|
+
let timedOut = false;
|
|
325
|
+
const timer =
|
|
326
|
+
timeout && timeout > 0
|
|
327
|
+
? setTimeout(() => {
|
|
328
|
+
timedOut = true;
|
|
329
|
+
controller.abort();
|
|
330
|
+
}, timeout * 1000)
|
|
331
|
+
: undefined;
|
|
332
|
+
|
|
333
|
+
try {
|
|
334
|
+
const proc = vm.exec([shellPath, "-lc", command], {
|
|
335
|
+
cwd: guestCwd,
|
|
336
|
+
// Deliberately do not forward the host shell environment into the VM.
|
|
337
|
+
// Atomic authentication and other host secrets stay on the host.
|
|
338
|
+
signal: controller.signal,
|
|
339
|
+
stdout: "pipe",
|
|
340
|
+
stderr: "pipe",
|
|
341
|
+
});
|
|
342
|
+
for await (const chunk of proc.output()) onData(chunk.data);
|
|
343
|
+
const result = await proc;
|
|
344
|
+
return { exitCode: result.exitCode };
|
|
345
|
+
} catch (error) {
|
|
346
|
+
if (signal?.aborted) throw new Error("aborted");
|
|
347
|
+
if (timedOut) throw new Error(`timeout:${timeout}`);
|
|
348
|
+
throw error;
|
|
349
|
+
} finally {
|
|
350
|
+
if (timer) clearTimeout(timer);
|
|
351
|
+
signal?.removeEventListener("abort", onAbort);
|
|
352
|
+
}
|
|
353
|
+
},
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
export default function (pi: ExtensionAPI) {
|
|
358
|
+
const localCwd = process.cwd();
|
|
359
|
+
const localRead = createReadTool(localCwd);
|
|
360
|
+
const localWrite = createWriteTool(localCwd);
|
|
361
|
+
const localEdit = createEditTool(localCwd);
|
|
362
|
+
const localBash = createBashTool(localCwd);
|
|
363
|
+
const localGrep = createGrepTool(localCwd);
|
|
364
|
+
const localFind = createFindTool(localCwd);
|
|
365
|
+
const localLs = createLsTool(localCwd);
|
|
366
|
+
|
|
367
|
+
let vm: VM | undefined;
|
|
368
|
+
let vmStarting: Promise<VM> | undefined;
|
|
369
|
+
let shellPath = "/bin/sh";
|
|
370
|
+
|
|
371
|
+
async function startVm(ctx?: ExtensionContext): Promise<VM> {
|
|
372
|
+
ctx?.ui.setStatus("gondolin", ctx.ui.theme.fg("accent", `Gondolin: starting ${GUEST_WORKSPACE}`));
|
|
373
|
+
const created = await VM.create({
|
|
374
|
+
sessionLabel: `atomic ${path.basename(localCwd)}`,
|
|
375
|
+
vfs: {
|
|
376
|
+
mounts: {
|
|
377
|
+
[GUEST_WORKSPACE]: new RealFSProvider(localCwd),
|
|
378
|
+
},
|
|
379
|
+
},
|
|
380
|
+
});
|
|
381
|
+
const bashProbe = await created.exec(["/bin/sh", "-lc", "command -v bash || true"]);
|
|
382
|
+
shellPath = bashProbe.stdout.trim() || "/bin/sh";
|
|
383
|
+
vm = created;
|
|
384
|
+
ctx?.ui.setStatus(
|
|
385
|
+
"gondolin",
|
|
386
|
+
ctx.ui.theme.fg("accent", `Gondolin: ${created.id.slice(0, 8)} (${GUEST_WORKSPACE})`),
|
|
387
|
+
);
|
|
388
|
+
ctx?.ui.notify(`Gondolin VM ready. ${localCwd} is mounted at ${GUEST_WORKSPACE}.`, "info");
|
|
389
|
+
return created;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
async function ensureVm(ctx?: ExtensionContext): Promise<VM> {
|
|
393
|
+
if (vm) return vm;
|
|
394
|
+
if (!vmStarting) {
|
|
395
|
+
vmStarting = startVm(ctx).finally(() => {
|
|
396
|
+
vmStarting = undefined;
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
return vmStarting;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
pi.on("session_start", async (_event, ctx) => {
|
|
403
|
+
await ensureVm(ctx);
|
|
404
|
+
});
|
|
405
|
+
|
|
406
|
+
pi.on("session_shutdown", async (_event, ctx) => {
|
|
407
|
+
const activeVm = vm;
|
|
408
|
+
vm = undefined;
|
|
409
|
+
vmStarting = undefined;
|
|
410
|
+
if (!activeVm) return;
|
|
411
|
+
ctx.ui.setStatus("gondolin", ctx.ui.theme.fg("muted", "Gondolin: stopping"));
|
|
412
|
+
try {
|
|
413
|
+
await activeVm.close();
|
|
414
|
+
} finally {
|
|
415
|
+
ctx.ui.setStatus("gondolin", undefined);
|
|
416
|
+
}
|
|
417
|
+
});
|
|
418
|
+
|
|
419
|
+
pi.registerCommand("gondolin", {
|
|
420
|
+
description: "Show Gondolin VM status",
|
|
421
|
+
handler: async (_args, ctx) => {
|
|
422
|
+
const activeVm = await ensureVm(ctx);
|
|
423
|
+
ctx.ui.notify(
|
|
424
|
+
[
|
|
425
|
+
`Gondolin VM: ${activeVm.id}`,
|
|
426
|
+
`Host workspace: ${localCwd}`,
|
|
427
|
+
`Guest workspace: ${GUEST_WORKSPACE}`,
|
|
428
|
+
`Shell: ${shellPath}`,
|
|
429
|
+
].join("\n"),
|
|
430
|
+
"info",
|
|
431
|
+
);
|
|
432
|
+
},
|
|
433
|
+
});
|
|
434
|
+
|
|
435
|
+
pi.registerTool({
|
|
436
|
+
...localRead,
|
|
437
|
+
async execute(id, params, signal, onUpdate, ctx) {
|
|
438
|
+
const activeVm = await ensureVm(ctx);
|
|
439
|
+
const tool = createReadTool(GUEST_WORKSPACE, {
|
|
440
|
+
operations: createGondolinReadOps(activeVm, localCwd),
|
|
441
|
+
});
|
|
442
|
+
return tool.execute(id, params, signal, onUpdate);
|
|
443
|
+
},
|
|
444
|
+
});
|
|
445
|
+
|
|
446
|
+
pi.registerTool({
|
|
447
|
+
...localWrite,
|
|
448
|
+
async execute(id, params, signal, onUpdate, ctx) {
|
|
449
|
+
const activeVm = await ensureVm(ctx);
|
|
450
|
+
const tool = createWriteTool(GUEST_WORKSPACE, {
|
|
451
|
+
operations: createGondolinWriteOps(activeVm, localCwd),
|
|
452
|
+
});
|
|
453
|
+
return tool.execute(id, params, signal, onUpdate);
|
|
454
|
+
},
|
|
455
|
+
});
|
|
456
|
+
|
|
457
|
+
pi.registerTool({
|
|
458
|
+
...localEdit,
|
|
459
|
+
async execute(id, params, signal, onUpdate, ctx) {
|
|
460
|
+
const activeVm = await ensureVm(ctx);
|
|
461
|
+
const tool = createEditTool(GUEST_WORKSPACE, {
|
|
462
|
+
operations: createGondolinEditOps(activeVm, localCwd),
|
|
463
|
+
});
|
|
464
|
+
return tool.execute(id, params, signal, onUpdate);
|
|
465
|
+
},
|
|
466
|
+
});
|
|
467
|
+
|
|
468
|
+
pi.registerTool({
|
|
469
|
+
...localBash,
|
|
470
|
+
async execute(id, params, signal, onUpdate, ctx) {
|
|
471
|
+
const activeVm = await ensureVm(ctx);
|
|
472
|
+
const tool = createBashTool(GUEST_WORKSPACE, {
|
|
473
|
+
operations: createGondolinBashOps(activeVm, localCwd, shellPath),
|
|
474
|
+
});
|
|
475
|
+
return tool.execute(id, params, signal, onUpdate);
|
|
476
|
+
},
|
|
477
|
+
});
|
|
478
|
+
|
|
479
|
+
pi.registerTool({
|
|
480
|
+
...localLs,
|
|
481
|
+
async execute(id, params, signal, onUpdate, ctx) {
|
|
482
|
+
const activeVm = await ensureVm(ctx);
|
|
483
|
+
const tool = createLsTool(GUEST_WORKSPACE, {
|
|
484
|
+
operations: createGondolinLsOps(activeVm, localCwd),
|
|
485
|
+
});
|
|
486
|
+
return tool.execute(id, params, signal, onUpdate);
|
|
487
|
+
},
|
|
488
|
+
});
|
|
489
|
+
|
|
490
|
+
pi.registerTool({
|
|
491
|
+
...localFind,
|
|
492
|
+
async execute(id, params, signal, onUpdate, ctx) {
|
|
493
|
+
const activeVm = await ensureVm(ctx);
|
|
494
|
+
const tool = createFindTool(GUEST_WORKSPACE, {
|
|
495
|
+
operations: createGondolinFindOps(activeVm, localCwd),
|
|
496
|
+
});
|
|
497
|
+
return tool.execute(id, params, signal, onUpdate);
|
|
498
|
+
},
|
|
499
|
+
});
|
|
500
|
+
|
|
501
|
+
pi.registerTool({
|
|
502
|
+
...localGrep,
|
|
503
|
+
async execute(_id, params, signal, _onUpdate, ctx) {
|
|
504
|
+
const activeVm = await ensureVm(ctx);
|
|
505
|
+
return executeGondolinGrep(activeVm, localCwd, params, signal);
|
|
506
|
+
},
|
|
507
|
+
});
|
|
508
|
+
|
|
509
|
+
pi.on("user_bash", async (_event, ctx) => {
|
|
510
|
+
const activeVm = await ensureVm(ctx);
|
|
511
|
+
return { operations: createGondolinBashOps(activeVm, localCwd, shellPath) };
|
|
512
|
+
});
|
|
513
|
+
|
|
514
|
+
pi.on("before_agent_start", async (event, ctx) => {
|
|
515
|
+
await ensureVm(ctx);
|
|
516
|
+
const localLine = `Current working directory: ${localCwd}`;
|
|
517
|
+
const guestLine = `Current working directory: ${GUEST_WORKSPACE} (Gondolin VM; host workspace mounted from ${localCwd})`;
|
|
518
|
+
const systemPrompt = event.systemPrompt.includes(localLine)
|
|
519
|
+
? event.systemPrompt.replace(localLine, guestLine)
|
|
520
|
+
: `${event.systemPrompt}\n\n${guestLine}`;
|
|
521
|
+
return { systemPrompt };
|
|
522
|
+
});
|
|
523
|
+
}
|