@knightcodeai/cli-linux-arm64 0.9.1 → 0.9.3

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 (45) hide show
  1. package/bin/CHANGELOG.md +60 -0
  2. package/bin/README.md +52 -19
  3. package/bin/docs/cli-integration.md +106 -0
  4. package/bin/docs/cli.md +270 -0
  5. package/bin/docs/compaction.md +56 -37
  6. package/bin/docs/configuration.md +46 -0
  7. package/bin/docs/containerization.md +86 -54
  8. package/bin/docs/custom-provider.md +132 -785
  9. package/bin/docs/docs.json +143 -103
  10. package/bin/docs/environment-variables.md +5 -4
  11. package/bin/docs/extensions.md +134 -2956
  12. package/bin/docs/how-knightcode-works.md +49 -0
  13. package/bin/docs/index.md +24 -69
  14. package/bin/docs/json.md +193 -65
  15. package/bin/docs/keybindings.md +56 -101
  16. package/bin/docs/llama-cpp.md +3 -3
  17. package/bin/docs/message-types.md +261 -0
  18. package/bin/docs/models.md +64 -547
  19. package/bin/docs/packages.md +66 -167
  20. package/bin/docs/prompt-templates.md +31 -68
  21. package/bin/docs/providers.md +103 -241
  22. package/bin/docs/quickstart.md +61 -106
  23. package/bin/docs/rpc-commands.md +854 -0
  24. package/bin/docs/rpc-extension-ui.md +200 -0
  25. package/bin/docs/rpc.md +129 -1556
  26. package/bin/docs/sdk.md +76 -1160
  27. package/bin/docs/security.md +70 -32
  28. package/bin/docs/session-format.md +25 -216
  29. package/bin/docs/sessions.md +38 -143
  30. package/bin/docs/settings.md +111 -389
  31. package/bin/docs/shell-aliases.md +85 -5
  32. package/bin/docs/skills.md +51 -189
  33. package/bin/docs/slash-commands.md +63 -0
  34. package/bin/docs/terminal-setup.md +107 -79
  35. package/bin/docs/termux.md +74 -83
  36. package/bin/docs/themes.md +68 -280
  37. package/bin/docs/tmux.md +31 -39
  38. package/bin/docs/tui.md +69 -923
  39. package/bin/docs/usage.md +79 -286
  40. package/bin/docs/windows.md +43 -17
  41. package/bin/export-html/template.js +6 -1
  42. package/bin/knightcode +2 -2
  43. package/bin/package.json +6 -6
  44. package/package.json +1 -1
  45. package/bin/docs/development.md +0 -71
@@ -0,0 +1,854 @@
1
+ # RPC Commands
2
+
3
+ This reference lists commands accepted on stdin in [RPC mode](rpc.md). Each command and response is one JSON object. Shared message values use the [message types](message-types.md).
4
+
5
+ ## Prompting
6
+
7
+ ### prompt
8
+
9
+ Send a user prompt to the agent. The command response is emitted after the prompt is accepted, queued, or handled. Events continue streaming asynchronously after acceptance.
10
+
11
+ ```json
12
+ {"id": "req-1", "type": "prompt", "message": "Hello, world!"}
13
+ ```
14
+
15
+ With images:
16
+ ```json
17
+ {"type": "prompt", "message": "What's in this image?", "images": [{"type": "image", "data": "base64-encoded-data", "mimeType": "image/png"}]}
18
+ ```
19
+
20
+ **During streaming**: If the agent is already streaming, you must specify `streamingBehavior` to queue the message:
21
+
22
+ ```json
23
+ {"type": "prompt", "message": "New instruction", "streamingBehavior": "steer"}
24
+ ```
25
+
26
+ - `"steer"`: Queue the message while the agent is running. It is delivered after the current assistant turn finishes executing its tool calls, before the next LLM call.
27
+ - `"followUp"`: Wait until the agent finishes. Message is delivered only when agent stops.
28
+
29
+ If the agent is streaming and no `streamingBehavior` is specified, the command returns an error.
30
+
31
+ **Extension commands**: If the message is an extension command (e.g., `/mycommand`), it executes immediately even during streaming. Extension commands manage their own LLM interaction via `knightcode.sendMessage()`.
32
+
33
+ **Input expansion**: Skill commands (`/skill:name`) and prompt templates (`/template`) are expanded before sending/queueing.
34
+
35
+ Response:
36
+ ```json
37
+ {"id": "req-1", "type": "response", "command": "prompt", "success": true}
38
+ ```
39
+
40
+ `success: true` means the prompt was accepted, queued, or handled immediately. `success: false` means the prompt was rejected before acceptance. Failures after acceptance are reported through the normal event and message stream, not as a second `response` for the same request id.
41
+
42
+ The `images` field is optional. Each image uses `ImageContent` format: `{"type": "image", "data": "base64-encoded-data", "mimeType": "image/png"}`.
43
+
44
+ ### steer
45
+
46
+ Queue a steering message while the agent is running. It is delivered after the current assistant turn finishes executing its tool calls, before the next LLM call. Skill commands and prompt templates are expanded. Extension commands are not allowed (use `prompt` instead).
47
+
48
+ ```json
49
+ {"type": "steer", "message": "Stop and do this instead"}
50
+ ```
51
+
52
+ With images:
53
+ ```json
54
+ {"type": "steer", "message": "Look at this instead", "images": [{"type": "image", "data": "base64-encoded-data", "mimeType": "image/png"}]}
55
+ ```
56
+
57
+ The `images` field is optional. Each image uses `ImageContent` format (same as `prompt`).
58
+
59
+ Response:
60
+ ```json
61
+ {"type": "response", "command": "steer", "success": true}
62
+ ```
63
+
64
+ See [set_steering_mode](#set_steering_mode) for controlling how steering messages are processed.
65
+
66
+ ### follow_up
67
+
68
+ Queue a follow-up message to be processed after the agent finishes. Delivered only when agent has no more tool calls or steering messages. Skill commands and prompt templates are expanded. Extension commands are not allowed (use `prompt` instead).
69
+
70
+ ```json
71
+ {"type": "follow_up", "message": "After you're done, also do this"}
72
+ ```
73
+
74
+ With images:
75
+ ```json
76
+ {"type": "follow_up", "message": "Also check this image", "images": [{"type": "image", "data": "base64-encoded-data", "mimeType": "image/png"}]}
77
+ ```
78
+
79
+ The `images` field is optional. Each image uses `ImageContent` format (same as `prompt`).
80
+
81
+ Response:
82
+ ```json
83
+ {"type": "response", "command": "follow_up", "success": true}
84
+ ```
85
+
86
+ See [set_follow_up_mode](#set_follow_up_mode) for controlling how follow-up messages are processed.
87
+
88
+ ### abort
89
+
90
+ Abort the current operation and wait for the session to become idle before responding.
91
+
92
+ ```json
93
+ {"type": "abort"}
94
+ ```
95
+
96
+ Response:
97
+ ```json
98
+ {"type": "response", "command": "abort", "success": true}
99
+ ```
100
+
101
+ ### clear_queue
102
+
103
+ Remove queued steering and follow-up messages and return their text.
104
+
105
+ ```json
106
+ {"type": "clear_queue"}
107
+ ```
108
+
109
+ Response:
110
+ ```json
111
+ {
112
+ "type": "response",
113
+ "command": "clear_queue",
114
+ "success": true,
115
+ "data": {
116
+ "steering": ["Change direction"],
117
+ "followUp": ["Summarize when finished"]
118
+ }
119
+ }
120
+ ```
121
+
122
+ To implement interactive Esc behavior, send `clear_queue` before `abort`, then restore the returned text in the client editor. `abort` continues queued messages when they remain in the session.
123
+
124
+ ### new_session
125
+
126
+ Start a fresh session. Can be canceled by a `session_before_switch` extension event handler.
127
+
128
+ ```json
129
+ {"type": "new_session"}
130
+ ```
131
+
132
+ With optional parent session tracking:
133
+ ```json
134
+ {"type": "new_session", "parentSession": "/path/to/parent-session.jsonl"}
135
+ ```
136
+
137
+ Response:
138
+ ```json
139
+ {"type": "response", "command": "new_session", "success": true, "data": {"cancelled": false}}
140
+ ```
141
+
142
+ If an extension canceled:
143
+ ```json
144
+ {"type": "response", "command": "new_session", "success": true, "data": {"cancelled": true}}
145
+ ```
146
+
147
+ ## State
148
+
149
+ ### get_state
150
+
151
+ Get current session state.
152
+
153
+ ```json
154
+ {"type": "get_state"}
155
+ ```
156
+
157
+ Response:
158
+ ```json
159
+ {
160
+ "type": "response",
161
+ "command": "get_state",
162
+ "success": true,
163
+ "data": {
164
+ "model": {...},
165
+ "thinkingLevel": "medium",
166
+ "isStreaming": false,
167
+ "isCompacting": false,
168
+ "steeringMode": "all",
169
+ "followUpMode": "one-at-a-time",
170
+ "sessionFile": "/path/to/session.jsonl",
171
+ "sessionId": "abc123",
172
+ "sessionName": "my-feature-work",
173
+ "autoCompactionEnabled": true,
174
+ "messageCount": 5,
175
+ "pendingMessageCount": 0
176
+ }
177
+ }
178
+ ```
179
+
180
+ The `model` field is a full [Model](#model-object) object, or omitted when no model is selected. The `sessionName` field is the display name set via `set_session_name`, or omitted if not set.
181
+
182
+ ### get_messages
183
+
184
+ Get all messages in the conversation.
185
+
186
+ ```json
187
+ {"type": "get_messages"}
188
+ ```
189
+
190
+ Response:
191
+ ```json
192
+ {
193
+ "type": "response",
194
+ "command": "get_messages",
195
+ "success": true,
196
+ "data": {"messages": [...]}
197
+ }
198
+ ```
199
+
200
+ Messages are `AgentMessage` objects (see [Message Types](message-types.md)).
201
+
202
+ ## Model
203
+
204
+ ### set_model
205
+
206
+ Switch to a specific model.
207
+
208
+ ```json
209
+ {"type": "set_model", "provider": "anthropic", "modelId": "claude-sonnet-4-20250514"}
210
+ ```
211
+
212
+ Response contains the full [Model](#model-object) object:
213
+ ```json
214
+ {
215
+ "type": "response",
216
+ "command": "set_model",
217
+ "success": true,
218
+ "data": {...}
219
+ }
220
+ ```
221
+
222
+ ### cycle_model
223
+
224
+ Cycle to the next available model. Returns `null` data if only one model available.
225
+
226
+ ```json
227
+ {"type": "cycle_model"}
228
+ ```
229
+
230
+ Response:
231
+ ```json
232
+ {
233
+ "type": "response",
234
+ "command": "cycle_model",
235
+ "success": true,
236
+ "data": {
237
+ "model": {...},
238
+ "thinkingLevel": "medium",
239
+ "isScoped": false
240
+ }
241
+ }
242
+ ```
243
+
244
+ The `model` field is a full [Model](#model-object) object.
245
+
246
+ ### get_available_models
247
+
248
+ List all configured models.
249
+
250
+ ```json
251
+ {"type": "get_available_models"}
252
+ ```
253
+
254
+ Response contains an array of full [Model](#model-object) objects:
255
+ ```json
256
+ {
257
+ "type": "response",
258
+ "command": "get_available_models",
259
+ "success": true,
260
+ "data": {
261
+ "models": [...]
262
+ }
263
+ }
264
+ ```
265
+
266
+ ## Thinking
267
+
268
+ ### set_thinking_level
269
+
270
+ Set the reasoning/thinking level for models that support it.
271
+
272
+ ```json
273
+ {"type": "set_thinking_level", "level": "high"}
274
+ ```
275
+
276
+ Levels: `"off"`, `"minimal"`, `"low"`, `"medium"`, `"high"`, `"xhigh"`, `"max"`
277
+
278
+ `"xhigh"` and `"max"` are exposed only when supported by the selected model. Some models, including GPT-5.6, expose both.
279
+
280
+ Response:
281
+ ```json
282
+ {"type": "response", "command": "set_thinking_level", "success": true}
283
+ ```
284
+
285
+ ### cycle_thinking_level
286
+
287
+ Cycle through available thinking levels. Returns `null` data if model doesn't support thinking.
288
+
289
+ ```json
290
+ {"type": "cycle_thinking_level"}
291
+ ```
292
+
293
+ Response:
294
+ ```json
295
+ {
296
+ "type": "response",
297
+ "command": "cycle_thinking_level",
298
+ "success": true,
299
+ "data": {"level": "high"}
300
+ }
301
+ ```
302
+
303
+ ### get_available_thinking_levels
304
+
305
+ List the thinking levels supported by the current model. Returns `["off"]` for a model without reasoning support.
306
+
307
+ ```json
308
+ {"type": "get_available_thinking_levels"}
309
+ ```
310
+
311
+ Response:
312
+ ```json
313
+ {
314
+ "type": "response",
315
+ "command": "get_available_thinking_levels",
316
+ "success": true,
317
+ "data": {
318
+ "levels": ["off", "minimal", "low", "medium", "high"]
319
+ }
320
+ }
321
+ ```
322
+
323
+ ## Queue modes
324
+
325
+ ### set_steering_mode
326
+
327
+ Control how steering messages (from `steer`) are delivered.
328
+
329
+ ```json
330
+ {"type": "set_steering_mode", "mode": "one-at-a-time"}
331
+ ```
332
+
333
+ Modes:
334
+ - `"all"`: Deliver all steering messages after the current assistant turn finishes executing its tool calls
335
+ - `"one-at-a-time"`: Deliver one steering message per completed assistant turn (default)
336
+
337
+ Response:
338
+ ```json
339
+ {"type": "response", "command": "set_steering_mode", "success": true}
340
+ ```
341
+
342
+ ### set_follow_up_mode
343
+
344
+ Control how follow-up messages (from `follow_up`) are delivered.
345
+
346
+ ```json
347
+ {"type": "set_follow_up_mode", "mode": "one-at-a-time"}
348
+ ```
349
+
350
+ Modes:
351
+ - `"all"`: Deliver all follow-up messages when agent finishes
352
+ - `"one-at-a-time"`: Deliver one follow-up message per agent completion (default)
353
+
354
+ Response:
355
+ ```json
356
+ {"type": "response", "command": "set_follow_up_mode", "success": true}
357
+ ```
358
+
359
+ ## Compaction
360
+
361
+ ### compact
362
+
363
+ Manually compact conversation context to reduce token usage.
364
+
365
+ ```json
366
+ {"type": "compact"}
367
+ ```
368
+
369
+ With custom instructions:
370
+ ```json
371
+ {"type": "compact", "customInstructions": "Focus on code changes"}
372
+ ```
373
+
374
+ Response:
375
+ ```json
376
+ {
377
+ "type": "response",
378
+ "command": "compact",
379
+ "success": true,
380
+ "data": {
381
+ "summary": "Summary of conversation...",
382
+ "firstKeptEntryId": "abc123",
383
+ "tokensBefore": 150000,
384
+ "estimatedTokensAfter": 32000,
385
+ "usage": {
386
+ "input": 32000,
387
+ "output": 1200,
388
+ "cacheRead": 0,
389
+ "cacheWrite": 0,
390
+ "totalTokens": 33200,
391
+ "cost": {"input": 0.01, "output": 0.02, "cacheRead": 0, "cacheWrite": 0, "total": 0.03}
392
+ },
393
+ "details": {}
394
+ }
395
+ }
396
+ ```
397
+
398
+ `estimatedTokensAfter` is a heuristic estimate over the rebuilt message context immediately after compaction, not a provider-exact token count. `usage` reports the LLM call or calls that generated the summary and may be omitted by custom compaction handlers.
399
+
400
+ ### set_auto_compaction
401
+
402
+ Enable or disable automatic compaction when context is nearly full.
403
+
404
+ ```json
405
+ {"type": "set_auto_compaction", "enabled": true}
406
+ ```
407
+
408
+ Response:
409
+ ```json
410
+ {"type": "response", "command": "set_auto_compaction", "success": true}
411
+ ```
412
+
413
+ ## Retry
414
+
415
+ ### set_auto_retry
416
+
417
+ Enable or disable automatic retry on transient errors (overloaded, rate limit, 5xx).
418
+
419
+ ```json
420
+ {"type": "set_auto_retry", "enabled": true}
421
+ ```
422
+
423
+ Response:
424
+ ```json
425
+ {"type": "response", "command": "set_auto_retry", "success": true}
426
+ ```
427
+
428
+ ### abort_retry
429
+
430
+ Abort an in-progress retry (cancel the delay and stop retrying).
431
+
432
+ ```json
433
+ {"type": "abort_retry"}
434
+ ```
435
+
436
+ Response:
437
+ ```json
438
+ {"type": "response", "command": "abort_retry", "success": true}
439
+ ```
440
+
441
+ ## Bash
442
+
443
+ ### bash
444
+
445
+ Execute a shell command and add output to conversation context. Output streams as `bash_execution_update` events while the command runs; the response contains the final result.
446
+
447
+ ```json
448
+ {"id": "req-1", "type": "bash", "command": "ls -la"}
449
+ ```
450
+
451
+ Set `excludeFromContext` to `true` when the command output should be stored in the session but omitted from the model context on the next prompt.
452
+
453
+ Include an `id` to associate streamed `bash_execution_update` events with this command.
454
+
455
+ Response:
456
+ ```json
457
+ {
458
+ "id": "req-1",
459
+ "type": "response",
460
+ "command": "bash",
461
+ "success": true,
462
+ "data": {
463
+ "output": "total 48\ndrwxr-xr-x ...",
464
+ "exitCode": 0,
465
+ "cancelled": false,
466
+ "truncated": false
467
+ }
468
+ }
469
+ ```
470
+
471
+ If output was truncated, includes `fullOutputPath`:
472
+ ```json
473
+ {
474
+ "type": "response",
475
+ "command": "bash",
476
+ "success": true,
477
+ "data": {
478
+ "output": "truncated output...",
479
+ "exitCode": 0,
480
+ "cancelled": false,
481
+ "truncated": true,
482
+ "fullOutputPath": "/tmp/knightcode-bash-abc123.log"
483
+ }
484
+ }
485
+ ```
486
+
487
+ **How bash results reach the LLM:**
488
+
489
+ The `bash` command executes immediately and returns a `BashResult`. Internally, a `BashExecutionMessage` is created and stored in the agent's message state.
490
+
491
+ When the next `prompt` command is sent, KnightCode transforms context messages before sending them to the model. Unless `excludeFromContext` is true, the `BashExecutionMessage` becomes a `UserMessage` with this format:
492
+
493
+ ````
494
+ Ran `ls -la`
495
+ ```
496
+ total 48
497
+ drwxr-xr-x ...
498
+ ```
499
+ ````
500
+
501
+ This means:
502
+ 1. Included bash output reaches the model on the **next prompt**, not immediately.
503
+ 2. Multiple bash commands can run before a prompt; KnightCode includes each output that does not set `excludeFromContext`.
504
+
505
+ ### abort_bash
506
+
507
+ Abort a running bash command.
508
+
509
+ ```json
510
+ {"type": "abort_bash"}
511
+ ```
512
+
513
+ Response:
514
+ ```json
515
+ {"type": "response", "command": "abort_bash", "success": true}
516
+ ```
517
+
518
+ ## Session
519
+
520
+ ### get_session_stats
521
+
522
+ Get token usage, cost statistics, and current context window usage.
523
+
524
+ ```json
525
+ {"type": "get_session_stats"}
526
+ ```
527
+
528
+ Response:
529
+ ```json
530
+ {
531
+ "type": "response",
532
+ "command": "get_session_stats",
533
+ "success": true,
534
+ "data": {
535
+ "sessionFile": "/path/to/session.jsonl",
536
+ "sessionId": "abc123",
537
+ "userMessages": 5,
538
+ "assistantMessages": 5,
539
+ "toolCalls": 12,
540
+ "toolResults": 12,
541
+ "totalMessages": 22,
542
+ "tokens": {
543
+ "input": 50000,
544
+ "output": 10000,
545
+ "cacheRead": 40000,
546
+ "cacheWrite": 5000,
547
+ "total": 105000
548
+ },
549
+ "cost": 0.45,
550
+ "contextUsage": {
551
+ "tokens": 60000,
552
+ "contextWindow": 200000,
553
+ "percent": 30
554
+ }
555
+ }
556
+ }
557
+ ```
558
+
559
+ `tokens` and `cost` include assistant messages, usage reported by tools, and compaction/branch-summary generation across the full session. `contextUsage` contains the actual current context-window estimate used for compaction and footer display.
560
+
561
+ `contextUsage` is omitted when no model or context window is available. `contextUsage.tokens` and `contextUsage.percent` are `null` immediately after compaction until a fresh post-compaction assistant response provides valid usage data.
562
+
563
+ ### export_html
564
+
565
+ Export session to an HTML file.
566
+
567
+ ```json
568
+ {"type": "export_html"}
569
+ ```
570
+
571
+ With custom path:
572
+ ```json
573
+ {"type": "export_html", "outputPath": "/tmp/session.html"}
574
+ ```
575
+
576
+ Response:
577
+ ```json
578
+ {
579
+ "type": "response",
580
+ "command": "export_html",
581
+ "success": true,
582
+ "data": {"path": "/tmp/session.html"}
583
+ }
584
+ ```
585
+
586
+ ### switch_session
587
+
588
+ Load a different session file. Can be canceled by a `session_before_switch` extension event handler.
589
+
590
+ ```json
591
+ {"type": "switch_session", "sessionPath": "/path/to/session.jsonl"}
592
+ ```
593
+
594
+ Response:
595
+ ```json
596
+ {"type": "response", "command": "switch_session", "success": true, "data": {"cancelled": false}}
597
+ ```
598
+
599
+ If an extension canceled the switch:
600
+ ```json
601
+ {"type": "response", "command": "switch_session", "success": true, "data": {"cancelled": true}}
602
+ ```
603
+
604
+ ### fork
605
+
606
+ Create a new fork from a previous user message on the active branch. Can be canceled by a `session_before_fork` extension event handler. Returns the text of the message being forked from.
607
+
608
+ ```json
609
+ {"type": "fork", "entryId": "abc123"}
610
+ ```
611
+
612
+ Response:
613
+ ```json
614
+ {
615
+ "type": "response",
616
+ "command": "fork",
617
+ "success": true,
618
+ "data": {"text": "The original prompt text...", "cancelled": false}
619
+ }
620
+ ```
621
+
622
+ If an extension canceled the fork:
623
+ ```json
624
+ {
625
+ "type": "response",
626
+ "command": "fork",
627
+ "success": true,
628
+ "data": {"cancelled": true}
629
+ }
630
+ ```
631
+
632
+ ### clone
633
+
634
+ Duplicate the current active branch into a new session at the current position. Can be canceled by a `session_before_fork` extension event handler.
635
+
636
+ ```json
637
+ {"type": "clone"}
638
+ ```
639
+
640
+ Response:
641
+ ```json
642
+ {
643
+ "type": "response",
644
+ "command": "clone",
645
+ "success": true,
646
+ "data": {"cancelled": false}
647
+ }
648
+ ```
649
+
650
+ If an extension canceled the clone:
651
+ ```json
652
+ {
653
+ "type": "response",
654
+ "command": "clone",
655
+ "success": true,
656
+ "data": {"cancelled": true}
657
+ }
658
+ ```
659
+
660
+ ### get_fork_messages
661
+
662
+ Get user messages available for forking.
663
+
664
+ ```json
665
+ {"type": "get_fork_messages"}
666
+ ```
667
+
668
+ Response:
669
+ ```json
670
+ {
671
+ "type": "response",
672
+ "command": "get_fork_messages",
673
+ "success": true,
674
+ "data": {
675
+ "messages": [
676
+ {"entryId": "abc123", "text": "First prompt..."},
677
+ {"entryId": "def456", "text": "Second prompt..."}
678
+ ]
679
+ }
680
+ }
681
+ ```
682
+
683
+ ### get_entries
684
+
685
+ Get all session entries in append order (excluding the session header). The session is an append-only tree of entries with stable ids, so an entry id works as a durable cursor: pass the last entry id you have seen as `since` to get only entries strictly after it, even across client restarts. Unlike `get_messages`, this includes pre-compaction history and abandoned branches.
686
+
687
+ ```json
688
+ {"type": "get_entries"}
689
+ ```
690
+
691
+ With a cursor:
692
+ ```json
693
+ {"type": "get_entries", "since": "abc123"}
694
+ ```
695
+
696
+ Response:
697
+ ```json
698
+ {
699
+ "type": "response",
700
+ "command": "get_entries",
701
+ "success": true,
702
+ "data": {
703
+ "entries": [
704
+ {"type": "message", "id": "def456", "parentId": "abc123", "timestamp": "...", "message": {"role": "user", "...": "..."}}
705
+ ],
706
+ "leafId": "def456"
707
+ }
708
+ }
709
+ ```
710
+
711
+ `leafId` is the id of the current leaf entry (`null` for an empty session), so a client can tell in one round trip whether the active branch moved. If `since` does not match any entry id, the response is `success: false`.
712
+
713
+ ### get_tree
714
+
715
+ Get the session as a tree of entries. Each node is `{entry, children, label?, labelTimestamp?}`. The result is an array because navigation APIs can create multiple roots; orphaned entries with broken parent chains also appear as roots.
716
+
717
+ ```json
718
+ {"type": "get_tree"}
719
+ ```
720
+
721
+ Response:
722
+ ```json
723
+ {
724
+ "type": "response",
725
+ "command": "get_tree",
726
+ "success": true,
727
+ "data": {
728
+ "tree": [
729
+ {
730
+ "entry": {"type": "message", "id": "abc123", "parentId": null, "...": "..."},
731
+ "children": [
732
+ {"entry": {"type": "message", "id": "def456", "parentId": "abc123", "...": "..."}, "children": []}
733
+ ]
734
+ }
735
+ ],
736
+ "leafId": "def456"
737
+ }
738
+ }
739
+ ```
740
+
741
+ ### get_last_assistant_text
742
+
743
+ Get the text content of the last assistant message.
744
+
745
+ ```json
746
+ {"type": "get_last_assistant_text"}
747
+ ```
748
+
749
+ Response:
750
+ ```json
751
+ {
752
+ "type": "response",
753
+ "command": "get_last_assistant_text",
754
+ "success": true,
755
+ "data": {"text": "The assistant's response..."}
756
+ }
757
+ ```
758
+
759
+ The `text` value is `null` if no assistant text exists.
760
+
761
+ ### set_session_name
762
+
763
+ Set a display name for the current session. The name appears in session listings and helps identify sessions.
764
+
765
+ ```json
766
+ {"type": "set_session_name", "name": "my-feature-work"}
767
+ ```
768
+
769
+ Response:
770
+ ```json
771
+ {
772
+ "type": "response",
773
+ "command": "set_session_name",
774
+ "success": true
775
+ }
776
+ ```
777
+
778
+ The current session name is available via `get_state` in the `sessionName` field. To set the initial name when starting RPC mode, pass `--name <name>` or `-n <name>` to the `knightcode --mode rpc` process.
779
+
780
+ ## Discoverable commands
781
+
782
+ ### get_commands
783
+
784
+ Get available commands (extension commands, prompt templates, and skills). Run one through the `prompt` command by prefixing its name with `/`.
785
+
786
+ ```json
787
+ {"type": "get_commands"}
788
+ ```
789
+
790
+ Response:
791
+ ```json
792
+ {
793
+ "type": "response",
794
+ "command": "get_commands",
795
+ "success": true,
796
+ "data": {
797
+ "commands": [
798
+ {
799
+ "name": "fix-tests",
800
+ "description": "Fix failing tests",
801
+ "source": "prompt",
802
+ "sourceInfo": {
803
+ "path": "/home/user/myproject/.knightcode/agent/prompts/fix-tests.md",
804
+ "source": "local",
805
+ "scope": "project",
806
+ "origin": "top-level"
807
+ }
808
+ }
809
+ ]
810
+ }
811
+ }
812
+ ```
813
+
814
+ Each command has:
815
+ - `name`: Command name (use `/name`)
816
+ - `description`: Human-readable description (optional for extension commands)
817
+ - `source`: What kind of command:
818
+ - `"extension"`: Registered via `knightcode.registerCommand()` in an extension
819
+ - `"prompt"`: Loaded from a prompt template `.md` file
820
+ - `"skill"`: Loaded from a skill directory (name is prefixed with `skill:`)
821
+ - `sourceInfo`: Metadata for the resource that registered the command:
822
+ - `path`: Absolute path to the resource
823
+ - `source`: How KnightCode discovered it, such as `"local"`, `"auto"`, or `"cli"`
824
+ - `scope`: `"user"`, `"project"`, or `"temporary"`
825
+ - `origin`: `"top-level"` for a directly loaded resource or `"package"` for a package resource
826
+ - `baseDir`: Package base directory, when applicable
827
+
828
+ **Note**: Built-in TUI commands (`/settings`, `/hotkeys`, etc.) are not included. They are handled only in interactive mode and would not execute if sent via `prompt`.
829
+
830
+ ## Model object
831
+
832
+ Model commands return the complete configured model definition. Costs are in US dollars per million tokens.
833
+
834
+ ```json
835
+ {
836
+ "id": "claude-sonnet-4-20250514",
837
+ "name": "Claude Sonnet 4",
838
+ "api": "anthropic-messages",
839
+ "provider": "anthropic",
840
+ "baseUrl": "https://api.anthropic.com",
841
+ "reasoning": true,
842
+ "input": ["text", "image"],
843
+ "contextWindow": 200000,
844
+ "maxTokens": 16384,
845
+ "cost": {
846
+ "input": 3.0,
847
+ "output": 15.0,
848
+ "cacheRead": 0.3,
849
+ "cacheWrite": 3.75
850
+ }
851
+ }
852
+ ```
853
+
854
+ For model configuration, see [Configure a compatible endpoint](models.md#configure-a-compatible-endpoint). For TypeScript, use the exported `Model` type from `@knightcode/ai`.