@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,8 +1,11 @@
1
+ import { type ChildProcess, spawn } from "node:child_process";
1
2
  import { createHash } from "node:crypto";
2
3
  import * as fs from "node:fs/promises";
3
4
  import * as os from "node:os";
4
5
  import * as path from "node:path";
5
6
  import { Args, CliParseError, Command, Flags, renderCommandHelp } from "@sayknow-cli/utils/cli";
7
+ import { startupProjectEnvSnapshot } from "@sayknow-cli/utils/env";
8
+ import { type ProjectEnvSnapshot, projectEnvSnapshot } from "@sayknow-cli/utils/env-file";
6
9
  import type { Args as ParsedArgs } from "../cli/args";
7
10
  import { Settings } from "../config/settings";
8
11
  import { applyStartupModelProfiles, createSessionManager } from "../main";
@@ -20,6 +23,7 @@ import {
20
23
  } from "../sdk/broker/lifecycle";
21
24
  import { exitIfSourceGone, startSessionHostGuard } from "../sdk/broker/process-guard";
22
25
  import { processIncarnation } from "../sdk/broker/process-incarnation";
26
+ import { resolveSdkInternalSpawnCommand } from "../sdk/broker/runtime";
23
27
  import { type CreateLifecycleAgentSessionResult, createLifecycleAgentSession } from "../sdk/lifecycle-session";
24
28
  import { listManagedSessionCandidates, resolveManagedSessionScope } from "../sdk/session-directory";
25
29
  import {
@@ -34,6 +38,7 @@ import {
34
38
  type ResumeSessionIdentity,
35
39
  SessionManager,
36
40
  } from "../session/session-manager";
41
+ import { trustedCoordinatorEnv } from "../skc-runtime/sidecar-bootstrap-env";
37
42
 
38
43
  export async function lifecycleArgs(
39
44
  request: SessionLifecycleLaunchRequest,
@@ -198,6 +203,38 @@ export async function openLifecycleSessionManager(
198
203
  return { parsed, sessionManager };
199
204
  }
200
205
 
206
+ const SDK_CWD_EQUALITY_TEST_SEAMS = [
207
+ "SKC_SDK_TEST_HANG_MODEL_PROFILE",
208
+ "SKC_SDK_TEST_FAIL_AFTER_REGISTRATION",
209
+ ] as const;
210
+
211
+ type SdkCwdEqualityTestSeam = (typeof SDK_CWD_EQUALITY_TEST_SEAMS)[number];
212
+
213
+ function isSdkCwdEqualityTestSeam(name: string): name is SdkCwdEqualityTestSeam {
214
+ return (SDK_CWD_EQUALITY_TEST_SEAMS as readonly string[]).includes(name);
215
+ }
216
+
217
+ function sdkCwdEqualitySnapshots(cwd: string): ProjectEnvSnapshot[] {
218
+ // The startup snapshot keeps a declaration Bun loaded before a later chdir.
219
+ return [projectEnvSnapshot(cwd), startupProjectEnvSnapshot()];
220
+ }
221
+
222
+ /**
223
+ * Cwd-equality test seams accept only an operator value. A project dotenv line,
224
+ * including one Bun expands from `$PWD`, never arms the seam.
225
+ */
226
+ export function sdkCwdEqualityTestSeamActive(
227
+ name: string,
228
+ cwd: string,
229
+ env: NodeJS.ProcessEnv = process.env,
230
+ snapshots: readonly ProjectEnvSnapshot[] = sdkCwdEqualitySnapshots(cwd),
231
+ ): boolean {
232
+ if (!isSdkCwdEqualityTestSeam(name) || env[name] !== cwd) return false;
233
+ // Provenance only. trustedCoordinatorEnv trims, so a second compare to cwd
234
+ // would drop a trusted path that still matches exactly, including trailing space.
235
+ return snapshots.every(snapshot => trustedCoordinatorEnv(name, env, snapshot) !== undefined);
236
+ }
237
+
201
238
  /** Runs the same persisted AgentSession bootstrap used by the production CLI. */
202
239
  export async function runSessionHost(
203
240
  timing: {
@@ -214,6 +251,9 @@ export async function runSessionHost(
214
251
  const agentDir = process.env.SKC_AGENT_DIR;
215
252
  if (!agentDir) throw new Error("SKC_AGENT_DIR is required for sdk session-host-internal.");
216
253
  const cwd = timing.cwd ?? process.cwd();
254
+ const cwdSeamSnapshots = sdkCwdEqualitySnapshots(cwd);
255
+ const cwdEqualitySeam = (name: SdkCwdEqualityTestSeam): boolean =>
256
+ sdkCwdEqualityTestSeamActive(name, cwd, process.env, cwdSeamSnapshots);
217
257
  if ((await fs.realpath(request.cwd)) !== (await fs.realpath(cwd)))
218
258
  throw new Error(`Lifecycle worktree mismatch: expected ${request.cwd}, got ${cwd}.`);
219
259
  if (
@@ -284,8 +324,7 @@ export async function runSessionHost(
284
324
  },
285
325
  absent.result,
286
326
  );
287
-
288
- throw new Error("SDK startup did not complete before readiness cutoff.");
327
+ return;
289
328
  }
290
329
 
291
330
  // Inlined rather than extracted to a helper: TypeScript's definite-assignment
@@ -461,15 +500,14 @@ export async function runSessionHost(
461
500
  };
462
501
 
463
502
  try {
464
- const modelProfileStartup =
465
- process.env.SKC_SDK_TEST_HANG_MODEL_PROFILE === cwd
466
- ? new Promise<void>(() => {})
467
- : applyStartupModelProfiles({
468
- session,
469
- settings: session.settings,
470
- modelRegistry: session.modelRegistry,
471
- parsedArgs: parsed,
472
- });
503
+ const modelProfileStartup = cwdEqualitySeam("SKC_SDK_TEST_HANG_MODEL_PROFILE")
504
+ ? new Promise<void>(() => {})
505
+ : applyStartupModelProfiles({
506
+ session,
507
+ settings: session.settings,
508
+ modelRegistry: session.modelRegistry,
509
+ parsedArgs: parsed,
510
+ });
473
511
  await beforeCutoff(modelProfileStartup);
474
512
  throwIfCutoff();
475
513
  await beforeCutoff(
@@ -487,7 +525,7 @@ export async function runSessionHost(
487
525
  const startup = await beforeCutoff(capability.promise);
488
526
  if (startup.status !== "started") throw startup.failure;
489
527
  throwIfCutoff();
490
- if (process.env.SKC_SDK_TEST_FAIL_AFTER_REGISTRATION === cwd)
528
+ if (cwdEqualitySeam("SKC_SDK_TEST_FAIL_AFTER_REGISTRATION"))
491
529
  throw new Error("Lifecycle test failure after SDK host registration.");
492
530
 
493
531
  await session.sessionManager.ensureOnDisk();
@@ -510,16 +548,75 @@ export async function runSessionHost(
510
548
  await new Promise<void>(() => {});
511
549
  }
512
550
 
513
- export type SdkInternalArgv = { action: "broker-internal"; agentDir: string } | { action: "session-host-internal" };
551
+ export type SdkInternalArgv =
552
+ | { action: "broker-internal"; agentDir: string }
553
+ | { action: "broker-trampoline-internal"; agentDir: string }
554
+ | { action: "session-host-internal" };
514
555
 
515
556
  /** Parses the exact private argv contracts used by SDK child-process spawns. */
516
557
  export function parseSdkInternalArgv(argv: readonly string[]): SdkInternalArgv {
517
558
  if (argv[0] === "session-host-internal" && argv.length === 1) return { action: "session-host-internal" };
518
559
  if (argv[0] === "broker-internal" && argv.length === 3 && argv[1] === "--agent-dir" && argv[2])
519
560
  return { action: "broker-internal", agentDir: argv[2] };
561
+ if (argv[0] === "broker-trampoline-internal" && argv.length === 3 && argv[1] === "--agent-dir" && argv[2])
562
+ return { action: "broker-trampoline-internal", agentDir: argv[2] };
520
563
  throw new CliParseError("Invalid internal SDK invocation.");
521
564
  }
522
565
 
566
+ /**
567
+ * Detached trampoline for the shared broker (POSIX only): it starts the real
568
+ * broker, reports its exact `pid\tincarnation` on stdout, and exits so the
569
+ * broker reparents out of the spawner's process tree before that tree can be
570
+ * reaped. The spawner binds startup evidence to the reported identity, never to
571
+ * the trampoline.
572
+ */
573
+ async function runBrokerTrampoline(agentDir: string): Promise<void> {
574
+ if (process.platform === "win32") throw new CliParseError("Broker trampoline is unavailable on Windows.");
575
+ const command = resolveSdkInternalSpawnCommand("broker-internal");
576
+ let child: ChildProcess;
577
+ try {
578
+ child = spawn(command.file, [...command.args, "--agent-dir", agentDir], {
579
+ detached: true,
580
+ stdio: ["ignore", "ignore", "inherit"],
581
+ env: command.env,
582
+ ...(command.kind === "bun-source" ? { cwd: command.cwd } : {}),
583
+ });
584
+ } catch (error) {
585
+ throw new Error("Broker trampoline could not start broker.", { cause: error });
586
+ }
587
+ let spawnError: Error | undefined;
588
+ child.once("error", error => {
589
+ spawnError = error;
590
+ });
591
+ if (child.pid === undefined) throw new Error("Broker trampoline could not start broker.");
592
+ const incarnation = processIncarnation(child.pid);
593
+ if (!incarnation) {
594
+ try {
595
+ child.kill("SIGKILL");
596
+ } catch {
597
+ // The child may already have exited; either way identity was not established.
598
+ }
599
+ throw new Error("Broker trampoline could not observe broker identity.");
600
+ }
601
+ if (spawnError) throw new Error("Broker trampoline could not start broker.", { cause: spawnError });
602
+ const stdoutWrite = Promise.withResolvers<void>();
603
+ process.stdout.write(`${child.pid}\t${incarnation}\n`, error => {
604
+ if (error) stdoutWrite.reject(error);
605
+ else stdoutWrite.resolve();
606
+ });
607
+ try {
608
+ await stdoutWrite.promise;
609
+ } catch (error) {
610
+ try {
611
+ child.kill("SIGKILL");
612
+ } catch {
613
+ // The child may already have exited; reporting failure remains authoritative.
614
+ }
615
+ throw error;
616
+ }
617
+ child.unref();
618
+ }
619
+
523
620
  class SdkServeHelp extends Command {
524
621
  static description = "skc sdk serve --stdio | --socket <path> [--session <id>] [--pending-ceiling <bytes>]";
525
622
  static flags = {
@@ -547,9 +644,13 @@ export default class Sdk extends Command {
547
644
  await runSdkServe(this.argv.slice(1));
548
645
  return;
549
646
  }
550
- if (action !== "broker-internal" && action !== "session-host-internal")
647
+ if (action !== "broker-internal" && action !== "broker-trampoline-internal" && action !== "session-host-internal")
551
648
  throw new CliParseError("Expected action to be serve.");
552
649
  const internal = parseSdkInternalArgv(this.argv);
650
+ if (internal.action === "broker-trampoline-internal") {
651
+ await runBrokerTrampoline(internal.agentDir);
652
+ return;
653
+ }
553
654
  if (internal.action === "session-host-internal") {
554
655
  await runSessionHost();
555
656
  return;
@@ -7,6 +7,7 @@ import {
7
7
  writeCurrentSessionGoalModeState,
8
8
  writePendingGoalModeRequest,
9
9
  } from "../skc-runtime/goal-mode-request";
10
+ import { trustedCoordinatorEnv } from "../skc-runtime/sidecar-bootstrap-env";
10
11
  import { runNativeUltragoalCommand } from "../skc-runtime/ultragoal-runtime";
11
12
 
12
13
  export default class Ultragoal extends Command {
@@ -29,16 +30,21 @@ export default class Ultragoal extends Command {
29
30
  const { objective, goalsPath, provenance } = await readUltragoalSkcObjective(cwd);
30
31
 
31
32
  await writeCurrentSessionGoalModeState({
32
- sessionFile: process.env[SKC_SESSION_FILE_ENV],
33
+ sessionFile: trustedCoordinatorEnv(SKC_SESSION_FILE_ENV),
33
34
  objective,
34
35
  provenance,
35
36
  });
36
- await writePendingGoalModeRequest({
37
- cwd,
38
- objective,
39
- goalsPath,
40
- provenance,
41
- sessionId: process.env[SKC_SESSION_ID_ENV],
42
- });
37
+ // A matching or dynamic project declaration must not select the session.
38
+ // Skip the write in that case: the helper falls back to the same env value.
39
+ const sessionId = trustedCoordinatorEnv(SKC_SESSION_ID_ENV);
40
+ if (sessionId !== undefined || !process.env[SKC_SESSION_ID_ENV]?.trim()) {
41
+ await writePendingGoalModeRequest({
42
+ cwd,
43
+ objective,
44
+ goalsPath,
45
+ provenance,
46
+ sessionId,
47
+ });
48
+ }
43
49
  }
44
50
  }
@@ -1,7 +1,7 @@
1
1
  import { INTENT_FIELD, type ThinkingLevel } from "@sayknow-cli/agent-core";
2
2
  import type { Api, Model } from "@sayknow-cli/ai";
3
3
  import { Markdown } from "@sayknow-cli/tui";
4
- import { prompt } from "@sayknow-cli/utils";
4
+ import { prompt, sanitizeText } from "@sayknow-cli/utils";
5
5
  import chalk from "chalk";
6
6
  import typesDescriptionPrompt from "../../commit/prompts/types-description.md" with { type: "text" };
7
7
  import type { ModelRegistry } from "../../config/model-registry";
@@ -81,7 +81,7 @@ export async function runCommitAgentSession(input: CommitAgentInput): Promise<Co
81
81
  const toolArgsById = new Map<string, { name: string; args?: Record<string, unknown> }>();
82
82
  const writeThinkingLine = (text: string) => {
83
83
  if (!process.stdout.isTTY) return;
84
- const line = chalk.dim(`… ${text}`);
84
+ const line = chalk.dim(`… ${sanitizeText(text)}`);
85
85
  process.stdout.write(`\r\x1b[2K${line}`);
86
86
  thinkingLineActive = true;
87
87
  };
@@ -118,7 +118,7 @@ export async function runCommitAgentSession(input: CommitAgentInput): Promise<Co
118
118
  clearThinkingLine();
119
119
  const assistantMessage = event.message as { stopReason?: string; errorMessage?: string };
120
120
  if (assistantMessage.stopReason === "error" && assistantMessage.errorMessage) {
121
- process.stdout.write(`● Error: ${assistantMessage.errorMessage}\n`);
121
+ process.stdout.write(`● Error: ${sanitizeText(assistantMessage.errorMessage)}\n`);
122
122
  }
123
123
  const messageText = extractMessageText(event.message?.content ?? []);
124
124
  if (messageText) {
@@ -131,10 +131,10 @@ export async function runCommitAgentSession(input: CommitAgentInput): Promise<Co
131
131
  const stored = toolArgsById.get(event.toolCallId) ?? { name: event.toolName };
132
132
  toolArgsById.delete(event.toolCallId);
133
133
  clearThinkingLine();
134
- const toolLabel = formatToolLabel(stored.name);
134
+ const toolLabel = sanitizeText(formatToolLabel(stored.name));
135
135
  const symbol = event.isError ? "" : "";
136
136
  process.stdout.write(`${symbol} ${toolLabel}\n`);
137
- const argsLines = formatToolArgs(stored.args);
137
+ const argsLines = formatToolArgs(stored.args).map(line => sanitizeText(line));
138
138
  if (argsLines.length > 0) {
139
139
  process.stdout.write(`${formatToolArgsBlock(argsLines)}\n`);
140
140
  }
@@ -201,7 +201,7 @@ function extractMessageText(content: Array<{ type: string; text?: string }>): st
201
201
  }
202
202
 
203
203
  function writeAssistantMessage(message: string): void {
204
- const lines = renderMarkdownLines(message);
204
+ const lines = renderMarkdownLines(sanitizeText(message));
205
205
  if (lines.length === 0) return;
206
206
  let firstContentIndex = lines.findIndex(line => line.trim().length > 0);
207
207
  if (firstContentIndex === -1) {
@@ -5,6 +5,7 @@ import { prompt } from "@sayknow-cli/utils";
5
5
  import analysisSystemPrompt from "../../commit/prompts/analysis-system.md" with { type: "text" };
6
6
  import analysisUserPrompt from "../../commit/prompts/analysis-user.md" with { type: "text" };
7
7
  import type { ConventionalAnalysis } from "../../commit/types";
8
+ import { escapePromptMetadata } from "../../session/messages";
8
9
  import { toReasoningEffort } from "../../thinking";
9
10
  import { createConventionalAnalysisTool, parseConventionalAnalysisResponse } from "../shared-llm";
10
11
 
@@ -41,13 +42,21 @@ export async function generateConventionalAnalysis({
41
42
  diff,
42
43
  }: ConventionalAnalysisInput): Promise<ConventionalAnalysis> {
43
44
  const userContent = prompt.render(analysisUserPrompt, {
44
- context_files: contextFiles && contextFiles.length > 0 ? contextFiles : undefined,
45
+ context_files:
46
+ contextFiles && contextFiles.length > 0
47
+ ? contextFiles.map(file => ({
48
+ path: escapePromptMetadata(file.path),
49
+ content: escapePromptMetadata(file.content, { preserveNewlines: true }),
50
+ }))
51
+ : undefined,
45
52
  user_context: userContext,
46
53
  types_description: typesDescription,
47
- recent_commits: recentCommits?.join("\n"),
48
- scope_candidates: scopeCandidates,
49
- stat,
50
- diff,
54
+ recent_commits: recentCommits
55
+ ?.map(subject => escapePromptMetadata(subject, { preserveNewlines: true }))
56
+ .join("\n"),
57
+ scope_candidates: escapePromptMetadata(scopeCandidates, { preserveNewlines: true }),
58
+ stat: escapePromptMetadata(stat, { preserveNewlines: true }),
59
+ diff: escapePromptMetadata(diff, { preserveNewlines: true }),
51
60
  });
52
61
 
53
62
  const response = await completeSimple(
@@ -168,11 +168,49 @@ function applyChangelogEntries(
168
168
  if (deletions) {
169
169
  base = applyDeletions(base, deletions);
170
170
  }
171
- const merged = mergeEntries(base, entries);
171
+ const merged = mergeEntries(base, redactPersistedEntries(entries));
172
172
  const sectionLines = renderUnreleasedSections(merged);
173
173
  return [...before, ...sectionLines, ...after].join("\n");
174
174
  }
175
175
 
176
+ function redactPersistedEntries(entries: Record<string, string[]>): Record<string, string[]> {
177
+ const redacted: Record<string, string[]> = {};
178
+ for (const [section, items] of Object.entries(entries)) {
179
+ redacted[section] = items.map(item => redactChangelogEntry(item));
180
+ }
181
+ return redacted;
182
+ }
183
+
184
+ const AWS_LABELED_KEY =
185
+ "(?:(?:aws[_-]?)?secret[_-]?access[_-]?key|(?:aws[_-]?)?session[_-]?token|x[_-]?amz[_-]?security[_-]?token)";
186
+
187
+ export function redactChangelogEntry(text: string): string {
188
+ let redacted = text.replace(/(^|[^0-9A-Za-z])(?:AKIA|ASIA)[0-9A-Z]{16}(?![0-9A-Za-z])/g, "$1[REDACTED_AWS_KEY_ID]");
189
+ redacted = redacted.replace(
190
+ new RegExp(
191
+ `(^|[^A-Za-z0-9_-])(["']?${AWS_LABELED_KEY}["']?\\s*[=:]\\s*)(\\$?)(["'\`])([^"'\`\\r\\n]{8,})\\4`,
192
+ "gi",
193
+ ),
194
+ "$1$2$3$4[REDACTED_SECRET]$4",
195
+ );
196
+ redacted = redacted.replace(
197
+ new RegExp(`(^|[^A-Za-z0-9_-])(["']?${AWS_LABELED_KEY}["']?\\s*[=:]\\s*)[^\\s"'\`,;{}[\\]()&<>#]{8,}`, "gi"),
198
+ "$1$2[REDACTED_SECRET]",
199
+ );
200
+ redacted = redacted.replace(/\b(?:sk|pk|rk|xox[baprs])-[-_A-Za-z0-9]{12,}\b/g, "[REDACTED_TOKEN]");
201
+ redacted = redacted.replace(/(?<![A-Za-z0-9_-])AIza[0-9A-Za-z_-]{35}(?![A-Za-z0-9_-])/g, "[REDACTED_TOKEN]");
202
+ redacted = redacted.replace(/\b(?:gh[opsur]_[A-Za-z0-9_]{12,}|github_pat_[A-Za-z0-9_]{12,})\b/g, "[REDACTED_TOKEN]");
203
+ redacted = redacted.replace(
204
+ /\b((?:ANTHROPIC|OPENAI|GITHUB|GOOGLE|GEMINI|KAGI|TAVILY|EXA|PERPLEXITY|ZAI|KIMI|BRAVE|SEARXNG|AWS)_[A-Z0-9_]*(?:KEY|TOKEN|SECRET|COOKIE|PASSWORD))\s*=\s*[^\s\n]+/gi,
205
+ "$1=[REDACTED_SECRET]",
206
+ );
207
+ redacted = redacted.replace(
208
+ /\b(Authorization|Proxy-Authorization)\s*:\s*(?:Bearer|Basic|Token)\s+[^\s\n]+/gi,
209
+ "$1: [REDACTED_AUTH_HEADER]",
210
+ );
211
+ return redacted.replace(/\b(Cookie|Set-Cookie)\s*:\s*[^\n]+/gi, "$1: [REDACTED_COOKIE]");
212
+ }
213
+
176
214
  function applyDeletions(
177
215
  existing: Record<string, string[]>,
178
216
  deletions: Record<string, string[]>,
@@ -1,9 +1,16 @@
1
+ import { redactCrashSecrets } from "@sayknow-cli/utils";
2
+ import { redactChangelogEntry } from "./changelog";
1
3
  import type { ConventionalAnalysis } from "./types";
2
4
 
5
+ /** Same order as generated task messages, so a second pass stays stable. */
6
+ function redactCommitText(text: string): string {
7
+ return redactCrashSecrets(redactChangelogEntry(text));
8
+ }
9
+
3
10
  export function formatCommitMessage(analysis: ConventionalAnalysis, summary: string): string {
4
- const scopePart = analysis.scope ? `(${analysis.scope})` : "";
5
- const header = `${analysis.type}${scopePart}: ${summary}`;
6
- const bodyLines = analysis.details.map(detail => `- ${detail.text.trim()}`);
11
+ const scopePart = analysis.scope ? `(${redactCommitText(analysis.scope)})` : "";
12
+ const header = `${analysis.type}${scopePart}: ${redactCommitText(summary)}`;
13
+ const bodyLines = analysis.details.map(detail => `- ${redactCommitText(detail.text.trim())}`);
7
14
  if (bodyLines.length === 0) {
8
15
  return header;
9
16
  }
@@ -1,18 +1,121 @@
1
+ import { randomBytes } from "node:crypto";
1
2
  import * as fs from "node:fs";
2
3
  import * as path from "node:path";
3
- import { getAgentDir, isEnoent, logger } from "@sayknow-cli/utils";
4
+ import { renameNoReplacePath } from "@sayknow-cli/natives";
5
+ import { getAgentDir, isEnoent, isFsError, logger } from "@sayknow-cli/utils";
4
6
  import { JSONC, YAML } from "bun";
5
7
  import type { ZodType } from "zod/v4";
6
8
 
9
+ // Volumes without hard links fail `link`. Windows maps FAT ERROR_INVALID_FUNCTION to EISDIR.
10
+ const HARD_LINK_UNAVAILABLE = new Set(["EACCES", "EISDIR", "ENOSYS", "ENOTSUP", "EOPNOTSUPP", "EPERM", "EXDEV"]);
11
+
7
12
  /** Minimal subset of the AJV ConfigSchemaError shape this module actually relies on. */
8
13
  interface ConfigSchemaError {
9
14
  instancePath: string;
10
15
  message: string | undefined;
11
16
  }
12
17
 
18
+ /** True when the final path component exists, including a dangling symlink. */
19
+ function ymlPathPresent(ymlPath: string): boolean {
20
+ try {
21
+ fs.lstatSync(ymlPath);
22
+ return true;
23
+ } catch (error) {
24
+ if (isEnoent(error)) return false;
25
+ throw error;
26
+ }
27
+ }
28
+
29
+ function hardLinkUnavailable(error: unknown): boolean {
30
+ return isFsError(error) && HARD_LINK_UNAVAILABLE.has(error.code);
31
+ }
32
+
33
+ function stagedRegularFile(tmpPath: string): boolean {
34
+ try {
35
+ return fs.lstatSync(tmpPath).isFile();
36
+ } catch {
37
+ return false;
38
+ }
39
+ }
40
+
41
+ function discardStaged(tmpPath: string): void {
42
+ try {
43
+ fs.unlinkSync(tmpPath);
44
+ } catch {
45
+ // Unpublished, or the no-replace rename already moved this name.
46
+ }
47
+ }
48
+
49
+ /** Publish the completed private file when `link` is not supported. Never replaces `ymlPath`. */
50
+ function publishStagedWithoutHardLink(tmpPath: string, ymlPath: string): void {
51
+ const published = renameNoReplacePath(tmpPath, ymlPath);
52
+ if (!published.ok && published.reason !== "destination_exists") {
53
+ discardStaged(tmpPath);
54
+ throw new Error(`config migration could not publish without a hard link (${published.reason})`);
55
+ }
56
+ discardStaged(tmpPath);
57
+ }
58
+
59
+ /**
60
+ * Publish a new regular file as mode 0600. The bytes go to a private inode
61
+ * opened with O_EXCL and O_NOFOLLOW. `link` then attaches that inode to
62
+ * `ymlPath` and fails when the name exists, so a final-component symlink is
63
+ * not followed and an existing file is not replaced. A volume without hard
64
+ * links publishes that same completed file with a no-replace rename. The
65
+ * destination name stays absent until the bytes are complete.
66
+ */
67
+ function writeNewOwnerOnlyNoFollow(ymlPath: string, content: string): void {
68
+ // Ancestor symlinks only. The final component stays unresolved so no-follow still applies.
69
+ ymlPath = path.join(fs.realpathSync(path.dirname(ymlPath)), path.basename(ymlPath));
70
+ const noFollow = process.platform === "win32" ? 0 : (fs.constants.O_NOFOLLOW ?? 0);
71
+ const tmpPath = path.join(
72
+ path.dirname(ymlPath),
73
+ `.${path.basename(ymlPath)}.${process.pid}.${randomBytes(8).toString("hex")}.tmp`,
74
+ );
75
+ let fd: number | undefined;
76
+ try {
77
+ fd = fs.openSync(tmpPath, fs.constants.O_WRONLY | fs.constants.O_CREAT | fs.constants.O_EXCL | noFollow, 0o600);
78
+ if (process.platform !== "win32") fs.fchmodSync(fd, 0o600);
79
+ fs.writeFileSync(fd, content);
80
+ fs.fsyncSync(fd);
81
+ fs.closeSync(fd);
82
+ fd = undefined;
83
+ } catch (error) {
84
+ if (fd !== undefined) {
85
+ try {
86
+ fs.closeSync(fd);
87
+ } catch {
88
+ // The original failure is the one that must surface.
89
+ }
90
+ try {
91
+ fs.unlinkSync(tmpPath);
92
+ } catch {
93
+ // The destination name was not published.
94
+ }
95
+ }
96
+ throw error;
97
+ }
98
+ try {
99
+ fs.linkSync(tmpPath, ymlPath);
100
+ } catch (error) {
101
+ // The name is already present: a finished peer publish, or a file or symlink we must not replace.
102
+ if (isFsError(error) && (error.code === "EEXIST" || error.code === "ELOOP")) {
103
+ discardStaged(tmpPath);
104
+ return;
105
+ }
106
+ if (hardLinkUnavailable(error) && stagedRegularFile(tmpPath)) {
107
+ publishStagedWithoutHardLink(tmpPath, ymlPath);
108
+ return;
109
+ }
110
+ discardStaged(tmpPath);
111
+ throw error;
112
+ }
113
+ discardStaged(tmpPath);
114
+ }
115
+
13
116
  function migrateJsonToYml(jsonPath: string, ymlPath: string) {
14
117
  try {
15
- if (fs.existsSync(ymlPath)) return;
118
+ if (ymlPathPresent(ymlPath)) return;
16
119
  if (!fs.existsSync(jsonPath)) return;
17
120
 
18
121
  const content = fs.readFileSync(jsonPath, "utf-8");
@@ -21,7 +124,7 @@ function migrateJsonToYml(jsonPath: string, ymlPath: string) {
21
124
  logger.warn("migrateJsonToYml: invalid json structure", { path: jsonPath });
22
125
  return;
23
126
  }
24
- fs.writeFileSync(ymlPath, YAML.stringify(parsed, null, 2));
127
+ writeNewOwnerOnlyNoFollow(ymlPath, YAML.stringify(parsed, null, 2));
25
128
  } catch (error) {
26
129
  logger.warn("migrateJsonToYml: migration failed", { error: String(error) });
27
130
  }