@sayknow-cli/coding-agent 0.7.11 → 0.7.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (427) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/types/async/result-formatting.d.ts +2 -0
  3. package/dist/types/capability/fs.d.ts +22 -3
  4. package/dist/types/capability/mcp.d.ts +2 -0
  5. package/dist/types/cli/append-system-prompt.d.ts +6 -0
  6. package/dist/types/cli/update-cli.d.ts +3 -0
  7. package/dist/types/commands/contribution-prep.d.ts +0 -3
  8. package/dist/types/commands/migrate.d.ts +1 -1
  9. package/dist/types/commands/sdk.d.ts +9 -0
  10. package/dist/types/commit/changelog/index.d.ts +1 -0
  11. package/dist/types/config/settings-schema.d.ts +14 -0
  12. package/dist/types/config/settings.d.ts +7 -1
  13. package/dist/types/coordinator-mcp/session-reaper.d.ts +5 -0
  14. package/dist/types/cursor-delete-path.d.ts +1 -0
  15. package/dist/types/cursor-mcp-name.d.ts +8 -0
  16. package/dist/types/dap/config.d.ts +8 -4
  17. package/dist/types/dap/session.d.ts +11 -2
  18. package/dist/types/debug/report-bundle-parent.d.ts +2 -0
  19. package/dist/types/debug/system-info.d.ts +6 -1
  20. package/dist/types/discovery/helpers.d.ts +11 -3
  21. package/dist/types/discovery/mcp-json.d.ts +1 -0
  22. package/dist/types/edit/file-read-cache.d.ts +4 -0
  23. package/dist/types/edit/modes/patch.d.ts +14 -0
  24. package/dist/types/edit/modes/replace.d.ts +8 -0
  25. package/dist/types/eval/py/runtime.d.ts +9 -0
  26. package/dist/types/exa/mcp-client.d.ts +11 -6
  27. package/dist/types/exec/bash-executor.d.ts +18 -1
  28. package/dist/types/export/html/css-color.d.ts +2 -0
  29. package/dist/types/export/html/html-export-destination.d.ts +2 -0
  30. package/dist/types/export/html/template.generated.d.ts +1 -1
  31. package/dist/types/extensibility/custom-tools/loader.d.ts +3 -2
  32. package/dist/types/extensibility/custom-tools/types.d.ts +3 -1
  33. package/dist/types/extensibility/plugins/marketplace/cache.d.ts +2 -0
  34. package/dist/types/extensibility/plugins/plugin-link-path.d.ts +2 -0
  35. package/dist/types/goals/runtime.d.ts +6 -0
  36. package/dist/types/harness-control-plane/receipt-spool.d.ts +4 -0
  37. package/dist/types/hindsight/content.d.ts +5 -6
  38. package/dist/types/internal-urls/skill-path.d.ts +1 -0
  39. package/dist/types/internal-urls/types.d.ts +2 -0
  40. package/dist/types/lsp/clients/swiftlint-client.d.ts +0 -4
  41. package/dist/types/lsp/config.d.ts +8 -5
  42. package/dist/types/lsp/workspace-path.d.ts +1 -0
  43. package/dist/types/migrate/adapters/codex.d.ts +2 -1
  44. package/dist/types/migrate/adapters/index.d.ts +10 -1
  45. package/dist/types/migrate/executor.d.ts +3 -1
  46. package/dist/types/migrate/types.d.ts +15 -3
  47. package/dist/types/modes/components/custom-editor.d.ts +6 -0
  48. package/dist/types/modes/components/extensions/state-manager.d.ts +4 -3
  49. package/dist/types/modes/components/model-selector.d.ts +46 -0
  50. package/dist/types/modes/controllers/input-controller.d.ts +9 -0
  51. package/dist/types/modes/interactive-mode.d.ts +1 -0
  52. package/dist/types/modes/utils/macos-option-forwarding.d.ts +17 -0
  53. package/dist/types/runtime-mcp/content-limits.d.ts +4 -0
  54. package/dist/types/runtime-mcp/manager.d.ts +9 -1
  55. package/dist/types/runtime-mcp/mcp-redirect.d.ts +9 -0
  56. package/dist/types/runtime-mcp/oauth-public-url.d.ts +1 -0
  57. package/dist/types/runtime-mcp/plugin-mcp-name-filter.d.ts +22 -0
  58. package/dist/types/runtime-mcp/plugin-network-boundary.d.ts +1 -0
  59. package/dist/types/runtime-mcp/project-host-values.d.ts +33 -0
  60. package/dist/types/runtime-mcp/smithery-registry.d.ts +24 -0
  61. package/dist/types/runtime-mcp/tool-bridge.d.ts +4 -0
  62. package/dist/types/runtime-mcp/types.d.ts +6 -0
  63. package/dist/types/sdk/broker/ensure.d.ts +2 -0
  64. package/dist/types/sdk/broker/lifecycle-ledger.d.ts +5 -1
  65. package/dist/types/sdk/broker/runtime.d.ts +1 -1
  66. package/dist/types/sdk/bus/chat-daemon-control.d.ts +3 -1
  67. package/dist/types/sdk/bus/telegram-daemon-contract.d.ts +3 -1
  68. package/dist/types/sdk/bus/telegram-daemon.d.ts +1 -0
  69. package/dist/types/sdk/host/events.d.ts +4 -0
  70. package/dist/types/session/agent-session.d.ts +22 -2
  71. package/dist/types/session/auto-resume.d.ts +5 -0
  72. package/dist/types/session/messages.d.ts +5 -1
  73. package/dist/types/session/session-manager.d.ts +13 -0
  74. package/dist/types/session/session-storage.d.ts +8 -0
  75. package/dist/types/session/streaming-output.d.ts +11 -0
  76. package/dist/types/session-import/redact.d.ts +1 -1
  77. package/dist/types/skc-runtime/managed-owner-admission.d.ts +3 -0
  78. package/dist/types/skc-runtime/psmux-detect.d.ts +5 -4
  79. package/dist/types/skc-runtime/ralplan-runtime.d.ts +5 -0
  80. package/dist/types/skc-runtime/sidecar-bootstrap-env.d.ts +6 -0
  81. package/dist/types/skc-runtime/state-writer.d.ts +4 -1
  82. package/dist/types/skc-runtime/tmux-sessions.d.ts +24 -0
  83. package/dist/types/skc-runtime/ultragoal-runtime.d.ts +4 -0
  84. package/dist/types/skill-state/workflow-mutation-guard.d.ts +20 -1
  85. package/dist/types/slash-commands/helpers/mcp.d.ts +5 -0
  86. package/dist/types/ssh/ssh-executor.d.ts +3 -1
  87. package/dist/types/system-prompt.d.ts +5 -2
  88. package/dist/types/task/executor.d.ts +17 -3
  89. package/dist/types/task/isolation-dir.d.ts +26 -0
  90. package/dist/types/task/role-body.d.ts +11 -0
  91. package/dist/types/task/token-log-mode.test.d.ts +1 -0
  92. package/dist/types/tools/ask.d.ts +77 -254
  93. package/dist/types/tools/ast-edit-write-path.d.ts +23 -0
  94. package/dist/types/tools/atomic-file-write.d.ts +74 -0
  95. package/dist/types/tools/auto-generated-guard.d.ts +5 -2
  96. package/dist/types/tools/bash-allowed-prefixes.d.ts +16 -0
  97. package/dist/types/tools/bash-interactive.d.ts +2 -0
  98. package/dist/types/tools/bash-skill-urls.d.ts +5 -1
  99. package/dist/types/tools/bash.d.ts +1 -0
  100. package/dist/types/tools/browser/cdp-url.d.ts +2 -0
  101. package/dist/types/tools/browser/tab-worker.d.ts +2 -0
  102. package/dist/types/tools/debug.d.ts +2 -2
  103. package/dist/types/tools/explicit-artifact.d.ts +8 -0
  104. package/dist/types/tools/fetch.d.ts +7 -4
  105. package/dist/types/tools/github-side-effect.d.ts +22 -0
  106. package/dist/types/tools/index.d.ts +3 -0
  107. package/dist/types/tools/monitor-mutation.d.ts +9 -0
  108. package/dist/types/tools/recipe/index.d.ts +2 -0
  109. package/dist/types/tools/recipe/recipe-guard.d.ts +7 -0
  110. package/dist/types/tools/restricted-cwd.d.ts +1 -0
  111. package/dist/types/tools/reverse-engineer.d.ts +81 -0
  112. package/dist/types/tools/search-tool-bm25.d.ts +2 -0
  113. package/dist/types/tools/tmux-self-injection-guard.d.ts +17 -0
  114. package/dist/types/tools/untrusted-content.d.ts +12 -0
  115. package/dist/types/utils/file-mentions.d.ts +5 -0
  116. package/dist/types/utils/open.d.ts +0 -1
  117. package/dist/types/utils/shell-snapshot.d.ts +2 -0
  118. package/dist/types/utils/title-generator.d.ts +12 -2
  119. package/dist/types/utils/tools-checksum.d.ts +7 -0
  120. package/dist/types/utils/xml-escape.d.ts +2 -0
  121. package/dist/types/web/scrapers/types.d.ts +8 -1
  122. package/dist/types/web/search/providers/codex.d.ts +6 -7
  123. package/dist/types/web/search/providers/insane.d.ts +7 -1
  124. package/dist/types/web/search/providers/kimi.d.ts +2 -0
  125. package/dist/types/web/search/providers/searxng.d.ts +7 -0
  126. package/dist/types/web/search/providers/xai.d.ts +2 -0
  127. package/package.json +7 -7
  128. package/scripts/generate-sdk-operation-inventory.ts +4 -0
  129. package/src/async/job-manager.ts +23 -9
  130. package/src/async/result-formatting.ts +40 -0
  131. package/src/capability/fs.ts +78 -11
  132. package/src/capability/mcp.ts +2 -0
  133. package/src/cli/append-system-prompt.ts +12 -0
  134. package/src/cli/auth-broker-cli.ts +22 -12
  135. package/src/cli/config-cli.ts +8 -18
  136. package/src/cli/migrate-cli.ts +7 -5
  137. package/src/cli/ssh-cli.ts +6 -3
  138. package/src/cli/stats-cli.ts +9 -4
  139. package/src/cli/update-cli.ts +42 -0
  140. package/src/cli/web-search-cli.ts +9 -3
  141. package/src/cli.ts +5 -9
  142. package/src/commands/commit.ts +2 -2
  143. package/src/commands/contribution-prep.ts +1 -3
  144. package/src/commands/harness.ts +25 -15
  145. package/src/commands/launch.ts +1 -1
  146. package/src/commands/migrate.ts +3 -3
  147. package/src/commands/sdk.ts +115 -14
  148. package/src/commands/ultragoal.ts +14 -8
  149. package/src/commit/agentic/agent.ts +6 -6
  150. package/src/commit/analysis/conventional.ts +14 -5
  151. package/src/commit/changelog/index.ts +39 -1
  152. package/src/commit/message.ts +10 -3
  153. package/src/config/config-file.ts +106 -3
  154. package/src/config/keybindings.ts +154 -7
  155. package/src/config/mcp-schema.json +4 -0
  156. package/src/config/model-registry.ts +10 -2
  157. package/src/config/settings-schema.ts +18 -0
  158. package/src/config/settings.ts +32 -4
  159. package/src/coordinator-mcp/policy.ts +14 -4
  160. package/src/coordinator-mcp/server.ts +44 -4
  161. package/src/coordinator-mcp/session-reaper.ts +9 -1
  162. package/src/cursor-delete-path.ts +10 -0
  163. package/src/cursor-mcp-name.ts +15 -0
  164. package/src/cursor.ts +13 -2
  165. package/src/dap/client.ts +9 -2
  166. package/src/dap/config.ts +33 -13
  167. package/src/dap/defaults.json +1 -1
  168. package/src/dap/session.ts +161 -36
  169. package/src/debug/crash-diagnostics.ts +89 -6
  170. package/src/debug/report-bundle-parent.ts +22 -0
  171. package/src/debug/report-bundle.ts +100 -3
  172. package/src/debug/system-info.ts +21 -4
  173. package/src/defaults/skc/extensions/grok-cli-vendor/src/shared/base-url.ts +21 -7
  174. package/src/defaults/skc/skills/deep-interview/SKILL.md +1 -1
  175. package/src/discovery/agents-md.ts +3 -2
  176. package/src/discovery/agents.ts +3 -2
  177. package/src/discovery/builtin.ts +21 -11
  178. package/src/discovery/claude.ts +5 -4
  179. package/src/discovery/cline.ts +2 -2
  180. package/src/discovery/codex.ts +6 -5
  181. package/src/discovery/cursor.ts +11 -2
  182. package/src/discovery/gemini.ts +4 -3
  183. package/src/discovery/github.ts +2 -2
  184. package/src/discovery/helpers.ts +51 -11
  185. package/src/discovery/mcp-json.ts +28 -12
  186. package/src/discovery/opencode.ts +2 -1
  187. package/src/discovery/ssh.ts +11 -6
  188. package/src/discovery/substitute-plugin-root.ts +3 -1
  189. package/src/discovery/vscode.ts +3 -3
  190. package/src/edit/apply-patch/index.ts +12 -1
  191. package/src/edit/file-read-cache.ts +24 -6
  192. package/src/edit/index.ts +90 -20
  193. package/src/edit/modes/patch.ts +215 -9
  194. package/src/edit/modes/replace.ts +141 -0
  195. package/src/eval/js/context-manager.ts +29 -3
  196. package/src/eval/js/worker-entry.ts +51 -18
  197. package/src/eval/py/runner.py +144 -5
  198. package/src/eval/py/runtime.ts +44 -4
  199. package/src/eval/py/tool-bridge.ts +4 -0
  200. package/src/exa/mcp-client.ts +53 -11
  201. package/src/exec/bash-executor.ts +87 -4
  202. package/src/exec/non-interactive-env.ts +0 -1
  203. package/src/export/html/css-color.ts +9 -0
  204. package/src/export/html/html-export-destination.ts +16 -0
  205. package/src/export/html/index.ts +102 -8
  206. package/src/export/html/template.generated.ts +1 -1
  207. package/src/extensibility/custom-tools/loader.ts +13 -3
  208. package/src/extensibility/custom-tools/types.ts +3 -1
  209. package/src/extensibility/custom-tools/wrapper.ts +3 -1
  210. package/src/extensibility/plugins/manager.ts +3 -2
  211. package/src/extensibility/plugins/marketplace/cache.ts +15 -0
  212. package/src/extensibility/plugins/marketplace/fetcher.ts +2 -2
  213. package/src/extensibility/plugins/marketplace/manager.ts +5 -3
  214. package/src/extensibility/plugins/plugin-link-path.ts +12 -0
  215. package/src/extensibility/skc-plugins/mcp-policy.ts +2 -1
  216. package/src/goals/runtime.ts +30 -8
  217. package/src/harness-control-plane/finalize.ts +10 -0
  218. package/src/harness-control-plane/operate.ts +12 -4
  219. package/src/harness-control-plane/owner.ts +8 -1
  220. package/src/harness-control-plane/receipt-spool.ts +105 -28
  221. package/src/harness-control-plane/storage.ts +124 -6
  222. package/src/hashline/execute.ts +3 -3
  223. package/src/hashline/recovery.ts +85 -2
  224. package/src/hindsight/config.ts +9 -3
  225. package/src/hindsight/content.ts +116 -16
  226. package/src/hindsight/mental-models.ts +22 -10
  227. package/src/hindsight/state.ts +7 -4
  228. package/src/hooks/native-skill-hook.ts +17 -12
  229. package/src/i18n/messages/de.settings.ts +3 -0
  230. package/src/i18n/messages/es.settings.ts +3 -0
  231. package/src/i18n/messages/fr.settings.ts +3 -0
  232. package/src/i18n/messages/ja.settings.ts +3 -0
  233. package/src/i18n/messages/ko.settings.ts +3 -0
  234. package/src/i18n/messages/zh.settings.ts +3 -0
  235. package/src/internal-urls/artifact-protocol.ts +3 -1
  236. package/src/internal-urls/docs-index.generated.ts +10 -10
  237. package/src/internal-urls/local-protocol.ts +167 -8
  238. package/src/internal-urls/skill-path.ts +18 -0
  239. package/src/internal-urls/skill-protocol.ts +2 -0
  240. package/src/internal-urls/types.ts +2 -0
  241. package/src/lsp/client.ts +2 -1
  242. package/src/lsp/clients/biome-client.ts +2 -0
  243. package/src/lsp/clients/swiftlint-client.ts +2 -0
  244. package/src/lsp/config.ts +18 -62
  245. package/src/lsp/edits.ts +6 -0
  246. package/src/lsp/index.ts +29 -0
  247. package/src/lsp/workspace-path.ts +75 -0
  248. package/src/main.ts +33 -11
  249. package/src/memories/index.ts +141 -9
  250. package/src/migrate/action-planner.ts +57 -0
  251. package/src/migrate/adapters/claude-code.ts +23 -4
  252. package/src/migrate/adapters/codex.ts +22 -4
  253. package/src/migrate/adapters/index.ts +22 -4
  254. package/src/migrate/adapters/opencode.ts +6 -1
  255. package/src/migrate/executor.ts +84 -7
  256. package/src/migrate/report.ts +19 -2
  257. package/src/migrate/types.ts +14 -4
  258. package/src/modes/DESIGN.md +5 -0
  259. package/src/modes/acp/acp-agent.ts +35 -2
  260. package/src/modes/acp/permission-mode.ts +18 -1
  261. package/src/modes/components/custom-editor.ts +14 -0
  262. package/src/modes/components/extensions/extension-dashboard.ts +2 -2
  263. package/src/modes/components/extensions/inspector-panel.ts +9 -5
  264. package/src/modes/components/extensions/state-manager.ts +15 -5
  265. package/src/modes/components/model-selector.ts +144 -94
  266. package/src/modes/components/welcome.ts +3 -2
  267. package/src/modes/controllers/command-controller.ts +300 -9
  268. package/src/modes/controllers/event-controller.ts +1 -1
  269. package/src/modes/controllers/extension-ui-controller.ts +32 -19
  270. package/src/modes/controllers/input-controller.ts +62 -26
  271. package/src/modes/controllers/plan-mode-controller.ts +17 -7
  272. package/src/modes/controllers/runtime-mcp-command-controller.ts +25 -20
  273. package/src/modes/controllers/ssh-command-controller.ts +3 -1
  274. package/src/modes/interactive-mode.ts +10 -0
  275. package/src/modes/utils/macos-option-forwarding.ts +80 -0
  276. package/src/prompts/system/irc-incoming.md +3 -1
  277. package/src/prompts/system/project-prompt.md +19 -0
  278. package/src/prompts/system/system-prompt.md +3 -0
  279. package/src/prompts/tools/ask.md +2 -0
  280. package/src/prompts/tools/debug.md +1 -1
  281. package/src/prompts/tools/monitor.md +7 -5
  282. package/src/prompts/tools/reverse-engineer.md +29 -0
  283. package/src/runtime-credential-selector.ts +2 -2
  284. package/src/runtime-mcp/config-writer.ts +10 -6
  285. package/src/runtime-mcp/config.ts +1 -0
  286. package/src/runtime-mcp/content-limits.ts +7 -0
  287. package/src/runtime-mcp/json-rpc.ts +2 -1
  288. package/src/runtime-mcp/manager.ts +57 -9
  289. package/src/runtime-mcp/mcp-redirect.ts +73 -0
  290. package/src/runtime-mcp/oauth-flow.ts +43 -5
  291. package/src/runtime-mcp/oauth-public-url.ts +8 -0
  292. package/src/runtime-mcp/plugin-mcp-name-filter.ts +62 -0
  293. package/src/runtime-mcp/plugin-network-boundary.ts +4 -0
  294. package/src/runtime-mcp/project-host-values.ts +50 -0
  295. package/src/runtime-mcp/render.ts +16 -1
  296. package/src/runtime-mcp/smithery-registry.ts +22 -3
  297. package/src/runtime-mcp/tool-bridge.ts +194 -21
  298. package/src/runtime-mcp/transports/http.ts +4 -3
  299. package/src/runtime-mcp/transports/stdio.ts +2 -1
  300. package/src/runtime-mcp/types.ts +6 -0
  301. package/src/sdk/broker/broker.ts +11 -2
  302. package/src/sdk/broker/ensure.ts +131 -10
  303. package/src/sdk/broker/lifecycle-ledger.ts +18 -3
  304. package/src/sdk/broker/lifecycle.ts +21 -19
  305. package/src/sdk/broker/runtime.ts +1 -1
  306. package/src/sdk/bus/chat-daemon-cli.ts +38 -1
  307. package/src/sdk/bus/chat-daemon-control.ts +5 -3
  308. package/src/sdk/bus/index.ts +5 -3
  309. package/src/sdk/bus/lifecycle-control-runtime.ts +9 -2
  310. package/src/sdk/bus/session-control.ts +2 -0
  311. package/src/sdk/bus/slack-daemon.ts +8 -1
  312. package/src/sdk/bus/slack-live-provider.ts +3 -1
  313. package/src/sdk/bus/telegram-daemon-contract.ts +3 -1
  314. package/src/sdk/bus/telegram-daemon-control.ts +17 -12
  315. package/src/sdk/bus/telegram-daemon.ts +41 -1
  316. package/src/sdk/host/events.ts +67 -4
  317. package/src/sdk/mcp/server.ts +16 -3
  318. package/src/sdk/protocol/operation-inventory.generated.json +22 -0
  319. package/src/sdk/session.ts +18 -25
  320. package/src/secrets/obfuscator.ts +92 -12
  321. package/src/session/agent-session.ts +466 -100
  322. package/src/session/artifacts.ts +3 -1
  323. package/src/session/auto-resume.ts +45 -8
  324. package/src/session/history-storage.ts +172 -8
  325. package/src/session/internal/managed-session-scope.ts +130 -52
  326. package/src/session/messages.ts +47 -6
  327. package/src/session/session-manager.ts +116 -8
  328. package/src/session/session-storage.ts +31 -1
  329. package/src/session/streaming-output.ts +263 -4
  330. package/src/session-import/redact.ts +76 -3
  331. package/src/setup/hermes-setup.ts +4 -1
  332. package/src/skc-runtime/gc-runtime.ts +26 -4
  333. package/src/skc-runtime/launch-tmux.ts +21 -11
  334. package/src/skc-runtime/launch-worktree.ts +42 -3
  335. package/src/skc-runtime/managed-owner-admission.ts +46 -2
  336. package/src/skc-runtime/psmux-detect.ts +29 -5
  337. package/src/skc-runtime/ralplan-runtime.ts +14 -1
  338. package/src/skc-runtime/session-resolution.ts +38 -6
  339. package/src/skc-runtime/sidecar-bootstrap-env.ts +19 -0
  340. package/src/skc-runtime/state-writer.ts +134 -16
  341. package/src/skc-runtime/tmux-sessions.ts +85 -4
  342. package/src/skc-runtime/ultragoal-change-set.ts +18 -2
  343. package/src/skc-runtime/ultragoal-guard.ts +9 -1
  344. package/src/skc-runtime/ultragoal-runtime.ts +26 -9
  345. package/src/skill-state/active-state.ts +13 -0
  346. package/src/skill-state/workflow-mutation-guard.ts +3297 -180
  347. package/src/slash-commands/builtin-registry.ts +14 -8
  348. package/src/slash-commands/helpers/mcp.ts +20 -7
  349. package/src/ssh/ssh-executor.ts +3 -1
  350. package/src/stt/recorder.ts +26 -9
  351. package/src/system-prompt.ts +65 -16
  352. package/src/task/commands.ts +3 -1
  353. package/src/task/executor.ts +52 -7
  354. package/src/task/index.ts +28 -0
  355. package/src/task/isolation-dir.ts +143 -0
  356. package/src/task/role-body.ts +84 -0
  357. package/src/task/token-log-mode.test.ts +162 -0
  358. package/src/task/token-log.ts +91 -2
  359. package/src/task/worktree.ts +16 -7
  360. package/src/tools/archive-reader.ts +653 -31
  361. package/src/tools/ask.ts +86 -14
  362. package/src/tools/ast-edit-write-path.ts +133 -0
  363. package/src/tools/ast-edit.ts +27 -1
  364. package/src/tools/ast-grep.ts +7 -2
  365. package/src/tools/atomic-file-write.ts +625 -0
  366. package/src/tools/auto-generated-guard.ts +28 -8
  367. package/src/tools/bash-allowed-prefixes.ts +225 -6
  368. package/src/tools/bash-interactive.ts +12 -0
  369. package/src/tools/bash-skill-urls.ts +113 -7
  370. package/src/tools/bash.ts +152 -20
  371. package/src/tools/browser/cdp-url.ts +18 -0
  372. package/src/tools/browser/tab-worker.ts +49 -14
  373. package/src/tools/browser.ts +25 -8
  374. package/src/tools/cron.ts +10 -1
  375. package/src/tools/debug.ts +16 -8
  376. package/src/tools/eval.ts +71 -34
  377. package/src/tools/explicit-artifact.ts +89 -0
  378. package/src/tools/fetch.ts +26 -17
  379. package/src/tools/gh.ts +40 -12
  380. package/src/tools/github-side-effect.ts +112 -0
  381. package/src/tools/image-gen.ts +24 -10
  382. package/src/tools/index.ts +6 -0
  383. package/src/tools/monitor-mutation.ts +27 -0
  384. package/src/tools/monitor.ts +28 -1
  385. package/src/tools/output-meta.ts +74 -5
  386. package/src/tools/read.ts +24 -36
  387. package/src/tools/recipe/index.ts +12 -0
  388. package/src/tools/recipe/recipe-guard.ts +19 -0
  389. package/src/tools/recipe/runner.ts +23 -12
  390. package/src/tools/render-utils.ts +2 -2
  391. package/src/tools/restricted-cwd.ts +10 -0
  392. package/src/tools/reverse-engineer.ts +497 -0
  393. package/src/tools/search-tool-bm25.ts +14 -3
  394. package/src/tools/search.ts +3 -2
  395. package/src/tools/ssh.ts +235 -8
  396. package/src/tools/subagent-render.ts +43 -7
  397. package/src/tools/subagent.ts +7 -3
  398. package/src/tools/tmux-self-injection-guard.ts +3538 -0
  399. package/src/tools/todo-write.ts +41 -3
  400. package/src/tools/untrusted-content.ts +23 -0
  401. package/src/tools/vim.ts +2 -2
  402. package/src/tools/write.ts +37 -4
  403. package/src/tui/tree-list.ts +15 -1
  404. package/src/utils/commit-message-generator.ts +9 -2
  405. package/src/utils/external-editor.ts +21 -7
  406. package/src/utils/file-mentions.ts +75 -7
  407. package/src/utils/git.ts +38 -7
  408. package/src/utils/open.ts +73 -4
  409. package/src/utils/shell-snapshot.ts +9 -1
  410. package/src/utils/title-generator.ts +61 -16
  411. package/src/utils/tools-checksum.ts +34 -0
  412. package/src/utils/tools-manager.ts +24 -6
  413. package/src/utils/xml-escape.ts +14 -0
  414. package/src/web/insane/url-guard.ts +2 -1
  415. package/src/web/scrapers/types.ts +8 -0
  416. package/src/web/scrapers/youtube.ts +3 -2
  417. package/src/web/search/index.ts +4 -3
  418. package/src/web/search/providers/anthropic.ts +4 -4
  419. package/src/web/search/providers/codex.ts +31 -34
  420. package/src/web/search/providers/insane.ts +145 -28
  421. package/src/web/search/providers/kimi.ts +15 -5
  422. package/src/web/search/providers/searxng.ts +47 -4
  423. package/src/web/search/providers/xai.ts +7 -2
  424. package/dist/types/cli/shell-cli.d.ts +0 -8
  425. package/dist/types/commands/shell.d.ts +0 -21
  426. package/src/cli/shell-cli.ts +0 -176
  427. package/src/commands/shell.ts +0 -29
@@ -8,6 +8,7 @@ import type { AgentToolResult } from "@sayknow-cli/agent-core";
8
8
  import * as z from "zod/v4";
9
9
  import type { WritethroughCallback, WritethroughDeferredHandle } from "../../lsp";
10
10
  import type { ToolSession } from "../../tools";
11
+ import { assertEditableFile, assertEditableFileContent } from "../../tools/auto-generated-guard";
11
12
  import { invalidateFsScanAfterWrite } from "../../tools/fs-cache-invalidation";
12
13
  import { outputMeta } from "../../tools/output-meta";
13
14
  import { enforcePlanModeWrite, resolvePlanPath } from "../../tools/plan-mode-guard";
@@ -1088,6 +1089,7 @@ export async function executeReplaceSingle(
1088
1089
  }
1089
1090
 
1090
1091
  const absolutePath = resolvePlanPath(session, path);
1092
+ await assertEditableFile(absolutePath, path, session.settings);
1091
1093
  return withEditPathMutation([absolutePath], () =>
1092
1094
  executeReplaceSingleUnderLock({
1093
1095
  session,
@@ -1116,6 +1118,7 @@ async function executeReplaceSingleUnderLock(
1116
1118
  },
1117
1119
  ): Promise<AgentToolResult<EditToolDetails, typeof replaceEditEntrySchema>> {
1118
1120
  const {
1121
+ session,
1119
1122
  path,
1120
1123
  signal,
1121
1124
  batchRequest,
@@ -1130,6 +1133,8 @@ async function executeReplaceSingleUnderLock(
1130
1133
  } = options;
1131
1134
 
1132
1135
  const rawContent = await readEditFileText(absolutePath, path);
1136
+ assertEditableFileContent(rawContent, path, session.settings);
1137
+ await assertEditableFile(absolutePath, path, session.settings);
1133
1138
  const { bom, text: content } = stripBom(rawContent);
1134
1139
  const originalEnding = detectLineEnding(content);
1135
1140
  const normalizedContent = normalizeToLF(content);
@@ -1201,3 +1206,139 @@ async function executeReplaceSingleUnderLock(
1201
1206
  },
1202
1207
  };
1203
1208
  }
1209
+
1210
+ /**
1211
+ * Apply every replacement for one path in memory and write once. A generated
1212
+ * file (on disk or produced by an earlier entry) refuses the whole batch, so a
1213
+ * later refusal never leaves earlier entries published.
1214
+ */
1215
+ export async function executeReplaceEntries(
1216
+ options: Omit<ExecuteReplaceSingleOptions, "params"> & { edits: ReplaceEditEntry[] },
1217
+ ): Promise<AgentToolResult<EditToolDetails, typeof replaceEditSchema>> {
1218
+ if (options.edits.length <= 1) {
1219
+ const only = options.edits[0];
1220
+ if (!only) {
1221
+ throw new Error("edits must not be empty.");
1222
+ }
1223
+ return executeReplaceSingle({ ...options, params: only });
1224
+ }
1225
+
1226
+ const { session, path, edits } = options;
1227
+ try {
1228
+ enforcePlanModeWrite(session, path);
1229
+ for (const entry of edits) {
1230
+ if (entry.old_text.length === 0) {
1231
+ throw new Error("old_text must not be empty.");
1232
+ }
1233
+ }
1234
+ const absolutePath = resolvePlanPath(session, path);
1235
+ return await withEditPathMutation([absolutePath], () =>
1236
+ executeReplaceEntriesUnderLock({ ...options, absolutePath }),
1237
+ );
1238
+ } catch (err) {
1239
+ const errorText = err instanceof Error ? err.message : String(err);
1240
+ return {
1241
+ content: [{ type: "text", text: `Error editing ${path}: ${errorText}` }],
1242
+ details: { diff: "", path },
1243
+ isError: true,
1244
+ };
1245
+ }
1246
+ }
1247
+
1248
+ async function executeReplaceEntriesUnderLock(
1249
+ options: Omit<ExecuteReplaceSingleOptions, "params"> & {
1250
+ edits: ReplaceEditEntry[];
1251
+ absolutePath: string;
1252
+ },
1253
+ ): Promise<AgentToolResult<EditToolDetails, typeof replaceEditSchema>> {
1254
+ const {
1255
+ session,
1256
+ path,
1257
+ edits,
1258
+ signal,
1259
+ batchRequest,
1260
+ allowFuzzy,
1261
+ fuzzyThreshold,
1262
+ writethrough,
1263
+ beginDeferredDiagnosticsForPath,
1264
+ absolutePath,
1265
+ } = options;
1266
+
1267
+ const rawContent = await readEditFileText(absolutePath, path);
1268
+ assertEditableFileContent(rawContent, path, session.settings);
1269
+ await assertEditableFile(absolutePath, path, session.settings);
1270
+
1271
+ const { bom, text: content } = stripBom(rawContent);
1272
+ const originalEnding = detectLineEnding(content);
1273
+ let normalizedContent = normalizeToLF(content);
1274
+ const originalNormalized = normalizedContent;
1275
+ const texts: string[] = [];
1276
+
1277
+ for (const [index, entry] of edits.entries()) {
1278
+ const normalizedOldText = normalizeToLF(entry.old_text);
1279
+ const normalizedNewText = normalizeToLF(entry.new_text);
1280
+ const replaced = replaceText(normalizedContent, normalizedOldText, normalizedNewText, {
1281
+ fuzzy: allowFuzzy,
1282
+ all: entry.all ?? false,
1283
+ threshold: fuzzyThreshold,
1284
+ });
1285
+ if (replaced.count === 0) {
1286
+ const matchOutcome = findMatch(normalizedContent, normalizedOldText, {
1287
+ allowFuzzy,
1288
+ threshold: fuzzyThreshold,
1289
+ });
1290
+ if (matchOutcome.occurrences && matchOutcome.occurrences > 1) {
1291
+ throw new Error(formatOccurrenceError(path, matchOutcome));
1292
+ }
1293
+ throw new EditMatchError(path, normalizedOldText, matchOutcome.closest, {
1294
+ allowFuzzy,
1295
+ threshold: fuzzyThreshold,
1296
+ fuzzyMatches: matchOutcome.fuzzyMatches,
1297
+ });
1298
+ }
1299
+ if (normalizedContent === replaced.content) {
1300
+ throw new Error(`Edits to ${path} resulted in no changes being made.`);
1301
+ }
1302
+ normalizedContent = replaced.content;
1303
+ if (index < edits.length - 1) {
1304
+ assertEditableFileContent(normalizedContent, path, session.settings);
1305
+ }
1306
+ texts.push(
1307
+ replaced.count > 1
1308
+ ? `Successfully replaced ${replaced.count} occurrences in ${path}.`
1309
+ : `Successfully replaced text in ${path}.`,
1310
+ );
1311
+ }
1312
+
1313
+ const finalContent = await serializeEditFileText(
1314
+ absolutePath,
1315
+ path,
1316
+ bom + restoreLineEndings(normalizedContent, originalEnding),
1317
+ );
1318
+ const diagnostics = await writethrough(
1319
+ absolutePath,
1320
+ finalContent,
1321
+ signal,
1322
+ Bun.file(absolutePath),
1323
+ batchRequest,
1324
+ dst => (dst === absolutePath ? beginDeferredDiagnosticsForPath(absolutePath) : undefined),
1325
+ );
1326
+ invalidateFsScanAfterWrite(absolutePath);
1327
+
1328
+ const diffResult = generateDiffString(originalNormalized, normalizedContent);
1329
+ const meta = outputMeta()
1330
+ .diagnostics(diagnostics?.summary ?? "", diagnostics?.messages ?? [])
1331
+ .get();
1332
+ return {
1333
+ content: [{ type: "text", text: texts.join("\n") }],
1334
+ details: {
1335
+ diff: diffResult.diff,
1336
+ path: absolutePath,
1337
+ firstChangedLine: diffResult.firstChangedLine,
1338
+ diagnostics,
1339
+ meta,
1340
+ oldText: rawContent,
1341
+ newText: finalContent,
1342
+ },
1343
+ };
1344
+ }
@@ -523,15 +523,41 @@ async function spawnJsWorker(): Promise<WorkerHandle> {
523
523
  }
524
524
 
525
525
  function wrapBunWorker(worker: Worker): WorkerHandle {
526
+ // Cells share parentPort, so worker→host frames use a port transferred before
527
+ // the first cell. worker "message" events are accepted only until ready.
528
+ const channel = new MessageChannel();
529
+ const hostPort = channel.port2;
530
+ const queued: WorkerOutbound[] = [];
531
+ let onFrame: ((msg: WorkerOutbound) => void) | undefined;
532
+ let acceptWorkerEvent = true;
533
+ const deliver = (msg: WorkerOutbound): void => {
534
+ if (msg?.type === "ready" || msg?.type === "init-failed") acceptWorkerEvent = false;
535
+ if (onFrame) onFrame(msg);
536
+ else queued.push(msg);
537
+ };
538
+ const onPort = (event: Event): void => {
539
+ deliver((event as MessageEvent).data as WorkerOutbound);
540
+ };
541
+ const onWorker = (event: Event): void => {
542
+ if (!acceptWorkerEvent) return;
543
+ deliver((event as MessageEvent).data as WorkerOutbound);
544
+ };
545
+ hostPort.addEventListener("message", onPort);
546
+ worker.addEventListener("message", onWorker);
547
+ worker.postMessage({ type: "skc-bind", port: channel.port1 }, { transfer: [channel.port1] });
526
548
  return {
527
549
  mode: "worker",
528
550
  send(msg) {
529
551
  worker.postMessage(msg);
530
552
  },
531
553
  onMessage(handler) {
532
- const wrap = (event: MessageEvent): void => handler(event.data as WorkerOutbound);
533
- worker.addEventListener("message", wrap);
534
- return () => worker.removeEventListener("message", wrap);
554
+ onFrame = handler;
555
+ for (const msg of queued.splice(0)) handler(msg);
556
+ return () => {
557
+ if (onFrame === handler) onFrame = undefined;
558
+ hostPort.removeEventListener("message", onPort);
559
+ worker.removeEventListener("message", onWorker);
560
+ };
535
561
  },
536
562
  async terminate() {
537
563
  worker.terminate();
@@ -1,24 +1,57 @@
1
- import { parentPort } from "node:worker_threads";
1
+ import { type MessagePort, parentPort } from "node:worker_threads";
2
2
  import { WorkerCore } from "./worker-core";
3
3
  import type { Transport, WorkerInbound, WorkerOutbound } from "./worker-protocol";
4
4
 
5
5
  if (!parentPort) throw new Error("js worker-entry: missing parentPort");
6
6
 
7
- const port = parentPort;
8
- const transport: Transport = {
9
- send: (msg: WorkerOutbound) => port.postMessage(msg),
10
- onMessage: handler => {
11
- const wrap = (data: unknown): void => handler(data as WorkerInbound);
12
- port.on("message", wrap);
13
- return () => port.off("message", wrap);
14
- },
15
- close: () => {
16
- try {
17
- port.close();
18
- } catch {
19
- // Already closed.
20
- }
21
- },
22
- };
7
+ const parent = parentPort;
8
+
9
+ function isHostPort(value: unknown): value is MessagePort {
10
+ if (!value || typeof value !== "object") return false;
11
+ const port = value as MessagePort;
12
+ return typeof port.postMessage === "function" && typeof port.on === "function";
13
+ }
14
+
15
+ function readBindPort(data: unknown): MessagePort | undefined {
16
+ if (!data || typeof data !== "object") return undefined;
17
+ const record = data as { type?: unknown; port?: unknown };
18
+ if (record.type !== "skc-bind" || !isHostPort(record.port)) return undefined;
19
+ return record.port;
20
+ }
23
21
 
24
- new WorkerCore(transport);
22
+ function listen(port: MessagePort): void {
23
+ // Bound before any user cell. A later prototype patch cannot retarget this send.
24
+ const post = port.postMessage.bind(port);
25
+ const transport: Transport = {
26
+ send: (msg: WorkerOutbound) => {
27
+ post(msg);
28
+ },
29
+ onMessage: handler => {
30
+ const wrap = (data: unknown): void => handler(data as WorkerInbound);
31
+ parent.on("message", wrap);
32
+ return () => parent.off("message", wrap);
33
+ },
34
+ close: () => {
35
+ try {
36
+ port.close();
37
+ } catch {
38
+ // Already closed.
39
+ }
40
+ try {
41
+ parent.close();
42
+ } catch {
43
+ // Already closed.
44
+ }
45
+ },
46
+ };
47
+ new WorkerCore(transport);
48
+ }
49
+
50
+ const onParent = (data: unknown): void => {
51
+ const port = readBindPort(data);
52
+ if (!port) return;
53
+ if (data && typeof data === "object") (data as { port?: unknown }).port = undefined;
54
+ parent.off("message", onParent);
55
+ listen(port);
56
+ };
57
+ parent.on("message", onParent);
@@ -29,6 +29,7 @@ import asyncio
29
29
  import ast
30
30
  import base64
31
31
  import builtins
32
+ import codecs
32
33
  import inspect
33
34
  import io
34
35
  import json
@@ -49,9 +50,14 @@ from typing import Any, Callable
49
50
  # Frame writer
50
51
  # ---------------------------------------------------------------------------
51
52
 
52
- _RAW_STDOUT = sys.__stdout__
53
53
  _RAW_STDERR = sys.__stderr__
54
54
  _OUT_LOCK = threading.Lock()
55
+ _PROTO_FD: int | None = None
56
+ _CAP_LOCK = threading.Lock()
57
+ _FLUSH_EVENT = threading.Event()
58
+ _FLUSH_TOKEN: bytes | None = None
59
+ _CAPTURED = b""
60
+ _CAPTURE_DECODER = codecs.getincrementaldecoder("utf-8")(errors="replace")
55
61
 
56
62
 
57
63
  def _json_default(o: Any) -> Any:
@@ -61,13 +67,141 @@ def _json_default(o: Any) -> Any:
61
67
  return f"<unrepr {type(o).__name__}>"
62
68
 
63
69
 
70
+ def _write_all(fd: int, data: bytes) -> None:
71
+ view = memoryview(data)
72
+ while len(view):
73
+ written = os.write(fd, view)
74
+ if written <= 0:
75
+ raise OSError(0, "protocol write returned no bytes")
76
+ view = view[written:]
77
+
78
+
64
79
  def _emit(frame: dict) -> None:
65
80
  """Serialize a frame and write it to the host as a single NDJSON line."""
66
- line = json.dumps(frame, ensure_ascii=False, default=_json_default)
81
+ payload = (json.dumps(frame, ensure_ascii=False, default=_json_default) + "\n").encode("utf-8")
82
+ fd = _PROTO_FD if _PROTO_FD is not None else 1
67
83
  with _OUT_LOCK:
68
- _RAW_STDOUT.write(line)
69
- _RAW_STDOUT.write("\n")
70
- _RAW_STDOUT.flush()
84
+ _write_all(fd, payload)
85
+
86
+
87
+ def _token_suffix_len(buf: bytes, token: bytes) -> int:
88
+ max_n = min(len(buf), len(token) - 1)
89
+ for size in range(max_n, 0, -1):
90
+ if buf.endswith(token[:size]):
91
+ return size
92
+ return 0
93
+
94
+
95
+ def _take_captured_locked() -> tuple[list[bytes], bool]:
96
+ """Split captured fd-1 bytes. A flush token is a delimiter, not output."""
97
+ global _CAPTURED, _FLUSH_TOKEN
98
+ pieces: list[bytes] = []
99
+ flushed = False
100
+ while True:
101
+ token = _FLUSH_TOKEN
102
+ if token is None:
103
+ if _CAPTURED:
104
+ pieces.append(_CAPTURED)
105
+ _CAPTURED = b""
106
+ return pieces, flushed
107
+ idx = _CAPTURED.find(token)
108
+ if idx < 0:
109
+ keep = _token_suffix_len(_CAPTURED, token)
110
+ if len(_CAPTURED) > keep:
111
+ pieces.append(_CAPTURED[: len(_CAPTURED) - keep])
112
+ _CAPTURED = _CAPTURED[-keep:] if keep else b""
113
+ return pieces, flushed
114
+ if idx:
115
+ pieces.append(_CAPTURED[:idx])
116
+ _CAPTURED = _CAPTURED[idx + len(token) :]
117
+ _FLUSH_TOKEN = None
118
+ flushed = True
119
+
120
+
121
+ def _publish_captured(pieces: list[bytes], flushed: bool) -> None:
122
+ global _CAPTURE_DECODER
123
+ for piece in pieces:
124
+ text = _CAPTURE_DECODER.decode(piece)
125
+ if text:
126
+ _forward_captured_stdout(text)
127
+ if not flushed:
128
+ return
129
+ tail = _CAPTURE_DECODER.decode(b"", final=True)
130
+ if tail:
131
+ _forward_captured_stdout(tail)
132
+ _CAPTURE_DECODER = codecs.getincrementaldecoder("utf-8")(errors="replace")
133
+
134
+
135
+ def _forward_captured_stdout(text: str) -> None:
136
+ rid = _STATE.current_id
137
+ if not text:
138
+ return
139
+ if rid is None:
140
+ _RAW_STDERR.write(text)
141
+ _RAW_STDERR.flush()
142
+ return
143
+ _emit({"type": "stdout", "id": rid, "data": text})
144
+
145
+
146
+ def _pump_captured_stdout(read_fd: int) -> None:
147
+ global _CAPTURED
148
+ while True:
149
+ try:
150
+ chunk = os.read(read_fd, 65536)
151
+ except OSError:
152
+ return
153
+ if not chunk:
154
+ return
155
+ with _CAP_LOCK:
156
+ _CAPTURED += chunk
157
+ pieces, flushed = _take_captured_locked()
158
+ _publish_captured(pieces, flushed)
159
+ if flushed:
160
+ _FLUSH_EVENT.set()
161
+
162
+
163
+ def _capture_user_stdout() -> None:
164
+ """Move the host pipe off fd 1 so raw user writes are cell output."""
165
+ global _PROTO_FD
166
+ if _PROTO_FD is not None:
167
+ return
168
+ try:
169
+ sys.__stdout__.flush()
170
+ except Exception:
171
+ pass
172
+ proto = os.dup(1)
173
+ os.set_inheritable(proto, False)
174
+ _PROTO_FD = proto
175
+ read_fd, write_fd = os.pipe()
176
+ os.set_inheritable(read_fd, False)
177
+ os.dup2(write_fd, 1, inheritable=True)
178
+ os.close(write_fd)
179
+ threading.Thread(
180
+ target=_pump_captured_stdout,
181
+ args=(read_fd,),
182
+ name="skc-stdout-capture",
183
+ daemon=True,
184
+ ).start()
185
+
186
+
187
+ def _flush_captured_stdout() -> None:
188
+ if _PROTO_FD is None:
189
+ return
190
+ token = b"\0skcfd1:" + os.urandom(8).hex().encode("ascii") + b"\0"
191
+ with _CAP_LOCK:
192
+ global _FLUSH_TOKEN
193
+ _FLUSH_EVENT.clear()
194
+ _FLUSH_TOKEN = token
195
+ _write_all(1, token)
196
+ if _FLUSH_EVENT.wait(5):
197
+ return
198
+ with _CAP_LOCK:
199
+ if _FLUSH_TOKEN == token:
200
+ _FLUSH_TOKEN = None
201
+ pieces, flushed = _take_captured_locked()
202
+ else:
203
+ pieces, flushed = [], False
204
+ _publish_captured(pieces, flushed)
71
205
 
72
206
 
73
207
  # ---------------------------------------------------------------------------
@@ -902,6 +1036,10 @@ def _handle_request(req: dict) -> None:
902
1036
  _flush_matplotlib_figures()
903
1037
  except Exception:
904
1038
  pass
1039
+ try:
1040
+ _flush_captured_stdout()
1041
+ except Exception:
1042
+ pass
905
1043
 
906
1044
  _emit({
907
1045
  "type": "done",
@@ -930,6 +1068,7 @@ def _emit_error(rid: str, exc: BaseException) -> None:
930
1068
 
931
1069
 
932
1070
  def main() -> None:
1071
+ _capture_user_stdout()
933
1072
  sys.stdout = _StreamProxy("stdout")
934
1073
  sys.stderr = _StreamProxy("stderr")
935
1074
  _install_idle_sigint()
@@ -7,7 +7,8 @@
7
7
  */
8
8
  import * as fs from "node:fs";
9
9
  import * as path from "node:path";
10
- import { $env, $which, getPythonEnvDir } from "@sayknow-cli/utils";
10
+ import { $env, $which, getPythonEnvDir, relativePathEscapesRoot } from "@sayknow-cli/utils";
11
+ import { isProjectControlledPath } from "../../lsp/path-trust";
11
12
 
12
13
  export const RLM_MANAGED_PYTHON_PACKAGES: readonly string[] = ["numpy", "pandas", "matplotlib", "polars"];
13
14
 
@@ -124,6 +125,47 @@ function resolvePythonCandidateInVenv(venvPath: string): { venvPath: string; pyt
124
125
  return { venvPath, pythonPath, binDir };
125
126
  }
126
127
 
128
+ /**
129
+ * A workspace `.venv` or `venv` directory is repository content. Use it only when
130
+ * it is a real virtualenv (`pyvenv.cfg`) whose interpreter file resolves outside
131
+ * the project. An in-tree script or binary is not an interpreter.
132
+ *
133
+ * True when `candidate` is `root` or a descendant after `path.resolve`.
134
+ * A name such as `..payload` stays inside. Only `..` and a parent segment escape.
135
+ */
136
+ export function workspacePathContained(root: string, candidate: string): boolean {
137
+ const normalize = (value: string): string => {
138
+ const resolved = path.resolve(value);
139
+ return process.platform === "win32" ? resolved.toLowerCase() : resolved;
140
+ };
141
+ return !relativePathEscapesRoot(path.relative(normalize(root), normalize(candidate)));
142
+ }
143
+
144
+ function isAutoDetectedWorkspaceVenv(candidate: string, cwd: string): boolean {
145
+ try {
146
+ if (!fs.statSync(path.join(candidate, "pyvenv.cfg")).isFile()) return false;
147
+ } catch {
148
+ return false;
149
+ }
150
+ let canonicalPython: string;
151
+ try {
152
+ canonicalPython = fs.realpathSync(resolvePythonCandidateInVenv(candidate).pythonPath);
153
+ } catch {
154
+ return false;
155
+ }
156
+ // HOME stops project-root discovery, so a workspace that is the home directory
157
+ // is not project-controlled. Refuse an interpreter that still resolves inside
158
+ // cwd, including a file whose name is `..payload`.
159
+ let canonicalCwd = path.resolve(cwd);
160
+ try {
161
+ canonicalCwd = fs.realpathSync(cwd);
162
+ } catch {
163
+ // Missing cwd keeps the resolved path.
164
+ }
165
+ if (workspacePathContained(canonicalCwd, canonicalPython)) return false;
166
+ return !isProjectControlledPath(canonicalPython, cwd);
167
+ }
168
+
127
169
  function resolveManagedPythonCandidate(): { venvPath: string; pythonPath: string; binDir: string } {
128
170
  return resolvePythonCandidateInVenv(resolveGlobalManagedPythonEnv());
129
171
  }
@@ -188,9 +230,7 @@ export function resolveVenvPath(cwd: string): string | undefined {
188
230
  if ($env.CONDA_PREFIX) return $env.CONDA_PREFIX;
189
231
  const candidates = [path.join(cwd, ".venv"), path.join(cwd, "venv")];
190
232
  for (const candidate of candidates) {
191
- if (fs.existsSync(candidate)) {
192
- return candidate;
193
- }
233
+ if (isAutoDetectedWorkspaceVenv(candidate, cwd)) return candidate;
194
234
  }
195
235
  return undefined;
196
236
  }
@@ -72,6 +72,10 @@ async function startServer(): Promise<BridgeServer> {
72
72
  if (!sessionId || !name) {
73
73
  return Response.json({ ok: false, error: "Missing session/name" }, { status: 400 });
74
74
  }
75
+ const live = registrations.get(capability);
76
+ if (live !== registration || registration.signal?.aborted) {
77
+ return new Response("Forbidden", { status: 403 });
78
+ }
75
79
  if (sessionId !== registration.sessionId) {
76
80
  return new Response("Forbidden", { status: 403 });
77
81
  }
@@ -1,5 +1,5 @@
1
1
  import type { TSchema } from "@sayknow-cli/ai";
2
- import { $env, logger } from "@sayknow-cli/utils";
2
+ import { $credentialEnv, logger } from "@sayknow-cli/utils";
3
3
  import type { CustomTool, CustomToolResult } from "../extensibility/custom-tools/types";
4
4
  import { callMCP } from "../runtime-mcp/json-rpc";
5
5
  import type {
@@ -11,9 +11,18 @@ import type {
11
11
  MCPToolWrapperConfig,
12
12
  } from "./types";
13
13
 
14
- /** Find EXA_API_KEY from Bun.env or .env files */
14
+ /**
15
+ * Find `EXA_API_KEY` from trusted environment sources.
16
+ *
17
+ * The key authenticates every Exa MCP call and travels in the request URL, so
18
+ * whatever can set it decides which account the agent's searches run through —
19
+ * and therefore who can see those queries. `$env` merges the caller's `cwd/.env`
20
+ * into `process.env`, so reading it there would let repository content supply
21
+ * that account. Resolve it the same way provider credentials are: launching
22
+ * shell plus SKC/user-owned `.env` files, never the project `.env`.
23
+ */
15
24
  export function findApiKey(): string | null {
16
- return $env.EXA_API_KEY;
25
+ return $credentialEnv("EXA_API_KEY") ?? null;
17
26
  }
18
27
 
19
28
  function asRecord(value: unknown): Record<string, unknown> | null {
@@ -178,7 +187,16 @@ export function formatSearchResults(data: ExaSearchResponse): string {
178
187
  * Format a non-search MCP response as human-readable text.
179
188
  * Handles objects, arrays, primitives, and common MCP response shapes.
180
189
  */
181
- export function formatGenericResponse(data: unknown): string {
190
+ // Nesting depth is bounded. Each object level re-indents the entire formatted
191
+ // subtree, so cost grows super-linearly with depth: 500/1000/2000/4000/8000
192
+ // levels cost 60ms/227ms/730ms/5.9s/94s. A tool-call payload is whatever the
193
+ // remote MCP server returned, and `MCP_MAX_CONTENT_BYTES` does not bound depth
194
+ // — 8000 levels of `{"a":` is under 47 KB. The limit matches the one the
195
+ // session-import walker already applies (`sanitizeImportedValue`, depth > 64).
196
+ const MAX_GENERIC_RESPONSE_DEPTH = 64;
197
+
198
+ export function formatGenericResponse(data: unknown, depth = 0): string {
199
+ if (depth > MAX_GENERIC_RESPONSE_DEPTH) return "[depth-limit]";
182
200
  if (data === null || data === undefined) return "No result.";
183
201
  if (typeof data === "string") return data;
184
202
  if (typeof data === "number" || typeof data === "boolean") return String(data);
@@ -190,14 +208,22 @@ export function formatGenericResponse(data: unknown): string {
190
208
  const item = data[i];
191
209
  if (typeof item === "object" && item !== null) {
192
210
  const record = item as Record<string, unknown>;
193
- const title = (record.title ?? record.name ?? record.id ?? `Item ${i + 1}`) as string;
211
+ const rawTitle = record.title ?? record.name ?? record.id;
212
+ // A remote title is unvalidated JSON: stringify non-strings through the
213
+ // depth-bounded path instead of template coercion, which recurses unbounded.
214
+ const title =
215
+ rawTitle === undefined || rawTitle === null
216
+ ? `Item ${i + 1}`
217
+ : typeof rawTitle === "string"
218
+ ? rawTitle
219
+ : formatValue(rawTitle, depth + 2);
194
220
  parts.push(`\n### ${title}`);
195
221
  for (const [k, v] of Object.entries(record)) {
196
222
  if (["title", "name", "id"].includes(k)) continue;
197
- parts.push(`- **${k}:** ${formatValue(v)}`);
223
+ parts.push(`- **${k}:** ${formatValue(v, depth + 2)}`);
198
224
  }
199
225
  } else {
200
- parts.push(`- ${formatValue(item)}`);
226
+ parts.push(`- ${formatValue(item, depth + 1)}`);
201
227
  }
202
228
  }
203
229
  return parts.join("\n");
@@ -222,10 +248,10 @@ export function formatGenericResponse(data: unknown): string {
222
248
  if (k === "content") continue; // handled above
223
249
  if (v === null || v === undefined) continue;
224
250
  if (typeof v === "object") {
225
- const formatted = formatGenericResponse(v);
251
+ const formatted = formatGenericResponse(v, depth + 1);
226
252
  if (formatted) lines.push(`- **${k}:**\n${indent(formatted, 2)}`);
227
253
  } else {
228
- lines.push(`- **${k}:** ${formatValue(v)}`);
254
+ lines.push(`- **${k}:** ${formatValue(v, depth + 1)}`);
229
255
  }
230
256
  }
231
257
  return lines.join("\n") || "(empty)";
@@ -234,12 +260,28 @@ export function formatGenericResponse(data: unknown): string {
234
260
  return String(data);
235
261
  }
236
262
 
237
- function formatValue(v: unknown): string {
263
+ function formatValue(v: unknown, depth: number): string {
238
264
  if (v === null || v === undefined) return "—";
239
- if (typeof v === "object") return JSON.stringify(v);
265
+ if (typeof v === "object") return JSON.stringify(truncateDepth(v, depth));
240
266
  return String(v);
241
267
  }
242
268
 
269
+ /**
270
+ * Copies a value, replacing anything nested past MAX_GENERIC_RESPONSE_DEPTH with
271
+ * "[depth-limit]", so JSON.stringify never recurses through a remote payload's
272
+ * unbounded structure.
273
+ */
274
+ function truncateDepth(value: unknown, depth: number): unknown {
275
+ if (value === null || typeof value !== "object") return value;
276
+ if (depth > MAX_GENERIC_RESPONSE_DEPTH) return "[depth-limit]";
277
+ if (Array.isArray(value)) return value.map(item => truncateDepth(item, depth + 1));
278
+ // Null prototype: an own "__proto__" key from a parsed payload must stay an
279
+ // own data property instead of hitting the Object.prototype setter.
280
+ const copy: Record<string, unknown> = Object.create(null);
281
+ for (const [key, child] of Object.entries(value)) copy[key] = truncateDepth(child, depth + 1);
282
+ return copy;
283
+ }
284
+
243
285
  function indent(text: string, spaces: number): string {
244
286
  const pad = " ".repeat(spaces);
245
287
  return text