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,374 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The opt-in per-session diagnostics log.
|
|
3
|
+
*
|
|
4
|
+
* Two channels darwin otherwise throws away meet in one file: the SDK's `debug`
|
|
5
|
+
* and `info` output — which is the *only* place the SDK says it was throttled
|
|
6
|
+
* (`models/bedrock.js`: `logger.debug('throttled | error_message=…')`), where it
|
|
7
|
+
* put its cache points, or that native token counting fell back to estimation —
|
|
8
|
+
* and darwin's own notices, which live in Ink's scrollback and die with the frame.
|
|
9
|
+
* `warn`/`error` are written here too even though they already reach the renderer,
|
|
10
|
+
* so one file holds the whole story rather than half of it.
|
|
11
|
+
*
|
|
12
|
+
* Off unless asked for: unlike default-on context offload, these lines
|
|
13
|
+
* interpolate provider payloads and can therefore carry conversation-derived
|
|
14
|
+
* material. With the feature off nothing here runs at all — `sdk-logging.ts`
|
|
15
|
+
* installs literal no-ops and `AgentRuntime` builds no log — so a default run is
|
|
16
|
+
* byte-for-byte the run it was before this module existed.
|
|
17
|
+
*
|
|
18
|
+
* It is an observer, under the same discipline the trajectory earned
|
|
19
|
+
* (`src/trajectory/`), and one bound stricter:
|
|
20
|
+
*
|
|
21
|
+
* 1. **It cannot affect a turn.** {@link DiagnosticsLog.write} is synchronous,
|
|
22
|
+
* catches everything, performs no I/O and never touches the console — the SDK's
|
|
23
|
+
* default `console.warn` tearing the Ink frame is why `sdk-logging.ts` exists at
|
|
24
|
+
* all. Appends run on a promise chain no caller awaits.
|
|
25
|
+
* 2. **It is bounded twice.** Per line and per file, like the record — and also per
|
|
26
|
+
* *pending* byte, which the record did not need: `logger.debug` is called
|
|
27
|
+
* synchronously from inside the SDK's own stream loop, so a long turn can offer
|
|
28
|
+
* lines faster than a disk accepts them. Diagnostic lines are then dropped and
|
|
29
|
+
* counted; a stream event never is.
|
|
30
|
+
* 3. **Every stop is written down.** Reaching a bound, dropping lines and failing to
|
|
31
|
+
* write all leave a line in the file (or a surfaced problem when the file is what
|
|
32
|
+
* failed). A log that went quiet without saying so would be worse than none.
|
|
33
|
+
*
|
|
34
|
+
* See `docs/architecture/load-bearing-decisions.md` § Session diagnostics.
|
|
35
|
+
*/
|
|
36
|
+
import { open, mkdir, stat } from 'node:fs/promises';
|
|
37
|
+
import path from 'node:path';
|
|
38
|
+
/**
|
|
39
|
+
* Per line, in **code points** — the `headlessField` convention, so a multi-byte
|
|
40
|
+
* message cannot be cut mid-sequence. Matches the trajectory's field cap: a
|
|
41
|
+
* provider that echoes a whole rejected request back is the reason both exist.
|
|
42
|
+
*/
|
|
43
|
+
export const MAX_DIAGNOSTIC_LINE_CHARS = 8_000;
|
|
44
|
+
/**
|
|
45
|
+
* Per session file, in bytes.
|
|
46
|
+
*
|
|
47
|
+
* Deliberately an eighth of the trajectory's 64 MiB, and the difference is the
|
|
48
|
+
* point: a trajectory is the artifact you *keep*, so its bound has to leave a long
|
|
49
|
+
* session's history intact. This is scratch for one debugging session, nothing ever
|
|
50
|
+
* garbage-collects it (see `contextOffload` in `src/config.ts`), and 8 MiB is on the
|
|
51
|
+
* order of 80,000 lines — far past the point where a human tailing a file is still
|
|
52
|
+
* reading it. Whoever needs more than this needs a different tool, not a bigger file.
|
|
53
|
+
*/
|
|
54
|
+
export const MAX_DIAGNOSTICS_BYTES = 8 * 1024 * 1024;
|
|
55
|
+
/**
|
|
56
|
+
* Formatted-but-unwritten bytes held in memory, before arriving lines are dropped.
|
|
57
|
+
*
|
|
58
|
+
* The bound the trajectory does not have. It buffers one turn and flushes at the
|
|
59
|
+
* end, so its memory is bounded by a turn; this one accepts lines from inside the
|
|
60
|
+
* SDK's stream loop and flushes continuously, so a `debug` firehose against a slow
|
|
61
|
+
* disk is a real unbounded-growth path. Dropping is the correct failure here:
|
|
62
|
+
* blocking would delay the event the SDK was in the middle of, which the observer
|
|
63
|
+
* contract forbids outright.
|
|
64
|
+
*/
|
|
65
|
+
export const MAX_DIAGNOSTICS_PENDING_BYTES = 1024 * 1024;
|
|
66
|
+
/** Fixed-width columns: aligned for a human, still splittable for a script. */
|
|
67
|
+
const SOURCE_WIDTH = 6;
|
|
68
|
+
const LEVEL_WIDTH = 5;
|
|
69
|
+
/**
|
|
70
|
+
* One line: `<ISO timestamp> <source> <level> — <message>`.
|
|
71
|
+
*
|
|
72
|
+
* Text rather than JSONL, unlike the trajectory, because the reader is a person with
|
|
73
|
+
* `tail -f` rather than a replay engine — and because these lines are already text
|
|
74
|
+
* the SDK formatted, so wrapping each one in an object would add punctuation and no
|
|
75
|
+
* structure. The parts stay unambiguous anyway: three fixed leading fields, then
|
|
76
|
+
* ` — ` (the `sdk warn — …` delimiter headless already uses) and the message.
|
|
77
|
+
*
|
|
78
|
+
* The message is collapsed to a single line, so one event is always exactly one line
|
|
79
|
+
* — a multi-line notice (`/usage`'s table, say) must not be able to break a reader
|
|
80
|
+
* that counts lines, and a `tail -f` that shows half an event is worse than one that
|
|
81
|
+
* shows a long one.
|
|
82
|
+
*/
|
|
83
|
+
export function formatDiagnosticLine(at, entry) {
|
|
84
|
+
const message = capLine(entry.message.replace(/\s+/gu, ' ').trim());
|
|
85
|
+
return `${at} ${entry.source.padEnd(SOURCE_WIDTH)} ${entry.level.padEnd(LEVEL_WIDTH)} — ${message}\n`;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Caps in code points and *says* it did, because the alternative is a reader quoting
|
|
89
|
+
* a truncated provider message as if it were the whole one. The count is the original
|
|
90
|
+
* length, so the size of what is missing is knowable.
|
|
91
|
+
*/
|
|
92
|
+
function capLine(message) {
|
|
93
|
+
const points = [...message];
|
|
94
|
+
if (points.length <= MAX_DIAGNOSTIC_LINE_CHARS)
|
|
95
|
+
return message;
|
|
96
|
+
const kept = points.slice(0, MAX_DIAGNOSTIC_LINE_CHARS).join('');
|
|
97
|
+
return `${kept}… (truncated, ${points.length} code points)`;
|
|
98
|
+
}
|
|
99
|
+
export class DiagnosticsLog {
|
|
100
|
+
file;
|
|
101
|
+
openFile;
|
|
102
|
+
maxBytes;
|
|
103
|
+
maxPendingBytes;
|
|
104
|
+
/** Formatted-but-unwritten lines, in observation order. */
|
|
105
|
+
pending = [];
|
|
106
|
+
pendingBytes = 0;
|
|
107
|
+
/** True while an append is in flight; see {@link flush}. */
|
|
108
|
+
writing = false;
|
|
109
|
+
/** The serialized append chain: every write waits for the previous one. */
|
|
110
|
+
chain = Promise.resolve();
|
|
111
|
+
active = true;
|
|
112
|
+
problem;
|
|
113
|
+
linesThisRun = 0;
|
|
114
|
+
bytesThisRun = 0;
|
|
115
|
+
fileBytes = 0;
|
|
116
|
+
opened = false;
|
|
117
|
+
/** Dropped since the last line that reported drops, and in total. */
|
|
118
|
+
droppedSinceReport = 0;
|
|
119
|
+
droppedLines = 0;
|
|
120
|
+
constructor(options) {
|
|
121
|
+
this.file = options.file;
|
|
122
|
+
this.openFile = options.openFile ?? open;
|
|
123
|
+
this.maxBytes = options.maxBytes ?? MAX_DIAGNOSTICS_BYTES;
|
|
124
|
+
this.maxPendingBytes = options.maxPendingBytes ?? MAX_DIAGNOSTICS_PENDING_BYTES;
|
|
125
|
+
// The header is buffered, not written: no file exists until the first flush, so a
|
|
126
|
+
// session that logs nothing else still leaves nothing behind — the same lazy rule
|
|
127
|
+
// the recorder and the resume pointer follow. It names the budget so the stop
|
|
128
|
+
// marker at the end of a full file is not the first mention of a bound.
|
|
129
|
+
this.write({
|
|
130
|
+
source: 'darwin',
|
|
131
|
+
level: 'info',
|
|
132
|
+
message: `diagnostics started · session ${options.run.session} · darwin ${options.run.darwinVersion} · ` +
|
|
133
|
+
`${options.run.provider}/${options.run.model} · pid ${process.pid} · budget ${this.maxBytes} bytes`,
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
/** Where the lines go. Reported so a caller can tell the user without guessing. */
|
|
137
|
+
get path() {
|
|
138
|
+
return this.file;
|
|
139
|
+
}
|
|
140
|
+
get status() {
|
|
141
|
+
return {
|
|
142
|
+
file: this.file,
|
|
143
|
+
linesThisRun: this.linesThisRun,
|
|
144
|
+
bytesThisRun: this.bytesThisRun,
|
|
145
|
+
droppedLines: this.droppedLines,
|
|
146
|
+
problem: this.problem,
|
|
147
|
+
active: this.active,
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Records one line. Synchronous, no I/O, and it swallows its own failures.
|
|
152
|
+
*
|
|
153
|
+
* This is the whole observer contract in one method: it is called from inside the
|
|
154
|
+
* SDK's stream loop and from the TUI's dispatch path, so it may not await, may not
|
|
155
|
+
* throw, and may not write to the console. Everything it does is format a string,
|
|
156
|
+
* push it, and register a continuation on the append chain.
|
|
157
|
+
*/
|
|
158
|
+
write(entry) {
|
|
159
|
+
if (!this.active)
|
|
160
|
+
return;
|
|
161
|
+
try {
|
|
162
|
+
const line = formatDiagnosticLine(new Date().toISOString(), entry);
|
|
163
|
+
const bytes = Buffer.byteLength(line, 'utf8');
|
|
164
|
+
// Full queue: drop this line rather than grow without bound or make the caller
|
|
165
|
+
// wait. Counted, and reported in the file by the next successful flush — a
|
|
166
|
+
// silent gap would leave a reader believing nothing happened in it.
|
|
167
|
+
if (this.pendingBytes + bytes > this.maxPendingBytes) {
|
|
168
|
+
this.droppedSinceReport += 1;
|
|
169
|
+
this.droppedLines += 1;
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
this.pending.push(line);
|
|
173
|
+
this.pendingBytes += bytes;
|
|
174
|
+
this.flush();
|
|
175
|
+
}
|
|
176
|
+
catch (error) {
|
|
177
|
+
this.fail(error);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* A sink for `routeSdkLogs`' verbose tap, bound once.
|
|
182
|
+
*
|
|
183
|
+
* Bound here rather than built at each call site so the two entry points cannot
|
|
184
|
+
* disagree about the `source` label, and so a caller never has to re-create a
|
|
185
|
+
* closure to satisfy narrowing on an optional log.
|
|
186
|
+
*/
|
|
187
|
+
sdkSink = (entry) => {
|
|
188
|
+
this.write({ source: 'sdk', ...entry });
|
|
189
|
+
};
|
|
190
|
+
/** A darwin-side line: what the TUI showed the user, with the severity it showed. */
|
|
191
|
+
notice = (text, level = 'info') => {
|
|
192
|
+
this.write({ source: 'darwin', level, message: text });
|
|
193
|
+
};
|
|
194
|
+
/**
|
|
195
|
+
* Appends everything buffered so far — but only when the previous append has
|
|
196
|
+
* finished.
|
|
197
|
+
*
|
|
198
|
+
* The wait is the whole point, and it is where this differs from the trajectory's
|
|
199
|
+
* writer: that one flushes once per turn, so it can hand every batch straight to the
|
|
200
|
+
* chain. Lines here arrive continuously from inside the SDK's stream loop, and
|
|
201
|
+
* draining on every arrival would queue an unbounded number of batches — moving the
|
|
202
|
+
* unbounded growth from one array into a promise chain rather than removing it. By
|
|
203
|
+
* leaving lines in `pending` while a write is in flight, the pending-byte bound in
|
|
204
|
+
* {@link write} is the real bound on memory.
|
|
205
|
+
*
|
|
206
|
+
* Returns nothing on purpose: no caller on the streaming path may await this.
|
|
207
|
+
* `close()` is the one place the chain is awaited.
|
|
208
|
+
*/
|
|
209
|
+
flush() {
|
|
210
|
+
if (this.writing || this.pending.length === 0)
|
|
211
|
+
return;
|
|
212
|
+
const batch = this.pending;
|
|
213
|
+
this.pending = [];
|
|
214
|
+
this.pendingBytes = 0;
|
|
215
|
+
this.writing = true;
|
|
216
|
+
this.chain = this.chain
|
|
217
|
+
.then(() => this.append(batch))
|
|
218
|
+
.catch((error) => {
|
|
219
|
+
this.fail(error);
|
|
220
|
+
})
|
|
221
|
+
.finally(() => {
|
|
222
|
+
this.writing = false;
|
|
223
|
+
// Whatever arrived while that write was in flight goes out now, so a burst
|
|
224
|
+
// costs one append per disk round-trip rather than one per line.
|
|
225
|
+
this.flush();
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
/** Flushes and waits, so a session's last lines are durable before the process exits. */
|
|
229
|
+
async close() {
|
|
230
|
+
this.flush();
|
|
231
|
+
// Two rounds are possible: the awaited chain may schedule a follow-up flush for
|
|
232
|
+
// lines that arrived during it, and `await` on the *current* chain would not cover
|
|
233
|
+
// the one that replaced it. Looping until nothing is left is what makes the last
|
|
234
|
+
// line of a session actually reach the disk.
|
|
235
|
+
while (this.pending.length > 0 || this.writing) {
|
|
236
|
+
await this.chain;
|
|
237
|
+
this.flush();
|
|
238
|
+
}
|
|
239
|
+
await this.chain;
|
|
240
|
+
// Latched shut, like the permission queue's `close()`: a line offered after this
|
|
241
|
+
// would be buffered onto a chain nobody awaits any more, so it might or might not
|
|
242
|
+
// reach the disk before the process exits. Refusing it makes the file's end mean
|
|
243
|
+
// one thing — everything up to the session's shutdown — instead of being a race.
|
|
244
|
+
// `problem` stays unset, which is how a reader tells a closed log from a broken one.
|
|
245
|
+
this.active = false;
|
|
246
|
+
}
|
|
247
|
+
/** Latches the first failure and stops logging; never rethrows. */
|
|
248
|
+
fail(error) {
|
|
249
|
+
if (this.problem !== undefined)
|
|
250
|
+
return;
|
|
251
|
+
this.problem = `${this.file}: ${error instanceof Error ? error.message : String(error)}`;
|
|
252
|
+
this.active = false;
|
|
253
|
+
this.pending = [];
|
|
254
|
+
this.pendingBytes = 0;
|
|
255
|
+
}
|
|
256
|
+
async append(batch) {
|
|
257
|
+
if (this.problem !== undefined)
|
|
258
|
+
return;
|
|
259
|
+
const prefix = await this.prepare();
|
|
260
|
+
// Reported before the batch it belongs to rather than after: the lines that were
|
|
261
|
+
// dropped happened *before* these arrived, so a reader scanning downwards meets
|
|
262
|
+
// the gap where the gap was.
|
|
263
|
+
const dropped = this.takeDroppedReport();
|
|
264
|
+
const queued = dropped === '' ? batch : [dropped, ...batch];
|
|
265
|
+
// Trimmed to the budget rather than written and then regretted. One append can
|
|
266
|
+
// carry a whole burst, so checking the total only afterwards would let the file
|
|
267
|
+
// overshoot by the entire pending bound — a bound that can be exceeded by a
|
|
268
|
+
// megabyte is not the bound it claims to be. What does not fit is not written, and
|
|
269
|
+
// the marker below says so.
|
|
270
|
+
const room = this.maxBytes - this.fileBytes - Buffer.byteLength(prefix, 'utf8');
|
|
271
|
+
const fitting = [];
|
|
272
|
+
let used = 0;
|
|
273
|
+
for (const line of queued) {
|
|
274
|
+
const size = Buffer.byteLength(line, 'utf8');
|
|
275
|
+
if (used + size > room)
|
|
276
|
+
break;
|
|
277
|
+
fitting.push(line);
|
|
278
|
+
used += size;
|
|
279
|
+
}
|
|
280
|
+
const full = fitting.length < queued.length;
|
|
281
|
+
const payload = `${prefix}${fitting.join('')}`;
|
|
282
|
+
let handle;
|
|
283
|
+
try {
|
|
284
|
+
handle = await this.openFile(this.file, 'a');
|
|
285
|
+
if (payload !== '') {
|
|
286
|
+
await handle.write(payload, null, 'utf8');
|
|
287
|
+
const written = Buffer.byteLength(payload, 'utf8');
|
|
288
|
+
this.linesThisRun += fitting.length;
|
|
289
|
+
this.bytesThisRun += written;
|
|
290
|
+
this.fileBytes += written;
|
|
291
|
+
}
|
|
292
|
+
if (full || this.fileBytes >= this.maxBytes)
|
|
293
|
+
await this.stopForBudget(handle);
|
|
294
|
+
}
|
|
295
|
+
finally {
|
|
296
|
+
await handle?.close().catch(() => {
|
|
297
|
+
// A failed close has already had its write succeed or fail on its own.
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
/** One line naming the drops since the last report, or nothing to report. */
|
|
302
|
+
takeDroppedReport() {
|
|
303
|
+
if (this.droppedSinceReport === 0)
|
|
304
|
+
return '';
|
|
305
|
+
const count = this.droppedSinceReport;
|
|
306
|
+
this.droppedSinceReport = 0;
|
|
307
|
+
return formatDiagnosticLine(new Date().toISOString(), {
|
|
308
|
+
source: 'darwin',
|
|
309
|
+
level: 'warn',
|
|
310
|
+
message: `${count} line(s) dropped: the writer could not keep up`,
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* One-time setup for the first append of this process: creates the directory and
|
|
315
|
+
* measures what is already there, so the budget covers the whole session rather
|
|
316
|
+
* than only this run. Returns a newline guard when a previous run left a partial
|
|
317
|
+
* line, for the same reason the recorder does — an interrupted write stays one
|
|
318
|
+
* broken line instead of being glued onto the next good one. Nothing here modifies
|
|
319
|
+
* existing bytes.
|
|
320
|
+
*/
|
|
321
|
+
async prepare() {
|
|
322
|
+
if (this.opened)
|
|
323
|
+
return '';
|
|
324
|
+
this.opened = true;
|
|
325
|
+
await mkdir(path.dirname(this.file), { recursive: true });
|
|
326
|
+
try {
|
|
327
|
+
const info = await stat(this.file);
|
|
328
|
+
this.fileBytes = info.size;
|
|
329
|
+
if (info.size === 0)
|
|
330
|
+
return '';
|
|
331
|
+
return (await this.endsWithNewline(info.size)) ? '' : '\n';
|
|
332
|
+
}
|
|
333
|
+
catch {
|
|
334
|
+
// No file yet, the common case. A real permission problem surfaces on the
|
|
335
|
+
// append that follows, where it becomes the latched problem.
|
|
336
|
+
this.fileBytes = 0;
|
|
337
|
+
return '';
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
async endsWithNewline(size) {
|
|
341
|
+
let handle;
|
|
342
|
+
try {
|
|
343
|
+
handle = await this.openFile(this.file, 'r');
|
|
344
|
+
const buffer = Buffer.alloc(1);
|
|
345
|
+
await handle.read(buffer, 0, 1, size - 1);
|
|
346
|
+
return buffer.toString('utf8') === '\n';
|
|
347
|
+
}
|
|
348
|
+
catch {
|
|
349
|
+
// Unreadable: assume a guard is needed. A spurious blank line costs a reader
|
|
350
|
+
// nothing, while a missing one corrupts the line that follows.
|
|
351
|
+
return false;
|
|
352
|
+
}
|
|
353
|
+
finally {
|
|
354
|
+
await handle?.close().catch(() => { });
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
/** Appends the final line and latches logging off for this session. */
|
|
358
|
+
async stopForBudget(handle) {
|
|
359
|
+
const line = formatDiagnosticLine(new Date().toISOString(), {
|
|
360
|
+
source: 'darwin',
|
|
361
|
+
level: 'warn',
|
|
362
|
+
message: `diagnostics stopped: reached the ${this.maxBytes}-byte per-session budget ` +
|
|
363
|
+
'(nothing after this line was written)',
|
|
364
|
+
});
|
|
365
|
+
await handle.write(line, null, 'utf8');
|
|
366
|
+
this.linesThisRun += 1;
|
|
367
|
+
this.bytesThisRun += Buffer.byteLength(line, 'utf8');
|
|
368
|
+
this.active = false;
|
|
369
|
+
this.problem =
|
|
370
|
+
`diagnostics stopped: ${this.file} reached its ${this.maxBytes}-byte budget ` +
|
|
371
|
+
'(the log is complete up to that point)';
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
//# sourceMappingURL=diagnostics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diagnostics.js","sourceRoot":"","sources":["../../../src/agent/diagnostics.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAmB,MAAM,kBAAkB,CAAC;AACtE,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B;;;;GAIG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,KAAK,CAAC;AAE/C;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC;AAErD;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAAG,IAAI,GAAG,IAAI,CAAC;AA0DzD,+EAA+E;AAC/E,MAAM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AAE,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;QACxC,CAAC;IACH,CAAC;IAED,uEAAuE;IAC/D,KAAK,CAAC,aAAa,CAAC,MAAkB;QAC5C,MAAM,IAAI,GAAG,oBAAoB,CAAC,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,EAAE;YAC1D,MAAM,EAAE,QAAQ;YAChB,KAAK,EAAE,MAAM;YACb,OAAO,EACL,oCAAoC,IAAI,CAAC,QAAQ,2BAA2B;gBAC5E,uCAAuC;SAC1C,CAAC,CAAC;QACH,MAAM,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;QACvC,IAAI,CAAC,YAAY,IAAI,CAAC,CAAC;QACvB,IAAI,CAAC,YAAY,IAAI,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QACrD,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,IAAI,CAAC,OAAO;YACV,wBAAwB,IAAI,CAAC,IAAI,gBAAgB,IAAI,CAAC,QAAQ,eAAe;gBAC7E,wCAAwC,CAAC;IAC7C,CAAC;CACF"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
export declare const AGENTS_FILENAME = "AGENTS.md";
|
|
2
|
+
/**
|
|
3
|
+
* Instructions past this size are truncated rather than sent whole.
|
|
4
|
+
*
|
|
5
|
+
* AGENTS.md goes into the system prompt, so it is re-sent with every request of
|
|
6
|
+
* the session; an oversized file would silently spend the context budget the
|
|
7
|
+
* conversation itself needs.
|
|
8
|
+
*/
|
|
9
|
+
export declare const MAX_INSTRUCTIONS_BYTES: number;
|
|
10
|
+
export interface ProjectInstructions {
|
|
11
|
+
/** Absolute path of the file that was read. */
|
|
12
|
+
path: string;
|
|
13
|
+
/** Size on disk, in bytes, before any truncation. */
|
|
14
|
+
bytes: number;
|
|
15
|
+
/** True when only the first {@link MAX_INSTRUCTIONS_BYTES} were kept. */
|
|
16
|
+
truncated: boolean;
|
|
17
|
+
/** The system-prompt fragment, delimited and labelled with its source. */
|
|
18
|
+
fragment: string;
|
|
19
|
+
}
|
|
20
|
+
/** What a UI needs to report the load; the fragment itself is not displayable. */
|
|
21
|
+
export type ProjectInstructionsSummary = Omit<ProjectInstructions, 'fragment'>;
|
|
22
|
+
export interface ProjectInstructionsLoad {
|
|
23
|
+
/** What to inject, or undefined when there is nothing usable to inject. */
|
|
24
|
+
instructions: ProjectInstructions | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* Why an AGENTS.md that is present could not be used. Undefined both when the
|
|
27
|
+
* file loaded and when there is no file at all — those two need no reporting.
|
|
28
|
+
*/
|
|
29
|
+
problem: string | undefined;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Reads `<projectRoot>/AGENTS.md`.
|
|
33
|
+
*
|
|
34
|
+
* A broken file never blocks startup — the agent works without project
|
|
35
|
+
* instructions — but the two ways of ending up without them are not the same. No
|
|
36
|
+
* file is the normal case and stays silent; a file that exists and cannot be read
|
|
37
|
+
* (a directory in its place, no read permission) is reported, since otherwise the
|
|
38
|
+
* user has rules they believe are in effect and nothing on screen contradicts
|
|
39
|
+
* that. Same isolation rule as a broken skill directory: skip it, say why.
|
|
40
|
+
*
|
|
41
|
+
* An empty or whitespace-only file is silently skipped: injecting the delimiters
|
|
42
|
+
* with nothing between them would only point the model at emptiness.
|
|
43
|
+
*/
|
|
44
|
+
export declare function loadProjectInstructions(projectRoot: string): Promise<ProjectInstructionsLoad>;
|
|
45
|
+
/**
|
|
46
|
+
* Places project instructions directly after the base prompt.
|
|
47
|
+
*
|
|
48
|
+
* The order of the assembled request is fixed: base prompt → project instructions
|
|
49
|
+
* → the official skills catalogue injected before invocation → working context →
|
|
50
|
+
* final cache point. Instructions belong with the base prompt because they
|
|
51
|
+
* describe how to work in this repository; the skills list is a menu and reads
|
|
52
|
+
* better last, and the working context is not rules at all.
|
|
53
|
+
*/
|
|
54
|
+
export declare function composeSystemPrompt(basePrompt: string, instructions: ProjectInstructions | undefined): string;
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Project instructions preloaded from AGENTS.md.
|
|
3
|
+
*
|
|
4
|
+
* Only the run directory's own `AGENTS.md` is read: no walking up to parent
|
|
5
|
+
* directories and no merging of several files, so what reaches the model is
|
|
6
|
+
* exactly the file sitting next to the repository the user is working in.
|
|
7
|
+
*/
|
|
8
|
+
import { readFile } from 'node:fs/promises';
|
|
9
|
+
import path from 'node:path';
|
|
10
|
+
import { StringDecoder } from 'node:string_decoder';
|
|
11
|
+
export const AGENTS_FILENAME = 'AGENTS.md';
|
|
12
|
+
/**
|
|
13
|
+
* Instructions past this size are truncated rather than sent whole.
|
|
14
|
+
*
|
|
15
|
+
* AGENTS.md goes into the system prompt, so it is re-sent with every request of
|
|
16
|
+
* the session; an oversized file would silently spend the context budget the
|
|
17
|
+
* conversation itself needs.
|
|
18
|
+
*/
|
|
19
|
+
export const MAX_INSTRUCTIONS_BYTES = 32 * 1024;
|
|
20
|
+
/**
|
|
21
|
+
* Reads `<projectRoot>/AGENTS.md`.
|
|
22
|
+
*
|
|
23
|
+
* A broken file never blocks startup — the agent works without project
|
|
24
|
+
* instructions — but the two ways of ending up without them are not the same. No
|
|
25
|
+
* file is the normal case and stays silent; a file that exists and cannot be read
|
|
26
|
+
* (a directory in its place, no read permission) is reported, since otherwise the
|
|
27
|
+
* user has rules they believe are in effect and nothing on screen contradicts
|
|
28
|
+
* that. Same isolation rule as a broken skill directory: skip it, say why.
|
|
29
|
+
*
|
|
30
|
+
* An empty or whitespace-only file is silently skipped: injecting the delimiters
|
|
31
|
+
* with nothing between them would only point the model at emptiness.
|
|
32
|
+
*/
|
|
33
|
+
export async function loadProjectInstructions(projectRoot) {
|
|
34
|
+
const filePath = path.join(projectRoot, AGENTS_FILENAME);
|
|
35
|
+
let raw;
|
|
36
|
+
try {
|
|
37
|
+
raw = await readFile(filePath);
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
return { instructions: undefined, problem: isMissingFile(error) ? undefined : describe(error) };
|
|
41
|
+
}
|
|
42
|
+
const bytes = raw.byteLength;
|
|
43
|
+
const truncated = bytes > MAX_INSTRUCTIONS_BYTES;
|
|
44
|
+
const text = truncated
|
|
45
|
+
? clipToLastLine(raw.subarray(0, MAX_INSTRUCTIONS_BYTES))
|
|
46
|
+
: raw.toString('utf8');
|
|
47
|
+
if (text.trim() === '')
|
|
48
|
+
return { instructions: undefined, problem: undefined };
|
|
49
|
+
return {
|
|
50
|
+
instructions: {
|
|
51
|
+
path: filePath,
|
|
52
|
+
bytes,
|
|
53
|
+
truncated,
|
|
54
|
+
fragment: renderFragment(text.trimEnd(), truncated),
|
|
55
|
+
},
|
|
56
|
+
problem: undefined,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Places project instructions directly after the base prompt.
|
|
61
|
+
*
|
|
62
|
+
* The order of the assembled request is fixed: base prompt → project instructions
|
|
63
|
+
* → the official skills catalogue injected before invocation → working context →
|
|
64
|
+
* final cache point. Instructions belong with the base prompt because they
|
|
65
|
+
* describe how to work in this repository; the skills list is a menu and reads
|
|
66
|
+
* better last, and the working context is not rules at all.
|
|
67
|
+
*/
|
|
68
|
+
export function composeSystemPrompt(basePrompt, instructions) {
|
|
69
|
+
if (instructions === undefined)
|
|
70
|
+
return basePrompt;
|
|
71
|
+
return `${basePrompt}\n\n${instructions.fragment}`;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* True when the file is simply not there.
|
|
75
|
+
*
|
|
76
|
+
* `ENOTDIR` counts: a path component that is a file rather than a directory means
|
|
77
|
+
* there is no AGENTS.md at that location either.
|
|
78
|
+
*/
|
|
79
|
+
function isMissingFile(error) {
|
|
80
|
+
const code = typeof error === 'object' && error !== null ? error.code : undefined;
|
|
81
|
+
return code === 'ENOENT' || code === 'ENOTDIR';
|
|
82
|
+
}
|
|
83
|
+
function describe(error) {
|
|
84
|
+
return error instanceof Error ? error.message : String(error);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Decodes a byte-truncated slice, dropping the final partial line.
|
|
88
|
+
*
|
|
89
|
+
* A cut at a byte offset can land inside a multi-byte character or halfway
|
|
90
|
+
* through a sentence. `StringDecoder` holds back an incomplete trailing sequence
|
|
91
|
+
* instead of emitting a replacement character for it — `Buffer.toString()` would
|
|
92
|
+
* put a `�` at the end of the instructions — and trimming to the last newline
|
|
93
|
+
* keeps what the model reads to whole lines.
|
|
94
|
+
*/
|
|
95
|
+
function clipToLastLine(slice) {
|
|
96
|
+
const decoded = new StringDecoder('utf8').write(slice);
|
|
97
|
+
const lastNewline = decoded.lastIndexOf('\n');
|
|
98
|
+
return lastNewline === -1 ? decoded : decoded.slice(0, lastNewline);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Wraps the text in a labelled block. The source attribute matters: the model has
|
|
102
|
+
* to be able to tell these instructions came from the project's own file rather
|
|
103
|
+
* than from darwin itself, since only one of the two is something the user can edit.
|
|
104
|
+
*/
|
|
105
|
+
function renderFragment(text, truncated) {
|
|
106
|
+
const attributes = truncated
|
|
107
|
+
? `source="${AGENTS_FILENAME}" truncated="true"`
|
|
108
|
+
: `source="${AGENTS_FILENAME}"`;
|
|
109
|
+
return [
|
|
110
|
+
`<project-instructions ${attributes}>`,
|
|
111
|
+
text,
|
|
112
|
+
...(truncated
|
|
113
|
+
? [`(This file is larger than ${MAX_INSTRUCTIONS_BYTES / 1024} KB and was cut off here.)`]
|
|
114
|
+
: []),
|
|
115
|
+
'</project-instructions>',
|
|
116
|
+
].join('\n');
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=instructions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"instructions.js","sourceRoot":"","sources":["../../../src/agent/instructions.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,kB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AU,GAAG;QACtC,IAAI;QACJ,GAAG,CAAC,SAAS;YACX,CAAC,CAAC,CAAC,6BAA6B,sBAAsB,GAAG,IAAI,4BAA4B,CAAC;YAC1F,CAAC,CAAC,EAAE,CAAC;QACP,yBAAyB;KAC1B,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Message, type InvocationState, type LocalAgent } from '@strands-agents/sdk';
|
|
2
|
+
/** Adds privately consumed partial output back to an invoke()-only result. */
|
|
3
|
+
export declare function withRetainedMaxTokensText(result: string, invocationState: InvocationState): string;
|
|
4
|
+
/**
|
|
5
|
+
* The partial assistant messages this recovery retained for one invocation, in
|
|
6
|
+
* order. Read-only view for the failed-child seam; the key itself stays private.
|
|
7
|
+
*/
|
|
8
|
+
export declare function retainedMaxTokensPartials(invocationState: InvocationState): readonly Message[];
|
|
9
|
+
/**
|
|
10
|
+
* Installs one invocation-scoped continuation for output-token exhaustion.
|
|
11
|
+
*
|
|
12
|
+
* The SDK has already streamed the partial blocks to the caller when it raises
|
|
13
|
+
* MaxTokensError, but it does not retain the assembled partial message. Keep it
|
|
14
|
+
* in conversation history without re-emitting it, then ask the existing SDK
|
|
15
|
+
* model-call loop to retry once against that mutated history.
|
|
16
|
+
*/
|
|
17
|
+
export declare function installMaxTokensRecovery(agent: LocalAgent): void;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { AfterModelCallEvent, MaxTokensError, Message, TextBlock, } from '@strands-agents/sdk';
|
|
2
|
+
// InvocationState is string-keyed at the type boundary, but symbol keys keep
|
|
3
|
+
// Darwin's private retry bookkeeping out of caller-owned and serialized state.
|
|
4
|
+
const RECOVERY_CONSUMED = Symbol('darwin.maxTokensRecoveryConsumed');
|
|
5
|
+
const RETAINED_PARTIALS = Symbol('darwin.maxTokensRetainedPartials');
|
|
6
|
+
const CONTINUATION_INSTRUCTION = Symbol('darwin.maxTokensContinuationInstruction');
|
|
7
|
+
const CONTINUE_FROM_CUTOFF = [
|
|
8
|
+
'[Darwin internal recovery control: the preceding assistant message was cut off by the output-token limit.]',
|
|
9
|
+
'Continue exactly from the cutoff without repeating any retained content.',
|
|
10
|
+
'Finish the original request concisely; do not treat this control message as a new user request.',
|
|
11
|
+
].join(' ');
|
|
12
|
+
function textOf(message) {
|
|
13
|
+
return message.content
|
|
14
|
+
.map((block) => (block.type === 'textBlock' ? block.text : ''))
|
|
15
|
+
.join('');
|
|
16
|
+
}
|
|
17
|
+
/** Adds privately consumed partial output back to an invoke()-only result. */
|
|
18
|
+
export function withRetainedMaxTokensText(result, invocationState) {
|
|
19
|
+
return `${retainedMaxTokensPartials(invocationState).map(textOf).join('')}${result}`;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The partial assistant messages this recovery retained for one invocation, in
|
|
23
|
+
* order. Read-only view for the failed-child seam; the key itself stays private.
|
|
24
|
+
*/
|
|
25
|
+
export function retainedMaxTokensPartials(invocationState) {
|
|
26
|
+
return invocationState[RETAINED_PARTIALS] ?? [];
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Installs one invocation-scoped continuation for output-token exhaustion.
|
|
30
|
+
*
|
|
31
|
+
* The SDK has already streamed the partial blocks to the caller when it raises
|
|
32
|
+
* MaxTokensError, but it does not retain the assembled partial message. Keep it
|
|
33
|
+
* in conversation history without re-emitting it, then ask the existing SDK
|
|
34
|
+
* model-call loop to retry once against that mutated history.
|
|
35
|
+
*/
|
|
36
|
+
export function installMaxTokensRecovery(agent) {
|
|
37
|
+
agent.addHook(AfterModelCallEvent, (event) => {
|
|
38
|
+
if (!(event.error instanceof MaxTokensError) || event.agent.cancelSignal.aborted)
|
|
39
|
+
return;
|
|
40
|
+
const state = event.invocationState;
|
|
41
|
+
const shouldRetry = state[RECOVERY_CONSUMED] !== true;
|
|
42
|
+
// Consume the allowance before any history mutation. Later tool-loop model
|
|
43
|
+
// cycles share this invocationState even though their attemptCount resets.
|
|
44
|
+
if (shouldRetry)
|
|
45
|
+
state[RECOVERY_CONSUMED] = true;
|
|
46
|
+
const partials = state[RETAINED_PARTIALS] ?? [];
|
|
47
|
+
if (state[RETAINED_PARTIALS] === undefined)
|
|
48
|
+
state[RETAINED_PARTIALS] = partials;
|
|
49
|
+
// Every max-token failure has useful assistant context. This includes the
|
|
50
|
+
// one allowed continuation failing: persist that second partial, but let its
|
|
51
|
+
// MaxTokensError propagate so truncation is never reported as success.
|
|
52
|
+
event.agent.messages.push(event.error.partialMessage);
|
|
53
|
+
partials.push(event.error.partialMessage);
|
|
54
|
+
if (!shouldRetry)
|
|
55
|
+
return;
|
|
56
|
+
const instruction = new Message({
|
|
57
|
+
role: 'user',
|
|
58
|
+
content: [new TextBlock(CONTINUE_FROM_CUTOFF)],
|
|
59
|
+
});
|
|
60
|
+
state[CONTINUATION_INSTRUCTION] = instruction;
|
|
61
|
+
event.agent.messages.push(instruction);
|
|
62
|
+
event.retry = true;
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=max-tokens-recovery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"max-tokens-recovery.js","sourceRoot":"","sources":["../../../src/agent/max-tokens-recovery.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,cAAc,EACd,OAAO,EACP,SAAS,GAGV,MAAM,qBAAqB,CAAC;AAE7B,6EAA6E;AAC7E,+EAA+E;AAC/E,MAAM,iBAAiB,GAAkB,MAAM,CAAC,kCAAkC,CAAC,CAAC;AACpF,MAAM,iBAAiB,GAAkB,MAAM,CAAC,kCAAkC,CAAC,CAAC;AACpF,MAAM,wBAAwB,GAAkB,MAAM,CAAC,yCAAyC,CAAC,CAAC;AAElG,MAAM,oBAAoB,GAAG;IAC3B,4GAA4G;IAC5G,0EAA0E;IAC1E,iGAAiG;CAClG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAQZ,SAAS,MAAM,CAAC,OAAgB;IA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