@operad-io/engine 0.1.1 → 0.2.0

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 (80) hide show
  1. package/config.schema.json +2 -1
  2. package/package.json +1 -1
  3. package/src/config/config.ts +74 -45
  4. package/src/flow/types.ts +4 -0
  5. package/src/flow/validate.ts +5 -0
  6. package/src/http/index.ts +2 -0
  7. package/src/http/plugins.ts +66 -0
  8. package/src/http/server.ts +342 -48
  9. package/src/kernel/decide.ts +115 -30
  10. package/src/kernel/state.ts +9 -0
  11. package/src/kernel/types.ts +25 -40
  12. package/src/log/open-log.ts +2 -5
  13. package/src/log/sqlite.ts +127 -85
  14. package/src/log/types.ts +35 -9
  15. package/src/loop/code-watch.ts +108 -2
  16. package/src/loop/older-code.ts +3 -4
  17. package/src/loop/serve.ts +122 -95
  18. package/src/notify/notify.ts +2 -6
  19. package/src/platform/atomic-write.ts +163 -0
  20. package/src/platform/file-lock.ts +43 -21
  21. package/src/platform/index.ts +2 -0
  22. package/src/platform/kept-workers.ts +290 -0
  23. package/src/platform/process-group.ts +11 -3
  24. package/src/platform/sqlite-open.ts +20 -6
  25. package/src/platform/sqlite-schema.ts +30 -0
  26. package/src/platform/step-reap.ts +33 -18
  27. package/src/platform/watch.ts +1 -11
  28. package/src/plugin/action-schema.ts +59 -1
  29. package/src/plugin/choice-info.ts +133 -0
  30. package/src/plugin/context.ts +279 -0
  31. package/src/plugin/declared-flows.ts +3 -10
  32. package/src/plugin/errors.ts +9 -0
  33. package/src/plugin/freeze.ts +12 -0
  34. package/src/plugin/harness.ts +28 -0
  35. package/src/plugin/index.ts +8 -7
  36. package/src/plugin/install.ts +265 -17
  37. package/src/plugin/keys.ts +2 -12
  38. package/src/plugin/load.ts +47 -23
  39. package/src/plugin/logger.ts +14 -0
  40. package/src/plugin/open-store.ts +0 -6
  41. package/src/plugin/question-form.ts +323 -0
  42. package/src/plugin/registry.ts +512 -76
  43. package/src/plugin/secrets.ts +14 -24
  44. package/src/plugin/semver.ts +52 -0
  45. package/src/plugin/settings.ts +1 -9
  46. package/src/plugin/sqlite-store.ts +94 -64
  47. package/src/plugin/store.ts +5 -0
  48. package/src/plugin/types.ts +566 -21
  49. package/src/plugin/validate.ts +396 -26
  50. package/src/runner/answer.ts +26 -68
  51. package/src/runner/ask.ts +227 -28
  52. package/src/runner/cancel.ts +10 -7
  53. package/src/runner/grants.ts +2 -2
  54. package/src/runner/index.ts +1 -3
  55. package/src/runner/limits.ts +2 -2
  56. package/src/runner/runner.ts +15 -14
  57. package/src/runner/service.ts +52 -19
  58. package/src/runner/step-worker.ts +9 -0
  59. package/src/testing/answer.ts +69 -0
  60. package/src/testing/clock-manual.ts +152 -0
  61. package/src/testing/config.ts +16 -0
  62. package/src/testing/fs.ts +172 -0
  63. package/src/testing/home.ts +43 -0
  64. package/src/testing/index.ts +19 -0
  65. package/src/testing/types.ts +2 -0
  66. package/src/testing/world.ts +9 -2
  67. package/src/trigger/kernel.ts +13 -46
  68. package/src/trigger/rules.ts +22 -12
  69. package/src/trigger/types.ts +2 -6
  70. package/src/util.ts +99 -0
  71. package/src/views/event-line.ts +22 -0
  72. package/src/views/history.ts +36 -19
  73. package/src/views/live-logs.ts +313 -0
  74. package/src/views/pending.ts +23 -5
  75. package/src/views/presentation.ts +629 -81
  76. package/src/views/running.ts +5 -5
  77. package/src/views/settings.ts +205 -66
  78. package/src/views/types.ts +3 -2
  79. package/src/views/uploads.ts +15 -7
  80. package/triggers.schema.json +4 -0
@@ -11,7 +11,7 @@
11
11
 
12
12
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
13
13
  import { basename, dirname, join } from "node:path";
14
- import { isRecord } from "../util.ts";
14
+ import { isMissingFile, isRecord } from "../util.ts";
15
15
 
16
16
  /** The directory under the operad home that holds the Bun project. */
17
17
  export const PLUGIN_PROJECT_DIRECTORY = "plugins";
@@ -145,21 +145,73 @@ export interface InstallRun {
145
145
  readonly stderr: string;
146
146
  }
147
147
 
148
+ /** Receives one line a package command printed while it ran. */
149
+ export type InstallProgress = (line: string) => void;
150
+
148
151
  /** Runs one command; a test replaces the real Bun process. */
149
- export type InstallRunner = (cwd: string, args: readonly string[]) => InstallRun;
152
+ export type InstallRunner = (
153
+ cwd: string,
154
+ args: readonly string[],
155
+ onProgress?: InstallProgress,
156
+ ) => InstallRun | Promise<InstallRun>;
157
+
158
+ /** The most characters of one progress line kept for a client. */
159
+ const PROGRESS_LINE_MAX = 200;
150
160
 
151
- function runWithBun(cwd: string, args: readonly string[]): InstallRun {
152
- const ran = Bun.spawnSync({
161
+ function reportLine(text: string, onProgress: InstallProgress | undefined): void {
162
+ if (onProgress === undefined) return;
163
+ const line = text.replace(/\x1b\[[0-9;]*m/g, "").trim();
164
+ if (line.length > 0) onProgress(line.slice(0, PROGRESS_LINE_MAX));
165
+ }
166
+
167
+ /** Reads a child's stream into `out`, reporting whole lines as they arrive. */
168
+ async function readReported(
169
+ stream: ReadableStream<Uint8Array> | undefined,
170
+ out: string[],
171
+ onProgress: InstallProgress | undefined,
172
+ ): Promise<void> {
173
+ if (stream === undefined) return;
174
+ const reader = stream.getReader();
175
+ const decoder = new TextDecoder();
176
+ let pending = "";
177
+ for (;;) {
178
+ const chunk = await reader.read();
179
+ if (chunk.done) break;
180
+ const text = decoder.decode(chunk.value, { stream: true });
181
+ out.push(text);
182
+ pending += text;
183
+ const parts = pending.split(/[\r\n]+/);
184
+ pending = parts.pop() ?? "";
185
+ for (const part of parts) reportLine(part, onProgress);
186
+ }
187
+ const last = decoder.decode();
188
+ out.push(last);
189
+ pending += last;
190
+ for (const part of pending.split(/[\r\n]+/)) reportLine(part, onProgress);
191
+ }
192
+
193
+ async function runWithBun(
194
+ cwd: string,
195
+ args: readonly string[],
196
+ onProgress?: InstallProgress,
197
+ ): Promise<InstallRun> {
198
+ const child = Bun.spawn({
153
199
  cmd: [process.execPath, ...args],
154
200
  cwd,
155
201
  stdin: "ignore",
156
202
  stdout: "pipe",
157
203
  stderr: "pipe",
158
204
  });
205
+ const stdout: string[] = [];
206
+ const stderr: string[] = [];
207
+ await Promise.all([
208
+ readReported(child.stdout, stdout, onProgress),
209
+ readReported(child.stderr, stderr, onProgress),
210
+ ]);
159
211
  return {
160
- exitCode: ran.exitCode,
161
- stdout: ran.stdout.toString(),
162
- stderr: ran.stderr.toString(),
212
+ exitCode: await child.exited,
213
+ stdout: stdout.join(""),
214
+ stderr: stderr.join(""),
163
215
  };
164
216
  }
165
217
 
@@ -168,12 +220,7 @@ function readManifest(path: string): Record<string, unknown> | undefined {
168
220
  try {
169
221
  text = readFileSync(path, "utf8");
170
222
  } catch (error) {
171
- if (
172
- typeof error === "object" &&
173
- error !== null &&
174
- "code" in error &&
175
- (error as { code?: unknown }).code === "ENOENT"
176
- ) {
223
+ if (isMissingFile(error)) {
177
224
  return undefined;
178
225
  }
179
226
  throw error;
@@ -196,6 +243,29 @@ function outputTail(run: InstallRun): string {
196
243
  return lines.length > 2000 ? lines.slice(-2000) : lines;
197
244
  }
198
245
 
246
+ /** True when the output says the package could not be downloaded. */
247
+ function looksLikeNetworkFailure(text: string): boolean {
248
+ return /ENOTFOUND|EAI_AGAIN|ECONNREFUSED|ECONNRESET|ETIMEDOUT|getaddrinfo|fetch failed|network is unreachable|could not resolve/i.test(
249
+ text,
250
+ );
251
+ }
252
+
253
+ /** The refusal of a failed install, with how to retry a download that did not happen. */
254
+ function failedInstall(
255
+ specifier: string,
256
+ args: readonly string[],
257
+ directory: string,
258
+ run: InstallRun,
259
+ ): Error {
260
+ const text = `${run.stdout}\n${run.stderr}`;
261
+ const retry = looksLikeNetworkFailure(text)
262
+ ? "; the package could not be downloaded, so check the network and run the command again"
263
+ : "; run the command again to retry";
264
+ return new Error(
265
+ `${specifier}: \`bun ${args.join(" ")}\` in ${directory} failed with exit code ${String(run.exitCode)}; ${outputTail(run)}${retry}`,
266
+ );
267
+ }
268
+
199
269
  /** Options for installing one package into the home project. */
200
270
  export interface EnsureInstalledOptions {
201
271
  readonly home: string;
@@ -207,6 +277,8 @@ export interface EnsureInstalledOptions {
207
277
  readonly from?: string | undefined;
208
278
  /** Skip optional dependencies; the claude SDK's platform binaries are optional. */
209
279
  readonly omitOptional?: boolean | undefined;
280
+ /** Receives each line the install prints while it runs. */
281
+ readonly onProgress?: InstallProgress | undefined;
210
282
  /** A test replaces the command; defaults to Bun. */
211
283
  readonly run?: InstallRunner | undefined;
212
284
  }
@@ -254,11 +326,9 @@ export async function ensureInstalledPackage(options: EnsureInstalledOptions): P
254
326
  writeFileSync(path, `${JSON.stringify(manifest, null, 2)}\n`);
255
327
 
256
328
  const args = ["install", ...(options.omitOptional === true ? ["--omit=optional"] : []), "--no-summary"];
257
- const run = (options.run ?? runWithBun)(directory, args);
329
+ const run = await (options.run ?? runWithBun)(directory, args, options.onProgress);
258
330
  if (run.exitCode !== 0) {
259
- throw new Error(
260
- `${specifier}: \`bun ${args.join(" ")}\` in ${directory} failed with exit code ${String(run.exitCode)}; ${outputTail(run)}`,
261
- );
331
+ throw failedInstall(specifier, args, directory, run);
262
332
  }
263
333
  const installed = installedPackageFile(home, specifier);
264
334
  if (installed === undefined) {
@@ -266,3 +336,181 @@ export async function ensureInstalledPackage(options: EnsureInstalledOptions): P
266
336
  }
267
337
  return installed;
268
338
  }
339
+
340
+
341
+ /** The lifecycle scripts a package needs before it can be imported. */
342
+ const INSTALL_SCRIPT_NAMES = ["preinstall", "install", "postinstall"] as const;
343
+
344
+ function packageManifest(packageDirectory: string): Record<string, unknown> | undefined {
345
+ try {
346
+ return readManifest(join(packageDirectory, "package.json"));
347
+ } catch {
348
+ return undefined;
349
+ }
350
+ }
351
+
352
+ /** True when the package's manifest declares a lifecycle script. */
353
+ function declaresInstallScript(manifest: Record<string, unknown> | undefined): boolean {
354
+ const scripts = manifest?.scripts;
355
+ if (!isRecord(scripts)) return false;
356
+ return INSTALL_SCRIPT_NAMES.some((name) => typeof scripts[name] === "string");
357
+ }
358
+
359
+ function installScriptHint(packageDirectory: string): string {
360
+ return declaresInstallScript(packageManifest(packageDirectory))
361
+ ? "; its package declares an install script, and installing runs no package scripts, so a package that needs one cannot be added"
362
+ : "";
363
+ }
364
+
365
+ function dependenciesOf(manifest: Record<string, unknown> | undefined): Record<string, unknown> {
366
+ if (manifest === undefined) return {};
367
+ const dependencies = manifest.dependencies;
368
+ return isRecord(dependencies) ? dependencies : {};
369
+ }
370
+
371
+ /** The dependency name `bun add` wrote for a package, including a local tarball. */
372
+ function addedDependencyName(
373
+ before: Record<string, unknown>,
374
+ after: Record<string, unknown>,
375
+ wanted: string | undefined,
376
+ ): string | undefined {
377
+ if (wanted !== undefined) return wanted;
378
+ const previous = dependenciesOf(before);
379
+ const next = dependenciesOf(after);
380
+ const changed = Object.keys(next).filter((name) => previous[name] !== next[name]);
381
+ if (changed.length === 1) return changed[0];
382
+ const named = Object.entries(next).find(
383
+ ([, value]) => typeof value === "string" && value.includes("file:"),
384
+ );
385
+ return named?.[0];
386
+ }
387
+
388
+ /** Options for adding one package to the home project. */
389
+ export interface AddPackageOptions {
390
+ readonly home: string;
391
+ /** A package name, or a local tarball a test installs without a registry. */
392
+ readonly specifier: string;
393
+ /** An exact version; absent asks Bun for the latest. */
394
+ readonly version?: string | undefined;
395
+ /** Receives each line the install prints while it runs. */
396
+ readonly onProgress?: InstallProgress | undefined;
397
+ /** A test replaces the command; defaults to Bun. */
398
+ readonly run?: InstallRunner | undefined;
399
+ }
400
+
401
+ /** Options for removing one package from the home project. */
402
+ export interface RemovePackageOptions {
403
+ readonly home: string;
404
+ /** The package name `addPackage` returned. */
405
+ readonly name: string;
406
+ /**
407
+ * The dependency spec the project had before the add; when present, put it
408
+ * back instead of removing the package the project already needed.
409
+ */
410
+ readonly previous?: string | undefined;
411
+ /** A test replaces the command; defaults to Bun. */
412
+ readonly run?: InstallRunner | undefined;
413
+ }
414
+
415
+ /** What adding a package installed. */
416
+ export interface AddedPackage {
417
+ readonly name: string;
418
+ readonly version: string;
419
+ readonly file: string;
420
+ /** True when the package declares a lifecycle script Bun was told not to run. */
421
+ readonly hasInstallScript: boolean;
422
+ /** The dependency spec the project named before the add, when it named one. */
423
+ readonly previousVersion?: string | undefined;
424
+ }
425
+
426
+ /**
427
+ * Installs one package into the home's Bun project with install scripts off.
428
+ * The package may be a name with an exact version, a name with no version
429
+ * (the latest), or a local tarball a test names. Unlike
430
+ * `ensureInstalledPackage`, this always asks Bun for the package, so a person
431
+ * adding it gets the version they named.
432
+ */
433
+ export async function addPackage(options: AddPackageOptions): Promise<AddedPackage> {
434
+ const directory = pluginProjectPath(options.home);
435
+ const path = join(directory, "package.json");
436
+ const before = readManifest(path);
437
+ mkdirSync(directory, { recursive: true });
438
+ if (before === undefined) {
439
+ writeFileSync(
440
+ path,
441
+ `${JSON.stringify({ name: PROJECT_NAME, private: true, type: "module" }, null, 2)}\n`,
442
+ );
443
+ }
444
+ const target =
445
+ options.version === undefined ? options.specifier : `${options.specifier}@${options.version}`;
446
+ const args = ["add", target, "--exact", "--ignore-scripts", "--no-summary"];
447
+ const run = await (options.run ?? runWithBun)(directory, args, options.onProgress);
448
+ if (run.exitCode !== 0) {
449
+ throw failedInstall(options.specifier, args, directory, run);
450
+ }
451
+ const after = readManifest(path);
452
+ if (after === undefined) {
453
+ throw new Error(`${options.specifier}: \`bun ${args.join(" ")}\` in ${directory} wrote no package.json`);
454
+ }
455
+ const wanted =
456
+ options.specifier.startsWith("file:") || options.specifier.startsWith(".") || options.specifier.startsWith("/")
457
+ ? undefined
458
+ : options.specifier;
459
+ const name = addedDependencyName(before ?? {}, after, wanted);
460
+ if (name === undefined) {
461
+ throw new Error(`${options.specifier}: was installed into ${directory}, but the project does not name it`);
462
+ }
463
+ const packageDirectory = join(directory, "node_modules", packageNameOf(name));
464
+ const manifest = packageManifest(packageDirectory);
465
+ if (manifest === undefined) {
466
+ throw new Error(`${options.specifier}: was installed into ${directory}, but its package.json is missing`);
467
+ }
468
+ const version = manifest.version;
469
+ if (typeof version !== "string" || version.length === 0) {
470
+ throw new Error(`${options.specifier}: its installed package has no version`);
471
+ }
472
+ const file = installedPackageFile(options.home, name);
473
+ if (file === undefined) {
474
+ throw new Error(
475
+ `${options.specifier}: was installed into ${directory}, but its entry does not resolve${installScriptHint(packageDirectory)}`,
476
+ );
477
+ }
478
+ const previous = before === undefined ? undefined : dependenciesOf(before)[name];
479
+ return {
480
+ name,
481
+ version,
482
+ file,
483
+ hasInstallScript: declaresInstallScript(manifest),
484
+ previousVersion: typeof previous === "string" ? previous : undefined,
485
+ };
486
+ }
487
+
488
+ /**
489
+ * Takes a package out of the home's Bun project again, dependency, files and
490
+ * lockfile entry alike. A refusal after `addPackage` calls this so a package
491
+ * operad refused does not stay installed; the project already naming it means
492
+ * it was not this add's to take away, so `previous` puts that dependency back.
493
+ * A package the project does not name is left alone.
494
+ */
495
+ export async function removePackage(options: RemovePackageOptions): Promise<void> {
496
+ const directory = pluginProjectPath(options.home);
497
+ const path = join(directory, "package.json");
498
+ const manifest = readManifest(path);
499
+ if (manifest === undefined) return;
500
+ let args: string[];
501
+ if (options.previous !== undefined) {
502
+ const dependencies = isRecord(manifest.dependencies) ? manifest.dependencies : {};
503
+ dependencies[options.name] = options.previous;
504
+ manifest.dependencies = dependencies;
505
+ writeFileSync(path, `${JSON.stringify(manifest, null, 2)}\n`);
506
+ args = ["install", "--ignore-scripts", "--no-summary"];
507
+ } else {
508
+ const dependencies = manifest.dependencies;
509
+ if (!isRecord(dependencies) || !Object.hasOwn(dependencies, options.name)) return;
510
+ args = ["remove", options.name, "--ignore-scripts", "--no-summary"];
511
+ }
512
+ const run = await (options.run ?? runWithBun)(directory, args);
513
+ if (run.exitCode !== 0) {
514
+ throw failedInstall(options.name, args, directory, run);
515
+ }
516
+ }
@@ -4,17 +4,7 @@ import { readFile } from "node:fs/promises";
4
4
  import { join } from "node:path";
5
5
  import { messageOf, PluginError } from "./errors.ts";
6
6
  import type { KeyBindings } from "./types.ts";
7
- import { isRecord } from "../util.ts";
8
-
9
- function isMissing(error: unknown): boolean {
10
- return (
11
- typeof error === "object" &&
12
- error !== null &&
13
- "code" in error &&
14
- error.code === "ENOENT"
15
- );
16
- }
17
-
7
+ import { isMissingFile, isRecord } from "../util.ts";
18
8
  /** The path of the key overrides for an operad home. */
19
9
  export function keysPathFor(home: string): string {
20
10
  return join(home, "keys.json");
@@ -26,7 +16,7 @@ export async function readKeysFile(path: string): Promise<KeyBindings> {
26
16
  try {
27
17
  text = await readFile(path, "utf8");
28
18
  } catch (error) {
29
- if (isMissing(error)) return {};
19
+ if (isMissingFile(error)) return {};
30
20
  throw new PluginError(`key bindings "${path}": ${messageOf(error)}`, {
31
21
  cause: error,
32
22
  });
@@ -7,6 +7,7 @@ import { messageOf, PluginError } from "./errors.ts";
7
7
  import { defaultOperadHome } from "./home.ts";
8
8
  import { installedPackageFile, runningFromWorkspace } from "./install.ts";
9
9
  import { keysPathFor, readKeysFile } from "./keys.ts";
10
+ import { definitionGuide, definitionName, isMissingFile } from "../util.ts";
10
11
  import { PluginRegistry } from "./registry.ts";
11
12
  import type { PluginRegistryOptions } from "./registry.ts";
12
13
 
@@ -22,6 +23,11 @@ export interface LoadPluginRegistryOptions extends PluginRegistryOptions {
22
23
  * Empty by default: the engine names no plugin.
23
24
  */
24
25
  readonly installOnEnable?: readonly string[] | undefined;
26
+ /**
27
+ * The shipped plugins a person may turn on that `config.json` need not name,
28
+ * by name and module. Their setup guides are readable while they are off.
29
+ */
30
+ readonly optional?: Readonly<Record<string, string>> | undefined;
25
31
  }
26
32
 
27
33
  let loadCount = 0;
@@ -126,27 +132,6 @@ export interface DefinitelyLoadedPlugin {
126
132
  readonly definition: unknown;
127
133
  }
128
134
 
129
- function definitionName(value: unknown): string | undefined {
130
- if (
131
- typeof value === "object" &&
132
- value !== null &&
133
- "name" in value &&
134
- typeof (value as { name?: unknown }).name === "string"
135
- ) {
136
- return (value as { name: string }).name;
137
- }
138
- return undefined;
139
- }
140
-
141
- function isMissingFileError(error: unknown): boolean {
142
- return (
143
- typeof error === "object" &&
144
- error !== null &&
145
- "code" in error &&
146
- (error as { code?: unknown }).code === "ENOENT"
147
- );
148
- }
149
-
150
135
  /**
151
136
  * False only when the config file does not exist. Any other access error means
152
137
  * the file may exist but cannot be read, so `readConfig` gets to report it
@@ -157,7 +142,7 @@ async function configFileExists(path: string): Promise<boolean> {
157
142
  await access(path);
158
143
  return true;
159
144
  } catch (error) {
160
- return !isMissingFileError(error);
145
+ return !isMissingFile(error);
161
146
  }
162
147
  }
163
148
 
@@ -221,6 +206,40 @@ export async function loadConfiguredPlugins(
221
206
  return { entries: config.plugins, loaded, disabled, errors };
222
207
  }
223
208
 
209
+ /** The plugins that are off: switched off in the file, or offered and not in it. */
210
+ function offNames(entries: readonly PluginConfigEntry[], optional: Readonly<Record<string, string>>): string[] {
211
+ const names = entries.filter((item) => !item.enabled && item.name !== undefined).map((item) => item.name ?? "");
212
+ for (const name of Object.keys(optional)) {
213
+ if (!entries.some((item) => item.name === name) && !names.includes(name)) names.push(name);
214
+ }
215
+ return names;
216
+ }
217
+
218
+ /**
219
+ * Reads the guide path of a switched-off plugin from its module, once per
220
+ * name: a module that cannot be loaded has no guide to offer.
221
+ */
222
+ function offGuideReader(
223
+ entries: readonly PluginConfigEntry[],
224
+ optional: Readonly<Record<string, string>>,
225
+ home: string,
226
+ ): (name: string) => Promise<string | undefined> {
227
+ const seen = new Map<string, Promise<string | undefined>>();
228
+ return (name) => {
229
+ const known = seen.get(name);
230
+ if (known !== undefined) return known;
231
+ const module =
232
+ entries.find((item) => !item.enabled && item.name === name)?.module ??
233
+ (entries.some((item) => item.name === name) ? undefined : optional[name]);
234
+ const read =
235
+ module === undefined
236
+ ? Promise.resolve(undefined)
237
+ : loadPlugin(module, home).then(definitionGuide, () => undefined);
238
+ seen.set(name, read);
239
+ return read;
240
+ };
241
+ }
242
+
224
243
  /**
225
244
  * Loads the plugins listed in `$OPERAD_HOME/config.json` (default
226
245
  * `~/.operad/config.json`) and validates them together.
@@ -245,12 +264,17 @@ export async function loadPluginRegistry(
245
264
  }
246
265
 
247
266
  const keys = await readKeysFile(options.keysPath ?? keysPathFor(home));
248
- return new PluginRegistry(definitions, {
267
+ const registry = new PluginRegistry(definitions, {
249
268
  ...options,
250
269
  home,
251
270
  keys: options.keys ?? keys,
252
271
  sources,
253
272
  settings: options.settings ?? settings,
254
273
  disabled: options.disabled ?? config.disabled,
274
+ off: offNames(config.entries, options.optional ?? {}),
275
+ disabledGuide: options.disabledGuide ?? offGuideReader(config.entries, options.optional ?? {}, home),
255
276
  });
277
+ // A harness reads its model list in the background; the load asks for none,
278
+ // so a client that asks just after it gets the list the home already keeps.
279
+ return registry;
256
280
  }
@@ -10,6 +10,20 @@ function segment(value: string): string {
10
10
  : cleaned;
11
11
  }
12
12
 
13
+ /** The directory a plugin's runs write their step logs in: `<store>/logs/<plugin>/runs`. */
14
+ function runLogsDirectory(storeRoot: string, plugin: string): string {
15
+ return join(storeRoot, "logs", segment(plugin), "runs");
16
+ }
17
+
18
+ /** One run's step-log directory: `<store>/logs/<plugin>/runs/<run>`. */
19
+ export function runLogDirectory(
20
+ storeRoot: string,
21
+ plugin: string,
22
+ runId: string,
23
+ ): string {
24
+ return join(runLogsDirectory(storeRoot, plugin), segment(runId));
25
+ }
26
+
13
27
  /**
14
28
  * A logger for one step, action, command or tick. It appends to a file under
15
29
  * `<store>/logs` and returns that path so the plugin can put it in a fact.
@@ -5,10 +5,7 @@ import type { SubscriptionWatchOptions } from "../platform/index.ts";
5
5
  import { SqlitePluginStore } from "./sqlite-store.ts";
6
6
  import type { PluginStore } from "./types.ts";
7
7
 
8
- export type PluginStoreBackend = "sqlite";
9
-
10
8
  export interface OpenPluginStoreOptions extends SubscriptionWatchOptions {
11
- readonly backend: PluginStoreBackend;
12
9
  /** The home's store directory. */
13
10
  readonly root: string;
14
11
  readonly clock?: (() => number) | undefined;
@@ -24,9 +21,6 @@ export function openPluginStore(options: OpenPluginStoreOptions): PluginStore {
24
21
  file: join(options.root, "plugins.sqlite"),
25
22
  ...(options.clock === undefined ? {} : { clock: options.clock }),
26
23
  ...(options.follow === undefined ? {} : { follow: options.follow }),
27
- ...(options.readonly === undefined ? {} : { readonly: options.readonly }),
28
- ...(options.readOnly === undefined ? {} : { readOnly: options.readOnly }),
29
- ...(options.oneShot === undefined ? {} : { oneShot: options.oneShot }),
30
24
  ...(options.repeat === undefined ? {} : { repeat: options.repeat }),
31
25
  });
32
26
  }