@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,193 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* fleet/types.ts — Shared types for parallel-agent Fleet runtime (v2).
|
|
3
|
+
*
|
|
4
|
+
* A Fleet is a bounded set of parallel subagents, each running the v2
|
|
5
|
+
* agent-loop inside its own isolated git worktree. The parent observes
|
|
6
|
+
* all of them through a single EventStream and receives a FleetResult
|
|
7
|
+
* summarising every agent's outcome.
|
|
8
|
+
*
|
|
9
|
+
* Vocabulary (carried over from v1):
|
|
10
|
+
* - worktree — filesystem isolation (git worktree)
|
|
11
|
+
* - fleet — a set of parallel agents pursuing one goal
|
|
12
|
+
* - subtask — one independent stream inside a fleet
|
|
13
|
+
* - shot — a single stylistic variant in a tripleshot
|
|
14
|
+
*/
|
|
15
|
+
import type { AgentEvent, UsageTotal, Message, StopReason } from '../kernel/types.js';
|
|
16
|
+
import type { EventStream } from '../kernel/event-stream.js';
|
|
17
|
+
export type FleetAgentStatus = 'pending' | 'running' | 'completed' | 'failed' | 'cancelled';
|
|
18
|
+
export type AgentType = 'explore' | 'plan' | 'verify' | 'code' | 'research' | 'custom';
|
|
19
|
+
export type TripleVariant = 'conservative' | 'balanced' | 'bold';
|
|
20
|
+
/** A task the fleet should run in one worktree. */
|
|
21
|
+
export interface FleetSubtask {
|
|
22
|
+
/** Short kebab-case identifier; also used as branch suffix. */
|
|
23
|
+
id: string;
|
|
24
|
+
/** Human-readable title, shown in progress output. */
|
|
25
|
+
title: string;
|
|
26
|
+
/** Prompt sent to the agent. Must be self-contained. */
|
|
27
|
+
task: string;
|
|
28
|
+
/** Agent type — determines tool allowlist. Default: 'code'. */
|
|
29
|
+
type?: AgentType;
|
|
30
|
+
/** Per-subtask model override. Default: fleet-level `model`. */
|
|
31
|
+
model?: string;
|
|
32
|
+
/** Explicit tool allowlist. Default: derived from `type`. */
|
|
33
|
+
toolAllowlist?: string[];
|
|
34
|
+
}
|
|
35
|
+
/** Live state of a single fleet agent. */
|
|
36
|
+
export interface FleetAgent {
|
|
37
|
+
id: string;
|
|
38
|
+
subtask: FleetSubtask;
|
|
39
|
+
status: FleetAgentStatus;
|
|
40
|
+
worktreePath: string;
|
|
41
|
+
branchName: string;
|
|
42
|
+
startedAt: number;
|
|
43
|
+
completedAt?: number;
|
|
44
|
+
/** Captured assistant text output. */
|
|
45
|
+
output: string;
|
|
46
|
+
/** Final error message when status = 'failed'/'cancelled'. */
|
|
47
|
+
error?: string;
|
|
48
|
+
/** Bytes of assistant text written (drives activity indicators). */
|
|
49
|
+
bytesWritten: number;
|
|
50
|
+
/** Cumulative token usage for this agent. */
|
|
51
|
+
usage: UsageTotal;
|
|
52
|
+
/** Stop reason from the agent loop. */
|
|
53
|
+
stopReason?: StopReason;
|
|
54
|
+
/** Child session id assigned by the agent loop. */
|
|
55
|
+
sessionId?: string;
|
|
56
|
+
/** Full transcript (only populated after completion). */
|
|
57
|
+
transcript?: Message[];
|
|
58
|
+
}
|
|
59
|
+
/** Handle to a git worktree created by the fleet. */
|
|
60
|
+
export interface WorktreeHandle {
|
|
61
|
+
/** Absolute path to the worktree root. */
|
|
62
|
+
path: string;
|
|
63
|
+
/** Branch name created for the worktree. */
|
|
64
|
+
branch: string;
|
|
65
|
+
/** Absolute path to the repository that owns the worktree. */
|
|
66
|
+
repoRoot: string;
|
|
67
|
+
/** HEAD commit at the time of creation. */
|
|
68
|
+
baseCommit: string;
|
|
69
|
+
}
|
|
70
|
+
/** Configuration for a fleet launch. */
|
|
71
|
+
export interface FleetConfig {
|
|
72
|
+
/** Goal to work on. */
|
|
73
|
+
goal: string;
|
|
74
|
+
/** Explicit subtasks. If omitted, runFleet() will decompose `goal`. */
|
|
75
|
+
subtasks?: FleetSubtask[];
|
|
76
|
+
/** Max concurrent agents (default 3). */
|
|
77
|
+
concurrency?: number;
|
|
78
|
+
/** Model id used by each agent. Default: `DIRGHA_MODEL` env. */
|
|
79
|
+
model?: string;
|
|
80
|
+
/** Model id used for decomposition + judge. Default: same as `model`. */
|
|
81
|
+
plannerModel?: string;
|
|
82
|
+
/** Max turns per agent (default 15). */
|
|
83
|
+
maxTurns?: number;
|
|
84
|
+
/** Timeout per agent in ms (default 10 min). */
|
|
85
|
+
timeoutMs?: number;
|
|
86
|
+
/** cwd of the parent invocation — used to locate the repo root. */
|
|
87
|
+
cwd?: string;
|
|
88
|
+
/** Subdirectory name under repoRoot for worktrees (default `.fleet`). */
|
|
89
|
+
worktreeBase?: string;
|
|
90
|
+
/** Shared event stream. Fleet events and per-agent events are emitted here. */
|
|
91
|
+
events?: EventStream;
|
|
92
|
+
/** If true, destroy worktrees once the fleet exits. Default: false. */
|
|
93
|
+
autoCleanup?: boolean;
|
|
94
|
+
/** AbortSignal to cancel the fleet. */
|
|
95
|
+
signal?: AbortSignal;
|
|
96
|
+
/** Verbose: mirror child agent text to stderr. */
|
|
97
|
+
verbose?: boolean;
|
|
98
|
+
/** Optional per-subtask progress hook. */
|
|
99
|
+
onAgent?: (agent: FleetAgent) => void;
|
|
100
|
+
}
|
|
101
|
+
/** Result of a fleet run. */
|
|
102
|
+
export interface FleetResult {
|
|
103
|
+
goal: string;
|
|
104
|
+
agents: FleetAgent[];
|
|
105
|
+
worktrees: WorktreeHandle[];
|
|
106
|
+
successCount: number;
|
|
107
|
+
failCount: number;
|
|
108
|
+
durationMs: number;
|
|
109
|
+
totalTokens: UsageTotal;
|
|
110
|
+
failed: FleetAgent[];
|
|
111
|
+
}
|
|
112
|
+
/** Apply-back strategy. */
|
|
113
|
+
export type ApplyStrategy =
|
|
114
|
+
/** Commit in the worktree, generate diff vs parent HEAD, apply 3-way to parent as unstaged. */
|
|
115
|
+
'3way'
|
|
116
|
+
/** Fast-forward merge parent branch → worktree branch (only if no divergence). */
|
|
117
|
+
| 'merge'
|
|
118
|
+
/** Cherry-pick every commit from worktree onto parent HEAD. */
|
|
119
|
+
| 'cherry-pick';
|
|
120
|
+
/** Options for applyBack(). */
|
|
121
|
+
export interface ApplyOptions {
|
|
122
|
+
strategy?: ApplyStrategy;
|
|
123
|
+
/** Commit message used for the transient commit inside the worktree. */
|
|
124
|
+
message?: string;
|
|
125
|
+
/** Restrict apply to these paths (relative to repo root). */
|
|
126
|
+
paths?: string[];
|
|
127
|
+
/** Repo root. Default: auto-detected from worktree. */
|
|
128
|
+
repoRoot?: string;
|
|
129
|
+
}
|
|
130
|
+
/** Result of an applyBack() call. */
|
|
131
|
+
export interface ApplyResult {
|
|
132
|
+
success: boolean;
|
|
133
|
+
strategy: ApplyStrategy;
|
|
134
|
+
appliedFiles: string[];
|
|
135
|
+
conflicts: string[];
|
|
136
|
+
error?: string;
|
|
137
|
+
}
|
|
138
|
+
/** A single tripleshot variant. */
|
|
139
|
+
export interface TripleshotShot {
|
|
140
|
+
variant: TripleVariant;
|
|
141
|
+
agent: FleetAgent;
|
|
142
|
+
diff: string;
|
|
143
|
+
}
|
|
144
|
+
/** Result of runTripleshot(). */
|
|
145
|
+
export interface TripleshotResult {
|
|
146
|
+
goal: string;
|
|
147
|
+
winner: TripleVariant | null;
|
|
148
|
+
runnerUp: TripleVariant | null;
|
|
149
|
+
reason: string;
|
|
150
|
+
shots: TripleshotShot[];
|
|
151
|
+
agents: FleetAgent[];
|
|
152
|
+
worktrees: WorktreeHandle[];
|
|
153
|
+
/** Set when --auto-merge is used. */
|
|
154
|
+
apply?: ApplyResult;
|
|
155
|
+
totalTokens: UsageTotal;
|
|
156
|
+
durationMs: number;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Fleet-level events forwarded into the parent EventStream.
|
|
160
|
+
* These ride alongside normal AgentEvents so the parent UI can correlate.
|
|
161
|
+
*/
|
|
162
|
+
export type FleetEvent = {
|
|
163
|
+
type: 'fleet_start';
|
|
164
|
+
goal: string;
|
|
165
|
+
agents: FleetAgent[];
|
|
166
|
+
} | {
|
|
167
|
+
type: 'fleet_agent_start';
|
|
168
|
+
agentId: string;
|
|
169
|
+
subtask: FleetSubtask;
|
|
170
|
+
worktreePath: string;
|
|
171
|
+
branch: string;
|
|
172
|
+
} | {
|
|
173
|
+
type: 'fleet_agent_progress';
|
|
174
|
+
agentId: string;
|
|
175
|
+
status: FleetAgentStatus;
|
|
176
|
+
bytes: number;
|
|
177
|
+
} | {
|
|
178
|
+
type: 'fleet_agent_end';
|
|
179
|
+
agentId: string;
|
|
180
|
+
status: FleetAgentStatus;
|
|
181
|
+
error?: string;
|
|
182
|
+
usage: UsageTotal;
|
|
183
|
+
} | {
|
|
184
|
+
type: 'fleet_end';
|
|
185
|
+
goal: string;
|
|
186
|
+
successCount: number;
|
|
187
|
+
failCount: number;
|
|
188
|
+
durationMs: number;
|
|
189
|
+
};
|
|
190
|
+
/** Helper type — union of AgentEvent and FleetEvent. */
|
|
191
|
+
export type FleetOrAgentEvent = AgentEvent | FleetEvent;
|
|
192
|
+
/** Default tool allowlists by AgentType. */
|
|
193
|
+
export declare const AGENT_TYPE_TOOLS: Record<AgentType, string[]>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* fleet/types.ts — Shared types for parallel-agent Fleet runtime (v2).
|
|
3
|
+
*
|
|
4
|
+
* A Fleet is a bounded set of parallel subagents, each running the v2
|
|
5
|
+
* agent-loop inside its own isolated git worktree. The parent observes
|
|
6
|
+
* all of them through a single EventStream and receives a FleetResult
|
|
7
|
+
* summarising every agent's outcome.
|
|
8
|
+
*
|
|
9
|
+
* Vocabulary (carried over from v1):
|
|
10
|
+
* - worktree — filesystem isolation (git worktree)
|
|
11
|
+
* - fleet — a set of parallel agents pursuing one goal
|
|
12
|
+
* - subtask — one independent stream inside a fleet
|
|
13
|
+
* - shot — a single stylistic variant in a tripleshot
|
|
14
|
+
*/
|
|
15
|
+
/** Default tool allowlists by AgentType. */
|
|
16
|
+
export const AGENT_TYPE_TOOLS = {
|
|
17
|
+
explore: ['fs_read', 'fs_ls', 'search_grep', 'search_glob', 'git'],
|
|
18
|
+
plan: ['fs_read', 'fs_ls', 'search_grep', 'search_glob'],
|
|
19
|
+
verify: ['fs_read', 'fs_ls', 'search_grep', 'search_glob', 'shell', 'git'],
|
|
20
|
+
code: ['fs_read', 'fs_write', 'fs_edit', 'fs_ls', 'search_grep', 'search_glob', 'shell', 'git'],
|
|
21
|
+
research: ['fs_read', 'fs_ls', 'search_grep', 'search_glob'],
|
|
22
|
+
custom: [],
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* fleet/worktree.ts — Create, destroy, and list git worktrees.
|
|
3
|
+
*
|
|
4
|
+
* We always shell out via execFile with argv arrays (never a shell string),
|
|
5
|
+
* so branch names and paths containing special characters are safe.
|
|
6
|
+
*
|
|
7
|
+
* Layout:
|
|
8
|
+
* <repo-root>/<worktreeBase>/<slug(branch)>/
|
|
9
|
+
*
|
|
10
|
+
* Branch naming convention for fleet:
|
|
11
|
+
* fleet/<goal-slug>/<subtask-id>
|
|
12
|
+
*
|
|
13
|
+
* Worktrees are registered on process exit so SIGINT doesn't leave them
|
|
14
|
+
* stranded — see registerExitCleanup().
|
|
15
|
+
*/
|
|
16
|
+
import type { WorktreeHandle } from './types.js';
|
|
17
|
+
/** Slug: lowercase alphanumerics + hyphens, bounded length. */
|
|
18
|
+
export declare function slug(input: string, maxLen?: number): string;
|
|
19
|
+
/** Find the git repo root (via `git rev-parse --show-toplevel`). Throws if not in a repo. */
|
|
20
|
+
export declare function getRepoRoot(cwd?: string): Promise<string>;
|
|
21
|
+
/** Get current HEAD commit SHA for a given working directory. */
|
|
22
|
+
export declare function getHeadSha(cwd: string): Promise<string>;
|
|
23
|
+
export interface CreateWorktreeOptions {
|
|
24
|
+
repoRoot: string;
|
|
25
|
+
/** Base directory under repoRoot (default `.fleet`). */
|
|
26
|
+
worktreeBase?: string;
|
|
27
|
+
/** Base ref for the new branch. Default: `HEAD`. */
|
|
28
|
+
base?: string;
|
|
29
|
+
/** If the branch already exists, check it out instead of `-b`-creating. */
|
|
30
|
+
reuseBranch?: boolean;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Create a new worktree on a fresh branch off `base` (default HEAD).
|
|
34
|
+
*
|
|
35
|
+
* Idempotent: if the target path already exists and git already knows
|
|
36
|
+
* about it, we return the existing handle instead of failing.
|
|
37
|
+
*/
|
|
38
|
+
export declare function createWorktree(branch: string, opts: CreateWorktreeOptions): Promise<WorktreeHandle>;
|
|
39
|
+
/** Remove a worktree. Falls back to `rm -rf` if git refuses. */
|
|
40
|
+
export declare function destroyWorktree(handle: WorktreeHandle, force?: boolean): Promise<void>;
|
|
41
|
+
/** Delete a local branch. Silent on failure. */
|
|
42
|
+
export declare function deleteBranch(repoRoot: string, branch: string, force?: boolean): Promise<void>;
|
|
43
|
+
/** List all git worktrees attached to this repo. Includes the primary. */
|
|
44
|
+
export declare function listWorktrees(repoRoot: string): Promise<WorktreeHandle[]>;
|
|
45
|
+
/** Public for testing — parse `git worktree list --porcelain`. */
|
|
46
|
+
export declare function parseWorktreePorcelain(stdout: string, repoRoot: string): WorktreeHandle[];
|
|
47
|
+
/**
|
|
48
|
+
* Make fleet-owned worktrees immune to cleanup. Useful after a successful
|
|
49
|
+
* apply-back when the user wants to keep the branch for review.
|
|
50
|
+
*/
|
|
51
|
+
export declare function detachFromCleanup(h: WorktreeHandle): void;
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* fleet/worktree.ts — Create, destroy, and list git worktrees.
|
|
3
|
+
*
|
|
4
|
+
* We always shell out via execFile with argv arrays (never a shell string),
|
|
5
|
+
* so branch names and paths containing special characters are safe.
|
|
6
|
+
*
|
|
7
|
+
* Layout:
|
|
8
|
+
* <repo-root>/<worktreeBase>/<slug(branch)>/
|
|
9
|
+
*
|
|
10
|
+
* Branch naming convention for fleet:
|
|
11
|
+
* fleet/<goal-slug>/<subtask-id>
|
|
12
|
+
*
|
|
13
|
+
* Worktrees are registered on process exit so SIGINT doesn't leave them
|
|
14
|
+
* stranded — see registerExitCleanup().
|
|
15
|
+
*/
|
|
16
|
+
import { execFile } from 'node:child_process';
|
|
17
|
+
import { existsSync, rmSync } from 'node:fs';
|
|
18
|
+
import { join } from 'node:path';
|
|
19
|
+
import { promisify } from 'node:util';
|
|
20
|
+
const pexec = promisify(execFile);
|
|
21
|
+
/** Slug: lowercase alphanumerics + hyphens, bounded length. */
|
|
22
|
+
export function slug(input, maxLen = 40) {
|
|
23
|
+
return input
|
|
24
|
+
.toLowerCase()
|
|
25
|
+
.replace(/[^a-z0-9]+/g, '-')
|
|
26
|
+
.replace(/(^-|-$)/g, '')
|
|
27
|
+
.slice(0, maxLen) || 'task';
|
|
28
|
+
}
|
|
29
|
+
/** Find the git repo root (via `git rev-parse --show-toplevel`). Throws if not in a repo. */
|
|
30
|
+
export async function getRepoRoot(cwd = process.cwd()) {
|
|
31
|
+
try {
|
|
32
|
+
const { stdout } = await pexec('git', ['rev-parse', '--show-toplevel'], { cwd });
|
|
33
|
+
return stdout.trim();
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
throw new Error('fleet: not inside a git repository — fleet requires a git-tracked project.');
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/** Get current HEAD commit SHA for a given working directory. */
|
|
40
|
+
export async function getHeadSha(cwd) {
|
|
41
|
+
const { stdout } = await pexec('git', ['rev-parse', 'HEAD'], { cwd });
|
|
42
|
+
return stdout.trim();
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Create a new worktree on a fresh branch off `base` (default HEAD).
|
|
46
|
+
*
|
|
47
|
+
* Idempotent: if the target path already exists and git already knows
|
|
48
|
+
* about it, we return the existing handle instead of failing.
|
|
49
|
+
*/
|
|
50
|
+
export async function createWorktree(branch, opts) {
|
|
51
|
+
const { repoRoot } = opts;
|
|
52
|
+
const base = opts.base ?? 'HEAD';
|
|
53
|
+
const worktreeBase = opts.worktreeBase ?? '.fleet';
|
|
54
|
+
const safeName = branch.replace(/\//g, '_');
|
|
55
|
+
const path = join(repoRoot, worktreeBase, safeName);
|
|
56
|
+
if (existsSync(path)) {
|
|
57
|
+
try {
|
|
58
|
+
const baseCommit = await getHeadSha(path);
|
|
59
|
+
const handle = { path, branch, repoRoot, baseCommit };
|
|
60
|
+
trackForCleanup(handle);
|
|
61
|
+
return handle;
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
// Stale directory — nuke it.
|
|
65
|
+
try {
|
|
66
|
+
rmSync(path, { recursive: true, force: true });
|
|
67
|
+
}
|
|
68
|
+
catch { /* best effort */ }
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
const args = opts.reuseBranch
|
|
72
|
+
? ['worktree', 'add', path, branch]
|
|
73
|
+
: ['worktree', 'add', '-b', branch, path, base];
|
|
74
|
+
await pexec('git', args, { cwd: repoRoot });
|
|
75
|
+
const baseCommit = await getHeadSha(path);
|
|
76
|
+
const handle = { path, branch, repoRoot, baseCommit };
|
|
77
|
+
trackForCleanup(handle);
|
|
78
|
+
return handle;
|
|
79
|
+
}
|
|
80
|
+
/** Remove a worktree. Falls back to `rm -rf` if git refuses. */
|
|
81
|
+
export async function destroyWorktree(handle, force = false) {
|
|
82
|
+
untrackForCleanup(handle);
|
|
83
|
+
if (!existsSync(handle.path))
|
|
84
|
+
return;
|
|
85
|
+
try {
|
|
86
|
+
const args = ['worktree', 'remove', handle.path];
|
|
87
|
+
if (force)
|
|
88
|
+
args.push('--force');
|
|
89
|
+
await pexec('git', args, { cwd: handle.repoRoot });
|
|
90
|
+
}
|
|
91
|
+
catch {
|
|
92
|
+
try {
|
|
93
|
+
rmSync(handle.path, { recursive: true, force: true });
|
|
94
|
+
}
|
|
95
|
+
catch { /* best effort */ }
|
|
96
|
+
}
|
|
97
|
+
// Best-effort prune of the registered worktree entry.
|
|
98
|
+
try {
|
|
99
|
+
await pexec('git', ['worktree', 'prune'], { cwd: handle.repoRoot });
|
|
100
|
+
}
|
|
101
|
+
catch { /* ignore */ }
|
|
102
|
+
}
|
|
103
|
+
/** Delete a local branch. Silent on failure. */
|
|
104
|
+
export async function deleteBranch(repoRoot, branch, force = false) {
|
|
105
|
+
try {
|
|
106
|
+
await pexec('git', ['branch', force ? '-D' : '-d', branch], { cwd: repoRoot });
|
|
107
|
+
}
|
|
108
|
+
catch { /* not an error — branch may still be in use or already gone */ }
|
|
109
|
+
}
|
|
110
|
+
/** List all git worktrees attached to this repo. Includes the primary. */
|
|
111
|
+
export async function listWorktrees(repoRoot) {
|
|
112
|
+
try {
|
|
113
|
+
const { stdout } = await pexec('git', ['worktree', 'list', '--porcelain'], { cwd: repoRoot });
|
|
114
|
+
return parseWorktreePorcelain(stdout, repoRoot);
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
return [];
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
/** Public for testing — parse `git worktree list --porcelain`. */
|
|
121
|
+
export function parseWorktreePorcelain(stdout, repoRoot) {
|
|
122
|
+
const blocks = stdout.trim().split(/\n\s*\n/);
|
|
123
|
+
const out = [];
|
|
124
|
+
for (const block of blocks) {
|
|
125
|
+
const path = /^worktree (.+)$/m.exec(block)?.[1] ?? '';
|
|
126
|
+
const head = /^HEAD (.+)$/m.exec(block)?.[1] ?? '';
|
|
127
|
+
const branch = (/^branch (.+)$/m.exec(block)?.[1] ?? '').replace(/^refs\/heads\//, '');
|
|
128
|
+
if (!path)
|
|
129
|
+
continue;
|
|
130
|
+
out.push({ path, branch: branch || '(detached)', repoRoot, baseCommit: head });
|
|
131
|
+
}
|
|
132
|
+
return out;
|
|
133
|
+
}
|
|
134
|
+
/* --------------------------------------------------------------------------
|
|
135
|
+
* Exit-cleanup registry: ensures SIGINT / uncaught exceptions don't leave
|
|
136
|
+
* worktrees behind. Managed per-process; idempotent when wired from many
|
|
137
|
+
* callers.
|
|
138
|
+
* -------------------------------------------------------------------------- */
|
|
139
|
+
const tracked = new Set();
|
|
140
|
+
let exitHandlerInstalled = false;
|
|
141
|
+
function trackForCleanup(h) {
|
|
142
|
+
tracked.add(h);
|
|
143
|
+
installExitHandler();
|
|
144
|
+
}
|
|
145
|
+
function untrackForCleanup(h) {
|
|
146
|
+
tracked.delete(h);
|
|
147
|
+
}
|
|
148
|
+
function installExitHandler() {
|
|
149
|
+
if (exitHandlerInstalled)
|
|
150
|
+
return;
|
|
151
|
+
exitHandlerInstalled = true;
|
|
152
|
+
const handler = (signal) => {
|
|
153
|
+
for (const h of tracked) {
|
|
154
|
+
try {
|
|
155
|
+
rmSync(h.path, { recursive: true, force: true });
|
|
156
|
+
}
|
|
157
|
+
catch { /* best effort */ }
|
|
158
|
+
}
|
|
159
|
+
tracked.clear();
|
|
160
|
+
if (signal) {
|
|
161
|
+
// Re-raise the signal so the default exit code is preserved.
|
|
162
|
+
process.kill(process.pid, signal);
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
process.once('SIGINT', () => handler('SIGINT'));
|
|
166
|
+
process.once('SIGTERM', () => handler('SIGTERM'));
|
|
167
|
+
process.once('exit', () => handler());
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Make fleet-owned worktrees immune to cleanup. Useful after a successful
|
|
171
|
+
* apply-back when the user wants to keep the branch for review.
|
|
172
|
+
*/
|
|
173
|
+
export function detachFromCleanup(h) {
|
|
174
|
+
untrackForCleanup(h);
|
|
175
|
+
}
|
|
176
|
+
//# sourceMappingURL=worktree.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './registry.js';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hook registry. Hooks fire at named lifecycle events: session_start,
|
|
3
|
+
* session_end, turn_start, turn_end, tool_call_before, tool_call_after,
|
|
4
|
+
* compaction_before, compaction_after. Each handler may veto by
|
|
5
|
+
* returning { block: true, reason }, in which case the caller decides
|
|
6
|
+
* how to react.
|
|
7
|
+
*/
|
|
8
|
+
export type HookEvent = 'session_start' | 'session_end' | 'turn_start' | 'turn_end' | 'tool_call_before' | 'tool_call_after' | 'compaction_before' | 'compaction_after' | 'message_user' | 'message_assistant';
|
|
9
|
+
export type HookBlock = {
|
|
10
|
+
block: true;
|
|
11
|
+
reason: string;
|
|
12
|
+
};
|
|
13
|
+
export type HookResult = void | HookBlock;
|
|
14
|
+
export type HookHandler<T = unknown> = (payload: T) => HookResult | Promise<HookResult>;
|
|
15
|
+
export declare class HookRegistry {
|
|
16
|
+
private handlers;
|
|
17
|
+
on<T = unknown>(event: HookEvent, handler: HookHandler<T>): () => void;
|
|
18
|
+
emit<T = unknown>(event: HookEvent, payload: T): Promise<HookBlock | undefined>;
|
|
19
|
+
clear(event?: HookEvent): void;
|
|
20
|
+
}
|
|
21
|
+
export declare function createHookRegistry(): HookRegistry;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hook registry. Hooks fire at named lifecycle events: session_start,
|
|
3
|
+
* session_end, turn_start, turn_end, tool_call_before, tool_call_after,
|
|
4
|
+
* compaction_before, compaction_after. Each handler may veto by
|
|
5
|
+
* returning { block: true, reason }, in which case the caller decides
|
|
6
|
+
* how to react.
|
|
7
|
+
*/
|
|
8
|
+
export class HookRegistry {
|
|
9
|
+
handlers = new Map();
|
|
10
|
+
on(event, handler) {
|
|
11
|
+
let set = this.handlers.get(event);
|
|
12
|
+
if (!set) {
|
|
13
|
+
set = new Set();
|
|
14
|
+
this.handlers.set(event, set);
|
|
15
|
+
}
|
|
16
|
+
set.add(handler);
|
|
17
|
+
return () => { set?.delete(handler); };
|
|
18
|
+
}
|
|
19
|
+
async emit(event, payload) {
|
|
20
|
+
const set = this.handlers.get(event);
|
|
21
|
+
if (!set)
|
|
22
|
+
return undefined;
|
|
23
|
+
for (const handler of set) {
|
|
24
|
+
const outcome = await handler(payload);
|
|
25
|
+
if (outcome && outcome.block)
|
|
26
|
+
return outcome;
|
|
27
|
+
}
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
clear(event) {
|
|
31
|
+
if (event)
|
|
32
|
+
this.handlers.get(event)?.clear();
|
|
33
|
+
else
|
|
34
|
+
this.handlers.clear();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
export function createHookRegistry() {
|
|
38
|
+
return new HookRegistry();
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Library entrypoint for the v2 core.
|
|
3
|
+
*
|
|
4
|
+
* Re-exports the kernel, providers, and tools so embedders can build
|
|
5
|
+
* their own agents against the same primitives the CLI binary uses.
|
|
6
|
+
*/
|
|
7
|
+
export * from './kernel/index.js';
|
|
8
|
+
export { ProviderRegistry, ProviderError, NvidiaProvider, OpenRouterProvider, OpenAIProvider, AnthropicProvider, GeminiProvider, OllamaProvider, FireworksProvider, routeModel, isKnownProvider, } from './providers/index.js';
|
|
9
|
+
export type { ProviderId, ProviderConfig, ProviderRegistryConfig, } from './providers/index.js';
|
|
10
|
+
export { ToolRegistry, createToolRegistry, createToolExecutor, DefaultPermissionEngine, builtInTools, fsReadTool, fsWriteTool, fsEditTool, fsLsTool, shellTool, searchGrepTool, searchGlobTool, gitTool, unifiedDiff, summariseDiff, } from './tools/index.js';
|
|
11
|
+
export type { Tool, ToolContext, PermissionEngine, PermissionCheck, PermissionDecision, } from './tools/index.js';
|
|
12
|
+
export { repairJSON } from './utils/json-repair.js';
|
package/dist_v2/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Library entrypoint for the v2 core.
|
|
3
|
+
*
|
|
4
|
+
* Re-exports the kernel, providers, and tools so embedders can build
|
|
5
|
+
* their own agents against the same primitives the CLI binary uses.
|
|
6
|
+
*/
|
|
7
|
+
export * from './kernel/index.js';
|
|
8
|
+
export { ProviderRegistry, ProviderError, NvidiaProvider, OpenRouterProvider, OpenAIProvider, AnthropicProvider, GeminiProvider, OllamaProvider, FireworksProvider, routeModel, isKnownProvider, } from './providers/index.js';
|
|
9
|
+
export { ToolRegistry, createToolRegistry, createToolExecutor, DefaultPermissionEngine, builtInTools, fsReadTool, fsWriteTool, fsEditTool, fsLsTool, shellTool, searchGrepTool, searchGlobTool, gitTool, unifiedDiff, summariseDiff, } from './tools/index.js';
|
|
10
|
+
export { repairJSON } from './utils/json-repair.js';
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Arniko security scanner client. Supports code scans by string,
|
|
3
|
+
* directory path, or git diff. When the service is unreachable, the
|
|
4
|
+
* bootstrap() entry attempts to bring up the docker-compose file that
|
|
5
|
+
* ships in the user's `~/.dirgha/arniko/` directory.
|
|
6
|
+
*/
|
|
7
|
+
export interface Finding {
|
|
8
|
+
id: string;
|
|
9
|
+
severity: 'critical' | 'high' | 'medium' | 'low';
|
|
10
|
+
title: string;
|
|
11
|
+
file?: string;
|
|
12
|
+
line?: number;
|
|
13
|
+
snippet?: string;
|
|
14
|
+
reason: string;
|
|
15
|
+
}
|
|
16
|
+
export interface ScanResult {
|
|
17
|
+
passed: boolean;
|
|
18
|
+
findings: Finding[];
|
|
19
|
+
maturityScore: number;
|
|
20
|
+
taskId?: string;
|
|
21
|
+
reason?: string;
|
|
22
|
+
}
|
|
23
|
+
export interface ArnikoClientOptions {
|
|
24
|
+
baseUrl?: string;
|
|
25
|
+
timeoutMs?: number;
|
|
26
|
+
}
|
|
27
|
+
export declare function createArnikoClient(opts?: ArnikoClientOptions): {
|
|
28
|
+
isAvailable(): Promise<boolean>;
|
|
29
|
+
scanCode(code: string, taskId?: string): Promise<ScanResult>;
|
|
30
|
+
scanPath(path: string, opts?: {
|
|
31
|
+
tools?: string[];
|
|
32
|
+
}): Promise<ScanResult>;
|
|
33
|
+
scanDiff(diffPath: string, opts?: {
|
|
34
|
+
tools?: string[];
|
|
35
|
+
}): Promise<ScanResult>;
|
|
36
|
+
bootstrap(composePath: string): Promise<{
|
|
37
|
+
started: boolean;
|
|
38
|
+
message: string;
|
|
39
|
+
}>;
|
|
40
|
+
summarise(result: ScanResult): string;
|
|
41
|
+
};
|
|
42
|
+
export type ArnikoClient = ReturnType<typeof createArnikoClient>;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Arniko security scanner client. Supports code scans by string,
|
|
3
|
+
* directory path, or git diff. When the service is unreachable, the
|
|
4
|
+
* bootstrap() entry attempts to bring up the docker-compose file that
|
|
5
|
+
* ships in the user's `~/.dirgha/arniko/` directory.
|
|
6
|
+
*/
|
|
7
|
+
import { readFile, stat } from 'node:fs/promises';
|
|
8
|
+
import { resolve } from 'node:path';
|
|
9
|
+
import { spawn } from 'node:child_process';
|
|
10
|
+
import { jsonRequest, IntegrationError } from './http.js';
|
|
11
|
+
export function createArnikoClient(opts = {}) {
|
|
12
|
+
const baseUrl = opts.baseUrl ?? process.env.DIRGHA_ARNIKO_URL ?? 'http://localhost:3010';
|
|
13
|
+
const timeoutMs = opts.timeoutMs ?? 60_000;
|
|
14
|
+
return {
|
|
15
|
+
async isAvailable() {
|
|
16
|
+
try {
|
|
17
|
+
await jsonRequest({ baseUrl, path: '/healthz', timeoutMs: 2000 });
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
async scanCode(code, taskId) {
|
|
25
|
+
return jsonRequest({
|
|
26
|
+
baseUrl,
|
|
27
|
+
path: '/api/arniko/scans',
|
|
28
|
+
method: 'POST',
|
|
29
|
+
body: {
|
|
30
|
+
tools: ['semgrep', 'trufflehog'],
|
|
31
|
+
target: { type: 'code', identifier: taskId ?? 'inline', metadata: { code } },
|
|
32
|
+
},
|
|
33
|
+
timeoutMs,
|
|
34
|
+
});
|
|
35
|
+
},
|
|
36
|
+
async scanPath(path, opts = {}) {
|
|
37
|
+
const abs = resolve(path);
|
|
38
|
+
const info = await stat(abs).catch(() => undefined);
|
|
39
|
+
if (!info)
|
|
40
|
+
throw new IntegrationError(`Path does not exist: ${path}`);
|
|
41
|
+
return jsonRequest({
|
|
42
|
+
baseUrl,
|
|
43
|
+
path: '/api/arniko/scans',
|
|
44
|
+
method: 'POST',
|
|
45
|
+
body: {
|
|
46
|
+
tools: opts.tools ?? ['semgrep', 'trufflehog'],
|
|
47
|
+
target: { type: 'path', identifier: abs, metadata: {} },
|
|
48
|
+
},
|
|
49
|
+
timeoutMs,
|
|
50
|
+
});
|
|
51
|
+
},
|
|
52
|
+
async scanDiff(diffPath, opts = {}) {
|
|
53
|
+
const diff = await readFile(diffPath, 'utf8');
|
|
54
|
+
return jsonRequest({
|
|
55
|
+
baseUrl,
|
|
56
|
+
path: '/api/arniko/scans',
|
|
57
|
+
method: 'POST',
|
|
58
|
+
body: {
|
|
59
|
+
tools: opts.tools ?? ['semgrep', 'trufflehog'],
|
|
60
|
+
target: { type: 'diff', identifier: diffPath, metadata: { diff } },
|
|
61
|
+
},
|
|
62
|
+
timeoutMs,
|
|
63
|
+
});
|
|
64
|
+
},
|
|
65
|
+
async bootstrap(composePath) {
|
|
66
|
+
return new Promise(resolveBootstrap => {
|
|
67
|
+
const child = spawn('docker', ['compose', '-f', composePath, 'up', '-d'], { stdio: 'pipe' });
|
|
68
|
+
const errChunks = [];
|
|
69
|
+
child.stderr.on('data', (b) => errChunks.push(b));
|
|
70
|
+
child.on('error', err => resolveBootstrap({ started: false, message: err.message }));
|
|
71
|
+
child.on('exit', code => resolveBootstrap({
|
|
72
|
+
started: code === 0,
|
|
73
|
+
message: code === 0 ? 'docker compose up -d exited 0' : Buffer.concat(errChunks).toString('utf8'),
|
|
74
|
+
}));
|
|
75
|
+
});
|
|
76
|
+
},
|
|
77
|
+
summarise(result) {
|
|
78
|
+
const counts = { critical: 0, high: 0, medium: 0, low: 0 };
|
|
79
|
+
for (const f of result.findings)
|
|
80
|
+
counts[f.severity]++;
|
|
81
|
+
const verdict = result.passed ? 'PASS' : 'FAIL';
|
|
82
|
+
return `security: ${verdict} · maturity=${result.maturityScore.toFixed(2)} · C=${counts.critical} H=${counts.high} M=${counts.medium} L=${counts.low}`;
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=arniko-client.js.map
|