@sayknow-cli/coding-agent 0.7.11 → 0.7.13

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.
Files changed (427) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/types/async/result-formatting.d.ts +2 -0
  3. package/dist/types/capability/fs.d.ts +22 -3
  4. package/dist/types/capability/mcp.d.ts +2 -0
  5. package/dist/types/cli/append-system-prompt.d.ts +6 -0
  6. package/dist/types/cli/update-cli.d.ts +3 -0
  7. package/dist/types/commands/contribution-prep.d.ts +0 -3
  8. package/dist/types/commands/migrate.d.ts +1 -1
  9. package/dist/types/commands/sdk.d.ts +9 -0
  10. package/dist/types/commit/changelog/index.d.ts +1 -0
  11. package/dist/types/config/settings-schema.d.ts +14 -0
  12. package/dist/types/config/settings.d.ts +7 -1
  13. package/dist/types/coordinator-mcp/session-reaper.d.ts +5 -0
  14. package/dist/types/cursor-delete-path.d.ts +1 -0
  15. package/dist/types/cursor-mcp-name.d.ts +8 -0
  16. package/dist/types/dap/config.d.ts +8 -4
  17. package/dist/types/dap/session.d.ts +11 -2
  18. package/dist/types/debug/report-bundle-parent.d.ts +2 -0
  19. package/dist/types/debug/system-info.d.ts +6 -1
  20. package/dist/types/discovery/helpers.d.ts +11 -3
  21. package/dist/types/discovery/mcp-json.d.ts +1 -0
  22. package/dist/types/edit/file-read-cache.d.ts +4 -0
  23. package/dist/types/edit/modes/patch.d.ts +14 -0
  24. package/dist/types/edit/modes/replace.d.ts +8 -0
  25. package/dist/types/eval/py/runtime.d.ts +9 -0
  26. package/dist/types/exa/mcp-client.d.ts +11 -6
  27. package/dist/types/exec/bash-executor.d.ts +18 -1
  28. package/dist/types/export/html/css-color.d.ts +2 -0
  29. package/dist/types/export/html/html-export-destination.d.ts +2 -0
  30. package/dist/types/export/html/template.generated.d.ts +1 -1
  31. package/dist/types/extensibility/custom-tools/loader.d.ts +3 -2
  32. package/dist/types/extensibility/custom-tools/types.d.ts +3 -1
  33. package/dist/types/extensibility/plugins/marketplace/cache.d.ts +2 -0
  34. package/dist/types/extensibility/plugins/plugin-link-path.d.ts +2 -0
  35. package/dist/types/goals/runtime.d.ts +6 -0
  36. package/dist/types/harness-control-plane/receipt-spool.d.ts +4 -0
  37. package/dist/types/hindsight/content.d.ts +5 -6
  38. package/dist/types/internal-urls/skill-path.d.ts +1 -0
  39. package/dist/types/internal-urls/types.d.ts +2 -0
  40. package/dist/types/lsp/clients/swiftlint-client.d.ts +0 -4
  41. package/dist/types/lsp/config.d.ts +8 -5
  42. package/dist/types/lsp/workspace-path.d.ts +1 -0
  43. package/dist/types/migrate/adapters/codex.d.ts +2 -1
  44. package/dist/types/migrate/adapters/index.d.ts +10 -1
  45. package/dist/types/migrate/executor.d.ts +3 -1
  46. package/dist/types/migrate/types.d.ts +15 -3
  47. package/dist/types/modes/components/custom-editor.d.ts +6 -0
  48. package/dist/types/modes/components/extensions/state-manager.d.ts +4 -3
  49. package/dist/types/modes/components/model-selector.d.ts +46 -0
  50. package/dist/types/modes/controllers/input-controller.d.ts +9 -0
  51. package/dist/types/modes/interactive-mode.d.ts +1 -0
  52. package/dist/types/modes/utils/macos-option-forwarding.d.ts +17 -0
  53. package/dist/types/runtime-mcp/content-limits.d.ts +4 -0
  54. package/dist/types/runtime-mcp/manager.d.ts +9 -1
  55. package/dist/types/runtime-mcp/mcp-redirect.d.ts +9 -0
  56. package/dist/types/runtime-mcp/oauth-public-url.d.ts +1 -0
  57. package/dist/types/runtime-mcp/plugin-mcp-name-filter.d.ts +22 -0
  58. package/dist/types/runtime-mcp/plugin-network-boundary.d.ts +1 -0
  59. package/dist/types/runtime-mcp/project-host-values.d.ts +33 -0
  60. package/dist/types/runtime-mcp/smithery-registry.d.ts +24 -0
  61. package/dist/types/runtime-mcp/tool-bridge.d.ts +4 -0
  62. package/dist/types/runtime-mcp/types.d.ts +6 -0
  63. package/dist/types/sdk/broker/ensure.d.ts +2 -0
  64. package/dist/types/sdk/broker/lifecycle-ledger.d.ts +5 -1
  65. package/dist/types/sdk/broker/runtime.d.ts +1 -1
  66. package/dist/types/sdk/bus/chat-daemon-control.d.ts +3 -1
  67. package/dist/types/sdk/bus/telegram-daemon-contract.d.ts +3 -1
  68. package/dist/types/sdk/bus/telegram-daemon.d.ts +1 -0
  69. package/dist/types/sdk/host/events.d.ts +4 -0
  70. package/dist/types/session/agent-session.d.ts +22 -2
  71. package/dist/types/session/auto-resume.d.ts +5 -0
  72. package/dist/types/session/messages.d.ts +5 -1
  73. package/dist/types/session/session-manager.d.ts +13 -0
  74. package/dist/types/session/session-storage.d.ts +8 -0
  75. package/dist/types/session/streaming-output.d.ts +11 -0
  76. package/dist/types/session-import/redact.d.ts +1 -1
  77. package/dist/types/skc-runtime/managed-owner-admission.d.ts +3 -0
  78. package/dist/types/skc-runtime/psmux-detect.d.ts +5 -4
  79. package/dist/types/skc-runtime/ralplan-runtime.d.ts +5 -0
  80. package/dist/types/skc-runtime/sidecar-bootstrap-env.d.ts +6 -0
  81. package/dist/types/skc-runtime/state-writer.d.ts +4 -1
  82. package/dist/types/skc-runtime/tmux-sessions.d.ts +24 -0
  83. package/dist/types/skc-runtime/ultragoal-runtime.d.ts +4 -0
  84. package/dist/types/skill-state/workflow-mutation-guard.d.ts +20 -1
  85. package/dist/types/slash-commands/helpers/mcp.d.ts +5 -0
  86. package/dist/types/ssh/ssh-executor.d.ts +3 -1
  87. package/dist/types/system-prompt.d.ts +5 -2
  88. package/dist/types/task/executor.d.ts +17 -3
  89. package/dist/types/task/isolation-dir.d.ts +26 -0
  90. package/dist/types/task/role-body.d.ts +11 -0
  91. package/dist/types/task/token-log-mode.test.d.ts +1 -0
  92. package/dist/types/tools/ask.d.ts +77 -254
  93. package/dist/types/tools/ast-edit-write-path.d.ts +23 -0
  94. package/dist/types/tools/atomic-file-write.d.ts +74 -0
  95. package/dist/types/tools/auto-generated-guard.d.ts +5 -2
  96. package/dist/types/tools/bash-allowed-prefixes.d.ts +16 -0
  97. package/dist/types/tools/bash-interactive.d.ts +2 -0
  98. package/dist/types/tools/bash-skill-urls.d.ts +5 -1
  99. package/dist/types/tools/bash.d.ts +1 -0
  100. package/dist/types/tools/browser/cdp-url.d.ts +2 -0
  101. package/dist/types/tools/browser/tab-worker.d.ts +2 -0
  102. package/dist/types/tools/debug.d.ts +2 -2
  103. package/dist/types/tools/explicit-artifact.d.ts +8 -0
  104. package/dist/types/tools/fetch.d.ts +7 -4
  105. package/dist/types/tools/github-side-effect.d.ts +22 -0
  106. package/dist/types/tools/index.d.ts +3 -0
  107. package/dist/types/tools/monitor-mutation.d.ts +9 -0
  108. package/dist/types/tools/recipe/index.d.ts +2 -0
  109. package/dist/types/tools/recipe/recipe-guard.d.ts +7 -0
  110. package/dist/types/tools/restricted-cwd.d.ts +1 -0
  111. package/dist/types/tools/reverse-engineer.d.ts +81 -0
  112. package/dist/types/tools/search-tool-bm25.d.ts +2 -0
  113. package/dist/types/tools/tmux-self-injection-guard.d.ts +17 -0
  114. package/dist/types/tools/untrusted-content.d.ts +12 -0
  115. package/dist/types/utils/file-mentions.d.ts +5 -0
  116. package/dist/types/utils/open.d.ts +0 -1
  117. package/dist/types/utils/shell-snapshot.d.ts +2 -0
  118. package/dist/types/utils/title-generator.d.ts +12 -2
  119. package/dist/types/utils/tools-checksum.d.ts +7 -0
  120. package/dist/types/utils/xml-escape.d.ts +2 -0
  121. package/dist/types/web/scrapers/types.d.ts +8 -1
  122. package/dist/types/web/search/providers/codex.d.ts +6 -7
  123. package/dist/types/web/search/providers/insane.d.ts +7 -1
  124. package/dist/types/web/search/providers/kimi.d.ts +2 -0
  125. package/dist/types/web/search/providers/searxng.d.ts +7 -0
  126. package/dist/types/web/search/providers/xai.d.ts +2 -0
  127. package/package.json +7 -7
  128. package/scripts/generate-sdk-operation-inventory.ts +4 -0
  129. package/src/async/job-manager.ts +23 -9
  130. package/src/async/result-formatting.ts +40 -0
  131. package/src/capability/fs.ts +78 -11
  132. package/src/capability/mcp.ts +2 -0
  133. package/src/cli/append-system-prompt.ts +12 -0
  134. package/src/cli/auth-broker-cli.ts +22 -12
  135. package/src/cli/config-cli.ts +8 -18
  136. package/src/cli/migrate-cli.ts +7 -5
  137. package/src/cli/ssh-cli.ts +6 -3
  138. package/src/cli/stats-cli.ts +9 -4
  139. package/src/cli/update-cli.ts +42 -0
  140. package/src/cli/web-search-cli.ts +9 -3
  141. package/src/cli.ts +5 -9
  142. package/src/commands/commit.ts +2 -2
  143. package/src/commands/contribution-prep.ts +1 -3
  144. package/src/commands/harness.ts +25 -15
  145. package/src/commands/launch.ts +1 -1
  146. package/src/commands/migrate.ts +3 -3
  147. package/src/commands/sdk.ts +115 -14
  148. package/src/commands/ultragoal.ts +14 -8
  149. package/src/commit/agentic/agent.ts +6 -6
  150. package/src/commit/analysis/conventional.ts +14 -5
  151. package/src/commit/changelog/index.ts +39 -1
  152. package/src/commit/message.ts +10 -3
  153. package/src/config/config-file.ts +106 -3
  154. package/src/config/keybindings.ts +154 -7
  155. package/src/config/mcp-schema.json +4 -0
  156. package/src/config/model-registry.ts +10 -2
  157. package/src/config/settings-schema.ts +18 -0
  158. package/src/config/settings.ts +32 -4
  159. package/src/coordinator-mcp/policy.ts +14 -4
  160. package/src/coordinator-mcp/server.ts +44 -4
  161. package/src/coordinator-mcp/session-reaper.ts +9 -1
  162. package/src/cursor-delete-path.ts +10 -0
  163. package/src/cursor-mcp-name.ts +15 -0
  164. package/src/cursor.ts +13 -2
  165. package/src/dap/client.ts +9 -2
  166. package/src/dap/config.ts +33 -13
  167. package/src/dap/defaults.json +1 -1
  168. package/src/dap/session.ts +161 -36
  169. package/src/debug/crash-diagnostics.ts +89 -6
  170. package/src/debug/report-bundle-parent.ts +22 -0
  171. package/src/debug/report-bundle.ts +100 -3
  172. package/src/debug/system-info.ts +21 -4
  173. package/src/defaults/skc/extensions/grok-cli-vendor/src/shared/base-url.ts +21 -7
  174. package/src/defaults/skc/skills/deep-interview/SKILL.md +1 -1
  175. package/src/discovery/agents-md.ts +3 -2
  176. package/src/discovery/agents.ts +3 -2
  177. package/src/discovery/builtin.ts +21 -11
  178. package/src/discovery/claude.ts +5 -4
  179. package/src/discovery/cline.ts +2 -2
  180. package/src/discovery/codex.ts +6 -5
  181. package/src/discovery/cursor.ts +11 -2
  182. package/src/discovery/gemini.ts +4 -3
  183. package/src/discovery/github.ts +2 -2
  184. package/src/discovery/helpers.ts +51 -11
  185. package/src/discovery/mcp-json.ts +28 -12
  186. package/src/discovery/opencode.ts +2 -1
  187. package/src/discovery/ssh.ts +11 -6
  188. package/src/discovery/substitute-plugin-root.ts +3 -1
  189. package/src/discovery/vscode.ts +3 -3
  190. package/src/edit/apply-patch/index.ts +12 -1
  191. package/src/edit/file-read-cache.ts +24 -6
  192. package/src/edit/index.ts +90 -20
  193. package/src/edit/modes/patch.ts +215 -9
  194. package/src/edit/modes/replace.ts +141 -0
  195. package/src/eval/js/context-manager.ts +29 -3
  196. package/src/eval/js/worker-entry.ts +51 -18
  197. package/src/eval/py/runner.py +144 -5
  198. package/src/eval/py/runtime.ts +44 -4
  199. package/src/eval/py/tool-bridge.ts +4 -0
  200. package/src/exa/mcp-client.ts +53 -11
  201. package/src/exec/bash-executor.ts +87 -4
  202. package/src/exec/non-interactive-env.ts +0 -1
  203. package/src/export/html/css-color.ts +9 -0
  204. package/src/export/html/html-export-destination.ts +16 -0
  205. package/src/export/html/index.ts +102 -8
  206. package/src/export/html/template.generated.ts +1 -1
  207. package/src/extensibility/custom-tools/loader.ts +13 -3
  208. package/src/extensibility/custom-tools/types.ts +3 -1
  209. package/src/extensibility/custom-tools/wrapper.ts +3 -1
  210. package/src/extensibility/plugins/manager.ts +3 -2
  211. package/src/extensibility/plugins/marketplace/cache.ts +15 -0
  212. package/src/extensibility/plugins/marketplace/fetcher.ts +2 -2
  213. package/src/extensibility/plugins/marketplace/manager.ts +5 -3
  214. package/src/extensibility/plugins/plugin-link-path.ts +12 -0
  215. package/src/extensibility/skc-plugins/mcp-policy.ts +2 -1
  216. package/src/goals/runtime.ts +30 -8
  217. package/src/harness-control-plane/finalize.ts +10 -0
  218. package/src/harness-control-plane/operate.ts +12 -4
  219. package/src/harness-control-plane/owner.ts +8 -1
  220. package/src/harness-control-plane/receipt-spool.ts +105 -28
  221. package/src/harness-control-plane/storage.ts +124 -6
  222. package/src/hashline/execute.ts +3 -3
  223. package/src/hashline/recovery.ts +85 -2
  224. package/src/hindsight/config.ts +9 -3
  225. package/src/hindsight/content.ts +116 -16
  226. package/src/hindsight/mental-models.ts +22 -10
  227. package/src/hindsight/state.ts +7 -4
  228. package/src/hooks/native-skill-hook.ts +17 -12
  229. package/src/i18n/messages/de.settings.ts +3 -0
  230. package/src/i18n/messages/es.settings.ts +3 -0
  231. package/src/i18n/messages/fr.settings.ts +3 -0
  232. package/src/i18n/messages/ja.settings.ts +3 -0
  233. package/src/i18n/messages/ko.settings.ts +3 -0
  234. package/src/i18n/messages/zh.settings.ts +3 -0
  235. package/src/internal-urls/artifact-protocol.ts +3 -1
  236. package/src/internal-urls/docs-index.generated.ts +10 -10
  237. package/src/internal-urls/local-protocol.ts +167 -8
  238. package/src/internal-urls/skill-path.ts +18 -0
  239. package/src/internal-urls/skill-protocol.ts +2 -0
  240. package/src/internal-urls/types.ts +2 -0
  241. package/src/lsp/client.ts +2 -1
  242. package/src/lsp/clients/biome-client.ts +2 -0
  243. package/src/lsp/clients/swiftlint-client.ts +2 -0
  244. package/src/lsp/config.ts +18 -62
  245. package/src/lsp/edits.ts +6 -0
  246. package/src/lsp/index.ts +29 -0
  247. package/src/lsp/workspace-path.ts +75 -0
  248. package/src/main.ts +33 -11
  249. package/src/memories/index.ts +141 -9
  250. package/src/migrate/action-planner.ts +57 -0
  251. package/src/migrate/adapters/claude-code.ts +23 -4
  252. package/src/migrate/adapters/codex.ts +22 -4
  253. package/src/migrate/adapters/index.ts +22 -4
  254. package/src/migrate/adapters/opencode.ts +6 -1
  255. package/src/migrate/executor.ts +84 -7
  256. package/src/migrate/report.ts +19 -2
  257. package/src/migrate/types.ts +14 -4
  258. package/src/modes/DESIGN.md +5 -0
  259. package/src/modes/acp/acp-agent.ts +35 -2
  260. package/src/modes/acp/permission-mode.ts +18 -1
  261. package/src/modes/components/custom-editor.ts +14 -0
  262. package/src/modes/components/extensions/extension-dashboard.ts +2 -2
  263. package/src/modes/components/extensions/inspector-panel.ts +9 -5
  264. package/src/modes/components/extensions/state-manager.ts +15 -5
  265. package/src/modes/components/model-selector.ts +144 -94
  266. package/src/modes/components/welcome.ts +3 -2
  267. package/src/modes/controllers/command-controller.ts +300 -9
  268. package/src/modes/controllers/event-controller.ts +1 -1
  269. package/src/modes/controllers/extension-ui-controller.ts +32 -19
  270. package/src/modes/controllers/input-controller.ts +62 -26
  271. package/src/modes/controllers/plan-mode-controller.ts +17 -7
  272. package/src/modes/controllers/runtime-mcp-command-controller.ts +25 -20
  273. package/src/modes/controllers/ssh-command-controller.ts +3 -1
  274. package/src/modes/interactive-mode.ts +10 -0
  275. package/src/modes/utils/macos-option-forwarding.ts +80 -0
  276. package/src/prompts/system/irc-incoming.md +3 -1
  277. package/src/prompts/system/project-prompt.md +19 -0
  278. package/src/prompts/system/system-prompt.md +3 -0
  279. package/src/prompts/tools/ask.md +2 -0
  280. package/src/prompts/tools/debug.md +1 -1
  281. package/src/prompts/tools/monitor.md +7 -5
  282. package/src/prompts/tools/reverse-engineer.md +29 -0
  283. package/src/runtime-credential-selector.ts +2 -2
  284. package/src/runtime-mcp/config-writer.ts +10 -6
  285. package/src/runtime-mcp/config.ts +1 -0
  286. package/src/runtime-mcp/content-limits.ts +7 -0
  287. package/src/runtime-mcp/json-rpc.ts +2 -1
  288. package/src/runtime-mcp/manager.ts +57 -9
  289. package/src/runtime-mcp/mcp-redirect.ts +73 -0
  290. package/src/runtime-mcp/oauth-flow.ts +43 -5
  291. package/src/runtime-mcp/oauth-public-url.ts +8 -0
  292. package/src/runtime-mcp/plugin-mcp-name-filter.ts +62 -0
  293. package/src/runtime-mcp/plugin-network-boundary.ts +4 -0
  294. package/src/runtime-mcp/project-host-values.ts +50 -0
  295. package/src/runtime-mcp/render.ts +16 -1
  296. package/src/runtime-mcp/smithery-registry.ts +22 -3
  297. package/src/runtime-mcp/tool-bridge.ts +194 -21
  298. package/src/runtime-mcp/transports/http.ts +4 -3
  299. package/src/runtime-mcp/transports/stdio.ts +2 -1
  300. package/src/runtime-mcp/types.ts +6 -0
  301. package/src/sdk/broker/broker.ts +11 -2
  302. package/src/sdk/broker/ensure.ts +131 -10
  303. package/src/sdk/broker/lifecycle-ledger.ts +18 -3
  304. package/src/sdk/broker/lifecycle.ts +21 -19
  305. package/src/sdk/broker/runtime.ts +1 -1
  306. package/src/sdk/bus/chat-daemon-cli.ts +38 -1
  307. package/src/sdk/bus/chat-daemon-control.ts +5 -3
  308. package/src/sdk/bus/index.ts +5 -3
  309. package/src/sdk/bus/lifecycle-control-runtime.ts +9 -2
  310. package/src/sdk/bus/session-control.ts +2 -0
  311. package/src/sdk/bus/slack-daemon.ts +8 -1
  312. package/src/sdk/bus/slack-live-provider.ts +3 -1
  313. package/src/sdk/bus/telegram-daemon-contract.ts +3 -1
  314. package/src/sdk/bus/telegram-daemon-control.ts +17 -12
  315. package/src/sdk/bus/telegram-daemon.ts +41 -1
  316. package/src/sdk/host/events.ts +67 -4
  317. package/src/sdk/mcp/server.ts +16 -3
  318. package/src/sdk/protocol/operation-inventory.generated.json +22 -0
  319. package/src/sdk/session.ts +18 -25
  320. package/src/secrets/obfuscator.ts +92 -12
  321. package/src/session/agent-session.ts +466 -100
  322. package/src/session/artifacts.ts +3 -1
  323. package/src/session/auto-resume.ts +45 -8
  324. package/src/session/history-storage.ts +172 -8
  325. package/src/session/internal/managed-session-scope.ts +130 -52
  326. package/src/session/messages.ts +47 -6
  327. package/src/session/session-manager.ts +116 -8
  328. package/src/session/session-storage.ts +31 -1
  329. package/src/session/streaming-output.ts +263 -4
  330. package/src/session-import/redact.ts +76 -3
  331. package/src/setup/hermes-setup.ts +4 -1
  332. package/src/skc-runtime/gc-runtime.ts +26 -4
  333. package/src/skc-runtime/launch-tmux.ts +21 -11
  334. package/src/skc-runtime/launch-worktree.ts +42 -3
  335. package/src/skc-runtime/managed-owner-admission.ts +46 -2
  336. package/src/skc-runtime/psmux-detect.ts +29 -5
  337. package/src/skc-runtime/ralplan-runtime.ts +14 -1
  338. package/src/skc-runtime/session-resolution.ts +38 -6
  339. package/src/skc-runtime/sidecar-bootstrap-env.ts +19 -0
  340. package/src/skc-runtime/state-writer.ts +134 -16
  341. package/src/skc-runtime/tmux-sessions.ts +85 -4
  342. package/src/skc-runtime/ultragoal-change-set.ts +18 -2
  343. package/src/skc-runtime/ultragoal-guard.ts +9 -1
  344. package/src/skc-runtime/ultragoal-runtime.ts +26 -9
  345. package/src/skill-state/active-state.ts +13 -0
  346. package/src/skill-state/workflow-mutation-guard.ts +3297 -180
  347. package/src/slash-commands/builtin-registry.ts +14 -8
  348. package/src/slash-commands/helpers/mcp.ts +20 -7
  349. package/src/ssh/ssh-executor.ts +3 -1
  350. package/src/stt/recorder.ts +26 -9
  351. package/src/system-prompt.ts +65 -16
  352. package/src/task/commands.ts +3 -1
  353. package/src/task/executor.ts +52 -7
  354. package/src/task/index.ts +28 -0
  355. package/src/task/isolation-dir.ts +143 -0
  356. package/src/task/role-body.ts +84 -0
  357. package/src/task/token-log-mode.test.ts +162 -0
  358. package/src/task/token-log.ts +91 -2
  359. package/src/task/worktree.ts +16 -7
  360. package/src/tools/archive-reader.ts +653 -31
  361. package/src/tools/ask.ts +86 -14
  362. package/src/tools/ast-edit-write-path.ts +133 -0
  363. package/src/tools/ast-edit.ts +27 -1
  364. package/src/tools/ast-grep.ts +7 -2
  365. package/src/tools/atomic-file-write.ts +625 -0
  366. package/src/tools/auto-generated-guard.ts +28 -8
  367. package/src/tools/bash-allowed-prefixes.ts +225 -6
  368. package/src/tools/bash-interactive.ts +12 -0
  369. package/src/tools/bash-skill-urls.ts +113 -7
  370. package/src/tools/bash.ts +152 -20
  371. package/src/tools/browser/cdp-url.ts +18 -0
  372. package/src/tools/browser/tab-worker.ts +49 -14
  373. package/src/tools/browser.ts +25 -8
  374. package/src/tools/cron.ts +10 -1
  375. package/src/tools/debug.ts +16 -8
  376. package/src/tools/eval.ts +71 -34
  377. package/src/tools/explicit-artifact.ts +89 -0
  378. package/src/tools/fetch.ts +26 -17
  379. package/src/tools/gh.ts +40 -12
  380. package/src/tools/github-side-effect.ts +112 -0
  381. package/src/tools/image-gen.ts +24 -10
  382. package/src/tools/index.ts +6 -0
  383. package/src/tools/monitor-mutation.ts +27 -0
  384. package/src/tools/monitor.ts +28 -1
  385. package/src/tools/output-meta.ts +74 -5
  386. package/src/tools/read.ts +24 -36
  387. package/src/tools/recipe/index.ts +12 -0
  388. package/src/tools/recipe/recipe-guard.ts +19 -0
  389. package/src/tools/recipe/runner.ts +23 -12
  390. package/src/tools/render-utils.ts +2 -2
  391. package/src/tools/restricted-cwd.ts +10 -0
  392. package/src/tools/reverse-engineer.ts +497 -0
  393. package/src/tools/search-tool-bm25.ts +14 -3
  394. package/src/tools/search.ts +3 -2
  395. package/src/tools/ssh.ts +235 -8
  396. package/src/tools/subagent-render.ts +43 -7
  397. package/src/tools/subagent.ts +7 -3
  398. package/src/tools/tmux-self-injection-guard.ts +3538 -0
  399. package/src/tools/todo-write.ts +41 -3
  400. package/src/tools/untrusted-content.ts +23 -0
  401. package/src/tools/vim.ts +2 -2
  402. package/src/tools/write.ts +37 -4
  403. package/src/tui/tree-list.ts +15 -1
  404. package/src/utils/commit-message-generator.ts +9 -2
  405. package/src/utils/external-editor.ts +21 -7
  406. package/src/utils/file-mentions.ts +75 -7
  407. package/src/utils/git.ts +38 -7
  408. package/src/utils/open.ts +73 -4
  409. package/src/utils/shell-snapshot.ts +9 -1
  410. package/src/utils/title-generator.ts +61 -16
  411. package/src/utils/tools-checksum.ts +34 -0
  412. package/src/utils/tools-manager.ts +24 -6
  413. package/src/utils/xml-escape.ts +14 -0
  414. package/src/web/insane/url-guard.ts +2 -1
  415. package/src/web/scrapers/types.ts +8 -0
  416. package/src/web/scrapers/youtube.ts +3 -2
  417. package/src/web/search/index.ts +4 -3
  418. package/src/web/search/providers/anthropic.ts +4 -4
  419. package/src/web/search/providers/codex.ts +31 -34
  420. package/src/web/search/providers/insane.ts +145 -28
  421. package/src/web/search/providers/kimi.ts +15 -5
  422. package/src/web/search/providers/searxng.ts +47 -4
  423. package/src/web/search/providers/xai.ts +7 -2
  424. package/dist/types/cli/shell-cli.d.ts +0 -8
  425. package/dist/types/commands/shell.d.ts +0 -21
  426. package/src/cli/shell-cli.ts +0 -176
  427. package/src/commands/shell.ts +0 -29
@@ -14,6 +14,7 @@ import {
14
14
  type ManagedSessionDescendantStore,
15
15
  publishManagedFileNoReplace,
16
16
  } from "./internal/managed-session-storage";
17
+ import { writeExplicitOwnerOnlyTextSync } from "./session-storage";
17
18
  import { DEFAULT_ARTIFACT_MAX_BYTES, truncateHeadBytes } from "./streaming-output";
18
19
 
19
20
  export interface ManagedOutputGeneration {
@@ -138,7 +139,8 @@ export class ArtifactManager {
138
139
  if (!/^[a-zA-Z0-9_.-]+$/.test(filename)) throw new Error("Unsafe named artifact");
139
140
  await this.#ensureDir();
140
141
  if (this.#store) await this.#store.replace(filename, Buffer.from(content, "utf8"));
141
- else await Bun.write(path.join(this.#dir, filename), content);
142
+ // Named files, including draft.txt, are created here.
143
+ else writeExplicitOwnerOnlyTextSync(path.join(this.#dir, filename), content);
142
144
  }
143
145
 
144
146
  async replaceNamedBytes(filename: string, bytes: Uint8Array): Promise<void> {
@@ -72,6 +72,38 @@ export function isThinkingOnlyFailure(message: AgentMessage | undefined): boolea
72
72
  return thinking;
73
73
  }
74
74
 
75
+ /**
76
+ * A failed attempt cut off before any answer text whose only public content is tool
77
+ * calls: the loop runs tools only after a stream completes, so these calls never ran
78
+ * and only got placeholder results. Like a reasoning-only failure it holds no answer;
79
+ * recovery drops it with those placeholders and asks the same model again.
80
+ */
81
+ function isUnexecutedToolCallFailure(message: AgentMessage): boolean {
82
+ if (message.role !== "assistant" || message.stopReason !== "error") return false;
83
+ let toolCall = false;
84
+ for (const block of message.content) {
85
+ if (block.type === "toolCall") toolCall = true;
86
+ else if (block.type === "text" && block.text.trim().length > 0) return false;
87
+ }
88
+ return toolCall;
89
+ }
90
+
91
+ /**
92
+ * The transcript before its trailing unexecuted tool-call failure, without the error
93
+ * placeholder results paired with its calls; undefined when the tail is anything else.
94
+ */
95
+ export function dropUnexecutedToolCallFailure(messages: readonly AgentMessage[]): AgentMessage[] | undefined {
96
+ const index = messages.findLastIndex(message => message.role === "assistant");
97
+ if (index === -1) return undefined;
98
+ const failed = messages[index];
99
+ if (failed.role !== "assistant" || !isUnexecutedToolCallFailure(failed)) return undefined;
100
+ const callIds = new Set(failed.content.flatMap(block => (block.type === "toolCall" ? [block.id] : [])));
101
+ for (const message of messages.slice(index + 1)) {
102
+ if (message.role !== "toolResult" || !message.isError || !callIds.has(message.toolCallId)) return undefined;
103
+ }
104
+ return messages.slice(0, index);
105
+ }
106
+
75
107
  /** Built-in tools whose execution has no side effects and may run again after a restart. */
76
108
  const RESTART_SAFE_TOOL_CLASSES = [ReadTool, SearchTool, FindTool, AstGrepTool, LocateTool] as const;
77
109
 
@@ -129,7 +161,8 @@ export function findInterruptedToolCalls(messages: readonly AgentMessage[]): Too
129
161
  * Tails that cannot be resumed safely: a failed step holding private signed reasoning
130
162
  * next to an answer or tool calls (possibly cut off mid-arguments), a call without an
131
163
  * id, or unanswered calls whose results could no longer be placed directly after their
132
- * assistant. A failure that streamed only reasoning is dropped before resuming instead.
164
+ * assistant. A failure that streamed only reasoning, or tool calls that never ran, is
165
+ * dropped before resuming instead.
133
166
  */
134
167
  function hasUnsafeAssistantTail(messages: readonly AgentMessage[]): boolean {
135
168
  const assistantIndex = messages.findLastIndex(message => message.role === "assistant");
@@ -194,14 +227,18 @@ export function resolveAutoResumePolicy(input: AutoResumePolicyInput): AutoResum
194
227
  if (input.userInputPending) return { type: "pause", reason: "user_input_pending" };
195
228
  if (!input.selectorAvailable) return { type: "pause", reason: "selector_unavailable" };
196
229
  if (!input.budgetAdmits) return { type: "pause", reason: "budget_exhausted" };
197
- if (hasUnsafeAssistantTail(input.messages)) return { type: "pause", reason: "unsafe_tail" };
198
- if (hasVisibleFailedPrefix(input.messages) && !input.prefixReplayable)
199
- return { type: "pause", reason: "unsafe_tail" };
200
- const tail = input.messages.at(-1);
230
+ // Tool calls cut off by the failure never ran: the attempt is dropped before resuming,
231
+ // so only the transcript before it is judged.
232
+ const withoutAttempt = dropUnexecutedToolCallFailure(input.messages);
233
+ const messages = withoutAttempt ?? input.messages;
234
+ if (hasUnsafeAssistantTail(messages)) return { type: "pause", reason: "unsafe_tail" };
235
+ if (hasVisibleFailedPrefix(messages) && !input.prefixReplayable) return { type: "pause", reason: "unsafe_tail" };
236
+ const tail = messages.at(-1);
201
237
  if (!tail) return { type: "pause", reason: "not_interrupted" };
202
- // Only a restart can find a user message whose request never settled.
238
+ // Only a restart can find a user message whose request never settled, unless the
239
+ // failed attempt answering it was just dropped.
203
240
  if (tail.role === "user") {
204
- return input.trigger === "restart"
241
+ return input.trigger === "restart" || withoutAttempt
205
242
  ? { type: "resume", mode: "full", interruptedCalls: [] }
206
243
  : { type: "pause", reason: "not_interrupted" };
207
244
  }
@@ -210,7 +247,7 @@ export function resolveAutoResumePolicy(input: AutoResumePolicyInput): AutoResum
210
247
  const settled = !tail.content.some(block => block.type === "toolCall");
211
248
  if (settled) return { type: "pause", reason: "not_interrupted" };
212
249
  }
213
- const interruptedCalls = findInterruptedToolCalls(input.messages);
250
+ const interruptedCalls = findInterruptedToolCalls(messages);
214
251
  if (interruptedCalls.length === 0) return { type: "resume", mode: "full", interruptedCalls };
215
252
  if (!input.selectedTools.some(tool => isRestartSafeTool(tool, input.selectedTools))) {
216
253
  return { type: "pause", reason: "no_restart_safe_tools" };
@@ -25,6 +25,155 @@ function escapeLikePattern(text: string): string {
25
25
  return text.replace(/[\\%_]/g, "\\$&");
26
26
  }
27
27
 
28
+ const HISTORY_SUFFIXES = ["", "-wal", "-shm"] as const;
29
+ let openingHistory: Database | undefined;
30
+
31
+ function secureHistoryPath(pathname: string, kind: "directory" | "file"): void {
32
+ if (process.platform !== "win32") return;
33
+ const native = require("@sayknow-cli/natives") as typeof import("@sayknow-cli/natives");
34
+ const applied = native.applyOwnerOnlyPathSecurity(pathname, kind);
35
+ const verified = native.verifyOwnerOnlyPathSecurity(pathname, kind);
36
+ if (applied?.ok !== true || verified?.ok !== true) {
37
+ throw new Error("history database owner-only protection could not be established");
38
+ }
39
+ }
40
+
41
+ function historyErrno(error: unknown): string | undefined {
42
+ return (error as NodeJS.ErrnoException | undefined)?.code;
43
+ }
44
+
45
+ function historyLeaf(dbPath: string, suffix: string): fs.BigIntStats | undefined {
46
+ try {
47
+ return fs.lstatSync(`${dbPath}${suffix}`, { bigint: true });
48
+ } catch (error) {
49
+ if (historyErrno(error) !== "ENOENT") throw error;
50
+ return undefined;
51
+ }
52
+ }
53
+
54
+ function assertRegularHistoryLeaf(existing: fs.BigIntStats | undefined): void {
55
+ if (existing && (existing.isSymbolicLink() || !existing.isFile())) {
56
+ throw new Error("history database path is not a regular file");
57
+ }
58
+ }
59
+
60
+ function assertHistoryLeaves(dbPath: string): Set<string> {
61
+ const present = new Set<string>();
62
+ for (const suffix of HISTORY_SUFFIXES) {
63
+ const existing = historyLeaf(dbPath, suffix);
64
+ assertRegularHistoryLeaf(existing);
65
+ if (existing) present.add(suffix);
66
+ }
67
+ return present;
68
+ }
69
+
70
+ function removeNewHistoryLeaves(): void {
71
+ // A WAL reader can stay live while BEGIN EXCLUSIVE succeeds, so failure
72
+ // cleanup must not unlink a database another opener has adopted.
73
+ try {
74
+ openingHistory?.close();
75
+ } catch {
76
+ // The caller reports the original open failure.
77
+ }
78
+ openingHistory = undefined;
79
+ }
80
+
81
+ function readHistoryDirectory(dir: string): fs.Stats | undefined {
82
+ let existing: fs.Stats;
83
+ try {
84
+ existing = fs.lstatSync(dir);
85
+ } catch (error) {
86
+ if (historyErrno(error) !== "ENOENT") throw error;
87
+ return undefined;
88
+ }
89
+ if (existing.isSymbolicLink() || !existing.isDirectory()) {
90
+ throw new Error("history database directory is not a real directory");
91
+ }
92
+ return existing;
93
+ }
94
+
95
+ function tightenHistoryDirectory(dir: string): void {
96
+ let existing = readHistoryDirectory(dir);
97
+ if (!existing) {
98
+ try {
99
+ fs.mkdirSync(dir, { recursive: true, mode: 0o700 });
100
+ } catch (error) {
101
+ if (historyErrno(error) !== "EEXIST") throw error;
102
+ }
103
+ existing = readHistoryDirectory(dir);
104
+ if (!existing) throw new Error("history database directory is not a real directory");
105
+ }
106
+ secureHistoryPath(dir, "directory");
107
+ if (process.platform === "win32") return;
108
+ // 0300/0700 are already owner-only. Sticky directories are shared and stay as they are.
109
+ // chmod(2) needs no read bit, so mode 0333 becomes 0700. A symlink swap is
110
+ // followed by chmod; the recheck then refuses and no database file is created.
111
+ if ((existing.mode & 0o077) === 0 || (existing.mode & 0o1000) !== 0) return;
112
+ try {
113
+ fs.chmodSync(dir, 0o700);
114
+ } catch (error) {
115
+ if (historyErrno(error) === "ELOOP") throw new Error("history database directory is not a real directory");
116
+ throw error;
117
+ }
118
+ const after = readHistoryDirectory(dir);
119
+ if (!after || (after.mode & 0o077) !== 0) {
120
+ throw new Error("history database directory could not be tightened to mode 0700");
121
+ }
122
+ }
123
+
124
+ function sameHistoryFile(left: fs.BigIntStats, right: fs.BigIntStats): boolean {
125
+ return left.dev === right.dev && left.ino === right.ino && left.nlink === right.nlink;
126
+ }
127
+
128
+ function restrictHistoryFiles(dbPath: string, createMissingDb: boolean): void {
129
+ const noFollow = process.platform === "win32" ? 0 : (fs.constants.O_NOFOLLOW ?? 0);
130
+ for (const suffix of HISTORY_SUFFIXES) {
131
+ const target = `${dbPath}${suffix}`;
132
+ let existing = historyLeaf(dbPath, suffix);
133
+ assertRegularHistoryLeaf(existing);
134
+ if (!existing && suffix === "" && createMissingDb) {
135
+ let created: number | undefined;
136
+ try {
137
+ created = fs.openSync(
138
+ target,
139
+ fs.constants.O_WRONLY | fs.constants.O_CREAT | fs.constants.O_EXCL | noFollow,
140
+ 0o600,
141
+ );
142
+ fs.fchmodSync(created, 0o600);
143
+ } catch (error) {
144
+ if (historyErrno(error) === "ELOOP") throw new Error("history database path is not a regular file");
145
+ if (historyErrno(error) !== "EEXIST") throw error;
146
+ } finally {
147
+ if (created !== undefined) fs.closeSync(created);
148
+ }
149
+ existing = historyLeaf(dbPath, suffix);
150
+ assertRegularHistoryLeaf(existing);
151
+ if (!existing) throw new Error("history database path is not a regular file");
152
+ }
153
+ if (!existing) continue;
154
+ secureHistoryPath(target, "file");
155
+ if (process.platform === "win32" || (Number(existing.mode) & 0o077) === 0) continue;
156
+ let fd: number | undefined;
157
+ try {
158
+ fd = fs.openSync(target, fs.constants.O_RDONLY | noFollow);
159
+ const opened = fs.fstatSync(fd, { bigint: true });
160
+ const again = historyLeaf(dbPath, suffix);
161
+ if (!again || !opened.isFile() || !sameHistoryFile(existing, opened) || !sameHistoryFile(opened, again)) {
162
+ throw new Error("history database path is not a regular file");
163
+ }
164
+ fs.fchmodSync(fd, 0o600);
165
+ if ((Number(fs.fstatSync(fd, { bigint: true }).mode) & 0o777) !== 0o600) {
166
+ throw new Error("history database path could not be tightened to mode 0600");
167
+ }
168
+ } catch (error) {
169
+ if (historyErrno(error) === "ELOOP") throw new Error("history database path is not a regular file");
170
+ throw error;
171
+ } finally {
172
+ if (fd !== undefined) fs.closeSync(fd);
173
+ }
174
+ }
175
+ }
176
+
28
177
  class AsyncDrain<T> {
29
178
  #queue?: T[];
30
179
  #promise = Promise.resolve();
@@ -80,9 +229,8 @@ export class HistoryStorage {
80
229
  #lastPromptCache: string | null = null;
81
230
 
82
231
  private constructor(dbPath: string) {
83
- this.#ensureDir(dbPath);
84
-
85
232
  this.#db = new Database(dbPath);
233
+ openingHistory = this.#db;
86
234
 
87
235
  const hasFts = this.#db.prepare("SELECT 1 FROM sqlite_master WHERE type='table' AND name='history_fts'").get();
88
236
 
@@ -137,11 +285,32 @@ CREATE TRIGGER IF NOT EXISTS history_ai AFTER INSERT ON history BEGIN
137
285
 
138
286
  const last = this.#lastPromptStmt.get() as { prompt?: string } | undefined;
139
287
  this.#lastPromptCache = last?.prompt ?? null;
288
+ try {
289
+ restrictHistoryFiles(dbPath, false);
290
+ } catch (error) {
291
+ this.#db.close();
292
+ throw error;
293
+ }
294
+ openingHistory = undefined;
295
+ }
296
+
297
+ static #openNew(dbPath: string): HistoryStorage {
298
+ openingHistory = undefined;
299
+ assertHistoryLeaves(dbPath);
300
+ try {
301
+ tightenHistoryDirectory(path.dirname(dbPath));
302
+ assertHistoryLeaves(dbPath);
303
+ restrictHistoryFiles(dbPath, true);
304
+ return new HistoryStorage(dbPath);
305
+ } catch (error) {
306
+ removeNewHistoryLeaves();
307
+ throw error;
308
+ }
140
309
  }
141
310
 
142
311
  static open(dbPath: string = getHistoryDbPath()): HistoryStorage {
143
312
  if (!HistoryStorage.#instance) {
144
- HistoryStorage.#instance = new HistoryStorage(dbPath);
313
+ HistoryStorage.#instance = HistoryStorage.#openNew(dbPath);
145
314
  }
146
315
  return HistoryStorage.#instance;
147
316
  }
@@ -241,11 +410,6 @@ CREATE TRIGGER IF NOT EXISTS history_ai AFTER INSERT ON history BEGIN
241
410
  return merged;
242
411
  }
243
412
 
244
- #ensureDir(dbPath: string): void {
245
- const dir = path.dirname(dbPath);
246
- fs.mkdirSync(dir, { recursive: true });
247
- }
248
-
249
413
  #historySchemaUsesUnixEpoch(): boolean {
250
414
  const row = this.#db.prepare("SELECT sql FROM sqlite_master WHERE type = 'table' AND name = 'history'").get() as
251
415
  | { sql?: string | null }
@@ -95,14 +95,22 @@ function bindManagedWriteAuthority(scope: ManagedScope, authority: ManagedCandid
95
95
  function assertRetainedManagedDirectoryIdentity(scope: ManagedScope): void {
96
96
  const expected = managedDirectoryIdentities.get(scope);
97
97
  if (!expected) return;
98
- const current = fs.lstatSync(scope.directoryPath, { bigint: true });
99
- if (
100
- !current.isDirectory() ||
101
- current.isSymbolicLink() ||
102
- current.dev !== expected.dev ||
103
- current.ino !== expected.ino
104
- )
105
- throw new Error("Managed session directory changed");
98
+ assertSameManagedDirectoryIdentity(fs.lstatSync(scope.directoryPath, { bigint: true }), expected);
99
+ }
100
+
101
+ /**
102
+ * Fence a managed directory to the identity it was bound with. The decision is
103
+ * the same for every mismatch; only the reported reason differs. The same
104
+ * inode on a different `dev` is the shape a remount, drive-letter change or
105
+ * volume-serial change leaves behind (#6750). It is still refused, because an
106
+ * inode is only unique within one volume, but it is named so an operator is
107
+ * not sent looking for a corrupted binding.
108
+ */
109
+ function assertSameManagedDirectoryIdentity(current: fs.BigIntStats, expected: { dev: bigint; ino: bigint }): void {
110
+ if (!current.isDirectory() || current.isSymbolicLink()) throw new Error("Managed session directory changed");
111
+ if (current.dev === expected.dev && current.ino === expected.ino) return;
112
+ if (current.ino === expected.ino) throw new Error("volume_identity_changed");
113
+ throw new Error("Managed session directory changed");
106
114
  }
107
115
 
108
116
  export function managedDirectoryAuthorityForScope(scope: ManagedScope): native.RecoveryFsRoot | undefined {
@@ -746,7 +754,8 @@ function listDirectoryCandidates(
746
754
  try {
747
755
  directoryStat = fs.lstatSync(directory);
748
756
  } catch (error) {
749
- if ((error as NodeJS.ErrnoException).code === "ENOENT") return [];
757
+ const code = (error as NodeJS.ErrnoException).code;
758
+ if (code === "ENOENT" || (provenance === "legacy" && code === "ENAMETOOLONG")) return [];
750
759
  throw error;
751
760
  }
752
761
  if (!directoryStat.isDirectory() || directoryStat.isSymbolicLink()) throw new Error("unsafe directory");
@@ -948,13 +957,7 @@ export function prepareManagedSessionScopeForWriteSync(
948
957
  const validated = validateBindingRaw(scope, capturedBinding.bytes.toString("utf8"));
949
958
  managedDirectoryAuthorities.set(scope, retainedAuthority);
950
959
  const directoryStat = fs.lstatSync(scope.directoryPath, { bigint: true });
951
- if (
952
- !directoryStat.isDirectory() ||
953
- directoryStat.isSymbolicLink() ||
954
- directoryStat.dev !== preparedDirectory.dev ||
955
- directoryStat.ino !== preparedDirectory.ino
956
- )
957
- throw new Error("Managed session directory changed");
960
+ assertSameManagedDirectoryIdentity(directoryStat, preparedDirectory);
958
961
  managedDirectoryIdentities.set(scope, { dev: preparedDirectory.dev, ino: preparedDirectory.ino });
959
962
  if (validated) return validated;
960
963
  const internal = managedInternalDirectory(scope);
@@ -1053,7 +1056,8 @@ export function listManagedCandidates(
1053
1056
  }
1054
1057
  }
1055
1058
  }
1056
- const visible = owned.filter(candidate => !isRetired(scope, candidate));
1059
+ const retired = owned.length > 0 ? retiredTargetKeys(scope) : new Set<string>();
1060
+ const visible = owned.filter(candidate => !isRetiredIn(retired, candidate));
1057
1061
  const active = visible.filter(
1058
1062
  candidate =>
1059
1063
  candidate.provenance === "v2" ||
@@ -2158,8 +2162,96 @@ function tombstonePathContaining(scope: ManagedScope, candidate: ManagedCandidat
2158
2162
  return undefined;
2159
2163
  }
2160
2164
 
2161
- function isRetired(scope: ManagedScope, candidate: ManagedCandidate): boolean {
2165
+ /**
2166
+ * Identity fields a retired tombstone target must match exactly for a candidate
2167
+ * to be hidden. `dev`, `ino`, and `mtimeNs` are persisted as decimal strings.
2168
+ */
2169
+ type RetiredTargetIdentity = readonly [
2170
+ path: string,
2171
+ sessionId: string,
2172
+ cwd: string,
2173
+ canonicalPath: string,
2174
+ dev: string,
2175
+ ino: string,
2176
+ size: number,
2177
+ mtimeNs: string,
2178
+ sha256: string,
2179
+ ];
2180
+
2181
+ function candidateRetiredIdentity(candidate: ManagedCandidate): RetiredTargetIdentity {
2182
+ return [
2183
+ candidate.path,
2184
+ candidate.sessionId,
2185
+ candidate.cwd,
2186
+ candidate.identity.canonicalPath,
2187
+ String(candidate.identity.dev),
2188
+ String(candidate.identity.ino),
2189
+ candidate.identity.size,
2190
+ String(candidate.identity.mtimeNs),
2191
+ candidate.identity.sha256,
2192
+ ];
2193
+ }
2194
+
2195
+ /** Returns the target's identity only when every field has the type a candidate can carry. */
2196
+ function parseRetiredTargetIdentity(target: unknown): RetiredTargetIdentity | undefined {
2197
+ if (!target || typeof target !== "object") return undefined;
2198
+ const value = target as { path?: unknown; sessionId?: unknown; cwd?: unknown; identity?: unknown };
2199
+ if (!value.identity || typeof value.identity !== "object") return undefined;
2200
+ const identity = value.identity as {
2201
+ canonicalPath?: unknown;
2202
+ dev?: unknown;
2203
+ ino?: unknown;
2204
+ size?: unknown;
2205
+ mtimeNs?: unknown;
2206
+ sha256?: unknown;
2207
+ };
2208
+ if (
2209
+ typeof value.path !== "string" ||
2210
+ typeof value.sessionId !== "string" ||
2211
+ typeof value.cwd !== "string" ||
2212
+ typeof identity.canonicalPath !== "string" ||
2213
+ typeof identity.dev !== "string" ||
2214
+ typeof identity.ino !== "string" ||
2215
+ typeof identity.size !== "number" ||
2216
+ typeof identity.mtimeNs !== "string" ||
2217
+ typeof identity.sha256 !== "string"
2218
+ )
2219
+ return undefined;
2220
+ return [
2221
+ value.path,
2222
+ value.sessionId,
2223
+ value.cwd,
2224
+ identity.canonicalPath,
2225
+ identity.dev,
2226
+ identity.ino,
2227
+ identity.size,
2228
+ identity.mtimeNs,
2229
+ identity.sha256,
2230
+ ];
2231
+ }
2232
+
2233
+ /**
2234
+ * Key equality matches strict equality of every member: strings and finite
2235
+ * numbers encode distinctly. A non-finite tombstone `size` encodes as `null`,
2236
+ * which no candidate produces.
2237
+ */
2238
+ function retiredIdentityKey(identity: RetiredTargetIdentity): string {
2239
+ return JSON.stringify(identity);
2240
+ }
2241
+
2242
+ /**
2243
+ * Snapshot of the identities retired by a scope's tombstones.
2244
+ *
2245
+ * Tombstones are visited in directory order and the walk stops at the first
2246
+ * unreadable or malformed one: it grants no retirement authority, and neither do
2247
+ * the tombstones after it. Listing builds this once and checks every candidate
2248
+ * against it, so its cost is linear in tombstones rather than in
2249
+ * candidates x tombstones.
2250
+ */
2251
+ function retiredTargetKeys(scope: ManagedScope): ReadonlySet<string> {
2252
+ const keys = new Set<string>();
2162
2253
  const directory = path.join(managedInternalDirectory(scope), MANAGED_TOMBSTONES_DIRECTORY);
2254
+ const digest = scopeDigest(scope.platform, scope.canonicalCwd);
2163
2255
  try {
2164
2256
  for (const name of fs.readdirSync(directory)) {
2165
2257
  const pathname = path.join(directory, name);
@@ -2169,47 +2261,27 @@ function isRetired(scope: ManagedScope, candidate: ManagedCandidate): boolean {
2169
2261
  if (
2170
2262
  record.schemaVersion !== 2 ||
2171
2263
  record.state !== "retired" ||
2172
- record.scope !== scopeDigest(scope.platform, scope.canonicalCwd) ||
2264
+ record.scope !== digest ||
2173
2265
  !Array.isArray(record.targets)
2174
2266
  )
2175
2267
  continue;
2176
- if (
2177
- record.targets.some(target => {
2178
- if (!target || typeof target !== "object") return false;
2179
- const value = target as {
2180
- path?: unknown;
2181
- sessionId?: unknown;
2182
- cwd?: unknown;
2183
- identity?: {
2184
- canonicalPath?: unknown;
2185
- dev?: unknown;
2186
- ino?: unknown;
2187
- size?: unknown;
2188
- mtimeNs?: unknown;
2189
- sha256?: unknown;
2190
- };
2191
- };
2192
- const identity = value.identity;
2193
- if (!identity) return false;
2194
- return (
2195
- value.path === candidate.path &&
2196
- value.sessionId === candidate.sessionId &&
2197
- value.cwd === candidate.cwd &&
2198
- identity.canonicalPath === candidate.identity.canonicalPath &&
2199
- identity.dev === String(candidate.identity.dev) &&
2200
- identity.ino === String(candidate.identity.ino) &&
2201
- identity.size === candidate.identity.size &&
2202
- identity.mtimeNs === String(candidate.identity.mtimeNs) &&
2203
- identity.sha256 === candidate.identity.sha256
2204
- );
2205
- })
2206
- )
2207
- return true;
2268
+ for (const target of record.targets) {
2269
+ const identity = parseRetiredTargetIdentity(target);
2270
+ if (identity) keys.add(retiredIdentityKey(identity));
2271
+ }
2208
2272
  }
2209
2273
  } catch {
2210
2274
  /* a missing/malformed tombstone grants no retirement authority */
2211
2275
  }
2212
- return false;
2276
+ return keys;
2277
+ }
2278
+
2279
+ function isRetiredIn(retired: ReadonlySet<string>, candidate: ManagedCandidate): boolean {
2280
+ return retired.has(retiredIdentityKey(candidateRetiredIdentity(candidate)));
2281
+ }
2282
+
2283
+ function isRetired(scope: ManagedScope, candidate: ManagedCandidate): boolean {
2284
+ return isRetiredIn(retiredTargetKeys(scope), candidate);
2213
2285
  }
2214
2286
 
2215
2287
  type ArtifactManifestEntry =
@@ -2868,6 +2940,12 @@ export async function reconcileManagedTombstones(
2868
2940
  expectedCandidate?: ManagedCandidate,
2869
2941
  ): Promise<void> {
2870
2942
  const directory = path.join(managedInternalDirectory(scope), MANAGED_TOMBSTONES_DIRECTORY);
2943
+ // Ensure scope authority is prepared before any operations that might access the GC protocol
2944
+ const prepared = await ensureManagedScope(
2945
+ scope,
2946
+ scope.platform === "win32" ? "windows-existing-verify-first" : "default",
2947
+ );
2948
+ if (prepared.kind === "error") throw new Error(prepared.message);
2871
2949
  for (const name of fs.readdirSync(directory)) {
2872
2950
  const tombstone = path.join(directory, name);
2873
2951
  const targets = retiredTargets(scope, tombstone);
@@ -218,6 +218,34 @@ function getPrunedToolResultContent(message: ToolResultMessage): (TextContent |
218
218
  export const PRE_ADMISSION_ARTIFACT_SPILL_HEAD_BYTES = 4096;
219
219
  export const PRE_ADMISSION_ARTIFACT_SPILL_TAIL_BYTES = 4096;
220
220
 
221
+ /**
222
+ * Keep an authenticated `#SKC1_` placeholder whole when the byte cut lands
223
+ * inside it. Short inputs whose head and tail already overlap stay on the
224
+ * original byte limits.
225
+ */
226
+ function retainStraddlingPlaceholders(text: string, head: string, tail: string): { head: string; tail: string } {
227
+ const headEnd = head.length;
228
+ const tailStart = text.length - tail.length;
229
+ if (headEnd > tailStart) return { head, tail };
230
+
231
+ let nextHeadEnd = headEnd;
232
+ let nextTailStart = tailStart;
233
+ const placeholder = /#SKC1_[A-Za-z0-9_-]{22}#/g;
234
+ for (;;) {
235
+ const match = placeholder.exec(text);
236
+ if (match === null) break;
237
+ const start = match.index;
238
+ const stop = start + match[0].length;
239
+ if (start < headEnd && stop > headEnd) nextHeadEnd = Math.max(nextHeadEnd, stop);
240
+ if (start < tailStart && stop > tailStart) nextTailStart = Math.min(nextTailStart, start);
241
+ }
242
+ if (nextHeadEnd > nextTailStart) return { head, tail };
243
+ return {
244
+ head: nextHeadEnd === headEnd ? head : text.slice(0, nextHeadEnd),
245
+ tail: nextTailStart === tailStart ? tail : text.slice(nextTailStart),
246
+ };
247
+ }
248
+
221
249
  function utf8Prefix(text: string, maxBytes: number): string {
222
250
  if (Buffer.byteLength(text, "utf-8") <= maxBytes) return text;
223
251
  let bytes = 0;
@@ -253,15 +281,28 @@ function utf8Suffix(text: string, maxBytes: number): string {
253
281
  * Build the deterministic inline receipt for a tool result saved before the
254
282
  * next provider context is constructed. Byte boundaries never split UTF-8
255
283
  * code points, so head/tail recovery remains readable for emoji and CJK text.
284
+ *
285
+ * `redact` runs on the complete text before the cut. The digest stays the
286
+ * caller's hash of the stored artifact; the omitted count is the redacted
287
+ * preview's omitted bytes.
256
288
  */
257
- export function createPreAdmissionArtifactSpillPreview(fullText: string, artifactId: string, digest: string): string {
258
- const totalBytes = Buffer.byteLength(fullText, "utf-8");
259
- const head = utf8Prefix(fullText, PRE_ADMISSION_ARTIFACT_SPILL_HEAD_BYTES);
260
- const tail = utf8Suffix(fullText, PRE_ADMISSION_ARTIFACT_SPILL_TAIL_BYTES);
261
- const retainedBytes = Buffer.byteLength(head, "utf-8") + Buffer.byteLength(tail, "utf-8");
289
+ export function createPreAdmissionArtifactSpillPreview(
290
+ fullText: string,
291
+ artifactId: string,
292
+ digest: string,
293
+ redact?: (text: string) => string,
294
+ ): string {
295
+ const source = redact ? redact(fullText) : fullText;
296
+ const totalBytes = Buffer.byteLength(source, "utf-8");
297
+ const head = utf8Prefix(source, PRE_ADMISSION_ARTIFACT_SPILL_HEAD_BYTES);
298
+ const tail = utf8Suffix(source, PRE_ADMISSION_ARTIFACT_SPILL_TAIL_BYTES);
299
+ // Without redaction the cut stays on the historical byte limits, including
300
+ // when the tool text itself contains a placeholder-shaped string.
301
+ const retained = redact ? retainStraddlingPlaceholders(source, head, tail) : { head, tail };
302
+ const retainedBytes = Buffer.byteLength(retained.head, "utf-8") + Buffer.byteLength(retained.tail, "utf-8");
262
303
  const omittedBytes = Math.max(0, totalBytes - retainedBytes);
263
304
  const receipt = `[${omittedBytes} bytes omitted; sha256:${digest}; full output: artifact://${artifactId}]`;
264
- return `${head}\n\n${receipt}\n\n${tail}`;
305
+ return `${retained.head}\n\n${receipt}\n\n${retained.tail}`;
265
306
  }
266
307
 
267
308
  /**