@armadra/agent 0.5.1 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +177 -304
- package/CHANGELOG.zh-CN.md +442 -0
- package/README.md +408 -364
- package/README.zh-CN.md +705 -0
- package/dist/agent/session-plan.js +2 -2
- package/dist/agent/session-state.d.ts +3 -0
- package/dist/agent/session-state.js +20 -0
- package/dist/agent/session-subagent.d.ts +15 -1
- package/dist/agent/session-subagent.js +26 -3
- package/dist/agent/session-telemetry.d.ts +16 -2
- package/dist/agent/session-telemetry.js +29 -7
- package/dist/agent/session-tools.js +5 -2
- package/dist/agent/session-trace-writer.d.ts +27 -0
- package/dist/agent/session-trace-writer.js +253 -0
- package/dist/agent/session.d.ts +2 -0
- package/dist/agent/session.js +12 -0
- package/dist/agent/subagent-direct.d.ts +20 -0
- package/dist/agent/subagent-direct.js +76 -0
- package/dist/agent/subagent-registry.d.ts +8 -1
- package/dist/agent/subagent-registry.js +28 -1
- package/dist/agent/system-prompt.d.ts +3 -1
- package/dist/agent/system-prompt.js +3 -0
- package/dist/agent/tool-runner.d.ts +2 -1
- package/dist/agent/tool-runner.js +5 -4
- package/dist/agent/types-w6.d.ts +39 -0
- package/dist/agent/types-w6.js +4 -0
- package/dist/agent/types.d.ts +5 -2
- package/dist/agents/external.js +1 -1
- package/dist/agents/task-record.d.ts +74 -1
- package/dist/agents/task-record.js +100 -0
- package/dist/ai/apis/cache-params.js +2 -1
- package/dist/ai/apis/chatgpt-backend.d.ts +52 -0
- package/dist/ai/apis/chatgpt-backend.js +224 -0
- package/dist/ai/apis/chatgpt-rate-limits.d.ts +26 -0
- package/dist/ai/apis/chatgpt-rate-limits.js +91 -0
- package/dist/ai/apis/openai-responses-request.d.ts +2 -1
- package/dist/ai/apis/openai-responses-request.js +8 -2
- package/dist/ai/apis/openai-responses.d.ts +2 -0
- package/dist/ai/apis/openai-responses.js +51 -16
- package/dist/ai/overflow.d.ts +1 -1
- package/dist/ai/overflow.js +10 -7
- package/dist/ai/providers/auth.d.ts +15 -2
- package/dist/ai/providers/auth.js +69 -2
- package/dist/ai/providers/builtin.js +27 -0
- package/dist/ai/providers/catalog-data.js +1 -0
- package/dist/ai/providers/enrich.js +2 -7
- package/dist/ai/providers/models-dev-cache.js +15 -19
- package/dist/ai/providers/models-dev-snapshot.js +8 -7
- package/dist/ai/providers/models-dev.js +5 -15
- package/dist/ai/providers/suggest.js +2 -16
- package/dist/ai/types.d.ts +27 -1
- package/dist/auth/chatgpt/backend-client.d.ts +26 -0
- package/dist/auth/chatgpt/backend-client.js +74 -0
- package/dist/auth/chatgpt/claims.d.ts +17 -0
- package/dist/auth/chatgpt/claims.js +46 -0
- package/dist/auth/chatgpt/cli.d.ts +33 -0
- package/dist/auth/chatgpt/cli.js +252 -0
- package/dist/auth/chatgpt/doctor.d.ts +17 -0
- package/dist/auth/chatgpt/doctor.js +36 -0
- package/dist/auth/chatgpt/host-id.d.ts +7 -0
- package/dist/auth/chatgpt/host-id.js +26 -0
- package/dist/auth/chatgpt/login.d.ts +30 -0
- package/dist/auth/chatgpt/login.js +130 -0
- package/dist/auth/chatgpt/presets.d.ts +66 -0
- package/dist/auth/chatgpt/presets.js +120 -0
- package/dist/auth/chatgpt/quota-text.d.ts +13 -0
- package/dist/auth/chatgpt/quota-text.js +36 -0
- package/dist/auth/oauth/browser.d.ts +12 -0
- package/dist/auth/oauth/browser.js +27 -0
- package/dist/auth/oauth/callback-server.d.ts +47 -0
- package/dist/auth/oauth/callback-server.js +147 -0
- package/dist/auth/oauth/flows.d.ts +62 -0
- package/dist/auth/oauth/flows.js +113 -0
- package/dist/auth/oauth/jwt.d.ts +24 -0
- package/dist/auth/oauth/jwt.js +81 -0
- package/dist/auth/oauth/live.d.ts +21 -0
- package/dist/auth/oauth/live.js +25 -0
- package/dist/auth/oauth/oidc.d.ts +26 -0
- package/dist/auth/oauth/oidc.js +72 -0
- package/dist/auth/oauth/pkce.d.ts +15 -0
- package/dist/auth/oauth/pkce.js +20 -0
- package/dist/auth/oauth/refresh.d.ts +35 -0
- package/dist/auth/oauth/refresh.js +129 -0
- package/dist/auth/oauth/token-client.d.ts +33 -0
- package/dist/auth/oauth/token-client.js +121 -0
- package/dist/auth/oauth/token-store.d.ts +23 -0
- package/dist/auth/oauth/token-store.js +125 -0
- package/dist/auth/testing/fake-oauth.d.ts +73 -0
- package/dist/auth/testing/fake-oauth.js +271 -0
- package/dist/auth/testing/refresh-child.d.ts +5 -0
- package/dist/auth/testing/refresh-child.js +16 -0
- package/dist/bundle/ama.cjs +25928 -11144
- 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 +5 -0
- package/dist/cli/compose-providers.js +32 -2
- package/dist/cli/compose-session.d.ts +5 -0
- package/dist/cli/compose-session.js +27 -13
- package/dist/cli/compose-store.d.ts +2 -0
- package/dist/cli/compose-store.js +9 -5
- package/dist/cli/compose.d.ts +2 -0
- package/dist/cli/compose.js +13 -5
- package/dist/cli/default-model.d.ts +0 -2
- package/dist/cli/default-model.js +5 -8
- package/dist/cli/deps.d.ts +5 -1
- package/dist/cli/exit-codes.d.ts +1 -1
- package/dist/cli/exit-codes.js +7 -16
- package/dist/cli/from-prompt.js +3 -2
- package/dist/cli/help-text.d.ts +2 -1
- package/dist/cli/help-text.js +5 -99
- package/dist/cli/main.d.ts +5 -0
- package/dist/cli/main.js +21 -2
- package/dist/cli/proxy.js +14 -9
- package/dist/cli/runtime.d.ts +5 -0
- package/dist/cli/startup-screen.js +20 -27
- package/dist/cli/startup-steps.js +6 -8
- package/dist/cli/subcommands/auth.d.ts +6 -3
- package/dist/cli/subcommands/auth.js +52 -22
- package/dist/cli/subcommands/config-set.d.ts +21 -0
- package/dist/cli/subcommands/config-set.js +137 -0
- package/dist/cli/subcommands/config.d.ts +2 -1
- package/dist/cli/subcommands/config.js +51 -37
- package/dist/cli/subcommands/doctor.d.ts +2 -1
- package/dist/cli/subcommands/doctor.js +97 -58
- package/dist/cli/subcommands/init.d.ts +1 -1
- package/dist/cli/subcommands/init.js +8 -7
- package/dist/cli/subcommands/memory.d.ts +18 -0
- package/dist/cli/subcommands/memory.js +189 -0
- package/dist/cli/subcommands/model-meta.js +11 -9
- package/dist/cli/subcommands/models-cache-probe.js +23 -20
- package/dist/cli/subcommands/models-discover.d.ts +3 -0
- package/dist/cli/subcommands/models-discover.js +44 -21
- package/dist/cli/subcommands/models.d.ts +1 -1
- package/dist/cli/subcommands/models.js +29 -22
- package/dist/cli/subcommands/probe-runner.js +8 -7
- package/dist/cli/subcommands/providers-list.js +32 -21
- package/dist/cli/subcommands/providers-plan.js +24 -25
- package/dist/cli/subcommands/providers-probe.js +5 -6
- package/dist/cli/subcommands/providers.d.ts +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 +101 -68
- package/dist/config/key-docs.d.ts +18 -7
- package/dist/config/key-docs.js +43 -128
- package/dist/config/load.js +7 -6
- package/dist/config/merge.d.ts +4 -1
- package/dist/config/merge.js +42 -22
- package/dist/config/paths.js +6 -5
- package/dist/config/profile.d.ts +5 -1
- package/dist/config/profile.js +7 -2
- package/dist/config/schema-w5.js +3 -2
- package/dist/config/schema-w6.d.ts +19 -0
- package/dist/config/schema-w6.js +115 -0
- package/dist/config/schema.js +34 -20
- package/dist/config/settings-registry.d.ts +78 -0
- package/dist/config/settings-registry.js +184 -0
- package/dist/config/types-w6.d.ts +109 -0
- package/dist/config/types-w6.js +19 -0
- package/dist/config/types.d.ts +11 -8
- package/dist/config/types.js +1 -0
- package/dist/drivers/acp/client.js +1 -1
- package/dist/drivers/acp/driver.js +13 -8
- package/dist/drivers/agents.js +4 -3
- package/dist/drivers/base.js +3 -2
- package/dist/drivers/host-runners.js +2 -1
- package/dist/drivers/native/claude-stream.js +12 -11
- package/dist/drivers/native/codex-app-server.js +17 -12
- package/dist/drivers/native/oneshot.js +8 -7
- package/dist/drivers/pool.js +1 -1
- package/dist/drivers/runner.d.ts +3 -1
- package/dist/drivers/runner.js +68 -20
- package/dist/drivers/turn.js +1 -1
- package/dist/hooks/config.js +3 -2
- package/dist/hooks/protocol.js +18 -12
- package/dist/host/api-impl.js +11 -10
- package/dist/host/loader.js +9 -8
- package/dist/host/types.d.ts +3 -0
- package/dist/i18n/catalog.d.ts +2169 -0
- package/dist/i18n/catalog.js +72 -0
- package/dist/i18n/format.d.ts +21 -0
- package/dist/i18n/format.js +58 -0
- package/dist/i18n/index.d.ts +58 -0
- package/dist/i18n/index.js +72 -0
- package/dist/i18n/messages/agents.d.ts +84 -0
- package/dist/i18n/messages/agents.js +85 -0
- package/dist/i18n/messages/approval.d.ts +99 -0
- package/dist/i18n/messages/approval.js +100 -0
- package/dist/i18n/messages/auth.d.ts +187 -0
- package/dist/i18n/messages/auth.js +189 -0
- package/dist/i18n/messages/cli-args.d.ts +46 -0
- package/dist/i18n/messages/cli-args.js +46 -0
- package/dist/i18n/messages/cli-help.d.ts +12 -0
- package/dist/i18n/messages/cli-help.js +244 -0
- package/dist/i18n/messages/cli.d.ts +336 -0
- package/dist/i18n/messages/cli.js +311 -0
- package/dist/i18n/messages/config-keys.d.ts +289 -0
- package/dist/i18n/messages/config-keys.js +292 -0
- package/dist/i18n/messages/config.d.ts +502 -0
- package/dist/i18n/messages/config.js +239 -0
- package/dist/i18n/messages/drivers.d.ts +123 -0
- package/dist/i18n/messages/drivers.js +124 -0
- package/dist/i18n/messages/errors.d.ts +83 -0
- package/dist/i18n/messages/errors.js +171 -0
- package/dist/i18n/messages/interactive-line.d.ts +61 -0
- package/dist/i18n/messages/interactive-line.js +69 -0
- package/dist/i18n/messages/interactive-startup.d.ts +103 -0
- package/dist/i18n/messages/interactive-startup.js +104 -0
- package/dist/i18n/messages/interactive-view.d.ts +140 -0
- package/dist/i18n/messages/interactive-view.js +141 -0
- package/dist/i18n/messages/interactive.d.ts +493 -0
- package/dist/i18n/messages/interactive.js +248 -0
- package/dist/i18n/messages/memory.d.ts +123 -0
- package/dist/i18n/messages/memory.js +128 -0
- package/dist/i18n/messages/panels.d.ts +190 -0
- package/dist/i18n/messages/panels.js +189 -0
- package/dist/i18n/messages/permissions.d.ts +126 -0
- package/dist/i18n/messages/permissions.js +151 -0
- package/dist/i18n/messages/plan.d.ts +123 -0
- package/dist/i18n/messages/plan.js +124 -0
- package/dist/i18n/messages/print.d.ts +86 -0
- package/dist/i18n/messages/print.js +91 -0
- package/dist/i18n/messages/report.d.ts +391 -0
- package/dist/i18n/messages/report.js +490 -0
- package/dist/i18n/messages/rewind.d.ts +198 -0
- package/dist/i18n/messages/rewind.js +217 -0
- package/dist/i18n/messages/session.d.ts +230 -0
- package/dist/i18n/messages/session.js +258 -0
- package/dist/i18n/messages/settings.d.ts +348 -0
- package/dist/i18n/messages/settings.js +336 -0
- package/dist/i18n/messages/subcommands-config.d.ts +111 -0
- package/dist/i18n/messages/subcommands-config.js +127 -0
- package/dist/i18n/messages/subcommands.d.ts +548 -0
- package/dist/i18n/messages/subcommands.js +474 -0
- package/dist/i18n/messages/trace.d.ts +243 -0
- package/dist/i18n/messages/trace.js +238 -0
- package/dist/i18n/types.d.ts +15 -0
- package/dist/i18n/types.js +7 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +2 -0
- package/dist/memory/edit.d.ts +24 -0
- package/dist/memory/edit.js +63 -0
- package/dist/memory/frontmatter.d.ts +37 -0
- package/dist/memory/frontmatter.js +79 -0
- package/dist/memory/index.d.ts +28 -0
- package/dist/memory/index.js +126 -0
- package/dist/memory/lock.d.ts +17 -0
- package/dist/memory/lock.js +62 -0
- package/dist/memory/paths.d.ts +57 -0
- package/dist/memory/paths.js +175 -0
- package/dist/memory/report.d.ts +36 -0
- package/dist/memory/report.js +86 -0
- package/dist/memory/runtime.d.ts +42 -0
- package/dist/memory/runtime.js +36 -0
- package/dist/memory/secrets.d.ts +8 -0
- package/dist/memory/secrets.js +27 -0
- package/dist/memory/section.d.ts +28 -0
- package/dist/memory/section.js +59 -0
- package/dist/memory/store.d.ts +70 -0
- package/dist/memory/store.js +284 -0
- package/dist/memory/tool.d.ts +31 -0
- package/dist/memory/tool.js +94 -0
- package/dist/modes/acp/acp-events.js +2 -1
- package/dist/modes/acp/acp-server.js +13 -12
- package/dist/modes/commands-core.d.ts +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 +19 -1
- package/dist/modes/interactive/commands.js +84 -40
- 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 +19 -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/panels.js +39 -31
- package/dist/modes/interactive/pickers.d.ts +2 -1
- package/dist/modes/interactive/pickers.js +10 -6
- package/dist/modes/interactive/plan-command.d.ts +1 -1
- package/dist/modes/interactive/plan-command.js +24 -27
- package/dist/modes/interactive/plan-dialog.js +18 -17
- package/dist/modes/interactive/plan-flow.js +6 -5
- package/dist/modes/interactive/rewind-command.d.ts +1 -1
- package/dist/modes/interactive/rewind-command.js +18 -16
- package/dist/modes/interactive/rewind-flow.d.ts +0 -1
- package/dist/modes/interactive/rewind-flow.js +13 -14
- package/dist/modes/interactive/rewind-list.js +7 -6
- package/dist/modes/interactive/rewind-panel.js +40 -40
- package/dist/modes/interactive/rewind-text.d.ts +5 -3
- package/dist/modes/interactive/rewind-text.js +48 -38
- package/dist/modes/interactive/run-indicator.js +15 -12
- package/dist/modes/interactive/session-events.js +3 -2
- package/dist/modes/interactive/startup-header.js +22 -23
- package/dist/modes/interactive/startup-ui.js +38 -30
- 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/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 +625 -0
- package/docs/en/rpc.md +361 -0
- package/docs/en/sessions.md +219 -0
- package/docs/en/tui.md +527 -0
- package/docs/host-api.md +18 -17
- package/docs/memory.md +172 -0
- package/docs/permissions.md +2 -2
- package/docs/providers.md +67 -1
- package/docs/rpc.md +31 -3
- package/docs/session-format.md +8 -2
- package/docs/sessions.md +29 -1
- package/docs/tui.md +132 -3
- package/package.json +8 -3
package/dist/tools/image-file.js
CHANGED
|
@@ -138,22 +138,53 @@ export async function fitImage(buf, mimeType, options = {}, path) {
|
|
|
138
138
|
resized: { tool: resized.tool, ...(fit.size !== undefined ? { from: fit.size } : {}) },
|
|
139
139
|
};
|
|
140
140
|
}
|
|
141
|
+
const HINT_TEXT = {
|
|
142
|
+
resize_off: " (images.resize is off)",
|
|
143
|
+
no_tool: " (no resize tool found: install ImageMagick, or sips on macOS)",
|
|
144
|
+
still_too_large: " (resizing did not bring it under the limit)",
|
|
145
|
+
};
|
|
146
|
+
function imageError(message, detail) {
|
|
147
|
+
return new AmaError("invalid_arguments", message, { detail });
|
|
148
|
+
}
|
|
149
|
+
/** `AmaError.detail` 是否是读图失败的说明。 */
|
|
150
|
+
export function isImageFileErrorDetail(detail) {
|
|
151
|
+
return (typeof detail === "object" &&
|
|
152
|
+
detail !== null &&
|
|
153
|
+
typeof detail.path === "string" &&
|
|
154
|
+
["missing", "not_file", "unsupported", "too_large", "too_wide"].includes(String(detail.reason)));
|
|
155
|
+
}
|
|
141
156
|
function fitError(path, fit, limit, bytes, resizeOff) {
|
|
142
157
|
const hint = resizeOff
|
|
143
|
-
? "
|
|
158
|
+
? "resize_off"
|
|
144
159
|
: fit.note.includes("no resize tool")
|
|
145
|
-
? "
|
|
160
|
+
? "no_tool"
|
|
146
161
|
: fit.note.includes("resizing did not")
|
|
147
|
-
? "
|
|
148
|
-
:
|
|
162
|
+
? "still_too_large"
|
|
163
|
+
: undefined;
|
|
164
|
+
const hintText = hint === undefined ? "" : HINT_TEXT[hint];
|
|
149
165
|
if (fit.reason === "too_wide") {
|
|
150
|
-
const dims = fit.size !== undefined ?
|
|
151
|
-
return
|
|
166
|
+
const dims = fit.size !== undefined ? ` (${fit.size.width}x${fit.size.height})` : "";
|
|
167
|
+
return imageError(`Image edge exceeds ${MAX_IMAGE_EDGE} px: ${path}${dims}${hintText}`, {
|
|
168
|
+
reason: "too_wide",
|
|
169
|
+
path,
|
|
170
|
+
maxEdge: MAX_IMAGE_EDGE,
|
|
171
|
+
...(fit.size !== undefined ? { size: fit.size } : {}),
|
|
172
|
+
...(hint !== undefined ? { hint } : {}),
|
|
173
|
+
});
|
|
152
174
|
}
|
|
153
|
-
|
|
175
|
+
const limitMb = formatMb(limit);
|
|
176
|
+
const sizeMb = formatMb(base64Size(bytes));
|
|
177
|
+
return imageError(`Image exceeds the ${limitMb} limit (base64): ${path} (${sizeMb})${hintText}`, {
|
|
178
|
+
reason: "too_large",
|
|
179
|
+
path,
|
|
180
|
+
limitMb,
|
|
181
|
+
sizeMb,
|
|
182
|
+
...(hint !== undefined ? { hint } : {}),
|
|
183
|
+
});
|
|
154
184
|
}
|
|
155
185
|
/**
|
|
156
|
-
* 读一张图片作为附件。文件不存在、不是图片、超过上限 → AmaError(`invalid_arguments
|
|
186
|
+
* 读一张图片作为附件。文件不存在、不是图片、超过上限 → AmaError(`invalid_arguments`,英文 message,
|
|
187
|
+
* `detail` 为 `ImageFileErrorDetail`,界面层据此本地化)。
|
|
157
188
|
*/
|
|
158
189
|
export async function loadImageFile(path, options = {}) {
|
|
159
190
|
let info;
|
|
@@ -161,17 +192,28 @@ export async function loadImageFile(path, options = {}) {
|
|
|
161
192
|
info = await stat(path);
|
|
162
193
|
}
|
|
163
194
|
catch {
|
|
164
|
-
throw
|
|
195
|
+
throw imageError(`Image not found: ${path}`, { reason: "missing", path });
|
|
165
196
|
}
|
|
166
197
|
if (!info.isFile())
|
|
167
|
-
throw
|
|
198
|
+
throw imageError(`Not a file: ${path}`, { reason: "not_file", path });
|
|
168
199
|
const limit = options.maxBase64Bytes ?? DEFAULT_IMAGE_BASE64_LIMIT;
|
|
169
|
-
if (info.size > MAX_IMAGE_FILE_BYTES)
|
|
170
|
-
|
|
200
|
+
if (info.size > MAX_IMAGE_FILE_BYTES) {
|
|
201
|
+
const limitMb = formatMb(limit);
|
|
202
|
+
const sizeMb = formatMb(base64Size(info.size));
|
|
203
|
+
throw imageError(`Image exceeds the ${limitMb} limit (base64): ${path} (${sizeMb})`, {
|
|
204
|
+
reason: "too_large",
|
|
205
|
+
path,
|
|
206
|
+
limitMb,
|
|
207
|
+
sizeMb,
|
|
208
|
+
});
|
|
209
|
+
}
|
|
171
210
|
const buf = await readFile(path);
|
|
172
211
|
const mimeType = sniffImageMime(buf) ?? imageMimeFromPath(path);
|
|
173
212
|
if (mimeType === undefined)
|
|
174
|
-
throw
|
|
213
|
+
throw imageError(`Unsupported image (PNG / JPEG / GIF / WebP): ${path}`, {
|
|
214
|
+
reason: "unsupported",
|
|
215
|
+
path,
|
|
216
|
+
});
|
|
175
217
|
const fit = await fitImage(buf, mimeType, options, path);
|
|
176
218
|
if (!fit.ok)
|
|
177
219
|
throw fitError(path, fit, limit, buf.length, options.resize === "off");
|
package/dist/tools/presets.d.ts
CHANGED
|
@@ -61,13 +61,26 @@ export declare function codemodeCallableFilter(config: Pick<AmaConfig, "tools">)
|
|
|
61
61
|
* 返回去重后的名字(保持首次出现顺序)。
|
|
62
62
|
*/
|
|
63
63
|
export declare function applyToolAdjustments(base: readonly string[], adjustments: readonly string[] | undefined): string[];
|
|
64
|
+
/**
|
|
65
|
+
* [W6-I3] 预设解析的警告(给人看):本模块在模型侧目录里、不 import i18n,返回结构,
|
|
66
|
+
* 由调用方经 `msg().session.codemode.presetWarning()` 渲染。
|
|
67
|
+
*/
|
|
68
|
+
export type PresetWarning = {
|
|
69
|
+
kind: "codemode_only_fallback";
|
|
70
|
+
} | {
|
|
71
|
+
kind: "codemode_unavailable";
|
|
72
|
+
mode: CodemodeMode;
|
|
73
|
+
} | {
|
|
74
|
+
kind: "unknown_tool";
|
|
75
|
+
name: string;
|
|
76
|
+
};
|
|
64
77
|
export interface PresetResolution {
|
|
65
78
|
/** 生效的预设(codemode 工具缺失时回退为 default)。 */
|
|
66
79
|
preset: ToolsPreset;
|
|
67
80
|
codemode: CodemodeMode;
|
|
68
81
|
/** 活动的内置工具名(按名排序)。 */
|
|
69
82
|
builtin: string[];
|
|
70
|
-
warnings:
|
|
83
|
+
warnings: PresetWarning[];
|
|
71
84
|
}
|
|
72
85
|
export declare function resolvePreset(input: {
|
|
73
86
|
config: Pick<AmaConfig, "tools" | "codemode">;
|
package/dist/tools/presets.js
CHANGED
|
@@ -104,8 +104,8 @@ export function resolvePreset(input) {
|
|
|
104
104
|
}
|
|
105
105
|
if (codemode !== "off" && !input.available(CODEMODE_TOOL)) {
|
|
106
106
|
warnings.push(preset === "codemode-only"
|
|
107
|
-
?
|
|
108
|
-
:
|
|
107
|
+
? { kind: "codemode_only_fallback" }
|
|
108
|
+
: { kind: "codemode_unavailable", mode: codemode });
|
|
109
109
|
if (preset === "codemode-only")
|
|
110
110
|
preset = "default";
|
|
111
111
|
codemode = "off";
|
|
@@ -124,7 +124,7 @@ export function resolvePreset(input) {
|
|
|
124
124
|
if (input.available(name))
|
|
125
125
|
names.push(name);
|
|
126
126
|
else
|
|
127
|
-
warnings.push(
|
|
127
|
+
warnings.push({ kind: "unknown_tool", name });
|
|
128
128
|
}
|
|
129
129
|
return { preset, codemode, builtin: names.sort(), warnings };
|
|
130
130
|
}
|
package/dist/tools/registry.js
CHANGED
|
@@ -49,7 +49,7 @@ export function validateToolDefinition(tool) {
|
|
|
49
49
|
if (typeof tool.name !== "string" || !TOOL_NAME_RE.test(tool.name)) {
|
|
50
50
|
throw new AmaError("invalid_arguments", `Invalid tool name "${String(tool.name)}"`);
|
|
51
51
|
}
|
|
52
|
-
if (!["read", "write", "execute"].includes(tool.permission)) {
|
|
52
|
+
if (!["read", "write", "execute", "memory"].includes(tool.permission)) {
|
|
53
53
|
throw new AmaError("invalid_arguments", `Tool ${tool.name}: invalid permission`);
|
|
54
54
|
}
|
|
55
55
|
if (typeof tool.execute !== "function") {
|
package/dist/tools/truncate.d.ts
CHANGED
|
@@ -45,7 +45,7 @@ export interface MiddleTruncation {
|
|
|
45
45
|
}
|
|
46
46
|
/**
|
|
47
47
|
* 头 + 尾截断([W5-H2] §8.3 H5):超过 `maxChars` 时保留前 70% 与后 30%,中间换成
|
|
48
|
-
* `marker(省略字符数)` 的文本(缺省 `[… N
|
|
48
|
+
* `marker(省略字符数)` 的文本(缺省 `[… N chars omitted]`;[W6-C0] 进模型的标记固定英文)。
|
|
49
49
|
*/
|
|
50
50
|
export declare function truncateMiddle(text: string, maxChars: number, marker?: (omitted: number) => string): MiddleTruncation;
|
|
51
51
|
/** 单行按字符截断,附省略提示。 */
|
package/dist/tools/truncate.js
CHANGED
|
@@ -155,9 +155,9 @@ function charBoundary(text, index) {
|
|
|
155
155
|
}
|
|
156
156
|
/**
|
|
157
157
|
* 头 + 尾截断([W5-H2] §8.3 H5):超过 `maxChars` 时保留前 70% 与后 30%,中间换成
|
|
158
|
-
* `marker(省略字符数)` 的文本(缺省 `[… N
|
|
158
|
+
* `marker(省略字符数)` 的文本(缺省 `[… N chars omitted]`;[W6-C0] 进模型的标记固定英文)。
|
|
159
159
|
*/
|
|
160
|
-
export function truncateMiddle(text, maxChars, marker = (omitted) => `[… ${omitted}
|
|
160
|
+
export function truncateMiddle(text, maxChars, marker = (omitted) => `[… ${omitted} chars omitted]`) {
|
|
161
161
|
if (text.length <= maxChars)
|
|
162
162
|
return { content: text, omitted: 0 };
|
|
163
163
|
const limit = Math.max(0, Math.floor(maxChars));
|
package/dist/tools/types.d.ts
CHANGED
|
@@ -21,9 +21,13 @@
|
|
|
21
21
|
import type { ContentBlock, JsonSchema, ModelRef, ModelThinkingLevel, Usage } from "../ai/types.js";
|
|
22
22
|
import type { CheckpointHooks } from "../checkpoints/types.js";
|
|
23
23
|
import type { PermissionMode } from "../permissions/types.js";
|
|
24
|
+
import type { TraceExternalTurnData } from "../trace/types.js";
|
|
24
25
|
export type { JsonSchema } from "../ai/types.js";
|
|
25
26
|
/** 权限管线的粗分类(§7)。 */
|
|
26
|
-
|
|
27
|
+
/**
|
|
28
|
+
* [W6-C0] `memory`:记忆工具专用(`permissions/memory-class.ts`)——`view` 按 read、写命令按 execute 判定。
|
|
29
|
+
*/
|
|
30
|
+
export type ToolPermission = "read" | "write" | "execute" | "memory";
|
|
27
31
|
export type ToolExecutionMode = "sequential" | "parallel";
|
|
28
32
|
export interface ToolAnnotations {
|
|
29
33
|
readOnly?: boolean;
|
|
@@ -130,9 +134,21 @@ export type SubagentEvent = {
|
|
|
130
134
|
type: "tool";
|
|
131
135
|
toolName: string;
|
|
132
136
|
status: "started" | "completed" | "failed";
|
|
137
|
+
/** [W6-C0] runner 内的调用 id(外部 Agent 的 tool_call id;配对 started / 结束)。 */
|
|
138
|
+
id?: string;
|
|
139
|
+
/** [W6-C0] 事件时刻(epoch ms)。 */
|
|
140
|
+
at?: number;
|
|
133
141
|
} | {
|
|
134
142
|
type: "turn";
|
|
135
143
|
turn: number;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* [W6-C0] 外部 Agent 一个回合结束时的骨架(docs/wave6-plan.md §2.2):任务注册表写成父会话的
|
|
147
|
+
* `ama.trace{kind:"external_turn"}`。只有种类、状态、时间与计数——不含工具标题、命令行、路径。
|
|
148
|
+
*/
|
|
149
|
+
| {
|
|
150
|
+
type: "turn_trace";
|
|
151
|
+
trace: Omit<TraceExternalTurnData, "kind" | "taskId" | "agent">;
|
|
136
152
|
} | {
|
|
137
153
|
type: "usage";
|
|
138
154
|
usage?: Usage;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 轨迹构建器的索引与扫描状态(`build.ts` 用)。[W6-T1]
|
|
3
|
+
*
|
|
4
|
+
* 预建索引:`ama.trace` 按 assistant / toolCall / compaction / usage 条目 id,`ama.task` 按父 toolCallId(同一
|
|
5
|
+
* taskId 取分支上最后一条),`external_turn` 按 taskId,`context_edit{retry|overflow}` 的目标。
|
|
6
|
+
*/
|
|
7
|
+
import type { Usage } from "../ai/types.js";
|
|
8
|
+
import type { SessionEntry } from "../session/types.js";
|
|
9
|
+
import { type TraceAuxData, type TraceAuxNode, type TraceCompactionData, type TraceEntryData, type TraceExternalTurnData, type TraceStepData, type TraceSubcallTiming, type TraceToolNode, type TraceToolTiming, type TraceTurnNode } from "./types.js";
|
|
10
|
+
/** 父会话 `ama.task` 的 customType(与 agents/task-record.ts 相同;这里不 import 运行时模块)。 */
|
|
11
|
+
export declare const TASK_CUSTOM_TYPE = "ama.task";
|
|
12
|
+
/** 父会话里一个任务的最后一条快照(`TaskInfo + parentToolCallId`)。 */
|
|
13
|
+
export interface TaskData {
|
|
14
|
+
taskId: string;
|
|
15
|
+
agent?: string;
|
|
16
|
+
runner?: string;
|
|
17
|
+
background?: boolean;
|
|
18
|
+
status?: string;
|
|
19
|
+
startedAt?: number;
|
|
20
|
+
endedAt?: number;
|
|
21
|
+
turns?: number;
|
|
22
|
+
usage?: Usage;
|
|
23
|
+
costUsd?: number;
|
|
24
|
+
parentToolCallId?: string;
|
|
25
|
+
sessionRef?: {
|
|
26
|
+
runner?: string;
|
|
27
|
+
sessionId?: string;
|
|
28
|
+
sessionFile?: string;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
export interface Index {
|
|
32
|
+
stepByAssistant: Map<string, {
|
|
33
|
+
data: TraceStepData;
|
|
34
|
+
entryId: string;
|
|
35
|
+
}>;
|
|
36
|
+
toolTiming: Map<string, TraceToolTiming>;
|
|
37
|
+
subcalls: Map<string, {
|
|
38
|
+
data: TraceSubcallTiming;
|
|
39
|
+
entryId: string;
|
|
40
|
+
}[]>;
|
|
41
|
+
compactionByEntry: Map<string, {
|
|
42
|
+
data: TraceCompactionData;
|
|
43
|
+
entryId: string;
|
|
44
|
+
}>;
|
|
45
|
+
auxByUsage: Map<string, {
|
|
46
|
+
data: TraceAuxData;
|
|
47
|
+
entryId: string;
|
|
48
|
+
}>;
|
|
49
|
+
external: Map<string, {
|
|
50
|
+
data: TraceExternalTurnData;
|
|
51
|
+
entryId: string;
|
|
52
|
+
}[]>;
|
|
53
|
+
/** 父 toolCallId → taskId → 最后一条快照。 */
|
|
54
|
+
tasks: Map<string, Map<string, {
|
|
55
|
+
data: TaskData;
|
|
56
|
+
entryId: string;
|
|
57
|
+
}>>;
|
|
58
|
+
/** 被 context_edit{retry|overflow} 剔除的 assistant。 */
|
|
59
|
+
retried: Set<string>;
|
|
60
|
+
}
|
|
61
|
+
export interface ScanState {
|
|
62
|
+
turns: TraceTurnNode[];
|
|
63
|
+
aux: TraceAuxNode[];
|
|
64
|
+
turn: TraceTurnNode | undefined;
|
|
65
|
+
/** 回合开始时的模型(推算回退用)。 */
|
|
66
|
+
turnModel: string | undefined;
|
|
67
|
+
model: string | undefined;
|
|
68
|
+
tools: Map<string, TraceToolNode>;
|
|
69
|
+
/** 有 toolResult 的调用。 */
|
|
70
|
+
resolved: Set<string>;
|
|
71
|
+
/** 回合 id → 压缩 / 分支摘要等不属于 step 的用量。 */
|
|
72
|
+
extraUsage: Map<string, Usage[]>;
|
|
73
|
+
}
|
|
74
|
+
export declare function isObject(value: unknown): value is Record<string, unknown>;
|
|
75
|
+
/** ISO 时间 → epoch ms;不合法返回 undefined。 */
|
|
76
|
+
export declare function entryTime(entry: {
|
|
77
|
+
timestamp: string;
|
|
78
|
+
}): number | undefined;
|
|
79
|
+
export declare function num(value: unknown): number | undefined;
|
|
80
|
+
/** 是有限数字时写入 `target[key]`。 */
|
|
81
|
+
export declare function putNum<T extends object>(target: T, key: keyof T, value: unknown): void;
|
|
82
|
+
/** `ama.trace` 的 data(形状不对返回 undefined)。 */
|
|
83
|
+
export declare function traceData(entry: SessionEntry): TraceEntryData | undefined;
|
|
84
|
+
export declare function buildIndex(entries: readonly SessionEntry[]): Index;
|
|
85
|
+
export declare function zeroUsage(): Usage;
|
|
86
|
+
/** cacheRead / (input + cacheRead + cacheWrite);分母为 0 时 undefined。 */
|
|
87
|
+
export declare function cacheHitRatio(usage: Usage | undefined): number | undefined;
|
|
88
|
+
export declare function splitRef(ref: string | undefined): {
|
|
89
|
+
provider: string;
|
|
90
|
+
model: string;
|
|
91
|
+
};
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 轨迹构建器的索引与扫描状态(`build.ts` 用)。[W6-T1]
|
|
3
|
+
*
|
|
4
|
+
* 预建索引:`ama.trace` 按 assistant / toolCall / compaction / usage 条目 id,`ama.task` 按父 toolCallId(同一
|
|
5
|
+
* taskId 取分支上最后一条),`external_turn` 按 taskId,`context_edit{retry|overflow}` 的目标。
|
|
6
|
+
*/
|
|
7
|
+
import { TRACE_CUSTOM_TYPE, } from "./types.js";
|
|
8
|
+
/** 父会话 `ama.task` 的 customType(与 agents/task-record.ts 相同;这里不 import 运行时模块)。 */
|
|
9
|
+
export const TASK_CUSTOM_TYPE = "ama.task";
|
|
10
|
+
export function isObject(value) {
|
|
11
|
+
return typeof value === "object" && value !== null;
|
|
12
|
+
}
|
|
13
|
+
/** ISO 时间 → epoch ms;不合法返回 undefined。 */
|
|
14
|
+
export function entryTime(entry) {
|
|
15
|
+
const t = Date.parse(entry.timestamp);
|
|
16
|
+
return Number.isFinite(t) ? t : undefined;
|
|
17
|
+
}
|
|
18
|
+
export function num(value) {
|
|
19
|
+
return typeof value === "number" && Number.isFinite(value) ? value : undefined;
|
|
20
|
+
}
|
|
21
|
+
/** 是有限数字时写入 `target[key]`。 */
|
|
22
|
+
export function putNum(target, key, value) {
|
|
23
|
+
const v = num(value);
|
|
24
|
+
if (v !== undefined)
|
|
25
|
+
target[key] = v;
|
|
26
|
+
}
|
|
27
|
+
/** `ama.trace` 的 data(形状不对返回 undefined)。 */
|
|
28
|
+
export function traceData(entry) {
|
|
29
|
+
if (entry.type !== "custom" || entry.customType !== TRACE_CUSTOM_TYPE)
|
|
30
|
+
return undefined;
|
|
31
|
+
const data = entry.data;
|
|
32
|
+
return isObject(data) && typeof data["kind"] === "string"
|
|
33
|
+
? data
|
|
34
|
+
: undefined;
|
|
35
|
+
}
|
|
36
|
+
export function buildIndex(entries) {
|
|
37
|
+
const index = {
|
|
38
|
+
stepByAssistant: new Map(),
|
|
39
|
+
toolTiming: new Map(),
|
|
40
|
+
subcalls: new Map(),
|
|
41
|
+
compactionByEntry: new Map(),
|
|
42
|
+
auxByUsage: new Map(),
|
|
43
|
+
external: new Map(),
|
|
44
|
+
tasks: new Map(),
|
|
45
|
+
retried: new Set(),
|
|
46
|
+
};
|
|
47
|
+
for (const entry of entries) {
|
|
48
|
+
if (entry.type === "context_edit") {
|
|
49
|
+
if (entry.reason === "retry" || entry.reason === "overflow")
|
|
50
|
+
index.retried.add(entry.targetId);
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
if (entry.type === "custom" && entry.customType === TASK_CUSTOM_TYPE) {
|
|
54
|
+
const data = entry.data;
|
|
55
|
+
// 子会话自己的首条没有 status,不是父会话的快照
|
|
56
|
+
if (!isObject(data) || typeof data["taskId"] !== "string" || data["status"] === undefined)
|
|
57
|
+
continue;
|
|
58
|
+
const parent = typeof data["parentToolCallId"] === "string" ? data["parentToolCallId"] : "";
|
|
59
|
+
const byTask = index.tasks.get(parent) ?? new Map();
|
|
60
|
+
byTask.set(data["taskId"], { data: data, entryId: entry.id });
|
|
61
|
+
index.tasks.set(parent, byTask);
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
const data = traceData(entry);
|
|
65
|
+
if (data === undefined)
|
|
66
|
+
continue;
|
|
67
|
+
switch (data.kind) {
|
|
68
|
+
case "step": {
|
|
69
|
+
if (typeof data.assistantEntryId === "string")
|
|
70
|
+
index.stepByAssistant.set(data.assistantEntryId, { data, entryId: entry.id });
|
|
71
|
+
for (const tool of Array.isArray(data.tools) ? data.tools : []) {
|
|
72
|
+
if (!isObject(tool) || typeof tool.id !== "string")
|
|
73
|
+
continue;
|
|
74
|
+
const known = index.toolTiming.get(tool.id);
|
|
75
|
+
// 同一调用出现两次(中断兜底 + 正常)时留有结束时间的那条
|
|
76
|
+
if (known === undefined || (known.endedAt === undefined && tool.endedAt !== undefined))
|
|
77
|
+
index.toolTiming.set(tool.id, tool);
|
|
78
|
+
}
|
|
79
|
+
for (const sub of Array.isArray(data.subcalls) ? data.subcalls : []) {
|
|
80
|
+
if (!isObject(sub) || typeof sub.id !== "string" || typeof sub.parentId !== "string")
|
|
81
|
+
continue;
|
|
82
|
+
const list = index.subcalls.get(sub.parentId) ?? [];
|
|
83
|
+
if (!list.some((s) => s.data.id === sub.id))
|
|
84
|
+
list.push({ data: sub, entryId: entry.id });
|
|
85
|
+
index.subcalls.set(sub.parentId, list);
|
|
86
|
+
}
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
case "compaction":
|
|
90
|
+
if (typeof data.compactionEntryId === "string")
|
|
91
|
+
index.compactionByEntry.set(data.compactionEntryId, { data, entryId: entry.id });
|
|
92
|
+
break;
|
|
93
|
+
case "aux":
|
|
94
|
+
if (typeof data.usageEntryId === "string")
|
|
95
|
+
index.auxByUsage.set(data.usageEntryId, { data, entryId: entry.id });
|
|
96
|
+
break;
|
|
97
|
+
case "external_turn":
|
|
98
|
+
if (typeof data.taskId === "string") {
|
|
99
|
+
const list = index.external.get(data.taskId) ?? [];
|
|
100
|
+
list.push({ data, entryId: entry.id });
|
|
101
|
+
index.external.set(data.taskId, list);
|
|
102
|
+
}
|
|
103
|
+
break;
|
|
104
|
+
default:
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return index;
|
|
109
|
+
}
|
|
110
|
+
export function zeroUsage() {
|
|
111
|
+
return { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, totalTokens: 0 };
|
|
112
|
+
}
|
|
113
|
+
/** cacheRead / (input + cacheRead + cacheWrite);分母为 0 时 undefined。 */
|
|
114
|
+
export function cacheHitRatio(usage) {
|
|
115
|
+
if (usage === undefined)
|
|
116
|
+
return undefined;
|
|
117
|
+
const prompt = usage.input + usage.cacheRead + usage.cacheWrite;
|
|
118
|
+
return prompt > 0 ? usage.cacheRead / prompt : undefined;
|
|
119
|
+
}
|
|
120
|
+
export function splitRef(ref) {
|
|
121
|
+
if (ref === undefined)
|
|
122
|
+
return { provider: "", model: "" };
|
|
123
|
+
const at = ref.indexOf("/");
|
|
124
|
+
return at < 0
|
|
125
|
+
? { provider: "", model: ref }
|
|
126
|
+
: { provider: ref.slice(0, at), model: ref.slice(at + 1) };
|
|
127
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 轨迹构建器的节点构造(`build.ts` 用):step / tool / subcall / compaction / retry_wait / subagent /
|
|
3
|
+
* external_turn。精确时间来自 `ama.trace`,缺失时按条目时间推算并标 `approx`。[W6-T1]
|
|
4
|
+
*/
|
|
5
|
+
import type { AssistantMessage, Usage } from "../ai/types.js";
|
|
6
|
+
import { type Index, type ScanState, type TaskData } from "./build-index.js";
|
|
7
|
+
import { type TraceAuxNode, type TraceCompactionData, type TraceCompactionNode, type TraceExternalTurnData, type TraceExternalTurnNode, type TraceNodeStatus, type TraceRetryWaitData, type TraceRetryWaitNode, type TraceStepData, type TraceStepNode, type TraceSubagentNode, type TraceToolNode, type TraceTurnNode } from "./types.js";
|
|
8
|
+
export declare function stepStatus(message: AssistantMessage, retried: boolean, data: TraceStepData | undefined): TraceNodeStatus;
|
|
9
|
+
export declare function pushUsage(state: ScanState, turnId: string, usage: Usage): void;
|
|
10
|
+
export declare function assistantStep(entryId: string, m: AssistantMessage, at: number | undefined, turn: TraceTurnNode, state: ScanState, index: Index): TraceStepNode;
|
|
11
|
+
export declare function toolNode(id: string, name: string, assistantEntryId: string, step: TraceStepNode, index: Index): TraceToolNode;
|
|
12
|
+
export declare function compactionNode(id: string, at: number | undefined, trace: {
|
|
13
|
+
data: TraceCompactionData;
|
|
14
|
+
entryId: string;
|
|
15
|
+
} | undefined): TraceCompactionNode;
|
|
16
|
+
export declare function compactionAsAux(node: TraceCompactionNode, usage: Usage | undefined): TraceAuxNode;
|
|
17
|
+
export declare function retryNode(id: string, data: TraceRetryWaitData): TraceRetryWaitNode;
|
|
18
|
+
/** 中断兜底的 step(没有 assistant 条目):请求在途时补一个 aborted 的 step。 */
|
|
19
|
+
export declare function abortedRequest(entryId: string, data: TraceStepData, state: ScanState): void;
|
|
20
|
+
export declare function externalNodes(taskId: string, list: readonly {
|
|
21
|
+
data: TraceExternalTurnData;
|
|
22
|
+
entryId: string;
|
|
23
|
+
}[]): TraceExternalTurnNode[];
|
|
24
|
+
export declare function subagentNode(data: TaskData, entryId: string, live: boolean): TraceSubagentNode;
|