@armadra/agent 0.5.1 → 0.6.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 +203 -304
- package/CHANGELOG.zh-CN.md +462 -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/discovered-cache.d.ts +48 -0
- package/dist/ai/providers/discovered-cache.js +102 -0
- package/dist/ai/providers/enrich.js +2 -7
- package/dist/ai/providers/model-visibility.d.ts +33 -0
- package/dist/ai/providers/model-visibility.js +70 -0
- 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/registry.d.ts +2 -0
- package/dist/ai/providers/registry.js +6 -1
- 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 +35 -0
- package/dist/auth/chatgpt/cli.js +279 -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 +26532 -11045
- 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.js +8 -6
- 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 +6 -0
- package/dist/cli/compose-providers.js +38 -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 +145 -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.js +23 -20
- package/dist/cli/subcommands/models-discover.d.ts +4 -0
- package/dist/cli/subcommands/models-discover.js +60 -21
- package/dist/cli/subcommands/models-enable.d.ts +13 -0
- package/dist/cli/subcommands/models-enable.js +145 -0
- package/dist/cli/subcommands/models.d.ts +3 -1
- package/dist/cli/subcommands/models.js +39 -24
- 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 +1 -1
- package/dist/cli/subcommands/providers.js +45 -50
- 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 +102 -69
- 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 +12 -4
- 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 +81 -0
- package/dist/config/settings-registry.js +185 -0
- package/dist/config/types-w5.d.ts +7 -0
- package/dist/config/types-w5.js +2 -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 +2209 -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 +189 -0
- package/dist/i18n/messages/auth.js +201 -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 +248 -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 +293 -0
- package/dist/i18n/messages/config-keys.js +296 -0
- package/dist/i18n/messages/config.d.ts +508 -0
- package/dist/i18n/messages/config.js +241 -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 +99 -0
- package/dist/i18n/messages/interactive-startup.js +100 -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 +489 -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 +233 -0
- package/dist/i18n/messages/panels.js +232 -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 +355 -0
- package/dist/i18n/messages/settings.js +343 -0
- package/dist/i18n/messages/subcommands-config.d.ts +113 -0
- package/dist/i18n/messages/subcommands-config.js +129 -0
- package/dist/i18n/messages/subcommands-models.d.ts +34 -0
- package/dist/i18n/messages/subcommands-models.js +34 -0
- package/dist/i18n/messages/subcommands.d.ts +576 -0
- package/dist/i18n/messages/subcommands.js +477 -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 +11 -0
- package/dist/modes/commands-core.js +93 -62
- 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 +100 -49
- 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.js +6 -7
- 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 +21 -22
- package/dist/modes/interactive/key-dispatch.d.ts +12 -0
- package/dist/modes/interactive/key-dispatch.js +24 -9
- package/dist/modes/interactive/line/line-editor.js +2 -1
- package/dist/modes/interactive/line/line-mode.js +18 -7
- 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/model-items.d.ts +45 -0
- package/dist/modes/interactive/model-items.js +134 -0
- package/dist/modes/interactive/model-picker.d.ts +57 -0
- package/dist/modes/interactive/model-picker.js +191 -0
- 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.d.ts +3 -9
- package/dist/modes/interactive/startup-ui.js +44 -88
- 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 +8 -10
- package/dist/permissions/bypass.js +19 -10
- 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/select-list.d.ts +2 -0
- package/dist/tui/components/select-list.js +7 -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 +5 -0
- package/dist/tui/keybindings.js +17 -5
- 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 +627 -0
- package/docs/en/rpc.md +361 -0
- package/docs/en/sessions.md +219 -0
- package/docs/en/tui.md +534 -0
- package/docs/host-api.md +18 -17
- package/docs/memory.md +172 -0
- package/docs/permissions.md +2 -2
- package/docs/providers.md +73 -1
- package/docs/rpc.md +31 -3
- package/docs/session-format.md +8 -2
- package/docs/sessions.md +29 -1
- package/docs/tui.md +140 -4
- package/package.json +8 -3
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 运行中会话的轨迹查询:RPC `get_trace` 与 SDK `session.trace()`(docs/wave6-plan.md §2.6、D29)。[W6-T2]
|
|
3
|
+
*
|
|
4
|
+
* 构建器输入取自会话(`traceInputOf`);运行中时叠一层 `{ running: true }`(没有结果的工具算 running 而不是
|
|
5
|
+
* interrupted,不编造时长);子会话读取按会话缓存(mtime + 大小没变就不重读)。
|
|
6
|
+
*/
|
|
7
|
+
import { queryTrace } from "./query.js";
|
|
8
|
+
import { childLoader, traceInputOf } from "./session.js";
|
|
9
|
+
const loaders = new WeakMap();
|
|
10
|
+
function loaderOf(session) {
|
|
11
|
+
let loader = loaders.get(session);
|
|
12
|
+
if (loader === undefined) {
|
|
13
|
+
loader = childLoader();
|
|
14
|
+
loaders.set(session, loader);
|
|
15
|
+
}
|
|
16
|
+
return loader;
|
|
17
|
+
}
|
|
18
|
+
/** RPC `get_trace`。参数不合法抛 `invalid_arguments`,任务不存在抛 `task_not_found`。 */
|
|
19
|
+
export function sessionTrace(session, params) {
|
|
20
|
+
return queryTrace(traceInputOf(session), params, {
|
|
21
|
+
loadChild: loaderOf(session),
|
|
22
|
+
live: { running: session.state.isStreaming },
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
/** SDK `session.trace(options?)`:缺省全部回合;`turnLimit` 取尾部若干回合;`taskId` 取子轨迹。 */
|
|
26
|
+
export function sdkSessionTrace(session, options = {}) {
|
|
27
|
+
const { branch, turnLimit, taskId, now } = options;
|
|
28
|
+
return queryTrace(traceInputOf(session), {
|
|
29
|
+
...(branch !== undefined ? { branch } : {}),
|
|
30
|
+
...(turnLimit !== undefined ? { turnLimit } : {}),
|
|
31
|
+
...(taskId !== undefined ? { taskId } : {}),
|
|
32
|
+
}, {
|
|
33
|
+
loadChild: loaderOf(session),
|
|
34
|
+
live: { running: session.state.isStreaming },
|
|
35
|
+
unlimited: turnLimit === undefined,
|
|
36
|
+
...(now !== undefined ? { now } : {}),
|
|
37
|
+
}).trace;
|
|
38
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 轨迹查询:RPC `get_trace`、SDK `session.trace()`、`ama sessions trace --json` 共用(docs/wave6-plan.md §2.6)。
|
|
3
|
+
* [W6-T2]
|
|
4
|
+
*
|
|
5
|
+
* - **窗口**:在 `Trace.turns` 上切。缺省尾部 `turnLimit`(50,上限 500)个回合;`before`(回合 id)向前翻页;
|
|
6
|
+
* `since`(条目 id)只返回「受该条目之后的新条目影响」的回合起到末尾——含 `since` 所在回合,以及子树
|
|
7
|
+
* `entryIds` 引用了新条目的更早回合(后台任务晚到的结束条目会改到旧回合)。`since` 不在所选分支上
|
|
8
|
+
* (rewind 之后、或未知 id)时从第一个回合起全量返回,与 `get_entries.since` 一致。客户端合并规则:
|
|
9
|
+
* 从返回的第一个回合 id 起替换本地列表的尾部(找不到该 id 就整体替换)。
|
|
10
|
+
* - `totals` 与 `aux` 始终是整条分支的;`turns` 才是窗口。
|
|
11
|
+
* - **脱敏**:结果整棵过 `redactValue`;`content:"preview"` 时附 `previews`(`preview.ts`,先脱敏后截断)。
|
|
12
|
+
* - `taskId`:ama 子会话 → 子轨迹(游标与 `leafId` 都按子会话);外部 Agent → 空回合的轨迹 + `task.external`
|
|
13
|
+
* 骨架。两种都在 `task` 里回子 Agent 节点本身(不含 `child`,避免重复)。
|
|
14
|
+
* - 错误:`task_not_found`、`invalid_arguments`(英文 message,界面层自己渲染)。
|
|
15
|
+
*/
|
|
16
|
+
import { type LiveOverlay, type TraceInput } from "./build.js";
|
|
17
|
+
import { type TracePreview } from "./preview.js";
|
|
18
|
+
import type { Trace, TraceSubagentNode } from "./types.js";
|
|
19
|
+
export declare const TURN_LIMIT_DEFAULT = 50;
|
|
20
|
+
export declare const TURN_LIMIT_MAX = 500;
|
|
21
|
+
export interface TraceQuery {
|
|
22
|
+
branch?: "leaf" | "all";
|
|
23
|
+
turnLimit?: number;
|
|
24
|
+
before?: string;
|
|
25
|
+
since?: string;
|
|
26
|
+
taskId?: string;
|
|
27
|
+
content?: "none" | "preview";
|
|
28
|
+
}
|
|
29
|
+
export interface TraceQueryResult {
|
|
30
|
+
trace: Trace;
|
|
31
|
+
hasMoreBefore: boolean;
|
|
32
|
+
cursor: {
|
|
33
|
+
before?: string;
|
|
34
|
+
since: string;
|
|
35
|
+
};
|
|
36
|
+
leafId: string | null;
|
|
37
|
+
/** `taskId` 时:子 Agent 节点本身(不含 `child`)。 */
|
|
38
|
+
task?: TraceSubagentNode;
|
|
39
|
+
/** `content:"preview"` 时:`<kind>:<id>` → 预览(只含窗口内的节点)。 */
|
|
40
|
+
previews?: Record<string, TracePreview>;
|
|
41
|
+
}
|
|
42
|
+
export interface TraceQueryDeps {
|
|
43
|
+
/** 读子会话(`taskId` 用;缺省时任务的子轨迹标 childMissing)。 */
|
|
44
|
+
loadChild?: (sessionFile: string) => TraceInput | undefined;
|
|
45
|
+
/** 构建时就加载全部 ama 子会话(`sessions trace --json`;RPC 不加载,按 `taskId` 取)。 */
|
|
46
|
+
loadChildren?: boolean;
|
|
47
|
+
/** 不分页:返回全部回合(`sessions trace --json`)。 */
|
|
48
|
+
unlimited?: boolean;
|
|
49
|
+
live?: LiveOverlay;
|
|
50
|
+
now?: number;
|
|
51
|
+
}
|
|
52
|
+
/** 校验参数(RPC 的 JSON 可能是任意形状)。 */
|
|
53
|
+
export declare function checkTraceQuery(q: TraceQuery): Required<Pick<TraceQuery, "branch" | "turnLimit" | "content">>;
|
|
54
|
+
/** 构建 + 切窗口 + 脱敏。 */
|
|
55
|
+
export declare function queryTrace(input: TraceInput, q?: TraceQuery, deps?: TraceQueryDeps): TraceQueryResult;
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 轨迹查询:RPC `get_trace`、SDK `session.trace()`、`ama sessions trace --json` 共用(docs/wave6-plan.md §2.6)。
|
|
3
|
+
* [W6-T2]
|
|
4
|
+
*
|
|
5
|
+
* - **窗口**:在 `Trace.turns` 上切。缺省尾部 `turnLimit`(50,上限 500)个回合;`before`(回合 id)向前翻页;
|
|
6
|
+
* `since`(条目 id)只返回「受该条目之后的新条目影响」的回合起到末尾——含 `since` 所在回合,以及子树
|
|
7
|
+
* `entryIds` 引用了新条目的更早回合(后台任务晚到的结束条目会改到旧回合)。`since` 不在所选分支上
|
|
8
|
+
* (rewind 之后、或未知 id)时从第一个回合起全量返回,与 `get_entries.since` 一致。客户端合并规则:
|
|
9
|
+
* 从返回的第一个回合 id 起替换本地列表的尾部(找不到该 id 就整体替换)。
|
|
10
|
+
* - `totals` 与 `aux` 始终是整条分支的;`turns` 才是窗口。
|
|
11
|
+
* - **脱敏**:结果整棵过 `redactValue`;`content:"preview"` 时附 `previews`(`preview.ts`,先脱敏后截断)。
|
|
12
|
+
* - `taskId`:ama 子会话 → 子轨迹(游标与 `leafId` 都按子会话);外部 Agent → 空回合的轨迹 + `task.external`
|
|
13
|
+
* 骨架。两种都在 `task` 里回子 Agent 节点本身(不含 `child`,避免重复)。
|
|
14
|
+
* - 错误:`task_not_found`、`invalid_arguments`(英文 message,界面层自己渲染)。
|
|
15
|
+
*/
|
|
16
|
+
import { AmaError } from "../errors.js";
|
|
17
|
+
import { redactValue } from "../session/redact.js";
|
|
18
|
+
import { buildTrace, findSubagent, loadSubagentTrace, selectTraceEntries, } from "./build.js";
|
|
19
|
+
import { entryLookup } from "./detail.js";
|
|
20
|
+
import { childrenOf } from "./flatten.js";
|
|
21
|
+
import { previewKey, previewOf } from "./preview.js";
|
|
22
|
+
export const TURN_LIMIT_DEFAULT = 50;
|
|
23
|
+
export const TURN_LIMIT_MAX = 500;
|
|
24
|
+
function invalid(message) {
|
|
25
|
+
throw new AmaError("invalid_arguments", message);
|
|
26
|
+
}
|
|
27
|
+
/** 校验参数(RPC 的 JSON 可能是任意形状)。 */
|
|
28
|
+
export function checkTraceQuery(q) {
|
|
29
|
+
const branch = q.branch ?? "leaf";
|
|
30
|
+
if (branch !== "leaf" && branch !== "all")
|
|
31
|
+
invalid("branch must be leaf | all");
|
|
32
|
+
const content = q.content ?? "none";
|
|
33
|
+
if (content !== "none" && content !== "preview")
|
|
34
|
+
invalid("content must be none | preview");
|
|
35
|
+
const turnLimit = q.turnLimit ?? TURN_LIMIT_DEFAULT;
|
|
36
|
+
if (!Number.isInteger(turnLimit) || turnLimit < 1 || turnLimit > TURN_LIMIT_MAX)
|
|
37
|
+
invalid(`turnLimit must be an integer in 1..${TURN_LIMIT_MAX}`);
|
|
38
|
+
for (const key of ["before", "since", "taskId"]) {
|
|
39
|
+
const value = q[key];
|
|
40
|
+
if (value !== undefined && (typeof value !== "string" || value === ""))
|
|
41
|
+
invalid(`${key} must be a non-empty string`);
|
|
42
|
+
}
|
|
43
|
+
if (q.before !== undefined && q.since !== undefined)
|
|
44
|
+
invalid("before and since are exclusive");
|
|
45
|
+
return { branch, turnLimit, content };
|
|
46
|
+
}
|
|
47
|
+
/** 回合子树引用的条目 id(不进子 Agent 的子轨迹:那是另一个会话的条目)。 */
|
|
48
|
+
function subtreeEntryIds(node, out) {
|
|
49
|
+
for (const id of node.entryIds)
|
|
50
|
+
out.add(id);
|
|
51
|
+
if (node.kind === "subagent")
|
|
52
|
+
return;
|
|
53
|
+
for (const child of childrenOf(node))
|
|
54
|
+
subtreeEntryIds(child, out);
|
|
55
|
+
}
|
|
56
|
+
/** `since` 的起始回合下标。 */
|
|
57
|
+
function sinceStart(turns, entries, since) {
|
|
58
|
+
const at = entries.findIndex((e) => e.id === since);
|
|
59
|
+
if (at < 0)
|
|
60
|
+
return 0;
|
|
61
|
+
const position = new Map(entries.map((e, i) => [e.id, i]));
|
|
62
|
+
const fresh = new Set(entries.slice(at + 1).map((e) => e.id));
|
|
63
|
+
let start = turns.length;
|
|
64
|
+
turns.forEach((turn, i) => {
|
|
65
|
+
if ((position.get(turn.id) ?? Infinity) <= at)
|
|
66
|
+
start = i;
|
|
67
|
+
});
|
|
68
|
+
if (start === turns.length)
|
|
69
|
+
start = 0;
|
|
70
|
+
if (fresh.size === 0)
|
|
71
|
+
return start;
|
|
72
|
+
for (let i = 0; i < start; i++) {
|
|
73
|
+
const ids = new Set();
|
|
74
|
+
subtreeEntryIds(turns[i], ids);
|
|
75
|
+
if ([...ids].some((id) => fresh.has(id)))
|
|
76
|
+
return i;
|
|
77
|
+
}
|
|
78
|
+
return start;
|
|
79
|
+
}
|
|
80
|
+
function windowOf(trace, entries, q, turnLimit) {
|
|
81
|
+
const n = trace.turns.length;
|
|
82
|
+
if (q.since !== undefined)
|
|
83
|
+
return { start: sinceStart(trace.turns, entries, q.since), end: n };
|
|
84
|
+
let end = n;
|
|
85
|
+
if (q.before !== undefined) {
|
|
86
|
+
end = trace.turns.findIndex((t) => t.id === q.before);
|
|
87
|
+
if (end < 0)
|
|
88
|
+
invalid(`before ${q.before} is not a turn id on this branch`);
|
|
89
|
+
}
|
|
90
|
+
return { start: Math.max(0, end - turnLimit), end };
|
|
91
|
+
}
|
|
92
|
+
function emptyTrace(parent, node) {
|
|
93
|
+
const trace = {
|
|
94
|
+
version: 1,
|
|
95
|
+
sessionId: node.childRef?.sessionId ?? node.taskId,
|
|
96
|
+
cwd: parent.cwd,
|
|
97
|
+
startedAt: node.startedAt ?? parent.startedAt,
|
|
98
|
+
totals: {
|
|
99
|
+
requests: 0,
|
|
100
|
+
input: node.usage?.input ?? 0,
|
|
101
|
+
output: node.usage?.output ?? 0,
|
|
102
|
+
cacheRead: node.usage?.cacheRead ?? 0,
|
|
103
|
+
cacheWrite: node.usage?.cacheWrite ?? 0,
|
|
104
|
+
toolCalls: (node.external ?? []).reduce((n, t) => n + t.toolCount, 0),
|
|
105
|
+
...(node.costUsd !== undefined ? { cost: node.costUsd } : {}),
|
|
106
|
+
},
|
|
107
|
+
turns: [],
|
|
108
|
+
aux: [],
|
|
109
|
+
partial: node.status === "running",
|
|
110
|
+
};
|
|
111
|
+
if (node.endedAt !== undefined)
|
|
112
|
+
trace.endedAt = node.endedAt;
|
|
113
|
+
return trace;
|
|
114
|
+
}
|
|
115
|
+
function collectPreviews(nodes, lookup) {
|
|
116
|
+
const out = {};
|
|
117
|
+
const visit = (node) => {
|
|
118
|
+
const p = previewOf(node, lookup);
|
|
119
|
+
if (p !== undefined)
|
|
120
|
+
out[previewKey(node)] = p;
|
|
121
|
+
if (node.kind === "subagent")
|
|
122
|
+
return;
|
|
123
|
+
for (const child of childrenOf(node))
|
|
124
|
+
visit(child);
|
|
125
|
+
};
|
|
126
|
+
for (const node of nodes)
|
|
127
|
+
visit(node);
|
|
128
|
+
return out;
|
|
129
|
+
}
|
|
130
|
+
/** 构建 + 切窗口 + 脱敏。 */
|
|
131
|
+
export function queryTrace(input, q = {}, deps = {}) {
|
|
132
|
+
const { branch, turnLimit, content } = checkTraceQuery(q);
|
|
133
|
+
const base = {
|
|
134
|
+
...(deps.live !== undefined ? { live: deps.live } : {}),
|
|
135
|
+
...(deps.now !== undefined ? { now: deps.now } : {}),
|
|
136
|
+
};
|
|
137
|
+
const eager = deps.loadChildren === true && deps.loadChild !== undefined;
|
|
138
|
+
let trace = buildTrace(input, {
|
|
139
|
+
branch,
|
|
140
|
+
...base,
|
|
141
|
+
...(eager ? { loadChild: deps.loadChild } : {}),
|
|
142
|
+
});
|
|
143
|
+
let source = input;
|
|
144
|
+
let sourceBranch = branch;
|
|
145
|
+
let task;
|
|
146
|
+
if (q.taskId !== undefined) {
|
|
147
|
+
const node = findSubagent(trace, q.taskId);
|
|
148
|
+
if (node === undefined)
|
|
149
|
+
throw new AmaError("task_not_found", `no task ${q.taskId} in this session`);
|
|
150
|
+
const loadChild = deps.loadChild ?? (() => undefined);
|
|
151
|
+
const child = loadSubagentTrace(node, loadChild, deps.now);
|
|
152
|
+
const file = node.childRef?.sessionFile;
|
|
153
|
+
const childInput = child !== undefined && file !== undefined ? loadChild(file) : undefined;
|
|
154
|
+
const { child: _omit, ...rest } = node;
|
|
155
|
+
task = rest;
|
|
156
|
+
if (child !== undefined && childInput !== undefined) {
|
|
157
|
+
trace = child;
|
|
158
|
+
source = childInput;
|
|
159
|
+
sourceBranch = "leaf";
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
trace = emptyTrace(trace, node);
|
|
163
|
+
source = { ...input, entries: [] };
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
const entries = selectTraceEntries(source, sourceBranch);
|
|
167
|
+
const { start, end } = windowOf(trace, entries, q, deps.unlimited === true ? Infinity : turnLimit);
|
|
168
|
+
const turns = trace.turns.slice(start, end);
|
|
169
|
+
const leafId = source.entries.length === 0
|
|
170
|
+
? null
|
|
171
|
+
: source.leaf === undefined
|
|
172
|
+
? (source.entries.at(-1)?.id ?? null)
|
|
173
|
+
: source.leaf;
|
|
174
|
+
const result = {
|
|
175
|
+
trace: { ...trace, turns },
|
|
176
|
+
hasMoreBefore: start > 0,
|
|
177
|
+
cursor: {
|
|
178
|
+
...(start > 0 && turns[0] !== undefined ? { before: turns[0].id } : {}),
|
|
179
|
+
since: entries.at(-1)?.id ?? "",
|
|
180
|
+
},
|
|
181
|
+
leafId,
|
|
182
|
+
};
|
|
183
|
+
if (task !== undefined)
|
|
184
|
+
result.task = task;
|
|
185
|
+
if (content === "preview")
|
|
186
|
+
result.previews = collectPreviews(turns, entryLookup(source.entries, source.header.cwd));
|
|
187
|
+
return redactValue(result);
|
|
188
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 轨迹与运行中会话之间的胶水(TUI `/trace`、line 模式 `/trace`;W6-T2 的 RPC / SDK 可复用)。[W6-T1]
|
|
3
|
+
*
|
|
4
|
+
* - `traceInputOf(session)`:会话 → `TraceInput`(头、全部条目、当前叶子、会话文件)。
|
|
5
|
+
* - `childLoader()`:读 ama 子会话文件(只读、不加锁),按 mtime + 大小缓存;读不到返回 undefined
|
|
6
|
+
* (构建器据此标 `childMissing`)。
|
|
7
|
+
* - `LiveTracker`:订阅会话事件,给出 `LiveOverlay`(在途请求、执行中的工具、是否运行中)。
|
|
8
|
+
* - `traceText(session, taskId?)`:line 模式的整表文本。
|
|
9
|
+
*/
|
|
10
|
+
import type { AgentSession, SessionEvent } from "../agent/types.js";
|
|
11
|
+
import type { CommandHandler } from "../modes/commands-core.js";
|
|
12
|
+
import { type LiveOverlay, type TraceInput } from "./build.js";
|
|
13
|
+
import type { Trace } from "./types.js";
|
|
14
|
+
/** 会话 → 构建器输入。非 `AgentSessionImpl`(测试替身)用 state 拼一个头,叶子取最后一条。 */
|
|
15
|
+
export declare function traceInputOf(session: AgentSession): TraceInput;
|
|
16
|
+
/** 只读读取一个会话文件为构建器输入;读不到或损坏返回 undefined。 */
|
|
17
|
+
export declare function readTraceInput(file: string): TraceInput | undefined;
|
|
18
|
+
export type ChildLoader = ((file: string) => TraceInput | undefined) & {
|
|
19
|
+
/** 已读过的子会话(详情预览取正文用)。 */
|
|
20
|
+
inputs(): TraceInput[];
|
|
21
|
+
};
|
|
22
|
+
/** 带缓存的子会话读取(文件没变就不重读)。 */
|
|
23
|
+
export declare function childLoader(read?: (file: string) => TraceInput | undefined): ChildLoader;
|
|
24
|
+
/** 订阅会话事件,维护 live 叠加层。 */
|
|
25
|
+
export declare class LiveTracker {
|
|
26
|
+
private readonly session;
|
|
27
|
+
private readonly now;
|
|
28
|
+
private request;
|
|
29
|
+
private readonly tools;
|
|
30
|
+
constructor(session: () => AgentSession, now?: () => number);
|
|
31
|
+
/** 处理一个事件;返回它是否影响轨迹(调用方据此安排刷新)。 */
|
|
32
|
+
onEvent(event: SessionEvent): boolean;
|
|
33
|
+
overlay(): LiveOverlay;
|
|
34
|
+
}
|
|
35
|
+
/** 任务的根节点(ama 子会话就地加载子轨迹)。 */
|
|
36
|
+
export declare function taskRoot(trace: Trace, taskId: string, loadChild: ChildLoader): import("./types.js").TraceSubagentNode | undefined;
|
|
37
|
+
/** line 模式 `/trace [任务 id]` 的文本。 */
|
|
38
|
+
export declare function traceText(session: AgentSession, taskId?: string): string;
|
|
39
|
+
/** line 模式 `CommandContext.extra.trace`。 */
|
|
40
|
+
export declare const lineTraceCommand: CommandHandler;
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 轨迹与运行中会话之间的胶水(TUI `/trace`、line 模式 `/trace`;W6-T2 的 RPC / SDK 可复用)。[W6-T1]
|
|
3
|
+
*
|
|
4
|
+
* - `traceInputOf(session)`:会话 → `TraceInput`(头、全部条目、当前叶子、会话文件)。
|
|
5
|
+
* - `childLoader()`:读 ama 子会话文件(只读、不加锁),按 mtime + 大小缓存;读不到返回 undefined
|
|
6
|
+
* (构建器据此标 `childMissing`)。
|
|
7
|
+
* - `LiveTracker`:订阅会话事件,给出 `LiveOverlay`(在途请求、执行中的工具、是否运行中)。
|
|
8
|
+
* - `traceText(session, taskId?)`:line 模式的整表文本。
|
|
9
|
+
*/
|
|
10
|
+
import { statSync } from "node:fs";
|
|
11
|
+
import { AgentSessionImpl } from "../agent/session.js";
|
|
12
|
+
import { msg } from "../i18n/index.js";
|
|
13
|
+
import { readSessionReadOnly } from "../session/scan.js";
|
|
14
|
+
import { plainTheme } from "../tui/theme.js";
|
|
15
|
+
import { buildTrace, findSubagent, loadSubagentTrace, } from "./build.js";
|
|
16
|
+
import { describeNode, entryLookup } from "./detail.js";
|
|
17
|
+
import { flattenNode } from "./flatten.js";
|
|
18
|
+
import { expandAll, formatTraceText, summaryText } from "./format.js";
|
|
19
|
+
/** 会话 → 构建器输入。非 `AgentSessionImpl`(测试替身)用 state 拼一个头,叶子取最后一条。 */
|
|
20
|
+
export function traceInputOf(session) {
|
|
21
|
+
if (session instanceof AgentSessionImpl) {
|
|
22
|
+
const manager = session.manager;
|
|
23
|
+
const file = manager.file();
|
|
24
|
+
return {
|
|
25
|
+
header: manager.header(),
|
|
26
|
+
entries: manager.entries(),
|
|
27
|
+
leaf: manager.leafId(),
|
|
28
|
+
...(file !== undefined ? { sessionFile: file } : {}),
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
const entries = session.entries;
|
|
32
|
+
const header = {
|
|
33
|
+
type: "session",
|
|
34
|
+
version: 1,
|
|
35
|
+
id: session.state.sessionId,
|
|
36
|
+
timestamp: entries[0]?.timestamp ?? new Date(0).toISOString(),
|
|
37
|
+
cwd: session.state.cwd,
|
|
38
|
+
agent: { name: "ama", version: "" },
|
|
39
|
+
};
|
|
40
|
+
const file = session.state.sessionFile;
|
|
41
|
+
return { header, entries, ...(file !== undefined ? { sessionFile: file } : {}) };
|
|
42
|
+
}
|
|
43
|
+
/** 只读读取一个会话文件为构建器输入;读不到或损坏返回 undefined。 */
|
|
44
|
+
export function readTraceInput(file) {
|
|
45
|
+
try {
|
|
46
|
+
const read = readSessionReadOnly(file);
|
|
47
|
+
return { header: read.header, entries: read.entries, leaf: read.leaf, sessionFile: file };
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/** 带缓存的子会话读取(文件没变就不重读)。 */
|
|
54
|
+
export function childLoader(read = readTraceInput) {
|
|
55
|
+
const cache = new Map();
|
|
56
|
+
const load = ((file) => {
|
|
57
|
+
let stamp = "";
|
|
58
|
+
try {
|
|
59
|
+
const st = statSync(file);
|
|
60
|
+
stamp = `${st.mtimeMs}:${st.size}`;
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
stamp = "missing";
|
|
64
|
+
}
|
|
65
|
+
const hit = cache.get(file);
|
|
66
|
+
if (hit !== undefined && hit.stamp === stamp)
|
|
67
|
+
return hit.input;
|
|
68
|
+
const input = stamp === "missing" ? undefined : read(file);
|
|
69
|
+
cache.set(file, { stamp, input });
|
|
70
|
+
return input;
|
|
71
|
+
});
|
|
72
|
+
load.inputs = () => [...cache.values()].flatMap((v) => (v.input === undefined ? [] : [v.input]));
|
|
73
|
+
return load;
|
|
74
|
+
}
|
|
75
|
+
/** 订阅会话事件,维护 live 叠加层。 */
|
|
76
|
+
export class LiveTracker {
|
|
77
|
+
session;
|
|
78
|
+
now;
|
|
79
|
+
request;
|
|
80
|
+
tools = new Map();
|
|
81
|
+
constructor(session, now = Date.now) {
|
|
82
|
+
this.session = session;
|
|
83
|
+
this.now = now;
|
|
84
|
+
}
|
|
85
|
+
/** 处理一个事件;返回它是否影响轨迹(调用方据此安排刷新)。 */
|
|
86
|
+
onEvent(event) {
|
|
87
|
+
switch (event.type) {
|
|
88
|
+
case "message_start":
|
|
89
|
+
if (event.message.role !== "assistant")
|
|
90
|
+
return false;
|
|
91
|
+
this.request = { requestAt: event.message.timestamp };
|
|
92
|
+
return true;
|
|
93
|
+
case "message_update":
|
|
94
|
+
if (this.request === undefined || this.request.firstTokenAt !== undefined)
|
|
95
|
+
return false;
|
|
96
|
+
this.request.firstTokenAt = this.now();
|
|
97
|
+
this.request.provider = event.message.provider;
|
|
98
|
+
this.request.model = event.message.model;
|
|
99
|
+
return true;
|
|
100
|
+
case "message_end":
|
|
101
|
+
if (event.message.role !== "assistant")
|
|
102
|
+
return false;
|
|
103
|
+
this.request = undefined;
|
|
104
|
+
return true;
|
|
105
|
+
case "tool_execution_start":
|
|
106
|
+
this.tools.set(event.toolCallId, {
|
|
107
|
+
id: event.toolCallId,
|
|
108
|
+
name: event.toolName,
|
|
109
|
+
startedAt: this.now(),
|
|
110
|
+
...(event.parentToolCallId !== undefined ? { parentId: event.parentToolCallId } : {}),
|
|
111
|
+
});
|
|
112
|
+
return true;
|
|
113
|
+
case "tool_execution_end":
|
|
114
|
+
this.tools.delete(event.toolCallId);
|
|
115
|
+
return true;
|
|
116
|
+
case "agent_end":
|
|
117
|
+
this.request = undefined;
|
|
118
|
+
this.tools.clear();
|
|
119
|
+
return true;
|
|
120
|
+
case "entry_appended":
|
|
121
|
+
case "telemetry_tick":
|
|
122
|
+
case "agent_start":
|
|
123
|
+
return true;
|
|
124
|
+
default:
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
overlay() {
|
|
129
|
+
const live = { running: this.session().state.isStreaming };
|
|
130
|
+
if (this.request !== undefined)
|
|
131
|
+
live.request = { ...this.request };
|
|
132
|
+
if (this.tools.size > 0)
|
|
133
|
+
live.tools = [...this.tools.values()];
|
|
134
|
+
return live;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
/** 任务的根节点(ama 子会话就地加载子轨迹)。 */
|
|
138
|
+
export function taskRoot(trace, taskId, loadChild) {
|
|
139
|
+
const node = findSubagent(trace, taskId);
|
|
140
|
+
if (node !== undefined)
|
|
141
|
+
loadSubagentTrace(node, loadChild);
|
|
142
|
+
return node;
|
|
143
|
+
}
|
|
144
|
+
/** line 模式 `/trace [任务 id]` 的文本。 */
|
|
145
|
+
export function traceText(session, taskId) {
|
|
146
|
+
const input = traceInputOf(session);
|
|
147
|
+
const loadChild = childLoader();
|
|
148
|
+
const trace = buildTrace(input, { loadChild });
|
|
149
|
+
const lookup = entryLookup([...input.entries, ...loadChild.inputs().flatMap((i) => i.entries)], input.header.cwd);
|
|
150
|
+
const ctx = {
|
|
151
|
+
theme: plainTheme(),
|
|
152
|
+
describe: (n) => describeNode(n, lookup),
|
|
153
|
+
};
|
|
154
|
+
if (taskId === undefined)
|
|
155
|
+
return formatTraceText(trace, ctx);
|
|
156
|
+
const node = taskRoot(trace, taskId, loadChild);
|
|
157
|
+
if (node === undefined)
|
|
158
|
+
return `${msg().trace.taskNotFound(taskId)}\n`;
|
|
159
|
+
const rows = expandAll((expanded) => flattenNode(node, { expanded }));
|
|
160
|
+
// 标题换成任务;汇总用子轨迹(外部任务没有子轨迹,只有标题与骨架行)
|
|
161
|
+
const summary = node.child !== undefined ? ` · ${summaryText(node.child, ctx.theme)}` : "";
|
|
162
|
+
return formatTraceText(trace, ctx, rows, `${msg().trace.taskTitle(node.taskId, node.agent)}${summary}`);
|
|
163
|
+
}
|
|
164
|
+
/** line 模式 `CommandContext.extra.trace`。 */
|
|
165
|
+
export const lineTraceCommand = async (args, ctx) => {
|
|
166
|
+
const taskId = args.trim() === "" ? undefined : args.trim();
|
|
167
|
+
return { kind: "handled", message: traceText(ctx.session(), taskId).replace(/\n$/, "") };
|
|
168
|
+
};
|