@armadra/agent 0.5.0 → 0.6.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 +177 -294
- package/CHANGELOG.zh-CN.md +442 -0
- package/README.md +408 -364
- package/README.zh-CN.md +705 -0
- package/dist/agent/session-plan.js +2 -2
- package/dist/agent/session-state.d.ts +3 -0
- package/dist/agent/session-state.js +20 -0
- package/dist/agent/session-subagent.d.ts +15 -1
- package/dist/agent/session-subagent.js +26 -3
- package/dist/agent/session-telemetry.d.ts +16 -2
- package/dist/agent/session-telemetry.js +29 -7
- package/dist/agent/session-tools.js +5 -2
- package/dist/agent/session-trace-writer.d.ts +27 -0
- package/dist/agent/session-trace-writer.js +253 -0
- package/dist/agent/session.d.ts +2 -0
- package/dist/agent/session.js +12 -0
- package/dist/agent/subagent-direct.d.ts +20 -0
- package/dist/agent/subagent-direct.js +76 -0
- package/dist/agent/subagent-registry.d.ts +8 -1
- package/dist/agent/subagent-registry.js +28 -1
- package/dist/agent/system-prompt.d.ts +3 -1
- package/dist/agent/system-prompt.js +3 -0
- package/dist/agent/tool-runner.d.ts +2 -1
- package/dist/agent/tool-runner.js +5 -4
- package/dist/agent/types-w6.d.ts +39 -0
- package/dist/agent/types-w6.js +4 -0
- package/dist/agent/types.d.ts +5 -2
- package/dist/agents/external.js +1 -1
- package/dist/agents/task-record.d.ts +74 -1
- package/dist/agents/task-record.js +100 -0
- package/dist/ai/apis/cache-params.js +2 -1
- package/dist/ai/apis/chatgpt-backend.d.ts +52 -0
- package/dist/ai/apis/chatgpt-backend.js +224 -0
- package/dist/ai/apis/chatgpt-rate-limits.d.ts +26 -0
- package/dist/ai/apis/chatgpt-rate-limits.js +91 -0
- package/dist/ai/apis/openai-responses-request.d.ts +2 -1
- package/dist/ai/apis/openai-responses-request.js +8 -2
- package/dist/ai/apis/openai-responses.d.ts +2 -0
- package/dist/ai/apis/openai-responses.js +51 -16
- package/dist/ai/overflow.d.ts +1 -1
- package/dist/ai/overflow.js +10 -7
- package/dist/ai/providers/auth.d.ts +15 -2
- package/dist/ai/providers/auth.js +69 -2
- package/dist/ai/providers/builtin.js +27 -0
- package/dist/ai/providers/catalog-data.js +1 -0
- package/dist/ai/providers/enrich.js +2 -7
- package/dist/ai/providers/models-dev-cache.js +15 -19
- package/dist/ai/providers/models-dev-snapshot.js +8 -7
- package/dist/ai/providers/models-dev.js +5 -15
- package/dist/ai/providers/suggest.js +2 -16
- package/dist/ai/types.d.ts +27 -1
- package/dist/auth/chatgpt/backend-client.d.ts +26 -0
- package/dist/auth/chatgpt/backend-client.js +74 -0
- package/dist/auth/chatgpt/claims.d.ts +17 -0
- package/dist/auth/chatgpt/claims.js +46 -0
- package/dist/auth/chatgpt/cli.d.ts +33 -0
- package/dist/auth/chatgpt/cli.js +252 -0
- package/dist/auth/chatgpt/doctor.d.ts +17 -0
- package/dist/auth/chatgpt/doctor.js +36 -0
- package/dist/auth/chatgpt/host-id.d.ts +7 -0
- package/dist/auth/chatgpt/host-id.js +26 -0
- package/dist/auth/chatgpt/login.d.ts +30 -0
- package/dist/auth/chatgpt/login.js +130 -0
- package/dist/auth/chatgpt/presets.d.ts +66 -0
- package/dist/auth/chatgpt/presets.js +120 -0
- package/dist/auth/chatgpt/quota-text.d.ts +13 -0
- package/dist/auth/chatgpt/quota-text.js +36 -0
- package/dist/auth/oauth/browser.d.ts +12 -0
- package/dist/auth/oauth/browser.js +27 -0
- package/dist/auth/oauth/callback-server.d.ts +47 -0
- package/dist/auth/oauth/callback-server.js +147 -0
- package/dist/auth/oauth/flows.d.ts +62 -0
- package/dist/auth/oauth/flows.js +113 -0
- package/dist/auth/oauth/jwt.d.ts +24 -0
- package/dist/auth/oauth/jwt.js +81 -0
- package/dist/auth/oauth/live.d.ts +21 -0
- package/dist/auth/oauth/live.js +25 -0
- package/dist/auth/oauth/oidc.d.ts +26 -0
- package/dist/auth/oauth/oidc.js +72 -0
- package/dist/auth/oauth/pkce.d.ts +15 -0
- package/dist/auth/oauth/pkce.js +20 -0
- package/dist/auth/oauth/refresh.d.ts +35 -0
- package/dist/auth/oauth/refresh.js +129 -0
- package/dist/auth/oauth/token-client.d.ts +33 -0
- package/dist/auth/oauth/token-client.js +121 -0
- package/dist/auth/oauth/token-store.d.ts +23 -0
- package/dist/auth/oauth/token-store.js +125 -0
- package/dist/auth/testing/fake-oauth.d.ts +73 -0
- package/dist/auth/testing/fake-oauth.js +271 -0
- package/dist/auth/testing/refresh-child.d.ts +5 -0
- package/dist/auth/testing/refresh-child.js +16 -0
- package/dist/bundle/ama.cjs +28307 -13241
- package/dist/checkpoints/backend.js +6 -5
- package/dist/checkpoints/restore.js +3 -2
- package/dist/checkpoints/settings.js +2 -1
- package/dist/checkpoints/shadow-git.js +7 -6
- package/dist/checkpoints/shadow-restore.js +3 -2
- package/dist/checkpoints/tracker.js +4 -3
- package/dist/cli/args.d.ts +9 -2
- package/dist/cli/args.js +74 -27
- package/dist/cli/bootstrap.js +53 -31
- package/dist/cli/choice-prompt.d.ts +58 -0
- package/dist/cli/choice-prompt.js +142 -0
- package/dist/cli/codemode-notice.js +2 -2
- package/dist/cli/compose-agents.js +2 -1
- package/dist/cli/compose-extensions.js +2 -0
- package/dist/cli/compose-memory.d.ts +53 -0
- package/dist/cli/compose-memory.js +127 -0
- package/dist/cli/compose-providers.d.ts +5 -0
- package/dist/cli/compose-providers.js +32 -2
- package/dist/cli/compose-session.d.ts +5 -0
- package/dist/cli/compose-session.js +27 -13
- package/dist/cli/compose-store.d.ts +2 -0
- package/dist/cli/compose-store.js +9 -5
- package/dist/cli/compose.d.ts +2 -0
- package/dist/cli/compose.js +13 -5
- package/dist/cli/default-model.d.ts +0 -2
- package/dist/cli/default-model.js +5 -8
- package/dist/cli/deps.d.ts +5 -1
- package/dist/cli/exit-codes.d.ts +1 -1
- package/dist/cli/exit-codes.js +7 -16
- package/dist/cli/from-prompt.js +3 -2
- package/dist/cli/help-text.d.ts +2 -1
- package/dist/cli/help-text.js +5 -99
- package/dist/cli/main.d.ts +5 -0
- package/dist/cli/main.js +21 -2
- package/dist/cli/proxy.js +14 -9
- package/dist/cli/runtime.d.ts +5 -0
- package/dist/cli/startup-screen.js +20 -27
- package/dist/cli/startup-steps.js +6 -8
- package/dist/cli/subcommands/auth.d.ts +6 -3
- package/dist/cli/subcommands/auth.js +52 -22
- package/dist/cli/subcommands/config-set.d.ts +21 -0
- package/dist/cli/subcommands/config-set.js +137 -0
- package/dist/cli/subcommands/config.d.ts +2 -1
- package/dist/cli/subcommands/config.js +51 -37
- package/dist/cli/subcommands/doctor.d.ts +2 -1
- package/dist/cli/subcommands/doctor.js +97 -58
- package/dist/cli/subcommands/init.d.ts +1 -1
- package/dist/cli/subcommands/init.js +8 -7
- package/dist/cli/subcommands/memory.d.ts +18 -0
- package/dist/cli/subcommands/memory.js +189 -0
- package/dist/cli/subcommands/model-meta.js +11 -9
- package/dist/cli/subcommands/models-cache-probe.d.ts +1 -1
- package/dist/cli/subcommands/models-cache-probe.js +26 -32
- package/dist/cli/subcommands/models-discover.d.ts +3 -0
- package/dist/cli/subcommands/models-discover.js +44 -21
- package/dist/cli/subcommands/models.d.ts +1 -1
- package/dist/cli/subcommands/models.js +29 -22
- package/dist/cli/subcommands/probe-runner.js +8 -7
- package/dist/cli/subcommands/providers-list.js +32 -21
- package/dist/cli/subcommands/providers-plan.js +24 -25
- package/dist/cli/subcommands/providers-probe.js +5 -6
- package/dist/cli/subcommands/providers.d.ts +2 -2
- package/dist/cli/subcommands/providers.js +48 -59
- package/dist/cli/subcommands/sessions-export.d.ts +1 -1
- package/dist/cli/subcommands/sessions-export.js +10 -9
- package/dist/cli/subcommands/sessions-search.d.ts +1 -1
- package/dist/cli/subcommands/sessions-search.js +11 -10
- package/dist/cli/subcommands/sessions-trace.d.ts +30 -0
- package/dist/cli/subcommands/sessions-trace.js +156 -0
- package/dist/cli/subcommands/sessions.d.ts +4 -3
- package/dist/cli/subcommands/sessions.js +40 -37
- package/dist/cli/subcommands/stats.d.ts +1 -1
- package/dist/cli/subcommands/stats.js +49 -30
- package/dist/cli/system-prompt-arg.js +3 -2
- package/dist/codemode/capability.js +3 -2
- package/dist/compaction/post-compact.d.ts +1 -0
- package/dist/compaction/post-compact.js +15 -1
- package/dist/compaction/prune-tier.d.ts +1 -1
- package/dist/compaction/prune-tier.js +3 -3
- package/dist/compaction/serialize.js +2 -1
- package/dist/config/auth-file.d.ts +12 -2
- package/dist/config/auth-file.js +32 -10
- package/dist/config/checker.js +12 -11
- package/dist/config/context-files.js +3 -2
- package/dist/config/edit.d.ts +106 -0
- package/dist/config/edit.js +350 -0
- package/dist/config/init.d.ts +4 -3
- package/dist/config/init.js +10 -18
- package/dist/config/json-schema.d.ts +2 -1
- package/dist/config/json-schema.js +101 -68
- package/dist/config/key-docs.d.ts +18 -7
- package/dist/config/key-docs.js +43 -128
- package/dist/config/load.js +7 -6
- package/dist/config/merge.d.ts +4 -1
- package/dist/config/merge.js +42 -22
- package/dist/config/paths.js +6 -5
- package/dist/config/profile.d.ts +5 -1
- package/dist/config/profile.js +7 -2
- package/dist/config/schema-w5.js +3 -2
- package/dist/config/schema-w6.d.ts +19 -0
- package/dist/config/schema-w6.js +115 -0
- package/dist/config/schema.js +34 -20
- package/dist/config/settings-registry.d.ts +78 -0
- package/dist/config/settings-registry.js +184 -0
- package/dist/config/types-w6.d.ts +109 -0
- package/dist/config/types-w6.js +19 -0
- package/dist/config/types.d.ts +11 -8
- package/dist/config/types.js +1 -0
- package/dist/drivers/acp/client.js +1 -1
- package/dist/drivers/acp/driver.js +13 -8
- package/dist/drivers/agents.js +4 -3
- package/dist/drivers/base.js +3 -2
- package/dist/drivers/host-runners.js +2 -1
- package/dist/drivers/native/claude-stream.js +12 -11
- package/dist/drivers/native/codex-app-server.js +17 -12
- package/dist/drivers/native/oneshot.js +8 -7
- package/dist/drivers/pool.js +1 -1
- package/dist/drivers/runner.d.ts +3 -1
- package/dist/drivers/runner.js +68 -20
- package/dist/drivers/turn.js +1 -1
- package/dist/hooks/config.js +3 -2
- package/dist/hooks/protocol.js +18 -12
- package/dist/host/api-impl.js +11 -10
- package/dist/host/loader.js +9 -8
- package/dist/host/types.d.ts +3 -0
- package/dist/i18n/catalog.d.ts +2169 -0
- package/dist/i18n/catalog.js +72 -0
- package/dist/i18n/format.d.ts +21 -0
- package/dist/i18n/format.js +58 -0
- package/dist/i18n/index.d.ts +58 -0
- package/dist/i18n/index.js +72 -0
- package/dist/i18n/messages/agents.d.ts +84 -0
- package/dist/i18n/messages/agents.js +85 -0
- package/dist/i18n/messages/approval.d.ts +99 -0
- package/dist/i18n/messages/approval.js +100 -0
- package/dist/i18n/messages/auth.d.ts +187 -0
- package/dist/i18n/messages/auth.js +189 -0
- package/dist/i18n/messages/cli-args.d.ts +46 -0
- package/dist/i18n/messages/cli-args.js +46 -0
- package/dist/i18n/messages/cli-help.d.ts +12 -0
- package/dist/i18n/messages/cli-help.js +244 -0
- package/dist/i18n/messages/cli.d.ts +336 -0
- package/dist/i18n/messages/cli.js +311 -0
- package/dist/i18n/messages/config-keys.d.ts +289 -0
- package/dist/i18n/messages/config-keys.js +292 -0
- package/dist/i18n/messages/config.d.ts +502 -0
- package/dist/i18n/messages/config.js +239 -0
- package/dist/i18n/messages/drivers.d.ts +123 -0
- package/dist/i18n/messages/drivers.js +124 -0
- package/dist/i18n/messages/errors.d.ts +83 -0
- package/dist/i18n/messages/errors.js +171 -0
- package/dist/i18n/messages/interactive-line.d.ts +61 -0
- package/dist/i18n/messages/interactive-line.js +69 -0
- package/dist/i18n/messages/interactive-startup.d.ts +103 -0
- package/dist/i18n/messages/interactive-startup.js +104 -0
- package/dist/i18n/messages/interactive-view.d.ts +140 -0
- package/dist/i18n/messages/interactive-view.js +141 -0
- package/dist/i18n/messages/interactive.d.ts +493 -0
- package/dist/i18n/messages/interactive.js +248 -0
- package/dist/i18n/messages/memory.d.ts +123 -0
- package/dist/i18n/messages/memory.js +128 -0
- package/dist/i18n/messages/panels.d.ts +190 -0
- package/dist/i18n/messages/panels.js +189 -0
- package/dist/i18n/messages/permissions.d.ts +126 -0
- package/dist/i18n/messages/permissions.js +151 -0
- package/dist/i18n/messages/plan.d.ts +123 -0
- package/dist/i18n/messages/plan.js +124 -0
- package/dist/i18n/messages/print.d.ts +86 -0
- package/dist/i18n/messages/print.js +91 -0
- package/dist/i18n/messages/report.d.ts +391 -0
- package/dist/i18n/messages/report.js +490 -0
- package/dist/i18n/messages/rewind.d.ts +198 -0
- package/dist/i18n/messages/rewind.js +217 -0
- package/dist/i18n/messages/session.d.ts +230 -0
- package/dist/i18n/messages/session.js +258 -0
- package/dist/i18n/messages/settings.d.ts +348 -0
- package/dist/i18n/messages/settings.js +336 -0
- package/dist/i18n/messages/subcommands-config.d.ts +111 -0
- package/dist/i18n/messages/subcommands-config.js +127 -0
- package/dist/i18n/messages/subcommands.d.ts +548 -0
- package/dist/i18n/messages/subcommands.js +474 -0
- package/dist/i18n/messages/trace.d.ts +243 -0
- package/dist/i18n/messages/trace.js +238 -0
- package/dist/i18n/types.d.ts +15 -0
- package/dist/i18n/types.js +7 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +2 -0
- package/dist/memory/edit.d.ts +24 -0
- package/dist/memory/edit.js +63 -0
- package/dist/memory/frontmatter.d.ts +37 -0
- package/dist/memory/frontmatter.js +79 -0
- package/dist/memory/index.d.ts +28 -0
- package/dist/memory/index.js +126 -0
- package/dist/memory/lock.d.ts +17 -0
- package/dist/memory/lock.js +62 -0
- package/dist/memory/paths.d.ts +57 -0
- package/dist/memory/paths.js +175 -0
- package/dist/memory/report.d.ts +36 -0
- package/dist/memory/report.js +86 -0
- package/dist/memory/runtime.d.ts +42 -0
- package/dist/memory/runtime.js +36 -0
- package/dist/memory/secrets.d.ts +8 -0
- package/dist/memory/secrets.js +27 -0
- package/dist/memory/section.d.ts +28 -0
- package/dist/memory/section.js +59 -0
- package/dist/memory/store.d.ts +70 -0
- package/dist/memory/store.js +284 -0
- package/dist/memory/tool.d.ts +31 -0
- package/dist/memory/tool.js +94 -0
- package/dist/modes/acp/acp-events.js +2 -1
- package/dist/modes/acp/acp-server.js +13 -12
- package/dist/modes/commands-core.d.ts +17 -0
- package/dist/modes/commands-core.js +101 -61
- package/dist/modes/image-input.js +20 -6
- package/dist/modes/interactive/agent-bar.d.ts +95 -0
- package/dist/modes/interactive/agent-bar.js +248 -0
- package/dist/modes/interactive/agent-panels.js +27 -26
- package/dist/modes/interactive/agent-transcript.d.ts +47 -0
- package/dist/modes/interactive/agent-transcript.js +191 -0
- package/dist/modes/interactive/agent-ui.d.ts +36 -1
- package/dist/modes/interactive/agent-ui.js +180 -14
- package/dist/modes/interactive/agent-view.d.ts +72 -0
- package/dist/modes/interactive/agent-view.js +281 -0
- package/dist/modes/interactive/approval-dialog.js +46 -34
- package/dist/modes/interactive/clipboard-paste.d.ts +2 -2
- package/dist/modes/interactive/clipboard-paste.js +9 -4
- package/dist/modes/interactive/commands.d.ts +22 -1
- package/dist/modes/interactive/commands.js +93 -38
- package/dist/modes/interactive/completion.js +2 -1
- package/dist/modes/interactive/config-panel.d.ts +70 -0
- package/dist/modes/interactive/config-panel.js +319 -0
- package/dist/modes/interactive/config-ui.d.ts +96 -0
- package/dist/modes/interactive/config-ui.js +397 -0
- package/dist/modes/interactive/confirm-dialog.d.ts +49 -0
- package/dist/modes/interactive/confirm-dialog.js +120 -0
- package/dist/modes/interactive/event-notices.js +11 -9
- package/dist/modes/interactive/interactive-mode.d.ts +1 -1
- package/dist/modes/interactive/interactive-mode.js +25 -22
- package/dist/modes/interactive/key-dispatch.d.ts +18 -0
- package/dist/modes/interactive/key-dispatch.js +39 -13
- package/dist/modes/interactive/line/line-editor.js +2 -1
- package/dist/modes/interactive/line/line-mode.d.ts +2 -0
- package/dist/modes/interactive/line/line-mode.js +24 -4
- package/dist/modes/interactive/line/line-render.js +25 -24
- package/dist/modes/interactive/memory-panel.d.ts +64 -0
- package/dist/modes/interactive/memory-panel.js +221 -0
- package/dist/modes/interactive/message-view.d.ts +4 -2
- package/dist/modes/interactive/message-view.js +42 -33
- package/dist/modes/interactive/panels.js +39 -31
- package/dist/modes/interactive/pickers.d.ts +2 -1
- package/dist/modes/interactive/pickers.js +10 -6
- package/dist/modes/interactive/plan-command.d.ts +1 -1
- package/dist/modes/interactive/plan-command.js +24 -27
- package/dist/modes/interactive/plan-dialog.js +18 -17
- package/dist/modes/interactive/plan-flow.js +6 -5
- package/dist/modes/interactive/rewind-command.d.ts +1 -1
- package/dist/modes/interactive/rewind-command.js +18 -16
- package/dist/modes/interactive/rewind-flow.d.ts +0 -1
- package/dist/modes/interactive/rewind-flow.js +13 -14
- package/dist/modes/interactive/rewind-list.js +7 -6
- package/dist/modes/interactive/rewind-panel.js +40 -40
- package/dist/modes/interactive/rewind-text.d.ts +5 -3
- package/dist/modes/interactive/rewind-text.js +48 -38
- package/dist/modes/interactive/run-indicator.js +15 -12
- package/dist/modes/interactive/session-events.js +3 -2
- package/dist/modes/interactive/startup-header.js +22 -23
- package/dist/modes/interactive/startup-ui.js +41 -29
- package/dist/modes/interactive/status-area.d.ts +2 -0
- package/dist/modes/interactive/status-area.js +8 -2
- package/dist/modes/interactive/status-bar.js +4 -3
- package/dist/modes/interactive/subagent-view.js +9 -7
- package/dist/modes/interactive/tasks-report.d.ts +6 -0
- package/dist/modes/interactive/tasks-report.js +28 -31
- package/dist/modes/interactive/terminal-setup.d.ts +9 -0
- package/dist/modes/interactive/terminal-setup.js +23 -0
- package/dist/modes/interactive/tool-summary.js +19 -17
- package/dist/modes/interactive/tool-view.js +7 -4
- package/dist/modes/interactive/trace-view.d.ts +89 -0
- package/dist/modes/interactive/trace-view.js +332 -0
- package/dist/modes/print/print-mode.js +14 -15
- package/dist/modes/rpc/commands.js +7 -3
- package/dist/modes/rpc/rpc-mode.js +9 -3
- package/dist/modes/session-report.d.ts +2 -0
- package/dist/modes/session-report.js +101 -105
- package/dist/modes/startup-ui-text.js +11 -6
- package/dist/permissions/bypass.d.ts +30 -0
- package/dist/permissions/bypass.js +45 -0
- package/dist/permissions/memory-class.d.ts +23 -0
- package/dist/permissions/memory-class.js +54 -0
- package/dist/permissions/modes.d.ts +3 -3
- package/dist/permissions/modes.js +21 -16
- package/dist/permissions/pipeline.d.ts +1 -1
- package/dist/permissions/pipeline.js +9 -2
- package/dist/permissions/preview.js +49 -42
- package/dist/permissions/rules.js +5 -2
- package/dist/permissions/types.d.ts +4 -0
- package/dist/plan/store.js +2 -1
- package/dist/rpc.d.ts +39 -1
- package/dist/rpc.js +3 -0
- package/dist/sandbox/bash.js +11 -8
- package/dist/sandbox/detect.js +14 -11
- package/dist/sdk.d.ts +17 -1
- package/dist/sdk.js +29 -7
- package/dist/session/export.js +31 -30
- package/dist/session/manager.d.ts +1 -1
- package/dist/session/manager.js +5 -3
- package/dist/session/reuse.js +5 -4
- package/dist/session/scan.js +3 -2
- package/dist/session/stats-aggregate.d.ts +3 -1
- package/dist/session/stats-aggregate.js +5 -1
- package/dist/session/stats-index.js +2 -1
- package/dist/session/stats-scan.d.ts +4 -1
- package/dist/session/stats-scan.js +6 -2
- package/dist/session/store.d.ts +11 -0
- package/dist/session/store.js +48 -1
- package/dist/session/types.d.ts +2 -0
- package/dist/skills/builtin.js +2 -1
- package/dist/tools/image-file.d.ts +26 -1
- package/dist/tools/image-file.js +55 -13
- package/dist/tools/presets.d.ts +14 -1
- package/dist/tools/presets.js +3 -3
- package/dist/tools/registry.js +1 -1
- package/dist/tools/truncate.d.ts +1 -1
- package/dist/tools/truncate.js +2 -2
- package/dist/tools/types.d.ts +17 -1
- package/dist/trace/build-index.d.ts +91 -0
- package/dist/trace/build-index.js +127 -0
- package/dist/trace/build-nodes.d.ts +24 -0
- package/dist/trace/build-nodes.js +279 -0
- package/dist/trace/build-util.d.ts +43 -0
- package/dist/trace/build-util.js +120 -0
- package/dist/trace/build.d.ts +82 -0
- package/dist/trace/build.js +382 -0
- package/dist/trace/detail.d.ts +35 -0
- package/dist/trace/detail.js +205 -0
- package/dist/trace/flatten.d.ts +69 -0
- package/dist/trace/flatten.js +173 -0
- package/dist/trace/format.d.ts +47 -0
- package/dist/trace/format.js +329 -0
- package/dist/trace/html-template.d.ts +19 -0
- package/dist/trace/html-template.js +150 -0
- package/dist/trace/html.d.ts +104 -0
- package/dist/trace/html.js +292 -0
- package/dist/trace/preview.d.ts +29 -0
- package/dist/trace/preview.js +59 -0
- package/dist/trace/query-session.d.ts +14 -0
- package/dist/trace/query-session.js +38 -0
- package/dist/trace/query.d.ts +55 -0
- package/dist/trace/query.js +188 -0
- package/dist/trace/session.d.ts +40 -0
- package/dist/trace/session.js +168 -0
- package/dist/trace/types.d.ts +243 -0
- package/dist/trace/types.js +13 -0
- package/dist/tui/components/editor-paste.d.ts +2 -0
- package/dist/tui/components/editor-paste.js +6 -3
- package/dist/tui/components/editor.js +2 -2
- package/dist/tui/components/loader.d.ts +3 -0
- package/dist/tui/components/loader.js +14 -0
- package/dist/tui/components/settings-list.d.ts +61 -0
- package/dist/tui/components/settings-list.js +135 -0
- package/dist/tui/keybindings.d.ts +6 -1
- package/dist/tui/keybindings.js +18 -6
- package/dist/tui.d.ts +1 -0
- package/dist/tui.js +2 -0
- package/docs/en/host-api.md +167 -0
- package/docs/en/permissions.md +214 -0
- package/docs/en/providers.md +625 -0
- package/docs/en/rpc.md +361 -0
- package/docs/en/sessions.md +219 -0
- package/docs/en/tui.md +527 -0
- package/docs/host-api.md +18 -17
- package/docs/memory.md +172 -0
- package/docs/permissions.md +3 -2
- package/docs/providers.md +67 -1
- package/docs/rpc.md +31 -3
- package/docs/session-format.md +8 -2
- package/docs/sessions.md +29 -1
- package/docs/tui.md +189 -21
- package/package.json +8 -3
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 子 Agent 视图的直接对话与实时数据(docs/wave6-plan.md §1.2–§1.3、D3)。[W6-A]
|
|
3
|
+
*
|
|
4
|
+
* 从 subagent-registry.ts 拆出(保持 ≤ 600 行):
|
|
5
|
+
* - `liveOf`:视图读的快照、是否在并发池排队、ama 子会话的观察钩子与外部 Agent 的环形缓冲;
|
|
6
|
+
* - `directMessage`:人在视图里发的消息——ama 运行中 → 子会话 followUp(回合结束投递,返回 `steered`);
|
|
7
|
+
* 外部 Agent 运行中 / 还在排队 → 等本次运行结束后续聊(`queued`);已结束 → 同 `task_ctl send` 的后台续聊
|
|
8
|
+
* (`resumed`,完成后父会话照常收 `<task-notification>`)。子会话 user 消息记 `origin: "direct"`;
|
|
9
|
+
* - `drainDirect`:运行结束时把排着的消息合成一条续聊;任务被停止时丢弃(停止的一方不想它再跑)。
|
|
10
|
+
*/
|
|
11
|
+
import type { TaskLive, TaskRecord } from "../agents/task-record.js";
|
|
12
|
+
import type { SubagentRequest, SubagentResult } from "../tools/types.js";
|
|
13
|
+
export type DirectReply = "steered" | "queued" | "resumed";
|
|
14
|
+
export interface DirectHost {
|
|
15
|
+
spawnSubagent?(request: SubagentRequest): Promise<SubagentResult>;
|
|
16
|
+
log(level: "debug" | "info" | "warn" | "error", message: string): void;
|
|
17
|
+
}
|
|
18
|
+
export declare function liveOf(record: TaskRecord): TaskLive;
|
|
19
|
+
export declare function directMessage(record: TaskRecord, text: string, host: DirectHost): Promise<DirectReply>;
|
|
20
|
+
export declare function drainDirect(record: TaskRecord, host: DirectHost): void;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 子 Agent 视图的直接对话与实时数据(docs/wave6-plan.md §1.2–§1.3、D3)。[W6-A]
|
|
3
|
+
*
|
|
4
|
+
* 从 subagent-registry.ts 拆出(保持 ≤ 600 行):
|
|
5
|
+
* - `liveOf`:视图读的快照、是否在并发池排队、ama 子会话的观察钩子与外部 Agent 的环形缓冲;
|
|
6
|
+
* - `directMessage`:人在视图里发的消息——ama 运行中 → 子会话 followUp(回合结束投递,返回 `steered`);
|
|
7
|
+
* 外部 Agent 运行中 / 还在排队 → 等本次运行结束后续聊(`queued`);已结束 → 同 `task_ctl send` 的后台续聊
|
|
8
|
+
* (`resumed`,完成后父会话照常收 `<task-notification>`)。子会话 user 消息记 `origin: "direct"`;
|
|
9
|
+
* - `drainDirect`:运行结束时把排着的消息合成一条续聊;任务被停止时丢弃(停止的一方不想它再跑)。
|
|
10
|
+
*/
|
|
11
|
+
import { AmaError } from "../errors.js";
|
|
12
|
+
export function liveOf(record) {
|
|
13
|
+
const handle = record.handle;
|
|
14
|
+
const live = {
|
|
15
|
+
info: { ...record.info },
|
|
16
|
+
queued: record.queued === true,
|
|
17
|
+
recent: handle?.recent?.() ?? record.ring?.items() ?? [],
|
|
18
|
+
pending: record.direct?.length ?? 0,
|
|
19
|
+
};
|
|
20
|
+
const observe = handle?.observe;
|
|
21
|
+
const entries = handle?.entries;
|
|
22
|
+
if (observe !== undefined)
|
|
23
|
+
live.observe = (listener) => observe.call(handle, listener);
|
|
24
|
+
if (entries !== undefined)
|
|
25
|
+
live.entries = () => entries.call(handle);
|
|
26
|
+
return live;
|
|
27
|
+
}
|
|
28
|
+
export async function directMessage(record, text, host) {
|
|
29
|
+
if (text.trim() === "")
|
|
30
|
+
throw new AmaError("invalid_arguments", "empty message");
|
|
31
|
+
if (record.running !== undefined) {
|
|
32
|
+
const handle = record.handle;
|
|
33
|
+
if (handle?.message !== undefined && record.queued !== true) {
|
|
34
|
+
try {
|
|
35
|
+
await handle.message(text, "followUp");
|
|
36
|
+
return "steered";
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
// 子会话这一轮刚结束、注册表还没收尾:排到运行结束后续聊
|
|
40
|
+
if (!(error instanceof AmaError) || error.code !== "task_idle")
|
|
41
|
+
throw error;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
(record.direct ??= []).push(text);
|
|
45
|
+
return "queued";
|
|
46
|
+
}
|
|
47
|
+
await resumeDirect(record, text, host);
|
|
48
|
+
return "resumed";
|
|
49
|
+
}
|
|
50
|
+
async function resumeDirect(record, text, host) {
|
|
51
|
+
const spawn = host.spawnSubagent;
|
|
52
|
+
if (spawn === undefined)
|
|
53
|
+
throw new AmaError("unsupported", "this session cannot continue sub-agent tasks");
|
|
54
|
+
record.directNext = true;
|
|
55
|
+
const result = await spawn.call(host, {
|
|
56
|
+
prompt: text,
|
|
57
|
+
taskId: record.info.taskId,
|
|
58
|
+
background: true,
|
|
59
|
+
parentToolCallId: record.parentToolCallId,
|
|
60
|
+
signal: new AbortController().signal,
|
|
61
|
+
});
|
|
62
|
+
if (result.isError) {
|
|
63
|
+
delete record.directNext;
|
|
64
|
+
throw new AmaError("task_not_resumable", result.text);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
export function drainDirect(record, host) {
|
|
68
|
+
const queued = record.direct?.splice(0) ?? [];
|
|
69
|
+
if (queued.length === 0)
|
|
70
|
+
return;
|
|
71
|
+
if (record.info.status === "aborted") {
|
|
72
|
+
host.log("info", `task ${record.info.taskId} was stopped; ${queued.length} queued message(s) dropped`);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
void resumeDirect(record, queued.join("\n\n"), host).catch((error) => host.log("warn", `task ${record.info.taskId}: queued message failed: ${String(error)}`));
|
|
76
|
+
}
|
|
@@ -12,10 +12,11 @@
|
|
|
12
12
|
* - 结果 > 50 KB 保留头尾并全文落 `outputs/`;轮数耗尽加说明;worktree 隔离;
|
|
13
13
|
* - 事件 `subagent_start / update / end`;父会话 `custom{ama.task}` 记任务快照(带 `status`),
|
|
14
14
|
* resume 时据此重建(未完成标 `interrupted`)。
|
|
15
|
+
* - [W6-A] 子 Agent 视图的 `live()` / `message()`(实现在 subagent-direct.ts)。
|
|
15
16
|
*/
|
|
16
17
|
import type { SubagentRequest, SubagentResult, SubagentRunner, TaskInfo, TaskRegistryView } from "../tools/types.js";
|
|
17
18
|
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 { SubagentPool, TASK_CUSTOM_TYPE, type AmaRunnerSpec, type TaskHandle, type TaskLive } from "../agents/task-record.js";
|
|
19
20
|
import { type TaskControl } from "../agents/task-control.js";
|
|
20
21
|
import type { AgentDefinition, AgentInfo } from "../agents/types.js";
|
|
21
22
|
import type { SessionCore } from "./session-core.js";
|
|
@@ -41,6 +42,8 @@ export type RegistryHost = Pick<SessionCore, "manager" | "cwd" | "emit" | "appen
|
|
|
41
42
|
origin?: string;
|
|
42
43
|
}): Promise<unknown>;
|
|
43
44
|
waitForIdle?(): Promise<void>;
|
|
45
|
+
/** [W6-A] 视图里续聊已结束的任务(AgentSessionImpl 的方法,经 runSubagent 拿到 ama runner 工厂)。 */
|
|
46
|
+
spawnSubagent?(request: SubagentRequest): Promise<SubagentResult>;
|
|
44
47
|
};
|
|
45
48
|
/** RPC `get_tasks` / `/tasks`:会话 id → 注册表视图(没有任务时 undefined)。 */
|
|
46
49
|
export declare function taskRegistryView(sessionId: string): TaskRegistryView | undefined;
|
|
@@ -68,6 +71,10 @@ export declare class SubagentRegistry implements TaskControl {
|
|
|
68
71
|
output(taskId: string): string | undefined;
|
|
69
72
|
/** 等任务结束或超时;超时返回 undefined。 */
|
|
70
73
|
wait(taskId: string, timeoutMs: number): Promise<SubagentResult | undefined>;
|
|
74
|
+
/** [W6-A] 子 Agent 视图读的实时数据;未知任务 undefined。 */
|
|
75
|
+
live(taskId: string): TaskLive | undefined;
|
|
76
|
+
/** [W6-A] 人在子 Agent 视图里发的消息(subagent-direct.ts)。 */
|
|
77
|
+
message(taskId: string, text: string): Promise<"steered" | "queued" | "resumed">;
|
|
71
78
|
stop(taskId: string): Promise<SubagentResult | undefined>;
|
|
72
79
|
run(request: SubagentRequest, ama: AmaRunnerFactory): Promise<SubagentResult>;
|
|
73
80
|
private continueTask;
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
* - 结果 > 50 KB 保留头尾并全文落 `outputs/`;轮数耗尽加说明;worktree 隔离;
|
|
13
13
|
* - 事件 `subagent_start / update / end`;父会话 `custom{ama.task}` 记任务快照(带 `status`),
|
|
14
14
|
* resume 时据此重建(未完成标 `interrupted`)。
|
|
15
|
+
* - [W6-A] 子 Agent 视图的 `live()` / `message()`(实现在 subagent-direct.ts)。
|
|
15
16
|
*/
|
|
16
17
|
import { tmpdir } from "node:os";
|
|
17
18
|
import { join } from "node:path";
|
|
@@ -23,6 +24,8 @@ import { SubagentPool, TASK_CUSTOM_TYPE, applyRunnerEvent, flushText, newRecord,
|
|
|
23
24
|
import { registerTaskControl, unregisterTaskControl, } from "../agents/task-control.js";
|
|
24
25
|
import { ZERO_USAGE } from "./loop.js";
|
|
25
26
|
import { createWorktree, finishWorktree } from "./worktree.js";
|
|
27
|
+
import { appendTraceEntry } from "./session-trace-writer.js";
|
|
28
|
+
import { directMessage, drainDirect, liveOf } from "./subagent-direct.js";
|
|
26
29
|
export const DEFAULT_SUBAGENT_CONCURRENCY = 4;
|
|
27
30
|
export const DEFAULT_MAX_PENDING = 16;
|
|
28
31
|
export const DEFAULT_RETAINED = 16;
|
|
@@ -126,6 +129,18 @@ export class SubagentRegistry {
|
|
|
126
129
|
clearTimeout(timer);
|
|
127
130
|
}
|
|
128
131
|
}
|
|
132
|
+
/** [W6-A] 子 Agent 视图读的实时数据;未知任务 undefined。 */
|
|
133
|
+
live(taskId) {
|
|
134
|
+
const record = this.tasks.get(taskId);
|
|
135
|
+
return record === undefined ? undefined : liveOf(record);
|
|
136
|
+
}
|
|
137
|
+
/** [W6-A] 人在子 Agent 视图里发的消息(subagent-direct.ts)。 */
|
|
138
|
+
async message(taskId, text) {
|
|
139
|
+
const record = this.tasks.get(taskId);
|
|
140
|
+
if (record === undefined)
|
|
141
|
+
throw new AmaError("task_not_found", `unknown task ${taskId}`);
|
|
142
|
+
return directMessage(record, text, this.host);
|
|
143
|
+
}
|
|
129
144
|
async stop(taskId) {
|
|
130
145
|
const record = this.tasks.get(taskId);
|
|
131
146
|
if (record === undefined)
|
|
@@ -206,6 +221,8 @@ export class SubagentRegistry {
|
|
|
206
221
|
parentSignal?.removeEventListener("abort", onParentAbort);
|
|
207
222
|
delete record.running;
|
|
208
223
|
delete record.controller;
|
|
224
|
+
if (!this.disposed)
|
|
225
|
+
drainDirect(record, this.host);
|
|
209
226
|
});
|
|
210
227
|
record.running = running;
|
|
211
228
|
if (!background)
|
|
@@ -229,12 +246,15 @@ export class SubagentRegistry {
|
|
|
229
246
|
return result;
|
|
230
247
|
}
|
|
231
248
|
async execute(record, request, ama, signal) {
|
|
249
|
+
record.queued = true;
|
|
232
250
|
try {
|
|
233
251
|
await this.pool.acquire(signal);
|
|
234
252
|
}
|
|
235
253
|
catch {
|
|
254
|
+
delete record.queued;
|
|
236
255
|
return this.finish(record, { ...failed("aborted by user"), status: "aborted" });
|
|
237
256
|
}
|
|
257
|
+
delete record.queued;
|
|
238
258
|
try {
|
|
239
259
|
if (record.isolation === "worktree" && record.worktree === undefined) {
|
|
240
260
|
// 名字带会话 id 前缀:不同会话的 t1 不会撞到同一个 worktree / 分支
|
|
@@ -265,10 +285,15 @@ export class SubagentRegistry {
|
|
|
265
285
|
}
|
|
266
286
|
async handleFor(record, request, ama, signal) {
|
|
267
287
|
const live = record.handle;
|
|
288
|
+
const direct = record.directNext === true;
|
|
289
|
+
delete record.directNext;
|
|
268
290
|
if (live !== undefined) {
|
|
269
291
|
this.touch(record.info.taskId);
|
|
270
292
|
this.emitStart(record, live);
|
|
271
|
-
|
|
293
|
+
if (direct && live.message !== undefined)
|
|
294
|
+
await live.message(request.prompt, "send");
|
|
295
|
+
else
|
|
296
|
+
await live.send(request.prompt);
|
|
272
297
|
return live;
|
|
273
298
|
}
|
|
274
299
|
const ref = record.info.sessionRef;
|
|
@@ -281,6 +306,7 @@ export class SubagentRegistry {
|
|
|
281
306
|
cwd: record.cwd,
|
|
282
307
|
...(ref?.sessionFile === undefined ? {} : { resumeFile: ref.sessionFile }),
|
|
283
308
|
isolated: record.worktree !== undefined,
|
|
309
|
+
...(direct ? { origin: "direct" } : {}),
|
|
284
310
|
})
|
|
285
311
|
: this.env.runners?.(record.agent);
|
|
286
312
|
if (runner === undefined)
|
|
@@ -327,6 +353,7 @@ export class SubagentRegistry {
|
|
|
327
353
|
emit: (event) => this.host.emit(event),
|
|
328
354
|
log: (level, message) => this.host.log(level, message),
|
|
329
355
|
now: () => this.now(),
|
|
356
|
+
appendTrace: (data) => appendTraceEntry(this.host, data), // [W6-C0]
|
|
330
357
|
};
|
|
331
358
|
}
|
|
332
359
|
async finish(record, result, aborted = false) {
|
|
@@ -13,7 +13,7 @@ import type { SystemMessage, ToolDecl } from "../ai/types.js";
|
|
|
13
13
|
import { type SystemState } from "../session/projection.js";
|
|
14
14
|
import type { AgentMessage } from "../session/types.js";
|
|
15
15
|
import type { ToolDefinition } from "../tools/types.js";
|
|
16
|
-
export declare const SECTION_ORDER: readonly ["preamble", "tools", "rules", "project_context", "skills", "hooks", "cwd", "host", "role"];
|
|
16
|
+
export declare const SECTION_ORDER: readonly ["preamble", "tools", "rules", "project_context", "skills", "memory", "hooks", "cwd", "host", "role"];
|
|
17
17
|
export type SectionName = (typeof SECTION_ORDER)[number];
|
|
18
18
|
export declare const DEFAULT_PREAMBLE: string;
|
|
19
19
|
export interface SystemPromptInput {
|
|
@@ -38,6 +38,8 @@ export interface SystemPromptInput {
|
|
|
38
38
|
hostInstructions?: readonly string[];
|
|
39
39
|
/** [W5-G] task 子会话的角色说明(子 Agent 通用说明 + 类型正文);主会话没有。 */
|
|
40
40
|
role?: string;
|
|
41
|
+
/** [W6-C0] 预渲染的 `<memory_index>` 节(W6-M 的 memory/section.ts);未开启记忆时不给。 */
|
|
42
|
+
memory?: string;
|
|
41
43
|
}
|
|
42
44
|
export declare function toolDecl(tool: ToolDefinition): ToolDecl;
|
|
43
45
|
/** 按名排序的工具声明(与 ToolRegistry.active() 的顺序一致)。 */
|
|
@@ -18,6 +18,8 @@ export const SECTION_ORDER = [
|
|
|
18
18
|
"rules",
|
|
19
19
|
"project_context",
|
|
20
20
|
"skills",
|
|
21
|
+
// [W6-C0] 记忆索引(W6-M,docs/wave6-plan.md §3.4);未开启时为 undefined,字节不变
|
|
22
|
+
"memory",
|
|
21
23
|
"hooks",
|
|
22
24
|
"cwd",
|
|
23
25
|
"host",
|
|
@@ -66,6 +68,7 @@ export function assembleSections(input) {
|
|
|
66
68
|
rules: rules.length > 0 ? `Rules:\n${rules.map((rule) => `- ${rule}`).join("\n")}` : undefined,
|
|
67
69
|
project_context: nonEmpty(projectContext),
|
|
68
70
|
skills: nonEmpty(skills),
|
|
71
|
+
memory: nonEmpty(input.memory),
|
|
69
72
|
hooks: nonEmpty(input.hookContext),
|
|
70
73
|
cwd: `Current working directory: ${input.cwd}`,
|
|
71
74
|
host: host.length > 0 ? host.join("\n\n") : undefined,
|
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
* `terminate` 要整批都为真才提前结束。`stopReason: "length"` 且有工具调用 → 整批判失败不执行。
|
|
9
9
|
* abort:未开始的调用直接给 `aborted by user` 错误结果;执行中的工具收到 signal,超过宽限期仍未结束
|
|
10
10
|
* 则不再等待、记 `aborted by user`。结果超 `maxToolResultChars` 截断并把全文写到 `outputDir`:
|
|
11
|
-
* [W5-H2] 保留头 70% + 尾 30%,中间 `[… N
|
|
11
|
+
* [W5-H2] 保留头 70% + 尾 30%,中间 `[… N chars omitted (…; full output at <path>)]`(tools/truncate.ts;
|
|
12
|
+
* [W6-C0] 进模型的标记固定英文,与界面语言无关)。
|
|
12
13
|
*
|
|
13
14
|
* 嵌套调用(`ToolContext.tools.executeTool`,codemode 脚本里的 `tools.*`)走 `runSingleToolCall`:
|
|
14
15
|
* 同一套校验与门禁,按**全部未禁用工具**查找(codemode only 模式下活动集只有 codemode),
|
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
* `terminate` 要整批都为真才提前结束。`stopReason: "length"` 且有工具调用 → 整批判失败不执行。
|
|
9
9
|
* abort:未开始的调用直接给 `aborted by user` 错误结果;执行中的工具收到 signal,超过宽限期仍未结束
|
|
10
10
|
* 则不再等待、记 `aborted by user`。结果超 `maxToolResultChars` 截断并把全文写到 `outputDir`:
|
|
11
|
-
* [W5-H2] 保留头 70% + 尾 30%,中间 `[… N
|
|
11
|
+
* [W5-H2] 保留头 70% + 尾 30%,中间 `[… N chars omitted (…; full output at <path>)]`(tools/truncate.ts;
|
|
12
|
+
* [W6-C0] 进模型的标记固定英文,与界面语言无关)。
|
|
12
13
|
*
|
|
13
14
|
* 嵌套调用(`ToolContext.tools.executeTool`,codemode 脚本里的 `tools.*`)走 `runSingleToolCall`:
|
|
14
15
|
* 同一套校验与门禁,按**全部未禁用工具**查找(codemode only 模式下活动集只有 codemode),
|
|
@@ -130,13 +131,13 @@ function truncateResult(call, result, options, nested = false) {
|
|
|
130
131
|
const text = resultText(result.content);
|
|
131
132
|
if (text.length <= limit)
|
|
132
133
|
return result;
|
|
133
|
-
let where = "
|
|
134
|
+
let where = "full output not saved";
|
|
134
135
|
if (options.outputDir !== undefined) {
|
|
135
136
|
try {
|
|
136
137
|
mkdirSync(options.outputDir, { recursive: true });
|
|
137
138
|
const file = join(options.outputDir, `${call.id.replace(/[^A-Za-z0-9_-]/g, "_")}.txt`);
|
|
138
139
|
writeFileSync(file, text, "utf8");
|
|
139
|
-
where =
|
|
140
|
+
where = `full output at ${file}`;
|
|
140
141
|
}
|
|
141
142
|
catch {
|
|
142
143
|
// 落盘失败只影响提示文字
|
|
@@ -145,7 +146,7 @@ function truncateResult(call, result, options, nested = false) {
|
|
|
145
146
|
const images = typeof result.content === "string"
|
|
146
147
|
? []
|
|
147
148
|
: result.content.filter((block) => block.type === "image");
|
|
148
|
-
const { content } = truncateMiddle(text, limit, (omitted) => `[… ${omitted}
|
|
149
|
+
const { content } = truncateMiddle(text, limit, (omitted) => `[… ${omitted} chars omitted (truncated from ${text.length} chars; ${where})]`);
|
|
149
150
|
return {
|
|
150
151
|
...result,
|
|
151
152
|
content: images.length > 0 ? [{ type: "text", text: content }, ...images] : content,
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 第六波会话事件与统计(docs/wave6-plan.md §4.4、D17)。[W6-C0] 契约文件:形状在这里,行为由 W6-O 实现。
|
|
3
|
+
*/
|
|
4
|
+
/** 一档配额窗口的用量。 */
|
|
5
|
+
export interface QuotaWindow {
|
|
6
|
+
/** 0–100。 */
|
|
7
|
+
usedPercent: number;
|
|
8
|
+
/** epoch ms。 */
|
|
9
|
+
resetsAt?: number;
|
|
10
|
+
windowMinutes?: number;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* [W6-O] 订阅配额更新:codex flavor 来自 `x-codex-*` 响应头与 `codex.rate_limits` 事件;SIWC 只在 429 时给出。
|
|
14
|
+
* 宿主只消费它与错误码 `auth_expired` / `quota_exceeded`。
|
|
15
|
+
*/
|
|
16
|
+
export interface QuotaUpdateEvent {
|
|
17
|
+
type: "quota_update";
|
|
18
|
+
provider: string;
|
|
19
|
+
planType?: string;
|
|
20
|
+
primary?: QuotaWindow;
|
|
21
|
+
secondary?: QuotaWindow;
|
|
22
|
+
}
|
|
23
|
+
export type SessionEventW6 = QuotaUpdateEvent;
|
|
24
|
+
/** [W6-O] 订阅计费的请求(`Usage.billing: "subscription"`):单列,不折算美元。 */
|
|
25
|
+
export interface SubscriptionStats {
|
|
26
|
+
requests: number;
|
|
27
|
+
byProvider: Record<string, {
|
|
28
|
+
requests: number;
|
|
29
|
+
input: number;
|
|
30
|
+
output: number;
|
|
31
|
+
cacheRead: number;
|
|
32
|
+
}>;
|
|
33
|
+
/** [W6-O] 本会话最近一次 `quota_update`(没有收到过时缺省)。 */
|
|
34
|
+
quota?: QuotaUpdateEvent;
|
|
35
|
+
}
|
|
36
|
+
export interface SessionStatsW6 {
|
|
37
|
+
/** [W6-O] 订阅用量;没有订阅请求时缺省。 */
|
|
38
|
+
subscription?: SubscriptionStats;
|
|
39
|
+
}
|
package/dist/agent/types.d.ts
CHANGED
|
@@ -28,6 +28,7 @@ import type { AgentMessage, BranchSummaryEntry, SessionEntry } from "../session/
|
|
|
28
28
|
import type { RewindMode, RewindPoint, RewindRequest, RewindResult, RewindSkipReason } from "../checkpoints/types.js";
|
|
29
29
|
import type { ToolDefinition, ToolResult } from "../tools/types.js";
|
|
30
30
|
import type { SessionEventW5, SessionStatsW5 } from "./types-w5.js";
|
|
31
|
+
import type { SessionEventW6, SessionStatsW6 } from "./types-w6.js";
|
|
31
32
|
export type * from "./types-w5.js";
|
|
32
33
|
export type { AssistantContentBlock, AssistantMessage, ContentBlock, ImageBlock, Message, StopReason, SystemMessage, TextBlock, ThinkingBlock, ToolCallBlock, ToolResultMessage, Usage, UserMessage, } from "../ai/types.js";
|
|
33
34
|
export type { AgentMessage, BranchSummaryMessage, CompactionSummaryMessage, CustomMessage, } from "../session/types.js";
|
|
@@ -292,7 +293,9 @@ export type SessionEvent = {
|
|
|
292
293
|
estimatedTurnsLeft?: number;
|
|
293
294
|
}
|
|
294
295
|
/** [W5-C0] 第五波事件(agent/types-w5.ts)。 */
|
|
295
|
-
| SessionEventW5
|
|
296
|
+
| SessionEventW5
|
|
297
|
+
/** [W6-C0] 第六波事件(agent/types-w6.ts)。 */
|
|
298
|
+
| SessionEventW6;
|
|
296
299
|
export type SessionEventType = SessionEvent["type"];
|
|
297
300
|
export type PromptDisposition = "started" | "queued" | "handled";
|
|
298
301
|
export interface PromptOptions {
|
|
@@ -325,7 +328,7 @@ export interface SessionState {
|
|
|
325
328
|
autoRetry: boolean;
|
|
326
329
|
}
|
|
327
330
|
/** [W5-C0] `telemetry? / external? / tasks?` 见 `SessionStatsW5`。 */
|
|
328
|
-
export interface SessionStats extends SessionStatsW5 {
|
|
331
|
+
export interface SessionStats extends SessionStatsW5, SessionStatsW6 {
|
|
329
332
|
sessionId: string;
|
|
330
333
|
sessionFile: string | undefined;
|
|
331
334
|
userMessages: number;
|
package/dist/agents/external.js
CHANGED
|
@@ -106,7 +106,7 @@ class ExternalTaskHandle {
|
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
108
|
if (this.inner.id === "")
|
|
109
|
-
throw new AmaError("agent_closed", "
|
|
109
|
+
throw new AmaError("agent_closed", "the external agent session was never established; cannot continue it");
|
|
110
110
|
this.inner = await this.reopen(this.inner.id, text);
|
|
111
111
|
this.stopped = false;
|
|
112
112
|
}
|
|
@@ -4,6 +4,9 @@
|
|
|
4
4
|
* 编排在 agent/subagent-registry.ts。
|
|
5
5
|
*/
|
|
6
6
|
import type { SubagentUpdateEvent } from "../agent/types-w5.js";
|
|
7
|
+
import type { MessageOrigin } from "../ai/types.js";
|
|
8
|
+
import type { SessionEvent } from "../agent/types.js";
|
|
9
|
+
import type { TraceExternalTurnData } from "../trace/types.js";
|
|
7
10
|
import type { Worktree, WorktreeOutcome } from "../agent/worktree.js";
|
|
8
11
|
import type { SessionEntry } from "../session/types.js";
|
|
9
12
|
import type { RunnerHandle, SubagentEvent, SubagentRequest, SubagentResult, TaskInfo } from "../tools/types.js";
|
|
@@ -34,13 +37,73 @@ export interface AmaRunnerSpec {
|
|
|
34
37
|
resumeFile?: string;
|
|
35
38
|
/** worktree 里运行:不记父会话检查点。 */
|
|
36
39
|
isolated: boolean;
|
|
40
|
+
/** [W6-A] 首条 prompt 的 origin(子 Agent 视图里续聊已释放的子会话 = `"direct"`)。 */
|
|
41
|
+
origin?: MessageOrigin;
|
|
37
42
|
}
|
|
38
|
-
/**
|
|
43
|
+
/**
|
|
44
|
+
* [W6-C0] 外部 Agent 的展示事件(`DriverEvent` 派生,子 Agent 视图用):只在内存环形缓冲里(≤ 2000 条 /
|
|
45
|
+
* 1 MB),不落盘(docs/wave6-plan.md §1.2、D2)。
|
|
46
|
+
*/
|
|
47
|
+
export interface ExternalDisplayEvent {
|
|
48
|
+
at: number;
|
|
49
|
+
kind: "text" | "thought" | "tool" | "notice" | "turn";
|
|
50
|
+
text?: string;
|
|
51
|
+
toolName?: string;
|
|
52
|
+
toolId?: string;
|
|
53
|
+
status?: "started" | "completed" | "failed";
|
|
54
|
+
level?: "info" | "warn";
|
|
55
|
+
turn?: number;
|
|
56
|
+
}
|
|
57
|
+
/** runner 句柄的可选扩展(ama 子会话提供;[W6-C0] 视图钩子由 W6-A 实现)。 */
|
|
39
58
|
export type TaskHandle = RunnerHandle & {
|
|
40
59
|
readonly sessionFile?: string;
|
|
41
60
|
readonly model?: string;
|
|
42
61
|
dispose?(): Promise<void>;
|
|
62
|
+
/** [W6-C0] ama 子会话的实时事件(子 Agent 视图跟随);返回取消订阅。 */
|
|
63
|
+
observe?(listener: (event: SessionEvent) => void): () => void;
|
|
64
|
+
/** [W6-C0] ama 子会话当前分支的条目(视图全量渲染)。 */
|
|
65
|
+
entries?(): readonly SessionEntry[];
|
|
66
|
+
/** [W6-C0] 外部 Agent 的环形缓冲(W6-A)。 */
|
|
67
|
+
recent?(): readonly ExternalDisplayEvent[];
|
|
68
|
+
/**
|
|
69
|
+
* [W6-A] 人在子 Agent 视图里直接发的消息(子会话 user 消息 `origin: "direct"`):`followUp` = 本轮运行中
|
|
70
|
+
* 排到回合结束(不在运行中抛 `task_idle`,由注册表排队到运行结束后续聊);`send` = 空闲时开新一轮(同 `send`)。
|
|
71
|
+
* ama 子会话提供。
|
|
72
|
+
*/
|
|
73
|
+
message?(text: string, when: "followUp" | "send"): Promise<void>;
|
|
43
74
|
};
|
|
75
|
+
/** [W6-A] 外部 Agent 环形缓冲的上限(docs/wave6-plan.md D2)。 */
|
|
76
|
+
export declare const RING_MAX_EVENTS = 2000;
|
|
77
|
+
export declare const RING_MAX_BYTES: number;
|
|
78
|
+
/**
|
|
79
|
+
* [W6-A] 外部 Agent 展示事件的内存环形缓冲:相邻的同类文本(text / thought)合并成一条;超过条数或字节
|
|
80
|
+
* 上限从最旧的丢。只在内存,不落盘(第五波 §5.4:外部 Agent 原始事件不进 JSONL)。
|
|
81
|
+
*/
|
|
82
|
+
export declare class DisplayRing {
|
|
83
|
+
private readonly maxEvents;
|
|
84
|
+
private readonly maxBytes;
|
|
85
|
+
private readonly events;
|
|
86
|
+
private bytes;
|
|
87
|
+
constructor(maxEvents?: number, maxBytes?: number);
|
|
88
|
+
get size(): number;
|
|
89
|
+
items(): readonly ExternalDisplayEvent[];
|
|
90
|
+
push(event: ExternalDisplayEvent): void;
|
|
91
|
+
private trim;
|
|
92
|
+
private drop;
|
|
93
|
+
}
|
|
94
|
+
/** [W6-A] 子 Agent 视图读的一条任务的实时数据(`SubagentRegistry.live`)。 */
|
|
95
|
+
export interface TaskLive {
|
|
96
|
+
info: TaskInfo;
|
|
97
|
+
/** 还在并发池里排队(尚未开跑)。 */
|
|
98
|
+
queued: boolean;
|
|
99
|
+
/** ama 子会话的观察钩子(句柄在内存时)。 */
|
|
100
|
+
observe?(listener: (event: SessionEvent) => void): () => void;
|
|
101
|
+
entries?(): readonly SessionEntry[];
|
|
102
|
+
/** 外部 Agent 的环形缓冲(本进程里跑过才有)。 */
|
|
103
|
+
recent: readonly ExternalDisplayEvent[];
|
|
104
|
+
/** 人在视图里发、等运行结束再续聊的消息数。 */
|
|
105
|
+
pending: number;
|
|
106
|
+
}
|
|
44
107
|
export interface TaskRecord {
|
|
45
108
|
info: TaskInfo;
|
|
46
109
|
agent: AgentDefinition;
|
|
@@ -59,12 +122,22 @@ export interface TaskRecord {
|
|
|
59
122
|
worktreeOutcome?: WorktreeOutcome;
|
|
60
123
|
last?: SubagentResult;
|
|
61
124
|
onUpdate?: (partial: string) => void;
|
|
125
|
+
/** [W6-A] 在并发池里排队(acquire 之前)。 */
|
|
126
|
+
queued?: boolean;
|
|
127
|
+
/** [W6-A] 外部 Agent 的展示事件(内存环形缓冲)。 */
|
|
128
|
+
ring?: DisplayRing;
|
|
129
|
+
/** [W6-A] 视图里发来、等本次运行结束再续聊的消息。 */
|
|
130
|
+
direct?: string[];
|
|
131
|
+
/** [W6-A] 下一次续聊是人在视图里发的(子会话 user 消息记 `origin: "direct"`)。 */
|
|
132
|
+
directNext?: boolean;
|
|
62
133
|
}
|
|
63
134
|
export declare function newRecord(info: TaskInfo, agent: AgentDefinition, parentToolCallId: string, cwd: string, isolation?: "none" | "worktree"): TaskRecord;
|
|
64
135
|
export interface ProgressSink {
|
|
65
136
|
emit(event: SubagentUpdateEvent): void;
|
|
66
137
|
log(level: "info" | "warn", message: string): void;
|
|
67
138
|
now(): number;
|
|
139
|
+
/** [W6-C0] 写父会话的 `ama.trace`(外部 Agent 回合骨架)。 */
|
|
140
|
+
appendTrace?(data: TraceExternalTurnData): void;
|
|
68
141
|
}
|
|
69
142
|
export declare function flushText(record: TaskRecord, sink: ProgressSink): void;
|
|
70
143
|
/** runner 进度 → 记录与 `subagent_update`(文本 ≥ 250 ms 合并,轮次与结束时冲刷)。 */
|
|
@@ -44,6 +44,66 @@ export class SubagentPool {
|
|
|
44
44
|
this.waiters[0]?.();
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
|
+
/** [W6-A] 外部 Agent 环形缓冲的上限(docs/wave6-plan.md D2)。 */
|
|
48
|
+
export const RING_MAX_EVENTS = 2000;
|
|
49
|
+
export const RING_MAX_BYTES = 1024 * 1024;
|
|
50
|
+
/**
|
|
51
|
+
* [W6-A] 外部 Agent 展示事件的内存环形缓冲:相邻的同类文本(text / thought)合并成一条;超过条数或字节
|
|
52
|
+
* 上限从最旧的丢。只在内存,不落盘(第五波 §5.4:外部 Agent 原始事件不进 JSONL)。
|
|
53
|
+
*/
|
|
54
|
+
export class DisplayRing {
|
|
55
|
+
maxEvents;
|
|
56
|
+
maxBytes;
|
|
57
|
+
events = [];
|
|
58
|
+
bytes = 0;
|
|
59
|
+
constructor(maxEvents = RING_MAX_EVENTS, maxBytes = RING_MAX_BYTES) {
|
|
60
|
+
this.maxEvents = maxEvents;
|
|
61
|
+
this.maxBytes = maxBytes;
|
|
62
|
+
}
|
|
63
|
+
get size() {
|
|
64
|
+
return this.bytes;
|
|
65
|
+
}
|
|
66
|
+
items() {
|
|
67
|
+
return this.events;
|
|
68
|
+
}
|
|
69
|
+
push(event) {
|
|
70
|
+
const last = this.events.at(-1);
|
|
71
|
+
const add = sizeOf(event);
|
|
72
|
+
if (last !== undefined &&
|
|
73
|
+
(event.kind === "text" || event.kind === "thought") &&
|
|
74
|
+
last.kind === event.kind &&
|
|
75
|
+
last.turn === event.turn) {
|
|
76
|
+
last.text = (last.text ?? "") + (event.text ?? "");
|
|
77
|
+
this.bytes += add;
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
this.events.push({ ...event });
|
|
81
|
+
this.bytes += add;
|
|
82
|
+
}
|
|
83
|
+
this.trim();
|
|
84
|
+
}
|
|
85
|
+
trim() {
|
|
86
|
+
while (this.events.length > this.maxEvents)
|
|
87
|
+
this.drop();
|
|
88
|
+
while (this.bytes > this.maxBytes && this.events.length > 1)
|
|
89
|
+
this.drop();
|
|
90
|
+
const only = this.events[0];
|
|
91
|
+
if (this.bytes > this.maxBytes && only?.text !== undefined) {
|
|
92
|
+
// 单条超过上限:保留尾部
|
|
93
|
+
const keep = only.text.slice(only.text.length - Math.floor(this.maxBytes / 4));
|
|
94
|
+
this.bytes = this.bytes - Buffer.byteLength(only.text) + Buffer.byteLength(keep);
|
|
95
|
+
only.text = keep;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
drop() {
|
|
99
|
+
const first = this.events.shift();
|
|
100
|
+
if (first !== undefined)
|
|
101
|
+
this.bytes -= sizeOf(first);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
function sizeOf(event) {
|
|
105
|
+
return Buffer.byteLength(event.text ?? "") + Buffer.byteLength(event.toolName ?? "") + 32;
|
|
106
|
+
}
|
|
47
107
|
export function newRecord(info, agent, parentToolCallId, cwd, isolation = "none") {
|
|
48
108
|
return { info, agent, parentToolCallId, isolation, cwd, text: "", pendingText: "", lastFlush: 0 };
|
|
49
109
|
}
|
|
@@ -63,6 +123,8 @@ export function flushText(record, sink) {
|
|
|
63
123
|
/** runner 进度 → 记录与 `subagent_update`(文本 ≥ 250 ms 合并,轮次与结束时冲刷)。 */
|
|
64
124
|
export function applyRunnerEvent(record, event, sink) {
|
|
65
125
|
const taskId = record.info.taskId;
|
|
126
|
+
if (record.info.runner !== "ama")
|
|
127
|
+
recordDisplay(record, event, sink.now());
|
|
66
128
|
switch (event.type) {
|
|
67
129
|
case "text":
|
|
68
130
|
record.text += event.delta;
|
|
@@ -105,6 +167,44 @@ export function applyRunnerEvent(record, event, sink) {
|
|
|
105
167
|
case "notice":
|
|
106
168
|
sink.log(event.level, `[task ${taskId}] ${event.text}`);
|
|
107
169
|
return;
|
|
170
|
+
case "turn_trace":
|
|
171
|
+
sink.appendTrace?.({
|
|
172
|
+
kind: "external_turn",
|
|
173
|
+
taskId,
|
|
174
|
+
agent: record.info.agent,
|
|
175
|
+
...event.trace,
|
|
176
|
+
});
|
|
177
|
+
return;
|
|
178
|
+
default:
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
/** [W6-A] 外部 Agent 的进度 → 环形缓冲(ama 子会话由视图直接订阅子会话,不进这里)。 */
|
|
183
|
+
function recordDisplay(record, event, now) {
|
|
184
|
+
const turn = record.info.turns ?? 0;
|
|
185
|
+
const ring = (record.ring ??= new DisplayRing());
|
|
186
|
+
switch (event.type) {
|
|
187
|
+
case "text":
|
|
188
|
+
case "thought":
|
|
189
|
+
if (event.delta !== "")
|
|
190
|
+
ring.push({ at: now, kind: event.type, text: event.delta, turn });
|
|
191
|
+
return;
|
|
192
|
+
case "tool":
|
|
193
|
+
ring.push({
|
|
194
|
+
at: event.at ?? now,
|
|
195
|
+
kind: "tool",
|
|
196
|
+
toolName: event.toolName,
|
|
197
|
+
status: event.status,
|
|
198
|
+
...(event.id === undefined ? {} : { toolId: event.id }),
|
|
199
|
+
turn,
|
|
200
|
+
});
|
|
201
|
+
return;
|
|
202
|
+
case "turn":
|
|
203
|
+
ring.push({ at: now, kind: "turn", turn: event.turn });
|
|
204
|
+
return;
|
|
205
|
+
case "notice":
|
|
206
|
+
ring.push({ at: now, kind: "notice", text: event.text, level: event.level, turn });
|
|
207
|
+
return;
|
|
108
208
|
default:
|
|
109
209
|
return;
|
|
110
210
|
}
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
* 并提示一次(实测:某中转的 Responses 对 DeepSeek 拒收 prompt_cache_retention / _options)。
|
|
15
15
|
*/
|
|
16
16
|
import { HttpError, postJson } from "../http.js";
|
|
17
|
+
import { msg } from "../../i18n/index.js";
|
|
17
18
|
const DEFAULT_BASE_URLS = {
|
|
18
19
|
"anthropic-messages": "https://api.anthropic.com",
|
|
19
20
|
"openai-completions": "https://api.openai.com/v1",
|
|
@@ -176,7 +177,7 @@ export async function postWithCacheFallback(model, url, options) {
|
|
|
176
177
|
if (!field || !stripped || stripped.removed === 0)
|
|
177
178
|
throw error;
|
|
178
179
|
strippedCacheParams.add(key);
|
|
179
|
-
warn(
|
|
180
|
+
warn(msg().errors.cacheParamsStripped(key, field, SUGGESTION[field]));
|
|
180
181
|
return postJson(url, { ...options, body: stripped.body });
|
|
181
182
|
}
|
|
182
183
|
}
|