@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,113 @@
1
+ /**
2
+ * The honesty block — one machine-readable field composing everything that qualifies a verdict's
3
+ * trustworthiness: the assertion grade, the attribution tier, the envelope maturity, the verified-surface
4
+ * coverage, and the capture integrity. The invariant: a green may never LOOK stronger than its honesty
5
+ * block. Harnesses gate on it (e.g. "grade ≥ net AND integrity clean"). This is pure composition +
6
+ * assessment — all five components already exist individually; wiring it onto results is a later step.
7
+ */
8
+ import type { CaptureLoss } from '@reticlehq/core';
9
+ /** Assertion grade, strongest first — the tier the verdict actually proved. */
10
+ export declare const HonestyGrade: {
11
+ readonly SIGNAL: "signal";
12
+ readonly NET: "net";
13
+ readonly STATE: "state";
14
+ readonly PRESENCE: "presence";
15
+ readonly NONE: "none";
16
+ };
17
+ export type HonestyGrade = (typeof HonestyGrade)[keyof typeof HonestyGrade];
18
+ /**
19
+ * Compare two grades on the one ladder, so nothing outside this file re-derives the order.
20
+ *
21
+ * Both directions are needed, and which one is correct is a fact about the claim rather than a
22
+ * preference: an AND greens only when every branch held, so the STRONGEST branch is honestly
23
+ * claimable; an OR greens on a single branch and nothing records which, so only the WEAKEST is.
24
+ * Callers that picked for themselves are how a combinator ends up graded by its first child.
25
+ */
26
+ export declare const strongerGrade: (a: HonestyGrade, b: HonestyGrade) => HonestyGrade;
27
+ export declare const weakerGrade: (a: HonestyGrade, b: HonestyGrade) => HonestyGrade;
28
+ interface HonestyInputs {
29
+ grade: HonestyGrade;
30
+ /** Present when a causal chain is presented; `window` = time-heuristic, never dataflow truth. */
31
+ attribution?: string;
32
+ envelopeSamples?: number;
33
+ coveragePct?: number;
34
+ coveragePartial?: boolean;
35
+ /**
36
+ * The sentence naming WHAT went unobserved, from `buildCoverageStatement`.
37
+ *
38
+ * Separate from `blindSpots`, which carries only the IMPEACHING notes — the ones that downgrade a
39
+ * verdict. A bounding spot does not impeach anything, so it never entered that list, and the flag
40
+ * that survived (`partial: true`) is unanswerable on its own: the verdict prose tells the reader
41
+ * to see `coverage` for what went unobserved, and there was nothing there to see.
42
+ */
43
+ coverageNote?: string;
44
+ truncated?: boolean;
45
+ blindSpots?: readonly string[];
46
+ /**
47
+ * The machine-readable half of `issues` — WHICH kind of loss, from core's closed `CaptureLoss`.
48
+ *
49
+ * `issues` is prose built for an agent to read, and prose is not something a dashboard can group
50
+ * by: `unclean_capture` became a large share of all field verdicts with no way to ask which of its three
51
+ * causes produced them. Passed by the caller rather than derived here, because only the caller
52
+ * knows whether a blind-spot note came from the browser transport or from a boundary in the page.
53
+ */
54
+ losses?: readonly CaptureLoss[];
55
+ /**
56
+ * Did the page go quiet inside the action's window? Omitted when nothing measured it.
57
+ *
58
+ * Settlement stopped being a veto over a declared consequence that held (see `verified.ts`), and a
59
+ * fact that no longer decides the verdict must not therefore disappear: a page that never goes
60
+ * idle is worth knowing about, and a caller who cares can still gate on it. Reported here rather
61
+ * than beside `verified`, where the answer belongs to the rule and not to its inputs.
62
+ */
63
+ settled?: boolean;
64
+ }
65
+ export interface HonestyBlock {
66
+ grade: HonestyGrade;
67
+ attribution?: string;
68
+ /** Present only when an envelope was actually sampled — never a fabricated zero. */
69
+ envelope?: {
70
+ samples: number;
71
+ sufficient: boolean;
72
+ };
73
+ /** `pct` is present only when it was measured (or provably full); `partial` is always known. */
74
+ coverage: {
75
+ pct?: number;
76
+ partial: boolean;
77
+ note?: string;
78
+ };
79
+ integrity: {
80
+ clean: boolean;
81
+ issues: string[];
82
+ losses?: CaptureLoss[];
83
+ };
84
+ /** Whether the page went quiet in this window — present only when it was measured. */
85
+ settled?: boolean;
86
+ }
87
+ export declare function buildHonestyBlock(inputs: HonestyInputs): HonestyBlock;
88
+ interface HonestyBar {
89
+ /** The minimum grade a green must carry to be trusted (default: any). */
90
+ minGrade?: HonestyGrade;
91
+ /** Require capture integrity to be clean (no truncation / blind spots). */
92
+ requireIntegrityClean?: boolean;
93
+ }
94
+ /** Whether a verdict's honesty block clears the harness's bar. Reasons list every failed criterion. */
95
+ export declare function meetsHonestyBar(block: HonestyBlock, bar?: HonestyBar): {
96
+ ok: boolean;
97
+ reasons: string[];
98
+ };
99
+ /**
100
+ * The coverage sentence, kept only on a verdict that points at it.
101
+ *
102
+ * Exactly one branch of `decideVerified` promises it — the YES branch says "coverage was PARTIAL —
103
+ * see `coverage` for what went unobserved". UNKNOWN keeps it too, because "I could not tell" is a
104
+ * statement about what went unseen and the note is the answer. A NO has already named a concrete
105
+ * counter-example, nothing directs the reader to `coverage`, and `partial` plus the spot kinds still
106
+ * travel — so the prose there is cost with no question behind it.
107
+ *
108
+ * Measured: emitting it on every verdict regressed the benchmark's verification efficiency by 4.1%,
109
+ * one note per observation. Accuracy outranks tokens, but this buys no accuracy — the promise is
110
+ * kept wherever it is made.
111
+ */
112
+ export declare function honestyForVerdict(verified: string, honesty: HonestyBlock): HonestyBlock;
113
+ export {};
@@ -0,0 +1,105 @@
1
+ /**
2
+ * The honesty block — one machine-readable field composing everything that qualifies a verdict's
3
+ * trustworthiness: the assertion grade, the attribution tier, the envelope maturity, the verified-surface
4
+ * coverage, and the capture integrity. The invariant: a green may never LOOK stronger than its honesty
5
+ * block. Harnesses gate on it (e.g. "grade ≥ net AND integrity clean"). This is pure composition +
6
+ * assessment — all five components already exist individually; wiring it onto results is a later step.
7
+ */
8
+ import { Verified } from '@reticlehq/core';
9
+ /** Assertion grade, strongest first — the tier the verdict actually proved. */
10
+ export const HonestyGrade = {
11
+ SIGNAL: 'signal',
12
+ NET: 'net',
13
+ STATE: 'state',
14
+ PRESENCE: 'presence',
15
+ NONE: 'none',
16
+ };
17
+ const GRADE_RANK = {
18
+ [HonestyGrade.SIGNAL]: 4,
19
+ [HonestyGrade.NET]: 3,
20
+ [HonestyGrade.STATE]: 2,
21
+ [HonestyGrade.PRESENCE]: 1,
22
+ [HonestyGrade.NONE]: 0,
23
+ };
24
+ /**
25
+ * Compare two grades on the one ladder, so nothing outside this file re-derives the order.
26
+ *
27
+ * Both directions are needed, and which one is correct is a fact about the claim rather than a
28
+ * preference: an AND greens only when every branch held, so the STRONGEST branch is honestly
29
+ * claimable; an OR greens on a single branch and nothing records which, so only the WEAKEST is.
30
+ * Callers that picked for themselves are how a combinator ends up graded by its first child.
31
+ */
32
+ export const strongerGrade = (a, b) => GRADE_RANK[a] >= GRADE_RANK[b] ? a : b;
33
+ export const weakerGrade = (a, b) => GRADE_RANK[a] <= GRADE_RANK[b] ? a : b;
34
+ /** Below this envelope sample count a deviation verdict is noise, not judgment. */
35
+ const MIN_ENVELOPE_SAMPLES = 3;
36
+ /** Coverage when the SDK reported no blind spots during the window — it saw everything it can see. */
37
+ const FULL_COVERAGE_PCT = 100;
38
+ export function buildHonestyBlock(inputs) {
39
+ const issues = [];
40
+ if (true === inputs.truncated)
41
+ issues.push('capture truncated');
42
+ for (const spot of inputs.blindSpots ?? [])
43
+ issues.push(`blind spot: ${spot}`);
44
+ // Report only what was measured. `envelope` used to be emitted unconditionally with samples=0, so
45
+ // every act carried `sufficient: false` — and the tool description tells the agent to gate on this
46
+ // block, meaning an agent that obeyed rejected 100% of green verdicts on a value that never changed.
47
+ // A field that always reads "insufficient" is worse than an absent one: it looks like a finding.
48
+ const samples = inputs.envelopeSamples;
49
+ const partial = inputs.coveragePartial ?? false;
50
+ // Nothing blind reported ⇒ the SDK saw everything it is able to see. When coverage IS partial we know
51
+ // that much but not the fraction, so the percentage is omitted rather than invented.
52
+ const pct = inputs.coveragePct ?? (partial ? undefined : FULL_COVERAGE_PCT);
53
+ return {
54
+ grade: inputs.grade,
55
+ ...(inputs.attribution === undefined ? {} : { attribution: inputs.attribution }),
56
+ ...(samples === undefined
57
+ ? {}
58
+ : { envelope: { samples, sufficient: samples >= MIN_ENVELOPE_SAMPLES } }),
59
+ coverage: {
60
+ ...(pct === undefined ? {} : { pct }),
61
+ partial,
62
+ ...(partial && inputs.coverageNote !== undefined ? { note: inputs.coverageNote } : {}),
63
+ },
64
+ ...(inputs.settled === undefined ? {} : { settled: inputs.settled }),
65
+ integrity: {
66
+ clean: 0 === issues.length,
67
+ issues,
68
+ // Only when something was actually lost. An empty array beside `clean: true` would be a field
69
+ // that is always present and always says nothing, which is how a signal gets tuned out.
70
+ ...(0 === issues.length || undefined === inputs.losses || 0 === inputs.losses.length
71
+ ? {}
72
+ : { losses: [...new Set(inputs.losses)] }),
73
+ },
74
+ };
75
+ }
76
+ /** Whether a verdict's honesty block clears the harness's bar. Reasons list every failed criterion. */
77
+ export function meetsHonestyBar(block, bar = {}) {
78
+ const reasons = [];
79
+ if (bar.minGrade !== undefined && GRADE_RANK[block.grade] < GRADE_RANK[bar.minGrade]) {
80
+ reasons.push(`grade ${block.grade} below required ${bar.minGrade}`);
81
+ }
82
+ if (true === bar.requireIntegrityClean && !block.integrity.clean) {
83
+ reasons.push(`integrity not clean: ${block.integrity.issues.join('; ')}`);
84
+ }
85
+ return { ok: 0 === reasons.length, reasons };
86
+ }
87
+ /**
88
+ * The coverage sentence, kept only on a verdict that points at it.
89
+ *
90
+ * Exactly one branch of `decideVerified` promises it — the YES branch says "coverage was PARTIAL —
91
+ * see `coverage` for what went unobserved". UNKNOWN keeps it too, because "I could not tell" is a
92
+ * statement about what went unseen and the note is the answer. A NO has already named a concrete
93
+ * counter-example, nothing directs the reader to `coverage`, and `partial` plus the spot kinds still
94
+ * travel — so the prose there is cost with no question behind it.
95
+ *
96
+ * Measured: emitting it on every verdict regressed the benchmark's verification efficiency by 4.1%,
97
+ * one note per observation. Accuracy outranks tokens, but this buys no accuracy — the promise is
98
+ * kept wherever it is made.
99
+ */
100
+ export function honestyForVerdict(verified, honesty) {
101
+ if (Verified.NO !== verified || honesty.coverage.note === undefined)
102
+ return honesty;
103
+ const { note: _dropped, ...coverage } = honesty.coverage;
104
+ return { ...honesty, coverage };
105
+ }
@@ -0,0 +1,91 @@
1
+ import { type InstrumentationGap } from '@reticlehq/core/artifacts';
2
+ /**
3
+ * The gaps ONE action revealed, derived from facts the act path already holds.
4
+ *
5
+ * Pure, and deliberately fed by primitives rather than by the action result: every fact below is
6
+ * already computed for other reasons — `actedSource` for the red-verdict file:line, `stateUnwatched`
7
+ * because an empty `stateDiffs` would otherwise read as "the app changed nothing", the signal count
8
+ * and route movement for the causal summary. Nothing here costs a new observation. The gap surface
9
+ * is a second reading of evidence Reticle was already collecting and then discarding.
10
+ *
11
+ * ## Each kind carries its OWN gate
12
+ *
13
+ * The rule is that a gap fires only when the verdict came back weaker because of it — and "weaker"
14
+ * is different per kind, so a single global flag would be a lie in both directions:
15
+ *
16
+ * - a missing source mapping costs nothing on a PASS. The act path already says so in as many
17
+ * words: on green nobody needs the file:line and it is noise. It costs a great deal on a red,
18
+ * where it is the first thing the agent wants;
19
+ * - a missing store costs nothing unless the caller ASKED about state;
20
+ * - a silent mutation costs nothing if the app proved the outcome some other way.
21
+ *
22
+ * Encoding the gates per kind is what keeps this from degenerating into a linter that fires on every
23
+ * uninstrumented control on the page. That surface would be ignored within a day, and it would take
24
+ * the true positives with it.
25
+ */
26
+ export interface ActionInstrumentationFacts {
27
+ /** Did the verdict pass? Several gates turn on this, in different directions. */
28
+ pass: boolean;
29
+ /** True when the outcome was positively PROVED rather than inferred. */
30
+ proved?: boolean;
31
+ /**
32
+ * The `file:line` of the element this verdict is about, when the build plugin stamped one.
33
+ *
34
+ * Was a boolean, on the reasoning that the gap only needed to know WHETHER the agent could be
35
+ * pointed at code. That was true while the only gap reading it was the one that fires when the
36
+ * pointer is missing. It stopped being true the moment a gap wanted to CARRY the pointer: a gap is
37
+ * read back later, out of the ledger, by which time its `ref` is very likely dead, and a boolean
38
+ * cannot be turned back into a location. Both callers already hold this as a formatted string.
39
+ */
40
+ source?: string | undefined;
41
+ /** The ref that was driven, for the report. */
42
+ ref?: string | undefined;
43
+ /** Did the caller's predicate ask about registered state? */
44
+ stateAsked: boolean;
45
+ /** True when the session has no store registered to read. */
46
+ stateUnwatched: boolean;
47
+ /**
48
+ * Did the app declare any capabilities at all?
49
+ *
50
+ * Undefined means NOT KNOWN, and not-known must never become an accusation — callers that predate
51
+ * this field keep their behaviour rather than start reporting a gap they cannot substantiate.
52
+ */
53
+ hasCapabilities?: boolean | undefined;
54
+ /** Did the DOM move in this action's window? */
55
+ domMutated: boolean;
56
+ /** How many app signals fired in the window. */
57
+ signalsFired: number;
58
+ /**
59
+ * Did a code change land since the last verdict with nothing declaring what it was for?
60
+ *
61
+ * Arrives already decided, because the decision needs the intent ledger and this stays pure. Its
62
+ * gate — and the reasoning that keeps it from becoming a nag — lives in `isChangeUndeclared`, and
63
+ * that is the only place allowed to answer it.
64
+ */
65
+ changeUndeclared?: boolean;
66
+ /**
67
+ * How many intents the ledger still holds undischarged. Undefined when nothing consulted it.
68
+ *
69
+ * A count rather than a boolean because the message names the number: "one thing still unproved"
70
+ * and "four things still unproved" are different situations for an agent deciding whether it is
71
+ * finished, and a bare flag makes them read the same.
72
+ */
73
+ openIntentCount?: number;
74
+ /**
75
+ * The page announced that this build has the `data-reticle-source` stamp switched OFF.
76
+ *
77
+ * Only `true` means anything: absent is "nobody said", which is every SDK predating the field and
78
+ * every hand-wired connect. See the HELLO field of the same name.
79
+ */
80
+ sourceMappingDisabled?: boolean;
81
+ /**
82
+ * How long the OLDEST open intent has been owed, in ms.
83
+ *
84
+ * A count alone cannot tell "you declared this a minute ago and have not proved it yet" from
85
+ * "this project has owed eighteen things since last week". Only the first is actionable on the
86
+ * result being read, and a number that is always large is a number people learn to skip — which
87
+ * is exactly how an honest gap gets filtered out along with the noise.
88
+ */
89
+ oldestOpenIntentAgeMs?: number;
90
+ }
91
+ export declare function gapsForAction(facts: ActionInstrumentationFacts): InstrumentationGap[];
@@ -0,0 +1,102 @@
1
+ import { InstrumentationGapKind, dedupeGaps, instrumentationGap, } from '@reticlehq/core/artifacts';
2
+ export function gapsForAction(facts) {
3
+ const gaps = [];
4
+ // A red verdict names the control and cannot name the line that renders it. That is the round trip
5
+ // the agent is about to spend, and the one a build plugin removes permanently.
6
+ //
7
+ // ...unless the project TURNED THE STAMP OFF, which is a different situation with the opposite
8
+ // remedy. Reported from the field: a react-three-fiber app disabled `sourceMapping` because the
9
+ // stamp crashed it to a white screen, and every red verdict afterwards told the reader to install
10
+ // a build plugin that was already there. Only a definite `false` counts — an SDK that says nothing
11
+ // is unknown, and reading silence as an opt-out would mute the honest gap for every app that
12
+ // simply has no source mapping at all.
13
+ if (!facts.pass && facts.source === undefined) {
14
+ const off = true === facts.sourceMappingDisabled;
15
+ gaps.push(instrumentationGap(off ? InstrumentationGapKind.SOURCE_MAPPING_OFF : InstrumentationGapKind.NO_SOURCE_MAPPING, off
16
+ ? 'source mapping is turned off for this build, so no element carries data-reticle-source'
17
+ : 'the control that was driven carries no source mapping', 'this verdict can name the control but not the file and line that render it, so finding the code is a separate search', { ...(facts.ref === undefined ? {} : { ref: facts.ref }) }));
18
+ }
19
+ // Asked about state, and there is no state channel to answer from. Deliberately UNLOCATED: a store
20
+ // is registered once at app setup, nowhere near the control that was driven, and nothing in this
21
+ // window knows where that setup lives. Borrowing the acted line would send the agent to a file
22
+ // that cannot hold the fix — worse than no pointer, because it costs the trip as well.
23
+ // An app that declared NOTHING is told once, without having to be asked.
24
+ //
25
+ // The rule below fires only when an assertion about state could not be answered, which is correct
26
+ // for that gap and leaves the common case silent: an app whose capabilities file registers
27
+ // nothing drives fine, produces verdicts, and never mentions being under-instrumented — unless
28
+ // the agent happens to ask about state, which an agent with no reason to suspect a problem will
29
+ // not do. The session has known the answer the whole time and no verdict ever consulted it.
30
+ //
31
+ // Reported as the same kind, because it is the same missing thing seen from the other side, and
32
+ // guarded so the two conditions cannot report it twice.
33
+ //
34
+ // BOTH arms require `stateUnwatched`, which is the store registry. Keying the first on
35
+ // `hasCapabilities` alone made this fire on apps whose store IS registered and readable: an app
36
+ // that calls `registerStore()` without `registerCapabilities()` has no declaration and a perfectly
37
+ // good store, and got a gap saying "no state can be read from it" in the same response that
38
+ // carried `reticle_state { found: true }`, a populated `stateDiffs`, and `statePathsChanged`
39
+ // naming the store (#700). A gap contradicted by its own response tells the agent to redo work it
40
+ // has already done, and teaches it to distrust the whole block.
41
+ //
42
+ // The kind is NO_STORE_REGISTERED and every sentence it carries is about stores, so the store
43
+ // registry is what it must be keyed on. An undeclared-capabilities app with a working store is a
44
+ // different observation, and if it is worth reporting it needs its own kind and its own words.
45
+ if (facts.stateUnwatched && (false === facts.hasCapabilities || facts.stateAsked)) {
46
+ // Same missing thing, two ways of meeting it — and the sentence has to say which. Describing an
47
+ // assertion about state to an agent that made no such assertion is a false explanation, and a
48
+ // gap nobody can act on is worse than no gap: it costs the trip and teaches the wrong lesson.
49
+ const declaredNothing = false === facts.hasCapabilities;
50
+ gaps.push(instrumentationGap(InstrumentationGapKind.NO_STORE_REGISTERED, declaredNothing
51
+ ? 'this app declared no capabilities at all, so no state can be read from it'
52
+ : 'no store is registered, and this assertion was about state', declaredNothing
53
+ ? 'every verdict here rests on what the DOM happens to show, and reticle_state will stay empty however many flows are driven'
54
+ : 'the assertion could not be answered from the deterministic channel and had to fall back to what the DOM happens to show'));
55
+ }
56
+ // The app moved and said nothing, and Reticle could not prove the outcome another way.
57
+ if (facts.domMutated && 0 === facts.signalsFired && true !== facts.proved) {
58
+ gaps.push(instrumentationGap(InstrumentationGapKind.NO_SIGNAL_ON_MUTATION, 'the DOM changed and no signal fired for it', 'the outcome had to be inferred from the DOM instead of read from the app asserting its own success, which is the strongest evidence available',
59
+ // The one gap here that can be LOCATED. It is about the element that was driven, and that
60
+ // element is exactly what `source` describes — so the pointer is a fact, not a guess. It
61
+ // also outlives the `ref` beside it, which is what makes this gap still actionable when
62
+ // coverage reads it back long after the page has re-rendered.
63
+ {
64
+ ...(facts.ref === undefined ? {} : { ref: facts.ref }),
65
+ ...(facts.source === undefined ? {} : { source: facts.source }),
66
+ }));
67
+ }
68
+ // The one gap here that is not about the app. Deliberately UNLOCATED and deliberately generic: the
69
+ // only honest thing to report is that the intent is absent. Naming the file that changed, or the
70
+ // control that was driven, would invite the reader to treat a guess as the declaration — and a
71
+ // guessed intent reads as the developer's own words, which is strictly worse than honest absence.
72
+ if (true === facts.changeUndeclared) {
73
+ gaps.push(instrumentationGap(InstrumentationGapKind.UNDECLARED_CHANGE, 'code changed since the last verdict and no intent says what the change was for', 'this verdict can only check the app against itself, so a green here means "nothing visibly broke" rather than "the change did what it was meant to"'));
74
+ }
75
+ /**
76
+ * Say how old the debt is, when it is old enough to change what the reader should do.
77
+ *
78
+ * The ledger is a PROJECT's, deliberately — "what does this still owe" outlives one session. But an
79
+ * intent declared minutes ago and one abandoned last week produce the same sentence, and the second
80
+ * one is not about the work in front of you. Naming the age separates them without weakening the
81
+ * gap, and without pretending a stale backlog is this verdict's fault.
82
+ */
83
+ // A green that does not settle what the run OWES.
84
+ //
85
+ // The mirror of `changeUndeclared` above, and the more expensive half: that fires when nothing was
86
+ // declared, this when something was and no verdict ever proved it. Measured on the bench fixture —
87
+ // an agent drew SEVEN green verdicts and reported FIXED on a form that still accepted a
88
+ // whitespace-only service, quoting its own patch as the evidence. Every verdict was honestly
89
+ // green; none of them was about the thing claimed, and nothing in the result said so.
90
+ //
91
+ // Only on a PASS: a failing verdict proved nothing and already says that, so adding this would be
92
+ // two sentences for one fact. It downgrades nothing either — the assertion did hold — it just
93
+ // names the debt on the result the agent is already reading, while it is deciding if it is done.
94
+ // `proved`, not `pass`, because a bare `{ settled }` wait scores the predicate true while proving
95
+ // nothing — the verdict comes back `no-fault`, and keying on `pass` attached "this verdict passed"
96
+ // to a result whose own `because` says it is not verification.
97
+ const owed = facts.openIntentCount ?? 0;
98
+ if (facts.pass && true === facts.proved && 0 < owed) {
99
+ gaps.push(instrumentationGap(InstrumentationGapKind.INTENT_UNDISCHARGED, `this verdict passed, and ${String(owed)} intent(s) declared in this run are still unproved`, 'a green settles what it asserted, not what the run set out to do — reporting done here rests on the change looking right rather than on anything having checked it'));
100
+ }
101
+ return dedupeGaps(gaps);
102
+ }
@@ -0,0 +1,75 @@
1
+ /**
2
+ * What a flow learns from having been run.
3
+ *
4
+ * The assertions a user writes by hand are the ones they thought of. The defects a drive actually
5
+ * finds are the ones the app really has — and today they are reported once and forgotten, so the
6
+ * next replay of the same flow is exactly as blind to them as the first was. A bug can be found,
7
+ * fixed, and silently return, and the flow that caught it the first time says nothing.
8
+ *
9
+ * This is the loop that closes that, and it turns on one distinction that has to be got right:
10
+ *
11
+ * A contradiction observed RIGHT NOW is not an assertion.
12
+ *
13
+ * Asserting "this must not happen" while it IS happening makes the flow red over a defect the user
14
+ * already knows about, and a check that is red for an accepted reason is a check they learn to
15
+ * ignore. Asserting the opposite — "this does happen" — is worse: it pins broken behaviour as
16
+ * expected, producing a regression test that fires when somebody FIXES the bug.
17
+ *
18
+ * So a finding is first remembered as an OPEN issue, and becomes a guard only at the moment a run
19
+ * stops showing it. That moment is the only one where the fix is a fact rather than a hope. After
20
+ * it, the defect's return is a regression — and that is the compounding: every defect this flow has
21
+ * ever seen and survived becomes something the app can never quietly reacquire.
22
+ */
23
+ export declare const GuardState: {
24
+ /** Seen, and still happening. Remembered, deliberately not asserted. */
25
+ readonly OPEN: "open";
26
+ /** Seen, and then observed GONE. Its return is now a regression. */
27
+ readonly GUARDED: "guarded";
28
+ };
29
+ export type GuardState = (typeof GuardState)[keyof typeof GuardState];
30
+ export interface LearnedGuard {
31
+ /** The contradiction kind, as the engine names it. */
32
+ readonly kind: string;
33
+ /** Which step of the flow it was attributed to. The same kind at two steps is two defects. */
34
+ readonly step: number;
35
+ readonly state: GuardState;
36
+ /**
37
+ * Consecutive runs that did not show this defect, while it is still open.
38
+ *
39
+ * Exists because one quiet run is not a fix. Driving a real flow three times, a
40
+ * `request-never-settled` appeared in run 1 and not in run 2 — one second apart, with no code
41
+ * changed. Promoting there would have minted a guard out of INTERMITTENCE, and every later
42
+ * appearance of a flaky defect would then be reported as a regression: flakiness arriving dressed
43
+ * as a code change, which is the most expensive kind of false alarm because it looks actionable.
44
+ *
45
+ * Reset to zero the moment the defect reappears. Consecutive, never cumulative — two quiet runs
46
+ * with a failure between them say "intermittent", not "fixed".
47
+ */
48
+ readonly cleanRuns?: number | undefined;
49
+ }
50
+ export interface SeenContradiction {
51
+ readonly kind: string;
52
+ readonly step: number;
53
+ }
54
+ export interface LearnInput {
55
+ /** What this flow already knows. */
56
+ readonly guards: readonly LearnedGuard[];
57
+ /** What this run saw. */
58
+ readonly seen: readonly SeenContradiction[];
59
+ /**
60
+ * Whether the run could observe at all. Default true.
61
+ *
62
+ * A run that observed NOTHING is not a run that found the app clean, and promoting on it would
63
+ * manufacture guards out of an absence of evidence — the false green, one level up. An empty
64
+ * `seen` from a blind run and an empty `seen` from a clean run are opposite facts.
65
+ */
66
+ readonly observed?: boolean;
67
+ }
68
+ export interface LearnResult {
69
+ readonly guards: LearnedGuard[];
70
+ /** Issues that became guards in this run — the app got better here. */
71
+ readonly promoted: string[];
72
+ /** Guards that fired — the app got worse here. */
73
+ readonly regressed: string[];
74
+ }
75
+ export declare function learnFromRun(input: LearnInput): LearnResult;
@@ -0,0 +1,78 @@
1
+ /**
2
+ * What a flow learns from having been run.
3
+ *
4
+ * The assertions a user writes by hand are the ones they thought of. The defects a drive actually
5
+ * finds are the ones the app really has — and today they are reported once and forgotten, so the
6
+ * next replay of the same flow is exactly as blind to them as the first was. A bug can be found,
7
+ * fixed, and silently return, and the flow that caught it the first time says nothing.
8
+ *
9
+ * This is the loop that closes that, and it turns on one distinction that has to be got right:
10
+ *
11
+ * A contradiction observed RIGHT NOW is not an assertion.
12
+ *
13
+ * Asserting "this must not happen" while it IS happening makes the flow red over a defect the user
14
+ * already knows about, and a check that is red for an accepted reason is a check they learn to
15
+ * ignore. Asserting the opposite — "this does happen" — is worse: it pins broken behaviour as
16
+ * expected, producing a regression test that fires when somebody FIXES the bug.
17
+ *
18
+ * So a finding is first remembered as an OPEN issue, and becomes a guard only at the moment a run
19
+ * stops showing it. That moment is the only one where the fix is a fact rather than a hope. After
20
+ * it, the defect's return is a regression — and that is the compounding: every defect this flow has
21
+ * ever seen and survived becomes something the app can never quietly reacquire.
22
+ */
23
+ export const GuardState = {
24
+ /** Seen, and still happening. Remembered, deliberately not asserted. */
25
+ OPEN: 'open',
26
+ /** Seen, and then observed GONE. Its return is now a regression. */
27
+ GUARDED: 'guarded',
28
+ };
29
+ /**
30
+ * Consecutive quiet runs before an open defect becomes a guard.
31
+ *
32
+ * Two, not one, for the reason recorded on `cleanRuns`. Not more than two: every extra run is a
33
+ * real replay the user pays for, and a defect that stays away twice in a row has earned the benefit
34
+ * of the doubt — a guard being wrong costs one investigated regression, while never promoting costs
35
+ * every regression this mechanism exists to catch.
36
+ */
37
+ const CLEAN_RUNS_TO_PROMOTE = 2;
38
+ const idOf = (kind, step) => `${kind}@${String(step)}`;
39
+ export function learnFromRun(input) {
40
+ const observed = input.observed ?? true;
41
+ const seenIds = new Set(input.seen.map((s) => idOf(s.kind, s.step)));
42
+ const guards = [];
43
+ const promoted = [];
44
+ const regressed = [];
45
+ for (const guard of input.guards) {
46
+ const isSeen = seenIds.has(idOf(guard.kind, guard.step));
47
+ if (GuardState.GUARDED === guard.state) {
48
+ // This flow proved once that this defect was gone. Its return is the regression this whole
49
+ // mechanism exists to catch. The guard STAYS guarded: a defect that comes back has not
50
+ // un-learned anything, and demoting it would mean the next return goes unreported too.
51
+ if (isSeen)
52
+ regressed.push(guard.kind);
53
+ guards.push(guard);
54
+ continue;
55
+ }
56
+ // Open, and gone — but only a run that could actually look is allowed to conclude that.
57
+ if (!isSeen && observed) {
58
+ const clean = (guard.cleanRuns ?? 0) + 1;
59
+ if (clean >= CLEAN_RUNS_TO_PROMOTE) {
60
+ guards.push({ kind: guard.kind, step: guard.step, state: GuardState.GUARDED });
61
+ promoted.push(guard.kind);
62
+ }
63
+ else {
64
+ guards.push({ ...guard, cleanRuns: clean });
65
+ }
66
+ continue;
67
+ }
68
+ // Seen again: the streak is broken, not merely paused.
69
+ guards.push(isSeen ? { ...guard, cleanRuns: 0 } : guard);
70
+ }
71
+ const known = new Set(input.guards.map((g) => idOf(g.kind, g.step)));
72
+ for (const s of input.seen) {
73
+ if (known.has(idOf(s.kind, s.step)))
74
+ continue;
75
+ guards.push({ kind: s.kind, step: s.step, state: GuardState.OPEN });
76
+ }
77
+ return { guards, promoted, regressed };
78
+ }
@@ -0,0 +1,38 @@
1
+ import type { InstrumentationGap } from '@reticlehq/core/artifacts';
2
+ /**
3
+ * Of the controls this session drove, how many could Reticle fully observe?
4
+ *
5
+ * The first honest denominator this product has ever had. `reticle_verify{action:"coverage"}`
6
+ * already answers "which controls did you not drive"; this answers the question underneath it —
7
+ * *of the ones you did drive, how many could the app actually answer for?* A high untouched-count is
8
+ * work remaining for the agent. A low observability is work remaining in the APP, and no amount of
9
+ * driving closes it.
10
+ *
11
+ * ## Two things it deliberately refuses to do
12
+ *
13
+ * **It does not report a percentage for an empty run.** 0/0 rendered as 100% is the most flattering
14
+ * possible reading of no evidence at all, and a coverage number that starts perfect is one nobody
15
+ * believes the first time it drops.
16
+ *
17
+ * **It does not count app-level gaps against a control.** An unregistered store or an unsignalled
18
+ * route is missing from the application, not from a button. Attributing it to whichever control
19
+ * happened to be driven would put the number on the wrong thing and make it move for reasons the
20
+ * agent cannot act on. Those gaps are reported alongside, not divided into.
21
+ */
22
+ interface Observability {
23
+ /** Distinct controls driven this session. */
24
+ driven: number;
25
+ /** How many of them Reticle could fully observe. */
26
+ observable: number;
27
+ /** Rounded percentage. OMITTED when nothing was driven — see above. */
28
+ percent?: number;
29
+ }
30
+ export declare function observabilityOf(drivenRefs: Iterable<string>, gaps: readonly InstrumentationGap[]): Observability;
31
+ interface CoverageRegression {
32
+ was: number;
33
+ now: number;
34
+ }
35
+ export declare function coverageRegressed(best: {
36
+ percent: number;
37
+ } | undefined, current: Observability): CoverageRegression | undefined;
38
+ export {};
@@ -0,0 +1,40 @@
1
+ export function observabilityOf(
2
+ // Iterable, not an array: the session holds these as a Set, and making the caller spread it would
3
+ // be a conversion that exists only to satisfy a signature.
4
+ drivenRefs, gaps) {
5
+ const driven = new Set(drivenRefs);
6
+ const impaired = new Set();
7
+ for (const gap of gaps) {
8
+ // App-level gaps carry no ref, and a gap on a control this session never drove is about some
9
+ // earlier route — neither belongs in a ratio over what WAS driven.
10
+ if (gap.ref !== undefined && driven.has(gap.ref))
11
+ impaired.add(gap.ref);
12
+ }
13
+ const observable = driven.size - impaired.size;
14
+ if (0 === driven.size)
15
+ return { driven: 0, observable: 0 };
16
+ return { driven: driven.size, observable, percent: Math.round((observable / driven.size) * 100) };
17
+ }
18
+ /**
19
+ * The floor under the number, shipped with it rather than after it.
20
+ *
21
+ * A coverage figure with no downgrade check is a figure that gets gamed, and we would be the ones
22
+ * teaching agents to game it: the cheapest way to stop a gap firing is to stop asserting the thing
23
+ * that revealed it. The same reasoning already runs for flow assertions in `assertion-tiers-store`,
24
+ * where a flow that passes more weakly than it used to is a finding rather than a pass.
25
+ *
26
+ * Returns undefined — not a false — when there is nothing honest to compare. A first run has no
27
+ * best to fall from, and a run that drove almost nothing is evidence of a short session rather than
28
+ * of a regression.
29
+ */
30
+ /** Below this, a run is too small for its ratio to mean anything. */
31
+ const MIN_DRIVEN_TO_COMPARE = 3;
32
+ export function coverageRegressed(best, current) {
33
+ if (best === undefined)
34
+ return undefined;
35
+ if (current.percent === undefined)
36
+ return undefined;
37
+ if (current.driven < MIN_DRIVEN_TO_COMPARE)
38
+ return undefined;
39
+ return current.percent < best.percent ? { was: best.percent, now: current.percent } : undefined;
40
+ }