@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.
- package/CHANGELOG.md +4 -4
- package/NOTICE +2 -0
- package/README.md +11 -15
- package/calendly/plugin.json +3 -3
- package/cloudflare/lib/forms.mjs +9 -10
- package/cloudflare/lib/target.mjs +1 -1
- package/cloudflare/plugin.json +3 -3
- package/cloudflare/worker/forms-receiver.mjs +9 -9
- package/composio/plugin.json +3 -3
- package/core/persistent-state.js +227 -163
- package/dist/admin-surfaces/connections/connections.d.ts +11 -6
- package/dist/admin-surfaces/connections/connections.js +102 -85
- package/dist/admin-surfaces/node.d.ts +27 -0
- package/dist/admin-surfaces/node.js +32 -0
- package/dist/admin-surfaces/plugin-state.js +21 -18
- package/dist/admin-surfaces/surface-client.d.ts +4 -0
- package/dist/admin-surfaces/surface-client.js +124 -117
- package/dist/admin-surfaces/surface-handlers.js +21 -17
- package/dist/admin-surfaces/theme.d.ts +5 -1
- package/dist/admin-surfaces/theme.js +3 -3
- package/dist/connect/access-token-tool.d.ts +3 -1
- package/dist/connect/access-token-tool.js +3 -2
- package/dist/connect/apply-connect-defaults.js +2 -2
- package/dist/connect/apply-tool-renames.js +9 -8
- package/dist/connect/connect-tool.d.ts +2 -0
- package/dist/connect/connect-tool.js +3 -2
- package/dist/connect/credential-cards.js +3 -2
- package/dist/connect/credential-save-tool.d.ts +14 -11
- package/dist/connect/credential-save-tool.js +128 -121
- package/dist/connect/enable-access.d.ts +2 -2
- package/dist/connect/enable-access.js +6 -6
- package/dist/connect/executable/register.js +40 -34
- package/dist/connect/federate-mcp.d.ts +21 -11
- package/dist/connect/federate-mcp.js +28 -21
- package/dist/connect/grant-signed-in-defaults.js +3 -3
- package/dist/connect/import-access-token.js +2 -1
- package/dist/connect/index.d.ts +1 -0
- package/dist/connect/index.js +1 -0
- package/dist/connect/plugin-credential-card.js +2 -1
- package/dist/connect/plugin-host/index.d.ts +10 -5
- package/dist/connect/plugin-host/index.js +113 -100
- package/dist/connect/ports.d.ts +1 -1
- package/dist/connect/row-update.d.ts +22 -0
- package/dist/connect/row-update.js +18 -0
- package/dist/connect/switch-on-saved-token.d.ts +4 -2
- package/dist/connect/switch-on-saved-token.js +1 -1
- package/dist/connect/token-map.d.ts +44 -0
- package/dist/connect/token-map.js +49 -0
- package/dist/core/identity-namespace.js +5 -0
- package/dist/folder-zip.d.ts +3 -1
- package/dist/folder-zip.js +2 -2
- package/dist/lifecycle/activation.d.ts +4 -4
- package/dist/lifecycle/activation.js +4 -5
- package/dist/lifecycle/automatic-use.js +236 -210
- package/dist/lifecycle/bundled-digests.d.ts +75 -12
- package/dist/lifecycle/bundled-digests.js +213 -212
- package/dist/lifecycle/bundled-source-archive.d.ts +1 -1
- package/dist/lifecycle/bundled-source-archive.js +263 -264
- package/dist/lifecycle/capability-projection.d.ts +1 -1
- package/dist/lifecycle/capability-projection.js +1 -1
- package/dist/lifecycle/credential-card-metadata.d.ts +1 -1
- package/dist/lifecycle/credential-card-metadata.js +27 -3
- package/dist/lifecycle/exports.js +9 -4
- package/dist/lifecycle/fetch-archive.d.ts +1 -1
- package/dist/lifecycle/fetch-archive.js +1 -1
- package/dist/lifecycle/host-tools/identity.js +3 -2
- package/dist/lifecycle/host-tools/ports.d.ts +2 -0
- package/dist/lifecycle/host-tools/search-tool.d.ts +4 -2
- package/dist/lifecycle/host-tools/search-tool.js +9 -8
- package/dist/lifecycle/host-tools/skill-tool.d.ts +18 -2
- package/dist/lifecycle/host-tools/skill-tool.js +16 -8
- package/dist/lifecycle/index.d.ts +118 -110
- package/dist/lifecycle/index.js +45 -12
- package/dist/lifecycle/install-errors.d.ts +1 -1
- package/dist/lifecycle/install-from-url.d.ts +1 -1
- package/dist/lifecycle/install-from-url.js +1 -1
- package/dist/lifecycle/install.d.ts +7 -2
- package/dist/lifecycle/install.js +414 -396
- package/dist/lifecycle/installed-package-index.js +45 -42
- package/dist/lifecycle/layout.d.ts +1 -1
- package/dist/lifecycle/layout.js +1 -1
- package/dist/lifecycle/mail/catalog.d.ts +8 -32
- package/dist/lifecycle/mail/catalog.js +25 -20
- package/dist/lifecycle/mail/contribution.d.ts +2 -2
- package/dist/lifecycle/mail/contribution.js +34 -34
- package/dist/lifecycle/mail/selection.js +6 -2
- package/dist/lifecycle/manifest.d.ts +3 -3
- package/dist/lifecycle/manifest.js +4 -4
- package/dist/lifecycle/mcp-provisioning.d.ts +3 -3
- package/dist/lifecycle/mcp-provisioning.js +3 -3
- package/dist/lifecycle/package-paths.d.ts +1 -1
- package/dist/lifecycle/package-paths.js +1 -1
- package/dist/lifecycle/persistent-state.js +1 -2
- package/dist/lifecycle/ports.d.ts +5 -1
- package/dist/lifecycle/resolve-agent-plugin-refs.d.ts +30 -8
- package/dist/lifecycle/resolve-agent-plugin-refs.js +227 -228
- package/dist/lifecycle/retire-bundled.d.ts +1 -52
- package/dist/lifecycle/retire-bundled.js +134 -84
- package/dist/lifecycle/search.d.ts +2 -1
- package/dist/lifecycle/search.js +1 -1
- package/dist/lifecycle/seed-bundled.d.ts +1 -1
- package/dist/lifecycle/seed-bundled.js +154 -155
- package/dist/lifecycle/set-enabled.d.ts +1 -1
- package/dist/lifecycle/set-enabled.js +1 -1
- package/dist/lifecycle/skill-file-reader.js +53 -50
- package/dist/lifecycle/tools/projection.d.ts +4 -7
- package/dist/lifecycle/tools/projection.js +109 -108
- package/dist/lifecycle/trusted-plugin-files.d.ts +2 -2
- package/dist/lifecycle/trusted-plugin-files.js +1 -1
- package/dist/lifecycle/uninstall.d.ts +1 -1
- package/dist/lifecycle/uninstall.js +237 -241
- package/dist/lifecycle/update-store.js +20 -17
- package/dist/lifecycle/update.js +287 -281
- package/dist/lifecycle/yauzl-archive-reader.d.ts +2 -2
- package/dist/lifecycle/yauzl-archive-reader.js +8 -2
- package/dist/manifest.d.ts +11 -3
- package/dist/manifest.js +9 -9
- package/fly/jini-credential-schemes.json +11 -0
- package/fly/plugin.json +3 -4
- package/github/plugin.json +3 -3
- package/github/source-control/backup-push.mjs +11 -11
- package/github/source-control/commit-site.mjs +23 -13
- package/github/source-control/github.mjs +12 -6
- package/github/source-control/write-files.mjs +27 -28
- package/github-pages/{tovu-deploy-targets.json → jini-deploy-targets.json} +22 -22
- package/github-pages/plugin.json +3 -3
- package/github-pages/targets/github-pages.mjs +3 -3
- package/google-login/plugin.json +3 -3
- package/google-workspace/README.md +14 -14
- package/google-workspace/form-destinations/README.md +3 -3
- package/google-workspace/form-destinations/dedupe.mjs +1 -1
- package/google-workspace/form-destinations/mapping.mjs +8 -9
- package/google-workspace/form-destinations/sheets.mjs +1 -1
- package/google-workspace/{tovu-admin-surfaces.json → jini-admin-surfaces.json} +2 -2
- package/google-workspace/{tovu-agent-tools.json → jini-agent-tools.json} +28 -28
- package/google-workspace/{tovu-connections.json → jini-connections.json} +2 -2
- package/google-workspace/lib/auth.mjs +2 -2
- package/google-workspace/lib/form-destination-settings.mjs +1 -1
- package/google-workspace/lib/picker-flow.mjs +2 -2
- package/google-workspace/lib/request-policy.mjs +1 -1
- package/google-workspace/lib/surface-actions.mjs +1 -1
- package/google-workspace/plugin.json +3 -3
- package/google-workspace/tools/sheets/README.md +3 -3
- package/google-workspace/tools/sheets-admin/README.md +3 -3
- package/google-workspace/ui/README.md +4 -4
- package/google-workspace/ui/connection-panel.mjs +51 -51
- package/google-workspace/ui/destination-panel.mjs +34 -34
- package/google-workspace/ui/dom.mjs +15 -16
- package/google-workspace/ui/picker-flow.mjs +2 -2
- package/google-workspace/ui/picker.mjs +19 -19
- package/google-workspace/ui/surface-client.mjs +96 -69
- package/higgsfield-media/plugin.json +3 -3
- package/jev/plugin.json +3 -3
- package/kuinetic/CHANGELOG.md +12 -0
- package/kuinetic/mcp.json +4 -0
- package/kuinetic/plugin.json +27 -0
- package/kuinetic/skills/kuinetic/SKILL.md +120 -0
- package/kuinetic/skills/kuinetic/references/effects-by-family.md +32 -0
- package/kuinetic/skills/kuinetic/references/opt-in-tiers.md +12 -0
- package/kuinetic/skills/kuinetic/references/reserved-keys.md +36 -0
- package/meilisearch/plugin.json +5 -5
- package/netlify/plugin.json +3 -3
- package/netlify/targets/netlify.mjs +14 -4
- package/opentelemetry/plugin.json +3 -3
- package/package.json +27 -22
- package/posthog/plugin.json +3 -3
- package/railway/plugin.json +3 -3
- package/render/plugin.json +3 -3
- package/resend/NOTES.md +2 -2
- package/resend/adapters/resend.mjs +1 -1
- package/resend/{tovu-mail-adapters.json → jini-mail-adapters.json} +1 -1
- package/resend/lib/domains.mjs +8 -8
- package/resend/plugin.json +3 -3
- package/s3-compatible/{tovu-deploy-targets.json → jini-deploy-targets.json} +68 -68
- package/s3-compatible/jini-object-stores.json +29 -0
- package/s3-compatible/object-stores/s3-compatible.mjs +19 -13
- package/s3-compatible/plugin.json +3 -3
- package/s3-compatible/targets/s3-compatible.mjs +25 -25
- package/sentry/plugin.json +3 -3
- package/shadcn-ui/CHANGELOG.md +7 -0
- package/shadcn-ui/LICENSE +201 -0
- package/shadcn-ui/NOTICE +10 -0
- package/shadcn-ui/mcp.json +4 -0
- package/shadcn-ui/plugin.json +26 -0
- package/shopify/plugin.json +3 -3
- package/site-compliance/plugin.json +3 -3
- package/site-import/plugin.json +3 -3
- package/supabase/mcp.json +1 -4
- package/supabase/plugin.json +3 -3
- package/ui-ux-design/CHANGELOG.md +13 -0
- package/ui-ux-design/NOTICE +2 -0
- package/ui-ux-design/README.md +17 -7
- package/ui-ux-design/plugin.json +6 -3
- package/ui-ux-design/skills/ui-ux-design/SKILL.md +38 -152
- package/ui-ux-design/skills/ui-ux-design/references/full-workflow.md +156 -0
- package/ui-ux-design/skills/ui-ux-design/references/ui-animation.md +4 -4
- package/vercel/NOTES.md +1 -1
- package/vercel/object-stores/vercel-blob.mjs +12 -2
- package/vercel/plugin.json +3 -3
- package/vercel/targets/vercel.mjs +3 -3
- package/wordpress/plugin.json +3 -3
- package/dist/lifecycle/node.d.ts +0 -11
- package/dist/lifecycle/node.js +0 -38
- package/fly/tovu-credential-schemes.json +0 -11
- package/github/deployments/github.mjs +0 -415
- package/s3-compatible/tovu-object-stores.json +0 -29
- package/ui-ux-design/skills/ui-ux-design/references/kuinetic-reference.md +0 -184
- /package/cloudflare/{tovu-consent.json → jini-consent.json} +0 -0
- /package/cloudflare/{tovu-deploy-targets.json → jini-deploy-targets.json} +0 -0
- /package/cloudflare/{tovu-form-destinations.json → jini-form-destinations.json} +0 -0
- /package/fly/{tovu-deploy-configs.json → jini-deploy-configs.json} +0 -0
- /package/fly/{tovu-deploy-ops.json → jini-deploy-ops.json} +0 -0
- /package/github/{tovu-deploy-ops.json → jini-deploy-ops.json} +0 -0
- /package/github/{tovu-source-control.json → jini-source-control.json} +0 -0
- /package/google-login/{tovu-login-providers.json → jini-login-providers.json} +0 -0
- /package/google-workspace/{tovu-form-destinations.json → jini-form-destinations.json} +0 -0
- /package/meilisearch/{tovu-search-providers.json → jini-search-providers.json} +0 -0
- /package/netlify/{tovu-consent.json → jini-consent.json} +0 -0
- /package/netlify/{tovu-deploy-targets.json → jini-deploy-targets.json} +0 -0
- /package/railway/{tovu-deploy-configs.json → jini-deploy-configs.json} +0 -0
- /package/railway/{tovu-deploy-ops.json → jini-deploy-ops.json} +0 -0
- /package/render/{tovu-deploy-configs.json → jini-deploy-configs.json} +0 -0
- /package/render/{tovu-deploy-ops.json → jini-deploy-ops.json} +0 -0
- /package/{ui-ux-design → shadcn-ui}/skills/shadcn-ui/README.md +0 -0
- /package/{ui-ux-design → shadcn-ui}/skills/shadcn-ui/SKILL.md +0 -0
- /package/{ui-ux-design → shadcn-ui}/skills/shadcn-ui/examples/auth-layout.tsx +0 -0
- /package/{ui-ux-design → shadcn-ui}/skills/shadcn-ui/examples/data-table.tsx +0 -0
- /package/{ui-ux-design → shadcn-ui}/skills/shadcn-ui/examples/form-pattern.tsx +0 -0
- /package/{ui-ux-design → shadcn-ui}/skills/shadcn-ui/resources/component-catalog.md +0 -0
- /package/{ui-ux-design → shadcn-ui}/skills/shadcn-ui/resources/customization-guide.md +0 -0
- /package/{ui-ux-design → shadcn-ui}/skills/shadcn-ui/resources/migration-guide.md +0 -0
- /package/{ui-ux-design → shadcn-ui}/skills/shadcn-ui/resources/setup-guide.md +0 -0
- /package/{ui-ux-design → shadcn-ui}/skills/shadcn-ui/scripts/verify-setup.sh +0 -0
- /package/vercel/{tovu-consent.json → jini-consent.json} +0 -0
- /package/vercel/{tovu-deploy-targets.json → jini-deploy-targets.json} +0 -0
- /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
|
-
* `
|
|
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
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
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
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
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
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
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
|
|
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
|
-
|
|
200
|
-
|
|
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
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
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
|
-
|
|
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
|
-
|
|
216
|
+
if (!isAncestorStillInUse(error))
|
|
217
|
+
throw error;
|
|
217
218
|
}
|
|
218
|
-
return staged;
|
|
219
219
|
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
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
|
-
|
|
246
|
-
|
|
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
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
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(
|
|
285
|
+
await ports.filesystem.rename(tree.quarantined, tree.original);
|
|
286
|
+
await ports.filesystem.chmod(tree.original, tree.originalMode).catch(() => undefined);
|
|
278
287
|
}
|
|
279
|
-
catch
|
|
280
|
-
|
|
281
|
-
throw error;
|
|
288
|
+
catch {
|
|
289
|
+
stranded.push(tree.quarantined);
|
|
282
290
|
}
|
|
283
|
-
return { quarantined, original: packageRoot, originalMode };
|
|
284
291
|
}
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
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
|
-
|
|
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
|
-
|
|
343
|
-
|
|
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
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
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
|
-
|
|
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
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
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
|
-
|
|
378
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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 });
|