@armadra/agent 0.4.0 → 0.5.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/CHANGELOG.md +174 -1
- package/README.md +201 -82
- package/THIRD_PARTY_NOTICES.md +34 -0
- package/dist/acp.d.ts +18 -0
- package/dist/acp.js +19 -0
- package/dist/agent/limits.d.ts +38 -0
- package/dist/agent/limits.js +127 -0
- package/dist/agent/loop-guard.d.ts +38 -0
- package/dist/agent/loop-guard.js +95 -0
- package/dist/agent/loop.d.ts +4 -0
- package/dist/agent/loop.js +7 -0
- package/dist/agent/prompt-rules.d.ts +12 -0
- package/dist/agent/prompt-rules.js +18 -0
- package/dist/agent/reminders.d.ts +59 -0
- package/dist/agent/reminders.js +327 -0
- package/dist/agent/session-cache.d.ts +5 -0
- package/dist/agent/session-cache.js +17 -1
- package/dist/agent/session-classifier.d.ts +1 -1
- package/dist/agent/session-classifier.js +3 -1
- package/dist/agent/session-compaction.d.ts +35 -6
- package/dist/agent/session-compaction.js +157 -31
- package/dist/agent/session-core.d.ts +27 -1
- package/dist/agent/session-extensions.d.ts +61 -0
- package/dist/agent/session-extensions.js +129 -0
- package/dist/agent/session-images.d.ts +23 -0
- package/dist/agent/session-images.js +97 -0
- package/dist/agent/session-plan.d.ts +21 -0
- package/dist/agent/session-plan.js +524 -0
- package/dist/agent/session-rewind.d.ts +81 -0
- package/dist/agent/session-rewind.js +354 -0
- package/dist/agent/session-run.d.ts +28 -1
- package/dist/agent/session-run.js +157 -6
- package/dist/agent/session-settings.d.ts +49 -0
- package/dist/agent/session-settings.js +95 -0
- package/dist/agent/session-subagent.d.ts +36 -24
- package/dist/agent/session-subagent.js +259 -129
- package/dist/agent/session-sync.d.ts +10 -3
- package/dist/agent/session-sync.js +37 -8
- package/dist/agent/session-telemetry.d.ts +39 -0
- package/dist/agent/session-telemetry.js +231 -0
- package/dist/agent/session-tools.js +40 -1
- package/dist/agent/session.d.ts +30 -29
- package/dist/agent/session.js +79 -123
- package/dist/agent/subagent-registry.d.ts +91 -0
- package/dist/agent/subagent-registry.js +494 -0
- package/dist/agent/system-prompt.d.ts +6 -3
- package/dist/agent/system-prompt.js +7 -2
- package/dist/agent/tool-runner.d.ts +8 -1
- package/dist/agent/tool-runner.js +57 -4
- package/dist/agent/types-w5.d.ts +192 -0
- package/dist/agent/types-w5.js +10 -0
- package/dist/agent/types.d.ts +47 -4
- package/dist/agent/types.js +2 -0
- package/dist/agent/worktree.d.ts +36 -0
- package/dist/agent/worktree.js +86 -0
- package/dist/agents/builtin.d.ts +14 -0
- package/dist/agents/builtin.js +39 -0
- package/dist/agents/catalog.d.ts +43 -0
- package/dist/agents/catalog.js +82 -0
- package/dist/agents/discover.d.ts +35 -0
- package/dist/agents/discover.js +83 -0
- package/dist/agents/external.d.ts +82 -0
- package/dist/agents/external.js +326 -0
- package/dist/agents/parse.d.ts +18 -0
- package/dist/agents/parse.js +116 -0
- package/dist/agents/result.d.ts +32 -0
- package/dist/agents/result.js +67 -0
- package/dist/agents/task-control.d.ts +17 -0
- package/dist/agents/task-control.js +17 -0
- package/dist/agents/task-record.d.ts +78 -0
- package/dist/agents/task-record.js +141 -0
- package/dist/agents/types.d.ts +46 -0
- package/dist/agents/types.js +8 -0
- package/dist/ai/apis/anthropic-compat.d.ts +36 -0
- package/dist/ai/apis/anthropic-compat.js +92 -0
- package/dist/ai/apis/anthropic-request.d.ts +7 -6
- package/dist/ai/apis/anthropic-request.js +10 -28
- package/dist/ai/apis/cache-params.d.ts +11 -2
- package/dist/ai/apis/cache-params.js +25 -6
- package/dist/ai/apis/openai-compat.d.ts +4 -1
- package/dist/ai/apis/openai-compat.js +8 -1
- package/dist/ai/image-limits.d.ts +45 -0
- package/dist/ai/image-limits.js +68 -0
- package/dist/ai/providers/builtin.d.ts +18 -6
- package/dist/ai/providers/builtin.js +135 -6
- package/dist/ai/providers/catalog-data.js +17 -13
- package/dist/ai/providers/catalog.d.ts +60 -7
- package/dist/ai/providers/catalog.js +197 -38
- package/dist/ai/providers/channels.d.ts +33 -3
- package/dist/ai/providers/channels.js +108 -7
- package/dist/ai/providers/enrich.d.ts +6 -3
- package/dist/ai/providers/enrich.js +19 -4
- package/dist/ai/providers/models-dev-cache.d.ts +28 -24
- package/dist/ai/providers/models-dev-cache.js +92 -78
- package/dist/ai/providers/models-dev-data.d.ts +7 -0
- package/dist/ai/providers/models-dev-data.js +32 -0
- package/dist/ai/providers/models-dev-snapshot.d.ts +50 -0
- package/dist/ai/providers/models-dev-snapshot.js +137 -0
- package/dist/ai/providers/models-dev.d.ts +51 -10
- package/dist/ai/providers/models-dev.js +132 -39
- package/dist/ai/providers/registry.d.ts +20 -10
- package/dist/ai/providers/registry.js +82 -43
- package/dist/ai/types.d.ts +28 -2
- package/dist/ai/types.js +5 -0
- package/dist/bundle/ama.cjs +36203 -20499
- package/dist/checkpoints/backend.d.ts +61 -0
- package/dist/checkpoints/backend.js +135 -0
- package/dist/checkpoints/blobs.d.ts +60 -0
- package/dist/checkpoints/blobs.js +203 -0
- package/dist/checkpoints/gc.d.ts +47 -0
- package/dist/checkpoints/gc.js +144 -0
- package/dist/checkpoints/git-head.d.ts +15 -0
- package/dist/checkpoints/git-head.js +89 -0
- package/dist/checkpoints/index.d.ts +17 -0
- package/dist/checkpoints/index.js +17 -0
- package/dist/checkpoints/replay.d.ts +48 -0
- package/dist/checkpoints/replay.js +154 -0
- package/dist/checkpoints/restore.d.ts +86 -0
- package/dist/checkpoints/restore.js +263 -0
- package/dist/checkpoints/settings.d.ts +14 -0
- package/dist/checkpoints/settings.js +23 -0
- package/dist/checkpoints/shadow-git.d.ts +108 -0
- package/dist/checkpoints/shadow-git.js +491 -0
- package/dist/checkpoints/shadow-restore.d.ts +25 -0
- package/dist/checkpoints/shadow-restore.js +128 -0
- package/dist/checkpoints/tracker.d.ts +64 -0
- package/dist/checkpoints/tracker.js +192 -0
- package/dist/checkpoints/types.d.ts +99 -0
- package/dist/checkpoints/types.js +12 -0
- package/dist/cli/args.d.ts +8 -4
- package/dist/cli/args.js +17 -97
- package/dist/cli/bootstrap.js +13 -1
- package/dist/cli/codemode-notice.d.ts +3 -2
- package/dist/cli/codemode-notice.js +3 -2
- package/dist/cli/compose-agents.d.ts +27 -0
- package/dist/cli/compose-agents.js +111 -0
- package/dist/cli/compose-extensions.d.ts +29 -0
- package/dist/cli/compose-extensions.js +44 -0
- package/dist/cli/compose-session.d.ts +3 -0
- package/dist/cli/compose-session.js +47 -4
- package/dist/cli/compose.d.ts +3 -0
- package/dist/cli/compose.js +33 -6
- package/dist/cli/deps.d.ts +6 -0
- package/dist/cli/exit-codes.d.ts +10 -0
- package/dist/cli/exit-codes.js +12 -0
- package/dist/cli/help-text.d.ts +4 -0
- package/dist/cli/help-text.js +102 -0
- package/dist/cli/startup-screen.js +5 -3
- package/dist/cli/startup-steps.js +7 -1
- package/dist/cli/subcommands/config.d.ts +4 -1
- package/dist/cli/subcommands/config.js +17 -6
- package/dist/cli/subcommands/doctor.js +21 -0
- package/dist/cli/subcommands/models-discover.js +5 -6
- package/dist/cli/subcommands/models.d.ts +2 -0
- package/dist/cli/subcommands/models.js +33 -14
- package/dist/cli/subcommands/providers.js +5 -6
- package/dist/cli/subcommands/sessions.d.ts +3 -1
- package/dist/cli/subcommands/sessions.js +36 -2
- package/dist/codemode/capability.d.ts +24 -7
- package/dist/codemode/capability.js +38 -10
- package/dist/codemode/host-side.d.ts +14 -0
- package/dist/codemode/host-side.js +24 -1
- package/dist/codemode/tool.d.ts +1 -1
- package/dist/codemode/tool.js +6 -4
- package/dist/compaction/breaker.d.ts +25 -9
- package/dist/compaction/breaker.js +47 -17
- package/dist/compaction/estimate.d.ts +11 -3
- package/dist/compaction/estimate.js +64 -22
- package/dist/compaction/image-budget.d.ts +45 -0
- package/dist/compaction/image-budget.js +115 -0
- package/dist/compaction/post-compact.d.ts +38 -0
- package/dist/compaction/post-compact.js +152 -0
- package/dist/compaction/protect.d.ts +27 -0
- package/dist/compaction/protect.js +56 -0
- package/dist/compaction/prune-tier.d.ts +58 -12
- package/dist/compaction/prune-tier.js +120 -54
- package/dist/compaction/summarize-tier.d.ts +23 -4
- package/dist/compaction/summarize-tier.js +100 -29
- package/dist/config/checker.d.ts +28 -0
- package/dist/config/checker.js +97 -0
- package/dist/config/json-schema.js +63 -2
- package/dist/config/key-docs.js +72 -3
- package/dist/config/merge.d.ts +5 -3
- package/dist/config/merge.js +81 -7
- package/dist/config/profile.d.ts +2 -0
- package/dist/config/profile.js +2 -0
- package/dist/config/schema-w5.d.ts +18 -0
- package/dist/config/schema-w5.js +109 -0
- package/dist/config/schema.d.ts +5 -9
- package/dist/config/schema.js +68 -114
- package/dist/config/types-w5.d.ts +118 -0
- package/dist/config/types-w5.js +20 -0
- package/dist/config/types.d.ts +50 -1
- package/dist/config/types.js +12 -0
- package/dist/drivers/acp/client.d.ts +57 -0
- package/dist/drivers/acp/client.js +160 -0
- package/dist/drivers/acp/driver.d.ts +31 -0
- package/dist/drivers/acp/driver.js +274 -0
- package/dist/drivers/acp/testing/fake-agent-main.d.ts +5 -0
- package/dist/drivers/acp/testing/fake-agent-main.js +7 -0
- package/dist/drivers/acp/testing/fake-agent.d.ts +27 -0
- package/dist/drivers/acp/testing/fake-agent.js +211 -0
- package/dist/drivers/acp/types.d.ts +285 -0
- package/dist/drivers/acp/types.js +36 -0
- package/dist/drivers/agents.d.ts +58 -0
- package/dist/drivers/agents.js +142 -0
- package/dist/drivers/base.d.ts +35 -0
- package/dist/drivers/base.js +59 -0
- package/dist/drivers/catalog.d.ts +46 -0
- package/dist/drivers/catalog.js +167 -0
- package/dist/drivers/env.d.ts +20 -0
- package/dist/drivers/env.js +46 -0
- package/dist/drivers/host-runners.d.ts +18 -0
- package/dist/drivers/host-runners.js +45 -0
- package/dist/drivers/jsonrpc.d.ts +58 -0
- package/dist/drivers/jsonrpc.js +180 -0
- package/dist/drivers/native/claude-normalize.d.ts +46 -0
- package/dist/drivers/native/claude-normalize.js +106 -0
- package/dist/drivers/native/claude-stream.d.ts +29 -0
- package/dist/drivers/native/claude-stream.js +456 -0
- package/dist/drivers/native/codex-app-server.d.ts +26 -0
- package/dist/drivers/native/codex-app-server.js +407 -0
- package/dist/drivers/native/codex-normalize.d.ts +38 -0
- package/dist/drivers/native/codex-normalize.js +124 -0
- package/dist/drivers/native/oneshot.d.ts +28 -0
- package/dist/drivers/native/oneshot.js +312 -0
- package/dist/drivers/permissions.d.ts +40 -0
- package/dist/drivers/permissions.js +92 -0
- package/dist/drivers/pids.d.ts +32 -0
- package/dist/drivers/pids.js +93 -0
- package/dist/drivers/pool.d.ts +28 -0
- package/dist/drivers/pool.js +96 -0
- package/dist/drivers/probe.d.ts +47 -0
- package/dist/drivers/probe.js +172 -0
- package/dist/drivers/process.d.ts +48 -0
- package/dist/drivers/process.js +100 -0
- package/dist/drivers/runner.d.ts +61 -0
- package/dist/drivers/runner.js +388 -0
- package/dist/drivers/store.d.ts +49 -0
- package/dist/drivers/store.js +91 -0
- package/dist/drivers/turn.d.ts +41 -0
- package/dist/drivers/turn.js +99 -0
- package/dist/drivers/types.d.ts +122 -0
- package/dist/drivers/types.js +11 -0
- package/dist/git/info.d.ts +75 -0
- package/dist/git/info.js +191 -0
- package/dist/hooks/protocol.js +6 -1
- package/dist/hooks/types.d.ts +10 -1
- package/dist/hooks/types.js +2 -0
- package/dist/host/api-impl.d.ts +7 -0
- package/dist/host/api-impl.js +15 -0
- package/dist/host/types.d.ts +24 -2
- package/dist/host/types.js +4 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +1 -0
- package/dist/modes/acp/acp-events.d.ts +46 -0
- package/dist/modes/acp/acp-events.js +233 -0
- package/dist/modes/acp/acp-mode.d.ts +17 -0
- package/dist/modes/acp/acp-mode.js +47 -0
- package/dist/modes/acp/acp-server.d.ts +79 -0
- package/dist/modes/acp/acp-server.js +315 -0
- package/dist/modes/commands-core.d.ts +7 -1
- package/dist/modes/commands-core.js +55 -0
- package/dist/modes/image-input.d.ts +12 -4
- package/dist/modes/image-input.js +22 -5
- package/dist/modes/interactive/agent-panels.d.ts +14 -0
- package/dist/modes/interactive/agent-panels.js +103 -0
- package/dist/modes/interactive/agent-ui.d.ts +73 -0
- package/dist/modes/interactive/agent-ui.js +234 -0
- package/dist/modes/interactive/approval-dialog.d.ts +21 -4
- package/dist/modes/interactive/approval-dialog.js +98 -20
- package/dist/modes/interactive/approval-merge.d.ts +41 -0
- package/dist/modes/interactive/approval-merge.js +89 -0
- package/dist/modes/interactive/clipboard-paste.d.ts +18 -0
- package/dist/modes/interactive/clipboard-paste.js +28 -0
- package/dist/modes/interactive/commands.d.ts +9 -1
- package/dist/modes/interactive/commands.js +19 -0
- package/dist/modes/interactive/double-esc.d.ts +20 -0
- package/dist/modes/interactive/double-esc.js +34 -0
- package/dist/modes/interactive/event-notices.d.ts +32 -0
- package/dist/modes/interactive/event-notices.js +79 -0
- package/dist/modes/interactive/external-editor.d.ts +16 -0
- package/dist/modes/interactive/external-editor.js +39 -0
- package/dist/modes/interactive/interactive-mode.d.ts +14 -1
- package/dist/modes/interactive/interactive-mode.js +134 -136
- package/dist/modes/interactive/key-dispatch.d.ts +16 -2
- package/dist/modes/interactive/key-dispatch.js +49 -1
- package/dist/modes/interactive/line/line-mode.d.ts +2 -1
- package/dist/modes/interactive/line/line-mode.js +22 -5
- package/dist/modes/interactive/line/line-render.d.ts +2 -1
- package/dist/modes/interactive/line/line-render.js +40 -4
- package/dist/modes/interactive/message-view.d.ts +1 -1
- package/dist/modes/interactive/message-view.js +24 -2
- package/dist/modes/interactive/panels.d.ts +18 -1
- package/dist/modes/interactive/panels.js +19 -5
- package/dist/modes/interactive/plan-command.d.ts +40 -0
- package/dist/modes/interactive/plan-command.js +129 -0
- package/dist/modes/interactive/plan-dialog.d.ts +98 -0
- package/dist/modes/interactive/plan-dialog.js +290 -0
- package/dist/modes/interactive/plan-flow.d.ts +34 -0
- package/dist/modes/interactive/plan-flow.js +98 -0
- package/dist/modes/interactive/rewind-command.d.ts +31 -0
- package/dist/modes/interactive/rewind-command.js +106 -0
- package/dist/modes/interactive/rewind-flow.d.ts +37 -0
- package/dist/modes/interactive/rewind-flow.js +151 -0
- package/dist/modes/interactive/rewind-list.d.ts +36 -0
- package/dist/modes/interactive/rewind-list.js +123 -0
- package/dist/modes/interactive/rewind-panel.d.ts +77 -0
- package/dist/modes/interactive/rewind-panel.js +309 -0
- package/dist/modes/interactive/rewind-text.d.ts +40 -0
- package/dist/modes/interactive/rewind-text.js +139 -0
- package/dist/modes/interactive/session-events.d.ts +24 -0
- package/dist/modes/interactive/session-events.js +96 -0
- package/dist/modes/interactive/status-area.d.ts +73 -0
- package/dist/modes/interactive/status-area.js +190 -0
- package/dist/modes/interactive/status-bar.d.ts +99 -11
- package/dist/modes/interactive/status-bar.js +273 -90
- package/dist/modes/interactive/status-line.d.ts +33 -0
- package/dist/modes/interactive/status-line.js +113 -0
- package/dist/modes/interactive/subagent-view.d.ts +56 -0
- package/dist/modes/interactive/subagent-view.js +154 -0
- package/dist/modes/interactive/tasks-report.d.ts +27 -0
- package/dist/modes/interactive/tasks-report.js +114 -0
- package/dist/modes/interactive/tool-view.d.ts +12 -2
- package/dist/modes/interactive/tool-view.js +34 -4
- package/dist/modes/print/print-mode.d.ts +13 -4
- package/dist/modes/print/print-mode.js +56 -12
- package/dist/modes/rpc/commands.d.ts +9 -0
- package/dist/modes/rpc/commands.js +44 -0
- package/dist/modes/rpc/rpc-mode.js +7 -1
- package/dist/modes/session-report.d.ts +11 -0
- package/dist/modes/session-report.js +48 -1
- package/dist/permissions/auto-safe.d.ts +5 -0
- package/dist/permissions/auto-safe.js +18 -0
- package/dist/permissions/classifier.d.ts +4 -0
- package/dist/permissions/classifier.js +2 -0
- package/dist/permissions/modes.js +1 -1
- package/dist/permissions/pipeline.d.ts +43 -4
- package/dist/permissions/pipeline.js +114 -9
- package/dist/permissions/readonly-bash.d.ts +30 -0
- package/dist/permissions/readonly-bash.js +118 -0
- package/dist/permissions/types.d.ts +42 -0
- package/dist/plan/compose.d.ts +9 -0
- package/dist/plan/compose.js +19 -0
- package/dist/plan/controller.d.ts +71 -0
- package/dist/plan/controller.js +27 -0
- package/dist/plan/done-markers.d.ts +17 -0
- package/dist/plan/done-markers.js +51 -0
- package/dist/plan/extract.d.ts +29 -0
- package/dist/plan/extract.js +160 -0
- package/dist/plan/prompts.d.ts +36 -0
- package/dist/plan/prompts.js +89 -0
- package/dist/plan/store.d.ts +37 -0
- package/dist/plan/store.js +90 -0
- package/dist/rpc.d.ts +58 -2
- package/dist/rpc.js +7 -0
- package/dist/sandbox/bash.d.ts +74 -0
- package/dist/sandbox/bash.js +126 -0
- package/dist/sandbox/detect.d.ts +48 -0
- package/dist/sandbox/detect.js +149 -0
- package/dist/sandbox/index.d.ts +5 -0
- package/dist/sandbox/index.js +5 -0
- package/dist/sandbox/profile.d.ts +33 -0
- package/dist/sandbox/profile.js +76 -0
- package/dist/sandbox/wrap.d.ts +29 -0
- package/dist/sandbox/wrap.js +117 -0
- package/dist/sdk.d.ts +33 -2
- package/dist/sdk.js +24 -2
- package/dist/session/types.d.ts +3 -1
- package/dist/session/types.js +1 -0
- package/dist/skills/builtin.d.ts +31 -0
- package/dist/skills/builtin.js +109 -0
- package/dist/skills/discover.d.ts +2 -1
- package/dist/skills/index-prompt.js +5 -8
- package/dist/tools/background-jobs.d.ts +71 -0
- package/dist/tools/background-jobs.js +198 -0
- package/dist/tools/bash.d.ts +53 -1
- package/dist/tools/bash.js +158 -7
- package/dist/tools/clipboard-image.d.ts +44 -0
- package/dist/tools/clipboard-image.js +148 -0
- package/dist/tools/edit.d.ts +2 -0
- package/dist/tools/edit.js +18 -3
- package/dist/tools/image-file.d.ts +38 -3
- package/dist/tools/image-file.js +81 -10
- package/dist/tools/image-resize.d.ts +58 -0
- package/dist/tools/image-resize.js +97 -0
- package/dist/tools/presets.d.ts +7 -2
- package/dist/tools/presets.js +11 -4
- package/dist/tools/read.d.ts +5 -2
- package/dist/tools/read.js +13 -10
- package/dist/tools/registry.d.ts +7 -1
- package/dist/tools/registry.js +27 -4
- package/dist/tools/task-ctl.d.ts +22 -0
- package/dist/tools/task-ctl.js +116 -0
- package/dist/tools/task.d.ts +22 -10
- package/dist/tools/task.js +66 -26
- package/dist/tools/todo.d.ts +22 -2
- package/dist/tools/todo.js +58 -14
- package/dist/tools/truncate.d.ts +15 -0
- package/dist/tools/truncate.js +25 -0
- package/dist/tools/types.d.ts +113 -0
- package/dist/tools/types.js +5 -0
- package/dist/tools/write.js +3 -0
- package/dist/tui/glyphs.d.ts +4 -0
- package/dist/tui/glyphs.js +4 -0
- package/dist/tui/keybindings.d.ts +5 -0
- package/dist/tui/keybindings.js +5 -0
- package/docs/acp.md +78 -0
- package/docs/agents.md +250 -0
- package/docs/codemode.md +12 -8
- package/docs/hooks.md +26 -22
- package/docs/permissions.md +77 -13
- package/docs/plan.md +107 -0
- package/docs/providers.md +228 -52
- package/docs/rewind-plan.md +181 -0
- package/docs/rpc.md +92 -5
- package/docs/sandbox.md +215 -0
- package/docs/session-format.md +41 -21
- package/docs/sessions.md +41 -1
- package/docs/tui-design.md +751 -0
- package/docs/tui.md +125 -6
- package/package.json +13 -2
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSON-RPC 2.0 over NDJSON 的对等端(docs/wave5-plan.md §5.1)。[W5-E]
|
|
3
|
+
*
|
|
4
|
+
* ACP 客户端 / 服务端与 Codex app-server 驱动共用:
|
|
5
|
+
* - 分帧复用 `modes/rpc/jsonl.ts`(只按 `\n` 切行、64 KiB 分片写、背压等 drain),写入串行;
|
|
6
|
+
* - 双向:本端可发请求 / 通知,也处理对端的请求(`onRequest` 抛 {@link RpcError} 即回错误)与通知;
|
|
7
|
+
* - `jsonrpcField: false` 时不写 `"jsonrpc":"2.0"`(Codex app-server 的线上形状),读取两种都认;
|
|
8
|
+
* - 连接关闭(输入流结束)时所有挂起的请求以 `connection_closed` 失败。
|
|
9
|
+
*/
|
|
10
|
+
import { createLineReader, writeChunked } from "../modes/rpc/jsonl.js";
|
|
11
|
+
import { RPC_ERRORS } from "./acp/types.js";
|
|
12
|
+
export class RpcError extends Error {
|
|
13
|
+
code;
|
|
14
|
+
data;
|
|
15
|
+
constructor(code, message, data) {
|
|
16
|
+
super(message);
|
|
17
|
+
this.code = code;
|
|
18
|
+
this.data = data;
|
|
19
|
+
this.name = "RpcError";
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export class JsonRpcPeer {
|
|
23
|
+
options;
|
|
24
|
+
pending = new Map();
|
|
25
|
+
reader;
|
|
26
|
+
lifetime = new AbortController();
|
|
27
|
+
nextId = 1;
|
|
28
|
+
writing = Promise.resolve();
|
|
29
|
+
isClosed = false;
|
|
30
|
+
resolveClosed;
|
|
31
|
+
/** 输入流结束或 `close()` 后 resolve。 */
|
|
32
|
+
closed = new Promise((resolve) => (this.resolveClosed = resolve));
|
|
33
|
+
constructor(options) {
|
|
34
|
+
this.options = options;
|
|
35
|
+
// 对端先退出时写入会 EPIPE / write after end:交给 closed 处理,不变成未捕获异常
|
|
36
|
+
options.output.on("error", () => undefined);
|
|
37
|
+
this.reader = createLineReader(options.input, (line) => this.onLine(line), () => this.shutdown());
|
|
38
|
+
}
|
|
39
|
+
get isOpen() {
|
|
40
|
+
return !this.isClosed;
|
|
41
|
+
}
|
|
42
|
+
/** 发请求;`signal` abort 时本端不再等(不通知对端,协议级取消由调用方另发)。 */
|
|
43
|
+
request(method, params, signal) {
|
|
44
|
+
if (this.isClosed)
|
|
45
|
+
return Promise.reject(closedError(method));
|
|
46
|
+
const id = this.nextId++;
|
|
47
|
+
return new Promise((resolve, reject) => {
|
|
48
|
+
const onAbort = () => {
|
|
49
|
+
this.pending.delete(id);
|
|
50
|
+
reject(new RpcError(RPC_ERRORS.internalError, `${method}: aborted`));
|
|
51
|
+
};
|
|
52
|
+
if (signal?.aborted === true)
|
|
53
|
+
return onAbort();
|
|
54
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
55
|
+
this.pending.set(id, {
|
|
56
|
+
method,
|
|
57
|
+
resolve: (value) => {
|
|
58
|
+
signal?.removeEventListener("abort", onAbort);
|
|
59
|
+
resolve(value);
|
|
60
|
+
},
|
|
61
|
+
reject: (error) => {
|
|
62
|
+
signal?.removeEventListener("abort", onAbort);
|
|
63
|
+
reject(error);
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
void this.send({ id, method, ...(params !== undefined ? { params } : {}) });
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
/** 输入流结束后仍可写(对端可能只关了自己的写端,还在读);写失败静默。 */
|
|
70
|
+
notify(method, params) {
|
|
71
|
+
return this.send({ method, ...(params !== undefined ? { params } : {}) });
|
|
72
|
+
}
|
|
73
|
+
/** 停止读取并让挂起请求失败;不关闭底层流(由调用方决定)。 */
|
|
74
|
+
close() {
|
|
75
|
+
this.reader.close();
|
|
76
|
+
this.shutdown();
|
|
77
|
+
}
|
|
78
|
+
/** 等所有已排队的写入完成。 */
|
|
79
|
+
flush() {
|
|
80
|
+
return this.writing;
|
|
81
|
+
}
|
|
82
|
+
shutdown() {
|
|
83
|
+
if (this.isClosed)
|
|
84
|
+
return;
|
|
85
|
+
this.isClosed = true;
|
|
86
|
+
this.lifetime.abort();
|
|
87
|
+
for (const [id, pending] of [...this.pending]) {
|
|
88
|
+
this.pending.delete(id);
|
|
89
|
+
pending.reject(closedError(pending.method));
|
|
90
|
+
}
|
|
91
|
+
this.options.onClose?.();
|
|
92
|
+
this.resolveClosed();
|
|
93
|
+
}
|
|
94
|
+
send(message) {
|
|
95
|
+
const body = this.options.jsonrpcField === false ? message : { jsonrpc: "2.0", ...message };
|
|
96
|
+
const line = `${JSON.stringify(body)}\n`;
|
|
97
|
+
const output = this.options.output;
|
|
98
|
+
this.writing = this.writing
|
|
99
|
+
.then(() => output.writableEnded === true || output.destroyed === true
|
|
100
|
+
? undefined
|
|
101
|
+
: writeChunked(output, line))
|
|
102
|
+
.catch(() => undefined);
|
|
103
|
+
return this.writing;
|
|
104
|
+
}
|
|
105
|
+
onLine(line) {
|
|
106
|
+
let message;
|
|
107
|
+
try {
|
|
108
|
+
message = JSON.parse(line);
|
|
109
|
+
}
|
|
110
|
+
catch {
|
|
111
|
+
this.options.onProtocolError?.(line, "invalid JSON");
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
if (typeof message !== "object" || message === null) {
|
|
115
|
+
this.options.onProtocolError?.(line, "not an object");
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
if (typeof message.method === "string") {
|
|
119
|
+
if (message.id !== undefined && message.id !== null) {
|
|
120
|
+
void this.handleRequest(message.id, message.method, message.params);
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
try {
|
|
124
|
+
this.options.onNotification?.(message.method, message.params);
|
|
125
|
+
}
|
|
126
|
+
catch (error) {
|
|
127
|
+
this.options.onProtocolError?.(line, `notification handler: ${String(error)}`);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
if (message.id === undefined || message.id === null) {
|
|
133
|
+
this.options.onProtocolError?.(line, "response without id");
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
const pending = this.pending.get(message.id);
|
|
137
|
+
if (pending === undefined)
|
|
138
|
+
return;
|
|
139
|
+
this.pending.delete(message.id);
|
|
140
|
+
if (message.error !== undefined) {
|
|
141
|
+
const err = message.error;
|
|
142
|
+
pending.reject(new RpcError(typeof err.code === "number" ? err.code : RPC_ERRORS.internalError, typeof err.message === "string" ? err.message : "error", err.data));
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
pending.resolve(message.result ?? null);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
async handleRequest(id, method, params) {
|
|
149
|
+
const handler = this.options.onRequest;
|
|
150
|
+
if (handler === undefined) {
|
|
151
|
+
await this.send({
|
|
152
|
+
id,
|
|
153
|
+
error: { code: RPC_ERRORS.methodNotFound, message: `method not found: ${method}` },
|
|
154
|
+
});
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
try {
|
|
158
|
+
const result = await handler(method, params, { id, signal: this.lifetime.signal });
|
|
159
|
+
await this.send({ id, result: result ?? null });
|
|
160
|
+
}
|
|
161
|
+
catch (error) {
|
|
162
|
+
const rpc = error instanceof RpcError
|
|
163
|
+
? error
|
|
164
|
+
: new RpcError(RPC_ERRORS.internalError, error instanceof Error ? error.message : String(error));
|
|
165
|
+
await this.send({
|
|
166
|
+
id,
|
|
167
|
+
error: {
|
|
168
|
+
code: rpc.code,
|
|
169
|
+
message: rpc.message,
|
|
170
|
+
...(rpc.data !== undefined ? { data: rpc.data } : {}),
|
|
171
|
+
},
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
function closedError(method) {
|
|
177
|
+
return new RpcError(RPC_ERRORS.internalError, `${method}: connection closed`, {
|
|
178
|
+
reason: "connection_closed",
|
|
179
|
+
});
|
|
180
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Claude Code stream-json → DriverEvent 的映射表(docs/wave5-plan.md §5.1 normalize,R2 §3.2)。[W5-E]
|
|
3
|
+
*
|
|
4
|
+
* 线上形状按 Claude Code 2.1.x 的 `--output-format stream-json`(Agent SDK 所用的同一协议;
|
|
5
|
+
* 官方称其不是公开的 CLI 接口,R3),只读用到的字段,其余忽略。
|
|
6
|
+
*/
|
|
7
|
+
import type { PermissionMode } from "../../permissions/types.js";
|
|
8
|
+
import type { AcpToolKind } from "../types.js";
|
|
9
|
+
export declare function claudeToolKind(name: string): AcpToolKind;
|
|
10
|
+
export declare function claudeToolTitle(name: string, input: unknown): string;
|
|
11
|
+
export declare function claudeToolLocations(input: unknown): string[] | undefined;
|
|
12
|
+
/** TodoWrite 的 todos → plan 条目。 */
|
|
13
|
+
export declare function claudeTodos(input: unknown): {
|
|
14
|
+
content: string;
|
|
15
|
+
status: string;
|
|
16
|
+
}[] | undefined;
|
|
17
|
+
/**
|
|
18
|
+
* ama 模式 → Claude `--permission-mode`。full-auto 不映射成 bypassPermissions:协调者永远不替
|
|
19
|
+
* 外部 Agent 打开「跳过全部检查」,最宽给到 auto(Claude 自己的分类器 + 需要时问人)。
|
|
20
|
+
* `manual` 是 2.1.x 新名字,旧版本叫 `default`(探测 `--help` 决定)。
|
|
21
|
+
*/
|
|
22
|
+
export declare function claudePermissionMode(mode: PermissionMode, manualName: "manual" | "default"): string;
|
|
23
|
+
/** 只能由人回答的提问类工具(ama 不代答)。 */
|
|
24
|
+
export declare const CLAUDE_QUESTION_TOOLS: ReadonlySet<string>;
|
|
25
|
+
export interface ClaudeResult {
|
|
26
|
+
subtype?: string;
|
|
27
|
+
is_error?: boolean;
|
|
28
|
+
result?: string;
|
|
29
|
+
session_id?: string;
|
|
30
|
+
total_cost_usd?: number;
|
|
31
|
+
num_turns?: number;
|
|
32
|
+
usage?: {
|
|
33
|
+
input_tokens?: number;
|
|
34
|
+
output_tokens?: number;
|
|
35
|
+
cache_read_input_tokens?: number;
|
|
36
|
+
cache_creation_input_tokens?: number;
|
|
37
|
+
};
|
|
38
|
+
permission_denials?: {
|
|
39
|
+
tool_name?: string;
|
|
40
|
+
}[];
|
|
41
|
+
errors?: string[];
|
|
42
|
+
}
|
|
43
|
+
/** result.subtype → 回合结束原因;`undefined` 表示执行出错(调用方按错误处理)。 */
|
|
44
|
+
export declare function claudeStopReason(result: ClaudeResult, interrupted: boolean): "end_turn" | "max_turn_requests" | "cancelled" | undefined;
|
|
45
|
+
/** 只保留会话范围的权限建议(`localSettings` 等会改用户 / 项目配置文件,不能替人写)。 */
|
|
46
|
+
export declare function sessionScopedSuggestions(suggestions: unknown): unknown[];
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Claude Code stream-json → DriverEvent 的映射表(docs/wave5-plan.md §5.1 normalize,R2 §3.2)。[W5-E]
|
|
3
|
+
*
|
|
4
|
+
* 线上形状按 Claude Code 2.1.x 的 `--output-format stream-json`(Agent SDK 所用的同一协议;
|
|
5
|
+
* 官方称其不是公开的 CLI 接口,R3),只读用到的字段,其余忽略。
|
|
6
|
+
*/
|
|
7
|
+
import { oneLine } from "../turn.js";
|
|
8
|
+
const KINDS = {
|
|
9
|
+
Read: "read",
|
|
10
|
+
Write: "edit",
|
|
11
|
+
Edit: "edit",
|
|
12
|
+
MultiEdit: "edit",
|
|
13
|
+
NotebookEdit: "edit",
|
|
14
|
+
Bash: "execute",
|
|
15
|
+
BashOutput: "execute",
|
|
16
|
+
KillShell: "execute",
|
|
17
|
+
Grep: "search",
|
|
18
|
+
Glob: "search",
|
|
19
|
+
LS: "search",
|
|
20
|
+
WebFetch: "fetch",
|
|
21
|
+
WebSearch: "fetch",
|
|
22
|
+
TodoWrite: "think",
|
|
23
|
+
ExitPlanMode: "switch_mode",
|
|
24
|
+
};
|
|
25
|
+
export function claudeToolKind(name) {
|
|
26
|
+
return KINDS[name] ?? "other";
|
|
27
|
+
}
|
|
28
|
+
function field(input, ...keys) {
|
|
29
|
+
if (input === null || typeof input !== "object")
|
|
30
|
+
return undefined;
|
|
31
|
+
for (const key of keys) {
|
|
32
|
+
const v = input[key];
|
|
33
|
+
if (typeof v === "string" && v !== "")
|
|
34
|
+
return v;
|
|
35
|
+
}
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
export function claudeToolTitle(name, input) {
|
|
39
|
+
const detail = field(input, "command") ??
|
|
40
|
+
field(input, "file_path", "notebook_path", "path") ??
|
|
41
|
+
field(input, "pattern", "url", "query", "description");
|
|
42
|
+
return detail === undefined ? name : `${name}: ${oneLine(detail, 100)}`;
|
|
43
|
+
}
|
|
44
|
+
export function claudeToolLocations(input) {
|
|
45
|
+
const path = field(input, "file_path", "notebook_path", "path");
|
|
46
|
+
return path === undefined ? undefined : [path];
|
|
47
|
+
}
|
|
48
|
+
/** TodoWrite 的 todos → plan 条目。 */
|
|
49
|
+
export function claudeTodos(input) {
|
|
50
|
+
const todos = input?.todos;
|
|
51
|
+
if (!Array.isArray(todos))
|
|
52
|
+
return undefined;
|
|
53
|
+
return todos.flatMap((t) => t !== null && typeof t === "object" && typeof t.content === "string"
|
|
54
|
+
? [
|
|
55
|
+
{
|
|
56
|
+
content: t.content,
|
|
57
|
+
status: String(t.status ?? "pending"),
|
|
58
|
+
},
|
|
59
|
+
]
|
|
60
|
+
: []);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* ama 模式 → Claude `--permission-mode`。full-auto 不映射成 bypassPermissions:协调者永远不替
|
|
64
|
+
* 外部 Agent 打开「跳过全部检查」,最宽给到 auto(Claude 自己的分类器 + 需要时问人)。
|
|
65
|
+
* `manual` 是 2.1.x 新名字,旧版本叫 `default`(探测 `--help` 决定)。
|
|
66
|
+
*/
|
|
67
|
+
export function claudePermissionMode(mode, manualName) {
|
|
68
|
+
switch (mode) {
|
|
69
|
+
// allowlist 也按 plan:Claude 的 dontAsk 会放行它自己配置里的 allow 规则(可能含写操作)
|
|
70
|
+
case "plan":
|
|
71
|
+
case "allowlist":
|
|
72
|
+
return "plan";
|
|
73
|
+
case "default":
|
|
74
|
+
return manualName;
|
|
75
|
+
case "auto-edit":
|
|
76
|
+
return "acceptEdits";
|
|
77
|
+
case "auto":
|
|
78
|
+
case "full-auto":
|
|
79
|
+
return "auto";
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/** 只能由人回答的提问类工具(ama 不代答)。 */
|
|
83
|
+
export const CLAUDE_QUESTION_TOOLS = new Set(["AskUserQuestion"]);
|
|
84
|
+
/** result.subtype → 回合结束原因;`undefined` 表示执行出错(调用方按错误处理)。 */
|
|
85
|
+
export function claudeStopReason(result, interrupted) {
|
|
86
|
+
if (interrupted)
|
|
87
|
+
return "cancelled";
|
|
88
|
+
switch (result.subtype) {
|
|
89
|
+
case "success":
|
|
90
|
+
return result.is_error === true ? undefined : "end_turn";
|
|
91
|
+
case "error_max_turns":
|
|
92
|
+
return "max_turn_requests";
|
|
93
|
+
case "error_max_budget_usd":
|
|
94
|
+
return "cancelled";
|
|
95
|
+
default:
|
|
96
|
+
return undefined;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
/** 只保留会话范围的权限建议(`localSettings` 等会改用户 / 项目配置文件,不能替人写)。 */
|
|
100
|
+
export function sessionScopedSuggestions(suggestions) {
|
|
101
|
+
if (!Array.isArray(suggestions))
|
|
102
|
+
return [];
|
|
103
|
+
return suggestions.filter((s) => s !== null &&
|
|
104
|
+
typeof s === "object" &&
|
|
105
|
+
s.destination === "session");
|
|
106
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Claude Code 原生驱动:stream-json 长驻进程(docs/wave5-plan.md §5.1,R2 §1.2)。[W5-E]
|
|
3
|
+
*
|
|
4
|
+
* `claude -p --input-format stream-json --output-format stream-json --verbose
|
|
5
|
+
* --include-partial-messages --permission-prompt-tool stdio --permission-mode <m> --session-id <uuid>`
|
|
6
|
+
* (续聊 `--resume <id>`;预算 `--max-budget-usd`;无人值守改 `--permission-prompts none`)。
|
|
7
|
+
*
|
|
8
|
+
* - 多轮复用同一进程:每回合写一行 `{"type":"user",…}`,以 `result` 结束;运行中再写即 steer。
|
|
9
|
+
* - 权限:`control_request{can_use_tool}` → hooks.onPermission(只交给人)→ `control_response`
|
|
10
|
+
* allow(必须带 `updatedInput`,原样回传)/ deny;`control_cancel_request` 让挂起的请求回
|
|
11
|
+
* cancelled。「本会话允许」只在 Claude 给了 `destination: "session"` 的建议时提供,并只回传这些
|
|
12
|
+
* (会写配置文件的建议不替人接受)。`AskUserQuestion` 不代答:拒绝并提示写进最终回复。
|
|
13
|
+
* - 中断:`control_request{interrupt}`;15 s 无 `result` → 关 stdin → 杀进程树(#98713 / #94741)。
|
|
14
|
+
* - `--bare` 永不使用(它只认 API key,会把订阅切到 API 计费)。
|
|
15
|
+
* - 成本:`result.total_cost_usd` 是 Claude 自己的估算(同一进程内累计,按差值记本回合)。
|
|
16
|
+
*/
|
|
17
|
+
import { type DriverDeps } from "../base.js";
|
|
18
|
+
import type { CatalogCandidate } from "../catalog.js";
|
|
19
|
+
import type { AgentDriver, DriverOpenOptions, DriverProbe, DriverSession } from "../types.js";
|
|
20
|
+
export declare function claudeArgs(options: Pick<DriverOpenOptions, "mode" | "model" | "resume" | "budgetUsd" | "unattended">, sessionId: string, manualName?: "manual" | "default"): string[];
|
|
21
|
+
export declare class ClaudeStreamDriver implements AgentDriver {
|
|
22
|
+
readonly agentId: string;
|
|
23
|
+
private readonly candidate;
|
|
24
|
+
private readonly deps;
|
|
25
|
+
readonly kind: "claude-stream";
|
|
26
|
+
constructor(agentId: string, candidate: CatalogCandidate, deps?: DriverDeps);
|
|
27
|
+
probe(): Promise<DriverProbe>;
|
|
28
|
+
open(options: DriverOpenOptions): Promise<DriverSession>;
|
|
29
|
+
}
|