@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.
- package/dist/artifacts/flow-composition.d.ts +3 -2
- package/dist/artifacts/flow-constants.d.ts +49 -2
- package/dist/artifacts/flow-constants.js +49 -2
- package/dist/artifacts/flow-expect-flat.d.ts +260 -0
- package/dist/artifacts/flow-expect-flat.js +284 -0
- package/dist/artifacts/flow-mutation-target.d.ts +0 -1
- package/dist/artifacts/flow-mutation-target.js +26 -2
- package/dist/artifacts/flow-step-tool.d.ts +2 -0
- package/dist/artifacts/flow-types.d.ts +1074 -1228
- package/dist/artifacts/flow-types.js +96 -140
- package/dist/artifacts/impact.d.ts +48 -20
- package/dist/artifacts/impact.js +11 -0
- package/dist/artifacts/journal.d.ts +33 -6
- package/dist/artifacts/journal.js +13 -0
- package/dist/hooks/hook-events.d.ts +18 -18
- package/dist/hud-entry.d.ts +9 -0
- package/dist/hud-entry.js +9 -0
- package/dist/identity/source-constants.d.ts +11 -0
- package/dist/identity/source-constants.js +11 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +24 -1
- package/dist/onboarding.d.ts +2 -2
- package/dist/realm/registry.d.ts +0 -8
- package/dist/realm/registry.js +1 -11
- package/dist/schema/event-message.json +3 -1
- package/dist/schema/event-payloads.json +69 -0
- package/dist/schema/event-type.json +3 -1
- package/dist/schema/reticle-event.json +3 -1
- package/dist/schema/reticle-message.json +3 -1
- package/dist/source-constants.cjs +1 -0
- package/dist/source-constants.d.cts +1 -0
- package/dist/telemetry-feedback.d.ts +6 -6
- package/dist/telemetry-refusal.d.ts +2 -2
- package/dist/telemetry-session.d.ts +25 -2
- package/dist/telemetry-session.js +13 -0
- package/dist/telemetry.d.ts +121 -94
- package/dist/verdict/consequence.d.ts +10 -0
- package/dist/verdict/consequence.js +13 -0
- package/dist/verdict/intent.d.ts +36 -12
- package/dist/verdict/intent.js +66 -10
- package/dist/verdict/predicate-tree.d.ts +47 -0
- package/dist/verdict/predicate-tree.js +146 -0
- package/dist/verdict/predicate.d.ts +129 -0
- package/dist/verdict/predicate.js +394 -0
- package/dist/verdict/property-assertion.d.ts +191 -0
- package/dist/verdict/property-assertion.js +42 -0
- package/dist/verdict/security.js +16 -4
- package/dist/verdict/verdict-attribution.d.ts +52 -0
- package/dist/verdict/verdict-attribution.js +87 -0
- package/dist/verdict/verification-run.d.ts +98 -84
- package/dist/verdict/verification-run.js +8 -1
- package/dist/verdict/verified-constants.d.ts +9 -0
- package/dist/verdict/verified-constants.js +9 -0
- package/dist/wire/constants/constants.d.ts +20 -98
- package/dist/wire/constants/constants.js +22 -97
- package/dist/wire/constants/discovery.d.ts +25 -0
- package/dist/wire/constants/discovery.js +25 -0
- package/dist/wire/constants/event-types.d.ts +122 -0
- package/dist/wire/constants/event-types.js +121 -0
- package/dist/wire/constants/hud-controls.d.ts +19 -0
- package/dist/wire/constants/hud-controls.js +95 -0
- package/dist/wire/constants/hud-use.d.ts +27 -0
- package/dist/wire/constants/hud-use.js +24 -0
- package/dist/wire/constants/session-constants.d.ts +10 -0
- package/dist/wire/constants/session-constants.js +10 -0
- package/dist/wire/event-payloads.d.ts +66 -10
- package/dist/wire/event-payloads.js +18 -1
- package/dist/wire/messages.d.ts +89 -48
- package/dist/wire/messages.js +17 -0
- package/dist/wire/net.d.ts +18 -0
- package/dist/wire/net.js +24 -0
- package/dist/wire/state-select.d.ts +2 -1
- package/dist/wire/state-select.js +56 -3
- package/dist/wire/toon.js +28 -7
- package/dist/wire/types.d.ts +91 -66
- package/dist/wire/types.js +23 -1
- package/package.json +5 -1
|
@@ -0,0 +1,394 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The predicate: what a caller can declare, as a shape that crosses the wire.
|
|
3
|
+
*
|
|
4
|
+
* This is the CONTRACT half of the predicate language, and it is here for the reason everything
|
|
5
|
+
* else in this package is: a message that crosses browser ↔ bridge ↔ agent is defined in core, and
|
|
6
|
+
* a predicate is now one. `FlowStep.expect` is a `Predicate`, which means a saved flow file carries
|
|
7
|
+
* one, which means core has to be able to parse what it reads off disk.
|
|
8
|
+
*
|
|
9
|
+
* It was in `@reticlehq/engine` and it was already half here: `PredicateKind` has always lived in
|
|
10
|
+
* `verdict/consequence.ts`, so the engine's schema imported its own vocabulary back from its parent.
|
|
11
|
+
* This finishes that migration rather than starting one.
|
|
12
|
+
*
|
|
13
|
+
* WHAT DID NOT COME WITH IT, and the line is deliberate. Evaluation stays in the engine:
|
|
14
|
+
* `satisfiesProperty`, the residual-query checks, the grammar and nested-key introspection. Core is
|
|
15
|
+
* the contract, not the reasoning. A reader looking for "what may I write" is in the right file; a
|
|
16
|
+
* reader looking for "what does it decide" is one package out.
|
|
17
|
+
*/
|
|
18
|
+
import { z } from 'zod';
|
|
19
|
+
import { ElementQuerySchema } from '../wire/types.js';
|
|
20
|
+
import { ElementState } from '../wire/constants/constants.js';
|
|
21
|
+
import { PredicateKind } from './consequence.js';
|
|
22
|
+
import { propertyAssertionSchema } from './property-assertion.js';
|
|
23
|
+
/**
|
|
24
|
+
* Spellings an agent plausibly reaches for, mapped to the real field.
|
|
25
|
+
*
|
|
26
|
+
* `route` spells its field `pathname` while `state`, in the same union, spells its `path`. Every one
|
|
27
|
+
* of these was silently DROPPED before, and because these kinds have all-optional fields, dropping
|
|
28
|
+
* the only key supplied left a predicate that asserts nothing and passes on anything.
|
|
29
|
+
*/
|
|
30
|
+
const PREDICATE_ALIASES = {
|
|
31
|
+
// `text`/`value`/`query` on a `text` predicate: the kind is called "text", so `text:` is the first
|
|
32
|
+
// thing anyone writes for it, `value` follows from the element query's own `value` field, and
|
|
33
|
+
// `query` from `element`'s nested locator, the spelling agents reach for after `reticle_query`.
|
|
34
|
+
// All were hard rejections, and a rejected predicate produces NO verdict at all — the drive ends
|
|
35
|
+
// with nothing rather than with a failure, which is the worst outcome of the three.
|
|
36
|
+
[PredicateKind.TEXT]: { text: 'contains', value: 'contains', query: 'contains' },
|
|
37
|
+
// `urlContains`/`url` reported from the field: an agent that had just written
|
|
38
|
+
// `net { urlContains }` applied the same word to `route`, which spells it `contains`, and got
|
|
39
|
+
// `unrecognized_keys` with no list of what would have worked. The parallel it assumed is a fair
|
|
40
|
+
// one — route's `contains` matches the WHOLE route (path + query + fragment), so "the URL
|
|
41
|
+
// contains this" is precisely what it does — and asserting a redirect after login is the single
|
|
42
|
+
// most common thing an agent reaches for here.
|
|
43
|
+
[PredicateKind.ROUTE]: { path: 'pathname', urlContains: 'contains', url: 'contains' },
|
|
44
|
+
[PredicateKind.NET]: { url: 'urlContains', responseBodyMatches: 'bodyMatches' },
|
|
45
|
+
// `textContains` on a `console` predicate: the reporter who hit the missing matcher reached for
|
|
46
|
+
// it first, by analogy with `net { urlContains }` — and that parallel is exactly right, since
|
|
47
|
+
// both mean "this entry must contain this substring". Accepted as an alias for `contains`.
|
|
48
|
+
[PredicateKind.CONSOLE]: { textContains: 'contains' },
|
|
49
|
+
[PredicateKind.SIGNAL]: { data: 'dataMatches' },
|
|
50
|
+
// `of` on a composite: it reads naturally, several assertion libraries spell it that way, and it has
|
|
51
|
+
// no other meaning here. Observed twice in one drive on a real app, and each rejection cost a round
|
|
52
|
+
// trip AND produced no verdict — a composite is what an agent reaches for precisely when it has two
|
|
53
|
+
// things to prove at once, so failing it is expensive at the worst moment.
|
|
54
|
+
[PredicateKind.ALL_OF]: { of: 'predicates' },
|
|
55
|
+
[PredicateKind.ANY_OF]: { of: 'predicates' },
|
|
56
|
+
// `of` on `not` for the same reason it is accepted on the composites above — an agent that learned
|
|
57
|
+
// the spelling one line earlier applies it to the third composite, and `not` was the one that
|
|
58
|
+
// rejected it. The refusal did name `predicate`, but naming a field still costs the round trip
|
|
59
|
+
// that produced no verdict, and the guess is unambiguous: `not` has exactly one child.
|
|
60
|
+
[PredicateKind.NOT]: { of: 'predicate' },
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* The word half the assertion world spells `kind`.
|
|
64
|
+
*
|
|
65
|
+
* A discriminated union rejects `{ type: "text", ... }` with "Invalid discriminator value" on a field
|
|
66
|
+
* the caller never wrote, so the reply reads as being about `kind` — which is absent — and never
|
|
67
|
+
* says the word `type`. Observed on a live drive as the first rung of a ladder: one field name
|
|
68
|
+
* learned per rejected call, each costing a verdict. No predicate kind declares a `type` field, so
|
|
69
|
+
* lifting it is unambiguous, and an explicit `kind` still wins.
|
|
70
|
+
*/
|
|
71
|
+
const KIND_SPELLING = 'type';
|
|
72
|
+
/**
|
|
73
|
+
* Element-query fields an agent writes FLAT on an `element` predicate instead of nested under
|
|
74
|
+
* `query`. `reticle_query` takes exactly these at the top level, so an agent that has just located
|
|
75
|
+
* something writes the same words again when it asserts on it — and got `query: Required` plus an
|
|
76
|
+
* `unknown field` list for its trouble. Lifting them is unambiguous: they have no other meaning on
|
|
77
|
+
* this kind.
|
|
78
|
+
*/
|
|
79
|
+
const ELEMENT_QUERY_FIELDS = [
|
|
80
|
+
'by',
|
|
81
|
+
'value',
|
|
82
|
+
'role',
|
|
83
|
+
'name',
|
|
84
|
+
'text',
|
|
85
|
+
'label',
|
|
86
|
+
'placeholder',
|
|
87
|
+
'testid',
|
|
88
|
+
'alt',
|
|
89
|
+
'component',
|
|
90
|
+
];
|
|
91
|
+
/** `type` read as the discriminator when — and only when — `kind` is absent. */
|
|
92
|
+
function renameKindSpelling(obj) {
|
|
93
|
+
if (obj['kind'] !== undefined || 'string' !== typeof obj[KIND_SPELLING])
|
|
94
|
+
return obj;
|
|
95
|
+
const out = { ...obj, kind: obj[KIND_SPELLING] };
|
|
96
|
+
delete out[KIND_SPELLING];
|
|
97
|
+
return out;
|
|
98
|
+
}
|
|
99
|
+
/** Rename known aliases before parse; an explicit canonical key always wins. */
|
|
100
|
+
function applyPredicateAliases(input) {
|
|
101
|
+
if (typeof input !== 'object' || null === input || Array.isArray(input))
|
|
102
|
+
return input;
|
|
103
|
+
const given = input;
|
|
104
|
+
const obj = renameKindSpelling(given);
|
|
105
|
+
const kind = 'string' === typeof obj['kind'] ? obj['kind'] : '';
|
|
106
|
+
const aliases = PREDICATE_ALIASES[kind];
|
|
107
|
+
let out = obj;
|
|
108
|
+
if (aliases !== undefined) {
|
|
109
|
+
out = { ...obj };
|
|
110
|
+
for (const [from, to] of Object.entries(aliases)) {
|
|
111
|
+
if (out[from] === undefined)
|
|
112
|
+
continue;
|
|
113
|
+
if (out[to] === undefined)
|
|
114
|
+
out[to] = out[from];
|
|
115
|
+
delete out[from];
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return PredicateKind.ELEMENT === kind ? liftElementQuery(out) : out;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Fold flat query fields into `query`. An explicit `query` wins outright — a caller that supplied
|
|
122
|
+
* both told us which one it meant, and merging the two would invent a locator neither side wrote.
|
|
123
|
+
*/
|
|
124
|
+
function liftElementQuery(obj) {
|
|
125
|
+
const loose = ELEMENT_QUERY_FIELDS.filter((field) => obj[field] !== undefined);
|
|
126
|
+
if (0 === loose.length)
|
|
127
|
+
return obj;
|
|
128
|
+
const out = { ...obj };
|
|
129
|
+
const query = {};
|
|
130
|
+
for (const field of loose) {
|
|
131
|
+
query[field] = out[field];
|
|
132
|
+
delete out[field];
|
|
133
|
+
}
|
|
134
|
+
if (out['query'] === undefined)
|
|
135
|
+
out['query'] = query;
|
|
136
|
+
return out;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Strict on every branch. A key that is nobody's spelling is now a schema error naming it, instead of
|
|
140
|
+
* a stripped field and a green — see predicate-strict.test.ts for the MCP session that found this.
|
|
141
|
+
*
|
|
142
|
+
* Built on demand rather than at module scope: the `allOf`/`anyOf`/`not` branches reference
|
|
143
|
+
* `PredicateSchema` itself, which does not exist yet while this module is initialising. Calling it
|
|
144
|
+
* after init is what makes the union introspectable — see `predicateFieldsFor`.
|
|
145
|
+
*/
|
|
146
|
+
function predicateUnion() {
|
|
147
|
+
return z.discriminatedUnion('kind', [
|
|
148
|
+
z
|
|
149
|
+
.object({
|
|
150
|
+
kind: z.literal(PredicateKind.ELEMENT),
|
|
151
|
+
query: ElementQuerySchema,
|
|
152
|
+
state: z.nativeEnum(ElementState).optional(),
|
|
153
|
+
absent: z.boolean().optional(),
|
|
154
|
+
})
|
|
155
|
+
.strict(),
|
|
156
|
+
z
|
|
157
|
+
.object({
|
|
158
|
+
kind: z.literal(PredicateKind.TEXT),
|
|
159
|
+
/**
|
|
160
|
+
* Optional ONLY because `satisfies` can carry the claim instead — see the refinement below,
|
|
161
|
+
* which refuses a text predicate that names neither. A `text` predicate with nothing to
|
|
162
|
+
* assert resolves to "some element, some text" and passes on every page that has one.
|
|
163
|
+
*/
|
|
164
|
+
contains: z.string().optional(),
|
|
165
|
+
visible: z.boolean().optional(),
|
|
166
|
+
absent: z.boolean().optional(),
|
|
167
|
+
scope: z.string().optional(),
|
|
168
|
+
self: z.boolean().optional(),
|
|
169
|
+
satisfies: propertyAssertionSchema.optional(),
|
|
170
|
+
})
|
|
171
|
+
.strict(),
|
|
172
|
+
z
|
|
173
|
+
.object({
|
|
174
|
+
kind: z.literal(PredicateKind.NET),
|
|
175
|
+
method: z.string().optional(),
|
|
176
|
+
urlContains: z.string().optional(),
|
|
177
|
+
status: z.number().optional(),
|
|
178
|
+
ok: z.boolean().optional(),
|
|
179
|
+
since: z.number().optional(),
|
|
180
|
+
count: z.number().int().nonnegative().optional(),
|
|
181
|
+
/**
|
|
182
|
+
* A substring the call's RESPONSE body must contain - what the server answered.
|
|
183
|
+
*
|
|
184
|
+
* The only channel that can catch a UI echoing its own input instead of the server's answer.
|
|
185
|
+
* Reported from a real payments UI: a refund posted `{"amount":"1187.01"}`, the server read it
|
|
186
|
+
* as paise and answered 200 with `{"refunded":11.87}`, and the page displayed the number the
|
|
187
|
+
* user had typed. Request fired, exactly once, status 200, console clean, page settled — every
|
|
188
|
+
* assertable channel green on a hundred-fold wrong refund, so the verdict was `yes`.
|
|
189
|
+
*
|
|
190
|
+
* A substring rather than a JSON path, deliberately: `"refunded":11.87` is the whole assertion
|
|
191
|
+
* for the money case, it needs no schema for the body, and it works the same on JSON, form
|
|
192
|
+
* encoding and plain text. A path-and-equals form can be added later if a real case needs one;
|
|
193
|
+
* this is the shape that turns "a blob I read" into a verdict.
|
|
194
|
+
*
|
|
195
|
+
* Requires body capture (`reticle({ captureNetworkBodies: true })`), and says so when the body
|
|
196
|
+
* was never recorded rather than reporting an ordinary mismatch.
|
|
197
|
+
*/
|
|
198
|
+
bodyContains: z.string().min(1).optional(),
|
|
199
|
+
/**
|
|
200
|
+
* Shallow JSON match over the RESPONSE body, keyed like `signal.dataMatches` and sharing its
|
|
201
|
+
* `matchValue` operators (`*`, `$gte`, `$contains`, …) — the field-level half of
|
|
202
|
+
* `bodyContains` (#987).
|
|
203
|
+
*
|
|
204
|
+
* `bodyContains` is a substring test, and the comment above says why that shape was chosen.
|
|
205
|
+
* It leaves one assertion unsayable: "this FIELD holds this value". Reported from the field
|
|
206
|
+
* as the only false green in that export — `bodyContains: "completed"` returned
|
|
207
|
+
* `verified: "yes"` for a job whose status was `queued`, because the body carried
|
|
208
|
+
* `"completedAt": null` and the needle matched the KEY. An enum state in a JSON response is
|
|
209
|
+
* the natural reach for a substring and the one thing a substring cannot decide:
|
|
210
|
+
* `completed`/`completedAt`, `success`/`successRate`, `sent`/`unsent`.
|
|
211
|
+
*
|
|
212
|
+
* `{ bodyMatches: { status: "completed" } }` cannot be satisfied by a key name, by a longer
|
|
213
|
+
* sibling value, or by key order, whitespace and serialisation — all of which a substring
|
|
214
|
+
* answers to. Use `bodyContains` for a non-JSON body, or when the substring IS the claim.
|
|
215
|
+
*
|
|
216
|
+
* A field whose captured value was REDACTED cannot be matched, and the verdict says so
|
|
217
|
+
* instead of reporting a mismatch: a redacted field is unknown, not different.
|
|
218
|
+
*/
|
|
219
|
+
bodyMatches: z.record(z.string(), z.unknown()).optional(),
|
|
220
|
+
/**
|
|
221
|
+
* A substring the REQUEST body must contain — the other half of `bodyContains`.
|
|
222
|
+
*
|
|
223
|
+
* `bodyContains` deliberately searches only the response, and the comment above says why:
|
|
224
|
+
* searching the request too would let it pass on the very defect it exists to catch. That
|
|
225
|
+
* reasoning is sound and it leaves a real gap. For a filter, a search or a form, the thing
|
|
226
|
+
* under test IS the outgoing payload: "applying this filter actually sends it" had no
|
|
227
|
+
* verdict at all, only `reticle_network { bodies: true }` and a human reading `requestBody`
|
|
228
|
+
* by eye (#798).
|
|
229
|
+
*
|
|
230
|
+
* A separate field rather than a mode on `bodyContains`, so neither assertion can ever be
|
|
231
|
+
* satisfied by the wrong half of the exchange.
|
|
232
|
+
*
|
|
233
|
+
* Requires body capture, and says so when the request body was never recorded rather than
|
|
234
|
+
* reporting an ordinary mismatch.
|
|
235
|
+
*/
|
|
236
|
+
requestBodyContains: z.string().min(1).optional(),
|
|
237
|
+
/**
|
|
238
|
+
* Shallow JSON match over the REQUEST body, keyed like `signal.dataMatches` and sharing its
|
|
239
|
+
* `matchValue` operators (`*`, `$gte`, `$contains`, …).
|
|
240
|
+
*
|
|
241
|
+
* `{ requestBodyMatches: { filter: "manual_review" } }` is the one-call verdict for "the UI
|
|
242
|
+
* put the selected value into the payload", and it does not care about key order,
|
|
243
|
+
* whitespace or how the client serialised the object — all of which a substring does.
|
|
244
|
+
*
|
|
245
|
+
* A field whose captured value was REDACTED cannot be matched, and the verdict says so
|
|
246
|
+
* instead of reporting a mismatch: a redacted field is unknown, not different.
|
|
247
|
+
*/
|
|
248
|
+
requestBodyMatches: z.record(z.string(), z.unknown()).optional(),
|
|
249
|
+
})
|
|
250
|
+
.strict(),
|
|
251
|
+
z
|
|
252
|
+
.object({
|
|
253
|
+
kind: z.literal(PredicateKind.ROUTE),
|
|
254
|
+
pathname: z.string().optional(),
|
|
255
|
+
contains: z.string().optional(),
|
|
256
|
+
since: z.number().optional(),
|
|
257
|
+
})
|
|
258
|
+
.strict(),
|
|
259
|
+
z
|
|
260
|
+
.object({
|
|
261
|
+
kind: z.literal(PredicateKind.CONSOLE),
|
|
262
|
+
level: z.string().optional(),
|
|
263
|
+
contains: z.string().min(1).optional(),
|
|
264
|
+
absent: z.boolean().optional(),
|
|
265
|
+
since: z.number().optional(),
|
|
266
|
+
})
|
|
267
|
+
.strict(),
|
|
268
|
+
z
|
|
269
|
+
.object({
|
|
270
|
+
kind: z.literal(PredicateKind.ANIMATION),
|
|
271
|
+
name: z.string().optional(),
|
|
272
|
+
target: z.string().optional(),
|
|
273
|
+
completed: z.boolean().optional(),
|
|
274
|
+
since: z.number().optional(),
|
|
275
|
+
})
|
|
276
|
+
.strict(),
|
|
277
|
+
z
|
|
278
|
+
.object({
|
|
279
|
+
kind: z.literal(PredicateKind.SIGNAL),
|
|
280
|
+
name: z.string().optional(),
|
|
281
|
+
dataMatches: z.record(z.unknown()).optional(),
|
|
282
|
+
/**
|
|
283
|
+
* Exact number of matching signals since the action — presence becomes cardinality.
|
|
284
|
+
*
|
|
285
|
+
* The double-fire is the defect no state-only oracle can see: a handler wired twice fires
|
|
286
|
+
* the signal twice, the store ends up in the right shape either way, and a presence check
|
|
287
|
+
* is green on both. The wrong-name variant is the same blind spot from the other side — the
|
|
288
|
+
* intended signal fires once while a mistyped sibling fires alongside it, and only a count
|
|
289
|
+
* scoped to the matched name tells the two apart. Omit = presence (≥1); `0` asserts the
|
|
290
|
+
* signal never fired, which is a claim in its own right and NOT the same as omitting it.
|
|
291
|
+
*/
|
|
292
|
+
count: z.number().int().nonnegative().optional(),
|
|
293
|
+
since: z.number().optional(),
|
|
294
|
+
})
|
|
295
|
+
.strict(),
|
|
296
|
+
z
|
|
297
|
+
.object({
|
|
298
|
+
kind: z.literal(PredicateKind.STATE),
|
|
299
|
+
store: z.string().optional(),
|
|
300
|
+
path: z.string(),
|
|
301
|
+
equals: z.unknown().optional(),
|
|
302
|
+
/*
|
|
303
|
+
* Assert a PROPERTY instead of exact bytes, for output that is right differently every run.
|
|
304
|
+
* `equals` cannot express a generated summary, a classification or a computed total; this
|
|
305
|
+
* can, and stays decidable here with no model and no network. Supplying both is allowed and
|
|
306
|
+
* both must hold.
|
|
307
|
+
*/
|
|
308
|
+
satisfies: propertyAssertionSchema.optional(),
|
|
309
|
+
})
|
|
310
|
+
.strict(),
|
|
311
|
+
z
|
|
312
|
+
.object({
|
|
313
|
+
kind: z.literal(PredicateKind.SETTLED),
|
|
314
|
+
quietMs: z.number().positive().optional(),
|
|
315
|
+
})
|
|
316
|
+
.strict(),
|
|
317
|
+
/*
|
|
318
|
+
* `.min(1)` on both combinators, because an EMPTY one is a false green and not an edge case.
|
|
319
|
+
*
|
|
320
|
+
* `allOf` over no members is vacuous truth — every member holds because there are none — so it
|
|
321
|
+
* evaluated `pass: true` and reported `verified: "yes"` for a drive that asserted nothing.
|
|
322
|
+
* Nobody writes that by hand; an agent that builds `predicates` by mapping over a list of
|
|
323
|
+
* channels to check emits it the moment the list comes back empty.
|
|
324
|
+
*
|
|
325
|
+
* `anyOf` over no members is the mirror and is merely a false RED, which is honest-ish and far
|
|
326
|
+
* cheaper. It is refused here anyway: one rule is easier to hold than two, and an empty `anyOf`
|
|
327
|
+
* is a mistake in either direction.
|
|
328
|
+
*/
|
|
329
|
+
z
|
|
330
|
+
.object({
|
|
331
|
+
kind: z.literal(PredicateKind.ALL_OF),
|
|
332
|
+
predicates: z.array(PredicateSchema).min(1),
|
|
333
|
+
})
|
|
334
|
+
.strict(),
|
|
335
|
+
z
|
|
336
|
+
.object({
|
|
337
|
+
kind: z.literal(PredicateKind.ANY_OF),
|
|
338
|
+
predicates: z.array(PredicateSchema).min(1),
|
|
339
|
+
})
|
|
340
|
+
.strict(),
|
|
341
|
+
z.object({ kind: z.literal(PredicateKind.NOT), predicate: PredicateSchema }).strict(),
|
|
342
|
+
]);
|
|
343
|
+
}
|
|
344
|
+
/*
|
|
345
|
+
* Cross-field rules, applied to every predicate INCLUDING the ones nested in a composite.
|
|
346
|
+
*
|
|
347
|
+
* They live on the union rather than on the member because `z.discriminatedUnion` takes plain
|
|
348
|
+
* objects only — wrapping one member in a refinement makes the whole union refuse to build, and
|
|
349
|
+
* `shapeForKind` walks those same options to derive the accepted-field list in a rejection message.
|
|
350
|
+
*/
|
|
351
|
+
function checkPredicateShape(predicate, ctx) {
|
|
352
|
+
// Structural and narrowed HERE, not in the signature: the refinement runs on the union zod
|
|
353
|
+
// inferred, whose optional fields are spelled `| undefined`, and naming any concrete type in the
|
|
354
|
+
// parameter makes the overload unresolvable. Only the four fields this reads are looked at.
|
|
355
|
+
if ('object' !== typeof predicate || null === predicate)
|
|
356
|
+
return;
|
|
357
|
+
const p = predicate;
|
|
358
|
+
if (PredicateKind.TEXT !== p.kind)
|
|
359
|
+
return;
|
|
360
|
+
if (undefined === p.contains && undefined === p.satisfies) {
|
|
361
|
+
ctx.addIssue({
|
|
362
|
+
code: z.ZodIssueCode.custom,
|
|
363
|
+
message: 'a text predicate must say WHAT about the text: `contains` for a substring, `satisfies` ' +
|
|
364
|
+
'for a property of it. With neither it matches any element with any text and cannot fail',
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
if (undefined !== p.satisfies && undefined === p.contains && undefined === p.scope) {
|
|
368
|
+
ctx.addIssue({
|
|
369
|
+
code: z.ZodIssueCode.custom,
|
|
370
|
+
message: '`satisfies` needs a subject: add `scope` (the element whose text is tested, with ' +
|
|
371
|
+
'`self: true` to read the scope root itself) or a `contains` that selects one. Without ' +
|
|
372
|
+
'either, the locator is every element on the page and the property would run against ' +
|
|
373
|
+
'whichever one happened to match first',
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
export const PredicateSchema = z.lazy(() => z.preprocess(applyPredicateAliases, predicateUnion()).superRefine(checkPredicateShape));
|
|
378
|
+
/**
|
|
379
|
+
* The fields one predicate kind accepts, as the schema itself declares them.
|
|
380
|
+
*
|
|
381
|
+
* Exported because the ENGINE's introspection needs it and the union it reads is built here. A
|
|
382
|
+
* second copy of the union next door is how a rejection message comes to name a stale field set,
|
|
383
|
+
* which is worse than naming none: the agent trusts it and retries into the same wall.
|
|
384
|
+
*/
|
|
385
|
+
export function predicateShapeFor(kind) {
|
|
386
|
+
for (const option of predicateUnion().options) {
|
|
387
|
+
const shape = option.shape;
|
|
388
|
+
const literal = shape?.['kind'];
|
|
389
|
+
const value = literal?._def?.value;
|
|
390
|
+
if (value === kind)
|
|
391
|
+
return shape;
|
|
392
|
+
}
|
|
393
|
+
return null;
|
|
394
|
+
}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A property assertion: what a caller may claim about a value other than its exact bytes.
|
|
3
|
+
*
|
|
4
|
+
* The contract half only. `satisfiesProperty` — the function that DECIDES whether a reading has a
|
|
5
|
+
* property — stays in the engine, with the baseline plumbing and the `show`/`numberIn` helpers it
|
|
6
|
+
* reasons with. This file is what a flow file on disk can legally contain.
|
|
7
|
+
*
|
|
8
|
+
* Split out of the engine with the rest of the predicate contract, and for the same reason: a saved
|
|
9
|
+
* flow carries one of these now, so core has to be able to parse what it reads.
|
|
10
|
+
*/
|
|
11
|
+
import { z } from 'zod';
|
|
12
|
+
import { MeasureOp } from 'open-verification';
|
|
13
|
+
export type PropertyAssertion =
|
|
14
|
+
/** Produced something at all — the honest floor for any generated output. */
|
|
15
|
+
{
|
|
16
|
+
readonly property: 'nonEmpty';
|
|
17
|
+
}
|
|
18
|
+
/** A classification landed inside the allowed set. Exact membership, no coercion. */
|
|
19
|
+
| {
|
|
20
|
+
readonly property: 'oneOf';
|
|
21
|
+
readonly values: readonly unknown[];
|
|
22
|
+
}
|
|
23
|
+
/** A number near enough to an expected one — inclusive on the bound. */
|
|
24
|
+
| {
|
|
25
|
+
readonly property: 'withinTolerance';
|
|
26
|
+
readonly of: number;
|
|
27
|
+
readonly tolerance: number;
|
|
28
|
+
}
|
|
29
|
+
/** The shape of the output, as a regular expression over its string form. */
|
|
30
|
+
| {
|
|
31
|
+
readonly property: 'matchesPattern';
|
|
32
|
+
readonly pattern: string;
|
|
33
|
+
}
|
|
34
|
+
/** The right KIND of thing: `array` and `object` are distinguished, which `typeof` cannot do. */
|
|
35
|
+
| {
|
|
36
|
+
readonly property: 'type';
|
|
37
|
+
readonly is: 'string' | 'number' | 'boolean' | 'array' | 'object';
|
|
38
|
+
} | {
|
|
39
|
+
readonly property: 'changed';
|
|
40
|
+
} | {
|
|
41
|
+
readonly property: 'unchanged';
|
|
42
|
+
} | {
|
|
43
|
+
readonly property: 'increased';
|
|
44
|
+
readonly by?: Delta;
|
|
45
|
+
} | {
|
|
46
|
+
readonly property: 'decreased';
|
|
47
|
+
readonly by?: Delta;
|
|
48
|
+
};
|
|
49
|
+
/** How far a reading moved, in the protocol's comparison vocabulary. Tolerance defaults to exact. */
|
|
50
|
+
export interface Delta {
|
|
51
|
+
readonly op: MeasureOp;
|
|
52
|
+
readonly value: number;
|
|
53
|
+
readonly tolerance?: number;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* The reading taken BEFORE the action, when one was taken.
|
|
57
|
+
*
|
|
58
|
+
* A wrapper rather than a bare value because `undefined` is a legitimate reading — a store path
|
|
59
|
+
* that held nothing — and "the path was empty" and "nobody looked" must not collapse into the same
|
|
60
|
+
* answer. The first is a comparison; the second is a refusal to pretend one happened.
|
|
61
|
+
*/
|
|
62
|
+
export interface Baseline {
|
|
63
|
+
readonly taken: true;
|
|
64
|
+
readonly value: unknown;
|
|
65
|
+
}
|
|
66
|
+
export declare const propertyAssertionSchema: z.ZodDiscriminatedUnion<"property", [z.ZodObject<{
|
|
67
|
+
property: z.ZodLiteral<"nonEmpty">;
|
|
68
|
+
}, "strict", z.ZodTypeAny, {
|
|
69
|
+
property: "nonEmpty";
|
|
70
|
+
}, {
|
|
71
|
+
property: "nonEmpty";
|
|
72
|
+
}>, z.ZodObject<{
|
|
73
|
+
property: z.ZodLiteral<"oneOf">;
|
|
74
|
+
values: z.ZodArray<z.ZodUnknown, "many">;
|
|
75
|
+
}, "strict", z.ZodTypeAny, {
|
|
76
|
+
values: unknown[];
|
|
77
|
+
property: "oneOf";
|
|
78
|
+
}, {
|
|
79
|
+
values: unknown[];
|
|
80
|
+
property: "oneOf";
|
|
81
|
+
}>, z.ZodObject<{
|
|
82
|
+
property: z.ZodLiteral<"withinTolerance">;
|
|
83
|
+
of: z.ZodNumber;
|
|
84
|
+
tolerance: z.ZodNumber;
|
|
85
|
+
}, "strict", z.ZodTypeAny, {
|
|
86
|
+
tolerance: number;
|
|
87
|
+
property: "withinTolerance";
|
|
88
|
+
of: number;
|
|
89
|
+
}, {
|
|
90
|
+
tolerance: number;
|
|
91
|
+
property: "withinTolerance";
|
|
92
|
+
of: number;
|
|
93
|
+
}>, z.ZodObject<{
|
|
94
|
+
property: z.ZodLiteral<"matchesPattern">;
|
|
95
|
+
pattern: z.ZodString;
|
|
96
|
+
}, "strict", z.ZodTypeAny, {
|
|
97
|
+
property: "matchesPattern";
|
|
98
|
+
pattern: string;
|
|
99
|
+
}, {
|
|
100
|
+
property: "matchesPattern";
|
|
101
|
+
pattern: string;
|
|
102
|
+
}>, z.ZodObject<{
|
|
103
|
+
property: z.ZodLiteral<"type">;
|
|
104
|
+
is: z.ZodEnum<["string", "number", "boolean", "array", "object"]>;
|
|
105
|
+
}, "strict", z.ZodTypeAny, {
|
|
106
|
+
property: "type";
|
|
107
|
+
is: "string" | "number" | "boolean" | "object" | "array";
|
|
108
|
+
}, {
|
|
109
|
+
property: "type";
|
|
110
|
+
is: "string" | "number" | "boolean" | "object" | "array";
|
|
111
|
+
}>, z.ZodObject<{
|
|
112
|
+
property: z.ZodLiteral<"changed">;
|
|
113
|
+
}, "strict", z.ZodTypeAny, {
|
|
114
|
+
property: "changed";
|
|
115
|
+
}, {
|
|
116
|
+
property: "changed";
|
|
117
|
+
}>, z.ZodObject<{
|
|
118
|
+
property: z.ZodLiteral<"unchanged">;
|
|
119
|
+
}, "strict", z.ZodTypeAny, {
|
|
120
|
+
property: "unchanged";
|
|
121
|
+
}, {
|
|
122
|
+
property: "unchanged";
|
|
123
|
+
}>, z.ZodObject<{
|
|
124
|
+
property: z.ZodLiteral<"increased">;
|
|
125
|
+
by: z.ZodOptional<z.ZodObject<{
|
|
126
|
+
op: z.ZodNativeEnum<{
|
|
127
|
+
readonly EQUALS: "equals";
|
|
128
|
+
readonly AT_LEAST: "at-least";
|
|
129
|
+
readonly AT_MOST: "at-most";
|
|
130
|
+
}>;
|
|
131
|
+
value: z.ZodNumber;
|
|
132
|
+
/** Never negative — a negative tolerance NARROWS the band, which is a different claim by accident. */
|
|
133
|
+
tolerance: z.ZodOptional<z.ZodNumber>;
|
|
134
|
+
}, "strict", z.ZodTypeAny, {
|
|
135
|
+
value: number;
|
|
136
|
+
op: "equals" | "at-least" | "at-most";
|
|
137
|
+
tolerance?: number | undefined;
|
|
138
|
+
}, {
|
|
139
|
+
value: number;
|
|
140
|
+
op: "equals" | "at-least" | "at-most";
|
|
141
|
+
tolerance?: number | undefined;
|
|
142
|
+
}>>;
|
|
143
|
+
}, "strict", z.ZodTypeAny, {
|
|
144
|
+
property: "increased";
|
|
145
|
+
by?: {
|
|
146
|
+
value: number;
|
|
147
|
+
op: "equals" | "at-least" | "at-most";
|
|
148
|
+
tolerance?: number | undefined;
|
|
149
|
+
} | undefined;
|
|
150
|
+
}, {
|
|
151
|
+
property: "increased";
|
|
152
|
+
by?: {
|
|
153
|
+
value: number;
|
|
154
|
+
op: "equals" | "at-least" | "at-most";
|
|
155
|
+
tolerance?: number | undefined;
|
|
156
|
+
} | undefined;
|
|
157
|
+
}>, z.ZodObject<{
|
|
158
|
+
property: z.ZodLiteral<"decreased">;
|
|
159
|
+
by: z.ZodOptional<z.ZodObject<{
|
|
160
|
+
op: z.ZodNativeEnum<{
|
|
161
|
+
readonly EQUALS: "equals";
|
|
162
|
+
readonly AT_LEAST: "at-least";
|
|
163
|
+
readonly AT_MOST: "at-most";
|
|
164
|
+
}>;
|
|
165
|
+
value: z.ZodNumber;
|
|
166
|
+
/** Never negative — a negative tolerance NARROWS the band, which is a different claim by accident. */
|
|
167
|
+
tolerance: z.ZodOptional<z.ZodNumber>;
|
|
168
|
+
}, "strict", z.ZodTypeAny, {
|
|
169
|
+
value: number;
|
|
170
|
+
op: "equals" | "at-least" | "at-most";
|
|
171
|
+
tolerance?: number | undefined;
|
|
172
|
+
}, {
|
|
173
|
+
value: number;
|
|
174
|
+
op: "equals" | "at-least" | "at-most";
|
|
175
|
+
tolerance?: number | undefined;
|
|
176
|
+
}>>;
|
|
177
|
+
}, "strict", z.ZodTypeAny, {
|
|
178
|
+
property: "decreased";
|
|
179
|
+
by?: {
|
|
180
|
+
value: number;
|
|
181
|
+
op: "equals" | "at-least" | "at-most";
|
|
182
|
+
tolerance?: number | undefined;
|
|
183
|
+
} | undefined;
|
|
184
|
+
}, {
|
|
185
|
+
property: "decreased";
|
|
186
|
+
by?: {
|
|
187
|
+
value: number;
|
|
188
|
+
op: "equals" | "at-least" | "at-most";
|
|
189
|
+
tolerance?: number | undefined;
|
|
190
|
+
} | undefined;
|
|
191
|
+
}>]>;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A property assertion: what a caller may claim about a value other than its exact bytes.
|
|
3
|
+
*
|
|
4
|
+
* The contract half only. `satisfiesProperty` — the function that DECIDES whether a reading has a
|
|
5
|
+
* property — stays in the engine, with the baseline plumbing and the `show`/`numberIn` helpers it
|
|
6
|
+
* reasons with. This file is what a flow file on disk can legally contain.
|
|
7
|
+
*
|
|
8
|
+
* Split out of the engine with the rest of the predicate contract, and for the same reason: a saved
|
|
9
|
+
* flow carries one of these now, so core has to be able to parse what it reads.
|
|
10
|
+
*/
|
|
11
|
+
import { z } from 'zod';
|
|
12
|
+
import { MeasureOp } from 'open-verification';
|
|
13
|
+
const deltaSchema = z
|
|
14
|
+
.object({
|
|
15
|
+
op: z.nativeEnum(MeasureOp),
|
|
16
|
+
value: z.number().finite(),
|
|
17
|
+
/** Never negative — a negative tolerance NARROWS the band, which is a different claim by accident. */
|
|
18
|
+
tolerance: z.number().finite().nonnegative().optional(),
|
|
19
|
+
})
|
|
20
|
+
.strict();
|
|
21
|
+
export const propertyAssertionSchema = z.discriminatedUnion('property', [
|
|
22
|
+
z.object({ property: z.literal('nonEmpty') }).strict(),
|
|
23
|
+
z.object({ property: z.literal('oneOf'), values: z.array(z.unknown()).min(1) }).strict(),
|
|
24
|
+
z
|
|
25
|
+
.object({
|
|
26
|
+
property: z.literal('withinTolerance'),
|
|
27
|
+
of: z.number().finite(),
|
|
28
|
+
tolerance: z.number().finite().nonnegative(),
|
|
29
|
+
})
|
|
30
|
+
.strict(),
|
|
31
|
+
z.object({ property: z.literal('matchesPattern'), pattern: z.string().min(1) }).strict(),
|
|
32
|
+
z
|
|
33
|
+
.object({
|
|
34
|
+
property: z.literal('type'),
|
|
35
|
+
is: z.enum(['string', 'number', 'boolean', 'array', 'object']),
|
|
36
|
+
})
|
|
37
|
+
.strict(),
|
|
38
|
+
z.object({ property: z.literal('changed') }).strict(),
|
|
39
|
+
z.object({ property: z.literal('unchanged') }).strict(),
|
|
40
|
+
z.object({ property: z.literal('increased'), by: deltaSchema.optional() }).strict(),
|
|
41
|
+
z.object({ property: z.literal('decreased'), by: deltaSchema.optional() }).strict(),
|
|
42
|
+
]);
|
package/dist/verdict/security.js
CHANGED
|
@@ -29,10 +29,22 @@
|
|
|
29
29
|
*/
|
|
30
30
|
const DANGEROUS_ACTION = /\b(delete|remove|destroy|erase|drop|terminate|revoke|reset|close account|cancel subscription|purchase|buy|pay|payment|place order|confirm order|send money|send funds|transfer|withdraw|refund)\b/i;
|
|
31
31
|
/**
|
|
32
|
-
* Roles that pick a
|
|
33
|
-
*
|
|
32
|
+
* Roles that pick a VALUE, not perform an action. Selecting "Payment" as a document type is not a
|
|
33
|
+
* payment, and choosing "Refund" from a reason group is not a refund -- the act those choices feed
|
|
34
|
+
* is the submit that follows, and that control is judged on its own terms.
|
|
35
|
+
*
|
|
36
|
+
* `radio` joins `option` on exactly that argument. Reported from the field alongside the other
|
|
37
|
+
* false positives in the same session: choosing "Inlet" from two radio-like choices was blocked,
|
|
38
|
+
* and the reporter's summary is the cost -- "I ended up passing confirmDangerous: true reflexively
|
|
39
|
+
* on every action, which is how a safety guard becomes decoration". A guard that fires on picking a
|
|
40
|
+
* value is not protecting the destructive action either.
|
|
41
|
+
*
|
|
42
|
+
* `checkbox` is deliberately NOT here. It is a value picker too, but it is also the shape a
|
|
43
|
+
* one-click irreversible confirmation takes ("Delete this repository" with no separate submit), and
|
|
44
|
+
* this guard is asymmetric on purpose: a false block costs a round trip, a missed block cannot be
|
|
45
|
+
* undone. `menuitem` stays out for the reason it always did -- a menu item labelled Delete IS one.
|
|
34
46
|
*/
|
|
35
|
-
const
|
|
47
|
+
const VALUE_PICKER_ROLES = new Set(['option', 'radio']);
|
|
36
48
|
/** The hostnames that ARE loopback outright, with no parsing: the name, and IPv6 ::1 both ways. */
|
|
37
49
|
const LOOPBACK_HOSTNAMES = ['localhost', '::1', '0:0:0:0:0:0:0:1'];
|
|
38
50
|
/** IPv4 loopback is the whole 127.0.0.0/8 block, so the first octet is the entire test. */
|
|
@@ -107,7 +119,7 @@ export function isOpaqueOrigin(origin) {
|
|
|
107
119
|
* role (a tool name, a click with no role on the descriptor) omit it and the text decides.
|
|
108
120
|
*/
|
|
109
121
|
export function isDangerousActionText(text, role) {
|
|
110
|
-
if (role !== undefined && role.trim().toLowerCase()
|
|
122
|
+
if (role !== undefined && VALUE_PICKER_ROLES.has(role.trim().toLowerCase()))
|
|
111
123
|
return false;
|
|
112
124
|
return DANGEROUS_ACTION.test(text.replace(/[_-]+/g, ' '));
|
|
113
125
|
}
|