@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,407 @@
|
|
|
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 { AmaError } from "../../errors.js";
|
|
16
|
+
import { AMA_VERSION } from "../../version.js";
|
|
17
|
+
import { armCancelWatchdog, probeCandidate, spawnOf } from "../base.js";
|
|
18
|
+
import { JsonRpcPeer, RpcError } from "../jsonrpc.js";
|
|
19
|
+
import { stderrHint } from "../process.js";
|
|
20
|
+
import { TurnCollector, oneLine } from "../turn.js";
|
|
21
|
+
import { codexDecision, codexPlan, codexPolicy, codexToolEvent, grantedProfile, readTokens, } from "./codex-normalize.js";
|
|
22
|
+
const DECISION_OPTIONS = [
|
|
23
|
+
{ optionId: "accept", kind: "allow_once" },
|
|
24
|
+
{ optionId: "acceptForSession", kind: "allow_always" },
|
|
25
|
+
{ optionId: "decline", kind: "reject_once" },
|
|
26
|
+
];
|
|
27
|
+
function textInput(content) {
|
|
28
|
+
return content.flatMap((b) => b.type === "text" ? [{ type: "text", text: b.text, text_elements: [] }] : []);
|
|
29
|
+
}
|
|
30
|
+
export class CodexAppServerDriver {
|
|
31
|
+
agentId;
|
|
32
|
+
candidate;
|
|
33
|
+
deps;
|
|
34
|
+
kind = "codex-app-server";
|
|
35
|
+
constructor(agentId, candidate, deps = {}) {
|
|
36
|
+
this.agentId = agentId;
|
|
37
|
+
this.candidate = candidate;
|
|
38
|
+
this.deps = deps;
|
|
39
|
+
}
|
|
40
|
+
probe() {
|
|
41
|
+
return probeCandidate(this.candidate, this.deps);
|
|
42
|
+
}
|
|
43
|
+
async open(options) {
|
|
44
|
+
const probed = await probeCandidate(this.candidate, this.deps);
|
|
45
|
+
const transport = spawnOf(this.deps)({
|
|
46
|
+
program: probed.path ?? this.candidate.program,
|
|
47
|
+
args: this.candidate.args,
|
|
48
|
+
cwd: options.cwd,
|
|
49
|
+
env: options.env,
|
|
50
|
+
});
|
|
51
|
+
const session = new CodexSession(this.agentId, transport, this.deps);
|
|
52
|
+
if (probed.warning !== undefined)
|
|
53
|
+
session.notices.push(probed.warning);
|
|
54
|
+
try {
|
|
55
|
+
await session.start(options);
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
await session.close();
|
|
59
|
+
if (error instanceof AmaError)
|
|
60
|
+
throw error;
|
|
61
|
+
throw new AmaError("agent_start_failed", `${this.agentId}:app-server 启动失败(${error.message})${stderrHint(transport) !== "" ? `:${stderrHint(transport)}` : ""}`, { cause: error });
|
|
62
|
+
}
|
|
63
|
+
return session;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
class CodexSession {
|
|
67
|
+
agentId;
|
|
68
|
+
transport;
|
|
69
|
+
deps;
|
|
70
|
+
notices = [];
|
|
71
|
+
peer;
|
|
72
|
+
threadId = "";
|
|
73
|
+
turnId;
|
|
74
|
+
turn;
|
|
75
|
+
hooks;
|
|
76
|
+
finishTurn;
|
|
77
|
+
running;
|
|
78
|
+
permissions = new Set();
|
|
79
|
+
/** fileChange 条目的路径(审批请求只带 itemId)。 */
|
|
80
|
+
itemPaths = new Map();
|
|
81
|
+
messages = new Map();
|
|
82
|
+
tokensTotal;
|
|
83
|
+
tokensAtStart;
|
|
84
|
+
contextWindow;
|
|
85
|
+
closed = false;
|
|
86
|
+
interruptRequested = false;
|
|
87
|
+
constructor(agentId, transport, deps) {
|
|
88
|
+
this.agentId = agentId;
|
|
89
|
+
this.transport = transport;
|
|
90
|
+
this.deps = deps;
|
|
91
|
+
this.peer = new JsonRpcPeer({
|
|
92
|
+
input: transport.stdout,
|
|
93
|
+
output: transport.stdin,
|
|
94
|
+
jsonrpcField: false,
|
|
95
|
+
onRequest: (method, params) => this.onServerRequest(method, (params ?? {})),
|
|
96
|
+
onNotification: (method, params) => this.onNotification(method, (params ?? {})),
|
|
97
|
+
onClose: () => {
|
|
98
|
+
for (const c of this.permissions)
|
|
99
|
+
c.abort();
|
|
100
|
+
},
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
get sessionId() {
|
|
104
|
+
return this.threadId;
|
|
105
|
+
}
|
|
106
|
+
async start(options) {
|
|
107
|
+
const signal = options.signal;
|
|
108
|
+
await this.peer.request("initialize", {
|
|
109
|
+
clientInfo: { name: "ama", title: "ama", version: AMA_VERSION },
|
|
110
|
+
capabilities: { experimentalApi: false, requestAttestation: false },
|
|
111
|
+
}, signal);
|
|
112
|
+
await this.peer.notify("initialized");
|
|
113
|
+
const policy = codexPolicy(options.mode, options.unattended === true);
|
|
114
|
+
const common = {
|
|
115
|
+
cwd: options.cwd,
|
|
116
|
+
...policy,
|
|
117
|
+
...(options.model !== undefined ? { model: options.model } : {}),
|
|
118
|
+
};
|
|
119
|
+
if (options.resume !== undefined) {
|
|
120
|
+
try {
|
|
121
|
+
const resumed = await this.peer.request("thread/resume", { threadId: options.resume, excludeTurns: true, ...common }, signal);
|
|
122
|
+
this.threadId = resumed.thread?.id ?? options.resume;
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
catch (error) {
|
|
126
|
+
if (signal.aborted || !(error instanceof RpcError))
|
|
127
|
+
throw error;
|
|
128
|
+
this.notices.push(`${this.agentId} 找不到会话 ${options.resume},已新开`);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
const started = await this.peer.request("thread/start", common, signal);
|
|
132
|
+
const id = started.thread?.id;
|
|
133
|
+
if (typeof id !== "string" || id === "")
|
|
134
|
+
throw new Error("thread/start 没有返回 thread.id");
|
|
135
|
+
this.threadId = id;
|
|
136
|
+
}
|
|
137
|
+
async prompt(content, hooks) {
|
|
138
|
+
if (this.closed || !this.peer.isOpen)
|
|
139
|
+
throw new AmaError("agent_closed", `${this.agentId} 会话已关闭`);
|
|
140
|
+
if (this.running !== undefined)
|
|
141
|
+
throw new AmaError("busy", `${this.agentId} 正在运行`);
|
|
142
|
+
const turn = new TurnCollector((e) => hooks.onEvent(e));
|
|
143
|
+
for (const text of this.notices.splice(0))
|
|
144
|
+
turn.push({ type: "notice", level: "info", text });
|
|
145
|
+
if (content.some((b) => b.type === "image"))
|
|
146
|
+
turn.push({ type: "notice", level: "warn", text: `${this.agentId} 驱动暂不传图片,已省略` });
|
|
147
|
+
this.turn = turn;
|
|
148
|
+
this.hooks = hooks;
|
|
149
|
+
this.messages.clear();
|
|
150
|
+
this.tokensAtStart = this.tokensTotal;
|
|
151
|
+
this.interruptRequested = false;
|
|
152
|
+
const completed = new Promise((resolve) => (this.finishTurn = resolve));
|
|
153
|
+
const closed = this.peer.closed.then(() => {
|
|
154
|
+
throw new AmaError("agent_exited", `${this.agentId} 进程已退出${stderrHint(this.transport) !== "" ? `:${stderrHint(this.transport)}` : ""}`);
|
|
155
|
+
});
|
|
156
|
+
void closed.catch(() => undefined);
|
|
157
|
+
this.running = (async () => {
|
|
158
|
+
const response = await Promise.race([
|
|
159
|
+
this.peer.request("turn/start", {
|
|
160
|
+
threadId: this.threadId,
|
|
161
|
+
input: textInput(content),
|
|
162
|
+
}),
|
|
163
|
+
closed,
|
|
164
|
+
]);
|
|
165
|
+
if (typeof response.turn?.id === "string")
|
|
166
|
+
this.setTurnId(response.turn.id);
|
|
167
|
+
const done = await Promise.race([completed, closed]);
|
|
168
|
+
return this.complete(done, turn);
|
|
169
|
+
})();
|
|
170
|
+
try {
|
|
171
|
+
return await this.running;
|
|
172
|
+
}
|
|
173
|
+
finally {
|
|
174
|
+
this.running = undefined;
|
|
175
|
+
this.turn = undefined;
|
|
176
|
+
this.hooks = undefined;
|
|
177
|
+
this.turnId = undefined;
|
|
178
|
+
this.finishTurn = undefined;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
async steer(content) {
|
|
182
|
+
if (this.turnId === undefined)
|
|
183
|
+
throw new AmaError("not_running", `${this.agentId} 没有进行中的回合`);
|
|
184
|
+
await this.peer.request("turn/steer", {
|
|
185
|
+
threadId: this.threadId,
|
|
186
|
+
input: textInput(content),
|
|
187
|
+
expectedTurnId: this.turnId,
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
async cancel() {
|
|
191
|
+
const running = this.running;
|
|
192
|
+
if (running === undefined || this.closed)
|
|
193
|
+
return;
|
|
194
|
+
for (const c of this.permissions)
|
|
195
|
+
c.abort();
|
|
196
|
+
this.interruptRequested = true;
|
|
197
|
+
if (this.turnId !== undefined)
|
|
198
|
+
this.sendInterrupt(this.turnId);
|
|
199
|
+
armCancelWatchdog(this.transport, running.catch(() => undefined), this.deps);
|
|
200
|
+
}
|
|
201
|
+
async close() {
|
|
202
|
+
if (this.closed)
|
|
203
|
+
return;
|
|
204
|
+
this.closed = true;
|
|
205
|
+
for (const c of this.permissions)
|
|
206
|
+
c.abort();
|
|
207
|
+
this.peer.close();
|
|
208
|
+
await this.transport.terminate();
|
|
209
|
+
}
|
|
210
|
+
/** turn id 可能先从通知 / 服务端请求里知道(早于 turn/start 的响应被处理)。 */
|
|
211
|
+
setTurnId(id) {
|
|
212
|
+
if (this.running === undefined || this.turnId !== undefined)
|
|
213
|
+
return;
|
|
214
|
+
this.turnId = id;
|
|
215
|
+
if (this.interruptRequested)
|
|
216
|
+
this.sendInterrupt(id);
|
|
217
|
+
}
|
|
218
|
+
sendInterrupt(turnId) {
|
|
219
|
+
void this.peer
|
|
220
|
+
.request("turn/interrupt", { threadId: this.threadId, turnId })
|
|
221
|
+
.catch(() => undefined);
|
|
222
|
+
}
|
|
223
|
+
complete(turnInfo, turn) {
|
|
224
|
+
const start = this.tokensAtStart;
|
|
225
|
+
const end = this.tokensTotal;
|
|
226
|
+
if (end !== undefined) {
|
|
227
|
+
turn.push({
|
|
228
|
+
type: "usage",
|
|
229
|
+
input: end.inputTokens - (start?.inputTokens ?? 0),
|
|
230
|
+
output: end.outputTokens - (start?.outputTokens ?? 0),
|
|
231
|
+
cacheRead: end.cachedInputTokens - (start?.cachedInputTokens ?? 0),
|
|
232
|
+
...(this.contextWindow !== undefined ? { contextWindow: this.contextWindow } : {}),
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
const last = [...this.messages.values()].at(-1);
|
|
236
|
+
if (last !== undefined)
|
|
237
|
+
turn.setFinalText(last);
|
|
238
|
+
const status = turnInfo["status"];
|
|
239
|
+
if (status === "interrupted")
|
|
240
|
+
return turn.result("cancelled");
|
|
241
|
+
if (status === "failed") {
|
|
242
|
+
const error = (turnInfo["error"] ?? {});
|
|
243
|
+
throw new AmaError("agent_failed", `${this.agentId} 回合失败:${oneLine(String(error["message"] ?? "unknown"), 300)}`);
|
|
244
|
+
}
|
|
245
|
+
return turn.result("end_turn");
|
|
246
|
+
}
|
|
247
|
+
onNotification(method, params) {
|
|
248
|
+
const turn = this.turn;
|
|
249
|
+
switch (method) {
|
|
250
|
+
case "thread/tokenUsage/updated": {
|
|
251
|
+
const usage = (params["tokenUsage"] ?? {});
|
|
252
|
+
const total = readTokens(usage["total"]);
|
|
253
|
+
if (total !== undefined)
|
|
254
|
+
this.tokensTotal = total;
|
|
255
|
+
if (typeof usage["modelContextWindow"] === "number")
|
|
256
|
+
this.contextWindow = usage["modelContextWindow"];
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
case "turn/started": {
|
|
260
|
+
const id = (params["turn"] ?? {})["id"];
|
|
261
|
+
if (typeof id === "string")
|
|
262
|
+
this.setTurnId(id);
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
case "turn/completed": {
|
|
266
|
+
const info = (params["turn"] ?? {});
|
|
267
|
+
if (this.turnId === undefined || info["id"] === this.turnId)
|
|
268
|
+
this.finishTurn?.(info);
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
271
|
+
default:
|
|
272
|
+
break;
|
|
273
|
+
}
|
|
274
|
+
if (turn === undefined)
|
|
275
|
+
return;
|
|
276
|
+
switch (method) {
|
|
277
|
+
case "item/agentMessage/delta": {
|
|
278
|
+
const delta = String(params["delta"] ?? "");
|
|
279
|
+
const id = String(params["itemId"] ?? "");
|
|
280
|
+
this.messages.set(id, (this.messages.get(id) ?? "") + delta);
|
|
281
|
+
turn.push({ type: "message_delta", text: delta });
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
case "item/reasoning/summaryTextDelta":
|
|
285
|
+
case "item/reasoning/textDelta":
|
|
286
|
+
turn.push({ type: "thought_delta", text: String(params["delta"] ?? "") });
|
|
287
|
+
return;
|
|
288
|
+
case "item/started":
|
|
289
|
+
case "item/completed": {
|
|
290
|
+
const item = (params["item"] ?? {});
|
|
291
|
+
if (item["type"] === "agentMessage" && method === "item/completed") {
|
|
292
|
+
this.messages.set(String(item["id"]), String(item["text"] ?? ""));
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
const event = codexToolEvent(item, method === "item/started" ? "started" : "completed");
|
|
296
|
+
if (event === undefined)
|
|
297
|
+
return;
|
|
298
|
+
if (event.locations !== undefined)
|
|
299
|
+
this.itemPaths.set(event.id, event.locations);
|
|
300
|
+
turn.push(event);
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
case "turn/plan/updated": {
|
|
304
|
+
const plan = codexPlan(params);
|
|
305
|
+
if (plan !== undefined)
|
|
306
|
+
turn.push(plan);
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
case "error": {
|
|
310
|
+
const error = (params["error"] ?? {});
|
|
311
|
+
turn.push({
|
|
312
|
+
type: "notice",
|
|
313
|
+
level: "warn",
|
|
314
|
+
text: `${this.agentId}:${oneLine(String(error["message"] ?? "error"), 200)}${params["willRetry"] === true ? "(重试中)" : ""}`,
|
|
315
|
+
});
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
default:
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
async ask(request) {
|
|
323
|
+
const hooks = this.hooks;
|
|
324
|
+
if (hooks === undefined || this.closed)
|
|
325
|
+
return undefined;
|
|
326
|
+
const controller = new AbortController();
|
|
327
|
+
this.permissions.add(controller);
|
|
328
|
+
try {
|
|
329
|
+
const outcome = await hooks.onPermission(request, controller.signal);
|
|
330
|
+
return outcome.outcome === "selected" && !controller.signal.aborted
|
|
331
|
+
? outcome.optionId
|
|
332
|
+
: undefined;
|
|
333
|
+
}
|
|
334
|
+
finally {
|
|
335
|
+
this.permissions.delete(controller);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
async onServerRequest(method, params) {
|
|
339
|
+
if (typeof params["turnId"] === "string")
|
|
340
|
+
this.setTurnId(params["turnId"]);
|
|
341
|
+
switch (method) {
|
|
342
|
+
case "item/commandExecution/requestApproval": {
|
|
343
|
+
const command = String(params["command"] ?? "");
|
|
344
|
+
const reason = typeof params["reason"] === "string" ? ` — ${params["reason"]}` : "";
|
|
345
|
+
const cwd = typeof params["cwd"] === "string" ? [params["cwd"]] : undefined;
|
|
346
|
+
const answer = await this.ask({
|
|
347
|
+
toolCall: {
|
|
348
|
+
title: `$ ${oneLine(command, 100)}`,
|
|
349
|
+
kind: "execute",
|
|
350
|
+
...(cwd !== undefined ? { locations: cwd } : {}),
|
|
351
|
+
inputSummary: oneLine(`${command}${reason}`, 300),
|
|
352
|
+
},
|
|
353
|
+
options: DECISION_OPTIONS,
|
|
354
|
+
});
|
|
355
|
+
return { decision: codexDecision(answer) };
|
|
356
|
+
}
|
|
357
|
+
case "item/fileChange/requestApproval": {
|
|
358
|
+
const paths = this.itemPaths.get(String(params["itemId"] ?? "")) ?? [];
|
|
359
|
+
const reason = typeof params["reason"] === "string" ? params["reason"] : "";
|
|
360
|
+
const answer = await this.ask({
|
|
361
|
+
toolCall: {
|
|
362
|
+
title: paths.length > 0 ? `edit ${paths.join(", ")}` : "edit files",
|
|
363
|
+
kind: "edit",
|
|
364
|
+
...(paths.length > 0 ? { locations: paths } : {}),
|
|
365
|
+
...(reason !== "" ? { inputSummary: oneLine(reason, 300) } : {}),
|
|
366
|
+
},
|
|
367
|
+
options: DECISION_OPTIONS,
|
|
368
|
+
});
|
|
369
|
+
return { decision: codexDecision(answer) };
|
|
370
|
+
}
|
|
371
|
+
case "item/permissions/requestApproval": {
|
|
372
|
+
const reason = typeof params["reason"] === "string" ? params["reason"] : "";
|
|
373
|
+
const answer = await this.ask({
|
|
374
|
+
toolCall: {
|
|
375
|
+
title: "request additional permissions",
|
|
376
|
+
kind: "other",
|
|
377
|
+
inputSummary: oneLine(`${JSON.stringify(params["permissions"] ?? {})} ${reason}`, 300),
|
|
378
|
+
},
|
|
379
|
+
options: [
|
|
380
|
+
{ optionId: "turn", kind: "allow_once" },
|
|
381
|
+
{ optionId: "session", kind: "allow_always" },
|
|
382
|
+
{ optionId: "deny", kind: "reject_once" },
|
|
383
|
+
],
|
|
384
|
+
});
|
|
385
|
+
if (answer === "turn" || answer === "session")
|
|
386
|
+
return { permissions: grantedProfile(params["permissions"]), scope: answer };
|
|
387
|
+
return { permissions: {}, scope: "turn" };
|
|
388
|
+
}
|
|
389
|
+
case "item/tool/requestUserInput":
|
|
390
|
+
this.turn?.push({
|
|
391
|
+
type: "notice",
|
|
392
|
+
level: "warn",
|
|
393
|
+
text: `${this.agentId} 想向你提问;ama 不代答,请让它把问题写进最终回复`,
|
|
394
|
+
});
|
|
395
|
+
throw new RpcError(-32601, "The coordinator cannot relay interactive questions");
|
|
396
|
+
case "mcpServer/elicitation/request":
|
|
397
|
+
this.turn?.push({
|
|
398
|
+
type: "notice",
|
|
399
|
+
level: "warn",
|
|
400
|
+
text: `${this.agentId} 的 MCP 服务器请求输入;ama 不代答,已取消`,
|
|
401
|
+
});
|
|
402
|
+
return { action: "cancel", content: null, _meta: null };
|
|
403
|
+
default:
|
|
404
|
+
throw new RpcError(-32601, `ama does not handle ${method}`);
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Codex app-server(0.160.x,`[experimental]`)↔ ama 的映射(docs/wave5-plan.md §5.1 normalize,
|
|
3
|
+
* R2 §1.3)。[W5-E]
|
|
4
|
+
*
|
|
5
|
+
* 只依赖 `test/fixtures/drivers/codex-schema/shapes.json` 锁住的方法与字段(12 个方法 + 5 类审批
|
|
6
|
+
* 请求);线上不写 `"jsonrpc"` 字段。
|
|
7
|
+
*/
|
|
8
|
+
import type { PermissionMode } from "../../permissions/types.js";
|
|
9
|
+
import type { DriverEvent } from "../types.js";
|
|
10
|
+
export type CodexApprovalPolicy = "untrusted" | "on-request" | "never";
|
|
11
|
+
export type CodexSandbox = "read-only" | "workspace-write" | "danger-full-access";
|
|
12
|
+
/**
|
|
13
|
+
* ama 模式 → Codex `approvalPolicy` + `sandbox`。从不给 `danger-full-access`;
|
|
14
|
+
* 无人值守一律 `never`(不发审批请求,越权的操作由沙箱拒绝后交回模型)。
|
|
15
|
+
*/
|
|
16
|
+
export declare function codexPolicy(mode: PermissionMode, unattended: boolean): {
|
|
17
|
+
approvalPolicy: CodexApprovalPolicy;
|
|
18
|
+
sandbox: CodexSandbox;
|
|
19
|
+
};
|
|
20
|
+
type Json = Record<string, unknown>;
|
|
21
|
+
/** ThreadItem → tool_call(非工具类条目返回 undefined)。 */
|
|
22
|
+
export declare function codexToolEvent(item: Json, phase: "started" | "completed"): Extract<DriverEvent, {
|
|
23
|
+
type: "tool_call";
|
|
24
|
+
}> | undefined;
|
|
25
|
+
/** turn/plan/updated → plan。 */
|
|
26
|
+
export declare function codexPlan(params: Json): DriverEvent | undefined;
|
|
27
|
+
export interface CodexTokens {
|
|
28
|
+
totalTokens: number;
|
|
29
|
+
inputTokens: number;
|
|
30
|
+
cachedInputTokens: number;
|
|
31
|
+
outputTokens: number;
|
|
32
|
+
}
|
|
33
|
+
export declare function readTokens(value: unknown): CodexTokens | undefined;
|
|
34
|
+
/** 审批决定(ACP 词汇 → Codex);execpolicy 修订是持久配置变更,不提供。 */
|
|
35
|
+
export declare function codexDecision(optionId: string | undefined): "accept" | "acceptForSession" | "decline" | "cancel";
|
|
36
|
+
/** 去掉 null 字段(`RequestPermissionProfile` → `GrantedPermissionProfile`)。 */
|
|
37
|
+
export declare function grantedProfile(permissions: unknown): Json;
|
|
38
|
+
export {};
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Codex app-server(0.160.x,`[experimental]`)↔ ama 的映射(docs/wave5-plan.md §5.1 normalize,
|
|
3
|
+
* R2 §1.3)。[W5-E]
|
|
4
|
+
*
|
|
5
|
+
* 只依赖 `test/fixtures/drivers/codex-schema/shapes.json` 锁住的方法与字段(12 个方法 + 5 类审批
|
|
6
|
+
* 请求);线上不写 `"jsonrpc"` 字段。
|
|
7
|
+
*/
|
|
8
|
+
import { oneLine } from "../turn.js";
|
|
9
|
+
/**
|
|
10
|
+
* ama 模式 → Codex `approvalPolicy` + `sandbox`。从不给 `danger-full-access`;
|
|
11
|
+
* 无人值守一律 `never`(不发审批请求,越权的操作由沙箱拒绝后交回模型)。
|
|
12
|
+
*/
|
|
13
|
+
export function codexPolicy(mode, unattended) {
|
|
14
|
+
const base = (() => {
|
|
15
|
+
switch (mode) {
|
|
16
|
+
case "plan":
|
|
17
|
+
case "allowlist":
|
|
18
|
+
return { approvalPolicy: "never", sandbox: "read-only" };
|
|
19
|
+
case "default":
|
|
20
|
+
// 写文件 / 越过只读沙箱都要先问人(≈ ama default 的「写与执行要问」)
|
|
21
|
+
return { approvalPolicy: "on-request", sandbox: "read-only" };
|
|
22
|
+
case "auto-edit":
|
|
23
|
+
return { approvalPolicy: "untrusted", sandbox: "workspace-write" };
|
|
24
|
+
case "auto":
|
|
25
|
+
return { approvalPolicy: "on-request", sandbox: "workspace-write" };
|
|
26
|
+
case "full-auto":
|
|
27
|
+
return { approvalPolicy: "never", sandbox: "workspace-write" };
|
|
28
|
+
}
|
|
29
|
+
})();
|
|
30
|
+
return unattended ? { ...base, approvalPolicy: "never" } : base;
|
|
31
|
+
}
|
|
32
|
+
/** ThreadItem → tool_call(非工具类条目返回 undefined)。 */
|
|
33
|
+
export function codexToolEvent(item, phase) {
|
|
34
|
+
const id = String(item["id"] ?? "");
|
|
35
|
+
const type = item["type"];
|
|
36
|
+
let kind;
|
|
37
|
+
let title;
|
|
38
|
+
let locations;
|
|
39
|
+
switch (type) {
|
|
40
|
+
case "commandExecution":
|
|
41
|
+
kind = "execute";
|
|
42
|
+
title = `$ ${oneLine(String(item["command"] ?? ""), 100)}`;
|
|
43
|
+
break;
|
|
44
|
+
case "fileChange": {
|
|
45
|
+
kind = "edit";
|
|
46
|
+
const changes = Array.isArray(item["changes"]) ? item["changes"] : [];
|
|
47
|
+
locations = changes.map((c) => String(c["path"] ?? "")).filter((p) => p !== "");
|
|
48
|
+
title = locations.length > 0 ? `edit ${locations.join(", ")}` : "edit";
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
case "mcpToolCall":
|
|
52
|
+
kind = "other";
|
|
53
|
+
title = `${String(item["server"] ?? "mcp")}.${String(item["tool"] ?? "tool")}`;
|
|
54
|
+
break;
|
|
55
|
+
case "dynamicToolCall":
|
|
56
|
+
kind = "other";
|
|
57
|
+
title = String(item["tool"] ?? "tool");
|
|
58
|
+
break;
|
|
59
|
+
case "webSearch":
|
|
60
|
+
kind = "fetch";
|
|
61
|
+
title = `search ${oneLine(String(item["query"] ?? ""), 80)}`;
|
|
62
|
+
break;
|
|
63
|
+
default:
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
const status = String(item["status"] ?? "");
|
|
67
|
+
const failed = status === "failed" || status === "declined";
|
|
68
|
+
return {
|
|
69
|
+
type: "tool_call",
|
|
70
|
+
id,
|
|
71
|
+
title,
|
|
72
|
+
kind,
|
|
73
|
+
status: phase === "started" ? "in_progress" : failed ? "failed" : "completed",
|
|
74
|
+
...(locations !== undefined && locations.length > 0 ? { locations } : {}),
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
/** turn/plan/updated → plan。 */
|
|
78
|
+
export function codexPlan(params) {
|
|
79
|
+
const plan = params["plan"];
|
|
80
|
+
if (!Array.isArray(plan))
|
|
81
|
+
return undefined;
|
|
82
|
+
return {
|
|
83
|
+
type: "plan",
|
|
84
|
+
entries: plan.map((s) => ({
|
|
85
|
+
content: String(s["step"] ?? ""),
|
|
86
|
+
status: String(s["status"] ?? "pending"),
|
|
87
|
+
})),
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
export function readTokens(value) {
|
|
91
|
+
if (value === null || typeof value !== "object")
|
|
92
|
+
return undefined;
|
|
93
|
+
const v = value;
|
|
94
|
+
const num = (k) => (typeof v[k] === "number" ? v[k] : 0);
|
|
95
|
+
return {
|
|
96
|
+
totalTokens: num("totalTokens"),
|
|
97
|
+
inputTokens: num("inputTokens"),
|
|
98
|
+
cachedInputTokens: num("cachedInputTokens"),
|
|
99
|
+
outputTokens: num("outputTokens"),
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
/** 审批决定(ACP 词汇 → Codex);execpolicy 修订是持久配置变更,不提供。 */
|
|
103
|
+
export function codexDecision(optionId) {
|
|
104
|
+
switch (optionId) {
|
|
105
|
+
case "accept":
|
|
106
|
+
return "accept";
|
|
107
|
+
case "acceptForSession":
|
|
108
|
+
return "acceptForSession";
|
|
109
|
+
case "decline":
|
|
110
|
+
return "decline";
|
|
111
|
+
default:
|
|
112
|
+
return "cancel";
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
/** 去掉 null 字段(`RequestPermissionProfile` → `GrantedPermissionProfile`)。 */
|
|
116
|
+
export function grantedProfile(permissions) {
|
|
117
|
+
if (permissions === null || typeof permissions !== "object")
|
|
118
|
+
return {};
|
|
119
|
+
const out = {};
|
|
120
|
+
for (const [k, v] of Object.entries(permissions))
|
|
121
|
+
if (v !== null && v !== undefined)
|
|
122
|
+
out[k] = v;
|
|
123
|
+
return out;
|
|
124
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 一次性打印模式兜底(docs/wave5-plan.md §5.1 oneshot.ts)。[W5-E]
|
|
3
|
+
*
|
|
4
|
+
* `claude -p --output-format json`、`codex exec --json`、`gemini -p --output-format stream-json`:
|
|
5
|
+
* **不能审批**(能力 `permissions: "none"`),所以只在只读任务下用——open 时模式不是
|
|
6
|
+
* plan / allowlist 直接拒绝;子进程一律以只读方式启动(Claude `--permission-mode plan
|
|
7
|
+
* --permission-prompts none`,Codex `sandbox_mode="read-only"` + `approval_policy="never"`,
|
|
8
|
+
* Gemini `--approval-mode default`,无头时需要批准的工具不可用;未实测)。每回合起一个进程,提示从 stdin 给(Gemini 走 `-p` 参数);
|
|
9
|
+
* 续聊用各 CLI 自己的 resume。中断 = 结束进程树。
|
|
10
|
+
*/
|
|
11
|
+
import { type DriverDeps } from "../base.js";
|
|
12
|
+
import type { CatalogCandidate } from "../catalog.js";
|
|
13
|
+
import type { AgentDriver, DriverOpenOptions, DriverProbe, DriverSession } from "../types.js";
|
|
14
|
+
type Dialect = NonNullable<CatalogCandidate["oneshot"]>;
|
|
15
|
+
export declare function oneshotArgs(dialect: Dialect, options: Pick<DriverOpenOptions, "model" | "budgetUsd">, session: {
|
|
16
|
+
id: string;
|
|
17
|
+
resume: boolean;
|
|
18
|
+
}, prompt: string): string[];
|
|
19
|
+
export declare class OneshotDriver implements AgentDriver {
|
|
20
|
+
readonly agentId: string;
|
|
21
|
+
private readonly candidate;
|
|
22
|
+
private readonly deps;
|
|
23
|
+
readonly kind: "oneshot";
|
|
24
|
+
constructor(agentId: string, candidate: CatalogCandidate, deps?: DriverDeps);
|
|
25
|
+
probe(): Promise<DriverProbe>;
|
|
26
|
+
open(options: DriverOpenOptions): Promise<DriverSession>;
|
|
27
|
+
}
|
|
28
|
+
export {};
|