@reticlehq/engine 3.6.0 → 3.8.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 (54) hide show
  1. package/dist/disagreement/contradiction-evidence.d.ts +134 -2
  2. package/dist/disagreement/contradiction-evidence.js +291 -3
  3. package/dist/disagreement/contradiction-types.d.ts +16 -1
  4. package/dist/disagreement/contradictions.d.ts +12 -0
  5. package/dist/disagreement/contradictions.js +56 -84
  6. package/dist/disagreement/stale-response.js +56 -17
  7. package/dist/evidence/already-true.d.ts +5 -0
  8. package/dist/evidence/already-true.js +27 -6
  9. package/dist/evidence/baseline.js +2 -6
  10. package/dist/evidence/blind-spots.d.ts +14 -3
  11. package/dist/evidence/blind-spots.js +48 -10
  12. package/dist/evidence/body-capture-remedy.d.ts +1 -15
  13. package/dist/evidence/body-capture-remedy.js +6 -1
  14. package/dist/evidence/instrumentation-gaps.js +3 -1
  15. package/dist/evidence/state-bookkeeping.d.ts +2 -0
  16. package/dist/evidence/state-bookkeeping.js +2 -0
  17. package/dist/evidence/step-effect.d.ts +20 -1
  18. package/dist/evidence/step-effect.js +30 -2
  19. package/dist/evidence/superseded-checks.d.ts +29 -0
  20. package/dist/evidence/superseded-checks.js +30 -0
  21. package/dist/evidence/uncaptured-bodies.d.ts +18 -1
  22. package/dist/evidence/uncaptured-bodies.js +22 -1
  23. package/dist/evidence/unread-outcome.d.ts +7 -0
  24. package/dist/evidence/unread-outcome.js +22 -0
  25. package/dist/evidence/unsettled.js +29 -2
  26. package/dist/evidence/verified.d.ts +8 -1
  27. package/dist/evidence/verified.js +33 -5
  28. package/dist/question/declared.d.ts +20 -0
  29. package/dist/question/declared.js +20 -1
  30. package/dist/question/predicate/net-blind-spots.d.ts +49 -0
  31. package/dist/question/predicate/net-blind-spots.js +153 -0
  32. package/dist/question/predicate/predicate-compare.js +7 -1
  33. package/dist/question/predicate/predicate-console.js +23 -10
  34. package/dist/question/predicate/predicate-element.d.ts +23 -0
  35. package/dist/question/predicate/predicate-element.js +208 -16
  36. package/dist/question/predicate/predicate-eval-kit.d.ts +28 -3
  37. package/dist/question/predicate/predicate-eval-kit.js +34 -7
  38. package/dist/question/predicate/predicate-eval.d.ts +11 -1
  39. package/dist/question/predicate/predicate-eval.js +138 -177
  40. package/dist/question/predicate/predicate-parse.js +34 -0
  41. package/dist/question/predicate/predicate-request-body.d.ts +15 -1
  42. package/dist/question/predicate/predicate-request-body.js +23 -3
  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 +52 -1
  47. package/dist/question/predicate/predicate-state.js +7 -0
  48. package/dist/question/predicate/predicate.js +58 -18
  49. package/dist/question/predicate/split-text-miss.d.ts +7 -0
  50. package/dist/question/predicate/split-text-miss.js +18 -1
  51. package/dist/state-bookkeeping.d.ts +27 -0
  52. package/dist/state-bookkeeping.js +74 -0
  53. package/dist/window/adversary.js +5 -1
  54. package/package.json +2 -2
@@ -1,10 +1,6 @@
1
- import { PredicateKind, REDACTED_VALUE, selectPath } from '@reticlehq/core';
2
- export function str(value) {
3
- return 'string' === typeof value ? value : undefined;
4
- }
5
- export function num(value) {
6
- return 'number' === typeof value ? value : undefined;
7
- }
1
+ import { PredicateKind, REDACTED_VALUE, asNumber, asString, selectPath } from '@reticlehq/core';
2
+ /** Core's `asString` and `asNumber`, under the names the oracles here read them by. */
3
+ export { asString as str, asNumber as num };
8
4
  /**
9
5
  * Match one value against a pattern. Supports `*` (present), strict equality, and operators:
10
6
  * `{$gte,$lte,$gt,$lt}` (numbers), `{$contains}` (array membership or substring), `{$length}`.
@@ -66,6 +62,37 @@ export function matchValue(got, want) {
66
62
  }
67
63
  return structurallyEqual(got, want);
68
64
  }
65
+ /**
66
+ * Detects the #1117 pattern: an MCP client stringified a primitive before sending it, so
67
+ * `false` arrived as `"false"`, `42` as `"42"`, `null` as `"null"`. The store holds the real
68
+ * type and the comparison is a type mismatch, not a value mismatch — inconclusive, not `no`.
69
+ */
70
+ export function isStringifiedPrimitiveMismatch(got, want) {
71
+ if ('string' !== typeof want)
72
+ return false;
73
+ if ('boolean' === typeof got || 'number' === typeof got || null === got) {
74
+ return String(got) === want;
75
+ }
76
+ return false;
77
+ }
78
+ /**
79
+ * The inconclusive result for a stringified-primitive mismatch on a state `equals` check.
80
+ * Shared by both `evalStateNamed` and `evalState` so the reason and evidence shape stay in one
81
+ * place.
82
+ */
83
+ export function stringifiedPrimitiveResult(storeName, path, got, want, capDepth) {
84
+ const gotType = null === got ? 'null' : typeof got;
85
+ const reason = `state '${path}' is ${JSON.stringify(got)} (${gotType}), ` +
86
+ `but the expected value ${JSON.stringify(want)} is a string that looks like its stringified form — ` +
87
+ `use the ${gotType} literal ${JSON.stringify(got)} instead`;
88
+ return {
89
+ pass: false,
90
+ failureReason: reason,
91
+ inconclusive: reason,
92
+ assertion: 'state.equals',
93
+ evidence: { store: storeName, path, value: capDepth(got, 1) },
94
+ };
95
+ }
69
96
  /**
70
97
  * Value equality for the leaf comparison, because `===` could never match a literal.
71
98
  *
@@ -10,6 +10,16 @@ export * from './predicate-schema.js';
10
10
  * IPC. The capsule's blast radius uses it to keep a page load out of "what this action also did".
11
11
  */
12
12
  export declare function isDocumentInitiated(event: ReticleEvent): boolean;
13
+ /**
14
+ * The remedy for a body the SDK skipped ON PURPOSE with capture on, or `undefined` (#1520).
15
+ *
16
+ * Shared by every message that would otherwise say "enable captureNetworkBodies": that advice is
17
+ * wrong when capture is already on and the body was a stream, a binary type, or a read that did
18
+ * not finish. `undefined` means no reason was stamped: capture was off, or the SDK predates it.
19
+ */
20
+ export declare function skippedBodyRemedy(reason: unknown): string | undefined;
21
+ /** The skip reason every one of these calls carries, when they all carry the same one. */
22
+ export declare function sharedSkipReason(reasons: readonly unknown[]): unknown;
13
23
  export declare function evalNet(events: ReticleEvent[], p: Extract<Predicate, {
14
24
  kind: typeof PredicateKind.NET;
15
25
  }>): EvalResult;
@@ -37,7 +47,7 @@ export interface SettleScope {
37
47
  /**
38
48
  * "The page has gone quiet": no network/DOM/animation activity for at least `quietMs`. Needs the
39
49
  * wall-clock `now` (in the buffer's time base) because "no activity in the last N ms" is relative to
40
- * now, not to any buffered event — so `now` is injected (CLAUDE.md rule 7), and the wait loop's
50
+ * now, not to any buffered event — so `now` is injected (AGENTS.md rule 7), and the wait loop's
41
51
  * poll interval is what eventually flips this to pass once activity stops.
42
52
  */
43
53
  export declare function evalSettled(allEvents: ReticleEvent[], p: Extract<Predicate, {
@@ -1,11 +1,25 @@
1
- import { EventType, NetInitiator, PredicateKind, StreamDirection, isDevToolingUrl, isForeignTraffic, urlForMatch, REDACTED_VALUE, } from '@reticlehq/core';
1
+ import { EventType, NetInitiator, PredicateKind, ResponseBodyReason, SettledChannel, StreamDirection, isDevToolingUrl, isForeignTraffic, urlForMatch, REDACTED_VALUE, } from '@reticlehq/core';
2
+ import { isReticleVoice } from '../../state-bookkeeping.js';
2
3
  import { describeObserved } from './observed-in-window.js';
3
4
  import { netEvidence } from './net-evidence.js';
4
5
  import { checkRequestBody, newRequestBodyState, requestBodyVerdict, } from './predicate-request-body.js';
5
6
  export { evalConsole } from './predicate-console.js';
6
7
  import { clipBody, dataMatches, describeBodyFieldMiss, describeFieldMiss, describeNetFilter, matchJsonBody, num, redactedOnPath, str, } from './predicate-eval-kit.js';
7
8
  import { keyFragmentOnly } from './body-key-fragment.js';
9
+ import { PRE_ATTACH_CAVEAT, nativeDownloadReason, targetsNativeDownload, targetsUnobservedChannel, unobservedChannelReason, } from './net-blind-spots.js';
8
10
  export { clipBody, dataMatches, describeNetFilter, matchValue, str, } from './predicate-eval-kit.js';
11
+ /** The oracle a net body clause reports, so an agent can branch on which one decided. */
12
+ const NetBodyAssertion = {
13
+ CONTAINS: 'net.bodyContains',
14
+ MATCHES: 'net.bodyMatches',
15
+ };
16
+ /** A truncated body missed a `bodyContains`: the kept prefix can still answer a substring. */
17
+ const TRUNCATED_PREFIX_REMEDY = "Raise it past this response's size and re-run, or assert on something inside the recorded prefix";
18
+ /**
19
+ * A truncated body missed a `bodyMatches`. That clause parses the whole body and a JSON prefix never
20
+ * parses, so "assert inside the prefix" changes nothing for it (#1417): name what can work instead.
21
+ */
22
+ const TRUNCATED_MATCHES_REMEDY = "Raise it past this response's size and re-run. `bodyMatches` parses the whole body, and a JSON prefix never parses, so it cannot be judged on the kept part: to assert on what was kept, use `bodyContains` with a substring from it";
9
23
  // The predicate SHAPE — the discriminated union, its aliases and its zod schema — lives in
10
24
  // predicate-schema.ts, and is re-exported here: the two halves are ONE public surface.
11
25
  export * from './predicate-schema.js';
@@ -86,116 +100,10 @@ function evalExactCount(args) {
86
100
  assertion,
87
101
  };
88
102
  }
89
- /**
90
- * URL suffixes only the DOCUMENT fetches, which the network observer therefore never records.
91
- *
92
- * `network.ts` patches `fetch` and `XMLHttpRequest` and nothing else, so `<link rel=icon>`,
93
- * `<link rel=manifest>`, stylesheets, fonts and `<img src>` are invisible to it. "No matching call"
94
- * and "that class of call is not observed" are then indistinguishable, and the miss graded
95
- * `assertion_failed` — a false RED. Reported from the field: an assert over `/favicon.ico`,
96
- * `/site.webmanifest` and `/apple-touch-icon.png` returned `verified:"no"` while curl showed all
97
- * three answering 200. A false negative here is worse than an unknown, because an agent that trusts
98
- * it goes and "fixes" working code.
99
- *
100
- * Deliberately NOT here: `.js` and `.json`. Both are routinely fetched via `fetch`/XHR — a module
101
- * preload and an API call can share a suffix — so downgrading them would hide real misses. This list
102
- * is only the suffixes for which the document is the sole plausible initiator.
103
- *
104
- * This began as the smaller half of #447: it did not make these requests observable, it stopped
105
- * Reticle claiming they did not happen. The other half, observing them via resource timing, has
106
- * since landed in the browser SDK, so the two halves are no longer independent and this downgrade is
107
- * now GATED: when the event stream carries at least one document-initiated record, the observer is
108
- * demonstrably live and a miss over these suffixes is real evidence, graded a plain failure. Only a
109
- * page whose stream holds no resource entry at all keeps the honest "cannot tell apart" answer,
110
- * because there the observer may simply not exist.
111
- */
112
- const DOCUMENT_ONLY_SUFFIXES = [
113
- '.ico',
114
- '.png',
115
- '.jpg',
116
- '.jpeg',
117
- '.gif',
118
- '.svg',
119
- '.webp',
120
- '.avif',
121
- '.bmp',
122
- '.css',
123
- '.woff',
124
- '.woff2',
125
- '.ttf',
126
- '.otf',
127
- '.eot',
128
- '.webmanifest',
129
- ];
130
- /**
131
- * File suffixes a click typically downloads or navigates to as a document, never as fetch/XHR.
132
- *
133
- * Sibling of DOCUMENT_ONLY_SUFFIXES, not a member of it. Those are subresources: once resource
134
- * timing is live, a miss is evidence. A click on `<a href="/export.pdf">` is a navigation (or a
135
- * Content-Disposition attachment). Resource timing of stylesheets does not make it visible, so
136
- * grading the miss as "0 network calls" / a 404 is the lie #805 exists to stop — even on a page
137
- * whose observer is running. `.js` / `.json` stay off this list for the same reason they stay off
138
- * the other: they are routinely fetched.
139
- */
140
- const NATIVE_DOWNLOAD_SUFFIXES = [
141
- '.pdf',
142
- '.csv',
143
- '.tsv',
144
- '.zip',
145
- '.gz',
146
- '.tar',
147
- '.xlsx',
148
- '.xls',
149
- '.docx',
150
- '.doc',
151
- '.pptx',
152
- '.ppt',
153
- '.ods',
154
- '.odt',
155
- '.rtf',
156
- '.7z',
157
- '.rar',
158
- ];
159
- /**
160
- * Does this filter target a class of request the observer cannot see?
161
- *
162
- * Read off `urlContains` only, and only when the pattern ENDS in one of the suffixes — a filter of
163
- * `/api/` that happens to contain `.css` somewhere in a query string is still an ordinary XHR
164
- * target. Query strings and fragments are stripped first, since `favicon.ico?v=2` is the same asset.
165
- */
166
- function filterPath(urlContains) {
167
- return (urlContains.split('#')[0] ?? '').split('?')[0]?.toLowerCase() ?? '';
168
- }
169
- /**
170
- * Does this filter target a class of request the observer cannot see?
171
- *
172
- * Read off `urlContains` only, and only when the pattern ENDS in one of the suffixes — a filter of
173
- * `/api/` that happens to contain `.css` somewhere in a query string is still an ordinary XHR
174
- * target. Query strings and fragments are stripped first, since `favicon.ico?v=2` is the same asset.
175
- */
176
- function targetsUnobservedChannel(p) {
177
- const url = p.urlContains;
178
- if (undefined === url)
179
- return false;
180
- return DOCUMENT_ONLY_SUFFIXES.some((suffix) => filterPath(url).endsWith(suffix));
181
- }
182
- function targetsNativeDownload(p) {
183
- const url = p.urlContains;
184
- if (undefined === url)
185
- return false;
186
- return NATIVE_DOWNLOAD_SUFFIXES.some((suffix) => filterPath(url).endsWith(suffix));
187
- }
188
- function nativeDownloadReason(p) {
189
- return (`no fetch or XHR matched ${describeNetFilter(p)}. A native download or document navigation ` +
190
- `(an <a href> to a file, a Content-Disposition attachment, <a download>) never goes through ` +
191
- `fetch or XMLHttpRequest, so an empty net window is not a 404 and is not evidence the export ` +
192
- `failed. This is unobservable on the net channel. Assert the link href, or check the file ` +
193
- `outside the browser — Reticle cannot see the bytes land`);
194
- }
195
103
  function nativeDownloadMiss(events, p) {
196
- if (!targetsNativeDownload(p))
104
+ if (!targetsNativeDownload(p.urlContains))
197
105
  return undefined;
198
- const reason = nativeDownloadReason(p);
106
+ const reason = nativeDownloadReason(describeNetFilter(p));
199
107
  return {
200
108
  pass: false,
201
109
  failureReason: reason,
@@ -245,44 +153,6 @@ export function isDocumentInitiated(event) {
245
153
  function observerSawSubresources(events) {
246
154
  return events.some(isDocumentInitiated);
247
155
  }
248
- /** The sentence both zero-match branches hand to `inconclusive`. */
249
- function unobservedChannelReason(p) {
250
- return (`no call matched ${describeNetFilter(p)}, and no document-initiated load was recorded either, ` +
251
- `so this page exposed no resource timing to read: Reticle observes fetch and XMLHttpRequest ` +
252
- `directly, while a request the document initiates (<link rel=icon|manifest|preload>, a ` +
253
- `stylesheet, a font, <img src>) leaves no record, and that state cannot be told apart from the ` +
254
- `request having been made. ` +
255
- `Nothing here says the app is wrong. Check it outside the browser, or assert something the ` +
256
- `document does not fetch on its own`);
257
- }
258
- /**
259
- * Appended to a zero-match `net` negative whose window starts at SDK attach.
260
- *
261
- * Every event's `t` is stamped `performance.now() - #start`, where `#start` is taken when the SDK
262
- * is constructed, so `t` is never negative and a window with `since === 0` begins AT attach — never
263
- * before it. Whatever the page did between navigation start and attach left no event at all, so
264
- * "no matching call" over such a window cannot be told apart from "the call was made while nothing
265
- * was watching yet".
266
- *
267
- * The gap is routine rather than exotic: a `fetch` from an effect in a root provider, or a classic
268
- * `<script>` at the end of `<body>`, fires before a deferred module script has run. Read as proof
269
- * the request was never made, that sends a reader looking for a defect in code that works —
270
- * restarting dev servers and re-reading providers to establish that the request was invisible rather
271
- * than absent.
272
- *
273
- * Same argument as DOCUMENT_ONLY_SUFFIXES one axis over: that one is a channel Reticle does not
274
- * watch, this is a stretch of TIME it was not yet watching.
275
- *
276
- * The grade is deliberately NOT downgraded to `inconclusive`. A missing API call is the finding this
277
- * oracle exists to make, and it is the strongest grade available for the startup class — session
278
- * restore, feature flags, bootstrap config — which is exactly the class that silently breaks on
279
- * reload. Every window an action opens carries `since > 0` and is untouched. What changes is only
280
- * what the negative CLAIMS: it stops asserting the request never happened, and names the assertion
281
- * that can settle it, because the state such a request produces IS observable after attach.
282
- */
283
- const PRE_ATTACH_CAVEAT = ' — note that this window starts where the SDK attached, and requests made before that are never ' +
284
- 'captured, so a miss here cannot tell a call that was never made apart from one made before the ' +
285
- 'page connected; if the call is expected during startup, assert on the state it produces instead';
286
156
  /**
287
157
  * The response-body clause as the caller wrote it, for a verdict that has to quote it.
288
158
  *
@@ -293,6 +163,37 @@ const PRE_ATTACH_CAVEAT = ' — note that this window starts where the SDK attac
293
163
  function wantedBody(p) {
294
164
  return JSON.stringify(p.bodyContains ?? p.bodyMatches);
295
165
  }
166
+ /**
167
+ * The remedy for a body the SDK skipped ON PURPOSE with capture on, or `undefined` (#1520).
168
+ *
169
+ * Shared by every message that would otherwise say "enable captureNetworkBodies": that advice is
170
+ * wrong when capture is already on and the body was a stream, a binary type, or a read that did
171
+ * not finish. `undefined` means no reason was stamped: capture was off, or the SDK predates it.
172
+ */
173
+ export function skippedBodyRemedy(reason) {
174
+ if (ResponseBodyReason.STREAMING === reason) {
175
+ return 'The body was streamed (text/event-stream or ndjson): the SDK never reads a stream, because reading it would hang the app, and capture is already on. Assert the result in the DOM or in state instead, or use a non-streaming endpoint.';
176
+ }
177
+ if (ResponseBodyReason.NOT_TEXT === reason) {
178
+ return 'The body is not text (binary, or a content type that is not recorded), and capture is already on. Assert the result in the DOM or in state instead.';
179
+ }
180
+ if (ResponseBodyReason.UNREADABLE === reason) {
181
+ return 'The body could not be read before the read deadline, and capture is already on. A response that is still streaming does this. Assert the result in the DOM or in state instead.';
182
+ }
183
+ return undefined;
184
+ }
185
+ /** The skip reason every one of these calls carries, when they all carry the same one. */
186
+ export function sharedSkipReason(reasons) {
187
+ const [first] = reasons;
188
+ if (first === undefined)
189
+ return undefined;
190
+ return reasons.every((r) => r === first) ? first : undefined;
191
+ }
192
+ /** Why a matched call's body could not answer a body clause, and what to do instead (#1520). */
193
+ function unrecordedBodyReason(p, reason) {
194
+ const head = `a call matching ${describeNetFilter(p)} was answered, but its body was not recorded, so ${wantedBody(p)} could not be checked, which is not the same as absent.`;
195
+ return `${head} ${skippedBodyRemedy(reason) ?? 'Enable it where the app calls connect(): reticle({ captureNetworkBodies: true })'}`;
196
+ }
296
197
  export function evalNet(events, p) {
297
198
  const since = p.since ?? 0;
298
199
  /**
@@ -309,6 +210,8 @@ export function evalNet(events, p) {
309
210
  * because it is the same pass over the same events.
310
211
  */
311
212
  let matchedButUnrecorded = false;
213
+ /** Why the SDK skipped that body, when it said (#1520). Absent: capture off, or an older SDK. */
214
+ let unrecordedReason;
312
215
  /** A call matched url/method but carried NO readable status (document-initiated subresource). */
313
216
  let unobservableStatus = false;
314
217
  /**
@@ -326,6 +229,8 @@ export function evalNet(events, p) {
326
229
  * a truncated one cannot (#614).
327
230
  */
328
231
  let truncatedBody;
232
+ // Which clause the truncated body missed: a predicate can carry both, and the remedy for each differs.
233
+ let truncatedClause;
329
234
  /**
330
235
  * A `bodyContains` needle that was FOUND, and found only inside a key name (#987).
331
236
  *
@@ -361,6 +266,8 @@ export function evalNet(events, p) {
361
266
  }
362
267
  if (p.ok !== undefined && callSucceeded(d) !== p.ok)
363
268
  return false;
269
+ if (!checkRequestBody(d, p, requestState))
270
+ return false;
364
271
  if (p.bodyContains !== undefined || p.bodyMatches !== undefined) {
365
272
  // The RESPONSE body only, and this is the whole point of these fields. Searching the request
366
273
  // too would let `bodyContains: "1187.01"` pass on the very defect it exists to catch: the app
@@ -369,6 +276,7 @@ export function evalNet(events, p) {
369
276
  const response = str(d['responseBody']);
370
277
  if (response === undefined) {
371
278
  matchedButUnrecorded = true;
279
+ unrecordedReason ??= d['responseBodyReason'];
372
280
  return false;
373
281
  }
374
282
  // A needle missing from a body we only hold the FIRST N BYTES of is undecidable, not absent:
@@ -376,16 +284,18 @@ export function evalNet(events, p) {
376
284
  // there (#614). Grading it `pass: false` with "the response value is what differed" is the
377
285
  // inversion the honesty rules exist to prevent — an unknown reported as decided, against a
378
286
  // response that was very likely correct.
379
- const missed = () => {
380
- if (true === d['responseBodyTruncated'])
287
+ const missed = (clause) => {
288
+ if (true === d['responseBodyTruncated']) {
381
289
  truncatedBody ??= response;
290
+ truncatedClause ??= clause;
291
+ }
382
292
  else
383
293
  bodyMismatch ??= response;
384
294
  return false;
385
295
  };
386
296
  if (p.bodyContains !== undefined) {
387
297
  if (!response.includes(p.bodyContains))
388
- return missed();
298
+ return missed(NetBodyAssertion.CONTAINS);
389
299
  const fragment = keyFragmentOnly(response, p.bodyContains);
390
300
  if (fragment !== undefined) {
391
301
  keyFragment ??= { key: fragment, body: response };
@@ -395,15 +305,13 @@ export function evalNet(events, p) {
395
305
  if (p.bodyMatches !== undefined) {
396
306
  const verdict = matchJsonBody(response, p.bodyMatches);
397
307
  if ('mismatch' === verdict)
398
- return missed();
308
+ return missed(NetBodyAssertion.MATCHES);
399
309
  if ('match' !== verdict) {
400
310
  redactedResponseField ??= verdict.redacted;
401
311
  return false;
402
312
  }
403
313
  }
404
314
  }
405
- if (!checkRequestBody(d, p, requestState))
406
- return false;
407
315
  return true;
408
316
  });
409
317
  if (unobservableStatus && 0 === matches.length) {
@@ -419,12 +327,16 @@ export function evalNet(events, p) {
419
327
  };
420
328
  }
421
329
  if (matchedButUnrecorded && 0 === matches.length) {
330
+ // Inconclusive, never a plain failure: nothing says the body lacked the text, only that nobody
331
+ // read it (#1520). The same family as evicted evidence answering `no` (#1231).
332
+ const reason = unrecordedBodyReason(p, unrecordedReason);
422
333
  return {
423
334
  pass: false,
424
- failureReason: `a call matched but its body was not recorded, so \`bodyContains\` could not be checked — enable it where the app calls connect(): reticle({ captureNetworkBodies: true })`,
335
+ failureReason: reason,
336
+ inconclusive: reason,
425
337
  observed: 'a matching call with no recorded body',
426
338
  expected: `a body carrying ${wantedBody(p)}`,
427
- assertion: 'net.bodyContains',
339
+ assertion: NetBodyAssertion.CONTAINS,
428
340
  };
429
341
  }
430
342
  if (keyFragment !== undefined && 0 === matches.length) {
@@ -434,7 +346,7 @@ export function evalNet(events, p) {
434
346
  inconclusive: `a call matching ${describeNetFilter(p)} was answered with a body where ${JSON.stringify(p.bodyContains)} appears ONLY inside the key name ${JSON.stringify(keyFragment.key)} — no value in the response contains it, so this substring proves nothing about what any field holds. Assert the field itself: \`bodyMatches: { "<field>": <value> }\``,
435
347
  observed: `response body ${JSON.stringify(clipBody(keyFragment.body))}`,
436
348
  expected: `a response body carrying ${JSON.stringify(p.bodyContains)} as a value, or as a whole key`,
437
- assertion: 'net.bodyContains',
349
+ assertion: NetBodyAssertion.CONTAINS,
438
350
  };
439
351
  }
440
352
  if (redactedResponseField !== undefined && 0 === matches.length) {
@@ -444,24 +356,31 @@ export function evalNet(events, p) {
444
356
  inconclusive: `a call matching ${describeNetFilter(p)} was answered, but its ${field} was REDACTED before the body 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`,
445
357
  observed: `a matching response whose ${field} is ${REDACTED_VALUE}`,
446
358
  expected: `a response body matching ${JSON.stringify(p.bodyMatches)}`,
447
- assertion: 'net.bodyMatches',
359
+ assertion: NetBodyAssertion.MATCHES,
448
360
  };
449
361
  }
450
- const requestVerdict = requestBodyVerdict(requestState, p, matches.length);
451
- if (requestVerdict !== undefined)
452
- return requestVerdict;
453
362
  // Ranked ABOVE the mismatch branch: when both a truncated and a full body missed the needle,
454
363
  // the honest verdict is the undecidable one. Deciding on the full body would report a failure
455
364
  // the truncated call may well contradict.
456
365
  if (truncatedBody !== undefined && 0 === matches.length) {
366
+ // `bodyMatches` parses the whole body, and a JSON prefix never parses, so "assert on something
367
+ // inside the recorded prefix" changes nothing for it: the same clause on the same prefix is the
368
+ // same unknown. Name what can work for the clause that was actually asked (#1417). The grade
369
+ // stays inconclusive either way: a partial parse must not decide it, since a later duplicate key
370
+ // could overturn whatever the prefix seemed to say.
371
+ const missedMatch = NetBodyAssertion.MATCHES === truncatedClause;
372
+ const remedy = missedMatch ? TRUNCATED_MATCHES_REMEDY : TRUNCATED_PREFIX_REMEDY;
457
373
  return {
458
374
  pass: false,
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`,
375
+ 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. ${remedy}`,
460
376
  observed: `the first ${String(truncatedBody.length)} characters of a truncated response body ${JSON.stringify(clipBody(truncatedBody))}`,
461
377
  expected: `a response body carrying ${wantedBody(p)}`,
462
- assertion: 'net.bodyContains',
378
+ assertion: truncatedClause ?? NetBodyAssertion.CONTAINS,
463
379
  };
464
380
  }
381
+ const requestVerdict = requestBodyVerdict(requestState, p, matches.length, bodyMismatch);
382
+ if (requestVerdict !== undefined)
383
+ return requestVerdict;
465
384
  if (bodyMismatch !== undefined && 0 === matches.length) {
466
385
  // The call is there and its body is there; only the VALUE differs. Counting it as zero matches
467
386
  // points at the wiring, which is the one place the defect is not. A field clause also names the
@@ -473,7 +392,7 @@ export function evalNet(events, p) {
473
392
  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
393
  observed: `response body ${JSON.stringify(clipBody(bodyMismatch))}${because}`,
475
394
  expected: `a response body carrying ${wantedBody(p)}`,
476
- assertion: 'net.bodyContains',
395
+ assertion: NetBodyAssertion.CONTAINS,
477
396
  };
478
397
  }
479
398
  // `count` (exact) turns presence into a cardinality assertion — catches the double-submit /
@@ -487,12 +406,12 @@ export function evalNet(events, p) {
487
406
  }
488
407
  if (matches.length !== p.count &&
489
408
  0 === matches.length &&
490
- targetsUnobservedChannel(p) &&
409
+ targetsUnobservedChannel(p.urlContains) &&
491
410
  !sawSubresources) {
492
411
  return {
493
412
  pass: false,
494
- failureReason: unobservedChannelReason(p),
495
- inconclusive: unobservedChannelReason(p),
413
+ failureReason: unobservedChannelReason(describeNetFilter(p)),
414
+ inconclusive: unobservedChannelReason(describeNetFilter(p)),
496
415
  assertion: 'net.count',
497
416
  };
498
417
  }
@@ -517,8 +436,8 @@ export function evalNet(events, p) {
517
436
  if (download !== undefined)
518
437
  return download;
519
438
  }
520
- if (hit === undefined && targetsUnobservedChannel(p) && !sawSubresources) {
521
- const reason = unobservedChannelReason(p);
439
+ if (hit === undefined && targetsUnobservedChannel(p.urlContains) && !sawSubresources) {
440
+ const reason = unobservedChannelReason(describeNetFilter(p));
522
441
  return {
523
442
  pass: false,
524
443
  failureReason: reason,
@@ -545,7 +464,9 @@ export function evalAnimation(events, p) {
545
464
  const hit = events.find((e) => {
546
465
  if (e.type !== wantType)
547
466
  return false;
548
- if (p.name !== undefined && str(e.data['name']) !== p.name)
467
+ const name = str(e.data['name']);
468
+ // A check with no name asks about the app, so Reticle's own bookkeeping signals do not count.
469
+ if (p.name === undefined ? isReticleVoice(name ?? '') : name !== p.name)
549
470
  return false;
550
471
  if (p.target !== undefined && e.ref !== p.target)
551
472
  return false;
@@ -571,7 +492,9 @@ export function evalSignal(events, p) {
571
492
  const isMatch = (e) => {
572
493
  if (e.type !== EventType.SIGNAL)
573
494
  return false;
574
- if (p.name !== undefined && str(e.data['name']) !== p.name)
495
+ const name = str(e.data['name']);
496
+ // A check with no name asks about the app, so Reticle's own bookkeeping signals do not count.
497
+ if (p.name === undefined ? isReticleVoice(name ?? '') : name !== p.name)
575
498
  return false;
576
499
  if (p.dataMatches !== undefined) {
577
500
  const payload = (e.data['data'] ?? {});
@@ -676,6 +599,10 @@ const SETTLE_ACTIVITY = new Set([
676
599
  EventType.DOM_REMOVED,
677
600
  EventType.DOM_ATTR,
678
601
  ]);
602
+ /** An app-scoped settle: the default's activity, and every framework render commit. */
603
+ const APP_ACTIVITY = new Set([...SETTLE_ACTIVITY, EventType.RENDER_COMMIT]);
604
+ /** The quiet window of a network-scoped settle: a completed request is the only activity. */
605
+ const NETWORK_ACTIVITY = new Set([EventType.NET_REQUEST]);
679
606
  /** The three net-shaped event types a URL can be read off — the only ones dev tooling can produce. */
680
607
  const NET_TYPES = new Set([
681
608
  EventType.NET_PENDING,
@@ -684,6 +611,8 @@ const NET_TYPES = new Set([
684
611
  ]);
685
612
  /** Default quiet window — enough to absorb a render+xhr settle without waiting on slow polls. */
686
613
  const DEFAULT_QUIET_MS = 500;
614
+ /** Work the app declared (`reticle.busy`; core's `RETICLE_BUSY_SIGNAL`); not imported: coupling only shrinks. */
615
+ const RETICLE_BUSY_SIGNAL = 'reticle:busy';
687
616
  /**
688
617
  * Did the browser LEAVE for this record, rather than make a request whose result we will see?
689
618
  *
@@ -702,7 +631,7 @@ const isDeparture = (data) => data['initiator'] === NetInitiator.NAVIGATION;
702
631
  /**
703
632
  * "The page has gone quiet": no network/DOM/animation activity for at least `quietMs`. Needs the
704
633
  * wall-clock `now` (in the buffer's time base) because "no activity in the last N ms" is relative to
705
- * now, not to any buffered event — so `now` is injected (CLAUDE.md rule 7), and the wait loop's
634
+ * now, not to any buffered event — so `now` is injected (AGENTS.md rule 7), and the wait loop's
706
635
  * poll interval is what eventually flips this to pass once activity stops.
707
636
  */
708
637
  export function evalSettled(allEvents, p, now, scope) {
@@ -814,12 +743,35 @@ export function evalSettled(allEvents, p, now, scope) {
814
743
  openStreams.delete(id);
815
744
  }
816
745
  const streaming = openStreams.size;
746
+ // Work only the app can see (`reticle.busy`): starts minus ends, in order, never below zero, so an
747
+ // end whose start fell before this window is not credit against work started inside it.
748
+ let appBusy = 0;
749
+ for (const e of events) {
750
+ if (e.type !== EventType.SIGNAL || RETICLE_BUSY_SIGNAL !== e.data['name'])
751
+ continue;
752
+ const delta = e.data['data']?.delta;
753
+ if ('number' === typeof delta)
754
+ appBusy = Math.max(0, appBusy + Math.sign(delta));
755
+ }
756
+ if (appBusy > 0 && 0 === inFlight + streaming) {
757
+ const what = `${String(appBusy)} app task(s) still pending`;
758
+ return {
759
+ pass: false,
760
+ failureReason: `not settled: ${what}`,
761
+ observed: what,
762
+ expected: 'no work the app declared still pending',
763
+ assertion: 'settled.app-busy',
764
+ evidence: { settled: false, appBusy, ...disclosure },
765
+ };
766
+ }
817
767
  if (inFlight + streaming > 0) {
818
- const what = 0 === streaming
819
- ? `${String(inFlight)} request(s) still in flight`
820
- : 0 === inFlight
821
- ? `${String(streaming)} response body(ies) still streaming`
822
- : `${String(inFlight)} request(s) in flight and ${String(streaming)} response body(ies) still streaming`;
768
+ let what = `${String(inFlight)} request(s) in flight and ${String(streaming)} response body(ies) still streaming`;
769
+ if (0 === streaming) {
770
+ what = `${String(inFlight)} request(s) still in flight`;
771
+ }
772
+ else if (0 === inFlight) {
773
+ what = `${String(streaming)} response body(ies) still streaming`;
774
+ }
823
775
  return {
824
776
  pass: false,
825
777
  failureReason: `not settled: ${what}`,
@@ -834,10 +786,19 @@ export function evalSettled(allEvents, p, now, scope) {
834
786
  },
835
787
  };
836
788
  }
789
+ // A network-scoped settle reads only completed requests for the quiet window; the in-flight checks
790
+ // above already ran for every scope.
791
+ let activity = SETTLE_ACTIVITY;
792
+ if (SettledChannel.NETWORK === p.channel) {
793
+ activity = NETWORK_ACTIVITY;
794
+ }
795
+ else if (SettledChannel.APP === p.channel) {
796
+ activity = APP_ACTIVITY;
797
+ }
837
798
  let lastT = -1;
838
799
  let lastType;
839
800
  for (const e of events) {
840
- if (SETTLE_ACTIVITY.has(e.type) && e.t > lastT) {
801
+ if (activity.has(e.type) && e.t > lastT) {
841
802
  lastT = e.t;
842
803
  lastType = e.type;
843
804
  }
@@ -86,6 +86,30 @@ function placeholderValue(input) {
86
86
  const value = input['value'];
87
87
  return 'string' === typeof value && UNFILLED_PLACEHOLDER.test(value) ? value : undefined;
88
88
  }
89
+ /**
90
+ * The one member of an `allOf`/`anyOf`/`not` every issue points into, when there is exactly one.
91
+ *
92
+ * Read at the outer level, a member's mistake was reported as the combinator's: "allOf accepts:
93
+ * predicates … unknown field satisfies" for a `satisfies` on a nested `element`, which sends the
94
+ * agent to fix the wrong level. Re-parsing that member names its own kind, fields and example.
95
+ */
96
+ function onlyChildBlamed(input, issues) {
97
+ if ('object' !== typeof input || null === input)
98
+ return undefined;
99
+ const heads = new Set(issues.map((issue) => 'predicates' === issue.path[0] && 'number' === typeof issue.path[1]
100
+ ? `predicates.${issue.path[1]}`
101
+ : 'predicate' === issue.path[0] && 1 < issue.path.length
102
+ ? 'predicate'
103
+ : ''));
104
+ const [head] = heads;
105
+ if (1 !== heads.size || undefined === head || '' === head)
106
+ return undefined;
107
+ const [field, index] = head.split('.');
108
+ const record = input;
109
+ const container = record[field ?? ''];
110
+ const value = undefined === index ? container : container?.[Number(index)];
111
+ return undefined === value ? undefined : { path: head, value };
112
+ }
89
113
  export function parsePredicate(input) {
90
114
  const unfilled = placeholderValue(input);
91
115
  if (unfilled !== undefined) {
@@ -98,6 +122,16 @@ export function parsePredicate(input) {
98
122
  const parsed = PredicateSchema.safeParse(input);
99
123
  if (parsed.success)
100
124
  return parsed.data;
125
+ const child = onlyChildBlamed(input, parsed.error.issues);
126
+ if (child !== undefined) {
127
+ try {
128
+ parsePredicate(child.value);
129
+ }
130
+ catch (error) {
131
+ if (error instanceof Error)
132
+ throw new Error(`${child.path}: ${error.message}`);
133
+ }
134
+ }
101
135
  const asWritten = kindAsWritten(input);
102
136
  const kind = 'string' === typeof asWritten ? asWritten : 'unknown';
103
137
  // Bounded on purpose: a union rejection can produce one issue per member, and pasting all of them