@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,194 @@
1
+ /**
2
+ * What a request IS, which requests are OURS, and how to say one out loud.
3
+ *
4
+ * Split out of `contradictions.ts` when that file crossed the line cap — and the seam was already
5
+ * there rather than invented for the occasion. Everything here answers a question ABOUT NETWORK
6
+ * EVIDENCE: what did this event mean, was it a write, did a retry rescue it, is it the toolchain's
7
+ * own traffic rather than the app's, is this cadence a poll. Nothing here knows what a
8
+ * contradiction is.
9
+ *
10
+ * The rules next door read this vocabulary and decide what disagrees. Keeping the two apart means a
11
+ * new rule cannot quietly redefine what "in flight" or "ours" means for itself, which is how two
12
+ * rules end up disagreeing about the same window.
13
+ */
14
+ import { EventType, MUTATING_METHODS, asNumber, asString, isDevToolingUrl, isThirdPartyUrl, urlForMatch, } from '@reticlehq/core';
15
+ export function netCall(e) {
16
+ const status = asNumber(e.data['status']);
17
+ return {
18
+ method: (asString(e.data['method']) ?? '').toUpperCase(),
19
+ url: asString(e.data['url']) ?? '',
20
+ matchUrl: urlForMatch(e.data),
21
+ status,
22
+ // `ok` is authoritative when present (IPC sets it explicitly); status is the HTTP fallback.
23
+ // Neither present = no verdict was ever reported, which stays undefined all the way through.
24
+ ok: e.data['ok'] === undefined && status === undefined
25
+ ? undefined
26
+ : true === e.data['ok'] || (e.data['ok'] === undefined && (status ?? 0) < 400),
27
+ };
28
+ }
29
+ /**
30
+ * The failed calls that a LATER successful call to the same endpoint replaced.
31
+ *
32
+ * Identity, not index: each `netCall` is a fresh object held by `settled`, and `settled` is built
33
+ * from events in sequence order, so "later" is simply "further along the array". Compared on
34
+ * `matchUrl` so a cache-buster or a changing query token cannot make a retry look like a different
35
+ * call — the same normalisation every other url comparison here uses.
36
+ */
37
+ export function recoveredByRetry(settled) {
38
+ const out = new Set();
39
+ for (let i = 0; i < settled.length; i += 1) {
40
+ const call = settled[i];
41
+ if (call === undefined || false !== call.ok)
42
+ continue;
43
+ for (let j = i + 1; j < settled.length; j += 1) {
44
+ const later = settled[j];
45
+ if (later === undefined)
46
+ continue;
47
+ if (true === later.ok && later.method === call.method && later.matchUrl === call.matchUrl) {
48
+ out.add(call);
49
+ break;
50
+ }
51
+ }
52
+ }
53
+ return out;
54
+ }
55
+ /**
56
+ * Did the user-visible application state move forward? DOM, store and route only — deliberately NOT
57
+ * network, animation or signal. The question every rule below asks is "did the app act as if it
58
+ * succeeded", and a request firing is not the app acting as if anything.
59
+ */
60
+ export function isMutating(call) {
61
+ return MUTATING_METHODS.includes(call.method);
62
+ }
63
+ export function describe(call) {
64
+ return `${call.method} ${call.url}${call.status === undefined ? '' : ` → ${String(call.status)}`}`;
65
+ }
66
+ /**
67
+ * Actions that are SUPPOSED to make something happen, so producing nothing is a finding.
68
+ *
69
+ * Deliberately narrow. `hover`, `focus` and `scrollIntoView` can legitimately move nothing, and
70
+ * `fill`/`type` change an input's value without necessarily mutating the DOM tree — flagging those
71
+ * would manufacture noise, which is the failure mode opposite to a false green and just as bad.
72
+ */
73
+ export const NET_TYPES = new Set([
74
+ EventType.NET_PENDING,
75
+ EventType.NET_REQUEST,
76
+ EventType.NET_STREAM,
77
+ ]);
78
+ /**
79
+ * Hash-router paths put the route in the fragment (`#/settings`, `#!/home`). An in-page skip link
80
+ * does not (`#main-content`, `#`, empty). The blank-destination rule must still see the former.
81
+ */
82
+ export function isInPageFragment(hash) {
83
+ if ('' === hash || '#' === hash)
84
+ return true;
85
+ const body = hash.startsWith('#') ? hash.slice(1) : hash;
86
+ return !body.startsWith('/') && !body.startsWith('!');
87
+ }
88
+ export function hrefAsUrl(value) {
89
+ if (value === undefined || '' === value)
90
+ return undefined;
91
+ try {
92
+ return new URL(value);
93
+ }
94
+ catch {
95
+ return undefined;
96
+ }
97
+ }
98
+ /**
99
+ * Same origin + pathname + search, different in-page fragment — a skip link, not a new view.
100
+ *
101
+ * Returns false when `from`/`to` are missing, so older events without hrefs keep the existing rule.
102
+ */
103
+ export function isSameDocumentHashAnchor(event) {
104
+ if (event.type !== EventType.ROUTE_CHANGE)
105
+ return false;
106
+ const from = hrefAsUrl(asString(event.data['from']));
107
+ const to = hrefAsUrl(asString(event.data['to']));
108
+ if (from === undefined || to === undefined)
109
+ return false;
110
+ if (from.origin !== to.origin || from.pathname !== to.pathname || from.search !== to.search) {
111
+ return false;
112
+ }
113
+ if (from.hash === to.hash)
114
+ return false;
115
+ return isInPageFragment(to.hash);
116
+ }
117
+ /**
118
+ * Split the window into the app's traffic and the dev toolchain's own (see `DevToolingChannel`).
119
+ *
120
+ * NOTHING below may judge the toolchain. Reported from a real drive: a correct Next.js navigation
121
+ * graded `verified: "no"` because the dev overlay was resolving a source map for an unrelated React
122
+ * key warning, and that in-flight `POST /__nextjs_original-stack-frames` read as "the UI advanced
123
+ * over a request that never settled". Every app that logs one dev warning got a false negative on
124
+ * every action. The overlay's own 404s and duplicate fetches are the same story on other checks,
125
+ * which is why the split happens ONCE here rather than in the one check that reported it.
126
+ */
127
+ export function splitForeignTraffic(events, appOrigin) {
128
+ const ignored = [];
129
+ const app = events.filter((e) => {
130
+ if (!NET_TYPES.has(e.type))
131
+ return true;
132
+ const url = asString(e.data['url']);
133
+ // Somebody else's code, twice over: the toolchain's own channel, and any site that is not the
134
+ // app under test. Neither can answer the question every rule below asks.
135
+ if (!isDevToolingUrl(url) && !isThirdPartyUrl(url, appOrigin))
136
+ return true;
137
+ if (url !== undefined && !ignored.includes(url))
138
+ ignored.push(url);
139
+ return false;
140
+ });
141
+ return { app, ignored };
142
+ }
143
+ /**
144
+ * Cross-channel contradictions in this window, with the edit-epoch caveat attached when it applies.
145
+ *
146
+ * Cross-epoch evidence is LABELLED rather than excluded, which is the opposite of what the document
147
+ * scoping does, and the difference is the point. A navigation is total — it throws away the page,
148
+ * the refs, the in-flight requests and the state — so nothing recorded before it is still about the
149
+ * world, and dropping it is the only honest option. A hot update is not: most modules, most of the
150
+ * DOM, the whole network log and every console line survive one, so most of what was observed a
151
+ * second before an edit is still true a second after. Excluding it would empty windows that hold
152
+ * real findings, and an emptied window reads as "nothing happened" — which is the more expensive of
153
+ * the two wrong answers and the one this whole family of checks exists to prevent.
154
+ *
155
+ * So the findings stand and the caveat is said out loud, and only when it is unambiguous: EVERY
156
+ * observation in the window predates the edit. One post-edit observation and the agent is already
157
+ * looking at the code it wrote, so the label would be noise.
158
+ */
159
+ /**
160
+ * Below this, repeated writes are a BURST, whatever their spacing.
161
+ *
162
+ * A double submit is two clicks, or one click and a re-render: milliseconds apart. Nothing a human
163
+ * or a StrictMode remount does lands on a quarter-second grid, so this is the floor under which
164
+ * regularity means nothing.
165
+ */
166
+ export const POLL_MIN_INTERVAL_MS = 250;
167
+ /**
168
+ * How far a gap may sit from the median and still count as the same cadence.
169
+ *
170
+ * Loose on purpose: a real poll drifts under load, and a `setInterval` competing with a busy main
171
+ * thread is not metronomic. Tight enough that a burst followed by a late retry — the shape a double
172
+ * submit plus a user's second attempt makes — is not read as a rhythm.
173
+ */
174
+ export const POLL_JITTER_RATIO = 0.4;
175
+ /**
176
+ * Is this the same write on a steady interval, rather than the same write twice?
177
+ *
178
+ * THREE samples minimum, and that is the load-bearing part: two writes give one gap, and a single
179
+ * gap cannot distinguish a cadence from a coincidence. Two writes stay a duplicate however far
180
+ * apart they are, which is the classic double submit and every case this rule was written for.
181
+ */
182
+ export function isSteadyCadence(times) {
183
+ if (times.length < 3)
184
+ return false;
185
+ const ordered = [...times].sort((a, b) => a - b);
186
+ const gaps = [];
187
+ for (let i = 1; i < ordered.length; i += 1)
188
+ gaps.push((ordered[i] ?? 0) - (ordered[i - 1] ?? 0));
189
+ const sorted = [...gaps].sort((a, b) => a - b);
190
+ const median = sorted[Math.floor(sorted.length / 2)] ?? 0;
191
+ if (median < POLL_MIN_INTERVAL_MS)
192
+ return false;
193
+ return gaps.every((gap) => Math.abs(gap - median) <= median * POLL_JITTER_RATIO);
194
+ }
@@ -0,0 +1,61 @@
1
+ import type { ReticleEvent } from '@reticlehq/core';
2
+ import type { Contradiction, ContradictionOptions } from './contradiction-types.js';
3
+ /**
4
+ * Rules a CONSUMER adds to the contradiction pass, without editing the ones this package ships.
5
+ *
6
+ * Every rule in `contradictions.ts` is a pure fold over a recording — events in, findings out, no
7
+ * session, no clock, no IO. A service embedding this engine wants rules of exactly that shape for
8
+ * itself, and the only thing standing between it and one was that `findContradictions` folds over a
9
+ * list written into its own body. Appending to that list means editing this package, which means a
10
+ * fork, which means the consumer's rules and this package's rules become one tree to merge forever.
11
+ *
12
+ * A registry rather than a parameter on `findContradictions`, deliberately. There are six call sites
13
+ * and a consumer reaches none of them: the tools call the pass internally, and a tool handler is
14
+ * handed a deps bag, not options. Threading a parameter would mean touching every path a verdict can
15
+ * take — and would still miss the one inside `crawl`. Registration happens once, at boot, by whoever
16
+ * composed the process.
17
+ *
18
+ * This is not a public plugin API and should not be documented as one. It has a single intended
19
+ * consumer, which is a service we own, and its shape is free to change in lockstep with it.
20
+ */
21
+ /**
22
+ * One consumer rule.
23
+ *
24
+ * Receives the app's OWN events — dev-tooling traffic is already removed, exactly as it is for the
25
+ * shipped rules. A second answer to "which events count" would be a second product.
26
+ */
27
+ export type ContradictionFold = (events: readonly ReticleEvent[], options: ContradictionOptions) => readonly Contradiction[];
28
+ /**
29
+ * Add a rule to every verdict this engine produces. Returns the undo.
30
+ *
31
+ * The undo is not a convenience: without it a registry is process-global state that tests cannot
32
+ * clean up, so each one starts depending on the order it ran in.
33
+ */
34
+ export declare function registerContradictionFold(fold: ContradictionFold): () => void;
35
+ /** What is registered right now. Exported so a guard can assert the registry is empty by default. */
36
+ export declare function registeredContradictionFolds(): readonly ContradictionFold[];
37
+ /**
38
+ * What the engine can no longer see, in words meant for whoever reads the verdict.
39
+ *
40
+ * Empty is the normal case and the honest one: no rule has crashed, so nothing is missing.
41
+ */
42
+ export declare function crashedRuleNotes(): string[];
43
+ /** Forget the crashes. For tests, which must not inherit the previous test's damage. */
44
+ export declare function clearCrashedRules(): void;
45
+ /**
46
+ * Run every registered rule, containing anything one of them throws.
47
+ *
48
+ * A registered fold is somebody else's code running inside every verdict path this package has. If a
49
+ * throw could propagate, one defect in a consumer's rule would take down `assert`, `act_and_wait`,
50
+ * `observe` and `crawl` at once — turning a missing finding into a dead engine. So it is contained.
51
+ *
52
+ * Containment on its own is not enough, and this is the part that took a while to see. This engine
53
+ * reports what is WRONG with an app, so running with fewer rules produces FEWER findings, and fewer
54
+ * findings read as a healthier app. A crashing rule would quietly make things look better. That is
55
+ * the exact shape of a false green.
56
+ *
57
+ * The failure was already being reported -- to a log. Nothing that decides a verdict reads the log.
58
+ * So it is also recorded here, where the verdict path does read it, and a crashed rule becomes a
59
+ * blind spot: we did not see everything we were meant to see, so we do not claim a clean look.
60
+ */
61
+ export declare function runRegisteredFolds(events: readonly ReticleEvent[], options: ContradictionOptions): Contradiction[];
@@ -0,0 +1,71 @@
1
+ const FOLDS = [];
2
+ /**
3
+ * Add a rule to every verdict this engine produces. Returns the undo.
4
+ *
5
+ * The undo is not a convenience: without it a registry is process-global state that tests cannot
6
+ * clean up, so each one starts depending on the order it ran in.
7
+ */
8
+ export function registerContradictionFold(fold) {
9
+ FOLDS.push(fold);
10
+ return () => {
11
+ const at = FOLDS.indexOf(fold);
12
+ if (at !== -1)
13
+ FOLDS.splice(at, 1);
14
+ };
15
+ }
16
+ /** What is registered right now. Exported so a guard can assert the registry is empty by default. */
17
+ export function registeredContradictionFolds() {
18
+ return [...FOLDS];
19
+ }
20
+ /**
21
+ * Rules that have crashed, by the message they crashed with.
22
+ *
23
+ * Deliberately sticky and engine-wide rather than per-window. A rule that threw is still registered
24
+ * and still throwing, so every verdict after it really is being decided with fewer rules than the
25
+ * engine claims to have. Saying so once and then forgetting would be the less accurate answer.
26
+ *
27
+ * Keyed by message so a rule failing on every event reports one blind spot, not thousands.
28
+ */
29
+ const crashedRules = new Set();
30
+ /**
31
+ * What the engine can no longer see, in words meant for whoever reads the verdict.
32
+ *
33
+ * Empty is the normal case and the honest one: no rule has crashed, so nothing is missing.
34
+ */
35
+ export function crashedRuleNotes() {
36
+ return [...crashedRules].map((why) => `a consumer rule crashed, so findings may be missing: ${why}`);
37
+ }
38
+ /** Forget the crashes. For tests, which must not inherit the previous test's damage. */
39
+ export function clearCrashedRules() {
40
+ crashedRules.clear();
41
+ }
42
+ /**
43
+ * Run every registered rule, containing anything one of them throws.
44
+ *
45
+ * A registered fold is somebody else's code running inside every verdict path this package has. If a
46
+ * throw could propagate, one defect in a consumer's rule would take down `assert`, `act_and_wait`,
47
+ * `observe` and `crawl` at once — turning a missing finding into a dead engine. So it is contained.
48
+ *
49
+ * Containment on its own is not enough, and this is the part that took a while to see. This engine
50
+ * reports what is WRONG with an app, so running with fewer rules produces FEWER findings, and fewer
51
+ * findings read as a healthier app. A crashing rule would quietly make things look better. That is
52
+ * the exact shape of a false green.
53
+ *
54
+ * The failure was already being reported -- to a log. Nothing that decides a verdict reads the log.
55
+ * So it is also recorded here, where the verdict path does read it, and a crashed rule becomes a
56
+ * blind spot: we did not see everything we were meant to see, so we do not claim a clean look.
57
+ */
58
+ export function runRegisteredFolds(events, options) {
59
+ const found = [];
60
+ for (const fold of FOLDS) {
61
+ try {
62
+ found.push(...fold(events, options));
63
+ }
64
+ catch (error) {
65
+ const why = error instanceof Error ? error.message : String(error);
66
+ options.note?.('contradiction_fold_failed', { error: why });
67
+ crashedRules.add(why);
68
+ }
69
+ }
70
+ return found;
71
+ }
@@ -0,0 +1,164 @@
1
+ import type { Contradiction, ContradictionKind, ReticleEvent } from '@reticlehq/core';
2
+ import type { NoteFn } from '../window/engine-host.js';
3
+ import type { DeclaredNetFailure } from '../question/declared.js';
4
+ /**
5
+ * What a contradiction IS, separated from the rules that find one.
6
+ *
7
+ * A leaf. Five sibling rules name these shapes to declare their own signatures, and all five had to
8
+ * import them back out of `contradictions.ts` — the module that calls them. TypeScript erases those
9
+ * imports, so nothing was ever wrong at runtime; the cycle was real to every tool that reads imports,
10
+ * and it made the hunter look like the source of a vocabulary it only uses.
11
+ */
12
+ /**
13
+ * A contradiction emitted by one of THIS package's rules — the kind is closed.
14
+ *
15
+ * Widening `Contradiction.kind` to `string` for the consumer seam would otherwise have made every
16
+ * emit site below accept a typo'd literal. This keeps them checked without closing the edge.
17
+ */
18
+ export type { Contradiction };
19
+ export type OwnContradiction = Contradiction & {
20
+ kind: ContradictionKind;
21
+ };
22
+ export interface ContradictionOptions {
23
+ /**
24
+ * Somewhere to record a rule that threw while it ran. See engine-host.ts.
25
+ *
26
+ * Optional: leave it out and the crash is still collected and surfaced by `crashedRuleNotes`, it
27
+ * just is not written down anywhere else.
28
+ */
29
+ note?: NoteFn;
30
+ /** The action that opened this window, when one did. Enables the no-effect check. */
31
+ action?: string | undefined;
32
+ /**
33
+ * Was the page HIDDEN while this window was recorded? Stated by the caller, which knows.
34
+ *
35
+ * A backgrounded tab has its rAF clamped, and the DOM observer flushes on rAF, so real mutations
36
+ * are never emitted and the window looks silent when the app in fact rendered. Every
37
+ * absence-derived rule then reads that silence as a fault.
38
+ *
39
+ * It has to be STATED rather than inferred from the window: `page.health` is a heartbeat every few
40
+ * seconds and a crawl's per-control window is a few hundred milliseconds, so whether the marker
41
+ * lands inside it is luck. The daemon already tracks this per session and reports it as
42
+ * `throttled` on every tool response. Undefined means the caller cannot answer, and the guard stays
43
+ * inert rather than silencing findings on a page that was fine.
44
+ */
45
+ pageHidden?: boolean | undefined;
46
+ /**
47
+ * Events from BEFORE the window, used only to LEARN — never reported on. Some disagreements are
48
+ * with something the API stated earlier in the session, which an action-scoped window cannot
49
+ * contain. See `findUnitMismatches` for the measured case this exists for.
50
+ */
51
+ prior?: readonly ReticleEvent[] | undefined;
52
+ /**
53
+ * Event time at which the action that opened this window was dispatched — the attribution floor.
54
+ *
55
+ * `duplicate-request` claims "one user action was performed", and that claim is only sound over ONE
56
+ * action's window. `reticle_observe` takes a caller-supplied window that can be arbitrarily wide, so
57
+ * two legitimate separate saves to the same endpoint read as a double submit — and the finding then
58
+ * sat on every verdict for that tab. Undefined means nothing attributed the window to an action, and
59
+ * the rule stays silent rather than accusing an app of something nobody can show it did.
60
+ *
61
+ * ponytail: a NET_REQUEST is stamped when it COMPLETED, so a write dispatched before the action and
62
+ * landing after it counts as inside. Keying on the matching NET_PENDING would fix that; it has not
63
+ * been worth the second index.
64
+ */
65
+ actionSince?: number | undefined;
66
+ /**
67
+ * DOM mutations observed INSIDE the target's own subtree, as the act tool measured them.
68
+ *
69
+ * The no-effect check used to require a completely empty window, which is a statement about the
70
+ * PAGE rather than about the action — and no real app has a quiet page. Measured on a shipments
71
+ * console with a background event stream: clicking an inert heading produced `domMutatedWithin: 0`
72
+ * and four ambient events (a scroll position, an unrelated store update, a perf sample), so the
73
+ * window was not empty and the dead control went unreported. The user's framing of this is exact:
74
+ * the DOM moving after an action is not evidence that the action moved it.
75
+ *
76
+ * Undefined means the caller did not measure it — the check then falls back to the empty-window
77
+ * test, which is weaker but never wrong in the direction of a false accusation.
78
+ */
79
+ mutatedWithin?: number | undefined;
80
+ /**
81
+ * Requests the CALLER declared would fail, read off the oracle it wrote before acting.
82
+ *
83
+ * `ui-advanced-request-failed` cannot tell "the app swallowed the error and carried on" from "the
84
+ * app rendered the error, which is the behaviour under test" — both are a moved DOM beside a
85
+ * failed request. `failureAcknowledged` recovers the first from the app's own state, and an app
86
+ * that renders its error straight into the DOM without touching a store defeats it.
87
+ *
88
+ * The declaration is the missing evidence, and it costs no new API: an agent verifying an error
89
+ * path already writes `{ net, POST, /api/login, status: 500 }` into the predicate. Measured in the
90
+ * field: every branch of a login error path (500, 401, 503) passed every declared clause and every
91
+ * run still returned `verified: "no" / contradicted`, so error handling — empty states, offline
92
+ * banners, 4xx/5xx messaging, lockouts — was the code least able to reach a green verdict and the
93
+ * most worth verifying.
94
+ *
95
+ * Scoped as narrowly as it can be: it suppresses ONLY the heuristic rule that cannot see the
96
+ * difference. A success signal fired over the declared failure still contradicts, and a server
97
+ * fault blamed on the user is still misattributed — see the negative controls in
98
+ * `contradictions.declared.test.ts`.
99
+ */
100
+ expectedFailures?: readonly DeclaredNetFailure[] | undefined;
101
+ /**
102
+ * The caller declared an on-screen consequence and it HELD in this window.
103
+ *
104
+ * `route-rendered-nothing` infers a blank destination from the absence of DOM events, and a
105
+ * verdict that names it beside an element match — heading found, with its source file and line —
106
+ * is a clause its own evidence disproves. Positive evidence outranks the absence it is inferred
107
+ * from. Undefined/false leaves the rule exactly as it was, which is the case that catches a route
108
+ * with no view.
109
+ */
110
+ renderProved?: boolean | undefined;
111
+ /**
112
+ * The document currently under observation, as the session derived it from its own event stream.
113
+ *
114
+ * Every rule below reasons about "the same window", and a window is scoped by time and by
115
+ * ring-buffer capacity and by nothing else — so it can still hold the traffic of a page a full
116
+ * navigation or a reload has already thrown away. Naming that traffic as the cause of an action
117
+ * taken now is true about the bytes and false about the world.
118
+ *
119
+ * Undefined means nobody could say which document is current (an SDK too old to stamp one, a caller
120
+ * with no session in hand), and the scoping then does nothing at all — `isSameDocument` treats
121
+ * absence as current on both sides, so the engine behaves exactly as it did before this existed.
122
+ */
123
+ currentDocumentId?: string | undefined;
124
+ /**
125
+ * The edit epoch currently in force, as the session derived it from its own event stream.
126
+ *
127
+ * The edit-shaped half of `currentDocumentId`. A hot update replaces modules and re-renders inside
128
+ * the SAME document, so the document id cannot see it and observations of code the agent has
129
+ * already rewritten go on answering for it in silence.
130
+ *
131
+ * Undefined means nobody could say (an SDK too old to stamp one, a page with no hot-update channel,
132
+ * a caller with no session in hand) and the scoping then does nothing at all — `isSameEditEpoch`
133
+ * treats absence as current on both sides.
134
+ */
135
+ currentEditEpoch?: number | undefined;
136
+ /**
137
+ * The page under test, as the session last recorded it — the app's own origin, in URL form.
138
+ *
139
+ * The first-party/third-party axis. Every rule below asks "did the app disagree with itself", and
140
+ * a failed analytics beacon is not the app: reported independently from several apps, any
141
+ * analytics package installed was enough to grade a correct drive `contradicted`, and on one app
142
+ * EVERY assertion came back that way forever, because it fires a branding call on page load. A
143
+ * verdict field that answers "no" to everything has stopped being a verdict field.
144
+ *
145
+ * Third-party traffic is dropped here rather than reported at a lower severity, for the reason the
146
+ * dev-tooling split is: the rules below would each have to learn to say it. The exclusion is never
147
+ * silent — the URLs ride out in the same disclosure line the toolchain's do — and the calls
148
+ * themselves are untouched in `reticle_network` and the event timeline.
149
+ *
150
+ * Undefined disables the axis, exactly as an undefined `currentDocumentId` disables the document
151
+ * one: a caller that cannot say which page is under test gets the behaviour it had before this.
152
+ */
153
+ appOrigin?: string | undefined;
154
+ /**
155
+ * The traffic the assertion actually named — `urlContains` from each net clause, `''` for a clause
156
+ * that named the whole channel.
157
+ *
158
+ * Used only by `duplicate-request`, to tell "the write you asked about fired twice" from "some
159
+ * other endpoint is busy". Undefined disables the split and every duplicate is reported as it was
160
+ * before, which is what a caller with no predicate (a bare `observe`) should get: with nothing
161
+ * declared, nothing is unrelated.
162
+ */
163
+ namedNetUrls?: readonly string[] | undefined;
164
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,5 @@
1
+ import { type ReticleEvent } from '@reticlehq/core';
2
+ import type { Contradiction, ContradictionOptions } from './contradiction-types.js';
3
+ export type { Contradiction, OwnContradiction, ContradictionOptions, } from './contradiction-types.js';
4
+ /** Net-shaped events — the only ones that carry a URL a dev-tooling channel could occupy. */
5
+ export declare function findContradictions(allEvents: readonly ReticleEvent[], options?: ContradictionOptions): Contradiction[];