@jini-ai/plugins 0.0.0-stage → 0.4.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 (84) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/LICENSE +201 -0
  3. package/README.md +60 -2
  4. package/dist/glue/attachment-points/content-lifecycle.d.ts +52 -0
  5. package/dist/glue/attachment-points/content-lifecycle.js +15 -0
  6. package/dist/glue/attachment-points/events.d.ts +12 -0
  7. package/dist/glue/attachment-points/events.js +5 -0
  8. package/dist/glue/attachment-points/tool-registration.d.ts +23 -0
  9. package/dist/glue/attachment-points/tool-registration.js +43 -0
  10. package/dist/glue/capability-gate.d.ts +73 -0
  11. package/dist/glue/capability-gate.js +41 -0
  12. package/dist/glue/dispatch.d.ts +20 -0
  13. package/dist/glue/dispatch.js +9 -0
  14. package/dist/glue/index.d.ts +8 -0
  15. package/dist/glue/index.js +8 -0
  16. package/dist/glue/manifest.d.ts +43 -0
  17. package/dist/glue/manifest.js +106 -0
  18. package/dist/glue/ports.d.ts +60 -0
  19. package/dist/glue/ports.js +2 -0
  20. package/dist/host/activation.d.ts +118 -0
  21. package/dist/host/activation.js +104 -0
  22. package/dist/host/attach-loaded-plugin.d.ts +37 -0
  23. package/dist/host/attach-loaded-plugin.js +19 -0
  24. package/dist/host/capability-sdk.d.ts +74 -0
  25. package/dist/host/capability-sdk.js +94 -0
  26. package/dist/host/claim-conflicts.d.ts +101 -0
  27. package/dist/host/claim-conflicts.js +139 -0
  28. package/dist/host/contributions.d.ts +129 -0
  29. package/dist/host/contributions.js +167 -0
  30. package/dist/host/declarative-enable.d.ts +43 -0
  31. package/dist/host/declarative-enable.js +73 -0
  32. package/dist/host/discovery-types.d.ts +55 -0
  33. package/dist/host/discovery-types.js +2 -0
  34. package/dist/host/errors.d.ts +20 -0
  35. package/dist/host/errors.js +22 -0
  36. package/dist/host/hook-registry.d.ts +113 -0
  37. package/dist/host/hook-registry.js +190 -0
  38. package/dist/host/index.d.ts +19 -0
  39. package/dist/host/index.js +19 -0
  40. package/dist/host/manifest.d.ts +159 -0
  41. package/dist/host/manifest.js +417 -0
  42. package/dist/host/node/discovery.d.ts +32 -0
  43. package/dist/host/node/discovery.js +241 -0
  44. package/dist/host/node/index.d.ts +8 -0
  45. package/dist/host/node/index.js +8 -0
  46. package/dist/host/node/install.d.ts +118 -0
  47. package/dist/host/node/install.js +431 -0
  48. package/dist/host/node/loader.d.ts +55 -0
  49. package/dist/host/node/loader.js +146 -0
  50. package/dist/host/node/module-snapshot.d.ts +25 -0
  51. package/dist/host/node/module-snapshot.js +53 -0
  52. package/dist/host/node/package-files.d.ts +52 -0
  53. package/dist/host/node/package-files.js +214 -0
  54. package/dist/host/node/source-drafts.d.ts +98 -0
  55. package/dist/host/node/source-drafts.js +323 -0
  56. package/dist/host/plugin-claims.d.ts +75 -0
  57. package/dist/host/plugin-claims.js +182 -0
  58. package/dist/host/ports.d.ts +208 -0
  59. package/dist/host/ports.js +2 -0
  60. package/dist/host/quarantine.d.ts +19 -0
  61. package/dist/host/quarantine.js +28 -0
  62. package/dist/host/repo.memory.d.ts +27 -0
  63. package/dist/host/repo.memory.js +33 -0
  64. package/dist/host/source-policy.d.ts +18 -0
  65. package/dist/host/source-policy.js +13 -0
  66. package/dist/host/sql/index.d.ts +4 -0
  67. package/dist/host/sql/index.js +4 -0
  68. package/dist/host/sql/repo.d.ts +38 -0
  69. package/dist/host/sql/repo.js +50 -0
  70. package/dist/host/sql/repo.rows.d.ts +28 -0
  71. package/dist/host/sql/repo.rows.js +28 -0
  72. package/dist/host/tool-contributions.d.ts +26 -0
  73. package/dist/host/tool-contributions.js +42 -0
  74. package/dist/host/uninstall.d.ts +88 -0
  75. package/dist/host/uninstall.js +112 -0
  76. package/dist/host/worker/import-seam.d.ts +45 -0
  77. package/dist/host/worker/import-seam.js +52 -0
  78. package/dist/host/worker/index.d.ts +5 -0
  79. package/dist/host/worker/index.js +5 -0
  80. package/dist/host/worker/protocol.d.ts +62 -0
  81. package/dist/host/worker/protocol.js +31 -0
  82. package/dist/host/worker/run-call.d.ts +27 -0
  83. package/dist/host/worker/run-call.js +76 -0
  84. package/package.json +107 -3
@@ -0,0 +1,417 @@
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 `tovu.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
+ */
27
+ import * as semver from "semver";
28
+ import { readPluginIdentity, validatePluginIdentity } from "@jini-ai/core/plugin-directory";
29
+ /**
30
+ * Validates one already-parsed manifest against BR-02 steps (2)-(6), collecting every applicable
31
+ * error rather than stopping at the first (BR-02: "collect ALL statically-determinable errors").
32
+ * Pure — no I/O, no mutation of `manifest`.
33
+ *
34
+ * @throws Nothing — validation failures are reported via the returned `errors` array, never a
35
+ * thrown error (this function itself cannot fail; a malformed top-level shape, e.g. `manifest`
36
+ * being `null` or an array, is itself a `MANIFEST_MALFORMED` entry in the result, not a throw).
37
+ * @complexity O(fields.length + capabilities.length + hooks.length) — bounded by one manifest's
38
+ * own declared arrays, never by external/unbounded input.
39
+ */
40
+ /** REQ-01's required top-level manifest keys — every one of these must be present. */
41
+ const REQUIRED_KEYS = [
42
+ "id",
43
+ "name",
44
+ "version",
45
+ "sdkRange",
46
+ "engine",
47
+ "tier",
48
+ "capabilities",
49
+ "hooks",
50
+ "fields",
51
+ "integrity",
52
+ ];
53
+ /** REQ-01's "parsed-and-stored but unused in v1" forward-compat keys — allowed, never validated. */
54
+ const OPTIONAL_KEYS = ["adminSurfaces", "contentTypes", "provenance", "dependencies", "contributes", "keywords", "extensions"];
55
+ const ALLOWED_KEYS = new Set([...REQUIRED_KEYS, ...OPTIONAL_KEYS]);
56
+ const VALID_TIERS = new Set(["tier-1", "tier-2", "tier-3"]);
57
+ const VALID_FIELD_TYPES = new Set(["string", "integer", "number", "boolean"]);
58
+ /** The one plugin-contract version this runtime understands in v1 (REQ-01). A manifest declaring
59
+ * any other value is `ENGINE_UNSUPPORTED` — there is no older version to be backward-compatible
60
+ * with yet, so "not exactly 1" and "newer than supported" coincide in practice. */
61
+ const SUPPORTED_ENGINE_VERSION = 1;
62
+ const ID_PATTERN = /^[a-z0-9-]+$/;
63
+ const MAX_ID_LENGTH = 50;
64
+ function malformed(message) {
65
+ return { code: "MANIFEST_MALFORMED", file: null, message };
66
+ }
67
+ /** Unknown-key and missing-required-key checks (BR-02 step 1's manifest-shape half). */
68
+ function validateKeys(raw) {
69
+ const errors = [];
70
+ for (const key of Object.keys(raw)) {
71
+ if (!ALLOWED_KEYS.has(key)) {
72
+ errors.push(malformed(`unknown manifest key '${key}'`));
73
+ }
74
+ }
75
+ for (const key of REQUIRED_KEYS) {
76
+ if (raw[key] === undefined) {
77
+ errors.push(malformed(`missing required manifest field '${key}'`));
78
+ }
79
+ }
80
+ return errors;
81
+ }
82
+ /** id shape only: pattern + length (BR-02 step 2 half of id validation). */
83
+ function validateIdFormat(id) {
84
+ if (!ID_PATTERN.test(id) || id.length < 1 || id.length > MAX_ID_LENGTH) {
85
+ return [malformed(`id '${id}' must match ${ID_PATTERN} and be 1-${MAX_ID_LENGTH} characters`)];
86
+ }
87
+ return [];
88
+ }
89
+ /** Shared id grammar for source paths and manifests. Identity admission (reserved ids, folder
90
+ * match and built-in shadowing) still belongs to full manifest validation. */
91
+ export function validatePluginIdFormat(required, _optional = {}) {
92
+ return validateIdFormat(required.id);
93
+ }
94
+ /** The owner id the claim system gives Tovu core (`plugin-claims.ts` re-exports it). Conflict
95
+ * detection never compares an owner with itself, so a plugin with this id would never conflict with
96
+ * core's reserved routes, tools or permissions — it is refused as an id instead. */
97
+ export const CORE_OWNER_ID = "core";
98
+ /** id identity: reserved id + folder match + built-in shadowing (BR-02 step 3, DUP-01). */
99
+ function validateIdIdentity(id, folderName, builtInIds, coreOwnerName) {
100
+ const errors = [];
101
+ if (id === CORE_OWNER_ID) {
102
+ errors.push({ code: "ID_RESERVED", file: null, message: `id '${id}' is reserved for ${coreOwnerName}` });
103
+ }
104
+ if (id !== folderName) {
105
+ errors.push({
106
+ code: "ID_FOLDER_MISMATCH",
107
+ file: null,
108
+ message: `manifest id '${id}' does not match its install folder name '${folderName}'`,
109
+ });
110
+ }
111
+ if (builtInIds.some((builtInId) => builtInId.toLowerCase() === id.toLowerCase())) {
112
+ errors.push({
113
+ code: "SHADOWS_BUILT_IN",
114
+ file: null,
115
+ message: `id '${id}' shadows an existing built-in plugin id`,
116
+ });
117
+ }
118
+ return errors;
119
+ }
120
+ /** id: presence/type gate, then format + folder match + built-in shadowing (BR-02 step 2/3). */
121
+ function validateId(raw, folderName, builtInIds, coreOwnerName) {
122
+ const id = typeof raw.id === "string" ? raw.id : undefined;
123
+ if (raw.id !== undefined && id === undefined) {
124
+ return { errors: [malformed("'id' must be a string")], id };
125
+ }
126
+ if (id === undefined) {
127
+ return { errors: [], id };
128
+ }
129
+ return { errors: [...validateIdFormat(id), ...validateIdIdentity(id, folderName, builtInIds, coreOwnerName)], id };
130
+ }
131
+ /** The one hash format `loader.ts` computes and compares (`sha256-` + 64 lowercase hex). */
132
+ const INTEGRITY_HASH_PATTERN = /^sha256-[0-9a-f]{64}$/;
133
+ /**
134
+ * `value` is a strict SemVer string written in canonical form. `semver.valid()` alone is not enough:
135
+ * it also accepts `v1.0.0` or padded text, and the canonical string it returns drops build metadata,
136
+ * so comparing against it would refuse a valid `1.0.0+build.42`. The build suffix is re-appended.
137
+ *
138
+ * @complexity O(n) for n characters.
139
+ */
140
+ function isExactSemver(value) {
141
+ const parsed = semver.parse(value);
142
+ if (parsed === null)
143
+ return false;
144
+ const build = parsed.build.length > 0 ? `+${parsed.build.join(".")}` : "";
145
+ return `${parsed.version}${build}` === value;
146
+ }
147
+ /**
148
+ * name, version and integrity shapes (REQ-01: `name`, `version` (semver), `integrity` (SHA-256 per
149
+ * packaged file)). Presence is `validateKeys`' job; a present-but-wrong value is caught here so it
150
+ * fails at discovery rather than later: a non-semver version cannot take part in latest-by-semver
151
+ * selection (AC-09), and a malformed hash can never match, so it would only surface at load time
152
+ * as a misleading INTEGRITY_FAILED (F3193).
153
+ */
154
+ function validateIdentityFields(raw) {
155
+ const errors = [];
156
+ if (raw.name !== undefined && (typeof raw.name !== "string" || raw.name.trim() === "")) {
157
+ errors.push(malformed("'name' must be a non-empty string"));
158
+ }
159
+ if (raw.version !== undefined && (typeof raw.version !== "string" || !isExactSemver(raw.version))) {
160
+ errors.push(malformed(`version '${String(raw.version)}' must be a semver version (e.g. 1.0.0)`));
161
+ }
162
+ if (raw.integrity === undefined)
163
+ return errors;
164
+ if (typeof raw.integrity !== "object" || raw.integrity === null || Array.isArray(raw.integrity)) {
165
+ errors.push(malformed("'integrity' must be an object mapping packaged file paths to sha256 hashes"));
166
+ return errors;
167
+ }
168
+ for (const [file, hash] of Object.entries(raw.integrity)) {
169
+ if (file === "" || typeof hash !== "string" || !INTEGRITY_HASH_PATTERN.test(hash)) {
170
+ errors.push(malformed(`integrity entry '${file}' must be 'sha256-' followed by 64 lowercase hex characters`));
171
+ }
172
+ }
173
+ return errors;
174
+ }
175
+ /** engine (BR-02 step 2). */
176
+ function validateEngine(raw) {
177
+ if (raw.engine === undefined) {
178
+ return [];
179
+ }
180
+ if (typeof raw.engine !== "number" || !Number.isInteger(raw.engine) || raw.engine < 1) {
181
+ return [malformed("'engine' must be a positive integer")];
182
+ }
183
+ if (raw.engine !== SUPPORTED_ENGINE_VERSION) {
184
+ return [
185
+ {
186
+ code: "ENGINE_UNSUPPORTED",
187
+ file: null,
188
+ message: `engine ${raw.engine} is not supported by this runtime (supports ${SUPPORTED_ENGINE_VERSION})`,
189
+ },
190
+ ];
191
+ }
192
+ return [];
193
+ }
194
+ /** tier (BR-02 step 2, ADR-024 §1 / 1.1.1 fix). */
195
+ function validateTier(raw) {
196
+ if (raw.tier === undefined) {
197
+ return [];
198
+ }
199
+ if (typeof raw.tier !== "string" || !VALID_TIERS.has(raw.tier)) {
200
+ return [malformed(`tier '${String(raw.tier)}' must be one of tier-1 | tier-2 | tier-3`)];
201
+ }
202
+ return [];
203
+ }
204
+ /** capabilities (BR-02 step 4, REQ-04). */
205
+ function validateCapabilities(raw, vocabulary) {
206
+ const errors = [];
207
+ const capabilities = Array.isArray(raw.capabilities) ? raw.capabilities : [];
208
+ if (raw.capabilities !== undefined && !Array.isArray(raw.capabilities)) {
209
+ errors.push(malformed("'capabilities' must be an array"));
210
+ }
211
+ for (const capability of capabilities) {
212
+ if (typeof capability !== "string" || !vocabulary.includes(capability)) {
213
+ errors.push({
214
+ code: "CAPABILITY_UNKNOWN",
215
+ file: null,
216
+ message: `capability '${String(capability)}' is outside the v1 vocabulary`,
217
+ });
218
+ }
219
+ }
220
+ return errors;
221
+ }
222
+ /** hooks (BR-02 step 5, REQ-05, INV-06 anti-hook-soup). */
223
+ function validateHooks(raw, hooksVocabulary) {
224
+ const errors = [];
225
+ const hooks = Array.isArray(raw.hooks) ? raw.hooks : [];
226
+ if (raw.hooks !== undefined && !Array.isArray(raw.hooks)) {
227
+ errors.push(malformed("'hooks' must be an array"));
228
+ }
229
+ for (const hook of hooks) {
230
+ if (typeof hook !== "string" || !hooksVocabulary.includes(hook)) {
231
+ errors.push({ code: "HOOK_UNKNOWN", file: null, message: `hook point '${String(hook)}' is not declared by core` });
232
+ }
233
+ }
234
+ return errors;
235
+ }
236
+ /** Path namespacing half of one `fields[]` entry (BR-02 step 6 part 1). */
237
+ function validateFieldPath(decl, expectedPrefix) {
238
+ if (typeof decl.path === "string" && decl.path.startsWith(expectedPrefix) && decl.path.length > expectedPrefix.length) {
239
+ return undefined;
240
+ }
241
+ return {
242
+ code: "FIELD_PATH_INVALID",
243
+ file: null,
244
+ message: `field path '${String(decl.path)}' must be namespaced to this plugin's own id ('${expectedPrefix}*')`,
245
+ };
246
+ }
247
+ /** Declared type half of one `fields[]` entry (BR-02 step 6 part 2). */
248
+ function validateFieldType(decl) {
249
+ if (typeof decl.type === "string" && VALID_FIELD_TYPES.has(decl.type))
250
+ return undefined;
251
+ return malformed(`field '${String(decl.path)}' has an unrecognized type '${String(decl.type)}'`);
252
+ }
253
+ /**
254
+ * `queryable` half of one `fields[]` entry (BR-02 step 6 part 3, EC-04).
255
+ *
256
+ * BUG FIX (this pass — found auditing this exact function for the complexity refactor, not
257
+ * introduced by it): the prior check was `decl.queryable === true`, which only ever rejects the
258
+ * literal boolean `true`. `PluginManifestFieldDecl.queryable` is a REQUIRED `boolean` field, but
259
+ * nothing enforced that shape — a manifest declaring `queryable: "true"` (a string), `queryable: 1`,
260
+ * or omitting `queryable` entirely all produced ZERO errors, silently accepted as if `queryable:
261
+ * false` had been declared. `queryable` currently has no downstream reader anywhere in this
262
+ * codebase (verified: `grep -rn '\.queryable\b'` finds only this file), so today's blast radius is
263
+ * a validator that doesn't validate rather than a live exploit — but the very first consumer that
264
+ * does `if (field.queryable)` on a manifest this function already certified as error-free would
265
+ * treat a JS-truthy non-boolean (`"true"`, `1`, `"false"` — also truthy!) as enabled, quietly
266
+ * defeating the "unsupported in v1" restriction this code exists to enforce. Fixed by requiring the
267
+ * boolean type itself first, matching how {@link validateFieldType} already validates shape before
268
+ * value for its own field. Regression: `manifest.unit.test.ts` ("a non-boolean queryable value...").
269
+ */
270
+ function validateFieldQueryable(decl) {
271
+ if (typeof decl.queryable !== "boolean") {
272
+ return malformed(`field '${String(decl.path)}' has an invalid 'queryable' value '${String(decl.queryable)}' — must be a boolean`);
273
+ }
274
+ if (decl.queryable === true) {
275
+ return {
276
+ code: "QUERYABLE_UNSUPPORTED_V1",
277
+ file: null,
278
+ message: `field '${String(decl.path)}' declares queryable:true, unsupported in v1 (OQ-04)`,
279
+ };
280
+ }
281
+ return undefined;
282
+ }
283
+ /** Optional `description` half of one `fields[]` entry (2026-08-26 addition, see
284
+ * `PluginManifestFieldDecl.description`'s own doc) — absent is always fine (most fields, and every
285
+ * pre-existing manifest, declare none); present-but-not-a-non-empty-string is rejected so a typo'd
286
+ * `description: ""` cannot silently ship an empty, useless search_tools description instead of a
287
+ * validation error a plugin author can act on. */
288
+ function validateFieldDescription(decl) {
289
+ if (decl.description === undefined)
290
+ return undefined;
291
+ if (typeof decl.description === "string" && decl.description.trim().length > 0)
292
+ return undefined;
293
+ return {
294
+ code: "FIELD_DESCRIPTION_INVALID",
295
+ file: null,
296
+ message: `field '${String(decl.path)}' declares a 'description' that must be a non-empty string when present`,
297
+ };
298
+ }
299
+ /** One `fields[]` entry (BR-02 step 6, REQ-06): path namespacing, declared type, `queryable`,
300
+ * optional `description` — each half delegated to its own validator (see each one's own doc), this
301
+ * function only shape-gates the entry itself and collects whichever of the four report an error. */
302
+ function validateField(field, expectedPrefix) {
303
+ if (typeof field !== "object" || field === null) {
304
+ return [malformed("each 'fields' entry must be an object")];
305
+ }
306
+ const decl = field;
307
+ return [validateFieldPath(decl, expectedPrefix), validateFieldType(decl), validateFieldQueryable(decl), validateFieldDescription(decl)].filter((error) => error !== undefined);
308
+ }
309
+ /** fields (BR-02 step 6, REQ-06) — `expectedPrefix` is constant across the array (it depends only
310
+ * on the manifest's own `id`, not on the field being checked), so it's computed once here rather
311
+ * than per-iteration. */
312
+ function validateFields(raw, id) {
313
+ const errors = [];
314
+ const fields = Array.isArray(raw.fields) ? raw.fields : [];
315
+ if (raw.fields !== undefined && !Array.isArray(raw.fields)) {
316
+ errors.push(malformed("'fields' must be an array"));
317
+ }
318
+ const expectedPrefix = `ext.${id ?? ""}.`;
319
+ for (const field of fields) {
320
+ errors.push(...validateField(field, expectedPrefix));
321
+ }
322
+ return errors;
323
+ }
324
+ /** The `contributes` lists `validateContributes` accepts, in the order claims are derived. */
325
+ export const CONTRIBUTION_KEYS = ["routes", "tools", "tables", "settings", "widgets", "permissions"];
326
+ const CONTRIBUTION_KEY_SET = new Set(CONTRIBUTION_KEYS);
327
+ /** Tool-id prefixes the runtime generates itself (`capability-tool-registrations.ts`,
328
+ * `agent-plugins/tool-registrations.ts`) — a plugin declaring one could impersonate another
329
+ * plugin's generated tool, so they are refused here, before conflict detection ever runs. */
330
+ const RESERVED_TOOL_PREFIXES = ["plugin_capability_", "agent_plugin_"];
331
+ const ROUTE_PATTERN = /^(?:(?:GET|HEAD|POST|PUT|PATCH|DELETE|OPTIONS|ANY|\*) )?\/\S*$/i;
332
+ function contributesInvalid(message) {
333
+ return { code: "CONTRIBUTES_INVALID", file: null, message };
334
+ }
335
+ /** Kind-specific shape checks, one per `contributes` list that has more than the shared rule —
336
+ * each returns the problem in words, or `undefined`. */
337
+ const CONTRIBUTION_CHECKS = {
338
+ routes: (entry) => (ROUTE_PATTERN.test(entry) ? undefined : "must be '/path' or 'METHOD /path'"),
339
+ tools: (entry) => RESERVED_TOOL_PREFIXES.some((prefix) => entry.startsWith(prefix)) ? "uses a prefix reserved for generated tools" : undefined,
340
+ tables: (entry, id) => {
341
+ const prefix = `p_${(id ?? "").replace(/-/g, "_")}__`;
342
+ return entry.startsWith(prefix) && entry.length > prefix.length ? undefined : `must be namespaced to this plugin ('${prefix}*')`;
343
+ },
344
+ };
345
+ /** One entry: the shared no-pattern rule, then its kind's own check. Plugins never claim a `*`
346
+ * prefix — reserving a whole namespace is core's privilege (see `claim-conflicts.ts` rule 6); a
347
+ * plugin doing it would squat every future name in it. */
348
+ function validateContribution(key, entry, id) {
349
+ // A route's leading `* ` is its METHOD ("every method"), not a name pattern.
350
+ const name = key === "routes" ? entry.replace(/^\* /, "") : entry;
351
+ const problem = name.includes("*") ? "must name one thing, not a '*' pattern" : CONTRIBUTION_CHECKS[key]?.(entry, id);
352
+ return problem === undefined ? undefined : contributesInvalid(`contributes.${key} entry '${entry}' ${problem}`);
353
+ }
354
+ /** `contributes` (2026-10-04): an object of known string lists — see `PluginManifest.contributes`. */
355
+ function validateContributes(raw, id) {
356
+ if (raw.contributes === undefined || raw.contributes === null)
357
+ return [];
358
+ if (typeof raw.contributes !== "object" || Array.isArray(raw.contributes)) {
359
+ return [contributesInvalid("'contributes' must be an object of string lists")];
360
+ }
361
+ const errors = [];
362
+ for (const [key, list] of Object.entries(raw.contributes)) {
363
+ if (!CONTRIBUTION_KEY_SET.has(key)) {
364
+ errors.push(contributesInvalid(`unknown contributes key '${key}' (expected one of ${CONTRIBUTION_KEYS.join(", ")})`));
365
+ continue;
366
+ }
367
+ if (!Array.isArray(list) || list.some((entry) => typeof entry !== "string" || entry.trim() === "")) {
368
+ errors.push(contributesInvalid(`contributes.${key} must be a list of non-empty strings`));
369
+ continue;
370
+ }
371
+ for (const entry of list) {
372
+ const error = validateContribution(key, entry, id);
373
+ if (error)
374
+ errors.push(error);
375
+ }
376
+ }
377
+ return errors;
378
+ }
379
+ /**
380
+ * Validates one already-parsed manifest against BR-02 steps (2)-(6), collecting every applicable
381
+ * error rather than stopping at the first (BR-02: "collect ALL statically-determinable errors").
382
+ * Pure — no I/O, no mutation of `manifest`.
383
+ *
384
+ * @throws Nothing — validation failures are reported via the returned `errors` array, never a
385
+ * thrown error (this function itself cannot fail; a malformed top-level shape, e.g. `manifest`
386
+ * being `null` or an array, is itself a `MANIFEST_MALFORMED` entry in the result, not a throw).
387
+ * @complexity O(fields.length + capabilities.length + hooks.length) — bounded by one manifest's
388
+ * own declared arrays, never by external/unbounded input.
389
+ */
390
+ export function validateManifest(required, _optional = {}) {
391
+ const { manifest, folderName, builtInIds } = required;
392
+ if (typeof manifest !== "object" || manifest === null || Array.isArray(manifest)) {
393
+ return { errors: [malformed("tovu.plugin.json must be a JSON object")] };
394
+ }
395
+ // Treat the input as a read-only bag of unknown values — never assigned back into.
396
+ const raw = manifest;
397
+ const { errors: idErrors, id } = validateId(raw, folderName, builtInIds, required.coreOwnerName);
398
+ const errors = [
399
+ ...validateKeys(raw),
400
+ ...validatePluginIdentity({ manifest: raw, namespace: required.identityNamespace ?? "tovu" }).errors.map(message => ({ code: "PLUGIN_IDENTITY_INVALID", file: null, message })),
401
+ ...idErrors,
402
+ ...validateIdentityFields(raw),
403
+ ...validateEngine(raw),
404
+ ...validateTier(raw),
405
+ ...validateCapabilities(raw, required.capabilityVocabulary),
406
+ ...validateHooks(raw, required.pluginSdkBinding.hookIds),
407
+ ...validateFields(raw, id),
408
+ ...validateContributes(raw, id),
409
+ // AW-7 Tier 1: `contentTypes` grammar and the tier-1 "no code surface" rule.
410
+ ...required.declarativeContentTypes.validateManifest({ manifest: raw }).errors,
411
+ ];
412
+ const warnings = errors.length === 0
413
+ ? readPluginIdentity({ manifest: raw, name: id, namespace: required.identityNamespace ?? "tovu" }).warnings
414
+ : [];
415
+ return { errors, warnings };
416
+ }
417
+ //# sourceMappingURL=manifest.js.map
@@ -0,0 +1,32 @@
1
+ import type { BuiltInPluginSource, PluginDiscoveryRecord } from "../discovery-types.js";
2
+ import type { ManifestHostPorts, PluginTierPolicy } from "../ports.js";
3
+ export type { BuiltInPluginSource, PluginDiscoveryRecord } from "../discovery-types.js";
4
+ export interface DiscoverPluginsRequired extends ManifestHostPorts {
5
+ readonly builtIns: readonly BuiltInPluginSource[];
6
+ readonly installDir?: string;
7
+ readonly tierPolicy: PluginTierPolicy;
8
+ }
9
+ /** Activation/boot may pin an enabled revision while newer packages remain installed for review.
10
+ * Admin discovery defaults to the latest version; a missing pinned version never falls forward. */
11
+ export interface DiscoverPluginsOptional {
12
+ readonly versions?: ReadonlyMap<string, string>;
13
+ }
14
+ export declare class PluginDiscoveryVersionError extends Error {
15
+ constructor(message: string);
16
+ }
17
+ /**
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
20
+ * same join `discoverOneSiteCandidate()` below already performs internally for its manifest read.
21
+ * Exported so a composition root resolving a dynamic site-sourced load target (`plugin-runtime.ts`)
22
+ * does not re-derive this convention independently and risk it drifting from discovery's own.
23
+ *
24
+ * @complexity O(1) — pure path join, no I/O.
25
+ */
26
+ export declare function siteEntryPath({ installDir, id, version }: {
27
+ installDir: string;
28
+ id: string;
29
+ version: string;
30
+ }, _optional?: Record<string, never>): string;
31
+ export declare function discoverPlugins(required: DiscoverPluginsRequired, optional?: DiscoverPluginsOptional): Promise<readonly PluginDiscoveryRecord[]>;
32
+ //# sourceMappingURL=discovery.d.ts.map