@reticlehq/engine 3.5.0 → 3.7.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 (57) hide show
  1. package/dist/disagreement/body-failures.js +2 -1
  2. package/dist/disagreement/contradiction-evidence.d.ts +73 -1
  3. package/dist/disagreement/contradiction-evidence.js +154 -6
  4. package/dist/disagreement/contradiction-types.d.ts +8 -1
  5. package/dist/disagreement/contradictions.d.ts +17 -1
  6. package/dist/disagreement/contradictions.js +111 -38
  7. package/dist/disagreement/echo-mismatch.js +42 -3
  8. package/dist/disagreement/reconcile.js +15 -0
  9. package/dist/disagreement/stale-response.js +37 -2
  10. package/dist/evidence/accepted-write.d.ts +26 -2
  11. package/dist/evidence/accepted-write.js +35 -18
  12. package/dist/evidence/already-true.d.ts +16 -0
  13. package/dist/evidence/already-true.js +48 -0
  14. package/dist/evidence/baseline.js +2 -6
  15. package/dist/evidence/blind-spots.d.ts +14 -3
  16. package/dist/evidence/blind-spots.js +48 -10
  17. package/dist/evidence/body-capture-remedy.d.ts +10 -0
  18. package/dist/evidence/body-capture-remedy.js +15 -2
  19. package/dist/evidence/instrumentation-gaps.js +3 -1
  20. package/dist/evidence/state-bookkeeping.d.ts +2 -0
  21. package/dist/evidence/state-bookkeeping.js +2 -0
  22. package/dist/evidence/superseded-checks.d.ts +29 -0
  23. package/dist/evidence/superseded-checks.js +30 -0
  24. package/dist/evidence/unsettled.js +4 -2
  25. package/dist/evidence/verified.d.ts +8 -1
  26. package/dist/evidence/verified.js +42 -4
  27. package/dist/question/declared.d.ts +24 -4
  28. package/dist/question/declared.js +26 -5
  29. package/dist/question/predicate/name-near-miss.d.ts +24 -0
  30. package/dist/question/predicate/name-near-miss.js +39 -0
  31. package/dist/question/predicate/net-blind-spots.d.ts +49 -0
  32. package/dist/question/predicate/net-blind-spots.js +153 -0
  33. package/dist/question/predicate/predicate-compare.js +13 -4
  34. package/dist/question/predicate/predicate-element.d.ts +15 -1
  35. package/dist/question/predicate/predicate-element.js +108 -7
  36. package/dist/question/predicate/predicate-eval-kit.d.ts +25 -0
  37. package/dist/question/predicate/predicate-eval-kit.js +31 -0
  38. package/dist/question/predicate/predicate-eval.d.ts +17 -2
  39. package/dist/question/predicate/predicate-eval.js +117 -180
  40. package/dist/question/predicate/predicate-parse.js +153 -13
  41. package/dist/question/predicate/predicate-request-body.d.ts +6 -1
  42. package/dist/question/predicate/predicate-request-body.js +7 -2
  43. package/dist/question/predicate/predicate-route.d.ts +2 -0
  44. package/dist/question/predicate/predicate-route.js +30 -0
  45. package/dist/question/predicate/predicate-schema.d.ts +11 -0
  46. package/dist/question/predicate/predicate-schema.js +110 -24
  47. package/dist/question/predicate/predicate-session.d.ts +10 -0
  48. package/dist/question/predicate/predicate-state.js +7 -0
  49. package/dist/question/predicate/predicate-to-links.js +1 -0
  50. package/dist/question/predicate/predicate.js +76 -25
  51. package/dist/question/predicate/split-text-miss.d.ts +6 -0
  52. package/dist/question/predicate/split-text-miss.js +10 -0
  53. package/dist/question/reaction.d.ts +1 -1
  54. package/dist/question/reaction.js +1 -1
  55. package/dist/state-bookkeeping.d.ts +25 -0
  56. package/dist/state-bookkeeping.js +70 -0
  57. package/package.json +2 -2
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Which checks read too early: the ONE rule every fold of a run's checks applies.
3
+ *
4
+ * A passive check (an assert, made after acting rather than declared before it) that came back `no`
5
+ * is superseded when the SAME claim holds later in the same run. Driven over MCP: the Harness
6
+ * asserted the text Generate produces before its POST answered, read `no`, and a working journey
7
+ * was failed while the same assert held a second later.
8
+ *
9
+ * It lived in four places — the Harness's tally, the run's verdict, the synced run's flow status and
10
+ * the session's result block — each keyed differently and one not at all, so one end-of-session
11
+ * answer could carry `claim: pass` beside "Reticle result: failed". Every fold calls this instead.
12
+ *
13
+ * A DECLARED check that failed is never excused: a first click that did nothing is a finding even if
14
+ * a second one works. A `no` AFTER a `yes` on the same claim is never excused either: that is a
15
+ * regression inside the run.
16
+ */
17
+ /** One check, as a fold reads it. */
18
+ export interface CheckReading {
19
+ /** The claim: two readings with the same key are the same claim. */
20
+ readonly key: string;
21
+ /** Made after acting (an assert), rather than declared before the action it judges. */
22
+ readonly passive: boolean;
23
+ /** Came back `yes`. */
24
+ readonly held: boolean;
25
+ /** Came back `no`. Neither is undecided. */
26
+ readonly failed: boolean;
27
+ }
28
+ /** The indexes, into `readings`, of the passive `no`s a later `yes` of the same claim supersedes. */
29
+ export declare function supersededChecks(readings: readonly CheckReading[]): ReadonlySet<number>;
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Which checks read too early: the ONE rule every fold of a run's checks applies.
3
+ *
4
+ * A passive check (an assert, made after acting rather than declared before it) that came back `no`
5
+ * is superseded when the SAME claim holds later in the same run. Driven over MCP: the Harness
6
+ * asserted the text Generate produces before its POST answered, read `no`, and a working journey
7
+ * was failed while the same assert held a second later.
8
+ *
9
+ * It lived in four places — the Harness's tally, the run's verdict, the synced run's flow status and
10
+ * the session's result block — each keyed differently and one not at all, so one end-of-session
11
+ * answer could carry `claim: pass` beside "Reticle result: failed". Every fold calls this instead.
12
+ *
13
+ * A DECLARED check that failed is never excused: a first click that did nothing is a finding even if
14
+ * a second one works. A `no` AFTER a `yes` on the same claim is never excused either: that is a
15
+ * regression inside the run.
16
+ */
17
+ /** The indexes, into `readings`, of the passive `no`s a later `yes` of the same claim supersedes. */
18
+ export function supersededChecks(readings) {
19
+ const superseded = new Set();
20
+ for (const [at, reading] of readings.entries()) {
21
+ if (!reading.passive || !reading.failed)
22
+ continue;
23
+ const heldLater = readings
24
+ .slice(at + 1)
25
+ .some((later) => later.key === reading.key && later.held);
26
+ if (heldLater)
27
+ superseded.add(at);
28
+ }
29
+ return superseded;
30
+ }
@@ -36,10 +36,12 @@ export function describeWaitTarget(predicate) {
36
36
  return `a route change${predicate.pathname === undefined ? '' : ` to '${predicate.pathname}'`}${predicate.contains === undefined ? '' : ` containing '${predicate.contains}'`}`;
37
37
  case PredicateKind.STATE:
38
38
  return `state at '${predicate.path}'`;
39
+ // Every part that decides the claim stays in it: the label is the check's title downstream, and
40
+ // one that dropped `ignoreCase` or the wanted state read as a different check from its own result.
39
41
  case PredicateKind.TEXT:
40
- return `text containing '${predicate.contains}'`;
42
+ return `text containing '${predicate.contains}'${true === predicate.ignoreCase ? ', ignoring case' : ''}`;
41
43
  case PredicateKind.ELEMENT:
42
- return `an element matching ${JSON.stringify(predicate.query)}`;
44
+ return `an element matching ${JSON.stringify(predicate.query)}${predicate.state === undefined ? '' : ` in state '${predicate.state}'`}`;
43
45
  case PredicateKind.CONSOLE:
44
46
  return 'a console message';
45
47
  case PredicateKind.ANIMATION:
@@ -1,4 +1,4 @@
1
- import { type ChannelId, Verified, VerifiedReason } from '@reticlehq/core';
1
+ import { 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 {
@@ -148,6 +148,8 @@ interface VerifiedInputs {
148
148
  unsettled?: UnsettledWindow;
149
149
  /** A passing absence assertion targeted a region that the current capture could not observe. */
150
150
  absenceBlindSpot?: string;
151
+ /** The green rested on matches that are all hidden; the sentence that says so. See `hiddenMatchNote`. */
152
+ hiddenMatch?: string;
151
153
  }
152
154
  interface VerifiedVerdict {
153
155
  verified: Verified;
@@ -161,5 +163,10 @@ interface VerifiedVerdict {
161
163
  /** One sentence naming the deciding evidence — never a restatement of the field. */
162
164
  because: string;
163
165
  }
166
+ /**
167
+ * The sentence a vacuous-grade `unknown` carries. Exported because it is the CALLER's unknown — it
168
+ * asserted nothing real — and the feedback invite has to tell it from "Reticle could not tell".
169
+ */
170
+ export declare const VACUOUS_BECAUSE = "nothing was asserted at a real grade, so passing proves nothing \u2014 assert a signal, request, or state path";
164
171
  export declare function decideVerified(inputs: VerifiedInputs): VerifiedVerdict;
165
172
  export {};
@@ -1,5 +1,5 @@
1
1
  import { bodyCaptureRemedy } from './body-capture-remedy.js';
2
- import { ContradictionKind, MUTATING_METHODS, Verified, VerifiedReason, isAbsenceDerived, isAdvisory, } from '@reticlehq/core';
2
+ import { ChannelId, ContradictionKind, MUTATING_METHODS, Verified, VerifiedReason, isAbsenceDerived, isAdvisory, } from '@reticlehq/core';
3
3
  import { HonestyGrade } from './honesty.js';
4
4
  import { unsettledBecause } from './unsettled.js';
5
5
  import { pageTornDownWhileOn } from './page-teardown.js';
@@ -29,6 +29,13 @@ function undeclaredChannels(inputs) {
29
29
  const needed = inputs.channelsRead ?? [];
30
30
  return needed.filter((channel) => !observable.includes(channel));
31
31
  }
32
+ /**
33
+ * The sentence a vacuous-grade `unknown` carries. Exported because it is the CALLER's unknown — it
34
+ * asserted nothing real — and the feedback invite has to tell it from "Reticle could not tell".
35
+ */
36
+ export const VACUOUS_BECAUSE = 'nothing was asserted at a real grade, so passing proves nothing — assert a signal, request, or state path';
37
+ /** A `"POST /api/x"` label: is it a write? */
38
+ const isWriteLabel = (label) => MUTATING_METHODS.includes((label.split(' ')[0] ?? '').toUpperCase());
32
39
  export function decideVerified(inputs) {
33
40
  const { pass, honesty, contradictions = [], settled, outcomePending, outcomeUnread } = inputs;
34
41
  // Ahead of everything, with `capability-absent` below it and for the same reason: a skewed wire
@@ -123,6 +130,27 @@ export function decideVerified(inputs) {
123
130
  'consequence was not disproved — it had not finished', inputs.unsettled),
124
131
  };
125
132
  }
133
+ // The same rule, for a claim that does not NAME the request. Driven over MCP: the Harness asserted
134
+ // "Generated script for" the moment Generate was pressed, while the POST that produces that text
135
+ // was still open; `no` failed the journey, and the same assert held a second later. A write that
136
+ // has not answered is an outcome not in yet, whatever the claim is about. It only ever turns a
137
+ // `no` into `unknown`, never into a `yes`.
138
+ //
139
+ // A claim about the network keeps the named-request rule above: its request not firing while an
140
+ // UNRELATED write is open is a real miss. Only a claim that reads the page waits on the write.
141
+ const readsThePageOnly = inputs.channelsRead !== undefined &&
142
+ 0 < inputs.channelsRead.length &&
143
+ !inputs.channelsRead.includes(ChannelId.NET);
144
+ if (false === pass &&
145
+ readsThePageOnly &&
146
+ (inputs.unsettled?.stillInFlight ?? []).some(isWriteLabel)) {
147
+ return {
148
+ verified: Verified.UNKNOWN,
149
+ verifiedReason: VerifiedReason.WINDOW_CLOSED_EARLY,
150
+ because: unsettledBecause('a write this window started had not answered when the claim was read, so the ' +
151
+ 'consequence was not disproved — it had not arrived yet', inputs.unsettled),
152
+ };
153
+ }
126
154
  // ABOVE the failure clause, and for the same reason `observationLost` is: a consequence that has
127
155
  // not happened YET has not failed. `202 Accepted` is the only word HTTP has for "the outcome does
128
156
  // not exist yet", and a not-yet-reconciled write is indistinguishable from a broken one at the
@@ -198,7 +226,7 @@ export function decideVerified(inputs) {
198
226
  // catch, and its outcome genuinely does not exist yet. A poll or a prefetch left hanging says
199
227
  // nothing about the action; an unfinished mutation says the answer is not in yet. Read off the
200
228
  // labels the window already carries — and when there are no labels to read, nothing is softened.
201
- const openWrite = (inputs.unsettled?.stillInFlight ?? []).some((label) => MUTATING_METHODS.includes((label.split(' ')[0] ?? '').toUpperCase()));
229
+ const openWrite = (inputs.unsettled?.stillInFlight ?? []).some(isWriteLabel);
202
230
  const settlementOnly = declaredHeld &&
203
231
  inputs.unsettled !== undefined &&
204
232
  !openWrite &&
@@ -293,10 +321,20 @@ export function decideVerified(inputs) {
293
321
  verifiedReason: VerifiedReason.ALREADY_TRUE,
294
322
  because: 'the declared consequence was already true before this action, so it proves nothing about it — assert something the action CHANGES (a signal, a request, a route, or store state)' +
295
323
  (true === inputs.alreadyTrueHiddenMatch
296
- ? '. That prior match was against a HIDDEN element — this predicate checks DOM presence, not visibility, by default; add `visible: true` if you meant "this is showing", not merely "this exists"'
324
+ ? '. That prior match was against a HIDDEN element — this predicate checks DOM presence, not visibility, by default; add `visible: true` to a text check, or `state: "visible"` to an element check, if you meant "this is showing", not merely "this exists"'
297
325
  : ''),
298
326
  };
299
327
  }
328
+ // A green whose text or element clause matched only hidden nodes says the node exists, not that it
329
+ // is showing (#1408). UNKNOWN, not NO: the node may be hidden by design and the caller asked only
330
+ // for presence.
331
+ if (true === pass && inputs.hiddenMatch !== undefined) {
332
+ return {
333
+ verified: Verified.UNKNOWN,
334
+ verifiedReason: VerifiedReason.HIDDEN_MATCH,
335
+ because: inputs.hiddenMatch,
336
+ };
337
+ }
300
338
  // Dirty capture is NOT failure. The layer could not see part of the window, so any green is a
301
339
  // statement about what it happened to observe — which is precisely the thing that must not be
302
340
  // reported as proof.
@@ -344,7 +382,7 @@ export function decideVerified(inputs) {
344
382
  return {
345
383
  verified: Verified.UNKNOWN,
346
384
  verifiedReason: VerifiedReason.VACUOUS_GRADE,
347
- because: 'nothing was asserted at a real grade, so passing proves nothing — assert a signal, request, or state path',
385
+ because: VACUOUS_BECAUSE,
348
386
  };
349
387
  }
350
388
  // A write answered 2xx and its payload went unread, so the one channel that could contradict the
@@ -24,6 +24,11 @@ export interface DeclaredNetFailure {
24
24
  urlContains?: string;
25
25
  status?: number;
26
26
  }
27
+ /** A `net { repeatable: true }` clause: the endpoint it declared a read, and its method if named. */
28
+ export interface DeclaredRead {
29
+ urlContains: string;
30
+ method?: string;
31
+ }
27
32
  interface DeclaredExpectations {
28
33
  /** Requests the caller declared would FAIL, so failing is the expected outcome, not a disagreement. */
29
34
  netFailures: readonly DeclaredNetFailure[];
@@ -40,6 +45,11 @@ interface DeclaredExpectations {
40
45
  * is why an empty-string entry is meaningful and is preserved rather than skipped.
41
46
  */
42
47
  netUrls: readonly string[];
48
+ /**
49
+ * The net clauses that said `repeatable: true`: reads, not writes (#1353). One with no
50
+ * `urlContains` is never here: the schema refuses it, and it would excuse every request.
51
+ */
52
+ repeatableNetUrls: readonly DeclaredRead[];
43
53
  }
44
54
  export declare function declaredExpectations(predicate: Predicate | undefined): DeclaredExpectations;
45
55
  /**
@@ -52,10 +62,10 @@ export declare function declaredExpectations(predicate: Predicate | undefined):
52
62
  * verdict (measured: a 201 plus the unique row, unread body, agent went to enable capture instead
53
63
  * of finishing the drive).
54
64
  *
55
- * Same conservatism as `declaredExpectations`: only the top level and `allOf`. An `anyOf` branch
56
- * may never have held, and honouring it would skip the unread caveat on the strength of a net
57
- * success that was the branch that actually matched. An `absent` element is not a consequence the
58
- * body cannot own.
65
+ * Same conservatism as `declaredExpectations`: only the top level and `allOf`, plus an `anyOf` whose
66
+ * every branch is body-independent. An `anyOf` with a net branch may have held on that branch alone,
67
+ * so it must not skip the unread caveat. An `absent` element is not a consequence the body cannot
68
+ * own.
59
69
  */
60
70
  export declare function declaresBodyIndependentChannel(predicate: Predicate | undefined): boolean;
61
71
  /**
@@ -71,4 +81,14 @@ export declare function matchesDeclaredFailure(call: {
71
81
  matchUrl?: string;
72
82
  status: number | undefined;
73
83
  }, declared: readonly DeclaredNetFailure[]): boolean;
84
+ /**
85
+ * Was this call declared a read? Same matching as `matchesDeclaredFailure`: the URL must contain
86
+ * the clause's `urlContains`, and a method the clause named must agree, so a repeatable GET never
87
+ * excuses a POST to the same endpoint (#1353).
88
+ */
89
+ export declare function isDeclaredRead(call: {
90
+ method: string;
91
+ url: string;
92
+ matchUrl?: string;
93
+ }, reads: readonly DeclaredRead[] | undefined): boolean;
74
94
  export {};
@@ -68,6 +68,7 @@ function pushAuthDenialStatuses(into) {
68
68
  export function declaredExpectations(predicate) {
69
69
  const netFailures = [];
70
70
  const netUrls = [];
71
+ const repeatableNetUrls = [];
71
72
  let rendersContent = false;
72
73
  const walk = (p) => {
73
74
  switch (p.kind) {
@@ -81,6 +82,12 @@ export function declaredExpectations(predicate) {
81
82
  return;
82
83
  case PredicateKind.NET: {
83
84
  netUrls.push(p.urlContains ?? '');
85
+ if (true === p.repeatable && p.urlContains !== undefined && p.urlContains.trim() !== '') {
86
+ repeatableNetUrls.push({
87
+ urlContains: p.urlContains,
88
+ ...(p.method === undefined ? {} : { method: p.method }),
89
+ });
90
+ }
84
91
  const declaredFailure = false === p.ok || (p.status !== undefined && p.status >= FAILURE_STATUS_MIN);
85
92
  if (!declaredFailure)
86
93
  return;
@@ -112,7 +119,7 @@ export function declaredExpectations(predicate) {
112
119
  };
113
120
  if (predicate !== undefined)
114
121
  walk(predicate);
115
- return { netFailures, rendersContent, netUrls };
122
+ return { netFailures, rendersContent, netUrls, repeatableNetUrls };
116
123
  }
117
124
  /**
118
125
  * Did the caller name a consequence that does not depend on the response body?
@@ -124,10 +131,10 @@ export function declaredExpectations(predicate) {
124
131
  * verdict (measured: a 201 plus the unique row, unread body, agent went to enable capture instead
125
132
  * of finishing the drive).
126
133
  *
127
- * Same conservatism as `declaredExpectations`: only the top level and `allOf`. An `anyOf` branch
128
- * may never have held, and honouring it would skip the unread caveat on the strength of a net
129
- * success that was the branch that actually matched. An `absent` element is not a consequence the
130
- * body cannot own.
134
+ * Same conservatism as `declaredExpectations`: only the top level and `allOf`, plus an `anyOf` whose
135
+ * every branch is body-independent. An `anyOf` with a net branch may have held on that branch alone,
136
+ * so it must not skip the unread caveat. An `absent` element is not a consequence the body cannot
137
+ * own.
131
138
  */
132
139
  export function declaresBodyIndependentChannel(predicate) {
133
140
  if (predicate === undefined)
@@ -136,6 +143,8 @@ export function declaresBodyIndependentChannel(predicate) {
136
143
  switch (p.kind) {
137
144
  case PredicateKind.ALL_OF:
138
145
  return p.predicates.some(walk);
146
+ case PredicateKind.ANY_OF:
147
+ return p.predicates.every(walk);
139
148
  case PredicateKind.TEXT:
140
149
  return true !== p.absent;
141
150
  case PredicateKind.SIGNAL:
@@ -178,3 +187,15 @@ export function matchesDeclaredFailure(call, declared) {
178
187
  return true;
179
188
  });
180
189
  }
190
+ /**
191
+ * Was this call declared a read? Same matching as `matchesDeclaredFailure`: the URL must contain
192
+ * the clause's `urlContains`, and a method the clause named must agree, so a repeatable GET never
193
+ * excuses a POST to the same endpoint (#1353).
194
+ */
195
+ export function isDeclaredRead(call, reads) {
196
+ if (reads === undefined)
197
+ return false;
198
+ const haystack = call.matchUrl ?? call.url;
199
+ return reads.some((r) => haystack.includes(r.urlContains) &&
200
+ (r.method === undefined || r.method.toUpperCase() === call.method.toUpperCase()));
201
+ }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * The "…but that role IS carrying this label" clause on a failed element predicate.
3
+ *
4
+ * `reticle_query` answers a role+name miss with `hint.nameNearMiss` -- the labels that role really
5
+ * has, when one of them is a containment away from the one asked for. A failed PREDICATE had no
6
+ * equivalent: `no element matched {role: "button", name: "Mesh"}` is byte-identical for a page with
7
+ * no such button and for one showing `button "2 Mesh"`, and only one of those is a bug (#875).
8
+ *
9
+ * That asymmetry is the same one `describeSplitTextMiss` was written to close one field over: the
10
+ * identical failure through `reticle_query` listed what IS present while the predicate path was a
11
+ * dead end. The browser already computes this on its way to reporting zero, so the clause costs
12
+ * nothing but the sentence.
13
+ *
14
+ * Undefined when there is nothing to say, for the reason every clause in this family is: one that
15
+ * fires on every failure stops carrying information.
16
+ */
17
+ /**
18
+ * The clause, or undefined when the page carried no near-miss label.
19
+ *
20
+ * `role` is named in the sentence because the hint is scoped to it: the browser will not offer a
21
+ * link called "2 Mesh" as a recovery for a BUTTON called "Mesh", and the message should not read as
22
+ * if it might have.
23
+ */
24
+ export declare function describeNameNearMiss(near: readonly string[] | undefined, searchedName?: string, role?: string): string | undefined;
@@ -0,0 +1,39 @@
1
+ /**
2
+ * The "…but that role IS carrying this label" clause on a failed element predicate.
3
+ *
4
+ * `reticle_query` answers a role+name miss with `hint.nameNearMiss` -- the labels that role really
5
+ * has, when one of them is a containment away from the one asked for. A failed PREDICATE had no
6
+ * equivalent: `no element matched {role: "button", name: "Mesh"}` is byte-identical for a page with
7
+ * no such button and for one showing `button "2 Mesh"`, and only one of those is a bug (#875).
8
+ *
9
+ * That asymmetry is the same one `describeSplitTextMiss` was written to close one field over: the
10
+ * identical failure through `reticle_query` listed what IS present while the predicate path was a
11
+ * dead end. The browser already computes this on its way to reporting zero, so the clause costs
12
+ * nothing but the sentence.
13
+ *
14
+ * Undefined when there is nothing to say, for the reason every clause in this family is: one that
15
+ * fires on every failure stops carrying information.
16
+ */
17
+ /** Enough of a label to recognise it; this is read in a verdict, not a log. */
18
+ const MAX_NAME = 60;
19
+ /** At most this many alternatives in one sentence -- beyond that it is a result set, not a hint. */
20
+ const MAX_NAMED = 3;
21
+ function truncate(value) {
22
+ return value.length > MAX_NAME ? `${value.slice(0, MAX_NAME)}…` : value;
23
+ }
24
+ /**
25
+ * The clause, or undefined when the page carried no near-miss label.
26
+ *
27
+ * `role` is named in the sentence because the hint is scoped to it: the browser will not offer a
28
+ * link called "2 Mesh" as a recovery for a BUTTON called "Mesh", and the message should not read as
29
+ * if it might have.
30
+ */
31
+ export function describeNameNearMiss(near, searchedName, role) {
32
+ if (near === undefined || 0 === near.length)
33
+ return undefined;
34
+ const labels = near.slice(0, MAX_NAMED).map((name) => JSON.stringify(truncate(name)));
35
+ const asked = searchedName === undefined ? 'that name' : JSON.stringify(truncate(searchedName));
36
+ const what = role === undefined ? 'the page has' : `the page's ${role}s include`;
37
+ return (`role+name matching is EXACT and nothing is named ${asked}, but ${what} ${labels.join(', ')} — ` +
38
+ 're-query with the full name rather than a substring of it');
39
+ }
@@ -0,0 +1,49 @@
1
+ /**
2
+ * What the `net` channel cannot see, and what a miss over it is allowed to claim.
3
+ *
4
+ * The network observer patches `fetch` and `XMLHttpRequest`; a document-initiated subresource, a
5
+ * native download and anything before the SDK attached never reach it. Each rule here exists so a
6
+ * zero-match `net` verdict says "not observable" or names its blind stretch, instead of "never
7
+ * happened". Split from `predicate-eval.ts`, which decides the verdict; this only knows the channel.
8
+ *
9
+ * Takes the filter's parts rather than the predicate, so it needs nothing from the contract.
10
+ */
11
+ /**
12
+ * Does this filter target a class of request the observer cannot see?
13
+ *
14
+ * Read off `urlContains` only, and only when the pattern ENDS in one of the suffixes — a filter of
15
+ * `/api/` that happens to contain `.css` somewhere in a query string is still an ordinary XHR
16
+ * target. Query strings and fragments are stripped first, since `favicon.ico?v=2` is the same asset.
17
+ */
18
+ export declare function targetsUnobservedChannel(url: string | undefined): boolean;
19
+ export declare function targetsNativeDownload(url: string | undefined): boolean;
20
+ /** `filter` is the net clause as applied — `describeNetFilter` of it. */
21
+ export declare function nativeDownloadReason(filter: string): string;
22
+ /** The sentence both zero-match branches hand to `inconclusive`; `filter` as `nativeDownloadReason`. */
23
+ export declare function unobservedChannelReason(filter: string): string;
24
+ /**
25
+ * Appended to a zero-match `net` negative whose window starts at SDK attach.
26
+ *
27
+ * Every event's `t` is stamped `performance.now() - #start`, where `#start` is taken when the SDK
28
+ * is constructed, so `t` is never negative and a window with `since === 0` begins AT attach — never
29
+ * before it. Whatever the page did between navigation start and attach left no event at all, so
30
+ * "no matching call" over such a window cannot be told apart from "the call was made while nothing
31
+ * was watching yet".
32
+ *
33
+ * The gap is routine rather than exotic: a `fetch` from an effect in a root provider, or a classic
34
+ * `<script>` at the end of `<body>`, fires before a deferred module script has run. Read as proof
35
+ * the request was never made, that sends a reader looking for a defect in code that works —
36
+ * restarting dev servers and re-reading providers to establish that the request was invisible rather
37
+ * than absent.
38
+ *
39
+ * Same argument as DOCUMENT_ONLY_SUFFIXES one axis over: that one is a channel Reticle does not
40
+ * watch, this is a stretch of TIME it was not yet watching.
41
+ *
42
+ * The grade is deliberately NOT downgraded to `inconclusive`. A missing API call is the finding this
43
+ * oracle exists to make, and it is the strongest grade available for the startup class — session
44
+ * restore, feature flags, bootstrap config — which is exactly the class that silently breaks on
45
+ * reload. Every window an action opens carries `since > 0` and is untouched. What changes is only
46
+ * what the negative CLAIMS: it stops asserting the request never happened, and names the assertion
47
+ * that can settle it, because the state such a request produces IS observable after attach.
48
+ */
49
+ export declare const PRE_ATTACH_CAVEAT: string;
@@ -0,0 +1,153 @@
1
+ /**
2
+ * What the `net` channel cannot see, and what a miss over it is allowed to claim.
3
+ *
4
+ * The network observer patches `fetch` and `XMLHttpRequest`; a document-initiated subresource, a
5
+ * native download and anything before the SDK attached never reach it. Each rule here exists so a
6
+ * zero-match `net` verdict says "not observable" or names its blind stretch, instead of "never
7
+ * happened". Split from `predicate-eval.ts`, which decides the verdict; this only knows the channel.
8
+ *
9
+ * Takes the filter's parts rather than the predicate, so it needs nothing from the contract.
10
+ */
11
+ /**
12
+ * URL suffixes only the DOCUMENT fetches, which the network observer therefore never records.
13
+ *
14
+ * `network.ts` patches `fetch` and `XMLHttpRequest` and nothing else, so `<link rel=icon>`,
15
+ * `<link rel=manifest>`, stylesheets, fonts and `<img src>` are invisible to it. "No matching call"
16
+ * and "that class of call is not observed" are then indistinguishable, and the miss graded
17
+ * `assertion_failed` — a false RED. Reported from the field: an assert over `/favicon.ico`,
18
+ * `/site.webmanifest` and `/apple-touch-icon.png` returned `verified:"no"` while curl showed all
19
+ * three answering 200. A false negative here is worse than an unknown, because an agent that trusts
20
+ * it goes and "fixes" working code.
21
+ *
22
+ * Deliberately NOT here: `.js` and `.json`. Both are routinely fetched via `fetch`/XHR — a module
23
+ * preload and an API call can share a suffix — so downgrading them would hide real misses. This list
24
+ * is only the suffixes for which the document is the sole plausible initiator.
25
+ *
26
+ * This began as the smaller half of #447: it did not make these requests observable, it stopped
27
+ * Reticle claiming they did not happen. The other half, observing them via resource timing, has
28
+ * since landed in the browser SDK, so the two halves are no longer independent and this downgrade is
29
+ * now GATED: when the event stream carries at least one document-initiated record, the observer is
30
+ * demonstrably live and a miss over these suffixes is real evidence, graded a plain failure. Only a
31
+ * page whose stream holds no resource entry at all keeps the honest "cannot tell apart" answer,
32
+ * because there the observer may simply not exist.
33
+ */
34
+ const DOCUMENT_ONLY_SUFFIXES = [
35
+ '.ico',
36
+ '.png',
37
+ '.jpg',
38
+ '.jpeg',
39
+ '.gif',
40
+ '.svg',
41
+ '.webp',
42
+ '.avif',
43
+ '.bmp',
44
+ '.css',
45
+ '.woff',
46
+ '.woff2',
47
+ '.ttf',
48
+ '.otf',
49
+ '.eot',
50
+ '.webmanifest',
51
+ ];
52
+ /**
53
+ * File suffixes a click typically downloads or navigates to as a document, never as fetch/XHR.
54
+ *
55
+ * Sibling of DOCUMENT_ONLY_SUFFIXES, not a member of it. Those are subresources: once resource
56
+ * timing is live, a miss is evidence. A click on `<a href="/export.pdf">` is a navigation (or a
57
+ * Content-Disposition attachment). Resource timing of stylesheets does not make it visible, so
58
+ * grading the miss as "0 network calls" / a 404 is the lie #805 exists to stop — even on a page
59
+ * whose observer is running. `.js` / `.json` stay off this list for the same reason they stay off
60
+ * the other: they are routinely fetched.
61
+ */
62
+ const NATIVE_DOWNLOAD_SUFFIXES = [
63
+ '.pdf',
64
+ '.csv',
65
+ '.tsv',
66
+ '.zip',
67
+ '.gz',
68
+ '.tar',
69
+ '.xlsx',
70
+ '.xls',
71
+ '.docx',
72
+ '.doc',
73
+ '.pptx',
74
+ '.ppt',
75
+ '.ods',
76
+ '.odt',
77
+ '.rtf',
78
+ '.7z',
79
+ '.rar',
80
+ ];
81
+ /**
82
+ * Does this filter target a class of request the observer cannot see?
83
+ *
84
+ * Read off `urlContains` only, and only when the pattern ENDS in one of the suffixes — a filter of
85
+ * `/api/` that happens to contain `.css` somewhere in a query string is still an ordinary XHR
86
+ * target. Query strings and fragments are stripped first, since `favicon.ico?v=2` is the same asset.
87
+ */
88
+ function filterPath(urlContains) {
89
+ return (urlContains.split('#')[0] ?? '').split('?')[0]?.toLowerCase() ?? '';
90
+ }
91
+ /**
92
+ * Does this filter target a class of request the observer cannot see?
93
+ *
94
+ * Read off `urlContains` only, and only when the pattern ENDS in one of the suffixes — a filter of
95
+ * `/api/` that happens to contain `.css` somewhere in a query string is still an ordinary XHR
96
+ * target. Query strings and fragments are stripped first, since `favicon.ico?v=2` is the same asset.
97
+ */
98
+ export function targetsUnobservedChannel(url) {
99
+ if (undefined === url)
100
+ return false;
101
+ return DOCUMENT_ONLY_SUFFIXES.some((suffix) => filterPath(url).endsWith(suffix));
102
+ }
103
+ export function targetsNativeDownload(url) {
104
+ if (undefined === url)
105
+ return false;
106
+ return NATIVE_DOWNLOAD_SUFFIXES.some((suffix) => filterPath(url).endsWith(suffix));
107
+ }
108
+ /** `filter` is the net clause as applied — `describeNetFilter` of it. */
109
+ export function nativeDownloadReason(filter) {
110
+ return (`no fetch or XHR matched ${filter}. A native download or document navigation ` +
111
+ `(an <a href> to a file, a Content-Disposition attachment, <a download>) never goes through ` +
112
+ `fetch or XMLHttpRequest, so an empty net window is not a 404 and is not evidence the export ` +
113
+ `failed. This is unobservable on the net channel. Assert the link href, or check the file ` +
114
+ `outside the browser — Reticle cannot see the bytes land`);
115
+ }
116
+ /** The sentence both zero-match branches hand to `inconclusive`; `filter` as `nativeDownloadReason`. */
117
+ export function unobservedChannelReason(filter) {
118
+ return (`no call matched ${filter}, and no document-initiated load was recorded either, ` +
119
+ `so this page exposed no resource timing to read: Reticle observes fetch and XMLHttpRequest ` +
120
+ `directly, while a request the document initiates (<link rel=icon|manifest|preload>, a ` +
121
+ `stylesheet, a font, <img src>) leaves no record, and that state cannot be told apart from the ` +
122
+ `request having been made. ` +
123
+ `Nothing here says the app is wrong. Check it outside the browser, or assert something the ` +
124
+ `document does not fetch on its own`);
125
+ }
126
+ /**
127
+ * Appended to a zero-match `net` negative whose window starts at SDK attach.
128
+ *
129
+ * Every event's `t` is stamped `performance.now() - #start`, where `#start` is taken when the SDK
130
+ * is constructed, so `t` is never negative and a window with `since === 0` begins AT attach — never
131
+ * before it. Whatever the page did between navigation start and attach left no event at all, so
132
+ * "no matching call" over such a window cannot be told apart from "the call was made while nothing
133
+ * was watching yet".
134
+ *
135
+ * The gap is routine rather than exotic: a `fetch` from an effect in a root provider, or a classic
136
+ * `<script>` at the end of `<body>`, fires before a deferred module script has run. Read as proof
137
+ * the request was never made, that sends a reader looking for a defect in code that works —
138
+ * restarting dev servers and re-reading providers to establish that the request was invisible rather
139
+ * than absent.
140
+ *
141
+ * Same argument as DOCUMENT_ONLY_SUFFIXES one axis over: that one is a channel Reticle does not
142
+ * watch, this is a stretch of TIME it was not yet watching.
143
+ *
144
+ * The grade is deliberately NOT downgraded to `inconclusive`. A missing API call is the finding this
145
+ * oracle exists to make, and it is the strongest grade available for the startup class — session
146
+ * restore, feature flags, bootstrap config — which is exactly the class that silently breaks on
147
+ * reload. Every window an action opens carries `since > 0` and is untouched. What changes is only
148
+ * what the negative CLAIMS: it stops asserting the request never happened, and names the assertion
149
+ * that can settle it, because the state such a request produces IS observable after attach.
150
+ */
151
+ export const PRE_ATTACH_CAVEAT = ' — note that this window starts where the SDK attached, and requests made before that are never ' +
152
+ 'captured, so a miss here cannot tell a call that was never made apart from one made before the ' +
153
+ 'page connected; if the call is expected during startup, assert on the state it produces instead';
@@ -139,10 +139,11 @@ function readSide(session, events, source, diagnose) {
139
139
  }
140
140
  }
141
141
  /**
142
- * A thousands-grouped number or a plain one. A comma counts as a separator only in groups of three,
143
- * so `11,87` (a decimal comma) reads as two numbers, not as 1187 — and two numbers are refused.
142
+ * A thousands-grouped number or a plain one, optionally preceded by a minus sign and/or a currency
143
+ * symbol (`-$100`, `-₹1,187.01`). A comma counts as a separator only in groups of three, so `11,87`
144
+ * (a decimal comma) reads as two numbers, not as 1187 — and two numbers are refused.
144
145
  */
145
- const NUMBER_TOKEN = /-?(?:\d{1,3}(?:,\d{3})+|\d+)(?:\.\d+)?/g;
146
+ const NUMBER_TOKEN = /(?:-(?:[\p{Sc}]\s*)?|[\p{Sc}]\s*-?)?(?:\d{1,3}(?:,\d{3})+|\d+)(?:\.\d+)?/gu;
146
147
  /** One number out of a reading, or why there is not exactly one. */
147
148
  function numberOf(value) {
148
149
  if ('number' === typeof value)
@@ -156,7 +157,15 @@ function numberOf(value) {
156
157
  why: `holds ${String(tokens.length)} numbers in ${JSON.stringify(value)}, so which one was meant is a guess — narrow the scope to one value`,
157
158
  };
158
159
  }
159
- return { n: Number(only.replace(/,/g, '')) };
160
+ const isNegative = only.includes('-');
161
+ const cleaned = only.replace(/,/g, '');
162
+ const digits = cleaned.match(/(?:\d+(?:\.\d+)?)/);
163
+ if (null === digits) {
164
+ return { why: `could not parse a number from ${JSON.stringify(value)}` };
165
+ }
166
+ const parsed = Number(digits[0]);
167
+ const n = isNegative && 0 !== parsed ? -parsed : parsed;
168
+ return { n };
160
169
  }
161
170
  /**
162
171
  * A few units in the last place: the noise of arithmetic done in binary (`0.1 + 0.2` against the
@@ -6,7 +6,7 @@
6
6
  * back (`residualQueryChecks`), the absent/present asymmetry, and the near-miss diagnostics that only
7
7
  * ever enrich a failure. Nothing else in the predicate layer talks to `ReticleCommand.MATCH`.
8
8
  */
9
- import { type ElementQuery, type ElementState } from '@reticlehq/core';
9
+ import { type ElementQuery, ElementState } from '@reticlehq/core';
10
10
  import { type EvalResult } from './predicate-eval.js';
11
11
  import type { PredicateSession } from './predicate-session.js';
12
12
  import { type Baseline, type PropertyAssertion } from './property.js';
@@ -14,3 +14,17 @@ export declare function evalElement(session: PredicateSession, query: ElementQue
14
14
  /** The text of every element a passing match described, joined — what a reader sees there. */
15
15
  export declare function joinedText(evidence: unknown): string;
16
16
  export declare function withTextProperty(base: EvalResult, assertion: PropertyAssertion, subject: string, baseline?: Baseline): EvalResult;
17
+ /**
18
+ * The element query a text predicate is evaluated through — one builder for the verdict and its
19
+ * baseline, so the two cannot disagree about what text was asked for.
20
+ *
21
+ * `matchCase` unless the predicate opts out: a check that matched "Saved Priya" against "Saved
22
+ * priya" could never catch a capitalisation defect. An undefined `contains` must not reach the query
23
+ * as `text: undefined` — that is a locator asking for the empty string.
24
+ */
25
+ export declare function textPredicateQuery(predicate: {
26
+ contains?: string | undefined;
27
+ ignoreCase?: boolean | undefined;
28
+ scope?: string | undefined;
29
+ self?: boolean | undefined;
30
+ }): ElementQuery;