apex-code 0.0.1-alpha.8 → 0.0.4

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 (634) hide show
  1. package/CHANGELOG.md +231 -0
  2. package/README.md +9 -8
  3. package/dist/cli/args.d.ts +26 -1
  4. package/dist/cli/args.d.ts.map +1 -1
  5. package/dist/cli/args.js +72 -10
  6. package/dist/cli/args.js.map +1 -1
  7. package/dist/cli/file-processor.d.ts.map +1 -1
  8. package/dist/cli/file-processor.js +2 -1
  9. package/dist/cli/file-processor.js.map +1 -1
  10. package/dist/cli/mcp-command.d.ts +9 -0
  11. package/dist/cli/mcp-command.d.ts.map +1 -0
  12. package/dist/cli/mcp-command.js +53 -0
  13. package/dist/cli/mcp-command.js.map +1 -0
  14. package/dist/cli/project-trust.d.ts.map +1 -1
  15. package/dist/cli/project-trust.js +3 -1
  16. package/dist/cli/project-trust.js.map +1 -1
  17. package/dist/cli/startup-ui.d.ts.map +1 -1
  18. package/dist/cli/startup-ui.js +2 -1
  19. package/dist/cli/startup-ui.js.map +1 -1
  20. package/dist/cli.d.ts.map +1 -1
  21. package/dist/cli.js +94 -5
  22. package/dist/cli.js.map +1 -1
  23. package/dist/config.d.ts +3 -2
  24. package/dist/config.d.ts.map +1 -1
  25. package/dist/config.js +45 -18
  26. package/dist/config.js.map +1 -1
  27. package/dist/core/agent-session-services.d.ts +3 -0
  28. package/dist/core/agent-session-services.d.ts.map +1 -1
  29. package/dist/core/agent-session-services.js +1 -0
  30. package/dist/core/agent-session-services.js.map +1 -1
  31. package/dist/core/agent-session.d.ts +183 -15
  32. package/dist/core/agent-session.d.ts.map +1 -1
  33. package/dist/core/agent-session.js +728 -117
  34. package/dist/core/agent-session.js.map +1 -1
  35. package/dist/core/auth-storage.d.ts.map +1 -1
  36. package/dist/core/auth-storage.js +6 -7
  37. package/dist/core/auth-storage.js.map +1 -1
  38. package/dist/core/bash-executor.d.ts.map +1 -1
  39. package/dist/core/bash-executor.js +7 -0
  40. package/dist/core/bash-executor.js.map +1 -1
  41. package/dist/core/checkpoints/git-checkpoints.d.ts +39 -0
  42. package/dist/core/checkpoints/git-checkpoints.d.ts.map +1 -0
  43. package/dist/core/checkpoints/git-checkpoints.js +251 -0
  44. package/dist/core/checkpoints/git-checkpoints.js.map +1 -0
  45. package/dist/core/checkpoints/session-checkpoints.d.ts +23 -0
  46. package/dist/core/checkpoints/session-checkpoints.d.ts.map +1 -0
  47. package/dist/core/checkpoints/session-checkpoints.js +36 -0
  48. package/dist/core/checkpoints/session-checkpoints.js.map +1 -0
  49. package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
  50. package/dist/core/compaction/branch-summarization.js +7 -3
  51. package/dist/core/compaction/branch-summarization.js.map +1 -1
  52. package/dist/core/compaction/compaction.d.ts +9 -3
  53. package/dist/core/compaction/compaction.d.ts.map +1 -1
  54. package/dist/core/compaction/compaction.js +59 -36
  55. package/dist/core/compaction/compaction.js.map +1 -1
  56. package/dist/core/defaults.d.ts +1 -0
  57. package/dist/core/defaults.d.ts.map +1 -1
  58. package/dist/core/defaults.js +9 -0
  59. package/dist/core/defaults.js.map +1 -1
  60. package/dist/core/delegation/runtime.d.ts +6 -5
  61. package/dist/core/delegation/runtime.d.ts.map +1 -1
  62. package/dist/core/delegation/runtime.js +4 -3
  63. package/dist/core/delegation/runtime.js.map +1 -1
  64. package/dist/core/durable-state/sqlite.d.ts.map +1 -1
  65. package/dist/core/durable-state/sqlite.js +26 -2
  66. package/dist/core/durable-state/sqlite.js.map +1 -1
  67. package/dist/core/exec.d.ts.map +1 -1
  68. package/dist/core/exec.js +5 -2
  69. package/dist/core/exec.js.map +1 -1
  70. package/dist/core/extensions/index.d.ts +2 -2
  71. package/dist/core/extensions/index.d.ts.map +1 -1
  72. package/dist/core/extensions/index.js +1 -1
  73. package/dist/core/extensions/index.js.map +1 -1
  74. package/dist/core/extensions/loader.d.ts.map +1 -1
  75. package/dist/core/extensions/loader.js +123 -50
  76. package/dist/core/extensions/loader.js.map +1 -1
  77. package/dist/core/extensions/runner.d.ts +5 -0
  78. package/dist/core/extensions/runner.d.ts.map +1 -1
  79. package/dist/core/extensions/runner.js +45 -1
  80. package/dist/core/extensions/runner.js.map +1 -1
  81. package/dist/core/extensions/source-runtime.d.ts +14 -0
  82. package/dist/core/extensions/source-runtime.d.ts.map +1 -0
  83. package/dist/core/extensions/source-runtime.js +56 -0
  84. package/dist/core/extensions/source-runtime.js.map +1 -0
  85. package/dist/core/extensions/types.d.ts +60 -11
  86. package/dist/core/extensions/types.d.ts.map +1 -1
  87. package/dist/core/extensions/types.js +3 -0
  88. package/dist/core/extensions/types.js.map +1 -1
  89. package/dist/core/footer-data-provider.d.ts +1 -1
  90. package/dist/core/footer-data-provider.d.ts.map +1 -1
  91. package/dist/core/footer-data-provider.js +1 -1
  92. package/dist/core/footer-data-provider.js.map +1 -1
  93. package/dist/core/formatter-lifecycle.d.ts +69 -0
  94. package/dist/core/formatter-lifecycle.d.ts.map +1 -0
  95. package/dist/core/formatter-lifecycle.js +360 -0
  96. package/dist/core/formatter-lifecycle.js.map +1 -0
  97. package/dist/core/hooks/command-handler.d.ts +19 -0
  98. package/dist/core/hooks/command-handler.d.ts.map +1 -0
  99. package/dist/core/hooks/command-handler.js +112 -0
  100. package/dist/core/hooks/command-handler.js.map +1 -0
  101. package/dist/core/hooks/http-handler.d.ts +10 -0
  102. package/dist/core/hooks/http-handler.d.ts.map +1 -0
  103. package/dist/core/hooks/http-handler.js +36 -0
  104. package/dist/core/hooks/http-handler.js.map +1 -0
  105. package/dist/core/hooks/loader.d.ts +29 -0
  106. package/dist/core/hooks/loader.d.ts.map +1 -0
  107. package/dist/core/hooks/loader.js +139 -0
  108. package/dist/core/hooks/loader.js.map +1 -0
  109. package/dist/core/hooks/runtime.d.ts +13 -0
  110. package/dist/core/hooks/runtime.d.ts.map +1 -0
  111. package/dist/core/hooks/runtime.js +63 -0
  112. package/dist/core/hooks/runtime.js.map +1 -0
  113. package/dist/core/hooks/types.d.ts +83 -0
  114. package/dist/core/hooks/types.d.ts.map +1 -0
  115. package/dist/core/hooks/types.js +24 -0
  116. package/dist/core/hooks/types.js.map +1 -0
  117. package/dist/core/keybindings.d.ts +20 -19
  118. package/dist/core/keybindings.d.ts.map +1 -1
  119. package/dist/core/keybindings.js +26 -5
  120. package/dist/core/keybindings.js.map +1 -1
  121. package/dist/core/mcp/config.d.ts +16 -0
  122. package/dist/core/mcp/config.d.ts.map +1 -0
  123. package/dist/core/mcp/config.js +166 -0
  124. package/dist/core/mcp/config.js.map +1 -0
  125. package/dist/core/mcp/connector.d.ts +35 -0
  126. package/dist/core/mcp/connector.d.ts.map +1 -0
  127. package/dist/core/mcp/connector.js +105 -0
  128. package/dist/core/mcp/connector.js.map +1 -0
  129. package/dist/core/mcp/contract.d.ts +19 -0
  130. package/dist/core/mcp/contract.d.ts.map +1 -0
  131. package/dist/core/mcp/contract.js +89 -0
  132. package/dist/core/mcp/contract.js.map +1 -0
  133. package/dist/core/mcp/mcp-tool.d.ts +32 -0
  134. package/dist/core/mcp/mcp-tool.d.ts.map +1 -0
  135. package/dist/core/mcp/mcp-tool.js +171 -0
  136. package/dist/core/mcp/mcp-tool.js.map +1 -0
  137. package/dist/core/mcp/metadata-cache.d.ts +29 -0
  138. package/dist/core/mcp/metadata-cache.d.ts.map +1 -0
  139. package/dist/core/mcp/metadata-cache.js +99 -0
  140. package/dist/core/mcp/metadata-cache.js.map +1 -0
  141. package/dist/core/mcp/oauth/authorize.d.ts +21 -0
  142. package/dist/core/mcp/oauth/authorize.d.ts.map +1 -0
  143. package/dist/core/mcp/oauth/authorize.js +32 -0
  144. package/dist/core/mcp/oauth/authorize.js.map +1 -0
  145. package/dist/core/mcp/oauth/discover.d.ts +27 -0
  146. package/dist/core/mcp/oauth/discover.d.ts.map +1 -0
  147. package/dist/core/mcp/oauth/discover.js +116 -0
  148. package/dist/core/mcp/oauth/discover.js.map +1 -0
  149. package/dist/core/mcp/oauth/flow.d.ts +31 -0
  150. package/dist/core/mcp/oauth/flow.d.ts.map +1 -0
  151. package/dist/core/mcp/oauth/flow.js +175 -0
  152. package/dist/core/mcp/oauth/flow.js.map +1 -0
  153. package/dist/core/mcp/oauth/mcp-token.d.ts +51 -0
  154. package/dist/core/mcp/oauth/mcp-token.d.ts.map +1 -0
  155. package/dist/core/mcp/oauth/mcp-token.js +129 -0
  156. package/dist/core/mcp/oauth/mcp-token.js.map +1 -0
  157. package/dist/core/mcp/oauth/pkce.d.ts +12 -0
  158. package/dist/core/mcp/oauth/pkce.d.ts.map +1 -0
  159. package/dist/core/mcp/oauth/pkce.js +11 -0
  160. package/dist/core/mcp/oauth/pkce.js.map +1 -0
  161. package/dist/core/mcp/oauth/register.d.ts +16 -0
  162. package/dist/core/mcp/oauth/register.d.ts.map +1 -0
  163. package/dist/core/mcp/oauth/register.js +42 -0
  164. package/dist/core/mcp/oauth/register.js.map +1 -0
  165. package/dist/core/mcp/oauth/token-client.d.ts +33 -0
  166. package/dist/core/mcp/oauth/token-client.d.ts.map +1 -0
  167. package/dist/core/mcp/oauth/token-client.js +65 -0
  168. package/dist/core/mcp/oauth/token-client.js.map +1 -0
  169. package/dist/core/mcp/runtime.d.ts +20 -0
  170. package/dist/core/mcp/runtime.d.ts.map +1 -0
  171. package/dist/core/mcp/runtime.js +37 -0
  172. package/dist/core/mcp/runtime.js.map +1 -0
  173. package/dist/core/mcp/schema.d.ts +22 -0
  174. package/dist/core/mcp/schema.d.ts.map +1 -0
  175. package/dist/core/mcp/schema.js +20 -0
  176. package/dist/core/mcp/schema.js.map +1 -0
  177. package/dist/core/mcp/server-manager.d.ts +43 -0
  178. package/dist/core/mcp/server-manager.d.ts.map +1 -0
  179. package/dist/core/mcp/server-manager.js +142 -0
  180. package/dist/core/mcp/server-manager.js.map +1 -0
  181. package/dist/core/mcp/types.d.ts +100 -0
  182. package/dist/core/mcp/types.d.ts.map +1 -0
  183. package/dist/core/mcp/types.js +8 -0
  184. package/dist/core/mcp/types.js.map +1 -0
  185. package/dist/core/model-config.d.ts +5 -0
  186. package/dist/core/model-config.d.ts.map +1 -1
  187. package/dist/core/model-config.js +3 -1
  188. package/dist/core/model-config.js.map +1 -1
  189. package/dist/core/model-resolver.d.ts +1 -0
  190. package/dist/core/model-resolver.d.ts.map +1 -1
  191. package/dist/core/model-resolver.js +14 -8
  192. package/dist/core/model-resolver.js.map +1 -1
  193. package/dist/core/models-store.d.ts.map +1 -1
  194. package/dist/core/models-store.js +2 -1
  195. package/dist/core/models-store.js.map +1 -1
  196. package/dist/core/package-manager.d.ts.map +1 -1
  197. package/dist/core/package-manager.js +22 -14
  198. package/dist/core/package-manager.js.map +1 -1
  199. package/dist/core/permissions/gate.d.ts.map +1 -1
  200. package/dist/core/permissions/gate.js +45 -4
  201. package/dist/core/permissions/gate.js.map +1 -1
  202. package/dist/core/permissions/operations.d.ts +20 -0
  203. package/dist/core/permissions/operations.d.ts.map +1 -0
  204. package/dist/core/permissions/operations.js +9 -0
  205. package/dist/core/permissions/operations.js.map +1 -0
  206. package/dist/core/permissions/policy-command.d.ts +42 -0
  207. package/dist/core/permissions/policy-command.d.ts.map +1 -0
  208. package/dist/core/permissions/policy-command.js +44 -0
  209. package/dist/core/permissions/policy-command.js.map +1 -0
  210. package/dist/core/permissions/responder.d.ts +49 -2
  211. package/dist/core/permissions/responder.d.ts.map +1 -1
  212. package/dist/core/permissions/responder.js +20 -8
  213. package/dist/core/permissions/responder.js.map +1 -1
  214. package/dist/core/permissions/rules.d.ts.map +1 -1
  215. package/dist/core/permissions/rules.js +11 -1
  216. package/dist/core/permissions/rules.js.map +1 -1
  217. package/dist/core/permissions/store.d.ts +18 -0
  218. package/dist/core/permissions/store.d.ts.map +1 -1
  219. package/dist/core/permissions/store.js +89 -8
  220. package/dist/core/permissions/store.js.map +1 -1
  221. package/dist/core/pi-manifest.d.ts.map +1 -1
  222. package/dist/core/pi-manifest.js +2 -1
  223. package/dist/core/pi-manifest.js.map +1 -1
  224. package/dist/core/policy-executor.d.ts +47 -0
  225. package/dist/core/policy-executor.d.ts.map +1 -0
  226. package/dist/core/policy-executor.js +228 -0
  227. package/dist/core/policy-executor.js.map +1 -0
  228. package/dist/core/policy-loader.d.ts +72 -0
  229. package/dist/core/policy-loader.d.ts.map +1 -0
  230. package/dist/core/policy-loader.js +195 -0
  231. package/dist/core/policy-loader.js.map +1 -0
  232. package/dist/core/project-trust.d.ts +1 -1
  233. package/dist/core/project-trust.d.ts.map +1 -1
  234. package/dist/core/project-trust.js.map +1 -1
  235. package/dist/core/remote-catalog-provider.d.ts.map +1 -1
  236. package/dist/core/remote-catalog-provider.js +2 -1
  237. package/dist/core/remote-catalog-provider.js.map +1 -1
  238. package/dist/core/resource-loader.d.ts.map +1 -1
  239. package/dist/core/resource-loader.js +3 -2
  240. package/dist/core/resource-loader.js.map +1 -1
  241. package/dist/core/sandbox/bwrap-arguments.d.ts +41 -0
  242. package/dist/core/sandbox/bwrap-arguments.d.ts.map +1 -0
  243. package/dist/core/sandbox/bwrap-arguments.js +136 -0
  244. package/dist/core/sandbox/bwrap-arguments.js.map +1 -0
  245. package/dist/core/sandbox/child-entry.d.ts.map +1 -1
  246. package/dist/core/sandbox/child-entry.js +3 -1
  247. package/dist/core/sandbox/child-entry.js.map +1 -1
  248. package/dist/core/sandbox/cli-launch.d.ts +84 -4
  249. package/dist/core/sandbox/cli-launch.d.ts.map +1 -1
  250. package/dist/core/sandbox/cli-launch.js +115 -16
  251. package/dist/core/sandbox/cli-launch.js.map +1 -1
  252. package/dist/core/sandbox/cli-supervisor.d.ts +2 -0
  253. package/dist/core/sandbox/cli-supervisor.d.ts.map +1 -1
  254. package/dist/core/sandbox/cli-supervisor.js +50 -2
  255. package/dist/core/sandbox/cli-supervisor.js.map +1 -1
  256. package/dist/core/sandbox/full-access.d.ts +28 -0
  257. package/dist/core/sandbox/full-access.d.ts.map +1 -0
  258. package/dist/core/sandbox/full-access.js +63 -0
  259. package/dist/core/sandbox/full-access.js.map +1 -0
  260. package/dist/core/sandbox/git-identity.d.ts +57 -0
  261. package/dist/core/sandbox/git-identity.d.ts.map +1 -0
  262. package/dist/core/sandbox/git-identity.js +78 -0
  263. package/dist/core/sandbox/git-identity.js.map +1 -0
  264. package/dist/core/sandbox/host-approval.d.ts +42 -0
  265. package/dist/core/sandbox/host-approval.d.ts.map +1 -0
  266. package/dist/core/sandbox/host-approval.js +99 -0
  267. package/dist/core/sandbox/host-approval.js.map +1 -0
  268. package/dist/core/sandbox/linux-backend.d.ts +14 -0
  269. package/dist/core/sandbox/linux-backend.d.ts.map +1 -1
  270. package/dist/core/sandbox/linux-backend.js +158 -80
  271. package/dist/core/sandbox/linux-backend.js.map +1 -1
  272. package/dist/core/sandbox/macos-backend.d.ts +5 -0
  273. package/dist/core/sandbox/macos-backend.d.ts.map +1 -1
  274. package/dist/core/sandbox/macos-backend.js +164 -5
  275. package/dist/core/sandbox/macos-backend.js.map +1 -1
  276. package/dist/core/sandbox/network-proxy.d.ts +19 -0
  277. package/dist/core/sandbox/network-proxy.d.ts.map +1 -1
  278. package/dist/core/sandbox/network-proxy.js +93 -19
  279. package/dist/core/sandbox/network-proxy.js.map +1 -1
  280. package/dist/core/sandbox/policy.d.ts +8 -0
  281. package/dist/core/sandbox/policy.d.ts.map +1 -1
  282. package/dist/core/sandbox/policy.js +29 -12
  283. package/dist/core/sandbox/policy.js.map +1 -1
  284. package/dist/core/sandbox/profiles.d.ts +25 -0
  285. package/dist/core/sandbox/profiles.d.ts.map +1 -0
  286. package/dist/core/sandbox/profiles.js +23 -0
  287. package/dist/core/sandbox/profiles.js.map +1 -0
  288. package/dist/core/sandbox/rpc/command-client.d.ts +28 -0
  289. package/dist/core/sandbox/rpc/command-client.d.ts.map +1 -0
  290. package/dist/core/sandbox/rpc/command-client.js +86 -0
  291. package/dist/core/sandbox/rpc/command-client.js.map +1 -0
  292. package/dist/core/sandbox/rpc/command-proxy.d.ts +48 -0
  293. package/dist/core/sandbox/rpc/command-proxy.d.ts.map +1 -0
  294. package/dist/core/sandbox/rpc/command-proxy.js +120 -0
  295. package/dist/core/sandbox/rpc/command-proxy.js.map +1 -0
  296. package/dist/core/sandbox/rpc/credential-proxy.d.ts.map +1 -1
  297. package/dist/core/sandbox/rpc/credential-proxy.js +2 -96
  298. package/dist/core/sandbox/rpc/credential-proxy.js.map +1 -1
  299. package/dist/core/sandbox/rpc/framing.d.ts +35 -0
  300. package/dist/core/sandbox/rpc/framing.d.ts.map +1 -0
  301. package/dist/core/sandbox/rpc/framing.js +114 -0
  302. package/dist/core/sandbox/rpc/framing.js.map +1 -0
  303. package/dist/core/sandbox/rpc/git-credential-helper.d.ts +47 -0
  304. package/dist/core/sandbox/rpc/git-credential-helper.d.ts.map +1 -0
  305. package/dist/core/sandbox/rpc/git-credential-helper.js +222 -0
  306. package/dist/core/sandbox/rpc/git-credential-helper.js.map +1 -0
  307. package/dist/core/sandbox/rpc/git-credential-proxy.d.ts +66 -0
  308. package/dist/core/sandbox/rpc/git-credential-proxy.d.ts.map +1 -0
  309. package/dist/core/sandbox/rpc/git-credential-proxy.js +209 -0
  310. package/dist/core/sandbox/rpc/git-credential-proxy.js.map +1 -0
  311. package/dist/core/sandbox/supervisor-temp.d.ts +18 -0
  312. package/dist/core/sandbox/supervisor-temp.d.ts.map +1 -0
  313. package/dist/core/sandbox/supervisor-temp.js +21 -0
  314. package/dist/core/sandbox/supervisor-temp.js.map +1 -0
  315. package/dist/core/sandbox/supervisor.d.ts +12 -1
  316. package/dist/core/sandbox/supervisor.d.ts.map +1 -1
  317. package/dist/core/sandbox/supervisor.js +15 -1
  318. package/dist/core/sandbox/supervisor.js.map +1 -1
  319. package/dist/core/sandbox/terminal-handoff.d.ts +68 -0
  320. package/dist/core/sandbox/terminal-handoff.d.ts.map +1 -0
  321. package/dist/core/sandbox/terminal-handoff.js +221 -0
  322. package/dist/core/sandbox/terminal-handoff.js.map +1 -0
  323. package/dist/core/sandbox/terminal-size.d.ts +13 -0
  324. package/dist/core/sandbox/terminal-size.d.ts.map +1 -1
  325. package/dist/core/sandbox/terminal-size.js +23 -2
  326. package/dist/core/sandbox/terminal-size.js.map +1 -1
  327. package/dist/core/sdk.d.ts +24 -2
  328. package/dist/core/sdk.d.ts.map +1 -1
  329. package/dist/core/sdk.js +63 -4
  330. package/dist/core/sdk.js.map +1 -1
  331. package/dist/core/session-export.d.ts +4 -0
  332. package/dist/core/session-export.d.ts.map +1 -0
  333. package/dist/core/session-export.js +32 -0
  334. package/dist/core/session-export.js.map +1 -0
  335. package/dist/core/session-manager.d.ts +13 -1
  336. package/dist/core/session-manager.d.ts.map +1 -1
  337. package/dist/core/session-manager.js +34 -6
  338. package/dist/core/session-manager.js.map +1 -1
  339. package/dist/core/settings-diagnostics.d.ts +9 -0
  340. package/dist/core/settings-diagnostics.d.ts.map +1 -0
  341. package/dist/core/settings-diagnostics.js +21 -0
  342. package/dist/core/settings-diagnostics.js.map +1 -0
  343. package/dist/core/settings-manager.d.ts +172 -1
  344. package/dist/core/settings-manager.d.ts.map +1 -1
  345. package/dist/core/settings-manager.js +160 -11
  346. package/dist/core/settings-manager.js.map +1 -1
  347. package/dist/core/skills.d.ts.map +1 -1
  348. package/dist/core/skills.js +51 -33
  349. package/dist/core/skills.js.map +1 -1
  350. package/dist/core/slash-commands.d.ts.map +1 -1
  351. package/dist/core/slash-commands.js +4 -1
  352. package/dist/core/slash-commands.js.map +1 -1
  353. package/dist/core/system-prompt.d.ts.map +1 -1
  354. package/dist/core/system-prompt.js +8 -2
  355. package/dist/core/system-prompt.js.map +1 -1
  356. package/dist/core/tools/background-shell.d.ts +39 -0
  357. package/dist/core/tools/background-shell.d.ts.map +1 -0
  358. package/dist/core/tools/background-shell.js +81 -0
  359. package/dist/core/tools/background-shell.js.map +1 -0
  360. package/dist/core/tools/bash-command-segments.d.ts.map +1 -1
  361. package/dist/core/tools/bash-command-segments.js +2 -0
  362. package/dist/core/tools/bash-command-segments.js.map +1 -1
  363. package/dist/core/tools/bash.d.ts +44 -16
  364. package/dist/core/tools/bash.d.ts.map +1 -1
  365. package/dist/core/tools/bash.js +264 -32
  366. package/dist/core/tools/bash.js.map +1 -1
  367. package/dist/core/tools/contract-snapshot.d.ts +58 -0
  368. package/dist/core/tools/contract-snapshot.d.ts.map +1 -0
  369. package/dist/core/tools/contract-snapshot.js +51 -0
  370. package/dist/core/tools/contract-snapshot.js.map +1 -0
  371. package/dist/core/tools/contract.d.ts +53 -5
  372. package/dist/core/tools/contract.d.ts.map +1 -1
  373. package/dist/core/tools/contract.js +22 -2
  374. package/dist/core/tools/contract.js.map +1 -1
  375. package/dist/core/tools/delegate.d.ts +6 -4
  376. package/dist/core/tools/delegate.d.ts.map +1 -1
  377. package/dist/core/tools/delegate.js +21 -11
  378. package/dist/core/tools/delegate.js.map +1 -1
  379. package/dist/core/tools/edit-diff.d.ts +48 -5
  380. package/dist/core/tools/edit-diff.d.ts.map +1 -1
  381. package/dist/core/tools/edit-diff.js +217 -8
  382. package/dist/core/tools/edit-diff.js.map +1 -1
  383. package/dist/core/tools/edit.d.ts +8 -0
  384. package/dist/core/tools/edit.d.ts.map +1 -1
  385. package/dist/core/tools/edit.js +72 -10
  386. package/dist/core/tools/edit.js.map +1 -1
  387. package/dist/core/tools/find.d.ts.map +1 -1
  388. package/dist/core/tools/find.js +5 -2
  389. package/dist/core/tools/find.js.map +1 -1
  390. package/dist/core/tools/grep.d.ts.map +1 -1
  391. package/dist/core/tools/grep.js +5 -2
  392. package/dist/core/tools/grep.js.map +1 -1
  393. package/dist/core/tools/index.d.ts +14 -2
  394. package/dist/core/tools/index.d.ts.map +1 -1
  395. package/dist/core/tools/index.js +12 -0
  396. package/dist/core/tools/index.js.map +1 -1
  397. package/dist/core/tools/ls.d.ts.map +1 -1
  398. package/dist/core/tools/ls.js +5 -2
  399. package/dist/core/tools/ls.js.map +1 -1
  400. package/dist/core/tools/lsp.d.ts +19 -1
  401. package/dist/core/tools/lsp.d.ts.map +1 -1
  402. package/dist/core/tools/lsp.js +163 -10
  403. package/dist/core/tools/lsp.js.map +1 -1
  404. package/dist/core/tools/path-permission.d.ts +3 -0
  405. package/dist/core/tools/path-permission.d.ts.map +1 -1
  406. package/dist/core/tools/path-permission.js +16 -4
  407. package/dist/core/tools/path-permission.js.map +1 -1
  408. package/dist/core/tools/path-utils.d.ts +27 -2
  409. package/dist/core/tools/path-utils.d.ts.map +1 -1
  410. package/dist/core/tools/path-utils.js +221 -4
  411. package/dist/core/tools/path-utils.js.map +1 -1
  412. package/dist/core/tools/powershell.d.ts +16 -0
  413. package/dist/core/tools/powershell.d.ts.map +1 -0
  414. package/dist/core/tools/powershell.js +39 -0
  415. package/dist/core/tools/powershell.js.map +1 -0
  416. package/dist/core/tools/read.d.ts.map +1 -1
  417. package/dist/core/tools/read.js +20 -11
  418. package/dist/core/tools/read.js.map +1 -1
  419. package/dist/core/tools/test.d.ts +54 -9
  420. package/dist/core/tools/test.d.ts.map +1 -1
  421. package/dist/core/tools/test.js +239 -19
  422. package/dist/core/tools/test.js.map +1 -1
  423. package/dist/core/tools/write.d.ts +7 -0
  424. package/dist/core/tools/write.d.ts.map +1 -1
  425. package/dist/core/tools/write.js +64 -9
  426. package/dist/core/tools/write.js.map +1 -1
  427. package/dist/core/trust-manager.d.ts.map +1 -1
  428. package/dist/core/trust-manager.js +2 -1
  429. package/dist/core/trust-manager.js.map +1 -1
  430. package/dist/core/verification-lifecycle.d.ts +77 -0
  431. package/dist/core/verification-lifecycle.d.ts.map +1 -0
  432. package/dist/core/verification-lifecycle.js +146 -0
  433. package/dist/core/verification-lifecycle.js.map +1 -0
  434. package/dist/core/workspace/artifacts.d.ts +45 -0
  435. package/dist/core/workspace/artifacts.d.ts.map +1 -0
  436. package/dist/core/workspace/artifacts.js +165 -0
  437. package/dist/core/workspace/artifacts.js.map +1 -0
  438. package/dist/core/workspace/comparison.d.ts +27 -0
  439. package/dist/core/workspace/comparison.d.ts.map +1 -0
  440. package/dist/core/workspace/comparison.js +94 -0
  441. package/dist/core/workspace/comparison.js.map +1 -0
  442. package/dist/core/workspace/git-observer.d.ts +48 -0
  443. package/dist/core/workspace/git-observer.d.ts.map +1 -0
  444. package/dist/core/workspace/git-observer.js +346 -0
  445. package/dist/core/workspace/git-observer.js.map +1 -0
  446. package/dist/core/workspace/projection.d.ts +3 -0
  447. package/dist/core/workspace/projection.d.ts.map +1 -0
  448. package/dist/core/workspace/projection.js +56 -0
  449. package/dist/core/workspace/projection.js.map +1 -0
  450. package/dist/core/workspace/state.d.ts +133 -0
  451. package/dist/core/workspace/state.d.ts.map +1 -0
  452. package/dist/core/workspace/state.js +96 -0
  453. package/dist/core/workspace/state.js.map +1 -0
  454. package/dist/extensions/llama/client.d.ts +6 -0
  455. package/dist/extensions/llama/client.d.ts.map +1 -1
  456. package/dist/extensions/llama/client.js +7 -0
  457. package/dist/extensions/llama/client.js.map +1 -1
  458. package/dist/extensions/llama/index.d.ts.map +1 -1
  459. package/dist/extensions/llama/index.js +2 -0
  460. package/dist/extensions/llama/index.js.map +1 -1
  461. package/dist/extensions/llama/provider.d.ts +3 -1
  462. package/dist/extensions/llama/provider.d.ts.map +1 -1
  463. package/dist/extensions/llama/provider.js +29 -4
  464. package/dist/extensions/llama/provider.js.map +1 -1
  465. package/dist/index.d.ts +8 -5
  466. package/dist/index.d.ts.map +1 -1
  467. package/dist/index.js +7 -4
  468. package/dist/index.js.map +1 -1
  469. package/dist/main.d.ts +6 -0
  470. package/dist/main.d.ts.map +1 -1
  471. package/dist/main.js +58 -23
  472. package/dist/main.js.map +1 -1
  473. package/dist/migrations.d.ts.map +1 -1
  474. package/dist/migrations.js +4 -3
  475. package/dist/migrations.js.map +1 -1
  476. package/dist/modes/acp/server.d.ts +55 -0
  477. package/dist/modes/acp/server.d.ts.map +1 -0
  478. package/dist/modes/acp/server.js +244 -0
  479. package/dist/modes/acp/server.js.map +1 -0
  480. package/dist/modes/acp/translate.d.ts +37 -0
  481. package/dist/modes/acp/translate.d.ts.map +1 -0
  482. package/dist/modes/acp/translate.js +50 -0
  483. package/dist/modes/acp/translate.js.map +1 -0
  484. package/dist/modes/index.d.ts +1 -0
  485. package/dist/modes/index.d.ts.map +1 -1
  486. package/dist/modes/index.js +1 -0
  487. package/dist/modes/index.js.map +1 -1
  488. package/dist/modes/interactive/components/assistant-message.d.ts +29 -0
  489. package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
  490. package/dist/modes/interactive/components/assistant-message.js +182 -23
  491. package/dist/modes/interactive/components/assistant-message.js.map +1 -1
  492. package/dist/modes/interactive/components/bash-execution.d.ts +7 -0
  493. package/dist/modes/interactive/components/bash-execution.d.ts.map +1 -1
  494. package/dist/modes/interactive/components/bash-execution.js +20 -0
  495. package/dist/modes/interactive/components/bash-execution.js.map +1 -1
  496. package/dist/modes/interactive/components/custom-editor.d.ts +9 -4
  497. package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -1
  498. package/dist/modes/interactive/components/custom-editor.js +20 -9
  499. package/dist/modes/interactive/components/custom-editor.js.map +1 -1
  500. package/dist/modes/interactive/components/extension-selector.d.ts +7 -1
  501. package/dist/modes/interactive/components/extension-selector.d.ts.map +1 -1
  502. package/dist/modes/interactive/components/extension-selector.js +7 -3
  503. package/dist/modes/interactive/components/extension-selector.js.map +1 -1
  504. package/dist/modes/interactive/components/footer.d.ts +19 -0
  505. package/dist/modes/interactive/components/footer.d.ts.map +1 -1
  506. package/dist/modes/interactive/components/footer.js +70 -10
  507. package/dist/modes/interactive/components/footer.js.map +1 -1
  508. package/dist/modes/interactive/components/model-selector.d.ts +10 -3
  509. package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
  510. package/dist/modes/interactive/components/model-selector.js +56 -14
  511. package/dist/modes/interactive/components/model-selector.js.map +1 -1
  512. package/dist/modes/interactive/components/permission-preview.d.ts +15 -0
  513. package/dist/modes/interactive/components/permission-preview.d.ts.map +1 -0
  514. package/dist/modes/interactive/components/permission-preview.js +33 -0
  515. package/dist/modes/interactive/components/permission-preview.js.map +1 -0
  516. package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
  517. package/dist/modes/interactive/components/session-selector.js +2 -2
  518. package/dist/modes/interactive/components/session-selector.js.map +1 -1
  519. package/dist/modes/interactive/components/settings-selector.d.ts +9 -2
  520. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  521. package/dist/modes/interactive/components/settings-selector.js +128 -56
  522. package/dist/modes/interactive/components/settings-selector.js.map +1 -1
  523. package/dist/modes/interactive/components/settings-submenu.d.ts +72 -0
  524. package/dist/modes/interactive/components/settings-submenu.d.ts.map +1 -0
  525. package/dist/modes/interactive/components/settings-submenu.js +165 -0
  526. package/dist/modes/interactive/components/settings-submenu.js.map +1 -0
  527. package/dist/modes/interactive/components/thinking-selector.d.ts +15 -3
  528. package/dist/modes/interactive/components/thinking-selector.d.ts.map +1 -1
  529. package/dist/modes/interactive/components/thinking-selector.js +74 -17
  530. package/dist/modes/interactive/components/thinking-selector.js.map +1 -1
  531. package/dist/modes/interactive/components/tool-execution.d.ts +23 -1
  532. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  533. package/dist/modes/interactive/components/tool-execution.js +64 -10
  534. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  535. package/dist/modes/interactive/external-editor.d.ts.map +1 -1
  536. package/dist/modes/interactive/external-editor.js +2 -1
  537. package/dist/modes/interactive/external-editor.js.map +1 -1
  538. package/dist/modes/interactive/interactive-mode.d.ts +45 -0
  539. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  540. package/dist/modes/interactive/interactive-mode.js +395 -43
  541. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  542. package/dist/modes/interactive/theme/theme.d.ts +12 -0
  543. package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
  544. package/dist/modes/interactive/theme/theme.js +20 -9
  545. package/dist/modes/interactive/theme/theme.js.map +1 -1
  546. package/dist/modes/json-event.d.ts +16 -13
  547. package/dist/modes/json-event.d.ts.map +1 -1
  548. package/dist/modes/json-event.js +20 -6
  549. package/dist/modes/json-event.js.map +1 -1
  550. package/dist/modes/print-mode.d.ts.map +1 -1
  551. package/dist/modes/print-mode.js +27 -12
  552. package/dist/modes/print-mode.js.map +1 -1
  553. package/dist/modes/rpc/rpc-client.d.ts +7 -0
  554. package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
  555. package/dist/modes/rpc/rpc-client.js +7 -0
  556. package/dist/modes/rpc/rpc-client.js.map +1 -1
  557. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  558. package/dist/modes/rpc/rpc-mode.js +3 -0
  559. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  560. package/dist/modes/rpc/rpc-types.d.ts +12 -0
  561. package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
  562. package/dist/modes/rpc/rpc-types.js.map +1 -1
  563. package/dist/package-manager-cli.d.ts +1 -0
  564. package/dist/package-manager-cli.d.ts.map +1 -1
  565. package/dist/package-manager-cli.js +196 -10
  566. package/dist/package-manager-cli.js.map +1 -1
  567. package/dist/utils/frontmatter.d.ts.map +1 -1
  568. package/dist/utils/frontmatter.js +2 -1
  569. package/dist/utils/frontmatter.js.map +1 -1
  570. package/dist/utils/management-http.d.ts +5 -3
  571. package/dist/utils/management-http.d.ts.map +1 -1
  572. package/dist/utils/management-http.js +14 -10
  573. package/dist/utils/management-http.js.map +1 -1
  574. package/dist/utils/shell.d.ts +3 -0
  575. package/dist/utils/shell.d.ts.map +1 -1
  576. package/dist/utils/shell.js +23 -9
  577. package/dist/utils/shell.js.map +1 -1
  578. package/dist/utils/syntax-highlight.d.ts +1 -0
  579. package/dist/utils/syntax-highlight.d.ts.map +1 -1
  580. package/dist/utils/syntax-highlight.js +60 -1
  581. package/dist/utils/syntax-highlight.js.map +1 -1
  582. package/dist/utils/text.d.ts +8 -0
  583. package/dist/utils/text.d.ts.map +1 -0
  584. package/dist/utils/text.js +9 -0
  585. package/dist/utils/text.js.map +1 -0
  586. package/dist/utils/version-check.d.ts.map +1 -1
  587. package/dist/utils/version-check.js +6 -4
  588. package/dist/utils/version-check.js.map +1 -1
  589. package/docs/compaction.md +19 -0
  590. package/docs/custom-provider.md +12 -9
  591. package/docs/environment-variables.md +1 -1
  592. package/docs/extensions.md +35 -7
  593. package/docs/json.md +7 -2
  594. package/docs/keybindings.md +9 -9
  595. package/docs/llama-cpp.md +2 -0
  596. package/docs/models.md +8 -2
  597. package/docs/packages.md +2 -2
  598. package/docs/quickstart.md +1 -1
  599. package/docs/rpc.md +32 -3
  600. package/docs/sdk.md +32 -2
  601. package/docs/settings.md +23 -7
  602. package/docs/skills.md +4 -3
  603. package/docs/terminal-setup.md +23 -7
  604. package/docs/usage.md +10 -5
  605. package/docs/windows.md +24 -2
  606. package/examples/extensions/border-status-editor.ts +1 -1
  607. package/examples/extensions/built-in-tool-renderer.ts +8 -4
  608. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  609. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  610. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  611. package/examples/extensions/git-checkpoint.ts +24 -36
  612. package/examples/extensions/gondolin/package-lock.json +2 -2
  613. package/examples/extensions/gondolin/package.json +1 -1
  614. package/examples/extensions/minimal-mode.ts +2 -2
  615. package/examples/extensions/notify.ts +3 -1
  616. package/examples/extensions/permission-gate.ts +1 -1
  617. package/examples/extensions/plan-mode/index.ts +1 -1
  618. package/examples/extensions/rpc-demo.ts +1 -1
  619. package/examples/extensions/sandbox/package-lock.json +2 -2
  620. package/examples/extensions/sandbox/package.json +1 -1
  621. package/examples/extensions/subagent/README.md +1 -1
  622. package/examples/extensions/subagent/index.ts +6 -1
  623. package/examples/extensions/titlebar-spinner.ts +1 -1
  624. package/examples/extensions/with-deps/package-lock.json +2 -2
  625. package/examples/extensions/with-deps/package.json +1 -1
  626. package/examples/rpc-extension-ui.ts +1 -1
  627. package/examples/sdk/06-extensions.ts +1 -1
  628. package/examples/sdk/README.md +1 -1
  629. package/npm-shrinkwrap.json +439 -405
  630. package/package.json +17 -17
  631. package/dist/server/create-harness.d.ts +0 -26
  632. package/dist/server/create-harness.d.ts.map +0 -1
  633. package/dist/server/create-harness.js +0 -107
  634. package/dist/server/create-harness.js.map +0 -1
@@ -1,24 +1,46 @@
1
+ import { isAbsolute, relative } from "node:path";
1
2
  import { fileURLToPath, pathToFileURL } from "node:url";
2
3
  import { Type } from "typebox";
3
4
  import { formatPathRelativeToCwdOrAbsolute } from "../../utils/paths.js";
5
+ import { toolUnion } from "./contract.js";
4
6
  import { createPathPermissionSpec } from "./path-permission.js";
5
7
  import { resolveToCwd } from "./path-utils.js";
6
8
  import { wrapToolDefinition } from "./tool-definition-wrapper.js";
7
9
  const MAX_LOCATIONS = 1_000;
8
10
  const MAX_SYMBOLS = 2_000;
11
+ /** Cap on the serialized symbol details so a result can never grow unbounded (spec § 4). */
12
+ const MAX_DETAILS_BYTES = 256 * 1024;
9
13
  const lspNavigationSchema = Type.Object({
10
- operation: Type.Union([Type.Literal("definition"), Type.Literal("references")], {
11
- description: "Which navigation query to run.",
12
- }),
13
- path: Type.String({ description: "Path to the file (relative or absolute)." }),
14
- line: Type.Number({ description: "One-based line number." }),
15
- character: Type.Number({ description: "One-based UTF-16 character offset within the line." }),
14
+ operation: Type.Union([Type.Literal("definition"), Type.Literal("references")]),
15
+ path: Type.String(),
16
+ line: Type.Number(),
17
+ character: Type.Number(),
16
18
  });
17
19
  const lspDocumentSymbolsSchema = Type.Object({
18
- operation: Type.Literal("document_symbols", { description: "List the symbols declared in a file." }),
19
- path: Type.String({ description: "Path to the file (relative or absolute)." }),
20
+ operation: Type.Literal("document_symbols"),
21
+ path: Type.String(),
22
+ });
23
+ const lspWorkspaceSymbolsSchema = Type.Object({
24
+ operation: Type.Literal("workspace_symbol"),
25
+ query: Type.String(),
20
26
  });
21
- const lspSchema = Type.Union([lspNavigationSchema, lspDocumentSymbolsSchema]);
27
+ const lspSchemaProperties = {
28
+ operation: Type.Union([
29
+ Type.Literal("definition"),
30
+ Type.Literal("references"),
31
+ Type.Literal("document_symbols"),
32
+ Type.Literal("workspace_symbol"),
33
+ ], { description: "Which query to run." }),
34
+ path: Type.String({
35
+ description: "Path to the file (relative or absolute). Required by every operation but workspace_symbol.",
36
+ }),
37
+ line: Type.Number({ description: "One-based line number. Required by definition and references." }),
38
+ character: Type.Number({
39
+ description: "One-based UTF-16 character offset within the line. Required by definition and references.",
40
+ }),
41
+ query: Type.String({ description: "The symbol name to search for. Required by workspace_symbol." }),
42
+ };
43
+ const lspSchema = toolUnion([lspNavigationSchema, lspDocumentSymbolsSchema, lspWorkspaceSymbolsSchema], lspSchemaProperties);
22
44
  function isRecord(value) {
23
45
  return typeof value === "object" && value !== null && !Array.isArray(value);
24
46
  }
@@ -138,6 +160,96 @@ function capSymbols(symbols, max) {
138
160
  const capped = sorted.slice(0, max);
139
161
  return { symbols: capped, truncated: sorted.length - capped.length };
140
162
  }
163
+ function isInsideRoot(absolutePath, root) {
164
+ const rel = relative(root, absolutePath);
165
+ return rel === "" || (!rel.startsWith("..") && !isAbsolute(rel));
166
+ }
167
+ function rawWorkspaceSymbol(value) {
168
+ if (!isRecord(value) || typeof value.name !== "string")
169
+ return undefined;
170
+ return {
171
+ name: value.name,
172
+ kind: typeof value.kind === "number" ? value.kind : 0,
173
+ ...(typeof value.containerName === "string" ? { containerName: value.containerName } : {}),
174
+ };
175
+ }
176
+ /**
177
+ * Normalize `workspace/symbol` SymbolInformation results: file URIs to
178
+ * workspace-relative paths, zero-based ranges to one-based, and every result
179
+ * outside the authorized root dropped with an honest count (spec § 4: the
180
+ * root is never widened because a result points outside it).
181
+ */
182
+ function normalizeWorkspaceSymbols(raw, cwd) {
183
+ const items = Array.isArray(raw) ? raw : raw === undefined || raw === null ? [] : [raw];
184
+ const symbols = [];
185
+ let omitted = 0;
186
+ let outsideRoot = 0;
187
+ for (const item of items) {
188
+ const parsed = rawLocationUriAndRange(isRecord(item) ? (item.location ?? item) : undefined);
189
+ const absolutePath = parsed ? fileUriToAbsolutePath(parsed.uri) : undefined;
190
+ const info = rawWorkspaceSymbol(item);
191
+ if (!parsed || !absolutePath || !info) {
192
+ omitted++;
193
+ continue;
194
+ }
195
+ if (!isInsideRoot(absolutePath, cwd)) {
196
+ outsideRoot++;
197
+ continue;
198
+ }
199
+ symbols.push({
200
+ ...info,
201
+ path: formatPathRelativeToCwdOrAbsolute(absolutePath, cwd),
202
+ range: toOneBasedRange(parsed.range),
203
+ });
204
+ }
205
+ return { symbols, omitted, outsideRoot };
206
+ }
207
+ function compareWorkspaceSymbols(a, b) {
208
+ if (a.path !== b.path)
209
+ return a.path < b.path ? -1 : 1;
210
+ if (a.range.start.line !== b.range.start.line)
211
+ return a.range.start.line - b.range.start.line;
212
+ return a.name === b.name ? 0 : a.name < b.name ? -1 : 1;
213
+ }
214
+ function capWorkspaceSymbolsByCount(symbols, max) {
215
+ const sorted = [...symbols].sort(compareWorkspaceSymbols);
216
+ const capped = sorted.slice(0, max);
217
+ return { symbols: capped, truncated: sorted.length - capped.length };
218
+ }
219
+ function capWorkspaceSymbolsByBytes(symbols, maxBytes) {
220
+ let used = 2; // "[]"
221
+ for (let i = 0; i < symbols.length; i++) {
222
+ const cost = Buffer.byteLength(JSON.stringify(symbols[i]), "utf-8") + 1;
223
+ if (used + cost > maxBytes) {
224
+ return { symbols: symbols.slice(0, i), truncated: symbols.length - i };
225
+ }
226
+ used += cost;
227
+ }
228
+ return { symbols, truncated: 0 };
229
+ }
230
+ function isUnsupportedMethodError(error) {
231
+ const message = error instanceof Error ? error.message : String(error);
232
+ return message.includes("-32601") || /method not found/i.test(message);
233
+ }
234
+ function formatWorkspaceSymbolsNotices(omitted, truncated, outsideRoot) {
235
+ const notices = [];
236
+ if (omitted > 0)
237
+ notices.push(`${omitted} non-file result(s) omitted`);
238
+ if (outsideRoot > 0)
239
+ notices.push(`${outsideRoot} result(s) outside the workspace root omitted`);
240
+ if (truncated > 0)
241
+ notices.push(`${truncated} result(s) truncated`);
242
+ return notices.length > 0 ? `\n\n[${notices.join(", ")}]` : "";
243
+ }
244
+ function formatWorkspaceSymbolsText(symbols, omitted, truncated, outsideRoot) {
245
+ if (symbols.length === 0) {
246
+ const base = "No symbols found.";
247
+ const notices = formatWorkspaceSymbolsNotices(omitted, truncated, outsideRoot);
248
+ return notices ? `${base}${notices}` : base;
249
+ }
250
+ const lines = symbols.map((symbol) => `${symbol.path}:${symbol.range.start.line}:${symbol.range.start.character} ${symbol.name}`);
251
+ return `${lines.join("\n")}${formatWorkspaceSymbolsNotices(omitted, truncated, outsideRoot)}`;
252
+ }
141
253
  function formatNotices(omitted, truncated) {
142
254
  const notices = [];
143
255
  if (omitted > 0)
@@ -177,12 +289,53 @@ export function createLspToolDefinition(cwd, options) {
177
289
  cwd,
178
290
  defaultBehavior: "allow",
179
291
  verb: "Query",
180
- getPath: (params) => params.path,
292
+ // A workspace_symbol call has no path; returning undefined normalizes to
293
+ // the workspace root, so the same gate authorizes the root before the
294
+ // request is sent and `ruleForCall` stays inside one grammar.
295
+ getPath: (params) => ("path" in params ? params.path : undefined),
181
296
  }),
182
297
  context: { resultRecoverable: true, deferSchema: true },
183
298
  evidence: { emits: new Set(), capture: () => [] },
184
299
  },
185
300
  async execute(_toolCallId, input, signal) {
301
+ if (input.operation === "workspace_symbol") {
302
+ // The permission gate has already authorized the workspace root by the
303
+ // time execute runs; only now does the request go out.
304
+ try {
305
+ const raw = await operations.request(cwd, "workspace/symbol", { query: input.query }, signal);
306
+ const { symbols, omitted, outsideRoot } = normalizeWorkspaceSymbols(raw, cwd);
307
+ const { symbols: countCapped, truncated: countTruncated } = capWorkspaceSymbolsByCount(symbols, MAX_SYMBOLS);
308
+ const { symbols: capped, truncated: byteTruncated } = capWorkspaceSymbolsByBytes(countCapped, MAX_DETAILS_BYTES);
309
+ const truncated = countTruncated + byteTruncated;
310
+ return {
311
+ content: [
312
+ { type: "text", text: formatWorkspaceSymbolsText(capped, omitted, truncated, outsideRoot) },
313
+ ],
314
+ details: { operation: "workspace_symbol", symbols: capped, omitted, truncated, outsideRoot },
315
+ };
316
+ }
317
+ catch (error) {
318
+ if (isUnsupportedMethodError(error)) {
319
+ return {
320
+ content: [
321
+ {
322
+ type: "text",
323
+ text: "workspace_symbol is not supported by the configured language server.",
324
+ },
325
+ ],
326
+ details: {
327
+ operation: "workspace_symbol",
328
+ symbols: [],
329
+ omitted: 0,
330
+ truncated: 0,
331
+ outsideRoot: 0,
332
+ unsupported: true,
333
+ },
334
+ };
335
+ }
336
+ throw error;
337
+ }
338
+ }
186
339
  const absolutePath = resolveToCwd(input.path, cwd);
187
340
  const uri = pathToFileURL(absolutePath).href;
188
341
  if (input.operation === "document_symbols") {
@@ -1 +1 @@
1
- {"version":3,"file":"lsp.js","sourceRoot":"","sources":["../../../src/core/tools/lsp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAExD,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,iCAAiC,EAAE,MAAM,sBAAsB,CAAC;AAEzE,OAAO,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAElE,MAAM,aAAa,GAAG,KAAK,CAAC;AAC5B,MAAM,WAAW,GAAG,KAAK,CAAC;AAE1B,MAAM,mBAAmB,GAAG,IAAI,CAAC,MAAM,CAAC;IACvC,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,EAAE;QAC/E,WAAW,EAAE,gCAAgC;KAC7C,CAAC;IACF,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,0CAA0C,EAAE,CAAC;IAC9E,IAAI,EAAE,IAAI,CAAC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C,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,mBAAmB,CAAC,KAAK,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,CAAC,EAAE,CAAC;gBACnG,OAAO,EAAE,EAAE,SAAS,EAAE,KAAK,CAAC,SAAS,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE;aAC9E,CAAC;QAAA,CACF;KACD,CAAC;AAAA,CACF;AAED,MAAM,UAAU,aAAa,CAAC,GAAW,EAAE,OAAuB,EAA+B;IAChG,OAAO,kBAAkB,CAAC,uBAAuB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC;AAAA,CACjE","sourcesContent":["import { fileURLToPath, pathToFileURL } from \"node:url\";\nimport type { AgentTool } from \"apex-code-agent-core\";\nimport { type Static, Type } from \"typebox\";\nimport { formatPathRelativeToCwdOrAbsolute } from \"../../utils/paths.ts\";\nimport type { ApexToolDefinition } from \"./contract.ts\";\nimport { createPathPermissionSpec } from \"./path-permission.ts\";\nimport { resolveToCwd } from \"./path-utils.ts\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\n\nconst MAX_LOCATIONS = 1_000;\nconst MAX_SYMBOLS = 2_000;\n\nconst lspNavigationSchema = Type.Object({\n\toperation: Type.Union([Type.Literal(\"definition\"), Type.Literal(\"references\")], {\n\t\tdescription: \"Which navigation query to run.\",\n\t}),\n\tpath: Type.String({ description: \"Path to the file (relative or absolute).\" }),\n\tline: Type.Number({ description: \"One-based line number.\" }),\n\tcharacter: Type.Number({ description: \"One-based UTF-16 character offset within the line.\" }),\n});\n\nconst lspDocumentSymbolsSchema = Type.Object({\n\toperation: Type.Literal(\"document_symbols\", { description: \"List the symbols declared in a file.\" }),\n\tpath: Type.String({ description: \"Path to the file (relative or absolute).\" }),\n});\n\nconst lspSchema = Type.Union([lspNavigationSchema, lspDocumentSymbolsSchema]);\n\nexport type LspToolInput = Static<typeof lspSchema>;\n\nexport interface LspPosition {\n\treadonly line: number;\n\treadonly character: number;\n}\n\nexport interface LspRange {\n\treadonly start: LspPosition;\n\treadonly end: LspPosition;\n}\n\n/** A navigation result normalized to a workspace-relative path and one-based range. */\nexport interface LspLocation {\n\treadonly path: string;\n\treadonly range: LspRange;\n}\n\n/** A flattened document symbol normalized to a workspace-relative path and one-based ranges. */\nexport interface LspSymbol {\n\treadonly name: string;\n\treadonly kind: number;\n\treadonly path: string;\n\treadonly range: LspRange;\n\treadonly selectionRange: LspRange;\n\treadonly detail?: string;\n}\n\nexport type LspToolDetails =\n\t| { operation: \"definition\" | \"references\"; locations: LspLocation[]; omitted: number; truncated: number }\n\t| { operation: \"document_symbols\"; symbols: LspSymbol[]; omitted: number; truncated: number };\n\n/**\n * Pluggable transport for the `lsp` tool. The executable, its arguments, and the\n * closed JSON-RPC method set are all fixed by configuration the tool never chooses\n * itself -- see contract.capabilities below for why that keeps this `{fs.read}`\n * rather than `{exec}`.\n */\nexport interface LspOperations {\n\trequest(absolutePath: string, method: string, params: unknown, signal?: AbortSignal): Promise<unknown>;\n}\n\nexport interface LspToolOptions {\n\toperations: LspOperations;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction isPosition(value: unknown): value is LspPosition {\n\treturn isRecord(value) && typeof value.line === \"number\" && typeof value.character === \"number\";\n}\n\nfunction isRange(value: unknown): value is LspRange {\n\treturn isRecord(value) && isPosition(value.start) && isPosition(value.end);\n}\n\nfunction toOneBasedPosition(position: LspPosition): LspPosition {\n\treturn { line: position.line + 1, character: position.character + 1 };\n}\n\nfunction toOneBasedRange(range: LspRange): LspRange {\n\treturn { start: toOneBasedPosition(range.start), end: toOneBasedPosition(range.end) };\n}\n\nfunction fileUriToAbsolutePath(uri: string): string | undefined {\n\tif (!uri.startsWith(\"file:\")) return undefined;\n\ttry {\n\t\treturn fileURLToPath(uri);\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nfunction rawLocationUriAndRange(value: unknown): { uri: string; range: LspRange } | undefined {\n\tif (!isRecord(value)) return undefined;\n\tif (typeof value.uri === \"string\" && isRange(value.range)) return { uri: value.uri, range: value.range };\n\tif (typeof value.targetUri === \"string\" && isRange(value.targetRange)) {\n\t\treturn { uri: value.targetUri, range: value.targetRange };\n\t}\n\treturn undefined;\n}\n\nfunction normalizeLocations(raw: unknown, cwd: string): { locations: LspLocation[]; omitted: number } {\n\tconst items = Array.isArray(raw) ? raw : raw === undefined || raw === null ? [] : [raw];\n\tconst locations: LspLocation[] = [];\n\tlet omitted = 0;\n\tfor (const item of items) {\n\t\tconst parsed = rawLocationUriAndRange(item);\n\t\tconst absolutePath = parsed ? fileUriToAbsolutePath(parsed.uri) : undefined;\n\t\tif (!parsed || !absolutePath) {\n\t\t\tomitted++;\n\t\t\tcontinue;\n\t\t}\n\t\tlocations.push({\n\t\t\tpath: formatPathRelativeToCwdOrAbsolute(absolutePath, cwd),\n\t\t\trange: toOneBasedRange(parsed.range),\n\t\t});\n\t}\n\treturn { locations, omitted };\n}\n\nfunction compareLocations(a: LspLocation, b: LspLocation): number {\n\tif (a.path !== b.path) return a.path < b.path ? -1 : 1;\n\tif (a.range.start.line !== b.range.start.line) return a.range.start.line - b.range.start.line;\n\tif (a.range.start.character !== b.range.start.character) return a.range.start.character - b.range.start.character;\n\tif (a.range.end.line !== b.range.end.line) return a.range.end.line - b.range.end.line;\n\treturn a.range.end.character - b.range.end.character;\n}\n\nfunction dedupeSortAndCap(locations: LspLocation[], max: number): { locations: LspLocation[]; truncated: number } {\n\tconst seen = new Set<string>();\n\tconst unique: LspLocation[] = [];\n\tfor (const location of locations) {\n\t\tconst key = JSON.stringify(location);\n\t\tif (seen.has(key)) continue;\n\t\tseen.add(key);\n\t\tunique.push(location);\n\t}\n\tunique.sort(compareLocations);\n\tconst capped = unique.slice(0, max);\n\treturn { locations: capped, truncated: unique.length - capped.length };\n}\n\nfunction isRawDocumentSymbol(value: unknown): value is Record<string, unknown> {\n\treturn isRecord(value) && typeof value.name === \"string\" && isRange(value.range) && isRange(value.selectionRange);\n}\n\nfunction flattenSymbols(raw: unknown, path: string): { symbols: LspSymbol[]; omitted: number } {\n\tconst symbols: LspSymbol[] = [];\n\tlet omitted = 0;\n\tconst visit = (value: unknown): void => {\n\t\tif (!Array.isArray(value)) return;\n\t\tfor (const item of value) {\n\t\t\tif (!isRawDocumentSymbol(item)) {\n\t\t\t\tomitted++;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tsymbols.push({\n\t\t\t\tname: item.name as string,\n\t\t\t\tkind: typeof item.kind === \"number\" ? item.kind : 0,\n\t\t\t\tpath,\n\t\t\t\trange: toOneBasedRange(item.range as LspRange),\n\t\t\t\tselectionRange: toOneBasedRange(item.selectionRange as LspRange),\n\t\t\t\t...(typeof item.detail === \"string\" ? { detail: item.detail } : {}),\n\t\t\t});\n\t\t\tif (Array.isArray(item.children)) visit(item.children);\n\t\t}\n\t};\n\tvisit(Array.isArray(raw) ? raw : []);\n\treturn { symbols, omitted };\n}\n\nfunction compareSymbols(a: LspSymbol, b: LspSymbol): number {\n\tif (a.range.start.line !== b.range.start.line) return a.range.start.line - b.range.start.line;\n\tif (a.range.start.character !== b.range.start.character) return a.range.start.character - b.range.start.character;\n\treturn a.name === b.name ? 0 : a.name < b.name ? -1 : 1;\n}\n\nfunction capSymbols(symbols: LspSymbol[], max: number): { symbols: LspSymbol[]; truncated: number } {\n\tconst sorted = [...symbols].sort(compareSymbols);\n\tconst capped = sorted.slice(0, max);\n\treturn { symbols: capped, truncated: sorted.length - capped.length };\n}\n\nfunction formatNotices(omitted: number, truncated: number): string {\n\tconst notices: string[] = [];\n\tif (omitted > 0) notices.push(`${omitted} non-file result(s) omitted`);\n\tif (truncated > 0) notices.push(`${truncated} result(s) truncated`);\n\treturn notices.length > 0 ? `\\n\\n[${notices.join(\", \")}]` : \"\";\n}\n\nfunction formatLocationsText(\n\toperation: \"definition\" | \"references\",\n\tlocations: LspLocation[],\n\tomitted: number,\n\ttruncated: number,\n): string {\n\tif (locations.length === 0) {\n\t\treturn operation === \"definition\" ? \"No definition found.\" : \"No references found.\";\n\t}\n\tconst lines = locations.map(\n\t\t(location) => `${location.path}:${location.range.start.line}:${location.range.start.character}`,\n\t);\n\treturn `${lines.join(\"\\n\")}${formatNotices(omitted, truncated)}`;\n}\n\nfunction formatSymbolsText(symbols: LspSymbol[], omitted: number, truncated: number): string {\n\tif (symbols.length === 0) return \"No symbols found.\";\n\tconst lines = symbols.map(\n\t\t(symbol) => `${symbol.path}:${symbol.range.start.line}:${symbol.range.start.character} ${symbol.name}`,\n\t);\n\treturn `${lines.join(\"\\n\")}${formatNotices(omitted, truncated)}`;\n}\n\nexport function createLspToolDefinition(\n\tcwd: string,\n\toptions: LspToolOptions,\n): ApexToolDefinition<typeof lspSchema, LspToolDetails> {\n\tconst { operations } = options;\n\treturn {\n\t\tname: \"lsp\",\n\t\tlabel: \"lsp\",\n\t\tdescription: \"Query the configured language server for definitions, references, or symbols.\",\n\t\tparameters: lspSchema,\n\t\tcontract: {\n\t\t\t// `grep` spawns `rg` and declares {fs.read}, not {exec}, because the caller\n\t\t\t// never chooses what runs -- the executable, args, and closed JSON-RPC\n\t\t\t// method set all come from settings.json / this tool's own code. Same\n\t\t\t// reasoning here: {exec} would silently widen a delegation ceiling for no\n\t\t\t// capability the model can actually reach through this tool.\n\t\t\tcapabilities: new Set([\"fs.read\"]),\n\t\t\tpermission: createPathPermissionSpec({\n\t\t\t\tcwd,\n\t\t\t\tdefaultBehavior: \"allow\",\n\t\t\t\tverb: \"Query\",\n\t\t\t\tgetPath: (params) => params.path,\n\t\t\t}),\n\t\t\tcontext: { resultRecoverable: true, deferSchema: true },\n\t\t\tevidence: { emits: new Set(), capture: () => [] },\n\t\t},\n\t\tasync execute(_toolCallId, input: LspToolInput, signal?: AbortSignal) {\n\t\t\tconst absolutePath = resolveToCwd(input.path, cwd);\n\t\t\tconst uri = pathToFileURL(absolutePath).href;\n\n\t\t\tif (input.operation === \"document_symbols\") {\n\t\t\t\tconst raw = await operations.request(\n\t\t\t\t\tabsolutePath,\n\t\t\t\t\t\"textDocument/documentSymbol\",\n\t\t\t\t\t{ textDocument: { uri } },\n\t\t\t\t\tsignal,\n\t\t\t\t);\n\t\t\t\tconst relativePath = formatPathRelativeToCwdOrAbsolute(absolutePath, cwd);\n\t\t\t\tconst { symbols, omitted } = flattenSymbols(raw, relativePath);\n\t\t\t\tconst { symbols: capped, truncated } = capSymbols(symbols, MAX_SYMBOLS);\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\", text: formatSymbolsText(capped, omitted, truncated) }],\n\t\t\t\t\tdetails: { operation: \"document_symbols\", symbols: capped, omitted, truncated },\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst position = { line: input.line - 1, character: input.character - 1 };\n\t\t\tconst method = input.operation === \"definition\" ? \"textDocument/definition\" : \"textDocument/references\";\n\t\t\tconst params: Record<string, unknown> = { textDocument: { uri }, position };\n\t\t\tif (input.operation === \"references\") params.context = { includeDeclaration: true };\n\t\t\tconst raw = await operations.request(absolutePath, method, params, signal);\n\t\t\tconst { locations, omitted } = normalizeLocations(raw, cwd);\n\t\t\tconst { locations: capped, truncated } = dedupeSortAndCap(locations, MAX_LOCATIONS);\n\t\t\treturn {\n\t\t\t\tcontent: [{ type: \"text\", text: formatLocationsText(input.operation, capped, omitted, truncated) }],\n\t\t\t\tdetails: { operation: input.operation, locations: capped, omitted, truncated },\n\t\t\t};\n\t\t},\n\t};\n}\n\nexport function createLspTool(cwd: string, options: LspToolOptions): AgentTool<typeof lspSchema> {\n\treturn wrapToolDefinition(createLspToolDefinition(cwd, options));\n}\n"]}
1
+ {"version":3,"file":"lsp.js","sourceRoot":"","sources":["../../../src/core/tools/lsp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE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,CAAC,EAAE,CAAC;YAC1E,MAAM,MAAM,GAAG,KAAK,CAAC,SAAS,KAAK,YAAY,CAAC,CAAC,CAAC,yBAAyB,CAAC,CAAC,CAAC,yBAAyB,CAAC;YACxG,MAAM,MAAM,GAA4B,EAAE,YAAY,EAAE,EAAE,GAAG,EAAE,EAAE,QAAQ,EAAE,CAAC;YAC5E,IAAI,KAAK,CAAC,SAAS,KAAK,YAAY;gBAAE,MAAM,CAAC,OAAO,GAAG,EAAE,kBAAkB,EAAE,IAAI,EAAE,CAAC;YACpF,MAAM,GAAG,GAAG,MAAM,UAAU,CAAC,OAAO,CAAC,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;YAC3E,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,GAAG,kBAAkB,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;YAC5D,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,gBAAgB,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC;YACpF,OAAO;gBACN,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,mBAAmB,CAAC,KAAK,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,CAAC,EAAE,CAAC;gBACnG,OAAO,EAAE,EAAE,SAAS,EAAE,KAAK,CAAC,SAAS,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE;aAC9E,CAAC;QAAA,CACF;KACD,CAAC;AAAA,CACF;AAED,MAAM,UAAU,aAAa,CAAC,GAAW,EAAE,OAAuB,EAA+B;IAChG,OAAO,kBAAkB,CAAC,uBAAuB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC;AAAA,CACjE","sourcesContent":["import { isAbsolute, relative } from \"node:path\";\nimport { fileURLToPath, pathToFileURL } from \"node:url\";\nimport type { AgentTool } from \"apex-code-agent-core\";\nimport { type Static, Type } from \"typebox\";\nimport { formatPathRelativeToCwdOrAbsolute } from \"../../utils/paths.ts\";\nimport { type ApexToolDefinition, toolUnion } from \"./contract.ts\";\nimport { createPathPermissionSpec } from \"./path-permission.ts\";\nimport { resolveToCwd } from \"./path-utils.ts\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\n\nconst MAX_LOCATIONS = 1_000;\nconst MAX_SYMBOLS = 2_000;\n/** Cap on the serialized symbol details so a result can never grow unbounded (spec § 4). */\nconst MAX_DETAILS_BYTES = 256 * 1024;\n\nconst lspNavigationSchema = Type.Object({\n\toperation: Type.Union([Type.Literal(\"definition\"), Type.Literal(\"references\")]),\n\tpath: Type.String(),\n\tline: Type.Number(),\n\tcharacter: Type.Number(),\n});\n\nconst lspDocumentSymbolsSchema = Type.Object({\n\toperation: Type.Literal(\"document_symbols\"),\n\tpath: Type.String(),\n});\n\nconst lspWorkspaceSymbolsSchema = Type.Object({\n\toperation: Type.Literal(\"workspace_symbol\"),\n\tquery: Type.String(),\n});\n\nconst lspSchemaProperties = {\n\toperation: Type.Union(\n\t\t[\n\t\t\tType.Literal(\"definition\"),\n\t\t\tType.Literal(\"references\"),\n\t\t\tType.Literal(\"document_symbols\"),\n\t\t\tType.Literal(\"workspace_symbol\"),\n\t\t],\n\t\t{ description: \"Which query to run.\" },\n\t),\n\tpath: Type.String({\n\t\tdescription: \"Path to the file (relative or absolute). Required by every operation but workspace_symbol.\",\n\t}),\n\tline: Type.Number({ description: \"One-based line number. Required by definition and references.\" }),\n\tcharacter: Type.Number({\n\t\tdescription: \"One-based UTF-16 character offset within the line. Required by definition and references.\",\n\t}),\n\tquery: Type.String({ description: \"The symbol name to search for. Required by workspace_symbol.\" }),\n};\n\nconst lspSchema = toolUnion(\n\t[lspNavigationSchema, lspDocumentSymbolsSchema, lspWorkspaceSymbolsSchema],\n\tlspSchemaProperties,\n);\n\nexport type LspToolInput = Static<typeof lspSchema>;\n\nexport interface LspPosition {\n\treadonly line: number;\n\treadonly character: number;\n}\n\nexport interface LspRange {\n\treadonly start: LspPosition;\n\treadonly end: LspPosition;\n}\n\n/** A navigation result normalized to a workspace-relative path and one-based range. */\nexport interface LspLocation {\n\treadonly path: string;\n\treadonly range: LspRange;\n}\n\n/** A flattened document symbol normalized to a workspace-relative path and one-based ranges. */\nexport interface LspSymbol {\n\treadonly name: string;\n\treadonly kind: number;\n\treadonly path: string;\n\treadonly range: LspRange;\n\treadonly selectionRange: LspRange;\n\treadonly detail?: string;\n}\n\n/** A workspace-wide symbol (LSP SymbolInformation) normalized like {@link LspSymbol} without a selection range. */\nexport interface LspWorkspaceSymbol {\n\treadonly name: string;\n\treadonly kind: number;\n\treadonly path: string;\n\treadonly range: LspRange;\n\treadonly containerName?: string;\n}\n\nexport type LspToolDetails =\n\t| { operation: \"definition\" | \"references\"; locations: LspLocation[]; omitted: number; truncated: number }\n\t| { operation: \"document_symbols\"; symbols: LspSymbol[]; omitted: number; truncated: number }\n\t| {\n\t\t\toperation: \"workspace_symbol\";\n\t\t\tsymbols: LspWorkspaceSymbol[];\n\t\t\tomitted: number;\n\t\t\ttruncated: number;\n\t\t\toutsideRoot: number;\n\t\t\tunsupported?: boolean;\n\t };\n\n/**\n * Pluggable transport for the `lsp` tool. The executable, its arguments, and the\n * closed JSON-RPC method set are all fixed by configuration the tool never chooses\n * itself -- see contract.capabilities below for why that keeps this `{fs.read}`\n * rather than `{exec}`.\n */\nexport interface LspOperations {\n\trequest(absolutePath: string, method: string, params: unknown, signal?: AbortSignal): Promise<unknown>;\n}\n\nexport interface LspToolOptions {\n\toperations: LspOperations;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction isPosition(value: unknown): value is LspPosition {\n\treturn isRecord(value) && typeof value.line === \"number\" && typeof value.character === \"number\";\n}\n\nfunction isRange(value: unknown): value is LspRange {\n\treturn isRecord(value) && isPosition(value.start) && isPosition(value.end);\n}\n\nfunction toOneBasedPosition(position: LspPosition): LspPosition {\n\treturn { line: position.line + 1, character: position.character + 1 };\n}\n\nfunction toOneBasedRange(range: LspRange): LspRange {\n\treturn { start: toOneBasedPosition(range.start), end: toOneBasedPosition(range.end) };\n}\n\nfunction fileUriToAbsolutePath(uri: string): string | undefined {\n\tif (!uri.startsWith(\"file:\")) return undefined;\n\ttry {\n\t\treturn fileURLToPath(uri);\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nfunction rawLocationUriAndRange(value: unknown): { uri: string; range: LspRange } | undefined {\n\tif (!isRecord(value)) return undefined;\n\tif (typeof value.uri === \"string\" && isRange(value.range)) return { uri: value.uri, range: value.range };\n\tif (typeof value.targetUri === \"string\" && isRange(value.targetRange)) {\n\t\treturn { uri: value.targetUri, range: value.targetRange };\n\t}\n\treturn undefined;\n}\n\nfunction normalizeLocations(raw: unknown, cwd: string): { locations: LspLocation[]; omitted: number } {\n\tconst items = Array.isArray(raw) ? raw : raw === undefined || raw === null ? [] : [raw];\n\tconst locations: LspLocation[] = [];\n\tlet omitted = 0;\n\tfor (const item of items) {\n\t\tconst parsed = rawLocationUriAndRange(item);\n\t\tconst absolutePath = parsed ? fileUriToAbsolutePath(parsed.uri) : undefined;\n\t\tif (!parsed || !absolutePath) {\n\t\t\tomitted++;\n\t\t\tcontinue;\n\t\t}\n\t\tlocations.push({\n\t\t\tpath: formatPathRelativeToCwdOrAbsolute(absolutePath, cwd),\n\t\t\trange: toOneBasedRange(parsed.range),\n\t\t});\n\t}\n\treturn { locations, omitted };\n}\n\nfunction compareLocations(a: LspLocation, b: LspLocation): number {\n\tif (a.path !== b.path) return a.path < b.path ? -1 : 1;\n\tif (a.range.start.line !== b.range.start.line) return a.range.start.line - b.range.start.line;\n\tif (a.range.start.character !== b.range.start.character) return a.range.start.character - b.range.start.character;\n\tif (a.range.end.line !== b.range.end.line) return a.range.end.line - b.range.end.line;\n\treturn a.range.end.character - b.range.end.character;\n}\n\nfunction dedupeSortAndCap(locations: LspLocation[], max: number): { locations: LspLocation[]; truncated: number } {\n\tconst seen = new Set<string>();\n\tconst unique: LspLocation[] = [];\n\tfor (const location of locations) {\n\t\tconst key = JSON.stringify(location);\n\t\tif (seen.has(key)) continue;\n\t\tseen.add(key);\n\t\tunique.push(location);\n\t}\n\tunique.sort(compareLocations);\n\tconst capped = unique.slice(0, max);\n\treturn { locations: capped, truncated: unique.length - capped.length };\n}\n\nfunction isRawDocumentSymbol(value: unknown): value is Record<string, unknown> {\n\treturn isRecord(value) && typeof value.name === \"string\" && isRange(value.range) && isRange(value.selectionRange);\n}\n\nfunction flattenSymbols(raw: unknown, path: string): { symbols: LspSymbol[]; omitted: number } {\n\tconst symbols: LspSymbol[] = [];\n\tlet omitted = 0;\n\tconst visit = (value: unknown): void => {\n\t\tif (!Array.isArray(value)) return;\n\t\tfor (const item of value) {\n\t\t\tif (!isRawDocumentSymbol(item)) {\n\t\t\t\tomitted++;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tsymbols.push({\n\t\t\t\tname: item.name as string,\n\t\t\t\tkind: typeof item.kind === \"number\" ? item.kind : 0,\n\t\t\t\tpath,\n\t\t\t\trange: toOneBasedRange(item.range as LspRange),\n\t\t\t\tselectionRange: toOneBasedRange(item.selectionRange as LspRange),\n\t\t\t\t...(typeof item.detail === \"string\" ? { detail: item.detail } : {}),\n\t\t\t});\n\t\t\tif (Array.isArray(item.children)) visit(item.children);\n\t\t}\n\t};\n\tvisit(Array.isArray(raw) ? raw : []);\n\treturn { symbols, omitted };\n}\n\nfunction compareSymbols(a: LspSymbol, b: LspSymbol): number {\n\tif (a.range.start.line !== b.range.start.line) return a.range.start.line - b.range.start.line;\n\tif (a.range.start.character !== b.range.start.character) return a.range.start.character - b.range.start.character;\n\treturn a.name === b.name ? 0 : a.name < b.name ? -1 : 1;\n}\n\nfunction capSymbols(symbols: LspSymbol[], max: number): { symbols: LspSymbol[]; truncated: number } {\n\tconst sorted = [...symbols].sort(compareSymbols);\n\tconst capped = sorted.slice(0, max);\n\treturn { symbols: capped, truncated: sorted.length - capped.length };\n}\n\nfunction isInsideRoot(absolutePath: string, root: string): boolean {\n\tconst rel = relative(root, absolutePath);\n\treturn rel === \"\" || (!rel.startsWith(\"..\") && !isAbsolute(rel));\n}\n\nfunction rawWorkspaceSymbol(value: unknown): { name: string; kind: number; containerName?: string } | undefined {\n\tif (!isRecord(value) || typeof value.name !== \"string\") return undefined;\n\treturn {\n\t\tname: value.name,\n\t\tkind: typeof value.kind === \"number\" ? value.kind : 0,\n\t\t...(typeof value.containerName === \"string\" ? { containerName: value.containerName } : {}),\n\t};\n}\n\n/**\n * Normalize `workspace/symbol` SymbolInformation results: file URIs to\n * workspace-relative paths, zero-based ranges to one-based, and every result\n * outside the authorized root dropped with an honest count (spec § 4: the\n * root is never widened because a result points outside it).\n */\nfunction normalizeWorkspaceSymbols(\n\traw: unknown,\n\tcwd: string,\n): { symbols: LspWorkspaceSymbol[]; omitted: number; outsideRoot: number } {\n\tconst items = Array.isArray(raw) ? raw : raw === undefined || raw === null ? [] : [raw];\n\tconst symbols: LspWorkspaceSymbol[] = [];\n\tlet omitted = 0;\n\tlet outsideRoot = 0;\n\tfor (const item of items) {\n\t\tconst parsed = rawLocationUriAndRange(isRecord(item) ? (item.location ?? item) : undefined);\n\t\tconst absolutePath = parsed ? fileUriToAbsolutePath(parsed.uri) : undefined;\n\t\tconst info = rawWorkspaceSymbol(item);\n\t\tif (!parsed || !absolutePath || !info) {\n\t\t\tomitted++;\n\t\t\tcontinue;\n\t\t}\n\t\tif (!isInsideRoot(absolutePath, cwd)) {\n\t\t\toutsideRoot++;\n\t\t\tcontinue;\n\t\t}\n\t\tsymbols.push({\n\t\t\t...info,\n\t\t\tpath: formatPathRelativeToCwdOrAbsolute(absolutePath, cwd),\n\t\t\trange: toOneBasedRange(parsed.range),\n\t\t});\n\t}\n\treturn { symbols, omitted, outsideRoot };\n}\n\nfunction compareWorkspaceSymbols(a: LspWorkspaceSymbol, b: LspWorkspaceSymbol): number {\n\tif (a.path !== b.path) return a.path < b.path ? -1 : 1;\n\tif (a.range.start.line !== b.range.start.line) return a.range.start.line - b.range.start.line;\n\treturn a.name === b.name ? 0 : a.name < b.name ? -1 : 1;\n}\n\nfunction capWorkspaceSymbolsByCount(\n\tsymbols: LspWorkspaceSymbol[],\n\tmax: number,\n): { symbols: LspWorkspaceSymbol[]; truncated: number } {\n\tconst sorted = [...symbols].sort(compareWorkspaceSymbols);\n\tconst capped = sorted.slice(0, max);\n\treturn { symbols: capped, truncated: sorted.length - capped.length };\n}\n\nfunction capWorkspaceSymbolsByBytes(\n\tsymbols: LspWorkspaceSymbol[],\n\tmaxBytes: number,\n): { symbols: LspWorkspaceSymbol[]; truncated: number } {\n\tlet used = 2; // \"[]\"\n\tfor (let i = 0; i < symbols.length; i++) {\n\t\tconst cost = Buffer.byteLength(JSON.stringify(symbols[i]), \"utf-8\") + 1;\n\t\tif (used + cost > maxBytes) {\n\t\t\treturn { symbols: symbols.slice(0, i), truncated: symbols.length - i };\n\t\t}\n\t\tused += cost;\n\t}\n\treturn { symbols, truncated: 0 };\n}\n\nfunction isUnsupportedMethodError(error: unknown): boolean {\n\tconst message = error instanceof Error ? error.message : String(error);\n\treturn message.includes(\"-32601\") || /method not found/i.test(message);\n}\n\nfunction formatWorkspaceSymbolsNotices(omitted: number, truncated: number, outsideRoot: number): string {\n\tconst notices: string[] = [];\n\tif (omitted > 0) notices.push(`${omitted} non-file result(s) omitted`);\n\tif (outsideRoot > 0) notices.push(`${outsideRoot} result(s) outside the workspace root omitted`);\n\tif (truncated > 0) notices.push(`${truncated} result(s) truncated`);\n\treturn notices.length > 0 ? `\\n\\n[${notices.join(\", \")}]` : \"\";\n}\n\nfunction formatWorkspaceSymbolsText(\n\tsymbols: LspWorkspaceSymbol[],\n\tomitted: number,\n\ttruncated: number,\n\toutsideRoot: number,\n): string {\n\tif (symbols.length === 0) {\n\t\tconst base = \"No symbols found.\";\n\t\tconst notices = formatWorkspaceSymbolsNotices(omitted, truncated, outsideRoot);\n\t\treturn notices ? `${base}${notices}` : base;\n\t}\n\tconst lines = symbols.map(\n\t\t(symbol) => `${symbol.path}:${symbol.range.start.line}:${symbol.range.start.character} ${symbol.name}`,\n\t);\n\treturn `${lines.join(\"\\n\")}${formatWorkspaceSymbolsNotices(omitted, truncated, outsideRoot)}`;\n}\n\nfunction formatNotices(omitted: number, truncated: number): string {\n\tconst notices: string[] = [];\n\tif (omitted > 0) notices.push(`${omitted} non-file result(s) omitted`);\n\tif (truncated > 0) notices.push(`${truncated} result(s) truncated`);\n\treturn notices.length > 0 ? `\\n\\n[${notices.join(\", \")}]` : \"\";\n}\n\nfunction formatLocationsText(\n\toperation: \"definition\" | \"references\",\n\tlocations: LspLocation[],\n\tomitted: number,\n\ttruncated: number,\n): string {\n\tif (locations.length === 0) {\n\t\treturn operation === \"definition\" ? \"No definition found.\" : \"No references found.\";\n\t}\n\tconst lines = locations.map(\n\t\t(location) => `${location.path}:${location.range.start.line}:${location.range.start.character}`,\n\t);\n\treturn `${lines.join(\"\\n\")}${formatNotices(omitted, truncated)}`;\n}\n\nfunction formatSymbolsText(symbols: LspSymbol[], omitted: number, truncated: number): string {\n\tif (symbols.length === 0) return \"No symbols found.\";\n\tconst lines = symbols.map(\n\t\t(symbol) => `${symbol.path}:${symbol.range.start.line}:${symbol.range.start.character} ${symbol.name}`,\n\t);\n\treturn `${lines.join(\"\\n\")}${formatNotices(omitted, truncated)}`;\n}\n\nexport function createLspToolDefinition(\n\tcwd: string,\n\toptions: LspToolOptions,\n): ApexToolDefinition<typeof lspSchema, LspToolDetails> {\n\tconst { operations } = options;\n\treturn {\n\t\tname: \"lsp\",\n\t\tlabel: \"lsp\",\n\t\tdescription: \"Query the configured language server for definitions, references, or symbols.\",\n\t\tparameters: lspSchema,\n\t\tcontract: {\n\t\t\t// `grep` spawns `rg` and declares {fs.read}, not {exec}, because the caller\n\t\t\t// never chooses what runs -- the executable, args, and closed JSON-RPC\n\t\t\t// method set all come from settings.json / this tool's own code. Same\n\t\t\t// reasoning here: {exec} would silently widen a delegation ceiling for no\n\t\t\t// capability the model can actually reach through this tool.\n\t\t\tcapabilities: new Set([\"fs.read\"]),\n\t\t\tpermission: createPathPermissionSpec({\n\t\t\t\tcwd,\n\t\t\t\tdefaultBehavior: \"allow\",\n\t\t\t\tverb: \"Query\",\n\t\t\t\t// A workspace_symbol call has no path; returning undefined normalizes to\n\t\t\t\t// the workspace root, so the same gate authorizes the root before the\n\t\t\t\t// request is sent and `ruleForCall` stays inside one grammar.\n\t\t\t\tgetPath: (params) => (\"path\" in params ? params.path : undefined),\n\t\t\t}),\n\t\t\tcontext: { resultRecoverable: true, deferSchema: true },\n\t\t\tevidence: { emits: new Set(), capture: () => [] },\n\t\t},\n\t\tasync execute(_toolCallId, input: LspToolInput, signal?: AbortSignal) {\n\t\t\tif (input.operation === \"workspace_symbol\") {\n\t\t\t\t// The permission gate has already authorized the workspace root by the\n\t\t\t\t// time execute runs; only now does the request go out.\n\t\t\t\ttry {\n\t\t\t\t\tconst raw = await operations.request(cwd, \"workspace/symbol\", { query: input.query }, signal);\n\t\t\t\t\tconst { symbols, omitted, outsideRoot } = normalizeWorkspaceSymbols(raw, cwd);\n\t\t\t\t\tconst { symbols: countCapped, truncated: countTruncated } = capWorkspaceSymbolsByCount(\n\t\t\t\t\t\tsymbols,\n\t\t\t\t\t\tMAX_SYMBOLS,\n\t\t\t\t\t);\n\t\t\t\t\tconst { symbols: capped, truncated: byteTruncated } = capWorkspaceSymbolsByBytes(\n\t\t\t\t\t\tcountCapped,\n\t\t\t\t\t\tMAX_DETAILS_BYTES,\n\t\t\t\t\t);\n\t\t\t\t\tconst truncated = countTruncated + byteTruncated;\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontent: [\n\t\t\t\t\t\t\t{ type: \"text\", text: formatWorkspaceSymbolsText(capped, omitted, truncated, outsideRoot) },\n\t\t\t\t\t\t],\n\t\t\t\t\t\tdetails: { operation: \"workspace_symbol\", symbols: capped, omitted, truncated, outsideRoot },\n\t\t\t\t\t};\n\t\t\t\t} catch (error) {\n\t\t\t\t\tif (isUnsupportedMethodError(error)) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tcontent: [\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\ttype: \"text\",\n\t\t\t\t\t\t\t\t\ttext: \"workspace_symbol is not supported by the configured language server.\",\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\tdetails: {\n\t\t\t\t\t\t\t\toperation: \"workspace_symbol\",\n\t\t\t\t\t\t\t\tsymbols: [],\n\t\t\t\t\t\t\t\tomitted: 0,\n\t\t\t\t\t\t\t\ttruncated: 0,\n\t\t\t\t\t\t\t\toutsideRoot: 0,\n\t\t\t\t\t\t\t\tunsupported: true,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst absolutePath = resolveToCwd(input.path, cwd);\n\t\t\tconst uri = pathToFileURL(absolutePath).href;\n\n\t\t\tif (input.operation === \"document_symbols\") {\n\t\t\t\tconst raw = await operations.request(\n\t\t\t\t\tabsolutePath,\n\t\t\t\t\t\"textDocument/documentSymbol\",\n\t\t\t\t\t{ textDocument: { uri } },\n\t\t\t\t\tsignal,\n\t\t\t\t);\n\t\t\t\tconst relativePath = formatPathRelativeToCwdOrAbsolute(absolutePath, cwd);\n\t\t\t\tconst { symbols, omitted } = flattenSymbols(raw, relativePath);\n\t\t\t\tconst { symbols: capped, truncated } = capSymbols(symbols, MAX_SYMBOLS);\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\", text: formatSymbolsText(capped, omitted, truncated) }],\n\t\t\t\t\tdetails: { operation: \"document_symbols\", symbols: capped, omitted, truncated },\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst position = { line: input.line - 1, character: input.character - 1 };\n\t\t\tconst method = input.operation === \"definition\" ? \"textDocument/definition\" : \"textDocument/references\";\n\t\t\tconst params: Record<string, unknown> = { textDocument: { uri }, position };\n\t\t\tif (input.operation === \"references\") params.context = { includeDeclaration: true };\n\t\t\tconst raw = await operations.request(absolutePath, method, params, signal);\n\t\t\tconst { locations, omitted } = normalizeLocations(raw, cwd);\n\t\t\tconst { locations: capped, truncated } = dedupeSortAndCap(locations, MAX_LOCATIONS);\n\t\t\treturn {\n\t\t\t\tcontent: [{ type: \"text\", text: formatLocationsText(input.operation, capped, omitted, truncated) }],\n\t\t\t\tdetails: { operation: input.operation, locations: capped, omitted, truncated },\n\t\t\t};\n\t\t},\n\t};\n}\n\nexport function createLspTool(cwd: string, options: LspToolOptions): AgentTool<typeof lspSchema> {\n\treturn wrapToolDefinition(createLspToolDefinition(cwd, options));\n}\n"]}
@@ -1,5 +1,6 @@
1
1
  /** Shared PermissionSpec construction for the path-shaped tools (read, grep, find, ls, write, edit). */
2
2
  import type { Static, TSchema } from "typebox";
3
+ import type { PermissionPreview } from "../permissions/responder.ts";
3
4
  import type { PermissionBehavior, PermissionSpec } from "./contract.ts";
4
5
  /**
5
6
  * Builds a glob-based PermissionSpec over a single path field. `getPath` extracts
@@ -14,5 +15,7 @@ export declare function createPathPermissionSpec<TParams extends TSchema>(option
14
15
  defaultBehavior: PermissionBehavior;
15
16
  verb: string;
16
17
  getPath: (params: Static<TParams>) => string | undefined;
18
+ /** Describes the change for a human about to approve it. See PermissionSpec.previewCall. */
19
+ previewCall?: (params: Static<TParams>) => PermissionPreview;
17
20
  }): PermissionSpec<TParams>;
18
21
  //# sourceMappingURL=path-permission.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"path-permission.d.ts","sourceRoot":"","sources":["../../../src/core/tools/path-permission.ts"],"names":[],"mappings":"AAAA,wGAAwG;AAGxG,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAE/C,OAAO,KAAK,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAExE;;;;;;;GAOG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,SAAS,OAAO,EAAE,OAAO,EAAE;IAC1E,GAAG,EAAE,MAAM,CAAC;IACZ,eAAe,EAAE,kBAAkB,CAAC;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,KAAK,MAAM,GAAG,SAAS,CAAC;CACzD,GAAG,cAAc,CAAC,OAAO,CAAC,CAkB1B","sourcesContent":["/** Shared PermissionSpec construction for the path-shaped tools (read, grep, find, ls, write, edit). */\n\nimport { minimatch } from \"minimatch\";\nimport type { Static, TSchema } from \"typebox\";\nimport { formatPathRelativeToCwdOrAbsolute } from \"../../utils/paths.ts\";\nimport type { PermissionBehavior, PermissionSpec } from \"./contract.ts\";\n\n/**\n * Builds a glob-based PermissionSpec over a single path field. `getPath` extracts\n * the workspace path a call touches (returning undefined defaults to the tool's own\n * cwd-relative root, e.g. `ls` with no `path` argument). Rule content is a\n * cwd-relative glob; `ruleForCall` returns the exact normalized path of the call, so\n * \"always allow this\" authorizes only that path — never a pattern the tool did not\n * generate itself.\n */\nexport function createPathPermissionSpec<TParams extends TSchema>(options: {\n\tcwd: string;\n\tdefaultBehavior: PermissionBehavior;\n\tverb: string;\n\tgetPath: (params: Static<TParams>) => string | undefined;\n}): PermissionSpec<TParams> {\n\tconst { cwd, defaultBehavior, verb, getPath } = options;\n\n\tconst normalize = (path: string | undefined): string =>\n\t\tformatPathRelativeToCwdOrAbsolute(path?.trim() ? path : \".\", cwd);\n\n\treturn {\n\t\tdefaultBehavior,\n\t\tmatches(ruleContent, params) {\n\t\t\treturn minimatch(normalize(getPath(params)), ruleContent, { dot: true });\n\t\t},\n\t\tdescribe(ruleContent) {\n\t\t\treturn `${verb} paths matching \"${ruleContent}\"`;\n\t\t},\n\t\truleForCall(params) {\n\t\t\treturn normalize(getPath(params));\n\t\t},\n\t};\n}\n"]}
1
+ {"version":3,"file":"path-permission.d.ts","sourceRoot":"","sources":["../../../src/core/tools/path-permission.ts"],"names":[],"mappings":"AAAA,wGAAwG;AAGxG,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAG/C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,KAAK,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAGxE;;;;;;;GAOG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,SAAS,OAAO,EAAE,OAAO,EAAE;IAC1E,GAAG,EAAE,MAAM,CAAC;IACZ,eAAe,EAAE,kBAAkB,CAAC;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,KAAK,MAAM,GAAG,SAAS,CAAC;IACzD,4FAA4F;IAC5F,WAAW,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,KAAK,iBAAiB,CAAC;CAC7D,GAAG,cAAc,CAAC,OAAO,CAAC,CA2B1B","sourcesContent":["/** Shared PermissionSpec construction for the path-shaped tools (read, grep, find, ls, write, edit). */\n\nimport { minimatch } from \"minimatch\";\nimport type { Static, TSchema } from \"typebox\";\nimport { formatPathRelativeToCwdOrAbsolute } from \"../../utils/paths.ts\";\nimport { setPreparedPathOperation } from \"../permissions/operations.ts\";\nimport type { PermissionPreview } from \"../permissions/responder.ts\";\nimport type { PermissionBehavior, PermissionSpec } from \"./contract.ts\";\nimport { preparePathOperation, resolveToCwd } from \"./path-utils.ts\";\n\n/**\n * Builds a glob-based PermissionSpec over a single path field. `getPath` extracts\n * the workspace path a call touches (returning undefined defaults to the tool's own\n * cwd-relative root, e.g. `ls` with no `path` argument). Rule content is a\n * cwd-relative glob; `ruleForCall` returns the exact normalized path of the call, so\n * \"always allow this\" authorizes only that path — never a pattern the tool did not\n * generate itself.\n */\nexport function createPathPermissionSpec<TParams extends TSchema>(options: {\n\tcwd: string;\n\tdefaultBehavior: PermissionBehavior;\n\tverb: string;\n\tgetPath: (params: Static<TParams>) => string | undefined;\n\t/** Describes the change for a human about to approve it. See PermissionSpec.previewCall. */\n\tpreviewCall?: (params: Static<TParams>) => PermissionPreview;\n}): PermissionSpec<TParams> {\n\tconst { cwd, defaultBehavior, verb, getPath, previewCall } = options;\n\n\tconst normalize = (path: string | undefined): string => {\n\t\tconst canonical = resolveToCwd(path?.trim() ? path : \".\", cwd);\n\t\treturn formatPathRelativeToCwdOrAbsolute(canonical, cwd);\n\t};\n\tconst escapeExact = (value: string): string => `exact:${value}`;\n\n\treturn {\n\t\tdefaultBehavior,\n\t\tprepareCall(params) {\n\t\t\tsetPreparedPathOperation(params as object, preparePathOperation(getPath(params) ?? \".\", cwd));\n\t\t},\n\t\t...(previewCall ? { previewCall } : {}),\n\t\tmatches(ruleContent, params) {\n\t\t\treturn ruleContent.startsWith(\"exact:\")\n\t\t\t\t? normalize(getPath(params)) === ruleContent.slice(\"exact:\".length)\n\t\t\t\t: minimatch(normalize(getPath(params)), ruleContent, { dot: true });\n\t\t},\n\t\tdescribe(ruleContent) {\n\t\t\treturn `${verb} paths matching \"${ruleContent}\"`;\n\t\t},\n\t\truleForCall(params) {\n\t\t\treturn escapeExact(normalize(getPath(params)));\n\t\t},\n\t};\n}\n"]}
@@ -1,6 +1,8 @@
1
1
  /** Shared PermissionSpec construction for the path-shaped tools (read, grep, find, ls, write, edit). */
2
2
  import { minimatch } from "minimatch";
3
3
  import { formatPathRelativeToCwdOrAbsolute } from "../../utils/paths.js";
4
+ import { setPreparedPathOperation } from "../permissions/operations.js";
5
+ import { preparePathOperation, resolveToCwd } from "./path-utils.js";
4
6
  /**
5
7
  * Builds a glob-based PermissionSpec over a single path field. `getPath` extracts
6
8
  * the workspace path a call touches (returning undefined defaults to the tool's own
@@ -10,18 +12,28 @@ import { formatPathRelativeToCwdOrAbsolute } from "../../utils/paths.js";
10
12
  * generate itself.
11
13
  */
12
14
  export function createPathPermissionSpec(options) {
13
- const { cwd, defaultBehavior, verb, getPath } = options;
14
- const normalize = (path) => formatPathRelativeToCwdOrAbsolute(path?.trim() ? path : ".", cwd);
15
+ const { cwd, defaultBehavior, verb, getPath, previewCall } = options;
16
+ const normalize = (path) => {
17
+ const canonical = resolveToCwd(path?.trim() ? path : ".", cwd);
18
+ return formatPathRelativeToCwdOrAbsolute(canonical, cwd);
19
+ };
20
+ const escapeExact = (value) => `exact:${value}`;
15
21
  return {
16
22
  defaultBehavior,
23
+ prepareCall(params) {
24
+ setPreparedPathOperation(params, preparePathOperation(getPath(params) ?? ".", cwd));
25
+ },
26
+ ...(previewCall ? { previewCall } : {}),
17
27
  matches(ruleContent, params) {
18
- return minimatch(normalize(getPath(params)), ruleContent, { dot: true });
28
+ return ruleContent.startsWith("exact:")
29
+ ? normalize(getPath(params)) === ruleContent.slice("exact:".length)
30
+ : minimatch(normalize(getPath(params)), ruleContent, { dot: true });
19
31
  },
20
32
  describe(ruleContent) {
21
33
  return `${verb} paths matching "${ruleContent}"`;
22
34
  },
23
35
  ruleForCall(params) {
24
- return normalize(getPath(params));
36
+ return escapeExact(normalize(getPath(params)));
25
37
  },
26
38
  };
27
39
  }
@@ -1 +1 @@
1
- {"version":3,"file":"path-permission.js","sourceRoot":"","sources":["../../../src/core/tools/path-permission.ts"],"names":[],"mappings":"AAAA,wGAAwG;AAExG,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,OAAO,EAAE,iCAAiC,EAAE,MAAM,sBAAsB,CAAC;AAGzE;;;;;;;GAOG;AACH,MAAM,UAAU,wBAAwB,CAA0B,OAKjE,EAA2B;IAC3B,MAAM,EAAE,GAAG,EAAE,eAAe,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;IAExD,MAAM,SAAS,GAAG,CAAC,IAAwB,EAAU,EAAE,CACtD,iCAAiC,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IAEnE,OAAO;QACN,eAAe;QACf,OAAO,CAAC,WAAW,EAAE,MAAM,EAAE;YAC5B,OAAO,SAAS,CAAC,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,WAAW,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC;QAAA,CACzE;QACD,QAAQ,CAAC,WAAW,EAAE;YACrB,OAAO,GAAG,IAAI,oBAAoB,WAAW,GAAG,CAAC;QAAA,CACjD;QACD,WAAW,CAAC,MAAM,EAAE;YACnB,OAAO,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;QAAA,CAClC;KACD,CAAC;AAAA,CACF","sourcesContent":["/** Shared PermissionSpec construction for the path-shaped tools (read, grep, find, ls, write, edit). */\n\nimport { minimatch } from \"minimatch\";\nimport type { Static, TSchema } from \"typebox\";\nimport { formatPathRelativeToCwdOrAbsolute } from \"../../utils/paths.ts\";\nimport type { PermissionBehavior, PermissionSpec } from \"./contract.ts\";\n\n/**\n * Builds a glob-based PermissionSpec over a single path field. `getPath` extracts\n * the workspace path a call touches (returning undefined defaults to the tool's own\n * cwd-relative root, e.g. `ls` with no `path` argument). Rule content is a\n * cwd-relative glob; `ruleForCall` returns the exact normalized path of the call, so\n * \"always allow this\" authorizes only that path — never a pattern the tool did not\n * generate itself.\n */\nexport function createPathPermissionSpec<TParams extends TSchema>(options: {\n\tcwd: string;\n\tdefaultBehavior: PermissionBehavior;\n\tverb: string;\n\tgetPath: (params: Static<TParams>) => string | undefined;\n}): PermissionSpec<TParams> {\n\tconst { cwd, defaultBehavior, verb, getPath } = options;\n\n\tconst normalize = (path: string | undefined): string =>\n\t\tformatPathRelativeToCwdOrAbsolute(path?.trim() ? path : \".\", cwd);\n\n\treturn {\n\t\tdefaultBehavior,\n\t\tmatches(ruleContent, params) {\n\t\t\treturn minimatch(normalize(getPath(params)), ruleContent, { dot: true });\n\t\t},\n\t\tdescribe(ruleContent) {\n\t\t\treturn `${verb} paths matching \"${ruleContent}\"`;\n\t\t},\n\t\truleForCall(params) {\n\t\t\treturn normalize(getPath(params));\n\t\t},\n\t};\n}\n"]}
1
+ {"version":3,"file":"path-permission.js","sourceRoot":"","sources":["../../../src/core/tools/path-permission.ts"],"names":[],"mappings":"AAAA,wGAAwG;AAExG,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,OAAO,EAAE,iCAAiC,EAAE,MAAM,sBAAsB,CAAC;AACzE,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AAGxE,OAAO,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAErE;;;;;;;GAOG;AACH,MAAM,UAAU,wBAAwB,CAA0B,OAOjE,EAA2B;IAC3B,MAAM,EAAE,GAAG,EAAE,eAAe,EAAE,IAAI,EAAE,OAAO,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC;IAErE,MAAM,SAAS,GAAG,CAAC,IAAwB,EAAU,EAAE,CAAC;QACvD,MAAM,SAAS,GAAG,YAAY,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QAC/D,OAAO,iCAAiC,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC;IAAA,CACzD,CAAC;IACF,MAAM,WAAW,GAAG,CAAC,KAAa,EAAU,EAAE,CAAC,SAAS,KAAK,EAAE,CAAC;IAEhE,OAAO;QACN,eAAe;QACf,WAAW,CAAC,MAAM,EAAE;YACnB,wBAAwB,CAAC,MAAgB,EAAE,oBAAoB,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;QAAA,CAC9F;QACD,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACvC,OAAO,CAAC,WAAW,EAAE,MAAM,EAAE;YAC5B,OAAO,WAAW,CAAC,UAAU,CAAC,QAAQ,CAAC;gBACtC,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,KAAK,WAAW,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC;gBACnE,CAAC,CAAC,SAAS,CAAC,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,WAAW,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC;QAAA,CACrE;QACD,QAAQ,CAAC,WAAW,EAAE;YACrB,OAAO,GAAG,IAAI,oBAAoB,WAAW,GAAG,CAAC;QAAA,CACjD;QACD,WAAW,CAAC,MAAM,EAAE;YACnB,OAAO,WAAW,CAAC,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QAAA,CAC/C;KACD,CAAC;AAAA,CACF","sourcesContent":["/** Shared PermissionSpec construction for the path-shaped tools (read, grep, find, ls, write, edit). */\n\nimport { minimatch } from \"minimatch\";\nimport type { Static, TSchema } from \"typebox\";\nimport { formatPathRelativeToCwdOrAbsolute } from \"../../utils/paths.ts\";\nimport { setPreparedPathOperation } from \"../permissions/operations.ts\";\nimport type { PermissionPreview } from \"../permissions/responder.ts\";\nimport type { PermissionBehavior, PermissionSpec } from \"./contract.ts\";\nimport { preparePathOperation, resolveToCwd } from \"./path-utils.ts\";\n\n/**\n * Builds a glob-based PermissionSpec over a single path field. `getPath` extracts\n * the workspace path a call touches (returning undefined defaults to the tool's own\n * cwd-relative root, e.g. `ls` with no `path` argument). Rule content is a\n * cwd-relative glob; `ruleForCall` returns the exact normalized path of the call, so\n * \"always allow this\" authorizes only that path — never a pattern the tool did not\n * generate itself.\n */\nexport function createPathPermissionSpec<TParams extends TSchema>(options: {\n\tcwd: string;\n\tdefaultBehavior: PermissionBehavior;\n\tverb: string;\n\tgetPath: (params: Static<TParams>) => string | undefined;\n\t/** Describes the change for a human about to approve it. See PermissionSpec.previewCall. */\n\tpreviewCall?: (params: Static<TParams>) => PermissionPreview;\n}): PermissionSpec<TParams> {\n\tconst { cwd, defaultBehavior, verb, getPath, previewCall } = options;\n\n\tconst normalize = (path: string | undefined): string => {\n\t\tconst canonical = resolveToCwd(path?.trim() ? path : \".\", cwd);\n\t\treturn formatPathRelativeToCwdOrAbsolute(canonical, cwd);\n\t};\n\tconst escapeExact = (value: string): string => `exact:${value}`;\n\n\treturn {\n\t\tdefaultBehavior,\n\t\tprepareCall(params) {\n\t\t\tsetPreparedPathOperation(params as object, preparePathOperation(getPath(params) ?? \".\", cwd));\n\t\t},\n\t\t...(previewCall ? { previewCall } : {}),\n\t\tmatches(ruleContent, params) {\n\t\t\treturn ruleContent.startsWith(\"exact:\")\n\t\t\t\t? normalize(getPath(params)) === ruleContent.slice(\"exact:\".length)\n\t\t\t\t: minimatch(normalize(getPath(params)), ruleContent, { dot: true });\n\t\t},\n\t\tdescribe(ruleContent) {\n\t\t\treturn `${verb} paths matching \"${ruleContent}\"`;\n\t\t},\n\t\truleForCall(params) {\n\t\t\treturn escapeExact(normalize(getPath(params)));\n\t\t},\n\t};\n}\n"]}
@@ -1,8 +1,33 @@
1
+ import type { PreparedPathOperation } from "../permissions/operations.ts";
2
+ export declare function preparePathOperation(filePath: string, cwd: string): PreparedPathOperation;
3
+ /**
4
+ * Read the authorized target through a no-follow final-component open, verifying
5
+ * the descriptor identity captured at authorization before any byte is returned.
6
+ * A replaced alias or an injected symlink never matches and the read aborts.
7
+ */
8
+ export declare function readPreparedPath(operation: PreparedPathOperation, maxBytes?: number): Buffer;
9
+ /** The authorized target changed between permission evaluation and execution. */
10
+ export declare class PreparedTargetChangedError extends Error {
11
+ }
12
+ /**
13
+ * Execute an authorized write against the prepared target.
14
+ *
15
+ * - `path-existing`: the final component is opened `O_NOFOLLOW`, its descriptor
16
+ * identity is compared with the identity captured at authorization, and only
17
+ * then is the file truncated and written through that descriptor. A swapped
18
+ * alias, an injected symlink, or a redirected parent never matches and the
19
+ * write aborts before any byte changes.
20
+ * - `path-new`: missing parents are created no-follow under the walked directory
21
+ * descriptor, and the file is created `O_CREAT | O_EXCL | O_NOFOLLOW`, so a
22
+ * replaced parent or a pre-placed symlink is never followed.
23
+ */
24
+ export declare function writePreparedPath(operation: PreparedPathOperation, content: string | Buffer): void;
1
25
  export declare function pathExists(filePath: string): Promise<boolean>;
2
26
  export declare function expandPath(filePath: string): string;
3
27
  /**
4
- * Resolve a path relative to the given cwd.
5
- * Handles ~ expansion and absolute paths.
28
+ * Resolve a path relative to the given cwd, handling ~ expansion and absolute
29
+ * paths. The result is the single target used by both permission matching and
30
+ * filesystem execution.
6
31
  */
7
32
  export declare function resolveToCwd(filePath: string, cwd: string): string;
8
33
  export declare function resolveReadPath(filePath: string, cwd: string): string;
@@ -1 +1 @@
1
- {"version":3,"file":"path-utils.d.ts","sourceRoot":"","sources":["../../../src/core/tools/path-utils.ts"],"names":[],"mappings":"AA8BA,wBAAsB,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAOnE;AAED,wBAAgB,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEnD;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAElE;AAED,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAgCrE;AAED,wBAAsB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAgCzF","sourcesContent":["import { accessSync, constants } from \"node:fs\";\nimport { access } from \"node:fs/promises\";\nimport { normalizePath, resolvePath } from \"../../utils/paths.ts\";\n\nconst NARROW_NO_BREAK_SPACE = \"\\u202F\";\n\nfunction tryMacOSScreenshotPath(filePath: string): string {\n\treturn filePath.replace(/ (AM|PM)\\./gi, `${NARROW_NO_BREAK_SPACE}$1.`);\n}\n\nfunction tryNFDVariant(filePath: string): string {\n\t// macOS stores filenames in NFD (decomposed) form, try converting user input to NFD\n\treturn filePath.normalize(\"NFD\");\n}\n\nfunction tryCurlyQuoteVariant(filePath: string): string {\n\t// macOS uses U+2019 (right single quotation mark) in screenshot names like \"Capture d'écran\"\n\t// Users typically type U+0027 (straight apostrophe)\n\treturn filePath.replace(/'/g, \"\\u2019\");\n}\n\nfunction fileExists(filePath: string): boolean {\n\ttry {\n\t\taccessSync(filePath, constants.F_OK);\n\t\treturn true;\n\t} catch {\n\t\treturn false;\n\t}\n}\n\nexport async function pathExists(filePath: string): Promise<boolean> {\n\ttry {\n\t\tawait access(filePath, constants.F_OK);\n\t\treturn true;\n\t} catch {\n\t\treturn false;\n\t}\n}\n\nexport function expandPath(filePath: string): string {\n\treturn normalizePath(filePath, { normalizeUnicodeSpaces: true, stripAtPrefix: true });\n}\n\n/**\n * Resolve a path relative to the given cwd.\n * Handles ~ expansion and absolute paths.\n */\nexport function resolveToCwd(filePath: string, cwd: string): string {\n\treturn resolvePath(filePath, cwd, { normalizeUnicodeSpaces: true, stripAtPrefix: true });\n}\n\nexport function resolveReadPath(filePath: string, cwd: string): string {\n\tconst resolved = resolveToCwd(filePath, cwd);\n\n\tif (fileExists(resolved)) {\n\t\treturn resolved;\n\t}\n\n\t// Try macOS AM/PM variant (narrow no-break space before AM/PM)\n\tconst amPmVariant = tryMacOSScreenshotPath(resolved);\n\tif (amPmVariant !== resolved && fileExists(amPmVariant)) {\n\t\treturn amPmVariant;\n\t}\n\n\t// Try NFD variant (macOS stores filenames in NFD form)\n\tconst nfdVariant = tryNFDVariant(resolved);\n\tif (nfdVariant !== resolved && fileExists(nfdVariant)) {\n\t\treturn nfdVariant;\n\t}\n\n\t// Try curly quote variant (macOS uses U+2019 in screenshot names)\n\tconst curlyVariant = tryCurlyQuoteVariant(resolved);\n\tif (curlyVariant !== resolved && fileExists(curlyVariant)) {\n\t\treturn curlyVariant;\n\t}\n\n\t// Try combined NFD + curly quote (for French macOS screenshots like \"Capture d'écran\")\n\tconst nfdCurlyVariant = tryCurlyQuoteVariant(nfdVariant);\n\tif (nfdCurlyVariant !== resolved && fileExists(nfdCurlyVariant)) {\n\t\treturn nfdCurlyVariant;\n\t}\n\n\treturn resolved;\n}\n\nexport async function resolveReadPathAsync(filePath: string, cwd: string): Promise<string> {\n\tconst resolved = resolveToCwd(filePath, cwd);\n\n\tif (await pathExists(resolved)) {\n\t\treturn resolved;\n\t}\n\n\t// Try macOS AM/PM variant (narrow no-break space before AM/PM)\n\tconst amPmVariant = tryMacOSScreenshotPath(resolved);\n\tif (amPmVariant !== resolved && (await pathExists(amPmVariant))) {\n\t\treturn amPmVariant;\n\t}\n\n\t// Try NFD variant (macOS stores filenames in NFD form)\n\tconst nfdVariant = tryNFDVariant(resolved);\n\tif (nfdVariant !== resolved && (await pathExists(nfdVariant))) {\n\t\treturn nfdVariant;\n\t}\n\n\t// Try curly quote variant (macOS uses U+2019 in screenshot names)\n\tconst curlyVariant = tryCurlyQuoteVariant(resolved);\n\tif (curlyVariant !== resolved && (await pathExists(curlyVariant))) {\n\t\treturn curlyVariant;\n\t}\n\n\t// Try combined NFD + curly quote (for French macOS screenshots like \"Capture d'écran\")\n\tconst nfdCurlyVariant = tryCurlyQuoteVariant(nfdVariant);\n\tif (nfdCurlyVariant !== resolved && (await pathExists(nfdCurlyVariant))) {\n\t\treturn nfdCurlyVariant;\n\t}\n\n\treturn resolved;\n}\n"]}
1
+ {"version":3,"file":"path-utils.d.ts","sourceRoot":"","sources":["../../../src/core/tools/path-utils.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAI1E,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,qBAAqB,CAazF;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,qBAAqB,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CA6B5F;AAED,iFAAiF;AACjF,qBAAa,0BAA2B,SAAQ,KAAK;CAAG;AA2GxD;;;;;;;;;;;GAWG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,qBAAqB,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAsClG;AA0BD,wBAAsB,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAOnE;AAED,wBAAgB,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEnD;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAWlE;AAMD,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAgCrE;AAED,wBAAsB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAgCzF","sourcesContent":["import {\n\taccessSync,\n\tcloseSync,\n\tconstants,\n\texistsSync,\n\tfstatSync,\n\tftruncateSync,\n\tmkdirSync,\n\topenSync,\n\treadSync,\n\trealpathSync,\n\tstatSync,\n\twriteSync,\n} from \"node:fs\";\nimport { access } from \"node:fs/promises\";\nimport { basename, dirname, isAbsolute, join, parse, sep } from \"node:path\";\nimport { normalizePath, resolvePath } from \"../../utils/paths.ts\";\nimport type { PreparedPathOperation } from \"../permissions/operations.ts\";\n\nconst NARROW_NO_BREAK_SPACE = \"\\u202F\";\n\nexport function preparePathOperation(filePath: string, cwd: string): PreparedPathOperation {\n\tconst canonicalPath = resolveToCwd(filePath, cwd);\n\tif (!isAbsolute(canonicalPath)) throw new Error(\"Canonical path must be absolute\");\n\ttry {\n\t\tconst stats = statSync(canonicalPath);\n\t\treturn {\n\t\t\tkind: \"path-existing\",\n\t\t\tpath: { kind: \"canonical-path\", value: canonicalPath },\n\t\t\tidentity: { device: stats.dev, inode: stats.ino },\n\t\t};\n\t} catch {\n\t\treturn { kind: \"path-new\", path: { kind: \"canonical-path\", value: canonicalPath } };\n\t}\n}\n\n/**\n * Read the authorized target through a no-follow final-component open, verifying\n * the descriptor identity captured at authorization before any byte is returned.\n * A replaced alias or an injected symlink never matches and the read aborts.\n */\nexport function readPreparedPath(operation: PreparedPathOperation, maxBytes?: number): Buffer {\n\tif (operation.kind !== \"path-existing\") {\n\t\tthrow new PreparedTargetChangedError(\"Authorized read target did not exist when permission was checked\");\n\t}\n\treturn withTargetDirectory(operation, { createMissingDirectories: false }, (parent, name) => {\n\t\tlet fd: number;\n\t\ttry {\n\t\t\tfd = openUnder(parent, name, constants.O_RDONLY | constants.O_NOFOLLOW);\n\t\t} catch (error) {\n\t\t\tthrow new PreparedTargetChangedError(\"Authorized read target changed before execution\", { cause: error });\n\t\t}\n\t\ttry {\n\t\t\tconst stats = fstatSync(fd);\n\t\t\tif (stats.dev !== operation.identity.device || stats.ino !== operation.identity.inode) {\n\t\t\t\tthrow new PreparedTargetChangedError(\"Authorized read target changed before execution\");\n\t\t\t}\n\t\t\tconst length = maxBytes === undefined ? stats.size : Math.min(stats.size, maxBytes);\n\t\t\tconst buffer = Buffer.alloc(length);\n\t\t\tlet offset = 0;\n\t\t\twhile (offset < buffer.length) {\n\t\t\t\tconst read = readSync(fd, buffer, offset, buffer.length - offset, null);\n\t\t\t\tif (read === 0) break;\n\t\t\t\toffset += read;\n\t\t\t}\n\t\t\treturn offset === buffer.length ? buffer : buffer.subarray(0, offset);\n\t\t} finally {\n\t\t\tcloseSync(fd);\n\t\t}\n\t});\n}\n\n/** The authorized target changed between permission evaluation and execution. */\nexport class PreparedTargetChangedError extends Error {}\n\nconst PROC_FD = \"/proc/self/fd\";\nlet procFdAvailable: boolean | undefined;\n\n/** /proc lets an already-open directory fd act as the parent of the next open, so a swapped intermediate directory cannot be traversed. */\nfunction useProcFd(): boolean {\n\tif (procFdAvailable === undefined) {\n\t\ttry {\n\t\t\tprocFdAvailable = existsSync(`${PROC_FD}/self`);\n\t\t} catch {\n\t\t\tprocFdAvailable = false;\n\t\t}\n\t}\n\treturn procFdAvailable;\n}\n\ninterface OpenDirectory {\n\tfd: number;\n\t/** Fallback parent path for platforms without /proc/self/fd. */\n\tpath: string;\n}\n\nfunction openUnder(parent: OpenDirectory, name: string, flags: number, mode?: number): number {\n\tif (useProcFd()) return openSync(`${PROC_FD}/${parent.fd}/${name}`, flags, mode);\n\treturn openSync(join(parent.path, name), flags, mode);\n}\n\nfunction mkdirUnder(parent: OpenDirectory, name: string): void {\n\tif (useProcFd()) mkdirSync(`${PROC_FD}/${parent.fd}/${name}`);\n\telse mkdirSync(join(parent.path, name));\n}\n\nfunction openChildDirectory(parent: OpenDirectory, name: string): OpenDirectory {\n\tconst flags = constants.O_RDONLY | constants.O_DIRECTORY | constants.O_NOFOLLOW;\n\tconst fd = openUnder(parent, name, flags);\n\tcloseSync(parent.fd);\n\treturn { fd, path: join(parent.path, name) };\n}\n\nfunction writeAll(fd: number, content: string | Buffer): void {\n\tconst buffer = typeof content === \"string\" ? Buffer.from(content, \"utf-8\") : content;\n\tlet written = 0;\n\twhile (written < buffer.length) {\n\t\twritten += writeSync(fd, buffer, written, buffer.length - written);\n\t}\n}\n\nfunction isMissingEntryError(error: unknown): boolean {\n\treturn (\n\t\ttypeof error === \"object\" && error !== null && \"code\" in error && (error as { code?: unknown }).code === \"ENOENT\"\n\t);\n}\n\n/**\n * Walk every directory component of the authorized path no-follow, holding one\n * directory fd across the walk, then run the caller's final-component step against\n * that walked parent. Any intermediate that is not a real directory — a swapped\n * symlink, a removed component — aborts before the target is touched.\n */\nfunction withTargetDirectory<T>(\n\toperation: PreparedPathOperation,\n\toptions: { createMissingDirectories: boolean },\n\trun: (parent: OpenDirectory, name: string) => T,\n): T {\n\tconst root = parse(operation.path.value).root;\n\tconst components = operation.path.value\n\t\t.slice(root.length)\n\t\t.split(sep)\n\t\t.filter((component) => component.length > 0);\n\tconst name = components[components.length - 1];\n\tif (name === undefined) throw new PreparedTargetChangedError(\"Authorized path has no final component\");\n\tlet parent: OpenDirectory = { fd: openSync(root, constants.O_RDONLY | constants.O_DIRECTORY), path: root };\n\tconst closeParent = (): void => {\n\t\ttry {\n\t\t\tcloseSync(parent.fd);\n\t\t} catch {}\n\t};\n\tfor (const component of components.slice(0, -1)) {\n\t\ttry {\n\t\t\tparent = openChildDirectory(parent, component);\n\t\t} catch (error) {\n\t\t\tif (options.createMissingDirectories && isMissingEntryError(error)) {\n\t\t\t\ttry {\n\t\t\t\t\tmkdirUnder(parent, component);\n\t\t\t\t\tparent = openChildDirectory(parent, component);\n\t\t\t\t\tcontinue;\n\t\t\t\t} catch (mkdirError) {\n\t\t\t\t\tcloseParent();\n\t\t\t\t\tthrow new PreparedTargetChangedError(`Authorized write parent \"${component}\" changed before execution`, {\n\t\t\t\t\t\tcause: mkdirError,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t\tcloseParent();\n\t\t\tthrow new PreparedTargetChangedError(`Authorized path component \"${component}\" changed before execution`, {\n\t\t\t\tcause: error,\n\t\t\t});\n\t\t}\n\t}\n\ttry {\n\t\treturn run(parent, name);\n\t} finally {\n\t\tcloseParent();\n\t}\n}\n\n/**\n * Execute an authorized write against the prepared target.\n *\n * - `path-existing`: the final component is opened `O_NOFOLLOW`, its descriptor\n * identity is compared with the identity captured at authorization, and only\n * then is the file truncated and written through that descriptor. A swapped\n * alias, an injected symlink, or a redirected parent never matches and the\n * write aborts before any byte changes.\n * - `path-new`: missing parents are created no-follow under the walked directory\n * descriptor, and the file is created `O_CREAT | O_EXCL | O_NOFOLLOW`, so a\n * replaced parent or a pre-placed symlink is never followed.\n */\nexport function writePreparedPath(operation: PreparedPathOperation, content: string | Buffer): void {\n\twithTargetDirectory(operation, { createMissingDirectories: operation.kind === \"path-new\" }, (parent, name) => {\n\t\tif (operation.kind === \"path-existing\") {\n\t\t\tlet fd: number;\n\t\t\ttry {\n\t\t\t\tfd = openUnder(parent, name, constants.O_WRONLY | constants.O_NOFOLLOW);\n\t\t\t} catch (error) {\n\t\t\t\tthrow new PreparedTargetChangedError(\"Authorized write target changed before execution\", { cause: error });\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tconst stats = fstatSync(fd);\n\t\t\t\tif (stats.dev !== operation.identity.device || stats.ino !== operation.identity.inode) {\n\t\t\t\t\tthrow new PreparedTargetChangedError(\"Authorized write target changed before execution\");\n\t\t\t\t}\n\t\t\t\tftruncateSync(fd, 0);\n\t\t\t\twriteAll(fd, content);\n\t\t\t} finally {\n\t\t\t\tcloseSync(fd);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tlet fd: number;\n\t\ttry {\n\t\t\tfd = openUnder(\n\t\t\t\tparent,\n\t\t\t\tname,\n\t\t\t\tconstants.O_WRONLY | constants.O_CREAT | constants.O_EXCL | constants.O_NOFOLLOW,\n\t\t\t\t0o600,\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tthrow new PreparedTargetChangedError(\"Authorized new-file target changed before execution\", { cause: error });\n\t\t}\n\t\ttry {\n\t\t\twriteAll(fd, content);\n\t\t} finally {\n\t\t\tcloseSync(fd);\n\t\t}\n\t});\n}\n\nfunction tryMacOSScreenshotPath(filePath: string): string {\n\treturn filePath.replace(/ (AM|PM)\\./gi, `${NARROW_NO_BREAK_SPACE}$1.`);\n}\n\nfunction tryNFDVariant(filePath: string): string {\n\t// macOS stores filenames in NFD (decomposed) form, try converting user input to NFD\n\treturn filePath.normalize(\"NFD\");\n}\n\nfunction tryCurlyQuoteVariant(filePath: string): string {\n\t// macOS uses U+2019 (right single quotation mark) in screenshot names like \"Capture d'écran\"\n\t// Users typically type U+0027 (straight apostrophe)\n\treturn filePath.replace(/'/g, \"\\u2019\");\n}\n\nfunction fileExists(filePath: string): boolean {\n\ttry {\n\t\taccessSync(filePath, constants.F_OK);\n\t\treturn true;\n\t} catch {\n\t\treturn false;\n\t}\n}\n\nexport async function pathExists(filePath: string): Promise<boolean> {\n\ttry {\n\t\tawait access(filePath, constants.F_OK);\n\t\treturn true;\n\t} catch {\n\t\treturn false;\n\t}\n}\n\nexport function expandPath(filePath: string): string {\n\treturn normalizePath(filePath, { normalizeUnicodeSpaces: true, stripAtPrefix: true });\n}\n\n/**\n * Resolve a path relative to the given cwd, handling ~ expansion and absolute\n * paths. The result is the single target used by both permission matching and\n * filesystem execution.\n */\nexport function resolveToCwd(filePath: string, cwd: string): string {\n\tconst requested = resolvePath(filePath, cwd, { normalizeUnicodeSpaces: true, stripAtPrefix: true });\n\ttry {\n\t\treturn realpathSync(requested);\n\t} catch {\n\t\ttry {\n\t\t\treturn joinCanonicalParent(requested);\n\t\t} catch {\n\t\t\treturn requested;\n\t\t}\n\t}\n}\n\nfunction joinCanonicalParent(requested: string): string {\n\treturn join(realpathSync(dirname(requested)), basename(requested));\n}\n\nexport function resolveReadPath(filePath: string, cwd: string): string {\n\tconst resolved = resolveToCwd(filePath, cwd);\n\n\tif (fileExists(resolved)) {\n\t\treturn resolved;\n\t}\n\n\t// Try macOS AM/PM variant (narrow no-break space before AM/PM)\n\tconst amPmVariant = tryMacOSScreenshotPath(resolved);\n\tif (amPmVariant !== resolved && fileExists(amPmVariant)) {\n\t\treturn amPmVariant;\n\t}\n\n\t// Try NFD variant (macOS stores filenames in NFD form)\n\tconst nfdVariant = tryNFDVariant(resolved);\n\tif (nfdVariant !== resolved && fileExists(nfdVariant)) {\n\t\treturn nfdVariant;\n\t}\n\n\t// Try curly quote variant (macOS uses U+2019 in screenshot names)\n\tconst curlyVariant = tryCurlyQuoteVariant(resolved);\n\tif (curlyVariant !== resolved && fileExists(curlyVariant)) {\n\t\treturn curlyVariant;\n\t}\n\n\t// Try combined NFD + curly quote (for French macOS screenshots like \"Capture d'écran\")\n\tconst nfdCurlyVariant = tryCurlyQuoteVariant(nfdVariant);\n\tif (nfdCurlyVariant !== resolved && fileExists(nfdCurlyVariant)) {\n\t\treturn nfdCurlyVariant;\n\t}\n\n\treturn resolved;\n}\n\nexport async function resolveReadPathAsync(filePath: string, cwd: string): Promise<string> {\n\tconst resolved = resolveToCwd(filePath, cwd);\n\n\tif (await pathExists(resolved)) {\n\t\treturn resolved;\n\t}\n\n\t// Try macOS AM/PM variant (narrow no-break space before AM/PM)\n\tconst amPmVariant = tryMacOSScreenshotPath(resolved);\n\tif (amPmVariant !== resolved && (await pathExists(amPmVariant))) {\n\t\treturn amPmVariant;\n\t}\n\n\t// Try NFD variant (macOS stores filenames in NFD form)\n\tconst nfdVariant = tryNFDVariant(resolved);\n\tif (nfdVariant !== resolved && (await pathExists(nfdVariant))) {\n\t\treturn nfdVariant;\n\t}\n\n\t// Try curly quote variant (macOS uses U+2019 in screenshot names)\n\tconst curlyVariant = tryCurlyQuoteVariant(resolved);\n\tif (curlyVariant !== resolved && (await pathExists(curlyVariant))) {\n\t\treturn curlyVariant;\n\t}\n\n\t// Try combined NFD + curly quote (for French macOS screenshots like \"Capture d'écran\")\n\tconst nfdCurlyVariant = tryCurlyQuoteVariant(nfdVariant);\n\tif (nfdCurlyVariant !== resolved && (await pathExists(nfdCurlyVariant))) {\n\t\treturn nfdCurlyVariant;\n\t}\n\n\treturn resolved;\n}\n"]}