@jini-ai/agent-plugins 0.7.2 → 0.7.3-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -6
- 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 +9 -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.js +8 -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 +3 -3
- 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 +25 -20
- 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
|
@@ -26,7 +26,7 @@ import { readPluginIdentity, assertPluginIdentityAvailable } from "@jini-ai/core
|
|
|
26
26
|
* bounding bytes actually observed leaving `openReadStream()`, not the archive's own declared
|
|
27
27
|
* size) and the "many small files" shape (caught by a running total across the whole archive).
|
|
28
28
|
*
|
|
29
|
-
* Why this is a SEPARATE format from the host runtime-plugin format's loader (`
|
|
29
|
+
* Why this is a SEPARATE format from the host runtime-plugin format's loader (`packages/plugins/src/host/node/loader.ts`), not a
|
|
30
30
|
* shared one: verified against that file directly. `loadPlugin()`'s BR-01 pipeline requires
|
|
31
31
|
* `manifest.integrity` (a per-file SHA-256 map), `manifest.sdkRange` checked against a runtime
|
|
32
32
|
* the host plugin SDK version, and a `server/index.mjs` ESM entry point it `import()`s. An Agent Plugin has
|
|
@@ -38,7 +38,7 @@ import { readPluginIdentity, assertPluginIdentityAvailable } from "@jini-ai/core
|
|
|
38
38
|
* feature's own owner-locked decisions (see `CTX-AGENTPLUGINS-2026-08-12.md` F2) rule out.
|
|
39
39
|
*
|
|
40
40
|
* Why the archive itself is a `ArchiveReaderPort`, not a concrete zip/tar library call: this
|
|
41
|
-
* codebase's own port+adapter discipline (`mcp
|
|
41
|
+
* codebase's own port+adapter discipline (`packages/mcp/src/federation/ports.ts`'s `McpSessionPort`/
|
|
42
42
|
* `McpStdioChannel` split is the direct precedent) — and, concretely, no zip/tar dependency exists
|
|
43
43
|
* in this repo's `package.json` today. Choosing and vetting one (license, maintenance, streaming
|
|
44
44
|
* support) is a real decision outside a Programmer's scope to make silently; this module declares
|
|
@@ -72,440 +72,458 @@ import path from "node:path";
|
|
|
72
72
|
import { PackagePathViolation } from "./package-paths.js";
|
|
73
73
|
import { createPackagePathsModule } from "./package-paths.js";
|
|
74
74
|
export { AgentPluginInstallError } from "./install-errors.js";
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
75
|
+
const LIMITS = {
|
|
76
|
+
maxArchiveBytes: 32 * 1024 * 1024,
|
|
77
|
+
maxEntries: 4096,
|
|
78
|
+
maxFileBytes: 16 * 1024 * 1024,
|
|
79
|
+
maxTotalExtractedBytes: 64 * 1024 * 1024,
|
|
80
|
+
};
|
|
81
|
+
const SHA256_HEX_PATTERN = /^[a-f0-9]{64}$/;
|
|
82
|
+
/** Publisher ids are metadata, never filesystem segments. The workspace identity lock
|
|
83
|
+
* serializes installs under different local names competing for one qualified id.
|
|
84
|
+
* @complexity O(d) manifest reads for d installed revisions; no executable imports. */
|
|
85
|
+
async function assertIdentityAvailable({ ports, workspaceRoot, candidate }) {
|
|
86
|
+
// Installed roots are canonical paths; compare against the same root even when the host
|
|
87
|
+
// supplied an OS alias (macOS /var -> /private/var). Containment still rejects escaped links.
|
|
88
|
+
workspaceRoot = await ports.filesystem.realpath(workspaceRoot);
|
|
89
|
+
for (const root of await listInstalledPackageRoots({ ports, workspaceRoot })) {
|
|
90
|
+
const manifestPath = path.join(root.packageRoot, 'plugin.json');
|
|
91
|
+
await createPersistentStateModule(ports).assertOwnedPath({ workspaceRoot, entryPath: path.relative(workspaceRoot, manifestPath) });
|
|
92
|
+
let raw;
|
|
93
|
+
let identity;
|
|
94
|
+
try {
|
|
95
|
+
raw = JSON.parse(await ports.filesystem.readFile(manifestPath, 'utf8'));
|
|
96
|
+
identity = readPluginIdentity({ manifest: raw, name: root.localId, namespace: resolveAgentPluginLifecycleNamespace({ value: raw, extensionNamespace: ports.extensionNamespace }) });
|
|
97
|
+
}
|
|
98
|
+
catch {
|
|
99
|
+
// A damaged unrelated install must not block fresh installs or bundled seeding.
|
|
100
|
+
ports.onEvent?.({ event: 'agent-plugin-identity-warning', message: `Plugin '${root.localId}': installed identity manifest is unreadable or invalid; omitted from identity admission.` });
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
try {
|
|
104
|
+
assertPluginIdentityAvailable({ candidate: { id: candidate.id, localId: candidate.pluginId, family: 'agent-plugin' },
|
|
105
|
+
installed: [{ ...identity, localId: root.localId, family: 'agent-plugin', version: typeof raw.version === 'string' ? raw.version : null, enabled: false }] });
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
throw new AgentPluginInstallError({ code: 'PLUGIN_ID_CONFLICT', message: 'The publisher-qualified plugin id conflicts with an installed package.' });
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/** Retires only this plugin's superseded revisions after accepted publication, under the same
|
|
113
|
+
* identity/plugin locks. Persistent data, learned facts and notes never enter this operation.
|
|
114
|
+
* Reuse uninstall's frozen-tree staging so an interrupted removal is no longer a live digest.
|
|
115
|
+
* There is no previous-revision rollback slot in this lifecycle; failed publication keeps all
|
|
116
|
+
* prior bytes. Cleanup faults warn without turning an accepted install into a failed install.
|
|
117
|
+
* @complexity O(d + f), d workspace revisions, f files in this plugin's superseded packages.
|
|
118
|
+
*/
|
|
119
|
+
async function pruneSupersededRevisions({ ports, workspaceRoot, installed }) {
|
|
120
|
+
try {
|
|
121
|
+
const removal = createUninstallModule(ports);
|
|
102
122
|
for (const root of await listInstalledPackageRoots({ ports, workspaceRoot })) {
|
|
103
|
-
|
|
104
|
-
await persistentState.assertOwnedPath({ workspaceRoot, entryPath: path.relative(workspaceRoot, manifestPath) });
|
|
105
|
-
let raw;
|
|
106
|
-
let identity;
|
|
107
|
-
try {
|
|
108
|
-
raw = JSON.parse(await readFile(manifestPath, 'utf8'));
|
|
109
|
-
identity = readPluginIdentity({ manifest: raw, name: root.localId, namespace: resolveAgentPluginLifecycleNamespace({ value: raw, extensionNamespace: ports.extensionNamespace }) });
|
|
110
|
-
}
|
|
111
|
-
catch {
|
|
112
|
-
// A damaged unrelated install must not block fresh installs or bundled seeding.
|
|
113
|
-
ports.onEvent?.({ event: 'agent-plugin-identity-warning', message: `Plugin '${root.localId}': installed identity manifest is unreadable or invalid; omitted from identity admission.` });
|
|
123
|
+
if (root.localId !== installed.pluginId || root.archiveDigest === installed.archiveDigest)
|
|
114
124
|
continue;
|
|
115
|
-
}
|
|
116
125
|
try {
|
|
117
|
-
|
|
118
|
-
|
|
126
|
+
const staged = await removal.stageForRemoval(path.dirname(root.packageRoot), root.packageRoot);
|
|
127
|
+
await removal.removeFrozenPackageTree(staged.quarantined);
|
|
119
128
|
}
|
|
120
129
|
catch {
|
|
121
|
-
|
|
130
|
+
ports.onEvent?.({ event: 'agent-plugin-revision-prune-warning', message: `Plugin '${installed.pluginId}': a superseded revision could not be pruned.` });
|
|
122
131
|
}
|
|
123
132
|
}
|
|
124
133
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
* Reuse uninstall's frozen-tree staging so an interrupted removal is no longer a live digest.
|
|
128
|
-
* There is no previous-revision rollback slot in this lifecycle; failed publication keeps all
|
|
129
|
-
* prior bytes. Cleanup faults warn without turning an accepted install into a failed install.
|
|
130
|
-
* @complexity O(d + f), d workspace revisions, f files in this plugin's superseded packages.
|
|
131
|
-
*/
|
|
132
|
-
async function pruneSupersededRevisions({ workspaceRoot, installed }, _optional = {}) {
|
|
133
|
-
try {
|
|
134
|
-
const removal = createUninstallModule(ports);
|
|
135
|
-
for (const root of await listInstalledPackageRoots({ ports, workspaceRoot })) {
|
|
136
|
-
if (root.localId !== installed.pluginId || root.archiveDigest === installed.archiveDigest)
|
|
137
|
-
continue;
|
|
138
|
-
try {
|
|
139
|
-
const staged = await removal.stageForRemoval(path.dirname(root.packageRoot), root.packageRoot);
|
|
140
|
-
await removal.removeFrozenPackageTree(staged.quarantined);
|
|
141
|
-
}
|
|
142
|
-
catch {
|
|
143
|
-
ports.onEvent?.({ event: 'agent-plugin-revision-prune-warning', message: `Plugin '${installed.pluginId}': a superseded revision could not be pruned.` });
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
catch {
|
|
148
|
-
ports.onEvent?.({ event: 'agent-plugin-revision-prune-warning', message: `Plugin '${installed.pluginId}': superseded revisions could not be scanned for pruning.` });
|
|
149
|
-
}
|
|
134
|
+
catch {
|
|
135
|
+
ports.onEvent?.({ event: 'agent-plugin-revision-prune-warning', message: `Plugin '${installed.pluginId}': superseded revisions could not be scanned for pruning.` });
|
|
150
136
|
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
137
|
+
}
|
|
138
|
+
/** Exposes `LIMITS.maxArchiveBytes` for a caller outside this module — concretely, a test asserting
|
|
139
|
+
* `@jini-ai/agent-plugins/lifecycle`'s fetch cap constant stays pinned to this one. The local fetch-archive.ts fork was deleted; see the package's fetch module
|
|
140
|
+
* for why it duplicates the number instead of importing it (no runtime dependency on `install.ts`);
|
|
141
|
+
* this accessor is what lets a test assert the pairing without either module importing the other. */
|
|
142
|
+
function maxAgentPluginInstallArchiveBytes() {
|
|
143
|
+
return LIMITS.maxArchiveBytes;
|
|
144
|
+
}
|
|
145
|
+
/** Size and digest gates on the archive bytes before anything touches disk; returns the verified digest. */
|
|
146
|
+
function verifyArchiveBytes({ archive, expectedSha256 }) {
|
|
147
|
+
if (archive.byteLength > LIMITS.maxArchiveBytes) {
|
|
148
|
+
throw new AgentPluginInstallError({ code: "ARCHIVE_TOO_LARGE", message: `archive is ${archive.byteLength} bytes, over the ${LIMITS.maxArchiveBytes}-byte cap` });
|
|
157
149
|
}
|
|
158
|
-
const
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
*
|
|
162
|
-
* @throws {AgentPluginInstallError} For every expected failure — a hostile or malformed archive, a
|
|
163
|
-
* digest mismatch, an invalid manifest. Never partially publishes: any failure after extraction has
|
|
164
|
-
* begun removes the whole staging directory before rethrowing.
|
|
165
|
-
* @complexity O(e) in archive entry count, O(b) in total extracted bytes — both explicitly bounded
|
|
166
|
-
* by {@link LIMITS}, so this function's cost cannot be driven unbounded by a hostile archive.
|
|
167
|
-
*/
|
|
168
|
-
// The ONE call that turns (instance layout, workspaceId) into real, internally-consistent
|
|
169
|
-
// packages/staging/pluginDataDir paths — see the SECURITY note on `InstallAgentPluginRequired.layout`
|
|
170
|
-
// above for why this replaces accepting an already-resolved `AgentPluginWorkspaceLayout` directly.
|
|
171
|
-
// `forWorkspace` itself still throws for a syntactically invalid `workspaceId`, unchanged.
|
|
172
|
-
// Whether this install succeeded (bytes now live at `finalRoot`) or failed, the staging
|
|
173
|
-
// transaction directory itself must never be left behind — on success `rename` already moved
|
|
174
|
-
// `extractionRoot` out of it, so this only ever removes the (now-empty, or failure-abandoned)
|
|
175
|
-
// temp directory, never the published package.
|
|
176
|
-
async function installAgentPlugin(required, optional = {}) {
|
|
177
|
-
const { archive, expectedSha256, archiveReader, layout, workspaceId } = required;
|
|
178
|
-
const workspaceLayout = layout.forWorkspace({ workspaceId });
|
|
179
|
-
if (archive.byteLength > LIMITS.maxArchiveBytes) {
|
|
180
|
-
throw new AgentPluginInstallError({ code: "ARCHIVE_TOO_LARGE", message: `archive is ${archive.byteLength} bytes, over the ${LIMITS.maxArchiveBytes}-byte cap` });
|
|
181
|
-
}
|
|
182
|
-
const digest = sha256(archive);
|
|
183
|
-
if (!SHA256_HEX_PATTERN.test(expectedSha256) || digest !== expectedSha256.toLowerCase()) {
|
|
184
|
-
throw new AgentPluginInstallError({ code: "DIGEST_MISMATCH", message: `archive SHA-256 '${digest}' does not match the expected '${expectedSha256}' — refusing to extract unverified bytes` });
|
|
185
|
-
}
|
|
186
|
-
await mkdir(workspaceLayout.root, { recursive: true, mode: 0o700 });
|
|
187
|
-
await persistentState.assertOwnedPath({ workspaceRoot: workspaceLayout.root, entryPath: "staging" });
|
|
188
|
-
await mkdir(workspaceLayout.staging, { recursive: true, mode: 0o700 });
|
|
189
|
-
await assertEntryCountWithinCap(archiveReader.entries({ archive }));
|
|
190
|
-
const transactionRoot = await mkdtemp(path.join(workspaceLayout.staging, "install-"));
|
|
191
|
-
const extractionRoot = path.join(transactionRoot, "root");
|
|
192
|
-
await mkdir(extractionRoot, { mode: 0o700 });
|
|
193
|
-
try {
|
|
194
|
-
const executablePaths = await extractEntries(archiveReader.entries({ archive }), extractionRoot);
|
|
195
|
-
const indexed = await indexInstalledRoot(extractionRoot, digest);
|
|
196
|
-
if (optional.previewOnly)
|
|
197
|
-
return indexed;
|
|
198
|
-
// Layout B needs the manifest id before choosing the package destination. Dedup still
|
|
199
|
-
// skips publication and freezing, after one bounded staging extraction.
|
|
200
|
-
// Owner decision 2026-10-04: learned facts begin empty for each site; author guidance stays
|
|
201
|
-
// in package docs. Package extension files never seed learned memory or the user's notes.
|
|
202
|
-
// Content-addressed dedup, scoped to THIS workspace's own tree (`workspaceLayout` was just
|
|
203
|
-
// resolved above, atomically, from this same `workspaceId`): identical bytes were already
|
|
204
|
-
// extracted, verified, and frozen by a prior install of this same workspace's — never
|
|
205
|
-
// re-extracted for a different workspace, by construction, since a different workspace's
|
|
206
|
-
// `workspaceLayout.packages` is a different path entirely. one bounded staging extraction precedes this check.
|
|
207
|
-
// Publish BEFORE freezing permissions, not after: `rename()` moves `extractionRoot` as a single
|
|
208
|
-
// directory-entry operation, and on this filesystem renaming an already-read-only (0o555)
|
|
209
|
-
// directory itself fails EACCES (observed, not merely theoretical — see the regression test this
|
|
210
|
-
// ordering fixed). Freezing after publish also closes a smaller race for free: nothing outside
|
|
211
|
-
// this function can observe the package at its live path while it is still writable, because the
|
|
212
|
-
// live path does not exist until `publish` returns.
|
|
213
|
-
let publishedPlugin;
|
|
214
|
-
const publishPackage = async () => {
|
|
215
|
-
// The manifest identifies the plugin only after bounded staging extraction (Layout B).
|
|
216
|
-
const pluginId = indexed.pluginId;
|
|
217
|
-
const packagesDir = workspaceLayout.pluginPackagesDir({ pluginId });
|
|
218
|
-
await persistentState.assertOwnedPath({ workspaceRoot: workspaceLayout.root, entryPath: path.relative(workspaceLayout.root, packagesDir) });
|
|
219
|
-
await mkdir(packagesDir, { recursive: true, mode: 0o700 });
|
|
220
|
-
const finalRoot = await assertContainedOnDisk(packagesDir, digest);
|
|
221
|
-
for (const directory of [workspaceLayout.pluginDataDir({ pluginId }),
|
|
222
|
-
workspaceLayout.pluginMemoryDir({ pluginId, kind: 'learned' }),
|
|
223
|
-
workspaceLayout.pluginMemoryDir({ pluginId, kind: 'notes' })]) {
|
|
224
|
-
await persistentState.assertOwnedPath({ workspaceRoot: workspaceLayout.root, entryPath: path.relative(workspaceLayout.root, directory) });
|
|
225
|
-
await mkdir(directory, { recursive: true, mode: 0o700 });
|
|
226
|
-
}
|
|
227
|
-
if (await reuseOrSetAsideExisting({ packagesDir, finalRoot, extractionRoot, pluginId })) {
|
|
228
|
-
publishedPlugin = await indexInstalledRoot(finalRoot, digest);
|
|
229
|
-
return publishedPlugin;
|
|
230
|
-
}
|
|
231
|
-
await publish(extractionRoot, finalRoot);
|
|
232
|
-
await freezeTree(finalRoot, executablePaths);
|
|
233
|
-
/** Absolute, read-only (frozen) path to the extracted package root. */
|
|
234
|
-
publishedPlugin = { ...indexed, packageRoot: finalRoot };
|
|
235
|
-
return publishedPlugin;
|
|
236
|
-
};
|
|
237
|
-
const publishWithinPluginLock = () => persistentState.withPluginLock({ workspaceRoot: workspaceLayout.root, pluginId: indexed.pluginId, run: async () => {
|
|
238
|
-
// Every install and replacement, not only an update, is a mutation of this plugin: an
|
|
239
|
-
// unfinished update journal refuses it here, under the same plugin lock, because boot
|
|
240
|
-
// recovery removes only the journal's own candidate digest and would otherwise restore the
|
|
241
|
-
// old revision beside whatever this install published.
|
|
242
|
-
// The journal lives under the layout this install was given, the one it publishes into.
|
|
243
|
-
await settleAgentPluginUpdateJournal({ store: createAgentPluginUpdateStore({ ports: { ...ports, layout }, workspaceId, pluginId: indexed.pluginId }) });
|
|
244
|
-
const installed = await (optional.publishGuard ? optional.publishGuard({ plugin: indexed, publish: publishPackage }, {}) : publishPackage());
|
|
245
|
-
if (publishedPlugin && optional.pruneSupersededRevisions !== false)
|
|
246
|
-
await pruneSupersededRevisions({ workspaceRoot: workspaceLayout.root, installed: publishedPlugin });
|
|
247
|
-
return installed;
|
|
248
|
-
} });
|
|
249
|
-
return await persistentState.withIdentityLock({ workspaceRoot: workspaceLayout.root, run: async () => {
|
|
250
|
-
await assertIdentityAvailable(workspaceLayout.root, indexed);
|
|
251
|
-
if (ports.identityAdmission)
|
|
252
|
-
return ports.identityAdmission({ id: indexed.id, localId: indexed.pluginId, run: publishWithinPluginLock }, {});
|
|
253
|
-
return publishWithinPluginLock();
|
|
254
|
-
} });
|
|
255
|
-
}
|
|
256
|
-
finally {
|
|
257
|
-
await rm(transactionRoot, { recursive: true, force: true });
|
|
258
|
-
}
|
|
150
|
+
const digest = sha256(archive);
|
|
151
|
+
if (!SHA256_HEX_PATTERN.test(expectedSha256) || digest !== expectedSha256.toLowerCase()) {
|
|
152
|
+
throw new AgentPluginInstallError({ code: "DIGEST_MISMATCH", message: `archive SHA-256 '${digest}' does not match the expected '${expectedSha256}' — refusing to extract unverified bytes` });
|
|
259
153
|
}
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
154
|
+
return digest;
|
|
155
|
+
}
|
|
156
|
+
/** Creates the workspace root and its owned staging directory. */
|
|
157
|
+
async function ensureStagingArea(ports, workspaceLayout) {
|
|
158
|
+
await ports.filesystem.mkdir(workspaceLayout.root, { recursive: true, mode: 0o700 });
|
|
159
|
+
await createPersistentStateModule(ports).assertOwnedPath({ workspaceRoot: workspaceLayout.root, entryPath: "staging" });
|
|
160
|
+
await ports.filesystem.mkdir(workspaceLayout.staging, { recursive: true, mode: 0o700 });
|
|
161
|
+
}
|
|
162
|
+
/** Publishes the extracted package at its digest path (creating its owned dirs), reusing identical existing bytes. */
|
|
163
|
+
async function publishPackage(scope) {
|
|
164
|
+
const { ports, workspaceLayout, digest, indexed, extractionRoot, executablePaths } = scope;
|
|
165
|
+
// Layout B needs the manifest id before choosing the package destination. Dedup still
|
|
166
|
+
// skips publication and freezing, after one bounded staging extraction.
|
|
167
|
+
// Owner decision 2026-10-04: learned facts begin empty for each site; author guidance stays
|
|
168
|
+
// in package docs. Package extension files never seed learned memory or the user's notes.
|
|
169
|
+
// Content-addressed dedup, scoped to THIS workspace's own tree (`workspaceLayout` was just
|
|
170
|
+
// resolved above, atomically, from this same `workspaceId`): identical bytes were already
|
|
171
|
+
// extracted, verified, and frozen by a prior install of this same workspace's — never
|
|
172
|
+
// re-extracted for a different workspace, by construction, since a different workspace's
|
|
173
|
+
// `workspaceLayout.packages` is a different path entirely. one bounded staging extraction precedes this check.
|
|
174
|
+
// Publish BEFORE freezing permissions, not after: `ports.filesystem.rename()` moves `extractionRoot` as a single
|
|
175
|
+
// directory-entry operation, and on this filesystem renaming an already-read-only (0o555)
|
|
176
|
+
// directory itself fails EACCES (observed, not merely theoretical — see the regression test this
|
|
177
|
+
// ordering fixed). Freezing after publish also closes a smaller race for free: nothing outside
|
|
178
|
+
// this function can observe the package at its live path while it is still writable, because the
|
|
179
|
+
// live path does not exist until `publish` returns.
|
|
180
|
+
// The manifest identifies the plugin only after bounded staging extraction (Layout B).
|
|
181
|
+
const pluginId = indexed.pluginId;
|
|
182
|
+
const packagesDir = workspaceLayout.pluginPackagesDir({ pluginId });
|
|
183
|
+
await createPersistentStateModule(ports).assertOwnedPath({ workspaceRoot: workspaceLayout.root, entryPath: path.relative(workspaceLayout.root, packagesDir) });
|
|
184
|
+
await ports.filesystem.mkdir(packagesDir, { recursive: true, mode: 0o700 });
|
|
185
|
+
const finalRoot = await createPackagePathsModule(ports).assertContainedOnDisk(packagesDir, digest);
|
|
186
|
+
await ensurePluginOwnedDirs({ ports, workspaceLayout, pluginId });
|
|
187
|
+
if (await reuseOrSetAsideExisting(ports, { packagesDir, finalRoot, extractionRoot, pluginId })) {
|
|
188
|
+
scope.published = await indexInstalledRoot({ ports, packageRoot: finalRoot, archiveDigest: digest });
|
|
189
|
+
return scope.published;
|
|
279
190
|
}
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
}
|
|
294
|
-
return true;
|
|
191
|
+
await publish({ ports, extractionRoot, finalRoot });
|
|
192
|
+
await freezeTree({ ports, root: finalRoot, executables: executablePaths });
|
|
193
|
+
/** Absolute, read-only (frozen) path to the extracted package root. */
|
|
194
|
+
scope.published = { ...indexed, packageRoot: finalRoot };
|
|
195
|
+
return scope.published;
|
|
196
|
+
}
|
|
197
|
+
/** Creates (owned, 0700) the plugin's data and learned/notes memory directories. */
|
|
198
|
+
async function ensurePluginOwnedDirs({ ports, workspaceLayout, pluginId }) {
|
|
199
|
+
for (const directory of [workspaceLayout.pluginDataDir({ pluginId }),
|
|
200
|
+
workspaceLayout.pluginMemoryDir({ pluginId, kind: 'learned' }),
|
|
201
|
+
workspaceLayout.pluginMemoryDir({ pluginId, kind: 'notes' })]) {
|
|
202
|
+
await createPersistentStateModule(ports).assertOwnedPath({ workspaceRoot: workspaceLayout.root, entryPath: path.relative(workspaceLayout.root, directory) });
|
|
203
|
+
await ports.filesystem.mkdir(directory, { recursive: true, mode: 0o700 });
|
|
295
204
|
}
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
205
|
+
}
|
|
206
|
+
/** Publish under the plugin lock, then prune superseded revisions of the plugin just published. */
|
|
207
|
+
function publishWithinPluginLock(scope) {
|
|
208
|
+
const { ports, required, optional, workspaceLayout, indexed } = scope;
|
|
209
|
+
return createPersistentStateModule(ports).withPluginLock({ workspaceRoot: workspaceLayout.root, pluginId: indexed.pluginId, run: async () => {
|
|
210
|
+
// Every install and replacement, not only an update, is a mutation of this plugin: an
|
|
211
|
+
// unfinished update journal refuses it here, under the same plugin lock, because boot
|
|
212
|
+
// recovery removes only the journal's own candidate digest and would otherwise restore the
|
|
213
|
+
// old revision beside whatever this install published.
|
|
214
|
+
// The journal lives under the layout this install was given, the one it publishes into.
|
|
215
|
+
await settleAgentPluginUpdateJournal({ store: createAgentPluginUpdateStore({ ports: { ...ports, layout: required.layout }, workspaceId: required.workspaceId, pluginId: indexed.pluginId }) });
|
|
216
|
+
const installed = await (optional.publishGuard ? optional.publishGuard({ plugin: indexed, publish: () => publishPackage(scope) }, {}) : publishPackage(scope));
|
|
217
|
+
if (scope.published && optional.pruneSupersededRevisions !== false)
|
|
218
|
+
await pruneSupersededRevisions({ ports, workspaceRoot: workspaceLayout.root, installed: scope.published });
|
|
219
|
+
return installed;
|
|
220
|
+
} });
|
|
221
|
+
}
|
|
222
|
+
/** Publishes under the identity lock, asking the host's identity admission first when it has one. */
|
|
223
|
+
function publishUnderIdentityLock(scope) {
|
|
224
|
+
const { ports, workspaceLayout, indexed } = scope;
|
|
225
|
+
return createPersistentStateModule(ports).withIdentityLock({ workspaceRoot: workspaceLayout.root, run: async () => {
|
|
226
|
+
await assertIdentityAvailable({ ports, workspaceRoot: workspaceLayout.root, candidate: indexed });
|
|
227
|
+
if (ports.identityAdmission)
|
|
228
|
+
return ports.identityAdmission({ id: indexed.id, localId: indexed.pluginId, run: () => publishWithinPluginLock(scope) }, {});
|
|
229
|
+
return publishWithinPluginLock(scope);
|
|
230
|
+
} });
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Verifies, extracts, and publishes one Agent Plugin archive.
|
|
234
|
+
*
|
|
235
|
+
* @throws {AgentPluginInstallError} For every expected failure — a hostile or malformed archive, a
|
|
236
|
+
* digest mismatch, an invalid manifest. Never partially publishes: any failure after extraction has
|
|
237
|
+
* begun removes the whole staging directory before rethrowing.
|
|
238
|
+
* @complexity O(e) in archive entry count, O(b) in total extracted bytes — both explicitly bounded
|
|
239
|
+
* by {@link LIMITS}, so this function's cost cannot be driven unbounded by a hostile archive.
|
|
240
|
+
*/
|
|
241
|
+
// The ONE call that turns (instance layout, workspaceId) into real, internally-consistent
|
|
242
|
+
// packages/staging/pluginDataDir paths — see the SECURITY note on `InstallAgentPluginRequired.layout`
|
|
243
|
+
// above for why this replaces accepting an already-resolved `AgentPluginWorkspaceLayout` directly.
|
|
244
|
+
// `forWorkspace` itself still throws for a syntactically invalid `workspaceId`, unchanged.
|
|
245
|
+
// Whether this install succeeded (bytes now live at `finalRoot`) or failed, the staging
|
|
246
|
+
// transaction directory itself must never be left behind — on success `ports.filesystem.rename` already moved
|
|
247
|
+
// `extractionRoot` out of it, so this only ever removes the (now-empty, or failure-abandoned)
|
|
248
|
+
// temp directory, never the published package.
|
|
249
|
+
async function installAgentPlugin({ ports, required }, optional = {}) {
|
|
250
|
+
const { archive, expectedSha256, archiveReader, layout, workspaceId } = required;
|
|
251
|
+
const workspaceLayout = layout.forWorkspace({ workspaceId });
|
|
252
|
+
const digest = verifyArchiveBytes({ archive, expectedSha256 });
|
|
253
|
+
await ensureStagingArea(ports, workspaceLayout);
|
|
254
|
+
await assertEntryCountWithinCap(archiveReader.entries({ archive }));
|
|
255
|
+
const transactionRoot = await ports.filesystem.mkdtemp(path.join(workspaceLayout.staging, "install-"));
|
|
256
|
+
const extractionRoot = path.join(transactionRoot, "root");
|
|
257
|
+
await ports.filesystem.mkdir(extractionRoot, { mode: 0o700 });
|
|
258
|
+
try {
|
|
259
|
+
const executablePaths = await extractEntries({ ports, entries: archiveReader.entries({ archive }), extractionRoot });
|
|
260
|
+
const indexed = await indexInstalledRoot({ ports, packageRoot: extractionRoot, archiveDigest: digest });
|
|
261
|
+
if (optional.previewOnly)
|
|
262
|
+
return indexed;
|
|
263
|
+
return await publishUnderIdentityLock({ ports, required, optional, workspaceLayout, digest, indexed, extractionRoot, executablePaths, published: undefined });
|
|
264
|
+
}
|
|
265
|
+
finally {
|
|
266
|
+
await ports.filesystem.rm(transactionRoot, { recursive: true, force: true });
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
/** Reads an extracted or installed package root into its indexed plugin record. */
|
|
270
|
+
function indexInstalledRoot({ ports, packageRoot, archiveDigest }) {
|
|
271
|
+
return createInstalledPackageIndex({ ports }).indexInstalledRoot({ packageRoot, archiveDigest });
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Whether `finalRoot` already holds exactly the verified bytes in `extractionRoot`, so the install
|
|
275
|
+
* can deduplicate. A digest directory's NAME is only a claim: an operator with shell access can
|
|
276
|
+
* edit it in place ({@link freezeTree} is not a security boundary), and the ledger and the
|
|
277
|
+
* contribution trust gate check digest identity only — so reuse without comparing bytes would
|
|
278
|
+
* keep edited executable modules selected as shipped code. A mismatched copy is renamed aside
|
|
279
|
+
* under a non-digest name (kept for the operator, never indexed or selected) and `false` tells the
|
|
280
|
+
* caller to publish the pristine bytes in its place.
|
|
281
|
+
* @complexity O(f + b) in the file count and bytes of the two trees.
|
|
282
|
+
*/
|
|
283
|
+
async function reuseOrSetAsideExisting(ports, { packagesDir, finalRoot, extractionRoot, pluginId }) {
|
|
284
|
+
if (!(await isRealDirectory({ ports, target: finalRoot })))
|
|
285
|
+
return false;
|
|
286
|
+
if (await sameTree({ ports, left: finalRoot, right: extractionRoot }))
|
|
287
|
+
return true;
|
|
288
|
+
const aside = path.join(packagesDir, `.modified-${path.basename(finalRoot).slice(0, 12)}-${randomUUID()}`);
|
|
289
|
+
await createUninstallModule(ports).stageForRemoval(packagesDir, finalRoot, { quarantined: aside });
|
|
290
|
+
ports.onEvent?.({ event: 'agent-plugin-modified-revision-preserved', message: `Plugin '${pluginId}': an installed revision no longer matched its digest; it was kept at '${aside}' and the verified bytes were reinstalled.` });
|
|
291
|
+
return false;
|
|
292
|
+
}
|
|
293
|
+
/** Same entry names, kinds and file bytes, recursively. @complexity O(f + b). */
|
|
294
|
+
async function sameTree({ ports, left, right }) {
|
|
295
|
+
const [leftEntries, rightEntries] = await Promise.all([ports.filesystem.readdir(left, { withFileTypes: true }), ports.filesystem.readdir(right, { withFileTypes: true })]);
|
|
296
|
+
if (leftEntries.length !== rightEntries.length)
|
|
297
|
+
return false;
|
|
298
|
+
const rightByName = new Map(rightEntries.map(entry => [entry.name, entry]));
|
|
299
|
+
for (const entry of leftEntries) {
|
|
300
|
+
const other = rightByName.get(entry.name);
|
|
301
|
+
if (!other || entry.isDirectory() !== other.isDirectory() || entry.isFile() !== other.isFile())
|
|
302
|
+
return false;
|
|
303
|
+
const [leftPath, rightPath] = [path.join(left, entry.name), path.join(right, entry.name)];
|
|
304
|
+
if (!(await (entry.isDirectory() ? sameTree({ ports, left: leftPath, right: rightPath }) : sameFile({ ports, left: leftPath, right: rightPath }))))
|
|
299
305
|
return false;
|
|
300
|
-
return Buffer.from(await readFile(left)).equals(Buffer.from(await readFile(right)));
|
|
301
306
|
}
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
return
|
|
307
|
+
return true;
|
|
308
|
+
}
|
|
309
|
+
/** Size first, so a grown file is rejected without reading it. */
|
|
310
|
+
async function sameFile({ ports, left, right }) {
|
|
311
|
+
if ((await ports.filesystem.stat(left)).size !== (await ports.filesystem.stat(right)).size)
|
|
312
|
+
return false;
|
|
313
|
+
return Buffer.from(await ports.filesystem.readFile(left)).equals(Buffer.from(await ports.filesystem.readFile(right)));
|
|
314
|
+
}
|
|
315
|
+
/** The `(target '...')` suffix on the symlink-rejection message, or nothing when the entry carries
|
|
316
|
+
* no `linkTarget` at all — split out purely to keep that `&&`/ternary pair out of
|
|
317
|
+
* {@link extractOneEntry}'s own branch count. */
|
|
318
|
+
function symlinkRejectionMessage(entry) {
|
|
319
|
+
const targetSuffix = "linkTarget" in entry && entry.linkTarget ? ` (target '${entry.linkTarget}')` : "";
|
|
320
|
+
return `archive entry '${entry.entryPath}' has kind '${entry.kind}', which Agent Plugin packages are not permitted to contain${targetSuffix}`;
|
|
321
|
+
}
|
|
322
|
+
/** `createPackagePathsModule(ports).normalizePackageEntryPath()`, with its thrown error re-shaped into the module's own
|
|
323
|
+
* `AgentPluginInstallError` vocabulary. */
|
|
324
|
+
function normalizeEntryPathOrThrow({ ports, entryPath }) {
|
|
325
|
+
try {
|
|
326
|
+
return createPackagePathsModule(ports).normalizePackageEntryPath(entryPath);
|
|
308
327
|
}
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
function normalizeEntryPathOrThrow(entryPath) {
|
|
312
|
-
try {
|
|
313
|
-
return normalizePackageEntryPath(entryPath);
|
|
314
|
-
}
|
|
315
|
-
catch (error) {
|
|
316
|
-
throw new AgentPluginInstallError({ code: "UNSAFE_ENTRY_PATH", message: `archive entry path is unsafe: '${entryPath}'` }, { cause: error });
|
|
317
|
-
}
|
|
328
|
+
catch (error) {
|
|
329
|
+
throw new AgentPluginInstallError({ code: "UNSAFE_ENTRY_PATH", message: `archive entry path is unsafe: '${entryPath}'` }, { cause: error });
|
|
318
330
|
}
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
catch (error) {
|
|
325
|
-
throw new AgentPluginInstallError({ code: "UNSAFE_ENTRY_PATH", message: `archive entry resolves outside the package root: '${normalized}'` }, {
|
|
326
|
-
cause: error instanceof PackagePathViolation ? error : undefined,
|
|
327
|
-
});
|
|
328
|
-
}
|
|
331
|
+
}
|
|
332
|
+
/** `createPackagePathsModule(ports).assertContainedOnDisk()`, with its thrown error re-shaped the same way. */
|
|
333
|
+
async function resolveContainedDestinationOrThrow({ ports, extractionRoot, normalized }) {
|
|
334
|
+
try {
|
|
335
|
+
return await createPackagePathsModule(ports).assertContainedOnDisk(extractionRoot, normalized);
|
|
329
336
|
}
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
* entry) the actual write. Returns the running total-extracted-bytes count, since that is the one
|
|
334
|
-
* piece of `extractEntries`'s loop state a single entry's processing can change.
|
|
335
|
-
*/
|
|
336
|
-
// Refused BEFORE path normalization: a symlink entry is never acceptable regardless of how
|
|
337
|
-
// "safe" its own name looks, matching the ecosystem fix this module's header cites — validating
|
|
338
|
-
// where a permitted symlink might point is more attack surface than refusing the entry kind.
|
|
339
|
-
async function extractOneEntry(args) {
|
|
340
|
-
const { entry, extractionRoot, seen, executablePaths, totalBytesSoFar } = args;
|
|
341
|
-
if (entry.kind !== "file" && entry.kind !== "directory") {
|
|
342
|
-
throw new AgentPluginInstallError({ code: "SYMLINK_ENTRY_REJECTED", message: symlinkRejectionMessage(entry) });
|
|
343
|
-
}
|
|
344
|
-
const normalized = normalizeEntryPathOrThrow(entry.entryPath);
|
|
345
|
-
if (seen.has(normalized)) {
|
|
346
|
-
throw new AgentPluginInstallError({ code: "DUPLICATE_ENTRY", message: `duplicate archive entry '${normalized}' — refusing a second write over an already-vetted first one` });
|
|
347
|
-
}
|
|
348
|
-
seen.add(normalized);
|
|
349
|
-
const destination = await resolveContainedDestinationOrThrow(extractionRoot, normalized);
|
|
350
|
-
if (entry.kind === "directory") {
|
|
351
|
-
await mkdir(destination, { recursive: true, mode: 0o700 });
|
|
352
|
-
return totalBytesSoFar;
|
|
353
|
-
}
|
|
354
|
-
if ((entry.declaredSize ?? 0) > LIMITS.maxFileBytes) {
|
|
355
|
-
throw new AgentPluginInstallError({ code: "FILE_TOO_LARGE", message: `archive file '${normalized}' declares ${entry.declaredSize} bytes, over the ${LIMITS.maxFileBytes}-byte cap` });
|
|
356
|
-
}
|
|
357
|
-
await mkdir(path.dirname(destination), { recursive: true, mode: 0o700 });
|
|
358
|
-
const totalBytes = await writeContainedFile({
|
|
359
|
-
destination,
|
|
360
|
-
normalized,
|
|
361
|
-
stream: entry.openReadStream({}),
|
|
362
|
-
totalBytesSoFar,
|
|
337
|
+
catch (error) {
|
|
338
|
+
throw new AgentPluginInstallError({ code: "UNSAFE_ENTRY_PATH", message: `archive entry resolves outside the package root: '${normalized}'` }, {
|
|
339
|
+
cause: error instanceof PackagePathViolation ? error : undefined,
|
|
363
340
|
});
|
|
364
|
-
if (entry.executable)
|
|
365
|
-
executablePaths.add(normalized);
|
|
366
|
-
return totalBytes;
|
|
367
341
|
}
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
let entryCount = 0;
|
|
383
|
-
for (let next = await iterator.next(); !next.done; next = await iterator.next()) {
|
|
384
|
-
entryCount += 1;
|
|
385
|
-
if (entryCount > LIMITS.maxEntries) {
|
|
386
|
-
await Promise.resolve(iterator.return?.()).catch(() => undefined);
|
|
387
|
-
throw tooManyEntriesError();
|
|
388
|
-
}
|
|
389
|
-
}
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* Applies every hardening rule in this module's header to one archive entry: symlink rejection,
|
|
345
|
+
* path normalization, duplicate detection, containment, the per-file size cap, and (for a file
|
|
346
|
+
* entry) the actual write. Returns the running total-extracted-bytes count, since that is the one
|
|
347
|
+
* piece of `extractEntries`'s loop state a single entry's processing can change.
|
|
348
|
+
*/
|
|
349
|
+
// Refused BEFORE path normalization: a symlink entry is never acceptable regardless of how
|
|
350
|
+
// "safe" its own name looks, matching the ecosystem fix this module's header cites — validating
|
|
351
|
+
// where a permitted symlink might point is more attack surface than refusing the entry kind.
|
|
352
|
+
async function extractOneEntry(ports, args) {
|
|
353
|
+
const { entry, extractionRoot, seen, executablePaths, totalBytesSoFar } = args;
|
|
354
|
+
if (entry.kind !== "file" && entry.kind !== "directory") {
|
|
355
|
+
throw new AgentPluginInstallError({ code: "SYMLINK_ENTRY_REJECTED", message: symlinkRejectionMessage(entry) });
|
|
390
356
|
}
|
|
391
|
-
|
|
392
|
-
|
|
357
|
+
const normalized = normalizeEntryPathOrThrow({ ports, entryPath: entry.entryPath });
|
|
358
|
+
if (seen.has(normalized)) {
|
|
359
|
+
throw new AgentPluginInstallError({ code: "DUPLICATE_ENTRY", message: `duplicate archive entry '${normalized}' — refusing a second write over an already-vetted first one` });
|
|
393
360
|
}
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
const executablePaths = new Set();
|
|
400
|
-
let entryCount = 0;
|
|
401
|
-
let totalBytes = 0;
|
|
402
|
-
for await (const entry of entries) {
|
|
403
|
-
entryCount += 1;
|
|
404
|
-
// Still enforced here: the pre-pass trusts the reader to yield the same entries twice.
|
|
405
|
-
if (entryCount > LIMITS.maxEntries)
|
|
406
|
-
throw tooManyEntriesError();
|
|
407
|
-
totalBytes = await extractOneEntry({ entry, extractionRoot, seen, executablePaths, totalBytesSoFar: totalBytes });
|
|
408
|
-
}
|
|
409
|
-
return executablePaths;
|
|
361
|
+
seen.add(normalized);
|
|
362
|
+
const destination = await resolveContainedDestinationOrThrow({ ports, extractionRoot, normalized });
|
|
363
|
+
if (entry.kind === "directory") {
|
|
364
|
+
await ports.filesystem.mkdir(destination, { recursive: true, mode: 0o700 });
|
|
365
|
+
return totalBytesSoFar;
|
|
410
366
|
}
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
367
|
+
if ((entry.declaredSize ?? 0) > LIMITS.maxFileBytes) {
|
|
368
|
+
throw new AgentPluginInstallError({ code: "FILE_TOO_LARGE", message: `archive file '${normalized}' declares ${entry.declaredSize} bytes, over the ${LIMITS.maxFileBytes}-byte cap` });
|
|
369
|
+
}
|
|
370
|
+
await ports.filesystem.mkdir(path.dirname(destination), { recursive: true, mode: 0o700 });
|
|
371
|
+
const totalBytes = await writeContainedFile(ports, {
|
|
372
|
+
destination,
|
|
373
|
+
normalized,
|
|
374
|
+
stream: entry.openReadStream({}),
|
|
375
|
+
totalBytesSoFar,
|
|
376
|
+
});
|
|
377
|
+
if (entry.executable)
|
|
378
|
+
executablePaths.add(normalized);
|
|
379
|
+
return totalBytes;
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* Refuses a "million small files" archive from entry metadata alone, before a staging
|
|
383
|
+
* transaction exists. Checking only inside the extraction loop meant an over-cap archive first
|
|
384
|
+
* had the cap's worth of files contained, written and then deleted again. Every reader derives
|
|
385
|
+
* its entries from the archive bytes, so a second iteration costs one central-directory walk
|
|
386
|
+
* and opens no content stream.
|
|
387
|
+
*/
|
|
388
|
+
/** Ported from Jini 78d4b60b: reject from metadata before a staging transaction exists.
|
|
389
|
+
* A second central-directory walk opens no content streams and avoids over-cap disk churn. */
|
|
390
|
+
async function assertEntryCountWithinCap(entries) {
|
|
391
|
+
// Only the count matters, so the entries are stepped through without being bound to a name.
|
|
392
|
+
// Leaving early closes the walk the way for-await would, without letting a failing close
|
|
393
|
+
// replace the cap error.
|
|
394
|
+
const iterator = entries[Symbol.asyncIterator]();
|
|
395
|
+
let entryCount = 0;
|
|
396
|
+
for (let next = await iterator.next(); !next.done; next = await iterator.next()) {
|
|
397
|
+
entryCount += 1;
|
|
398
|
+
if (entryCount > LIMITS.maxEntries) {
|
|
399
|
+
await Promise.resolve(iterator.return?.()).catch(() => undefined);
|
|
400
|
+
throw tooManyEntriesError();
|
|
439
401
|
}
|
|
440
|
-
return totalBytes;
|
|
441
402
|
}
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
403
|
+
}
|
|
404
|
+
function tooManyEntriesError() {
|
|
405
|
+
return new AgentPluginInstallError({ code: "TOO_MANY_ENTRIES", message: `archive exceeds the ${LIMITS.maxEntries}-entry cap` });
|
|
406
|
+
}
|
|
407
|
+
/** Extracts every entry into `extractionRoot`, enforcing every hardening rule in this module's
|
|
408
|
+
* header. Returns the set of archive-relative paths the archive marked executable, for
|
|
409
|
+
* {@link freezeTree} to preserve the `+x` bit on. */
|
|
410
|
+
async function extractEntries({ ports, entries, extractionRoot }) {
|
|
411
|
+
const seen = new Set();
|
|
412
|
+
const executablePaths = new Set();
|
|
413
|
+
let entryCount = 0;
|
|
414
|
+
let totalBytes = 0;
|
|
415
|
+
for await (const entry of entries) {
|
|
416
|
+
entryCount += 1;
|
|
417
|
+
// Still enforced here: the pre-pass trusts the reader to yield the same entries twice.
|
|
418
|
+
if (entryCount > LIMITS.maxEntries)
|
|
419
|
+
throw tooManyEntriesError();
|
|
420
|
+
totalBytes = await extractOneEntry(ports, { entry, extractionRoot, seen, executablePaths, totalBytesSoFar: totalBytes });
|
|
421
|
+
}
|
|
422
|
+
return executablePaths;
|
|
423
|
+
}
|
|
424
|
+
/** Streams one file entry to disk, bounding both its own size and the running archive total against
|
|
425
|
+
* bytes ACTUALLY observed — never the archive format's declared size, which a decompression bomb
|
|
426
|
+
* lies about by construction. `O_EXCL` refuses to write over anything already at `destination`
|
|
427
|
+
* (there cannot legitimately be one — `extractEntries`'s duplicate check already refused a second
|
|
428
|
+
* entry for the same path); `O_NOFOLLOW` refuses to follow a final-component symlink if the
|
|
429
|
+
* filesystem somehow already had one (defense in depth — this module never creates one itself). */
|
|
430
|
+
async function writeContainedFile(ports, params) {
|
|
431
|
+
let flags = constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL;
|
|
432
|
+
if (ports.process.platform !== "win32")
|
|
433
|
+
flags |= constants.O_NOFOLLOW;
|
|
434
|
+
const handle = await ports.filesystem.open(params.destination, flags, 0o600);
|
|
435
|
+
let fileBytes = 0;
|
|
436
|
+
let totalBytes = params.totalBytesSoFar;
|
|
437
|
+
try {
|
|
438
|
+
for await (const chunk of params.stream) {
|
|
439
|
+
fileBytes += chunk.byteLength;
|
|
440
|
+
totalBytes += chunk.byteLength;
|
|
441
|
+
if (fileBytes > LIMITS.maxFileBytes) {
|
|
442
|
+
throw new AgentPluginInstallError({ code: "DECOMPRESSION_BOMB", message: `archive file '${params.normalized}' exceeded the ${LIMITS.maxFileBytes}-byte cap while decompressing — its declared size was a lie` });
|
|
458
443
|
}
|
|
459
|
-
|
|
460
|
-
|
|
444
|
+
if (totalBytes > LIMITS.maxTotalExtractedBytes) {
|
|
445
|
+
throw new AgentPluginInstallError({ code: "TOTAL_SIZE_EXCEEDED", message: `archive exceeds the ${LIMITS.maxTotalExtractedBytes}-byte total extracted-size cap` });
|
|
461
446
|
}
|
|
447
|
+
await handle.write(chunk instanceof Buffer ? chunk : Buffer.from(chunk));
|
|
462
448
|
}
|
|
463
|
-
await chmod(root, 0o555);
|
|
464
449
|
}
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
450
|
+
finally {
|
|
451
|
+
await handle.close();
|
|
452
|
+
}
|
|
453
|
+
return totalBytes;
|
|
454
|
+
}
|
|
455
|
+
/** Makes every file/directory under `root` read-only (executables keep `+x`, per the Agent Plugins
|
|
456
|
+
* spec's own MCP `command` needing to launch a `./`-relative script — not exercised by anything in
|
|
457
|
+
* this slice, since MCP execution is out of scope for v1, but the bit is preserved now rather than
|
|
458
|
+
* silently dropped for whenever it is).
|
|
459
|
+
*
|
|
460
|
+
* Stated plainly rather than implied (`packages/mcp/src/federation/trust.ts`'s own "what this tier deliberately
|
|
461
|
+
* does NOT claim" discipline): this is best-effort defense against an ACCIDENTAL same-process write
|
|
462
|
+
* into what is supposed to be a read-only `PLUGIN_ROOT`, not a security boundary against a
|
|
463
|
+
* determined attacker already running code as this same OS user — that user can `ports.filesystem.chmod` again. */
|
|
464
|
+
async function freezeTree({ ports, root, executables }, { prefix = "" } = {}) {
|
|
465
|
+
for (const entry of await ports.filesystem.readdir(root, { withFileTypes: true })) {
|
|
466
|
+
const relative = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
467
|
+
const absolute = path.join(root, entry.name);
|
|
468
|
+
if (entry.isDirectory()) {
|
|
469
|
+
await freezeTree({ ports, root: absolute, executables }, { prefix: relative });
|
|
470
|
+
await ports.filesystem.chmod(absolute, 0o555);
|
|
475
471
|
}
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
throw new AgentPluginInstallError({ code: "PUBLISH_FAILED", message: `failed to publish the extracted package to '${finalRoot}'` }, { cause: error });
|
|
479
|
-
}
|
|
480
|
-
if (!(await isRealDirectory(finalRoot))) {
|
|
481
|
-
throw new AgentPluginInstallError({ code: "PUBLISH_FAILED", message: `'${finalRoot}' exists but is not a real, published package directory` }, { cause: error });
|
|
482
|
-
}
|
|
483
|
-
// Lost the race to a concurrent install of identical bytes — the bytes at `finalRoot` are the
|
|
484
|
-
// ones this install itself would have written, so this is not a failure.
|
|
472
|
+
else {
|
|
473
|
+
await ports.filesystem.chmod(absolute, executables.has(relative) ? 0o555 : 0o444);
|
|
485
474
|
}
|
|
486
475
|
}
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
476
|
+
await ports.filesystem.chmod(root, 0o555);
|
|
477
|
+
}
|
|
478
|
+
/** Publishes `extractionRoot` to `finalRoot` by ports.filesystem.rename — atomic on the same filesystem, so a reader
|
|
479
|
+
* can never observe a partially-extracted package at the live path. Tolerates losing a race against
|
|
480
|
+
* a concurrent install of the byte-identical digest (the same content, published a moment earlier by
|
|
481
|
+
* another process) rather than treating that as a failure. */
|
|
482
|
+
// macOS reports EACCES, rather than ENOTEMPTY, when the winning install has already
|
|
483
|
+
// frozen its destination directory. Still require a real directory below: a permission
|
|
484
|
+
// failure with no published winner must remain PUBLISH_FAILED.
|
|
485
|
+
async function publish({ ports, extractionRoot, finalRoot }) {
|
|
486
|
+
try {
|
|
487
|
+
await ports.filesystem.rename(extractionRoot, finalRoot);
|
|
488
|
+
}
|
|
489
|
+
catch (error) {
|
|
490
|
+
if (!isErrnoException(error) || (error.code !== "EEXIST" && error.code !== "ENOTEMPTY" && error.code !== "EACCES")) {
|
|
491
|
+
throw new AgentPluginInstallError({ code: "PUBLISH_FAILED", message: `failed to publish the extracted package to '${finalRoot}'` }, { cause: error });
|
|
491
492
|
}
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
return false;
|
|
495
|
-
throw error;
|
|
493
|
+
if (!(await isRealDirectory({ ports, target: finalRoot }))) {
|
|
494
|
+
throw new AgentPluginInstallError({ code: "PUBLISH_FAILED", message: `'${finalRoot}' exists but is not a real, published package directory` }, { cause: error });
|
|
496
495
|
}
|
|
496
|
+
// Lost the race to a concurrent install of identical bytes — the bytes at `finalRoot` are the
|
|
497
|
+
// ones this install itself would have written, so this is not a failure.
|
|
497
498
|
}
|
|
498
|
-
|
|
499
|
-
|
|
499
|
+
}
|
|
500
|
+
async function isRealDirectory({ ports, target }) {
|
|
501
|
+
try {
|
|
502
|
+
const info = await ports.filesystem.stat(target);
|
|
503
|
+
return info.isDirectory();
|
|
500
504
|
}
|
|
501
|
-
|
|
502
|
-
|
|
505
|
+
catch (error) {
|
|
506
|
+
if (isErrnoException(error) && error.code === "ENOENT")
|
|
507
|
+
return false;
|
|
508
|
+
throw error;
|
|
503
509
|
}
|
|
504
|
-
|
|
510
|
+
}
|
|
511
|
+
function sha256(value) {
|
|
512
|
+
return createHash("sha256").update(value).digest("hex");
|
|
513
|
+
}
|
|
514
|
+
function isErrnoException(error) {
|
|
515
|
+
return typeof error === "object" && error !== null && "code" in error;
|
|
516
|
+
}
|
|
517
|
+
function buildModule(ports) {
|
|
518
|
+
return {
|
|
519
|
+
maxAgentPluginInstallArchiveBytes,
|
|
520
|
+
installAgentPlugin: (required, optional = {}) => installAgentPlugin({ ports, required }, optional),
|
|
521
|
+
indexInstalledRoot: (packageRoot, archiveDigest) => indexInstalledRoot({ ports, packageRoot, archiveDigest }),
|
|
522
|
+
};
|
|
505
523
|
}
|
|
506
524
|
const instances = new WeakMap();
|
|
507
525
|
/** Internal composition; one state/queue instance per injected host context. */
|
|
508
|
-
export function createInstallModule(ports) {
|
|
526
|
+
export function createInstallModule(ports, _optional = {}) {
|
|
509
527
|
let instance = instances.get(ports);
|
|
510
528
|
if (!instance) {
|
|
511
529
|
instance = buildModule(ports);
|