glimmervoid 0.30.0 → 0.31.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 (66) hide show
  1. package/README.md +1 -1
  2. package/dist/bin/glimmervoid.js +140 -57
  3. package/dist/chunks/{adapters-Dho1VSY5.js → adapters-ClA_GbtA.js} +1 -1
  4. package/dist/chunks/{adapters-zPDx1Xox.js → adapters-gn7ulNO4.js} +32 -12
  5. package/dist/chunks/agent-api-cli-DAA7Jx8N.js +135 -0
  6. package/dist/chunks/{agent-api-core-Dz0r21y9.js → agent-api-core-hVcT26JW.js} +10 -1
  7. package/dist/chunks/{agent-setup-cli-B5Atxr3F.js → agent-setup-cli-CiJSDWSo.js} +11 -28
  8. package/dist/chunks/backoff-DjVpfHk7.js +14 -0
  9. package/dist/chunks/child-process-safe-BKPZ-5qQ.js +2 -0
  10. package/dist/chunks/coerce-NSst8oRP.js +32 -0
  11. package/dist/chunks/{contracts-DGkKNh9W.js → config-W1Sv-iPK.js} +358 -1682
  12. package/dist/chunks/{config-store-mm7MgzoL.js → config-store-BCy4FHNG.js} +583 -327
  13. package/dist/chunks/config-store-DbBp7LJZ.js +2 -0
  14. package/dist/chunks/contracts-3LkrilQX.js +2078 -0
  15. package/dist/chunks/{grok-DuU8xVLZ.js → grok-CXKeSt2z.js} +24 -20
  16. package/dist/chunks/{hook-relay-core-BHfYFnYV.js → hook-relay-core-DA_bz2KA.js} +10 -5
  17. package/dist/chunks/{hook-tools-pSJia7ks.js → hook-tools-UX2fmt81.js} +3 -5
  18. package/dist/chunks/{ingest-editor-core-BuI1gMF_.js → ingest-editor-core-vR6Wv6bP.js} +24 -13
  19. package/dist/chunks/json-core-dfa_7Fak.js +23 -0
  20. package/dist/chunks/json-file-oEH9vt-0.js +352 -0
  21. package/dist/chunks/knowledge-graph-cli-D2tt5hPn.js +1354 -0
  22. package/dist/chunks/{loopback-post-C7C22eYi.js → loopback-post-DepQfdcM.js} +40 -26
  23. package/dist/chunks/{main-CuIZQPhZ.js → main-DyTCWIu2.js} +28498 -21129
  24. package/dist/chunks/{node-pty-preflight-CK1knGIR.js → node-pty-preflight-C8QIlrtU.js} +4 -6
  25. package/dist/chunks/{pair-cli-w-gCAF-1.js → pair-cli-BbCBfd6l.js} +4 -3
  26. package/dist/chunks/paths-CeJl2Vcg.js +55 -0
  27. package/dist/chunks/{remote-config-C2ytQwrs.js → remote-config-DKIH_VxM.js} +36 -40
  28. package/dist/chunks/{rtk-hook-core-Bl6gYHPN.js → rtk-hook-core-BmEz2aq9.js} +3 -5
  29. package/dist/chunks/{rtk-resolver-CLo-gZzw.js → rtk-resolver-BGDzw5XK.js} +2 -2
  30. package/dist/chunks/rtk-resolver-D4Nke1Fr.js +2 -0
  31. package/dist/chunks/{runtime-paths-Ci_ksSkj.js → runtime-paths-BPoxENmK.js} +2 -6
  32. package/dist/chunks/runtime-paths-DU5jBEEO.js +2 -0
  33. package/dist/chunks/{sandbox-deps-Dd5-kZnf.js → sandbox-deps-BPKE-ylr.js} +16 -13
  34. package/dist/chunks/sandbox-proxy-core-hnQgKR0T.js +27 -0
  35. package/dist/chunks/{session-Cez8aIWg.js → session-fc4pFbon.js} +8 -2
  36. package/dist/chunks/text-DoirglWV.js +21 -0
  37. package/dist/chunks/timer-deps-u2DAQLok.js +15 -0
  38. package/dist/chunks/{visions-cli-BXQFIBCX.js → visions-cli-CT5rjiwf.js} +1 -1
  39. package/dist/chunks/{visions-setup-CvVnOe1r.js → visions-setup-BmOkI-QE.js} +20 -357
  40. package/dist/client/assets/index-C6KD8lgZ.css +1 -0
  41. package/dist/client/assets/index-CThQEAEy.js +249 -0
  42. package/dist/client/fonts/CommitMono-OFL.txt +92 -0
  43. package/dist/client/fonts/commit-mono-400-italic.woff2 +0 -0
  44. package/dist/client/fonts/commit-mono-400-regular.woff2 +0 -0
  45. package/dist/client/fonts/commit-mono-700-italic.woff2 +0 -0
  46. package/dist/client/fonts/commit-mono-700-regular.woff2 +0 -0
  47. package/dist/client/index.html +7 -24
  48. package/dist/client/octicons-LICENSE.txt +21 -0
  49. package/dist/scripts/postinstall-path-check.js +1 -1
  50. package/dist/server/index.js +3 -3
  51. package/dist/session/command-hook-relay.js +1 -1
  52. package/dist/session/hook-relay.js +3 -3
  53. package/dist/session/hook-tool-relay.js +2 -2
  54. package/dist/session/sandbox-open-launcher.js +79 -0
  55. package/dist/session/statusline-relay.js +8 -18
  56. package/dist/session/visions-relay.js +20 -11
  57. package/package.json +4 -1
  58. package/dist/chunks/agent-api-cli-D0MmtEdz.js +0 -71
  59. package/dist/chunks/child-process-safe-DvQjXsgz.js +0 -2
  60. package/dist/chunks/config-store-CC8T3okC.js +0 -2
  61. package/dist/chunks/ingest-core-DWI1Mbu4.js +0 -342
  62. package/dist/chunks/rtk-resolver-CMQAidlI.js +0 -2
  63. package/dist/chunks/runtime-paths-JLrZ3wyi.js +0 -2
  64. package/dist/client/assets/index-B1MFijjb.css +0 -1
  65. package/dist/client/assets/index-CU1iPPdn.js +0 -249
  66. package/dist/chunks/{child-process-safe-DRGsp0TE.js → child-process-safe-Ch-Zgxqs.js} +1 -1
@@ -0,0 +1,2078 @@
1
+ import { c as PendingPromptDetail, f as SessionSnapshot, h as TaskTitle, p as SessionState, u as PendingWakeup } from "./session-fc4pFbon.js";
2
+ import { D as MyPrMergeWhenReadyRequest, Dt as CoherenceRisk, Et as CoherenceReadiness, F as CommitSha, O as MyPrMergeWhenReadyResult, P as MyPrsStatus, Q as TeamReviewActionResult, S as MyPrKeepMergeableResult, T as MyPrMergeResult, Tt as CoherenceOrient, Z as TeamReviewActionRequest, _t as ReviewsRefreshResult, gt as ReviewsRefreshRequest, jt as CoherenceWorkState, mt as REPO_SLUG_RE, n as BUILTIN_AGENT_IDS, nt as TeamReviewStatus, vt as reviewsPollingShape, w as MyPrMergeRequest, x as MyPrKeepMergeableRequest } from "./config-W1Sv-iPK.js";
3
+ import { z } from "zod";
4
+ //#region shared/contracts/factory.ts
5
+ var FactoryIssue = z.object({
6
+ issueId: z.string().min(1),
7
+ firstSeenMs: z.number().finite(),
8
+ framePaths: z.array(z.string())
9
+ });
10
+ var FactoryWatchEntry = z.object({
11
+ workId: z.string().min(1),
12
+ intentId: z.string().min(1),
13
+ projectId: z.string().min(1),
14
+ mergedSha: z.string().regex(/^[a-f0-9]{40,64}$/),
15
+ mergedAt: z.iso.datetime(),
16
+ writeScopes: z.array(z.string()),
17
+ breaches: z.array(FactoryIssue).optional()
18
+ });
19
+ var FactoryHogQLResponse = z.looseObject({ results: z.array(z.unknown()) });
20
+ var FactoryIssueQueryRow = z.object({
21
+ issueId: z.string().min(1),
22
+ firstSeen: z.string().min(1),
23
+ framePaths: z.array(z.string())
24
+ });
25
+ var FactoryConsequences = z.looseObject({ records: z.array(z.looseObject({
26
+ from: z.object({
27
+ kind: z.string(),
28
+ id: z.string()
29
+ }),
30
+ relation: z.string(),
31
+ to: z.object({
32
+ kind: z.string(),
33
+ id: z.string()
34
+ }),
35
+ session: z.string().optional(),
36
+ evidence: z.string().optional()
37
+ })) });
38
+ var FactoryProjectState = z.object({
39
+ projectId: z.string(),
40
+ projectName: z.string(),
41
+ headSha: z.string().nullable(),
42
+ paused: z.boolean(),
43
+ orchestrator: z.object({
44
+ sessionId: z.string(),
45
+ intentId: z.string(),
46
+ state: SessionState
47
+ }).nullable(),
48
+ liveWorkers: z.array(z.object({
49
+ workId: z.string(),
50
+ sessionId: z.string()
51
+ })).optional(),
52
+ reviewing: z.array(z.string()).optional(),
53
+ watches: z.array(FactoryWatchEntry).optional(),
54
+ note: z.string().nullable().optional(),
55
+ spentTodayUsd: z.number().finite().nonnegative().optional(),
56
+ dailyBudgetUsd: z.number().finite().nonnegative().nullable().optional(),
57
+ verifierIntentIds: z.array(z.string()).optional(),
58
+ error: z.string().nullable(),
59
+ heading: z.object({
60
+ action: CoherenceOrient.shape.action,
61
+ reasons: z.array(z.string())
62
+ }),
63
+ orders: z.array(z.object({
64
+ id: z.string(),
65
+ objective: z.string(),
66
+ openedAt: z.iso.datetime(),
67
+ criteria: z.array(z.string()),
68
+ boundary: z.string(),
69
+ risk: CoherenceRisk,
70
+ state: CoherenceWorkState,
71
+ readiness: CoherenceReadiness,
72
+ parent: z.string().nullable(),
73
+ dependsOn: z.array(z.string()),
74
+ writeScopes: z.array(z.string()),
75
+ owner: z.string().nullable(),
76
+ lastEvent: z.object({
77
+ event: z.string(),
78
+ at: z.string(),
79
+ session: z.string()
80
+ }).nullable()
81
+ })),
82
+ conflicts: z.array(z.object({
83
+ left: z.string(),
84
+ right: z.string(),
85
+ scope: z.string()
86
+ })),
87
+ unverifiedCompletedWork: z.array(z.string())
88
+ });
89
+ var FactoryState = z.object({
90
+ type: z.literal("factory-state"),
91
+ ts: z.number().finite(),
92
+ projects: z.array(FactoryProjectState)
93
+ });
94
+ var FACTORY_ERROR_MAX_CHARS = 16384;
95
+ function isSingleFactoryPathSegment(value) {
96
+ return value !== "." && value !== ".." && !/[/\\]/.test(value);
97
+ }
98
+ var projectId = z.string().trim().min(1).max(128).refine(isSingleFactoryPathSegment, "Invalid factory project id");
99
+ var intentText = z.string().trim().min(1).max(4096);
100
+ var scopeText = z.string().trim().min(1).max(1024);
101
+ var FACTORY_INTENT_TICKET_LIMIT = 32;
102
+ var ticketKey = z.string().trim().min(1).max(64);
103
+ var FactoryIntentTicket = z.object({
104
+ id: ticketKey,
105
+ objective: intentText,
106
+ criteria: z.array(intentText).min(1).max(12),
107
+ dependsOn: z.array(ticketKey).max(FACTORY_INTENT_TICKET_LIMIT),
108
+ writeScopes: z.array(scopeText).min(1).max(32)
109
+ });
110
+ var FactoryQueueIntentRequest = z.object({
111
+ projectId,
112
+ objective: intentText,
113
+ criteria: z.array(intentText).min(1).max(12),
114
+ risk: CoherenceRisk,
115
+ boundary: intentText,
116
+ writeScopes: z.array(scopeText).max(32),
117
+ tickets: z.array(FactoryIntentTicket).min(1).max(FACTORY_INTENT_TICKET_LIMIT).optional()
118
+ });
119
+ var FactoryQueueIntentResult = z.object({
120
+ projectId: z.string().max(128),
121
+ ok: z.boolean(),
122
+ workId: z.string().min(1).max(128).optional(),
123
+ error: z.string().max(FACTORY_ERROR_MAX_CHARS).optional()
124
+ });
125
+ var FactoryControlRequest = z.object({
126
+ projectId,
127
+ action: z.enum(["pause", "resume"])
128
+ });
129
+ var FactoryControlResult = z.object({
130
+ projectId: z.string().max(128),
131
+ action: FactoryControlRequest.shape.action,
132
+ ok: z.boolean(),
133
+ error: z.string().max(FACTORY_ERROR_MAX_CHARS).optional()
134
+ });
135
+ var FactoryReviewVerdict = z.object({
136
+ pass: z.boolean(),
137
+ findings: z.array(z.string())
138
+ }).strict();
139
+ var FactoryReviewerOutput = z.object({
140
+ type: z.literal("result"),
141
+ subtype: z.literal("success"),
142
+ is_error: z.literal(false),
143
+ structured_output: FactoryReviewVerdict
144
+ });
145
+ var FactoryLaneState = z.object({
146
+ ledgerPath: z.string().min(1).max(4096).nullable(),
147
+ ledgerBranch: z.string().min(1).max(1024).nullable(),
148
+ paused: z.boolean(),
149
+ watch: z.array(FactoryWatchEntry).optional(),
150
+ trustedVerifications: z.array(z.object({
151
+ id: z.string().min(1),
152
+ sha: z.string().regex(/^[a-f0-9]{40,64}$/)
153
+ })).optional(),
154
+ trustedIntentCloses: z.array(z.string().min(1)).optional(),
155
+ trustedIntentIds: z.array(z.string().min(1)).optional(),
156
+ intentWriteScopes: z.record(z.string().min(1), z.array(z.string().min(1))).optional(),
157
+ ticketedIntentIds: z.array(z.string().min(1)).optional(),
158
+ pendingIntentTickets: z.record(z.string().min(1), z.object({
159
+ risk: CoherenceRisk,
160
+ boundary: intentText,
161
+ tickets: z.array(FactoryIntentTicket).min(1).max(FACTORY_INTENT_TICKET_LIMIT)
162
+ })).optional(),
163
+ intentBaseShas: z.record(z.string().min(1), z.string().regex(/^[a-f0-9]{40,64}$/)).optional(),
164
+ filedBreaches: z.array(z.string().min(1)).optional(),
165
+ factoryLandedShas: z.array(z.string().regex(/^[a-f0-9]{40,64}$/)).optional()
166
+ });
167
+ var FactoryWorkerEvent = z.object({
168
+ workId: z.string().min(1),
169
+ event: z.string().min(1),
170
+ sessionId: z.string().optional(),
171
+ detail: z.string().optional()
172
+ });
173
+ z.discriminatedUnion("ok", [z.object({
174
+ ok: z.literal(true),
175
+ sessionId: z.string()
176
+ }), z.object({
177
+ ok: z.literal(false),
178
+ reason: z.string()
179
+ })]);
180
+ //#endregion
181
+ //#region shared/contracts/factory-decision-log.ts
182
+ var FACTORY_DECISION_OUTPUT_MAX_BYTES = 16384;
183
+ var FactoryDecisionKind = z.enum([
184
+ "admission",
185
+ "closeout",
186
+ "merge",
187
+ "watch",
188
+ "verification",
189
+ "exception",
190
+ "landing",
191
+ "trust"
192
+ ]);
193
+ var FactoryDecisionOutcome = z.enum([
194
+ "refused",
195
+ "available",
196
+ "dispatched",
197
+ "ended",
198
+ "retry",
199
+ "block",
200
+ "merge",
201
+ "merged",
202
+ "breach",
203
+ "verified",
204
+ "verified-unwatched",
205
+ "failed",
206
+ "stale",
207
+ "passed",
208
+ "raised",
209
+ "stalled",
210
+ "recovered",
211
+ "granted"
212
+ ]);
213
+ var FactoryDecisionFailureClass = z.enum([
214
+ "admission",
215
+ "worker",
216
+ "fence",
217
+ "check",
218
+ "review",
219
+ "closeout",
220
+ "breach",
221
+ "verification",
222
+ "stale",
223
+ "exception",
224
+ "stall",
225
+ "landing"
226
+ ]);
227
+ var decisionCheck = z.strictObject({
228
+ command: z.string(),
229
+ pass: z.boolean(),
230
+ output: z.string()
231
+ });
232
+ var decisionFence = z.discriminatedUnion("ok", [z.strictObject({ ok: z.literal(true) }), z.strictObject({
233
+ ok: z.literal(false),
234
+ outside: z.array(z.string()),
235
+ protected: z.array(z.string()),
236
+ unsupportedProtectedPaths: z.array(z.string())
237
+ })]);
238
+ var decisionFields = {
239
+ timestamp: z.iso.datetime(),
240
+ projectId: z.string().min(1).max(128).refine(isSingleFactoryPathSegment),
241
+ outcome: FactoryDecisionOutcome,
242
+ workId: z.string().min(1).nullable(),
243
+ intentId: z.string().min(1).nullable(),
244
+ sessionId: z.string().min(1).nullable(),
245
+ attempt: z.number().int().positive().nullable(),
246
+ durationMs: z.number().int().nonnegative().nullable(),
247
+ failureClass: FactoryDecisionFailureClass.nullable(),
248
+ reason: z.string().max(1e3).nullable()
249
+ };
250
+ var FactoryDecisionLogLine = z.discriminatedUnion("kind", [
251
+ z.strictObject({
252
+ ...decisionFields,
253
+ kind: z.literal("admission"),
254
+ outcome: z.enum([
255
+ "refused",
256
+ "available",
257
+ "dispatched",
258
+ "ended",
259
+ "block"
260
+ ])
261
+ }),
262
+ z.strictObject({
263
+ ...decisionFields,
264
+ kind: z.literal("closeout"),
265
+ outcome: z.enum([
266
+ "retry",
267
+ "block",
268
+ "merge"
269
+ ]),
270
+ attempt: z.number().int().positive(),
271
+ durationMs: z.number().int().nonnegative(),
272
+ fence: decisionFence.nullable(),
273
+ checks: z.array(decisionCheck).refine((checks) => checks.reduce((totalBytes, check) => totalBytes + new TextEncoder().encode(check.output).length, 0) <= FACTORY_DECISION_OUTPUT_MAX_BYTES),
274
+ review: FactoryReviewVerdict.nullable()
275
+ }),
276
+ z.strictObject({
277
+ ...decisionFields,
278
+ kind: z.literal("merge"),
279
+ outcome: z.literal("merged"),
280
+ mergedSha: z.string().regex(/^[a-f0-9]{40,64}$/)
281
+ }),
282
+ z.strictObject({
283
+ ...decisionFields,
284
+ kind: z.literal("watch"),
285
+ outcome: z.enum([
286
+ "breach",
287
+ "verified",
288
+ "verified-unwatched"
289
+ ])
290
+ }),
291
+ z.strictObject({
292
+ ...decisionFields,
293
+ kind: z.literal("verification"),
294
+ outcome: z.enum([
295
+ "failed",
296
+ "stale",
297
+ "passed"
298
+ ])
299
+ }),
300
+ z.strictObject({
301
+ ...decisionFields,
302
+ kind: z.literal("exception"),
303
+ outcome: z.enum(["raised", "stalled"])
304
+ }),
305
+ z.strictObject({
306
+ ...decisionFields,
307
+ kind: z.literal("landing"),
308
+ outcome: z.enum(["failed", "recovered"])
309
+ }),
310
+ z.strictObject({
311
+ ...decisionFields,
312
+ kind: z.literal("trust"),
313
+ outcome: z.literal("granted")
314
+ })
315
+ ]).superRefine((line, context) => {
316
+ const isFailure = [
317
+ "refused",
318
+ "retry",
319
+ "block",
320
+ "breach",
321
+ "failed",
322
+ "stale",
323
+ "raised",
324
+ "stalled"
325
+ ].includes(line.outcome);
326
+ if (isFailure && line.failureClass === null) context.addIssue({
327
+ code: "custom",
328
+ path: ["failureClass"],
329
+ message: "Failure requires a failure class"
330
+ });
331
+ if (!isFailure && line.outcome !== "ended" && line.failureClass !== null) context.addIssue({
332
+ code: "custom",
333
+ path: ["failureClass"],
334
+ message: "Success requires a null failure class"
335
+ });
336
+ });
337
+ //#endregion
338
+ //#region shared/contracts/telemetry.ts
339
+ var TELEMETRY_ADAPTERS = Object.freeze([...BUILTIN_AGENT_IDS, "custom"]);
340
+ var SESSION_EXIT_KINDS = Object.freeze([
341
+ "clean",
342
+ "error",
343
+ "signal",
344
+ "no_output"
345
+ ]);
346
+ var nonNegativeInteger = z.number().int().nonnegative();
347
+ var boundedText = z.string().max(512);
348
+ var AppStartedProperties = z.object({}).strict();
349
+ var AppActiveProperties = z.object({ active_session_count: nonNegativeInteger }).strict();
350
+ var SessionStartedProperties = z.object({ adapter: z.enum(TELEMETRY_ADAPTERS) }).strict();
351
+ var SessionEndedProperties = z.object({
352
+ adapter: z.enum(TELEMETRY_ADAPTERS),
353
+ exit_kind: z.enum(SESSION_EXIT_KINDS),
354
+ duration_seconds: nonNegativeInteger
355
+ }).strict();
356
+ var ExceptionFrame = z.object({
357
+ platform: z.enum(["node:javascript", "web:javascript"]),
358
+ function: boundedText,
359
+ filename: boundedText,
360
+ lineno: nonNegativeInteger,
361
+ colno: nonNegativeInteger,
362
+ in_app: z.boolean()
363
+ }).strict();
364
+ var ExceptionProperties = z.object({
365
+ $exception_list: z.array(z.object({
366
+ type: boundedText,
367
+ value: boundedText,
368
+ mechanism: z.object({
369
+ handled: z.boolean(),
370
+ synthetic: z.boolean(),
371
+ type: z.literal("generic")
372
+ }).strict(),
373
+ stacktrace: z.object({
374
+ type: z.literal("raw"),
375
+ frames: z.array(ExceptionFrame).max(64)
376
+ }).strict()
377
+ }).strict()).length(1),
378
+ $exception_level: z.enum(["error", "fatal"])
379
+ }).strict();
380
+ var AiGenerationProperties = z.object({
381
+ $ai_trace_id: z.string().regex(/^[0-9a-f]{64}$/),
382
+ $ai_provider: z.string().max(64),
383
+ $ai_model: z.string().max(128),
384
+ $ai_input_tokens: nonNegativeInteger,
385
+ $ai_output_tokens: nonNegativeInteger,
386
+ $ai_cache_read_input_tokens: nonNegativeInteger.optional(),
387
+ $ai_cache_creation_input_tokens: nonNegativeInteger.optional(),
388
+ $ai_total_cost_usd: z.number().finite().nonnegative().optional(),
389
+ agent_adapter: z.enum(TELEMETRY_ADAPTERS)
390
+ }).strict();
391
+ var FactoryDecisionProperties = z.object({
392
+ kind: FactoryDecisionKind,
393
+ outcome: FactoryDecisionOutcome,
394
+ failure_class: FactoryDecisionFailureClass.nullable(),
395
+ duration_ms: nonNegativeInteger.nullable(),
396
+ attempt: nonNegativeInteger.nullable()
397
+ }).strict();
398
+ var TELEMETRY_EVENT_SCHEMAS = Object.freeze({
399
+ app_started: AppStartedProperties,
400
+ app_active: AppActiveProperties,
401
+ session_started: SessionStartedProperties,
402
+ session_ended: SessionEndedProperties,
403
+ $exception: ExceptionProperties,
404
+ $ai_generation: AiGenerationProperties,
405
+ factory_decision: FactoryDecisionProperties
406
+ });
407
+ Object.freeze([
408
+ {
409
+ name: "app_started",
410
+ description: "The server started listening."
411
+ },
412
+ {
413
+ name: "app_active",
414
+ description: "Once a day while the server runs, with how many sessions are live."
415
+ },
416
+ {
417
+ name: "session_started",
418
+ description: "A session spawned, with which kind of agent (any custom agent counts as `custom`)."
419
+ },
420
+ {
421
+ name: "session_ended",
422
+ description: "A session exited: how it exited and how long it ran, in whole seconds."
423
+ },
424
+ {
425
+ name: "$exception",
426
+ description: "An error in the server or the dashboard: its type, an error code when it has one, and stack frames with file paths cut to the package or URL path. Never the error message. Each distinct error is sent once per run, and a crash is sent on the next start."
427
+ },
428
+ {
429
+ name: "$ai_generation",
430
+ description: "Per agent session and model, after each usage scan, for usage recorded in the last 24 hours: token counts, the model name and estimated cost, under a one-way hash of the session. A model name outside the shipped pricing table is sent as unknown. No prompts or output."
431
+ },
432
+ {
433
+ name: "factory_decision",
434
+ description: "Each time the factory decides something (a dispatch, a close-out attempt, a merge, a watch or verification result, an exception, a landing, a Claude Code folder trust grant): which kind of decision, how it came out, the class of failure when it failed, how long it took and which attempt it was. Never the objective, the reason, check output, a path or a repository name."
435
+ }
436
+ ]);
437
+ Object.freeze([
438
+ "app_version",
439
+ "os_platform",
440
+ "node_major",
441
+ "install_flavor",
442
+ "is_bundled",
443
+ "is_dev_install"
444
+ ]);
445
+ Object.freeze(["$release_id"]);
446
+ var TELEMETRY_KILL_SWITCH_FLAG = "telemetry-enabled";
447
+ var FeatureFlagsResponse = z.object({
448
+ flags: z.object({ [TELEMETRY_KILL_SWITCH_FLAG]: z.object({ enabled: z.boolean() }).passthrough().optional() }).passthrough(),
449
+ errorsWhileComputingFlags: z.boolean().optional()
450
+ }).passthrough();
451
+ var PendingCrashReport = z.object({
452
+ timestamp: z.string(),
453
+ properties: ExceptionProperties
454
+ }).strict();
455
+ var TelemetryState = z.object({
456
+ installId: z.uuid(),
457
+ noticeShownAt: z.string().nullable().optional(),
458
+ remoteDisabled: z.boolean().optional()
459
+ });
460
+ //#endregion
461
+ //#region shared/contracts/benchmark.ts
462
+ var BENCHMARK_ID_RE = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/;
463
+ var ENV_NAME_RE = /^[A-Za-z_][A-Za-z0-9_]*$/;
464
+ var repoSlug = z.string().regex(/^[^/\s]+\/[^/\s]+$/);
465
+ var timestamp$1 = z.number().finite();
466
+ var nonEmptyText = z.string().min(1);
467
+ var BENCHMARK_INJECTED_ENV_NAMES = Object.freeze(["CLAUDE_CODE_OAUTH_TOKEN"]);
468
+ var BenchmarkId = z.string().regex(BENCHMARK_ID_RE);
469
+ function hasUniqueIds(entries) {
470
+ return new Set(entries.map((entry) => entry.id)).size === entries.length;
471
+ }
472
+ var BenchmarkCaseSource = z.discriminatedUnion("kind", [z.strictObject({ kind: z.literal("manual") }), z.strictObject({
473
+ kind: z.literal("github-merged-prs"),
474
+ repo: repoSlug,
475
+ minBodies: z.number().int().min(1),
476
+ limit: z.number().int().min(1).max(500)
477
+ })]);
478
+ var BenchmarkWorkspace = z.discriminatedUnion("kind", [z.strictObject({ kind: z.literal("none") }), z.strictObject({ kind: z.literal("pr-checkout") })]);
479
+ var BenchmarkSubjectOutput = z.enum(["review-findings", "json"]);
480
+ var BenchmarkSubject = z.strictObject({
481
+ promptTemplate: nonEmptyText,
482
+ output: BenchmarkSubjectOutput,
483
+ timeoutSeconds: z.number().int().min(30).max(14400)
484
+ });
485
+ var BenchmarkArm = z.strictObject({
486
+ id: BenchmarkId,
487
+ env: z.record(z.string().regex(ENV_NAME_RE), z.string()).refine((env) => BENCHMARK_INJECTED_ENV_NAMES.every((name) => !Object.hasOwn(env, name)), { message: `arm env must not set ${BENCHMARK_INJECTED_ENV_NAMES.join(", ")}; Glimmervoid injects it per cell` }).optional(),
488
+ extraArgs: z.array(z.string()).optional(),
489
+ setup: z.strictObject({ command: z.array(nonEmptyText).min(1) }).optional()
490
+ });
491
+ var BenchmarkScorer = z.discriminatedUnion("kind", [z.strictObject({
492
+ kind: z.literal("llm-judge-match"),
493
+ model: nonEmptyText
494
+ })]);
495
+ var BenchmarkSuite = z.strictObject({
496
+ id: BenchmarkId,
497
+ title: nonEmptyText,
498
+ caseSource: BenchmarkCaseSource,
499
+ workspace: BenchmarkWorkspace,
500
+ subject: BenchmarkSubject,
501
+ arms: z.array(BenchmarkArm).min(2).refine(hasUniqueIds, { message: "arm ids must be unique" }),
502
+ baselineArm: BenchmarkId,
503
+ trials: z.number().int().min(1).max(20),
504
+ scorer: BenchmarkScorer
505
+ }).refine((suite) => suite.arms.some((arm) => arm.id === suite.baselineArm), {
506
+ message: "baselineArm must name one of the arms",
507
+ path: ["baselineArm"]
508
+ });
509
+ var BenchmarkReference = z.strictObject({
510
+ id: BenchmarkId,
511
+ text: nonEmptyText,
512
+ tags: z.array(BenchmarkId),
513
+ path: nonEmptyText.optional(),
514
+ line: z.number().int().positive().optional()
515
+ });
516
+ var BenchmarkCaseOrigin = z.discriminatedUnion("kind", [z.strictObject({ kind: z.literal("manual") }), z.strictObject({
517
+ kind: z.literal("github-pr"),
518
+ repo: repoSlug,
519
+ number: z.number().int().positive(),
520
+ url: nonEmptyText,
521
+ minedAt: timestamp$1
522
+ })]);
523
+ var BenchmarkCase = z.strictObject({
524
+ id: BenchmarkId,
525
+ input: z.record(z.string(), z.unknown()),
526
+ references: z.array(BenchmarkReference).min(1).refine(hasUniqueIds, { message: "reference ids must be unique" }),
527
+ source: BenchmarkCaseOrigin
528
+ });
529
+ var PrCheckoutCaseInput = z.object({
530
+ repo: repoSlug,
531
+ number: z.number().int().positive(),
532
+ reviewedSha: CommitSha,
533
+ baseSha: CommitSha,
534
+ changedFiles: z.array(nonEmptyText)
535
+ });
536
+ var BenchmarkMatchVerdict = z.enum([
537
+ "found",
538
+ "partial",
539
+ "missed"
540
+ ]);
541
+ var BenchmarkJudgement = z.strictObject({
542
+ referenceId: BenchmarkId,
543
+ verdict: BenchmarkMatchVerdict,
544
+ findingIndexes: z.array(z.number().int().nonnegative())
545
+ });
546
+ var BenchmarkCellStatus = z.enum([
547
+ "scored",
548
+ "invalid",
549
+ "error"
550
+ ]);
551
+ var BenchmarkCellResult = z.strictObject({
552
+ caseId: BenchmarkId,
553
+ armId: BenchmarkId,
554
+ trial: z.number().int().min(1),
555
+ status: BenchmarkCellStatus,
556
+ startedAt: timestamp$1,
557
+ finishedAt: timestamp$1,
558
+ degradedReasons: z.array(nonEmptyText),
559
+ findingCount: z.number().int().nonnegative(),
560
+ judgements: z.array(BenchmarkJudgement),
561
+ costUsd: z.number().finite().nonnegative().nullable(),
562
+ error: nonEmptyText.nullable()
563
+ });
564
+ var BenchmarkRunStatus = z.enum([
565
+ "running",
566
+ "completed",
567
+ "interrupted",
568
+ "failed"
569
+ ]);
570
+ var BenchmarkRun = z.strictObject({
571
+ id: BenchmarkId,
572
+ suiteId: BenchmarkId,
573
+ status: BenchmarkRunStatus,
574
+ startedAt: timestamp$1,
575
+ finishedAt: timestamp$1.nullable(),
576
+ error: nonEmptyText.nullable(),
577
+ cells: z.array(BenchmarkCellResult)
578
+ });
579
+ var nullableRatio = z.number().min(0).max(1).nullable();
580
+ var BenchmarkArmScore = z.strictObject({
581
+ trials: z.number().int().nonnegative(),
582
+ recall: nullableRatio,
583
+ recallByTag: z.record(BenchmarkId, nullableRatio),
584
+ degraded: z.number().int().nonnegative(),
585
+ invalid: z.number().int().nonnegative(),
586
+ costUsd: z.number().finite().nonnegative().nullable()
587
+ });
588
+ var BenchmarkReportRow = z.strictObject({
589
+ caseId: BenchmarkId,
590
+ arms: z.record(BenchmarkId, BenchmarkArmScore),
591
+ deltaVsBaseline: z.record(BenchmarkId, z.number().min(-1).max(1).nullable())
592
+ });
593
+ var BenchmarkReport = z.strictObject({
594
+ runId: BenchmarkId,
595
+ suiteId: BenchmarkId,
596
+ status: BenchmarkRunStatus,
597
+ baselineArm: BenchmarkId,
598
+ armIds: z.array(BenchmarkId),
599
+ rows: z.array(BenchmarkReportRow),
600
+ totals: z.record(BenchmarkId, BenchmarkArmScore)
601
+ });
602
+ var BenchmarkAction = z.enum([
603
+ "mine",
604
+ "run",
605
+ "cancel"
606
+ ]);
607
+ var BenchmarkActionRequest = z.object({
608
+ suiteId: BenchmarkId,
609
+ action: BenchmarkAction
610
+ });
611
+ var BenchmarkActionResult = z.object({
612
+ suiteId: BenchmarkId,
613
+ action: BenchmarkAction,
614
+ ok: z.boolean(),
615
+ error: z.string().optional(),
616
+ runId: BenchmarkId.optional()
617
+ });
618
+ var BenchmarkCellPhase = z.enum([
619
+ "setup",
620
+ "preflight",
621
+ "workspace",
622
+ "subject",
623
+ "judge"
624
+ ]);
625
+ var BenchmarkInFlightCell = z.object({
626
+ suiteId: BenchmarkId,
627
+ runId: BenchmarkId,
628
+ caseId: BenchmarkId.nullable(),
629
+ armId: BenchmarkId,
630
+ trial: z.number().int().min(1),
631
+ phase: BenchmarkCellPhase,
632
+ cellIndex: z.number().int().nonnegative(),
633
+ cellCount: z.number().int().positive(),
634
+ startedAt: timestamp$1
635
+ });
636
+ var BenchmarkSuiteSummary = z.object({
637
+ id: BenchmarkId,
638
+ title: z.string(),
639
+ error: z.string().nullable(),
640
+ caseCount: z.number().int().nonnegative(),
641
+ candidateCount: z.number().int().nonnegative(),
642
+ armIds: z.array(BenchmarkId),
643
+ baselineArm: BenchmarkId.nullable(),
644
+ latestReport: BenchmarkReport.nullable()
645
+ });
646
+ var BenchmarkStatus = z.object({
647
+ type: z.literal("benchmark-status"),
648
+ ts: timestamp$1,
649
+ configured: z.boolean(),
650
+ reason: z.string().nullable(),
651
+ suites: z.array(BenchmarkSuiteSummary),
652
+ inFlight: BenchmarkInFlightCell.nullable()
653
+ }).passthrough();
654
+ var githubAuthor = z.object({
655
+ __typename: z.string(),
656
+ login: z.string()
657
+ }).nullable();
658
+ var MergedPrListing = z.object({
659
+ number: z.number().int().positive(),
660
+ title: z.string(),
661
+ url: nonEmptyText,
662
+ mergedAt: z.string().nullable(),
663
+ reviewThreads: z.object({ totalCount: z.number().int().nonnegative() }),
664
+ reviews: z.object({ totalCount: z.number().int().nonnegative() })
665
+ });
666
+ var MinedReviewThread = z.object({
667
+ path: z.string(),
668
+ line: z.number().int().positive().nullable(),
669
+ originalLine: z.number().int().positive().nullable(),
670
+ comments: z.object({ nodes: z.array(z.object({
671
+ databaseId: z.number().int().positive(),
672
+ author: githubAuthor,
673
+ body: z.string(),
674
+ createdAt: z.string(),
675
+ originalCommit: z.object({ oid: CommitSha }).nullable()
676
+ })) })
677
+ });
678
+ var MinedReview = z.object({
679
+ databaseId: z.number().int().positive(),
680
+ author: githubAuthor,
681
+ body: z.string(),
682
+ submittedAt: z.string().nullable(),
683
+ commit: z.object({ oid: CommitSha }).nullable()
684
+ });
685
+ var MinedBaseEvent = z.discriminatedUnion("__typename", [z.object({
686
+ __typename: z.literal("BaseRefChangedEvent"),
687
+ createdAt: z.string()
688
+ }), z.object({
689
+ __typename: z.literal("BaseRefForcePushedEvent"),
690
+ createdAt: z.string(),
691
+ beforeCommit: z.object({ oid: CommitSha }).nullable()
692
+ })]);
693
+ var MinedPrReviewData = z.object({
694
+ author: githubAuthor,
695
+ baseRefOid: CommitSha,
696
+ reviewThreads: z.object({
697
+ pageInfo: z.object({ hasNextPage: z.boolean() }),
698
+ nodes: z.array(MinedReviewThread)
699
+ }),
700
+ reviews: z.object({
701
+ pageInfo: z.object({ hasNextPage: z.boolean() }),
702
+ nodes: z.array(MinedReview)
703
+ }),
704
+ timelineItems: z.object({
705
+ pageInfo: z.object({ hasNextPage: z.boolean() }),
706
+ nodes: z.array(MinedBaseEvent)
707
+ })
708
+ });
709
+ var CommitComparison = z.object({
710
+ mergeBaseSha: CommitSha,
711
+ changedFiles: z.array(nonEmptyText),
712
+ isFileListComplete: z.boolean()
713
+ });
714
+ Object.freeze([
715
+ "file",
716
+ "subsystem",
717
+ "co-change",
718
+ "hotspot",
719
+ "blast",
720
+ "untested",
721
+ "collision",
722
+ "link"
723
+ ]);
724
+ function changeMapFactId(kind, repoName, ...parts) {
725
+ return [
726
+ kind,
727
+ repoName,
728
+ ...parts
729
+ ].join(":");
730
+ }
731
+ var factId = z.string().min(1);
732
+ var repoPath = z.string().min(1);
733
+ var count = z.number().int().nonnegative();
734
+ var cappedPaths = z.array(repoPath).max(20);
735
+ var ChangedFileStatus = z.enum([
736
+ "added",
737
+ "modified",
738
+ "deleted",
739
+ "renamed",
740
+ "untracked"
741
+ ]);
742
+ var ChangedFile = z.strictObject({
743
+ factId,
744
+ path: repoPath,
745
+ previousPath: repoPath.optional(),
746
+ status: ChangedFileStatus,
747
+ isCommitted: z.boolean()
748
+ });
749
+ var SubsystemFact = z.strictObject({
750
+ factId,
751
+ agentsPath: repoPath,
752
+ title: z.string(),
753
+ paths: z.array(repoPath).min(1)
754
+ });
755
+ var CoChangeGap = z.strictObject({
756
+ factId,
757
+ path: repoPath,
758
+ partner: repoPath,
759
+ support: count,
760
+ confidence: z.number().min(0).max(1)
761
+ });
762
+ var HotspotFact = z.strictObject({
763
+ factId,
764
+ path: repoPath,
765
+ commitCount: count,
766
+ fixCommitCount: count
767
+ });
768
+ var BlastRadiusFact = z.strictObject({
769
+ factId,
770
+ path: repoPath,
771
+ directDependents: cappedPaths,
772
+ directDependentCount: count,
773
+ transitiveDependentCount: count,
774
+ dependentTests: cappedPaths,
775
+ dependentTestCount: count
776
+ });
777
+ var UntestedFileFact = z.strictObject({
778
+ factId,
779
+ path: repoPath
780
+ });
781
+ var CollisionFact = z.strictObject({
782
+ factId,
783
+ path: repoPath,
784
+ otherSessionId: z.string().min(1),
785
+ otherSessionName: z.string()
786
+ });
787
+ var CrossRepoLink = z.strictObject({
788
+ factId,
789
+ providerRepo: z.string().min(1),
790
+ packageName: z.string().min(1),
791
+ packageDir: z.string(),
792
+ consumerManifest: repoPath,
793
+ versionSpec: z.string(),
794
+ isLocalLink: z.boolean(),
795
+ providerChangedPathCount: count,
796
+ importers: cappedPaths,
797
+ importerCount: count,
798
+ changedImporterCount: count
799
+ });
800
+ var RepoChangeMap = z.strictObject({
801
+ name: z.string().min(1),
802
+ root: z.string().min(1),
803
+ sessionPathPrefix: z.string(),
804
+ base: z.string().nullable(),
805
+ files: z.array(ChangedFile),
806
+ subsystems: z.array(SubsystemFact),
807
+ coChangeGaps: z.array(CoChangeGap),
808
+ hotspots: z.array(HotspotFact),
809
+ blastRadius: z.array(BlastRadiusFact),
810
+ untestedFiles: z.array(UntestedFileFact),
811
+ collisions: z.array(CollisionFact),
812
+ links: z.array(CrossRepoLink),
813
+ error: z.string().nullable()
814
+ });
815
+ var NarrativeClaim = z.strictObject({
816
+ text: z.string().min(1).max(600),
817
+ factIds: z.array(factId).min(1)
818
+ });
819
+ var ChangeNarrative = z.strictObject({
820
+ factsHash: z.string().min(1),
821
+ model: z.string().nullable(),
822
+ claims: z.array(NarrativeClaim).max(12)
823
+ });
824
+ var NarratorState = z.enum([
825
+ "disabled",
826
+ "pending",
827
+ "ready",
828
+ "failed"
829
+ ]);
830
+ var ChangeMap = z.strictObject({
831
+ sessionId: z.string().min(1),
832
+ sig: z.string().nullable(),
833
+ generatedAt: z.number().finite(),
834
+ repos: z.array(RepoChangeMap),
835
+ narrative: ChangeNarrative.nullable(),
836
+ narratorState: NarratorState,
837
+ error: z.string().min(1).optional()
838
+ });
839
+ //#endregion
840
+ //#region shared/contracts/issues.ts
841
+ var IssueRepoSlug = z.string().regex(REPO_SLUG_RE);
842
+ var IssueKey = z.string().regex(new RegExp(`${REPO_SLUG_RE.source.slice(0, -1)}#[1-9][0-9]*$`));
843
+ var IssuePullRequest = z.object({
844
+ number: z.number().int().positive(),
845
+ url: z.string().url(),
846
+ title: z.string(),
847
+ state: z.enum([
848
+ "open",
849
+ "draft",
850
+ "merged",
851
+ "closed"
852
+ ])
853
+ });
854
+ var GithubIssuePullRequestsRepository = z.object({ issue: z.object({ closedByPullRequestsReferences: z.object({ nodes: z.array(z.object({
855
+ number: IssuePullRequest.shape.number,
856
+ url: IssuePullRequest.shape.url,
857
+ title: IssuePullRequest.shape.title,
858
+ state: z.enum([
859
+ "OPEN",
860
+ "MERGED",
861
+ "CLOSED"
862
+ ]),
863
+ isDraft: z.boolean()
864
+ }).nullable()).max(5) }) }).nullable() });
865
+ var issueFields = {
866
+ key: z.string(),
867
+ repo: IssueRepoSlug,
868
+ number: z.number().int().positive(),
869
+ title: z.string(),
870
+ url: z.string().url(),
871
+ labels: z.array(z.string()),
872
+ assignees: z.array(z.string()),
873
+ author: z.string(),
874
+ comments: z.number().int().nonnegative(),
875
+ createdAt: z.iso.datetime(),
876
+ updatedAt: z.iso.datetime()
877
+ };
878
+ var IssueSource = z.enum([
879
+ "project",
880
+ "me",
881
+ "team"
882
+ ]);
883
+ var cachedIssueFields = {
884
+ ...issueFields,
885
+ sources: z.array(IssueSource).nonempty().refine((sources) => new Set(sources).size === sources.length),
886
+ teams: z.array(IssueRepoSlug),
887
+ projectId: z.string().nullable(),
888
+ pullRequests: z.array(IssuePullRequest).max(5).default([])
889
+ };
890
+ var CachedIssueRow = z.object(cachedIssueFields).refine((issue) => issue.key === `${issue.repo}#${issue.number}`);
891
+ var IssueRow = z.object({
892
+ ...cachedIssueFields,
893
+ sessionId: z.string().nullable().default(null)
894
+ }).refine((issue) => issue.key === `${issue.repo}#${issue.number}`);
895
+ var IssueUpdate = z.object({
896
+ ...issueFields,
897
+ state: z.enum(["open", "closed"])
898
+ });
899
+ var GithubIssueResponse = z.object({
900
+ number: issueFields.number,
901
+ title: issueFields.title,
902
+ html_url: issueFields.url,
903
+ state: z.enum(["open", "closed"]),
904
+ labels: z.array(z.union([z.string(), z.object({ name: z.string() })])),
905
+ assignees: z.array(z.object({ login: z.string() })),
906
+ user: z.object({ login: z.string() }).nullable(),
907
+ comments: issueFields.comments,
908
+ created_at: issueFields.createdAt,
909
+ updated_at: issueFields.updatedAt,
910
+ repository_url: z.string().url().optional(),
911
+ pull_request: z.unknown().optional()
912
+ });
913
+ var IssuesSearchResponse = z.object({
914
+ items: z.array(z.unknown()),
915
+ total_count: z.number().int().nonnegative(),
916
+ incomplete_results: z.boolean()
917
+ });
918
+ z.object({
919
+ ok: z.boolean(),
920
+ items: z.array(IssueUpdate),
921
+ isComplete: z.boolean(),
922
+ error: z.string()
923
+ });
924
+ var IssuesState = z.object({
925
+ issues: z.array(CachedIssueRow),
926
+ lastSyncAt: z.number().finite().nonnegative().nullable(),
927
+ perRepoSync: z.record(IssueRepoSlug, z.object({
928
+ lastSyncAt: z.number().finite().nonnegative().nullable(),
929
+ ticks: z.number().int().nonnegative(),
930
+ needsFullReconcile: z.boolean()
931
+ })),
932
+ sessionLinks: z.record(IssueKey, z.string()).default({}),
933
+ pullRequestsFetchedAt: z.record(IssueKey, z.iso.datetime()).default({})
934
+ });
935
+ var IssuesStatus = z.object({
936
+ type: z.literal("issues-status"),
937
+ ts: z.number().finite(),
938
+ configured: z.boolean(),
939
+ reason: z.string().nullable(),
940
+ lastSyncAt: z.number().finite().nonnegative().nullable(),
941
+ issues: z.array(IssueRow),
942
+ ...reviewsPollingShape
943
+ }).passthrough();
944
+ var PLAN_FEEDBACK_MAX_CHARS = 2e4;
945
+ var PLAN_COMMENT_MAX_CHARS = 4e3;
946
+ var PLAN_BODY_CAP_BYTES = 524288;
947
+ var PLAN_HOOK_OUTPUT_MAX_CHARS = 1e4;
948
+ var PLAN_HOOK_EVENT = "permissionrequest-plan";
949
+ var PLAN_RESULT_HOOK_EVENT = "posttooluse-plan";
950
+ var PLAN_TOOL_NAME = "ExitPlanMode";
951
+ var HEADING_SCAN_MAX_CHARS = 4096;
952
+ var ATX_HEADING = /^ {0,3}(#{1,6})[ \t]+(.*)$/;
953
+ function capPlanTitle(text) {
954
+ const trimmed = text.trim();
955
+ if (trimmed.length <= 120) return trimmed;
956
+ return trimmed.slice(0, 120);
957
+ }
958
+ function withoutClosingHeadingMarks(text) {
959
+ const trimmed = text.trimEnd();
960
+ let textEnd = trimmed.length;
961
+ while (textEnd > 0 && trimmed[textEnd - 1] === "#") textEnd--;
962
+ if (textEnd === trimmed.length || textEnd === 0) return trimmed;
963
+ const charBeforeMarks = trimmed[textEnd - 1];
964
+ if (charBeforeMarks !== " " && charBeforeMarks !== " ") return trimmed;
965
+ return trimmed.slice(0, textEnd).trimEnd();
966
+ }
967
+ function parseAtxHeading(line, { overlongLine }) {
968
+ if (overlongLine === "reject" && line.length > 4096) return null;
969
+ const heading = ATX_HEADING.exec(line.slice(0, HEADING_SCAN_MAX_CHARS));
970
+ if (!heading) return null;
971
+ return {
972
+ level: heading[1].length,
973
+ text: withoutClosingHeadingMarks(heading[2])
974
+ };
975
+ }
976
+ function headingTitle(line) {
977
+ return parseAtxHeading(line, { overlongLine: "truncate" })?.text ?? "";
978
+ }
979
+ function planTitle(plan) {
980
+ const lines = typeof plan === "string" ? plan.split(/\r?\n/) : [];
981
+ for (const line of lines) {
982
+ const title = headingTitle(line);
983
+ if (title.length > 0) return capPlanTitle(title);
984
+ }
985
+ return capPlanTitle(lines.find((line) => line.trim().length > 0) ?? "");
986
+ }
987
+ var ExitPlanModeInput = z.object({
988
+ plan: z.string().min(1),
989
+ planFilePath: z.string().min(1),
990
+ agent_id: z.string().min(1).optional(),
991
+ agent_type: z.string().min(1).optional()
992
+ }).passthrough();
993
+ var ExitPlanModeHookPayload = z.object({
994
+ tool_name: z.literal(PLAN_TOOL_NAME),
995
+ tool_input: ExitPlanModeInput,
996
+ agent_id: z.string().min(1).optional(),
997
+ agent_type: z.string().min(1).optional()
998
+ }).passthrough();
999
+ var ExitPlanModeRequest = z.object({
1000
+ plan: z.string(),
1001
+ planFilePath: z.string(),
1002
+ agentId: z.string().nullable(),
1003
+ agentType: z.string().nullable()
1004
+ });
1005
+ function parseExitPlanModeHookPayload(body) {
1006
+ const parsed = ExitPlanModeHookPayload.safeParse(body);
1007
+ if (!parsed.success) return null;
1008
+ const input = parsed.data.tool_input;
1009
+ return {
1010
+ plan: input.plan,
1011
+ planFilePath: input.planFilePath,
1012
+ agentId: parsed.data.agent_id ?? input.agent_id ?? null,
1013
+ agentType: parsed.data.agent_type ?? input.agent_type ?? null
1014
+ };
1015
+ }
1016
+ var PlanRevision = ExitPlanModeRequest.extend({
1017
+ sessionId: z.string().min(1),
1018
+ revision: z.number().int().positive(),
1019
+ receivedAt: z.number().finite()
1020
+ });
1021
+ var PLAN_REVIEW_STATE_VALUES = Object.freeze([
1022
+ "open",
1023
+ "released",
1024
+ "decided",
1025
+ "closed"
1026
+ ]);
1027
+ var PlanReviewStateValue = z.enum(PLAN_REVIEW_STATE_VALUES);
1028
+ var PLAN_DECISION_KINDS = Object.freeze([
1029
+ "approve",
1030
+ "approve-accept-edits",
1031
+ "revise",
1032
+ "terminal"
1033
+ ]);
1034
+ var PlanDecisionKind = z.enum(PLAN_DECISION_KINDS);
1035
+ var PlanSectionComment = z.object({
1036
+ heading: z.string().max(PLAN_COMMENT_MAX_CHARS).nullable(),
1037
+ comment: z.string().min(1).max(PLAN_COMMENT_MAX_CHARS)
1038
+ });
1039
+ var PlanDecision = z.object({
1040
+ id: z.string().min(1),
1041
+ agentId: z.string().nullable(),
1042
+ revision: z.number().int().positive(),
1043
+ decision: PlanDecisionKind,
1044
+ feedback: z.string().max(PLAN_FEEDBACK_MAX_CHARS).optional(),
1045
+ comments: z.array(PlanSectionComment).max(40).optional(),
1046
+ plan: z.string().min(1).max(PLAN_BODY_CAP_BYTES).optional()
1047
+ });
1048
+ var PlanRevisionSummary = z.object({
1049
+ revision: z.number().int().positive(),
1050
+ receivedAt: z.number().finite(),
1051
+ chars: z.number().int().nonnegative(),
1052
+ title: z.string()
1053
+ });
1054
+ var PlanReviewOpenRevision = z.object({
1055
+ revision: z.number().int().positive(),
1056
+ since: z.number().finite()
1057
+ });
1058
+ var PlanReview = z.object({
1059
+ agentId: z.string().nullable(),
1060
+ agentType: z.string().nullable(),
1061
+ revisions: z.array(PlanRevisionSummary),
1062
+ state: PlanReviewStateValue,
1063
+ openRevision: PlanReviewOpenRevision.nullable(),
1064
+ approvedRevision: z.number().int().positive().nullable(),
1065
+ lastDecision: PlanDecisionKind.nullable()
1066
+ });
1067
+ z.object({ reviews: z.array(PlanReview) });
1068
+ var PlanRevisionBody = z.object({
1069
+ agentId: z.string().nullable(),
1070
+ revision: z.number().int().nonnegative(),
1071
+ plan: z.string(),
1072
+ planFilePath: z.string(),
1073
+ receivedAt: z.number().finite()
1074
+ });
1075
+ var PlanChangedPush = z.object({
1076
+ id: z.string(),
1077
+ agentId: z.string().nullable(),
1078
+ agentType: z.string().nullable(),
1079
+ revision: z.number().int().positive(),
1080
+ receivedAt: z.number().finite(),
1081
+ state: PlanReviewStateValue,
1082
+ lastDecision: PlanDecisionKind.nullable(),
1083
+ approvedRevision: z.number().int().positive().nullable(),
1084
+ chars: z.number().int().nonnegative(),
1085
+ title: z.string(),
1086
+ hasPlan: z.boolean()
1087
+ });
1088
+ var PlanDraftPush = z.object({
1089
+ id: z.string(),
1090
+ agentId: z.string().nullable(),
1091
+ planFilePath: z.string(),
1092
+ changedAt: z.number().finite()
1093
+ });
1094
+ var PlanResponseFrame = z.object({
1095
+ id: z.string(),
1096
+ reviews: z.array(PlanReview),
1097
+ body: PlanRevisionBody.nullable()
1098
+ });
1099
+ //#endregion
1100
+ //#region shared/contracts/trace.ts
1101
+ var MAX_RAW_LINE_CHARS = 4e3;
1102
+ var TraceRecordBase = z.object({
1103
+ ts: z.number().finite(),
1104
+ uuid: z.string().nullable(),
1105
+ parentUuid: z.string().nullable(),
1106
+ vendorSessionId: z.string().min(1),
1107
+ agentId: z.string().min(1).optional(),
1108
+ agentType: z.string().min(1).optional(),
1109
+ transcriptOffset: z.number().int().nonnegative().optional(),
1110
+ truncated: z.boolean().optional()
1111
+ });
1112
+ var TraceRecord = z.discriminatedUnion("kind", [
1113
+ TraceRecordBase.extend({
1114
+ kind: z.literal("prompt"),
1115
+ text: z.string()
1116
+ }),
1117
+ TraceRecordBase.extend({
1118
+ kind: z.literal("expansion"),
1119
+ text: z.string(),
1120
+ toolUseId: z.string().min(1).optional()
1121
+ }),
1122
+ TraceRecordBase.extend({
1123
+ kind: z.literal("thinking"),
1124
+ text: z.string()
1125
+ }),
1126
+ TraceRecordBase.extend({
1127
+ kind: z.literal("assistant"),
1128
+ text: z.string()
1129
+ }),
1130
+ TraceRecordBase.extend({
1131
+ kind: z.literal("tool_call"),
1132
+ toolUseId: z.string().min(1),
1133
+ name: z.string().min(1),
1134
+ input: z.unknown()
1135
+ }),
1136
+ TraceRecordBase.extend({
1137
+ kind: z.literal("tool_result"),
1138
+ toolUseId: z.string().min(1),
1139
+ content: z.string(),
1140
+ isError: z.boolean(),
1141
+ truncated: z.boolean()
1142
+ }),
1143
+ TraceRecordBase.extend({
1144
+ kind: z.literal("session"),
1145
+ vendor: z.string().min(1),
1146
+ transcriptPath: z.string().min(1),
1147
+ reason: z.string().min(1).optional()
1148
+ }),
1149
+ TraceRecordBase.extend({
1150
+ kind: z.literal("notice"),
1151
+ text: z.string().max(MAX_RAW_LINE_CHARS)
1152
+ }),
1153
+ TraceRecordBase.extend({
1154
+ kind: z.literal("raw"),
1155
+ line: z.string().max(MAX_RAW_LINE_CHARS)
1156
+ })
1157
+ ]);
1158
+ var TraceCheckpoint = z.object({
1159
+ transcriptPath: z.string().min(1),
1160
+ vendorSessionId: z.string().min(1),
1161
+ offset: z.number().int().nonnegative(),
1162
+ ingestedSubagentPaths: z.array(z.string().min(1)),
1163
+ offsetByTranscriptPath: z.record(z.string().min(1), z.number().int().nonnegative()).default({}),
1164
+ subagentOffsetByPath: z.record(z.string().min(1), z.number().int().nonnegative()).default({})
1165
+ });
1166
+ //#endregion
1167
+ //#region shared/contracts/update-journal.ts
1168
+ var UpdateChannel = z.enum(["release", "main"]);
1169
+ var UpdateRunState = z.enum([
1170
+ "idle",
1171
+ "running",
1172
+ "staged",
1173
+ "succeeded",
1174
+ "failed",
1175
+ "discarded",
1176
+ "interrupted"
1177
+ ]);
1178
+ var UpdateStepId = z.enum([
1179
+ "fetch",
1180
+ "stage",
1181
+ "install",
1182
+ "link-deps",
1183
+ "build"
1184
+ ]);
1185
+ var UpdateStepStatus = z.enum([
1186
+ "pending",
1187
+ "running",
1188
+ "succeeded",
1189
+ "failed"
1190
+ ]);
1191
+ var UpdateJournalStep = z.object({
1192
+ id: UpdateStepId,
1193
+ status: UpdateStepStatus,
1194
+ startedAt: z.number().finite().nullable(),
1195
+ finishedAt: z.number().finite().nullable(),
1196
+ outputTail: z.array(z.string())
1197
+ }).strict();
1198
+ var UpdateJournal = z.object({
1199
+ state: UpdateRunState,
1200
+ fromSha: z.string().nullable(),
1201
+ toSha: z.string().nullable(),
1202
+ toVersion: z.string().nullable(),
1203
+ channel: UpdateChannel,
1204
+ steps: z.array(UpdateJournalStep),
1205
+ activeStep: UpdateStepId.nullable(),
1206
+ reason: z.string().nullable(),
1207
+ startedAt: z.number().finite().nullable(),
1208
+ finishedAt: z.number().finite().nullable(),
1209
+ failedAtHandOff: z.boolean().optional()
1210
+ }).strict();
1211
+ var UpdateJournalSummary = UpdateJournal.pick({
1212
+ state: true,
1213
+ activeStep: true,
1214
+ reason: true,
1215
+ startedAt: true,
1216
+ finishedAt: true
1217
+ });
1218
+ //#endregion
1219
+ //#region shared/contracts/control-messages.ts
1220
+ var requestId = z.string().nullable().optional();
1221
+ var sessionId = z.string();
1222
+ function loose(type, shape) {
1223
+ return z.looseObject({
1224
+ type: z.literal(type),
1225
+ ...shape
1226
+ });
1227
+ }
1228
+ function openObject(shape = {}) {
1229
+ return z.looseObject(shape);
1230
+ }
1231
+ var nullableString = z.string().nullable();
1232
+ var timestamp = z.number().finite();
1233
+ var optionalTimestamp = timestamp.optional();
1234
+ var optionalError = nullableString.optional();
1235
+ var opaqueObject = openObject();
1236
+ var opaqueArray = z.array(z.unknown());
1237
+ var planRevisionNumber = z.number().int().positive();
1238
+ var trailSteps = z.array(openObject({
1239
+ at: timestamp,
1240
+ tool: z.string(),
1241
+ detail: z.string()
1242
+ }));
1243
+ z.object({
1244
+ id: z.string(),
1245
+ label: z.string(),
1246
+ command: z.string(),
1247
+ args: z.array(z.string()),
1248
+ resolvable: z.boolean().nullable()
1249
+ }).strict();
1250
+ var SessionCardFields = z.object({
1251
+ id: sessionId,
1252
+ session: z.string(),
1253
+ taskTitle: TaskTitle.nullable().optional(),
1254
+ taskTitleIsCustom: z.boolean().optional(),
1255
+ path: z.string(),
1256
+ agent: z.string(),
1257
+ state: SessionState,
1258
+ stateSince: timestamp,
1259
+ skipPerms: z.boolean(),
1260
+ saneYolo: z.boolean(),
1261
+ worktree: z.boolean(),
1262
+ workspace: z.boolean().optional(),
1263
+ resumeSessionId: nullableString,
1264
+ ephemeral: z.boolean().optional()
1265
+ });
1266
+ var DIFF_ANNOTATION_NOTE_MAX_CHARS = 1e3;
1267
+ var DIFF_ANNOTATION_PATH_RE = new RegExp(`^[^${String.fromCharCode(0)}-${String.fromCharCode(31)}${String.fromCharCode(127)}-${String.fromCharCode(159)}]+$`);
1268
+ var DiffAnnotation = z.strictObject({
1269
+ section: z.enum(["committed", "uncommitted"]),
1270
+ path: z.string().min(1).max(400).regex(DIFF_ANNOTATION_PATH_RE),
1271
+ line: z.number().int().positive(),
1272
+ side: z.enum(["old", "new"]),
1273
+ note: z.string().min(1).max(DIFF_ANNOTATION_NOTE_MAX_CHARS)
1274
+ });
1275
+ var CONTROL_FRAME_MAX_BYTES = 4096 + 2 * (PLAN_BODY_CAP_BYTES + PLAN_FEEDBACK_MAX_CHARS + 80 * PLAN_COMMENT_MAX_CHARS);
1276
+ var UpdateApplyRefusal = z.object({
1277
+ reason: z.string(),
1278
+ message: z.string()
1279
+ });
1280
+ var InstallFlavor = z.enum([
1281
+ "npm-global",
1282
+ "npx",
1283
+ "clone",
1284
+ "unknown"
1285
+ ]);
1286
+ var updateStatusShape = {
1287
+ updateAvailable: z.boolean(),
1288
+ current: nullableString,
1289
+ latest: nullableString,
1290
+ currentSha: nullableString,
1291
+ latestSha: nullableString,
1292
+ releaseUrl: nullableString,
1293
+ command: z.string(),
1294
+ flavor: InstallFlavor,
1295
+ platform: z.string(),
1296
+ installedBranch: nullableString,
1297
+ upstream: nullableString,
1298
+ isTreeClean: z.boolean().nullable(),
1299
+ lastCheckAt: timestamp,
1300
+ channel: UpdateChannel,
1301
+ behindCount: z.number().int().nonnegative().nullable(),
1302
+ reason: nullableString,
1303
+ journalSummary: UpdateJournalSummary.nullable(),
1304
+ applyRefusal: UpdateApplyRefusal.nullable()
1305
+ };
1306
+ z.object(updateStatusShape);
1307
+ var ClientErrorReport = z.object({
1308
+ name: z.string().max(128),
1309
+ stack: z.string().max(8192)
1310
+ }).strict();
1311
+ var idOnlyClientTypes = [
1312
+ "remove-session",
1313
+ "kill",
1314
+ "start-session",
1315
+ "restart",
1316
+ "force-restart",
1317
+ "sleep",
1318
+ "wake",
1319
+ "merge-session",
1320
+ "finish-session",
1321
+ "merge-continue-session",
1322
+ "discard-session-worktree",
1323
+ "resolve-session-merge",
1324
+ "request-session-diff",
1325
+ "request-change-map",
1326
+ "request-branch-sync",
1327
+ "resync-branch",
1328
+ "debug-state"
1329
+ ];
1330
+ function idOnlyClientVariant(type) {
1331
+ return loose(type, {
1332
+ id: sessionId,
1333
+ force: z.unknown().optional()
1334
+ });
1335
+ }
1336
+ var idOnlyClientVariants = idOnlyClientTypes.map(idOnlyClientVariant);
1337
+ var clientVariants = [
1338
+ loose("add-session", {
1339
+ name: z.string(),
1340
+ path: z.string(),
1341
+ repos: z.array(z.string()).optional(),
1342
+ agent: z.string().optional(),
1343
+ dangerouslySkipPermissions: z.boolean().optional()
1344
+ }),
1345
+ loose("list-conversations", {
1346
+ id: sessionId,
1347
+ requestId
1348
+ }),
1349
+ loose("resume-conversation", {
1350
+ id: sessionId,
1351
+ conversationId: z.string()
1352
+ }),
1353
+ loose("rename-session", {
1354
+ id: sessionId,
1355
+ newName: z.string()
1356
+ }),
1357
+ loose("set-session-title", {
1358
+ id: sessionId,
1359
+ title: TaskTitle
1360
+ }),
1361
+ loose("reorder-sessions", { order: z.array(sessionId) }),
1362
+ loose("ping", { requestId }),
1363
+ loose("get-settings", { requestId }),
1364
+ loose("update-settings", {
1365
+ settings: z.record(z.string(), z.unknown()),
1366
+ requestId
1367
+ }),
1368
+ loose("scan-repo-roots", { requestId }),
1369
+ loose("list-agents", { requestId }),
1370
+ loose("get-posthog-report", {
1371
+ issueId: z.union([z.string(), z.number()]),
1372
+ requestId
1373
+ }),
1374
+ loose("posthog-open-session", {
1375
+ projectId: z.union([z.string(), z.number()]),
1376
+ issueId: z.union([z.string(), z.number()]),
1377
+ requestId
1378
+ }),
1379
+ loose("issue-detail", {
1380
+ requestId: z.string().min(1),
1381
+ repo: IssueRepoSlug,
1382
+ issueNumber: z.number().int().positive()
1383
+ }),
1384
+ loose("open-issue-session", {
1385
+ requestId,
1386
+ projectId: z.string(),
1387
+ repo: IssueRepoSlug,
1388
+ issueNumber: z.number().int().positive()
1389
+ }),
1390
+ loose("posthog-issue-action", {
1391
+ projectId: z.union([z.string(), z.number()]),
1392
+ issueId: z.union([z.string(), z.number()]),
1393
+ action: z.string(),
1394
+ requestId
1395
+ }),
1396
+ loose("team-review-action", {
1397
+ ...TeamReviewActionRequest.shape,
1398
+ requestId
1399
+ }),
1400
+ loose("factory-queue-intent", {
1401
+ ...FactoryQueueIntentRequest.shape,
1402
+ requestId
1403
+ }),
1404
+ loose("factory-control", {
1405
+ ...FactoryControlRequest.shape,
1406
+ requestId
1407
+ }),
1408
+ loose("benchmark-action", {
1409
+ ...BenchmarkActionRequest.shape,
1410
+ requestId
1411
+ }),
1412
+ loose("my-pr-merge", {
1413
+ ...MyPrMergeRequest.shape,
1414
+ requestId
1415
+ }),
1416
+ loose("my-pr-keep-mergeable", {
1417
+ ...MyPrKeepMergeableRequest.shape,
1418
+ requestId
1419
+ }),
1420
+ loose("my-pr-merge-when-ready", {
1421
+ ...MyPrMergeWhenReadyRequest.shape,
1422
+ requestId
1423
+ }),
1424
+ loose("reviews-refresh", {
1425
+ ...ReviewsRefreshRequest.shape,
1426
+ requestId
1427
+ }),
1428
+ loose("posthog-archive-investigation", {
1429
+ id: z.unknown().optional(),
1430
+ requestId
1431
+ }),
1432
+ loose("request-usage-report", {
1433
+ requestId,
1434
+ days: z.unknown().optional(),
1435
+ force: z.unknown().optional()
1436
+ }),
1437
+ loose("request-hooks-report", { requestId }),
1438
+ loose("send-diff-annotations", {
1439
+ id: sessionId,
1440
+ annotations: z.array(DiffAnnotation).min(1).max(50),
1441
+ requestId
1442
+ }),
1443
+ loose("save-hook", {
1444
+ hook: z.record(z.string(), z.unknown()),
1445
+ requestId
1446
+ }),
1447
+ loose("delete-hook", {
1448
+ id: z.string(),
1449
+ requestId
1450
+ }),
1451
+ loose("shutdown"),
1452
+ loose("restart-server"),
1453
+ loose("focus-change", { focused: z.boolean() }),
1454
+ loose("request-health-snapshot"),
1455
+ loose("update-check"),
1456
+ loose("update-apply", {
1457
+ restartWhenStaged: z.boolean().optional(),
1458
+ confirmedSessionIds: z.array(z.string().min(1)).max(1e3).optional()
1459
+ }),
1460
+ loose("session-trace", {
1461
+ id: sessionId,
1462
+ after: z.number().int().nonnegative().default(0),
1463
+ endingAt: z.union([z.number().int().nonnegative(), z.literal("tail")]).optional()
1464
+ }),
1465
+ loose("session-plan", {
1466
+ id: sessionId,
1467
+ agentId: nullableString,
1468
+ revision: planRevisionNumber.optional(),
1469
+ draft: z.boolean().optional()
1470
+ }),
1471
+ loose("plan-decision", PlanDecision.shape),
1472
+ loose("client-error", ClientErrorReport.shape),
1473
+ loose("dismiss", {
1474
+ id: sessionId,
1475
+ force: z.unknown().optional(),
1476
+ expectedState: SessionState.optional()
1477
+ }),
1478
+ ...idOnlyClientVariants
1479
+ ];
1480
+ var ClientMessage = z.discriminatedUnion("type", clientVariants);
1481
+ Object.freeze([
1482
+ "snapshot",
1483
+ "hooks-report",
1484
+ "save-hook-result",
1485
+ "delete-hook-result",
1486
+ "hooks-updated",
1487
+ "state-change",
1488
+ "session-added",
1489
+ "session-removed",
1490
+ "session-renamed",
1491
+ "session-title",
1492
+ "session-modified",
1493
+ "session-git",
1494
+ "session-agents",
1495
+ "session-wakeup",
1496
+ "session-prompt",
1497
+ "session-sleep",
1498
+ "session-wake",
1499
+ "session-merge-status",
1500
+ "session-worktree-blocked",
1501
+ "session-worktree-warning",
1502
+ "session-worktree-ready",
1503
+ "session-diff",
1504
+ "session-diff-error",
1505
+ "change-map",
1506
+ "send-diff-annotations-result",
1507
+ "branch-sync-status",
1508
+ "session-changed",
1509
+ "post-turn-result",
1510
+ "debug-state-response",
1511
+ "session-trace-response",
1512
+ "session-trace-changed",
1513
+ "session-plan-changed",
1514
+ "session-plan-draft",
1515
+ "session-plan-response",
1516
+ "notify",
1517
+ "update-status",
1518
+ "update-progress",
1519
+ "error",
1520
+ "session-error",
1521
+ "settings",
1522
+ "settings-error",
1523
+ "settings-updated",
1524
+ "pong",
1525
+ "agents-listed",
1526
+ "repo-roots-scanned",
1527
+ "conversations",
1528
+ "resume-conversation-ack",
1529
+ "health-snapshot",
1530
+ "posthog-status",
1531
+ "posthog-investigation-activity",
1532
+ "posthog-investigation-finished",
1533
+ "posthog-report",
1534
+ "posthog-open-session-result",
1535
+ "issue-detail-result",
1536
+ "open-issue-session-result",
1537
+ "posthog-issue-action-result",
1538
+ "team-review-action-result",
1539
+ "benchmark-action-result",
1540
+ "factory-queue-intent-result",
1541
+ "factory-control-result",
1542
+ "my-pr-merge-result",
1543
+ "my-pr-keep-mergeable-result",
1544
+ "my-pr-merge-when-ready-result",
1545
+ "reviews-refresh-result",
1546
+ "posthog-archive-investigation-result",
1547
+ "team-review-status",
1548
+ "benchmark-status",
1549
+ "factory-state",
1550
+ "my-prs-status",
1551
+ "issues-status",
1552
+ "branch-gc-status",
1553
+ "usage-sessions",
1554
+ "usage-report",
1555
+ "plan-limits",
1556
+ "usage-budget-alert",
1557
+ "visions-findings",
1558
+ "visions-comments",
1559
+ "visions-hand",
1560
+ "visions-intent",
1561
+ "visions-fix",
1562
+ "visions-snapshot",
1563
+ "ingest-activity",
1564
+ "ingest-snapshot",
1565
+ "client-trust",
1566
+ "sessions-reordered",
1567
+ "shutting-down",
1568
+ "restarting"
1569
+ ]);
1570
+ var serverVariants = [
1571
+ loose("snapshot", {
1572
+ sessions: z.array(SessionSnapshot),
1573
+ serverBuild: nullableString
1574
+ }),
1575
+ loose("hooks-report", {
1576
+ requestId,
1577
+ ts: optionalTimestamp,
1578
+ hooks: z.array(opaqueObject).optional(),
1579
+ builtin: z.array(opaqueObject).optional(),
1580
+ events: z.array(openObject({
1581
+ name: z.string(),
1582
+ matcher: nullableString,
1583
+ description: z.string(),
1584
+ http: z.boolean().optional()
1585
+ })).optional(),
1586
+ projects: z.array(openObject({
1587
+ id: z.string(),
1588
+ name: z.string(),
1589
+ agent: z.string()
1590
+ })).optional(),
1591
+ limits: openObject({ maxTimeoutSec: z.number().int().positive() }).optional(),
1592
+ error: optionalError
1593
+ }),
1594
+ loose("save-hook-result", {
1595
+ requestId,
1596
+ ok: z.boolean(),
1597
+ error: optionalError,
1598
+ hook: opaqueObject.optional()
1599
+ }),
1600
+ loose("delete-hook-result", {
1601
+ requestId,
1602
+ ok: z.boolean(),
1603
+ error: optionalError,
1604
+ id: z.string().optional()
1605
+ }),
1606
+ loose("hooks-updated", { count: z.number().int().nonnegative() }),
1607
+ loose("state-change", {
1608
+ id: sessionId,
1609
+ session: z.string(),
1610
+ from: SessionState,
1611
+ to: SessionState,
1612
+ event: z.string(),
1613
+ timestamp,
1614
+ skipPerms: z.boolean().optional(),
1615
+ saneYolo: z.boolean().optional(),
1616
+ hasEndedTurn: z.boolean().optional()
1617
+ }),
1618
+ loose("session-added", SessionCardFields.shape),
1619
+ loose("session-modified", SessionCardFields.shape),
1620
+ loose("session-removed", {
1621
+ id: sessionId,
1622
+ session: z.string()
1623
+ }),
1624
+ loose("session-renamed", {
1625
+ id: sessionId,
1626
+ oldName: z.string(),
1627
+ newName: z.string()
1628
+ }),
1629
+ loose("session-title", {
1630
+ id: sessionId,
1631
+ taskTitle: TaskTitle.nullable(),
1632
+ isCustom: z.boolean()
1633
+ }),
1634
+ loose("session-git", {
1635
+ id: sessionId,
1636
+ worktree: z.boolean()
1637
+ }),
1638
+ loose("session-agents", {
1639
+ id: sessionId,
1640
+ activeAgents: z.number().int().nonnegative(),
1641
+ awaitingBackgroundTasks: z.boolean(),
1642
+ timestamp
1643
+ }),
1644
+ loose("session-wakeup", {
1645
+ id: sessionId,
1646
+ pendingWakeup: PendingWakeup.nullable(),
1647
+ timestamp
1648
+ }),
1649
+ loose("session-prompt", {
1650
+ isCompacting: z.boolean().optional(),
1651
+ id: sessionId,
1652
+ pendingPromptKind: nullableString,
1653
+ pendingPromptDetail: PendingPromptDetail.nullable().optional(),
1654
+ timestamp
1655
+ }),
1656
+ loose("session-sleep"),
1657
+ loose("session-wake"),
1658
+ loose("session-merge-status", {
1659
+ id: sessionId,
1660
+ mergeStatus: z.string(),
1661
+ reason: nullableString,
1662
+ parked: z.boolean(),
1663
+ timestamp
1664
+ }),
1665
+ loose("session-worktree-blocked", {
1666
+ id: sessionId,
1667
+ session: z.string(),
1668
+ branch: nullableString,
1669
+ notice: nullableString,
1670
+ timestamp
1671
+ }),
1672
+ loose("session-worktree-warning", {
1673
+ id: sessionId,
1674
+ session: z.string(),
1675
+ branch: nullableString,
1676
+ notice: nullableString,
1677
+ timestamp
1678
+ }),
1679
+ loose("session-worktree-ready", {
1680
+ id: sessionId,
1681
+ session: z.string(),
1682
+ branch: nullableString,
1683
+ base: nullableString,
1684
+ timestamp
1685
+ }),
1686
+ loose("session-diff", {
1687
+ id: sessionId,
1688
+ committed: openObject({
1689
+ stat: z.string(),
1690
+ diff: z.string()
1691
+ }),
1692
+ uncommitted: openObject({
1693
+ stat: z.string(),
1694
+ diff: z.string()
1695
+ }),
1696
+ hasCommits: z.boolean()
1697
+ }),
1698
+ loose("session-diff-error", {
1699
+ id: sessionId,
1700
+ message: z.string()
1701
+ }),
1702
+ loose("change-map", {
1703
+ id: sessionId,
1704
+ map: ChangeMap
1705
+ }),
1706
+ loose("send-diff-annotations-result", {
1707
+ requestId,
1708
+ ok: z.boolean(),
1709
+ error: optionalError,
1710
+ pending: z.boolean().optional()
1711
+ }),
1712
+ loose("branch-sync-status", {
1713
+ id: sessionId,
1714
+ branch: nullableString,
1715
+ upstream: nullableString,
1716
+ state: z.string(),
1717
+ ahead: z.number().int().nonnegative(),
1718
+ behind: z.number().int().nonnegative(),
1719
+ fetched: z.boolean().nullable(),
1720
+ action: z.string().optional(),
1721
+ error: optionalError
1722
+ }),
1723
+ loose("session-changed", { id: sessionId }),
1724
+ loose("post-turn-result", {
1725
+ id: sessionId,
1726
+ mode: z.string(),
1727
+ skipped: nullableString,
1728
+ filesFixed: z.number().int().nonnegative(),
1729
+ findings: z.array(openObject({
1730
+ file: z.string(),
1731
+ rule: z.string(),
1732
+ count: z.number().int().nonnegative()
1733
+ })),
1734
+ timestamp
1735
+ }),
1736
+ loose("debug-state-response", {
1737
+ id: sessionId,
1738
+ payload: opaqueObject
1739
+ }),
1740
+ loose("session-trace-response", {
1741
+ id: sessionId,
1742
+ records: z.array(TraceRecord),
1743
+ start: z.number().int().nonnegative(),
1744
+ next: z.number().int().nonnegative(),
1745
+ reset: z.boolean(),
1746
+ path: z.string()
1747
+ }),
1748
+ loose("session-trace-changed", { id: sessionId }),
1749
+ loose("session-plan-changed", PlanChangedPush.shape),
1750
+ loose("session-plan-draft", PlanDraftPush.shape),
1751
+ loose("session-plan-response", PlanResponseFrame.shape),
1752
+ loose("notify", {
1753
+ session: z.string(),
1754
+ category: z.string(),
1755
+ message: z.string(),
1756
+ escalationCount: z.number().int().nonnegative(),
1757
+ kind: z.literal("plan").optional()
1758
+ }),
1759
+ loose("update-status", updateStatusShape),
1760
+ loose("update-progress", { journal: UpdateJournal }),
1761
+ loose("error", {
1762
+ id: sessionId.optional(),
1763
+ message: z.string(),
1764
+ requestId,
1765
+ scope: z.string().optional()
1766
+ }),
1767
+ loose("session-error", {
1768
+ id: sessionId.optional(),
1769
+ session: z.string(),
1770
+ message: z.string(),
1771
+ scope: z.string().optional()
1772
+ }),
1773
+ loose("settings", {
1774
+ settings: opaqueObject,
1775
+ requestId
1776
+ }),
1777
+ loose("settings-error", {
1778
+ message: z.string(),
1779
+ requestId
1780
+ }),
1781
+ loose("settings-updated", {
1782
+ settings: opaqueObject,
1783
+ requestId
1784
+ }),
1785
+ loose("pong", { requestId }),
1786
+ loose("agents-listed", {
1787
+ requestId,
1788
+ agents: z.array(openObject({
1789
+ id: z.string(),
1790
+ label: z.string(),
1791
+ resolvable: z.boolean()
1792
+ }))
1793
+ }),
1794
+ loose("repo-roots-scanned", {
1795
+ requestId,
1796
+ directories: z.array(openObject({
1797
+ root: z.string(),
1798
+ projects: z.array(openObject({
1799
+ name: z.string(),
1800
+ path: z.string()
1801
+ }))
1802
+ })),
1803
+ error: z.string().optional()
1804
+ }),
1805
+ loose("conversations", {
1806
+ requestId,
1807
+ id: nullableString,
1808
+ current: nullableString.optional(),
1809
+ conversations: z.array(openObject({
1810
+ id: z.string(),
1811
+ title: z.string(),
1812
+ cwd: z.string(),
1813
+ worktreePath: z.string(),
1814
+ worktreeName: z.string(),
1815
+ gitBranch: nullableString,
1816
+ mtime: timestamp
1817
+ })),
1818
+ error: z.string().optional()
1819
+ }),
1820
+ loose("resume-conversation-ack", {
1821
+ id: sessionId.optional(),
1822
+ resumeSessionId: nullableString.optional(),
1823
+ ok: z.boolean(),
1824
+ error: z.string().optional(),
1825
+ requestId
1826
+ }),
1827
+ loose("health-snapshot", { stats: opaqueObject }),
1828
+ loose("posthog-status", {
1829
+ ts: timestamp,
1830
+ intervalMinutes: z.number(),
1831
+ projects: z.array(opaqueObject),
1832
+ investigations: z.array(opaqueObject)
1833
+ }),
1834
+ loose("posthog-investigation-activity", {
1835
+ projectId: z.union([z.string(), z.number()]),
1836
+ issueId: z.string(),
1837
+ inFlight: z.literal(true),
1838
+ startedAt: timestamp.nullable(),
1839
+ trail: trailSteps
1840
+ }),
1841
+ loose("posthog-investigation-finished", {
1842
+ projectId: z.union([z.string(), z.number()]),
1843
+ issueId: z.string(),
1844
+ verdict: z.string(),
1845
+ summaryLine: nullableString,
1846
+ startedAt: timestamp.nullable(),
1847
+ trail: trailSteps
1848
+ }),
1849
+ loose("posthog-report", {
1850
+ requestId,
1851
+ ok: z.boolean(),
1852
+ found: z.boolean(),
1853
+ issueId: nullableString,
1854
+ format: z.string().optional(),
1855
+ content: z.string().optional(),
1856
+ message: z.string().optional(),
1857
+ error: z.string().optional()
1858
+ }),
1859
+ loose("posthog-open-session-result", {
1860
+ requestId,
1861
+ ok: z.boolean(),
1862
+ error: optionalError,
1863
+ sessionId: z.string().optional(),
1864
+ sessionName: z.string().optional(),
1865
+ pending: z.boolean().optional()
1866
+ }),
1867
+ loose("issue-detail-result", {
1868
+ requestId: z.string().min(1),
1869
+ ok: z.boolean(),
1870
+ body: z.string().nullable(),
1871
+ error: z.string().nullable()
1872
+ }),
1873
+ loose("open-issue-session-result", {
1874
+ requestId,
1875
+ ok: z.boolean(),
1876
+ error: optionalError,
1877
+ sessionId: z.string().optional(),
1878
+ sessionName: z.string().optional(),
1879
+ pending: z.boolean().optional(),
1880
+ existing: z.boolean().optional()
1881
+ }),
1882
+ loose("posthog-issue-action-result", {
1883
+ requestId,
1884
+ ok: z.boolean(),
1885
+ error: optionalError,
1886
+ status: nullableString.optional()
1887
+ }),
1888
+ loose("team-review-action-result", {
1889
+ ...TeamReviewActionResult.shape,
1890
+ requestId
1891
+ }),
1892
+ loose("factory-queue-intent-result", {
1893
+ ...FactoryQueueIntentResult.shape,
1894
+ requestId
1895
+ }),
1896
+ loose("factory-control-result", {
1897
+ ...FactoryControlResult.shape,
1898
+ requestId
1899
+ }),
1900
+ loose("benchmark-action-result", {
1901
+ ...BenchmarkActionResult.shape,
1902
+ requestId
1903
+ }),
1904
+ loose("my-pr-merge-result", {
1905
+ ...MyPrMergeResult.shape,
1906
+ requestId
1907
+ }),
1908
+ loose("my-pr-keep-mergeable-result", {
1909
+ ...MyPrKeepMergeableResult.shape,
1910
+ requestId
1911
+ }),
1912
+ loose("my-pr-merge-when-ready-result", {
1913
+ ...MyPrMergeWhenReadyResult.shape,
1914
+ requestId
1915
+ }),
1916
+ loose("reviews-refresh-result", {
1917
+ ...ReviewsRefreshResult.shape,
1918
+ requestId
1919
+ }),
1920
+ loose("posthog-archive-investigation-result", {
1921
+ requestId,
1922
+ ok: z.boolean(),
1923
+ error: optionalError
1924
+ }),
1925
+ TeamReviewStatus,
1926
+ BenchmarkStatus,
1927
+ loose("factory-state", FactoryState.shape),
1928
+ MyPrsStatus,
1929
+ IssuesStatus,
1930
+ loose("branch-gc-status"),
1931
+ loose("usage-sessions", {
1932
+ ts: timestamp,
1933
+ pricingSource: nullableString,
1934
+ sessions: z.array(openObject({
1935
+ id: sessionId,
1936
+ tokens: z.number(),
1937
+ costUSD: z.number(),
1938
+ officialCostUSD: z.number().nullable().optional()
1939
+ }))
1940
+ }),
1941
+ loose("usage-report", {
1942
+ requestId,
1943
+ ts: optionalTimestamp,
1944
+ tz: z.string().optional(),
1945
+ blockHours: z.number().optional(),
1946
+ totals: opaqueObject.optional(),
1947
+ daily: opaqueArray.optional(),
1948
+ models: opaqueArray.optional(),
1949
+ sessions: opaqueArray.optional(),
1950
+ blocks: opaqueArray.optional(),
1951
+ activeBlock: z.unknown().nullable().optional(),
1952
+ anomaly: z.unknown().nullable().optional(),
1953
+ byLane: z.unknown().optional(),
1954
+ planWindowLanes: z.unknown().nullable().optional(),
1955
+ budget: z.unknown().optional(),
1956
+ savings: z.unknown().optional(),
1957
+ tokenLimit: z.unknown().nullable().optional(),
1958
+ pricing: opaqueObject.optional(),
1959
+ scan: opaqueObject.optional(),
1960
+ warning: optionalError,
1961
+ error: optionalError
1962
+ }),
1963
+ loose("plan-limits", {
1964
+ ts: timestamp,
1965
+ fiveHour: z.unknown().nullable(),
1966
+ sevenDay: z.unknown().nullable(),
1967
+ source: z.string()
1968
+ }),
1969
+ loose("usage-budget-alert", {
1970
+ scope: z.string(),
1971
+ periodKey: z.string(),
1972
+ threshold: z.number(),
1973
+ text: z.string(),
1974
+ ts: timestamp
1975
+ }),
1976
+ loose("visions-findings", {
1977
+ uri: z.string(),
1978
+ diagnostics: opaqueArray,
1979
+ ts: timestamp
1980
+ }),
1981
+ loose("visions-comments", {
1982
+ uri: z.string(),
1983
+ comments: opaqueArray,
1984
+ ts: timestamp
1985
+ }),
1986
+ loose("visions-hand", {
1987
+ uri: z.string(),
1988
+ hand: nullableString,
1989
+ ts: timestamp
1990
+ }),
1991
+ loose("visions-intent", {
1992
+ projectId: nullableString,
1993
+ intent: opaqueObject,
1994
+ ts: timestamp
1995
+ }),
1996
+ loose("visions-fix", {
1997
+ uri: z.string(),
1998
+ fix: opaqueObject,
1999
+ ts: timestamp
2000
+ }),
2001
+ loose("visions-snapshot", {
2002
+ documents: z.array(opaqueObject),
2003
+ intent: opaqueObject,
2004
+ fixes: z.array(opaqueObject),
2005
+ ts: timestamp
2006
+ }),
2007
+ loose("ingest-activity", {
2008
+ events: z.array(opaqueObject),
2009
+ overflow: z.number().int().nonnegative(),
2010
+ ts: timestamp
2011
+ }),
2012
+ loose("ingest-snapshot", {
2013
+ events: z.array(opaqueObject),
2014
+ sources: z.unknown(),
2015
+ ts: timestamp
2016
+ }),
2017
+ loose("client-trust", { trust: z.enum(["local", "remote"]) }),
2018
+ loose("sessions-reordered", { order: z.array(sessionId) }),
2019
+ loose("shutting-down"),
2020
+ loose("restarting")
2021
+ ];
2022
+ z.discriminatedUnion("type", serverVariants);
2023
+ var viewerCols = z.number().int().min(1).max(500);
2024
+ var viewerRows = z.number().int().min(1).max(200);
2025
+ var DataClientMessage = z.discriminatedUnion("type", [
2026
+ z.object({
2027
+ type: z.literal("input"),
2028
+ data: z.string()
2029
+ }),
2030
+ z.object({
2031
+ type: z.literal("claim"),
2032
+ cols: viewerCols,
2033
+ rows: viewerRows
2034
+ }),
2035
+ z.object({ type: z.literal("unview") })
2036
+ ]);
2037
+ z.object({
2038
+ type: z.literal("pty-size"),
2039
+ cols: viewerCols,
2040
+ rows: viewerRows,
2041
+ seq: z.number().int().nonnegative()
2042
+ });
2043
+ function decodeJson(raw) {
2044
+ try {
2045
+ return JSON.parse(raw);
2046
+ } catch {
2047
+ return null;
2048
+ }
2049
+ }
2050
+ function parseDataClientMessage(raw) {
2051
+ const parsed = DataClientMessage.safeParse(decodeJson(raw));
2052
+ if (!parsed.success) return null;
2053
+ return parsed.data;
2054
+ }
2055
+ //#endregion
2056
+ //#region shared/contracts/hooks.ts
2057
+ var HTTP_URL_RE = /^https?:\/\/\S+$/i;
2058
+ var HookPayload = z.record(z.string(), z.unknown());
2059
+ var HookEnvelope = z.object({
2060
+ glimmervoidId: z.string().min(1),
2061
+ event: z.string().min(1),
2062
+ token: z.string().nullable().optional(),
2063
+ payload: HookPayload
2064
+ });
2065
+ z.object({
2066
+ id: z.string().min(1),
2067
+ name: z.string().min(1),
2068
+ event: z.string().min(1),
2069
+ matcher: z.string().optional(),
2070
+ type: z.enum(["command", "http"]),
2071
+ command: z.string().optional(),
2072
+ url: z.string().optional(),
2073
+ timeout: z.number().int().positive().optional(),
2074
+ enabled: z.boolean(),
2075
+ projects: z.array(z.string()).optional()
2076
+ }).passthrough();
2077
+ //#endregion
2078
+ export { FactoryIssueQueryRow as $, BenchmarkActionRequest as A, PrCheckoutCaseInput as B, IssueKey as C, IssuesStatus as D, IssuesState as E, BenchmarkStatus as F, TelemetryState as G, PendingCrashReport as H, BenchmarkSuite as I, FACTORY_ERROR_MAX_CHARS as J, FACTORY_DECISION_OUTPUT_MAX_BYTES as K, CommitComparison as L, BenchmarkId as M, BenchmarkJudgement as N, ChangeMap as O, BenchmarkRun as P, FactoryIssue as Q, MergedPrListing as R, GithubIssueResponse as S, IssuesSearchResponse as T, TELEMETRY_EVENT_SCHEMAS as U, FeatureFlagsResponse as V, TELEMETRY_KILL_SWITCH_FLAG as W, FactoryControlRequest as X, FactoryConsequences as Y, FactoryHogQLResponse as Z, PlanDecision as _, ClientMessage as a, FactoryWorkerEvent as at, planTitle as b, UpdateJournal as c, TraceRecord as d, FactoryLaneState as et, PLAN_BODY_CAP_BYTES as f, PLAN_TOOL_NAME as g, PLAN_RESULT_HOOK_EVENT as h, CONTROL_FRAME_MAX_BYTES as i, FactoryReviewerOutput as it, BenchmarkCase as j, changeMapFactId as k, MAX_RAW_LINE_CHARS as l, PLAN_HOOK_OUTPUT_MAX_CHARS as m, HookEnvelope as n, FactoryQueueIntentRequest as nt, DIFF_ANNOTATION_NOTE_MAX_CHARS as o, isSingleFactoryPathSegment as ot, PLAN_HOOK_EVENT as p, FactoryDecisionLogLine as q, parseDataClientMessage as r, FactoryReviewVerdict as rt, InstallFlavor as s, HTTP_URL_RE as t, FactoryProjectState as tt, TraceCheckpoint as u, PlanRevision as v, IssueUpdate as w, GithubIssuePullRequestsRepository as x, parseExitPlanModeHookPayload as y, MinedPrReviewData as z };