@dirgha/code 1.2.0
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/LICENSE +101 -0
- package/README.md +674 -0
- package/dist/dirgha.mjs +2185 -0
- package/dist_v2/acp/index.d.ts +1 -0
- package/dist_v2/acp/index.js +2 -0
- package/dist_v2/acp/server.d.ts +31 -0
- package/dist_v2/acp/server.js +137 -0
- package/dist_v2/cli/auth-cmd.d.ts +10 -0
- package/dist_v2/cli/auth-cmd.js +69 -0
- package/dist_v2/cli/config.d.ts +46 -0
- package/dist_v2/cli/config.js +70 -0
- package/dist_v2/cli/flags.d.ts +10 -0
- package/dist_v2/cli/flags.js +49 -0
- package/dist_v2/cli/flows/full-cycle.d.ts +30 -0
- package/dist_v2/cli/flows/full-cycle.js +39 -0
- package/dist_v2/cli/flows/index.d.ts +2 -0
- package/dist_v2/cli/flows/index.js +3 -0
- package/dist_v2/cli/flows/tarball.d.ts +10 -0
- package/dist_v2/cli/flows/tarball.js +47 -0
- package/dist_v2/cli/index.d.ts +4 -0
- package/dist_v2/cli/index.js +5 -0
- package/dist_v2/cli/interactive.d.ts +21 -0
- package/dist_v2/cli/interactive.js +207 -0
- package/dist_v2/cli/main.d.ts +10 -0
- package/dist_v2/cli/main.js +173 -0
- package/dist_v2/cli/models-cmd.d.ts +6 -0
- package/dist_v2/cli/models-cmd.js +50 -0
- package/dist_v2/cli/setup.d.ts +13 -0
- package/dist_v2/cli/setup.js +128 -0
- package/dist_v2/cli/slash/account.d.ts +10 -0
- package/dist_v2/cli/slash/account.js +59 -0
- package/dist_v2/cli/slash/clear.d.ts +8 -0
- package/dist_v2/cli/slash/clear.js +15 -0
- package/dist_v2/cli/slash/compact.d.ts +7 -0
- package/dist_v2/cli/slash/compact.js +13 -0
- package/dist_v2/cli/slash/config.d.ts +8 -0
- package/dist_v2/cli/slash/config.js +49 -0
- package/dist_v2/cli/slash/exit.d.ts +7 -0
- package/dist_v2/cli/slash/exit.js +16 -0
- package/dist_v2/cli/slash/fleet.d.ts +7 -0
- package/dist_v2/cli/slash/fleet.js +22 -0
- package/dist_v2/cli/slash/help.d.ts +9 -0
- package/dist_v2/cli/slash/help.js +31 -0
- package/dist_v2/cli/slash/history.d.ts +7 -0
- package/dist_v2/cli/slash/history.js +42 -0
- package/dist_v2/cli/slash/index.d.ts +30 -0
- package/dist_v2/cli/slash/index.js +52 -0
- package/dist_v2/cli/slash/init.d.ts +8 -0
- package/dist_v2/cli/slash/init.js +57 -0
- package/dist_v2/cli/slash/keys.d.ts +8 -0
- package/dist_v2/cli/slash/keys.js +101 -0
- package/dist_v2/cli/slash/login.d.ts +10 -0
- package/dist_v2/cli/slash/login.js +47 -0
- package/dist_v2/cli/slash/memory.d.ts +8 -0
- package/dist_v2/cli/slash/memory.js +101 -0
- package/dist_v2/cli/slash/mode.d.ts +8 -0
- package/dist_v2/cli/slash/mode.js +30 -0
- package/dist_v2/cli/slash/models.d.ts +8 -0
- package/dist_v2/cli/slash/models.js +73 -0
- package/dist_v2/cli/slash/resume.d.ts +8 -0
- package/dist_v2/cli/slash/resume.js +24 -0
- package/dist_v2/cli/slash/session.d.ts +8 -0
- package/dist_v2/cli/slash/session.js +74 -0
- package/dist_v2/cli/slash/setup.d.ts +8 -0
- package/dist_v2/cli/slash/setup.js +50 -0
- package/dist_v2/cli/slash/status.d.ts +7 -0
- package/dist_v2/cli/slash/status.js +37 -0
- package/dist_v2/cli/slash/theme.d.ts +9 -0
- package/dist_v2/cli/slash/theme.js +53 -0
- package/dist_v2/cli/slash/types.d.ts +14 -0
- package/dist_v2/cli/slash/types.js +9 -0
- package/dist_v2/cli/slash/upgrade.d.ts +9 -0
- package/dist_v2/cli/slash/upgrade.js +66 -0
- package/dist_v2/cli/slash.d.ts +72 -0
- package/dist_v2/cli/slash.js +77 -0
- package/dist_v2/cli/subcommands/ask.d.ts +17 -0
- package/dist_v2/cli/subcommands/ask.js +76 -0
- package/dist_v2/cli/subcommands/audit.d.ts +15 -0
- package/dist_v2/cli/subcommands/audit.js +128 -0
- package/dist_v2/cli/subcommands/chat.d.ts +13 -0
- package/dist_v2/cli/subcommands/chat.js +72 -0
- package/dist_v2/cli/subcommands/compact.d.ts +14 -0
- package/dist_v2/cli/subcommands/compact.js +114 -0
- package/dist_v2/cli/subcommands/doctor.d.ts +11 -0
- package/dist_v2/cli/subcommands/doctor.js +103 -0
- package/dist_v2/cli/subcommands/export-session.d.ts +10 -0
- package/dist_v2/cli/subcommands/export-session.js +60 -0
- package/dist_v2/cli/subcommands/import-session.d.ts +11 -0
- package/dist_v2/cli/subcommands/import-session.js +77 -0
- package/dist_v2/cli/subcommands/index.d.ts +40 -0
- package/dist_v2/cli/subcommands/index.js +38 -0
- package/dist_v2/cli/subcommands/init.d.ts +10 -0
- package/dist_v2/cli/subcommands/init.js +74 -0
- package/dist_v2/cli/subcommands/keys.d.ts +12 -0
- package/dist_v2/cli/subcommands/keys.js +136 -0
- package/dist_v2/cli/subcommands/login.d.ts +10 -0
- package/dist_v2/cli/subcommands/login.js +60 -0
- package/dist_v2/cli/subcommands/logout.d.ts +10 -0
- package/dist_v2/cli/subcommands/logout.js +21 -0
- package/dist_v2/cli/subcommands/models.d.ts +14 -0
- package/dist_v2/cli/subcommands/models.js +144 -0
- package/dist_v2/cli/subcommands/setup.d.ts +11 -0
- package/dist_v2/cli/subcommands/setup.js +107 -0
- package/dist_v2/cli/subcommands/stats.d.ts +13 -0
- package/dist_v2/cli/subcommands/stats.js +148 -0
- package/dist_v2/cli/subcommands/status.d.ts +14 -0
- package/dist_v2/cli/subcommands/status.js +91 -0
- package/dist_v2/cli/submit-paper.d.ts +15 -0
- package/dist_v2/cli/submit-paper.js +68 -0
- package/dist_v2/context/_fts.d.ts +62 -0
- package/dist_v2/context/_fts.js +195 -0
- package/dist_v2/context/branch.d.ts +18 -0
- package/dist_v2/context/branch.js +66 -0
- package/dist_v2/context/compaction.d.ts +26 -0
- package/dist_v2/context/compaction.js +120 -0
- package/dist_v2/context/index.d.ts +5 -0
- package/dist_v2/context/index.js +6 -0
- package/dist_v2/context/knowledge.d.ts +38 -0
- package/dist_v2/context/knowledge.js +146 -0
- package/dist_v2/context/memory.d.ts +80 -0
- package/dist_v2/context/memory.js +276 -0
- package/dist_v2/context/mode.d.ts +25 -0
- package/dist_v2/context/mode.js +81 -0
- package/dist_v2/context/session.d.ts +56 -0
- package/dist_v2/context/session.js +108 -0
- package/dist_v2/daemon/index.d.ts +2 -0
- package/dist_v2/daemon/index.js +3 -0
- package/dist_v2/daemon/protocol.d.ts +73 -0
- package/dist_v2/daemon/protocol.js +6 -0
- package/dist_v2/daemon/server.d.ts +35 -0
- package/dist_v2/daemon/server.js +191 -0
- package/dist_v2/eval/index.d.ts +5 -0
- package/dist_v2/eval/index.js +6 -0
- package/dist_v2/eval/regression.d.ts +14 -0
- package/dist_v2/eval/regression.js +106 -0
- package/dist_v2/eval/reporter.d.ts +7 -0
- package/dist_v2/eval/reporter.js +34 -0
- package/dist_v2/eval/swe-bench.d.ts +18 -0
- package/dist_v2/eval/swe-bench.js +23 -0
- package/dist_v2/eval/terminal-bench.d.ts +13 -0
- package/dist_v2/eval/terminal-bench.js +19 -0
- package/dist_v2/eval/types.d.ts +36 -0
- package/dist_v2/eval/types.js +5 -0
- package/dist_v2/fleet/apply-back.d.ts +27 -0
- package/dist_v2/fleet/apply-back.js +191 -0
- package/dist_v2/fleet/cli-command.d.ts +61 -0
- package/dist_v2/fleet/cli-command.js +329 -0
- package/dist_v2/fleet/index.d.ts +21 -0
- package/dist_v2/fleet/index.js +21 -0
- package/dist_v2/fleet/runner.d.ts +28 -0
- package/dist_v2/fleet/runner.js +347 -0
- package/dist_v2/fleet/tripleshot.d.ts +21 -0
- package/dist_v2/fleet/tripleshot.js +222 -0
- package/dist_v2/fleet/types.d.ts +193 -0
- package/dist_v2/fleet/types.js +24 -0
- package/dist_v2/fleet/worktree.d.ts +51 -0
- package/dist_v2/fleet/worktree.js +176 -0
- package/dist_v2/hooks/index.d.ts +1 -0
- package/dist_v2/hooks/index.js +2 -0
- package/dist_v2/hooks/registry.d.ts +21 -0
- package/dist_v2/hooks/registry.js +40 -0
- package/dist_v2/index.d.ts +12 -0
- package/dist_v2/index.js +11 -0
- package/dist_v2/integrations/arniko-client.d.ts +42 -0
- package/dist_v2/integrations/arniko-client.js +86 -0
- package/dist_v2/integrations/auth.d.ts +45 -0
- package/dist_v2/integrations/auth.js +54 -0
- package/dist_v2/integrations/billing.d.ts +71 -0
- package/dist_v2/integrations/billing.js +107 -0
- package/dist_v2/integrations/bucky-client.d.ts +105 -0
- package/dist_v2/integrations/bucky-client.js +76 -0
- package/dist_v2/integrations/deploy-client.d.ts +60 -0
- package/dist_v2/integrations/deploy-client.js +87 -0
- package/dist_v2/integrations/device-auth.d.ts +48 -0
- package/dist_v2/integrations/device-auth.js +192 -0
- package/dist_v2/integrations/entitlements.d.ts +34 -0
- package/dist_v2/integrations/entitlements.js +43 -0
- package/dist_v2/integrations/http.d.ts +22 -0
- package/dist_v2/integrations/http.js +114 -0
- package/dist_v2/integrations/index.d.ts +8 -0
- package/dist_v2/integrations/index.js +15 -0
- package/dist_v2/intelligence/cost.d.ts +28 -0
- package/dist_v2/intelligence/cost.js +58 -0
- package/dist_v2/intelligence/error-classifier.d.ts +8 -0
- package/dist_v2/intelligence/error-classifier.js +71 -0
- package/dist_v2/intelligence/index.d.ts +5 -0
- package/dist_v2/intelligence/index.js +6 -0
- package/dist_v2/intelligence/prices.d.ts +13 -0
- package/dist_v2/intelligence/prices.js +26 -0
- package/dist_v2/intelligence/smart-router.d.ts +21 -0
- package/dist_v2/intelligence/smart-router.js +59 -0
- package/dist_v2/intelligence/telemetry.d.ts +22 -0
- package/dist_v2/intelligence/telemetry.js +31 -0
- package/dist_v2/kernel/agent-loop.d.ts +32 -0
- package/dist_v2/kernel/agent-loop.js +151 -0
- package/dist_v2/kernel/event-stream.d.ts +18 -0
- package/dist_v2/kernel/event-stream.js +102 -0
- package/dist_v2/kernel/index.d.ts +4 -0
- package/dist_v2/kernel/index.js +5 -0
- package/dist_v2/kernel/message.d.ts +29 -0
- package/dist_v2/kernel/message.js +118 -0
- package/dist_v2/kernel/types.d.ts +206 -0
- package/dist_v2/kernel/types.js +9 -0
- package/dist_v2/mcp/client.d.ts +44 -0
- package/dist_v2/mcp/client.js +63 -0
- package/dist_v2/mcp/index.d.ts +3 -0
- package/dist_v2/mcp/index.js +4 -0
- package/dist_v2/mcp/tool-bridge.d.ts +11 -0
- package/dist_v2/mcp/tool-bridge.js +33 -0
- package/dist_v2/mcp/transport.d.ts +29 -0
- package/dist_v2/mcp/transport.js +73 -0
- package/dist_v2/parity/index.d.ts +3 -0
- package/dist_v2/parity/index.js +4 -0
- package/dist_v2/parity/mock-openai-compat.d.ts +15 -0
- package/dist_v2/parity/mock-openai-compat.js +35 -0
- package/dist_v2/parity/runner.d.ts +21 -0
- package/dist_v2/parity/runner.js +76 -0
- package/dist_v2/parity/scenarios.d.ts +20 -0
- package/dist_v2/parity/scenarios.js +70 -0
- package/dist_v2/providers/anthropic.d.ts +21 -0
- package/dist_v2/providers/anthropic.js +191 -0
- package/dist_v2/providers/dispatch.d.ts +11 -0
- package/dist_v2/providers/dispatch.js +45 -0
- package/dist_v2/providers/fireworks.d.ts +18 -0
- package/dist_v2/providers/fireworks.js +44 -0
- package/dist_v2/providers/gemini.d.ts +19 -0
- package/dist_v2/providers/gemini.js +188 -0
- package/dist_v2/providers/http.d.ts +41 -0
- package/dist_v2/providers/http.js +188 -0
- package/dist_v2/providers/iface.d.ts +18 -0
- package/dist_v2/providers/iface.js +18 -0
- package/dist_v2/providers/index.d.ts +39 -0
- package/dist_v2/providers/index.js +51 -0
- package/dist_v2/providers/nvidia.d.ts +27 -0
- package/dist_v2/providers/nvidia.js +142 -0
- package/dist_v2/providers/ollama.d.ts +15 -0
- package/dist_v2/providers/ollama.js +37 -0
- package/dist_v2/providers/openai-compat.d.ts +29 -0
- package/dist_v2/providers/openai-compat.js +239 -0
- package/dist_v2/providers/openai.d.ts +20 -0
- package/dist_v2/providers/openai.js +107 -0
- package/dist_v2/providers/openrouter.d.ts +24 -0
- package/dist_v2/providers/openrouter.js +69 -0
- package/dist_v2/safety/approval-bus.d.ts +26 -0
- package/dist_v2/safety/approval-bus.js +48 -0
- package/dist_v2/safety/audit-log.d.ts +27 -0
- package/dist_v2/safety/audit-log.js +71 -0
- package/dist_v2/safety/index.d.ts +4 -0
- package/dist_v2/safety/index.js +5 -0
- package/dist_v2/safety/policy.d.ts +32 -0
- package/dist_v2/safety/policy.js +131 -0
- package/dist_v2/safety/sandbox/bwrap.d.ts +11 -0
- package/dist_v2/safety/sandbox/bwrap.js +52 -0
- package/dist_v2/safety/sandbox/iface.d.ts +29 -0
- package/dist_v2/safety/sandbox/iface.js +8 -0
- package/dist_v2/safety/sandbox/index.d.ts +7 -0
- package/dist_v2/safety/sandbox/index.js +8 -0
- package/dist_v2/safety/sandbox/landlock.d.ts +17 -0
- package/dist_v2/safety/sandbox/landlock.js +26 -0
- package/dist_v2/safety/sandbox/noop.d.ts +12 -0
- package/dist_v2/safety/sandbox/noop.js +52 -0
- package/dist_v2/safety/sandbox/seatbelt.d.ts +11 -0
- package/dist_v2/safety/sandbox/seatbelt.js +49 -0
- package/dist_v2/safety/sandbox/select.d.ts +6 -0
- package/dist_v2/safety/sandbox/select.js +42 -0
- package/dist_v2/safety/sandbox/windows.d.ts +13 -0
- package/dist_v2/safety/sandbox/windows.js +22 -0
- package/dist_v2/skills/index.d.ts +3 -0
- package/dist_v2/skills/index.js +4 -0
- package/dist_v2/skills/loader.d.ts +38 -0
- package/dist_v2/skills/loader.js +102 -0
- package/dist_v2/skills/matcher.d.ts +14 -0
- package/dist_v2/skills/matcher.js +72 -0
- package/dist_v2/skills/runtime.d.ts +13 -0
- package/dist_v2/skills/runtime.js +40 -0
- package/dist_v2/subagents/delegator.d.ts +36 -0
- package/dist_v2/subagents/delegator.js +82 -0
- package/dist_v2/subagents/index.d.ts +2 -0
- package/dist_v2/subagents/index.js +3 -0
- package/dist_v2/subagents/pool.d.ts +18 -0
- package/dist_v2/subagents/pool.js +31 -0
- package/dist_v2/tools/browser.d.ts +27 -0
- package/dist_v2/tools/browser.js +179 -0
- package/dist_v2/tools/checkpoint.d.ts +25 -0
- package/dist_v2/tools/checkpoint.js +222 -0
- package/dist_v2/tools/cron.d.ts +32 -0
- package/dist_v2/tools/cron.js +160 -0
- package/dist_v2/tools/diff.d.ts +18 -0
- package/dist_v2/tools/diff.js +117 -0
- package/dist_v2/tools/exec.d.ts +19 -0
- package/dist_v2/tools/exec.js +49 -0
- package/dist_v2/tools/fs-edit.d.ts +11 -0
- package/dist_v2/tools/fs-edit.js +81 -0
- package/dist_v2/tools/fs-ls.d.ts +7 -0
- package/dist_v2/tools/fs-ls.js +57 -0
- package/dist_v2/tools/fs-read.d.ts +7 -0
- package/dist_v2/tools/fs-read.js +60 -0
- package/dist_v2/tools/fs-write.d.ts +8 -0
- package/dist_v2/tools/fs-write.js +46 -0
- package/dist_v2/tools/git.d.ts +8 -0
- package/dist_v2/tools/git.js +57 -0
- package/dist_v2/tools/index.d.ts +25 -0
- package/dist_v2/tools/index.js +39 -0
- package/dist_v2/tools/multimodal.d.ts +41 -0
- package/dist_v2/tools/multimodal.js +381 -0
- package/dist_v2/tools/permission.d.ts +27 -0
- package/dist_v2/tools/permission.js +43 -0
- package/dist_v2/tools/registry.d.ts +44 -0
- package/dist_v2/tools/registry.js +62 -0
- package/dist_v2/tools/search-glob.d.ts +7 -0
- package/dist_v2/tools/search-glob.js +98 -0
- package/dist_v2/tools/search-grep.d.ts +7 -0
- package/dist_v2/tools/search-grep.js +109 -0
- package/dist_v2/tools/shell.d.ts +10 -0
- package/dist_v2/tools/shell.js +76 -0
- package/dist_v2/tools/task.d.ts +8 -0
- package/dist_v2/tools/task.js +37 -0
- package/dist_v2/tui/approval.d.ts +7 -0
- package/dist_v2/tui/approval.js +55 -0
- package/dist_v2/tui/index.d.ts +4 -0
- package/dist_v2/tui/index.js +5 -0
- package/dist_v2/tui/ink/App.d.ts +39 -0
- package/dist_v2/tui/ink/App.js +206 -0
- package/dist_v2/tui/ink/components/AtFileComplete.d.ts +25 -0
- package/dist_v2/tui/ink/components/AtFileComplete.js +158 -0
- package/dist_v2/tui/ink/components/HelpOverlay.d.ts +24 -0
- package/dist_v2/tui/ink/components/HelpOverlay.js +130 -0
- package/dist_v2/tui/ink/components/InputBox.d.ts +35 -0
- package/dist_v2/tui/ink/components/InputBox.js +153 -0
- package/dist_v2/tui/ink/components/Logo.d.ts +12 -0
- package/dist_v2/tui/ink/components/Logo.js +27 -0
- package/dist_v2/tui/ink/components/ModelPicker.d.ts +26 -0
- package/dist_v2/tui/ink/components/ModelPicker.js +80 -0
- package/dist_v2/tui/ink/components/PasteCollapse.d.ts +36 -0
- package/dist_v2/tui/ink/components/PasteCollapse.js +59 -0
- package/dist_v2/tui/ink/components/StatusBar.d.ts +18 -0
- package/dist_v2/tui/ink/components/StatusBar.js +41 -0
- package/dist_v2/tui/ink/components/StreamingText.d.ts +14 -0
- package/dist_v2/tui/ink/components/StreamingText.js +11 -0
- package/dist_v2/tui/ink/components/ThinkingBlock.d.ts +13 -0
- package/dist_v2/tui/ink/components/ThinkingBlock.js +13 -0
- package/dist_v2/tui/ink/components/ToolBox.d.ts +20 -0
- package/dist_v2/tui/ink/components/ToolBox.js +63 -0
- package/dist_v2/tui/ink/components/vim-bindings.d.ts +43 -0
- package/dist_v2/tui/ink/components/vim-bindings.js +135 -0
- package/dist_v2/tui/ink/index.d.ts +39 -0
- package/dist_v2/tui/ink/index.js +47 -0
- package/dist_v2/tui/ink/use-event-projection.d.ts +51 -0
- package/dist_v2/tui/ink/use-event-projection.js +126 -0
- package/dist_v2/tui/ink/use-overlays.d.ts +24 -0
- package/dist_v2/tui/ink/use-overlays.js +50 -0
- package/dist_v2/tui/renderer.d.ts +19 -0
- package/dist_v2/tui/renderer.js +64 -0
- package/dist_v2/tui/status-bar.d.ts +12 -0
- package/dist_v2/tui/status-bar.js +16 -0
- package/dist_v2/tui/theme.d.ts +27 -0
- package/dist_v2/tui/theme.js +56 -0
- package/dist_v2/utils/json-repair.d.ts +7 -0
- package/dist_v2/utils/json-repair.js +45 -0
- package/package.json +113 -0
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* fleet/apply-back.ts — Land a worktree's changes back into the parent
|
|
3
|
+
* working tree.
|
|
4
|
+
*
|
|
5
|
+
* Three strategies:
|
|
6
|
+
* - '3way' (default) — commit in worktree, `git diff base..HEAD`, then
|
|
7
|
+
* `git apply --3way` to the parent tree so the user reviews as
|
|
8
|
+
* UNSTAGED changes. Reversible; conflict markers are produced in
|
|
9
|
+
* files on mismatch rather than failing outright.
|
|
10
|
+
*
|
|
11
|
+
* - 'merge' — `git merge --no-ff <branch>` on the parent. Leaves a
|
|
12
|
+
* merge commit. Use when you want the history.
|
|
13
|
+
*
|
|
14
|
+
* - 'cherry-pick' — `git cherry-pick <base>..<HEAD>` replays every
|
|
15
|
+
* commit from the worktree onto the parent HEAD.
|
|
16
|
+
*
|
|
17
|
+
* Returns structured ApplyResult; does NOT throw on merge conflicts —
|
|
18
|
+
* caller inspects `conflicts`/`success` and decides.
|
|
19
|
+
*/
|
|
20
|
+
import { execFile } from 'node:child_process';
|
|
21
|
+
import { writeFile, unlink } from 'node:fs/promises';
|
|
22
|
+
import { join } from 'node:path';
|
|
23
|
+
import { tmpdir } from 'node:os';
|
|
24
|
+
import { promisify } from 'node:util';
|
|
25
|
+
import { getRepoRoot, getHeadSha } from './worktree.js';
|
|
26
|
+
const pexec = promisify(execFile);
|
|
27
|
+
const MAX_DIFF_BYTES = 50 * 1024 * 1024;
|
|
28
|
+
/**
|
|
29
|
+
* Apply a worktree's changes back to the parent working tree.
|
|
30
|
+
*
|
|
31
|
+
* The worktree is expected to be in a clean-or-dirty state; any dirty
|
|
32
|
+
* changes are staged + committed transparently before the apply.
|
|
33
|
+
*/
|
|
34
|
+
export async function applyBack(worktree, options = {}) {
|
|
35
|
+
const strategy = options.strategy ?? '3way';
|
|
36
|
+
const repoRoot = options.repoRoot ?? await getRepoRoot(worktree.repoRoot);
|
|
37
|
+
const message = options.message ?? `fleet: ${worktree.branch.split('/').pop() ?? 'agent'}`;
|
|
38
|
+
try {
|
|
39
|
+
await commitDirty(worktree, message);
|
|
40
|
+
}
|
|
41
|
+
catch (err) {
|
|
42
|
+
return fail(strategy, `commit failed: ${errMsg(err)}`);
|
|
43
|
+
}
|
|
44
|
+
switch (strategy) {
|
|
45
|
+
case '3way': return apply3way(worktree, repoRoot, options.paths);
|
|
46
|
+
case 'merge': return applyMerge(worktree, repoRoot);
|
|
47
|
+
case 'cherry-pick': return applyCherryPick(worktree, repoRoot);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/** Commit every dirty file in the worktree (stage+commit). */
|
|
51
|
+
async function commitDirty(worktree, message) {
|
|
52
|
+
await pexec('git', ['add', '-A'], { cwd: worktree.path });
|
|
53
|
+
const { stdout } = await pexec('git', ['status', '--porcelain'], { cwd: worktree.path });
|
|
54
|
+
if (!stdout.trim())
|
|
55
|
+
return;
|
|
56
|
+
await pexec('git', ['commit', '-m', message, '--allow-empty'], { cwd: worktree.path });
|
|
57
|
+
}
|
|
58
|
+
/* -------------------------- 3-way apply -------------------------- */
|
|
59
|
+
async function apply3way(worktree, repoRoot, pathsFilter) {
|
|
60
|
+
const parentHead = await getHeadSha(repoRoot);
|
|
61
|
+
let diff = '';
|
|
62
|
+
try {
|
|
63
|
+
const args = ['diff', parentHead, 'HEAD'];
|
|
64
|
+
if (pathsFilter && pathsFilter.length > 0) {
|
|
65
|
+
args.push('--', ...pathsFilter);
|
|
66
|
+
}
|
|
67
|
+
const { stdout } = await pexec('git', args, {
|
|
68
|
+
cwd: worktree.path,
|
|
69
|
+
maxBuffer: MAX_DIFF_BYTES,
|
|
70
|
+
});
|
|
71
|
+
diff = stdout;
|
|
72
|
+
}
|
|
73
|
+
catch (err) {
|
|
74
|
+
return fail('3way', `diff failed: ${errMsg(err)}`);
|
|
75
|
+
}
|
|
76
|
+
if (!diff.trim()) {
|
|
77
|
+
return { success: true, strategy: '3way', appliedFiles: [], conflicts: [] };
|
|
78
|
+
}
|
|
79
|
+
const appliedFiles = extractDiffPaths(diff);
|
|
80
|
+
const patchPath = join(tmpdir(), `fleet-${Date.now()}-${Math.random().toString(36).slice(2)}.patch`);
|
|
81
|
+
await writeFile(patchPath, diff, 'utf8');
|
|
82
|
+
try {
|
|
83
|
+
await pexec('git', ['apply', '--3way', patchPath], { cwd: repoRoot });
|
|
84
|
+
return { success: true, strategy: '3way', appliedFiles, conflicts: [] };
|
|
85
|
+
}
|
|
86
|
+
catch (err) {
|
|
87
|
+
const stderr = extractStderr(err);
|
|
88
|
+
const conflicts = extractConflicts(stderr);
|
|
89
|
+
return {
|
|
90
|
+
success: conflicts.length === 0 && !stderr,
|
|
91
|
+
strategy: '3way',
|
|
92
|
+
appliedFiles,
|
|
93
|
+
conflicts,
|
|
94
|
+
error: conflicts.length > 0 ? `${conflicts.length} conflict(s)` : stderr.slice(0, 500),
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
finally {
|
|
98
|
+
try {
|
|
99
|
+
await unlink(patchPath);
|
|
100
|
+
}
|
|
101
|
+
catch { /* best effort */ }
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
/* --------------------------- Merge -------------------------------- */
|
|
105
|
+
async function applyMerge(worktree, repoRoot) {
|
|
106
|
+
try {
|
|
107
|
+
await pexec('git', ['merge', '--no-ff', '--no-edit', worktree.branch], { cwd: repoRoot });
|
|
108
|
+
// Diff the just-created merge commit vs its first parent.
|
|
109
|
+
const { stdout } = await pexec('git', ['diff', '--name-only', 'HEAD~1..HEAD'], { cwd: repoRoot });
|
|
110
|
+
const appliedFiles = stdout.split('\n').map(s => s.trim()).filter(Boolean);
|
|
111
|
+
return { success: true, strategy: 'merge', appliedFiles, conflicts: [] };
|
|
112
|
+
}
|
|
113
|
+
catch (err) {
|
|
114
|
+
const stderr = extractStderr(err);
|
|
115
|
+
const conflicts = extractConflicts(stderr);
|
|
116
|
+
return {
|
|
117
|
+
success: false,
|
|
118
|
+
strategy: 'merge',
|
|
119
|
+
appliedFiles: [],
|
|
120
|
+
conflicts,
|
|
121
|
+
error: stderr.slice(0, 500) || errMsg(err),
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
/* ---------------------- Cherry-pick range ------------------------- */
|
|
126
|
+
async function applyCherryPick(worktree, repoRoot) {
|
|
127
|
+
try {
|
|
128
|
+
const parentHead = await getHeadSha(repoRoot);
|
|
129
|
+
const { stdout: revList } = await pexec('git', ['rev-list', `${parentHead}..HEAD`], { cwd: worktree.path });
|
|
130
|
+
const shas = revList.split('\n').map(s => s.trim()).filter(Boolean).reverse();
|
|
131
|
+
if (shas.length === 0) {
|
|
132
|
+
return { success: true, strategy: 'cherry-pick', appliedFiles: [], conflicts: [] };
|
|
133
|
+
}
|
|
134
|
+
await pexec('git', ['cherry-pick', ...shas], { cwd: repoRoot });
|
|
135
|
+
const { stdout } = await pexec('git', ['diff', '--name-only', `HEAD~${shas.length}..HEAD`], { cwd: repoRoot });
|
|
136
|
+
const appliedFiles = stdout.split('\n').map(s => s.trim()).filter(Boolean);
|
|
137
|
+
return { success: true, strategy: 'cherry-pick', appliedFiles, conflicts: [] };
|
|
138
|
+
}
|
|
139
|
+
catch (err) {
|
|
140
|
+
const stderr = extractStderr(err);
|
|
141
|
+
const conflicts = extractConflicts(stderr);
|
|
142
|
+
return {
|
|
143
|
+
success: false,
|
|
144
|
+
strategy: 'cherry-pick',
|
|
145
|
+
appliedFiles: [],
|
|
146
|
+
conflicts,
|
|
147
|
+
error: stderr.slice(0, 500) || errMsg(err),
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
/* ---------------------------- helpers ----------------------------- */
|
|
152
|
+
function extractDiffPaths(diff) {
|
|
153
|
+
const seen = new Set();
|
|
154
|
+
for (const m of diff.matchAll(/^diff --git a\/(.+?) b\/(.+?)$/gm)) {
|
|
155
|
+
seen.add(m[2] ?? m[1] ?? '');
|
|
156
|
+
}
|
|
157
|
+
return [...seen].filter(Boolean);
|
|
158
|
+
}
|
|
159
|
+
function extractConflicts(stderr) {
|
|
160
|
+
const conflicts = new Set();
|
|
161
|
+
for (const m of stderr.matchAll(/conflict(?: in| :)? (.+?)(?:\n|$)/gi)) {
|
|
162
|
+
conflicts.add(m[1].trim());
|
|
163
|
+
}
|
|
164
|
+
for (const m of stderr.matchAll(/CONFLICT .+? in (.+?)\n/g)) {
|
|
165
|
+
conflicts.add(m[1].trim());
|
|
166
|
+
}
|
|
167
|
+
return [...conflicts];
|
|
168
|
+
}
|
|
169
|
+
function extractStderr(err) {
|
|
170
|
+
if (err && typeof err === 'object') {
|
|
171
|
+
const e = err;
|
|
172
|
+
if (typeof e.stderr === 'string')
|
|
173
|
+
return e.stderr;
|
|
174
|
+
if (Buffer.isBuffer(e.stderr))
|
|
175
|
+
return e.stderr.toString('utf8');
|
|
176
|
+
if (typeof e.stdout === 'string')
|
|
177
|
+
return e.stdout;
|
|
178
|
+
if (typeof e.message === 'string')
|
|
179
|
+
return e.message;
|
|
180
|
+
}
|
|
181
|
+
return String(err);
|
|
182
|
+
}
|
|
183
|
+
function errMsg(err) {
|
|
184
|
+
if (err instanceof Error)
|
|
185
|
+
return err.message;
|
|
186
|
+
return String(err);
|
|
187
|
+
}
|
|
188
|
+
function fail(strategy, error) {
|
|
189
|
+
return { success: false, strategy, appliedFiles: [], conflicts: [], error };
|
|
190
|
+
}
|
|
191
|
+
//# sourceMappingURL=apply-back.js.map
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* fleet/cli-command.ts — Fleet dispatch for v2's slash + CLI flow.
|
|
3
|
+
*
|
|
4
|
+
* Exports three entry points so the host can plug in whichever fits:
|
|
5
|
+
*
|
|
6
|
+
* 1. fleetCommand(argv, env) — call from main.ts when positionals[0] === 'fleet'.
|
|
7
|
+
* Handles all subcommands non-interactively, writes to stdout/stderr,
|
|
8
|
+
* returns exit code.
|
|
9
|
+
*
|
|
10
|
+
* 2. registerFleetSlash(slashRegistry, opts) — register `/fleet`, `/triple`,
|
|
11
|
+
* `/worktrees` so the interactive REPL picks them up.
|
|
12
|
+
*
|
|
13
|
+
* 3. The default export `fleetCommand` is a thin façade matching the
|
|
14
|
+
* integration contract specified by the spec.
|
|
15
|
+
*
|
|
16
|
+
* Subcommands:
|
|
17
|
+
* fleet launch <goal…> — decompose + spawn agents in worktrees
|
|
18
|
+
* fleet list — list active fleet worktrees
|
|
19
|
+
* fleet merge <branch> — applyBack (3-way by default)
|
|
20
|
+
* fleet discard <branch> — destroyWorktree + deleteBranch
|
|
21
|
+
* fleet triple <goal…> — tripleshot + judge
|
|
22
|
+
* fleet cleanup — remove every fleet/ worktree
|
|
23
|
+
*/
|
|
24
|
+
import type { ApplyStrategy, WorktreeHandle } from './types.js';
|
|
25
|
+
import type { SlashRegistry } from '../cli/slash.js';
|
|
26
|
+
export interface FleetCommandOptions {
|
|
27
|
+
cwd?: string;
|
|
28
|
+
model?: string;
|
|
29
|
+
plannerModel?: string;
|
|
30
|
+
verbose?: boolean;
|
|
31
|
+
json?: boolean;
|
|
32
|
+
autoMerge?: boolean;
|
|
33
|
+
strategy?: ApplyStrategy;
|
|
34
|
+
maxTurns?: number;
|
|
35
|
+
concurrency?: number;
|
|
36
|
+
timeoutMs?: number;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Entry point for `dirgha fleet …` — returns a POSIX exit code.
|
|
40
|
+
* `argv` is the list of tokens AFTER the `fleet` verb.
|
|
41
|
+
*/
|
|
42
|
+
export declare function fleetCommand(argv: string[], opts?: FleetCommandOptions): Promise<number>;
|
|
43
|
+
export interface SlashOptions {
|
|
44
|
+
cwd?: string;
|
|
45
|
+
model?: string;
|
|
46
|
+
plannerModel?: string;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Register /fleet, /triple and /worktrees in a SlashRegistry.
|
|
50
|
+
* The handlers call through to fleetCommand; their return value is the
|
|
51
|
+
* text the REPL prints.
|
|
52
|
+
*/
|
|
53
|
+
export declare function registerFleetSlash(registry: SlashRegistry, opts?: SlashOptions): void;
|
|
54
|
+
/**
|
|
55
|
+
* Public helper for callers who want to build worktrees by hand
|
|
56
|
+
* (e.g. scripts wrapping fleet).
|
|
57
|
+
*/
|
|
58
|
+
export declare function openWorktreeByBranch(branch: string, opts?: {
|
|
59
|
+
repoRoot?: string;
|
|
60
|
+
cwd?: string;
|
|
61
|
+
}): Promise<WorktreeHandle>;
|
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* fleet/cli-command.ts — Fleet dispatch for v2's slash + CLI flow.
|
|
3
|
+
*
|
|
4
|
+
* Exports three entry points so the host can plug in whichever fits:
|
|
5
|
+
*
|
|
6
|
+
* 1. fleetCommand(argv, env) — call from main.ts when positionals[0] === 'fleet'.
|
|
7
|
+
* Handles all subcommands non-interactively, writes to stdout/stderr,
|
|
8
|
+
* returns exit code.
|
|
9
|
+
*
|
|
10
|
+
* 2. registerFleetSlash(slashRegistry, opts) — register `/fleet`, `/triple`,
|
|
11
|
+
* `/worktrees` so the interactive REPL picks them up.
|
|
12
|
+
*
|
|
13
|
+
* 3. The default export `fleetCommand` is a thin façade matching the
|
|
14
|
+
* integration contract specified by the spec.
|
|
15
|
+
*
|
|
16
|
+
* Subcommands:
|
|
17
|
+
* fleet launch <goal…> — decompose + spawn agents in worktrees
|
|
18
|
+
* fleet list — list active fleet worktrees
|
|
19
|
+
* fleet merge <branch> — applyBack (3-way by default)
|
|
20
|
+
* fleet discard <branch> — destroyWorktree + deleteBranch
|
|
21
|
+
* fleet triple <goal…> — tripleshot + judge
|
|
22
|
+
* fleet cleanup — remove every fleet/ worktree
|
|
23
|
+
*/
|
|
24
|
+
import { createEventStream } from '../kernel/event-stream.js';
|
|
25
|
+
import { runFleet } from './runner.js';
|
|
26
|
+
import { runTripleshot } from './tripleshot.js';
|
|
27
|
+
import { applyBack } from './apply-back.js';
|
|
28
|
+
import { createWorktree, deleteBranch, destroyWorktree, detachFromCleanup, getRepoRoot, listWorktrees, } from './worktree.js';
|
|
29
|
+
/**
|
|
30
|
+
* Entry point for `dirgha fleet …` — returns a POSIX exit code.
|
|
31
|
+
* `argv` is the list of tokens AFTER the `fleet` verb.
|
|
32
|
+
*/
|
|
33
|
+
export async function fleetCommand(argv, opts = {}) {
|
|
34
|
+
const [sub, ...rest] = argv;
|
|
35
|
+
switch (sub) {
|
|
36
|
+
case undefined:
|
|
37
|
+
case '--help':
|
|
38
|
+
case '-h':
|
|
39
|
+
case 'help':
|
|
40
|
+
printHelp();
|
|
41
|
+
return 0;
|
|
42
|
+
case 'launch': return doLaunch(rest, opts);
|
|
43
|
+
case 'triple': return doTriple(rest, opts);
|
|
44
|
+
case 'list': return doList(opts);
|
|
45
|
+
case 'merge': return doMerge(rest, opts);
|
|
46
|
+
case 'discard': return doDiscard(rest, opts);
|
|
47
|
+
case 'cleanup': return doCleanup(opts);
|
|
48
|
+
default:
|
|
49
|
+
process.stderr.write(`fleet: unknown subcommand "${sub}"\n`);
|
|
50
|
+
printHelp();
|
|
51
|
+
return 1;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/* ---------------------------- subcommands ------------------------- */
|
|
55
|
+
async function doLaunch(argv, opts) {
|
|
56
|
+
const goal = argv.join(' ').trim();
|
|
57
|
+
if (!goal) {
|
|
58
|
+
process.stderr.write('usage: dirgha fleet launch <goal>\n');
|
|
59
|
+
return 1;
|
|
60
|
+
}
|
|
61
|
+
const events = createEventStream();
|
|
62
|
+
if (opts.verbose)
|
|
63
|
+
subscribeVerbose(events);
|
|
64
|
+
const config = {
|
|
65
|
+
goal,
|
|
66
|
+
cwd: opts.cwd ?? process.cwd(),
|
|
67
|
+
model: opts.model,
|
|
68
|
+
plannerModel: opts.plannerModel,
|
|
69
|
+
maxTurns: opts.maxTurns,
|
|
70
|
+
concurrency: opts.concurrency,
|
|
71
|
+
timeoutMs: opts.timeoutMs,
|
|
72
|
+
events,
|
|
73
|
+
verbose: opts.verbose,
|
|
74
|
+
};
|
|
75
|
+
process.stderr.write(`[fleet] decomposing and launching…\n`);
|
|
76
|
+
const result = await runFleet(config);
|
|
77
|
+
emitResult('launch', result, opts);
|
|
78
|
+
return result.failCount > 0 && result.successCount === 0 ? 1 : 0;
|
|
79
|
+
}
|
|
80
|
+
async function doTriple(argv, opts) {
|
|
81
|
+
const goal = argv.join(' ').trim();
|
|
82
|
+
if (!goal) {
|
|
83
|
+
process.stderr.write('usage: dirgha fleet triple <goal>\n');
|
|
84
|
+
return 1;
|
|
85
|
+
}
|
|
86
|
+
const events = createEventStream();
|
|
87
|
+
if (opts.verbose)
|
|
88
|
+
subscribeVerbose(events);
|
|
89
|
+
const result = await runTripleshot(goal, {
|
|
90
|
+
goal,
|
|
91
|
+
cwd: opts.cwd ?? process.cwd(),
|
|
92
|
+
model: opts.model,
|
|
93
|
+
plannerModel: opts.plannerModel,
|
|
94
|
+
maxTurns: opts.maxTurns,
|
|
95
|
+
timeoutMs: opts.timeoutMs,
|
|
96
|
+
events,
|
|
97
|
+
verbose: opts.verbose,
|
|
98
|
+
autoMerge: opts.autoMerge,
|
|
99
|
+
});
|
|
100
|
+
emitTripleshot(result, opts);
|
|
101
|
+
return result.winner ? 0 : 1;
|
|
102
|
+
}
|
|
103
|
+
async function doList(opts) {
|
|
104
|
+
const repoRoot = await getRepoRoot(opts.cwd ?? process.cwd());
|
|
105
|
+
const wts = (await listWorktrees(repoRoot)).filter(w => w.branch.startsWith('fleet/'));
|
|
106
|
+
if (opts.json) {
|
|
107
|
+
process.stdout.write(`${JSON.stringify({ worktrees: wts }, null, 2)}\n`);
|
|
108
|
+
}
|
|
109
|
+
else if (wts.length === 0) {
|
|
110
|
+
process.stdout.write('No fleet worktrees.\n');
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
process.stdout.write(`Fleet worktrees (${wts.length}):\n`);
|
|
114
|
+
for (const w of wts) {
|
|
115
|
+
process.stdout.write(` ${w.branch.padEnd(50)} ${w.path}\n`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return 0;
|
|
119
|
+
}
|
|
120
|
+
async function doMerge(argv, opts) {
|
|
121
|
+
const target = argv[0];
|
|
122
|
+
if (!target) {
|
|
123
|
+
process.stderr.write('usage: dirgha fleet merge <branch|agent-id>\n');
|
|
124
|
+
return 1;
|
|
125
|
+
}
|
|
126
|
+
const repoRoot = await getRepoRoot(opts.cwd ?? process.cwd());
|
|
127
|
+
const wt = (await listWorktrees(repoRoot)).find(w => w.branch === target
|
|
128
|
+
|| w.branch.endsWith(`/${target}`)
|
|
129
|
+
|| w.branch.includes(`/${target}`));
|
|
130
|
+
if (!wt) {
|
|
131
|
+
process.stderr.write(`fleet: no worktree found for "${target}". Try \`dirgha fleet list\`.\n`);
|
|
132
|
+
return 1;
|
|
133
|
+
}
|
|
134
|
+
const result = await applyBack(wt, {
|
|
135
|
+
strategy: opts.strategy ?? '3way',
|
|
136
|
+
message: `fleet: ${target}`,
|
|
137
|
+
repoRoot,
|
|
138
|
+
});
|
|
139
|
+
if (opts.json) {
|
|
140
|
+
process.stdout.write(`${JSON.stringify(result, null, 2)}\n`);
|
|
141
|
+
}
|
|
142
|
+
else if (result.success) {
|
|
143
|
+
process.stdout.write(`Applied ${result.appliedFiles.length} file(s) via ${result.strategy}. Review with \`git diff\`.\n`);
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
process.stderr.write(`fleet: merge failed — ${result.error ?? 'unknown error'}\n`);
|
|
147
|
+
if (result.conflicts.length) {
|
|
148
|
+
process.stderr.write(`Conflicts:\n${result.conflicts.map(c => ` - ${c}`).join('\n')}\n`);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return result.success ? 0 : 1;
|
|
152
|
+
}
|
|
153
|
+
async function doDiscard(argv, opts) {
|
|
154
|
+
const target = argv[0];
|
|
155
|
+
if (!target) {
|
|
156
|
+
process.stderr.write('usage: dirgha fleet discard <branch|agent-id>\n');
|
|
157
|
+
return 1;
|
|
158
|
+
}
|
|
159
|
+
const repoRoot = await getRepoRoot(opts.cwd ?? process.cwd());
|
|
160
|
+
const wt = (await listWorktrees(repoRoot)).find(w => w.branch === target
|
|
161
|
+
|| w.branch.endsWith(`/${target}`)
|
|
162
|
+
|| w.branch.includes(`/${target}`));
|
|
163
|
+
if (!wt) {
|
|
164
|
+
process.stderr.write(`fleet: no worktree found for "${target}".\n`);
|
|
165
|
+
return 1;
|
|
166
|
+
}
|
|
167
|
+
await destroyWorktree(wt, true);
|
|
168
|
+
await deleteBranch(repoRoot, wt.branch, true);
|
|
169
|
+
if (opts.json) {
|
|
170
|
+
process.stdout.write(`${JSON.stringify({ discarded: wt.branch, path: wt.path })}\n`);
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
process.stdout.write(`Discarded ${wt.branch}.\n`);
|
|
174
|
+
}
|
|
175
|
+
return 0;
|
|
176
|
+
}
|
|
177
|
+
async function doCleanup(opts) {
|
|
178
|
+
const repoRoot = await getRepoRoot(opts.cwd ?? process.cwd());
|
|
179
|
+
const wts = (await listWorktrees(repoRoot)).filter(w => w.branch.startsWith('fleet/'));
|
|
180
|
+
let removed = 0;
|
|
181
|
+
for (const w of wts) {
|
|
182
|
+
try {
|
|
183
|
+
await destroyWorktree(w, true);
|
|
184
|
+
await deleteBranch(repoRoot, w.branch, true);
|
|
185
|
+
removed++;
|
|
186
|
+
}
|
|
187
|
+
catch { /* skip */ }
|
|
188
|
+
}
|
|
189
|
+
process.stdout.write(`Removed ${removed}/${wts.length} fleet worktrees.\n`);
|
|
190
|
+
return 0;
|
|
191
|
+
}
|
|
192
|
+
/* -------------------------- emit helpers -------------------------- */
|
|
193
|
+
function emitResult(phase, r, opts) {
|
|
194
|
+
if (opts.json) {
|
|
195
|
+
process.stdout.write(`${JSON.stringify({ phase, result: r }, null, 2)}\n`);
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
process.stdout.write(`\nFleet done: ${r.successCount}/${r.agents.length} succeeded · ${Math.floor(r.durationMs / 1000)}s\n`);
|
|
199
|
+
for (const a of r.agents) {
|
|
200
|
+
const dot = a.status === 'completed' ? '✓'
|
|
201
|
+
: a.status === 'failed' ? '✗'
|
|
202
|
+
: a.status === 'cancelled' ? '⊘'
|
|
203
|
+
: '·';
|
|
204
|
+
const dur = a.completedAt && a.startedAt
|
|
205
|
+
? `${Math.floor((a.completedAt - a.startedAt) / 1000)}s`
|
|
206
|
+
: '';
|
|
207
|
+
process.stdout.write(` ${dot} ${a.subtask.title.padEnd(40)} ${a.branchName.padEnd(30)} ${dur}\n`);
|
|
208
|
+
}
|
|
209
|
+
if (r.failed.length === 0 && r.successCount > 0) {
|
|
210
|
+
process.stdout.write('\nNext:\n dirgha fleet list\n dirgha fleet merge <branch>\n dirgha fleet discard <branch>\n');
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
function emitTripleshot(r, opts) {
|
|
214
|
+
if (opts.json) {
|
|
215
|
+
process.stdout.write(`${JSON.stringify(r, null, 2)}\n`);
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
process.stdout.write(`\nTripleShot: ${r.winner ?? '(none)'}\n`);
|
|
219
|
+
process.stdout.write(` runner-up: ${r.runnerUp ?? '(none)'}\n`);
|
|
220
|
+
process.stdout.write(` reason: ${r.reason}\n`);
|
|
221
|
+
if (r.apply) {
|
|
222
|
+
if (r.apply.success) {
|
|
223
|
+
process.stdout.write(` applied: ${r.apply.appliedFiles.length} file(s) via ${r.apply.strategy}\n`);
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
process.stdout.write(` apply failed: ${r.apply.error}\n`);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
function subscribeVerbose(events) {
|
|
231
|
+
events.subscribe(ev => {
|
|
232
|
+
if (ev.type === 'text_delta')
|
|
233
|
+
process.stderr.write(ev.delta);
|
|
234
|
+
else if (ev.type === 'error')
|
|
235
|
+
process.stderr.write(`\n[err] ${ev.message}\n`);
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
function printHelp() {
|
|
239
|
+
process.stdout.write(`dirgha fleet — parallel multi-agent work in isolated git worktrees
|
|
240
|
+
|
|
241
|
+
Usage:
|
|
242
|
+
dirgha fleet launch <goal> Decompose + spawn agents in worktrees
|
|
243
|
+
dirgha fleet triple <goal> TripleShot (3 variants + judge)
|
|
244
|
+
dirgha fleet list List fleet worktrees
|
|
245
|
+
dirgha fleet merge <branch> Apply worktree diff back (3-way unstaged)
|
|
246
|
+
dirgha fleet discard <branch> Remove worktree + branch
|
|
247
|
+
dirgha fleet cleanup Remove every fleet/* worktree
|
|
248
|
+
|
|
249
|
+
Options (applicable where relevant):
|
|
250
|
+
--model <id> Model for subagents
|
|
251
|
+
--planner <id> Model for decomposition + judge
|
|
252
|
+
--concurrency <n> Max concurrent agents (default 3)
|
|
253
|
+
--max-turns <n> Per-agent turn cap (default 15)
|
|
254
|
+
--auto-merge Auto-apply the winner in tripleshot
|
|
255
|
+
--strategy <kind> 3way (default) | merge | cherry-pick
|
|
256
|
+
--verbose Mirror agent text to stderr
|
|
257
|
+
--json NDJSON output to stdout
|
|
258
|
+
`);
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Register /fleet, /triple and /worktrees in a SlashRegistry.
|
|
262
|
+
* The handlers call through to fleetCommand; their return value is the
|
|
263
|
+
* text the REPL prints.
|
|
264
|
+
*/
|
|
265
|
+
export function registerFleetSlash(registry, opts = {}) {
|
|
266
|
+
const fleetHandler = async (args) => {
|
|
267
|
+
const captured = captureStdout();
|
|
268
|
+
try {
|
|
269
|
+
await fleetCommand(args, { cwd: opts.cwd, model: opts.model, plannerModel: opts.plannerModel });
|
|
270
|
+
}
|
|
271
|
+
finally {
|
|
272
|
+
captured.restore();
|
|
273
|
+
}
|
|
274
|
+
return captured.stdout || undefined;
|
|
275
|
+
};
|
|
276
|
+
const tripleHandler = async (args) => {
|
|
277
|
+
const captured = captureStdout();
|
|
278
|
+
try {
|
|
279
|
+
await fleetCommand(['triple', ...args], {
|
|
280
|
+
cwd: opts.cwd, model: opts.model, plannerModel: opts.plannerModel,
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
finally {
|
|
284
|
+
captured.restore();
|
|
285
|
+
}
|
|
286
|
+
return captured.stdout || undefined;
|
|
287
|
+
};
|
|
288
|
+
const worktreesHandler = async () => {
|
|
289
|
+
const captured = captureStdout();
|
|
290
|
+
try {
|
|
291
|
+
await fleetCommand(['list'], { cwd: opts.cwd });
|
|
292
|
+
}
|
|
293
|
+
finally {
|
|
294
|
+
captured.restore();
|
|
295
|
+
}
|
|
296
|
+
return captured.stdout || undefined;
|
|
297
|
+
};
|
|
298
|
+
registry.register('fleet', fleetHandler);
|
|
299
|
+
registry.register('triple', tripleHandler);
|
|
300
|
+
registry.register('worktrees', worktreesHandler);
|
|
301
|
+
}
|
|
302
|
+
function captureStdout() {
|
|
303
|
+
const original = process.stdout.write.bind(process.stdout);
|
|
304
|
+
let buffer = '';
|
|
305
|
+
process.stdout.write = ((chunk) => {
|
|
306
|
+
buffer += typeof chunk === 'string' ? chunk : String(chunk);
|
|
307
|
+
return true;
|
|
308
|
+
});
|
|
309
|
+
return {
|
|
310
|
+
get stdout() { return buffer; },
|
|
311
|
+
restore() {
|
|
312
|
+
process.stdout.write = original;
|
|
313
|
+
},
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Public helper for callers who want to build worktrees by hand
|
|
318
|
+
* (e.g. scripts wrapping fleet).
|
|
319
|
+
*/
|
|
320
|
+
export async function openWorktreeByBranch(branch, opts = {}) {
|
|
321
|
+
const repoRoot = opts.repoRoot ?? await getRepoRoot(opts.cwd ?? process.cwd());
|
|
322
|
+
const existing = (await listWorktrees(repoRoot)).find(w => w.branch === branch);
|
|
323
|
+
if (existing) {
|
|
324
|
+
detachFromCleanup(existing);
|
|
325
|
+
return existing;
|
|
326
|
+
}
|
|
327
|
+
return createWorktree(branch, { repoRoot });
|
|
328
|
+
}
|
|
329
|
+
//# sourceMappingURL=cli-command.js.map
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* fleet — Parallel multi-agent work in isolated git worktrees.
|
|
3
|
+
*
|
|
4
|
+
* Each agent runs v2's agent-loop inside its own worktree. The parent
|
|
5
|
+
* observes every agent through a single EventStream and can apply the
|
|
6
|
+
* resulting diffs back with 3-way, merge, or cherry-pick strategies.
|
|
7
|
+
*
|
|
8
|
+
* runFleet({ goal, … }) → N parallel agents decomposed from goal
|
|
9
|
+
* runTripleshot(goal, …) → 3 stylistic variants + LLM judge
|
|
10
|
+
* applyBack(worktree, strategy) → land diff back in parent tree
|
|
11
|
+
* createWorktree/destroyWorktree → low-level worktree lifecycle
|
|
12
|
+
* fleetCommand(argv, opts) → CLI dispatch for positional `fleet …`
|
|
13
|
+
* registerFleetSlash(registry) → wire /fleet /triple /worktrees in REPL
|
|
14
|
+
*/
|
|
15
|
+
export * from './types.js';
|
|
16
|
+
export { createWorktree, destroyWorktree, deleteBranch, listWorktrees, getRepoRoot, getHeadSha, slug, detachFromCleanup, } from './worktree.js';
|
|
17
|
+
export { applyBack } from './apply-back.js';
|
|
18
|
+
export { runFleet, decomposeGoal } from './runner.js';
|
|
19
|
+
export { runTripleshot } from './tripleshot.js';
|
|
20
|
+
export type { TripleshotConfig } from './tripleshot.js';
|
|
21
|
+
export { fleetCommand, registerFleetSlash, openWorktreeByBranch, type FleetCommandOptions, type SlashOptions, } from './cli-command.js';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* fleet — Parallel multi-agent work in isolated git worktrees.
|
|
3
|
+
*
|
|
4
|
+
* Each agent runs v2's agent-loop inside its own worktree. The parent
|
|
5
|
+
* observes every agent through a single EventStream and can apply the
|
|
6
|
+
* resulting diffs back with 3-way, merge, or cherry-pick strategies.
|
|
7
|
+
*
|
|
8
|
+
* runFleet({ goal, … }) → N parallel agents decomposed from goal
|
|
9
|
+
* runTripleshot(goal, …) → 3 stylistic variants + LLM judge
|
|
10
|
+
* applyBack(worktree, strategy) → land diff back in parent tree
|
|
11
|
+
* createWorktree/destroyWorktree → low-level worktree lifecycle
|
|
12
|
+
* fleetCommand(argv, opts) → CLI dispatch for positional `fleet …`
|
|
13
|
+
* registerFleetSlash(registry) → wire /fleet /triple /worktrees in REPL
|
|
14
|
+
*/
|
|
15
|
+
export * from './types.js';
|
|
16
|
+
export { createWorktree, destroyWorktree, deleteBranch, listWorktrees, getRepoRoot, getHeadSha, slug, detachFromCleanup, } from './worktree.js';
|
|
17
|
+
export { applyBack } from './apply-back.js';
|
|
18
|
+
export { runFleet, decomposeGoal } from './runner.js';
|
|
19
|
+
export { runTripleshot } from './tripleshot.js';
|
|
20
|
+
export { fleetCommand, registerFleetSlash, openWorktreeByBranch, } from './cli-command.js';
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* fleet/runner.ts — Spawn and orchestrate N subagents in parallel worktrees.
|
|
3
|
+
*
|
|
4
|
+
* Each agent runs v2's agent-loop directly, NOT as a subprocess. cwd is
|
|
5
|
+
* swapped per-agent via the ToolExecutor's `cwd`, so file operations are
|
|
6
|
+
* isolated to the worktree without process isolation overhead.
|
|
7
|
+
*
|
|
8
|
+
* Flow:
|
|
9
|
+
* 1. Resolve subtasks (decompose goal if not supplied).
|
|
10
|
+
* 2. Create one worktree per subtask.
|
|
11
|
+
* 3. Spawn agents under a bounded-concurrency semaphore.
|
|
12
|
+
* 4. Forward per-agent AgentEvents + FleetEvents onto the parent stream.
|
|
13
|
+
* 5. Gather results, compute totals, return FleetResult.
|
|
14
|
+
* 6. Optional cleanup of worktrees.
|
|
15
|
+
*/
|
|
16
|
+
import { ProviderRegistry } from '../providers/index.js';
|
|
17
|
+
import { type FleetConfig, type FleetResult, type FleetSubtask } from './types.js';
|
|
18
|
+
/**
|
|
19
|
+
* Run a fleet. Accepts either explicit `subtasks` or a bare `goal` that
|
|
20
|
+
* will be decomposed via the planner model.
|
|
21
|
+
*/
|
|
22
|
+
export declare function runFleet(config: FleetConfig): Promise<FleetResult>;
|
|
23
|
+
/**
|
|
24
|
+
* Decompose a goal into subtasks via an LLM call. Single-shot; falls back
|
|
25
|
+
* to a 1-element list ({ id:slug(goal), task:goal, type:'code' }) on any
|
|
26
|
+
* error or unparseable response.
|
|
27
|
+
*/
|
|
28
|
+
export declare function decomposeGoal(goal: string, model: string, providers: ProviderRegistry): Promise<FleetSubtask[]>;
|