@jini-ai/plugins 0.4.1 → 0.4.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.
@@ -70,6 +70,12 @@ export interface PluginSourcePort {
70
70
  isSealedHere(required: Id & {
71
71
  version: string;
72
72
  }, optional?: Options): Promise<boolean>;
73
+ /** The capability set (`pluginCapabilitySet`) the owner last approved for this id, if any. */
74
+ readApproval(required: Id, optional?: Options): Promise<readonly string[] | undefined>;
75
+ /** Host-only: called after the owner confirmed an enable. Never exposed as a model tool. */
76
+ recordApproval(required: Id & {
77
+ capabilities: readonly string[];
78
+ }, optional?: Options): Promise<void>;
73
79
  }
74
80
  export interface PluginSourceDeps extends ManifestHostPorts {
75
81
  readonly installDir: string;
@@ -1,6 +1,6 @@
1
1
  /** Site-scoped source authoring. Drafts never enter discovery; publication belongs to the
2
2
  * existing installer. Node filesystem effects live here, host SDK/policy/reload stay ports. */
3
- import { lstat, mkdir, mkdtemp, readdir, rename, rm, writeFile, unlink } from 'node:fs/promises';
3
+ import { lstat, mkdir, mkdtemp, readdir, readFile, rename, rm, writeFile, unlink } from 'node:fs/promises';
4
4
  import path from 'node:path';
5
5
  import { tmpdir } from 'node:os';
6
6
  import * as semver from 'semver';
@@ -86,6 +86,9 @@ export function createPluginSourceService(required, optional = {}) {
86
86
  const drafts = path.join(root, '.drafts');
87
87
  const draft = (id) => path.join(drafts, id);
88
88
  const marker = (id, version) => path.join(drafts, '.sealed', id, version, 'digest.json');
89
+ // Beside the per-version provenance markers, so version pruning never removes it and no draft
90
+ // path (ids cannot start with '.') can write it. Per site: one approval covers every workspace.
91
+ const approval = (id) => path.join(drafts, '.sealed', id, 'approved.json');
89
92
  /** Cross-process source lock serializes edits with seal snapshots. Installer keeps its own
90
93
  * publication lock. Platform records pid/time and reclaims only dead owners; age alone must
91
94
  * never steal a long seal from a live process. Token-owned release preserves a replacement. */
@@ -318,6 +321,29 @@ export function createPluginSourceService(required, optional = {}) {
318
321
  const digest = JSON.parse(markers.get(path.basename(provenance)).toString('utf8')).digest;
319
322
  return digest === digestSitePluginSnapshot({ files: await snapshot(path.join(root, id, version)) });
320
323
  },
324
+ // Lock-free like isSealedHere: rename-published, and enabling during a seal must not fail BUSY.
325
+ readApproval: async ({ id }, _options = {}) => {
326
+ safeId(id);
327
+ if (!await exists(root))
328
+ return undefined;
329
+ await confined(root, approval(id));
330
+ if (!await exists(approval(id)))
331
+ return undefined;
332
+ // A damaged record means "not approved": the owner is simply asked again.
333
+ let parsed;
334
+ try {
335
+ parsed = JSON.parse(await readFile(approval(id), 'utf8')).capabilities;
336
+ }
337
+ catch {
338
+ return undefined;
339
+ }
340
+ return Array.isArray(parsed) && parsed.every(entry => typeof entry === 'string') ? parsed : undefined;
341
+ },
342
+ recordApproval: async ({ id, capabilities }, _options = {}) => {
343
+ safeId(id);
344
+ await mkdir(root, { recursive: true });
345
+ await writeAtomic(root, approval(id), jsonBytes({ capabilities: [...capabilities] }));
346
+ },
321
347
  };
322
348
  }
323
349
  //# sourceMappingURL=source-drafts.js.map
@@ -1,11 +1,17 @@
1
+ import type { PluginManifest } from "./manifest.js";
1
2
  /** Host-injected deployment policy. Environment interpretation belongs to composition adapters. */
2
3
  export interface PluginSourcePolicyPort {
3
4
  localInstallEnabled(required?: Record<string, never>, optional?: Record<string, never>): boolean;
5
+ /** `added` is what this version declares beyond the owner's last approval (see `addedPluginCapabilities`). */
4
6
  confirmEnable(required: {
5
7
  sealedHere: boolean;
8
+ added: readonly string[];
6
9
  }, optional?: Record<string, never>): boolean;
7
10
  }
8
11
  /** Local authoring runs directly; hosted sideloading retains the host's explicit opt-in.
12
+ * Enabling asks the owner unless the package was sealed on this site AND adds nothing beyond the
13
+ * owner's last approval. Tier-3 code runs in-process with full server authority, so "sealed here"
14
+ * (possibly by the assistant itself) is never consent on its own (owner, 2026-10-12).
9
15
  * @param required Deployment facts supplied by the host.
10
16
  * @param _optional Reserved factory options.
11
17
  * @returns The shared install/enable policy, with no environment reads.
@@ -15,4 +21,18 @@ export declare function createPluginSourcePolicy(required: {
15
21
  hosted: boolean;
16
22
  localInstallOptIn: boolean;
17
23
  }, _optional?: {}): PluginSourcePolicyPort;
24
+ /** Everything a manifest lets the plugin reach, as stable `kind:name` entries. Code may change
25
+ * freely between versions without re-asking; only a new entry here is a widening. The tier is an
26
+ * entry so a tier-1 package that becomes tier-3 (code execution) counts as widened.
27
+ * @complexity O(n log n) in the number of declared entries.
28
+ */
29
+ export declare function pluginCapabilitySet({ manifest }: {
30
+ manifest: Pick<PluginManifest, "tier" | "capabilities" | "hooks" | "fields" | "contentTypes" | "contributes">;
31
+ }, _optional?: {}): readonly string[];
32
+ /** Entries of `next` absent from `approved`; with no approval on record, all of `next`.
33
+ * @complexity O(n + m). */
34
+ export declare function addedPluginCapabilities({ approved, next }: {
35
+ approved: readonly string[] | undefined;
36
+ next: readonly string[];
37
+ }, _optional?: {}): readonly string[];
18
38
  //# sourceMappingURL=source-policy.d.ts.map
@@ -1,4 +1,7 @@
1
1
  /** Local authoring runs directly; hosted sideloading retains the host's explicit opt-in.
2
+ * Enabling asks the owner unless the package was sealed on this site AND adds nothing beyond the
3
+ * owner's last approval. Tier-3 code runs in-process with full server authority, so "sealed here"
4
+ * (possibly by the assistant itself) is never consent on its own (owner, 2026-10-12).
2
5
  * @param required Deployment facts supplied by the host.
3
6
  * @param _optional Reserved factory options.
4
7
  * @returns The shared install/enable policy, with no environment reads.
@@ -7,7 +10,33 @@
7
10
  export function createPluginSourcePolicy(required, _optional = {}) {
8
11
  return {
9
12
  localInstallEnabled: (_required = {}, _optional = {}) => !required.hosted || required.localInstallOptIn,
10
- confirmEnable: ({ sealedHere }, _optional = {}) => !sealedHere,
13
+ confirmEnable: ({ sealedHere, added }, _optional = {}) => !sealedHere || added.length > 0,
11
14
  };
12
15
  }
16
+ /** Everything a manifest lets the plugin reach, as stable `kind:name` entries. Code may change
17
+ * freely between versions without re-asking; only a new entry here is a widening. The tier is an
18
+ * entry so a tier-1 package that becomes tier-3 (code execution) counts as widened.
19
+ * @complexity O(n log n) in the number of declared entries.
20
+ */
21
+ export function pluginCapabilitySet({ manifest }, _optional = {}) {
22
+ const contributes = manifest.contributes ?? {};
23
+ const contentTypeName = (entry) => typeof entry?.key === "string" ? entry.key : JSON.stringify(entry);
24
+ return [...new Set([
25
+ `tier:${manifest.tier}`,
26
+ ...manifest.capabilities.map(name => `capability:${name}`),
27
+ ...manifest.hooks.map(name => `hook:${name}`),
28
+ ...manifest.fields.map(field => `field:${field.path}`),
29
+ ...(manifest.contentTypes ?? []).map(entry => `content-type:${contentTypeName(entry)}`),
30
+ ...["routes", "tools", "tables", "settings", "widgets", "permissions"]
31
+ .flatMap(kind => (contributes[kind] ?? []).map(name => `${kind.slice(0, -1)}:${name}`)),
32
+ ])].sort();
33
+ }
34
+ /** Entries of `next` absent from `approved`; with no approval on record, all of `next`.
35
+ * @complexity O(n + m). */
36
+ export function addedPluginCapabilities({ approved, next }, _optional = {}) {
37
+ if (approved === undefined)
38
+ return next;
39
+ const known = new Set(approved);
40
+ return next.filter(entry => !known.has(entry));
41
+ }
13
42
  //# sourceMappingURL=source-policy.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jini-ai/plugins",
3
- "version": "0.4.1",
3
+ "version": "0.4.2",
4
4
  "description": "Host-independent extension glue and site-plugin runtime with injected SDK, trust, archive and storage ports.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {