@jini-ai/plugins 0.5.1 → 0.5.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.
Files changed (112) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/dist/host/browser-providers.d.ts +2 -9
  3. package/dist/host/browser-providers.js +34 -18
  4. package/dist/host/contributions.d.ts +4 -1
  5. package/dist/host/contributions.js +19 -8
  6. package/dist/host/discovery-types.d.ts +1 -1
  7. package/dist/host/hook-registry.js +7 -5
  8. package/dist/host/manifest-types.d.ts +103 -0
  9. package/dist/host/manifest-types.js +2 -0
  10. package/dist/host/manifest.d.ts +2 -94
  11. package/dist/host/manifest.js +27 -19
  12. package/dist/host/node/discovery.js +23 -18
  13. package/dist/host/node/install.js +252 -200
  14. package/dist/host/node/loader.js +84 -66
  15. package/dist/host/node/open-flags.d.ts +18 -0
  16. package/dist/host/node/open-flags.js +14 -0
  17. package/dist/host/node/package-files.js +18 -12
  18. package/dist/host/node/source-drafts.js +83 -56
  19. package/dist/host/plugin-claims.js +3 -1
  20. package/dist/host/ports.d.ts +1 -1
  21. package/dist/host/tool-contributions.js +3 -1
  22. package/dist/host/worker/protocol.js +8 -6
  23. package/dist/host/worker/run-call.js +20 -17
  24. package/package.json +5 -5
  25. package/dist/glue/attachment-points/content-lifecycle.d.ts.map +0 -1
  26. package/dist/glue/attachment-points/content-lifecycle.js.map +0 -1
  27. package/dist/glue/attachment-points/events.d.ts.map +0 -1
  28. package/dist/glue/attachment-points/events.js.map +0 -1
  29. package/dist/glue/attachment-points/tool-registration.d.ts.map +0 -1
  30. package/dist/glue/attachment-points/tool-registration.js.map +0 -1
  31. package/dist/glue/capability-gate.d.ts.map +0 -1
  32. package/dist/glue/capability-gate.js.map +0 -1
  33. package/dist/glue/dispatch.d.ts.map +0 -1
  34. package/dist/glue/dispatch.js.map +0 -1
  35. package/dist/glue/index.d.ts.map +0 -1
  36. package/dist/glue/index.js.map +0 -1
  37. package/dist/glue/manifest.d.ts.map +0 -1
  38. package/dist/glue/manifest.js.map +0 -1
  39. package/dist/glue/ports.d.ts.map +0 -1
  40. package/dist/glue/ports.js.map +0 -1
  41. package/dist/host/activation.d.ts.map +0 -1
  42. package/dist/host/activation.js.map +0 -1
  43. package/dist/host/attach-loaded-plugin.d.ts.map +0 -1
  44. package/dist/host/attach-loaded-plugin.js.map +0 -1
  45. package/dist/host/browser-providers.d.ts.map +0 -1
  46. package/dist/host/browser-providers.js.map +0 -1
  47. package/dist/host/bundled-initialization.d.ts.map +0 -1
  48. package/dist/host/bundled-initialization.js.map +0 -1
  49. package/dist/host/capability-sdk.d.ts.map +0 -1
  50. package/dist/host/capability-sdk.js.map +0 -1
  51. package/dist/host/claim-conflicts.d.ts.map +0 -1
  52. package/dist/host/claim-conflicts.js.map +0 -1
  53. package/dist/host/contributions.d.ts.map +0 -1
  54. package/dist/host/contributions.js.map +0 -1
  55. package/dist/host/declarative-enable.d.ts.map +0 -1
  56. package/dist/host/declarative-enable.js.map +0 -1
  57. package/dist/host/discovery-types.d.ts.map +0 -1
  58. package/dist/host/discovery-types.js.map +0 -1
  59. package/dist/host/errors.d.ts.map +0 -1
  60. package/dist/host/errors.js.map +0 -1
  61. package/dist/host/hook-registry.d.ts.map +0 -1
  62. package/dist/host/hook-registry.js.map +0 -1
  63. package/dist/host/index.d.ts.map +0 -1
  64. package/dist/host/index.js.map +0 -1
  65. package/dist/host/manifest.d.ts.map +0 -1
  66. package/dist/host/manifest.js.map +0 -1
  67. package/dist/host/node/browser-provider-assets.d.ts.map +0 -1
  68. package/dist/host/node/browser-provider-assets.js.map +0 -1
  69. package/dist/host/node/discovery.d.ts.map +0 -1
  70. package/dist/host/node/discovery.js.map +0 -1
  71. package/dist/host/node/index.d.ts.map +0 -1
  72. package/dist/host/node/index.js.map +0 -1
  73. package/dist/host/node/install.d.ts.map +0 -1
  74. package/dist/host/node/install.js.map +0 -1
  75. package/dist/host/node/loader.d.ts.map +0 -1
  76. package/dist/host/node/loader.js.map +0 -1
  77. package/dist/host/node/module-snapshot.d.ts.map +0 -1
  78. package/dist/host/node/module-snapshot.js.map +0 -1
  79. package/dist/host/node/package-files.d.ts.map +0 -1
  80. package/dist/host/node/package-files.js.map +0 -1
  81. package/dist/host/node/source-drafts.d.ts.map +0 -1
  82. package/dist/host/node/source-drafts.js.map +0 -1
  83. package/dist/host/plugin-claims.d.ts.map +0 -1
  84. package/dist/host/plugin-claims.js.map +0 -1
  85. package/dist/host/plugin-format.d.ts.map +0 -1
  86. package/dist/host/plugin-format.js.map +0 -1
  87. package/dist/host/ports.d.ts.map +0 -1
  88. package/dist/host/ports.js.map +0 -1
  89. package/dist/host/quarantine.d.ts.map +0 -1
  90. package/dist/host/quarantine.js.map +0 -1
  91. package/dist/host/repo.memory.d.ts.map +0 -1
  92. package/dist/host/repo.memory.js.map +0 -1
  93. package/dist/host/source-policy.d.ts.map +0 -1
  94. package/dist/host/source-policy.js.map +0 -1
  95. package/dist/host/sql/index.d.ts.map +0 -1
  96. package/dist/host/sql/index.js.map +0 -1
  97. package/dist/host/sql/repo.d.ts.map +0 -1
  98. package/dist/host/sql/repo.js.map +0 -1
  99. package/dist/host/sql/repo.rows.d.ts.map +0 -1
  100. package/dist/host/sql/repo.rows.js.map +0 -1
  101. package/dist/host/tool-contributions.d.ts.map +0 -1
  102. package/dist/host/tool-contributions.js.map +0 -1
  103. package/dist/host/uninstall.d.ts.map +0 -1
  104. package/dist/host/uninstall.js.map +0 -1
  105. package/dist/host/worker/import-seam.d.ts.map +0 -1
  106. package/dist/host/worker/import-seam.js.map +0 -1
  107. package/dist/host/worker/index.d.ts.map +0 -1
  108. package/dist/host/worker/index.js.map +0 -1
  109. package/dist/host/worker/protocol.d.ts.map +0 -1
  110. package/dist/host/worker/protocol.js.map +0 -1
  111. package/dist/host/worker/run-call.d.ts.map +0 -1
  112. package/dist/host/worker/run-call.js.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # @jini-ai/plugins
2
2
 
3
+ ## 0.5.2 — 2026-10-22
4
+
5
+ - 2026-10-22: Optional declared effect on plugin tool contributions, security fixes, complexity refactors, coverage.
6
+
3
7
  ## 0.5.1 — 2026-10-13
4
8
 
5
9
  - The plugin manifest is `jini.plugin.json` and the plugin SDK specifier is `@jini-ai/plugin-sdk`. `tovu.plugin.json` and `@tovu/sdk` are still read as legacy aliases (the new name wins when both exist); installs and drafts write only the new name. `./host` exports `PLUGIN_MANIFEST_FILENAME`, `PLUGIN_MANIFEST_FILENAMES`, `LEGACY_PLUGIN_MANIFEST_FILENAME`, `PLUGIN_SDK_SPECIFIER`, `PLUGIN_SDK_SPECIFIERS`, `LEGACY_PLUGIN_SDK_SPECIFIER` and `canonicalizePluginManifest`.
@@ -1,13 +1,6 @@
1
1
  /** Bundled chart declarations only. ADR-025 trust comes from composition, never the manifest. */
2
- import type { PluginValidationError } from './manifest.js';
3
- export interface BrowserProviderDeclaration {
4
- readonly id: string;
5
- readonly kind: 'chart';
6
- readonly contractVersion: 1;
7
- readonly kinds: readonly string[];
8
- readonly javascript: string;
9
- readonly stylesheet?: string;
10
- }
2
+ import type { BrowserProviderDeclaration, PluginValidationError } from './manifest-types.js';
3
+ export type { BrowserProviderDeclaration } from './manifest-types.js';
11
4
  export interface BrowserProviderAsset {
12
5
  readonly path: string;
13
6
  readonly digest: string;
@@ -1,7 +1,38 @@
1
+ import { isNonArrayRecord } from '@jini-ai/core/records';
1
2
  /** Portable package-relative paths. Refuse dot segments, URL syntax and alternate separators. */
2
3
  export function isPluginRelativePath({ path }, _options = {}) {
3
4
  return path.length > 0 && !/[\\:\u0000-\u001f]/.test(path) && path.split('/').every((segment) => segment.length > 0 && segment !== '.' && segment !== '..');
4
5
  }
6
+ function validChartKinds({ kinds }, _options = {}) {
7
+ return Array.isArray(kinds) && kinds.length > 0
8
+ && !kinds.some((kind) => typeof kind !== 'string' || kind.trim() === '')
9
+ && new Set(kinds).size === kinds.length;
10
+ }
11
+ function validateBrowserProviderDeclaration({ provider, ids }, _options = {}) {
12
+ const errors = [];
13
+ if (Object.keys(provider).some((key) => !['id', 'kind', 'contractVersion', 'kinds', 'javascript', 'stylesheet'].includes(key)))
14
+ errors.push('Unknown browser provider field.');
15
+ if (typeof provider.id !== 'string' || !/^[a-z0-9][a-z0-9.-]*$/.test(provider.id) || ids.has(provider.id))
16
+ errors.push('Browser provider id must be unique and non-empty.');
17
+ if (typeof provider.id === 'string')
18
+ ids.add(provider.id);
19
+ if (provider.kind !== 'chart' || provider.contractVersion !== 1)
20
+ errors.push('Only chart contractVersion 1 is supported.');
21
+ if (!validChartKinds({ kinds: provider.kinds }))
22
+ errors.push('Chart kinds must be unique non-empty strings.');
23
+ return errors;
24
+ }
25
+ function validateBrowserProviderAssets({ provider, integrity }, _options = {}) {
26
+ const errors = [];
27
+ for (const [key, suffix] of [['javascript', /\.(?:m?js)$/], ['stylesheet', /\.css$/]]) {
28
+ const file = provider[key];
29
+ if (key === 'stylesheet' && file === undefined)
30
+ continue;
31
+ if (typeof file !== 'string' || !isPluginRelativePath({ path: file }) || !file.startsWith('client/') || !suffix.test(file) || !/^sha256-[0-9a-f]{64}$/.test(String(integrity[file])))
32
+ errors.push(`Browser provider ${key} must name a digest-covered client asset.`);
33
+ }
34
+ return errors;
35
+ }
5
36
  /** Collect static declaration errors; admission additionally requires compiled-in host pins.
6
37
  * @example validateBrowserProviders({ browserProviders, integrity })
7
38
  */
@@ -16,28 +47,13 @@ export function validateBrowserProviders({ browserProviders, integrity }, _optio
16
47
  }
17
48
  const ids = new Set();
18
49
  for (const value of browserProviders) {
19
- if (typeof value !== 'object' || value === null || Array.isArray(value)) {
50
+ if (!isNonArrayRecord({ value })) {
20
51
  invalid('Browser provider must be an object.');
21
52
  continue;
22
53
  }
23
54
  const provider = value;
24
- if (Object.keys(provider).some((key) => !['id', 'kind', 'contractVersion', 'kinds', 'javascript', 'stylesheet'].includes(key)))
25
- invalid('Unknown browser provider field.');
26
- if (typeof provider.id !== 'string' || !/^[a-z0-9][a-z0-9.-]*$/.test(provider.id) || ids.has(provider.id))
27
- invalid('Browser provider id must be unique and non-empty.');
28
- if (typeof provider.id === 'string')
29
- ids.add(provider.id);
30
- if (provider.kind !== 'chart' || provider.contractVersion !== 1)
31
- invalid('Only chart contractVersion 1 is supported.');
32
- if (!Array.isArray(provider.kinds) || provider.kinds.length === 0 || provider.kinds.some((kind) => typeof kind !== 'string' || kind.trim() === '') || new Set(provider.kinds).size !== provider.kinds.length)
33
- invalid('Chart kinds must be unique non-empty strings.');
34
- for (const [key, suffix] of [['javascript', /\.(?:m?js)$/], ['stylesheet', /\.css$/]]) {
35
- const file = provider[key];
36
- if (key === 'stylesheet' && file === undefined)
37
- continue;
38
- if (typeof file !== 'string' || !isPluginRelativePath({ path: file }) || !file.startsWith('client/') || !suffix.test(file) || !/^sha256-[0-9a-f]{64}$/.test(String(integrity[file])))
39
- invalid(`Browser provider ${key} must name a digest-covered client asset.`);
40
- }
55
+ validateBrowserProviderDeclaration({ provider, ids }).forEach(invalid);
56
+ validateBrowserProviderAssets({ provider, integrity }).forEach(invalid);
41
57
  }
42
58
  return errors;
43
59
  }
@@ -1,4 +1,4 @@
1
- import type { PluginManifest } from './manifest.js';
1
+ import type { PluginManifest } from './manifest-types.js';
2
2
  import type { PluginSdk } from './ports.js';
3
3
  export declare const PLUGIN_CONTRIBUTION_CAPABILITIES: readonly ["http.route.register", "tools.register", "render.contribute"];
4
4
  export type PluginRouteAccess = 'public' | 'member' | 'admin';
@@ -28,10 +28,13 @@ export interface PluginRouteContribution {
28
28
  readonly access: PluginRouteAccess;
29
29
  readonly handler: (required: PluginRouteInput, optional?: Record<string, never>) => PluginRouteResult | void | Promise<PluginRouteResult | void>;
30
30
  }
31
+ /** Declared change class. Only ever tightens host policy: `destructive` forces confirmation. */
32
+ export type PluginToolEffect = 'read' | 'write' | 'destructive';
31
33
  export interface PluginToolContribution {
32
34
  readonly name: string;
33
35
  readonly description: string;
34
36
  readonly inputSchema: Readonly<Record<string, unknown>>;
37
+ readonly effect?: PluginToolEffect;
35
38
  readonly handler: (required: PluginInvocationContext & {
36
39
  readonly input: unknown;
37
40
  }, optional?: Record<string, never>) => unknown | Promise<unknown>;
@@ -16,6 +16,21 @@ export function validatePluginRoute(required, _optional = {}) {
16
16
  if (!/^\/(?:[a-zA-Z0-9_-]+|:[a-zA-Z][a-zA-Z0-9_]*)(?:\/(?:[a-zA-Z0-9_-]+|:[a-zA-Z][a-zA-Z0-9_]*))*\/?$/.test(required.path) && required.path !== '/')
17
17
  throw new Error('unsafe plugin route path');
18
18
  }
19
+ /** Enforces the object-schema contract before and after plugin-controlled JSON serialization.
20
+ * Throws a fixed admission error. O(1) time/space. */
21
+ function requireObjectSchema({ schema }, _options = {}) {
22
+ if (!schema || typeof schema !== 'object' || Array.isArray(schema) || !('type' in schema) || schema.type !== 'object')
23
+ throw new Error('plugin tool input schema must describe an object');
24
+ return schema;
25
+ }
26
+ function serializePluginToolSchema({ schema }, _optional = {}) {
27
+ requireObjectSchema({ schema });
28
+ // Detach the JSON schema so later plugin mutations cannot alter the assistant contract.
29
+ const json = JSON.stringify(schema);
30
+ if (new TextEncoder().encode(json).byteLength > 65536)
31
+ throw new Error('plugin tool schema is too large');
32
+ return json;
33
+ }
19
34
  /** Bounded registration and detached snapshots; all runtime surfaces require a manifest claim.
20
35
  * SDK capability checks remain in buildCapabilityScopedSdk; this owner checks declarations too. */
21
36
  export function createPluginContributionCapture(required, optional = {}) {
@@ -60,14 +75,10 @@ export function createPluginContributionCapture(required, optional = {}) {
60
75
  throw new Error('duplicate plugin tool');
61
76
  if (typeof value.handler !== 'function' || typeof value.description !== 'string' || !value.description.trim() || value.description.length > 8000)
62
77
  throw new Error('plugin tool handler and description are required');
63
- const schema = value.inputSchema;
64
- if (!schema || typeof schema !== 'object' || Array.isArray(schema) || schema.type !== 'object')
65
- throw new Error('plugin tool input schema must describe an object');
66
- // Detach the JSON schema so later plugin mutations cannot alter the assistant contract.
67
- const json = JSON.stringify(schema);
68
- if (new TextEncoder().encode(json).byteLength > 65536)
69
- throw new Error('plugin tool schema is too large');
70
- tools.push(Object.freeze({ ...value, inputSchema: JSON.parse(json) }));
78
+ const json = serializePluginToolSchema({ schema: value.inputSchema });
79
+ const captured = { ...value };
80
+ const inputSchema = requireObjectSchema({ schema: JSON.parse(json) });
81
+ tools.push(Object.freeze({ ...captured, inputSchema }));
71
82
  } },
72
83
  widgets: { add(value, _optional = {}) {
73
84
  check();
@@ -1,4 +1,4 @@
1
- import type { PluginManifest, PluginValidationError } from "./manifest.js";
1
+ import type { PluginManifest, PluginValidationError } from "./manifest-types.js";
2
2
  /** A built-in plugin's in-code manifest-equivalent (ADR Decision item 4) — no tarball, no
3
3
  * integrity file (compiled-in code is definitionally not tampered), but still validated through
4
4
  * the same `validateManifest()` path as a site-installed plugin. */
@@ -20,7 +20,11 @@ function compareTb01(a, b) {
20
20
  return rankDiff;
21
21
  return a[0].localeCompare(b[0]);
22
22
  }
23
- /** The four JSON-primitive field types BR-06's declared-field vocabulary supports. */
23
+ /** The four JSON-primitive field types BR-06's declared-field vocabulary supports. The switch is
24
+ * exhaustive over `HookRegistryFieldDecl["type"]`, and `validateManifest` (`VALID_FIELD_TYPES`)
25
+ * refuses any other declared type before a plugin can attach, so there is no `default` arm: a type
26
+ * outside the union would fall through to `undefined`, which the only caller reads as a mismatch
27
+ * (still fail-closed). */
24
28
  function matchesDeclaredType(value, type) {
25
29
  switch (type) {
26
30
  case "integer":
@@ -31,15 +35,13 @@ function matchesDeclaredType(value, type) {
31
35
  return typeof value === "string";
32
36
  case "boolean":
33
37
  return typeof value === "boolean";
34
- default:
35
- return false;
36
38
  }
37
39
  }
38
40
  /** Last dot-segment of a declared `ext.{pluginId}.{field}` path — the field name a returned patch
39
41
  * key is checked against. */
40
42
  function fieldNameOf(declaredPath) {
41
- const segments = declaredPath.split(".");
42
- return segments[segments.length - 1] ?? declaredPath;
43
+ // `lastIndexOf` is -1 for a path with no dot, so the whole path is its own last segment.
44
+ return declaredPath.slice(declaredPath.lastIndexOf(".") + 1);
43
45
  }
44
46
  /** Calls one plugin's filter, re-shaping a thrown error into the module's own
45
47
  * `PluginHookFailedError` vocabulary — the ONE place `runBeforeSave`'s per-plugin work touches the
@@ -0,0 +1,103 @@
1
+ /** Manifest data contracts do not depend on validation or host composition. */
2
+ import type { PluginIdentityExtension } from '@jini-ai/core/plugin-directory';
3
+ export interface BrowserProviderDeclaration {
4
+ readonly id: string;
5
+ readonly kind: 'chart';
6
+ readonly contractVersion: 1;
7
+ readonly kinds: readonly string[];
8
+ readonly javascript: string;
9
+ readonly stylesheet?: string;
10
+ }
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`). */
13
+ export type PluginTier = "tier-1" | "tier-2" | "tier-3";
14
+ /** REQ-04's exactly-three v1 capability vocabulary, as manifest-declared strings (validated
15
+ * against this set by `validateManifest`; `@jini-ai/plugin-sdk`'s `CONTENT_READ`/`CONTENT_EXTEND`/
16
+ * `HOOKS_ATTACH` constants are the same literal values, kept independent here so this module has
17
+ * no dependency on the SDK package per the Module Map). Sourced from `core/`'s
18
+ * `SharedExtensionCapability` — the sibling `site-glue` mechanism's own capability vocabulary
19
+ * declares this same three-member set as its first three members; both import the one shared
20
+ * declaration rather than each retyping the literals (2026-08-20 swarm-consensus synthesis,
21
+ * Result 1). */
22
+ export type PluginCapability = string;
23
+ /** REQ-06 field declaration — `ext.{pluginId}.{field}` (BR-06). `queryable` MUST be `false` in
24
+ * v1 (EC-04); a `true` value is a validation error (`QUERYABLE_UNSUPPORTED_V1`), not silently
25
+ * coerced. */
26
+ export interface PluginManifestFieldDecl {
27
+ readonly path: string;
28
+ readonly type: "string" | "integer" | "number" | "boolean";
29
+ readonly queryable: boolean;
30
+ /**
31
+ * Optional, human-readable, action-oriented description of what this field represents and how an
32
+ * agent should use it (2026-08-26 addition — `features/plugin-runtime/capability-tool-registrations.ts`
33
+ * is the sole consumer: it is folded into the indexed `search_tools` description for this plugin's
34
+ * capability-read tool when the plugin is enabled). Absent on every pre-existing manifest — this
35
+ * is additive, not a widened requirement, so no previously-valid manifest becomes invalid by
36
+ * omitting it; a plugin author who wants their capability to rank well against a real user query
37
+ * simply adds one.
38
+ */
39
+ readonly description?: string;
40
+ }
41
+ /** `jini.plugin.json` — the ecosystem compatibility surface (state.spec.md §2, ADR-004). */
42
+ export interface PluginManifest {
43
+ /** Storage/activation key. Publisher identity lives in extensions[identityNamespace].id. */
44
+ readonly id: string;
45
+ readonly keywords?: readonly string[];
46
+ readonly extensions?: Readonly<Record<string, PluginIdentityExtension>>;
47
+ readonly name: string;
48
+ readonly version: string;
49
+ readonly sdkRange: string;
50
+ readonly engine: number;
51
+ readonly tier: PluginTier;
52
+ readonly capabilities: readonly string[];
53
+ readonly hooks: readonly string[];
54
+ readonly fields: readonly PluginManifestFieldDecl[];
55
+ readonly integrity: Readonly<Record<string, string>>;
56
+ /** Parsed-and-stored, UNUSED in v1 (forward-compat, no behavior — state.spec.md §2). */
57
+ readonly adminSurfaces?: readonly unknown[] | null;
58
+ /** Reviewed bundled chart assets only; host admission supplies trust outside this manifest. */
59
+ readonly browserProviders?: readonly BrowserProviderDeclaration[];
60
+ /** Content types the plugin declares (AW-7 Tier 1, 2026-10-04) — no longer unused: validated by
61
+ * `declarative-content-types.ts`, claimed by key (`plugin-claims.ts`), created at enable. */
62
+ readonly contentTypes?: readonly unknown[] | null;
63
+ readonly provenance?: {
64
+ readonly sourceUrl?: string;
65
+ readonly signature?: string;
66
+ } | null;
67
+ readonly dependencies?: Readonly<Record<string, string>> | null;
68
+ /**
69
+ * What this plugin says it provides, by name (2026-10-04, conflict detection — see
70
+ * `plugin-claims.ts` and `ADS-memory/specs/005-plugin-system/conflicts.spec.md`). Optional and
71
+ * additive: a manifest without it claims only what its other fields already imply (its hooks and,
72
+ * when it declares `fields`, its generated capability tool). Each entry is a CLAIM: two enabled
73
+ * plugins, or a plugin and core, naming the same thing is refused at enable time and quarantined
74
+ * 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
+ * still binding for conflicts, so a plugin cannot squat a name today that a future mount would
77
+ * then have to arbitrate.
78
+ */
79
+ readonly contributes?: PluginContributions | null;
80
+ }
81
+ /** `jini.plugin.json`'s `contributes` block — every list optional, every entry a plain name. */
82
+ export interface PluginContributions {
83
+ /** `"METHOD /path"` or `"/path"` (every method). Parameter names do not distinguish routes. */
84
+ readonly routes?: readonly string[];
85
+ /** Agent tool ids. The generated prefixes `plugin_capability_`/`agent_plugin_` are reserved. */
86
+ readonly tools?: readonly string[];
87
+ /** Data-module tables — must sit in this plugin's own `p_{id}__` namespace (ADR-023 §5). */
88
+ readonly tables?: readonly string[];
89
+ readonly settings?: readonly string[];
90
+ readonly widgets?: readonly string[];
91
+ /** Permission ids this plugin DEFINES (not ones it merely requires). */
92
+ readonly permissions?: readonly string[];
93
+ }
94
+ /** One validation-vocabulary entry (errors.spec.md §3). `file` names the offending packaged file
95
+ * when applicable; `null` for manifest-level errors with no single implicated file. This is the
96
+ * shared shape used verbatim by both `PLUGINS_LIST.plugins[].errors[]` and
97
+ * `PLUGIN_INVALID.details.errors[]` (errors.spec.md §4 — "one validator, two surfaces"). */
98
+ export interface PluginValidationError {
99
+ readonly code: string;
100
+ readonly file: string | null;
101
+ readonly message: string;
102
+ }
103
+ //# sourceMappingURL=manifest-types.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=manifest-types.js.map
@@ -24,101 +24,9 @@
24
24
  * engine/tier, capabilities, hooks, fields) rather than stopping at the first, returning them in
25
25
  * `errors[]` — it never throws. Verified against `__tests__/unit/manifest.unit.test.ts`.
26
26
  */
27
- import { type BrowserProviderDeclaration } from "./browser-providers.js";
28
- import { type PluginIdentityExtension } from "@jini-ai/core/plugin-directory";
27
+ import type { PluginValidationError } from './manifest-types.js';
28
+ export type { PluginTier, PluginCapability, PluginManifestFieldDecl, PluginManifest, PluginContributions, PluginValidationError } from './manifest-types.js';
29
29
  import type { HookPoints, ManifestHostPorts } from "./ports.js";
30
- /** ADR-024 §1 trust-tier vocabulary (1.1.1 REQ-01 fix). Literal encoding reused verbatim from the
31
- * existing, approved SPEC-032/ADR-023 precedent (`DataModuleDecl.pluginTier`). */
32
- export type PluginTier = "tier-1" | "tier-2" | "tier-3";
33
- /** REQ-04's exactly-three v1 capability vocabulary, as manifest-declared strings (validated
34
- * against this set by `validateManifest`; `@jini-ai/plugin-sdk`'s `CONTENT_READ`/`CONTENT_EXTEND`/
35
- * `HOOKS_ATTACH` constants are the same literal values, kept independent here so this module has
36
- * no dependency on the SDK package per the Module Map). Sourced from `core/`'s
37
- * `SharedExtensionCapability` — the sibling `site-glue` mechanism's own capability vocabulary
38
- * declares this same three-member set as its first three members; both import the one shared
39
- * declaration rather than each retyping the literals (2026-08-20 swarm-consensus synthesis,
40
- * Result 1). */
41
- export type PluginCapability = string;
42
- /** REQ-06 field declaration — `ext.{pluginId}.{field}` (BR-06). `queryable` MUST be `false` in
43
- * v1 (EC-04); a `true` value is a validation error (`QUERYABLE_UNSUPPORTED_V1`), not silently
44
- * coerced. */
45
- export interface PluginManifestFieldDecl {
46
- readonly path: string;
47
- readonly type: "string" | "integer" | "number" | "boolean";
48
- readonly queryable: boolean;
49
- /**
50
- * Optional, human-readable, action-oriented description of what this field represents and how an
51
- * agent should use it (2026-08-26 addition — `features/plugin-runtime/capability-tool-registrations.ts`
52
- * is the sole consumer: it is folded into the indexed `search_tools` description for this plugin's
53
- * capability-read tool when the plugin is enabled). Absent on every pre-existing manifest — this
54
- * is additive, not a widened requirement, so no previously-valid manifest becomes invalid by
55
- * omitting it; a plugin author who wants their capability to rank well against a real user query
56
- * simply adds one.
57
- */
58
- readonly description?: string;
59
- }
60
- /** `jini.plugin.json` — the ecosystem compatibility surface (state.spec.md §2, ADR-004). */
61
- export interface PluginManifest {
62
- /** Storage/activation key. Publisher identity lives in extensions[identityNamespace].id. */
63
- readonly id: string;
64
- readonly keywords?: readonly string[];
65
- readonly extensions?: Readonly<Record<string, PluginIdentityExtension>>;
66
- readonly name: string;
67
- readonly version: string;
68
- readonly sdkRange: string;
69
- readonly engine: number;
70
- readonly tier: PluginTier;
71
- readonly capabilities: readonly string[];
72
- readonly hooks: readonly string[];
73
- readonly fields: readonly PluginManifestFieldDecl[];
74
- readonly integrity: Readonly<Record<string, string>>;
75
- /** Parsed-and-stored, UNUSED in v1 (forward-compat, no behavior — state.spec.md §2). */
76
- readonly adminSurfaces?: readonly unknown[] | null;
77
- /** Reviewed bundled chart assets only; host admission supplies trust outside this manifest. */
78
- readonly browserProviders?: readonly BrowserProviderDeclaration[];
79
- /** Content types the plugin declares (AW-7 Tier 1, 2026-10-04) — no longer unused: validated by
80
- * `declarative-content-types.ts`, claimed by key (`plugin-claims.ts`), created at enable. */
81
- readonly contentTypes?: readonly unknown[] | null;
82
- readonly provenance?: {
83
- readonly sourceUrl?: string;
84
- readonly signature?: string;
85
- } | null;
86
- readonly dependencies?: Readonly<Record<string, string>> | null;
87
- /**
88
- * What this plugin says it provides, by name (2026-10-04, conflict detection — see
89
- * `plugin-claims.ts` and `ADS-memory/specs/005-plugin-system/conflicts.spec.md`). Optional and
90
- * additive: a manifest without it claims only what its other fields already imply (its hooks and,
91
- * when it declares `fields`, its generated capability tool). Each entry is a CLAIM: two enabled
92
- * plugins, or a plugin and core, naming the same thing is refused at enable time and quarantined
93
- * at boot rather than silently letting one overwrite the other. Declaring a surface the runtime
94
- * does not mount yet (settings, widgets, routes — ADR-025/`adminSurfaces` are still unwired) is
95
- * still binding for conflicts, so a plugin cannot squat a name today that a future mount would
96
- * then have to arbitrate.
97
- */
98
- readonly contributes?: PluginContributions | null;
99
- }
100
- /** `jini.plugin.json`'s `contributes` block — every list optional, every entry a plain name. */
101
- export interface PluginContributions {
102
- /** `"METHOD /path"` or `"/path"` (every method). Parameter names do not distinguish routes. */
103
- readonly routes?: readonly string[];
104
- /** Agent tool ids. The generated prefixes `plugin_capability_`/`agent_plugin_` are reserved. */
105
- readonly tools?: readonly string[];
106
- /** Data-module tables — must sit in this plugin's own `p_{id}__` namespace (ADR-023 §5). */
107
- readonly tables?: readonly string[];
108
- readonly settings?: readonly string[];
109
- readonly widgets?: readonly string[];
110
- /** Permission ids this plugin DEFINES (not ones it merely requires). */
111
- readonly permissions?: readonly string[];
112
- }
113
- /** One validation-vocabulary entry (errors.spec.md §3). `file` names the offending packaged file
114
- * when applicable; `null` for manifest-level errors with no single implicated file. This is the
115
- * shared shape used verbatim by both `PLUGINS_LIST.plugins[].errors[]` and
116
- * `PLUGIN_INVALID.details.errors[]` (errors.spec.md §4 — "one validator, two surfaces"). */
117
- export interface PluginValidationError {
118
- readonly code: string;
119
- readonly file: string | null;
120
- readonly message: string;
121
- }
122
30
  export interface ValidateManifestRequired<H extends HookPoints = HookPoints> extends ManifestHostPorts<H> {
123
31
  /** An already-parsed `jini.plugin.json` value (unparseable JSON is `discovery.ts`'s concern —
124
32
  * this function receives a JS value, never a file path or raw bytes). */
@@ -28,6 +28,7 @@ import * as semver from "semver";
28
28
  import { PLUGIN_MANIFEST_FILENAME } from "./plugin-format.js";
29
29
  import { validateBrowserProviders } from "./browser-providers.js";
30
30
  import { readPluginIdentity, validatePluginIdentity } from "@jini-ai/core/plugin-directory";
31
+ import { isNonArrayRecord } from "@jini-ai/core/records";
31
32
  /**
32
33
  * Validates one already-parsed manifest against BR-02 steps (2)-(6), collecting every applicable
33
34
  * error rather than stopping at the first (BR-02: "collect ALL statically-determinable errors").
@@ -161,13 +162,17 @@ function validateIdentityFields(raw) {
161
162
  if (raw.version !== undefined && (typeof raw.version !== "string" || !isExactSemver(raw.version))) {
162
163
  errors.push(malformed(`version '${String(raw.version)}' must be a semver version (e.g. 1.0.0)`));
163
164
  }
164
- if (raw.integrity === undefined)
165
- return errors;
166
- if (typeof raw.integrity !== "object" || raw.integrity === null || Array.isArray(raw.integrity)) {
167
- errors.push(malformed("'integrity' must be an object mapping packaged file paths to sha256 hashes"));
168
- return errors;
165
+ return [...errors, ...validateIntegrity({ integrity: raw.integrity })];
166
+ }
167
+ function validateIntegrity({ integrity }, _optional = {}) {
168
+ if (integrity === undefined)
169
+ return [];
170
+ const input = { value: integrity };
171
+ if (!isNonArrayRecord(input)) {
172
+ return [malformed("'integrity' must be an object mapping packaged file paths to sha256 hashes")];
169
173
  }
170
- for (const [file, hash] of Object.entries(raw.integrity)) {
174
+ const errors = [];
175
+ for (const [file, hash] of Object.entries(input.value)) {
171
176
  if (file === "" || typeof hash !== "string" || !INTEGRITY_HASH_PATTERN.test(hash)) {
172
177
  errors.push(malformed(`integrity entry '${file}' must be 'sha256-' followed by 64 lowercase hex characters`));
173
178
  }
@@ -362,19 +367,22 @@ function validateContributes(raw, id) {
362
367
  }
363
368
  const errors = [];
364
369
  for (const [key, list] of Object.entries(raw.contributes)) {
365
- if (!CONTRIBUTION_KEY_SET.has(key)) {
366
- errors.push(contributesInvalid(`unknown contributes key '${key}' (expected one of ${CONTRIBUTION_KEYS.join(", ")})`));
367
- continue;
368
- }
369
- if (!Array.isArray(list) || list.some((entry) => typeof entry !== "string" || entry.trim() === "")) {
370
- errors.push(contributesInvalid(`contributes.${key} must be a list of non-empty strings`));
371
- continue;
372
- }
373
- for (const entry of list) {
374
- const error = validateContribution(key, entry, id);
375
- if (error)
376
- errors.push(error);
377
- }
370
+ errors.push(...validateContributionList({ key, list, id }));
371
+ }
372
+ return errors;
373
+ }
374
+ function validateContributionList({ key, list, id }, _optional = {}) {
375
+ if (!CONTRIBUTION_KEY_SET.has(key)) {
376
+ return [contributesInvalid(`unknown contributes key '${key}' (expected one of ${CONTRIBUTION_KEYS.join(", ")})`)];
377
+ }
378
+ if (!Array.isArray(list) || list.some((entry) => typeof entry !== "string" || entry.trim() === "")) {
379
+ return [contributesInvalid(`contributes.${key} must be a list of non-empty strings`)];
380
+ }
381
+ const errors = [];
382
+ for (const entry of list) {
383
+ const error = validateContribution(key, entry, id);
384
+ if (error)
385
+ errors.push(error);
378
386
  }
379
387
  return errors;
380
388
  }
@@ -134,7 +134,26 @@ async function pickLatestVersionFolder(idFolderPath) {
134
134
  return 1;
135
135
  return b.localeCompare(a);
136
136
  });
137
- return sorted[0] ?? null;
137
+ return sorted[0];
138
+ }
139
+ /** Activation pins must be exact, path-safe semver; a malformed pin is the caller's fault, not a plugin's. */
140
+ function assertSafeRequestedVersion(requestedVersion) {
141
+ if (requestedVersion !== undefined && (!semver.valid(requestedVersion) || !/^[0-9A-Za-z][0-9A-Za-z.+-]*$/.test(requestedVersion))) {
142
+ throw new PluginDiscoveryVersionError('The requested plugin activation version is not a safe semantic version.');
143
+ }
144
+ }
145
+ /** The first manifest present (current name, then the legacy alias); `missing` when neither exists. */
146
+ async function readSiteManifest(versionDir) {
147
+ for (const filename of PLUGIN_MANIFEST_FILENAMES) { // legacy alias
148
+ try {
149
+ return { missing: false, manifestValue: parseManifestJson(await readFile(path.join(versionDir, filename), "utf8")) };
150
+ }
151
+ catch (error) {
152
+ if (error?.code !== "ENOENT")
153
+ throw error;
154
+ }
155
+ }
156
+ return { missing: true, manifestValue: null };
138
157
  }
139
158
  /**
140
159
  * The installer refuses a sideloaded tier-2 package (`install.ts`'s `checkTierAndCode`): a package
@@ -148,25 +167,11 @@ async function pickLatestVersionFolder(idFolderPath) {
148
167
  async function discoverOneSiteCandidate(installDir, idFolderName, builtInIds, host, options = {}) {
149
168
  const idFolderPath = path.join(installDir, idFolderName);
150
169
  const requestedVersion = options.versions?.get(idFolderName);
151
- if (requestedVersion !== undefined && (!semver.valid(requestedVersion) || !/^[0-9A-Za-z][0-9A-Za-z.+-]*$/.test(requestedVersion))) {
152
- throw new PluginDiscoveryVersionError('The requested plugin activation version is not a safe semantic version.');
153
- }
170
+ assertSafeRequestedVersion(requestedVersion);
154
171
  const versionFolderName = requestedVersion ?? await pickLatestVersionFolder(idFolderPath);
155
172
  if (versionFolderName === null)
156
173
  return null;
157
- let manifestValue = null;
158
- let missing = true;
159
- for (const filename of PLUGIN_MANIFEST_FILENAMES) { // legacy alias
160
- try {
161
- manifestValue = parseManifestJson(await readFile(path.join(idFolderPath, versionFolderName, filename), "utf8"));
162
- missing = false;
163
- break;
164
- }
165
- catch (error) {
166
- if (error?.code !== "ENOENT")
167
- throw error;
168
- }
169
- }
174
+ const { missing, manifestValue } = await readSiteManifest(path.join(idFolderPath, versionFolderName));
170
175
  const errors = missing
171
176
  ? [{ code: "MANIFEST_MISSING", file: PLUGIN_MANIFEST_FILENAME, message: `${PLUGIN_MANIFEST_FILENAME} was not found` }]
172
177
  : [...validateManifest({ ...host, manifest: manifestValue, folderName: idFolderName, builtInIds }).errors, ...host.tierPolicy.siteErrors({ manifestValue })];
@@ -185,7 +190,7 @@ function markCaseInsensitiveDuplicates(records) {
185
190
  countByLowerId.set(key, (countByLowerId.get(key) ?? 0) + 1);
186
191
  }
187
192
  return records.map((record) => {
188
- const isDuplicate = (countByLowerId.get(record.id.toLowerCase()) ?? 0) > 1;
193
+ const isDuplicate = countByLowerId.get(record.id.toLowerCase()) > 1;
189
194
  if (!isDuplicate)
190
195
  return record;
191
196
  const errors = [