@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,231 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 会话遥测:输出速率与首 token 延迟(docs/wave5-plan.md §1.3,D2)。[W5-A]
|
|
3
|
+
*
|
|
4
|
+
* 以 `SessionExtension.wrapStream` 包一层流,只观察不改事件:
|
|
5
|
+
* - 只统计 `purpose: "turn"`(缺省即 turn);summary / warm / probe / classify 原样透传、不计入;
|
|
6
|
+
* - 首 token = 首个 `text_delta` / `thinking_delta` / `toolcall_start`(`ttftMs = firstTokenAt − requestAt`);
|
|
7
|
+
* - 流式中按增量字符估算输出 token(CJK / 假名 / 谚文每字 1,其余 / 4,与 `compaction/estimate.ts`
|
|
8
|
+
* 同口径,不逐块取整),瞬时速率取最近 2 s 滑动窗口;请求结束改用 `usage.output`(含 reasoning);
|
|
9
|
+
* - `tps = outputTokens / (doneAt − firstTokenAt)`;会话均速 = Σoutput / Σ(done − firstToken),只计有首
|
|
10
|
+
* token、非 error 且生成时长 ≥ 250 ms 的请求(更短的整块到达,速率无意义,`tps` 留空);
|
|
11
|
+
* - 流式中经 `emit` 发 `telemetry_tick`:首个在首 token 后 ≥ 500 ms,之后两次间隔 ≥ 500 ms(≤ 2 Hz,
|
|
12
|
+
* 只由增量驱动、不起计时器);
|
|
13
|
+
* `ticks: false`(`ui.animation: false`)时不发,界面在 message_end 时刷新。
|
|
14
|
+
*
|
|
15
|
+
* 数据从 `getStats().telemetry` 取(`contributeStats`):进行中的请求出了首 token 后 `last` 即指向它(只有
|
|
16
|
+
* `requestAt / firstTokenAt / ttftMs`),结束后补齐 `doneAt / outputTokens / tps`;`sessionStartedAt` 是扩展创建(本进程打开会话)的时刻。
|
|
17
|
+
*/
|
|
18
|
+
export const TELEMETRY_TICK_MS = 500;
|
|
19
|
+
export const TELEMETRY_WINDOW_MS = 2000;
|
|
20
|
+
/** 不足这么长(自首 token 起)不算速率:开头几块或整块到达的回复会把速率放大到无意义。 */
|
|
21
|
+
const MIN_SPAN_MS = 250;
|
|
22
|
+
/** 一段增量文本的 token 估算(不取整,逐块累加不放大)。 */
|
|
23
|
+
export function deltaTokens(text) {
|
|
24
|
+
let wide = 0;
|
|
25
|
+
let narrow = 0;
|
|
26
|
+
for (let i = 0; i < text.length; i++) {
|
|
27
|
+
const code = text.charCodeAt(i);
|
|
28
|
+
if (code < 0x1100)
|
|
29
|
+
narrow++;
|
|
30
|
+
else if (code >= 0xd840 && code <= 0xd87f) {
|
|
31
|
+
wide++;
|
|
32
|
+
i++;
|
|
33
|
+
}
|
|
34
|
+
else if ((code >= 0x1100 && code <= 0x11ff) ||
|
|
35
|
+
(code >= 0x3000 && code <= 0x30ff) ||
|
|
36
|
+
(code >= 0x3130 && code <= 0x318f) ||
|
|
37
|
+
(code >= 0x31f0 && code <= 0x31ff) ||
|
|
38
|
+
(code >= 0x3400 && code <= 0x4dbf) ||
|
|
39
|
+
(code >= 0x4e00 && code <= 0x9fff) ||
|
|
40
|
+
(code >= 0xac00 && code <= 0xd7af) ||
|
|
41
|
+
(code >= 0xf900 && code <= 0xfaff) ||
|
|
42
|
+
(code >= 0xff00 && code <= 0xffef))
|
|
43
|
+
wide++;
|
|
44
|
+
else
|
|
45
|
+
narrow++;
|
|
46
|
+
}
|
|
47
|
+
return wide + narrow / 4;
|
|
48
|
+
}
|
|
49
|
+
function deltaText(event) {
|
|
50
|
+
switch (event.type) {
|
|
51
|
+
case "text_delta":
|
|
52
|
+
case "thinking_delta":
|
|
53
|
+
case "toolcall_delta":
|
|
54
|
+
return event.delta;
|
|
55
|
+
case "toolcall_start":
|
|
56
|
+
return event.name;
|
|
57
|
+
default:
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/** 一次 turn 请求的进行中记录。 */
|
|
62
|
+
class RequestTracker {
|
|
63
|
+
record;
|
|
64
|
+
estimate = 0;
|
|
65
|
+
samples = [];
|
|
66
|
+
finished = false;
|
|
67
|
+
constructor(requestAt) {
|
|
68
|
+
this.record = { requestAt };
|
|
69
|
+
}
|
|
70
|
+
observe(event, at) {
|
|
71
|
+
if (this.finished)
|
|
72
|
+
return false;
|
|
73
|
+
const first = event.type === "text_delta" ||
|
|
74
|
+
event.type === "thinking_delta" ||
|
|
75
|
+
event.type === "toolcall_start";
|
|
76
|
+
if (first && this.record.firstTokenAt === undefined) {
|
|
77
|
+
this.record.firstTokenAt = at;
|
|
78
|
+
this.record.ttftMs = at - this.record.requestAt;
|
|
79
|
+
}
|
|
80
|
+
const text = deltaText(event);
|
|
81
|
+
if (text === undefined || text === "")
|
|
82
|
+
return false;
|
|
83
|
+
const tokens = deltaTokens(text);
|
|
84
|
+
this.estimate += tokens;
|
|
85
|
+
this.samples.push({ at, tokens });
|
|
86
|
+
while (this.samples.length > 0 && at - this.samples[0].at > TELEMETRY_WINDOW_MS)
|
|
87
|
+
this.samples.shift();
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
live(now) {
|
|
91
|
+
const first = this.record.firstTokenAt;
|
|
92
|
+
if (this.finished || first === undefined)
|
|
93
|
+
return undefined;
|
|
94
|
+
const elapsedMs = Math.max(0, now - first);
|
|
95
|
+
const recent = this.samples.filter((s) => now - s.at <= TELEMETRY_WINDOW_MS);
|
|
96
|
+
const windowTokens = recent.reduce((sum, s) => sum + s.tokens, 0);
|
|
97
|
+
const span = Math.min(TELEMETRY_WINDOW_MS, elapsedMs);
|
|
98
|
+
const tps = span < MIN_SPAN_MS ? 0 : windowTokens / (span / 1000);
|
|
99
|
+
return { tps, outputTokens: Math.round(this.estimate), elapsedMs };
|
|
100
|
+
}
|
|
101
|
+
finish(message, at) {
|
|
102
|
+
if (this.finished)
|
|
103
|
+
return;
|
|
104
|
+
this.finished = true;
|
|
105
|
+
const record = this.record;
|
|
106
|
+
record.doneAt = at;
|
|
107
|
+
const reported = message?.usage?.output;
|
|
108
|
+
const output = reported !== undefined && reported > 0 ? reported : Math.round(this.estimate);
|
|
109
|
+
record.outputTokens = output;
|
|
110
|
+
// 太短(整块到达)的请求不算速率,免得显示成上万 tok/s
|
|
111
|
+
if (record.firstTokenAt !== undefined && at - record.firstTokenAt >= MIN_SPAN_MS) {
|
|
112
|
+
record.tps = output / ((at - record.firstTokenAt) / 1000);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
export function createTelemetryExtension(deps = {}) {
|
|
117
|
+
const now = deps.now ?? Date.now;
|
|
118
|
+
const ticks = deps.ticks !== false && deps.emit !== undefined;
|
|
119
|
+
const sessionStartedAt = now();
|
|
120
|
+
let last;
|
|
121
|
+
let current;
|
|
122
|
+
let sumOutput = 0;
|
|
123
|
+
let sumMs = 0;
|
|
124
|
+
let lastTickAt = Number.NEGATIVE_INFINITY;
|
|
125
|
+
const finish = (tracker, message) => {
|
|
126
|
+
if (tracker.finished)
|
|
127
|
+
return;
|
|
128
|
+
tracker.finish(message, now());
|
|
129
|
+
if (current === tracker)
|
|
130
|
+
current = undefined;
|
|
131
|
+
const r = tracker.record;
|
|
132
|
+
last = { ...r };
|
|
133
|
+
const failed = message === undefined || message.stopReason === "error";
|
|
134
|
+
if (!failed && r.firstTokenAt !== undefined && r.doneAt !== undefined) {
|
|
135
|
+
const ms = r.doneAt - r.firstTokenAt;
|
|
136
|
+
if (ms >= MIN_SPAN_MS) {
|
|
137
|
+
sumOutput += r.outputTokens ?? 0;
|
|
138
|
+
sumMs += ms;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
const wrap = (inner, tracker) => {
|
|
143
|
+
let iterating = false;
|
|
144
|
+
let final;
|
|
145
|
+
// 只等 result() 的消费者:结果到了就结束记录;在迭代的消费者以读到终止事件为准(事件可能还在队列里)
|
|
146
|
+
void inner.result().then((message) => {
|
|
147
|
+
final = message;
|
|
148
|
+
if (!iterating)
|
|
149
|
+
finish(tracker, message);
|
|
150
|
+
}, () => finish(tracker, undefined));
|
|
151
|
+
const observe = (event) => {
|
|
152
|
+
const at = now();
|
|
153
|
+
if (event.type === "done" || event.type === "error") {
|
|
154
|
+
finish(tracker, event.message);
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
if (!tracker.observe(event, at) || !ticks)
|
|
158
|
+
return;
|
|
159
|
+
// 首个 tick 在首 token 之后 500 ms:瞬时完成的短回复不发(RPC 事件序列不变)
|
|
160
|
+
const since = Math.max(lastTickAt, tracker.record.firstTokenAt ?? at);
|
|
161
|
+
if (at - since >= TELEMETRY_TICK_MS) {
|
|
162
|
+
lastTickAt = at;
|
|
163
|
+
deps.emit?.({ type: "telemetry_tick" });
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
return {
|
|
167
|
+
result: () => inner.result(),
|
|
168
|
+
[Symbol.asyncIterator]() {
|
|
169
|
+
iterating = true;
|
|
170
|
+
const it = inner[Symbol.asyncIterator]();
|
|
171
|
+
const iterator = {
|
|
172
|
+
async next() {
|
|
173
|
+
const step = await it.next();
|
|
174
|
+
if (step.done === true)
|
|
175
|
+
finish(tracker, final);
|
|
176
|
+
else
|
|
177
|
+
observe(step.value);
|
|
178
|
+
return step;
|
|
179
|
+
},
|
|
180
|
+
// 提前退出(break / return):按已有结果结束记录
|
|
181
|
+
async return(value) {
|
|
182
|
+
finish(tracker, final);
|
|
183
|
+
return it.return !== undefined
|
|
184
|
+
? it.return(value)
|
|
185
|
+
: { done: true, value: undefined };
|
|
186
|
+
},
|
|
187
|
+
};
|
|
188
|
+
return iterator;
|
|
189
|
+
},
|
|
190
|
+
};
|
|
191
|
+
};
|
|
192
|
+
const snapshot = () => {
|
|
193
|
+
const out = { sessionStartedAt };
|
|
194
|
+
// 进行中的请求有了首 token 就算「最近一次」(没有 doneAt / tps),之前仍显示上一次
|
|
195
|
+
const recent = current?.record.firstTokenAt !== undefined ? current.record : last;
|
|
196
|
+
if (recent !== undefined)
|
|
197
|
+
out.last = { ...recent };
|
|
198
|
+
const live = current?.live(now());
|
|
199
|
+
if (live !== undefined)
|
|
200
|
+
out.live = live;
|
|
201
|
+
if (sumMs > 0)
|
|
202
|
+
out.avgTps = sumOutput / (sumMs / 1000);
|
|
203
|
+
return out;
|
|
204
|
+
};
|
|
205
|
+
return {
|
|
206
|
+
id: "telemetry",
|
|
207
|
+
wrapStream(stream) {
|
|
208
|
+
return (model, context, options) => {
|
|
209
|
+
const inner = stream(model, context, options);
|
|
210
|
+
if ((options.purpose ?? "turn") !== "turn")
|
|
211
|
+
return inner;
|
|
212
|
+
const tracker = new RequestTracker(now());
|
|
213
|
+
current = tracker;
|
|
214
|
+
return wrap(inner, tracker);
|
|
215
|
+
};
|
|
216
|
+
},
|
|
217
|
+
contributeStats(stats) {
|
|
218
|
+
stats.telemetry = snapshot();
|
|
219
|
+
},
|
|
220
|
+
snapshot,
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
/** 组装表用的工厂:只装主会话(depth 0);`ui.animation: false` 不发 tick。 */
|
|
224
|
+
export function telemetryFactory(ui) {
|
|
225
|
+
return ({ core }) => core.depth > 0
|
|
226
|
+
? undefined
|
|
227
|
+
: createTelemetryExtension({
|
|
228
|
+
emit: (event) => core.emit(event),
|
|
229
|
+
ticks: ui?.animation !== false,
|
|
230
|
+
});
|
|
231
|
+
}
|
|
@@ -13,6 +13,8 @@
|
|
|
13
13
|
import { randomUUID } from "node:crypto";
|
|
14
14
|
import { DEFAULT_APPROVAL_TIMEOUT_MS } from "../permissions/broker.js";
|
|
15
15
|
import { previewAction } from "../permissions/preview.js";
|
|
16
|
+
import { PermissionPipeline } from "../permissions/pipeline.js";
|
|
17
|
+
import { classifierRequest } from "./session-classifier.js";
|
|
16
18
|
import { runSingleToolCall } from "./tool-runner.js";
|
|
17
19
|
/** 外层是这个工具时,嵌套调用的 Hook 输入带 `viaCodemode: true`。 */
|
|
18
20
|
const CODEMODE_TOOL_NAME = "codemode";
|
|
@@ -21,6 +23,35 @@ function textOf(content) {
|
|
|
21
23
|
return content;
|
|
22
24
|
return content.map((block) => (block.type === "text" ? block.text : "")).join("");
|
|
23
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* [W5-EG] `permission_request.context`:子 Agent(depth、taskId)与外部 Agent(origin)的来源,供
|
|
28
|
+
* RPC 客户端与对话框标注。ama 子会话的请求没带 taskId 时取子会话首条 `custom{ama.task}`;
|
|
29
|
+
* 主会话自己的调用返回 undefined(事件形状不变)。
|
|
30
|
+
*/
|
|
31
|
+
function requestContext(core, request) {
|
|
32
|
+
const source = request.context;
|
|
33
|
+
const depth = Math.max(source?.depth ?? 0, core.depth);
|
|
34
|
+
let taskId = source?.taskId;
|
|
35
|
+
if (taskId === undefined && core.depth > 0) {
|
|
36
|
+
const head = core.manager
|
|
37
|
+
.branch()
|
|
38
|
+
.find((e) => e.type === "custom" && e.customType === "ama.task");
|
|
39
|
+
const data = head?.type === "custom" ? head.data : undefined;
|
|
40
|
+
if (typeof data?.taskId === "string")
|
|
41
|
+
taskId = data.taskId;
|
|
42
|
+
}
|
|
43
|
+
const origin = source?.origin;
|
|
44
|
+
if (depth === 0 && taskId === undefined && origin === undefined)
|
|
45
|
+
return undefined;
|
|
46
|
+
const context = {};
|
|
47
|
+
if (depth > 0)
|
|
48
|
+
context.depth = depth;
|
|
49
|
+
if (taskId !== undefined)
|
|
50
|
+
context.taskId = taskId;
|
|
51
|
+
if (origin !== undefined)
|
|
52
|
+
context.origin = origin;
|
|
53
|
+
return context;
|
|
54
|
+
}
|
|
24
55
|
/** 审批链:依次问每个 broker,第一个给出决定的为准;全部弃权 → deny。 */
|
|
25
56
|
export async function requestApproval(core, request, signal) {
|
|
26
57
|
const timeoutMs = core.options.approvalTimeoutMs ?? DEFAULT_APPROVAL_TIMEOUT_MS;
|
|
@@ -36,6 +67,11 @@ export async function requestApproval(core, request, signal) {
|
|
|
36
67
|
event.hookReason = request.hookReason;
|
|
37
68
|
if (request.preview !== undefined)
|
|
38
69
|
event.preview = request.preview;
|
|
70
|
+
if (request.autoDecision !== undefined)
|
|
71
|
+
event.autoDecision = request.autoDecision;
|
|
72
|
+
const context = requestContext(core, request);
|
|
73
|
+
if (context !== undefined)
|
|
74
|
+
event.context = context;
|
|
39
75
|
core.emit(event);
|
|
40
76
|
void core.runHook("Notification", {
|
|
41
77
|
notification: { kind: "approval", message: `approval requested for ${request.toolName}` },
|
|
@@ -117,6 +153,7 @@ export async function gateToolCall(core, call, ctx) {
|
|
|
117
153
|
let decision = hookDecision === "ask" ? "ask" : "allow";
|
|
118
154
|
let approvalReason = "hook";
|
|
119
155
|
let denyMessage;
|
|
156
|
+
let autoDecision;
|
|
120
157
|
if (permission !== undefined) {
|
|
121
158
|
const checkInput = {
|
|
122
159
|
toolName: call.name,
|
|
@@ -132,12 +169,29 @@ export async function gateToolCall(core, call, ctx) {
|
|
|
132
169
|
decision = verdict.decision;
|
|
133
170
|
approvalReason = verdict.approvalReason ?? "mode";
|
|
134
171
|
denyMessage = verdict.message;
|
|
172
|
+
autoDecision = verdict.auto;
|
|
173
|
+
if (verdict.classify === true) {
|
|
174
|
+
// auto 第 3 层:规则层与静态判定都没决定,问一次独立的模型分类器(只能变 allow)
|
|
175
|
+
const judged = await core
|
|
176
|
+
.autoClassifier()
|
|
177
|
+
.classify(classifierRequest(core, call.name, input, permission.projectRoot, verdict.sandboxed === true && permission instanceof PermissionPipeline
|
|
178
|
+
? { network: permission.bashSandbox?.network ?? "deny" }
|
|
179
|
+
: undefined), ctx.signal);
|
|
180
|
+
autoDecision = { layer: "classifier", decision: judged.decision, reason: judged.reason };
|
|
181
|
+
if (judged.cached)
|
|
182
|
+
autoDecision.cached = true;
|
|
183
|
+
if (judged.decision === "allow")
|
|
184
|
+
decision = "allow";
|
|
185
|
+
}
|
|
186
|
+
if (autoDecision !== undefined)
|
|
187
|
+
permission.recordAutoDecision?.(call.name, input, autoDecision);
|
|
135
188
|
}
|
|
136
189
|
else if (decision === "ask" && core.options.unattended === true) {
|
|
137
190
|
decision = "deny";
|
|
138
191
|
}
|
|
192
|
+
const withAuto = (gate) => autoDecision === undefined ? gate : { ...gate, autoDecision };
|
|
139
193
|
if (decision === "deny") {
|
|
140
|
-
return { block: true, reason: denyMessage ?? `Permission denied for ${call.name}` };
|
|
194
|
+
return withAuto({ block: true, reason: denyMessage ?? `Permission denied for ${call.name}` });
|
|
141
195
|
}
|
|
142
196
|
if (decision === "ask") {
|
|
143
197
|
const request = {
|
|
@@ -149,16 +203,18 @@ export async function gateToolCall(core, call, ctx) {
|
|
|
149
203
|
};
|
|
150
204
|
if (hookReason !== undefined)
|
|
151
205
|
request.hookReason = hookReason;
|
|
206
|
+
if (autoDecision !== undefined)
|
|
207
|
+
request.autoDecision = autoDecision;
|
|
152
208
|
const preview = safePreview(core, request);
|
|
153
209
|
if (preview !== undefined)
|
|
154
210
|
request.preview = preview;
|
|
155
211
|
const answer = await requestApproval(core, request, ctx.signal);
|
|
156
212
|
if (answer === "deny")
|
|
157
|
-
return { block: true, reason: `The user denied ${call.name}` };
|
|
213
|
+
return withAuto({ block: true, reason: `The user denied ${call.name}` });
|
|
158
214
|
if (answer === "allow_session")
|
|
159
215
|
permission?.rememberForSession(call.name, input);
|
|
160
216
|
}
|
|
161
|
-
return replaced ? { input } : {};
|
|
217
|
+
return withAuto(replaced ? { input } : {});
|
|
162
218
|
}
|
|
163
219
|
export async function afterToolCall(core, call, result, parent) {
|
|
164
220
|
if (core.options.hooks?.has("PostToolUse", call.name) !== true)
|
|
@@ -250,6 +306,10 @@ export function createToolContext(core, runner, call, signal, onUpdate) {
|
|
|
250
306
|
const extra = {};
|
|
251
307
|
if (file !== undefined)
|
|
252
308
|
extra.sessionFile = file;
|
|
309
|
+
// [RW-B] 检查点钩子:主会话有后端时为它,task 子会话为父会话的(记到父会话当前回合)
|
|
310
|
+
const checkpoint = core.checkpointHooks?.();
|
|
311
|
+
if (checkpoint !== undefined)
|
|
312
|
+
extra.checkpoint = checkpoint;
|
|
253
313
|
if (outputDir !== undefined)
|
|
254
314
|
extra.outputDir = outputDir;
|
|
255
315
|
if (core.depth === 0 && core.options.subagents !== false) {
|
package/dist/agent/session.d.ts
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* AgentSessionImpl(设计 §4.2–§4.3、§9、§11.1 第 16 步、§13.1)。[B2]
|
|
3
3
|
*
|
|
4
|
-
* 会话 = SessionManager(JSONL 树,事实来源)+ Agent
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* - `steer()` / `followUp()`:运行中入队(返回 "queued");空闲时直接以该消息开始一个周期("handled")。
|
|
11
|
-
* - `abort()`:中断供应商流、工具、重试等待与压缩;回到 idle 后 resolve;不清队列。
|
|
4
|
+
* 会话 = SessionManager(JSONL 树,事实来源)+ Agent(上下文、队列、run)+ 压缩 / 重试 / Hook / 回滚调度。
|
|
5
|
+
* 每条 message_end 落盘;首次请求前落 system + 工具表并 flush。`prompt()` 运行中且无
|
|
6
|
+
* streamingBehavior → busy;`steer / followUp` 运行中入队、空闲时直接开周期;`abort()` 不清队列。
|
|
7
|
+
* [W5-C0] 设置类方法在 session-settings.ts;扩展点(session-extensions.ts)的调用点:构造时
|
|
8
|
+
* wrapStream、emit 后 onEvent、runPrompt 的 beforePrompts、agent_settled 后 onAgentSettled、
|
|
9
|
+
* getStats 末尾 contributeStats、dispose。
|
|
12
10
|
*/
|
|
13
11
|
import type { Model, ModelThinkingLevel } from "../ai/types.js";
|
|
14
12
|
import type { HookEvent, HookEventPayload, HookOutcome } from "../hooks/types.js";
|
|
13
|
+
import type { PermissionClassifier } from "../permissions/classifier.js";
|
|
15
14
|
import type { PermissionMode } from "../permissions/types.js";
|
|
16
15
|
import type { SessionManager } from "../session/manager.js";
|
|
17
16
|
import type { AgentMessage, BranchSummaryEntry, SessionEntry, SessionEntryInput } from "../session/types.js";
|
|
@@ -20,7 +19,9 @@ import { Agent } from "./agent.js";
|
|
|
20
19
|
import type { StreamFn } from "./loop.js";
|
|
21
20
|
import type { AgentSessionOptions, SessionCore } from "./session-core.js";
|
|
22
21
|
import { SessionCacheController } from "./session-cache.js";
|
|
23
|
-
import type
|
|
22
|
+
import { type StaticSystemInput } from "./session-settings.js";
|
|
23
|
+
import { type RewindDraft, type SummarizeFromResult } from "./session-rewind.js";
|
|
24
|
+
import type * as CP from "../checkpoints/types.js";
|
|
24
25
|
import type { AgentSession, CompactionResult, EnqueueOptions, PromptDisposition, PromptOptions, SessionEvent, SessionState, SessionStats } from "./types.js";
|
|
25
26
|
export type { AgentSessionOptions } from "./session-core.js";
|
|
26
27
|
export declare class AgentSessionImpl implements AgentSession, SessionCore {
|
|
@@ -32,10 +33,8 @@ export declare class AgentSessionImpl implements AgentSession, SessionCore {
|
|
|
32
33
|
readonly readFiles: Set<string>;
|
|
33
34
|
readonly stream: StreamFn;
|
|
34
35
|
readonly cache: SessionCacheController;
|
|
35
|
-
private
|
|
36
|
-
private
|
|
37
|
-
private readonly allTools;
|
|
38
|
-
private activeNames;
|
|
36
|
+
private readonly settings;
|
|
37
|
+
private readonly extensions;
|
|
39
38
|
private readonly listeners;
|
|
40
39
|
private readonly compaction;
|
|
41
40
|
private retrySettings;
|
|
@@ -44,11 +43,12 @@ export declare class AgentSessionImpl implements AgentSession, SessionCore {
|
|
|
44
43
|
private stopReason;
|
|
45
44
|
private stopFlag;
|
|
46
45
|
private turns;
|
|
47
|
-
private systemInput;
|
|
48
46
|
private readonly subagentPool;
|
|
49
47
|
private disposed;
|
|
48
|
+
private classifier;
|
|
50
49
|
/** 已入队、尚未投递的消息(投递时发 queue_update)。 */
|
|
51
50
|
private readonly queuedMessages;
|
|
51
|
+
private readonly rewinder;
|
|
52
52
|
constructor(options: AgentSessionOptions);
|
|
53
53
|
model(): Model;
|
|
54
54
|
thinkingLevel(): ModelThinkingLevel;
|
|
@@ -81,29 +81,32 @@ export declare class AgentSessionImpl implements AgentSession, SessionCore {
|
|
|
81
81
|
followUp: string[];
|
|
82
82
|
};
|
|
83
83
|
subscribe(listener: (event: SessionEvent) => void): () => void;
|
|
84
|
-
/** 手动压缩;运行中 → busy
|
|
85
|
-
compact(instructions?: string): Promise<CompactionResult>;
|
|
84
|
+
/** 手动压缩;运行中 → busy。`cutAt`:以该条目为切点(「摘要到这里」)。 */
|
|
85
|
+
compact(instructions?: string, cutAt?: string): Promise<CompactionResult>;
|
|
86
|
+
readonly rewindPoints: () => CP.RewindPoint[];
|
|
87
|
+
readonly rewind: (request: CP.RewindRequest) => Promise<CP.RewindResult>;
|
|
88
|
+
readonly summarizeFrom: (entryId: string, instructions?: string) => Promise<SummarizeFromResult>;
|
|
89
|
+
readonly summarizeUpTo: (entryId: string, instructions?: string) => Promise<CompactionResult>;
|
|
90
|
+
readonly canUndoAbortedTurn: () => boolean;
|
|
91
|
+
readonly undoAbortedTurn: () => Promise<RewindDraft | undefined>;
|
|
92
|
+
readonly checkpointHooks: () => CP.CheckpointHooks | undefined;
|
|
86
93
|
fork(entryId: string): Promise<AgentSessionImpl>;
|
|
87
|
-
/**
|
|
88
|
-
* `/tree`:同文件换叶子;`summarize` 时为离开的分支写 branch_summary(挂在新叶子下)。
|
|
89
|
-
*/
|
|
94
|
+
/** `/tree`:同文件换叶子;`summarize` 时为离开的分支写 branch_summary(挂在新叶子下)。 */
|
|
90
95
|
navigate(targetId: string | null, options?: {
|
|
91
96
|
summarize?: boolean;
|
|
92
97
|
instructions?: string;
|
|
93
98
|
}): Promise<BranchSummaryEntry | undefined>;
|
|
94
|
-
setModel(ref: string)
|
|
95
|
-
setThinkingLevel(level: ModelThinkingLevel)
|
|
96
|
-
setPermissionMode(mode: PermissionMode)
|
|
97
|
-
setActiveTools(names: string[])
|
|
99
|
+
readonly setModel: (ref: string) => Promise<void>;
|
|
100
|
+
readonly setThinkingLevel: (level: ModelThinkingLevel) => void;
|
|
101
|
+
readonly setPermissionMode: (mode: PermissionMode) => void;
|
|
102
|
+
readonly setActiveTools: (names: string[]) => void;
|
|
98
103
|
/** 宿主 / SDK 在会话创建后追加工具(下次请求前以 system 补丁声明)。 */
|
|
99
|
-
addTool(tool: ToolDefinition, active?: boolean)
|
|
100
|
-
|
|
101
|
-
|
|
104
|
+
readonly addTool: (tool: ToolDefinition, active?: boolean) => void;
|
|
105
|
+
readonly updateSystem: (patch: Partial<StaticSystemInput>) => void;
|
|
106
|
+
readonly getTools: () => readonly ToolDefinition[];
|
|
107
|
+
readonly announceStart: (reason: "startup" | "resume" | "new" | "fork") => void;
|
|
102
108
|
setAutoCompaction(enabled: boolean): void;
|
|
103
109
|
setAutoRetry(enabled: boolean): void;
|
|
104
|
-
getTools(): readonly ToolDefinition[];
|
|
105
|
-
/** 发 session_start(bootstrap / SDK 在会话就绪后调用一次)。 */
|
|
106
|
-
announceStart(reason: "startup" | "resume" | "new" | "fork"): void;
|
|
107
110
|
get state(): SessionState;
|
|
108
111
|
get messages(): readonly AgentMessage[];
|
|
109
112
|
get entries(): readonly SessionEntry[];
|
|
@@ -113,5 +116,6 @@ export declare class AgentSessionImpl implements AgentSession, SessionCore {
|
|
|
113
116
|
getStats(): SessionStats;
|
|
114
117
|
dispose(): Promise<void>;
|
|
115
118
|
childBase(): Pick<AgentSessionOptions, "model" | "thinkingLevel" | "activeTools" | "system">;
|
|
119
|
+
autoClassifier(): PermissionClassifier;
|
|
116
120
|
spawnSubagent(request: SubagentRequest): Promise<SubagentResult>;
|
|
117
121
|
}
|