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