@reticlehq/engine 3.2.0 → 3.4.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 (45) hide show
  1. package/NOTICE +5 -0
  2. package/dist/disagreement/body-failures.js +32 -12
  3. package/dist/disagreement/contradiction-evidence.d.ts +1 -1
  4. package/dist/disagreement/contradiction-evidence.js +3 -3
  5. package/dist/disagreement/contradiction-types.d.ts +6 -0
  6. package/dist/disagreement/contradictions.js +24 -30
  7. package/dist/disagreement/echo-mismatch.js +16 -0
  8. package/dist/evidence/already-true.js +14 -3
  9. package/dist/evidence/baseline.d.ts +21 -0
  10. package/dist/evidence/baseline.js +129 -0
  11. package/dist/evidence/instrumentation-gaps.js +8 -2
  12. package/dist/evidence/unsettled.js +7 -1
  13. package/dist/evidence/verified.d.ts +7 -0
  14. package/dist/evidence/verified.js +35 -1
  15. package/dist/question/declared.js +11 -2
  16. package/dist/question/lineage.d.ts +14 -5
  17. package/dist/question/lineage.js +65 -10
  18. package/dist/question/predicate/predicate-asks.js +7 -1
  19. package/dist/question/predicate/predicate-compare.d.ts +18 -0
  20. package/dist/question/predicate/predicate-compare.js +226 -0
  21. package/dist/question/predicate/predicate-element.d.ts +5 -2
  22. package/dist/question/predicate/predicate-element.js +122 -8
  23. package/dist/question/predicate/predicate-eval-kit.d.ts +43 -2
  24. package/dist/question/predicate/predicate-eval-kit.js +107 -14
  25. package/dist/question/predicate/predicate-eval.d.ts +6 -0
  26. package/dist/question/predicate/predicate-eval.js +60 -13
  27. package/dist/question/predicate/predicate-parse.js +1 -0
  28. package/dist/question/predicate/predicate-precheck.js +3 -5
  29. package/dist/question/predicate/predicate-request-body.d.ts +1 -1
  30. package/dist/question/predicate/predicate-request-body.js +7 -3
  31. package/dist/question/predicate/predicate-route.d.ts +2 -1
  32. package/dist/question/predicate/predicate-schema.d.ts +14 -93
  33. package/dist/question/predicate/predicate-schema.js +33 -288
  34. package/dist/question/predicate/predicate-session.d.ts +20 -1
  35. package/dist/question/predicate/predicate-session.js +25 -1
  36. package/dist/question/predicate/predicate-state.d.ts +15 -0
  37. package/dist/question/predicate/predicate-state.js +317 -0
  38. package/dist/question/predicate/predicate-to-links.js +3 -1
  39. package/dist/question/predicate/predicate.d.ts +17 -3
  40. package/dist/question/predicate/predicate.js +200 -336
  41. package/dist/question/predicate/property.d.ts +24 -73
  42. package/dist/question/predicate/property.js +134 -20
  43. package/dist/window/json-salvage.d.ts +2 -1
  44. package/dist/window/json-salvage.js +2 -1
  45. package/package.json +5 -6
package/NOTICE ADDED
@@ -0,0 +1,5 @@
1
+ Reticle
2
+ Copyright 2026 Reticle Labs
3
+
4
+ This product includes software developed at Reticle Labs.
5
+ Licensed under the Apache License, Version 2.0.
@@ -27,6 +27,36 @@ const ITEM_KEYS = ['results', 'items', 'data', 'records', 'responses'];
27
27
  function isRecord(value) {
28
28
  return 'object' === typeof value && value !== null && !Array.isArray(value);
29
29
  }
30
+ /**
31
+ * Whether the value under an error key carries an actual error.
32
+ *
33
+ * An API that always sends its error slot and leaves it EMPTY is saying the opposite of a failure,
34
+ * and every empty shape below was being read as one — because the test was the key's PRESENCE, with
35
+ * `[]` and `''` carved out by hand and nothing else. Reported from the field on a 200 whose error
36
+ * container was empty: `verified: "no"`, "its body reports the operation FAILED", nothing in the
37
+ * body reporting anything of the kind.
38
+ *
39
+ * `false` and `0` are the two that look like judgement calls and are not. `{"error": false}` is the
40
+ * envelope flag for "there was none" — the exact dual of the `ok`/`success` flags read above — and
41
+ * an errno-style `{"error": 0}` spells the same thing; under the plural key, `{"errors": 0}` is a
42
+ * count of none. Each says "none" in both available readings, and the non-empty side of each is
43
+ * untouched: a populated map, a non-zero code, `error: true` and a real message all still report.
44
+ */
45
+ function carriesError(value) {
46
+ if (value === undefined || null === value)
47
+ return false;
48
+ if (Array.isArray(value))
49
+ return value.length > 0;
50
+ if ('string' === typeof value)
51
+ return value.trim().length > 0;
52
+ if ('boolean' === typeof value)
53
+ return value;
54
+ if ('number' === typeof value)
55
+ return 0 !== value;
56
+ if (isRecord(value))
57
+ return Object.keys(value).length > 0;
58
+ return true;
59
+ }
30
60
  /** Whether one object reports a failure of its own. */
31
61
  function reportsFailure(item) {
32
62
  if (!isRecord(item))
@@ -36,18 +66,8 @@ function reportsFailure(item) {
36
66
  return true;
37
67
  }
38
68
  for (const key of ERROR_KEYS) {
39
- const value = item[key];
40
- if (value === undefined || null === value)
41
- continue;
42
- if (Array.isArray(value)) {
43
- if (value.length > 0)
44
- return true;
45
- continue;
46
- }
47
- // An empty string or an explicit null is an API saying "no error", not an error.
48
- if ('string' === typeof value && 0 === value.length)
49
- continue;
50
- return true;
69
+ if (carriesError(item[key]))
70
+ return true;
51
71
  }
52
72
  return false;
53
73
  }
@@ -76,7 +76,7 @@ export declare function isSameDocumentHashAnchor(event: ReticleEvent): boolean;
76
76
  * every action. The overlay's own 404s and duplicate fetches are the same story on other checks,
77
77
  * which is why the split happens ONCE here rather than in the one check that reported it.
78
78
  */
79
- export declare function splitForeignTraffic(events: readonly ReticleEvent[], appOrigin: string | undefined): {
79
+ export declare function splitForeignTraffic(events: readonly ReticleEvent[], appOrigin: string | undefined, background?: readonly string[]): {
80
80
  app: readonly ReticleEvent[];
81
81
  ignored: string[];
82
82
  };
@@ -11,7 +11,7 @@
11
11
  * new rule cannot quietly redefine what "in flight" or "ours" means for itself, which is how two
12
12
  * rules end up disagreeing about the same window.
13
13
  */
14
- import { EventType, MUTATING_METHODS, asNumber, asString, isDevToolingUrl, isThirdPartyUrl, urlForMatch, } from '@reticlehq/core';
14
+ import { EventType, MUTATING_METHODS, asNumber, asString, isDevToolingUrl, isForeignTraffic, urlForMatch, } from '@reticlehq/core';
15
15
  export function netCall(e) {
16
16
  const status = asNumber(e.data['status']);
17
17
  return {
@@ -124,7 +124,7 @@ export function isSameDocumentHashAnchor(event) {
124
124
  * every action. The overlay's own 404s and duplicate fetches are the same story on other checks,
125
125
  * which is why the split happens ONCE here rather than in the one check that reported it.
126
126
  */
127
- export function splitForeignTraffic(events, appOrigin) {
127
+ export function splitForeignTraffic(events, appOrigin, background = []) {
128
128
  const ignored = [];
129
129
  const app = events.filter((e) => {
130
130
  if (!NET_TYPES.has(e.type))
@@ -132,7 +132,7 @@ export function splitForeignTraffic(events, appOrigin) {
132
132
  const url = asString(e.data['url']);
133
133
  // Somebody else's code, twice over: the toolchain's own channel, and any site that is not the
134
134
  // app under test. Neither can answer the question every rule below asks.
135
- if (!isDevToolingUrl(url) && !isThirdPartyUrl(url, appOrigin))
135
+ if (!isDevToolingUrl(url) && !isForeignTraffic(url, appOrigin, background))
136
136
  return true;
137
137
  if (url !== undefined && !ignored.includes(url))
138
138
  ignored.push(url);
@@ -151,6 +151,12 @@ export interface ContradictionOptions {
151
151
  * one: a caller that cannot say which page is under test gets the behaviour it had before this.
152
152
  */
153
153
  appOrigin?: string | undefined;
154
+ /**
155
+ * Same-origin endpoints the project declared the app fires on its own (`.reticle.json`
156
+ * `background`). Dropped with the third-party traffic and disclosed the same way; empty or
157
+ * undefined excludes nothing, because same-origin traffic is never guessed at.
158
+ */
159
+ background?: readonly string[] | undefined;
154
160
  /**
155
161
  * The traffic the assertion actually named — `urlContains` from each net clause, `''` for a clause
156
162
  * that named the whole channel.
@@ -1,4 +1,4 @@
1
- import { ContradictionKind, EventType, REQUEST_SHAPE_FIELD, isAbsenceDerived, isSameDocument, isSameEditEpoch, } from '@reticlehq/core';
1
+ import { ContradictionKind, EventType, NEXT_ACTION_FIELD, REQUEST_SHAPE_FIELD, isAbsenceDerived, isSameDocument, isSameEditEpoch, } from '@reticlehq/core';
2
2
  import { describeSuperseded } from '../question/predicate/observed-in-window.js';
3
3
  import { describe, isMutating, isSameDocumentHashAnchor, isSteadyCadence, netCall, recoveredByRetry, splitForeignTraffic, } from './contradiction-evidence.js';
4
4
  import { findStaleResponses } from './stale-response.js';
@@ -8,40 +8,28 @@ import { findUnitMismatches } from './unit-mismatch.js';
8
8
  import { asString } from '@reticlehq/core';
9
9
  import { matchesDeclaredFailure } from '../question/declared.js';
10
10
  import { runRegisteredFolds } from './contradiction-folds.js';
11
- /**
12
- * The contradiction hunter.
13
- *
14
- * Every other check reads ONE channel and asks "did something bad happen there?". This asks what a
15
- * person watching the screen structurally cannot: do the channels DISAGREE? The DOM, the store, the
16
- * app's own signals, the console and the network arrive in one causally ordered window, so the case
17
- * where the screen says one thing and the network says the opposite is visible — and that gap is
18
- * where false greens live, because a screenshot, a DOM assertion and a human all agree there.
19
- *
20
- * Pure: a window of events in, findings out. No session, no IO, no clock.
21
- */
22
- /**
23
- * What this request CARRIED, as far as the record knows — `undefined` when it does not know.
24
- *
25
- * The page's shape fingerprint first: it is present on every request from an instrumented page,
26
- * including the overwhelming majority where body capture is off. A captured body is the fallback for
27
- * a realm that records one without a fingerprint (desktop IPC). Neither means the record does not
28
- * say what this request carried — a body the page could not read as text, or an SDK too old to
29
- * compute a fingerprint — and that is an ABSENCE of identity, not an identity shared with every
30
- * other silent request.
31
- */
32
11
  function identityOf(event) {
12
+ const action = asString(event.data[NEXT_ACTION_FIELD]);
33
13
  const shape = asString(event.data[REQUEST_SHAPE_FIELD]);
34
- if (shape !== undefined && 0 !== shape.length)
35
- return shape;
36
14
  const body = asString(event.data['requestBody']);
37
- return body === undefined || 0 === body.length ? undefined : body;
15
+ const carried = shape !== undefined && 0 !== shape.length
16
+ ? shape
17
+ : body === undefined || 0 === body.length
18
+ ? undefined
19
+ : body;
20
+ if (action === undefined || 0 === action.length) {
21
+ return carried === undefined ? undefined : { key: carried, carried: true };
22
+ }
23
+ return carried === undefined
24
+ ? { key: action, carried: false }
25
+ : { key: `${action}:${carried}`, carried: true };
38
26
  }
39
27
  /** Split calls to one endpoint into the sets that sent the same thing. Callers check first that
40
28
  * every identity is known; an unknown one would otherwise pool with every other unknown. */
41
29
  function groupByIdentity(calls) {
42
30
  const byIdentity = new Map();
43
31
  for (const call of calls) {
44
- const key = call.identity ?? '';
32
+ const key = call.identity?.key ?? '';
45
33
  byIdentity.set(key, [...(byIdentity.get(key) ?? []), call]);
46
34
  }
47
35
  return [...byIdentity.values()];
@@ -193,7 +181,7 @@ export function findContradictions(allEvents, options = {}) {
193
181
  }
194
182
  function findWindowContradictions(allEvents, options) {
195
183
  const found = [];
196
- const { app: allApp, ignored: ignoredForeign } = splitForeignTraffic(allEvents, options.appOrigin);
184
+ const { app: allApp, ignored: ignoredForeign } = splitForeignTraffic(allEvents, options.appOrigin, options.background);
197
185
  // ── Evidence belonging to a document that has since been replaced ───────────────────────────
198
186
  // Scoped ONCE, here, for the same reason the dev-tooling split is: every rule below asks "what
199
187
  // else was in this window", and answering that with a dead page's traffic is a defect in all of
@@ -589,6 +577,10 @@ function findWindowContradictions(allEvents, options) {
589
577
  const landed = group.filter((c) => c.landed).length;
590
578
  if (times.length < 2)
591
579
  continue;
580
+ // The identity also has to say WHICH PAYLOAD, not only which action ran. A group held
581
+ // together by an action id over bodies the record could not read keeps the uncertainty in
582
+ // its wording: two runs of one action can carry different form data.
583
+ const carriedKnown = group.every((c) => true === c.identity?.carried);
592
584
  // A DOUBLE SUBMIT is a write that landed twice. Two attempts of which one failed is a RETRY,
593
585
  // and the field case is the commonest retry there is: a 401 that refreshed a token and went
594
586
  // again, one row created, reported here as `duplicate-request ×2`. Two attempts that both
@@ -616,10 +608,10 @@ function findWindowContradictions(allEvents, options) {
616
608
  claim: related
617
609
  ? 'one user action was performed'
618
610
  : 'the assertion did not name this endpoint',
619
- counter: identified
611
+ counter: carriedKnown
620
612
  ? `the same write fired ${count} times`
621
613
  : `this endpoint was written to ${count} times`,
622
- detail: identified
614
+ detail: carriedKnown
623
615
  ? `${label} ×${count}`
624
616
  : `${label} ×${count} — nothing on the record says what these requests carried, ` +
625
617
  'so whether they were one write repeated or different writes could not be established',
@@ -651,7 +643,9 @@ function findWindowContradictions(allEvents, options) {
651
643
  inFlight.map((p) => describe(p.call)).join('; '),
652
644
  ...(0 === ignoredForeign.length
653
645
  ? []
654
- : [`ignored as dev tooling or third-party: ${ignoredForeign.join(', ')}`]),
646
+ : [
647
+ `ignored as dev tooling, third-party or declared background: ${ignoredForeign.join(', ')}`,
648
+ ]),
655
649
  ].join(' — '),
656
650
  });
657
651
  }
@@ -91,6 +91,20 @@ function isIdentityKey(key) {
91
91
  const lower = key.toLowerCase();
92
92
  return 'id' === lower || lower.endsWith('_id');
93
93
  }
94
+ /**
95
+ * Keys that name an optimistic-concurrency token, not a persisted attribute. A compare-and-set
96
+ * write sends the version it read and expects the server to bump it — the changed value in the
97
+ * response is the proof the write applied, not evidence the write was ignored, the same way a
98
+ * create's assigned `id` is not a dropped field.
99
+ */
100
+ function isVersionKey(key) {
101
+ const lower = key.toLowerCase();
102
+ return ('version' === lower ||
103
+ '_version' === lower ||
104
+ 'etag' === lower ||
105
+ 'rev' === lower ||
106
+ 'revision' === lower);
107
+ }
94
108
  /**
95
109
  * Every scalar value the response carries for each key, at any depth.
96
110
  *
@@ -273,6 +287,8 @@ export function findEchoMismatches(events, actionSince) {
273
287
  continue;
274
288
  if (isIdentityKey(key))
275
289
  continue;
290
+ if (isVersionKey(key))
291
+ continue;
276
292
  const values = echoed.get(key);
277
293
  // Not echoed at all = no evidence either way. Only a key the server chose to report back can
278
294
  // contradict the request, and silence is not a contradiction.
@@ -16,7 +16,8 @@
16
16
  * So these are the kinds worth evaluating BEFORE the act, to find out whether the green means
17
17
  * anything.
18
18
  */
19
- import { PredicateKind } from '@reticlehq/core';
19
+ import { PredicateKind, compareSourceClauses } from '@reticlehq/core';
20
+ import { asksForComparison } from './baseline.js';
20
21
  export function readsDomState(predicate) {
21
22
  switch (predicate.kind) {
22
23
  // ROUTE is here, and it did not used to be. It was purely event-based — satisfiable only by a
@@ -38,16 +39,26 @@ export function readsDomState(predicate) {
38
39
  // rather than through the floored event buffer. If the store already holds the expected value
39
40
  // before dispatch, an inert click would immediately pass post-dispatch on the pre-existing state.
40
41
  // Evaluating before dispatch routes that pre-existing condition into already_true.
41
- case PredicateKind.ELEMENT:
42
+ //
43
+ // A RELATIVE property is the one exception, and it is excluded by construction rather than by
44
+ // taste: `unchanged` compares this reading with the one taken a microsecond ago and is
45
+ // therefore always true before the action. Pre-checking it would report `already_true` — and
46
+ // so UNKNOWN — for the assertion whose whole purpose is that the value survives what follows.
42
47
  case PredicateKind.TEXT:
43
- case PredicateKind.ROUTE:
44
48
  case PredicateKind.STATE:
49
+ return !asksForComparison(predicate);
50
+ case PredicateKind.ELEMENT:
51
+ case PredicateKind.ROUTE:
45
52
  return true;
46
53
  case PredicateKind.ALL_OF:
47
54
  case PredicateKind.ANY_OF:
48
55
  return predicate.predicates.some(readsDomState);
49
56
  case PredicateKind.NOT:
50
57
  return readsDomState(predicate.predicate);
58
+ // A comparison between two LIVE readings (text, a store) can already agree before the click, and
59
+ // then it proves nothing about the click. A `net` or `signal` side is floored like any other.
60
+ case PredicateKind.COMPARE:
61
+ return compareSourceClauses(predicate).some(readsDomState);
51
62
  default:
52
63
  return false;
53
64
  }
@@ -0,0 +1,21 @@
1
+ import type { Predicate } from '../question/predicate/predicate.js';
2
+ import type { Baseline } from '../question/predicate/property.js';
3
+ import type { PredicateSession } from '../question/predicate/predicate-session.js';
4
+ /**
5
+ * Does this leaf's claim compare two readings?
6
+ *
7
+ * Exported because `readsDomState` has to exclude exactly these. A relative property is NEVER
8
+ * answerable before the action — `unchanged` is trivially true against a baseline taken a
9
+ * microsecond earlier — so pre-checking one would report `already_true` for the assertion whose
10
+ * entire purpose is that the value survives what comes next, and turn its verdict into UNKNOWN.
11
+ */
12
+ export declare function asksForComparison(predicate: Predicate): boolean;
13
+ /** Does the whole tree need a pre-action reading at all? One walk, so the caller pays nothing. */
14
+ export declare function needsBaseline(predicate: Predicate | undefined): boolean;
15
+ /**
16
+ * Read what every comparing leaf needs, once, before the action.
17
+ *
18
+ * Keyed by the predicate OBJECT: the same parsed tree is evaluated before and after, so identity
19
+ * is exact and no path or index has to be kept in step with the walk.
20
+ */
21
+ export declare function captureBaselines(session: PredicateSession, predicate: Predicate | undefined): Promise<ReadonlyMap<Predicate, Baseline>>;
@@ -0,0 +1,129 @@
1
+ /**
2
+ * The reading taken BEFORE the action, so a predicate can talk about the past.
3
+ *
4
+ * Every leaf in the grammar read the present tense — the DOM now, the store now, the events since a
5
+ * cursor — so the assertions that catch money bugs could not be written: the balance went down by
6
+ * what was charged, the list gained three rows, this field held its value across the re-render.
7
+ *
8
+ * Nothing new is observed to make them writable. `already-true` was already taking a pre-action
9
+ * reading and throwing it away one function short of being this feature; the only change is that a
10
+ * leaf which asked for a comparison gets its own value kept.
11
+ *
12
+ * Deliberately just "before this action" — the window every verdict is already scoped to — and not
13
+ * arbitrary named checkpoints. A `snapshot("cart")` / `compare("cart")` pair is a different feature
14
+ * and has no evidence behind it.
15
+ */
16
+ import { PredicateKind, ReticleCommand } from '@reticlehq/core';
17
+ /** The properties that mean nothing without a before-reading. Mirrors `RELATIVE` in property.ts. */
18
+ const NEEDS_BASELINE = new Set([
19
+ 'changed',
20
+ 'unchanged',
21
+ 'increased',
22
+ 'decreased',
23
+ ]);
24
+ /**
25
+ * Does this leaf's claim compare two readings?
26
+ *
27
+ * Exported because `readsDomState` has to exclude exactly these. A relative property is NEVER
28
+ * answerable before the action — `unchanged` is trivially true against a baseline taken a
29
+ * microsecond earlier — so pre-checking one would report `already_true` for the assertion whose
30
+ * entire purpose is that the value survives what comes next, and turn its verdict into UNKNOWN.
31
+ */
32
+ export function asksForComparison(predicate) {
33
+ if (PredicateKind.STATE === predicate.kind || PredicateKind.TEXT === predicate.kind) {
34
+ return predicate.satisfies !== undefined && NEEDS_BASELINE.has(predicate.satisfies.property);
35
+ }
36
+ return false;
37
+ }
38
+ /** Every leaf that asked for a comparison, composites included. */
39
+ function leavesNeedingBaseline(predicate, into) {
40
+ switch (predicate.kind) {
41
+ case PredicateKind.ALL_OF:
42
+ case PredicateKind.ANY_OF:
43
+ for (const part of predicate.predicates)
44
+ leavesNeedingBaseline(part, into);
45
+ return;
46
+ case PredicateKind.NOT:
47
+ leavesNeedingBaseline(predicate.predicate, into);
48
+ return;
49
+ default:
50
+ if (asksForComparison(predicate))
51
+ into.push(predicate);
52
+ }
53
+ }
54
+ /** Does the whole tree need a pre-action reading at all? One walk, so the caller pays nothing. */
55
+ export function needsBaseline(predicate) {
56
+ if (predicate === undefined)
57
+ return false;
58
+ const found = [];
59
+ leavesNeedingBaseline(predicate, found);
60
+ return found.length > 0;
61
+ }
62
+ async function readStateValue(session, predicate) {
63
+ const args = predicate.store === undefined
64
+ ? { path: predicate.path }
65
+ : { store: predicate.store, path: predicate.path };
66
+ const read = await session.command(ReticleCommand.STATE_READ, args);
67
+ if (!read.ok)
68
+ return undefined;
69
+ const reply = (read.result ?? {});
70
+ // `found: false` is a reading — the path held nothing — and it is NOT the same as "nobody
71
+ // looked". Only an unreadable store returns undefined above.
72
+ return 'boolean' === typeof reply.found ? { taken: true, value: reply.value } : undefined;
73
+ }
74
+ async function readText(session, predicate) {
75
+ const query = {
76
+ ...(predicate.contains === undefined ? {} : { text: predicate.contains }),
77
+ ...(predicate.scope === undefined
78
+ ? {}
79
+ : { scope: predicate.scope, ...(true === predicate.self ? { self: true } : {}) }),
80
+ };
81
+ const match = await session.command(ReticleCommand.MATCH, { query });
82
+ if (!match.ok)
83
+ return undefined;
84
+ const elements = (match.result ?? {}).elements;
85
+ if (!Array.isArray(elements))
86
+ return undefined;
87
+ const text = elements
88
+ .map((element) => {
89
+ if ('object' !== typeof element || null === element)
90
+ return '';
91
+ const value = element.text;
92
+ return 'string' === typeof value ? value : '';
93
+ })
94
+ .join(' ')
95
+ .trim();
96
+ // An empty page is a reading of "": the element was not there, and that is what a later
97
+ // `changed` is comparing against. Refusing here would turn "it appeared" into "nobody looked".
98
+ return { taken: true, value: text };
99
+ }
100
+ /**
101
+ * Read what every comparing leaf needs, once, before the action.
102
+ *
103
+ * Keyed by the predicate OBJECT: the same parsed tree is evaluated before and after, so identity
104
+ * is exact and no path or index has to be kept in step with the walk.
105
+ */
106
+ export async function captureBaselines(session, predicate) {
107
+ const captured = new Map();
108
+ if (predicate === undefined)
109
+ return captured;
110
+ const leaves = [];
111
+ leavesNeedingBaseline(predicate, leaves);
112
+ for (const leaf of leaves) {
113
+ try {
114
+ const reading = PredicateKind.STATE === leaf.kind
115
+ ? await readStateValue(session, leaf)
116
+ : PredicateKind.TEXT === leaf.kind
117
+ ? await readText(session, leaf)
118
+ : undefined;
119
+ if (reading !== undefined)
120
+ captured.set(leaf, reading);
121
+ }
122
+ catch {
123
+ // A reading that could not be taken leaves the leaf with no baseline, which the evaluator
124
+ // reports as `inconclusive`. Throwing here would lose the whole verdict for one unreadable
125
+ // store — and an unevaluated clause is already the honest answer for exactly this.
126
+ }
127
+ }
128
+ return captured;
129
+ }
@@ -47,11 +47,17 @@ export function gapsForAction(facts) {
47
47
  // assertion about state to an agent that made no such assertion is a false explanation, and a
48
48
  // gap nobody can act on is worse than no gap: it costs the trip and teaches the wrong lesson.
49
49
  const declaredNothing = false === facts.hasCapabilities;
50
+ // `stateUnwatched` means no SUBSCRIBABLE store, not no store (#1146). A bare getter —
51
+ // `registerStore('app', () => state)` — is registered and readable, and a `state` assertion is
52
+ // answered by reading it on demand, so "no store is registered" contradicted a passing verdict
53
+ // in the same response. Nothing here can tell that app from one that registered nothing, or from
54
+ // a React app whose only store is Reticle's own `__reticle_renders` getter, so the sentence says
55
+ // only what is true of all three.
50
56
  gaps.push(instrumentationGap(InstrumentationGapKind.NO_STORE_REGISTERED, declaredNothing
51
57
  ? 'this app declared no capabilities at all, so no state can be read from it'
52
- : 'no store is registered, and this assertion was about state', declaredNothing
58
+ : 'no subscribable store is registered, and this assertion was about state', declaredNothing
53
59
  ? 'every verdict here rests on what the DOM happens to show, and reticle_state will stay empty however many flows are driven'
54
- : 'the assertion could not be answered from the deterministic channel and had to fall back to what the DOM happens to show'));
60
+ : 'no state change is observed, so state, when it can be read at all, is read only as it stands and never seen changing'));
55
61
  }
56
62
  // The app moved and said nothing, and Reticle could not prove the outcome another way.
57
63
  if (facts.domMutated && 0 === facts.signalsFired && true !== facts.proved) {
@@ -15,7 +15,7 @@
15
15
  * It rides in `because`, beside `verifiedReason`, rather than in a field of its own: the verdict has
16
16
  * one sentence an agent is known to read, and a caveat parked anywhere else is a caveat nobody reads.
17
17
  */
18
- import { PredicateKind } from '@reticlehq/core';
18
+ import { PredicateKind, compareSourceClauses } from '@reticlehq/core';
19
19
  /** Enough to recognise the one that is stuck; not so many that a chatty window eats the verdict. */
20
20
  const MAX_LISTED_REQUESTS = 3;
21
21
  /**
@@ -44,6 +44,8 @@ export function describeWaitTarget(predicate) {
44
44
  return 'a console message';
45
45
  case PredicateKind.ANIMATION:
46
46
  return predicate.name === undefined ? 'an animation' : `animation '${predicate.name}'`;
47
+ case PredicateKind.COMPARE:
48
+ return `${predicate.left.from} and ${predicate.right.from} readings to agree`;
47
49
  case PredicateKind.ALL_OF:
48
50
  return `all of (${predicate.predicates.map(describeWaitTarget).join('; ')})`;
49
51
  case PredicateKind.ANY_OF:
@@ -71,6 +73,10 @@ export function namedNetIsInFlight(predicate, stillInFlight) {
71
73
  for (const child of p.predicates)
72
74
  walk(child);
73
75
  return;
76
+ case PredicateKind.COMPARE:
77
+ for (const child of compareSourceClauses(p))
78
+ walk(child);
79
+ return;
74
80
  case PredicateKind.NET: {
75
81
  if (undefined === p.urlContains || 0 === p.urlContains.length)
76
82
  return;
@@ -2,6 +2,13 @@ import { type ChannelId, Verified, VerifiedReason } from '@reticlehq/core';
2
2
  import { type HonestyBlock } from './honesty.js';
3
3
  import { type UnsettledWindow } from './unsettled.js';
4
4
  interface VerifiedInputs {
5
+ /**
6
+ * The page SDK and daemon wire mismatch, when the handshake found one. Absent means they agree.
7
+ *
8
+ * Carried rather than re-derived: only the bridge sees both halves of the handshake, and a verdict
9
+ * that re-guessed it from versions would disagree with the warning the session already printed.
10
+ */
11
+ versionSkew?: string;
5
12
  /** Did the declared consequence hold? Undefined when the action declared none. */
6
13
  pass?: boolean;
7
14
  /**
@@ -31,7 +31,24 @@ function undeclaredChannels(inputs) {
31
31
  }
32
32
  export function decideVerified(inputs) {
33
33
  const { pass, honesty, contradictions = [], settled, outcomePending, outcomeUnread } = inputs;
34
- // FIRST, ahead of every other clause. A claim that needed to read something nobody was watching
34
+ // Ahead of everything, with `capability-absent` below it and for the same reason: a skewed wire
35
+ // means the ACTION may never have happened, so grading the quality of an observation of it is
36
+ // grading nothing. `session-health` already ranks skew above the throttle warning on this
37
+ // argument; this is the verdict finally agreeing with the warning it was printing beside.
38
+ //
39
+ // UNKNOWN, not NO. Nothing about the app was disproved -- the link under the evidence is what is
40
+ // in doubt. An empty string is not a skew.
41
+ const skew = inputs.versionSkew;
42
+ if (skew !== undefined && skew.length > 0) {
43
+ return {
44
+ verified: Verified.UNKNOWN,
45
+ verifiedReason: VerifiedReason.VERSION_SKEW,
46
+ because: `the page SDK and this daemon are on different wire contracts (${skew}), so dispatched ` +
47
+ 'and settled may be silent no-ops — nothing was proved or disproved about the app. ' +
48
+ 'Converge the versions and re-run',
49
+ };
50
+ }
51
+ // FIRST among the evidence clauses. A claim that needed to read something nobody was watching
35
52
  // was never answerable, and any clause reaching a verdict before this one would report that as
36
53
  // something else -- most often as a failure, which blames the app for a gap in the tooling.
37
54
  const unobservable = undeclaredChannels(inputs);
@@ -207,6 +224,23 @@ export function decideVerified(inputs) {
207
224
  'the store holds) before trusting it',
208
225
  };
209
226
  }
227
+ // `route-rendered-nothing` gets its own sentence for the same reason: the generic one blames churn
228
+ // and a slow app, and here nothing was busy - the URL moved and no view appeared for it. Driven on
229
+ // bench-app with a store that ignored the navigation: the route predicate held, this fired, and the
230
+ // generic sentence sent the reader to wait. UNKNOWN rather than NO because a view revealed from DOM
231
+ // that already existed (a CSS-toggled tab) emits this same window.
232
+ const routeOnly = deciding.length > 0 &&
233
+ deciding.every((c) => c.kind === ContradictionKind.ROUTE_RENDERED_NOTHING);
234
+ if (routeOnly) {
235
+ return {
236
+ verified: Verified.UNKNOWN,
237
+ verifiedReason: VerifiedReason.EVIDENCE_INCOMPLETE,
238
+ because: 'the URL changed, but nothing rendered for it: no content added or removed and no request ' +
239
+ 'made, so the new route may show the old view. A route change alone does not prove the ' +
240
+ 'destination appeared. Assert what the destination shows (its heading or a testid) or the ' +
241
+ 'store value that selects it, rather than the URL',
242
+ };
243
+ }
210
244
  if (deciding.length > 0 && !settlementOnly) {
211
245
  const kinds = deciding.map((c) => c.kind).join(', ');
212
246
  return {
@@ -17,7 +17,7 @@
17
17
  * opposite of a consequence — honouring either would suppress a real finding on the strength of
18
18
  * something that never happened. Pure: a predicate in, a description out.
19
19
  */
20
- import { PredicateKind, QueryBy } from '@reticlehq/core';
20
+ import { PredicateKind, QueryBy, compareSourceClauses } from '@reticlehq/core';
21
21
  /** Below this, a status is a success or a redirect: not a declared failure. */
22
22
  const FAILURE_STATUS_MIN = 400;
23
23
  /** Statuses that mean the caller was refused — the proof of an auth/authz denial, not a fault. */
@@ -75,6 +75,10 @@ export function declaredExpectations(predicate) {
75
75
  for (const child of p.predicates)
76
76
  walk(child);
77
77
  return;
78
+ case PredicateKind.COMPARE:
79
+ for (const child of compareSourceClauses(p))
80
+ walk(child);
81
+ return;
78
82
  case PredicateKind.NET: {
79
83
  netUrls.push(p.urlContains ?? '');
80
84
  const declaredFailure = false === p.ok || (p.status !== undefined && p.status >= FAILURE_STATUS_MIN);
@@ -97,8 +101,9 @@ export function declaredExpectations(predicate) {
97
101
  case PredicateKind.TEXT:
98
102
  if (true !== p.absent) {
99
103
  rendersContent = true;
100
- if (isDenialPhrase(p.contains))
104
+ if (p.contains !== undefined && isDenialPhrase(p.contains)) {
101
105
  pushAuthDenialStatuses(netFailures);
106
+ }
102
107
  }
103
108
  return;
104
109
  default:
@@ -137,6 +142,10 @@ export function declaresBodyIndependentChannel(predicate) {
137
142
  case PredicateKind.STATE:
138
143
  case PredicateKind.ROUTE:
139
144
  return true;
145
+ // Only through a side the body does not own. Two body fields compared with each other are
146
+ // still body evidence, and another write's unread answer stays unread beside them.
147
+ case PredicateKind.COMPARE:
148
+ return [p.left, p.right].some((side) => PredicateKind.NET !== side.from);
140
149
  case PredicateKind.ELEMENT:
141
150
  return (true !== p.absent &&
142
151
  (p.query.value !== undefined ||
@@ -16,18 +16,26 @@
16
16
  * one thing a correlation cannot justify;
17
17
  * - no candidate says the value was not seen to pass through one, and reaches for nothing.
18
18
  *
19
+ * One more source, read rather than recomputed: the SDK stamps `actionId` + `attribution` onto every
20
+ * event observed while a driven action is active (see `core/messages.ts`). That is a time-window
21
+ * heuristic too — `EventAttribution.WINDOW`'s own comment says so — but it is the same tier, already
22
+ * computed, already labelled, and narrower than a fresh look-back, so the join reads it two ways:
23
+ * a candidate stamped with a DIFFERENT act is not a candidate for this one (the stamp rules out; it
24
+ * never rules in), and a stamped change with no signal behind it names the act rather than calling
25
+ * its cause "not in evidence" when the evidence is on the event (#939).
26
+ *
19
27
  * Read-only. Produces no verdict, is not reachable from an assert path, and changes nothing.
20
28
  */
21
29
  import { type ReticleEvent } from '@reticlehq/core';
22
30
  /** What the caller is asking about. `value` narrows a path that changed more than once. */
23
- export interface LineageQuery {
31
+ interface LineageQuery {
24
32
  path: string;
25
33
  value?: string;
26
34
  }
27
35
  /** One line of the chain, with the confidence that produced it. */
28
- export interface LineageLink {
29
- /** Which stream this came from. */
30
- kind: 'state' | 'signal' | 'net';
36
+ interface LineageLink {
37
+ /** Which stream this came from. `act` is the driven action the event was stamped with. */
38
+ kind: 'state' | 'act' | 'signal' | 'net';
31
39
  /** The rendered line, already carrying its own hedge. */
32
40
  text: string;
33
41
  /** True only when this is an event we hold. A join is never observed. */
@@ -35,7 +43,7 @@ export interface LineageLink {
35
43
  /** Every candidate, when more than one could explain the link. Present only when ambiguous. */
36
44
  candidates?: string[];
37
45
  }
38
- export interface Lineage {
46
+ interface Lineage {
39
47
  /** False when the path was never seen to change — a different answer from an empty chain. */
40
48
  found: boolean;
41
49
  chain: LineageLink[];
@@ -50,3 +58,4 @@ export interface Lineage {
50
58
  * claim.
51
59
  */
52
60
  export declare function traceLineage(events: readonly ReticleEvent[], query: LineageQuery): Lineage;
61
+ export {};