@ai-primitives-hub/app 0.2.0 → 0.2.2-next.0

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 (325) hide show
  1. package/README.md +5 -1
  2. package/dist/collection/affected-collections.d.ts +11 -0
  3. package/dist/collection/affected-collections.d.ts.map +1 -0
  4. package/dist/collection/affected-collections.js +90 -0
  5. package/dist/collection/affected-collections.js.map +1 -0
  6. package/dist/collection/create-plugin.d.ts +35 -0
  7. package/dist/collection/create-plugin.d.ts.map +1 -0
  8. package/dist/collection/create-plugin.js +118 -0
  9. package/dist/collection/create-plugin.js.map +1 -0
  10. package/dist/collection/index.d.ts +4 -2
  11. package/dist/collection/index.d.ts.map +1 -1
  12. package/dist/collection/index.js +8 -4
  13. package/dist/collection/index.js.map +1 -1
  14. package/dist/collection/kind-route-warning.d.ts +13 -0
  15. package/dist/collection/kind-route-warning.d.ts.map +1 -0
  16. package/dist/collection/kind-route-warning.js +40 -0
  17. package/dist/collection/kind-route-warning.js.map +1 -0
  18. package/dist/collection/plugin-item-issues.d.ts +36 -0
  19. package/dist/collection/plugin-item-issues.d.ts.map +1 -0
  20. package/dist/collection/plugin-item-issues.js +31 -0
  21. package/dist/collection/plugin-item-issues.js.map +1 -0
  22. package/dist/collection/read-collection.d.ts +1 -1
  23. package/dist/collection/read-collection.d.ts.map +1 -1
  24. package/dist/collection/read-collection.js +14 -15
  25. package/dist/collection/read-collection.js.map +1 -1
  26. package/dist/collection-editor/collection-contribution-workflow.d.ts +96 -0
  27. package/dist/collection-editor/collection-contribution-workflow.d.ts.map +1 -0
  28. package/dist/collection-editor/collection-contribution-workflow.js +479 -0
  29. package/dist/collection-editor/collection-contribution-workflow.js.map +1 -0
  30. package/dist/collection-editor/collection-editor-service.d.ts +232 -0
  31. package/dist/collection-editor/collection-editor-service.d.ts.map +1 -0
  32. package/dist/collection-editor/collection-editor-service.js +868 -0
  33. package/dist/collection-editor/collection-editor-service.js.map +1 -0
  34. package/dist/collection-editor/index.d.ts +7 -0
  35. package/dist/collection-editor/index.d.ts.map +1 -0
  36. package/dist/collection-editor/index.js +12 -0
  37. package/dist/collection-editor/index.js.map +1 -0
  38. package/dist/diagnostics/find-ancestor-file.d.ts +13 -0
  39. package/dist/diagnostics/find-ancestor-file.d.ts.map +1 -0
  40. package/dist/diagnostics/find-ancestor-file.js +85 -0
  41. package/dist/diagnostics/find-ancestor-file.js.map +1 -0
  42. package/dist/diagnostics/index.d.ts +10 -0
  43. package/dist/diagnostics/index.d.ts.map +1 -0
  44. package/dist/diagnostics/index.js +26 -0
  45. package/dist/diagnostics/index.js.map +1 -0
  46. package/dist/diagnostics/run-primitive-diagnostics.d.ts +43 -0
  47. package/dist/diagnostics/run-primitive-diagnostics.d.ts.map +1 -0
  48. package/dist/diagnostics/run-primitive-diagnostics.js +413 -0
  49. package/dist/diagnostics/run-primitive-diagnostics.js.map +1 -0
  50. package/dist/diagnostics/sandbox-snapshot.d.ts +20 -0
  51. package/dist/diagnostics/sandbox-snapshot.d.ts.map +1 -0
  52. package/dist/diagnostics/sandbox-snapshot.js +117 -0
  53. package/dist/diagnostics/sandbox-snapshot.js.map +1 -0
  54. package/dist/governance/generate-catalogue.d.ts +16 -0
  55. package/dist/governance/generate-catalogue.d.ts.map +1 -0
  56. package/dist/governance/generate-catalogue.js +67 -0
  57. package/dist/governance/generate-catalogue.js.map +1 -0
  58. package/dist/governance/hub-scoped-governance.d.ts +37 -0
  59. package/dist/governance/hub-scoped-governance.d.ts.map +1 -0
  60. package/dist/governance/hub-scoped-governance.js +110 -0
  61. package/dist/governance/hub-scoped-governance.js.map +1 -0
  62. package/dist/governance/index.d.ts +10 -0
  63. package/dist/governance/index.d.ts.map +1 -0
  64. package/dist/governance/index.js +26 -0
  65. package/dist/governance/index.js.map +1 -0
  66. package/dist/governance/load-config.d.ts +45 -0
  67. package/dist/governance/load-config.d.ts.map +1 -0
  68. package/dist/governance/load-config.js +137 -0
  69. package/dist/governance/load-config.js.map +1 -0
  70. package/dist/governance/pr-scope.d.ts +23 -0
  71. package/dist/governance/pr-scope.d.ts.map +1 -0
  72. package/dist/governance/pr-scope.js +22 -0
  73. package/dist/governance/pr-scope.js.map +1 -0
  74. package/dist/governance/report.d.ts +23 -0
  75. package/dist/governance/report.d.ts.map +1 -0
  76. package/dist/governance/report.js +177 -0
  77. package/dist/governance/report.js.map +1 -0
  78. package/dist/governance/run-governance.d.ts +22 -0
  79. package/dist/governance/run-governance.d.ts.map +1 -0
  80. package/dist/governance/run-governance.js +78 -0
  81. package/dist/governance/run-governance.js.map +1 -0
  82. package/dist/governance/source-checks.d.ts +29 -0
  83. package/dist/governance/source-checks.d.ts.map +1 -0
  84. package/dist/governance/source-checks.js +80 -0
  85. package/dist/governance/source-checks.js.map +1 -0
  86. package/dist/governance/validate-collection-governance.d.ts +46 -0
  87. package/dist/governance/validate-collection-governance.d.ts.map +1 -0
  88. package/dist/governance/validate-collection-governance.js +291 -0
  89. package/dist/governance/validate-collection-governance.js.map +1 -0
  90. package/dist/hub-editor/hub-config-editor-service.d.ts +94 -0
  91. package/dist/hub-editor/hub-config-editor-service.d.ts.map +1 -0
  92. package/dist/hub-editor/hub-config-editor-service.js +289 -0
  93. package/dist/hub-editor/hub-config-editor-service.js.map +1 -0
  94. package/dist/hub-editor/hub-contribution-workflow.d.ts +99 -0
  95. package/dist/hub-editor/hub-contribution-workflow.d.ts.map +1 -0
  96. package/dist/hub-editor/hub-contribution-workflow.js +385 -0
  97. package/dist/hub-editor/hub-contribution-workflow.js.map +1 -0
  98. package/dist/hub-editor/index.d.ts +7 -0
  99. package/dist/hub-editor/index.d.ts.map +1 -0
  100. package/dist/hub-editor/index.js +23 -0
  101. package/dist/hub-editor/index.js.map +1 -0
  102. package/dist/index.d.ts +6 -0
  103. package/dist/index.d.ts.map +1 -1
  104. package/dist/index.js +6 -0
  105. package/dist/index.js.map +1 -1
  106. package/dist/install/index.d.ts +2 -0
  107. package/dist/install/index.d.ts.map +1 -1
  108. package/dist/install/index.js +3 -1
  109. package/dist/install/index.js.map +1 -1
  110. package/dist/install/partial-target-write.d.ts +63 -0
  111. package/dist/install/partial-target-write.d.ts.map +1 -0
  112. package/dist/install/partial-target-write.js +128 -0
  113. package/dist/install/partial-target-write.js.map +1 -0
  114. package/dist/install/pipeline.d.ts +2 -1
  115. package/dist/install/pipeline.d.ts.map +1 -1
  116. package/dist/install/pipeline.js +4 -3
  117. package/dist/install/pipeline.js.map +1 -1
  118. package/dist/install/target-write.d.ts +10 -0
  119. package/dist/install/target-write.d.ts.map +1 -1
  120. package/dist/install/target-write.js +3 -2
  121. package/dist/install/target-write.js.map +1 -1
  122. package/dist/install/uninstall-pipeline.d.ts +11 -10
  123. package/dist/install/uninstall-pipeline.d.ts.map +1 -1
  124. package/dist/install/uninstall-pipeline.js +10 -11
  125. package/dist/install/uninstall-pipeline.js.map +1 -1
  126. package/dist/records/atomic-write.d.ts +11 -0
  127. package/dist/records/atomic-write.d.ts.map +1 -0
  128. package/dist/records/atomic-write.js +66 -0
  129. package/dist/records/atomic-write.js.map +1 -0
  130. package/dist/records/confine-path.d.ts +35 -0
  131. package/dist/records/confine-path.d.ts.map +1 -0
  132. package/dist/records/confine-path.js +140 -0
  133. package/dist/records/confine-path.js.map +1 -0
  134. package/dist/records/git-root.d.ts +66 -0
  135. package/dist/records/git-root.d.ts.map +1 -0
  136. package/dist/records/git-root.js +208 -0
  137. package/dist/records/git-root.js.map +1 -0
  138. package/dist/records/index.d.ts +30 -0
  139. package/dist/records/index.d.ts.map +1 -0
  140. package/dist/records/index.js +46 -0
  141. package/dist/records/index.js.map +1 -0
  142. package/dist/records/install-record-service.d.ts +496 -0
  143. package/dist/records/install-record-service.d.ts.map +1 -0
  144. package/dist/records/install-record-service.js +1365 -0
  145. package/dist/records/install-record-service.js.map +1 -0
  146. package/dist/records/install-record-services.d.ts +29 -0
  147. package/dist/records/install-record-services.d.ts.map +1 -0
  148. package/dist/records/install-record-services.js +17 -0
  149. package/dist/records/install-record-services.js.map +1 -0
  150. package/dist/records/legacy-shapes.d.ts +18 -0
  151. package/dist/records/legacy-shapes.d.ts.map +1 -0
  152. package/dist/records/legacy-shapes.js +30 -0
  153. package/dist/records/legacy-shapes.js.map +1 -0
  154. package/dist/records/map-tool-to-target.d.ts +33 -0
  155. package/dist/records/map-tool-to-target.d.ts.map +1 -0
  156. package/dist/records/map-tool-to-target.js +98 -0
  157. package/dist/records/map-tool-to-target.js.map +1 -0
  158. package/dist/records/mcp-servers.d.ts +116 -0
  159. package/dist/records/mcp-servers.d.ts.map +1 -0
  160. package/dist/records/mcp-servers.js +268 -0
  161. package/dist/records/mcp-servers.js.map +1 -0
  162. package/dist/records/modified-files.d.ts +32 -0
  163. package/dist/records/modified-files.d.ts.map +1 -0
  164. package/dist/records/modified-files.js +146 -0
  165. package/dist/records/modified-files.js.map +1 -0
  166. package/dist/records/plan-record-entries.d.ts +76 -0
  167. package/dist/records/plan-record-entries.d.ts.map +1 -0
  168. package/dist/records/plan-record-entries.js +84 -0
  169. package/dist/records/plan-record-entries.js.map +1 -0
  170. package/dist/records/read-record-text.d.ts +15 -0
  171. package/dist/records/read-record-text.d.ts.map +1 -0
  172. package/dist/records/read-record-text.js +36 -0
  173. package/dist/records/read-record-text.js.map +1 -0
  174. package/dist/records/record-entry.d.ts +31 -0
  175. package/dist/records/record-entry.d.ts.map +1 -0
  176. package/dist/records/record-entry.js +81 -0
  177. package/dist/records/record-entry.js.map +1 -0
  178. package/dist/records/record-file-shape.d.ts +90 -0
  179. package/dist/records/record-file-shape.d.ts.map +1 -0
  180. package/dist/records/record-file-shape.js +288 -0
  181. package/dist/records/record-file-shape.js.map +1 -0
  182. package/dist/records/record-hub.d.ts +42 -0
  183. package/dist/records/record-hub.d.ts.map +1 -0
  184. package/dist/records/record-hub.js +85 -0
  185. package/dist/records/record-hub.js.map +1 -0
  186. package/dist/records/record-identity.d.ts +14 -0
  187. package/dist/records/record-identity.d.ts.map +1 -0
  188. package/dist/records/record-identity.js +41 -0
  189. package/dist/records/record-identity.js.map +1 -0
  190. package/dist/records/record-migration.d.ts +118 -0
  191. package/dist/records/record-migration.d.ts.map +1 -0
  192. package/dist/records/record-migration.js +454 -0
  193. package/dist/records/record-migration.js.map +1 -0
  194. package/dist/records/record-store.d.ts +123 -0
  195. package/dist/records/record-store.d.ts.map +1 -0
  196. package/dist/records/record-store.js +291 -0
  197. package/dist/records/record-store.js.map +1 -0
  198. package/dist/records/resolve-record-source.d.ts +64 -0
  199. package/dist/records/resolve-record-source.d.ts.map +1 -0
  200. package/dist/records/resolve-record-source.js +160 -0
  201. package/dist/records/resolve-record-source.js.map +1 -0
  202. package/dist/records/sanitize-source.d.ts +18 -0
  203. package/dist/records/sanitize-source.d.ts.map +1 -0
  204. package/dist/records/sanitize-source.js +90 -0
  205. package/dist/records/sanitize-source.js.map +1 -0
  206. package/dist/records/select-record.d.ts +54 -0
  207. package/dist/records/select-record.d.ts.map +1 -0
  208. package/dist/records/select-record.js +180 -0
  209. package/dist/records/select-record.js.map +1 -0
  210. package/dist/records/serialize-record.d.ts +20 -0
  211. package/dist/records/serialize-record.d.ts.map +1 -0
  212. package/dist/records/serialize-record.js +100 -0
  213. package/dist/records/serialize-record.js.map +1 -0
  214. package/dist/records/source-fields.d.ts +21 -0
  215. package/dist/records/source-fields.d.ts.map +1 -0
  216. package/dist/records/source-fields.js +28 -0
  217. package/dist/records/source-fields.js.map +1 -0
  218. package/dist/records/to-record-source.d.ts +23 -0
  219. package/dist/records/to-record-source.d.ts.map +1 -0
  220. package/dist/records/to-record-source.js +39 -0
  221. package/dist/records/to-record-source.js.map +1 -0
  222. package/dist/records/user-home.d.ts +16 -0
  223. package/dist/records/user-home.d.ts.map +1 -0
  224. package/dist/records/user-home.js +84 -0
  225. package/dist/records/user-home.js.map +1 -0
  226. package/dist/records/writer-group.d.ts +7 -0
  227. package/dist/records/writer-group.d.ts.map +1 -0
  228. package/dist/records/writer-group.js +31 -0
  229. package/dist/records/writer-group.js.map +1 -0
  230. package/dist/registry/activate-registry-profile.d.ts.map +1 -1
  231. package/dist/registry/activate-registry-profile.js +4 -1
  232. package/dist/registry/activate-registry-profile.js.map +1 -1
  233. package/dist/registry/batch-install-profile.d.ts +76 -0
  234. package/dist/registry/batch-install-profile.d.ts.map +1 -0
  235. package/dist/registry/batch-install-profile.js +67 -0
  236. package/dist/registry/batch-install-profile.js.map +1 -0
  237. package/dist/registry/create-source-adapter.d.ts +16 -1
  238. package/dist/registry/create-source-adapter.d.ts.map +1 -1
  239. package/dist/registry/create-source-adapter.js +76 -3
  240. package/dist/registry/create-source-adapter.js.map +1 -1
  241. package/dist/registry/hub-manager.d.ts +41 -0
  242. package/dist/registry/hub-manager.d.ts.map +1 -1
  243. package/dist/registry/hub-manager.js +82 -4
  244. package/dist/registry/hub-manager.js.map +1 -1
  245. package/dist/registry/index.d.ts +1 -0
  246. package/dist/registry/index.d.ts.map +1 -1
  247. package/dist/registry/index.js +1 -0
  248. package/dist/registry/index.js.map +1 -1
  249. package/dist/registry/install-registry-bundle.js +4 -3
  250. package/dist/registry/install-registry-bundle.js.map +1 -1
  251. package/dist/registry/list-installed-bundles.d.ts +2 -3
  252. package/dist/registry/list-installed-bundles.d.ts.map +1 -1
  253. package/dist/registry/list-installed-bundles.js.map +1 -1
  254. package/dist/registry/load-hub-sources.d.ts +8 -0
  255. package/dist/registry/load-hub-sources.d.ts.map +1 -1
  256. package/dist/registry/load-hub-sources.js +70 -3
  257. package/dist/registry/load-hub-sources.js.map +1 -1
  258. package/dist/registry/profile-lifecycle.d.ts +7 -2
  259. package/dist/registry/profile-lifecycle.d.ts.map +1 -1
  260. package/dist/registry/profile-lifecycle.js +82 -11
  261. package/dist/registry/profile-lifecycle.js.map +1 -1
  262. package/dist/registry/uninstall-installed-bundle.d.ts +2 -3
  263. package/dist/registry/uninstall-installed-bundle.d.ts.map +1 -1
  264. package/dist/registry/uninstall-installed-bundle.js.map +1 -1
  265. package/dist/registry/update-registry-bundle.d.ts +2 -2
  266. package/dist/registry/update-registry-bundle.js +2 -2
  267. package/dist/registry/update-registry-bundle.js.map +1 -1
  268. package/dist/registry/validate-hub-config-file.d.ts +14 -1
  269. package/dist/registry/validate-hub-config-file.d.ts.map +1 -1
  270. package/dist/registry/validate-hub-config-file.js +81 -44
  271. package/dist/registry/validate-hub-config-file.js.map +1 -1
  272. package/dist/release/plan-bundle-release.d.ts +6 -12
  273. package/dist/release/plan-bundle-release.d.ts.map +1 -1
  274. package/dist/release/plan-bundle-release.js +178 -7
  275. package/dist/release/plan-bundle-release.js.map +1 -1
  276. package/dist/replicate/replicate.d.ts +5 -2
  277. package/dist/replicate/replicate.d.ts.map +1 -1
  278. package/dist/replicate/replicate.js +121 -17
  279. package/dist/replicate/replicate.js.map +1 -1
  280. package/dist/security/index.d.ts +4 -0
  281. package/dist/security/index.d.ts.map +1 -0
  282. package/dist/security/index.js +22 -0
  283. package/dist/security/index.js.map +1 -0
  284. package/dist/security/rating/bundle-discovery.d.ts +19 -0
  285. package/dist/security/rating/bundle-discovery.d.ts.map +1 -0
  286. package/dist/security/rating/bundle-discovery.js +244 -0
  287. package/dist/security/rating/bundle-discovery.js.map +1 -0
  288. package/dist/security/rating/index.d.ts +5 -0
  289. package/dist/security/rating/index.d.ts.map +1 -0
  290. package/dist/security/rating/index.js +21 -0
  291. package/dist/security/rating/index.js.map +1 -0
  292. package/dist/security/rating/security-rating-markdown.d.ts +17 -0
  293. package/dist/security/rating/security-rating-markdown.d.ts.map +1 -0
  294. package/dist/security/rating/security-rating-markdown.js +131 -0
  295. package/dist/security/rating/security-rating-markdown.js.map +1 -0
  296. package/dist/security/rating/security-rating-scan.d.ts +23 -0
  297. package/dist/security/rating/security-rating-scan.d.ts.map +1 -0
  298. package/dist/security/rating/security-rating-scan.js +40 -0
  299. package/dist/security/rating/security-rating-scan.js.map +1 -0
  300. package/dist/security/rating/security-rating-templates.d.ts +40 -0
  301. package/dist/security/rating/security-rating-templates.d.ts.map +1 -0
  302. package/dist/security/rating/security-rating-templates.js +83 -0
  303. package/dist/security/rating/security-rating-templates.js.map +1 -0
  304. package/dist/security/rating/security-rating.d.ts +32 -0
  305. package/dist/security/rating/security-rating.d.ts.map +1 -0
  306. package/dist/security/rating/security-rating.js +94 -0
  307. package/dist/security/rating/security-rating.js.map +1 -0
  308. package/dist/security/security-scan-use-case.d.ts +101 -0
  309. package/dist/security/security-scan-use-case.d.ts.map +1 -0
  310. package/dist/security/security-scan-use-case.js +185 -0
  311. package/dist/security/security-scan-use-case.js.map +1 -0
  312. package/dist/stores/json-lockfile-store.d.ts.map +1 -1
  313. package/dist/stores/json-lockfile-store.js +6 -32
  314. package/dist/stores/json-lockfile-store.js.map +1 -1
  315. package/dist/transform/transformer-registry.d.ts.map +1 -1
  316. package/dist/transform/transformer-registry.js +3 -0
  317. package/dist/transform/transformer-registry.js.map +1 -1
  318. package/dist/transform/transformers/windsurf-transformer.d.ts +5 -0
  319. package/dist/transform/transformers/windsurf-transformer.d.ts.map +1 -1
  320. package/dist/transform/transformers/windsurf-transformer.js.map +1 -1
  321. package/dist/writers/file-tree-writer.d.ts +14 -1
  322. package/dist/writers/file-tree-writer.d.ts.map +1 -1
  323. package/dist/writers/file-tree-writer.js +23 -71
  324. package/dist/writers/file-tree-writer.js.map +1 -1
  325. package/package.json +5 -4
@@ -0,0 +1,268 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.mcpServerKeyOf = exports.removeMcpServers = exports.writeMcpServers = exports.checkMcpServers = exports.writeMcpConfigText = exports.readMcpConfig = exports.prepareMcpServers = exports.mcpServerChecksumOf = void 0;
37
+ /**
38
+ * MCP servers an install record entry owns. A server's definition lives in the
39
+ * tool's own MCP file (`.vscode/mcp.json`, `.kiro/settings/mcp.json`, …), next
40
+ * to servers the user added; the entry records each server's file, name and the
41
+ * checksum of the definition it wrote. Only servers an entry recorded are
42
+ * changed or removed, and a server whose definition changed since is kept.
43
+ * Files are read and written as plain JSON; a file with comments is refused.
44
+ * @module records/mcp-servers
45
+ */
46
+ const node_crypto_1 = require("node:crypto");
47
+ const path = __importStar(require("node:path"));
48
+ const core_1 = require("@ai-primitives-hub/core");
49
+ const atomic_write_1 = require("./atomic-write");
50
+ /** Fields that do not count as a change of the definition: tools set them, as duplicate detection sets both. */
51
+ const VOLATILE_FIELDS = new Set(['disabled', 'description']);
52
+ const canonical = (value) => {
53
+ if (Array.isArray(value)) {
54
+ return value.map((item) => canonical(item));
55
+ }
56
+ if ((0, core_1.isJsonObject)(value)) {
57
+ return Object.fromEntries(Object.keys(value).toSorted().map((key) => [key, canonical(value[key])]));
58
+ }
59
+ return value;
60
+ };
61
+ /**
62
+ * `sha256:` of a server definition, keys sorted, without fields the tools change themselves (`disabled`, `description`).
63
+ * @param definition - Server definition as in the MCP file.
64
+ */
65
+ const mcpServerChecksumOf = (definition) => {
66
+ const fields = (0, core_1.isJsonObject)(definition)
67
+ ? Object.fromEntries(Object.entries(definition).filter(([key]) => !VOLATILE_FIELDS.has(key)))
68
+ : definition;
69
+ return `sha256:${(0, node_crypto_1.createHash)('sha256').update(JSON.stringify(canonical(fields))).digest('hex')}`;
70
+ };
71
+ exports.mcpServerChecksumOf = mcpServerChecksumOf;
72
+ const substitute = (value, replace) => {
73
+ if (typeof value === 'string') {
74
+ return replace(value);
75
+ }
76
+ if (Array.isArray(value)) {
77
+ return value.map((item) => substitute(item, replace));
78
+ }
79
+ if ((0, core_1.isJsonObject)(value)) {
80
+ return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, substitute(item, replace)]));
81
+ }
82
+ return value;
83
+ };
84
+ /**
85
+ * The bundle's MCP servers as they are written: named like the extension names
86
+ * them, `${bundlePath}`, `${bundleId}` and `${bundleVersion}` filled in, and
87
+ * `${env:VAR}` kept unresolved in the tool's syntax.
88
+ * @param input - Manifest servers and the bundle they come from.
89
+ */
90
+ const prepareMcpServers = (input) => {
91
+ const style = input.envPlaceholderStyle ?? 'prefixed';
92
+ const replace = (text) => (0, core_1.rewriteEnvPlaceholders)(text
93
+ .replaceAll('${bundlePath}', input.bundlePath)
94
+ .replaceAll('${bundleId}', input.bundleId)
95
+ .replaceAll('${bundleVersion}', input.version), style);
96
+ return Object.entries(input.servers ?? {})
97
+ .filter((entry) => (0, core_1.isJsonObject)(entry[1]))
98
+ .map(([item, definition]) => ({
99
+ name: (0, core_1.resolveMcpServerKey)({
100
+ bundleId: input.bundleId,
101
+ serverName: item,
102
+ ...(input.manifestId === undefined ? {} : { manifestId: input.manifestId }),
103
+ ...(input.manifestRepository === undefined ? {} : { manifestRepository: input.manifestRepository }),
104
+ ...(input.sourceRepository === undefined ? {} : { sourceRepository: input.sourceRepository })
105
+ }),
106
+ item,
107
+ definition: substitute(definition, replace)
108
+ }));
109
+ };
110
+ exports.prepareMcpServers = prepareMcpServers;
111
+ /**
112
+ * Read an MCP file; a missing file is empty.
113
+ * @param fs - Filesystem port.
114
+ * @param file - The MCP file.
115
+ * @param label - File named in errors.
116
+ * @throws {RegistryError} `RECORD.MCP_CONFIG_UNREADABLE` for a file that is not a plain JSON object.
117
+ */
118
+ const readMcpConfig = async (fs, file, label) => {
119
+ if (!(await fs.exists(file.path))) {
120
+ return {};
121
+ }
122
+ try {
123
+ const bytes = await fs.readCapped(file.path, core_1.RECORD_MAX_BYTES + 1);
124
+ if (bytes.byteLength > core_1.RECORD_MAX_BYTES) {
125
+ throw new Error('larger than 10 MB');
126
+ }
127
+ const text = new TextDecoder('utf-8', { fatal: true }).decode(bytes);
128
+ const parsed = text.trim() === '' ? {} : JSON.parse(text);
129
+ if (!(0, core_1.isJsonObject)(parsed)) {
130
+ throw new Error('not a JSON object');
131
+ }
132
+ return parsed;
133
+ }
134
+ catch (error) {
135
+ throw (0, core_1.recordError)('RECORD.MCP_CONFIG_UNREADABLE', { file: label, detail: error instanceof Error ? error.message : String(error), cause: error });
136
+ }
137
+ };
138
+ exports.readMcpConfig = readMcpConfig;
139
+ const serversIn = (config, serversKey) => {
140
+ const servers = config[serversKey];
141
+ return (0, core_1.isJsonObject)(servers) ? servers : {};
142
+ };
143
+ /**
144
+ * Replace an MCP file atomically (temp file, then rename): a failed write leaves
145
+ * the old file intact, so no backup copy is kept. A symlinked file keeps its link,
146
+ * and a `<file>.backup` copy an earlier release left is removed.
147
+ * @param fs - Filesystem port.
148
+ * @param filePath - Absolute MCP file path.
149
+ * @param text - New contents.
150
+ */
151
+ const writeMcpConfigText = async (fs, filePath, text) => {
152
+ await fs.mkdir(path.dirname(filePath), { recursive: true });
153
+ const target = (await fs.lstat(filePath))?.kind === 'symlink' ? await fs.realpath(filePath) : filePath;
154
+ await (0, atomic_write_1.writeFileAtomically)(fs, target, text);
155
+ await fs.unlink(`${filePath}.backup`).catch(() => undefined);
156
+ };
157
+ exports.writeMcpConfigText = writeMcpConfigText;
158
+ const writeMcpConfig = (fs, file, config) => (0, exports.writeMcpConfigText)(fs, file.path, `${JSON.stringify(config, null, 2)}\n`);
159
+ /**
160
+ * Read an MCP file and refuse a server name another writer put there. A name no
161
+ * record lists is accepted when its definition is the one being written, as a
162
+ * failed install leaves it, so a retry is not a conflict.
163
+ * @param fs - Filesystem port.
164
+ * @param file - The MCP file.
165
+ * @param servers - Servers to write.
166
+ * @param options - Recorded names and the file name for errors.
167
+ * @throws {RegistryError} `RECORD.MCP_CONFLICT` or `RECORD.MCP_CONFIG_UNREADABLE`.
168
+ */
169
+ const readForMcpWrite = async (fs, file, servers, options) => {
170
+ const config = await (0, exports.readMcpConfig)(fs, file, options.label);
171
+ const existing = serversIn(config, file.serversKey);
172
+ const taken = servers.filter((server) => Object.hasOwn(existing, server.name) && !options.isRecorded(server.name)
173
+ && (0, exports.mcpServerChecksumOf)(existing[server.name]) !== (0, exports.mcpServerChecksumOf)(server.definition));
174
+ if (taken.length > 0) {
175
+ throw (0, core_1.recordError)('RECORD.MCP_CONFLICT', {
176
+ file: options.label,
177
+ detail: `server ${taken.map((server) => JSON.stringify(server.name)).join(', ')} is already in the file`,
178
+ context: { servers: taken.map((server) => server.name) }
179
+ });
180
+ }
181
+ return { config, existing };
182
+ };
183
+ /**
184
+ * Check that servers can be written into an MCP file, writing nothing.
185
+ * @param fs - Filesystem port.
186
+ * @param file - The MCP file.
187
+ * @param servers - Servers to write.
188
+ * @param options - Recorded names and the file name for errors.
189
+ * @throws {RegistryError} `RECORD.MCP_CONFLICT` or `RECORD.MCP_CONFIG_UNREADABLE`.
190
+ */
191
+ const checkMcpServers = async (fs, file, servers, options) => {
192
+ if (servers.length > 0) {
193
+ await readForMcpWrite(fs, file, servers, options);
194
+ }
195
+ };
196
+ exports.checkMcpServers = checkMcpServers;
197
+ /**
198
+ * Write servers into an MCP file, keeping every other key and server. A name the
199
+ * file has that `isRecorded` does not claim, with another definition, was added by
200
+ * someone else and is refused.
201
+ * @param fs - Filesystem port.
202
+ * @param file - The MCP file.
203
+ * @param servers - Servers to write.
204
+ * @param options - Recorded names and the file name for errors.
205
+ * @returns Each server as recorded, without `config`.
206
+ * @throws {RegistryError} `RECORD.MCP_CONFLICT` or `RECORD.MCP_CONFIG_UNREADABLE`; the file is then unchanged.
207
+ */
208
+ const writeMcpServers = async (fs, file, servers, options) => {
209
+ if (servers.length === 0) {
210
+ return [];
211
+ }
212
+ const { config, existing } = await readForMcpWrite(fs, file, servers, options);
213
+ const next = { ...existing };
214
+ for (const server of servers) {
215
+ // A tool's own `disabled` setting survives a rewrite.
216
+ const current = existing[server.name];
217
+ const kept = (0, core_1.isJsonObject)(current) && current.disabled !== undefined ? { disabled: current.disabled } : {};
218
+ next[server.name] = { ...server.definition, ...kept };
219
+ }
220
+ await writeMcpConfig(fs, file, { ...config, [file.serversKey]: next });
221
+ return servers.map((server) => ({ name: server.name, item: server.item, checksum: (0, exports.mcpServerChecksumOf)(server.definition) }));
222
+ };
223
+ exports.writeMcpServers = writeMcpServers;
224
+ /**
225
+ * Remove recorded servers from an MCP file. A server whose definition no longer
226
+ * matches its recorded checksum is kept; a missing one is skipped. The file is
227
+ * deleted only when nothing but an empty server map is left.
228
+ * @param fs - Filesystem port.
229
+ * @param file - The MCP file.
230
+ * @param servers - Recorded servers of this file.
231
+ * @param label - File named in errors.
232
+ * @throws {RegistryError} `RECORD.MCP_CONFIG_UNREADABLE`; the file is then unchanged.
233
+ */
234
+ const removeMcpServers = async (fs, file, servers, label) => {
235
+ const result = { removed: [], modified: [] };
236
+ if (servers.length === 0 || !(await fs.exists(file.path))) {
237
+ return result;
238
+ }
239
+ const config = await (0, exports.readMcpConfig)(fs, file, label);
240
+ const next = { ...serversIn(config, file.serversKey) };
241
+ for (const server of servers) {
242
+ if (!Object.hasOwn(next, server.name)) {
243
+ continue;
244
+ }
245
+ if (server.checksum !== undefined && (0, exports.mcpServerChecksumOf)(next[server.name]) !== server.checksum) {
246
+ result.modified.push(server.name);
247
+ continue;
248
+ }
249
+ delete next[server.name];
250
+ result.removed.push(server.name);
251
+ }
252
+ if (result.removed.length === 0) {
253
+ return result;
254
+ }
255
+ // A file left with nothing but an empty server map is the one an install created: it goes too.
256
+ await (Object.keys(next).length === 0 && Object.keys(config).every((key) => key === file.serversKey)
257
+ ? fs.unlink(file.path)
258
+ : writeMcpConfig(fs, file, { ...config, [file.serversKey]: next }));
259
+ return result;
260
+ };
261
+ exports.removeMcpServers = removeMcpServers;
262
+ /**
263
+ * The key a server is known by across entries: its file and name.
264
+ * @param server - Recorded server.
265
+ */
266
+ const mcpServerKeyOf = (server) => `${server.config}\u0000${server.name}`;
267
+ exports.mcpServerKeyOf = mcpServerKeyOf;
268
+ //# sourceMappingURL=mcp-servers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-servers.js","sourceRoot":"","sources":["../../src/records/mcp-servers.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;GAQG;AACH,6CAEqB;AACrB,gDAAkC;AAClC,kDAUiC;AACjC,iDAEwB;AAmCxB,gHAAgH;AAChH,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC,CAAC,UAAU,EAAE,aAAa,CAAC,CAAC,CAAC;AAE7D,MAAM,SAAS,GAAG,CAAC,KAAc,EAAW,EAAE;IAC5C,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;IAC9C,CAAC;IACD,IAAI,IAAA,mBAAY,EAAC,KAAK,CAAC,EAAE,CAAC;QACxB,OAAO,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,QAAQ,EAA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C,KAAK,MAAM,CAAC,QAAQ,EAAE,CAAC;YAChG,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;YAClC,SAAS;QACX,CAAC;QACD,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACzB,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACnC,CAAC;IACD,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAChC,OAAO,MAAM,CAAC;IAChB,CAAC;IACD,+FAA+F;IAC/F,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,KAAK,IAAI,CAAC,UAAU,CAAC;QAClG,CAAC,CAAC,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC;QACtB,CAAC,CAAC,cAAc,CAAC,EAAE,EAAE,IAAI,EAAE,EAAE,GAAG,MAAM,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;IACtE,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AA/BW,QAAA,gBAAgB,oBA+B3B;AAEF;;;GAGG;AACI,MAAM,cAAc,GAAG,CAAC,MAAkD,EAAU,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,SAAS,MAAM,CAAC,IAAI,EAAE,CAAC;AAAxH,QAAA,cAAc,kBAA0G"}
@@ -0,0 +1,32 @@
1
+ import type { RecordFs } from '@ai-primitives-hub/core';
2
+ /** A recorded file to check. */
3
+ export interface RecordedFileCheck {
4
+ /** Path relative to the root, forward slashes. */
5
+ path: string;
6
+ /** `sha256:<hex>`, or the bare hex digest old lockfiles store. */
7
+ checksum?: string;
8
+ }
9
+ /**
10
+ * The recorded files that changed since the install or are missing, sorted.
11
+ * @param fs - Filesystem port.
12
+ * @param root - Root the paths are relative to.
13
+ * @param files - Recorded files with their checksums.
14
+ */
15
+ export declare const findModifiedFiles: (fs: RecordFs, root: string, files: readonly RecordedFileCheck[]) => Promise<string[]>;
16
+ /**
17
+ * Whether every recorded file is missing, the stale-entry rule. A path that
18
+ * cannot be checked counts as present.
19
+ * @param fs - Filesystem port.
20
+ * @param root - Root the paths are relative to.
21
+ * @param paths - Root-relative recorded paths.
22
+ */
23
+ export declare const areAllFilesMissing: (fs: RecordFs, root: string, paths: readonly string[]) => Promise<boolean>;
24
+ /**
25
+ * Whether any recorded file is missing. A path that cannot be checked counts as present.
26
+ * @param fs - Filesystem port.
27
+ * @param root - Root the paths are relative to.
28
+ * @param paths - Root-relative recorded paths.
29
+ * @param onError - Called for a path whose check failed.
30
+ */
31
+ export declare const isAnyFileMissing: (fs: RecordFs, root: string, paths: readonly string[], onError?: (recordedPath: string, error: unknown) => void) => Promise<boolean>;
32
+ //# sourceMappingURL=modified-files.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"modified-files.d.ts","sourceRoot":"","sources":["../../src/records/modified-files.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EACV,QAAQ,EACT,MAAM,yBAAyB,CAAC;AAKjC,gCAAgC;AAChC,MAAM,WAAW,iBAAiB;IAChC,kDAAkD;IAClD,IAAI,EAAE,MAAM,CAAC;IACb,kEAAkE;IAClE,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AA2CD;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,GAAU,IAAI,QAAQ,EAAE,MAAM,MAAM,EAAE,OAAO,SAAS,iBAAiB,EAAE,KAAG,OAAO,CAAC,MAAM,EAAE,CAQzH,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,GAAU,IAAI,QAAQ,EAAE,MAAM,MAAM,EAAE,OAAO,SAAS,MAAM,EAAE,KAAG,OAAO,CAAC,OAAO,CAc9G,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,GAC3B,IAAI,QAAQ,EACZ,MAAM,MAAM,EACZ,OAAO,SAAS,MAAM,EAAE,EACxB,UAAU,CAAC,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,KAAK,IAAI,KACvD,OAAO,CAAC,OAAO,CAWjB,CAAC"}
@@ -0,0 +1,146 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.isAnyFileMissing = exports.areAllFilesMissing = exports.findModifiedFiles = void 0;
37
+ /**
38
+ * Locally modified installed files: content that no longer matches the
39
+ * recorded checksum, or a missing file. Callers keep them instead of deleting.
40
+ * A path that fails confinement, is not a regular file or has no checksum
41
+ * counts as modified, so it is kept. A symlink is compared by the content of
42
+ * the file it resolves to.
43
+ * @module records/modified-files
44
+ */
45
+ const path = __importStar(require("node:path"));
46
+ const confine_path_1 = require("./confine-path");
47
+ /** A bare SHA-256 hex digest, as old `prompt-registry` lockfiles store it. */
48
+ const BARE_SHA256 = /^[0-9a-f]{64}$/;
49
+ const toRecordChecksum = (checksum) => BARE_SHA256.test(checksum) ? `sha256:${checksum}` : checksum;
50
+ /**
51
+ * The regular file whose bytes a recorded leaf holds: the leaf, or the file a
52
+ * symlink resolves to (user-scope files can link into the bundle cache).
53
+ * @param fs - Filesystem port.
54
+ * @param leaf - Absolute recorded path, already confined.
55
+ * @returns The file to hash, or `undefined` for a dangling link or a non-file.
56
+ */
57
+ const contentFile = async (fs, leaf) => {
58
+ const kind = (await fs.lstat(leaf))?.kind;
59
+ if (kind === 'file') {
60
+ return leaf;
61
+ }
62
+ if (kind !== 'symlink') {
63
+ return undefined;
64
+ }
65
+ const resolved = await fs.realpath(leaf).catch(() => undefined);
66
+ return resolved !== undefined && (await fs.lstat(resolved))?.kind === 'file' ? resolved : undefined;
67
+ };
68
+ const isModified = async (fs, root, file) => {
69
+ const target = await (0, confine_path_1.resolveDeleteTarget)(fs, root, file.path);
70
+ if (target.status !== 'delete' || file.checksum === undefined) {
71
+ return true;
72
+ }
73
+ const content = await contentFile(fs, target.absolute);
74
+ if (content === undefined) {
75
+ return true;
76
+ }
77
+ try {
78
+ return (await fs.hashFile(content)) !== toRecordChecksum(file.checksum);
79
+ }
80
+ catch {
81
+ // A file that cannot be read cannot be shown to be unchanged: keep it.
82
+ return true;
83
+ }
84
+ };
85
+ /**
86
+ * The recorded files that changed since the install or are missing, sorted.
87
+ * @param fs - Filesystem port.
88
+ * @param root - Root the paths are relative to.
89
+ * @param files - Recorded files with their checksums.
90
+ */
91
+ const findModifiedFiles = async (fs, root, files) => {
92
+ const modified = new Set();
93
+ for (const file of files) {
94
+ if (!modified.has(file.path) && await isModified(fs, root, file)) {
95
+ modified.add(file.path);
96
+ }
97
+ }
98
+ return [...modified].toSorted();
99
+ };
100
+ exports.findModifiedFiles = findModifiedFiles;
101
+ /**
102
+ * Whether every recorded file is missing, the stale-entry rule. A path that
103
+ * cannot be checked counts as present.
104
+ * @param fs - Filesystem port.
105
+ * @param root - Root the paths are relative to.
106
+ * @param paths - Root-relative recorded paths.
107
+ */
108
+ const areAllFilesMissing = async (fs, root, paths) => {
109
+ if (paths.length === 0) {
110
+ return false;
111
+ }
112
+ for (const recordedPath of paths) {
113
+ try {
114
+ if (await fs.lstat(path.join(root, ...recordedPath.split('/'))) !== undefined) {
115
+ return false;
116
+ }
117
+ }
118
+ catch {
119
+ return false;
120
+ }
121
+ }
122
+ return true;
123
+ };
124
+ exports.areAllFilesMissing = areAllFilesMissing;
125
+ /**
126
+ * Whether any recorded file is missing. A path that cannot be checked counts as present.
127
+ * @param fs - Filesystem port.
128
+ * @param root - Root the paths are relative to.
129
+ * @param paths - Root-relative recorded paths.
130
+ * @param onError - Called for a path whose check failed.
131
+ */
132
+ const isAnyFileMissing = async (fs, root, paths, onError) => {
133
+ for (const recordedPath of paths) {
134
+ try {
135
+ if (await fs.lstat(path.join(root, ...recordedPath.split('/'))) === undefined) {
136
+ return true;
137
+ }
138
+ }
139
+ catch (error) {
140
+ onError?.(recordedPath, error);
141
+ }
142
+ }
143
+ return false;
144
+ };
145
+ exports.isAnyFileMissing = isAnyFileMissing;
146
+ //# sourceMappingURL=modified-files.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"modified-files.js","sourceRoot":"","sources":["../../src/records/modified-files.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;GAOG;AACH,gDAAkC;AAIlC,iDAEwB;AAUxB,8EAA8E;AAC9E,MAAM,WAAW,GAAG,gBAAgB,CAAC;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C9E,OAAO,KAAK,CAAC;YACf,CAAC;QACH,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAdW,QAAA,kBAAkB,sBAc7B;AAEF;;;;;;GAMG;AACI,MAAM,gBAAgB,GAAG,KAAK,EACnC,EAAY,EACZ,IAAY,EACZ,KAAwB,EACxB,OAAwD,EACtC,EAAE;IACpB,KAAK,MAAM,YAAY,IAAI,KAAK,EAAE,CAAC;QACjC,IAAI,CAAC;YACH,IAAI,MAAM,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,YAAY,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,SAAS,EAAE,CAAC;gBAC9E,OAAO,IAAI,CAAC;YACd,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,EAAE,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC;QACjC,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAhBW,QAAA,gBAAgB,oBAgB3B"}
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Plans a record replay or update: maps each entry to a target, finds its file
3
+ * and gates its source before anything contacts a source, also under `--dry-run`.
4
+ * @module records/plan-record-entries
5
+ */
6
+ import type { RecordFs, RecordLocation, RegistrySource, SourceRecord, Target, ToolEntry } from '@ai-primitives-hub/core';
7
+ import type { InstallRecordService, StatusRow } from './install-record-service';
8
+ import { type TargetMapping } from './map-tool-to-target';
9
+ import type { RecordHubInput } from './record-hub';
10
+ import type { RecordStore } from './record-store';
11
+ import type { RecordSelection } from './select-record';
12
+ /** One (bundle, tool) entry to write again, with its mapped target and decided source. */
13
+ export interface RecordPlanEntry {
14
+ bundleId: string;
15
+ tool: string;
16
+ /** The file that holds the entry; it is re-recorded there. */
17
+ location: RecordLocation;
18
+ entry: ToolEntry;
19
+ /** Source decided by the trust gate. */
20
+ source: SourceRecord & {
21
+ sourceId: string;
22
+ };
23
+ target: Target;
24
+ /** `true` when the source came from the record only and is fetched without credentials. */
25
+ fromRecordOnly: boolean;
26
+ /** The configured source's shareable hub, recorded with it. */
27
+ hub?: RecordHubInput;
28
+ }
29
+ /** A (bundle, tool) entry the plan left out, and why. */
30
+ export interface RecordPlanSkip {
31
+ bundleId: string;
32
+ tool: string;
33
+ reason: string;
34
+ }
35
+ /** Outcome of {@link planRecordEntries}. */
36
+ export interface RecordPlan {
37
+ items: RecordPlanEntry[];
38
+ /** Entries with no target or an untrusted source. */
39
+ skipped: RecordPlanSkip[];
40
+ /** Entries only a reinstall can restore; never planned. */
41
+ needsReinstall: StatusRow[];
42
+ /** Entries considered after the `--target` narrowing. */
43
+ considered: number;
44
+ /** Why a target was picked when several matched. */
45
+ notes: string[];
46
+ /** The cached tool-to-target mapping, for sibling tools. */
47
+ mapTool: (tool: string) => Promise<TargetMapping>;
48
+ }
49
+ /** Where an entry is re-recorded: the first file holding it (replay) or the file it was listed from (update). */
50
+ export type HoldingFileRule = 'first-holding' | 'listed';
51
+ /** Inputs of {@link planRecordEntries}. */
52
+ export interface PlanRecordEntriesOptions {
53
+ service: InstallRecordService;
54
+ store: RecordStore;
55
+ fs: RecordFs;
56
+ selection: RecordSelection;
57
+ targets: readonly Target[];
58
+ /** Configured sources by id, in lookup order. */
59
+ configured: ReadonlyMap<string, RegistrySource>;
60
+ /** Every configured source, of any hub; one from the recorded hub wins. */
61
+ candidates?: readonly RegistrySource[];
62
+ /** Shareable configured hubs by id. */
63
+ hubs?: ReadonlyMap<string, RecordHubInput>;
64
+ /** The target named by `--target`; only it narrows the plan to one tool. */
65
+ explicit?: Target;
66
+ /** Root of a target without `rootPath`. */
67
+ cwd: string;
68
+ holdingFile: HoldingFileRule;
69
+ }
70
+ /**
71
+ * Plan a record replay or update before any lookup or download.
72
+ * @param options - Plan inputs.
73
+ * @throws {RegistryError} Any `RECORD.*` error from loading a selected file.
74
+ */
75
+ export declare const planRecordEntries: (options: PlanRecordEntriesOptions) => Promise<RecordPlan>;
76
+ //# sourceMappingURL=plan-record-entries.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plan-record-entries.d.ts","sourceRoot":"","sources":["../../src/records/plan-record-entries.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EACV,QAAQ,EACR,cAAc,EACd,cAAc,EACd,YAAY,EACZ,MAAM,EACN,SAAS,EACV,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EACV,oBAAoB,EACpB,SAAS,EACV,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAEL,KAAK,aAAa,EACnB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EACV,cAAc,EACf,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EACV,WAAW,EACZ,MAAM,gBAAgB,CAAC;AAIxB,OAAO,KAAK,EACV,eAAe,EAChB,MAAM,iBAAiB,CAAC;AAEzB,0FAA0F;AAC1F,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,8DAA8D;IAC9D,QAAQ,EAAE,cAAc,CAAC;IACzB,KAAK,EAAE,SAAS,CAAC;IACjB,wCAAwC;IACxC,MAAM,EAAE,YAAY,GAAG;QAAE,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC;IAC5C,MAAM,EAAE,MAAM,CAAC;IACf,2FAA2F;IAC3F,cAAc,EAAE,OAAO,CAAC;IACxB,+DAA+D;IAC/D,GAAG,CAAC,EAAE,cAAc,CAAC;CACtB;AAED,yDAAyD;AACzD,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,4CAA4C;AAC5C,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,eAAe,EAAE,CAAC;IACzB,qDAAqD;IACrD,OAAO,EAAE,cAAc,EAAE,CAAC;IAC1B,2DAA2D;IAC3D,cAAc,EAAE,SAAS,EAAE,CAAC;IAC5B,yDAAyD;IACzD,UAAU,EAAE,MAAM,CAAC;IACnB,oDAAoD;IACpD,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,4DAA4D;IAC5D,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,aAAa,CAAC,CAAC;CACnD;AAED,iHAAiH;AACjH,MAAM,MAAM,eAAe,GAAG,eAAe,GAAG,QAAQ,CAAC;AAEzD,2CAA2C;AAC3C,MAAM,WAAW,wBAAwB;IACvC,OAAO,EAAE,oBAAoB,CAAC;IAC9B,KAAK,EAAE,WAAW,CAAC;IACnB,EAAE,EAAE,QAAQ,CAAC;IACb,SAAS,EAAE,eAAe,CAAC;IAC3B,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IAC3B,iDAAiD;IACjD,UAAU,EAAE,WAAW,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IAChD,2EAA2E;IAC3E,UAAU,CAAC,EAAE,SAAS,cAAc,EAAE,CAAC;IACvC,uCAAuC;IACvC,IAAI,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IAC3C,4EAA4E;IAC5E,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,2CAA2C;IAC3C,GAAG,EAAE,MAAM,CAAC;IACZ,WAAW,EAAE,eAAe,CAAC;CAC9B;AAED;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,GAAU,SAAS,wBAAwB,KAAG,OAAO,CAAC,UAAU,CAwE7F,CAAC"}
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.planRecordEntries = void 0;
4
+ const map_tool_to_target_1 = require("./map-tool-to-target");
5
+ const resolve_record_source_1 = require("./resolve-record-source");
6
+ /**
7
+ * Plan a record replay or update before any lookup or download.
8
+ * @param options - Plan inputs.
9
+ * @throws {RegistryError} Any `RECORD.*` error from loading a selected file.
10
+ */
11
+ const planRecordEntries = async (options) => {
12
+ const { service, store, fs, selection, targets, configured, explicit, cwd } = options;
13
+ const mappings = new Map();
14
+ const mapTool = async (tool) => {
15
+ let mapping = mappings.get(tool);
16
+ if (mapping === undefined) {
17
+ mapping = await (0, map_tool_to_target_1.mapToolToTarget)({ fs, tool, level: selection.level, gitRoot: selection.root, targets, explicit, cwd });
18
+ mappings.set(tool, mapping);
19
+ }
20
+ return mapping;
21
+ };
22
+ const plan = { items: [], skipped: [], needsReinstall: [], considered: 0, notes: [], mapTool };
23
+ const notes = new Set();
24
+ for (const row of await service.listEntries(selection.locations)) {
25
+ const { bundleId, tool } = row;
26
+ if (row.needsReinstall) {
27
+ plan.needsReinstall.push(row);
28
+ continue;
29
+ }
30
+ if (explicit !== undefined && tool !== explicit.type) {
31
+ continue;
32
+ }
33
+ plan.considered++;
34
+ const mapping = await mapTool(tool);
35
+ if ('skip' in mapping) {
36
+ plan.skipped.push({ bundleId, tool, reason: mapping.skip });
37
+ continue;
38
+ }
39
+ if (mapping.note !== undefined) {
40
+ notes.add(mapping.note);
41
+ }
42
+ const location = options.holdingFile === 'first-holding'
43
+ ? await service.holdingLocation(selection.locations, bundleId, tool)
44
+ : selection.locations.find((candidate) => candidate.path === row.record);
45
+ if (location === undefined) {
46
+ continue;
47
+ }
48
+ const { record } = await store.load(location);
49
+ const entry = record.bundles[bundleId].tools[tool];
50
+ const fromRecord = Object.hasOwn(record.sources, entry.sourceId) ? record.sources[entry.sourceId] : undefined;
51
+ if (fromRecord === undefined) {
52
+ plan.skipped.push({ bundleId, tool, reason: `source ${entry.sourceId} is not in the record` });
53
+ continue;
54
+ }
55
+ // Trust gate before any lookup or download.
56
+ const decision = await (0, resolve_record_source_1.resolveRecordSource)(entry.sourceId, fromRecord, configured, selection.root, fs, {
57
+ candidates: options.candidates,
58
+ hubs: options.hubs
59
+ });
60
+ if ('skip' in decision) {
61
+ plan.skipped.push({ bundleId, tool, reason: decision.skip });
62
+ continue;
63
+ }
64
+ plan.items.push({
65
+ bundleId,
66
+ tool,
67
+ location,
68
+ entry,
69
+ source: decision.use,
70
+ // A mapped target writes in the holding file's commit mode, so new files of a local-only
71
+ // entry stay excluded; a --target keeps its own, which a --commit-mode can set.
72
+ target: mapping.target === explicit || location.commitMode === undefined
73
+ || (mapping.target.commitMode ?? 'commit') === location.commitMode
74
+ ? mapping.target
75
+ : { ...mapping.target, commitMode: location.commitMode },
76
+ fromRecordOnly: decision.configured !== true,
77
+ ...(decision.hub === undefined ? {} : { hub: decision.hub })
78
+ });
79
+ }
80
+ plan.notes = [...notes];
81
+ return plan;
82
+ };
83
+ exports.planRecordEntries = planRecordEntries;
84
+ //# sourceMappingURL=plan-record-entries.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plan-record-entries.js","sourceRoot":"","sources":["../../src/records/plan-record-entries.ts"],"names":[],"mappings":";;;AAiBA,6DAG8B;AAO9B,mEAEiC;AAkEjC;;;;GAIG;AACI,MAAM,iBAAiB,GAAG,KAAK,EAAE,OAAiC,EAAuB,EAAE;IAChG,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,SAAS,EAAE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC;IACtF,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAyB,CAAC;IAClD,MAAM,OAAO,GAAG,KAAK,EAAE,IAAY,EAA0B,EAAE;QAC7D,IAAI,OAAO,GAAG,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACjC,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;YAC1B,OAAO,GAAG,MAAM,IAAA,oCAAe,EAAC,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,CAAC,KAAK,EAAE,OAAO,EAAE,SAAS,CAAC,IAAI,EAAE,OAAO,EAAE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