@jini-ai/agent-plugins 0.7.1 → 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 -4
  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
@@ -1,101 +1,151 @@
1
+ /**
2
+ * @file `retireBundledAgentPlugins()` — removes bundled Agent Plugins the host no longer ships from a
3
+ * workspace, and moves their users onto the plugin that absorbed them. Runs on every boot from
4
+ * `seed-bundled.ts`, after seeding, and is a no-op once a workspace has been migrated.
5
+ *
6
+ * ---------------------------------------------------------------------------
7
+ * Why a retirement step exists
8
+ * ---------------------------------------------------------------------------
9
+ * Deleting `content/agent-plugins/<id>/` stops the seeder installing a plugin, but it removes nothing
10
+ * a workspace already has: the installed package stays under `packages/sha256/`, its activation
11
+ * record stays in `activations.json`, and its digest stays in `bundled-digests.json`. An ENABLED
12
+ * leftover keeps its skill in every prompt, now duplicating (and slowly contradicting) the successor
13
+ * that carries the same content. And the operator cannot remove it: `uninstall.ts` refuses a
14
+ * bundled plugin because it would be re-seeded, which is exactly what stops being true here. Owner
15
+ * rule: the user never fixes anything by hand, so the boot does it.
16
+ *
17
+ * ---------------------------------------------------------------------------
18
+ * What happens per retired id (idempotent)
19
+ * ---------------------------------------------------------------------------
20
+ * 1. Nothing installed and no activation record: nothing to do (the second boot after a migration).
21
+ * A leftover ledger entry is still dropped.
22
+ * 1a. Otherwise EVERY successor must be usable first: installed at the digest `bundled-digests.json`
23
+ * records for it (the build's own seed — the same trust `trusted-plugin-files.ts` demands before
24
+ * core takes a contribution from it), whether it seeded this boot or on an earlier one. If any
25
+ * is not, the retired plugin is KEPT and the outcome is `failed` with the reason; the next boot
26
+ * retries. Without this a successor whose seed failed (a broken `plugin.json`, a full disk) left
27
+ * the retired plugin removed and only an activation record for the successor — a switch with no
28
+ * code behind it (R6, 2026-10-12). A plugin split into several (`deploy` -> `fly`, `render`, ...)
29
+ * is kept until all of them are usable: one working successor must not cost the others' capability.
30
+ * 2. The retired plugin was ENABLED (explicitly, or by the "absent means active" default while its
31
+ * package is installed): the successor is switched on — unless an operator explicitly turned the
32
+ * successor off, which is left exactly as it is and reported in the outcome. No silent override.
33
+ * 3. The retired plugin's package(s) and activation record are removed through `uninstall.ts`
34
+ * (`retiredBundled: true` skips only its bundled refusal). A record with no package left is
35
+ * deleted directly.
36
+ * 4. The retired id is dropped from `bundled-digests.json`.
37
+ *
38
+ * A malformed or unreadable activation record for the retired id stops that id's retirement with a
39
+ * `failed` outcome and changes nothing: whether the operator had it enabled cannot be established,
40
+ * so neither enabling the successor nor deleting the record is safe. The next boot retries.
41
+ *
42
+ * Out of scope on purpose: nothing a retired plugin could own survives it. Agent Plugins have no
43
+ * per-plugin settings store (a workspace's `data/<pluginId>` directory has no production writer),
44
+ * and custom credentials (a saved `fly.io` token, say) belong to the workspace, not to a plugin.
45
+ *
46
+ * Architectural role:
47
+ * Composition over `activation.ts`, `uninstall.ts`, and `bundled-digests.ts`. Never throws: every
48
+ * failure is captured per id, exactly like `seed-bundled.ts`'s own outcomes, so one stuck retirement
49
+ * cannot stop a workspace from booting.
50
+ */
51
+ /** Extracted from the host plugin lifecycle. Effects are supplied per host context. */
52
+ import { describeErrorForLog } from "@jini-ai/core";
1
53
  import { createActivationModule } from "./activation.js";
2
54
  import { createBundledDigestsModule } from "./bundled-digests.js";
3
55
  import { createResolveAgentPluginRefsModule } from "./resolve-agent-plugin-refs.js";
4
56
  import { createUninstallModule } from "./uninstall.js";
5
- function buildModule(ports) {
6
- const { deleteAgentPluginActivation, enableBundledAgentPluginUnlessOperatorDisabled, readAgentPluginActivations, resolveAgentPluginActivation } = createActivationModule(ports);
7
- const { readBundledAgentPluginDigests, removeBundledAgentPluginDigest } = createBundledDigestsModule(ports);
8
- const { listInstalledPlugins } = createResolveAgentPluginRefsModule(ports);
9
- const { uninstallAgentPlugin } = createUninstallModule(ports);
10
- /**
11
- * Retires every id in `retired` from one workspace. See this file's header for the steps.
12
- *
13
- * @returns One outcome per retired id, in map order.
14
- * @throws Nothing.
15
- * @complexity O(r) retired ids, each one `listInstalledPlugins` walk plus a few small file writes.
16
- */
17
- async function retireBundledAgentPlugins(required, optional = {}) {
18
- const outcomes = [];
19
- for (const [pluginId, successor] of optional.retired ?? ports.retiredBundledPlugins) {
20
- const successorIds = typeof successor === "string" ? [successor] : successor;
21
- const ids = { successorId: successorIds[0] ?? "", ...(typeof successor === "string" ? {} : { successorIds }) };
22
- try {
23
- outcomes.push(await retireOne(required, optional, pluginId, ids));
24
- }
25
- catch (error) {
26
- outcomes.push({ pluginId, ...ids, status: "failed", reason: error instanceof Error ? error.message : String(error) });
27
- }
28
- }
29
- return outcomes;
30
- }
31
- // The successor first: if a later step fails, the operator keeps the capability, and the next boot
32
- // (which finds this step already done) retries only what is left.
33
- async function retireOne(required, optional, pluginId, ids) {
34
- const workspaceLayout = required.layout.forWorkspace({ workspaceId: required.workspaceId });
35
- const workspaceRoot = workspaceLayout.root;
36
- const successorIds = ids.successorIds ?? [ids.successorId];
37
- const verdict = await resolveAgentPluginActivation(workspaceRoot, pluginId);
38
- if (verdict.verdict === "undetermined") {
39
- return { pluginId, ...ids, status: "failed", reason: `cannot tell whether '${pluginId}' was enabled: ${verdict.reason}` };
40
- }
41
- const allInstalled = await listInstalledPlugins(workspaceLayout.root);
42
- const installed = allInstalled.filter((plugin) => plugin.pluginId === pluginId);
43
- const hasRecord = Object.hasOwn((await readAgentPluginActivations(workspaceRoot)).plugins, pluginId);
44
- if (installed.length === 0 && !hasRecord)
45
- return dropLeftoverLedgerEntry({ workspaceRoot, pluginId, ids });
46
- const unusable = await unusableSuccessor(workspaceRoot, allInstalled, successorIds);
47
- if (unusable !== undefined) {
48
- return { pluginId, ...ids, status: "failed", reason: `'${pluginId}' is kept until every successor is usable: ${unusable}` };
57
+ /**
58
+ * Retires every id in `retired` from one workspace. See this file's header for the steps.
59
+ *
60
+ * @returns One outcome per retired id, in map order.
61
+ * @throws Nothing.
62
+ * @complexity O(r) retired ids, each one `createResolveAgentPluginRefsModule(ports).listInstalledPlugins` walk plus a few small file writes.
63
+ */
64
+ async function retireBundledAgentPlugins({ ports, required }, optional = {}) {
65
+ const outcomes = [];
66
+ for (const [pluginId, successor] of optional.retired ?? ports.retiredBundledPlugins) {
67
+ const successorIds = typeof successor === "string" ? [successor] : successor;
68
+ const ids = { successorId: successorIds[0] ?? "", ...(typeof successor === "string" ? {} : { successorIds }) };
69
+ try {
70
+ outcomes.push(await retireOne({ ports, required, optional, pluginId, ids }));
49
71
  }
50
- const successors = await switchOnSuccessors({ workspaceRoot, pluginId, successorIds, wasActive: verdict.verdict === "active" }, { now: optional.now });
51
- const successor = successors[ids.successorId] ?? "not-needed";
52
- let removedDigests = [];
53
- if (installed.length > 0) {
54
- removedDigests = (await uninstallAgentPlugin({ layout: required.layout, workspaceId: required.workspaceId, pluginId }, { retiredBundled: true })).removedDigests;
72
+ catch (error) {
73
+ outcomes.push({ pluginId, ...ids, status: "failed", reason: describeErrorForLog({ err: error }) });
55
74
  }
56
- else {
57
- await deleteAgentPluginActivation({ workspaceRoot, pluginId });
58
- }
59
- const ledgerEntryRemoved = await removeBundledAgentPluginDigest({ workspaceRoot, pluginId });
60
- return { pluginId, ...ids, status: "retired", removedDigests, activationRemoved: hasRecord, ledgerEntryRemoved, successor, ...(ids.successorIds ? { successors } : {}) };
61
75
  }
62
- /** Step 1: nothing installed and no record — only a leftover ledger entry can remain to drop. */
63
- async function dropLeftoverLedgerEntry({ workspaceRoot, pluginId, ids }) {
64
- const ledgerEntryRemoved = await removeBundledAgentPluginDigest({ workspaceRoot, pluginId });
65
- if (!ledgerEntryRemoved)
66
- return { pluginId, ...ids, status: "absent" };
67
- return { pluginId, ...ids, status: "retired", removedDigests: [], activationRemoved: false, ledgerEntryRemoved, successor: "not-needed", ...(ids.successorIds ? { successors: {} } : {}) };
76
+ return outcomes;
77
+ }
78
+ // The successor first: if a later step fails, the operator keeps the capability, and the next boot
79
+ // (which finds this step already done) retries only what is left.
80
+ async function retireOne({ ports, required, optional, pluginId, ids }) {
81
+ const workspaceLayout = required.layout.forWorkspace({ workspaceId: required.workspaceId });
82
+ const workspaceRoot = workspaceLayout.root;
83
+ const successorIds = ids.successorIds ?? [ids.successorId];
84
+ const verdict = await createActivationModule(ports).resolveAgentPluginActivation(workspaceRoot, pluginId);
85
+ if (verdict.verdict === "undetermined") {
86
+ return { pluginId, ...ids, status: "failed", reason: `cannot tell whether '${pluginId}' was enabled: ${verdict.reason}` };
87
+ }
88
+ const allInstalled = await createResolveAgentPluginRefsModule(ports).listInstalledPlugins(workspaceLayout.root);
89
+ const installed = allInstalled.filter((plugin) => plugin.pluginId === pluginId);
90
+ const hasRecord = Object.hasOwn((await createActivationModule(ports).readAgentPluginActivations(workspaceRoot)).plugins, pluginId);
91
+ if (installed.length === 0 && !hasRecord)
92
+ return dropLeftoverLedgerEntry(ports, { workspaceRoot, pluginId, ids });
93
+ const unusable = await unusableSuccessor({ ports, workspaceRoot, allInstalled, successorIds });
94
+ if (unusable !== undefined) {
95
+ return { pluginId, ...ids, status: "failed", reason: `'${pluginId}' is kept until every successor is usable: ${unusable}` };
68
96
  }
69
- /** Step 2: each successor's outcome — switched on only when the retired plugin was active. */
70
- async function switchOnSuccessors({ workspaceRoot, pluginId, successorIds, wasActive }, { now } = {}) {
71
- const successors = {};
72
- for (const successorId of successorIds) {
73
- successors[successorId] = wasActive
74
- ? await enableBundledAgentPluginUnlessOperatorDisabled({ workspaceRoot, pluginId: successorId, actor: `system:retire-${pluginId}`, ...(now !== undefined ? { now } : {}) })
75
- : "not-needed";
76
- }
77
- return successors;
97
+ const successors = await switchOnSuccessors({ ports, workspaceRoot, pluginId, successorIds, wasActive: verdict.verdict === "active" }, { now: optional.now });
98
+ const successor = successors[ids.successorId] ?? "not-needed";
99
+ let removedDigests = [];
100
+ if (installed.length > 0) {
101
+ removedDigests = (await createUninstallModule(ports).uninstallAgentPlugin({ layout: required.layout, workspaceId: required.workspaceId, pluginId }, { retiredBundled: true })).removedDigests;
78
102
  }
79
- /** Why one of `successorIds` cannot take over yet, or `undefined` when every one is installed at the
80
- * digest the ledger records for it (this file's header, step 1a).
81
- * @complexity O(s * n) for s successors over n installed packages; both are small bundled counts. */
82
- async function unusableSuccessor(workspaceRoot, allInstalled, successorIds) {
83
- const ledger = await readBundledAgentPluginDigests(workspaceRoot);
84
- for (const successorId of successorIds) {
85
- const digest = ledger.get(successorId);
86
- if (digest === undefined)
87
- return `successor '${successorId}' has never been seeded into this workspace`;
88
- if (!allInstalled.some((plugin) => plugin.pluginId === successorId && plugin.archiveDigest === digest)) {
89
- return `successor '${successorId}' is not installed at its seeded digest`;
90
- }
103
+ else {
104
+ await createActivationModule(ports).deleteAgentPluginActivation({ workspaceRoot, pluginId });
105
+ }
106
+ const ledgerEntryRemoved = await createBundledDigestsModule(ports).removeBundledAgentPluginDigest({ workspaceRoot, pluginId });
107
+ return { pluginId, ...ids, status: "retired", removedDigests, activationRemoved: hasRecord, ledgerEntryRemoved, successor, ...(ids.successorIds ? { successors } : {}) };
108
+ }
109
+ /** Step 1: nothing installed and no record — only a leftover ledger entry can remain to drop. */
110
+ async function dropLeftoverLedgerEntry(ports, { workspaceRoot, pluginId, ids }) {
111
+ const ledgerEntryRemoved = await createBundledDigestsModule(ports).removeBundledAgentPluginDigest({ workspaceRoot, pluginId });
112
+ if (!ledgerEntryRemoved)
113
+ return { pluginId, ...ids, status: "absent" };
114
+ return { pluginId, ...ids, status: "retired", removedDigests: [], activationRemoved: false, ledgerEntryRemoved, successor: "not-needed", ...(ids.successorIds ? { successors: {} } : {}) };
115
+ }
116
+ /** Step 2: each successor's outcome — switched on only when the retired plugin was active. */
117
+ async function switchOnSuccessors({ ports, workspaceRoot, pluginId, successorIds, wasActive }, { now } = {}) {
118
+ const successors = {};
119
+ for (const successorId of successorIds) {
120
+ successors[successorId] = wasActive
121
+ ? await createActivationModule(ports).enableBundledAgentPluginUnlessOperatorDisabled({ workspaceRoot, pluginId: successorId, actor: `system:retire-${pluginId}`, ...(now !== undefined ? { now } : {}) })
122
+ : "not-needed";
123
+ }
124
+ return successors;
125
+ }
126
+ /** Why one of `successorIds` cannot take over yet, or `undefined` when every one is installed at the
127
+ * digest the ledger records for it (this file's header, step 1a).
128
+ * @complexity O(s * n) for s successors over n installed packages; both are small bundled counts. */
129
+ async function unusableSuccessor({ ports, workspaceRoot, allInstalled, successorIds }) {
130
+ const ledger = await createBundledDigestsModule(ports).readBundledAgentPluginDigests(workspaceRoot);
131
+ for (const successorId of successorIds) {
132
+ const digest = ledger.get(successorId);
133
+ if (digest === undefined)
134
+ return `successor '${successorId}' has never been seeded into this workspace`;
135
+ if (!allInstalled.some((plugin) => plugin.pluginId === successorId && plugin.archiveDigest === digest)) {
136
+ return `successor '${successorId}' is not installed at its seeded digest`;
91
137
  }
92
- return undefined;
93
138
  }
94
- return { retireBundledAgentPlugins };
139
+ return undefined;
140
+ }
141
+ function buildModule(ports) {
142
+ return {
143
+ retireBundledAgentPlugins: (required, optional = {}) => retireBundledAgentPlugins({ ports, required }, optional),
144
+ };
95
145
  }
96
146
  const instances = new WeakMap();
97
147
  /** Internal composition; one state/queue instance per injected host context. */
98
- export function createRetireBundledModule(ports) {
148
+ export function createRetireBundledModule(ports, _optional = {}) {
99
149
  let instance = instances.get(ports);
100
150
  if (!instance) {
101
151
  instance = buildModule(ports);
@@ -74,6 +74,7 @@ export interface AgentPluginSearchCandidate {
74
74
  readonly keywords: readonly string[];
75
75
  readonly id?: string | undefined;
76
76
  readonly provides?: readonly string[] | undefined;
77
+ readonly requires?: readonly string[] | undefined;
77
78
  /** Whether this workspace currently has the plugin enabled — reflects `activation.ts`'s
78
79
  * absent-means-active default, same as everywhere else this codebase reads activation state. */
79
80
  readonly enabled: boolean;
@@ -87,7 +88,7 @@ export interface AgentPluginSearchMatch extends AgentPluginSearchCandidate {
87
88
  readonly score: number;
88
89
  }
89
90
  /** Internal composition; one state/queue instance per injected host context. */
90
- export declare function createSearchModule(ports: AgentPluginLifecyclePorts): {
91
+ export declare function createSearchModule(ports: AgentPluginLifecyclePorts, _optional?: Record<string, never>): {
91
92
  rankInstalledAgentPlugins: (query: string, candidates: readonly AgentPluginSearchCandidate[], limit: number, automatic?: boolean) => readonly AgentPluginSearchMatch[];
92
93
  };
93
94
  //# sourceMappingURL=search.d.ts.map
@@ -112,7 +112,7 @@ function buildModule(ports) {
112
112
  }
113
113
  const instances = new WeakMap();
114
114
  /** Internal composition; one state/queue instance per injected host context. */
115
- export function createSearchModule(ports) {
115
+ export function createSearchModule(ports, _optional = {}) {
116
116
  let instance = instances.get(ports);
117
117
  if (!instance) {
118
118
  instance = buildModule(ports);
@@ -49,7 +49,7 @@ export interface SeedBundledAgentPluginsRequired {
49
49
  readonly sourceRoot: string;
50
50
  }
51
51
  /** Internal composition; one state/queue instance per injected host context. */
52
- export declare function createSeedBundledModule(ports: AgentPluginLifecyclePorts): {
52
+ export declare function createSeedBundledModule(ports: AgentPluginLifecyclePorts, _optional?: Record<string, never>): {
53
53
  seedBundledAgentPlugins: (required: SeedBundledAgentPluginsRequired, optional?: SeedBundledAgentPluginsOptional) => Promise<SeedBundledAgentPluginsResult>;
54
54
  };
55
55
  //# sourceMappingURL=seed-bundled.d.ts.map
@@ -79,178 +79,177 @@
79
79
  */
80
80
  import { createPersistentStateModule } from "./persistent-state.js";
81
81
  import path from "node:path";
82
+ import { describeErrorForLog } from "@jini-ai/core";
82
83
  import { createActivationModule } from "./activation.js";
83
84
  import { createBundledDigestsModule } from "./bundled-digests.js";
84
85
  import { createBundledSourceArchiveModule } from "./bundled-source-archive.js";
85
86
  import { createInstallModule } from "./install.js";
86
87
  import { createRetireBundledModule } from "./retire-bundled.js";
87
- function buildModule(ports) {
88
- const readdir = ports.filesystem.readdir.bind(ports.filesystem);
89
- const stat = ports.filesystem.stat.bind(ports.filesystem);
90
- const { assertAgentPluginActivationsWritable, recordBundledAgentPluginIfAbsent } = createActivationModule(ports);
91
- const { recordBundledAgentPluginDigests } = createBundledDigestsModule(ports);
92
- const { createBundledSourceArchiveReader, packAgentPluginDirectory } = createBundledSourceArchiveModule(ports);
93
- const { installAgentPlugin } = createInstallModule(ports);
94
- const { retireBundledAgentPlugins } = createRetireBundledModule(ports);
95
- /**
96
- * Installs every bundled Agent Plugin into one workspace and records each inactive-by-default,
97
- * except {@link BUNDLED_AGENT_PLUGINS_SEEDED_ENABLED}.
98
- *
99
- * @returns A per-plugin report. An absent or unreadable `sourceRoot` yields an empty `outcomes`
100
- * list rather than an error: a build that shipped no bundled plugins is a legitimate configuration,
101
- * and a self-hosted operator who deleted the directory has made a choice this function should not
102
- * override by crashing.
103
- * @throws Nothing. Every per-plugin failure is captured into the report.
104
- * @complexity O(p) plugins, each O(f) files and O(b) bytes — all bounded by
105
- * `bundled-source-archive.ts`'s file cap and `install.ts`'s own byte caps.
106
- */
107
- // The migration must finish before new installs, including bundled packages, are published.
108
- // Rejected legacy entries are preserved in quarantine and count as handled. An incomplete run
109
- // means a move/quarantine failed; a held lock also refuses seeding until migration can finish.
110
- // ONE strict pre-flight read BEFORE any install — so a bundled package never lands on disk
111
- // without the activation record that would keep it inactive (this file's header). Every bundled
112
- // plugin is reported failed with the SAME reason, rather than attempting each one and hitting the
113
- // identical fault p times.
114
- // AFTER every install, never before: the ledger names digests, and a digest is only worth naming
115
- // once its bytes are actually on disk for this workspace.
116
- // AFTER seeding and the ledger: a retired plugin's successor is itself bundled, so its record and
117
- // its ledger entry exist by now, and the retirement only has to decide whether to switch it on.
118
- // A successor whose seed FAILED has neither; `retire-bundled.ts` then keeps the retired plugin
119
- // rather than remove it in favour of a switch with no code behind it (its header, step 1a).
120
- async function seedBundledAgentPlugins(required, optional = {}) {
121
- const { layout, workspaceId, sourceRoot } = required;
122
- const pluginDirNames = await listBundledPluginDirs(sourceRoot);
123
- try {
124
- const migration = ports.migrateBeforeSeed
125
- ? await ports.migrateBeforeSeed({ layout, workspaceId }, {})
126
- : await createPersistentStateModule(ports).migrate({ workspaceRoot: layout.forWorkspace({ workspaceId }).root });
127
- if (!migration.complete)
128
- throw new Error('Legacy plugin layout migration has unfinished filesystem moves; see boot log');
129
- }
130
- catch (error) {
131
- const reason = error instanceof Error ? error.message : String(error);
132
- return { sourceRoot, outcomes: pluginDirNames.map(pluginId => ({ pluginId, status: 'failed', reason })), retirements: [] };
133
- }
134
- const refusal = await activationsRefusal(layout, workspaceId);
135
- if (refusal !== undefined) {
136
- return {
137
- sourceRoot,
138
- outcomes: pluginDirNames.map((dirName) => ({ pluginId: dirName, status: "failed", reason: refusal })),
139
- retirements: [],
140
- };
141
- }
142
- const outcomes = [];
143
- for (const dirName of pluginDirNames) {
144
- outcomes.push(await seedOne({ layout, workspaceId, sourceDir: path.join(sourceRoot, dirName), dirName }, optional));
145
- }
146
- const ledgerFailure = await recordSeededDigests(layout.forWorkspace({ workspaceId }).root, outcomes);
147
- const retirements = await retireBundledAgentPlugins({ layout, workspaceId });
148
- return { sourceRoot, outcomes, retirements, ...(ledgerFailure !== undefined ? { ledgerFailure } : {}) };
88
+ /**
89
+ * Installs every bundled Agent Plugin into one workspace and records each inactive-by-default,
90
+ * except {@link BUNDLED_AGENT_PLUGINS_SEEDED_ENABLED}.
91
+ *
92
+ * @returns A per-plugin report. An absent or unreadable `sourceRoot` yields an empty `outcomes`
93
+ * list rather than an error: a build that shipped no bundled plugins is a legitimate configuration,
94
+ * and a self-hosted operator who deleted the directory has made a choice this function should not
95
+ * override by crashing.
96
+ * @throws Nothing. Every per-plugin failure is captured into the report.
97
+ * @complexity O(p) plugins, each O(f) files and O(b) bytes — all bounded by
98
+ * `bundled-source-archive.ts`'s file cap and `install.ts`'s own byte caps.
99
+ */
100
+ // The migration must finish before new installs, including bundled packages, are published.
101
+ // Rejected legacy entries are preserved in quarantine and count as handled. An incomplete run
102
+ // means a move/quarantine failed; a held lock also refuses seeding until migration can finish.
103
+ // ONE strict pre-flight read BEFORE any install — so a bundled package never lands on disk
104
+ // without the activation record that would keep it inactive (this file's header). Every bundled
105
+ // plugin is reported failed with the SAME reason, rather than attempting each one and hitting the
106
+ // identical fault p times.
107
+ // AFTER every install, never before: the ledger names digests, and a digest is only worth naming
108
+ // once its bytes are actually on disk for this workspace.
109
+ // AFTER seeding and the ledger: a retired plugin's successor is itself bundled, so its record and
110
+ // its ledger entry exist by now, and the retirement only has to decide whether to switch it on.
111
+ // A successor whose seed FAILED has neither; `retire-bundled.ts` then keeps the retired plugin
112
+ // rather than remove it in favour of a switch with no code behind it (its header, step 1a).
113
+ async function seedBundledAgentPlugins({ ports, required }, optional = {}) {
114
+ const { layout, workspaceId, sourceRoot } = required;
115
+ const pluginDirNames = await listBundledPluginDirs({ ports, sourceRoot });
116
+ try {
117
+ const migration = ports.migrateBeforeSeed
118
+ ? await ports.migrateBeforeSeed({ layout, workspaceId }, {})
119
+ : await createPersistentStateModule(ports).migrate({ workspaceRoot: layout.forWorkspace({ workspaceId }).root });
120
+ if (!migration.complete)
121
+ throw new Error('Legacy plugin layout migration has unfinished filesystem moves; see boot log');
149
122
  }
150
- /** Records which digest this boot published for each plugin that seeded successfully, and returns
151
- * why it could not, rather than throwing — {@link seedBundledAgentPlugins}'s own contract is
152
- * "@throws Nothing", and a ledger this boot failed to write costs the workspace nothing it had
153
- * before the ledger existed.
154
- * @complexity One file read and one atomic write. */
155
- async function recordSeededDigests(workspaceRoot, outcomes) {
156
- try {
157
- await recordBundledAgentPluginDigests({
158
- workspaceRoot,
159
- seeded: outcomes.flatMap((outcome) => outcome.status === "seeded" ? [{ pluginId: outcome.pluginId, archiveDigest: outcome.archiveDigest }] : []),
160
- });
161
- return undefined;
162
- }
163
- catch (error) {
164
- return error instanceof Error ? error.message : String(error);
165
- }
123
+ catch (error) {
124
+ const reason = describeErrorForLog({ err: error });
125
+ return { sourceRoot, outcomes: pluginDirNames.map(pluginId => ({ pluginId, status: 'failed', reason })), retirements: [] };
166
126
  }
167
- /** Why nothing may be seeded into this workspace right now, or `undefined`. One strict read BEFORE
168
- * any install, so a bundled package never lands on disk without the record that keeps it inactive.
169
- * Catches everything (including `forWorkspace`'s own throw) to keep this function's own contract
170
- * "@throws Nothing", matching {@link seedBundledAgentPlugins}'s own guarantee.
171
- * @complexity One file read. */
172
- async function activationsRefusal(layout, workspaceId) {
173
- try {
174
- await assertAgentPluginActivationsWritable(layout.forWorkspace({ workspaceId }).root);
175
- return undefined;
176
- }
177
- catch (error) {
178
- return error instanceof Error ? error.message : String(error);
179
- }
127
+ const refusal = await activationsRefusal({ ports, layout, workspaceId });
128
+ if (refusal !== undefined) {
129
+ return {
130
+ sourceRoot,
131
+ outcomes: pluginDirNames.map((dirName) => ({ pluginId: dirName, status: "failed", reason: refusal })),
132
+ retirements: [],
133
+ };
180
134
  }
181
- // The plugin's OWN manifest name, not the directory name — `install.ts` reads the id from
182
- // `plugin.json`, and every consumer keys activation off that same id. Using the folder name
183
- // here would produce a record nothing ever consults if the two ever disagreed.
184
- async function seedOne(args, optional = {}) {
185
- try {
186
- const packing = typeof optional.packing === 'function'
187
- ? await optional.packing({ sourceDir: args.sourceDir, dirName: args.dirName }, {}) : optional.packing;
188
- const packed = await packAgentPluginDirectory(args.sourceDir, packing);
189
- // No revision pruning here, not even of the digest the ledger recorded last boot: that digest
190
- // names the bytes this build once published, not what is on disk now, so an operator edit
191
- // under it would be deleted. Every same-name copy stays; the ledger selects this build's.
192
- const installed = await installAgentPlugin({
193
- archive: packed.bytes,
194
- expectedSha256: packed.sha256,
195
- archiveReader: packed.archiveReader ?? createBundledSourceArchiveReader(),
196
- layout: args.layout,
197
- workspaceId: args.workspaceId,
198
- }, { pruneSupersededRevisions: false });
199
- const { recorded } = await recordBundledAgentPluginIfAbsent({ workspaceRoot: args.layout.forWorkspace({ workspaceId: args.workspaceId }).root, pluginId: installed.pluginId }, { enabled: ports.seededEnabledPluginIds.has(installed.pluginId) });
200
- return {
201
- pluginId: installed.pluginId,
202
- status: "seeded",
203
- archiveDigest: installed.archiveDigest,
204
- activationRecorded: recorded,
205
- };
206
- }
207
- catch (error) {
208
- return {
209
- pluginId: args.dirName,
210
- status: "failed",
211
- reason: error instanceof Error ? error.message : String(error),
212
- };
213
- }
135
+ const outcomes = [];
136
+ for (const dirName of pluginDirNames) {
137
+ outcomes.push(await seedOne({
138
+ ports,
139
+ args: { layout, workspaceId, sourceDir: path.join(sourceRoot, dirName), dirName },
140
+ }, { optional }));
214
141
  }
215
- /**
216
- * Lists the subdirectories of `sourceRoot` that actually look like Agent Plugin packages (they hold
217
- * a `plugin.json` at their own root, which is where `indexInstalledRoot` looks for it).
218
- *
219
- * Filtering here rather than letting the installer reject them keeps a stray `README.md` or an
220
- * editor's scratch directory from showing up in the report as a failed plugin.
221
- *
222
- * @complexity O(d) in the subdirectory count.
223
- */
224
- // A retired id is never seeded, even from a stale build that still carries its directory —
225
- // otherwise every boot would reinstall it only for `retire-bundled.ts` to remove it again.
226
- async function listBundledPluginDirs(sourceRoot) {
227
- let entries;
142
+ const ledgerFailure = await recordSeededDigests({ ports, workspaceRoot: layout.forWorkspace({ workspaceId }).root, outcomes });
143
+ const retirements = await createRetireBundledModule(ports).retireBundledAgentPlugins({ layout, workspaceId });
144
+ return { sourceRoot, outcomes, retirements, ...(ledgerFailure !== undefined ? { ledgerFailure } : {}) };
145
+ }
146
+ /** Records which digest this boot published for each plugin that seeded successfully, and returns
147
+ * why it could not, rather than throwing — {@link seedBundledAgentPlugins}'s own contract is
148
+ * "@throws Nothing", and a ledger this boot failed to write costs the workspace nothing it had
149
+ * before the ledger existed.
150
+ * @complexity One file read and one atomic write. */
151
+ async function recordSeededDigests({ ports, workspaceRoot, outcomes }) {
152
+ try {
153
+ await createBundledDigestsModule(ports).recordBundledAgentPluginDigests({
154
+ workspaceRoot,
155
+ seeded: outcomes.flatMap((outcome) => outcome.status === "seeded" ? [{ pluginId: outcome.pluginId, archiveDigest: outcome.archiveDigest }] : []),
156
+ });
157
+ return undefined;
158
+ }
159
+ catch (error) {
160
+ return describeErrorForLog({ err: error });
161
+ }
162
+ }
163
+ /** Why nothing may be seeded into this workspace right now, or `undefined`. One strict read BEFORE
164
+ * any install, so a bundled package never lands on disk without the record that keeps it inactive.
165
+ * Catches everything (including `forWorkspace`'s own throw) to keep this function's own contract
166
+ * "@throws Nothing", matching {@link seedBundledAgentPlugins}'s own guarantee.
167
+ * @complexity One file read. */
168
+ async function activationsRefusal({ ports, layout, workspaceId }) {
169
+ try {
170
+ await createActivationModule(ports).assertAgentPluginActivationsWritable(layout.forWorkspace({ workspaceId }).root);
171
+ return undefined;
172
+ }
173
+ catch (error) {
174
+ return describeErrorForLog({ err: error });
175
+ }
176
+ }
177
+ // The plugin's OWN manifest name, not the directory name — `install.ts` reads the id from
178
+ // `plugin.json`, and every consumer keys activation off that same id. Using the folder name
179
+ // here would produce a record nothing ever consults if the two ever disagreed.
180
+ async function seedOne({ ports, args }, { optional = {} } = {}) {
181
+ try {
182
+ const packing = typeof optional.packing === 'function'
183
+ ? await optional.packing({ sourceDir: args.sourceDir, dirName: args.dirName }, {}) : optional.packing;
184
+ const packed = await createBundledSourceArchiveModule(ports).packAgentPluginDirectory(args.sourceDir, packing);
185
+ // No revision pruning here, not even of the digest the ledger recorded last boot: that digest
186
+ // names the bytes this build once published, not what is on disk now, so an operator edit
187
+ // under it would be deleted. Every same-name copy stays; the ledger selects this build's.
188
+ const installed = await createInstallModule(ports).installAgentPlugin({
189
+ archive: packed.bytes,
190
+ expectedSha256: packed.sha256,
191
+ archiveReader: packed.archiveReader ?? createBundledSourceArchiveModule(ports).createBundledSourceArchiveReader(),
192
+ layout: args.layout,
193
+ workspaceId: args.workspaceId,
194
+ }, { pruneSupersededRevisions: false });
195
+ const { recorded } = await createActivationModule(ports).recordBundledAgentPluginIfAbsent({ workspaceRoot: args.layout.forWorkspace({ workspaceId: args.workspaceId }).root, pluginId: installed.pluginId }, { enabled: ports.seededEnabledPluginIds.has(installed.pluginId) });
196
+ return {
197
+ pluginId: installed.pluginId,
198
+ status: "seeded",
199
+ archiveDigest: installed.archiveDigest,
200
+ activationRecorded: recorded,
201
+ };
202
+ }
203
+ catch (error) {
204
+ return {
205
+ pluginId: args.dirName,
206
+ status: "failed",
207
+ reason: describeErrorForLog({ err: error }),
208
+ };
209
+ }
210
+ }
211
+ /**
212
+ * Lists the subdirectories of `sourceRoot` that actually look like Agent Plugin packages (they hold
213
+ * a `plugin.json` at their own root, which is where `indexInstalledRoot` looks for it).
214
+ *
215
+ * Filtering here rather than letting the installer reject them keeps a stray `README.md` or an
216
+ * editor's scratch directory from showing up in the report as a failed plugin.
217
+ *
218
+ * @complexity O(d) in the subdirectory count.
219
+ */
220
+ // A retired id is never seeded, even from a stale build that still carries its directory —
221
+ // otherwise every boot would reinstall it only for `retire-bundled.ts` to remove it again.
222
+ async function listBundledPluginDirs({ ports, sourceRoot }) {
223
+ let entries;
224
+ try {
225
+ entries = await ports.filesystem.readdir(sourceRoot, { withFileTypes: true });
226
+ }
227
+ catch {
228
+ return [];
229
+ }
230
+ const dirs = [];
231
+ for (const entry of entries) {
232
+ if (!entry.isDirectory() || ports.retiredBundledPlugins.has(entry.name))
233
+ continue;
228
234
  try {
229
- entries = await readdir(sourceRoot, { withFileTypes: true });
235
+ const manifest = await ports.filesystem.stat(path.join(sourceRoot, entry.name, "plugin.json"));
236
+ if (manifest.isFile())
237
+ dirs.push(entry.name);
230
238
  }
231
239
  catch {
232
- return [];
233
- }
234
- const dirs = [];
235
- for (const entry of entries) {
236
- if (!entry.isDirectory() || ports.retiredBundledPlugins.has(entry.name))
237
- continue;
238
- try {
239
- const manifest = await stat(path.join(sourceRoot, entry.name, "plugin.json"));
240
- if (manifest.isFile())
241
- dirs.push(entry.name);
242
- }
243
- catch {
244
- // No plugin.json: not a package. Silently skipped — see this function's own doc.
245
- }
240
+ // No plugin.json: not a package. Silently skipped — see this function's own doc.
246
241
  }
247
- return dirs.sort();
248
242
  }
249
- return { seedBundledAgentPlugins };
243
+ return dirs.sort();
244
+ }
245
+ function buildModule(ports) {
246
+ return {
247
+ seedBundledAgentPlugins: (required, optional = {}) => seedBundledAgentPlugins({ ports, required }, optional),
248
+ };
250
249
  }
251
250
  const instances = new WeakMap();
252
251
  /** Internal composition; one state/queue instance per injected host context. */
253
- export function createSeedBundledModule(ports) {
252
+ export function createSeedBundledModule(ports, _optional = {}) {
254
253
  let instance = instances.get(ports);
255
254
  if (!instance) {
256
255
  instance = buildModule(ports);