@reticlehq/core 2.4.0 → 2.6.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 (46) hide show
  1. package/dist/consequence.d.ts +27 -0
  2. package/dist/consequence.js +26 -0
  3. package/dist/constants.d.ts +68 -0
  4. package/dist/constants.js +65 -0
  5. package/dist/contract-fingerprint.d.ts +29 -0
  6. package/dist/contract-fingerprint.js +56 -0
  7. package/dist/daemon-registry.js +1 -1
  8. package/dist/event-classification.d.ts +7 -0
  9. package/dist/event-classification.js +15 -0
  10. package/dist/event-payloads.d.ts +48 -0
  11. package/dist/event-payloads.js +12 -1
  12. package/dist/flow-constants.d.ts +8 -0
  13. package/dist/flow-constants.js +12 -0
  14. package/dist/flow-types.d.ts +23 -0
  15. package/dist/index.d.ts +3 -0
  16. package/dist/index.js +3 -0
  17. package/dist/journal.d.ts +2 -2
  18. package/dist/messages.d.ts +48 -0
  19. package/dist/messages.js +20 -0
  20. package/dist/net.d.ts +40 -0
  21. package/dist/net.js +44 -0
  22. package/dist/project-id.d.ts +28 -0
  23. package/dist/project-id.js +51 -0
  24. package/dist/redaction.js +4 -4
  25. package/dist/schema/hello-message.json +8 -0
  26. package/dist/schema/reticle-message.json +8 -0
  27. package/dist/security.js +10 -5
  28. package/dist/source-constants.d.ts +6 -0
  29. package/dist/source-constants.js +6 -0
  30. package/dist/state-select.d.ts +14 -2
  31. package/dist/state-select.js +77 -14
  32. package/dist/telemetry-feedback.d.ts +32 -10
  33. package/dist/telemetry-feedback.js +21 -0
  34. package/dist/telemetry-session.d.ts +169 -0
  35. package/dist/telemetry-session.js +139 -0
  36. package/dist/telemetry.d.ts +706 -92
  37. package/dist/telemetry.js +251 -4
  38. package/dist/toon.d.ts +2 -1
  39. package/dist/toon.js +37 -37
  40. package/dist/types.d.ts +48 -0
  41. package/dist/types.js +12 -0
  42. package/dist/upgrade.js +1 -1
  43. package/dist/verification-run.d.ts +28 -28
  44. package/dist/verified-constants.d.ts +53 -0
  45. package/dist/verified-constants.js +52 -0
  46. package/package.json +5 -3
package/dist/telemetry.js CHANGED
@@ -17,7 +17,8 @@
17
17
  */
18
18
  import { z } from 'zod';
19
19
  import { MachineSnapshotSchema, ProjectProfileSchema, SessionSummarySchema, } from './telemetry-session.js';
20
- import { FeedbackSchema } from './telemetry-feedback.js';
20
+ import { BrowserBrand, FeedbackSchema } from './telemetry-feedback.js';
21
+ import { VerifiedReason } from './verified-constants.js';
21
22
  import { IdentitySchema } from './telemetry-feedback.js';
22
23
  /** Bump when the event shape changes so the analytics side can segment old senders. */
23
24
  export const TELEMETRY_EVENT_VERSION = 3;
@@ -55,6 +56,20 @@ export const TelemetryEventKind = {
55
56
  * errors, features touched). One event replaces the hundreds the old per-call `tool` event sent.
56
57
  */
57
58
  DAEMON_STOPPED: 'daemon_stopped',
59
+ /**
60
+ * A PERIODIC roll-up from a daemon that is still running — same payload shape as DAEMON_STOPPED,
61
+ * `final: false`.
62
+ *
63
+ * It used to be emitted AS `daemon_stopped`, which made an event named for an exit fire while the
64
+ * process was alive. Measured over one day: 98 `daemon_stopped` events were 73 real exits plus 25
65
+ * flushes, so anything counting sessions over-stated by 34% — and worse, the two populations are
66
+ * opposites. Every one of the 25 flushes had tool calls; not one of the 73 exits did (a daemon that
67
+ * served a tool never idle-exits, so only the idle ones ever reach a clean shutdown). A funnel over
68
+ * the raw event therefore describes active sessions at one end and abandoned ones at the other.
69
+ *
70
+ * Count sessions with DAEMON_STOPPED. Sum work with both.
71
+ */
72
+ SESSION_PROGRESS: 'session_progress',
58
73
  /**
59
74
  * A verification produced a verdict. The product's reason to exist, and the one metric an investor
60
75
  * should be shown: not "tools were called" but "an app was actually verified, and here is how often
@@ -93,6 +108,23 @@ export const TelemetryEventKind = {
93
108
  * identical to healthy usage in every other metric.
94
109
  */
95
110
  MCP_CLIENT_CONNECTED: 'mcp_client_connected',
111
+ /**
112
+ * The agent LOST its Reticle tools — the worst thing this product does to anyone, and until now
113
+ * completely invisible in the field.
114
+ *
115
+ * `mcp_client_connected` shows reconnect churn only from the daemon's side, and the proxy's own
116
+ * account of an outage went to a local file nobody sends us. So "how often does a real user's MCP
117
+ * server go down, and does it come back" — the single question the transport has to answer — could
118
+ * not be asked of any dashboard.
119
+ *
120
+ * Deliberately capped at TWO per proxy process: once on the first outage of a session, and once if
121
+ * the retry budget is spent (the severe case, where it stopped retrying and went dormant). The
122
+ * per-call `tool` event was already removed here for cost, and one measured afternoon produced 547
123
+ * proxy reconnects — an event per reconnect would bill for the pathology instead of measuring it.
124
+ * The first-outage event answers "what share of sessions lose MCP at all", which is the number
125
+ * that decides whether this is fixed.
126
+ */
127
+ MCP_CONNECTION_LOST: 'mcp_connection_lost',
96
128
  /**
97
129
  * `reticle init` finished. The onboarding funnel had no instrumentation at all, so a setup that
98
130
  * failed on a missing dependency was indistinguishable from a user who never tried.
@@ -112,6 +144,32 @@ export const TelemetryEventKind = {
112
144
  */
113
145
  BUG_FOUND: 'bug_found',
114
146
  };
147
+ /**
148
+ * Events that belong to a DAEMON RUN, and therefore carry `sessionId`.
149
+ *
150
+ * `sessionId` is minted per process, which is right for a daemon (a daemon run IS the session) and
151
+ * wrong for a one-shot CLI command, which invents one that joins to nothing. Measured over a real
152
+ * day: uniq(sessionId) was 704, of which 561 came from `cli_command_run` and NOT ONE was shared with
153
+ * a daemon. The real number of daemon runs was 121, so every tile counting sessions was ~6x high.
154
+ *
155
+ * Omitting the id on the one-shot events costs nothing — no join on those ids could ever have
156
+ * succeeded — and makes `uniq(sessionId)` mean the thing every dashboard already assumes it means.
157
+ */
158
+ const SESSION_SCOPED = new Set([
159
+ TelemetryEventKind.DAEMON_STARTED,
160
+ TelemetryEventKind.DAEMON_STOPPED,
161
+ TelemetryEventKind.SESSION_PROGRESS,
162
+ TelemetryEventKind.MCP_CLIENT_CONNECTED,
163
+ TelemetryEventKind.PROJECT_PROFILED,
164
+ TelemetryEventKind.VERIFICATION_COMPLETED,
165
+ TelemetryEventKind.BUG_FOUND,
166
+ TelemetryEventKind.RUNTIME_CRASHED,
167
+ TelemetryEventKind.FEEDBACK_SUBMITTED,
168
+ ]);
169
+ /** True when this event happened inside a daemon run, so a `sessionId` on it means something. */
170
+ export function isSessionScoped(kind) {
171
+ return SESSION_SCOPED.has(kind);
172
+ }
115
173
  /**
116
174
  * Who caused this. The only honest split available to us: a `reticle` command was TYPED by a person,
117
175
  * while an MCP tool call came from the agent's own loop.
@@ -128,14 +186,24 @@ export const TelemetryActor = {
128
186
  * What `projectId` was derived from — and therefore whether it is comparable ACROSS machines.
129
187
  *
130
188
  * This is the field that keeps "how many users share this project" from silently lying. A
131
- * cwd-derived id is unique per machine, so those rows always show exactly one user per project. Left
189
+ * path-derived id is unique per machine, so those rows always show exactly one user per project. Left
132
190
  * unlabelled they would drag the average toward 1 and hide real team adoption; labelled, the
133
191
  * analytics can restrict that question to `git_origin` rows, where it is a real measurement.
192
+ *
193
+ * The three non-origin sources are ordered by how stable they are WITHIN one machine, which is the
194
+ * property the funnel actually needs: `init` runs in the app directory and the daemon is spawned from
195
+ * wherever the agent's client happens to sit, so an id that changes with the working directory
196
+ * severs the two halves of the funnel. Only `cwd` has that defect, and it is now the last resort
197
+ * rather than the first fallback — measured 2026-08-11 at 1131 ids for 243 users.
134
198
  */
135
199
  export const ProjectIdSource = {
136
200
  /** Hash of the shared git origin — the same on every clone, so cross-machine counting is valid. */
137
201
  GIT_ORIGIN: 'git_origin',
138
- /** Hash of the local directory path — unique per machine; NOT comparable across users. */
202
+ /** Hash of the repo ROOT path — machine-local, but the same for every directory inside the repo. */
203
+ GIT_ROOT: 'git_root',
204
+ /** Hash of the nearest package.json's directory — machine-local; used when there is no git at all. */
205
+ PACKAGE_ROOT: 'package_root',
206
+ /** Hash of the raw working directory — the last resort, and the only source that is NOT stable. */
139
207
  CWD: 'cwd',
140
208
  };
141
209
  /**
@@ -165,11 +233,54 @@ export const VerificationSchema = z.object({
165
233
  */
166
234
  falseGreenCaught: z.boolean(),
167
235
  durationMs: z.number().int().nonnegative().optional(),
236
+ /**
237
+ * `headless` | `headed` | `attached` — how the browser under verification got there.
238
+ *
239
+ * Without it, "verifications run" is one undifferentiated number covering three different
240
+ * products: unattended CI, a human watching an agent work, and the SDK in somebody's own dev
241
+ * server. They have different costs, different failure modes and different value, and only the
242
+ * last one is what most installs actually do.
243
+ */
244
+ browser: z.string().min(1).max(16).optional(),
245
+ /**
246
+ * WHICH browser it was — `chrome` | `edge` | `arc` | `dia` | `brave` | `opera` | `firefox` |
247
+ * `safari` | `other`, from `BrowserBrand`.
248
+ *
249
+ * `browser` above says who drove it, and its most common value by far is `attached`: the SDK
250
+ * connected from a browser Reticle never launched. That leaves the actual browser unknown, and
251
+ * the engine cannot fill the gap — Chrome, Edge, Arc, Dia and Brave are one `blink`.
252
+ *
253
+ * OPTIONAL and absent rather than `"unknown"` when the page did not say: a desktop webview has no
254
+ * brand, and an older SDK does not report one. A guessed value would be indistinguishable from a
255
+ * measured one on a dashboard.
256
+ */
257
+ brand: z.nativeEnum(BrowserBrand).optional(),
258
+ /**
259
+ * WHICH clause of the honesty rule decided this — see `VerifiedReason`.
260
+ *
261
+ * `verified` alone cannot answer the question the product is judged on. `unknown` + `passed:false`
262
+ * was measured covering "Reticle caught a real bug", "the agent wrote a bad predicate" and
263
+ * "Reticle itself could not see", which need opposite responses and arrive as one value; `no`
264
+ * collapses "channels disagree" into "the agent's predicate failed" the same way.
265
+ *
266
+ * OPTIONAL because not every verdict comes from `decideVerified` — a suite reports pass/fail with
267
+ * no clause behind it, and an older SDK reports none. Absent means unclassified, never guessed.
268
+ */
269
+ reason: z.nativeEnum(VerifiedReason).optional(),
168
270
  });
169
271
  /** Which way the installed version moved, and between which versions. */
170
272
  export const VersionChangeSchema = z.object({
171
273
  from: z.string().min(1).max(64),
172
274
  to: z.string().min(1).max(64),
275
+ /**
276
+ * True when an agent had been told about exactly this version recently — so the nudge plausibly
277
+ * caused the update.
278
+ *
279
+ * Without it, `version_changed` says a version moved and never why, which leaves "the nudge never
280
+ * fired" and "the nudge fired and nobody acted" indistinguishable. Those need opposite responses,
281
+ * and the whole adoption story rests on knowing which one is happening.
282
+ */
283
+ nudged: z.boolean().optional(),
173
284
  /** `update` (forward) or `rollback` (back) — a rollback is a release-quality alarm. */
174
285
  direction: z.string().min(1).max(16),
175
286
  });
@@ -182,6 +293,17 @@ export const VersionChangeSchema = z.object({
182
293
  * give the hash a meaning, while keeping the line that matters: our code and our failure, never the
183
294
  * user's code and never their data.
184
295
  */
296
+ /**
297
+ * Whether a failed connection was aimed at a port Reticle itself uses.
298
+ *
299
+ * An enum rather than the number, because the number is the reporter's and the answer is ours: all
300
+ * anyone needs to know is whose problem it is. Refused on a Reticle port is a lifecycle problem —
301
+ * a daemon that is not up; refused anywhere else is somebody else's service.
302
+ */
303
+ export const CrashPort = {
304
+ RETICLE: 'reticle',
305
+ OTHER: 'other',
306
+ };
185
307
  export const CrashSchema = z.object({
186
308
  /** `uncaught_exception` | `unhandled_rejection`. */
187
309
  kind: z.string().min(1).max(32),
@@ -224,6 +346,34 @@ export const CrashSchema = z.object({
224
346
  * trace and are completely different problems; this is what tells them apart.
225
347
  */
226
348
  machine: MachineSnapshotSchema.optional(),
349
+ /**
350
+ * The failing SYSCALL — `connect`, `write`, `open`. Already inside `message`; structured here so
351
+ * it can be grouped on rather than parsed back out of prose.
352
+ */
353
+ syscall: z.string().max(32).optional(),
354
+ /**
355
+ * The symbolic errno — `ECONNREFUSED`, `EPIPE`. The name, never the platform-specific number.
356
+ */
357
+ errno: z.string().max(32).optional(),
358
+ /**
359
+ * Was the target the machine it was running on?
360
+ *
361
+ * One bit, and it splits two populations that currently look identical and have different owners:
362
+ * refused ON loopback is a Reticle-lifecycle problem (no daemon), refused off-box is a network
363
+ * problem that is not ours.
364
+ */
365
+ loopback: z.boolean().optional(),
366
+ /** Whether the port was one of ours, as an enum. The number itself is never sent. */
367
+ port: z.enum([CrashPort.RETICLE, CrashPort.OTHER]).optional(),
368
+ /**
369
+ * The innermost frame naming NODE's own source — `node:net:1637`.
370
+ *
371
+ * Only present when the crash is a system error AND no Reticle frame survived, which is exactly
372
+ * the report that otherwise arrives with no location at all. It is a line in Node's published
373
+ * source: it says a connect failed rather than a DNS lookup, and carries nothing about the
374
+ * machine, the app, or anyone's directory layout.
375
+ */
376
+ internalFrame: z.string().max(64).optional(),
227
377
  });
228
378
  /**
229
379
  * How Reticle came to find a defect. Four routes, in descending order of "a human would have missed
@@ -241,6 +391,28 @@ export const BugSource = {
241
391
  /** An assertion the agent declared did not hold. */
242
392
  ASSERTION: 'assertion',
243
393
  };
394
+ /**
395
+ * WHOSE fault the defect was.
396
+ *
397
+ * `bugsFound` is the number this product would most like to publish, and it is not publishable
398
+ * without this. Measured over one real session: 8 `bug_found` events, of which **one** was a defect
399
+ * in the app under test. The other seven were the agent's own bad predicates (a store path that
400
+ * never existed, an impossible selector) and one empty ref, all published as defects in the
401
+ * customer's product. A founder steering on that number is steering on noise.
402
+ *
403
+ * Deliberately OMITTED rather than guessed when the evidence does not say. A failed `element.present`
404
+ * covers "the button is missing", "the API is down" and "the agent mistyped a testid" identically,
405
+ * and inventing an owner for it would put a guess into the one number we intend to publish — the
406
+ * same mistake `brand` refuses to make by being absent rather than `"unknown"`.
407
+ */
408
+ export const BugAttribution = {
409
+ /** A defect in the app under test — the only bucket that belongs in a published defect count. */
410
+ APP: 'app',
411
+ /** The agent's own call was wrong: a path, store or target that never existed. Teach the agent. */
412
+ REQUEST: 'request',
413
+ /** Reticle could not see or could not drive. Our bug, or our configuration. Ship a fix. */
414
+ RETICLE: 'reticle',
415
+ };
244
416
  /**
245
417
  * One defect Reticle found in the app under test.
246
418
  *
@@ -283,6 +455,11 @@ export const BugFoundSchema = z.object({
283
455
  * as one — and must not be, since that would need data this event refuses to collect.
284
456
  */
285
457
  repeat: z.boolean(),
458
+ /**
459
+ * Whose fault it was — `app` | `request` | `reticle`. ABSENT when the evidence cannot say; see
460
+ * `BugAttribution`. Count `attribution: 'app'` for defects found in anybody's product.
461
+ */
462
+ attribution: z.nativeEnum(BugAttribution).optional(),
286
463
  });
287
464
  /** An MCP client attaching. Separates "installed and running" from "someone is actually using it". */
288
465
  export const McpConnectionSchema = z.object({
@@ -297,6 +474,61 @@ export const McpConnectionSchema = z.object({
297
474
  /** Which client, from its own handshake (`claude-code`, `cursor`). */
298
475
  client: z.string().min(1).max(64).optional(),
299
476
  });
477
+ /**
478
+ * WHICH stage of an MCP outage this is. Reported at most twice per proxy process, and the two are
479
+ * different facts: `first` says the session lost its tools at all, `budget_spent` says the proxy
480
+ * stopped retrying and never came back on its own.
481
+ */
482
+ export const OutageStage = {
483
+ FIRST: 'first',
484
+ BUDGET_SPENT: 'budget_spent',
485
+ };
486
+ /**
487
+ * WHY the stream went away, as far as the proxy can tell. A closed vocabulary because the proxy's
488
+ * own reason strings are free text feeding a log — `OTHER` is the bucket that lets a new one arrive
489
+ * without a raw string reaching the wire, per the classifier rule.
490
+ */
491
+ export const OutageReason = {
492
+ /** The SSE stream ended cleanly — usually the daemon exiting. */
493
+ SSE_ENDED: 'sse_ended',
494
+ /** The stream errored. */
495
+ SSE_ERROR: 'sse_error',
496
+ /** The socket died under us with neither `end` nor `error` — daemon killed, network reset. */
497
+ SSE_ABORTED: 'sse_aborted',
498
+ /** The response closed. */
499
+ SSE_CLOSED: 'sse_closed',
500
+ /** A reconnect attempt could not reach the daemon at all. */
501
+ CONNECT_ERROR: 'connect_error',
502
+ /** Anything the proxy reported that this list does not name. A classifier must be able to say so. */
503
+ OTHER: 'other',
504
+ };
505
+ /**
506
+ * The agent LOST its Reticle tools.
507
+ *
508
+ * This block existed on the emitter's input type and never on the wire: `emit()` builds its event
509
+ * from an explicit allow-list of keys and `outage` was not in it, so two deliberately different
510
+ * outages — `first`/`sse_ended`/3 and `budget_spent`/`connect_error`/12 — produced byte-identical
511
+ * events. Against a standing "MCP must never go down" mandate, the metric that measures it reported
512
+ * a bare count with no cause and no recovery signal. This is the schema half of the fix.
513
+ */
514
+ export const McpOutageSchema = z.object({
515
+ stage: z.nativeEnum(OutageStage),
516
+ reason: z.nativeEnum(OutageReason),
517
+ /** Consecutive reconnects tried when this was reported. `first` is near 1; a spent budget is high. */
518
+ attempts: z.number().int().nonnegative(),
519
+ /**
520
+ * In-flight tool calls this drop actually killed — the only part an agent can FEEL.
521
+ *
522
+ * Without it every drop looks equally bad. Measured 2026-08-10/11: **320 of 321 outages were
523
+ * `stage: first` with `attempts: 1`** — the stream ended once and the proxy reconnected, which for
524
+ * an agent with nothing in flight is invisible. Reading that 321 as "the agent lost its tools 321
525
+ * times" overstates the problem by roughly the whole number, and buries the one drop that mattered.
526
+ *
527
+ * Zero means nobody noticed. Non-zero is the number of calls that came back `-32001` and the count
528
+ * worth driving down.
529
+ */
530
+ pendingLost: z.number().int().nonnegative().optional(),
531
+ });
300
532
  /** How `reticle init` went. The onboarding funnel, which had no instrumentation whatsoever. */
301
533
  export const InitOutcomeSchema = z.object({
302
534
  ok: z.boolean(),
@@ -326,7 +558,12 @@ export const TelemetryEventSchema = z.object({
326
558
  * explicitly supports) interleaved into one undifferentiated stream, and no per-session funnel could
327
559
  * be built at all. It cannot be backfilled, which is why it is worth adding before the data matters.
328
560
  */
329
- sessionId: z.string().min(1).max(64),
561
+ /**
562
+ * The daemon run this happened inside. ABSENT on one-shot CLI events — see isSessionScoped: a
563
+ * per-process id on `reticle status` is not a session, it is a number that inflates every session
564
+ * count and joins to nothing.
565
+ */
566
+ sessionId: z.string().min(1).max(64).optional(),
330
567
  event: z.nativeEnum(TelemetryEventKind),
331
568
  /** Client epoch-ms when the event happened (the server also stamps its own receive time). */
332
569
  ts: z.number().int().nonnegative(),
@@ -342,6 +579,14 @@ export const TelemetryEventSchema = z.object({
342
579
  projectIdSource: z.nativeEnum(ProjectIdSource).optional(),
343
580
  /** `process.platform` (darwin/linux/win32) — OS mix, low cardinality, non-identifying. */
344
581
  os: z.string().min(1).max(32),
582
+ /**
583
+ * Minutes this machine's local time is offset from UTC.
584
+ *
585
+ * "When do they work" was answerable only through ingest-side GeoIP, which may be off and is a
586
+ * coarser thing than a working day. One integer, no location, identifies nobody — and it turns
587
+ * every time-of-day tile from "which continent" into "9am or 11pm".
588
+ */
589
+ tzOffsetMin: z.number().int().min(-900).max(900).optional(),
345
590
  /** Only on `feedback`: the author-submitted report + its environment context. Never sent otherwise. */
346
591
  feedback: FeedbackSchema.optional(),
347
592
  /** Human or agent. Absent on events that are neither (a crash, a version change). */
@@ -372,4 +617,6 @@ export const TelemetryEventSchema = z.object({
372
617
  init: InitOutcomeSchema.optional(),
373
618
  /** Only on `bug_found`. */
374
619
  bug: BugFoundSchema.optional(),
620
+ /** Only on `mcp_connection_lost`: which stage of the outage, why, and after how many retries. */
621
+ outage: McpOutageSchema.optional(),
375
622
  });
package/dist/toon.d.ts CHANGED
@@ -17,7 +17,8 @@
17
17
  *
18
18
  * State flags (inside []):
19
19
  * vis visible hid hidden en enabled dis disabled
20
- * chk checked uch unchecked exp expanded col collapsed focus
20
+ * chk checked exp expanded focus focused
21
+ * (`present` is on every element, so it is never encoded — see STATE_FLAG.)
21
22
  *
22
23
  * Attributes (key=value, space-separated):
23
24
  * val="..." current value of the element
package/dist/toon.js CHANGED
@@ -17,13 +17,15 @@
17
17
  *
18
18
  * State flags (inside []):
19
19
  * vis visible hid hidden en enabled dis disabled
20
- * chk checked uch unchecked exp expanded col collapsed focus
20
+ * chk checked exp expanded focus focused
21
+ * (`present` is on every element, so it is never encoded — see STATE_FLAG.)
21
22
  *
22
23
  * Attributes (key=value, space-separated):
23
24
  * val="..." current value of the element
24
25
  * count=N child count (for containers, replaces expanding children)
25
26
  * ph="..." placeholder text
26
27
  */
28
+ import { ElementState } from './constants.js';
27
29
  const ROLE_MAP = {
28
30
  button: 'btn',
29
31
  textbox: 'inp',
@@ -65,51 +67,49 @@ const ROLE_MAP = {
65
67
  function abbreviateRole(role) {
66
68
  return ROLE_MAP[role] ?? 'el';
67
69
  }
70
+ /**
71
+ * Short flags for the states the SDK reports.
72
+ *
73
+ * `present` is deliberately absent: `getStates` seeds every element's array with it, so it is true
74
+ * of everything that could appear here and encodes nothing — while costing eight characters per
75
+ * element in the layer whose entire job is cutting the agent's token bill. `visible`/`hidden` are
76
+ * likewise absent because the `visible` field already carries them.
77
+ *
78
+ * An unlisted state falls through to its own name, so an SDK newer than this daemon still reaches
79
+ * the agent with something readable instead of losing the state.
80
+ */
81
+ const STATE_FLAG = {
82
+ [ElementState.ENABLED]: 'en',
83
+ [ElementState.DISABLED]: 'dis',
84
+ [ElementState.CHECKED]: 'chk',
85
+ [ElementState.EXPANDED]: 'exp',
86
+ [ElementState.FOCUSED]: 'focus',
87
+ };
88
+ /** States the `visible` field already encodes, plus the one that is true of everything. */
89
+ const UNENCODED_STATES = new Set([
90
+ ElementState.PRESENT,
91
+ ElementState.VISIBLE,
92
+ ElementState.HIDDEN,
93
+ ]);
68
94
  function encodeStates(states, visible) {
69
95
  const flags = [];
70
- if (visible === true)
96
+ if (true === visible)
71
97
  flags.push('vis');
72
- else if (visible === false)
98
+ else if (false === visible)
73
99
  flags.push('hid');
74
100
  for (const s of states) {
75
- switch (s) {
76
- case 'visible':
77
- break; // handled above
78
- case 'hidden':
79
- break; // handled above
80
- case 'enabled':
81
- flags.push('en');
82
- break;
83
- case 'disabled':
84
- flags.push('dis');
85
- break;
86
- case 'checked':
87
- flags.push('chk');
88
- break;
89
- case 'unchecked':
90
- flags.push('uch');
91
- break;
92
- case 'expanded':
93
- flags.push('exp');
94
- break;
95
- case 'collapsed':
96
- flags.push('col');
97
- break;
98
- case 'focused':
99
- flags.push('focus');
100
- break;
101
- default:
102
- flags.push(s);
103
- }
101
+ if (UNENCODED_STATES.has(s))
102
+ continue;
103
+ flags.push(STATE_FLAG[s] ?? s);
104
104
  }
105
105
  return flags.length > 0 ? `[${flags.join(',')}]` : '';
106
106
  }
107
107
  /** Coerce a wire field to a string. resultToToon receives UNVALIDATED wire data cast to ToonElement,
108
108
  * so a missing/numeric `name` must not make `.replace` throw and lose the whole encode. */
109
109
  function toText(v) {
110
- if (typeof v === 'string')
110
+ if ('string' === typeof v)
111
111
  return v;
112
- if (typeof v === 'number' || typeof v === 'boolean' || typeof v === 'bigint')
112
+ if ('number' === typeof v || 'boolean' === typeof v || 'bigint' === typeof v)
113
113
  return String(v);
114
114
  return ''; // undefined / null / object / symbol have no representable text on a wire field
115
115
  }
@@ -125,7 +125,7 @@ function encodeLine(el, depth) {
125
125
  const states = encodeStates(Array.isArray(el.states) ? el.states : [], el.visible);
126
126
  const ref = toText(el.ref) || '?';
127
127
  const parts = [indent + type, ref, encodeName(el.name), ...(states ? [states] : [])];
128
- if (typeof el.value === 'string' && el.value.length > 0)
128
+ if ('string' === typeof el.value && el.value.length > 0)
129
129
  parts.push(`val=${encodeValue(el.value)}`);
130
130
  if (el.childCount !== undefined)
131
131
  parts.push(`count=${String(el.childCount)}`);
@@ -149,7 +149,7 @@ function encodeTree(elements, depth = 0) {
149
149
  }
150
150
  /** Encode an array of ElementDescriptor-shaped objects to TOON text. */
151
151
  export function toToon(elements) {
152
- if (elements.length === 0)
152
+ if (0 === elements.length)
153
153
  return '# TOON v1 — empty';
154
154
  return `# TOON v1\n${encodeTree(elements)}`;
155
155
  }
@@ -162,7 +162,7 @@ export function resultToToon(result) {
162
162
  }
163
163
  /** Whether a tool result object should be encoded as TOON (has an elements array). */
164
164
  export function isToonable(result) {
165
- return (typeof result === 'object' &&
165
+ return ('object' === typeof result &&
166
166
  result !== null &&
167
167
  !Array.isArray(result) &&
168
168
  Array.isArray(result['elements']));
package/dist/types.d.ts CHANGED
@@ -136,6 +136,12 @@ export interface MatchResult {
136
136
  * confirmed absence (a false negative); both are the false-green shape this tool exists to prevent.
137
137
  */
138
138
  scopeMissing?: boolean;
139
+ /**
140
+ * Zero-match diagnosis, present only on a miss: what IS on the page. `reticle_query` has always
141
+ * returned this; MATCH (the command every PREDICATE uses) did not, so a failed assertion was a
142
+ * dead end while the same failure through query was one step from fixed.
143
+ */
144
+ hint?: QueryEmptyHint;
139
145
  }
140
146
  /**
141
147
  * A semantic cluster of interactive elements in the DOM — the replacement for the raw testid list
@@ -764,6 +770,40 @@ export declare const AnnotationSchema: z.ZodDiscriminatedUnion<"kind", [z.ZodObj
764
770
  statePath: string;
765
771
  store?: string | undefined;
766
772
  equals?: unknown;
773
+ }>, z.ZodObject<{
774
+ kind: z.ZodLiteral<"assert-net">;
775
+ net: z.ZodObject<{
776
+ method: z.ZodOptional<z.ZodString>;
777
+ urlContains: z.ZodOptional<z.ZodString>;
778
+ status: z.ZodOptional<z.ZodNumber>;
779
+ count: z.ZodOptional<z.ZodNumber>;
780
+ }, "strip", z.ZodTypeAny, {
781
+ status?: number | undefined;
782
+ method?: string | undefined;
783
+ count?: number | undefined;
784
+ urlContains?: string | undefined;
785
+ }, {
786
+ status?: number | undefined;
787
+ method?: string | undefined;
788
+ count?: number | undefined;
789
+ urlContains?: string | undefined;
790
+ }>;
791
+ }, "strip", z.ZodTypeAny, {
792
+ kind: "assert-net";
793
+ net: {
794
+ status?: number | undefined;
795
+ method?: string | undefined;
796
+ count?: number | undefined;
797
+ urlContains?: string | undefined;
798
+ };
799
+ }, {
800
+ kind: "assert-net";
801
+ net: {
802
+ status?: number | undefined;
803
+ method?: string | undefined;
804
+ count?: number | undefined;
805
+ urlContains?: string | undefined;
806
+ };
767
807
  }>, z.ZodObject<{
768
808
  kind: z.ZodLiteral<"mark-dynamic">;
769
809
  testid: z.ZodString;
@@ -863,6 +903,14 @@ export type AnnotateResult = {
863
903
  ok: true;
864
904
  target: AnnotationTarget;
865
905
  compiled: string;
906
+ /**
907
+ * Set when the compiled annotation is NOT something a replay evaluates, so `compiled` on its
908
+ * own would overstate it. `assert-signal` writes a STEP expect, and replay checks exactly two
909
+ * things per step — element presence and state — so a step signal is recorded and then never
910
+ * checked. Saying "will assert signal X" and passing regardless is a false green in the
911
+ * feature whose whole job is to catch them.
912
+ */
913
+ note?: string;
866
914
  }
867
915
  /**
868
916
  * A failure carries its own way out. `code` alone told the caller WHAT was wrong and never what to
package/dist/types.js CHANGED
@@ -127,6 +127,18 @@ export const AnnotationSchema = z.discriminatedUnion('kind', [
127
127
  store: z.string().min(1).optional(),
128
128
  equals: z.unknown().optional(),
129
129
  }),
130
+ z.object({
131
+ kind: z.literal(AnnotationKind.ASSERT_NET),
132
+ // Same shape SUCCESS_STATE already accepts, so one vocabulary describes a network consequence
133
+ // whether it gates a step or ends the flow. `count` is the point of it: presence says the
134
+ // request fired, cardinality catches the double-submit that fired it twice.
135
+ net: z.object({
136
+ method: z.string().min(1).optional(),
137
+ urlContains: z.string().min(1).optional(),
138
+ status: z.number().optional(),
139
+ count: z.number().int().nonnegative().optional(),
140
+ }),
141
+ }),
130
142
  z.object({
131
143
  kind: z.literal(AnnotationKind.MARK_DYNAMIC),
132
144
  testid: z.string().min(1),
package/dist/upgrade.js CHANGED
@@ -53,7 +53,7 @@ export const UpgradeHintSchema = z.object({
53
53
  });
54
54
  /** Narrow an unknown wire value to a CloudCapability. */
55
55
  export function isCloudCapability(value) {
56
- return typeof value === 'string' && Object.values(CloudCapability).includes(value);
56
+ return 'string' === typeof value && Object.values(CloudCapability).includes(value);
57
57
  }
58
58
  /**
59
59
  * Canned, honest copy per capability. Kept here (not inlined at emit sites) so the tone is reviewed in