@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
|
@@ -7,24 +7,34 @@
|
|
|
7
7
|
* `tool_execution_end` 按完成顺序发;toolResult 消息按原序发 `message_start/end`(入转录)。
|
|
8
8
|
* `terminate` 要整批都为真才提前结束。`stopReason: "length"` 且有工具调用 → 整批判失败不执行。
|
|
9
9
|
* abort:未开始的调用直接给 `aborted by user` 错误结果;执行中的工具收到 signal,超过宽限期仍未结束
|
|
10
|
-
* 则不再等待、记 `aborted by user`。结果超 `maxToolResultChars` 截断并把全文写到 `outputDir
|
|
10
|
+
* 则不再等待、记 `aborted by user`。结果超 `maxToolResultChars` 截断并把全文写到 `outputDir`:
|
|
11
|
+
* [W5-H2] 保留头 70% + 尾 30%,中间 `[… N 字符已省略,全文 <path>]`(tools/truncate.ts)。
|
|
11
12
|
*
|
|
12
13
|
* 嵌套调用(`ToolContext.tools.executeTool`,codemode 脚本里的 `tools.*`)走 `runSingleToolCall`:
|
|
13
14
|
* 同一套校验与门禁,按**全部未禁用工具**查找(codemode only 模式下活动集只有 codemode),
|
|
14
15
|
* 发带 `parentToolCallId` 的 `tool_execution_start / update / end`(不入转录),门禁与 PostToolUse
|
|
15
16
|
* 拿到 `parent`(Hook 输入的 `viaCodemode / parentToolCallId`);结果给脚本而不是模型,截断上限放宽到
|
|
16
17
|
* `NESTED_MAX_RESULT_CHARS`。
|
|
18
|
+
*
|
|
19
|
+
* [W5-H2] 重复调用检测(loop-guard.ts)只看顶层调用:同 run 同名同参第 3、4 次在结果末尾追加提醒,
|
|
20
|
+
* 第 5 次不执行、给错误结果,整批返回 `stop: "repeated_tool_call"`(循环据此结束 run)。
|
|
17
21
|
*/
|
|
18
22
|
import { mkdirSync, writeFileSync } from "node:fs";
|
|
19
23
|
import { join } from "node:path";
|
|
24
|
+
import { REPEATED_TOOL_CALL, guardFor, loopReminderText, loopStopText, } from "./loop-guard.js";
|
|
20
25
|
import { formatSchemaErrors, validateSchema } from "./schema.js";
|
|
21
26
|
import { CODEMODE_TOOL } from "../tools/presets.js";
|
|
22
27
|
import { executionModeOf } from "../tools/registry.js";
|
|
28
|
+
import { truncateMiddle } from "../tools/truncate.js";
|
|
23
29
|
export const ABORTED_TOOL_TEXT = "aborted by user";
|
|
24
30
|
export const DEFAULT_MAX_TOOL_RESULT_CHARS = 30_000;
|
|
25
31
|
export const DEFAULT_ABORT_GRACE_MS = 3000;
|
|
26
32
|
/** 嵌套调用结果的截断上限(给脚本,不进上下文)。 */
|
|
27
33
|
export const NESTED_MAX_RESULT_CHARS = 1024 * 1024;
|
|
34
|
+
/** 门禁给出的 auto 判定,随 tool_execution_end 发出(按调用对象记,调用结束后随之回收)。 */
|
|
35
|
+
const autoDecisions = new WeakMap();
|
|
36
|
+
/** 门禁拒绝(gate.block)而没有执行的调用:tool_execution_end 带 `denied`。 */
|
|
37
|
+
const deniedCalls = new WeakSet();
|
|
28
38
|
export function errorResult(text) {
|
|
29
39
|
return { content: text, isError: true };
|
|
30
40
|
}
|
|
@@ -80,9 +90,12 @@ async function prepare(call, assistant, options, signal, parent) {
|
|
|
80
90
|
try {
|
|
81
91
|
const gateContext = parent === undefined ? { signal, assistant, tool } : { signal, assistant, tool, parent };
|
|
82
92
|
const gate = await options.beforeToolCall(call, gateContext);
|
|
93
|
+
if (gate.autoDecision !== undefined)
|
|
94
|
+
autoDecisions.set(call, gate.autoDecision);
|
|
83
95
|
if (signal.aborted)
|
|
84
96
|
return { kind: "immediate", call, result: errorResult(ABORTED_TOOL_TEXT) };
|
|
85
97
|
if (gate.block === true) {
|
|
98
|
+
deniedCalls.add(call);
|
|
86
99
|
return {
|
|
87
100
|
kind: "immediate",
|
|
88
101
|
call,
|
|
@@ -132,10 +145,10 @@ function truncateResult(call, result, options, nested = false) {
|
|
|
132
145
|
const images = typeof result.content === "string"
|
|
133
146
|
? []
|
|
134
147
|
: result.content.filter((block) => block.type === "image");
|
|
135
|
-
const
|
|
148
|
+
const { content } = truncateMiddle(text, limit, (omitted) => `[… ${omitted} 字符已省略(输出过长已截断:共 ${text.length} 字符,${where})]`);
|
|
136
149
|
return {
|
|
137
150
|
...result,
|
|
138
|
-
content: images.length > 0 ? [{ type: "text", text:
|
|
151
|
+
content: images.length > 0 ? [{ type: "text", text: content }, ...images] : content,
|
|
139
152
|
};
|
|
140
153
|
}
|
|
141
154
|
async function execute(prepared, options, signal, emit, parent) {
|
|
@@ -193,13 +206,19 @@ async function execute(prepared, options, signal, emit, parent) {
|
|
|
193
206
|
return truncateResult(call, result, options, parent !== undefined);
|
|
194
207
|
}
|
|
195
208
|
async function emitEnd(call, result, emit) {
|
|
196
|
-
|
|
209
|
+
const event = {
|
|
197
210
|
type: "tool_execution_end",
|
|
198
211
|
toolCallId: call.id,
|
|
199
212
|
toolName: call.name,
|
|
200
213
|
result,
|
|
201
214
|
isError: result.isError === true,
|
|
202
|
-
}
|
|
215
|
+
};
|
|
216
|
+
const auto = autoDecisions.get(call);
|
|
217
|
+
if (auto !== undefined)
|
|
218
|
+
event.autoDecision = auto;
|
|
219
|
+
if (deniedCalls.has(call))
|
|
220
|
+
event.denied = true;
|
|
221
|
+
await emit(event);
|
|
203
222
|
}
|
|
204
223
|
async function emitResultMessages(finalized, emit) {
|
|
205
224
|
const messages = [];
|
|
@@ -214,6 +233,9 @@ async function emitResultMessages(finalized, emit) {
|
|
|
214
233
|
export async function runToolBatch(assistant, options, signal, emit) {
|
|
215
234
|
const calls = toolCallsOf(assistant);
|
|
216
235
|
const preparedList = [];
|
|
236
|
+
const guard = guardFor(signal);
|
|
237
|
+
const verdicts = new Map();
|
|
238
|
+
let stop;
|
|
217
239
|
for (const call of calls) {
|
|
218
240
|
await emit({
|
|
219
241
|
type: "tool_execution_start",
|
|
@@ -221,6 +243,15 @@ export async function runToolBatch(assistant, options, signal, emit) {
|
|
|
221
243
|
toolName: call.name,
|
|
222
244
|
args: call.arguments,
|
|
223
245
|
});
|
|
246
|
+
const verdict = guard.observe(call, options.getTool(call.name));
|
|
247
|
+
verdicts.set(call, verdict);
|
|
248
|
+
if (verdict === "stop") {
|
|
249
|
+
stop = REPEATED_TOOL_CALL;
|
|
250
|
+
const result = errorResult(loopStopText(call.name, guard.count(call)));
|
|
251
|
+
await emitEnd(call, result, emit);
|
|
252
|
+
preparedList.push({ kind: "immediate", call, result });
|
|
253
|
+
continue;
|
|
254
|
+
}
|
|
224
255
|
const prepared = await prepare(call, assistant, options, signal);
|
|
225
256
|
if (prepared.kind === "immediate")
|
|
226
257
|
await emitEnd(call, prepared.result, emit);
|
|
@@ -249,9 +280,44 @@ export async function runToolBatch(assistant, options, signal, emit) {
|
|
|
249
280
|
}));
|
|
250
281
|
finalized.push(...results);
|
|
251
282
|
}
|
|
283
|
+
appendBatchSuffix(finalized, signal, stop);
|
|
284
|
+
for (const item of finalized) {
|
|
285
|
+
if (verdicts.get(item.call) === "remind")
|
|
286
|
+
item.result = withReminder(item.result, loopReminderText(item.call.name, guard.count(item.call)));
|
|
287
|
+
}
|
|
252
288
|
const messages = await emitResultMessages(finalized, emit);
|
|
253
289
|
const terminate = finalized.length > 0 && finalized.every(({ result }) => result.terminate === true);
|
|
254
|
-
return { messages, terminate };
|
|
290
|
+
return stop === undefined ? { messages, terminate } : { messages, terminate, stop };
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* [W5-H2] 本 run 的「批次尾部提醒」来源(reminders.ts 在 agent_start 时以 run 的 signal 登记):
|
|
294
|
+
* 每个工具批次结束时取一次,非空就追加在本批**最后一条**结果末尾——run 进行中的提醒(todo 复述、
|
|
295
|
+
* 文件改动、上下文用量、预算、后台命令退出)由此进上下文,只改新结果、不碰前缀。
|
|
296
|
+
*/
|
|
297
|
+
const batchSuffixSources = new WeakMap();
|
|
298
|
+
export function setBatchSuffixSource(signal, source) {
|
|
299
|
+
batchSuffixSources.set(signal, source);
|
|
300
|
+
}
|
|
301
|
+
function appendBatchSuffix(finalized, signal, stop) {
|
|
302
|
+
const last = finalized.at(-1);
|
|
303
|
+
if (last === undefined || stop !== undefined || signal.aborted)
|
|
304
|
+
return;
|
|
305
|
+
let suffix;
|
|
306
|
+
try {
|
|
307
|
+
suffix = batchSuffixSources.get(signal)?.();
|
|
308
|
+
}
|
|
309
|
+
catch {
|
|
310
|
+
suffix = undefined;
|
|
311
|
+
}
|
|
312
|
+
if (suffix !== undefined && suffix !== "")
|
|
313
|
+
last.result = withReminder(last.result, suffix);
|
|
314
|
+
}
|
|
315
|
+
/** 在结果末尾追加一段文本(字符串结果拼接,块数组追加 text 块)。 */
|
|
316
|
+
function withReminder(result, text) {
|
|
317
|
+
const content = typeof result.content === "string"
|
|
318
|
+
? `${result.content}\n\n${text}`
|
|
319
|
+
: [...result.content, { type: "text", text }];
|
|
320
|
+
return { ...result, content };
|
|
255
321
|
}
|
|
256
322
|
/** `length` 截断的助手消息:整批判失败,不执行。 */
|
|
257
323
|
export async function failTruncatedBatch(assistant, emit) {
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 第五波会话契约(docs/wave5-plan.md §1.3、§5.4、§6.3、§6.5、§7.5、§8.3;[W5-C0])。
|
|
3
|
+
*
|
|
4
|
+
* 这里放新增事件的载荷与 `SessionStats` 的扩展形状,由 agent/types.ts 并入 `SessionEvent` /
|
|
5
|
+
* `SessionStats` 并再导出(agent/types.ts 已接近 600 行)。全部是新增事件与可选字段:
|
|
6
|
+
* `RpcEvent` 由 `SessionEvent` 派生,新事件自动上线;`RPC_PROTOCOL_VERSION` 不变。
|
|
7
|
+
* 实现归各批次:遥测 W5-A、子 Agent W5-G(外部 runner W5-E)、计划 / todo W5-F、
|
|
8
|
+
* 预算 / 回退 / 后台命令 W5-H2。
|
|
9
|
+
*/
|
|
10
|
+
import type { ModelRef, Usage } from "../ai/types.js";
|
|
11
|
+
import type { PermissionMode } from "../permissions/types.js";
|
|
12
|
+
import type { SubagentStatus } from "../tools/types.js";
|
|
13
|
+
export type { SubagentStatus } from "../tools/types.js";
|
|
14
|
+
/** 一次 `purpose: "turn"` 请求的速率数据。 */
|
|
15
|
+
export interface RequestTelemetry {
|
|
16
|
+
requestAt: number;
|
|
17
|
+
/** 首个 text_delta / thinking_delta / toolcall_start。 */
|
|
18
|
+
firstTokenAt?: number;
|
|
19
|
+
doneAt?: number;
|
|
20
|
+
/** usage.output(含 reasoning);流式期间用增量字符估算。 */
|
|
21
|
+
outputTokens?: number;
|
|
22
|
+
/** outputTokens / (doneAt − firstTokenAt)。 */
|
|
23
|
+
tps?: number;
|
|
24
|
+
ttftMs?: number;
|
|
25
|
+
}
|
|
26
|
+
export interface SessionTelemetry {
|
|
27
|
+
/** 最近一次 turn 请求。 */
|
|
28
|
+
last?: RequestTelemetry;
|
|
29
|
+
/** 流式中(2 s 滑动窗口)。 */
|
|
30
|
+
live?: {
|
|
31
|
+
tps: number;
|
|
32
|
+
outputTokens: number;
|
|
33
|
+
elapsedMs: number;
|
|
34
|
+
};
|
|
35
|
+
/** 会话内全部 turn 请求的 Σoutput / Σ(done − firstToken)。 */
|
|
36
|
+
avgTps?: number;
|
|
37
|
+
/** 本进程打开该会话的时刻(不是会话文件创建时间)。 */
|
|
38
|
+
sessionStartedAt: number;
|
|
39
|
+
}
|
|
40
|
+
/** 外部 Agent 的用量单位(Codex 订阅 token、Copilot premium request 等不换算美元)。 */
|
|
41
|
+
export type ExternalUsageUnit = "usd" | "tokens" | "requests";
|
|
42
|
+
export interface SubagentStartEvent {
|
|
43
|
+
type: "subagent_start";
|
|
44
|
+
taskId: string;
|
|
45
|
+
parentToolCallId: string;
|
|
46
|
+
/** 子 Agent 类型(`general` / `explore` / 定义文件名 / 外部 Agent id)。 */
|
|
47
|
+
agent: string;
|
|
48
|
+
/** `ama` | `claude` | `codex` | `acp:<program>` | 宿主 runner id。 */
|
|
49
|
+
runner: string;
|
|
50
|
+
description: string;
|
|
51
|
+
background: boolean;
|
|
52
|
+
model?: string;
|
|
53
|
+
sessionFile?: string;
|
|
54
|
+
cwd: string;
|
|
55
|
+
}
|
|
56
|
+
export interface SubagentUpdateEvent {
|
|
57
|
+
type: "subagent_update";
|
|
58
|
+
taskId: string;
|
|
59
|
+
kind: "tool" | "text" | "turn";
|
|
60
|
+
toolName?: string;
|
|
61
|
+
/** 文本增量(节流 ≥ 250 ms 合并)。 */
|
|
62
|
+
textDelta?: string;
|
|
63
|
+
turn: number;
|
|
64
|
+
usage?: Usage;
|
|
65
|
+
}
|
|
66
|
+
export interface SubagentEndEvent {
|
|
67
|
+
type: "subagent_end";
|
|
68
|
+
taskId: string;
|
|
69
|
+
status: SubagentStatus;
|
|
70
|
+
/** 外部 runner 可能拿不到 token 用量。 */
|
|
71
|
+
usage?: Usage;
|
|
72
|
+
cache?: {
|
|
73
|
+
hitRate?: number;
|
|
74
|
+
reBilledTokens: number;
|
|
75
|
+
};
|
|
76
|
+
/** 全文结果(> 50 KB 截断时)。 */
|
|
77
|
+
outputFile?: string;
|
|
78
|
+
worktree?: {
|
|
79
|
+
branch: string;
|
|
80
|
+
changed: boolean;
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
export interface PlanStep {
|
|
84
|
+
/** `S1`、`S2` …;编号列表时按序号生成。 */
|
|
85
|
+
id: string;
|
|
86
|
+
text: string;
|
|
87
|
+
dependsOn?: string[];
|
|
88
|
+
/** 建议执行者(`[agent: codex]`)。 */
|
|
89
|
+
agent?: string;
|
|
90
|
+
}
|
|
91
|
+
/** `custom{customType:"ama.plan"}` 的 data,也是 RPC `get_plan` 的返回。 */
|
|
92
|
+
export interface PlanData {
|
|
93
|
+
id: string;
|
|
94
|
+
version: number;
|
|
95
|
+
status: "proposed" | "approved" | "rejected" | "superseded";
|
|
96
|
+
markdown: string;
|
|
97
|
+
steps: PlanStep[];
|
|
98
|
+
sourceEntryId: string;
|
|
99
|
+
filePath?: string;
|
|
100
|
+
}
|
|
101
|
+
/** `custom{customType:"ama.plan_state"}` 的 data(resume 回到 plan 模式)。 */
|
|
102
|
+
export interface PlanStateData {
|
|
103
|
+
active: boolean;
|
|
104
|
+
prePlanMode: PermissionMode;
|
|
105
|
+
planId?: string;
|
|
106
|
+
}
|
|
107
|
+
/** 审批四选项 + 拒绝(Esc)。 */
|
|
108
|
+
export type PlanDecisionKind = "approve" | "approve_fresh" | "revise" | "reject";
|
|
109
|
+
export interface PlanProposedEvent {
|
|
110
|
+
type: "plan_proposed";
|
|
111
|
+
planId: string;
|
|
112
|
+
version: number;
|
|
113
|
+
markdown: string;
|
|
114
|
+
steps: PlanStep[];
|
|
115
|
+
filePath?: string;
|
|
116
|
+
}
|
|
117
|
+
export interface PlanResolvedEvent {
|
|
118
|
+
type: "plan_resolved";
|
|
119
|
+
planId: string;
|
|
120
|
+
decision: PlanDecisionKind;
|
|
121
|
+
/** `approve` 时指定的执行模式(缺省回到进入 plan 前的模式)。 */
|
|
122
|
+
mode?: PermissionMode;
|
|
123
|
+
}
|
|
124
|
+
/** todo 条目的线上形状(与 `tools/todo.ts` 的 `TodoItem` 结构兼容;`planStep` 由 W5-F 加)。 */
|
|
125
|
+
export interface TodoItemView {
|
|
126
|
+
id: string;
|
|
127
|
+
text: string;
|
|
128
|
+
status: "pending" | "in_progress" | "done";
|
|
129
|
+
planStep?: string;
|
|
130
|
+
}
|
|
131
|
+
export interface TodoUpdatedEvent {
|
|
132
|
+
type: "todo_updated";
|
|
133
|
+
items: TodoItemView[];
|
|
134
|
+
}
|
|
135
|
+
export type LimitKind = "turns" | "cost";
|
|
136
|
+
/** `--max-turns` / `--max-cost` / `limits.*` 到限;`-p` 下以退出码 7 结束。 */
|
|
137
|
+
export interface LimitReachedEvent {
|
|
138
|
+
type: "limit_reached";
|
|
139
|
+
kind: LimitKind;
|
|
140
|
+
/** 到限时的值(回合数或美元)。 */
|
|
141
|
+
value: number;
|
|
142
|
+
limit: number;
|
|
143
|
+
}
|
|
144
|
+
export interface ModelFallbackEvent {
|
|
145
|
+
type: "model_fallback";
|
|
146
|
+
from: ModelRef;
|
|
147
|
+
to: ModelRef;
|
|
148
|
+
/** 触发原因(`overloaded` / 重试用尽的错误文本)。 */
|
|
149
|
+
reason: string;
|
|
150
|
+
}
|
|
151
|
+
export interface BackgroundJobEvent {
|
|
152
|
+
type: "background_job";
|
|
153
|
+
jobId: string;
|
|
154
|
+
phase: "started" | "exited" | "stopped";
|
|
155
|
+
command: string;
|
|
156
|
+
pid?: number;
|
|
157
|
+
outputPath?: string;
|
|
158
|
+
exitCode?: number | null;
|
|
159
|
+
}
|
|
160
|
+
export type SessionEventW5 =
|
|
161
|
+
/** 流式中 ≤ 2 Hz(`ui.animation: false` 时不发);数据从 `getStats().telemetry` 取。 */
|
|
162
|
+
{
|
|
163
|
+
type: "telemetry_tick";
|
|
164
|
+
} | SubagentStartEvent | SubagentUpdateEvent | SubagentEndEvent | PlanProposedEvent | PlanResolvedEvent | TodoUpdatedEvent | LimitReachedEvent | ModelFallbackEvent | BackgroundJobEvent;
|
|
165
|
+
/** 外部 Agent 记账(`custom{ama.agent-usage}` 汇总,§5.4)。 */
|
|
166
|
+
export interface ExternalAgentStats {
|
|
167
|
+
byAgent: Record<string, {
|
|
168
|
+
runs: number;
|
|
169
|
+
unit: ExternalUsageUnit;
|
|
170
|
+
amount: number;
|
|
171
|
+
tokens?: number;
|
|
172
|
+
}>;
|
|
173
|
+
}
|
|
174
|
+
/** 子 Agent 任务注册表的汇总(`/session` 与 `get_session_stats`)。 */
|
|
175
|
+
export interface SessionTaskStats {
|
|
176
|
+
total: number;
|
|
177
|
+
running: number;
|
|
178
|
+
byStatus: Partial<Record<SubagentStatus, number>>;
|
|
179
|
+
}
|
|
180
|
+
export interface SessionStatsW5 {
|
|
181
|
+
/** [W5-A] 速率与会话时长;遥测扩展未装配时缺省。 */
|
|
182
|
+
telemetry?: SessionTelemetry;
|
|
183
|
+
/** [W5-E] 外部 Agent 用量;没有外部运行时缺省。 */
|
|
184
|
+
external?: ExternalAgentStats;
|
|
185
|
+
/** [W5-G] 子 Agent 任务;没有任务时缺省。 */
|
|
186
|
+
tasks?: SessionTaskStats;
|
|
187
|
+
}
|
|
188
|
+
/** `limits` 选项(`--max-turns` / `--max-cost` / config `limits.*`),W5-H2 实现。 */
|
|
189
|
+
export interface SessionLimits {
|
|
190
|
+
maxTurns?: number;
|
|
191
|
+
maxCostUsd?: number;
|
|
192
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 第五波会话契约(docs/wave5-plan.md §1.3、§5.4、§6.3、§6.5、§7.5、§8.3;[W5-C0])。
|
|
3
|
+
*
|
|
4
|
+
* 这里放新增事件的载荷与 `SessionStats` 的扩展形状,由 agent/types.ts 并入 `SessionEvent` /
|
|
5
|
+
* `SessionStats` 并再导出(agent/types.ts 已接近 600 行)。全部是新增事件与可选字段:
|
|
6
|
+
* `RpcEvent` 由 `SessionEvent` 派生,新事件自动上线;`RPC_PROTOCOL_VERSION` 不变。
|
|
7
|
+
* 实现归各批次:遥测 W5-A、子 Agent W5-G(外部 runner W5-E)、计划 / todo W5-F、
|
|
8
|
+
* 预算 / 回退 / 后台命令 W5-H2。
|
|
9
|
+
*/
|
|
10
|
+
export {};
|
package/dist/agent/types.d.ts
CHANGED
|
@@ -17,13 +17,18 @@
|
|
|
17
17
|
* - (W3-C0)缓存可观测性(第三波 §1.10):`SessionEvent` 加 `cache_miss` / `cache_warm` /
|
|
18
18
|
* `context_pressure`,`SessionStats.cache`(可选,C1b 填);`CacheSettings` 是
|
|
19
19
|
* `SessionCacheController` 的解析后设置(来自 config `cache` 段与环境变量)。
|
|
20
|
+
* - (W5-C0)第五波事件与统计(遥测、子 Agent、计划 / todo、预算、回退、后台命令)定义在
|
|
21
|
+
* agent/types-w5.ts,这里并入 `SessionEvent` / `SessionStats` 并再导出。
|
|
20
22
|
*/
|
|
21
23
|
import type { AssistantEvent, AssistantMessage, CacheRetention, ImageBlock, Message, MessageOrigin, Model, ModelRef, ModelThinkingLevel, ToolCallBlock, ToolResultMessage, TranscriptContext, Usage } from "../ai/types.js";
|
|
22
24
|
import type { CacheMiss, CacheMissReason, CacheReporting, WarmerStatus, WarmingMode } from "../ai/cache/types.js";
|
|
23
25
|
import type { HookEvent } from "../hooks/types.js";
|
|
24
|
-
import type { ActionPreview, ApprovalDecision, ApprovalReason, PermissionMode } from "../permissions/types.js";
|
|
25
|
-
import type { AgentMessage, SessionEntry } from "../session/types.js";
|
|
26
|
+
import type { ActionPreview, ApprovalDecision, ApprovalReason, AutoDecision, PermissionMode, PermissionRequestContext } from "../permissions/types.js";
|
|
27
|
+
import type { AgentMessage, BranchSummaryEntry, SessionEntry } from "../session/types.js";
|
|
28
|
+
import type { RewindMode, RewindPoint, RewindRequest, RewindResult, RewindSkipReason } from "../checkpoints/types.js";
|
|
26
29
|
import type { ToolDefinition, ToolResult } from "../tools/types.js";
|
|
30
|
+
import type { SessionEventW5, SessionStatsW5 } from "./types-w5.js";
|
|
31
|
+
export type * from "./types-w5.js";
|
|
27
32
|
export type { AssistantContentBlock, AssistantMessage, ContentBlock, ImageBlock, Message, StopReason, SystemMessage, TextBlock, ThinkingBlock, ToolCallBlock, ToolResultMessage, Usage, UserMessage, } from "../ai/types.js";
|
|
28
33
|
export type { AgentMessage, BranchSummaryMessage, CompactionSummaryMessage, CustomMessage, } from "../session/types.js";
|
|
29
34
|
export type ToolCall = ToolCallBlock;
|
|
@@ -56,6 +61,8 @@ export interface ToolCallGate {
|
|
|
56
61
|
reason?: string;
|
|
57
62
|
/** Hook 的 updatedInput 替换后的输入。 */
|
|
58
63
|
input?: unknown;
|
|
64
|
+
/** auto 权限模式的判定(随 tool_execution_end 发出)。 */
|
|
65
|
+
autoDecision?: AutoDecision;
|
|
59
66
|
}
|
|
60
67
|
export interface LoopHooks {
|
|
61
68
|
/** 档一裁剪、Hook 的 additionalContext 注入。 */
|
|
@@ -175,6 +182,10 @@ export type SessionEvent = {
|
|
|
175
182
|
result: ToolResult;
|
|
176
183
|
isError: boolean;
|
|
177
184
|
parentToolCallId?: string;
|
|
185
|
+
/** auto 权限模式下这次调用的判定(层、结论、原因);其它模式缺省。 */
|
|
186
|
+
autoDecision?: AutoDecision;
|
|
187
|
+
/** 被拒(权限管线、PreToolUse Hook、审批或无人值守)而没有执行;原因是 `result` 的文本。 */
|
|
188
|
+
denied?: true;
|
|
178
189
|
} | {
|
|
179
190
|
type: "queue_update";
|
|
180
191
|
steering: string[];
|
|
@@ -210,6 +221,13 @@ export type SessionEvent = {
|
|
|
210
221
|
timeoutMs: number;
|
|
211
222
|
/** [W3-C0] 执行前预览(同 `ApprovalRequest.preview`)。 */
|
|
212
223
|
preview?: ActionPreview;
|
|
224
|
+
/** auto 权限模式下为什么询问(同 `ApprovalRequest.autoDecision`)。 */
|
|
225
|
+
autoDecision?: AutoDecision;
|
|
226
|
+
/**
|
|
227
|
+
* [W5-EG] 发起方:`depth > 0` 来自 task 子 Agent、`taskId` 来源任务、`origin` 外部 Agent 的
|
|
228
|
+
* 权限请求(对话框标 `[claude · 会话 abc1]`)。主会话自己的调用不带。
|
|
229
|
+
*/
|
|
230
|
+
context?: PermissionRequestContext;
|
|
213
231
|
} | {
|
|
214
232
|
type: "permission_resolved";
|
|
215
233
|
requestId: string;
|
|
@@ -230,6 +248,19 @@ export type SessionEvent = {
|
|
|
230
248
|
type: "session_changed";
|
|
231
249
|
sessionId: string;
|
|
232
250
|
sessionFile?: string;
|
|
251
|
+
}
|
|
252
|
+
/** [RW-B] 回滚完成(rewind-plan §5):dryRun 不发;仅对话时文件清单为空。 */
|
|
253
|
+
| {
|
|
254
|
+
type: "session_rewound";
|
|
255
|
+
entryId: string;
|
|
256
|
+
mode: RewindMode;
|
|
257
|
+
restored: string[];
|
|
258
|
+
deleted: string[];
|
|
259
|
+
conflicts: string[];
|
|
260
|
+
skipped: {
|
|
261
|
+
path: string;
|
|
262
|
+
reason: RewindSkipReason;
|
|
263
|
+
}[];
|
|
233
264
|
} | {
|
|
234
265
|
type: "model_changed";
|
|
235
266
|
model: ModelRef;
|
|
@@ -259,7 +290,9 @@ export type SessionEvent = {
|
|
|
259
290
|
remainingTokens?: number;
|
|
260
291
|
/** 按最近 5 回合均值估算。 */
|
|
261
292
|
estimatedTurnsLeft?: number;
|
|
262
|
-
}
|
|
293
|
+
}
|
|
294
|
+
/** [W5-C0] 第五波事件(agent/types-w5.ts)。 */
|
|
295
|
+
| SessionEventW5;
|
|
263
296
|
export type SessionEventType = SessionEvent["type"];
|
|
264
297
|
export type PromptDisposition = "started" | "queued" | "handled";
|
|
265
298
|
export interface PromptOptions {
|
|
@@ -291,7 +324,8 @@ export interface SessionState {
|
|
|
291
324
|
autoCompaction: boolean;
|
|
292
325
|
autoRetry: boolean;
|
|
293
326
|
}
|
|
294
|
-
|
|
327
|
+
/** [W5-C0] `telemetry? / external? / tasks?` 见 `SessionStatsW5`。 */
|
|
328
|
+
export interface SessionStats extends SessionStatsW5 {
|
|
295
329
|
sessionId: string;
|
|
296
330
|
sessionFile: string | undefined;
|
|
297
331
|
userMessages: number;
|
|
@@ -374,5 +408,22 @@ export interface AgentSession {
|
|
|
374
408
|
readonly entries: readonly SessionEntry[];
|
|
375
409
|
getLastAssistantText(): string | null;
|
|
376
410
|
getStats(): SessionStats;
|
|
411
|
+
/** [RW-B] 活动路径上开启新回合的用户消息,从旧到新(rewind-plan §3.1)。 */
|
|
412
|
+
rewindPoints(): RewindPoint[];
|
|
413
|
+
/** [RW-B] 运行中 → busy;全部失败且无一恢复 → rewind_failed。 */
|
|
414
|
+
rewind(request: RewindRequest): Promise<RewindResult>;
|
|
415
|
+
/** [RW-B] 「从这里摘要」:回到该消息之前并为离开的分支写摘要,返回原消息草稿。 */
|
|
416
|
+
summarizeFrom(entryId: string, instructions?: string): Promise<{
|
|
417
|
+
leafId: string | null;
|
|
418
|
+
draft: RewindDraftText;
|
|
419
|
+
summary?: BranchSummaryEntry;
|
|
420
|
+
}>;
|
|
421
|
+
/** [RW-B] 「摘要到这里」:以该消息为切点压缩之前的上下文,停在末尾。 */
|
|
422
|
+
summarizeUpTo(entryId: string, instructions?: string): Promise<CompactionResult>;
|
|
377
423
|
dispose(): Promise<void>;
|
|
378
424
|
}
|
|
425
|
+
/** [RW-B] 回滚回填的原消息。 */
|
|
426
|
+
export type RewindDraftText = {
|
|
427
|
+
text: string;
|
|
428
|
+
images?: ImageBlock[];
|
|
429
|
+
};
|
package/dist/agent/types.js
CHANGED
|
@@ -17,5 +17,7 @@
|
|
|
17
17
|
* - (W3-C0)缓存可观测性(第三波 §1.10):`SessionEvent` 加 `cache_miss` / `cache_warm` /
|
|
18
18
|
* `context_pressure`,`SessionStats.cache`(可选,C1b 填);`CacheSettings` 是
|
|
19
19
|
* `SessionCacheController` 的解析后设置(来自 config `cache` 段与环境变量)。
|
|
20
|
+
* - (W5-C0)第五波事件与统计(遥测、子 Agent、计划 / todo、预算、回退、后台命令)定义在
|
|
21
|
+
* agent/types-w5.ts,这里并入 `SessionEvent` / `SessionStats` 并再导出。
|
|
20
22
|
*/
|
|
21
23
|
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 子 Agent 的 git worktree 隔离(docs/wave5-plan.md §7.4,D24)。[W5-G]
|
|
3
|
+
*
|
|
4
|
+
* - `git worktree add -b ama/task-<taskId> <repo>/.ama/worktrees/<taskId> HEAD`;子会话 cwd 指向
|
|
5
|
+
* worktree 里与父 cwd 对应的子目录;
|
|
6
|
+
* - 结束时没有改动(工作区干净且 HEAD 未动)→ `git worktree remove --force` 并删分支;有改动则保留,
|
|
7
|
+
* 结果里给分支名与 `git diff --stat`;
|
|
8
|
+
* - 非 git 目录直接报错,不回落到共享目录;`.ama/worktrees/.gitignore` 写 `*`,父会话的 git 与
|
|
9
|
+
* grep / glob(读嵌套 .gitignore)都看不到这些目录;
|
|
10
|
+
* - worktree 不保证可运行:依赖(node_modules 等)不共享。
|
|
11
|
+
*/
|
|
12
|
+
export interface Worktree {
|
|
13
|
+
/** worktree 根目录。 */
|
|
14
|
+
path: string;
|
|
15
|
+
/** 子会话 cwd(worktree 里与父 cwd 对应的目录)。 */
|
|
16
|
+
cwd: string;
|
|
17
|
+
branch: string;
|
|
18
|
+
/** 创建时的提交(判断有无新提交)。 */
|
|
19
|
+
base: string;
|
|
20
|
+
repo: string;
|
|
21
|
+
}
|
|
22
|
+
export interface WorktreeOutcome {
|
|
23
|
+
branch: string;
|
|
24
|
+
changed: boolean;
|
|
25
|
+
/** 有改动时:`git diff --stat <base>` 与未跟踪文件。 */
|
|
26
|
+
diffStat?: string;
|
|
27
|
+
/** 保留时的路径。 */
|
|
28
|
+
path?: string;
|
|
29
|
+
}
|
|
30
|
+
export type GitRunner = (args: readonly string[], cwd: string) => Promise<string>;
|
|
31
|
+
export declare const runGit: GitRunner;
|
|
32
|
+
export declare function worktreeBranch(taskId: string): string;
|
|
33
|
+
/** 在父 cwd 所在仓库里为任务建 worktree;非 git 目录抛错。 */
|
|
34
|
+
export declare function createWorktree(cwd: string, taskId: string, git?: GitRunner): Promise<Worktree>;
|
|
35
|
+
/** 运行结束:无改动删除 worktree 与分支;有改动保留并给 diff 摘要。 */
|
|
36
|
+
export declare function finishWorktree(tree: Worktree, git?: GitRunner): Promise<WorktreeOutcome>;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 子 Agent 的 git worktree 隔离(docs/wave5-plan.md §7.4,D24)。[W5-G]
|
|
3
|
+
*
|
|
4
|
+
* - `git worktree add -b ama/task-<taskId> <repo>/.ama/worktrees/<taskId> HEAD`;子会话 cwd 指向
|
|
5
|
+
* worktree 里与父 cwd 对应的子目录;
|
|
6
|
+
* - 结束时没有改动(工作区干净且 HEAD 未动)→ `git worktree remove --force` 并删分支;有改动则保留,
|
|
7
|
+
* 结果里给分支名与 `git diff --stat`;
|
|
8
|
+
* - 非 git 目录直接报错,不回落到共享目录;`.ama/worktrees/.gitignore` 写 `*`,父会话的 git 与
|
|
9
|
+
* grep / glob(读嵌套 .gitignore)都看不到这些目录;
|
|
10
|
+
* - worktree 不保证可运行:依赖(node_modules 等)不共享。
|
|
11
|
+
*/
|
|
12
|
+
import { execFile } from "node:child_process";
|
|
13
|
+
import { existsSync, mkdirSync, realpathSync, writeFileSync } from "node:fs";
|
|
14
|
+
import { join, relative } from "node:path";
|
|
15
|
+
const TIMEOUT_MS = 30_000;
|
|
16
|
+
export const runGit = (args, cwd) => new Promise((resolve, reject) => {
|
|
17
|
+
execFile("git", [...args], { cwd, timeout: TIMEOUT_MS, maxBuffer: 4 * 1024 * 1024, windowsHide: true }, (error, stdout, stderr) => {
|
|
18
|
+
if (error)
|
|
19
|
+
reject(new Error(String(stderr).trim() || error.message));
|
|
20
|
+
else
|
|
21
|
+
resolve(String(stdout));
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
/**
|
|
25
|
+
* 两边都取系统的真实路径再比:git 给的是真实路径(macOS 的 /var → /private/var;Windows 是长文件名、
|
|
26
|
+
* 正斜杠),而 cwd 可能是 8.3 短名(RUNNER~1)或符号链接。
|
|
27
|
+
*/
|
|
28
|
+
function realPath(path) {
|
|
29
|
+
try {
|
|
30
|
+
return realpathSync.native(path);
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return path;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
export function worktreeBranch(taskId) {
|
|
37
|
+
return `ama/task-${taskId}`;
|
|
38
|
+
}
|
|
39
|
+
/** 在父 cwd 所在仓库里为任务建 worktree;非 git 目录抛错。 */
|
|
40
|
+
export async function createWorktree(cwd, taskId, git = runGit) {
|
|
41
|
+
let repo;
|
|
42
|
+
try {
|
|
43
|
+
repo = realPath((await git(["rev-parse", "--show-toplevel"], cwd)).trim());
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
throw new Error(`isolation "worktree" needs a git repository; ${cwd} is not inside one`);
|
|
47
|
+
}
|
|
48
|
+
const base = (await git(["rev-parse", "HEAD"], repo)).trim();
|
|
49
|
+
const root = join(repo, ".ama", "worktrees");
|
|
50
|
+
mkdirSync(root, { recursive: true });
|
|
51
|
+
const ignore = join(root, ".gitignore");
|
|
52
|
+
if (!existsSync(ignore))
|
|
53
|
+
writeFileSync(ignore, "*\n");
|
|
54
|
+
const path = join(root, taskId);
|
|
55
|
+
const branch = worktreeBranch(taskId);
|
|
56
|
+
if (!existsSync(path))
|
|
57
|
+
await git(["worktree", "add", "-b", branch, path, base], repo);
|
|
58
|
+
const sub = relative(repo, realPath(cwd));
|
|
59
|
+
const childCwd = sub === "" || sub.startsWith("..") ? path : join(path, sub);
|
|
60
|
+
mkdirSync(childCwd, { recursive: true });
|
|
61
|
+
return { path, cwd: childCwd, branch, base, repo };
|
|
62
|
+
}
|
|
63
|
+
/** 运行结束:无改动删除 worktree 与分支;有改动保留并给 diff 摘要。 */
|
|
64
|
+
export async function finishWorktree(tree, git = runGit) {
|
|
65
|
+
const status = (await git(["status", "--porcelain"], tree.path)).trim();
|
|
66
|
+
const head = (await git(["rev-parse", "HEAD"], tree.path)).trim();
|
|
67
|
+
if (status === "" && head === tree.base) {
|
|
68
|
+
await git(["worktree", "remove", "--force", tree.path], tree.repo);
|
|
69
|
+
await git(["branch", "-D", tree.branch], tree.repo).catch(() => "");
|
|
70
|
+
return { branch: tree.branch, changed: false };
|
|
71
|
+
}
|
|
72
|
+
const stat = (await git(["diff", "--stat", tree.base], tree.path).catch(() => "")).trim();
|
|
73
|
+
const untracked = status
|
|
74
|
+
.split("\n")
|
|
75
|
+
.filter((line) => line.startsWith("??"))
|
|
76
|
+
.map((line) => line.slice(3));
|
|
77
|
+
const parts = [stat];
|
|
78
|
+
if (untracked.length > 0)
|
|
79
|
+
parts.push(`untracked: ${untracked.join(", ")}`);
|
|
80
|
+
return {
|
|
81
|
+
branch: tree.branch,
|
|
82
|
+
changed: true,
|
|
83
|
+
diffStat: parts.filter((part) => part !== "").join("\n"),
|
|
84
|
+
path: tree.path,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 内置子 Agent 类型(docs/wave5-plan.md §7.2,D22–D23)。[W5-G]
|
|
3
|
+
*
|
|
4
|
+
* 三个类型都用父会话的活动工具集(工具表与父字节一致,缓存前缀可复用);只读靠权限层:
|
|
5
|
+
* `explore` / `plan` 的 `permissionMode: "plan"` 让子会话用 plan 模式的管线,写类工具与非只读 bash
|
|
6
|
+
* 被拒绝且不弹审批(session-subagent.ts)。正文是追加到子会话系统提示末尾的角色说明(`role` 节)。
|
|
7
|
+
*/
|
|
8
|
+
import type { AgentDefinition } from "./types.js";
|
|
9
|
+
/** 所有 ama 子会话共有的角色说明(类型正文追加在它后面)。 */
|
|
10
|
+
export declare const SUBAGENT_ROLE_PREAMBLE: string;
|
|
11
|
+
export declare const BUILTIN_AGENTS: readonly AgentDefinition[];
|
|
12
|
+
export declare const DEFAULT_AGENT = "general";
|
|
13
|
+
/** 子会话系统提示 `role` 节:通用说明 + 类型正文。 */
|
|
14
|
+
export declare function agentRole(agent: Pick<AgentDefinition, "prompt">): string;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 内置子 Agent 类型(docs/wave5-plan.md §7.2,D22–D23)。[W5-G]
|
|
3
|
+
*
|
|
4
|
+
* 三个类型都用父会话的活动工具集(工具表与父字节一致,缓存前缀可复用);只读靠权限层:
|
|
5
|
+
* `explore` / `plan` 的 `permissionMode: "plan"` 让子会话用 plan 模式的管线,写类工具与非只读 bash
|
|
6
|
+
* 被拒绝且不弹审批(session-subagent.ts)。正文是追加到子会话系统提示末尾的角色说明(`role` 节)。
|
|
7
|
+
*/
|
|
8
|
+
/** 所有 ama 子会话共有的角色说明(类型正文追加在它后面)。 */
|
|
9
|
+
export const SUBAGENT_ROLE_PREAMBLE = "You are a sub-agent: the main agent delegated one task to you. It cannot see your work, only " +
|
|
10
|
+
"your final reply. Complete the task directly; do not delegate further. End with a concise " +
|
|
11
|
+
"report: what you did, key findings, and files changed (if any).";
|
|
12
|
+
function builtin(name, description, prompt, permissionMode) {
|
|
13
|
+
return {
|
|
14
|
+
name,
|
|
15
|
+
description,
|
|
16
|
+
permissionMode,
|
|
17
|
+
model: "inherit",
|
|
18
|
+
maxTurns: 30,
|
|
19
|
+
isolation: "none",
|
|
20
|
+
background: false,
|
|
21
|
+
runner: "ama",
|
|
22
|
+
prompt,
|
|
23
|
+
source: "builtin",
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export const BUILTIN_AGENTS = Object.freeze([
|
|
27
|
+
builtin("general", "General-purpose sub-agent (default): researches and changes code like you do.", "", "inherit"),
|
|
28
|
+
builtin("explore", "Read-only search: locates files, symbols and code paths; returns paths with line numbers.", "Locate, do not review. Return file paths with line numbers and short notes on what is " +
|
|
29
|
+
"where. State the search scope you covered. You cannot modify files; bash runs read-only " +
|
|
30
|
+
"commands only.", "plan"),
|
|
31
|
+
builtin("plan", "Read-only planner: returns a step-by-step plan with key files and trade-offs.", "Produce a step-by-step implementation plan: key files to change, the order of steps, and " +
|
|
32
|
+
"trade-offs or risks. Do not modify files; you are read-only.", "plan"),
|
|
33
|
+
]);
|
|
34
|
+
export const DEFAULT_AGENT = "general";
|
|
35
|
+
/** 子会话系统提示 `role` 节:通用说明 + 类型正文。 */
|
|
36
|
+
export function agentRole(agent) {
|
|
37
|
+
const own = agent.prompt.trim();
|
|
38
|
+
return own === "" ? SUBAGENT_ROLE_PREAMBLE : `${SUBAGENT_ROLE_PREAMBLE}\n\n${own}`;
|
|
39
|
+
}
|