@reticlehq/core 3.2.0 → 3.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/README.md +1 -1
  2. package/dist/artifacts/flow-composition.d.ts +3 -2
  3. package/dist/artifacts/flow-constants.d.ts +68 -2
  4. package/dist/artifacts/flow-constants.js +84 -2
  5. package/dist/artifacts/flow-expect-flat.d.ts +260 -0
  6. package/dist/artifacts/flow-expect-flat.js +284 -0
  7. package/dist/artifacts/flow-mutation-target.d.ts +0 -1
  8. package/dist/artifacts/flow-mutation-target.js +30 -2
  9. package/dist/artifacts/flow-step-tool.d.ts +2 -0
  10. package/dist/artifacts/flow-types.d.ts +1285 -1343
  11. package/dist/artifacts/flow-types.js +111 -140
  12. package/dist/artifacts/impact.d.ts +48 -20
  13. package/dist/artifacts/impact.js +11 -0
  14. package/dist/artifacts/journal.d.ts +34 -6
  15. package/dist/artifacts/journal.js +13 -0
  16. package/dist/hooks/hook-events.d.ts +18 -18
  17. package/dist/hud-entry.d.ts +9 -0
  18. package/dist/hud-entry.js +9 -0
  19. package/dist/identity/source-constants.d.ts +11 -0
  20. package/dist/identity/source-constants.js +11 -0
  21. package/dist/index.d.ts +9 -0
  22. package/dist/index.js +25 -1
  23. package/dist/onboarding.d.ts +2 -2
  24. package/dist/realm/registry.d.ts +0 -8
  25. package/dist/realm/registry.js +1 -11
  26. package/dist/registry/daemon-registry.d.ts +14 -4
  27. package/dist/registry/daemon-registry.js +20 -4
  28. package/dist/schema/event-message.json +3 -1
  29. package/dist/schema/event-payloads.json +72 -0
  30. package/dist/schema/event-type.json +3 -1
  31. package/dist/schema/reticle-event.json +3 -1
  32. package/dist/schema/reticle-message.json +3 -1
  33. package/dist/source-constants.cjs +1 -0
  34. package/dist/source-constants.d.cts +1 -0
  35. package/dist/telemetry-feedback.d.ts +6 -6
  36. package/dist/telemetry-refusal.d.ts +5 -4
  37. package/dist/telemetry-session.d.ts +25 -2
  38. package/dist/telemetry-session.js +13 -0
  39. package/dist/telemetry.d.ts +130 -102
  40. package/dist/verdict/compare-source.d.ts +80 -0
  41. package/dist/verdict/compare-source.js +93 -0
  42. package/dist/verdict/consequence.d.ts +12 -0
  43. package/dist/verdict/consequence.js +15 -0
  44. package/dist/verdict/instrumentation-gap.js +1 -1
  45. package/dist/verdict/intent.d.ts +24 -0
  46. package/dist/verdict/intent.js +66 -10
  47. package/dist/verdict/predicate-tree.d.ts +82 -0
  48. package/dist/verdict/predicate-tree.js +186 -0
  49. package/dist/verdict/predicate.d.ts +138 -0
  50. package/dist/verdict/predicate.js +430 -0
  51. package/dist/verdict/property-assertion.d.ts +191 -0
  52. package/dist/verdict/property-assertion.js +42 -0
  53. package/dist/verdict/security.js +16 -4
  54. package/dist/verdict/verdict-attribution.d.ts +52 -0
  55. package/dist/verdict/verdict-attribution.js +87 -0
  56. package/dist/verdict/verification-run.d.ts +330 -83
  57. package/dist/verdict/verification-run.js +44 -1
  58. package/dist/verdict/verified-constants.d.ts +9 -0
  59. package/dist/verdict/verified-constants.js +9 -0
  60. package/dist/wire/channel.d.ts +10 -0
  61. package/dist/wire/channel.js +25 -0
  62. package/dist/wire/constants/constants.d.ts +65 -102
  63. package/dist/wire/constants/constants.js +79 -101
  64. package/dist/wire/constants/discovery.d.ts +25 -0
  65. package/dist/wire/constants/discovery.js +25 -0
  66. package/dist/wire/constants/event-types.d.ts +122 -0
  67. package/dist/wire/constants/event-types.js +121 -0
  68. package/dist/wire/constants/hud-controls.d.ts +19 -0
  69. package/dist/wire/constants/hud-controls.js +95 -0
  70. package/dist/wire/constants/hud-use.d.ts +27 -0
  71. package/dist/wire/constants/hud-use.js +24 -0
  72. package/dist/wire/constants/session-constants.d.ts +10 -0
  73. package/dist/wire/constants/session-constants.js +10 -0
  74. package/dist/wire/event-payloads.d.ts +72 -13
  75. package/dist/wire/event-payloads.js +26 -4
  76. package/dist/wire/messages.d.ts +97 -56
  77. package/dist/wire/messages.js +17 -0
  78. package/dist/wire/net.d.ts +35 -0
  79. package/dist/wire/net.js +41 -0
  80. package/dist/wire/redaction.js +17 -0
  81. package/dist/wire/state-select.d.ts +2 -1
  82. package/dist/wire/state-select.js +56 -3
  83. package/dist/wire/toon.d.ts +1 -1
  84. package/dist/wire/toon.js +30 -8
  85. package/dist/wire/types.d.ts +119 -94
  86. package/dist/wire/types.js +23 -1
  87. package/dist/words/no-session-reason.d.ts +7 -0
  88. package/dist/words/no-session-reason.js +7 -0
  89. package/dist/words/notices.d.ts +7 -0
  90. package/dist/words/notices.js +9 -2
  91. package/package.json +7 -2
@@ -0,0 +1,80 @@
1
+ /**
2
+ * The `compare` predicate's contract: where each side's value is read from, and how the two are
3
+ * compared.
4
+ *
5
+ * Every other predicate checks one observation against a value the CALLER supplies. That leaves one
6
+ * claim unsayable: "the page shows what the server answered". The refund case is the one that
7
+ * shipped — the server read `1187.01` as paise and answered `{"refunded":11.87}`, the page displayed
8
+ * the number the user had typed, and every channel was green. `bodyContains` catches it only when
9
+ * the agent already knows the right number, and an agent verifying a fix usually does not.
10
+ *
11
+ * `compare` reads two observed values and relates them, so the claim needs no expected value at all.
12
+ * The sources are the four channels that carry a VALUE (a request or response field, a signal
13
+ * payload field, a store path, an element's text). Route, console and animation carry events, not
14
+ * values, so they are not sources.
15
+ */
16
+ import { z } from 'zod';
17
+ import { PredicateKind } from './consequence.js';
18
+ /** Which half of an exchange a `net` source reads. */
19
+ export declare const NetBodySide: {
20
+ readonly RESPONSE: "response";
21
+ readonly REQUEST: "request";
22
+ };
23
+ export type NetBodySide = (typeof NetBodySide)[keyof typeof NetBodySide];
24
+ /**
25
+ * How the two readings are compared.
26
+ *
27
+ * `value` is strict equality of two scalars: `"11.87"` and `11.87` differ, because text and a JSON
28
+ * number are different things and saying they agree would be a guess. `number` reads ONE number out
29
+ * of each side (a JSON number as is, a string by its only numeric token, so `"₹1,187.01"` reads as
30
+ * 1187.01) and compares those, within `tolerance`. A string with no number, or with two, is
31
+ * unreadable rather than unequal: picking one would be a guess about which the caller meant.
32
+ */
33
+ export declare const CompareAs: {
34
+ readonly VALUE: "value";
35
+ readonly NUMBER: "number";
36
+ };
37
+ export type CompareAs = (typeof CompareAs)[keyof typeof CompareAs];
38
+ export type CompareSource = {
39
+ from: typeof PredicateKind.NET;
40
+ urlContains: string;
41
+ method?: string;
42
+ /** Which body the path reads. Defaults to the response, the half a UI cannot fake. */
43
+ body?: NetBodySide;
44
+ path: string;
45
+ } | {
46
+ from: typeof PredicateKind.SIGNAL;
47
+ name: string;
48
+ path: string;
49
+ } | {
50
+ from: typeof PredicateKind.STATE;
51
+ store?: string;
52
+ path: string;
53
+ }
54
+ /** The whole text of the element `scope` names (a CSS selector), itself included. */
55
+ | {
56
+ from: typeof PredicateKind.TEXT;
57
+ scope: string;
58
+ };
59
+ /**
60
+ * Cast rather than annotated for the reason `PredicateSchema` is: zod infers optional fields as
61
+ * `| undefined`, which `exactOptionalPropertyTypes` will not assign to the hand-written type.
62
+ */
63
+ export declare const CompareSourceSchema: z.ZodType<CompareSource>;
64
+ /**
65
+ * Does this source read a value the APP produced — a request, a payload, a store — rather than
66
+ * rendered text?
67
+ *
68
+ * Decides how a `compare` grades. With at least one such side, a pass means the page agrees with the
69
+ * app's own record of what happened, which a healed-but-wrong locator cannot fake. Text against text
70
+ * is a presence-grade claim, because both sides are readings of the same DOM.
71
+ */
72
+ export declare function isConsequenceSource(source: CompareSource): boolean;
73
+ /**
74
+ * Do two sources read the same value, for refusing a comparison with itself?
75
+ *
76
+ * Spelled-out defaults are filled in first. Otherwise `{ body: "response" }` against a source that
77
+ * left `body` out would read as two different sources, and a comparison that cannot fail would get
78
+ * past the refusal just by being written two ways.
79
+ */
80
+ export declare function sameCompareSource(a: CompareSource, b: CompareSource): boolean;
@@ -0,0 +1,93 @@
1
+ /**
2
+ * The `compare` predicate's contract: where each side's value is read from, and how the two are
3
+ * compared.
4
+ *
5
+ * Every other predicate checks one observation against a value the CALLER supplies. That leaves one
6
+ * claim unsayable: "the page shows what the server answered". The refund case is the one that
7
+ * shipped — the server read `1187.01` as paise and answered `{"refunded":11.87}`, the page displayed
8
+ * the number the user had typed, and every channel was green. `bodyContains` catches it only when
9
+ * the agent already knows the right number, and an agent verifying a fix usually does not.
10
+ *
11
+ * `compare` reads two observed values and relates them, so the claim needs no expected value at all.
12
+ * The sources are the four channels that carry a VALUE (a request or response field, a signal
13
+ * payload field, a store path, an element's text). Route, console and animation carry events, not
14
+ * values, so they are not sources.
15
+ */
16
+ import { z } from 'zod';
17
+ import { PredicateKind } from './consequence.js';
18
+ /** Which half of an exchange a `net` source reads. */
19
+ export const NetBodySide = {
20
+ RESPONSE: 'response',
21
+ REQUEST: 'request',
22
+ };
23
+ /**
24
+ * How the two readings are compared.
25
+ *
26
+ * `value` is strict equality of two scalars: `"11.87"` and `11.87` differ, because text and a JSON
27
+ * number are different things and saying they agree would be a guess. `number` reads ONE number out
28
+ * of each side (a JSON number as is, a string by its only numeric token, so `"₹1,187.01"` reads as
29
+ * 1187.01) and compares those, within `tolerance`. A string with no number, or with two, is
30
+ * unreadable rather than unequal: picking one would be a guess about which the caller meant.
31
+ */
32
+ export const CompareAs = {
33
+ VALUE: 'value',
34
+ NUMBER: 'number',
35
+ };
36
+ /** A path into a JSON value: `data.total`, `items.0.id` — the grammar `state.path` speaks. */
37
+ const pathField = z.string().min(1);
38
+ /**
39
+ * Cast rather than annotated for the reason `PredicateSchema` is: zod infers optional fields as
40
+ * `| undefined`, which `exactOptionalPropertyTypes` will not assign to the hand-written type.
41
+ */
42
+ export const CompareSourceSchema = z.discriminatedUnion('from', [
43
+ z
44
+ .object({
45
+ from: z.literal(PredicateKind.NET),
46
+ urlContains: z.string().min(1),
47
+ method: z.string().optional(),
48
+ body: z.enum([NetBodySide.RESPONSE, NetBodySide.REQUEST]).optional(),
49
+ path: pathField,
50
+ })
51
+ .strict(),
52
+ z
53
+ .object({ from: z.literal(PredicateKind.SIGNAL), name: z.string().min(1), path: pathField })
54
+ .strict(),
55
+ z
56
+ .object({ from: z.literal(PredicateKind.STATE), store: z.string().optional(), path: pathField })
57
+ .strict(),
58
+ z.object({ from: z.literal(PredicateKind.TEXT), scope: z.string().min(1) }).strict(),
59
+ ]);
60
+ /**
61
+ * Does this source read a value the APP produced — a request, a payload, a store — rather than
62
+ * rendered text?
63
+ *
64
+ * Decides how a `compare` grades. With at least one such side, a pass means the page agrees with the
65
+ * app's own record of what happened, which a healed-but-wrong locator cannot fake. Text against text
66
+ * is a presence-grade claim, because both sides are readings of the same DOM.
67
+ */
68
+ export function isConsequenceSource(source) {
69
+ return PredicateKind.TEXT !== source.from;
70
+ }
71
+ /**
72
+ * Do two sources read the same value, for refusing a comparison with itself?
73
+ *
74
+ * Spelled-out defaults are filled in first. Otherwise `{ body: "response" }` against a source that
75
+ * left `body` out would read as two different sources, and a comparison that cannot fail would get
76
+ * past the refusal just by being written two ways.
77
+ */
78
+ export function sameCompareSource(a, b) {
79
+ const left = withDefaults(a);
80
+ const right = withDefaults(b);
81
+ const keys = new Set([...Object.keys(left), ...Object.keys(right)]);
82
+ return [...keys].every((key) => left[key] === right[key]);
83
+ }
84
+ function withDefaults(source) {
85
+ // The network reader matches methods case-blind, so `GET` and `get` pick the same call.
86
+ if (PredicateKind.NET === source.from)
87
+ return {
88
+ ...source,
89
+ body: source.body ?? NetBodySide.RESPONSE,
90
+ method: source.method?.toUpperCase(),
91
+ };
92
+ return { ...source };
93
+ }
@@ -43,12 +43,24 @@ export declare const PredicateKind: {
43
43
  readonly CONSOLE: "console";
44
44
  readonly ANIMATION: "animation";
45
45
  readonly SETTLED: "settled";
46
+ /** Two observed values, related to each other — see compare-source.ts. */
47
+ readonly COMPARE: "compare";
46
48
  readonly ALL_OF: "allOf";
47
49
  readonly ANY_OF: "anyOf";
48
50
  readonly NOT: "not";
49
51
  };
50
52
  export type PredicateKind = (typeof PredicateKind)[keyof typeof PredicateKind];
51
53
  export declare const CONSEQUENCE_KINDS: ReadonlySet<string>;
54
+ /**
55
+ * The kinds that grade a flow as PRESENCE-ONLY rather than assertion-free.
56
+ *
57
+ * `element` and `text` are the weak checks `PresenceKind` names. `route` joins them here and only
58
+ * here: a route change is observed on a channel rather than queried from the DOM, so it is not a
59
+ * presence check in the sense `isPresenceKind` means, but a route-only expect must still grade as
60
+ * presence rather than falling through to `assertion-free` — which would be a permanent green
61
+ * wearing an assertion.
62
+ */
63
+ export declare const PRESENCE_GRADED: ReadonlySet<string>;
52
64
  /** True when `kind` (a predicate/expect kind) asserts a consequence (signal/net/state). */
53
65
  export declare function isConsequenceKind(kind: string): boolean;
54
66
  /** True when `kind` is a weak presence check (element/text). */
@@ -41,12 +41,27 @@ export const PredicateKind = {
41
41
  CONSOLE: 'console',
42
42
  ANIMATION: 'animation',
43
43
  SETTLED: 'settled',
44
+ /** Two observed values, related to each other — see compare-source.ts. */
45
+ COMPARE: 'compare',
44
46
  ALL_OF: 'allOf',
45
47
  ANY_OF: 'anyOf',
46
48
  NOT: 'not',
47
49
  };
48
50
  export const CONSEQUENCE_KINDS = new Set(Object.values(ConsequenceKind));
49
51
  const PRESENCE_KINDS = new Set(Object.values(PresenceKind));
52
+ /**
53
+ * The kinds that grade a flow as PRESENCE-ONLY rather than assertion-free.
54
+ *
55
+ * `element` and `text` are the weak checks `PresenceKind` names. `route` joins them here and only
56
+ * here: a route change is observed on a channel rather than queried from the DOM, so it is not a
57
+ * presence check in the sense `isPresenceKind` means, but a route-only expect must still grade as
58
+ * presence rather than falling through to `assertion-free` — which would be a permanent green
59
+ * wearing an assertion.
60
+ */
61
+ export const PRESENCE_GRADED = new Set([
62
+ ...PRESENCE_KINDS,
63
+ PredicateKind.ROUTE,
64
+ ]);
50
65
  /** True when `kind` (a predicate/expect kind) asserts a consequence (signal/net/state). */
51
66
  export function isConsequenceKind(kind) {
52
67
  return CONSEQUENCE_KINDS.has(kind);
@@ -119,7 +119,7 @@ export const InstrumentationGapKind = {
119
119
  */
120
120
  const GAP_FIX = {
121
121
  [InstrumentationGapKind.NO_SOURCE_MAPPING]: 'add the Reticle build plugin (@reticlehq/vite-plugin, @reticlehq/next, or the babel plugin) so elements carry data-reticle-source',
122
- [InstrumentationGapKind.NO_STORE_REGISTERED]: 'register the store with reticle.registerStore(name, getState) so state can be read directly instead of inferred from the DOM',
122
+ [InstrumentationGapKind.NO_STORE_REGISTERED]: 'register the store itself with reticle.registerStore(name, store), or registerStore(name, getState, subscribe), so its changes are observed — a bare getter can be read but never reports a change',
123
123
  [InstrumentationGapKind.NO_SIGNAL_ON_MUTATION]: 'fire reticle.signal(name, data) where this state is committed — commitAndSignal binds the two so they cannot drift',
124
124
  [InstrumentationGapKind.UNDECLARED_CONTROL]: 'add this control to reticle.describe() so the capability contract matches what the app actually exposes',
125
125
  [InstrumentationGapKind.MISSING_TESTID]: 'add data-testid="..." on this control so the flow can name it after a refactor',
@@ -307,6 +307,16 @@ export declare function dischargeIntent(intent: Intent, proof: {
307
307
  grade: string;
308
308
  at: number;
309
309
  }): Intent;
310
+ /**
311
+ * What declaring an intent that may already exist should leave stored.
312
+ *
313
+ * Declaring is what a re-run does — a flow re-saved, a feature's intents declared again in a later
314
+ * session — and it replaced the record outright, so a proved rule lost its check and its proof every
315
+ * time somebody said it again. Same words: nothing about the promise changed, so nothing is
316
+ * discarded. Different words: the check usually survives a rewording, the proof cannot, because it
317
+ * was evidence for words that are gone. The amendment itself is recorded by `upsertIntent`.
318
+ */
319
+ export declare function redeclareIntent(existing: Intent | undefined, fresh: Intent): Intent;
310
320
  /**
311
321
  * Add or amend an intent, keeping the previous statement in its history.
312
322
  *
@@ -315,6 +325,20 @@ export declare function dischargeIntent(intent: Intent, proof: {
315
325
  * amendment somebody needs to see.
316
326
  */
317
327
  export declare function upsertIntent(file: IntentFile, intent: Intent): IntentFile;
328
+ /**
329
+ * The next version of an intent, carrying the previous wording into its history when it changed.
330
+ *
331
+ * One rule for every store that keeps intents, so a flat ledger and a sharded one cannot keep two
332
+ * different histories of the same promise.
333
+ */
334
+ export declare function amendIntent(previous: Intent | undefined, next: Intent): Intent;
335
+ /**
336
+ * Is this a description of what was DONE rather than a statement of what must be TRUE?
337
+ *
338
+ * An intent is the business rule a teammate reads in six months. A step label is a log line, and a
339
+ * ledger full of them buries the rules behind "click button \"Cancel\"" and inflates what is owed.
340
+ */
341
+ export declare function isActionLabel(statement: string): boolean;
318
342
  /** Everything not yet proved — what an agent asking "am I done?" still owes. */
319
343
  export declare function openIntents(file: IntentFile): Intent[];
320
344
  /** Parse an intent file, failing soft to empty. Never throws — a cache must not take a daemon down. */
@@ -75,7 +75,13 @@ export function declareIntent(input) {
75
75
  }
76
76
  /** Attach the predicate that would prove it. Pure — returns a new intent. */
77
77
  export function bindIntent(intent, binding) {
78
- return { ...intent, state: IntentState.BOUND, binding };
78
+ // The same check again — what re-saving a flow does — leaves a proved intent proved.
79
+ // ponytail: JSON equality, so key order matters; both bindings come from the same writers.
80
+ if (JSON.stringify(intent.binding) === JSON.stringify(binding))
81
+ return intent;
82
+ // A different check has proved nothing yet, whatever the old one did.
83
+ const { provenBy: _proof, ...unproved } = intent;
84
+ return { ...unproved, state: IntentState.BOUND, binding };
79
85
  }
80
86
  /**
81
87
  * Record that a verdict proved it.
@@ -90,6 +96,30 @@ export function dischargeIntent(intent, proof) {
90
96
  return intent;
91
97
  return { ...intent, state: IntentState.PROVED, provenBy: proof };
92
98
  }
99
+ /**
100
+ * What declaring an intent that may already exist should leave stored.
101
+ *
102
+ * Declaring is what a re-run does — a flow re-saved, a feature's intents declared again in a later
103
+ * session — and it replaced the record outright, so a proved rule lost its check and its proof every
104
+ * time somebody said it again. Same words: nothing about the promise changed, so nothing is
105
+ * discarded. Different words: the check usually survives a rewording, the proof cannot, because it
106
+ * was evidence for words that are gone. The amendment itself is recorded by `upsertIntent`.
107
+ */
108
+ export function redeclareIntent(existing, fresh) {
109
+ if (existing === undefined)
110
+ return fresh;
111
+ const surface = existing.surface ?? fresh.surface;
112
+ const withSurface = surface === undefined ? {} : { surface };
113
+ if (existing.statement === fresh.statement)
114
+ return { ...existing, ...withSurface };
115
+ const { provenBy: _proof, ...unproved } = existing;
116
+ return {
117
+ ...unproved,
118
+ statement: fresh.statement,
119
+ state: existing.binding === undefined ? IntentState.DECLARED : IntentState.BOUND,
120
+ ...withSurface,
121
+ };
122
+ }
93
123
  /**
94
124
  * Add or amend an intent, keeping the previous statement in its history.
95
125
  *
@@ -98,19 +128,45 @@ export function dischargeIntent(intent, proof) {
98
128
  * amendment somebody needs to see.
99
129
  */
100
130
  export function upsertIntent(file, intent) {
101
- const previous = file.intents[intent.id];
102
- const changed = previous !== undefined && previous.statement !== intent.statement;
103
- const amended = changed
104
- ? [...(previous.amended ?? []), { statement: previous.statement, at: previous.declaredAt }]
105
- : previous?.amended;
106
131
  return {
107
132
  version: INTENT_FILE_VERSION,
108
- intents: {
109
- ...file.intents,
110
- [intent.id]: { ...intent, ...(amended === undefined ? {} : { amended }) },
111
- },
133
+ intents: { ...file.intents, [intent.id]: amendIntent(file.intents[intent.id], intent) },
112
134
  };
113
135
  }
136
+ /**
137
+ * The next version of an intent, carrying the previous wording into its history when it changed.
138
+ *
139
+ * One rule for every store that keeps intents, so a flat ledger and a sharded one cannot keep two
140
+ * different histories of the same promise.
141
+ */
142
+ export function amendIntent(previous, next) {
143
+ const changed = previous !== undefined && previous.statement !== next.statement;
144
+ const amended = changed
145
+ ? [...(previous.amended ?? []), { statement: previous.statement, at: previous.declaredAt }]
146
+ : previous?.amended;
147
+ return { ...next, ...(amended === undefined ? {} : { amended }) };
148
+ }
149
+ /**
150
+ * A step verb directly followed by an element role: `click button "Save"`, `check switch "X"`.
151
+ *
152
+ * The shape an ACTION DESCRIPTION takes, which is what tools generate from a snapshot line. Narrow on
153
+ * purpose: "click the Save button and the order appears" names a consequence and is kept, as is any
154
+ * gerund ("clicking Send makes the badge read…"). Refusing a real intent costs more than admitting a
155
+ * label, so only the unmistakable shape is refused.
156
+ */
157
+ const STEP_LABEL = /^(click|dblclick|fill|type|clear|select|check|uncheck|press|hover|focus|tap|drag|scroll|submit|upload)\s+(button|link|textbox|searchbox|switch|checkbox|menuitem|menuitemcheckbox|tab|combobox|option|radio|slider|spinbutton|heading|img|row|cell|listitem|treeitem)\b/i;
158
+ /** What an automated drive used to file as its "intent": a count of what it did. */
159
+ const DRIVE_LOG = /^Autonomous coverage drive\b/i;
160
+ /**
161
+ * Is this a description of what was DONE rather than a statement of what must be TRUE?
162
+ *
163
+ * An intent is the business rule a teammate reads in six months. A step label is a log line, and a
164
+ * ledger full of them buries the rules behind "click button \"Cancel\"" and inflates what is owed.
165
+ */
166
+ export function isActionLabel(statement) {
167
+ const text = statement.trim();
168
+ return STEP_LABEL.test(text) || DRIVE_LOG.test(text);
169
+ }
114
170
  /** Everything not yet proved — what an agent asking "am I done?" still owes. */
115
171
  export function openIntents(file) {
116
172
  return Object.values(file.intents).filter((intent) => intent.state !== IntentState.PROVED);
@@ -0,0 +1,82 @@
1
+ /**
2
+ * Reading a predicate's TOP-LEVEL clauses.
3
+ *
4
+ * Structural, not evaluative: these answer "what does this predicate say" from the shape alone, the
5
+ * same basis `predicateShapeFor` sits here on. Nothing here decides anything about an app.
6
+ *
7
+ * It lived beside the replay code until the journal's flow-naming needed it too, and a
8
+ * `journal -> flows` reach is a file filed in the wrong place rather than a dependency anybody
9
+ * wanted. The thing both callers want is a reader for a core type, so it lives with the type.
10
+ *
11
+ * v1 stored one slot per kind, so "does this step assert state?" was a property read and "drop the
12
+ * element clause" was a `delete`. A `Predicate` nests, so every one of those questions is a walk.
13
+ *
14
+ * The walks here are deliberately SHALLOW, and that is the whole design. A lifted v1 file produces
15
+ * either a single leaf or one flat `allOf`, so a top-level walk reproduces v1 behaviour exactly. A
16
+ * hand-written v2 predicate can nest arbitrarily, and going deeper would silently change what an
17
+ * existing flow asserts:
18
+ *
19
+ * - dropping a leaf from an `allOf` removes a conjunct, which is what v1's `delete` did;
20
+ * - dropping a branch from an `anyOf` removes an ALTERNATIVE, which makes the predicate STRICTER
21
+ * and can turn a passing flow red;
22
+ * - dropping anything under a `not` inverts the meaning of the thing you dropped.
23
+ *
24
+ * So the composite cases are handled where they mean what v1 meant, and left alone everywhere else.
25
+ */
26
+ import { PredicateKind } from './consequence.js';
27
+ import type { Predicate } from './predicate.js';
28
+ /**
29
+ * The plain clause each side of a `compare` reads, so a walker that asks "which endpoints, signals,
30
+ * stores or elements does this predicate depend on?" answers for a comparison without learning its
31
+ * shape. They are READERS of the same channel, never claims: a compare's `net` side is not an
32
+ * assertion that some call succeeded, only that the comparison reads one.
33
+ */
34
+ export declare function compareSourceClauses(predicate: Extract<Predicate, {
35
+ kind: typeof PredicateKind.COMPARE;
36
+ }>): readonly Predicate[];
37
+ /** Every clause at the top level: the predicate itself, or the members of a top-level `allOf`. */
38
+ export declare function conjuncts(predicate: Predicate | undefined): readonly Predicate[];
39
+ /** The first top-level clause of this kind, or undefined. */
40
+ export declare function clauseOfKind<K extends Predicate['kind']>(predicate: Predicate | undefined, kind: K): Extract<Predicate, {
41
+ kind: K;
42
+ }> | undefined;
43
+ /** Does this expectation assert store state at the top level? The drift kind branches on it. */
44
+ export declare function assertsState(predicate: Predicate | undefined): boolean;
45
+ /**
46
+ * The testid an element clause says must be PRESENT, when the expectation has one at the top level.
47
+ *
48
+ * An `absent: true` clause names a testid that must be gone, and asking the replay runner to
49
+ * require it made a correct dismissal fail. That clause is left to the predicate wait instead.
50
+ */
51
+ export declare function expectedElementTestid(predicate: Predicate | undefined): string | undefined;
52
+ /**
53
+ * Rebuild the expectation without the top-level clauses a caller wants gone, collapsing as it goes.
54
+ *
55
+ * One clause left is that clause, not an `allOf` of one: a single-member composite grades weaker
56
+ * than its own member and reads worse in a report, and `combine()` has had to be taught about
57
+ * zero-branch composites once already.
58
+ */
59
+ export declare function withoutClauses(predicate: Predicate | undefined, drop: (clause: Predicate) => boolean): Predicate | undefined;
60
+ /**
61
+ * Name what was asserted, for the drift row's `anchor` column.
62
+ *
63
+ * Reports the STRONGEST clause rather than the first, because that is the one a reader is asking
64
+ * about: an `allOf[settled, net]` is about the request, and answering "settled" names the gate
65
+ * instead of the claim.
66
+ */
67
+ export declare function expectLabel(predicate: Predicate | undefined): string;
68
+ /**
69
+ * An element ref: `e` and a sequence number, minted per session by the SDK's ref table. It is an
70
+ * address inside ONE session's numbering, not an identity.
71
+ */
72
+ export declare const SESSION_REF: RegExp;
73
+ /** Why a flow refused a predicate holding a ref, naming the field. */
74
+ export declare function sessionRefRefusal(field: string): string;
75
+ /**
76
+ * The first field anywhere in the tree that holds a session ref, as `kind.field "value"`.
77
+ *
78
+ * DEEP, unlike every reader above: those walk the top level because dropping a nested clause would
79
+ * change what a flow means, while this only asks whether the predicate can mean anything at all in
80
+ * another session. A ref under a `not` is exactly as meaningless as one at the top.
81
+ */
82
+ export declare function sessionBoundField(predicate: Predicate): string | undefined;
@@ -0,0 +1,186 @@
1
+ /**
2
+ * Reading a predicate's TOP-LEVEL clauses.
3
+ *
4
+ * Structural, not evaluative: these answer "what does this predicate say" from the shape alone, the
5
+ * same basis `predicateShapeFor` sits here on. Nothing here decides anything about an app.
6
+ *
7
+ * It lived beside the replay code until the journal's flow-naming needed it too, and a
8
+ * `journal -> flows` reach is a file filed in the wrong place rather than a dependency anybody
9
+ * wanted. The thing both callers want is a reader for a core type, so it lives with the type.
10
+ *
11
+ * v1 stored one slot per kind, so "does this step assert state?" was a property read and "drop the
12
+ * element clause" was a `delete`. A `Predicate` nests, so every one of those questions is a walk.
13
+ *
14
+ * The walks here are deliberately SHALLOW, and that is the whole design. A lifted v1 file produces
15
+ * either a single leaf or one flat `allOf`, so a top-level walk reproduces v1 behaviour exactly. A
16
+ * hand-written v2 predicate can nest arbitrarily, and going deeper would silently change what an
17
+ * existing flow asserts:
18
+ *
19
+ * - dropping a leaf from an `allOf` removes a conjunct, which is what v1's `delete` did;
20
+ * - dropping a branch from an `anyOf` removes an ALTERNATIVE, which makes the predicate STRICTER
21
+ * and can turn a passing flow red;
22
+ * - dropping anything under a `not` inverts the meaning of the thing you dropped.
23
+ *
24
+ * So the composite cases are handled where they mean what v1 meant, and left alone everywhere else.
25
+ */
26
+ import { PredicateKind } from './consequence.js';
27
+ /**
28
+ * The plain clause each side of a `compare` reads, so a walker that asks "which endpoints, signals,
29
+ * stores or elements does this predicate depend on?" answers for a comparison without learning its
30
+ * shape. They are READERS of the same channel, never claims: a compare's `net` side is not an
31
+ * assertion that some call succeeded, only that the comparison reads one.
32
+ */
33
+ export function compareSourceClauses(predicate) {
34
+ return [predicate.left, predicate.right].map((source) => {
35
+ switch (source.from) {
36
+ case PredicateKind.NET:
37
+ return {
38
+ kind: PredicateKind.NET,
39
+ urlContains: source.urlContains,
40
+ ...(source.method === undefined ? {} : { method: source.method }),
41
+ };
42
+ case PredicateKind.SIGNAL:
43
+ return { kind: PredicateKind.SIGNAL, name: source.name };
44
+ case PredicateKind.STATE:
45
+ return {
46
+ kind: PredicateKind.STATE,
47
+ path: source.path,
48
+ ...(source.store === undefined ? {} : { store: source.store }),
49
+ };
50
+ case PredicateKind.TEXT:
51
+ return { kind: PredicateKind.TEXT, scope: source.scope };
52
+ }
53
+ });
54
+ }
55
+ /** Every clause at the top level: the predicate itself, or the members of a top-level `allOf`. */
56
+ export function conjuncts(predicate) {
57
+ if (predicate === undefined)
58
+ return [];
59
+ return PredicateKind.ALL_OF === predicate.kind ? predicate.predicates : [predicate];
60
+ }
61
+ /** The first top-level clause of this kind, or undefined. */
62
+ export function clauseOfKind(predicate, kind) {
63
+ return conjuncts(predicate).find((one) => one.kind === kind);
64
+ }
65
+ /** Does this expectation assert store state at the top level? The drift kind branches on it. */
66
+ export function assertsState(predicate) {
67
+ return clauseOfKind(predicate, PredicateKind.STATE) !== undefined;
68
+ }
69
+ /**
70
+ * The testid an element clause says must be PRESENT, when the expectation has one at the top level.
71
+ *
72
+ * An `absent: true` clause names a testid that must be gone, and asking the replay runner to
73
+ * require it made a correct dismissal fail. That clause is left to the predicate wait instead.
74
+ */
75
+ export function expectedElementTestid(predicate) {
76
+ const element = clauseOfKind(predicate, PredicateKind.ELEMENT);
77
+ return true === element?.absent ? undefined : element?.query.testid;
78
+ }
79
+ /**
80
+ * Rebuild the expectation without the top-level clauses a caller wants gone, collapsing as it goes.
81
+ *
82
+ * One clause left is that clause, not an `allOf` of one: a single-member composite grades weaker
83
+ * than its own member and reads worse in a report, and `combine()` has had to be taught about
84
+ * zero-branch composites once already.
85
+ */
86
+ export function withoutClauses(predicate, drop) {
87
+ if (predicate === undefined)
88
+ return undefined;
89
+ const kept = conjuncts(predicate).filter((clause) => !drop(clause));
90
+ const [only] = kept;
91
+ if (0 === kept.length)
92
+ return undefined;
93
+ if (1 === kept.length && only !== undefined)
94
+ return only;
95
+ return { kind: PredicateKind.ALL_OF, predicates: [...kept] };
96
+ }
97
+ /**
98
+ * Name what was asserted, for the drift row's `anchor` column.
99
+ *
100
+ * Reports the STRONGEST clause rather than the first, because that is the one a reader is asking
101
+ * about: an `allOf[settled, net]` is about the request, and answering "settled" names the gate
102
+ * instead of the claim.
103
+ */
104
+ export function expectLabel(predicate) {
105
+ const clauses = conjuncts(predicate);
106
+ const signal = clauses.find((c) => PredicateKind.SIGNAL === c.kind);
107
+ if (signal !== undefined && PredicateKind.SIGNAL === signal.kind) {
108
+ return `signal:${signal.name ?? '*'}`;
109
+ }
110
+ const net = clauses.find((c) => PredicateKind.NET === c.kind);
111
+ if (net !== undefined && PredicateKind.NET === net.kind) {
112
+ return `net:${net.urlContains ?? net.method ?? '*'}`;
113
+ }
114
+ const state = clauses.find((c) => PredicateKind.STATE === c.kind);
115
+ if (state !== undefined && PredicateKind.STATE === state.kind)
116
+ return `state:${state.path}`;
117
+ const console_ = clauses.find((c) => PredicateKind.CONSOLE === c.kind);
118
+ if (console_ !== undefined && PredicateKind.CONSOLE === console_.kind) {
119
+ return `console:${console_.level ?? '*'}`;
120
+ }
121
+ const element = clauses.find((c) => PredicateKind.ELEMENT === c.kind);
122
+ if (element !== undefined && PredicateKind.ELEMENT === element.kind) {
123
+ const q = element.query;
124
+ return q.testid ?? q.name ?? q.role ?? 'element';
125
+ }
126
+ const text = clauses.find((c) => PredicateKind.TEXT === c.kind);
127
+ if (text !== undefined && PredicateKind.TEXT === text.kind)
128
+ return `text:${text.contains ?? '*'}`;
129
+ const route = clauses.find((c) => PredicateKind.ROUTE === c.kind);
130
+ if (route !== undefined && PredicateKind.ROUTE === route.kind) {
131
+ return `route:${route.pathname ?? route.contains ?? '*'}`;
132
+ }
133
+ return 'expect';
134
+ }
135
+ /**
136
+ * An element ref: `e` and a sequence number, minted per session by the SDK's ref table. It is an
137
+ * address inside ONE session's numbering, not an identity.
138
+ */
139
+ export const SESSION_REF = /^e\d+$/;
140
+ /** Why a flow refused a predicate holding a ref, naming the field. */
141
+ export function sessionRefRefusal(field) {
142
+ return (`${field} is an element ref, which only exists in the session that minted it — ` +
143
+ 'scope by a CSS selector or a testid so the flow can check it again');
144
+ }
145
+ /**
146
+ * The first field anywhere in the tree that holds a session ref, as `kind.field "value"`.
147
+ *
148
+ * DEEP, unlike every reader above: those walk the top level because dropping a nested clause would
149
+ * change what a flow means, while this only asks whether the predicate can mean anything at all in
150
+ * another session. A ref under a `not` is exactly as meaningless as one at the top.
151
+ */
152
+ export function sessionBoundField(predicate) {
153
+ const ref = (field, value) => value !== undefined && SESSION_REF.test(value) ? `${field} "${value}"` : undefined;
154
+ switch (predicate.kind) {
155
+ case PredicateKind.ALL_OF:
156
+ case PredicateKind.ANY_OF:
157
+ for (const one of predicate.predicates) {
158
+ const found = sessionBoundField(one);
159
+ if (found !== undefined)
160
+ return found;
161
+ }
162
+ return undefined;
163
+ case PredicateKind.NOT:
164
+ return sessionBoundField(predicate.predicate);
165
+ case PredicateKind.TEXT:
166
+ return ref('text.scope', predicate.scope);
167
+ case PredicateKind.ELEMENT:
168
+ return ref('element.query.scope', predicate.query.scope);
169
+ case PredicateKind.ANIMATION:
170
+ return ref('animation.target', predicate.target);
171
+ case PredicateKind.COMPARE:
172
+ for (const [side, source] of [
173
+ ['left', predicate.left],
174
+ ['right', predicate.right],
175
+ ]) {
176
+ if (PredicateKind.TEXT !== source.from)
177
+ continue;
178
+ const found = ref(`compare.${side}.scope`, source.scope);
179
+ if (found !== undefined)
180
+ return found;
181
+ }
182
+ return undefined;
183
+ default:
184
+ return undefined;
185
+ }
186
+ }