@reticlehq/core 2.14.0 → 3.2.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 (148) hide show
  1. package/dist/{artifacts-entry.d.ts → artifacts/artifacts-entry.d.ts} +7 -7
  2. package/dist/{artifacts-entry.js → artifacts/artifacts-entry.js} +7 -7
  3. package/dist/artifacts/flow-composition.d.ts +30 -0
  4. package/dist/artifacts/flow-composition.js +19 -0
  5. package/dist/{flow-constants.d.ts → artifacts/flow-constants.d.ts} +99 -3
  6. package/dist/{flow-constants.js → artifacts/flow-constants.js} +108 -4
  7. package/dist/artifacts/flow-mutation-target.d.ts +39 -0
  8. package/dist/artifacts/flow-mutation-target.js +89 -0
  9. package/dist/artifacts/flow-order.d.ts +30 -0
  10. package/dist/artifacts/flow-order.js +49 -0
  11. package/dist/artifacts/flow-select.d.ts +56 -0
  12. package/dist/artifacts/flow-select.js +56 -0
  13. package/dist/artifacts/flow-step-tool.d.ts +31 -0
  14. package/dist/artifacts/flow-step-tool.js +31 -0
  15. package/dist/artifacts/flow-types.d.ts +3736 -0
  16. package/dist/artifacts/flow-types.js +463 -0
  17. package/dist/artifacts/flow-unreached.d.ts +12 -0
  18. package/dist/artifacts/flow-unreached.js +24 -0
  19. package/dist/{impact.d.ts → artifacts/impact.d.ts} +271 -103
  20. package/dist/{impact.js → artifacts/impact.js} +75 -5
  21. package/dist/artifacts/journal.d.ts +218 -0
  22. package/dist/artifacts/journal.js +130 -0
  23. package/dist/artifacts/step-effect.d.ts +29 -0
  24. package/dist/artifacts/step-effect.js +28 -0
  25. package/dist/hooks/hook-events.d.ts +311 -0
  26. package/dist/hooks/hook-events.js +127 -0
  27. package/dist/hooks/hooks-entry.d.ts +9 -0
  28. package/dist/hooks/hooks-entry.js +9 -0
  29. package/dist/identity/brand.d.ts +102 -0
  30. package/dist/{brand.js → identity/brand.js} +7 -0
  31. package/dist/{contract-fingerprint.d.ts → identity/contract-fingerprint.d.ts} +21 -3
  32. package/dist/{contract-fingerprint.js → identity/contract-fingerprint.js} +22 -4
  33. package/dist/{document-identity.d.ts → identity/document-identity.d.ts} +4 -5
  34. package/dist/{document-identity.js → identity/document-identity.js} +4 -5
  35. package/dist/{source-constants.d.ts → identity/source-constants.d.ts} +4 -4
  36. package/dist/{source-constants.js → identity/source-constants.js} +4 -4
  37. package/dist/index.d.ts +57 -43
  38. package/dist/index.js +66 -45
  39. package/dist/onboarding.d.ts +114 -0
  40. package/dist/onboarding.js +141 -0
  41. package/dist/realm/registry.d.ts +212 -0
  42. package/dist/realm/registry.js +302 -0
  43. package/dist/{dev-server-registry.d.ts → registry/dev-server-registry.d.ts} +6 -7
  44. package/dist/{dev-server-registry.js → registry/dev-server-registry.js} +28 -19
  45. package/dist/{project-registry.d.ts → registry/project-registry.d.ts} +5 -5
  46. package/dist/{project-registry.js → registry/project-registry.js} +5 -5
  47. package/dist/schema/command-name.json +31 -0
  48. package/dist/schema/event-payloads.json +795 -0
  49. package/dist/schema/hello-message.json +70 -2
  50. package/dist/schema/reticle-message.json +70 -2
  51. package/dist/telemetry-entry.d.ts +1 -1
  52. package/dist/telemetry-entry.js +1 -1
  53. package/dist/telemetry-feedback.d.ts +15 -16
  54. package/dist/telemetry-feedback.js +11 -12
  55. package/dist/telemetry-license.d.ts +1 -1
  56. package/dist/telemetry-license.js +1 -1
  57. package/dist/telemetry-refusal.d.ts +11 -11
  58. package/dist/telemetry-refusal.js +7 -8
  59. package/dist/telemetry-session.d.ts +51 -59
  60. package/dist/telemetry-session.js +47 -55
  61. package/dist/telemetry.d.ts +306 -222
  62. package/dist/telemetry.js +112 -99
  63. package/dist/tour-entry.d.ts +10 -0
  64. package/dist/tour-entry.js +10 -0
  65. package/dist/tour.d.ts +125 -0
  66. package/dist/tour.js +165 -0
  67. package/dist/{consequence.d.ts → verdict/consequence.d.ts} +32 -15
  68. package/dist/{consequence.js → verdict/consequence.js} +9 -31
  69. package/dist/{finding-fingerprint.js → verdict/finding-fingerprint.js} +1 -1
  70. package/dist/{findings.d.ts → verdict/findings.d.ts} +86 -39
  71. package/dist/{findings.js → verdict/findings.js} +103 -49
  72. package/dist/{instrumentation-gap.d.ts → verdict/instrumentation-gap.d.ts} +7 -14
  73. package/dist/{instrumentation-gap.js → verdict/instrumentation-gap.js} +7 -15
  74. package/dist/{intent.d.ts → verdict/intent.d.ts} +35 -46
  75. package/dist/{intent.js → verdict/intent.js} +11 -22
  76. package/dist/verdict/revision.d.ts +44 -0
  77. package/dist/verdict/revision.js +53 -0
  78. package/dist/{run-context.d.ts → verdict/run-context.d.ts} +13 -34
  79. package/dist/{run-context.js → verdict/run-context.js} +15 -36
  80. package/dist/{security.js → verdict/security.js} +12 -21
  81. package/dist/{verification-run.d.ts → verdict/verification-run.d.ts} +381 -105
  82. package/dist/{verification-run.js → verdict/verification-run.js} +157 -21
  83. package/dist/{verified-constants.d.ts → verdict/verified-constants.d.ts} +34 -13
  84. package/dist/{verified-constants.js → verdict/verified-constants.js} +34 -13
  85. package/dist/{verify-progress.d.ts → verdict/verify-progress.d.ts} +18 -22
  86. package/dist/{verify-progress.js → verdict/verify-progress.js} +6 -10
  87. package/dist/wire/channel.d.ts +46 -0
  88. package/dist/wire/channel.js +95 -0
  89. package/dist/{constants.d.ts → wire/constants/constants.d.ts} +179 -28
  90. package/dist/{constants.js → wire/constants/constants.js} +199 -28
  91. package/dist/{session-constants.d.ts → wire/constants/session-constants.d.ts} +23 -2
  92. package/dist/{session-constants.js → wire/constants/session-constants.js} +23 -2
  93. package/dist/{desktop-contract.js → wire/desktop-contract.js} +1 -1
  94. package/dist/{event-classification.js → wire/event-classification.js} +1 -1
  95. package/dist/{event-payloads.d.ts → wire/event-payloads.d.ts} +72 -13
  96. package/dist/{event-payloads.js → wire/event-payloads.js} +23 -3
  97. package/dist/{event-priority.d.ts → wire/event-priority.d.ts} +1 -4
  98. package/dist/{event-priority.js → wire/event-priority.js} +2 -5
  99. package/dist/{global-press.js → wire/global-press.js} +1 -1
  100. package/dist/{messages.d.ts → wire/messages.d.ts} +240 -48
  101. package/dist/{messages.js → wire/messages.js} +68 -5
  102. package/dist/wire/narrow.d.ts +39 -0
  103. package/dist/wire/narrow.js +45 -0
  104. package/dist/{net.d.ts → wire/net.d.ts} +36 -13
  105. package/dist/{net.js → wire/net.js} +36 -13
  106. package/dist/wire/platform.d.ts +37 -0
  107. package/dist/wire/platform.js +36 -0
  108. package/dist/{redaction.js → wire/redaction.js} +12 -12
  109. package/dist/wire/snapshot-tree.d.ts +33 -0
  110. package/dist/wire/snapshot-tree.js +43 -0
  111. package/dist/wire/tool-names.d.ts +133 -0
  112. package/dist/wire/tool-names.js +142 -0
  113. package/dist/{toon.js → wire/toon.js} +1 -1
  114. package/dist/{types.d.ts → wire/types.d.ts} +77 -76
  115. package/dist/{types.js → wire/types.js} +4 -3
  116. package/dist/{no-session-reason.d.ts → words/no-session-reason.d.ts} +7 -3
  117. package/dist/{no-session-reason.js → words/no-session-reason.js} +7 -3
  118. package/dist/{notices.d.ts → words/notices.d.ts} +8 -12
  119. package/dist/{notices.js → words/notices.js} +8 -12
  120. package/package.json +16 -7
  121. package/dist/brand.d.ts +0 -49
  122. package/dist/flow-types.d.ts +0 -1711
  123. package/dist/flow-types.js +0 -247
  124. package/dist/journal.d.ts +0 -122
  125. package/dist/journal.js +0 -57
  126. package/dist/{impact-savings.d.ts → artifacts/impact-savings.d.ts} +0 -0
  127. package/dist/{impact-savings.js → artifacts/impact-savings.js} +0 -0
  128. package/dist/{edit-epoch.d.ts → identity/edit-epoch.d.ts} +0 -0
  129. package/dist/{edit-epoch.js → identity/edit-epoch.js} +0 -0
  130. package/dist/{project-id.d.ts → identity/project-id.d.ts} +0 -0
  131. package/dist/{project-id.js → identity/project-id.js} +0 -0
  132. package/dist/{daemon-registry.d.ts → registry/daemon-registry.d.ts} +0 -0
  133. package/dist/{daemon-registry.js → registry/daemon-registry.js} +0 -0
  134. package/dist/{finding-fingerprint.d.ts → verdict/finding-fingerprint.d.ts} +0 -0
  135. package/dist/{security.d.ts → verdict/security.d.ts} +0 -0
  136. package/dist/{desktop-contract.d.ts → wire/desktop-contract.d.ts} +0 -0
  137. package/dist/{event-classification.d.ts → wire/event-classification.d.ts} +0 -0
  138. package/dist/{global-press.d.ts → wire/global-press.d.ts} +0 -0
  139. package/dist/{redaction.d.ts → wire/redaction.d.ts} +0 -0
  140. package/dist/{state-select.d.ts → wire/state-select.d.ts} +0 -0
  141. package/dist/{state-select.js → wire/state-select.js} +0 -0
  142. package/dist/{toon.d.ts → wire/toon.d.ts} +0 -0
  143. package/dist/{browser-misdirect.d.ts → words/browser-misdirect.d.ts} +0 -0
  144. package/dist/{browser-misdirect.js → words/browser-misdirect.js} +0 -0
  145. package/dist/{unreachable-notice.d.ts → words/unreachable-notice.d.ts} +0 -0
  146. package/dist/{unreachable-notice.js → words/unreachable-notice.js} +0 -0
  147. package/dist/{upgrade.d.ts → words/upgrade.d.ts} +2 -2
  148. /package/dist/{upgrade.js → words/upgrade.js} +0 -0
@@ -10,11 +10,11 @@
10
10
  * exists so a Node-side importer can say which half of core it depends on, and so
11
11
  * `core-boundary.test.ts` in @reticlehq/browser can fail when the DOM side reaches for one of them.
12
12
  */
13
- export * from './daemon-registry.js';
14
- export * from './dev-server-registry.js';
15
- export * from './project-registry.js';
16
- export * from './intent.js';
17
- export * from './run-context.js';
18
- export * from './instrumentation-gap.js';
19
- export * from './upgrade.js';
13
+ export * from '../registry/daemon-registry.js';
14
+ export * from '../registry/dev-server-registry.js';
15
+ export * from '../registry/project-registry.js';
16
+ export * from '../verdict/intent.js';
17
+ export * from '../verdict/run-context.js';
18
+ export * from '../verdict/instrumentation-gap.js';
19
+ export * from '../words/upgrade.js';
20
20
  export * from './journal.js';
@@ -10,11 +10,11 @@
10
10
  * exists so a Node-side importer can say which half of core it depends on, and so
11
11
  * `core-boundary.test.ts` in @reticlehq/browser can fail when the DOM side reaches for one of them.
12
12
  */
13
- export * from './daemon-registry.js';
14
- export * from './dev-server-registry.js';
15
- export * from './project-registry.js';
16
- export * from './intent.js';
17
- export * from './run-context.js';
18
- export * from './instrumentation-gap.js';
19
- export * from './upgrade.js';
13
+ export * from '../registry/daemon-registry.js';
14
+ export * from '../registry/dev-server-registry.js';
15
+ export * from '../registry/project-registry.js';
16
+ export * from '../verdict/intent.js';
17
+ export * from '../verdict/run-context.js';
18
+ export * from '../verdict/instrumentation-gap.js';
19
+ export * from '../words/upgrade.js';
20
20
  export * from './journal.js';
@@ -0,0 +1,30 @@
1
+ import type { FlowExpect, FlowFile } from './flow-types.js';
2
+ /**
3
+ * Whether one flow may be replayed straight after another.
4
+ *
5
+ * Replaying journeys back to back only works when the state one leaves is the state the next
6
+ * expects. Two flows that each pass alone can fail composed, and the reverse, and the red looks
7
+ * like a regression — the most expensive kind, because it sends somebody to read product code that
8
+ * is fine.
9
+ *
10
+ * It answers over DECLARATIONS, not over a running app: a pure comparison of what B says it needs
11
+ * against what A says it leaves, so it can be asked before either flow runs.
12
+ *
13
+ * SILENCE IS PERMISSIVE. A flow that declares neither `requires` nor `ensures` says nothing, and
14
+ * unknown means unchecked rather than unsafe; `unmet` names the claims that could not be
15
+ * discharged, so the answer is never a bare boolean.
16
+ *
17
+ * NOT ENFORCED AT REPLAY TIME. An unmet precondition reported as a step result would read as a
18
+ * FAILURE — `FlowStepResult` has `ok: boolean` and no third state — and honestly it is `unknown`:
19
+ * nothing ran, so nothing was proved.
20
+ */
21
+ export interface CompositionCheck {
22
+ /** True when nothing B requires is left undischarged by A. Vacuously true when either is silent. */
23
+ readonly ok: boolean;
24
+ /** The claims B requires that A does not ensure. Empty when `ok`. */
25
+ readonly unmet: readonly FlowExpect[];
26
+ /** True when neither flow declared anything, so the answer is "unchecked" rather than "safe". */
27
+ readonly unchecked: boolean;
28
+ }
29
+ /** Can `next` be replayed immediately after `previous`? */
30
+ export declare function canFollow(previous: FlowFile, next: FlowFile): CompositionCheck;
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Compared by VALUE, because a precondition is a claim and two claims are the same claim when they
3
+ * say the same thing. Deep equality over a small JSON-shaped object, which is what these are: no
4
+ * functions, no cycles, no class instances. A structural compare here would need a schema-aware
5
+ * walk to be any better and would be wrong in ways that are hard to see.
6
+ */
7
+ function sameClaim(a, b) {
8
+ return JSON.stringify(a) === JSON.stringify(b);
9
+ }
10
+ /** Can `next` be replayed immediately after `previous`? */
11
+ export function canFollow(previous, next) {
12
+ const required = next.requires ?? [];
13
+ const ensured = previous.ensures ?? [];
14
+ if (0 === required.length) {
15
+ return { ok: true, unmet: [], unchecked: 0 === ensured.length };
16
+ }
17
+ const unmet = required.filter((claim) => !ensured.some((have) => sameClaim(have, claim)));
18
+ return { ok: 0 === unmet.length, unmet, unchecked: false };
19
+ }
@@ -1,8 +1,6 @@
1
1
  /**
2
2
  * On-disk artifact constants: the project history, flow files, replay/drift status, the recorder
3
- * lifecycle, heal outcomes, and the structured-annotation vocabulary. Split out of constants.ts so
4
- * each file stays one cohesive unit under the size cap; re-exported from constants.ts (and so from
5
- * the package index) — every existing `@reticlehq/core` import is unchanged.
3
+ * lifecycle, heal outcomes, and the structured-annotation vocabulary.
6
4
  */
7
5
  /**
8
6
  * Schema version stamped into project.json so a reader can reject/upgrade old files.
@@ -16,6 +14,14 @@ export declare const PROJECT_FILE_VERSION = 1;
16
14
  export declare const ProjectReadError: {
17
15
  readonly MISSING: "project-missing";
18
16
  readonly MALFORMED: "project-malformed";
17
+ /**
18
+ * Readable, and written by a version of Reticle this one does not know.
19
+ *
20
+ * Kept apart from MALFORMED because the two need opposite handling. A malformed file has nothing
21
+ * left to lose, so recording a run repairs it. A file from another version is intact, and
22
+ * repairing it would overwrite history a later release could still read.
23
+ */
24
+ readonly WRONG_VERSION: "project-wrong-version";
19
25
  };
20
26
  export type ProjectReadError = (typeof ProjectReadError)[keyof typeof ProjectReadError];
21
27
  /** How a run record was produced. */
@@ -72,6 +78,31 @@ export declare const FlowErrorCode: {
72
78
  };
73
79
  export type FlowErrorCode = (typeof FlowErrorCode)[keyof typeof FlowErrorCode];
74
80
  /** A flow name must be a single safe path segment (no '/', '\\', '..', leading dot). */
81
+ /**
82
+ * ONE safe path segment: the guard for anything that becomes a single directory or file name.
83
+ *
84
+ * Session ids and run ids are this. They are joined into `.reticle/sessions/<id>/` and written to,
85
+ * and a session LABEL is supplied by the tab — so a separator here is a tab choosing where on disk
86
+ * Reticle writes. Flow names were this too until they became namespaced, and the two guards shared
87
+ * one pattern; widening the flow pattern silently widened these, which a test caught immediately.
88
+ * They answer different questions and now have different patterns: a flow name may be a path, a
89
+ * session id may never be one.
90
+ */
91
+ export declare const SAFE_SEGMENT_PATTERN: RegExp;
92
+ /**
93
+ * A flow name: one or more `/`-separated segments.
94
+ *
95
+ * Namespaced because the replay grammar addresses documents by path — `onboarding/signup` is how a
96
+ * composite names the sub-journey it invokes, and the protocol's `FlowNameSchema` has said so since
97
+ * grammar v2. This pattern is the PERSISTENCE half, and while it stayed single-segment
98
+ * `reticle_flow_save` refused every name the language is built on. Found by driving a composite:
99
+ * recording worked, closing the boundary worked, saving it was refused.
100
+ *
101
+ * Traversal is impossible by CONSTRUCTION rather than by a filter. No segment may contain a dot at
102
+ * all, so `..` cannot be spelled; every segment must START with a letter or digit, so a leading,
103
+ * trailing or doubled separator cannot either. That is stronger than checking for `..`, because
104
+ * there is no encoding of it left to miss.
105
+ */
75
106
  export declare const FLOW_NAME_PATTERN: RegExp;
76
107
  /**
77
108
  * The outcome of replaying an on-disk flow by re-resolving its
@@ -108,8 +139,32 @@ export declare const DriftReason: {
108
139
  * step whose anchor was fine.
109
140
  */
110
141
  readonly EXPECT_ELEMENT_NOT_FOUND: "expect_element_not_found";
142
+ /**
143
+ * The step's `expect.net` named a request that was still ON THE WIRE when the budget ended.
144
+ *
145
+ * A blind spot, not a failed assertion. Reported as SIGNAL_NOT_OBSERVED it reads as "the request
146
+ * you declared never happened", which sends a reader hunting a feature that works — the live
147
+ * verdict path already refuses to grade a named in-flight request as a miss, and replay was the
148
+ * one reader that had not asked the question. The fix for this drift is a longer budget or a
149
+ * faster endpoint; the fix for SIGNAL_NOT_OBSERVED is the handler behind the action.
150
+ */
151
+ readonly NET_STILL_IN_FLIGHT: "net_still_in_flight";
111
152
  };
112
153
  export type DriftReason = (typeof DriftReason)[keyof typeof DriftReason];
154
+ /**
155
+ * Did the step's anchor resolve and its action RUN, leaving only the declared consequence unmet?
156
+ *
157
+ * The three reasons below all mean the same thing about the app's state: the element was found, the
158
+ * action was dispatched, and the page is where the step left it. Only the assertion failed. The
159
+ * other reasons mean the anchor itself was never resolved, so the page is somewhere the flow never
160
+ * described and every later step would run against a state nobody predicted.
161
+ *
162
+ * That difference is what lets a replay CONTINUE past a failure without turning one wrong result
163
+ * into several — see the sweep option on replayFlow. Halting on both was correct while there was no
164
+ * way to tell them apart; it stopped a 6-step bug sweep at its first defect and reported the other
165
+ * five as `notAttempted`.
166
+ */
167
+ export declare function isConsequenceDrift(reason: DriftReason): boolean;
113
168
  /** Default timeout (ms) a signal anchor waits to be observed at replay. */
114
169
  export declare const FLOW_SIGNAL_TIMEOUT_MS = 4000;
115
170
  /**
@@ -149,12 +204,32 @@ export type RecordedSaveError = (typeof RecordedSaveError)[keyof typeof Recorded
149
204
  * Rebinds testid anchors only (role/name/signal re-anchoring is future). A confident nearest-match
150
205
  * is required before any disk write — the "never silently rewrite" invariant.
151
206
  */
207
+ /**
208
+ * Whether a suite should run this flow at all.
209
+ *
210
+ * Absent means `active` — every flow already on disk stays exactly as it was.
211
+ *
212
+ * `quarantined` exists because a permanently failing flow is worse than no flow: measured on this
213
+ * repo's own ledger, one flow has failed 366 of 366 runs and is still replayed on every suite. That
214
+ * is not a regression signal, it is noise, and noise is what teaches people to stop reading the
215
+ * suite. Quarantine takes it out of the verdict while keeping it VISIBLE and owned -- a silent skip
216
+ * would just be the same problem with the evidence removed.
217
+ *
218
+ * `draft` is for a flow being authored: saved, not yet part of anybody's verdict.
219
+ */
220
+ export declare const FlowStatus: {
221
+ readonly ACTIVE: "active";
222
+ readonly QUARANTINED: "quarantined";
223
+ readonly DRAFT: "draft";
224
+ };
225
+ export type FlowStatus = (typeof FlowStatus)[keyof typeof FlowStatus];
152
226
  export declare const HealStatus: {
153
227
  readonly HEALED: "healed";
154
228
  readonly DRIFT: "drift";
155
229
  readonly UNHEALABLE: "unhealable";
156
230
  readonly NOTHING_TO_HEAL: "nothing_to_heal";
157
231
  readonly CONSEQUENCE_BROKEN: "consequence_broken";
232
+ readonly UNFALSIFIABLE: "unfalsifiable";
158
233
  readonly ERROR: "error";
159
234
  };
160
235
  export type HealStatus = (typeof HealStatus)[keyof typeof HealStatus];
@@ -190,3 +265,24 @@ export declare const AnnotationErrorCode: {
190
265
  export type AnnotationErrorCode = (typeof AnnotationErrorCode)[keyof typeof AnnotationErrorCode];
191
266
  /** Leading word of the compiled-predicate confirmation ("will assert …"). */
192
267
  export declare const COMPILED_PREDICATE_PREFIX = "will";
268
+ /**
269
+ * How a suite kept its flows apart from each other.
270
+ *
271
+ * Sequential replay runs every flow in ONE live session, so each starts wherever the last one left
272
+ * the app. MEASURED on the bench app: four flows that click a nav item behind a sign-in, and never
273
+ * sign in, pass sequentially because an earlier flow signed in — and fail under per-flow leases,
274
+ * which is the correct answer. The same corpus reported 13/34 and 11/34 with nothing changed but
275
+ * this, and both numbers were reproducible.
276
+ *
277
+ * Resetting between sequential flows was tried and reverted (see flow-tools.ts): storageState
278
+ * restores cookies and localStorage but not sessionStorage, which leaves an app holding two thirds
279
+ * of an auth session. So the modes genuinely differ, and the verdict names which one it is rather
280
+ * than letting two incomparable numbers look like a regression.
281
+ */
282
+ export declare const SuiteIsolation: {
283
+ /** Every flow replayed in the agent's live session, in order. State carries between them. */
284
+ readonly SHARED_SESSION: "shared-session";
285
+ /** Every flow got its own leased context, seeded once. Flows cannot affect each other. */
286
+ readonly PER_FLOW_LEASE: "per-flow-lease";
287
+ };
288
+ export type SuiteIsolation = (typeof SuiteIsolation)[keyof typeof SuiteIsolation];
@@ -1,8 +1,6 @@
1
1
  /**
2
2
  * On-disk artifact constants: the project history, flow files, replay/drift status, the recorder
3
- * lifecycle, heal outcomes, and the structured-annotation vocabulary. Split out of constants.ts so
4
- * each file stays one cohesive unit under the size cap; re-exported from constants.ts (and so from
5
- * the package index) — every existing `@reticlehq/core` import is unchanged.
3
+ * lifecycle, heal outcomes, and the structured-annotation vocabulary.
6
4
  */
7
5
  /**
8
6
  * Schema version stamped into project.json so a reader can reject/upgrade old files.
@@ -16,6 +14,14 @@ export const PROJECT_FILE_VERSION = 1;
16
14
  export const ProjectReadError = {
17
15
  MISSING: 'project-missing', // no .reticle/project.json on disk
18
16
  MALFORMED: 'project-malformed', // present but not valid JSON / fails schema
17
+ /**
18
+ * Readable, and written by a version of Reticle this one does not know.
19
+ *
20
+ * Kept apart from MALFORMED because the two need opposite handling. A malformed file has nothing
21
+ * left to lose, so recording a run repairs it. A file from another version is intact, and
22
+ * repairing it would overwrite history a later release could still read.
23
+ */
24
+ WRONG_VERSION: 'project-wrong-version',
19
25
  };
20
26
  /** How a run record was produced. */
21
27
  export const RunKind = {
@@ -67,7 +73,32 @@ export const FlowErrorCode = {
67
73
  NO_RECORDING: 'flow_no_recording', // save with no compiled program by that name
68
74
  };
69
75
  /** A flow name must be a single safe path segment (no '/', '\\', '..', leading dot). */
70
- export const FLOW_NAME_PATTERN = /^[a-z0-9][a-z0-9-_]{0,63}$/i;
76
+ /**
77
+ * ONE safe path segment: the guard for anything that becomes a single directory or file name.
78
+ *
79
+ * Session ids and run ids are this. They are joined into `.reticle/sessions/<id>/` and written to,
80
+ * and a session LABEL is supplied by the tab — so a separator here is a tab choosing where on disk
81
+ * Reticle writes. Flow names were this too until they became namespaced, and the two guards shared
82
+ * one pattern; widening the flow pattern silently widened these, which a test caught immediately.
83
+ * They answer different questions and now have different patterns: a flow name may be a path, a
84
+ * session id may never be one.
85
+ */
86
+ export const SAFE_SEGMENT_PATTERN = /^[a-z0-9][a-z0-9-_]{0,63}$/i;
87
+ /**
88
+ * A flow name: one or more `/`-separated segments.
89
+ *
90
+ * Namespaced because the replay grammar addresses documents by path — `onboarding/signup` is how a
91
+ * composite names the sub-journey it invokes, and the protocol's `FlowNameSchema` has said so since
92
+ * grammar v2. This pattern is the PERSISTENCE half, and while it stayed single-segment
93
+ * `reticle_flow_save` refused every name the language is built on. Found by driving a composite:
94
+ * recording worked, closing the boundary worked, saving it was refused.
95
+ *
96
+ * Traversal is impossible by CONSTRUCTION rather than by a filter. No segment may contain a dot at
97
+ * all, so `..` cannot be spelled; every segment must START with a letter or digit, so a leading,
98
+ * trailing or doubled separator cannot either. That is stronger than checking for `..`, because
99
+ * there is no encoding of it left to miss.
100
+ */
101
+ export const FLOW_NAME_PATTERN = /^[a-z0-9][a-z0-9-_]{0,63}(?:\/[a-z0-9][a-z0-9-_]{0,63})*$/i;
71
102
  /**
72
103
  * The outcome of replaying an on-disk flow by re-resolving its
73
104
  * semantic anchors against the live DOM. `drift` (an anchor missed → contract changed) is
@@ -102,7 +133,38 @@ export const DriftReason = {
102
133
  * step whose anchor was fine.
103
134
  */
104
135
  EXPECT_ELEMENT_NOT_FOUND: 'expect_element_not_found',
136
+ /**
137
+ * The step's `expect.net` named a request that was still ON THE WIRE when the budget ended.
138
+ *
139
+ * A blind spot, not a failed assertion. Reported as SIGNAL_NOT_OBSERVED it reads as "the request
140
+ * you declared never happened", which sends a reader hunting a feature that works — the live
141
+ * verdict path already refuses to grade a named in-flight request as a miss, and replay was the
142
+ * one reader that had not asked the question. The fix for this drift is a longer budget or a
143
+ * faster endpoint; the fix for SIGNAL_NOT_OBSERVED is the handler behind the action.
144
+ */
145
+ NET_STILL_IN_FLIGHT: 'net_still_in_flight',
105
146
  };
147
+ /**
148
+ * Did the step's anchor resolve and its action RUN, leaving only the declared consequence unmet?
149
+ *
150
+ * The three reasons below all mean the same thing about the app's state: the element was found, the
151
+ * action was dispatched, and the page is where the step left it. Only the assertion failed. The
152
+ * other reasons mean the anchor itself was never resolved, so the page is somewhere the flow never
153
+ * described and every later step would run against a state nobody predicted.
154
+ *
155
+ * That difference is what lets a replay CONTINUE past a failure without turning one wrong result
156
+ * into several — see the sweep option on replayFlow. Halting on both was correct while there was no
157
+ * way to tell them apart; it stopped a 6-step bug sweep at its first defect and reported the other
158
+ * five as `notAttempted`.
159
+ */
160
+ export function isConsequenceDrift(reason) {
161
+ return (DriftReason.SIGNAL_NOT_OBSERVED === reason ||
162
+ DriftReason.STATE_MISMATCH === reason ||
163
+ DriftReason.EXPECT_ELEMENT_NOT_FOUND === reason ||
164
+ // Same class: the anchor resolved, the action ran, and the page is where the step left it. Only
165
+ // the answer is missing. Excluding it would halt a sweep on a slow endpoint.
166
+ DriftReason.NET_STILL_IN_FLIGHT === reason);
167
+ }
106
168
  /** Default timeout (ms) a signal anchor waits to be observed at replay. */
107
169
  export const FLOW_SIGNAL_TIMEOUT_MS = 4000;
108
170
  /**
@@ -143,12 +205,34 @@ export const RecordedSaveError = {
143
205
  * Rebinds testid anchors only (role/name/signal re-anchoring is future). A confident nearest-match
144
206
  * is required before any disk write — the "never silently rewrite" invariant.
145
207
  */
208
+ /**
209
+ * Whether a suite should run this flow at all.
210
+ *
211
+ * Absent means `active` — every flow already on disk stays exactly as it was.
212
+ *
213
+ * `quarantined` exists because a permanently failing flow is worse than no flow: measured on this
214
+ * repo's own ledger, one flow has failed 366 of 366 runs and is still replayed on every suite. That
215
+ * is not a regression signal, it is noise, and noise is what teaches people to stop reading the
216
+ * suite. Quarantine takes it out of the verdict while keeping it VISIBLE and owned -- a silent skip
217
+ * would just be the same problem with the evidence removed.
218
+ *
219
+ * `draft` is for a flow being authored: saved, not yet part of anybody's verdict.
220
+ */
221
+ export const FlowStatus = {
222
+ ACTIVE: 'active',
223
+ QUARANTINED: 'quarantined',
224
+ DRAFT: 'draft',
225
+ };
146
226
  export const HealStatus = {
147
227
  HEALED: 'healed', // apply:true and >=1 anchor rewritten on disk
148
228
  DRIFT: 'drift', // apply:false: confident proposal(s) returned, file untouched
149
229
  UNHEALABLE: 'unhealable', // drift exists but no proposal cleared the confidence floor
150
230
  NOTHING_TO_HEAL: 'nothing_to_heal', // replay was green
151
231
  CONSEQUENCE_BROKEN: 'consequence_broken', // rebind resolves a locator but the flow's success consequence no longer fires — REFUSED (file untouched)
232
+ // the flow asserts nothing a wrong rebind could fail — REFUSED before replaying (file untouched).
233
+ // Distinct from CONSEQUENCE_BROKEN: there the consequence exists and stopped firing; here there is
234
+ // no consequence at all, so a heal could never be checked and would pass forever.
235
+ UNFALSIFIABLE: 'unfalsifiable',
152
236
  ERROR: 'error', // flow missing/malformed/invalid-name, or a resolved action failed
153
237
  };
154
238
  /**
@@ -181,3 +265,23 @@ export const AnnotationErrorCode = {
181
265
  };
182
266
  /** Leading word of the compiled-predicate confirmation ("will assert …"). */
183
267
  export const COMPILED_PREDICATE_PREFIX = 'will';
268
+ /**
269
+ * How a suite kept its flows apart from each other.
270
+ *
271
+ * Sequential replay runs every flow in ONE live session, so each starts wherever the last one left
272
+ * the app. MEASURED on the bench app: four flows that click a nav item behind a sign-in, and never
273
+ * sign in, pass sequentially because an earlier flow signed in — and fail under per-flow leases,
274
+ * which is the correct answer. The same corpus reported 13/34 and 11/34 with nothing changed but
275
+ * this, and both numbers were reproducible.
276
+ *
277
+ * Resetting between sequential flows was tried and reverted (see flow-tools.ts): storageState
278
+ * restores cookies and localStorage but not sessionStorage, which leaves an app holding two thirds
279
+ * of an auth session. So the modes genuinely differ, and the verdict names which one it is rather
280
+ * than letting two incomparable numbers look like a regression.
281
+ */
282
+ export const SuiteIsolation = {
283
+ /** Every flow replayed in the agent's live session, in order. State carries between them. */
284
+ SHARED_SESSION: 'shared-session',
285
+ /** Every flow got its own leased context, seeded once. Flows cannot affect each other. */
286
+ PER_FLOW_LEASE: 'per-flow-lease',
287
+ };
@@ -0,0 +1,39 @@
1
+ /**
2
+ * What a flow DECLARED it depends on, and the two things worth doing with that.
3
+ *
4
+ * Both live here because both answer the same question first — which endpoints did this flow name
5
+ * in its own words, at record time — and then diverge only in what they do next: break one
6
+ * (mutation), or slow them all by different amounts (perturbation). Splitting them would let two
7
+ * files drift about what "declared" means, which is the one thing neither can afford.
8
+ *
9
+ * This is the decision that makes a mutation score mean anything, and the single place it can
10
+ * quietly stop meaning anything. Break an endpoint the flow never touches and the flow survives —
11
+ * which reads as *"this test is worthless"* and is really *"we broke the wrong thing"*. A mutation
12
+ * set that aims badly reports a suite full of bad tests and is itself the bug.
13
+ *
14
+ * A flow that declared a network consequence has already said what it depends on, in its own words,
15
+ * at record time. That declaration is the target: break exactly what the flow claims to need, and a
16
+ * flow that still passes has genuinely proved nothing about it.
17
+ *
18
+ * A flow that declared none yields NOTHING, and that is a finding rather than a gap to paper over.
19
+ * Guessing a target would manufacture the demotion instead of measuring it.
20
+ */
21
+ import type { FlowFile } from './flow-types.js';
22
+ /** Every endpoint this flow's own declarations name, in order, once each. */
23
+ export declare function mutationTargetsFor(flow: FlowFile): string[];
24
+ /** The shape a network mock needs from us: which endpoint, and how much later. Nothing else. */
25
+ export interface Perturbation {
26
+ urlContains: string;
27
+ delayMs: number;
28
+ }
29
+ /**
30
+ * Which endpoints to slow, and by how much, for this seed.
31
+ *
32
+ * Every endpoint the flow DECLARED it depends on gets its own delay, drawn independently, so the
33
+ * spread is what reorders them. One uniform delay would slow everything equally and race nothing —
34
+ * the app would see the same order it always sees, just later.
35
+ *
36
+ * `targets` comes from what the flow itself declared (`mutationTargetsFor`), so chaos is applied to
37
+ * the endpoints the flow claims to care about rather than to traffic it never mentioned.
38
+ */
39
+ export declare function perturbationFor(seed: number, targets: readonly string[]): Perturbation[];
@@ -0,0 +1,89 @@
1
+ /**
2
+ * What a flow DECLARED it depends on, and the two things worth doing with that.
3
+ *
4
+ * Both live here because both answer the same question first — which endpoints did this flow name
5
+ * in its own words, at record time — and then diverge only in what they do next: break one
6
+ * (mutation), or slow them all by different amounts (perturbation). Splitting them would let two
7
+ * files drift about what "declared" means, which is the one thing neither can afford.
8
+ *
9
+ * This is the decision that makes a mutation score mean anything, and the single place it can
10
+ * quietly stop meaning anything. Break an endpoint the flow never touches and the flow survives —
11
+ * which reads as *"this test is worthless"* and is really *"we broke the wrong thing"*. A mutation
12
+ * set that aims badly reports a suite full of bad tests and is itself the bug.
13
+ *
14
+ * A flow that declared a network consequence has already said what it depends on, in its own words,
15
+ * at record time. That declaration is the target: break exactly what the flow claims to need, and a
16
+ * flow that still passes has genuinely proved nothing about it.
17
+ *
18
+ * A flow that declared none yields NOTHING, and that is a finding rather than a gap to paper over.
19
+ * Guessing a target would manufacture the demotion instead of measuring it.
20
+ */
21
+ /** Every endpoint this flow's own declarations name, in order, once each. */
22
+ export function mutationTargetsFor(flow) {
23
+ const targets = [];
24
+ const add = (url) => {
25
+ if (url === undefined || '' === url)
26
+ return;
27
+ if (!targets.includes(url))
28
+ targets.push(url);
29
+ };
30
+ const walk = (steps) => {
31
+ for (const step of steps) {
32
+ add(step.expect?.net?.urlContains);
33
+ // A sequence is where the real journeys live, so its children are where the real dependencies
34
+ // are declared. A walk that stopped at the top level would find nothing in the common case.
35
+ if (step.steps !== undefined)
36
+ walk(step.steps);
37
+ }
38
+ };
39
+ walk(flow.steps);
40
+ add(flow.success?.net?.urlContains);
41
+ return targets;
42
+ }
43
+ /**
44
+ * The widest delay injected, in ms.
45
+ *
46
+ * Big enough that a later request can beat an earlier one home — that is the whole mechanism — and
47
+ * small enough to stay under an ordinary settle budget, so a perturbed replay still finishes rather
48
+ * than timing out and reporting a stall it caused itself.
49
+ */
50
+ const MAX_DELAY_MS = 400;
51
+ /** The narrowest non-zero delay. Below this the scheduler noise IS the perturbation. */
52
+ const MIN_DELAY_MS = 40;
53
+ /**
54
+ * mulberry32 — small, fast, and famously well-distributed for a 32-bit seed.
55
+ *
56
+ * Written out rather than imported because the only thing that matters is that it never changes:
57
+ * a seed's meaning is a promise to whoever recorded a repro against it, and a dependency bump that
58
+ * silently reshuffled the sequence would break every one of them without a test going red.
59
+ */
60
+ function mulberry32(seed) {
61
+ let a = seed >>> 0;
62
+ return () => {
63
+ a = (a + 0x6d2b79f5) >>> 0;
64
+ let t = a;
65
+ t = Math.imul(t ^ (t >>> 15), t | 1);
66
+ t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
67
+ return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
68
+ };
69
+ }
70
+ /**
71
+ * Which endpoints to slow, and by how much, for this seed.
72
+ *
73
+ * Every endpoint the flow DECLARED it depends on gets its own delay, drawn independently, so the
74
+ * spread is what reorders them. One uniform delay would slow everything equally and race nothing —
75
+ * the app would see the same order it always sees, just later.
76
+ *
77
+ * `targets` comes from what the flow itself declared (`mutationTargetsFor`), so chaos is applied to
78
+ * the endpoints the flow claims to care about rather than to traffic it never mentioned.
79
+ */
80
+ export function perturbationFor(seed, targets) {
81
+ if (0 === targets.length)
82
+ return [];
83
+ const rand = mulberry32(seed);
84
+ const span = MAX_DELAY_MS - MIN_DELAY_MS;
85
+ return targets.map((urlContains) => ({
86
+ urlContains,
87
+ delayMs: MIN_DELAY_MS + Math.floor(rand() * span),
88
+ }));
89
+ }
@@ -0,0 +1,30 @@
1
+ /**
2
+ * The order a suite runs its flows in, from what each one declares it needs.
3
+ *
4
+ * "Checkout" assumes a signed-in user. Run it first and it fails for a reason that has nothing to do
5
+ * with checkout, which costs somebody a debugging session on working code. Directory order is not an
6
+ * answer to that — it is alphabetical luck.
7
+ *
8
+ * A FOLD, not a scheduler. It says what must come before what; a cycle or a missing prerequisite is
9
+ * REPORTED, never resolved. Inventing an order for a contradictory declaration would produce a suite
10
+ * that runs in an order nobody asked for and cannot be reasoned about when it fails — and a flow
11
+ * whose prerequisite is absent is not "run it anyway", it is a question nobody has answered.
12
+ *
13
+ * Stable among independents: declaration order is preserved, because a suite whose order shuffles
14
+ * between runs makes a flaky flow impossible to attribute — what ran before it changed too.
15
+ *
16
+ * Pure: flows in, an order and its problems out.
17
+ */
18
+ import type { FlowFile } from './flow-types.js';
19
+ export interface OrderedFlows {
20
+ /** What to run, prerequisites first. */
21
+ run: FlowFile[];
22
+ /** Flows caught in a dependency cycle. None of them run. */
23
+ cycles: string[];
24
+ /** A flow that needs something not in this run, named with what it wanted. */
25
+ unsatisfied: {
26
+ flow: string;
27
+ needs: string;
28
+ }[];
29
+ }
30
+ export declare function orderFlows(flows: readonly FlowFile[]): OrderedFlows;
@@ -0,0 +1,49 @@
1
+ /**
2
+ * The order a suite runs its flows in, from what each one declares it needs.
3
+ *
4
+ * "Checkout" assumes a signed-in user. Run it first and it fails for a reason that has nothing to do
5
+ * with checkout, which costs somebody a debugging session on working code. Directory order is not an
6
+ * answer to that — it is alphabetical luck.
7
+ *
8
+ * A FOLD, not a scheduler. It says what must come before what; a cycle or a missing prerequisite is
9
+ * REPORTED, never resolved. Inventing an order for a contradictory declaration would produce a suite
10
+ * that runs in an order nobody asked for and cannot be reasoned about when it fails — and a flow
11
+ * whose prerequisite is absent is not "run it anyway", it is a question nobody has answered.
12
+ *
13
+ * Stable among independents: declaration order is preserved, because a suite whose order shuffles
14
+ * between runs makes a flaky flow impossible to attribute — what ran before it changed too.
15
+ *
16
+ * Pure: flows in, an order and its problems out.
17
+ */
18
+ export function orderFlows(flows) {
19
+ const present = new Map(flows.map((flow) => [flow.name, flow]));
20
+ const unsatisfied = [];
21
+ for (const flow of flows) {
22
+ for (const need of flow.needs ?? []) {
23
+ if (!present.has(need))
24
+ unsatisfied.push({ flow: flow.name, needs: need });
25
+ }
26
+ }
27
+ const blocked = new Set(unsatisfied.map((entry) => entry.flow));
28
+ const run = [];
29
+ const done = new Set();
30
+ const cycles = new Set();
31
+ // Repeated passes rather than a recursive walk: a pass that places nothing means every remaining
32
+ // flow is waiting on another that is also waiting, which IS the cycle — found without having to
33
+ // track a traversal stack.
34
+ let remaining = flows.filter((flow) => !blocked.has(flow.name));
35
+ while (remaining.length > 0) {
36
+ const ready = remaining.filter((flow) => (flow.needs ?? []).every((need) => done.has(need) || !present.has(need)));
37
+ if (0 === ready.length) {
38
+ for (const flow of remaining)
39
+ cycles.add(flow.name);
40
+ break;
41
+ }
42
+ for (const flow of ready) {
43
+ run.push(flow);
44
+ done.add(flow.name);
45
+ }
46
+ remaining = remaining.filter((flow) => !done.has(flow.name));
47
+ }
48
+ return { run, cycles: [...cycles].sort(), unsatisfied };
49
+ }
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Which flows a run replays, which it refused to — and which it runs AGAIN.
3
+ *
4
+ * Two jobs that must stay distinguishable in the answer. SELECTION is what the caller asked for.
5
+ * EXCLUSION is what the suite declined to run despite being asked. A run that silently returns fewer
6
+ * flows than were selected is a run whose coverage nobody can account for — so anything held back
7
+ * comes back NAMED, never subtracted.
8
+ *
9
+ * The same reasoning applies to a selection that matched nothing. Quietly passing over a typo is how
10
+ * "all green" comes to mean "nothing ran", which is the failure this product exists to prevent
11
+ * wearing a different hat.
12
+ *
13
+ * Pure: flows and a selection in, three lists out. No store, no clock, no IO.
14
+ */
15
+ import { type FlowFile } from './flow-types.js';
16
+ export interface FlowSelection {
17
+ /** Run flows carrying ANY of these labels. A set is the union of what you named, not the overlap. */
18
+ labels?: readonly string[];
19
+ /** Run exactly these flows, by name. */
20
+ names?: readonly string[];
21
+ }
22
+ export interface SelectedFlows {
23
+ /** What will actually replay, in the order given. */
24
+ run: FlowFile[];
25
+ /** Held back by a justified quarantine, named so the verdict can report them. */
26
+ quarantined: string[];
27
+ /** Labels and names that matched nothing — a typo, or a set that no longer exists. */
28
+ unmatched: string[];
29
+ }
30
+ export declare function selectFlows(flows: readonly FlowFile[], selection: FlowSelection): SelectedFlows;
31
+ /** How many times a flow may be re-attempted, and on what evidence. */
32
+ export interface RetryPolicy {
33
+ attempts: number;
34
+ /** `flake-classified` asks the ledger first; `any` does not, and the caller owns the cost. */
35
+ on: 'any' | 'flake-classified';
36
+ }
37
+ /** What the flake ledger knows about one flow: replays on UNCHANGED code, and how many failed. */
38
+ export interface FlakeHistory {
39
+ runs: number;
40
+ fails: number;
41
+ }
42
+ /**
43
+ * Should this flow be re-attempted?
44
+ *
45
+ * Held back until there was a ledger to ask, because without one "retry on failure" is
46
+ * retry-everything with extra steps: a genuinely broken flow is run three times to fail three times,
47
+ * and the suite pays triple to learn what it already knew after the first attempt.
48
+ *
49
+ * The ledger answers the one question that makes retry honest — has this flow been seen to BOTH pass
50
+ * and fail on unchanged code? A flow that has only ever failed is not flaky, it is broken, and
51
+ * re-running it is how a suite turns a real regression into a slow one. A flow with no history has
52
+ * not been classified at all, and guessing is the same mistake with less evidence.
53
+ *
54
+ * Silence is never an opt-in: no policy means no retry.
55
+ */
56
+ export declare function shouldRetry(policy: RetryPolicy | undefined, history: FlakeHistory | undefined, attemptsSoFar: number): boolean;