@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,102 @@
1
+ import { z } from 'zod';
2
+ /**
3
+ * Assert a PROPERTY of an observed value rather than its exact bytes.
4
+ *
5
+ * Every predicate this engine had compared for equality, and equality cannot express the one thing
6
+ * a generative feature needs: an app whose output IS a model's output is different on every run and
7
+ * correct on every one of them. `equals: "Paris is the capital of France"` fails the next run for
8
+ * the right answer. "a non-empty string matching /Paris/" holds for every right answer and fails
9
+ * for an empty one, a stack trace, or a spinner that never resolved.
10
+ *
11
+ * DETERMINISM is the discipline, and it is not negotiable. Every property here is decided by this
12
+ * function alone — no model, no network, no clock. "Ask a model whether the output looks right" is
13
+ * the obvious next idea and it is the one that must not be built: it makes the verdict
14
+ * unfalsifiable, which is precisely what `no-fault` exists to name instead of paper over.
15
+ *
16
+ * A failing check always says why. An assertion that reports only `false` sends the reader back for
17
+ * another call to find out what it saw, and that round trip is most of what a verdict costs.
18
+ */
19
+ export type PropertyAssertion =
20
+ /** Produced something at all — the honest floor for any generated output. */
21
+ {
22
+ readonly property: 'nonEmpty';
23
+ }
24
+ /** A classification landed inside the allowed set. Exact membership, no coercion. */
25
+ | {
26
+ readonly property: 'oneOf';
27
+ readonly values: readonly unknown[];
28
+ }
29
+ /** A number near enough to an expected one — inclusive on the bound. */
30
+ | {
31
+ readonly property: 'withinTolerance';
32
+ readonly of: number;
33
+ readonly tolerance: number;
34
+ }
35
+ /** The shape of the output, as a regular expression over its string form. */
36
+ | {
37
+ readonly property: 'matchesPattern';
38
+ readonly pattern: string;
39
+ }
40
+ /** The right KIND of thing: `array` and `object` are distinguished, which `typeof` cannot do. */
41
+ | {
42
+ readonly property: 'type';
43
+ readonly is: 'string' | 'number' | 'boolean' | 'array' | 'object';
44
+ };
45
+ export interface PropertyResult {
46
+ readonly ok: boolean;
47
+ /** Why, in the words a reader needs — always present, on pass and on fail. */
48
+ readonly because: string;
49
+ }
50
+ export declare function satisfiesProperty(value: unknown, assertion: PropertyAssertion): PropertyResult;
51
+ /**
52
+ * The wire shape of a property assertion.
53
+ *
54
+ * Lives here beside the evaluator on purpose: a schema in one file and the switch that consumes it
55
+ * in another is how a new property comes to parse and then silently never match.
56
+ */
57
+ export declare const propertyAssertionSchema: z.ZodDiscriminatedUnion<"property", [z.ZodObject<{
58
+ property: z.ZodLiteral<"nonEmpty">;
59
+ }, "strict", z.ZodTypeAny, {
60
+ property: "nonEmpty";
61
+ }, {
62
+ property: "nonEmpty";
63
+ }>, z.ZodObject<{
64
+ property: z.ZodLiteral<"oneOf">;
65
+ values: z.ZodArray<z.ZodUnknown, "many">;
66
+ }, "strict", z.ZodTypeAny, {
67
+ values: unknown[];
68
+ property: "oneOf";
69
+ }, {
70
+ values: unknown[];
71
+ property: "oneOf";
72
+ }>, z.ZodObject<{
73
+ property: z.ZodLiteral<"withinTolerance">;
74
+ of: z.ZodNumber;
75
+ tolerance: z.ZodNumber;
76
+ }, "strict", z.ZodTypeAny, {
77
+ property: "withinTolerance";
78
+ of: number;
79
+ tolerance: number;
80
+ }, {
81
+ property: "withinTolerance";
82
+ of: number;
83
+ tolerance: number;
84
+ }>, z.ZodObject<{
85
+ property: z.ZodLiteral<"matchesPattern">;
86
+ pattern: z.ZodString;
87
+ }, "strict", z.ZodTypeAny, {
88
+ property: "matchesPattern";
89
+ pattern: string;
90
+ }, {
91
+ property: "matchesPattern";
92
+ pattern: string;
93
+ }>, z.ZodObject<{
94
+ property: z.ZodLiteral<"type">;
95
+ is: z.ZodEnum<["string", "number", "boolean", "array", "object"]>;
96
+ }, "strict", z.ZodTypeAny, {
97
+ property: "type";
98
+ is: "string" | "number" | "boolean" | "object" | "array";
99
+ }, {
100
+ property: "type";
101
+ is: "string" | "number" | "boolean" | "object" | "array";
102
+ }>]>;
@@ -0,0 +1,135 @@
1
+ import { z } from 'zod';
2
+ /**
3
+ * A short, readable rendering of any observed value.
4
+ *
5
+ * Never `String(value)` on an unknown: an object stringifies to `[object Object]`, which tells the
6
+ * reader nothing and looks like a real reading. A value JSON cannot encode (a cycle, a BigInt, a
7
+ * function) is named by its TYPE instead, because "cyclic object" is a fact and "[object Object]"
8
+ * is noise wearing the shape of one.
9
+ */
10
+ const show = (value) => {
11
+ if (undefined === value)
12
+ return 'undefined';
13
+ if (null === value)
14
+ return 'null';
15
+ if ('string' === typeof value)
16
+ return JSON.stringify(value).slice(0, 80);
17
+ if ('number' === typeof value || 'boolean' === typeof value || 'bigint' === typeof value) {
18
+ return String(value);
19
+ }
20
+ try {
21
+ const encoded = JSON.stringify(value);
22
+ return undefined === encoded ? `<${typeof value}>` : encoded.slice(0, 80);
23
+ }
24
+ catch {
25
+ return Array.isArray(value) ? '<cyclic array>' : '<cyclic object>';
26
+ }
27
+ };
28
+ function isNonEmpty(value) {
29
+ if (null === value || undefined === value)
30
+ return false;
31
+ if ('string' === typeof value)
32
+ return value.trim().length > 0;
33
+ if (Array.isArray(value))
34
+ return value.length > 0;
35
+ if ('object' === typeof value)
36
+ return Object.keys(value).length > 0;
37
+ // A number or boolean is a value that exists; 0 and false are not "empty".
38
+ return true;
39
+ }
40
+ function typeOf(value) {
41
+ if (null === value)
42
+ return 'null';
43
+ if (Array.isArray(value))
44
+ return 'array';
45
+ return typeof value;
46
+ }
47
+ export function satisfiesProperty(value, assertion) {
48
+ switch (assertion.property) {
49
+ case 'nonEmpty': {
50
+ const ok = isNonEmpty(value);
51
+ return {
52
+ ok,
53
+ because: ok
54
+ ? `produced ${typeOf(value)} ${show(value)}`
55
+ : `expected something, got ${show(value)} — an empty result is the failure mode a generated feature actually has`,
56
+ };
57
+ }
58
+ case 'oneOf': {
59
+ const ok = assertion.values.some((v) => Object.is(v, value));
60
+ return {
61
+ ok,
62
+ because: ok
63
+ ? `${show(value)} is in the allowed set`
64
+ : `${show(value)} is not one of ${show(assertion.values)}`,
65
+ };
66
+ }
67
+ case 'withinTolerance': {
68
+ if ('number' !== typeof value || !Number.isFinite(value)) {
69
+ return {
70
+ ok: false,
71
+ because: `expected a finite number within ${String(assertion.tolerance)} of ${String(assertion.of)}, got ${typeOf(value)} ${show(value)} — not coerced, because "100" and 100 are different answers`,
72
+ };
73
+ }
74
+ const delta = Math.abs(value - assertion.of);
75
+ const ok = delta <= assertion.tolerance;
76
+ return {
77
+ ok,
78
+ because: `${String(value)} is ${String(delta)} from ${String(assertion.of)} (tolerance ${String(assertion.tolerance)})`,
79
+ };
80
+ }
81
+ case 'matchesPattern': {
82
+ let re;
83
+ try {
84
+ re = new RegExp(assertion.pattern);
85
+ }
86
+ catch {
87
+ // Never report a broken check as a real negative: that is the false-green shape in miniature.
88
+ return {
89
+ ok: false,
90
+ because: `"${assertion.pattern}" is not a valid regular expression, so nothing was tested — fix the pattern; this is not a result about the app`,
91
+ };
92
+ }
93
+ const text = 'string' === typeof value ? value : show(value);
94
+ const ok = re.test(text);
95
+ return {
96
+ ok,
97
+ because: ok
98
+ ? `${show(text)} matches /${assertion.pattern}/`
99
+ : `${show(text)} does not match /${assertion.pattern}/`,
100
+ };
101
+ }
102
+ case 'type': {
103
+ const actual = typeOf(value);
104
+ const ok = actual === assertion.is;
105
+ return {
106
+ ok,
107
+ because: ok ? `is ${actual}` : `expected ${assertion.is}, got ${actual} ${show(value)}`,
108
+ };
109
+ }
110
+ }
111
+ }
112
+ /**
113
+ * The wire shape of a property assertion.
114
+ *
115
+ * Lives here beside the evaluator on purpose: a schema in one file and the switch that consumes it
116
+ * in another is how a new property comes to parse and then silently never match.
117
+ */
118
+ export const propertyAssertionSchema = z.discriminatedUnion('property', [
119
+ z.object({ property: z.literal('nonEmpty') }).strict(),
120
+ z.object({ property: z.literal('oneOf'), values: z.array(z.unknown()).min(1) }).strict(),
121
+ z
122
+ .object({
123
+ property: z.literal('withinTolerance'),
124
+ of: z.number().finite(),
125
+ tolerance: z.number().finite().nonnegative(),
126
+ })
127
+ .strict(),
128
+ z.object({ property: z.literal('matchesPattern'), pattern: z.string().min(1) }).strict(),
129
+ z
130
+ .object({
131
+ property: z.literal('type'),
132
+ is: z.enum(['string', 'number', 'boolean', 'array', 'object']),
133
+ })
134
+ .strict(),
135
+ ]);
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Turning "no element matched {text: …}" into something an agent can act on, when the string IS here.
3
+ *
4
+ * `by: text` matches an element's own text nodes. A label rendered across several children —
5
+ * `v-html`, one `<span>` per word, a highlighted substring — is on the page and matches nothing, and
6
+ * the verdict is byte-identical to the one for an element that never rendered.
7
+ *
8
+ * That equivalence is the expensive part. Reported from the field: `act_and_wait` returned
9
+ * `effect.appeared` containing `"Move to Reticle Repro Folder"`, the `until` predicate in the SAME
10
+ * call searched for that string and failed, and the drive ended in a bug report against an app that
11
+ * had rendered correctly. `appeared` concatenates an added subtree while `text` reads direct text
12
+ * only, so the channel an agent is most likely to copy from produces the one locator this query
13
+ * cannot resolve.
14
+ *
15
+ * Naming the container ends it in one step: `ref` is a locator, and a scoped text predicate with
16
+ * `self: true` checks the container's combined subtree text. The recovery is a predicate the agent
17
+ * can paste rather than another guess, and it is serialized as JSON so the schema test can parse it.
18
+ */
19
+ /** The container descriptor the browser attaches to a missed text query. */
20
+ interface SplitTextOwner {
21
+ ref?: string;
22
+ role?: string;
23
+ name?: string;
24
+ }
25
+ /**
26
+ * The "…but it IS here, split across children" clause, or undefined when there is nothing to say.
27
+ *
28
+ * Undefined — not a vaguer sentence — when the browser found no container: an ordinary miss keeps the
29
+ * short message it already had. A clause that fires on every failure stops carrying information.
30
+ */
31
+ export declare function describeSplitTextMiss(owner: SplitTextOwner | undefined, searchedText?: string): string | undefined;
32
+ export {};
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Turning "no element matched {text: …}" into something an agent can act on, when the string IS here.
3
+ *
4
+ * `by: text` matches an element's own text nodes. A label rendered across several children —
5
+ * `v-html`, one `<span>` per word, a highlighted substring — is on the page and matches nothing, and
6
+ * the verdict is byte-identical to the one for an element that never rendered.
7
+ *
8
+ * That equivalence is the expensive part. Reported from the field: `act_and_wait` returned
9
+ * `effect.appeared` containing `"Move to Reticle Repro Folder"`, the `until` predicate in the SAME
10
+ * call searched for that string and failed, and the drive ended in a bug report against an app that
11
+ * had rendered correctly. `appeared` concatenates an added subtree while `text` reads direct text
12
+ * only, so the channel an agent is most likely to copy from produces the one locator this query
13
+ * cannot resolve.
14
+ *
15
+ * Naming the container ends it in one step: `ref` is a locator, and a scoped text predicate with
16
+ * `self: true` checks the container's combined subtree text. The recovery is a predicate the agent
17
+ * can paste rather than another guess, and it is serialized as JSON so the schema test can parse it.
18
+ */
19
+ import { PredicateKind } from '@reticlehq/core';
20
+ /** Enough of the label to recognise it; the message is read in a tool result, not a log. */
21
+ const MAX_TEXT = 60;
22
+ /** What the container is, in the fewest words that still identify it on the page. */
23
+ function nameOf(owner) {
24
+ const name = owner.name !== undefined && owner.name.length > 0 ? owner.name : undefined;
25
+ const role = owner.role !== undefined && owner.role.length > 0 ? owner.role : 'element';
26
+ return name === undefined ? role : `${role} '${truncate(name)}'`;
27
+ }
28
+ function truncate(value) {
29
+ return value.length > MAX_TEXT ? `${value.slice(0, MAX_TEXT)}…` : value;
30
+ }
31
+ /**
32
+ * The "…but it IS here, split across children" clause, or undefined when there is nothing to say.
33
+ *
34
+ * Undefined — not a vaguer sentence — when the browser found no container: an ordinary miss keeps the
35
+ * short message it already had. A clause that fires on every failure stops carrying information.
36
+ */
37
+ export function describeSplitTextMiss(owner, searchedText) {
38
+ if (owner === undefined)
39
+ return undefined;
40
+ const where = nameOf(owner);
41
+ const scope = owner.ref !== undefined && owner.ref.length > 0 ? owner.ref : undefined;
42
+ const recovery = scope === undefined || searchedText === undefined
43
+ ? 'scope to that container and match it as a whole'
44
+ : `retry as ${JSON.stringify({
45
+ kind: PredicateKind.TEXT,
46
+ contains: searchedText,
47
+ scope,
48
+ self: true,
49
+ })}`;
50
+ return `that text IS on the page, split across the children of ${where} — no single element's own text carries it, so no text query can match it; ${recovery}`;
51
+ }
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Turning "no element matched {testid: …}" into something an agent can act on.
3
+ *
4
+ * `reticle_query` on a missing testid already returns the testids that ARE present, so a typo is one
5
+ * step from fixed. The same failure through a PREDICATE — `act_and_wait { until: { kind:'element',
6
+ * query:{ testid } } }` — said only "no element matched" and stopped, naming nothing.
7
+ *
8
+ * The near-miss machinery covered an element in the wrong STATE and a wrong NAME for a role (which
9
+ * even lists the names it saw). Testid — the anchor this codebase calls the gold standard — had
10
+ * none, and it is the one agents use most.
11
+ *
12
+ * It also just became the highest-traffic failure in the product: putting act_and_wait on the
13
+ * verification path means agents assert far more, so a failed element assertion is now the common
14
+ * case rather than the rare one.
15
+ */
16
+ /**
17
+ * The "…but these ARE here" clause, or undefined when there is nothing useful to say.
18
+ *
19
+ * Returns the empty string when the queried testid is itself present: the miss was then about STATE,
20
+ * not presence, and "you asked for X; X is present" reads as a contradiction rather than a hint.
21
+ */
22
+ export declare function describeTestidMiss(wanted: string, present: readonly string[]): string | undefined;
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Turning "no element matched {testid: …}" into something an agent can act on.
3
+ *
4
+ * `reticle_query` on a missing testid already returns the testids that ARE present, so a typo is one
5
+ * step from fixed. The same failure through a PREDICATE — `act_and_wait { until: { kind:'element',
6
+ * query:{ testid } } }` — said only "no element matched" and stopped, naming nothing.
7
+ *
8
+ * The near-miss machinery covered an element in the wrong STATE and a wrong NAME for a role (which
9
+ * even lists the names it saw). Testid — the anchor this codebase calls the gold standard — had
10
+ * none, and it is the one agents use most.
11
+ *
12
+ * It also just became the highest-traffic failure in the product: putting act_and_wait on the
13
+ * verification path means agents assert far more, so a failed element assertion is now the common
14
+ * case rather than the rare one.
15
+ */
16
+ /** Enough to recognise the one you meant; not so many that a large page floods the message. */
17
+ const MAX_LISTED = 12;
18
+ /**
19
+ * The "…but these ARE here" clause, or undefined when there is nothing useful to say.
20
+ *
21
+ * Returns the empty string when the queried testid is itself present: the miss was then about STATE,
22
+ * not presence, and "you asked for X; X is present" reads as a contradiction rather than a hint.
23
+ */
24
+ export function describeTestidMiss(wanted, present) {
25
+ if (0 === present.length)
26
+ return undefined;
27
+ if (present.includes(wanted))
28
+ return '';
29
+ const shown = present.slice(0, MAX_LISTED);
30
+ const rest = present.length - shown.length;
31
+ const tail = rest > 0 ? `, and ${String(rest)} more` : '';
32
+ return `testids present here: ${shown.join(', ')}${tail}`;
33
+ }
@@ -0,0 +1,17 @@
1
+ import { type ReactionDigest, type ReactionSummary, type ReticleEvent } from '@reticlehq/core';
2
+ interface ReactionReport {
3
+ window_ms: number;
4
+ events: ReticleEvent[];
5
+ summary: ReactionSummary;
6
+ }
7
+ /** Turn a slice of the event buffer into the structured "what the app did" report (plan/05). */
8
+ export declare function buildReactionReport(events: ReticleEvent[], windowMs: number): ReactionReport;
9
+ /**
10
+ * Drop the per-event `events` array, keeping the window and counts. The counts already answer "what
11
+ * did the app do?" (DOM added/removed/changed, network, signals…), and a predicate verdict carries
12
+ * the matching evidence — so a tool returning this digest stays cheap while the full timeline is one
13
+ * `reticle_observe { since }` away when the agent needs it. On a large DOM the events array dominates
14
+ * the cost (hundreds of tokens of mutations); the digest is a handful.
15
+ */
16
+ export declare function summarizeReaction(report: ReactionReport): ReactionDigest;
17
+ export {};
@@ -0,0 +1,67 @@
1
+ import { EventType, } from '@reticlehq/core';
2
+ /** Turn a slice of the event buffer into the structured "what the app did" report (plan/05). */
3
+ export function buildReactionReport(events, windowMs) {
4
+ const summary = {
5
+ total: events.length,
6
+ network: 0,
7
+ domAdded: 0,
8
+ domRemoved: 0,
9
+ domChanged: 0,
10
+ routeChanges: 0,
11
+ consoleErrors: 0,
12
+ animations: 0,
13
+ signals: 0,
14
+ };
15
+ for (const e of events) {
16
+ switch (e.type) {
17
+ case EventType.NET_REQUEST:
18
+ summary.network += 1;
19
+ break;
20
+ case EventType.DOM_ADDED:
21
+ summary.domAdded += 1;
22
+ break;
23
+ case EventType.DOM_REMOVED:
24
+ summary.domRemoved += 1;
25
+ break;
26
+ case EventType.DOM_ATTR:
27
+ case EventType.DOM_TEXT:
28
+ summary.domChanged += 1;
29
+ break;
30
+ case EventType.ROUTE_CHANGE:
31
+ summary.routeChanges += 1;
32
+ break;
33
+ case EventType.CONSOLE_ERROR:
34
+ case EventType.ERROR_UNCAUGHT:
35
+ summary.consoleErrors += 1;
36
+ break;
37
+ case EventType.ANIM_START:
38
+ case EventType.ANIM_END:
39
+ summary.animations += 1;
40
+ break;
41
+ case EventType.SIGNAL:
42
+ summary.signals += 1;
43
+ break;
44
+ default:
45
+ break;
46
+ }
47
+ }
48
+ return { window_ms: windowMs, events, summary };
49
+ }
50
+ /**
51
+ * Drop the per-event `events` array, keeping the window and counts. The counts already answer "what
52
+ * did the app do?" (DOM added/removed/changed, network, signals…), and a predicate verdict carries
53
+ * the matching evidence — so a tool returning this digest stays cheap while the full timeline is one
54
+ * `reticle_observe { since }` away when the agent needs it. On a large DOM the events array dominates
55
+ * the cost (hundreds of tokens of mutations); the digest is a handful.
56
+ */
57
+ export function summarizeReaction(report) {
58
+ const { total, ...counters } = report.summary;
59
+ const summary = { total };
60
+ for (const [key, count] of Object.entries(counters)) {
61
+ // A zero counter is the DEFAULT, and spelling out a default on every step of every replay is
62
+ // paying per turn to say nothing. An absent counter reads as zero; read one as `?? 0`.
63
+ if (0 !== count)
64
+ Object.assign(summary, { [key]: count });
65
+ }
66
+ return { window_ms: report.window_ms, summary };
67
+ }
@@ -0,0 +1,28 @@
1
+ /**
2
+ * An SDK that tells us the bare minimum, built on purpose.
3
+ *
4
+ * Every optional field on the wire exists because some version of the page could not supply it: an
5
+ * older SDK, a framework that hides the information, a setting somebody switched off. The code that
6
+ * reads those fields is written to cope, and this file exists because "written to cope" is a claim
7
+ * nobody had checked all at once.
8
+ *
9
+ * The rule it tests is the one this codebase states over and over, in `captureBodies`, in
10
+ * `sourceMapping`, in the protocol version: **absent means unknown, never false.** A reader that
11
+ * treats a missing field as a negative answer turns silence into evidence, and silence is the one
12
+ * thing every old and minimal client has in common.
13
+ *
14
+ * So: for each kind of event, the smallest payload the contract still accepts. Nothing optional,
15
+ * nothing helpful, everything the schema demands and not one field more.
16
+ *
17
+ * This is not a fuzzer. It does not send malformed input -- the schemas already reject that, and a
18
+ * rejection is a good outcome. It sends input that is entirely VALID and entirely unhelpful, which
19
+ * is what a real minimal client looks like and what no fixture in this repository resembles.
20
+ */
21
+ import { type ReticleEvent } from '@reticlehq/core';
22
+ /**
23
+ * One event of each kind, carrying the least the contract accepts.
24
+ *
25
+ * Timestamps ascend so a window has an order; nothing else is offered. The event id is fixed rather
26
+ * than random, because a test that fails only sometimes is one people re-run rather than read.
27
+ */
28
+ export declare function barestEvents(): ReticleEvent[];
@@ -0,0 +1,90 @@
1
+ /**
2
+ * An SDK that tells us the bare minimum, built on purpose.
3
+ *
4
+ * Every optional field on the wire exists because some version of the page could not supply it: an
5
+ * older SDK, a framework that hides the information, a setting somebody switched off. The code that
6
+ * reads those fields is written to cope, and this file exists because "written to cope" is a claim
7
+ * nobody had checked all at once.
8
+ *
9
+ * The rule it tests is the one this codebase states over and over, in `captureBodies`, in
10
+ * `sourceMapping`, in the protocol version: **absent means unknown, never false.** A reader that
11
+ * treats a missing field as a negative answer turns silence into evidence, and silence is the one
12
+ * thing every old and minimal client has in common.
13
+ *
14
+ * So: for each kind of event, the smallest payload the contract still accepts. Nothing optional,
15
+ * nothing helpful, everything the schema demands and not one field more.
16
+ *
17
+ * This is not a fuzzer. It does not send malformed input -- the schemas already reject that, and a
18
+ * rejection is a good outcome. It sends input that is entirely VALID and entirely unhelpful, which
19
+ * is what a real minimal client looks like and what no fixture in this repository resembles.
20
+ */
21
+ import { z } from 'zod';
22
+ import { EVENT_PAYLOAD_SCHEMAS, EventType } from '@reticlehq/core';
23
+ /** A value that satisfies a schema while carrying as little as the contract allows. */
24
+ function barestValue(schema) {
25
+ const def = schema._def;
26
+ switch (def.typeName) {
27
+ // An optional field is the whole point: leave it out.
28
+ case 'ZodOptional':
29
+ case 'ZodNullable':
30
+ return undefined;
31
+ case 'ZodDefault':
32
+ return undefined;
33
+ case 'ZodString': {
34
+ // A minimum length is part of the contract, not decoration: `note` and `anchor` on a human
35
+ // mark both demand one. The barest string that still parses is one character, not none.
36
+ const checks = def.checks ?? [];
37
+ const min = checks.find((c) => 'min' === c.kind)?.value ?? 0;
38
+ return 'x'.repeat(min);
39
+ }
40
+ case 'ZodNumber': {
41
+ const checks = def.checks ?? [];
42
+ return checks.find((c) => 'min' === c.kind)?.value ?? 0;
43
+ }
44
+ case 'ZodBoolean':
45
+ return false;
46
+ case 'ZodArray':
47
+ return [];
48
+ case 'ZodLiteral':
49
+ return def.value;
50
+ case 'ZodEnum':
51
+ return schema.options[0];
52
+ case 'ZodNativeEnum':
53
+ return Object.values(schema._def.values)[0];
54
+ case 'ZodUnion':
55
+ return barestValue((def.options ?? [])[0]);
56
+ case 'ZodRecord':
57
+ return {};
58
+ case 'ZodObject':
59
+ return barestObject(schema);
60
+ default:
61
+ // Unknown, any, and anything else the contract does not constrain.
62
+ return undefined;
63
+ }
64
+ }
65
+ /** The smallest object that still parses: required keys only, each at its barest value. */
66
+ function barestObject(schema) {
67
+ const out = {};
68
+ for (const [key, field] of Object.entries(schema.shape)) {
69
+ const value = barestValue(field);
70
+ if (value !== undefined)
71
+ out[key] = value;
72
+ }
73
+ return out;
74
+ }
75
+ /**
76
+ * One event of each kind, carrying the least the contract accepts.
77
+ *
78
+ * Timestamps ascend so a window has an order; nothing else is offered. The event id is fixed rather
79
+ * than random, because a test that fails only sometimes is one people re-run rather than read.
80
+ */
81
+ export function barestEvents() {
82
+ return Object.values(EventType).map((type, index) => {
83
+ const payload = EVENT_PAYLOAD_SCHEMAS[type];
84
+ return {
85
+ type,
86
+ t: index + 1,
87
+ data: barestValue(payload) ?? {},
88
+ };
89
+ });
90
+ }
@@ -0,0 +1,63 @@
1
+ import type { ReticleEvent } from '@reticlehq/core';
2
+ /**
3
+ * Ambient-region learning. On a real-time app (chat, tickers, presence) whole DOM regions churn with
4
+ * NO action driving them — an event with no `actionId`. Left unlearned, they make `settled` never fire
5
+ * and flood every summary. This learns, per element ref, how often it churns ambiently; a ref past the
6
+ * threshold is treated as ambient and excluded from the settle oracle, summaries, and envelopes. The
7
+ * map is a learned, persisted per-app fact (like the contract) — confirmable, not silent.
8
+ *
9
+ * Global, not per-flow: the journal already sees the churn across every session, so the map sharpens
10
+ * over time. Only UNATTRIBUTED churn counts — an event caused by an action is signal, never ambient.
11
+ *
12
+ * Deciding which changes on a page are background noise and which are the consequence of an action
13
+ * is a judgement about what happened, so it lives with the rules that decide a verdict. Where the
14
+ * learned map is kept between runs is a different question, and that part stayed in the journal.
15
+ */
16
+ /** Per-region ambient churn counts. */
17
+ export type AmbientCounts = Record<string, number>;
18
+ /**
19
+ * The identity ambient learning counts against. Prefer the emitted `region` (the stable CONTAINER of a
20
+ * mutation) over the element ref: a churning feed appends a NEW element every tick (fresh ref) and a
21
+ * removed element has no ref at all, so per-ref counts never accumulate and the region is never learned.
22
+ * The container persists, so it is the only key that converges. Falls back to the ref for events that
23
+ * mutate a single stable element (a ticker's text).
24
+ */
25
+ export declare function ambientKeyOf(event: {
26
+ ref?: string | undefined;
27
+ data?: Record<string, unknown>;
28
+ }): string | undefined;
29
+ /** A ref must churn ambiently at least this many times before it is treated as ambient. */
30
+ export declare const DEFAULT_AMBIENT_THRESHOLD = 20;
31
+ /**
32
+ * Is this ambient key meaningful in a DIFFERENT session?
33
+ *
34
+ * `regionKeyOf` prefers the nearest `data-testid` — a name the app chose, stable across every run —
35
+ * and falls back to the element's ref when the region has none. Within a session that fallback is
36
+ * correct and useful. Across one it is not merely useless, it is WRONG: the next session hands `e404`
37
+ * to some other element, and the learned suppression lands on whatever that turns out to be.
38
+ *
39
+ * WHAT IT ACTUALLY AFFECTS. This map is read in exactly one place — the `settled` predicate drops
40
+ * events on learned-ambient regions before deciding the page went quiet. So a poisoned map makes
41
+ * `{kind: "settled"}` ignore regions that were never the churning ones, which is a false-green risk
42
+ * in the settle oracle. It does NOT filter the windows that summaries or contradictions are computed
43
+ * from; those read the buffer raw.
44
+ *
45
+ * That scope is narrower than this rule was first written as. The measurement offered for the wider
46
+ * claim — DOM events reappearing once the file was cleared — was taken across a daemon restart and a
47
+ * new session, so it did not isolate the file, and it is withdrawn. What stands without it: all 43
48
+ * keys in the persisted map were ref-shaped, and a ref cannot mean anything in a session that did
49
+ * not mint it.
50
+ */
51
+ export declare function isStableAmbientKey(key: string): boolean;
52
+ /** The counts worth carrying between sessions — the stable keys, and nothing else. */
53
+ export declare function onlyStableAmbient(counts: AmbientCounts): AmbientCounts;
54
+ /** Fold a batch of events into the running ambient counts. Only unattributed, ref-bearing events count. */
55
+ export declare function accumulateAmbient(counts: AmbientCounts, events: readonly ReticleEvent[]): AmbientCounts;
56
+ /** Whether a ref has churned ambiently often enough to be excluded from oracles/summaries. */
57
+ export declare function isAmbient(counts: AmbientCounts, ref: string | undefined, threshold?: number): boolean;
58
+ /**
59
+ * Drop events on learned-ambient regions — the exclusion the settle oracle and summaries apply. An
60
+ * action-attributed event is ALWAYS kept, even on an ambient ref: if an action caused a change there,
61
+ * it is signal, not background churn.
62
+ */
63
+ export declare function excludeAmbient(counts: AmbientCounts, events: readonly ReticleEvent[], threshold?: number): ReticleEvent[];