@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
@@ -0,0 +1,311 @@
1
+ /**
2
+ * What Reticle says happened, and the shape it says it in.
3
+ *
4
+ * This is a CONTRACT, not an internal enum, which is why it lives in `core` beside the wire types.
5
+ * A hook payload crosses into somebody else's script, so renaming an event kind is a breaking
6
+ * change and has to be treated as one.
7
+ *
8
+ * Every event is a MOMENT SOMETHING BECAME TRUE, never a step on the way there. `verdict` is a
9
+ * verdict; there is no `verdict_starting`, no `snapshot_taken`, no per-tool-call firehose — an event
10
+ * that fires on internal progress freezes internal structure into a public contract. The bar for
11
+ * adding one is the bar for a tool: name what a consumer could not otherwise know, and that stays
12
+ * true if the implementation is rewritten.
13
+ *
14
+ * A payload carries NO credentials, ever — not the pairing token, not the cloud API key, not a
15
+ * session cookie the page was carrying. Assume anything put here ends up in a log nobody here
16
+ * controls. `hook-payload-carries-no-secret.test.ts` is the check, and it reads this file's schemas
17
+ * rather than a hand-kept list.
18
+ */
19
+ import { z } from 'zod';
20
+ /**
21
+ * The events a hook can attach to.
22
+ *
23
+ * Values are the STRING a user writes in `.reticle/hooks.json`, so they read as English and stay
24
+ * stable. A constant object rather than a TypeScript `enum` for the same reason as everything else
25
+ * here: it survives `JSON.stringify` and a consumer can compare against the literal.
26
+ */
27
+ export declare const HookEvent: {
28
+ /**
29
+ * A verdict landed — the thing this product exists to produce.
30
+ *
31
+ * Fires for ALL FOUR outcomes, `unknown` and `no-fault` included. A hook that only heard about
32
+ * passes and failures would be told a different story from the one the verdict channel tells, and
33
+ * "I could not tell" leaving the account is precisely the failure mode Reticle is built to stop.
34
+ */
35
+ readonly VERDICT: "verdict";
36
+ /**
37
+ * A defect was found. One event per defect, not one per run.
38
+ *
39
+ * Carries `repeat`, so a consumer can tell a newly-found defect from the same one seen again
40
+ * without keeping its own ledger — counting instances as defects is how a number inflates itself.
41
+ */
42
+ readonly BUG_FOUND: "bug_found";
43
+ /** A browser session attached. */
44
+ readonly SESSION_STARTED: "session_started";
45
+ /** A browser session ended, and its run artifact (if any) is on disk by the time this fires. */
46
+ readonly SESSION_ENDED: "session_ended";
47
+ /**
48
+ * A cloud sync cycle finished, with what it actually moved.
49
+ *
50
+ * Fires on a cycle that sent NOTHING too. "Nothing changed" and "sync is broken" look identical
51
+ * from outside, and a consumer that cannot tell them apart has to guess.
52
+ */
53
+ readonly SYNC_COMPLETED: "sync_completed";
54
+ };
55
+ export type HookEventName = (typeof HookEvent)[keyof typeof HookEvent];
56
+ /** Every event name, for validating a config file and for telling a user what they may write. */
57
+ export declare const HOOK_EVENT_NAMES: readonly HookEventName[];
58
+ export declare const VerdictHookPayloadSchema: z.ZodObject<{
59
+ at: z.ZodString;
60
+ projectId: z.ZodOptional<z.ZodString>;
61
+ } & {
62
+ event: z.ZodLiteral<"verdict">;
63
+ tool: z.ZodString;
64
+ verified: z.ZodString;
65
+ because: z.ZodOptional<z.ZodString>;
66
+ sessionId: z.ZodOptional<z.ZodString>;
67
+ url: z.ZodOptional<z.ZodString>;
68
+ }, "strip", z.ZodTypeAny, {
69
+ event: "verdict";
70
+ at: string;
71
+ tool: string;
72
+ verified: string;
73
+ projectId?: string | undefined;
74
+ url?: string | undefined;
75
+ sessionId?: string | undefined;
76
+ because?: string | undefined;
77
+ }, {
78
+ event: "verdict";
79
+ at: string;
80
+ tool: string;
81
+ verified: string;
82
+ projectId?: string | undefined;
83
+ url?: string | undefined;
84
+ sessionId?: string | undefined;
85
+ because?: string | undefined;
86
+ }>;
87
+ export type VerdictHookPayload = z.infer<typeof VerdictHookPayloadSchema>;
88
+ export declare const BugFoundHookPayloadSchema: z.ZodObject<{
89
+ at: z.ZodString;
90
+ projectId: z.ZodOptional<z.ZodString>;
91
+ } & {
92
+ event: z.ZodLiteral<"bug_found">;
93
+ kind: z.ZodString;
94
+ source: z.ZodOptional<z.ZodString>;
95
+ fingerprint: z.ZodOptional<z.ZodString>;
96
+ repeat: z.ZodBoolean;
97
+ route: z.ZodOptional<z.ZodString>;
98
+ tool: z.ZodString;
99
+ sessionId: z.ZodOptional<z.ZodString>;
100
+ }, "strip", z.ZodTypeAny, {
101
+ event: "bug_found";
102
+ kind: string;
103
+ at: string;
104
+ tool: string;
105
+ repeat: boolean;
106
+ route?: string | undefined;
107
+ source?: string | undefined;
108
+ projectId?: string | undefined;
109
+ sessionId?: string | undefined;
110
+ fingerprint?: string | undefined;
111
+ }, {
112
+ event: "bug_found";
113
+ kind: string;
114
+ at: string;
115
+ tool: string;
116
+ repeat: boolean;
117
+ route?: string | undefined;
118
+ source?: string | undefined;
119
+ projectId?: string | undefined;
120
+ sessionId?: string | undefined;
121
+ fingerprint?: string | undefined;
122
+ }>;
123
+ export type BugFoundHookPayload = z.infer<typeof BugFoundHookPayloadSchema>;
124
+ export declare const SessionHookPayloadSchema: z.ZodObject<{
125
+ at: z.ZodString;
126
+ projectId: z.ZodOptional<z.ZodString>;
127
+ } & {
128
+ event: z.ZodEnum<["session_started", "session_ended"]>;
129
+ sessionId: z.ZodString;
130
+ url: z.ZodOptional<z.ZodString>;
131
+ runtime: z.ZodOptional<z.ZodString>;
132
+ }, "strip", z.ZodTypeAny, {
133
+ event: "session_started" | "session_ended";
134
+ at: string;
135
+ sessionId: string;
136
+ projectId?: string | undefined;
137
+ url?: string | undefined;
138
+ runtime?: string | undefined;
139
+ }, {
140
+ event: "session_started" | "session_ended";
141
+ at: string;
142
+ sessionId: string;
143
+ projectId?: string | undefined;
144
+ url?: string | undefined;
145
+ runtime?: string | undefined;
146
+ }>;
147
+ export type SessionHookPayload = z.infer<typeof SessionHookPayloadSchema>;
148
+ export declare const SyncHookPayloadSchema: z.ZodObject<{
149
+ at: z.ZodString;
150
+ projectId: z.ZodOptional<z.ZodString>;
151
+ } & {
152
+ event: z.ZodLiteral<"sync_completed">;
153
+ runsPushed: z.ZodNumber;
154
+ ok: z.ZodBoolean;
155
+ error: z.ZodOptional<z.ZodString>;
156
+ }, "strip", z.ZodTypeAny, {
157
+ event: "sync_completed";
158
+ ok: boolean;
159
+ at: string;
160
+ runsPushed: number;
161
+ error?: string | undefined;
162
+ projectId?: string | undefined;
163
+ }, {
164
+ event: "sync_completed";
165
+ ok: boolean;
166
+ at: string;
167
+ runsPushed: number;
168
+ error?: string | undefined;
169
+ projectId?: string | undefined;
170
+ }>;
171
+ export type SyncHookPayload = z.infer<typeof SyncHookPayloadSchema>;
172
+ /** Any hook payload. A consumer narrows on `event`, which every variant carries as a literal. */
173
+ export declare const HookPayloadSchema: z.ZodDiscriminatedUnion<"event", [z.ZodObject<{
174
+ at: z.ZodString;
175
+ projectId: z.ZodOptional<z.ZodString>;
176
+ } & {
177
+ event: z.ZodLiteral<"verdict">;
178
+ tool: z.ZodString;
179
+ verified: z.ZodString;
180
+ because: z.ZodOptional<z.ZodString>;
181
+ sessionId: z.ZodOptional<z.ZodString>;
182
+ url: z.ZodOptional<z.ZodString>;
183
+ }, "strip", z.ZodTypeAny, {
184
+ event: "verdict";
185
+ at: string;
186
+ tool: string;
187
+ verified: string;
188
+ projectId?: string | undefined;
189
+ url?: string | undefined;
190
+ sessionId?: string | undefined;
191
+ because?: string | undefined;
192
+ }, {
193
+ event: "verdict";
194
+ at: string;
195
+ tool: string;
196
+ verified: string;
197
+ projectId?: string | undefined;
198
+ url?: string | undefined;
199
+ sessionId?: string | undefined;
200
+ because?: string | undefined;
201
+ }>, z.ZodObject<{
202
+ at: z.ZodString;
203
+ projectId: z.ZodOptional<z.ZodString>;
204
+ } & {
205
+ event: z.ZodLiteral<"bug_found">;
206
+ kind: z.ZodString;
207
+ source: z.ZodOptional<z.ZodString>;
208
+ fingerprint: z.ZodOptional<z.ZodString>;
209
+ repeat: z.ZodBoolean;
210
+ route: z.ZodOptional<z.ZodString>;
211
+ tool: z.ZodString;
212
+ sessionId: z.ZodOptional<z.ZodString>;
213
+ }, "strip", z.ZodTypeAny, {
214
+ event: "bug_found";
215
+ kind: string;
216
+ at: string;
217
+ tool: string;
218
+ repeat: boolean;
219
+ route?: string | undefined;
220
+ source?: string | undefined;
221
+ projectId?: string | undefined;
222
+ sessionId?: string | undefined;
223
+ fingerprint?: string | undefined;
224
+ }, {
225
+ event: "bug_found";
226
+ kind: string;
227
+ at: string;
228
+ tool: string;
229
+ repeat: boolean;
230
+ route?: string | undefined;
231
+ source?: string | undefined;
232
+ projectId?: string | undefined;
233
+ sessionId?: string | undefined;
234
+ fingerprint?: string | undefined;
235
+ }>, z.ZodObject<{
236
+ at: z.ZodString;
237
+ projectId: z.ZodOptional<z.ZodString>;
238
+ sessionId: z.ZodString;
239
+ url: z.ZodOptional<z.ZodString>;
240
+ runtime: z.ZodOptional<z.ZodString>;
241
+ } & {
242
+ event: z.ZodLiteral<"session_started">;
243
+ }, "strip", z.ZodTypeAny, {
244
+ event: "session_started";
245
+ at: string;
246
+ sessionId: string;
247
+ projectId?: string | undefined;
248
+ url?: string | undefined;
249
+ runtime?: string | undefined;
250
+ }, {
251
+ event: "session_started";
252
+ at: string;
253
+ sessionId: string;
254
+ projectId?: string | undefined;
255
+ url?: string | undefined;
256
+ runtime?: string | undefined;
257
+ }>, z.ZodObject<{
258
+ at: z.ZodString;
259
+ projectId: z.ZodOptional<z.ZodString>;
260
+ sessionId: z.ZodString;
261
+ url: z.ZodOptional<z.ZodString>;
262
+ runtime: z.ZodOptional<z.ZodString>;
263
+ } & {
264
+ event: z.ZodLiteral<"session_ended">;
265
+ }, "strip", z.ZodTypeAny, {
266
+ event: "session_ended";
267
+ at: string;
268
+ sessionId: string;
269
+ projectId?: string | undefined;
270
+ url?: string | undefined;
271
+ runtime?: string | undefined;
272
+ }, {
273
+ event: "session_ended";
274
+ at: string;
275
+ sessionId: string;
276
+ projectId?: string | undefined;
277
+ url?: string | undefined;
278
+ runtime?: string | undefined;
279
+ }>, z.ZodObject<{
280
+ at: z.ZodString;
281
+ projectId: z.ZodOptional<z.ZodString>;
282
+ } & {
283
+ event: z.ZodLiteral<"sync_completed">;
284
+ runsPushed: z.ZodNumber;
285
+ ok: z.ZodBoolean;
286
+ error: z.ZodOptional<z.ZodString>;
287
+ }, "strip", z.ZodTypeAny, {
288
+ event: "sync_completed";
289
+ ok: boolean;
290
+ at: string;
291
+ runsPushed: number;
292
+ error?: string | undefined;
293
+ projectId?: string | undefined;
294
+ }, {
295
+ event: "sync_completed";
296
+ ok: boolean;
297
+ at: string;
298
+ runsPushed: number;
299
+ error?: string | undefined;
300
+ projectId?: string | undefined;
301
+ }>]>;
302
+ export type HookPayload = z.infer<typeof HookPayloadSchema>;
303
+ /**
304
+ * The file a user writes: event name to command.
305
+ *
306
+ * A single command per event, deliberately. A list would invite "run these five things in order",
307
+ * which is a build system, and the shell already has one — a user who needs two things writes a
308
+ * script that does two things, and keeps the failure handling where they can see it.
309
+ */
310
+ export declare const HookConfigSchema: z.ZodRecord<z.ZodString, z.ZodString>;
311
+ export type HookConfig = z.infer<typeof HookConfigSchema>;
@@ -0,0 +1,127 @@
1
+ /**
2
+ * What Reticle says happened, and the shape it says it in.
3
+ *
4
+ * This is a CONTRACT, not an internal enum, which is why it lives in `core` beside the wire types.
5
+ * A hook payload crosses into somebody else's script, so renaming an event kind is a breaking
6
+ * change and has to be treated as one.
7
+ *
8
+ * Every event is a MOMENT SOMETHING BECAME TRUE, never a step on the way there. `verdict` is a
9
+ * verdict; there is no `verdict_starting`, no `snapshot_taken`, no per-tool-call firehose — an event
10
+ * that fires on internal progress freezes internal structure into a public contract. The bar for
11
+ * adding one is the bar for a tool: name what a consumer could not otherwise know, and that stays
12
+ * true if the implementation is rewritten.
13
+ *
14
+ * A payload carries NO credentials, ever — not the pairing token, not the cloud API key, not a
15
+ * session cookie the page was carrying. Assume anything put here ends up in a log nobody here
16
+ * controls. `hook-payload-carries-no-secret.test.ts` is the check, and it reads this file's schemas
17
+ * rather than a hand-kept list.
18
+ */
19
+ import { z } from 'zod';
20
+ /**
21
+ * The events a hook can attach to.
22
+ *
23
+ * Values are the STRING a user writes in `.reticle/hooks.json`, so they read as English and stay
24
+ * stable. A constant object rather than a TypeScript `enum` for the same reason as everything else
25
+ * here: it survives `JSON.stringify` and a consumer can compare against the literal.
26
+ */
27
+ export const HookEvent = {
28
+ /**
29
+ * A verdict landed — the thing this product exists to produce.
30
+ *
31
+ * Fires for ALL FOUR outcomes, `unknown` and `no-fault` included. A hook that only heard about
32
+ * passes and failures would be told a different story from the one the verdict channel tells, and
33
+ * "I could not tell" leaving the account is precisely the failure mode Reticle is built to stop.
34
+ */
35
+ VERDICT: 'verdict',
36
+ /**
37
+ * A defect was found. One event per defect, not one per run.
38
+ *
39
+ * Carries `repeat`, so a consumer can tell a newly-found defect from the same one seen again
40
+ * without keeping its own ledger — counting instances as defects is how a number inflates itself.
41
+ */
42
+ BUG_FOUND: 'bug_found',
43
+ /** A browser session attached. */
44
+ SESSION_STARTED: 'session_started',
45
+ /** A browser session ended, and its run artifact (if any) is on disk by the time this fires. */
46
+ SESSION_ENDED: 'session_ended',
47
+ /**
48
+ * A cloud sync cycle finished, with what it actually moved.
49
+ *
50
+ * Fires on a cycle that sent NOTHING too. "Nothing changed" and "sync is broken" look identical
51
+ * from outside, and a consumer that cannot tell them apart has to guess.
52
+ */
53
+ SYNC_COMPLETED: 'sync_completed',
54
+ };
55
+ /** Every event name, for validating a config file and for telling a user what they may write. */
56
+ export const HOOK_EVENT_NAMES = Object.values(HookEvent);
57
+ /**
58
+ * Carried on every payload, so a consumer reading one event off stdin knows what it is holding
59
+ * without being told out of band.
60
+ *
61
+ * `at` is an ISO timestamp rather than an epoch number because the first thing most hook scripts do
62
+ * is print it, and because a payload is a document a human may end up reading in a log.
63
+ */
64
+ const BaseHookPayload = z.object({
65
+ event: z.enum(HOOK_EVENT_NAMES),
66
+ at: z.string(),
67
+ /** The project this happened in, when one is identifiable. Absent outside a wired project. */
68
+ projectId: z.string().optional(),
69
+ });
70
+ export const VerdictHookPayloadSchema = BaseHookPayload.extend({
71
+ event: z.literal(HookEvent.VERDICT),
72
+ /** The tool that produced it — `reticle_assert`, `reticle_act_and_wait`, and so on. */
73
+ tool: z.string(),
74
+ /** `yes` | `no` | `unknown` | `no-fault`, in the protocol's own words. */
75
+ verified: z.string(),
76
+ /** The sentence the verdict gave for itself, when it gave one. */
77
+ because: z.string().optional(),
78
+ sessionId: z.string().optional(),
79
+ url: z.string().optional(),
80
+ });
81
+ export const BugFoundHookPayloadSchema = BaseHookPayload.extend({
82
+ event: z.literal(HookEvent.BUG_FOUND),
83
+ /** The finding kind from core's enum — `response-ignored`, `state-vs-render`, and so on. */
84
+ kind: z.string(),
85
+ /** Which channel reported it. */
86
+ source: z.string().optional(),
87
+ /** Stable across runs for the same defect, so a consumer can deduplicate without heuristics. */
88
+ fingerprint: z.string().optional(),
89
+ /** True when this defect kind has already been seen in this session. */
90
+ repeat: z.boolean(),
91
+ /** The route it was found on, when the result named one. */
92
+ route: z.string().optional(),
93
+ tool: z.string(),
94
+ sessionId: z.string().optional(),
95
+ });
96
+ export const SessionHookPayloadSchema = BaseHookPayload.extend({
97
+ event: z.enum([HookEvent.SESSION_STARTED, HookEvent.SESSION_ENDED]),
98
+ sessionId: z.string(),
99
+ url: z.string().optional(),
100
+ /** `web`, `electron`, `tauri` — absent on an SDK too old to report one, never defaulted. */
101
+ runtime: z.string().optional(),
102
+ });
103
+ export const SyncHookPayloadSchema = BaseHookPayload.extend({
104
+ event: z.literal(HookEvent.SYNC_COMPLETED),
105
+ /** How many run artifacts this cycle pushed. Zero is a real and useful answer. */
106
+ runsPushed: z.number().int().nonnegative(),
107
+ /** Whether the cycle completed without error. */
108
+ ok: z.boolean(),
109
+ /** Why it failed, when it did. */
110
+ error: z.string().optional(),
111
+ });
112
+ /** Any hook payload. A consumer narrows on `event`, which every variant carries as a literal. */
113
+ export const HookPayloadSchema = z.discriminatedUnion('event', [
114
+ VerdictHookPayloadSchema,
115
+ BugFoundHookPayloadSchema,
116
+ SessionHookPayloadSchema.extend({ event: z.literal(HookEvent.SESSION_STARTED) }),
117
+ SessionHookPayloadSchema.extend({ event: z.literal(HookEvent.SESSION_ENDED) }),
118
+ SyncHookPayloadSchema,
119
+ ]);
120
+ /**
121
+ * The file a user writes: event name to command.
122
+ *
123
+ * A single command per event, deliberately. A list would invite "run these five things in order",
124
+ * which is a build system, and the shell already has one — a user who needs two things writes a
125
+ * script that does two things, and keeps the failure handling where they can see it.
126
+ */
127
+ export const HookConfigSchema = z.record(z.string(), z.string());
@@ -0,0 +1,9 @@
1
+ /**
2
+ * `@reticlehq/core/hooks` — what Reticle says happened, for anyone building on top of it.
3
+ *
4
+ * A subpath rather than a root export for the same measured reason as `./tour`: the SDK imports
5
+ * core's root entry on every page load of every instrumented app, and a hook contract is read by a
6
+ * hook CONSUMER — a script, or a product embedding the daemon — which is a different audience that
7
+ * never runs in the page. Charging every developer's bundle for it would be a cost with no reader.
8
+ */
9
+ export * from './hook-events.js';
@@ -0,0 +1,9 @@
1
+ /**
2
+ * `@reticlehq/core/hooks` — what Reticle says happened, for anyone building on top of it.
3
+ *
4
+ * A subpath rather than a root export for the same measured reason as `./tour`: the SDK imports
5
+ * core's root entry on every page load of every instrumented app, and a hook contract is read by a
6
+ * hook CONSUMER — a script, or a product embedding the daemon — which is a different audience that
7
+ * never runs in the page. Charging every developer's bundle for it would be a cost with no reader.
8
+ */
9
+ export * from './hook-events.js';
@@ -0,0 +1,102 @@
1
+ /**
2
+ * Opaque/branded primitive types — give domain strings (and numbers) a NOMINAL type so a value can only
3
+ * be passed where that exact kind is expected. A plain `string` runId and a `string` flowName are
4
+ * interchangeable to the compiler and get swapped by accident (both feed path helpers!); a branded
5
+ * `RunId` vs `FlowName` cannot. This complements the "no free strings" rule (named constants for the
6
+ * allowed *set*) with type safety for the *values* that travel.
7
+ *
8
+ * Pattern:
9
+ * export type RunId = Brand<string, 'RunId'>;
10
+ * export const asRunId = (s: string): RunId => s as RunId; // mint at a trusted/validated boundary
11
+ * The brand is a phantom (erased at runtime) — `RunId` is just a string at runtime, free to serialize.
12
+ * Mint ONLY after validation (e.g. behind a `(s): s is RunId` guard) so a branded value is also a valid
13
+ * one. Zod-validated fields use `z.string.brand<'X'>` instead, so the schema is the single source.
14
+ */
15
+ declare const brand: unique symbol;
16
+ /** A nominal wrapper: `T` tagged with brand `B`, assignable FROM nowhere except an explicit mint/cast. */
17
+ export type Brand<T, B extends string> = T & {
18
+ readonly [brand]: B;
19
+ };
20
+ /**
21
+ * A flow name that has passed the path-segment guard.
22
+ *
23
+ * The doc above names this exact hazard — "a plain `string` runId and a `string` flowName are
24
+ * interchangeable to the compiler and get swapped by accident (both feed path helpers!)" — and for a
25
+ * long time only RunId was branded, so the pair the warning describes was half-fixed. `flowPath` and
26
+ * `runPath` sit beside each other and take the same shape; the compiler could not tell them apart.
27
+ *
28
+ * Both halves now carry it, along with `sessionDirPath` and the two journal path helpers under it.
29
+ * The last gap was not a missing brand but a discarded one: `RunStore.list()` already returned
30
+ * `RunId[]`, and a local `Array<{ id: string }>` annotation threw it away three lines before the
31
+ * value reached `runPath`. A brand is only worth the weakest annotation between its mint and its
32
+ * use — so `driveFlowName` and `isValidSessionId` now hand back the branded type directly, rather
33
+ * than a `string` each caller has to re-bless.
34
+ */
35
+ export type FlowName = Brand<string, 'FlowName'>;
36
+ /**
37
+ * A session id that has passed the path-segment guard. Joined straight into journal paths, so the same
38
+ * argument applies. Mint ONLY through the validating guard, never with a bare cast.
39
+ */
40
+ export type SessionId = Brand<string, 'SessionId'>;
41
+ /**
42
+ * A live element handle (`e42`) minted by the browser's ref registry.
43
+ *
44
+ * The most-passed identifier in the codebase and the one crossing browser↔bridge↔agent most often. The
45
+ * registry keys a plain `Map<string, WeakRef<Element>>`, so handing it a sessionId returns null — a
46
+ * silent miss rather than an error. Branding stops OUR code confusing the two; a ref arriving from the
47
+ * wire is still an untrusted string until the registry resolves it.
48
+ */
49
+ export type Ref = Brand<string, 'Ref'>;
50
+ /** Mint a Ref — the registry does this when it hands out a handle. */
51
+ export declare const asRef: (value: string) => Ref;
52
+ /** Mint a FlowName — call ONLY behind isValidFlowName, or on a literal in a test. */
53
+ export declare const asFlowName: (value: string) => FlowName;
54
+ /** Mint a SessionId — call ONLY behind isValidSessionId, or on a literal in a test. */
55
+ export declare const asSessionId: (value: string) => SessionId;
56
+ /**
57
+ * The stable build-stamped identity of an APP (`acme-web-9f3c1d`) — the one path identifier that
58
+ * had no brand.
59
+ *
60
+ * The incident shape: `sessionRoot(deps, sessionId)` and `rootForProjectId(deps, projectId)` sit
61
+ * two lines apart with the SAME signature (`(ToolDeps, string | undefined) => string`), so swapping
62
+ * the arguments compiles. Neither then throws. `sessionRoot` given a projectId asks the session
63
+ * manager for a session by that name, gets a throw, catches it and answers the daemon root;
64
+ * `rootForProjectId` given a sessionId matches no candidate, resolves `NO_MATCH` and answers the
65
+ * daemon root. No error, no log — artifacts land in a directory belonging to whichever tree the
66
+ * daemon was launched in, and the tool reports success. That is the same silent-wrong-root family
67
+ * `artifact-root-resolver` was written to end, arriving through the type system instead of the
68
+ * filesystem.
69
+ *
70
+ * ASYMMETRY — read this before trusting it. Branding `ProjectId` alone closes ONE direction:
71
+ *
72
+ * - CAUGHT: a plain-`string` sessionId passed where a `ProjectId` is expected. `string` is not
73
+ * assignable to `ProjectId`, so `rootForProjectId(deps, sessionId)` is a compile error. This is
74
+ * the dangerous direction, because it is the one that silently writes to the wrong project.
75
+ * - NOT CAUGHT: a `ProjectId` passed where a `sessionId` is expected. `ProjectId` IS assignable to
76
+ * `string`, so `sessionRoot(deps, projectId)` still compiles. It fails safe-ish — the lookup
77
+ * throws, is caught, and the caller gets the daemon root — but it is not a compile error.
78
+ *
79
+ * The line is drawn there because closing the second direction means branding `sessionId` at every
80
+ * tool-call boundary where it arrives as a raw `unknown` argument off the wire, which is a much
81
+ * larger change than this one. Stating it is the point: a half-closed door that claims to be shut
82
+ * is worse than one labelled honestly.
83
+ *
84
+ * Minted at PROVENANCE, not at validation, and that distinction is load-bearing here. A project id
85
+ * and a session id are both single safe path segments, so `SAFE_SEGMENT_PATTERN` cannot tell them
86
+ * apart — minting on that guard would LAUNDER a mistyped sessionId into a `ProjectId` and hand back
87
+ * exactly the confidence this brand exists to withhold. The mints are the places a value is known to
88
+ * be a project's id because of WHERE IT CAME FROM: the page's HELLO `projectId` field, the
89
+ * `projectId` key of a project's own `.reticle.json`, and the names of the subdirectories under
90
+ * `.reticle/flows/`, which the flow store is the only writer of and writes from an already-branded
91
+ * id. `safeProjectId` stays a FILTER over an already-branded value — it decides whether an id is
92
+ * safe on disk, never whether it is a project.
93
+ */
94
+ export type ProjectId = Brand<string, 'ProjectId'>;
95
+ /**
96
+ * Mint a ProjectId — call ONLY where the value's PROVENANCE says it is a project's id: the HELLO
97
+ * message's `projectId` field, `.reticle.json`'s `projectId` key, a directory Reticle itself named
98
+ * after one, or a literal in a test. Never on a string that merely passed a path-segment guard; see
99
+ * the asymmetry note above.
100
+ */
101
+ export declare const asProjectId: (value: string) => ProjectId;
102
+ export {};
@@ -18,3 +18,10 @@ export const asRef = (value) => value;
18
18
  export const asFlowName = (value) => value;
19
19
  /** Mint a SessionId — call ONLY behind isValidSessionId, or on a literal in a test. */
20
20
  export const asSessionId = (value) => value;
21
+ /**
22
+ * Mint a ProjectId — call ONLY where the value's PROVENANCE says it is a project's id: the HELLO
23
+ * message's `projectId` field, `.reticle.json`'s `projectId` key, a directory Reticle itself named
24
+ * after one, or a literal in a test. Never on a string that merely passed a path-segment guard; see
25
+ * the asymmetry note above.
26
+ */
27
+ export const asProjectId = (value) => value;
@@ -4,9 +4,9 @@
4
4
  * Reticle is installed as separate pieces — the SDK in the page, the daemon, the MCP server the
5
5
  * agent spawns — upgraded independently and therefore drifting constantly. The question that
6
6
  * matters when they meet is not "are these the same release?" but "do these speak the same
7
- * contract?", and package-version equality answers it wrongly in both directions: it fires on
8
- * 2.4.0-vs-2.4.1 where nothing changed, and it stays silent for two different BUILDS of one version
9
- * number, which is exactly what a stale daemon and a cached npx package are.
7
+ * contract?", and package-version equality answers it wrongly in both directions: it fires on two
8
+ * adjacent patch releases where nothing changed, and it stays silent for two different BUILDS of one
9
+ * version number, which is exactly what a stale daemon and a cached npx package are.
10
10
  *
11
11
  * So this hashes the vocabulary itself. Both sides compute it from their own copy of core, so equal
12
12
  * hashes mean "we agree" whatever the version strings say, and a hash that moved means a name on the
@@ -34,3 +34,21 @@ export declare function fingerprintOf(vocabulary: Record<string, readonly string
34
34
  * either side misunderstanding the other.
35
35
  */
36
36
  export declare const CONTRACT_FINGERPRINT: string;
37
+ /**
38
+ * The same vocabulary, by NAME rather than by hash — what a peer announces so skew can be decided
39
+ * structurally.
40
+ *
41
+ * A hash answers "same" or "different" and nothing else, so it cannot tell an ADDITIVE change from
42
+ * a breaking one: adding an `ActionType` an older page never needs to know about moves the hash,
43
+ * and a peer with a pinned SDK is then told "they speak DIFFERENT wire contracts — tools will
44
+ * behave in ways neither side reports" about a change that breaks nothing. Every peer MUST announce
45
+ * this list; `describeSkew` falls back to the hash branch when nothing produces it.
46
+ *
47
+ * `messageKinds` is deliberately absent: it frames the envelope rather than naming a capability, so
48
+ * a peer that did not know a message kind could not have parsed the message carrying this list.
49
+ */
50
+ export declare const CONTRACT_PARTS: {
51
+ readonly commands: readonly string[];
52
+ readonly events: readonly string[];
53
+ readonly actions: readonly string[];
54
+ };
@@ -4,9 +4,9 @@
4
4
  * Reticle is installed as separate pieces — the SDK in the page, the daemon, the MCP server the
5
5
  * agent spawns — upgraded independently and therefore drifting constantly. The question that
6
6
  * matters when they meet is not "are these the same release?" but "do these speak the same
7
- * contract?", and package-version equality answers it wrongly in both directions: it fires on
8
- * 2.4.0-vs-2.4.1 where nothing changed, and it stays silent for two different BUILDS of one version
9
- * number, which is exactly what a stale daemon and a cached npx package are.
7
+ * contract?", and package-version equality answers it wrongly in both directions: it fires on two
8
+ * adjacent patch releases where nothing changed, and it stays silent for two different BUILDS of one
9
+ * version number, which is exactly what a stale daemon and a cached npx package are.
10
10
  *
11
11
  * So this hashes the vocabulary itself. Both sides compute it from their own copy of core, so equal
12
12
  * hashes mean "we agree" whatever the version strings say, and a hash that moved means a name on the
@@ -15,7 +15,7 @@
15
15
  * Derived on purpose. A hand-maintained contract number is one somebody eventually forgets to bump,
16
16
  * and a forgotten bump is silent skew — the failure this exists to end.
17
17
  */
18
- import { ActionType, EventType, MessageKind, ReticleCommand } from './constants.js';
18
+ import { ActionType, EventType, MessageKind, ReticleCommand } from '../wire/constants/constants.js';
19
19
  /**
20
20
  * FNV-1a, 32-bit. Chosen over a crypto hash because this runs in the PAGE: `crypto.subtle` is async
21
21
  * and unavailable on insecure origins, and a dependency is not worth 40 lines. Collisions do not
@@ -54,3 +54,21 @@ export const CONTRACT_FINGERPRINT = fingerprintOf({
54
54
  actions: Object.values(ActionType),
55
55
  events: Object.values(EventType),
56
56
  });
57
+ /**
58
+ * The same vocabulary, by NAME rather than by hash — what a peer announces so skew can be decided
59
+ * structurally.
60
+ *
61
+ * A hash answers "same" or "different" and nothing else, so it cannot tell an ADDITIVE change from
62
+ * a breaking one: adding an `ActionType` an older page never needs to know about moves the hash,
63
+ * and a peer with a pinned SDK is then told "they speak DIFFERENT wire contracts — tools will
64
+ * behave in ways neither side reports" about a change that breaks nothing. Every peer MUST announce
65
+ * this list; `describeSkew` falls back to the hash branch when nothing produces it.
66
+ *
67
+ * `messageKinds` is deliberately absent: it frames the envelope rather than naming a capability, so
68
+ * a peer that did not know a message kind could not have parsed the message carrying this list.
69
+ */
70
+ export const CONTRACT_PARTS = {
71
+ commands: Object.values(ReticleCommand),
72
+ events: Object.values(EventType),
73
+ actions: Object.values(ActionType),
74
+ };
@@ -1,11 +1,10 @@
1
1
  /**
2
2
  * Which document an observation belongs to.
3
3
  *
4
- * Evidence used to be scoped by time and by ring-buffer capacity and by nothing else. A request
5
- * observed under a PREVIOUS document — or under a previous run of the application entirely — could
6
- * therefore be counted against an action taken now. Field reports describe exactly that, including
7
- * one where the failing request Reticle cited named a database row that no longer exists: true about
8
- * the bytes, false about the world, which is the worst kind of wrong a verification tool can be.
4
+ * Evidence scoped by time and ring-buffer capacity alone lets a request observed under a PREVIOUS
5
+ * document — or under a previous run of the application entirely — be counted against an action
6
+ * taken now. That is a citation that is true about the bytes and false about the world, which is
7
+ * the worst kind of wrong a verification tool can be.
9
8
  *
10
9
  * A document id is minted once per real document and dies with it. A full navigation replaces the
11
10
  * document and so replaces the id. An SPA route change does NOT, which is correct rather than a