@reticlehq/core 3.6.0 → 3.7.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/artifacts-entry.d.ts +2 -0
- package/dist/artifacts/artifacts-entry.js +2 -0
- package/dist/artifacts/drive-script.d.ts +158 -52
- package/dist/artifacts/drive-script.js +24 -1
- package/dist/artifacts/flow-constants.d.ts +18 -0
- package/dist/artifacts/flow-constants.js +20 -0
- package/dist/artifacts/flow-results.d.ts +450 -0
- package/dist/artifacts/flow-results.js +1 -0
- package/dist/artifacts/flow-types.d.ts +25 -437
- package/dist/artifacts/flow-types.js +5 -2
- package/dist/artifacts/harness-credits.d.ts +39 -0
- package/dist/artifacts/harness-credits.js +69 -0
- package/dist/artifacts/harness-map.d.ts +98 -0
- package/dist/artifacts/harness-map.js +36 -0
- package/dist/artifacts/impact.d.ts +354 -145
- package/dist/artifacts/impact.js +66 -48
- package/dist/artifacts/journal.d.ts +56 -5
- package/dist/artifacts/journal.js +26 -0
- package/dist/artifacts/screenshot-upload.d.ts +51 -0
- package/dist/artifacts/screenshot-upload.js +26 -0
- package/dist/hooks/hook-events.d.ts +4 -4
- package/dist/hud-entry.d.ts +1 -0
- package/dist/hud-entry.js +2 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +5 -0
- package/dist/onboarding.d.ts +8 -0
- package/dist/onboarding.js +6 -0
- package/dist/realm/registry.js +19 -1
- package/dist/schema/command-message.json +30 -0
- package/dist/schema/command-name.json +3 -1
- package/dist/schema/event-payloads.json +40 -2
- package/dist/schema/reticle-message.json +30 -0
- package/dist/telemetry-bug.d.ts +169 -0
- package/dist/telemetry-bug.js +123 -0
- package/dist/telemetry-entry.d.ts +1 -0
- package/dist/telemetry-entry.js +1 -0
- package/dist/telemetry-feedback.d.ts +2 -2
- package/dist/telemetry-refusal.d.ts +2 -2
- package/dist/telemetry-session.d.ts +74 -0
- package/dist/telemetry-session.js +54 -0
- package/dist/telemetry-signals.d.ts +339 -0
- package/dist/telemetry-signals.js +138 -0
- package/dist/telemetry.d.ts +300 -254
- package/dist/telemetry.js +40 -115
- package/dist/verdict/disparity.d.ts +105 -0
- package/dist/verdict/disparity.js +40 -0
- package/dist/verdict/findings.d.ts +6 -0
- package/dist/verdict/findings.js +9 -0
- package/dist/verdict/instrumentation-coverage.d.ts +115 -0
- package/dist/verdict/instrumentation-coverage.js +226 -0
- package/dist/verdict/instrumentation-gap.js +1 -1
- package/dist/verdict/intent.d.ts +19 -5
- package/dist/verdict/intent.js +13 -1
- package/dist/verdict/predicate-tree.d.ts +15 -0
- package/dist/verdict/predicate-tree.js +21 -0
- package/dist/verdict/predicate.d.ts +14 -0
- package/dist/verdict/predicate.js +87 -3
- package/dist/verdict/security.d.ts +25 -0
- package/dist/verdict/security.js +82 -0
- package/dist/verdict/verification-run.d.ts +620 -32
- package/dist/verdict/verification-run.js +82 -0
- package/dist/wire/constants/constants.d.ts +15 -16
- package/dist/wire/constants/constants.js +16 -17
- package/dist/wire/constants/hud-controls.js +17 -5
- package/dist/wire/constants/hud-use.d.ts +29 -4
- package/dist/wire/constants/hud-use.js +26 -4
- package/dist/wire/constants/mcp-wire.d.ts +10 -0
- package/dist/wire/constants/mcp-wire.js +10 -0
- package/dist/wire/constants/reticle-chrome.d.ts +19 -0
- package/dist/wire/constants/reticle-chrome.js +19 -0
- package/dist/wire/constants/session-constants.d.ts +15 -2
- package/dist/wire/constants/session-constants.js +15 -2
- package/dist/wire/desktop-contract.d.ts +8 -0
- package/dist/wire/desktop-contract.js +11 -0
- package/dist/wire/event-payloads.d.ts +56 -4
- package/dist/wire/event-payloads.js +17 -0
- package/dist/wire/messages.d.ts +105 -32
- package/dist/wire/messages.js +9 -1
- package/dist/wire/platform-link.d.ts +77 -0
- package/dist/wire/platform-link.js +45 -0
- package/dist/wire/tool-names.d.ts +2 -0
- package/dist/wire/tool-names.js +2 -0
- package/dist/wire/types.d.ts +19 -6
- package/dist/wire/types.js +5 -0
- package/dist/words/notices.d.ts +1 -1
- package/dist/words/notices.js +1 -1
- package/dist/words/upgrade.js +1 -1
- package/dist/words/writing-rule.d.ts +14 -0
- package/dist/words/writing-rule.js +17 -0
- package/package.json +1 -1
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How much of an app Reticle can see, and the prompt that asks a coding agent to close the rest.
|
|
3
|
+
*
|
|
4
|
+
* Built only from what a page announced (its HELLO channels, plus the `source` / `testid` markers in
|
|
5
|
+
* the same list) and the gaps its verdicts actually recorded, never from a survey of the page: the
|
|
6
|
+
* rule `instrumentation-gap.ts` keeps. The platform derives the same three states from the same
|
|
7
|
+
* report, so the HUD, `doctor` and the dashboard agree:
|
|
8
|
+
*
|
|
9
|
+
* missing a verdict recorded the gap that names it (or a channel every SDK has is absent);
|
|
10
|
+
* a gap about one control does not outrank its channel seen elsewhere
|
|
11
|
+
* seen its channel or marker was announced
|
|
12
|
+
* not seen yet neither — never counted as covered
|
|
13
|
+
*/
|
|
14
|
+
import { z } from 'zod';
|
|
15
|
+
import { ChannelId } from 'open-verification';
|
|
16
|
+
import { InstrumentationGapKind, fixForGap } from './instrumentation-gap.js';
|
|
17
|
+
import { CoverageMarker, SOURCE_MAPPING_CAPABILITY } from '../wire/platform-link.js';
|
|
18
|
+
/** The eight things that decide how strong a verdict on this app can be. */
|
|
19
|
+
export const CoverageCapability = {
|
|
20
|
+
PAGE_CONNECTED: 'page connected',
|
|
21
|
+
DOM_ACTIONS: 'DOM actions',
|
|
22
|
+
NETWORK: 'network',
|
|
23
|
+
CONSOLE: 'console',
|
|
24
|
+
APP_STATE: 'app state (store registered)',
|
|
25
|
+
SIGNALS: 'signals on mutation',
|
|
26
|
+
SOURCE_MAPPING: SOURCE_MAPPING_CAPABILITY,
|
|
27
|
+
TEST_IDS: 'stable test ids',
|
|
28
|
+
};
|
|
29
|
+
const CONNECT_FIX = 'run `npx @reticlehq/server init` in the app so its pages connect to Reticle in development';
|
|
30
|
+
/** Ordered as a reader climbs them: nothing works without the first, everything sharpens with the last. */
|
|
31
|
+
const RULES = [
|
|
32
|
+
{
|
|
33
|
+
capability: CoverageCapability.PAGE_CONNECTED,
|
|
34
|
+
gaps: [],
|
|
35
|
+
cost: 'no page has connected, so nothing can be verified',
|
|
36
|
+
fix: CONNECT_FIX,
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
capability: CoverageCapability.DOM_ACTIONS,
|
|
40
|
+
channel: ChannelId.UI,
|
|
41
|
+
always: true,
|
|
42
|
+
gaps: [],
|
|
43
|
+
cost: 'controls cannot be driven or read',
|
|
44
|
+
fix: CONNECT_FIX,
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
capability: CoverageCapability.NETWORK,
|
|
48
|
+
channel: ChannelId.NET,
|
|
49
|
+
always: true,
|
|
50
|
+
gaps: [],
|
|
51
|
+
cost: 'requests cannot be asserted, so a save that never reached the server can pass',
|
|
52
|
+
fix: 'update @reticlehq/browser so the page reports its network channel',
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
capability: CoverageCapability.CONSOLE,
|
|
56
|
+
channel: ChannelId.LOG,
|
|
57
|
+
always: true,
|
|
58
|
+
gaps: [],
|
|
59
|
+
cost: 'errors thrown in the page are invisible to a verdict',
|
|
60
|
+
fix: 'update @reticlehq/browser so the page reports its console channel',
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
capability: CoverageCapability.APP_STATE,
|
|
64
|
+
channel: ChannelId.STATE,
|
|
65
|
+
gaps: [InstrumentationGapKind.NO_STORE_REGISTERED],
|
|
66
|
+
cost: 'state predicates fall back to reading the DOM',
|
|
67
|
+
fix: fixForGap(InstrumentationGapKind.NO_STORE_REGISTERED),
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
capability: CoverageCapability.SIGNALS,
|
|
71
|
+
channel: ChannelId.SIGNAL,
|
|
72
|
+
gaps: [InstrumentationGapKind.NO_SIGNAL_ON_MUTATION],
|
|
73
|
+
cost: 'the app never says it succeeded, so every verdict infers success from the DOM',
|
|
74
|
+
fix: fixForGap(InstrumentationGapKind.NO_SIGNAL_ON_MUTATION),
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
capability: CoverageCapability.SOURCE_MAPPING,
|
|
78
|
+
channel: CoverageMarker.SOURCE,
|
|
79
|
+
gaps: [InstrumentationGapKind.NO_SOURCE_MAPPING, InstrumentationGapKind.SOURCE_MAPPING_OFF],
|
|
80
|
+
perControl: [InstrumentationGapKind.NO_SOURCE_MAPPING],
|
|
81
|
+
cost: 'a broken control is named, never the line that renders it',
|
|
82
|
+
fix: fixForGap(InstrumentationGapKind.NO_SOURCE_MAPPING),
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
capability: CoverageCapability.TEST_IDS,
|
|
86
|
+
channel: CoverageMarker.TESTID,
|
|
87
|
+
gaps: [InstrumentationGapKind.MISSING_TESTID],
|
|
88
|
+
cost: 'a saved flow loses its controls after a refactor',
|
|
89
|
+
fix: fixForGap(InstrumentationGapKind.MISSING_TESTID),
|
|
90
|
+
},
|
|
91
|
+
];
|
|
92
|
+
/** What a page with these channels and these recorded gaps lets Reticle see. Pure. */
|
|
93
|
+
export function coverageOf(input) {
|
|
94
|
+
const channels = new Set(input.channels);
|
|
95
|
+
const connected = 0 < channels.size;
|
|
96
|
+
const seen = [];
|
|
97
|
+
const missing = [];
|
|
98
|
+
const notSeenYet = [];
|
|
99
|
+
for (const rule of RULES) {
|
|
100
|
+
const announced = rule.channel === undefined ? connected : channels.has(rule.channel);
|
|
101
|
+
const recorded = input.gaps.find((gap) => rule.gaps.some((kind) => kind === gap.kind) &&
|
|
102
|
+
!(announced && true === rule.perControl?.some((kind) => kind === gap.kind)));
|
|
103
|
+
if (recorded !== undefined) {
|
|
104
|
+
missing.push({
|
|
105
|
+
capability: rule.capability,
|
|
106
|
+
cost: recorded.cost ?? rule.cost,
|
|
107
|
+
fix: recorded.fix ?? rule.fix,
|
|
108
|
+
});
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
if (announced)
|
|
112
|
+
seen.push(rule.capability);
|
|
113
|
+
else if (!connected || true === rule.always)
|
|
114
|
+
missing.push({ capability: rule.capability, cost: rule.cost, fix: rule.fix });
|
|
115
|
+
else
|
|
116
|
+
notSeenYet.push(rule.capability);
|
|
117
|
+
}
|
|
118
|
+
return { seen, missing, notSeenYet, total: RULES.length, covered: seen.length };
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* The gaps that would close these capabilities: the ones verdicts recorded (they name the control
|
|
122
|
+
* and file), else the capability's own fix, so a capability never checked is still named. Pure.
|
|
123
|
+
*/
|
|
124
|
+
export function gapsToClose(gaps, capabilities) {
|
|
125
|
+
return RULES.filter((rule) => capabilities.includes(rule.capability)).flatMap((rule) => {
|
|
126
|
+
const recorded = gaps.filter((gap) => rule.gaps.some((kind) => kind === gap.kind));
|
|
127
|
+
return 0 < recorded.length
|
|
128
|
+
? recorded
|
|
129
|
+
: [{ kind: rule.capability, missing: rule.capability, fix: rule.fix }];
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
/** The first line of every coverage prompt. */
|
|
133
|
+
export const AGENT_PROMPT_LEAD = "Read https://reticle.sh/SKILL.md, then improve Reticle's coverage in this repo:";
|
|
134
|
+
/** The last line: what the agent hands back. */
|
|
135
|
+
export const AGENT_PROMPT_TAIL = 'Report the coverage line it prints.';
|
|
136
|
+
/** The placeholder the person replaces with the journey their change touched. */
|
|
137
|
+
const JOURNEY_PLACEHOLDER = '<one journey you changed>';
|
|
138
|
+
/**
|
|
139
|
+
* The copy-paste prompt for a coding agent: only the gaps verdicts recorded, each with its fix and
|
|
140
|
+
* what it is missing (and the control or file, when the gap names one), then the verify that proves
|
|
141
|
+
* the change. The same text the platform builds from the same report. Pure.
|
|
142
|
+
*/
|
|
143
|
+
export function agentPromptFor(input) {
|
|
144
|
+
const items = input.gaps.map((gap) => {
|
|
145
|
+
const where = [
|
|
146
|
+
gap.missing === undefined ? undefined : `missing: ${gap.missing}`,
|
|
147
|
+
gap.ref === undefined ? undefined : `control ${gap.ref}`,
|
|
148
|
+
gap.source === undefined ? undefined : `at ${gap.source}`,
|
|
149
|
+
].filter((part) => part !== undefined);
|
|
150
|
+
return `- ${gap.fix ?? fixForKind(gap.kind)}${0 === where.length ? '' : ` (${where.join(', ')})`}`;
|
|
151
|
+
});
|
|
152
|
+
return [
|
|
153
|
+
AGENT_PROMPT_LEAD,
|
|
154
|
+
`App: ${input.appName} at ${input.url}`,
|
|
155
|
+
...new Set(items),
|
|
156
|
+
`Then run: reticle verify ${input.url} --expect "${JOURNEY_PLACEHOLDER}"`,
|
|
157
|
+
AGENT_PROMPT_TAIL,
|
|
158
|
+
].join('\n');
|
|
159
|
+
}
|
|
160
|
+
/** The vocabulary's fix for a kind this build knows, else nothing invented. */
|
|
161
|
+
function fixForKind(kind) {
|
|
162
|
+
const known = Object.values(InstrumentationGapKind).find((k) => k === kind);
|
|
163
|
+
return known === undefined ? kind : fixForGap(known);
|
|
164
|
+
}
|
|
165
|
+
// ── The Harness coverage gate ─────────────────────────────────────────────────────────────────
|
|
166
|
+
/*
|
|
167
|
+
* When the Reticle Harness may drive an app: only once Reticle can see enough of it.
|
|
168
|
+
*
|
|
169
|
+
* A Harness drive decides on the platform and spends credits; on an app Reticle half sees, it pays
|
|
170
|
+
* for verdicts that can only infer from the DOM. So the Harness unlocks at a coverage score, and the
|
|
171
|
+
* coding agent (which can use every other tool at any coverage) is how an app gets there.
|
|
172
|
+
*
|
|
173
|
+
* THE RULE, one definition; the platform mirrors it exactly:
|
|
174
|
+
*
|
|
175
|
+
* capabilities the eight `CoverageCapability` entries, as `coverageOf` reads them
|
|
176
|
+
* applicable capabilities minus those that do not apply to this app (excluded from both sides;
|
|
177
|
+
* the daemon reports them as `notApplicable` on each local-apps app)
|
|
178
|
+
* seen applicable capabilities `coverageOf` lists as seen; "not seen yet" is NOT seen
|
|
179
|
+
* score seen ÷ applicable, 0 when nothing applies
|
|
180
|
+
* percent floor(score × 100), so a shown percent is below 80 exactly when the gate is shut
|
|
181
|
+
* unlocked score ≥ HARNESS_UNLOCK_COVERAGE (0.8)
|
|
182
|
+
*
|
|
183
|
+
* The gate is the Harness's alone. Pure: coverage in, a decision and its sentence out.
|
|
184
|
+
*/
|
|
185
|
+
/** The capabilities an app reports as not applying to it, on the wire. Closed: core's eight only. */
|
|
186
|
+
export const NotApplicableSchema = z.array(z.nativeEnum(CoverageCapability)).max(8);
|
|
187
|
+
/** The score at which the Harness unlocks. */
|
|
188
|
+
export const HARNESS_UNLOCK_COVERAGE = 0.8;
|
|
189
|
+
/** Floating-point slack, so 0.29 × 100 floors to 29 and not 28. */
|
|
190
|
+
const PERCENT_EPSILON = 1e-9;
|
|
191
|
+
/** Seen ÷ applicable over the eight capabilities. See the header for the exact rule. */
|
|
192
|
+
export function coverageScore(coverage, notApplicable = []) {
|
|
193
|
+
const applicable = Object.values(CoverageCapability).filter((c) => !notApplicable.includes(c));
|
|
194
|
+
if (0 === applicable.length)
|
|
195
|
+
return 0;
|
|
196
|
+
return applicable.filter((c) => coverage.seen.includes(c)).length / applicable.length;
|
|
197
|
+
}
|
|
198
|
+
/** The one sentence a locked Harness answers with. */
|
|
199
|
+
export const harnessLockedReason = (percent, unseen) => `Harness unlocks at ${String(Math.round(HARNESS_UNLOCK_COVERAGE * 100))}% instrumentation. ` +
|
|
200
|
+
`This app is at ${String(percent)}%: missing ${unseen.join(', ')}.`;
|
|
201
|
+
/** Whether the Harness may drive an app with this coverage, and the sentence when it may not. */
|
|
202
|
+
export function harnessGateOf(coverage, notApplicable = []) {
|
|
203
|
+
const score = coverageScore(coverage, notApplicable);
|
|
204
|
+
const percent = Math.floor(score * 100 + PERCENT_EPSILON);
|
|
205
|
+
const unseen = Object.values(CoverageCapability).filter((c) => !notApplicable.includes(c) && !coverage.seen.includes(c));
|
|
206
|
+
const unlocked = HARNESS_UNLOCK_COVERAGE <= score;
|
|
207
|
+
return {
|
|
208
|
+
score,
|
|
209
|
+
percent,
|
|
210
|
+
unlocked,
|
|
211
|
+
unseen,
|
|
212
|
+
...(unlocked ? {} : { reason: harnessLockedReason(percent, unseen) }),
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* The prompt for the coding agent that closes the gate: each unseen capability with how to close it
|
|
217
|
+
* (the control and file when a verdict named one), then the one flow that proves it. Pure.
|
|
218
|
+
*/
|
|
219
|
+
export function harnessUnlockPrompt(input) {
|
|
220
|
+
const { unseen } = harnessGateOf(input.coverage, input.notApplicable);
|
|
221
|
+
return agentPromptFor({
|
|
222
|
+
gaps: gapsToClose(input.gaps, unseen),
|
|
223
|
+
appName: input.appName,
|
|
224
|
+
url: input.url,
|
|
225
|
+
});
|
|
226
|
+
}
|
|
@@ -119,7 +119,7 @@ export const InstrumentationGapKind = {
|
|
|
119
119
|
*/
|
|
120
120
|
const GAP_FIX = {
|
|
121
121
|
[InstrumentationGapKind.NO_SOURCE_MAPPING]: 'add the Reticle build plugin (@reticlehq/vite-plugin, @reticlehq/next, or the babel plugin) so elements carry data-reticle-source',
|
|
122
|
-
[InstrumentationGapKind.NO_STORE_REGISTERED]:
|
|
122
|
+
[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
123
|
[InstrumentationGapKind.NO_SIGNAL_ON_MUTATION]: 'fire reticle.signal(name, data) where this state is committed — commitAndSignal binds the two so they cannot drift',
|
|
124
124
|
[InstrumentationGapKind.UNDECLARED_CONTROL]: 'add this control to reticle.describe() so the capability contract matches what the app actually exposes',
|
|
125
125
|
[InstrumentationGapKind.MISSING_TESTID]: 'add data-testid="..." on this control so the flow can name it after a refactor',
|
package/dist/verdict/intent.d.ts
CHANGED
|
@@ -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
|
*
|
package/dist/verdict/intent.js
CHANGED
|
@@ -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
|
-
|
|
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
|
/**
|
|
@@ -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 — ` +
|
|
@@ -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;
|
|
@@ -141,6 +145,16 @@ export type Predicate = {
|
|
|
141
145
|
* A list beside a schema is a list that drifts; a list read FROM the schema cannot.
|
|
142
146
|
*/
|
|
143
147
|
export declare const ELEMENT_QUERY_FIELDS: readonly (keyof ElementQuery)[];
|
|
148
|
+
/**
|
|
149
|
+
* Which aliases a predicate as WRITTEN would have renamed, as `kind.from → to` (and `type → kind`).
|
|
150
|
+
*
|
|
151
|
+
* The parse itself is silent on purpose — it is a preprocess step — so this reads the same table
|
|
152
|
+
* to tell the caller its spelling was normalised: a forgiving parse that never says so teaches a
|
|
153
|
+
* spelling that only works here. Walks `allOf`/`anyOf`/`not` the way the schema does. Unknown
|
|
154
|
+
* fields are never guessed at: they are not in the table, so they are never reported here, and the
|
|
155
|
+
* schema still refuses them.
|
|
156
|
+
*/
|
|
157
|
+
export declare function predicateAliasesUsed(input: unknown, depth?: number): string[];
|
|
144
158
|
export declare const PredicateSchema: z.ZodType<Predicate>;
|
|
145
159
|
/**
|
|
146
160
|
* The fields one predicate kind accepts, as the schema itself declares them.
|
|
@@ -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
|
-
|
|
45
|
-
|
|
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`.
|
|
@@ -92,6 +105,43 @@ function renameKindSpelling(obj) {
|
|
|
92
105
|
delete out[KIND_SPELLING];
|
|
93
106
|
return out;
|
|
94
107
|
}
|
|
108
|
+
/**
|
|
109
|
+
* Which aliases a predicate as WRITTEN would have renamed, as `kind.from → to` (and `type → kind`).
|
|
110
|
+
*
|
|
111
|
+
* The parse itself is silent on purpose — it is a preprocess step — so this reads the same table
|
|
112
|
+
* to tell the caller its spelling was normalised: a forgiving parse that never says so teaches a
|
|
113
|
+
* spelling that only works here. Walks `allOf`/`anyOf`/`not` the way the schema does. Unknown
|
|
114
|
+
* fields are never guessed at: they are not in the table, so they are never reported here, and the
|
|
115
|
+
* schema still refuses them.
|
|
116
|
+
*/
|
|
117
|
+
export function predicateAliasesUsed(input, depth = 0) {
|
|
118
|
+
if (depth > 8 || typeof input !== 'object' || null === input || Array.isArray(input))
|
|
119
|
+
return [];
|
|
120
|
+
const given = input;
|
|
121
|
+
const used = [];
|
|
122
|
+
if (given['kind'] === undefined && 'string' === typeof given[KIND_SPELLING]) {
|
|
123
|
+
used.push(`${KIND_SPELLING} → kind`);
|
|
124
|
+
}
|
|
125
|
+
const obj = renameKindSpelling(given);
|
|
126
|
+
const kind = 'string' === typeof obj['kind'] ? obj['kind'] : '';
|
|
127
|
+
for (const [from, to] of Object.entries(PREDICATE_ALIASES[kind] ?? {})) {
|
|
128
|
+
if (obj[from] !== undefined && obj[to] === undefined)
|
|
129
|
+
used.push(`${kind}.${from} → ${to}`);
|
|
130
|
+
}
|
|
131
|
+
if (PredicateKind.ELEMENT === kind && obj['query'] === undefined) {
|
|
132
|
+
for (const field of ELEMENT_QUERY_FIELDS) {
|
|
133
|
+
if (obj[field] !== undefined)
|
|
134
|
+
used.push(`element.${field} → query.${field}`);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
for (const field of ['predicates', 'of', 'predicate']) {
|
|
138
|
+
const child = obj[field];
|
|
139
|
+
for (const nested of Array.isArray(child) ? child : [child]) {
|
|
140
|
+
used.push(...predicateAliasesUsed(nested, depth + 1));
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return used;
|
|
144
|
+
}
|
|
95
145
|
/** Rename known aliases before parse; an explicit canonical key always wins. */
|
|
96
146
|
function applyPredicateAliases(input) {
|
|
97
147
|
if (typeof input !== 'object' || null === input || Array.isArray(input))
|
|
@@ -163,6 +213,11 @@ function predicateUnion() {
|
|
|
163
213
|
scope: z.string().optional(),
|
|
164
214
|
self: z.boolean().optional(),
|
|
165
215
|
satisfies: propertyAssertionSchema.optional(),
|
|
216
|
+
/**
|
|
217
|
+
* Match `contains` regardless of case. Off by default: a check that passed "Saved Priya"
|
|
218
|
+
* against "Saved priya" could never catch a capitalisation defect.
|
|
219
|
+
*/
|
|
220
|
+
ignoreCase: z.boolean().optional(),
|
|
166
221
|
})
|
|
167
222
|
.strict(),
|
|
168
223
|
z
|
|
@@ -242,6 +297,14 @@ function predicateUnion() {
|
|
|
242
297
|
* instead of reporting a mismatch: a redacted field is unknown, not different.
|
|
243
298
|
*/
|
|
244
299
|
requestBodyMatches: z.record(z.string(), z.unknown()).optional(),
|
|
300
|
+
/**
|
|
301
|
+
* The endpoint READS, so running twice in one window is not a double submit (#1353). GraphQL
|
|
302
|
+
* queries, tRPC batches, query buses and read Server Actions all read over POST, and React
|
|
303
|
+
* StrictMode runs the effect behind them twice in development. Scoped to this verdict and to
|
|
304
|
+
* the duplicate rule only: the request is still waited for and still counted. Needs a
|
|
305
|
+
* non-empty `urlContains`, and honours `method` when one is given (`checkRepeatableShape`).
|
|
306
|
+
*/
|
|
307
|
+
repeatable: z.boolean().optional(),
|
|
245
308
|
})
|
|
246
309
|
.strict(),
|
|
247
310
|
z
|
|
@@ -356,10 +419,14 @@ function predicateUnion() {
|
|
|
356
419
|
function checkPredicateShape(predicate, ctx) {
|
|
357
420
|
// Structural and narrowed HERE, not in the signature: the refinement runs on the union zod
|
|
358
421
|
// inferred, whose optional fields are spelled `| undefined`, and naming any concrete type in the
|
|
359
|
-
// parameter makes the overload unresolvable. Only the
|
|
422
|
+
// parameter makes the overload unresolvable. Only the fields this reads are looked at.
|
|
360
423
|
if ('object' !== typeof predicate || null === predicate)
|
|
361
424
|
return;
|
|
362
425
|
const p = predicate;
|
|
426
|
+
if (PredicateKind.NET === p.kind) {
|
|
427
|
+
checkRepeatableShape(p.repeatable, p.urlContains, ctx);
|
|
428
|
+
return;
|
|
429
|
+
}
|
|
363
430
|
if (PredicateKind.COMPARE === p.kind) {
|
|
364
431
|
checkCompareShape(predicate, ctx);
|
|
365
432
|
return;
|
|
@@ -383,6 +450,23 @@ function checkPredicateShape(predicate, ctx) {
|
|
|
383
450
|
});
|
|
384
451
|
}
|
|
385
452
|
}
|
|
453
|
+
/**
|
|
454
|
+
* `repeatable` exempts the endpoint it names from `duplicate-request`, so it has to name one. On a
|
|
455
|
+
* clause with no `urlContains` it would exempt every request in the window, and two identical
|
|
456
|
+
* writes, a real double submit, would pass as reads (#1353).
|
|
457
|
+
*/
|
|
458
|
+
function checkRepeatableShape(repeatable, urlContains, ctx) {
|
|
459
|
+
if (true !== repeatable)
|
|
460
|
+
return;
|
|
461
|
+
if ('string' === typeof urlContains && urlContains.trim().length > 0)
|
|
462
|
+
return;
|
|
463
|
+
ctx.addIssue({
|
|
464
|
+
code: z.ZodIssueCode.custom,
|
|
465
|
+
message: '`repeatable: true` needs a non-empty `urlContains` naming the read endpoint, for example ' +
|
|
466
|
+
'`{ kind: "net", method: "POST", urlContains: "/graphql", repeatable: true }`. Without one it ' +
|
|
467
|
+
'would excuse every request in the window from duplicate-request, a real double submit included',
|
|
468
|
+
});
|
|
469
|
+
}
|
|
386
470
|
/**
|
|
387
471
|
* The two ways a `compare` can be written so that it cannot fail, refused before it can report `yes`.
|
|
388
472
|
*
|
|
@@ -28,3 +28,28 @@ export declare function isOpaqueOrigin(origin: string): boolean;
|
|
|
28
28
|
* role (a tool name, a click with no role on the descriptor) omit it and the text decides.
|
|
29
29
|
*/
|
|
30
30
|
export declare function isDangerousActionText(text: string, role?: string): boolean;
|
|
31
|
+
export declare const OutwardAction: {
|
|
32
|
+
readonly INVITE: "invite";
|
|
33
|
+
readonly SEND: "send";
|
|
34
|
+
readonly SHARE: "share";
|
|
35
|
+
readonly DELETE: "delete";
|
|
36
|
+
readonly PAY: "pay";
|
|
37
|
+
readonly PUBLISH: "publish";
|
|
38
|
+
readonly REVOKE: "revoke";
|
|
39
|
+
readonly TRANSFER: "transfer";
|
|
40
|
+
readonly SIGN_OUT: "sign out";
|
|
41
|
+
readonly CHANGE_ROLE: "change role";
|
|
42
|
+
readonly CREATE_KEY: "create key";
|
|
43
|
+
/** Reassigning, reopening, archiving, approving: changing an item's state for everyone. */
|
|
44
|
+
readonly CHANGE_STATE: "change state";
|
|
45
|
+
};
|
|
46
|
+
export type OutwardAction = (typeof OutwardAction)[keyof typeof OutwardAction];
|
|
47
|
+
/** The outward action a control would take, from its text and role; value pickers take none. */
|
|
48
|
+
export declare function outwardActionOf(text: string, role?: string): OutwardAction | undefined;
|
|
49
|
+
/**
|
|
50
|
+
* The outward actions a journey asks for in so many words. "Invite a teammate" asks for invite;
|
|
51
|
+
* "she does not send an invite" and "without sending" ask for nothing. Pure.
|
|
52
|
+
*/
|
|
53
|
+
export declare function outwardActionsAsked(journey: string): OutwardAction[];
|
|
54
|
+
/** What the Harness says, and the journey records, when it would not press one. */
|
|
55
|
+
export declare const outwardRefusal: (action: OutwardAction) => string;
|