@osdlc/wayfinder 0.8.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 (61) hide show
  1. package/CHANGELOG.md +100 -0
  2. package/CONTRIBUTING.md +6 -1
  3. package/README.md +31 -11
  4. package/dist/args.d.ts +7 -8
  5. package/dist/args.js +7 -8
  6. package/dist/catalog.d.ts +26 -3
  7. package/dist/catalog.js +65 -12
  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/browse.js +4 -2
  12. package/dist/commands/index.js +1 -1
  13. package/dist/commands/list.d.ts +21 -2
  14. package/dist/commands/list.js +85 -9
  15. package/dist/commands/query.js +1 -1
  16. package/dist/commands/run.js +1 -1
  17. package/dist/commands/shared.js +2 -1
  18. package/dist/config-keys.d.ts +4 -0
  19. package/dist/config-keys.js +4 -0
  20. package/dist/config.d.ts +24 -9
  21. package/dist/config.js +64 -18
  22. package/dist/core/run.d.ts +2 -1
  23. package/dist/core/run.js +10 -2
  24. package/dist/core/saved-view.d.ts +2 -7
  25. package/dist/core/saved-view.js +5 -12
  26. package/dist/core/session.d.ts +32 -6
  27. package/dist/core/session.js +86 -36
  28. package/dist/core/writes.d.ts +13 -0
  29. package/dist/core/writes.js +22 -0
  30. package/dist/document-schemas.generated.js +6 -0
  31. package/dist/documents.d.ts +90 -1
  32. package/dist/documents.js +39 -12
  33. package/dist/guide.js +2 -2
  34. package/dist/index.d.ts +8 -2
  35. package/dist/index.js +8 -5
  36. package/dist/providers-command.d.ts +2 -2
  37. package/dist/schema.d.ts +1 -1
  38. package/dist/schema.js +1 -1
  39. package/dist/serve/auth.js +3 -16
  40. package/dist/serve/catalog-share.d.ts +13 -1
  41. package/dist/serve/catalog-share.js +42 -3
  42. package/dist/serve/index.d.ts +5 -3
  43. package/dist/serve/index.js +20 -12
  44. package/dist/serve/routes.d.ts +1 -1
  45. package/dist/serve/routes.js +1 -26
  46. package/dist/terminal-text.d.ts +4 -4
  47. package/dist/terminal-text.js +17 -12
  48. package/dist/tool-info.d.ts +2 -2
  49. package/dist/tools.js +1 -1
  50. package/dist/tui/app.d.ts +15 -2
  51. package/dist/tui/app.js +189 -43
  52. package/dist/tui/index.js +3 -3
  53. package/dist/vocabulary.d.ts +7 -1
  54. package/dist/vocabulary.js +5 -1
  55. package/dist/web/main.js +345 -59
  56. package/dist/web/page.html +2 -0
  57. package/dist/web/styles.css +56 -0
  58. package/dist/xdg.d.ts +0 -7
  59. package/dist/xdg.js +0 -14
  60. package/package.json +16 -14
  61. package/schema/config.json +14 -1
@@ -3,10 +3,11 @@
3
3
  * Copy puts on the clipboard, then one `/<name>` line per agent skill;
4
4
  * `--json` is the catalog document.
5
5
  */
6
+ import { inDisplayOrder } from "../catalog.js";
6
7
  import { documentGroups } from "../groups.js";
7
8
  import { filterTasks } from "../core/filter.js";
8
9
  import { filterSkills, skillLine } from "../core/skills.js";
9
- import { CATALOG_DOCUMENT_VERSION, CatalogOutput } from "../documents.js";
10
+ import { CATALOG_DOCUMENT_VERSION, CatalogOutput, CatalogProgressOutput, } from "../documents.js";
10
11
  import { taskLine } from "../core/copy-text.js";
11
12
  import { terminalSafe } from "../terminal-text.js";
12
13
  import { FILTER_FLAGS, filterFrom, kit, noteUnknowns, openSession } from "./shared.js";
@@ -52,6 +53,59 @@ export function sourceOf(snapshot) {
52
53
  ? { source: 'cached', storedAt: snapshot.catalog.generatedAt }
53
54
  : { source: 'fresh', storedAt: null };
54
55
  }
56
+ /**
57
+ * The largest progress line, in UTF-16 code units of its JSON. A runner
58
+ * whose line would be larger is sent without its report, as `omitted`; its
59
+ * rows come with the catalog document.
60
+ */
61
+ export const MAX_PROGRESS_LINE = 1024 * 1024;
62
+ /**
63
+ * A {@link CatalogProgress} that sends `session`'s probe as progress lines:
64
+ * the runners first, in the order the catalog will list them, then each
65
+ * runner as it answers, with its unknowns, and the agent skills on a line of
66
+ * their own once they are read. Skills read before the runners are known
67
+ * wait for the first line. They pass `filter`, as in the document. No skills,
68
+ * or skills too large for a line, come only with the document.
69
+ */
70
+ export function progressLines(session, emit, maxLine = MAX_PROGRESS_LINE, filter = {}) {
71
+ let pending = [];
72
+ let total = 0;
73
+ let named = false;
74
+ let early = null;
75
+ const sendSkills = (skills) => {
76
+ const line = { pending: [...pending], total, skills };
77
+ if (JSON.stringify(line).length <= maxLine)
78
+ emit(line);
79
+ };
80
+ return {
81
+ onRunners(runners) {
82
+ pending = inDisplayOrder(runners.map((runner) => ({ runner })), session.runnerOrder()).map((r) => r.runner);
83
+ total = runners.length;
84
+ named = true;
85
+ emit({ pending: [...pending], total });
86
+ if (early !== null)
87
+ sendSkills(early);
88
+ early = null;
89
+ },
90
+ onSkills(all) {
91
+ const skills = filterSkills(all, filter).map((h) => h.skill);
92
+ if (skills.length === 0)
93
+ return;
94
+ if (named)
95
+ sendSkills(skills);
96
+ else
97
+ early = skills;
98
+ },
99
+ onRunner(report, cache) {
100
+ pending = pending.filter((r) => r !== report.runner);
101
+ const unknowns = session.unknowns({ catalog: { reports: [report] }, cache: [cache] });
102
+ const line = { pending: [...pending], total, report, cache, unknowns };
103
+ emit(JSON.stringify(line).length <= maxLine
104
+ ? line
105
+ : { pending: [...pending], total, omitted: report.runner });
106
+ },
107
+ };
108
+ }
55
109
  /** Every task in the document, in catalog order. */
56
110
  function documentTasks(doc) {
57
111
  return doc.reports.flatMap((r) => r.tasks);
@@ -65,7 +119,8 @@ export function listCommand(home, share) {
65
119
  summary: 'the whole catalog: one pasteable command line per task, or the catalog document with --json',
66
120
  description: 'Each task line is the command Copy gives, quoted and with a cd when the task runs from ' +
67
121
  'its own directory, so it pastes into a shell; "run" takes that line or the task id, which ' +
68
- '--json shows. --output jsonl prints one runner report per line; "query" with no terms ' +
122
+ '--json shows. --output jsonl prints one runner report per line; with --progress it first ' +
123
+ 'prints a catalog-progress line as each runner answers. "query" with no terms ' +
69
124
  'prints one task per line. ' +
70
125
  'Probes every runner, so a script gets what the repository has now. --cached answers at ' +
71
126
  'once with the last listing saved under the same trust and settings, and does not check ' +
@@ -86,10 +141,16 @@ export function listCommand(home, share) {
86
141
  hidden: true,
87
142
  help: 'in the web view, answer with a probe already running for the same catalog',
88
143
  },
144
+ progress: {
145
+ kind: 'boolean',
146
+ help: 'send a catalog-progress line as each runner answers, before the document: with ' +
147
+ '--output jsonl, or as NDJSON over HTTP',
148
+ },
89
149
  },
90
150
  output: CatalogOutput,
91
151
  kind: 'catalog',
92
152
  schemaVersion: CATALOG_DOCUMENT_VERSION,
153
+ events: { schema: CatalogProgressOutput, kind: 'catalog-progress' },
93
154
  items: { field: 'reports', kind: 'report' },
94
155
  readOnly: true,
95
156
  examples: ['list', 'list --json', 'list --services', '-C ../repo list --cached --json'],
@@ -99,22 +160,37 @@ export function listCommand(home, share) {
99
160
  // A shared probe outlives the request that started it, so the session
100
161
  // runs on the share's signal; this request's own is passed to the share.
101
162
  const session = await openSession(globals, sharing ? { ...ctx, signal: share.signal } : ctx, home, positionals[0]);
102
- const read = async (cached, signal) => {
103
- const snapshot = await session.catalog({ cached, signal });
163
+ // Progress lines only when asked for, so --output jsonl is unchanged.
164
+ const own = flags.progress ? (line) => ctx.emit(line) : undefined;
165
+ const read = async (cached, signal, emit) => {
166
+ const snapshot = await session.catalog({
167
+ cached,
168
+ signal,
169
+ ...(emit !== undefined
170
+ ? { progress: progressLines(session, emit, MAX_PROGRESS_LINE, filter) }
171
+ : {}),
172
+ });
104
173
  const unknowns = session.unknowns(snapshot);
105
174
  noteUnknowns(ctx, session, snapshot, unknowns);
106
175
  return catalogDocument(snapshot, unknowns, filter, session.settings().trustedTools);
107
176
  };
108
177
  if (sharing) {
109
178
  const key = session.viewKey();
110
- if (flags.cached)
111
- return share.cached(key) ?? read(true, ctx.signal);
112
- return share.fresh(key, (signal) => read(false, signal), {
113
- join: flags.join,
179
+ const shared = (join) => share.fresh(key, (signal, emit) => read(false, signal, emit), {
180
+ join,
114
181
  signal: ctx.signal,
182
+ onEvent: own,
115
183
  });
184
+ if (flags.cached) {
185
+ // With nothing held yet, the probe serve started is the answer.
186
+ const held = share.cached(key);
187
+ if (held !== null)
188
+ return held;
189
+ return share.probing(key) ? shared(true) : read(true, ctx.signal, own);
190
+ }
191
+ return shared(flags.join);
116
192
  }
117
- return read(flags.cached);
193
+ return read(flags.cached, undefined, own);
118
194
  },
119
195
  text(doc) {
120
196
  const lines = [
@@ -30,7 +30,7 @@ export function queryCommand(home) {
30
30
  items: { field: 'tasks', kind: 'task' },
31
31
  exits: { 1: 'the terms matched nothing' },
32
32
  readOnly: true,
33
- examples: ['query build', "query 'dev web --json", 'query test --services'],
33
+ examples: ['query build', 'query "\'dev" web --json', 'query test --services'],
34
34
  async run({ flags, globals, positionals }, ctx) {
35
35
  const filter = {
36
36
  ...filterFrom(flags),
@@ -58,7 +58,7 @@ export function runCommand(home) {
58
58
  kind: 'run',
59
59
  examples: [
60
60
  'run just:justfile:build',
61
- 'run npm:package.json:test -- --watch',
61
+ 'run node-scripts:package.json:test -- --watch',
62
62
  'run x --dry-run --json',
63
63
  ],
64
64
  // Running a task is the command line's; an adapter may only ask what would run.
@@ -6,6 +6,7 @@ import { commandKit, CommandError, UsageError } from '@osdlc/cli-tool/command';
6
6
  import { closestMatches } from '@osdlc/config-layers/did-you-mean';
7
7
  import { humanAge } from '@osdlc/system-model/duration';
8
8
  import { BIN } from "../app.js";
9
+ import { DISCOVERY_VALUES } from "../config-keys.js";
9
10
  import { SessionError, createSession } from "../core/session.js";
10
11
  import { unknownLine } from "../core/unknowns.js";
11
12
  import { NOT_CACHED, refreshCostLabel, runnerLabel, staleLabel } from "../vocabulary.js";
@@ -41,7 +42,7 @@ export const GLOBALS = {
41
42
  },
42
43
  discovery: {
43
44
  kind: 'enum',
44
- choices: ['git', 'walk', 'auto'],
45
+ choices: DISCOVERY_VALUES,
45
46
  valueName: 'M',
46
47
  hidden: true,
47
48
  help: 'how to find directories. Default: auto',
@@ -6,6 +6,10 @@
6
6
  export declare const THEME_VALUES: readonly ["system", "light", "dark"];
7
7
  /** The web view's theme. */
8
8
  export type Theme = (typeof THEME_VALUES)[number];
9
+ /** The `discovery` values. */
10
+ export declare const DISCOVERY_VALUES: readonly ["git", "walk", "auto"];
11
+ /** The `open` values: what the bare `way` command opens. */
12
+ export declare const OPEN_VALUES: readonly ["tui", "web"];
9
13
  /**
10
14
  * The keys `config set` and `config unset` change from the command line only.
11
15
  * cli-tool's adapters, such as the HTTP one the web view's server runs,
@@ -4,6 +4,10 @@
4
4
  */
5
5
  /** The `theme` values for the web view. `system` follows the browser. */
6
6
  export const THEME_VALUES = ['system', 'light', 'dark'];
7
+ /** The `discovery` values. */
8
+ export const DISCOVERY_VALUES = ['git', 'walk', 'auto'];
9
+ /** The `open` values: what the bare `way` command opens. */
10
+ export const OPEN_VALUES = ['tui', 'web'];
7
11
  /**
8
12
  * The keys `config set` and `config unset` change from the command line only.
9
13
  * cli-tool's adapters, such as the HTTP one the web view's server runs,
package/dist/config.d.ts 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`).
@@ -54,23 +58,25 @@
54
58
  import { z } from 'zod';
55
59
  import { type PolicyDecisionOptions, type TrustPolicy } from '@osdlc/trust-repo';
56
60
  import { CONFIG_ENV_VAR, PROJECT_CONFIG_FILENAME } from './app.ts';
57
- import { type Theme } from './config-keys.ts';
61
+ import { OPEN_VALUES, type Theme } from './config-keys.ts';
58
62
  import { USER_CONFIG_FILENAME } from './xdg.ts';
59
63
  import type { WayOptions } from './catalog.ts';
60
64
  import { type SkillsSetting } from './core/skills.ts';
61
65
  export { CONFIG_ENV_VAR, PROJECT_CONFIG_FILENAME, USER_CONFIG_FILENAME };
62
66
  /**
63
67
  * The URL a written file's `$schema` names: the schema this release line ships
64
- * in `schema/config.json`. Raise it with each minor release.
68
+ * in `schema/config.json`. It follows package.json's version, and
69
+ * `scripts/write-config-schema.mjs` writes it into `schema/config.json` and
70
+ * the configuration guide.
65
71
  */
66
- export declare const CONFIG_SCHEMA_URL = "https://unpkg.com/@osdlc/wayfinder@0.8/schema/config.json";
67
- /** The `discovery` values. */
68
- export declare const DISCOVERY_VALUES: readonly ["git", "walk", "auto"];
69
- /** The `open` values: what the bare `way` command opens. */
70
- export declare const OPEN_VALUES: readonly ["tui", "web"];
72
+ export declare const CONFIG_SCHEMA_URL: string;
73
+ /** The smallest `runners.timeout`, in seconds. */
74
+ export declare const MIN_RUNNER_TIMEOUT_S = 1;
75
+ /** The largest `runners.timeout`, in seconds: one hour. */
76
+ export declare const MAX_RUNNER_TIMEOUT_S = 3600;
71
77
  /** What the bare `way` command opens. */
72
78
  export type OpenSurface = (typeof OPEN_VALUES)[number];
73
- export { THEME_VALUES, type Theme } from './config-keys.ts';
79
+ export { DISCOVERY_VALUES, OPEN_VALUES, THEME_VALUES, type Theme } from './config-keys.ts';
74
80
  /**
75
81
  * The configuration file, as a Zod schema. Every key is optional; the defaults
76
82
  * are {@link DEFAULT_CONFIG}.
@@ -80,6 +86,7 @@ export declare const WayfinderConfigSchema: z.ZodObject<{
80
86
  runners: z.ZodOptional<z.ZodObject<{
81
87
  disabled: z.ZodOptional<z.ZodArray<z.ZodString>>;
82
88
  order: z.ZodOptional<z.ZodArray<z.ZodString>>;
89
+ timeout: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
83
90
  }, z.core.$strip>>;
84
91
  allowExec: z.ZodOptional<z.ZodBoolean>;
85
92
  discovery: z.ZodOptional<z.ZodEnum<{
@@ -361,11 +368,19 @@ export declare function unsetConfigValue<T extends object>(config: T, key: strin
361
368
  export declare function parseConfigValue(raw: string): unknown;
362
369
  /** The key a typed key names, or undefined when it names no setting. */
363
370
  export declare function resolveConfigKey(key: string): string | undefined;
371
+ type ConfigOptions = Pick<WayOptions, 'exclude' | 'allowExec' | 'discovery' | 'excludePaths' | 'probeTimeoutMs' | 'maxProbeTimeoutMs'>;
364
372
  /**
365
373
  * The {@link WayOptions} fields this configuration controls. Only keys the
366
374
  * config sets are present, so a caller spreads its own flags after it.
375
+ *
376
+ * With `layers`, `runners.timeout` comes from them: the user's value replaces
377
+ * each runner's limit, and the project's caps it. Without, `config`'s value
378
+ * replaces each runner's limit.
367
379
  */
368
- export declare function collectOptionsFromConfig(config: WayfinderConfig): Pick<WayOptions, 'exclude' | 'allowExec' | 'discovery' | 'excludePaths'>;
380
+ export declare function collectOptionsFromConfig(config: WayfinderConfig, layers?: {
381
+ user: WayfinderConfig | null;
382
+ project: WayfinderConfig | null;
383
+ }): ConfigOptions;
369
384
  /**
370
385
  * `config.trust` as the policy `@osdlc/trust-repo` expects: the top-level
371
386
  * rules, and `trust.tools` as its per-scope rules.
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,18 +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.
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.
70
80
  */
71
- export const CONFIG_SCHEMA_URL = 'https://unpkg.com/@osdlc/wayfinder@0.8/schema/config.json';
81
+ export const CONFIG_SCHEMA_URL = `https://unpkg.com/@osdlc/wayfinder@${RELEASE_LINE}/schema/config.json`;
72
82
  const strings = (description) => z.array(z.string()).describe(description);
73
83
  /** One set of trust rules: globs over the resolved root, and origin owners. */
74
84
  const TrustRulesSchema = z.object({
@@ -76,11 +86,11 @@ const TrustRulesSchema = z.object({
76
86
  'descendants only. A leading ~ is your home.').optional(),
77
87
  owners: strings('Origin remote owners, as host/owner, or a bare owner for github.com/owner. Case-insensitive.').optional(),
78
88
  });
79
- /** The `discovery` values. */
80
- export const DISCOVERY_VALUES = ['git', 'walk', 'auto'];
81
- /** The `open` values: what the bare `way` command opens. */
82
- export const OPEN_VALUES = ['tui', 'web'];
83
- 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";
84
94
  /**
85
95
  * The configuration file, as a Zod schema. Every key is optional; the defaults
86
96
  * are {@link DEFAULT_CONFIG}.
@@ -92,6 +102,16 @@ export const WayfinderConfigSchema = z
92
102
  .object({
93
103
  disabled: strings('Runner ids to skip entirely.'),
94
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.'),
95
115
  })
96
116
  .partial()
97
117
  .describe('Which runners are read, and in what order they are shown.'),
@@ -150,6 +170,11 @@ function expectation(schema) {
150
170
  const s = unwrap(schema);
151
171
  if (s instanceof z.ZodBoolean)
152
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}`;
153
178
  if (s instanceof z.ZodEnum)
154
179
  return `one of ${s.options.join(', ')}`;
155
180
  if (s instanceof z.ZodArray)
@@ -212,7 +237,7 @@ function under(key, top) {
212
237
  export function projectIgnoreReason(key, value) {
213
238
  if (under(key, 'trust'))
214
239
  return 'a repository cannot grant itself trust';
215
- if (under(key, 'open') || under(key, 'theme') || under(key, 'skills')) {
240
+ if (USER_ONLY_KEYS.some((top) => under(key, top))) {
216
241
  return 'a personal setting, for the user config';
217
242
  }
218
243
  if (key === 'allowExec' && value === true)
@@ -354,7 +379,7 @@ function check(schema, value, key, file, warnings) {
354
379
  const bad = value.findIndex((item) => !s.element.safeParse(item).success);
355
380
  throw new ConfigError(`${where}${key} must be ${expectation(s)}, got ${describe(value[bad])} at index ${bad}`, file);
356
381
  }
357
- 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);
358
383
  throw new ConfigError(`${where}${key} must be ${expectation(s)}, got ${got}`, file);
359
384
  }
360
385
  /**
@@ -416,7 +441,7 @@ export function mergeConfig(base, over) {
416
441
  * execution.
417
442
  */
418
443
  export const DEFAULT_CONFIG = {
419
- runners: { disabled: [], order: [] },
444
+ runners: { disabled: [], order: [], timeout: null },
420
445
  allowExec: true,
421
446
  discovery: 'auto',
422
447
  excludePaths: [],
@@ -548,9 +573,19 @@ export async function writeConfigFile(file, config) {
548
573
  * The project layer with what a project may not set removed, and a warning
549
574
  * for each removal that could have mattered.
550
575
  */
551
- function projectRules(project, locations) {
576
+ function projectRules(project, user, locations) {
552
577
  const warnings = [];
553
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
+ }
554
589
  if (project.allowExec === true) {
555
590
  // Warned even when the user layer also says true: the file's setting is
556
591
  // never honoured, and its author might rely on it.
@@ -570,8 +605,9 @@ function projectRules(project, locations) {
570
605
  }
571
606
  delete out['trust'];
572
607
  }
573
- for (const key of ['open', 'theme', 'skills']) {
574
- 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) {
575
611
  warnings.push(`${locations.project}: ${key} is ignored in a project file — it is a personal setting; ` +
576
612
  `set it in your user config (${locations.user}) instead`);
577
613
  delete out[key];
@@ -601,7 +637,7 @@ export async function loadConfig(root, env = process.env, home = homeDir()) {
601
637
  const user = userRead?.config ?? null;
602
638
  let project = null;
603
639
  if (projectRead !== null) {
604
- const ruled = projectRules(projectRead.config, locations);
640
+ const ruled = projectRules(projectRead.config, user, locations);
605
641
  project = ruled.project;
606
642
  warnings.push(...ruled.warnings);
607
643
  }
@@ -801,16 +837,26 @@ export function parseConfigValue(raw) {
801
837
  export function resolveConfigKey(key) {
802
838
  return schemaAt(key) === undefined ? undefined : key;
803
839
  }
804
- // ── Uses of the config ──────────────────────────────────────────────────────
805
840
  /**
806
841
  * The {@link WayOptions} fields this configuration controls. Only keys the
807
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.
808
847
  */
809
- export function collectOptionsFromConfig(config) {
848
+ export function collectOptionsFromConfig(config, layers) {
810
849
  const options = {};
811
850
  const disabled = config.runners?.disabled;
812
851
  if (disabled !== undefined)
813
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;
814
860
  if (config.allowExec !== undefined)
815
861
  options.allowExec = config.allowExec;
816
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
  }
@@ -3,8 +3,9 @@
3
3
  * and the operations every surface shares. See `README.md` beside this file
4
4
  * for how the CLI, the terminal UI and the web view use it.
5
5
  */
6
- import type { Catalog, Project, RunnerCacheState, Task } from '@osdlc/system-model/detect';
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
  }
@@ -59,6 +60,25 @@ export type CacheState = RunnerCacheState & {
59
60
  /** How long this runner's probe took, when it was probed in this call. */
60
61
  probeMs?: number | undefined;
61
62
  };
63
+ /**
64
+ * What a probe reports while it runs, so a surface can draw each runner as
65
+ * it answers. See {@link Session.catalog}.
66
+ */
67
+ export interface CatalogProgress {
68
+ /** Once, before any runner answers: every runner this call probes. */
69
+ onRunners?(runners: readonly string[]): void;
70
+ /**
71
+ * Once per runner, as it answers, a withheld runner included: its report
72
+ * and its cache state. The snapshot `catalog` resolves with is still the
73
+ * answer to show; it can add a diagnostic this report lacks.
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;
81
+ }
62
82
  /** A catalog and where each runner's rows came from. */
63
83
  export interface CatalogSnapshot {
64
84
  /** Grouped and in the configured runner order. */
@@ -162,10 +182,13 @@ export interface Session {
162
182
  * checks each runner's files, and probes only the runners missing from it.
163
183
  * A probe always writes the store. `signal`
164
184
  * stops this call's probes as well as the session's own signal.
185
+ * `progress` hears about each runner this call probes as it answers; an
186
+ * answer from the saved view or the store probes none.
165
187
  */
166
188
  catalog(opts?: {
167
189
  cached?: boolean;
168
190
  signal?: AbortSignal | undefined;
191
+ progress?: CatalogProgress | undefined;
169
192
  }): Promise<CatalogSnapshot>;
170
193
  /**
171
194
  * The catalog from the store alone, probing nothing: for a first paint
@@ -196,11 +219,14 @@ export interface Session {
196
219
  */
197
220
  viewKey(): string;
198
221
  /** The tasks of `catalog` that pass `filter`, best first when there is a query. */
199
- search(catalog: Catalog, filter: TaskFilter): TaskHit[];
222
+ search(catalog: Pick<Catalog, 'reports'>, filter: TaskFilter): TaskHit[];
200
223
  /** The skills that pass `filter`, matched as {@link search} matches tasks. */
201
224
  searchSkills(skills: readonly SkillRow[], filter: TaskFilter): SkillHit[];
202
225
  /** Everything this session could not know about `snapshot`. */
203
- unknowns(snapshot: Pick<CatalogSnapshot, 'catalog' | 'cache'>): Unknown[];
226
+ unknowns(snapshot: {
227
+ catalog: Pick<Catalog, 'reports'>;
228
+ cache: readonly CacheState[];
229
+ }): Unknown[];
204
230
  /** Whether a trust grant would change this session's execution. */
205
231
  trustable(): boolean;
206
232
  /**
@@ -249,7 +275,7 @@ export interface Session {
249
275
  * {@link SessionError}: `task-not-found`, `ambiguous-task`, `not-runnable` or
250
276
  * `bad-arguments`.
251
277
  */
252
- resolveRun(catalog: Catalog, id: string, args?: readonly string[]): RunPlan;
278
+ resolveRun(catalog: Pick<Catalog, 'reports'>, id: string, args?: readonly string[]): RunPlan;
253
279
  }
254
280
  /**
255
281
  * Start a session: find the root, load config, decide execution against the
@@ -259,4 +285,4 @@ export interface Session {
259
285
  */
260
286
  export declare function createSession(opts: SessionOptions): Promise<Session>;
261
287
  /** See {@link Session.resolveRun}. */
262
- export declare function resolveRun(project: Project, root: string, catalog: Catalog, id: string, args?: readonly string[]): RunPlan;
288
+ export declare function resolveRun(project: Project, root: string, catalog: Pick<Catalog, 'reports'>, id: string, args?: readonly string[]): RunPlan;