@reticlehq/core 3.7.0 → 3.8.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 (108) hide show
  1. package/dist/activation-entry.d.ts +9 -0
  2. package/dist/activation-entry.js +9 -0
  3. package/dist/artifacts/drive-script.d.ts +64 -64
  4. package/dist/artifacts/flow-constants.d.ts +15 -0
  5. package/dist/artifacts/flow-constants.js +15 -0
  6. package/dist/artifacts/flow-expect-flat.d.ts +8 -8
  7. package/dist/artifacts/flow-results.d.ts +11 -0
  8. package/dist/artifacts/flow-types.d.ts +164 -118
  9. package/dist/artifacts/flow-types.js +12 -0
  10. package/dist/artifacts/harness-credits.d.ts +6 -3
  11. package/dist/artifacts/harness-credits.js +9 -6
  12. package/dist/artifacts/harness-map.d.ts +6 -6
  13. package/dist/artifacts/impact.d.ts +77 -80
  14. package/dist/artifacts/impact.js +34 -17
  15. package/dist/artifacts/journal.d.ts +25 -6
  16. package/dist/artifacts/journal.js +13 -0
  17. package/dist/artifacts/prompt-context.d.ts +12 -0
  18. package/dist/artifacts/prompt-context.js +14 -3
  19. package/dist/graph/app-graph.d.ts +137 -0
  20. package/dist/graph/app-graph.js +498 -0
  21. package/dist/hooks/hook-events.d.ts +22 -22
  22. package/dist/hud-entry.js +1 -1
  23. package/dist/identity/checkout.d.ts +41 -0
  24. package/dist/identity/checkout.js +118 -0
  25. package/dist/identity/state-dir.d.ts +23 -0
  26. package/dist/identity/state-dir.js +43 -0
  27. package/dist/index.d.ts +10 -0
  28. package/dist/index.js +10 -0
  29. package/dist/onboarding.d.ts +22 -1
  30. package/dist/onboarding.js +19 -0
  31. package/dist/registry/dev-server-registry.d.ts +2 -2
  32. package/dist/schema/event-message.json +3 -1
  33. package/dist/schema/event-payloads.json +116 -1
  34. package/dist/schema/event-type.json +3 -1
  35. package/dist/schema/hello-message.json +21 -0
  36. package/dist/schema/reticle-event.json +3 -1
  37. package/dist/schema/reticle-message.json +24 -1
  38. package/dist/telemetry-bug.d.ts +6 -6
  39. package/dist/telemetry-entry.d.ts +1 -1
  40. package/dist/telemetry-entry.js +1 -1
  41. package/dist/telemetry-feedback.d.ts +14 -0
  42. package/dist/telemetry-feedback.js +19 -0
  43. package/dist/telemetry-refusal.d.ts +2 -2
  44. package/dist/telemetry-session.d.ts +23 -8
  45. package/dist/telemetry-session.js +15 -4
  46. package/dist/telemetry-signals.d.ts +227 -9
  47. package/dist/telemetry-signals.js +88 -1
  48. package/dist/telemetry.d.ts +379 -72
  49. package/dist/telemetry.js +71 -5
  50. package/dist/verdict/check-sentence.d.ts +34 -0
  51. package/dist/verdict/check-sentence.js +228 -0
  52. package/dist/verdict/consequence.d.ts +15 -0
  53. package/dist/verdict/consequence.js +11 -0
  54. package/dist/verdict/findings.d.ts +10 -0
  55. package/dist/verdict/findings.js +13 -0
  56. package/dist/verdict/instrumentation-coverage.d.ts +3 -34
  57. package/dist/verdict/instrumentation-coverage.js +14 -58
  58. package/dist/verdict/instrumentation-gap.d.ts +79 -0
  59. package/dist/verdict/instrumentation-gap.js +64 -0
  60. package/dist/verdict/predicate-tree.d.ts +2 -0
  61. package/dist/verdict/predicate-tree.js +16 -0
  62. package/dist/verdict/predicate.d.ts +2 -1
  63. package/dist/verdict/predicate.js +103 -12
  64. package/dist/verdict/property-assertion.d.ts +2 -2
  65. package/dist/verdict/run-report.d.ts +166 -0
  66. package/dist/verdict/run-report.js +53 -0
  67. package/dist/verdict/security.d.ts +36 -2
  68. package/dist/verdict/security.js +94 -14
  69. package/dist/verdict/verification-run.d.ts +95 -38
  70. package/dist/verdict/verification-run.js +33 -2
  71. package/dist/verdict/verify-progress.d.ts +6 -6
  72. package/dist/wire/constants/constants.d.ts +56 -141
  73. package/dist/wire/constants/constants.js +64 -144
  74. package/dist/wire/constants/discovery.d.ts +4 -4
  75. package/dist/wire/constants/discovery.js +4 -4
  76. package/dist/wire/constants/event-types.d.ts +35 -1
  77. package/dist/wire/constants/event-types.js +33 -1
  78. package/dist/wire/constants/hud-controls.js +0 -2
  79. package/dist/wire/constants/hud-use.d.ts +4 -0
  80. package/dist/wire/constants/hud-use.js +4 -0
  81. package/dist/wire/constants/mcp-wire.d.ts +16 -0
  82. package/dist/wire/constants/mcp-wire.js +16 -0
  83. package/dist/wire/constants/response-body-reason.d.ts +19 -0
  84. package/dist/wire/constants/response-body-reason.js +18 -0
  85. package/dist/wire/constants/reticle-env.d.ts +138 -0
  86. package/dist/wire/constants/reticle-env.js +138 -0
  87. package/dist/wire/constants/session-constants.d.ts +11 -0
  88. package/dist/wire/constants/session-constants.js +11 -0
  89. package/dist/wire/event-payloads.d.ts +150 -36
  90. package/dist/wire/event-payloads.js +83 -16
  91. package/dist/wire/messages.d.ts +102 -36
  92. package/dist/wire/messages.js +16 -0
  93. package/dist/wire/narrow.d.ts +6 -0
  94. package/dist/wire/narrow.js +26 -0
  95. package/dist/wire/next-step.d.ts +90 -0
  96. package/dist/wire/next-step.js +37 -0
  97. package/dist/wire/platform-link.d.ts +7 -0
  98. package/dist/wire/platform-link.js +12 -6
  99. package/dist/wire/production/activation-ticket.d.ts +64 -0
  100. package/dist/wire/production/activation-ticket.js +148 -0
  101. package/dist/wire/production/hello-mode.d.ts +35 -0
  102. package/dist/wire/production/hello-mode.js +32 -0
  103. package/dist/wire/production/production-policy.d.ts +138 -0
  104. package/dist/wire/production/production-policy.js +133 -0
  105. package/dist/wire/tool-names.d.ts +2 -0
  106. package/dist/wire/tool-names.js +2 -0
  107. package/dist/wire/types.d.ts +73 -48
  108. package/package.json +5 -1
@@ -0,0 +1,498 @@
1
+ /**
2
+ * The App Graph (what the cloud calls the App Map): the app as a graph, built from what each run recorded.
3
+ *
4
+ * Nodes are screens (route patterns), actions (what an act pressed, anchored the way a saved flow
5
+ * anchors it), requests (method and route pattern) and the things writes made. Edges say a screen HAS
6
+ * an action, an action LEADS TO a screen, SENDS a request and MAKES a thing. Everything here was
7
+ * observed: the model's words never add a node. Ids collapse (`templatePath`), so a hundred
8
+ * conversations are one screen and a row the drive created is a thing made, never a new screen: the
9
+ * create-and-back-out loop a state graph otherwise falls into: each new row looks like a new screen,
10
+ * so the drive keeps making rows and backing out.
11
+ *
12
+ * Pure: a run's acts and recording in, a run's map out; merged into the app's map across runs. One fold,
13
+ * here in core, so the cloud verifier and the open-source daemon describe an app the same way: a fix to
14
+ * how a screen is named lands in both. A run's acts arrive already parsed (`DrivenStep`): reading them
15
+ * off a harness's tool calls needs the server package, so each caller does that and hands this the steps.
16
+ */
17
+ import { EventType } from '../wire/constants/event-types.js';
18
+ import { NetInitiator, isDevToolingUrl } from '../wire/net.js';
19
+ /** An app's identity: its origin, so every path of one deployment is one app. */
20
+ export function appIdentity(url) {
21
+ try {
22
+ return new URL(url).origin;
23
+ }
24
+ catch {
25
+ return url;
26
+ }
27
+ }
28
+ /**
29
+ * Segments that identify one record rather than one kind of record: numeric, uuid-shaped, and a long
30
+ * run of id characters (`chat_659b…`, `run_9_1792651401085`). Anything cleverer would start guessing.
31
+ */
32
+ const UUID_LIKE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
33
+ const NUMERIC = /^\d+$/;
34
+ const ID_RUN = /[0-9a-f]{12,}|\d{9,}/i;
35
+ const ID_PLACEHOLDER = ':id';
36
+ /** A path or URL as a route pattern: query dropped, origin dropped, record ids as `:id`. */
37
+ export function templatePath(url) {
38
+ const withoutQuery = url.split('?')[0] ?? url;
39
+ const path = withoutQuery.startsWith('http')
40
+ ? (withoutQuery.split('/').slice(3).join('/') ?? '')
41
+ : withoutQuery.replace(/^\/+/, '');
42
+ const segments = path
43
+ .split('/')
44
+ .map((segment) => NUMERIC.test(segment) || UUID_LIKE.test(segment) || ID_RUN.test(segment)
45
+ ? ID_PLACEHOLDER
46
+ : segment);
47
+ return `/${segments.join('/')}`;
48
+ }
49
+ const asString = (value) => 'string' === typeof value ? value : undefined;
50
+ /** The route a route-change event names: the app's own pattern first, else the path it went to. */
51
+ export const routeOf = (data) => asString(data['pattern']) ??
52
+ asString(data['pathname']) ??
53
+ asString(data['to']) ??
54
+ asString(data['path']);
55
+ export const MapNodeKind = {
56
+ SCREEN: 'screen',
57
+ ACTION: 'action',
58
+ REQUEST: 'request',
59
+ THING: 'thing',
60
+ };
61
+ export const MapEdgeKind = {
62
+ HAS: 'has',
63
+ LEADS_TO: 'leads-to',
64
+ SENDS: 'sends',
65
+ MAKES: 'makes',
66
+ };
67
+ const WRITES = new Set(['POST', 'PUT', 'PATCH']);
68
+ const READS = new Set(['GET', 'HEAD']);
69
+ const APP_INITIATORS = new Set([NetInitiator.FETCH, NetInitiator.XHR]);
70
+ const OK_MIN = 200;
71
+ const OK_MAX = 300;
72
+ const str = (value) => 'string' === typeof value && '' !== value ? value : undefined;
73
+ /** A control's name with its counts taken out: "Open 2" and "Open 3" are one control. */
74
+ const normalName = (name) => name.replace(/\d+/g, '#').trim();
75
+ /** A name this long is a row's data, not a control's label: a row is a thing, never an action. */
76
+ const ROW_NAME_CHARS = 60;
77
+ /**
78
+ * What a person presses or fills. A list's options, a region or a heading is the screen's content: an
79
+ * option without a test id is a row of data (a palette entry, a search result), so it stays out.
80
+ */
81
+ const CONTROL_ROLES = new Set([
82
+ 'button',
83
+ 'link',
84
+ 'textbox',
85
+ 'searchbox',
86
+ 'combobox',
87
+ 'checkbox',
88
+ 'radio',
89
+ 'switch',
90
+ 'tab',
91
+ 'menuitem',
92
+ 'menuitemcheckbox',
93
+ 'menuitemradio',
94
+ 'slider',
95
+ 'spinbutton',
96
+ ]);
97
+ /** A snapshot line's start: `- <role> "`. */
98
+ const LINE_HEAD = /^\s*- (\S+) "/;
99
+ /** What ends a name, before the ref: `" (ref=`. */
100
+ const REF_OPEN = '" (ref=';
101
+ const REF_CLOSE = ')';
102
+ /** Line breaks other than `\n`. A name or a rest that holds one is not read. */
103
+ const LINE_BREAK = /[\r\u2028\u2029]/g;
104
+ /**
105
+ * A snapshot line as role, name and the part after the ref: `- <role> "<name>" (ref=<ref>)<rest>`.
106
+ * The name runs to the LAST `" (ref=` that a non-empty ref and a `)` follow.
107
+ *
108
+ * Read with `indexOf`, not one regular expression. The page writes this text, and a pattern with
109
+ * two open-ended groups backtracks: its time grows with the square of the line length.
110
+ */
111
+ const snapshotLine = (line) => {
112
+ const head = LINE_HEAD.exec(line);
113
+ if (null === head) {
114
+ return undefined;
115
+ }
116
+ const start = head[0].length;
117
+ const breaks = [...line.slice(start).matchAll(LINE_BREAK)].map((m) => start + m.index);
118
+ const firstBreak = breaks[0] ?? line.length;
119
+ const lastBreak = breaks[breaks.length - 1] ?? -1;
120
+ const lastClose = line.lastIndexOf(REF_CLOSE);
121
+ for (let at = line.lastIndexOf(REF_OPEN); start <= at; at = line.lastIndexOf(REF_OPEN, at - 1)) {
122
+ const ref = at + REF_OPEN.length;
123
+ if (ref < lastClose && REF_CLOSE !== line[ref]) {
124
+ const close = line.indexOf(REF_CLOSE, ref);
125
+ // A break may sit only inside the ref: never in the name, never in the rest.
126
+ if (at <= firstBreak && lastBreak < close) {
127
+ return { role: head[1] ?? '', name: line.slice(start, at), rest: line.slice(close + 1) };
128
+ }
129
+ }
130
+ }
131
+ return undefined;
132
+ };
133
+ /** The value of the first `[key=value]` with a non-empty value, read in one pass. */
134
+ const bracketValue = (text, key) => {
135
+ const open = `[${key}=`;
136
+ for (let at = text.indexOf(open); -1 !== at; at = text.indexOf(open, at + 1)) {
137
+ const start = at + open.length;
138
+ const end = text.indexOf(']', start);
139
+ if (-1 === end) {
140
+ return undefined;
141
+ }
142
+ if (start < end) {
143
+ return text.slice(start, end);
144
+ }
145
+ }
146
+ return undefined;
147
+ };
148
+ /** The controls in a snapshot tree; rows (long, data-named, with no test id) left out. */
149
+ export const controlsOf = (tree) => tree.split('\n').flatMap((line) => {
150
+ const parsed = snapshotLine(line);
151
+ if (parsed === undefined) {
152
+ return [];
153
+ }
154
+ const { role, name, rest } = parsed;
155
+ const testid = bracketValue(rest, 'testid');
156
+ const component = bracketValue(rest, 'component');
157
+ if (testid === undefined && !CONTROL_ROLES.has(role)) {
158
+ return [];
159
+ }
160
+ // A data-named row is kept only when its component names it; otherwise it is the row's data.
161
+ if (testid === undefined && component === undefined && name.length > ROW_NAME_CHARS) {
162
+ return [];
163
+ }
164
+ return [
165
+ {
166
+ role,
167
+ name: normalName(name),
168
+ ...(testid === undefined ? {} : { testid }),
169
+ ...(component === undefined ? {} : { component }),
170
+ },
171
+ ];
172
+ });
173
+ /** A seen control's identity on its screen, the same as the act that presses it would have. */
174
+ const controlKey = (c) => {
175
+ if (c.testid !== undefined) {
176
+ return `testid=${c.testid}`;
177
+ }
178
+ if (c.component !== undefined && c.name.length > ROW_NAME_CHARS) {
179
+ return `component=${c.component}`;
180
+ }
181
+ if ('' === c.name) {
182
+ return undefined;
183
+ }
184
+ return `${c.role} "${c.name}"`;
185
+ };
186
+ /** An action's identity on its screen: the anchor a flow would use, never a ref. */
187
+ const anchorKey = (anchor) => {
188
+ const value = str(anchor['value']);
189
+ if ('testid' === anchor['by'] && value !== undefined) {
190
+ return `testid=${value}`;
191
+ }
192
+ const name = str(anchor['name']);
193
+ const component = str(anchor['component']);
194
+ // A row named by its data is one action of its component, as the look that saw it keyed it.
195
+ if (component !== undefined && name !== undefined && name.length > ROW_NAME_CHARS) {
196
+ return `component=${component}`;
197
+ }
198
+ if ('role' === anchor['by'] && value !== undefined && name !== undefined) {
199
+ return `${value} "${normalName(name)}"`;
200
+ }
201
+ return component === undefined ? undefined : `component=${component}`;
202
+ };
203
+ /** What a write to a path made: its last segment that names a kind (`/v1/projects/:id/envs` → envs). */
204
+ const thingOf = (path) => path
205
+ .split('/')
206
+ .filter((segment) => '' !== segment && !segment.startsWith(':') && !/^v\d+$/.test(segment))
207
+ .at(-1);
208
+ /**
209
+ * The type a write's answer names, when it is JSON and says: Stripe's `object`, JSON:API's
210
+ * `data.type`, or GraphQL's `__typename` a few levels down. Every GraphQL write goes to one path, so
211
+ * the path alone would call every thing "graphql"; a REST answer that declares nothing keeps its path.
212
+ */
213
+ const TYPENAME_DEPTH = 4;
214
+ const typenameOf = (body) => {
215
+ if ('string' !== typeof body || '' === body) {
216
+ return undefined;
217
+ }
218
+ let parsed;
219
+ try {
220
+ parsed = JSON.parse(body);
221
+ }
222
+ catch {
223
+ return undefined;
224
+ }
225
+ // REST's own declarations: Stripe's `object`, JSON:API's `data.type`.
226
+ const top = parsed;
227
+ if (null !== top && 'object' === typeof top) {
228
+ if ('string' === typeof top.object && '' !== top.object) {
229
+ return top.object;
230
+ }
231
+ if ('string' === typeof top.data?.type && '' !== top.data.type) {
232
+ return top.data.type;
233
+ }
234
+ }
235
+ if (!body.includes('__typename')) {
236
+ return undefined;
237
+ }
238
+ const walk = (value, depth) => {
239
+ if (depth > TYPENAME_DEPTH || null === value || 'object' !== typeof value) {
240
+ return undefined;
241
+ }
242
+ const own = value['__typename'];
243
+ if ('string' === typeof own && '' !== own) {
244
+ return own;
245
+ }
246
+ for (const child of Object.values(value)) {
247
+ const found = walk(child, depth + 1);
248
+ if (found !== undefined) {
249
+ return found;
250
+ }
251
+ }
252
+ return undefined;
253
+ };
254
+ return walk(parsed, 0);
255
+ };
256
+ /** The map one run recorded. `start` is the route the run was loaded on. */
257
+ export function mapOfRun(steps, events, start, seen = []) {
258
+ const nodes = new Map();
259
+ const edges = new Map();
260
+ const node = (kind, label) => {
261
+ const id = `${kind} ${label}`;
262
+ if (!nodes.has(id)) {
263
+ nodes.set(id, { kind, label });
264
+ }
265
+ return id;
266
+ };
267
+ const edge = (from, to, kind) => {
268
+ edges.set(`${from} ${kind} ${to}`, { from, to, kind });
269
+ };
270
+ const screenOf = (path) => node(MapNodeKind.SCREEN, templatePath(path));
271
+ const routes = events
272
+ .filter((e) => EventType.ROUTE_CHANGE === e.type)
273
+ .map((e) => ({ t: e.t, path: routeOf(e.data) }))
274
+ .filter((r) => r.path !== undefined);
275
+ if (start !== undefined) {
276
+ screenOf(start);
277
+ }
278
+ for (const r of routes) {
279
+ screenOf(r.path);
280
+ }
281
+ // The screen an act was pressed on: the last route before its window opened.
282
+ const on = (since) => {
283
+ const before = routes.filter((r) => r.t < since).at(-1)?.path ?? start;
284
+ return before === undefined ? undefined : templatePath(before);
285
+ };
286
+ // A look records the address; the route change that reached it named the screen. Same screen.
287
+ const named = new Map(events
288
+ .filter((e) => EventType.ROUTE_CHANGE === e.type)
289
+ .flatMap((e) => {
290
+ const at = str(e.data['pathname']);
291
+ const pattern = str(e.data['pattern']);
292
+ return at === undefined || pattern === undefined ? [] : [[at, pattern]];
293
+ }));
294
+ // What each look saw: every control a screen offers, pressed or not.
295
+ for (const look of seen) {
296
+ const screen = templatePath(named.get(look.screen) ?? look.screen);
297
+ const at = node(MapNodeKind.SCREEN, screen);
298
+ for (const control of look.controls) {
299
+ const key = controlKey(control);
300
+ if (key !== undefined) {
301
+ edge(at, node(MapNodeKind.ACTION, `${screen} ${key}`), MapEdgeKind.HAS);
302
+ }
303
+ }
304
+ }
305
+ /**
306
+ * Reads the app sent with nothing pressed (a poll, a badge refresh) are its background: one that
307
+ * lands inside an action's window was not caused by it. Writes are always the action's.
308
+ */
309
+ const pressedWindows = new Set(steps.flatMap((s) => s.window));
310
+ const background = new Set(events
311
+ .filter((e) => EventType.NET_REQUEST === e.type && !pressedWindows.has(e))
312
+ .map((e) => `${(str(e.data['method']) ?? 'GET').toUpperCase()} ${templatePath(str(e.data['url']) ?? '')}`)
313
+ .filter((key) => READS.has(key.split(' ')[0] ?? '')));
314
+ for (const s of steps) {
315
+ const key = anchorKey(s.anchor);
316
+ const screen = on(s.since);
317
+ if (key === undefined || screen === undefined) {
318
+ continue;
319
+ }
320
+ const action = node(MapNodeKind.ACTION, `${screen} ${key}`);
321
+ // Proven if any press of it this run held; refuted only if one failed and none held.
322
+ const seenAs = nodes.get(action);
323
+ if (seenAs !== undefined) {
324
+ seenAs.pressed = true;
325
+ const by = str(s.anchor['by']);
326
+ const value = str(s.anchor['value']);
327
+ const name = str(s.anchor['name']);
328
+ if (by !== undefined && value !== undefined) {
329
+ seenAs.anchor = { by, value, ...(name === undefined ? {} : { name }) };
330
+ }
331
+ }
332
+ if (seenAs !== undefined && s.held !== undefined && true !== seenAs.held) {
333
+ seenAs.held = s.held;
334
+ }
335
+ edge(node(MapNodeKind.SCREEN, screen), action, MapEdgeKind.HAS);
336
+ for (const e of s.window) {
337
+ if (EventType.ROUTE_CHANGE === e.type) {
338
+ const to = routeOf(e.data);
339
+ if (to !== undefined) {
340
+ edge(action, screenOf(to), MapEdgeKind.LEADS_TO);
341
+ }
342
+ continue;
343
+ }
344
+ if (EventType.NET_REQUEST !== e.type) {
345
+ continue;
346
+ }
347
+ const url = str(e.data['url']) ?? '';
348
+ if (isDevToolingUrl(url) || !APP_INITIATORS.has(str(e.data['initiator']) ?? '')) {
349
+ continue;
350
+ }
351
+ const method = (str(e.data['method']) ?? 'GET').toUpperCase();
352
+ const path = templatePath(url);
353
+ if (background.has(`${method} ${path}`)) {
354
+ continue;
355
+ }
356
+ edge(action, node(MapNodeKind.REQUEST, `${method} ${path}`), MapEdgeKind.SENDS);
357
+ const status = 'number' === typeof e.data['status'] ? e.data['status'] : 0;
358
+ const made = typenameOf(e.data['responseBody']) ?? thingOf(path);
359
+ if (WRITES.has(method) && status >= OK_MIN && status < OK_MAX && made !== undefined) {
360
+ edge(action, node(MapNodeKind.THING, made), MapEdgeKind.MAKES);
361
+ }
362
+ }
363
+ }
364
+ return { nodes, edges };
365
+ }
366
+ /** The app's map with one more run folded in: counts add up, nothing a run did not see is lost. */
367
+ export function mergeMap(map, run, runId) {
368
+ const nodes = new Map((map?.nodes ?? []).map((n) => [n.id, { ...n }]));
369
+ for (const [id, { held: verdict, pressed: wasPressed, anchor: pressedBy, ...n }] of run.nodes) {
370
+ const held = nodes.get(id);
371
+ const proven = (held?.proven ?? 0) + (true === verdict ? 1 : 0);
372
+ const refuted = (held?.refuted ?? 0) + (false === verdict ? 1 : 0);
373
+ const pressed = (held?.pressed ?? 0) + (true === wasPressed ? 1 : 0);
374
+ nodes.set(id, {
375
+ id,
376
+ ...n,
377
+ seen: (held?.seen ?? 0) + 1,
378
+ lastRun: runId,
379
+ ...(0 === proven ? {} : { proven }),
380
+ ...(0 === refuted ? {} : { refuted }),
381
+ ...(0 === pressed ? {} : { pressed }),
382
+ // The latest way it was pressed, else the one it was pressed by before.
383
+ ...((a) => (a === undefined ? {} : { anchor: a }))(pressedBy ?? held?.anchor),
384
+ });
385
+ }
386
+ const key = (e) => `${e.from} ${e.kind} ${e.to}`;
387
+ const edges = new Map((map?.edges ?? []).map((e) => [key(e), { ...e }]));
388
+ for (const e of run.edges.values()) {
389
+ const held = edges.get(key(e));
390
+ edges.set(key(e), { ...e, seen: (held?.seen ?? 0) + 1, lastRun: runId });
391
+ }
392
+ const byId = (a, b) => a.id.localeCompare(b.id);
393
+ return {
394
+ nodes: [...nodes.values()].sort(byId),
395
+ edges: [...edges.values()].sort((a, b) => key(a).localeCompare(key(b))),
396
+ };
397
+ }
398
+ /** What the map knows, in one line. */
399
+ export function mapLine(map) {
400
+ const of = (kind) => map.nodes.filter((n) => kind === n.kind);
401
+ const count = (n, one, many) => `${String(n)} ${1 === n ? one : many}`;
402
+ const things = of(MapNodeKind.THING).map((n) => n.label);
403
+ return `The map so far: ${count(of(MapNodeKind.SCREEN).length, 'screen', 'screens')}, ${count(of(MapNodeKind.ACTION).length, 'action', 'actions')}, ${count(of(MapNodeKind.REQUEST).length, 'request', 'requests')}, ${count(things.length, 'thing made', 'things made')}${0 === things.length ? '' : ` (${things.join(', ')})`}.`;
404
+ }
405
+ /** At most this many screens the frontier line names. */
406
+ const FRONTIER_NAMED = 6;
407
+ /**
408
+ * The most important screens first, with how much of each is proven: where the next run should go.
409
+ * Importance is read off the graph, never guessed: the actions that lead to a screen, and, twice over,
410
+ * the kinds of thing its actions make (the work people come to do).
411
+ */
412
+ export function frontierLine(map) {
413
+ const plural = (n, one) => `${String(n)} ${one}${1 === n ? '' : 's'}`;
414
+ const screens = map.nodes
415
+ .filter((n) => MapNodeKind.SCREEN === n.kind)
416
+ .map((screen) => {
417
+ const actions = map.edges
418
+ .filter((e) => MapEdgeKind.HAS === e.kind && screen.id === e.from)
419
+ .map((e) => e.to);
420
+ const inbound = new Set(map.edges
421
+ .filter((e) => MapEdgeKind.LEADS_TO === e.kind && screen.id === e.to)
422
+ .map((e) => e.from)).size;
423
+ const makes = [
424
+ ...new Set(map.edges
425
+ .filter((e) => MapEdgeKind.MAKES === e.kind && actions.includes(e.from))
426
+ .map((e) => e.to.replace(`${MapNodeKind.THING} `, ''))),
427
+ ];
428
+ const count = (field) => actions.filter((id) => 0 < (map.nodes.find((n) => id === n.id)?.[field] ?? 0)).length;
429
+ const tried = count('pressed');
430
+ const facts = [
431
+ ...(0 === actions.length
432
+ ? []
433
+ : [
434
+ `${String(tried)} of ${plural(actions.length, 'action')} tried, ${String(count('proven'))} proven`,
435
+ ]),
436
+ ...(0 === inbound ? [] : [`reached from ${plural(inbound, 'action')}`]),
437
+ ...(0 === makes.length ? [] : [`makes ${makes.join(', ')}`]),
438
+ ];
439
+ return {
440
+ label: screen.label,
441
+ score: inbound + 2 * makes.length,
442
+ untried: actions.length - tried,
443
+ facts,
444
+ };
445
+ })
446
+ .filter((s) => 0 < s.facts.length)
447
+ // The most important first; among equals, the one with the most left to try (the frontier rule).
448
+ .sort((a, b) => b.score - a.score || b.untried - a.untried)
449
+ .slice(0, FRONTIER_NAMED);
450
+ return 0 === screens.length
451
+ ? ''
452
+ : `Most important first: ${screens.map((s) => `${s.label} (${s.facts.join(', ')})`).join(', ')}.`;
453
+ }
454
+ /**
455
+ * The actions to press to get from one screen to another, by the map's pressed edges: the shortest
456
+ * way, each by the anchor it was pressed with. Empty when already there; undefined when the map knows
457
+ * no way (a run then reaches it some other way, or a replay starts where it is).
458
+ */
459
+ export function pathTo(map, from, to) {
460
+ const start = `${MapNodeKind.SCREEN} ${templatePath(from)}`;
461
+ const goal = `${MapNodeKind.SCREEN} ${templatePath(to)}`;
462
+ if (start === goal) {
463
+ return [];
464
+ }
465
+ const anchors = new Map(map.nodes.flatMap((n) => (n.anchor === undefined ? [] : [[n.id, n.anchor]])));
466
+ // screen -> (action, next screen), only through actions that can be pressed again.
467
+ const next = new Map();
468
+ for (const has of map.edges.filter((e) => MapEdgeKind.HAS === e.kind && anchors.has(e.to))) {
469
+ for (const lead of map.edges.filter((e) => MapEdgeKind.LEADS_TO === e.kind && has.to === e.from)) {
470
+ next.set(has.from, [...(next.get(has.from) ?? []), { action: has.to, to: lead.to }]);
471
+ }
472
+ }
473
+ const via = new Map();
474
+ const queue = [start];
475
+ for (let at = queue.shift(); at !== undefined; at = queue.shift()) {
476
+ for (const step of next.get(at) ?? []) {
477
+ if (step.to === start || via.has(step.to)) {
478
+ continue;
479
+ }
480
+ via.set(step.to, { from: at, action: step.action });
481
+ if (step.to === goal) {
482
+ const path = [];
483
+ for (let back = via.get(goal); back !== undefined; back = via.get(back.from)) {
484
+ const anchor = anchors.get(back.action);
485
+ if (anchor !== undefined) {
486
+ path.unshift(anchor);
487
+ }
488
+ if (back.from === start) {
489
+ break;
490
+ }
491
+ }
492
+ return path;
493
+ }
494
+ queue.push(step.to);
495
+ }
496
+ }
497
+ return undefined;
498
+ }
@@ -66,8 +66,8 @@ export declare const VerdictHookPayloadSchema: z.ZodObject<{
66
66
  sessionId: z.ZodOptional<z.ZodString>;
67
67
  url: z.ZodOptional<z.ZodString>;
68
68
  }, "strip", z.ZodTypeAny, {
69
- event: "verdict";
70
69
  at: string;
70
+ event: "verdict";
71
71
  verified: string;
72
72
  tool: string;
73
73
  url?: string | undefined;
@@ -75,8 +75,8 @@ export declare const VerdictHookPayloadSchema: z.ZodObject<{
75
75
  sessionId?: string | undefined;
76
76
  because?: string | undefined;
77
77
  }, {
78
- event: "verdict";
79
78
  at: string;
79
+ event: "verdict";
80
80
  verified: string;
81
81
  tool: string;
82
82
  url?: string | undefined;
@@ -98,22 +98,22 @@ export declare const BugFoundHookPayloadSchema: z.ZodObject<{
98
98
  tool: z.ZodString;
99
99
  sessionId: z.ZodOptional<z.ZodString>;
100
100
  }, "strip", z.ZodTypeAny, {
101
+ repeat: boolean;
102
+ at: string;
101
103
  kind: string;
102
104
  event: "bug_found";
103
- at: string;
104
105
  tool: string;
105
- repeat: boolean;
106
106
  route?: string | undefined;
107
107
  source?: string | undefined;
108
108
  projectId?: string | undefined;
109
109
  sessionId?: string | undefined;
110
110
  fingerprint?: string | undefined;
111
111
  }, {
112
+ repeat: boolean;
113
+ at: string;
112
114
  kind: string;
113
115
  event: "bug_found";
114
- at: string;
115
116
  tool: string;
116
- repeat: boolean;
117
117
  route?: string | undefined;
118
118
  source?: string | undefined;
119
119
  projectId?: string | undefined;
@@ -130,15 +130,15 @@ export declare const SessionHookPayloadSchema: z.ZodObject<{
130
130
  url: z.ZodOptional<z.ZodString>;
131
131
  runtime: z.ZodOptional<z.ZodString>;
132
132
  }, "strip", z.ZodTypeAny, {
133
- event: "session_started" | "session_ended";
134
133
  at: string;
134
+ event: "session_started" | "session_ended";
135
135
  sessionId: string;
136
136
  url?: string | undefined;
137
137
  projectId?: string | undefined;
138
138
  runtime?: string | undefined;
139
139
  }, {
140
- event: "session_started" | "session_ended";
141
140
  at: string;
141
+ event: "session_started" | "session_ended";
142
142
  sessionId: string;
143
143
  url?: string | undefined;
144
144
  projectId?: string | undefined;
@@ -154,16 +154,16 @@ export declare const SyncHookPayloadSchema: z.ZodObject<{
154
154
  ok: z.ZodBoolean;
155
155
  error: z.ZodOptional<z.ZodString>;
156
156
  }, "strip", z.ZodTypeAny, {
157
+ at: string;
157
158
  ok: boolean;
158
159
  event: "sync_completed";
159
- at: string;
160
160
  runsPushed: number;
161
161
  error?: string | undefined;
162
162
  projectId?: string | undefined;
163
163
  }, {
164
+ at: string;
164
165
  ok: boolean;
165
166
  event: "sync_completed";
166
- at: string;
167
167
  runsPushed: number;
168
168
  error?: string | undefined;
169
169
  projectId?: string | undefined;
@@ -181,8 +181,8 @@ export declare const HookPayloadSchema: z.ZodDiscriminatedUnion<"event", [z.ZodO
181
181
  sessionId: z.ZodOptional<z.ZodString>;
182
182
  url: z.ZodOptional<z.ZodString>;
183
183
  }, "strip", z.ZodTypeAny, {
184
- event: "verdict";
185
184
  at: string;
185
+ event: "verdict";
186
186
  verified: string;
187
187
  tool: string;
188
188
  url?: string | undefined;
@@ -190,8 +190,8 @@ export declare const HookPayloadSchema: z.ZodDiscriminatedUnion<"event", [z.ZodO
190
190
  sessionId?: string | undefined;
191
191
  because?: string | undefined;
192
192
  }, {
193
- event: "verdict";
194
193
  at: string;
194
+ event: "verdict";
195
195
  verified: string;
196
196
  tool: string;
197
197
  url?: string | undefined;
@@ -211,22 +211,22 @@ export declare const HookPayloadSchema: z.ZodDiscriminatedUnion<"event", [z.ZodO
211
211
  tool: z.ZodString;
212
212
  sessionId: z.ZodOptional<z.ZodString>;
213
213
  }, "strip", z.ZodTypeAny, {
214
+ repeat: boolean;
215
+ at: string;
214
216
  kind: string;
215
217
  event: "bug_found";
216
- at: string;
217
218
  tool: string;
218
- repeat: boolean;
219
219
  route?: string | undefined;
220
220
  source?: string | undefined;
221
221
  projectId?: string | undefined;
222
222
  sessionId?: string | undefined;
223
223
  fingerprint?: string | undefined;
224
224
  }, {
225
+ repeat: boolean;
226
+ at: string;
225
227
  kind: string;
226
228
  event: "bug_found";
227
- at: string;
228
229
  tool: string;
229
- repeat: boolean;
230
230
  route?: string | undefined;
231
231
  source?: string | undefined;
232
232
  projectId?: string | undefined;
@@ -241,15 +241,15 @@ export declare const HookPayloadSchema: z.ZodDiscriminatedUnion<"event", [z.ZodO
241
241
  } & {
242
242
  event: z.ZodLiteral<"session_started">;
243
243
  }, "strip", z.ZodTypeAny, {
244
- event: "session_started";
245
244
  at: string;
245
+ event: "session_started";
246
246
  sessionId: string;
247
247
  url?: string | undefined;
248
248
  projectId?: string | undefined;
249
249
  runtime?: string | undefined;
250
250
  }, {
251
- event: "session_started";
252
251
  at: string;
252
+ event: "session_started";
253
253
  sessionId: string;
254
254
  url?: string | undefined;
255
255
  projectId?: string | undefined;
@@ -263,15 +263,15 @@ export declare const HookPayloadSchema: z.ZodDiscriminatedUnion<"event", [z.ZodO
263
263
  } & {
264
264
  event: z.ZodLiteral<"session_ended">;
265
265
  }, "strip", z.ZodTypeAny, {
266
- event: "session_ended";
267
266
  at: string;
267
+ event: "session_ended";
268
268
  sessionId: string;
269
269
  url?: string | undefined;
270
270
  projectId?: string | undefined;
271
271
  runtime?: string | undefined;
272
272
  }, {
273
- event: "session_ended";
274
273
  at: string;
274
+ event: "session_ended";
275
275
  sessionId: string;
276
276
  url?: string | undefined;
277
277
  projectId?: string | undefined;
@@ -285,16 +285,16 @@ export declare const HookPayloadSchema: z.ZodDiscriminatedUnion<"event", [z.ZodO
285
285
  ok: z.ZodBoolean;
286
286
  error: z.ZodOptional<z.ZodString>;
287
287
  }, "strip", z.ZodTypeAny, {
288
+ at: string;
288
289
  ok: boolean;
289
290
  event: "sync_completed";
290
- at: string;
291
291
  runsPushed: number;
292
292
  error?: string | undefined;
293
293
  projectId?: string | undefined;
294
294
  }, {
295
+ at: string;
295
296
  ok: boolean;
296
297
  event: "sync_completed";
297
- at: string;
298
298
  runsPushed: number;
299
299
  error?: string | undefined;
300
300
  projectId?: string | undefined;
package/dist/hud-entry.js CHANGED
@@ -9,5 +9,5 @@
9
9
  export * from './wire/constants/hud-controls.js';
10
10
  // The rail's notices: read by the daemon that chooses them and the lazy panel that renders them.
11
11
  export * from './artifacts/hud-notices.js';
12
- // Harness credits: the HUD's row says what the daemon's refusal says.
12
+ // Credits: the HUD's row says what the daemon's refusal says.
13
13
  export * from './artifacts/harness-credits.js';