@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
@@ -146,6 +146,109 @@ async function assertDirectoryNotSymlink(directoryPath: string): Promise<void> {
146
146
  }
147
147
  }
148
148
 
149
+ /** Group-write and world-write bits. Either one lets another user rename the session directory. */
150
+ const GROUP_OR_WORLD_WRITABLE = 0o022;
151
+
152
+ interface DirectoryIdentityStat {
153
+ isDirectory(): boolean;
154
+ isSymbolicLink(): boolean;
155
+ dev: number;
156
+ ino: number;
157
+ uid: number;
158
+ mode: number;
159
+ }
160
+
161
+ interface ManagedRootIdentity {
162
+ readonly dev: number;
163
+ readonly ino: number;
164
+ readonly uid: number;
165
+ }
166
+
167
+ function isUnsafeDirectory(stat: DirectoryIdentityStat): boolean {
168
+ return !stat.isDirectory() || stat.isSymbolicLink();
169
+ }
170
+
171
+ function managedRootIdentity(stat: DirectoryIdentityStat): ManagedRootIdentity {
172
+ return { dev: stat.dev, ino: stat.ino, uid: stat.uid };
173
+ }
174
+
175
+ function sameManagedRoot(stat: DirectoryIdentityStat, recorded: ManagedRootIdentity): boolean {
176
+ if (isUnsafeDirectory(stat) || stat.dev !== recorded.dev || stat.ino !== recorded.ino) return false;
177
+ // A later chmod to 0755 keeps the same directory. Only a writable bit, a new
178
+ // inode, or a different owner means the root was replaced or opened up.
179
+ if (process.platform === "win32") return true;
180
+ return stat.uid === recorded.uid && (stat.mode & GROUP_OR_WORLD_WRITABLE) === 0;
181
+ }
182
+
183
+ /**
184
+ * An existing managed session directory is adopted only when this user owns it
185
+ * and the group and world cannot write it. Windows has no POSIX owner bits.
186
+ */
187
+ function assertAdoptedManagedRoot(stat: DirectoryIdentityStat): void {
188
+ if (isUnsafeDirectory(stat)) throw new Error("Unsafe local:// root");
189
+ if (process.platform === "win32") return;
190
+ const uid = process.getuid?.();
191
+ if (uid === undefined || stat.uid !== uid || (stat.mode & GROUP_OR_WORLD_WRITABLE) !== 0) {
192
+ throw new Error("Unsafe local:// root");
193
+ }
194
+ }
195
+
196
+ function assertManagedParentSync(localRoot: string): void {
197
+ let parentStat: fsSync.Stats;
198
+ try {
199
+ parentStat = fsSync.lstatSync(path.dirname(localRoot));
200
+ } catch {
201
+ throw new Error("Unsafe local:// root");
202
+ }
203
+ assertAdoptedManagedRoot(parentStat);
204
+ }
205
+
206
+ /**
207
+ * Keep a pinned root unless a changed inode is validated as a settled
208
+ * recreation. A root created by this call may be rebound after migration.
209
+ */
210
+ function acceptManagedRootForInit(
211
+ localRoot: string,
212
+ rootStat: DirectoryIdentityStat,
213
+ recorded: ManagedRootIdentity | undefined,
214
+ adoptedExisting: boolean,
215
+ ): void {
216
+ if (recorded && adoptedExisting) {
217
+ if (sameManagedRoot(rootStat, recorded)) return;
218
+ const pending = pendingCreatedRoots.get(localRoot);
219
+ if (pending && sameManagedRoot(rootStat, pending)) return;
220
+ if (isSettledRecreatedManagedRoot(localRoot, rootStat)) return;
221
+ throw new Error("Unsafe local:// root");
222
+ }
223
+ if (recorded || adoptedExisting) {
224
+ assertAdoptedManagedRoot(rootStat);
225
+ return;
226
+ }
227
+ if (isUnsafeDirectory(rootStat)) throw new Error("Unsafe local:// root");
228
+ }
229
+
230
+ /**
231
+ * A pinned root whose inode changed is still ours when a skc initializer
232
+ * completed it: the temp sweeper (or `skc gc`) removed the directory and
233
+ * another process for the same session recreated it, writing a settled
234
+ * migration marker. POSIX owner and write-bit checks on the root and parent
235
+ * protect this exception. Windows changed-inode adoption stays fail-closed
236
+ * until this path validates the replacement's identity and ACLs.
237
+ */
238
+ function isSettledRecreatedManagedRoot(localRoot: string, rootStat: DirectoryIdentityStat): boolean {
239
+ if (process.platform === "win32") return false;
240
+ try {
241
+ assertAdoptedManagedRoot(rootStat);
242
+ assertManagedParentSync(localRoot);
243
+ const marker = path.join(localRoot, LEGACY_MIGRATION_MARKER);
244
+ const markerStat = fsSync.lstatSync(marker);
245
+ if (!markerStat.isFile() || markerStat.isSymbolicLink()) return false;
246
+ return isSettledMigrationMarkerValue(fsSync.readFileSync(marker, "utf8"));
247
+ } catch {
248
+ return false;
249
+ }
250
+ }
251
+
149
252
  const LEGACY_MIGRATION_MARKER = ".skc-local-legacy-migrated-v1";
150
253
  const MAX_LEGACY_LOCAL_BYTES = 64 * 1024 * 1024;
151
254
 
@@ -475,7 +578,31 @@ async function migrateLegacyLocal(
475
578
  }
476
579
  }
477
580
 
478
- const initializedLocalRoots = new Set<string>();
581
+ const initializedLocalRoots = new Map<string, ManagedRootIdentity>();
582
+ /** A directory this process created and has not finished migrating. */
583
+ const pendingCreatedRoots = new Map<string, ManagedRootIdentity>();
584
+
585
+ function assertRememberedManagedRoot(localRoot: string, recorded: ManagedRootIdentity): void {
586
+ let stat: fsSync.Stats;
587
+ try {
588
+ stat = fsSync.lstatSync(localRoot);
589
+ } catch {
590
+ throw new Error("Unsafe local:// root");
591
+ }
592
+ if (!sameManagedRoot(stat, recorded)) throw new Error("Unsafe local:// root");
593
+ }
594
+
595
+ function rememberManagedRoot(localRoot: string, expected: ManagedRootIdentity): void {
596
+ let stat: fsSync.Stats;
597
+ try {
598
+ stat = fsSync.lstatSync(localRoot);
599
+ } catch {
600
+ throw new Error("Unsafe local:// root");
601
+ }
602
+ if (!sameManagedRoot(stat, expected)) throw new Error("Unsafe local:// root");
603
+ initializedLocalRoots.set(localRoot, managedRootIdentity(stat));
604
+ pendingCreatedRoots.delete(localRoot);
605
+ }
479
606
 
480
607
  /**
481
608
  * Completes the mandatory legacy migration gate for a local root.
@@ -513,16 +640,21 @@ export async function initializeLocalRoot(options: LocalProtocolOptions): Promis
513
640
 
514
641
  await fs.mkdir(scratchParent, { recursive: true, mode: 0o700 });
515
642
  await assertDirectoryNotSymlink(scratchParent);
643
+ assertAdoptedManagedRoot(await fs.lstat(scratchParent));
644
+ let adoptedExisting = false;
516
645
  try {
517
646
  await fs.mkdir(localRoot, { mode: 0o700 });
518
647
  } catch (error) {
519
648
  if (error instanceof Error && "code" in error && error.code === "EEXIST") {
520
- await assertDirectoryNotSymlink(localRoot);
649
+ adoptedExisting = true;
521
650
  } else {
522
651
  throw error;
523
652
  }
524
653
  }
525
- await assertDirectoryNotSymlink(localRoot);
654
+ const rootStat = await fs.lstat(localRoot);
655
+ const recorded = initializedLocalRoots.get(localRoot);
656
+ acceptManagedRootForInit(localRoot, rootStat, recorded, adoptedExisting);
657
+ if (!adoptedExisting) pendingCreatedRoots.set(localRoot, managedRootIdentity(rootStat));
526
658
  await migrateLegacyLocal(options, localRoot, scratchParent);
527
659
 
528
660
  const resolvedScratchParent = await fs.realpath(scratchParent);
@@ -531,7 +663,10 @@ export async function initializeLocalRoot(options: LocalProtocolOptions): Promis
531
663
  if (resolvedLocalRoot === resolvedScratchParent) {
532
664
  throw new Error("Unsafe local:// root");
533
665
  }
534
- initializedLocalRoots.add(resolvedLocalRoot);
666
+ // Key the lexical path the sync resolver checks. realpath(/var -> /private/var)
667
+ // is a different string for the same directory, so caching only the real path
668
+ // let a later rename-swap skip this identity check.
669
+ rememberManagedRoot(localRoot, managedRootIdentity(rootStat));
535
670
  return resolvedLocalRoot;
536
671
  }
537
672
 
@@ -541,18 +676,41 @@ function initializeLocalRootSyncWhenLegacyAbsent(options: LocalProtocolOptions,
541
676
  initializeExplicitLocalRootSync(explicitRoot);
542
677
  return;
543
678
  }
544
- if (initializedLocalRoots.has(localRoot)) return;
679
+ const recorded = initializedLocalRoots.get(localRoot);
680
+ if (recorded) {
681
+ assertManagedParentSync(localRoot);
682
+ let present: fsSync.Stats | undefined;
683
+ try {
684
+ present = fsSync.lstatSync(localRoot);
685
+ } catch (error) {
686
+ if (!isEnoent(error)) throw new Error("Unsafe local:// root");
687
+ }
688
+ if (present) {
689
+ if (sameManagedRoot(present, recorded)) {
690
+ assertRememberedManagedRoot(localRoot, recorded);
691
+ return;
692
+ }
693
+ const pending = pendingCreatedRoots.get(localRoot);
694
+ if (!(pending && sameManagedRoot(present, pending)) && !isSettledRecreatedManagedRoot(localRoot, present)) {
695
+ throw new Error("Unsafe local:// root");
696
+ }
697
+ }
698
+ }
545
699
  const scratchParent = path.dirname(localRoot);
546
700
  fsSync.mkdirSync(scratchParent, { recursive: true, mode: 0o700 });
547
701
  const parentStat = fsSync.lstatSync(scratchParent);
548
702
  if (!parentStat.isDirectory() || parentStat.isSymbolicLink()) throw new Error("Unsafe local:// root");
703
+ assertAdoptedManagedRoot(parentStat);
704
+ let adoptedExisting = false;
549
705
  try {
550
706
  fsSync.mkdirSync(localRoot, { mode: 0o700 });
551
707
  } catch (error) {
552
708
  if ((error as NodeJS.ErrnoException).code !== "EEXIST") throw error;
709
+ adoptedExisting = true;
553
710
  }
554
711
  const rootStat = fsSync.lstatSync(localRoot);
555
- if (!rootStat.isDirectory() || rootStat.isSymbolicLink()) throw new Error("Unsafe local:// root");
712
+ acceptManagedRootForInit(localRoot, rootStat, recorded, adoptedExisting);
713
+ if (!adoptedExisting) pendingCreatedRoots.set(localRoot, managedRootIdentity(rootStat));
556
714
  const marker = path.join(localRoot, LEGACY_MIGRATION_MARKER);
557
715
  try {
558
716
  // Accept exactly the marker states the async gate treats as settled. A
@@ -562,7 +720,7 @@ function initializeLocalRootSyncWhenLegacyAbsent(options: LocalProtocolOptions,
562
720
  // async gate had already completed.
563
721
  if (!isSettledMigrationMarkerValue(fsSync.readFileSync(marker, "utf8")))
564
722
  throw new Error("Unsafe local:// migration marker");
565
- initializedLocalRoots.add(localRoot);
723
+ rememberManagedRoot(localRoot, managedRootIdentity(rootStat));
566
724
  return;
567
725
  } catch (error) {
568
726
  if (!isEnoent(error)) throw error;
@@ -583,7 +741,7 @@ function initializeLocalRootSyncWhenLegacyAbsent(options: LocalProtocolOptions,
583
741
  if (!isSettledMigrationMarkerValue(fsSync.readFileSync(marker, "utf8")))
584
742
  throw new Error("Unsafe local:// migration marker");
585
743
  }
586
- initializedLocalRoots.add(localRoot);
744
+ rememberManagedRoot(localRoot, managedRootIdentity(rootStat));
587
745
  }
588
746
 
589
747
  export function resolveLocalRoot(options: LocalProtocolOptions): string {
@@ -650,6 +808,7 @@ export class LocalProtocolHandler implements ProtocolHandler {
650
808
  LocalProtocolHandler.#override = undefined;
651
809
  LocalProtocolHandler.#ownedOverrides = [];
652
810
  initializedLocalRoots.clear();
811
+ pendingCreatedRoots.clear();
653
812
  }
654
813
 
655
814
  /**
@@ -0,0 +1,18 @@
1
+ import * as fs from "node:fs/promises";
2
+ import * as path from "node:path";
3
+ import { isEnoent } from "@sayknow-cli/utils";
4
+
5
+ export async function realSkillPath(baseDir: string, targetPath: string): Promise<string> {
6
+ const realBase = await fs.realpath(baseDir);
7
+ let realTarget: string;
8
+ try {
9
+ realTarget = await fs.realpath(targetPath);
10
+ } catch (error) {
11
+ if (isEnoent(error)) throw new Error(`File not found: ${targetPath}`);
12
+ throw error;
13
+ }
14
+ if (realTarget !== realBase && !realTarget.startsWith(realBase + path.sep)) {
15
+ throw new Error("Path traversal is not allowed");
16
+ }
17
+ return realTarget;
18
+ }
@@ -9,6 +9,7 @@
9
9
  */
10
10
  import * as path from "node:path";
11
11
  import { getActiveSkills } from "../extensibility/skills";
12
+ import { realSkillPath } from "./skill-path";
12
13
  import type { InternalResource, InternalUrl, ProtocolHandler } from "./types";
13
14
 
14
15
  function getContentType(filePath: string): InternalResource["contentType"] {
@@ -70,6 +71,7 @@ export class SkillProtocolHandler implements ProtocolHandler {
70
71
  if (!resolvedPath.startsWith(resolvedBaseDir + path.sep) && resolvedPath !== resolvedBaseDir) {
71
72
  throw new Error("Path traversal is not allowed");
72
73
  }
74
+ targetPath = await realSkillPath(skill.baseDir, targetPath);
73
75
  } else {
74
76
  targetPath = skill.filePath;
75
77
  }
@@ -21,6 +21,8 @@ export interface InternalResource {
21
21
  size?: number;
22
22
  /** Underlying filesystem path (for debugging, not exposed to agent) */
23
23
  sourcePath?: string;
24
+ /** True when model-facing reads must wrap the selected content as untrusted. */
25
+ untrusted?: boolean;
24
26
  /** Additional notes about resolution */
25
27
  notes?: string[];
26
28
  /**
package/src/lsp/client.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { isEnoent, isKnownSinkPeerClosedError, logger, untilAborted } from "@sayknow-cli/utils";
2
+ import { projectSafeSpawnEnv } from "@sayknow-cli/utils/shell-config";
2
3
  import { formatCrashDiagnosticNotice, writeCrashReport } from "../debug/crash-diagnostics";
3
4
  import { registerResourceOwner, spawnOwnedProcess } from "../runtime/process-lifecycle";
4
5
  import { ToolAbortError, throwIfAborted } from "../tools/tool-errors";
@@ -514,7 +515,7 @@ export async function getOrCreateClient(config: ServerConfig, cwd: string, initT
514
515
  const owner = spawnOwnedProcess([command, ...args], {
515
516
  cwd,
516
517
  stdin: "pipe",
517
- env: env ? { ...Bun.env, ...env } : undefined,
518
+ env: { ...projectSafeSpawnEnv(), ...env },
518
519
  name: `lsp:${config.command}`,
519
520
  });
520
521
  const proc = owner.child;
@@ -3,6 +3,7 @@
3
3
  * Uses Biome's CLI with JSON output instead of LSP (which has stale diagnostics issues).
4
4
  */
5
5
  import path from "node:path";
6
+ import { projectSafeSpawnEnv } from "@sayknow-cli/utils/shell-config";
6
7
  import type { Diagnostic, DiagnosticSeverity, LinterClient, ServerConfig } from "../../lsp/types";
7
8
 
8
9
  // =============================================================================
@@ -84,6 +85,7 @@ async function runBiome(
84
85
  try {
85
86
  const proc = Bun.spawn([command, ...args], {
86
87
  cwd,
88
+ env: projectSafeSpawnEnv(),
87
89
  stdout: "pipe",
88
90
  stderr: "pipe",
89
91
  windowsHide: true,
@@ -2,6 +2,7 @@
2
2
  * SwiftLint CLI-based linter client.
3
3
  * Parses SwiftLint's JSON reporter output into LSP Diagnostic format.
4
4
  */
5
+ import { projectSafeSpawnEnv } from "@sayknow-cli/utils/shell-config";
5
6
  import type { Diagnostic, DiagnosticSeverity, LinterClient, ServerConfig } from "../../lsp/types";
6
7
 
7
8
  /** Shape of a single violation from `swiftlint lint --reporter json`. */
@@ -36,6 +37,7 @@ async function runSwiftLint(
36
37
  try {
37
38
  const proc = Bun.spawn([command, ...args], {
38
39
  cwd,
40
+ env: projectSafeSpawnEnv(),
39
41
  stdout: "pipe",
40
42
  stderr: "pipe",
41
43
  windowsHide: true,
package/src/lsp/config.ts CHANGED
@@ -275,74 +275,30 @@ export function hasRootMarkers(cwd: string, markers: string[]): boolean {
275
275
  }
276
276
 
277
277
  // =============================================================================
278
- // Local Binary Resolution
278
+ // Trusted executable resolution
279
279
  // =============================================================================
280
280
 
281
281
  /**
282
- * Local bin directories to check before $PATH, ordered by priority.
283
- * Each entry maps a root marker to the bin directory to check.
284
- */
285
- const LOCAL_BIN_PATHS: Array<{ markers: string[]; binDir: string }> = [
286
- // Node.js - check node_modules/.bin/
287
- { markers: ["package.json", "package-lock.json", "yarn.lock", "pnpm-lock.yaml"], binDir: "node_modules/.bin" },
288
- // Python - check virtual environment bin directories
289
- { markers: ["pyproject.toml", "requirements.txt", "setup.py", "Pipfile"], binDir: ".venv/bin" },
290
- { markers: ["pyproject.toml", "requirements.txt", "setup.py", "Pipfile"], binDir: "venv/bin" },
291
- { markers: ["pyproject.toml", "requirements.txt", "setup.py", "Pipfile"], binDir: ".env/bin" },
292
- // Ruby - check vendor bundle and binstubs
293
- { markers: ["Gemfile", "Gemfile.lock"], binDir: "vendor/bundle/bin" },
294
- { markers: ["Gemfile", "Gemfile.lock"], binDir: "bin" },
295
- // Go - check project-local bin
296
- { markers: ["go.mod", "go.sum"], binDir: "bin" },
297
- ];
298
-
299
- const WINDOWS_LOCAL_EXECUTABLE_EXTENSIONS = [".exe", ".cmd", ".bat"] as const;
300
-
301
- function resolveLocalCommand(basePath: string): string | null {
302
- if (fs.existsSync(basePath)) return basePath;
303
- if (process.platform !== "win32") return null;
304
-
305
- // Package managers write Windows launchers with executable suffixes in node_modules/.bin.
306
- for (const extension of WINDOWS_LOCAL_EXECUTABLE_EXTENSIONS) {
307
- const candidate = `${basePath}${extension}`;
308
- if (fs.existsSync(candidate)) return candidate;
309
- }
310
-
311
- return null;
312
- }
313
-
314
- /**
315
- * Resolve a command to an executable path.
316
- * Checks project-local bin directories first, then falls back to $PATH.
282
+ * Resolve a host-spawn executable from $PATH without consulting project-controlled bin directories.
283
+ * LSP auto-detection and DAP adapter launch both use this rule.
317
284
  *
318
- * @param command - The command name (e.g., "typescript-language-server")
319
- * @param cwd - Working directory to search from
320
- * @returns Absolute path to the executable, or null if not found
285
+ * Trust is evaluated on both the discovered and canonical paths, but the returned
286
+ * path is the discovered one: multiplexed launchers such as rustup pick the proxied
287
+ * tool from argv[0], so `~/.cargo/bin/rust-analyzer -> rustup` must be spawned as
288
+ * `rust-analyzer`, not as the resolved `rustup` binary.
321
289
  */
322
- export function resolveCommand(command: string, cwd: string): string | null {
323
- // Check local bin directories based on project markers
324
- for (const { markers, binDir } of LOCAL_BIN_PATHS) {
325
- if (hasRootMarkers(cwd, markers)) {
326
- const localPath = path.join(cwd, binDir, command);
327
- const resolvedLocalPath = resolveLocalCommand(localPath);
328
- if (resolvedLocalPath) {
329
- return resolvedLocalPath;
330
- }
331
- }
332
- }
333
-
334
- // Fall back to $PATH
335
- return $which(command);
336
- }
337
-
338
- /** Resolve an LSP executable without consulting project-controlled bin directories. */
339
- function resolveTrustedLspCommand(command: string, cwd: string): string | null {
290
+ export function resolveTrustedCommand(command: string, cwd: string): string | null {
340
291
  if (!path.isAbsolute(command) && (command.includes("/") || command.includes("\\"))) return null;
341
292
  const discovered = path.isAbsolute(command) ? command : $which(command);
342
293
  if (!discovered) return null;
343
294
  if (isProjectControlledPath(discovered, cwd)) return null;
344
- const canonical = canonicalExistingPath(discovered);
345
- return canonical;
295
+ if (!canonicalExistingPath(discovered)) return null;
296
+ return discovered;
297
+ }
298
+
299
+ /** Same rule as `resolveTrustedCommand`: project-local bin directories are never searched. */
300
+ export function resolveCommand(command: string, cwd: string): string | null {
301
+ return resolveTrustedCommand(command, cwd);
346
302
  }
347
303
 
348
304
  interface ConfigSource {
@@ -548,8 +504,8 @@ export function loadConfig(cwd: string): LspConfig {
548
504
  // Check if project has root markers for this language
549
505
  if (!hasRootMarkers(cwd, config.rootMarkers)) continue;
550
506
 
551
- // Check if the language server binary is available (local or $PATH)
552
- const resolved = resolveTrustedLspCommand(config.command, cwd);
507
+ // Check if a trusted language server binary is available on $PATH.
508
+ const resolved = resolveTrustedCommand(config.command, cwd);
553
509
  if (!resolved) continue;
554
510
 
555
511
  detected[name] = { ...config, resolvedCommand: resolved };
@@ -564,7 +520,7 @@ export function loadConfig(cwd: string): LspConfig {
564
520
  for (const [name, config] of Object.entries(mergedWithRuntime)) {
565
521
  if (config.disabled) continue;
566
522
  if (!hasRootMarkers(cwd, config.rootMarkers)) continue;
567
- const resolved = resolveTrustedLspCommand(config.command, cwd);
523
+ const resolved = resolveTrustedCommand(config.command, cwd);
568
524
  if (!resolved) continue;
569
525
  available[name] = { ...config, resolvedCommand: resolved };
570
526
  }
package/src/lsp/edits.ts CHANGED
@@ -13,6 +13,7 @@ import type {
13
13
  WorkspaceEdit,
14
14
  } from "./types";
15
15
  import { uriToFile } from "./utils";
16
+ import { assertInsideWorkspace } from "./workspace-path";
16
17
 
17
18
  // =============================================================================
18
19
  // Text Edit Application
@@ -133,6 +134,7 @@ export async function applyWorkspaceEdit(edit: WorkspaceEdit, cwd: string): Prom
133
134
  const textEditsByUri = flattenWorkspaceTextEdits(edit);
134
135
  for (const [uri, textEdits] of textEditsByUri) {
135
136
  const filePath = uriToFile(uri);
137
+ await assertInsideWorkspace(cwd, filePath);
136
138
  await applyTextEdits(filePath, textEdits);
137
139
  applied.push(`Applied ${textEdits.length} edit(s) to ${formatPathRelativeToCwd(filePath, cwd)}`);
138
140
  }
@@ -144,18 +146,22 @@ export async function applyWorkspaceEdit(edit: WorkspaceEdit, cwd: string): Prom
144
146
  if (change.kind === "create") {
145
147
  const createOp = change as CreateFile;
146
148
  const filePath = uriToFile(createOp.uri);
149
+ await assertInsideWorkspace(cwd, filePath);
147
150
  await Bun.write(filePath, "");
148
151
  applied.push(`Created ${formatPathRelativeToCwd(filePath, cwd)}`);
149
152
  } else if (change.kind === "rename") {
150
153
  const renameOp = change as RenameFile;
151
154
  const oldPath = uriToFile(renameOp.oldUri);
152
155
  const newPath = uriToFile(renameOp.newUri);
156
+ await assertInsideWorkspace(cwd, oldPath);
157
+ await assertInsideWorkspace(cwd, newPath);
153
158
  await fs.mkdir(path.dirname(newPath), { recursive: true });
154
159
  await fs.rename(oldPath, newPath);
155
160
  applied.push(`Renamed ${formatPathRelativeToCwd(oldPath, cwd)} → ${formatPathRelativeToCwd(newPath, cwd)}`);
156
161
  } else if (change.kind === "delete") {
157
162
  const deleteOp = change as DeleteFile;
158
163
  const filePath = uriToFile(deleteOp.uri);
164
+ await assertInsideWorkspace(cwd, filePath);
159
165
  await fs.rm(filePath, { recursive: true });
160
166
  applied.push(`Deleted ${formatPathRelativeToCwd(filePath, cwd)}`);
161
167
  }
package/src/lsp/index.ts CHANGED
@@ -76,6 +76,7 @@ import {
76
76
  symbolKindToIcon,
77
77
  uriToFile,
78
78
  } from "./utils";
79
+ import { assertInsideWorkspace } from "./workspace-path";
79
80
 
80
81
  export type { LspServerStatus } from "./client";
81
82
  export type { LspToolDetails } from "./types";
@@ -346,6 +347,17 @@ interface FileRenamePair {
346
347
  * For files this is a single pair. For directories this walks every regular file underneath
347
348
  * and produces a parallel pair anchored at the new directory root.
348
349
  */
350
+ /**
351
+ * POSIX `/` contains every absolute path, and the shared helper's prefix for
352
+ * it is `//`, so skip containment there. A Windows drive root is only that
353
+ * volume, so it is checked. Any other platform root keeps the previous skip.
354
+ */
355
+ function workspaceRootSkipsContainment(root: string): boolean {
356
+ if (root === "/") return true;
357
+ if (/^[A-Za-z]:[\\/]$/.test(root)) return false;
358
+ return root === path.parse(root).root;
359
+ }
360
+
349
361
  async function enumerateRenamePairs(
350
362
  source: string,
351
363
  dest: string,
@@ -1505,6 +1517,23 @@ export class LspTool implements AgentTool<typeof lspSchema, LspToolDetails, Them
1505
1517
  }
1506
1518
  }
1507
1519
 
1520
+ // Reject every path this rename will write before the first write. Check the
1521
+ // caller signal after each await, including the last one.
1522
+ const cwd = this.session.cwd;
1523
+ throwIfAborted(signal);
1524
+ const workspaceRoot = await fs.promises.realpath(cwd);
1525
+ throwIfAborted(signal);
1526
+ if (!workspaceRootSkipsContainment(workspaceRoot)) {
1527
+ await assertInsideWorkspace(cwd, source);
1528
+ throwIfAborted(signal);
1529
+ await assertInsideWorkspace(cwd, dest);
1530
+ throwIfAborted(signal);
1531
+ for (const uri of acceptedByUri.keys()) {
1532
+ await assertInsideWorkspace(cwd, uriToFile(uri));
1533
+ throwIfAborted(signal);
1534
+ }
1535
+ }
1536
+
1508
1537
  for (const [uri, bucket] of acceptedByUri) {
1509
1538
  const filePath = uriToFile(uri);
1510
1539
  await applyTextEdits(filePath, bucket.edits);
@@ -0,0 +1,75 @@
1
+ import type { Stats } from "node:fs";
2
+ import * as fs from "node:fs/promises";
3
+ import path from "node:path";
4
+ import { ToolError } from "../tools/tool-errors";
5
+
6
+ function isEnoent(error: unknown): boolean {
7
+ return (error as NodeJS.ErrnoException).code === "ENOENT";
8
+ }
9
+
10
+ /** Drive-letter root such as `C:\`. A UNC share root is not a drive root. */
11
+ function windowsDriveLetter(root: string): string | null {
12
+ const match = /^([A-Za-z]):[\\/]$/.exec(root);
13
+ return match ? match[1].toLowerCase() : null;
14
+ }
15
+
16
+ /**
17
+ * A Windows drive root already ends in a separator. Prefixing another one
18
+ * (`C:\` + `\`) matches nothing on that volume, so compare the drive letter.
19
+ * Same-volume paths stay inside, including `\\?\C:\`. Other drives and UNC
20
+ * shares do not.
21
+ */
22
+ function sameWindowsDrive(driveRoot: string, candidate: string): boolean {
23
+ const letter = windowsDriveLetter(driveRoot);
24
+ if (!letter) return false;
25
+ const normalized = candidate.replace(/\//g, "\\");
26
+ const extended = /^\\\\\?\\([A-Za-z]):\\/.exec(normalized);
27
+ if (extended) return extended[1].toLowerCase() === letter;
28
+ if (normalized.startsWith("\\\\")) return false;
29
+ return path.win32.parse(normalized).root.toLowerCase() === `${letter}:\\`;
30
+ }
31
+
32
+ function escapes(root: string, candidate: string): boolean {
33
+ if (windowsDriveLetter(root)) return !sameWindowsDrive(root, candidate);
34
+ return candidate !== root && !candidate.startsWith(`${root}${path.sep}`);
35
+ }
36
+
37
+ /** Resolve a missing path through the nearest existing ancestor. */
38
+ async function canonicalize(filePath: string): Promise<string> {
39
+ try {
40
+ return await fs.realpath(filePath);
41
+ } catch (error) {
42
+ if (!isEnoent(error)) throw error;
43
+ }
44
+
45
+ const missing: string[] = [];
46
+ let cursor = filePath;
47
+ for (;;) {
48
+ let stat: Stats | undefined;
49
+ try {
50
+ stat = await fs.lstat(cursor);
51
+ } catch (error) {
52
+ if (!isEnoent(error)) throw error;
53
+ }
54
+ if (stat) {
55
+ try {
56
+ return path.join(await fs.realpath(cursor), ...missing);
57
+ } catch (error) {
58
+ if (isEnoent(error)) throw new ToolError(`LSP edit escapes the workspace: ${filePath}`);
59
+ throw error;
60
+ }
61
+ }
62
+ const parent = path.dirname(cursor);
63
+ if (parent === cursor) throw new ToolError(`LSP edit escapes the workspace: ${filePath}`);
64
+ missing.unshift(path.basename(cursor));
65
+ cursor = parent;
66
+ }
67
+ }
68
+
69
+ export async function assertInsideWorkspace(cwd: string, filePath: string): Promise<void> {
70
+ const root = await fs.realpath(cwd);
71
+ const candidate = await canonicalize(filePath);
72
+ if (escapes(root, candidate)) {
73
+ throw new ToolError(`LSP edit escapes the workspace: ${filePath}`);
74
+ }
75
+ }