@osdlc/wayfinder 0.8.0 → 0.9.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.
@@ -224,6 +224,81 @@ export declare const CatalogOutput: z.ZodObject<{
224
224
  maxDepth: z.ZodOptional<z.ZodNumber>;
225
225
  }, z.core.$strip>;
226
226
  }, z.core.$strip>;
227
+ /**
228
+ * 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
+ */
231
+ export declare const CatalogProgressOutput: z.ZodObject<{
232
+ pending: z.ZodArray<z.ZodString>;
233
+ total: z.ZodNumber;
234
+ report: z.ZodOptional<z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>;
235
+ omitted: z.ZodOptional<z.ZodString>;
236
+ cache: z.ZodOptional<z.ZodObject<{
237
+ runner: z.ZodString;
238
+ state: z.ZodEnum<{
239
+ fresh: "fresh";
240
+ stale: "stale";
241
+ miss: "miss";
242
+ }>;
243
+ reason: z.ZodOptional<z.ZodEnum<{
244
+ changed: "changed";
245
+ "max-age": "max-age";
246
+ excludes: "excludes";
247
+ exec: "exec";
248
+ version: "version";
249
+ tool: "tool";
250
+ }>>;
251
+ ageMs: z.ZodOptional<z.ZodNumber>;
252
+ estimateMs: z.ZodNullable<z.ZodNumber>;
253
+ slow: z.ZodBoolean;
254
+ cost: z.ZodOptional<z.ZodEnum<{
255
+ slow: "slow";
256
+ cheap: "cheap";
257
+ }>>;
258
+ probeMs: z.ZodOptional<z.ZodNumber>;
259
+ }, z.core.$strip>>;
260
+ unknowns: z.ZodOptional<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
261
+ kind: z.ZodLiteral<"withheld">;
262
+ runner: z.ZodString;
263
+ reason: z.ZodEnum<{
264
+ untrusted: "untrusted";
265
+ "tool-untrusted": "tool-untrusted";
266
+ "exec-off": "exec-off";
267
+ }>;
268
+ missing: z.ZodOptional<z.ZodArray<z.ZodString>>;
269
+ label: z.ZodString;
270
+ }, z.core.$strip>, z.ZodObject<{
271
+ kind: z.ZodLiteral<"parameters">;
272
+ runner: z.ZodString;
273
+ reason: z.ZodEnum<{
274
+ "exec-withheld": "exec-withheld";
275
+ "tool-missing": "tool-missing";
276
+ "tool-failed": "tool-failed";
277
+ "not-read": "not-read";
278
+ "editor-variable": "editor-variable";
279
+ }>;
280
+ tasks: z.ZodArray<z.ZodString>;
281
+ label: z.ZodString;
282
+ }, z.core.$strip>, z.ZodObject<{
283
+ kind: z.ZodLiteral<"stale">;
284
+ runner: z.ZodString;
285
+ reason: z.ZodOptional<z.ZodEnum<{
286
+ changed: "changed";
287
+ "max-age": "max-age";
288
+ excludes: "excludes";
289
+ exec: "exec";
290
+ version: "version";
291
+ tool: "tool";
292
+ }>>;
293
+ ageMs: z.ZodOptional<z.ZodNumber>;
294
+ label: z.ZodString;
295
+ }, z.core.$strip>, z.ZodObject<{
296
+ kind: z.ZodLiteral<"binary">;
297
+ runner: z.ZodString;
298
+ binary: z.ZodString;
299
+ label: z.ZodString;
300
+ }, z.core.$strip>], "kind">>>;
301
+ }, z.core.$strip>;
227
302
  /** The catalog document's `schemaVersion`: the catalog's own. */
228
303
  export declare const CATALOG_DOCUMENT_VERSION = 1;
229
304
  /** `way query --json`: the matching tasks, best first. */
@@ -427,6 +502,7 @@ export declare const RunOutput: z.ZodObject<{
427
502
  }, z.core.$strip>], "kind">>;
428
503
  }, z.core.$strip>;
429
504
  export type CatalogDocumentBody = z.input<typeof CatalogOutput>;
505
+ export type CatalogProgressBody = z.input<typeof CatalogProgressOutput>;
430
506
  export type QueryDocumentBody = z.input<typeof QueryOutput>;
431
507
  export type ProvidersDocumentBody = z.input<typeof ProvidersOutput>;
432
508
  export type RunDocumentBody = z.input<typeof RunOutput>;
package/dist/documents.js CHANGED
@@ -113,6 +113,24 @@ export const CatalogOutput = z.object({
113
113
  .describe('The tool ids trusted on their own here. Empty when the repository is trusted as a whole.'),
114
114
  filter: FilterZ,
115
115
  });
116
+ /**
117
+ * One line `list --progress` sends while it probes, before the catalog
118
+ * document: which runners have not answered, and the one that just did.
119
+ */
120
+ export const CatalogProgressOutput = z.object({
121
+ pending: z.array(z.string()).describe('The runners that have not answered yet, in report order.'),
122
+ total: z.number().int().describe('How many runners the probe reports.'),
123
+ report: RunnerReportZ.optional().describe('The runner that answered. Absent on the first line, which only names the runners, and when omitted is set.'),
124
+ omitted: z
125
+ .string()
126
+ .optional()
127
+ .describe('A runner that answered with a report too large for one line. Its rows come with the catalog document.'),
128
+ cache: CacheStateZ.optional().describe("The answered runner's cache verdict."),
129
+ unknowns: z
130
+ .array(UnknownZ)
131
+ .optional()
132
+ .describe('What could not be read about the answered runner.'),
133
+ });
116
134
  /** The catalog document's `schemaVersion`: the catalog's own. */
117
135
  export const CATALOG_DOCUMENT_VERSION = CATALOG_SCHEMA_VERSION;
118
136
  /** `way query --json`: the matching tasks, best first. */
package/dist/index.d.ts CHANGED
@@ -13,11 +13,11 @@
13
13
  */
14
14
  import type { DiscoveryMode, RunnerReport } from '@osdlc/system-model/detect';
15
15
  import type { TaskFilter } from './core/filter.ts';
16
- import { type CacheState, type SessionFlags } from './core/session.ts';
16
+ import { type CacheState, type CatalogProgress, type SessionFlags } from './core/session.ts';
17
17
  import type { SkillRow } from './core/skills.ts';
18
18
  import type { Unknown } from './core/unknowns.ts';
19
19
  import type { DocumentGroup } from './groups.ts';
20
- export { SessionError, type CacheState, type SessionFlags } from './core/session.ts';
20
+ export { SessionError, type CacheState, type CatalogProgress, type SessionFlags, } from './core/session.ts';
21
21
  export { filterTasks, hasQuery, keepsTask, sourceDepth } from './core/filter.ts';
22
22
  export type { TaskFilter, TaskHit } from './core/filter.ts';
23
23
  export { filterSkills, skillLine, SKILLS_SETTING_VALUES } from './core/skills.ts';
@@ -54,6 +54,12 @@ export interface BuildCatalogOptions {
54
54
  filter?: TaskFilter | undefined;
55
55
  /** Stops every probe. */
56
56
  signal?: AbortSignal | undefined;
57
+ /**
58
+ * Hears about each runner the call probes as it answers: `onRunners`
59
+ * once, then `onRunner` per runner. An answer from the saved listing or
60
+ * the store probes none. The document is still the answer to use.
61
+ */
62
+ progress?: CatalogProgress | undefined;
57
63
  /**
58
64
  * Called with each warning from the config files and tool modules, such
59
65
  * as a project file key that is ignored. The CLI prints these on stderr.
package/dist/index.js CHANGED
@@ -13,9 +13,9 @@
13
13
  */
14
14
  import { catalogDocument } from "./commands/list.js";
15
15
  import { flushViews } from "./core/saved-view.js";
16
- import { createSession } from "./core/session.js";
16
+ import { createSession, } from "./core/session.js";
17
17
  import { CATALOG_DOCUMENT_VERSION } from "./documents.js";
18
- export { SessionError } from "./core/session.js";
18
+ export { SessionError, } from "./core/session.js";
19
19
  export { filterTasks, hasQuery, keepsTask, sourceDepth } from "./core/filter.js";
20
20
  export { filterSkills, skillLine, SKILLS_SETTING_VALUES } from "./core/skills.js";
21
21
  export { unknownLine, unknownsOf } from "./core/unknowns.js";
@@ -50,7 +50,10 @@ export async function buildCatalog(options) {
50
50
  });
51
51
  for (const warning of session.warnings)
52
52
  options.onWarning?.(warning);
53
- const snapshot = await session.catalog({ cached: options.cached === true });
53
+ const snapshot = await session.catalog({
54
+ cached: options.cached === true,
55
+ progress: options.progress,
56
+ });
54
57
  // A library caller gets a call whose writes are done.
55
58
  await flushViews();
56
59
  const body = catalogDocument(snapshot, session.unknowns(snapshot), options.filter ?? {}, session.settings().trustedTools);
@@ -20,8 +20,15 @@
20
20
  * An entry is used only by a request whose session has the same view key
21
21
  * (trust and settings), so a trust grant or a saved setting is never answered
22
22
  * with rows from before it. Only unfiltered listings are shared.
23
+ *
24
+ * A shared probe's progress lines (one per runner as it answers) go to every
25
+ * waiter that asks for them. One that joins late gets the lines sent so far
26
+ * first, so each waiter sees every runner.
23
27
  */
24
28
  import type { CatalogBody } from '../commands/list.ts';
29
+ import type { CatalogProgressBody } from '../documents.ts';
30
+ /** Sends one progress line of a shared probe. */
31
+ export type ProgressSink = (line: CatalogProgressBody) => void;
25
32
  /** See the module comment. One per command tree; `serve` turns it on. */
26
33
  export interface CatalogShare {
27
34
  /** True once `serve` has started, until it stops. The command line never shares. */
@@ -35,15 +42,20 @@ export interface CatalogShare {
35
42
  remember(key: string, body: CatalogBody): void;
36
43
  /** The newest catalog for `key`, marked as cached, or null. */
37
44
  cached(key: string): CatalogBody | null;
45
+ /** True while a probe for `key` runs. */
46
+ probing(key: string): boolean;
38
47
  /**
39
48
  * A fresh catalog for `key`. With `join`, the probe already running for it
40
49
  * when there is one; otherwise `probe` starts now. `probe` gets the
41
50
  * share's signal, not the caller's. `signal` is the caller's own: when it
42
51
  * aborts, this call rejects and the probe goes on for the other waiters.
52
+ * `probe` sends its progress lines through its second argument; `onEvent`
53
+ * gets them, the ones sent before this call first.
43
54
  */
44
- fresh(key: string, probe: (signal: AbortSignal) => Promise<CatalogBody>, opts: {
55
+ fresh(key: string, probe: (signal: AbortSignal, emit: ProgressSink) => Promise<CatalogBody>, opts: {
45
56
  join: boolean;
46
57
  signal?: AbortSignal | undefined;
58
+ onEvent?: ProgressSink | undefined;
47
59
  }): Promise<CatalogBody>;
48
60
  /** How many callers wait on the running probe for `key`. For tests. */
49
61
  waiting(key: string): number;
@@ -20,7 +20,24 @@
20
20
  * An entry is used only by a request whose session has the same view key
21
21
  * (trust and settings), so a trust grant or a saved setting is never answered
22
22
  * with rows from before it. Only unfiltered listings are shared.
23
+ *
24
+ * A shared probe's progress lines (one per runner as it answers) go to every
25
+ * waiter that asks for them. One that joins late gets the lines sent so far
26
+ * first, so each waiter sees every runner.
27
+ */
28
+ /**
29
+ * Give `line` to one waiter's listener. False when it throws: that waiter
30
+ * gets no more lines, and the probe and the other waiters go on.
23
31
  */
32
+ function tell(listener, line) {
33
+ try {
34
+ listener(line);
35
+ return true;
36
+ }
37
+ catch {
38
+ return false;
39
+ }
40
+ }
24
41
  export function createCatalogShare() {
25
42
  let active = false;
26
43
  const stopper = new AbortController();
@@ -31,13 +48,26 @@ export function createCatalogShare() {
31
48
  const controller = new AbortController();
32
49
  const onStop = () => controller.abort(stopper.signal.reason);
33
50
  stopper.signal.addEventListener('abort', onStop, { once: true });
51
+ const events = [];
52
+ const listeners = new Set();
53
+ const emit = (line) => {
54
+ if (run.settled)
55
+ return;
56
+ events.push(line);
57
+ for (const listener of listeners) {
58
+ if (!tell(listener, line))
59
+ listeners.delete(listener);
60
+ }
61
+ };
34
62
  const run = {
35
63
  key,
36
64
  seq: ++seq,
37
65
  controller,
38
- promise: Promise.resolve().then(() => probe(controller.signal)),
66
+ promise: Promise.resolve().then(() => probe(controller.signal, emit)),
39
67
  waiters: 0,
40
68
  settled: false,
69
+ events,
70
+ listeners,
41
71
  };
42
72
  running = run;
43
73
  const done = () => {
@@ -54,7 +84,7 @@ export function createCatalogShare() {
54
84
  }, done);
55
85
  return run;
56
86
  };
57
- const wait = (run, signal) => new Promise((resolve, reject) => {
87
+ const wait = (run, signal, onEvent) => new Promise((resolve, reject) => {
58
88
  let left = false;
59
89
  run.waiters++;
60
90
  const leave = () => {
@@ -62,6 +92,8 @@ export function createCatalogShare() {
62
92
  return;
63
93
  left = true;
64
94
  run.waiters--;
95
+ if (onEvent !== undefined)
96
+ run.listeners.delete(onEvent);
65
97
  signal?.removeEventListener('abort', onAbort);
66
98
  if (run.waiters === 0 && !run.settled)
67
99
  run.controller.abort(new Error('nobody is waiting'));
@@ -73,6 +105,10 @@ export function createCatalogShare() {
73
105
  if (signal?.aborted === true)
74
106
  return onAbort();
75
107
  signal?.addEventListener('abort', onAbort, { once: true });
108
+ // After `leave` is set up, so a listener that throws cannot leak this waiter.
109
+ if (onEvent !== undefined && run.events.every((line) => tell(onEvent, line))) {
110
+ run.listeners.add(onEvent);
111
+ }
76
112
  run.promise.then((body) => {
77
113
  leave();
78
114
  resolve(body);
@@ -104,10 +140,13 @@ export function createCatalogShare() {
104
140
  ? body
105
141
  : { ...body, source: 'cached', storedAt: body.generatedAt };
106
142
  },
143
+ probing(key) {
144
+ return running !== null && running.key === key && !running.settled;
145
+ },
107
146
  fresh(key, probe, opts) {
108
147
  const joinable = running !== null && running.key === key && !running.settled;
109
148
  const run = opts.join && joinable ? running : start(key, probe);
110
- return wait(run, opts.signal);
149
+ return wait(run, opts.signal, opts.onEvent);
111
150
  },
112
151
  waiting(key) {
113
152
  return running !== null && running.key === key ? running.waiters : 0;
@@ -81,11 +81,13 @@ export interface WebServer {
81
81
  export declare function startServer(options: ServeOptions): Promise<WebServer>;
82
82
  /**
83
83
  * The first lines `serve` prints: the address, the root, what was collected
84
- * and what came from the store. Repository text in them is terminal-safe.
84
+ * and what came from the store. With nothing saved (`first` null), `root`
85
+ * and that the page shows each runner as it answers. Repository text in them
86
+ * is terminal-safe.
85
87
  */
86
- export declare function startupSummary(address: string, first: Omit<CatalogSnapshot, 'origin'> & {
88
+ export declare function startupSummary(address: string, first: (Omit<CatalogSnapshot, 'origin'> & {
87
89
  origin?: CatalogSnapshot['origin'];
88
- }): string;
90
+ }) | null, root?: string): string;
89
91
  /** The program that opens a URL in the default browser on `platform`, before the URL. */
90
92
  export declare function browserOpener(platform: NodeJS.Platform): {
91
93
  binary: string;
@@ -13,7 +13,7 @@ import { commandString, spawnRunnerAsync } from '@osdlc/command-seam';
13
13
  import { humanAge } from '@osdlc/system-model/duration';
14
14
  import { APP, BIN } from "../app.js";
15
15
  import { handOff as defaultHandOff } from "../core/run.js";
16
- import { catalogDocument } from "../commands/list.js";
16
+ import { catalogDocument, progressLines } from "../commands/list.js";
17
17
  import { buildPage } from "../page.js";
18
18
  import { terminalSafe } from "../terminal-text.js";
19
19
  import { WITHHELD, runnerLabel, staleLabel } from "../vocabulary.js";
@@ -144,9 +144,16 @@ export async function startServer(options) {
144
144
  }
145
145
  /**
146
146
  * The first lines `serve` prints: the address, the root, what was collected
147
- * and what came from the store. Repository text in them is terminal-safe.
147
+ * and what came from the store. With nothing saved (`first` null), `root`
148
+ * and that the page shows each runner as it answers. Repository text in them
149
+ * is terminal-safe.
148
150
  */
149
- export function startupSummary(address, first) {
151
+ export function startupSummary(address, first, root = first?.catalog.root ?? '') {
152
+ if (first === null) {
153
+ return (`${APP} ${address}\n` +
154
+ ` root ${terminalSafe(root)}\n` +
155
+ ` collected nothing yet; the page shows each runner as it answers\n`);
156
+ }
150
157
  // A withheld runner reports `absent`. It is named withheld here, because
151
158
  // absent means the repository does not have it.
152
159
  const counts = first.catalog.reports
@@ -190,27 +197,28 @@ export async function serve(options) {
190
197
  const web = await startServer(options);
191
198
  const address = web.server.url;
192
199
  const bootUrl = () => `${address}/?boot=${web.signIn.bootToken}`;
193
- // The saved view when there is one, else the store, so the address shows
194
- // at once. A probe starts now; the page's first fresh read joins it.
200
+ // The saved view when there is one, so the address shows at once. A probe
201
+ // starts now; the page's first reads join it, and without a saved view
202
+ // the page shows each runner as it answers. Without a share (tests), the
203
+ // store, then a probe.
195
204
  const session = options.session;
196
- const first = (await session.savedCatalog()) ?? (await session.catalog({ cached: true }));
197
205
  const share = options.share;
206
+ const saved = await session.savedCatalog();
207
+ const first = saved ?? (share === undefined ? await session.catalog({ cached: true }) : null);
198
208
  if (share !== undefined) {
199
209
  const key = session.viewKey();
200
210
  const documentOf = (snapshot) => catalogDocument(snapshot, session.unknowns(snapshot), {}, session.settings().trustedTools);
201
- share.remember(key, documentOf(first));
211
+ if (first !== null)
212
+ share.remember(key, documentOf(first));
202
213
  share.activate();
203
214
  // It waits on the share's own signal, so it runs to the end unless the
204
215
  // server stops, as on a hand-off.
205
216
  void share
206
- .fresh(key, async (signal) => documentOf(await session.catalog({ signal })), {
207
- join: true,
208
- signal: share.signal,
209
- })
217
+ .fresh(key, async (signal, emit) => documentOf(await session.catalog({ signal, progress: progressLines(session, emit) })), { join: true, signal: share.signal })
210
218
  .catch(() => { });
211
219
  }
212
220
  web.signIn.arm();
213
- options.stdout(startupSummary(address, first));
221
+ options.stdout(startupSummary(address, first, session.root));
214
222
  options.stdout(` live the page refreshes on focus and every 15s; Refresh re-reads\n`);
215
223
  options.stdout(` stop Ctrl-C\n`);
216
224
  /** Open the current link, or print it when there is no browser to open. */
package/dist/tui/app.d.ts CHANGED
@@ -5,9 +5,11 @@
5
5
  * host, so every key and every frame can be checked without a terminal.
6
6
  *
7
7
  * Collection is async, which is what much of the state handling is for: keys
8
- * arrive during a refresh, and a row can be stale.
8
+ * arrive during a refresh, and a row can be stale. With nothing on screen,
9
+ * each runner's rows are drawn as that runner answers. Over rows already on
10
+ * screen, a refresh replaces them all at once when it ends.
9
11
  */
10
- import type { Catalog, RunnerCacheState, Task } from '@osdlc/system-model/detect';
12
+ import type { Catalog, RunnerCacheState, RunnerReport, Task } from '@osdlc/system-model/detect';
11
13
  import type { Mode } from '@osdlc/system-model/match';
12
14
  import type { Settings } from '../config.ts';
13
15
  import type { TaskHit } from '../core/filter.ts';
@@ -74,6 +76,17 @@ export type ListEntry = {
74
76
  /** Everything the screen shows. */
75
77
  export interface TuiState {
76
78
  catalog: Catalog | null;
79
+ /**
80
+ * The reports the first probe has sent so far, while there is no catalog
81
+ * to show. Null once there is one, and before a probe starts.
82
+ */
83
+ partial: RunnerReport[] | null;
84
+ /** The runners the running probe has not heard from yet. */
85
+ pending: string[];
86
+ /** How many runners the running probe reports; -1 until it names them. */
87
+ expected: number;
88
+ /** When the running probe started, in ms, so a long refresh can name what it waits on. */
89
+ loadStarted: number;
77
90
  /** Where each runner's rows came from, one entry per selected runner. */
78
91
  cache: CacheState[];
79
92
  /** The agent skills from the last probe. */