@reticlehq/core 3.6.0 → 3.8.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 (133) hide show
  1. package/dist/activation-entry.d.ts +9 -0
  2. package/dist/activation-entry.js +9 -0
  3. package/dist/artifacts/artifacts-entry.d.ts +2 -0
  4. package/dist/artifacts/artifacts-entry.js +2 -0
  5. package/dist/artifacts/drive-script.d.ts +222 -116
  6. package/dist/artifacts/drive-script.js +24 -1
  7. package/dist/artifacts/flow-constants.d.ts +33 -0
  8. package/dist/artifacts/flow-constants.js +35 -0
  9. package/dist/artifacts/flow-expect-flat.d.ts +8 -8
  10. package/dist/artifacts/flow-results.d.ts +461 -0
  11. package/dist/artifacts/flow-results.js +1 -0
  12. package/dist/artifacts/flow-types.d.ts +177 -543
  13. package/dist/artifacts/flow-types.js +17 -2
  14. package/dist/artifacts/harness-credits.d.ts +42 -0
  15. package/dist/artifacts/harness-credits.js +72 -0
  16. package/dist/artifacts/harness-map.d.ts +98 -0
  17. package/dist/artifacts/harness-map.js +36 -0
  18. package/dist/artifacts/impact.d.ts +355 -149
  19. package/dist/artifacts/impact.js +84 -49
  20. package/dist/artifacts/journal.d.ts +81 -11
  21. package/dist/artifacts/journal.js +39 -0
  22. package/dist/artifacts/prompt-context.d.ts +12 -0
  23. package/dist/artifacts/prompt-context.js +14 -3
  24. package/dist/artifacts/screenshot-upload.d.ts +51 -0
  25. package/dist/artifacts/screenshot-upload.js +26 -0
  26. package/dist/graph/app-graph.d.ts +137 -0
  27. package/dist/graph/app-graph.js +498 -0
  28. package/dist/hooks/hook-events.d.ts +26 -26
  29. package/dist/hud-entry.d.ts +1 -0
  30. package/dist/hud-entry.js +2 -0
  31. package/dist/identity/checkout.d.ts +41 -0
  32. package/dist/identity/checkout.js +118 -0
  33. package/dist/identity/state-dir.d.ts +23 -0
  34. package/dist/identity/state-dir.js +43 -0
  35. package/dist/index.d.ts +15 -0
  36. package/dist/index.js +15 -0
  37. package/dist/onboarding.d.ts +30 -1
  38. package/dist/onboarding.js +25 -0
  39. package/dist/realm/registry.js +19 -1
  40. package/dist/registry/dev-server-registry.d.ts +2 -2
  41. package/dist/schema/command-message.json +30 -0
  42. package/dist/schema/command-name.json +3 -1
  43. package/dist/schema/event-message.json +3 -1
  44. package/dist/schema/event-payloads.json +156 -3
  45. package/dist/schema/event-type.json +3 -1
  46. package/dist/schema/hello-message.json +21 -0
  47. package/dist/schema/reticle-event.json +3 -1
  48. package/dist/schema/reticle-message.json +54 -1
  49. package/dist/telemetry-bug.d.ts +169 -0
  50. package/dist/telemetry-bug.js +123 -0
  51. package/dist/telemetry-entry.d.ts +2 -1
  52. package/dist/telemetry-entry.js +2 -1
  53. package/dist/telemetry-feedback.d.ts +16 -2
  54. package/dist/telemetry-feedback.js +19 -0
  55. package/dist/telemetry-session.d.ts +91 -2
  56. package/dist/telemetry-session.js +65 -0
  57. package/dist/telemetry-signals.d.ts +557 -0
  58. package/dist/telemetry-signals.js +225 -0
  59. package/dist/telemetry.d.ts +649 -296
  60. package/dist/telemetry.js +110 -119
  61. package/dist/verdict/check-sentence.d.ts +34 -0
  62. package/dist/verdict/check-sentence.js +228 -0
  63. package/dist/verdict/consequence.d.ts +15 -0
  64. package/dist/verdict/consequence.js +11 -0
  65. package/dist/verdict/disparity.d.ts +105 -0
  66. package/dist/verdict/disparity.js +40 -0
  67. package/dist/verdict/findings.d.ts +16 -0
  68. package/dist/verdict/findings.js +22 -0
  69. package/dist/verdict/instrumentation-coverage.d.ts +84 -0
  70. package/dist/verdict/instrumentation-coverage.js +182 -0
  71. package/dist/verdict/instrumentation-gap.d.ts +79 -0
  72. package/dist/verdict/instrumentation-gap.js +65 -1
  73. package/dist/verdict/intent.d.ts +19 -5
  74. package/dist/verdict/intent.js +13 -1
  75. package/dist/verdict/predicate-tree.d.ts +17 -0
  76. package/dist/verdict/predicate-tree.js +37 -0
  77. package/dist/verdict/predicate.d.ts +16 -1
  78. package/dist/verdict/predicate.js +188 -13
  79. package/dist/verdict/property-assertion.d.ts +2 -2
  80. package/dist/verdict/run-report.d.ts +166 -0
  81. package/dist/verdict/run-report.js +53 -0
  82. package/dist/verdict/security.d.ts +60 -1
  83. package/dist/verdict/security.js +174 -12
  84. package/dist/verdict/verification-run.d.ts +713 -68
  85. package/dist/verdict/verification-run.js +113 -0
  86. package/dist/verdict/verify-progress.d.ts +6 -6
  87. package/dist/wire/constants/constants.d.ts +69 -155
  88. package/dist/wire/constants/constants.js +78 -159
  89. package/dist/wire/constants/discovery.d.ts +4 -4
  90. package/dist/wire/constants/discovery.js +4 -4
  91. package/dist/wire/constants/event-types.d.ts +35 -1
  92. package/dist/wire/constants/event-types.js +33 -1
  93. package/dist/wire/constants/hud-controls.js +15 -5
  94. package/dist/wire/constants/hud-use.d.ts +33 -4
  95. package/dist/wire/constants/hud-use.js +30 -4
  96. package/dist/wire/constants/mcp-wire.d.ts +26 -0
  97. package/dist/wire/constants/mcp-wire.js +26 -0
  98. package/dist/wire/constants/response-body-reason.d.ts +19 -0
  99. package/dist/wire/constants/response-body-reason.js +18 -0
  100. package/dist/wire/constants/reticle-chrome.d.ts +19 -0
  101. package/dist/wire/constants/reticle-chrome.js +19 -0
  102. package/dist/wire/constants/reticle-env.d.ts +138 -0
  103. package/dist/wire/constants/reticle-env.js +138 -0
  104. package/dist/wire/constants/session-constants.d.ts +26 -2
  105. package/dist/wire/constants/session-constants.js +26 -2
  106. package/dist/wire/desktop-contract.d.ts +8 -0
  107. package/dist/wire/desktop-contract.js +11 -0
  108. package/dist/wire/event-payloads.d.ts +202 -36
  109. package/dist/wire/event-payloads.js +100 -16
  110. package/dist/wire/messages.d.ts +193 -54
  111. package/dist/wire/messages.js +25 -1
  112. package/dist/wire/narrow.d.ts +6 -0
  113. package/dist/wire/narrow.js +26 -0
  114. package/dist/wire/next-step.d.ts +90 -0
  115. package/dist/wire/next-step.js +37 -0
  116. package/dist/wire/platform-link.d.ts +84 -0
  117. package/dist/wire/platform-link.js +57 -6
  118. package/dist/wire/production/activation-ticket.d.ts +64 -0
  119. package/dist/wire/production/activation-ticket.js +148 -0
  120. package/dist/wire/production/hello-mode.d.ts +35 -0
  121. package/dist/wire/production/hello-mode.js +32 -0
  122. package/dist/wire/production/production-policy.d.ts +138 -0
  123. package/dist/wire/production/production-policy.js +133 -0
  124. package/dist/wire/tool-names.d.ts +4 -0
  125. package/dist/wire/tool-names.js +4 -0
  126. package/dist/wire/types.d.ts +90 -52
  127. package/dist/wire/types.js +5 -0
  128. package/dist/words/notices.d.ts +1 -1
  129. package/dist/words/notices.js +1 -1
  130. package/dist/words/upgrade.js +1 -1
  131. package/dist/words/writing-rule.d.ts +14 -0
  132. package/dist/words/writing-rule.js +17 -0
  133. package/package.json +5 -1
@@ -14,6 +14,7 @@
14
14
  * everything uninstrumented on the page. The test is *did this absence change the answer the agent
15
15
  * just got?* — if not, it does not fire.
16
16
  */
17
+ import { z } from 'zod';
17
18
  /**
18
19
  * The kinds of absence that can weaken a verdict. Most name a capability the app did not provide;
19
20
  * `UNDECLARED_CHANGE` names one the agent did not, and is here because it costs a verdict the same.
@@ -119,7 +120,7 @@ export const InstrumentationGapKind = {
119
120
  */
120
121
  const GAP_FIX = {
121
122
  [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 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
+ [InstrumentationGapKind.NO_STORE_REGISTERED]: "import { registerStore } from '@reticlehq/browser' and call registerStore(name, store) with a subscribable store so its changes are observed; a bare getter is readable but does not report changes. For component-local React state, import { useReticleStore } from '@reticlehq/react/store' and call useReticleStore(name, value), assert the DOM, or read it with reticle_look { action: 'state', ref: '...' }",
123
124
  [InstrumentationGapKind.NO_SIGNAL_ON_MUTATION]: 'fire reticle.signal(name, data) where this state is committed — commitAndSignal binds the two so they cannot drift',
124
125
  [InstrumentationGapKind.UNDECLARED_CONTROL]: 'add this control to reticle.describe() so the capability contract matches what the app actually exposes',
125
126
  [InstrumentationGapKind.MISSING_TESTID]: 'add data-testid="..." on this control so the flow can name it after a refactor',
@@ -170,3 +171,66 @@ export function dedupeGaps(gaps) {
170
171
  }
171
172
  return out;
172
173
  }
174
+ /**
175
+ * What the ENGINE could not observe in a run, so a host can refuse to call that run clean.
176
+ *
177
+ * Not an instrumentation gap: nothing the app adds closes these, because this engine has no reader
178
+ * for them. Each verdict result (`reticle_act_and_wait`, `reticle_assert`) carries the list under
179
+ * `ENGINE_BLIND_SPOTS_FIELD`, CUMULATIVE for its session: everything seen since the session began,
180
+ * and `[]` when there is nothing. So the LAST verdict result of a run is the run's list. A host that
181
+ * predates the field ignores it; nothing else in the result changes.
182
+ */
183
+ export const EngineBlindSpotKind = {
184
+ /**
185
+ * An action ran while a `<canvas>` was visible, and this engine records no canvas digest.
186
+ *
187
+ * The pixels are the output there. A colour picker that no longer reaches the renderer leaves the
188
+ * DOM, the network and the store exactly as they were on the build that works, so "nothing
189
+ * disagreed" is not evidence that the canvas is right.
190
+ */
191
+ PIXELS_UNOBSERVED: 'pixels-unobserved',
192
+ /**
193
+ * A claim under test names a number or a total, and no verdict ran a computed comparison
194
+ * (`compare`).
195
+ *
196
+ * "Each hit adds one point" is broken by a handler that adds two. The store, the screen and the
197
+ * wire all agree with each other on that build, so only the arithmetic the claim states can catch
198
+ * it, and nothing checked it.
199
+ */
200
+ CLAIM_ARITHMETIC_UNCHECKED: 'claim-arithmetic-unchecked',
201
+ };
202
+ export const EngineBlindSpotSchema = z.object({
203
+ kind: z.nativeEnum(EngineBlindSpotKind),
204
+ /** What could not be seen, in words. */
205
+ detail: z.string().min(1),
206
+ });
207
+ /** The verdict-result field that carries a session's `EngineBlindSpot[]`. */
208
+ export const ENGINE_BLIND_SPOTS_FIELD = 'engineBlindSpots';
209
+ /** Number words and arithmetic nouns a claim uses to state an amount. Whole words only. */
210
+ const ARITHMETIC_WORDS = /\b(?:one|two|three|four|five|six|seven|eight|nine|ten|eleven|twelve|hundred|thousand|once|twice|double|triple|half|total|sum|subtotal|count|score|points?|balance|average|percent)\b/i;
211
+ /** True when a claim states an amount: a digit, a percent sign, or a number word. */
212
+ export function namesArithmetic(claim) {
213
+ return /\d|%/.test(claim) || ARITHMETIC_WORDS.test(claim);
214
+ }
215
+ /**
216
+ * What this engine could not observe in a session, cumulative. See `EngineBlindSpotKind`.
217
+ *
218
+ * Pixels: this engine records no canvas digest, so a visible canvas is always unobserved.
219
+ */
220
+ export function engineBlindSpots(facts) {
221
+ const spots = [];
222
+ if (facts.canvasSeen) {
223
+ spots.push({
224
+ kind: EngineBlindSpotKind.PIXELS_UNOBSERVED,
225
+ detail: 'an action ran while a canvas was visible, and no canvas digest was recorded, so what it draws was not compared',
226
+ });
227
+ }
228
+ const numeric = facts.claims.find((claim) => claim !== undefined && namesArithmetic(claim));
229
+ if (numeric !== undefined && !facts.compared) {
230
+ spots.push({
231
+ kind: EngineBlindSpotKind.CLAIM_ARITHMETIC_UNCHECKED,
232
+ detail: `the claim "${numeric}" states an amount, and no verdict ran a computed comparison against it`,
233
+ });
234
+ }
235
+ return spots;
236
+ }
@@ -53,14 +53,18 @@ export declare const IntentProofSchema: z.ZodObject<{
53
53
  verdictId: z.ZodString;
54
54
  grade: z.ZodString;
55
55
  at: z.ZodNumber;
56
+ /** The run the proving check landed in, so a reader links proof and run by id, not by time. */
57
+ runId: z.ZodOptional<z.ZodString>;
56
58
  }, "strip", z.ZodTypeAny, {
57
59
  at: number;
58
60
  grade: string;
59
61
  verdictId: string;
62
+ runId?: string | undefined;
60
63
  }, {
61
64
  at: number;
62
65
  grade: string;
63
66
  verdictId: string;
67
+ runId?: string | undefined;
64
68
  }>;
65
69
  export declare const IntentSchema: z.ZodObject<{
66
70
  id: z.ZodString;
@@ -87,14 +91,18 @@ export declare const IntentSchema: z.ZodObject<{
87
91
  verdictId: z.ZodString;
88
92
  grade: z.ZodString;
89
93
  at: z.ZodNumber;
94
+ /** The run the proving check landed in, so a reader links proof and run by id, not by time. */
95
+ runId: z.ZodOptional<z.ZodString>;
90
96
  }, "strip", z.ZodTypeAny, {
91
97
  at: number;
92
98
  grade: string;
93
99
  verdictId: string;
100
+ runId?: string | undefined;
94
101
  }, {
95
102
  at: number;
96
103
  grade: string;
97
104
  verdictId: string;
105
+ runId?: string | undefined;
98
106
  }>>;
99
107
  /** Every statement this intent previously carried, oldest first. Append-only, never rewritten. */
100
108
  amended: z.ZodOptional<z.ZodArray<z.ZodObject<{
@@ -122,6 +130,7 @@ export declare const IntentSchema: z.ZodObject<{
122
130
  at: number;
123
131
  grade: string;
124
132
  verdictId: string;
133
+ runId?: string | undefined;
125
134
  } | undefined;
126
135
  amended?: {
127
136
  at: number;
@@ -142,6 +151,7 @@ export declare const IntentSchema: z.ZodObject<{
142
151
  at: number;
143
152
  grade: string;
144
153
  verdictId: string;
154
+ runId?: string | undefined;
145
155
  } | undefined;
146
156
  amended?: {
147
157
  at: number;
@@ -176,14 +186,18 @@ export declare const IntentFileSchema: z.ZodObject<{
176
186
  verdictId: z.ZodString;
177
187
  grade: z.ZodString;
178
188
  at: z.ZodNumber;
189
+ /** The run the proving check landed in, so a reader links proof and run by id, not by time. */
190
+ runId: z.ZodOptional<z.ZodString>;
179
191
  }, "strip", z.ZodTypeAny, {
180
192
  at: number;
181
193
  grade: string;
182
194
  verdictId: string;
195
+ runId?: string | undefined;
183
196
  }, {
184
197
  at: number;
185
198
  grade: string;
186
199
  verdictId: string;
200
+ runId?: string | undefined;
187
201
  }>>;
188
202
  /** Every statement this intent previously carried, oldest first. Append-only, never rewritten. */
189
203
  amended: z.ZodOptional<z.ZodArray<z.ZodObject<{
@@ -211,6 +225,7 @@ export declare const IntentFileSchema: z.ZodObject<{
211
225
  at: number;
212
226
  grade: string;
213
227
  verdictId: string;
228
+ runId?: string | undefined;
214
229
  } | undefined;
215
230
  amended?: {
216
231
  at: number;
@@ -231,6 +246,7 @@ export declare const IntentFileSchema: z.ZodObject<{
231
246
  at: number;
232
247
  grade: string;
233
248
  verdictId: string;
249
+ runId?: string | undefined;
234
250
  } | undefined;
235
251
  amended?: {
236
252
  at: number;
@@ -254,6 +270,7 @@ export declare const IntentFileSchema: z.ZodObject<{
254
270
  at: number;
255
271
  grade: string;
256
272
  verdictId: string;
273
+ runId?: string | undefined;
257
274
  } | undefined;
258
275
  amended?: {
259
276
  at: number;
@@ -277,6 +294,7 @@ export declare const IntentFileSchema: z.ZodObject<{
277
294
  at: number;
278
295
  grade: string;
279
296
  verdictId: string;
297
+ runId?: string | undefined;
280
298
  } | undefined;
281
299
  amended?: {
282
300
  at: number;
@@ -302,11 +320,7 @@ export declare function bindIntent(intent: Intent, binding: unknown): Intent;
302
320
  * evidence — the shape this whole feature exists to stop. A throw would be the wrong shape too,
303
321
  * because discharge runs off the back of a verdict and must never be why one fails to return.
304
322
  */
305
- export declare function dischargeIntent(intent: Intent, proof: {
306
- verdictId: string;
307
- grade: string;
308
- at: number;
309
- }): Intent;
323
+ export declare function dischargeIntent(intent: Intent, proof: z.infer<typeof IntentProofSchema>): Intent;
310
324
  /**
311
325
  * What declaring an intent that may already exist should leave stored.
312
326
  *
@@ -43,6 +43,8 @@ export const IntentProofSchema = z.object({
43
43
  verdictId: z.string(),
44
44
  grade: z.string(),
45
45
  at: z.number(),
46
+ /** The run the proving check landed in, so a reader links proof and run by id, not by time. */
47
+ runId: z.string().optional(),
46
48
  });
47
49
  export const IntentSchema = z.object({
48
50
  id: z.string().min(1),
@@ -108,7 +110,17 @@ export function dischargeIntent(intent, proof) {
108
110
  export function redeclareIntent(existing, fresh) {
109
111
  if (existing === undefined)
110
112
  return fresh;
111
- const surface = existing.surface ?? fresh.surface;
113
+ // What the record already says wins; a field it never had (a route, a flow, files) is filled in,
114
+ // so a fact first declared with nothing to file it under can be given somewhere to live.
115
+ const surface = existing.surface === undefined
116
+ ? fresh.surface
117
+ : {
118
+ ...fresh.surface,
119
+ ...existing.surface,
120
+ ...(0 < (existing.surface.files?.length ?? 0) || fresh.surface?.files === undefined
121
+ ? {}
122
+ : { files: fresh.surface.files }),
123
+ };
112
124
  const withSurface = surface === undefined ? {} : { surface };
113
125
  if (existing.statement === fresh.statement)
114
126
  return { ...existing, ...withSurface };
@@ -70,6 +70,21 @@ export declare function expectLabel(predicate: Predicate | undefined): string;
70
70
  * address inside ONE session's numbering, not an identity.
71
71
  */
72
72
  export declare const SESSION_REF: RegExp;
73
+ /**
74
+ * The stable part of the refusal for a `ref` Reticle never minted. The server's recovery table keys
75
+ * on it, so it is one constant rather than two spellings that could drift.
76
+ */
77
+ export declare const UNISSUED_REF_REFUSAL = "is not a ref Reticle issued";
78
+ /**
79
+ * Why an act refused a `ref` that does not have the minted shape.
80
+ *
81
+ * The browser's ref table answers a miss with null, and an unknown string and a detached element
82
+ * reached the same refusal: "that ref is stale: refs are invalidated whenever the DOM re-renders".
83
+ * For `find:aria-label=Open menu` — never a ref at all — that diagnosis is wrong, and the agent
84
+ * retried the same mistake. A string that cannot have been minted is answered for what it is, and
85
+ * pointed at `target`, which is what the caller was reaching for.
86
+ */
87
+ export declare function unissuedRefRefusal(ref: string): string;
73
88
  /** Why a flow refused a predicate holding a ref, naming the field. */
74
89
  export declare function sessionRefRefusal(field: string): string;
75
90
  /**
@@ -80,3 +95,5 @@ export declare function sessionRefRefusal(field: string): string;
80
95
  * another session. A ref under a `not` is exactly as meaningless as one at the top.
81
96
  */
82
97
  export declare function sessionBoundField(predicate: Predicate): string | undefined;
98
+ /** True when any clause of this predicate, at any depth, is a computed `compare`. */
99
+ export declare function computesComparison(predicate: Predicate | undefined): boolean;
@@ -24,6 +24,7 @@
24
24
  * So the composite cases are handled where they mean what v1 meant, and left alone everywhere else.
25
25
  */
26
26
  import { PredicateKind } from './consequence.js';
27
+ import { TRANSPORT_LIMITS } from '../wire/constants/constants.js';
27
28
  /**
28
29
  * The plain clause each side of a `compare` reads, so a walker that asks "which endpoints, signals,
29
30
  * stores or elements does this predicate depend on?" answers for a comparison without learning its
@@ -137,6 +138,26 @@ export function expectLabel(predicate) {
137
138
  * address inside ONE session's numbering, not an identity.
138
139
  */
139
140
  export const SESSION_REF = /^e\d+$/;
141
+ /**
142
+ * The stable part of the refusal for a `ref` Reticle never minted. The server's recovery table keys
143
+ * on it, so it is one constant rather than two spellings that could drift.
144
+ */
145
+ export const UNISSUED_REF_REFUSAL = 'is not a ref Reticle issued';
146
+ /**
147
+ * Why an act refused a `ref` that does not have the minted shape.
148
+ *
149
+ * The browser's ref table answers a miss with null, and an unknown string and a detached element
150
+ * reached the same refusal: "that ref is stale: refs are invalidated whenever the DOM re-renders".
151
+ * For `find:aria-label=Open menu` — never a ref at all — that diagnosis is wrong, and the agent
152
+ * retried the same mistake. A string that cannot have been minted is answered for what it is, and
153
+ * pointed at `target`, which is what the caller was reaching for.
154
+ */
155
+ export function unissuedRefRefusal(ref) {
156
+ const max = TRANSPORT_LIMITS.MAX_REF_LENGTH;
157
+ const echoed = max >= ref.length ? ref : `${ref.slice(0, max)}…`;
158
+ return (`${JSON.stringify(echoed)} ${UNISSUED_REF_REFUSAL}; refs look like e12. To address an element ` +
159
+ 'by what it shows, pass target: { label }, { role, name }, { text } or { testid }.');
160
+ }
140
161
  /** Why a flow refused a predicate holding a ref, naming the field. */
141
162
  export function sessionRefRefusal(field) {
142
163
  return (`${field} is an element ref, which only exists in the session that minted it — ` +
@@ -184,3 +205,19 @@ export function sessionBoundField(predicate) {
184
205
  return undefined;
185
206
  }
186
207
  }
208
+ /** True when any clause of this predicate, at any depth, is a computed `compare`. */
209
+ export function computesComparison(predicate) {
210
+ if (predicate === undefined)
211
+ return false;
212
+ switch (predicate.kind) {
213
+ case PredicateKind.COMPARE:
214
+ return true;
215
+ case PredicateKind.ALL_OF:
216
+ case PredicateKind.ANY_OF:
217
+ return predicate.predicates.some(computesComparison);
218
+ case PredicateKind.NOT:
219
+ return computesComparison(predicate.predicate);
220
+ default:
221
+ return false;
222
+ }
223
+ }
@@ -19,7 +19,7 @@ import { z } from 'zod';
19
19
  import { type ElementQuery } from '../wire/types.js';
20
20
  import { ElementState } from '../wire/constants/constants.js';
21
21
  import { CompareAs, type CompareSource } from './compare-source.js';
22
- import { PredicateKind } from './consequence.js';
22
+ import { PredicateKind, SettledChannel } from './consequence.js';
23
23
  import { type PropertyAssertion } from './property-assertion.js';
24
24
  export type Predicate = {
25
25
  kind: typeof PredicateKind.ELEMENT;
@@ -51,6 +51,8 @@ export type Predicate = {
51
51
  * then both must hold — `satisfies` narrows, it never excuses.
52
52
  */
53
53
  satisfies?: PropertyAssertion;
54
+ /** Match `contains` regardless of case. Off by default: a check compares case exactly. */
55
+ ignoreCase?: boolean;
54
56
  } | {
55
57
  kind: typeof PredicateKind.NET;
56
58
  method?: string;
@@ -68,6 +70,8 @@ export type Predicate = {
68
70
  requestBodyContains?: string;
69
71
  /** JSON field match over the REQUEST body, in the style of `signal.dataMatches`. */
70
72
  requestBodyMatches?: Record<string, unknown>;
73
+ /** Repeats of this call are expected (a read over POST), so they are not a double submit. */
74
+ repeatable?: boolean;
71
75
  } | {
72
76
  kind: typeof PredicateKind.ROUTE;
73
77
  pathname?: string;
@@ -109,6 +113,7 @@ export type Predicate = {
109
113
  } | {
110
114
  kind: typeof PredicateKind.SETTLED;
111
115
  quietMs?: number;
116
+ channel?: SettledChannel;
112
117
  } | {
113
118
  kind: typeof PredicateKind.COMPARE;
114
119
  left: CompareSource;
@@ -141,6 +146,16 @@ export type Predicate = {
141
146
  * A list beside a schema is a list that drifts; a list read FROM the schema cannot.
142
147
  */
143
148
  export declare const ELEMENT_QUERY_FIELDS: readonly (keyof ElementQuery)[];
149
+ /**
150
+ * Which aliases a predicate as WRITTEN would have renamed, as `kind.from → to` (and `type → kind`).
151
+ *
152
+ * The parse itself is silent on purpose — it is a preprocess step — so this reads the same table
153
+ * to tell the caller its spelling was normalised: a forgiving parse that never says so teaches a
154
+ * spelling that only works here. Walks `allOf`/`anyOf`/`not` the way the schema does. Unknown
155
+ * fields are never guessed at: they are not in the table, so they are never reported here, and the
156
+ * schema still refuses them.
157
+ */
158
+ export declare function predicateAliasesUsed(input: unknown, depth?: number): string[];
144
159
  export declare const PredicateSchema: z.ZodType<Predicate>;
145
160
  /**
146
161
  * The fields one predicate kind accepts, as the schema itself declares them.
@@ -19,7 +19,7 @@ import { z } from 'zod';
19
19
  import { ElementQuerySchema } from '../wire/types.js';
20
20
  import { ElementState } from '../wire/constants/constants.js';
21
21
  import { CompareAs, CompareSourceSchema, sameCompareSource, } from './compare-source.js';
22
- import { PredicateKind } from './consequence.js';
22
+ import { PredicateKind, SettledChannel } from './consequence.js';
23
23
  import { propertyAssertionSchema } from './property-assertion.js';
24
24
  /**
25
25
  * Spellings an agent plausibly reaches for, mapped to the real field.
@@ -41,8 +41,21 @@ const PREDICATE_ALIASES = {
41
41
  // one — route's `contains` matches the WHOLE route (path + query + fragment), so "the URL
42
42
  // contains this" is precisely what it does — and asserting a redirect after login is the single
43
43
  // most common thing an agent reaches for here.
44
- [PredicateKind.ROUTE]: { path: 'pathname', urlContains: 'contains', url: 'contains' },
45
- [PredicateKind.NET]: { url: 'urlContains', responseBodyMatches: 'bodyMatches' },
44
+ // `pathContains` is the spelling agents reach for after writing `pathname`; it means what
45
+ // `urlContains` already means here (the route contains this), so it is the same unambiguous lift.
46
+ [PredicateKind.ROUTE]: {
47
+ path: 'pathname',
48
+ urlContains: 'contains',
49
+ url: 'contains',
50
+ pathContains: 'contains',
51
+ },
52
+ // `pathContains` on `net`: the request's URL contains it — `urlContains`, which matches the path
53
+ // the agent meant plus anything else in the URL, exactly as the route alias above does.
54
+ [PredicateKind.NET]: {
55
+ url: 'urlContains',
56
+ responseBodyMatches: 'bodyMatches',
57
+ pathContains: 'urlContains',
58
+ },
46
59
  // `textContains` on a `console` predicate: the reporter who hit the missing matcher reached for
47
60
  // it first, by analogy with `net { urlContains }` — and that parallel is exactly right, since
48
61
  // both mean "this entry must contain this substring". Accepted as an alias for `contains`.
@@ -52,13 +65,14 @@ const PREDICATE_ALIASES = {
52
65
  // no other meaning here. Observed twice in one drive on a real app, and each rejection cost a round
53
66
  // trip AND produced no verdict — a composite is what an agent reaches for precisely when it has two
54
67
  // things to prove at once, so failing it is expensive at the worst moment.
55
- [PredicateKind.ALL_OF]: { of: 'predicates' },
56
- [PredicateKind.ANY_OF]: { of: 'predicates' },
68
+ // The kind's own name as the key (`{ allOf: [...] }`) is the shorthand `inferKind` reads.
69
+ [PredicateKind.ALL_OF]: { of: 'predicates', allOf: 'predicates' },
70
+ [PredicateKind.ANY_OF]: { of: 'predicates', anyOf: 'predicates' },
57
71
  // `of` on `not` for the same reason it is accepted on the composites above — an agent that learned
58
72
  // the spelling one line earlier applies it to the third composite, and `not` was the one that
59
73
  // rejected it. The refusal did name `predicate`, but naming a field still costs the round trip
60
74
  // that produced no verdict, and the guess is unambiguous: `not` has exactly one child.
61
- [PredicateKind.NOT]: { of: 'predicate' },
75
+ [PredicateKind.NOT]: { of: 'predicate', not: 'predicate' },
62
76
  };
63
77
  /**
64
78
  * The word half the assertion world spells `kind`.
@@ -92,12 +106,136 @@ function renameKindSpelling(obj) {
92
106
  delete out[KIND_SPELLING];
93
107
  return out;
94
108
  }
109
+ /**
110
+ * Keys that are also the name of a kind. `{ text: "Saved" }` and `{ allOf: [...] }` are what agents
111
+ * write when they leave out `kind`. The key names the kind, and the alias table maps it to a field.
112
+ */
113
+ const KIND_NAMED_KEYS = {
114
+ text: PredicateKind.TEXT,
115
+ allOf: PredicateKind.ALL_OF,
116
+ anyOf: PredicateKind.ANY_OF,
117
+ not: PredicateKind.NOT,
118
+ };
119
+ /** Each kind and every key it takes: its fields, its aliases and, for `element`, flat query fields. */
120
+ let keysByKind;
121
+ function keysOfEachKind() {
122
+ if (keysByKind !== undefined) {
123
+ return keysByKind;
124
+ }
125
+ const out = new Map();
126
+ for (const option of predicateUnion().options) {
127
+ const shape = option.shape;
128
+ const kind = shape['kind']._def.value;
129
+ const flat = PredicateKind.ELEMENT === kind ? ELEMENT_QUERY_FIELDS : [];
130
+ out.set(kind, new Set([
131
+ ...Object.keys(shape).filter((key) => 'kind' !== key),
132
+ ...Object.keys(PREDICATE_ALIASES[kind] ?? {}),
133
+ ...flat,
134
+ ]));
135
+ }
136
+ keysByKind = out;
137
+ return out;
138
+ }
139
+ const writtenKeys = (obj) => Object.keys(obj).filter((key) => obj[key] !== undefined);
140
+ /**
141
+ * The kind of a predicate written with no `kind`, when its keys fit exactly one kind.
142
+ *
143
+ * A key that names a kind (`text`, `allOf`, `anyOf`, `not`) selects that kind, if the kind takes
144
+ * every other key too. Otherwise the kind is the only one that takes every key. Keys that fit two
145
+ * kinds (`name` is on `signal` and `animation`) or none give no kind, and the schema refuses them.
146
+ * This only supplies `kind`: the predicate that results is the one the explicit form gives.
147
+ */
148
+ function inferKind(obj) {
149
+ const keys = writtenKeys(obj);
150
+ if (0 === keys.length) {
151
+ return undefined;
152
+ }
153
+ const kinds = keysOfEachKind();
154
+ const takesAll = (kind) => {
155
+ const accepted = kinds.get(kind);
156
+ return accepted !== undefined && keys.every((key) => accepted.has(key));
157
+ };
158
+ const named = keys.flatMap((key) => {
159
+ const kind = KIND_NAMED_KEYS[key];
160
+ return kind === undefined ? [] : [kind];
161
+ });
162
+ if (1 < named.length) {
163
+ return undefined;
164
+ }
165
+ const [byName] = named;
166
+ if (byName !== undefined) {
167
+ return takesAll(byName) ? byName : undefined;
168
+ }
169
+ const fits = [...kinds.keys()].filter(takesAll);
170
+ return 1 === fits.length ? fits[0] : undefined;
171
+ }
172
+ /** The kind inferred for a predicate written with neither `kind` nor `type`, if any. */
173
+ function kindToInfer(given) {
174
+ const renamed = renameKindSpelling(given);
175
+ return renamed['kind'] === undefined ? inferKind(renamed) : undefined;
176
+ }
177
+ /** `type` renamed to `kind`, then the kind inferred from the keys when neither was written. */
178
+ function withKind(given) {
179
+ const renamed = renameKindSpelling(given);
180
+ const kind = kindToInfer(given);
181
+ return kind === undefined ? renamed : { ...renamed, kind };
182
+ }
183
+ /** Why a predicate with no `kind` was refused: the keys it had, and the kinds there are. */
184
+ function noKindRefusal(obj) {
185
+ const keys = writtenKeys(obj).map((key) => `\`${key}\``);
186
+ return (`this predicate has no \`kind\`, and its keys (${keys.length > 0 ? keys.join(', ') : 'none'}) ` +
187
+ `do not fit exactly one kind. Add \`kind\`: one of ${[...keysOfEachKind().keys()].join(', ')}`);
188
+ }
189
+ /**
190
+ * Which aliases a predicate as WRITTEN would have renamed, as `kind.from → to` (and `type → kind`).
191
+ *
192
+ * The parse itself is silent on purpose — it is a preprocess step — so this reads the same table
193
+ * to tell the caller its spelling was normalised: a forgiving parse that never says so teaches a
194
+ * spelling that only works here. Walks `allOf`/`anyOf`/`not` the way the schema does. Unknown
195
+ * fields are never guessed at: they are not in the table, so they are never reported here, and the
196
+ * schema still refuses them.
197
+ */
198
+ export function predicateAliasesUsed(input, depth = 0) {
199
+ if (depth > 8 || typeof input !== 'object' || null === input || Array.isArray(input))
200
+ return [];
201
+ const given = input;
202
+ const used = [];
203
+ if (given['kind'] === undefined && 'string' === typeof given[KIND_SPELLING]) {
204
+ used.push(`${KIND_SPELLING} → kind`);
205
+ }
206
+ const inferred = kindToInfer(given);
207
+ if (inferred !== undefined) {
208
+ used.push(`(no kind) → kind: "${inferred}"`);
209
+ }
210
+ const obj = withKind(given);
211
+ const kind = 'string' === typeof obj['kind'] ? obj['kind'] : '';
212
+ for (const [from, to] of Object.entries(PREDICATE_ALIASES[kind] ?? {})) {
213
+ if (obj[from] !== undefined && obj[to] === undefined)
214
+ used.push(`${kind}.${from} → ${to}`);
215
+ }
216
+ if (PredicateKind.ELEMENT === kind && obj['query'] === undefined) {
217
+ for (const field of ELEMENT_QUERY_FIELDS) {
218
+ if (obj[field] !== undefined)
219
+ used.push(`element.${field} → query.${field}`);
220
+ }
221
+ }
222
+ for (const field of ['predicates', 'of', 'predicate', 'allOf', 'anyOf', 'not']) {
223
+ const child = obj[field];
224
+ for (const nested of Array.isArray(child) ? child : [child]) {
225
+ used.push(...predicateAliasesUsed(nested, depth + 1));
226
+ }
227
+ }
228
+ return used;
229
+ }
95
230
  /** Rename known aliases before parse; an explicit canonical key always wins. */
96
- function applyPredicateAliases(input) {
231
+ function applyPredicateAliases(input, ctx) {
97
232
  if (typeof input !== 'object' || null === input || Array.isArray(input))
98
233
  return input;
99
234
  const given = input;
100
- const obj = renameKindSpelling(given);
235
+ const obj = withKind(given);
236
+ if (obj['kind'] === undefined) {
237
+ ctx.addIssue({ code: z.ZodIssueCode.custom, message: noKindRefusal(obj) });
238
+ }
101
239
  const kind = 'string' === typeof obj['kind'] ? obj['kind'] : '';
102
240
  const aliases = PREDICATE_ALIASES[kind];
103
241
  let out = obj;
@@ -114,10 +252,13 @@ function applyPredicateAliases(input) {
114
252
  return PredicateKind.ELEMENT === kind ? liftElementQuery(out) : out;
115
253
  }
116
254
  /**
117
- * Fold flat query fields into `query`. An explicit `query` wins outright — a caller that supplied
118
- * both told us which one it meant, and merging the two would invent a locator neither side wrote.
255
+ * Fold flat query fields into `query`. With an explicit `query` nothing is folded and nothing is
256
+ * dropped: merging would invent a locator neither side wrote, and dropping a flat `value` checked
257
+ * only that the element exists. The strict schema refuses the flat field instead, by name.
119
258
  */
120
259
  function liftElementQuery(obj) {
260
+ if (obj['query'] !== undefined)
261
+ return obj;
121
262
  const loose = ELEMENT_QUERY_FIELDS.filter((field) => obj[field] !== undefined);
122
263
  if (0 === loose.length)
123
264
  return obj;
@@ -127,8 +268,7 @@ function liftElementQuery(obj) {
127
268
  query[field] = out[field];
128
269
  delete out[field];
129
270
  }
130
- if (out['query'] === undefined)
131
- out['query'] = query;
271
+ out['query'] = query;
132
272
  return out;
133
273
  }
134
274
  /**
@@ -163,6 +303,11 @@ function predicateUnion() {
163
303
  scope: z.string().optional(),
164
304
  self: z.boolean().optional(),
165
305
  satisfies: propertyAssertionSchema.optional(),
306
+ /**
307
+ * Match `contains` regardless of case. Off by default: a check that passed "Saved Priya"
308
+ * against "Saved priya" could never catch a capitalisation defect.
309
+ */
310
+ ignoreCase: z.boolean().optional(),
166
311
  })
167
312
  .strict(),
168
313
  z
@@ -242,6 +387,14 @@ function predicateUnion() {
242
387
  * instead of reporting a mismatch: a redacted field is unknown, not different.
243
388
  */
244
389
  requestBodyMatches: z.record(z.string(), z.unknown()).optional(),
390
+ /**
391
+ * The endpoint READS, so running twice in one window is not a double submit (#1353). GraphQL
392
+ * queries, tRPC batches, query buses and read Server Actions all read over POST, and React
393
+ * StrictMode runs the effect behind them twice in development. Scoped to this verdict and to
394
+ * the duplicate rule only: the request is still waited for and still counted. Needs a
395
+ * non-empty `urlContains`, and honours `method` when one is given (`checkRepeatableShape`).
396
+ */
397
+ repeatable: z.boolean().optional(),
245
398
  })
246
399
  .strict(),
247
400
  z
@@ -308,6 +461,7 @@ function predicateUnion() {
308
461
  .object({
309
462
  kind: z.literal(PredicateKind.SETTLED),
310
463
  quietMs: z.number().positive().optional(),
464
+ channel: z.enum([SettledChannel.NETWORK, SettledChannel.APP]).optional(),
311
465
  })
312
466
  .strict(),
313
467
  z
@@ -356,10 +510,14 @@ function predicateUnion() {
356
510
  function checkPredicateShape(predicate, ctx) {
357
511
  // Structural and narrowed HERE, not in the signature: the refinement runs on the union zod
358
512
  // inferred, whose optional fields are spelled `| undefined`, and naming any concrete type in the
359
- // parameter makes the overload unresolvable. Only the four fields this reads are looked at.
513
+ // parameter makes the overload unresolvable. Only the fields this reads are looked at.
360
514
  if ('object' !== typeof predicate || null === predicate)
361
515
  return;
362
516
  const p = predicate;
517
+ if (PredicateKind.NET === p.kind) {
518
+ checkRepeatableShape(p.repeatable, p.urlContains, ctx);
519
+ return;
520
+ }
363
521
  if (PredicateKind.COMPARE === p.kind) {
364
522
  checkCompareShape(predicate, ctx);
365
523
  return;
@@ -383,6 +541,23 @@ function checkPredicateShape(predicate, ctx) {
383
541
  });
384
542
  }
385
543
  }
544
+ /**
545
+ * `repeatable` exempts the endpoint it names from `duplicate-request`, so it has to name one. On a
546
+ * clause with no `urlContains` it would exempt every request in the window, and two identical
547
+ * writes, a real double submit, would pass as reads (#1353).
548
+ */
549
+ function checkRepeatableShape(repeatable, urlContains, ctx) {
550
+ if (true !== repeatable)
551
+ return;
552
+ if ('string' === typeof urlContains && urlContains.trim().length > 0)
553
+ return;
554
+ ctx.addIssue({
555
+ code: z.ZodIssueCode.custom,
556
+ message: '`repeatable: true` needs a non-empty `urlContains` naming the read endpoint, for example ' +
557
+ '`{ kind: "net", method: "POST", urlContains: "/graphql", repeatable: true }`. Without one it ' +
558
+ 'would excuse every request in the window from duplicate-request, a real double submit included',
559
+ });
560
+ }
386
561
  /**
387
562
  * The two ways a `compare` can be written so that it cannot fail, refused before it can report `yes`.
388
563
  *
@@ -94,11 +94,11 @@ export declare const propertyAssertionSchema: z.ZodDiscriminatedUnion<"property"
94
94
  property: z.ZodLiteral<"matchesPattern">;
95
95
  pattern: z.ZodString;
96
96
  }, "strict", z.ZodTypeAny, {
97
- property: "matchesPattern";
98
97
  pattern: string;
99
- }, {
100
98
  property: "matchesPattern";
99
+ }, {
101
100
  pattern: string;
101
+ property: "matchesPattern";
102
102
  }>, z.ZodObject<{
103
103
  property: z.ZodLiteral<"type">;
104
104
  is: z.ZodEnum<["string", "number", "boolean", "array", "object"]>;