@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
|
@@ -1,33 +1,21 @@
|
|
|
1
1
|
import { agentVisiblePluginCandidate } from './search-projection.js';
|
|
2
2
|
export const DEFAULT_CHAT_AGENT_PLUGINS = 'auto';
|
|
3
3
|
const MAX_AUTOMATIC_GUIDANCE_BYTES = 8 * 1024;
|
|
4
|
-
const
|
|
4
|
+
const MAX_QUERY_GUIDANCE_BYTES = 24 * 1024;
|
|
5
5
|
/** Use the same one-line metadata reason in consent and progressive disclosure. */
|
|
6
6
|
function describeMatch({ plugin }, _options = {}) {
|
|
7
7
|
return { id: plugin.pluginId, name: (plugin.displayName ?? plugin.pluginId).replace(/\s+/g, ' '),
|
|
8
8
|
why: (plugin.summary ?? plugin.description ?? `Provides ${(plugin.provides ?? plugin.keywords).join(', ')}`).split(/[\n.]/)[0].replace(/\s+/g, ' ').slice(0, 180) };
|
|
9
9
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
function
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const footer = formatPluginToolPointer ? `\nLoad one with ${formatPluginToolPointer({ pluginId: '<pluginId>', file: 'SKILL.md' })} before acting on that part.` : '';
|
|
20
|
-
const more = (remaining) => remaining ? `\n+${remaining} more relevant: search_agent_plugin_local({ query: <same request>, offset: 0 }); page with nextOffset` : '';
|
|
21
|
-
const lines = [];
|
|
22
|
-
const bytes = (text) => new TextEncoder().encode(text).length;
|
|
23
|
-
for (const match of matches) {
|
|
24
|
-
const { id, name, why } = describeMatch({ plugin: match });
|
|
25
|
-
const line = `${name} (${id}) — ${why}`;
|
|
26
|
-
if (bytes(header + [...lines, line].join('\n') + more(matches.length - lines.length - 1) + footer) > 600)
|
|
27
|
-
break;
|
|
28
|
-
lines.push(line);
|
|
29
|
-
}
|
|
30
|
-
return header + lines.join('\n') + more(matches.length - lines.length) + footer;
|
|
10
|
+
function enabledPluginCatalog({ ctx, candidates }, _options = {}) {
|
|
11
|
+
const rows = [...candidates].filter(plugin => !ctx.state.excluded.includes(plugin.pluginId) && !ctx.delivered.has(plugin.pluginId))
|
|
12
|
+
.sort((a, b) => a.pluginId.localeCompare(b.pluginId));
|
|
13
|
+
return rows.length ? 'Enabled agent plugins (load one before acting on its part):\n' + rows.map(plugin => catalogRow({ ctx, plugin })).join('\n') : '';
|
|
14
|
+
}
|
|
15
|
+
function catalogRow({ ctx, plugin }, _options = {}) {
|
|
16
|
+
const { id, name, why } = describeMatch({ plugin });
|
|
17
|
+
const pointer = ctx.ports.formatPluginToolPointer?.({ pluginId: id, file: 'SKILL.md' }) ?? `search_agent_plugin_local({ query: "${id}" })`;
|
|
18
|
+
return `- ${name} (${id}): ${why}` + (plugin.keywords.length ? `\n Use for: ${plugin.keywords.slice(0, 8).join(', ')}` : '') + `\n Load: ${pointer}`;
|
|
31
19
|
}
|
|
32
20
|
/** A guarded capability admits its providers outright; a query is ranked for relevance. */
|
|
33
21
|
function rankCandidates({ candidates, input, ports }, _options = {}) {
|
|
@@ -35,7 +23,16 @@ function rankCandidates({ candidates, input, ports }, _options = {}) {
|
|
|
35
23
|
const admit = (plugins) => plugins.map(plugin => ({ ...plugin, score: 4 }));
|
|
36
24
|
if (capabilities)
|
|
37
25
|
return admit(candidates.filter(plugin => plugin.provides?.some(capability => capabilities.includes(capability))));
|
|
38
|
-
return ports.rank({ query: input.query ?? '', candidates, limit: candidates.length }, {});
|
|
26
|
+
return withRequiredProviders({ ranked: ports.rank({ query: input.query ?? '', candidates, limit: candidates.length }, {}), candidates });
|
|
27
|
+
}
|
|
28
|
+
function withRequiredProviders({ ranked, candidates }, _options = {}) {
|
|
29
|
+
const top = ranked[0];
|
|
30
|
+
if (!top)
|
|
31
|
+
return ranked;
|
|
32
|
+
const required = candidates.filter(plugin => plugin.enabled && plugin.provides?.some(capability => top.requires?.includes(capability)))
|
|
33
|
+
.map(plugin => ranked.find(match => match.pluginId === plugin.pluginId) ?? { ...plugin, score: 4 });
|
|
34
|
+
const ordered = [top, ...required, ...ranked];
|
|
35
|
+
return ordered.filter((plugin, index) => ordered.findIndex(match => match.pluginId === plugin.pluginId) === index);
|
|
39
36
|
}
|
|
40
37
|
/** Validate the request's small browser state; malformed state means no previous decision.
|
|
41
38
|
* @returns A fresh state; no caller input is mutated. @complexity O(n) in saved identities.
|
|
@@ -45,215 +42,244 @@ export function readChatAgentPluginState({ value }, _options = {}) {
|
|
|
45
42
|
if (!value || typeof value !== 'object')
|
|
46
43
|
return empty;
|
|
47
44
|
const record = value;
|
|
48
|
-
const ids = (raw) => Array.isArray(raw) && raw.every(id => typeof id === 'string' && id.length > 0 && id.length <= 160);
|
|
49
45
|
if (!ids(record.excluded))
|
|
50
46
|
return empty;
|
|
51
47
|
const decision = record.decision;
|
|
52
48
|
if (decision !== null && (!decision || !ids(decision.selected)))
|
|
53
49
|
return empty;
|
|
54
|
-
return { decision: decision ?
|
|
50
|
+
return { decision: decision ? copyDecision({ decision }) : null, excluded: [...new Set(record.excluded)] };
|
|
55
51
|
}
|
|
56
|
-
/**
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
// Failed preference persistence must leave this controller without the rejected consent.
|
|
84
|
-
if (answer.action === 'auto') {
|
|
85
|
-
await ports.saveAuto({}, {});
|
|
86
|
-
mode = 'auto';
|
|
87
|
-
}
|
|
88
|
-
state = { decision: { selected, asked: true }, excluded: [...new Set([...state.excluded, ...matches.filter(plugin => !selected.includes(plugin.pluginId)).map(plugin => plugin.pluginId)])] };
|
|
89
|
-
// Consent changes only this person's preference, never a workspace default.
|
|
90
|
-
return matches.filter(plugin => selected.includes(plugin.pluginId));
|
|
52
|
+
/** A saved id list: non-empty strings of at most 160 characters. O(n). */
|
|
53
|
+
function ids(raw) {
|
|
54
|
+
return Array.isArray(raw) && raw.every(id => typeof id === 'string' && id.length > 0 && id.length <= 160);
|
|
55
|
+
}
|
|
56
|
+
/** Copy a decision whose `selected` list was already validated, keeping only well-formed optional fields. O(n). */
|
|
57
|
+
function copyDecision({ decision }, _options = {}) {
|
|
58
|
+
return { selected: [...new Set(decision.selected)], ...(typeof decision.asked === 'boolean' ? { asked: decision.asked } : {}), ...(ids(decision.delivered) ? { delivered: [...new Set(decision.delivered)] } : {}) };
|
|
59
|
+
}
|
|
60
|
+
/** Ask mode admits only consented matches; the first non-empty match set asks the person once. */
|
|
61
|
+
async function applyConsent({ ctx, matches }, { signal } = {}) {
|
|
62
|
+
if (ctx.mode !== 'ask')
|
|
63
|
+
return matches;
|
|
64
|
+
const { decision } = ctx.state;
|
|
65
|
+
if (decision === null || decision.asked === false)
|
|
66
|
+
return matches.length ? askConsent({ ctx, matches }, { signal }) : matches;
|
|
67
|
+
// Consent survives cold runs; relevance still comes from this request or write capability.
|
|
68
|
+
// Later matches do not inherit consent, and exclusions were applied before ranking.
|
|
69
|
+
return matches.filter(plugin => decision.selected.includes(plugin.pluginId));
|
|
70
|
+
}
|
|
71
|
+
async function askConsent({ ctx, matches }, { signal } = {}) {
|
|
72
|
+
const offered = matches.map(plugin => describeMatch({ plugin }));
|
|
73
|
+
const answer = await ctx.ports.ask({ matches: offered, ...(signal ? { signal } : {}) }, {});
|
|
74
|
+
const selected = answer.action === 'skip' ? [] : answer.selected.filter(id => matches.some(plugin => plugin.pluginId === id));
|
|
75
|
+
// Failed preference persistence must leave this controller without the rejected consent.
|
|
76
|
+
if (answer.action === 'auto') {
|
|
77
|
+
await ctx.ports.saveAuto({}, {});
|
|
78
|
+
ctx.mode = 'auto';
|
|
91
79
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
// Automatic guidance is advisory; unavailable plugins must not block the run.
|
|
80
|
+
ctx.state = { decision: { selected, asked: true }, excluded: [...new Set([...ctx.state.excluded, ...matches.filter(plugin => !selected.includes(plugin.pluginId)).map(plugin => plugin.pluginId)])] };
|
|
81
|
+
// Consent changes only this person's preference, never a workspace default.
|
|
82
|
+
return matches.filter(plugin => selected.includes(plugin.pluginId));
|
|
83
|
+
}
|
|
84
|
+
/** Resolve through the host's activation/trust owner; delivery is recorded only by the caller.
|
|
85
|
+
* Explicit content requests retain safe resolver refusals so the model can correct its request;
|
|
86
|
+
* thrown host diagnostics remain private. Failures stay retryable. O(1) bookkeeping.
|
|
87
|
+
*/
|
|
88
|
+
async function resolveOneGuidance(ctx, { plugin, ...request }, { signal } = {}) {
|
|
89
|
+
if (signal?.aborted)
|
|
90
|
+
return { status: 'cancelled', guidance: '' };
|
|
91
|
+
try {
|
|
92
|
+
const result = await ctx.ports.resolve({ pluginId: plugin.pluginId, ...request }, {});
|
|
93
|
+
if (!result.ok)
|
|
94
|
+
return { status: result.code ?? 'unavailable', guidance: request.skill !== undefined || request.file !== undefined ? result.reason : '' };
|
|
95
|
+
if (!result.promptPrefix.trim())
|
|
109
96
|
return { status: 'unavailable', guidance: '' };
|
|
110
|
-
}
|
|
97
|
+
return { status: 'loaded', guidance: result.promptPrefix };
|
|
111
98
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
delivered.set(plugin.pluginId, plugin.displayName ?? plugin.pluginId);
|
|
116
|
-
}
|
|
117
|
-
/** Bound automatic attachments before recording delivery; explicit loads retain complete text.
|
|
118
|
-
* O(p*b) in resolved plugins and guidance bytes; a deferred plugin remains retryable.
|
|
119
|
-
*/
|
|
120
|
-
async function resolveGuidance({ matches, primaryId }, { signal } = {}) {
|
|
121
|
-
const guidance = [];
|
|
122
|
-
// Unloaded plugins contribute nothing; oversized guidance becomes a pointer instead of the text.
|
|
123
|
-
const guidanceFor = async (match) => {
|
|
124
|
-
const result = await resolveOneGuidance({ plugin: match }, { signal });
|
|
125
|
-
if (result.status !== 'loaded')
|
|
126
|
-
return undefined;
|
|
127
|
-
if (new TextEncoder().encode(result.guidance).length > (match.pluginId === primaryId ? MAX_PRIMARY_GUIDANCE_BYTES : MAX_AUTOMATIC_GUIDANCE_BYTES)) {
|
|
128
|
-
const pointer = ports.formatPluginToolPointer?.({ pluginId: match.pluginId, skill: match.pluginId, file: 'SKILL.md' });
|
|
129
|
-
const howToLoad = pointer === undefined ? '' : ` Load the full instructions with ${pointer}; use the same call with file '<relative path>' for supporting references.`;
|
|
130
|
-
return `Agent Plugin '${match.pluginId}' guidance is deferred because it exceeds the automatic byte limit.${howToLoad}`;
|
|
131
|
-
}
|
|
132
|
-
recordDelivery({ plugin: match, result });
|
|
133
|
-
return result.guidance;
|
|
134
|
-
};
|
|
135
|
-
for (const match of matches) {
|
|
136
|
-
if (signal?.aborted)
|
|
137
|
-
break;
|
|
138
|
-
const text = await guidanceFor(match);
|
|
139
|
-
if (text !== undefined)
|
|
140
|
-
guidance.push(text);
|
|
141
|
-
}
|
|
142
|
-
return guidance;
|
|
99
|
+
catch {
|
|
100
|
+
// Automatic guidance is advisory; unavailable plugins must not block the run.
|
|
101
|
+
return { status: 'unavailable', guidance: '' };
|
|
143
102
|
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
103
|
+
}
|
|
104
|
+
/** Only complete primary guidance updates the loaded set. O(1), no host effects. */
|
|
105
|
+
function recordDelivery({ ctx, plugin, result }) {
|
|
106
|
+
if (result.status === 'loaded')
|
|
107
|
+
ctx.delivered.set(plugin.pluginId, plugin.displayName ?? plugin.pluginId);
|
|
108
|
+
}
|
|
109
|
+
/** Bound automatic attachments before recording delivery; explicit loads retain complete text.
|
|
110
|
+
* O(p*b) in resolved plugins and guidance bytes; a deferred plugin remains retryable.
|
|
111
|
+
*/
|
|
112
|
+
async function resolveGuidance({ ctx, matches }, { budget, signal } = {}) {
|
|
113
|
+
const guidance = [];
|
|
114
|
+
// Unloaded plugins contribute nothing; oversized guidance becomes a pointer instead of the text.
|
|
115
|
+
const guidanceFor = async (match) => {
|
|
116
|
+
const result = await resolveOneGuidance(ctx, { plugin: match }, { signal });
|
|
117
|
+
if (result.status !== 'loaded')
|
|
118
|
+
return undefined;
|
|
119
|
+
if (new TextEncoder().encode(result.guidance).length > (budget ?? MAX_AUTOMATIC_GUIDANCE_BYTES)) {
|
|
120
|
+
const pointer = ctx.ports.formatPluginToolPointer?.({ pluginId: match.pluginId, skill: match.pluginId, file: 'SKILL.md' });
|
|
121
|
+
const howToLoad = pointer === undefined ? '' : ` Load the full instructions with ${pointer}; use the same call with file '<relative path>' for supporting references.`;
|
|
122
|
+
return `Agent Plugin '${match.pluginId}' guidance is deferred because it exceeds the automatic byte limit.${howToLoad}`;
|
|
164
123
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
alreadyLoaded.add(id);
|
|
172
|
-
if (mode === 'off' || input.signal?.aborted)
|
|
173
|
-
return '';
|
|
174
|
-
const catalog = (await ports.list({}, {})).filter(plugin => !state.excluded.includes(plugin.pluginId));
|
|
175
|
-
const candidates = catalog.filter(plugin => plugin.enabled);
|
|
176
|
-
for (const id of alreadyLoaded)
|
|
177
|
-
if (!candidates.some(plugin => plugin.pluginId === id))
|
|
178
|
-
alreadyLoaded.delete(id);
|
|
179
|
-
const ranked = rankCandidates({ candidates, input, ports });
|
|
180
|
-
// Owner decision 2026-10-18: no per-chat plugin count; the relevance threshold and vendor gate decide.
|
|
181
|
-
const relevant = ranked.filter(plugin => !delivered.has(plugin.pluginId) && !input.loaded?.includes(plugin.pluginId) && (!alreadyLoaded.has(plugin.pluginId) || !!input.query));
|
|
182
|
-
const matches = await applyConsent({ matches: relevant }, { signal: input.signal });
|
|
183
|
-
const shouldLoad = !!input.capabilities?.length;
|
|
184
|
-
const primary = input.maxPromptArgBytes === undefined && input.query && !input.loaded?.length && !alreadyLoaded.has(matches[0]?.pluginId ?? '') ? matches.slice(0, 1) : [];
|
|
185
|
-
const result = shouldLoad ? (await resolveGuidance({ matches }, { signal: input.signal })).join('\n\n') : [
|
|
186
|
-
...(await resolveGuidance({ matches: primary, primaryId: primary[0]?.pluginId }, { signal: input.signal })),
|
|
187
|
-
relevantPluginNote({ matches: matches.slice(primary.length), formatPluginToolPointer: ports.formatPluginToolPointer }),
|
|
188
|
-
].filter(Boolean).join('\n\n');
|
|
189
|
-
rememberDelivery();
|
|
190
|
-
await publishUsage();
|
|
191
|
-
// Preflight never resolves off packages implicitly. A catalog line offers an explicit read;
|
|
192
|
-
// its setup guidance may explain whether enabling or credentials are needed.
|
|
193
|
-
const off = offPluginNote({ catalog, input });
|
|
194
|
-
return [result, off].filter(Boolean).join('\n\n');
|
|
195
|
-
}
|
|
196
|
-
/** Rank readable metadata for off plugins; never load their tools or guidance implicitly. O(p*t). */
|
|
197
|
-
function offPluginNote({ catalog, input }) {
|
|
198
|
-
if (!input.query)
|
|
199
|
-
return '';
|
|
200
|
-
const candidates = catalog.filter(plugin => !plugin.enabled).map(candidate => agentVisiblePluginCandidate({ candidate }));
|
|
201
|
-
return ports.rank({ query: input.query, candidates, limit: 10 }, {}).map(plugin => [plugin.description,
|
|
202
|
-
ports.formatPluginToolPointer?.({ pluginId: plugin.pluginId, file: 'SKILL.md' })].filter(Boolean).join(' ')).join('\n');
|
|
203
|
-
}
|
|
204
|
-
/** Admit one explicit id using the same catalog, consent, resolver and delivery state as prepare.
|
|
205
|
-
* No activation writes; unavailable guidance is retryable. O(p) local catalog lookup.
|
|
206
|
-
*/
|
|
207
|
-
async function load({ pluginId, signal, ...request }, _options = {}) {
|
|
208
|
-
if (mode === 'off' && !alreadyLoaded.has(pluginId))
|
|
209
|
-
return { status: 'off', guidance: '' };
|
|
124
|
+
recordDelivery({ ctx, plugin: match, result });
|
|
125
|
+
if (budget !== undefined)
|
|
126
|
+
budget -= new TextEncoder().encode(result.guidance).length;
|
|
127
|
+
return result.guidance;
|
|
128
|
+
};
|
|
129
|
+
for (const match of matches) {
|
|
210
130
|
if (signal?.aborted)
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
if (!plugin)
|
|
216
|
-
return { status: 'missing', guidance: '' };
|
|
217
|
-
return loadPermitted({ plugin, ...request }, { signal });
|
|
131
|
+
break;
|
|
132
|
+
const text = await guidanceFor(match);
|
|
133
|
+
if (text !== undefined)
|
|
134
|
+
guidance.push(text);
|
|
218
135
|
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
136
|
+
return guidance;
|
|
137
|
+
}
|
|
138
|
+
/** Persist actual deliveries separately from consent, using the existing chat decision. */
|
|
139
|
+
function rememberDelivery(ctx) {
|
|
140
|
+
if (!ctx.alreadyLoaded.size && !ctx.delivered.size)
|
|
141
|
+
return;
|
|
142
|
+
const { decision } = ctx.state;
|
|
143
|
+
ctx.state = { ...ctx.state, decision: { selected: [...new Set([...(decision?.selected ?? []), ...(ctx.mode === 'auto' ? ctx.delivered.keys() : [])])],
|
|
144
|
+
asked: decision?.asked ?? false, delivered: [...new Set([...(decision?.delivered ?? []), ...ctx.alreadyLoaded, ...ctx.delivered.keys()])] } };
|
|
145
|
+
}
|
|
146
|
+
/** Initialize usage after a decision (including Skip), then publish only loaded-set changes.
|
|
147
|
+
* Empty discovery must not consume that initial publication: a later Ask answer must persist.
|
|
148
|
+
*/
|
|
149
|
+
async function publishUsage(ctx) {
|
|
150
|
+
if (ctx.publishedSize === ctx.delivered.size || (ctx.delivered.size === 0 && ctx.state.decision === null))
|
|
151
|
+
return;
|
|
152
|
+
ctx.publishedSize = ctx.delivered.size;
|
|
153
|
+
try {
|
|
154
|
+
await ctx.ports.publish({ state: ctx.state, plugins: [...ctx.delivered].map(([id, name]) => ({ id, name })) }, {});
|
|
222
155
|
}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
*/
|
|
226
|
-
async function loadPermitted({ plugin, ...request }, { signal } = {}) {
|
|
227
|
-
const matches = await applyConsent({ matches: [{ ...plugin, score: 4 }] }, { signal });
|
|
228
|
-
if (!matches.length) {
|
|
229
|
-
await publishUsage();
|
|
230
|
-
return { status: 'excluded', guidance: '' };
|
|
231
|
-
}
|
|
232
|
-
let result = await resolveOneGuidance({ plugin, ...request }, { signal });
|
|
233
|
-
if (!plugin.enabled && result.status === 'loaded') {
|
|
234
|
-
result = { status: 'installed-but-inactive', guidance: `Plugin '${plugin.pluginId}' is off; its tools are unavailable.\n\n${result.guidance}` };
|
|
235
|
-
}
|
|
236
|
-
if (isPrimaryInstructions({ pluginId: plugin.pluginId, ...request }))
|
|
237
|
-
recordDelivery({ plugin, result });
|
|
238
|
-
rememberDelivery();
|
|
239
|
-
await publishUsage();
|
|
240
|
-
return result;
|
|
156
|
+
catch {
|
|
157
|
+
// Usage publication is advisory; losing its event must not discard resolved model guidance.
|
|
241
158
|
}
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
159
|
+
}
|
|
160
|
+
/** Query preflight delivers the top and required providers; guarded capabilities resolve their providers.
|
|
161
|
+
* Effects serialize with loads so a suggestion never consumes a backstop's delivery.
|
|
162
|
+
*/
|
|
163
|
+
async function prepare({ ctx, input }) {
|
|
164
|
+
for (const id of input.loaded ?? [])
|
|
165
|
+
ctx.alreadyLoaded.add(id);
|
|
166
|
+
if (ctx.mode === 'off' || input.signal?.aborted)
|
|
167
|
+
return '';
|
|
168
|
+
const installed = (await ctx.ports.list({}, {})).filter(plugin => !ctx.state.excluded.includes(plugin.pluginId));
|
|
169
|
+
const candidates = installed.filter(plugin => plugin.enabled);
|
|
170
|
+
for (const id of ctx.alreadyLoaded)
|
|
171
|
+
if (!candidates.some(plugin => plugin.pluginId === id))
|
|
172
|
+
ctx.alreadyLoaded.delete(id);
|
|
173
|
+
const matches = await consentedMatches({ ctx, candidates, input });
|
|
174
|
+
const result = await preparedGuidance({ ctx, matches, input });
|
|
175
|
+
rememberDelivery(ctx);
|
|
176
|
+
await publishUsage(ctx);
|
|
177
|
+
return withPluginNotes({ ctx, input, installed, candidates, result });
|
|
178
|
+
}
|
|
179
|
+
/** Appends the enabled-plugin catalog and the off-plugin note to the prepared guidance. */
|
|
180
|
+
function withPluginNotes({ ctx, input, installed, candidates, result }) {
|
|
181
|
+
// Preflight never resolves off packages implicitly. A catalog line offers an explicit read;
|
|
182
|
+
// its setup guidance may explain whether enabling or credentials are needed.
|
|
183
|
+
const off = offPluginNote(ctx, { catalog: installed, input });
|
|
184
|
+
const catalog = input.query !== undefined && !input.capabilities?.length ? enabledPluginCatalog({ ctx, candidates }) : '';
|
|
185
|
+
return [result, catalog, off].filter(Boolean).join('\n\n');
|
|
186
|
+
}
|
|
187
|
+
/** Rank enabled candidates, drop plugins this run already has, then apply the person's consent. */
|
|
188
|
+
async function consentedMatches({ ctx, candidates, input }) {
|
|
189
|
+
const ranked = rankCandidates({ candidates, input, ports: ctx.ports });
|
|
190
|
+
// Owner decision 2026-10-18: no per-chat plugin count; the relevance threshold and vendor gate decide.
|
|
191
|
+
const relevant = ranked.filter(plugin => !ctx.delivered.has(plugin.pluginId) && !input.loaded?.includes(plugin.pluginId) && (!ctx.alreadyLoaded.has(plugin.pluginId) || !!input.query));
|
|
192
|
+
return applyConsent({ ctx, matches: relevant }, { signal: input.signal });
|
|
193
|
+
}
|
|
194
|
+
/** Capability calls resolve every match; a query resolves the top and required providers. */
|
|
195
|
+
async function preparedGuidance({ ctx, matches, input }) {
|
|
196
|
+
const shouldLoad = !!input.capabilities?.length;
|
|
197
|
+
const primary = primaryMatch({ ctx, matches, input });
|
|
198
|
+
return shouldLoad ? (await resolveGuidance({ ctx, matches }, { signal: input.signal })).join('\n\n') : (await resolveGuidance({ ctx, matches: primary }, { budget: MAX_QUERY_GUIDANCE_BYTES, signal: input.signal })).join('\n\n');
|
|
199
|
+
}
|
|
200
|
+
/** The top match and required providers a fresh, unbounded query preflight delivers in full; otherwise none. */
|
|
201
|
+
function primaryMatch({ ctx, matches, input }) {
|
|
202
|
+
if (!(input.maxPromptArgBytes === undefined && input.query && !input.loaded?.length && !ctx.alreadyLoaded.has(matches[0]?.pluginId ?? '')))
|
|
203
|
+
return [];
|
|
204
|
+
const [top, ...rest] = matches;
|
|
205
|
+
if (!top)
|
|
206
|
+
return [];
|
|
207
|
+
const required = rest.filter(plugin => !ctx.alreadyLoaded.has(plugin.pluginId) && plugin.provides?.some(capability => top.requires?.includes(capability)));
|
|
208
|
+
return [top, ...required].slice(0, 3);
|
|
209
|
+
}
|
|
210
|
+
/** Rank readable metadata for off plugins; never load their tools or guidance implicitly. O(p*t). */
|
|
211
|
+
function offPluginNote(ctx, { catalog, input }) {
|
|
212
|
+
if (!input.query)
|
|
213
|
+
return '';
|
|
214
|
+
const candidates = catalog.filter(plugin => !plugin.enabled).map(candidate => agentVisiblePluginCandidate({ candidate }));
|
|
215
|
+
return ctx.ports.rank({ query: input.query, candidates, limit: 10 }, {}).map(plugin => [plugin.description,
|
|
216
|
+
ctx.ports.formatPluginToolPointer?.({ pluginId: plugin.pluginId, file: 'SKILL.md' })].filter(Boolean).join(' ')).join('\n');
|
|
217
|
+
}
|
|
218
|
+
/** Admit one explicit id using the same catalog, consent, resolver and delivery state as prepare.
|
|
219
|
+
* No activation writes; unavailable guidance is retryable. O(p) local catalog lookup.
|
|
220
|
+
*/
|
|
221
|
+
async function load(ctx, { pluginId, signal, ...request }, _options = {}) {
|
|
222
|
+
if (ctx.mode === 'off' && !ctx.alreadyLoaded.has(pluginId))
|
|
223
|
+
return { status: 'off', guidance: '' };
|
|
224
|
+
if (signal?.aborted)
|
|
225
|
+
return { status: 'cancelled', guidance: '' };
|
|
226
|
+
if (ctx.state.excluded.includes(pluginId))
|
|
227
|
+
return { status: 'excluded', guidance: '' };
|
|
228
|
+
const plugin = (await ctx.ports.list({}, {})).find(candidate => candidate.pluginId === pluginId);
|
|
229
|
+
if (!plugin)
|
|
230
|
+
return { status: 'missing', guidance: '' };
|
|
231
|
+
return loadPermitted(ctx, { plugin, ...request }, { signal });
|
|
232
|
+
}
|
|
233
|
+
/** The plugin's own SKILL.md, whether defaulted or named explicitly. O(1). */
|
|
234
|
+
function isPrimaryInstructions(ctx, { pluginId, skill, file }, _options = {}) {
|
|
235
|
+
return (skill === undefined || skill === pluginId) && (file === undefined || file === 'SKILL.md');
|
|
236
|
+
}
|
|
237
|
+
/** Requested content bypasses only deduplication, never consent or the resolver's trust checks.
|
|
238
|
+
* Only the primary SKILL.md records full plugin delivery. O(p) consent filtering plus one read.
|
|
239
|
+
*/
|
|
240
|
+
async function loadPermitted(ctx, { plugin, ...request }, { signal } = {}) {
|
|
241
|
+
const matches = await applyConsent({ ctx, matches: [{ ...plugin, score: 4 }] }, { signal });
|
|
242
|
+
if (!matches.length) {
|
|
243
|
+
await publishUsage(ctx);
|
|
244
|
+
return { status: 'excluded', guidance: '' };
|
|
245
|
+
}
|
|
246
|
+
let result = await resolveOneGuidance(ctx, { plugin, ...request }, { signal });
|
|
247
|
+
if (!plugin.enabled && result.status === 'loaded') {
|
|
248
|
+
result = { status: 'installed-but-inactive', guidance: `Plugin '${plugin.pluginId}' is off; its tools are unavailable.\n\n${result.guidance}` };
|
|
247
249
|
}
|
|
250
|
+
if (isPrimaryInstructions(ctx, { pluginId: plugin.pluginId, ...request }))
|
|
251
|
+
recordDelivery({ ctx, plugin, result });
|
|
252
|
+
rememberDelivery(ctx);
|
|
253
|
+
await publishUsage(ctx);
|
|
254
|
+
return result;
|
|
255
|
+
}
|
|
256
|
+
/** Share one queue between preflight, explicit reads and simultaneous guarded writes. */
|
|
257
|
+
function enqueue({ ctx, operation }) {
|
|
258
|
+
const next = ctx.queue.then(operation);
|
|
259
|
+
ctx.queue = next.catch(() => undefined);
|
|
260
|
+
return next;
|
|
261
|
+
}
|
|
262
|
+
/** Create one run's preparation owner. Calls serialize so parallel tool writes share one question.
|
|
263
|
+
* @param required Host effects and the person's mode; browser state is advisory selection only.
|
|
264
|
+
* @returns prepare(): a relevance note or capability guidance; load(): a truthful admission/delivery outcome.
|
|
265
|
+
* @complexity O(p*t) ranking plus at most one resolve per admitted plugin; relevance, not a count, bounds it.
|
|
266
|
+
* @example const use = createAutomaticAgentPluginUse({ mode: 'auto', ports });
|
|
267
|
+
*/
|
|
268
|
+
export function createAutomaticAgentPluginUse({ mode, state: initialState, ports }, _options = {}) {
|
|
269
|
+
const state = readChatAgentPluginState({ value: initialState });
|
|
270
|
+
const ctx = {
|
|
271
|
+
mode, state, ports, delivered: new Map(), publishedSize: undefined, queue: Promise.resolve(),
|
|
272
|
+
alreadyLoaded: new Set(mode === 'off' ? [] : state.decision?.delivered?.filter(id => !state.excluded.includes(id))),
|
|
273
|
+
};
|
|
248
274
|
return {
|
|
249
|
-
guidanceIds: (_required, _options = {}) => [...new Set([...alreadyLoaded, ...delivered.keys()])].filter(id => !state.excluded.includes(id)),
|
|
275
|
+
guidanceIds: (_required, _options = {}) => [...new Set([...ctx.alreadyLoaded, ...ctx.delivered.keys()])].filter(id => !ctx.state.excluded.includes(id)),
|
|
250
276
|
/** Suggest relevant metadata for a query; capability calls load only their providers. */
|
|
251
|
-
prepare: (input, _options = {}) => enqueue({ operation: () => prepare(input) }),
|
|
277
|
+
prepare: (input, _options = {}) => enqueue({ ctx, operation: () => prepare({ ctx, input }) }),
|
|
252
278
|
/** Resolve one active, permitted id and publish usage only after real guidance is read.
|
|
253
279
|
* Returns a concrete status and delivered content or a safe explicit-request refusal.
|
|
254
280
|
* @example await controller.load({ pluginId: 'my-plugin' });
|
|
255
281
|
*/
|
|
256
|
-
load: (input, _options = {}) => enqueue({ operation: () => load(input) }),
|
|
282
|
+
load: (input, _options = {}) => enqueue({ ctx, operation: () => load(ctx, input) }),
|
|
257
283
|
};
|
|
258
284
|
}
|
|
259
285
|
//# sourceMappingURL=automatic-use.js.map
|
|
@@ -15,19 +15,82 @@ export interface InstalledDigestIdentity {
|
|
|
15
15
|
readonly pluginId: string;
|
|
16
16
|
readonly archiveDigest: string;
|
|
17
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* Validates an already-`JSON.parse`d ledger value, dropping anything that does not match the shape.
|
|
20
|
+
* Pure, so the parsing rules are assertable without touching a filesystem.
|
|
21
|
+
*
|
|
22
|
+
* @complexity O(p) in the entry count.
|
|
23
|
+
*/
|
|
24
|
+
declare function normalizeBundledDigests(value: unknown): BundledAgentPluginDigests;
|
|
25
|
+
/**
|
|
26
|
+
* Records the digest this boot seeded for each bundled plugin, merged over whatever was already
|
|
27
|
+
* recorded.
|
|
28
|
+
*
|
|
29
|
+
* MERGED, not replaced, for failure isolation (the property `seed-bundled.ts`'s header names): a
|
|
30
|
+
* plugin that failed to seed this boot — an unreadable source directory, a transient I/O fault —
|
|
31
|
+
* must not lose the perfectly good entry an earlier boot wrote for it, which is what a wholesale
|
|
32
|
+
* rewrite of only this boot's successes would do.
|
|
33
|
+
*
|
|
34
|
+
* A plugin id seeded TWICE in one run under two different digests (two bundled source directories
|
|
35
|
+
* declaring the same manifest `name`) is dropped from the ledger entirely, prior entry included:
|
|
36
|
+
* the build itself is ambiguous about what it ships, so there is nothing authoritative to record and
|
|
37
|
+
* the explicit ambiguity refusal downstream is the correct outcome.
|
|
38
|
+
*
|
|
39
|
+
* @param seeded - One entry per successfully seeded plugin. An empty list writes nothing at all —
|
|
40
|
+
* not even an empty file — so a boot that seeded nothing cannot create a workspace directory or
|
|
41
|
+
* truncate an existing ledger.
|
|
42
|
+
* @throws {Error} Any filesystem fault from the write. The caller (`seed-bundled.ts`) captures it
|
|
43
|
+
* into its report rather than failing the boot.
|
|
44
|
+
* @complexity One file read and one atomic write, O(p) in the recorded plugin count.
|
|
45
|
+
*/
|
|
46
|
+
declare function recordBundledAgentPluginDigests(ports: AgentPluginLifecyclePorts, required: {
|
|
47
|
+
readonly workspaceRoot: string;
|
|
48
|
+
readonly seeded: readonly SeededBundledAgentPluginDigest[];
|
|
49
|
+
readonly now?: ((required: Record<string, never>) => Date) | undefined;
|
|
50
|
+
}): Promise<void>;
|
|
51
|
+
/**
|
|
52
|
+
* Drops one plugin id from the ledger — for `retire-bundled.ts`, once a retired bundled plugin's
|
|
53
|
+
* packages are gone and no build will ever seed it again.
|
|
54
|
+
*
|
|
55
|
+
* Every other entry is kept byte-for-byte, `seededAt` included: this rewrites the raw `plugins` bag
|
|
56
|
+
* rather than the normalized map, so it cannot lose a field a later schema adds. A missing,
|
|
57
|
+
* unreadable, malformed, or wrong-version ledger, or one with no entry for `pluginId`, writes
|
|
58
|
+
* nothing — there is nothing to drop, and a fail-closed reader already treats such a file as empty.
|
|
59
|
+
*
|
|
60
|
+
* @returns Whether an entry was removed.
|
|
61
|
+
* @throws {Error} Any filesystem fault from the write. `retire-bundled.ts` captures it into its report.
|
|
62
|
+
* @complexity One file read and at most one atomic write, O(p) in the recorded plugin count.
|
|
63
|
+
*/
|
|
64
|
+
declare function removeBundledAgentPluginDigest(ports: AgentPluginLifecyclePorts, required: {
|
|
65
|
+
readonly workspaceRoot: string;
|
|
66
|
+
readonly pluginId: string;
|
|
67
|
+
}): Promise<boolean>;
|
|
68
|
+
/**
|
|
69
|
+
* Drops the SUPERSEDED installs of any bundled plugin id from a list of installed packages, leaving
|
|
70
|
+
* every other entry — and every other plugin id — exactly as it was.
|
|
71
|
+
*
|
|
72
|
+
* An id is narrowed only when all three hold: it has more than one installed digest, the ledger
|
|
73
|
+
* records a digest for it, and exactly one of its installed digests is that recorded one. Anything
|
|
74
|
+
* else passes through untouched, so the caller's own ambiguity refusal still fires for every case
|
|
75
|
+
* this module has no authority over (this file's header, consequences 1 and 2).
|
|
76
|
+
*
|
|
77
|
+
* Applied at READ time by the surfaces that must pick one package per plugin id. Deliberately NOT
|
|
78
|
+
* folded into `listInstalledPlugins` itself: `uninstall.ts` needs to see EVERY digest of a plugin to
|
|
79
|
+
* remove them, and a filter hidden inside the shared walk would make superseded bytes unremovable.
|
|
80
|
+
*
|
|
81
|
+
* @returns A list in the input's own order, with superseded entries removed. The input is never
|
|
82
|
+
* mutated.
|
|
83
|
+
* @complexity O(n) in the installed-package count, over one O(n) pre-pass that counts digests per
|
|
84
|
+
* plugin id.
|
|
85
|
+
*/
|
|
86
|
+
declare function preferBundledAgentPluginDigests<T extends InstalledDigestIdentity>(installed: readonly T[], bundled: BundledAgentPluginDigests): readonly T[];
|
|
18
87
|
/** Internal composition; one state/queue instance per injected host context. */
|
|
19
|
-
export declare function createBundledDigestsModule(ports: AgentPluginLifecyclePorts): {
|
|
88
|
+
export declare function createBundledDigestsModule(ports: AgentPluginLifecyclePorts, _optional?: Record<string, never>): {
|
|
20
89
|
readBundledAgentPluginDigests: (workspaceRoot: string) => Promise<BundledAgentPluginDigests>;
|
|
21
|
-
normalizeBundledDigests:
|
|
22
|
-
recordBundledAgentPluginDigests: (required:
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
readonly now?: ((required: Record<string, never>) => Date) | undefined;
|
|
26
|
-
}) => Promise<void>;
|
|
27
|
-
removeBundledAgentPluginDigest: (required: {
|
|
28
|
-
readonly workspaceRoot: string;
|
|
29
|
-
readonly pluginId: string;
|
|
30
|
-
}) => Promise<boolean>;
|
|
31
|
-
preferBundledAgentPluginDigests: <T extends InstalledDigestIdentity>(installed: readonly T[], bundled: BundledAgentPluginDigests) => readonly T[];
|
|
90
|
+
normalizeBundledDigests: typeof normalizeBundledDigests;
|
|
91
|
+
recordBundledAgentPluginDigests: (required: Parameters<typeof recordBundledAgentPluginDigests>[1]) => Promise<void>;
|
|
92
|
+
removeBundledAgentPluginDigest: (required: Parameters<typeof removeBundledAgentPluginDigest>[1]) => Promise<boolean>;
|
|
93
|
+
preferBundledAgentPluginDigests: typeof preferBundledAgentPluginDigests;
|
|
32
94
|
};
|
|
95
|
+
export {};
|
|
33
96
|
//# sourceMappingURL=bundled-digests.d.ts.map
|