@osdlc/wayfinder 0.9.0 → 0.11.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 (52) hide show
  1. package/CHANGELOG.md +74 -0
  2. package/CONTRIBUTING.md +6 -1
  3. package/README.md +9 -4
  4. package/dist/args.d.ts +7 -8
  5. package/dist/args.js +7 -8
  6. package/dist/catalog.d.ts +13 -4
  7. package/dist/catalog.js +16 -8
  8. package/dist/clean-command.d.ts +3 -1
  9. package/dist/clean-command.js +23 -11
  10. package/dist/cli.js +3 -3
  11. package/dist/commands/index.js +1 -1
  12. package/dist/commands/list.d.ts +5 -2
  13. package/dist/commands/list.js +28 -3
  14. package/dist/commands/query.js +1 -1
  15. package/dist/commands/run.js +1 -1
  16. package/dist/commands/shared.js +2 -1
  17. package/dist/config-keys.d.ts +4 -0
  18. package/dist/config-keys.js +4 -0
  19. package/dist/config.d.ts +24 -10
  20. package/dist/config.js +64 -19
  21. package/dist/core/run.d.ts +2 -1
  22. package/dist/core/run.js +10 -2
  23. package/dist/core/saved-view.d.ts +2 -7
  24. package/dist/core/saved-view.js +5 -12
  25. package/dist/core/session.d.ts +7 -1
  26. package/dist/core/session.js +59 -22
  27. package/dist/core/writes.d.ts +13 -0
  28. package/dist/core/writes.js +22 -0
  29. package/dist/document-schemas.generated.js +6 -0
  30. package/dist/documents.d.ts +15 -2
  31. package/dist/documents.js +23 -14
  32. package/dist/guide.js +2 -2
  33. package/dist/index.js +2 -2
  34. package/dist/providers-command.d.ts +2 -2
  35. package/dist/schema.d.ts +1 -1
  36. package/dist/schema.js +1 -1
  37. package/dist/serve/auth.js +3 -16
  38. package/dist/serve/routes.d.ts +1 -1
  39. package/dist/serve/routes.js +1 -26
  40. package/dist/terminal-text.d.ts +4 -4
  41. package/dist/terminal-text.js +17 -12
  42. package/dist/tool-info.d.ts +2 -2
  43. package/dist/tools.js +1 -1
  44. package/dist/tui/app.js +24 -0
  45. package/dist/tui/index.js +3 -3
  46. package/dist/vocabulary.d.ts +5 -1
  47. package/dist/vocabulary.js +3 -1
  48. package/dist/web/main.js +67 -34
  49. package/dist/xdg.d.ts +0 -7
  50. package/dist/xdg.js +0 -14
  51. package/package.json +15 -13
  52. package/schema/config.json +14 -1
package/dist/config.js CHANGED
@@ -28,6 +28,10 @@
28
28
  * of repositories that includes it.
29
29
  * - `open`, `theme` and `skills`, which say how a person likes to work.
30
30
  *
31
+ * `runners.timeout` from a project can only lower a limit: it caps each
32
+ * runner's own limit, or the user's value. A project value above the user's,
33
+ * or a project `null` that would undo it, is dropped with a warning.
34
+ *
31
35
  * `tools` is gated too, because a tool module is code. User-layer entries
32
36
  * always load; project-layer entries load only when the repository is trusted
33
37
  * and execution is allowed (see `tools.ts`).
@@ -57,19 +61,24 @@ import { dirname, isAbsolute, join as joinPath, resolve } from 'node:path';
57
61
  import { z } from 'zod';
58
62
  import { closestMatches } from '@osdlc/config-layers/did-you-mean';
59
63
  import { atomicWriteAsync } from '@osdlc/etag-write';
64
+ import { expandTilde } from '@osdlc/tiered-dirs';
60
65
  import { expandTrustPath, homeDir, } from '@osdlc/trust-repo';
61
66
  import { originOwner } from '@osdlc/trust-repo/git';
62
67
  import { APP, BIN, CONFIG_ENV_VAR, PROJECT_CONFIG_FILENAME } from "./app.js";
63
- import { THEME_VALUES } from "./config-keys.js";
64
- import { appDirs, expandTilde, pre08Bases, USER_CONFIG_FILENAME } from "./xdg.js";
68
+ import { DISCOVERY_VALUES, OPEN_VALUES, THEME_VALUES, USER_ONLY_KEYS, } from "./config-keys.js";
69
+ import { VERSION } from "./version.js";
70
+ import { appDirs, pre08Bases, USER_CONFIG_FILENAME } from "./xdg.js";
65
71
  import { SKILLS_SETTING_VALUES } from "./core/skills.js";
66
72
  export { CONFIG_ENV_VAR, PROJECT_CONFIG_FILENAME, USER_CONFIG_FILENAME };
73
+ /** The release line, `major.minor` of package.json's version. */
74
+ const RELEASE_LINE = VERSION.split('.').slice(0, 2).join('.');
67
75
  /**
68
76
  * The URL a written file's `$schema` names: the schema this release line ships
69
- * in `schema/config.json`. Raise it with each minor release, here, in
70
- * `schema/config.json` and in the configuration guide; tests check all three.
77
+ * in `schema/config.json`. It follows package.json's version, and
78
+ * `scripts/write-config-schema.mjs` writes it into `schema/config.json` and
79
+ * the configuration guide.
71
80
  */
72
- export const CONFIG_SCHEMA_URL = 'https://unpkg.com/@osdlc/wayfinder@0.9/schema/config.json';
81
+ export const CONFIG_SCHEMA_URL = `https://unpkg.com/@osdlc/wayfinder@${RELEASE_LINE}/schema/config.json`;
73
82
  const strings = (description) => z.array(z.string()).describe(description);
74
83
  /** One set of trust rules: globs over the resolved root, and origin owners. */
75
84
  const TrustRulesSchema = z.object({
@@ -77,11 +86,11 @@ const TrustRulesSchema = z.object({
77
86
  'descendants only. A leading ~ is your home.').optional(),
78
87
  owners: strings('Origin remote owners, as host/owner, or a bare owner for github.com/owner. Case-insensitive.').optional(),
79
88
  });
80
- /** The `discovery` values. */
81
- export const DISCOVERY_VALUES = ['git', 'walk', 'auto'];
82
- /** The `open` values: what the bare `way` command opens. */
83
- export const OPEN_VALUES = ['tui', 'web'];
84
- export { THEME_VALUES } from "./config-keys.js";
89
+ /** The smallest `runners.timeout`, in seconds. */
90
+ export const MIN_RUNNER_TIMEOUT_S = 1;
91
+ /** The largest `runners.timeout`, in seconds: one hour. */
92
+ export const MAX_RUNNER_TIMEOUT_S = 3600;
93
+ export { DISCOVERY_VALUES, OPEN_VALUES, THEME_VALUES } from "./config-keys.js";
85
94
  /**
86
95
  * The configuration file, as a Zod schema. Every key is optional; the defaults
87
96
  * are {@link DEFAULT_CONFIG}.
@@ -93,6 +102,16 @@ export const WayfinderConfigSchema = z
93
102
  .object({
94
103
  disabled: strings('Runner ids to skip entirely.'),
95
104
  order: strings('Preferred display order. Runners not named follow alphabetically.'),
105
+ timeout: z
106
+ .number()
107
+ .min(MIN_RUNNER_TIMEOUT_S)
108
+ .max(MAX_RUNNER_TIMEOUT_S)
109
+ .nullable()
110
+ .describe('Seconds one runner may take to list its tasks, its subprocesses included. A runner ' +
111
+ 'still running then is stopped and shows "timed out". null (the default): each ' +
112
+ 'runner has its own limit, 10 for just and task, 30 for mise and rake, 120 for ' +
113
+ 'moon, 300 for gradle and sbt, 60 for the rest. A project file can only lower a ' +
114
+ 'limit: each runner takes the smaller of its value and the limit it would have.'),
96
115
  })
97
116
  .partial()
98
117
  .describe('Which runners are read, and in what order they are shown.'),
@@ -151,6 +170,11 @@ function expectation(schema) {
151
170
  const s = unwrap(schema);
152
171
  if (s instanceof z.ZodBoolean)
153
172
  return 'true or false';
173
+ if (s instanceof z.ZodNullable)
174
+ return `${expectation(s.unwrap())}, or null`;
175
+ // `runners.timeout` is the only number key.
176
+ if (s instanceof z.ZodNumber)
177
+ return `a number from ${MIN_RUNNER_TIMEOUT_S} to ${MAX_RUNNER_TIMEOUT_S}`;
154
178
  if (s instanceof z.ZodEnum)
155
179
  return `one of ${s.options.join(', ')}`;
156
180
  if (s instanceof z.ZodArray)
@@ -213,7 +237,7 @@ function under(key, top) {
213
237
  export function projectIgnoreReason(key, value) {
214
238
  if (under(key, 'trust'))
215
239
  return 'a repository cannot grant itself trust';
216
- if (under(key, 'open') || under(key, 'theme') || under(key, 'skills')) {
240
+ if (USER_ONLY_KEYS.some((top) => under(key, top))) {
217
241
  return 'a personal setting, for the user config';
218
242
  }
219
243
  if (key === 'allowExec' && value === true)
@@ -355,7 +379,7 @@ function check(schema, value, key, file, warnings) {
355
379
  const bad = value.findIndex((item) => !s.element.safeParse(item).success);
356
380
  throw new ConfigError(`${where}${key} must be ${expectation(s)}, got ${describe(value[bad])} at index ${bad}`, file);
357
381
  }
358
- const got = s instanceof z.ZodEnum ? JSON.stringify(value) : describe(value);
382
+ const got = s instanceof z.ZodEnum || typeof value === 'number' ? JSON.stringify(value) : describe(value);
359
383
  throw new ConfigError(`${where}${key} must be ${expectation(s)}, got ${got}`, file);
360
384
  }
361
385
  /**
@@ -417,7 +441,7 @@ export function mergeConfig(base, over) {
417
441
  * execution.
418
442
  */
419
443
  export const DEFAULT_CONFIG = {
420
- runners: { disabled: [], order: [] },
444
+ runners: { disabled: [], order: [], timeout: null },
421
445
  allowExec: true,
422
446
  discovery: 'auto',
423
447
  excludePaths: [],
@@ -549,9 +573,19 @@ export async function writeConfigFile(file, config) {
549
573
  * The project layer with what a project may not set removed, and a warning
550
574
  * for each removal that could have mattered.
551
575
  */
552
- function projectRules(project, locations) {
576
+ function projectRules(project, user, locations) {
553
577
  const warnings = [];
554
578
  const out = { ...project };
579
+ const timeout = project.runners?.timeout;
580
+ const userTimeout = user?.runners?.timeout;
581
+ if (timeout !== undefined &&
582
+ typeof userTimeout === 'number' &&
583
+ (timeout === null || timeout > userTimeout)) {
584
+ warnings.push(`${locations.project}: runners.timeout ${JSON.stringify(timeout)} is ignored — a project ` +
585
+ `file can only lower the limit below your user value (${userTimeout})`);
586
+ const { timeout: _dropped, ...runners } = project.runners;
587
+ out['runners'] = runners;
588
+ }
555
589
  if (project.allowExec === true) {
556
590
  // Warned even when the user layer also says true: the file's setting is
557
591
  // never honoured, and its author might rely on it.
@@ -571,8 +605,9 @@ function projectRules(project, locations) {
571
605
  }
572
606
  delete out['trust'];
573
607
  }
574
- for (const key of ['open', 'theme', 'skills']) {
575
- if (project[key] !== undefined) {
608
+ // `trust` is dropped above, with its own warning.
609
+ for (const key of USER_ONLY_KEYS) {
610
+ if (key !== 'trust' && out[key] !== undefined) {
576
611
  warnings.push(`${locations.project}: ${key} is ignored in a project file — it is a personal setting; ` +
577
612
  `set it in your user config (${locations.user}) instead`);
578
613
  delete out[key];
@@ -602,7 +637,7 @@ export async function loadConfig(root, env = process.env, home = homeDir()) {
602
637
  const user = userRead?.config ?? null;
603
638
  let project = null;
604
639
  if (projectRead !== null) {
605
- const ruled = projectRules(projectRead.config, locations);
640
+ const ruled = projectRules(projectRead.config, user, locations);
606
641
  project = ruled.project;
607
642
  warnings.push(...ruled.warnings);
608
643
  }
@@ -802,16 +837,26 @@ export function parseConfigValue(raw) {
802
837
  export function resolveConfigKey(key) {
803
838
  return schemaAt(key) === undefined ? undefined : key;
804
839
  }
805
- // ── Uses of the config ──────────────────────────────────────────────────────
806
840
  /**
807
841
  * The {@link WayOptions} fields this configuration controls. Only keys the
808
842
  * config sets are present, so a caller spreads its own flags after it.
843
+ *
844
+ * With `layers`, `runners.timeout` comes from them: the user's value replaces
845
+ * each runner's limit, and the project's caps it. Without, `config`'s value
846
+ * replaces each runner's limit.
809
847
  */
810
- export function collectOptionsFromConfig(config) {
848
+ export function collectOptionsFromConfig(config, layers) {
811
849
  const options = {};
812
850
  const disabled = config.runners?.disabled;
813
851
  if (disabled !== undefined)
814
852
  options.exclude = [...disabled];
853
+ const ms = (seconds) => typeof seconds === 'number' ? Math.round(seconds * 1000) : undefined;
854
+ const replace = ms(layers === undefined ? config.runners?.timeout : layers.user?.runners?.timeout);
855
+ if (replace !== undefined)
856
+ options.probeTimeoutMs = replace;
857
+ const cap = ms(layers?.project?.runners?.timeout);
858
+ if (cap !== undefined)
859
+ options.maxProbeTimeoutMs = cap;
815
860
  if (config.allowExec !== undefined)
816
861
  options.allowExec = config.allowExec;
817
862
  if (config.discovery !== undefined)
@@ -12,7 +12,8 @@ export interface HandOffResult {
12
12
  }
13
13
  /**
14
14
  * Run `plan` with this process's terminal and wait for it. `argv` is spawned
15
- * without a shell, with `plan.env` added to the environment.
15
+ * without a shell, with `plan.env` added to the environment. A bare program
16
+ * name runs only from an absolute `PATH` entry.
16
17
  *
17
18
  * Ctrl-C reaches the task and this process alike, since both are in the
18
19
  * terminal's foreground group. This process ignores it while the task runs,
package/dist/core/run.js CHANGED
@@ -18,7 +18,8 @@ import { streamRunner } from '@osdlc/command-seam';
18
18
  const TERMINAL_SIGNALS = process.platform === 'win32' ? ['SIGINT'] : ['SIGINT', 'SIGQUIT', 'SIGTERM', 'SIGHUP'];
19
19
  /**
20
20
  * Run `plan` with this process's terminal and wait for it. `argv` is spawned
21
- * without a shell, with `plan.env` added to the environment.
21
+ * without a shell, with `plan.env` added to the environment. A bare program
22
+ * name runs only from an absolute `PATH` entry.
22
23
  *
23
24
  * Ctrl-C reaches the task and this process alike, since both are in the
24
25
  * terminal's foreground group. This process ignores it while the task runs,
@@ -35,7 +36,14 @@ export function handOff(plan) {
35
36
  return { exit: 1, error: 'the task has no command' };
36
37
  let res;
37
38
  try {
38
- res = streamRunner(binary).run(rest, { cwd: plan.cwd, env: plan.env, quiet: true });
39
+ // The task runs inside the repository, so a bare name such as `npm` is
40
+ // looked up on absolute PATH entries only: a relative entry would find a
41
+ // file the repository ships. A path (`./gradlew`) runs as given.
42
+ res = streamRunner(binary, { absolutePathOnly: true }).run(rest, {
43
+ cwd: plan.cwd,
44
+ env: plan.env,
45
+ quiet: true,
46
+ });
39
47
  }
40
48
  catch (err) {
41
49
  return { exit: 1, error: err instanceof Error ? err.message : String(err) };
@@ -45,15 +45,10 @@ export declare function viewKey(parts: Record<string, unknown>): string;
45
45
  * throws.
46
46
  */
47
47
  export declare function readView(store: string, root: string, key: string): Promise<SavedView | null>;
48
- /**
49
- * Settles when every view write this process started has ended. Call it
50
- * before `process.exit`, which would drop a write in flight, and before a
51
- * test removes the cache directory.
52
- */
53
- export declare function flushViews(): Promise<void>;
54
48
  /**
55
49
  * Save the view, without waiting: the caller answers first. A failed write
56
50
  * only makes the next first paint slower. The returned promise settles when
57
- * the file is written, for a caller that must wait.
51
+ * the file is written, for a caller that must wait; `flushWrites` waits for
52
+ * it too.
58
53
  */
59
54
  export declare function writeView(store: string, view: Omit<SavedView, 'version'>): Promise<void>;
@@ -19,6 +19,7 @@ import { basename, join } from 'node:path';
19
19
  import { atomicWriteAsync } from '@osdlc/etag-write';
20
20
  import { z } from 'zod';
21
21
  import { CacheStateZ, CatalogZ, SkillZ } from "../documents.js";
22
+ import { trackWrite } from "./writes.js";
22
23
  const VIEW_FORMAT_VERSION = 1;
23
24
  /**
24
25
  * A view file larger than this is not read. The largest catalog measured, of
@@ -84,21 +85,13 @@ export async function readView(store, root, key) {
84
85
  return null;
85
86
  }
86
87
  }
87
- /** The writes this process has in flight, by file. */
88
+ /** The view writes in flight, by file: a write waits for the one before it. */
88
89
  const writing = new Map();
89
- /**
90
- * Settles when every view write this process started has ended. Call it
91
- * before `process.exit`, which would drop a write in flight, and before a
92
- * test removes the cache directory.
93
- */
94
- export async function flushViews() {
95
- while (writing.size > 0)
96
- await Promise.all(writing.values());
97
- }
98
90
  /**
99
91
  * Save the view, without waiting: the caller answers first. A failed write
100
92
  * only makes the next first paint slower. The returned promise settles when
101
- * the file is written, for a caller that must wait.
93
+ * the file is written, for a caller that must wait; `flushWrites` waits for
94
+ * it too.
102
95
  */
103
96
  export function writeView(store, view) {
104
97
  const file = viewPath(store, view.catalog.root, view.key);
@@ -115,5 +108,5 @@ export function writeView(store, view) {
115
108
  writing.delete(file);
116
109
  });
117
110
  writing.set(file, done);
118
- return done;
111
+ return trackWrite(done);
119
112
  }
@@ -5,6 +5,7 @@
5
5
  */
6
6
  import type { Catalog, Project, RunnerCacheState, RunnerReport, Task } from '@osdlc/system-model/detect';
7
7
  import { type ExecGate } from '@osdlc/trust-repo';
8
+ import { DISCOVERY_VALUES } from '../config-keys.ts';
8
9
  import { type WayOptions } from '../catalog.ts';
9
10
  import { type LoadedConfig, type Settings } from '../config.ts';
10
11
  import { type ToolSummary } from '../tool-info.ts';
@@ -36,7 +37,7 @@ export interface SessionFlags {
36
37
  exclude?: string[] | undefined;
37
38
  /** `--exclude-path`, replacing the configured list. */
38
39
  excludePaths?: string[] | undefined;
39
- discovery?: 'git' | 'walk' | 'auto' | undefined;
40
+ discovery?: (typeof DISCOVERY_VALUES)[number] | undefined;
40
41
  /** `--config` modules of extra tools, as typed. */
41
42
  toolModules?: readonly string[] | undefined;
42
43
  }
@@ -72,6 +73,11 @@ export interface CatalogProgress {
72
73
  * answer to show; it can add a diagnostic this report lacks.
73
74
  */
74
75
  onRunner?(report: RunnerReport, cache: CacheState): void;
76
+ /**
77
+ * Once, as soon as the agent skills are read: before, between or after the
78
+ * runners. The snapshot holds the same rows.
79
+ */
80
+ onSkills?(skills: readonly SkillRow[]): void;
75
81
  }
76
82
  /** A catalog and where each runner's rows came from. */
77
83
  export interface CatalogSnapshot {
@@ -9,8 +9,8 @@ import { closestMatches } from '@osdlc/config-layers/did-you-mean';
9
9
  import { homeDir, parseTrustScope, policyExecGate, withheldHint, } from '@osdlc/trust-repo';
10
10
  import { BIN, PROJECT_CONFIG_FILENAME } from "../app.js";
11
11
  import { cacheDir } from "../cache.js";
12
- import { settingLayer } from "../config-keys.js";
13
- import { collectAndCache, fromStore, makeProject, orderedCatalog, projectRootFor, readCachedCatalog, runnerIds, settledBoth, } from "../catalog.js";
12
+ import { DISCOVERY_VALUES, settingLayer } from "../config-keys.js";
13
+ import { collectAndStore, fromStore, makeProject, orderedCatalog, projectRootFor, readCachedCatalog, runnerIds, settledBoth, } from "../catalog.js";
14
14
  import { ConfigError, collectOptionsFromConfig, readSettings, trustPolicyFromConfig, writeSetting, trustPolicyOptions, } from "../config.js";
15
15
  import { readSkills } from "../skills.js";
16
16
  import { toolSummary } from "../tool-info.js";
@@ -21,6 +21,7 @@ import { EDITOR_VARIABLE_LABEL } from "../vocabulary.js";
21
21
  import { taskCopyText } from "./copy-text.js";
22
22
  import { filterTasks } from "./filter.js";
23
23
  import { readView, viewKey, writeView } from "./saved-view.js";
24
+ import { flushWrites } from "./writes.js";
24
25
  import { filterSkills } from "./skills.js";
25
26
  import { execOffSource, unknownsOf } from "./unknowns.js";
26
27
  /**
@@ -99,12 +100,17 @@ function parseScope(scope) {
99
100
  throw new SessionError('bad-arguments', err instanceof Error ? err.message : String(err));
100
101
  }
101
102
  }
103
+ /**
104
+ * Each setting a settings screen saves that is also a collect option a flag
105
+ * sets. A flag pins its option: the setting no longer moves it.
106
+ */
107
+ const COLLECT_SETTINGS = [
108
+ { setting: 'runners.disabled', option: 'exclude' },
109
+ { setting: 'excludePaths', option: 'excludePaths' },
110
+ { setting: 'discovery', option: 'discovery' },
111
+ ];
102
112
  /** The collect option a flag sets, for each setting a settings screen saves. */
103
- const FLAG_OF_SETTING = {
104
- 'runners.disabled': 'exclude',
105
- discovery: 'discovery',
106
- excludePaths: 'excludePaths',
107
- };
113
+ const FLAG_OF_SETTING = Object.fromEntries(COLLECT_SETTINGS.map((c) => [c.setting, c.option]));
108
114
  /** A config error as a session error; anything else unchanged. */
109
115
  function asSessionError(err, prefix = '') {
110
116
  if (err instanceof ConfigError)
@@ -126,6 +132,16 @@ function probedState(runner, probeMs) {
126
132
  function probedStates(catalog, times) {
127
133
  return catalog.reports.map((r) => probedState(r.runner, times.get(r.runner)));
128
134
  }
135
+ /**
136
+ * The selected runners the store has no rows for. That is a miss, and also a
137
+ * runner whose stored rows were dropped: a probe that ran the repository's
138
+ * tools does not answer a run that may not run them, so that entry is stale
139
+ * with no report.
140
+ */
141
+ function unanswered(catalog, runners) {
142
+ const answered = new Set(catalog.reports.map((r) => r.runner));
143
+ return runners.filter((r) => !answered.has(r.runner)).map((r) => r.runner);
144
+ }
129
145
  /**
130
146
  * Start a session: find the root, load config, decide execution against the
131
147
  * trust store, and load tool modules. Throws {@link SessionError} for a start
@@ -164,7 +180,7 @@ export async function createSession(opts) {
164
180
  const built = await projectFor(flags.toolModules ?? [], config, opts.cwd, home, projectAllowed);
165
181
  const projectToolsPending = !projectAllowed && (config.layers.project?.tools?.length ?? 0) > 0;
166
182
  // The config's own allowExec was consumed by the gate.
167
- const { allowExec: _consumed, ...configOptions } = collectOptionsFromConfig(config.effective);
183
+ const { allowExec: _consumed, ...configOptions } = collectOptionsFromConfig(config.effective, config.layers);
168
184
  // Config first, flags second. --exclude REPLACES runners.disabled.
169
185
  const options = {
170
186
  ...configOptions,
@@ -178,11 +194,7 @@ export async function createSession(opts) {
178
194
  ...(flags.discovery !== undefined ? { discovery: flags.discovery } : {}),
179
195
  ...(opts.signal !== undefined ? { signal: opts.signal } : {}),
180
196
  };
181
- const pinnedByFlag = [
182
- ...(flags.exclude ? ['exclude'] : []),
183
- ...(flags.excludePaths ? ['excludePaths'] : []),
184
- ...(flags.discovery !== undefined ? ['discovery'] : []),
185
- ];
197
+ const pinnedByFlag = COLLECT_SETTINGS.filter((c) => flags[c.option] !== undefined).map((c) => c.option);
186
198
  // Per-tool trust applies only when the repository's own trust is what
187
199
  // withholds execution. The set is read on every probe, so a tool grant in
188
200
  // this session applies to the next one.
@@ -208,14 +220,25 @@ export async function createSession(opts) {
208
220
  };
209
221
  }
210
222
  const skills = () => readSkills(root, { setting: settings.skills.value, home, env, signal: opts.signal });
223
+ /** The skills, told to `progress` as soon as they are read. */
224
+ const toldSkills = async (progress) => {
225
+ const rows = await skills();
226
+ progress?.onSkills?.(rows);
227
+ return rows;
228
+ };
211
229
  const store = cacheDir(env, home);
212
230
  const runnerOrder = () => settings.loaded.effective.runners?.order;
213
231
  /** Take `next` as the settings: the collect options follow, except where a flag decided. */
214
232
  const adopt = (next) => {
215
233
  settings = next;
216
- const derived = collectOptionsFromConfig(next.loaded.effective);
234
+ const derived = collectOptionsFromConfig(next.loaded.effective, next.loaded.layers);
217
235
  const target = options;
218
- for (const key of ['exclude', 'discovery', 'excludePaths']) {
236
+ // The probe time limits have no flag, so a setting always moves them.
237
+ for (const key of [
238
+ ...COLLECT_SETTINGS.map((c) => c.option),
239
+ 'probeTimeoutMs',
240
+ 'maxProbeTimeoutMs',
241
+ ]) {
219
242
  if (pinnedByFlag.includes(key))
220
243
  continue;
221
244
  if (derived[key] === undefined)
@@ -241,7 +264,7 @@ export async function createSession(opts) {
241
264
  /** Probe the runners `only` names (all when absent), timing each and telling `progress`. */
242
265
  const probe = async (only, signal, progress) => {
243
266
  const times = new Map();
244
- const catalog = await collectAndCache(project, root, {
267
+ const catalog = await collectAndStore(project, root, {
245
268
  ...withSignal(signal),
246
269
  ...(only !== undefined ? { only } : {}),
247
270
  onProbe: ({ runner, durationMs }) => times.set(runner, durationMs),
@@ -310,7 +333,7 @@ export async function createSession(opts) {
310
333
  if (opts.cached !== true) {
311
334
  // The skills are read beside the probe, so the answer does not wait
312
335
  // for both in turn. Both settle before a failure is thrown.
313
- const [{ catalog, times }, skillRows] = await settledBoth(probe(undefined, opts.signal, opts.progress), skills());
336
+ const [{ catalog, times }, skillRows] = await settledBoth(probe(undefined, opts.signal, opts.progress), toldSkills(opts.progress));
314
337
  return saved({
315
338
  catalog: orderedCatalog(catalog, runnerOrder()),
316
339
  cache: probedStates(catalog, times),
@@ -321,19 +344,22 @@ export async function createSession(opts) {
321
344
  const view = await session.savedCatalog();
322
345
  if (view !== null)
323
346
  return view;
347
+ // A probe in this process writes the store after it answers.
348
+ await flushWrites();
324
349
  // The call's signal too: a closed tab stops hashing the store.
325
350
  const stored = await readCachedCatalog(project, root, withSignal(opts.signal), store);
326
351
  if (stored.catalog === null || !fromStore(stored)) {
327
- const { catalog, times } = await probe(undefined, opts.signal, opts.progress);
352
+ const [{ catalog, times }, skillRows] = await settledBoth(probe(undefined, opts.signal, opts.progress), toldSkills(opts.progress));
328
353
  return saved({
329
354
  catalog: orderedCatalog(catalog, runnerOrder()),
330
355
  cache: probedStates(catalog, times),
331
- skills: await skills(),
356
+ skills: skillRows,
332
357
  origin: 'empty-store',
333
358
  });
334
359
  }
335
- // A miss is a runner with nothing stored. Only the missing runners are probed.
336
- const missing = stored.runners.filter((r) => r.state === 'miss').map((r) => r.runner);
360
+ // Only the runners with no stored rows are probed: a miss, or a stale
361
+ // entry whose report the store dropped.
362
+ const missing = unanswered(stored.catalog, stored.runners);
337
363
  if (missing.length === 0) {
338
364
  return saved({
339
365
  catalog: orderedCatalog(stored.catalog, runnerOrder()),
@@ -354,12 +380,23 @@ export async function createSession(opts) {
354
380
  });
355
381
  },
356
382
  async storedCatalog() {
383
+ await flushWrites();
357
384
  const stored = await readCachedCatalog(project, root, options, store);
358
385
  if (stored.catalog === null || !fromStore(stored))
359
386
  return null;
387
+ // A runner with no stored rows is missing from the catalog, so it is a miss.
388
+ const missing = new Set(unanswered(stored.catalog, stored.runners));
360
389
  return {
361
390
  catalog: orderedCatalog(stored.catalog, runnerOrder()),
362
- cache: stored.runners,
391
+ cache: stored.runners.map((r) => missing.has(r.runner)
392
+ ? {
393
+ runner: r.runner,
394
+ state: 'miss',
395
+ estimateMs: r.estimateMs,
396
+ slow: r.slow,
397
+ cost: r.cost,
398
+ }
399
+ : r),
363
400
  skills: await skills(),
364
401
  origin: 'store',
365
402
  };
@@ -0,0 +1,13 @@
1
+ /**
2
+ * The writes this process starts without waiting: the saved view and the
3
+ * probe store. A surface answers first and writes after. `process.exit`
4
+ * would drop a write in flight, so every normal exit awaits {@link flushWrites}.
5
+ */
6
+ /** Keep `write` until it settles, so {@link flushWrites} waits for it. Returns `write`. */
7
+ export declare function trackWrite<T>(write: Promise<T>): Promise<T>;
8
+ /**
9
+ * Settles when every write this process started has ended, those started
10
+ * while it waits included. Call it before `process.exit`, and before a test
11
+ * removes the cache directory.
12
+ */
13
+ export declare function flushWrites(): Promise<void>;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * The writes this process starts without waiting: the saved view and the
3
+ * probe store. A surface answers first and writes after. `process.exit`
4
+ * would drop a write in flight, so every normal exit awaits {@link flushWrites}.
5
+ */
6
+ const pending = new Set();
7
+ /** Keep `write` until it settles, so {@link flushWrites} waits for it. Returns `write`. */
8
+ export function trackWrite(write) {
9
+ const settled = write.then(() => { }, () => { });
10
+ pending.add(settled);
11
+ void settled.finally(() => pending.delete(settled));
12
+ return write;
13
+ }
14
+ /**
15
+ * Settles when every write this process started has ended, those started
16
+ * while it waits included. Call it before `process.exit`, and before a test
17
+ * removes the cache directory.
18
+ */
19
+ export async function flushWrites() {
20
+ while (pending.size > 0)
21
+ await Promise.all(pending);
22
+ }
@@ -142,6 +142,9 @@ export const GENERATED_SCHEMAS = {
142
142
  },
143
143
  "file": {
144
144
  "type": "string"
145
+ },
146
+ "dryRun": {
147
+ "type": "boolean"
145
148
  }
146
149
  },
147
150
  "required": [
@@ -173,6 +176,9 @@ export const GENERATED_SCHEMAS = {
173
176
  },
174
177
  "file": {
175
178
  "type": "string"
179
+ },
180
+ "dryRun": {
181
+ "type": "boolean"
176
182
  }
177
183
  },
178
184
  "required": [
@@ -2,7 +2,8 @@
2
2
  * The JSON documents wayfinder prints, as Zod schemas. Each command declares
3
3
  * one as its output; `schema.ts` turns them into the JSON Schemas the
4
4
  * `./schema` entry exports. The task and report shapes come from
5
- * `@osdlc/system-model/schema`, so they cannot drift from the library.
5
+ * `@osdlc/system-model/schema`, and so do the values of every enum that names
6
+ * a system-model value, so they cannot drift from the library.
6
7
  */
7
8
  import { z } from 'zod';
8
9
  /** A `Task` from system-model. */
@@ -226,7 +227,8 @@ export declare const CatalogOutput: z.ZodObject<{
226
227
  }, z.core.$strip>;
227
228
  /**
228
229
  * One line `list --progress` sends while it probes, before the catalog
229
- * document: which runners have not answered, and the one that just did.
230
+ * document: which runners have not answered, and the one that just did or
231
+ * the agent skills.
230
232
  */
231
233
  export declare const CatalogProgressOutput: z.ZodObject<{
232
234
  pending: z.ZodArray<z.ZodString>;
@@ -298,6 +300,17 @@ export declare const CatalogProgressOutput: z.ZodObject<{
298
300
  binary: z.ZodString;
299
301
  label: z.ZodString;
300
302
  }, z.core.$strip>], "kind">>>;
303
+ skills: z.ZodOptional<z.ZodArray<z.ZodObject<{
304
+ id: z.ZodString;
305
+ name: z.ZodString;
306
+ description: z.ZodNullable<z.ZodString>;
307
+ argumentHint: z.ZodNullable<z.ZodString>;
308
+ path: z.ZodString;
309
+ scope: z.ZodString;
310
+ origin: z.ZodString;
311
+ harnesses: z.ZodArray<z.ZodString>;
312
+ invoke: z.ZodString;
313
+ }, z.core.$strip>>>;
301
314
  }, z.core.$strip>;
302
315
  /** The catalog document's `schemaVersion`: the catalog's own. */
303
316
  export declare const CATALOG_DOCUMENT_VERSION = 1;