@armadra/agent 0.3.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 +257 -0
- package/README.md +263 -95
- 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/retry.d.ts +1 -1
- package/dist/agent/retry.js +2 -1
- package/dist/agent/session-cache.d.ts +5 -0
- package/dist/agent/session-cache.js +18 -2
- package/dist/agent/session-classifier.d.ts +18 -0
- package/dist/agent/session-classifier.js +105 -0
- package/dist/agent/session-compaction.d.ts +35 -6
- package/dist/agent/session-compaction.js +157 -31
- package/dist/agent/session-core.d.ts +40 -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 +63 -3
- package/dist/agent/session.d.ts +33 -29
- package/dist/agent/session.js +91 -126
- 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 +72 -6
- package/dist/agent/types-w5.d.ts +192 -0
- package/dist/agent/types-w5.js +10 -0
- package/dist/agent/types.d.ts +55 -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-messages.js +3 -2
- 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/google-generative-ai.js +3 -2
- package/dist/ai/apis/openai-compat.d.ts +4 -1
- package/dist/ai/apis/openai-compat.js +8 -1
- package/dist/ai/apis/openai-completions.js +3 -2
- package/dist/ai/apis/openai-responses.js +3 -2
- package/dist/ai/http.d.ts +28 -6
- package/dist/ai/http.js +41 -8
- 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 +28 -11
- package/dist/ai/providers/registry.js +112 -65
- package/dist/ai/providers/suggest.d.ts +18 -0
- package/dist/ai/providers/suggest.js +72 -0
- package/dist/ai/sse.d.ts +6 -2
- package/dist/ai/sse.js +22 -2
- package/dist/ai/types.d.ts +37 -4
- package/dist/ai/types.js +5 -0
- package/dist/bundle/ama.cjs +41979 -21147
- 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 +26 -7
- package/dist/cli/args.js +75 -82
- package/dist/cli/bootstrap.js +40 -4
- package/dist/cli/codemode-notice.d.ts +21 -0
- package/dist/cli/codemode-notice.js +56 -0
- 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 +8 -0
- package/dist/cli/compose-session.js +76 -2
- package/dist/cli/compose-store.d.ts +1 -1
- package/dist/cli/compose-store.js +3 -1
- package/dist/cli/compose.d.ts +17 -4
- package/dist/cli/compose.js +60 -14
- package/dist/cli/default-model.d.ts +38 -1
- package/dist/cli/default-model.js +96 -9
- package/dist/cli/deps.d.ts +42 -0
- package/dist/cli/exit-codes.d.ts +12 -0
- package/dist/cli/exit-codes.js +15 -0
- package/dist/cli/fake-visibility.d.ts +13 -0
- package/dist/cli/fake-visibility.js +26 -0
- package/dist/cli/from-prompt.d.ts +18 -0
- package/dist/cli/from-prompt.js +49 -0
- package/dist/cli/help-text.d.ts +4 -0
- package/dist/cli/help-text.js +102 -0
- package/dist/cli/main.d.ts +9 -2
- package/dist/cli/main.js +77 -3
- package/dist/cli/proxy.d.ts +51 -0
- package/dist/cli/proxy.js +135 -0
- package/dist/cli/startup-screen.d.ts +29 -0
- package/dist/cli/startup-screen.js +51 -2
- package/dist/cli/startup-steps.d.ts +1 -1
- package/dist/cli/startup-steps.js +21 -13
- package/dist/cli/subcommands/config.d.ts +22 -3
- package/dist/cli/subcommands/config.js +119 -21
- package/dist/cli/subcommands/context.js +4 -1
- package/dist/cli/subcommands/doctor.js +33 -1
- package/dist/cli/subcommands/init.js +2 -1
- package/dist/cli/subcommands/models-discover.d.ts +15 -9
- package/dist/cli/subcommands/models-discover.js +58 -52
- package/dist/cli/subcommands/models.d.ts +2 -0
- package/dist/cli/subcommands/models.js +33 -14
- package/dist/cli/subcommands/probe-runner.d.ts +96 -0
- package/dist/cli/subcommands/probe-runner.js +264 -0
- package/dist/cli/subcommands/providers-probe.d.ts +34 -0
- package/dist/cli/subcommands/providers-probe.js +87 -0
- package/dist/cli/subcommands/providers.d.ts +3 -2
- package/dist/cli/subcommands/providers.js +53 -51
- package/dist/cli/subcommands/sessions-export.d.ts +10 -0
- package/dist/cli/subcommands/sessions-export.js +59 -0
- package/dist/cli/subcommands/sessions-search.d.ts +13 -0
- package/dist/cli/subcommands/sessions-search.js +103 -0
- package/dist/cli/subcommands/sessions.d.ts +6 -3
- package/dist/cli/subcommands/sessions.js +58 -3
- package/dist/cli/subcommands/stats.d.ts +17 -0
- package/dist/cli/subcommands/stats.js +198 -0
- package/dist/cli/system-prompt-arg.d.ts +11 -0
- package/dist/cli/system-prompt-arg.js +34 -0
- 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/modes.d.ts +4 -11
- package/dist/codemode/modes.js +5 -27
- package/dist/codemode/tool.d.ts +18 -14
- package/dist/codemode/tool.js +76 -31
- 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/init.d.ts +6 -2
- package/dist/config/init.js +12 -5
- package/dist/config/json-schema.d.ts +1 -0
- package/dist/config/json-schema.js +98 -4
- package/dist/config/key-docs.d.ts +22 -0
- package/dist/config/key-docs.js +174 -0
- package/dist/config/merge.d.ts +12 -9
- package/dist/config/merge.js +102 -13
- 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 +91 -118
- package/dist/config/types-w5.d.ts +118 -0
- package/dist/config/types-w5.js +20 -0
- package/dist/config/types.d.ts +84 -7
- package/dist/config/types.js +29 -1
- 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 +61 -5
- 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 +40 -7
- package/dist/modes/interactive/approval-dialog.js +192 -35
- 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 +20 -3
- package/dist/modes/interactive/commands.js +75 -16
- 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 +16 -2
- package/dist/modes/interactive/interactive-mode.js +184 -202
- package/dist/modes/interactive/key-dispatch.d.ts +18 -2
- package/dist/modes/interactive/key-dispatch.js +53 -6
- package/dist/modes/interactive/line/line-mode.d.ts +3 -1
- package/dist/modes/interactive/line/line-mode.js +28 -9
- package/dist/modes/interactive/line/line-render.d.ts +6 -1
- package/dist/modes/interactive/line/line-render.js +66 -8
- package/dist/modes/interactive/message-view.d.ts +49 -10
- package/dist/modes/interactive/message-view.js +262 -46
- package/dist/modes/interactive/panels.d.ts +35 -0
- package/dist/modes/interactive/panels.js +157 -0
- package/dist/modes/interactive/pickers.d.ts +23 -2
- package/dist/modes/interactive/pickers.js +48 -15
- 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/run-indicator.d.ts +51 -0
- package/dist/modes/interactive/run-indicator.js +189 -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-header.d.ts +40 -0
- package/dist/modes/interactive/startup-header.js +169 -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 +107 -16
- package/dist/modes/interactive/status-bar.js +306 -81
- 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-summary.d.ts +46 -0
- package/dist/modes/interactive/tool-summary.js +218 -0
- package/dist/modes/interactive/tool-view.d.ts +58 -15
- package/dist/modes/interactive/tool-view.js +233 -145
- package/dist/modes/print/print-mode.d.ts +40 -4
- package/dist/modes/print/print-mode.js +161 -8
- package/dist/modes/rpc/commands.d.ts +9 -0
- package/dist/modes/rpc/commands.js +49 -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 +65 -0
- package/dist/permissions/auto-safe.js +547 -0
- package/dist/permissions/classifier.d.ts +68 -0
- package/dist/permissions/classifier.js +186 -0
- package/dist/permissions/dangerous.d.ts +5 -0
- package/dist/permissions/dangerous.js +1 -1
- package/dist/permissions/modes.d.ts +30 -0
- package/dist/permissions/modes.js +78 -0
- package/dist/permissions/pipeline.d.ts +72 -6
- package/dist/permissions/pipeline.js +306 -11
- package/dist/permissions/protected.d.ts +19 -0
- package/dist/permissions/protected.js +74 -0
- package/dist/permissions/readonly-bash.d.ts +30 -0
- package/dist/permissions/readonly-bash.js +118 -0
- package/dist/permissions/rules.js +3 -0
- package/dist/permissions/types.d.ts +92 -3
- package/dist/permissions/types.js +3 -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 +42 -5
- package/dist/sdk.js +34 -4
- package/dist/session/export.d.ts +32 -0
- package/dist/session/export.js +187 -0
- package/dist/session/redact.d.ts +15 -0
- package/dist/session/redact.js +55 -0
- package/dist/session/reuse.d.ts +33 -0
- package/dist/session/reuse.js +86 -0
- package/dist/session/scan.d.ts +34 -0
- package/dist/session/scan.js +140 -0
- package/dist/session/search.d.ts +52 -0
- package/dist/session/search.js +211 -0
- package/dist/session/stats-aggregate.d.ts +63 -0
- package/dist/session/stats-aggregate.js +163 -0
- package/dist/session/stats-index.d.ts +26 -0
- package/dist/session/stats-index.js +91 -0
- package/dist/session/stats-scan.d.ts +54 -0
- package/dist/session/stats-scan.js +236 -0
- 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 +40 -8
- package/dist/tools/presets.js +65 -19
- 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/component.d.ts +8 -2
- package/dist/tui/component.js +3 -1
- package/dist/tui/components/box.d.ts +6 -1
- package/dist/tui/components/box.js +16 -6
- package/dist/tui/components/card.d.ts +23 -0
- package/dist/tui/components/card.js +37 -0
- package/dist/tui/components/editor-history.d.ts +6 -0
- package/dist/tui/components/editor-history.js +45 -0
- package/dist/tui/components/editor-paste.d.ts +1 -1
- package/dist/tui/components/editor-paste.js +4 -4
- package/dist/tui/components/editor.d.ts +11 -5
- package/dist/tui/components/editor.js +52 -58
- package/dist/tui/components/key-value.d.ts +3 -0
- package/dist/tui/components/key-value.js +16 -6
- package/dist/tui/components/loader.d.ts +37 -7
- package/dist/tui/components/loader.js +84 -21
- package/dist/tui/components/markdown.d.ts +5 -1
- package/dist/tui/components/markdown.js +45 -21
- package/dist/tui/components/meter.d.ts +3 -3
- package/dist/tui/components/meter.js +13 -11
- package/dist/tui/components/select-list.d.ts +23 -1
- package/dist/tui/components/select-list.js +76 -13
- package/dist/tui/glyphs.d.ts +72 -0
- package/dist/tui/glyphs.js +118 -0
- package/dist/tui/keybindings.d.ts +5 -0
- package/dist/tui/keybindings.js +5 -0
- package/dist/tui/theme.d.ts +30 -6
- package/dist/tui/theme.js +103 -17
- package/dist/tui.d.ts +4 -2
- package/dist/tui.js +3 -1
- package/docs/acp.md +78 -0
- package/docs/agents.md +250 -0
- package/docs/codemode.md +28 -10
- package/docs/hooks.md +36 -32
- package/docs/permissions.md +212 -0
- package/docs/plan.md +107 -0
- package/docs/providers.md +261 -62
- package/docs/rewind-plan.md +181 -0
- package/docs/rpc.md +127 -40
- package/docs/sandbox.md +215 -0
- package/docs/session-format.md +43 -22
- package/docs/sessions.md +174 -0
- package/docs/tui-design.md +751 -0
- package/docs/tui.md +260 -64
- package/package.json +15 -2
|
@@ -0,0 +1,456 @@
|
|
|
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 { randomUUID } from "node:crypto";
|
|
18
|
+
import { AmaError } from "../../errors.js";
|
|
19
|
+
import { createLineReader } from "../../modes/rpc/jsonl.js";
|
|
20
|
+
import { armCancelWatchdog, probeCandidate, spawnOf } from "../base.js";
|
|
21
|
+
import { stderrHint } from "../process.js";
|
|
22
|
+
import { TurnCollector, oneLine } from "../turn.js";
|
|
23
|
+
import { CLAUDE_QUESTION_TOOLS, claudePermissionMode, claudeStopReason, claudeTodos, claudeToolKind, claudeToolLocations, claudeToolTitle, sessionScopedSuggestions, } from "./claude-normalize.js";
|
|
24
|
+
export function claudeArgs(options, sessionId, manualName = "manual") {
|
|
25
|
+
const args = [
|
|
26
|
+
"-p",
|
|
27
|
+
"--input-format",
|
|
28
|
+
"stream-json",
|
|
29
|
+
"--output-format",
|
|
30
|
+
"stream-json",
|
|
31
|
+
"--verbose",
|
|
32
|
+
"--include-partial-messages",
|
|
33
|
+
"--permission-mode",
|
|
34
|
+
claudePermissionMode(options.mode, manualName),
|
|
35
|
+
];
|
|
36
|
+
if (options.unattended === true)
|
|
37
|
+
args.push("--permission-prompts", "none");
|
|
38
|
+
else
|
|
39
|
+
args.push("--permission-prompt-tool", "stdio");
|
|
40
|
+
if (options.resume !== undefined)
|
|
41
|
+
args.push("--resume", options.resume);
|
|
42
|
+
else
|
|
43
|
+
args.push("--session-id", sessionId);
|
|
44
|
+
if (options.model !== undefined)
|
|
45
|
+
args.push("--model", options.model);
|
|
46
|
+
if (options.budgetUsd !== undefined)
|
|
47
|
+
args.push("--max-budget-usd", String(options.budgetUsd));
|
|
48
|
+
return args;
|
|
49
|
+
}
|
|
50
|
+
function userLine(content) {
|
|
51
|
+
const blocks = content.map((b) => b.type === "text"
|
|
52
|
+
? { type: "text", text: b.text }
|
|
53
|
+
: { type: "image", source: { type: "base64", media_type: b.mimeType, data: b.data } });
|
|
54
|
+
return `${JSON.stringify({
|
|
55
|
+
type: "user",
|
|
56
|
+
message: { role: "user", content: blocks },
|
|
57
|
+
parent_tool_use_id: null,
|
|
58
|
+
})}\n`;
|
|
59
|
+
}
|
|
60
|
+
export class ClaudeStreamDriver {
|
|
61
|
+
agentId;
|
|
62
|
+
candidate;
|
|
63
|
+
deps;
|
|
64
|
+
kind = "claude-stream";
|
|
65
|
+
constructor(agentId, candidate, deps = {}) {
|
|
66
|
+
this.agentId = agentId;
|
|
67
|
+
this.candidate = candidate;
|
|
68
|
+
this.deps = deps;
|
|
69
|
+
}
|
|
70
|
+
probe() {
|
|
71
|
+
return probeCandidate(this.candidate, this.deps);
|
|
72
|
+
}
|
|
73
|
+
async open(options) {
|
|
74
|
+
let manual = "manual";
|
|
75
|
+
const probed = await probeCandidate(this.candidate, this.deps);
|
|
76
|
+
if (probed.path !== undefined && this.deps.probe !== undefined) {
|
|
77
|
+
const help = await this.deps.probe.capture(probed.path, ["--help"]);
|
|
78
|
+
if (help !== undefined && !help.includes('"manual"'))
|
|
79
|
+
manual = "default";
|
|
80
|
+
}
|
|
81
|
+
const sessionId = options.resume ?? randomUUID();
|
|
82
|
+
const transport = spawnOf(this.deps)({
|
|
83
|
+
program: probed.path ?? this.candidate.program,
|
|
84
|
+
args: [...this.candidate.args, ...claudeArgs(options, sessionId, manual)],
|
|
85
|
+
cwd: options.cwd,
|
|
86
|
+
env: options.env,
|
|
87
|
+
});
|
|
88
|
+
const session = new ClaudeStreamSession(this.agentId, sessionId, transport, this.deps);
|
|
89
|
+
if (probed.warning !== undefined)
|
|
90
|
+
session.notices.push(probed.warning);
|
|
91
|
+
try {
|
|
92
|
+
await session.initialize(options.signal);
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
await session.close();
|
|
96
|
+
throw new AmaError("agent_start_failed", `${this.agentId}:启动失败(${error.message})${stderrHint(transport) !== "" ? `:${stderrHint(transport)}` : ""}`, { cause: error });
|
|
97
|
+
}
|
|
98
|
+
return session;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
class ClaudeStreamSession {
|
|
102
|
+
agentId;
|
|
103
|
+
id;
|
|
104
|
+
transport;
|
|
105
|
+
deps;
|
|
106
|
+
notices = [];
|
|
107
|
+
nextRequest = 1;
|
|
108
|
+
controls = new Map();
|
|
109
|
+
permissions = new Map();
|
|
110
|
+
turn;
|
|
111
|
+
hooks;
|
|
112
|
+
finishTurn;
|
|
113
|
+
failTurn;
|
|
114
|
+
running;
|
|
115
|
+
interrupted = false;
|
|
116
|
+
sawPartialText = false;
|
|
117
|
+
lastTotalCost = 0;
|
|
118
|
+
closed = false;
|
|
119
|
+
exited = false;
|
|
120
|
+
constructor(agentId, id, transport, deps) {
|
|
121
|
+
this.agentId = agentId;
|
|
122
|
+
this.id = id;
|
|
123
|
+
this.transport = transport;
|
|
124
|
+
this.deps = deps;
|
|
125
|
+
createLineReader(transport.stdout, (line) => this.onLine(line), () => this.onExit());
|
|
126
|
+
transport.stdin.on?.("error", () => undefined);
|
|
127
|
+
}
|
|
128
|
+
get sessionId() {
|
|
129
|
+
return this.id;
|
|
130
|
+
}
|
|
131
|
+
/** SDK 握手;旧版本不认 initialize 时忽略错误继续。 */
|
|
132
|
+
async initialize(signal) {
|
|
133
|
+
const response = this.control({ subtype: "initialize", hooks: null });
|
|
134
|
+
const aborted = new Promise((_, reject) => {
|
|
135
|
+
if (signal.aborted)
|
|
136
|
+
reject(new Error("aborted"));
|
|
137
|
+
signal.addEventListener("abort", () => reject(new Error("aborted")), { once: true });
|
|
138
|
+
});
|
|
139
|
+
const timeout = new Promise((resolve) => setTimeout(resolve, 10_000).unref());
|
|
140
|
+
try {
|
|
141
|
+
await Promise.race([response, aborted, timeout]);
|
|
142
|
+
}
|
|
143
|
+
catch (error) {
|
|
144
|
+
if (this.exited || signal.aborted)
|
|
145
|
+
throw error;
|
|
146
|
+
this.deps.log?.("debug", `${this.agentId}: initialize 未被接受(${error.message})`);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
async prompt(content, hooks) {
|
|
150
|
+
if (this.closed || this.exited)
|
|
151
|
+
throw new AmaError("agent_closed", `${this.agentId} 会话已关闭`);
|
|
152
|
+
if (this.running !== undefined)
|
|
153
|
+
throw new AmaError("busy", `${this.agentId} 正在运行`);
|
|
154
|
+
const turn = new TurnCollector((e) => hooks.onEvent(e));
|
|
155
|
+
for (const text of this.notices.splice(0))
|
|
156
|
+
turn.push({ type: "notice", level: "warn", text });
|
|
157
|
+
this.turn = turn;
|
|
158
|
+
this.hooks = hooks;
|
|
159
|
+
this.interrupted = false;
|
|
160
|
+
this.sawPartialText = false;
|
|
161
|
+
const done = new Promise((resolve, reject) => {
|
|
162
|
+
this.finishTurn = resolve;
|
|
163
|
+
this.failTurn = reject;
|
|
164
|
+
});
|
|
165
|
+
this.running = done.then((result) => this.complete(result, turn));
|
|
166
|
+
this.write(userLine(content));
|
|
167
|
+
try {
|
|
168
|
+
return await this.running;
|
|
169
|
+
}
|
|
170
|
+
finally {
|
|
171
|
+
this.running = undefined;
|
|
172
|
+
this.turn = undefined;
|
|
173
|
+
this.hooks = undefined;
|
|
174
|
+
this.finishTurn = undefined;
|
|
175
|
+
this.failTurn = undefined;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
async steer(content) {
|
|
179
|
+
if (this.closed || this.exited)
|
|
180
|
+
throw new AmaError("agent_closed", `${this.agentId} 会话已关闭`);
|
|
181
|
+
this.write(userLine(content));
|
|
182
|
+
}
|
|
183
|
+
async cancel() {
|
|
184
|
+
const running = this.running;
|
|
185
|
+
if (running === undefined || this.closed)
|
|
186
|
+
return;
|
|
187
|
+
this.interrupted = true;
|
|
188
|
+
for (const controller of this.permissions.values())
|
|
189
|
+
controller.abort();
|
|
190
|
+
void this.control({ subtype: "interrupt" }).catch(() => undefined);
|
|
191
|
+
armCancelWatchdog(this.transport, running.catch(() => undefined), this.deps);
|
|
192
|
+
}
|
|
193
|
+
async close() {
|
|
194
|
+
if (this.closed)
|
|
195
|
+
return;
|
|
196
|
+
this.closed = true;
|
|
197
|
+
for (const controller of this.permissions.values())
|
|
198
|
+
controller.abort();
|
|
199
|
+
if (this.running !== undefined) {
|
|
200
|
+
this.interrupted = true;
|
|
201
|
+
void this.control({ subtype: "interrupt" }).catch(() => undefined);
|
|
202
|
+
}
|
|
203
|
+
await this.transport.terminate();
|
|
204
|
+
}
|
|
205
|
+
complete(result, turn) {
|
|
206
|
+
if (typeof result.session_id === "string" && result.session_id !== "")
|
|
207
|
+
this.id = result.session_id;
|
|
208
|
+
const u = result.usage ?? {};
|
|
209
|
+
const total = typeof result.total_cost_usd === "number" ? result.total_cost_usd : undefined;
|
|
210
|
+
const cost = total === undefined ? undefined : Math.max(0, total - this.lastTotalCost);
|
|
211
|
+
if (total !== undefined)
|
|
212
|
+
this.lastTotalCost = total;
|
|
213
|
+
turn.push({
|
|
214
|
+
type: "usage",
|
|
215
|
+
...(u.input_tokens !== undefined ? { input: u.input_tokens } : {}),
|
|
216
|
+
...(u.output_tokens !== undefined ? { output: u.output_tokens } : {}),
|
|
217
|
+
...(u.cache_read_input_tokens !== undefined ? { cacheRead: u.cache_read_input_tokens } : {}),
|
|
218
|
+
...(cost !== undefined ? { costUsd: cost } : {}),
|
|
219
|
+
});
|
|
220
|
+
if (typeof result.result === "string" && result.result !== "")
|
|
221
|
+
turn.setFinalText(result.result);
|
|
222
|
+
const denials = result.permission_denials?.length ?? 0;
|
|
223
|
+
if (denials > 0)
|
|
224
|
+
turn.push({
|
|
225
|
+
type: "notice",
|
|
226
|
+
level: "info",
|
|
227
|
+
text: `${this.agentId} 有 ${denials} 次操作因无人审批被拒绝`,
|
|
228
|
+
});
|
|
229
|
+
if (result.subtype === "error_max_budget_usd")
|
|
230
|
+
turn.push({
|
|
231
|
+
type: "notice",
|
|
232
|
+
level: "warn",
|
|
233
|
+
text: `${this.agentId} 达到美元预算上限,已停止`,
|
|
234
|
+
});
|
|
235
|
+
const stop = claudeStopReason(result, this.interrupted);
|
|
236
|
+
if (stop === undefined) {
|
|
237
|
+
const detail = result.errors?.join("; ") ?? result.result ?? result.subtype ?? "unknown";
|
|
238
|
+
throw new AmaError("agent_failed", `${this.agentId} 回合失败:${oneLine(detail, 300)}`);
|
|
239
|
+
}
|
|
240
|
+
return turn.result(stop);
|
|
241
|
+
}
|
|
242
|
+
write(line) {
|
|
243
|
+
if (this.exited)
|
|
244
|
+
return;
|
|
245
|
+
this.transport.stdin.write(line);
|
|
246
|
+
}
|
|
247
|
+
control(request) {
|
|
248
|
+
const requestId = `ama-${this.nextRequest++}`;
|
|
249
|
+
return new Promise((resolve, reject) => {
|
|
250
|
+
this.controls.set(requestId, { resolve, reject });
|
|
251
|
+
this.write(`${JSON.stringify({ type: "control_request", request_id: requestId, request })}\n`);
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
respond(requestId, response) {
|
|
255
|
+
this.write(`${JSON.stringify({ type: "control_response", response: { subtype: "success", request_id: requestId, response } })}\n`);
|
|
256
|
+
}
|
|
257
|
+
respondError(requestId, error) {
|
|
258
|
+
this.write(`${JSON.stringify({ type: "control_response", response: { subtype: "error", request_id: requestId, error } })}\n`);
|
|
259
|
+
}
|
|
260
|
+
onExit() {
|
|
261
|
+
this.exited = true;
|
|
262
|
+
for (const controller of this.permissions.values())
|
|
263
|
+
controller.abort();
|
|
264
|
+
const error = new AmaError("agent_exited", `${this.agentId} 进程已退出${stderrHint(this.transport) !== "" ? `:${stderrHint(this.transport)}` : ""}`);
|
|
265
|
+
for (const pending of this.controls.values())
|
|
266
|
+
pending.reject(error);
|
|
267
|
+
this.controls.clear();
|
|
268
|
+
this.failTurn?.(error);
|
|
269
|
+
}
|
|
270
|
+
onLine(line) {
|
|
271
|
+
let msg;
|
|
272
|
+
try {
|
|
273
|
+
msg = JSON.parse(line);
|
|
274
|
+
}
|
|
275
|
+
catch {
|
|
276
|
+
this.deps.log?.("debug", `${this.agentId}: 非 JSON 输出`);
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
switch (msg["type"]) {
|
|
280
|
+
case "control_response":
|
|
281
|
+
return this.onControlResponse(msg["response"]);
|
|
282
|
+
case "control_request":
|
|
283
|
+
void this.onControlRequest(String(msg["request_id"]), (msg["request"] ?? {}));
|
|
284
|
+
return;
|
|
285
|
+
case "control_cancel_request":
|
|
286
|
+
this.permissions.get(String(msg["request_id"]))?.abort();
|
|
287
|
+
return;
|
|
288
|
+
case "system":
|
|
289
|
+
if (msg["subtype"] === "init" && typeof msg["session_id"] === "string")
|
|
290
|
+
this.id = msg["session_id"];
|
|
291
|
+
return;
|
|
292
|
+
case "stream_event":
|
|
293
|
+
// 子 Agent(Task)内部的流式文本不进最终文本
|
|
294
|
+
if (typeof msg["parent_tool_use_id"] === "string")
|
|
295
|
+
return;
|
|
296
|
+
return this.onStreamEvent((msg["event"] ?? {}));
|
|
297
|
+
case "assistant":
|
|
298
|
+
return this.onAssistant((msg["message"] ?? {}), msg["parent_tool_use_id"]);
|
|
299
|
+
case "user":
|
|
300
|
+
return this.onToolResults((msg["message"] ?? {}));
|
|
301
|
+
case "result":
|
|
302
|
+
this.finishTurn?.(msg);
|
|
303
|
+
return;
|
|
304
|
+
default:
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
onControlResponse(response) {
|
|
309
|
+
if (response === undefined)
|
|
310
|
+
return;
|
|
311
|
+
const id = String(response["request_id"]);
|
|
312
|
+
const pending = this.controls.get(id);
|
|
313
|
+
if (pending === undefined)
|
|
314
|
+
return;
|
|
315
|
+
this.controls.delete(id);
|
|
316
|
+
if (response["subtype"] === "error")
|
|
317
|
+
pending.reject(new Error(String(response["error"] ?? "error")));
|
|
318
|
+
else
|
|
319
|
+
pending.resolve((response["response"] ?? {}));
|
|
320
|
+
}
|
|
321
|
+
onStreamEvent(event) {
|
|
322
|
+
if (event["type"] !== "content_block_delta" || this.turn === undefined)
|
|
323
|
+
return;
|
|
324
|
+
const delta = (event["delta"] ?? {});
|
|
325
|
+
if (delta["type"] === "text_delta" && typeof delta["text"] === "string") {
|
|
326
|
+
this.sawPartialText = true;
|
|
327
|
+
this.turn.push({ type: "message_delta", text: delta["text"] });
|
|
328
|
+
}
|
|
329
|
+
else if (delta["type"] === "thinking_delta" && typeof delta["thinking"] === "string") {
|
|
330
|
+
this.turn.push({ type: "thought_delta", text: delta["thinking"] });
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
onAssistant(message, parent) {
|
|
334
|
+
const turn = this.turn;
|
|
335
|
+
if (turn === undefined || !Array.isArray(message["content"]))
|
|
336
|
+
return;
|
|
337
|
+
// 子 Agent(Task)内部的消息不进最终文本
|
|
338
|
+
const nested = typeof parent === "string" && parent !== "";
|
|
339
|
+
for (const block of message["content"]) {
|
|
340
|
+
if (block["type"] === "text" &&
|
|
341
|
+
!nested &&
|
|
342
|
+
!this.sawPartialText &&
|
|
343
|
+
typeof block["text"] === "string")
|
|
344
|
+
turn.push({ type: "message_delta", text: block["text"] });
|
|
345
|
+
else if (block["type"] === "tool_use") {
|
|
346
|
+
const name = String(block["name"] ?? "tool");
|
|
347
|
+
const input = block["input"];
|
|
348
|
+
const locations = claudeToolLocations(input);
|
|
349
|
+
turn.push({
|
|
350
|
+
type: "tool_call",
|
|
351
|
+
id: String(block["id"]),
|
|
352
|
+
title: claudeToolTitle(name, input),
|
|
353
|
+
kind: claudeToolKind(name),
|
|
354
|
+
status: "pending",
|
|
355
|
+
...(locations !== undefined ? { locations } : {}),
|
|
356
|
+
});
|
|
357
|
+
const todos = name === "TodoWrite" ? claudeTodos(input) : undefined;
|
|
358
|
+
if (todos !== undefined)
|
|
359
|
+
turn.push({ type: "plan", entries: todos });
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
// 下一条助手消息的流式文本重新计
|
|
363
|
+
if (!nested)
|
|
364
|
+
this.sawPartialText = false;
|
|
365
|
+
}
|
|
366
|
+
onToolResults(message) {
|
|
367
|
+
const turn = this.turn;
|
|
368
|
+
if (turn === undefined || !Array.isArray(message["content"]))
|
|
369
|
+
return;
|
|
370
|
+
for (const block of message["content"]) {
|
|
371
|
+
if (block["type"] !== "tool_result")
|
|
372
|
+
continue;
|
|
373
|
+
const id = String(block["tool_use_id"]);
|
|
374
|
+
const known = turn.tool(id);
|
|
375
|
+
if (known === undefined)
|
|
376
|
+
continue;
|
|
377
|
+
turn.push({
|
|
378
|
+
type: "tool_call",
|
|
379
|
+
id,
|
|
380
|
+
title: known.title,
|
|
381
|
+
kind: known.kind,
|
|
382
|
+
status: block["is_error"] === true ? "failed" : "completed",
|
|
383
|
+
...(known.locations.length > 0 ? { locations: [...known.locations] } : {}),
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
async onControlRequest(requestId, request) {
|
|
388
|
+
if (request["subtype"] !== "can_use_tool") {
|
|
389
|
+
this.respondError(requestId, `ama does not handle ${String(request["subtype"])}`);
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
392
|
+
const name = String(request["tool_name"] ?? "tool");
|
|
393
|
+
const input = request["input"] ?? {};
|
|
394
|
+
const hooks = this.hooks;
|
|
395
|
+
if (CLAUDE_QUESTION_TOOLS.has(name)) {
|
|
396
|
+
this.turn?.push({
|
|
397
|
+
type: "notice",
|
|
398
|
+
level: "warn",
|
|
399
|
+
text: `${this.agentId} 想向你提问(${name});ama 不代答,已请它把问题写进最终回复`,
|
|
400
|
+
});
|
|
401
|
+
this.respond(requestId, {
|
|
402
|
+
behavior: "deny",
|
|
403
|
+
message: "The coordinator cannot relay interactive questions. Put your questions in your final reply and stop.",
|
|
404
|
+
});
|
|
405
|
+
return;
|
|
406
|
+
}
|
|
407
|
+
if (hooks === undefined || this.interrupted) {
|
|
408
|
+
this.respond(requestId, { behavior: "deny", message: "Cancelled", interrupt: true });
|
|
409
|
+
return;
|
|
410
|
+
}
|
|
411
|
+
const suggestions = sessionScopedSuggestions(request["permission_suggestions"]);
|
|
412
|
+
const controller = new AbortController();
|
|
413
|
+
this.permissions.set(requestId, controller);
|
|
414
|
+
const locations = claudeToolLocations(input);
|
|
415
|
+
try {
|
|
416
|
+
const outcome = await hooks.onPermission({
|
|
417
|
+
toolCall: {
|
|
418
|
+
title: claudeToolTitle(name, input),
|
|
419
|
+
kind: claudeToolKind(name),
|
|
420
|
+
...(locations !== undefined ? { locations } : {}),
|
|
421
|
+
inputSummary: oneLine(JSON.stringify(input), 300),
|
|
422
|
+
},
|
|
423
|
+
options: [
|
|
424
|
+
{ optionId: "allow", kind: "allow_once" },
|
|
425
|
+
...(suggestions.length > 0
|
|
426
|
+
? [{ optionId: "allow_session", kind: "allow_always" }]
|
|
427
|
+
: []),
|
|
428
|
+
{ optionId: "deny", kind: "reject_once" },
|
|
429
|
+
],
|
|
430
|
+
}, controller.signal);
|
|
431
|
+
// Claude 自己取消了这个请求:不再回应
|
|
432
|
+
if (controller.signal.aborted && !this.interrupted && !this.closed)
|
|
433
|
+
return;
|
|
434
|
+
if (outcome.outcome === "cancelled" || controller.signal.aborted) {
|
|
435
|
+
this.respond(requestId, {
|
|
436
|
+
behavior: "deny",
|
|
437
|
+
message: "Cancelled by the user",
|
|
438
|
+
interrupt: true,
|
|
439
|
+
});
|
|
440
|
+
}
|
|
441
|
+
else if (outcome.optionId === "allow" || outcome.optionId === "allow_session") {
|
|
442
|
+
this.respond(requestId, {
|
|
443
|
+
behavior: "allow",
|
|
444
|
+
updatedInput: input,
|
|
445
|
+
...(outcome.optionId === "allow_session" ? { updatedPermissions: suggestions } : {}),
|
|
446
|
+
});
|
|
447
|
+
}
|
|
448
|
+
else {
|
|
449
|
+
this.respond(requestId, { behavior: "deny", message: "The user denied this action" });
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
finally {
|
|
453
|
+
this.permissions.delete(requestId);
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Codex 原生驱动:`codex app-server`(stdio JSON-RPC,docs/wave5-plan.md §5.1,R2 §1.3)。[W5-E]
|
|
3
|
+
*
|
|
4
|
+
* - `initialize{clientInfo}` → `initialized` 通知 → `thread/start`(或 `thread/resume`,带
|
|
5
|
+
* `excludeTurns` 不回放)→ 每回合 `turn/start`,以对应 turn 的 `turn/completed` 结束;
|
|
6
|
+
* 运行中追加用 `turn/steer{expectedTurnId}`;中断 `turn/interrupt`(15 s 看门狗)。
|
|
7
|
+
* - 审批(服务端请求,只交给人):`item/commandExecution/requestApproval`、
|
|
8
|
+
* `item/fileChange/requestApproval` → accept / acceptForSession / decline(回合取消 → cancel;
|
|
9
|
+
* execpolicy 与网络策略修订会改持久配置,不提供);`item/permissions/requestApproval` →
|
|
10
|
+
* 按人的选择授予本回合 / 本会话或不授予;`item/tool/requestUserInput` 与
|
|
11
|
+
* `mcpServer/elicitation/request` 不代答(错误 / cancel,并发提示)。
|
|
12
|
+
* - 用量:`thread/tokenUsage/updated` 的 `total` 差值记本回合(订阅 token,不换算美元)。
|
|
13
|
+
* - 每个会话一个子进程,不连共享 daemon(隔离清楚)。
|
|
14
|
+
*/
|
|
15
|
+
import { type DriverDeps } from "../base.js";
|
|
16
|
+
import type { CatalogCandidate } from "../catalog.js";
|
|
17
|
+
import type { AgentDriver, DriverOpenOptions, DriverProbe, DriverSession } from "../types.js";
|
|
18
|
+
export declare class CodexAppServerDriver implements AgentDriver {
|
|
19
|
+
readonly agentId: string;
|
|
20
|
+
private readonly candidate;
|
|
21
|
+
private readonly deps;
|
|
22
|
+
readonly kind: "codex-app-server";
|
|
23
|
+
constructor(agentId: string, candidate: CatalogCandidate, deps?: DriverDeps);
|
|
24
|
+
probe(): Promise<DriverProbe>;
|
|
25
|
+
open(options: DriverOpenOptions): Promise<DriverSession>;
|
|
26
|
+
}
|