@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
@@ -119,18 +119,70 @@ export const ImpactScopeSchema = z.object({
119
119
  /**
120
120
  * Whether this machine is signed in to a Reticle workspace, as the HUD is allowed to know it.
121
121
  *
122
- * Deliberately the smallest shape that answers the question, because it is pushed to a BROWSER: a
123
- * token here would be a token in the DOM of the user's own app, readable by anything else running
124
- * on it. There is no field for one and the reader is tested for never emitting one.
122
+ * Deliberately small, because it is pushed to a BROWSER: a token here would be a token in the DOM of
123
+ * the user's own app, readable by anything else running on it. There is no field for one and the
124
+ * reader is tested for never emitting one.
125
125
  *
126
- * `org` and `host` are present only when signed in. `host` matters because a self-hosted install is
127
- * not app.reticle.sh, and telling that user to visit a host they do not use is worse than silence.
126
+ * `org`, `email` and `host` are present only when signed in. `host` matters because a self-hosted
127
+ * install is not app.reticle.sh, and telling that user to visit a host they do not use is worse than
128
+ * silence.
129
+ *
130
+ * `email` IS personal data, and it is here because a capsule that cannot name who you are does not
131
+ * answer the question it exists to answer -- an org name is shared by a whole team. It is rendered
132
+ * only inside the account menu, never in the always-visible capsule, so it reaches the DOM on the
133
+ * same terms as the org name and no sooner. It stays OPTIONAL because no cloud sends it yet: the
134
+ * device flow returns `{ status, token, org }` and the session file stores `{ url, token, orgName }`,
135
+ * so today every reader takes the absent branch.
128
136
  */
129
137
  export const AccountStateSchema = z.object({
130
138
  signedIn: z.boolean(),
131
139
  org: z.string().optional(),
140
+ email: z.string().optional(),
132
141
  host: z.string().optional(),
133
142
  });
143
+ /**
144
+ * The standing offer on the autonomous harness, as the daemon last heard it from the platform.
145
+ *
146
+ * `claimed` is the only field that decides whether anything is shown, and ABSENCE of this whole
147
+ * object means "we do not know" — never "not claimed". That distinction is the difference between
148
+ * an offer and a nag: a machine that is offline, unlinked, or paired with an older daemon has not
149
+ * told us the person still needs this, and advertising at them anyway is how a dev-only HUD gets
150
+ * switched off for good. The account field beside this one already carries that warning; it applies
151
+ * here with more force, because this one is marketing.
152
+ */
153
+ export const HarnessOfferSchema = z.object({
154
+ /** True once this org has claimed. A claimed offer is shown as remaining time, never as a pitch. */
155
+ claimed: z.boolean(),
156
+ /** When the free period ends, epoch ms. Absent when nothing has been claimed. */
157
+ expiresAt: z.number().optional(),
158
+ /** Whole days left, already computed — the HUD has no clock worth trusting for this. */
159
+ daysRemaining: z.number().optional(),
160
+ /** Where claiming happens. Absent ⇒ the HUD shows nothing, because a pitch with no door is noise. */
161
+ claimUrl: z.string().optional(),
162
+ /**
163
+ * Whether claiming would still grant anything.
164
+ *
165
+ * Carried separately because `claimed` is "running RIGHT NOW", and an expired free period reads
166
+ * `claimed: false` — the same as never having taken it. Without this the HUD would advertise a
167
+ * three-month offer to the one group of people who can never accept it again, which is worse than
168
+ * saying nothing at all. Absent ⇒ treated as still offerable: an older platform that does not
169
+ * report it also has no expiries to get wrong.
170
+ */
171
+ eligible: z.boolean().optional(),
172
+ });
173
+ /**
174
+ * What the platform says about autonomous driving for this project.
175
+ *
176
+ * Mirrors `PlatformModelConfig` on the server side; both are the same wire answer read by different
177
+ * layers. Kept here because it crosses daemon -> browser, which is what makes it a wire type.
178
+ */
179
+ export const HarnessConfigSchema = z.object({
180
+ provider: z.string(),
181
+ /** The switch somebody set. The platform's default is on. */
182
+ harnessEnabled: z.boolean(),
183
+ /** Whether this workspace may drive on OUR model spend. Never folded into the switch. */
184
+ harnessEntitled: z.boolean(),
185
+ });
134
186
  export const ImpactSnapshotSchema = z.object({
135
187
  schemaVersion: z.number().int().positive(),
136
188
  project: ImpactScopeSchema,
@@ -149,6 +201,24 @@ export const ImpactSnapshotSchema = z.object({
149
201
  * kind of nag that gets a dev-only HUD switched off for good.
150
202
  */
151
203
  account: AccountStateSchema.optional(),
204
+ /**
205
+ * The harness offer, when the daemon knows it. Absent is "unknown" and shows nothing — see
206
+ * `HarnessOfferSchema` for why that asymmetry is deliberate.
207
+ */
208
+ harnessOffer: HarnessOfferSchema.optional(),
209
+ /**
210
+ * The harness switch and whether this workspace may drive on our spend.
211
+ *
212
+ * Two fields, never one, and the HUD renders them differently: `harnessEnabled` is a switch the
213
+ * person owns, `harnessEntitled` is a fact about their account. A panel that collapsed them would
214
+ * show "off" to somebody whose free months lapsed and invite them to turn on something they no
215
+ * longer have.
216
+ *
217
+ * Absent means the daemon has not heard -- an offline machine, an unlinked project, an older
218
+ * platform -- and the panel shows no control at all rather than guessing. Showing a switch that
219
+ * cannot be honoured is worse than showing none.
220
+ */
221
+ harnessConfig: HarnessConfigSchema.optional(),
152
222
  });
153
223
  /** Empty counters - the starting point for a fresh store and the identity for merges. */
154
224
  export function emptyImpactCounts() {
@@ -0,0 +1,218 @@
1
+ import { z } from 'zod';
2
+ /**
3
+ * The durable causal journal. Each session gets an append-only pair on disk:
4
+ * `.reticle/sessions/<id>/events.jsonl` (one `ReticleEvent` per line — already seq/actionId-stamped
5
+ * and browser-edge-redacted) and `actions.jsonl` (one JournalAction per line). The ring buffer becomes
6
+ * a hot cache over this ledger, so evidence survives eviction. Local-only; JSONL is versioned per line
7
+ * so a schema bump never orphans an old file.
8
+ */
9
+ /** Per-record schema version. JSONL is line-addressable, so versioning rides each record, not a header. */
10
+ export declare const JOURNAL_FILE_VERSION = 1;
11
+ /**
12
+ * An action entity — every act/navigate the server dispatches. `seqRange`/`tRange` are the window used
13
+ * to attribute events to this action (`attribution:"window"`); `effect` is a bounded summary of what
14
+ * the tool returned. Args are already edge-redacted by the browser before they reach here.
15
+ */
16
+ export declare const JournalActionSchema: z.ZodObject<{
17
+ v: z.ZodLiteral<1>;
18
+ /** The command correlation id (`c<n>`) — the natural, cross-side-stable action identity. */
19
+ actionId: z.ZodString;
20
+ /** The MCP tool / command name that drove it (e.g. "reticle_act"). */
21
+ tool: z.ZodString;
22
+ /** Redacted invocation args. */
23
+ args: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
24
+ /** Bounded effect summary (settle glyph, target, etc.). Kept open; narrowed by the writer. */
25
+ effect: z.ZodOptional<z.ZodUnknown>;
26
+ /** Whether the page settled within budget after the action, when known. */
27
+ settled: z.ZodOptional<z.ZodBoolean>;
28
+ /** Time from dispatch to settle in ms, when known. */
29
+ settledInMs: z.ZodOptional<z.ZodNumber>;
30
+ /** Inclusive seq range of events attributed to this action, when any were observed. */
31
+ seqRange: z.ZodOptional<z.ZodObject<{
32
+ from: z.ZodNumber;
33
+ to: z.ZodNumber;
34
+ }, "strip", z.ZodTypeAny, {
35
+ from: number;
36
+ to: number;
37
+ }, {
38
+ from: number;
39
+ to: number;
40
+ }>>;
41
+ /** Elapsed-ms window [dispatch, resolve] used for window attribution. */
42
+ tRange: z.ZodObject<{
43
+ from: z.ZodNumber;
44
+ to: z.ZodNumber;
45
+ }, "strip", z.ZodTypeAny, {
46
+ from: number;
47
+ to: number;
48
+ }, {
49
+ from: number;
50
+ to: number;
51
+ }>;
52
+ /** Elapsed-ms timestamp the action was recorded at (clock injected by the writer). */
53
+ at: z.ZodNumber;
54
+ }, "strip", z.ZodTypeAny, {
55
+ at: number;
56
+ tool: string;
57
+ args: Record<string, unknown>;
58
+ actionId: string;
59
+ v: 1;
60
+ tRange: {
61
+ from: number;
62
+ to: number;
63
+ };
64
+ settled?: boolean | undefined;
65
+ effect?: unknown;
66
+ settledInMs?: number | undefined;
67
+ seqRange?: {
68
+ from: number;
69
+ to: number;
70
+ } | undefined;
71
+ }, {
72
+ at: number;
73
+ tool: string;
74
+ actionId: string;
75
+ v: 1;
76
+ tRange: {
77
+ from: number;
78
+ to: number;
79
+ };
80
+ settled?: boolean | undefined;
81
+ effect?: unknown;
82
+ args?: Record<string, unknown> | undefined;
83
+ settledInMs?: number | undefined;
84
+ seqRange?: {
85
+ from: number;
86
+ to: number;
87
+ } | undefined;
88
+ }>;
89
+ export type JournalAction = z.infer<typeof JournalActionSchema>;
90
+ /**
91
+ * The report written beside `events.jsonl` when its byte ceiling refuses a batch.
92
+ *
93
+ * The event ledger is bounded on disk, and a bound means a ledger can be INCOMPLETE. The refusal is
94
+ * declared twice on purpose, because neither declaration can do the other's job:
95
+ *
96
+ * - IN-BAND, as one `TRUNCATED` record on the event stream, so every existing reader sees it with
97
+ * no new field and no new allowlist.
98
+ * - OUT-OF-BAND, as this file, because the in-band record carries a `t` and every journal-backed
99
+ * query filters on `t`. A window opened after the ceiling was hit contains no marker and no
100
+ * events, which is exactly a complete window in which nothing happened.
101
+ *
102
+ * Every field but `v` and `channel` is OPTIONAL, and that is a rule rather than a convenience: the
103
+ * file's PRESENCE is the durable fact ("this ledger was closed"), while its contents are a detail
104
+ * that a truncated or corrupted write can lose. A reader that cannot parse the details reports them
105
+ * absent. It must never fill them in from what is true NOW — the current ceiling is not necessarily
106
+ * the ceiling that closed the ledger — and it must never read an unparseable file as an open one.
107
+ */
108
+ export declare const JournalWriteLossSchema: z.ZodObject<{
109
+ v: z.ZodLiteral<1>;
110
+ /** Which channel lost data — the same vocabulary the in-band `TRUNCATED` record names. */
111
+ channel: z.ZodLiteral<"journal">;
112
+ /** The ceiling that refused the write, in bytes. */
113
+ capBytes: z.ZodOptional<z.ZodNumber>;
114
+ /** Bytes already in the ledger when it was closed. */
115
+ bytesOnDisk: z.ZodOptional<z.ZodNumber>;
116
+ /**
117
+ * Events in the ONE batch that was refused — never a running total of everything dropped after.
118
+ *
119
+ * An append-only file cannot revise a line it has already written, and re-emitting a fresh count
120
+ * per refusal would recreate the growth this bound exists to stop. The load-bearing fact is that
121
+ * the ledger closed; the count says how much was in the batch that closed it, and nothing more.
122
+ */
123
+ droppedInBatch: z.ZodOptional<z.ZodNumber>;
124
+ /** Elapsed-ms stamp of the last record in the first refused batch; not a loss-window boundary. */
125
+ at: z.ZodOptional<z.ZodNumber>;
126
+ }, "strip", z.ZodTypeAny, {
127
+ channel: "journal";
128
+ v: 1;
129
+ at?: number | undefined;
130
+ capBytes?: number | undefined;
131
+ bytesOnDisk?: number | undefined;
132
+ droppedInBatch?: number | undefined;
133
+ }, {
134
+ channel: "journal";
135
+ v: 1;
136
+ at?: number | undefined;
137
+ capBytes?: number | undefined;
138
+ bytesOnDisk?: number | undefined;
139
+ droppedInBatch?: number | undefined;
140
+ }>;
141
+ export type JournalWriteLoss = z.infer<typeof JournalWriteLossSchema>;
142
+ /**
143
+ * The bounded verdict summary a verification tool writes into a journal action's `effect`.
144
+ *
145
+ * `effect` is deliberately open (`unknown`) and narrowed by its writer; this is that narrowing for
146
+ * the one writer whose record has to be READ back later. Without it a verdict lives only in the tool
147
+ * response, which is exactly the place that disappears when an agent compacts, so "what did this run
148
+ * already prove" would have no ledger to fold and the answer would be silently empty.
149
+ *
150
+ * Three fields and no more: the claim the verdict was about, how it came out, and where in the
151
+ * source it pointed. A transcript here would grow the journal without making the answer better.
152
+ */
153
+ export declare const JournalVerdictEffectSchema: z.ZodObject<{
154
+ /** What was claimed, in the caller's own words — the subject a later proof supersedes. */
155
+ claim: z.ZodString;
156
+ /** The verdict, as the one field an agent reads. The enum, never a re-typed copy of it. */
157
+ verified: z.ZodNativeEnum<{
158
+ readonly YES: "yes";
159
+ readonly NO: "no";
160
+ readonly UNKNOWN: "unknown";
161
+ readonly NO_FAULT: "no-fault";
162
+ }>;
163
+ /** `file:line` for the element driven, when the page told us one. */
164
+ source: z.ZodOptional<z.ZodString>;
165
+ /**
166
+ * Was the claim written down BEFORE the action, or after it?
167
+ *
168
+ * The difference between a check and a rationalisation. Recorded here because the journal is the
169
+ * durable record a run artifact is built from: a fact that never reaches it is a fact nothing
170
+ * downstream can ever report, however well the verdict knew it at the time.
171
+ *
172
+ * Absent is not `false`. `false` says the claim came afterwards; absent says nobody recorded which.
173
+ */
174
+ declaredBeforeActing: z.ZodOptional<z.ZodBoolean>;
175
+ /**
176
+ * What kind of evidence bought the answer -- the grade the verdict actually proved.
177
+ *
178
+ * A green paid for with "something matching was on screen" is not the green paid for with "the
179
+ * request went out", and a record that keeps only the word `yes` cannot tell them apart later.
180
+ */
181
+ grade: z.ZodOptional<z.ZodString>;
182
+ /**
183
+ * What could not be seen while this was being checked.
184
+ *
185
+ * The one property with no prior art: every other kind of test record is silent about its own
186
+ * blind spots. Empty means nothing was hidden; absent means nobody looked.
187
+ */
188
+ couldNotSee: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
189
+ /**
190
+ * WHY the verdict came out this way, in the engine's own vocabulary.
191
+ *
192
+ * Without it, `unknown` is one word for facts that need opposite responses: "the outcome has
193
+ * not arrived yet" and "the capture was dirty so I could not see" are both `unknown`, and only
194
+ * the first can ever be answered by waiting. A reader of the record -- or a fold over it --
195
+ * cannot tell a question that is still open from one that was never answerable.
196
+ *
197
+ * Optional, because a record written before this existed has no reason to offer and must not
198
+ * be read as though it did.
199
+ */
200
+ reason: z.ZodOptional<z.ZodString>;
201
+ }, "strip", z.ZodTypeAny, {
202
+ claim: string;
203
+ verified: "unknown" | "yes" | "no" | "no-fault";
204
+ source?: string | undefined;
205
+ reason?: string | undefined;
206
+ declaredBeforeActing?: boolean | undefined;
207
+ grade?: string | undefined;
208
+ couldNotSee?: string[] | undefined;
209
+ }, {
210
+ claim: string;
211
+ verified: "unknown" | "yes" | "no" | "no-fault";
212
+ source?: string | undefined;
213
+ reason?: string | undefined;
214
+ declaredBeforeActing?: boolean | undefined;
215
+ grade?: string | undefined;
216
+ couldNotSee?: string[] | undefined;
217
+ }>;
218
+ export type JournalVerdictEffect = z.infer<typeof JournalVerdictEffectSchema>;
@@ -0,0 +1,130 @@
1
+ import { z } from 'zod';
2
+ import { TRANSPORT_LIMITS, TruncationChannel } from '../wire/constants/constants.js';
3
+ import { Verified } from '../verdict/verified-constants.js';
4
+ /**
5
+ * The durable causal journal. Each session gets an append-only pair on disk:
6
+ * `.reticle/sessions/<id>/events.jsonl` (one `ReticleEvent` per line — already seq/actionId-stamped
7
+ * and browser-edge-redacted) and `actions.jsonl` (one JournalAction per line). The ring buffer becomes
8
+ * a hot cache over this ledger, so evidence survives eviction. Local-only; JSONL is versioned per line
9
+ * so a schema bump never orphans an old file.
10
+ */
11
+ /** Per-record schema version. JSONL is line-addressable, so versioning rides each record, not a header. */
12
+ export const JOURNAL_FILE_VERSION = 1;
13
+ /**
14
+ * An action entity — every act/navigate the server dispatches. `seqRange`/`tRange` are the window used
15
+ * to attribute events to this action (`attribution:"window"`); `effect` is a bounded summary of what
16
+ * the tool returned. Args are already edge-redacted by the browser before they reach here.
17
+ */
18
+ export const JournalActionSchema = z.object({
19
+ v: z.literal(JOURNAL_FILE_VERSION),
20
+ /** The command correlation id (`c<n>`) — the natural, cross-side-stable action identity. */
21
+ actionId: z.string().min(1).max(TRANSPORT_LIMITS.MAX_REF_LENGTH),
22
+ /** The MCP tool / command name that drove it (e.g. "reticle_act"). */
23
+ tool: z.string().min(1).max(TRANSPORT_LIMITS.MAX_COMMAND_NAME_LENGTH),
24
+ /** Redacted invocation args. */
25
+ args: z.record(z.unknown()).default({}),
26
+ /** Bounded effect summary (settle glyph, target, etc.). Kept open; narrowed by the writer. */
27
+ effect: z.unknown().optional(),
28
+ /** Whether the page settled within budget after the action, when known. */
29
+ settled: z.boolean().optional(),
30
+ /** Time from dispatch to settle in ms, when known. */
31
+ settledInMs: z.number().int().min(0).optional(),
32
+ /** Inclusive seq range of events attributed to this action, when any were observed. */
33
+ seqRange: z.object({ from: z.number().int().min(0), to: z.number().int().min(0) }).optional(),
34
+ /** Elapsed-ms window [dispatch, resolve] used for window attribution. */
35
+ tRange: z.object({ from: z.number().int().min(0), to: z.number().int().min(0) }),
36
+ /** Elapsed-ms timestamp the action was recorded at (clock injected by the writer). */
37
+ at: z.number().int().min(0),
38
+ });
39
+ /**
40
+ * The report written beside `events.jsonl` when its byte ceiling refuses a batch.
41
+ *
42
+ * The event ledger is bounded on disk, and a bound means a ledger can be INCOMPLETE. The refusal is
43
+ * declared twice on purpose, because neither declaration can do the other's job:
44
+ *
45
+ * - IN-BAND, as one `TRUNCATED` record on the event stream, so every existing reader sees it with
46
+ * no new field and no new allowlist.
47
+ * - OUT-OF-BAND, as this file, because the in-band record carries a `t` and every journal-backed
48
+ * query filters on `t`. A window opened after the ceiling was hit contains no marker and no
49
+ * events, which is exactly a complete window in which nothing happened.
50
+ *
51
+ * Every field but `v` and `channel` is OPTIONAL, and that is a rule rather than a convenience: the
52
+ * file's PRESENCE is the durable fact ("this ledger was closed"), while its contents are a detail
53
+ * that a truncated or corrupted write can lose. A reader that cannot parse the details reports them
54
+ * absent. It must never fill them in from what is true NOW — the current ceiling is not necessarily
55
+ * the ceiling that closed the ledger — and it must never read an unparseable file as an open one.
56
+ */
57
+ export const JournalWriteLossSchema = z.object({
58
+ v: z.literal(JOURNAL_FILE_VERSION),
59
+ /** Which channel lost data — the same vocabulary the in-band `TRUNCATED` record names. */
60
+ channel: z.literal(TruncationChannel.JOURNAL),
61
+ /** The ceiling that refused the write, in bytes. */
62
+ capBytes: z.number().int().min(1).optional(),
63
+ /** Bytes already in the ledger when it was closed. */
64
+ bytesOnDisk: z.number().int().min(0).optional(),
65
+ /**
66
+ * Events in the ONE batch that was refused — never a running total of everything dropped after.
67
+ *
68
+ * An append-only file cannot revise a line it has already written, and re-emitting a fresh count
69
+ * per refusal would recreate the growth this bound exists to stop. The load-bearing fact is that
70
+ * the ledger closed; the count says how much was in the batch that closed it, and nothing more.
71
+ */
72
+ droppedInBatch: z.number().int().min(0).optional(),
73
+ /** Elapsed-ms stamp of the last record in the first refused batch; not a loss-window boundary. */
74
+ at: z.number().optional(),
75
+ });
76
+ /**
77
+ * The bounded verdict summary a verification tool writes into a journal action's `effect`.
78
+ *
79
+ * `effect` is deliberately open (`unknown`) and narrowed by its writer; this is that narrowing for
80
+ * the one writer whose record has to be READ back later. Without it a verdict lives only in the tool
81
+ * response, which is exactly the place that disappears when an agent compacts, so "what did this run
82
+ * already prove" would have no ledger to fold and the answer would be silently empty.
83
+ *
84
+ * Three fields and no more: the claim the verdict was about, how it came out, and where in the
85
+ * source it pointed. A transcript here would grow the journal without making the answer better.
86
+ */
87
+ export const JournalVerdictEffectSchema = z.object({
88
+ /** What was claimed, in the caller's own words — the subject a later proof supersedes. */
89
+ claim: z.string().min(1).max(TRANSPORT_LIMITS.MAX_STRING_LENGTH),
90
+ /** The verdict, as the one field an agent reads. The enum, never a re-typed copy of it. */
91
+ verified: z.nativeEnum(Verified),
92
+ /** `file:line` for the element driven, when the page told us one. */
93
+ source: z.string().max(TRANSPORT_LIMITS.MAX_URL_LENGTH).optional(),
94
+ /**
95
+ * Was the claim written down BEFORE the action, or after it?
96
+ *
97
+ * The difference between a check and a rationalisation. Recorded here because the journal is the
98
+ * durable record a run artifact is built from: a fact that never reaches it is a fact nothing
99
+ * downstream can ever report, however well the verdict knew it at the time.
100
+ *
101
+ * Absent is not `false`. `false` says the claim came afterwards; absent says nobody recorded which.
102
+ */
103
+ declaredBeforeActing: z.boolean().optional(),
104
+ /**
105
+ * What kind of evidence bought the answer -- the grade the verdict actually proved.
106
+ *
107
+ * A green paid for with "something matching was on screen" is not the green paid for with "the
108
+ * request went out", and a record that keeps only the word `yes` cannot tell them apart later.
109
+ */
110
+ grade: z.string().max(TRANSPORT_LIMITS.MAX_STRING_LENGTH).optional(),
111
+ /**
112
+ * What could not be seen while this was being checked.
113
+ *
114
+ * The one property with no prior art: every other kind of test record is silent about its own
115
+ * blind spots. Empty means nothing was hidden; absent means nobody looked.
116
+ */
117
+ couldNotSee: z.array(z.string().max(TRANSPORT_LIMITS.MAX_STRING_LENGTH)).optional(),
118
+ /**
119
+ * WHY the verdict came out this way, in the engine's own vocabulary.
120
+ *
121
+ * Without it, `unknown` is one word for facts that need opposite responses: "the outcome has
122
+ * not arrived yet" and "the capture was dirty so I could not see" are both `unknown`, and only
123
+ * the first can ever be answered by waiting. A reader of the record -- or a fold over it --
124
+ * cannot tell a question that is still open from one that was never answerable.
125
+ *
126
+ * Optional, because a record written before this existed has no reason to offer and must not
127
+ * be read as though it did.
128
+ */
129
+ reason: z.string().max(TRANSPORT_LIMITS.MAX_STRING_LENGTH).optional(),
130
+ });
@@ -0,0 +1,29 @@
1
+ /**
2
+ * What a step DOES to the subject, so a resume can refuse to re-run a prefix that commits.
3
+ *
4
+ * Replay resumes by re-driving the steps before the one you asked for: it does not restore state,
5
+ * because there is no way to put an app back. `flow-replay.ts` states the cost honestly — "nearly
6
+ * free, just re-run the prefix" is true of a browser and false of a subject that COMMITS, where it
7
+ * re-sends every request before step N. The flow could not SAY which steps those were, so the engine
8
+ * had no way to refuse and the guard was a sentence in a comment.
9
+ *
10
+ * Absent means UNKNOWN, and unknown behaves exactly as it always has: the prefix is re-driven.
11
+ * Assuming `commits` for an unlabelled step would refuse every flow recorded before this shipped,
12
+ * which is a worse failure than the one it prevents.
13
+ *
14
+ * IN A LEAF OF ITS OWN, and that is not tidiness. It first landed in `flow-constants.ts`, which the
15
+ * browser SDK's recorder imports for `FLOW_FILE_VERSION` — so this object was downloaded by every
16
+ * instrumented page, on every load, to support a decision only the replay engine ever makes. The
17
+ * first-load guard caught it at 79 bytes over its ceiling. The lesson is already written down beside
18
+ * that guard: naming a single value that lives beside something heavy pulls in everything its file
19
+ * holds, so put the value in a leaf of its own instead.
20
+ */
21
+ export declare const StepEffect: {
22
+ /** Reads the subject and changes nothing. Always safe to re-run. */
23
+ readonly READ: "read";
24
+ /** Changes state, but running it twice lands in the same place. Safe to re-run. */
25
+ readonly IDEMPOTENT: "idempotent";
26
+ /** Has an effect the subject keeps: a payment, a send, a create. NEVER re-run silently. */
27
+ readonly COMMITS: "commits";
28
+ };
29
+ export type StepEffect = (typeof StepEffect)[keyof typeof StepEffect];
@@ -0,0 +1,28 @@
1
+ /**
2
+ * What a step DOES to the subject, so a resume can refuse to re-run a prefix that commits.
3
+ *
4
+ * Replay resumes by re-driving the steps before the one you asked for: it does not restore state,
5
+ * because there is no way to put an app back. `flow-replay.ts` states the cost honestly — "nearly
6
+ * free, just re-run the prefix" is true of a browser and false of a subject that COMMITS, where it
7
+ * re-sends every request before step N. The flow could not SAY which steps those were, so the engine
8
+ * had no way to refuse and the guard was a sentence in a comment.
9
+ *
10
+ * Absent means UNKNOWN, and unknown behaves exactly as it always has: the prefix is re-driven.
11
+ * Assuming `commits` for an unlabelled step would refuse every flow recorded before this shipped,
12
+ * which is a worse failure than the one it prevents.
13
+ *
14
+ * IN A LEAF OF ITS OWN, and that is not tidiness. It first landed in `flow-constants.ts`, which the
15
+ * browser SDK's recorder imports for `FLOW_FILE_VERSION` — so this object was downloaded by every
16
+ * instrumented page, on every load, to support a decision only the replay engine ever makes. The
17
+ * first-load guard caught it at 79 bytes over its ceiling. The lesson is already written down beside
18
+ * that guard: naming a single value that lives beside something heavy pulls in everything its file
19
+ * holds, so put the value in a leaf of its own instead.
20
+ */
21
+ export const StepEffect = {
22
+ /** Reads the subject and changes nothing. Always safe to re-run. */
23
+ READ: 'read',
24
+ /** Changes state, but running it twice lands in the same place. Safe to re-run. */
25
+ IDEMPOTENT: 'idempotent',
26
+ /** Has an effect the subject keeps: a payment, a send, a create. NEVER re-run silently. */
27
+ COMMITS: 'commits',
28
+ };