@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,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 轨迹 HTML 的页面骨架、样式与脚本(docs/wave6-plan.md §2.5)。[W6-T2]
|
|
3
|
+
*
|
|
4
|
+
* 全部静态:页面只插入三样东西——`lang`、转义过的 `<title>`、已做脚本安全转义的 JSON(`html.ts`)。
|
|
5
|
+
* 脚本只用 `textContent` / `createElement` 写 DOM,不用 `innerHTML`;没有任何外部资源(CSP 见 `CSP`)。
|
|
6
|
+
*
|
|
7
|
+
* 页面:顶部标题 / 汇总 / 工具栏(搜索、跳到回合、缩放、全部展开 / 折叠、图例);中间是一张表——左列树
|
|
8
|
+
* (sticky)+ 右侧瀑布(横轴 = 会话时间,回合间空闲已压缩,刻度标原始时间);底部详情。行高固定、只建
|
|
9
|
+
* 可见 ±50 行的 DOM(虚拟列表),10k 行也流畅。键:↑↓ 选择、←→ 折叠 / 展开、`/` 搜索、Enter / Shift+Enter
|
|
10
|
+
* 在匹配间跳转、Ctrl + 滚轮缩放。深浅色跟随系统。
|
|
11
|
+
*/
|
|
12
|
+
export const CSP = "default-src 'none'; style-src 'unsafe-inline'; script-src 'unsafe-inline'";
|
|
13
|
+
export function escapeHtml(text) {
|
|
14
|
+
return text.replace(/[&<>"']/g, (c) => `&#${c.charCodeAt(0)};`);
|
|
15
|
+
}
|
|
16
|
+
const STYLE = `
|
|
17
|
+
:root{--bg:#fff;--fg:#1f2328;--mut:#656d76;--line:#d8dee4;--alt:#f6f8fa;--sel:#ddf4ff;--hit:#fff8c5;
|
|
18
|
+
--ttft:#bf8700;--dec:#0969da;--tool:#1a7f37;--agent:#8250df;--wait:#8c959f;--oth:#1b7c83;--turn:#d0d7de;
|
|
19
|
+
--err:#cf222e;--warn:#9a6700;--run:#0969da;--lw:420px;font:13px/1.4 ui-sans-serif,system-ui,sans-serif}
|
|
20
|
+
@media (prefers-color-scheme:dark){:root{--bg:#0d1117;--fg:#e6edf3;--mut:#8d96a0;--line:#30363d;--alt:#161b22;
|
|
21
|
+
--sel:#1f3a5f;--hit:#3b2e00;--ttft:#d29922;--dec:#4493f8;--tool:#3fb950;--agent:#ab7df8;--wait:#6e7681;
|
|
22
|
+
--oth:#39c5cf;--turn:#30363d;--err:#f85149;--warn:#d29922;--run:#4493f8}}
|
|
23
|
+
*{box-sizing:border-box}html,body{margin:0;height:100%;background:var(--bg);color:var(--fg)}
|
|
24
|
+
body{display:flex;flex-direction:column}
|
|
25
|
+
header{padding:8px 12px;border-bottom:1px solid var(--line)}
|
|
26
|
+
h1{font-size:15px;margin:0 0 2px}.sum{font-variant-numeric:tabular-nums}.mut{color:var(--mut)}
|
|
27
|
+
.bar{display:flex;flex-wrap:wrap;gap:6px;align-items:center;margin-top:6px}
|
|
28
|
+
input,select,button{font:inherit;color:inherit;background:var(--alt);border:1px solid var(--line);border-radius:4px;padding:2px 6px}
|
|
29
|
+
button{cursor:pointer}input{width:200px}
|
|
30
|
+
.lg{display:inline-flex;align-items:center;gap:4px;margin-left:6px;color:var(--mut)}
|
|
31
|
+
.sw{display:inline-block;width:10px;height:10px;border-radius:2px}
|
|
32
|
+
#sc{flex:1;overflow:auto;position:relative}
|
|
33
|
+
#ru{position:sticky;top:0;z-index:3;height:20px;display:flex;background:var(--bg);border-bottom:1px solid var(--line)}
|
|
34
|
+
#ru .lc{background:var(--bg)}#tk{position:relative;flex:none;height:20px}
|
|
35
|
+
.tick{position:absolute;top:0;height:20px;border-left:1px solid var(--line);padding-left:3px;font-size:11px;color:var(--mut);white-space:nowrap}
|
|
36
|
+
#bd{position:relative}
|
|
37
|
+
.row{position:absolute;left:0;height:22px;display:flex;cursor:default}
|
|
38
|
+
.row.odd .lc,.row.odd .wf{background:var(--alt)}
|
|
39
|
+
.row.sel .lc,.row.sel .wf{background:var(--sel)}.row.hit .lc{background:var(--hit)}
|
|
40
|
+
.lc{position:sticky;left:0;z-index:2;flex:none;width:var(--lw);display:flex;align-items:center;gap:4px;
|
|
41
|
+
padding-right:6px;background:var(--bg);border-right:1px solid var(--line);overflow:hidden;white-space:nowrap}
|
|
42
|
+
.tg{flex:none;width:14px;text-align:center;color:var(--mut);cursor:pointer}
|
|
43
|
+
.lb{flex:1;overflow:hidden;text-overflow:ellipsis}.k-turn .lb{font-weight:600}
|
|
44
|
+
.cols{flex:none;color:var(--mut);font-size:12px;font-variant-numeric:tabular-nums}
|
|
45
|
+
.st{flex:none;font-size:11px;padding:0 4px;border-radius:3px;color:var(--bg);background:var(--mut)}
|
|
46
|
+
.st.error,.st.denied{background:var(--err)}.st.aborted,.st.interrupted,.st.retried{background:var(--warn)}.st.running{background:var(--run)}
|
|
47
|
+
.wf{position:relative;flex:none;height:22px}
|
|
48
|
+
.sg{position:absolute;top:6px;height:10px;min-width:2px;border-radius:2px}
|
|
49
|
+
.sg.turn{top:9px;height:4px;background:var(--turn)}.sg.ttft{background:var(--ttft)}.sg.dec{background:var(--dec)}
|
|
50
|
+
.sg.tool{background:var(--tool)}.sg.agent{background:var(--agent)}.sg.oth{background:var(--oth)}
|
|
51
|
+
.sg.wait{background:repeating-linear-gradient(45deg,var(--wait) 0 3px,transparent 3px 6px)}
|
|
52
|
+
.sg.run{width:2px;top:3px;height:16px;background:var(--run)}
|
|
53
|
+
#dt{height:32vh;overflow:auto;border-top:1px solid var(--line);padding:8px 12px}
|
|
54
|
+
#dt h2{font-size:14px;margin:0 0 6px}#dt h3{font-size:12px;margin:10px 0 4px;color:var(--mut)}
|
|
55
|
+
#dt table{border-collapse:collapse}#dt td{padding:1px 12px 1px 0;vertical-align:top}#dt td:first-child{color:var(--mut);white-space:nowrap}
|
|
56
|
+
pre{margin:0;padding:6px 8px;background:var(--alt);border:1px solid var(--line);border-radius:4px;white-space:pre-wrap;word-break:break-word;max-height:40vh;overflow:auto}
|
|
57
|
+
footer{padding:4px 12px;border-top:1px solid var(--line);font-size:11px;color:var(--mut)}
|
|
58
|
+
`;
|
|
59
|
+
const SCRIPT = `
|
|
60
|
+
(function(){"use strict";
|
|
61
|
+
var D=JSON.parse(document.getElementById("data").textContent),R=D.rows,I=D.i18n,N=R.length;
|
|
62
|
+
var RH=22,OV=50,LW=420,AX=D.axis,SPAN=D.span;
|
|
63
|
+
function lw(){LW=Math.max(200,Math.min(420,Math.floor($("sc").clientWidth*0.45)));document.documentElement.style.setProperty("--lw",LW+"px")}
|
|
64
|
+
var $=function(id){return document.getElementById(id)};
|
|
65
|
+
function el(tag,cls,text){var e=document.createElement(tag);if(cls)e.className=cls;if(text!=null)e.textContent=text;return e}
|
|
66
|
+
var kids=new Uint8Array(N),open=new Uint8Array(N),vis=[],sel=-1,hits=[],hit=-1,hitSet={},scale=1,W=0,fitted=1;
|
|
67
|
+
for(var i=0;i<N;i++){if(R[i].p>=0)kids[R[i].p]=1;if(R[i].e)open[i]=1}
|
|
68
|
+
function rebuild(){vis=[];var skip=1e9;for(var i=0;i<N;i++){var r=R[i];if(r.d>skip)continue;skip=1e9;vis.push(i);if(kids[i]&&!open[i])skip=r.d}
|
|
69
|
+
$("bd").style.height=(vis.length*RH)+"px";draw()}
|
|
70
|
+
function width(){return Math.max(SPAN*scale,$("sc").clientWidth-LW-2)}
|
|
71
|
+
function fit(){fitted=1;scale=Math.max(1e-6,($("sc").clientWidth-LW-24)/SPAN);rebuild()}
|
|
72
|
+
function inv(m){var p=AX[0]||[0,0];for(var k=0;k<AX.length;k++){var q=AX[k];if(m<=q[1]){return q[1]===p[1]?q[0]:p[0]+(m-p[1])*(q[0]-p[0])/(q[1]-p[1])}p=q}return p[0]+(m-p[1])}
|
|
73
|
+
function fmt(ms){ms=Math.max(0,Math.round(ms));if(ms<1000)return ms+"ms";var s=ms/1000;if(s<60)return(s<10?s.toFixed(1):Math.floor(s))+"s";s=Math.floor(s);return Math.floor(s/60)+"m"+String(s%60).padStart(2,"0")+"s"}
|
|
74
|
+
function ticks(){var t=$("tk"),sc=$("sc");t.style.width=W+"px";t.textContent="";
|
|
75
|
+
var a=Math.max(0,sc.scrollLeft-LW),b=a+sc.clientWidth,raw=90/scale,step=1;
|
|
76
|
+
while(step<raw){step*=(String(step).charAt(0)==="2"?2.5:2)}
|
|
77
|
+
for(var x=Math.floor(a/scale/step)*step;x*scale<=b;x+=step){if(x<0)continue;var e=el("div","tick",fmt(inv(x)));e.style.left=(x*scale)+"px";t.appendChild(e)}}
|
|
78
|
+
function row(idx,top){var i=vis[idx],r=R[i],e=el("div","row k-"+r.k+(idx%2?" odd":"")+(i===sel?" sel":"")+(hitSet[i]?" hit":""));
|
|
79
|
+
e.style.top=top+"px";e.dataset.i=i;var lc=el("div","lc");lc.style.paddingLeft=(4+Math.min(r.d,12)*14)+"px";
|
|
80
|
+
var tg=el("span","tg",kids[i]?(open[i]?"\\u25BE":"\\u25B8"):"");tg.dataset.t="1";lc.appendChild(tg);
|
|
81
|
+
if(r.s){lc.appendChild(el("span","st "+(r.sc||""),r.s))}
|
|
82
|
+
var lb=el("span","lb",r.l);lb.title=r.l;lc.appendChild(lb);
|
|
83
|
+
var cols=[r.du,r.tk,r.ca].filter(Boolean).join(" ");if(cols)lc.appendChild(el("span","cols",cols));
|
|
84
|
+
e.appendChild(lc);var wf=el("div","wf");wf.style.width=W+"px";
|
|
85
|
+
(r.g||[]).forEach(function(g){var s=el("div","sg "+g[2]);s.style.left=(g[0]*scale)+"px";if(g[2]!=="run")s.style.width=Math.max(2,(g[1]-g[0])*scale)+"px";wf.appendChild(s)});
|
|
86
|
+
e.appendChild(wf);e.style.width=(LW+W)+"px";return e}
|
|
87
|
+
var pend=0;function draw(){if(pend)return;pend=1;requestAnimationFrame(function(){pend=0;paint()})}
|
|
88
|
+
function paint(){var sc=$("sc"),bd=$("bd"),h=sc.clientHeight,first=Math.max(0,Math.floor(sc.scrollTop/RH)-OV),last=Math.min(vis.length,Math.ceil((sc.scrollTop+h)/RH)+OV);
|
|
89
|
+
W=width();bd.textContent="";if(N===0){bd.appendChild(el("div","mut",I.empty));return}
|
|
90
|
+
for(var k=first;k<last;k++)bd.appendChild(row(k,k*RH));ticks()}
|
|
91
|
+
function select(i,scroll){sel=i;var at=vis.indexOf(i);if(scroll&&at>=0){var sc=$("sc"),top=at*RH;if(top<sc.scrollTop+20||top>sc.scrollTop+sc.clientHeight-RH*2)sc.scrollTop=Math.max(0,top-sc.clientHeight/3)}detail(i);draw()}
|
|
92
|
+
function reveal(i){for(var p=R[i].p;p>=0;p=R[p].p)open[p]=1;rebuild();select(i,true)}
|
|
93
|
+
function toggle(i,v){if(!kids[i])return;open[i]=v==null?(open[i]?0:1):v;rebuild()}
|
|
94
|
+
function detail(i){var d=$("dt");d.textContent="";if(i<0){d.appendChild(el("div","mut",I.detailEmpty));return}var r=R[i];
|
|
95
|
+
d.appendChild(el("h2",null,r.l));if(r.kv.length){var t=el("table");r.kv.forEach(function(kv){var tr=el("tr");tr.appendChild(el("td",null,kv[0]));tr.appendChild(el("td",null,kv[1]));t.appendChild(tr)});d.appendChild(t)}
|
|
96
|
+
(r.pv||[]).forEach(function(p){d.appendChild(el("h3",null,p[0]));d.appendChild(el("pre",null,p[1]))});
|
|
97
|
+
var note=!D.content?I.noContent:r.pd?I.previewDropped:r.pc?I.childPreviewOff:"";if(note)d.appendChild(el("p","mut",note))}
|
|
98
|
+
function search(q){q=q.trim().toLowerCase();hits=[];hitSet={};hit=-1;if(q){for(var i=0;i<N;i++){var r=R[i],s=r.l+" "+(r.pv||[]).map(function(p){return p[1]}).join(" ");if(s.toLowerCase().indexOf(q)>=0){hits.push(i);hitSet[i]=1}}}
|
|
99
|
+
$("cnt").textContent=q?(hits.length?"0/"+hits.length:I.noMatch):"";draw()}
|
|
100
|
+
function next(dir){if(!hits.length)return;hit=(hit+dir+hits.length)%hits.length;$("cnt").textContent=(hit+1)+"/"+hits.length;reveal(hits[hit])}
|
|
101
|
+
function init(){document.title=D.title;$("h").textContent=D.title;$("sum").textContent=D.summary;$("meta").textContent=D.meta;$("ft").textContent=D.footer;
|
|
102
|
+
var q=$("q");q.placeholder=I.search;q.addEventListener("input",function(){search(q.value)});
|
|
103
|
+
q.addEventListener("keydown",function(e){if(e.key==="Enter"){next(e.shiftKey?-1:1);e.preventDefault()}else if(e.key==="Escape")q.blur()});
|
|
104
|
+
var j=$("jump");j.appendChild(el("option",null,I.jump)).value="";
|
|
105
|
+
R.forEach(function(r,i){if(r.t){var o=el("option",null,r.l.length>60?r.l.slice(0,59)+"\\u2026":r.l);o.value=String(i);j.appendChild(o)}});
|
|
106
|
+
j.addEventListener("change",function(){if(j.value!==""){var i=+j.value;open[i]=1;reveal(i);j.value=""}});
|
|
107
|
+
[["zo",I.zoomOut,function(){zoom(0.5)}],["zi",I.zoomIn,function(){zoom(2)}],["zf",I.zoomFit,fit],
|
|
108
|
+
["ea",I.expandAll,function(){open.fill(1);rebuild()}],["ca",I.collapseAll,function(){open.fill(0);rebuild()}]].forEach(function(b){var e=$(b[0]);e.textContent=b[1];e.addEventListener("click",b[2])});
|
|
109
|
+
["ttft","dec","tool","agent","wait","oth"].forEach(function(c){var s=el("span","lg");s.appendChild(el("span","sw sg "+c)).style.position="static";s.appendChild(document.createTextNode(I[c]));$("lg").appendChild(s)});
|
|
110
|
+
$("note").textContent=I.axisNote+" \\u00B7 "+I.keys;
|
|
111
|
+
var sc=$("sc");sc.addEventListener("scroll",draw);window.addEventListener("resize",function(){lw();if(fitted)fit();else draw()});
|
|
112
|
+
sc.addEventListener("wheel",function(e){if(!e.ctrlKey&&!e.metaKey)return;e.preventDefault();var x=e.clientX-sc.getBoundingClientRect().left-LW;zoom(e.deltaY<0?1.25:0.8,x)},{passive:false});
|
|
113
|
+
$("bd").addEventListener("click",function(e){var r=e.target.closest(".row");if(!r)return;var i=+r.dataset.i;if(e.target.dataset.t)toggle(i);select(i,false)});
|
|
114
|
+
$("bd").addEventListener("dblclick",function(e){var r=e.target.closest(".row");if(r)toggle(+r.dataset.i)});
|
|
115
|
+
document.addEventListener("keydown",function(e){if(e.target===q||e.target===j||!vis.length)return;var at=vis.indexOf(sel);
|
|
116
|
+
if(e.key==="/"){q.focus();e.preventDefault()}else if(e.key==="ArrowDown"){select(vis[Math.min(vis.length-1,at+1)],true);e.preventDefault()}
|
|
117
|
+
else if(e.key==="ArrowUp"){select(vis[Math.max(0,at-1)],true);e.preventDefault()}
|
|
118
|
+
else if(e.key==="ArrowRight"&&sel>=0){toggle(sel,1);e.preventDefault()}
|
|
119
|
+
else if(e.key==="ArrowLeft"&&sel>=0){if(kids[sel]&&open[sel])toggle(sel,0);else if(R[sel].p>=0)select(R[sel].p,true);e.preventDefault()}});
|
|
120
|
+
detail(-1);lw();fit()}
|
|
121
|
+
function zoom(f,x){fitted=0;var sc=$("sc");if(x==null)x=(sc.clientWidth-LW)/2;var t=(sc.scrollLeft+x)/scale;scale=Math.min(1e3,Math.max(1e-7,scale*f));rebuild();sc.scrollLeft=Math.max(0,t*scale-x)}
|
|
122
|
+
init()})();
|
|
123
|
+
`;
|
|
124
|
+
/** 页面骨架。`json` 必须已经过 `scriptSafeJson`。 */
|
|
125
|
+
export function renderPage(parts) {
|
|
126
|
+
return `<!doctype html>
|
|
127
|
+
<html lang="${escapeHtml(parts.lang)}">
|
|
128
|
+
<head>
|
|
129
|
+
<meta charset="utf-8">
|
|
130
|
+
<meta http-equiv="Content-Security-Policy" content="${CSP}">
|
|
131
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
132
|
+
<meta name="referrer" content="no-referrer">
|
|
133
|
+
<title>${escapeHtml(parts.title)}</title>
|
|
134
|
+
<style>${STYLE}</style>
|
|
135
|
+
</head>
|
|
136
|
+
<body>
|
|
137
|
+
<header><h1 id="h"></h1><div class="sum" id="sum"></div><div class="mut" id="meta"></div>
|
|
138
|
+
<div class="bar"><input id="q" type="search" autocomplete="off"><span class="mut" id="cnt"></span>
|
|
139
|
+
<select id="jump"></select><button id="zo"></button><button id="zi"></button><button id="zf"></button>
|
|
140
|
+
<button id="ea"></button><button id="ca"></button><span id="lg"></span></div>
|
|
141
|
+
<div class="mut" id="note"></div></header>
|
|
142
|
+
<div id="sc"><div id="ru"><div class="lc"></div><div id="tk"></div></div><div id="bd"></div></div>
|
|
143
|
+
<section id="dt"></section>
|
|
144
|
+
<footer id="ft"></footer>
|
|
145
|
+
<script type="application/json" id="data">${parts.json}</script>
|
|
146
|
+
<script>${SCRIPT}</script>
|
|
147
|
+
</body>
|
|
148
|
+
</html>
|
|
149
|
+
`;
|
|
150
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 轨迹 HTML 导出:`ama sessions trace --html`(docs/wave6-plan.md §2.5、D7)。[W6-T2]
|
|
3
|
+
*
|
|
4
|
+
* 产物是**单文件、零依赖**的页面:样式与脚本内联(`html-template.ts`),数据放
|
|
5
|
+
* `<script type="application/json">`,`<meta>` CSP 禁止一切外联。页面在浏览器里只用 `textContent` 写字,
|
|
6
|
+
* 不拼 HTML。
|
|
7
|
+
*
|
|
8
|
+
* 这里把 `Trace` 摊成「行」(全部展开的扁平树:深度、父行、标签、耗时 / token / 缓存列、瀑布分段、详情键值、
|
|
9
|
+
* 预览),页面只做折叠、虚拟滚动、搜索、缩放与详情。
|
|
10
|
+
*
|
|
11
|
+
* - **双重脱敏**:整棵轨迹先 `redactValue`;正文经「先 redactValue 再读」的条目查找表取(标签里的提示预览、
|
|
12
|
+
* 工具参数摘要、详情预览都来自脱敏后的条目),预览自身再 `redactSecrets`(`preview.ts`);序列化时
|
|
13
|
+
* `<`、`>`、`&`、U+2028 / U+2029 全部转成 `\uXXXX`,数据里不可能出现 `</script>` 或 `<!--`。
|
|
14
|
+
* - `content: false`(`--no-content`):不读条目,标签只剩结构,详情去掉错误 / 原因两行,没有预览。
|
|
15
|
+
* - `children: false`:子会话的结构照样嵌(行与数字),预览只给本会话的节点。
|
|
16
|
+
* - 预览总预算(缺省 4 MB 字符):从最后一行往前计,超出后更早的预览置空并标注。
|
|
17
|
+
* - 横轴:会话时间,回合之间超过 2 秒的空闲压缩成 2 秒(页面标注);`axis` 给出原始 → 轴上的折点,
|
|
18
|
+
* 刻度按原始时间标注。
|
|
19
|
+
* - 确定性:不读时钟;生成时间与版本由调用方传入,写进页脚。
|
|
20
|
+
*/
|
|
21
|
+
import { type TraceEntryLookup } from "./detail.js";
|
|
22
|
+
import type { Trace } from "./types.js";
|
|
23
|
+
/** 预览总预算(字符)。 */
|
|
24
|
+
export declare const PREVIEW_BUDGET: number;
|
|
25
|
+
/** 回合之间的空闲在轴上最多占这么长(ms)。 */
|
|
26
|
+
export declare const IDLE_CAP_MS = 2000;
|
|
27
|
+
export interface TraceHtmlOptions {
|
|
28
|
+
/** 是否带正文(标签里的提示 / 参数摘要、详情预览)。 */
|
|
29
|
+
content: boolean;
|
|
30
|
+
/** 是否内嵌子会话节点的预览。 */
|
|
31
|
+
children: boolean;
|
|
32
|
+
/** 生成时间(epoch ms),写页脚。 */
|
|
33
|
+
generatedAt: number;
|
|
34
|
+
/** 正文来源(含已加载子会话的条目);`content` 为 false 时不用。 */
|
|
35
|
+
lookup?: TraceEntryLookup;
|
|
36
|
+
/** 写页脚的 ama 版本。 */
|
|
37
|
+
version: string;
|
|
38
|
+
/** 测试用:覆盖预览总预算。 */
|
|
39
|
+
previewBudget?: number;
|
|
40
|
+
}
|
|
41
|
+
/** 瀑布分段:`[轴上起点, 轴上终点, 类别]`;起点 = 终点表示进行中的起点标记。 */
|
|
42
|
+
type Seg = [number, number, SegClass];
|
|
43
|
+
type SegClass = "turn" | "ttft" | "dec" | "tool" | "agent" | "wait" | "oth" | "run";
|
|
44
|
+
/** 页面里的一行。键名短,数据量大时省体积。 */
|
|
45
|
+
export interface HtmlRow {
|
|
46
|
+
/** 深度。 */
|
|
47
|
+
d: number;
|
|
48
|
+
/** 父行下标(-1 = 顶层)。 */
|
|
49
|
+
p: number;
|
|
50
|
+
/** 节点种类。 */
|
|
51
|
+
k: string;
|
|
52
|
+
/** 状态(i18n 后);完成时省略。 */
|
|
53
|
+
s?: string;
|
|
54
|
+
/** 状态码(样式用)。 */
|
|
55
|
+
sc?: string;
|
|
56
|
+
l: string;
|
|
57
|
+
/** 耗时 / token / 缓存列。 */
|
|
58
|
+
du?: string;
|
|
59
|
+
tk?: string;
|
|
60
|
+
ca?: string;
|
|
61
|
+
/** 缺省展开。 */
|
|
62
|
+
e?: 1;
|
|
63
|
+
/** 回合序号(顶层回合行,跳转用)。 */
|
|
64
|
+
t?: number;
|
|
65
|
+
g?: Seg[];
|
|
66
|
+
/** 详情键值。 */
|
|
67
|
+
kv: [string, string][];
|
|
68
|
+
/** 预览(标题 → 正文)。 */
|
|
69
|
+
pv?: [string, string][];
|
|
70
|
+
/** 预览因预算被省略。 */
|
|
71
|
+
pd?: 1;
|
|
72
|
+
/** 在子会话里且没有 `--children`(预览未内嵌)。 */
|
|
73
|
+
pc?: 1;
|
|
74
|
+
}
|
|
75
|
+
export interface HtmlData {
|
|
76
|
+
lang: string;
|
|
77
|
+
title: string;
|
|
78
|
+
summary: string;
|
|
79
|
+
meta: string;
|
|
80
|
+
footer: string;
|
|
81
|
+
/** 原始时间 → 轴上时间的折点(相对会话开始,ms)。 */
|
|
82
|
+
axis: [number, number][];
|
|
83
|
+
/** 轴总长(ms)。 */
|
|
84
|
+
span: number;
|
|
85
|
+
content: boolean;
|
|
86
|
+
rows: HtmlRow[];
|
|
87
|
+
i18n: Record<string, string>;
|
|
88
|
+
}
|
|
89
|
+
/** 正文查找表:条目先整条 `redactValue` 再给 describe / preview 用。 */
|
|
90
|
+
export declare function redactedLookup(lookup: TraceEntryLookup): TraceEntryLookup;
|
|
91
|
+
/** 原始时间 → 轴:合并回合时间窗,窗口之间的空闲压到 `IDLE_CAP_MS`。 */
|
|
92
|
+
export declare function axisPoints(trace: Trace): [number, number][];
|
|
93
|
+
/** 按折点映射(折点之外按 1:1 外推)。 */
|
|
94
|
+
export declare function mapTime(points: readonly [number, number][], raw: number): number;
|
|
95
|
+
/** 轨迹 → 页面数据(已脱敏;纯函数)。 */
|
|
96
|
+
export declare function traceHtmlData(source: Trace, opts: TraceHtmlOptions): HtmlData;
|
|
97
|
+
/**
|
|
98
|
+
* 嵌进 `<script type="application/json">` 的 JSON:`<`、`>`、`&` 与 U+2028 / U+2029 转成 `\uXXXX`。
|
|
99
|
+
* 结果仍是合法 JSON(`JSON.parse` 还原原值),且不含 `</script>`、`<!--` 等能截断或改变脚本块的序列。
|
|
100
|
+
*/
|
|
101
|
+
export declare function scriptSafeJson(value: unknown): string;
|
|
102
|
+
/** 渲染整页 HTML。 */
|
|
103
|
+
export declare function renderTraceHtml(trace: Trace, opts: TraceHtmlOptions): string;
|
|
104
|
+
export {};
|
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 轨迹 HTML 导出:`ama sessions trace --html`(docs/wave6-plan.md §2.5、D7)。[W6-T2]
|
|
3
|
+
*
|
|
4
|
+
* 产物是**单文件、零依赖**的页面:样式与脚本内联(`html-template.ts`),数据放
|
|
5
|
+
* `<script type="application/json">`,`<meta>` CSP 禁止一切外联。页面在浏览器里只用 `textContent` 写字,
|
|
6
|
+
* 不拼 HTML。
|
|
7
|
+
*
|
|
8
|
+
* 这里把 `Trace` 摊成「行」(全部展开的扁平树:深度、父行、标签、耗时 / token / 缓存列、瀑布分段、详情键值、
|
|
9
|
+
* 预览),页面只做折叠、虚拟滚动、搜索、缩放与详情。
|
|
10
|
+
*
|
|
11
|
+
* - **双重脱敏**:整棵轨迹先 `redactValue`;正文经「先 redactValue 再读」的条目查找表取(标签里的提示预览、
|
|
12
|
+
* 工具参数摘要、详情预览都来自脱敏后的条目),预览自身再 `redactSecrets`(`preview.ts`);序列化时
|
|
13
|
+
* `<`、`>`、`&`、U+2028 / U+2029 全部转成 `\uXXXX`,数据里不可能出现 `</script>` 或 `<!--`。
|
|
14
|
+
* - `content: false`(`--no-content`):不读条目,标签只剩结构,详情去掉错误 / 原因两行,没有预览。
|
|
15
|
+
* - `children: false`:子会话的结构照样嵌(行与数字),预览只给本会话的节点。
|
|
16
|
+
* - 预览总预算(缺省 4 MB 字符):从最后一行往前计,超出后更早的预览置空并标注。
|
|
17
|
+
* - 横轴:会话时间,回合之间超过 2 秒的空闲压缩成 2 秒(页面标注);`axis` 给出原始 → 轴上的折点,
|
|
18
|
+
* 刻度按原始时间标注。
|
|
19
|
+
* - 确定性:不读时钟;生成时间与版本由调用方传入,写进页脚。
|
|
20
|
+
*/
|
|
21
|
+
import { getLocale, msg } from "../i18n/index.js";
|
|
22
|
+
import { formatUsd } from "../modes/session-report.js";
|
|
23
|
+
import { redactSecrets, redactValue } from "../session/redact.js";
|
|
24
|
+
import { plainTheme } from "../tui/theme.js";
|
|
25
|
+
import { describeNode, summaryRows } from "./detail.js";
|
|
26
|
+
import { defaultExpanded, flattenTrace, turnSpan } from "./flatten.js";
|
|
27
|
+
import { cacheText, durationText, rowLabel, summaryText, tokensText } from "./format.js";
|
|
28
|
+
import { renderPage } from "./html-template.js";
|
|
29
|
+
import { previewOf, previewSize } from "./preview.js";
|
|
30
|
+
/** 预览总预算(字符)。 */
|
|
31
|
+
export const PREVIEW_BUDGET = 4 * 1024 * 1024;
|
|
32
|
+
/** 回合之间的空闲在轴上最多占这么长(ms)。 */
|
|
33
|
+
export const IDLE_CAP_MS = 2000;
|
|
34
|
+
/** 全部展开(任何 key 都展开)。 */
|
|
35
|
+
const EXPAND_ALL = {
|
|
36
|
+
get: () => true,
|
|
37
|
+
};
|
|
38
|
+
/** 正文查找表:条目先整条 `redactValue` 再给 describe / preview 用。 */
|
|
39
|
+
export function redactedLookup(lookup) {
|
|
40
|
+
const cache = new Map();
|
|
41
|
+
return {
|
|
42
|
+
...(lookup.cwd !== undefined ? { cwd: lookup.cwd } : {}),
|
|
43
|
+
entry(id) {
|
|
44
|
+
if (!cache.has(id)) {
|
|
45
|
+
const raw = lookup.entry(id);
|
|
46
|
+
cache.set(id, raw === undefined ? undefined : redactValue(raw));
|
|
47
|
+
}
|
|
48
|
+
return cache.get(id);
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/** 原始时间 → 轴:合并回合时间窗,窗口之间的空闲压到 `IDLE_CAP_MS`。 */
|
|
53
|
+
export function axisPoints(trace) {
|
|
54
|
+
const t0 = trace.startedAt;
|
|
55
|
+
const windows = [];
|
|
56
|
+
for (const turn of trace.turns) {
|
|
57
|
+
const span = turnSpan(turn);
|
|
58
|
+
if (span !== undefined)
|
|
59
|
+
windows.push([span.start - t0, span.end - t0]);
|
|
60
|
+
}
|
|
61
|
+
for (const aux of trace.aux)
|
|
62
|
+
if (aux.startedAt !== undefined)
|
|
63
|
+
windows.push([aux.startedAt - t0, (aux.endedAt ?? aux.startedAt) - t0]);
|
|
64
|
+
windows.sort((a, b) => a[0] - b[0] || a[1] - b[1]);
|
|
65
|
+
const points = [[0, 0]];
|
|
66
|
+
let raw = 0;
|
|
67
|
+
let mapped = 0;
|
|
68
|
+
for (const [start, end] of windows) {
|
|
69
|
+
if (end <= raw)
|
|
70
|
+
continue;
|
|
71
|
+
const from = Math.max(start, raw);
|
|
72
|
+
if (from > raw) {
|
|
73
|
+
mapped += Math.min(from - raw, IDLE_CAP_MS);
|
|
74
|
+
raw = from;
|
|
75
|
+
points.push([raw, mapped]);
|
|
76
|
+
}
|
|
77
|
+
mapped += end - raw;
|
|
78
|
+
raw = end;
|
|
79
|
+
points.push([raw, mapped]);
|
|
80
|
+
}
|
|
81
|
+
return points;
|
|
82
|
+
}
|
|
83
|
+
/** 按折点映射(折点之外按 1:1 外推)。 */
|
|
84
|
+
export function mapTime(points, raw) {
|
|
85
|
+
let prev = points[0] ?? [0, 0];
|
|
86
|
+
for (const point of points) {
|
|
87
|
+
if (raw <= point[0]) {
|
|
88
|
+
const [r0, m0] = prev;
|
|
89
|
+
const [r1, m1] = point;
|
|
90
|
+
return r1 === r0 ? m1 : m0 + ((raw - r0) * (m1 - m0)) / (r1 - r0);
|
|
91
|
+
}
|
|
92
|
+
prev = point;
|
|
93
|
+
}
|
|
94
|
+
return prev[1] + (raw - prev[0]);
|
|
95
|
+
}
|
|
96
|
+
function segments(row, at) {
|
|
97
|
+
const node = row.node;
|
|
98
|
+
if (node.kind === "more" || node.kind === "aux_group")
|
|
99
|
+
return [];
|
|
100
|
+
const out = [];
|
|
101
|
+
const running = node.status === "running" && node.endedAt === undefined;
|
|
102
|
+
const bar = (from, to, cls) => {
|
|
103
|
+
if (from === undefined)
|
|
104
|
+
return;
|
|
105
|
+
if (to === undefined) {
|
|
106
|
+
if (running)
|
|
107
|
+
out.push([at(from), at(from), "run"]);
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
out.push([at(from), at(Math.max(from, to)), cls]);
|
|
111
|
+
};
|
|
112
|
+
switch (node.kind) {
|
|
113
|
+
case "turn":
|
|
114
|
+
if (node.startedAt !== undefined) {
|
|
115
|
+
const span = turnSpan(node);
|
|
116
|
+
bar(node.startedAt, running ? undefined : span?.end, "turn");
|
|
117
|
+
}
|
|
118
|
+
break;
|
|
119
|
+
case "step": {
|
|
120
|
+
const start = node.requestAt ?? node.startedAt;
|
|
121
|
+
if (node.firstTokenAt !== undefined) {
|
|
122
|
+
bar(start, node.firstTokenAt, "ttft");
|
|
123
|
+
bar(node.firstTokenAt, node.doneAt, "dec");
|
|
124
|
+
}
|
|
125
|
+
else
|
|
126
|
+
bar(start, node.doneAt ?? node.endedAt, "dec");
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
case "retry_wait":
|
|
130
|
+
bar(node.startedAt, node.startedAt === undefined ? undefined : node.startedAt + node.delayMs, "wait");
|
|
131
|
+
break;
|
|
132
|
+
case "compaction":
|
|
133
|
+
case "aux":
|
|
134
|
+
bar(node.startedAt, node.endedAt, "oth");
|
|
135
|
+
break;
|
|
136
|
+
case "subagent":
|
|
137
|
+
bar(node.startedAt, node.endedAt, "agent");
|
|
138
|
+
break;
|
|
139
|
+
default:
|
|
140
|
+
bar(node.startedAt, node.endedAt, "tool");
|
|
141
|
+
}
|
|
142
|
+
return out;
|
|
143
|
+
}
|
|
144
|
+
const PREVIEW_ORDER = ["input", "output", "args", "result"];
|
|
145
|
+
function previewPairs(p) {
|
|
146
|
+
const d = msg().trace.detail;
|
|
147
|
+
return PREVIEW_ORDER.flatMap((key) => {
|
|
148
|
+
const text = p[key];
|
|
149
|
+
return text === undefined ? [] : [[d[key], text]];
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
/** 轨迹 → 页面数据(已脱敏;纯函数)。 */
|
|
153
|
+
export function traceHtmlData(source, opts) {
|
|
154
|
+
const m = msg().trace;
|
|
155
|
+
const theme = plainTheme();
|
|
156
|
+
const trace = redactValue(source);
|
|
157
|
+
const lookup = opts.content && opts.lookup !== undefined ? redactedLookup(opts.lookup) : undefined;
|
|
158
|
+
const describe = lookup === undefined
|
|
159
|
+
? undefined
|
|
160
|
+
: (node) => describeNode(node, lookup);
|
|
161
|
+
const t0 = trace.startedAt;
|
|
162
|
+
const axis = axisPoints(trace);
|
|
163
|
+
const at = (t) => Math.round(mapTime(axis, t - t0));
|
|
164
|
+
const dropKeys = new Set([m.detail.error, m.detail.reason]);
|
|
165
|
+
const flat = flattenTrace(trace, { expanded: EXPAND_ALL });
|
|
166
|
+
const rows = [];
|
|
167
|
+
const parents = [];
|
|
168
|
+
/** 各深度上的行是否在子 Agent 的子树里(不含子 Agent 行本身)。 */
|
|
169
|
+
const under = [];
|
|
170
|
+
let span = axis.at(-1)?.[1] ?? 0;
|
|
171
|
+
flat.forEach((row, i) => {
|
|
172
|
+
parents.length = row.depth;
|
|
173
|
+
const node = row.node;
|
|
174
|
+
const out = {
|
|
175
|
+
d: row.depth,
|
|
176
|
+
p: row.depth === 0 ? -1 : (parents[row.depth - 1] ?? -1),
|
|
177
|
+
k: node.kind,
|
|
178
|
+
l: redactSecrets(rowLabel(row, describe === undefined ? {} : { describe })),
|
|
179
|
+
kv: [],
|
|
180
|
+
};
|
|
181
|
+
const parent = out.p < 0 ? undefined : rows[out.p];
|
|
182
|
+
const inChild = row.depth > 0 && ((under[row.depth - 1] ?? false) || parent?.k === "subagent");
|
|
183
|
+
under[row.depth] = inChild;
|
|
184
|
+
parents[row.depth] = i;
|
|
185
|
+
if (node.kind !== "more" && node.kind !== "aux_group") {
|
|
186
|
+
if (node.status !== "ok") {
|
|
187
|
+
out.s = m.status[node.status];
|
|
188
|
+
out.sc = node.status;
|
|
189
|
+
}
|
|
190
|
+
const du = durationText(node, theme);
|
|
191
|
+
if (du !== "")
|
|
192
|
+
out.du = du;
|
|
193
|
+
const tk = tokensText(node, theme);
|
|
194
|
+
if (tk !== "")
|
|
195
|
+
out.tk = tk;
|
|
196
|
+
const ca = cacheText(node);
|
|
197
|
+
if (ca !== "")
|
|
198
|
+
out.ca = ca;
|
|
199
|
+
out.kv = summaryRows(node, theme, t0)
|
|
200
|
+
.filter(([label]) => opts.content || !dropKeys.has(label))
|
|
201
|
+
.map(([label, value]) => [label, redactSecrets(value)]);
|
|
202
|
+
const g = segments(row, at);
|
|
203
|
+
if (g.length > 0) {
|
|
204
|
+
out.g = g;
|
|
205
|
+
for (const seg of g)
|
|
206
|
+
span = Math.max(span, seg[1]);
|
|
207
|
+
}
|
|
208
|
+
if (lookup !== undefined) {
|
|
209
|
+
if (inChild && !opts.children)
|
|
210
|
+
out.pc = 1;
|
|
211
|
+
else {
|
|
212
|
+
const p = previewOf(node, lookup);
|
|
213
|
+
if (p !== undefined && previewSize(p) > 0)
|
|
214
|
+
out.pv = previewPairs(p);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
if (row.expandable && defaultExpanded(node))
|
|
219
|
+
out.e = 1;
|
|
220
|
+
if (node.kind === "turn" && row.depth === 0)
|
|
221
|
+
out.t = row.turn;
|
|
222
|
+
rows.push(out);
|
|
223
|
+
});
|
|
224
|
+
// 预览总预算:从后往前
|
|
225
|
+
let budget = opts.previewBudget ?? PREVIEW_BUDGET;
|
|
226
|
+
for (let i = rows.length - 1; i >= 0; i--) {
|
|
227
|
+
const row = rows[i];
|
|
228
|
+
if (row.pv === undefined)
|
|
229
|
+
continue;
|
|
230
|
+
const size = row.pv.reduce((n, [, text]) => n + text.length, 0);
|
|
231
|
+
if (size <= budget)
|
|
232
|
+
budget -= size;
|
|
233
|
+
else {
|
|
234
|
+
budget = 0;
|
|
235
|
+
delete row.pv;
|
|
236
|
+
row.pd = 1;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
const h = m.html;
|
|
240
|
+
const generated = new Date(opts.generatedAt).toISOString();
|
|
241
|
+
const cost = trace.totals.cost !== undefined ? ` · ${formatUsd(trace.totals.cost)}` : "";
|
|
242
|
+
const started = new Date(t0).toISOString();
|
|
243
|
+
return {
|
|
244
|
+
lang: getLocale() === "zh" ? "zh-CN" : "en",
|
|
245
|
+
title: h.docTitle(trace.sessionId),
|
|
246
|
+
summary: `${summaryText(trace, theme)}${cost}`,
|
|
247
|
+
meta: `${trace.cwd} · ${started}${trace.partial ? ` · ${m.status.running}` : ""}`,
|
|
248
|
+
footer: h.footer(opts.version, generated),
|
|
249
|
+
axis,
|
|
250
|
+
span: Math.max(1, span),
|
|
251
|
+
content: opts.content,
|
|
252
|
+
rows,
|
|
253
|
+
i18n: {
|
|
254
|
+
search: h.search,
|
|
255
|
+
noMatch: h.noMatch,
|
|
256
|
+
jump: h.jump,
|
|
257
|
+
zoomIn: h.zoomIn,
|
|
258
|
+
zoomOut: h.zoomOut,
|
|
259
|
+
zoomFit: h.zoomFit,
|
|
260
|
+
expandAll: h.expandAll,
|
|
261
|
+
collapseAll: h.collapseAll,
|
|
262
|
+
ttft: h.legendTtft,
|
|
263
|
+
dec: h.legendDecode,
|
|
264
|
+
tool: h.legendTool,
|
|
265
|
+
agent: h.legendAgent,
|
|
266
|
+
wait: h.legendWait,
|
|
267
|
+
oth: h.legendOther,
|
|
268
|
+
axisNote: h.axisNote,
|
|
269
|
+
detailEmpty: h.detailEmpty,
|
|
270
|
+
noContent: h.noContent,
|
|
271
|
+
previewDropped: h.previewDropped,
|
|
272
|
+
childPreviewOff: h.childPreviewOff,
|
|
273
|
+
keys: h.keys,
|
|
274
|
+
empty: m.empty,
|
|
275
|
+
},
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* 嵌进 `<script type="application/json">` 的 JSON:`<`、`>`、`&` 与 U+2028 / U+2029 转成 `\uXXXX`。
|
|
280
|
+
* 结果仍是合法 JSON(`JSON.parse` 还原原值),且不含 `</script>`、`<!--` 等能截断或改变脚本块的序列。
|
|
281
|
+
*/
|
|
282
|
+
export function scriptSafeJson(value) {
|
|
283
|
+
return JSON.stringify(value).replace(/[<>&\u2028\u2029]/g, (c) => {
|
|
284
|
+
const code = c.charCodeAt(0).toString(16).padStart(4, "0");
|
|
285
|
+
return `\\u${code}`;
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
/** 渲染整页 HTML。 */
|
|
289
|
+
export function renderTraceHtml(trace, opts) {
|
|
290
|
+
const data = traceHtmlData(trace, opts);
|
|
291
|
+
return renderPage({ lang: data.lang, title: data.title, json: scriptSafeJson(data) });
|
|
292
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 轨迹节点的正文预览(脱敏版):HTML 导出与 RPC `get_trace{content:"preview"}` 共用。[W6-T2]
|
|
3
|
+
*
|
|
4
|
+
* 与 `detail.ts` 的 `nodePreviews`(只给本机 TUI 用、未脱敏)同一截断口径:参数 JSON 500 字符、提示 / 输出 /
|
|
5
|
+
* 结果 2000 字符。顺序很重要:**先脱敏整段原文,再截断**——反过来截断会把密钥截成不再匹配形态的残片。
|
|
6
|
+
* 参数先 `redactValue`(键名像机密的值整段遮掉)再序列化,序列化后再过一遍 `redactSecrets`。
|
|
7
|
+
*/
|
|
8
|
+
import { type TraceEntryLookup } from "./detail.js";
|
|
9
|
+
import type { TraceNode } from "./flatten.js";
|
|
10
|
+
/** 一个节点的预览;每段都已脱敏与截断(被截断的以 `…` 结尾)。 */
|
|
11
|
+
export interface TracePreview {
|
|
12
|
+
/** 回合:用户提示。 */
|
|
13
|
+
input?: string;
|
|
14
|
+
/** 请求:助手文字。 */
|
|
15
|
+
output?: string;
|
|
16
|
+
/** 工具:参数 JSON。 */
|
|
17
|
+
args?: string;
|
|
18
|
+
/** 工具:结果文本。 */
|
|
19
|
+
result?: string;
|
|
20
|
+
}
|
|
21
|
+
/** 节点 → 预览;没有正文返回 undefined。 */
|
|
22
|
+
export declare function previewOf(node: TraceNode, lookup: TraceEntryLookup): TracePreview | undefined;
|
|
23
|
+
/** 预览的字符数(总预算用)。 */
|
|
24
|
+
export declare function previewSize(p: TracePreview): number;
|
|
25
|
+
/** 预览表的 key:`<kind>:<id>`(同一轨迹内唯一;子轨迹的节点 id 来自子会话条目)。 */
|
|
26
|
+
export declare function previewKey(node: {
|
|
27
|
+
kind: string;
|
|
28
|
+
id: string;
|
|
29
|
+
}): string;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 轨迹节点的正文预览(脱敏版):HTML 导出与 RPC `get_trace{content:"preview"}` 共用。[W6-T2]
|
|
3
|
+
*
|
|
4
|
+
* 与 `detail.ts` 的 `nodePreviews`(只给本机 TUI 用、未脱敏)同一截断口径:参数 JSON 500 字符、提示 / 输出 /
|
|
5
|
+
* 结果 2000 字符。顺序很重要:**先脱敏整段原文,再截断**——反过来截断会把密钥截成不再匹配形态的残片。
|
|
6
|
+
* 参数先 `redactValue`(键名像机密的值整段遮掉)再序列化,序列化后再过一遍 `redactSecrets`。
|
|
7
|
+
*/
|
|
8
|
+
import { contentText } from "../session/reuse.js";
|
|
9
|
+
import { redactSecrets, redactValue } from "../session/redact.js";
|
|
10
|
+
import { ARGS_PREVIEW_MAX, RESULT_PREVIEW_MAX } from "./detail.js";
|
|
11
|
+
function clip(text, max) {
|
|
12
|
+
const clean = redactSecrets(text);
|
|
13
|
+
return clean.length > max ? `${clean.slice(0, max)}…` : clean;
|
|
14
|
+
}
|
|
15
|
+
function messageOf(lookup, id) {
|
|
16
|
+
const entry = id === undefined ? undefined : lookup.entry(id);
|
|
17
|
+
return entry?.type === "message" ? entry.message : undefined;
|
|
18
|
+
}
|
|
19
|
+
/** 节点 → 预览;没有正文返回 undefined。 */
|
|
20
|
+
export function previewOf(node, lookup) {
|
|
21
|
+
const out = {};
|
|
22
|
+
if (node.kind === "turn") {
|
|
23
|
+
const m = messageOf(lookup, node.id);
|
|
24
|
+
if (m?.role === "user")
|
|
25
|
+
out.input = clip(contentText(m.content), RESULT_PREVIEW_MAX);
|
|
26
|
+
}
|
|
27
|
+
else if (node.kind === "step") {
|
|
28
|
+
const m = messageOf(lookup, node.id);
|
|
29
|
+
if (m?.role === "assistant") {
|
|
30
|
+
const text = m.content
|
|
31
|
+
.flatMap((b) => (b.type === "text" && b.text.trim() !== "" ? [b.text] : []))
|
|
32
|
+
.join("\n");
|
|
33
|
+
if (text !== "")
|
|
34
|
+
out.output = clip(text, RESULT_PREVIEW_MAX);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
else if (node.kind === "tool") {
|
|
38
|
+
const m = messageOf(lookup, node.entryIds[0]);
|
|
39
|
+
if (m?.role === "assistant")
|
|
40
|
+
for (const block of m.content)
|
|
41
|
+
if (block.type === "toolCall" && block.id === node.id)
|
|
42
|
+
out.args = clip(JSON.stringify(redactValue(block.arguments), null, 2), ARGS_PREVIEW_MAX);
|
|
43
|
+
const r = messageOf(lookup, node.entryIds[1]);
|
|
44
|
+
if (r?.role === "toolResult")
|
|
45
|
+
out.result = clip(contentText(r.content), RESULT_PREVIEW_MAX);
|
|
46
|
+
}
|
|
47
|
+
return Object.keys(out).length === 0 ? undefined : out;
|
|
48
|
+
}
|
|
49
|
+
/** 预览的字符数(总预算用)。 */
|
|
50
|
+
export function previewSize(p) {
|
|
51
|
+
return ((p.input?.length ?? 0) +
|
|
52
|
+
(p.output?.length ?? 0) +
|
|
53
|
+
(p.args?.length ?? 0) +
|
|
54
|
+
(p.result?.length ?? 0));
|
|
55
|
+
}
|
|
56
|
+
/** 预览表的 key:`<kind>:<id>`(同一轨迹内唯一;子轨迹的节点 id 来自子会话条目)。 */
|
|
57
|
+
export function previewKey(node) {
|
|
58
|
+
return `${node.kind}:${node.id}`;
|
|
59
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
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 type { AgentSession } from "../agent/types.js";
|
|
8
|
+
import type { RpcGetTraceParams } from "../rpc.js";
|
|
9
|
+
import { type TraceQueryResult } from "./query.js";
|
|
10
|
+
import type { Trace, TraceOptions } from "./types.js";
|
|
11
|
+
/** RPC `get_trace`。参数不合法抛 `invalid_arguments`,任务不存在抛 `task_not_found`。 */
|
|
12
|
+
export declare function sessionTrace(session: AgentSession, params: RpcGetTraceParams): TraceQueryResult;
|
|
13
|
+
/** SDK `session.trace(options?)`:缺省全部回合;`turnLimit` 取尾部若干回合;`taskId` 取子轨迹。 */
|
|
14
|
+
export declare function sdkSessionTrace(session: AgentSession, options?: TraceOptions): Trace;
|