@reticlehq/engine 3.1.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 (123) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +36 -0
  3. package/dist/disagreement/body-failures.d.ts +4 -0
  4. package/dist/disagreement/body-failures.js +113 -0
  5. package/dist/disagreement/contradiction-evidence.d.ts +122 -0
  6. package/dist/disagreement/contradiction-evidence.js +194 -0
  7. package/dist/disagreement/contradiction-folds.d.ts +61 -0
  8. package/dist/disagreement/contradiction-folds.js +71 -0
  9. package/dist/disagreement/contradiction-types.d.ts +164 -0
  10. package/dist/disagreement/contradiction-types.js +1 -0
  11. package/dist/disagreement/contradictions.d.ts +5 -0
  12. package/dist/disagreement/contradictions.js +613 -0
  13. package/dist/disagreement/echo-mismatch.d.ts +10 -0
  14. package/dist/disagreement/echo-mismatch.js +299 -0
  15. package/dist/disagreement/reconcile.d.ts +39 -0
  16. package/dist/disagreement/reconcile.js +211 -0
  17. package/dist/disagreement/stale-response.d.ts +3 -0
  18. package/dist/disagreement/stale-response.js +186 -0
  19. package/dist/disagreement/unit-mismatch.d.ts +16 -0
  20. package/dist/disagreement/unit-mismatch.js +167 -0
  21. package/dist/disagreement/witness-disagreement.d.ts +42 -0
  22. package/dist/disagreement/witness-disagreement.js +43 -0
  23. package/dist/evidence/accepted-write.d.ts +35 -0
  24. package/dist/evidence/accepted-write.js +54 -0
  25. package/dist/evidence/already-true.d.ts +16 -0
  26. package/dist/evidence/already-true.js +89 -0
  27. package/dist/evidence/blind-spots.d.ts +133 -0
  28. package/dist/evidence/blind-spots.js +253 -0
  29. package/dist/evidence/body-capture-remedy.d.ts +42 -0
  30. package/dist/evidence/body-capture-remedy.js +96 -0
  31. package/dist/evidence/gap-ledger.d.ts +52 -0
  32. package/dist/evidence/gap-ledger.js +63 -0
  33. package/dist/evidence/honesty.d.ts +113 -0
  34. package/dist/evidence/honesty.js +105 -0
  35. package/dist/evidence/instrumentation-gaps.d.ts +91 -0
  36. package/dist/evidence/instrumentation-gaps.js +102 -0
  37. package/dist/evidence/learned-guards.d.ts +75 -0
  38. package/dist/evidence/learned-guards.js +78 -0
  39. package/dist/evidence/observability.d.ts +38 -0
  40. package/dist/evidence/observability.js +40 -0
  41. package/dist/evidence/page-teardown.d.ts +15 -0
  42. package/dist/evidence/page-teardown.js +17 -0
  43. package/dist/evidence/step-effect.d.ts +41 -0
  44. package/dist/evidence/step-effect.js +27 -0
  45. package/dist/evidence/uncaptured-bodies.d.ts +23 -0
  46. package/dist/evidence/uncaptured-bodies.js +41 -0
  47. package/dist/evidence/undeclared-change.d.ts +51 -0
  48. package/dist/evidence/undeclared-change.js +56 -0
  49. package/dist/evidence/unread-outcome.d.ts +10 -0
  50. package/dist/evidence/unread-outcome.js +77 -0
  51. package/dist/evidence/unsettled.d.ts +58 -0
  52. package/dist/evidence/unsettled.js +127 -0
  53. package/dist/evidence/verdict-intent-gap.d.ts +30 -0
  54. package/dist/evidence/verdict-intent-gap.js +35 -0
  55. package/dist/evidence/verified.d.ts +158 -0
  56. package/dist/evidence/verified.js +378 -0
  57. package/dist/index.d.ts +30 -0
  58. package/dist/index.js +25 -0
  59. package/dist/question/declared.d.ts +74 -0
  60. package/dist/question/declared.js +171 -0
  61. package/dist/question/lineage.d.ts +52 -0
  62. package/dist/question/lineage.js +122 -0
  63. package/dist/question/predicate/net-evidence.d.ts +21 -0
  64. package/dist/question/predicate/net-evidence.js +81 -0
  65. package/dist/question/predicate/observed-in-window.d.ts +24 -0
  66. package/dist/question/predicate/observed-in-window.js +38 -0
  67. package/dist/question/predicate/predicate-asks.d.ts +28 -0
  68. package/dist/question/predicate/predicate-asks.js +46 -0
  69. package/dist/question/predicate/predicate-console.d.ts +13 -0
  70. package/dist/question/predicate/predicate-console.js +138 -0
  71. package/dist/question/predicate/predicate-element.d.ts +13 -0
  72. package/dist/question/predicate/predicate-element.js +214 -0
  73. package/dist/question/predicate/predicate-eval-kit.d.ts +90 -0
  74. package/dist/question/predicate/predicate-eval-kit.js +126 -0
  75. package/dist/question/predicate/predicate-eval.d.ts +24 -0
  76. package/dist/question/predicate/predicate-eval.js +710 -0
  77. package/dist/question/predicate/predicate-parse.d.ts +15 -0
  78. package/dist/question/predicate/predicate-parse.js +173 -0
  79. package/dist/question/predicate/predicate-precheck.d.ts +8 -0
  80. package/dist/question/predicate/predicate-precheck.js +41 -0
  81. package/dist/question/predicate/predicate-request-body.d.ts +50 -0
  82. package/dist/question/predicate/predicate-request-body.js +120 -0
  83. package/dist/question/predicate/predicate-route.d.ts +66 -0
  84. package/dist/question/predicate/predicate-route.js +293 -0
  85. package/dist/question/predicate/predicate-schema.d.ts +170 -0
  86. package/dist/question/predicate/predicate-schema.js +509 -0
  87. package/dist/question/predicate/predicate-session.d.ts +72 -0
  88. package/dist/question/predicate/predicate-session.js +1 -0
  89. package/dist/question/predicate/predicate-to-links.d.ts +13 -0
  90. package/dist/question/predicate/predicate-to-links.js +38 -0
  91. package/dist/question/predicate/predicate.d.ts +26 -0
  92. package/dist/question/predicate/predicate.js +785 -0
  93. package/dist/question/predicate/property.d.ts +102 -0
  94. package/dist/question/predicate/property.js +135 -0
  95. package/dist/question/predicate/split-text-miss.d.ts +32 -0
  96. package/dist/question/predicate/split-text-miss.js +51 -0
  97. package/dist/question/predicate/testid-near-miss.d.ts +22 -0
  98. package/dist/question/predicate/testid-near-miss.js +33 -0
  99. package/dist/question/reaction.d.ts +17 -0
  100. package/dist/question/reaction.js +67 -0
  101. package/dist/window/adversary.d.ts +28 -0
  102. package/dist/window/adversary.js +90 -0
  103. package/dist/window/ambient.d.ts +63 -0
  104. package/dist/window/ambient.js +76 -0
  105. package/dist/window/appearance-budget.d.ts +41 -0
  106. package/dist/window/appearance-budget.js +47 -0
  107. package/dist/window/asset-noise.d.ts +42 -0
  108. package/dist/window/asset-noise.js +35 -0
  109. package/dist/window/body-relevance.d.ts +54 -0
  110. package/dist/window/body-relevance.js +78 -0
  111. package/dist/window/byte-size.d.ts +1 -0
  112. package/dist/window/byte-size.js +16 -0
  113. package/dist/window/engine-host.d.ts +35 -0
  114. package/dist/window/engine-host.js +20 -0
  115. package/dist/window/event-filters.d.ts +121 -0
  116. package/dist/window/event-filters.js +215 -0
  117. package/dist/window/json-salvage.d.ts +33 -0
  118. package/dist/window/json-salvage.js +96 -0
  119. package/dist/window/network-detail-merge.d.ts +8 -0
  120. package/dist/window/network-detail-merge.js +89 -0
  121. package/dist/window/ring-buffer.d.ts +41 -0
  122. package/dist/window/ring-buffer.js +152 -0
  123. package/package.json +71 -0
@@ -0,0 +1,76 @@
1
+ /**
2
+ * The identity ambient learning counts against. Prefer the emitted `region` (the stable CONTAINER of a
3
+ * mutation) over the element ref: a churning feed appends a NEW element every tick (fresh ref) and a
4
+ * removed element has no ref at all, so per-ref counts never accumulate and the region is never learned.
5
+ * The container persists, so it is the only key that converges. Falls back to the ref for events that
6
+ * mutate a single stable element (a ticker's text).
7
+ */
8
+ export function ambientKeyOf(event) {
9
+ const region = event.data?.['region'];
10
+ if ('string' === typeof region && region.length > 0)
11
+ return region;
12
+ return event.ref;
13
+ }
14
+ /** A ref must churn ambiently at least this many times before it is treated as ambient. */
15
+ export const DEFAULT_AMBIENT_THRESHOLD = 20;
16
+ /**
17
+ * An element ref: the letter `e` and a sequence number, minted per session by the SDK's ref table.
18
+ *
19
+ * It is an address within ONE session's numbering, not an identity. `e404` is whatever that session
20
+ * happened to hand out 404th.
21
+ */
22
+ const REF_SHAPED = /^e\d+$/;
23
+ /**
24
+ * Is this ambient key meaningful in a DIFFERENT session?
25
+ *
26
+ * `regionKeyOf` prefers the nearest `data-testid` — a name the app chose, stable across every run —
27
+ * and falls back to the element's ref when the region has none. Within a session that fallback is
28
+ * correct and useful. Across one it is not merely useless, it is WRONG: the next session hands `e404`
29
+ * to some other element, and the learned suppression lands on whatever that turns out to be.
30
+ *
31
+ * WHAT IT ACTUALLY AFFECTS. This map is read in exactly one place — the `settled` predicate drops
32
+ * events on learned-ambient regions before deciding the page went quiet. So a poisoned map makes
33
+ * `{kind: "settled"}` ignore regions that were never the churning ones, which is a false-green risk
34
+ * in the settle oracle. It does NOT filter the windows that summaries or contradictions are computed
35
+ * from; those read the buffer raw.
36
+ *
37
+ * That scope is narrower than this rule was first written as. The measurement offered for the wider
38
+ * claim — DOM events reappearing once the file was cleared — was taken across a daemon restart and a
39
+ * new session, so it did not isolate the file, and it is withdrawn. What stands without it: all 43
40
+ * keys in the persisted map were ref-shaped, and a ref cannot mean anything in a session that did
41
+ * not mint it.
42
+ */
43
+ export function isStableAmbientKey(key) {
44
+ return !REF_SHAPED.test(key);
45
+ }
46
+ /** The counts worth carrying between sessions — the stable keys, and nothing else. */
47
+ export function onlyStableAmbient(counts) {
48
+ return Object.fromEntries(Object.entries(counts).filter(([key]) => isStableAmbientKey(key)));
49
+ }
50
+ /** Fold a batch of events into the running ambient counts. Only unattributed, ref-bearing events count. */
51
+ export function accumulateAmbient(counts, events) {
52
+ const next = { ...counts };
53
+ for (const event of events) {
54
+ if (event.actionId !== undefined)
55
+ continue; // attributed to an action → signal, not ambient
56
+ const key = ambientKeyOf(event);
57
+ if (key === undefined)
58
+ continue;
59
+ next[key] = (next[key] ?? 0) + 1;
60
+ }
61
+ return next;
62
+ }
63
+ /** Whether a ref has churned ambiently often enough to be excluded from oracles/summaries. */
64
+ export function isAmbient(counts, ref, threshold = DEFAULT_AMBIENT_THRESHOLD) {
65
+ if (ref === undefined)
66
+ return false;
67
+ return (counts[ref] ?? 0) >= threshold;
68
+ }
69
+ /**
70
+ * Drop events on learned-ambient regions — the exclusion the settle oracle and summaries apply. An
71
+ * action-attributed event is ALWAYS kept, even on an ambient ref: if an action caused a change there,
72
+ * it is signal, not background churn.
73
+ */
74
+ export function excludeAmbient(counts, events, threshold) {
75
+ return events.filter((event) => event.actionId !== undefined || !isAmbient(counts, event.ref, threshold));
76
+ }
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Whether to act on what a name matched, wait for it, or refuse.
3
+ *
4
+ * Batching a whole journey into one round trip is the only way to stop paying a model turn per
5
+ * step, and it needs every step's element named up front. But the element a later step acts on
6
+ * often does not exist when the batch is submitted: the modal step 1 opens, the row step 2 creates.
7
+ * Resolving each name with a single query fails those instantly, which is exactly why an agent
8
+ * falls back to snapshot, act, snapshot, act — and that loop, not the engine, is where the time goes.
9
+ *
10
+ * Waiting fixes it. Only one kind of waiting is safe, and the asymmetry below IS the design:
11
+ *
12
+ * ONE match act. Nothing to decide.
13
+ * ZERO wait, while budget remains. The element may still be arriving, and there is nothing
14
+ * else it could be confused with, so waiting cannot act on the wrong thing.
15
+ * MANY refuse NOW, and never wait. This is the dangerous case and the reason this is a
16
+ * function rather than a retry loop: given time, a second element can arrive and make
17
+ * an ambiguous name resolve to whichever one the race happened to settle on. "It
18
+ * became unambiguous while I waited" is not the caller's intent — it is a coin toss
19
+ * the caller never saw, and the caller is the only one who can fix the name.
20
+ *
21
+ * Nothing here decides whether a consequence was PROVED. It decides only when to look again, which
22
+ * is why it can be this aggressive without touching a verdict.
23
+ */
24
+ export interface AppearanceInput {
25
+ /** How many elements the name matched on the most recent look. */
26
+ readonly matches: number;
27
+ /** How long this step has already spent looking. */
28
+ readonly elapsedMs: number;
29
+ /** The step's whole budget. Zero means the caller asked never to wait. */
30
+ readonly budgetMs: number;
31
+ }
32
+ export type AppearanceDecision = {
33
+ readonly do: 'act';
34
+ } | {
35
+ readonly do: 'wait';
36
+ readonly waitMs: number;
37
+ } | {
38
+ readonly do: 'refuse';
39
+ readonly because: string;
40
+ };
41
+ export declare function appearanceDecision(input: AppearanceInput): AppearanceDecision;
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Whether to act on what a name matched, wait for it, or refuse.
3
+ *
4
+ * Batching a whole journey into one round trip is the only way to stop paying a model turn per
5
+ * step, and it needs every step's element named up front. But the element a later step acts on
6
+ * often does not exist when the batch is submitted: the modal step 1 opens, the row step 2 creates.
7
+ * Resolving each name with a single query fails those instantly, which is exactly why an agent
8
+ * falls back to snapshot, act, snapshot, act — and that loop, not the engine, is where the time goes.
9
+ *
10
+ * Waiting fixes it. Only one kind of waiting is safe, and the asymmetry below IS the design:
11
+ *
12
+ * ONE match act. Nothing to decide.
13
+ * ZERO wait, while budget remains. The element may still be arriving, and there is nothing
14
+ * else it could be confused with, so waiting cannot act on the wrong thing.
15
+ * MANY refuse NOW, and never wait. This is the dangerous case and the reason this is a
16
+ * function rather than a retry loop: given time, a second element can arrive and make
17
+ * an ambiguous name resolve to whichever one the race happened to settle on. "It
18
+ * became unambiguous while I waited" is not the caller's intent — it is a coin toss
19
+ * the caller never saw, and the caller is the only one who can fix the name.
20
+ *
21
+ * Nothing here decides whether a consequence was PROVED. It decides only when to look again, which
22
+ * is why it can be this aggressive without touching a verdict.
23
+ */
24
+ /** How long to pause between looks. Short enough to catch a fast render, long enough not to spin. */
25
+ const POLL_MS = 120;
26
+ export function appearanceDecision(input) {
27
+ /*
28
+ * Ambiguity first, before any budget arithmetic, so no future edit to the timing can accidentally
29
+ * make a name that matches several things resolve by waiting.
30
+ */
31
+ if (input.matches > 1) {
32
+ return {
33
+ do: 'refuse',
34
+ because: `that name is ambiguous — it matched ${String(input.matches)} elements, and waiting cannot fix that: it would only change which one gets acted on. Name the one you mean.`,
35
+ };
36
+ }
37
+ if (1 === input.matches)
38
+ return { do: 'act' };
39
+ const remaining = input.budgetMs - input.elapsedMs;
40
+ if (remaining <= 0) {
41
+ return {
42
+ do: 'refuse',
43
+ because: `that name never appeared — nothing matched it within ${String(input.budgetMs)}ms. If it should have been there already, take a snapshot; if an earlier step was supposed to produce it, that step is the one that failed.`,
44
+ };
45
+ }
46
+ return { do: 'wait', waitMs: Math.min(POLL_MS, remaining) };
47
+ }
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Collapse the dev server's own traffic out of a network listing.
3
+ *
4
+ * Measured on a connected drive of the bench app: `reticle_network` returned 200 calls and 28,408
5
+ * bytes, mean 142 bytes each, and 68% of those bytes were URLs like `/src/main.tsx` and
6
+ * `/node_modules/.vite/deps/react.js`. None of them carried a body and none of them was evidence of
7
+ * anything being verified — it is the bundler talking to itself, billed to the agent on every read.
8
+ *
9
+ * This is a ROUTE cut and it has to stay one. `lean` is what happens when that line is crossed:
10
+ * dropping evidence to save tokens cost it two of five fixes and produced this project's first
11
+ * measured false green. So a FAILED asset is never folded — a 404 on a chunk is a real defect — and
12
+ * nothing folds once the caller's filter shows they are asking about particular calls. What is
13
+ * folded is reported with a count, a byte total, a sample and the argument that brings it all back,
14
+ * because a saving the reader cannot see or undo is a capability that degrades in silence.
15
+ */
16
+ /**
17
+ * The fields this reads. Structural on purpose: it runs over an already-projected call view and
18
+ * must not import that view's type, which lives on the other side of a package boundary.
19
+ *
20
+ * No index signature — one would force every caller's concrete view to declare it, and a projected
21
+ * view that carries exactly the fields it means is the better shape to keep.
22
+ */
23
+ export interface ListedCall {
24
+ readonly method?: string | undefined;
25
+ readonly url?: string | undefined;
26
+ readonly status?: number | string | undefined;
27
+ }
28
+ export interface FoldedNote {
29
+ readonly count: number;
30
+ readonly bytes: number;
31
+ readonly sample: string[];
32
+ readonly why: string;
33
+ readonly how: string;
34
+ }
35
+ export interface FoldOptions {
36
+ /** False whenever the caller filtered: a filter means they are asking about specific calls. */
37
+ readonly folding: boolean;
38
+ }
39
+ export declare function foldAssetNoise<T extends ListedCall>(calls: readonly T[], options: FoldOptions): {
40
+ calls: T[];
41
+ folded?: FoldedNote;
42
+ };
@@ -0,0 +1,35 @@
1
+ import { ASSET_URL } from './body-relevance.js';
2
+ import { byteSizeOf } from './byte-size.js';
3
+ /** How many folded URLs to show, so the reader can see WHAT was folded without paying for all of it. */
4
+ const SAMPLE = 3;
5
+ function isSuccess(status) {
6
+ return 'number' === typeof status && status >= 200 && status < 400;
7
+ }
8
+ /** A successful GET of something the build produced — the bulk, and the part nobody asked about. */
9
+ function isNoise(call) {
10
+ if ('GET' !== (call.method ?? '').toUpperCase())
11
+ return false;
12
+ if (!isSuccess(call.status))
13
+ return false;
14
+ return ASSET_URL.test(call.url ?? '');
15
+ }
16
+ export function foldAssetNoise(calls, options) {
17
+ if (!options.folding)
18
+ return { calls: [...calls] };
19
+ const kept = [];
20
+ const folded = [];
21
+ for (const call of calls)
22
+ (isNoise(call) ? folded : kept).push(call);
23
+ if (0 === folded.length)
24
+ return { calls: kept };
25
+ return {
26
+ calls: kept,
27
+ folded: {
28
+ count: folded.length,
29
+ bytes: byteSizeOf(JSON.stringify(folded)),
30
+ sample: folded.slice(0, SAMPLE).map((c) => c.url ?? ''),
31
+ why: 'successful GETs of build output (modules, styles, maps, Vite plumbing). They carry no verdict — this is the bundler talking to itself, not the app under test.',
32
+ how: 'pass assets:true to list them, or name what you mean with urlContains / method / status.',
33
+ },
34
+ };
35
+ }
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Whether a network call's body earns the bytes it costs.
3
+ *
4
+ * `reticle_network` was the most expensive read an agent makes: measured on a connected drive of the
5
+ * bench app with body capture ON, that one tool returned 59,458 bytes and was 90.9% of every byte
6
+ * the drive spent.
7
+ *
8
+ * It is NOT true that bodies dominate it, and that claim is retracted here rather than quietly
9
+ * dropped, because it is what motivated this file and it was written into the tool's own
10
+ * description. Re-measured with the DEFAULT configuration — capture off — the same tool returned 200
11
+ * calls and 28,408 bytes with ZERO bodies, and 68% of those bytes were URLs. So this gating is
12
+ * correct and INERT until somebody turns capture on; the bulk is the number of dev-server asset
13
+ * calls, which is what `asset-noise.ts` addresses.
14
+ *
15
+ * The flag to avoid that already existed and defaulted the expensive way, which is the same defect
16
+ * in a different costume — an optional saving nobody is told about is a saving nobody takes. So the
17
+ * DEFAULT moves and the question becomes "could this body change a verdict".
18
+ *
19
+ * The line this must not cross is the one `lean` crossed: dropping evidence to save tokens fixed 3
20
+ * of 5 bugs against the full surface's 5 and produced this project's first measured false green.
21
+ * Bodies are therefore kept for every call that FAILED (the body is where the reason lives), for
22
+ * every call whose outcome cannot be scored at all (no status, or an explicit `ok:false` — treating
23
+ * unknown as success is how an unverifiable call becomes an assumed one), and for any call the
24
+ * caller named through a filter, because naming a call IS asking about it. What is dropped is the
25
+ * body of a plain success nobody mentioned.
26
+ */
27
+ /** How much body detail the caller wants. `auto` keeps only what could decide a verdict. */
28
+ export type BodyMode = 'all' | 'none' | 'auto';
29
+ /** The fields of a captured call this decision reads. Deliberately structural, not a class. */
30
+ export interface ScorableCall {
31
+ readonly status?: number | string | undefined;
32
+ readonly ok?: boolean | undefined;
33
+ readonly method?: string | undefined;
34
+ readonly url?: string | undefined;
35
+ readonly contentType?: string | undefined;
36
+ }
37
+ /**
38
+ * What a dev server serves that nobody asked about: modules, styles, maps, and Vite's own plumbing.
39
+ *
40
+ * This is the actual bulk. Measured on a connected drive of the bench app, 200 calls averaged 142
41
+ * bytes and 68% of the payload was URLs of exactly this kind — `/src/main.tsx`, `/@vite/client`,
42
+ * `/node_modules/.vite/deps/...`. They carry no verdict and are the reason the tool cost 28,408
43
+ * bytes on that drive.
44
+ *
45
+ * Exported because the same question is asked twice: whether to keep this call's BODY, and whether
46
+ * to list the call at all. One regular expression, so the two answers cannot drift apart and start
47
+ * disagreeing about what an asset is.
48
+ */
49
+ export declare const ASSET_URL: RegExp;
50
+ /** True when the caller's filters singled this call out, so its body is the thing being asked about. */
51
+ export interface BodyContext {
52
+ readonly named?: boolean;
53
+ }
54
+ export declare function bodyIsEvidence(call: ScorableCall, mode: BodyMode, context?: BodyContext): boolean;
@@ -0,0 +1,78 @@
1
+ /**
2
+ * Whether a network call's body earns the bytes it costs.
3
+ *
4
+ * `reticle_network` was the most expensive read an agent makes: measured on a connected drive of the
5
+ * bench app with body capture ON, that one tool returned 59,458 bytes and was 90.9% of every byte
6
+ * the drive spent.
7
+ *
8
+ * It is NOT true that bodies dominate it, and that claim is retracted here rather than quietly
9
+ * dropped, because it is what motivated this file and it was written into the tool's own
10
+ * description. Re-measured with the DEFAULT configuration — capture off — the same tool returned 200
11
+ * calls and 28,408 bytes with ZERO bodies, and 68% of those bytes were URLs. So this gating is
12
+ * correct and INERT until somebody turns capture on; the bulk is the number of dev-server asset
13
+ * calls, which is what `asset-noise.ts` addresses.
14
+ *
15
+ * The flag to avoid that already existed and defaulted the expensive way, which is the same defect
16
+ * in a different costume — an optional saving nobody is told about is a saving nobody takes. So the
17
+ * DEFAULT moves and the question becomes "could this body change a verdict".
18
+ *
19
+ * The line this must not cross is the one `lean` crossed: dropping evidence to save tokens fixed 3
20
+ * of 5 bugs against the full surface's 5 and produced this project's first measured false green.
21
+ * Bodies are therefore kept for every call that FAILED (the body is where the reason lives), for
22
+ * every call whose outcome cannot be scored at all (no status, or an explicit `ok:false` — treating
23
+ * unknown as success is how an unverifiable call becomes an assumed one), and for any call the
24
+ * caller named through a filter, because naming a call IS asking about it. What is dropped is the
25
+ * body of a plain success nobody mentioned.
26
+ */
27
+ /**
28
+ * Methods that CHANGE something. Their bodies are the evidence that they changed the right thing.
29
+ *
30
+ * A successful `POST /api/todos -> {"id":7}` is the answer to "did that click create the todo",
31
+ * which is the question the whole tool exists for. An earlier version of this rule kept bodies on
32
+ * failures only, and dropped that one — the repo's own test caught it, which is what that test is
33
+ * for.
34
+ */
35
+ const MUTATING = new Set(['POST', 'PUT', 'PATCH', 'DELETE']);
36
+ /**
37
+ * What a dev server serves that nobody asked about: modules, styles, maps, and Vite's own plumbing.
38
+ *
39
+ * This is the actual bulk. Measured on a connected drive of the bench app, 200 calls averaged 142
40
+ * bytes and 68% of the payload was URLs of exactly this kind — `/src/main.tsx`, `/@vite/client`,
41
+ * `/node_modules/.vite/deps/...`. They carry no verdict and are the reason the tool cost 28,408
42
+ * bytes on that drive.
43
+ *
44
+ * Exported because the same question is asked twice: whether to keep this call's BODY, and whether
45
+ * to list the call at all. One regular expression, so the two answers cannot drift apart and start
46
+ * disagreeing about what an asset is.
47
+ */
48
+ export const ASSET_URL = /\.(m?[jt]sx?|css|map|woff2?|png|jpe?g|svg|gif|ico|webp|avif)(\?|$)|\/@vite\/|\/node_modules\//i;
49
+ /** A 2xx/3xx HTTP status. Anything else — including a string, or nothing — is not a plain success. */
50
+ function isSuccessStatus(status) {
51
+ if ('number' !== typeof status)
52
+ return false;
53
+ return status >= 200 && status < 400;
54
+ }
55
+ export function bodyIsEvidence(call, mode, context = {}) {
56
+ if ('all' === mode)
57
+ return true;
58
+ if ('none' === mode)
59
+ return false;
60
+ // A call the caller singled out is one they are asking about; withholding its body answers a
61
+ // different question than the one asked.
62
+ if (true === context.named)
63
+ return true;
64
+ if (false === call.ok)
65
+ return true;
66
+ // Not scorable — no status at all (desktop IPC fire-and-forget) — so the body is the only evidence
67
+ // there is. Keeping it is the difference between "outcome unknown" and "outcome assumed fine".
68
+ if (!isSuccessStatus(call.status))
69
+ return true;
70
+ // A mutation's body says WHAT it changed, which no other field carries.
71
+ if (MUTATING.has((call.method ?? '').toUpperCase()))
72
+ return true;
73
+ // Anything the app exchanged as data, rather than something the browser fetched to run.
74
+ if ((call.contentType ?? '').toLowerCase().includes('json'))
75
+ return true;
76
+ // What is left is a successful GET of something that looks like a build artifact.
77
+ return !ASSET_URL.test(call.url ?? '');
78
+ }
@@ -0,0 +1 @@
1
+ export declare function byteSizeOf(text: string): number;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * How many bytes a string is, in every runtime the rules are meant to run in.
3
+ *
4
+ * `Buffer.byteLength` was used here and is a Node GLOBAL — it needs no import, so the guard that
5
+ * polices `node:` imports never saw it, and it sat on a path this package exports from its front
6
+ * door. An adopter running the rules in a browser, a worker, Deno or an edge runtime got a
7
+ * ReferenceError out of code the package promises is standalone.
8
+ *
9
+ * `TextEncoder` is in all of them, and is WHATWG rather than Node. The encoder is created once:
10
+ * this is called per event on the buffer's hot path, and allocating an encoder each time was the
11
+ * only reason to prefer the global.
12
+ */
13
+ const ENCODER = new TextEncoder();
14
+ export function byteSizeOf(text) {
15
+ return ENCODER.encode(text).length;
16
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * The two things the rules cannot do for themselves.
3
+ *
4
+ * The rules read what happened and say whether the declared consequence held. They are meant to be
5
+ * liftable out of the daemon on their own, so anyone implementing the specification can have the
6
+ * rules without also taking a web socket, a command line and somewhere to put the answer.
7
+ *
8
+ * Two ordinary needs stand in the way of that. When a rule cannot be run at all, somebody should be
9
+ * told; and when a rule schedules a re-check for later, that re-check should still look like part of
10
+ * the call that asked for it, rather than an orphan nobody can trace back.
11
+ *
12
+ * Both are answered by whoever is running the rules, not by the rules going and finding the daemon.
13
+ * This is the same arrangement the project scaffolder uses: anything it cannot know for itself is
14
+ * handed to it, and a new outward need is a new member here rather than a new import.
15
+ *
16
+ * Both are optional everywhere they appear. Leave them out -- as a test with a fake usually does --
17
+ * and nothing is recorded and callbacks run as they always did. That is deliberate: a missing note
18
+ * should cost you a log line, never a verdict.
19
+ */
20
+ /**
21
+ * Record something the rules could not do.
22
+ *
23
+ * Example: a rule threw while reading a window, so the wait is ended rather than left pending, and
24
+ * `note('reticle_wait_failed', { predicate: 'net', error: 'bad selector' })` says why.
25
+ */
26
+ export type NoteFn = (event: string, detail: Record<string, unknown>) => void;
27
+ /**
28
+ * Wrap a callback so it still belongs to the call that created it.
29
+ *
30
+ * A wait re-checks itself when a new event arrives or a timer fires. Neither of those is inside the
31
+ * original call, so without this every re-check looked like a brand new piece of work starting from
32
+ * nowhere. On one healthy run that produced twenty-three of them, which is exactly what a genuinely
33
+ * stuck call looks like -- so the thing meant to spot trouble was manufacturing it.
34
+ */
35
+ export type KeepCallerContextFn = (callback: () => void) => () => void;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * The two things the rules cannot do for themselves.
3
+ *
4
+ * The rules read what happened and say whether the declared consequence held. They are meant to be
5
+ * liftable out of the daemon on their own, so anyone implementing the specification can have the
6
+ * rules without also taking a web socket, a command line and somewhere to put the answer.
7
+ *
8
+ * Two ordinary needs stand in the way of that. When a rule cannot be run at all, somebody should be
9
+ * told; and when a rule schedules a re-check for later, that re-check should still look like part of
10
+ * the call that asked for it, rather than an orphan nobody can trace back.
11
+ *
12
+ * Both are answered by whoever is running the rules, not by the rules going and finding the daemon.
13
+ * This is the same arrangement the project scaffolder uses: anything it cannot know for itself is
14
+ * handed to it, and a new outward need is a new member here rather than a new import.
15
+ *
16
+ * Both are optional everywhere they appear. Leave them out -- as a test with a fake usually does --
17
+ * and nothing is recorded and callbacks run as they always did. That is deliberate: a missing note
18
+ * should cost you a log line, never a verdict.
19
+ */
20
+ export {};
@@ -0,0 +1,121 @@
1
+ import { type ReticleEvent } from '@reticlehq/core';
2
+ /**
3
+ * The friendly bucket names reticle_observe's `filters` param advertises → the real event types.
4
+ *
5
+ * The schema promised `dom | net | route | console | animation | signal`, but the handler filtered
6
+ * with `filters.includes(e.type)` against types like `net.request` and `dom.added` — so every
7
+ * documented value matched nothing, and an agent passing `filters:['net']` to trim its payload got an
8
+ * EMPTY timeline instead. Empty reads as "the app did nothing" — a false green produced by using the
9
+ * feature exactly as documented. Mapping the bucket to its member types makes the documented values
10
+ * work; raw types are still accepted (see eventMatchesFilters) so neither spelling surprises a caller.
11
+ */
12
+ export declare const OBSERVE_FILTER_BUCKETS: Record<string, readonly string[]>;
13
+ /**
14
+ * True when an event passes an observe `filters` allowlist. A filter entry matches either as a bucket
15
+ * name (`net` keeps every net.* type) or as a raw event type (`net.request`). Unknown entries match
16
+ * nothing rather than throwing — a typo narrows the result, it never crashes the observe.
17
+ */
18
+ export declare function eventMatchesFilters(e: ReticleEvent, filters: readonly string[]): boolean;
19
+ /**
20
+ * Match a net.request event against optional method/url/status/ok filters (reticle_network).
21
+ *
22
+ * `ok` is the filter the tool's own description points at for desktop IPC, whose 200/500 is derived
23
+ * rather than sent by any server. A still-PENDING call never matches an `ok` filter in either
24
+ * direction: unresolved is not the same as failed, and answering "yes, it failed" about a request
25
+ * still in flight is the false green this whole surface exists to prevent.
26
+ */
27
+ export declare function matchNet(e: ReticleEvent, method: string | undefined, urlContains: string | undefined, status: number | undefined, ok?: boolean): boolean;
28
+ /**
29
+ * Reconcile network events into completed calls + still-in-flight calls. A NET_PENDING whose
30
+ * `id` never gets a matching NET_REQUEST is an unresolved/hung request — the case
31
+ * completion-only logging is blind to. Pending events are annotated `{ status: 'pending',
32
+ * pending: true }` so a numeric `status` filter excludes them but `urlContains`/`method` match.
33
+ */
34
+ export declare function reconcileNet(events: ReticleEvent[]): ReticleEvent[];
35
+ /**
36
+ * Strip the grader-only raw URL before an event is rendered to the agent.
37
+ *
38
+ * `urlRaw` exists so `urlContains` can match a path redaction rewrote. It is a secret-bearing field
39
+ * by construction (the whole reason `url` was redacted) and must never appear in observe, evidence,
40
+ * or a network listing.
41
+ */
42
+ export declare function withoutUrlRaw(event: unknown): unknown;
43
+ /** Compact network-call summary for reticle_network output — drops event plumbing (t, type,
44
+ * sessionId, ref, id, initiator, ok) the agent never needs, keeping only method/url/status/ms.
45
+ * This is the bulk of the token cost: raw ReticleEvent objects are ~5x larger than this. */
46
+ interface NetCallView {
47
+ method: string;
48
+ url: string;
49
+ status?: number | string;
50
+ statusText?: string;
51
+ contentType?: string;
52
+ responseSize?: number;
53
+ requestBody?: string;
54
+ responseBody?: string;
55
+ bodyTruncated?: boolean;
56
+ ms?: number;
57
+ /** Authoritative response headers merged from the driven (CDP) path — present only when driven. */
58
+ headers?: Record<string, string>;
59
+ /**
60
+ * A fire-and-forget desktop IPC send (`ipcRenderer.send`): dispatched, outcome unknowable.
61
+ *
62
+ * Carried into the projection on purpose. Such a record has no `status` and no `ok`, and without
63
+ * this flag a reader has no way to tell "the outcome is unknown" from "the fields were dropped" —
64
+ * which is the reading that turns an unverifiable call into an assumed success.
65
+ */
66
+ oneWay?: boolean;
67
+ }
68
+ export declare function projectNetCall(e: ReticleEvent, includeBodies?: boolean): NetCallView;
69
+ /**
70
+ * Compact console-log summary for reticle_console output.
71
+ *
72
+ * `stack`/`source` are the only localization signal a console failure carries — there is no element
73
+ * to map to a component here, so without them "an error was logged" is the whole report and the agent
74
+ * has to go find the origin itself. The browser already keeps this lean by capturing a stack for
75
+ * console.error only; the projection used to discard even that.
76
+ */
77
+ interface ConsoleLogView {
78
+ level: string;
79
+ text: string;
80
+ stack?: string;
81
+ source?: string;
82
+ }
83
+ export declare function projectConsoleLog(e: ReticleEvent): ConsoleLogView;
84
+ /** True for any console.* / uncaught-error event (the reticle_console universe). */
85
+ export declare function isConsoleEvent(e: ReticleEvent): boolean;
86
+ /** Match a console/error event against an optional level filter (reticle_console). */
87
+ export declare function matchConsole(e: ReticleEvent, level: string | undefined): boolean;
88
+ /** One present network call summarized for a zero-match hint. */
89
+ interface NetCallSummary {
90
+ method: string;
91
+ url: string;
92
+ status?: number;
93
+ }
94
+ /**
95
+ * Near-miss for reticle_network: when a filter matched zero calls, describe what DID fire so the
96
+ * agent self-corrects ("POST /x 200 matched nothing, but these 3 requests happened") instead of
97
+ * reading a bare []. `allNet` is every net.request in the window (pre-filter).
98
+ */
99
+ interface NetEmptyHint {
100
+ totalInWindow: number;
101
+ /** Up to HINT_SAMPLE_MAX present calls (most-recent first). */
102
+ present: NetCallSummary[];
103
+ }
104
+ export declare function netEmptyHint(allNet: ReticleEvent[]): NetEmptyHint;
105
+ /** Per-level console counts in the window — the body of a zero-match console hint. */
106
+ interface ConsoleLevelCounts {
107
+ log: number;
108
+ warn: number;
109
+ error: number;
110
+ }
111
+ /**
112
+ * Near-miss for reticle_console: when a level filter matched zero logs, report what levels ARE
113
+ * present so the agent knows the page isn't silent ("0 errors, but 3 warns + 5 logs"). `allConsole`
114
+ * is every console/error event in the window (pre-filter).
115
+ */
116
+ interface ConsoleEmptyHint {
117
+ totalInWindow: number;
118
+ byLevel: ConsoleLevelCounts;
119
+ }
120
+ export declare function consoleEmptyHint(allConsole: ReticleEvent[]): ConsoleEmptyHint;
121
+ export {};