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

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 (236) 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 +10 -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.d.ts +4 -2
  69. package/dist/lifecycle/host-tools/search-tool.js +9 -8
  70. package/dist/lifecycle/host-tools/skill-tool.d.ts +18 -2
  71. package/dist/lifecycle/host-tools/skill-tool.js +16 -8
  72. package/dist/lifecycle/index.d.ts +118 -110
  73. package/dist/lifecycle/index.js +45 -12
  74. package/dist/lifecycle/install-errors.d.ts +1 -1
  75. package/dist/lifecycle/install-from-url.d.ts +1 -1
  76. package/dist/lifecycle/install-from-url.js +1 -1
  77. package/dist/lifecycle/install.d.ts +7 -2
  78. package/dist/lifecycle/install.js +414 -396
  79. package/dist/lifecycle/installed-package-index.js +45 -42
  80. package/dist/lifecycle/layout.d.ts +1 -1
  81. package/dist/lifecycle/layout.js +1 -1
  82. package/dist/lifecycle/mail/catalog.d.ts +8 -32
  83. package/dist/lifecycle/mail/catalog.js +25 -20
  84. package/dist/lifecycle/mail/contribution.d.ts +2 -2
  85. package/dist/lifecycle/mail/contribution.js +34 -34
  86. package/dist/lifecycle/mail/selection.js +6 -2
  87. package/dist/lifecycle/manifest.d.ts +3 -3
  88. package/dist/lifecycle/manifest.js +4 -4
  89. package/dist/lifecycle/mcp-provisioning.d.ts +3 -3
  90. package/dist/lifecycle/mcp-provisioning.js +3 -3
  91. package/dist/lifecycle/package-paths.d.ts +1 -1
  92. package/dist/lifecycle/package-paths.js +1 -1
  93. package/dist/lifecycle/persistent-state.js +1 -2
  94. package/dist/lifecycle/ports.d.ts +5 -1
  95. package/dist/lifecycle/resolve-agent-plugin-refs.d.ts +30 -8
  96. package/dist/lifecycle/resolve-agent-plugin-refs.js +227 -228
  97. package/dist/lifecycle/retire-bundled.d.ts +1 -52
  98. package/dist/lifecycle/retire-bundled.js +134 -84
  99. package/dist/lifecycle/search.d.ts +2 -1
  100. package/dist/lifecycle/search.js +1 -1
  101. package/dist/lifecycle/seed-bundled.d.ts +1 -1
  102. package/dist/lifecycle/seed-bundled.js +154 -155
  103. package/dist/lifecycle/set-enabled.d.ts +1 -1
  104. package/dist/lifecycle/set-enabled.js +1 -1
  105. package/dist/lifecycle/skill-file-reader.js +53 -50
  106. package/dist/lifecycle/tools/projection.d.ts +4 -7
  107. package/dist/lifecycle/tools/projection.js +109 -108
  108. package/dist/lifecycle/trusted-plugin-files.d.ts +2 -2
  109. package/dist/lifecycle/trusted-plugin-files.js +1 -1
  110. package/dist/lifecycle/uninstall.d.ts +1 -1
  111. package/dist/lifecycle/uninstall.js +237 -241
  112. package/dist/lifecycle/update-store.js +20 -17
  113. package/dist/lifecycle/update.js +287 -281
  114. package/dist/lifecycle/yauzl-archive-reader.d.ts +2 -2
  115. package/dist/lifecycle/yauzl-archive-reader.js +8 -2
  116. package/dist/manifest.d.ts +11 -3
  117. package/dist/manifest.js +9 -9
  118. package/fly/jini-credential-schemes.json +11 -0
  119. package/fly/plugin.json +3 -4
  120. package/github/plugin.json +3 -3
  121. package/github/source-control/backup-push.mjs +11 -11
  122. package/github/source-control/commit-site.mjs +23 -13
  123. package/github/source-control/github.mjs +12 -6
  124. package/github/source-control/write-files.mjs +27 -28
  125. package/github-pages/{tovu-deploy-targets.json → jini-deploy-targets.json} +22 -22
  126. package/github-pages/plugin.json +3 -3
  127. package/github-pages/targets/github-pages.mjs +3 -3
  128. package/google-login/plugin.json +3 -3
  129. package/google-workspace/README.md +14 -14
  130. package/google-workspace/form-destinations/README.md +3 -3
  131. package/google-workspace/form-destinations/dedupe.mjs +1 -1
  132. package/google-workspace/form-destinations/mapping.mjs +8 -9
  133. package/google-workspace/form-destinations/sheets.mjs +1 -1
  134. package/google-workspace/{tovu-admin-surfaces.json → jini-admin-surfaces.json} +2 -2
  135. package/google-workspace/{tovu-agent-tools.json → jini-agent-tools.json} +28 -28
  136. package/google-workspace/{tovu-connections.json → jini-connections.json} +2 -2
  137. package/google-workspace/lib/auth.mjs +2 -2
  138. package/google-workspace/lib/form-destination-settings.mjs +1 -1
  139. package/google-workspace/lib/picker-flow.mjs +2 -2
  140. package/google-workspace/lib/request-policy.mjs +1 -1
  141. package/google-workspace/lib/surface-actions.mjs +1 -1
  142. package/google-workspace/plugin.json +3 -3
  143. package/google-workspace/tools/sheets/README.md +3 -3
  144. package/google-workspace/tools/sheets-admin/README.md +3 -3
  145. package/google-workspace/ui/README.md +4 -4
  146. package/google-workspace/ui/connection-panel.mjs +51 -51
  147. package/google-workspace/ui/destination-panel.mjs +34 -34
  148. package/google-workspace/ui/dom.mjs +15 -16
  149. package/google-workspace/ui/picker-flow.mjs +2 -2
  150. package/google-workspace/ui/picker.mjs +19 -19
  151. package/google-workspace/ui/surface-client.mjs +96 -69
  152. package/higgsfield-media/plugin.json +3 -3
  153. package/jev/plugin.json +3 -3
  154. package/kuinetic/CHANGELOG.md +12 -0
  155. package/kuinetic/mcp.json +4 -0
  156. package/kuinetic/plugin.json +27 -0
  157. package/kuinetic/skills/kuinetic/SKILL.md +120 -0
  158. package/kuinetic/skills/kuinetic/references/effects-by-family.md +32 -0
  159. package/kuinetic/skills/kuinetic/references/opt-in-tiers.md +12 -0
  160. package/kuinetic/skills/kuinetic/references/reserved-keys.md +36 -0
  161. package/meilisearch/plugin.json +5 -5
  162. package/netlify/plugin.json +3 -3
  163. package/netlify/targets/netlify.mjs +14 -4
  164. package/opentelemetry/plugin.json +3 -3
  165. package/package.json +27 -22
  166. package/posthog/plugin.json +3 -3
  167. package/railway/plugin.json +3 -3
  168. package/render/plugin.json +3 -3
  169. package/resend/NOTES.md +2 -2
  170. package/resend/adapters/resend.mjs +1 -1
  171. package/resend/{tovu-mail-adapters.json → jini-mail-adapters.json} +1 -1
  172. package/resend/lib/domains.mjs +8 -8
  173. package/resend/plugin.json +3 -3
  174. package/s3-compatible/{tovu-deploy-targets.json → jini-deploy-targets.json} +68 -68
  175. package/s3-compatible/jini-object-stores.json +29 -0
  176. package/s3-compatible/object-stores/s3-compatible.mjs +19 -13
  177. package/s3-compatible/plugin.json +3 -3
  178. package/s3-compatible/targets/s3-compatible.mjs +25 -25
  179. package/sentry/plugin.json +3 -3
  180. package/shadcn-ui/CHANGELOG.md +7 -0
  181. package/shadcn-ui/LICENSE +201 -0
  182. package/shadcn-ui/NOTICE +10 -0
  183. package/shadcn-ui/mcp.json +4 -0
  184. package/shadcn-ui/plugin.json +26 -0
  185. package/shopify/plugin.json +3 -3
  186. package/site-compliance/plugin.json +3 -3
  187. package/site-import/plugin.json +3 -3
  188. package/supabase/mcp.json +1 -4
  189. package/supabase/plugin.json +3 -3
  190. package/ui-ux-design/CHANGELOG.md +13 -0
  191. package/ui-ux-design/NOTICE +2 -0
  192. package/ui-ux-design/README.md +17 -7
  193. package/ui-ux-design/plugin.json +6 -3
  194. package/ui-ux-design/skills/ui-ux-design/SKILL.md +38 -152
  195. package/ui-ux-design/skills/ui-ux-design/references/full-workflow.md +156 -0
  196. package/ui-ux-design/skills/ui-ux-design/references/ui-animation.md +4 -4
  197. package/vercel/NOTES.md +1 -1
  198. package/vercel/object-stores/vercel-blob.mjs +12 -2
  199. package/vercel/plugin.json +3 -3
  200. package/vercel/targets/vercel.mjs +3 -3
  201. package/wordpress/plugin.json +3 -3
  202. package/dist/lifecycle/node.d.ts +0 -11
  203. package/dist/lifecycle/node.js +0 -38
  204. package/fly/tovu-credential-schemes.json +0 -11
  205. package/github/deployments/github.mjs +0 -415
  206. package/s3-compatible/tovu-object-stores.json +0 -29
  207. package/ui-ux-design/skills/ui-ux-design/references/kuinetic-reference.md +0 -184
  208. /package/cloudflare/{tovu-consent.json → jini-consent.json} +0 -0
  209. /package/cloudflare/{tovu-deploy-targets.json → jini-deploy-targets.json} +0 -0
  210. /package/cloudflare/{tovu-form-destinations.json → jini-form-destinations.json} +0 -0
  211. /package/fly/{tovu-deploy-configs.json → jini-deploy-configs.json} +0 -0
  212. /package/fly/{tovu-deploy-ops.json → jini-deploy-ops.json} +0 -0
  213. /package/github/{tovu-deploy-ops.json → jini-deploy-ops.json} +0 -0
  214. /package/github/{tovu-source-control.json → jini-source-control.json} +0 -0
  215. /package/google-login/{tovu-login-providers.json → jini-login-providers.json} +0 -0
  216. /package/google-workspace/{tovu-form-destinations.json → jini-form-destinations.json} +0 -0
  217. /package/meilisearch/{tovu-search-providers.json → jini-search-providers.json} +0 -0
  218. /package/netlify/{tovu-consent.json → jini-consent.json} +0 -0
  219. /package/netlify/{tovu-deploy-targets.json → jini-deploy-targets.json} +0 -0
  220. /package/railway/{tovu-deploy-configs.json → jini-deploy-configs.json} +0 -0
  221. /package/railway/{tovu-deploy-ops.json → jini-deploy-ops.json} +0 -0
  222. /package/render/{tovu-deploy-configs.json → jini-deploy-configs.json} +0 -0
  223. /package/render/{tovu-deploy-ops.json → jini-deploy-ops.json} +0 -0
  224. /package/{ui-ux-design → shadcn-ui}/skills/shadcn-ui/README.md +0 -0
  225. /package/{ui-ux-design → shadcn-ui}/skills/shadcn-ui/SKILL.md +0 -0
  226. /package/{ui-ux-design → shadcn-ui}/skills/shadcn-ui/examples/auth-layout.tsx +0 -0
  227. /package/{ui-ux-design → shadcn-ui}/skills/shadcn-ui/examples/data-table.tsx +0 -0
  228. /package/{ui-ux-design → shadcn-ui}/skills/shadcn-ui/examples/form-pattern.tsx +0 -0
  229. /package/{ui-ux-design → shadcn-ui}/skills/shadcn-ui/resources/component-catalog.md +0 -0
  230. /package/{ui-ux-design → shadcn-ui}/skills/shadcn-ui/resources/customization-guide.md +0 -0
  231. /package/{ui-ux-design → shadcn-ui}/skills/shadcn-ui/resources/migration-guide.md +0 -0
  232. /package/{ui-ux-design → shadcn-ui}/skills/shadcn-ui/resources/setup-guide.md +0 -0
  233. /package/{ui-ux-design → shadcn-ui}/skills/shadcn-ui/scripts/verify-setup.sh +0 -0
  234. /package/vercel/{tovu-consent.json → jini-consent.json} +0 -0
  235. /package/vercel/{tovu-deploy-targets.json → jini-deploy-targets.json} +0 -0
  236. /package/vercel/{tovu-object-stores.json → jini-object-stores.json} +0 -0
@@ -3,7 +3,7 @@
3
3
  * on-disk package(s) under `packages/sha256/*` for this `pluginId`, then its activation record.
4
4
  * `previewAgentPluginUninstall()` runs the same refusals without removing anything.
5
5
  *
6
- * `features/plugin-runtime/uninstall.ts` already has this exact feature for the OTHER plugin family
6
+ * `packages/plugins/src/host/uninstall.ts` already has this exact feature for the OTHER plugin family
7
7
  * (the host runtime-plugin format site/runtime plugins) — this is "the same feature, one family over", mirroring its
8
8
  * shape: the same `<Domain>NotFoundError`/`<Domain>NotUninstallableError` pair, thrown for the same
9
9
  * two reasons (unknown id; nothing an operator can actually remove). Two deliberate divergences from
@@ -127,273 +127,269 @@ export class AgentPluginNotUninstallableError extends Error {
127
127
  export class AgentPluginChangedSincePreviewError extends Error {
128
128
  constructor({ message }, optional = {}) { super(message, optional); }
129
129
  }
130
- function buildModule(ports) {
131
- const randomUUID = () => ports.ids.newId();
132
- const { assertContainedOnDisk } = createPackagePathsModule(ports);
133
- const rmdir = ports.filesystem.rmdir.bind(ports.filesystem);
134
- const chmod = ports.filesystem.chmod.bind(ports.filesystem);
135
- const readdir = ports.filesystem.readdir.bind(ports.filesystem);
136
- const rename = ports.filesystem.rename.bind(ports.filesystem);
137
- const rm = ports.filesystem.rm.bind(ports.filesystem);
138
- const stat = ports.filesystem.stat.bind(ports.filesystem);
139
- const { deleteAgentPluginActivation, isAgentPluginRecordedAsBundled, resolveAgentPluginActivation } = createActivationModule(ports);
140
- const { listInstalledPlugins } = createResolveAgentPluginRefsModule(ports);
141
- const STAGED_DIRNAME_PREFIX = ".uninstalling-";
142
- /**
143
- * Reports what uninstalling `pluginId` would remove, without removing anything.
144
- *
145
- * @throws {AgentPluginNotFoundError} No installed package for `pluginId` exists in this workspace.
146
- * @throws {AgentPluginNotUninstallableError} The plugin's activation record has `origin: "bundled"`, or a malformed
147
- * entry for it (t91 R4).
148
- * @throws {AgentPluginActivationsUnreadableError} The activation record could not be read at all, so
149
- * whether it says "bundled" cannot be established — see `activation.ts`'s
150
- * `isAgentPluginRecordedAsBundled`.
151
- * @complexity O(d) in this workspace's installed-digest count (one `listInstalledPlugins` walk).
152
- */
153
- async function previewAgentPluginUninstall(required) {
154
- const { matches } = await resolveUninstallTargets(required);
155
- const versions = [...new Set(matches.flatMap((plugin) => (plugin.version === undefined ? [] : [plugin.version])))];
156
- return { pluginId: required.pluginId, versions, archiveDigests: matches.map((plugin) => plugin.archiveDigest) };
130
+ const STAGED_DIRNAME_PREFIX = ".uninstalling-";
131
+ /**
132
+ * Reports what uninstalling `pluginId` would remove, without removing anything.
133
+ *
134
+ * @throws {AgentPluginNotFoundError} No installed package for `pluginId` exists in this workspace.
135
+ * @throws {AgentPluginNotUninstallableError} The plugin's activation record has `origin: "bundled"`, or a malformed
136
+ * entry for it (t91 R4).
137
+ * @throws {AgentPluginActivationsUnreadableError} The activation record could not be read at all, so
138
+ * whether it says "bundled" cannot be established — see `activation.ts`'s
139
+ * `createActivationModule(ports).isAgentPluginRecordedAsBundled`.
140
+ * @complexity O(d) in this workspace's installed-digest count (one `createResolveAgentPluginRefsModule(ports).listInstalledPlugins` walk).
141
+ */
142
+ async function previewAgentPluginUninstall({ ports, required }) {
143
+ const { matches } = await resolveUninstallTargets({ ports, required });
144
+ const versions = [...new Set(matches.flatMap((plugin) => (plugin.version === undefined ? [] : [plugin.version])))];
145
+ return { pluginId: required.pluginId, versions, archiveDigests: matches.map((plugin) => plugin.archiveDigest) };
146
+ }
147
+ /**
148
+ * Uninstalls one workspace's installed Agent Plugin: removes every installed archive digest for
149
+ * `pluginId` under this workspace's own `packages/sha256/`, then deletes its activation record.
150
+ *
151
+ * @throws {AgentPluginNotFoundError} No installed package for `pluginId` exists in this workspace.
152
+ * @throws {AgentPluginNotUninstallableError} The plugin's activation record has `origin: "bundled"`, or a malformed
153
+ * entry for it (t91 R4).
154
+ * @throws {AgentPluginActivationsUnreadableError} The activation record could not be read — refused
155
+ * before anything is staged, so nothing is removed.
156
+ * @throws {AgentPluginChangedSincePreviewError} `optional.confirmedPreview` was given and the installed digests differ from it.
157
+ * @throws Whatever the filesystem raised, after every staged tree has been put back — or, if a tree
158
+ * could not be put back, an error naming the staged paths an operator must recover by hand.
159
+ * @complexity O(d) in this workspace's installed-digest count (one `createResolveAgentPluginRefsModule(ports).listInstalledPlugins` walk) plus
160
+ * O(f) in the total file count under the matching digest(s) being removed.
161
+ */
162
+ async function uninstallAgentPlugin({ ports, required }, optional = {}) {
163
+ const workspaceRoot = required.layout.forWorkspace({ workspaceId: required.workspaceId }).root;
164
+ return createPersistentStateModule(ports).withPluginLock({ workspaceRoot, pluginId: required.pluginId,
165
+ run: () => uninstallAgentPluginUnlocked({ ports, required }, optional) });
166
+ }
167
+ async function uninstallAgentPluginUnlocked({ ports, required }, optional = {}) {
168
+ const { workspaceRoot, packagesDir, matches } = await resolveUninstallTargets({ ports, required }, { retiredBundled: optional.retiredBundled === true });
169
+ assertUnchangedSincePreview({ pluginId: required.pluginId, confirmedPreview: optional.confirmedPreview, matches });
170
+ assertMemoryDeletionConfirmed(required, optional);
171
+ // An unfinished update journal would make boot recovery resurrect the old revision over this
172
+ // uninstall, so it refuses (PLUGIN_UPDATE_PENDING) until a boot recovers it. The store resolves
173
+ // paths from this call's own layout, like every other path here.
174
+ const updates = createAgentPluginUpdateStore({ ports: { ...ports, layout: required.layout }, workspaceId: required.workspaceId, pluginId: required.pluginId });
175
+ await settleAgentPluginUpdateJournal({ store: updates });
176
+ const staged = await stageAndDeleteActivation(ports, { workspaceRoot, packagesDir, pluginId: required.pluginId, matches });
177
+ // Past this point the live state is already settled: the packages are no longer reachable under
178
+ // any installed-digest name and the activation record is gone. These removes are the only
179
+ // irreversible step, and nothing observable depends on them finishing.
180
+ for (const tree of staged) {
181
+ await removeFrozenPackageTree({ ports, root: tree.quarantined });
157
182
  }
158
- /**
159
- * Uninstalls one workspace's installed Agent Plugin: removes every installed archive digest for
160
- * `pluginId` under this workspace's own `packages/sha256/`, then deletes its activation record.
161
- *
162
- * @throws {AgentPluginNotFoundError} No installed package for `pluginId` exists in this workspace.
163
- * @throws {AgentPluginNotUninstallableError} The plugin's activation record has `origin: "bundled"`, or a malformed
164
- * entry for it (t91 R4).
165
- * @throws {AgentPluginActivationsUnreadableError} The activation record could not be read — refused
166
- * before anything is staged, so nothing is removed.
167
- * @throws {AgentPluginChangedSincePreviewError} `optional.confirmedPreview` was given and the installed digests differ from it.
168
- * @throws Whatever the filesystem raised, after every staged tree has been put back — or, if a tree
169
- * could not be put back, an error naming the staged paths an operator must recover by hand.
170
- * @complexity O(d) in this workspace's installed-digest count (one `listInstalledPlugins` walk) plus
171
- * O(f) in the total file count under the matching digest(s) being removed.
172
- */
173
- async function uninstallAgentPlugin(required, optional = {}) {
174
- const workspaceRoot = required.layout.forWorkspace({ workspaceId: required.workspaceId }).root;
175
- return createPersistentStateModule(ports).withPluginLock({ workspaceRoot, pluginId: required.pluginId,
176
- run: () => uninstallAgentPluginUnlocked(required, optional) });
183
+ await removeEmptyPackageAncestors(ports, { packagesDir });
184
+ if (optional.deleteMemory)
185
+ await deletePersistentMemory(ports, { ...required, workspaceRoot });
186
+ return { pluginId: required.pluginId, removedDigests: matches.map((plugin) => plugin.archiveDigest) };
187
+ }
188
+ function assertMemoryDeletionConfirmed(required, optional) {
189
+ if (optional.deleteMemory && optional.confirmedPreview?.pluginId !== required.pluginId) {
190
+ throw new Error('Deleting plugin memory requires a confirmed preview for this plugin');
177
191
  }
178
- async function uninstallAgentPluginUnlocked(required, optional = {}) {
179
- const { workspaceRoot, packagesDir, matches } = await resolveUninstallTargets(required, optional.retiredBundled === true);
180
- assertUnchangedSincePreview(required.pluginId, optional.confirmedPreview, matches);
181
- assertMemoryDeletionConfirmed(required, optional);
182
- // An unfinished update journal would make boot recovery resurrect the old revision over this
183
- // uninstall, so it refuses (PLUGIN_UPDATE_PENDING) until a boot recovers it. The store resolves
184
- // paths from this call's own layout, like every other path here.
185
- const updates = createAgentPluginUpdateStore({ ports: { ...ports, layout: required.layout }, workspaceId: required.workspaceId, pluginId: required.pluginId });
186
- await settleAgentPluginUpdateJournal({ store: updates });
187
- const staged = await stageAndDeleteActivation({ workspaceRoot, packagesDir, pluginId: required.pluginId, matches });
188
- // Past this point the live state is already settled: the packages are no longer reachable under
189
- // any installed-digest name and the activation record is gone. These removes are the only
190
- // irreversible step, and nothing observable depends on them finishing.
191
- for (const tree of staged) {
192
- await removeFrozenPackageTree(tree.quarantined);
192
+ }
193
+ /** Reversible work first — see this file's header, "Why removal stages first". Nothing in here is
194
+ * destructive: every step up to and including the activation-record delete can be undone by
195
+ * renaming the staged trees back where they came from. */
196
+ async function stageAndDeleteActivation(ports, required) {
197
+ const staged = [];
198
+ try {
199
+ for (const plugin of required.matches) {
200
+ staged.push(await stageForRemoval({ ports, packagesDir: required.packagesDir, packageRoot: plugin.packageRoot }));
193
201
  }
194
- await removeEmptyPackageAncestors({ packagesDir });
195
- if (optional.deleteMemory)
196
- await deletePersistentMemory({ ...required, workspaceRoot });
197
- return { pluginId: required.pluginId, removedDigests: matches.map((plugin) => plugin.archiveDigest) };
202
+ await createActivationModule(ports).deleteAgentPluginActivation({ workspaceRoot: required.workspaceRoot, pluginId: required.pluginId });
198
203
  }
199
- function assertMemoryDeletionConfirmed(required, optional) {
200
- if (optional.deleteMemory && optional.confirmedPreview?.pluginId !== required.pluginId) {
201
- throw new Error('Deleting plugin memory requires a confirmed preview for this plugin');
202
- }
204
+ catch (error) {
205
+ throw await restoreStagedTrees({ ports, staged, cause: error });
203
206
  }
204
- /** Reversible work first — see this file's header, "Why removal stages first". Nothing in here is
205
- * destructive: every step up to and including the activation-record delete can be undone by
206
- * renaming the staged trees back where they came from. */
207
- async function stageAndDeleteActivation(required) {
208
- const staged = [];
207
+ return staged;
208
+ }
209
+ /** Remove only empty package ancestors: a concurrently-installed digest must never be deleted. */
210
+ async function removeEmptyPackageAncestors(ports, required) {
211
+ for (const directory of [required.packagesDir, path.dirname(required.packagesDir)]) {
209
212
  try {
210
- for (const plugin of required.matches) {
211
- staged.push(await stageForRemoval(required.packagesDir, plugin.packageRoot));
212
- }
213
- await deleteAgentPluginActivation({ workspaceRoot: required.workspaceRoot, pluginId: required.pluginId });
213
+ await ports.filesystem.rmdir(directory);
214
214
  }
215
215
  catch (error) {
216
- throw await restoreStagedTrees(staged, error);
216
+ if (!isAncestorStillInUse(error))
217
+ throw error;
217
218
  }
218
- return staged;
219
219
  }
220
- /** Remove only empty package ancestors: a concurrently-installed digest must never be deleted. */
221
- async function removeEmptyPackageAncestors(required) {
222
- for (const directory of [required.packagesDir, path.dirname(required.packagesDir)]) {
223
- try {
224
- await rmdir(directory);
225
- }
226
- catch (error) {
227
- if (!isAncestorStillInUse(error))
228
- throw error;
229
- }
230
- }
231
- }
232
- function isAncestorStillInUse(error) {
233
- return typeof error === 'object' && error !== null && 'code' in error && ['ENOENT', 'ENOTEMPTY', 'EEXIST'].includes(String(error.code));
234
- }
235
- /** No package may have appeared since this uninstall's preview. Preserve it on a race. */
236
- async function deletePersistentMemory(required) {
237
- const { workspaceRoot, pluginId } = required;
238
- const pluginRoot = required.layout.forWorkspace({ workspaceId: required.workspaceId }).pluginRootDir({ pluginId });
239
- await assertContainedOnDisk(workspaceRoot, path.relative(workspaceRoot, pluginRoot));
240
- if ((await listInstalledPlugins(workspaceRoot)).some(plugin => plugin.pluginId === pluginId))
241
- throw new Error('Plugin was reinstalled during uninstall; persistent memory was kept');
242
- await rm(pluginRoot, { recursive: true, force: true });
220
+ }
221
+ function isAncestorStillInUse(error) {
222
+ return typeof error === 'object' && error !== null && 'code' in error && ['ENOENT', 'ENOTEMPTY', 'EEXIST'].includes(String(error.code));
223
+ }
224
+ /** No package may have appeared since this uninstall's preview. Preserve it on a race. */
225
+ async function deletePersistentMemory(ports, required) {
226
+ const { workspaceRoot, pluginId } = required;
227
+ const pluginRoot = required.layout.forWorkspace({ workspaceId: required.workspaceId }).pluginRootDir({ pluginId });
228
+ await createPackagePathsModule(ports).assertContainedOnDisk(workspaceRoot, path.relative(workspaceRoot, pluginRoot));
229
+ if ((await createResolveAgentPluginRefsModule(ports).listInstalledPlugins(workspaceRoot)).some(plugin => plugin.pluginId === pluginId))
230
+ throw new Error('Plugin was reinstalled during uninstall; persistent memory was kept');
231
+ await ports.filesystem.rm(pluginRoot, { recursive: true, force: true });
232
+ }
233
+ /**
234
+ * Refuses when the digests resolved now are not exactly the set a confirmed preview listed — an archive added
235
+ * OR removed for this id while the dialog was open. Runs in the same call that stages the removal, so it opens
236
+ * no new check-then-act gap of its own.
237
+ *
238
+ * @throws {AgentPluginChangedSincePreviewError} The two digest sets differ.
239
+ * @complexity O(d log d) in the digest count.
240
+ */
241
+ function assertUnchangedSincePreview({ pluginId, confirmedPreview, matches }) {
242
+ if (confirmedPreview === undefined)
243
+ return;
244
+ const previewed = [...confirmedPreview.archiveDigests].sort();
245
+ const installedNow = matches.map((plugin) => plugin.archiveDigest).sort();
246
+ if (previewed.join(",") === installedNow.join(","))
247
+ return;
248
+ throw new AgentPluginChangedSincePreviewError({ message: `Agent Plugin '${pluginId}' changed after its uninstall was previewed (previewed archive digests: ${previewed.join(", ")}; ` +
249
+ `installed now: ${installedNow.join(", ")}) — nothing was removed` });
250
+ }
251
+ /**
252
+ * Renames one package root aside, inside its own parent directory, so removing it becomes
253
+ * reversible. Unfreezes the root directory itself first — a frozen directory cannot be renamed at
254
+ * all (see this file's header) — and re-freezes it if the ports.filesystem.rename fails, so a package this function
255
+ * could not stage is left exactly as it found it.
256
+ *
257
+ * @complexity One `ports.filesystem.stat`, one or two `ports.filesystem.chmod`s, one `ports.filesystem.rename`.
258
+ */
259
+ async function stageForRemoval({ ports, packagesDir, packageRoot }, optional = {}) {
260
+ // Updates choose a journaled destination outside packages/sha256; uninstall keeps its sibling
261
+ // destination and same-filesystem guarantee documented above. Both retain the same move owner.
262
+ const quarantined = optional.quarantined ?? path.join(packagesDir, `${STAGED_DIRNAME_PREFIX}${(() => ports.ids.newId())()}`);
263
+ const originalMode = (await ports.filesystem.stat(packageRoot)).mode & 0o777;
264
+ await ports.filesystem.chmod(packageRoot, originalMode | 0o700);
265
+ try {
266
+ await ports.filesystem.rename(packageRoot, quarantined);
243
267
  }
244
- /**
245
- * Refuses when the digests resolved now are not exactly the set a confirmed preview listed — an archive added
246
- * OR removed for this id while the dialog was open. Runs in the same call that stages the removal, so it opens
247
- * no new check-then-act gap of its own.
248
- *
249
- * @throws {AgentPluginChangedSincePreviewError} The two digest sets differ.
250
- * @complexity O(d log d) in the digest count.
251
- */
252
- function assertUnchangedSincePreview(pluginId, confirmedPreview, matches) {
253
- if (confirmedPreview === undefined)
254
- return;
255
- const previewed = [...confirmedPreview.archiveDigests].sort();
256
- const installedNow = matches.map((plugin) => plugin.archiveDigest).sort();
257
- if (previewed.join(",") === installedNow.join(","))
258
- return;
259
- throw new AgentPluginChangedSincePreviewError({ message: `Agent Plugin '${pluginId}' changed after its uninstall was previewed (previewed archive digests: ${previewed.join(", ")}; ` +
260
- `installed now: ${installedNow.join(", ")}) — nothing was removed` });
268
+ catch (error) {
269
+ await ports.filesystem.chmod(packageRoot, originalMode).catch(() => undefined);
270
+ throw error;
261
271
  }
262
- /**
263
- * Renames one package root aside, inside its own parent directory, so removing it becomes
264
- * reversible. Unfreezes the root directory itself first — a frozen directory cannot be renamed at
265
- * all (see this file's header) — and re-freezes it if the rename fails, so a package this function
266
- * could not stage is left exactly as it found it.
267
- *
268
- * @complexity One `stat`, one or two `chmod`s, one `rename`.
269
- */
270
- async function stageForRemoval(packagesDir, packageRoot, optional = {}) {
271
- // Updates choose a journaled destination outside packages/sha256; uninstall keeps its sibling
272
- // destination and same-filesystem guarantee documented above. Both retain the same move owner.
273
- const quarantined = optional.quarantined ?? path.join(packagesDir, `${STAGED_DIRNAME_PREFIX}${randomUUID()}`);
274
- const originalMode = (await stat(packageRoot)).mode & 0o777;
275
- await chmod(packageRoot, originalMode | 0o700);
272
+ return { quarantined, original: packageRoot, originalMode };
273
+ }
274
+ /**
275
+ * Puts every staged tree back, newest first, and returns the error `uninstallAgentPlugin` should
276
+ * throw: `cause` when everything was restored, or — when some tree could not be — an error naming
277
+ * the staged paths, since those directories hold the only remaining copy of that package.
278
+ *
279
+ * @complexity O(s) renames in the staged-tree count.
280
+ */
281
+ async function restoreStagedTrees({ ports, staged, cause }) {
282
+ const stranded = [];
283
+ for (const tree of [...staged].reverse()) {
276
284
  try {
277
- await rename(packageRoot, quarantined);
285
+ await ports.filesystem.rename(tree.quarantined, tree.original);
286
+ await ports.filesystem.chmod(tree.original, tree.originalMode).catch(() => undefined);
278
287
  }
279
- catch (error) {
280
- await chmod(packageRoot, originalMode).catch(() => undefined);
281
- throw error;
288
+ catch {
289
+ stranded.push(tree.quarantined);
282
290
  }
283
- return { quarantined, original: packageRoot, originalMode };
284
291
  }
285
- /**
286
- * Puts every staged tree back, newest first, and returns the error `uninstallAgentPlugin` should
287
- * throw: `cause` when everything was restored, or — when some tree could not be — an error naming
288
- * the staged paths, since those directories hold the only remaining copy of that package.
289
- *
290
- * @complexity O(s) renames in the staged-tree count.
291
- */
292
- async function restoreStagedTrees(staged, cause) {
293
- const stranded = [];
294
- for (const tree of [...staged].reverse()) {
295
- try {
296
- await rename(tree.quarantined, tree.original);
297
- await chmod(tree.original, tree.originalMode).catch(() => undefined);
298
- }
299
- catch {
300
- stranded.push(tree.quarantined);
301
- }
302
- }
303
- if (stranded.length === 0)
304
- return cause;
305
- const reason = cause instanceof Error ? cause.message : String(cause);
306
- return new Error(`Agent Plugin uninstall failed (${reason}) and ${stranded.length} package tree(s) could not be put back. ` +
307
- `They still hold the package bytes and were left in place for recovery: ${stranded.join(", ")}`, { cause });
292
+ if (stranded.length === 0)
293
+ return cause;
294
+ const reason = cause instanceof Error ? cause.message : String(cause);
295
+ return new Error(`Agent Plugin uninstall failed (${reason}) and ${stranded.length} package tree(s) could not be put back. ` +
296
+ `They still hold the package bytes and were left in place for recovery: ${stranded.join(", ")}`, { cause });
297
+ }
298
+ /**
299
+ * Finds `pluginId`'s installed digests in this workspace and applies both refusals.
300
+ *
301
+ * @throws {AgentPluginNotFoundError} No match on disk.
302
+ * @throws {AgentPluginNotUninstallableError} The activation record says `origin: "bundled"`, or holds a malformed
303
+ * entry for this plugin.
304
+ * @throws {AgentPluginActivationsUnreadableError} The activation record exists but could not be
305
+ * read, so whether it says `origin: "bundled"` cannot be established.
306
+ * @complexity O(d) in the installed-digest count.
307
+ */
308
+ // The one call that turns (instance layout, workspaceId) into real, internally-consistent
309
+ // packages/root paths — see this file's header, "Why this module resolves its own workspace
310
+ // layout". `forWorkspace` itself still throws for a syntactically invalid `workspaceId`.
311
+ // The bundled read above answers `false` for a present-but-malformed entry (a non-object, a non-boolean
312
+ // `enabled`), which says nothing about provenance. The gate reads that entry as `undetermined` and denies; an
313
+ // uninstall does the same rather than remove what may be a bundled plugin the next boot re-seeds (t91 R4). A
314
+ // file that became unreadable between the two reads also lands here, and is refused the same way.
315
+ async function resolveUninstallTargets({ ports, required }, { retiredBundled = false } = {}) {
316
+ const { layout, workspaceId, pluginId } = required;
317
+ const workspaceLayout = layout.forWorkspace({ workspaceId });
318
+ const installed = await createResolveAgentPluginRefsModule(ports).listInstalledPlugins(workspaceLayout.root);
319
+ const matches = installed.filter((plugin) => plugin.pluginId === pluginId);
320
+ if (matches.length === 0) {
321
+ throw new AgentPluginNotFoundError({ message: `Agent Plugin '${pluginId}' is not installed in this workspace — nothing to uninstall` });
308
322
  }
309
- /**
310
- * Finds `pluginId`'s installed digests in this workspace and applies both refusals.
311
- *
312
- * @throws {AgentPluginNotFoundError} No match on disk.
313
- * @throws {AgentPluginNotUninstallableError} The activation record says `origin: "bundled"`, or holds a malformed
314
- * entry for this plugin.
315
- * @throws {AgentPluginActivationsUnreadableError} The activation record exists but could not be
316
- * read, so whether it says `origin: "bundled"` cannot be established.
317
- * @complexity O(d) in the installed-digest count.
318
- */
319
- // The one call that turns (instance layout, workspaceId) into real, internally-consistent
320
- // packages/root paths — see this file's header, "Why this module resolves its own workspace
321
- // layout". `forWorkspace` itself still throws for a syntactically invalid `workspaceId`.
322
- // The bundled read above answers `false` for a present-but-malformed entry (a non-object, a non-boolean
323
- // `enabled`), which says nothing about provenance. The gate reads that entry as `undetermined` and denies; an
324
- // uninstall does the same rather than remove what may be a bundled plugin the next boot re-seeds (t91 R4). A
325
- // file that became unreadable between the two reads also lands here, and is refused the same way.
326
- async function resolveUninstallTargets(required, retiredBundled = false) {
327
- const { layout, workspaceId, pluginId } = required;
328
- const workspaceLayout = layout.forWorkspace({ workspaceId });
329
- const installed = await listInstalledPlugins(workspaceLayout.root);
330
- const matches = installed.filter((plugin) => plugin.pluginId === pluginId);
331
- if (matches.length === 0) {
332
- throw new AgentPluginNotFoundError({ message: `Agent Plugin '${pluginId}' is not installed in this workspace — nothing to uninstall` });
333
- }
334
- if (!retiredBundled && (await isAgentPluginRecordedAsBundled(workspaceLayout.root, pluginId))) {
335
- throw new AgentPluginNotUninstallableError({ message: bundledRefusalMessage(pluginId) });
336
- }
337
- if ((await resolveAgentPluginActivation(workspaceLayout.root, pluginId)).verdict === "undetermined") {
338
- throw new AgentPluginNotUninstallableError({ message: malformedEntryRefusalMessage(pluginId) });
339
- }
340
- return { workspaceRoot: workspaceLayout.root, packagesDir: workspaceLayout.pluginPackagesDir({ pluginId }), matches };
323
+ if (!retiredBundled && (await createActivationModule(ports).isAgentPluginRecordedAsBundled(workspaceLayout.root, pluginId))) {
324
+ throw new AgentPluginNotUninstallableError({ message: bundledRefusalMessage({ ports, pluginId }) });
341
325
  }
342
- /** Names the levers that do work for a bundled plugin — see this file's header, item 2. */
343
- function bundledRefusalMessage(pluginId) {
344
- return (`Agent Plugin '${pluginId}' is bundled with ${ports.productName} and cannot be uninstalled — it is re-seeded on every boot ` +
345
- "(seed-bundled.ts), so removing its files now would silently reappear on the next restart. To stop it being " +
346
- (ports.formatBundledUninstallRecovery?.({ pluginId }, {}) ?? "used, disable it through the host's activation control."));
326
+ if ((await createActivationModule(ports).resolveAgentPluginActivation(workspaceLayout.root, pluginId)).verdict === "undetermined") {
327
+ throw new AgentPluginNotUninstallableError({ message: malformedEntryRefusalMessage({ ports, pluginId }) });
347
328
  }
348
- /** Path-free: says why provenance is unknown and what repairs it. Does not suggest toggling the plugin, which would
349
- * rewrite a garbled bundled entry as `operator-installed`. */
350
- function malformedEntryRefusalMessage(pluginId) {
351
- return (`Agent Plugin '${pluginId}' cannot be uninstalled: its entry in this workspace's activation record is malformed, so ` +
352
- `whether it is bundled with ${ports.productName} (and would be re-seeded on the next boot) cannot be established. Nothing was ` +
353
- "removed. Tell the user an operator has to repair that entry in activations.json first; until then this " +
354
- "plugin's tool calls and plugin-pinned runs are refused.");
329
+ return { workspaceRoot: workspaceLayout.root, packagesDir: workspaceLayout.pluginPackagesDir({ pluginId }), matches };
330
+ }
331
+ /** Names the levers that do work for a bundled plugin — see this file's header, item 2. */
332
+ function bundledRefusalMessage({ ports, pluginId }) {
333
+ return (`Agent Plugin '${pluginId}' is bundled with ${ports.productName} and cannot be uninstalled — it is re-seeded on every boot ` +
334
+ "(seed-bundled.ts), so removing its files now would silently reappear on the next restart. To stop it being " +
335
+ (ports.formatBundledUninstallRecovery?.({ pluginId }, {}) ?? "used, disable it through the host's activation control."));
336
+ }
337
+ /** Path-free: says why provenance is unknown and what repairs it. Does not suggest toggling the plugin, which would
338
+ * rewrite a garbled bundled entry as `operator-installed`. */
339
+ function malformedEntryRefusalMessage({ ports, pluginId }) {
340
+ return (`Agent Plugin '${pluginId}' cannot be uninstalled: its entry in this workspace's activation record is malformed, so ` +
341
+ `whether it is bundled with ${ports.productName} (and would be re-seeded on the next boot) cannot be established. Nothing was ` +
342
+ "removed. Tell the user an operator has to repair that entry in activations.json first; until then this " +
343
+ "plugin's tool calls and plugin-pinned runs are refused.");
344
+ }
345
+ /**
346
+ * Restores write permission through `root`'s whole tree, then removes it — the production
347
+ * counterpart of `__tests__/fixtures/force-remove.ts` (that file's own header explains why a plain
348
+ * recursive `ports.filesystem.rm` cannot work here: `install.ts`'s `freezeTree` leaves every directory `0o555`).
349
+ * Deliberately not shared code with that test fixture: the fixture is intentionally test-only and
350
+ * this is the first production need for the same operation, not a refactor opportunity forced by it.
351
+ *
352
+ * @complexity O(f) in the file/directory count under `root`.
353
+ */
354
+ async function removeFrozenPackageTree({ ports, root }) {
355
+ await makeTreeWritable({ ports, dir: root });
356
+ await ports.filesystem.rm(root, { recursive: true, force: true });
357
+ }
358
+ async function makeTreeWritable({ ports, dir }) {
359
+ let entries;
360
+ try {
361
+ entries = await ports.filesystem.readdir(dir, { withFileTypes: true });
355
362
  }
356
- /**
357
- * Restores write permission through `root`'s whole tree, then removes it — the production
358
- * counterpart of `__tests__/fixtures/force-remove.ts` (that file's own header explains why a plain
359
- * recursive `rm` cannot work here: `install.ts`'s `freezeTree` leaves every directory `0o555`).
360
- * Deliberately not shared code with that test fixture: the fixture is intentionally test-only and
361
- * this is the first production need for the same operation, not a refactor opportunity forced by it.
362
- *
363
- * @complexity O(f) in the file/directory count under `root`.
364
- */
365
- async function removeFrozenPackageTree(root) {
366
- await makeTreeWritable(root);
367
- await rm(root, { recursive: true, force: true });
363
+ catch {
364
+ return;
368
365
  }
369
- async function makeTreeWritable(dir) {
370
- let entries;
371
- try {
372
- entries = await readdir(dir, { withFileTypes: true });
373
- }
374
- catch {
375
- return;
366
+ await ports.filesystem.chmod(dir, 0o700).catch(() => undefined);
367
+ for (const entry of entries) {
368
+ // Dirents are lstat-typed: a link is removed by `ports.filesystem.rm`, never followed, since ports.filesystem.chmod through it
369
+ // would change the mode of whatever it points at, even outside the package.
370
+ if (entry.isSymbolicLink())
371
+ continue;
372
+ const absolute = path.join(dir, entry.name);
373
+ if (entry.isDirectory()) {
374
+ await makeTreeWritable({ ports, dir: absolute });
376
375
  }
377
- await chmod(dir, 0o700).catch(() => undefined);
378
- for (const entry of entries) {
379
- // Dirents are lstat-typed: a link is removed by `rm`, never followed, since chmod through it
380
- // would change the mode of whatever it points at, even outside the package.
381
- if (entry.isSymbolicLink())
382
- continue;
383
- const absolute = path.join(dir, entry.name);
384
- if (entry.isDirectory()) {
385
- await makeTreeWritable(absolute);
386
- }
387
- else {
388
- await chmod(absolute, 0o600).catch(() => undefined);
389
- }
376
+ else {
377
+ await ports.filesystem.chmod(absolute, 0o600).catch(() => undefined);
390
378
  }
391
379
  }
392
- return { previewAgentPluginUninstall, uninstallAgentPlugin, stageForRemoval, restoreStagedTrees, removeFrozenPackageTree };
380
+ }
381
+ function buildModule(ports) {
382
+ return {
383
+ previewAgentPluginUninstall: (required) => previewAgentPluginUninstall({ ports, required }),
384
+ uninstallAgentPlugin: (required, optional = {}) => uninstallAgentPlugin({ ports, required }, optional),
385
+ stageForRemoval: (packagesDir, packageRoot, optional = {}) => stageForRemoval({ ports, packagesDir, packageRoot }, optional),
386
+ restoreStagedTrees: (staged, cause) => restoreStagedTrees({ ports, staged, cause }),
387
+ removeFrozenPackageTree: (root) => removeFrozenPackageTree({ ports, root }),
388
+ };
393
389
  }
394
390
  const instances = new WeakMap();
395
391
  /** Internal composition; one state/queue instance per injected host context. */
396
- export function createUninstallModule(ports) {
392
+ export function createUninstallModule(ports, _optional = {}) {
397
393
  let instance = instances.get(ports);
398
394
  if (!instance) {
399
395
  instance = buildModule(ports);
@@ -1,5 +1,4 @@
1
1
  import path from 'node:path';
2
- import { writeJsonFileAtomicAsync } from '@jini-ai/platform/fs';
3
2
  import { createPersistentStateModule } from './persistent-state.js';
4
3
  export class AgentPluginUpdateError extends Error {
5
4
  code;
@@ -39,21 +38,7 @@ function parseJournal({ value, pluginId }, _optional = {}) {
39
38
  throw invalidJournal();
40
39
  return raw;
41
40
  }
42
- /** Durable per-plugin journal, audit history and frozen rollback area, all under the plugin's own
43
- * state root (never under `package/sha256`, so a rollback copy is never a live digest). Files use
44
- * the existing platform atomic writer. Settings snapshots are private (0600) and never returned to
45
- * tools or HTTP callers.
46
- * @complexity O(s) serialization of the host's settings slice.
47
- */
48
- export function createAgentPluginUpdateStore({ ports, workspaceId, pluginId }, _optional = {}) {
49
- const workspace = ports.layout.forWorkspace({ workspaceId });
50
- const root = workspace.pluginRootDir({ pluginId });
51
- const journalPath = path.join(root, 'update-journal.json');
52
- const rollbackDir = path.join(root, 'rollback');
53
- const persistent = createPersistentStateModule(ports);
54
- async function contain({ entryPath }, _optional = {}) {
55
- await persistent.assertOwnedPath({ workspaceRoot: workspace.root, entryPath: path.relative(workspace.root, entryPath) });
56
- }
41
+ function createUpdateJournalOperations({ ports, root, journalPath, pluginId }, contain) {
57
42
  async function read(_required, _optional = {}) {
58
43
  await contain({ entryPath: journalPath });
59
44
  let text;
@@ -77,7 +62,7 @@ export function createAgentPluginUpdateStore({ ports, workspaceId, pluginId }, _
77
62
  async function write({ journal, history = false }, _optional = {}) {
78
63
  const filePath = history ? path.join(root, 'update-history', `${journal.transactionId}.json`) : journalPath;
79
64
  await contain({ entryPath: filePath });
80
- await writeJsonFileAtomicAsync({ filePath, data: journal }, { fs: ports.filesystem,
65
+ await ports.atomicWriter.writeJson({ filePath, data: journal }, { fs: ports.filesystem,
81
66
  createParent: true, mode: 0o600, platform: ports.process.platform, tempName: () => ports.ids.newId() });
82
67
  }
83
68
  async function clear(_required, _optional = {}) {
@@ -90,6 +75,24 @@ export function createAgentPluginUpdateStore({ ports, workspaceId, pluginId }, _
90
75
  await write({ journal, history: true });
91
76
  await clear({});
92
77
  }
78
+ return { read, write, clear, finish };
79
+ }
80
+ /** Durable per-plugin journal, audit history and frozen rollback area, all under the plugin's own
81
+ * state root (never under `package/sha256`, so a rollback copy is never a live digest). Files use
82
+ * the existing platform atomic writer. Settings snapshots are private (0600) and never returned to
83
+ * tools or HTTP callers.
84
+ * @complexity O(s) serialization of the host's settings slice.
85
+ */
86
+ export function createAgentPluginUpdateStore({ ports, workspaceId, pluginId }, _optional = {}) {
87
+ const workspace = ports.layout.forWorkspace({ workspaceId });
88
+ const root = workspace.pluginRootDir({ pluginId });
89
+ const journalPath = path.join(root, 'update-journal.json');
90
+ const rollbackDir = path.join(root, 'rollback');
91
+ const persistent = createPersistentStateModule(ports);
92
+ async function contain({ entryPath }, _optional = {}) {
93
+ await persistent.assertOwnedPath({ workspaceRoot: workspace.root, entryPath: path.relative(workspace.root, entryPath) });
94
+ }
95
+ const { read, write, clear, finish } = createUpdateJournalOperations({ ports, root, journalPath, pluginId }, contain);
93
96
  async function prepare(_required, _optional = {}) {
94
97
  await contain({ entryPath: rollbackDir });
95
98
  await ports.filesystem.mkdir(rollbackDir, { recursive: true, mode: 0o700 });