@greppleai/grip 0.0.0-stage → 0.1.3

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 (1119) hide show
  1. package/CHANGELOG.md +115 -0
  2. package/README.md +731 -2
  3. package/dist/bun/cli.d.ts +3 -0
  4. package/dist/bun/cli.d.ts.map +1 -0
  5. package/dist/bun/cli.js +13 -0
  6. package/dist/bun/cli.js.map +1 -0
  7. package/dist/bun/embedded-assets.d.ts +3 -0
  8. package/dist/bun/embedded-assets.d.ts.map +1 -0
  9. package/dist/bun/embedded-assets.js +52 -0
  10. package/dist/bun/embedded-assets.js.map +1 -0
  11. package/dist/bun/register-bedrock.d.ts +2 -0
  12. package/dist/bun/register-bedrock.d.ts.map +1 -0
  13. package/dist/bun/register-bedrock.js +4 -0
  14. package/dist/bun/register-bedrock.js.map +1 -0
  15. package/dist/bun/restore-sandbox-env.d.ts +13 -0
  16. package/dist/bun/restore-sandbox-env.d.ts.map +1 -0
  17. package/dist/bun/restore-sandbox-env.js +32 -0
  18. package/dist/bun/restore-sandbox-env.js.map +1 -0
  19. package/dist/cli/args.d.ts +70 -0
  20. package/dist/cli/args.d.ts.map +1 -0
  21. package/dist/cli/args.js +442 -0
  22. package/dist/cli/args.js.map +1 -0
  23. package/dist/cli/config-selector.d.ts +14 -0
  24. package/dist/cli/config-selector.d.ts.map +1 -0
  25. package/dist/cli/config-selector.js +31 -0
  26. package/dist/cli/config-selector.js.map +1 -0
  27. package/dist/cli/file-processor.d.ts +15 -0
  28. package/dist/cli/file-processor.d.ts.map +1 -0
  29. package/dist/cli/file-processor.js +60 -0
  30. package/dist/cli/file-processor.js.map +1 -0
  31. package/dist/cli/initial-message.d.ts +18 -0
  32. package/dist/cli/initial-message.d.ts.map +1 -0
  33. package/dist/cli/initial-message.js +22 -0
  34. package/dist/cli/initial-message.js.map +1 -0
  35. package/dist/cli/list-models.d.ts +9 -0
  36. package/dist/cli/list-models.d.ts.map +1 -0
  37. package/dist/cli/list-models.js +98 -0
  38. package/dist/cli/list-models.js.map +1 -0
  39. package/dist/cli/session-picker.d.ts +9 -0
  40. package/dist/cli/session-picker.d.ts.map +1 -0
  41. package/dist/cli/session-picker.js +35 -0
  42. package/dist/cli/session-picker.js.map +1 -0
  43. package/dist/cli.d.ts +3 -0
  44. package/dist/cli.d.ts.map +1 -0
  45. package/dist/cli.js +14 -0
  46. package/dist/cli.js.map +1 -0
  47. package/dist/config.d.ts +82 -0
  48. package/dist/config.d.ts.map +1 -0
  49. package/dist/config.js +406 -0
  50. package/dist/config.js.map +1 -0
  51. package/dist/core/agent-session.d.ts +970 -0
  52. package/dist/core/agent-session.d.ts.map +1 -0
  53. package/dist/core/agent-session.js +5191 -0
  54. package/dist/core/agent-session.js.map +1 -0
  55. package/dist/core/auth-guidance.d.ts +5 -0
  56. package/dist/core/auth-guidance.d.ts.map +1 -0
  57. package/dist/core/auth-guidance.js +21 -0
  58. package/dist/core/auth-guidance.js.map +1 -0
  59. package/dist/core/auth-storage.d.ts +150 -0
  60. package/dist/core/auth-storage.d.ts.map +1 -0
  61. package/dist/core/auth-storage.js +557 -0
  62. package/dist/core/auth-storage.js.map +1 -0
  63. package/dist/core/bash-executor.d.ts +26 -0
  64. package/dist/core/bash-executor.d.ts.map +1 -0
  65. package/dist/core/bash-executor.js +99 -0
  66. package/dist/core/bash-executor.js.map +1 -0
  67. package/dist/core/compaction/branch-summarization.d.ts +83 -0
  68. package/dist/core/compaction/branch-summarization.d.ts.map +1 -0
  69. package/dist/core/compaction/branch-summarization.js +220 -0
  70. package/dist/core/compaction/branch-summarization.js.map +1 -0
  71. package/dist/core/compaction/compaction.d.ts +65 -0
  72. package/dist/core/compaction/compaction.d.ts.map +1 -0
  73. package/dist/core/compaction/compaction.js +550 -0
  74. package/dist/core/compaction/compaction.js.map +1 -0
  75. package/dist/core/compaction/compression-detection-ledger.d.ts +34 -0
  76. package/dist/core/compaction/compression-detection-ledger.d.ts.map +1 -0
  77. package/dist/core/compaction/compression-detection-ledger.js +52 -0
  78. package/dist/core/compaction/compression-detection-ledger.js.map +1 -0
  79. package/dist/core/compaction/compression-detector.d.ts +71 -0
  80. package/dist/core/compaction/compression-detector.d.ts.map +1 -0
  81. package/dist/core/compaction/compression-detector.js +407 -0
  82. package/dist/core/compaction/compression-detector.js.map +1 -0
  83. package/dist/core/compaction/compression-economics.d.ts +55 -0
  84. package/dist/core/compaction/compression-economics.d.ts.map +1 -0
  85. package/dist/core/compaction/compression-economics.js +151 -0
  86. package/dist/core/compaction/compression-economics.js.map +1 -0
  87. package/dist/core/compaction/utils.d.ts +28 -0
  88. package/dist/core/compaction/utils.d.ts.map +1 -0
  89. package/dist/core/compaction/utils.js +165 -0
  90. package/dist/core/compaction/utils.js.map +1 -0
  91. package/dist/core/defaults.d.ts +3 -0
  92. package/dist/core/defaults.d.ts.map +1 -0
  93. package/dist/core/defaults.js +2 -0
  94. package/dist/core/defaults.js.map +1 -0
  95. package/dist/core/diagnostics.d.ts +18 -0
  96. package/dist/core/diagnostics.d.ts.map +1 -0
  97. package/dist/core/diagnostics.js +2 -0
  98. package/dist/core/diagnostics.js.map +1 -0
  99. package/dist/core/event-bus.d.ts +9 -0
  100. package/dist/core/event-bus.d.ts.map +1 -0
  101. package/dist/core/event-bus.js +25 -0
  102. package/dist/core/event-bus.js.map +1 -0
  103. package/dist/core/exec.d.ts +29 -0
  104. package/dist/core/exec.d.ts.map +1 -0
  105. package/dist/core/exec.js +75 -0
  106. package/dist/core/exec.js.map +1 -0
  107. package/dist/core/export-html/ansi-to-html.d.ts +22 -0
  108. package/dist/core/export-html/ansi-to-html.d.ts.map +1 -0
  109. package/dist/core/export-html/ansi-to-html.js +245 -0
  110. package/dist/core/export-html/ansi-to-html.js.map +1 -0
  111. package/dist/core/export-html/index.d.ts +21 -0
  112. package/dist/core/export-html/index.d.ts.map +1 -0
  113. package/dist/core/export-html/index.js +230 -0
  114. package/dist/core/export-html/index.js.map +1 -0
  115. package/dist/core/export-html/template.css +1066 -0
  116. package/dist/core/export-html/template.html +55 -0
  117. package/dist/core/export-html/template.js +1864 -0
  118. package/dist/core/export-html/tool-renderer.d.ts +32 -0
  119. package/dist/core/export-html/tool-renderer.d.ts.map +1 -0
  120. package/dist/core/export-html/tool-renderer.js +108 -0
  121. package/dist/core/export-html/tool-renderer.js.map +1 -0
  122. package/dist/core/export-html/vendor/highlight.min.js +1213 -0
  123. package/dist/core/export-html/vendor/marked.min.js +78 -0
  124. package/dist/core/extensions/loader.d.ts +24 -0
  125. package/dist/core/extensions/loader.d.ts.map +1 -0
  126. package/dist/core/extensions/loader.js +613 -0
  127. package/dist/core/extensions/loader.js.map +1 -0
  128. package/dist/core/extensions/runner.d.ts +160 -0
  129. package/dist/core/extensions/runner.d.ts.map +1 -0
  130. package/dist/core/extensions/runner.js +962 -0
  131. package/dist/core/extensions/runner.js.map +1 -0
  132. package/dist/core/extensions/types.d.ts +1311 -0
  133. package/dist/core/extensions/types.d.ts.map +1 -0
  134. package/dist/core/extensions/types.js +51 -0
  135. package/dist/core/extensions/types.js.map +1 -0
  136. package/dist/core/extensions/wrapper.d.ts +20 -0
  137. package/dist/core/extensions/wrapper.d.ts.map +1 -0
  138. package/dist/core/extensions/wrapper.js +22 -0
  139. package/dist/core/extensions/wrapper.js.map +1 -0
  140. package/dist/core/footer-data-provider.d.ts +52 -0
  141. package/dist/core/footer-data-provider.d.ts.map +1 -0
  142. package/dist/core/footer-data-provider.js +318 -0
  143. package/dist/core/footer-data-provider.js.map +1 -0
  144. package/dist/core/grip-agent.d.ts +240 -0
  145. package/dist/core/grip-agent.d.ts.map +1 -0
  146. package/dist/core/grip-agent.js +1243 -0
  147. package/dist/core/grip-agent.js.map +1 -0
  148. package/dist/core/grip-manifest.d.ts +9 -0
  149. package/dist/core/grip-manifest.d.ts.map +1 -0
  150. package/dist/core/grip-manifest.js +25 -0
  151. package/dist/core/grip-manifest.js.map +1 -0
  152. package/dist/core/hooks/aggregate.d.ts +5 -0
  153. package/dist/core/hooks/aggregate.d.ts.map +1 -0
  154. package/dist/core/hooks/aggregate.js +226 -0
  155. package/dist/core/hooks/aggregate.js.map +1 -0
  156. package/dist/core/hooks/config.d.ts +14 -0
  157. package/dist/core/hooks/config.d.ts.map +1 -0
  158. package/dist/core/hooks/config.js +372 -0
  159. package/dist/core/hooks/config.js.map +1 -0
  160. package/dist/core/hooks/executor.d.ts +12 -0
  161. package/dist/core/hooks/executor.d.ts.map +1 -0
  162. package/dist/core/hooks/executor.js +708 -0
  163. package/dist/core/hooks/executor.js.map +1 -0
  164. package/dist/core/hooks/index.d.ts +9 -0
  165. package/dist/core/hooks/index.d.ts.map +1 -0
  166. package/dist/core/hooks/index.js +14 -0
  167. package/dist/core/hooks/index.js.map +1 -0
  168. package/dist/core/hooks/matcher.d.ts +10 -0
  169. package/dist/core/hooks/matcher.d.ts.map +1 -0
  170. package/dist/core/hooks/matcher.js +70 -0
  171. package/dist/core/hooks/matcher.js.map +1 -0
  172. package/dist/core/hooks/trust-store.d.ts +38 -0
  173. package/dist/core/hooks/trust-store.d.ts.map +1 -0
  174. package/dist/core/hooks/trust-store.js +167 -0
  175. package/dist/core/hooks/trust-store.js.map +1 -0
  176. package/dist/core/hooks/types.d.ts +234 -0
  177. package/dist/core/hooks/types.d.ts.map +1 -0
  178. package/dist/core/hooks/types.js +52 -0
  179. package/dist/core/hooks/types.js.map +1 -0
  180. package/dist/core/http-dispatcher.d.ts +21 -0
  181. package/dist/core/http-dispatcher.d.ts.map +1 -0
  182. package/dist/core/http-dispatcher.js +82 -0
  183. package/dist/core/http-dispatcher.js.map +1 -0
  184. package/dist/core/instruction-resource-loader.d.ts +81 -0
  185. package/dist/core/instruction-resource-loader.d.ts.map +1 -0
  186. package/dist/core/instruction-resource-loader.js +574 -0
  187. package/dist/core/instruction-resource-loader.js.map +1 -0
  188. package/dist/core/keybindings.d.ts +399 -0
  189. package/dist/core/keybindings.d.ts.map +1 -0
  190. package/dist/core/keybindings.js +299 -0
  191. package/dist/core/keybindings.js.map +1 -0
  192. package/dist/core/lsp/abort.d.ts +3 -0
  193. package/dist/core/lsp/abort.d.ts.map +1 -0
  194. package/dist/core/lsp/abort.js +28 -0
  195. package/dist/core/lsp/abort.js.map +1 -0
  196. package/dist/core/lsp/client.d.ts +108 -0
  197. package/dist/core/lsp/client.d.ts.map +1 -0
  198. package/dist/core/lsp/client.js +586 -0
  199. package/dist/core/lsp/client.js.map +1 -0
  200. package/dist/core/lsp/config-loader.d.ts +44 -0
  201. package/dist/core/lsp/config-loader.d.ts.map +1 -0
  202. package/dist/core/lsp/config-loader.js +223 -0
  203. package/dist/core/lsp/config-loader.js.map +1 -0
  204. package/dist/core/lsp/config.d.ts +134 -0
  205. package/dist/core/lsp/config.d.ts.map +1 -0
  206. package/dist/core/lsp/config.js +682 -0
  207. package/dist/core/lsp/config.js.map +1 -0
  208. package/dist/core/lsp/diagnostics.d.ts +18 -0
  209. package/dist/core/lsp/diagnostics.d.ts.map +1 -0
  210. package/dist/core/lsp/diagnostics.js +311 -0
  211. package/dist/core/lsp/diagnostics.js.map +1 -0
  212. package/dist/core/lsp/file-sync.d.ts +58 -0
  213. package/dist/core/lsp/file-sync.d.ts.map +1 -0
  214. package/dist/core/lsp/file-sync.js +432 -0
  215. package/dist/core/lsp/file-sync.js.map +1 -0
  216. package/dist/core/lsp/integration.d.ts +62 -0
  217. package/dist/core/lsp/integration.d.ts.map +1 -0
  218. package/dist/core/lsp/integration.js +145 -0
  219. package/dist/core/lsp/integration.js.map +1 -0
  220. package/dist/core/lsp/language-map.d.ts +54 -0
  221. package/dist/core/lsp/language-map.d.ts.map +1 -0
  222. package/dist/core/lsp/language-map.js +300 -0
  223. package/dist/core/lsp/language-map.js.map +1 -0
  224. package/dist/core/lsp/manager.d.ts +120 -0
  225. package/dist/core/lsp/manager.d.ts.map +1 -0
  226. package/dist/core/lsp/manager.js +636 -0
  227. package/dist/core/lsp/manager.js.map +1 -0
  228. package/dist/core/lsp/navigation.d.ts +32 -0
  229. package/dist/core/lsp/navigation.d.ts.map +1 -0
  230. package/dist/core/lsp/navigation.js +327 -0
  231. package/dist/core/lsp/navigation.js.map +1 -0
  232. package/dist/core/lsp/portable-path.d.ts +18 -0
  233. package/dist/core/lsp/portable-path.d.ts.map +1 -0
  234. package/dist/core/lsp/portable-path.js +83 -0
  235. package/dist/core/lsp/portable-path.js.map +1 -0
  236. package/dist/core/lsp/refactor.d.ts +32 -0
  237. package/dist/core/lsp/refactor.d.ts.map +1 -0
  238. package/dist/core/lsp/refactor.js +519 -0
  239. package/dist/core/lsp/refactor.js.map +1 -0
  240. package/dist/core/lsp/transport.d.ts +39 -0
  241. package/dist/core/lsp/transport.d.ts.map +1 -0
  242. package/dist/core/lsp/transport.js +261 -0
  243. package/dist/core/lsp/transport.js.map +1 -0
  244. package/dist/core/messages.d.ts +34 -0
  245. package/dist/core/messages.d.ts.map +1 -0
  246. package/dist/core/messages.js +140 -0
  247. package/dist/core/messages.js.map +1 -0
  248. package/dist/core/model-registry.d.ts +148 -0
  249. package/dist/core/model-registry.d.ts.map +1 -0
  250. package/dist/core/model-registry.js +812 -0
  251. package/dist/core/model-registry.js.map +1 -0
  252. package/dist/core/model-resolver.d.ts +115 -0
  253. package/dist/core/model-resolver.d.ts.map +1 -0
  254. package/dist/core/model-resolver.js +498 -0
  255. package/dist/core/model-resolver.js.map +1 -0
  256. package/dist/core/output-guard.d.ts +7 -0
  257. package/dist/core/output-guard.d.ts.map +1 -0
  258. package/dist/core/output-guard.js +89 -0
  259. package/dist/core/output-guard.js.map +1 -0
  260. package/dist/core/package-manager.d.ts +209 -0
  261. package/dist/core/package-manager.d.ts.map +1 -0
  262. package/dist/core/package-manager.js +2341 -0
  263. package/dist/core/package-manager.js.map +1 -0
  264. package/dist/core/prompt-templates.d.ts +57 -0
  265. package/dist/core/prompt-templates.d.ts.map +1 -0
  266. package/dist/core/prompt-templates.js +353 -0
  267. package/dist/core/prompt-templates.js.map +1 -0
  268. package/dist/core/provider-display-names.d.ts +2 -0
  269. package/dist/core/provider-display-names.d.ts.map +1 -0
  270. package/dist/core/provider-display-names.js +33 -0
  271. package/dist/core/provider-display-names.js.map +1 -0
  272. package/dist/core/remote-workspace-protocol/contract.d.ts +465 -0
  273. package/dist/core/remote-workspace-protocol/contract.d.ts.map +1 -0
  274. package/dist/core/remote-workspace-protocol/contract.js +825 -0
  275. package/dist/core/remote-workspace-protocol/contract.js.map +1 -0
  276. package/dist/core/remote-workspace-protocol/guest-shared-client.d.ts +16 -0
  277. package/dist/core/remote-workspace-protocol/guest-shared-client.d.ts.map +1 -0
  278. package/dist/core/remote-workspace-protocol/guest-shared-client.js +54 -0
  279. package/dist/core/remote-workspace-protocol/guest-shared-client.js.map +1 -0
  280. package/dist/core/remote-workspace-protocol/guest-shared-outbound-scheduler.d.ts +23 -0
  281. package/dist/core/remote-workspace-protocol/guest-shared-outbound-scheduler.d.ts.map +1 -0
  282. package/dist/core/remote-workspace-protocol/guest-shared-outbound-scheduler.js +112 -0
  283. package/dist/core/remote-workspace-protocol/guest-shared-outbound-scheduler.js.map +1 -0
  284. package/dist/core/remote-workspace-protocol/guest-shared-uplink.d.ts +30 -0
  285. package/dist/core/remote-workspace-protocol/guest-shared-uplink.d.ts.map +1 -0
  286. package/dist/core/remote-workspace-protocol/guest-shared-uplink.js +243 -0
  287. package/dist/core/remote-workspace-protocol/guest-shared-uplink.js.map +1 -0
  288. package/dist/core/remote-workspace-protocol/lima-owner-directory.d.ts +3 -0
  289. package/dist/core/remote-workspace-protocol/lima-owner-directory.d.ts.map +1 -0
  290. package/dist/core/remote-workspace-protocol/lima-owner-directory.js +31 -0
  291. package/dist/core/remote-workspace-protocol/lima-owner-directory.js.map +1 -0
  292. package/dist/core/remote-workspace-protocol/lima-owner-lock.d.ts +9 -0
  293. package/dist/core/remote-workspace-protocol/lima-owner-lock.d.ts.map +1 -0
  294. package/dist/core/remote-workspace-protocol/lima-owner-lock.js +89 -0
  295. package/dist/core/remote-workspace-protocol/lima-owner-lock.js.map +1 -0
  296. package/dist/core/remote-workspace-protocol/session.d.ts +249 -0
  297. package/dist/core/remote-workspace-protocol/session.d.ts.map +1 -0
  298. package/dist/core/remote-workspace-protocol/session.js +1842 -0
  299. package/dist/core/remote-workspace-protocol/session.js.map +1 -0
  300. package/dist/core/remote-workspace-protocol/shared-transport.d.ts +71 -0
  301. package/dist/core/remote-workspace-protocol/shared-transport.d.ts.map +1 -0
  302. package/dist/core/remote-workspace-protocol/shared-transport.js +68 -0
  303. package/dist/core/remote-workspace-protocol/shared-transport.js.map +1 -0
  304. package/dist/core/resolve-config-value.d.ts +32 -0
  305. package/dist/core/resolve-config-value.d.ts.map +1 -0
  306. package/dist/core/resolve-config-value.js +257 -0
  307. package/dist/core/resolve-config-value.js.map +1 -0
  308. package/dist/core/resource-loader.d.ts +200 -0
  309. package/dist/core/resource-loader.d.ts.map +1 -0
  310. package/dist/core/resource-loader.js +1209 -0
  311. package/dist/core/resource-loader.js.map +1 -0
  312. package/dist/core/rules.d.ts +40 -0
  313. package/dist/core/rules.d.ts.map +1 -0
  314. package/dist/core/rules.js +57 -0
  315. package/dist/core/rules.js.map +1 -0
  316. package/dist/core/sandbox/command.d.ts +25 -0
  317. package/dist/core/sandbox/command.d.ts.map +1 -0
  318. package/dist/core/sandbox/command.js +102 -0
  319. package/dist/core/sandbox/command.js.map +1 -0
  320. package/dist/core/sandbox/config.d.ts +91 -0
  321. package/dist/core/sandbox/config.d.ts.map +1 -0
  322. package/dist/core/sandbox/config.js +88 -0
  323. package/dist/core/sandbox/config.js.map +1 -0
  324. package/dist/core/sandbox/lima-guest-binary.d.ts +11 -0
  325. package/dist/core/sandbox/lima-guest-binary.d.ts.map +1 -0
  326. package/dist/core/sandbox/lima-guest-binary.js +140 -0
  327. package/dist/core/sandbox/lima-guest-binary.js.map +1 -0
  328. package/dist/core/sandbox/lima.d.ts +57 -0
  329. package/dist/core/sandbox/lima.d.ts.map +1 -0
  330. package/dist/core/sandbox/lima.js +716 -0
  331. package/dist/core/sandbox/lima.js.map +1 -0
  332. package/dist/core/sandbox/shared-lima-roots.d.ts +11 -0
  333. package/dist/core/sandbox/shared-lima-roots.d.ts.map +1 -0
  334. package/dist/core/sandbox/shared-lima-roots.js +25 -0
  335. package/dist/core/sandbox/shared-lima-roots.js.map +1 -0
  336. package/dist/core/sandbox/update-shared-guest-binary.d.ts +8 -0
  337. package/dist/core/sandbox/update-shared-guest-binary.d.ts.map +1 -0
  338. package/dist/core/sandbox/update-shared-guest-binary.js +100 -0
  339. package/dist/core/sandbox/update-shared-guest-binary.js.map +1 -0
  340. package/dist/core/session/constants.d.ts +2 -0
  341. package/dist/core/session/constants.d.ts.map +1 -0
  342. package/dist/core/session/constants.js +2 -0
  343. package/dist/core/session/constants.js.map +1 -0
  344. package/dist/core/session/context-metadata.d.ts +5 -0
  345. package/dist/core/session/context-metadata.d.ts.map +1 -0
  346. package/dist/core/session/context-metadata.js +55 -0
  347. package/dist/core/session/context-metadata.js.map +1 -0
  348. package/dist/core/session/context.d.ts +14 -0
  349. package/dist/core/session/context.d.ts.map +1 -0
  350. package/dist/core/session/context.js +117 -0
  351. package/dist/core/session/context.js.map +1 -0
  352. package/dist/core/session/ids.d.ts +9 -0
  353. package/dist/core/session/ids.d.ts.map +1 -0
  354. package/dist/core/session/ids.js +21 -0
  355. package/dist/core/session/ids.js.map +1 -0
  356. package/dist/core/session/in-memory-session-manager.d.ts +17 -0
  357. package/dist/core/session/in-memory-session-manager.d.ts.map +1 -0
  358. package/dist/core/session/in-memory-session-manager.js +40 -0
  359. package/dist/core/session/in-memory-session-manager.js.map +1 -0
  360. package/dist/core/session/in-memory-session.d.ts +7 -0
  361. package/dist/core/session/in-memory-session.d.ts.map +1 -0
  362. package/dist/core/session/in-memory-session.js +11 -0
  363. package/dist/core/session/in-memory-session.js.map +1 -0
  364. package/dist/core/session/jsonl-errors.d.ts +36 -0
  365. package/dist/core/session/jsonl-errors.d.ts.map +1 -0
  366. package/dist/core/session/jsonl-errors.js +49 -0
  367. package/dist/core/session/jsonl-errors.js.map +1 -0
  368. package/dist/core/session/jsonl-helpers.d.ts +20 -0
  369. package/dist/core/session/jsonl-helpers.d.ts.map +1 -0
  370. package/dist/core/session/jsonl-helpers.js +21 -0
  371. package/dist/core/session/jsonl-helpers.js.map +1 -0
  372. package/dist/core/session/local-session-manager.d.ts +30 -0
  373. package/dist/core/session/local-session-manager.d.ts.map +1 -0
  374. package/dist/core/session/local-session-manager.js +205 -0
  375. package/dist/core/session/local-session-manager.js.map +1 -0
  376. package/dist/core/session/local-session.d.ts +9 -0
  377. package/dist/core/session/local-session.d.ts.map +1 -0
  378. package/dist/core/session/local-session.js +15 -0
  379. package/dist/core/session/local-session.js.map +1 -0
  380. package/dist/core/session/migrations.d.ts +11 -0
  381. package/dist/core/session/migrations.d.ts.map +1 -0
  382. package/dist/core/session/migrations.js +78 -0
  383. package/dist/core/session/migrations.js.map +1 -0
  384. package/dist/core/session/remote-session-client.d.ts +83 -0
  385. package/dist/core/session/remote-session-client.d.ts.map +1 -0
  386. package/dist/core/session/remote-session-client.js +224 -0
  387. package/dist/core/session/remote-session-client.js.map +1 -0
  388. package/dist/core/session/remote-session-manager.d.ts +32 -0
  389. package/dist/core/session/remote-session-manager.d.ts.map +1 -0
  390. package/dist/core/session/remote-session-manager.js +124 -0
  391. package/dist/core/session/remote-session-manager.js.map +1 -0
  392. package/dist/core/session/remote-session.d.ts +20 -0
  393. package/dist/core/session/remote-session.d.ts.map +1 -0
  394. package/dist/core/session/remote-session.js +33 -0
  395. package/dist/core/session/remote-session.js.map +1 -0
  396. package/dist/core/session/session-manager.d.ts +18 -0
  397. package/dist/core/session/session-manager.d.ts.map +1 -0
  398. package/dist/core/session/session-manager.js +2 -0
  399. package/dist/core/session/session-manager.js.map +1 -0
  400. package/dist/core/session/session.d.ts +140 -0
  401. package/dist/core/session/session.d.ts.map +1 -0
  402. package/dist/core/session/session.js +461 -0
  403. package/dist/core/session/session.js.map +1 -0
  404. package/dist/core/session/stores/in-memory-session-store.d.ts +39 -0
  405. package/dist/core/session/stores/in-memory-session-store.d.ts.map +1 -0
  406. package/dist/core/session/stores/in-memory-session-store.js +168 -0
  407. package/dist/core/session/stores/in-memory-session-store.js.map +1 -0
  408. package/dist/core/session/stores/jsonl-session-store.d.ts +97 -0
  409. package/dist/core/session/stores/jsonl-session-store.d.ts.map +1 -0
  410. package/dist/core/session/stores/jsonl-session-store.js +1140 -0
  411. package/dist/core/session/stores/jsonl-session-store.js.map +1 -0
  412. package/dist/core/session/stores/remote-session-store.d.ts +44 -0
  413. package/dist/core/session/stores/remote-session-store.d.ts.map +1 -0
  414. package/dist/core/session/stores/remote-session-store.js +159 -0
  415. package/dist/core/session/stores/remote-session-store.js.map +1 -0
  416. package/dist/core/session/stores/session-store.d.ts +42 -0
  417. package/dist/core/session/stores/session-store.d.ts.map +1 -0
  418. package/dist/core/session/stores/session-store.js +2 -0
  419. package/dist/core/session/stores/session-store.js.map +1 -0
  420. package/dist/core/session/types.d.ts +141 -0
  421. package/dist/core/session/types.d.ts.map +1 -0
  422. package/dist/core/session/types.js +2 -0
  423. package/dist/core/session/types.js.map +1 -0
  424. package/dist/core/session/usage-ledger.d.ts +18 -0
  425. package/dist/core/session/usage-ledger.d.ts.map +1 -0
  426. package/dist/core/session/usage-ledger.js +68 -0
  427. package/dist/core/session/usage-ledger.js.map +1 -0
  428. package/dist/core/session-cwd.d.ts +19 -0
  429. package/dist/core/session-cwd.d.ts.map +1 -0
  430. package/dist/core/session-cwd.js +38 -0
  431. package/dist/core/session-cwd.js.map +1 -0
  432. package/dist/core/settings-manager.d.ts +314 -0
  433. package/dist/core/settings-manager.d.ts.map +1 -0
  434. package/dist/core/settings-manager.js +991 -0
  435. package/dist/core/settings-manager.js.map +1 -0
  436. package/dist/core/skills.d.ts +40 -0
  437. package/dist/core/skills.d.ts.map +1 -0
  438. package/dist/core/skills.js +57 -0
  439. package/dist/core/skills.js.map +1 -0
  440. package/dist/core/slash-commands.d.ts +15 -0
  441. package/dist/core/slash-commands.d.ts.map +1 -0
  442. package/dist/core/slash-commands.js +36 -0
  443. package/dist/core/slash-commands.js.map +1 -0
  444. package/dist/core/source-info.d.ts +26 -0
  445. package/dist/core/source-info.d.ts.map +1 -0
  446. package/dist/core/source-info.js +27 -0
  447. package/dist/core/source-info.js.map +1 -0
  448. package/dist/core/system-prompt.d.ts +32 -0
  449. package/dist/core/system-prompt.d.ts.map +1 -0
  450. package/dist/core/system-prompt.js +131 -0
  451. package/dist/core/system-prompt.js.map +1 -0
  452. package/dist/core/telemetry.d.ts +3 -0
  453. package/dist/core/telemetry.d.ts.map +1 -0
  454. package/dist/core/telemetry.js +9 -0
  455. package/dist/core/telemetry.js.map +1 -0
  456. package/dist/core/timings.d.ts +10 -0
  457. package/dist/core/timings.d.ts.map +1 -0
  458. package/dist/core/timings.js +41 -0
  459. package/dist/core/timings.js.map +1 -0
  460. package/dist/core/tools/bash.d.ts +51 -0
  461. package/dist/core/tools/bash.d.ts.map +1 -0
  462. package/dist/core/tools/bash.js +321 -0
  463. package/dist/core/tools/bash.js.map +1 -0
  464. package/dist/core/tools/compress-context.d.ts +27 -0
  465. package/dist/core/tools/compress-context.d.ts.map +1 -0
  466. package/dist/core/tools/compress-context.js +142 -0
  467. package/dist/core/tools/compress-context.js.map +1 -0
  468. package/dist/core/tools/edit-diff.d.ts +82 -0
  469. package/dist/core/tools/edit-diff.d.ts.map +1 -0
  470. package/dist/core/tools/edit-diff.js +327 -0
  471. package/dist/core/tools/edit-diff.js.map +1 -0
  472. package/dist/core/tools/edit.d.ts +50 -0
  473. package/dist/core/tools/edit.d.ts.map +1 -0
  474. package/dist/core/tools/edit.js +324 -0
  475. package/dist/core/tools/edit.js.map +1 -0
  476. package/dist/core/tools/file-mutation-queue.d.ts +8 -0
  477. package/dist/core/tools/file-mutation-queue.d.ts.map +1 -0
  478. package/dist/core/tools/file-mutation-queue.js +69 -0
  479. package/dist/core/tools/file-mutation-queue.js.map +1 -0
  480. package/dist/core/tools/find.d.ts +22 -0
  481. package/dist/core/tools/find.d.ts.map +1 -0
  482. package/dist/core/tools/find.js +268 -0
  483. package/dist/core/tools/find.js.map +1 -0
  484. package/dist/core/tools/grep.d.ts +27 -0
  485. package/dist/core/tools/grep.d.ts.map +1 -0
  486. package/dist/core/tools/grep.js +332 -0
  487. package/dist/core/tools/grep.js.map +1 -0
  488. package/dist/core/tools/hash-store.d.ts +12 -0
  489. package/dist/core/tools/hash-store.d.ts.map +1 -0
  490. package/dist/core/tools/hash-store.js +48 -0
  491. package/dist/core/tools/hash-store.js.map +1 -0
  492. package/dist/core/tools/hashline/apply.d.ts +40 -0
  493. package/dist/core/tools/hashline/apply.d.ts.map +1 -0
  494. package/dist/core/tools/hashline/apply.js +261 -0
  495. package/dist/core/tools/hashline/apply.js.map +1 -0
  496. package/dist/core/tools/hashline/hash.d.ts +56 -0
  497. package/dist/core/tools/hashline/hash.d.ts.map +1 -0
  498. package/dist/core/tools/hashline/hash.js +196 -0
  499. package/dist/core/tools/hashline/hash.js.map +1 -0
  500. package/dist/core/tools/hashline/parse.d.ts +8 -0
  501. package/dist/core/tools/hashline/parse.d.ts.map +1 -0
  502. package/dist/core/tools/hashline/parse.js +41 -0
  503. package/dist/core/tools/hashline/parse.js.map +1 -0
  504. package/dist/core/tools/hashline/resolve.d.ts +51 -0
  505. package/dist/core/tools/hashline/resolve.d.ts.map +1 -0
  506. package/dist/core/tools/hashline/resolve.js +187 -0
  507. package/dist/core/tools/hashline/resolve.js.map +1 -0
  508. package/dist/core/tools/hashline-utils.d.ts +6 -0
  509. package/dist/core/tools/hashline-utils.d.ts.map +1 -0
  510. package/dist/core/tools/hashline-utils.js +23 -0
  511. package/dist/core/tools/hashline-utils.js.map +1 -0
  512. package/dist/core/tools/index.d.ts +36 -0
  513. package/dist/core/tools/index.d.ts.map +1 -0
  514. package/dist/core/tools/index.js +141 -0
  515. package/dist/core/tools/index.js.map +1 -0
  516. package/dist/core/tools/ls.d.ts +21 -0
  517. package/dist/core/tools/ls.d.ts.map +1 -0
  518. package/dist/core/tools/ls.js +156 -0
  519. package/dist/core/tools/ls.js.map +1 -0
  520. package/dist/core/tools/operations.d.ts +212 -0
  521. package/dist/core/tools/operations.d.ts.map +1 -0
  522. package/dist/core/tools/operations.js +793 -0
  523. package/dist/core/tools/operations.js.map +1 -0
  524. package/dist/core/tools/output-accumulator.d.ts +54 -0
  525. package/dist/core/tools/output-accumulator.d.ts.map +1 -0
  526. package/dist/core/tools/output-accumulator.js +184 -0
  527. package/dist/core/tools/output-accumulator.js.map +1 -0
  528. package/dist/core/tools/path-utils.d.ts +9 -0
  529. package/dist/core/tools/path-utils.d.ts.map +1 -0
  530. package/dist/core/tools/path-utils.js +99 -0
  531. package/dist/core/tools/path-utils.js.map +1 -0
  532. package/dist/core/tools/read.d.ts +32 -0
  533. package/dist/core/tools/read.d.ts.map +1 -0
  534. package/dist/core/tools/read.js +318 -0
  535. package/dist/core/tools/read.js.map +1 -0
  536. package/dist/core/tools/render-utils.d.ts +33 -0
  537. package/dist/core/tools/render-utils.d.ts.map +1 -0
  538. package/dist/core/tools/render-utils.js +61 -0
  539. package/dist/core/tools/render-utils.js.map +1 -0
  540. package/dist/core/tools/replace-diff.d.ts +16 -0
  541. package/dist/core/tools/replace-diff.d.ts.map +1 -0
  542. package/dist/core/tools/replace-diff.js +117 -0
  543. package/dist/core/tools/replace-diff.js.map +1 -0
  544. package/dist/core/tools/replace-normalize.d.ts +2 -0
  545. package/dist/core/tools/replace-normalize.d.ts.map +1 -0
  546. package/dist/core/tools/replace-normalize.js +73 -0
  547. package/dist/core/tools/replace-normalize.js.map +1 -0
  548. package/dist/core/tools/replace-render.d.ts +51 -0
  549. package/dist/core/tools/replace-render.d.ts.map +1 -0
  550. package/dist/core/tools/replace-render.js +162 -0
  551. package/dist/core/tools/replace-render.js.map +1 -0
  552. package/dist/core/tools/runtime.d.ts +2 -0
  553. package/dist/core/tools/runtime.d.ts.map +1 -0
  554. package/dist/core/tools/runtime.js +6 -0
  555. package/dist/core/tools/runtime.js.map +1 -0
  556. package/dist/core/tools/session-history.d.ts +55 -0
  557. package/dist/core/tools/session-history.d.ts.map +1 -0
  558. package/dist/core/tools/session-history.js +649 -0
  559. package/dist/core/tools/session-history.js.map +1 -0
  560. package/dist/core/tools/subagent-agents.d.ts +29 -0
  561. package/dist/core/tools/subagent-agents.d.ts.map +1 -0
  562. package/dist/core/tools/subagent-agents.js +223 -0
  563. package/dist/core/tools/subagent-agents.js.map +1 -0
  564. package/dist/core/tools/subagent.d.ts +185 -0
  565. package/dist/core/tools/subagent.d.ts.map +1 -0
  566. package/dist/core/tools/subagent.js +1309 -0
  567. package/dist/core/tools/subagent.js.map +1 -0
  568. package/dist/core/tools/tool-definition-wrapper.d.ts +14 -0
  569. package/dist/core/tools/tool-definition-wrapper.d.ts.map +1 -0
  570. package/dist/core/tools/tool-definition-wrapper.js +34 -0
  571. package/dist/core/tools/tool-definition-wrapper.js.map +1 -0
  572. package/dist/core/tools/truncate.d.ts +39 -0
  573. package/dist/core/tools/truncate.d.ts.map +1 -0
  574. package/dist/core/tools/truncate.js +215 -0
  575. package/dist/core/tools/truncate.js.map +1 -0
  576. package/dist/core/tools/websearch.d.ts +33 -0
  577. package/dist/core/tools/websearch.d.ts.map +1 -0
  578. package/dist/core/tools/websearch.js +341 -0
  579. package/dist/core/tools/websearch.js.map +1 -0
  580. package/dist/core/tools/workspace-tool-host.d.ts +102 -0
  581. package/dist/core/tools/workspace-tool-host.d.ts.map +1 -0
  582. package/dist/core/tools/workspace-tool-host.js +348 -0
  583. package/dist/core/tools/workspace-tool-host.js.map +1 -0
  584. package/dist/core/tools/write.d.ts +16 -0
  585. package/dist/core/tools/write.d.ts.map +1 -0
  586. package/dist/core/tools/write.js +204 -0
  587. package/dist/core/tools/write.js.map +1 -0
  588. package/dist/core/workspace-identity.d.ts +7 -0
  589. package/dist/core/workspace-identity.d.ts.map +1 -0
  590. package/dist/core/workspace-identity.js +2 -0
  591. package/dist/core/workspace-identity.js.map +1 -0
  592. package/dist/daemon/activity-budget.d.ts +10 -0
  593. package/dist/daemon/activity-budget.d.ts.map +1 -0
  594. package/dist/daemon/activity-budget.js +34 -0
  595. package/dist/daemon/activity-budget.js.map +1 -0
  596. package/dist/daemon/command.d.ts +6 -0
  597. package/dist/daemon/command.d.ts.map +1 -0
  598. package/dist/daemon/command.js +58 -0
  599. package/dist/daemon/command.js.map +1 -0
  600. package/dist/daemon/config.d.ts +45 -0
  601. package/dist/daemon/config.d.ts.map +1 -0
  602. package/dist/daemon/config.js +319 -0
  603. package/dist/daemon/config.js.map +1 -0
  604. package/dist/daemon/help.d.ts +2 -0
  605. package/dist/daemon/help.d.ts.map +1 -0
  606. package/dist/daemon/help.js +42 -0
  607. package/dist/daemon/help.js.map +1 -0
  608. package/dist/daemon/lsp-config.d.ts +4 -0
  609. package/dist/daemon/lsp-config.d.ts.map +1 -0
  610. package/dist/daemon/lsp-config.js +155 -0
  611. package/dist/daemon/lsp-config.js.map +1 -0
  612. package/dist/daemon/outbound-budget.d.ts +10 -0
  613. package/dist/daemon/outbound-budget.d.ts.map +1 -0
  614. package/dist/daemon/outbound-budget.js +30 -0
  615. package/dist/daemon/outbound-budget.js.map +1 -0
  616. package/dist/daemon/security.d.ts +19 -0
  617. package/dist/daemon/security.d.ts.map +1 -0
  618. package/dist/daemon/security.js +177 -0
  619. package/dist/daemon/security.js.map +1 -0
  620. package/dist/daemon/server.d.ts +20 -0
  621. package/dist/daemon/server.d.ts.map +1 -0
  622. package/dist/daemon/server.js +480 -0
  623. package/dist/daemon/server.js.map +1 -0
  624. package/dist/daemon/shared-connection.d.ts +33 -0
  625. package/dist/daemon/shared-connection.d.ts.map +1 -0
  626. package/dist/daemon/shared-connection.js +271 -0
  627. package/dist/daemon/shared-connection.js.map +1 -0
  628. package/dist/daemon/shared-revision.d.ts +5 -0
  629. package/dist/daemon/shared-revision.d.ts.map +1 -0
  630. package/dist/daemon/shared-revision.js +61 -0
  631. package/dist/daemon/shared-revision.js.map +1 -0
  632. package/dist/daemon/shared-roots.d.ts +9 -0
  633. package/dist/daemon/shared-roots.d.ts.map +1 -0
  634. package/dist/daemon/shared-roots.js +33 -0
  635. package/dist/daemon/shared-roots.js.map +1 -0
  636. package/dist/daemon/workspace-runtime.d.ts +46 -0
  637. package/dist/daemon/workspace-runtime.d.ts.map +1 -0
  638. package/dist/daemon/workspace-runtime.js +705 -0
  639. package/dist/daemon/workspace-runtime.js.map +1 -0
  640. package/dist/index.d.ts +109 -0
  641. package/dist/index.d.ts.map +1 -0
  642. package/dist/index.js +107 -0
  643. package/dist/index.js.map +1 -0
  644. package/dist/main.d.ts +39 -0
  645. package/dist/main.d.ts.map +1 -0
  646. package/dist/main.js +765 -0
  647. package/dist/main.js.map +1 -0
  648. package/dist/migrations.d.ts +35 -0
  649. package/dist/migrations.d.ts.map +1 -0
  650. package/dist/migrations.js +412 -0
  651. package/dist/migrations.js.map +1 -0
  652. package/dist/modes/interactive/components/assistant-message.d.ts +30 -0
  653. package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -0
  654. package/dist/modes/interactive/components/assistant-message.js +159 -0
  655. package/dist/modes/interactive/components/assistant-message.js.map +1 -0
  656. package/dist/modes/interactive/components/bash-execution.d.ts +36 -0
  657. package/dist/modes/interactive/components/bash-execution.d.ts.map +1 -0
  658. package/dist/modes/interactive/components/bash-execution.js +173 -0
  659. package/dist/modes/interactive/components/bash-execution.js.map +1 -0
  660. package/dist/modes/interactive/components/bordered-loader.d.ts +18 -0
  661. package/dist/modes/interactive/components/bordered-loader.d.ts.map +1 -0
  662. package/dist/modes/interactive/components/bordered-loader.js +54 -0
  663. package/dist/modes/interactive/components/bordered-loader.js.map +1 -0
  664. package/dist/modes/interactive/components/branch-summary-message.d.ts +17 -0
  665. package/dist/modes/interactive/components/branch-summary-message.d.ts.map +1 -0
  666. package/dist/modes/interactive/components/branch-summary-message.js +45 -0
  667. package/dist/modes/interactive/components/branch-summary-message.js.map +1 -0
  668. package/dist/modes/interactive/components/compaction-summary-message.d.ts +17 -0
  669. package/dist/modes/interactive/components/compaction-summary-message.d.ts.map +1 -0
  670. package/dist/modes/interactive/components/compaction-summary-message.js +46 -0
  671. package/dist/modes/interactive/components/compaction-summary-message.js.map +1 -0
  672. package/dist/modes/interactive/components/config-selector.d.ts +74 -0
  673. package/dist/modes/interactive/components/config-selector.d.ts.map +1 -0
  674. package/dist/modes/interactive/components/config-selector.js +514 -0
  675. package/dist/modes/interactive/components/config-selector.js.map +1 -0
  676. package/dist/modes/interactive/components/countdown-timer.d.ts +14 -0
  677. package/dist/modes/interactive/components/countdown-timer.d.ts.map +1 -0
  678. package/dist/modes/interactive/components/countdown-timer.js +33 -0
  679. package/dist/modes/interactive/components/countdown-timer.js.map +1 -0
  680. package/dist/modes/interactive/components/custom-editor.d.ts +25 -0
  681. package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -0
  682. package/dist/modes/interactive/components/custom-editor.js +85 -0
  683. package/dist/modes/interactive/components/custom-editor.js.map +1 -0
  684. package/dist/modes/interactive/components/custom-message.d.ts +20 -0
  685. package/dist/modes/interactive/components/custom-message.d.ts.map +1 -0
  686. package/dist/modes/interactive/components/custom-message.js +81 -0
  687. package/dist/modes/interactive/components/custom-message.js.map +1 -0
  688. package/dist/modes/interactive/components/diff.d.ts +12 -0
  689. package/dist/modes/interactive/components/diff.d.ts.map +1 -0
  690. package/dist/modes/interactive/components/diff.js +118 -0
  691. package/dist/modes/interactive/components/diff.js.map +1 -0
  692. package/dist/modes/interactive/components/dynamic-border.d.ts +15 -0
  693. package/dist/modes/interactive/components/dynamic-border.d.ts.map +1 -0
  694. package/dist/modes/interactive/components/dynamic-border.js +21 -0
  695. package/dist/modes/interactive/components/dynamic-border.js.map +1 -0
  696. package/dist/modes/interactive/components/extension-editor.d.ts +22 -0
  697. package/dist/modes/interactive/components/extension-editor.d.ts.map +1 -0
  698. package/dist/modes/interactive/components/extension-editor.js +128 -0
  699. package/dist/modes/interactive/components/extension-editor.js.map +1 -0
  700. package/dist/modes/interactive/components/extension-input.d.ts +23 -0
  701. package/dist/modes/interactive/components/extension-input.d.ts.map +1 -0
  702. package/dist/modes/interactive/components/extension-input.js +61 -0
  703. package/dist/modes/interactive/components/extension-input.js.map +1 -0
  704. package/dist/modes/interactive/components/extension-selector.d.ts +26 -0
  705. package/dist/modes/interactive/components/extension-selector.d.ts.map +1 -0
  706. package/dist/modes/interactive/components/extension-selector.js +83 -0
  707. package/dist/modes/interactive/components/extension-selector.js.map +1 -0
  708. package/dist/modes/interactive/components/footer.d.ts +36 -0
  709. package/dist/modes/interactive/components/footer.d.ts.map +1 -0
  710. package/dist/modes/interactive/components/footer.js +227 -0
  711. package/dist/modes/interactive/components/footer.js.map +1 -0
  712. package/dist/modes/interactive/components/hook-execution.d.ts +19 -0
  713. package/dist/modes/interactive/components/hook-execution.d.ts.map +1 -0
  714. package/dist/modes/interactive/components/hook-execution.js +185 -0
  715. package/dist/modes/interactive/components/hook-execution.js.map +1 -0
  716. package/dist/modes/interactive/components/keybinding-hints.d.ts +13 -0
  717. package/dist/modes/interactive/components/keybinding-hints.d.ts.map +1 -0
  718. package/dist/modes/interactive/components/keybinding-hints.js +36 -0
  719. package/dist/modes/interactive/components/keybinding-hints.js.map +1 -0
  720. package/dist/modes/interactive/components/login-dialog.d.ts +55 -0
  721. package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -0
  722. package/dist/modes/interactive/components/login-dialog.js +176 -0
  723. package/dist/modes/interactive/components/login-dialog.js.map +1 -0
  724. package/dist/modes/interactive/components/markdown-transform.d.ts +4 -0
  725. package/dist/modes/interactive/components/markdown-transform.d.ts.map +1 -0
  726. package/dist/modes/interactive/components/markdown-transform.js +19 -0
  727. package/dist/modes/interactive/components/markdown-transform.js.map +1 -0
  728. package/dist/modes/interactive/components/mermaid.d.ts +14 -0
  729. package/dist/modes/interactive/components/mermaid.d.ts.map +1 -0
  730. package/dist/modes/interactive/components/mermaid.js +228 -0
  731. package/dist/modes/interactive/components/mermaid.js.map +1 -0
  732. package/dist/modes/interactive/components/message-card.d.ts +9 -0
  733. package/dist/modes/interactive/components/message-card.d.ts.map +1 -0
  734. package/dist/modes/interactive/components/message-card.js +24 -0
  735. package/dist/modes/interactive/components/message-card.js.map +1 -0
  736. package/dist/modes/interactive/components/model-selector.d.ts +52 -0
  737. package/dist/modes/interactive/components/model-selector.d.ts.map +1 -0
  738. package/dist/modes/interactive/components/model-selector.js +296 -0
  739. package/dist/modes/interactive/components/model-selector.js.map +1 -0
  740. package/dist/modes/interactive/components/oauth-selector.d.ts +33 -0
  741. package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -0
  742. package/dist/modes/interactive/components/oauth-selector.js +165 -0
  743. package/dist/modes/interactive/components/oauth-selector.js.map +1 -0
  744. package/dist/modes/interactive/components/scoped-models-selector.d.ts +50 -0
  745. package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -0
  746. package/dist/modes/interactive/components/scoped-models-selector.js +300 -0
  747. package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -0
  748. package/dist/modes/interactive/components/session-selector-search.d.ts +22 -0
  749. package/dist/modes/interactive/components/session-selector-search.d.ts.map +1 -0
  750. package/dist/modes/interactive/components/session-selector-search.js +144 -0
  751. package/dist/modes/interactive/components/session-selector-search.js.map +1 -0
  752. package/dist/modes/interactive/components/session-selector.d.ts +108 -0
  753. package/dist/modes/interactive/components/session-selector.d.ts.map +1 -0
  754. package/dist/modes/interactive/components/session-selector.js +835 -0
  755. package/dist/modes/interactive/components/session-selector.js.map +1 -0
  756. package/dist/modes/interactive/components/settings-selector.d.ts +81 -0
  757. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -0
  758. package/dist/modes/interactive/components/settings-selector.js +455 -0
  759. package/dist/modes/interactive/components/settings-selector.js.map +1 -0
  760. package/dist/modes/interactive/components/show-images-selector.d.ts +10 -0
  761. package/dist/modes/interactive/components/show-images-selector.d.ts.map +1 -0
  762. package/dist/modes/interactive/components/show-images-selector.js +39 -0
  763. package/dist/modes/interactive/components/show-images-selector.js.map +1 -0
  764. package/dist/modes/interactive/components/skill-invocation-message.d.ts +18 -0
  765. package/dist/modes/interactive/components/skill-invocation-message.d.ts.map +1 -0
  766. package/dist/modes/interactive/components/skill-invocation-message.js +48 -0
  767. package/dist/modes/interactive/components/skill-invocation-message.js.map +1 -0
  768. package/dist/modes/interactive/components/theme-selector.d.ts +11 -0
  769. package/dist/modes/interactive/components/theme-selector.d.ts.map +1 -0
  770. package/dist/modes/interactive/components/theme-selector.js +50 -0
  771. package/dist/modes/interactive/components/theme-selector.js.map +1 -0
  772. package/dist/modes/interactive/components/thinking-selector.d.ts +11 -0
  773. package/dist/modes/interactive/components/thinking-selector.d.ts.map +1 -0
  774. package/dist/modes/interactive/components/thinking-selector.js +51 -0
  775. package/dist/modes/interactive/components/thinking-selector.js.map +1 -0
  776. package/dist/modes/interactive/components/tool-execution.d.ts +67 -0
  777. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -0
  778. package/dist/modes/interactive/components/tool-execution.js +312 -0
  779. package/dist/modes/interactive/components/tool-execution.js.map +1 -0
  780. package/dist/modes/interactive/components/tree-selector.d.ts +127 -0
  781. package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -0
  782. package/dist/modes/interactive/components/tree-selector.js +1098 -0
  783. package/dist/modes/interactive/components/tree-selector.js.map +1 -0
  784. package/dist/modes/interactive/components/user-message-selector.d.ts +30 -0
  785. package/dist/modes/interactive/components/user-message-selector.d.ts.map +1 -0
  786. package/dist/modes/interactive/components/user-message-selector.js +114 -0
  787. package/dist/modes/interactive/components/user-message-selector.js.map +1 -0
  788. package/dist/modes/interactive/components/user-message.d.ts +16 -0
  789. package/dist/modes/interactive/components/user-message.d.ts.map +1 -0
  790. package/dist/modes/interactive/components/user-message.js +50 -0
  791. package/dist/modes/interactive/components/user-message.js.map +1 -0
  792. package/dist/modes/interactive/components/visual-truncate.d.ts +24 -0
  793. package/dist/modes/interactive/components/visual-truncate.d.ts.map +1 -0
  794. package/dist/modes/interactive/components/visual-truncate.js +33 -0
  795. package/dist/modes/interactive/components/visual-truncate.js.map +1 -0
  796. package/dist/modes/interactive/interactive-mode.d.ts +554 -0
  797. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -0
  798. package/dist/modes/interactive/interactive-mode.js +5870 -0
  799. package/dist/modes/interactive/interactive-mode.js.map +1 -0
  800. package/dist/modes/interactive/theme/dark.json +86 -0
  801. package/dist/modes/interactive/theme/light.json +85 -0
  802. package/dist/modes/interactive/theme/theme-schema.json +335 -0
  803. package/dist/modes/interactive/theme/theme.d.ts +109 -0
  804. package/dist/modes/interactive/theme/theme.d.ts.map +1 -0
  805. package/dist/modes/interactive/theme/theme.js +1040 -0
  806. package/dist/modes/interactive/theme/theme.js.map +1 -0
  807. package/dist/modes/json-event.d.ts +28 -0
  808. package/dist/modes/json-event.d.ts.map +1 -0
  809. package/dist/modes/json-event.js +12 -0
  810. package/dist/modes/json-event.js.map +1 -0
  811. package/dist/modes/print-mode.d.ts +29 -0
  812. package/dist/modes/print-mode.d.ts.map +1 -0
  813. package/dist/modes/print-mode.js +142 -0
  814. package/dist/modes/print-mode.js.map +1 -0
  815. package/dist/modes/rpc/jsonl.d.ts +17 -0
  816. package/dist/modes/rpc/jsonl.d.ts.map +1 -0
  817. package/dist/modes/rpc/jsonl.js +49 -0
  818. package/dist/modes/rpc/jsonl.js.map +1 -0
  819. package/dist/modes/rpc/rpc-client.d.ts +321 -0
  820. package/dist/modes/rpc/rpc-client.d.ts.map +1 -0
  821. package/dist/modes/rpc/rpc-client.js +755 -0
  822. package/dist/modes/rpc/rpc-client.js.map +1 -0
  823. package/dist/modes/rpc/rpc-mode.d.ts +20 -0
  824. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -0
  825. package/dist/modes/rpc/rpc-mode.js +963 -0
  826. package/dist/modes/rpc/rpc-mode.js.map +1 -0
  827. package/dist/modes/rpc/rpc-types.d.ts +652 -0
  828. package/dist/modes/rpc/rpc-types.d.ts.map +1 -0
  829. package/dist/modes/rpc/rpc-types.js +8 -0
  830. package/dist/modes/rpc/rpc-types.js.map +1 -0
  831. package/dist/package-manager-cli.d.ts +4 -0
  832. package/dist/package-manager-cli.d.ts.map +1 -0
  833. package/dist/package-manager-cli.js +488 -0
  834. package/dist/package-manager-cli.js.map +1 -0
  835. package/dist/utils/ansi.d.ts +2 -0
  836. package/dist/utils/ansi.d.ts.map +1 -0
  837. package/dist/utils/ansi.js +25 -0
  838. package/dist/utils/ansi.js.map +1 -0
  839. package/dist/utils/changelog.d.ts +23 -0
  840. package/dist/utils/changelog.d.ts.map +1 -0
  841. package/dist/utils/changelog.js +74 -0
  842. package/dist/utils/changelog.js.map +1 -0
  843. package/dist/utils/child-process.d.ts +15 -0
  844. package/dist/utils/child-process.d.ts.map +1 -0
  845. package/dist/utils/child-process.js +88 -0
  846. package/dist/utils/child-process.js.map +1 -0
  847. package/dist/utils/clipboard-image.d.ts +13 -0
  848. package/dist/utils/clipboard-image.d.ts.map +1 -0
  849. package/dist/utils/clipboard-image.js +248 -0
  850. package/dist/utils/clipboard-image.js.map +1 -0
  851. package/dist/utils/clipboard-native.d.ts +11 -0
  852. package/dist/utils/clipboard-native.d.ts.map +1 -0
  853. package/dist/utils/clipboard-native.js +20 -0
  854. package/dist/utils/clipboard-native.js.map +1 -0
  855. package/dist/utils/clipboard.d.ts +4 -0
  856. package/dist/utils/clipboard.d.ts.map +1 -0
  857. package/dist/utils/clipboard.js +171 -0
  858. package/dist/utils/clipboard.js.map +1 -0
  859. package/dist/utils/deprecation.d.ts +4 -0
  860. package/dist/utils/deprecation.d.ts.map +1 -0
  861. package/dist/utils/deprecation.js +13 -0
  862. package/dist/utils/deprecation.js.map +1 -0
  863. package/dist/utils/directory-completions.d.ts +5 -0
  864. package/dist/utils/directory-completions.d.ts.map +1 -0
  865. package/dist/utils/directory-completions.js +64 -0
  866. package/dist/utils/directory-completions.js.map +1 -0
  867. package/dist/utils/exif-orientation.d.ts +6 -0
  868. package/dist/utils/exif-orientation.d.ts.map +1 -0
  869. package/dist/utils/exif-orientation.js +166 -0
  870. package/dist/utils/exif-orientation.js.map +1 -0
  871. package/dist/utils/frontmatter.d.ts +8 -0
  872. package/dist/utils/frontmatter.d.ts.map +1 -0
  873. package/dist/utils/frontmatter.js +26 -0
  874. package/dist/utils/frontmatter.js.map +1 -0
  875. package/dist/utils/fs-watch.d.ts +5 -0
  876. package/dist/utils/fs-watch.d.ts.map +1 -0
  877. package/dist/utils/fs-watch.js +25 -0
  878. package/dist/utils/fs-watch.js.map +1 -0
  879. package/dist/utils/git.d.ts +27 -0
  880. package/dist/utils/git.d.ts.map +1 -0
  881. package/dist/utils/git.js +237 -0
  882. package/dist/utils/git.js.map +1 -0
  883. package/dist/utils/grip-user-agent.d.ts +2 -0
  884. package/dist/utils/grip-user-agent.d.ts.map +1 -0
  885. package/dist/utils/grip-user-agent.js +5 -0
  886. package/dist/utils/grip-user-agent.js.map +1 -0
  887. package/dist/utils/html.d.ts +7 -0
  888. package/dist/utils/html.d.ts.map +1 -0
  889. package/dist/utils/html.js +40 -0
  890. package/dist/utils/html.js.map +1 -0
  891. package/dist/utils/image-convert.d.ts +12 -0
  892. package/dist/utils/image-convert.d.ts.map +1 -0
  893. package/dist/utils/image-convert.js +43 -0
  894. package/dist/utils/image-convert.js.map +1 -0
  895. package/dist/utils/image-process.d.ts +18 -0
  896. package/dist/utils/image-process.d.ts.map +1 -0
  897. package/dist/utils/image-process.js +83 -0
  898. package/dist/utils/image-process.js.map +1 -0
  899. package/dist/utils/image-resize-core.d.ts +30 -0
  900. package/dist/utils/image-resize-core.d.ts.map +1 -0
  901. package/dist/utils/image-resize-core.js +133 -0
  902. package/dist/utils/image-resize-core.js.map +1 -0
  903. package/dist/utils/image-resize-worker.d.ts +2 -0
  904. package/dist/utils/image-resize-worker.d.ts.map +1 -0
  905. package/dist/utils/image-resize-worker.js +31 -0
  906. package/dist/utils/image-resize-worker.js.map +1 -0
  907. package/dist/utils/image-resize.d.ts +19 -0
  908. package/dist/utils/image-resize.d.ts.map +1 -0
  909. package/dist/utils/image-resize.js +86 -0
  910. package/dist/utils/image-resize.js.map +1 -0
  911. package/dist/utils/json.d.ts +3 -0
  912. package/dist/utils/json.d.ts.map +1 -0
  913. package/dist/utils/json.js +7 -0
  914. package/dist/utils/json.js.map +1 -0
  915. package/dist/utils/mime.d.ts +3 -0
  916. package/dist/utils/mime.d.ts.map +1 -0
  917. package/dist/utils/mime.js +110 -0
  918. package/dist/utils/mime.js.map +1 -0
  919. package/dist/utils/open-browser.d.ts +9 -0
  920. package/dist/utils/open-browser.d.ts.map +1 -0
  921. package/dist/utils/open-browser.js +22 -0
  922. package/dist/utils/open-browser.js.map +1 -0
  923. package/dist/utils/paths.d.ts +31 -0
  924. package/dist/utils/paths.d.ts.map +1 -0
  925. package/dist/utils/paths.js +87 -0
  926. package/dist/utils/paths.js.map +1 -0
  927. package/dist/utils/photon.d.ts +22 -0
  928. package/dist/utils/photon.d.ts.map +1 -0
  929. package/dist/utils/photon.js +126 -0
  930. package/dist/utils/photon.js.map +1 -0
  931. package/dist/utils/shell.d.ts +28 -0
  932. package/dist/utils/shell.d.ts.map +1 -0
  933. package/dist/utils/shell.js +188 -0
  934. package/dist/utils/shell.js.map +1 -0
  935. package/dist/utils/sleep.d.ts +5 -0
  936. package/dist/utils/sleep.d.ts.map +1 -0
  937. package/dist/utils/sleep.js +17 -0
  938. package/dist/utils/sleep.js.map +1 -0
  939. package/dist/utils/syntax-highlight.d.ts +12 -0
  940. package/dist/utils/syntax-highlight.d.ts.map +1 -0
  941. package/dist/utils/syntax-highlight.js +125 -0
  942. package/dist/utils/syntax-highlight.js.map +1 -0
  943. package/dist/utils/tools-manager.d.ts +5 -0
  944. package/dist/utils/tools-manager.d.ts.map +1 -0
  945. package/dist/utils/tools-manager.js +329 -0
  946. package/dist/utils/tools-manager.js.map +1 -0
  947. package/dist/utils/version-check.d.ts +14 -0
  948. package/dist/utils/version-check.d.ts.map +1 -0
  949. package/dist/utils/version-check.js +91 -0
  950. package/dist/utils/version-check.js.map +1 -0
  951. package/dist/utils/windows-self-update.d.ts +3 -0
  952. package/dist/utils/windows-self-update.d.ts.map +1 -0
  953. package/dist/utils/windows-self-update.js +77 -0
  954. package/dist/utils/windows-self-update.js.map +1 -0
  955. package/docs/compaction.md +408 -0
  956. package/docs/custom-provider.md +714 -0
  957. package/docs/daemon-architecture.md +399 -0
  958. package/docs/daemon.md +112 -0
  959. package/docs/development.md +72 -0
  960. package/docs/docs.json +164 -0
  961. package/docs/extensions.md +2745 -0
  962. package/docs/hooks.md +85 -0
  963. package/docs/images/doom-extension.png +0 -0
  964. package/docs/images/exy.png +0 -0
  965. package/docs/images/interactive-mode.png +0 -0
  966. package/docs/images/tree-view.png +0 -0
  967. package/docs/index.md +77 -0
  968. package/docs/json.md +89 -0
  969. package/docs/keybindings.md +230 -0
  970. package/docs/lsp.md +499 -0
  971. package/docs/migrating-to-grip.md +18 -0
  972. package/docs/models.md +496 -0
  973. package/docs/packages.md +228 -0
  974. package/docs/prompt-templates.md +88 -0
  975. package/docs/providers.md +251 -0
  976. package/docs/quickstart.md +159 -0
  977. package/docs/rpc.md +1492 -0
  978. package/docs/rules.md +117 -0
  979. package/docs/sandbox.md +104 -0
  980. package/docs/sdk.md +360 -0
  981. package/docs/session-format.md +414 -0
  982. package/docs/sessions.md +137 -0
  983. package/docs/settings.md +372 -0
  984. package/docs/shell-aliases.md +13 -0
  985. package/docs/skills.md +246 -0
  986. package/docs/terminal-setup.md +112 -0
  987. package/docs/termux.md +112 -0
  988. package/docs/themes.md +295 -0
  989. package/docs/tmux.md +61 -0
  990. package/docs/tui.md +918 -0
  991. package/docs/usage.md +304 -0
  992. package/docs/windows.md +17 -0
  993. package/examples/README.md +29 -0
  994. package/examples/daemon-docker/Dockerfile +43 -0
  995. package/examples/daemon-docker/README.md +45 -0
  996. package/examples/extensions/README.md +208 -0
  997. package/examples/extensions/auto-commit-on-exit.ts +46 -0
  998. package/examples/extensions/bash-spawn-hook.ts +30 -0
  999. package/examples/extensions/bookmark.ts +50 -0
  1000. package/examples/extensions/border-status-editor.ts +145 -0
  1001. package/examples/extensions/built-in-tool-renderer.ts +259 -0
  1002. package/examples/extensions/claude-rules.ts +86 -0
  1003. package/examples/extensions/commands.ts +82 -0
  1004. package/examples/extensions/confirm-destructive.ts +59 -0
  1005. package/examples/extensions/custom-compaction.ts +131 -0
  1006. package/examples/extensions/custom-footer.ts +79 -0
  1007. package/examples/extensions/custom-header.ts +73 -0
  1008. package/examples/extensions/custom-provider-anthropic/index.ts +707 -0
  1009. package/examples/extensions/custom-provider-anthropic/package-lock.json +24 -0
  1010. package/examples/extensions/custom-provider-anthropic/package.json +19 -0
  1011. package/examples/extensions/custom-provider-gitlab-duo/index.ts +402 -0
  1012. package/examples/extensions/custom-provider-gitlab-duo/package.json +16 -0
  1013. package/examples/extensions/custom-provider-gitlab-duo/test.ts +104 -0
  1014. package/examples/extensions/dirty-repo-guard.ts +59 -0
  1015. package/examples/extensions/doom-overlay/README.md +46 -0
  1016. package/examples/extensions/doom-overlay/doom/build/doom.js +21 -0
  1017. package/examples/extensions/doom-overlay/doom/build/doom.wasm +0 -0
  1018. package/examples/extensions/doom-overlay/doom/build.sh +152 -0
  1019. package/examples/extensions/doom-overlay/doom/doomgeneric_pi.c +72 -0
  1020. package/examples/extensions/doom-overlay/doom-component.ts +133 -0
  1021. package/examples/extensions/doom-overlay/doom-engine.ts +173 -0
  1022. package/examples/extensions/doom-overlay/doom-keys.ts +104 -0
  1023. package/examples/extensions/doom-overlay/index.ts +74 -0
  1024. package/examples/extensions/doom-overlay/wad-finder.ts +51 -0
  1025. package/examples/extensions/dynamic-resources/RULES.md +8 -0
  1026. package/examples/extensions/dynamic-resources/SKILL.md +8 -0
  1027. package/examples/extensions/dynamic-resources/dynamic.json +79 -0
  1028. package/examples/extensions/dynamic-resources/dynamic.md +5 -0
  1029. package/examples/extensions/dynamic-resources/index.ts +16 -0
  1030. package/examples/extensions/dynamic-tools.ts +74 -0
  1031. package/examples/extensions/event-bus.ts +43 -0
  1032. package/examples/extensions/file-trigger.ts +41 -0
  1033. package/examples/extensions/git-checkpoint.ts +53 -0
  1034. package/examples/extensions/git-merge-and-resolve.ts +125 -0
  1035. package/examples/extensions/github-issue-autocomplete.ts +191 -0
  1036. package/examples/extensions/handoff.ts +191 -0
  1037. package/examples/extensions/hello.ts +26 -0
  1038. package/examples/extensions/hidden-thinking-label.ts +53 -0
  1039. package/examples/extensions/inline-bash.ts +104 -0
  1040. package/examples/extensions/input-transform.ts +43 -0
  1041. package/examples/extensions/interactive-shell.ts +194 -0
  1042. package/examples/extensions/mac-system-theme.ts +47 -0
  1043. package/examples/extensions/message-renderer.ts +59 -0
  1044. package/examples/extensions/minimal-mode.ts +428 -0
  1045. package/examples/extensions/modal-editor.ts +86 -0
  1046. package/examples/extensions/model-status.ts +31 -0
  1047. package/examples/extensions/notify.ts +55 -0
  1048. package/examples/extensions/overlay-qa-tests.ts +1374 -0
  1049. package/examples/extensions/overlay-test.ts +171 -0
  1050. package/examples/extensions/permission-gate.ts +34 -0
  1051. package/examples/extensions/pirate.ts +47 -0
  1052. package/examples/extensions/plan-mode/README.md +65 -0
  1053. package/examples/extensions/plan-mode/index.ts +346 -0
  1054. package/examples/extensions/plan-mode/utils.ts +172 -0
  1055. package/examples/extensions/preset.ts +426 -0
  1056. package/examples/extensions/prompt-customizer.ts +97 -0
  1057. package/examples/extensions/protected-paths.ts +29 -0
  1058. package/examples/extensions/provider-payload.ts +18 -0
  1059. package/examples/extensions/qna.ts +125 -0
  1060. package/examples/extensions/question.ts +294 -0
  1061. package/examples/extensions/questionnaire.ts +459 -0
  1062. package/examples/extensions/rainbow-editor.ts +88 -0
  1063. package/examples/extensions/reload-runtime.ts +37 -0
  1064. package/examples/extensions/rpc-demo.ts +118 -0
  1065. package/examples/extensions/sandbox/index.ts +320 -0
  1066. package/examples/extensions/sandbox/package-lock.json +92 -0
  1067. package/examples/extensions/sandbox/package.json +19 -0
  1068. package/examples/extensions/send-user-message.ts +97 -0
  1069. package/examples/extensions/session-name.ts +27 -0
  1070. package/examples/extensions/shutdown-command.ts +63 -0
  1071. package/examples/extensions/snake.ts +381 -0
  1072. package/examples/extensions/space-invaders.ts +597 -0
  1073. package/examples/extensions/status-line.ts +32 -0
  1074. package/examples/extensions/structured-output.ts +65 -0
  1075. package/examples/extensions/subagent/README.md +175 -0
  1076. package/examples/extensions/subagent/agents/planner.md +37 -0
  1077. package/examples/extensions/subagent/agents/reviewer.md +35 -0
  1078. package/examples/extensions/subagent/agents/scout.md +50 -0
  1079. package/examples/extensions/subagent/agents/worker.md +24 -0
  1080. package/examples/extensions/subagent/agents.ts +126 -0
  1081. package/examples/extensions/subagent/index.ts +1083 -0
  1082. package/examples/extensions/subagent/prompts/implement-and-review.md +10 -0
  1083. package/examples/extensions/subagent/prompts/implement.md +10 -0
  1084. package/examples/extensions/subagent/prompts/scout-and-plan.md +9 -0
  1085. package/examples/extensions/summarize.ts +186 -0
  1086. package/examples/extensions/system-prompt-header.ts +17 -0
  1087. package/examples/extensions/tic-tac-toe.ts +1091 -0
  1088. package/examples/extensions/timed-confirm.ts +70 -0
  1089. package/examples/extensions/titlebar-spinner.ts +58 -0
  1090. package/examples/extensions/todo.ts +306 -0
  1091. package/examples/extensions/tool-override.ts +144 -0
  1092. package/examples/extensions/tools.ts +141 -0
  1093. package/examples/extensions/trigger-compact.ts +50 -0
  1094. package/examples/extensions/truncated-tool.ts +200 -0
  1095. package/examples/extensions/widget-placement.ts +9 -0
  1096. package/examples/extensions/with-deps/index.ts +32 -0
  1097. package/examples/extensions/with-deps/package-lock.json +31 -0
  1098. package/examples/extensions/with-deps/package.json +22 -0
  1099. package/examples/extensions/working-indicator.ts +123 -0
  1100. package/examples/extensions/working-message-test.ts +25 -0
  1101. package/examples/remote-session-server/README.md +71 -0
  1102. package/examples/remote-session-server/server.ts +353 -0
  1103. package/examples/rpc-extension-ui.ts +642 -0
  1104. package/examples/sdk/01-minimal.ts +27 -0
  1105. package/examples/sdk/02-custom-model.ts +54 -0
  1106. package/examples/sdk/03-custom-prompt.ts +76 -0
  1107. package/examples/sdk/04-skills.ts +60 -0
  1108. package/examples/sdk/05-tools.ts +55 -0
  1109. package/examples/sdk/06-extensions.ts +94 -0
  1110. package/examples/sdk/07-context-files.ts +47 -0
  1111. package/examples/sdk/08-prompt-templates.ts +56 -0
  1112. package/examples/sdk/09-api-keys-and-oauth.ts +50 -0
  1113. package/examples/sdk/10-settings.ts +58 -0
  1114. package/examples/sdk/11-sessions.ts +54 -0
  1115. package/examples/sdk/12-full-control.ts +79 -0
  1116. package/examples/sdk/13-session-runtime.ts +49 -0
  1117. package/examples/sdk/README.md +94 -0
  1118. package/npm-shrinkwrap.json +1878 -0
  1119. package/package.json +101 -5
@@ -0,0 +1,2341 @@
1
+ import { createHash } from "node:crypto";
2
+ import { existsSync, lstatSync, mkdirSync, readdirSync, readFileSync, realpathSync, rmSync, statSync, writeFileSync, } from "node:fs";
3
+ import { homedir, tmpdir } from "node:os";
4
+ function getEnv() {
5
+ if (process.platform !== "linux" || Object.keys(process.env).length > 0) {
6
+ return process.env;
7
+ }
8
+ try {
9
+ const data = readFileSync("/proc/self/environ", "utf-8");
10
+ const env = {};
11
+ for (const entry of data.split("\0")) {
12
+ const idx = entry.indexOf("=");
13
+ if (idx > 0) {
14
+ env[entry.slice(0, idx)] = entry.slice(idx + 1);
15
+ }
16
+ }
17
+ return env;
18
+ }
19
+ catch {
20
+ return process.env;
21
+ }
22
+ }
23
+ import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
24
+ import { globSync } from "glob";
25
+ import ignore from "ignore";
26
+ import { minimatch } from "minimatch";
27
+ import { CONFIG_DIR_NAME } from "../config.js";
28
+ import { spawnProcess, spawnProcessSync } from "../utils/child-process.js";
29
+ import { isSafeGitInstallPath, parseGitUrl } from "../utils/git.js";
30
+ import { canonicalizePath, isLocalPath, markPathIgnoredByCloudSync, resolvePath } from "../utils/paths.js";
31
+ import { readGripManifest } from "./grip-manifest.js";
32
+ import { isStdoutTakenOver } from "./output-guard.js";
33
+ const NETWORK_TIMEOUT_MS = 10000;
34
+ const UPDATE_CHECK_CONCURRENCY = 4;
35
+ const GIT_UPDATE_CONCURRENCY = 4;
36
+ function isOfflineModeEnabled() {
37
+ const value = process.env.GRIP_OFFLINE;
38
+ if (!value)
39
+ return false;
40
+ return value === "1" || value.toLowerCase() === "true" || value.toLowerCase() === "yes";
41
+ }
42
+ /**
43
+ * Compute a numeric precedence rank for a resource based on its metadata.
44
+ * Lower rank = higher precedence. Used to sort resolved resources so that
45
+ * name-collision resolution ("first wins") produces the correct outcome.
46
+ *
47
+ * Precedence (highest to lowest):
48
+ * 0 project + settings entry (source: "local", scope: "project")
49
+ * 1 project + auto-discovered (source: "auto", scope: "project")
50
+ * 2 user + settings entry (source: "local", scope: "user")
51
+ * 3 user + auto-discovered (source: "auto", scope: "user")
52
+ * 4 package resource (origin: "package")
53
+ */
54
+ function resourcePrecedenceRank(m) {
55
+ if (m.origin === "package")
56
+ return 4;
57
+ const scopeBase = m.scope === "project" ? 0 : 2;
58
+ return scopeBase + (m.source === "local" ? 0 : 1);
59
+ }
60
+ const RESOURCE_TYPES = ["extensions", "skills", "rules", "prompts", "themes"];
61
+ const FILE_PATTERNS = {
62
+ extensions: /\.(ts|js)$/,
63
+ skills: /\.md$/,
64
+ rules: /\.md$/,
65
+ prompts: /\.md$/,
66
+ themes: /\.json$/,
67
+ };
68
+ const IGNORE_FILE_NAMES = new Set([".gitignore", ".ignore", ".fdignore"]);
69
+ function toPosixPath(p) {
70
+ return p.split(sep).join("/");
71
+ }
72
+ function isPathWithin(root, candidate) {
73
+ const rel = relative(root, candidate);
74
+ return rel === "" || (rel !== ".." && !rel.startsWith(`..${sep}`) && !isAbsolute(rel));
75
+ }
76
+ function isMissingPathError(error) {
77
+ return (typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT");
78
+ }
79
+ function getHomeDir() {
80
+ return process.env.HOME || homedir();
81
+ }
82
+ function prefixIgnorePattern(line, prefix) {
83
+ const trimmed = line.trim();
84
+ if (!trimmed)
85
+ return null;
86
+ if (trimmed.startsWith("#") && !trimmed.startsWith("\\#"))
87
+ return null;
88
+ let pattern = line;
89
+ let negated = false;
90
+ if (pattern.startsWith("!")) {
91
+ negated = true;
92
+ pattern = pattern.slice(1);
93
+ }
94
+ else if (pattern.startsWith("\\!")) {
95
+ pattern = pattern.slice(1);
96
+ }
97
+ if (pattern.startsWith("/")) {
98
+ pattern = pattern.slice(1);
99
+ }
100
+ const prefixed = prefix ? `${prefix}${pattern}` : pattern;
101
+ return negated ? `!${prefixed}` : prefixed;
102
+ }
103
+ function addIgnoreRules(ig, dir, rootDir) {
104
+ const relativeDir = relative(rootDir, dir);
105
+ const prefix = relativeDir ? `${toPosixPath(relativeDir)}/` : "";
106
+ for (const filename of IGNORE_FILE_NAMES) {
107
+ const ignorePath = join(dir, filename);
108
+ if (!existsSync(ignorePath))
109
+ continue;
110
+ try {
111
+ const content = readFileSync(ignorePath, "utf-8");
112
+ const patterns = content
113
+ .split(/\r?\n/)
114
+ .map((line) => prefixIgnorePattern(line, prefix))
115
+ .filter((line) => Boolean(line));
116
+ if (patterns.length > 0) {
117
+ ig.add(patterns);
118
+ }
119
+ }
120
+ catch { }
121
+ }
122
+ }
123
+ function isPattern(s) {
124
+ return s.startsWith("!") || s.startsWith("+") || s.startsWith("-") || s.includes("*") || s.includes("?");
125
+ }
126
+ function isOverridePattern(s) {
127
+ return s.startsWith("!") || s.startsWith("+") || s.startsWith("-");
128
+ }
129
+ function hasGlobPattern(s) {
130
+ return s.includes("*") || s.includes("?");
131
+ }
132
+ function splitPatterns(entries) {
133
+ const plain = [];
134
+ const patterns = [];
135
+ for (const entry of entries) {
136
+ if (isPattern(entry)) {
137
+ patterns.push(entry);
138
+ }
139
+ else {
140
+ plain.push(entry);
141
+ }
142
+ }
143
+ return { plain, patterns };
144
+ }
145
+ function collectFileEntry(dir, entry, context) {
146
+ if (entry.name.startsWith("."))
147
+ return [];
148
+ if (context.skipNodeModules && entry.name === "node_modules")
149
+ return [];
150
+ const fullPath = join(dir, entry.name);
151
+ let isDirectory = entry.isDirectory();
152
+ let isFile = entry.isFile();
153
+ if (entry.isSymbolicLink()) {
154
+ try {
155
+ const stats = statSync(fullPath);
156
+ isDirectory = stats.isDirectory();
157
+ isFile = stats.isFile();
158
+ }
159
+ catch {
160
+ return [];
161
+ }
162
+ }
163
+ const relPath = toPosixPath(relative(context.rootDir, fullPath));
164
+ const ignorePath = isDirectory ? `${relPath}/` : relPath;
165
+ if (context.ignoreMatcher.ignores(ignorePath))
166
+ return [];
167
+ if (isDirectory) {
168
+ return collectFiles(fullPath, context.filePattern, context.skipNodeModules, context.ignoreMatcher, context.rootDir, context.visited);
169
+ }
170
+ return isFile && context.filePattern.test(entry.name) ? [fullPath] : [];
171
+ }
172
+ function collectFiles(dir, filePattern, skipNodeModules = true, ignoreMatcher, rootDir, visited = new Set()) {
173
+ const files = [];
174
+ if (!existsSync(dir))
175
+ return files;
176
+ let canonicalDir;
177
+ try {
178
+ canonicalDir = realpathSync(dir);
179
+ }
180
+ catch {
181
+ return files;
182
+ }
183
+ if (visited.has(canonicalDir))
184
+ return files;
185
+ visited.add(canonicalDir);
186
+ const root = rootDir ?? dir;
187
+ const ig = ignoreMatcher ?? ignore();
188
+ addIgnoreRules(ig, dir, root);
189
+ const context = {
190
+ filePattern,
191
+ skipNodeModules,
192
+ ignoreMatcher: ig,
193
+ rootDir: root,
194
+ visited,
195
+ };
196
+ try {
197
+ const entries = readdirSync(dir, { withFileTypes: true });
198
+ for (const entry of entries)
199
+ files.push(...collectFileEntry(dir, entry, context));
200
+ }
201
+ catch {
202
+ // Ignore errors
203
+ }
204
+ return files;
205
+ }
206
+ function resolveDirectoryEntryKind(fullPath, entry) {
207
+ if (!entry.isSymbolicLink()) {
208
+ return { isDirectory: entry.isDirectory(), isFile: entry.isFile() };
209
+ }
210
+ try {
211
+ const stats = statSync(fullPath);
212
+ return { isDirectory: stats.isDirectory(), isFile: stats.isFile() };
213
+ }
214
+ catch {
215
+ return undefined;
216
+ }
217
+ }
218
+ function findDirectInstructionFile(dir, directoryEntries, context) {
219
+ for (const entry of directoryEntries) {
220
+ if (entry.name !== context.entryFileName)
221
+ continue;
222
+ const fullPath = join(dir, entry.name);
223
+ const kind = resolveDirectoryEntryKind(fullPath, entry);
224
+ const relPath = toPosixPath(relative(context.rootDir, fullPath));
225
+ if (kind?.isFile && !context.ignoreMatcher.ignores(relPath))
226
+ return fullPath;
227
+ }
228
+ return undefined;
229
+ }
230
+ function collectInstructionDirectoryEntries(dir, directoryEntries, context, entries) {
231
+ for (const entry of directoryEntries) {
232
+ if (entry.name.startsWith("."))
233
+ continue;
234
+ if (entry.name === "node_modules")
235
+ continue;
236
+ const fullPath = join(dir, entry.name);
237
+ const kind = resolveDirectoryEntryKind(fullPath, entry);
238
+ if (!kind)
239
+ continue;
240
+ const relPath = toPosixPath(relative(context.rootDir, fullPath));
241
+ if (context.mode === "grip" &&
242
+ dir === context.rootDir &&
243
+ kind.isFile &&
244
+ entry.name.endsWith(".md") &&
245
+ !context.ignoreMatcher.ignores(relPath)) {
246
+ entries.push(fullPath);
247
+ continue;
248
+ }
249
+ if (!kind.isDirectory || context.ignoreMatcher.ignores(`${relPath}/`))
250
+ continue;
251
+ entries.push(...collectInstructionEntries(fullPath, context));
252
+ }
253
+ }
254
+ function collectInstructionEntries(dir, context) {
255
+ const entries = [];
256
+ if (!existsSync(dir))
257
+ return entries;
258
+ let canonicalDir;
259
+ try {
260
+ canonicalDir = realpathSync(dir);
261
+ }
262
+ catch {
263
+ return entries;
264
+ }
265
+ if (context.visited.has(canonicalDir))
266
+ return entries;
267
+ context.visited.add(canonicalDir);
268
+ addIgnoreRules(context.ignoreMatcher, dir, context.rootDir);
269
+ try {
270
+ const directoryEntries = readdirSync(dir, { withFileTypes: true });
271
+ const directFile = findDirectInstructionFile(dir, directoryEntries, context);
272
+ if (directFile)
273
+ return [directFile];
274
+ collectInstructionDirectoryEntries(dir, directoryEntries, context, entries);
275
+ }
276
+ catch {
277
+ // Ignore errors
278
+ }
279
+ return entries;
280
+ }
281
+ function collectSkillEntries(dir, mode, ignoreMatcher, rootDir, visited = new Set()) {
282
+ return collectInstructionEntries(dir, {
283
+ entryFileName: "SKILL.md",
284
+ mode,
285
+ ignoreMatcher: ignoreMatcher ?? ignore(),
286
+ rootDir: rootDir ?? dir,
287
+ visited,
288
+ });
289
+ }
290
+ function collectAutoSkillEntries(dir, mode) {
291
+ return collectSkillEntries(dir, mode);
292
+ }
293
+ function collectRuleEntries(dir, mode, ignoreMatcher, rootDir, visited = new Set()) {
294
+ return collectInstructionEntries(dir, {
295
+ entryFileName: "RULES.md",
296
+ mode,
297
+ ignoreMatcher: ignoreMatcher ?? ignore(),
298
+ rootDir: rootDir ?? dir,
299
+ visited,
300
+ });
301
+ }
302
+ function collectAutoRuleEntries(dir, mode) {
303
+ return collectRuleEntries(dir, mode);
304
+ }
305
+ function findGitRepoRoot(startDir) {
306
+ let dir = resolve(startDir);
307
+ while (true) {
308
+ if (existsSync(join(dir, ".git"))) {
309
+ return dir;
310
+ }
311
+ const parent = dirname(dir);
312
+ if (parent === dir) {
313
+ return null;
314
+ }
315
+ dir = parent;
316
+ }
317
+ }
318
+ function collectAncestorAgentsSkillDirs(startDir) {
319
+ const skillDirs = [];
320
+ const resolvedStartDir = resolve(startDir);
321
+ const gitRepoRoot = findGitRepoRoot(resolvedStartDir);
322
+ let dir = resolvedStartDir;
323
+ while (true) {
324
+ skillDirs.push(join(dir, ".agents", "skills"));
325
+ if (gitRepoRoot && dir === gitRepoRoot) {
326
+ break;
327
+ }
328
+ const parent = dirname(dir);
329
+ if (parent === dir) {
330
+ break;
331
+ }
332
+ dir = parent;
333
+ }
334
+ return skillDirs;
335
+ }
336
+ function collectAncestorAgentsRuleDirs(startDir) {
337
+ const ruleDirs = [];
338
+ const resolvedStartDir = resolve(startDir);
339
+ const gitRepoRoot = findGitRepoRoot(resolvedStartDir);
340
+ let dir = resolvedStartDir;
341
+ while (true) {
342
+ ruleDirs.push(join(dir, ".agents", "rules"));
343
+ if (gitRepoRoot && dir === gitRepoRoot) {
344
+ break;
345
+ }
346
+ const parent = dirname(dir);
347
+ if (parent === dir) {
348
+ break;
349
+ }
350
+ dir = parent;
351
+ }
352
+ return ruleDirs;
353
+ }
354
+ function collectAutoPromptEntries(dir) {
355
+ const entries = [];
356
+ if (!existsSync(dir))
357
+ return entries;
358
+ const ig = ignore();
359
+ addIgnoreRules(ig, dir, dir);
360
+ try {
361
+ const dirEntries = readdirSync(dir, { withFileTypes: true });
362
+ for (const entry of dirEntries) {
363
+ if (entry.name.startsWith("."))
364
+ continue;
365
+ if (entry.name === "node_modules")
366
+ continue;
367
+ const fullPath = join(dir, entry.name);
368
+ const kind = resolveDirectoryEntryKind(fullPath, entry);
369
+ if (!kind)
370
+ continue;
371
+ const relPath = toPosixPath(relative(dir, fullPath));
372
+ if (ig.ignores(relPath))
373
+ continue;
374
+ if (kind.isFile && entry.name.endsWith(".md"))
375
+ entries.push(fullPath);
376
+ }
377
+ }
378
+ catch {
379
+ // Ignore errors
380
+ }
381
+ return entries;
382
+ }
383
+ function collectAutoThemeEntries(dir) {
384
+ const entries = [];
385
+ if (!existsSync(dir))
386
+ return entries;
387
+ const ig = ignore();
388
+ addIgnoreRules(ig, dir, dir);
389
+ try {
390
+ const dirEntries = readdirSync(dir, { withFileTypes: true });
391
+ for (const entry of dirEntries) {
392
+ if (entry.name.startsWith("."))
393
+ continue;
394
+ if (entry.name === "node_modules")
395
+ continue;
396
+ const fullPath = join(dir, entry.name);
397
+ const kind = resolveDirectoryEntryKind(fullPath, entry);
398
+ if (!kind)
399
+ continue;
400
+ const relPath = toPosixPath(relative(dir, fullPath));
401
+ if (ig.ignores(relPath))
402
+ continue;
403
+ if (kind.isFile && entry.name.endsWith(".json"))
404
+ entries.push(fullPath);
405
+ }
406
+ }
407
+ catch {
408
+ // Ignore errors
409
+ }
410
+ return entries;
411
+ }
412
+ function resolveExtensionEntries(dir) {
413
+ const packageJsonPath = join(dir, "package.json");
414
+ if (existsSync(packageJsonPath)) {
415
+ const manifest = readGripManifest(packageJsonPath);
416
+ if (manifest?.extensions?.length) {
417
+ const entries = [];
418
+ for (const extPath of manifest.extensions) {
419
+ const resolvedExtPath = resolve(dir, extPath);
420
+ if (existsSync(resolvedExtPath)) {
421
+ entries.push(resolvedExtPath);
422
+ }
423
+ }
424
+ if (entries.length > 0) {
425
+ return entries;
426
+ }
427
+ }
428
+ }
429
+ const indexTs = join(dir, "index.ts");
430
+ const indexJs = join(dir, "index.ts");
431
+ if (existsSync(indexTs)) {
432
+ return [indexTs];
433
+ }
434
+ if (existsSync(indexJs)) {
435
+ return [indexJs];
436
+ }
437
+ return null;
438
+ }
439
+ function collectAutoExtensionDirectoryEntry(dir, entry, ignoreMatcher) {
440
+ if (entry.name.startsWith("."))
441
+ return [];
442
+ if (entry.name === "node_modules")
443
+ return [];
444
+ const fullPath = join(dir, entry.name);
445
+ const kind = resolveDirectoryEntryKind(fullPath, entry);
446
+ if (!kind)
447
+ return [];
448
+ const relPath = toPosixPath(relative(dir, fullPath));
449
+ const ignorePath = kind.isDirectory ? `${relPath}/` : relPath;
450
+ if (ignoreMatcher.ignores(ignorePath))
451
+ return [];
452
+ if (kind.isFile)
453
+ return entry.name.endsWith(".ts") ? [fullPath] : [];
454
+ if (!kind.isDirectory)
455
+ return [];
456
+ return resolveExtensionEntries(fullPath) ?? [];
457
+ }
458
+ function collectAutoExtensionEntries(dir) {
459
+ if (!existsSync(dir))
460
+ return [];
461
+ // An explicit package manifest or index takes precedence over child discovery.
462
+ const rootEntries = resolveExtensionEntries(dir);
463
+ if (rootEntries)
464
+ return rootEntries;
465
+ const entries = [];
466
+ const ignoreMatcher = ignore();
467
+ addIgnoreRules(ignoreMatcher, dir, dir);
468
+ try {
469
+ const directoryEntries = readdirSync(dir, { withFileTypes: true });
470
+ for (const entry of directoryEntries) {
471
+ entries.push(...collectAutoExtensionDirectoryEntry(dir, entry, ignoreMatcher));
472
+ }
473
+ }
474
+ catch {
475
+ // Ignore errors
476
+ }
477
+ return entries;
478
+ }
479
+ /**
480
+ * Collect resource files from a directory based on resource type.
481
+ * Extensions use smart discovery (index.ts in subdirs), others use recursive collection.
482
+ */
483
+ function collectResourceFiles(dir, resourceType) {
484
+ if (resourceType === "skills") {
485
+ return collectSkillEntries(dir, "grip");
486
+ }
487
+ if (resourceType === "rules") {
488
+ return collectRuleEntries(dir, "grip");
489
+ }
490
+ if (resourceType === "extensions") {
491
+ return collectAutoExtensionEntries(dir);
492
+ }
493
+ return collectFiles(dir, FILE_PATTERNS[resourceType]);
494
+ }
495
+ function matchesAnyPattern(filePath, patterns, baseDir) {
496
+ const rel = toPosixPath(relative(baseDir, filePath));
497
+ const name = basename(filePath);
498
+ const filePathPosix = toPosixPath(filePath);
499
+ const isDirectoryResourceFile = name === "SKILL.md" || name === "RULES.md";
500
+ const parentDir = isDirectoryResourceFile ? dirname(filePath) : undefined;
501
+ const parentRel = isDirectoryResourceFile ? toPosixPath(relative(baseDir, parentDir)) : undefined;
502
+ const parentName = isDirectoryResourceFile ? basename(parentDir) : undefined;
503
+ const parentDirPosix = isDirectoryResourceFile ? toPosixPath(parentDir) : undefined;
504
+ return patterns.some((pattern) => {
505
+ const normalizedPattern = toPosixPath(pattern);
506
+ if (minimatch(rel, normalizedPattern) ||
507
+ minimatch(name, normalizedPattern) ||
508
+ minimatch(filePathPosix, normalizedPattern)) {
509
+ return true;
510
+ }
511
+ if (!isDirectoryResourceFile)
512
+ return false;
513
+ return (minimatch(parentRel, normalizedPattern) ||
514
+ minimatch(parentName, normalizedPattern) ||
515
+ minimatch(parentDirPosix, normalizedPattern));
516
+ });
517
+ }
518
+ function normalizeExactPattern(pattern) {
519
+ const normalized = pattern.startsWith("./") || pattern.startsWith(".\\") ? pattern.slice(2) : pattern;
520
+ return toPosixPath(normalized);
521
+ }
522
+ function matchesAnyExactPattern(filePath, patterns, baseDir) {
523
+ if (patterns.length === 0)
524
+ return false;
525
+ const rel = toPosixPath(relative(baseDir, filePath));
526
+ const name = basename(filePath);
527
+ const filePathPosix = toPosixPath(filePath);
528
+ const isDirectoryResourceFile = name === "SKILL.md" || name === "RULES.md";
529
+ const parentDir = isDirectoryResourceFile ? dirname(filePath) : undefined;
530
+ const parentRel = isDirectoryResourceFile ? toPosixPath(relative(baseDir, parentDir)) : undefined;
531
+ const parentDirPosix = isDirectoryResourceFile ? toPosixPath(parentDir) : undefined;
532
+ return patterns.some((pattern) => {
533
+ const normalized = normalizeExactPattern(pattern);
534
+ if (normalized === rel || normalized === filePathPosix) {
535
+ return true;
536
+ }
537
+ if (!isDirectoryResourceFile)
538
+ return false;
539
+ return normalized === parentRel || normalized === parentDirPosix;
540
+ });
541
+ }
542
+ function getOverridePatterns(entries) {
543
+ return entries.filter((pattern) => pattern.startsWith("!") || pattern.startsWith("+") || pattern.startsWith("-"));
544
+ }
545
+ function isEnabledByOverrides(filePath, patterns, baseDir) {
546
+ const overrides = getOverridePatterns(patterns);
547
+ const excludes = overrides.filter((pattern) => pattern.startsWith("!")).map((pattern) => pattern.slice(1));
548
+ const forceIncludes = overrides.filter((pattern) => pattern.startsWith("+")).map((pattern) => pattern.slice(1));
549
+ const forceExcludes = overrides.filter((pattern) => pattern.startsWith("-")).map((pattern) => pattern.slice(1));
550
+ let enabled = true;
551
+ if (excludes.length > 0 && matchesAnyPattern(filePath, excludes, baseDir)) {
552
+ enabled = false;
553
+ }
554
+ if (forceIncludes.length > 0 && matchesAnyExactPattern(filePath, forceIncludes, baseDir)) {
555
+ enabled = true;
556
+ }
557
+ if (forceExcludes.length > 0 && matchesAnyExactPattern(filePath, forceExcludes, baseDir)) {
558
+ enabled = false;
559
+ }
560
+ return enabled;
561
+ }
562
+ function groupPackagePatterns(patterns) {
563
+ const groups = { includes: [], excludes: [], forceIncludes: [], forceExcludes: [] };
564
+ for (const pattern of patterns) {
565
+ if (pattern.startsWith("+")) {
566
+ groups.forceIncludes.push(pattern.slice(1));
567
+ }
568
+ else if (pattern.startsWith("-")) {
569
+ groups.forceExcludes.push(pattern.slice(1));
570
+ }
571
+ else if (pattern.startsWith("!")) {
572
+ groups.excludes.push(pattern.slice(1));
573
+ }
574
+ else {
575
+ groups.includes.push(pattern);
576
+ }
577
+ }
578
+ return groups;
579
+ }
580
+ function applyPatterns(allPaths, patterns, baseDir) {
581
+ const { includes, excludes, forceIncludes, forceExcludes } = groupPackagePatterns(patterns);
582
+ // Step 1: Apply includes (or all if no includes)
583
+ let result;
584
+ if (includes.length === 0) {
585
+ result = [...allPaths];
586
+ }
587
+ else {
588
+ result = allPaths.filter((filePath) => matchesAnyPattern(filePath, includes, baseDir));
589
+ }
590
+ // Step 2: Apply excludes
591
+ if (excludes.length > 0) {
592
+ result = result.filter((filePath) => !matchesAnyPattern(filePath, excludes, baseDir));
593
+ }
594
+ // Step 3: Force-include (add back from allPaths, overriding exclusions)
595
+ if (forceIncludes.length > 0) {
596
+ const includedPaths = new Set(result);
597
+ for (const filePath of allPaths) {
598
+ if (!includedPaths.has(filePath) && matchesAnyExactPattern(filePath, forceIncludes, baseDir)) {
599
+ includedPaths.add(filePath);
600
+ result.push(filePath);
601
+ }
602
+ }
603
+ }
604
+ // Step 4: Force-exclude (remove even if included or force-included)
605
+ if (forceExcludes.length > 0) {
606
+ result = result.filter((filePath) => !matchesAnyExactPattern(filePath, forceExcludes, baseDir));
607
+ }
608
+ return new Set(result);
609
+ }
610
+ export class DefaultPackageManager {
611
+ cwd;
612
+ agentDir;
613
+ settingsManager;
614
+ globalNpmRoot;
615
+ globalNpmRootCommandKey;
616
+ progressCallback;
617
+ constructor(options) {
618
+ this.cwd = resolvePath(options.cwd);
619
+ this.agentDir = resolvePath(options.agentDir);
620
+ this.settingsManager = options.settingsManager;
621
+ }
622
+ setProgressCallback(callback) {
623
+ this.progressCallback = callback;
624
+ }
625
+ addSourceToSettings(source, options) {
626
+ const scope = options?.local ? "project" : "user";
627
+ const currentSettings = scope === "project" ? this.settingsManager.getProjectSettings() : this.settingsManager.getGlobalSettings();
628
+ const currentPackages = currentSettings.packages ?? [];
629
+ const normalizedSource = this.normalizePackageSourceForSettings(source, scope);
630
+ const matchIndex = currentPackages.findIndex((existing) => this.packageSourcesMatch(existing, source, scope));
631
+ if (matchIndex !== -1) {
632
+ const existing = currentPackages[matchIndex];
633
+ if (this.getPackageSourceString(existing) === normalizedSource) {
634
+ return false;
635
+ }
636
+ const nextPackages = [...currentPackages];
637
+ nextPackages[matchIndex] =
638
+ typeof existing === "string" ? normalizedSource : { ...existing, source: normalizedSource };
639
+ if (scope === "project") {
640
+ this.settingsManager.setProjectPackages(nextPackages);
641
+ }
642
+ else {
643
+ this.settingsManager.setPackages(nextPackages);
644
+ }
645
+ return true;
646
+ }
647
+ const nextPackages = [...currentPackages, normalizedSource];
648
+ if (scope === "project") {
649
+ this.settingsManager.setProjectPackages(nextPackages);
650
+ }
651
+ else {
652
+ this.settingsManager.setPackages(nextPackages);
653
+ }
654
+ return true;
655
+ }
656
+ removeSourceFromSettings(source, options) {
657
+ const scope = options?.local ? "project" : "user";
658
+ const currentSettings = scope === "project" ? this.settingsManager.getProjectSettings() : this.settingsManager.getGlobalSettings();
659
+ const currentPackages = currentSettings.packages ?? [];
660
+ const nextPackages = currentPackages.filter((existing) => !this.packageSourcesMatch(existing, source, scope));
661
+ const changed = nextPackages.length !== currentPackages.length;
662
+ if (!changed) {
663
+ return false;
664
+ }
665
+ if (scope === "project") {
666
+ this.settingsManager.setProjectPackages(nextPackages);
667
+ }
668
+ else {
669
+ this.settingsManager.setPackages(nextPackages);
670
+ }
671
+ return true;
672
+ }
673
+ getInstalledPath(source, scope) {
674
+ const parsed = this.parseSource(source);
675
+ if (parsed.type === "npm") {
676
+ const path = this.getNpmInstallPath(parsed, scope);
677
+ return existsSync(path) ? path : undefined;
678
+ }
679
+ if (parsed.type === "git") {
680
+ const path = this.getGitInstallPath(parsed, scope);
681
+ return existsSync(path) ? path : undefined;
682
+ }
683
+ if (parsed.type === "local") {
684
+ const baseDir = this.getBaseDirForScope(scope);
685
+ const path = this.resolvePathFromBase(parsed.path, baseDir);
686
+ return existsSync(path) ? path : undefined;
687
+ }
688
+ return undefined;
689
+ }
690
+ emitProgress(event) {
691
+ this.progressCallback?.(event);
692
+ }
693
+ async withProgress(action, source, message, operation) {
694
+ this.emitProgress({ type: "start", action, source, message });
695
+ try {
696
+ await operation();
697
+ this.emitProgress({ type: "complete", action, source });
698
+ }
699
+ catch (error) {
700
+ const errorMessage = error instanceof Error ? error.message : String(error);
701
+ this.emitProgress({ type: "error", action, source, message: errorMessage });
702
+ throw error;
703
+ }
704
+ }
705
+ async resolve(onMissing) {
706
+ const accumulator = this.createAccumulator();
707
+ const globalSettings = this.settingsManager.getGlobalSettings();
708
+ const projectSettings = this.settingsManager.getProjectSettings();
709
+ // Collect all packages with scope (project first so cwd resources win collisions)
710
+ const allPackages = [];
711
+ for (const pkg of projectSettings.packages ?? []) {
712
+ allPackages.push({ pkg, scope: "project" });
713
+ }
714
+ for (const pkg of globalSettings.packages ?? []) {
715
+ allPackages.push({ pkg, scope: "user" });
716
+ }
717
+ // Dedupe: project scope wins over global for same package identity
718
+ const packageSources = this.dedupePackages(allPackages);
719
+ await this.resolvePackageSources(packageSources, accumulator, onMissing);
720
+ const globalBaseDir = this.agentDir;
721
+ const projectBaseDir = join(this.cwd, CONFIG_DIR_NAME);
722
+ for (const resourceType of RESOURCE_TYPES) {
723
+ const target = this.getTargetMap(accumulator, resourceType);
724
+ const globalEntries = (globalSettings[resourceType] ?? []);
725
+ const projectEntries = (projectSettings[resourceType] ?? []);
726
+ this.resolveLocalEntries(projectEntries, resourceType, target, {
727
+ source: "local",
728
+ scope: "project",
729
+ origin: "top-level",
730
+ }, projectBaseDir);
731
+ this.resolveLocalEntries(globalEntries, resourceType, target, {
732
+ source: "local",
733
+ scope: "user",
734
+ origin: "top-level",
735
+ }, globalBaseDir);
736
+ }
737
+ this.addAutoDiscoveredResources(accumulator, globalSettings, projectSettings, globalBaseDir, projectBaseDir);
738
+ return this.toResolvedPaths(accumulator);
739
+ }
740
+ async resolveExtensionSources(sources, options) {
741
+ const accumulator = this.createAccumulator();
742
+ const scope = options?.temporary ? "temporary" : options?.local ? "project" : "user";
743
+ const packageSources = sources.map((source) => ({ pkg: source, scope }));
744
+ await this.resolvePackageSources(packageSources, accumulator);
745
+ return this.toResolvedPaths(accumulator);
746
+ }
747
+ listConfiguredPackages() {
748
+ const globalSettings = this.settingsManager.getGlobalSettings();
749
+ const projectSettings = this.settingsManager.getProjectSettings();
750
+ const configuredPackages = [];
751
+ for (const pkg of globalSettings.packages ?? []) {
752
+ const source = typeof pkg === "string" ? pkg : pkg.source;
753
+ configuredPackages.push({
754
+ source,
755
+ scope: "user",
756
+ filtered: typeof pkg === "object",
757
+ installedPath: this.getInstalledPath(source, "user"),
758
+ });
759
+ }
760
+ for (const pkg of projectSettings.packages ?? []) {
761
+ const source = typeof pkg === "string" ? pkg : pkg.source;
762
+ configuredPackages.push({
763
+ source,
764
+ scope: "project",
765
+ filtered: typeof pkg === "object",
766
+ installedPath: this.getInstalledPath(source, "project"),
767
+ });
768
+ }
769
+ return configuredPackages;
770
+ }
771
+ async install(source, options) {
772
+ const parsed = this.parseSource(source);
773
+ const scope = options?.local ? "project" : "user";
774
+ await this.withProgress("install", source, `Installing ${source}...`, async () => {
775
+ if (parsed.type === "npm") {
776
+ await this.installNpm(parsed, scope, false);
777
+ return;
778
+ }
779
+ if (parsed.type === "git") {
780
+ await this.installGit(parsed, scope);
781
+ return;
782
+ }
783
+ if (parsed.type === "local") {
784
+ const resolved = this.resolvePath(parsed.path);
785
+ if (!existsSync(resolved)) {
786
+ throw new Error(`Path does not exist: ${resolved}`);
787
+ }
788
+ return;
789
+ }
790
+ throw new Error(`Unsupported install source: ${source}`);
791
+ });
792
+ }
793
+ async installAndPersist(source, options) {
794
+ await this.install(source, options);
795
+ this.addSourceToSettings(source, options);
796
+ }
797
+ async remove(source, options) {
798
+ const parsed = this.parseSource(source);
799
+ const scope = options?.local ? "project" : "user";
800
+ await this.withProgress("remove", source, `Removing ${source}...`, async () => {
801
+ if (parsed.type === "npm") {
802
+ await this.uninstallNpm(parsed, scope);
803
+ return;
804
+ }
805
+ if (parsed.type === "git") {
806
+ await this.removeGit(parsed, scope);
807
+ return;
808
+ }
809
+ if (parsed.type === "local") {
810
+ return;
811
+ }
812
+ throw new Error(`Unsupported remove source: ${source}`);
813
+ });
814
+ }
815
+ async removeAndPersist(source, options) {
816
+ await this.remove(source, options);
817
+ return this.removeSourceFromSettings(source, options);
818
+ }
819
+ collectConfiguredUpdateSources(packages, scope, identity) {
820
+ const sources = [];
821
+ for (const pkg of packages) {
822
+ const packageSource = typeof pkg === "string" ? pkg : pkg.source;
823
+ if (identity && this.getPackageIdentity(packageSource, scope) !== identity)
824
+ continue;
825
+ sources.push({ source: packageSource, scope });
826
+ }
827
+ return sources;
828
+ }
829
+ async update(source) {
830
+ const globalSettings = this.settingsManager.getGlobalSettings();
831
+ const projectSettings = this.settingsManager.getProjectSettings();
832
+ const globalPackages = globalSettings.packages ?? [];
833
+ const projectPackages = projectSettings.packages ?? [];
834
+ const identity = source ? this.getPackageIdentity(source) : undefined;
835
+ const updateSources = [
836
+ ...this.collectConfiguredUpdateSources(globalPackages, "user", identity),
837
+ ...this.collectConfiguredUpdateSources(projectPackages, "project", identity),
838
+ ];
839
+ if (source && updateSources.length === 0) {
840
+ throw new Error(this.buildNoMatchingPackageMessage(source, [...globalPackages, ...projectPackages]));
841
+ }
842
+ await this.updateConfiguredSources(updateSources);
843
+ }
844
+ classifyConfiguredUpdateSources(sources) {
845
+ const candidates = { npm: [], git: [] };
846
+ for (const entry of sources) {
847
+ const parsed = this.parseSource(entry.source);
848
+ // Pinned npm versions are fixed. Pinned git refs are configured checkout targets,
849
+ // so include them to reconcile an existing clone when the configured ref changes.
850
+ if (parsed.type === "npm") {
851
+ if (!parsed.pinned)
852
+ candidates.npm.push({ ...entry, parsed });
853
+ continue;
854
+ }
855
+ if (parsed.type === "git")
856
+ candidates.git.push({ ...entry, parsed });
857
+ }
858
+ return candidates;
859
+ }
860
+ async updateConfiguredSources(sources) {
861
+ if (isOfflineModeEnabled() || sources.length === 0) {
862
+ return;
863
+ }
864
+ const candidates = this.classifyConfiguredUpdateSources(sources);
865
+ const npmCheckTasks = candidates.npm.map((entry) => async () => ({
866
+ entry,
867
+ shouldUpdate: await this.shouldUpdateNpmSource(entry.parsed, entry.scope),
868
+ }));
869
+ const npmCheckResults = await this.runWithConcurrency(npmCheckTasks, UPDATE_CHECK_CONCURRENCY);
870
+ const userNpmUpdates = [];
871
+ const projectNpmUpdates = [];
872
+ for (const result of npmCheckResults) {
873
+ if (!result.shouldUpdate) {
874
+ continue;
875
+ }
876
+ if (result.entry.scope === "user") {
877
+ userNpmUpdates.push(result.entry);
878
+ }
879
+ else {
880
+ projectNpmUpdates.push(result.entry);
881
+ }
882
+ }
883
+ const tasks = [];
884
+ if (userNpmUpdates.length > 0) {
885
+ tasks.push(this.updateNpmBatch(userNpmUpdates, "user"));
886
+ }
887
+ if (projectNpmUpdates.length > 0) {
888
+ tasks.push(this.updateNpmBatch(projectNpmUpdates, "project"));
889
+ }
890
+ if (candidates.git.length > 0) {
891
+ const gitTasks = candidates.git.map((entry) => async () => this.withProgress("update", entry.source, `Updating ${entry.source}...`, async () => {
892
+ await this.updateGit(entry.parsed, entry.scope);
893
+ }));
894
+ tasks.push(this.runWithConcurrency(gitTasks, GIT_UPDATE_CONCURRENCY).then(() => { }));
895
+ }
896
+ await Promise.all(tasks);
897
+ }
898
+ async shouldUpdateNpmSource(source, scope) {
899
+ const installedPath = this.getManagedNpmInstallPath(source, scope);
900
+ const installedVersion = existsSync(installedPath) ? this.getInstalledNpmVersion(installedPath) : undefined;
901
+ if (!installedVersion) {
902
+ return true;
903
+ }
904
+ try {
905
+ const latestVersion = await this.getLatestNpmVersion(source.name);
906
+ return latestVersion !== installedVersion;
907
+ }
908
+ catch {
909
+ // Preserve existing update behavior when version lookup fails.
910
+ return true;
911
+ }
912
+ }
913
+ async updateNpmBatch(sources, scope) {
914
+ if (sources.length === 0) {
915
+ return;
916
+ }
917
+ const sourceLabel = sources.length === 1 ? sources[0].source : `${scope} npm packages`;
918
+ const message = sources.length === 1 ? `Updating ${sources[0].source}...` : `Updating ${scope} npm packages...`;
919
+ const specs = sources.map((entry) => `${entry.parsed.name}@latest`);
920
+ await this.withProgress("update", sourceLabel, message, async () => {
921
+ await this.installNpmBatch(specs, scope);
922
+ });
923
+ }
924
+ async installNpmBatch(specs, scope) {
925
+ const installRoot = this.getNpmInstallRoot(scope, false);
926
+ this.ensureNpmProject(installRoot);
927
+ await this.runNpmCommand(this.getNpmInstallArgs(specs, installRoot));
928
+ }
929
+ async getAvailableNpmUpdate(source, parsed, scope) {
930
+ const installedPath = this.getNpmInstallPath(parsed, scope);
931
+ if (!existsSync(installedPath))
932
+ return undefined;
933
+ if (!(await this.npmHasAvailableUpdate(parsed, installedPath)))
934
+ return undefined;
935
+ return { source, displayName: parsed.name, type: "npm", scope };
936
+ }
937
+ async getAvailableGitUpdate(source, parsed, scope) {
938
+ const installedPath = this.getGitInstallPath(parsed, scope);
939
+ if (!existsSync(installedPath))
940
+ return undefined;
941
+ if (!(await this.gitHasAvailableUpdate(installedPath)))
942
+ return undefined;
943
+ return { source, displayName: `${parsed.host}/${parsed.path}`, type: "git", scope };
944
+ }
945
+ async checkForAvailableUpdates() {
946
+ if (isOfflineModeEnabled()) {
947
+ return [];
948
+ }
949
+ const globalSettings = this.settingsManager.getGlobalSettings();
950
+ const projectSettings = this.settingsManager.getProjectSettings();
951
+ const allPackages = [];
952
+ for (const pkg of projectSettings.packages ?? []) {
953
+ allPackages.push({ pkg, scope: "project" });
954
+ }
955
+ for (const pkg of globalSettings.packages ?? []) {
956
+ allPackages.push({ pkg, scope: "user" });
957
+ }
958
+ const packageSources = this.dedupePackages(allPackages);
959
+ const checks = packageSources
960
+ .filter((entry) => entry.scope !== "temporary")
961
+ .map((entry) => async () => {
962
+ const source = typeof entry.pkg === "string" ? entry.pkg : entry.pkg.source;
963
+ const parsed = this.parseSource(source);
964
+ if (parsed.type === "local" || parsed.pinned)
965
+ return undefined;
966
+ if (parsed.type === "npm")
967
+ return this.getAvailableNpmUpdate(source, parsed, entry.scope);
968
+ return this.getAvailableGitUpdate(source, parsed, entry.scope);
969
+ });
970
+ const results = await this.runWithConcurrency(checks, UPDATE_CHECK_CONCURRENCY);
971
+ return results.filter((result) => result !== undefined);
972
+ }
973
+ async resolvePackageSources(sources, accumulator, onMissing) {
974
+ for (const { pkg, scope } of sources) {
975
+ const source = typeof pkg === "string" ? pkg : pkg.source;
976
+ const filter = typeof pkg === "object" ? pkg : undefined;
977
+ const parsed = this.parseSource(source);
978
+ const metadata = { source, scope, origin: "package" };
979
+ if (parsed.type === "local") {
980
+ const baseDir = this.getBaseDirForScope(scope);
981
+ this.resolveLocalExtensionSource(parsed, accumulator, filter, metadata, baseDir);
982
+ continue;
983
+ }
984
+ const context = {
985
+ source,
986
+ scope,
987
+ accumulator,
988
+ filter,
989
+ metadata,
990
+ onMissing,
991
+ };
992
+ if (parsed.type === "npm") {
993
+ await this.resolveNpmPackageSource(parsed, context);
994
+ continue;
995
+ }
996
+ await this.resolveGitPackageSource(parsed, context);
997
+ }
998
+ }
999
+ async installMissingPackageSource(parsed, context) {
1000
+ if (isOfflineModeEnabled())
1001
+ return false;
1002
+ if (!context.onMissing) {
1003
+ await this.installParsedSource(parsed, context.scope);
1004
+ return true;
1005
+ }
1006
+ const action = await context.onMissing(context.source);
1007
+ if (action === "skip")
1008
+ return false;
1009
+ if (action === "error")
1010
+ throw new Error(`Missing source: ${context.source}`);
1011
+ await this.installParsedSource(parsed, context.scope);
1012
+ return true;
1013
+ }
1014
+ async resolveNpmPackageSource(source, context) {
1015
+ let installedPath = this.getNpmInstallPath(source, context.scope);
1016
+ const needsInstall = !existsSync(installedPath) ||
1017
+ (source.pinned && !(await this.installedNpmMatchesPinnedVersion(source, installedPath)));
1018
+ if (needsInstall) {
1019
+ const installed = await this.installMissingPackageSource(source, context);
1020
+ if (!installed)
1021
+ return;
1022
+ installedPath = this.getNpmInstallPath(source, context.scope);
1023
+ }
1024
+ context.metadata.baseDir = installedPath;
1025
+ this.collectPackageResources(installedPath, context.accumulator, context.filter, context.metadata);
1026
+ }
1027
+ async resolveGitPackageSource(source, context) {
1028
+ const installedPath = this.getGitInstallPath(source, context.scope);
1029
+ if (!existsSync(installedPath)) {
1030
+ const installed = await this.installMissingPackageSource(source, context);
1031
+ if (!installed)
1032
+ return;
1033
+ }
1034
+ else if (context.scope === "temporary" && !source.pinned && !isOfflineModeEnabled()) {
1035
+ await this.refreshTemporaryGitSource(source, context.source);
1036
+ }
1037
+ context.metadata.baseDir = installedPath;
1038
+ this.collectManagedGitPackageResources(installedPath, context.accumulator, context.filter, context.metadata);
1039
+ }
1040
+ resolveLocalExtensionSource(source, accumulator, filter, metadata, baseDir) {
1041
+ const resolved = this.resolvePathFromBase(source.path, baseDir);
1042
+ if (!existsSync(resolved)) {
1043
+ return;
1044
+ }
1045
+ try {
1046
+ const stats = statSync(resolved);
1047
+ if (stats.isFile()) {
1048
+ metadata.baseDir = dirname(resolved);
1049
+ this.addResource(accumulator.extensions, resolved, metadata, true);
1050
+ return;
1051
+ }
1052
+ if (stats.isDirectory()) {
1053
+ metadata.baseDir = resolved;
1054
+ const resources = this.collectPackageResources(resolved, accumulator, filter, metadata);
1055
+ if (!resources) {
1056
+ this.addResource(accumulator.extensions, resolved, metadata, true);
1057
+ }
1058
+ }
1059
+ }
1060
+ catch {
1061
+ return;
1062
+ }
1063
+ }
1064
+ async installParsedSource(parsed, scope) {
1065
+ if (parsed.type === "npm") {
1066
+ await this.installNpm(parsed, scope, scope === "temporary");
1067
+ return;
1068
+ }
1069
+ if (parsed.type === "git") {
1070
+ await this.installGit(parsed, scope);
1071
+ return;
1072
+ }
1073
+ }
1074
+ getPackageSourceString(pkg) {
1075
+ return typeof pkg === "string" ? pkg : pkg.source;
1076
+ }
1077
+ getSourceMatchKeyForInput(source) {
1078
+ const parsed = this.parseSource(source);
1079
+ if (parsed.type === "npm") {
1080
+ return `npm:${parsed.name}`;
1081
+ }
1082
+ if (parsed.type === "git") {
1083
+ return `git:${parsed.host}/${parsed.path}`;
1084
+ }
1085
+ return `local:${this.resolvePath(parsed.path)}`;
1086
+ }
1087
+ getSourceMatchKeyForSettings(source, scope) {
1088
+ const parsed = this.parseSource(source);
1089
+ if (parsed.type === "npm") {
1090
+ return `npm:${parsed.name}`;
1091
+ }
1092
+ if (parsed.type === "git") {
1093
+ return `git:${parsed.host}/${parsed.path}`;
1094
+ }
1095
+ const baseDir = this.getBaseDirForScope(scope);
1096
+ return `local:${this.resolvePathFromBase(parsed.path, baseDir)}`;
1097
+ }
1098
+ buildNoMatchingPackageMessage(source, configuredPackages) {
1099
+ const suggestion = this.findSuggestedConfiguredSource(source, configuredPackages);
1100
+ if (!suggestion) {
1101
+ return `No matching package found for ${source}`;
1102
+ }
1103
+ return `No matching package found for ${source}. Did you mean ${suggestion}?`;
1104
+ }
1105
+ getConfiguredSourceAliases(source) {
1106
+ const parsed = this.parseSource(source);
1107
+ if (parsed.type === "npm")
1108
+ return [parsed.name, parsed.spec];
1109
+ if (parsed.type !== "git")
1110
+ return [];
1111
+ const shorthand = `${parsed.host}/${parsed.path}`;
1112
+ return parsed.ref ? [shorthand, `${shorthand}@${parsed.ref}`] : [shorthand];
1113
+ }
1114
+ findSuggestedConfiguredSource(source, configuredPackages) {
1115
+ const trimmedSource = source.trim();
1116
+ const suggestions = new Set();
1117
+ for (const pkg of configuredPackages) {
1118
+ const sourceStr = this.getPackageSourceString(pkg);
1119
+ if (this.getConfiguredSourceAliases(sourceStr).includes(trimmedSource))
1120
+ suggestions.add(sourceStr);
1121
+ }
1122
+ return suggestions.values().next().value;
1123
+ }
1124
+ packageSourcesMatch(existing, inputSource, scope) {
1125
+ const left = this.getSourceMatchKeyForSettings(this.getPackageSourceString(existing), scope);
1126
+ const right = this.getSourceMatchKeyForInput(inputSource);
1127
+ return left === right;
1128
+ }
1129
+ normalizePackageSourceForSettings(source, scope) {
1130
+ const parsed = this.parseSource(source);
1131
+ if (parsed.type !== "local") {
1132
+ return source;
1133
+ }
1134
+ const baseDir = this.getBaseDirForScope(scope);
1135
+ const resolved = this.resolvePath(parsed.path);
1136
+ const rel = relative(baseDir, resolved);
1137
+ return rel || ".";
1138
+ }
1139
+ parseSource(source) {
1140
+ if (source.startsWith("npm:")) {
1141
+ const spec = source.slice("npm:".length).trim();
1142
+ const { name, version } = this.parseNpmSpec(spec);
1143
+ return {
1144
+ type: "npm",
1145
+ spec,
1146
+ name,
1147
+ pinned: Boolean(version),
1148
+ };
1149
+ }
1150
+ if (isLocalPath(source)) {
1151
+ return { type: "local", path: source };
1152
+ }
1153
+ // Try parsing as git URL
1154
+ const gitParsed = parseGitUrl(source);
1155
+ if (gitParsed) {
1156
+ return gitParsed;
1157
+ }
1158
+ if (!isLocalPath(source)) {
1159
+ throw new Error(`Unsafe or invalid Git package source: ${source}`);
1160
+ }
1161
+ return { type: "local", path: source };
1162
+ }
1163
+ async installedNpmMatchesPinnedVersion(source, installedPath) {
1164
+ const installedVersion = this.getInstalledNpmVersion(installedPath);
1165
+ if (!installedVersion) {
1166
+ return false;
1167
+ }
1168
+ const { version: pinnedVersion } = this.parseNpmSpec(source.spec);
1169
+ if (!pinnedVersion) {
1170
+ return true;
1171
+ }
1172
+ return installedVersion === pinnedVersion;
1173
+ }
1174
+ async npmHasAvailableUpdate(source, installedPath) {
1175
+ if (isOfflineModeEnabled()) {
1176
+ return false;
1177
+ }
1178
+ const installedVersion = this.getInstalledNpmVersion(installedPath);
1179
+ if (!installedVersion) {
1180
+ return false;
1181
+ }
1182
+ try {
1183
+ const latestVersion = await this.getLatestNpmVersion(source.name);
1184
+ return latestVersion !== installedVersion;
1185
+ }
1186
+ catch {
1187
+ return false;
1188
+ }
1189
+ }
1190
+ getInstalledNpmVersion(installedPath) {
1191
+ const packageJsonPath = join(installedPath, "package.json");
1192
+ if (!existsSync(packageJsonPath))
1193
+ return undefined;
1194
+ try {
1195
+ const content = readFileSync(packageJsonPath, "utf-8");
1196
+ const pkg = JSON.parse(content);
1197
+ return pkg.version;
1198
+ }
1199
+ catch {
1200
+ return undefined;
1201
+ }
1202
+ }
1203
+ async getLatestNpmVersion(packageName) {
1204
+ const npmCommand = this.getNpmCommand();
1205
+ const stdout = await this.runCommandCapture(npmCommand.command, [...npmCommand.args, "view", packageName, "version", "--json"], { cwd: this.cwd, timeoutMs: NETWORK_TIMEOUT_MS });
1206
+ const raw = stdout.trim();
1207
+ if (!raw)
1208
+ throw new Error("Empty response from npm view");
1209
+ return JSON.parse(raw);
1210
+ }
1211
+ async gitHasAvailableUpdate(installedPath) {
1212
+ if (isOfflineModeEnabled()) {
1213
+ return false;
1214
+ }
1215
+ try {
1216
+ const localHead = await this.runCommandCapture("git", ["rev-parse", "HEAD"], {
1217
+ cwd: installedPath,
1218
+ timeoutMs: NETWORK_TIMEOUT_MS,
1219
+ });
1220
+ const remoteHead = await this.getRemoteGitHead(installedPath);
1221
+ return localHead.trim() !== remoteHead.trim();
1222
+ }
1223
+ catch {
1224
+ return false;
1225
+ }
1226
+ }
1227
+ async getRemoteGitHead(installedPath) {
1228
+ const upstreamRef = await this.getGitUpstreamRef(installedPath);
1229
+ if (upstreamRef) {
1230
+ const remoteHead = await this.runGitRemoteCommand(installedPath, ["ls-remote", "origin", upstreamRef]);
1231
+ const match = remoteHead.match(/^([0-9a-f]{40})\s+/m);
1232
+ if (match?.[1]) {
1233
+ return match[1];
1234
+ }
1235
+ }
1236
+ const remoteHead = await this.runGitRemoteCommand(installedPath, ["ls-remote", "origin", "HEAD"]);
1237
+ const match = remoteHead.match(/^([0-9a-f]{40})\s+HEAD$/m);
1238
+ if (!match?.[1]) {
1239
+ throw new Error("Failed to determine remote HEAD");
1240
+ }
1241
+ return match[1];
1242
+ }
1243
+ async getLocalGitUpdateTarget(installedPath) {
1244
+ try {
1245
+ const upstream = await this.runCommandCapture("git", ["rev-parse", "--abbrev-ref", "@{upstream}"], {
1246
+ cwd: installedPath,
1247
+ timeoutMs: NETWORK_TIMEOUT_MS,
1248
+ });
1249
+ const trimmedUpstream = upstream.trim();
1250
+ if (!trimmedUpstream.startsWith("origin/")) {
1251
+ throw new Error(`Unsupported upstream remote: ${trimmedUpstream}`);
1252
+ }
1253
+ const branch = trimmedUpstream.slice("origin/".length);
1254
+ if (!branch) {
1255
+ throw new Error("Missing upstream branch name");
1256
+ }
1257
+ const head = await this.runCommandCapture("git", ["rev-parse", "@{upstream}"], {
1258
+ cwd: installedPath,
1259
+ timeoutMs: NETWORK_TIMEOUT_MS,
1260
+ });
1261
+ return {
1262
+ ref: "@{upstream}",
1263
+ head,
1264
+ fetchArgs: [
1265
+ "fetch",
1266
+ "--prune",
1267
+ "--no-tags",
1268
+ "origin",
1269
+ `+refs/heads/${branch}:refs/remotes/origin/${branch}`,
1270
+ ],
1271
+ };
1272
+ }
1273
+ catch {
1274
+ await this.runCommand("git", ["remote", "set-head", "origin", "-a"], { cwd: installedPath }).catch(() => { });
1275
+ const head = await this.runCommandCapture("git", ["rev-parse", "origin/HEAD"], {
1276
+ cwd: installedPath,
1277
+ timeoutMs: NETWORK_TIMEOUT_MS,
1278
+ });
1279
+ const originHeadRef = await this.runCommandCapture("git", ["symbolic-ref", "refs/remotes/origin/HEAD"], {
1280
+ cwd: installedPath,
1281
+ timeoutMs: NETWORK_TIMEOUT_MS,
1282
+ }).catch(() => "");
1283
+ const branch = originHeadRef.trim().replace(/^refs\/remotes\/origin\//, "");
1284
+ if (branch) {
1285
+ return {
1286
+ ref: "origin/HEAD",
1287
+ head,
1288
+ fetchArgs: [
1289
+ "fetch",
1290
+ "--prune",
1291
+ "--no-tags",
1292
+ "origin",
1293
+ `+refs/heads/${branch}:refs/remotes/origin/${branch}`,
1294
+ ],
1295
+ };
1296
+ }
1297
+ return {
1298
+ ref: "origin/HEAD",
1299
+ head,
1300
+ fetchArgs: ["fetch", "--prune", "--no-tags", "origin", "+HEAD:refs/remotes/origin/HEAD"],
1301
+ };
1302
+ }
1303
+ }
1304
+ async getGitUpstreamRef(installedPath) {
1305
+ try {
1306
+ const upstream = await this.runCommandCapture("git", ["rev-parse", "--abbrev-ref", "@{upstream}"], {
1307
+ cwd: installedPath,
1308
+ timeoutMs: NETWORK_TIMEOUT_MS,
1309
+ });
1310
+ const trimmed = upstream.trim();
1311
+ if (!trimmed.startsWith("origin/")) {
1312
+ return undefined;
1313
+ }
1314
+ const branch = trimmed.slice("origin/".length);
1315
+ return branch ? `refs/heads/${branch}` : undefined;
1316
+ }
1317
+ catch {
1318
+ return undefined;
1319
+ }
1320
+ }
1321
+ runGitRemoteCommand(installedPath, args) {
1322
+ return this.runCommandCapture("git", args, {
1323
+ cwd: installedPath,
1324
+ timeoutMs: NETWORK_TIMEOUT_MS,
1325
+ env: {
1326
+ GIT_TERMINAL_PROMPT: "0",
1327
+ },
1328
+ });
1329
+ }
1330
+ async runWithConcurrency(tasks, limit) {
1331
+ if (tasks.length === 0) {
1332
+ return [];
1333
+ }
1334
+ const results = new Array(tasks.length);
1335
+ let nextIndex = 0;
1336
+ const workerCount = Math.max(1, Math.min(limit, tasks.length));
1337
+ const worker = async () => {
1338
+ while (true) {
1339
+ const index = nextIndex;
1340
+ nextIndex += 1;
1341
+ if (index >= tasks.length) {
1342
+ return;
1343
+ }
1344
+ results[index] = await tasks[index]();
1345
+ }
1346
+ };
1347
+ await Promise.all(Array.from({ length: workerCount }, () => worker()));
1348
+ return results;
1349
+ }
1350
+ /**
1351
+ * Get a unique identity for a package, ignoring version/ref.
1352
+ * Used to detect when the same package is in both global and project settings.
1353
+ * For git packages, uses normalized host/path to ensure SSH and HTTPS URLs
1354
+ * for the same repository are treated as identical.
1355
+ */
1356
+ getPackageIdentity(source, scope) {
1357
+ const parsed = this.parseSource(source);
1358
+ if (parsed.type === "npm") {
1359
+ return `npm:${parsed.name}`;
1360
+ }
1361
+ if (parsed.type === "git") {
1362
+ // Use host/path for identity to normalize SSH and HTTPS
1363
+ return `git:${parsed.host}/${parsed.path}`;
1364
+ }
1365
+ if (scope) {
1366
+ const baseDir = this.getBaseDirForScope(scope);
1367
+ return `local:${this.resolvePathFromBase(parsed.path, baseDir)}`;
1368
+ }
1369
+ return `local:${this.resolvePath(parsed.path)}`;
1370
+ }
1371
+ /**
1372
+ * Dedupe packages: if same package identity appears in both global and project,
1373
+ * keep only the project one (project wins).
1374
+ */
1375
+ dedupePackages(packages) {
1376
+ const seen = new Map();
1377
+ for (const entry of packages) {
1378
+ const sourceStr = typeof entry.pkg === "string" ? entry.pkg : entry.pkg.source;
1379
+ const identity = this.getPackageIdentity(sourceStr, entry.scope);
1380
+ const existing = seen.get(identity);
1381
+ if (!existing) {
1382
+ seen.set(identity, entry);
1383
+ }
1384
+ else if (entry.scope === "project" && existing.scope === "user") {
1385
+ // Project wins over user
1386
+ seen.set(identity, entry);
1387
+ }
1388
+ // If existing is project and new is global, keep existing (project)
1389
+ // If both are same scope, keep first one
1390
+ }
1391
+ return Array.from(seen.values());
1392
+ }
1393
+ parseNpmSpec(spec) {
1394
+ const match = spec.match(/^(@?[^@]+(?:\/[^@]+)?)(?:@(.+))?$/);
1395
+ if (!match) {
1396
+ return { name: spec };
1397
+ }
1398
+ const name = match[1] ?? spec;
1399
+ const version = match[2];
1400
+ return { name, version };
1401
+ }
1402
+ getNpmCommand() {
1403
+ const configuredCommand = this.settingsManager.getNpmCommand();
1404
+ if (!configuredCommand || configuredCommand.length === 0) {
1405
+ return { command: "npm", args: [] };
1406
+ }
1407
+ const [command, ...args] = configuredCommand;
1408
+ if (!command) {
1409
+ throw new Error("Invalid npmCommand: first array entry must be a non-empty command");
1410
+ }
1411
+ return { command, args };
1412
+ }
1413
+ getPackageManagerName() {
1414
+ const npmCommand = this.getNpmCommand();
1415
+ const commandParts = [npmCommand.command, ...npmCommand.args];
1416
+ const separatorIndex = commandParts.lastIndexOf("--");
1417
+ const packageManagerCommand = separatorIndex >= 0 ? commandParts[separatorIndex + 1] : npmCommand.command;
1418
+ return packageManagerCommand ? basename(packageManagerCommand).replace(/\.(cmd|exe)$/i, "") : "";
1419
+ }
1420
+ async runNpmCommand(args, options) {
1421
+ const npmCommand = this.getNpmCommand();
1422
+ await this.runCommand(npmCommand.command, [...npmCommand.args, ...args], options);
1423
+ }
1424
+ getGitDependencyInstallArgs() {
1425
+ const configuredCommand = this.settingsManager.getNpmCommand();
1426
+ if (configuredCommand && configuredCommand.length > 0) {
1427
+ return ["install"];
1428
+ }
1429
+ return ["install", "--omit=dev"];
1430
+ }
1431
+ runNpmCommandSync(args) {
1432
+ const npmCommand = this.getNpmCommand();
1433
+ return this.runCommandSync(npmCommand.command, [...npmCommand.args, ...args]);
1434
+ }
1435
+ getNpmInstallArgs(specs, installRoot) {
1436
+ const packageManagerName = this.getPackageManagerName();
1437
+ // Extension packages run inside grip and resolve grip APIs through loader aliases/virtual modules.
1438
+ // Disable peer dependency resolution for managed installs (npm's --legacy-peer-deps, and
1439
+ // equivalent bun/pnpm settings) so package managers do not install or solve host-provided
1440
+ // @greppleai/grip-* peers. Stale auto-installed grip peers can otherwise block updates.
1441
+ if (packageManagerName === "bun") {
1442
+ return ["install", ...specs, "--cwd", installRoot, "--omit=peer"];
1443
+ }
1444
+ if (packageManagerName === "pnpm") {
1445
+ return [
1446
+ "install",
1447
+ ...specs,
1448
+ "--prefix",
1449
+ installRoot,
1450
+ "--config.auto-install-peers=false",
1451
+ "--config.strict-peer-dependencies=false",
1452
+ "--config.strict-dep-builds=false",
1453
+ ];
1454
+ }
1455
+ return ["install", ...specs, "--prefix", installRoot, "--legacy-peer-deps"];
1456
+ }
1457
+ async installNpm(source, scope, temporary) {
1458
+ const installRoot = this.getNpmInstallRoot(scope, temporary);
1459
+ this.ensureNpmProject(installRoot);
1460
+ await this.runNpmCommand(this.getNpmInstallArgs([source.spec], installRoot));
1461
+ }
1462
+ async uninstallNpm(source, scope) {
1463
+ const installRoot = this.getNpmInstallRoot(scope, false);
1464
+ if (!existsSync(installRoot)) {
1465
+ return;
1466
+ }
1467
+ if (this.getPackageManagerName() === "bun") {
1468
+ await this.runNpmCommand(["uninstall", source.name, "--cwd", installRoot]);
1469
+ return;
1470
+ }
1471
+ await this.runNpmCommand(["uninstall", source.name, "--prefix", installRoot]);
1472
+ }
1473
+ async installGit(source, scope) {
1474
+ const targetDir = this.getGitInstallPath(source, scope);
1475
+ if (existsSync(targetDir)) {
1476
+ this.assertGitTarget(source, scope, targetDir);
1477
+ if (source.ref) {
1478
+ await this.ensureGitRef(targetDir, ["fetch", "origin", source.ref], "FETCH_HEAD", source, scope);
1479
+ return;
1480
+ }
1481
+ const target = await this.getLocalGitUpdateTarget(targetDir);
1482
+ this.assertGitTarget(source, scope, targetDir);
1483
+ await this.ensureGitRef(targetDir, target.fetchArgs, target.ref, source, scope);
1484
+ return;
1485
+ }
1486
+ const gitRoot = this.getGitInstallRoot(scope);
1487
+ this.assertGitTarget(source, scope, targetDir);
1488
+ if (gitRoot) {
1489
+ this.ensureGitIgnore(gitRoot, true);
1490
+ }
1491
+ this.assertGitTarget(source, scope, targetDir);
1492
+ mkdirSync(dirname(targetDir), { recursive: true });
1493
+ this.assertGitTarget(source, scope, targetDir);
1494
+ await this.runCommand("git", ["clone", source.repo, targetDir]);
1495
+ this.assertGitTarget(source, scope, targetDir);
1496
+ if (source.ref) {
1497
+ await this.runCommand("git", ["checkout", source.ref], { cwd: targetDir });
1498
+ this.assertGitTarget(source, scope, targetDir);
1499
+ }
1500
+ const packageJsonPath = join(targetDir, "package.json");
1501
+ if (existsSync(packageJsonPath)) {
1502
+ this.assertConfinedResourcePath(packageJsonPath, targetDir);
1503
+ await this.runNpmCommand(this.getGitDependencyInstallArgs(), { cwd: targetDir });
1504
+ }
1505
+ }
1506
+ async updateGit(source, scope) {
1507
+ const targetDir = this.getGitInstallPath(source, scope);
1508
+ if (!existsSync(targetDir)) {
1509
+ await this.installGit(source, scope);
1510
+ return;
1511
+ }
1512
+ this.assertGitTarget(source, scope, targetDir);
1513
+ if (source.ref) {
1514
+ await this.ensureGitRef(targetDir, ["fetch", "origin", source.ref], "FETCH_HEAD", source, scope);
1515
+ return;
1516
+ }
1517
+ const target = await this.getLocalGitUpdateTarget(targetDir);
1518
+ this.assertGitTarget(source, scope, targetDir);
1519
+ await this.ensureGitRef(targetDir, target.fetchArgs, target.ref, source, scope);
1520
+ }
1521
+ async ensureGitRef(targetDir, fetchArgs, ref, source, scope) {
1522
+ // Fetch only the ref we will reset to, avoiding unrelated branch/tag noise.
1523
+ this.assertGitTarget(source, scope, targetDir);
1524
+ await this.runCommand("git", fetchArgs, { cwd: targetDir });
1525
+ this.assertGitTarget(source, scope, targetDir);
1526
+ const localHead = await this.runCommandCapture("git", ["rev-parse", "HEAD"], {
1527
+ cwd: targetDir,
1528
+ timeoutMs: NETWORK_TIMEOUT_MS,
1529
+ });
1530
+ this.assertGitTarget(source, scope, targetDir);
1531
+ const commitRef = `${ref}^{commit}`;
1532
+ const targetHead = await this.runCommandCapture("git", ["rev-parse", commitRef], {
1533
+ cwd: targetDir,
1534
+ timeoutMs: NETWORK_TIMEOUT_MS,
1535
+ });
1536
+ if (localHead.trim() === targetHead.trim()) {
1537
+ return;
1538
+ }
1539
+ this.assertGitTarget(source, scope, targetDir);
1540
+ await this.runCommand("git", ["reset", "--hard", commitRef], { cwd: targetDir });
1541
+ // Clean untracked files (extensions should be pristine)
1542
+ this.assertGitTarget(source, scope, targetDir);
1543
+ await this.runCommand("git", ["clean", "-fdx"], { cwd: targetDir });
1544
+ this.assertGitTarget(source, scope, targetDir);
1545
+ const packageJsonPath = join(targetDir, "package.json");
1546
+ if (existsSync(packageJsonPath)) {
1547
+ this.assertConfinedResourcePath(packageJsonPath, targetDir);
1548
+ await this.runNpmCommand(this.getGitDependencyInstallArgs(), { cwd: targetDir });
1549
+ }
1550
+ }
1551
+ async refreshTemporaryGitSource(source, sourceStr) {
1552
+ if (isOfflineModeEnabled()) {
1553
+ return;
1554
+ }
1555
+ try {
1556
+ await this.withProgress("pull", sourceStr, `Refreshing ${sourceStr}...`, async () => {
1557
+ await this.updateGit(source, "temporary");
1558
+ });
1559
+ }
1560
+ catch {
1561
+ // Keep cached temporary checkout if refresh fails.
1562
+ }
1563
+ }
1564
+ async removeGit(source, scope) {
1565
+ const targetDir = this.getGitInstallPath(source, scope);
1566
+ if (!existsSync(targetDir))
1567
+ return;
1568
+ this.assertGitTarget(source, scope, targetDir);
1569
+ rmSync(targetDir, { recursive: true, force: true });
1570
+ this.pruneEmptyGitParents(targetDir, this.getGitInstallRoot(scope), source, scope);
1571
+ }
1572
+ isSafeGitParentForPruning(current, targetDir, source, scope) {
1573
+ try {
1574
+ this.assertGitTarget(source, scope, targetDir);
1575
+ return !existsSync(current) || !lstatSync(current).isSymbolicLink();
1576
+ }
1577
+ catch {
1578
+ return false;
1579
+ }
1580
+ }
1581
+ pruneEmptyGitParents(targetDir, installRoot, source, scope) {
1582
+ if (!installRoot)
1583
+ return;
1584
+ const resolvedRoot = resolve(installRoot);
1585
+ let current = dirname(resolve(targetDir));
1586
+ while (current !== resolvedRoot && isPathWithin(resolvedRoot, current)) {
1587
+ if (!this.isSafeGitParentForPruning(current, targetDir, source, scope))
1588
+ break;
1589
+ if (!existsSync(current)) {
1590
+ current = dirname(current);
1591
+ continue;
1592
+ }
1593
+ const entries = readdirSync(current);
1594
+ if (entries.length > 0) {
1595
+ break;
1596
+ }
1597
+ try {
1598
+ this.assertGitTarget(source, scope, targetDir);
1599
+ this.resolveManagedPath(resolvedRoot, relative(resolvedRoot, current));
1600
+ if (lstatSync(current).isSymbolicLink()) {
1601
+ break;
1602
+ }
1603
+ rmSync(current, { recursive: true, force: true });
1604
+ }
1605
+ catch {
1606
+ break;
1607
+ }
1608
+ current = dirname(current);
1609
+ }
1610
+ }
1611
+ ensureNpmProject(installRoot) {
1612
+ if (!existsSync(installRoot)) {
1613
+ mkdirSync(installRoot, { recursive: true });
1614
+ }
1615
+ markPathIgnoredByCloudSync(installRoot);
1616
+ this.ensureGitIgnore(installRoot);
1617
+ const packageJsonPath = join(installRoot, "package.json");
1618
+ if (!existsSync(packageJsonPath)) {
1619
+ const pkgJson = { name: "grip-extensions", private: true };
1620
+ writeFileSync(packageJsonPath, JSON.stringify(pkgJson, null, 2), "utf-8");
1621
+ }
1622
+ }
1623
+ ensureGitIgnore(dir, managedGitRoot = false) {
1624
+ if (!existsSync(dir)) {
1625
+ mkdirSync(dir, { recursive: true });
1626
+ }
1627
+ const ignorePath = join(dir, ".gitignore");
1628
+ if (!managedGitRoot) {
1629
+ if (!existsSync(ignorePath)) {
1630
+ writeFileSync(ignorePath, "*\n!.gitignore\n", "utf-8");
1631
+ }
1632
+ return;
1633
+ }
1634
+ try {
1635
+ const stats = lstatSync(ignorePath);
1636
+ if (stats.isSymbolicLink()) {
1637
+ throw new Error(`Refusing symbolic link in managed Git metadata path: ${ignorePath}`);
1638
+ }
1639
+ }
1640
+ catch (error) {
1641
+ if (!isMissingPathError(error))
1642
+ throw error;
1643
+ writeFileSync(ignorePath, "*\n!.gitignore\n", "utf-8");
1644
+ }
1645
+ }
1646
+ getNpmInstallRoot(scope, temporary) {
1647
+ if (temporary) {
1648
+ return this.getTemporaryDir("npm");
1649
+ }
1650
+ if (scope === "project") {
1651
+ return join(this.cwd, CONFIG_DIR_NAME, "npm");
1652
+ }
1653
+ return join(this.agentDir, "npm");
1654
+ }
1655
+ getGlobalNpmRoot() {
1656
+ const npmCommand = this.getNpmCommand();
1657
+ const commandKey = [npmCommand.command, ...npmCommand.args].join("\0");
1658
+ if (this.globalNpmRoot && this.globalNpmRootCommandKey === commandKey) {
1659
+ return this.globalNpmRoot;
1660
+ }
1661
+ if (this.getPackageManagerName() === "bun") {
1662
+ const binDir = this.runNpmCommandSync(["pm", "bin", "-g"]).trim();
1663
+ this.globalNpmRoot = join(dirname(binDir), "install", "global", "node_modules");
1664
+ }
1665
+ else {
1666
+ this.globalNpmRoot = this.runNpmCommandSync(["root", "-g"]).trim();
1667
+ }
1668
+ this.globalNpmRootCommandKey = commandKey;
1669
+ return this.globalNpmRoot;
1670
+ }
1671
+ getPnpmGlobalPackagePath(packageName) {
1672
+ if (this.getPackageManagerName() !== "pnpm") {
1673
+ return undefined;
1674
+ }
1675
+ const output = this.runNpmCommandSync(["list", "-g", "--depth", "0", "--json"]);
1676
+ const entries = JSON.parse(output);
1677
+ for (const entry of entries) {
1678
+ const path = entry.dependencies?.[packageName]?.path;
1679
+ if (path)
1680
+ return path;
1681
+ }
1682
+ return undefined;
1683
+ }
1684
+ getManagedNpmInstallPath(source, scope) {
1685
+ if (scope === "temporary") {
1686
+ return join(this.getTemporaryDir("npm"), "node_modules", source.name);
1687
+ }
1688
+ if (scope === "project") {
1689
+ return join(this.cwd, CONFIG_DIR_NAME, "npm", "node_modules", source.name);
1690
+ }
1691
+ return join(this.agentDir, "npm", "node_modules", source.name);
1692
+ }
1693
+ getLegacyGlobalNpmInstallPath(source) {
1694
+ try {
1695
+ return this.getPnpmGlobalPackagePath(source.name) ?? join(this.getGlobalNpmRoot(), source.name);
1696
+ }
1697
+ catch {
1698
+ return undefined;
1699
+ }
1700
+ }
1701
+ getNpmInstallPath(source, scope) {
1702
+ const managedPath = this.getManagedNpmInstallPath(source, scope);
1703
+ if (scope !== "user" || existsSync(managedPath)) {
1704
+ return managedPath;
1705
+ }
1706
+ const legacyPath = this.getLegacyGlobalNpmInstallPath(source);
1707
+ return legacyPath && existsSync(legacyPath) ? legacyPath : managedPath;
1708
+ }
1709
+ getGitInstallPath(source, scope) {
1710
+ if (!isSafeGitInstallPath(source)) {
1711
+ throw new Error(`Refusing unsafe Git package path: ${source.host}/${source.path}`);
1712
+ }
1713
+ let targetDir;
1714
+ if (scope === "temporary") {
1715
+ targetDir = this.getTemporaryDir(`git-${source.host}`, source.path);
1716
+ }
1717
+ else {
1718
+ const installRoot = this.getGitInstallRoot(scope);
1719
+ if (!installRoot) {
1720
+ throw new Error("Missing Git install root");
1721
+ }
1722
+ targetDir = this.resolveManagedPath(installRoot, source.host, source.path);
1723
+ }
1724
+ this.assertManagedGitPath(source, scope, targetDir);
1725
+ return targetDir;
1726
+ }
1727
+ getGitInstallRoot(scope) {
1728
+ if (scope === "temporary") {
1729
+ return undefined;
1730
+ }
1731
+ if (scope === "project") {
1732
+ return join(this.cwd, CONFIG_DIR_NAME, "git");
1733
+ }
1734
+ return join(this.agentDir, "git");
1735
+ }
1736
+ getGitConfinementRoot(scope) {
1737
+ return scope === "temporary" ? join(tmpdir(), "grip-extensions") : (this.getGitInstallRoot(scope) ?? "");
1738
+ }
1739
+ getGitScopeAnchor(scope) {
1740
+ if (scope === "temporary")
1741
+ return tmpdir();
1742
+ return scope === "project" ? this.cwd : this.agentDir;
1743
+ }
1744
+ getTemporaryDir(prefix, suffix) {
1745
+ const root = this.resolveManagedPath(join(tmpdir(), "grip-extensions"), prefix);
1746
+ const hash = createHash("sha256")
1747
+ .update(`${prefix}-${suffix ?? ""}`)
1748
+ .digest("hex")
1749
+ .slice(0, 8);
1750
+ return this.resolveManagedPath(root, hash, suffix ?? "");
1751
+ }
1752
+ resolveManagedPath(root, ...parts) {
1753
+ const resolvedRoot = resolve(root);
1754
+ const resolvedPath = resolve(resolvedRoot, ...parts);
1755
+ if (!isPathWithin(resolvedRoot, resolvedPath)) {
1756
+ throw new Error(`Refusing to use path outside package install root: ${resolvedPath}`);
1757
+ }
1758
+ return resolvedPath;
1759
+ }
1760
+ canonicalizeProspectivePath(path) {
1761
+ let current = resolve(path);
1762
+ const missingParts = [];
1763
+ while (true) {
1764
+ try {
1765
+ lstatSync(current);
1766
+ }
1767
+ catch (error) {
1768
+ if (!isMissingPathError(error)) {
1769
+ throw error;
1770
+ }
1771
+ const parent = dirname(current);
1772
+ if (parent === current) {
1773
+ throw error;
1774
+ }
1775
+ missingParts.unshift(basename(current));
1776
+ current = parent;
1777
+ continue;
1778
+ }
1779
+ return resolve(realpathSync(current), ...missingParts);
1780
+ }
1781
+ }
1782
+ assertManagedGitPath(source, scope, targetDir) {
1783
+ if (!isSafeGitInstallPath(source)) {
1784
+ throw new Error(`Refusing unsafe Git package path: ${source.host}/${source.path}`);
1785
+ }
1786
+ const anchor = resolve(this.getGitScopeAnchor(scope));
1787
+ const root = resolve(this.getGitConfinementRoot(scope));
1788
+ const target = resolve(targetDir);
1789
+ if (!isPathWithin(anchor, root) || !isPathWithin(root, target)) {
1790
+ throw new Error(`Refusing to use path outside package install root: ${target}`);
1791
+ }
1792
+ let canonicalAnchor;
1793
+ let canonicalRoot;
1794
+ try {
1795
+ canonicalAnchor = this.canonicalizeProspectivePath(anchor);
1796
+ canonicalRoot = this.canonicalizeProspectivePath(root);
1797
+ }
1798
+ catch {
1799
+ throw new Error(`Refusing unsafe Git package install root: ${root}`);
1800
+ }
1801
+ if (!isPathWithin(canonicalAnchor, canonicalRoot)) {
1802
+ throw new Error(`Refusing Git package install root outside its trusted anchor: ${root}`);
1803
+ }
1804
+ const relativeTarget = relative(root, target);
1805
+ let current = canonicalRoot;
1806
+ for (const component of relativeTarget.split(sep).filter(Boolean)) {
1807
+ current = join(current, component);
1808
+ try {
1809
+ const stats = lstatSync(current);
1810
+ if (stats.isSymbolicLink()) {
1811
+ throw new Error(`Refusing symbolic link in Git package path: ${current}`);
1812
+ }
1813
+ }
1814
+ catch (error) {
1815
+ if (isMissingPathError(error)) {
1816
+ break;
1817
+ }
1818
+ throw error;
1819
+ }
1820
+ }
1821
+ }
1822
+ assertGitTarget(source, scope, targetDir) {
1823
+ const expected = this.getGitInstallPath(source, scope);
1824
+ if (expected !== resolve(targetDir)) {
1825
+ throw new Error(`Refusing unexpected Git package path: ${targetDir}`);
1826
+ }
1827
+ }
1828
+ getBaseDirForScope(scope) {
1829
+ if (scope === "project") {
1830
+ return join(this.cwd, CONFIG_DIR_NAME);
1831
+ }
1832
+ if (scope === "user") {
1833
+ return this.agentDir;
1834
+ }
1835
+ return this.cwd;
1836
+ }
1837
+ resolvePath(input) {
1838
+ return resolvePath(input, this.cwd, { homeDir: getHomeDir(), trim: true });
1839
+ }
1840
+ resolvePathFromBase(input, baseDir) {
1841
+ return resolvePath(input, baseDir, { homeDir: getHomeDir(), trim: true });
1842
+ }
1843
+ assertConfinedResourcePath(candidate, packageRoot) {
1844
+ let canonicalRoot;
1845
+ let canonicalCandidate;
1846
+ try {
1847
+ canonicalRoot = realpathSync(packageRoot);
1848
+ canonicalCandidate = realpathSync(candidate);
1849
+ }
1850
+ catch {
1851
+ throw new Error(`Refusing unreadable or broken managed Git package resource: ${candidate}`);
1852
+ }
1853
+ if (!isPathWithin(canonicalRoot, canonicalCandidate)) {
1854
+ throw new Error(`Refusing managed Git package resource outside checkout: ${candidate}`);
1855
+ }
1856
+ }
1857
+ validateConfinedResourceTree(candidate, packageRoot, visited = new Set()) {
1858
+ lstatSync(candidate);
1859
+ this.assertConfinedResourcePath(candidate, packageRoot);
1860
+ const canonicalCandidate = realpathSync(candidate);
1861
+ const stats = statSync(candidate);
1862
+ if (!stats.isDirectory() || visited.has(canonicalCandidate))
1863
+ return;
1864
+ visited.add(canonicalCandidate);
1865
+ for (const entry of readdirSync(candidate, { withFileTypes: true })) {
1866
+ if (entry.name === "node_modules")
1867
+ continue;
1868
+ if (entry.name.startsWith(".") && !IGNORE_FILE_NAMES.has(entry.name))
1869
+ continue;
1870
+ this.validateConfinedResourceTree(join(candidate, entry.name), packageRoot, visited);
1871
+ }
1872
+ }
1873
+ validateOptionalConfinedResourcePath(candidate, packageRoot) {
1874
+ try {
1875
+ lstatSync(candidate);
1876
+ this.assertConfinedResourcePath(candidate, packageRoot);
1877
+ }
1878
+ catch (error) {
1879
+ if (!isMissingPathError(error))
1880
+ throw error;
1881
+ }
1882
+ }
1883
+ validateOptionalConfinedResourceTree(candidate, packageRoot) {
1884
+ try {
1885
+ this.validateConfinedResourceTree(candidate, packageRoot);
1886
+ }
1887
+ catch (error) {
1888
+ if (!isMissingPathError(error))
1889
+ throw error;
1890
+ }
1891
+ }
1892
+ validateManagedGitManifestEntry(entry, packageRoot) {
1893
+ if (entry.includes("\\") || /^[a-z]:/i.test(entry)) {
1894
+ throw new Error(`Refusing unsafe managed Git package resource entry: ${entry}`);
1895
+ }
1896
+ this.resolveManagedPath(packageRoot, entry);
1897
+ const entryParts = entry.split("/");
1898
+ const firstGlobPart = entryParts.findIndex((part) => hasGlobPattern(part));
1899
+ const scanEntry = firstGlobPart < 0 ? entry : entryParts.slice(0, firstGlobPart).join("/") || ".";
1900
+ this.validateOptionalConfinedResourceTree(resolve(packageRoot, scanEntry), packageRoot);
1901
+ if (firstGlobPart < 0)
1902
+ return;
1903
+ for (const match of globSync(entry, {
1904
+ cwd: packageRoot,
1905
+ absolute: true,
1906
+ dot: false,
1907
+ follow: false,
1908
+ nodir: false,
1909
+ })) {
1910
+ this.validateConfinedResourceTree(resolve(match), packageRoot);
1911
+ }
1912
+ }
1913
+ validateManagedGitManifestResources(manifest, packageRoot) {
1914
+ for (const resourceType of RESOURCE_TYPES) {
1915
+ const entries = manifest[resourceType];
1916
+ if (!Array.isArray(entries))
1917
+ continue;
1918
+ for (const entry of entries) {
1919
+ if (typeof entry !== "string" || isOverridePattern(entry))
1920
+ continue;
1921
+ this.validateManagedGitManifestEntry(entry, packageRoot);
1922
+ }
1923
+ }
1924
+ }
1925
+ validateManagedGitResourceInputs(packageRoot) {
1926
+ this.assertConfinedResourcePath(packageRoot, packageRoot);
1927
+ const packageJsonPath = join(packageRoot, "package.json");
1928
+ this.validateOptionalConfinedResourcePath(packageJsonPath, packageRoot);
1929
+ for (const resourceType of RESOURCE_TYPES) {
1930
+ this.validateOptionalConfinedResourceTree(join(packageRoot, resourceType), packageRoot);
1931
+ }
1932
+ const manifest = readGripManifest(packageJsonPath);
1933
+ if (manifest)
1934
+ this.validateManagedGitManifestResources(manifest, packageRoot);
1935
+ }
1936
+ collectManagedGitPackageResources(packageRoot, accumulator, filter, metadata) {
1937
+ this.validateManagedGitResourceInputs(packageRoot);
1938
+ const packageAccumulator = this.createAccumulator();
1939
+ this.collectPackageResources(packageRoot, packageAccumulator, filter, metadata);
1940
+ for (const resourceType of RESOURCE_TYPES) {
1941
+ const sourceMap = this.getTargetMap(packageAccumulator, resourceType);
1942
+ const targetMap = this.getTargetMap(accumulator, resourceType);
1943
+ for (const [path, value] of sourceMap) {
1944
+ this.assertConfinedResourcePath(path, packageRoot);
1945
+ this.addResource(targetMap, path, value.metadata, value.enabled);
1946
+ }
1947
+ }
1948
+ }
1949
+ collectPackageResources(packageRoot, accumulator, filter, metadata) {
1950
+ if (filter) {
1951
+ for (const resourceType of RESOURCE_TYPES) {
1952
+ const patterns = filter[resourceType];
1953
+ const target = this.getTargetMap(accumulator, resourceType);
1954
+ if (patterns !== undefined) {
1955
+ this.applyPackageFilter(packageRoot, patterns, resourceType, target, metadata);
1956
+ }
1957
+ else {
1958
+ this.collectDefaultResources(packageRoot, resourceType, target, metadata);
1959
+ }
1960
+ }
1961
+ return true;
1962
+ }
1963
+ const manifest = readGripManifest(join(packageRoot, "package.json"));
1964
+ if (manifest) {
1965
+ for (const resourceType of RESOURCE_TYPES) {
1966
+ const entries = manifest[resourceType];
1967
+ this.addManifestEntries(entries, packageRoot, resourceType, this.getTargetMap(accumulator, resourceType), metadata);
1968
+ }
1969
+ return true;
1970
+ }
1971
+ let hasAnyDir = false;
1972
+ for (const resourceType of RESOURCE_TYPES) {
1973
+ const dir = join(packageRoot, resourceType);
1974
+ if (!existsSync(dir))
1975
+ continue;
1976
+ // Collect all files from the directory (all enabled by default)
1977
+ const files = collectResourceFiles(dir, resourceType);
1978
+ for (const f of files) {
1979
+ this.addResource(this.getTargetMap(accumulator, resourceType), f, metadata, true);
1980
+ }
1981
+ hasAnyDir = true;
1982
+ }
1983
+ return hasAnyDir;
1984
+ }
1985
+ collectDefaultResources(packageRoot, resourceType, target, metadata) {
1986
+ const manifest = readGripManifest(join(packageRoot, "package.json"));
1987
+ const entries = manifest?.[resourceType];
1988
+ if (entries) {
1989
+ this.addManifestEntries(entries, packageRoot, resourceType, target, metadata);
1990
+ return;
1991
+ }
1992
+ const dir = join(packageRoot, resourceType);
1993
+ if (existsSync(dir)) {
1994
+ // Collect all files from the directory (all enabled by default)
1995
+ const files = collectResourceFiles(dir, resourceType);
1996
+ for (const f of files) {
1997
+ this.addResource(target, f, metadata, true);
1998
+ }
1999
+ }
2000
+ }
2001
+ applyPackageFilter(packageRoot, userPatterns, resourceType, target, metadata) {
2002
+ const { allFiles } = this.collectManifestFiles(packageRoot, resourceType);
2003
+ if (userPatterns.length === 0) {
2004
+ // Empty array explicitly disables all resources of this type
2005
+ for (const f of allFiles) {
2006
+ this.addResource(target, f, metadata, false);
2007
+ }
2008
+ return;
2009
+ }
2010
+ // Apply user patterns
2011
+ const enabledByUser = applyPatterns(allFiles, userPatterns, packageRoot);
2012
+ for (const f of allFiles) {
2013
+ const enabled = enabledByUser.has(f);
2014
+ this.addResource(target, f, metadata, enabled);
2015
+ }
2016
+ }
2017
+ /**
2018
+ * Collect all files from a package for a resource type, applying manifest patterns.
2019
+ * Returns { allFiles, enabledByManifest } where enabledByManifest is the set of files
2020
+ * that pass the manifest's own patterns.
2021
+ */
2022
+ collectManifestFiles(packageRoot, resourceType) {
2023
+ const manifest = readGripManifest(join(packageRoot, "package.json"));
2024
+ const entries = manifest?.[resourceType];
2025
+ if (entries && entries.length > 0) {
2026
+ const allFiles = this.collectFilesFromManifestEntries(entries, packageRoot, resourceType);
2027
+ const manifestPatterns = entries.filter(isOverridePattern);
2028
+ const enabledByManifest = manifestPatterns.length > 0 ? applyPatterns(allFiles, manifestPatterns, packageRoot) : new Set(allFiles);
2029
+ return { allFiles: Array.from(enabledByManifest), enabledByManifest };
2030
+ }
2031
+ const conventionDir = join(packageRoot, resourceType);
2032
+ if (!existsSync(conventionDir)) {
2033
+ return { allFiles: [], enabledByManifest: new Set() };
2034
+ }
2035
+ const allFiles = collectResourceFiles(conventionDir, resourceType);
2036
+ return { allFiles, enabledByManifest: new Set(allFiles) };
2037
+ }
2038
+ addManifestEntries(entries, root, resourceType, target, metadata) {
2039
+ if (!entries)
2040
+ return;
2041
+ const allFiles = this.collectFilesFromManifestEntries(entries, root, resourceType);
2042
+ const patterns = entries.filter(isOverridePattern);
2043
+ const enabledPaths = applyPatterns(allFiles, patterns, root);
2044
+ for (const f of allFiles) {
2045
+ if (enabledPaths.has(f)) {
2046
+ this.addResource(target, f, metadata, true);
2047
+ }
2048
+ }
2049
+ }
2050
+ collectFilesFromManifestEntries(entries, root, resourceType) {
2051
+ const sourceEntries = entries.filter((entry) => !isOverridePattern(entry));
2052
+ const resolved = sourceEntries.flatMap((entry) => {
2053
+ if (!hasGlobPattern(entry)) {
2054
+ return [resolve(root, entry)];
2055
+ }
2056
+ return globSync(entry, {
2057
+ cwd: root,
2058
+ absolute: true,
2059
+ dot: false,
2060
+ follow: false,
2061
+ nodir: false,
2062
+ }).map((match) => resolve(match));
2063
+ });
2064
+ return this.collectFilesFromPaths(resolved, resourceType);
2065
+ }
2066
+ resolveLocalEntries(entries, resourceType, target, metadata, baseDir) {
2067
+ if (entries.length === 0)
2068
+ return;
2069
+ // Collect all files from plain entries (non-pattern entries)
2070
+ const { plain, patterns } = splitPatterns(entries);
2071
+ const resolvedPlain = plain.map((p) => this.resolvePathFromBase(p, baseDir));
2072
+ const allFiles = this.collectFilesFromPaths(resolvedPlain, resourceType);
2073
+ // Determine which files are enabled based on patterns
2074
+ const enabledPaths = applyPatterns(allFiles, patterns, baseDir);
2075
+ // Add all files with their enabled state
2076
+ for (const f of allFiles) {
2077
+ this.addResource(target, f, metadata, enabledPaths.has(f));
2078
+ }
2079
+ }
2080
+ addAutoDiscoveredResources(accumulator, globalSettings, projectSettings, globalBaseDir, projectBaseDir) {
2081
+ const userMetadata = {
2082
+ source: "auto",
2083
+ scope: "user",
2084
+ origin: "top-level",
2085
+ baseDir: globalBaseDir,
2086
+ };
2087
+ const projectMetadata = {
2088
+ source: "auto",
2089
+ scope: "project",
2090
+ origin: "top-level",
2091
+ baseDir: projectBaseDir,
2092
+ };
2093
+ const userOverrides = {
2094
+ extensions: (globalSettings.extensions ?? []),
2095
+ skills: (globalSettings.skills ?? []),
2096
+ rules: (globalSettings.rules ?? []),
2097
+ prompts: (globalSettings.prompts ?? []),
2098
+ themes: (globalSettings.themes ?? []),
2099
+ };
2100
+ const projectOverrides = {
2101
+ extensions: (projectSettings.extensions ?? []),
2102
+ skills: (projectSettings.skills ?? []),
2103
+ rules: (projectSettings.rules ?? []),
2104
+ prompts: (projectSettings.prompts ?? []),
2105
+ themes: (projectSettings.themes ?? []),
2106
+ };
2107
+ const userDirs = {
2108
+ extensions: join(globalBaseDir, "extensions"),
2109
+ skills: join(globalBaseDir, "skills"),
2110
+ rules: join(globalBaseDir, "rules"),
2111
+ prompts: join(globalBaseDir, "prompts"),
2112
+ themes: join(globalBaseDir, "themes"),
2113
+ };
2114
+ const projectDirs = {
2115
+ extensions: join(projectBaseDir, "extensions"),
2116
+ skills: join(projectBaseDir, "skills"),
2117
+ rules: join(projectBaseDir, "rules"),
2118
+ prompts: join(projectBaseDir, "prompts"),
2119
+ themes: join(projectBaseDir, "themes"),
2120
+ };
2121
+ const userAgentsSkillsDir = join(getHomeDir(), ".agents", "skills");
2122
+ const userAgentsRulesDir = join(getHomeDir(), ".agents", "rules");
2123
+ const projectAgentsSkillDirs = collectAncestorAgentsSkillDirs(this.cwd).filter((dir) => resolve(dir) !== resolve(userAgentsSkillsDir));
2124
+ const projectAgentsRuleDirs = collectAncestorAgentsRuleDirs(this.cwd).filter((dir) => resolve(dir) !== resolve(userAgentsRulesDir));
2125
+ const addResources = (resourceType, paths, metadata, overrides, baseDir) => {
2126
+ const target = this.getTargetMap(accumulator, resourceType);
2127
+ for (const path of paths) {
2128
+ const enabled = isEnabledByOverrides(path, overrides, baseDir);
2129
+ this.addResource(target, path, metadata, enabled);
2130
+ }
2131
+ };
2132
+ // Project extensions from .grip/
2133
+ addResources("extensions", collectAutoExtensionEntries(projectDirs.extensions), projectMetadata, projectOverrides.extensions, projectBaseDir);
2134
+ // Project skills from .grip/
2135
+ addResources("skills", collectAutoSkillEntries(projectDirs.skills, "grip"), projectMetadata, projectOverrides.skills, projectBaseDir);
2136
+ // Project rules from .grip/
2137
+ addResources("rules", collectAutoRuleEntries(projectDirs.rules, "grip"), projectMetadata, projectOverrides.rules, projectBaseDir);
2138
+ // Project skills from .agents/ (each with its own baseDir)
2139
+ for (const agentsSkillsDir of projectAgentsSkillDirs) {
2140
+ const agentsBaseDir = dirname(agentsSkillsDir); // the .agents directory
2141
+ const agentsMetadata = {
2142
+ ...projectMetadata,
2143
+ baseDir: agentsBaseDir,
2144
+ };
2145
+ addResources("skills", collectAutoSkillEntries(agentsSkillsDir, "agents"), agentsMetadata, projectOverrides.skills, agentsBaseDir);
2146
+ }
2147
+ // Project rules from .agents/ (each with its own baseDir)
2148
+ for (const agentsRulesDir of projectAgentsRuleDirs) {
2149
+ const agentsBaseDir = dirname(agentsRulesDir); // the .agents directory
2150
+ const agentsMetadata = {
2151
+ ...projectMetadata,
2152
+ baseDir: agentsBaseDir,
2153
+ };
2154
+ addResources("rules", collectAutoRuleEntries(agentsRulesDir, "agents"), agentsMetadata, projectOverrides.rules, agentsBaseDir);
2155
+ }
2156
+ addResources("prompts", collectAutoPromptEntries(projectDirs.prompts), projectMetadata, projectOverrides.prompts, projectBaseDir);
2157
+ addResources("themes", collectAutoThemeEntries(projectDirs.themes), projectMetadata, projectOverrides.themes, projectBaseDir);
2158
+ // User extensions from ~/.grip/agent/
2159
+ addResources("extensions", collectAutoExtensionEntries(userDirs.extensions), userMetadata, userOverrides.extensions, globalBaseDir);
2160
+ // User skills from ~/.grip/agent/
2161
+ addResources("skills", collectAutoSkillEntries(userDirs.skills, "grip"), userMetadata, userOverrides.skills, globalBaseDir);
2162
+ // User rules from ~/.grip/agent/
2163
+ addResources("rules", collectAutoRuleEntries(userDirs.rules, "grip"), userMetadata, userOverrides.rules, globalBaseDir);
2164
+ // User skills from ~/.agents/ (with its own baseDir)
2165
+ const userAgentsBaseDir = dirname(userAgentsSkillsDir);
2166
+ const userAgentsMetadata = {
2167
+ ...userMetadata,
2168
+ baseDir: userAgentsBaseDir,
2169
+ };
2170
+ addResources("skills", collectAutoSkillEntries(userAgentsSkillsDir, "agents"), userAgentsMetadata, userOverrides.skills, userAgentsBaseDir);
2171
+ // User rules from ~/.agents/ (with its own baseDir)
2172
+ const userAgentsRulesBaseDir = dirname(userAgentsRulesDir);
2173
+ const userAgentsRulesMetadata = {
2174
+ ...userMetadata,
2175
+ baseDir: userAgentsRulesBaseDir,
2176
+ };
2177
+ addResources("rules", collectAutoRuleEntries(userAgentsRulesDir, "agents"), userAgentsRulesMetadata, userOverrides.rules, userAgentsRulesBaseDir);
2178
+ addResources("prompts", collectAutoPromptEntries(userDirs.prompts), userMetadata, userOverrides.prompts, globalBaseDir);
2179
+ addResources("themes", collectAutoThemeEntries(userDirs.themes), userMetadata, userOverrides.themes, globalBaseDir);
2180
+ }
2181
+ collectFilesFromPaths(paths, resourceType) {
2182
+ const files = [];
2183
+ for (const p of paths) {
2184
+ if (!existsSync(p))
2185
+ continue;
2186
+ try {
2187
+ const stats = statSync(p);
2188
+ if (stats.isFile()) {
2189
+ files.push(p);
2190
+ }
2191
+ else if (stats.isDirectory()) {
2192
+ files.push(...collectResourceFiles(p, resourceType));
2193
+ }
2194
+ }
2195
+ catch {
2196
+ // Ignore errors
2197
+ }
2198
+ }
2199
+ return files;
2200
+ }
2201
+ getTargetMap(accumulator, resourceType) {
2202
+ switch (resourceType) {
2203
+ case "extensions":
2204
+ return accumulator.extensions;
2205
+ case "skills":
2206
+ return accumulator.skills;
2207
+ case "rules":
2208
+ return accumulator.rules;
2209
+ case "prompts":
2210
+ return accumulator.prompts;
2211
+ case "themes":
2212
+ return accumulator.themes;
2213
+ default:
2214
+ throw new Error(`Unknown resource type: ${resourceType}`);
2215
+ }
2216
+ }
2217
+ addResource(map, path, metadata, enabled) {
2218
+ if (!path)
2219
+ return;
2220
+ if (!map.has(path)) {
2221
+ map.set(path, { metadata, enabled });
2222
+ }
2223
+ }
2224
+ createAccumulator() {
2225
+ return {
2226
+ extensions: new Map(),
2227
+ skills: new Map(),
2228
+ rules: new Map(),
2229
+ prompts: new Map(),
2230
+ themes: new Map(),
2231
+ };
2232
+ }
2233
+ toResolvedPaths(accumulator) {
2234
+ const mapToResolved = (entries) => {
2235
+ const resolved = Array.from(entries.entries()).map(([path, { metadata, enabled }]) => ({
2236
+ path,
2237
+ enabled,
2238
+ metadata,
2239
+ }));
2240
+ resolved.sort((a, b) => resourcePrecedenceRank(a.metadata) - resourcePrecedenceRank(b.metadata));
2241
+ const seen = new Set();
2242
+ return resolved.filter((entry) => {
2243
+ const canonicalPath = canonicalizePath(entry.path);
2244
+ if (seen.has(canonicalPath))
2245
+ return false;
2246
+ seen.add(canonicalPath);
2247
+ return true;
2248
+ });
2249
+ };
2250
+ return {
2251
+ extensions: mapToResolved(accumulator.extensions),
2252
+ skills: mapToResolved(accumulator.skills),
2253
+ rules: mapToResolved(accumulator.rules),
2254
+ prompts: mapToResolved(accumulator.prompts),
2255
+ themes: mapToResolved(accumulator.themes),
2256
+ };
2257
+ }
2258
+ spawnCommand(command, args, options) {
2259
+ const env = getEnv();
2260
+ return spawnProcess(command, args, {
2261
+ cwd: options?.cwd,
2262
+ stdio: isStdoutTakenOver() ? ["ignore", 2, 2] : "inherit",
2263
+ env,
2264
+ });
2265
+ }
2266
+ spawnCaptureCommand(command, args, options) {
2267
+ const baseEnv = getEnv();
2268
+ const env = options?.env ? { ...baseEnv, ...options.env } : baseEnv;
2269
+ return spawnProcess(command, args, {
2270
+ cwd: options?.cwd,
2271
+ stdio: ["ignore", "pipe", "pipe"],
2272
+ env,
2273
+ });
2274
+ }
2275
+ runCommandCapture(command, args, options) {
2276
+ return new Promise((resolvePromise, reject) => {
2277
+ const child = this.spawnCaptureCommand(command, args, options);
2278
+ let stdout = "";
2279
+ let stderr = "";
2280
+ let timedOut = false;
2281
+ const timeout = typeof options?.timeoutMs === "number"
2282
+ ? setTimeout(() => {
2283
+ timedOut = true;
2284
+ child.kill();
2285
+ }, options.timeoutMs)
2286
+ : undefined;
2287
+ child.stdout?.on("data", (data) => {
2288
+ stdout += data.toString();
2289
+ });
2290
+ child.stderr?.on("data", (data) => {
2291
+ stderr += data.toString();
2292
+ });
2293
+ child.once("error", (error) => {
2294
+ if (timeout)
2295
+ clearTimeout(timeout);
2296
+ reject(error);
2297
+ });
2298
+ child.once("close", (code, signal) => {
2299
+ if (timeout)
2300
+ clearTimeout(timeout);
2301
+ if (timedOut) {
2302
+ reject(new Error(`${command} ${args.join(" ")} timed out after ${options?.timeoutMs}ms`));
2303
+ return;
2304
+ }
2305
+ if (code === 0) {
2306
+ resolvePromise(stdout.trim());
2307
+ return;
2308
+ }
2309
+ const exitStatus = code === null ? `signal ${signal ?? "unknown"}` : `code ${code}`;
2310
+ reject(new Error(`${command} ${args.join(" ")} failed with ${exitStatus}: ${stderr || stdout}`));
2311
+ });
2312
+ });
2313
+ }
2314
+ runCommand(command, args, options) {
2315
+ return new Promise((resolvePromise, reject) => {
2316
+ const child = this.spawnCommand(command, args, options);
2317
+ child.on("error", reject);
2318
+ child.on("exit", (code) => {
2319
+ if (code === 0) {
2320
+ resolvePromise();
2321
+ }
2322
+ else {
2323
+ reject(new Error(`${command} ${args.join(" ")} failed with code ${code}`));
2324
+ }
2325
+ });
2326
+ });
2327
+ }
2328
+ runCommandSync(command, args) {
2329
+ const env = getEnv();
2330
+ const result = spawnProcessSync(command, args, {
2331
+ stdio: ["ignore", "pipe", "pipe"],
2332
+ encoding: "utf-8",
2333
+ env,
2334
+ });
2335
+ if (result.error || result.status !== 0) {
2336
+ throw new Error(`Failed to run ${command} ${args.join(" ")}: ${result.error?.message || result.stderr || result.stdout}`);
2337
+ }
2338
+ return (result.stdout || result.stderr || "").trim();
2339
+ }
2340
+ }
2341
+ //# sourceMappingURL=package-manager.js.map