@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
@@ -13,311 +13,317 @@ const PLAN_REFUSALS = {
13
13
  'downgrade-refused': { code: 'PLUGIN_DOWNGRADE_REFUSED', message: 'Plugin downgrades are refused.' },
14
14
  'id-mismatch': { code: 'PLUGIN_ID_MISMATCH', message: 'Choose a candidate for this plugin.' },
15
15
  };
16
- /** Update transaction owner for operator-installed plugins (bundled ones stay seed-managed).
17
- *
18
- * Runs inside the installer's identity lock and per-plugin file lock (the publish guard), so it is
19
- * serialized against enable/disable/uninstall, which take the same plugin lock. Nothing called in
20
- * the guard re-takes that lock: activation writes use their own activations.json lock.
21
- *
22
- * Invariant: never two live digests. The old revision moves to a frozen rollback area outside
23
- * `package/sha256` before the candidate is published; a per-plugin journal (pending -> published ->
24
- * committed) lets boot reconciliation restore it if the process dies before commit.
25
- *
26
- * Documented behavior:
27
- * - In-flight MCP calls against the old revision may fail once the roster is re-provisioned.
28
- * - Running chats keep the skill text they already captured; new runs resolve the new revision.
29
- * - Rollback bytes are retained after commit (a run may still read them) and collected by the next
30
- * boot's reconciliation, when no run can hold those paths.
31
- * - Plugin data and memory directories carry over untouched. A rollback restores package bytes and
32
- * activation only; it does NOT revert data, memory or settings written while the candidate ran.
33
- * The settings snapshot is an audit record, not a restore source.
34
- * - Caches: this package keeps no cache of skill prompt indexes or search ranking keyed by plugin
35
- * (search ranking is computed per call from the installed list; per-run automatic-use state is
36
- * per run; module imports are keyed by the digest path), so a switch has nothing to invalidate.
37
- */
38
- export function createUpdateModule(ports, optional = {}) {
39
- const installAgentPlugin = optional.installAgentPlugin ?? createInstallModule(ports).installAgentPlugin;
40
- const activation = createActivationModule(ports);
41
- const removal = createUninstallModule(ports);
42
- const refs = createResolveAgentPluginRefsModule(ports);
43
- const persistent = createPersistentStateModule(ports);
44
- const index = createInstalledPackageIndex({ ports });
45
- /** Verifies and stages the candidate through the installer, then runs the transaction in its
46
- * publish guard. @throws AgentPluginUpdateError, AgentPluginHostIncompatibleError, install errors. */
47
- async function updateAgentPlugin(required, _optional = {}) {
48
- const input = { ...required, layout: ports.layout };
49
- const outcomes = [];
50
- await installAgentPlugin(input, { publishGuard: async ({ plugin, publish }) => {
51
- const outcome = await updateLocked({ required: input, candidate: plugin, publish });
52
- outcomes.push(outcome);
53
- return outcome.plugin;
54
- } });
55
- const [outcome] = outcomes;
56
- if (!outcome)
57
- throw new AgentPluginUpdateError({ code: 'PLUGIN_UPDATE_NOT_RUN', message: 'The installer did not run the update transaction.' });
58
- return outcome;
16
+ /** Verifies and stages the candidate through the installer, then runs the transaction in its
17
+ * publish guard. @throws AgentPluginUpdateError, AgentPluginHostIncompatibleError, install errors. */
18
+ async function updateAgentPlugin({ scope, required }) {
19
+ const input = { ...required, layout: scope.ports.layout };
20
+ const outcomes = [];
21
+ await scope.installAgentPlugin(input, { publishGuard: async ({ plugin, publish }) => {
22
+ const outcome = await updateLocked({ scope, required: input, candidate: plugin, publish });
23
+ outcomes.push(outcome);
24
+ return outcome.plugin;
25
+ } });
26
+ const [outcome] = outcomes;
27
+ if (!outcome)
28
+ throw new AgentPluginUpdateError({ code: 'PLUGIN_UPDATE_NOT_RUN', message: 'The installer did not run the update transaction.' });
29
+ return outcome;
30
+ }
31
+ /** All validation precedes the first live-state mutation. @complexity O(p) installed plugins. */
32
+ async function updateLocked({ scope, required, candidate, publish }) {
33
+ // The installer locked the candidate's id; refuse before reading another plugin's state.
34
+ if (candidate.pluginId !== required.pluginId)
35
+ throw new AgentPluginUpdateError(PLAN_REFUSALS['id-mismatch']);
36
+ const store = createAgentPluginUpdateStore({ ports: scope.ports, workspaceId: required.workspaceId, pluginId: required.pluginId });
37
+ await settleAgentPluginUpdateJournal({ store });
38
+ const target = await readTarget({ scope, required });
39
+ const plan = planAgentPluginUpdate({ installed: { ...target.previous, enabled: target.enabled }, candidate });
40
+ if (plan.action === 'none')
41
+ return { plugin: target.previous, enabled: target.enabled, alreadyInstalled: true, warnings: [] };
42
+ const refusal = PLAN_REFUSALS[plan.action];
43
+ if (refusal)
44
+ throw new AgentPluginUpdateError(refusal);
45
+ const warnings = admissionWarnings({ target, candidate, planWarnings: plan.warnings });
46
+ const plugin = await performUpdate({ scope, transaction: { required, store, target, candidate, publish } });
47
+ return { plugin, enabled: target.enabled, alreadyInstalled: false, warnings };
48
+ }
49
+ /** Exactly one live revision at the previewed digest, operator-installed, with a readable decision. */
50
+ async function readTarget({ scope, required }) {
51
+ const workspaceRoot = scope.ports.layout.forWorkspace({ workspaceId: required.workspaceId }).root;
52
+ const installed = await scope.refs.listInstalledPlugins(workspaceRoot);
53
+ const matches = installed.filter(plugin => plugin.pluginId === required.pluginId);
54
+ if (matches.length !== 1 || matches[0].archiveDigest !== required.expectedOldDigest) {
55
+ throw new AgentPluginUpdateError({ code: 'PLUGIN_CHANGED', message: 'The installed plugin changed; preview it again.' });
59
56
  }
60
- /** All validation precedes the first live-state mutation. @complexity O(p) installed plugins. */
61
- async function updateLocked({ required, candidate, publish }, _optional = {}) {
62
- // The installer locked the candidate's id; refuse before reading another plugin's state.
63
- if (candidate.pluginId !== required.pluginId)
64
- throw new AgentPluginUpdateError(PLAN_REFUSALS['id-mismatch']);
65
- const store = createAgentPluginUpdateStore({ ports, workspaceId: required.workspaceId, pluginId: required.pluginId });
66
- await settleAgentPluginUpdateJournal({ store });
67
- const target = await readTarget({ required });
68
- const plan = planAgentPluginUpdate({ installed: { ...target.previous, enabled: target.enabled }, candidate });
69
- if (plan.action === 'none')
70
- return { plugin: target.previous, enabled: target.enabled, alreadyInstalled: true, warnings: [] };
71
- const refusal = PLAN_REFUSALS[plan.action];
72
- if (refusal)
73
- throw new AgentPluginUpdateError(refusal);
74
- const warnings = admissionWarnings({ target, candidate, planWarnings: plan.warnings });
75
- const plugin = await performUpdate({ required, store, target, candidate, publish });
76
- return { plugin, enabled: target.enabled, alreadyInstalled: false, warnings };
57
+ const previous = matches[0];
58
+ if (await scope.activation.isAgentPluginRecordedAsBundled(workspaceRoot, previous.pluginId)) {
59
+ throw new AgentPluginUpdateError({ code: 'PLUGIN_BUNDLED', message: 'Bundled plugins are managed by the host.' });
77
60
  }
78
- /** Exactly one live revision at the previewed digest, operator-installed, with a readable decision. */
79
- async function readTarget({ required }, _optional = {}) {
80
- const workspaceRoot = ports.layout.forWorkspace({ workspaceId: required.workspaceId }).root;
81
- const installed = await refs.listInstalledPlugins(workspaceRoot);
82
- const matches = installed.filter(plugin => plugin.pluginId === required.pluginId);
83
- if (matches.length !== 1 || matches[0].archiveDigest !== required.expectedOldDigest) {
84
- throw new AgentPluginUpdateError({ code: 'PLUGIN_CHANGED', message: 'The installed plugin changed; preview it again.' });
85
- }
86
- const previous = matches[0];
87
- if (await activation.isAgentPluginRecordedAsBundled(workspaceRoot, previous.pluginId)) {
88
- throw new AgentPluginUpdateError({ code: 'PLUGIN_BUNDLED', message: 'Bundled plugins are managed by the host.' });
89
- }
90
- const verdict = await activation.resolveAgentPluginActivation(workspaceRoot, previous.pluginId);
91
- if (verdict.verdict === 'undetermined')
92
- throw new AgentPluginUpdateError({ code: 'PLUGIN_ACTIVATION_UNKNOWN', message: 'Repair this plugin activation record before updating.' });
93
- const activations = await activation.readAgentPluginActivations(workspaceRoot);
94
- return { previous, installed, activations, enabled: verdict.verdict === 'active' };
61
+ const verdict = await scope.activation.resolveAgentPluginActivation(workspaceRoot, previous.pluginId);
62
+ if (verdict.verdict === 'undetermined')
63
+ throw new AgentPluginUpdateError({ code: 'PLUGIN_ACTIVATION_UNKNOWN', message: 'Repair this plugin scope.activation record before updating.' });
64
+ const activations = await scope.activation.readAgentPluginActivations(workspaceRoot);
65
+ return { previous, installed, activations, enabled: verdict.verdict === 'active' };
66
+ }
67
+ /** An enabled plugin must stay host-compatible; requirement and dependent losses only warn. */
68
+ function admissionWarnings({ target, candidate, planWarnings }, _optional = {}) {
69
+ const { previous, installed, activations } = target;
70
+ const compatibility = describeAgentPluginCompatibility({ plugin: candidate, installed, activations });
71
+ if (target.enabled && !compatibility.hostOk)
72
+ throw new AgentPluginHostIncompatibleError({ pluginId: candidate.pluginId });
73
+ return [...planWarnings, ...compatibility.missingRequires.map(id => `Needs ${id}`),
74
+ ...agentPluginDependentWarnings({ plugin: previous, installed, activations, nextProvides: candidate.provides ?? [] })];
75
+ }
76
+ /** Records intent, switches revisions, then files the audit. A failed audit filing after commit
77
+ * does not undo the update: the committed journal stays and the next update or boot files it. */
78
+ async function performUpdate({ scope, transaction }) {
79
+ const journal = await beginJournal({ scope, ...transaction });
80
+ const installed = await switchRevision({ scope, ...transaction, journal });
81
+ try {
82
+ await transaction.store.finish({ journal: { ...journal, state: 'committed', result: 'updated' } });
95
83
  }
96
- /** An enabled plugin must stay host-compatible; requirement and dependent losses only warn. */
97
- function admissionWarnings({ target, candidate, planWarnings }, _optional = {}) {
98
- const { previous, installed, activations } = target;
99
- const compatibility = describeAgentPluginCompatibility({ plugin: candidate, installed, activations });
100
- if (target.enabled && !compatibility.hostOk)
101
- throw new AgentPluginHostIncompatibleError({ pluginId: candidate.pluginId });
102
- return [...planWarnings, ...compatibility.missingRequires.map(id => `Needs ${id}`),
103
- ...agentPluginDependentWarnings({ plugin: previous, installed, activations, nextProvides: candidate.provides ?? [] })];
84
+ catch {
85
+ scope.ports.onEvent?.({ event: 'agent-plugin-update-audit-deferred', message: `Plugin '${journal.pluginId}': the committed update will be filed in its history at the next boot.` });
104
86
  }
105
- /** Records intent, switches revisions, then files the audit. A failed audit filing after commit
106
- * does not undo the update: the committed journal stays and the next update or boot files it. */
107
- async function performUpdate(transaction, _optional = {}) {
108
- const journal = await beginJournal(transaction);
109
- const installed = await switchRevision({ ...transaction, journal });
110
- try {
111
- await transaction.store.finish({ journal: { ...journal, state: 'committed', result: 'updated' } });
112
- }
113
- catch {
114
- ports.onEvent?.({ event: 'agent-plugin-update-audit-deferred', message: `Plugin '${journal.pluginId}': the committed update will be filed in its history at the next boot.` });
115
- }
87
+ return installed;
88
+ }
89
+ async function beginJournal({ scope, required, store, target, candidate }) {
90
+ const { previous, enabled } = target;
91
+ const settingsSnapshot = await required.snapshotSettings({ workspaceId: required.workspaceId, pluginId: previous.pluginId }, {});
92
+ const journal = { schemaVersion: 1, state: 'pending', transactionId: scope.ports.ids.newId(),
93
+ pluginId: previous.pluginId, actor: required.actor, enabled, fromDigest: previous.archiveDigest,
94
+ toDigest: candidate.archiveDigest, fromVersion: previous.version, toVersion: candidate.version,
95
+ settingsSnapshot, startedAt: new Date(scope.ports.clock.nowMs()).toISOString() };
96
+ await store.prepare({});
97
+ // A copy of this same digest retained by an earlier committed update (kept for in-flight runs
98
+ // until boot) holds identical bytes and would make the rollback rename fail, so it is removed,
99
+ // and only when present: the rename cannot replace a non-empty directory. A run still reading
100
+ // that retained copy loses it here (the same bytes stay live at package/sha256/<digest> until
101
+ // the switch below). Done before recording intent, so recovery never sees both a stale copy
102
+ // and a live old revision.
103
+ const staleCopy = store.rollbackRoot({ digest: journal.fromDigest });
104
+ if (await store.realDirectoryExists({ root: staleCopy }))
105
+ await scope.removal.removeFrozenPackageTree(staleCopy);
106
+ await store.write({ journal });
107
+ return journal;
108
+ }
109
+ /** The live-state switch. Any failure restores the old revision; a failed restore keeps the
110
+ * journal for boot and reports PLUGIN_ROLLBACK_INCOMPLETE carrying both errors. The candidate is
111
+ * re-enabled only after its MCP roster is provisioned, so an MCP failure leaves it off even when
112
+ * the rollback that follows cannot finish. */
113
+ async function switchRevision({ scope, required, store, target, publish, journal }) {
114
+ const { workspaceId } = required;
115
+ await disableBeforeSwitch({ scope, workspaceId, store, journal });
116
+ let current = journal;
117
+ try {
118
+ await freezeRollback({ scope, store, previous: target.previous });
119
+ const installed = await publish();
120
+ // `current` follows the durable record: recovery re-provisions MCP only once `published` is on disk.
121
+ const published = { ...journal, state: 'published' };
122
+ await store.write({ journal: published });
123
+ current = published;
124
+ await provisionAgentPluginMcp({ mcpProvisioning: scope.ports.mcpProvisioning, workspaceId, installed });
125
+ await setActivation({ scope, workspaceId, journal, enabled: journal.enabled });
126
+ await store.write({ journal: { ...journal, state: 'committed', result: 'updated' } });
116
127
  return installed;
117
128
  }
118
- async function beginJournal({ required, store, target, candidate }, _optional = {}) {
119
- const { previous, enabled } = target;
120
- const settingsSnapshot = await required.snapshotSettings({ workspaceId: required.workspaceId, pluginId: previous.pluginId }, {});
121
- const journal = { schemaVersion: 1, state: 'pending', transactionId: ports.ids.newId(),
122
- pluginId: previous.pluginId, actor: required.actor, enabled, fromDigest: previous.archiveDigest,
123
- toDigest: candidate.archiveDigest, fromVersion: previous.version, toVersion: candidate.version,
124
- settingsSnapshot, startedAt: new Date(ports.clock.nowMs()).toISOString() };
125
- await store.prepare({});
126
- // A copy of this same digest retained by an earlier committed update (kept for in-flight runs
127
- // until boot) holds identical bytes and would make the rollback rename fail, so it is removed,
128
- // and only when present: the rename cannot replace a non-empty directory. A run still reading
129
- // that retained copy loses it here (the same bytes stay live at package/sha256/<digest> until
130
- // the switch below). Done before recording intent, so recovery never sees both a stale copy
131
- // and a live old revision.
132
- const staleCopy = store.rollbackRoot({ digest: journal.fromDigest });
133
- if (await store.realDirectoryExists({ root: staleCopy }))
134
- await removal.removeFrozenPackageTree(staleCopy);
135
- await store.write({ journal });
136
- return journal;
129
+ catch (cause) {
130
+ throw await rollBackAfterFailure({ scope, workspaceId, journal: current, cause });
137
131
  }
138
- /** The live-state switch. Any failure restores the old revision; a failed restore keeps the
139
- * journal for boot and reports PLUGIN_ROLLBACK_INCOMPLETE carrying both errors. The candidate is
140
- * re-enabled only after its MCP roster is provisioned, so an MCP failure leaves it off even when
141
- * the rollback that follows cannot finish. */
142
- async function switchRevision({ required, store, target, publish, journal }, _optional = {}) {
143
- const { workspaceId } = required;
144
- await disableBeforeSwitch({ workspaceId, store, journal });
145
- let current = journal;
146
- try {
147
- await freezeRollback({ store, previous: target.previous });
148
- const installed = await publish();
149
- // `current` follows the durable record: recovery re-provisions MCP only once `published` is on disk.
150
- const published = { ...journal, state: 'published' };
151
- await store.write({ journal: published });
152
- current = published;
153
- await provisionAgentPluginMcp({ mcpProvisioning: ports.mcpProvisioning, workspaceId, installed });
154
- await setActivation({ workspaceId, journal, enabled: journal.enabled });
155
- await store.write({ journal: { ...journal, state: 'committed', result: 'updated' } });
156
- return installed;
157
- }
158
- catch (cause) {
159
- throw await rollBackAfterFailure({ workspaceId, journal: current, cause });
160
- }
132
+ }
133
+ /** If the first switch-off fails no byte has moved and scope.activation is unchanged, so there is
134
+ * nothing to recover: the intent is dropped instead of being left pending for boot. */
135
+ async function disableBeforeSwitch({ scope, workspaceId, store, journal }) {
136
+ try {
137
+ await setActivation({ scope, workspaceId, journal, enabled: false });
161
138
  }
162
- /** If the first switch-off fails no byte has moved and activation is unchanged, so there is
163
- * nothing to recover: the intent is dropped instead of being left pending for boot. */
164
- async function disableBeforeSwitch({ workspaceId, store, journal }, _optional = {}) {
165
- try {
166
- await setActivation({ workspaceId, journal, enabled: false });
167
- }
168
- catch (cause) {
169
- await store.clear({});
170
- throw cause;
171
- }
139
+ catch (cause) {
140
+ await store.clear({});
141
+ throw cause;
172
142
  }
173
- /** Moves the old revision out of `package/sha256` (reusing uninstall's staging move) and refreezes it. */
174
- async function freezeRollback({ store, previous }, _optional = {}) {
175
- const rollbackRoot = store.rollbackRoot({ digest: previous.archiveDigest });
176
- await removal.stageForRemoval(path.dirname(previous.packageRoot), previous.packageRoot, { quarantined: rollbackRoot });
177
- await ports.filesystem.chmod(rollbackRoot, 0o555);
143
+ }
144
+ /** Moves the old revision out of `package/sha256` (reusing uninstall's staging move) and refreezes it. */
145
+ async function freezeRollback({ scope, store, previous }) {
146
+ const rollbackRoot = store.rollbackRoot({ digest: previous.archiveDigest });
147
+ await scope.removal.stageForRemoval(path.dirname(previous.packageRoot), previous.packageRoot, { quarantined: rollbackRoot });
148
+ await scope.ports.filesystem.chmod(rollbackRoot, 0o555);
149
+ }
150
+ async function rollBackAfterFailure({ scope, workspaceId, journal, cause }) {
151
+ try {
152
+ await restoreUpdate({ scope, workspaceId, journal });
153
+ return cause;
178
154
  }
179
- async function rollBackAfterFailure({ workspaceId, journal, cause }, _optional = {}) {
180
- try {
181
- await restoreUpdate({ workspaceId, journal });
182
- return cause;
183
- }
184
- catch (rollbackError) {
185
- return new AgentPluginUpdateError({ code: 'PLUGIN_ROLLBACK_INCOMPLETE', message: 'The update failed and its rollback did not finish; restart the host to recover.' }, { cause: new AggregateError([cause, rollbackError], 'update failure, then rollback failure') });
186
- }
155
+ catch (rollbackError) {
156
+ return new AgentPluginUpdateError({ code: 'PLUGIN_ROLLBACK_INCOMPLETE', message: 'The update failed and its rollback did not finish; restart the host to recover.' }, { cause: new AggregateError([cause, rollbackError], 'update failure, then rollback failure') });
187
157
  }
188
- async function setActivation({ workspaceId, journal, enabled }, _optional = {}) {
189
- return activation.setAgentPluginActivation({ workspaceRoot: ports.layout.forWorkspace({ workspaceId }).root,
190
- pluginId: journal.pluginId, enabled, actor: journal.actor }, { origin: 'operator-installed' });
158
+ }
159
+ async function setActivation({ scope, workspaceId, journal, enabled }) {
160
+ return scope.activation.setAgentPluginActivation({ workspaceRoot: scope.ports.layout.forWorkspace({ workspaceId }).root,
161
+ pluginId: journal.pluginId, enabled, actor: journal.actor }, { origin: 'operator-installed' });
162
+ }
163
+ /** Idempotent recovery (automatic rollback restore, exempt from downgrade planning): remove the
164
+ * candidate, put the old revision back live and frozen, re-provision its MCP roster when the
165
+ * candidate may have been provisioned (journal reached `published`), and only then restore its
166
+ * scope.activation decision. Any failure restoring bytes keeps the journal for the next boot, including
167
+ * failure after the restore rename.
168
+ *
169
+ * MCP re-provisioning is attempted at boot too, not skipped: provisioning writes host-owned roster
170
+ * records naming the candidate's servers, and nothing guarantees the host rebuilds them from the
171
+ * installed bytes at start. A host whose boot binding has no MCP port (it throws) therefore gets the
172
+ * degraded outcome below rather than a journal that fails every boot.
173
+ */
174
+ async function restoreUpdate({ scope, workspaceId, journal }) {
175
+ const store = createAgentPluginUpdateStore({ ports: scope.ports, workspaceId, pluginId: journal.pluginId });
176
+ const oldRoot = store.liveRoot({ digest: journal.fromDigest });
177
+ await setActivation({ scope, workspaceId, journal, enabled: false });
178
+ await restoreOldBytes({ scope, store, journal, oldRoot });
179
+ if (journal.state === 'published' && !await reprovisionOld({ scope, workspaceId, journal, oldRoot })) {
180
+ scope.ports.onEvent?.({ event: 'agent-plugin-update-recovered-disabled', message: `Plugin '${journal.pluginId}': the previous revision is back but its MCP servers could not be re-provisioned; it stays off until an operator enables it.` });
191
181
  }
192
- /** Idempotent recovery (automatic rollback restore, exempt from downgrade planning): remove the
193
- * candidate, put the old revision back live and frozen, re-provision its MCP roster when the
194
- * candidate may have been provisioned (journal reached `published`), and only then restore its
195
- * activation decision. Any failure restoring bytes keeps the journal for the next boot, including
196
- * failure after the restore rename.
197
- *
198
- * MCP re-provisioning is attempted at boot too, not skipped: provisioning writes host-owned roster
199
- * records naming the candidate's servers, and nothing guarantees the host rebuilds them from the
200
- * installed bytes at start. A host whose boot binding has no MCP port (it throws) therefore gets the
201
- * degraded outcome below rather than a journal that fails every boot.
202
- */
203
- async function restoreUpdate({ workspaceId, journal }, _optional = {}) {
204
- const store = createAgentPluginUpdateStore({ ports, workspaceId, pluginId: journal.pluginId });
205
- const oldRoot = store.liveRoot({ digest: journal.fromDigest });
206
- await setActivation({ workspaceId, journal, enabled: false });
207
- await restoreOldBytes({ store, journal, oldRoot });
208
- if (journal.state === 'published' && !await reprovisionOld({ workspaceId, journal, oldRoot })) {
209
- ports.onEvent?.({ event: 'agent-plugin-update-recovered-disabled', message: `Plugin '${journal.pluginId}': the previous revision is back but its MCP servers could not be re-provisioned; it stays off until an operator enables it.` });
210
- }
211
- else {
212
- await setActivation({ workspaceId, journal, enabled: journal.enabled });
213
- }
214
- await store.finish({ journal: { ...journal, result: 'rolled-back' } });
182
+ else {
183
+ await setActivation({ scope, workspaceId, journal, enabled: journal.enabled });
215
184
  }
216
- /** Removes the candidate and puts the old revision back live. Refreezing runs whichever branch
217
- * ran, so a crash between an earlier reinstate rename and its refreeze is repaired here.
218
- * @throws AgentPluginUpdateError PLUGIN_ROLLBACK_MISSING, PLUGIN_UPDATE_PATH_UNSAFE. */
219
- async function restoreOldBytes({ store, journal, oldRoot }, _optional = {}) {
220
- const rollbackRoot = store.rollbackRoot({ digest: journal.fromDigest });
221
- const oldLive = await store.realDirectoryExists({ root: oldRoot });
222
- if (!oldLive && !await store.realDirectoryExists({ root: rollbackRoot })) {
223
- throw new AgentPluginUpdateError({ code: 'PLUGIN_ROLLBACK_MISSING', message: 'Previous plugin bytes are missing; recovery is required.' });
224
- }
225
- const candidateRoot = store.liveRoot({ digest: journal.toDigest });
226
- if (await store.realDirectoryExists({ root: candidateRoot }))
227
- await removal.removeFrozenPackageTree(candidateRoot);
228
- // A read-only directory cannot be renamed, so unfreeze the rollback root before moving it back.
229
- if (!oldLive) {
230
- await ports.filesystem.chmod(rollbackRoot, 0o700);
231
- await ports.filesystem.rename(rollbackRoot, oldRoot);
232
- }
233
- await ports.filesystem.chmod(oldRoot, 0o555);
185
+ await store.finish({ journal: { ...journal, result: 'rolled-back' } });
186
+ }
187
+ /** Removes the candidate and puts the old revision back live. Refreezing runs whichever branch
188
+ * ran, so a crash between an earlier reinstate rename and its refreeze is repaired here.
189
+ * @throws AgentPluginUpdateError PLUGIN_ROLLBACK_MISSING, PLUGIN_UPDATE_PATH_UNSAFE. */
190
+ async function restoreOldBytes({ scope, store, journal, oldRoot }) {
191
+ const rollbackRoot = store.rollbackRoot({ digest: journal.fromDigest });
192
+ const oldLive = await store.realDirectoryExists({ root: oldRoot });
193
+ if (!oldLive && !await store.realDirectoryExists({ root: rollbackRoot })) {
194
+ throw new AgentPluginUpdateError({ code: 'PLUGIN_ROLLBACK_MISSING', message: 'Previous plugin bytes are missing; recovery is required.' });
234
195
  }
235
- /** @returns false when the old revision's MCP roster could not be re-provisioned; the bytes are
236
- * already back, so the caller degrades to "restored but off" instead of wedging the journal. */
237
- async function reprovisionOld({ workspaceId, journal, oldRoot }, _optional = {}) {
238
- try {
239
- const installed = await index.indexInstalledRoot({ packageRoot: oldRoot, archiveDigest: journal.fromDigest });
240
- await provisionAgentPluginMcp({ mcpProvisioning: ports.mcpProvisioning, workspaceId, installed });
241
- return true;
242
- }
243
- catch {
244
- return false;
245
- }
196
+ const candidateRoot = store.liveRoot({ digest: journal.toDigest });
197
+ if (await store.realDirectoryExists({ root: candidateRoot }))
198
+ await scope.removal.removeFrozenPackageTree(candidateRoot);
199
+ // A read-only directory cannot be renamed, so unfreeze the rollback root before moving it back.
200
+ if (!oldLive) {
201
+ await scope.ports.filesystem.chmod(rollbackRoot, 0o700);
202
+ await scope.ports.filesystem.rename(rollbackRoot, oldRoot);
246
203
  }
247
- /** Boot only, before serving runs: recover incomplete switches, file committed audits, then
248
- * collect retained rollback bytes. One plugin's failure does not stop the others; the first
249
- * failure is rethrown afterwards. Bundled plugins have no update journal and get no decisions.
250
- * @complexity O(p + f) workspace entries and retained rollback files.
251
- */
252
- async function reconcileAgentPluginUpdates({ workspaceId }, _optional = {}) {
253
- const workspaceRoot = ports.layout.forWorkspace({ workspaceId }).root;
254
- const failures = [];
255
- for (const pluginId of await listPluginStateIds({ workspaceId })) {
256
- try {
257
- await persistent.withPluginLock({ workspaceRoot, pluginId, run: () => reconcilePlugin({ workspaceId, pluginId }) });
258
- }
259
- catch (error) {
260
- failures.push(error);
261
- ports.onEvent?.({ event: 'agent-plugin-update-recovery-failed', message: `Plugin '${pluginId}': an interrupted update could not be recovered (${errorCode({ error })}); it is kept off until a later boot recovers it.` });
262
- }
263
- }
264
- if (failures.length)
265
- throw failures[0];
204
+ await scope.ports.filesystem.chmod(oldRoot, 0o555);
205
+ }
206
+ /** @returns false when the old revision's MCP roster could not be re-provisioned; the bytes are
207
+ * already back, so the caller degrades to "restored but off" instead of wedging the journal. */
208
+ async function reprovisionOld({ scope, workspaceId, journal, oldRoot }) {
209
+ try {
210
+ const installed = await scope.index.indexInstalledRoot({ packageRoot: oldRoot, archiveDigest: journal.fromDigest });
211
+ await provisionAgentPluginMcp({ mcpProvisioning: scope.ports.mcpProvisioning, workspaceId, installed });
212
+ return true;
266
213
  }
267
- /** Workspace entries that can be plugin state roots. Reserved names (staging, packages, memory,
268
- * data) and invalid ids are rejected by the layout itself and are skipped, never locked. */
269
- async function listPluginStateIds({ workspaceId }, _optional = {}) {
270
- const workspace = ports.layout.forWorkspace({ workspaceId });
271
- let entries;
214
+ catch {
215
+ return false;
216
+ }
217
+ }
218
+ /** Boot only, before serving runs: recover incomplete switches, file committed audits, then
219
+ * collect retained rollback bytes. One plugin's failure does not stop the others; the first
220
+ * failure is rethrown afterwards. Bundled plugins have no update journal and get no decisions.
221
+ * @complexity O(p + f) workspace entries and retained rollback files.
222
+ */
223
+ async function reconcileAgentPluginUpdates({ scope, workspaceId }) {
224
+ const workspaceRoot = scope.ports.layout.forWorkspace({ workspaceId }).root;
225
+ const failures = [];
226
+ for (const pluginId of await listPluginStateIds({ scope, workspaceId })) {
272
227
  try {
273
- entries = await ports.filesystem.readdir(workspace.root, { withFileTypes: true });
228
+ await scope.persistent.withPluginLock({ workspaceRoot, pluginId, run: () => reconcilePlugin({ scope, workspaceId, pluginId }) });
274
229
  }
275
230
  catch (error) {
276
- if (!isMissing({ error }))
277
- throw error;
278
- return [];
231
+ failures.push(error);
232
+ scope.ports.onEvent?.({ event: 'agent-plugin-update-recovery-failed', message: `Plugin '${pluginId}': an interrupted update could not be recovered (${errorCode({ error })}); it is kept off until a later boot recovers it.` });
279
233
  }
280
- return entries.filter(entry => entry.isDirectory() && isPluginStateRoot({ workspace, pluginId: entry.name })).map(entry => entry.name);
281
234
  }
282
- function isPluginStateRoot({ workspace, pluginId }) {
283
- try {
284
- workspace.pluginRootDir({ pluginId });
285
- return true;
286
- }
287
- catch {
288
- return false;
289
- }
235
+ if (failures.length)
236
+ throw failures[0];
237
+ }
238
+ /** Workspace entries that can be plugin state roots. Reserved names (staging, packages, memory,
239
+ * data) and invalid ids are rejected by the layout itself and are skipped, never locked. */
240
+ async function listPluginStateIds({ scope, workspaceId }) {
241
+ const workspace = scope.ports.layout.forWorkspace({ workspaceId });
242
+ let entries;
243
+ try {
244
+ entries = await scope.ports.filesystem.readdir(workspace.root, { withFileTypes: true });
290
245
  }
291
- async function reconcilePlugin({ workspaceId, pluginId }, _optional = {}) {
292
- const store = createAgentPluginUpdateStore({ ports, workspaceId, pluginId });
293
- const switchOff = (error) => switchOffUnrecovered({ workspaceId, pluginId, error });
294
- const journal = await store.read({}).catch(switchOff);
295
- // A committed update only needs finishing; any other journal is rolled back.
296
- const committed = journal?.state === 'committed';
297
- if (journal && committed)
298
- await store.finish({ journal });
299
- if (journal && !committed)
300
- await restoreUpdate({ workspaceId, journal }).catch(switchOff);
301
- for (const rollbackRoot of await store.listRollbackRoots({}))
302
- await removal.removeFrozenPackageTree(rollbackRoot);
246
+ catch (error) {
247
+ if (!isMissing({ error }))
248
+ throw error;
249
+ return [];
303
250
  }
304
- /** Unrecovered = off: an unreadable journal or a failed restore switches the plugin off (best
305
- * effort; the journal stays, so the next boot retries) and rethrows. A failure only filing a
306
- * committed audit or collecting rollback bytes never reaches here. Bundled plugins never get a
307
- * journal from this module and are never touched. */
308
- async function switchOffUnrecovered({ workspaceId, pluginId, error }, _optional = {}) {
309
- const workspaceRoot = ports.layout.forWorkspace({ workspaceId }).root;
310
- try {
311
- if (!await activation.isAgentPluginRecordedAsBundled(workspaceRoot, pluginId)) {
312
- await activation.setAgentPluginActivation({ workspaceRoot, pluginId, enabled: false, actor: 'system:update-recovery' }, { origin: 'operator-installed' });
313
- }
314
- }
315
- catch { /* best effort: the retained journal keeps refusing mutations until a boot recovers it */ }
316
- throw error;
251
+ return entries.filter(entry => entry.isDirectory() && isPluginStateRoot({ workspace, pluginId: entry.name })).map(entry => entry.name);
252
+ }
253
+ function isPluginStateRoot({ workspace, pluginId }) {
254
+ try {
255
+ workspace.pluginRootDir({ pluginId });
256
+ return true;
257
+ }
258
+ catch {
259
+ return false;
317
260
  }
318
- function errorCode({ error }, _optional = {}) {
319
- return typeof error === 'object' && error !== null && 'code' in error ? String(error.code) : 'unknown error';
261
+ }
262
+ async function reconcilePlugin({ scope, workspaceId, pluginId }) {
263
+ const store = createAgentPluginUpdateStore({ ports: scope.ports, workspaceId, pluginId });
264
+ const switchOff = (error) => switchOffUnrecovered({ scope, workspaceId, pluginId, error });
265
+ const journal = await store.read({}).catch(switchOff);
266
+ // A committed update only needs finishing; any other journal is rolled back.
267
+ const committed = journal?.state === 'committed';
268
+ if (journal && committed)
269
+ await store.finish({ journal });
270
+ if (journal && !committed)
271
+ await restoreUpdate({ scope, workspaceId, journal }).catch(switchOff);
272
+ for (const rollbackRoot of await store.listRollbackRoots({}))
273
+ await scope.removal.removeFrozenPackageTree(rollbackRoot);
274
+ }
275
+ /** Unrecovered = off: an unreadable journal or a failed restore switches the plugin off (best
276
+ * effort; the journal stays, so the next boot retries) and rethrows. A failure only filing a
277
+ * committed audit or collecting rollback bytes never reaches here. Bundled plugins never get a
278
+ * journal from this module and are never touched. */
279
+ async function switchOffUnrecovered({ scope, workspaceId, pluginId, error }) {
280
+ const workspaceRoot = scope.ports.layout.forWorkspace({ workspaceId }).root;
281
+ try {
282
+ if (!await scope.activation.isAgentPluginRecordedAsBundled(workspaceRoot, pluginId)) {
283
+ await scope.activation.setAgentPluginActivation({ workspaceRoot, pluginId, enabled: false, actor: 'system:update-recovery' }, { origin: 'operator-installed' });
284
+ }
320
285
  }
321
- return { updateAgentPlugin, reconcileAgentPluginUpdates };
286
+ catch { /* best effort: the retained journal keeps refusing mutations until a boot recovers it */ }
287
+ throw error;
288
+ }
289
+ function errorCode({ error }, _optional = {}) {
290
+ return typeof error === 'object' && error !== null && 'code' in error ? String(error.code) : 'unknown error';
291
+ }
292
+ /** Update transaction owner for operator-installed plugins (bundled ones stay seed-managed).
293
+ *
294
+ * Runs inside the installer's identity lock and per-plugin file lock (the publish guard), so it is
295
+ * serialized against enable/disable/uninstall, which take the same plugin lock. Nothing called in
296
+ * the guard re-takes that lock: activation writes use their own activations.json lock.
297
+ *
298
+ * Invariant: never two live digests. The old revision moves to a frozen rollback area outside
299
+ * `package/sha256` before the candidate is published; a per-plugin journal (pending -> published ->
300
+ * committed) lets boot reconciliation restore it if the process dies before commit.
301
+ *
302
+ * Documented behavior:
303
+ * - In-flight MCP calls against the old revision may fail once the roster is re-provisioned.
304
+ * - Running chats keep the skill text they already captured; new runs resolve the new revision.
305
+ * - Rollback bytes are retained after commit (a run may still read them) and collected by the next
306
+ * boot's reconciliation, when no run can hold those paths.
307
+ * - Plugin data and memory directories carry over untouched. A rollback restores package bytes and
308
+ * activation only; it does NOT revert data, memory or settings written while the candidate ran.
309
+ * The settings snapshot is an audit record, not a restore source.
310
+ * - Caches: this package keeps no cache of skill prompt indexes or search ranking keyed by plugin
311
+ * (search ranking is computed per call from the installed list; per-run automatic-use state is
312
+ * per run; module imports are keyed by the digest path), so a switch has nothing to invalidate.
313
+ */
314
+ export function createUpdateModule(ports, optional = {}) {
315
+ const scope = {
316
+ ports,
317
+ installAgentPlugin: optional.installAgentPlugin ?? createInstallModule(ports).installAgentPlugin,
318
+ activation: createActivationModule(ports),
319
+ removal: createUninstallModule(ports),
320
+ refs: createResolveAgentPluginRefsModule(ports),
321
+ persistent: createPersistentStateModule(ports),
322
+ index: createInstalledPackageIndex({ ports }),
323
+ };
324
+ return {
325
+ updateAgentPlugin: (required, _optional = {}) => updateAgentPlugin({ scope, required }),
326
+ reconcileAgentPluginUpdates: ({ workspaceId }, _optional = {}) => reconcileAgentPluginUpdates({ scope, workspaceId }),
327
+ };
322
328
  }
323
329
  //# sourceMappingURL=update.js.map