@jini-ai/plugins 0.7.2 → 0.7.3-next.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/core/manifest-keys.d.ts +8 -0
- package/dist/core/manifest-keys.js +16 -0
- package/dist/glue/attachment-points/content-lifecycle.d.ts +6 -7
- package/dist/glue/attachment-points/content-lifecycle.js +1 -1
- package/dist/glue/capability-gate.d.ts +2 -2
- package/dist/glue/manifest.js +2 -12
- package/dist/host/activation.d.ts +4 -5
- package/dist/host/admin-response.d.ts +2 -3
- package/dist/host/attach-loaded-plugin.d.ts +4 -4
- package/dist/host/attach-loaded-plugin.js +2 -2
- package/dist/host/browser-providers.d.ts +1 -1
- package/dist/host/capability-sdk.d.ts +8 -7
- package/dist/host/capability-sdk.js +39 -31
- package/dist/host/capability-tools.d.ts +4 -3
- package/dist/host/capability-tools.js +250 -238
- package/dist/host/contributions.d.ts +7 -66
- package/dist/host/contributions.js +64 -51
- package/dist/host/declarative-content-types.d.ts +6 -6
- package/dist/host/declarative-content-types.js +141 -135
- package/dist/host/declarative-enable.js +1 -1
- package/dist/host/discovery-types.d.ts +3 -3
- package/dist/host/hook-registry.d.ts +9 -9
- package/dist/host/hook-registry.js +86 -76
- package/dist/host/index.d.ts +1 -2
- package/dist/host/index.js +1 -1
- package/dist/host/manifest-types.d.ts +6 -59
- package/dist/host/manifest.d.ts +6 -5
- package/dist/host/manifest.js +5 -41
- package/dist/host/node/discovery.d.ts +1 -1
- package/dist/host/node/discovery.js +5 -6
- package/dist/host/node/index.d.ts +3 -0
- package/dist/host/node/index.js +2 -0
- package/dist/host/node/install.js +4 -4
- package/dist/host/node/integrity-command.d.ts +8 -0
- package/dist/host/node/integrity-command.js +26 -0
- package/dist/host/node/invocation-binding.d.ts +1 -1
- package/dist/host/node/invocation-binding.js +1 -1
- package/dist/host/node/loader.d.ts +3 -2
- package/dist/host/node/loader.js +12 -12
- package/dist/host/node/module-snapshot.d.ts +20 -0
- package/dist/host/node/module-snapshot.js +31 -0
- package/dist/host/node/open-flags.d.ts +4 -1
- package/dist/host/node/open-flags.js +1 -1
- package/dist/host/node/package-files.js +1 -1
- package/dist/host/node/provider-artifact.d.ts +1 -2
- package/dist/host/node/runtime-contracts.d.ts +238 -0
- package/dist/host/node/runtime-contracts.js +2 -0
- package/dist/host/node/runtime-core.d.ts +1 -243
- package/dist/host/node/runtime-core.js +18 -114
- package/dist/host/node/runtime-load-target.d.ts +44 -0
- package/dist/host/node/runtime-load-target.js +45 -0
- package/dist/host/node/runtime-package-location.d.ts +45 -0
- package/dist/host/node/runtime-package-location.js +57 -0
- package/dist/host/node/source-drafts.d.ts +4 -2
- package/dist/host/node/source-drafts.js +107 -39
- package/dist/host/ports.d.ts +2 -38
- package/dist/host/provider-contributions.d.ts +2 -14
- package/dist/host/provider-contributions.js +1 -1
- package/dist/host/provider-host.d.ts +4 -19
- package/dist/host/provider-host.js +83 -71
- package/dist/host/provider-revision-watch.d.ts +36 -0
- package/dist/host/provider-revision-watch.js +52 -0
- package/dist/host/provider-setting-required.d.ts +1 -7
- package/dist/host/provider-setting-required.js +1 -18
- package/dist/host/provider-settings-migrations.d.ts +1 -1
- package/dist/host/repo.memory.d.ts +1 -1
- package/dist/host/repo.memory.js +1 -1
- package/dist/host/sql/repo.d.ts +4 -3
- package/dist/host/sql/repo.rows.js +2 -2
- package/dist/host/tool-contributions.d.ts +2 -1
- package/dist/host/tool-contributions.js +1 -0
- package/dist/host/tools/install.js +1 -0
- package/dist/host/tools/management.js +97 -83
- package/dist/host/uninstall.d.ts +1 -1
- package/dist/host/worker/import-seam.d.ts +2 -2
- package/dist/host/worker/protocol.d.ts +2 -2
- package/dist/host/worker/run-call.d.ts +2 -1
- package/dist/host/worker/run-call.js +2 -2
- package/dist/host/worker/start.js +1 -1
- 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
|
-
/**
|
|
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` (
|
|
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
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
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
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
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
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
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
|
-
|
|
167
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
package/dist/host/index.d.ts
CHANGED
|
@@ -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';
|
package/dist/host/index.js
CHANGED
|
@@ -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
|
-
/**
|
|
12
|
-
* existing, approved
|
|
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
|
|
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 —
|
|
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
|
|
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
|
package/dist/host/manifest.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @file `PluginManifest` type + `validateManifest()` — static, collect-all manifest validation
|
|
3
|
-
* (
|
|
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
|
|
10
|
-
* validator shape, per feature
|
|
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,
|
|
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 {
|
|
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). */
|
package/dist/host/manifest.js
CHANGED
|
@@ -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
|
-
|
|
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 (
|
|
163
|
+
/** Trust-tier validation (step 2). */
|
|
200
164
|
function validateTier(raw) {
|
|
201
165
|
if (raw.tier === undefined) {
|
|
202
166
|
return [];
|
|
@@ -410,7 +374,7 @@ export function validateManifest(required, _optional = {}) {
|
|
|
410
374
|
const { errors: idErrors, id } = validateId(raw, folderName, builtInIds, required.coreOwnerName);
|
|
411
375
|
const errors = [
|
|
412
376
|
...validateKeys(raw),
|
|
413
|
-
...validatePluginIdentity({ manifest: raw, namespace: required.identityNamespace }).errors.map(message => ({ code: "PLUGIN_IDENTITY_INVALID", file: null, message })),
|
|
377
|
+
...validatePluginIdentity({ manifest: raw, namespace: required.identityNamespace, legacyNamespace: required.legacyIdentityNamespace }).errors.map(message => ({ code: "PLUGIN_IDENTITY_INVALID", file: null, message })),
|
|
414
378
|
...idErrors,
|
|
415
379
|
...validateIdentityFields(raw),
|
|
416
380
|
...validateEngine(raw),
|
|
@@ -424,7 +388,7 @@ export function validateManifest(required, _optional = {}) {
|
|
|
424
388
|
...required.declarativeContentTypes.validateManifest({ manifest: raw }).errors,
|
|
425
389
|
];
|
|
426
390
|
const warnings = errors.length === 0
|
|
427
|
-
? readPluginIdentity({ manifest: raw, name: id, namespace: required.identityNamespace }).warnings
|
|
391
|
+
? readPluginIdentity({ manifest: raw, name: id, namespace: required.identityNamespace, legacyNamespace: required.legacyIdentityNamespace }).warnings
|
|
428
392
|
: [];
|
|
429
393
|
return { errors, warnings };
|
|
430
394
|
}
|
|
@@ -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
|
|
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
|
|
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
|
-
*
|
|
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
|
|
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")) };
|
|
@@ -290,7 +289,7 @@ export async function discoverPlugins(required, optional = {}) {
|
|
|
290
289
|
return records.map(record => {
|
|
291
290
|
if (record.status !== "valid" || !record.manifest)
|
|
292
291
|
return record;
|
|
293
|
-
const identity = readPluginIdentity({ manifest: record.manifest, name: record.id, namespace: required.identityNamespace });
|
|
292
|
+
const identity = readPluginIdentity({ manifest: record.manifest, name: record.id, namespace: required.identityNamespace, legacyNamespace: required.legacyIdentityNamespace });
|
|
294
293
|
if (!qualifiedIds.has(identity.id)) {
|
|
295
294
|
qualifiedIds.add(identity.id);
|
|
296
295
|
return { ...record, warnings: identity.warnings };
|
|
@@ -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
|
package/dist/host/node/index.js
CHANGED
|
@@ -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
|
|
129
|
-
*
|
|
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
|
|
@@ -185,7 +185,7 @@ function validatePackage(files, deps) {
|
|
|
185
185
|
return candidate;
|
|
186
186
|
}
|
|
187
187
|
function identityOf(manifest, deps, name = manifest.id) {
|
|
188
|
-
return readPluginIdentity({ manifest: manifest, name, namespace: deps.identityNamespace });
|
|
188
|
+
return readPluginIdentity({ manifest: manifest, name, namespace: deps.identityNamespace, legacyNamespace: deps.legacyIdentityNamespace });
|
|
189
189
|
}
|
|
190
190
|
function assertIdentityFree(candidate, installed) {
|
|
191
191
|
try {
|
|
@@ -250,7 +250,7 @@ async function readInstalledIdentity(required) {
|
|
|
250
250
|
if (!manifestInfo.isFile() || manifestInfo.isSymbolicLink())
|
|
251
251
|
fail("PLUGIN_PACKAGE_UNSAFE", "Installed plugin manifests must not be links.");
|
|
252
252
|
const installedManifest = JSON.parse(await scan.readFile(manifestPath, "utf8"));
|
|
253
|
-
return readPluginIdentity({ manifest: installedManifest, name: localId, namespace: deps.identityNamespace });
|
|
253
|
+
return readPluginIdentity({ manifest: installedManifest, name: localId, namespace: deps.identityNamespace, legacyNamespace: deps.legacyIdentityNamespace });
|
|
254
254
|
}
|
|
255
255
|
catch (error) {
|
|
256
256
|
if (error instanceof PluginInstallError)
|
|
@@ -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 "
|
|
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
|
-
* (
|
|
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 {
|
|
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
|
|
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`);
|