@sayknow-cli/coding-agent 0.7.11 → 0.7.12

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 (425) hide show
  1. package/CHANGELOG.md +10 -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 +20 -1
  71. package/dist/types/session/messages.d.ts +5 -1
  72. package/dist/types/session/session-manager.d.ts +13 -0
  73. package/dist/types/session/session-storage.d.ts +8 -0
  74. package/dist/types/session/streaming-output.d.ts +11 -0
  75. package/dist/types/session-import/redact.d.ts +1 -1
  76. package/dist/types/skc-runtime/managed-owner-admission.d.ts +3 -0
  77. package/dist/types/skc-runtime/psmux-detect.d.ts +5 -4
  78. package/dist/types/skc-runtime/ralplan-runtime.d.ts +5 -0
  79. package/dist/types/skc-runtime/sidecar-bootstrap-env.d.ts +6 -0
  80. package/dist/types/skc-runtime/state-writer.d.ts +4 -1
  81. package/dist/types/skc-runtime/tmux-sessions.d.ts +24 -0
  82. package/dist/types/skc-runtime/ultragoal-runtime.d.ts +4 -0
  83. package/dist/types/skill-state/workflow-mutation-guard.d.ts +20 -1
  84. package/dist/types/slash-commands/helpers/mcp.d.ts +5 -0
  85. package/dist/types/ssh/ssh-executor.d.ts +3 -1
  86. package/dist/types/system-prompt.d.ts +5 -2
  87. package/dist/types/task/executor.d.ts +17 -3
  88. package/dist/types/task/isolation-dir.d.ts +26 -0
  89. package/dist/types/task/role-body.d.ts +11 -0
  90. package/dist/types/task/token-log-mode.test.d.ts +1 -0
  91. package/dist/types/tools/ask.d.ts +77 -254
  92. package/dist/types/tools/ast-edit-write-path.d.ts +23 -0
  93. package/dist/types/tools/atomic-file-write.d.ts +74 -0
  94. package/dist/types/tools/auto-generated-guard.d.ts +5 -2
  95. package/dist/types/tools/bash-allowed-prefixes.d.ts +16 -0
  96. package/dist/types/tools/bash-interactive.d.ts +2 -0
  97. package/dist/types/tools/bash-skill-urls.d.ts +5 -1
  98. package/dist/types/tools/bash.d.ts +1 -0
  99. package/dist/types/tools/browser/cdp-url.d.ts +2 -0
  100. package/dist/types/tools/browser/tab-worker.d.ts +2 -0
  101. package/dist/types/tools/debug.d.ts +2 -2
  102. package/dist/types/tools/explicit-artifact.d.ts +8 -0
  103. package/dist/types/tools/fetch.d.ts +7 -4
  104. package/dist/types/tools/github-side-effect.d.ts +22 -0
  105. package/dist/types/tools/index.d.ts +3 -0
  106. package/dist/types/tools/monitor-mutation.d.ts +9 -0
  107. package/dist/types/tools/recipe/index.d.ts +2 -0
  108. package/dist/types/tools/recipe/recipe-guard.d.ts +7 -0
  109. package/dist/types/tools/restricted-cwd.d.ts +1 -0
  110. package/dist/types/tools/reverse-engineer.d.ts +81 -0
  111. package/dist/types/tools/search-tool-bm25.d.ts +2 -0
  112. package/dist/types/tools/tmux-self-injection-guard.d.ts +17 -0
  113. package/dist/types/tools/untrusted-content.d.ts +12 -0
  114. package/dist/types/utils/file-mentions.d.ts +5 -0
  115. package/dist/types/utils/open.d.ts +0 -1
  116. package/dist/types/utils/shell-snapshot.d.ts +2 -0
  117. package/dist/types/utils/title-generator.d.ts +12 -2
  118. package/dist/types/utils/tools-checksum.d.ts +7 -0
  119. package/dist/types/utils/xml-escape.d.ts +2 -0
  120. package/dist/types/web/scrapers/types.d.ts +8 -1
  121. package/dist/types/web/search/providers/codex.d.ts +6 -7
  122. package/dist/types/web/search/providers/insane.d.ts +7 -1
  123. package/dist/types/web/search/providers/kimi.d.ts +2 -0
  124. package/dist/types/web/search/providers/searxng.d.ts +7 -0
  125. package/dist/types/web/search/providers/xai.d.ts +2 -0
  126. package/package.json +7 -7
  127. package/scripts/generate-sdk-operation-inventory.ts +4 -0
  128. package/src/async/job-manager.ts +23 -9
  129. package/src/async/result-formatting.ts +40 -0
  130. package/src/capability/fs.ts +78 -11
  131. package/src/capability/mcp.ts +2 -0
  132. package/src/cli/append-system-prompt.ts +12 -0
  133. package/src/cli/auth-broker-cli.ts +22 -12
  134. package/src/cli/config-cli.ts +8 -18
  135. package/src/cli/migrate-cli.ts +7 -5
  136. package/src/cli/ssh-cli.ts +6 -3
  137. package/src/cli/stats-cli.ts +9 -4
  138. package/src/cli/update-cli.ts +42 -0
  139. package/src/cli/web-search-cli.ts +9 -3
  140. package/src/cli.ts +5 -9
  141. package/src/commands/commit.ts +2 -2
  142. package/src/commands/contribution-prep.ts +1 -3
  143. package/src/commands/harness.ts +25 -15
  144. package/src/commands/launch.ts +1 -1
  145. package/src/commands/migrate.ts +3 -3
  146. package/src/commands/sdk.ts +115 -14
  147. package/src/commands/ultragoal.ts +14 -8
  148. package/src/commit/agentic/agent.ts +6 -6
  149. package/src/commit/analysis/conventional.ts +14 -5
  150. package/src/commit/changelog/index.ts +39 -1
  151. package/src/commit/message.ts +10 -3
  152. package/src/config/config-file.ts +106 -3
  153. package/src/config/keybindings.ts +154 -7
  154. package/src/config/mcp-schema.json +4 -0
  155. package/src/config/model-registry.ts +10 -2
  156. package/src/config/settings-schema.ts +18 -0
  157. package/src/config/settings.ts +32 -4
  158. package/src/coordinator-mcp/policy.ts +14 -4
  159. package/src/coordinator-mcp/server.ts +44 -4
  160. package/src/coordinator-mcp/session-reaper.ts +9 -1
  161. package/src/cursor-delete-path.ts +10 -0
  162. package/src/cursor-mcp-name.ts +15 -0
  163. package/src/cursor.ts +13 -2
  164. package/src/dap/client.ts +9 -2
  165. package/src/dap/config.ts +33 -13
  166. package/src/dap/defaults.json +1 -1
  167. package/src/dap/session.ts +161 -36
  168. package/src/debug/crash-diagnostics.ts +89 -6
  169. package/src/debug/report-bundle-parent.ts +22 -0
  170. package/src/debug/report-bundle.ts +100 -3
  171. package/src/debug/system-info.ts +21 -4
  172. package/src/defaults/skc/extensions/grok-cli-vendor/src/shared/base-url.ts +21 -7
  173. package/src/defaults/skc/skills/deep-interview/SKILL.md +1 -1
  174. package/src/discovery/agents-md.ts +3 -2
  175. package/src/discovery/agents.ts +3 -2
  176. package/src/discovery/builtin.ts +21 -11
  177. package/src/discovery/claude.ts +5 -4
  178. package/src/discovery/cline.ts +2 -2
  179. package/src/discovery/codex.ts +6 -5
  180. package/src/discovery/cursor.ts +11 -2
  181. package/src/discovery/gemini.ts +4 -3
  182. package/src/discovery/github.ts +2 -2
  183. package/src/discovery/helpers.ts +51 -11
  184. package/src/discovery/mcp-json.ts +28 -12
  185. package/src/discovery/opencode.ts +2 -1
  186. package/src/discovery/ssh.ts +11 -6
  187. package/src/discovery/substitute-plugin-root.ts +3 -1
  188. package/src/discovery/vscode.ts +3 -3
  189. package/src/edit/apply-patch/index.ts +12 -1
  190. package/src/edit/file-read-cache.ts +24 -6
  191. package/src/edit/index.ts +90 -20
  192. package/src/edit/modes/patch.ts +215 -9
  193. package/src/edit/modes/replace.ts +141 -0
  194. package/src/eval/js/context-manager.ts +29 -3
  195. package/src/eval/js/worker-entry.ts +51 -18
  196. package/src/eval/py/runner.py +144 -5
  197. package/src/eval/py/runtime.ts +44 -4
  198. package/src/eval/py/tool-bridge.ts +4 -0
  199. package/src/exa/mcp-client.ts +53 -11
  200. package/src/exec/bash-executor.ts +87 -4
  201. package/src/exec/non-interactive-env.ts +0 -1
  202. package/src/export/html/css-color.ts +9 -0
  203. package/src/export/html/html-export-destination.ts +16 -0
  204. package/src/export/html/index.ts +102 -8
  205. package/src/export/html/template.generated.ts +1 -1
  206. package/src/extensibility/custom-tools/loader.ts +13 -3
  207. package/src/extensibility/custom-tools/types.ts +3 -1
  208. package/src/extensibility/custom-tools/wrapper.ts +3 -1
  209. package/src/extensibility/plugins/manager.ts +3 -2
  210. package/src/extensibility/plugins/marketplace/cache.ts +15 -0
  211. package/src/extensibility/plugins/marketplace/fetcher.ts +2 -2
  212. package/src/extensibility/plugins/marketplace/manager.ts +5 -3
  213. package/src/extensibility/plugins/plugin-link-path.ts +12 -0
  214. package/src/extensibility/skc-plugins/mcp-policy.ts +2 -1
  215. package/src/goals/runtime.ts +30 -8
  216. package/src/harness-control-plane/finalize.ts +10 -0
  217. package/src/harness-control-plane/operate.ts +12 -4
  218. package/src/harness-control-plane/owner.ts +8 -1
  219. package/src/harness-control-plane/receipt-spool.ts +105 -28
  220. package/src/harness-control-plane/storage.ts +124 -6
  221. package/src/hashline/execute.ts +3 -3
  222. package/src/hashline/recovery.ts +85 -2
  223. package/src/hindsight/config.ts +9 -3
  224. package/src/hindsight/content.ts +116 -16
  225. package/src/hindsight/mental-models.ts +22 -10
  226. package/src/hindsight/state.ts +7 -4
  227. package/src/hooks/native-skill-hook.ts +17 -12
  228. package/src/i18n/messages/de.settings.ts +3 -0
  229. package/src/i18n/messages/es.settings.ts +3 -0
  230. package/src/i18n/messages/fr.settings.ts +3 -0
  231. package/src/i18n/messages/ja.settings.ts +3 -0
  232. package/src/i18n/messages/ko.settings.ts +3 -0
  233. package/src/i18n/messages/zh.settings.ts +3 -0
  234. package/src/internal-urls/artifact-protocol.ts +3 -1
  235. package/src/internal-urls/docs-index.generated.ts +10 -10
  236. package/src/internal-urls/local-protocol.ts +167 -8
  237. package/src/internal-urls/skill-path.ts +18 -0
  238. package/src/internal-urls/skill-protocol.ts +2 -0
  239. package/src/internal-urls/types.ts +2 -0
  240. package/src/lsp/client.ts +2 -1
  241. package/src/lsp/clients/biome-client.ts +2 -0
  242. package/src/lsp/clients/swiftlint-client.ts +2 -0
  243. package/src/lsp/config.ts +18 -62
  244. package/src/lsp/edits.ts +6 -0
  245. package/src/lsp/index.ts +29 -0
  246. package/src/lsp/workspace-path.ts +75 -0
  247. package/src/main.ts +33 -11
  248. package/src/memories/index.ts +141 -9
  249. package/src/migrate/action-planner.ts +57 -0
  250. package/src/migrate/adapters/claude-code.ts +23 -4
  251. package/src/migrate/adapters/codex.ts +22 -4
  252. package/src/migrate/adapters/index.ts +22 -4
  253. package/src/migrate/adapters/opencode.ts +6 -1
  254. package/src/migrate/executor.ts +84 -7
  255. package/src/migrate/report.ts +19 -2
  256. package/src/migrate/types.ts +14 -4
  257. package/src/modes/DESIGN.md +5 -0
  258. package/src/modes/acp/acp-agent.ts +35 -2
  259. package/src/modes/acp/permission-mode.ts +18 -1
  260. package/src/modes/components/custom-editor.ts +14 -0
  261. package/src/modes/components/extensions/extension-dashboard.ts +2 -2
  262. package/src/modes/components/extensions/inspector-panel.ts +9 -5
  263. package/src/modes/components/extensions/state-manager.ts +15 -5
  264. package/src/modes/components/model-selector.ts +144 -94
  265. package/src/modes/components/welcome.ts +3 -2
  266. package/src/modes/controllers/command-controller.ts +300 -9
  267. package/src/modes/controllers/event-controller.ts +1 -1
  268. package/src/modes/controllers/extension-ui-controller.ts +32 -19
  269. package/src/modes/controllers/input-controller.ts +62 -26
  270. package/src/modes/controllers/plan-mode-controller.ts +17 -7
  271. package/src/modes/controllers/runtime-mcp-command-controller.ts +25 -20
  272. package/src/modes/controllers/ssh-command-controller.ts +3 -1
  273. package/src/modes/interactive-mode.ts +10 -0
  274. package/src/modes/utils/macos-option-forwarding.ts +80 -0
  275. package/src/prompts/system/irc-incoming.md +3 -1
  276. package/src/prompts/system/project-prompt.md +19 -0
  277. package/src/prompts/system/system-prompt.md +3 -0
  278. package/src/prompts/tools/ask.md +2 -0
  279. package/src/prompts/tools/debug.md +1 -1
  280. package/src/prompts/tools/monitor.md +7 -5
  281. package/src/prompts/tools/reverse-engineer.md +29 -0
  282. package/src/runtime-credential-selector.ts +2 -2
  283. package/src/runtime-mcp/config-writer.ts +10 -6
  284. package/src/runtime-mcp/config.ts +1 -0
  285. package/src/runtime-mcp/content-limits.ts +7 -0
  286. package/src/runtime-mcp/json-rpc.ts +2 -1
  287. package/src/runtime-mcp/manager.ts +57 -9
  288. package/src/runtime-mcp/mcp-redirect.ts +73 -0
  289. package/src/runtime-mcp/oauth-flow.ts +43 -5
  290. package/src/runtime-mcp/oauth-public-url.ts +8 -0
  291. package/src/runtime-mcp/plugin-mcp-name-filter.ts +62 -0
  292. package/src/runtime-mcp/plugin-network-boundary.ts +4 -0
  293. package/src/runtime-mcp/project-host-values.ts +50 -0
  294. package/src/runtime-mcp/render.ts +16 -1
  295. package/src/runtime-mcp/smithery-registry.ts +22 -3
  296. package/src/runtime-mcp/tool-bridge.ts +194 -21
  297. package/src/runtime-mcp/transports/http.ts +4 -3
  298. package/src/runtime-mcp/transports/stdio.ts +2 -1
  299. package/src/runtime-mcp/types.ts +6 -0
  300. package/src/sdk/broker/broker.ts +11 -2
  301. package/src/sdk/broker/ensure.ts +131 -10
  302. package/src/sdk/broker/lifecycle-ledger.ts +18 -3
  303. package/src/sdk/broker/lifecycle.ts +21 -19
  304. package/src/sdk/broker/runtime.ts +1 -1
  305. package/src/sdk/bus/chat-daemon-cli.ts +38 -1
  306. package/src/sdk/bus/chat-daemon-control.ts +5 -3
  307. package/src/sdk/bus/index.ts +5 -3
  308. package/src/sdk/bus/lifecycle-control-runtime.ts +9 -2
  309. package/src/sdk/bus/session-control.ts +2 -0
  310. package/src/sdk/bus/slack-daemon.ts +8 -1
  311. package/src/sdk/bus/slack-live-provider.ts +3 -1
  312. package/src/sdk/bus/telegram-daemon-contract.ts +3 -1
  313. package/src/sdk/bus/telegram-daemon-control.ts +17 -12
  314. package/src/sdk/bus/telegram-daemon.ts +41 -1
  315. package/src/sdk/host/events.ts +67 -4
  316. package/src/sdk/mcp/server.ts +16 -3
  317. package/src/sdk/protocol/operation-inventory.generated.json +22 -0
  318. package/src/sdk/session.ts +18 -25
  319. package/src/secrets/obfuscator.ts +92 -12
  320. package/src/session/agent-session.ts +395 -79
  321. package/src/session/artifacts.ts +3 -1
  322. package/src/session/history-storage.ts +172 -8
  323. package/src/session/internal/managed-session-scope.ts +130 -52
  324. package/src/session/messages.ts +47 -6
  325. package/src/session/session-manager.ts +116 -8
  326. package/src/session/session-storage.ts +31 -1
  327. package/src/session/streaming-output.ts +263 -4
  328. package/src/session-import/redact.ts +76 -3
  329. package/src/setup/hermes-setup.ts +4 -1
  330. package/src/skc-runtime/gc-runtime.ts +26 -4
  331. package/src/skc-runtime/launch-tmux.ts +21 -11
  332. package/src/skc-runtime/launch-worktree.ts +42 -3
  333. package/src/skc-runtime/managed-owner-admission.ts +46 -2
  334. package/src/skc-runtime/psmux-detect.ts +29 -5
  335. package/src/skc-runtime/ralplan-runtime.ts +14 -1
  336. package/src/skc-runtime/session-resolution.ts +38 -6
  337. package/src/skc-runtime/sidecar-bootstrap-env.ts +19 -0
  338. package/src/skc-runtime/state-writer.ts +134 -16
  339. package/src/skc-runtime/tmux-sessions.ts +85 -4
  340. package/src/skc-runtime/ultragoal-change-set.ts +18 -2
  341. package/src/skc-runtime/ultragoal-guard.ts +9 -1
  342. package/src/skc-runtime/ultragoal-runtime.ts +26 -9
  343. package/src/skill-state/active-state.ts +13 -0
  344. package/src/skill-state/workflow-mutation-guard.ts +3297 -180
  345. package/src/slash-commands/builtin-registry.ts +14 -8
  346. package/src/slash-commands/helpers/mcp.ts +20 -7
  347. package/src/ssh/ssh-executor.ts +3 -1
  348. package/src/stt/recorder.ts +26 -9
  349. package/src/system-prompt.ts +65 -16
  350. package/src/task/commands.ts +3 -1
  351. package/src/task/executor.ts +52 -7
  352. package/src/task/index.ts +28 -0
  353. package/src/task/isolation-dir.ts +143 -0
  354. package/src/task/role-body.ts +84 -0
  355. package/src/task/token-log-mode.test.ts +162 -0
  356. package/src/task/token-log.ts +91 -2
  357. package/src/task/worktree.ts +16 -7
  358. package/src/tools/archive-reader.ts +653 -31
  359. package/src/tools/ask.ts +86 -14
  360. package/src/tools/ast-edit-write-path.ts +133 -0
  361. package/src/tools/ast-edit.ts +27 -1
  362. package/src/tools/ast-grep.ts +7 -2
  363. package/src/tools/atomic-file-write.ts +625 -0
  364. package/src/tools/auto-generated-guard.ts +28 -8
  365. package/src/tools/bash-allowed-prefixes.ts +225 -6
  366. package/src/tools/bash-interactive.ts +12 -0
  367. package/src/tools/bash-skill-urls.ts +113 -7
  368. package/src/tools/bash.ts +152 -20
  369. package/src/tools/browser/cdp-url.ts +18 -0
  370. package/src/tools/browser/tab-worker.ts +49 -14
  371. package/src/tools/browser.ts +25 -8
  372. package/src/tools/cron.ts +10 -1
  373. package/src/tools/debug.ts +16 -8
  374. package/src/tools/eval.ts +71 -34
  375. package/src/tools/explicit-artifact.ts +89 -0
  376. package/src/tools/fetch.ts +26 -17
  377. package/src/tools/gh.ts +40 -12
  378. package/src/tools/github-side-effect.ts +112 -0
  379. package/src/tools/image-gen.ts +24 -10
  380. package/src/tools/index.ts +6 -0
  381. package/src/tools/monitor-mutation.ts +27 -0
  382. package/src/tools/monitor.ts +28 -1
  383. package/src/tools/output-meta.ts +74 -5
  384. package/src/tools/read.ts +24 -36
  385. package/src/tools/recipe/index.ts +12 -0
  386. package/src/tools/recipe/recipe-guard.ts +19 -0
  387. package/src/tools/recipe/runner.ts +23 -12
  388. package/src/tools/render-utils.ts +2 -2
  389. package/src/tools/restricted-cwd.ts +10 -0
  390. package/src/tools/reverse-engineer.ts +497 -0
  391. package/src/tools/search-tool-bm25.ts +14 -3
  392. package/src/tools/search.ts +3 -2
  393. package/src/tools/ssh.ts +235 -8
  394. package/src/tools/subagent-render.ts +43 -7
  395. package/src/tools/subagent.ts +7 -3
  396. package/src/tools/tmux-self-injection-guard.ts +3538 -0
  397. package/src/tools/todo-write.ts +41 -3
  398. package/src/tools/untrusted-content.ts +23 -0
  399. package/src/tools/vim.ts +2 -2
  400. package/src/tools/write.ts +37 -4
  401. package/src/tui/tree-list.ts +15 -1
  402. package/src/utils/commit-message-generator.ts +9 -2
  403. package/src/utils/external-editor.ts +21 -7
  404. package/src/utils/file-mentions.ts +75 -7
  405. package/src/utils/git.ts +38 -7
  406. package/src/utils/open.ts +73 -4
  407. package/src/utils/shell-snapshot.ts +9 -1
  408. package/src/utils/title-generator.ts +61 -16
  409. package/src/utils/tools-checksum.ts +34 -0
  410. package/src/utils/tools-manager.ts +24 -6
  411. package/src/utils/xml-escape.ts +14 -0
  412. package/src/web/insane/url-guard.ts +2 -1
  413. package/src/web/scrapers/types.ts +8 -0
  414. package/src/web/scrapers/youtube.ts +3 -2
  415. package/src/web/search/index.ts +4 -3
  416. package/src/web/search/providers/anthropic.ts +4 -4
  417. package/src/web/search/providers/codex.ts +31 -34
  418. package/src/web/search/providers/insane.ts +145 -28
  419. package/src/web/search/providers/kimi.ts +15 -5
  420. package/src/web/search/providers/searxng.ts +47 -4
  421. package/src/web/search/providers/xai.ts +7 -2
  422. package/dist/types/cli/shell-cli.d.ts +0 -8
  423. package/dist/types/commands/shell.d.ts +0 -21
  424. package/src/cli/shell-cli.ts +0 -176
  425. package/src/commands/shell.ts +0 -29
@@ -1,5 +1,6 @@
1
1
  import { type ChildProcess, spawn } from "node:child_process";
2
2
  import { type BrokerDiscovery, brokerProcessIncarnation, readBrokerDiscovery } from "./discovery";
3
+ import { isProcessIncarnation } from "./process-incarnation";
3
4
  import { resolveSdkInternalSpawnCommand, type SdkInternalSpawnCommand } from "./runtime";
4
5
  export interface EnsureBrokerSettings {
5
6
  agentDir: string;
@@ -51,6 +52,8 @@ interface BrokerOwner {
51
52
  stop(): Promise<void>;
52
53
  canReuse(discovery: BrokerDiscovery | null): boolean;
53
54
  markReady(discovery: BrokerDiscovery): boolean;
55
+ /** Rebinds ownership to the broker identity a trampoline reported. */
56
+ setTarget(pid: number, incarnation: string): void;
54
57
  }
55
58
  type EnsureInitiator = "discovery" | "fixture-lease";
56
59
  type EnsureOutcome =
@@ -136,24 +139,72 @@ async function reapSpawnedBroker(child: ChildProcess, timing: ReapTiming = DEFAU
136
139
  throw new Error(`Detached SDK broker (pid ${child.pid}) did not exit after SIGKILL during reap.`);
137
140
  }
138
141
 
142
+ type BrokerIdentityObservation = "same" | "gone" | "unknown";
143
+
144
+ /**
145
+ * Observes a reported broker identity. A missing incarnation is only proof of
146
+ * exit when the kernel also reports ESRCH; an unreadable incarnation for a live
147
+ * PID stays unknown rather than being mistaken for a dead broker.
148
+ */
149
+ function observeBrokerIdentity(pid: number, incarnation: string): BrokerIdentityObservation {
150
+ const observed = brokerProcessIncarnation(pid);
151
+ if (observed === incarnation) return "same";
152
+ if (observed !== undefined) return "gone";
153
+ try {
154
+ process.kill(pid, 0);
155
+ return "unknown";
156
+ } catch (error) {
157
+ return (error as NodeJS.ErrnoException).code === "ESRCH" ? "gone" : "unknown";
158
+ }
159
+ }
160
+
161
+ /**
162
+ * Reaps a trampoline-reported broker. The retained child handle no longer owns
163
+ * it, so graceful shutdown cannot be observed: force termination keeps cleanup
164
+ * within the caller's bounded deadline while the identity check prevents PID reuse.
165
+ */
166
+ async function reapSpawnedBrokerIdentity(
167
+ pid: number,
168
+ incarnation: string,
169
+ timing: ReapTiming = DEFAULT_REAP_TIMING,
170
+ ): Promise<void> {
171
+ if (observeBrokerIdentity(pid, incarnation) !== "same") return;
172
+ try {
173
+ process.kill(pid, "SIGKILL");
174
+ } catch {
175
+ // already exited between identity check and signal delivery
176
+ }
177
+ const until = Date.now() + timing.killVerifyMs;
178
+ while (Date.now() < until) {
179
+ if (observeBrokerIdentity(pid, incarnation) === "gone") return;
180
+ await sleep(10);
181
+ }
182
+ if (observeBrokerIdentity(pid, incarnation) !== "gone")
183
+ throw new Error(`Detached SDK broker (pid ${pid}) did not exit after SIGKILL during reap.`);
184
+ }
185
+
139
186
  function registerBrokerOwner(
140
187
  agentDir: string,
141
188
  child: ChildProcess,
142
189
  timing: ReapTiming = DEFAULT_REAP_TIMING,
143
190
  ): BrokerOwner {
144
- const incarnation = child.pid === undefined ? undefined : brokerProcessIncarnation(child.pid);
191
+ let targetPid = child.pid;
192
+ let targetIncarnation = child.pid === undefined ? undefined : brokerProcessIncarnation(child.pid);
145
193
  let state: "starting" | "ready" | "cleanup-unverified" = "starting";
146
194
  const matches = (discovery: BrokerDiscovery | null): boolean =>
147
195
  Boolean(
148
196
  discovery &&
149
- child.pid !== undefined &&
150
- incarnation &&
151
- discovery.pid === child.pid &&
152
- discovery.incarnation === incarnation,
197
+ targetPid !== undefined &&
198
+ targetIncarnation &&
199
+ discovery.pid === targetPid &&
200
+ discovery.incarnation === targetIncarnation,
153
201
  );
154
202
  const owner: BrokerOwner = {
155
203
  async stop(): Promise<void> {
156
204
  try {
205
+ if (targetPid !== undefined && targetIncarnation !== undefined && targetPid !== child.pid)
206
+ await reapSpawnedBrokerIdentity(targetPid, targetIncarnation, timing);
207
+ // The trampoline normally exits right after reporting; reap it if it did not.
157
208
  await reapSpawnedBroker(child, timing);
158
209
  } catch (error) {
159
210
  state = "cleanup-unverified";
@@ -169,6 +220,10 @@ function registerBrokerOwner(
169
220
  state = "ready";
170
221
  return true;
171
222
  },
223
+ setTarget(pid, incarnation): void {
224
+ targetPid = pid;
225
+ targetIncarnation = incarnation;
226
+ },
172
227
  };
173
228
  owners.set(agentDir, owner);
174
229
  return owner;
@@ -244,10 +299,15 @@ async function ensureBrokerOnce(settings: EnsureBrokerSettings, initiator: Ensur
244
299
  return { kind: "external-discovery", discovery: existing };
245
300
  }
246
301
 
247
- const command = resolveSdkInternalSpawnCommand("broker-internal");
302
+ // On POSIX the shared broker starts through a detached trampoline so it
303
+ // reparents out of this process tree before a process-tree reaper of the
304
+ // spawner can take it down with the spawning session. Fixture leases keep the
305
+ // exact direct child they hand to tests.
306
+ const isTrampoline = process.platform !== "win32" && initiator !== "fixture-lease";
307
+ const command = resolveSdkInternalSpawnCommand(isTrampoline ? "broker-trampoline-internal" : "broker-internal");
248
308
  const child = spawn(command.file, [...command.args, "--agent-dir", settings.agentDir], {
249
309
  detached: true,
250
- stdio: "ignore",
310
+ stdio: ["ignore", isTrampoline ? "pipe" : "ignore", "ignore"],
251
311
  env: brokerSpawnEnvironment(command, settings.env),
252
312
  ...(command.kind === "bun-source" ? { cwd: command.cwd } : {}),
253
313
  });
@@ -256,15 +316,61 @@ async function ensureBrokerOnce(settings: EnsureBrokerSettings, initiator: Ensur
256
316
  child.once("error", error => {
257
317
  spawnError = error;
258
318
  });
319
+ let childExited = false;
320
+ let childExitCode: number | null = null;
321
+ let childSignalCode: NodeJS.Signals | null = null;
322
+ child.once("close", (code, signal) => {
323
+ childExited = true;
324
+ childExitCode = code;
325
+ childSignalCode = signal;
326
+ });
259
327
  const owner = registerBrokerOwner(settings.agentDir, child);
328
+ let reported: { pid: number; incarnation: string } | undefined;
329
+ if (isTrampoline && child.stdout) {
330
+ let output = "";
331
+ child.stdout.on("data", chunk => {
332
+ if (reported) return;
333
+ output += Buffer.from(chunk).toString("utf8");
334
+ const newline = output.indexOf("\n");
335
+ if (newline < 0) return;
336
+ const [rawPid, rawIncarnation] = output.slice(0, newline).trim().split("\t");
337
+ const pid = rawPid ? Number(rawPid) : Number.NaN;
338
+ if (!Number.isSafeInteger(pid) || pid <= 0 || !isProcessIncarnation(rawIncarnation)) return;
339
+ reported = { pid, incarnation: rawIncarnation };
340
+ owner.setTarget(pid, rawIncarnation);
341
+ });
342
+ }
260
343
  const discoveryTimeoutMs = initiator === "fixture-lease" ? FIXTURE_DISCOVERY_TIMEOUT_MS : DISCOVERY_TIMEOUT_MS;
261
344
  const deadline = Date.now() + discoveryTimeoutMs;
262
345
  let discoveryError: unknown;
346
+ let trampolineFailed = false;
347
+ let brokerDeathObserved = false;
263
348
  while (Date.now() < deadline) {
264
- if (spawnError || child.exitCode !== null || child.signalCode !== null) break;
349
+ if (spawnError) break;
350
+ if (isTrampoline) {
351
+ if (childExited && (!reported || childExitCode !== 0 || childSignalCode !== null)) {
352
+ trampolineFailed = true;
353
+ break;
354
+ }
355
+ if (reported && observeBrokerIdentity(reported.pid, reported.incarnation) === "gone") {
356
+ brokerDeathObserved = true;
357
+ break;
358
+ }
359
+ // The reported line identifies the real broker; discovery is only bound
360
+ // to that identity, never to the trampoline.
361
+ if (!reported) {
362
+ await sleep(50);
363
+ continue;
364
+ }
365
+ } else if (child.exitCode !== null || child.signalCode !== null) break;
265
366
  try {
266
367
  const discovered = await readBrokerDiscovery(settings.agentDir, settings.heartbeatTtlMs);
267
368
  if (discovered) {
369
+ // Ready only after the trampoline exited, i.e. once the broker reparented.
370
+ if (isTrampoline && !childExited) {
371
+ await sleep(50);
372
+ continue;
373
+ }
268
374
  if (owner.markReady(discovered)) {
269
375
  return initiator === "fixture-lease"
270
376
  ? { kind: "local-started-fixture", discovery: discovered, owner, child }
@@ -278,12 +384,27 @@ async function ensureBrokerOnce(settings: EnsureBrokerSettings, initiator: Ensur
278
384
  }
279
385
  await sleep(50);
280
386
  }
281
- const exitedBeforeDiscovery = child.exitCode !== null || child.signalCode !== null;
387
+ if (brokerDeathObserved) {
388
+ // Without a startup lock, a concurrent spawner's broker can win ownership and
389
+ // ours exits; its discovery is then the authoritative live owner.
390
+ const winner = await readBrokerDiscovery(settings.agentDir, settings.heartbeatTtlMs).catch(() => null);
391
+ if (winner && !owner.markReady(winner)) {
392
+ await owner.stop();
393
+ return { kind: "external-discovery", discovery: winner };
394
+ }
395
+ }
396
+ const exitedBeforeDiscovery = isTrampoline
397
+ ? trampolineFailed || brokerDeathObserved
398
+ : child.exitCode !== null || child.signalCode !== null;
282
399
  const failure = spawnError
283
400
  ? new Error(`Failed to spawn detached SDK broker: ${spawnError.message}`)
284
401
  : exitedBeforeDiscovery
285
402
  ? new Error(
286
- `Detached SDK broker exited before discovery (code=${child.exitCode}, signal=${child.signalCode}).`,
403
+ trampolineFailed
404
+ ? `Detached SDK broker trampoline exited before reporting the broker (code=${childExitCode}, signal=${childSignalCode}).`
405
+ : brokerDeathObserved
406
+ ? `Detached SDK broker (pid ${reported?.pid}) exited before discovery.`
407
+ : `Detached SDK broker exited before discovery (code=${child.exitCode}, signal=${child.signalCode}).`,
287
408
  )
288
409
  : discoveryError
289
410
  ? discoveryError
@@ -270,12 +270,16 @@ export class LifecycleLedger {
270
270
  return this;
271
271
  }
272
272
  /**
273
- * Reads terminal proof for one request without recovering or changing the ledger.
273
+ * Reads the durable terminal record for one request without recovering or changing the ledger.
274
274
  *
275
275
  * This intentionally accepts an unrelated unterminated final write: concurrent
276
276
  * appenders may have started a different row after this request's synced terminal
277
277
  * row. Complete rows are still decoded and validated strictly, and any incomplete
278
278
  * tail that identifies this request withholds proof.
279
+ *
280
+ * `terminal_uncertain` is a durable terminal record too: an operation that concluded
281
+ * uncertainly persists that conclusion, and refusing to read it back would report a
282
+ * synced row as unpersisted and replace its true reason with a generic one.
279
283
  */
280
284
  async readTerminal(identity: string, requestHash: string): Promise<LifecycleLedgerEntry | undefined> {
281
285
  const source = await this.#readBoundedSourceReadOnly();
@@ -320,12 +324,20 @@ export class LifecycleLedger {
320
324
  const identityMarker = Buffer.from(`"identity":${JSON.stringify(identity)}`);
321
325
  if (tail.includes(identityMarker)) return undefined;
322
326
  }
323
- return latest && terminal(latest.state) ? latest : undefined;
327
+ return latest && final(latest.state) ? latest : undefined;
324
328
  }
325
329
 
330
+ /**
331
+ * A recovery pass appends `terminal_uncertain` for every row it finds mid-flight, so a
332
+ * long-running operation can have that marker interleaved before its own terminal row
333
+ * lands. The marker records unresolved work, not a proven outcome: the owner that ran
334
+ * the effects stays authoritative and may still resolve it. A proven terminal row is
335
+ * immutable and admits no successor.
336
+ */
326
337
  #isValidHistoryContinuation(previous: LifecycleLedgerEntry | undefined, next: LifecycleLedgerEntry): boolean {
327
338
  if (!previous) return next.state === "accepted";
328
- if (previous.requestHash !== next.requestHash || final(previous.state)) return false;
339
+ if (previous.requestHash !== next.requestHash || terminal(previous.state)) return false;
340
+ if (previous.state === "terminal_uncertain") return final(next.state);
329
341
  if (previous.state === "accepted") return true;
330
342
  return next.state === "effect_started" || next.state === "awaiting_ready" || final(next.state);
331
343
  }
@@ -544,6 +556,9 @@ export class LifecycleLedger {
544
556
  return this.#mutate(async () => {
545
557
  const previous = this.#byIdentity.get(identity);
546
558
  if (!previous) throw new Error("Unknown lifecycle identity");
559
+ // Match replay validation: proven terminal records admit no successor.
560
+ // A late failure must not append a row that will be quarantined on reopen.
561
+ if (terminal(previous.state)) return previous;
547
562
  const next = { ...previous, ...fields, state, ts: Date.now() };
548
563
  if (
549
564
  (terminal(state) || state === "terminal_uncertain") &&
@@ -3557,25 +3557,27 @@ export async function executeLifecycle(
3557
3557
  )
3558
3558
  : undefined;
3559
3559
  const cleanupProof = await exactCleanupProof(broker, root, entry?.intendedSessionId, expected, evidence);
3560
- const startupFailure: LifecycleStartupFailureReceipt | undefined = evidence
3561
- ? {
3562
- artifactDigest: evidence.digest,
3563
- phase: evidence.artifact.phase,
3564
- reason: evidence.artifact.reason,
3565
- message: evidence.artifact.message,
3566
- ...(evidence.artifact.code === undefined
3567
- ? {}
3568
- : { code: evidence.artifact.code, details: evidence.artifact.details }),
3569
- rollback: {
3570
- endpointGeneration: evidence.artifact.rollback.endpointGeneration,
3571
- fenced: evidence.artifact.rollback.fenced,
3572
- runtimeRemoved: evidence.artifact.rollback.runtimeRemoved,
3573
- hostStopped: evidence.artifact.rollback.hostStopped,
3574
- brokerRegistrationReleased: evidence.artifact.rollback.brokerRegistrationReleased,
3575
- },
3576
- ...(cleanupProof ? { cleanupProof } : {}),
3577
- }
3578
- : undefined;
3560
+ // A successful response carries no startup failure, even when cleanup evidence exists.
3561
+ const startupFailure: LifecycleStartupFailureReceipt | undefined =
3562
+ evidence && !response.ok
3563
+ ? {
3564
+ artifactDigest: evidence.digest,
3565
+ phase: evidence.artifact.phase,
3566
+ reason: evidence.artifact.reason,
3567
+ message: evidence.artifact.message,
3568
+ ...(evidence.artifact.code === undefined
3569
+ ? {}
3570
+ : { code: evidence.artifact.code, details: evidence.artifact.details }),
3571
+ rollback: {
3572
+ endpointGeneration: evidence.artifact.rollback.endpointGeneration,
3573
+ fenced: evidence.artifact.rollback.fenced,
3574
+ runtimeRemoved: evidence.artifact.rollback.runtimeRemoved,
3575
+ hostStopped: evidence.artifact.rollback.hostStopped,
3576
+ brokerRegistrationReleased: evidence.artifact.rollback.brokerRegistrationReleased,
3577
+ },
3578
+ ...(cleanupProof ? { cleanupProof } : {}),
3579
+ }
3580
+ : undefined;
3579
3581
  const durableEffectsBody: Omit<LifecycleDurableEffectsReceipt, "digest"> = {
3580
3582
  ...(priorDurableEffects?.worktree ? { worktree: priorDurableEffects.worktree } : {}),
3581
3583
  ...(evidence?.artifact.transcript
@@ -2,7 +2,7 @@ import * as fs from "node:fs";
2
2
  import * as path from "node:path";
3
3
  import internalSourceMarker from "./internal-source-marker-2178.txt" with { type: "file" };
4
4
 
5
- export type SdkInternalAction = "broker-internal" | "session-host-internal";
5
+ export type SdkInternalAction = "broker-internal" | "broker-trampoline-internal" | "session-host-internal";
6
6
 
7
7
  export type SdkInternalSpawnCommand =
8
8
  | {
@@ -140,6 +140,29 @@ async function loadConfig(agentDir: string, kind: ChatDaemonKind): Promise<ChatD
140
140
  };
141
141
  }
142
142
 
143
+ /**
144
+ * Consecutive definite-disabled config reads required before a running owner
145
+ * retires. A non-atomic rewrite can briefly expose a truncated file that parses
146
+ * as valid YAML with `notifications.enabled` defaulted off, so one read is not
147
+ * a settled verdict. With the 5 s heartbeat tick this retires within ~10 s.
148
+ */
149
+ const DISABLED_READS_BEFORE_RETIRE = 2;
150
+
151
+ /**
152
+ * True only when the current config definitely disables this provider:
153
+ * `notifications.enabled: false`, the provider switched off, or a missing
154
+ * config file (the same results that keep a new owner from starting). Read or
155
+ * validation errors (half-written file, incomplete or quarantined provider) are
156
+ * indeterminate and keep the owner serving.
157
+ */
158
+ async function configDisablesProvider(agentDir: string, kind: ChatDaemonKind): Promise<boolean> {
159
+ try {
160
+ return (await loadConfig(agentDir, kind)) === undefined;
161
+ } catch {
162
+ return false;
163
+ }
164
+ }
165
+
143
166
  function ownerPid(ownerId: string): number | undefined {
144
167
  const match = /^(\d+)(?:-|$)/.exec(ownerId);
145
168
  const pid = Number(match?.[1]);
@@ -225,10 +248,24 @@ export async function runChatDaemonInternal(
225
248
  return;
226
249
  }
227
250
  await runtime.start();
251
+ let disabledReads = 0;
252
+ const retireIfDisabled = async (): Promise<void> => {
253
+ if (!(await configDisablesProvider(agentDir, kind))) {
254
+ disabledReads = 0;
255
+ return;
256
+ }
257
+ if (++disabledReads < DISABLED_READS_BEFORE_RETIRE || stopping) return;
258
+ // Same orderly path as an operator stop: stop the transport, let the
259
+ // serve loop exit, and release ownership as stopped in `finally`.
260
+ stopping = true;
261
+ await stopRuntime();
262
+ };
263
+ // The returned promise never rejects; tests await it to drive one tick.
228
264
  interval = (deps.setInterval ?? setInterval)(() => {
229
- void (async () => {
265
+ return (async () => {
230
266
  try {
231
267
  if (!(await renewHeartbeat())) await terminateForLostOwnership();
268
+ else await retireIfDisabled();
232
269
  } catch (error) {
233
270
  terminalError ??= error;
234
271
  stopping = true;
@@ -35,11 +35,13 @@ export type ChatDaemonAction = "stop" | "reload";
35
35
  * when deleting an observed owner-lock lease. Generation 12 refreshes retained
36
36
  * native path and process authority semantics. Generation 13 rejects special
37
37
  * files before retained native authority opens. Generation 14 reloads shared
38
- * chat daemons after notification configuration parsing changes.
38
+ * chat daemons after notification configuration parsing changes. Generation 15
39
+ * retires a running owner once its notifications are definitely disabled.
40
+ * Slack generation 16 reclaims the daemon's own expired root publication lease.
39
41
  */
40
42
  export const CHAT_DAEMON_GENERATIONS: Readonly<Record<ChatDaemonKind, number>> = {
41
- discord: 14,
42
- slack: 14,
43
+ discord: 15,
44
+ slack: 16,
43
45
  };
44
46
 
45
47
  export function chatDaemonGeneration(kind: ChatDaemonKind): number {
@@ -1840,7 +1840,9 @@ function sdkQuerySurface(
1840
1840
  kind: ctx.sessionMetadata?.kind ?? "main",
1841
1841
  });
1842
1842
  // A continued answer includes its preserved prefix (the same chain print and /copy use).
1843
- const lastAssistantText = () => lastVisibleAnswerText(ctx.sessionManager.getBranch());
1843
+ // Missing assistant text is an empty observation (null), not an unavailable
1844
+ // snapshot payload: `undefined` would surface as Q17 `resource_gone`.
1845
+ const lastAssistantText = () => lastVisibleAnswerText(ctx.sessionManager.getBranch()) ?? null;
1844
1846
  const getDiff = async () => {
1845
1847
  try {
1846
1848
  const { stdout } = await execFileAsync("git", ["diff", "--no-ext-diff"], {
@@ -2480,8 +2482,8 @@ function sdkControlSurface(
2480
2482
  return unavailable("model.cycle", "no session model-cycle seam is installed")();
2481
2483
  return { changed: (await ctx.cycleModel()) !== undefined };
2482
2484
  },
2483
- setThinking: level => {
2484
- api.setThinkingLevel(level as ThinkingLevel);
2485
+ setThinking: async level => {
2486
+ await api.setThinkingLevelForControl(level as ThinkingLevel, false);
2485
2487
  return { changed: true };
2486
2488
  },
2487
2489
  cycleThinking: () => {
@@ -19,6 +19,7 @@ import {
19
19
  MANAGED_OWNER_PREDECESSOR_RUN_ID_ENV,
20
20
  MANAGED_OWNER_PREDECESSOR_TOKEN_ENV,
21
21
  MANAGED_OWNER_TRANSCRIPT_PATH_ENV,
22
+ trustedManagedOwnerLaunchSessionFile,
22
23
  } from "../../skc-runtime/managed-owner-admission";
23
24
  import {
24
25
  MANAGED_OWNER_INCARNATION_ENV,
@@ -924,7 +925,10 @@ export function daemonSpawnCreate(
924
925
  [MANAGED_OWNER_PREDECESSOR_GENERATION_ENV]: predecessor.generation,
925
926
  [MANAGED_OWNER_PREDECESSOR_RUN_ID_ENV]: predecessor.runId,
926
927
  [MANAGED_OWNER_PREDECESSOR_INCARNATION_ENV]: predecessor.incarnation,
927
- [MANAGED_OWNER_TRANSCRIPT_PATH_ENV]: env.SKC_SESSION_FILE ?? "",
928
+ [MANAGED_OWNER_TRANSCRIPT_PATH_ENV]: trustedManagedOwnerLaunchSessionFile(
929
+ { SKC_SESSION_FILE: env.SKC_SESSION_FILE },
930
+ cwd,
931
+ ),
928
932
  }
929
933
  : {}),
930
934
  };
@@ -1168,7 +1172,10 @@ export function daemonResumeSession(
1168
1172
  [MANAGED_OWNER_PREDECESSOR_GENERATION_ENV]: predecessor.generation,
1169
1173
  [MANAGED_OWNER_PREDECESSOR_RUN_ID_ENV]: predecessor.runId,
1170
1174
  [MANAGED_OWNER_PREDECESSOR_INCARNATION_ENV]: predecessor.incarnation,
1171
- [MANAGED_OWNER_TRANSCRIPT_PATH_ENV]: env.SKC_SESSION_FILE ?? "",
1175
+ [MANAGED_OWNER_TRANSCRIPT_PATH_ENV]: trustedManagedOwnerLaunchSessionFile(
1176
+ { SKC_SESSION_FILE: env.SKC_SESSION_FILE },
1177
+ resolvedResumeCwd,
1178
+ ),
1172
1179
  }
1173
1180
  : {}),
1174
1181
  };
@@ -1,3 +1,4 @@
1
+ import { setSessionOutboundRedact } from "../host/events";
1
2
  import {
2
3
  getCurrentTelegramActivationMarker,
3
4
  isNotificationStreamingEnabled,
@@ -369,6 +370,7 @@ export class NotificationSessionController {
369
370
  policy: Omit<NotificationRuntimePolicy, "mode">,
370
371
  mode: NotificationRuntimePolicy["mode"],
371
372
  ): void {
373
+ setSessionOutboundRedact(binding.sessionId, policy.redact);
372
374
  runtime?.refreshPolicy?.(binding, { ...policy, mode });
373
375
  }
374
376
 
@@ -365,7 +365,14 @@ export class SlackNotificationDaemon {
365
365
  )
366
366
  return current;
367
367
  if (current?.state === "posting_root") {
368
- if (current.rootPublicationOwner === this.#publicationOwnerId) return current;
368
+ // A live lease of our own belongs to an in-flight post; an expired one is
369
+ // reclaimed under a new fence exactly like a crashed peer's, otherwise the
370
+ // root waiter would re-enter postRoot until it gives up (upstream 98cb96aaa7).
371
+ if (
372
+ current.rootPublicationOwner === this.#publicationOwnerId &&
373
+ !this.#leaseExpired(current.rootPublicationLeaseExpiresAt, now)
374
+ )
375
+ return current;
369
376
  claimed = true;
370
377
  return nextRecord(current, {
371
378
  rootPublicationOwner: this.#publicationOwnerId,
@@ -89,7 +89,9 @@ function retryAfterMilliseconds(response: Response, body: SlackApiResponse, maxi
89
89
  }
90
90
 
91
91
  function socketFromGlobal(url: string): SlackWebSocket {
92
- return new WebSocket(url);
92
+ // bun-types 1.4.4 types WebSocket.onerror with ErrorEvent, which is not
93
+ // assignable to the DOM Event handler this structural interface declares.
94
+ return new WebSocket(url) as unknown as SlackWebSocket;
93
95
  }
94
96
 
95
97
  /**
@@ -41,8 +41,10 @@ export const NOTIFICATION_PROTOCOL_VERSION = 3;
41
41
  * and Bot API cooldown structural fixes (#2956, #2960, #3048).
42
42
  * Generation 30 adds opt-in tool activity delivery, closed lifecycle phases,
43
43
  * and capability-versioned mixed-host compatibility.
44
+ * Generation 31 lets a Windows controller wait for a cooperative stop and has
45
+ * the owner watch its control request during a long poll (upstream #6174).
44
46
  */
45
- export const DAEMON_GENERATION = 30;
47
+ export const DAEMON_GENERATION = 31;
46
48
 
47
49
  /**
48
50
  * Serving-compatibility boundary for daemon lifecycle requests. Epoch 1 covers
@@ -56,6 +56,16 @@ const nodeFs: TelegramDaemonFs = {
56
56
  const DEFAULT_GRACEFUL_TIMEOUT_MS = 8_000;
57
57
  const DEFAULT_KILL_TIMEOUT_MS = 3_000;
58
58
  const DEFAULT_WAIT_STEP_MS = 25;
59
+ // Windows process handles cannot deliver SIGTERM cooperatively. The request
60
+ // file is therefore the sole notification channel, so a captured owner gets
61
+ // enough time to finish its long poll, network slack, and shutdown joins before
62
+ // an explicit force request may escalate. Short explicit timeouts are clamped
63
+ // to this floor only for hard-termination authorities; POSIX keeps 8 seconds.
64
+ const HARD_TERMINATION_LONG_POLL_MS = 25_000;
65
+ const HARD_TERMINATION_NETWORK_SLACK_MS = 5_000;
66
+ const HARD_TERMINATION_SHUTDOWN_JOINS_MS = 10_000;
67
+ const HARD_TERMINATION_GRACE_MS =
68
+ HARD_TERMINATION_LONG_POLL_MS + HARD_TERMINATION_NETWORK_SLACK_MS + HARD_TERMINATION_SHUTDOWN_JOINS_MS;
59
69
 
60
70
  export interface TelegramDaemonControlRequest {
61
71
  version: 1;
@@ -604,17 +614,6 @@ export class TelegramDaemonController implements BuiltInDaemonController {
604
614
  const signalResult = attestedLegacyOwner
605
615
  ? await this.#signalAttestedLegacyOwner(attestedLegacyOwner, fp, chatId, "SIGTERM")
606
616
  : await this.signalCapturedOwner(modernCapturedOwner!, fp, chatId, "SIGTERM");
607
- if (signalResult === "hard_termination") {
608
- await this.clearOwnRequest(requestId);
609
- return this.result(
610
- action,
611
- false,
612
- "telegram daemon has hard process authority; refusing cooperative SIGTERM",
613
- before,
614
- await this.status(),
615
- warnings,
616
- );
617
- }
618
617
  if (signalResult === "ownership_changed") {
619
618
  await this.clearOwnRequest(requestId);
620
619
  return this.result(
@@ -630,7 +629,13 @@ export class TelegramDaemonController implements BuiltInDaemonController {
630
629
  // death through the normal path — waitForPidDeath returns immediately for a
631
630
  // dead pid, so stop succeeds and reload proceeds to spawn the replacement.
632
631
 
633
- let dead = await this.waitForPidDeath(oldPid, gracefulTimeoutMs);
632
+ // Hard termination (Windows) has no cooperative signal: the control request
633
+ // file written above is the only stop notice, so wait for the owner to honor it.
634
+ const cooperativeGraceMs =
635
+ signalResult === "hard_termination"
636
+ ? Math.max(gracefulTimeoutMs, HARD_TERMINATION_GRACE_MS)
637
+ : gracefulTimeoutMs;
638
+ let dead = await this.waitForPidDeath(oldPid, cooperativeGraceMs);
634
639
  if (!dead) {
635
640
  // Old pid still alive after the cooperative SIGTERM. Inspect current ownership.
636
641
  const currentSnapshot = await readOwnerFreshnessSnapshot({ settings: this.settings, fs: this.fsImpl });
@@ -245,6 +245,9 @@ const BOT_API_RETRY_ATTEMPTS = 3;
245
245
  // Backoff after a failed getUpdates long-poll so a persistent outage does not
246
246
  // busy-loop the daemon.
247
247
  const POLL_BACKOFF_MS = 1_000;
248
+ // A Windows controller cannot signal the owner, so the owner also polls its
249
+ // control request while a long poll is in flight instead of only between loops.
250
+ const CONTROL_STOP_WATCH_INTERVAL_MS = 750;
248
251
  const AUTOMATIC_RELOAD_COOLDOWN_MS = 10 * 60 * 1_000;
249
252
  // Default freshness-poll window a cooldown contender waits for a sibling's
250
253
  // replacement daemon to publish a fresh ready owner before reloading itself.
@@ -4135,6 +4138,7 @@ export class TelegramNotificationDaemon {
4135
4138
  private running = false;
4136
4139
  /** Once set, a concurrent startup await can never restore a running daemon. */
4137
4140
  private stopRequested = false;
4141
+ #controlStopCheck: Promise<boolean> | undefined;
4138
4142
 
4139
4143
  private readonly fsImpl: TelegramDaemonFs;
4140
4144
  private readonly botApi: BotApi;
@@ -9558,6 +9562,9 @@ export class TelegramNotificationDaemon {
9558
9562
  // token, there is no authenticated daemon identity or lifecycle authority.
9559
9563
  if (!validBotToken(this.opts.botToken)) return;
9560
9564
  let ownershipProved = false;
9565
+ let controlWatchTimer: Timer | NodeJS.Timeout | undefined;
9566
+ let controlWatchActive = true;
9567
+ const clearTimeoutImpl = this.opts.clearTimeoutImpl ?? clearTimeout;
9561
9568
  try {
9562
9569
  const renewed = await renewDaemonHeartbeat({
9563
9570
  settings: this.opts.settings,
@@ -9605,6 +9612,19 @@ export class TelegramNotificationDaemon {
9605
9612
  await this.replyStore.load();
9606
9613
  await this.runScan();
9607
9614
  let idleSince = this.runtime.now();
9615
+ const setTimeoutImpl = this.opts.setTimeoutImpl ?? setTimeout;
9616
+ const watchControl = () => {
9617
+ if (!controlWatchActive || !this.running || !this.opts.control) return;
9618
+ controlWatchTimer = setTimeoutImpl(() => {
9619
+ controlWatchTimer = undefined;
9620
+ void this.controlStopRequested()
9621
+ .catch(() => false)
9622
+ .finally(() => {
9623
+ if (controlWatchActive && this.running) watchControl();
9624
+ });
9625
+ }, CONTROL_STOP_WATCH_INTERVAL_MS);
9626
+ };
9627
+ if (this.opts.control) watchControl();
9608
9628
  while (this.running) {
9609
9629
  if (await this.controlStopRequested()) break;
9610
9630
  if (
@@ -9653,6 +9673,8 @@ export class TelegramNotificationDaemon {
9653
9673
  await this.runtime.sleep(10);
9654
9674
  }
9655
9675
  } finally {
9676
+ controlWatchActive = false;
9677
+ if (controlWatchTimer !== undefined) clearTimeoutImpl(controlWatchTimer);
9656
9678
  this.running = false;
9657
9679
  this.runtime.stop();
9658
9680
  this.stopOwnershipHeartbeatTimer();
@@ -9722,8 +9744,26 @@ export class TelegramNotificationDaemon {
9722
9744
  private async controlStopRequested(): Promise<boolean> {
9723
9745
  if (this.runtime.stopRequested) return true;
9724
9746
  if (!this.opts.control) return false;
9747
+ // The loop and the in-flight watch share one file read at a time.
9748
+ if (this.#controlStopCheck) return this.#controlStopCheck;
9749
+ const check = this.checkControlStopRequested();
9750
+ this.#controlStopCheck = check;
9725
9751
  try {
9726
- return await this.opts.control.shouldStop(this.opts.ownerId);
9752
+ return await check;
9753
+ } finally {
9754
+ if (this.#controlStopCheck === check) this.#controlStopCheck = undefined;
9755
+ }
9756
+ }
9757
+
9758
+ private async checkControlStopRequested(): Promise<boolean> {
9759
+ try {
9760
+ const control = this.opts.control;
9761
+ if (!control) return false;
9762
+ const requested = await control.shouldStop(this.opts.ownerId);
9763
+ if (!requested) return false;
9764
+ // Abort the in-flight long poll so the run loop sees the stop now.
9765
+ this.requestStop("stop");
9766
+ return true;
9727
9767
  } catch {
9728
9768
  return false;
9729
9769
  }