@reticlehq/core 3.2.0 → 3.3.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 (77) hide show
  1. package/dist/artifacts/flow-composition.d.ts +3 -2
  2. package/dist/artifacts/flow-constants.d.ts +49 -2
  3. package/dist/artifacts/flow-constants.js +49 -2
  4. package/dist/artifacts/flow-expect-flat.d.ts +260 -0
  5. package/dist/artifacts/flow-expect-flat.js +284 -0
  6. package/dist/artifacts/flow-mutation-target.d.ts +0 -1
  7. package/dist/artifacts/flow-mutation-target.js +26 -2
  8. package/dist/artifacts/flow-step-tool.d.ts +2 -0
  9. package/dist/artifacts/flow-types.d.ts +1074 -1228
  10. package/dist/artifacts/flow-types.js +96 -140
  11. package/dist/artifacts/impact.d.ts +48 -20
  12. package/dist/artifacts/impact.js +11 -0
  13. package/dist/artifacts/journal.d.ts +33 -6
  14. package/dist/artifacts/journal.js +13 -0
  15. package/dist/hooks/hook-events.d.ts +18 -18
  16. package/dist/hud-entry.d.ts +9 -0
  17. package/dist/hud-entry.js +9 -0
  18. package/dist/identity/source-constants.d.ts +11 -0
  19. package/dist/identity/source-constants.js +11 -0
  20. package/dist/index.d.ts +8 -0
  21. package/dist/index.js +24 -1
  22. package/dist/onboarding.d.ts +2 -2
  23. package/dist/realm/registry.d.ts +0 -8
  24. package/dist/realm/registry.js +1 -11
  25. package/dist/schema/event-message.json +3 -1
  26. package/dist/schema/event-payloads.json +69 -0
  27. package/dist/schema/event-type.json +3 -1
  28. package/dist/schema/reticle-event.json +3 -1
  29. package/dist/schema/reticle-message.json +3 -1
  30. package/dist/source-constants.cjs +1 -0
  31. package/dist/source-constants.d.cts +1 -0
  32. package/dist/telemetry-feedback.d.ts +6 -6
  33. package/dist/telemetry-refusal.d.ts +2 -2
  34. package/dist/telemetry-session.d.ts +25 -2
  35. package/dist/telemetry-session.js +13 -0
  36. package/dist/telemetry.d.ts +121 -94
  37. package/dist/verdict/consequence.d.ts +10 -0
  38. package/dist/verdict/consequence.js +13 -0
  39. package/dist/verdict/intent.d.ts +36 -12
  40. package/dist/verdict/intent.js +66 -10
  41. package/dist/verdict/predicate-tree.d.ts +47 -0
  42. package/dist/verdict/predicate-tree.js +146 -0
  43. package/dist/verdict/predicate.d.ts +129 -0
  44. package/dist/verdict/predicate.js +394 -0
  45. package/dist/verdict/property-assertion.d.ts +191 -0
  46. package/dist/verdict/property-assertion.js +42 -0
  47. package/dist/verdict/security.js +16 -4
  48. package/dist/verdict/verdict-attribution.d.ts +52 -0
  49. package/dist/verdict/verdict-attribution.js +87 -0
  50. package/dist/verdict/verification-run.d.ts +98 -84
  51. package/dist/verdict/verification-run.js +8 -1
  52. package/dist/verdict/verified-constants.d.ts +9 -0
  53. package/dist/verdict/verified-constants.js +9 -0
  54. package/dist/wire/constants/constants.d.ts +20 -98
  55. package/dist/wire/constants/constants.js +22 -97
  56. package/dist/wire/constants/discovery.d.ts +25 -0
  57. package/dist/wire/constants/discovery.js +25 -0
  58. package/dist/wire/constants/event-types.d.ts +122 -0
  59. package/dist/wire/constants/event-types.js +121 -0
  60. package/dist/wire/constants/hud-controls.d.ts +19 -0
  61. package/dist/wire/constants/hud-controls.js +95 -0
  62. package/dist/wire/constants/hud-use.d.ts +27 -0
  63. package/dist/wire/constants/hud-use.js +24 -0
  64. package/dist/wire/constants/session-constants.d.ts +10 -0
  65. package/dist/wire/constants/session-constants.js +10 -0
  66. package/dist/wire/event-payloads.d.ts +66 -10
  67. package/dist/wire/event-payloads.js +18 -1
  68. package/dist/wire/messages.d.ts +89 -48
  69. package/dist/wire/messages.js +17 -0
  70. package/dist/wire/net.d.ts +18 -0
  71. package/dist/wire/net.js +24 -0
  72. package/dist/wire/state-select.d.ts +2 -1
  73. package/dist/wire/state-select.js +56 -3
  74. package/dist/wire/toon.js +28 -7
  75. package/dist/wire/types.d.ts +91 -66
  76. package/dist/wire/types.js +23 -1
  77. package/package.json +5 -1
@@ -0,0 +1,284 @@
1
+ /**
2
+ * Reading the FLAT expect a flow file used to store.
3
+ *
4
+ * The older format held one slot per kind — `{ signal, net, element, text, state, console, route }`
5
+ * — which could not nest, compose or negate. A step's expect is a `Predicate` now. This is the
6
+ * reader that bridges them, and it lives in core because the schema that parses a flow is here and
7
+ * the lift happens during the parse.
8
+ *
9
+ * A READ NEVER REWRITES. A v1 file stays v1 on disk until something saves it again; only the value
10
+ * in memory is lifted. That is what makes the migration safe to ship to people whose flows are
11
+ * committed to a repository they share.
12
+ */
13
+ import { z } from 'zod';
14
+ import { PredicateKind } from '../verdict/consequence.js';
15
+ /**
16
+ * A post-condition a step asserts (compiled from a structured annotation; optional).
17
+ *
18
+ * Strict, at every nesting level: an unrecognized key (a typo, or a predicate kind this schema
19
+ * doesn't model, e.g. `allOf`, or a typo'd `net`/`console`/`element`/`state` sub-field) must fail
20
+ * to parse instead of being silently dropped. A loose z.object() here would quietly discard the
21
+ * extra key and leave the step with a weaker (or empty) assertion than its author wrote — the
22
+ * flow then replays green against nothing, having proved no real regression.
23
+ */
24
+ export const FlowExpectSchema = z
25
+ .object({
26
+ /**
27
+ * The route the step must have reached — the consequence of a NAVIGATION.
28
+ *
29
+ * Absent until now, and its absence was not a corner case: navigation is one of the commonest
30
+ * journeys there is, and every route-asserted drive saved a flow that could never go red. Found
31
+ * by driving a real app, where `act_and_wait { until: { kind: "route" } }` returned
32
+ * `verified: "yes"` and the flow saved from that same drive graded `assertion-free`.
33
+ *
34
+ * Additive and optional, so a flow file written before it still parses and FLOW_FILE_VERSION
35
+ * stays 1 — the same treatment `signalData` and `signalCount` had.
36
+ */
37
+ route: z
38
+ .object({ pathname: z.string().optional(), contains: z.string().optional() })
39
+ .optional(),
40
+ signal: z.string().optional(),
41
+ /**
42
+ * Optional payload shape an `assert-signal` annotation requires the signal
43
+ * to match (the predicate DSL's signal.dataMatches). Additive/optional — a flow file with a
44
+ * bare `signal` still parses, and the on-disk version stays FLOW_FILE_VERSION 1.
45
+ */
46
+ signalData: z.record(z.unknown()).optional(),
47
+ /**
48
+ * Exact number of times the signal must have fired — the signal-side twin of `net.count`, and the
49
+ * only way a saved flow can keep a cardinality the agent actually asserted. Without it a
50
+ * `count: 1` drive would be recorded as bare presence, which is a strictly WEAKER claim than the
51
+ * one made: the replayed flow then goes green on the double-fire it was recorded to catch.
52
+ * Additive/optional — a flow file with a bare `signal` still parses, and FLOW_FILE_VERSION stays 1.
53
+ */
54
+ signalCount: z.number().int().nonnegative().optional(),
55
+ net: z
56
+ .object({
57
+ method: z.string().optional(),
58
+ urlContains: z.string().optional(),
59
+ status: z.number().optional(),
60
+ /**
61
+ * Exact number of matching requests since the action — turns presence into a cardinality
62
+ * assertion. Catches the double-submit / useEffect-double-fire / retry-storm regression class:
63
+ * the request fired (presence passes) but fired the WRONG number of times. Omit = presence (≥1).
64
+ */
65
+ count: z.number().int().nonnegative().optional(),
66
+ })
67
+ .strict()
68
+ .optional(),
69
+ /**
70
+ * Console golden end-condition: assert the action logged (or, with absent:true, did NOT log) a
71
+ * console message at `level` (default 'error'). `absent:true` is the common case — "the action
72
+ * completed with a clean console" — catching the regression where an action throws a caught error
73
+ * / logs an uncaught rejection while the UI still renders fine (a presence check passes it).
74
+ */
75
+ console: z
76
+ .object({
77
+ level: z.string().optional(),
78
+ absent: z.boolean().optional(),
79
+ })
80
+ .strict()
81
+ .optional(),
82
+ element: z
83
+ .object({
84
+ testid: z.string().optional(),
85
+ role: z.string().optional(),
86
+ name: z.string().optional(),
87
+ })
88
+ .strict()
89
+ .optional(),
90
+ /**
91
+ * Rendered text as an end-condition, using the shapes the assert surface already accepts.
92
+ *
93
+ * The gap this closes: an app with no testids, no `reticle.signal`, no registrable store and no
94
+ * network call on the interaction under test -- a discount price computed and rendered, a
95
+ * formatted total, a derived label -- could not produce an asserted flow AT ALL. Everything the
96
+ * vocabulary offered needed a channel that app does not have, so the only honest outcome was
97
+ * `assertion-free`, which is a permanent green (#811).
98
+ *
99
+ * Derived-DOM rendering is a large share of what actually breaks in a UI, and it was the share
100
+ * that could not be pinned.
101
+ *
102
+ * Classified PRESENCE, not consequence, and that is not a technicality: text is read from the
103
+ * DOM, so a locator healed to the wrong element can still satisfy it. It earns `presence-only`,
104
+ * which is a real grade above `assertion-free` and honestly below `signal`/`net`/`state`.
105
+ */
106
+ text: z
107
+ .object({
108
+ contains: z.string().min(1),
109
+ /** Narrow the search to a container, exactly as the `text` predicate's `scope` does. */
110
+ scope: z.string().optional(),
111
+ /** Assert the text is GONE — the regression check for a cleared error or a dismissed toast. */
112
+ absent: z.boolean().optional(),
113
+ /** Require the match to be visible, not merely present in the DOM. */
114
+ visible: z.boolean().optional(),
115
+ })
116
+ .strict()
117
+ .optional(),
118
+ /**
119
+ * Assert a registered store's value — the source of truth no DOM/network read can reach. Compiles
120
+ * to the predicate engine's `state` predicate. Additive/optional — a flow without it still parses
121
+ * and the on-disk version stays FLOW_FILE_VERSION 1. `equals` accepts a literal, omitted = presence,
122
+ * or a `{ $gte | $contains | $length }` operator pattern.
123
+ */
124
+ state: z
125
+ .object({
126
+ store: z.string().optional(),
127
+ path: z.string(),
128
+ equals: z.unknown().optional(),
129
+ /**
130
+ * Treat this as an INVARIANT that must still hold AFTER the action settles, rather than a
131
+ * condition to wait for. Set it for a blast-radius check ("this unrelated path must NOT have
132
+ * moved") — without it a wait-until-true read passes before an over-reaching side-effect lands.
133
+ */
134
+ hold: z.boolean().optional(),
135
+ })
136
+ .strict()
137
+ .optional(),
138
+ })
139
+ .strict();
140
+ /**
141
+ * Lift a flat `FlowExpect` into the predicate a current file stores directly.
142
+ *
143
+ * THE READER FOR THE OLDER FORMAT. A flow written before `FlowStep.expect` became a `Predicate` holds one slot
144
+ * per kind, and this is what turns that into the tree everything downstream now evaluates. It runs
145
+ * on READ and changes nothing on disk: a v1 file stays a v1 file until something re-saves it.
146
+ *
147
+ * Faithful on purpose, including one wart it does NOT fix: a `route` clause returns immediately and
148
+ * drops every other clause beside it. That is what v1 files have always meant, and a migration that
149
+ * quietly started asserting a clause those files used to ignore would turn greens red for a reason
150
+ * nobody could see in their diff. It is a real lossy path and it is being fixed separately, where it
151
+ * can carry its own test and its own explanation.
152
+ *
153
+ * `undefined` means nothing assertable, which is vacuously met rather than failed.
154
+ */
155
+ export function flowExpectToPredicate(success) {
156
+ const parts = [];
157
+ if (success.signal !== undefined) {
158
+ const signal = {
159
+ kind: PredicateKind.SIGNAL,
160
+ name: success.signal,
161
+ };
162
+ if (success.signalData !== undefined)
163
+ signal.dataMatches = success.signalData;
164
+ if (success.signalCount !== undefined) {
165
+ signal.count = success.signalCount;
166
+ // Same post-settle reasoning as net.count: the success waiter is wait-until-true, so an exact
167
+ // count is transiently satisfied the instant the FIRST matching signal fires — before a
168
+ // double-fire's duplicate arrives. Gating on `settled` forces the count to be read only after
169
+ // the app goes quiet, by which point the duplicate IS counted and the over-count fails.
170
+ parts.push({ kind: PredicateKind.SETTLED });
171
+ }
172
+ parts.push(signal);
173
+ }
174
+ if (success.route !== undefined) {
175
+ // The mirror of `predicateToExpect`'s ROUTE case. Replay evaluates predicates, so carrying the
176
+ // route back here is the whole of what makes a recorded navigation able to fail.
177
+ const route = {
178
+ kind: PredicateKind.ROUTE,
179
+ };
180
+ if (success.route.pathname !== undefined)
181
+ route.pathname = success.route.pathname;
182
+ if (success.route.contains !== undefined)
183
+ route.contains = success.route.contains;
184
+ return route;
185
+ }
186
+ if (success.net !== undefined) {
187
+ const net = { kind: PredicateKind.NET };
188
+ if (success.net.method !== undefined)
189
+ net.method = success.net.method;
190
+ if (success.net.urlContains !== undefined)
191
+ net.urlContains = success.net.urlContains;
192
+ if (success.net.status !== undefined)
193
+ net.status = success.net.status;
194
+ if (success.net.count !== undefined) {
195
+ net.count = success.net.count;
196
+ // A cardinality assertion is inherently POST-SETTLE. The success waiter is wait-until-true, so an
197
+ // exact count (e.g. 1) is transiently satisfied the instant the FIRST matching request lands —
198
+ // before a double-submit's duplicate arrives. Gating on `settled` forces the count to be read
199
+ // only after the network has gone quiet, so the duplicate IS counted and the over-count fails.
200
+ parts.push({ kind: PredicateKind.SETTLED });
201
+ }
202
+ parts.push(net);
203
+ }
204
+ if (success.console !== undefined) {
205
+ const con = {
206
+ kind: PredicateKind.CONSOLE,
207
+ };
208
+ if (success.console.level !== undefined)
209
+ con.level = success.console.level;
210
+ if (success.console.absent !== undefined) {
211
+ con.absent = success.console.absent;
212
+ // An `absent` assertion is post-settle, same as net.count: a wait-until-true waiter sees "no
213
+ // error yet" at the first poll and passes BEFORE the action's error fires. Gate on `settled` so
214
+ // the console is read only after the page quiets, by which point any error is in the buffer.
215
+ if (success.console.absent)
216
+ parts.push({ kind: PredicateKind.SETTLED });
217
+ }
218
+ parts.push(con);
219
+ }
220
+ const state = success.state;
221
+ if (state !== undefined) {
222
+ const part = {
223
+ kind: PredicateKind.STATE,
224
+ path: state.path,
225
+ };
226
+ if (state.store !== undefined)
227
+ part.store = state.store;
228
+ if (state.equals !== undefined)
229
+ part.equals = state.equals;
230
+ // `hold` = an INVARIANT ("this state must still hold after the action settles"), vs the default
231
+ // wait-for-change. A wait-until-true waiter would pass the instant the path already equals the
232
+ // value — which, for "an unrelated path stayed put", is true BEFORE a side-effect leak fires. Gate
233
+ // on `settled` so the read happens after the page quiets, by which point the leak has landed.
234
+ if (true === state.hold)
235
+ parts.push({ kind: PredicateKind.SETTLED });
236
+ parts.push(part);
237
+ }
238
+ const element = success.element;
239
+ if (element !== undefined) {
240
+ /*
241
+ * The dynamic (LLM-output) skip is NOT applied here, and that is the whole reason this moved.
242
+ *
243
+ * "Do not assert the presence of a testid whose content a model writes" is a REPLAY rule, not a
244
+ * fact about the file. Applying it during the read would make the lift lossy in a way that
245
+ * depends on a sibling field, and a v1 file would mean two different things depending on who
246
+ * was reading it. The lift is faithful; replay applies its own rule to the predicate.
247
+ */
248
+ const query = {};
249
+ if (element.testid !== undefined)
250
+ query['testid'] = element.testid;
251
+ if (element.role !== undefined)
252
+ query['role'] = element.role;
253
+ if (element.name !== undefined)
254
+ query['name'] = element.name;
255
+ if (Object.keys(query).length > 0)
256
+ parts.push({ kind: PredicateKind.ELEMENT, query });
257
+ }
258
+ const text = success.text;
259
+ if (text !== undefined) {
260
+ const part = {
261
+ kind: PredicateKind.TEXT,
262
+ contains: text.contains,
263
+ };
264
+ if (text.scope !== undefined)
265
+ part.scope = text.scope;
266
+ if (text.visible !== undefined)
267
+ part.visible = text.visible;
268
+ if (true === text.absent) {
269
+ part.absent = true;
270
+ // Same post-settle reasoning as `console.absent` and `state.hold`: a wait-until-true waiter
271
+ // reads "not there yet" on the first poll and passes BEFORE the text it is meant to see
272
+ // disappear has even been rendered. Gate on `settled` so the read happens after the page
273
+ // quiets, by which point a text that was going to appear has.
274
+ parts.push({ kind: PredicateKind.SETTLED });
275
+ }
276
+ parts.push(part);
277
+ }
278
+ const [first] = parts;
279
+ if (0 === parts.length)
280
+ return undefined;
281
+ if (1 === parts.length && first !== undefined)
282
+ return first;
283
+ return { kind: PredicateKind.ALL_OF, predicates: parts };
284
+ }
@@ -19,7 +19,6 @@
19
19
  * Guessing a target would manufacture the demotion instead of measuring it.
20
20
  */
21
21
  import type { FlowFile } from './flow-types.js';
22
- /** Every endpoint this flow's own declarations name, in order, once each. */
23
22
  export declare function mutationTargetsFor(flow: FlowFile): string[];
24
23
  /** The shape a network mock needs from us: which endpoint, and how much later. Nothing else. */
25
24
  export interface Perturbation {
@@ -18,7 +18,29 @@
18
18
  * A flow that declared none yields NOTHING, and that is a finding rather than a gap to paper over.
19
19
  * Guessing a target would manufacture the demotion instead of measuring it.
20
20
  */
21
+ import { PredicateKind } from '../verdict/consequence.js';
21
22
  /** Every endpoint this flow's own declarations name, in order, once each. */
23
+ /**
24
+ * Every `net` URL a predicate names, composites included.
25
+ *
26
+ * `expect` used to be a flat struct with one `net` slot, so this was a property read. It is a
27
+ * PREDICATE now, and a net clause can sit inside an `allOf` two levels down — which is exactly the
28
+ * shape an agent writes when it asserts a request AND what the request changed. Reading only the
29
+ * top level would silently stop finding the endpoint this whole module exists to perturb.
30
+ */
31
+ function netUrlsIn(predicate) {
32
+ if (predicate === undefined)
33
+ return [];
34
+ if (PredicateKind.NET === predicate.kind) {
35
+ return predicate.urlContains === undefined ? [] : [predicate.urlContains];
36
+ }
37
+ if (PredicateKind.ALL_OF === predicate.kind || PredicateKind.ANY_OF === predicate.kind) {
38
+ return predicate.predicates.flatMap(netUrlsIn);
39
+ }
40
+ if (PredicateKind.NOT === predicate.kind)
41
+ return netUrlsIn(predicate.predicate);
42
+ return [];
43
+ }
22
44
  export function mutationTargetsFor(flow) {
23
45
  const targets = [];
24
46
  const add = (url) => {
@@ -29,7 +51,8 @@ export function mutationTargetsFor(flow) {
29
51
  };
30
52
  const walk = (steps) => {
31
53
  for (const step of steps) {
32
- add(step.expect?.net?.urlContains);
54
+ for (const url of netUrlsIn(step.expect))
55
+ add(url);
33
56
  // A sequence is where the real journeys live, so its children are where the real dependencies
34
57
  // are declared. A walk that stopped at the top level would find nothing in the common case.
35
58
  if (step.steps !== undefined)
@@ -37,7 +60,8 @@ export function mutationTargetsFor(flow) {
37
60
  }
38
61
  };
39
62
  walk(flow.steps);
40
- add(flow.success?.net?.urlContains);
63
+ for (const url of netUrlsIn(flow.success))
64
+ add(url);
41
65
  return targets;
42
66
  }
43
67
  /**
@@ -29,3 +29,5 @@ export declare const FlowStepTool: {
29
29
  */
30
30
  readonly INVOKE: "reticle_invoke";
31
31
  };
32
+ /** The companion type. It lives beside the const, so naming either one reaches only this leaf. */
33
+ export type FlowStepTool = (typeof FlowStepTool)[keyof typeof FlowStepTool];