@armadra/agent 0.4.0 → 0.5.1
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 +184 -1
- package/README.md +202 -83
- 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 +37605 -21619
- 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/choice-prompt.d.ts +58 -0
- package/dist/cli/choice-prompt.js +140 -0
- 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-cache-probe.d.ts +1 -1
- package/dist/cli/subcommands/models-cache-probe.js +3 -12
- 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.d.ts +1 -1
- package/dist/cli/subcommands/providers.js +8 -15
- 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 +13 -1
- package/dist/modes/commands-core.js +64 -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 +12 -1
- package/dist/modes/interactive/commands.js +31 -1
- package/dist/modes/interactive/confirm-dialog.d.ts +49 -0
- package/dist/modes/interactive/confirm-dialog.js +121 -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 +140 -136
- package/dist/modes/interactive/key-dispatch.d.ts +22 -2
- package/dist/modes/interactive/key-dispatch.js +66 -7
- package/dist/modes/interactive/line/line-mode.d.ts +4 -1
- package/dist/modes/interactive/line/line-mode.js +31 -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/startup-ui.js +5 -1
- 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/bypass.d.ts +32 -0
- package/dist/permissions/bypass.js +36 -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 +6 -1
- package/dist/tui/keybindings.js +6 -1
- 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 +78 -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 +179 -21
- package/package.json +13 -2
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ACP 客户端(docs/wave5-plan.md §5.1,D14)。[W5-E]
|
|
3
|
+
*
|
|
4
|
+
* JSON-RPC over NDJSON({@link JsonRpcPeer}),手写零依赖;`@armadra/agent/acp` 导出供 Armadra 复用。
|
|
5
|
+
*
|
|
6
|
+
* - 不声明 `fs` / `terminal` 能力:Agent 发来的 `fs/*`、`terminal/*` 请求一律 method not found。
|
|
7
|
+
* - `session/request_permission` 交给 `onPermission`(驱动再交给 ama 的审批通道,只交给人);
|
|
8
|
+
* 没有处理器时按无人值守回首个 `reject_once`(没有则 cancelled)。
|
|
9
|
+
* - `cancel(sessionId)` 发 `session/cancel` 通知,并让该会话所有挂起的权限请求回 `cancelled`
|
|
10
|
+
* (规范要求:客户端取消回合后必须以 cancelled 回答挂起的请求)。
|
|
11
|
+
*/
|
|
12
|
+
import { JsonRpcPeer, RpcError } from "../jsonrpc.js";
|
|
13
|
+
import { ACP_METHODS, ACP_PROTOCOL_VERSION, RPC_ERRORS, } from "./types.js";
|
|
14
|
+
/** 无人值守的回答:首个 reject_once,没有就 cancelled。 */
|
|
15
|
+
export function unattendedOutcome(params) {
|
|
16
|
+
const reject = params.options.find((o) => o.kind === "reject_once");
|
|
17
|
+
return {
|
|
18
|
+
outcome: reject !== undefined
|
|
19
|
+
? { outcome: "selected", optionId: reject.optionId }
|
|
20
|
+
: { outcome: "cancelled" },
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export class AcpClient {
|
|
24
|
+
options;
|
|
25
|
+
peer;
|
|
26
|
+
/** sessionId → 挂起权限请求的取消器。 */
|
|
27
|
+
pendingPermissions = new Map();
|
|
28
|
+
initResult;
|
|
29
|
+
constructor(options) {
|
|
30
|
+
this.options = options;
|
|
31
|
+
this.peer = new JsonRpcPeer({
|
|
32
|
+
input: options.input,
|
|
33
|
+
output: options.output,
|
|
34
|
+
onRequest: (method, params, ctx) => this.onRequest(method, params, ctx.signal),
|
|
35
|
+
onNotification: (method, params) => {
|
|
36
|
+
if (method === ACP_METHODS.sessionUpdate)
|
|
37
|
+
options.onUpdate?.(params);
|
|
38
|
+
},
|
|
39
|
+
onClose: () => {
|
|
40
|
+
for (const set of this.pendingPermissions.values())
|
|
41
|
+
for (const c of set)
|
|
42
|
+
c.abort();
|
|
43
|
+
options.onClose?.();
|
|
44
|
+
},
|
|
45
|
+
...(options.onProtocolError !== undefined
|
|
46
|
+
? { onProtocolError: options.onProtocolError }
|
|
47
|
+
: {}),
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
get closed() {
|
|
51
|
+
return this.peer.closed;
|
|
52
|
+
}
|
|
53
|
+
get isOpen() {
|
|
54
|
+
return this.peer.isOpen;
|
|
55
|
+
}
|
|
56
|
+
get agentCapabilities() {
|
|
57
|
+
return this.initResult?.agentCapabilities ?? {};
|
|
58
|
+
}
|
|
59
|
+
get agentInfo() {
|
|
60
|
+
return this.initResult?.agentInfo;
|
|
61
|
+
}
|
|
62
|
+
async initialize(signal) {
|
|
63
|
+
const result = await this.peer.request(ACP_METHODS.initialize, {
|
|
64
|
+
protocolVersion: ACP_PROTOCOL_VERSION,
|
|
65
|
+
clientCapabilities: { fs: { readTextFile: false, writeTextFile: false }, terminal: false },
|
|
66
|
+
...(this.options.clientInfo !== undefined ? { clientInfo: this.options.clientInfo } : {}),
|
|
67
|
+
}, signal);
|
|
68
|
+
if (result.protocolVersion !== ACP_PROTOCOL_VERSION)
|
|
69
|
+
throw new RpcError(RPC_ERRORS.invalidRequest, `ACP 协议版本不兼容:Agent ${String(result.protocolVersion)},客户端 ${ACP_PROTOCOL_VERSION}`);
|
|
70
|
+
this.initResult = result;
|
|
71
|
+
return result;
|
|
72
|
+
}
|
|
73
|
+
supportsResume() {
|
|
74
|
+
return this.agentCapabilities.sessionCapabilities?.resume != null;
|
|
75
|
+
}
|
|
76
|
+
supportsLoad() {
|
|
77
|
+
return this.agentCapabilities.loadSession === true;
|
|
78
|
+
}
|
|
79
|
+
supportsList() {
|
|
80
|
+
return this.agentCapabilities.sessionCapabilities?.list != null;
|
|
81
|
+
}
|
|
82
|
+
supportsClose() {
|
|
83
|
+
return this.agentCapabilities.sessionCapabilities?.close != null;
|
|
84
|
+
}
|
|
85
|
+
supportsImages() {
|
|
86
|
+
return this.agentCapabilities.promptCapabilities?.image === true;
|
|
87
|
+
}
|
|
88
|
+
newSession(cwd, signal) {
|
|
89
|
+
return this.peer.request(ACP_METHODS.sessionNew, { cwd, mcpServers: [] }, signal);
|
|
90
|
+
}
|
|
91
|
+
/** 不回放历史(优先,R13:v2 计划取消 load)。 */
|
|
92
|
+
resumeSession(sessionId, cwd, signal) {
|
|
93
|
+
return this.peer.request(ACP_METHODS.sessionResume, { sessionId, cwd, mcpServers: [] }, signal);
|
|
94
|
+
}
|
|
95
|
+
/** 回放历史(以 session/update 通知)。 */
|
|
96
|
+
loadSession(sessionId, cwd, signal) {
|
|
97
|
+
return this.peer.request(ACP_METHODS.sessionLoad, { sessionId, cwd, mcpServers: [] }, signal);
|
|
98
|
+
}
|
|
99
|
+
listSessions(cwd, cursor) {
|
|
100
|
+
return this.peer.request(ACP_METHODS.sessionList, {
|
|
101
|
+
...(cwd !== undefined ? { cwd } : {}),
|
|
102
|
+
...(cursor !== undefined ? { cursor } : {}),
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
closeSession(sessionId) {
|
|
106
|
+
return this.peer.request(ACP_METHODS.sessionClose, { sessionId });
|
|
107
|
+
}
|
|
108
|
+
prompt(sessionId, prompt, signal) {
|
|
109
|
+
return this.peer.request(ACP_METHODS.sessionPrompt, { sessionId, prompt }, signal);
|
|
110
|
+
}
|
|
111
|
+
setMode(sessionId, modeId) {
|
|
112
|
+
return this.peer.request(ACP_METHODS.sessionSetMode, { sessionId, modeId });
|
|
113
|
+
}
|
|
114
|
+
/** 协议级取消:发通知,并让挂起的权限请求回 cancelled。 */
|
|
115
|
+
async cancel(sessionId) {
|
|
116
|
+
for (const controller of this.pendingPermissions.get(sessionId) ?? [])
|
|
117
|
+
controller.abort();
|
|
118
|
+
await this.peer.notify(ACP_METHODS.sessionCancel, { sessionId });
|
|
119
|
+
}
|
|
120
|
+
close() {
|
|
121
|
+
this.peer.close();
|
|
122
|
+
}
|
|
123
|
+
async onRequest(method, params, connection) {
|
|
124
|
+
if (method !== ACP_METHODS.requestPermission)
|
|
125
|
+
throw new RpcError(RPC_ERRORS.methodNotFound, `client does not support ${method}`);
|
|
126
|
+
const request = params;
|
|
127
|
+
if (typeof request?.sessionId !== "string" || !Array.isArray(request.options))
|
|
128
|
+
throw new RpcError(RPC_ERRORS.invalidParams, "invalid session/request_permission params");
|
|
129
|
+
const handler = this.options.onPermission;
|
|
130
|
+
if (handler === undefined)
|
|
131
|
+
return unattendedOutcome(request);
|
|
132
|
+
const controller = new AbortController();
|
|
133
|
+
const set = this.pendingPermissions.get(request.sessionId) ?? new Set();
|
|
134
|
+
set.add(controller);
|
|
135
|
+
this.pendingPermissions.set(request.sessionId, set);
|
|
136
|
+
const signal = AbortSignal.any([controller.signal, connection]);
|
|
137
|
+
try {
|
|
138
|
+
const answer = await Promise.race([
|
|
139
|
+
handler(request, signal),
|
|
140
|
+
new Promise((resolve) => {
|
|
141
|
+
const cancelled = () => resolve({ outcome: { outcome: "cancelled" } });
|
|
142
|
+
if (signal.aborted)
|
|
143
|
+
cancelled();
|
|
144
|
+
else
|
|
145
|
+
signal.addEventListener("abort", cancelled, { once: true });
|
|
146
|
+
}),
|
|
147
|
+
]);
|
|
148
|
+
if (signal.aborted)
|
|
149
|
+
return { outcome: { outcome: "cancelled" } };
|
|
150
|
+
// 只认 Agent 自己给的选项
|
|
151
|
+
if (answer.outcome.outcome === "selected" &&
|
|
152
|
+
!request.options.some((o) => answer.outcome.outcome === "selected" && o.optionId === answer.outcome.optionId))
|
|
153
|
+
return { outcome: { outcome: "cancelled" } };
|
|
154
|
+
return answer;
|
|
155
|
+
}
|
|
156
|
+
finally {
|
|
157
|
+
set.delete(controller);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AcpDriver:经 ACP 驱动外部 Agent(docs/wave5-plan.md §5.1–§5.2,D14)。[W5-E]
|
|
3
|
+
*
|
|
4
|
+
* open:起进程 → `initialize` → 续聊优先 `session/resume`(不回放),其次 `session/load`
|
|
5
|
+
* (回放的历史通知在 open 期间丢弃),都不支持则新开并发 notice「已新开」→ 按 ama 模式
|
|
6
|
+
* `session/set_mode`(只读模式没有映射时拒绝启动,避免以 Agent 缺省模式跑写操作)。
|
|
7
|
+
* prompt:`session/update` → DriverEvent;`session/request_permission` → hooks.onPermission
|
|
8
|
+
* (只交给人);回合以 `session/prompt` 的 stopReason 结束。
|
|
9
|
+
* cancel:`session/cancel`,挂起的权限请求回 cancelled,15 s 内无回合结束 → 关 stdin → 杀进程树。
|
|
10
|
+
*/
|
|
11
|
+
import type { ContentBlock } from "../../ai/types.js";
|
|
12
|
+
import type { PermissionMode } from "../../permissions/types.js";
|
|
13
|
+
import { type DriverDeps } from "../base.js";
|
|
14
|
+
import type { CatalogCandidate } from "../catalog.js";
|
|
15
|
+
import { TurnCollector } from "../turn.js";
|
|
16
|
+
import type { AgentDriver, DriverOpenOptions, DriverProbe, DriverSession } from "../types.js";
|
|
17
|
+
import type { AcpContentBlock, AcpSessionModeState, AcpSessionUpdate } from "./types.js";
|
|
18
|
+
export declare function toAcpContent(blocks: readonly ContentBlock[], images: boolean): AcpContentBlock[];
|
|
19
|
+
/** session/update → DriverEvent(用户消息回放、命令表等忽略)。 */
|
|
20
|
+
export declare function pushAcpUpdate(update: AcpSessionUpdate, turn: TurnCollector): void;
|
|
21
|
+
/** ama 模式 → 该 Agent 的模式 id(显式映射 > 同名)。 */
|
|
22
|
+
export declare function pickModeId(mode: PermissionMode, candidate: CatalogCandidate, state: AcpSessionModeState | null | undefined): string | undefined;
|
|
23
|
+
export declare class AcpDriver implements AgentDriver {
|
|
24
|
+
readonly agentId: string;
|
|
25
|
+
private readonly candidate;
|
|
26
|
+
private readonly deps;
|
|
27
|
+
readonly kind: "acp" | "acp-adapter";
|
|
28
|
+
constructor(agentId: string, candidate: CatalogCandidate, deps?: DriverDeps);
|
|
29
|
+
probe(): Promise<DriverProbe>;
|
|
30
|
+
open(options: DriverOpenOptions): Promise<DriverSession>;
|
|
31
|
+
}
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AcpDriver:经 ACP 驱动外部 Agent(docs/wave5-plan.md §5.1–§5.2,D14)。[W5-E]
|
|
3
|
+
*
|
|
4
|
+
* open:起进程 → `initialize` → 续聊优先 `session/resume`(不回放),其次 `session/load`
|
|
5
|
+
* (回放的历史通知在 open 期间丢弃),都不支持则新开并发 notice「已新开」→ 按 ama 模式
|
|
6
|
+
* `session/set_mode`(只读模式没有映射时拒绝启动,避免以 Agent 缺省模式跑写操作)。
|
|
7
|
+
* prompt:`session/update` → DriverEvent;`session/request_permission` → hooks.onPermission
|
|
8
|
+
* (只交给人);回合以 `session/prompt` 的 stopReason 结束。
|
|
9
|
+
* cancel:`session/cancel`,挂起的权限请求回 cancelled,15 s 内无回合结束 → 关 stdin → 杀进程树。
|
|
10
|
+
*/
|
|
11
|
+
import { AmaError } from "../../errors.js";
|
|
12
|
+
import { armCancelWatchdog, isReadOnlyMode, probeCandidate, spawnOf, } from "../base.js";
|
|
13
|
+
import { stderrHint } from "../process.js";
|
|
14
|
+
import { TurnCollector, oneLine } from "../turn.js";
|
|
15
|
+
import { AcpClient } from "./client.js";
|
|
16
|
+
import { AMA_VERSION } from "../../version.js";
|
|
17
|
+
export function toAcpContent(blocks, images) {
|
|
18
|
+
const out = [];
|
|
19
|
+
for (const block of blocks) {
|
|
20
|
+
if (block.type === "text")
|
|
21
|
+
out.push({ type: "text", text: block.text });
|
|
22
|
+
else if (images)
|
|
23
|
+
out.push({ type: "image", data: block.data, mimeType: block.mimeType });
|
|
24
|
+
}
|
|
25
|
+
return out;
|
|
26
|
+
}
|
|
27
|
+
function locationsOf(locations) {
|
|
28
|
+
return locations === undefined ? undefined : locations.map((l) => l.path);
|
|
29
|
+
}
|
|
30
|
+
/** session/update → DriverEvent(用户消息回放、命令表等忽略)。 */
|
|
31
|
+
export function pushAcpUpdate(update, turn) {
|
|
32
|
+
switch (update.sessionUpdate) {
|
|
33
|
+
case "agent_message_chunk":
|
|
34
|
+
if (update.content.type === "text")
|
|
35
|
+
turn.push({ type: "message_delta", text: update.content.text });
|
|
36
|
+
return;
|
|
37
|
+
case "agent_thought_chunk":
|
|
38
|
+
if (update.content.type === "text")
|
|
39
|
+
turn.push({ type: "thought_delta", text: update.content.text });
|
|
40
|
+
return;
|
|
41
|
+
case "tool_call":
|
|
42
|
+
case "tool_call_update": {
|
|
43
|
+
const known = turn.tool(update.toolCallId);
|
|
44
|
+
const locations = locationsOf(update.locations);
|
|
45
|
+
turn.push({
|
|
46
|
+
type: "tool_call",
|
|
47
|
+
id: update.toolCallId,
|
|
48
|
+
title: oneLine(update.title ?? known?.title ?? ""),
|
|
49
|
+
kind: update.kind ?? known?.kind ?? "other",
|
|
50
|
+
status: update.status ?? known?.status ?? "pending",
|
|
51
|
+
...(locations !== undefined ? { locations } : {}),
|
|
52
|
+
});
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
case "plan":
|
|
56
|
+
turn.push({
|
|
57
|
+
type: "plan",
|
|
58
|
+
entries: update.entries.map((e) => ({ content: e.content, status: e.status })),
|
|
59
|
+
});
|
|
60
|
+
return;
|
|
61
|
+
case "usage_update":
|
|
62
|
+
turn.push({
|
|
63
|
+
type: "usage",
|
|
64
|
+
contextTokens: update.used,
|
|
65
|
+
contextWindow: update.size,
|
|
66
|
+
...(update.cost?.currency === "USD" ? { costUsd: update.cost.amount } : {}),
|
|
67
|
+
});
|
|
68
|
+
return;
|
|
69
|
+
default:
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/** ama 模式 → 该 Agent 的模式 id(显式映射 > 同名)。 */
|
|
74
|
+
export function pickModeId(mode, candidate, state) {
|
|
75
|
+
const wanted = [candidate.modes?.[mode] ?? mode];
|
|
76
|
+
// allowlist 在外部 Agent 那边没有等价物:退到只读的 plan
|
|
77
|
+
if (mode === "allowlist")
|
|
78
|
+
wanted.push(candidate.modes?.plan ?? "plan");
|
|
79
|
+
return wanted.find((id) => state?.availableModes.some((m) => m.id === id) === true);
|
|
80
|
+
}
|
|
81
|
+
export class AcpDriver {
|
|
82
|
+
agentId;
|
|
83
|
+
candidate;
|
|
84
|
+
deps;
|
|
85
|
+
kind;
|
|
86
|
+
constructor(agentId, candidate, deps = {}) {
|
|
87
|
+
this.agentId = agentId;
|
|
88
|
+
this.candidate = candidate;
|
|
89
|
+
this.deps = deps;
|
|
90
|
+
this.kind = candidate.kind === "acp-adapter" ? "acp-adapter" : "acp";
|
|
91
|
+
}
|
|
92
|
+
probe() {
|
|
93
|
+
return probeCandidate(this.candidate, this.deps);
|
|
94
|
+
}
|
|
95
|
+
async open(options) {
|
|
96
|
+
// 与原生驱动一致:用探测到的完整路径启动。Windows 上 npm 装的 ACP Agent 是 `.cmd` 垫片,
|
|
97
|
+
// 裸程序名 spawn 会 ENOENT(commandLine 只认带扩展名的路径改走 cmd.exe)。[W5-Z]
|
|
98
|
+
const probed = await probeCandidate(this.candidate, this.deps);
|
|
99
|
+
const transport = spawnOf(this.deps)({
|
|
100
|
+
program: probed.path ?? this.candidate.program,
|
|
101
|
+
args: this.candidate.args,
|
|
102
|
+
cwd: options.cwd,
|
|
103
|
+
env: options.env,
|
|
104
|
+
});
|
|
105
|
+
const session = new AcpDriverSession(this.agentId, transport, this.deps);
|
|
106
|
+
try {
|
|
107
|
+
await session.start(options, this.candidate);
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
await session.close();
|
|
111
|
+
if (error instanceof AmaError)
|
|
112
|
+
throw error;
|
|
113
|
+
const hint = stderrHint(transport);
|
|
114
|
+
throw new AmaError("agent_start_failed", `${this.agentId}:ACP 启动失败(${error.message})${hint !== "" ? `:${hint}` : ""}`, { cause: error });
|
|
115
|
+
}
|
|
116
|
+
return session;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
class AcpDriverSession {
|
|
120
|
+
agentId;
|
|
121
|
+
transport;
|
|
122
|
+
deps;
|
|
123
|
+
id = "";
|
|
124
|
+
client;
|
|
125
|
+
hooks;
|
|
126
|
+
turn;
|
|
127
|
+
replaying = false;
|
|
128
|
+
running;
|
|
129
|
+
closed = false;
|
|
130
|
+
notices = [];
|
|
131
|
+
constructor(agentId, transport, deps) {
|
|
132
|
+
this.agentId = agentId;
|
|
133
|
+
this.transport = transport;
|
|
134
|
+
this.deps = deps;
|
|
135
|
+
}
|
|
136
|
+
get sessionId() {
|
|
137
|
+
return this.id;
|
|
138
|
+
}
|
|
139
|
+
async start(options, candidate) {
|
|
140
|
+
this.client = new AcpClient({
|
|
141
|
+
input: this.transport.stdout,
|
|
142
|
+
output: this.transport.stdin,
|
|
143
|
+
clientInfo: { name: "ama", version: AMA_VERSION },
|
|
144
|
+
onUpdate: (n) => this.onUpdate(n),
|
|
145
|
+
onPermission: (p, signal) => this.onPermission(p, signal),
|
|
146
|
+
onProtocolError: (_line, reason) => this.deps.log?.("debug", `${this.agentId}: ${reason}`),
|
|
147
|
+
});
|
|
148
|
+
const signal = options.signal;
|
|
149
|
+
await this.client.initialize(signal);
|
|
150
|
+
let modes;
|
|
151
|
+
if (options.resume !== undefined) {
|
|
152
|
+
if (this.client.supportsResume()) {
|
|
153
|
+
modes = (await this.client.resumeSession(options.resume, options.cwd, signal)).modes;
|
|
154
|
+
this.id = options.resume;
|
|
155
|
+
}
|
|
156
|
+
else if (this.client.supportsLoad()) {
|
|
157
|
+
this.replaying = true;
|
|
158
|
+
try {
|
|
159
|
+
modes = (await this.client.loadSession(options.resume, options.cwd, signal)).modes;
|
|
160
|
+
}
|
|
161
|
+
finally {
|
|
162
|
+
this.replaying = false;
|
|
163
|
+
}
|
|
164
|
+
this.id = options.resume;
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
this.notices.push(`${this.agentId} 不支持续接会话,已新开`);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
if (this.id === "") {
|
|
171
|
+
const created = await this.client.newSession(options.cwd, signal);
|
|
172
|
+
this.id = created.sessionId;
|
|
173
|
+
modes = created.modes;
|
|
174
|
+
}
|
|
175
|
+
const modeId = pickModeId(options.mode, candidate, modes);
|
|
176
|
+
if (modeId !== undefined) {
|
|
177
|
+
if (modes?.currentModeId !== modeId)
|
|
178
|
+
await this.client.setMode(this.id, modeId);
|
|
179
|
+
}
|
|
180
|
+
else if (isReadOnlyMode(options.mode)) {
|
|
181
|
+
throw new AmaError("agent_mode_unsupported", `${this.agentId} 没有与 ama「${options.mode}」对应的只读模式,不能以它的缺省模式代替`);
|
|
182
|
+
}
|
|
183
|
+
else if (modes != null) {
|
|
184
|
+
this.notices.push(`${this.agentId} 没有「${options.mode}」模式,按它自己的缺省模式运行(需要授权的操作仍交给你)`);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
async prompt(content, hooks) {
|
|
188
|
+
if (this.closed)
|
|
189
|
+
throw new AmaError("agent_closed", `${this.agentId} 会话已关闭`);
|
|
190
|
+
if (this.running !== undefined)
|
|
191
|
+
throw new AmaError("busy", `${this.agentId} 正在运行`);
|
|
192
|
+
const turn = new TurnCollector((e) => hooks.onEvent(e));
|
|
193
|
+
for (const text of this.notices.splice(0))
|
|
194
|
+
turn.push({ type: "notice", level: "info", text });
|
|
195
|
+
this.hooks = hooks;
|
|
196
|
+
this.turn = turn;
|
|
197
|
+
const images = this.client.supportsImages();
|
|
198
|
+
if (!images && content.some((b) => b.type === "image"))
|
|
199
|
+
turn.push({ type: "notice", level: "warn", text: `${this.agentId} 不接受图片,已省略` });
|
|
200
|
+
const request = this.client.prompt(this.id, toAcpContent(content, images));
|
|
201
|
+
this.running = request;
|
|
202
|
+
try {
|
|
203
|
+
const result = await request.catch((error) => {
|
|
204
|
+
if (this.client.isOpen)
|
|
205
|
+
throw error;
|
|
206
|
+
const hint = stderrHint(this.transport);
|
|
207
|
+
throw new AmaError("agent_exited", `${this.agentId} 进程已退出${hint !== "" ? `:${hint}` : ""}`, {
|
|
208
|
+
cause: error,
|
|
209
|
+
});
|
|
210
|
+
});
|
|
211
|
+
const usage = result.usage;
|
|
212
|
+
if (usage != null) {
|
|
213
|
+
turn.mergeUsage({
|
|
214
|
+
...(usage.inputTokens !== undefined ? { input: usage.inputTokens } : {}),
|
|
215
|
+
...(usage.outputTokens !== undefined ? { output: usage.outputTokens } : {}),
|
|
216
|
+
...(usage.cachedReadTokens !== undefined ? { cacheRead: usage.cachedReadTokens } : {}),
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
return turn.result(result.stopReason);
|
|
220
|
+
}
|
|
221
|
+
finally {
|
|
222
|
+
this.running = undefined;
|
|
223
|
+
this.hooks = undefined;
|
|
224
|
+
this.turn = undefined;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
async cancel() {
|
|
228
|
+
const running = this.running;
|
|
229
|
+
if (running === undefined || this.closed)
|
|
230
|
+
return;
|
|
231
|
+
await this.client.cancel(this.id).catch(() => undefined);
|
|
232
|
+
armCancelWatchdog(this.transport, running.catch(() => undefined), this.deps);
|
|
233
|
+
}
|
|
234
|
+
async close() {
|
|
235
|
+
if (this.closed)
|
|
236
|
+
return;
|
|
237
|
+
this.closed = true;
|
|
238
|
+
if (this.client !== undefined) {
|
|
239
|
+
if (this.running !== undefined)
|
|
240
|
+
await this.client.cancel(this.id).catch(() => undefined);
|
|
241
|
+
if (this.id !== "" && this.client.isOpen && this.client.supportsClose()) {
|
|
242
|
+
const timer = new Promise((resolve) => setTimeout(resolve, 2_000).unref());
|
|
243
|
+
await Promise.race([this.client.closeSession(this.id).catch(() => undefined), timer]);
|
|
244
|
+
}
|
|
245
|
+
this.client.close();
|
|
246
|
+
}
|
|
247
|
+
await this.transport.terminate();
|
|
248
|
+
}
|
|
249
|
+
onUpdate(notification) {
|
|
250
|
+
if (this.replaying || notification.sessionId !== this.id || this.turn === undefined)
|
|
251
|
+
return;
|
|
252
|
+
pushAcpUpdate(notification.update, this.turn);
|
|
253
|
+
}
|
|
254
|
+
async onPermission(params, signal) {
|
|
255
|
+
const hooks = this.hooks;
|
|
256
|
+
if (hooks === undefined || params.sessionId !== this.id)
|
|
257
|
+
return { outcome: { outcome: "cancelled" } };
|
|
258
|
+
const call = params.toolCall;
|
|
259
|
+
const known = this.turn?.tool(call.toolCallId);
|
|
260
|
+
const locations = locationsOf(call.locations) ?? known?.locations;
|
|
261
|
+
const outcome = await hooks.onPermission({
|
|
262
|
+
toolCall: {
|
|
263
|
+
title: oneLine(call.title ?? known?.title ?? call.toolCallId),
|
|
264
|
+
kind: call.kind ?? known?.kind ?? "other",
|
|
265
|
+
...(locations !== undefined && locations.length > 0 ? { locations: [...locations] } : {}),
|
|
266
|
+
...(call.rawInput !== undefined
|
|
267
|
+
? { inputSummary: oneLine(JSON.stringify(call.rawInput), 300) }
|
|
268
|
+
: {}),
|
|
269
|
+
},
|
|
270
|
+
options: params.options.map((o) => ({ optionId: o.optionId, kind: o.kind })),
|
|
271
|
+
}, signal);
|
|
272
|
+
return { outcome };
|
|
273
|
+
}
|
|
274
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 假 ACP Agent 的进程入口:`node dist/drivers/acp/testing/fake-agent-main.js [--minimal]`。[W5-E]
|
|
3
|
+
* 行为见 fake-agent.ts;stdin 结束即退出。
|
|
4
|
+
*/
|
|
5
|
+
import { runFakeAcpAgent } from "./fake-agent.js";
|
|
6
|
+
const minimal = process.argv.includes("--minimal");
|
|
7
|
+
void runFakeAcpAgent(process.stdin, process.stdout, { minimal }).then(() => process.exit(0));
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 黄金记录用的假 ACP Agent(docs/wave5-plan.md §5.1、§5.7)。[W5-E]
|
|
3
|
+
*
|
|
4
|
+
* 零依赖、不联网、不碰文件系统;行为由提示文本里的标记决定,供 ama 自己的测试与 Armadra 复用
|
|
5
|
+
* (`@armadra/agent/acp` 导出 {@link runFakeAcpAgent} 与可执行入口路径):
|
|
6
|
+
*
|
|
7
|
+
* | 提示里含 | 行为 |
|
|
8
|
+
* | ---------------- | --------------------------------------------------------------------------------- |
|
|
9
|
+
* | (无标记) | `agent_message_chunk` 回 `echo: <文本>`,`usage_update`,`end_turn` |
|
|
10
|
+
* | `[permission]` | `tool_call`(edit, pending) → `session/request_permission`(四个选项)→ 按结果 |
|
|
11
|
+
* | | `tool_call_update` completed / failed;客户端回 cancelled 时本回合 `cancelled` |
|
|
12
|
+
* | `[slow]` | 一直等,直到 `session/cancel` → `cancelled` |
|
|
13
|
+
* | `[plan]` | 先发 `plan`(两条)再回文本 |
|
|
14
|
+
* | `[think]` | 先发 `agent_thought_chunk` |
|
|
15
|
+
* | `[refuse]` | `refusal` |
|
|
16
|
+
*
|
|
17
|
+
* 会话:`session/new` 发 `fake-<n>`;`session/resume` / `session/load` 接受任何 `fake-` 开头的 id
|
|
18
|
+
* (load 先回放一条用户消息与一条回复);`session/list` 列本进程建过的会话。
|
|
19
|
+
*/
|
|
20
|
+
export interface FakeAcpAgentOptions {
|
|
21
|
+
/** `initialize` 回的 agentInfo.name,缺省 `fake-acp-agent`。 */
|
|
22
|
+
name?: string;
|
|
23
|
+
/** 不声明 resume / list / close / loadSession(测降级路径)。 */
|
|
24
|
+
minimal?: boolean;
|
|
25
|
+
}
|
|
26
|
+
/** 在给定流上跑假 Agent;输入流结束时 resolve。 */
|
|
27
|
+
export declare function runFakeAcpAgent(input: NodeJS.ReadableStream, output: NodeJS.WritableStream, options?: FakeAcpAgentOptions): Promise<void>;
|