@telora/daemon-core 0.2.5

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 (81) hide show
  1. package/dist/activity-tracker.d.ts +69 -0
  2. package/dist/activity-tracker.d.ts.map +1 -0
  3. package/dist/activity-tracker.js +155 -0
  4. package/dist/activity-tracker.js.map +1 -0
  5. package/dist/api-client.d.ts +94 -0
  6. package/dist/api-client.d.ts.map +1 -0
  7. package/dist/api-client.js +145 -0
  8. package/dist/api-client.js.map +1 -0
  9. package/dist/config.d.ts +117 -0
  10. package/dist/config.d.ts.map +1 -0
  11. package/dist/config.js +348 -0
  12. package/dist/config.js.map +1 -0
  13. package/dist/engine.d.ts +120 -0
  14. package/dist/engine.d.ts.map +1 -0
  15. package/dist/engine.js +18 -0
  16. package/dist/engine.js.map +1 -0
  17. package/dist/escalation-types.d.ts +31 -0
  18. package/dist/escalation-types.d.ts.map +1 -0
  19. package/dist/escalation-types.js +24 -0
  20. package/dist/escalation-types.js.map +1 -0
  21. package/dist/event-logger.d.ts +13 -0
  22. package/dist/event-logger.d.ts.map +1 -0
  23. package/dist/event-logger.js +82 -0
  24. package/dist/event-logger.js.map +1 -0
  25. package/dist/git.d.ts +39 -0
  26. package/dist/git.d.ts.map +1 -0
  27. package/dist/git.js +72 -0
  28. package/dist/git.js.map +1 -0
  29. package/dist/index.d.ts +20 -0
  30. package/dist/index.d.ts.map +1 -0
  31. package/dist/index.js +36 -0
  32. package/dist/index.js.map +1 -0
  33. package/dist/lifecycle.d.ts +104 -0
  34. package/dist/lifecycle.d.ts.map +1 -0
  35. package/dist/lifecycle.js +192 -0
  36. package/dist/lifecycle.js.map +1 -0
  37. package/dist/log-manager.d.ts +83 -0
  38. package/dist/log-manager.d.ts.map +1 -0
  39. package/dist/log-manager.js +217 -0
  40. package/dist/log-manager.js.map +1 -0
  41. package/dist/otel-env.d.ts +29 -0
  42. package/dist/otel-env.d.ts.map +1 -0
  43. package/dist/otel-env.js +44 -0
  44. package/dist/otel-env.js.map +1 -0
  45. package/dist/resilience.d.ts +127 -0
  46. package/dist/resilience.d.ts.map +1 -0
  47. package/dist/resilience.js +300 -0
  48. package/dist/resilience.js.map +1 -0
  49. package/dist/resource-governor.d.ts +83 -0
  50. package/dist/resource-governor.d.ts.map +1 -0
  51. package/dist/resource-governor.js +184 -0
  52. package/dist/resource-governor.js.map +1 -0
  53. package/dist/spawn.d.ts +72 -0
  54. package/dist/spawn.d.ts.map +1 -0
  55. package/dist/spawn.js +82 -0
  56. package/dist/spawn.js.map +1 -0
  57. package/dist/stream-json.d.ts +885 -0
  58. package/dist/stream-json.d.ts.map +1 -0
  59. package/dist/stream-json.js +298 -0
  60. package/dist/stream-json.js.map +1 -0
  61. package/dist/token-usage.d.ts +67 -0
  62. package/dist/token-usage.d.ts.map +1 -0
  63. package/dist/token-usage.js +150 -0
  64. package/dist/token-usage.js.map +1 -0
  65. package/dist/transforms.d.ts +64 -0
  66. package/dist/transforms.d.ts.map +1 -0
  67. package/dist/transforms.js +78 -0
  68. package/dist/transforms.js.map +1 -0
  69. package/dist/unified-config.d.ts +62 -0
  70. package/dist/unified-config.d.ts.map +1 -0
  71. package/dist/unified-config.js +155 -0
  72. package/dist/unified-config.js.map +1 -0
  73. package/dist/workflow-types.d.ts +202 -0
  74. package/dist/workflow-types.d.ts.map +1 -0
  75. package/dist/workflow-types.js +15 -0
  76. package/dist/workflow-types.js.map +1 -0
  77. package/dist/worktree.d.ts +92 -0
  78. package/dist/worktree.d.ts.map +1 -0
  79. package/dist/worktree.js +221 -0
  80. package/dist/worktree.js.map +1 -0
  81. package/package.json +57 -0
@@ -0,0 +1,885 @@
1
+ /**
2
+ * Stream-JSON protocol module -- shared core for Claude Code interactive sessions.
3
+ *
4
+ * This is the canonical implementation used by both the Telora daemon and factory
5
+ * engines. It handles parsing NDJSON output from `--output-format stream-json`
6
+ * and writing messages for `--input-format stream-json`.
7
+ *
8
+ * Wire format: newline-delimited JSON (one JSON object per line).
9
+ *
10
+ * All inbound events are validated against Zod schemas before routing.
11
+ * Malformed events are logged, counted, and skipped -- never crash the parser.
12
+ */
13
+ import { EventEmitter } from 'node:events';
14
+ import type { Readable, Writable } from 'node:stream';
15
+ import { z } from 'zod';
16
+ declare const OutputEventSchema: z.ZodUnion<[z.ZodObject<{
17
+ type: z.ZodLiteral<"system">;
18
+ subtype: z.ZodLiteral<"init">;
19
+ uuid: z.ZodString;
20
+ session_id: z.ZodString;
21
+ cwd: z.ZodString;
22
+ model: z.ZodString;
23
+ tools: z.ZodArray<z.ZodString, "many">;
24
+ mcp_servers: z.ZodArray<z.ZodObject<{
25
+ name: z.ZodString;
26
+ status: z.ZodString;
27
+ }, "strip", z.ZodTypeAny, {
28
+ status: string;
29
+ name: string;
30
+ }, {
31
+ status: string;
32
+ name: string;
33
+ }>, "many">;
34
+ permissionMode: z.ZodString;
35
+ }, "strip", z.ZodTypeAny, {
36
+ type: "system";
37
+ subtype: "init";
38
+ uuid: string;
39
+ session_id: string;
40
+ cwd: string;
41
+ model: string;
42
+ tools: string[];
43
+ mcp_servers: {
44
+ status: string;
45
+ name: string;
46
+ }[];
47
+ permissionMode: string;
48
+ }, {
49
+ type: "system";
50
+ subtype: "init";
51
+ uuid: string;
52
+ session_id: string;
53
+ cwd: string;
54
+ model: string;
55
+ tools: string[];
56
+ mcp_servers: {
57
+ status: string;
58
+ name: string;
59
+ }[];
60
+ permissionMode: string;
61
+ }>, z.ZodObject<{
62
+ type: z.ZodLiteral<"system">;
63
+ subtype: z.ZodEnum<["teammate_spawned", "teammate_idle", "teammate_completed"]>;
64
+ uuid: z.ZodString;
65
+ session_id: z.ZodString;
66
+ agent_id: z.ZodString;
67
+ agent_name: z.ZodString;
68
+ team_id: z.ZodString;
69
+ agent_type: z.ZodOptional<z.ZodString>;
70
+ result: z.ZodOptional<z.ZodString>;
71
+ is_error: z.ZodOptional<z.ZodBoolean>;
72
+ }, "strip", z.ZodTypeAny, {
73
+ type: "system";
74
+ subtype: "teammate_spawned" | "teammate_idle" | "teammate_completed";
75
+ uuid: string;
76
+ session_id: string;
77
+ agent_id: string;
78
+ agent_name: string;
79
+ team_id: string;
80
+ agent_type?: string | undefined;
81
+ result?: string | undefined;
82
+ is_error?: boolean | undefined;
83
+ }, {
84
+ type: "system";
85
+ subtype: "teammate_spawned" | "teammate_idle" | "teammate_completed";
86
+ uuid: string;
87
+ session_id: string;
88
+ agent_id: string;
89
+ agent_name: string;
90
+ team_id: string;
91
+ agent_type?: string | undefined;
92
+ result?: string | undefined;
93
+ is_error?: boolean | undefined;
94
+ }>, z.ZodObject<{
95
+ type: z.ZodLiteral<"system">;
96
+ subtype: z.ZodString;
97
+ uuid: z.ZodString;
98
+ session_id: z.ZodString;
99
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
100
+ type: z.ZodLiteral<"system">;
101
+ subtype: z.ZodString;
102
+ uuid: z.ZodString;
103
+ session_id: z.ZodString;
104
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
105
+ type: z.ZodLiteral<"system">;
106
+ subtype: z.ZodString;
107
+ uuid: z.ZodString;
108
+ session_id: z.ZodString;
109
+ }, z.ZodTypeAny, "passthrough">>, z.ZodObject<{
110
+ type: z.ZodLiteral<"stream_event">;
111
+ event: z.ZodObject<{
112
+ type: z.ZodString;
113
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
114
+ type: z.ZodString;
115
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
116
+ type: z.ZodString;
117
+ }, z.ZodTypeAny, "passthrough">>;
118
+ parent_tool_use_id: z.ZodNullable<z.ZodString>;
119
+ uuid: z.ZodString;
120
+ session_id: z.ZodString;
121
+ }, "strip", z.ZodTypeAny, {
122
+ type: "stream_event";
123
+ uuid: string;
124
+ session_id: string;
125
+ parent_tool_use_id: string | null;
126
+ event: {
127
+ type: string;
128
+ } & {
129
+ [k: string]: unknown;
130
+ };
131
+ }, {
132
+ type: "stream_event";
133
+ uuid: string;
134
+ session_id: string;
135
+ parent_tool_use_id: string | null;
136
+ event: {
137
+ type: string;
138
+ } & {
139
+ [k: string]: unknown;
140
+ };
141
+ }>, z.ZodObject<{
142
+ type: z.ZodLiteral<"assistant">;
143
+ uuid: z.ZodString;
144
+ session_id: z.ZodString;
145
+ message: z.ZodObject<{
146
+ id: z.ZodString;
147
+ type: z.ZodLiteral<"message">;
148
+ role: z.ZodLiteral<"assistant">;
149
+ content: z.ZodArray<z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
150
+ type: z.ZodLiteral<"text">;
151
+ text: z.ZodString;
152
+ }, "strip", z.ZodTypeAny, {
153
+ type: "text";
154
+ text: string;
155
+ }, {
156
+ type: "text";
157
+ text: string;
158
+ }>, z.ZodObject<{
159
+ type: z.ZodLiteral<"tool_use">;
160
+ id: z.ZodString;
161
+ name: z.ZodString;
162
+ input: z.ZodRecord<z.ZodString, z.ZodUnknown>;
163
+ }, "strip", z.ZodTypeAny, {
164
+ type: "tool_use";
165
+ id: string;
166
+ name: string;
167
+ input: Record<string, unknown>;
168
+ }, {
169
+ type: "tool_use";
170
+ id: string;
171
+ name: string;
172
+ input: Record<string, unknown>;
173
+ }>, z.ZodObject<{
174
+ type: z.ZodLiteral<"thinking">;
175
+ thinking: z.ZodString;
176
+ signature: z.ZodString;
177
+ }, "strip", z.ZodTypeAny, {
178
+ type: "thinking";
179
+ thinking: string;
180
+ signature: string;
181
+ }, {
182
+ type: "thinking";
183
+ thinking: string;
184
+ signature: string;
185
+ }>]>, "many">;
186
+ model: z.ZodString;
187
+ stop_reason: z.ZodNullable<z.ZodString>;
188
+ usage: z.ZodObject<{
189
+ input_tokens: z.ZodNumber;
190
+ output_tokens: z.ZodNumber;
191
+ cache_creation_input_tokens: z.ZodOptional<z.ZodNumber>;
192
+ cache_read_input_tokens: z.ZodOptional<z.ZodNumber>;
193
+ }, "strip", z.ZodTypeAny, {
194
+ input_tokens: number;
195
+ output_tokens: number;
196
+ cache_creation_input_tokens?: number | undefined;
197
+ cache_read_input_tokens?: number | undefined;
198
+ }, {
199
+ input_tokens: number;
200
+ output_tokens: number;
201
+ cache_creation_input_tokens?: number | undefined;
202
+ cache_read_input_tokens?: number | undefined;
203
+ }>;
204
+ }, "strip", z.ZodTypeAny, {
205
+ type: "message";
206
+ id: string;
207
+ model: string;
208
+ role: "assistant";
209
+ content: ({
210
+ type: "text";
211
+ text: string;
212
+ } | {
213
+ type: "tool_use";
214
+ id: string;
215
+ name: string;
216
+ input: Record<string, unknown>;
217
+ } | {
218
+ type: "thinking";
219
+ thinking: string;
220
+ signature: string;
221
+ })[];
222
+ stop_reason: string | null;
223
+ usage: {
224
+ input_tokens: number;
225
+ output_tokens: number;
226
+ cache_creation_input_tokens?: number | undefined;
227
+ cache_read_input_tokens?: number | undefined;
228
+ };
229
+ }, {
230
+ type: "message";
231
+ id: string;
232
+ model: string;
233
+ role: "assistant";
234
+ content: ({
235
+ type: "text";
236
+ text: string;
237
+ } | {
238
+ type: "tool_use";
239
+ id: string;
240
+ name: string;
241
+ input: Record<string, unknown>;
242
+ } | {
243
+ type: "thinking";
244
+ thinking: string;
245
+ signature: string;
246
+ })[];
247
+ stop_reason: string | null;
248
+ usage: {
249
+ input_tokens: number;
250
+ output_tokens: number;
251
+ cache_creation_input_tokens?: number | undefined;
252
+ cache_read_input_tokens?: number | undefined;
253
+ };
254
+ }>;
255
+ parent_tool_use_id: z.ZodNullable<z.ZodString>;
256
+ }, "strip", z.ZodTypeAny, {
257
+ message: {
258
+ type: "message";
259
+ id: string;
260
+ model: string;
261
+ role: "assistant";
262
+ content: ({
263
+ type: "text";
264
+ text: string;
265
+ } | {
266
+ type: "tool_use";
267
+ id: string;
268
+ name: string;
269
+ input: Record<string, unknown>;
270
+ } | {
271
+ type: "thinking";
272
+ thinking: string;
273
+ signature: string;
274
+ })[];
275
+ stop_reason: string | null;
276
+ usage: {
277
+ input_tokens: number;
278
+ output_tokens: number;
279
+ cache_creation_input_tokens?: number | undefined;
280
+ cache_read_input_tokens?: number | undefined;
281
+ };
282
+ };
283
+ type: "assistant";
284
+ uuid: string;
285
+ session_id: string;
286
+ parent_tool_use_id: string | null;
287
+ }, {
288
+ message: {
289
+ type: "message";
290
+ id: string;
291
+ model: string;
292
+ role: "assistant";
293
+ content: ({
294
+ type: "text";
295
+ text: string;
296
+ } | {
297
+ type: "tool_use";
298
+ id: string;
299
+ name: string;
300
+ input: Record<string, unknown>;
301
+ } | {
302
+ type: "thinking";
303
+ thinking: string;
304
+ signature: string;
305
+ })[];
306
+ stop_reason: string | null;
307
+ usage: {
308
+ input_tokens: number;
309
+ output_tokens: number;
310
+ cache_creation_input_tokens?: number | undefined;
311
+ cache_read_input_tokens?: number | undefined;
312
+ };
313
+ };
314
+ type: "assistant";
315
+ uuid: string;
316
+ session_id: string;
317
+ parent_tool_use_id: string | null;
318
+ }>, z.ZodObject<{
319
+ type: z.ZodLiteral<"user">;
320
+ uuid: z.ZodString;
321
+ session_id: z.ZodString;
322
+ message: z.ZodObject<{
323
+ role: z.ZodLiteral<"user">;
324
+ content: z.ZodArray<z.ZodObject<{
325
+ type: z.ZodLiteral<"tool_result">;
326
+ tool_use_id: z.ZodString;
327
+ content: z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodRecord<z.ZodString, z.ZodUnknown>, "many">]>;
328
+ }, "strip", z.ZodTypeAny, {
329
+ type: "tool_result";
330
+ content: string | Record<string, unknown>[];
331
+ tool_use_id: string;
332
+ }, {
333
+ type: "tool_result";
334
+ content: string | Record<string, unknown>[];
335
+ tool_use_id: string;
336
+ }>, "many">;
337
+ }, "strip", z.ZodTypeAny, {
338
+ role: "user";
339
+ content: {
340
+ type: "tool_result";
341
+ content: string | Record<string, unknown>[];
342
+ tool_use_id: string;
343
+ }[];
344
+ }, {
345
+ role: "user";
346
+ content: {
347
+ type: "tool_result";
348
+ content: string | Record<string, unknown>[];
349
+ tool_use_id: string;
350
+ }[];
351
+ }>;
352
+ parent_tool_use_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
353
+ }, "strip", z.ZodTypeAny, {
354
+ message: {
355
+ role: "user";
356
+ content: {
357
+ type: "tool_result";
358
+ content: string | Record<string, unknown>[];
359
+ tool_use_id: string;
360
+ }[];
361
+ };
362
+ type: "user";
363
+ uuid: string;
364
+ session_id: string;
365
+ parent_tool_use_id?: string | null | undefined;
366
+ }, {
367
+ message: {
368
+ role: "user";
369
+ content: {
370
+ type: "tool_result";
371
+ content: string | Record<string, unknown>[];
372
+ tool_use_id: string;
373
+ }[];
374
+ };
375
+ type: "user";
376
+ uuid: string;
377
+ session_id: string;
378
+ parent_tool_use_id?: string | null | undefined;
379
+ }>, z.ZodObject<{
380
+ type: z.ZodLiteral<"user">;
381
+ uuid: z.ZodString;
382
+ session_id: z.ZodString;
383
+ message: z.ZodObject<{
384
+ role: z.ZodLiteral<"user">;
385
+ content: z.ZodArray<z.ZodObject<{
386
+ type: z.ZodLiteral<"text">;
387
+ text: z.ZodString;
388
+ }, "strip", z.ZodTypeAny, {
389
+ type: "text";
390
+ text: string;
391
+ }, {
392
+ type: "text";
393
+ text: string;
394
+ }>, "many">;
395
+ }, "strip", z.ZodTypeAny, {
396
+ role: "user";
397
+ content: {
398
+ type: "text";
399
+ text: string;
400
+ }[];
401
+ }, {
402
+ role: "user";
403
+ content: {
404
+ type: "text";
405
+ text: string;
406
+ }[];
407
+ }>;
408
+ parent_tool_use_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
409
+ }, "strip", z.ZodTypeAny, {
410
+ message: {
411
+ role: "user";
412
+ content: {
413
+ type: "text";
414
+ text: string;
415
+ }[];
416
+ };
417
+ type: "user";
418
+ uuid: string;
419
+ session_id: string;
420
+ parent_tool_use_id?: string | null | undefined;
421
+ }, {
422
+ message: {
423
+ role: "user";
424
+ content: {
425
+ type: "text";
426
+ text: string;
427
+ }[];
428
+ };
429
+ type: "user";
430
+ uuid: string;
431
+ session_id: string;
432
+ parent_tool_use_id?: string | null | undefined;
433
+ }>, z.ZodObject<{
434
+ type: z.ZodLiteral<"result">;
435
+ subtype: z.ZodString;
436
+ is_error: z.ZodBoolean;
437
+ duration_ms: z.ZodNumber;
438
+ duration_api_ms: z.ZodNumber;
439
+ num_turns: z.ZodNumber;
440
+ total_cost_usd: z.ZodOptional<z.ZodNumber>;
441
+ usage: z.ZodOptional<z.ZodObject<{
442
+ input_tokens: z.ZodNumber;
443
+ output_tokens: z.ZodNumber;
444
+ cache_creation_input_tokens: z.ZodOptional<z.ZodNumber>;
445
+ cache_read_input_tokens: z.ZodOptional<z.ZodNumber>;
446
+ }, "strip", z.ZodTypeAny, {
447
+ input_tokens: number;
448
+ output_tokens: number;
449
+ cache_creation_input_tokens?: number | undefined;
450
+ cache_read_input_tokens?: number | undefined;
451
+ }, {
452
+ input_tokens: number;
453
+ output_tokens: number;
454
+ cache_creation_input_tokens?: number | undefined;
455
+ cache_read_input_tokens?: number | undefined;
456
+ }>>;
457
+ result: z.ZodOptional<z.ZodString>;
458
+ errors: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
459
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
460
+ type: z.ZodLiteral<"result">;
461
+ subtype: z.ZodString;
462
+ is_error: z.ZodBoolean;
463
+ duration_ms: z.ZodNumber;
464
+ duration_api_ms: z.ZodNumber;
465
+ num_turns: z.ZodNumber;
466
+ total_cost_usd: z.ZodOptional<z.ZodNumber>;
467
+ usage: z.ZodOptional<z.ZodObject<{
468
+ input_tokens: z.ZodNumber;
469
+ output_tokens: z.ZodNumber;
470
+ cache_creation_input_tokens: z.ZodOptional<z.ZodNumber>;
471
+ cache_read_input_tokens: z.ZodOptional<z.ZodNumber>;
472
+ }, "strip", z.ZodTypeAny, {
473
+ input_tokens: number;
474
+ output_tokens: number;
475
+ cache_creation_input_tokens?: number | undefined;
476
+ cache_read_input_tokens?: number | undefined;
477
+ }, {
478
+ input_tokens: number;
479
+ output_tokens: number;
480
+ cache_creation_input_tokens?: number | undefined;
481
+ cache_read_input_tokens?: number | undefined;
482
+ }>>;
483
+ result: z.ZodOptional<z.ZodString>;
484
+ errors: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
485
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
486
+ type: z.ZodLiteral<"result">;
487
+ subtype: z.ZodString;
488
+ is_error: z.ZodBoolean;
489
+ duration_ms: z.ZodNumber;
490
+ duration_api_ms: z.ZodNumber;
491
+ num_turns: z.ZodNumber;
492
+ total_cost_usd: z.ZodOptional<z.ZodNumber>;
493
+ usage: z.ZodOptional<z.ZodObject<{
494
+ input_tokens: z.ZodNumber;
495
+ output_tokens: z.ZodNumber;
496
+ cache_creation_input_tokens: z.ZodOptional<z.ZodNumber>;
497
+ cache_read_input_tokens: z.ZodOptional<z.ZodNumber>;
498
+ }, "strip", z.ZodTypeAny, {
499
+ input_tokens: number;
500
+ output_tokens: number;
501
+ cache_creation_input_tokens?: number | undefined;
502
+ cache_read_input_tokens?: number | undefined;
503
+ }, {
504
+ input_tokens: number;
505
+ output_tokens: number;
506
+ cache_creation_input_tokens?: number | undefined;
507
+ cache_read_input_tokens?: number | undefined;
508
+ }>>;
509
+ result: z.ZodOptional<z.ZodString>;
510
+ errors: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
511
+ }, z.ZodTypeAny, "passthrough">>, z.ZodObject<{
512
+ type: z.ZodLiteral<"result">;
513
+ subtype: z.ZodString;
514
+ is_error: z.ZodBoolean;
515
+ duration_ms: z.ZodNumber;
516
+ duration_api_ms: z.ZodNumber;
517
+ num_turns: z.ZodNumber;
518
+ total_cost_usd: z.ZodOptional<z.ZodNumber>;
519
+ usage: z.ZodOptional<z.ZodObject<{
520
+ input_tokens: z.ZodNumber;
521
+ output_tokens: z.ZodNumber;
522
+ cache_creation_input_tokens: z.ZodOptional<z.ZodNumber>;
523
+ cache_read_input_tokens: z.ZodOptional<z.ZodNumber>;
524
+ }, "strip", z.ZodTypeAny, {
525
+ input_tokens: number;
526
+ output_tokens: number;
527
+ cache_creation_input_tokens?: number | undefined;
528
+ cache_read_input_tokens?: number | undefined;
529
+ }, {
530
+ input_tokens: number;
531
+ output_tokens: number;
532
+ cache_creation_input_tokens?: number | undefined;
533
+ cache_read_input_tokens?: number | undefined;
534
+ }>>;
535
+ result: z.ZodOptional<z.ZodString>;
536
+ errors: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
537
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
538
+ type: z.ZodLiteral<"result">;
539
+ subtype: z.ZodString;
540
+ is_error: z.ZodBoolean;
541
+ duration_ms: z.ZodNumber;
542
+ duration_api_ms: z.ZodNumber;
543
+ num_turns: z.ZodNumber;
544
+ total_cost_usd: z.ZodOptional<z.ZodNumber>;
545
+ usage: z.ZodOptional<z.ZodObject<{
546
+ input_tokens: z.ZodNumber;
547
+ output_tokens: z.ZodNumber;
548
+ cache_creation_input_tokens: z.ZodOptional<z.ZodNumber>;
549
+ cache_read_input_tokens: z.ZodOptional<z.ZodNumber>;
550
+ }, "strip", z.ZodTypeAny, {
551
+ input_tokens: number;
552
+ output_tokens: number;
553
+ cache_creation_input_tokens?: number | undefined;
554
+ cache_read_input_tokens?: number | undefined;
555
+ }, {
556
+ input_tokens: number;
557
+ output_tokens: number;
558
+ cache_creation_input_tokens?: number | undefined;
559
+ cache_read_input_tokens?: number | undefined;
560
+ }>>;
561
+ result: z.ZodOptional<z.ZodString>;
562
+ errors: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
563
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
564
+ type: z.ZodLiteral<"result">;
565
+ subtype: z.ZodString;
566
+ is_error: z.ZodBoolean;
567
+ duration_ms: z.ZodNumber;
568
+ duration_api_ms: z.ZodNumber;
569
+ num_turns: z.ZodNumber;
570
+ total_cost_usd: z.ZodOptional<z.ZodNumber>;
571
+ usage: z.ZodOptional<z.ZodObject<{
572
+ input_tokens: z.ZodNumber;
573
+ output_tokens: z.ZodNumber;
574
+ cache_creation_input_tokens: z.ZodOptional<z.ZodNumber>;
575
+ cache_read_input_tokens: z.ZodOptional<z.ZodNumber>;
576
+ }, "strip", z.ZodTypeAny, {
577
+ input_tokens: number;
578
+ output_tokens: number;
579
+ cache_creation_input_tokens?: number | undefined;
580
+ cache_read_input_tokens?: number | undefined;
581
+ }, {
582
+ input_tokens: number;
583
+ output_tokens: number;
584
+ cache_creation_input_tokens?: number | undefined;
585
+ cache_read_input_tokens?: number | undefined;
586
+ }>>;
587
+ result: z.ZodOptional<z.ZodString>;
588
+ errors: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
589
+ }, z.ZodTypeAny, "passthrough">>, z.ZodObject<{
590
+ type: z.ZodLiteral<"rate_limit_event">;
591
+ rate_limit_info: z.ZodObject<{
592
+ status: z.ZodString;
593
+ resetsAt: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber]>>;
594
+ rateLimitType: z.ZodOptional<z.ZodString>;
595
+ overageStatus: z.ZodOptional<z.ZodString>;
596
+ overageDisabledReason: z.ZodOptional<z.ZodNullable<z.ZodString>>;
597
+ isUsingOverage: z.ZodOptional<z.ZodBoolean>;
598
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
599
+ status: z.ZodString;
600
+ resetsAt: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber]>>;
601
+ rateLimitType: z.ZodOptional<z.ZodString>;
602
+ overageStatus: z.ZodOptional<z.ZodString>;
603
+ overageDisabledReason: z.ZodOptional<z.ZodNullable<z.ZodString>>;
604
+ isUsingOverage: z.ZodOptional<z.ZodBoolean>;
605
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
606
+ status: z.ZodString;
607
+ resetsAt: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber]>>;
608
+ rateLimitType: z.ZodOptional<z.ZodString>;
609
+ overageStatus: z.ZodOptional<z.ZodString>;
610
+ overageDisabledReason: z.ZodOptional<z.ZodNullable<z.ZodString>>;
611
+ isUsingOverage: z.ZodOptional<z.ZodBoolean>;
612
+ }, z.ZodTypeAny, "passthrough">>;
613
+ uuid: z.ZodString;
614
+ session_id: z.ZodString;
615
+ }, "strip", z.ZodTypeAny, {
616
+ type: "rate_limit_event";
617
+ uuid: string;
618
+ session_id: string;
619
+ rate_limit_info: {
620
+ status: string;
621
+ resetsAt?: string | number | undefined;
622
+ rateLimitType?: string | undefined;
623
+ overageStatus?: string | undefined;
624
+ overageDisabledReason?: string | null | undefined;
625
+ isUsingOverage?: boolean | undefined;
626
+ } & {
627
+ [k: string]: unknown;
628
+ };
629
+ }, {
630
+ type: "rate_limit_event";
631
+ uuid: string;
632
+ session_id: string;
633
+ rate_limit_info: {
634
+ status: string;
635
+ resetsAt?: string | number | undefined;
636
+ rateLimitType?: string | undefined;
637
+ overageStatus?: string | undefined;
638
+ overageDisabledReason?: string | null | undefined;
639
+ isUsingOverage?: boolean | undefined;
640
+ } & {
641
+ [k: string]: unknown;
642
+ };
643
+ }>]>;
644
+ export { OutputEventSchema };
645
+ /** System init event emitted at session start. */
646
+ export interface SystemInitEvent {
647
+ type: 'system';
648
+ subtype: 'init';
649
+ uuid: string;
650
+ session_id: string;
651
+ cwd: string;
652
+ model: string;
653
+ tools: string[];
654
+ mcp_servers: Array<{
655
+ name: string;
656
+ status: string;
657
+ }>;
658
+ permissionMode: string;
659
+ }
660
+ /** System event for teammate lifecycle (Agent Teams). */
661
+ export interface TeammateEvent {
662
+ type: 'system';
663
+ subtype: 'teammate_spawned' | 'teammate_idle' | 'teammate_completed';
664
+ uuid: string;
665
+ session_id: string;
666
+ agent_id: string;
667
+ agent_name: string;
668
+ team_id: string;
669
+ agent_type?: string;
670
+ result?: string;
671
+ is_error?: boolean;
672
+ }
673
+ /** Generic system event for subtypes beyond init and teammate lifecycle. */
674
+ export interface GenericSystemEvent {
675
+ type: 'system';
676
+ subtype: string;
677
+ uuid: string;
678
+ session_id: string;
679
+ [key: string]: unknown;
680
+ }
681
+ /** User text message -- emitted during compaction and other system-generated user messages. */
682
+ export interface UserTextMessageEvent {
683
+ type: 'user';
684
+ uuid: string;
685
+ session_id: string;
686
+ message: {
687
+ role: 'user';
688
+ content: Array<{
689
+ type: 'text';
690
+ text: string;
691
+ }>;
692
+ };
693
+ parent_tool_use_id?: string | null;
694
+ }
695
+ /** Raw streaming event wrapper -- contains Claude API streaming events. */
696
+ export interface StreamEvent {
697
+ type: 'stream_event';
698
+ event: RawStreamEvent;
699
+ parent_tool_use_id: string | null;
700
+ uuid: string;
701
+ session_id: string;
702
+ }
703
+ /** Raw Claude API stream event types. */
704
+ export type RawStreamEvent = {
705
+ type: 'message_start';
706
+ message: {
707
+ id: string;
708
+ role: string;
709
+ model: string;
710
+ usage: TokenUsage;
711
+ };
712
+ } | {
713
+ type: 'content_block_start';
714
+ index: number;
715
+ content_block: TextBlock | ToolUseBlock | ThinkingBlock;
716
+ } | {
717
+ type: 'content_block_delta';
718
+ index: number;
719
+ delta: TextDelta | InputJsonDelta;
720
+ } | {
721
+ type: 'content_block_stop';
722
+ index: number;
723
+ } | {
724
+ type: 'message_delta';
725
+ delta: {
726
+ stop_reason: string | null;
727
+ stop_sequence: string | null;
728
+ };
729
+ usage: {
730
+ output_tokens: number;
731
+ };
732
+ } | {
733
+ type: 'message_stop';
734
+ } | {
735
+ type: 'ping';
736
+ };
737
+ export interface TextBlock {
738
+ type: 'text';
739
+ text: string;
740
+ }
741
+ export interface ToolUseBlock {
742
+ type: 'tool_use';
743
+ id: string;
744
+ name: string;
745
+ input: Record<string, unknown>;
746
+ }
747
+ export interface ThinkingBlock {
748
+ type: 'thinking';
749
+ thinking: string;
750
+ signature: string;
751
+ }
752
+ export interface TextDelta {
753
+ type: 'text_delta';
754
+ text: string;
755
+ }
756
+ export interface InputJsonDelta {
757
+ type: 'input_json_delta';
758
+ partial_json: string;
759
+ }
760
+ export interface TokenUsage {
761
+ input_tokens: number;
762
+ output_tokens: number;
763
+ cache_creation_input_tokens?: number;
764
+ cache_read_input_tokens?: number;
765
+ }
766
+ /** Complete assistant message (emitted after all stream events for a turn). */
767
+ export interface AssistantMessage {
768
+ type: 'assistant';
769
+ uuid: string;
770
+ session_id: string;
771
+ message: {
772
+ id: string;
773
+ type: 'message';
774
+ role: 'assistant';
775
+ content: Array<TextBlock | ToolUseBlock | ThinkingBlock>;
776
+ model: string;
777
+ stop_reason: string | null;
778
+ usage: TokenUsage;
779
+ };
780
+ parent_tool_use_id: string | null;
781
+ }
782
+ /** Successful result -- signals turn completion. */
783
+ export interface ResultSuccess {
784
+ type: 'result';
785
+ subtype: string;
786
+ is_error: false;
787
+ duration_ms: number;
788
+ duration_api_ms: number;
789
+ num_turns: number;
790
+ result?: string;
791
+ total_cost_usd?: number;
792
+ usage?: TokenUsage;
793
+ [key: string]: unknown;
794
+ }
795
+ /** Error result -- signals turn completion with error. */
796
+ export interface ResultError {
797
+ type: 'result';
798
+ subtype: string;
799
+ is_error: true;
800
+ duration_ms: number;
801
+ duration_api_ms: number;
802
+ num_turns: number;
803
+ total_cost_usd?: number;
804
+ usage?: TokenUsage;
805
+ errors?: string[];
806
+ result?: string;
807
+ [key: string]: unknown;
808
+ }
809
+ /** User tool_result message -- emitted when Claude Code sends tool results back. */
810
+ export interface UserToolResultEvent {
811
+ type: 'user';
812
+ uuid: string;
813
+ session_id: string;
814
+ message: {
815
+ role: 'user';
816
+ content: Array<{
817
+ type: 'tool_result';
818
+ tool_use_id: string;
819
+ content: string | Array<Record<string, unknown>>;
820
+ }>;
821
+ };
822
+ parent_tool_use_id?: string | null;
823
+ }
824
+ /** Rate limit event -- emitted when Claude Code encounters API rate limits. */
825
+ export interface RateLimitEvent {
826
+ type: 'rate_limit_event';
827
+ rate_limit_info: {
828
+ status: string;
829
+ resetsAt?: string | number;
830
+ rateLimitType?: string;
831
+ overageStatus?: string;
832
+ overageDisabledReason?: string | null;
833
+ isUsingOverage?: boolean;
834
+ [key: string]: unknown;
835
+ };
836
+ uuid: string;
837
+ session_id: string;
838
+ }
839
+ /** Union of all possible output events. */
840
+ export type OutputEvent = SystemInitEvent | TeammateEvent | GenericSystemEvent | StreamEvent | AssistantMessage | UserToolResultEvent | UserTextMessageEvent | ResultSuccess | ResultError | RateLimitEvent;
841
+ /** User message sent to Claude Code via stdin. */
842
+ export interface UserMessage {
843
+ type: 'user';
844
+ message: {
845
+ role: 'user';
846
+ content: string;
847
+ };
848
+ }
849
+ export interface StreamJsonParserEvents {
850
+ event: (event: OutputEvent) => void;
851
+ result: (result: ResultSuccess | ResultError) => void;
852
+ init: (event: SystemInitEvent) => void;
853
+ teammate: (event: TeammateEvent) => void;
854
+ assistant: (message: AssistantMessage) => void;
855
+ error: (err: Error, line: string) => void;
856
+ }
857
+ /**
858
+ * Line-buffered NDJSON parser for Claude Code stream-json output.
859
+ *
860
+ * Reads from a Readable stream, validates each line against Zod schemas,
861
+ * and emits typed events. Malformed events are logged, counted, and skipped.
862
+ */
863
+ export declare class StreamJsonParser extends EventEmitter {
864
+ private buffer;
865
+ private _sessionId;
866
+ private _lastEventTime;
867
+ private _unparsedEventCount;
868
+ get sessionId(): string | null;
869
+ get lastEventTime(): Date;
870
+ /** Number of events that failed Zod validation and were skipped. */
871
+ get unparsedEventCount(): number;
872
+ /**
873
+ * Attach the parser to a readable stream (typically process.stdout).
874
+ */
875
+ attach(stream: Readable): void;
876
+ private processBuffer;
877
+ private routeEvent;
878
+ }
879
+ /**
880
+ * Send a user message to Claude Code via stdin (stream-json format).
881
+ *
882
+ * Each message is serialized as a single JSON line followed by a newline.
883
+ */
884
+ export declare function sendMessage(stdin: Writable, content: string): boolean;
885
+ //# sourceMappingURL=stream-json.d.ts.map