@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,233 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `ama --mode acp`:ama 的会话事件 → ACP `session/update`(docs/wave5-plan.md §5.6)。[W5-E]
|
|
3
|
+
*
|
|
4
|
+
* | ama | ACP |
|
|
5
|
+
* | ------------------------------------ | ---------------------------------------------------------- |
|
|
6
|
+
* | message_update text_delta | agent_message_chunk |
|
|
7
|
+
* | message_update thinking_delta | agent_thought_chunk |
|
|
8
|
+
* | message_update toolcall_end | tool_call(pending,带 rawInput 与 locations) |
|
|
9
|
+
* | tool_execution_start / end | tool_call_update(in_progress → completed / failed) |
|
|
10
|
+
* | todo_updated | plan |
|
|
11
|
+
* | turn_end | usage_update(上下文用量、窗口、会话累计美元) |
|
|
12
|
+
* | permission_mode_changed | current_mode_update |
|
|
13
|
+
*
|
|
14
|
+
* 工具结果只回前 4 KB 文本(完整结果在 ama 会话里),codemode 内层调用(带 parentToolCallId)
|
|
15
|
+
* 不单列。`session/load` 回放同一套映射(用户消息 → user_message_chunk)。
|
|
16
|
+
*/
|
|
17
|
+
import { isAbsolute, resolve } from "node:path";
|
|
18
|
+
import { PERMISSION_MODES_STRICT_FIRST } from "../../permissions/types.js";
|
|
19
|
+
import { oneLine } from "../../drivers/turn.js";
|
|
20
|
+
export const TOOL_OUTPUT_LIMIT = 4 * 1024;
|
|
21
|
+
const KINDS = {
|
|
22
|
+
read: "read",
|
|
23
|
+
write: "edit",
|
|
24
|
+
edit: "edit",
|
|
25
|
+
bash: "execute",
|
|
26
|
+
grep: "search",
|
|
27
|
+
glob: "search",
|
|
28
|
+
ls: "search",
|
|
29
|
+
find: "search",
|
|
30
|
+
web_fetch: "fetch",
|
|
31
|
+
web_search: "fetch",
|
|
32
|
+
todo: "think",
|
|
33
|
+
};
|
|
34
|
+
export function toolKind(name) {
|
|
35
|
+
return KINDS[name] ?? "other";
|
|
36
|
+
}
|
|
37
|
+
function argOf(args, ...keys) {
|
|
38
|
+
if (args === null || typeof args !== "object")
|
|
39
|
+
return undefined;
|
|
40
|
+
for (const key of keys) {
|
|
41
|
+
const value = args[key];
|
|
42
|
+
if (typeof value === "string" && value !== "")
|
|
43
|
+
return value;
|
|
44
|
+
}
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
export function toolTitle(name, args) {
|
|
48
|
+
const detail = argOf(args, "command") ??
|
|
49
|
+
argOf(args, "path", "file_path", "filePath") ??
|
|
50
|
+
argOf(args, "pattern", "query", "url", "prompt");
|
|
51
|
+
return detail === undefined ? name : `${name}: ${oneLine(detail, 100)}`;
|
|
52
|
+
}
|
|
53
|
+
export function toolLocations(args, cwd) {
|
|
54
|
+
const path = argOf(args, "path", "file_path", "filePath");
|
|
55
|
+
if (path === undefined)
|
|
56
|
+
return undefined;
|
|
57
|
+
return [{ path: isAbsolute(path) ? path : resolve(cwd, path) }];
|
|
58
|
+
}
|
|
59
|
+
function resultText(result) {
|
|
60
|
+
const text = typeof result.content === "string"
|
|
61
|
+
? result.content
|
|
62
|
+
: result.content.map((b) => (b.type === "text" ? b.text : `[${b.type}]`)).join("");
|
|
63
|
+
return text.length > TOOL_OUTPUT_LIMIT
|
|
64
|
+
? `${text.slice(0, TOOL_OUTPUT_LIMIT)}\n…(已截断,共 ${text.length} 字符)`
|
|
65
|
+
: text;
|
|
66
|
+
}
|
|
67
|
+
export function permissionModes(currentModeId) {
|
|
68
|
+
return {
|
|
69
|
+
currentModeId,
|
|
70
|
+
availableModes: PERMISSION_MODES_STRICT_FIRST.map((id) => ({ id, name: id })),
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
/** 一个会话的事件映射器(记住模型发出的工具调用,供权限请求关联 toolCallId)。 */
|
|
74
|
+
export class AcpEventMapper {
|
|
75
|
+
cwd;
|
|
76
|
+
emit;
|
|
77
|
+
session;
|
|
78
|
+
/** 模型已发出、尚未执行完的工具调用。 */
|
|
79
|
+
pendingCalls = [];
|
|
80
|
+
constructor(cwd, emit, session) {
|
|
81
|
+
this.cwd = cwd;
|
|
82
|
+
this.emit = emit;
|
|
83
|
+
this.session = session;
|
|
84
|
+
}
|
|
85
|
+
/** 权限请求对应的工具调用 id(按工具名与参数匹配最近一个)。 */
|
|
86
|
+
toolCallIdFor(toolName, input) {
|
|
87
|
+
const args = JSON.stringify(input ?? null);
|
|
88
|
+
for (let i = this.pendingCalls.length - 1; i >= 0; i--) {
|
|
89
|
+
const call = this.pendingCalls[i];
|
|
90
|
+
if (call.name === toolName && call.args === args)
|
|
91
|
+
return call.id;
|
|
92
|
+
}
|
|
93
|
+
return undefined;
|
|
94
|
+
}
|
|
95
|
+
onEvent(event) {
|
|
96
|
+
switch (event.type) {
|
|
97
|
+
case "message_update": {
|
|
98
|
+
const e = event.assistantMessageEvent;
|
|
99
|
+
if (e.type === "text_delta")
|
|
100
|
+
this.emit({
|
|
101
|
+
sessionUpdate: "agent_message_chunk",
|
|
102
|
+
content: { type: "text", text: e.delta },
|
|
103
|
+
});
|
|
104
|
+
else if (e.type === "thinking_delta")
|
|
105
|
+
this.emit({
|
|
106
|
+
sessionUpdate: "agent_thought_chunk",
|
|
107
|
+
content: { type: "text", text: e.delta },
|
|
108
|
+
});
|
|
109
|
+
else if (e.type === "toolcall_end") {
|
|
110
|
+
const call = e.toolCall;
|
|
111
|
+
this.pendingCalls.push({
|
|
112
|
+
id: call.id,
|
|
113
|
+
name: call.name,
|
|
114
|
+
args: JSON.stringify(call.arguments),
|
|
115
|
+
});
|
|
116
|
+
this.emitToolCall(call.id, call.name, call.arguments, "pending");
|
|
117
|
+
}
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
case "tool_execution_start":
|
|
121
|
+
if (event.parentToolCallId !== undefined)
|
|
122
|
+
return;
|
|
123
|
+
this.emit({
|
|
124
|
+
sessionUpdate: "tool_call_update",
|
|
125
|
+
toolCallId: event.toolCallId,
|
|
126
|
+
status: "in_progress",
|
|
127
|
+
});
|
|
128
|
+
return;
|
|
129
|
+
case "tool_execution_end": {
|
|
130
|
+
if (event.parentToolCallId !== undefined)
|
|
131
|
+
return;
|
|
132
|
+
const at = this.pendingCalls.findIndex((c) => c.id === event.toolCallId);
|
|
133
|
+
if (at >= 0)
|
|
134
|
+
this.pendingCalls.splice(at, 1);
|
|
135
|
+
this.emit({
|
|
136
|
+
sessionUpdate: "tool_call_update",
|
|
137
|
+
toolCallId: event.toolCallId,
|
|
138
|
+
status: event.isError ? "failed" : "completed",
|
|
139
|
+
content: [{ type: "content", content: { type: "text", text: resultText(event.result) } }],
|
|
140
|
+
});
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
case "todo_updated":
|
|
144
|
+
this.emit({
|
|
145
|
+
sessionUpdate: "plan",
|
|
146
|
+
entries: event.items.map((item) => ({
|
|
147
|
+
content: item.text,
|
|
148
|
+
priority: "medium",
|
|
149
|
+
status: item.status === "done" ? "completed" : item.status,
|
|
150
|
+
})),
|
|
151
|
+
});
|
|
152
|
+
return;
|
|
153
|
+
case "turn_end":
|
|
154
|
+
this.emitUsage();
|
|
155
|
+
return;
|
|
156
|
+
case "permission_mode_changed":
|
|
157
|
+
this.emit({ sessionUpdate: "current_mode_update", currentModeId: event.mode });
|
|
158
|
+
return;
|
|
159
|
+
default:
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
emitUsage() {
|
|
164
|
+
const stats = this.session().getStats();
|
|
165
|
+
if (stats.contextWindow === undefined)
|
|
166
|
+
return;
|
|
167
|
+
this.emit({
|
|
168
|
+
sessionUpdate: "usage_update",
|
|
169
|
+
used: stats.contextTokens ?? 0,
|
|
170
|
+
size: stats.contextWindow,
|
|
171
|
+
...(stats.cost !== undefined ? { cost: { amount: stats.cost, currency: "USD" } } : {}),
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
/** `session/load`:按消息回放历史。 */
|
|
175
|
+
replay(messages) {
|
|
176
|
+
for (const message of messages) {
|
|
177
|
+
if (!("role" in message))
|
|
178
|
+
continue;
|
|
179
|
+
if (message.role === "user") {
|
|
180
|
+
for (const block of contentOf(message.content))
|
|
181
|
+
this.emit({ sessionUpdate: "user_message_chunk", content: block });
|
|
182
|
+
}
|
|
183
|
+
else if (message.role === "assistant") {
|
|
184
|
+
for (const block of message.content) {
|
|
185
|
+
if (block.type === "text")
|
|
186
|
+
this.emit({
|
|
187
|
+
sessionUpdate: "agent_message_chunk",
|
|
188
|
+
content: { type: "text", text: block.text },
|
|
189
|
+
});
|
|
190
|
+
else if (block.type === "thinking" && block.redacted !== true)
|
|
191
|
+
this.emit({
|
|
192
|
+
sessionUpdate: "agent_thought_chunk",
|
|
193
|
+
content: { type: "text", text: block.thinking },
|
|
194
|
+
});
|
|
195
|
+
else if (block.type === "toolCall")
|
|
196
|
+
this.emitToolCall(block.id, block.name, block.arguments, "pending");
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
else if (message.role === "toolResult") {
|
|
200
|
+
this.emit({
|
|
201
|
+
sessionUpdate: "tool_call_update",
|
|
202
|
+
toolCallId: message.toolCallId,
|
|
203
|
+
status: message.isError ? "failed" : "completed",
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
emitToolCall(id, name, args, status) {
|
|
209
|
+
const locations = toolLocations(args, this.cwd);
|
|
210
|
+
this.emit({
|
|
211
|
+
sessionUpdate: "tool_call",
|
|
212
|
+
toolCallId: id,
|
|
213
|
+
title: toolTitle(name, args),
|
|
214
|
+
kind: toolKind(name),
|
|
215
|
+
status,
|
|
216
|
+
rawInput: args,
|
|
217
|
+
...(locations !== undefined ? { locations } : {}),
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
function contentOf(content) {
|
|
222
|
+
if (typeof content === "string")
|
|
223
|
+
return content === "" ? [] : [{ type: "text", text: content }];
|
|
224
|
+
const out = [];
|
|
225
|
+
for (const block of content) {
|
|
226
|
+
if (block.type === "text")
|
|
227
|
+
out.push({ type: "text", text: block.text });
|
|
228
|
+
else if (block.type === "image") {
|
|
229
|
+
out.push({ type: "image", data: block.data, mimeType: block.mimeType });
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
return out;
|
|
233
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `ama --mode acp` 的进程入口(docs/wave5-plan.md §5.6)。[W5-E]
|
|
3
|
+
*
|
|
4
|
+
* - stdin / stdout 是 ACP(JSON-RPC 2.0 over NDJSON),不发 hello(ACP 由客户端 `initialize` 起头);
|
|
5
|
+
* 诊断与宿主通知写 stderr。
|
|
6
|
+
* - 审批:挂 {@link AcpServer.broker} 为 UI broker,ama 的审批请求以 `session/request_permission`
|
|
7
|
+
* 交给客户端。
|
|
8
|
+
* - 退出语义同 rpc:stdin 关闭 → 撤下审批、等在途请求与已开始的运行结束 → 退出 0;
|
|
9
|
+
* SIGINT / SIGTERM → abort 后退出 130 / 143。
|
|
10
|
+
*/
|
|
11
|
+
import type { ModeContext } from "../../cli/deps.js";
|
|
12
|
+
import type { Runtime } from "../../cli/runtime.js";
|
|
13
|
+
export interface AcpModeOptions {
|
|
14
|
+
stdin?: NodeJS.ReadableStream;
|
|
15
|
+
stdout?: NodeJS.WritableStream;
|
|
16
|
+
}
|
|
17
|
+
export declare function runAcpMode(runtime: Runtime, context: ModeContext, options?: AcpModeOptions): Promise<number>;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `ama --mode acp` 的进程入口(docs/wave5-plan.md §5.6)。[W5-E]
|
|
3
|
+
*
|
|
4
|
+
* - stdin / stdout 是 ACP(JSON-RPC 2.0 over NDJSON),不发 hello(ACP 由客户端 `initialize` 起头);
|
|
5
|
+
* 诊断与宿主通知写 stderr。
|
|
6
|
+
* - 审批:挂 {@link AcpServer.broker} 为 UI broker,ama 的审批请求以 `session/request_permission`
|
|
7
|
+
* 交给客户端。
|
|
8
|
+
* - 退出语义同 rpc:stdin 关闭 → 撤下审批、等在途请求与已开始的运行结束 → 退出 0;
|
|
9
|
+
* SIGINT / SIGTERM → abort 后退出 130 / 143。
|
|
10
|
+
*/
|
|
11
|
+
import { ExitCode } from "../../cli/exit-codes.js";
|
|
12
|
+
import { onTerminationSignals } from "../shared.js";
|
|
13
|
+
import { AcpServer } from "./acp-server.js";
|
|
14
|
+
export async function runAcpMode(runtime, context, options = {}) {
|
|
15
|
+
const stdin = options.stdin ?? process.stdin;
|
|
16
|
+
const stdout = options.stdout ?? process.stdout;
|
|
17
|
+
const server = new AcpServer(runtime, { input: stdin, output: stdout }, (message) => context.io.stderr(`ama: ${message}\n`));
|
|
18
|
+
runtime.approvals.setUiBroker(server.broker);
|
|
19
|
+
runtime.notifier.set((message, level) => context.io.stderr(`ama: [${level}] ${message}\n`));
|
|
20
|
+
return new Promise((resolve) => {
|
|
21
|
+
let finished = false;
|
|
22
|
+
const finish = async (code, abort) => {
|
|
23
|
+
if (finished)
|
|
24
|
+
return;
|
|
25
|
+
finished = true;
|
|
26
|
+
offSignals();
|
|
27
|
+
stdin.pause?.();
|
|
28
|
+
runtime.approvals.setUiBroker(undefined);
|
|
29
|
+
const session = server.session();
|
|
30
|
+
if (abort)
|
|
31
|
+
await session.abort().catch(() => undefined);
|
|
32
|
+
await session.waitForIdle().catch(() => undefined);
|
|
33
|
+
await server.peer.flush();
|
|
34
|
+
server.peer.close();
|
|
35
|
+
server.dispose();
|
|
36
|
+
runtime.notifier.set(undefined);
|
|
37
|
+
resolve(code);
|
|
38
|
+
};
|
|
39
|
+
void server.peer.closed.then(() => finish(ExitCode.Ok, false));
|
|
40
|
+
const offSignals = onTerminationSignals((code) => {
|
|
41
|
+
if (finished)
|
|
42
|
+
void server.session().abort();
|
|
43
|
+
else
|
|
44
|
+
void finish(code, true);
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `ama --mode acp`:把 ama 的会话暴露为 ACP Agent(docs/wave5-plan.md §5.6,D14)。[W5-E]
|
|
3
|
+
*
|
|
4
|
+
* 与 `--mode rpc` 同一引擎(Runtime + 组装根的会话切换),一次只有一个活动会话:
|
|
5
|
+
* - `session/new` 新开(启动时那个空会话第一次直接认领);`session/load` 切到该会话并回放历史;
|
|
6
|
+
* `session/resume` 切换不回放;`session/list` 列本 cwd 的会话;`session/close` 中断并释放;
|
|
7
|
+
* 对非活动会话发 `session/prompt` 时(空闲)先切过去。
|
|
8
|
+
* - `session/prompt` → `prompt`(文本 + 图片;资源链接以 `@uri` 文本给出,嵌入资源取文本);
|
|
9
|
+
* 回合结束按会话状态给 stopReason:中断 → cancelled,输出截断 → max_tokens,出错 → JSON-RPC 错误。
|
|
10
|
+
* - `session/cancel` → `abort`;`session/set_mode` → `setPermissionMode`(模式 id = ama 权限模式)。
|
|
11
|
+
* - 审批:ama 的审批请求经 `session/request_permission` 交给客户端(允许 / 本会话允许 / 拒绝);
|
|
12
|
+
* 客户端回 cancelled、连接断开或回合被中断 → 交给链上下一个回答者(无人 → 拒绝)。
|
|
13
|
+
* - 不声明 / 不使用客户端的 `fs`、`terminal` 能力(Armadra Q5);ama 自己读写、自己跑命令。
|
|
14
|
+
* - cwd 固定为启动目录(信任与项目配置都按它判定);客户端给别的 cwd → invalid params。
|
|
15
|
+
*/
|
|
16
|
+
import type { ImageBlock } from "../../ai/types.js";
|
|
17
|
+
import type { AgentSession } from "../../agent/types.js";
|
|
18
|
+
import type { Runtime } from "../../cli/runtime.js";
|
|
19
|
+
import { JsonRpcPeer } from "../../drivers/jsonrpc.js";
|
|
20
|
+
import type { ApprovalBroker } from "../../permissions/types.js";
|
|
21
|
+
export declare const ACP_AGENT_CAPABILITIES: {
|
|
22
|
+
loadSession: boolean;
|
|
23
|
+
promptCapabilities: {
|
|
24
|
+
image: boolean;
|
|
25
|
+
audio: boolean;
|
|
26
|
+
embeddedContext: boolean;
|
|
27
|
+
};
|
|
28
|
+
mcpCapabilities: {
|
|
29
|
+
http: boolean;
|
|
30
|
+
sse: boolean;
|
|
31
|
+
};
|
|
32
|
+
sessionCapabilities: {
|
|
33
|
+
list: {};
|
|
34
|
+
resume: {};
|
|
35
|
+
close: {};
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
/** ACP 提示 → ama 的文本与图片。 */
|
|
39
|
+
export declare function promptOf(blocks: unknown): {
|
|
40
|
+
text: string;
|
|
41
|
+
images: ImageBlock[];
|
|
42
|
+
};
|
|
43
|
+
export declare class AcpServer {
|
|
44
|
+
private readonly runtime;
|
|
45
|
+
private readonly log;
|
|
46
|
+
readonly peer: JsonRpcPeer;
|
|
47
|
+
private activeId;
|
|
48
|
+
/** 启动时的空会话还没被 session/new 认领。 */
|
|
49
|
+
private freshUnclaimed;
|
|
50
|
+
private mapper;
|
|
51
|
+
private unsubscribe;
|
|
52
|
+
private cancelRequested;
|
|
53
|
+
private readonly cwd;
|
|
54
|
+
constructor(runtime: Runtime, streams: {
|
|
55
|
+
input: NodeJS.ReadableStream;
|
|
56
|
+
output: NodeJS.WritableStream;
|
|
57
|
+
}, log?: (message: string) => void);
|
|
58
|
+
session(): AgentSession;
|
|
59
|
+
/** 审批交给客户端:ama 的 UI broker。 */
|
|
60
|
+
readonly broker: ApprovalBroker;
|
|
61
|
+
private makeMapper;
|
|
62
|
+
private emit;
|
|
63
|
+
private subscribe;
|
|
64
|
+
dispose(): void;
|
|
65
|
+
private handle;
|
|
66
|
+
private initialize;
|
|
67
|
+
private checkCwd;
|
|
68
|
+
private modes;
|
|
69
|
+
private switchTo;
|
|
70
|
+
private newSession;
|
|
71
|
+
private openSession;
|
|
72
|
+
private list;
|
|
73
|
+
private close;
|
|
74
|
+
private ensureIdle;
|
|
75
|
+
private prompt;
|
|
76
|
+
private cancel;
|
|
77
|
+
private setMode;
|
|
78
|
+
private askClient;
|
|
79
|
+
}
|