@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.
Files changed (81) hide show
  1. package/README.md +1 -1
  2. package/dist/core/manifest-keys.d.ts +8 -0
  3. package/dist/core/manifest-keys.js +16 -0
  4. package/dist/glue/attachment-points/content-lifecycle.d.ts +6 -7
  5. package/dist/glue/attachment-points/content-lifecycle.js +1 -1
  6. package/dist/glue/capability-gate.d.ts +2 -2
  7. package/dist/glue/manifest.js +2 -12
  8. package/dist/host/activation.d.ts +4 -5
  9. package/dist/host/admin-response.d.ts +2 -3
  10. package/dist/host/attach-loaded-plugin.d.ts +4 -4
  11. package/dist/host/attach-loaded-plugin.js +2 -2
  12. package/dist/host/browser-providers.d.ts +1 -1
  13. package/dist/host/capability-sdk.d.ts +8 -7
  14. package/dist/host/capability-sdk.js +39 -31
  15. package/dist/host/capability-tools.d.ts +4 -3
  16. package/dist/host/capability-tools.js +250 -238
  17. package/dist/host/contributions.d.ts +7 -66
  18. package/dist/host/contributions.js +64 -51
  19. package/dist/host/declarative-content-types.d.ts +6 -6
  20. package/dist/host/declarative-content-types.js +141 -135
  21. package/dist/host/declarative-enable.js +1 -1
  22. package/dist/host/discovery-types.d.ts +3 -3
  23. package/dist/host/hook-registry.d.ts +9 -9
  24. package/dist/host/hook-registry.js +86 -76
  25. package/dist/host/index.d.ts +1 -2
  26. package/dist/host/index.js +1 -1
  27. package/dist/host/manifest-types.d.ts +6 -59
  28. package/dist/host/manifest.d.ts +6 -5
  29. package/dist/host/manifest.js +5 -41
  30. package/dist/host/node/discovery.d.ts +1 -1
  31. package/dist/host/node/discovery.js +5 -6
  32. package/dist/host/node/index.d.ts +3 -0
  33. package/dist/host/node/index.js +2 -0
  34. package/dist/host/node/install.js +4 -4
  35. package/dist/host/node/integrity-command.d.ts +8 -0
  36. package/dist/host/node/integrity-command.js +26 -0
  37. package/dist/host/node/invocation-binding.d.ts +1 -1
  38. package/dist/host/node/invocation-binding.js +1 -1
  39. package/dist/host/node/loader.d.ts +3 -2
  40. package/dist/host/node/loader.js +12 -12
  41. package/dist/host/node/module-snapshot.d.ts +20 -0
  42. package/dist/host/node/module-snapshot.js +31 -0
  43. package/dist/host/node/open-flags.d.ts +4 -1
  44. package/dist/host/node/open-flags.js +1 -1
  45. package/dist/host/node/package-files.js +1 -1
  46. package/dist/host/node/provider-artifact.d.ts +1 -2
  47. package/dist/host/node/runtime-contracts.d.ts +238 -0
  48. package/dist/host/node/runtime-contracts.js +2 -0
  49. package/dist/host/node/runtime-core.d.ts +1 -243
  50. package/dist/host/node/runtime-core.js +18 -114
  51. package/dist/host/node/runtime-load-target.d.ts +44 -0
  52. package/dist/host/node/runtime-load-target.js +45 -0
  53. package/dist/host/node/runtime-package-location.d.ts +45 -0
  54. package/dist/host/node/runtime-package-location.js +57 -0
  55. package/dist/host/node/source-drafts.d.ts +4 -2
  56. package/dist/host/node/source-drafts.js +107 -39
  57. package/dist/host/ports.d.ts +2 -38
  58. package/dist/host/provider-contributions.d.ts +2 -14
  59. package/dist/host/provider-contributions.js +1 -1
  60. package/dist/host/provider-host.d.ts +4 -19
  61. package/dist/host/provider-host.js +83 -71
  62. package/dist/host/provider-revision-watch.d.ts +36 -0
  63. package/dist/host/provider-revision-watch.js +52 -0
  64. package/dist/host/provider-setting-required.d.ts +1 -7
  65. package/dist/host/provider-setting-required.js +1 -18
  66. package/dist/host/provider-settings-migrations.d.ts +1 -1
  67. package/dist/host/repo.memory.d.ts +1 -1
  68. package/dist/host/repo.memory.js +1 -1
  69. package/dist/host/sql/repo.d.ts +4 -3
  70. package/dist/host/sql/repo.rows.js +2 -2
  71. package/dist/host/tool-contributions.d.ts +2 -1
  72. package/dist/host/tool-contributions.js +1 -0
  73. package/dist/host/tools/install.js +1 -0
  74. package/dist/host/tools/management.js +97 -83
  75. package/dist/host/uninstall.d.ts +1 -1
  76. package/dist/host/worker/import-seam.d.ts +2 -2
  77. package/dist/host/worker/protocol.d.ts +2 -2
  78. package/dist/host/worker/run-call.d.ts +2 -1
  79. package/dist/host/worker/run-call.js +2 -2
  80. package/dist/host/worker/start.js +1 -1
  81. package/package.json +7 -17
@@ -1,18 +1,18 @@
1
1
  /** SDK version, hashing and executable import are required host ports. The importer must retain
2
2
  * the fresh snapshot and containment guarantees described below. */
3
3
  /**
4
- * @file `loadPlugin()` — BR-01's ordered load pipeline (SPEC-005 REQ-03).
5
- * The signature and JSDoc are design-frozen under implementation outline C-008.
6
- * Host-supplied SDK versions respect ADR-005's public-export boundary; do not deep-import the
4
+ * @file `loadPlugin()` — the ordered load pipeline.
5
+ * The signature and JSDoc are design-frozen under the implementation outline.
6
+ * Host-supplied SDK versions respect the public-export boundary; do not deep-import the
7
7
  * SDK's package.json to discover a version.
8
8
  * Verify packaged-file integrity, check the host SDK version against manifest.sdkRange, then
9
9
  * import executable code, validate its export and run setup with a capability-scoped SDK.
10
10
  * Hook attachment is composition-owned: see the successful return path and attachLoadedPlugin.
11
11
  *
12
- * CIC U-001 (Binding, ESCALATE_SECURITY): integrity and SDK compatibility MUST both pass before
12
+ * Binding, ESCALATE_SECURITY: integrity and SDK compatibility MUST both pass before
13
13
  * any plugin code is evaluated, even at module-evaluation time. Deviating from that ordering
14
14
  * requires a recorded [CIC_DEVIATION_APPROVED] entry under
15
- * reports/pipeline/005-plugin-system/critical-internal-constraints.md U-001.
15
+ * reports/pipeline/005-plugin-system/critical-internal-constraints.md.
16
16
  *
17
17
  * Injectable import and digest ports let checks observe that rejected code was never imported,
18
18
  * without depending on real module resolution (CIC Verification Surface Rule).
@@ -23,11 +23,11 @@ import path from "node:path";
23
23
  import { admitBrowserProviderAssets } from "./browser-provider-assets.js";
24
24
  import { isPluginRelativePath } from "../browser-providers.js";
25
25
  import * as semver from "semver";
26
- import { PLUGIN_PROVIDER_CAPABILITY } from '../provider-contributions.js';
26
+ import { PLUGIN_PROVIDER_CAPABILITY } from '@jini-ai/core/contracts/plugin-sdk';
27
27
  import { createPluginContributionCapture } from '../contributions.js';
28
28
  import { buildCapabilityScopedSdk } from "../capability-sdk.js";
29
29
  export { attachLoadedPlugin } from "../attach-loaded-plugin.js";
30
- /** A packaged artifact's file layout is fixed (ADR-004): `jini.plugin.json` + `server/index.mjs` at
30
+ /** A packaged artifact's file layout is fixed: `jini.plugin.json` + `server/index.mjs` at
31
31
  * the plugin root. `entryPath` is always `<pluginRoot>/server/index.mjs`, so the root two
32
32
  * directories up from it is where `manifest.integrity`'s relative file paths resolve from. */
33
33
  function derivePluginRoot(entryPath) {
@@ -97,7 +97,7 @@ function isExecutionAdmitted(required) {
97
97
  async function importPluginModule(required, _optional = {}) {
98
98
  try {
99
99
  // Same-version replacement must evaluate the reviewed package again. Build this URL only at
100
- // step (3), after integrity and SDK compatibility have passed (CIC U-001 order unchanged).
100
+ // step (3), after integrity and SDK compatibility have passed (order unchanged).
101
101
  // Injected import seams keep their original path contract. A fresh filesystem graph refreshes
102
102
  // ALL packaged helpers (including nested/dynamic imports and CommonJS require caches).
103
103
  const imported = await required.importModule({ plugin: { pluginId: required.record.id, packageRoot: required.pluginRoot }, modulePath: required.entryPath });
@@ -155,15 +155,15 @@ function publishProviderCapture(required) {
155
155
  }
156
156
  return undefined;
157
157
  }
158
- /** Integrity and SDK compatibility remain ordered before any executable importer (CIC U-001). */
158
+ /** Integrity and SDK compatibility remain ordered before any executable importer. */
159
159
  async function admitPluginPackage(required) {
160
160
  const { record, manifest, entryPath } = required;
161
161
  const pluginRoot = derivePluginRoot(entryPath);
162
162
  const computeFileHash = (absoluteFilePath) => required.verifyDigest({ absoluteFilePath });
163
- // --- CIC U-001-ORD1: step (1), integrity, MUST complete successfully before step (2)/(3). ---
163
+ // --- Step (1), integrity, MUST complete successfully before step (2)/(3). ---
164
164
  if (!await verifyIntegrity({ record, manifest, pluginRoot, entryPath, computeFileHash }))
165
165
  return { failure: 'INTEGRITY_FAILED' };
166
- // --- CIC U-001-ORD1: step (2), sdkRange, MUST complete successfully before step (3). ---
166
+ // --- Step (2), sdkRange, MUST complete successfully before step (3). ---
167
167
  if (!semver.satisfies(required.pluginSdkBinding.runtimeSdkVersion, manifest.sdkRange))
168
168
  return { failure: 'SDK_RANGE_UNSATISFIED' };
169
169
  const admission = await admitDeclaredBrowserProviders({ record, manifest, pluginRoot, approvals: required.browserProviderApprovals });
@@ -180,7 +180,7 @@ function isProviderSelected(required) {
180
180
  return required.providerContributions?.isSelected({ pluginId: required.record.id }, {}) === true;
181
181
  }
182
182
  /**
183
- * Executes BR-01's 5-step ordered pipeline for one plugin. See CIC U-001 above for the binding
183
+ * Executes the 5-step ordered pipeline for one plugin. See above for the binding
184
184
  * ordering constraint this function's statement order must never invert.
185
185
  *
186
186
  * @throws Never for an expected pipeline failure (those are reported via the returned `reason`);
@@ -4,6 +4,7 @@
4
4
  */
5
5
  import * as nativeFs from "node:fs/promises";
6
6
  import type { PluginManifest } from "../manifest.js";
7
+ import type { PluginModuleImportPort } from "../ports.js";
7
8
  export declare class PluginSnapshotIntegrityError extends Error {
8
9
  }
9
10
  /** Lifecycle failures have a stable category without exposing package paths or file contents. */
@@ -91,5 +92,24 @@ export declare function verifyPluginSnapshotIntegrity(required: {
91
92
  files: ReadonlyMap<string, Uint8Array>;
92
93
  integrity: Readonly<Record<string, string>>;
93
94
  }, _options?: Record<string, never>): void;
95
+ /** Adapts the product's module seam to Jini's registry. A built-in/test seam retains its original path;
96
+ * a site entry is contained and snapshotted only after Jini verifies integrity and SDK range.
97
+ * Same-version replacement needs a fresh filesystem identity for ALL helpers, including late
98
+ * dynamic imports and CommonJS require caches. Snapshots remain available until shutdown.
99
+ * @param required The validated manifest and source selected for this load.
100
+ * @param optional.importModule The existing built-in/worker/test import seam, when present.
101
+ * @param optional.snapshots The runtime's snapshot owner, disposed after plugin users stop.
102
+ * @returns A registry importer projecting the default export without changing export validation.
103
+ * @throws Snapshot/filesystem/import errors; Jini maps them to the existing load reasons.
104
+ * @complexity O(total package bytes) for a site snapshot; O(1) for an injected seam.
105
+ * @example createPluginModuleImporter({ manifest, source: "site" }, {})
106
+ */
107
+ export declare function createPluginModuleImporter(required: {
108
+ manifest: PluginManifest;
109
+ source: "built-in" | "site";
110
+ }, optional?: {
111
+ importModule?: (entryPath: string) => Promise<unknown>;
112
+ snapshots?: PluginModuleSnapshotLifecycle;
113
+ }): PluginModuleImportPort;
94
114
  export {};
95
115
  //# sourceMappingURL=module-snapshot.d.ts.map
@@ -6,6 +6,7 @@ import * as nativeFs from "node:fs/promises";
6
6
  import { hostname } from "node:os";
7
7
  import { createHash } from "node:crypto";
8
8
  import path from "node:path";
9
+ import { pathToFileURL } from "node:url";
9
10
  import { snapshotSitePluginPackage } from "./install.js";
10
11
  import { PLUGIN_MANIFEST_FILENAMES } from "../plugin-format.js";
11
12
  import { isPluginRelativePath } from "../browser-providers.js";
@@ -228,4 +229,34 @@ export function verifyPluginSnapshotIntegrity(required, _options = {}) {
228
229
  throw new PluginSnapshotIntegrityError("Package file disappeared before loading.");
229
230
  }
230
231
  }
232
+ /** Adapts the product's module seam to Jini's registry. A built-in/test seam retains its original path;
233
+ * a site entry is contained and snapshotted only after Jini verifies integrity and SDK range.
234
+ * Same-version replacement needs a fresh filesystem identity for ALL helpers, including late
235
+ * dynamic imports and CommonJS require caches. Snapshots remain available until shutdown.
236
+ * @param required The validated manifest and source selected for this load.
237
+ * @param optional.importModule The existing built-in/worker/test import seam, when present.
238
+ * @param optional.snapshots The runtime's snapshot owner, disposed after plugin users stop.
239
+ * @returns A registry importer projecting the default export without changing export validation.
240
+ * @throws Snapshot/filesystem/import errors; Jini maps them to the existing load reasons.
241
+ * @complexity O(total package bytes) for a site snapshot; O(1) for an injected seam.
242
+ * @example createPluginModuleImporter({ manifest, source: "site" }, {})
243
+ */
244
+ export function createPluginModuleImporter(required, optional = {}) {
245
+ return async ({ plugin, modulePath }) => {
246
+ if (optional.importModule) {
247
+ const imported = await optional.importModule(modulePath);
248
+ return { exported: typeof imported === "object" && imported !== null ? imported.default : undefined };
249
+ }
250
+ let entryPath = modulePath;
251
+ if (required.source === "site") {
252
+ const [root, entry] = await Promise.all([nativeFs.realpath(plugin.packageRoot), nativeFs.realpath(modulePath)]);
253
+ // The immutable snapshot owner rejects symlinks/hardlinks and checks every retained byte.
254
+ if (!entry.startsWith(root + path.sep))
255
+ return `module path '${modulePath}' escapes the plugin root`;
256
+ entryPath = await snapshotPluginModuleGraph({ pluginRoot: plugin.packageRoot, manifest: required.manifest }, optional.snapshots ? { lifecycle: optional.snapshots } : {});
257
+ }
258
+ const imported = await import(pathToFileURL(entryPath).href);
259
+ return { exported: imported.default };
260
+ };
261
+ }
231
262
  //# sourceMappingURL=module-snapshot.js.map
@@ -17,5 +17,8 @@ export declare function readNoFollowFlags({ constants }: {
17
17
  constants: OpenFlagConstants;
18
18
  }, _optional?: Record<string, never>): number;
19
19
  /** Reads up to `maxBytes` from the start of the file. */
20
- export declare function readAtMost(handle: FileHandle, maxBytes: number): Promise<Buffer>;
20
+ export declare function readAtMost({ handle, maxBytes }: {
21
+ handle: FileHandle;
22
+ maxBytes: number;
23
+ }, _optional?: Record<string, never>): Promise<Buffer>;
21
24
  //# sourceMappingURL=open-flags.d.ts.map
@@ -7,7 +7,7 @@ export function readNoFollowFlags({ constants }, _optional = {}) {
7
7
  return constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0);
8
8
  }
9
9
  /** Reads up to `maxBytes` from the start of the file. */
10
- export async function readAtMost(handle, maxBytes) {
10
+ export async function readAtMost({ handle, maxBytes }, _optional = {}) {
11
11
  const buffer = Buffer.alloc(maxBytes);
12
12
  let offset = 0;
13
13
  while (offset < maxBytes) {
@@ -136,7 +136,7 @@ async function readFileEntry({ absolutePath, relativePath, state }, _optional =
136
136
  state.truncated = true;
137
137
  return;
138
138
  }
139
- const bytes = await readAtMost(opened, maxFileBytes + 1);
139
+ const bytes = await readAtMost({ handle: opened, maxBytes: maxFileBytes + 1 });
140
140
  if (bytes.length > maxFileBytes) {
141
141
  state.files.push(omittedFile(relativePath, bytes.length, "too-large"));
142
142
  return;
@@ -1,6 +1,5 @@
1
1
  import { type PluginProviderContract } from '../provider-host.js';
2
- import type { PluginProviderResource } from '../provider-contributions.js';
3
- import type { HookPoints } from '../ports.js';
2
+ import type { PluginProviderResource, HookPoints } from '@jini-ai/core/contracts/plugin-sdk';
4
3
  import { type LoadPluginRequired } from './loader.js';
5
4
  /**
6
5
  * Load one already-discovered provider artifact and initialize its selected contract.
@@ -0,0 +1,238 @@
1
+ import type { PluginLookupPort } from "@jini-ai/core/plugin-directory";
2
+ import type { Clock as ClockPort } from "@jini-ai/core/primitives";
3
+ import type { FileLockPort } from "@jini-ai/core/contracts/runtime";
4
+ import type { PluginActivationRepoPort } from "../activation.js";
5
+ import type { PluginContributionRegistry } from "../contributions.js";
6
+ import type { AdmittedBrowserProvider } from "../browser-providers.js";
7
+ import type { ArchiveReaderPort, BundledBrowserProviderApproval, DeclarativeContentTypesPort, DeclaredContentTypePorts, PluginModuleImportPort, PluginSdkBinding, PluginTierPolicy, VerifyDigestPort } from "../ports.js";
8
+ import type { PluginSourcePolicyPort } from "../source-policy.js";
9
+ import type { BuiltInPluginSource, PluginDiscoveryRecord } from "../discovery-types.js";
10
+ import type { HookRegistry } from "../hook-registry.js";
11
+ import type { PluginManifest } from "../manifest-types.js";
12
+ import type { ExtensionClaim } from "../claim-conflicts.js";
13
+ import type { PluginConflict } from "../plugin-claims.js";
14
+ import type { PluginInstallerPort } from "./install.js";
15
+ import type { createPluginModuleSnapshotLifecycle } from "./module-snapshot.js";
16
+ import type { PluginSourcePort } from "./source-drafts.js";
17
+ import type { PluginPackageFiles } from "./package-files.js";
18
+ import type { Tier2CallRunner } from "../worker/protocol.js";
19
+ import type { RunTier2CallRequired } from "../worker/run-call.js";
20
+ /** Executable metadata for one compiled-in plugin. Discovery consumes only `manifest`; the enable
21
+ * callback consumes the import seam after integrity/sdkRange checks. Site-artifact sources can use
22
+ * the same shape once their install-dir resolver is composed here.
23
+ * @agent-note `importModule` is reached only through `loadPlugin()` after integrity and `sdkRange`
24
+ * passed; the host owns the entry path and importer. */
25
+ export interface PluginRuntimeSource extends BuiltInPluginSource {
26
+ readonly source: "built-in";
27
+ readonly entryPath: string;
28
+ readonly importModule: (entryPath: string) => Promise<unknown>;
29
+ /** The built-in's own source folder, shown read-only by the admin Plugins screen's
30
+ * package-files viewer (a host route). Omitted ⇒ that viewer lists no files. */
31
+ readonly sourceDir?: string;
32
+ }
33
+ /** What {@link createPluginRuntimeCore} returns: one runtime's shared handles.
34
+ * @agent-note Every member closes over the SAME repo, workspace, hook/contribution/provider registries
35
+ * and pending-attachment set; hosts adapt members (e.g. positional SDK types) without rebuilding them. */
36
+ export interface PluginRuntimeCoreBindings {
37
+ /** Call after provider teardown and stopped hook users; drains copies and releases owned graphs. */
38
+ readonly dispose: (required: Record<string, never>, optional?: Record<string, never>) => Promise<void>;
39
+ /** Successfully attached, admitted providers only; disable/quarantine retires their assets. */
40
+ readonly browserProviders: (input: Record<string, never>, options?: Record<string, never>) => {
41
+ generation: number;
42
+ providers: readonly AdmittedBrowserProvider[];
43
+ };
44
+ readonly pluginSource?: PluginSourcePort;
45
+ readonly pluginSourcePolicy: PluginSourcePolicyPort;
46
+ /** Actual loaded snapshot revision, used by the existing cross-process activation poll. */
47
+ readonly pluginLoadedVersion: (required: {
48
+ id: string;
49
+ }, optional?: Record<string, never>) => string | undefined;
50
+ readonly pluginInstaller?: PluginInstallerPort;
51
+ readonly hookRegistry: HookRegistry;
52
+ readonly pluginContributions: PluginContributionRegistry;
53
+ /** Provider factories of admitted provider plugins only (`createPluginProviderHost` reads this).
54
+ * Separate from `pluginContributions`, whose route/tool/widget snapshots carry no providers. */
55
+ readonly providerContributions: PluginContributionRegistry;
56
+ /**
57
+ * Boot-only: loads the given provider plugins when each is installed and enabled here, admitting
58
+ * their factories into `providerContributions`. Provider plugins are loaded nowhere else (boot
59
+ * re-attach and enable skip them), so a running provider is never replaced mid-process; enabling
60
+ * one takes effect at the next boot, disabling or quarantining one retires it immediately.
61
+ * @returns The ids actually loaded. Per-plugin failures are logged and skipped, never thrown.
62
+ */
63
+ readonly loadProviderPlugins: (required: {
64
+ pluginIds: readonly string[];
65
+ }, optional?: {
66
+ timeoutMs?: number;
67
+ }) => Promise<readonly string[]>;
68
+ /** Installed + enabled plugins here that declare providers, with their declarations (manifest only). */
69
+ readonly listProviderPlugins: (required: Record<string, never>, optional?: Record<string, never>) => Promise<readonly {
70
+ pluginId: string;
71
+ providers: NonNullable<NonNullable<PluginManifest["contributes"]>["providers"]>;
72
+ }[]>;
73
+ readonly discoverPlugins: () => Promise<readonly PluginDiscoveryRecord[]>;
74
+ /** Discovery with the enabled activations' version pins: the versions boot runs (a pin never falls forward). */
75
+ readonly discoverActivePlugins: () => Promise<readonly PluginDiscoveryRecord[]>;
76
+ readonly onPluginEnabled: (pluginId: string) => Promise<void>;
77
+ readonly onPluginDisabled: (pluginId: string) => void;
78
+ readonly locatePluginPackageDirs: (pluginId: string) => Promise<{
79
+ liveParent: string;
80
+ liveNames: readonly string[];
81
+ parkedDir: string;
82
+ }>;
83
+ /** Lists one discovered plugin's own files, read-only and bounded, for the admin Plugins
84
+ * screen's package-files viewer — see {@link resolvePackageLocation} and
85
+ * `Jini/packages/plugins/src/host/node/package-files.ts`. Rejects with `PluginPackagePathError` for an
86
+ * unsafe id/version or a directory that resolves outside its container. */
87
+ readonly readPluginPackageFiles: (record: PluginDiscoveryRecord) => Promise<PluginPackageFiles>;
88
+ /** @agent-note Positional adapter over the shared hook registry; the entry object is passed
89
+ * through untouched so every host payload field reaches each filter. */
90
+ readonly beforeSaveHook: (entry: Parameters<HookRegistry["runBeforeSave"]>[0]["entry"]) => ReturnType<HookRegistry["runBeforeSave"]>;
91
+ /** Admin preview (AW-7): one attached plugin's beforeSave patch for a draft, nothing saved or
92
+ * counted toward quarantine. `null` ⇒ not attached. See `HookRegistry.previewBeforeSave`.
93
+ * @agent-note Preview writes nothing and counts nothing toward quarantine. */
94
+ readonly previewPluginBeforeSave: (pluginId: string, entry: Parameters<HookRegistry["previewBeforeSave"]>[0]["entry"]) => ReturnType<HookRegistry["previewBeforeSave"]>;
95
+ /**
96
+ * P0a fix (2026-09-23): re-runs `onPluginEnabled` for every plugin `activationRepo` durably
97
+ * marks `enabled` for THIS composition's `workspaceId`. Before this existed, nothing replayed
98
+ * that durable state into a freshly-constructed (empty) `hookRegistry` — a plugin enabled in a
99
+ * prior process looked enabled in the admin UI and in `listAll()`, but its filter/action/
100
+ * contribution never fired again until an operator disabled and re-enabled it. Best-effort: one
101
+ * plugin failing to re-attach (e.g. its package was removed from disk) is logged and skipped, not
102
+ * thrown, so it can never block the rest of boot (mirrors `seedBundledAgentPlugins`'s own
103
+ * per-package isolation).
104
+ */
105
+ readonly attachEnabledPluginsAtBoot: () => Promise<void>;
106
+ /** Every discovered plugin that has a name conflict right now — an enabled loser, or a plugin that
107
+ * is off and WOULD be refused if turned on — for the admin screen and the host's plugin-list tool. See
108
+ * `Jini/packages/plugins/src/host/plugin-claims.ts`'s `resolvePluginConflicts`. */
109
+ readonly listPluginConflicts: () => Promise<ReadonlyMap<string, readonly PluginConflict[]>>;
110
+ }
111
+ /**
112
+ * The host bag spread into discovery, conflicts, enable, load, the Tier-2 seam, install and the
113
+ * source service. Extract-s6 L1b: a local port so the runtime core imports no host module.
114
+ * @agent-note Second-host rule: build ONE bag per runtime and keep it for the runtime's lifetime;
115
+ * every member is host-owned (capability vocabulary, declared content types, core owner name,
116
+ * identity namespace, install-disabled wording, tier policy, archive reader, digest format and the
117
+ * per-load invocation binding factory). The archive reader is always host-supplied (no fallback).
118
+ */
119
+ export interface PluginRuntimeHostBinding {
120
+ readonly capabilityVocabulary: readonly string[];
121
+ readonly declarativeContentTypes: DeclarativeContentTypesPort;
122
+ readonly coreOwnerName: string;
123
+ readonly identityNamespace: string;
124
+ readonly legacyIdentityNamespace?: string;
125
+ readonly localInstallDisabledMessage: string;
126
+ readonly tierPolicy: PluginTierPolicy;
127
+ readonly archiveReader: ArchiveReaderPort;
128
+ readonly verifyDigest: VerifyDigestPort;
129
+ readonly createInvocationCoreDeps: RunTier2CallRequired["createInvocationCoreDeps"];
130
+ /** Serializes plugin source edits with seal snapshots; Node hosts pass `nodeFileLock` of `@jini-ai/node-adapters/fs`. */
131
+ readonly fileLock: FileLockPort;
132
+ }
133
+ /** Only the tracker member the runtime calls. @agent-note The host supplies the event vocabulary
134
+ * through `quarantineTelemetry`; the runtime never names an event, user or property itself. */
135
+ export interface PluginRuntimeTracker<TEvent, TOptions> {
136
+ capture(event: TEvent, options: TOptions): unknown;
137
+ }
138
+ /** Install admission + plugin lookup. @agent-note `withInstallIdentity` must serialize admission
139
+ * of one candidate identity and run `run` at most once; it is read per install, never cached. */
140
+ export interface PluginRuntimeLookup extends PluginLookupPort {
141
+ /**
142
+ * Admits one site-runtime publisher identity, then publishes it by running `run`.
143
+ * @agent-note Second-host rule: the runtime only names the candidate; identity custody is the
144
+ * host's, and this port must perform the WHOLE sequence, in this order:
145
+ * 1. take ONE lock shared by every publisher of every plugin family the host runs, across all
146
+ * processes that can publish into the same install (a per-process or per-family mutex is not
147
+ * enough: two families could then both publish the same `publisher/local` identity);
148
+ * 2. under that lock, read a FRESH admission inventory of all families (never a cached list),
149
+ * including disabled installs, reserved/built-in identities and any other reservation;
150
+ * 3. assert the candidate identity is available against that inventory, refusing a clash with any
151
+ * other family or owner and allowing only a permitted upgrade of the same plugin's identity;
152
+ * 4. run `run` (which publishes the install) while STILL holding the same lock, at most once,
153
+ * and release the lock only after it settles. The site installer itself checks only its own
154
+ * install directory and built-ins; it cannot see another family's reservation.
155
+ */
156
+ withInstallIdentity<T>(required: {
157
+ candidate: {
158
+ id: string;
159
+ localId: string;
160
+ family: "site-runtime";
161
+ };
162
+ run: () => Promise<T>;
163
+ }): Promise<T>;
164
+ }
165
+ /** Host wording the runtime surfaces. @agent-note Exact host bytes; names of host tools, manifest
166
+ * file names and route prefixes live here, never in the runtime. */
167
+ export interface PluginRuntimeText {
168
+ /** Source written to a new local plugin draft. */
169
+ readonly scaffoldEntry: string;
170
+ /** Reload refusal when a re-sealed version widens capabilities (`added` in manifest order). */
171
+ readonly reloadApprovalRequired: (required: {
172
+ added: readonly string[];
173
+ }) => string;
174
+ /** Quarantine reason when a source reload and the restored-version reload both failed. */
175
+ readonly restoreFailedReason: string;
176
+ }
177
+ /**
178
+ * Required inputs of the plugin-owned runtime core (extract-s6 L1b seam; moved here in L1c).
179
+ * @agent-note Second-host rule: `pluginSourcePolicy`, `tier2CallRunner` and `pluginSdkBinding` have
180
+ * NO defaults here — the host owns env/policy, the worker entry/runner/timeout, and the SDK (hook
181
+ * ids, version, `beforeSaveHook`). `activationRepo` and the hook registry built here are shared by
182
+ * save AND preview of this one runtime. The Tier-2 runner must register its SDK resolver before
183
+ * importing. `createModuleImporter` is two-stage; see its own note.
184
+ */
185
+ export interface PluginRuntimeCoreRequired<TEvent = unknown, TOptions = unknown> {
186
+ readonly workspaceId: string;
187
+ readonly clock: ClockPort;
188
+ readonly activationRepo: PluginActivationRepoPort;
189
+ readonly sources: readonly PluginRuntimeSource[];
190
+ readonly pluginSourcePolicy: PluginSourcePolicyPort;
191
+ readonly tier2CallRunner: Tier2CallRunner;
192
+ readonly pluginSdkBinding: PluginSdkBinding;
193
+ readonly hostBinding: PluginRuntimeHostBinding;
194
+ /**
195
+ * Builds the module importer for one load target.
196
+ * @agent-note Second-host rule: two stages, with different guarantees.
197
+ * 1. Factory call: the runtime calls this while preparing the `loadPlugin` arguments, BEFORE that
198
+ * load's integrity and `sdkRange` checks run, and possibly for a package those checks then
199
+ * reject. The call must therefore only build a closure: no import, no snapshot, no file read,
200
+ * no executable loading of any kind.
201
+ * 2. Returned importer: invoked by the loader only AFTER admission (integrity, `sdkRange`). For a
202
+ * site package it must (a) enforce containment: the resolved entry stays inside the plugin's
203
+ * real package root, with links refused; (b) import a FRESH identity of the entire dependency
204
+ * graph on every load, never a cached module, so a replaced package never runs stale helpers;
205
+ * (c) keep any snapshot it takes, when `snapshots` is given, alive for late/lazy imports until
206
+ * that lifecycle is disposed. A plain cached `import()` adapter violates (b). An injected
207
+ * `importModule` seam (built-in, worker or test) keeps its original path.
208
+ */
209
+ readonly createModuleImporter: (required: {
210
+ manifest: PluginManifest;
211
+ source: "built-in" | "site";
212
+ }, optional?: {
213
+ importModule?: (entryPath: string) => Promise<unknown>;
214
+ snapshots?: NonNullable<ReturnType<typeof createPluginModuleSnapshotLifecycle>>;
215
+ }) => PluginModuleImportPort;
216
+ readonly text: PluginRuntimeText;
217
+ /** Host projection of one quarantine into its own telemetry event; called only when `tracker` is set. */
218
+ readonly quarantineTelemetry: (required: {
219
+ pluginId: string;
220
+ }) => {
221
+ event: TEvent;
222
+ options: TOptions;
223
+ };
224
+ }
225
+ /** Optional inputs; each omitted value keeps the documented default.
226
+ * @agent-note `dispose()` must run after provider teardown and stopped hook users; it drains
227
+ * pending attachments, then releases module snapshots. Load epochs retire stale generations. */
228
+ export interface PluginRuntimeCoreOptional<TEvent = unknown, TOptions = unknown> {
229
+ readonly tracker?: () => PluginRuntimeTracker<TEvent, TOptions>;
230
+ readonly lookup?: () => PluginRuntimeLookup | undefined;
231
+ readonly browserProviderApprovals?: readonly BundledBrowserProviderApproval[];
232
+ readonly bundledEnabledIds?: readonly string[];
233
+ readonly failureThreshold?: number;
234
+ readonly installDir?: string;
235
+ readonly coreClaims?: readonly ExtensionClaim[];
236
+ readonly declaredContentTypes?: DeclaredContentTypePorts;
237
+ }
238
+ //# sourceMappingURL=runtime-contracts.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=runtime-contracts.js.map