@jini-ai/plugins 0.6.22 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/CHANGELOG.md +54 -0
  2. package/dist/host/admin-response.d.ts +93 -0
  3. package/dist/host/admin-response.js +32 -0
  4. package/dist/host/capability-tools.d.ts +369 -0
  5. package/dist/host/capability-tools.js +306 -0
  6. package/dist/host/declarative-content-types.d.ts +245 -0
  7. package/dist/host/declarative-content-types.js +270 -0
  8. package/dist/host/index.d.ts +3 -0
  9. package/dist/host/index.js +3 -0
  10. package/dist/host/manifest.d.ts +1 -4
  11. package/dist/host/manifest.js +2 -5
  12. package/dist/host/node/archive-policy.d.ts +57 -0
  13. package/dist/host/node/archive-policy.js +115 -0
  14. package/dist/host/node/index.d.ts +3 -0
  15. package/dist/host/node/index.js +3 -0
  16. package/dist/host/node/install.d.ts +1 -4
  17. package/dist/host/node/install.js +2 -8
  18. package/dist/host/node/invocation-binding.d.ts +45 -0
  19. package/dist/host/node/invocation-binding.js +69 -0
  20. package/dist/host/node/runtime-core.d.ts +273 -0
  21. package/dist/host/node/runtime-core.js +613 -0
  22. package/dist/host/node/source-drafts.d.ts +1 -5
  23. package/dist/host/node/source-drafts.js +2 -8
  24. package/dist/host/plugin-claims.d.ts +2 -1
  25. package/dist/host/plugin-claims.js +1 -1
  26. package/dist/host/plugin-format.d.ts +4 -0
  27. package/dist/host/plugin-format.js +4 -0
  28. package/dist/host/plugin-tool-errors.d.ts +11 -0
  29. package/dist/host/plugin-tool-errors.js +19 -0
  30. package/dist/host/tools/contract.d.ts +397 -0
  31. package/dist/host/tools/contract.js +7 -0
  32. package/dist/host/tools/index.d.ts +7 -0
  33. package/dist/host/tools/index.js +6 -0
  34. package/dist/host/tools/install.d.ts +12 -0
  35. package/dist/host/tools/install.js +71 -0
  36. package/dist/host/tools/management.d.ts +51 -0
  37. package/dist/host/tools/management.js +607 -0
  38. package/dist/host/tools/source.d.ts +14 -0
  39. package/dist/host/tools/source.js +95 -0
  40. package/dist/host/worker/index.d.ts +1 -0
  41. package/dist/host/worker/index.js +1 -0
  42. package/dist/host/worker/start.d.ts +44 -0
  43. package/dist/host/worker/start.js +31 -0
  44. package/package.json +16 -9
package/CHANGELOG.md CHANGED
@@ -1,5 +1,59 @@
1
1
  # @jini-ai/plugins
2
2
 
3
+ ## 0.7.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [873f10c]
8
+ - @jini-ai/core@0.7.1
9
+
10
+ ## 0.7.0
11
+
12
+ ### Minor Changes
13
+
14
+ - 01b36f2: Publish the declarative content-type rules on `@jini-ai/plugins/host`:
15
+ `createDeclarativeContentTypes({ cms, reservedKeys }, {})` returns `validateManifest`, `parse`,
16
+ `plan` and `apply` (usable as `DeclarativeContentTypesPort`), with the `DeclaredContentTypeCms`
17
+ vocabulary contract, `DeclaredContentTypeWritePorts`, the concrete `DeclaredContentTypeDefinition`
18
+ / `DeclaredContentTypeDefinitionPlan` shapes and the `MAX_DECLARED_*` bounds. Hosts supply their
19
+ field kinds, kind checks, identifier grammar, already-exists classifier and reserved keys; the
20
+ package imports no content-type implementation.
21
+ - ecefd45: Publish the plugin capability-tool registrar on `@jini-ai/plugins/host`:
22
+ `createPluginCapabilityTools(required, {})` returns `loadSources`, `buildRegistrations` and
23
+ `registerEnabled` for one read-only `plugin_capability_<id>` tool per enabled, field-declaring
24
+ plugin, plus `pluginCapabilityToolDerivedRisk({ sources }, {})`. Hosts supply the identity
25
+ namespace, every model-facing sentence (`PluginCapabilityToolText`), the catalog domain, path and
26
+ metadata, the read permission and entity scope (one object, published and enforced), the
27
+ executable-tool permission and metadata, the approval family and port, and the preview draft.
28
+ - 070fe2a: Publish the per-load plugin invocation binding on `@jini-ai/plugins/host/node`:
29
+ `createPluginInvocationBinding({ pluginId, declaredHooks, beforeSaveHook }, {})` returns the
30
+ `coreDeps` for `buildCapabilityScopedSdk()` and the captured beforeSave filter, with
31
+ `content.read`/`content.extend` bound to the running filter through one AsyncLocalStorage per load.
32
+ Hosts supply their SDK's beforeSave hook id; entry and filter types are the plugin-domain
33
+ envelope from `@jini-ai/plugins/host`.
34
+ - 7087c13: Add `toAdminPluginResponse({ discovery, activation }, { conflicts })` and `AdminPluginEnvelope` to
35
+ `@jini-ai/plugins/host`, the bounded `readPluginArchive({ archive, reader })` policy with a required
36
+ host `PluginArchiveReaderPort` to `@jini-ai/plugins/host/node`, and `startTier2Worker({ workerData,
37
+ parentPort, binding, registerSdkResolver, realImport }, { importModule })` to
38
+ `@jini-ai/plugins/host/worker` (no auto-start on import).
39
+ - 0f76f15: Add `createPluginRuntimeCore(required, optional)` and its port types (`PluginRuntimeSource`, `PluginRuntimeHostBinding`, `PluginRuntimeTracker`, `PluginRuntimeLookup`, `PluginRuntimeText`, `PluginRuntimeCoreRequired`/`Optional`/`Bindings`) plus `PluginUninstallPathError` to `@jini-ai/plugins/host/node`: the plugin runtime core (discovery, conflict gates, enable/load/attach, boot re-attach, provider admission, install/source/reload wiring) with every host value injected.
40
+ - 3932647: Add the node-only `/host/tools` entry for plugin management, installation and source registrations. Hosts supply catalogs, ids, permissions, descriptions, canonical cross-family operations, command and approval-fingerprint owners, authenticated confirmation transport, runtime copy and telemetry. Existing saved formats and lifecycle owners remain unchanged. This opt-in entry requires semver and @jini-ai/platform, as does `/host/node`.
41
+
42
+ ### Patch Changes
43
+
44
+ - Updated dependencies [8fe045b]
45
+ - Updated dependencies [c393010]
46
+ - Updated dependencies [41ff2ff]
47
+ - Updated dependencies [a266ba8]
48
+ - Updated dependencies [2364f89]
49
+ - Updated dependencies [27063ef]
50
+ - Updated dependencies [6ab1d81]
51
+ - Updated dependencies [699b478]
52
+ - Updated dependencies [39cf677]
53
+ - @jini-ai/core@0.7.0
54
+ - @jini-ai/platform@0.7.0
55
+ - @jini-ai/db@0.7.0
56
+
3
57
  ## 0.6.22
4
58
 
5
59
  - Enabling a tier-3 plugin always asks the owner, including a version approved before.
@@ -0,0 +1,93 @@
1
+ /**
2
+ * @file `toAdminPluginResponse()` — DTO mapping for the admin plugin list / set-enabled wire shape
3
+ * (SPEC-005 REQ-10, api.spec.md §5; C-017).
4
+ *
5
+ * Purpose:
6
+ * Projects a `PluginDiscoveryRecord` plus its (possibly absent) `PluginActivationRecord` into the
7
+ * exact `api.spec.md` §5 wire shape — `enabled` is the one field discovery itself does not know
8
+ * (state.spec.md §2: "enabled: boolean # projected from plugin_activations"); this function is
9
+ * where that projection happens (discovery.ts stays activation-ignorant by design).
10
+ *
11
+ * Architectural role:
12
+ * TDD-certified implementation (implementation outline C-017). `toAdminPluginResponse()` is a pure
13
+ * projection — no I/O — that folds discovery's `tier`/`status`/`errors` with activation's
14
+ * `enabled`/quarantine fields into the wire envelope. Routes, authorization and transport stay
15
+ * with the host.
16
+ */
17
+ import type { PluginActivationRecord } from "./activation.js";
18
+ import type { PluginDiscoveryRecord } from "./discovery-types.js";
19
+ import type { PluginConflict } from "./plugin-claims.js";
20
+ /**
21
+ * api.spec.md §5 per-plugin admin wire shape.
22
+ *
23
+ * @agent-note Key order is the serialized wire order; a host must send this object as returned
24
+ * (no re-keying) so saved/compared bytes stay identical.
25
+ */
26
+ export interface AdminPluginEnvelope {
27
+ readonly id: string;
28
+ readonly name: string;
29
+ readonly version: string;
30
+ readonly source: "built-in" | "site";
31
+ /** (1.1.2, REQ-10/REQ-18) Projected verbatim from `PluginDiscoveryRecord.tier`, itself projected
32
+ * verbatim from the plugin's already-required `PluginManifest.tier` (REQ-01/ADR-024 §1) — the
33
+ * same additive-field mechanism REQ-10's revision note describes ("mirroring how `enabled` is
34
+ * already projected"). Required at this wire-contract layer (api.spec.md §5 lists it as a plain,
35
+ * always-present field, consumed by REQ-18's per-row badge, AC-26).
36
+ *
37
+ * @agent-note A record without a tier is reported as `"tier-3"`. */
38
+ readonly tier: "tier-1" | "tier-2" | "tier-3";
39
+ readonly status: "valid" | "invalid" | "incompatible";
40
+ /** @agent-note Projected from the activation record; an absent record means disabled. */
41
+ readonly enabled: boolean;
42
+ /** @agent-note Non-null only when the activation record carries all three quarantine fields. */
43
+ readonly quarantine: null | {
44
+ readonly at: string;
45
+ readonly reason: string;
46
+ readonly consecutiveFailures: number;
47
+ };
48
+ readonly errors: readonly {
49
+ code: string;
50
+ file: string | null;
51
+ message: string;
52
+ }[];
53
+ /** (2026-10-04) Names this plugin claims that core or an earlier-enabled plugin already holds —
54
+ * for an enabled plugin, why it was refused; for one that is off, what turning it on would hit.
55
+ * Always present (empty when clear), so the admin row and the list tool need no absent case.
56
+ *
57
+ * @agent-note The host supplies this plugin's own conflict entry (for example from
58
+ * `listPluginConflicts()`); omitted means none. */
59
+ readonly conflicts: readonly PluginConflict[];
60
+ /** (2026-10-26) Present (true) only when the plugin's manifest declares provider settings — the
61
+ * host's admin row then offers its settings card. Absent otherwise.
62
+ *
63
+ * @agent-note Absent rather than `false`; hosts must not add the key themselves. */
64
+ readonly providerSettings?: true;
65
+ }
66
+ /**
67
+ * Required inputs of {@link toAdminPluginResponse}.
68
+ *
69
+ * @agent-note Both records belong to the same plugin id; the host reads them (one discovery pass,
70
+ * one activation read) and this function never re-reads either.
71
+ */
72
+ export interface ToAdminPluginResponseRequired {
73
+ /** One plugin's discovery-time record (source/status/errors). */
74
+ readonly discovery: PluginDiscoveryRecord;
75
+ /** That plugin's persisted activation row, or `null` when it has never been enabled (treated as
76
+ * disabled — `enabled: false`, not an error). */
77
+ readonly activation: PluginActivationRecord | null;
78
+ }
79
+ /** Optional inputs of {@link toAdminPluginResponse}. */
80
+ export interface ToAdminPluginResponseOptional {
81
+ /** This plugin's entry from `listPluginConflicts()`, if any. */
82
+ readonly conflicts?: readonly PluginConflict[];
83
+ }
84
+ /**
85
+ * Projects one discovery record + its (possibly absent, meaning "never enabled") activation
86
+ * record into the wire shape. Pure — no I/O.
87
+ *
88
+ * @agent-note Pure and synchronous: no I/O, no shared state, safe per call from any host route or
89
+ * agent tool. Never throws for a well-typed input. The host owns the route, authorization and
90
+ * transport; this function only shapes the envelope.
91
+ */
92
+ export declare function toAdminPluginResponse(required: ToAdminPluginResponseRequired, optional?: ToAdminPluginResponseOptional): AdminPluginEnvelope;
93
+ //# sourceMappingURL=admin-response.d.ts.map
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Projects one discovery record + its (possibly absent, meaning "never enabled") activation
3
+ * record into the wire shape. Pure — no I/O.
4
+ *
5
+ * @agent-note Pure and synchronous: no I/O, no shared state, safe per call from any host route or
6
+ * agent tool. Never throws for a well-typed input. The host owns the route, authorization and
7
+ * transport; this function only shapes the envelope.
8
+ */
9
+ export function toAdminPluginResponse(required, optional = {}) {
10
+ const { discovery, activation } = required;
11
+ return {
12
+ id: discovery.id,
13
+ name: discovery.name,
14
+ version: discovery.version,
15
+ source: discovery.source,
16
+ tier: (discovery.tier ?? "tier-3"),
17
+ status: discovery.status,
18
+ enabled: activation?.enabled ?? false,
19
+ quarantine: quarantineResponse({ activation }),
20
+ errors: discovery.errors,
21
+ conflicts: optional.conflicts ?? [],
22
+ ...((discovery.manifest?.contributes?.providers ?? []).some((provider) => (provider.settings?.length ?? 0) > 0) ? { providerSettings: true } : {}),
23
+ };
24
+ }
25
+ /** Partial activation metadata is not a quarantine in the admin wire contract. */
26
+ function quarantineResponse({ activation }, _options = {}) {
27
+ if (activation?.quarantinedAt !== undefined && activation.quarantineReason !== undefined && activation.quarantineFailureCount !== undefined) {
28
+ return { at: activation.quarantinedAt, reason: activation.quarantineReason, consecutiveFailures: activation.quarantineFailureCount };
29
+ }
30
+ return null;
31
+ }
32
+ //# sourceMappingURL=admin-response.js.map
@@ -0,0 +1,369 @@
1
+ import { type DerivedRiskByToolId, type ToolRegistration, type ToolRegistry, type LegacyToolAuthorizeFn, type ToolMetadata, type ToolMetadataById } from "@jini-ai/core";
2
+ import type { JsonObject } from "@jini-ai/core/primitives";
3
+ import type { PluginContributionRegistry } from "./contributions.js";
4
+ import type { PluginActivationRepoPort } from "./activation.js";
5
+ import type { PluginDiscoveryRecord } from "./discovery-types.js";
6
+ import type { PluginManifestFieldDecl } from "./manifest-types.js";
7
+ /**
8
+ * @file Projects each ENABLED plugin-runtime plugin's own declared `fields[]` (manifest.ts,
9
+ * SPEC-005 REQ-06) into one real, `search_tools`-discoverable tool per plugin — the fix for the
10
+ * 2026-08-26 registration-gap audit (`ADS-memory/reports/2026-08-26-plugin-discoverability-audit.md`):
11
+ * a live, valid, tier-3 Word Count plugin was computing and storing a real per-post word count on
12
+ * every save, yet no agent-callable tool anywhere ever exposed it, so `search_tools` correctly
13
+ * returned nothing for "compute word count or reading time statistics for post content" — a
14
+ * registration gap, not a ranking or selection miss.
15
+ *
16
+ * ---------------------------------------------------------------------------
17
+ * Why THIS shape and not the other two the dispatch offered
18
+ * ---------------------------------------------------------------------------
19
+ * Historical field-read decision: the 2026-10-09 owner dispatch now authorizes executable tools
20
+ * through this SAME registrar; these reasons still explain why field-read tools retain their
21
+ * separate contract. The generic executable registration owner is Jini plugins/host.
22
+ *
23
+ * (1) "Plugins declare invocable tools" was rejected as the bigger, contract-changing option: v1's
24
+ * entire capability vocabulary (`Jini/packages/plugins/src/host/manifest.ts`'s `VALID_CAPABILITIES`/`VALID_HOOKS`) has no notion of
25
+ * "expose a callable function" at all, and inventing one — arbitrary handler code a plugin author
26
+ * supplies, executed inside the agent's tool-call path — is a real security/sandboxing question this
27
+ * dispatch's time-box cannot responsibly answer.
28
+ * (3) "Discoverable but not invocable" (a catalog entry that only explains a capability exists) was
29
+ * rejected because the owner's own repro ("is there a way to count words in posts?") needed a real
30
+ * ANSWER, not a pointer — a tool the agent cannot actually call would leave it exactly where it
31
+ * started, manually counting words with Bash.
32
+ * This file is (2): a plugin's already-written, already-durable `ext.{pluginId}.*` output becomes
33
+ * READABLE through one native, read-only tool per plugin — no new execution surface, no new
34
+ * capability vocabulary, just a read path onto data that already exists (`post.ts`'s `ext` field).
35
+ *
36
+ * ---------------------------------------------------------------------------
37
+ * One tool PER PLUGIN, not per field (mirrors `agent-plugins/tool-registrations.ts`'s own
38
+ * one-tool-per-plugin collapse, same rationale: crowding `search_tools`' result slots one field at a
39
+ * time does not scale, and a plugin's fields are typically one cohesive capability anyway).
40
+ * ---------------------------------------------------------------------------
41
+ * Tool id: `plugin_capability_<pluginId>` (hyphens folded to underscores, matching
42
+ * `agent_plugin_<pluginId>`'s own scheme) — deliberately NOT `plugins_*` (already
43
+ * the host's plugin-management tools, which this is not) and NOT `plugin_*` bare
44
+ * (would read as belonging to the Agent Plugins family). Checked against every existing catalog's
45
+ * ids (`grep -rn 'name: "[a-z_]*"' src/**\/agent-tools.ts src/**\/*tool-registrations.ts`) before
46
+ * choosing it — no collision today. `@jini-ai/core`'s `createToolRegistry().register()` throws on a
47
+ * duplicate id at registration time regardless (verified by reading `tool-registry.ts`), so a future
48
+ * collision fails loudly at boot rather than silently shadowing a native tool — this module does not
49
+ * need to (and does not) reimplement that guard.
50
+ *
51
+ * ---------------------------------------------------------------------------
52
+ * The description text IS the fix — folds each field's own manifest-declared, action-oriented
53
+ * `description` (see `Jini/packages/plugins/src/host/manifest.ts`'s `PluginManifestFieldDecl.description`, added alongside this
54
+ * file) into one tool description. A plugin with no authored field description still gets a tool —
55
+ * degraded to a generic, weaker description ({@link PluginCapabilityToolText.genericFieldDescription}) rather than no tool at
56
+ * all, the same graceful-degradation shape `agent-plugins/tool-registrations.ts`'s
57
+ * `extractFallbackSummary` already uses for a skill with no frontmatter.
58
+ *
59
+ * ---------------------------------------------------------------------------
60
+ * Activation gate — the OPPOSITE default from Agent Plugins, and that is a real, disclosed decision
61
+ * ---------------------------------------------------------------------------
62
+ * `features/agent-plugins/activation.ts` treats an absent activation record as ACTIVE ("presence
63
+ * implies consent"). Plugin-runtime's own projection (`admin-response.ts`: `enabled: activation?.
64
+ * enabled ?? false`) is the opposite: absent means DISABLED. This loader follows plugin-runtime's own
65
+ * convention, not the Agent Plugins one it sits next to — a disabled plugin's `content.entry.
66
+ * beforeSave` hook never fires (`Jini/packages/plugins/src/host/hook-registry.ts`), so its `ext` data (if any survives from when it
67
+ * was last enabled, INV-03) is not being kept fresh. Advertising that as a live capability would be a
68
+ * new bug this file exists to avoid, not fix. Only `status: "valid"` AND `activation.enabled === true`
69
+ * plugins are ever projected into a tool source — verified by both an enabled-plugin test and a
70
+ * disabled-plugin (absent-activation) test in this file's own unit suite.
71
+ *
72
+ * ---------------------------------------------------------------------------
73
+ * Revocation — the activation gate runs AGAIN on every call (t91 F1.2, 2026-09-16)
74
+ * ---------------------------------------------------------------------------
75
+ * The loader above runs once, at daemon boot, and `@jini-ai/core`'s `ToolRegistry` is append-only, so
76
+ * a plugin disabled, quarantined or uninstalled afterwards used to keep a callable tool until restart.
77
+ * Every registration built here therefore carries a `ToolPolicy` that re-reads the activation row
78
+ * before the handler can be reached (`withActivationGate`), mirroring `agent-plugins/
79
+ * tool-registrations.ts`'s REVOCATION note: a refused call ends as `denied` in the daemon audit, and a
80
+ * read that throws also denies (and is logged). Boot filter and per-call gate share one predicate,
81
+ * `isPluginEnabledInWorkspace`, so they cannot drift. The tool stays LISTED until restart; enabling a
82
+ * plugin that was disabled at boot still needs a restart, because there is no registration to re-admit.
83
+ *
84
+ * ---------------------------------------------------------------------------
85
+ * Fresh results for Tier-2 plugins (AW-7 Tier 2, 2026-10-04)
86
+ * ---------------------------------------------------------------------------
87
+ * A stored `ext` value is only as fresh as the post's last save, so "analyze this page" used to answer
88
+ * with whatever the plugin computed then. A tier-2 plugin with a filter on the host's before-save hook
89
+ * ({@link PluginCapabilityToolSource.runsFresh}) now runs again on the post as stored, through the
90
+ * optional `previewPluginBeforeSave` port: the same hook-registry preview the admin editor's
91
+ * "Analyze now" uses, so the code runs in a fresh worker and nothing is saved or counted toward
92
+ * quarantine. Still ONE tool per plugin (no second "analyze" tool competing in `search_tools`).
93
+ * Without the port, or when this process has not attached the plugin, it reads the stored values as
94
+ * before. Tier-3 plugins keep reading stored values: their filter runs in-process, and this change
95
+ * was scoped to the worker-isolated tier. `ExtPatch` is scalar-only, so a plugin stores structured
96
+ * output (content-analyzer's `report`) as a JSON string; {@link decodeFieldValue} hands it back
97
+ * parsed instead of as JSON inside JSON.
98
+ *
99
+ * Architectural role:
100
+ * The host's plugin-runtime domain declaration, alongside (not replacing) the host's static
101
+ * management tool registrations — this file's tool ids
102
+ * are dynamic (learned only by awaiting `discoverPlugins()` + `pluginActivationRepo`), the same
103
+ * reason `agent-plugins/tool-registrations.ts` is not a synchronous `ToolContributor` either. Called
104
+ * once from `agent-daemon-server.ts`'s `start()`, immediately before `buildToolCatalogQuery` snapshots
105
+ * the registry into a one-shot FTS index — see that call site's own comment for why placement there
106
+ * (not before) makes a registered-late tool invisible to `search_tools`.
107
+ *
108
+ * Seam (2026-11-09): the registrar algorithm lives here; every permission name, entity scope, identity
109
+ * namespace, catalog path, metadata, approval family and model-facing sentence is a required host input
110
+ * of {@link createPluginCapabilityTools}. The host keeps its old module as a thin binder.
111
+ */
112
+ /** Model-facing prose for the capability tools. Every sentence is host wording.
113
+ * @agent-note Second-host rules: the host owns all of this text, including tool names it mentions
114
+ * and any example values. Members are pure, synchronous and called detached; each must return a
115
+ * non-empty string. The registrar only concatenates the results in the documented order and never
116
+ * inspects them, so a host that changes wording changes no behavior. */
117
+ export interface PluginCapabilityToolText {
118
+ /** @agent-note Fallback field description when the manifest field has none. Never empty. */
119
+ readonly genericFieldDescription: (required: {
120
+ pluginName: string;
121
+ path: string;
122
+ type: PluginManifestFieldDecl["type"];
123
+ }, optional?: Record<string, never>) => string;
124
+ /** @agent-note Appended after the space-joined field descriptions; `terms` is the identity id,
125
+ * keywords and provides joined with single spaces, read through `identityNamespace`. */
126
+ readonly discovery: (required: {
127
+ terms: string;
128
+ }, optional?: Record<string, never>) => string;
129
+ /** @agent-note Description of a tool that runs the plugin's before-save filter now (tier-2 with
130
+ * that hook). `fieldText` is the field descriptions plus the discovery suffix. */
131
+ readonly freshDescription: (required: {
132
+ pluginName: string;
133
+ fieldText: string;
134
+ }, optional?: Record<string, never>) => string;
135
+ /** @agent-note Description of a tool that reads stored values. Same `fieldText` as above. */
136
+ readonly storedDescription: (required: {
137
+ pluginName: string;
138
+ fieldText: string;
139
+ }, optional?: Record<string, never>) => string;
140
+ /** @agent-note The `postId` input property's description in the published input schema. */
141
+ readonly postIdDescription: string;
142
+ /** @agent-note Result `note` when no declared field has a value; added only in that case. */
143
+ readonly noDataNote: (required: {
144
+ pluginName: string;
145
+ }, optional?: Record<string, never>) => string;
146
+ /** @agent-note Message of the `ToolInputError` thrown when a fresh run fails. The original error
147
+ * stays on `cause`; the model sees only this text. It must not claim a write happened. */
148
+ readonly previewFailed: (required: {
149
+ pluginName: string;
150
+ postId: string;
151
+ }, optional?: Record<string, never>) => string;
152
+ /** @agent-note Warning logged through `console.warn` when the per-call activation read throws and
153
+ * the call is denied. `detail` is the error message, or `String(value)` for a non-Error. */
154
+ readonly activationReadDenied: (required: {
155
+ pluginId: string;
156
+ detail: string;
157
+ }, optional?: Record<string, never>) => string;
158
+ }
159
+ /** The permission and authorization entity a capability tool call needs.
160
+ * @agent-note Second-host rules: this ONE object is both published on the catalog entry
161
+ * (`authorization.permission`) and checked by the handler (`permission` with `entityType` and the
162
+ * call's post id), so the advertised and enforced permission cannot drift. The host owns the names. */
163
+ export interface PluginCapabilityToolAccess {
164
+ /** @agent-note Host permission name; published and enforced. */
165
+ readonly permission: string;
166
+ /** @agent-note Host authorization entity type for the post being read; the entity id is the input `postId`. */
167
+ readonly entityType: string;
168
+ }
169
+ /** Authority for executable plugin contribution tools attached through the same registrar.
170
+ * @agent-note Second-host rules: checked on every call with the plugin id as entity id, after the
171
+ * live activation check; `metadata` is the host's approval metadata for arbitrary plugin code and is
172
+ * passed unchanged to `attachPluginContributionTools`. A grant resolves to admin access. */
173
+ export interface PluginCapabilityExecutableAccess {
174
+ /** @agent-note Host permission required to call an executable plugin tool. */
175
+ readonly permission: string;
176
+ /** @agent-note Host authorization entity type; the entity id is the plugin id. */
177
+ readonly entityType: string;
178
+ /** @agent-note Host tool metadata (approval class/confirmation) for executable plugin tools. */
179
+ readonly metadata: ToolMetadata;
180
+ }
181
+ /** The minimum a stored post must carry for the capability tools.
182
+ * @agent-note Read-only view: the registrar reads `id` and `ext[pluginId]` and never writes a post. */
183
+ export interface PluginCapabilityPost {
184
+ /** @agent-note Post id echoed into the result payload. */
185
+ readonly id: string;
186
+ /** @agent-note Plugin-namespaced stored values, `{ [pluginId]: { [fieldKey]: value } }`. */
187
+ readonly ext?: JsonObject;
188
+ }
189
+ /** Host read port for one post.
190
+ * @agent-note Second-host rules: read-only; must throw the host's own not-found error for an
191
+ * unknown id (it propagates unchanged). Called once per tool call, after the permission check. */
192
+ export interface PluginCapabilityPostReadPort<TPost extends PluginCapabilityPost> {
193
+ /** @agent-note Reads one post in the caller's workspace; never writes. */
194
+ readRequired(input: {
195
+ workspaceId: string;
196
+ id: string;
197
+ }, options?: Record<string, never>): Promise<TPost>;
198
+ }
199
+ /** Runs ONE attached plugin's before-save filter on a draft without saving.
200
+ * @agent-note Existing positional plugin callback ABI, kept as is. Second-host rules: must write
201
+ * nothing, count nothing toward quarantine, and resolve `null` when this process has not attached
202
+ * the plugin (the stored values are then read). A rejection becomes `text.previewFailed`. */
203
+ export type PluginCapabilityPreviewPort<TDraft> = (pluginId: string, entry: TDraft) => Promise<Readonly<Record<string, unknown>> | null>;
204
+ /** Applies the host's extension approval policy to one built registration.
205
+ * @agent-note Second-host rules: called once per registration AFTER the activation gate is
206
+ * wrapped, with the host-supplied `approvalFamily`; must return a registration for the same id. */
207
+ export type PluginCapabilityApprovalPort<TFamily extends string> = (required: {
208
+ registration: ToolRegistration;
209
+ family: TFamily;
210
+ }, optional?: Record<string, never>) => ToolRegistration;
211
+ /** One resolved, already-namespace-parsed `ext.{pluginId}.*` field this tool can read back.
212
+ * @agent-note Built only from a `status: "valid"` manifest; no host input. */
213
+ export interface PluginCapabilityFieldSource {
214
+ /** The full manifest-declared path, e.g. `"ext.word-count.count"`.
215
+ * @agent-note Manifest data, already validated; no host input. */
216
+ readonly path: string;
217
+ /** The key this field is stored under inside `post.ext[pluginId]` — `path` with the
218
+ * `ext.{pluginId}.` prefix stripped (e.g. `"count"`). Namespacing is already enforced by
219
+ * `Jini/packages/plugins/src/host/manifest.ts`'s `validateField` before a record can ever reach `status: "valid"`, so this is a
220
+ * plain slice, not a re-validation.
221
+ * @agent-note Key of this field in the result payload's `fields` object. */
222
+ readonly fieldKey: string;
223
+ /** @agent-note Manifest field type, passed to the host's generic description only. */
224
+ readonly type: PluginManifestFieldDecl["type"];
225
+ /** Action-oriented, human-authored text when the manifest supplies one; otherwise
226
+ * {@link PluginCapabilityToolText.genericFieldDescription}'s weaker fallback. Never empty.
227
+ * @agent-note Plugin-authored or host-worded text; indexed for tool search. */
228
+ readonly description: string;
229
+ }
230
+ /** One enabled plugin's tool-ready source — everything {@link PluginCapabilityTools.buildRegistrations}
231
+ * needs to mint one real `ToolRegistration`, with nothing left for the handler to (re)compute from
232
+ * raw discovery/activation state at call time.
233
+ * @agent-note `id` is {@link capabilityToolIdFor}'s saved `plugin_capability_<id>` derivation, the
234
+ * same id the conflict detector claims; hosts must not re-derive it. */
235
+ export interface PluginCapabilityToolSource {
236
+ /** @agent-note Saved tool id; see the interface note. */
237
+ readonly id: string;
238
+ /** @agent-note Activation key re-read on every call. */
239
+ readonly pluginId: string;
240
+ /** @agent-note Manifest display name handed to the host's text members. */
241
+ readonly pluginName: string;
242
+ /** @agent-note Host-worded model-facing description, built once at load. */
243
+ readonly description: string;
244
+ /** @agent-note Declared fields in manifest order; the result payload follows this order. */
245
+ readonly fields: readonly PluginCapabilityFieldSource[];
246
+ /** A tier-2 plugin with a filter on the host-supplied `beforeSaveHook`: each call runs that filter on the
247
+ * stored post through `PluginCapabilityToolDeps.previewPluginBeforeSave` — see this file's header,
248
+ * "Fresh results for Tier-2 plugins".
249
+ * @agent-note Fresh calls go through the host preview port and write nothing. */
250
+ readonly runsFresh: boolean;
251
+ }
252
+ /** Per-workspace call dependencies.
253
+ * @agent-note Second-host rules: pass the SAME object to every member; it is held by reference and
254
+ * each member is read when used (activation repo on every call, preview port per call), never copied.
255
+ * Use the same activation repository the enable/disable path writes so revocation is seen at once. */
256
+ export interface PluginCapabilityToolDeps<TPost extends PluginCapabilityPost, TDraft> {
257
+ /** @agent-note Optional executable contribution registry; attached only when present. */
258
+ readonly pluginContributions?: PluginContributionRegistry;
259
+ /** @agent-note Separate registry for executable tools; otherwise the given registry when it can list. */
260
+ readonly executablePluginToolRegistry?: ToolRegistry;
261
+ /** @agent-note Host authorization callback (legacy flat shape), adapted per check. */
262
+ readonly authorize: LegacyToolAuthorizeFn;
263
+ /** @agent-note The one workspace every read and check is scoped to. */
264
+ readonly workspaceId: string;
265
+ /** @agent-note Read-only post port. */
266
+ readonly postRead: PluginCapabilityPostReadPort<TPost>;
267
+ /** Re-read on EVERY call by each registration's policy — see this file's header, "Revocation".
268
+ * @agent-note A read that throws denies the call and is logged. */
269
+ readonly pluginActivationRepo: PluginActivationRepoPort;
270
+ /** Runs ONE attached plugin's beforeSave filter on a draft without saving — the composition
271
+ * root's `previewPluginBeforeSave` binding (`HookRegistry.previewBeforeSave`). Omitted ⇒ every
272
+ * tool reads stored values. See this file's header, "Fresh results for Tier-2 plugins".
273
+ * @agent-note Optional; read per call. */
274
+ readonly previewPluginBeforeSave?: PluginCapabilityPreviewPort<TDraft>;
275
+ }
276
+ /** Discovery-time dependencies of {@link PluginCapabilityTools.loadSources}.
277
+ * @agent-note One discovery call; one activation read per field-declaring valid plugin. */
278
+ export interface PluginCapabilitySourceDeps {
279
+ /** @agent-note Workspace whose activation rows decide which plugins get a tool. */
280
+ readonly workspaceId: string;
281
+ /** @agent-note Host discovery; called once per load, never per plugin. */
282
+ readonly discoverPlugins: () => Promise<readonly PluginDiscoveryRecord[]>;
283
+ /** @agent-note Same activation repository the per-call gate reads. */
284
+ readonly pluginActivationRepo: PluginActivationRepoPort;
285
+ }
286
+ /** Host inputs of {@link createPluginCapabilityTools}.
287
+ * @agent-note Second-host rules: everything a host names lives here; one instance per host
288
+ * vocabulary (it holds no per-workspace state, so one instance serves every workspace). */
289
+ export interface PluginCapabilityToolsRequired<TPost extends PluginCapabilityPost, TDraft, TFamily extends string> {
290
+ /** @agent-note Namespace passed to `readPluginIdentity` for the discovery terms. */
291
+ readonly identityNamespace: string;
292
+ /** The host SDK's before-save hook id (the same id its `PluginSdkBinding.hookIds` admits and its
293
+ * invocation binding receives as `beforeSaveHook`).
294
+ * @agent-note Second-host rule: required, no default. A tier-2 plugin whose manifest `hooks`
295
+ * include exactly this id runs fresh through `previewPluginBeforeSave` on every call; any other
296
+ * plugin reads stored values. Supply the same id every other runtime port uses, or a valid
297
+ * tier-2 plugin is silently classified stored-only. */
298
+ readonly beforeSaveHook: string;
299
+ /** @agent-note All model-facing prose; see {@link PluginCapabilityToolText}. */
300
+ readonly text: PluginCapabilityToolText;
301
+ /** @agent-note `buildDomainRegistrations` inputs: `domain` (failure messages), `catalogModule`
302
+ * (the host file named in drift messages) and `metadata` (host tool metadata by id). */
303
+ readonly catalog: {
304
+ readonly domain: string;
305
+ readonly catalogModule: string;
306
+ readonly metadata: ToolMetadataById;
307
+ };
308
+ /** @agent-note Same object reaches catalog entry and handler. */
309
+ readonly access: PluginCapabilityToolAccess;
310
+ /** @agent-note Authority for executable contribution tools. */
311
+ readonly executableAccess: PluginCapabilityExecutableAccess;
312
+ /** @agent-note Family handed to the approval port with every registration. */
313
+ readonly approvalFamily: TFamily;
314
+ /** @agent-note Builds the host's before-save draft from the stored post, per fresh call; the host
315
+ * owns the payload fields (the same ones its save path hands the filter on an update). */
316
+ readonly toPreviewDraft: (required: {
317
+ post: TPost;
318
+ }, optional?: Record<string, never>) => TDraft;
319
+ }
320
+ /** The registrar bound to one host vocabulary.
321
+ * @agent-note Second-host rules: call `registerEnabled` (or `loadSources` + `buildRegistrations`)
322
+ * BEFORE any one-shot tool search index snapshots the registry; a later registration is invisible
323
+ * to search. Registry id collisions throw from `register` and are not caught here. */
324
+ export interface PluginCapabilityTools<TPost extends PluginCapabilityPost, TDraft, TFamily extends string> {
325
+ /** @agent-note Valid, enabled, field-declaring plugins only, in discovery order. */
326
+ loadSources(required: PluginCapabilitySourceDeps, optional?: Record<string, never>): Promise<readonly PluginCapabilityToolSource[]>;
327
+ /** @agent-note Pure and synchronous; each registration is gate-wrapped, then approval-wrapped. */
328
+ buildRegistrations(required: {
329
+ sources: readonly PluginCapabilityToolSource[];
330
+ deps: PluginCapabilityToolDeps<TPost, TDraft>;
331
+ applyApprovalPolicy: PluginCapabilityApprovalPort<TFamily>;
332
+ }, optional?: Record<string, never>): ToolRegistration[];
333
+ /** @agent-note Loads, registers each field tool, then attaches executable contribution tools when a
334
+ * contribution registry and a listable registry are present. */
335
+ registerEnabled(required: {
336
+ registry: PluginCapabilityRegistryPort;
337
+ deps: PluginCapabilityToolDeps<TPost, TDraft> & PluginCapabilitySourceDeps;
338
+ applyApprovalPolicy: PluginCapabilityApprovalPort<TFamily>;
339
+ }, optional?: Record<string, never>): Promise<void>;
340
+ }
341
+ /** The registry surface `registerEnabled` uses.
342
+ * @agent-note `register` must throw on a duplicate id; `has` and `list` are needed only for
343
+ * attaching executable tools to this same registry. */
344
+ export interface PluginCapabilityRegistryPort {
345
+ /** @agent-note Throws on a duplicate id; not caught by the registrar. */
346
+ register: (registration: ToolRegistration) => void;
347
+ /** @agent-note With `list`, lets executable tools attach to this registry. */
348
+ has?: ToolRegistry["has"];
349
+ /** @agent-note With `has`, lets executable tools attach to this registry. */
350
+ list?: ToolRegistry["list"];
351
+ }
352
+ /** This module's own risk classification — every capability tool is a pure read of an already-saved
353
+ * post's already-computed `ext` bag: no domain call, no write path. Mirrors
354
+ * `agent-plugins/tool-registrations.ts`'s identical `"none"` classification for the same reason.
355
+ * @agent-note Host-independent: every source is classified `"none"`. */
356
+ export declare function pluginCapabilityToolDerivedRisk(required: {
357
+ sources: readonly PluginCapabilityToolSource[];
358
+ }, _optional?: Record<string, never>): DerivedRiskByToolId;
359
+ /**
360
+ * Binds the capability-tool registrar to one host vocabulary.
361
+ * @agent-note Second-host rules: supply every required input; nothing has a default. The returned
362
+ * members hold no state between calls; per-workspace state lives in the `deps` object the caller
363
+ * passes (held by reference). Calls to the host ports happen in this order per tool call: activation
364
+ * read (policy), inner policy, approval policy, permission check, post read, optional preview.
365
+ * @param required Host vocabulary and ports, see {@link PluginCapabilityToolsRequired}.
366
+ * @param _optional Reserved; pass `{}`.
367
+ */
368
+ export declare function createPluginCapabilityTools<TPost extends PluginCapabilityPost, TDraft, TFamily extends string>(required: PluginCapabilityToolsRequired<TPost, TDraft, TFamily>, _optional?: Record<string, never>): PluginCapabilityTools<TPost, TDraft, TFamily>;
369
+ //# sourceMappingURL=capability-tools.d.ts.map