@greppleai/grip 0.1.5 → 0.1.7

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 (587) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/README.md +1 -1
  3. package/dist/bun/cli.d.ts.map +1 -1
  4. package/dist/bun/cli.js.map +1 -1
  5. package/dist/bun/embedded-assets.d.ts.map +1 -1
  6. package/dist/bun/embedded-assets.js.map +1 -1
  7. package/dist/bun/register-bedrock.d.ts.map +1 -1
  8. package/dist/bun/restore-sandbox-env.d.ts.map +1 -1
  9. package/dist/bun/restore-sandbox-env.js.map +1 -1
  10. package/dist/cli/args.d.ts.map +1 -1
  11. package/dist/cli/args.js.map +1 -1
  12. package/dist/cli/config-selector.d.ts.map +1 -1
  13. package/dist/cli/config-selector.js.map +1 -1
  14. package/dist/cli/file-processor.d.ts.map +1 -1
  15. package/dist/cli/file-processor.js.map +1 -1
  16. package/dist/cli/initial-message.d.ts +1 -1
  17. package/dist/cli/initial-message.d.ts.map +1 -1
  18. package/dist/cli/initial-message.js.map +1 -1
  19. package/dist/cli/list-models.d.ts.map +1 -1
  20. package/dist/cli/list-models.js.map +1 -1
  21. package/dist/cli/session-picker.d.ts.map +1 -1
  22. package/dist/cli/session-picker.js.map +1 -1
  23. package/dist/cli.d.ts.map +1 -1
  24. package/dist/cli.js.map +1 -1
  25. package/dist/config.d.ts.map +1 -1
  26. package/dist/config.js +2 -0
  27. package/dist/config.js.map +1 -1
  28. package/dist/core/agent-session.d.ts +38 -1
  29. package/dist/core/agent-session.d.ts.map +1 -1
  30. package/dist/core/agent-session.js +289 -154
  31. package/dist/core/agent-session.js.map +1 -1
  32. package/dist/core/auth-guidance.d.ts.map +1 -1
  33. package/dist/core/auth-guidance.js.map +1 -1
  34. package/dist/core/auth-storage.d.ts +4 -0
  35. package/dist/core/auth-storage.d.ts.map +1 -1
  36. package/dist/core/auth-storage.js +3 -10
  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 +19 -23
  40. package/dist/core/bash-executor.js.map +1 -1
  41. package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
  42. package/dist/core/compaction/branch-summarization.js.map +1 -1
  43. package/dist/core/compaction/compaction.d.ts.map +1 -1
  44. package/dist/core/compaction/compaction.js +9 -2
  45. package/dist/core/compaction/compaction.js.map +1 -1
  46. package/dist/core/compaction/compression-detection-ledger.d.ts.map +1 -1
  47. package/dist/core/compaction/compression-detection-ledger.js.map +1 -1
  48. package/dist/core/compaction/compression-detector.d.ts +1 -0
  49. package/dist/core/compaction/compression-detector.d.ts.map +1 -1
  50. package/dist/core/compaction/compression-detector.js +10 -21
  51. package/dist/core/compaction/compression-detector.js.map +1 -1
  52. package/dist/core/compaction/compression-economics.d.ts.map +1 -1
  53. package/dist/core/compaction/compression-economics.js.map +1 -1
  54. package/dist/core/compaction/utils.d.ts.map +1 -1
  55. package/dist/core/compaction/utils.js.map +1 -1
  56. package/dist/core/defaults.d.ts.map +1 -1
  57. package/dist/core/diagnostics.d.ts.map +1 -1
  58. package/dist/core/event-bus.d.ts.map +1 -1
  59. package/dist/core/event-bus.js.map +1 -1
  60. package/dist/core/exec.d.ts.map +1 -1
  61. package/dist/core/exec.js.map +1 -1
  62. package/dist/core/export-html/ansi-to-html.d.ts.map +1 -1
  63. package/dist/core/export-html/ansi-to-html.js.map +1 -1
  64. package/dist/core/export-html/index.d.ts.map +1 -1
  65. package/dist/core/export-html/index.js.map +1 -1
  66. package/dist/core/export-html/tool-renderer.d.ts.map +1 -1
  67. package/dist/core/export-html/tool-renderer.js.map +1 -1
  68. package/dist/core/extensions/loader.d.ts.map +1 -1
  69. package/dist/core/extensions/loader.js.map +1 -1
  70. package/dist/core/extensions/runner.d.ts +3 -0
  71. package/dist/core/extensions/runner.d.ts.map +1 -1
  72. package/dist/core/extensions/runner.js +40 -30
  73. package/dist/core/extensions/runner.js.map +1 -1
  74. package/dist/core/extensions/types.d.ts +21 -1
  75. package/dist/core/extensions/types.d.ts.map +1 -1
  76. package/dist/core/extensions/types.js.map +1 -1
  77. package/dist/core/extensions/wrapper.d.ts.map +1 -1
  78. package/dist/core/extensions/wrapper.js.map +1 -1
  79. package/dist/core/footer-data-provider.d.ts.map +1 -1
  80. package/dist/core/footer-data-provider.js +15 -16
  81. package/dist/core/footer-data-provider.js.map +1 -1
  82. package/dist/core/grip-agent.d.ts.map +1 -1
  83. package/dist/core/grip-agent.js +7 -21
  84. package/dist/core/grip-agent.js.map +1 -1
  85. package/dist/core/grip-manifest.d.ts.map +1 -1
  86. package/dist/core/grip-manifest.js.map +1 -1
  87. package/dist/core/hooks/aggregate.d.ts.map +1 -1
  88. package/dist/core/hooks/aggregate.js.map +1 -1
  89. package/dist/core/hooks/config.d.ts.map +1 -1
  90. package/dist/core/hooks/config.js.map +1 -1
  91. package/dist/core/hooks/executor.d.ts.map +1 -1
  92. package/dist/core/hooks/executor.js.map +1 -1
  93. package/dist/core/hooks/index.d.ts.map +1 -1
  94. package/dist/core/hooks/index.js.map +1 -1
  95. package/dist/core/hooks/matcher.d.ts.map +1 -1
  96. package/dist/core/hooks/matcher.js.map +1 -1
  97. package/dist/core/hooks/trust-store.d.ts.map +1 -1
  98. package/dist/core/hooks/trust-store.js +0 -3
  99. package/dist/core/hooks/trust-store.js.map +1 -1
  100. package/dist/core/hooks/types.d.ts.map +1 -1
  101. package/dist/core/hooks/types.js.map +1 -1
  102. package/dist/core/http-dispatcher.d.ts.map +1 -1
  103. package/dist/core/http-dispatcher.js.map +1 -1
  104. package/dist/core/instruction-resource-loader.d.ts +1 -0
  105. package/dist/core/instruction-resource-loader.d.ts.map +1 -1
  106. package/dist/core/instruction-resource-loader.js +2 -4
  107. package/dist/core/instruction-resource-loader.js.map +1 -1
  108. package/dist/core/keybindings.d.ts.map +1 -1
  109. package/dist/core/keybindings.js +0 -1
  110. package/dist/core/keybindings.js.map +1 -1
  111. package/dist/core/lsp/abort.d.ts.map +1 -1
  112. package/dist/core/lsp/abort.js.map +1 -1
  113. package/dist/core/lsp/client.d.ts.map +1 -1
  114. package/dist/core/lsp/client.js +8 -22
  115. package/dist/core/lsp/client.js.map +1 -1
  116. package/dist/core/lsp/config-loader.d.ts.map +1 -1
  117. package/dist/core/lsp/config-loader.js.map +1 -1
  118. package/dist/core/lsp/config.d.ts.map +1 -1
  119. package/dist/core/lsp/config.js.map +1 -1
  120. package/dist/core/lsp/diagnostics.d.ts.map +1 -1
  121. package/dist/core/lsp/diagnostics.js.map +1 -1
  122. package/dist/core/lsp/file-sync.d.ts.map +1 -1
  123. package/dist/core/lsp/file-sync.js +7 -9
  124. package/dist/core/lsp/file-sync.js.map +1 -1
  125. package/dist/core/lsp/integration.d.ts.map +1 -1
  126. package/dist/core/lsp/integration.js.map +1 -1
  127. package/dist/core/lsp/language-map.d.ts.map +1 -1
  128. package/dist/core/lsp/language-map.js +2 -7
  129. package/dist/core/lsp/language-map.js.map +1 -1
  130. package/dist/core/lsp/manager.d.ts.map +1 -1
  131. package/dist/core/lsp/manager.js +18 -29
  132. package/dist/core/lsp/manager.js.map +1 -1
  133. package/dist/core/lsp/navigation.d.ts.map +1 -1
  134. package/dist/core/lsp/navigation.js.map +1 -1
  135. package/dist/core/lsp/portable-path.d.ts.map +1 -1
  136. package/dist/core/lsp/portable-path.js.map +1 -1
  137. package/dist/core/lsp/refactor.d.ts.map +1 -1
  138. package/dist/core/lsp/refactor.js.map +1 -1
  139. package/dist/core/lsp/transport.d.ts.map +1 -1
  140. package/dist/core/lsp/transport.js.map +1 -1
  141. package/dist/core/messages.d.ts.map +1 -1
  142. package/dist/core/messages.js +30 -1
  143. package/dist/core/messages.js.map +1 -1
  144. package/dist/core/model-registry.d.ts.map +1 -1
  145. package/dist/core/model-registry.js +5 -7
  146. package/dist/core/model-registry.js.map +1 -1
  147. package/dist/core/model-resolver.d.ts.map +1 -1
  148. package/dist/core/model-resolver.js.map +1 -1
  149. package/dist/core/output-guard.d.ts.map +1 -1
  150. package/dist/core/output-guard.js.map +1 -1
  151. package/dist/core/package-manager.d.ts.map +1 -1
  152. package/dist/core/package-manager.js +0 -6
  153. package/dist/core/package-manager.js.map +1 -1
  154. package/dist/core/prompt-templates.d.ts.map +1 -1
  155. package/dist/core/prompt-templates.js.map +1 -1
  156. package/dist/core/provider-display-names.d.ts.map +1 -1
  157. package/dist/core/remote-workspace-protocol/contract.d.ts.map +1 -1
  158. package/dist/core/remote-workspace-protocol/contract.js +4 -2
  159. package/dist/core/remote-workspace-protocol/contract.js.map +1 -1
  160. package/dist/core/remote-workspace-protocol/guest-shared-client.d.ts.map +1 -1
  161. package/dist/core/remote-workspace-protocol/guest-shared-client.js +1 -5
  162. package/dist/core/remote-workspace-protocol/guest-shared-client.js.map +1 -1
  163. package/dist/core/remote-workspace-protocol/guest-shared-outbound-scheduler.d.ts.map +1 -1
  164. package/dist/core/remote-workspace-protocol/guest-shared-outbound-scheduler.js +5 -10
  165. package/dist/core/remote-workspace-protocol/guest-shared-outbound-scheduler.js.map +1 -1
  166. package/dist/core/remote-workspace-protocol/guest-shared-uplink.d.ts.map +1 -1
  167. package/dist/core/remote-workspace-protocol/guest-shared-uplink.js +2 -9
  168. package/dist/core/remote-workspace-protocol/guest-shared-uplink.js.map +1 -1
  169. package/dist/core/remote-workspace-protocol/lima-owner-directory.d.ts.map +1 -1
  170. package/dist/core/remote-workspace-protocol/lima-owner-directory.js.map +1 -1
  171. package/dist/core/remote-workspace-protocol/lima-owner-lock.d.ts.map +1 -1
  172. package/dist/core/remote-workspace-protocol/lima-owner-lock.js.map +1 -1
  173. package/dist/core/remote-workspace-protocol/session.d.ts.map +1 -1
  174. package/dist/core/remote-workspace-protocol/session.js +27 -65
  175. package/dist/core/remote-workspace-protocol/session.js.map +1 -1
  176. package/dist/core/remote-workspace-protocol/shared-transport.d.ts.map +1 -1
  177. package/dist/core/remote-workspace-protocol/shared-transport.js.map +1 -1
  178. package/dist/core/resolve-config-value.d.ts.map +1 -1
  179. package/dist/core/resolve-config-value.js.map +1 -1
  180. package/dist/core/resource-loader.d.ts.map +1 -1
  181. package/dist/core/resource-loader.js +0 -48
  182. package/dist/core/resource-loader.js.map +1 -1
  183. package/dist/core/rules.d.ts.map +1 -1
  184. package/dist/core/rules.js.map +1 -1
  185. package/dist/core/sandbox/command.d.ts.map +1 -1
  186. package/dist/core/sandbox/command.js.map +1 -1
  187. package/dist/core/sandbox/config.d.ts.map +1 -1
  188. package/dist/core/sandbox/config.js.map +1 -1
  189. package/dist/core/sandbox/lima-guest-binary.d.ts.map +1 -1
  190. package/dist/core/sandbox/lima-guest-binary.js.map +1 -1
  191. package/dist/core/sandbox/lima.d.ts +2 -0
  192. package/dist/core/sandbox/lima.d.ts.map +1 -1
  193. package/dist/core/sandbox/lima.js +3 -9
  194. package/dist/core/sandbox/lima.js.map +1 -1
  195. package/dist/core/sandbox/shared-lima-roots.d.ts.map +1 -1
  196. package/dist/core/sandbox/shared-lima-roots.js.map +1 -1
  197. package/dist/core/sandbox/update-shared-guest-binary.d.ts.map +1 -1
  198. package/dist/core/sandbox/update-shared-guest-binary.js.map +1 -1
  199. package/dist/core/session/constants.d.ts.map +1 -1
  200. package/dist/core/session/context-metadata.d.ts.map +1 -1
  201. package/dist/core/session/context-metadata.js.map +1 -1
  202. package/dist/core/session/context.d.ts.map +1 -1
  203. package/dist/core/session/context.js.map +1 -1
  204. package/dist/core/session/ids.d.ts.map +1 -1
  205. package/dist/core/session/ids.js.map +1 -1
  206. package/dist/core/session/in-memory-session-manager.d.ts.map +1 -1
  207. package/dist/core/session/in-memory-session-manager.js +0 -1
  208. package/dist/core/session/in-memory-session-manager.js.map +1 -1
  209. package/dist/core/session/in-memory-session.d.ts.map +1 -1
  210. package/dist/core/session/in-memory-session.js.map +1 -1
  211. package/dist/core/session/jsonl-errors.d.ts.map +1 -1
  212. package/dist/core/session/jsonl-errors.js +0 -11
  213. package/dist/core/session/jsonl-errors.js.map +1 -1
  214. package/dist/core/session/jsonl-helpers.d.ts.map +1 -1
  215. package/dist/core/session/jsonl-helpers.js.map +1 -1
  216. package/dist/core/session/local-session-manager.d.ts.map +1 -1
  217. package/dist/core/session/local-session-manager.js +4 -6
  218. package/dist/core/session/local-session-manager.js.map +1 -1
  219. package/dist/core/session/local-session.d.ts.map +1 -1
  220. package/dist/core/session/local-session.js.map +1 -1
  221. package/dist/core/session/migrations.d.ts.map +1 -1
  222. package/dist/core/session/migrations.js.map +1 -1
  223. package/dist/core/session/remote-session-client.d.ts.map +1 -1
  224. package/dist/core/session/remote-session-client.js +0 -6
  225. package/dist/core/session/remote-session-client.js.map +1 -1
  226. package/dist/core/session/remote-session-manager.d.ts.map +1 -1
  227. package/dist/core/session/remote-session-manager.js +0 -3
  228. package/dist/core/session/remote-session-manager.js.map +1 -1
  229. package/dist/core/session/remote-session.d.ts.map +1 -1
  230. package/dist/core/session/remote-session.js +0 -1
  231. package/dist/core/session/remote-session.js.map +1 -1
  232. package/dist/core/session/session-manager.d.ts.map +1 -1
  233. package/dist/core/session/session.d.ts.map +1 -1
  234. package/dist/core/session/session.js +1 -5
  235. package/dist/core/session/session.js.map +1 -1
  236. package/dist/core/session/stores/in-memory-session-store.d.ts.map +1 -1
  237. package/dist/core/session/stores/in-memory-session-store.js +7 -6
  238. package/dist/core/session/stores/in-memory-session-store.js.map +1 -1
  239. package/dist/core/session/stores/jsonl-session-store.d.ts.map +1 -1
  240. package/dist/core/session/stores/jsonl-session-store.js +6 -14
  241. package/dist/core/session/stores/jsonl-session-store.js.map +1 -1
  242. package/dist/core/session/stores/remote-session-store.d.ts.map +1 -1
  243. package/dist/core/session/stores/remote-session-store.js +3 -8
  244. package/dist/core/session/stores/remote-session-store.js.map +1 -1
  245. package/dist/core/session/stores/session-store.d.ts.map +1 -1
  246. package/dist/core/session/types.d.ts.map +1 -1
  247. package/dist/core/session/usage-ledger.d.ts.map +1 -1
  248. package/dist/core/session/usage-ledger.js.map +1 -1
  249. package/dist/core/session-cwd.d.ts.map +1 -1
  250. package/dist/core/session-cwd.js +0 -1
  251. package/dist/core/session-cwd.js.map +1 -1
  252. package/dist/core/settings-manager.d.ts.map +1 -1
  253. package/dist/core/settings-manager.js +9 -17
  254. package/dist/core/settings-manager.js.map +1 -1
  255. package/dist/core/skills.d.ts.map +1 -1
  256. package/dist/core/skills.js +3 -2
  257. package/dist/core/skills.js.map +1 -1
  258. package/dist/core/slash-commands.d.ts.map +1 -1
  259. package/dist/core/source-info.d.ts.map +1 -1
  260. package/dist/core/source-info.js.map +1 -1
  261. package/dist/core/system-prompt.d.ts +1 -1
  262. package/dist/core/system-prompt.d.ts.map +1 -1
  263. package/dist/core/system-prompt.js +3 -2
  264. package/dist/core/system-prompt.js.map +1 -1
  265. package/dist/core/telemetry.d.ts.map +1 -1
  266. package/dist/core/telemetry.js.map +1 -1
  267. package/dist/core/timings.d.ts.map +1 -1
  268. package/dist/core/timings.js.map +1 -1
  269. package/dist/core/tools/bash.d.ts +1 -0
  270. package/dist/core/tools/bash.d.ts.map +1 -1
  271. package/dist/core/tools/bash.js +34 -28
  272. package/dist/core/tools/bash.js.map +1 -1
  273. package/dist/core/tools/compress-context.d.ts.map +1 -1
  274. package/dist/core/tools/compress-context.js.map +1 -1
  275. package/dist/core/tools/edit-diff.d.ts.map +1 -1
  276. package/dist/core/tools/edit-diff.js.map +1 -1
  277. package/dist/core/tools/edit.d.ts.map +1 -1
  278. package/dist/core/tools/edit.js.map +1 -1
  279. package/dist/core/tools/file-mutation-queue.d.ts.map +1 -1
  280. package/dist/core/tools/file-mutation-queue.js.map +1 -1
  281. package/dist/core/tools/find.d.ts.map +1 -1
  282. package/dist/core/tools/find.js.map +1 -1
  283. package/dist/core/tools/grep.d.ts.map +1 -1
  284. package/dist/core/tools/grep.js.map +1 -1
  285. package/dist/core/tools/hash-store.d.ts.map +1 -1
  286. package/dist/core/tools/hash-store.js.map +1 -1
  287. package/dist/core/tools/hashline/apply.d.ts.map +1 -1
  288. package/dist/core/tools/hashline/apply.js.map +1 -1
  289. package/dist/core/tools/hashline/hash.d.ts.map +1 -1
  290. package/dist/core/tools/hashline/hash.js.map +1 -1
  291. package/dist/core/tools/hashline/parse.d.ts.map +1 -1
  292. package/dist/core/tools/hashline/parse.js.map +1 -1
  293. package/dist/core/tools/hashline/resolve.d.ts.map +1 -1
  294. package/dist/core/tools/hashline/resolve.js.map +1 -1
  295. package/dist/core/tools/hashline-utils.d.ts.map +1 -1
  296. package/dist/core/tools/hashline-utils.js.map +1 -1
  297. package/dist/core/tools/index.d.ts.map +1 -1
  298. package/dist/core/tools/index.js.map +1 -1
  299. package/dist/core/tools/ls.d.ts.map +1 -1
  300. package/dist/core/tools/ls.js.map +1 -1
  301. package/dist/core/tools/operations.d.ts +11 -0
  302. package/dist/core/tools/operations.d.ts.map +1 -1
  303. package/dist/core/tools/operations.js +54 -28
  304. package/dist/core/tools/operations.js.map +1 -1
  305. package/dist/core/tools/output-accumulator.d.ts.map +1 -1
  306. package/dist/core/tools/output-accumulator.js +12 -18
  307. package/dist/core/tools/output-accumulator.js.map +1 -1
  308. package/dist/core/tools/path-utils.d.ts.map +1 -1
  309. package/dist/core/tools/path-utils.js.map +1 -1
  310. package/dist/core/tools/read.d.ts.map +1 -1
  311. package/dist/core/tools/read.js.map +1 -1
  312. package/dist/core/tools/render-utils.d.ts.map +1 -1
  313. package/dist/core/tools/render-utils.js.map +1 -1
  314. package/dist/core/tools/replace-diff.d.ts.map +1 -1
  315. package/dist/core/tools/replace-diff.js.map +1 -1
  316. package/dist/core/tools/replace-normalize.d.ts.map +1 -1
  317. package/dist/core/tools/replace-normalize.js.map +1 -1
  318. package/dist/core/tools/replace-render.d.ts +1 -1
  319. package/dist/core/tools/replace-render.d.ts.map +1 -1
  320. package/dist/core/tools/replace-render.js.map +1 -1
  321. package/dist/core/tools/runtime.d.ts.map +1 -1
  322. package/dist/core/tools/runtime.js.map +1 -1
  323. package/dist/core/tools/session-history.d.ts.map +1 -1
  324. package/dist/core/tools/session-history.js.map +1 -1
  325. package/dist/core/tools/subagent-agents.d.ts.map +1 -1
  326. package/dist/core/tools/subagent-agents.js.map +1 -1
  327. package/dist/core/tools/subagent.d.ts.map +1 -1
  328. package/dist/core/tools/subagent.js.map +1 -1
  329. package/dist/core/tools/tool-definition-wrapper.d.ts.map +1 -1
  330. package/dist/core/tools/tool-definition-wrapper.js.map +1 -1
  331. package/dist/core/tools/truncate.d.ts.map +1 -1
  332. package/dist/core/tools/truncate.js.map +1 -1
  333. package/dist/core/tools/websearch.d.ts.map +1 -1
  334. package/dist/core/tools/websearch.js.map +1 -1
  335. package/dist/core/tools/workspace-tool-host.d.ts +1 -0
  336. package/dist/core/tools/workspace-tool-host.d.ts.map +1 -1
  337. package/dist/core/tools/workspace-tool-host.js +36 -22
  338. package/dist/core/tools/workspace-tool-host.js.map +1 -1
  339. package/dist/core/tools/write.d.ts.map +1 -1
  340. package/dist/core/tools/write.js +0 -1
  341. package/dist/core/tools/write.js.map +1 -1
  342. package/dist/core/workspace-identity.d.ts.map +1 -1
  343. package/dist/daemon/activity-budget.d.ts.map +1 -1
  344. package/dist/daemon/activity-budget.js +2 -3
  345. package/dist/daemon/activity-budget.js.map +1 -1
  346. package/dist/daemon/command.d.ts.map +1 -1
  347. package/dist/daemon/command.js.map +1 -1
  348. package/dist/daemon/config.d.ts +2 -0
  349. package/dist/daemon/config.d.ts.map +1 -1
  350. package/dist/daemon/config.js +4 -0
  351. package/dist/daemon/config.js.map +1 -1
  352. package/dist/daemon/help.d.ts.map +1 -1
  353. package/dist/daemon/help.js +4 -3
  354. package/dist/daemon/help.js.map +1 -1
  355. package/dist/daemon/lsp-config.d.ts.map +1 -1
  356. package/dist/daemon/lsp-config.js.map +1 -1
  357. package/dist/daemon/outbound-budget.d.ts.map +1 -1
  358. package/dist/daemon/outbound-budget.js +2 -4
  359. package/dist/daemon/outbound-budget.js.map +1 -1
  360. package/dist/daemon/security.d.ts.map +1 -1
  361. package/dist/daemon/security.js.map +1 -1
  362. package/dist/daemon/server.d.ts.map +1 -1
  363. package/dist/daemon/server.js.map +1 -1
  364. package/dist/daemon/shared-connection.d.ts.map +1 -1
  365. package/dist/daemon/shared-connection.js +10 -15
  366. package/dist/daemon/shared-connection.js.map +1 -1
  367. package/dist/daemon/shared-revision.d.ts.map +1 -1
  368. package/dist/daemon/shared-revision.js +2 -1
  369. package/dist/daemon/shared-revision.js.map +1 -1
  370. package/dist/daemon/shared-roots.d.ts.map +1 -1
  371. package/dist/daemon/shared-roots.js +0 -1
  372. package/dist/daemon/shared-roots.js.map +1 -1
  373. package/dist/daemon/workspace-runtime.d.ts +2 -0
  374. package/dist/daemon/workspace-runtime.d.ts.map +1 -1
  375. package/dist/daemon/workspace-runtime.js +43 -15
  376. package/dist/daemon/workspace-runtime.js.map +1 -1
  377. package/dist/index.d.ts +1 -1
  378. package/dist/index.d.ts.map +1 -1
  379. package/dist/index.js.map +1 -1
  380. package/dist/main.d.ts.map +1 -1
  381. package/dist/main.js +8 -3
  382. package/dist/main.js.map +1 -1
  383. package/dist/migrations.d.ts.map +1 -1
  384. package/dist/migrations.js.map +1 -1
  385. package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
  386. package/dist/modes/interactive/components/assistant-message.js +3 -10
  387. package/dist/modes/interactive/components/assistant-message.js.map +1 -1
  388. package/dist/modes/interactive/components/bash-execution.d.ts.map +1 -1
  389. package/dist/modes/interactive/components/bash-execution.js +4 -9
  390. package/dist/modes/interactive/components/bash-execution.js.map +1 -1
  391. package/dist/modes/interactive/components/bordered-loader.d.ts.map +1 -1
  392. package/dist/modes/interactive/components/bordered-loader.js +0 -3
  393. package/dist/modes/interactive/components/bordered-loader.js.map +1 -1
  394. package/dist/modes/interactive/components/branch-summary-message.d.ts.map +1 -1
  395. package/dist/modes/interactive/components/branch-summary-message.js +1 -3
  396. package/dist/modes/interactive/components/branch-summary-message.js.map +1 -1
  397. package/dist/modes/interactive/components/compaction-summary-message.d.ts.map +1 -1
  398. package/dist/modes/interactive/components/compaction-summary-message.js +1 -3
  399. package/dist/modes/interactive/components/compaction-summary-message.js.map +1 -1
  400. package/dist/modes/interactive/components/config-selector.d.ts.map +1 -1
  401. package/dist/modes/interactive/components/config-selector.js +6 -16
  402. package/dist/modes/interactive/components/config-selector.js.map +1 -1
  403. package/dist/modes/interactive/components/countdown-timer.d.ts.map +1 -1
  404. package/dist/modes/interactive/components/countdown-timer.js +0 -5
  405. package/dist/modes/interactive/components/countdown-timer.js.map +1 -1
  406. package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -1
  407. package/dist/modes/interactive/components/custom-editor.js +1 -8
  408. package/dist/modes/interactive/components/custom-editor.js.map +1 -1
  409. package/dist/modes/interactive/components/custom-message.d.ts.map +1 -1
  410. package/dist/modes/interactive/components/custom-message.js +1 -6
  411. package/dist/modes/interactive/components/custom-message.js.map +1 -1
  412. package/dist/modes/interactive/components/diff.d.ts.map +1 -1
  413. package/dist/modes/interactive/components/diff.js.map +1 -1
  414. package/dist/modes/interactive/components/dynamic-border.d.ts.map +1 -1
  415. package/dist/modes/interactive/components/dynamic-border.js +0 -1
  416. package/dist/modes/interactive/components/dynamic-border.js.map +1 -1
  417. package/dist/modes/interactive/components/extension-editor.d.ts.map +1 -1
  418. package/dist/modes/interactive/components/extension-editor.js +1 -7
  419. package/dist/modes/interactive/components/extension-editor.js.map +1 -1
  420. package/dist/modes/interactive/components/extension-input.d.ts.map +1 -1
  421. package/dist/modes/interactive/components/extension-input.js +2 -8
  422. package/dist/modes/interactive/components/extension-input.js.map +1 -1
  423. package/dist/modes/interactive/components/extension-selector.d.ts.map +1 -1
  424. package/dist/modes/interactive/components/extension-selector.js +1 -9
  425. package/dist/modes/interactive/components/extension-selector.js.map +1 -1
  426. package/dist/modes/interactive/components/footer.d.ts.map +1 -1
  427. package/dist/modes/interactive/components/footer.js +8 -4
  428. package/dist/modes/interactive/components/footer.js.map +1 -1
  429. package/dist/modes/interactive/components/hook-execution.d.ts.map +1 -1
  430. package/dist/modes/interactive/components/hook-execution.js +2 -5
  431. package/dist/modes/interactive/components/hook-execution.js.map +1 -1
  432. package/dist/modes/interactive/components/keybinding-hints.d.ts.map +1 -1
  433. package/dist/modes/interactive/components/keybinding-hints.js.map +1 -1
  434. package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -1
  435. package/dist/modes/interactive/components/login-dialog.js +3 -9
  436. package/dist/modes/interactive/components/login-dialog.js.map +1 -1
  437. package/dist/modes/interactive/components/markdown-transform.d.ts.map +1 -1
  438. package/dist/modes/interactive/components/markdown-transform.js.map +1 -1
  439. package/dist/modes/interactive/components/mermaid.d.ts.map +1 -1
  440. package/dist/modes/interactive/components/mermaid.js.map +1 -1
  441. package/dist/modes/interactive/components/message-card.d.ts.map +1 -1
  442. package/dist/modes/interactive/components/message-card.js +0 -1
  443. package/dist/modes/interactive/components/message-card.js.map +1 -1
  444. package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
  445. package/dist/modes/interactive/components/model-selector.js +13 -28
  446. package/dist/modes/interactive/components/model-selector.js.map +1 -1
  447. package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -1
  448. package/dist/modes/interactive/components/oauth-selector.js +3 -12
  449. package/dist/modes/interactive/components/oauth-selector.js.map +1 -1
  450. package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -1
  451. package/dist/modes/interactive/components/scoped-models-selector.js +9 -13
  452. package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -1
  453. package/dist/modes/interactive/components/session-selector-search.d.ts.map +1 -1
  454. package/dist/modes/interactive/components/session-selector-search.js.map +1 -1
  455. package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
  456. package/dist/modes/interactive/components/session-selector.js +33 -58
  457. package/dist/modes/interactive/components/session-selector.js.map +1 -1
  458. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  459. package/dist/modes/interactive/components/settings-selector.js +0 -4
  460. package/dist/modes/interactive/components/settings-selector.js.map +1 -1
  461. package/dist/modes/interactive/components/show-images-selector.d.ts.map +1 -1
  462. package/dist/modes/interactive/components/show-images-selector.js +0 -1
  463. package/dist/modes/interactive/components/show-images-selector.js.map +1 -1
  464. package/dist/modes/interactive/components/skill-invocation-message.d.ts.map +1 -1
  465. package/dist/modes/interactive/components/skill-invocation-message.js +1 -3
  466. package/dist/modes/interactive/components/skill-invocation-message.js.map +1 -1
  467. package/dist/modes/interactive/components/theme-selector.d.ts.map +1 -1
  468. package/dist/modes/interactive/components/theme-selector.js +0 -2
  469. package/dist/modes/interactive/components/theme-selector.js.map +1 -1
  470. package/dist/modes/interactive/components/thinking-selector.d.ts.map +1 -1
  471. package/dist/modes/interactive/components/thinking-selector.js +0 -1
  472. package/dist/modes/interactive/components/thinking-selector.js.map +1 -1
  473. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  474. package/dist/modes/interactive/components/tool-execution.js +9 -24
  475. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  476. package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -1
  477. package/dist/modes/interactive/components/tree-selector.js +18 -34
  478. package/dist/modes/interactive/components/tree-selector.js.map +1 -1
  479. package/dist/modes/interactive/components/user-message-selector.d.ts.map +1 -1
  480. package/dist/modes/interactive/components/user-message-selector.js +3 -6
  481. package/dist/modes/interactive/components/user-message-selector.js.map +1 -1
  482. package/dist/modes/interactive/components/user-message.d.ts.map +1 -1
  483. package/dist/modes/interactive/components/user-message.js +0 -4
  484. package/dist/modes/interactive/components/user-message.js.map +1 -1
  485. package/dist/modes/interactive/components/visual-truncate.d.ts.map +1 -1
  486. package/dist/modes/interactive/components/visual-truncate.js.map +1 -1
  487. package/dist/modes/interactive/interactive-mode.d.ts +13 -0
  488. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  489. package/dist/modes/interactive/interactive-mode.js +162 -136
  490. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  491. package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
  492. package/dist/modes/interactive/theme/theme.js +0 -7
  493. package/dist/modes/interactive/theme/theme.js.map +1 -1
  494. package/dist/modes/json-event.d.ts.map +1 -1
  495. package/dist/modes/json-event.js.map +1 -1
  496. package/dist/modes/print-mode.d.ts.map +1 -1
  497. package/dist/modes/print-mode.js.map +1 -1
  498. package/dist/modes/rpc/jsonl.d.ts.map +1 -1
  499. package/dist/modes/rpc/jsonl.js.map +1 -1
  500. package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
  501. package/dist/modes/rpc/rpc-client.js +10 -11
  502. package/dist/modes/rpc/rpc-client.js.map +1 -1
  503. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  504. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  505. package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
  506. package/dist/package-manager-cli.d.ts.map +1 -1
  507. package/dist/package-manager-cli.js +33 -2
  508. package/dist/package-manager-cli.js.map +1 -1
  509. package/dist/utils/ansi.d.ts.map +1 -1
  510. package/dist/utils/ansi.js.map +1 -1
  511. package/dist/utils/binary-self-update.d.ts +25 -0
  512. package/dist/utils/binary-self-update.d.ts.map +1 -0
  513. package/dist/utils/binary-self-update.js +159 -0
  514. package/dist/utils/binary-self-update.js.map +1 -0
  515. package/dist/utils/changelog.d.ts.map +1 -1
  516. package/dist/utils/changelog.js.map +1 -1
  517. package/dist/utils/child-process.d.ts.map +1 -1
  518. package/dist/utils/child-process.js.map +1 -1
  519. package/dist/utils/clipboard-image.d.ts.map +1 -1
  520. package/dist/utils/clipboard-image.js.map +1 -1
  521. package/dist/utils/clipboard-native.d.ts.map +1 -1
  522. package/dist/utils/clipboard-native.js.map +1 -1
  523. package/dist/utils/clipboard.d.ts.map +1 -1
  524. package/dist/utils/clipboard.js.map +1 -1
  525. package/dist/utils/deprecation.d.ts.map +1 -1
  526. package/dist/utils/deprecation.js.map +1 -1
  527. package/dist/utils/directory-completions.d.ts +8 -0
  528. package/dist/utils/directory-completions.d.ts.map +1 -1
  529. package/dist/utils/directory-completions.js +42 -1
  530. package/dist/utils/directory-completions.js.map +1 -1
  531. package/dist/utils/exif-orientation.d.ts.map +1 -1
  532. package/dist/utils/exif-orientation.js.map +1 -1
  533. package/dist/utils/frontmatter.d.ts.map +1 -1
  534. package/dist/utils/frontmatter.js.map +1 -1
  535. package/dist/utils/fs-watch.d.ts.map +1 -1
  536. package/dist/utils/fs-watch.js.map +1 -1
  537. package/dist/utils/git.d.ts.map +1 -1
  538. package/dist/utils/git.js.map +1 -1
  539. package/dist/utils/grip-user-agent.d.ts.map +1 -1
  540. package/dist/utils/grip-user-agent.js.map +1 -1
  541. package/dist/utils/html.d.ts.map +1 -1
  542. package/dist/utils/html.js.map +1 -1
  543. package/dist/utils/image-convert.d.ts.map +1 -1
  544. package/dist/utils/image-convert.js.map +1 -1
  545. package/dist/utils/image-process.d.ts.map +1 -1
  546. package/dist/utils/image-process.js.map +1 -1
  547. package/dist/utils/image-resize-core.d.ts.map +1 -1
  548. package/dist/utils/image-resize-core.js.map +1 -1
  549. package/dist/utils/image-resize-worker.d.ts.map +1 -1
  550. package/dist/utils/image-resize-worker.js.map +1 -1
  551. package/dist/utils/image-resize.d.ts.map +1 -1
  552. package/dist/utils/image-resize.js.map +1 -1
  553. package/dist/utils/json.d.ts.map +1 -1
  554. package/dist/utils/json.js.map +1 -1
  555. package/dist/utils/mime.d.ts.map +1 -1
  556. package/dist/utils/mime.js.map +1 -1
  557. package/dist/utils/open-browser.d.ts.map +1 -1
  558. package/dist/utils/open-browser.js.map +1 -1
  559. package/dist/utils/paths.d.ts.map +1 -1
  560. package/dist/utils/paths.js.map +1 -1
  561. package/dist/utils/photon.d.ts.map +1 -1
  562. package/dist/utils/photon.js +10 -5
  563. package/dist/utils/photon.js.map +1 -1
  564. package/dist/utils/shell.d.ts.map +1 -1
  565. package/dist/utils/shell.js.map +1 -1
  566. package/dist/utils/sleep.d.ts.map +1 -1
  567. package/dist/utils/sleep.js.map +1 -1
  568. package/dist/utils/syntax-highlight.d.ts.map +1 -1
  569. package/dist/utils/syntax-highlight.js +1 -1
  570. package/dist/utils/syntax-highlight.js.map +1 -1
  571. package/dist/utils/tools-manager.d.ts.map +1 -1
  572. package/dist/utils/tools-manager.js.map +1 -1
  573. package/dist/utils/version-check.d.ts.map +1 -1
  574. package/dist/utils/version-check.js.map +1 -1
  575. package/dist/utils/windows-self-update.d.ts.map +1 -1
  576. package/dist/utils/windows-self-update.js.map +1 -1
  577. package/docs/extensions.md +31 -1
  578. package/docs/sandbox.md +6 -0
  579. package/docs/sessions.md +1 -1
  580. package/docs/skills.md +4 -4
  581. package/docs/usage.md +2 -1
  582. package/examples/extensions/custom-provider-anthropic/package.json +2 -2
  583. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  584. package/examples/extensions/sandbox/package.json +2 -2
  585. package/examples/extensions/with-deps/package.json +1 -1
  586. package/npm-shrinkwrap.json +602 -834
  587. package/package.json +20 -21
@@ -1 +1 @@
1
- {"version":3,"file":"prompt-templates.d.ts","sourceRoot":"","sources":["../../src/core/prompt-templates.ts"],"names":[],"mappings":"AAKA,OAAO,EAA6B,KAAK,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAE5D;;GAEG;AACH,MAAM,WAAW,cAAc;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,UAAU,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC;CACjB;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,EAAE,CA+B7D;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,CAkCtE;AA2ED,MAAM,WAAW,0BAA0B;IAC1C,qDAAqD;IACrD,GAAG,EAAE,MAAM,CAAC;IACZ,mDAAmD;IACnD,QAAQ,EAAE,MAAM,CAAC;IACjB,6DAA6D;IAC7D,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,0CAA0C;IAC1C,eAAe,EAAE,OAAO,CAAC;CACzB;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,0BAA0B,GAAG,cAAc,EAAE,CAqEzF;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,cAAc,EAAE,GAAG,MAAM,CAgBtF;AAqED,MAAM,WAAW,wCAAyC,SAAQ,0BAA0B;IAC3F,UAAU,EAAE,cAAc,CAAC;CAC3B;AAED,wBAAsB,iCAAiC,CACtD,OAAO,EAAE,wCAAwC,GAC/C,OAAO,CAAC,cAAc,EAAE,CAAC,CAkD3B","sourcesContent":["import { existsSync, readdirSync, readFileSync, statSync } from \"fs\";\nimport { basename, dirname, join, resolve, sep } from \"path\";\nimport { CONFIG_DIR_NAME } from \"../config.ts\";\nimport { parseFrontmatter } from \"../utils/frontmatter.ts\";\nimport { resolvePath } from \"../utils/paths.ts\";\nimport { createSyntheticSourceInfo, type SourceInfo } from \"./source-info.ts\";\nimport type { ToolOperations } from \"./tools/operations.ts\";\n\n/**\n * Represents a prompt template loaded from a markdown file\n */\nexport interface PromptTemplate {\n\tname: string;\n\tdescription: string;\n\targumentHint?: string;\n\tcontent: string;\n\tsourceInfo: SourceInfo;\n\tfilePath: string; // Absolute path to the template file\n}\n\n/**\n * Parse command arguments respecting quoted strings (bash-style)\n * Returns array of arguments\n */\nexport function parseCommandArgs(argsString: string): string[] {\n\tconst args: string[] = [];\n\tlet current = \"\";\n\tlet inQuote: string | null = null;\n\n\tfor (let i = 0; i < argsString.length; i++) {\n\t\tconst char = argsString[i];\n\n\t\tif (inQuote) {\n\t\t\tif (char === inQuote) {\n\t\t\t\tinQuote = null;\n\t\t\t} else {\n\t\t\t\tcurrent += char;\n\t\t\t}\n\t\t} else if (char === '\"' || char === \"'\") {\n\t\t\tinQuote = char;\n\t\t} else if (/\\s/.test(char)) {\n\t\t\tif (current) {\n\t\t\t\targs.push(current);\n\t\t\t\tcurrent = \"\";\n\t\t\t}\n\t\t} else {\n\t\t\tcurrent += char;\n\t\t}\n\t}\n\n\tif (current) {\n\t\targs.push(current);\n\t}\n\n\treturn args;\n}\n\n/**\n * Substitute argument placeholders in template content\n * Supports:\n * - $1, $2, ... for positional args\n * - $@ and $ARGUMENTS for all args\n * - ${@:N} for args from Nth onwards (bash-style slicing)\n * - ${@:N:L} for L args starting from Nth\n *\n * Note: Replacement happens on the template string only. Argument values\n * containing patterns like $1, $@, or $ARGUMENTS are NOT recursively substituted.\n */\nexport function substituteArgs(content: string, args: string[]): string {\n\tlet result = content;\n\n\t// Replace $1, $2, etc. with positional args FIRST (before wildcards)\n\t// This prevents wildcard replacement values containing $<digit> patterns from being re-substituted\n\tresult = result.replace(/\\$(\\d+)/g, (_, num) => {\n\t\tconst index = parseInt(num, 10) - 1;\n\t\treturn args[index] ?? \"\";\n\t});\n\n\t// Replace ${@:start} or ${@:start:length} with sliced args (bash-style)\n\t// Process BEFORE simple $@ to avoid conflicts\n\tresult = result.replace(/\\$\\{@:(\\d+)(?::(\\d+))?\\}/g, (_, startStr, lengthStr) => {\n\t\tlet start = parseInt(startStr, 10) - 1; // Convert to 0-indexed (user provides 1-indexed)\n\t\t// Treat 0 as 1 (bash convention: args start at 1)\n\t\tif (start < 0) start = 0;\n\n\t\tif (lengthStr) {\n\t\t\tconst length = parseInt(lengthStr, 10);\n\t\t\treturn args.slice(start, start + length).join(\" \");\n\t\t}\n\t\treturn args.slice(start).join(\" \");\n\t});\n\n\t// Pre-compute all args joined (optimization)\n\tconst allArgs = args.join(\" \");\n\n\t// Replace $ARGUMENTS with all args joined (new syntax, aligns with Claude, Codex, OpenCode)\n\tresult = result.replace(/\\$ARGUMENTS/g, allArgs);\n\n\t// Replace $@ with all args joined (existing syntax)\n\tresult = result.replace(/\\$@/g, allArgs);\n\n\treturn result;\n}\n\nfunction loadTemplateFromFile(filePath: string, sourceInfo: SourceInfo): PromptTemplate | null {\n\ttry {\n\t\tconst rawContent = readFileSync(filePath, \"utf-8\");\n\t\tconst { frontmatter, body } = parseFrontmatter<Record<string, string>>(rawContent);\n\n\t\tconst name = basename(filePath).replace(/\\.md$/, \"\");\n\n\t\t// Get description from frontmatter or first non-empty line\n\t\tlet description = frontmatter.description || \"\";\n\t\tif (!description) {\n\t\t\tconst firstLine = body.split(\"\\n\").find((line) => line.trim());\n\t\t\tif (firstLine) {\n\t\t\t\t// Truncate if too long\n\t\t\t\tdescription = firstLine.slice(0, 60);\n\t\t\t\tif (firstLine.length > 60) description += \"...\";\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\tname,\n\t\t\tdescription,\n\t\t\t...(frontmatter[\"argument-hint\"] && { argumentHint: frontmatter[\"argument-hint\"] }),\n\t\t\tcontent: body,\n\t\t\tsourceInfo,\n\t\t\tfilePath,\n\t\t};\n\t} catch {\n\t\treturn null;\n\t}\n}\n\n/**\n * Scan a directory for .md files (non-recursive) and load them as prompt templates.\n */\nfunction loadTemplatesFromDir(dir: string, getSourceInfo: (filePath: string) => SourceInfo): PromptTemplate[] {\n\tconst templates: PromptTemplate[] = [];\n\n\tif (!existsSync(dir)) {\n\t\treturn templates;\n\t}\n\n\ttry {\n\t\tconst entries = readdirSync(dir, { withFileTypes: true });\n\n\t\tfor (const entry of entries) {\n\t\t\tconst fullPath = join(dir, entry.name);\n\n\t\t\t// For symlinks, check if they point to a file\n\t\t\tlet isFile = entry.isFile();\n\t\t\tif (entry.isSymbolicLink()) {\n\t\t\t\ttry {\n\t\t\t\t\tconst stats = statSync(fullPath);\n\t\t\t\t\tisFile = stats.isFile();\n\t\t\t\t} catch {\n\t\t\t\t\t// Broken symlink, skip it\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (isFile && entry.name.endsWith(\".md\")) {\n\t\t\t\tconst template = loadTemplateFromFile(fullPath, getSourceInfo(fullPath));\n\t\t\t\tif (template) {\n\t\t\t\t\ttemplates.push(template);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t} catch {\n\t\treturn templates;\n\t}\n\n\treturn templates;\n}\n\nexport interface LoadPromptTemplatesOptions {\n\t/** Working directory for project-local templates. */\n\tcwd: string;\n\t/** Agent config directory for global templates. */\n\tagentDir: string;\n\t/** Explicit prompt template paths (files or directories). */\n\tpromptPaths: string[];\n\t/** Include default prompt directories. */\n\tincludeDefaults: boolean;\n}\n\n/**\n * Load all prompt templates from:\n * 1. Global: agentDir/prompts/\n * 2. Project: cwd/{CONFIG_DIR_NAME}/prompts/\n * 3. Explicit prompt paths\n */\nexport function loadPromptTemplates(options: LoadPromptTemplatesOptions): PromptTemplate[] {\n\tconst resolvedCwd = resolvePath(options.cwd);\n\tconst resolvedAgentDir = resolvePath(options.agentDir);\n\tconst promptPaths = options.promptPaths;\n\tconst includeDefaults = options.includeDefaults;\n\n\tconst templates: PromptTemplate[] = [];\n\n\tconst globalPromptsDir = join(resolvedAgentDir, \"prompts\");\n\tconst projectPromptsDir = resolve(resolvedCwd, CONFIG_DIR_NAME, \"prompts\");\n\n\tconst isUnderPath = (target: string, root: string): boolean => {\n\t\tconst normalizedRoot = resolve(root);\n\t\tif (target === normalizedRoot) {\n\t\t\treturn true;\n\t\t}\n\t\tconst prefix = normalizedRoot.endsWith(sep) ? normalizedRoot : `${normalizedRoot}${sep}`;\n\t\treturn target.startsWith(prefix);\n\t};\n\n\tconst getSourceInfo = (resolvedPath: string): SourceInfo => {\n\t\tif (isUnderPath(resolvedPath, globalPromptsDir)) {\n\t\t\treturn createSyntheticSourceInfo(resolvedPath, {\n\t\t\t\tsource: \"local\",\n\t\t\t\tscope: \"user\",\n\t\t\t\tbaseDir: globalPromptsDir,\n\t\t\t});\n\t\t}\n\t\tif (isUnderPath(resolvedPath, projectPromptsDir)) {\n\t\t\treturn createSyntheticSourceInfo(resolvedPath, {\n\t\t\t\tsource: \"local\",\n\t\t\t\tscope: \"project\",\n\t\t\t\tbaseDir: projectPromptsDir,\n\t\t\t});\n\t\t}\n\t\treturn createSyntheticSourceInfo(resolvedPath, {\n\t\t\tsource: \"local\",\n\t\t\tbaseDir: statSync(resolvedPath).isDirectory() ? resolvedPath : dirname(resolvedPath),\n\t\t});\n\t};\n\n\tif (includeDefaults) {\n\t\ttemplates.push(...loadTemplatesFromDir(globalPromptsDir, getSourceInfo));\n\t\ttemplates.push(...loadTemplatesFromDir(projectPromptsDir, getSourceInfo));\n\t}\n\n\t// 3. Load explicit prompt paths\n\tfor (const rawPath of promptPaths) {\n\t\tconst resolvedPath = resolvePath(rawPath, resolvedCwd, { trim: true });\n\t\tif (!existsSync(resolvedPath)) {\n\t\t\tcontinue;\n\t\t}\n\n\t\ttry {\n\t\t\tconst stats = statSync(resolvedPath);\n\t\t\tif (stats.isDirectory()) {\n\t\t\t\ttemplates.push(...loadTemplatesFromDir(resolvedPath, getSourceInfo));\n\t\t\t} else if (stats.isFile() && resolvedPath.endsWith(\".md\")) {\n\t\t\t\tconst template = loadTemplateFromFile(resolvedPath, getSourceInfo(resolvedPath));\n\t\t\t\tif (template) {\n\t\t\t\t\ttemplates.push(template);\n\t\t\t\t}\n\t\t\t}\n\t\t} catch {\n\t\t\t// Ignore read failures\n\t\t}\n\t}\n\n\treturn templates;\n}\n\n/**\n * Expand a prompt template if it matches a template name.\n * Returns the expanded content or the original text if not a template.\n */\nexport function expandPromptTemplate(text: string, templates: PromptTemplate[]): string {\n\tif (!text.startsWith(\"/\")) return text;\n\n\tconst match = text.match(/^\\/([^\\s]+)(?:\\s+([\\s\\S]*))?$/);\n\tif (!match) return text;\n\n\tconst templateName = match[1];\n\tconst argsString = match[2] ?? \"\";\n\n\tconst template = templates.find((t) => t.name === templateName);\n\tif (template) {\n\t\tconst args = parseCommandArgs(argsString);\n\t\treturn substituteArgs(template.content, args);\n\t}\n\n\treturn text;\n}\n\nasync function backendPathExists(operations: ToolOperations, path: string): Promise<boolean> {\n\ttry {\n\t\tawait operations.access(path, \"exists\");\n\t\treturn true;\n\t} catch {\n\t\treturn false;\n\t}\n}\n\nasync function loadTemplateFromFileWithOperations(\n\toperations: ToolOperations,\n\tfilePath: string,\n\tsourceInfo: SourceInfo,\n): Promise<PromptTemplate | null> {\n\ttry {\n\t\tconst rawContent = (await operations.readFile(filePath)).toString(\"utf-8\");\n\t\tconst { frontmatter, body } = parseFrontmatter<Record<string, string>>(rawContent);\n\t\tconst name = basename(filePath).replace(/\\.md$/, \"\");\n\t\tlet description = frontmatter.description || \"\";\n\t\tif (!description) {\n\t\t\tconst firstLine = body.split(\"\\n\").find((line) => line.trim());\n\t\t\tif (firstLine) {\n\t\t\t\tdescription = firstLine.slice(0, 60);\n\t\t\t\tif (firstLine.length > 60) description += \"...\";\n\t\t\t}\n\t\t}\n\t\treturn {\n\t\t\tname,\n\t\t\tdescription,\n\t\t\t...(frontmatter[\"argument-hint\"] && { argumentHint: frontmatter[\"argument-hint\"] }),\n\t\t\tcontent: body,\n\t\t\tsourceInfo,\n\t\t\tfilePath,\n\t\t};\n\t} catch {\n\t\treturn null;\n\t}\n}\n\nasync function loadTemplatesFromDirWithOperations(\n\toperations: ToolOperations,\n\tdir: string,\n\tgetSourceInfo: (filePath: string) => SourceInfo,\n): Promise<PromptTemplate[]> {\n\tconst templates: PromptTemplate[] = [];\n\tif (!(await backendPathExists(operations, dir))) return templates;\n\ttry {\n\t\tconst entries = await operations.readdir(dir);\n\t\tfor (const name of entries) {\n\t\t\tconst fullPath = join(dir, name);\n\t\t\tlet isFile = false;\n\t\t\ttry {\n\t\t\t\tisFile = (await operations.stat(fullPath)).isFile();\n\t\t\t} catch {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (isFile && name.endsWith(\".md\")) {\n\t\t\t\tconst template = await loadTemplateFromFileWithOperations(operations, fullPath, getSourceInfo(fullPath));\n\t\t\t\tif (template) templates.push(template);\n\t\t\t}\n\t\t}\n\t} catch {\n\t\treturn templates;\n\t}\n\treturn templates;\n}\n\nexport interface LoadPromptTemplatesWithOperationsOptions extends LoadPromptTemplatesOptions {\n\toperations: ToolOperations;\n}\n\nexport async function loadPromptTemplatesWithOperations(\n\toptions: LoadPromptTemplatesWithOperationsOptions,\n): Promise<PromptTemplate[]> {\n\tconst resolvedCwd = resolvePath(options.cwd);\n\tconst resolvedAgentDir = resolvePath(options.agentDir);\n\tconst promptPaths = options.promptPaths;\n\tconst includeDefaults = options.includeDefaults;\n\tconst operations = options.operations;\n\tconst templates: PromptTemplate[] = [];\n\tconst globalPromptsDir = join(resolvedAgentDir, \"prompts\");\n\tconst projectPromptsDir = resolve(resolvedCwd, CONFIG_DIR_NAME, \"prompts\");\n\tconst isUnderPath = (target: string, root: string): boolean => {\n\t\tconst normalizedRoot = resolve(root);\n\t\tif (target === normalizedRoot) return true;\n\t\tconst prefix = normalizedRoot.endsWith(sep) ? normalizedRoot : `${normalizedRoot}${sep}`;\n\t\treturn target.startsWith(prefix);\n\t};\n\tconst getSourceInfo = (resolvedPath: string): SourceInfo => {\n\t\tif (isUnderPath(resolvedPath, globalPromptsDir)) {\n\t\t\treturn createSyntheticSourceInfo(resolvedPath, { source: \"local\", scope: \"user\", baseDir: globalPromptsDir });\n\t\t}\n\t\tif (isUnderPath(resolvedPath, projectPromptsDir)) {\n\t\t\treturn createSyntheticSourceInfo(resolvedPath, {\n\t\t\t\tsource: \"remote\",\n\t\t\t\tscope: \"project\",\n\t\t\t\tbaseDir: projectPromptsDir,\n\t\t\t});\n\t\t}\n\t\treturn createSyntheticSourceInfo(resolvedPath, { source: \"remote\", baseDir: dirname(resolvedPath) });\n\t};\n\tif (includeDefaults) {\n\t\ttemplates.push(...(await loadTemplatesFromDirWithOperations(operations, globalPromptsDir, getSourceInfo)));\n\t\ttemplates.push(...(await loadTemplatesFromDirWithOperations(operations, projectPromptsDir, getSourceInfo)));\n\t}\n\tfor (const rawPath of promptPaths) {\n\t\tconst resolvedPath = resolvePath(rawPath, resolvedCwd, { trim: true });\n\t\tif (!(await backendPathExists(operations, resolvedPath))) continue;\n\t\ttry {\n\t\t\tconst stats = await operations.stat(resolvedPath);\n\t\t\tif (stats.isDirectory()) {\n\t\t\t\ttemplates.push(...(await loadTemplatesFromDirWithOperations(operations, resolvedPath, getSourceInfo)));\n\t\t\t} else if (stats.isFile() && resolvedPath.endsWith(\".md\")) {\n\t\t\t\tconst template = await loadTemplateFromFileWithOperations(\n\t\t\t\t\toperations,\n\t\t\t\t\tresolvedPath,\n\t\t\t\t\tgetSourceInfo(resolvedPath),\n\t\t\t\t);\n\t\t\t\tif (template) templates.push(template);\n\t\t\t}\n\t\t} catch {}\n\t}\n\treturn templates;\n}\n"]}
1
+ {"version":3,"file":"prompt-templates.d.ts","sourceRoot":"","sources":["../../src/core/prompt-templates.ts"],"names":[],"mappings":"AAKA,OAAO,EAA6B,KAAK,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAE5D;;GAEG;AACH,MAAM,WAAW,cAAc;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,UAAU,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC;CACjB;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,EAAE,CA+B7D;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,CAkCtE;AA2ED,MAAM,WAAW,0BAA0B;IAC1C,qDAAqD;IACrD,GAAG,EAAE,MAAM,CAAC;IACZ,mDAAmD;IACnD,QAAQ,EAAE,MAAM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AAM,IAAI,KAAK,CAAC,MAAM,EAAE,IAAI,YAAY,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;gBAC3D,MAAM,QAAQ,GAAG,MAAM,kCAAkC,CACxD,UAAU,EACV,YAAY,EACZ,aAAa,CAAC,YAAY,CAAC,CAC3B,CAAC;gBACF,IAAI,QAAQ;oBAAE,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YACxC,CAAC;QACF,CAAC;QAAC,MAAM,CAAC,CAAA,CAAC;IACX,CAAC;IACD,OAAO,SAAS,CAAC;AAAA,CACjB","sourcesContent":["import { existsSync, readdirSync, readFileSync, statSync } from \"fs\";\nimport { basename, dirname, join, resolve, sep } from \"path\";\nimport { CONFIG_DIR_NAME } from \"../config.ts\";\nimport { parseFrontmatter } from \"../utils/frontmatter.ts\";\nimport { resolvePath } from \"../utils/paths.ts\";\nimport { createSyntheticSourceInfo, type SourceInfo } from \"./source-info.ts\";\nimport type { ToolOperations } from \"./tools/operations.ts\";\n\n/**\n * Represents a prompt template loaded from a markdown file\n */\nexport interface PromptTemplate {\n\tname: string;\n\tdescription: string;\n\targumentHint?: string;\n\tcontent: string;\n\tsourceInfo: SourceInfo;\n\tfilePath: string; // Absolute path to the template file\n}\n\n/**\n * Parse command arguments respecting quoted strings (bash-style)\n * Returns array of arguments\n */\nexport function parseCommandArgs(argsString: string): string[] {\n\tconst args: string[] = [];\n\tlet current = \"\";\n\tlet inQuote: string | null = null;\n\n\tfor (let i = 0; i < argsString.length; i++) {\n\t\tconst char = argsString[i];\n\n\t\tif (inQuote) {\n\t\t\tif (char === inQuote) {\n\t\t\t\tinQuote = null;\n\t\t\t} else {\n\t\t\t\tcurrent += char;\n\t\t\t}\n\t\t} else if (char === '\"' || char === \"'\") {\n\t\t\tinQuote = char;\n\t\t} else if (/\\s/.test(char)) {\n\t\t\tif (current) {\n\t\t\t\targs.push(current);\n\t\t\t\tcurrent = \"\";\n\t\t\t}\n\t\t} else {\n\t\t\tcurrent += char;\n\t\t}\n\t}\n\n\tif (current) {\n\t\targs.push(current);\n\t}\n\n\treturn args;\n}\n\n/**\n * Substitute argument placeholders in template content\n * Supports:\n * - $1, $2, ... for positional args\n * - $@ and $ARGUMENTS for all args\n * - ${@:N} for args from Nth onwards (bash-style slicing)\n * - ${@:N:L} for L args starting from Nth\n *\n * Note: Replacement happens on the template string only. Argument values\n * containing patterns like $1, $@, or $ARGUMENTS are NOT recursively substituted.\n */\nexport function substituteArgs(content: string, args: string[]): string {\n\tlet result = content;\n\n\t// Replace $1, $2, etc. with positional args FIRST (before wildcards)\n\t// This prevents wildcard replacement values containing $<digit> patterns from being re-substituted\n\tresult = result.replace(/\\$(\\d+)/g, (_, num) => {\n\t\tconst index = parseInt(num, 10) - 1;\n\t\treturn args[index] ?? \"\";\n\t});\n\n\t// Replace ${@:start} or ${@:start:length} with sliced args (bash-style)\n\t// Process BEFORE simple $@ to avoid conflicts\n\tresult = result.replace(/\\$\\{@:(\\d+)(?::(\\d+))?\\}/g, (_, startStr, lengthStr) => {\n\t\tlet start = parseInt(startStr, 10) - 1; // Convert to 0-indexed (user provides 1-indexed)\n\t\t// Treat 0 as 1 (bash convention: args start at 1)\n\t\tif (start < 0) start = 0;\n\n\t\tif (lengthStr) {\n\t\t\tconst length = parseInt(lengthStr, 10);\n\t\t\treturn args.slice(start, start + length).join(\" \");\n\t\t}\n\t\treturn args.slice(start).join(\" \");\n\t});\n\n\t// Pre-compute all args joined (optimization)\n\tconst allArgs = args.join(\" \");\n\n\t// Replace $ARGUMENTS with all args joined (new syntax, aligns with Claude, Codex, OpenCode)\n\tresult = result.replace(/\\$ARGUMENTS/g, allArgs);\n\n\t// Replace $@ with all args joined (existing syntax)\n\tresult = result.replace(/\\$@/g, allArgs);\n\n\treturn result;\n}\n\nfunction loadTemplateFromFile(filePath: string, sourceInfo: SourceInfo): PromptTemplate | null {\n\ttry {\n\t\tconst rawContent = readFileSync(filePath, \"utf-8\");\n\t\tconst { frontmatter, body } = parseFrontmatter<Record<string, string>>(rawContent);\n\n\t\tconst name = basename(filePath).replace(/\\.md$/, \"\");\n\n\t\t// Get description from frontmatter or first non-empty line\n\t\tlet description = frontmatter.description || \"\";\n\t\tif (!description) {\n\t\t\tconst firstLine = body.split(\"\\n\").find((line) => line.trim());\n\t\t\tif (firstLine) {\n\t\t\t\t// Truncate if too long\n\t\t\t\tdescription = firstLine.slice(0, 60);\n\t\t\t\tif (firstLine.length > 60) description += \"...\";\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\tname,\n\t\t\tdescription,\n\t\t\t...(frontmatter[\"argument-hint\"] && { argumentHint: frontmatter[\"argument-hint\"] }),\n\t\t\tcontent: body,\n\t\t\tsourceInfo,\n\t\t\tfilePath,\n\t\t};\n\t} catch {\n\t\treturn null;\n\t}\n}\n\n/**\n * Scan a directory for .md files (non-recursive) and load them as prompt templates.\n */\nfunction loadTemplatesFromDir(dir: string, getSourceInfo: (filePath: string) => SourceInfo): PromptTemplate[] {\n\tconst templates: PromptTemplate[] = [];\n\n\tif (!existsSync(dir)) {\n\t\treturn templates;\n\t}\n\n\ttry {\n\t\tconst entries = readdirSync(dir, { withFileTypes: true });\n\n\t\tfor (const entry of entries) {\n\t\t\tconst fullPath = join(dir, entry.name);\n\n\t\t\t// For symlinks, check if they point to a file\n\t\t\tlet isFile = entry.isFile();\n\t\t\tif (entry.isSymbolicLink()) {\n\t\t\t\ttry {\n\t\t\t\t\tconst stats = statSync(fullPath);\n\t\t\t\t\tisFile = stats.isFile();\n\t\t\t\t} catch {\n\t\t\t\t\t// Broken symlink, skip it\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (isFile && entry.name.endsWith(\".md\")) {\n\t\t\t\tconst template = loadTemplateFromFile(fullPath, getSourceInfo(fullPath));\n\t\t\t\tif (template) {\n\t\t\t\t\ttemplates.push(template);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t} catch {\n\t\treturn templates;\n\t}\n\n\treturn templates;\n}\n\nexport interface LoadPromptTemplatesOptions {\n\t/** Working directory for project-local templates. */\n\tcwd: string;\n\t/** Agent config directory for global templates. */\n\tagentDir: string;\n\t/** Explicit prompt template paths (files or directories). */\n\tpromptPaths: string[];\n\t/** Include default prompt directories. */\n\tincludeDefaults: boolean;\n}\n\n/**\n * Load all prompt templates from:\n * 1. Global: agentDir/prompts/\n * 2. Project: cwd/{CONFIG_DIR_NAME}/prompts/\n * 3. Explicit prompt paths\n */\nexport function loadPromptTemplates(options: LoadPromptTemplatesOptions): PromptTemplate[] {\n\tconst resolvedCwd = resolvePath(options.cwd);\n\tconst resolvedAgentDir = resolvePath(options.agentDir);\n\tconst promptPaths = options.promptPaths;\n\tconst includeDefaults = options.includeDefaults;\n\n\tconst templates: PromptTemplate[] = [];\n\n\tconst globalPromptsDir = join(resolvedAgentDir, \"prompts\");\n\tconst projectPromptsDir = resolve(resolvedCwd, CONFIG_DIR_NAME, \"prompts\");\n\n\tconst isUnderPath = (target: string, root: string): boolean => {\n\t\tconst normalizedRoot = resolve(root);\n\t\tif (target === normalizedRoot) {\n\t\t\treturn true;\n\t\t}\n\t\tconst prefix = normalizedRoot.endsWith(sep) ? normalizedRoot : `${normalizedRoot}${sep}`;\n\t\treturn target.startsWith(prefix);\n\t};\n\n\tconst getSourceInfo = (resolvedPath: string): SourceInfo => {\n\t\tif (isUnderPath(resolvedPath, globalPromptsDir)) {\n\t\t\treturn createSyntheticSourceInfo(resolvedPath, {\n\t\t\t\tsource: \"local\",\n\t\t\t\tscope: \"user\",\n\t\t\t\tbaseDir: globalPromptsDir,\n\t\t\t});\n\t\t}\n\t\tif (isUnderPath(resolvedPath, projectPromptsDir)) {\n\t\t\treturn createSyntheticSourceInfo(resolvedPath, {\n\t\t\t\tsource: \"local\",\n\t\t\t\tscope: \"project\",\n\t\t\t\tbaseDir: projectPromptsDir,\n\t\t\t});\n\t\t}\n\t\treturn createSyntheticSourceInfo(resolvedPath, {\n\t\t\tsource: \"local\",\n\t\t\tbaseDir: statSync(resolvedPath).isDirectory() ? resolvedPath : dirname(resolvedPath),\n\t\t});\n\t};\n\n\tif (includeDefaults) {\n\t\ttemplates.push(...loadTemplatesFromDir(globalPromptsDir, getSourceInfo));\n\t\ttemplates.push(...loadTemplatesFromDir(projectPromptsDir, getSourceInfo));\n\t}\n\n\t// 3. Load explicit prompt paths\n\tfor (const rawPath of promptPaths) {\n\t\tconst resolvedPath = resolvePath(rawPath, resolvedCwd, { trim: true });\n\t\tif (!existsSync(resolvedPath)) {\n\t\t\tcontinue;\n\t\t}\n\n\t\ttry {\n\t\t\tconst stats = statSync(resolvedPath);\n\t\t\tif (stats.isDirectory()) {\n\t\t\t\ttemplates.push(...loadTemplatesFromDir(resolvedPath, getSourceInfo));\n\t\t\t} else if (stats.isFile() && resolvedPath.endsWith(\".md\")) {\n\t\t\t\tconst template = loadTemplateFromFile(resolvedPath, getSourceInfo(resolvedPath));\n\t\t\t\tif (template) {\n\t\t\t\t\ttemplates.push(template);\n\t\t\t\t}\n\t\t\t}\n\t\t} catch {\n\t\t\t// Ignore read failures\n\t\t}\n\t}\n\n\treturn templates;\n}\n\n/**\n * Expand a prompt template if it matches a template name.\n * Returns the expanded content or the original text if not a template.\n */\nexport function expandPromptTemplate(text: string, templates: PromptTemplate[]): string {\n\tif (!text.startsWith(\"/\")) return text;\n\n\tconst match = text.match(/^\\/([^\\s]+)(?:\\s+([\\s\\S]*))?$/);\n\tif (!match) return text;\n\n\tconst templateName = match[1];\n\tconst argsString = match[2] ?? \"\";\n\n\tconst template = templates.find((t) => t.name === templateName);\n\tif (template) {\n\t\tconst args = parseCommandArgs(argsString);\n\t\treturn substituteArgs(template.content, args);\n\t}\n\n\treturn text;\n}\n\nasync function backendPathExists(operations: ToolOperations, path: string): Promise<boolean> {\n\ttry {\n\t\tawait operations.access(path, \"exists\");\n\t\treturn true;\n\t} catch {\n\t\treturn false;\n\t}\n}\n\nasync function loadTemplateFromFileWithOperations(\n\toperations: ToolOperations,\n\tfilePath: string,\n\tsourceInfo: SourceInfo,\n): Promise<PromptTemplate | null> {\n\ttry {\n\t\tconst rawContent = (await operations.readFile(filePath)).toString(\"utf-8\");\n\t\tconst { frontmatter, body } = parseFrontmatter<Record<string, string>>(rawContent);\n\t\tconst name = basename(filePath).replace(/\\.md$/, \"\");\n\t\tlet description = frontmatter.description || \"\";\n\t\tif (!description) {\n\t\t\tconst firstLine = body.split(\"\\n\").find((line) => line.trim());\n\t\t\tif (firstLine) {\n\t\t\t\tdescription = firstLine.slice(0, 60);\n\t\t\t\tif (firstLine.length > 60) description += \"...\";\n\t\t\t}\n\t\t}\n\t\treturn {\n\t\t\tname,\n\t\t\tdescription,\n\t\t\t...(frontmatter[\"argument-hint\"] && { argumentHint: frontmatter[\"argument-hint\"] }),\n\t\t\tcontent: body,\n\t\t\tsourceInfo,\n\t\t\tfilePath,\n\t\t};\n\t} catch {\n\t\treturn null;\n\t}\n}\n\nasync function loadTemplatesFromDirWithOperations(\n\toperations: ToolOperations,\n\tdir: string,\n\tgetSourceInfo: (filePath: string) => SourceInfo,\n): Promise<PromptTemplate[]> {\n\tconst templates: PromptTemplate[] = [];\n\tif (!(await backendPathExists(operations, dir))) return templates;\n\ttry {\n\t\tconst entries = await operations.readdir(dir);\n\t\tfor (const name of entries) {\n\t\t\tconst fullPath = join(dir, name);\n\t\t\tlet isFile = false;\n\t\t\ttry {\n\t\t\t\tisFile = (await operations.stat(fullPath)).isFile();\n\t\t\t} catch {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (isFile && name.endsWith(\".md\")) {\n\t\t\t\tconst template = await loadTemplateFromFileWithOperations(operations, fullPath, getSourceInfo(fullPath));\n\t\t\t\tif (template) templates.push(template);\n\t\t\t}\n\t\t}\n\t} catch {\n\t\treturn templates;\n\t}\n\treturn templates;\n}\n\nexport interface LoadPromptTemplatesWithOperationsOptions extends LoadPromptTemplatesOptions {\n\toperations: ToolOperations;\n}\n\nexport async function loadPromptTemplatesWithOperations(\n\toptions: LoadPromptTemplatesWithOperationsOptions,\n): Promise<PromptTemplate[]> {\n\tconst resolvedCwd = resolvePath(options.cwd);\n\tconst resolvedAgentDir = resolvePath(options.agentDir);\n\tconst promptPaths = options.promptPaths;\n\tconst includeDefaults = options.includeDefaults;\n\tconst operations = options.operations;\n\tconst templates: PromptTemplate[] = [];\n\tconst globalPromptsDir = join(resolvedAgentDir, \"prompts\");\n\tconst projectPromptsDir = resolve(resolvedCwd, CONFIG_DIR_NAME, \"prompts\");\n\tconst isUnderPath = (target: string, root: string): boolean => {\n\t\tconst normalizedRoot = resolve(root);\n\t\tif (target === normalizedRoot) return true;\n\t\tconst prefix = normalizedRoot.endsWith(sep) ? normalizedRoot : `${normalizedRoot}${sep}`;\n\t\treturn target.startsWith(prefix);\n\t};\n\tconst getSourceInfo = (resolvedPath: string): SourceInfo => {\n\t\tif (isUnderPath(resolvedPath, globalPromptsDir)) {\n\t\t\treturn createSyntheticSourceInfo(resolvedPath, { source: \"local\", scope: \"user\", baseDir: globalPromptsDir });\n\t\t}\n\t\tif (isUnderPath(resolvedPath, projectPromptsDir)) {\n\t\t\treturn createSyntheticSourceInfo(resolvedPath, {\n\t\t\t\tsource: \"remote\",\n\t\t\t\tscope: \"project\",\n\t\t\t\tbaseDir: projectPromptsDir,\n\t\t\t});\n\t\t}\n\t\treturn createSyntheticSourceInfo(resolvedPath, { source: \"remote\", baseDir: dirname(resolvedPath) });\n\t};\n\tif (includeDefaults) {\n\t\ttemplates.push(...(await loadTemplatesFromDirWithOperations(operations, globalPromptsDir, getSourceInfo)));\n\t\ttemplates.push(...(await loadTemplatesFromDirWithOperations(operations, projectPromptsDir, getSourceInfo)));\n\t}\n\tfor (const rawPath of promptPaths) {\n\t\tconst resolvedPath = resolvePath(rawPath, resolvedCwd, { trim: true });\n\t\tif (!(await backendPathExists(operations, resolvedPath))) continue;\n\t\ttry {\n\t\t\tconst stats = await operations.stat(resolvedPath);\n\t\t\tif (stats.isDirectory()) {\n\t\t\t\ttemplates.push(...(await loadTemplatesFromDirWithOperations(operations, resolvedPath, getSourceInfo)));\n\t\t\t} else if (stats.isFile() && resolvedPath.endsWith(\".md\")) {\n\t\t\t\tconst template = await loadTemplateFromFileWithOperations(\n\t\t\t\t\toperations,\n\t\t\t\t\tresolvedPath,\n\t\t\t\t\tgetSourceInfo(resolvedPath),\n\t\t\t\t);\n\t\t\t\tif (template) templates.push(template);\n\t\t\t}\n\t\t} catch {}\n\t}\n\treturn templates;\n}\n"]}
1
+ {"version":3,"file":"prompt-templates.js","sourceRoot":"","sources":["../../src/core/prompt-templates.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC;AACrE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,yBAAyB,EAAmB,MAAM,kBAAkB,CAAC;AAe9E;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAAC,UAAkB;IAClD,MAAM,IAAI,GAAa,EAAE,CAAC;IAC1B,IAAI,OAAO,GAAG,EAAE,CAAC;IACjB,IAAI,OAAO,GAAkB,IAAI,CAAC;IAElC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,UAAU,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAC5C,MAAM,IAAI,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC;QAE3B,IAAI,OAAO,EAAE,CAAC;YACb,IAAI,IAAI,KAAK,OAAO,EAAE,CAAC;gBACtB,OAAO,GAAG,IAAI,CAAC;YAChB,CAAC;iBAAM,CAAC;gBACP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C,MAAM,CAAC,CAAA,CAAC;IACX,CAAC;IACD,OAAO,SAAS,CAAC;AAClB,CAAC","sourcesContent":["import { existsSync, readdirSync, readFileSync, statSync } from \"fs\";\nimport { basename, dirname, join, resolve, sep } from \"path\";\nimport { CONFIG_DIR_NAME } from \"../config.ts\";\nimport { parseFrontmatter } from \"../utils/frontmatter.ts\";\nimport { resolvePath } from \"../utils/paths.ts\";\nimport { createSyntheticSourceInfo, type SourceInfo } from \"./source-info.ts\";\nimport type { ToolOperations } from \"./tools/operations.ts\";\n\n/**\n * Represents a prompt template loaded from a markdown file\n */\nexport interface PromptTemplate {\n\tname: string;\n\tdescription: string;\n\targumentHint?: string;\n\tcontent: string;\n\tsourceInfo: SourceInfo;\n\tfilePath: string; // Absolute path to the template file\n}\n\n/**\n * Parse command arguments respecting quoted strings (bash-style)\n * Returns array of arguments\n */\nexport function parseCommandArgs(argsString: string): string[] {\n\tconst args: string[] = [];\n\tlet current = \"\";\n\tlet inQuote: string | null = null;\n\n\tfor (let i = 0; i < argsString.length; i++) {\n\t\tconst char = argsString[i];\n\n\t\tif (inQuote) {\n\t\t\tif (char === inQuote) {\n\t\t\t\tinQuote = null;\n\t\t\t} else {\n\t\t\t\tcurrent += char;\n\t\t\t}\n\t\t} else if (char === '\"' || char === \"'\") {\n\t\t\tinQuote = char;\n\t\t} else if (/\\s/.test(char)) {\n\t\t\tif (current) {\n\t\t\t\targs.push(current);\n\t\t\t\tcurrent = \"\";\n\t\t\t}\n\t\t} else {\n\t\t\tcurrent += char;\n\t\t}\n\t}\n\n\tif (current) {\n\t\targs.push(current);\n\t}\n\n\treturn args;\n}\n\n/**\n * Substitute argument placeholders in template content\n * Supports:\n * - $1, $2, ... for positional args\n * - $@ and $ARGUMENTS for all args\n * - ${@:N} for args from Nth onwards (bash-style slicing)\n * - ${@:N:L} for L args starting from Nth\n *\n * Note: Replacement happens on the template string only. Argument values\n * containing patterns like $1, $@, or $ARGUMENTS are NOT recursively substituted.\n */\nexport function substituteArgs(content: string, args: string[]): string {\n\tlet result = content;\n\n\t// Replace $1, $2, etc. with positional args FIRST (before wildcards)\n\t// This prevents wildcard replacement values containing $<digit> patterns from being re-substituted\n\tresult = result.replace(/\\$(\\d+)/g, (_, num) => {\n\t\tconst index = parseInt(num, 10) - 1;\n\t\treturn args[index] ?? \"\";\n\t});\n\n\t// Replace ${@:start} or ${@:start:length} with sliced args (bash-style)\n\t// Process BEFORE simple $@ to avoid conflicts\n\tresult = result.replace(/\\$\\{@:(\\d+)(?::(\\d+))?\\}/g, (_, startStr, lengthStr) => {\n\t\tlet start = parseInt(startStr, 10) - 1; // Convert to 0-indexed (user provides 1-indexed)\n\t\t// Treat 0 as 1 (bash convention: args start at 1)\n\t\tif (start < 0) start = 0;\n\n\t\tif (lengthStr) {\n\t\t\tconst length = parseInt(lengthStr, 10);\n\t\t\treturn args.slice(start, start + length).join(\" \");\n\t\t}\n\t\treturn args.slice(start).join(\" \");\n\t});\n\n\t// Pre-compute all args joined (optimization)\n\tconst allArgs = args.join(\" \");\n\n\t// Replace $ARGUMENTS with all args joined (new syntax, aligns with Claude, Codex, OpenCode)\n\tresult = result.replace(/\\$ARGUMENTS/g, allArgs);\n\n\t// Replace $@ with all args joined (existing syntax)\n\tresult = result.replace(/\\$@/g, allArgs);\n\n\treturn result;\n}\n\nfunction loadTemplateFromFile(filePath: string, sourceInfo: SourceInfo): PromptTemplate | null {\n\ttry {\n\t\tconst rawContent = readFileSync(filePath, \"utf-8\");\n\t\tconst { frontmatter, body } = parseFrontmatter<Record<string, string>>(rawContent);\n\n\t\tconst name = basename(filePath).replace(/\\.md$/, \"\");\n\n\t\t// Get description from frontmatter or first non-empty line\n\t\tlet description = frontmatter.description || \"\";\n\t\tif (!description) {\n\t\t\tconst firstLine = body.split(\"\\n\").find((line) => line.trim());\n\t\t\tif (firstLine) {\n\t\t\t\t// Truncate if too long\n\t\t\t\tdescription = firstLine.slice(0, 60);\n\t\t\t\tif (firstLine.length > 60) description += \"...\";\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\tname,\n\t\t\tdescription,\n\t\t\t...(frontmatter[\"argument-hint\"] && { argumentHint: frontmatter[\"argument-hint\"] }),\n\t\t\tcontent: body,\n\t\t\tsourceInfo,\n\t\t\tfilePath,\n\t\t};\n\t} catch {\n\t\treturn null;\n\t}\n}\n\n/**\n * Scan a directory for .md files (non-recursive) and load them as prompt templates.\n */\nfunction loadTemplatesFromDir(dir: string, getSourceInfo: (filePath: string) => SourceInfo): PromptTemplate[] {\n\tconst templates: PromptTemplate[] = [];\n\n\tif (!existsSync(dir)) {\n\t\treturn templates;\n\t}\n\n\ttry {\n\t\tconst entries = readdirSync(dir, { withFileTypes: true });\n\n\t\tfor (const entry of entries) {\n\t\t\tconst fullPath = join(dir, entry.name);\n\n\t\t\t// For symlinks, check if they point to a file\n\t\t\tlet isFile = entry.isFile();\n\t\t\tif (entry.isSymbolicLink()) {\n\t\t\t\ttry {\n\t\t\t\t\tconst stats = statSync(fullPath);\n\t\t\t\t\tisFile = stats.isFile();\n\t\t\t\t} catch {\n\t\t\t\t\t// Broken symlink, skip it\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (isFile && entry.name.endsWith(\".md\")) {\n\t\t\t\tconst template = loadTemplateFromFile(fullPath, getSourceInfo(fullPath));\n\t\t\t\tif (template) {\n\t\t\t\t\ttemplates.push(template);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t} catch {\n\t\treturn templates;\n\t}\n\n\treturn templates;\n}\n\nexport interface LoadPromptTemplatesOptions {\n\t/** Working directory for project-local templates. */\n\tcwd: string;\n\t/** Agent config directory for global templates. */\n\tagentDir: string;\n\t/** Explicit prompt template paths (files or directories). */\n\tpromptPaths: string[];\n\t/** Include default prompt directories. */\n\tincludeDefaults: boolean;\n}\n\n/**\n * Load all prompt templates from:\n * 1. Global: agentDir/prompts/\n * 2. Project: cwd/{CONFIG_DIR_NAME}/prompts/\n * 3. Explicit prompt paths\n */\nexport function loadPromptTemplates(options: LoadPromptTemplatesOptions): PromptTemplate[] {\n\tconst resolvedCwd = resolvePath(options.cwd);\n\tconst resolvedAgentDir = resolvePath(options.agentDir);\n\tconst promptPaths = options.promptPaths;\n\tconst includeDefaults = options.includeDefaults;\n\n\tconst templates: PromptTemplate[] = [];\n\n\tconst globalPromptsDir = join(resolvedAgentDir, \"prompts\");\n\tconst projectPromptsDir = resolve(resolvedCwd, CONFIG_DIR_NAME, \"prompts\");\n\n\tconst isUnderPath = (target: string, root: string): boolean => {\n\t\tconst normalizedRoot = resolve(root);\n\t\tif (target === normalizedRoot) {\n\t\t\treturn true;\n\t\t}\n\t\tconst prefix = normalizedRoot.endsWith(sep) ? normalizedRoot : `${normalizedRoot}${sep}`;\n\t\treturn target.startsWith(prefix);\n\t};\n\n\tconst getSourceInfo = (resolvedPath: string): SourceInfo => {\n\t\tif (isUnderPath(resolvedPath, globalPromptsDir)) {\n\t\t\treturn createSyntheticSourceInfo(resolvedPath, {\n\t\t\t\tsource: \"local\",\n\t\t\t\tscope: \"user\",\n\t\t\t\tbaseDir: globalPromptsDir,\n\t\t\t});\n\t\t}\n\t\tif (isUnderPath(resolvedPath, projectPromptsDir)) {\n\t\t\treturn createSyntheticSourceInfo(resolvedPath, {\n\t\t\t\tsource: \"local\",\n\t\t\t\tscope: \"project\",\n\t\t\t\tbaseDir: projectPromptsDir,\n\t\t\t});\n\t\t}\n\t\treturn createSyntheticSourceInfo(resolvedPath, {\n\t\t\tsource: \"local\",\n\t\t\tbaseDir: statSync(resolvedPath).isDirectory() ? resolvedPath : dirname(resolvedPath),\n\t\t});\n\t};\n\n\tif (includeDefaults) {\n\t\ttemplates.push(...loadTemplatesFromDir(globalPromptsDir, getSourceInfo));\n\t\ttemplates.push(...loadTemplatesFromDir(projectPromptsDir, getSourceInfo));\n\t}\n\n\t// 3. Load explicit prompt paths\n\tfor (const rawPath of promptPaths) {\n\t\tconst resolvedPath = resolvePath(rawPath, resolvedCwd, { trim: true });\n\t\tif (!existsSync(resolvedPath)) {\n\t\t\tcontinue;\n\t\t}\n\n\t\ttry {\n\t\t\tconst stats = statSync(resolvedPath);\n\t\t\tif (stats.isDirectory()) {\n\t\t\t\ttemplates.push(...loadTemplatesFromDir(resolvedPath, getSourceInfo));\n\t\t\t} else if (stats.isFile() && resolvedPath.endsWith(\".md\")) {\n\t\t\t\tconst template = loadTemplateFromFile(resolvedPath, getSourceInfo(resolvedPath));\n\t\t\t\tif (template) {\n\t\t\t\t\ttemplates.push(template);\n\t\t\t\t}\n\t\t\t}\n\t\t} catch {\n\t\t\t// Ignore read failures\n\t\t}\n\t}\n\n\treturn templates;\n}\n\n/**\n * Expand a prompt template if it matches a template name.\n * Returns the expanded content or the original text if not a template.\n */\nexport function expandPromptTemplate(text: string, templates: PromptTemplate[]): string {\n\tif (!text.startsWith(\"/\")) return text;\n\n\tconst match = text.match(/^\\/([^\\s]+)(?:\\s+([\\s\\S]*))?$/);\n\tif (!match) return text;\n\n\tconst templateName = match[1];\n\tconst argsString = match[2] ?? \"\";\n\n\tconst template = templates.find((t) => t.name === templateName);\n\tif (template) {\n\t\tconst args = parseCommandArgs(argsString);\n\t\treturn substituteArgs(template.content, args);\n\t}\n\n\treturn text;\n}\n\nasync function backendPathExists(operations: ToolOperations, path: string): Promise<boolean> {\n\ttry {\n\t\tawait operations.access(path, \"exists\");\n\t\treturn true;\n\t} catch {\n\t\treturn false;\n\t}\n}\n\nasync function loadTemplateFromFileWithOperations(\n\toperations: ToolOperations,\n\tfilePath: string,\n\tsourceInfo: SourceInfo,\n): Promise<PromptTemplate | null> {\n\ttry {\n\t\tconst rawContent = (await operations.readFile(filePath)).toString(\"utf-8\");\n\t\tconst { frontmatter, body } = parseFrontmatter<Record<string, string>>(rawContent);\n\t\tconst name = basename(filePath).replace(/\\.md$/, \"\");\n\t\tlet description = frontmatter.description || \"\";\n\t\tif (!description) {\n\t\t\tconst firstLine = body.split(\"\\n\").find((line) => line.trim());\n\t\t\tif (firstLine) {\n\t\t\t\tdescription = firstLine.slice(0, 60);\n\t\t\t\tif (firstLine.length > 60) description += \"...\";\n\t\t\t}\n\t\t}\n\t\treturn {\n\t\t\tname,\n\t\t\tdescription,\n\t\t\t...(frontmatter[\"argument-hint\"] && { argumentHint: frontmatter[\"argument-hint\"] }),\n\t\t\tcontent: body,\n\t\t\tsourceInfo,\n\t\t\tfilePath,\n\t\t};\n\t} catch {\n\t\treturn null;\n\t}\n}\n\nasync function loadTemplatesFromDirWithOperations(\n\toperations: ToolOperations,\n\tdir: string,\n\tgetSourceInfo: (filePath: string) => SourceInfo,\n): Promise<PromptTemplate[]> {\n\tconst templates: PromptTemplate[] = [];\n\tif (!(await backendPathExists(operations, dir))) return templates;\n\ttry {\n\t\tconst entries = await operations.readdir(dir);\n\t\tfor (const name of entries) {\n\t\t\tconst fullPath = join(dir, name);\n\t\t\tlet isFile = false;\n\t\t\ttry {\n\t\t\t\tisFile = (await operations.stat(fullPath)).isFile();\n\t\t\t} catch {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (isFile && name.endsWith(\".md\")) {\n\t\t\t\tconst template = await loadTemplateFromFileWithOperations(operations, fullPath, getSourceInfo(fullPath));\n\t\t\t\tif (template) templates.push(template);\n\t\t\t}\n\t\t}\n\t} catch {\n\t\treturn templates;\n\t}\n\treturn templates;\n}\n\nexport interface LoadPromptTemplatesWithOperationsOptions extends LoadPromptTemplatesOptions {\n\toperations: ToolOperations;\n}\n\nexport async function loadPromptTemplatesWithOperations(\n\toptions: LoadPromptTemplatesWithOperationsOptions,\n): Promise<PromptTemplate[]> {\n\tconst resolvedCwd = resolvePath(options.cwd);\n\tconst resolvedAgentDir = resolvePath(options.agentDir);\n\tconst promptPaths = options.promptPaths;\n\tconst includeDefaults = options.includeDefaults;\n\tconst operations = options.operations;\n\tconst templates: PromptTemplate[] = [];\n\tconst globalPromptsDir = join(resolvedAgentDir, \"prompts\");\n\tconst projectPromptsDir = resolve(resolvedCwd, CONFIG_DIR_NAME, \"prompts\");\n\tconst isUnderPath = (target: string, root: string): boolean => {\n\t\tconst normalizedRoot = resolve(root);\n\t\tif (target === normalizedRoot) return true;\n\t\tconst prefix = normalizedRoot.endsWith(sep) ? normalizedRoot : `${normalizedRoot}${sep}`;\n\t\treturn target.startsWith(prefix);\n\t};\n\tconst getSourceInfo = (resolvedPath: string): SourceInfo => {\n\t\tif (isUnderPath(resolvedPath, globalPromptsDir)) {\n\t\t\treturn createSyntheticSourceInfo(resolvedPath, { source: \"local\", scope: \"user\", baseDir: globalPromptsDir });\n\t\t}\n\t\tif (isUnderPath(resolvedPath, projectPromptsDir)) {\n\t\t\treturn createSyntheticSourceInfo(resolvedPath, {\n\t\t\t\tsource: \"remote\",\n\t\t\t\tscope: \"project\",\n\t\t\t\tbaseDir: projectPromptsDir,\n\t\t\t});\n\t\t}\n\t\treturn createSyntheticSourceInfo(resolvedPath, { source: \"remote\", baseDir: dirname(resolvedPath) });\n\t};\n\tif (includeDefaults) {\n\t\ttemplates.push(...(await loadTemplatesFromDirWithOperations(operations, globalPromptsDir, getSourceInfo)));\n\t\ttemplates.push(...(await loadTemplatesFromDirWithOperations(operations, projectPromptsDir, getSourceInfo)));\n\t}\n\tfor (const rawPath of promptPaths) {\n\t\tconst resolvedPath = resolvePath(rawPath, resolvedCwd, { trim: true });\n\t\tif (!(await backendPathExists(operations, resolvedPath))) continue;\n\t\ttry {\n\t\t\tconst stats = await operations.stat(resolvedPath);\n\t\t\tif (stats.isDirectory()) {\n\t\t\t\ttemplates.push(...(await loadTemplatesFromDirWithOperations(operations, resolvedPath, getSourceInfo)));\n\t\t\t} else if (stats.isFile() && resolvedPath.endsWith(\".md\")) {\n\t\t\t\tconst template = await loadTemplateFromFileWithOperations(\n\t\t\t\t\toperations,\n\t\t\t\t\tresolvedPath,\n\t\t\t\t\tgetSourceInfo(resolvedPath),\n\t\t\t\t);\n\t\t\t\tif (template) templates.push(template);\n\t\t\t}\n\t\t} catch {}\n\t}\n\treturn templates;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"provider-display-names.d.ts","sourceRoot":"","sources":["../../src/core/provider-display-names.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,+BAA+B,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CA+BlE,CAAC","sourcesContent":["export const BUILT_IN_PROVIDER_DISPLAY_NAMES: Record<string, string> = {\n\tanthropic: \"Anthropic\",\n\t\"amazon-bedrock\": \"Amazon Bedrock\",\n\t\"azure-openai-responses\": \"Azure OpenAI Responses\",\n\tcerebras: \"Cerebras\",\n\t\"cloudflare-ai-gateway\": \"Cloudflare AI Gateway\",\n\t\"cloudflare-workers-ai\": \"Cloudflare Workers AI\",\n\tdeepseek: \"DeepSeek\",\n\tfireworks: \"Fireworks\",\n\tgoogle: \"Google Gemini\",\n\t\"google-vertex\": \"Google Vertex AI\",\n\tgroq: \"Groq\",\n\thuggingface: \"Hugging Face\",\n\t\"kimi-coding\": \"Kimi For Coding\",\n\tmistral: \"Mistral\",\n\tminimax: \"MiniMax\",\n\t\"minimax-cn\": \"MiniMax (China)\",\n\tmoonshotai: \"Moonshot AI\",\n\t\"moonshotai-cn\": \"Moonshot AI (China)\",\n\topencode: \"OpenCode Zen\",\n\t\"opencode-go\": \"OpenCode Go\",\n\topenai: \"OpenAI\",\n\topenrouter: \"OpenRouter\",\n\ttogether: \"Together AI\",\n\t\"vercel-ai-gateway\": \"Vercel AI Gateway\",\n\txai: \"xAI\",\n\tzai: \"ZAI\",\n\txiaomi: \"Xiaomi MiMo\",\n\t\"xiaomi-token-plan-cn\": \"Xiaomi MiMo Token Plan (China)\",\n\t\"xiaomi-token-plan-ams\": \"Xiaomi MiMo Token Plan (Amsterdam)\",\n\t\"xiaomi-token-plan-sgp\": \"Xiaomi MiMo Token Plan (Singapore)\",\n};\n"]}
1
+ {"version":3,"file":"provider-display-names.d.ts","sourceRoot":"","sources":["../../src/core/provider-display-names.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,+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AAY,EAAE,MAAM,EAAE,CAAC;IACvB,MAAM,EAAE,6BAA6B,CAAC;CACtC;AAED,MAAM,MAAM,mCAAmC,GAAG,sBAAsB,GAAG,qBAAqB,CAAC;AAEjG,qBAAa,+BAAgC,SAAQ,KAAK;IACzD,QAAQ,CAAC,IAAI,EAAE,mCAAmC,CAAC;IAEnD,YAAY,IAAI,EAAE,mCAAmC,EAAE,OAAO,EAAE,MAAM,EAIrE;CACD;AA+BD,wBAAgB,iCAAiC,CAChD,SAAS,EAAE,wBAAwB,EACnC,OAAO,EAAE,iCAAiC,GACxC,gCAAgC,CA8ElC;AAED,wBAAgB,4BAA4B,CAAC,MAAM,EAAE,qBAAqB,GAAG,4BAA4B,CAaxG","sourcesContent":["import { createHash } from \"node:crypto\";\nimport { type Static, Type } from \"typebox\";\nimport { Compile, type Validator } from \"typebox/compile\";\n\nexport const REMOTE_WORKSPACE_PROTOCOL_VERSIONS = [{ major: 1, minMinor: 0, maxMinor: 0 }] as const;\n\nexport const REMOTE_WORKSPACE_CAPABILITIES = [\n\t\"catalog_refresh\",\n\t\"tool_updates\",\n\t\"primitive_operations\",\n\t\"lsp_status\",\n\t\"file_transfer\",\n\t\"artifacts\",\n] as const;\n\nexport type RemoteWorkspaceCapability = (typeof REMOTE_WORKSPACE_CAPABILITIES)[number];\n\nexport const REMOTE_WORKSPACE_METHODS = [\n\t\"catalog.get\",\n\t\"tool.invoke\",\n\t\"workspace.access\",\n\t\"workspace.read\",\n\t\"workspace.write\",\n\t\"workspace.mkdir\",\n\t\"workspace.stat\",\n\t\"workspace.readdir\",\n\t\"workspace.glob\",\n\t\"workspace.grep\",\n\t\"workspace.detect_image_mime\",\n\t\"workspace.exec\",\n\t\"lsp.status\",\n\t\"resource.read\",\n\t\"artifact.read\",\n\t\"transfer.upload\",\n\t\"transfer.download\",\n] as const;\n\nexport type RemoteWorkspaceMethod = (typeof REMOTE_WORKSPACE_METHODS)[number];\n\nexport const REMOTE_WORKSPACE_ERROR_CODES = [\n\t\"invalid_request\",\n\t\"method_not_supported\",\n\t\"incompatible_version\",\n\t\"capability_mismatch\",\n\t\"schema_mismatch\",\n\t\"stale_generation\",\n\t\"not_available\",\n\t\"limit_exceeded\",\n\t\"deadline_exceeded\",\n\t\"cancelled\",\n\t\"conflict\",\n\t\"generation_retired\",\n\t\"connection_draining\",\n\t\"result_too_large\",\n\t\"internal_error\",\n] as const;\n\nexport type RemoteWorkspaceErrorCode = (typeof REMOTE_WORKSPACE_ERROR_CODES)[number];\nexport type RemoteWorkspaceExecutionState = \"not_started\" | \"completed\" | \"indeterminate\";\nexport type RemoteWorkspacePathFlavor = \"posix\" | \"windows\";\nexport type RemoteWorkspaceOperationKind = \"read\" | \"mutation\" | \"process\" | \"service\";\n\nexport interface RemoteWorkspaceStructuralLimits {\n\tmaxMessageBytes: number;\n\tmaxStringBytes: number;\n\tmaxDepth: number;\n\tmaxObjectKeys: number;\n\tmaxArrayLength: number;\n\tmaxNodes: number;\n}\n\nexport interface RemoteWorkspaceProtocolLimits extends RemoteWorkspaceStructuralLimits {\n\tmaxRequestMs: number;\n\tmaxTransferChunkBytes: number;\n\tmaxPendingTransferBytes: number;\n\tmaxPendingInboundBytes: number;\n\tmaxPendingInboundMessages: number;\n\tmaxPendingOutboundBytes: number;\n\tmaxPendingOutboundMessages: number;\n\tmaxTransferBytes: number;\n\tmaxTransferChunks: number;\n\tmaxActiveRequests: number;\n\tmaxActiveTransfers: number;\n\tmaxCancellationMs: number;\n\tmaxTransportSendMs: number;\n}\n\nexport const DEFAULT_REMOTE_WORKSPACE_PROTOCOL_LIMITS: RemoteWorkspaceProtocolLimits = {\n\tmaxMessageBytes: 2 * 1024 * 1024,\n\tmaxStringBytes: 1536 * 1024,\n\tmaxDepth: 32,\n\tmaxObjectKeys: 4096,\n\tmaxArrayLength: 4096,\n\tmaxNodes: 16_384,\n\tmaxRequestMs: 10 * 60 * 1000,\n\tmaxTransferChunkBytes: 64 * 1024,\n\tmaxPendingTransferBytes: 256 * 1024,\n\tmaxPendingInboundBytes: 4 * 1024 * 1024,\n\tmaxPendingInboundMessages: 64,\n\tmaxPendingOutboundBytes: 4 * 1024 * 1024,\n\tmaxPendingOutboundMessages: 128,\n\tmaxTransferBytes: 100 * 1024 * 1024,\n\tmaxTransferChunks: 16_384,\n\tmaxActiveRequests: 64,\n\tmaxActiveTransfers: 8,\n\tmaxCancellationMs: 100,\n\tmaxTransportSendMs: 10_000,\n};\n\nconst closedObject = { additionalProperties: false } as const;\nconst safeIntegerOptions = { minimum: 0, maximum: Number.MAX_SAFE_INTEGER } as const;\nconst RequestIdSchema = Type.String({ minLength: 1, maxLength: 128, pattern: \"^[A-Za-z0-9._:-]+$\" });\nconst HashSchema = Type.String({ pattern: \"^[0-9a-f]{64}$\" });\nconst CapabilitySchema = Type.String({ minLength: 1, maxLength: 128, pattern: \"^[a-z][a-z0-9_.-]*$\" });\nconst RemoteWorkspaceMethodSchema = Type.Union([\n\tType.Literal(\"catalog.get\"),\n\tType.Literal(\"tool.invoke\"),\n\tType.Literal(\"workspace.access\"),\n\tType.Literal(\"workspace.read\"),\n\tType.Literal(\"workspace.write\"),\n\tType.Literal(\"workspace.mkdir\"),\n\tType.Literal(\"workspace.stat\"),\n\tType.Literal(\"workspace.readdir\"),\n\tType.Literal(\"workspace.glob\"),\n\tType.Literal(\"workspace.grep\"),\n\tType.Literal(\"workspace.detect_image_mime\"),\n\tType.Literal(\"workspace.exec\"),\n\tType.Literal(\"lsp.status\"),\n\tType.Literal(\"resource.read\"),\n\tType.Literal(\"artifact.read\"),\n\tType.Literal(\"transfer.upload\"),\n\tType.Literal(\"transfer.download\"),\n]);\n\nexport const RemoteWorkspaceVersionRangeSchema = Type.Object(\n\t{\n\t\tmajor: Type.Integer({ minimum: 1, maximum: 65535 }),\n\t\tminMinor: Type.Integer({ minimum: 0, maximum: 65535 }),\n\t\tmaxMinor: Type.Integer({ minimum: 0, maximum: 65535 }),\n\t},\n\tclosedObject,\n);\n\nexport type RemoteWorkspaceVersionRange = Static<typeof RemoteWorkspaceVersionRangeSchema>;\n\nexport const RemoteWorkspaceVersionSchema = Type.Object(\n\t{\n\t\tmajor: Type.Integer({ minimum: 1, maximum: 65535 }),\n\t\tminor: Type.Integer({ minimum: 0, maximum: 65535 }),\n\t},\n\tclosedObject,\n);\n\nexport type RemoteWorkspaceVersion = Static<typeof RemoteWorkspaceVersionSchema>;\n\nexport const RemoteWorkspaceLimitsSchema = Type.Object(\n\t{\n\t\tmaxMessageBytes: Type.Integer({ minimum: 1024, maximum: 64 * 1024 * 1024 }),\n\t\tmaxStringBytes: Type.Integer({ minimum: 1, maximum: 64 * 1024 * 1024 }),\n\t\tmaxDepth: Type.Integer({ minimum: 1, maximum: 256 }),\n\t\tmaxObjectKeys: Type.Integer({ minimum: 1, maximum: 1_000_000 }),\n\t\tmaxArrayLength: Type.Integer({ minimum: 1, maximum: 1_000_000 }),\n\t\tmaxNodes: Type.Integer({ minimum: 1, maximum: 2_000_000 }),\n\t\tmaxRequestMs: Type.Integer({ minimum: 1, maximum: 24 * 60 * 60 * 1000 }),\n\t\tmaxTransferChunkBytes: Type.Integer({ minimum: 1024, maximum: 1024 * 1024 }),\n\t\tmaxPendingTransferBytes: Type.Integer({ minimum: 1024, maximum: 16 * 1024 * 1024 }),\n\t\tmaxPendingInboundBytes: Type.Integer({ minimum: 1024, maximum: 64 * 1024 * 1024 }),\n\t\tmaxPendingInboundMessages: Type.Integer({ minimum: 1, maximum: 100_000 }),\n\t\tmaxPendingOutboundBytes: Type.Integer({ minimum: 1024, maximum: 64 * 1024 * 1024 }),\n\t\tmaxPendingOutboundMessages: Type.Integer({ minimum: 1, maximum: 100_000 }),\n\t\tmaxTransferBytes: Type.Integer({ minimum: 1, maximum: Number.MAX_SAFE_INTEGER }),\n\t\tmaxTransferChunks: Type.Integer({ minimum: 1, maximum: 1_000_000 }),\n\t\tmaxActiveRequests: Type.Integer({ minimum: 1, maximum: 10_000_000 }),\n\t\tmaxActiveTransfers: Type.Integer({ minimum: 1, maximum: 10_000 }),\n\t\tmaxCancellationMs: Type.Integer({ minimum: 1, maximum: 60_000 }),\n\t\tmaxTransportSendMs: Type.Integer({ minimum: 1, maximum: 5 * 60_000 }),\n\t},\n\tclosedObject,\n);\n\nexport const RemoteWorkspaceIdentitySchema = Type.Object(\n\t{\n\t\tid: Type.String({ minLength: 16, maxLength: 128, pattern: \"^[A-Za-z0-9_-]+$\" }),\n\t\troot: Type.String({ minLength: 1, maxLength: 32_768 }),\n\t\tpathFlavor: Type.Union([Type.Literal(\"posix\"), Type.Literal(\"windows\")]),\n\t},\n\tclosedObject,\n);\n\nexport type RemoteWorkspaceIdentity = Static<typeof RemoteWorkspaceIdentitySchema>;\n\nexport const RemoteWorkspaceToolCatalogEntrySchema = Type.Object(\n\t{\n\t\tname: Type.String({ minLength: 1, maxLength: 128, pattern: \"^[A-Za-z][A-Za-z0-9_.-]*$\" }),\n\t\texecutionMode: Type.Union([\n\t\t\tType.Literal(\"read\"),\n\t\t\tType.Literal(\"mutation\"),\n\t\t\tType.Literal(\"process\"),\n\t\t\tType.Literal(\"service\"),\n\t\t]),\n\t\tparameterSchema: Type.Record(Type.String({ maxLength: 256 }), Type.Unknown()),\n\t\tschemaHash: HashSchema,\n\t\tfeatureFlags: Type.Array(CapabilitySchema, { maxItems: 256 }),\n\t},\n\tclosedObject,\n);\n\nexport type RemoteWorkspaceToolCatalogEntry = Static<typeof RemoteWorkspaceToolCatalogEntrySchema>;\n\nexport const RemoteWorkspaceCatalogSchema = Type.Object(\n\t{\n\t\tgeneration: Type.Integer({ minimum: 1, maximum: Number.MAX_SAFE_INTEGER }),\n\t\ttools: Type.Array(RemoteWorkspaceToolCatalogEntrySchema, { maxItems: 1024 }),\n\t\toperations: Type.Array(RemoteWorkspaceMethodSchema, { maxItems: 256 }),\n\t},\n\tclosedObject,\n);\n\nexport type RemoteWorkspaceCatalog = Static<typeof RemoteWorkspaceCatalogSchema>;\n\nexport const RemoteWorkspaceHandshakeSchema = Type.Object(\n\t{\n\t\ttype: Type.Literal(\"handshake\"),\n\t\tid: RequestIdSchema,\n\t\tversions: Type.Array(RemoteWorkspaceVersionRangeSchema, { minItems: 1, maxItems: 16 }),\n\t\trequiredCapabilities: Type.Array(CapabilitySchema, { maxItems: 256 }),\n\t\toptionalCapabilities: Type.Array(CapabilitySchema, { maxItems: 256 }),\n\t\treceiveLimits: RemoteWorkspaceLimitsSchema,\n\t},\n\tclosedObject,\n);\n\nexport type RemoteWorkspaceHandshake = Static<typeof RemoteWorkspaceHandshakeSchema>;\n\nexport const RemoteWorkspaceHandshakeAckSchema = Type.Object(\n\t{\n\t\ttype: Type.Literal(\"handshake_ack\"),\n\t\tid: RequestIdSchema,\n\t\tversion: RemoteWorkspaceVersionSchema,\n\t\tcapabilities: Type.Array(CapabilitySchema, { maxItems: 256 }),\n\t\tworkspace: RemoteWorkspaceIdentitySchema,\n\t\tlimits: RemoteWorkspaceLimitsSchema,\n\t\tcatalog: RemoteWorkspaceCatalogSchema,\n\t\tcatalogHash: HashSchema,\n\t\tbackendMetadata: Type.Object(\n\t\t\t{\n\t\t\t\tkind: Type.Literal(\"remote-workspace\"),\n\t\t\t\tlabel: Type.Optional(Type.String({ minLength: 1, maxLength: 256 })),\n\t\t\t},\n\t\t\tclosedObject,\n\t\t),\n\t},\n\tclosedObject,\n);\n\nexport type RemoteWorkspaceHandshakeAck = Static<typeof RemoteWorkspaceHandshakeAckSchema>;\n\nexport const RemoteWorkspaceRequestSchema = Type.Object(\n\t{\n\t\ttype: Type.Literal(\"request\"),\n\t\tid: RequestIdSchema,\n\t\tmethod: Type.String({ minLength: 1, maxLength: 128 }),\n\t\ttimeoutMs: Type.Integer({ minimum: 1, maximum: 24 * 60 * 60 * 1000 }),\n\t\tparams: Type.Unknown(),\n\t},\n\tclosedObject,\n);\n\nexport type RemoteWorkspaceRequest = Static<typeof RemoteWorkspaceRequestSchema>;\n\nexport const RemoteWorkspaceCancelSchema = Type.Object(\n\t{\n\t\ttype: Type.Literal(\"cancel\"),\n\t\tid: RequestIdSchema,\n\t\treason: Type.Optional(Type.String({ maxLength: 256 })),\n\t},\n\tclosedObject,\n);\n\nexport type RemoteWorkspaceCancel = Static<typeof RemoteWorkspaceCancelSchema>;\n\nexport const RemoteWorkspaceTransferChunkSchema = Type.Object(\n\t{\n\t\ttype: Type.Literal(\"transfer_chunk\"),\n\t\tid: RequestIdSchema,\n\t\tsequence: Type.Integer(safeIntegerOptions),\n\t\tdataBase64: Type.String({ minLength: 4 }),\n\t},\n\tclosedObject,\n);\n\nexport type RemoteWorkspaceTransferChunk = Static<typeof RemoteWorkspaceTransferChunkSchema>;\n\nexport const RemoteWorkspaceTransferFinishSchema = Type.Object(\n\t{\n\t\ttype: Type.Literal(\"transfer_finish\"),\n\t\tid: RequestIdSchema,\n\t\tlength: Type.Integer(safeIntegerOptions),\n\t\tsha256: HashSchema,\n\t},\n\tclosedObject,\n);\n\nexport type RemoteWorkspaceTransferFinish = Static<typeof RemoteWorkspaceTransferFinishSchema>;\n\nexport const RemoteWorkspaceResultSchema = Type.Object(\n\t{\n\t\ttype: Type.Literal(\"result\"),\n\t\tid: RequestIdSchema,\n\t\tresult: Type.Unknown(),\n\t},\n\tclosedObject,\n);\n\nexport type RemoteWorkspaceResult = Static<typeof RemoteWorkspaceResultSchema>;\n\nexport const RemoteWorkspaceProtocolErrorSchema = Type.Object(\n\t{\n\t\tcode: Type.Union([\n\t\t\tType.Literal(\"invalid_request\"),\n\t\t\tType.Literal(\"method_not_supported\"),\n\t\t\tType.Literal(\"incompatible_version\"),\n\t\t\tType.Literal(\"capability_mismatch\"),\n\t\t\tType.Literal(\"schema_mismatch\"),\n\t\t\tType.Literal(\"stale_generation\"),\n\t\t\tType.Literal(\"not_available\"),\n\t\t\tType.Literal(\"limit_exceeded\"),\n\t\t\tType.Literal(\"deadline_exceeded\"),\n\t\t\tType.Literal(\"cancelled\"),\n\t\t\tType.Literal(\"conflict\"),\n\t\t\tType.Literal(\"generation_retired\"),\n\t\t\tType.Literal(\"connection_draining\"),\n\t\t\tType.Literal(\"result_too_large\"),\n\t\t\tType.Literal(\"internal_error\"),\n\t\t]),\n\t\tmessage: Type.String({ minLength: 1, maxLength: 4096 }),\n\t\texecutionState: Type.Union([\n\t\t\tType.Literal(\"not_started\"),\n\t\t\tType.Literal(\"completed\"),\n\t\t\tType.Literal(\"indeterminate\"),\n\t\t]),\n\t\tretryable: Type.Boolean(),\n\t\tdetails: Type.Optional(Type.Unknown()),\n\t},\n\tclosedObject,\n);\n\nexport type RemoteWorkspaceProtocolError = Static<typeof RemoteWorkspaceProtocolErrorSchema>;\n\nexport const RemoteWorkspaceErrorMessageSchema = Type.Object(\n\t{\n\t\ttype: Type.Literal(\"error\"),\n\t\tid: RequestIdSchema,\n\t\terror: RemoteWorkspaceProtocolErrorSchema,\n\t},\n\tclosedObject,\n);\n\nexport type RemoteWorkspaceErrorMessage = Static<typeof RemoteWorkspaceErrorMessageSchema>;\n\nexport const RemoteWorkspaceUpdateSchema = Type.Object(\n\t{\n\t\ttype: Type.Literal(\"update\"),\n\t\tid: RequestIdSchema,\n\t\tsequence: Type.Integer(safeIntegerOptions),\n\t\tupdate: Type.Unknown(),\n\t},\n\tclosedObject,\n);\n\nexport type RemoteWorkspaceUpdate = Static<typeof RemoteWorkspaceUpdateSchema>;\n\nexport const RemoteWorkspaceTransferStartSchema = Type.Object(\n\t{\n\t\ttype: Type.Literal(\"transfer_start\"),\n\t\tid: RequestIdSchema,\n\t\tlength: Type.Integer(safeIntegerOptions),\n\t\tsha256: HashSchema,\n\t},\n\tclosedObject,\n);\n\nexport type RemoteWorkspaceTransferStart = Static<typeof RemoteWorkspaceTransferStartSchema>;\n\nexport const RemoteWorkspaceCatalogChangedSchema = Type.Object(\n\t{\n\t\ttype: Type.Literal(\"catalog_changed\"),\n\t\tgeneration: Type.Integer({ minimum: 1, maximum: Number.MAX_SAFE_INTEGER }),\n\t\tcatalogHash: HashSchema,\n\t},\n\tclosedObject,\n);\n\nexport type RemoteWorkspaceCatalogChanged = Static<typeof RemoteWorkspaceCatalogChangedSchema>;\n\nexport const RemoteWorkspaceClientMessageSchema = Type.Union([\n\tRemoteWorkspaceHandshakeSchema,\n\tRemoteWorkspaceRequestSchema,\n\tRemoteWorkspaceCancelSchema,\n\tRemoteWorkspaceTransferChunkSchema,\n\tRemoteWorkspaceTransferFinishSchema,\n]);\n\nexport const RemoteWorkspaceServerMessageSchema = Type.Union([\n\tRemoteWorkspaceHandshakeAckSchema,\n\tRemoteWorkspaceResultSchema,\n\tRemoteWorkspaceErrorMessageSchema,\n\tRemoteWorkspaceUpdateSchema,\n\tRemoteWorkspaceTransferStartSchema,\n\tRemoteWorkspaceTransferChunkSchema,\n\tRemoteWorkspaceCatalogChangedSchema,\n]);\n\nexport type RemoteWorkspaceClientMessage = Static<typeof RemoteWorkspaceClientMessageSchema>;\nexport type RemoteWorkspaceServerMessage = Static<typeof RemoteWorkspaceServerMessageSchema>;\n\nconst EmptyParamsSchema = Type.Object({}, closedObject);\nconst PathParamsSchema = Type.Object({ path: Type.String({ minLength: 1, maxLength: 32_768 }) }, closedObject);\nconst CatalogGetParamsSchema = EmptyParamsSchema;\nconst SessionEnvironmentSchema = Type.Object(\n\t{\n\t\tGRIP_SESSION_ID: Type.Optional(Type.String({ maxLength: 32_768 })),\n\t\tGRIP_SESSION_FILE: Type.Optional(Type.String({ maxLength: 32_768 })),\n\t\tGRIP_PROVIDER: Type.Optional(Type.String({ maxLength: 32_768 })),\n\t\tGRIP_MODEL: Type.Optional(Type.String({ maxLength: 32_768 })),\n\t\tGRIP_REASONING_LEVEL: Type.Optional(Type.String({ maxLength: 32_768 })),\n\t},\n\tclosedObject,\n);\n/** Shared v2 mutations require an observed digest/absence, or an explicitly unsafe write. */\nconst ExpectedRevisionSchema = Type.Union([\n\tType.Object({ sha256: HashSchema }, closedObject),\n\tType.Object({ absent: Type.Literal(true) }, closedObject),\n\tType.Object({ unsafeOverwrite: Type.Literal(true) }, closedObject),\n]);\nexport type ExpectedWorkspaceRevision = Static<typeof ExpectedRevisionSchema>;\nconst ToolInvokeParamsSchema = Type.Object(\n\t{\n\t\tgeneration: Type.Integer({ minimum: 1, maximum: Number.MAX_SAFE_INTEGER }),\n\t\tcatalogHash: HashSchema,\n\t\ttoolName: Type.String({ minLength: 1, maxLength: 128 }),\n\t\tschemaHash: HashSchema,\n\t\targumentsPrepared: Type.Literal(true),\n\t\targuments: Type.Unknown(),\n\t\texpectedRevision: Type.Optional(ExpectedRevisionSchema),\n\t\texecutionOptions: Type.Object(\n\t\t\t{\n\t\t\t\timageAutoResize: Type.Optional(Type.Boolean()),\n\t\t\t\tshellCommandPrefix: Type.Optional(Type.String({ maxLength: 32_768 })),\n\t\t\t\tsessionEnvironment: Type.Optional(SessionEnvironmentSchema),\n\t\t\t},\n\t\t\tclosedObject,\n\t\t),\n\t},\n\tclosedObject,\n);\nconst AccessParamsSchema = Type.Object(\n\t{\n\t\tpath: Type.String({ minLength: 1, maxLength: 32_768 }),\n\t\tmode: Type.Optional(\n\t\t\tType.Union([Type.Literal(\"exists\"), Type.Literal(\"read\"), Type.Literal(\"write\"), Type.Literal(\"readwrite\")]),\n\t\t),\n\t},\n\tclosedObject,\n);\nconst WriteParamsSchema = Type.Object(\n\t{\n\t\tpath: Type.String({ minLength: 1, maxLength: 32_768 }),\n\t\tcontentBase64: Type.String(),\n\t\texpectedRevision: Type.Optional(ExpectedRevisionSchema),\n\t},\n\tclosedObject,\n);\nconst MkdirParamsSchema = Type.Object(\n\t{\n\t\tpath: Type.String({ minLength: 1, maxLength: 32_768 }),\n\t\trecursive: Type.Boolean(),\n\t},\n\tclosedObject,\n);\nconst GlobParamsSchema = Type.Object(\n\t{\n\t\tpattern: Type.String({ minLength: 1, maxLength: 32_768 }),\n\t\tcwd: Type.String({ minLength: 1, maxLength: 32_768 }),\n\t\tignore: Type.Array(Type.String({ maxLength: 32_768 }), { maxItems: 4096 }),\n\t\tlimit: Type.Integer({ minimum: 1, maximum: 1_000_000 }),\n\t},\n\tclosedObject,\n);\nconst GrepParamsSchema = Type.Object(\n\t{\n\t\tpattern: Type.String({ maxLength: 1024 * 1024 }),\n\t\tpath: Type.String({ minLength: 1, maxLength: 32_768 }),\n\t\tglob: Type.Optional(Type.String({ maxLength: 32_768 })),\n\t\tignoreCase: Type.Optional(Type.Boolean()),\n\t\tliteral: Type.Optional(Type.Boolean()),\n\t\tlimit: Type.Integer({ minimum: 1, maximum: 1_000_000 }),\n\t},\n\tclosedObject,\n);\nconst ExecParamsSchema = Type.Object(\n\t{\n\t\tcommand: Type.String({ minLength: 1 }),\n\t\tcwd: Type.String({ minLength: 1, maxLength: 32_768 }),\n\t},\n\tclosedObject,\n);\nconst TransferUploadParamsSchema = Type.Object(\n\t{\n\t\tpath: Type.String({ minLength: 1, maxLength: 32_768 }),\n\t\tlength: Type.Integer(safeIntegerOptions),\n\t\tsha256: HashSchema,\n\t\toverwrite: Type.Boolean(),\n\t},\n\tclosedObject,\n);\nconst TransferDownloadParamsSchema = Type.Object(\n\t{\n\t\tpath: Type.String({ minLength: 1, maxLength: 32_768 }),\n\t},\n\tclosedObject,\n);\n\nconst ToolContentSchema = Type.Union([\n\tType.Object({ type: Type.Literal(\"text\"), text: Type.String() }, closedObject),\n\tType.Object(\n\t\t{\n\t\t\ttype: Type.Literal(\"image\"),\n\t\t\tdata: Type.String(),\n\t\t\tmimeType: Type.String({ minLength: 1, maxLength: 256 }),\n\t\t},\n\t\tclosedObject,\n\t),\n]);\nconst ToolResultSchema = Type.Object(\n\t{\n\t\tcontent: Type.Array(ToolContentSchema),\n\t\tdetails: Type.Optional(Type.Unknown()),\n\t\tterminate: Type.Optional(Type.Boolean()),\n\t},\n\tclosedObject,\n);\nconst EmptyResultSchema = EmptyParamsSchema;\nconst LspStatusServerSchema = Type.Object(\n\t{\n\t\tserverId: Type.String({ minLength: 1, maxLength: 256 }),\n\t\tlanguageIds: Type.Array(Type.String({ maxLength: 256 }), { maxItems: 256 }),\n\t\ttransport: Type.String({ minLength: 1, maxLength: 128 }),\n\t\tinstanceKey: Type.Optional(Type.String({ maxLength: 4096 })),\n\t\tworkspaceRoot: Type.Optional(Type.String({ maxLength: 32_768 })),\n\t\tendpoint: Type.Optional(Type.String({ maxLength: 4096 })),\n\t\trootUri: Type.Optional(Type.String({ maxLength: 32_768 })),\n\t\townership: Type.Union([Type.Literal(\"managed\"), Type.Literal(\"attached\")]),\n\t\tshutdownMode: Type.Union([Type.Literal(\"protocol\"), Type.Literal(\"disconnect\")]),\n\t\tstate: Type.Union([\n\t\t\tType.Literal(\"idle\"),\n\t\t\tType.Literal(\"connecting\"),\n\t\t\tType.Literal(\"initializing\"),\n\t\t\tType.Literal(\"running\"),\n\t\t\tType.Literal(\"closed\"),\n\t\t\tType.Literal(\"failed\"),\n\t\t\tType.Literal(\"disposed\"),\n\t\t]),\n\t\treconnectEligible: Type.Boolean(),\n\t\trunning: Type.Boolean(),\n\t\tstarting: Type.Boolean(),\n\t\tdiagnosticsCount: Type.Integer(safeIntegerOptions),\n\t\tlastError: Type.Optional(Type.String()),\n\t\tlastRequestError: Type.Optional(Type.String()),\n\t\tstderr: Type.Optional(Type.String()),\n\t\tsynchronizationError: Type.Optional(Type.String()),\n\t},\n\tclosedObject,\n);\nconst LspStatusResultSchema = Type.Object(\n\t{ enabled: Type.Boolean(), servers: Type.Array(LspStatusServerSchema, { maxItems: 1024 }) },\n\tclosedObject,\n);\nexport type RemoteLspStatus = Static<typeof LspStatusResultSchema>;\nconst ReadResultSchema = Type.Object(\n\t{\n\t\tcontentBase64: Type.String(),\n\t\tworkspace: RemoteWorkspaceIdentitySchema,\n\t\trevision: Type.Optional(HashSchema),\n\t},\n\tclosedObject,\n);\nconst StatResultSchema = Type.Object(\n\t{\n\t\tkind: Type.Union([\n\t\t\tType.Literal(\"file\"),\n\t\t\tType.Literal(\"directory\"),\n\t\t\tType.Literal(\"other\"),\n\t\t\tType.Literal(\"absent\"),\n\t\t]),\n\t\tworkspace: RemoteWorkspaceIdentitySchema,\n\t},\n\tclosedObject,\n);\nconst ReaddirResultSchema = Type.Object(\n\t{\n\t\tentries: Type.Array(Type.String({ maxLength: 32_768 }), { maxItems: 1_000_000 }),\n\t\tworkspace: RemoteWorkspaceIdentitySchema,\n\t},\n\tclosedObject,\n);\nconst GlobResultSchema = Type.Object(\n\t{\n\t\tmatches: Type.Array(Type.String({ maxLength: 32_768 }), { maxItems: 1_000_000 }),\n\t\tworkspace: RemoteWorkspaceIdentitySchema,\n\t},\n\tclosedObject,\n);\nconst GrepResultSchema = Type.Object(\n\t{\n\t\tisDirectory: Type.Boolean(),\n\t\tmatches: Type.Array(\n\t\t\tType.Object(\n\t\t\t\t{\n\t\t\t\t\tfilePath: Type.String({ minLength: 1, maxLength: 32_768 }),\n\t\t\t\t\tlineNumber: Type.Integer({ minimum: 1, maximum: Number.MAX_SAFE_INTEGER }),\n\t\t\t\t\tlineText: Type.Optional(Type.String()),\n\t\t\t\t},\n\t\t\t\tclosedObject,\n\t\t\t),\n\t\t\t{ maxItems: 1_000_000 },\n\t\t),\n\t\tworkspace: RemoteWorkspaceIdentitySchema,\n\t},\n\tclosedObject,\n);\nconst MimeResultSchema = Type.Object(\n\t{\n\t\tmimeType: Type.Union([\n\t\t\tType.Literal(\"image/jpeg\"),\n\t\t\tType.Literal(\"image/png\"),\n\t\t\tType.Literal(\"image/gif\"),\n\t\t\tType.Literal(\"image/webp\"),\n\t\t\tType.Null(),\n\t\t]),\n\t\tworkspace: RemoteWorkspaceIdentitySchema,\n\t},\n\tclosedObject,\n);\nconst ExecResultSchema = Type.Object(\n\t{ exitCode: Type.Union([Type.Integer({ minimum: 0, maximum: 255 }), Type.Null()]) },\n\tclosedObject,\n);\nconst TransferResultSchema = Type.Object(\n\t{\n\t\tlength: Type.Integer(safeIntegerOptions),\n\t\tsha256: HashSchema,\n\t},\n\tclosedObject,\n);\n\nconst parameterValidators = {\n\t\"catalog.get\": Compile(CatalogGetParamsSchema),\n\t\"tool.invoke\": Compile(ToolInvokeParamsSchema),\n\t\"workspace.access\": Compile(AccessParamsSchema),\n\t\"workspace.read\": Compile(PathParamsSchema),\n\t\"workspace.write\": Compile(WriteParamsSchema),\n\t\"workspace.mkdir\": Compile(MkdirParamsSchema),\n\t\"workspace.stat\": Compile(PathParamsSchema),\n\t\"workspace.readdir\": Compile(PathParamsSchema),\n\t\"workspace.glob\": Compile(GlobParamsSchema),\n\t\"workspace.grep\": Compile(GrepParamsSchema),\n\t\"workspace.detect_image_mime\": Compile(PathParamsSchema),\n\t\"workspace.exec\": Compile(ExecParamsSchema),\n\t\"lsp.status\": Compile(EmptyParamsSchema),\n\t\"resource.read\": Compile(PathParamsSchema),\n\t\"artifact.read\": Compile(PathParamsSchema),\n\t\"transfer.upload\": Compile(TransferUploadParamsSchema),\n\t\"transfer.download\": Compile(TransferDownloadParamsSchema),\n} satisfies Record<RemoteWorkspaceMethod, ReturnType<typeof Compile>>;\n\nconst resultValidators = {\n\t\"catalog.get\": Compile(RemoteWorkspaceCatalogSchema),\n\t\"tool.invoke\": Compile(ToolResultSchema),\n\t\"workspace.access\": Compile(EmptyResultSchema),\n\t\"workspace.read\": Compile(ReadResultSchema),\n\t\"workspace.write\": Compile(EmptyResultSchema),\n\t\"workspace.mkdir\": Compile(EmptyResultSchema),\n\t\"workspace.stat\": Compile(StatResultSchema),\n\t\"workspace.readdir\": Compile(ReaddirResultSchema),\n\t\"workspace.glob\": Compile(GlobResultSchema),\n\t\"workspace.grep\": Compile(GrepResultSchema),\n\t\"workspace.detect_image_mime\": Compile(MimeResultSchema),\n\t\"workspace.exec\": Compile(ExecResultSchema),\n\t\"lsp.status\": Compile(LspStatusResultSchema),\n\t\"resource.read\": Compile(ReadResultSchema),\n\t\"artifact.read\": Compile(TransferResultSchema),\n\t\"transfer.upload\": Compile(TransferResultSchema),\n\t\"transfer.download\": Compile(TransferResultSchema),\n} satisfies Record<RemoteWorkspaceMethod, ReturnType<typeof Compile> | undefined>;\n\nconst clientMessageValidator = Compile(RemoteWorkspaceClientMessageSchema);\nconst serverMessageValidator = Compile(RemoteWorkspaceServerMessageSchema);\nconst handshakeAckValidator = Compile(RemoteWorkspaceHandshakeAckSchema);\nconst limitsValidator = Compile(RemoteWorkspaceLimitsSchema);\n\nexport class RemoteWorkspaceValidationError extends Error {\n\tconstructor(message: string) {\n\t\tsuper(message);\n\t\tthis.name = \"RemoteWorkspaceValidationError\";\n\t}\n}\n\nfunction validationMessage(validator: Validator, value: unknown): string {\n\tconst error = validator.Errors(value)[0];\n\tif (!error) return \"value does not match the protocol schema\";\n\treturn `${error.instancePath || \"/\"}: ${error.message}`;\n}\n\nfunction parseWithValidator<T>(validator: Validator, value: unknown, label: string): T {\n\tif (!validator.Check(value)) {\n\t\tthrow new RemoteWorkspaceValidationError(`Invalid ${label}: ${validationMessage(validator, value)}`);\n\t}\n\treturn value as T;\n}\n\nexport function validateRemoteWorkspaceProtocolLimits(value: unknown): RemoteWorkspaceProtocolLimits {\n\tconst limits = parseWithValidator<RemoteWorkspaceProtocolLimits>(limitsValidator, value, \"protocol limits\");\n\tif (limits.maxMessageBytes > limits.maxPendingInboundBytes) {\n\t\tthrow new RemoteWorkspaceValidationError(\"maxMessageBytes must not exceed maxPendingInboundBytes\");\n\t}\n\tif (limits.maxMessageBytes > limits.maxPendingOutboundBytes) {\n\t\tthrow new RemoteWorkspaceValidationError(\"maxMessageBytes must not exceed maxPendingOutboundBytes\");\n\t}\n\tif (limits.maxTransferChunkBytes > limits.maxPendingTransferBytes) {\n\t\tthrow new RemoteWorkspaceValidationError(\"maxTransferChunkBytes must not exceed maxPendingTransferBytes\");\n\t}\n\tif (Math.ceil((limits.maxTransferChunkBytes * 4) / 3) + 512 > limits.maxMessageBytes) {\n\t\tthrow new RemoteWorkspaceValidationError(\"maxTransferChunkBytes must fit in one base64 protocol message\");\n\t}\n\treturn limits;\n}\n\ninterface RemoteWorkspacePendingValue {\n\tvalue: unknown;\n\tdepth: number;\n}\n\ninterface RemoteWorkspaceStructureState {\n\tpending: RemoteWorkspacePendingValue[];\n\tnodes: number;\n\tobjectKeys: number;\n\tlimits: RemoteWorkspaceStructuralLimits;\n}\n\nfunction validateRemoteWorkspaceNodeBudget(depth: number, state: RemoteWorkspaceStructureState): void {\n\tstate.nodes++;\n\tif (state.nodes > state.limits.maxNodes)\n\t\tthrow new RemoteWorkspaceValidationError(\"Protocol value exceeds node limit\");\n\tif (depth > state.limits.maxDepth) throw new RemoteWorkspaceValidationError(\"Protocol value exceeds depth limit\");\n}\n\nfunction validateRemoteWorkspaceScalar(value: unknown, limits: RemoteWorkspaceStructuralLimits): boolean {\n\tif (value === null || typeof value === \"boolean\") return true;\n\tif (typeof value === \"number\") {\n\t\tif (!Number.isFinite(value)) throw new RemoteWorkspaceValidationError(\"Protocol numbers must be finite\");\n\t\treturn true;\n\t}\n\tif (typeof value !== \"string\") return false;\n\tif (Buffer.byteLength(value, \"utf8\") > limits.maxStringBytes) {\n\t\tthrow new RemoteWorkspaceValidationError(\"Protocol string exceeds byte limit\");\n\t}\n\treturn true;\n}\n\nfunction enqueueRemoteWorkspaceArray(value: unknown[], depth: number, state: RemoteWorkspaceStructureState): void {\n\tif (value.length > state.limits.maxArrayLength) {\n\t\tthrow new RemoteWorkspaceValidationError(\"Protocol array exceeds item limit\");\n\t}\n\tfor (let index = value.length - 1; index >= 0; index--) {\n\t\tstate.pending.push({ value: value[index], depth: depth + 1 });\n\t}\n}\n\nfunction enqueueRemoteWorkspaceObject(value: unknown, depth: number, state: RemoteWorkspaceStructureState): void {\n\tif (value === null || typeof value !== \"object\")\n\t\tthrow new RemoteWorkspaceValidationError(\"Protocol values must be JSON-compatible\");\n\tconst prototype = Object.getPrototypeOf(value);\n\tif (prototype !== Object.prototype && prototype !== null) {\n\t\tthrow new RemoteWorkspaceValidationError(\"Protocol objects must be plain JSON objects\");\n\t}\n\tconst entries = Object.entries(value);\n\tif (entries.length > state.limits.maxObjectKeys) {\n\t\tthrow new RemoteWorkspaceValidationError(\"Protocol object exceeds key limit\");\n\t}\n\tstate.objectKeys += entries.length;\n\tif (state.objectKeys > state.limits.maxObjectKeys) {\n\t\tthrow new RemoteWorkspaceValidationError(\"Protocol value exceeds total key limit\");\n\t}\n\tfor (let index = entries.length - 1; index >= 0; index--) {\n\t\tconst entry = entries[index];\n\t\tif (!entry) continue;\n\t\tif (Buffer.byteLength(entry[0], \"utf8\") > state.limits.maxStringBytes) {\n\t\t\tthrow new RemoteWorkspaceValidationError(\"Protocol object key exceeds byte limit\");\n\t\t}\n\t\tstate.pending.push({ value: entry[1], depth: depth + 1 });\n\t}\n}\n\nexport function assertRemoteWorkspaceJsonStructure(\n\tvalue: unknown,\n\tlimits: RemoteWorkspaceStructuralLimits = DEFAULT_REMOTE_WORKSPACE_PROTOCOL_LIMITS,\n): void {\n\tconst state: RemoteWorkspaceStructureState = {\n\t\tpending: [{ value, depth: 1 }],\n\t\tnodes: 0,\n\t\tobjectKeys: 0,\n\t\tlimits,\n\t};\n\twhile (state.pending.length > 0) {\n\t\tconst current = state.pending.pop();\n\t\tif (!current) break;\n\t\tvalidateRemoteWorkspaceNodeBudget(current.depth, state);\n\t\tif (validateRemoteWorkspaceScalar(current.value, limits)) continue;\n\t\tif (Array.isArray(current.value)) {\n\t\t\tenqueueRemoteWorkspaceArray(current.value, current.depth, state);\n\t\t\tcontinue;\n\t\t}\n\t\tenqueueRemoteWorkspaceObject(current.value, current.depth, state);\n\t}\n}\n\nexport function decodeRemoteWorkspaceMessage(\n\tpayload: string | Uint8Array,\n\tlimits: RemoteWorkspaceStructuralLimits = DEFAULT_REMOTE_WORKSPACE_PROTOCOL_LIMITS,\n): unknown {\n\tconst bytes = typeof payload === \"string\" ? Buffer.from(payload, \"utf8\") : payload;\n\tif (bytes.byteLength > limits.maxMessageBytes) {\n\t\tthrow new RemoteWorkspaceValidationError(\"Protocol message exceeds byte limit\");\n\t}\n\tconst text = typeof payload === \"string\" ? payload : new TextDecoder(\"utf-8\", { fatal: true }).decode(payload);\n\tlet value: unknown;\n\ttry {\n\t\tvalue = JSON.parse(text) as unknown;\n\t} catch (error) {\n\t\tthrow new RemoteWorkspaceValidationError(\n\t\t\t`Protocol message is not valid JSON: ${error instanceof Error ? error.message : String(error)}`,\n\t\t);\n\t}\n\tassertRemoteWorkspaceJsonStructure(value, limits);\n\treturn value;\n}\n\nexport function parseRemoteWorkspaceClientMessage(\n\tvalue: unknown,\n\tlimits: RemoteWorkspaceStructuralLimits = DEFAULT_REMOTE_WORKSPACE_PROTOCOL_LIMITS,\n): RemoteWorkspaceClientMessage {\n\tassertRemoteWorkspaceJsonStructure(value, limits);\n\treturn parseWithValidator<RemoteWorkspaceClientMessage>(clientMessageValidator, value, \"client message\");\n}\n\nexport function parseRemoteWorkspaceServerMessage(\n\tvalue: unknown,\n\tlimits: RemoteWorkspaceStructuralLimits = DEFAULT_REMOTE_WORKSPACE_PROTOCOL_LIMITS,\n): RemoteWorkspaceServerMessage {\n\tassertRemoteWorkspaceJsonStructure(value, limits);\n\treturn parseWithValidator<RemoteWorkspaceServerMessage>(serverMessageValidator, value, \"server message\");\n}\n\nexport function isRemoteWorkspaceMethod(method: string): method is RemoteWorkspaceMethod {\n\treturn (REMOTE_WORKSPACE_METHODS as readonly string[]).includes(method);\n}\n\nexport function parseRemoteWorkspaceRequestParams(\n\tmethod: RemoteWorkspaceMethod,\n\tvalue: unknown,\n\tlimits: RemoteWorkspaceStructuralLimits = DEFAULT_REMOTE_WORKSPACE_PROTOCOL_LIMITS,\n): unknown {\n\tassertRemoteWorkspaceJsonStructure(value, limits);\n\tconst parsed = parseWithValidator(parameterValidators[method], value, `${method} params`);\n\tif (method === \"workspace.write\") {\n\t\tdecodeCanonicalBase64((parsed as { contentBase64: string }).contentBase64, limits.maxMessageBytes);\n\t}\n\treturn parsed;\n}\n\nexport function parseRemoteWorkspaceResult(\n\tmethod: RemoteWorkspaceMethod,\n\tvalue: unknown,\n\tlimits: RemoteWorkspaceStructuralLimits = DEFAULT_REMOTE_WORKSPACE_PROTOCOL_LIMITS,\n): unknown {\n\tassertRemoteWorkspaceJsonStructure(value, limits);\n\tconst validator = resultValidators[method];\n\tconst parsed = validator ? parseWithValidator(validator, value, `${method} result`) : value;\n\tif (method === \"workspace.read\" || method === \"resource.read\") {\n\t\tdecodeCanonicalBase64((parsed as { contentBase64: string }).contentBase64, limits.maxMessageBytes);\n\t}\n\treturn parsed;\n}\n\nexport function parseRemoteWorkspaceToolResult(\n\tvalue: unknown,\n\tlimits: RemoteWorkspaceStructuralLimits = DEFAULT_REMOTE_WORKSPACE_PROTOCOL_LIMITS,\n): unknown {\n\tassertRemoteWorkspaceJsonStructure(value, limits);\n\treturn parseWithValidator(Compile(ToolResultSchema), value, \"tool result\");\n}\n\nexport function decodeCanonicalBase64(value: string, maxBytes: number): Buffer {\n\tif (value.length % 4 !== 0 || !/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(value)) {\n\t\tthrow new RemoteWorkspaceValidationError(\"Transfer data is not canonical base64\");\n\t}\n\tconst decoded = Buffer.from(value, \"base64\");\n\tif (decoded.byteLength > maxBytes) throw new RemoteWorkspaceValidationError(\"Transfer chunk exceeds byte limit\");\n\tif (decoded.toString(\"base64\") !== value) {\n\t\tthrow new RemoteWorkspaceValidationError(\"Transfer data is not canonical base64\");\n\t}\n\treturn decoded;\n}\n\nfunction canonicalJson(value: unknown): string {\n\tif (value === null) return \"null\";\n\tif (typeof value === \"boolean\") return value ? \"true\" : \"false\";\n\tif (typeof value === \"number\") {\n\t\tif (!Number.isFinite(value)) throw new RemoteWorkspaceValidationError(\"Cannot hash a non-finite number\");\n\t\treturn JSON.stringify(value);\n\t}\n\tif (typeof value === \"string\") return JSON.stringify(value);\n\tif (Array.isArray(value)) return `[${value.map((entry) => canonicalJson(entry)).join(\",\")}]`;\n\tif (typeof value !== \"object\" || value === undefined) {\n\t\tthrow new RemoteWorkspaceValidationError(\"Cannot hash a non-JSON value\");\n\t}\n\tconst entries = Object.entries(value).sort(([left], [right]) => (left < right ? -1 : left > right ? 1 : 0));\n\treturn `{${entries.map(([key, entry]) => `${JSON.stringify(key)}:${canonicalJson(entry)}`).join(\",\")}}`;\n}\n\nexport function hashRemoteWorkspaceJson(value: unknown): string {\n\tassertRemoteWorkspaceJsonStructure(value);\n\treturn createHash(\"sha256\").update(canonicalJson(value)).digest(\"hex\");\n}\n\nexport function hashRemoteWorkspaceCatalog(catalog: RemoteWorkspaceCatalog): string {\n\treturn hashRemoteWorkspaceJson(catalog);\n}\n\nfunction assertUnique(values: readonly string[], label: string): void {\n\tif (new Set(values).size !== values.length) throw new RemoteWorkspaceValidationError(`${label} contains duplicates`);\n}\n\nexport function validateRemoteWorkspaceCatalog(catalog: RemoteWorkspaceCatalog): void {\n\tparseWithValidator(Compile(RemoteWorkspaceCatalogSchema), catalog, \"tool catalog\");\n\tassertUnique(catalog.operations, \"Catalog operations\");\n\tassertUnique(\n\t\tcatalog.tools.map((tool) => tool.name),\n\t\t\"Catalog tool names\",\n\t);\n\tfor (const tool of catalog.tools) {\n\t\tassertUnique(tool.featureFlags, `Feature flags for ${tool.name}`);\n\t\tif (hashRemoteWorkspaceJson(tool.parameterSchema) !== tool.schemaHash) {\n\t\t\tthrow new RemoteWorkspaceValidationError(`Schema hash mismatch for tool ${tool.name}`);\n\t\t}\n\t}\n}\n\nexport function validateRemoteWorkspaceLocalToolSchemas(\n\tcatalog: RemoteWorkspaceCatalog,\n\tlocalToolSchemas: ReadonlyMap<string, string>,\n): void {\n\tfor (const tool of catalog.tools) {\n\t\tconst localHash = localToolSchemas.get(tool.name);\n\t\tif (localHash !== undefined && localHash !== tool.schemaHash) {\n\t\t\tthrow new RemoteWorkspaceValidationError(\n\t\t\t\t`Remote schema does not match the local canonical schema for ${tool.name}`,\n\t\t\t);\n\t\t}\n\t}\n}\n\nexport function validateRemoteWorkspaceHandshakeAck(\n\tack: unknown,\n\toffer: RemoteWorkspaceHandshake,\n\tlocalToolSchemas: ReadonlyMap<string, string> = new Map(),\n): RemoteWorkspaceHandshakeAck {\n\tconst parsed = parseWithValidator<RemoteWorkspaceHandshakeAck>(handshakeAckValidator, ack, \"handshake response\");\n\tvalidateRemoteWorkspaceProtocolLimits(offer.receiveLimits);\n\tvalidateRemoteWorkspaceProtocolLimits(parsed.limits);\n\tconst selected = offer.versions.some(\n\t\t(range) =>\n\t\t\trange.major === parsed.version.major &&\n\t\t\trange.minMinor <= parsed.version.minor &&\n\t\t\trange.maxMinor >= parsed.version.minor,\n\t);\n\tif (!selected)\n\t\tthrow new RemoteWorkspaceValidationError(\"Server selected a protocol version outside the offered range\");\n\tconst offeredCapabilities = new Set([...offer.requiredCapabilities, ...offer.optionalCapabilities]);\n\tfor (const capability of parsed.capabilities) {\n\t\tif (!offeredCapabilities.has(capability)) {\n\t\t\tthrow new RemoteWorkspaceValidationError(`Server selected an unoffered capability: ${capability}`);\n\t\t}\n\t}\n\tconst selectedCapabilities = new Set(parsed.capabilities);\n\tfor (const capability of offer.requiredCapabilities) {\n\t\tif (!selectedCapabilities.has(capability)) {\n\t\t\tthrow new RemoteWorkspaceValidationError(`Server omitted required capability: ${capability}`);\n\t\t}\n\t}\n\tassertUnique(parsed.capabilities, \"Negotiated capabilities\");\n\tvalidateRemoteWorkspaceCatalog(parsed.catalog);\n\tif (hashRemoteWorkspaceCatalog(parsed.catalog) !== parsed.catalogHash) {\n\t\tthrow new RemoteWorkspaceValidationError(\"Catalog hash does not match the negotiated catalog\");\n\t}\n\tvalidateRemoteWorkspaceLocalToolSchemas(parsed.catalog, localToolSchemas);\n\tfor (const key of Object.keys(offer.receiveLimits) as (keyof RemoteWorkspaceProtocolLimits)[]) {\n\t\tif (parsed.limits[key] > offer.receiveLimits[key]) {\n\t\t\tthrow new RemoteWorkspaceValidationError(`Server increased negotiated limit: ${key}`);\n\t\t}\n\t}\n\treturn parsed;\n}\n\nexport interface RemoteWorkspaceNegotiationOptions {\n\tserverVersions: readonly RemoteWorkspaceVersionRange[];\n\tserverCapabilities: readonly string[];\n\trequiredClientCapabilities?: readonly string[];\n\tserverLimits: RemoteWorkspaceProtocolLimits;\n}\n\nexport interface RemoteWorkspaceNegotiationResult {\n\tversion: RemoteWorkspaceVersion;\n\tcapabilities: string[];\n\tlimits: RemoteWorkspaceProtocolLimits;\n}\n\nexport type RemoteWorkspaceNegotiationErrorCode = \"incompatible_version\" | \"capability_mismatch\";\n\nexport class RemoteWorkspaceNegotiationError extends Error {\n\treadonly code: RemoteWorkspaceNegotiationErrorCode;\n\n\tconstructor(code: RemoteWorkspaceNegotiationErrorCode, message: string) {\n\t\tsuper(message);\n\t\tthis.name = \"RemoteWorkspaceNegotiationError\";\n\t\tthis.code = code;\n\t}\n}\n\nfunction validateVersionRanges(ranges: readonly RemoteWorkspaceVersionRange[], label: string): void {\n\tfor (const range of ranges) {\n\t\tif (range.minMinor > range.maxMinor) {\n\t\t\tthrow new RemoteWorkspaceNegotiationError(\"incompatible_version\", `${label} has an inverted minor range`);\n\t\t}\n\t}\n}\n\nfunction findCompatibleRemoteWorkspaceVersions(\n\tclientVersions: readonly RemoteWorkspaceVersionRange[],\n\tserverVersions: readonly RemoteWorkspaceVersionRange[],\n): RemoteWorkspaceVersion[] {\n\tconst serverVersionsByMajor = new Map<number, RemoteWorkspaceVersionRange[]>();\n\tfor (const server of serverVersions) {\n\t\tconst ranges = serverVersionsByMajor.get(server.major) ?? [];\n\t\tranges.push(server);\n\t\tserverVersionsByMajor.set(server.major, ranges);\n\t}\n\tconst candidates: RemoteWorkspaceVersion[] = [];\n\tfor (const client of clientVersions) {\n\t\tfor (const server of serverVersionsByMajor.get(client.major) ?? []) {\n\t\t\tconst minMinor = Math.max(client.minMinor, server.minMinor);\n\t\t\tconst maxMinor = Math.min(client.maxMinor, server.maxMinor);\n\t\t\tif (minMinor <= maxMinor) candidates.push({ major: client.major, minor: maxMinor });\n\t\t}\n\t}\n\treturn candidates;\n}\n\nexport function negotiateRemoteWorkspaceHandshake(\n\thandshake: RemoteWorkspaceHandshake,\n\toptions: RemoteWorkspaceNegotiationOptions,\n): RemoteWorkspaceNegotiationResult {\n\tvalidateRemoteWorkspaceProtocolLimits(handshake.receiveLimits);\n\tvalidateRemoteWorkspaceProtocolLimits(options.serverLimits);\n\tvalidateVersionRanges(handshake.versions, \"Client version offer\");\n\tvalidateVersionRanges(options.serverVersions, \"Server version offer\");\n\tassertUnique(handshake.requiredCapabilities, \"Required capabilities\");\n\tassertUnique(handshake.optionalCapabilities, \"Optional capabilities\");\n\tconst optionalCapabilities = new Set(handshake.optionalCapabilities);\n\tconst duplicateOffer = handshake.requiredCapabilities.find((capability) => optionalCapabilities.has(capability));\n\tif (duplicateOffer) {\n\t\tthrow new RemoteWorkspaceNegotiationError(\n\t\t\t\"capability_mismatch\",\n\t\t\t`Capability is both required and optional: ${duplicateOffer}`,\n\t\t);\n\t}\n\tconst candidates = findCompatibleRemoteWorkspaceVersions(handshake.versions, options.serverVersions);\n\tcandidates.sort((left, right) => right.major - left.major || right.minor - left.minor);\n\tconst version = candidates[0];\n\tif (!version) {\n\t\tthrow new RemoteWorkspaceNegotiationError(\n\t\t\t\"incompatible_version\",\n\t\t\t\"No compatible remote workspace protocol version\",\n\t\t);\n\t}\n\tconst serverCapabilities = new Set(options.serverCapabilities);\n\tfor (const capability of handshake.requiredCapabilities) {\n\t\tif (!serverCapabilities.has(capability)) {\n\t\t\tthrow new RemoteWorkspaceNegotiationError(\n\t\t\t\t\"capability_mismatch\",\n\t\t\t\t`Server does not support required capability: ${capability}`,\n\t\t\t);\n\t\t}\n\t}\n\tconst clientCapabilities = new Set([...handshake.requiredCapabilities, ...handshake.optionalCapabilities]);\n\tfor (const capability of options.requiredClientCapabilities ?? []) {\n\t\tif (!clientCapabilities.has(capability)) {\n\t\t\tthrow new RemoteWorkspaceNegotiationError(\n\t\t\t\t\"capability_mismatch\",\n\t\t\t\t`Client does not support required capability: ${capability}`,\n\t\t\t);\n\t\t}\n\t}\n\tconst capabilities = Array.from(clientCapabilities)\n\t\t.filter((capability) => serverCapabilities.has(capability))\n\t\t.sort();\n\tconst clientLimits = handshake.receiveLimits;\n\tconst serverLimits = options.serverLimits;\n\treturn {\n\t\tversion,\n\t\tcapabilities,\n\t\tlimits: {\n\t\t\tmaxMessageBytes: Math.min(clientLimits.maxMessageBytes, serverLimits.maxMessageBytes),\n\t\t\tmaxStringBytes: Math.min(clientLimits.maxStringBytes, serverLimits.maxStringBytes),\n\t\t\tmaxDepth: Math.min(clientLimits.maxDepth, serverLimits.maxDepth),\n\t\t\tmaxObjectKeys: Math.min(clientLimits.maxObjectKeys, serverLimits.maxObjectKeys),\n\t\t\tmaxArrayLength: Math.min(clientLimits.maxArrayLength, serverLimits.maxArrayLength),\n\t\t\tmaxNodes: Math.min(clientLimits.maxNodes, serverLimits.maxNodes),\n\t\t\tmaxRequestMs: Math.min(clientLimits.maxRequestMs, serverLimits.maxRequestMs),\n\t\t\tmaxTransferChunkBytes: Math.min(clientLimits.maxTransferChunkBytes, serverLimits.maxTransferChunkBytes),\n\t\t\tmaxPendingTransferBytes: Math.min(clientLimits.maxPendingTransferBytes, serverLimits.maxPendingTransferBytes),\n\t\t\tmaxPendingInboundBytes: Math.min(clientLimits.maxPendingInboundBytes, serverLimits.maxPendingInboundBytes),\n\t\t\tmaxPendingInboundMessages: Math.min(\n\t\t\t\tclientLimits.maxPendingInboundMessages,\n\t\t\t\tserverLimits.maxPendingInboundMessages,\n\t\t\t),\n\t\t\tmaxPendingOutboundBytes: Math.min(clientLimits.maxPendingOutboundBytes, serverLimits.maxPendingOutboundBytes),\n\t\t\tmaxPendingOutboundMessages: Math.min(\n\t\t\t\tclientLimits.maxPendingOutboundMessages,\n\t\t\t\tserverLimits.maxPendingOutboundMessages,\n\t\t\t),\n\t\t\tmaxTransferBytes: Math.min(clientLimits.maxTransferBytes, serverLimits.maxTransferBytes),\n\t\t\tmaxTransferChunks: Math.min(clientLimits.maxTransferChunks, serverLimits.maxTransferChunks),\n\t\t\tmaxActiveRequests: Math.min(clientLimits.maxActiveRequests, serverLimits.maxActiveRequests),\n\t\t\tmaxActiveTransfers: Math.min(clientLimits.maxActiveTransfers, serverLimits.maxActiveTransfers),\n\t\t\tmaxCancellationMs: Math.min(clientLimits.maxCancellationMs, serverLimits.maxCancellationMs),\n\t\t\tmaxTransportSendMs: Math.min(clientLimits.maxTransportSendMs, serverLimits.maxTransportSendMs),\n\t\t},\n\t};\n}\n\nexport function getRemoteWorkspaceMethodKind(method: RemoteWorkspaceMethod): RemoteWorkspaceOperationKind {\n\tswitch (method) {\n\t\tcase \"workspace.write\":\n\t\tcase \"workspace.mkdir\":\n\t\tcase \"transfer.upload\":\n\t\t\treturn \"mutation\";\n\t\tcase \"workspace.exec\":\n\t\t\treturn \"process\";\n\t\tcase \"tool.invoke\":\n\t\t\treturn \"service\";\n\t\tdefault:\n\t\t\treturn \"read\";\n\t}\n}\n"]}
1
+ {"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../../../src/core/remote-workspace-protocol/contract.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAG5C,eAAO,MAAM,kCAAkC;aAAM,KAAK,EAAE,CAAC;aAAE,QAAQ,EAAE,CAAC;aAAE,QAAQ,EAAE,CAAC;EAAY,CAAC;AAEpG,eAAO,MAAM,6BAA6B,YACzC,iBAAiB,EACjB,cAAc,EACd,sBAAsB,EACtB,YAAY,EACZ,eAAe,EACf,WAAW,CACF,CAAC;AAEX,MAAM,MAAM,yBAAyB,GAAG,CAAC,OAAO,6BAA6B,CAAC,CAAC,MAAM,CAAC,CAAC;AAEvF,eAAO,MAAM,wBAAwB,YACpC,aAAa,EACb,aAAa,EACb,kBAAkB,EAClB,gBAAgB,EAChB,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,EAChB,mBAAmB,EACnB,gBAAgB,EAChB,gBAAgB,EAChB,6BAA6B,EAC7B,gBAAgB,EAChB,YAAY,EACZ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AAC,IAAI,EAAE,mCAAmC,CAAC;IAEnD,YAAY,IAAI,EAAE,mCAAmC,EAAE,OAAO,EAAE,MAAM,EAIrE;CACD;AA+BD,wBAAgB,iCAAiC,CAChD,SAAS,EAAE,wBAAwB,EACnC,OAAO,EAAE,iCAAiC,GACxC,gCAAgC,CA8ElC;AAED,wBAAgB,4BAA4B,CAAC,MAAM,EAAE,qBAAqB,GAAG,4BAA4B,CAaxG"}
@@ -261,6 +261,7 @@ export const RemoteWorkspaceServerMessageSchema = Type.Union([
261
261
  ]);
262
262
  const EmptyParamsSchema = Type.Object({}, closedObject);
263
263
  const PathParamsSchema = Type.Object({ path: Type.String({ minLength: 1, maxLength: 32_768 }) }, closedObject);
264
+ const WorkspaceStatParamsSchema = Type.Object({ path: Type.String({ minLength: 1, maxLength: 32_768 }), workspaceOnly: Type.Optional(Type.Boolean()) }, closedObject);
264
265
  const CatalogGetParamsSchema = EmptyParamsSchema;
265
266
  const SessionEnvironmentSchema = Type.Object({
266
267
  GRIP_SESSION_ID: Type.Optional(Type.String({ maxLength: 32_768 })),
@@ -287,6 +288,7 @@ const ToolInvokeParamsSchema = Type.Object({
287
288
  imageAutoResize: Type.Optional(Type.Boolean()),
288
289
  shellCommandPrefix: Type.Optional(Type.String({ maxLength: 32_768 })),
289
290
  sessionEnvironment: Type.Optional(SessionEnvironmentSchema),
291
+ cwd: Type.Optional(Type.String({ minLength: 1, maxLength: 32_768 })),
290
292
  }, closedObject),
291
293
  }, closedObject);
292
294
  const AccessParamsSchema = Type.Object({
@@ -385,6 +387,7 @@ const StatResultSchema = Type.Object({
385
387
  Type.Literal("absent"),
386
388
  ]),
387
389
  workspace: RemoteWorkspaceIdentitySchema,
390
+ canonicalPath: Type.Optional(Type.String({ minLength: 1, maxLength: 32_768 })),
388
391
  }, closedObject);
389
392
  const ReaddirResultSchema = Type.Object({
390
393
  entries: Type.Array(Type.String({ maxLength: 32_768 }), { maxItems: 1_000_000 }),
@@ -425,7 +428,7 @@ const parameterValidators = {
425
428
  "workspace.read": Compile(PathParamsSchema),
426
429
  "workspace.write": Compile(WriteParamsSchema),
427
430
  "workspace.mkdir": Compile(MkdirParamsSchema),
428
- "workspace.stat": Compile(PathParamsSchema),
431
+ "workspace.stat": Compile(WorkspaceStatParamsSchema),
429
432
  "workspace.readdir": Compile(PathParamsSchema),
430
433
  "workspace.glob": Compile(GlobParamsSchema),
431
434
  "workspace.grep": Compile(GrepParamsSchema),
@@ -715,7 +718,6 @@ export function validateRemoteWorkspaceHandshakeAck(ack, offer, localToolSchemas
715
718
  return parsed;
716
719
  }
717
720
  export class RemoteWorkspaceNegotiationError extends Error {
718
- code;
719
721
  constructor(code, message) {
720
722
  super(message);
721
723
  this.name = "RemoteWorkspaceNegotiationError";