@armadra/agent 0.4.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +184 -1
- package/README.md +202 -83
- package/THIRD_PARTY_NOTICES.md +34 -0
- package/dist/acp.d.ts +18 -0
- package/dist/acp.js +19 -0
- package/dist/agent/limits.d.ts +38 -0
- package/dist/agent/limits.js +127 -0
- package/dist/agent/loop-guard.d.ts +38 -0
- package/dist/agent/loop-guard.js +95 -0
- package/dist/agent/loop.d.ts +4 -0
- package/dist/agent/loop.js +7 -0
- package/dist/agent/prompt-rules.d.ts +12 -0
- package/dist/agent/prompt-rules.js +18 -0
- package/dist/agent/reminders.d.ts +59 -0
- package/dist/agent/reminders.js +327 -0
- package/dist/agent/session-cache.d.ts +5 -0
- package/dist/agent/session-cache.js +17 -1
- package/dist/agent/session-classifier.d.ts +1 -1
- package/dist/agent/session-classifier.js +3 -1
- package/dist/agent/session-compaction.d.ts +35 -6
- package/dist/agent/session-compaction.js +157 -31
- package/dist/agent/session-core.d.ts +27 -1
- package/dist/agent/session-extensions.d.ts +61 -0
- package/dist/agent/session-extensions.js +129 -0
- package/dist/agent/session-images.d.ts +23 -0
- package/dist/agent/session-images.js +97 -0
- package/dist/agent/session-plan.d.ts +21 -0
- package/dist/agent/session-plan.js +524 -0
- package/dist/agent/session-rewind.d.ts +81 -0
- package/dist/agent/session-rewind.js +354 -0
- package/dist/agent/session-run.d.ts +28 -1
- package/dist/agent/session-run.js +157 -6
- package/dist/agent/session-settings.d.ts +49 -0
- package/dist/agent/session-settings.js +95 -0
- package/dist/agent/session-subagent.d.ts +36 -24
- package/dist/agent/session-subagent.js +259 -129
- package/dist/agent/session-sync.d.ts +10 -3
- package/dist/agent/session-sync.js +37 -8
- package/dist/agent/session-telemetry.d.ts +39 -0
- package/dist/agent/session-telemetry.js +231 -0
- package/dist/agent/session-tools.js +40 -1
- package/dist/agent/session.d.ts +30 -29
- package/dist/agent/session.js +79 -123
- package/dist/agent/subagent-registry.d.ts +91 -0
- package/dist/agent/subagent-registry.js +494 -0
- package/dist/agent/system-prompt.d.ts +6 -3
- package/dist/agent/system-prompt.js +7 -2
- package/dist/agent/tool-runner.d.ts +8 -1
- package/dist/agent/tool-runner.js +57 -4
- package/dist/agent/types-w5.d.ts +192 -0
- package/dist/agent/types-w5.js +10 -0
- package/dist/agent/types.d.ts +47 -4
- package/dist/agent/types.js +2 -0
- package/dist/agent/worktree.d.ts +36 -0
- package/dist/agent/worktree.js +86 -0
- package/dist/agents/builtin.d.ts +14 -0
- package/dist/agents/builtin.js +39 -0
- package/dist/agents/catalog.d.ts +43 -0
- package/dist/agents/catalog.js +82 -0
- package/dist/agents/discover.d.ts +35 -0
- package/dist/agents/discover.js +83 -0
- package/dist/agents/external.d.ts +82 -0
- package/dist/agents/external.js +326 -0
- package/dist/agents/parse.d.ts +18 -0
- package/dist/agents/parse.js +116 -0
- package/dist/agents/result.d.ts +32 -0
- package/dist/agents/result.js +67 -0
- package/dist/agents/task-control.d.ts +17 -0
- package/dist/agents/task-control.js +17 -0
- package/dist/agents/task-record.d.ts +78 -0
- package/dist/agents/task-record.js +141 -0
- package/dist/agents/types.d.ts +46 -0
- package/dist/agents/types.js +8 -0
- package/dist/ai/apis/anthropic-compat.d.ts +36 -0
- package/dist/ai/apis/anthropic-compat.js +92 -0
- package/dist/ai/apis/anthropic-request.d.ts +7 -6
- package/dist/ai/apis/anthropic-request.js +10 -28
- package/dist/ai/apis/cache-params.d.ts +11 -2
- package/dist/ai/apis/cache-params.js +25 -6
- package/dist/ai/apis/openai-compat.d.ts +4 -1
- package/dist/ai/apis/openai-compat.js +8 -1
- package/dist/ai/image-limits.d.ts +45 -0
- package/dist/ai/image-limits.js +68 -0
- package/dist/ai/providers/builtin.d.ts +18 -6
- package/dist/ai/providers/builtin.js +135 -6
- package/dist/ai/providers/catalog-data.js +17 -13
- package/dist/ai/providers/catalog.d.ts +60 -7
- package/dist/ai/providers/catalog.js +197 -38
- package/dist/ai/providers/channels.d.ts +33 -3
- package/dist/ai/providers/channels.js +108 -7
- package/dist/ai/providers/enrich.d.ts +6 -3
- package/dist/ai/providers/enrich.js +19 -4
- package/dist/ai/providers/models-dev-cache.d.ts +28 -24
- package/dist/ai/providers/models-dev-cache.js +92 -78
- package/dist/ai/providers/models-dev-data.d.ts +7 -0
- package/dist/ai/providers/models-dev-data.js +32 -0
- package/dist/ai/providers/models-dev-snapshot.d.ts +50 -0
- package/dist/ai/providers/models-dev-snapshot.js +137 -0
- package/dist/ai/providers/models-dev.d.ts +51 -10
- package/dist/ai/providers/models-dev.js +132 -39
- package/dist/ai/providers/registry.d.ts +20 -10
- package/dist/ai/providers/registry.js +82 -43
- package/dist/ai/types.d.ts +28 -2
- package/dist/ai/types.js +5 -0
- package/dist/bundle/ama.cjs +37605 -21619
- package/dist/checkpoints/backend.d.ts +61 -0
- package/dist/checkpoints/backend.js +135 -0
- package/dist/checkpoints/blobs.d.ts +60 -0
- package/dist/checkpoints/blobs.js +203 -0
- package/dist/checkpoints/gc.d.ts +47 -0
- package/dist/checkpoints/gc.js +144 -0
- package/dist/checkpoints/git-head.d.ts +15 -0
- package/dist/checkpoints/git-head.js +89 -0
- package/dist/checkpoints/index.d.ts +17 -0
- package/dist/checkpoints/index.js +17 -0
- package/dist/checkpoints/replay.d.ts +48 -0
- package/dist/checkpoints/replay.js +154 -0
- package/dist/checkpoints/restore.d.ts +86 -0
- package/dist/checkpoints/restore.js +263 -0
- package/dist/checkpoints/settings.d.ts +14 -0
- package/dist/checkpoints/settings.js +23 -0
- package/dist/checkpoints/shadow-git.d.ts +108 -0
- package/dist/checkpoints/shadow-git.js +491 -0
- package/dist/checkpoints/shadow-restore.d.ts +25 -0
- package/dist/checkpoints/shadow-restore.js +128 -0
- package/dist/checkpoints/tracker.d.ts +64 -0
- package/dist/checkpoints/tracker.js +192 -0
- package/dist/checkpoints/types.d.ts +99 -0
- package/dist/checkpoints/types.js +12 -0
- package/dist/cli/args.d.ts +8 -4
- package/dist/cli/args.js +17 -97
- package/dist/cli/bootstrap.js +13 -1
- package/dist/cli/choice-prompt.d.ts +58 -0
- package/dist/cli/choice-prompt.js +140 -0
- package/dist/cli/codemode-notice.d.ts +3 -2
- package/dist/cli/codemode-notice.js +3 -2
- package/dist/cli/compose-agents.d.ts +27 -0
- package/dist/cli/compose-agents.js +111 -0
- package/dist/cli/compose-extensions.d.ts +29 -0
- package/dist/cli/compose-extensions.js +44 -0
- package/dist/cli/compose-session.d.ts +3 -0
- package/dist/cli/compose-session.js +47 -4
- package/dist/cli/compose.d.ts +3 -0
- package/dist/cli/compose.js +33 -6
- package/dist/cli/deps.d.ts +6 -0
- package/dist/cli/exit-codes.d.ts +10 -0
- package/dist/cli/exit-codes.js +12 -0
- package/dist/cli/help-text.d.ts +4 -0
- package/dist/cli/help-text.js +102 -0
- package/dist/cli/startup-screen.js +5 -3
- package/dist/cli/startup-steps.js +7 -1
- package/dist/cli/subcommands/config.d.ts +4 -1
- package/dist/cli/subcommands/config.js +17 -6
- package/dist/cli/subcommands/doctor.js +21 -0
- package/dist/cli/subcommands/models-cache-probe.d.ts +1 -1
- package/dist/cli/subcommands/models-cache-probe.js +3 -12
- package/dist/cli/subcommands/models-discover.js +5 -6
- package/dist/cli/subcommands/models.d.ts +2 -0
- package/dist/cli/subcommands/models.js +33 -14
- package/dist/cli/subcommands/providers.d.ts +1 -1
- package/dist/cli/subcommands/providers.js +8 -15
- package/dist/cli/subcommands/sessions.d.ts +3 -1
- package/dist/cli/subcommands/sessions.js +36 -2
- package/dist/codemode/capability.d.ts +24 -7
- package/dist/codemode/capability.js +38 -10
- package/dist/codemode/host-side.d.ts +14 -0
- package/dist/codemode/host-side.js +24 -1
- package/dist/codemode/tool.d.ts +1 -1
- package/dist/codemode/tool.js +6 -4
- package/dist/compaction/breaker.d.ts +25 -9
- package/dist/compaction/breaker.js +47 -17
- package/dist/compaction/estimate.d.ts +11 -3
- package/dist/compaction/estimate.js +64 -22
- package/dist/compaction/image-budget.d.ts +45 -0
- package/dist/compaction/image-budget.js +115 -0
- package/dist/compaction/post-compact.d.ts +38 -0
- package/dist/compaction/post-compact.js +152 -0
- package/dist/compaction/protect.d.ts +27 -0
- package/dist/compaction/protect.js +56 -0
- package/dist/compaction/prune-tier.d.ts +58 -12
- package/dist/compaction/prune-tier.js +120 -54
- package/dist/compaction/summarize-tier.d.ts +23 -4
- package/dist/compaction/summarize-tier.js +100 -29
- package/dist/config/checker.d.ts +28 -0
- package/dist/config/checker.js +97 -0
- package/dist/config/json-schema.js +63 -2
- package/dist/config/key-docs.js +72 -3
- package/dist/config/merge.d.ts +5 -3
- package/dist/config/merge.js +81 -7
- package/dist/config/profile.d.ts +2 -0
- package/dist/config/profile.js +2 -0
- package/dist/config/schema-w5.d.ts +18 -0
- package/dist/config/schema-w5.js +109 -0
- package/dist/config/schema.d.ts +5 -9
- package/dist/config/schema.js +68 -114
- package/dist/config/types-w5.d.ts +118 -0
- package/dist/config/types-w5.js +20 -0
- package/dist/config/types.d.ts +50 -1
- package/dist/config/types.js +12 -0
- package/dist/drivers/acp/client.d.ts +57 -0
- package/dist/drivers/acp/client.js +160 -0
- package/dist/drivers/acp/driver.d.ts +31 -0
- package/dist/drivers/acp/driver.js +274 -0
- package/dist/drivers/acp/testing/fake-agent-main.d.ts +5 -0
- package/dist/drivers/acp/testing/fake-agent-main.js +7 -0
- package/dist/drivers/acp/testing/fake-agent.d.ts +27 -0
- package/dist/drivers/acp/testing/fake-agent.js +211 -0
- package/dist/drivers/acp/types.d.ts +285 -0
- package/dist/drivers/acp/types.js +36 -0
- package/dist/drivers/agents.d.ts +58 -0
- package/dist/drivers/agents.js +142 -0
- package/dist/drivers/base.d.ts +35 -0
- package/dist/drivers/base.js +59 -0
- package/dist/drivers/catalog.d.ts +46 -0
- package/dist/drivers/catalog.js +167 -0
- package/dist/drivers/env.d.ts +20 -0
- package/dist/drivers/env.js +46 -0
- package/dist/drivers/host-runners.d.ts +18 -0
- package/dist/drivers/host-runners.js +45 -0
- package/dist/drivers/jsonrpc.d.ts +58 -0
- package/dist/drivers/jsonrpc.js +180 -0
- package/dist/drivers/native/claude-normalize.d.ts +46 -0
- package/dist/drivers/native/claude-normalize.js +106 -0
- package/dist/drivers/native/claude-stream.d.ts +29 -0
- package/dist/drivers/native/claude-stream.js +456 -0
- package/dist/drivers/native/codex-app-server.d.ts +26 -0
- package/dist/drivers/native/codex-app-server.js +407 -0
- package/dist/drivers/native/codex-normalize.d.ts +38 -0
- package/dist/drivers/native/codex-normalize.js +124 -0
- package/dist/drivers/native/oneshot.d.ts +28 -0
- package/dist/drivers/native/oneshot.js +312 -0
- package/dist/drivers/permissions.d.ts +40 -0
- package/dist/drivers/permissions.js +92 -0
- package/dist/drivers/pids.d.ts +32 -0
- package/dist/drivers/pids.js +93 -0
- package/dist/drivers/pool.d.ts +28 -0
- package/dist/drivers/pool.js +96 -0
- package/dist/drivers/probe.d.ts +47 -0
- package/dist/drivers/probe.js +172 -0
- package/dist/drivers/process.d.ts +48 -0
- package/dist/drivers/process.js +100 -0
- package/dist/drivers/runner.d.ts +61 -0
- package/dist/drivers/runner.js +388 -0
- package/dist/drivers/store.d.ts +49 -0
- package/dist/drivers/store.js +91 -0
- package/dist/drivers/turn.d.ts +41 -0
- package/dist/drivers/turn.js +99 -0
- package/dist/drivers/types.d.ts +122 -0
- package/dist/drivers/types.js +11 -0
- package/dist/git/info.d.ts +75 -0
- package/dist/git/info.js +191 -0
- package/dist/hooks/protocol.js +6 -1
- package/dist/hooks/types.d.ts +10 -1
- package/dist/hooks/types.js +2 -0
- package/dist/host/api-impl.d.ts +7 -0
- package/dist/host/api-impl.js +15 -0
- package/dist/host/types.d.ts +24 -2
- package/dist/host/types.js +4 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +1 -0
- package/dist/modes/acp/acp-events.d.ts +46 -0
- package/dist/modes/acp/acp-events.js +233 -0
- package/dist/modes/acp/acp-mode.d.ts +17 -0
- package/dist/modes/acp/acp-mode.js +47 -0
- package/dist/modes/acp/acp-server.d.ts +79 -0
- package/dist/modes/acp/acp-server.js +315 -0
- package/dist/modes/commands-core.d.ts +13 -1
- package/dist/modes/commands-core.js +64 -0
- package/dist/modes/image-input.d.ts +12 -4
- package/dist/modes/image-input.js +22 -5
- package/dist/modes/interactive/agent-panels.d.ts +14 -0
- package/dist/modes/interactive/agent-panels.js +103 -0
- package/dist/modes/interactive/agent-ui.d.ts +73 -0
- package/dist/modes/interactive/agent-ui.js +234 -0
- package/dist/modes/interactive/approval-dialog.d.ts +21 -4
- package/dist/modes/interactive/approval-dialog.js +98 -20
- package/dist/modes/interactive/approval-merge.d.ts +41 -0
- package/dist/modes/interactive/approval-merge.js +89 -0
- package/dist/modes/interactive/clipboard-paste.d.ts +18 -0
- package/dist/modes/interactive/clipboard-paste.js +28 -0
- package/dist/modes/interactive/commands.d.ts +12 -1
- package/dist/modes/interactive/commands.js +31 -1
- package/dist/modes/interactive/confirm-dialog.d.ts +49 -0
- package/dist/modes/interactive/confirm-dialog.js +121 -0
- package/dist/modes/interactive/double-esc.d.ts +20 -0
- package/dist/modes/interactive/double-esc.js +34 -0
- package/dist/modes/interactive/event-notices.d.ts +32 -0
- package/dist/modes/interactive/event-notices.js +79 -0
- package/dist/modes/interactive/external-editor.d.ts +16 -0
- package/dist/modes/interactive/external-editor.js +39 -0
- package/dist/modes/interactive/interactive-mode.d.ts +14 -1
- package/dist/modes/interactive/interactive-mode.js +140 -136
- package/dist/modes/interactive/key-dispatch.d.ts +22 -2
- package/dist/modes/interactive/key-dispatch.js +66 -7
- package/dist/modes/interactive/line/line-mode.d.ts +4 -1
- package/dist/modes/interactive/line/line-mode.js +31 -5
- package/dist/modes/interactive/line/line-render.d.ts +2 -1
- package/dist/modes/interactive/line/line-render.js +40 -4
- package/dist/modes/interactive/message-view.d.ts +1 -1
- package/dist/modes/interactive/message-view.js +24 -2
- package/dist/modes/interactive/panels.d.ts +18 -1
- package/dist/modes/interactive/panels.js +19 -5
- package/dist/modes/interactive/plan-command.d.ts +40 -0
- package/dist/modes/interactive/plan-command.js +129 -0
- package/dist/modes/interactive/plan-dialog.d.ts +98 -0
- package/dist/modes/interactive/plan-dialog.js +290 -0
- package/dist/modes/interactive/plan-flow.d.ts +34 -0
- package/dist/modes/interactive/plan-flow.js +98 -0
- package/dist/modes/interactive/rewind-command.d.ts +31 -0
- package/dist/modes/interactive/rewind-command.js +106 -0
- package/dist/modes/interactive/rewind-flow.d.ts +37 -0
- package/dist/modes/interactive/rewind-flow.js +151 -0
- package/dist/modes/interactive/rewind-list.d.ts +36 -0
- package/dist/modes/interactive/rewind-list.js +123 -0
- package/dist/modes/interactive/rewind-panel.d.ts +77 -0
- package/dist/modes/interactive/rewind-panel.js +309 -0
- package/dist/modes/interactive/rewind-text.d.ts +40 -0
- package/dist/modes/interactive/rewind-text.js +139 -0
- package/dist/modes/interactive/session-events.d.ts +24 -0
- package/dist/modes/interactive/session-events.js +96 -0
- package/dist/modes/interactive/startup-ui.js +5 -1
- package/dist/modes/interactive/status-area.d.ts +73 -0
- package/dist/modes/interactive/status-area.js +190 -0
- package/dist/modes/interactive/status-bar.d.ts +99 -11
- package/dist/modes/interactive/status-bar.js +273 -90
- package/dist/modes/interactive/status-line.d.ts +33 -0
- package/dist/modes/interactive/status-line.js +113 -0
- package/dist/modes/interactive/subagent-view.d.ts +56 -0
- package/dist/modes/interactive/subagent-view.js +154 -0
- package/dist/modes/interactive/tasks-report.d.ts +27 -0
- package/dist/modes/interactive/tasks-report.js +114 -0
- package/dist/modes/interactive/tool-view.d.ts +12 -2
- package/dist/modes/interactive/tool-view.js +34 -4
- package/dist/modes/print/print-mode.d.ts +13 -4
- package/dist/modes/print/print-mode.js +56 -12
- package/dist/modes/rpc/commands.d.ts +9 -0
- package/dist/modes/rpc/commands.js +44 -0
- package/dist/modes/rpc/rpc-mode.js +7 -1
- package/dist/modes/session-report.d.ts +11 -0
- package/dist/modes/session-report.js +48 -1
- package/dist/permissions/auto-safe.d.ts +5 -0
- package/dist/permissions/auto-safe.js +18 -0
- package/dist/permissions/bypass.d.ts +32 -0
- package/dist/permissions/bypass.js +36 -0
- package/dist/permissions/classifier.d.ts +4 -0
- package/dist/permissions/classifier.js +2 -0
- package/dist/permissions/modes.js +1 -1
- package/dist/permissions/pipeline.d.ts +43 -4
- package/dist/permissions/pipeline.js +114 -9
- package/dist/permissions/readonly-bash.d.ts +30 -0
- package/dist/permissions/readonly-bash.js +118 -0
- package/dist/permissions/types.d.ts +42 -0
- package/dist/plan/compose.d.ts +9 -0
- package/dist/plan/compose.js +19 -0
- package/dist/plan/controller.d.ts +71 -0
- package/dist/plan/controller.js +27 -0
- package/dist/plan/done-markers.d.ts +17 -0
- package/dist/plan/done-markers.js +51 -0
- package/dist/plan/extract.d.ts +29 -0
- package/dist/plan/extract.js +160 -0
- package/dist/plan/prompts.d.ts +36 -0
- package/dist/plan/prompts.js +89 -0
- package/dist/plan/store.d.ts +37 -0
- package/dist/plan/store.js +90 -0
- package/dist/rpc.d.ts +58 -2
- package/dist/rpc.js +7 -0
- package/dist/sandbox/bash.d.ts +74 -0
- package/dist/sandbox/bash.js +126 -0
- package/dist/sandbox/detect.d.ts +48 -0
- package/dist/sandbox/detect.js +149 -0
- package/dist/sandbox/index.d.ts +5 -0
- package/dist/sandbox/index.js +5 -0
- package/dist/sandbox/profile.d.ts +33 -0
- package/dist/sandbox/profile.js +76 -0
- package/dist/sandbox/wrap.d.ts +29 -0
- package/dist/sandbox/wrap.js +117 -0
- package/dist/sdk.d.ts +33 -2
- package/dist/sdk.js +24 -2
- package/dist/session/types.d.ts +3 -1
- package/dist/session/types.js +1 -0
- package/dist/skills/builtin.d.ts +31 -0
- package/dist/skills/builtin.js +109 -0
- package/dist/skills/discover.d.ts +2 -1
- package/dist/skills/index-prompt.js +5 -8
- package/dist/tools/background-jobs.d.ts +71 -0
- package/dist/tools/background-jobs.js +198 -0
- package/dist/tools/bash.d.ts +53 -1
- package/dist/tools/bash.js +158 -7
- package/dist/tools/clipboard-image.d.ts +44 -0
- package/dist/tools/clipboard-image.js +148 -0
- package/dist/tools/edit.d.ts +2 -0
- package/dist/tools/edit.js +18 -3
- package/dist/tools/image-file.d.ts +38 -3
- package/dist/tools/image-file.js +81 -10
- package/dist/tools/image-resize.d.ts +58 -0
- package/dist/tools/image-resize.js +97 -0
- package/dist/tools/presets.d.ts +7 -2
- package/dist/tools/presets.js +11 -4
- package/dist/tools/read.d.ts +5 -2
- package/dist/tools/read.js +13 -10
- package/dist/tools/registry.d.ts +7 -1
- package/dist/tools/registry.js +27 -4
- package/dist/tools/task-ctl.d.ts +22 -0
- package/dist/tools/task-ctl.js +116 -0
- package/dist/tools/task.d.ts +22 -10
- package/dist/tools/task.js +66 -26
- package/dist/tools/todo.d.ts +22 -2
- package/dist/tools/todo.js +58 -14
- package/dist/tools/truncate.d.ts +15 -0
- package/dist/tools/truncate.js +25 -0
- package/dist/tools/types.d.ts +113 -0
- package/dist/tools/types.js +5 -0
- package/dist/tools/write.js +3 -0
- package/dist/tui/glyphs.d.ts +4 -0
- package/dist/tui/glyphs.js +4 -0
- package/dist/tui/keybindings.d.ts +6 -1
- package/dist/tui/keybindings.js +6 -1
- package/docs/acp.md +78 -0
- package/docs/agents.md +250 -0
- package/docs/codemode.md +12 -8
- package/docs/hooks.md +26 -22
- package/docs/permissions.md +78 -13
- package/docs/plan.md +107 -0
- package/docs/providers.md +228 -52
- package/docs/rewind-plan.md +181 -0
- package/docs/rpc.md +92 -5
- package/docs/sandbox.md +215 -0
- package/docs/session-format.md +41 -21
- package/docs/sessions.md +41 -1
- package/docs/tui-design.md +751 -0
- package/docs/tui.md +179 -21
- package/package.json +13 -2
package/dist/agent/session.js
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
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
|
-
import { modelRefOf } from "../ai/providers/channels.js";
|
|
14
11
|
import { join } from "node:path";
|
|
15
12
|
import { AmaError } from "../errors.js";
|
|
16
13
|
import { createSessionClassifier } from "./session-classifier.js";
|
|
@@ -20,16 +17,15 @@ import { queuedText } from "./queue.js";
|
|
|
20
17
|
import { resolveRetrySettings } from "./retry.js";
|
|
21
18
|
import { SessionCacheController, resolveCacheSettings } from "./session-cache.js";
|
|
22
19
|
import { CompactionController } from "./session-compaction.js";
|
|
23
|
-
import { makeUserMessage, runPrompt } from "./session-run.js";
|
|
20
|
+
import { makeUserMessage, normalizeOrigin, runPrompt } from "./session-run.js";
|
|
24
21
|
import { buildSessionState, computeStats, lastAssistantText } from "./session-state.js";
|
|
25
22
|
import { DEFAULT_SUBAGENT_CONCURRENCY, SubagentPool, runSubagent } from "./session-subagent.js";
|
|
26
23
|
import { persistMessage, runHookWithEvents, syncSystemMessage } from "./session-sync.js";
|
|
24
|
+
import { SessionExtensions } from "./session-extensions.js";
|
|
25
|
+
import { SessionSettings, providerStream } from "./session-settings.js";
|
|
27
26
|
import { createToolRunnerOptions } from "./session-tools.js";
|
|
27
|
+
import { RewindController } from "./session-rewind.js";
|
|
28
28
|
import { convertToLlm } from "./transform.js";
|
|
29
|
-
/** `"user"` = 普通用户输入,不写 origin。 */
|
|
30
|
-
function normalizeOrigin(origin) {
|
|
31
|
-
return origin === undefined || origin === "user" ? undefined : origin;
|
|
32
|
-
}
|
|
33
29
|
export class AgentSessionImpl {
|
|
34
30
|
options;
|
|
35
31
|
manager;
|
|
@@ -39,10 +35,8 @@ export class AgentSessionImpl {
|
|
|
39
35
|
readFiles = new Set();
|
|
40
36
|
stream;
|
|
41
37
|
cache;
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
allTools = new Map();
|
|
45
|
-
activeNames;
|
|
38
|
+
settings;
|
|
39
|
+
extensions;
|
|
46
40
|
listeners = new Set();
|
|
47
41
|
compaction;
|
|
48
42
|
retrySettings;
|
|
@@ -51,40 +45,35 @@ export class AgentSessionImpl {
|
|
|
51
45
|
stopReason;
|
|
52
46
|
stopFlag = false;
|
|
53
47
|
turns = 0;
|
|
54
|
-
systemInput;
|
|
55
48
|
subagentPool;
|
|
56
49
|
disposed = false;
|
|
57
50
|
classifier;
|
|
58
51
|
/** 已入队、尚未投递的消息(投递时发 queue_update)。 */
|
|
59
52
|
queuedMessages = new WeakSet();
|
|
53
|
+
rewinder;
|
|
60
54
|
constructor(options) {
|
|
61
55
|
this.options = options;
|
|
62
56
|
this.manager = options.sessionManager;
|
|
63
57
|
this.cwd = this.manager.cwd;
|
|
64
58
|
this.depth = options.depth ?? 0;
|
|
65
|
-
this.
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
this.
|
|
69
|
-
|
|
70
|
-
this.
|
|
59
|
+
this.settings = new SessionSettings(options, {
|
|
60
|
+
core: this,
|
|
61
|
+
assertUsable: () => this.assertUsable(),
|
|
62
|
+
onModelChanged: () => this.compaction.refresh(),
|
|
63
|
+
});
|
|
64
|
+
this.extensions = new SessionExtensions(this, options.extensions);
|
|
71
65
|
this.retrySettings = resolveRetrySettings(options.retry);
|
|
72
66
|
this.cache = new SessionCacheController(this, resolveCacheSettings(options.cache), {
|
|
73
67
|
decider: () => options.warmingDecider?.(),
|
|
74
68
|
});
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
if (api === undefined) {
|
|
78
|
-
throw new AmaError("provider_not_found", `no implementation registered for api ${model.api}`);
|
|
79
|
-
}
|
|
80
|
-
return api.stream(model, context, streamOptions);
|
|
81
|
-
});
|
|
69
|
+
// 缓存控制器在最外层(看到扩展改写后的最终请求)
|
|
70
|
+
this.stream = this.cache.wrapStream(this.extensions.wrapStream(providerStream(options.providers)));
|
|
82
71
|
const runner = createToolRunnerOptions(this);
|
|
83
72
|
const agentOptions = {
|
|
84
73
|
hooks: {
|
|
85
74
|
convertToLlm: (messages) => convertToLlm(messages, {
|
|
86
|
-
provider: this.
|
|
87
|
-
model: this.
|
|
75
|
+
provider: this.settings.model.provider,
|
|
76
|
+
model: this.settings.model.id,
|
|
88
77
|
}),
|
|
89
78
|
beforeToolCall: runner.beforeToolCall,
|
|
90
79
|
prepareNextTurn: async () => {
|
|
@@ -101,8 +90,8 @@ export class AgentSessionImpl {
|
|
|
101
90
|
},
|
|
102
91
|
},
|
|
103
92
|
stream: this.stream,
|
|
104
|
-
getModel: () => this.
|
|
105
|
-
getThinkingLevel: () => this.
|
|
93
|
+
getModel: () => this.settings.model,
|
|
94
|
+
getThinkingLevel: () => this.settings.thinking,
|
|
106
95
|
streamOptions: async () => {
|
|
107
96
|
const apiKey = await this.resolveApiKey();
|
|
108
97
|
const idle = options.idleTimeoutMs;
|
|
@@ -115,6 +104,7 @@ export class AgentSessionImpl {
|
|
|
115
104
|
beforeRequest: async () => {
|
|
116
105
|
this.syncSystem();
|
|
117
106
|
this.manager.flush();
|
|
107
|
+
await this.rewinder.ready();
|
|
118
108
|
},
|
|
119
109
|
tools: runner,
|
|
120
110
|
messages: buildProjection(this.manager.branch()).messages,
|
|
@@ -129,15 +119,24 @@ export class AgentSessionImpl {
|
|
|
129
119
|
this.compaction = new CompactionController(this, options.compaction);
|
|
130
120
|
const subagents = options.subagents === false ? undefined : options.subagents;
|
|
131
121
|
this.subagentPool = new SubagentPool(subagents?.maxConcurrent ?? DEFAULT_SUBAGENT_CONCURRENCY);
|
|
122
|
+
this.rewinder = new RewindController({
|
|
123
|
+
core: this,
|
|
124
|
+
running: () => {
|
|
125
|
+
this.assertUsable();
|
|
126
|
+
return this.cycle !== undefined;
|
|
127
|
+
},
|
|
128
|
+
navigate: (targetId, navigateOptions) => this.navigate(targetId, navigateOptions),
|
|
129
|
+
compactAt: (entryId, instructions) => this.compact(instructions, entryId),
|
|
130
|
+
});
|
|
132
131
|
}
|
|
133
132
|
// -------------------------------------------------------------------------
|
|
134
133
|
// SessionCore
|
|
135
134
|
// -------------------------------------------------------------------------
|
|
136
135
|
model() {
|
|
137
|
-
return this.
|
|
136
|
+
return this.settings.model;
|
|
138
137
|
}
|
|
139
138
|
thinkingLevel() {
|
|
140
|
-
return this.
|
|
139
|
+
return this.settings.thinking;
|
|
141
140
|
}
|
|
142
141
|
outputDir() {
|
|
143
142
|
if (this.options.outputDir !== undefined)
|
|
@@ -147,7 +146,7 @@ export class AgentSessionImpl {
|
|
|
147
146
|
}
|
|
148
147
|
async resolveApiKey() {
|
|
149
148
|
try {
|
|
150
|
-
const { provider, channel } = this.
|
|
149
|
+
const { provider, channel } = this.settings.model;
|
|
151
150
|
return (await this.options.providers.resolveApiKey(provider, channel)).apiKey;
|
|
152
151
|
}
|
|
153
152
|
catch {
|
|
@@ -164,6 +163,7 @@ export class AgentSessionImpl {
|
|
|
164
163
|
this.log("warn", `session listener failed on ${event.type}: ${String(error)}`);
|
|
165
164
|
}
|
|
166
165
|
}
|
|
166
|
+
this.extensions.onEvent(event);
|
|
167
167
|
}
|
|
168
168
|
appendEntry(input) {
|
|
169
169
|
const entry = this.manager.append(input);
|
|
@@ -174,13 +174,13 @@ export class AgentSessionImpl {
|
|
|
174
174
|
this.agent.messages = buildProjection(this.manager.branch()).messages;
|
|
175
175
|
}
|
|
176
176
|
activeTool(name) {
|
|
177
|
-
return this.
|
|
177
|
+
return this.settings.activeTool(name);
|
|
178
178
|
}
|
|
179
179
|
tool(name) {
|
|
180
|
-
return this.
|
|
180
|
+
return this.settings.tool(name);
|
|
181
181
|
}
|
|
182
182
|
activeToolNames() {
|
|
183
|
-
return
|
|
183
|
+
return this.settings.activeToolNames();
|
|
184
184
|
}
|
|
185
185
|
runHook(event, payload, signal) {
|
|
186
186
|
return runHookWithEvents(this, event, payload, signal);
|
|
@@ -197,7 +197,7 @@ export class AgentSessionImpl {
|
|
|
197
197
|
// -------------------------------------------------------------------------
|
|
198
198
|
onAgentEvent(event) {
|
|
199
199
|
if (event.type === "message_end")
|
|
200
|
-
persistMessage(this, event.message);
|
|
200
|
+
this.rewinder.onPersisted(persistMessage(this, event.message));
|
|
201
201
|
else if (event.type === "agent_start")
|
|
202
202
|
this.compaction.breaker.startRun();
|
|
203
203
|
this.emit(event);
|
|
@@ -215,7 +215,7 @@ export class AgentSessionImpl {
|
|
|
215
215
|
});
|
|
216
216
|
}
|
|
217
217
|
syncSystem() {
|
|
218
|
-
syncSystemMessage(this, this.systemInput, this.getTools());
|
|
218
|
+
syncSystemMessage(this, this.settings.systemInput, this.getTools());
|
|
219
219
|
}
|
|
220
220
|
// -------------------------------------------------------------------------
|
|
221
221
|
// 周期
|
|
@@ -256,6 +256,9 @@ export class AgentSessionImpl {
|
|
|
256
256
|
this.retrying = value;
|
|
257
257
|
},
|
|
258
258
|
lastAssistantText: () => this.getLastAssistantText(),
|
|
259
|
+
beginTurn: (message) => this.rewinder.beginTurn(message),
|
|
260
|
+
beforePrompts: (prompts) => this.extensions.beforePrompts(prompts),
|
|
261
|
+
afterSettled: () => this.extensions.onAgentSettled(),
|
|
259
262
|
};
|
|
260
263
|
}
|
|
261
264
|
// -------------------------------------------------------------------------
|
|
@@ -321,13 +324,21 @@ export class AgentSessionImpl {
|
|
|
321
324
|
this.listeners.add(listener);
|
|
322
325
|
return () => this.listeners.delete(listener);
|
|
323
326
|
}
|
|
324
|
-
/** 手动压缩;运行中 → busy
|
|
325
|
-
compact(instructions) {
|
|
327
|
+
/** 手动压缩;运行中 → busy。`cutAt`:以该条目为切点(「摘要到这里」)。 */
|
|
328
|
+
compact(instructions, cutAt) {
|
|
326
329
|
this.assertUsable();
|
|
327
330
|
if (this.cycle !== undefined)
|
|
328
331
|
return Promise.reject(new AmaError("busy", "cannot compact while running"));
|
|
329
|
-
return this.startCycle((signal) => this.compaction.compactManual(instructions, signal));
|
|
330
|
-
}
|
|
332
|
+
return this.startCycle((signal) => this.compaction.compactManual(instructions, signal, cutAt));
|
|
333
|
+
}
|
|
334
|
+
// [RW-B] 回滚(docs/rewind-plan.md §3;编排与校验在 session-rewind.ts)
|
|
335
|
+
rewindPoints = () => this.rewinder.points();
|
|
336
|
+
rewind = (request) => this.rewinder.rewind(request);
|
|
337
|
+
summarizeFrom = (entryId, instructions) => this.rewinder.summarizeFrom(entryId, instructions);
|
|
338
|
+
summarizeUpTo = (entryId, instructions) => this.rewinder.summarizeUpTo(entryId, instructions);
|
|
339
|
+
canUndoAbortedTurn = () => this.rewinder.canUndoAbortedTurn();
|
|
340
|
+
undoAbortedTurn = () => this.rewinder.undoAbortedTurn();
|
|
341
|
+
checkpointHooks = () => this.rewinder.hooks();
|
|
331
342
|
async fork(entryId) {
|
|
332
343
|
this.assertUsable();
|
|
333
344
|
if (this.cycle !== undefined)
|
|
@@ -338,9 +349,7 @@ export class AgentSessionImpl {
|
|
|
338
349
|
sessionManager: this.manager.fork(entryId),
|
|
339
350
|
});
|
|
340
351
|
}
|
|
341
|
-
/**
|
|
342
|
-
* `/tree`:同文件换叶子;`summarize` 时为离开的分支写 branch_summary(挂在新叶子下)。
|
|
343
|
-
*/
|
|
352
|
+
/** `/tree`:同文件换叶子;`summarize` 时为离开的分支写 branch_summary(挂在新叶子下)。 */
|
|
344
353
|
async navigate(targetId, options = {}) {
|
|
345
354
|
this.assertUsable();
|
|
346
355
|
if (this.cycle !== undefined)
|
|
@@ -355,83 +364,28 @@ export class AgentSessionImpl {
|
|
|
355
364
|
this.cache.onContextChanged();
|
|
356
365
|
return entry;
|
|
357
366
|
}
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
detail: lookup.candidates,
|
|
364
|
-
});
|
|
365
|
-
}
|
|
366
|
-
this.currentModel = lookup.model;
|
|
367
|
-
this.compaction.refresh();
|
|
368
|
-
const next = modelRefOf(lookup.model);
|
|
369
|
-
this.appendEntry({
|
|
370
|
-
type: "model_change",
|
|
371
|
-
provider: next.provider,
|
|
372
|
-
modelId: next.id,
|
|
373
|
-
...(next.channel !== undefined ? { channel: next.channel } : {}),
|
|
374
|
-
});
|
|
375
|
-
this.emit({ type: "model_changed", model: next });
|
|
376
|
-
}
|
|
377
|
-
setThinkingLevel(level) {
|
|
378
|
-
this.currentThinking = level;
|
|
379
|
-
this.appendEntry({ type: "thinking_level_change", thinkingLevel: level });
|
|
380
|
-
this.emit({ type: "thinking_level_changed", level });
|
|
381
|
-
}
|
|
382
|
-
setPermissionMode(mode) {
|
|
383
|
-
this.options.permission?.setMode(mode);
|
|
384
|
-
this.emit({ type: "permission_mode_changed", mode });
|
|
385
|
-
}
|
|
386
|
-
setActiveTools(names) {
|
|
387
|
-
const unknown = names.filter((name) => !this.allTools.has(name));
|
|
388
|
-
if (unknown.length > 0)
|
|
389
|
-
throw new AmaError("tool_not_found", `unknown tools: ${unknown.join(", ")}`);
|
|
390
|
-
this.activeNames = [...new Set(names)];
|
|
391
|
-
}
|
|
367
|
+
// [W5-C0] 设置类(session-settings.ts)
|
|
368
|
+
setModel = (ref) => this.settings.setModel(ref);
|
|
369
|
+
setThinkingLevel = (level) => this.settings.setThinkingLevel(level);
|
|
370
|
+
setPermissionMode = (mode) => this.settings.setPermissionMode(mode);
|
|
371
|
+
setActiveTools = (names) => this.settings.setActiveTools(names);
|
|
392
372
|
/** 宿主 / SDK 在会话创建后追加工具(下次请求前以 system 补丁声明)。 */
|
|
393
|
-
addTool(tool, active = true)
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
if (active)
|
|
398
|
-
this.activeNames.push(tool.name);
|
|
399
|
-
}
|
|
400
|
-
/** 更新系统提示的静态部分(SessionStart Hook 的 hookContext、宿主 instructions 等)。 */
|
|
401
|
-
updateSystem(patch) {
|
|
402
|
-
this.systemInput = { ...this.systemInput, ...patch };
|
|
403
|
-
}
|
|
373
|
+
addTool = (tool, active = true) => this.settings.addTool(tool, active);
|
|
374
|
+
updateSystem = (patch) => this.settings.updateSystem(patch);
|
|
375
|
+
getTools = () => this.settings.getTools();
|
|
376
|
+
announceStart = (reason) => this.settings.announceStart(reason);
|
|
404
377
|
setAutoCompaction(enabled) {
|
|
405
378
|
this.compaction.setAuto(enabled);
|
|
406
379
|
}
|
|
407
380
|
setAutoRetry(enabled) {
|
|
408
381
|
this.retrySettings = { ...this.retrySettings, enabled };
|
|
409
382
|
}
|
|
410
|
-
getTools() {
|
|
411
|
-
return this.activeNames
|
|
412
|
-
.map((name) => this.allTools.get(name))
|
|
413
|
-
.filter((tool) => tool !== undefined)
|
|
414
|
-
.sort((a, b) => a.name.localeCompare(b.name));
|
|
415
|
-
}
|
|
416
|
-
/** 发 session_start(bootstrap / SDK 在会话就绪后调用一次)。 */
|
|
417
|
-
announceStart(reason) {
|
|
418
|
-
const event = {
|
|
419
|
-
type: "session_start",
|
|
420
|
-
sessionId: this.manager.id,
|
|
421
|
-
cwd: this.cwd,
|
|
422
|
-
reason,
|
|
423
|
-
};
|
|
424
|
-
const file = this.manager.file();
|
|
425
|
-
if (file !== undefined)
|
|
426
|
-
event.sessionFile = file;
|
|
427
|
-
this.emit(event);
|
|
428
|
-
}
|
|
429
383
|
get state() {
|
|
430
384
|
return buildSessionState({
|
|
431
385
|
agent: this.agent,
|
|
432
386
|
manager: this.manager,
|
|
433
|
-
model: this.
|
|
434
|
-
thinkingLevel: this.
|
|
387
|
+
model: this.settings.model,
|
|
388
|
+
thinkingLevel: this.settings.thinking,
|
|
435
389
|
permissionMode: this.options.permission?.mode ?? "default",
|
|
436
390
|
isCompacting: this.compaction.isCompacting,
|
|
437
391
|
isRetrying: this.retrying,
|
|
@@ -454,8 +408,8 @@ export class AgentSessionImpl {
|
|
|
454
408
|
}
|
|
455
409
|
getStats() {
|
|
456
410
|
const contextTokens = this.compaction.estimate().tokens;
|
|
457
|
-
const contextWindow = this.
|
|
458
|
-
|
|
411
|
+
const contextWindow = this.settings.model.contextWindow;
|
|
412
|
+
const stats = computeStats({
|
|
459
413
|
sessionId: this.manager.id,
|
|
460
414
|
sessionFile: this.manager.file(),
|
|
461
415
|
branch: this.manager.branch(),
|
|
@@ -463,12 +417,14 @@ export class AgentSessionImpl {
|
|
|
463
417
|
contextWindow,
|
|
464
418
|
cache: this.cache.stats({ tokens: contextTokens, window: contextWindow }),
|
|
465
419
|
});
|
|
420
|
+
return this.extensions.contributeStats(stats);
|
|
466
421
|
}
|
|
467
422
|
async dispose() {
|
|
468
423
|
if (this.disposed)
|
|
469
424
|
return;
|
|
470
425
|
await this.abort();
|
|
471
426
|
this.cache.dispose();
|
|
427
|
+
this.extensions.dispose();
|
|
472
428
|
this.disposed = true;
|
|
473
429
|
this.manager.close();
|
|
474
430
|
this.listeners.clear();
|
|
@@ -478,10 +434,10 @@ export class AgentSessionImpl {
|
|
|
478
434
|
// -------------------------------------------------------------------------
|
|
479
435
|
childBase() {
|
|
480
436
|
return {
|
|
481
|
-
model: this.
|
|
482
|
-
thinkingLevel: this.
|
|
483
|
-
activeTools: this.
|
|
484
|
-
system: this.systemInput,
|
|
437
|
+
model: this.settings.model,
|
|
438
|
+
thinkingLevel: this.settings.thinking,
|
|
439
|
+
activeTools: this.settings.activeNamesRef(),
|
|
440
|
+
system: this.settings.systemInput,
|
|
485
441
|
};
|
|
486
442
|
}
|
|
487
443
|
autoClassifier() {
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 子 Agent 任务注册表(docs/wave5-plan.md §7.3–§7.6,D13、D23–D24)。[W5-G]
|
|
3
|
+
*
|
|
4
|
+
* 每个根会话一份(按会话 id 登记;compose-agents.ts 的扩展在会话构造时建,SDK / 测试直接构造的
|
|
5
|
+
* 会话在首次 task 时以缺省环境懒建)。职责:
|
|
6
|
+
* - 解析类型(catalog)→ 选 runner:ama 子会话(session-subagent.ts 的工厂)或外部 runner(W5-E /
|
|
7
|
+
* 宿主,经 `env.runners`);同一 `task(agent=…)` 入口;
|
|
8
|
+
* - 并发池(`subagents.maxConcurrent`,缺省 4)+ 排队上限(`maxPending`,缺省 16,超出报错不要重试);
|
|
9
|
+
* - 前台(等结果)/ 后台(立即返回 taskId,完成后 `<task-notification>` 走父会话 followUp 队列);
|
|
10
|
+
* - `taskId` 续聊:句柄保留 16 个(LRU,释放的只是内存,JSONL 永在),被释放或 resume 后按会话
|
|
11
|
+
* 文件 / 外部会话 id 重新接上;
|
|
12
|
+
* - 结果 > 50 KB 保留头尾并全文落 `outputs/`;轮数耗尽加说明;worktree 隔离;
|
|
13
|
+
* - 事件 `subagent_start / update / end`;父会话 `custom{ama.task}` 记任务快照(带 `status`),
|
|
14
|
+
* resume 时据此重建(未完成标 `interrupted`)。
|
|
15
|
+
*/
|
|
16
|
+
import type { SubagentRequest, SubagentResult, SubagentRunner, TaskInfo, TaskRegistryView } from "../tools/types.js";
|
|
17
|
+
import { AgentCatalog, type AgentModelConfig } from "../agents/catalog.js";
|
|
18
|
+
import { SubagentPool, TASK_CUSTOM_TYPE, type AmaRunnerSpec, type TaskHandle } from "../agents/task-record.js";
|
|
19
|
+
import { type TaskControl } from "../agents/task-control.js";
|
|
20
|
+
import type { AgentDefinition, AgentInfo } from "../agents/types.js";
|
|
21
|
+
import type { SessionCore } from "./session-core.js";
|
|
22
|
+
import type { SessionTaskStats } from "./types.js";
|
|
23
|
+
export declare const DEFAULT_SUBAGENT_CONCURRENCY = 4;
|
|
24
|
+
export declare const DEFAULT_MAX_PENDING = 16;
|
|
25
|
+
export declare const DEFAULT_RETAINED = 16;
|
|
26
|
+
export { SubagentPool, TASK_CUSTOM_TYPE, type AmaRunnerSpec, type TaskHandle };
|
|
27
|
+
export type AmaRunnerFactory = (spec: AmaRunnerSpec) => SubagentRunner;
|
|
28
|
+
export interface SubagentEnvironment {
|
|
29
|
+
catalog: AgentCatalog;
|
|
30
|
+
maxConcurrent?: number;
|
|
31
|
+
maxPending?: number;
|
|
32
|
+
retain?: number;
|
|
33
|
+
modelConfig?: AgentModelConfig;
|
|
34
|
+
/** 外部 / 宿主 runner(W5-E `ProcessRunner`、HostApi.runners);没有返回 undefined。 */
|
|
35
|
+
runners?(agent: AgentDefinition): SubagentRunner | undefined;
|
|
36
|
+
now?(): number;
|
|
37
|
+
}
|
|
38
|
+
/** 注册表需要的父会话能力(`SessionCore`;followUp 为 AgentSessionImpl 的公开方法)。 */
|
|
39
|
+
export type RegistryHost = Pick<SessionCore, "manager" | "cwd" | "emit" | "appendEntry" | "outputDir" | "log" | "options"> & {
|
|
40
|
+
followUp?(text: string, options?: {
|
|
41
|
+
origin?: string;
|
|
42
|
+
}): Promise<unknown>;
|
|
43
|
+
waitForIdle?(): Promise<void>;
|
|
44
|
+
};
|
|
45
|
+
/** RPC `get_tasks` / `/tasks`:会话 id → 注册表视图(没有任务时 undefined)。 */
|
|
46
|
+
export declare function taskRegistryView(sessionId: string): TaskRegistryView | undefined;
|
|
47
|
+
/** RPC `get_agents` / `/agents`:会话可用的类型(没有 task 工具、注册表未装配时为空)。 */
|
|
48
|
+
export declare function sessionAgents(sessionId: string): AgentInfo[];
|
|
49
|
+
export declare function registryOf(sessionId: string): SubagentRegistry | undefined;
|
|
50
|
+
/** 取会话的注册表;没有就以 `env`(缺省只有内置类型)新建并登记。 */
|
|
51
|
+
export declare function subagentRegistryFor(host: RegistryHost, env?: SubagentEnvironment): SubagentRegistry;
|
|
52
|
+
export declare class SubagentRegistry implements TaskControl {
|
|
53
|
+
private readonly host;
|
|
54
|
+
private readonly env;
|
|
55
|
+
readonly catalog: AgentCatalog;
|
|
56
|
+
private readonly pool;
|
|
57
|
+
private readonly tasks;
|
|
58
|
+
private readonly retained;
|
|
59
|
+
private seq;
|
|
60
|
+
private disposed;
|
|
61
|
+
private delivery;
|
|
62
|
+
constructor(host: RegistryHost, env: SubagentEnvironment);
|
|
63
|
+
private now;
|
|
64
|
+
list(): readonly TaskInfo[];
|
|
65
|
+
get(taskId: string): TaskInfo | undefined;
|
|
66
|
+
stats(): SessionTaskStats | undefined;
|
|
67
|
+
/** 运行中任务的已有输出(`task_ctl output`);结束后为最终文本。 */
|
|
68
|
+
output(taskId: string): string | undefined;
|
|
69
|
+
/** 等任务结束或超时;超时返回 undefined。 */
|
|
70
|
+
wait(taskId: string, timeoutMs: number): Promise<SubagentResult | undefined>;
|
|
71
|
+
stop(taskId: string): Promise<SubagentResult | undefined>;
|
|
72
|
+
run(request: SubagentRequest, ama: AmaRunnerFactory): Promise<SubagentResult>;
|
|
73
|
+
private continueTask;
|
|
74
|
+
private launch;
|
|
75
|
+
private startedResult;
|
|
76
|
+
private execute;
|
|
77
|
+
private handleFor;
|
|
78
|
+
private emitStart;
|
|
79
|
+
private sink;
|
|
80
|
+
private finish;
|
|
81
|
+
private notify;
|
|
82
|
+
private outputDirectory;
|
|
83
|
+
private outputName;
|
|
84
|
+
private outputFileFor;
|
|
85
|
+
private persist;
|
|
86
|
+
private touch;
|
|
87
|
+
/** 句柄 LRU:超出上限时释放最久未用、空闲的子会话(JSONL 仍在,续聊时重开)。 */
|
|
88
|
+
private retain;
|
|
89
|
+
/** 会话关闭:停止运行中的任务、释放保留的子会话。 */
|
|
90
|
+
dispose(): void;
|
|
91
|
+
}
|