@reticlehq/core 3.5.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.
Files changed (113) hide show
  1. package/dist/artifacts/artifacts-entry.d.ts +4 -0
  2. package/dist/artifacts/artifacts-entry.js +4 -0
  3. package/dist/artifacts/drive-script.d.ts +1404 -0
  4. package/dist/artifacts/drive-script.js +220 -0
  5. package/dist/artifacts/flow-constants.d.ts +19 -0
  6. package/dist/artifacts/flow-constants.js +21 -0
  7. package/dist/artifacts/flow-results.d.ts +450 -0
  8. package/dist/artifacts/flow-results.js +1 -0
  9. package/dist/artifacts/flow-types.d.ts +75 -427
  10. package/dist/artifacts/flow-types.js +15 -2
  11. package/dist/artifacts/harness-credits.d.ts +39 -0
  12. package/dist/artifacts/harness-credits.js +69 -0
  13. package/dist/artifacts/harness-map.d.ts +98 -0
  14. package/dist/artifacts/harness-map.js +36 -0
  15. package/dist/artifacts/hud-notices.d.ts +134 -0
  16. package/dist/artifacts/hud-notices.js +124 -0
  17. package/dist/artifacts/impact.d.ts +489 -189
  18. package/dist/artifacts/impact.js +90 -47
  19. package/dist/artifacts/journal.d.ts +105 -5
  20. package/dist/artifacts/journal.js +41 -0
  21. package/dist/artifacts/prompt-context.d.ts +105 -0
  22. package/dist/artifacts/prompt-context.js +108 -0
  23. package/dist/artifacts/screenshot-upload.d.ts +51 -0
  24. package/dist/artifacts/screenshot-upload.js +26 -0
  25. package/dist/desktop-contract.cjs +1 -0
  26. package/dist/desktop-contract.d.cts +1 -0
  27. package/dist/hooks/hook-events.d.ts +4 -4
  28. package/dist/hud-entry.d.ts +2 -0
  29. package/dist/hud-entry.js +4 -0
  30. package/dist/identity/contract-fingerprint.d.ts +9 -0
  31. package/dist/identity/contract-fingerprint.js +12 -0
  32. package/dist/identity/testid-attribute.d.ts +18 -0
  33. package/dist/identity/testid-attribute.js +24 -0
  34. package/dist/index.d.ts +9 -1
  35. package/dist/index.js +9 -1
  36. package/dist/onboarding.d.ts +10 -2
  37. package/dist/onboarding.js +6 -0
  38. package/dist/realm/registry.js +19 -1
  39. package/dist/schema/command-message.json +36 -0
  40. package/dist/schema/command-name.json +5 -1
  41. package/dist/schema/event-payloads.json +56 -2
  42. package/dist/schema/reticle-message.json +36 -0
  43. package/dist/telemetry-bug.d.ts +169 -0
  44. package/dist/telemetry-bug.js +123 -0
  45. package/dist/telemetry-entry.d.ts +1 -0
  46. package/dist/telemetry-entry.js +1 -0
  47. package/dist/telemetry-feedback.d.ts +2 -2
  48. package/dist/telemetry-refusal.d.ts +5 -4
  49. package/dist/telemetry-session.d.ts +79 -1
  50. package/dist/telemetry-session.js +57 -1
  51. package/dist/telemetry-signals.d.ts +339 -0
  52. package/dist/telemetry-signals.js +138 -0
  53. package/dist/telemetry.d.ts +330 -276
  54. package/dist/telemetry.js +40 -115
  55. package/dist/tour.d.ts +1 -0
  56. package/dist/tour.js +13 -5
  57. package/dist/verdict/consequence.d.ts +3 -0
  58. package/dist/verdict/disparity.d.ts +105 -0
  59. package/dist/verdict/disparity.js +40 -0
  60. package/dist/verdict/findings.d.ts +11 -0
  61. package/dist/verdict/findings.js +16 -0
  62. package/dist/verdict/instrumentation-coverage.d.ts +115 -0
  63. package/dist/verdict/instrumentation-coverage.js +226 -0
  64. package/dist/verdict/instrumentation-gap.js +1 -1
  65. package/dist/verdict/intent.d.ts +19 -5
  66. package/dist/verdict/intent.js +13 -1
  67. package/dist/verdict/predicate-tree.d.ts +15 -0
  68. package/dist/verdict/predicate-tree.js +21 -0
  69. package/dist/verdict/predicate.d.ts +28 -0
  70. package/dist/verdict/predicate.js +94 -15
  71. package/dist/verdict/security.d.ts +25 -0
  72. package/dist/verdict/security.js +82 -0
  73. package/dist/verdict/verdict-attribution.js +1 -0
  74. package/dist/verdict/verification-run.d.ts +638 -32
  75. package/dist/verdict/verification-run.js +90 -0
  76. package/dist/verdict/verified-constants.d.ts +19 -0
  77. package/dist/verdict/verified-constants.js +22 -0
  78. package/dist/wire/constants/constants.d.ts +60 -32
  79. package/dist/wire/constants/constants.js +61 -33
  80. package/dist/wire/constants/hud-controls.d.ts +1 -1
  81. package/dist/wire/constants/hud-controls.js +34 -1
  82. package/dist/wire/constants/hud-use.d.ts +89 -1
  83. package/dist/wire/constants/hud-use.js +62 -1
  84. package/dist/wire/constants/mcp-wire.d.ts +10 -0
  85. package/dist/wire/constants/mcp-wire.js +10 -0
  86. package/dist/wire/constants/reticle-chrome.d.ts +19 -0
  87. package/dist/wire/constants/reticle-chrome.js +19 -0
  88. package/dist/wire/constants/session-constants.d.ts +21 -0
  89. package/dist/wire/constants/session-constants.js +21 -0
  90. package/dist/wire/desktop-contract.d.ts +11 -0
  91. package/dist/wire/desktop-contract.js +14 -0
  92. package/dist/wire/event-payloads.d.ts +77 -4
  93. package/dist/wire/event-payloads.js +27 -0
  94. package/dist/wire/global-press.d.ts +34 -3
  95. package/dist/wire/global-press.js +91 -3
  96. package/dist/wire/hold.d.ts +14 -0
  97. package/dist/wire/hold.js +18 -0
  98. package/dist/wire/messages.d.ts +129 -32
  99. package/dist/wire/messages.js +17 -1
  100. package/dist/wire/platform-link.d.ts +238 -0
  101. package/dist/wire/platform-link.js +234 -0
  102. package/dist/wire/tool-names.d.ts +2 -0
  103. package/dist/wire/tool-names.js +2 -0
  104. package/dist/wire/types.d.ts +26 -6
  105. package/dist/wire/types.js +5 -0
  106. package/dist/words/no-session-reason.d.ts +7 -0
  107. package/dist/words/no-session-reason.js +7 -0
  108. package/dist/words/notices.d.ts +1 -1
  109. package/dist/words/notices.js +5 -3
  110. package/dist/words/upgrade.js +1 -1
  111. package/dist/words/writing-rule.d.ts +14 -0
  112. package/dist/words/writing-rule.js +17 -0
  113. package/package.json +1 -1
@@ -0,0 +1,220 @@
1
+ /**
2
+ * A drive script: the Harness's plan, written down before it drives, in a language small enough to
3
+ * check.
4
+ *
5
+ * Journeys say WHAT to drive: replay a saved flow (deterministic, no model), act and wait on one
6
+ * exact control, hand an open goal to the model, assert a consequence. Lanes say HOW: each lane is
7
+ * one browser context driven in order, and lanes run side by side. A journey that needs another one
8
+ * either follows it in the same lane (and inherits its page) or waits on it from a later lane (a
9
+ * barrier: it starts once that journey passed, and is blocked if it failed).
10
+ *
11
+ * A checkpoint names a point a journey can come back to, and how: replay a flow up to a step. A
12
+ * branch drives several cases from that point; every case after the first re-enters it first, so
13
+ * each case starts from the same page and not from wherever the previous case left it.
14
+ *
15
+ * Daemon-side only: the HUD draws a plan from a flat view of it (`PlanView`), never this schema.
16
+ */
17
+ import { z } from 'zod';
18
+ import { PredicateSchema } from '../verdict/predicate.js';
19
+ export const ScriptStepKind = {
20
+ REPLAY: 'replay',
21
+ ACT: 'act',
22
+ ASSERT: 'assert',
23
+ CHECKPOINT: 'checkpoint',
24
+ BRANCH: 'branch',
25
+ };
26
+ /** How a journey of a plan was answered: its saved flows replayed (no model), or the model drove it. */
27
+ export const JourneyBy = { REPLAY: 'replay', MODEL: 'model' };
28
+ export const ScriptSource = { LOCAL: 'local', PLATFORM: 'platform' };
29
+ /** How the journey a condition names must have ended for the conditional one to run. */
30
+ export const JourneyOutcome = { PASSED: 'passed', FAILED: 'failed' };
31
+ const ReplayStep = z.object({
32
+ kind: z.literal(ScriptStepKind.REPLAY),
33
+ flow: z.string().min(1),
34
+ /** Continue at this step on the page as it is: a branch case picking up at its checkpoint. */
35
+ at: z.number().int().positive().optional(),
36
+ /** Stop before this step. Absent: the whole flow. */
37
+ to: z.number().int().positive().optional(),
38
+ });
39
+ const ActStep = z
40
+ .object({
41
+ kind: z.literal(ScriptStepKind.ACT),
42
+ /** Exact: a target, an action and the consequence that must follow. */
43
+ target: z.record(z.string(), z.unknown()).optional(),
44
+ action: z.string().min(1).optional(),
45
+ args: z.record(z.string(), z.unknown()).optional(),
46
+ until: PredicateSchema.optional(),
47
+ /** Open: what the model should accomplish, in plain words. */
48
+ goal: z.string().min(1).optional(),
49
+ maxSteps: z.number().int().positive().max(40).optional(),
50
+ })
51
+ .refine((step) => (step.action === undefined) !== (step.goal === undefined), {
52
+ message: 'an act step is exact (`action`) or open (`goal`), never both and never neither',
53
+ });
54
+ const AssertStep = z.object({ kind: z.literal(ScriptStepKind.ASSERT), predicate: PredicateSchema });
55
+ const CheckpointStep = z.object({
56
+ kind: z.literal(ScriptStepKind.CHECKPOINT),
57
+ id: z.string().min(1),
58
+ /** How to get back here: replay this flow up to (not including) step `to`. */
59
+ reenter: z.object({ flow: z.string().min(1), to: z.number().int().positive() }),
60
+ });
61
+ const LeafStep = z.union([ReplayStep, ActStep, AssertStep]);
62
+ const BranchStep = z.object({
63
+ kind: z.literal(ScriptStepKind.BRANCH),
64
+ /** The checkpoint every case starts from. */
65
+ at: z.string().min(1),
66
+ cases: z
67
+ .array(z.object({
68
+ label: z.string().min(1),
69
+ /** Taken only when this holds once the checkpoint is re-entered. Absent: always taken. */
70
+ when: PredicateSchema.optional(),
71
+ steps: z.array(LeafStep).min(1),
72
+ }))
73
+ .min(2),
74
+ });
75
+ export const ScriptStepSchema = z.union([LeafStep, CheckpointStep, BranchStep]);
76
+ export const JourneySchema = z.object({
77
+ id: z.string().min(1),
78
+ title: z.string().min(1),
79
+ persona: z.string().optional(),
80
+ dependsOn: z.array(z.string()).default([]),
81
+ /**
82
+ * Run only when an earlier journey ended this way, else it is not taken: "if sign-in failed, the
83
+ * error says why". Unlike `dependsOn` it is not blocked by a failure; a failure can be the point.
84
+ */
85
+ when: z
86
+ .object({
87
+ journey: z.string().min(1),
88
+ is: z.enum([JourneyOutcome.PASSED, JourneyOutcome.FAILED]),
89
+ })
90
+ .optional(),
91
+ steps: z.array(ScriptStepSchema).min(1),
92
+ /**
93
+ * Replay first: when every replay in `steps` decides nothing (neither held nor failed), the model
94
+ * drives this goal instead. A replay that failed is a regression and is never re-driven. An older
95
+ * platform omits it.
96
+ */
97
+ fallback: z.object({ goal: z.string().min(1) }).optional(),
98
+ });
99
+ export const LaneSchema = z.object({
100
+ id: z.string().min(1),
101
+ /** Driven in this order, in one browser context. */
102
+ journeys: z.array(z.string()).min(1),
103
+ });
104
+ export const DriveScriptSchema = z.object({
105
+ version: z.literal(1),
106
+ source: z.enum([ScriptSource.LOCAL, ScriptSource.PLATFORM]),
107
+ personas: z.array(z.object({ name: z.string(), journey: z.string() })).default([]),
108
+ journeys: z.array(JourneySchema),
109
+ lanes: z.array(LaneSchema),
110
+ /** At most this many lanes at once. Absent: as many as the browser pool can lease. */
111
+ maxParallel: z.number().int().positive().optional(),
112
+ });
113
+ /**
114
+ * Every reason this script cannot run as written, or none.
115
+ *
116
+ * A dependency is honoured one of two ways: earlier in the same lane, or in an EARLIER lane (a
117
+ * barrier). Pointing only backwards is what makes a script acyclic and a barrier unable to wait on
118
+ * a lane that has not started, so no separate cycle check is needed.
119
+ */
120
+ export function checkScript(script) {
121
+ const problems = [];
122
+ const byId = new Map();
123
+ for (const journey of script.journeys) {
124
+ if (byId.has(journey.id))
125
+ problems.push(`journey "${journey.id}" is declared twice`);
126
+ byId.set(journey.id, journey);
127
+ }
128
+ const placed = new Set(script.lanes.flatMap((lane) => lane.journeys));
129
+ for (const journey of script.journeys) {
130
+ if (!placed.has(journey.id))
131
+ problems.push(`journey "${journey.id}" is in no lane`);
132
+ for (const dep of journey.dependsOn) {
133
+ if (!byId.has(dep))
134
+ problems.push(`journey "${journey.id}" depends on unknown "${dep}"`);
135
+ }
136
+ if (journey.when !== undefined && !byId.has(journey.when.journey))
137
+ problems.push(`journey "${journey.id}" runs when unknown "${journey.when.journey}" ends`);
138
+ problems.push(...checkBranches(journey));
139
+ }
140
+ script.lanes.forEach((lane, laneIndex) => {
141
+ lane.journeys.forEach((id, position) => {
142
+ const journey = byId.get(id);
143
+ if (journey === undefined) {
144
+ problems.push(`lane "${lane.id}" names unknown journey "${id}"`);
145
+ return;
146
+ }
147
+ const after = journey.when === undefined ? [] : [journey.when.journey];
148
+ for (const dep of [...journey.dependsOn, ...after]) {
149
+ if (!byId.has(dep))
150
+ continue;
151
+ const sameLane = lane.journeys.slice(0, position).includes(dep);
152
+ const earlierLane = script.lanes
153
+ .slice(0, laneIndex)
154
+ .some((other) => other.journeys.includes(dep));
155
+ if (!sameLane && !earlierLane) {
156
+ problems.push(`journey "${id}" in lane "${lane.id}" needs "${dep}", which is neither earlier in its lane nor in an earlier lane`);
157
+ }
158
+ }
159
+ });
160
+ });
161
+ return problems;
162
+ }
163
+ function checkBranches(journey) {
164
+ const problems = [];
165
+ const seen = new Set();
166
+ for (const step of journey.steps) {
167
+ if (ScriptStepKind.CHECKPOINT === step.kind)
168
+ seen.add(step.id);
169
+ if (ScriptStepKind.BRANCH === step.kind && !seen.has(step.at)) {
170
+ problems.push(`journey "${journey.id}" branches at "${step.at}", which is not a checkpoint before it`);
171
+ }
172
+ }
173
+ return problems;
174
+ }
175
+ /** The lane barrier a journey waits on: its dependencies that are not earlier in its own lane. */
176
+ export function barriersOf(script, laneId, journeyId) {
177
+ const lane = script.lanes.find((each) => each.id === laneId);
178
+ const journey = script.journeys.find((each) => each.id === journeyId);
179
+ if (lane === undefined || journey === undefined)
180
+ return [];
181
+ const before = lane.journeys.slice(0, lane.journeys.indexOf(journeyId));
182
+ return journey.dependsOn.filter((dep) => !before.includes(dep));
183
+ }
184
+ /** One line a person reads for a step: what it drives, in the plan's own words. */
185
+ export function stepLabel(step) {
186
+ switch (step.kind) {
187
+ case ScriptStepKind.REPLAY:
188
+ return `Replay ${step.flow}${step.at === undefined ? '' : ` from step ${String(step.at)}`}${step.to === undefined ? '' : ` to step ${String(step.to)}`}`;
189
+ case ScriptStepKind.ACT:
190
+ return step.goal ?? `${step.action ?? ''} ${targetText(step.target)}`.trim();
191
+ case ScriptStepKind.ASSERT:
192
+ return `Check ${predicateText(step.predicate)}`;
193
+ case ScriptStepKind.CHECKPOINT:
194
+ return `Checkpoint ${step.id}`;
195
+ case ScriptStepKind.BRANCH:
196
+ return `Branch at ${step.at}: ${step.cases.map((c) => c.label).join(' / ')}`;
197
+ }
198
+ }
199
+ function targetText(target) {
200
+ if (target === undefined)
201
+ return '';
202
+ const value = Object.values(target).find((v) => 'string' === typeof v);
203
+ return 'string' === typeof value ? value : '';
204
+ }
205
+ function predicateText(predicate) {
206
+ if ('object' !== typeof predicate || null === predicate)
207
+ return 'a consequence';
208
+ const record = predicate;
209
+ const query = record['query'];
210
+ const inner = 'object' === typeof query && null !== query ? query : {};
211
+ const named = record['name'] ??
212
+ record['urlContains'] ??
213
+ record['pathname'] ??
214
+ record['path'] ??
215
+ record['text'] ??
216
+ inner['testid'] ??
217
+ inner['text'];
218
+ const kind = 'string' === typeof record['kind'] ? record['kind'] : 'consequence';
219
+ return 'string' === typeof named ? `${kind} ${named}` : kind;
220
+ }
@@ -104,6 +104,24 @@ export type AnchorKind = (typeof AnchorKind)[keyof typeof AnchorKind];
104
104
  * here" marker that a human/self-healing pass re-binds. Satisfies the anchor min(1).
105
105
  */
106
106
  export declare const DEGRADED_ANCHOR_ROLE = "unresolved";
107
+ /**
108
+ * The JSON replacer every flow is written and sent with: a predicate flag at its default is left
109
+ * out. An older platform's schema rejects a key it does not know (`ignoreCase` on a text check was
110
+ * refused on every sync), so a flow that never asked for the flag must not carry it; only a check
111
+ * that really is case-insensitive depends on a platform that knows the word.
112
+ */
113
+ export declare function flowJsonReplacer(key: string, value: unknown): unknown;
114
+ /**
115
+ * How a missing flow is said, so a reader of a replay's error can tell "not on this computer" from
116
+ * "the journey failed": a whole-app run called missing flows "regressions in journeys that used to
117
+ * pass".
118
+ */
119
+ export declare const NO_SUCH_FLOW = "no such flow on disk";
120
+ /**
121
+ * A flow that calls one not on disk stops there, having never run: said with `NO_SUCH_FLOW`, so a
122
+ * plan does not call a flow that never passed a "regression in a journey that used to pass".
123
+ */
124
+ export declare const invokedFlowMissing: (name: string) => string;
107
125
  /** Structured failure codes for flow disk ops (returned, never thrown as free strings). */
108
126
  export declare const FlowErrorCode: {
109
127
  readonly INVALID_NAME: "flow_invalid_name";
@@ -162,6 +180,7 @@ export declare const ReplayStatus: {
162
180
  readonly OK: "ok";
163
181
  readonly DRIFT: "drift";
164
182
  readonly ERROR: "error";
183
+ readonly UNVERIFIABLE: "unverifiable";
165
184
  };
166
185
  export type ReplayStatus = (typeof ReplayStatus)[keyof typeof ReplayStatus];
167
186
  /**
@@ -116,6 +116,26 @@ export const AnchorKind = {
116
116
  * here" marker that a human/self-healing pass re-binds. Satisfies the anchor min(1).
117
117
  */
118
118
  export const DEGRADED_ANCHOR_ROLE = 'unresolved';
119
+ /**
120
+ * The JSON replacer every flow is written and sent with: a predicate flag at its default is left
121
+ * out. An older platform's schema rejects a key it does not know (`ignoreCase` on a text check was
122
+ * refused on every sync), so a flow that never asked for the flag must not carry it; only a check
123
+ * that really is case-insensitive depends on a platform that knows the word.
124
+ */
125
+ export function flowJsonReplacer(key, value) {
126
+ return 'ignoreCase' === key && false === value ? undefined : value;
127
+ }
128
+ /**
129
+ * How a missing flow is said, so a reader of a replay's error can tell "not on this computer" from
130
+ * "the journey failed": a whole-app run called missing flows "regressions in journeys that used to
131
+ * pass".
132
+ */
133
+ export const NO_SUCH_FLOW = 'no such flow on disk';
134
+ /**
135
+ * A flow that calls one not on disk stops there, having never run: said with `NO_SUCH_FLOW`, so a
136
+ * plan does not call a flow that never passed a "regression in a journey that used to pass".
137
+ */
138
+ export const invokedFlowMissing = (name) => `cannot replay "${name}": ${NO_SUCH_FLOW}, so this journey would report green having never run it`;
119
139
  /** Structured failure codes for flow disk ops (returned, never thrown as free strings). */
120
140
  export const FlowErrorCode = {
121
141
  INVALID_NAME: 'flow_invalid_name', // path traversal / illegal chars
@@ -173,6 +193,7 @@ export const ReplayStatus = {
173
193
  OK: 'ok', // every anchor resolved and every step ran green
174
194
  DRIFT: 'drift', // an anchor missed (testid renamed / signal not observed) — legible drift returned
175
195
  ERROR: 'error', // the flow could not load or a resolved action failed
196
+ UNVERIFIABLE: 'unverifiable', // run could not be completed or graded (precondition unmet, secrets missing, document replaced)
176
197
  };
177
198
  /**
178
199
  * Why an anchor failed to resolve at replay time (the "whose fault is