strands-darwin 0.0.3
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/README.md +140 -0
- package/README.zh-CN.md +140 -0
- package/dist/patches/@strands-agents+sdk+1.16.0.patch +1443 -0
- package/dist/src/agent/background-delegation.d.ts +67 -0
- package/dist/src/agent/background-delegation.js +159 -0
- package/dist/src/agent/background-delegation.js.map +1 -0
- package/dist/src/agent/call-stats.d.ts +118 -0
- package/dist/src/agent/call-stats.js +128 -0
- package/dist/src/agent/call-stats.js.map +1 -0
- package/dist/src/agent/compact.d.ts +108 -0
- package/dist/src/agent/compact.js +192 -0
- package/dist/src/agent/compact.js.map +1 -0
- package/dist/src/agent/context-anchor.d.ts +64 -0
- package/dist/src/agent/context-anchor.js +43 -0
- package/dist/src/agent/context-anchor.js.map +1 -0
- package/dist/src/agent/cost.d.ts +56 -0
- package/dist/src/agent/cost.js +44 -0
- package/dist/src/agent/cost.js.map +1 -0
- package/dist/src/agent/diagnostics.d.ts +212 -0
- package/dist/src/agent/diagnostics.js +374 -0
- package/dist/src/agent/diagnostics.js.map +1 -0
- package/dist/src/agent/instructions.d.ts +54 -0
- package/dist/src/agent/instructions.js +118 -0
- package/dist/src/agent/instructions.js.map +1 -0
- package/dist/src/agent/max-tokens-recovery.d.ts +17 -0
- package/dist/src/agent/max-tokens-recovery.js +65 -0
- package/dist/src/agent/max-tokens-recovery.js.map +1 -0
- package/dist/src/agent/model-call-budget.d.ts +8 -0
- package/dist/src/agent/model-call-budget.js +24 -0
- package/dist/src/agent/model-call-budget.js.map +1 -0
- package/dist/src/agent/model-retry.d.ts +134 -0
- package/dist/src/agent/model-retry.js +256 -0
- package/dist/src/agent/model-retry.js.map +1 -0
- package/dist/src/agent/permission-rules.d.ts +47 -0
- package/dist/src/agent/permission-rules.js +260 -0
- package/dist/src/agent/permission-rules.js.map +1 -0
- package/dist/src/agent/permission.d.ts +361 -0
- package/dist/src/agent/permission.js +797 -0
- package/dist/src/agent/permission.js.map +1 -0
- package/dist/src/agent/prompt-cache.d.ts +66 -0
- package/dist/src/agent/prompt-cache.js +194 -0
- package/dist/src/agent/prompt-cache.js.map +1 -0
- package/dist/src/agent/refusal.d.ts +20 -0
- package/dist/src/agent/refusal.js +23 -0
- package/dist/src/agent/refusal.js.map +1 -0
- package/dist/src/agent/retry-guard.d.ts +26 -0
- package/dist/src/agent/retry-guard.js +193 -0
- package/dist/src/agent/retry-guard.js.map +1 -0
- package/dist/src/agent/rewind.d.ts +29 -0
- package/dist/src/agent/rewind.js +118 -0
- package/dist/src/agent/rewind.js.map +1 -0
- package/dist/src/agent/runtime.d.ts +814 -0
- package/dist/src/agent/runtime.js +1596 -0
- package/dist/src/agent/runtime.js.map +1 -0
- package/dist/src/agent/safety-classifier.d.ts +11 -0
- package/dist/src/agent/safety-classifier.js +0 -0
- package/dist/src/agent/safety-classifier.js.map +1 -0
- package/dist/src/agent/sdk-logging.d.ts +49 -0
- package/dist/src/agent/sdk-logging.js +110 -0
- package/dist/src/agent/sdk-logging.js.map +1 -0
- package/dist/src/agent/session.d.ts +102 -0
- package/dist/src/agent/session.js +244 -0
- package/dist/src/agent/session.js.map +1 -0
- package/dist/src/agent/stream-resumption.d.ts +16 -0
- package/dist/src/agent/stream-resumption.js +33 -0
- package/dist/src/agent/stream-resumption.js.map +1 -0
- package/dist/src/agent/system-prompt.d.ts +50 -0
- package/dist/src/agent/system-prompt.js +161 -0
- package/dist/src/agent/system-prompt.js.map +1 -0
- package/dist/src/agent/thinking.d.ts +99 -0
- package/dist/src/agent/thinking.js +145 -0
- package/dist/src/agent/thinking.js.map +1 -0
- package/dist/src/agent/usage.d.ts +132 -0
- package/dist/src/agent/usage.js +233 -0
- package/dist/src/agent/usage.js.map +1 -0
- package/dist/src/agent/working-context.d.ts +51 -0
- package/dist/src/agent/working-context.js +160 -0
- package/dist/src/agent/working-context.js.map +1 -0
- package/dist/src/agents/child-recipe.d.ts +33 -0
- package/dist/src/agents/child-recipe.js +98 -0
- package/dist/src/agents/child-recipe.js.map +1 -0
- package/dist/src/agents/concurrency-limit.d.ts +25 -0
- package/dist/src/agents/concurrency-limit.js +43 -0
- package/dist/src/agents/concurrency-limit.js.map +1 -0
- package/dist/src/agents/dispatch-registry.d.ts +180 -0
- package/dist/src/agents/dispatch-registry.js +289 -0
- package/dist/src/agents/dispatch-registry.js.map +1 -0
- package/dist/src/agents/failed-child-text.d.ts +44 -0
- package/dist/src/agents/failed-child-text.js +69 -0
- package/dist/src/agents/failed-child-text.js.map +1 -0
- package/dist/src/agents/loader.d.ts +26 -0
- package/dist/src/agents/loader.js +134 -0
- package/dist/src/agents/loader.js.map +1 -0
- package/dist/src/agents/report-projection.d.ts +31 -0
- package/dist/src/agents/report-projection.js +125 -0
- package/dist/src/agents/report-projection.js.map +1 -0
- package/dist/src/agents/subagent-tool.d.ts +61 -0
- package/dist/src/agents/subagent-tool.js +180 -0
- package/dist/src/agents/subagent-tool.js.map +1 -0
- package/dist/src/agents/workflow-tool.d.ts +85 -0
- package/dist/src/agents/workflow-tool.js +530 -0
- package/dist/src/agents/workflow-tool.js.map +1 -0
- package/dist/src/cli-args.d.ts +39 -0
- package/dist/src/cli-args.js +198 -0
- package/dist/src/cli-args.js.map +1 -0
- package/dist/src/cli-doctor.d.ts +26 -0
- package/dist/src/cli-doctor.js +398 -0
- package/dist/src/cli-doctor.js.map +1 -0
- package/dist/src/cli-main.d.ts +1 -0
- package/dist/src/cli-main.js +279 -0
- package/dist/src/cli-main.js.map +1 -0
- package/dist/src/cli-sessions.d.ts +17 -0
- package/dist/src/cli-sessions.js +136 -0
- package/dist/src/cli-sessions.js.map +1 -0
- package/dist/src/cli-trajectory.d.ts +37 -0
- package/dist/src/cli-trajectory.js +303 -0
- package/dist/src/cli-trajectory.js.map +1 -0
- package/dist/src/cli-usage.d.ts +18 -0
- package/dist/src/cli-usage.js +53 -0
- package/dist/src/cli-usage.js.map +1 -0
- package/dist/src/cli.d.ts +2 -0
- package/dist/src/cli.js +29 -0
- package/dist/src/cli.js.map +1 -0
- package/dist/src/commands/custom-commands.d.ts +43 -0
- package/dist/src/commands/custom-commands.js +155 -0
- package/dist/src/commands/custom-commands.js.map +1 -0
- package/dist/src/commands/workflow-command.d.ts +26 -0
- package/dist/src/commands/workflow-command.js +56 -0
- package/dist/src/commands/workflow-command.js.map +1 -0
- package/dist/src/config.d.ts +463 -0
- package/dist/src/config.js +1457 -0
- package/dist/src/config.js.map +1 -0
- package/dist/src/context-overflow-error.d.ts +7 -0
- package/dist/src/context-overflow-error.js +26 -0
- package/dist/src/context-overflow-error.js.map +1 -0
- package/dist/src/dev-repl.d.ts +1 -0
- package/dist/src/dev-repl.js +365 -0
- package/dist/src/dev-repl.js.map +1 -0
- package/dist/src/headless-protocol.d.ts +147 -0
- package/dist/src/headless-protocol.js +359 -0
- package/dist/src/headless-protocol.js.map +1 -0
- package/dist/src/headless-runner.d.ts +30 -0
- package/dist/src/headless-runner.js +405 -0
- package/dist/src/headless-runner.js.map +1 -0
- package/dist/src/headless-stdin.d.ts +28 -0
- package/dist/src/headless-stdin.js +78 -0
- package/dist/src/headless-stdin.js.map +1 -0
- package/dist/src/headless.d.ts +106 -0
- package/dist/src/headless.js +229 -0
- package/dist/src/headless.js.map +1 -0
- package/dist/src/hooks/codex-hook-runner.d.ts +92 -0
- package/dist/src/hooks/codex-hook-runner.js +446 -0
- package/dist/src/hooks/codex-hook-runner.js.map +1 -0
- package/dist/src/hooks/codex-hooks.d.ts +23 -0
- package/dist/src/hooks/codex-hooks.js +152 -0
- package/dist/src/hooks/codex-hooks.js.map +1 -0
- package/dist/src/hooks/hook-process.d.ts +23 -0
- package/dist/src/hooks/hook-process.js +241 -0
- package/dist/src/hooks/hook-process.js.map +1 -0
- package/dist/src/hooks/lifecycle-hooks.d.ts +37 -0
- package/dist/src/hooks/lifecycle-hooks.js +153 -0
- package/dist/src/hooks/lifecycle-hooks.js.map +1 -0
- package/dist/src/hooks/tool-hooks.d.ts +63 -0
- package/dist/src/hooks/tool-hooks.js +350 -0
- package/dist/src/hooks/tool-hooks.js.map +1 -0
- package/dist/src/mcp/codegraph-preflight.d.ts +29 -0
- package/dist/src/mcp/codegraph-preflight.js +232 -0
- package/dist/src/mcp/codegraph-preflight.js.map +1 -0
- package/dist/src/mcp/registry.d.ts +133 -0
- package/dist/src/mcp/registry.js +209 -0
- package/dist/src/mcp/registry.js.map +1 -0
- package/dist/src/mcp/web-search-empty-results.d.ts +14 -0
- package/dist/src/mcp/web-search-empty-results.js +94 -0
- package/dist/src/mcp/web-search-empty-results.js.map +1 -0
- package/dist/src/memory/command.d.ts +11 -0
- package/dist/src/memory/command.js +253 -0
- package/dist/src/memory/command.js.map +1 -0
- package/dist/src/memory/controller.d.ts +51 -0
- package/dist/src/memory/controller.js +316 -0
- package/dist/src/memory/controller.js.map +1 -0
- package/dist/src/memory/prompt.d.ts +4 -0
- package/dist/src/memory/prompt.js +22 -0
- package/dist/src/memory/prompt.js.map +1 -0
- package/dist/src/memory/scheduler.d.ts +33 -0
- package/dist/src/memory/scheduler.js +134 -0
- package/dist/src/memory/scheduler.js.map +1 -0
- package/dist/src/memory/state.d.ts +112 -0
- package/dist/src/memory/state.js +355 -0
- package/dist/src/memory/state.js.map +1 -0
- package/dist/src/memory/store.d.ts +19 -0
- package/dist/src/memory/store.js +130 -0
- package/dist/src/memory/store.js.map +1 -0
- package/dist/src/memory/tools.d.ts +29 -0
- package/dist/src/memory/tools.js +22 -0
- package/dist/src/memory/tools.js.map +1 -0
- package/dist/src/memory/validation.d.ts +33 -0
- package/dist/src/memory/validation.js +159 -0
- package/dist/src/memory/validation.js.map +1 -0
- package/dist/src/npm-package/generate-patch.d.ts +23 -0
- package/dist/src/npm-package/generate-patch.js +88 -0
- package/dist/src/npm-package/generate-patch.js.map +1 -0
- package/dist/src/npm-package/patch-package-format.d.ts +43 -0
- package/dist/src/npm-package/patch-package-format.js +66 -0
- package/dist/src/npm-package/patch-package-format.js.map +1 -0
- package/dist/src/paths.d.ts +39 -0
- package/dist/src/paths.js +105 -0
- package/dist/src/paths.js.map +1 -0
- package/dist/src/pricing/cost.d.ts +182 -0
- package/dist/src/pricing/cost.js +215 -0
- package/dist/src/pricing/cost.js.map +1 -0
- package/dist/src/pricing/model-prices.d.ts +112 -0
- package/dist/src/pricing/model-prices.js +320 -0
- package/dist/src/pricing/model-prices.js.map +1 -0
- package/dist/src/sdk-patch-preflight.d.ts +23 -0
- package/dist/src/sdk-patch-preflight.js +71 -0
- package/dist/src/sdk-patch-preflight.js.map +1 -0
- package/dist/src/skills/builtin/commit-message/SKILL.md +45 -0
- package/dist/src/skills/builtin/commit-message/references/types.md +8 -0
- package/dist/src/skills/builtin/developer/SKILL.md +107 -0
- package/dist/src/skills/builtin/self-evolution-research/SKILL.md +150 -0
- package/dist/src/skills/builtin/self-evolution-research/scripts/roll-research-path.mjs +208 -0
- package/dist/src/skills/builtin/self-reflection/SKILL.md +172 -0
- package/dist/src/skills/builtin/self-reflection/references/reflection-template.md +90 -0
- package/dist/src/skills/builtin/self-reflection/scripts/locate-trajectory.mjs +175 -0
- package/dist/src/skills/loader.d.ts +26 -0
- package/dist/src/skills/loader.js +186 -0
- package/dist/src/skills/loader.js.map +1 -0
- package/dist/src/skills/plugin.d.ts +34 -0
- package/dist/src/skills/plugin.js +137 -0
- package/dist/src/skills/plugin.js.map +1 -0
- package/dist/src/skills/prompt.d.ts +8 -0
- package/dist/src/skills/prompt.js +214 -0
- package/dist/src/skills/prompt.js.map +1 -0
- package/dist/src/skills/resource-safety.d.ts +15 -0
- package/dist/src/skills/resource-safety.js +149 -0
- package/dist/src/skills/resource-safety.js.map +1 -0
- package/dist/src/tools/background-bash.d.ts +95 -0
- package/dist/src/tools/background-bash.js +639 -0
- package/dist/src/tools/background-bash.js.map +1 -0
- package/dist/src/tools/background-tail.d.ts +28 -0
- package/dist/src/tools/background-tail.js +75 -0
- package/dist/src/tools/background-tail.js.map +1 -0
- package/dist/src/tools/background-wait-contract.d.ts +4 -0
- package/dist/src/tools/background-wait-contract.js +7 -0
- package/dist/src/tools/background-wait-contract.js.map +1 -0
- package/dist/src/tools/file-editor-serial.d.ts +24 -0
- package/dist/src/tools/file-editor-serial.js +99 -0
- package/dist/src/tools/file-editor-serial.js.map +1 -0
- package/dist/src/tools/image-viewer.d.ts +43 -0
- package/dist/src/tools/image-viewer.js +256 -0
- package/dist/src/tools/image-viewer.js.map +1 -0
- package/dist/src/tools/update-plan.d.ts +30 -0
- package/dist/src/tools/update-plan.js +65 -0
- package/dist/src/tools/update-plan.js.map +1 -0
- package/dist/src/tools/web-fetch.d.ts +70 -0
- package/dist/src/tools/web-fetch.js +667 -0
- package/dist/src/tools/web-fetch.js.map +1 -0
- package/dist/src/trajectory/export.d.ts +31 -0
- package/dist/src/trajectory/export.js +116 -0
- package/dist/src/trajectory/export.js.map +1 -0
- package/dist/src/trajectory/fork.d.ts +19 -0
- package/dist/src/trajectory/fork.js +110 -0
- package/dist/src/trajectory/fork.js.map +1 -0
- package/dist/src/trajectory/memory-tool.d.ts +20 -0
- package/dist/src/trajectory/memory-tool.js +98 -0
- package/dist/src/trajectory/memory-tool.js.map +1 -0
- package/dist/src/trajectory/prompt-history.d.ts +62 -0
- package/dist/src/trajectory/prompt-history.js +256 -0
- package/dist/src/trajectory/prompt-history.js.map +1 -0
- package/dist/src/trajectory/reader.d.ts +21 -0
- package/dist/src/trajectory/reader.js +62 -0
- package/dist/src/trajectory/reader.js.map +1 -0
- package/dist/src/trajectory/record.d.ts +417 -0
- package/dist/src/trajectory/record.js +394 -0
- package/dist/src/trajectory/record.js.map +1 -0
- package/dist/src/trajectory/replay.d.ts +74 -0
- package/dist/src/trajectory/replay.js +285 -0
- package/dist/src/trajectory/replay.js.map +1 -0
- package/dist/src/trajectory/resume-recap.d.ts +43 -0
- package/dist/src/trajectory/resume-recap.js +68 -0
- package/dist/src/trajectory/resume-recap.js.map +1 -0
- package/dist/src/trajectory/search.d.ts +40 -0
- package/dist/src/trajectory/search.js +127 -0
- package/dist/src/trajectory/search.js.map +1 -0
- package/dist/src/trajectory/spend.d.ts +157 -0
- package/dist/src/trajectory/spend.js +264 -0
- package/dist/src/trajectory/spend.js.map +1 -0
- package/dist/src/trajectory/stream.d.ts +30 -0
- package/dist/src/trajectory/stream.js +30 -0
- package/dist/src/trajectory/stream.js.map +1 -0
- package/dist/src/trajectory/writer.d.ts +310 -0
- package/dist/src/trajectory/writer.js +636 -0
- package/dist/src/trajectory/writer.js.map +1 -0
- package/dist/src/tui/App.d.ts +109 -0
- package/dist/src/tui/App.js +2660 -0
- package/dist/src/tui/App.js.map +1 -0
- package/dist/src/tui/InputBox.d.ts +90 -0
- package/dist/src/tui/InputBox.js +129 -0
- package/dist/src/tui/InputBox.js.map +1 -0
- package/dist/src/tui/MarkdownText.d.ts +16 -0
- package/dist/src/tui/MarkdownText.js +117 -0
- package/dist/src/tui/MarkdownText.js.map +1 -0
- package/dist/src/tui/MessageList.d.ts +27 -0
- package/dist/src/tui/MessageList.js +61 -0
- package/dist/src/tui/MessageList.js.map +1 -0
- package/dist/src/tui/PermissionPrompt.d.ts +18 -0
- package/dist/src/tui/PermissionPrompt.js +114 -0
- package/dist/src/tui/PermissionPrompt.js.map +1 -0
- package/dist/src/tui/PlanChecklist.d.ts +7 -0
- package/dist/src/tui/PlanChecklist.js +12 -0
- package/dist/src/tui/PlanChecklist.js.map +1 -0
- package/dist/src/tui/QueuedMessages.d.ts +8 -0
- package/dist/src/tui/QueuedMessages.js +24 -0
- package/dist/src/tui/QueuedMessages.js.map +1 -0
- package/dist/src/tui/StartupScreen.d.ts +25 -0
- package/dist/src/tui/StartupScreen.js +51 -0
- package/dist/src/tui/StartupScreen.js.map +1 -0
- package/dist/src/tui/ToolCallPanel.d.ts +33 -0
- package/dist/src/tui/ToolCallPanel.js +112 -0
- package/dist/src/tui/ToolCallPanel.js.map +1 -0
- package/dist/src/tui/WelcomeHeader.d.ts +30 -0
- package/dist/src/tui/WelcomeHeader.js +69 -0
- package/dist/src/tui/WelcomeHeader.js.map +1 -0
- package/dist/src/tui/background-tool-presentation.d.ts +22 -0
- package/dist/src/tui/background-tool-presentation.js +209 -0
- package/dist/src/tui/background-tool-presentation.js.map +1 -0
- package/dist/src/tui/busy-suffix.d.ts +37 -0
- package/dist/src/tui/busy-suffix.js +39 -0
- package/dist/src/tui/busy-suffix.js.map +1 -0
- package/dist/src/tui/clipboard-image.d.ts +18 -0
- package/dist/src/tui/clipboard-image.js +109 -0
- package/dist/src/tui/clipboard-image.js.map +1 -0
- package/dist/src/tui/context-format.d.ts +43 -0
- package/dist/src/tui/context-format.js +71 -0
- package/dist/src/tui/context-format.js.map +1 -0
- package/dist/src/tui/copy-command.d.ts +68 -0
- package/dist/src/tui/copy-command.js +182 -0
- package/dist/src/tui/copy-command.js.map +1 -0
- package/dist/src/tui/edit-diff.d.ts +135 -0
- package/dist/src/tui/edit-diff.js +356 -0
- package/dist/src/tui/edit-diff.js.map +1 -0
- package/dist/src/tui/frame-budget.d.ts +351 -0
- package/dist/src/tui/frame-budget.js +446 -0
- package/dist/src/tui/frame-budget.js.map +1 -0
- package/dist/src/tui/help-format.d.ts +17 -0
- package/dist/src/tui/help-format.js +38 -0
- package/dist/src/tui/help-format.js.map +1 -0
- package/dist/src/tui/live-text.d.ts +51 -0
- package/dist/src/tui/live-text.js +154 -0
- package/dist/src/tui/live-text.js.map +1 -0
- package/dist/src/tui/markdown.d.ts +62 -0
- package/dist/src/tui/markdown.js +244 -0
- package/dist/src/tui/markdown.js.map +1 -0
- package/dist/src/tui/mcp-format.d.ts +28 -0
- package/dist/src/tui/mcp-format.js +67 -0
- package/dist/src/tui/mcp-format.js.map +1 -0
- package/dist/src/tui/path-completion.d.ts +119 -0
- package/dist/src/tui/path-completion.js +305 -0
- package/dist/src/tui/path-completion.js.map +1 -0
- package/dist/src/tui/permission-queue.d.ts +61 -0
- package/dist/src/tui/permission-queue.js +129 -0
- package/dist/src/tui/permission-queue.js.map +1 -0
- package/dist/src/tui/plan-format.d.ts +9 -0
- package/dist/src/tui/plan-format.js +30 -0
- package/dist/src/tui/plan-format.js.map +1 -0
- package/dist/src/tui/prompt-completion.d.ts +22 -0
- package/dist/src/tui/prompt-completion.js +46 -0
- package/dist/src/tui/prompt-completion.js.map +1 -0
- package/dist/src/tui/prompt-editor.d.ts +102 -0
- package/dist/src/tui/prompt-editor.js +379 -0
- package/dist/src/tui/prompt-editor.js.map +1 -0
- package/dist/src/tui/prompt-history-search.d.ts +53 -0
- package/dist/src/tui/prompt-history-search.js +123 -0
- package/dist/src/tui/prompt-history-search.js.map +1 -0
- package/dist/src/tui/prompt-queue.d.ts +58 -0
- package/dist/src/tui/prompt-queue.js +74 -0
- package/dist/src/tui/prompt-queue.js.map +1 -0
- package/dist/src/tui/prompt-recall.d.ts +74 -0
- package/dist/src/tui/prompt-recall.js +90 -0
- package/dist/src/tui/prompt-recall.js.map +1 -0
- package/dist/src/tui/react-environment.d.ts +11 -0
- package/dist/src/tui/react-environment.js +24 -0
- package/dist/src/tui/react-environment.js.map +1 -0
- package/dist/src/tui/rewind-search.d.ts +34 -0
- package/dist/src/tui/rewind-search.js +68 -0
- package/dist/src/tui/rewind-search.js.map +1 -0
- package/dist/src/tui/shell-command.d.ts +114 -0
- package/dist/src/tui/shell-command.js +310 -0
- package/dist/src/tui/shell-command.js.map +1 -0
- package/dist/src/tui/spend-advisory.d.ts +52 -0
- package/dist/src/tui/spend-advisory.js +64 -0
- package/dist/src/tui/spend-advisory.js.map +1 -0
- package/dist/src/tui/status-format.d.ts +120 -0
- package/dist/src/tui/status-format.js +192 -0
- package/dist/src/tui/status-format.js.map +1 -0
- package/dist/src/tui/subagent-format.d.ts +49 -0
- package/dist/src/tui/subagent-format.js +146 -0
- package/dist/src/tui/subagent-format.js.map +1 -0
- package/dist/src/tui/task-format.d.ts +29 -0
- package/dist/src/tui/task-format.js +87 -0
- package/dist/src/tui/task-format.js.map +1 -0
- package/dist/src/tui/terminal-bell.d.ts +20 -0
- package/dist/src/tui/terminal-bell.js +33 -0
- package/dist/src/tui/terminal-bell.js.map +1 -0
- package/dist/src/tui/tool-detail-presentation.d.ts +60 -0
- package/dist/src/tui/tool-detail-presentation.js +206 -0
- package/dist/src/tui/tool-detail-presentation.js.map +1 -0
- package/dist/src/tui/turn-state.d.ts +195 -0
- package/dist/src/tui/turn-state.js +548 -0
- package/dist/src/tui/turn-state.js.map +1 -0
- package/dist/src/tui/visual-language.d.ts +45 -0
- package/dist/src/tui/visual-language.js +57 -0
- package/dist/src/tui/visual-language.js.map +1 -0
- package/dist/src/version.d.ts +7 -0
- package/dist/src/version.js +38 -0
- package/dist/src/version.js.map +1 -0
- package/package.json +60 -0
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Replay: a recorded trajectory read back as the history it produced.
|
|
3
|
+
*
|
|
4
|
+
* The one rule that matters here is that replay does **not** own a projection.
|
|
5
|
+
* Records are turned back into `TurnAction`s and fed through the same
|
|
6
|
+
* `turnReducer` the live TUI uses, so live rendering and replay cannot drift into
|
|
7
|
+
* two different readings of the same events. What replay guarantees, and the nine
|
|
8
|
+
* things it explicitly does not reproduce, are written down in
|
|
9
|
+
* `docs/architecture/load-bearing-decisions.md` § Session trajectory.
|
|
10
|
+
*
|
|
11
|
+
* This module imports no `Agent`, no `Model` and nothing from `src/agent/runtime.ts`:
|
|
12
|
+
* replay makes zero model calls by construction, not by discipline.
|
|
13
|
+
*/
|
|
14
|
+
import { contentBlockFromData } from '@strands-agents/sdk';
|
|
15
|
+
import { initialTurnState, turnReducer } from '../tui/turn-state.js';
|
|
16
|
+
import { describeDamage } from './reader.js';
|
|
17
|
+
import { formatTurnFailure, turnFailureOf, } from './record.js';
|
|
18
|
+
import { formatModelCall, formatModelSpend, formatSessionCost, formatSpendFields, formatTurnSpend, modelCallEntries, priceSpend, summarizeSpend, turnSpendEntries, } from './spend.js';
|
|
19
|
+
/**
|
|
20
|
+
* Rebuilds history from records.
|
|
21
|
+
*
|
|
22
|
+
* Pure over its input: the same records always produce the same history, which is
|
|
23
|
+
* what makes replay quotable. History item `id`s come from a module counter in
|
|
24
|
+
* `turn-state.ts` and are process-local by construction, so comparisons against a
|
|
25
|
+
* live run must ignore them — see {@link historyWithoutIds}.
|
|
26
|
+
*/
|
|
27
|
+
export function replayRecords(records, options = {}) {
|
|
28
|
+
let state = initialTurnState;
|
|
29
|
+
const turns = new Set();
|
|
30
|
+
const runs = [];
|
|
31
|
+
const failures = [];
|
|
32
|
+
// Collected as the loop passes them, so a `--turn` replay reports that turn's spend
|
|
33
|
+
// rather than the file's: the history it prints is filtered the same way, and a total
|
|
34
|
+
// covering turns it did not show would describe a different report.
|
|
35
|
+
const closed = [];
|
|
36
|
+
// Same collection discipline as `closed`: a `--turn` replay reports only the calls
|
|
37
|
+
// of the turn it shows.
|
|
38
|
+
const modelCalls = [];
|
|
39
|
+
let droppedRecords = 0;
|
|
40
|
+
for (const record of records) {
|
|
41
|
+
if (record.turn > 0)
|
|
42
|
+
turns.add(record.turn);
|
|
43
|
+
if (options.turn !== undefined && record.turn !== options.turn && record.type !== 'runStarted') {
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
switch (record.type) {
|
|
47
|
+
case 'runStarted':
|
|
48
|
+
runs.push({
|
|
49
|
+
turn: record.turn,
|
|
50
|
+
session: record.session,
|
|
51
|
+
model: `${record.provider}/${record.model}`,
|
|
52
|
+
at: record.t,
|
|
53
|
+
resumed: record.resumed,
|
|
54
|
+
});
|
|
55
|
+
continue;
|
|
56
|
+
case 'userInput':
|
|
57
|
+
state = turnReducer(state, { type: 'userInput', text: record.text });
|
|
58
|
+
continue;
|
|
59
|
+
case 'shellCommand':
|
|
60
|
+
// A `!` command replays as exactly the two things the live session showed:
|
|
61
|
+
// the user row (`!command`, the normalized draft the TUI echoed) and the
|
|
62
|
+
// finished pseudo-tool row, composed by the same reducer case from the same
|
|
63
|
+
// recorded fields — printed, not skipped, because the transcript claims to
|
|
64
|
+
// be what happened and a shell command happened.
|
|
65
|
+
state = turnReducer(state, { type: 'userInput', text: `!${record.command}` });
|
|
66
|
+
state = turnReducer(state, {
|
|
67
|
+
type: 'shellCommand',
|
|
68
|
+
command: record.command,
|
|
69
|
+
exitCode: record.exitCode,
|
|
70
|
+
signal: record.signal,
|
|
71
|
+
timedOut: record.timedOut,
|
|
72
|
+
durationMs: record.durationMs,
|
|
73
|
+
output: record.output,
|
|
74
|
+
});
|
|
75
|
+
continue;
|
|
76
|
+
case 'contentBlockEvent':
|
|
77
|
+
case 'beforeToolCallEvent':
|
|
78
|
+
case 'afterToolCallEvent':
|
|
79
|
+
case 'agentResultEvent': {
|
|
80
|
+
const event = asStreamEvent(record);
|
|
81
|
+
if (event === undefined) {
|
|
82
|
+
droppedRecords += 1;
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
state = turnReducer(state, { type: 'streamEvent', event });
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
case 'turnEnded':
|
|
89
|
+
closed.push(record);
|
|
90
|
+
// The recorded partial text is what live history received from
|
|
91
|
+
// `flushLiveText` when a turn ended with unassembled deltas — normally a
|
|
92
|
+
// cancelled turn. Replayed as live text so the same flush produces it.
|
|
93
|
+
if (record.partialText !== undefined) {
|
|
94
|
+
state = { ...state, liveText: record.partialText };
|
|
95
|
+
}
|
|
96
|
+
{
|
|
97
|
+
// A failed turn reproduces the notice the TUI already appends in
|
|
98
|
+
// `runTurn` — the same text, the same severity, and before `turnEnded`,
|
|
99
|
+
// because `notice` does not flush live text and the live order is
|
|
100
|
+
// notice-then-flush. Replaying it as history rather than inventing a
|
|
101
|
+
// replay-only line is what keeps one reducer and one projection: a failed
|
|
102
|
+
// turn replays as the history it actually produced. The error's *class*
|
|
103
|
+
// is not in that notice (the live one never had it), so it is reported
|
|
104
|
+
// separately, in {@link formatReplay} and in `failures`.
|
|
105
|
+
const failure = turnFailureOf(record);
|
|
106
|
+
if (failure !== undefined) {
|
|
107
|
+
failures.push({ turn: record.turn, ...failure });
|
|
108
|
+
state = turnReducer(state, {
|
|
109
|
+
type: 'notice',
|
|
110
|
+
text: `turn failed: ${failure.message}`,
|
|
111
|
+
severity: 'error',
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
state = turnReducer(state, { type: 'turnEnded' });
|
|
116
|
+
continue;
|
|
117
|
+
case 'modelCall':
|
|
118
|
+
// No history item: the live TUI never drew a row for a completed model call,
|
|
119
|
+
// and replay must not invent one. The record surfaces as the bounded
|
|
120
|
+
// per-call lines `formatReplay` appends beside the spend report.
|
|
121
|
+
modelCalls.push(record);
|
|
122
|
+
continue;
|
|
123
|
+
case 'forkedFrom':
|
|
124
|
+
case 'recordingStopped':
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
const spend = summarizeSpend(closed);
|
|
129
|
+
return {
|
|
130
|
+
history: state.history,
|
|
131
|
+
turns: [...turns].sort((a, b) => a - b),
|
|
132
|
+
runs,
|
|
133
|
+
droppedRecords,
|
|
134
|
+
failures,
|
|
135
|
+
turnSpend: turnSpendEntries(closed),
|
|
136
|
+
modelCalls: modelCallEntries(modelCalls),
|
|
137
|
+
spend,
|
|
138
|
+
...(options.prices !== undefined && spend.turnsWithSpend > 0 && { cost: priceSpend(spend, options.prices) }),
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
/** Replays a file the reader has already opened, carrying its damage report along. */
|
|
142
|
+
export function replayRead(read, options = {}) {
|
|
143
|
+
return { ...replayRecords(read.records, options), damage: describeDamage(read) };
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* A record's payload as the stream event the reducer expects.
|
|
147
|
+
*
|
|
148
|
+
* The payload is the SDK event's own `toJSON()` output, which is the **wire** shape,
|
|
149
|
+
* not the in-memory one: measured on 1.12.0, a text block serializes as
|
|
150
|
+
* `{"text":"…"}` with no `type` discriminator, and a tool result as
|
|
151
|
+
* `{"toolResult":{status,content}}`. Feeding that straight to `turnReducer` silently
|
|
152
|
+
* renders nothing (and crashes on the tool result, whose `content` is one level
|
|
153
|
+
* deeper than it looks). So content blocks are rehydrated through the SDK's own
|
|
154
|
+
* `contentBlockFromData` — the mirror of the `toJSON()` used to write them, and the
|
|
155
|
+
* one deserializer that stays correct when the SDK adds a block type.
|
|
156
|
+
*
|
|
157
|
+
* A record whose payload a cap replaced (`dropped: 'record-too-large'`), or whose
|
|
158
|
+
* block shape this SDK version cannot rebuild, has no event to give back and is
|
|
159
|
+
* counted instead: replay never invents the content a cap removed, and a single
|
|
160
|
+
* unreadable record must not end a replay.
|
|
161
|
+
*/
|
|
162
|
+
function asStreamEvent(record) {
|
|
163
|
+
const data = record.data;
|
|
164
|
+
if (data === null || typeof data !== 'object')
|
|
165
|
+
return undefined;
|
|
166
|
+
const payload = data;
|
|
167
|
+
try {
|
|
168
|
+
switch (record.type) {
|
|
169
|
+
case 'contentBlockEvent': {
|
|
170
|
+
if (payload['contentBlock'] === undefined)
|
|
171
|
+
return undefined;
|
|
172
|
+
return {
|
|
173
|
+
type: 'contentBlockEvent',
|
|
174
|
+
contentBlock: contentBlockFromData(payload['contentBlock']),
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
case 'afterToolCallEvent': {
|
|
178
|
+
if (payload['toolUse'] === undefined || payload['result'] === undefined)
|
|
179
|
+
return undefined;
|
|
180
|
+
return {
|
|
181
|
+
type: 'afterToolCallEvent',
|
|
182
|
+
toolUse: payload['toolUse'],
|
|
183
|
+
result: contentBlockFromData(payload['result']),
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
case 'beforeToolCallEvent': {
|
|
187
|
+
if (payload['toolUse'] === undefined)
|
|
188
|
+
return undefined;
|
|
189
|
+
// Already the shape the reducer reads: name, toolUseId and assembled input.
|
|
190
|
+
return { type: 'beforeToolCallEvent', toolUse: payload['toolUse'] };
|
|
191
|
+
}
|
|
192
|
+
default:
|
|
193
|
+
// `agentResultEvent` and anything a newer darwin recorded: the reducer
|
|
194
|
+
// ignores what it does not know, exactly as it does live.
|
|
195
|
+
return { ...payload, type: record.type };
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
catch {
|
|
199
|
+
return undefined;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
/** History with the process-local ids removed, for comparing a replay to a live run. */
|
|
203
|
+
export function historyWithoutIds(history) {
|
|
204
|
+
return history.map((item) => {
|
|
205
|
+
const { id: _id, ...rest } = item;
|
|
206
|
+
return rest;
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
/** Plain-text transcript: content, deliberately not an imitation of the Ink frame. */
|
|
210
|
+
export function formatReplay(result) {
|
|
211
|
+
const lines = [];
|
|
212
|
+
for (const run of result.runs) {
|
|
213
|
+
lines.push(`--- run ${run.at} · ${run.model}${run.resumed ? ' · resumed' : ''}`);
|
|
214
|
+
}
|
|
215
|
+
for (const item of result.history) {
|
|
216
|
+
switch (item.kind) {
|
|
217
|
+
case 'user':
|
|
218
|
+
lines.push(`you> ${item.text}`);
|
|
219
|
+
break;
|
|
220
|
+
case 'assistant':
|
|
221
|
+
// One `darwin>` per answer, not per piece: a streamed answer reaches history
|
|
222
|
+
// in several entries (`turn-state.ts`), and replaying it as several replies
|
|
223
|
+
// would be a different transcript from the one the session showed. An empty
|
|
224
|
+
// closing piece is the blank row a live frame owes and a replay does not.
|
|
225
|
+
if (item.text === '')
|
|
226
|
+
break;
|
|
227
|
+
lines.push(item.part === 'whole' || item.part === 'first' ? `darwin> ${item.text}` : item.text);
|
|
228
|
+
break;
|
|
229
|
+
case 'tool':
|
|
230
|
+
lines.push(` tool ${item.name} [${item.status}] ${item.summary}`);
|
|
231
|
+
if (item.preview !== '') {
|
|
232
|
+
for (const previewLine of item.preview.split('\n'))
|
|
233
|
+
lines.push(` ${previewLine}`);
|
|
234
|
+
}
|
|
235
|
+
break;
|
|
236
|
+
case 'notice':
|
|
237
|
+
lines.push(` note ${item.text}`);
|
|
238
|
+
break;
|
|
239
|
+
case 'plan':
|
|
240
|
+
// TUI-only final Static projection. Replay retains the ordinary
|
|
241
|
+
// update_plan tool call/result row as its sole durable evidence.
|
|
242
|
+
break;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
if (result.history.length === 0)
|
|
246
|
+
lines.push('(the record contains no replayable history)');
|
|
247
|
+
if (result.droppedRecords > 0) {
|
|
248
|
+
lines.push(` ${result.droppedRecords} record(s) had their payload removed by a size cap`);
|
|
249
|
+
}
|
|
250
|
+
// The class name, which the reconstructed notice above cannot carry because the
|
|
251
|
+
// live notice it mirrors never carried one. Bounded like the `list` summary, since
|
|
252
|
+
// the message itself is already in the notice line, in full.
|
|
253
|
+
for (const failure of result.failures) {
|
|
254
|
+
lines.push(` turn ${failure.turn} failed: ${formatTurnFailure(failure)}`);
|
|
255
|
+
}
|
|
256
|
+
// The call-level reading first, one bounded line per completed model call, so a
|
|
257
|
+
// reader can see *which* call of a multi-cycle turn grew the context before the
|
|
258
|
+
// per-turn totals summarize it. Absent for files that predate the record type,
|
|
259
|
+
// which keeps their transcript (and `/export`) byte-identical.
|
|
260
|
+
for (const call of result.modelCalls)
|
|
261
|
+
lines.push(` ${formatModelCall(call)}`);
|
|
262
|
+
// What it cost, at the one verbosity a transcript can afford it: one bounded line per
|
|
263
|
+
// turn — including the turns nothing measured, because a report that quietly omitted
|
|
264
|
+
// them would read as a cheaper session — then the file's total. The per-model
|
|
265
|
+
// breakdown appears only when a total would otherwise mix two price lists. Money
|
|
266
|
+
// follows the tokens on the same rules, only when the caller priced the result:
|
|
267
|
+
// one `session cost:` line, and each model's own figure beside its token row.
|
|
268
|
+
for (const entry of result.turnSpend)
|
|
269
|
+
lines.push(` ${formatTurnSpend(entry)}`);
|
|
270
|
+
if (result.turnSpend.length > 0) {
|
|
271
|
+
const spend = result.spend;
|
|
272
|
+
const unknown = spend.turnsUnknown === 0 ? '' : `, ${spend.turnsUnknown} unknown`;
|
|
273
|
+
lines.push(spend.turnsWithSpend === 0
|
|
274
|
+
? ` session spend: unknown over ${spend.turnsUnknown} turn(s)`
|
|
275
|
+
: ` session spend: ${formatSpendFields(spend)} over ${spend.turnsWithSpend} turn(s)${unknown}`);
|
|
276
|
+
if (result.cost !== undefined)
|
|
277
|
+
lines.push(` ${formatSessionCost(result.cost)}`);
|
|
278
|
+
if (spend.models.length > 1) {
|
|
279
|
+
for (const model of spend.models)
|
|
280
|
+
lines.push(` ${formatModelSpend(model, result.cost)}`);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
return lines.join('\n');
|
|
284
|
+
}
|
|
285
|
+
//# sourceMappingURL=replay.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"replay.js","sourceRoot":"","sources":["../../../src/trajectory/replay.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,oBAAoB,EAAyB,MAAM,qBAAqB,CAAC;AAElF,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAoB,MAAM,sBAAsB,CAAC;AACvF,OAAO,EAAE,cAAc,EAA6B,MAAM,aAAa,CAAC;AACxE,OAAO,EACL,iBAAiB,EACjB,aAAa,GAMd,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,iBAAiB,EACjB,iBAAiB,EACjB,eAAe,EACf,gBAAgB,EAChB,UAAU,EACV,cAAc,EACd,gBAAgB,GAIjB,MAAM,YAAY,CAAC;AAmDpB;;;;;;;GAOG;AACH,MAAM,UAAU,aAAa,CAC3B,OAAoC,EACpC,OAAO,GAAkB,EAAE;IAE3B,IAAI,KAAK,GAAG,gBAAgB,CAAC;IAC7B,MAAM,KAAK,GAAG,IAAI,GAAG,EAAU,CAAC;IAChC,MAAM,IAAI,GAAyB,EAAE,CAAC;IACtC,MAAM,QAAQ,GAA6B,EAAE,CAAC;IAC9C,oFAAoF;IACpF,sFAAsF;IACtF,oEAAoE;IACpE,MAAM,MAAM,GAAsB,EAAE,CAAC;IACrC,mFAAm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;IACrF,8EAA8E;IAC9E,iFAAiF;IACjF,gFAAgF;IAChF,8EAA8E;IAC9E,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,SAAS;QAAE,KAAK,CAAC,IAAI,CAAC,KAAK,eAAe,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IAChF,IAAI,MAAM,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAChC,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;QAC3B,MAAM,OAAO,GAAG,KAAK,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,KAAK,CAAC,YAAY,UAAU,CAAC;QAClF,KAAK,CAAC,IAAI,CACR,KAAK,CAAC,cAAc,KAAK,CAAC;YACxB,CAAC,CAAC,iCAAiC,KAAK,CAAC,YAAY,UAAU;YAC/D,CAAC,CAAC,oBAAoB,iBAAiB,CAAC,KAAK,CAAC,SAAS,KAAK,CAAC,cAAc,WAAW,OAAO,EAAE,CAClG,CAAC;QACF,IAAI,MAAM,CAAC,IAAI,KAAK,SAAS;YAAE,KAAK,CAAC,IAAI,CAAC,KAAK,iBAAiB,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACjF,IAAI,KAAK,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC5B,KAAK,MAAM,KAAK,IAAI,KAAK,CAAC,MAAM;gBAAE,KAAK,CAAC,IAAI,CAAC,OAAO,gBAAgB,CAAC,KAAK,EAAE,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC9F,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Full human transcript for an interactively resumed session.
|
|
3
|
+
*
|
|
4
|
+
* This is a read-only derivative of trajectory replay: it opens one existing file,
|
|
5
|
+
* reconstructs the whole recorded transcript through the ordinary reducer
|
|
6
|
+
* (`replayRecords`, the same projection `/export` and `trajectory replay` use), and
|
|
7
|
+
* returns only display history. It imports no runtime, Agent, Model, session manager
|
|
8
|
+
* or writer, so loading a recap cannot call a provider or participate in the
|
|
9
|
+
* conversation.
|
|
10
|
+
*
|
|
11
|
+
* There is deliberately no size cap: measured on a 1.2 MiB / 2,801-record fixture,
|
|
12
|
+
* `replayRecords` reconstructs the transcript in ~12 ms, and the seeded items are
|
|
13
|
+
* written to terminal scrollback exactly once (`<Static>`), so startup scrollback
|
|
14
|
+
* length simply equals session length. History item ids come from the same
|
|
15
|
+
* process-local `nextId` counter the live session uses, so seeded and later live
|
|
16
|
+
* rows can never collide; the recap's own notices use a distinct `resume-recap-`
|
|
17
|
+
* namespace.
|
|
18
|
+
*/
|
|
19
|
+
import type { HistoryItem } from '../tui/turn-state.js';
|
|
20
|
+
import type { TrajectoryRecord } from './record.js';
|
|
21
|
+
export interface ResumeRecapOptions {
|
|
22
|
+
/** Exact resolved session trajectory; path ownership stays in `agent/session.ts`. */
|
|
23
|
+
file: string;
|
|
24
|
+
/** Number read from the already-restored Agent; reported, never modified. */
|
|
25
|
+
restoredMessages: number;
|
|
26
|
+
/** False when this run cannot append future trajectory records. */
|
|
27
|
+
trajectoryEnabled: boolean;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Reads one exact session's record and projects its full replayed transcript.
|
|
31
|
+
*
|
|
32
|
+
* Every failure is returned as startup history rather than thrown: an absent record
|
|
33
|
+
* is normal for sessions created before trajectory recording or while it was off.
|
|
34
|
+
*/
|
|
35
|
+
export declare function loadResumeRecap(options: ResumeRecapOptions): Promise<HistoryItem[]>;
|
|
36
|
+
interface ProjectionOptions {
|
|
37
|
+
restoredMessages: number;
|
|
38
|
+
trajectoryEnabled: boolean;
|
|
39
|
+
damage?: string;
|
|
40
|
+
}
|
|
41
|
+
/** Pure half of {@link loadResumeRecap}, exported for focused offline verification. */
|
|
42
|
+
export declare function projectResumeRecap(records: readonly TrajectoryRecord[], options: ProjectionOptions): HistoryItem[];
|
|
43
|
+
export {};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { describeDamage, readTrajectory } from './reader.js';
|
|
2
|
+
import { replayRecords } from './replay.js';
|
|
3
|
+
/**
|
|
4
|
+
* Reads one exact session's record and projects its full replayed transcript.
|
|
5
|
+
*
|
|
6
|
+
* Every failure is returned as startup history rather than thrown: an absent record
|
|
7
|
+
* is normal for sessions created before trajectory recording or while it was off.
|
|
8
|
+
*/
|
|
9
|
+
export async function loadResumeRecap(options) {
|
|
10
|
+
try {
|
|
11
|
+
const read = await readTrajectory(options.file);
|
|
12
|
+
const damage = describeDamage(read);
|
|
13
|
+
return projectResumeRecap(read.records, {
|
|
14
|
+
restoredMessages: options.restoredMessages,
|
|
15
|
+
trajectoryEnabled: options.trajectoryEnabled,
|
|
16
|
+
...(damage === undefined ? {} : { damage }),
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
// Missing/unreadable is the state the recap can know. Do not print a provider- or
|
|
21
|
+
// filesystem-controlled error/path here: the notice's shape must stay fixed.
|
|
22
|
+
return recapNotices(options, [
|
|
23
|
+
notice('resume recap unavailable: no readable trajectory record ' +
|
|
24
|
+
'(normal for a pre-recording or trajectory-disabled session)', 'warn', 'missing'),
|
|
25
|
+
]);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/** Pure half of {@link loadResumeRecap}, exported for focused offline verification. */
|
|
29
|
+
export function projectResumeRecap(records, options) {
|
|
30
|
+
// One projection: the whole record through the same reducer the live TUI and
|
|
31
|
+
// replay/export use. The recap adds notices around that history, never rows of
|
|
32
|
+
// its own making.
|
|
33
|
+
const replay = replayRecords(records);
|
|
34
|
+
const history = recapNotices(options, []);
|
|
35
|
+
if (replay.history.length === 0) {
|
|
36
|
+
history.push(notice('resume recap: the trajectory contains no replayable transcript', 'warn', 'empty'));
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
history.push(...replay.history);
|
|
40
|
+
}
|
|
41
|
+
// Honest degradation, each as its own distinct notice after the transcript.
|
|
42
|
+
if (options.damage !== undefined) {
|
|
43
|
+
history.push(notice(`resume recap source is damaged: ${options.damage}`, 'warn', 'damage'));
|
|
44
|
+
}
|
|
45
|
+
if (replay.droppedRecords > 0) {
|
|
46
|
+
history.push(notice(`resume recap replay omitted ${replay.droppedRecords} capped/unreadable payload record(s)`, 'warn', 'dropped'));
|
|
47
|
+
}
|
|
48
|
+
const truncations = records.reduce((total, record) => total + (record.trunc?.length ?? 0), 0);
|
|
49
|
+
if (truncations > 0) {
|
|
50
|
+
// Info, not warn: truncation is a recorded fact about the file (fields capped at
|
|
51
|
+
// write time), not damage — the restored conversation itself is intact.
|
|
52
|
+
history.push(notice(`resume recap transcript contains ${truncations} recorded field truncation(s)`, 'info', 'trunc'));
|
|
53
|
+
}
|
|
54
|
+
return history;
|
|
55
|
+
}
|
|
56
|
+
function recapNotices(options, tail) {
|
|
57
|
+
const history = [
|
|
58
|
+
notice(`resume recap · ${options.restoredMessages} restored model message(s) · read-only trajectory projection`, 'info', 'title'),
|
|
59
|
+
];
|
|
60
|
+
if (!options.trajectoryEnabled) {
|
|
61
|
+
history.push(notice('trajectory recording is disabled for this run', 'warn', 'disabled'));
|
|
62
|
+
}
|
|
63
|
+
return [...history, ...tail];
|
|
64
|
+
}
|
|
65
|
+
function notice(text, severity, suffix) {
|
|
66
|
+
return { kind: 'notice', id: `resume-recap-${suffix}`, text, severity };
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=resume-recap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resume-recap.js","sourceRoot":"","sources":["../../../src/trajectory/resume-recap.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7D,OAAO,EAAE,aAAa,EAAE,MAAM,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AE,gBAAgB,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;AAC1E,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export interface SearchHit {
|
|
2
|
+
sessionId: string;
|
|
3
|
+
seq: number;
|
|
4
|
+
turn: number;
|
|
5
|
+
type: string;
|
|
6
|
+
at: string;
|
|
7
|
+
/** One-line, bounded excerpt centred on the match. */
|
|
8
|
+
excerpt: string;
|
|
9
|
+
}
|
|
10
|
+
export interface SessionSearchResult {
|
|
11
|
+
sessionId: string;
|
|
12
|
+
hits: SearchHit[];
|
|
13
|
+
/** Records scanned in this session. */
|
|
14
|
+
scanned: number;
|
|
15
|
+
/** Damage the reader tolerated while scanning, ready to report. */
|
|
16
|
+
damage: string | undefined;
|
|
17
|
+
}
|
|
18
|
+
export interface SearchOutcome {
|
|
19
|
+
query: string;
|
|
20
|
+
sessions: SessionSearchResult[];
|
|
21
|
+
/** Sessions that have a snapshot but no trajectory file, named rather than counted. */
|
|
22
|
+
withoutRecord: string[];
|
|
23
|
+
hitCount: number;
|
|
24
|
+
/** True when `--limit` cut the reported hits. */
|
|
25
|
+
limited: boolean;
|
|
26
|
+
}
|
|
27
|
+
/** A session the caller named that darwin cannot find any state for at all. */
|
|
28
|
+
export declare class UnknownSessionError extends Error {
|
|
29
|
+
readonly sessionId: string;
|
|
30
|
+
constructor(sessionId: string);
|
|
31
|
+
}
|
|
32
|
+
export interface SearchOptions {
|
|
33
|
+
/** Restrict to one session; when absent every session in the project is scanned. */
|
|
34
|
+
sessionId?: string;
|
|
35
|
+
/** Restrict to one record type, e.g. `beforeToolCallEvent`. */
|
|
36
|
+
type?: string;
|
|
37
|
+
/** Maximum hits reported. */
|
|
38
|
+
limit?: number;
|
|
39
|
+
}
|
|
40
|
+
export declare function searchTrajectories(projectRoot: string, query: string, agentId: string, options?: SearchOptions): Promise<SearchOutcome>;
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Search over recorded trajectories.
|
|
3
|
+
*
|
|
4
|
+
* A bounded, case-insensitive substring match — deliberately not a regex: a
|
|
5
|
+
* user-supplied pattern must not be able to backtrack catastrophically, and a
|
|
6
|
+
* pattern needing shell quoting is a worse surface than one that does not.
|
|
7
|
+
*
|
|
8
|
+
* The honesty rules matter as much as the matching: a session with no record says
|
|
9
|
+
* so, an unknown session says something different, and zero matches over a record
|
|
10
|
+
* that really exists is a successful search, not a failure. Nothing here guesses.
|
|
11
|
+
*/
|
|
12
|
+
import { hasSnapshot, listSessionIds, trajectoryPath } from '../agent/session.js';
|
|
13
|
+
import { describeDamage, readTrajectory, TrajectoryMissingError } from './reader.js';
|
|
14
|
+
import { searchableText } from './record.js';
|
|
15
|
+
/** Excerpt length around a hit, in code points. */
|
|
16
|
+
const EXCERPT_CHARS = 160;
|
|
17
|
+
/** A session the caller named that darwin cannot find any state for at all. */
|
|
18
|
+
export class UnknownSessionError extends Error {
|
|
19
|
+
sessionId;
|
|
20
|
+
constructor(sessionId) {
|
|
21
|
+
super(`Session ${JSON.stringify(sessionId)} does not exist in this project.`);
|
|
22
|
+
this.sessionId = sessionId;
|
|
23
|
+
this.name = 'UnknownSessionError';
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
export async function searchTrajectories(projectRoot, query, agentId, options = {}) {
|
|
27
|
+
const needle = query.toLowerCase();
|
|
28
|
+
const limit = options.limit ?? 50;
|
|
29
|
+
const sessionIds = options.sessionId === undefined ? await listSessionIds(projectRoot) : [options.sessionId];
|
|
30
|
+
// A named session that has neither a record nor a snapshot is a different answer
|
|
31
|
+
// from one with no matches, and the caller is told which.
|
|
32
|
+
if (options.sessionId !== undefined && sessionIds.length === 1) {
|
|
33
|
+
const only = sessionIds[0];
|
|
34
|
+
const known = await hasSnapshot(projectRoot, only, agentId);
|
|
35
|
+
let readable = true;
|
|
36
|
+
try {
|
|
37
|
+
await readTrajectory(trajectoryPath(projectRoot, only));
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
readable = false;
|
|
41
|
+
}
|
|
42
|
+
if (!known && !readable)
|
|
43
|
+
throw new UnknownSessionError(only);
|
|
44
|
+
}
|
|
45
|
+
const sessions = [];
|
|
46
|
+
const withoutRecord = [];
|
|
47
|
+
let hitCount = 0;
|
|
48
|
+
let limited = false;
|
|
49
|
+
for (const sessionId of sessionIds) {
|
|
50
|
+
let read;
|
|
51
|
+
try {
|
|
52
|
+
read = await readTrajectory(trajectoryPath(projectRoot, sessionId));
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
if (error instanceof TrajectoryMissingError) {
|
|
56
|
+
withoutRecord.push(sessionId);
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
throw error;
|
|
60
|
+
}
|
|
61
|
+
const hits = [];
|
|
62
|
+
for (const record of read.records) {
|
|
63
|
+
if (options.type !== undefined && record.type !== options.type)
|
|
64
|
+
continue;
|
|
65
|
+
const excerpt = firstMatch(record, needle);
|
|
66
|
+
if (excerpt === undefined)
|
|
67
|
+
continue;
|
|
68
|
+
if (hitCount >= limit) {
|
|
69
|
+
limited = true;
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
hits.push({
|
|
73
|
+
sessionId,
|
|
74
|
+
seq: record.seq,
|
|
75
|
+
turn: record.turn,
|
|
76
|
+
type: record.type,
|
|
77
|
+
at: record.t,
|
|
78
|
+
excerpt,
|
|
79
|
+
});
|
|
80
|
+
hitCount += 1;
|
|
81
|
+
}
|
|
82
|
+
if (hits.length > 0 || read.records.length > 0) {
|
|
83
|
+
const damage = describeDamage(read);
|
|
84
|
+
sessions.push({
|
|
85
|
+
sessionId,
|
|
86
|
+
hits,
|
|
87
|
+
scanned: read.records.length,
|
|
88
|
+
...(damage === undefined ? { damage: undefined } : { damage }),
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
if (limited)
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
return { query, sessions, withoutRecord, hitCount, limited };
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* The first matching field of a record, as a bounded one-line excerpt.
|
|
98
|
+
*
|
|
99
|
+
* Whitespace is collapsed *before* matching so the reported window and the match
|
|
100
|
+
* are measured in the same string — finding the needle in the raw text and then
|
|
101
|
+
* slicing the collapsed one silently reports an off-by-a-newline window.
|
|
102
|
+
*/
|
|
103
|
+
function firstMatch(record, needle) {
|
|
104
|
+
for (const text of searchableText(record)) {
|
|
105
|
+
const collapsed = text.replace(/\s+/gu, ' ').trim();
|
|
106
|
+
const index = collapsed.toLowerCase().indexOf(needle);
|
|
107
|
+
if (index >= 0)
|
|
108
|
+
return excerpt(collapsed, index, needle.length);
|
|
109
|
+
}
|
|
110
|
+
return undefined;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* A bounded window around the match.
|
|
114
|
+
*
|
|
115
|
+
* Code points, not UTF-16 units: a hit next to an emoji must not be reported with
|
|
116
|
+
* half a surrogate pair — the same reason `headlessField` counts this way.
|
|
117
|
+
*/
|
|
118
|
+
function excerpt(collapsed, index, length) {
|
|
119
|
+
const points = [...collapsed];
|
|
120
|
+
if (points.length <= EXCERPT_CHARS)
|
|
121
|
+
return collapsed;
|
|
122
|
+
// Centre the match, then clamp so a hit near either end still fills the window.
|
|
123
|
+
const start = Math.min(Math.max(0, index - Math.floor((EXCERPT_CHARS - length) / 2)), Math.max(0, points.length - EXCERPT_CHARS));
|
|
124
|
+
const window = points.slice(start, start + EXCERPT_CHARS).join('');
|
|
125
|
+
return `${start > 0 ? '…' : ''}${window}${start + EXCERPT_CHARS < points.length ? '…' : ''}`;
|
|
126
|
+
}
|
|
127
|
+
//# sourceMappingURL=search.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search.js","sourceRoot":"","sources":["../../../src/trajectory/search.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,cAAc,EAAE,MAA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