@swifty.js/larky 0.0.1-alpha

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.
@@ -0,0 +1,1487 @@
1
+ # Wire Protocol
2
+
3
+ > Generated by `scripts/gen-protocol-doc.ts`. **Do not edit manually.**
4
+
5
+ ## Transport
6
+
7
+ - TCP loopback `127.0.0.1:5520` (override via `LARKY_HOST` / `LARKY_PORT`)
8
+ - Each message is one `\n`-terminated JSON line (NDJSON)
9
+ - Commands use JSON-RPC 2.0 (client → server); Events use `kind=event` envelope (server → client)
10
+
11
+ ## Commands
12
+
13
+ All commands are sent as JSON-RPC 2.0 requests. The `type` field inside `params` is used for routing.
14
+
15
+ ### PingCommand
16
+
17
+ | Field | Type | Required |
18
+ | -------- | -------- | -------- |
19
+ | `type` | `string` | yes |
20
+ | `client` | `string` | yes |
21
+
22
+ ```json
23
+ {
24
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
25
+ "type": "object",
26
+ "properties": {
27
+ "type": {
28
+ "default": "core.ping",
29
+ "type": "string",
30
+ "const": "core.ping"
31
+ },
32
+ "client": {
33
+ "type": "string"
34
+ }
35
+ },
36
+ "required": ["type", "client"],
37
+ "additionalProperties": false
38
+ }
39
+ ```
40
+
41
+ **Example:**
42
+
43
+ ```json
44
+ {
45
+ "jsonrpc": "2.0",
46
+ "id": "example-1",
47
+ "method": "core.ping",
48
+ "params": {
49
+ "client": "cli/0.0.1"
50
+ }
51
+ }
52
+ ```
53
+
54
+ ### PongResult
55
+
56
+ | Field | Type | Required |
57
+ | ---------------- | --------- | -------- |
58
+ | `server_version` | `string` | yes |
59
+ | `uptime_ms` | `integer` | yes |
60
+ | `received_at` | `string` | yes |
61
+
62
+ ```json
63
+ {
64
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
65
+ "type": "object",
66
+ "properties": {
67
+ "server_version": {
68
+ "type": "string"
69
+ },
70
+ "uptime_ms": {
71
+ "type": "integer",
72
+ "minimum": -9007199254740991,
73
+ "maximum": 9007199254740991
74
+ },
75
+ "received_at": {
76
+ "type": "string"
77
+ }
78
+ },
79
+ "required": ["server_version", "uptime_ms", "received_at"],
80
+ "additionalProperties": false
81
+ }
82
+ ```
83
+
84
+ **Example:**
85
+
86
+ ```json
87
+ {
88
+ "jsonrpc": "2.0",
89
+ "id": "example-1",
90
+ "result": {
91
+ "server_version": "0.2.0",
92
+ "uptime_ms": 12,
93
+ "received_at": "2026-05-16T10:00:00.001Z"
94
+ }
95
+ }
96
+ ```
97
+
98
+ ### AgentRunCommand
99
+
100
+ | Field | Type | Required |
101
+ | ------ | -------- | -------- |
102
+ | `type` | `string` | yes |
103
+ | `goal` | `string` | yes |
104
+
105
+ ```json
106
+ {
107
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
108
+ "type": "object",
109
+ "properties": {
110
+ "type": {
111
+ "default": "agent.run",
112
+ "type": "string",
113
+ "const": "agent.run"
114
+ },
115
+ "goal": {
116
+ "type": "string"
117
+ }
118
+ },
119
+ "required": ["type", "goal"],
120
+ "additionalProperties": false
121
+ }
122
+ ```
123
+
124
+ **Example:**
125
+
126
+ ```json
127
+ {
128
+ "jsonrpc": "2.0",
129
+ "id": "example-2",
130
+ "method": "agent.run",
131
+ "params": {
132
+ "goal": "Summarize the main sections of README.md"
133
+ }
134
+ }
135
+ ```
136
+
137
+ ### AgentRunResult
138
+
139
+ | Field | Type | Required |
140
+ | -------- | -------- | -------- |
141
+ | `run_id` | `string` | yes |
142
+
143
+ ```json
144
+ {
145
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
146
+ "type": "object",
147
+ "properties": {
148
+ "run_id": {
149
+ "type": "string"
150
+ }
151
+ },
152
+ "required": ["run_id"],
153
+ "additionalProperties": false
154
+ }
155
+ ```
156
+
157
+ **Example:**
158
+
159
+ ```json
160
+ {
161
+ "jsonrpc": "2.0",
162
+ "id": "example-2",
163
+ "result": {
164
+ "run_id": "20260516-100000-abc123"
165
+ }
166
+ }
167
+ ```
168
+
169
+ ### EventSubscribeCommand
170
+
171
+ | Field | Type | Required |
172
+ | ----------------- | -------- | -------- | --- |
173
+ | `type` | `string` | yes |
174
+ | `topics` | `array` | yes |
175
+ | `scope` | `string` | yes |
176
+ | `replay_from_run` | `string | null` | yes |
177
+
178
+ ```json
179
+ {
180
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
181
+ "type": "object",
182
+ "properties": {
183
+ "type": {
184
+ "default": "event.subscribe",
185
+ "type": "string",
186
+ "const": "event.subscribe"
187
+ },
188
+ "topics": {
189
+ "type": "array",
190
+ "items": {
191
+ "type": "string"
192
+ }
193
+ },
194
+ "scope": {
195
+ "default": "global",
196
+ "type": "string"
197
+ },
198
+ "replay_from_run": {
199
+ "default": null,
200
+ "anyOf": [
201
+ {
202
+ "type": "string"
203
+ },
204
+ {
205
+ "type": "null"
206
+ }
207
+ ]
208
+ }
209
+ },
210
+ "required": ["type", "topics", "scope", "replay_from_run"],
211
+ "additionalProperties": false
212
+ }
213
+ ```
214
+
215
+ **Example:**
216
+
217
+ ```json
218
+ {
219
+ "jsonrpc": "2.0",
220
+ "id": "example-3",
221
+ "method": "event.subscribe",
222
+ "params": {
223
+ "topics": ["run.*", "step.*", "tool.*", "llm.token"],
224
+ "scope": "global",
225
+ "replay_from_run": null
226
+ }
227
+ }
228
+ ```
229
+
230
+ ### EventSubscribeResult
231
+
232
+ | Field | Type | Required |
233
+ | ----------------- | --------- | -------- |
234
+ | `subscription_id` | `string` | yes |
235
+ | `replayed_count` | `integer` | yes |
236
+
237
+ ```json
238
+ {
239
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
240
+ "type": "object",
241
+ "properties": {
242
+ "subscription_id": {
243
+ "type": "string"
244
+ },
245
+ "replayed_count": {
246
+ "default": 0,
247
+ "type": "integer",
248
+ "minimum": -9007199254740991,
249
+ "maximum": 9007199254740991
250
+ }
251
+ },
252
+ "required": ["subscription_id", "replayed_count"],
253
+ "additionalProperties": false
254
+ }
255
+ ```
256
+
257
+ **Example:**
258
+
259
+ ```json
260
+ {
261
+ "jsonrpc": "2.0",
262
+ "id": "example-3",
263
+ "result": {
264
+ "subscription_id": "sub-abc123",
265
+ "replayed_count": 0
266
+ }
267
+ }
268
+ ```
269
+
270
+ ### SessionCreateCommand
271
+
272
+ | Field | Type | Required |
273
+ | ------- | -------- | -------- |
274
+ | `type` | `string` | yes |
275
+ | `mode` | `string` | yes |
276
+ | `title` | `string` | yes |
277
+
278
+ ```json
279
+ {
280
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
281
+ "type": "object",
282
+ "properties": {
283
+ "type": {
284
+ "default": "session.create",
285
+ "type": "string",
286
+ "const": "session.create"
287
+ },
288
+ "mode": {
289
+ "default": "chat",
290
+ "type": "string",
291
+ "enum": ["one_shot", "chat"]
292
+ },
293
+ "title": {
294
+ "default": "",
295
+ "type": "string"
296
+ }
297
+ },
298
+ "required": ["type", "mode", "title"],
299
+ "additionalProperties": false
300
+ }
301
+ ```
302
+
303
+ **Example:**
304
+
305
+ ```json
306
+ {
307
+ "jsonrpc": "2.0",
308
+ "id": "example-4",
309
+ "method": "session.create",
310
+ "params": {
311
+ "mode": "chat",
312
+ "title": ""
313
+ }
314
+ }
315
+ ```
316
+
317
+ ### SessionCreateResult
318
+
319
+ | Field | Type | Required |
320
+ | ------------ | -------- | -------- |
321
+ | `session_id` | `string` | yes |
322
+ | `status` | `string` | yes |
323
+
324
+ ```json
325
+ {
326
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
327
+ "type": "object",
328
+ "properties": {
329
+ "session_id": {
330
+ "type": "string"
331
+ },
332
+ "status": {
333
+ "type": "string",
334
+ "enum": ["active", "waiting_for_input", "closed"]
335
+ }
336
+ },
337
+ "required": ["session_id", "status"],
338
+ "additionalProperties": false
339
+ }
340
+ ```
341
+
342
+ **Example:**
343
+
344
+ ```json
345
+ {
346
+ "jsonrpc": "2.0",
347
+ "id": "example-4",
348
+ "result": {
349
+ "session_id": "session-abc123def456",
350
+ "status": "active"
351
+ }
352
+ }
353
+ ```
354
+
355
+ ### SessionSendMessageCommand
356
+
357
+ | Field | Type | Required |
358
+ | ------------ | -------- | -------- |
359
+ | `type` | `string` | yes |
360
+ | `session_id` | `string` | yes |
361
+ | `content` | `string` | yes |
362
+
363
+ ```json
364
+ {
365
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
366
+ "type": "object",
367
+ "properties": {
368
+ "type": {
369
+ "default": "session.send_message",
370
+ "type": "string",
371
+ "const": "session.send_message"
372
+ },
373
+ "session_id": {
374
+ "type": "string"
375
+ },
376
+ "content": {
377
+ "type": "string"
378
+ }
379
+ },
380
+ "required": ["type", "session_id", "content"],
381
+ "additionalProperties": false
382
+ }
383
+ ```
384
+
385
+ **Example:**
386
+
387
+ ```json
388
+ {
389
+ "jsonrpc": "2.0",
390
+ "id": "example-5",
391
+ "method": "session.sendMessage",
392
+ "params": {
393
+ "session_id": "session-abc123def456",
394
+ "content": "Summarize README.md"
395
+ }
396
+ }
397
+ ```
398
+
399
+ ### SessionSendMessageResult
400
+
401
+ | Field | Type | Required |
402
+ | -------- | -------- | -------- |
403
+ | `run_id` | `string` | yes |
404
+
405
+ ```json
406
+ {
407
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
408
+ "type": "object",
409
+ "properties": {
410
+ "run_id": {
411
+ "type": "string"
412
+ }
413
+ },
414
+ "required": ["run_id"],
415
+ "additionalProperties": false
416
+ }
417
+ ```
418
+
419
+ **Example:**
420
+
421
+ ```json
422
+ {
423
+ "jsonrpc": "2.0",
424
+ "id": "example-5",
425
+ "result": {
426
+ "run_id": "20260516-100000-abc123"
427
+ }
428
+ }
429
+ ```
430
+
431
+ ### SessionGetHistoryCommand
432
+
433
+ | Field | Type | Required |
434
+ | ------------ | -------- | -------- |
435
+ | `type` | `string` | yes |
436
+ | `session_id` | `string` | yes |
437
+
438
+ ```json
439
+ {
440
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
441
+ "type": "object",
442
+ "properties": {
443
+ "type": {
444
+ "default": "session.get_history",
445
+ "type": "string",
446
+ "const": "session.get_history"
447
+ },
448
+ "session_id": {
449
+ "type": "string"
450
+ }
451
+ },
452
+ "required": ["type", "session_id"],
453
+ "additionalProperties": false
454
+ }
455
+ ```
456
+
457
+ ### SessionGetHistoryResult
458
+
459
+ | Field | Type | Required |
460
+ | ---------- | ------- | -------- |
461
+ | `messages` | `array` | yes |
462
+
463
+ ```json
464
+ {
465
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
466
+ "type": "object",
467
+ "properties": {
468
+ "messages": {
469
+ "type": "array",
470
+ "items": {
471
+ "type": "object",
472
+ "propertyNames": {
473
+ "type": "string"
474
+ },
475
+ "additionalProperties": {}
476
+ }
477
+ }
478
+ },
479
+ "required": ["messages"],
480
+ "additionalProperties": false
481
+ }
482
+ ```
483
+
484
+ ### SessionCloseCommand
485
+
486
+ | Field | Type | Required |
487
+ | ------------ | -------- | -------- |
488
+ | `type` | `string` | yes |
489
+ | `session_id` | `string` | yes |
490
+
491
+ ```json
492
+ {
493
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
494
+ "type": "object",
495
+ "properties": {
496
+ "type": {
497
+ "default": "session.close",
498
+ "type": "string",
499
+ "const": "session.close"
500
+ },
501
+ "session_id": {
502
+ "type": "string"
503
+ }
504
+ },
505
+ "required": ["type", "session_id"],
506
+ "additionalProperties": false
507
+ }
508
+ ```
509
+
510
+ ### SessionCloseResult
511
+
512
+ | Field | Type | Required |
513
+ | -------- | -------- | -------- |
514
+ | `status` | `string` | yes |
515
+
516
+ ```json
517
+ {
518
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
519
+ "type": "object",
520
+ "properties": {
521
+ "status": {
522
+ "type": "string",
523
+ "enum": ["active", "waiting_for_input", "closed"]
524
+ }
525
+ },
526
+ "required": ["status"],
527
+ "additionalProperties": false
528
+ }
529
+ ```
530
+
531
+ ## Server Push
532
+
533
+ Events pushed from daemon to subscribed clients over the same TCP connection.
534
+
535
+ ### EventPushEnvelope
536
+
537
+ | Field | Type | Required |
538
+ | ------- | -------- | -------- |
539
+ | `kind` | `string` | yes |
540
+ | `event` | `object` | yes |
541
+
542
+ ```json
543
+ {
544
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
545
+ "type": "object",
546
+ "properties": {
547
+ "kind": {
548
+ "default": "event",
549
+ "type": "string",
550
+ "const": "event"
551
+ },
552
+ "event": {
553
+ "type": "object",
554
+ "propertyNames": {
555
+ "type": "string"
556
+ },
557
+ "additionalProperties": {}
558
+ }
559
+ },
560
+ "required": ["kind", "event"],
561
+ "additionalProperties": false
562
+ }
563
+ ```
564
+
565
+ **Example:**
566
+
567
+ ```json
568
+ {
569
+ "kind": "event",
570
+ "event": {
571
+ "type": "step.started",
572
+ "run_id": "20260516-100000-abc123",
573
+ "step": 1,
574
+ "timestamp": "2026-05-16T10:00:00.001Z"
575
+ }
576
+ }
577
+ ```
578
+
579
+ ## IPC Events
580
+
581
+ Events sent over the IPC socket (daemon → client).
582
+
583
+ ### CoreStartedEvent
584
+
585
+ | Field | Type | Required |
586
+ | ------------- | -------- | -------- |
587
+ | `type` | `string` | yes |
588
+ | `listen_addr` | `string` | yes |
589
+ | `version` | `string` | yes |
590
+
591
+ ```json
592
+ {
593
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
594
+ "type": "object",
595
+ "properties": {
596
+ "type": {
597
+ "default": "core.started",
598
+ "type": "string",
599
+ "const": "core.started"
600
+ },
601
+ "listen_addr": {
602
+ "type": "string"
603
+ },
604
+ "version": {
605
+ "type": "string"
606
+ }
607
+ },
608
+ "required": ["type", "listen_addr", "version"],
609
+ "additionalProperties": false
610
+ }
611
+ ```
612
+
613
+ ## Run Events
614
+
615
+ Events written to `runs/<run_id>/events.jsonl` and forwarded over IPC to subscribed clients.
616
+
617
+ ### RunStartedEvent
618
+
619
+ | Field | Type | Required |
620
+ | ----------- | -------- | -------- |
621
+ | `type` | `string` | yes |
622
+ | `run_id` | `string` | yes |
623
+ | `goal` | `string` | yes |
624
+ | `timestamp` | `string` | yes |
625
+
626
+ ```json
627
+ {
628
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
629
+ "type": "object",
630
+ "properties": {
631
+ "type": {
632
+ "default": "run.started",
633
+ "type": "string",
634
+ "const": "run.started"
635
+ },
636
+ "run_id": {
637
+ "type": "string"
638
+ },
639
+ "goal": {
640
+ "type": "string"
641
+ },
642
+ "timestamp": {
643
+ "type": "string"
644
+ }
645
+ },
646
+ "required": ["type", "run_id", "goal", "timestamp"],
647
+ "additionalProperties": false
648
+ }
649
+ ```
650
+
651
+ **Example:**
652
+
653
+ ```json
654
+ {
655
+ "type": "run.started",
656
+ "run_id": "20260516-100000-abc123",
657
+ "goal": "Summarize README.md",
658
+ "timestamp": "2026-05-16T10:00:00.001Z"
659
+ }
660
+ ```
661
+
662
+ ### RunFinishedEvent
663
+
664
+ | Field | Type | Required |
665
+ | ----------- | --------- | -------- | --- |
666
+ | `type` | `string` | yes |
667
+ | `run_id` | `string` | yes |
668
+ | `status` | `string` | yes |
669
+ | `reason` | `string | null` | yes |
670
+ | `steps` | `integer` | yes |
671
+ | `timestamp` | `string` | yes |
672
+
673
+ ```json
674
+ {
675
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
676
+ "type": "object",
677
+ "properties": {
678
+ "type": {
679
+ "default": "run.finished",
680
+ "type": "string",
681
+ "const": "run.finished"
682
+ },
683
+ "run_id": {
684
+ "type": "string"
685
+ },
686
+ "status": {
687
+ "type": "string"
688
+ },
689
+ "reason": {
690
+ "default": null,
691
+ "anyOf": [
692
+ {
693
+ "type": "string"
694
+ },
695
+ {
696
+ "type": "null"
697
+ }
698
+ ]
699
+ },
700
+ "steps": {
701
+ "type": "integer",
702
+ "minimum": -9007199254740991,
703
+ "maximum": 9007199254740991
704
+ },
705
+ "timestamp": {
706
+ "type": "string"
707
+ }
708
+ },
709
+ "required": ["type", "run_id", "status", "reason", "steps", "timestamp"],
710
+ "additionalProperties": false
711
+ }
712
+ ```
713
+
714
+ **Example:**
715
+
716
+ ```json
717
+ {
718
+ "type": "run.finished",
719
+ "run_id": "20260516-100000-abc123",
720
+ "status": "success",
721
+ "reason": null,
722
+ "steps": 2,
723
+ "timestamp": "2026-05-16T10:00:00.001Z"
724
+ }
725
+ ```
726
+
727
+ ### StepStartedEvent
728
+
729
+ | Field | Type | Required |
730
+ | ----------- | --------- | -------- |
731
+ | `type` | `string` | yes |
732
+ | `run_id` | `string` | yes |
733
+ | `step` | `integer` | yes |
734
+ | `timestamp` | `string` | yes |
735
+
736
+ ```json
737
+ {
738
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
739
+ "type": "object",
740
+ "properties": {
741
+ "type": {
742
+ "default": "step.started",
743
+ "type": "string",
744
+ "const": "step.started"
745
+ },
746
+ "run_id": {
747
+ "type": "string"
748
+ },
749
+ "step": {
750
+ "type": "integer",
751
+ "minimum": -9007199254740991,
752
+ "maximum": 9007199254740991
753
+ },
754
+ "timestamp": {
755
+ "type": "string"
756
+ }
757
+ },
758
+ "required": ["type", "run_id", "step", "timestamp"],
759
+ "additionalProperties": false
760
+ }
761
+ ```
762
+
763
+ **Example:**
764
+
765
+ ```json
766
+ {
767
+ "type": "step.started",
768
+ "run_id": "20260516-100000-abc123",
769
+ "step": 1,
770
+ "timestamp": "2026-05-16T10:00:00.001Z"
771
+ }
772
+ ```
773
+
774
+ ### StepFinishedEvent
775
+
776
+ | Field | Type | Required |
777
+ | ----------- | --------- | -------- |
778
+ | `type` | `string` | yes |
779
+ | `run_id` | `string` | yes |
780
+ | `step` | `integer` | yes |
781
+ | `timestamp` | `string` | yes |
782
+
783
+ ```json
784
+ {
785
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
786
+ "type": "object",
787
+ "properties": {
788
+ "type": {
789
+ "default": "step.finished",
790
+ "type": "string",
791
+ "const": "step.finished"
792
+ },
793
+ "run_id": {
794
+ "type": "string"
795
+ },
796
+ "step": {
797
+ "type": "integer",
798
+ "minimum": -9007199254740991,
799
+ "maximum": 9007199254740991
800
+ },
801
+ "timestamp": {
802
+ "type": "string"
803
+ }
804
+ },
805
+ "required": ["type", "run_id", "step", "timestamp"],
806
+ "additionalProperties": false
807
+ }
808
+ ```
809
+
810
+ **Example:**
811
+
812
+ ```json
813
+ {
814
+ "type": "step.finished",
815
+ "run_id": "20260516-100000-abc123",
816
+ "step": 1,
817
+ "timestamp": "2026-05-16T10:00:00.001Z"
818
+ }
819
+ ```
820
+
821
+ ### ToolUseStartedEvent
822
+
823
+ | Field | Type | Required |
824
+ | ------------- | -------- | -------- |
825
+ | `type` | `string` | yes |
826
+ | `run_id` | `string` | yes |
827
+ | `tool_use_id` | `string` | yes |
828
+ | `tool_name` | `string` | yes |
829
+ | `params` | `object` | yes |
830
+ | `timestamp` | `string` | yes |
831
+
832
+ ```json
833
+ {
834
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
835
+ "type": "object",
836
+ "properties": {
837
+ "type": {
838
+ "default": "tool.call_started",
839
+ "type": "string",
840
+ "const": "tool.call_started"
841
+ },
842
+ "run_id": {
843
+ "type": "string"
844
+ },
845
+ "tool_use_id": {
846
+ "type": "string"
847
+ },
848
+ "tool_name": {
849
+ "type": "string"
850
+ },
851
+ "params": {
852
+ "type": "object",
853
+ "propertyNames": {
854
+ "type": "string"
855
+ },
856
+ "additionalProperties": {}
857
+ },
858
+ "timestamp": {
859
+ "type": "string"
860
+ }
861
+ },
862
+ "required": ["type", "run_id", "tool_use_id", "tool_name", "params", "timestamp"],
863
+ "additionalProperties": false
864
+ }
865
+ ```
866
+
867
+ **Example:**
868
+
869
+ ```json
870
+ {
871
+ "type": "tool.call_started",
872
+ "run_id": "20260516-100000-abc123",
873
+ "tool_use_id": "tool_use_01",
874
+ "tool_name": "read_file",
875
+ "params": {
876
+ "path": "README.md"
877
+ },
878
+ "timestamp": "2026-05-16T10:00:00.001Z"
879
+ }
880
+ ```
881
+
882
+ ### ToolUseFinishedEvent
883
+
884
+ | Field | Type | Required |
885
+ | ------------- | --------- | -------- |
886
+ | `type` | `string` | yes |
887
+ | `run_id` | `string` | yes |
888
+ | `tool_use_id` | `string` | yes |
889
+ | `tool_name` | `string` | yes |
890
+ | `elapsed_ms` | `integer` | yes |
891
+ | `output` | `string` | yes |
892
+ | `timestamp` | `string` | yes |
893
+
894
+ ```json
895
+ {
896
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
897
+ "type": "object",
898
+ "properties": {
899
+ "type": {
900
+ "default": "tool.call_finished",
901
+ "type": "string",
902
+ "const": "tool.call_finished"
903
+ },
904
+ "run_id": {
905
+ "type": "string"
906
+ },
907
+ "tool_use_id": {
908
+ "type": "string"
909
+ },
910
+ "tool_name": {
911
+ "type": "string"
912
+ },
913
+ "elapsed_ms": {
914
+ "type": "integer",
915
+ "minimum": -9007199254740991,
916
+ "maximum": 9007199254740991
917
+ },
918
+ "output": {
919
+ "default": "",
920
+ "type": "string"
921
+ },
922
+ "timestamp": {
923
+ "type": "string"
924
+ }
925
+ },
926
+ "required": ["type", "run_id", "tool_use_id", "tool_name", "elapsed_ms", "output", "timestamp"],
927
+ "additionalProperties": false
928
+ }
929
+ ```
930
+
931
+ **Example:**
932
+
933
+ ```json
934
+ {
935
+ "type": "tool.call_finished",
936
+ "run_id": "20260516-100000-abc123",
937
+ "tool_use_id": "tool_use_01",
938
+ "tool_name": "read_file",
939
+ "elapsed_ms": 3,
940
+ "timestamp": "2026-05-16T10:00:00.001Z"
941
+ }
942
+ ```
943
+
944
+ ### ToolUseFailedEvent
945
+
946
+ | Field | Type | Required |
947
+ | --------------- | --------- | -------- |
948
+ | `type` | `string` | yes |
949
+ | `run_id` | `string` | yes |
950
+ | `tool_use_id` | `string` | yes |
951
+ | `tool_name` | `string` | yes |
952
+ | `error_class` | `string` | yes |
953
+ | `error_message` | `string` | yes |
954
+ | `elapsed_ms` | `integer` | yes |
955
+ | `attempt` | `integer` | yes |
956
+ | `timestamp` | `string` | yes |
957
+
958
+ ```json
959
+ {
960
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
961
+ "type": "object",
962
+ "properties": {
963
+ "type": {
964
+ "default": "tool.call_failed",
965
+ "type": "string",
966
+ "const": "tool.call_failed"
967
+ },
968
+ "run_id": {
969
+ "type": "string"
970
+ },
971
+ "tool_use_id": {
972
+ "type": "string"
973
+ },
974
+ "tool_name": {
975
+ "type": "string"
976
+ },
977
+ "error_class": {
978
+ "type": "string"
979
+ },
980
+ "error_message": {
981
+ "type": "string"
982
+ },
983
+ "elapsed_ms": {
984
+ "type": "integer",
985
+ "minimum": -9007199254740991,
986
+ "maximum": 9007199254740991
987
+ },
988
+ "attempt": {
989
+ "default": 1,
990
+ "type": "integer",
991
+ "minimum": -9007199254740991,
992
+ "maximum": 9007199254740991
993
+ },
994
+ "timestamp": {
995
+ "type": "string"
996
+ }
997
+ },
998
+ "required": [
999
+ "type",
1000
+ "run_id",
1001
+ "tool_use_id",
1002
+ "tool_name",
1003
+ "error_class",
1004
+ "error_message",
1005
+ "elapsed_ms",
1006
+ "attempt",
1007
+ "timestamp"
1008
+ ],
1009
+ "additionalProperties": false
1010
+ }
1011
+ ```
1012
+
1013
+ **Example:**
1014
+
1015
+ ```json
1016
+ {
1017
+ "type": "tool.call_failed",
1018
+ "run_id": "20260516-100000-abc123",
1019
+ "tool_use_id": "tool_use_02",
1020
+ "tool_name": "read_file",
1021
+ "error_class": "runtime_error",
1022
+ "error_message": "file not found",
1023
+ "elapsed_ms": 1,
1024
+ "attempt": 1,
1025
+ "timestamp": "2026-05-16T10:00:00.001Z"
1026
+ }
1027
+ ```
1028
+
1029
+ ### LlmModelSelectedEvent
1030
+
1031
+ | Field | Type | Required |
1032
+ | ----------- | -------- | -------- |
1033
+ | `type` | `string` | yes |
1034
+ | `run_id` | `string` | yes |
1035
+ | `model` | `string` | yes |
1036
+ | `strategy` | `string` | yes |
1037
+ | `timestamp` | `string` | yes |
1038
+
1039
+ ```json
1040
+ {
1041
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
1042
+ "type": "object",
1043
+ "properties": {
1044
+ "type": {
1045
+ "default": "llm.model_selected",
1046
+ "type": "string",
1047
+ "const": "llm.model_selected"
1048
+ },
1049
+ "run_id": {
1050
+ "type": "string"
1051
+ },
1052
+ "model": {
1053
+ "type": "string"
1054
+ },
1055
+ "strategy": {
1056
+ "type": "string"
1057
+ },
1058
+ "timestamp": {
1059
+ "type": "string"
1060
+ }
1061
+ },
1062
+ "required": ["type", "run_id", "model", "strategy", "timestamp"],
1063
+ "additionalProperties": false
1064
+ }
1065
+ ```
1066
+
1067
+ **Example:**
1068
+
1069
+ ```json
1070
+ {
1071
+ "type": "llm.model_selected",
1072
+ "run_id": "20260516-100000-abc123",
1073
+ "model": "claude-sonnet-4-6",
1074
+ "strategy": "static",
1075
+ "timestamp": "2026-05-16T10:00:00.001Z"
1076
+ }
1077
+ ```
1078
+
1079
+ ### LlmTokenEvent
1080
+
1081
+ | Field | Type | Required |
1082
+ | ----------- | -------- | -------- |
1083
+ | `type` | `string` | yes |
1084
+ | `run_id` | `string` | yes |
1085
+ | `token` | `string` | yes |
1086
+ | `timestamp` | `string` | yes |
1087
+
1088
+ ```json
1089
+ {
1090
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
1091
+ "type": "object",
1092
+ "properties": {
1093
+ "type": {
1094
+ "default": "llm.token",
1095
+ "type": "string",
1096
+ "const": "llm.token"
1097
+ },
1098
+ "run_id": {
1099
+ "type": "string"
1100
+ },
1101
+ "token": {
1102
+ "type": "string"
1103
+ },
1104
+ "timestamp": {
1105
+ "type": "string"
1106
+ }
1107
+ },
1108
+ "required": ["type", "run_id", "token", "timestamp"],
1109
+ "additionalProperties": false
1110
+ }
1111
+ ```
1112
+
1113
+ **Example:**
1114
+
1115
+ ```json
1116
+ {
1117
+ "type": "llm.token",
1118
+ "run_id": "20260516-100000-abc123",
1119
+ "token": "The ",
1120
+ "timestamp": "2026-05-16T10:00:00.001Z"
1121
+ }
1122
+ ```
1123
+
1124
+ ### LlmUsageEvent
1125
+
1126
+ | Field | Type | Required |
1127
+ | ----------------------------- | --------- | -------- |
1128
+ | `type` | `string` | yes |
1129
+ | `run_id` | `string` | yes |
1130
+ | `input_tokens` | `integer` | yes |
1131
+ | `output_tokens` | `integer` | yes |
1132
+ | `cache_read_input_tokens` | `integer` | yes |
1133
+ | `cache_creation_input_tokens` | `integer` | yes |
1134
+ | `context_percent` | `number` | yes |
1135
+ | `timestamp` | `string` | yes |
1136
+
1137
+ ```json
1138
+ {
1139
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
1140
+ "type": "object",
1141
+ "properties": {
1142
+ "type": {
1143
+ "default": "llm.usage",
1144
+ "type": "string",
1145
+ "const": "llm.usage"
1146
+ },
1147
+ "run_id": {
1148
+ "type": "string"
1149
+ },
1150
+ "input_tokens": {
1151
+ "type": "integer",
1152
+ "minimum": -9007199254740991,
1153
+ "maximum": 9007199254740991
1154
+ },
1155
+ "output_tokens": {
1156
+ "type": "integer",
1157
+ "minimum": -9007199254740991,
1158
+ "maximum": 9007199254740991
1159
+ },
1160
+ "cache_read_input_tokens": {
1161
+ "type": "integer",
1162
+ "minimum": -9007199254740991,
1163
+ "maximum": 9007199254740991
1164
+ },
1165
+ "cache_creation_input_tokens": {
1166
+ "type": "integer",
1167
+ "minimum": -9007199254740991,
1168
+ "maximum": 9007199254740991
1169
+ },
1170
+ "context_percent": {
1171
+ "default": 0,
1172
+ "type": "number"
1173
+ },
1174
+ "timestamp": {
1175
+ "type": "string"
1176
+ }
1177
+ },
1178
+ "required": [
1179
+ "type",
1180
+ "run_id",
1181
+ "input_tokens",
1182
+ "output_tokens",
1183
+ "cache_read_input_tokens",
1184
+ "cache_creation_input_tokens",
1185
+ "context_percent",
1186
+ "timestamp"
1187
+ ],
1188
+ "additionalProperties": false
1189
+ }
1190
+ ```
1191
+
1192
+ **Example:**
1193
+
1194
+ ```json
1195
+ {
1196
+ "type": "llm.usage",
1197
+ "run_id": "20260516-100000-abc123",
1198
+ "input_tokens": 512,
1199
+ "output_tokens": 48,
1200
+ "cache_read_input_tokens": 490,
1201
+ "cache_creation_input_tokens": 0,
1202
+ "timestamp": "2026-05-16T10:00:00.001Z"
1203
+ }
1204
+ ```
1205
+
1206
+ ### LogLineEvent
1207
+
1208
+ | Field | Type | Required |
1209
+ | ----------- | -------- | -------- |
1210
+ | `type` | `string` | yes |
1211
+ | `run_id` | `string` | yes |
1212
+ | `level` | `string` | yes |
1213
+ | `source` | `string` | yes |
1214
+ | `message` | `string` | yes |
1215
+ | `timestamp` | `string` | yes |
1216
+
1217
+ ```json
1218
+ {
1219
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
1220
+ "type": "object",
1221
+ "properties": {
1222
+ "type": {
1223
+ "default": "log.line",
1224
+ "type": "string",
1225
+ "const": "log.line"
1226
+ },
1227
+ "run_id": {
1228
+ "type": "string"
1229
+ },
1230
+ "level": {
1231
+ "type": "string"
1232
+ },
1233
+ "source": {
1234
+ "type": "string"
1235
+ },
1236
+ "message": {
1237
+ "type": "string"
1238
+ },
1239
+ "timestamp": {
1240
+ "type": "string"
1241
+ }
1242
+ },
1243
+ "required": ["type", "run_id", "level", "source", "message", "timestamp"],
1244
+ "additionalProperties": false
1245
+ }
1246
+ ```
1247
+
1248
+ **Example:**
1249
+
1250
+ ```json
1251
+ {
1252
+ "type": "log.line",
1253
+ "run_id": "20260516-100000-abc123",
1254
+ "level": "INFO",
1255
+ "source": "larky.core.loop",
1256
+ "message": "step 1 started",
1257
+ "timestamp": "2026-05-16T10:00:00.001Z"
1258
+ }
1259
+ ```
1260
+
1261
+ ## Session Events
1262
+
1263
+ ### SessionCreatedEvent
1264
+
1265
+ | Field | Type | Required |
1266
+ | ------------ | -------- | -------- |
1267
+ | `type` | `string` | yes |
1268
+ | `session_id` | `string` | yes |
1269
+ | `mode` | `string` | yes |
1270
+ | `timestamp` | `string` | yes |
1271
+
1272
+ ```json
1273
+ {
1274
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
1275
+ "type": "object",
1276
+ "properties": {
1277
+ "type": {
1278
+ "default": "session.created",
1279
+ "type": "string",
1280
+ "const": "session.created"
1281
+ },
1282
+ "session_id": {
1283
+ "type": "string"
1284
+ },
1285
+ "mode": {
1286
+ "type": "string"
1287
+ },
1288
+ "timestamp": {
1289
+ "type": "string"
1290
+ }
1291
+ },
1292
+ "required": ["type", "session_id", "mode", "timestamp"],
1293
+ "additionalProperties": false
1294
+ }
1295
+ ```
1296
+
1297
+ **Example:**
1298
+
1299
+ ```json
1300
+ {
1301
+ "type": "session.created",
1302
+ "session_id": "session-abc123def456",
1303
+ "mode": "chat",
1304
+ "timestamp": "2026-05-16T10:00:00.001Z"
1305
+ }
1306
+ ```
1307
+
1308
+ ### SessionMessageReceivedEvent
1309
+
1310
+ | Field | Type | Required |
1311
+ | ------------ | -------- | -------- |
1312
+ | `type` | `string` | yes |
1313
+ | `session_id` | `string` | yes |
1314
+ | `content` | `string` | yes |
1315
+ | `timestamp` | `string` | yes |
1316
+
1317
+ ```json
1318
+ {
1319
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
1320
+ "type": "object",
1321
+ "properties": {
1322
+ "type": {
1323
+ "default": "session.message_received",
1324
+ "type": "string",
1325
+ "const": "session.message_received"
1326
+ },
1327
+ "session_id": {
1328
+ "type": "string"
1329
+ },
1330
+ "content": {
1331
+ "type": "string"
1332
+ },
1333
+ "timestamp": {
1334
+ "type": "string"
1335
+ }
1336
+ },
1337
+ "required": ["type", "session_id", "content", "timestamp"],
1338
+ "additionalProperties": false
1339
+ }
1340
+ ```
1341
+
1342
+ **Example:**
1343
+
1344
+ ```json
1345
+ {
1346
+ "type": "session.message_received",
1347
+ "session_id": "session-abc123def456",
1348
+ "content": "Summarize README.md",
1349
+ "timestamp": "2026-05-16T10:00:00.001Z"
1350
+ }
1351
+ ```
1352
+
1353
+ ### SessionWaitingForInputEvent
1354
+
1355
+ | Field | Type | Required |
1356
+ | ------------- | -------- | -------- |
1357
+ | `type` | `string` | yes |
1358
+ | `session_id` | `string` | yes |
1359
+ | `last_run_id` | `string` | yes |
1360
+ | `timestamp` | `string` | yes |
1361
+
1362
+ ```json
1363
+ {
1364
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
1365
+ "type": "object",
1366
+ "properties": {
1367
+ "type": {
1368
+ "default": "session.waiting_for_input",
1369
+ "type": "string",
1370
+ "const": "session.waiting_for_input"
1371
+ },
1372
+ "session_id": {
1373
+ "type": "string"
1374
+ },
1375
+ "last_run_id": {
1376
+ "type": "string"
1377
+ },
1378
+ "timestamp": {
1379
+ "type": "string"
1380
+ }
1381
+ },
1382
+ "required": ["type", "session_id", "last_run_id", "timestamp"],
1383
+ "additionalProperties": false
1384
+ }
1385
+ ```
1386
+
1387
+ **Example:**
1388
+
1389
+ ```json
1390
+ {
1391
+ "type": "session.waiting_for_input",
1392
+ "session_id": "session-abc123def456",
1393
+ "last_run_id": "20260516-100000-abc123",
1394
+ "timestamp": "2026-05-16T10:00:00.001Z"
1395
+ }
1396
+ ```
1397
+
1398
+ ### SessionResumedEvent
1399
+
1400
+ | Field | Type | Required |
1401
+ | ------------ | -------- | -------- |
1402
+ | `type` | `string` | yes |
1403
+ | `session_id` | `string` | yes |
1404
+ | `timestamp` | `string` | yes |
1405
+
1406
+ ```json
1407
+ {
1408
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
1409
+ "type": "object",
1410
+ "properties": {
1411
+ "type": {
1412
+ "default": "session.resumed",
1413
+ "type": "string",
1414
+ "const": "session.resumed"
1415
+ },
1416
+ "session_id": {
1417
+ "type": "string"
1418
+ },
1419
+ "timestamp": {
1420
+ "type": "string"
1421
+ }
1422
+ },
1423
+ "required": ["type", "session_id", "timestamp"],
1424
+ "additionalProperties": false
1425
+ }
1426
+ ```
1427
+
1428
+ **Example:**
1429
+
1430
+ ```json
1431
+ {
1432
+ "type": "session.resumed",
1433
+ "session_id": "session-abc123def456",
1434
+ "timestamp": "2026-05-16T10:00:00.001Z"
1435
+ }
1436
+ ```
1437
+
1438
+ ### SessionClosedEvent
1439
+
1440
+ | Field | Type | Required |
1441
+ | ------------ | -------- | -------- |
1442
+ | `type` | `string` | yes |
1443
+ | `session_id` | `string` | yes |
1444
+ | `timestamp` | `string` | yes |
1445
+
1446
+ ```json
1447
+ {
1448
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
1449
+ "type": "object",
1450
+ "properties": {
1451
+ "type": {
1452
+ "default": "session.closed",
1453
+ "type": "string",
1454
+ "const": "session.closed"
1455
+ },
1456
+ "session_id": {
1457
+ "type": "string"
1458
+ },
1459
+ "timestamp": {
1460
+ "type": "string"
1461
+ }
1462
+ },
1463
+ "required": ["type", "session_id", "timestamp"],
1464
+ "additionalProperties": false
1465
+ }
1466
+ ```
1467
+
1468
+ **Example:**
1469
+
1470
+ ```json
1471
+ {
1472
+ "type": "session.closed",
1473
+ "session_id": "session-abc123def456",
1474
+ "timestamp": "2026-05-16T10:00:00.001Z"
1475
+ }
1476
+ ```
1477
+
1478
+ ## Error Codes
1479
+
1480
+ | Code | Name | Meaning |
1481
+ | ------ | ----------------- | ------------------------------------- |
1482
+ | -32700 | Parse Error | Invalid JSON received |
1483
+ | -32600 | Invalid Request | Missing required JSON-RPC fields |
1484
+ | -32601 | Method Not Found | Unknown method |
1485
+ | -32602 | Invalid Params | Parameter validation failed |
1486
+ | -32603 | Internal Error | Handler raised an unhandled exception |
1487
+ | -32000 | Application Error | e.g. another run already in progress |