@reticlehq/engine 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (123) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +36 -0
  3. package/dist/disagreement/body-failures.d.ts +4 -0
  4. package/dist/disagreement/body-failures.js +113 -0
  5. package/dist/disagreement/contradiction-evidence.d.ts +122 -0
  6. package/dist/disagreement/contradiction-evidence.js +194 -0
  7. package/dist/disagreement/contradiction-folds.d.ts +61 -0
  8. package/dist/disagreement/contradiction-folds.js +71 -0
  9. package/dist/disagreement/contradiction-types.d.ts +164 -0
  10. package/dist/disagreement/contradiction-types.js +1 -0
  11. package/dist/disagreement/contradictions.d.ts +5 -0
  12. package/dist/disagreement/contradictions.js +613 -0
  13. package/dist/disagreement/echo-mismatch.d.ts +10 -0
  14. package/dist/disagreement/echo-mismatch.js +299 -0
  15. package/dist/disagreement/reconcile.d.ts +39 -0
  16. package/dist/disagreement/reconcile.js +211 -0
  17. package/dist/disagreement/stale-response.d.ts +3 -0
  18. package/dist/disagreement/stale-response.js +186 -0
  19. package/dist/disagreement/unit-mismatch.d.ts +16 -0
  20. package/dist/disagreement/unit-mismatch.js +167 -0
  21. package/dist/disagreement/witness-disagreement.d.ts +42 -0
  22. package/dist/disagreement/witness-disagreement.js +43 -0
  23. package/dist/evidence/accepted-write.d.ts +35 -0
  24. package/dist/evidence/accepted-write.js +54 -0
  25. package/dist/evidence/already-true.d.ts +16 -0
  26. package/dist/evidence/already-true.js +89 -0
  27. package/dist/evidence/blind-spots.d.ts +133 -0
  28. package/dist/evidence/blind-spots.js +253 -0
  29. package/dist/evidence/body-capture-remedy.d.ts +42 -0
  30. package/dist/evidence/body-capture-remedy.js +96 -0
  31. package/dist/evidence/gap-ledger.d.ts +52 -0
  32. package/dist/evidence/gap-ledger.js +63 -0
  33. package/dist/evidence/honesty.d.ts +113 -0
  34. package/dist/evidence/honesty.js +105 -0
  35. package/dist/evidence/instrumentation-gaps.d.ts +91 -0
  36. package/dist/evidence/instrumentation-gaps.js +102 -0
  37. package/dist/evidence/learned-guards.d.ts +75 -0
  38. package/dist/evidence/learned-guards.js +78 -0
  39. package/dist/evidence/observability.d.ts +38 -0
  40. package/dist/evidence/observability.js +40 -0
  41. package/dist/evidence/page-teardown.d.ts +15 -0
  42. package/dist/evidence/page-teardown.js +17 -0
  43. package/dist/evidence/step-effect.d.ts +41 -0
  44. package/dist/evidence/step-effect.js +27 -0
  45. package/dist/evidence/uncaptured-bodies.d.ts +23 -0
  46. package/dist/evidence/uncaptured-bodies.js +41 -0
  47. package/dist/evidence/undeclared-change.d.ts +51 -0
  48. package/dist/evidence/undeclared-change.js +56 -0
  49. package/dist/evidence/unread-outcome.d.ts +10 -0
  50. package/dist/evidence/unread-outcome.js +77 -0
  51. package/dist/evidence/unsettled.d.ts +58 -0
  52. package/dist/evidence/unsettled.js +127 -0
  53. package/dist/evidence/verdict-intent-gap.d.ts +30 -0
  54. package/dist/evidence/verdict-intent-gap.js +35 -0
  55. package/dist/evidence/verified.d.ts +158 -0
  56. package/dist/evidence/verified.js +378 -0
  57. package/dist/index.d.ts +30 -0
  58. package/dist/index.js +25 -0
  59. package/dist/question/declared.d.ts +74 -0
  60. package/dist/question/declared.js +171 -0
  61. package/dist/question/lineage.d.ts +52 -0
  62. package/dist/question/lineage.js +122 -0
  63. package/dist/question/predicate/net-evidence.d.ts +21 -0
  64. package/dist/question/predicate/net-evidence.js +81 -0
  65. package/dist/question/predicate/observed-in-window.d.ts +24 -0
  66. package/dist/question/predicate/observed-in-window.js +38 -0
  67. package/dist/question/predicate/predicate-asks.d.ts +28 -0
  68. package/dist/question/predicate/predicate-asks.js +46 -0
  69. package/dist/question/predicate/predicate-console.d.ts +13 -0
  70. package/dist/question/predicate/predicate-console.js +138 -0
  71. package/dist/question/predicate/predicate-element.d.ts +13 -0
  72. package/dist/question/predicate/predicate-element.js +214 -0
  73. package/dist/question/predicate/predicate-eval-kit.d.ts +90 -0
  74. package/dist/question/predicate/predicate-eval-kit.js +126 -0
  75. package/dist/question/predicate/predicate-eval.d.ts +24 -0
  76. package/dist/question/predicate/predicate-eval.js +710 -0
  77. package/dist/question/predicate/predicate-parse.d.ts +15 -0
  78. package/dist/question/predicate/predicate-parse.js +173 -0
  79. package/dist/question/predicate/predicate-precheck.d.ts +8 -0
  80. package/dist/question/predicate/predicate-precheck.js +41 -0
  81. package/dist/question/predicate/predicate-request-body.d.ts +50 -0
  82. package/dist/question/predicate/predicate-request-body.js +120 -0
  83. package/dist/question/predicate/predicate-route.d.ts +66 -0
  84. package/dist/question/predicate/predicate-route.js +293 -0
  85. package/dist/question/predicate/predicate-schema.d.ts +170 -0
  86. package/dist/question/predicate/predicate-schema.js +509 -0
  87. package/dist/question/predicate/predicate-session.d.ts +72 -0
  88. package/dist/question/predicate/predicate-session.js +1 -0
  89. package/dist/question/predicate/predicate-to-links.d.ts +13 -0
  90. package/dist/question/predicate/predicate-to-links.js +38 -0
  91. package/dist/question/predicate/predicate.d.ts +26 -0
  92. package/dist/question/predicate/predicate.js +785 -0
  93. package/dist/question/predicate/property.d.ts +102 -0
  94. package/dist/question/predicate/property.js +135 -0
  95. package/dist/question/predicate/split-text-miss.d.ts +32 -0
  96. package/dist/question/predicate/split-text-miss.js +51 -0
  97. package/dist/question/predicate/testid-near-miss.d.ts +22 -0
  98. package/dist/question/predicate/testid-near-miss.js +33 -0
  99. package/dist/question/reaction.d.ts +17 -0
  100. package/dist/question/reaction.js +67 -0
  101. package/dist/window/adversary.d.ts +28 -0
  102. package/dist/window/adversary.js +90 -0
  103. package/dist/window/ambient.d.ts +63 -0
  104. package/dist/window/ambient.js +76 -0
  105. package/dist/window/appearance-budget.d.ts +41 -0
  106. package/dist/window/appearance-budget.js +47 -0
  107. package/dist/window/asset-noise.d.ts +42 -0
  108. package/dist/window/asset-noise.js +35 -0
  109. package/dist/window/body-relevance.d.ts +54 -0
  110. package/dist/window/body-relevance.js +78 -0
  111. package/dist/window/byte-size.d.ts +1 -0
  112. package/dist/window/byte-size.js +16 -0
  113. package/dist/window/engine-host.d.ts +35 -0
  114. package/dist/window/engine-host.js +20 -0
  115. package/dist/window/event-filters.d.ts +121 -0
  116. package/dist/window/event-filters.js +215 -0
  117. package/dist/window/json-salvage.d.ts +33 -0
  118. package/dist/window/json-salvage.js +96 -0
  119. package/dist/window/network-detail-merge.d.ts +8 -0
  120. package/dist/window/network-detail-merge.js +89 -0
  121. package/dist/window/ring-buffer.d.ts +41 -0
  122. package/dist/window/ring-buffer.js +152 -0
  123. package/package.json +71 -0
@@ -0,0 +1,15 @@
1
+ /**
2
+ * How we say that a page went away while it was on a particular address.
3
+ *
4
+ * Two different surfaces tell a person about the same event. The verdict says a consequence could
5
+ * not be checked because the page disappeared; the setup diagnosis says why no session is connected.
6
+ * If each wrote its own sentence they would eventually describe the same teardown in two ways, and
7
+ * whoever read both would go looking for two problems.
8
+ *
9
+ * It lives beside the rules that decide a verdict rather than beside the diagnosis, because the
10
+ * rules are meant to be liftable on their own. Anything they need has to come with them.
11
+ *
12
+ * Example: `pageTornDownWhileOn('http://localhost:3000/checkout')` gives
13
+ * "the page was torn down while on http://localhost:3000/checkout".
14
+ */
15
+ export declare function pageTornDownWhileOn(url: string): string;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * How we say that a page went away while it was on a particular address.
3
+ *
4
+ * Two different surfaces tell a person about the same event. The verdict says a consequence could
5
+ * not be checked because the page disappeared; the setup diagnosis says why no session is connected.
6
+ * If each wrote its own sentence they would eventually describe the same teardown in two ways, and
7
+ * whoever read both would go looking for two problems.
8
+ *
9
+ * It lives beside the rules that decide a verdict rather than beside the diagnosis, because the
10
+ * rules are meant to be liftable on their own. Anything they need has to come with them.
11
+ *
12
+ * Example: `pageTornDownWhileOn('http://localhost:3000/checkout')` gives
13
+ * "the page was torn down while on http://localhost:3000/checkout".
14
+ */
15
+ export function pageTornDownWhileOn(url) {
16
+ return `the page was torn down while on ${url}`;
17
+ }
@@ -0,0 +1,41 @@
1
+ /**
2
+ * What one action did, from the window it opened — built once, for every path that needs it.
3
+ *
4
+ * A driven step and a replayed step have to describe what happened in the SAME words. They did not:
5
+ * the live act path returned a reaction digest and contradictions, while replay returned a prose
6
+ * sentence, so the same click described twice read as two different events. That makes the
7
+ * before/after comparison this product exists for impossible to do, and it is the shape of drift
8
+ * that this repo keeps finding after it has shipped.
9
+ *
10
+ * Pure: events and a window in, a record out. No session, no clock, no IO — which is what lets the
11
+ * live path and the replay path share it instead of agreeing by coincidence.
12
+ */
13
+ import type { Contradiction, ReactionDigest, ReticleEvent } from '@reticlehq/core';
14
+ /** The cursor pair an observer can re-read this step's evidence with. */
15
+ export interface StepWindow {
16
+ since: number;
17
+ until: number;
18
+ }
19
+ export interface StepEffect {
20
+ /**
21
+ * The drill address. `reticle_observe { since, until }` returns exactly this span, so a step that
22
+ * carries it can be asked about later without re-driving anything.
23
+ *
24
+ * Bounded on BOTH ends: a `since` alone returns everything from that point to now, which on a long
25
+ * journey would hand step two the whole tail and invite a reader to blame one click for it.
26
+ *
27
+ * Omitted where the clock never advanced. `{since: 7, until: 7}` reads as "this step caused
28
+ * nothing" when it means "nothing here measures time".
29
+ */
30
+ window?: StepWindow;
31
+ /** What the app did, as counts. The timeline is the expensive half and stays addressable instead. */
32
+ digest?: ReactionDigest;
33
+ /**
34
+ * Channels that disagree about this action — present whether or not the step passed.
35
+ *
36
+ * The detectors run independently of the assertion, so a green step carrying one of these is a
37
+ * finding. Omitted when they agree rather than sent empty: its presence is the signal.
38
+ */
39
+ contradictions?: Contradiction[];
40
+ }
41
+ export declare function stepEffect(events: readonly ReticleEvent[], window: StepWindow): StepEffect;
@@ -0,0 +1,27 @@
1
+ /**
2
+ * What one action did, from the window it opened — built once, for every path that needs it.
3
+ *
4
+ * A driven step and a replayed step have to describe what happened in the SAME words. They did not:
5
+ * the live act path returned a reaction digest and contradictions, while replay returned a prose
6
+ * sentence, so the same click described twice read as two different events. That makes the
7
+ * before/after comparison this product exists for impossible to do, and it is the shape of drift
8
+ * that this repo keeps finding after it has shipped.
9
+ *
10
+ * Pure: events and a window in, a record out. No session, no clock, no IO — which is what lets the
11
+ * live path and the replay path share it instead of agreeing by coincidence.
12
+ */
13
+ import { buildReactionReport, summarizeReaction } from '../question/reaction.js';
14
+ import { findContradictions } from '../disagreement/contradictions.js';
15
+ export function stepEffect(events, window) {
16
+ const effect = {};
17
+ if (window.until > window.since)
18
+ effect.window = { since: window.since, until: window.until };
19
+ effect.digest = summarizeReaction(buildReactionReport([...events], window.until - window.since));
20
+ // `actionSince` is what tells the detectors which window belongs to THIS action. Without it the
21
+ // headline rule cannot attribute a failed request to the click that moved the screen, and the
22
+ // whole family goes quiet while looking perfectly wired.
23
+ const contradictions = findContradictions(events, { actionSince: window.since });
24
+ if (contradictions.length > 0)
25
+ effect.contradictions = contradictions;
26
+ return effect;
27
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Say so when a payload exists but was not recorded.
3
+ *
4
+ * A `reticle_network` row for a POST lists method/url/status and nothing else, and an agent reading
5
+ * that has no way to tell "this request had no interesting payload" from "Reticle was not looking at
6
+ * payloads". The second reading is the dangerous one: on a real payments dashboard the defect WAS
7
+ * the payload — a refund POSTing `amount: 1187.01` into a paise field, a 100x under-refund that
8
+ * every other field in the record agrees is a clean 200.
9
+ *
10
+ * So an omission is declared rather than left to inference, with the one line that fixes it. Present
11
+ * only when a body-bearing call was returned AND no body — request or response — was recorded
12
+ * anywhere in the result, so an app that already captures bodies pays nothing and the field's
13
+ * PRESENCE is the warning.
14
+ */
15
+ export declare function bodiesNotCaptured(calls: {
16
+ method?: string;
17
+ requestBody?: string;
18
+ responseBody?: string;
19
+ }[],
20
+ /** The page SDK's version, so the remedy can check whether it applies. See body-capture-remedy. */
21
+ sdkVersion?: string): {
22
+ bodiesNotCaptured?: string;
23
+ };
@@ -0,0 +1,41 @@
1
+ import { bodyCaptureRemedy } from './body-capture-remedy.js';
2
+ /** Methods that normally carry a payload — the ones where a missing body is worth explaining. */
3
+ const BODY_BEARING_METHODS = new Set(['POST', 'PUT', 'PATCH']);
4
+ /**
5
+ * Say so when a payload exists but was not recorded.
6
+ *
7
+ * A `reticle_network` row for a POST lists method/url/status and nothing else, and an agent reading
8
+ * that has no way to tell "this request had no interesting payload" from "Reticle was not looking at
9
+ * payloads". The second reading is the dangerous one: on a real payments dashboard the defect WAS
10
+ * the payload — a refund POSTing `amount: 1187.01` into a paise field, a 100x under-refund that
11
+ * every other field in the record agrees is a clean 200.
12
+ *
13
+ * So an omission is declared rather than left to inference, with the one line that fixes it. Present
14
+ * only when a body-bearing call was returned AND no body — request or response — was recorded
15
+ * anywhere in the result, so an app that already captures bodies pays nothing and the field's
16
+ * PRESENCE is the warning.
17
+ */
18
+ export function bodiesNotCaptured(calls,
19
+ /** The page SDK's version, so the remedy can check whether it applies. See body-capture-remedy. */
20
+ sdkVersion) {
21
+ const bodyBearing = calls.filter((c) => BODY_BEARING_METHODS.has((c.method ?? '').toUpperCase()));
22
+ if (0 === bodyBearing.length)
23
+ return {};
24
+ // A recorded response body anywhere in the result proves capture is ON. An absent request body
25
+ // then means this payload was not stringified (a multipart upload, a body the SDK skipped), not
26
+ // that recording is off — and firing the note would contradict the body sitting in the same
27
+ // result, exactly on the question the note exists to answer. (#394)
28
+ if (calls.some((c) => c.responseBody !== undefined))
29
+ return {};
30
+ if (bodyBearing.some((c) => c.requestBody !== undefined))
31
+ return {};
32
+ return {
33
+ // Framework-neutral on purpose. The first version named vite.config, and driving a Next.js app
34
+ // returned that advice verbatim for a SERVER ACTION — a POST a Next user cannot fix in a Vite
35
+ // config they do not have. Remediation that does not apply to the reader's stack is worse than
36
+ // none: it sends them to edit a file that is not there and reads as a tool that does not know
37
+ // what it is looking at.
38
+ bodiesNotCaptured: 'request/response bodies are NOT being recorded, so an absent body here means UNSEEN, not ' +
39
+ `empty — the payload of these calls was never inspected. ${bodyCaptureRemedy(sdkVersion)}`,
40
+ };
41
+ }
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Is this verdict being drawn over code nobody said anything about?
3
+ *
4
+ * Declaring intent is opt-in, and nothing has ever noticed that a change landed and nobody said what
5
+ * it was supposed to make true. That is the moment it matters: a change with no declared intent can
6
+ * only be verified against itself, which is the definition of a false green.
7
+ *
8
+ * ## Why this fires on EVERY verdict, not once per change
9
+ *
10
+ * The house rule is that a gap nobody hit is a backlog, and a backlog reported as a finding is how
11
+ * an agent learns to stop reading findings. This clears that bar on the same test every other
12
+ * instrumentation gap clears it on: **did the absence make THIS verdict weaker?** An unwatched store
13
+ * weakens every state assertion made over it, not merely the first, so it is reported on every one.
14
+ * An undeclared change is the same shape — while nothing says what the edit was for, each verdict
15
+ * drawn after it is checked against nothing but itself, and that is true of the fifth one exactly as
16
+ * it was of the first. Reporting it once and then falling silent would leave four verdicts carrying
17
+ * a weakness they no longer disclose, which is the failure mode this whole surface exists to prevent.
18
+ *
19
+ * It is also not a backlog, because it is not a survey of the project: it is answered from what this
20
+ * session observed (an epoch that moved) about the verdict being returned right now, and it is
21
+ * closed by one call the agent can make immediately. A finding that stays open only because the
22
+ * agent has not made that call is a finding about the current verdict, not a chore.
23
+ *
24
+ * ## The silences, and why each one is required
25
+ *
26
+ * - **An edit was actually OBSERVED.** The epoch degrades to `NO_EDITS_OBSERVED` outside Vite, and
27
+ * that means "no edits observed", never "no edits happened" — a finding built on an absence
28
+ * Reticle cannot see would be a fabrication.
29
+ * - **The ledger holds nothing undischarged.** An open intent IS the declaration; silence is the
30
+ * correct response to it, and declaring one is what turns this off from the next verdict on.
31
+ *
32
+ * ## Why "covers the work" is answered as "anything open at all"
33
+ *
34
+ * The tempting answer is to match the intent's `surface` against the files that changed. Reticle
35
+ * cannot do that honestly: it observes that an epoch advanced, not WHAT advanced — the hot-update
36
+ * channel reports a counter, not a diff — so any file-level matching would be inference dressed as a
37
+ * fact, and it would fire on an agent that had declared its intent perfectly well. Over-reporting on
38
+ * a correct agent is the direction of error that trains it to stop reading findings.
39
+ *
40
+ * So the question asked is the coarse one, and it is asked honestly: has the agent declared anything
41
+ * that is still outstanding? If it has, it is working to a stated purpose and this stays quiet.
42
+ */
43
+ /**
44
+ * `openIntents` is a thunk rather than a list because reading the ledger touches disk, and the epoch
45
+ * check answers without it for every page that never reported a hot update — which is most of them.
46
+ * Once an edit HAS been observed the read happens per verdict, and that is the intended cost: the
47
+ * ledger is the only thing that can end it, so it has to be re-asked each time.
48
+ */
49
+ export declare function isChangeUndeclared(
50
+ /** The epoch the session is under now. Undefined when the page never stamped one. */
51
+ currentEpoch: number | undefined, openIntents: () => Promise<readonly unknown[]>): Promise<boolean>;
@@ -0,0 +1,56 @@
1
+ import { NO_EDITS_OBSERVED } from '@reticlehq/core';
2
+ /**
3
+ * Is this verdict being drawn over code nobody said anything about?
4
+ *
5
+ * Declaring intent is opt-in, and nothing has ever noticed that a change landed and nobody said what
6
+ * it was supposed to make true. That is the moment it matters: a change with no declared intent can
7
+ * only be verified against itself, which is the definition of a false green.
8
+ *
9
+ * ## Why this fires on EVERY verdict, not once per change
10
+ *
11
+ * The house rule is that a gap nobody hit is a backlog, and a backlog reported as a finding is how
12
+ * an agent learns to stop reading findings. This clears that bar on the same test every other
13
+ * instrumentation gap clears it on: **did the absence make THIS verdict weaker?** An unwatched store
14
+ * weakens every state assertion made over it, not merely the first, so it is reported on every one.
15
+ * An undeclared change is the same shape — while nothing says what the edit was for, each verdict
16
+ * drawn after it is checked against nothing but itself, and that is true of the fifth one exactly as
17
+ * it was of the first. Reporting it once and then falling silent would leave four verdicts carrying
18
+ * a weakness they no longer disclose, which is the failure mode this whole surface exists to prevent.
19
+ *
20
+ * It is also not a backlog, because it is not a survey of the project: it is answered from what this
21
+ * session observed (an epoch that moved) about the verdict being returned right now, and it is
22
+ * closed by one call the agent can make immediately. A finding that stays open only because the
23
+ * agent has not made that call is a finding about the current verdict, not a chore.
24
+ *
25
+ * ## The silences, and why each one is required
26
+ *
27
+ * - **An edit was actually OBSERVED.** The epoch degrades to `NO_EDITS_OBSERVED` outside Vite, and
28
+ * that means "no edits observed", never "no edits happened" — a finding built on an absence
29
+ * Reticle cannot see would be a fabrication.
30
+ * - **The ledger holds nothing undischarged.** An open intent IS the declaration; silence is the
31
+ * correct response to it, and declaring one is what turns this off from the next verdict on.
32
+ *
33
+ * ## Why "covers the work" is answered as "anything open at all"
34
+ *
35
+ * The tempting answer is to match the intent's `surface` against the files that changed. Reticle
36
+ * cannot do that honestly: it observes that an epoch advanced, not WHAT advanced — the hot-update
37
+ * channel reports a counter, not a diff — so any file-level matching would be inference dressed as a
38
+ * fact, and it would fire on an agent that had declared its intent perfectly well. Over-reporting on
39
+ * a correct agent is the direction of error that trains it to stop reading findings.
40
+ *
41
+ * So the question asked is the coarse one, and it is asked honestly: has the agent declared anything
42
+ * that is still outstanding? If it has, it is working to a stated purpose and this stays quiet.
43
+ */
44
+ /**
45
+ * `openIntents` is a thunk rather than a list because reading the ledger touches disk, and the epoch
46
+ * check answers without it for every page that never reported a hot update — which is most of them.
47
+ * Once an edit HAS been observed the read happens per verdict, and that is the intended cost: the
48
+ * ledger is the only thing that can end it, so it has to be re-asked each time.
49
+ */
50
+ export async function isChangeUndeclared(
51
+ /** The epoch the session is under now. Undefined when the page never stamped one. */
52
+ currentEpoch, openIntents) {
53
+ if (undefined === currentEpoch || NO_EDITS_OBSERVED === currentEpoch)
54
+ return false;
55
+ return 0 === (await openIntents()).length;
56
+ }
@@ -0,0 +1,10 @@
1
+ import { type ReticleEvent } from '@reticlehq/core';
2
+ /**
3
+ * The writes whose outcome went unread, as "METHOD url".
4
+ *
5
+ * Named rather than counted, because a caveat an agent cannot locate is a caveat it learns to skip.
6
+ * The sentence used to say "a write returned 2xx with a response body that was never recorded" and
7
+ * name no write, which is unactionable on any page that makes more than one call.
8
+ */
9
+ export declare function unreadWriteLabels(events: readonly ReticleEvent[]): string[];
10
+ export declare function hasUnreadWriteOutcome(events: readonly ReticleEvent[]): boolean;
@@ -0,0 +1,77 @@
1
+ import { EventType, MUTATING_METHODS, NetInitiator, isDevToolingUrl, } from '@reticlehq/core';
2
+ import { asString } from '@reticlehq/core';
3
+ const IPC_METHOD = NetInitiator.IPC.toUpperCase();
4
+ /**
5
+ * A write whose outcome is sitting in a payload nobody read.
6
+ *
7
+ * `findBodyFailures` catches a 2xx that reports failure inside its body — but only when body capture
8
+ * is on, and it is OFF by default. Without this, the same window produces `verified: "yes"` with the
9
+ * reason "no channel disagreeing", which is true only because one channel was never opened. That is
10
+ * lying by omission, and it is the precise failure this honesty layer exists to prevent.
11
+ *
12
+ * Measured on a shipments console: `POST /api/bulk-hold` → 200, banner reads "9 shipments held",
13
+ * three of the nine failed inside the body. With capture on Reticle now says so. With capture off it
14
+ * said `verified: "yes"`.
15
+ *
16
+ * Deliberately narrow, because over-warning trains agents to ignore the field:
17
+ *
18
+ * - **writes only.** A GET's payload is what the UI renders, so the DOM already witnesses it. A
19
+ * write's outcome has no other witness.
20
+ * - **a payload that DEMONSTRABLY exists.** `responseSize > 0` with no recorded body means unread.
21
+ * An absent size or a genuinely empty response says nothing and is left alone — the distinction
22
+ * between "empty" and "unseen" is the whole point, so it must not be guessed.
23
+ * - **HTTP only.** An IPC record is excluded, and the reason is the rule's own premise: a 2xx is
24
+ * emitted by a framework whatever the app decided, so it describes the transport. An IPC `ok`
25
+ * means the main-process handler ran to completion without throwing — an application-level
26
+ * verdict, already reported. Treating the two as equivalent made every ordinary Electron action
27
+ * return `unknown` (measured: a healthy `todos:add` on the default config), which is the
28
+ * cry-wolf failure that teaches agents to ignore the field.
29
+ *
30
+ * The residual gap is real and narrower: a handler that RESOLVES with a failure inside its payload
31
+ * is invisible without body capture. That case is `findBodyFailures`, which reads the payload and
32
+ * catches it precisely — with capture on, where it belongs.
33
+ *
34
+ * - **the app's own traffic only.** The DEV TOOLCHAIN writes too: Next's overlay answers
35
+ * `POST /__nextjs_original-stack-frames` with a JSON body the moment the app logs one React
36
+ * warning, and nothing captures it. Judged as the app's write, that made every verdict in a Next
37
+ * dev app `unknown` — decided by a channel the caller never asked about, on a request the app did
38
+ * not make. `findContradictions` has split this traffic out for the same reason since the overlay
39
+ * turned correct navigations red; this rule was reading the unsplit window.
40
+ */
41
+ const OK_MIN = 200;
42
+ const OK_MAX = 300;
43
+ /**
44
+ * The writes whose outcome went unread, as "METHOD url".
45
+ *
46
+ * Named rather than counted, because a caveat an agent cannot locate is a caveat it learns to skip.
47
+ * The sentence used to say "a write returned 2xx with a response body that was never recorded" and
48
+ * name no write, which is unactionable on any page that makes more than one call.
49
+ */
50
+ export function unreadWriteLabels(events) {
51
+ const labels = [];
52
+ for (const event of events) {
53
+ if (event.type !== EventType.NET_REQUEST)
54
+ continue;
55
+ const method = ('string' === typeof event.data['method'] ? event.data['method'] : '').toUpperCase();
56
+ if (method === IPC_METHOD || !MUTATING_METHODS.includes(method))
57
+ continue;
58
+ const url = asString(event.data['url']);
59
+ if (isDevToolingUrl(url))
60
+ continue;
61
+ const status = event.data['status'];
62
+ if (typeof status !== 'number' || status < OK_MIN || status >= OK_MAX)
63
+ continue;
64
+ if (event.data['responseBody'] !== undefined)
65
+ continue; // read — findBodyFailures judged it
66
+ const size = event.data['responseSize'];
67
+ if ('number' !== typeof size || size <= 0)
68
+ continue;
69
+ const label = `${method} ${url ?? ''}`.trim();
70
+ if (!labels.includes(label))
71
+ labels.push(label);
72
+ }
73
+ return labels;
74
+ }
75
+ export function hasUnreadWriteOutcome(events) {
76
+ return unreadWriteLabels(events).length > 0;
77
+ }
@@ -0,0 +1,58 @@
1
+ /**
2
+ * What an `unsettled` verdict was waiting for, and what its window held instead.
3
+ *
4
+ * `unsettled` is the commonest reason a verdict comes back `unknown`, and all it said was that the
5
+ * page "never settled" — a sentence equally true of a page that polls, a page that animates, and a
6
+ * page whose write is still open. Those need three different next moves, and an agent handed the
7
+ * sentence cannot tell which it is holding, so the drive stops there. An `unknown` that explains
8
+ * itself is a retry; one that does not is a dead end.
9
+ *
10
+ * Two releases already tuned this window and neither is undone here. The budget is still spent in
11
+ * full before anything is called unsettled (settle-in-flight.ts), and the app is still given its
12
+ * reaction window before any accusation (waitForReaction). This only describes what was true at the
13
+ * moment the budget genuinely ran out.
14
+ *
15
+ * It rides in `because`, beside `verifiedReason`, rather than in a field of its own: the verdict has
16
+ * one sentence an agent is known to read, and a caveat parked anywhere else is a caveat nobody reads.
17
+ */
18
+ import type { Predicate } from '../question/predicate/predicate.js';
19
+ export interface UnsettledWindow {
20
+ /** What the wait was for, in the caller's own terms — see `describeWaitTarget`. */
21
+ waitedFor: string;
22
+ /** Requests that started in this window and had not come back, as "METHOD url". */
23
+ stillInFlight: readonly string[];
24
+ /**
25
+ * Endpoints called more than once in this window, as "METHOD url ×N" — see `repeatedRequestLabels`.
26
+ *
27
+ * The case `stillInFlight` structurally cannot see: a retry loop against a dead backend completes
28
+ * every attempt, so nothing is ever outstanding, and the verdict fell through to a sentence that
29
+ * blamed unnamed churn on an app whose whole problem was one endpoint being hammered. Optional —
30
+ * a caller that does not supply it gets exactly the sentence that shipped before.
31
+ */
32
+ repeated?: readonly string[];
33
+ }
34
+ /**
35
+ * The wait, in one phrase.
36
+ *
37
+ * The default matters most: a call that declares no `until` waits for the page to go IDLE, and an
38
+ * agent that never chose that wait cannot be expected to recognise it in a timeout about it.
39
+ */
40
+ export declare function describeWaitTarget(predicate: Predicate): string;
41
+ /**
42
+ * Did the assertion name a request that is still open?
43
+ *
44
+ * `waitForPredicate` reports a miss ("no request to /register") the moment the budget ends, even
45
+ * when that same POST is sitting in `stillInFlight`. Grading that miss `no` is a race against the
46
+ * backend, not a defect. Matching is the discriminator: an unrelated poll left open does not pardon
47
+ * a named URL that never started.
48
+ */
49
+ export declare function namedNetIsInFlight(predicate: Predicate, stillInFlight: readonly string[]): boolean;
50
+ /**
51
+ * The `because` sentence for an unsettled verdict: the wait, the observation, the next move.
52
+ *
53
+ * The two branches are the point. An outstanding write is worth waiting for and worth asserting
54
+ * directly; page churn is neither, and telling an agent to raise its timeout on churn sells it a
55
+ * slower dead end. Without the detail the sentence is the one that shipped before, so a caller that
56
+ * cannot supply the facts loses nothing.
57
+ */
58
+ export declare function unsettledBecause(base: string, window: UnsettledWindow | undefined): string;
@@ -0,0 +1,127 @@
1
+ /**
2
+ * What an `unsettled` verdict was waiting for, and what its window held instead.
3
+ *
4
+ * `unsettled` is the commonest reason a verdict comes back `unknown`, and all it said was that the
5
+ * page "never settled" — a sentence equally true of a page that polls, a page that animates, and a
6
+ * page whose write is still open. Those need three different next moves, and an agent handed the
7
+ * sentence cannot tell which it is holding, so the drive stops there. An `unknown` that explains
8
+ * itself is a retry; one that does not is a dead end.
9
+ *
10
+ * Two releases already tuned this window and neither is undone here. The budget is still spent in
11
+ * full before anything is called unsettled (settle-in-flight.ts), and the app is still given its
12
+ * reaction window before any accusation (waitForReaction). This only describes what was true at the
13
+ * moment the budget genuinely ran out.
14
+ *
15
+ * It rides in `because`, beside `verifiedReason`, rather than in a field of its own: the verdict has
16
+ * one sentence an agent is known to read, and a caveat parked anywhere else is a caveat nobody reads.
17
+ */
18
+ import { PredicateKind } from '@reticlehq/core';
19
+ /** Enough to recognise the one that is stuck; not so many that a chatty window eats the verdict. */
20
+ const MAX_LISTED_REQUESTS = 3;
21
+ /**
22
+ * The wait, in one phrase.
23
+ *
24
+ * The default matters most: a call that declares no `until` waits for the page to go IDLE, and an
25
+ * agent that never chose that wait cannot be expected to recognise it in a timeout about it.
26
+ */
27
+ export function describeWaitTarget(predicate) {
28
+ switch (predicate.kind) {
29
+ case PredicateKind.SETTLED:
30
+ return 'the page to go idle';
31
+ case PredicateKind.SIGNAL:
32
+ return predicate.name === undefined ? 'any signal' : `signal '${predicate.name}'`;
33
+ case PredicateKind.NET:
34
+ return `a request${predicate.method === undefined ? '' : ` ${predicate.method}`}${predicate.urlContains === undefined ? '' : ` matching '${predicate.urlContains}'`}`;
35
+ case PredicateKind.ROUTE:
36
+ return `a route change${predicate.pathname === undefined ? '' : ` to '${predicate.pathname}'`}${predicate.contains === undefined ? '' : ` containing '${predicate.contains}'`}`;
37
+ case PredicateKind.STATE:
38
+ return `state at '${predicate.path}'`;
39
+ case PredicateKind.TEXT:
40
+ return `text containing '${predicate.contains}'`;
41
+ case PredicateKind.ELEMENT:
42
+ return `an element matching ${JSON.stringify(predicate.query)}`;
43
+ case PredicateKind.CONSOLE:
44
+ return 'a console message';
45
+ case PredicateKind.ANIMATION:
46
+ return predicate.name === undefined ? 'an animation' : `animation '${predicate.name}'`;
47
+ case PredicateKind.ALL_OF:
48
+ return `all of (${predicate.predicates.map(describeWaitTarget).join('; ')})`;
49
+ case PredicateKind.ANY_OF:
50
+ return `any of (${predicate.predicates.map(describeWaitTarget).join('; ')})`;
51
+ case PredicateKind.NOT:
52
+ return `the absence of ${describeWaitTarget(predicate.predicate)}`;
53
+ }
54
+ }
55
+ /**
56
+ * Did the assertion name a request that is still open?
57
+ *
58
+ * `waitForPredicate` reports a miss ("no request to /register") the moment the budget ends, even
59
+ * when that same POST is sitting in `stillInFlight`. Grading that miss `no` is a race against the
60
+ * backend, not a defect. Matching is the discriminator: an unrelated poll left open does not pardon
61
+ * a named URL that never started.
62
+ */
63
+ export function namedNetIsInFlight(predicate, stillInFlight) {
64
+ if (0 === stillInFlight.length)
65
+ return false;
66
+ const nets = [];
67
+ const walk = (p) => {
68
+ switch (p.kind) {
69
+ case PredicateKind.ALL_OF:
70
+ case PredicateKind.ANY_OF:
71
+ for (const child of p.predicates)
72
+ walk(child);
73
+ return;
74
+ case PredicateKind.NET: {
75
+ if (undefined === p.urlContains || 0 === p.urlContains.length)
76
+ return;
77
+ nets.push({
78
+ ...(undefined === p.method ? {} : { method: p.method }),
79
+ urlContains: p.urlContains,
80
+ });
81
+ return;
82
+ }
83
+ default:
84
+ return;
85
+ }
86
+ };
87
+ walk(predicate);
88
+ return nets.some((net) => stillInFlight.some((label) => inFlightLabelMatchesNet(label, net)));
89
+ }
90
+ function inFlightLabelMatchesNet(label, net) {
91
+ const space = label.indexOf(' ');
92
+ if (space <= 0)
93
+ return false;
94
+ const method = label.slice(0, space);
95
+ const url = label.slice(space + 1);
96
+ if (undefined !== net.method && method.toUpperCase() !== net.method.toUpperCase())
97
+ return false;
98
+ return url.includes(net.urlContains);
99
+ }
100
+ /**
101
+ * The `because` sentence for an unsettled verdict: the wait, the observation, the next move.
102
+ *
103
+ * The two branches are the point. An outstanding write is worth waiting for and worth asserting
104
+ * directly; page churn is neither, and telling an agent to raise its timeout on churn sells it a
105
+ * slower dead end. Without the detail the sentence is the one that shipped before, so a caller that
106
+ * cannot supply the facts loses nothing.
107
+ */
108
+ export function unsettledBecause(base, window) {
109
+ if (window === undefined)
110
+ return `${base} — re-check, or assert a consequence that settles`;
111
+ if (0 === window.stillInFlight.length) {
112
+ const repeated = window.repeated ?? [];
113
+ return (`${base}. It waited for ${window.waitedFor}, and no request started in this window was left ` +
114
+ 'open — what kept the page busy was its own churn ' +
115
+ (0 === repeated.length
116
+ ? '(a poll, a timer, an animation)'
117
+ : `(these fired repeatedly: ${repeated.join(', ')} — a poll or a retrying query)`) +
118
+ ', so waiting longer will not help. Assert the consequence you care about (a signal, a route ' +
119
+ 'change, or store state) instead of waiting for idle, and re-check if the app is genuinely slow');
120
+ }
121
+ const shown = window.stillInFlight.slice(0, MAX_LISTED_REQUESTS);
122
+ const rest = window.stillInFlight.length - shown.length;
123
+ return (`${base}. It waited for ${window.waitedFor}, and ${String(window.stillInFlight.length)} ` +
124
+ `request(s) started in this window had not come back: ${shown.join(', ')}` +
125
+ `${rest > 0 ? `, and ${String(rest)} more` : ''} — re-check once they land, raise timeout_ms, ` +
126
+ 'or assert the request itself so the wait ends on the response rather than on idle');
127
+ }
@@ -0,0 +1,30 @@
1
+ import { type InstrumentationGap } from '@reticlehq/core';
2
+ /**
3
+ * A verdict that proved something nobody named, said out loud.
4
+ *
5
+ * Intent capture was already built and already reachable: an optional `intent` argument on the
6
+ * advertised verdict tools, writing the same ledger `reticle_intent` writes. What was missing is
7
+ * anybody asking for it. The nudge lived on `flow_save` alone, and a build-mode agent may never save
8
+ * a flow — it drives, asserts, reads a verdict, and never hears the word.
9
+ *
10
+ * An optional capability nobody is told about is one nobody uses. That is not a guess about this
11
+ * codebase: the same shape was measured on `reticle_network`'s `bodies` flag this week, where a real
12
+ * saving went untaken for months because the flag defaulted the expensive way and nothing mentioned
13
+ * it.
14
+ *
15
+ * Three restrictions, each deliberate:
16
+ *
17
+ * - Only on a PASS. A red verdict already carries a finding worth the reader's attention, and
18
+ * bookkeeping stacked on a failure buries the thing that failed.
19
+ * - Never on `no-fault` or `unknown`. Nothing was proved, so no intent was owed — asking there would
20
+ * train the reader to ignore the ask.
21
+ * - Never derived. It reports that the statement is missing and never guesses what it was, for the
22
+ * reason `flowIntentGap` gives: anything specific enough to identify the goal is specific enough
23
+ * to be read AS the goal, and somebody will act on it.
24
+ *
25
+ * It never fails a verdict. A tool that refuses to record work is one people route around.
26
+ */
27
+ export declare function verdictIntentGap(input: {
28
+ verified: string;
29
+ intent: string | undefined;
30
+ }): InstrumentationGap | undefined;
@@ -0,0 +1,35 @@
1
+ import { InstrumentationGapKind, instrumentationGap, } from '@reticlehq/core';
2
+ /**
3
+ * A verdict that proved something nobody named, said out loud.
4
+ *
5
+ * Intent capture was already built and already reachable: an optional `intent` argument on the
6
+ * advertised verdict tools, writing the same ledger `reticle_intent` writes. What was missing is
7
+ * anybody asking for it. The nudge lived on `flow_save` alone, and a build-mode agent may never save
8
+ * a flow — it drives, asserts, reads a verdict, and never hears the word.
9
+ *
10
+ * An optional capability nobody is told about is one nobody uses. That is not a guess about this
11
+ * codebase: the same shape was measured on `reticle_network`'s `bodies` flag this week, where a real
12
+ * saving went untaken for months because the flag defaulted the expensive way and nothing mentioned
13
+ * it.
14
+ *
15
+ * Three restrictions, each deliberate:
16
+ *
17
+ * - Only on a PASS. A red verdict already carries a finding worth the reader's attention, and
18
+ * bookkeeping stacked on a failure buries the thing that failed.
19
+ * - Never on `no-fault` or `unknown`. Nothing was proved, so no intent was owed — asking there would
20
+ * train the reader to ignore the ask.
21
+ * - Never derived. It reports that the statement is missing and never guesses what it was, for the
22
+ * reason `flowIntentGap` gives: anything specific enough to identify the goal is specific enough
23
+ * to be read AS the goal, and somebody will act on it.
24
+ *
25
+ * It never fails a verdict. A tool that refuses to record work is one people route around.
26
+ */
27
+ export function verdictIntentGap(input) {
28
+ if ('yes' !== input.verified)
29
+ return undefined;
30
+ // Blank is the shape an agent produces when it means to comply and has nothing to say. Treating it
31
+ // as satisfied would turn the ask into a formality the first time somebody passed an empty string.
32
+ if (input.intent !== undefined && input.intent.trim().length > 0)
33
+ return undefined;
34
+ return instrumentationGap(InstrumentationGapKind.NO_FLOW_INTENT, 'this verdict proved something, and no intent says what it was meant to make true', 'the pass is real but it is only about this run — six months from now the ledger can say a check went green and not what stopped being false, so a later agent re-derives the goal from the steps instead of reading it');
35
+ }