@jini-ai/agent-plugins 0.7.2 → 0.7.3-next.1

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 (235) hide show
  1. package/CHANGELOG.md +4 -6
  2. package/NOTICE +2 -0
  3. package/README.md +11 -15
  4. package/calendly/plugin.json +3 -3
  5. package/cloudflare/lib/forms.mjs +9 -10
  6. package/cloudflare/lib/target.mjs +1 -1
  7. package/cloudflare/plugin.json +3 -3
  8. package/cloudflare/worker/forms-receiver.mjs +9 -9
  9. package/composio/plugin.json +3 -3
  10. package/core/persistent-state.js +227 -163
  11. package/dist/admin-surfaces/connections/connections.d.ts +11 -6
  12. package/dist/admin-surfaces/connections/connections.js +102 -85
  13. package/dist/admin-surfaces/node.d.ts +27 -0
  14. package/dist/admin-surfaces/node.js +32 -0
  15. package/dist/admin-surfaces/plugin-state.js +21 -18
  16. package/dist/admin-surfaces/surface-client.d.ts +4 -0
  17. package/dist/admin-surfaces/surface-client.js +124 -117
  18. package/dist/admin-surfaces/surface-handlers.js +21 -17
  19. package/dist/admin-surfaces/theme.d.ts +5 -1
  20. package/dist/admin-surfaces/theme.js +3 -3
  21. package/dist/connect/access-token-tool.d.ts +3 -1
  22. package/dist/connect/access-token-tool.js +3 -2
  23. package/dist/connect/apply-connect-defaults.js +2 -2
  24. package/dist/connect/apply-tool-renames.js +9 -8
  25. package/dist/connect/connect-tool.d.ts +2 -0
  26. package/dist/connect/connect-tool.js +3 -2
  27. package/dist/connect/credential-cards.js +3 -2
  28. package/dist/connect/credential-save-tool.d.ts +14 -11
  29. package/dist/connect/credential-save-tool.js +128 -121
  30. package/dist/connect/enable-access.d.ts +2 -2
  31. package/dist/connect/enable-access.js +6 -6
  32. package/dist/connect/executable/register.js +40 -34
  33. package/dist/connect/federate-mcp.d.ts +21 -11
  34. package/dist/connect/federate-mcp.js +28 -21
  35. package/dist/connect/grant-signed-in-defaults.js +3 -3
  36. package/dist/connect/import-access-token.js +2 -1
  37. package/dist/connect/index.d.ts +1 -0
  38. package/dist/connect/index.js +1 -0
  39. package/dist/connect/plugin-credential-card.js +2 -1
  40. package/dist/connect/plugin-host/index.d.ts +9 -5
  41. package/dist/connect/plugin-host/index.js +113 -100
  42. package/dist/connect/ports.d.ts +1 -1
  43. package/dist/connect/row-update.d.ts +22 -0
  44. package/dist/connect/row-update.js +18 -0
  45. package/dist/connect/switch-on-saved-token.d.ts +4 -2
  46. package/dist/connect/switch-on-saved-token.js +1 -1
  47. package/dist/connect/token-map.d.ts +44 -0
  48. package/dist/connect/token-map.js +49 -0
  49. package/dist/core/identity-namespace.js +5 -0
  50. package/dist/folder-zip.d.ts +3 -1
  51. package/dist/folder-zip.js +2 -2
  52. package/dist/lifecycle/activation.d.ts +4 -4
  53. package/dist/lifecycle/activation.js +4 -5
  54. package/dist/lifecycle/automatic-use.js +236 -210
  55. package/dist/lifecycle/bundled-digests.d.ts +75 -12
  56. package/dist/lifecycle/bundled-digests.js +213 -212
  57. package/dist/lifecycle/bundled-source-archive.d.ts +1 -1
  58. package/dist/lifecycle/bundled-source-archive.js +263 -264
  59. package/dist/lifecycle/capability-projection.d.ts +1 -1
  60. package/dist/lifecycle/capability-projection.js +1 -1
  61. package/dist/lifecycle/credential-card-metadata.d.ts +1 -1
  62. package/dist/lifecycle/credential-card-metadata.js +27 -3
  63. package/dist/lifecycle/exports.js +9 -4
  64. package/dist/lifecycle/fetch-archive.d.ts +1 -1
  65. package/dist/lifecycle/fetch-archive.js +1 -1
  66. package/dist/lifecycle/host-tools/identity.js +3 -2
  67. package/dist/lifecycle/host-tools/ports.d.ts +2 -0
  68. package/dist/lifecycle/host-tools/search-tool.js +8 -8
  69. package/dist/lifecycle/host-tools/skill-tool.d.ts +18 -2
  70. package/dist/lifecycle/host-tools/skill-tool.js +16 -8
  71. package/dist/lifecycle/index.d.ts +118 -110
  72. package/dist/lifecycle/index.js +45 -12
  73. package/dist/lifecycle/install-errors.d.ts +1 -1
  74. package/dist/lifecycle/install-from-url.d.ts +1 -1
  75. package/dist/lifecycle/install-from-url.js +1 -1
  76. package/dist/lifecycle/install.d.ts +7 -2
  77. package/dist/lifecycle/install.js +414 -396
  78. package/dist/lifecycle/installed-package-index.js +45 -42
  79. package/dist/lifecycle/layout.d.ts +1 -1
  80. package/dist/lifecycle/layout.js +1 -1
  81. package/dist/lifecycle/mail/catalog.d.ts +8 -32
  82. package/dist/lifecycle/mail/catalog.js +25 -20
  83. package/dist/lifecycle/mail/contribution.d.ts +2 -2
  84. package/dist/lifecycle/mail/contribution.js +34 -34
  85. package/dist/lifecycle/mail/selection.js +6 -2
  86. package/dist/lifecycle/manifest.d.ts +3 -3
  87. package/dist/lifecycle/manifest.js +4 -4
  88. package/dist/lifecycle/mcp-provisioning.d.ts +3 -3
  89. package/dist/lifecycle/mcp-provisioning.js +3 -3
  90. package/dist/lifecycle/package-paths.d.ts +1 -1
  91. package/dist/lifecycle/package-paths.js +1 -1
  92. package/dist/lifecycle/persistent-state.js +1 -2
  93. package/dist/lifecycle/ports.d.ts +5 -1
  94. package/dist/lifecycle/resolve-agent-plugin-refs.d.ts +30 -8
  95. package/dist/lifecycle/resolve-agent-plugin-refs.js +227 -228
  96. package/dist/lifecycle/retire-bundled.d.ts +1 -52
  97. package/dist/lifecycle/retire-bundled.js +134 -84
  98. package/dist/lifecycle/search.d.ts +2 -1
  99. package/dist/lifecycle/search.js +1 -1
  100. package/dist/lifecycle/seed-bundled.d.ts +1 -1
  101. package/dist/lifecycle/seed-bundled.js +154 -155
  102. package/dist/lifecycle/set-enabled.d.ts +1 -1
  103. package/dist/lifecycle/set-enabled.js +1 -1
  104. package/dist/lifecycle/skill-file-reader.js +53 -50
  105. package/dist/lifecycle/tools/projection.d.ts +4 -7
  106. package/dist/lifecycle/tools/projection.js +109 -108
  107. package/dist/lifecycle/trusted-plugin-files.d.ts +2 -2
  108. package/dist/lifecycle/trusted-plugin-files.js +1 -1
  109. package/dist/lifecycle/uninstall.d.ts +1 -1
  110. package/dist/lifecycle/uninstall.js +237 -241
  111. package/dist/lifecycle/update-store.js +20 -17
  112. package/dist/lifecycle/update.js +287 -281
  113. package/dist/lifecycle/yauzl-archive-reader.d.ts +2 -2
  114. package/dist/lifecycle/yauzl-archive-reader.js +8 -2
  115. package/dist/manifest.d.ts +11 -3
  116. package/dist/manifest.js +9 -9
  117. package/fly/jini-credential-schemes.json +11 -0
  118. package/fly/plugin.json +3 -4
  119. package/github/plugin.json +3 -3
  120. package/github/source-control/backup-push.mjs +11 -11
  121. package/github/source-control/commit-site.mjs +3 -3
  122. package/github/source-control/github.mjs +12 -6
  123. package/github/source-control/write-files.mjs +27 -28
  124. package/github-pages/{tovu-deploy-targets.json → jini-deploy-targets.json} +22 -22
  125. package/github-pages/plugin.json +3 -3
  126. package/github-pages/targets/github-pages.mjs +3 -3
  127. package/google-login/plugin.json +3 -3
  128. package/google-workspace/README.md +14 -14
  129. package/google-workspace/form-destinations/README.md +3 -3
  130. package/google-workspace/form-destinations/dedupe.mjs +1 -1
  131. package/google-workspace/form-destinations/mapping.mjs +8 -9
  132. package/google-workspace/form-destinations/sheets.mjs +1 -1
  133. package/google-workspace/{tovu-admin-surfaces.json → jini-admin-surfaces.json} +2 -2
  134. package/google-workspace/{tovu-agent-tools.json → jini-agent-tools.json} +28 -28
  135. package/google-workspace/{tovu-connections.json → jini-connections.json} +2 -2
  136. package/google-workspace/lib/auth.mjs +2 -2
  137. package/google-workspace/lib/form-destination-settings.mjs +1 -1
  138. package/google-workspace/lib/picker-flow.mjs +2 -2
  139. package/google-workspace/lib/request-policy.mjs +1 -1
  140. package/google-workspace/lib/surface-actions.mjs +1 -1
  141. package/google-workspace/plugin.json +3 -3
  142. package/google-workspace/tools/sheets/README.md +3 -3
  143. package/google-workspace/tools/sheets-admin/README.md +3 -3
  144. package/google-workspace/ui/README.md +4 -4
  145. package/google-workspace/ui/connection-panel.mjs +51 -51
  146. package/google-workspace/ui/destination-panel.mjs +34 -34
  147. package/google-workspace/ui/dom.mjs +15 -16
  148. package/google-workspace/ui/picker-flow.mjs +2 -2
  149. package/google-workspace/ui/picker.mjs +19 -19
  150. package/google-workspace/ui/surface-client.mjs +96 -69
  151. package/higgsfield-media/plugin.json +3 -3
  152. package/jev/plugin.json +3 -3
  153. package/kuinetic/CHANGELOG.md +12 -0
  154. package/kuinetic/mcp.json +4 -0
  155. package/kuinetic/plugin.json +27 -0
  156. package/kuinetic/skills/kuinetic/SKILL.md +120 -0
  157. package/kuinetic/skills/kuinetic/references/effects-by-family.md +32 -0
  158. package/kuinetic/skills/kuinetic/references/opt-in-tiers.md +12 -0
  159. package/kuinetic/skills/kuinetic/references/reserved-keys.md +36 -0
  160. package/meilisearch/plugin.json +5 -5
  161. package/netlify/plugin.json +3 -3
  162. package/netlify/targets/netlify.mjs +14 -4
  163. package/opentelemetry/plugin.json +3 -3
  164. package/package.json +25 -20
  165. package/posthog/plugin.json +3 -3
  166. package/railway/plugin.json +3 -3
  167. package/render/plugin.json +3 -3
  168. package/resend/NOTES.md +2 -2
  169. package/resend/adapters/resend.mjs +1 -1
  170. package/resend/{tovu-mail-adapters.json → jini-mail-adapters.json} +1 -1
  171. package/resend/lib/domains.mjs +8 -8
  172. package/resend/plugin.json +3 -3
  173. package/s3-compatible/{tovu-deploy-targets.json → jini-deploy-targets.json} +68 -68
  174. package/s3-compatible/jini-object-stores.json +29 -0
  175. package/s3-compatible/object-stores/s3-compatible.mjs +19 -13
  176. package/s3-compatible/plugin.json +3 -3
  177. package/s3-compatible/targets/s3-compatible.mjs +25 -25
  178. package/sentry/plugin.json +3 -3
  179. package/shadcn-ui/CHANGELOG.md +7 -0
  180. package/shadcn-ui/LICENSE +201 -0
  181. package/shadcn-ui/NOTICE +10 -0
  182. package/shadcn-ui/mcp.json +4 -0
  183. package/shadcn-ui/plugin.json +26 -0
  184. package/shopify/plugin.json +3 -3
  185. package/site-compliance/plugin.json +3 -3
  186. package/site-import/plugin.json +3 -3
  187. package/supabase/mcp.json +1 -4
  188. package/supabase/plugin.json +3 -3
  189. package/ui-ux-design/CHANGELOG.md +13 -0
  190. package/ui-ux-design/NOTICE +2 -0
  191. package/ui-ux-design/README.md +17 -7
  192. package/ui-ux-design/plugin.json +6 -3
  193. package/ui-ux-design/skills/ui-ux-design/SKILL.md +38 -152
  194. package/ui-ux-design/skills/ui-ux-design/references/full-workflow.md +156 -0
  195. package/ui-ux-design/skills/ui-ux-design/references/ui-animation.md +4 -4
  196. package/vercel/NOTES.md +1 -1
  197. package/vercel/object-stores/vercel-blob.mjs +12 -2
  198. package/vercel/plugin.json +3 -3
  199. package/vercel/targets/vercel.mjs +3 -3
  200. package/wordpress/plugin.json +3 -3
  201. package/dist/lifecycle/node.d.ts +0 -11
  202. package/dist/lifecycle/node.js +0 -38
  203. package/fly/tovu-credential-schemes.json +0 -11
  204. package/github/deployments/github.mjs +0 -415
  205. package/s3-compatible/tovu-object-stores.json +0 -29
  206. package/ui-ux-design/skills/ui-ux-design/references/kuinetic-reference.md +0 -184
  207. /package/cloudflare/{tovu-consent.json → jini-consent.json} +0 -0
  208. /package/cloudflare/{tovu-deploy-targets.json → jini-deploy-targets.json} +0 -0
  209. /package/cloudflare/{tovu-form-destinations.json → jini-form-destinations.json} +0 -0
  210. /package/fly/{tovu-deploy-configs.json → jini-deploy-configs.json} +0 -0
  211. /package/fly/{tovu-deploy-ops.json → jini-deploy-ops.json} +0 -0
  212. /package/github/{tovu-deploy-ops.json → jini-deploy-ops.json} +0 -0
  213. /package/github/{tovu-source-control.json → jini-source-control.json} +0 -0
  214. /package/google-login/{tovu-login-providers.json → jini-login-providers.json} +0 -0
  215. /package/google-workspace/{tovu-form-destinations.json → jini-form-destinations.json} +0 -0
  216. /package/meilisearch/{tovu-search-providers.json → jini-search-providers.json} +0 -0
  217. /package/netlify/{tovu-consent.json → jini-consent.json} +0 -0
  218. /package/netlify/{tovu-deploy-targets.json → jini-deploy-targets.json} +0 -0
  219. /package/railway/{tovu-deploy-configs.json → jini-deploy-configs.json} +0 -0
  220. /package/railway/{tovu-deploy-ops.json → jini-deploy-ops.json} +0 -0
  221. /package/render/{tovu-deploy-configs.json → jini-deploy-configs.json} +0 -0
  222. /package/render/{tovu-deploy-ops.json → jini-deploy-ops.json} +0 -0
  223. /package/{ui-ux-design → shadcn-ui}/skills/shadcn-ui/README.md +0 -0
  224. /package/{ui-ux-design → shadcn-ui}/skills/shadcn-ui/SKILL.md +0 -0
  225. /package/{ui-ux-design → shadcn-ui}/skills/shadcn-ui/examples/auth-layout.tsx +0 -0
  226. /package/{ui-ux-design → shadcn-ui}/skills/shadcn-ui/examples/data-table.tsx +0 -0
  227. /package/{ui-ux-design → shadcn-ui}/skills/shadcn-ui/examples/form-pattern.tsx +0 -0
  228. /package/{ui-ux-design → shadcn-ui}/skills/shadcn-ui/resources/component-catalog.md +0 -0
  229. /package/{ui-ux-design → shadcn-ui}/skills/shadcn-ui/resources/customization-guide.md +0 -0
  230. /package/{ui-ux-design → shadcn-ui}/skills/shadcn-ui/resources/migration-guide.md +0 -0
  231. /package/{ui-ux-design → shadcn-ui}/skills/shadcn-ui/resources/setup-guide.md +0 -0
  232. /package/{ui-ux-design → shadcn-ui}/skills/shadcn-ui/scripts/verify-setup.sh +0 -0
  233. /package/vercel/{tovu-consent.json → jini-consent.json} +0 -0
  234. /package/vercel/{tovu-deploy-targets.json → jini-deploy-targets.json} +0 -0
  235. /package/vercel/{tovu-object-stores.json → jini-object-stores.json} +0 -0
@@ -68,233 +68,234 @@
68
68
  /** Extracted from the host plugin lifecycle. Effects are supplied per host context. */
69
69
  import path from "node:path";
70
70
  export const BUNDLED_DIGESTS_FILENAME = "bundled-digests.json";
71
- function buildModule(ports) {
72
- const open = ports.filesystem.open.bind(ports.filesystem);
73
- const readFile = ports.filesystem.readFile.bind(ports.filesystem);
74
- const rename = ports.filesystem.rename.bind(ports.filesystem);
75
- const rm = ports.filesystem.rm.bind(ports.filesystem);
76
- const randomUUID = () => ports.ids.newId();
77
- const SHA256_DIGEST_PATTERN = /^[a-f0-9]{64}$/;
78
- const SAFE_PLUGIN_ID_PATTERN = /^[a-z0-9]+(?:[-.][a-z0-9]+)*$/;
79
- const EMPTY_LEDGER = new Map();
80
- /**
81
- * Reads one workspace's bundled-digest ledger.
82
- *
83
- * @param workspaceRoot - `AgentPluginWorkspaceLayout.root`, never an instance-level path.
84
- * @returns The recorded plugin-id -> digest map, or an EMPTY map for a missing, unreadable,
85
- * malformed, or wrong-version file. Malformed INDIVIDUAL entries are skipped rather than discarding
86
- * the whole ledger, matching `activation.ts`'s own per-entry discipline.
87
- * @throws Nothing. An empty answer is always safe: it names no winner, so every ambiguity this
88
- * module could have resolved simply stays the explicit error it already was.
89
- * @complexity One file read plus O(p) in the recorded plugin count.
90
- */
91
- async function readBundledAgentPluginDigests(workspaceRoot) {
92
- let raw;
93
- try {
94
- raw = await readFile(path.join(workspaceRoot, BUNDLED_DIGESTS_FILENAME), "utf8");
95
- }
96
- catch {
97
- return EMPTY_LEDGER;
98
- }
99
- let parsed;
100
- try {
101
- parsed = JSON.parse(raw);
102
- }
103
- catch {
104
- return EMPTY_LEDGER;
105
- }
106
- return normalizeBundledDigests(parsed);
71
+ const SHA256_DIGEST_PATTERN = /^[a-f0-9]{64}$/;
72
+ const SAFE_PLUGIN_ID_PATTERN = /^[a-z0-9]+(?:[-.][a-z0-9]+)*$/;
73
+ const EMPTY_LEDGER = new Map();
74
+ /**
75
+ * Reads one workspace's bundled-digest ledger.
76
+ *
77
+ * @param workspaceRoot - `AgentPluginWorkspaceLayout.root`, never an instance-level path.
78
+ * @returns The recorded plugin-id -> digest map, or an EMPTY map for a missing, unreadable,
79
+ * malformed, or wrong-version file. Malformed INDIVIDUAL entries are skipped rather than discarding
80
+ * the whole ledger, matching `activation.ts`'s own per-entry discipline.
81
+ * @throws Nothing. An empty answer is always safe: it names no winner, so every ambiguity this
82
+ * module could have resolved simply stays the explicit error it already was.
83
+ * @complexity One file read plus O(p) in the recorded plugin count.
84
+ */
85
+ async function readBundledAgentPluginDigests({ ports, workspaceRoot }) {
86
+ let raw;
87
+ try {
88
+ raw = await ports.filesystem.readFile(path.join(workspaceRoot, BUNDLED_DIGESTS_FILENAME), "utf8");
107
89
  }
108
- /**
109
- * Validates an already-`JSON.parse`d ledger value, dropping anything that does not match the shape.
110
- * Pure, so the parsing rules are assertable without touching a filesystem.
111
- *
112
- * @complexity O(p) in the entry count.
113
- */
114
- function normalizeBundledDigests(value) {
115
- if (!isPlainObject(value) || value.schemaVersion !== 1 || !isPlainObject(value.plugins))
116
- return EMPTY_LEDGER;
117
- const digests = new Map();
118
- for (const [pluginId, entry] of Object.entries(value.plugins)) {
119
- const archiveDigest = SAFE_PLUGIN_ID_PATTERN.test(pluginId) && isPlainObject(entry) ? entry.archiveDigest : undefined;
120
- if (typeof archiveDigest === "string" && SHA256_DIGEST_PATTERN.test(archiveDigest))
121
- digests.set(pluginId, archiveDigest);
122
- }
123
- return digests;
90
+ catch {
91
+ return EMPTY_LEDGER;
124
92
  }
125
- /**
126
- * Records the digest this boot seeded for each bundled plugin, merged over whatever was already
127
- * recorded.
128
- *
129
- * MERGED, not replaced, for failure isolation (the property `seed-bundled.ts`'s header names): a
130
- * plugin that failed to seed this boot — an unreadable source directory, a transient I/O fault —
131
- * must not lose the perfectly good entry an earlier boot wrote for it, which is what a wholesale
132
- * rewrite of only this boot's successes would do.
133
- *
134
- * A plugin id seeded TWICE in one run under two different digests (two bundled source directories
135
- * declaring the same manifest `name`) is dropped from the ledger entirely, prior entry included:
136
- * the build itself is ambiguous about what it ships, so there is nothing authoritative to record and
137
- * the explicit ambiguity refusal downstream is the correct outcome.
138
- *
139
- * @param seeded - One entry per successfully seeded plugin. An empty list writes nothing at all —
140
- * not even an empty file — so a boot that seeded nothing cannot create a workspace directory or
141
- * truncate an existing ledger.
142
- * @throws {Error} Any filesystem fault from the write. The caller (`seed-bundled.ts`) captures it
143
- * into its report rather than failing the boot.
144
- * @complexity One file read and one atomic write, O(p) in the recorded plugin count.
145
- */
146
- async function recordBundledAgentPluginDigests(required) {
147
- if (required.seeded.length === 0)
148
- return;
149
- const existing = await readBundledAgentPluginDigests(required.workspaceRoot);
150
- const merged = new Map(existing);
151
- const seededAt = (required.now?.({}) ?? new Date(ports.clock.nowMs())).toISOString();
152
- for (const [pluginId, archiveDigest] of resolveThisBootsDigests(required.seeded)) {
153
- if (archiveDigest === undefined)
154
- merged.delete(pluginId);
155
- else
156
- merged.set(pluginId, archiveDigest);
157
- }
158
- const plugins = Object.fromEntries([...merged].map(([pluginId, archiveDigest]) => [pluginId, { archiveDigest, seededAt }]));
159
- await writeLedgerAtomically(required.workspaceRoot, plugins);
93
+ let parsed;
94
+ try {
95
+ parsed = JSON.parse(raw);
160
96
  }
161
- /**
162
- * This boot's verdict per plugin id: the digest it seeded, or `undefined` when the run seeded the
163
- * same id under two different digests and therefore has no authoritative answer for it.
164
- *
165
- * Split out as a pure step so the "a self-contradictory build records NOTHING" rule is assertable
166
- * without a filesystem, and so {@link recordBundledAgentPluginDigests} reads as merge-then-write.
167
- *
168
- * @complexity O(n) in the seeded-entry count.
169
- */
170
- function resolveThisBootsDigests(seeded) {
171
- const thisBoot = new Map();
172
- for (const { pluginId, archiveDigest } of seeded) {
173
- if (!SAFE_PLUGIN_ID_PATTERN.test(pluginId) || !SHA256_DIGEST_PATTERN.test(archiveDigest))
174
- continue;
175
- if (thisBoot.has(pluginId) && thisBoot.get(pluginId) !== archiveDigest)
176
- thisBoot.set(pluginId, undefined);
177
- else
178
- thisBoot.set(pluginId, archiveDigest);
179
- }
180
- return thisBoot;
97
+ catch {
98
+ return EMPTY_LEDGER;
181
99
  }
182
- /**
183
- * Drops one plugin id from the ledger — for `retire-bundled.ts`, once a retired bundled plugin's
184
- * packages are gone and no build will ever seed it again.
185
- *
186
- * Every other entry is kept byte-for-byte, `seededAt` included: this rewrites the raw `plugins` bag
187
- * rather than the normalized map, so it cannot lose a field a later schema adds. A missing,
188
- * unreadable, malformed, or wrong-version ledger, or one with no entry for `pluginId`, writes
189
- * nothing — there is nothing to drop, and a fail-closed reader already treats such a file as empty.
190
- *
191
- * @returns Whether an entry was removed.
192
- * @throws {Error} Any filesystem fault from the write. `retire-bundled.ts` captures it into its report.
193
- * @complexity One file read and at most one atomic write, O(p) in the recorded plugin count.
194
- */
195
- async function removeBundledAgentPluginDigest(required) {
196
- let parsed;
197
- try {
198
- parsed = JSON.parse(await readFile(path.join(required.workspaceRoot, BUNDLED_DIGESTS_FILENAME), "utf8"));
199
- }
200
- catch {
201
- return false;
202
- }
203
- if (!isPlainObject(parsed) || parsed.schemaVersion !== 1 || !isPlainObject(parsed.plugins))
204
- return false;
205
- if (!Object.hasOwn(parsed.plugins, required.pluginId))
206
- return false;
207
- const remaining = { ...parsed.plugins };
208
- delete remaining[required.pluginId];
209
- await writeLedgerAtomically(required.workspaceRoot, remaining);
210
- return true;
100
+ return normalizeBundledDigests(parsed);
101
+ }
102
+ /**
103
+ * Validates an already-`JSON.parse`d ledger value, dropping anything that does not match the shape.
104
+ * Pure, so the parsing rules are assertable without touching a filesystem.
105
+ *
106
+ * @complexity O(p) in the entry count.
107
+ */
108
+ function normalizeBundledDigests(value) {
109
+ if (!isPlainObject(value) || value.schemaVersion !== 1 || !isPlainObject(value.plugins))
110
+ return EMPTY_LEDGER;
111
+ const digests = new Map();
112
+ for (const [pluginId, entry] of Object.entries(value.plugins)) {
113
+ const archiveDigest = SAFE_PLUGIN_ID_PATTERN.test(pluginId) && isPlainObject(entry) ? entry.archiveDigest : undefined;
114
+ if (typeof archiveDigest === "string" && SHA256_DIGEST_PATTERN.test(archiveDigest))
115
+ digests.set(pluginId, archiveDigest);
116
+ }
117
+ return digests;
118
+ }
119
+ /**
120
+ * Records the digest this boot seeded for each bundled plugin, merged over whatever was already
121
+ * recorded.
122
+ *
123
+ * MERGED, not replaced, for failure isolation (the property `seed-bundled.ts`'s header names): a
124
+ * plugin that failed to seed this boot — an unreadable source directory, a transient I/O fault —
125
+ * must not lose the perfectly good entry an earlier boot wrote for it, which is what a wholesale
126
+ * rewrite of only this boot's successes would do.
127
+ *
128
+ * A plugin id seeded TWICE in one run under two different digests (two bundled source directories
129
+ * declaring the same manifest `name`) is dropped from the ledger entirely, prior entry included:
130
+ * the build itself is ambiguous about what it ships, so there is nothing authoritative to record and
131
+ * the explicit ambiguity refusal downstream is the correct outcome.
132
+ *
133
+ * @param seeded - One entry per successfully seeded plugin. An empty list writes nothing at all —
134
+ * not even an empty file — so a boot that seeded nothing cannot create a workspace directory or
135
+ * truncate an existing ledger.
136
+ * @throws {Error} Any filesystem fault from the write. The caller (`seed-bundled.ts`) captures it
137
+ * into its report rather than failing the boot.
138
+ * @complexity One file read and one atomic write, O(p) in the recorded plugin count.
139
+ */
140
+ async function recordBundledAgentPluginDigests(ports, required) {
141
+ if (required.seeded.length === 0)
142
+ return;
143
+ const existing = await readBundledAgentPluginDigests({ ports, workspaceRoot: required.workspaceRoot });
144
+ const merged = new Map(existing);
145
+ const seededAt = (required.now?.({}) ?? new Date(ports.clock.nowMs())).toISOString();
146
+ for (const [pluginId, archiveDigest] of resolveThisBootsDigests(required.seeded)) {
147
+ if (archiveDigest === undefined)
148
+ merged.delete(pluginId);
149
+ else
150
+ merged.set(pluginId, archiveDigest);
151
+ }
152
+ const plugins = Object.fromEntries([...merged].map(([pluginId, archiveDigest]) => [pluginId, { archiveDigest, seededAt }]));
153
+ await writeLedgerAtomically({ ports, workspaceRoot: required.workspaceRoot, plugins });
154
+ }
155
+ /**
156
+ * This boot's verdict per plugin id: the digest it seeded, or `undefined` when the run seeded the
157
+ * same id under two different digests and therefore has no authoritative answer for it.
158
+ *
159
+ * Split out as a pure step so the "a self-contradictory build records NOTHING" rule is assertable
160
+ * without a filesystem, and so {@link recordBundledAgentPluginDigests} reads as merge-then-write.
161
+ *
162
+ * @complexity O(n) in the seeded-entry count.
163
+ */
164
+ function resolveThisBootsDigests(seeded) {
165
+ const thisBoot = new Map();
166
+ for (const { pluginId, archiveDigest } of seeded) {
167
+ if (!SAFE_PLUGIN_ID_PATTERN.test(pluginId) || !SHA256_DIGEST_PATTERN.test(archiveDigest))
168
+ continue;
169
+ if (thisBoot.has(pluginId) && thisBoot.get(pluginId) !== archiveDigest)
170
+ thisBoot.set(pluginId, undefined);
171
+ else
172
+ thisBoot.set(pluginId, archiveDigest);
173
+ }
174
+ return thisBoot;
175
+ }
176
+ /**
177
+ * Drops one plugin id from the ledger — for `retire-bundled.ts`, once a retired bundled plugin's
178
+ * packages are gone and no build will ever seed it again.
179
+ *
180
+ * Every other entry is kept byte-for-byte, `seededAt` included: this rewrites the raw `plugins` bag
181
+ * rather than the normalized map, so it cannot lose a field a later schema adds. A missing,
182
+ * unreadable, malformed, or wrong-version ledger, or one with no entry for `pluginId`, writes
183
+ * nothing — there is nothing to drop, and a fail-closed reader already treats such a file as empty.
184
+ *
185
+ * @returns Whether an entry was removed.
186
+ * @throws {Error} Any filesystem fault from the write. `retire-bundled.ts` captures it into its report.
187
+ * @complexity One file read and at most one atomic write, O(p) in the recorded plugin count.
188
+ */
189
+ async function removeBundledAgentPluginDigest(ports, required) {
190
+ let parsed;
191
+ try {
192
+ parsed = JSON.parse(await ports.filesystem.readFile(path.join(required.workspaceRoot, BUNDLED_DIGESTS_FILENAME), "utf8"));
211
193
  }
212
- /** Temp-file-then-`rename`, so a reader never observes a half-written ledger and a crash mid-write
213
- * leaves the previous one intact — the same durability shape `activation.ts`'s
214
- * `writeActivationsAtomically` uses, minus its cross-process lock: this file has exactly one writer
215
- * (the boot seeder, retirement included), and two concurrent boots of the SAME build write byte-identical content.
216
- * @complexity One write and one rename. */
217
- async function writeLedgerAtomically(workspaceRoot, plugins) {
218
- const finalPath = path.join(workspaceRoot, BUNDLED_DIGESTS_FILENAME);
219
- const tempPath = `${finalPath}.tmp-${ports.process.pid}-${randomUUID()}`;
194
+ catch {
195
+ return false;
196
+ }
197
+ if (!isPlainObject(parsed) || parsed.schemaVersion !== 1 || !isPlainObject(parsed.plugins))
198
+ return false;
199
+ if (!Object.hasOwn(parsed.plugins, required.pluginId))
200
+ return false;
201
+ const remaining = { ...parsed.plugins };
202
+ delete remaining[required.pluginId];
203
+ await writeLedgerAtomically({ ports, workspaceRoot: required.workspaceRoot, plugins: remaining });
204
+ return true;
205
+ }
206
+ /** Temp-file-then-`rename`, so a reader never observes a half-written ledger and a crash mid-write
207
+ * leaves the previous one intact — the same durability shape `activation.ts`'s
208
+ * `writeActivationsAtomically` uses, minus its cross-process lock: this file has exactly one writer
209
+ * (the boot seeder, retirement included), and two concurrent boots of the SAME build write byte-identical content.
210
+ * @complexity One write and one rename. */
211
+ async function writeLedgerAtomically({ ports, workspaceRoot, plugins }) {
212
+ const finalPath = path.join(workspaceRoot, BUNDLED_DIGESTS_FILENAME);
213
+ const tempPath = `${finalPath}.tmp-${ports.process.pid}-${ports.ids.newId()}`;
214
+ try {
215
+ const handle = await ports.filesystem.open(tempPath, "wx", 0o600);
220
216
  try {
221
- const handle = await open(tempPath, "wx", 0o600);
222
- try {
223
- await handle.writeFile(`${JSON.stringify({ schemaVersion: 1, plugins }, null, 2)}\n`, "utf8");
224
- await handle.sync();
225
- }
226
- finally {
227
- await handle.close();
228
- }
229
- await rename(tempPath, finalPath);
217
+ await handle.writeFile(`${JSON.stringify({ schemaVersion: 1, plugins }, null, 2)}\n`, "utf8");
218
+ await handle.sync();
230
219
  }
231
- catch (error) {
232
- await rm(tempPath, { force: true });
233
- throw error;
220
+ finally {
221
+ await handle.close();
234
222
  }
223
+ await ports.filesystem.rename(tempPath, finalPath);
235
224
  }
236
- /**
237
- * Drops the SUPERSEDED installs of any bundled plugin id from a list of installed packages, leaving
238
- * every other entry — and every other plugin id — exactly as it was.
239
- *
240
- * An id is narrowed only when all three hold: it has more than one installed digest, the ledger
241
- * records a digest for it, and exactly one of its installed digests is that recorded one. Anything
242
- * else passes through untouched, so the caller's own ambiguity refusal still fires for every case
243
- * this module has no authority over (this file's header, consequences 1 and 2).
244
- *
245
- * Applied at READ time by the surfaces that must pick one package per plugin id. Deliberately NOT
246
- * folded into `listInstalledPlugins` itself: `uninstall.ts` needs to see EVERY digest of a plugin to
247
- * remove them, and a filter hidden inside the shared walk would make superseded bytes unremovable.
248
- *
249
- * @returns A list in the input's own order, with superseded entries removed. The input is never
250
- * mutated.
251
- * @complexity O(n) in the installed-package count, over one O(n) pre-pass that counts digests per
252
- * plugin id.
253
- */
254
- function preferBundledAgentPluginDigests(installed, bundled) {
255
- if (bundled.size === 0)
256
- return installed;
257
- const supersededIds = idsNarrowableToTheirBundledDigest(installed, bundled);
258
- if (supersededIds.size === 0)
259
- return installed;
260
- return installed.filter((plugin) => !supersededIds.has(plugin.pluginId) || plugin.archiveDigest === bundled.get(plugin.pluginId));
225
+ catch (error) {
226
+ await ports.filesystem.rm(tempPath, { force: true });
227
+ throw error;
261
228
  }
262
- /**
263
- * The plugin ids whose installed digests the ledger can authoritatively narrow to one — every id
264
- * that is installed under several digests, exactly one of which is the digest this build seeded.
265
- *
266
- * @complexity O(n) in the installed-package count.
267
- */
268
- function idsNarrowableToTheirBundledDigest(installed, bundled) {
269
- const digestsByPluginId = new Map();
270
- for (const plugin of installed) {
271
- const digests = digestsByPluginId.get(plugin.pluginId) ?? new Set();
272
- digests.add(plugin.archiveDigest);
273
- digestsByPluginId.set(plugin.pluginId, digests);
274
- }
275
- const narrowable = new Set();
276
- for (const [pluginId, digests] of digestsByPluginId) {
277
- if (digests.size < 2)
278
- continue;
279
- const bundledDigest = bundled.get(pluginId);
280
- if (bundledDigest !== undefined && digests.has(bundledDigest))
281
- narrowable.add(pluginId);
282
- }
283
- return narrowable;
229
+ }
230
+ /**
231
+ * Drops the SUPERSEDED installs of any bundled plugin id from a list of installed packages, leaving
232
+ * every other entry — and every other plugin id — exactly as it was.
233
+ *
234
+ * An id is narrowed only when all three hold: it has more than one installed digest, the ledger
235
+ * records a digest for it, and exactly one of its installed digests is that recorded one. Anything
236
+ * else passes through untouched, so the caller's own ambiguity refusal still fires for every case
237
+ * this module has no authority over (this file's header, consequences 1 and 2).
238
+ *
239
+ * Applied at READ time by the surfaces that must pick one package per plugin id. Deliberately NOT
240
+ * folded into `listInstalledPlugins` itself: `uninstall.ts` needs to see EVERY digest of a plugin to
241
+ * remove them, and a filter hidden inside the shared walk would make superseded bytes unremovable.
242
+ *
243
+ * @returns A list in the input's own order, with superseded entries removed. The input is never
244
+ * mutated.
245
+ * @complexity O(n) in the installed-package count, over one O(n) pre-pass that counts digests per
246
+ * plugin id.
247
+ */
248
+ function preferBundledAgentPluginDigests(installed, bundled) {
249
+ if (bundled.size === 0)
250
+ return installed;
251
+ const supersededIds = idsNarrowableToTheirBundledDigest(installed, bundled);
252
+ if (supersededIds.size === 0)
253
+ return installed;
254
+ return installed.filter((plugin) => !supersededIds.has(plugin.pluginId) || plugin.archiveDigest === bundled.get(plugin.pluginId));
255
+ }
256
+ /**
257
+ * The plugin ids whose installed digests the ledger can authoritatively narrow to one — every id
258
+ * that is installed under several digests, exactly one of which is the digest this build seeded.
259
+ *
260
+ * @complexity O(n) in the installed-package count.
261
+ */
262
+ function idsNarrowableToTheirBundledDigest(installed, bundled) {
263
+ const digestsByPluginId = new Map();
264
+ for (const plugin of installed) {
265
+ const digests = digestsByPluginId.get(plugin.pluginId) ?? new Set();
266
+ digests.add(plugin.archiveDigest);
267
+ digestsByPluginId.set(plugin.pluginId, digests);
284
268
  }
285
- /** Whether `value` is a plain (non-null, non-array) object — the shape both this file's JSON-adjacent
286
- * values must have before their own fields are worth looking at. Duplicated from `activation.ts`'s
287
- * private helper of the same name rather than widening that module's public surface, matching this
288
- * codebase's own precedent for small private formatting/shape helpers (see `resolve-agent-plugin-
289
- * refs.ts`'s note on `humanize()`). */
290
- function isPlainObject(value) {
291
- return typeof value === "object" && value !== null && !Array.isArray(value);
269
+ const narrowable = new Set();
270
+ for (const [pluginId, digests] of digestsByPluginId) {
271
+ if (digests.size < 2)
272
+ continue;
273
+ const bundledDigest = bundled.get(pluginId);
274
+ if (bundledDigest !== undefined && digests.has(bundledDigest))
275
+ narrowable.add(pluginId);
292
276
  }
293
- return { readBundledAgentPluginDigests, normalizeBundledDigests, recordBundledAgentPluginDigests, removeBundledAgentPluginDigest, preferBundledAgentPluginDigests };
277
+ return narrowable;
278
+ }
279
+ /** Whether `value` is a plain (non-null, non-array) object — the shape both this file's JSON-adjacent
280
+ * values must have before their own fields are worth looking at. Duplicated from `activation.ts`'s
281
+ * private helper of the same name rather than widening that module's public surface, matching this
282
+ * codebase's own precedent for small private formatting/shape helpers (see `resolve-agent-plugin-
283
+ * refs.ts`'s note on `humanize()`). */
284
+ function isPlainObject(value) {
285
+ return typeof value === "object" && value !== null && !Array.isArray(value);
286
+ }
287
+ function buildModule(ports) {
288
+ return {
289
+ readBundledAgentPluginDigests: (workspaceRoot) => readBundledAgentPluginDigests({ ports, workspaceRoot }),
290
+ normalizeBundledDigests,
291
+ recordBundledAgentPluginDigests: (required) => recordBundledAgentPluginDigests(ports, required),
292
+ removeBundledAgentPluginDigest: (required) => removeBundledAgentPluginDigest(ports, required),
293
+ preferBundledAgentPluginDigests,
294
+ };
294
295
  }
295
296
  const instances = new WeakMap();
296
297
  /** Internal composition; one state/queue instance per injected host context. */
297
- export function createBundledDigestsModule(ports) {
298
+ export function createBundledDigestsModule(ports, _optional = {}) {
298
299
  let instance = instances.get(ports);
299
300
  if (!instance) {
300
301
  instance = buildModule(ports);
@@ -38,7 +38,7 @@ export interface PackAgentPluginDirectoryOptional {
38
38
  readonly digestEncoding?: 'bundled-v1' | 'canonical-files-v1';
39
39
  }
40
40
  /** Internal composition; one state/queue instance per injected host context. */
41
- export declare function createBundledSourceArchiveModule(ports: AgentPluginLifecyclePorts): {
41
+ export declare function createBundledSourceArchiveModule(ports: AgentPluginLifecyclePorts, _optional?: Record<string, never>): {
42
42
  packAgentPluginDirectory: (sourceDir: string, options?: PackAgentPluginDirectoryOptional) => Promise<PackedAgentPluginArchive>;
43
43
  createBundledSourceArchiveReader: () => AgentPluginArchiveReaderPort;
44
44
  };