@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
@@ -1,4 +1,4 @@
1
- import { PredicateKind, REDACTED_VALUE } from '@reticlehq/core';
1
+ import { PredicateKind, REDACTED_VALUE, selectPath } from '@reticlehq/core';
2
2
  export function str(value) {
3
3
  return 'string' === typeof value ? value : undefined;
4
4
  }
@@ -96,16 +96,116 @@ function structurallyEqual(got, want) {
96
96
  return false;
97
97
  return keys.every((k) => k in b && structurallyEqual(a[k], b[k]));
98
98
  }
99
- /** Shallow JSON pattern match: each key in `pattern` must match (see matchValue). */
99
+ /**
100
+ * Read one pattern key out of a payload.
101
+ *
102
+ * A key the payload holds AS WRITTEN wins, so a literal `"a.b"` key keeps meaning what it always
103
+ * meant. Otherwise a dotted key is a path in the grammar `state.path` already speaks — own keys and
104
+ * canonical array indices, via `selectPath` — because most APIs wrap their answer
105
+ * (`{ data: { status } }`) and a top-level-only match left `bodyContains` as the only reach for a
106
+ * nested field, the substring a key name has already fooled once.
107
+ */
108
+ export function readField(actual, key) {
109
+ if (Object.hasOwn(actual, key))
110
+ return { found: true, value: actual[key] };
111
+ if (!key.includes('.'))
112
+ return { found: false, value: undefined, availableKeys: Object.keys(actual) };
113
+ const selection = selectPath(actual, key);
114
+ return selection.found
115
+ ? { found: true, value: selection.value }
116
+ : {
117
+ found: false,
118
+ value: undefined,
119
+ ...(selection.availableKeys === undefined
120
+ ? {}
121
+ : { availableKeys: selection.availableKeys }),
122
+ };
123
+ }
124
+ /**
125
+ * JSON pattern match: each key in `pattern` must match (see matchValue).
126
+ *
127
+ * A key is a field name or a dotted path to one (see readField). A nested literal OBJECT is still
128
+ * compared whole, as `equals` is: loosening that would quietly turn every existing exact assertion
129
+ * into a partial one, and the dotted path is the field-by-field form.
130
+ */
100
131
  export function dataMatches(actual, pattern) {
101
132
  for (const [key, want] of Object.entries(pattern)) {
102
- if (!matchValue(actual[key], want))
133
+ if (!matchValue(readField(actual, key).value, want))
103
134
  return false;
104
135
  }
105
136
  return true;
106
137
  }
107
138
  /**
108
- * Shallow JSON field match over a captured body, for either half of the exchange.
139
+ * The first pattern key that did not hold, said the way an agent can act on: what the field held,
140
+ * or that it was missing and which keys were there instead.
141
+ *
142
+ * A whole-object comparison that failed only because the payload carries MORE keys gets told the
143
+ * dotted path that would have matched the one field, because that is the mistake it almost always is.
144
+ */
145
+ export function describeFieldMiss(actual, pattern) {
146
+ for (const [key, want] of Object.entries(pattern)) {
147
+ const reading = readField(actual, key);
148
+ if (matchValue(reading.value, want))
149
+ continue;
150
+ if (!reading.found) {
151
+ const keys = reading.availableKeys ?? [];
152
+ return `${JSON.stringify(key)} is missing${0 === keys.length ? '' : ` (keys there: ${keys.join(', ')})`}`;
153
+ }
154
+ const held = `${JSON.stringify(key)} is ${JSON.stringify(reading.value)}`;
155
+ const firstNested = nestedLiteralKey(want);
156
+ return firstNested === undefined
157
+ ? held
158
+ : `${held} — a nested object is compared WHOLE; to match one field, key it by its path: ${JSON.stringify(`${key}.${firstNested}`)}`;
159
+ }
160
+ return undefined;
161
+ }
162
+ /** The first key of a nested literal object pattern, or undefined for anything else. */
163
+ function nestedLiteralKey(want) {
164
+ if ('object' !== typeof want || null === want || Array.isArray(want))
165
+ return undefined;
166
+ const keys = Object.keys(want);
167
+ if (keys.some((k) => k.startsWith('$')))
168
+ return undefined;
169
+ return keys[0];
170
+ }
171
+ /** The same, over a captured body — undefined when the body is not a JSON object. */
172
+ export function describeBodyFieldMiss(body, pattern) {
173
+ const actual = parseJsonObject(body);
174
+ return actual === undefined ? undefined : describeFieldMiss(actual, pattern);
175
+ }
176
+ export function parseJsonObject(body) {
177
+ let payload;
178
+ try {
179
+ payload = JSON.parse(body);
180
+ }
181
+ catch {
182
+ return undefined;
183
+ }
184
+ if (null === payload || 'object' !== typeof payload || Array.isArray(payload))
185
+ return undefined;
186
+ return payload;
187
+ }
188
+ /**
189
+ * Did redaction hide this key, at it or at any parent on its path?
190
+ *
191
+ * A parent redacted wholesale (`{ secrets: "[REDACTED]" }`) makes every field under it unreadable,
192
+ * and reporting that as "missing" would blame the server for the observer's own redaction.
193
+ */
194
+ export function redactedOnPath(actual, key) {
195
+ if (Object.hasOwn(actual, key))
196
+ return REDACTED_VALUE === actual[key];
197
+ const segments = key.split('.');
198
+ for (let i = 1; i <= segments.length; i += 1) {
199
+ const prefix = selectPath(actual, segments.slice(0, i).join('.'));
200
+ if (!prefix.found)
201
+ return false;
202
+ if (REDACTED_VALUE === prefix.value)
203
+ return true;
204
+ }
205
+ return false;
206
+ }
207
+ /**
208
+ * JSON field match over a captured body, for either half of the exchange.
109
209
  *
110
210
  * One function because both halves ask the identical question, and the request side already had
111
211
  * this exact sequence written out — parse, reject a non-object, check the wanted keys for
@@ -116,17 +216,10 @@ export function dataMatches(actual, pattern) {
116
216
  * exist for those bodies.
117
217
  */
118
218
  export function matchJsonBody(body, pattern) {
119
- let payload;
120
- try {
121
- payload = JSON.parse(body);
122
- }
123
- catch {
124
- return 'mismatch';
125
- }
126
- if (null === payload || 'object' !== typeof payload || Array.isArray(payload))
219
+ const actual = parseJsonObject(body);
220
+ if (actual === undefined)
127
221
  return 'mismatch';
128
- const actual = payload;
129
- const redacted = Object.keys(pattern).find((key) => REDACTED_VALUE === actual[key]);
222
+ const redacted = Object.keys(pattern).find((key) => redactedOnPath(actual, key));
130
223
  if (redacted !== undefined)
131
224
  return { redacted };
132
225
  return dataMatches(actual, pattern) ? 'match' : 'mismatch';
@@ -4,6 +4,12 @@ import type { Predicate } from './predicate-schema.js';
4
4
  import { type EvalResult } from './predicate-eval-kit.js';
5
5
  export { clipBody, dataMatches, describeNetFilter, matchValue, str, type EvalResult, } from './predicate-eval-kit.js';
6
6
  export * from './predicate-schema.js';
7
+ /**
8
+ * Whether a request was a subresource the DOCUMENT fetched (script, stylesheet, image…), as the
9
+ * resource-timing observer stamps them, rather than one the app sent through fetch, XHR, a beacon or
10
+ * IPC. The capsule's blast radius uses it to keep a page load out of "what this action also did".
11
+ */
12
+ export declare function isDocumentInitiated(event: ReticleEvent): boolean;
7
13
  export declare function evalNet(events: ReticleEvent[], p: Extract<Predicate, {
8
14
  kind: typeof PredicateKind.NET;
9
15
  }>): EvalResult;
@@ -3,7 +3,7 @@ import { describeObserved } from './observed-in-window.js';
3
3
  import { netEvidence } from './net-evidence.js';
4
4
  import { checkRequestBody, newRequestBodyState, requestBodyVerdict, } from './predicate-request-body.js';
5
5
  export { evalConsole } from './predicate-console.js';
6
- import { clipBody, dataMatches, describeNetFilter, matchJsonBody, num, str, } from './predicate-eval-kit.js';
6
+ import { clipBody, dataMatches, describeBodyFieldMiss, describeFieldMiss, describeNetFilter, matchJsonBody, num, redactedOnPath, str, } from './predicate-eval-kit.js';
7
7
  import { keyFragmentOnly } from './body-key-fragment.js';
8
8
  export { clipBody, dataMatches, describeNetFilter, matchValue, str, } from './predicate-eval-kit.js';
9
9
  // The predicate SHAPE — the discriminated union, its aliases and its zod schema — lives in
@@ -220,6 +220,17 @@ const DOCUMENT_INITIATORS = new Set([
220
220
  'manifest',
221
221
  'other',
222
222
  ]);
223
+ /**
224
+ * Whether a request was a subresource the DOCUMENT fetched (script, stylesheet, image…), as the
225
+ * resource-timing observer stamps them, rather than one the app sent through fetch, XHR, a beacon or
226
+ * IPC. The capsule's blast radius uses it to keep a page load out of "what this action also did".
227
+ */
228
+ export function isDocumentInitiated(event) {
229
+ if (event.type !== EventType.NET_REQUEST)
230
+ return false;
231
+ const initiator = str(event.data['initiator']);
232
+ return initiator !== undefined && DOCUMENT_INITIATORS.has(initiator);
233
+ }
223
234
  /**
224
235
  * Did the observer actually report a document-initiated load?
225
236
  *
@@ -232,12 +243,7 @@ const DOCUMENT_INITIATORS = new Set([
232
243
  * document-initiated record anywhere in the window proves the channel works.
233
244
  */
234
245
  function observerSawSubresources(events) {
235
- return events.some((e) => {
236
- if (e.type !== EventType.NET_REQUEST)
237
- return false;
238
- const initiator = str(e.data['initiator']);
239
- return initiator !== undefined && DOCUMENT_INITIATORS.has(initiator);
240
- });
246
+ return events.some(isDocumentInitiated);
241
247
  }
242
248
  /** The sentence both zero-match branches hand to `inconclusive`. */
243
249
  function unobservedChannelReason(p) {
@@ -450,7 +456,7 @@ export function evalNet(events, p) {
450
456
  if (truncatedBody !== undefined && 0 === matches.length) {
451
457
  return {
452
458
  pass: false,
453
- inconclusive: `a call matching ${describeNetFilter(p)} was answered with a body that was TRUNCATED before it was recorded, and ${wantedBody(p)} is not in the part that was kept — so this is undecidable, not a failure. Raise the capture cap or assert on something inside the recorded prefix`,
459
+ inconclusive: `a call matching ${describeNetFilter(p)} was answered with a body that was TRUNCATED before it was recorded, and ${wantedBody(p)} is not in the part that was kept — so this is undecidable, not a failure. The cap is per-body and set where the app calls connect(): \`reticle.connect({ captureNetworkBodies: true, networkBodyMaxChars: 65536 })\`, or for the Vite plugin \`reticle({ networkBodyMaxChars: 65536 })\` / VITE_RETICLE_BODY_MAX_CHARS=65536 (default 8192, max 262144). An SDK older than this daemon ignores the option; a version skew on the session says so. Raise it past this response's size and re-run, or assert on something inside the recorded prefix`,
454
460
  observed: `the first ${String(truncatedBody.length)} characters of a truncated response body ${JSON.stringify(clipBody(truncatedBody))}`,
455
461
  expected: `a response body carrying ${wantedBody(p)}`,
456
462
  assertion: 'net.bodyContains',
@@ -458,11 +464,14 @@ export function evalNet(events, p) {
458
464
  }
459
465
  if (bodyMismatch !== undefined && 0 === matches.length) {
460
466
  // The call is there and its body is there; only the VALUE differs. Counting it as zero matches
461
- // points at the wiring, which is the one place the defect is not.
467
+ // points at the wiring, which is the one place the defect is not. A field clause also names the
468
+ // field that differed, because a 200-character clip may not reach it.
469
+ const field = p.bodyMatches === undefined ? undefined : describeBodyFieldMiss(bodyMismatch, p.bodyMatches);
470
+ const because = field === undefined ? '' : `: ${field}`;
462
471
  return {
463
472
  pass: false,
464
- failureReason: `a call matching ${describeNetFilter(p)} was made and answered ${JSON.stringify(clipBody(bodyMismatch))}, which does not carry ${wantedBody(p)} — the request fired, the response value is what differed`,
465
- observed: `response body ${JSON.stringify(clipBody(bodyMismatch))}`,
473
+ failureReason: `a call matching ${describeNetFilter(p)} was made and answered ${JSON.stringify(clipBody(bodyMismatch))}, which does not carry ${wantedBody(p)}${because} — the request fired, the response value is what differed`,
474
+ observed: `response body ${JSON.stringify(clipBody(bodyMismatch))}${because}`,
466
475
  expected: `a response body carrying ${wantedBody(p)}`,
467
476
  assertion: 'net.bodyContains',
468
477
  };
@@ -553,6 +562,12 @@ export function evalAnimation(events, p) {
553
562
  };
554
563
  }
555
564
  export function evalSignal(events, p) {
565
+ /**
566
+ * A pattern key the transport sanitizer redacted on a payload of the right name. The marker is
567
+ * written for a sensitive key whatever it held, so neither `*` nor a value can be judged against it
568
+ * — the same rule the body clauses keep.
569
+ */
570
+ let redactedField;
556
571
  const isMatch = (e) => {
557
572
  if (e.type !== EventType.SIGNAL)
558
573
  return false;
@@ -560,19 +575,43 @@ export function evalSignal(events, p) {
560
575
  return false;
561
576
  if (p.dataMatches !== undefined) {
562
577
  const payload = (e.data['data'] ?? {});
578
+ const hidden = 'object' === typeof payload
579
+ ? Object.keys(p.dataMatches).find((key) => redactedOnPath(payload, key))
580
+ : undefined;
581
+ if (hidden !== undefined) {
582
+ redactedField ??= hidden;
583
+ return false;
584
+ }
563
585
  if (!dataMatches(payload, p.dataMatches))
564
586
  return false;
565
587
  }
566
588
  return true;
567
589
  };
590
+ const redactedVerdict = () => {
591
+ if (redactedField === undefined)
592
+ return undefined;
593
+ const field = JSON.stringify(redactedField);
594
+ return {
595
+ pass: false,
596
+ inconclusive: `signal '${p.name ?? '(any)'}' fired, but its ${field} was REDACTED before it was recorded, so this clause cannot be judged — a redacted field is unknown, not different. Assert on a non-sensitive key, or on the effect the value had`,
597
+ observed: `a signal payload whose ${field} is ${REDACTED_VALUE}`,
598
+ expected: `signal '${p.name ?? '(any)'}' with payload matching ${JSON.stringify(p.dataMatches)}`,
599
+ assertion: 'signal.payload',
600
+ };
601
+ };
568
602
  // `count` (exact) turns presence into a cardinality assertion, exactly as it does on `net`. The
569
603
  // double-fire is invisible to every state-only oracle — a handler wired twice leaves the store in
570
604
  // the right shape and fires the signal twice — and so is the wrong-name fire, where the intended
571
605
  // signal fires once beside a mistyped sibling and a presence check cannot say which is which.
572
606
  // Counting only what the MATCHER matched is what separates them. Omit = presence (≥1).
573
607
  if (p.count !== undefined) {
608
+ const matched = events.filter(isMatch).length;
609
+ // A redacted payload might have been one of the matches, so no count over it is decided.
610
+ const unjudgeable = redactedVerdict();
611
+ if (unjudgeable !== undefined)
612
+ return unjudgeable;
574
613
  return evalExactCount({
575
- matched: events.filter(isMatch).length,
614
+ matched,
576
615
  want: p.count,
577
616
  noun: 'signal(s)',
578
617
  filter: describeSignalFilter(p),
@@ -582,17 +621,25 @@ export function evalSignal(events, p) {
582
621
  const hit = events.find(isMatch);
583
622
  if (hit !== undefined)
584
623
  return { pass: true, evidence: hit.data };
624
+ // `find` scanned every event to get here, so a redacted payload has been seen if there was one.
625
+ const unjudgeable = redactedVerdict();
626
+ if (unjudgeable !== undefined)
627
+ return unjudgeable;
585
628
  // Near-miss: show signals that fired with the same name (so the agent sees the real data).
586
629
  const sameName = events
587
630
  .filter((e) => e.type === EventType.SIGNAL && (p.name === undefined || str(e.data['name']) === p.name))
588
631
  .map((e) => e.data['data'] ?? e.data);
632
+ const first = sameName[0];
633
+ const fieldMiss = p.dataMatches !== undefined && 'object' === typeof first && first !== null
634
+ ? describeFieldMiss(first, p.dataMatches)
635
+ : undefined;
589
636
  return {
590
637
  pass: false,
591
638
  failureReason: sameName.length > 0
592
639
  ? `signal '${p.name ?? '(any)'}' fired ${String(sameName.length)}x but data didn't match`
593
640
  : `no signal matched ${JSON.stringify(p)}`,
594
641
  observed: sameName.length > 0
595
- ? `signal '${p.name ?? '(any)'}' fired ${String(sameName.length)}x, payload: ${JSON.stringify(sameName[0])}`
642
+ ? `signal '${p.name ?? '(any)'}' fired ${String(sameName.length)}x, payload: ${JSON.stringify(first)}${fieldMiss === undefined ? '' : `; ${fieldMiss}`}`
596
643
  : // Name what DID fire: a typo'd signal name and a genuinely dead action produce the same
597
644
  // sentence otherwise, and the agent cannot tell them apart. See observed-in-window.ts.
598
645
  `signal '${p.name ?? '(any)'}' never fired; ${describeObserved('signals', events.filter((e) => e.type === EventType.SIGNAL).map((e) => str(e.data['name']) ?? ''))}`,
@@ -34,6 +34,7 @@ const EXAMPLES = {
34
34
  [PredicateKind.SIGNAL]: '{ kind: "signal", name: "todos:loaded" }',
35
35
  [PredicateKind.STATE]: '{ kind: "state", path: "cart.total", equals: 0 }',
36
36
  [PredicateKind.SETTLED]: '{ kind: "settled" }',
37
+ [PredicateKind.COMPARE]: '{ kind: "compare", left: { from: "text", scope: "#total" }, right: { from: "net", urlContains: "/api/cart", path: "total" }, as: "number" }',
37
38
  [PredicateKind.ALL_OF]: '{ kind: "allOf", predicates: [{ kind: "text", contains: "Saved" }, { kind: "console", level: "error", absent: true }] }',
38
39
  [PredicateKind.ANY_OF]: '{ kind: "anyOf", predicates: [{ kind: "text", contains: "Saved" }, { kind: "text", contains: "Updated" }] }',
39
40
  [PredicateKind.NOT]: '{ kind: "not", predicate: { kind: "text", contains: "Error" } }',
@@ -16,7 +16,7 @@
16
16
  * nothing to report." This is that, applied one step earlier.
17
17
  */
18
18
  import { PredicateKind } from '@reticlehq/core';
19
- import { residualQueryChecks } from './predicate-schema.js';
19
+ import { describeUnusableElementQuery, residualQueryChecks } from './predicate-schema.js';
20
20
  /** Composite predicates nest; the unusable one can be at any depth. */
21
21
  const NESTED_KEYS = ['predicates', 'predicate'];
22
22
  const isRecord = (v) => 'object' === typeof v && null !== v;
@@ -48,10 +48,8 @@ export function unevaluablePredicateReason(predicate) {
48
48
  const residual = residualQueryChecks(query);
49
49
  if (0 === residual.unusable.length)
50
50
  continue;
51
- return (`the element locator ignores ${residual.unusable.map((f) => `\`${f}\``).join(', ')} ` +
52
- `in ${JSON.stringify(query)} — it resolves by the first of by+value, component/source, role, ` +
53
- 'text, label, placeholder, testid, alt that is present, and nothing here can check the rest. ' +
54
- 'Assert them one locator at a time, or move the extra field into the locator. ' +
51
+ return (describeUnusableElementQuery(query, residual.unusable) +
52
+ ' ' +
55
53
  'Nothing was acted on: this predicate could never have been evaluated, so refusing it costs ' +
56
54
  'you nothing and spending the action on it would have cost you the verdict.');
57
55
  }
@@ -16,7 +16,7 @@ interface RequestBodyPredicate {
16
16
  * Accumulated during the single pass over events rather than recomputed after it, the way the
17
17
  * response-side trackers already are.
18
18
  */
19
- export interface RequestBodyState {
19
+ interface RequestBodyState {
20
20
  /** A call matched everything else but carried no recorded request body. */
21
21
  unrecorded: boolean;
22
22
  /** The request body a clause was checked against and did not match. */
@@ -14,7 +14,7 @@
14
14
  * Extracted from `predicate-eval.ts`, which was at the 1000-line cap.
15
15
  */
16
16
  import { REDACTED_VALUE } from '@reticlehq/core';
17
- import { clipBody, describeNetFilter, matchJsonBody, str, } from './predicate-eval-kit.js';
17
+ import { clipBody, describeBodyFieldMiss, describeNetFilter, matchJsonBody, str, } from './predicate-eval-kit.js';
18
18
  export function newRequestBodyState() {
19
19
  return { unrecorded: false };
20
20
  }
@@ -99,10 +99,14 @@ export function requestBodyVerdict(state, predicate, matchCount) {
99
99
  // Named separately from "no call matched", for the reason the response side already learned: the
100
100
  // request DID fire, and reporting zero matches sends the caller to check the url and the method,
101
101
  // which are both fine, instead of to the value the UI actually sent.
102
+ const field = predicate.requestBodyMatches === undefined
103
+ ? undefined
104
+ : describeBodyFieldMiss(state.mismatch, predicate.requestBodyMatches);
105
+ const because = field === undefined ? '' : `: ${field}`;
102
106
  return {
103
107
  pass: false,
104
- failureReason: `a call matching ${describeNetFilter(predicate)} was sent with ${JSON.stringify(clipBody(state.mismatch))}, which does not match the request-body clause — the request fired, the payload is what differed`,
105
- observed: `request body ${JSON.stringify(clipBody(state.mismatch))}`,
108
+ failureReason: `a call matching ${describeNetFilter(predicate)} was sent with ${JSON.stringify(clipBody(state.mismatch))}, which does not match the request-body clause${because} — the request fired, the payload is what differed`,
109
+ observed: `request body ${JSON.stringify(clipBody(state.mismatch))}${because}`,
106
110
  expected: `a request body matching ${wanted}`,
107
111
  assertion: 'net.requestBody',
108
112
  };
@@ -38,7 +38,7 @@ export declare function routePathOf(pathname: string, hash: string): string;
38
38
  * is the NAVIGABLE value a `reticle_navigate` can be pointed at. Call sites pick; collapsing
39
39
  * them into one string is how a hash-router miss lands as "every page is `/`".
40
40
  */
41
- export interface RouteParts {
41
+ interface RouteParts {
42
42
  routePath: string;
43
43
  docPath: string;
44
44
  hash: string;
@@ -64,3 +64,4 @@ export declare function evalRoute(events: ReticleEvent[], p: Extract<Predicate,
64
64
  currentUrl?: string,
65
65
  /** Event-time floor for the window, so a request already in flight before it is not counted. */
66
66
  since?: number): EvalResult;
67
+ export {};
@@ -1,95 +1,16 @@
1
- import { ElementState, PredicateKind, type ElementDescriptor, type ElementQuery } from '@reticlehq/core';
1
+ /**
2
+ * What the predicate engine adds to the CONTRACT: the fields a browser locator drops, and the
3
+ * introspection the tool surface builds its descriptions from.
4
+ *
5
+ * The shape itself — `Predicate`, `PredicateSchema`, the aliases and the union — moved to
6
+ * `@reticlehq/core`, because a saved flow now carries one and core has to be able to parse what it
7
+ * reads off disk. Core is the contract; this is the reasoning over it. Both halves are re-exported
8
+ * from here, so every existing importer of this module keeps working unchanged.
9
+ */
2
10
  import { z } from 'zod';
3
- import { type PropertyAssertion } from './property.js';
4
- export type Predicate = {
5
- kind: typeof PredicateKind.ELEMENT;
6
- query: ElementQuery;
7
- state?: ElementState;
8
- absent?: boolean;
9
- } | {
10
- kind: typeof PredicateKind.TEXT;
11
- contains: string;
12
- visible?: boolean;
13
- absent?: boolean;
14
- /**
15
- * Restrict the match to a subtree, as a CSS selector or a ref — the same field, and the same
16
- * meaning, as `scope` on an element query.
17
- *
18
- * Without it the match is page-wide, and a word that appears both in a background tab label
19
- * and in the dialog that just opened satisfies the predicate BEFORE the action runs, so
20
- * `act_and_wait` reports `already_true` for an action that did exactly the right thing.
21
- */
22
- scope?: string;
23
- /** Match the scope root itself and check its combined subtree text. Requires `scope`. */
24
- self?: boolean;
25
- } | {
26
- kind: typeof PredicateKind.NET;
27
- method?: string;
28
- urlContains?: string;
29
- status?: number;
30
- /** Did the call succeed? The honest field for IPC, which has no status code. */
31
- ok?: boolean;
32
- since?: number;
33
- count?: number;
34
- /** A substring the RESPONSE body must contain — what the server answered, not what was sent. */
35
- bodyContains?: string;
36
- /** Shallow JSON match over the RESPONSE body: this FIELD holds this value (#987). */
37
- bodyMatches?: Record<string, unknown>;
38
- /** A substring the REQUEST body must contain — what the UI sent, not what came back. */
39
- requestBodyContains?: string;
40
- /** Shallow JSON match over the REQUEST body, in the style of `signal.dataMatches`. */
41
- requestBodyMatches?: Record<string, unknown>;
42
- } | {
43
- kind: typeof PredicateKind.ROUTE;
44
- pathname?: string;
45
- contains?: string;
46
- since?: number;
47
- } | {
48
- kind: typeof PredicateKind.CONSOLE;
49
- level?: string;
50
- /**
51
- * A substring the captured message must contain. With `absent: true` this flips the meaning
52
- * from "no console entries at all" to "THIS message did not appear" — the assertion people
53
- * actually write regression checks for (deprecation warnings, no-op handler notices).
54
- */
55
- contains?: string;
56
- absent?: boolean;
57
- since?: number;
58
- } | {
59
- kind: typeof PredicateKind.ANIMATION;
60
- name?: string;
61
- target?: string;
62
- completed?: boolean;
63
- since?: number;
64
- } | {
65
- kind: typeof PredicateKind.SIGNAL;
66
- name?: string;
67
- dataMatches?: Record<string, unknown>;
68
- /**
69
- * Exact number of matching signals in the window — the same cardinality assertion `net`
70
- * carries, on the channel the app itself speaks. Omit for presence (≥1).
71
- */
72
- count?: number;
73
- since?: number;
74
- } | {
75
- kind: typeof PredicateKind.STATE;
76
- store?: string;
77
- path: string;
78
- equals?: unknown;
79
- satisfies?: PropertyAssertion;
80
- } | {
81
- kind: typeof PredicateKind.SETTLED;
82
- quietMs?: number;
83
- } | {
84
- kind: typeof PredicateKind.ALL_OF;
85
- predicates: Predicate[];
86
- } | {
87
- kind: typeof PredicateKind.ANY_OF;
88
- predicates: Predicate[];
89
- } | {
90
- kind: typeof PredicateKind.NOT;
91
- predicate: Predicate;
92
- };
11
+ import { type ElementDescriptor, type ElementQuery } from '@reticlehq/core';
12
+ export { PredicateSchema } from '@reticlehq/core';
13
+ export type { Predicate, PropertyAssertion } from '@reticlehq/core';
93
14
  interface ResidualQueryChecks {
94
15
  /** Dropped fields this side CAN check, as [field, wanted value] pairs. */
95
16
  checks: [string, string][];
@@ -105,11 +26,12 @@ interface ResidualQueryChecks {
105
26
  * outcome the caller was already assuming.
106
27
  */
107
28
  export declare function residualQueryChecks(query: ElementQuery): ResidualQueryChecks;
29
+ /** Explain an element query whose locator drops fields it cannot verify. */
30
+ export declare function describeUnusableElementQuery(query: ElementQuery, unusable: readonly string[]): string;
108
31
  /** Does this element satisfy every field the locator dropped? */
109
32
  export declare function satisfiesResiduals(element: ElementDescriptor, checks: readonly [string, string][]): boolean;
110
33
  /** How the element's own reading of a dropped field should be REPORTED back on a failure. */
111
34
  export declare function describeResidual(element: ElementDescriptor, field: string): string;
112
- export declare const PredicateSchema: z.ZodType<Predicate>;
113
35
  /**
114
36
  * The fields a given predicate kind accepts, read off the schema itself.
115
37
  *
@@ -169,4 +91,3 @@ export declare function nestedKeysOf(schema: z.ZodTypeAny | undefined): readonly
169
91
  * list is worse than none, because the agent trusts it and retries into the same wall.
170
92
  */
171
93
  export declare function predicateNestedFieldsFor(kind: string): Readonly<Record<string, readonly string[]>>;
172
- export {};