@jini-ai/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.
Files changed (82) hide show
  1. package/CHANGELOG.md +0 -6
  2. package/README.md +1 -1
  3. package/dist/core/manifest-keys.d.ts +8 -0
  4. package/dist/core/manifest-keys.js +16 -0
  5. package/dist/glue/attachment-points/content-lifecycle.d.ts +6 -7
  6. package/dist/glue/attachment-points/content-lifecycle.js +1 -1
  7. package/dist/glue/capability-gate.d.ts +2 -2
  8. package/dist/glue/manifest.js +2 -12
  9. package/dist/host/activation.d.ts +4 -5
  10. package/dist/host/admin-response.d.ts +2 -3
  11. package/dist/host/attach-loaded-plugin.d.ts +4 -4
  12. package/dist/host/attach-loaded-plugin.js +2 -2
  13. package/dist/host/browser-providers.d.ts +1 -1
  14. package/dist/host/capability-sdk.d.ts +8 -7
  15. package/dist/host/capability-sdk.js +39 -31
  16. package/dist/host/capability-tools.d.ts +3 -3
  17. package/dist/host/capability-tools.js +249 -237
  18. package/dist/host/contributions.d.ts +7 -66
  19. package/dist/host/contributions.js +64 -51
  20. package/dist/host/declarative-content-types.d.ts +6 -6
  21. package/dist/host/declarative-content-types.js +141 -135
  22. package/dist/host/declarative-enable.js +1 -1
  23. package/dist/host/discovery-types.d.ts +3 -3
  24. package/dist/host/hook-registry.d.ts +9 -9
  25. package/dist/host/hook-registry.js +86 -76
  26. package/dist/host/index.d.ts +1 -2
  27. package/dist/host/index.js +1 -1
  28. package/dist/host/manifest-types.d.ts +6 -59
  29. package/dist/host/manifest.d.ts +6 -5
  30. package/dist/host/manifest.js +3 -39
  31. package/dist/host/node/discovery.d.ts +1 -1
  32. package/dist/host/node/discovery.js +4 -5
  33. package/dist/host/node/index.d.ts +3 -0
  34. package/dist/host/node/index.js +2 -0
  35. package/dist/host/node/install.js +2 -2
  36. package/dist/host/node/integrity-command.d.ts +8 -0
  37. package/dist/host/node/integrity-command.js +26 -0
  38. package/dist/host/node/invocation-binding.d.ts +1 -1
  39. package/dist/host/node/invocation-binding.js +1 -1
  40. package/dist/host/node/loader.d.ts +3 -2
  41. package/dist/host/node/loader.js +12 -12
  42. package/dist/host/node/module-snapshot.d.ts +20 -0
  43. package/dist/host/node/module-snapshot.js +31 -0
  44. package/dist/host/node/open-flags.d.ts +4 -1
  45. package/dist/host/node/open-flags.js +1 -1
  46. package/dist/host/node/package-files.js +1 -1
  47. package/dist/host/node/provider-artifact.d.ts +1 -2
  48. package/dist/host/node/runtime-contracts.d.ts +237 -0
  49. package/dist/host/node/runtime-contracts.js +2 -0
  50. package/dist/host/node/runtime-core.d.ts +1 -243
  51. package/dist/host/node/runtime-core.js +18 -114
  52. package/dist/host/node/runtime-load-target.d.ts +44 -0
  53. package/dist/host/node/runtime-load-target.js +45 -0
  54. package/dist/host/node/runtime-package-location.d.ts +45 -0
  55. package/dist/host/node/runtime-package-location.js +57 -0
  56. package/dist/host/node/source-drafts.d.ts +4 -2
  57. package/dist/host/node/source-drafts.js +107 -39
  58. package/dist/host/ports.d.ts +1 -38
  59. package/dist/host/provider-contributions.d.ts +2 -14
  60. package/dist/host/provider-contributions.js +1 -1
  61. package/dist/host/provider-host.d.ts +4 -19
  62. package/dist/host/provider-host.js +83 -71
  63. package/dist/host/provider-revision-watch.d.ts +36 -0
  64. package/dist/host/provider-revision-watch.js +52 -0
  65. package/dist/host/provider-setting-required.d.ts +1 -7
  66. package/dist/host/provider-setting-required.js +1 -18
  67. package/dist/host/provider-settings-migrations.d.ts +1 -1
  68. package/dist/host/repo.memory.d.ts +1 -1
  69. package/dist/host/repo.memory.js +1 -1
  70. package/dist/host/sql/repo.d.ts +4 -3
  71. package/dist/host/sql/repo.rows.js +2 -2
  72. package/dist/host/tool-contributions.d.ts +2 -1
  73. package/dist/host/tool-contributions.js +1 -0
  74. package/dist/host/tools/install.js +1 -0
  75. package/dist/host/tools/management.js +97 -83
  76. package/dist/host/uninstall.d.ts +1 -1
  77. package/dist/host/worker/import-seam.d.ts +2 -2
  78. package/dist/host/worker/protocol.d.ts +2 -2
  79. package/dist/host/worker/run-call.d.ts +2 -1
  80. package/dist/host/worker/run-call.js +2 -2
  81. package/dist/host/worker/start.js +1 -1
  82. package/package.json +7 -17
@@ -5,14 +5,14 @@ export { PluginHookFailedError };
5
5
  /** Default recovery policy: tolerate two transient failures, quarantine on the third consecutive
6
6
  * failure. Composition may inject a different positive integer per runtime instance. */
7
7
  export const DEFAULT_PLUGIN_FAILURE_THRESHOLD = 3;
8
- /** TB-01's rank per source, ADR-057 Decision 3's additive third stage: built-ins (0), then site
8
+ /** Source rank with an additive third stage: built-ins (0), then site
9
9
  * plugins (1), then glue modules (2) — id-ascending within each rank (`compareTb01` below). */
10
10
  const SOURCE_RANK = { "built-in": 0, site: 1, glue: 2 };
11
11
  /**
12
12
  * TB-01 comparator: built-ins before site plugins before glue modules, id-ascending within each
13
13
  * group. Shared with `discovery.ts`'s own ordering rule for the `built-in`/`site` ranks (PLUGINS_LIST
14
14
  * uses the same order) so those two never diverge; the `glue` rank has no discovery-time analogue
15
- * since glue modules are never listed by `discovery.ts` (ADR-057 Decision 6 — a separate tier).
15
+ * since glue modules are never listed by `discovery.ts` (a separate tier).
16
16
  */
17
17
  function compareTb01(a, b) {
18
18
  const rankDiff = SOURCE_RANK[a[1].source] - SOURCE_RANK[b[1].source];
@@ -92,82 +92,50 @@ async function applyPluginFilter(pluginId, attachment, entry, mergedSoFar, befor
92
92
  assertPatchShape(pluginId, patch);
93
93
  return buildDeclaredPatch(pluginId, patch, attachment.declaredFields);
94
94
  }
95
- /**
96
- * Creates a fresh, empty hook registry (no plugins attached). Each process has exactly one
97
- * long-lived instance, constructed once at composition-root time and shared between `loader.ts`
98
- * (attach/detach) and `post.ts` (via `BeforeSaveHookPort`, `runBeforeSave` only).
99
- *
100
- * @complexity `attach`/`detach` are O(1) (Map operations). `runBeforeSave` is
101
- * O(attached-plugin-count · own-declared-field-count) for merge/validation bookkeeping, plus each
102
- * plugin's own filter cost (unbounded, plugin-defined — no latency budget exists, ADR scalability
103
- * axis, a disclosed gap).
104
- * @overallScore 100/100
105
- */
106
- export function createHookRegistry(required, options = {}) {
107
- const beforeSaveHook = required.pluginSdkBinding.beforeSaveHook;
108
- const failureThreshold = options.failureThreshold ?? DEFAULT_PLUGIN_FAILURE_THRESHOLD;
109
- if (!Number.isInteger(failureThreshold) || failureThreshold < 1) {
110
- throw new RangeError("plugin failure threshold must be a positive integer");
95
+ function clearHookFailures(consecutiveFailures, pluginId, workspaceId) {
96
+ if (workspaceId !== undefined) {
97
+ const workspaceFailures = consecutiveFailures.get(workspaceId);
98
+ workspaceFailures?.delete(pluginId);
99
+ if (workspaceFailures?.size === 0)
100
+ consecutiveFailures.delete(workspaceId);
101
+ return;
111
102
  }
112
- const attachments = new Map();
113
- const consecutiveFailures = new Map();
114
- /** A threshold count retains quarantine for this workspace until attach/detach resets it.
115
- * @complexity O(1) lookup; no persistence or filter execution.
116
- */
117
- function isQuarantined({ pluginId, workspaceId }, _optional = {}) {
118
- return (consecutiveFailures.get(workspaceId)?.get(pluginId) ?? 0) >= failureThreshold;
119
- }
120
- function clearFailures(pluginId, workspaceId) {
121
- if (workspaceId !== undefined) {
122
- const workspaceFailures = consecutiveFailures.get(workspaceId);
123
- workspaceFailures?.delete(pluginId);
124
- if (workspaceFailures?.size === 0)
125
- consecutiveFailures.delete(workspaceId);
126
- return;
127
- }
128
- for (const [workspace, workspaceFailures] of consecutiveFailures) {
129
- workspaceFailures.delete(pluginId);
130
- if (workspaceFailures.size === 0)
131
- consecutiveFailures.delete(workspace);
132
- }
103
+ for (const [workspace, workspaceFailures] of consecutiveFailures) {
104
+ workspaceFailures.delete(pluginId);
105
+ if (workspaceFailures.size === 0)
106
+ consecutiveFailures.delete(workspace);
133
107
  }
134
- /** Counts failures for one workspace and quarantines it before awaiting persistence.
135
- * Persistence failure throws a hook error; the workspace remains quarantined.
136
- * @complexity O(1) bookkeeping plus one host persistence callback at the threshold.
137
- */
138
- async function recordFailure({ pluginId, workspaceId, failure }, _optional = {}) {
139
- if (!options.onQuarantine)
140
- return;
141
- const workspaceFailures = consecutiveFailures.get(workspaceId) ?? new Map();
142
- const next = (workspaceFailures.get(pluginId) ?? 0) + 1;
143
- workspaceFailures.set(pluginId, next);
144
- consecutiveFailures.set(workspaceId, workspaceFailures);
145
- if (next < failureThreshold)
146
- return;
147
- // Recover the affected workspace first: the triggering save remains fail-closed, but the
148
- // threshold count skips later saves/previews while durable activation state is recorded.
149
- // Other workspaces retain the attachment and their own failure counts.
150
- try {
151
- await options.onQuarantine({
152
- pluginId,
153
- workspaceId,
154
- consecutiveFailures: next,
155
- reason: failure.message,
156
- });
157
- }
158
- catch (error) {
159
- throw new PluginHookFailedError(pluginId, `${failure.message}; automatic quarantine persistence failed: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
160
- }
161
- }
162
- function attach({ pluginId, source, filter, declaredFields }, _optional = {}) {
163
- clearFailures(pluginId);
164
- attachments.set(pluginId, { source, filter, declaredFields });
108
+ }
109
+ /** Counts failures for one workspace and quarantines it before awaiting persistence.
110
+ * Persistence failure throws a hook error; the workspace remains quarantined.
111
+ * @complexity O(1) bookkeeping plus one host persistence callback at the threshold.
112
+ */
113
+ async function recordHookFailure({ consecutiveFailures, failureThreshold, options }, { pluginId, workspaceId, failure }, _optional = {}) {
114
+ if (!options.onQuarantine)
115
+ return;
116
+ const workspaceFailures = consecutiveFailures.get(workspaceId) ?? new Map();
117
+ const next = (workspaceFailures.get(pluginId) ?? 0) + 1;
118
+ workspaceFailures.set(pluginId, next);
119
+ consecutiveFailures.set(workspaceId, workspaceFailures);
120
+ if (next < failureThreshold)
121
+ return;
122
+ // Recover the affected workspace first: the triggering save remains fail-closed, but the
123
+ // threshold count skips later saves/previews while durable activation state is recorded.
124
+ // Other workspaces retain the attachment and their own failure counts.
125
+ try {
126
+ await options.onQuarantine({
127
+ pluginId,
128
+ workspaceId,
129
+ consecutiveFailures: next,
130
+ reason: failure.message,
131
+ });
165
132
  }
166
- function detach({ pluginId }, _optional = {}) {
167
- attachments.delete(pluginId);
168
- clearFailures(pluginId);
133
+ catch (error) {
134
+ throw new PluginHookFailedError(pluginId, `${failure.message}; automatic quarantine persistence failed: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
169
135
  }
170
- async function runBeforeSave({ entry }, _optional = {}) {
136
+ }
137
+ function createBeforeSaveRunner({ attachments, beforeSaveHook, isQuarantined, clearFailures, recordFailure }) {
138
+ return async function runBeforeSave({ entry }, _optional = {}) {
171
139
  const ordered = [...attachments.entries()].sort(compareTb01);
172
140
  const merged = {};
173
141
  for (const [pluginId, attachment] of ordered) {
@@ -186,8 +154,10 @@ export function createHookRegistry(required, options = {}) {
186
154
  }
187
155
  }
188
156
  return merged;
189
- }
190
- async function previewBeforeSave({ pluginId, entry }, _optional = {}) {
157
+ };
158
+ }
159
+ function createBeforeSavePreview({ attachments, beforeSaveHook, isQuarantined }) {
160
+ return async function previewBeforeSave({ pluginId, entry }, _optional = {}) {
191
161
  const attachment = attachments.get(pluginId);
192
162
  if (!attachment || isQuarantined({ pluginId, workspaceId: entry.workspaceId }))
193
163
  return null;
@@ -199,7 +169,47 @@ export function createHookRegistry(required, options = {}) {
199
169
  ? error
200
170
  : new PluginHookFailedError(pluginId, `plugin '${pluginId}' beforeSave hook failed`, { cause: error });
201
171
  }
172
+ };
173
+ }
174
+ /**
175
+ * Creates a fresh, empty hook registry (no plugins attached). Each process has exactly one
176
+ * long-lived instance, constructed once at composition-root time and shared between `loader.ts`
177
+ * (attach/detach) and `post.ts` (via `BeforeSaveHookPort`, `runBeforeSave` only).
178
+ *
179
+ * @complexity `attach`/`detach` are O(1) (Map operations). `runBeforeSave` is
180
+ * O(attached-plugin-count · own-declared-field-count) for merge/validation bookkeeping, plus each
181
+ * plugin's own filter cost (unbounded, plugin-defined — no latency budget exists, ADR scalability
182
+ * axis, a disclosed gap).
183
+ * @overallScore 100/100
184
+ */
185
+ export function createHookRegistry(required, options = {}) {
186
+ const beforeSaveHook = required.pluginSdkBinding.beforeSaveHook;
187
+ const failureThreshold = options.failureThreshold ?? DEFAULT_PLUGIN_FAILURE_THRESHOLD;
188
+ if (!Number.isInteger(failureThreshold) || failureThreshold < 1) {
189
+ throw new RangeError("plugin failure threshold must be a positive integer");
190
+ }
191
+ const attachments = new Map();
192
+ const consecutiveFailures = new Map();
193
+ /** A threshold count retains quarantine for this workspace until attach/detach resets it.
194
+ * @complexity O(1) lookup; no persistence or filter execution.
195
+ */
196
+ function isQuarantined({ pluginId, workspaceId }, _optional = {}) {
197
+ return (consecutiveFailures.get(workspaceId)?.get(pluginId) ?? 0) >= failureThreshold;
198
+ }
199
+ const failureContext = { consecutiveFailures, failureThreshold, options };
200
+ const clearFailures = (pluginId, workspaceId) => clearHookFailures(consecutiveFailures, pluginId, workspaceId);
201
+ const recordFailure = (input) => recordHookFailure(failureContext, input);
202
+ function attach({ pluginId, source, filter, declaredFields }, _optional = {}) {
203
+ clearFailures(pluginId);
204
+ attachments.set(pluginId, { source, filter, declaredFields });
205
+ }
206
+ function detach({ pluginId }, _optional = {}) {
207
+ attachments.delete(pluginId);
208
+ clearFailures(pluginId);
202
209
  }
210
+ const executionContext = { attachments, beforeSaveHook, isQuarantined, clearFailures, recordFailure };
211
+ const runBeforeSave = createBeforeSaveRunner(executionContext);
212
+ const previewBeforeSave = createBeforeSavePreview(executionContext);
203
213
  return { attach, detach, runBeforeSave, previewBeforeSave };
204
214
  }
205
215
  //# sourceMappingURL=hook-registry.js.map
@@ -21,9 +21,8 @@ export * from './tool-contributions.js';
21
21
  export * from './capability-tools.js';
22
22
  export * from './browser-providers.js';
23
23
  export * from './bundled-initialization.js';
24
- export { PLUGIN_PROVIDER_CAPABILITY } from './provider-contributions.js';
25
- export type { PluginProviderResource, PluginProviderFactory, PluginProviderContribution, PluginProvidersSdk } from './provider-contributions.js';
26
24
  export * from './provider-host.js';
25
+ export * from './provider-revision-watch.js';
27
26
  export * from './provider-setting-required.js';
28
27
  export * from './provider-settings-migrations.js';
29
28
  export type { ProviderConfigSource, ProviderKeyUsage, ProviderPluginConfig, ProviderSettingsView, ProviderWriteResult } from './provider-config-source.js';
@@ -21,8 +21,8 @@ export * from './tool-contributions.js';
21
21
  export * from './capability-tools.js';
22
22
  export * from './browser-providers.js';
23
23
  export * from './bundled-initialization.js';
24
- export { PLUGIN_PROVIDER_CAPABILITY } from './provider-contributions.js';
25
24
  export * from './provider-host.js';
25
+ export * from './provider-revision-watch.js';
26
26
  export * from './provider-setting-required.js';
27
27
  export * from './provider-settings-migrations.js';
28
28
  export * from './admin-response.js';
@@ -1,5 +1,6 @@
1
1
  /** Manifest data contracts do not depend on validation or host composition. */
2
2
  import type { PluginIdentityExtension } from '@jini-ai/core/plugin-directory';
3
+ import type { PluginProviderDeclaration } from '@jini-ai/core/contracts/plugin-sdk';
3
4
  export interface BrowserProviderDeclaration {
4
5
  readonly id: string;
5
6
  readonly kind: 'chart';
@@ -8,8 +9,8 @@ export interface BrowserProviderDeclaration {
8
9
  readonly javascript: string;
9
10
  readonly stylesheet?: string;
10
11
  }
11
- /** ADR-024 §1 trust-tier vocabulary (1.1.1 REQ-01 fix). Literal encoding reused verbatim from the
12
- * existing, approved SPEC-032/ADR-023 precedent (`DataModuleDecl.pluginTier`). */
12
+ /** Trust-tier vocabulary. Literal encoding reused verbatim from the
13
+ * existing, approved data-module precedent (`DataModuleDecl.pluginTier`). */
13
14
  export type PluginTier = "tier-1" | "tier-2" | "tier-3";
14
15
  /** REQ-04's exactly-three v1 capability vocabulary, as manifest-declared strings (validated
15
16
  * against this set by `validateManifest`; `@jini-ai/plugin-sdk`'s `CONTENT_READ`/`CONTENT_EXTEND`/
@@ -38,7 +39,7 @@ export interface PluginManifestFieldDecl {
38
39
  */
39
40
  readonly description?: string;
40
41
  }
41
- /** `jini.plugin.json` — the ecosystem compatibility surface (state.spec.md §2, ADR-004). */
42
+ /** `jini.plugin.json` — the ecosystem compatibility surface. */
42
43
  export interface PluginManifest {
43
44
  /** Storage/activation key. Publisher identity lives in extensions[identityNamespace].id. */
44
45
  readonly id: string;
@@ -72,7 +73,7 @@ export interface PluginManifest {
72
73
  * when it declares `fields`, its generated capability tool). Each entry is a CLAIM: two enabled
73
74
  * plugins, or a plugin and core, naming the same thing is refused at enable time and quarantined
74
75
  * at boot rather than silently letting one overwrite the other. Declaring a surface the runtime
75
- * does not mount yet (settings, widgets, routes — ADR-025/`adminSurfaces` are still unwired) is
76
+ * does not mount yet (settings, widgets, routes — `adminSurfaces` are still unwired) is
76
77
  * still binding for conflicts, so a plugin cannot squat a name today that a future mount would
77
78
  * then have to arbitrate.
78
79
  */
@@ -86,67 +87,13 @@ export interface PluginContributions {
86
87
  readonly routes?: readonly string[];
87
88
  /** Agent tool ids. The generated prefixes `plugin_capability_`/`agent_plugin_` are reserved. */
88
89
  readonly tools?: readonly string[];
89
- /** Data-module tables — must sit in this plugin's own `p_{id}__` namespace (ADR-023 §5). */
90
+ /** Data-module tables — must sit in this plugin's own `p_{id}__` namespace. */
90
91
  readonly tables?: readonly string[];
91
92
  readonly settings?: readonly string[];
92
93
  readonly widgets?: readonly string[];
93
94
  /** Permission ids this plugin DEFINES (not ones it merely requires). */
94
95
  readonly permissions?: readonly string[];
95
96
  }
96
- export interface PluginProviderDeclaration {
97
- readonly contract: string;
98
- readonly id: string;
99
- readonly contractVersion: 1;
100
- /**
101
- * The settings a host collects (on its own secure settings card) and passes to this provider's
102
- * factory as `required[name]`. Declared here, not in code, so a host can render the card and decide
103
- * "configured?" without executing the plugin. Secret fields are sealed by the host and never shown back.
104
- */
105
- readonly settings?: readonly PluginProviderSettingField[];
106
- /** Ordered read-time public-setting migrations; never rewrite persisted rows or secrets. */
107
- readonly settingsMigrations?: readonly PluginProviderSettingsMigration[];
108
- }
109
- /** A plugin-owned migration of retired public choices, applied to a copy on read. */
110
- export interface PluginProviderSettingsMigration {
111
- readonly when: {
112
- readonly field: string;
113
- readonly in: readonly string[];
114
- readonly orAbsent?: boolean;
115
- };
116
- readonly whenPresent?: string;
117
- readonly set: Readonly<Record<string, string>>;
118
- }
119
- /** One declared provider setting; `name` is the factory input key. */
120
- export interface PluginProviderSettingField {
121
- readonly name: string;
122
- readonly label: string;
123
- readonly secret?: boolean;
124
- readonly required?: boolean;
125
- /** Waive on an exact choice or a nonblank alternative. With `headerNames`, only a listed nonblank Name=Value header qualifies. */
126
- readonly requiredUnless?: {
127
- readonly field: string;
128
- readonly equals: string;
129
- readonly orPresent?: string;
130
- readonly headerNames?: readonly string[];
131
- };
132
- /** Require this field only when the controlling public setting is one of these values. */
133
- readonly requiredWhen?: {
134
- readonly field: string;
135
- readonly in: readonly string[];
136
- };
137
- readonly hint?: string;
138
- /** Public fields only: the value a host prefills and uses while none is saved (e.g. a vendor's cloud host). */
139
- readonly default?: string;
140
- /** Public fields only: a host renders a select of these choices instead of free text. */
141
- readonly options?: readonly PluginProviderSettingOption[];
142
- /** With `options`: also offer "Custom…" free text (e.g. a self-hosted URL). */
143
- readonly allowCustom?: boolean;
144
- }
145
- /** One choice of a {@link PluginProviderSettingField}'s `options`. */
146
- export interface PluginProviderSettingOption {
147
- readonly value: string;
148
- readonly label: string;
149
- }
150
97
  /** One validation-vocabulary entry (errors.spec.md §3). `file` names the offending packaged file
151
98
  * when applicable; `null` for manifest-level errors with no single implicated file. This is the
152
99
  * shared shape used verbatim by both `PLUGINS_LIST.plugins[].errors[]` and
@@ -1,13 +1,13 @@
1
1
  /**
2
2
  * @file `PluginManifest` type + `validateManifest()` — static, collect-all manifest validation
3
- * (SPEC-005 REQ-01, BR-02/BR-03; ADR-024 `tier`, 1.1.1 fix).
3
+ * (including the required trust tier).
4
4
  *
5
5
  * Purpose:
6
6
  * Pure, no-I/O validation of an already-parsed `jini.plugin.json` object against the v1 required-
7
7
  * field set, id/folder match, capability vocabulary, hook vocabulary, and field-declaration rules.
8
8
  * Consumed by both `discovery.ts` (list-time, every discovery pass) and `loader.ts` (enable-time
9
- * re-validation, BR-05) — one validator, two call sites, never diverging (mirrors SPEC-004's theme
10
- * validator shape, per feature.spec.md's own Article IV note).
9
+ * re-validation) — one validator, two call sites, never diverging (mirrors the theme
10
+ * validator shape, per the feature specification's own Article IV note).
11
11
  *
12
12
  * Division of labor (a TDD design decision, not itself a spec requirement): BR-02 step (1),
13
13
  * "package-level (size, disallowed files, server/index.mjs presence)", requires a directory
@@ -25,9 +25,10 @@
25
25
  * `errors[]` — it never throws. Verified against `__tests__/unit/manifest.unit.test.ts`.
26
26
  */
27
27
  import type { PluginValidationError } from './manifest-types.js';
28
- export type { PluginTier, PluginCapability, PluginManifestFieldDecl, PluginManifest, PluginContributions, PluginProviderDeclaration, PluginProviderSettingsMigration, PluginProviderSettingField, PluginProviderSettingOption, PluginValidationError } from './manifest-types.js';
28
+ export type { PluginTier, PluginCapability, PluginManifestFieldDecl, PluginManifest, PluginContributions, PluginValidationError } from './manifest-types.js';
29
29
  export { CORE_OWNER_ID } from "./plugin-format.js";
30
- import type { HookPoints, ManifestHostPorts } from "./ports.js";
30
+ import type { ManifestHostPorts } from "./ports.js";
31
+ import type { HookPoints } from "@jini-ai/core/contracts/plugin-sdk";
31
32
  export interface ValidateManifestRequired<H extends HookPoints = HookPoints> extends ManifestHostPorts<H> {
32
33
  /** An already-parsed `jini.plugin.json` value (unparseable JSON is `discovery.ts`'s concern —
33
34
  * this function receives a JS value, never a file path or raw bytes). */
@@ -1,29 +1,4 @@
1
- /**
2
- * @file `PluginManifest` type + `validateManifest()` — static, collect-all manifest validation
3
- * (SPEC-005 REQ-01, BR-02/BR-03; ADR-024 `tier`, 1.1.1 fix).
4
- *
5
- * Purpose:
6
- * Pure, no-I/O validation of an already-parsed `jini.plugin.json` object against the v1 required-
7
- * field set, id/folder match, capability vocabulary, hook vocabulary, and field-declaration rules.
8
- * Consumed by both `discovery.ts` (list-time, every discovery pass) and `loader.ts` (enable-time
9
- * re-validation, BR-05) — one validator, two call sites, never diverging (mirrors SPEC-004's theme
10
- * validator shape, per feature.spec.md's own Article IV note).
11
- *
12
- * Division of labor (a TDD design decision, not itself a spec requirement): BR-02 step (1),
13
- * "package-level (size, disallowed files, server/index.mjs presence)", requires a directory
14
- * listing this function's contract deliberately does NOT take as input (Implementation Outline
15
- * C-006: `{ manifest: unknown, folderName: string, builtInIds: string[] }` — no file-list
16
- * parameter). Package-level filesystem checks are therefore `discovery.ts`'s responsibility
17
- * (REQ-02/03's discovery step, which does read the filesystem); this function owns BR-02 steps
18
- * (2)-(6) only: manifest / identity / capabilities / hooks / fields. `discovery.ts` merges both
19
- * error sets into one `PluginDiscoveryRecord.errors[]` array before listing/enabling a plugin.
20
- *
21
- * Architectural role:
22
- * TDD-certified implementation (implementation outline C-005/C-006). Signature and JSDoc are
23
- * design-frozen; `validateManifest()` collects every BR-02 steps (2)-(6) violation (identity,
24
- * engine/tier, capabilities, hooks, fields) rather than stopping at the first, returning them in
25
- * `errors[]` — it never throws. Verified against `__tests__/unit/manifest.unit.test.ts`.
26
- */
1
+ import { collectManifestKeyErrors } from "../core/manifest-keys.js";
27
2
  import * as semver from "semver";
28
3
  import { CORE_OWNER_ID, PLUGIN_MANIFEST_FILENAME } from "./plugin-format.js";
29
4
  export { CORE_OWNER_ID } from "./plugin-format.js";
@@ -71,18 +46,7 @@ function malformed(message) {
71
46
  }
72
47
  /** Unknown-key and missing-required-key checks (BR-02 step 1's manifest-shape half). */
73
48
  function validateKeys(raw) {
74
- const errors = [];
75
- for (const key of Object.keys(raw)) {
76
- if (!ALLOWED_KEYS.has(key)) {
77
- errors.push(malformed(`unknown manifest key '${key}'`));
78
- }
79
- }
80
- for (const key of REQUIRED_KEYS) {
81
- if (raw[key] === undefined) {
82
- errors.push(malformed(`missing required manifest field '${key}'`));
83
- }
84
- }
85
- return errors;
49
+ return collectManifestKeyErrors({ raw, allowedKeys: ALLOWED_KEYS, requiredKeys: REQUIRED_KEYS, malformed });
86
50
  }
87
51
  /** id shape only: pattern + length (BR-02 step 2 half of id validation). */
88
52
  function validateIdFormat(id) {
@@ -196,7 +160,7 @@ function validateEngine(raw) {
196
160
  }
197
161
  return [];
198
162
  }
199
- /** tier (BR-02 step 2, ADR-024 §1 / 1.1.1 fix). */
163
+ /** Trust-tier validation (step 2). */
200
164
  function validateTier(raw) {
201
165
  if (raw.tier === undefined) {
202
166
  return [];
@@ -16,7 +16,7 @@ export declare class PluginDiscoveryVersionError extends Error {
16
16
  }
17
17
  /**
18
18
  * The absolute entry-file path for a discovered SITE plugin (REQ-02's fixed `server/index.mjs`
19
- * package layout, ADR-004) — the exact path `loadPlugin()`'s `entryPath` param expects, and the
19
+ * package layout) — the exact path `loadPlugin()`'s `entryPath` param expects, and the
20
20
  * same join `discoverOneSiteCandidate()` below already performs internally for its manifest read.
21
21
  * Exported so a composition root resolving a dynamic site-sourced load target (`plugin-runtime.ts`)
22
22
  * does not re-derive this convention independently and risk it drifting from discovery's own.
@@ -2,8 +2,7 @@ import { readPluginIdentity } from "@jini-ai/core/plugin-directory";
2
2
  /** Site tier admission belongs to tierPolicy.siteErrors; static validation uses host-supplied
3
3
  * catalogs and declaration grammar. */
4
4
  /**
5
- * @file `discoverPlugins()` — enumerate built-in + site plugins with status (SPEC-005 REQ-02/03,
6
- * EC-08/EC-09, TB-01, DUP-01).
5
+ * @file `discoverPlugins()` — enumerate built-in + site plugins with status.
7
6
  *
8
7
  * Purpose:
9
8
  * Read-only enumeration. Scans the install-dir's `plugins/<id>/<version>/` tree (REQ-02) plus the
@@ -16,7 +15,7 @@ import { readPluginIdentity } from "@jini-ai/core/plugin-directory";
16
15
  * not).
17
16
  *
18
17
  * Never `import()`s plugin code — that is `loader.ts`'s job, gated by integrity/`sdkRange` first
19
- * (BR-01, CIC U-001). Discovery only reads bytes to hash/measure/list them.
18
+ * Discovery only reads bytes to hash/measure/list them.
20
19
  *
21
20
  * Architectural role:
22
21
  * TDD-certified implementation (implementation outline C-007). Signature and JSDoc are
@@ -92,7 +91,7 @@ function toDiscoveryRecord(params) {
92
91
  }
93
92
  /**
94
93
  * The absolute entry-file path for a discovered SITE plugin (REQ-02's fixed `server/index.mjs`
95
- * package layout, ADR-004) — the exact path `loadPlugin()`'s `entryPath` param expects, and the
94
+ * package layout) — the exact path `loadPlugin()`'s `entryPath` param expects, and the
96
95
  * same join `discoverOneSiteCandidate()` below already performs internally for its manifest read.
97
96
  * Exported so a composition root resolving a dynamic site-sourced load target (`plugin-runtime.ts`)
98
97
  * does not re-derive this convention independently and risk it drifting from discovery's own.
@@ -174,7 +173,7 @@ async function readOpenManifest(handle) {
174
173
  if (!(await handle.stat()).isFile())
175
174
  return refused("is not a regular file");
176
175
  // `+ 1` catches a file that grew past the cap after `stat`.
177
- const bytes = await readAtMost(handle, MAX_SITE_MANIFEST_BYTES + 1);
176
+ const bytes = await readAtMost({ handle, maxBytes: MAX_SITE_MANIFEST_BYTES + 1 });
178
177
  if (bytes.length > MAX_SITE_MANIFEST_BYTES)
179
178
  return refused(`is larger than ${MAX_SITE_MANIFEST_BYTES} bytes`);
180
179
  return { missing: false, manifestValue: parseManifestJson(bytes.toString("utf8")) };
@@ -10,4 +10,7 @@ export * from './provider-artifact.js';
10
10
  export * from './invocation-binding.js';
11
11
  export * from './archive-policy.js';
12
12
  export * from './runtime-core.js';
13
+ export type * from './runtime-contracts.js';
14
+ export { PluginUninstallPathError } from './runtime-package-location.js';
15
+ export * from './integrity-command.js';
13
16
  //# sourceMappingURL=index.d.ts.map
@@ -10,4 +10,6 @@ export * from './provider-artifact.js';
10
10
  export * from './invocation-binding.js';
11
11
  export * from './archive-policy.js';
12
12
  export * from './runtime-core.js';
13
+ export { PluginUninstallPathError } from './runtime-package-location.js';
14
+ export * from './integrity-command.js';
13
15
  //# sourceMappingURL=index.js.map
@@ -125,8 +125,8 @@ async function snapshot(sourceDir, limits = {}) {
125
125
  * left out on purpose: it can carry script). */
126
126
  const DECLARATIVE_DATA_FILE = /(?:^|\/)(?:LICENSE|[^/]+\.(?:json|md|txt|png|jpe?g|gif|webp))$/;
127
127
  /**
128
- * Tier rules for a sideloaded package. Tier-1 (AW-7, 2026-10-04) is the manifest-only tier ADR-024
129
- * §1 defines — "zero executable code", so it is safe from any publisher: it may not ship a single
128
+ * Tier rules for a sideloaded package. Tier-1 (AW-7, 2026-10-04) is the manifest-only tier:
129
+ * "zero executable code", so it is safe from any publisher: it may not ship a single
130
130
  * code file (its declarations — no code surface, parseable `contentTypes` — are already checked by
131
131
  * `validateManifest`). Anything else must
132
132
  * still be tier-3 with `server/index.mjs`, because a sideloaded manifest cannot grant itself a
@@ -0,0 +1,8 @@
1
+ /** Authoring helper: hashes bytes only; never imports the package's entry point. */
2
+ export declare function runPluginIntegrityCommand(required: {
3
+ dir: string;
4
+ write?: boolean;
5
+ }, optional?: {
6
+ output?: (message: string) => void;
7
+ }): Promise<void>;
8
+ //# sourceMappingURL=integrity-command.d.ts.map
@@ -0,0 +1,26 @@
1
+ /** Plugin authoring helper: prints (and with `write`, stores into the manifest) the integrity map of a plugin folder. */
2
+ import path from "node:path";
3
+ import { readFile, readdir, writeFile, rename, rm } from "node:fs/promises";
4
+ import { randomUUID } from "node:crypto";
5
+ import { computePluginIntegrity } from './install.js';
6
+ import { PLUGIN_MANIFEST_FILENAME, PLUGIN_MANIFEST_FILENAMES } from '../plugin-format.js';
7
+ /** Authoring helper: hashes bytes only; never imports the package's entry point. */
8
+ export async function runPluginIntegrityCommand(required, optional = {}) {
9
+ const integrity = await computePluginIntegrity({ sourceDir: required.dir });
10
+ if (required.write) {
11
+ const names = await readdir(required.dir);
12
+ const sourceName = PLUGIN_MANIFEST_FILENAMES.find((name) => names.includes(name)) ?? PLUGIN_MANIFEST_FILENAME; // legacy alias
13
+ const manifest = JSON.parse(await readFile(path.join(required.dir, sourceName), "utf8"));
14
+ const manifestPath = path.join(required.dir, PLUGIN_MANIFEST_FILENAME);
15
+ const staged = manifestPath + ".tmp-" + randomUUID();
16
+ try {
17
+ await writeFile(staged, JSON.stringify({ ...manifest, integrity }, null, 2) + "\n", { flag: "wx" });
18
+ await rename(staged, manifestPath);
19
+ }
20
+ finally {
21
+ await rm(staged, { force: true });
22
+ }
23
+ }
24
+ (optional.output ?? ((message) => process.stdout.write(message)))(JSON.stringify(integrity, null, 2) + "\n");
25
+ }
26
+ //# sourceMappingURL=integrity-command.js.map
@@ -1,4 +1,4 @@
1
- import type { BeforeSaveFilter } from "../ports.js";
1
+ import type { BeforeSaveFilter } from "@jini-ai/core/contracts/plugin-sdk";
2
2
  import type { CapabilityScopedSdkCoreDeps } from "../capability-sdk.js";
3
3
  /**
4
4
  * @agent-note Second-host rule: `beforeSaveHook` is YOUR SDK's beforeSave hook id (the same string
@@ -3,7 +3,7 @@
3
3
  * SDK (`content.read`, `content.extend`, `addFilter`), shared by every place that runs a plugin's
4
4
  * `setup()`: the host's in-process enable path and the Tier-2 worker (`../worker/run-call.ts`).
5
5
  * One implementation, so a Tier-2 plugin sees exactly the SDK semantics a Tier-3 plugin does
6
- * (ADR-024 §3: the ABI is the same; only where the code runs differs).
6
+ * (the ABI is the same; only where the code runs differs).
7
7
  *
8
8
  * `content.read`/`content.extend` are bound to the filter invocation that is currently running
9
9
  * (AsyncLocalStorage), never to load time: a plugin that calls them from `setup()` or from a timer
@@ -4,7 +4,8 @@ import { type PluginContributionRegistry } from '../contributions.js';
4
4
  import { type CapabilityScopedSdkCoreDeps } from "../capability-sdk.js";
5
5
  import type { PluginDiscoveryRecord } from "../discovery-types.js";
6
6
  import type { PluginManifest } from "../manifest.js";
7
- import type { HookPoints, PluginSdkBinding, PluginModuleImportPort, VerifyDigestPort, PluginTierPolicy } from "../ports.js";
7
+ import type { PluginSdkBinding, PluginModuleImportPort, VerifyDigestPort, PluginTierPolicy } from "../ports.js";
8
+ import type { HookPoints } from "@jini-ai/core/contracts/plugin-sdk";
8
9
  export { attachLoadedPlugin } from "../attach-loaded-plugin.js";
9
10
  /** Host-owned SDK, import, digest and tier-admission contracts for one ordered load. */
10
11
  export interface LoadPluginRequired<H extends HookPoints = HookPoints> {
@@ -55,7 +56,7 @@ export type LoadPluginResult = {
55
56
  readonly reason: PluginLoadFailureReason;
56
57
  };
57
58
  /**
58
- * Executes BR-01's 5-step ordered pipeline for one plugin. See CIC U-001 above for the binding
59
+ * Executes the 5-step ordered pipeline for one plugin. See above for the binding
59
60
  * ordering constraint this function's statement order must never invert.
60
61
  *
61
62
  * @throws Never for an expected pipeline failure (those are reported via the returned `reason`);