@knightcodeai/cli 0.17.4 → 0.18.1
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.
- package/CHANGELOG.md +1303 -0
- package/README.md +2 -2
- package/dist/bundle/chunks/anthropic-messages-A2IH2IY3.js +6 -0
- package/dist/bundle/chunks/anthropic.js +101 -0
- package/dist/bundle/chunks/azure-openai-responses-XZILQZOG.js +2 -0
- package/dist/bundle/chunks/bedrock-converse-stream.js +89 -0
- package/dist/bundle/chunks/chunk-253N4337.js +7 -0
- package/dist/bundle/chunks/chunk-2QIKI63P.js +108 -0
- package/dist/bundle/chunks/chunk-3LX7U45C.js +130 -0
- package/dist/bundle/chunks/chunk-4CRI7BMY.js +2 -0
- package/dist/bundle/chunks/chunk-57BPR4HF.js +2 -0
- package/dist/bundle/chunks/chunk-A5LJINMT.js +2 -0
- package/dist/bundle/chunks/chunk-AANBXVWQ.js +2 -0
- package/dist/bundle/chunks/chunk-AHB7JV5B.js +2 -0
- package/dist/bundle/chunks/chunk-B2FT7RH5.js +2 -0
- package/dist/bundle/chunks/chunk-BPNRVFVQ.js +2 -0
- package/dist/bundle/chunks/chunk-BRKUE2MD.js +2 -0
- package/dist/bundle/chunks/chunk-BXZL5C3N.js +58 -0
- package/dist/bundle/chunks/chunk-DGACKL4S.js +30 -0
- package/dist/bundle/chunks/chunk-DKOURXGU.js +2 -0
- package/dist/bundle/chunks/chunk-DVFCXHT4.js +2 -0
- package/dist/bundle/chunks/chunk-ETOMYYZC.js +2 -0
- package/dist/bundle/chunks/chunk-FA32X2UJ.js +7 -0
- package/dist/bundle/chunks/chunk-FHM6KUY3.js +44 -0
- package/dist/bundle/chunks/chunk-FO7CEQB3.js +11 -0
- package/dist/bundle/chunks/chunk-FXS5MU6B.js +2 -0
- package/dist/bundle/chunks/chunk-HHWP56PR.js +2 -0
- package/dist/bundle/chunks/chunk-HSL72VZI.js +2 -0
- package/dist/bundle/chunks/chunk-HUQB436V.js +2 -0
- package/dist/bundle/chunks/chunk-HWXGL4YB.js +2 -0
- package/dist/bundle/chunks/chunk-KQKUEQJA.js +6 -0
- package/dist/bundle/chunks/chunk-LROWZ6UF.js +1333 -0
- package/dist/bundle/chunks/chunk-MOALMQWH.js +9 -0
- package/dist/bundle/chunks/chunk-MXIWLMNT.js +8 -0
- package/dist/bundle/chunks/chunk-N6VDWLND.js +2 -0
- package/dist/bundle/chunks/chunk-NCIBB66G.js +2 -0
- package/dist/bundle/chunks/chunk-NDQ5OW6U.js +2 -0
- package/dist/bundle/chunks/chunk-O6JSP6YG.js +6 -0
- package/dist/bundle/chunks/chunk-OFST7FDG.js +2 -0
- package/dist/bundle/chunks/chunk-SPAUY3RD.js +12 -0
- package/dist/bundle/chunks/chunk-UZWP3NHW.js +2 -0
- package/dist/bundle/chunks/chunk-V5ANFNKF.js +11 -0
- package/dist/bundle/chunks/chunk-VJJ6J35N.js +20 -0
- package/dist/bundle/chunks/chunk-ZW7FVRHT.js +31 -0
- package/dist/bundle/chunks/cli-DFJTSQI6.js +51 -0
- package/dist/bundle/chunks/cloudflare-workers-ai-system-one-6E2UM7IG.js +2 -0
- package/dist/bundle/chunks/codemode-worker.js +478 -0
- package/dist/bundle/chunks/dist-DKI7Q6GY.js +13 -0
- package/dist/bundle/chunks/easter-egg-3d-7O2AHLAQ.js +2 -0
- package/dist/bundle/chunks/execute-4CLOTQIS.js +499 -0
- package/dist/bundle/chunks/github-copilot.js +2 -0
- package/dist/bundle/chunks/google-generative-ai-CSWR3ORZ.js +2 -0
- package/dist/bundle/chunks/google-vertex-QIDRFOFB.js +2 -0
- package/dist/bundle/chunks/image-resize-worker.js +2 -0
- package/dist/bundle/chunks/jiti-loader-BXVX3Y2R.js +21 -0
- package/dist/bundle/chunks/jiti-static-loader-NNBCFAO5.js +2 -0
- package/dist/bundle/chunks/kimi-coding.js +2 -0
- package/dist/bundle/chunks/knightcode-messages-3GNOTMSI.js +8 -0
- package/dist/bundle/chunks/lib-IHWMWJDR.js +9 -0
- package/dist/bundle/chunks/llama-cpp-classify-HRPRKOZA.js +22 -0
- package/dist/bundle/chunks/meta.js +2 -0
- package/dist/bundle/chunks/mistral-conversations-46TK5OBA.js +5 -0
- package/dist/bundle/chunks/multipart-parser-VTTMF2EO.js +3 -0
- package/dist/bundle/chunks/node-7S3GFMOZ.js +16 -0
- package/dist/bundle/chunks/node-MAEICQNS.js +2 -0
- package/dist/bundle/chunks/openai-chatgpt.js +101 -0
- package/dist/bundle/chunks/openai-codex-responses-IT7VEKUU.js +10 -0
- package/dist/bundle/chunks/openai-codex.js +101 -0
- package/dist/bundle/chunks/openai-completions-LOKIW33V.js +7 -0
- package/dist/bundle/chunks/openai-decisions-4F3LWHMG.js +5 -0
- package/dist/bundle/chunks/openai-responses-OK36GJXP.js +3 -0
- package/dist/bundle/chunks/openrouter-images-ZI7LLZ4Y.js +2 -0
- package/dist/bundle/chunks/openrouter.js +101 -0
- package/dist/bundle/chunks/radius.js +101 -0
- package/dist/bundle/chunks/runtime-IN7ZPKFY.js +2 -0
- package/dist/bundle/chunks/src-ETRMT73D.js +4 -0
- package/dist/bundle/chunks/typesafe-system-one-J2CJBWEH.js +2 -0
- package/dist/bundle/chunks/virtual-modules-7VXI3TVN.js +2 -0
- package/dist/bundle/chunks/xai.js +2 -0
- package/dist/bundle/cli-runtime.js +3 -0
- package/dist/bundle/cli.js +16 -0
- package/dist/bundle/native/darwin/prebuilds/darwin-arm64/darwin-platform.node +0 -0
- package/dist/bundle/native/darwin/prebuilds/darwin-x64/darwin-platform.node +0 -0
- package/dist/bundle/native/linux/prebuilds/linux-arm64/linux-platform-x11.node +0 -0
- package/dist/bundle/native/linux/prebuilds/linux-x64/linux-platform-x11.node +0 -0
- package/dist/bundle/native/win32/prebuilds/win32-arm64/win32-platform.node +0 -0
- package/dist/bundle/native/win32/prebuilds/win32-x64/win32-platform.node +0 -0
- package/dist/core/export-html/template.css +1015 -0
- package/dist/core/export-html/template.html +55 -0
- package/dist/core/export-html/template.js +1929 -0
- package/dist/core/export-html/vendor/highlight.min.js +1213 -0
- package/dist/core/export-html/vendor/marked.min.js +78 -0
- package/dist/modes/interactive/theme/dark.json +74 -0
- package/dist/modes/interactive/theme/light.json +74 -0
- package/dist/modes/interactive/theme/system-theme.ts +579 -0
- package/dist/modes/interactive/theme/theme-controller.ts +253 -0
- package/dist/modes/interactive/theme/theme-schema.ts +145 -0
- package/dist/modes/interactive/theme/theme-tokens.ts +145 -0
- package/dist/modes/interactive/theme/theme.ts +1076 -0
- package/docs/app-server.md +479 -0
- package/docs/app-server.schema.json +8128 -0
- package/docs/cli-integration.md +106 -0
- package/docs/cli.md +393 -0
- package/docs/codemode.md +230 -0
- package/docs/compaction.md +463 -0
- package/docs/configuration.md +48 -0
- package/docs/containerization.md +143 -0
- package/docs/custom-provider.md +225 -0
- package/docs/desktop.md +73 -0
- package/docs/docs.json +236 -0
- package/docs/environment-variables.md +138 -0
- package/docs/extensions.md +420 -0
- package/docs/how-knightcode-works.md +49 -0
- package/docs/images/doom-extension.png +0 -0
- package/docs/images/interactive-mode.png +0 -0
- package/docs/images/tree-view.png +0 -0
- package/docs/index.md +39 -0
- package/docs/json.md +226 -0
- package/docs/keybindings.md +197 -0
- package/docs/llama-cpp.md +121 -0
- package/docs/mcp.md +272 -0
- package/docs/message-types.md +279 -0
- package/docs/models-configuration.md +187 -0
- package/docs/models.md +221 -0
- package/docs/nvidia-rtx-llama-cpp.md +96 -0
- package/docs/packages.md +129 -0
- package/docs/plan-mode.md +121 -0
- package/docs/prompt-templates.md +59 -0
- package/docs/providers.md +282 -0
- package/docs/quickstart.md +128 -0
- package/docs/remote.md +87 -0
- package/docs/rpc-commands.md +860 -0
- package/docs/rpc-extension-ui.md +214 -0
- package/docs/rpc.md +193 -0
- package/docs/sdk.md +197 -0
- package/docs/security.md +99 -0
- package/docs/session-format.md +358 -0
- package/docs/sessions.md +135 -0
- package/docs/settings.md +220 -0
- package/docs/shell-aliases.md +93 -0
- package/docs/skills.md +93 -0
- package/docs/slash-commands.md +78 -0
- package/docs/terminal-setup.md +242 -0
- package/docs/termux.md +117 -0
- package/docs/themes.md +140 -0
- package/docs/tmux.md +55 -0
- package/docs/tui.md +195 -0
- package/docs/usage.md +167 -0
- package/docs/virtual-models.md +114 -0
- package/docs/windows.md +67 -0
- package/examples/README.md +36 -0
- package/examples/extensions/README.md +214 -0
- package/examples/extensions/auto-commit-on-exit.ts +55 -0
- package/examples/extensions/bash-spawn-hook.ts +30 -0
- package/examples/extensions/bookmark.ts +50 -0
- package/examples/extensions/border-status-editor.ts +151 -0
- package/examples/extensions/built-in-tool-renderer.ts +225 -0
- package/examples/extensions/claude-rules.ts +89 -0
- package/examples/extensions/commands.ts +72 -0
- package/examples/extensions/confirm-destructive.ts +60 -0
- package/examples/extensions/custom-compaction.ts +118 -0
- package/examples/extensions/custom-footer.ts +66 -0
- package/examples/extensions/custom-header.ts +73 -0
- package/examples/extensions/custom-provider-anthropic/index.ts +617 -0
- package/examples/extensions/custom-provider-anthropic/package-lock.json +24 -0
- package/examples/extensions/custom-provider-anthropic/package.json +19 -0
- package/examples/extensions/custom-provider-gitlab-duo/index.ts +399 -0
- package/examples/extensions/custom-provider-gitlab-duo/package.json +16 -0
- package/examples/extensions/custom-provider-gitlab-duo/test.ts +82 -0
- package/examples/extensions/debug-provider.ts +90 -0
- package/examples/extensions/dirty-repo-guard.ts +56 -0
- package/examples/extensions/doom-overlay/README.md +46 -0
- package/examples/extensions/doom-overlay/doom/build.sh +152 -0
- package/examples/extensions/doom-overlay/doom/doomgeneric_knightcode.c +72 -0
- package/examples/extensions/doom-overlay/doom-component.ts +132 -0
- package/examples/extensions/doom-overlay/doom-engine.ts +173 -0
- package/examples/extensions/doom-overlay/doom-keys.ts +104 -0
- package/examples/extensions/doom-overlay/index.ts +74 -0
- package/examples/extensions/doom-overlay/wad-finder.ts +55 -0
- package/examples/extensions/dynamic-resources/SKILL.md +8 -0
- package/examples/extensions/dynamic-resources/dynamic.json +75 -0
- package/examples/extensions/dynamic-resources/dynamic.md +5 -0
- package/examples/extensions/dynamic-resources/index.ts +15 -0
- package/examples/extensions/dynamic-tools.ts +74 -0
- package/examples/extensions/entry-renderer.ts +41 -0
- package/examples/extensions/event-bus.ts +43 -0
- package/examples/extensions/file-trigger.ts +41 -0
- package/examples/extensions/git-checkpoint.ts +53 -0
- package/examples/extensions/git-merge-and-resolve.ts +115 -0
- package/examples/extensions/github-issue-autocomplete.ts +185 -0
- package/examples/extensions/gondolin/index.ts +531 -0
- package/examples/extensions/gondolin/package-lock.json +185 -0
- package/examples/extensions/gondolin/package.json +19 -0
- package/examples/extensions/handoff.ts +190 -0
- package/examples/extensions/hello.ts +26 -0
- package/examples/extensions/hidden-thinking-label.ts +53 -0
- package/examples/extensions/inline-bash.ts +94 -0
- package/examples/extensions/input-transform-streaming.ts +39 -0
- package/examples/extensions/input-transform.ts +43 -0
- package/examples/extensions/interactive-shell.ts +196 -0
- package/examples/extensions/jev-router.ts +113 -0
- package/examples/extensions/mac-system-theme.ts +47 -0
- package/examples/extensions/message-renderer.ts +59 -0
- package/examples/extensions/minimal-mode.ts +353 -0
- package/examples/extensions/modal-editor.ts +85 -0
- package/examples/extensions/model-status.ts +31 -0
- package/examples/extensions/notify.ts +57 -0
- package/examples/extensions/overlay-qa-tests.ts +1450 -0
- package/examples/extensions/overlay-test.ts +153 -0
- package/examples/extensions/permission-gate.ts +34 -0
- package/examples/extensions/pirate.ts +47 -0
- package/examples/extensions/plan-mode/README.md +66 -0
- package/examples/extensions/plan-mode/index.ts +387 -0
- package/examples/extensions/plan-mode/utils.ts +168 -0
- package/examples/extensions/preset.ts +436 -0
- package/examples/extensions/project-trust.ts +64 -0
- package/examples/extensions/prompt-customizer.ts +49 -0
- package/examples/extensions/protected-paths.ts +30 -0
- package/examples/extensions/provider-payload.ts +18 -0
- package/examples/extensions/qna.ts +118 -0
- package/examples/extensions/question.ts +278 -0
- package/examples/extensions/questionnaire.ts +440 -0
- package/examples/extensions/rainbow-editor.ts +88 -0
- package/examples/extensions/reload-runtime.ts +37 -0
- package/examples/extensions/rpc-demo.ts +118 -0
- package/examples/extensions/sandbox/index.ts +321 -0
- package/examples/extensions/sandbox/package-lock.json +92 -0
- package/examples/extensions/sandbox/package.json +19 -0
- package/examples/extensions/send-user-message.ts +97 -0
- package/examples/extensions/session-name.ts +27 -0
- package/examples/extensions/shutdown-command.ts +63 -0
- package/examples/extensions/snake.ts +343 -0
- package/examples/extensions/space-invaders.ts +560 -0
- package/examples/extensions/ssh.ts +220 -0
- package/examples/extensions/status-line.ts +32 -0
- package/examples/extensions/structured-output.ts +65 -0
- package/examples/extensions/subagent/README.md +177 -0
- package/examples/extensions/subagent/agents/planner.md +37 -0
- package/examples/extensions/subagent/agents/reviewer.md +35 -0
- package/examples/extensions/subagent/agents/scout.md +50 -0
- package/examples/extensions/subagent/agents/worker.md +24 -0
- package/examples/extensions/subagent/agents.ts +157 -0
- package/examples/extensions/subagent/index.ts +1010 -0
- package/examples/extensions/subagent/prompts/implement-and-review.md +10 -0
- package/examples/extensions/subagent/prompts/implement.md +10 -0
- package/examples/extensions/subagent/prompts/scout-and-plan.md +9 -0
- package/examples/extensions/summarize.ts +199 -0
- package/examples/extensions/system-prompt-header.ts +17 -0
- package/examples/extensions/tic-tac-toe.ts +1004 -0
- package/examples/extensions/timed-confirm.ts +70 -0
- package/examples/extensions/titlebar-spinner.ts +58 -0
- package/examples/extensions/todo.ts +294 -0
- package/examples/extensions/tool-override.ts +144 -0
- package/examples/extensions/tools.ts +146 -0
- package/examples/extensions/trigger-compact.ts +50 -0
- package/examples/extensions/truncated-tool.ts +195 -0
- package/examples/extensions/widget-placement.ts +9 -0
- package/examples/extensions/with-deps/index.ts +32 -0
- package/examples/extensions/with-deps/package-lock.json +31 -0
- package/examples/extensions/with-deps/package.json +22 -0
- package/examples/extensions/working-indicator.ts +121 -0
- package/examples/extensions/working-message-test.ts +25 -0
- package/examples/rpc-client.ts +35 -0
- package/examples/rpc-extension-ui.ts +661 -0
- package/examples/sdk/01-minimal.ts +26 -0
- package/examples/sdk/02-custom-model.ts +49 -0
- package/examples/sdk/03-custom-prompt.ts +70 -0
- package/examples/sdk/04-skills.ts +55 -0
- package/examples/sdk/05-tools.ts +48 -0
- package/examples/sdk/06-extensions.ts +94 -0
- package/examples/sdk/07-context-files.ts +42 -0
- package/examples/sdk/08-prompt-templates.ts +51 -0
- package/examples/sdk/09-api-keys-and-oauth.ts +34 -0
- package/examples/sdk/10-settings.ts +53 -0
- package/examples/sdk/11-sessions.ts +52 -0
- package/examples/sdk/12-full-control.ts +74 -0
- package/examples/sdk/13-session-runtime.ts +67 -0
- package/examples/sdk/14-codemode-mcp.ts +61 -0
- package/examples/sdk/README.md +141 -0
- package/package.json +15 -15
- package/bin/knightcode +0 -62
package/docs/json.md
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
# JSON Event Stream
|
|
2
|
+
|
|
3
|
+
JSON mode emits structured progress for one invocation:
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
knightcode --mode json "Review this repository"
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
KnightCode writes one session header followed by session events, then exits after the supplied prompts finish. RPC mode emits the same session-event shapes but has no session header because it is a bidirectional, long-lived protocol. See [RPC Mode](rpc.md).
|
|
10
|
+
|
|
11
|
+
This page is the canonical reference for events shared by JSON and RPC mode. Message values use the [shared message types](message-types.md).
|
|
12
|
+
|
|
13
|
+
## Framing and process I/O
|
|
14
|
+
|
|
15
|
+
The stream uses strict JSONL framing. Each record is one JSON object terminated by LF (`\n`). Split records only on LF and strip an optional preceding carriage return. Unicode line and paragraph separators are valid inside JSON strings and are not record boundaries.
|
|
16
|
+
|
|
17
|
+
Node.js `readline` is not suitable for this stream because it also recognizes those Unicode separators. Use a byte or UTF-8 stream decoder and split on LF.
|
|
18
|
+
|
|
19
|
+
Read stdout continuously. A reader that stops consuming records can stall KnightCode when the pipe buffer fills. Stdout is reserved for JSONL; diagnostics and application logging go to stderr.
|
|
20
|
+
|
|
21
|
+
## Session header
|
|
22
|
+
|
|
23
|
+
The first JSON-mode record is the current [session header](session-format.md#sessionheader):
|
|
24
|
+
|
|
25
|
+
```json
|
|
26
|
+
{"type":"session","version":3,"id":"uuid","timestamp":"2024-12-03T14:00:00.000Z","cwd":"/path"}
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
RPC mode does not emit this record. Use [`get_state`](rpc-commands.md#get_state) for its current session ID and file.
|
|
30
|
+
|
|
31
|
+
## Event sequence
|
|
32
|
+
|
|
33
|
+
A basic run produces records like these:
|
|
34
|
+
|
|
35
|
+
```json
|
|
36
|
+
{"type":"agent_start"}
|
|
37
|
+
{"type":"turn_start"}
|
|
38
|
+
{"type":"message_start","message":{"role":"user","content":"Review this repository","timestamp":1733234401000}}
|
|
39
|
+
{"type":"message_end","message":{"role":"user","content":"Review this repository","timestamp":1733234401000}}
|
|
40
|
+
{"type":"message_start","message":{"role":"assistant","content":[],"stopReason":"pending","...":"..."}}
|
|
41
|
+
{"type":"message_update","usage":{"...":"..."},"assistantMessageEvent":{"type":"text_delta","contentIndex":0,"delta":"Hello"}}
|
|
42
|
+
{"type":"message_end","message":{"role":"assistant","...":"..."}}
|
|
43
|
+
{"type":"turn_end","message":{"role":"assistant","...":"..."},"toolResults":[]}
|
|
44
|
+
{"type":"agent_end","messages":[{"...":"..."}],"willRetry":false}
|
|
45
|
+
{"type":"agent_settled","aborted":false}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
`agent_end` closes one low-level agent run. Automatic retry, overflow recovery, compaction retry, steering, or follow-up work can still continue. `agent_settled` means KnightCode has no remaining automatic work for that session-level run.
|
|
49
|
+
|
|
50
|
+
## Agent and turn events
|
|
51
|
+
|
|
52
|
+
| Event | Fields | Meaning |
|
|
53
|
+
|---|---|---|
|
|
54
|
+
| `agent_start` | None | A low-level agent run started. |
|
|
55
|
+
| `agent_end` | `messages`, `willRetry` | That low-level run ended. `messages` contains messages generated by the run. |
|
|
56
|
+
| `agent_settled` | `aborted` | KnightCode will not continue automatically through retries, compaction recovery, or queued messages. `aborted` is `true` when the run ended because it was aborted. |
|
|
57
|
+
| `turn_start` | None | One assistant turn started. |
|
|
58
|
+
| `turn_end` | `message`, `toolResults` | One assistant response and its resulting tool calls finished. |
|
|
59
|
+
|
|
60
|
+
A turn is one assistant response plus any tool calls and tool results produced by that response.
|
|
61
|
+
|
|
62
|
+
## Message events
|
|
63
|
+
|
|
64
|
+
| Event | Fields | Meaning |
|
|
65
|
+
|---|---|---|
|
|
66
|
+
| `message_start` | `message` | A message started. |
|
|
67
|
+
| `message_update` | `usage`, `assistantMessageEvent` | An assistant message emitted a content-block update. |
|
|
68
|
+
| `message_end` | `message` | A message completed. This is the authoritative final message. |
|
|
69
|
+
|
|
70
|
+
### Reconstruct streaming messages
|
|
71
|
+
|
|
72
|
+
Wire `message_update` records are delta-only. They omit the SDK event's cumulative `message` field and every `assistantMessageEvent.partial` snapshot so stream size remains linear.
|
|
73
|
+
|
|
74
|
+
The nested event is one of:
|
|
75
|
+
|
|
76
|
+
| Type | Fields in addition to `type` | Meaning |
|
|
77
|
+
|---|---|---|
|
|
78
|
+
| `start` | None | The provider stream started; its cumulative `partial` field is removed on the wire. |
|
|
79
|
+
| `text_start` | `contentIndex` | A text block started. |
|
|
80
|
+
| `text_delta` | `contentIndex`, `delta` | Append text to the block. |
|
|
81
|
+
| `text_end` | `contentIndex`, `content` | The text block ended with authoritative content. |
|
|
82
|
+
| `thinking_start` | `contentIndex` | A thinking block started. |
|
|
83
|
+
| `thinking_delta` | `contentIndex`, `delta` | Append thinking text to the block. |
|
|
84
|
+
| `thinking_end` | `contentIndex`, `content` | The thinking block ended with authoritative content. |
|
|
85
|
+
| `toolcall_start` | `contentIndex`, `id`, `toolName` | A tool-call block started. |
|
|
86
|
+
| `toolcall_delta` | `contentIndex`, `delta` | Append serialized argument data. |
|
|
87
|
+
| `toolcall_end` | `contentIndex`, `toolCall` | The tool call ended with the complete `ToolCall`. |
|
|
88
|
+
| `done` | `reason`, `message` | The provider stream completed successfully. |
|
|
89
|
+
| `error` | `reason`, `error` | The provider stream ended with an error or abort message. |
|
|
90
|
+
|
|
91
|
+
The normal agent loop translates provider-level `start`, `done`, and `error` into `message_start` and `message_end` session events rather than emitting them as `message_update`. They remain admitted by the exported `JsonAgentSessionEvent` transformation for callers that construct a matching session event.
|
|
92
|
+
|
|
93
|
+
Use `contentIndex` to identify the content block. Buffer `delta` fields for a live display, but replace reconstructed data with the completed content in `text_end`, `thinking_end`, or `toolcall_end`. Replace the whole partial message with `message_end.message` when it arrives.
|
|
94
|
+
|
|
95
|
+
The top-level `usage` is the latest cumulative provider-reported usage for the assistant response. It can remain zero until completion when a provider does not report usage while streaming.
|
|
96
|
+
|
|
97
|
+
```json
|
|
98
|
+
{"type":"message_update","usage":{"input":100,"output":1,"cacheRead":0,"cacheWrite":0,"totalTokens":101,"cost":{"input":0,"output":0,"cacheRead":0,"cacheWrite":0,"total":0}},"assistantMessageEvent":{"type":"text_delta","contentIndex":0,"delta":"Hello "}}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Tool execution events
|
|
102
|
+
|
|
103
|
+
| Event | Fields | Meaning |
|
|
104
|
+
|---|---|---|
|
|
105
|
+
| `tool_execution_start` | `toolCallId`, `toolName`, `args` | Tool execution started. |
|
|
106
|
+
| `tool_execution_update` | `toolCallId`, `toolName`, `args`, `partialResult` | The tool reported a partial result. |
|
|
107
|
+
| `tool_execution_end` | `toolCallId`, `toolName`, `result`, `isError`, `durationMs` | Tool execution finished. `durationMs` is how long the tool's `execute()` took, measured with a monotonic clock; absent when the tool did not run. |
|
|
108
|
+
|
|
109
|
+
Use `toolCallId` to correlate the lifecycle. `partialResult` is the latest partial result supplied by the tool. Whether it replaces or extends an earlier update depends on that tool's result contract.
|
|
110
|
+
|
|
111
|
+
```json
|
|
112
|
+
{"type":"tool_execution_start","toolCallId":"call_abc123","toolName":"bash","args":{"command":"ls -la"}}
|
|
113
|
+
{"type":"tool_execution_update","toolCallId":"call_abc123","toolName":"bash","args":{"command":"ls -la"},"partialResult":{"content":[{"type":"text","text":"partial output"}],"details":{}}}
|
|
114
|
+
{"type":"tool_execution_end","toolCallId":"call_abc123","toolName":"bash","result":{"content":[{"type":"text","text":"complete output"}],"details":{}},"isError":false}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Queue and state events
|
|
118
|
+
|
|
119
|
+
| Event | Fields | Meaning |
|
|
120
|
+
|---|---|---|
|
|
121
|
+
| `queue_update` | `steering`, `followUp` | The pending steering or follow-up queue changed. Both fields contain the complete current queue. |
|
|
122
|
+
| `entry_appended` | `entry` | An extension appended a custom session entry through `knightcode.appendEntry()`. |
|
|
123
|
+
| `session_info_changed` | `name` | The session display name changed. An absent `name` means it was cleared. |
|
|
124
|
+
| `thinking_level_changed` | `level` | The active thinking level changed. |
|
|
125
|
+
|
|
126
|
+
The `entry` value uses a persisted [session entry type](session-format.md#entry-types).
|
|
127
|
+
|
|
128
|
+
## Compaction events
|
|
129
|
+
|
|
130
|
+
`compaction_start` reports why compaction began:
|
|
131
|
+
|
|
132
|
+
```json
|
|
133
|
+
{"type":"compaction_start","reason":"threshold"}
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
`reason` is `"manual"`, `"threshold"`, or `"overflow"`.
|
|
137
|
+
|
|
138
|
+
`compaction_end` contains the result when compaction succeeds:
|
|
139
|
+
|
|
140
|
+
```json
|
|
141
|
+
{
|
|
142
|
+
"type": "compaction_end",
|
|
143
|
+
"reason": "threshold",
|
|
144
|
+
"result": {
|
|
145
|
+
"summary": "Summary of conversation...",
|
|
146
|
+
"firstKeptEntryId": "abc123",
|
|
147
|
+
"tokensBefore": 150000,
|
|
148
|
+
"estimatedTokensAfter": 32000,
|
|
149
|
+
"usage": {"...": "..."},
|
|
150
|
+
"details": {}
|
|
151
|
+
},
|
|
152
|
+
"aborted": false,
|
|
153
|
+
"willRetry": false
|
|
154
|
+
}
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
If compaction was aborted, `result` is absent and `aborted` is true. If it failed, `result` is absent, `aborted` is false, and `errorMessage` describes the failure. Successful overflow recovery sets `willRetry` to true before KnightCode retries the prompt.
|
|
158
|
+
|
|
159
|
+
See [Compaction and Branch Summaries](compaction.md) for result semantics.
|
|
160
|
+
|
|
161
|
+
## Retry events
|
|
162
|
+
|
|
163
|
+
Assistant-turn retry emits:
|
|
164
|
+
|
|
165
|
+
```json
|
|
166
|
+
{"type":"auto_retry_start","attempt":1,"maxAttempts":3,"delayMs":2000,"errorMessage":"529 overloaded"}
|
|
167
|
+
{"type":"auto_retry_end","success":true,"attempt":2}
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
On final failure, `auto_retry_end` has `success: false` and a `finalError` string.
|
|
171
|
+
|
|
172
|
+
Compaction and branch-summary retry emit:
|
|
173
|
+
|
|
174
|
+
```json
|
|
175
|
+
{"type":"summarization_retry_scheduled","attempt":1,"maxAttempts":3,"delayMs":2000,"errorMessage":"terminated"}
|
|
176
|
+
{"type":"summarization_retry_attempt_start","source":"compaction","reason":"threshold"}
|
|
177
|
+
{"type":"summarization_retry_finished"}
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
For a branch summary, `source` is `"branchSummary"` and `reason` is absent. The `reason` on a compaction retry is `"manual"`, `"threshold"`, or `"overflow"`.
|
|
181
|
+
|
|
182
|
+
## RPC-only events
|
|
183
|
+
|
|
184
|
+
A direct RPC [`bash`](rpc-commands.md#bash) command emits one `bash_execution_update` for each output chunk. Its optional `id` matches the command ID. The final command response can contain truncated output, but these events stream all output:
|
|
185
|
+
|
|
186
|
+
```json
|
|
187
|
+
{"type":"bash_execution_update","id":"req-1","delta":"total 48\n"}
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
RPC also adds `extension_error` when an extension handler throws:
|
|
191
|
+
|
|
192
|
+
```json
|
|
193
|
+
{"type":"extension_error","extensionPath":"/path/to/extension.ts","event":"tool_call","error":"Error message"}
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
Extension UI records are a separate RPC subprotocol, not `AgentSessionEvent` values. See [RPC Extension UI](rpc-extension-ui.md).
|
|
197
|
+
|
|
198
|
+
## TypeScript types
|
|
199
|
+
|
|
200
|
+
The SDK's `AgentSessionEvent` contains cumulative streaming snapshots for in-process consumers. JSON and RPC transform only `message_update`:
|
|
201
|
+
|
|
202
|
+
```typescript
|
|
203
|
+
type WithoutPartial<T> = T extends { partial: unknown } ? Omit<T, "partial"> : T;
|
|
204
|
+
|
|
205
|
+
type JsonAssistantMessageEvent<T> = T extends { type: "toolcall_start"; partial: unknown }
|
|
206
|
+
? WithoutPartial<T> & { id: string; toolName: string }
|
|
207
|
+
: WithoutPartial<T>;
|
|
208
|
+
|
|
209
|
+
type JsonAgentSessionEvent =
|
|
210
|
+
| Exclude<AgentSessionEvent, { type: "message_update" }>
|
|
211
|
+
| {
|
|
212
|
+
type: "message_update";
|
|
213
|
+
usage: Usage;
|
|
214
|
+
assistantMessageEvent: JsonAssistantMessageEvent<AssistantMessageEvent>;
|
|
215
|
+
};
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
Use the exported `JsonAgentSessionEvent` type from `@knightcodeai/cli`. Its implementation is in [`json-event.ts`](https://github.com/KnightCodeAI/knightcode/blob/main/packages/cli/src/modes/json-event.ts).
|
|
219
|
+
|
|
220
|
+
## Example
|
|
221
|
+
|
|
222
|
+
Print completed messages from a one-shot run:
|
|
223
|
+
|
|
224
|
+
```bash
|
|
225
|
+
knightcode --mode json "List files" 2>/dev/null | jq -c 'select(.type == "message_end")'
|
|
226
|
+
```
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
# Keybindings Reference
|
|
2
|
+
|
|
3
|
+
KnightCode exposes named actions, such as `app.session.new`, that can be assigned keybindings. You can change default assignments or bind unassigned actions in KnightCode's [user configuration](configuration.md#agent-directory).
|
|
4
|
+
|
|
5
|
+
Run `/hotkeys` to see the active shortcuts for the main editor and application.
|
|
6
|
+
|
|
7
|
+
## Assign keybindings
|
|
8
|
+
|
|
9
|
+
Create `<agent-dir>/keybindings.json`. The agent directory defaults to `~/.knightcode/agent` and is described in [Agent directory](configuration.md#agent-directory).
|
|
10
|
+
|
|
11
|
+
Map each action identifier to one key or a list of keys:
|
|
12
|
+
|
|
13
|
+
```json
|
|
14
|
+
{
|
|
15
|
+
"$schema": "https://knightcode.dev/schemas/keybindings.schema.json",
|
|
16
|
+
"app.session.new": "ctrl+shift+n",
|
|
17
|
+
"app.session.tree": ["ctrl+shift+t", "alt+shift+t"]
|
|
18
|
+
}
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
A configured value replaces the default for that action. Use an empty list to disable an action's keybindings:
|
|
22
|
+
|
|
23
|
+
```json
|
|
24
|
+
{
|
|
25
|
+
"tui.altScreen.pageUp": []
|
|
26
|
+
}
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
After editing the file, run `/reload` to apply the changes to the active session.
|
|
30
|
+
|
|
31
|
+
## Key syntax
|
|
32
|
+
|
|
33
|
+
Write a key as `modifier+key`. Modifiers are `ctrl`, `shift`, `alt`, and `super`. You can combine modifiers. Valid keys are:
|
|
34
|
+
|
|
35
|
+
- **Letters:** `a-z`
|
|
36
|
+
- **Digits:** `0-9`
|
|
37
|
+
- **Special:** `escape`, `esc`, `enter`, `return`, `tab`, `space`, `backspace`, `delete`, `insert`, `clear`, `home`, `end`, `pageUp`, `pageDown`, `up`, `down`, `left`, `right`
|
|
38
|
+
- **Function:** `f1`-`f12`
|
|
39
|
+
- **Symbols:** `` ` ``, `-`, `=`, `[`, `]`, `\`, `;`, `'`, `,`, `.`, `/`, `!`, `@`, `#`, `$`, `%`, `^`, `&`, `*`, `(`, `)`, `_`, `+`, `|`, `~`, `{`, `}`, `:`, `<`, `>`, `?`
|
|
40
|
+
|
|
41
|
+
Examples: `ctrl+shift+x`, `alt+ctrl+x`, `ctrl+shift+alt+x`, `super+k`, `ctrl+super+k`, and `ctrl+1`.
|
|
42
|
+
|
|
43
|
+
`super` bindings require a terminal that reports the modifier separately, typically through the Kitty keyboard protocol. They may not work in terminals without that support.
|
|
44
|
+
|
|
45
|
+
## Actions
|
|
46
|
+
|
|
47
|
+
### Terminal UI
|
|
48
|
+
|
|
49
|
+
#### Cursor movement
|
|
50
|
+
|
|
51
|
+
| Keybinding id | Default | Description |
|
|
52
|
+
|---|---|---|
|
|
53
|
+
| `tui.editor.cursorUp` | `up` | Move cursor up, browsing older history at the top |
|
|
54
|
+
| `tui.editor.cursorDown` | `down` | Move cursor down, browsing newer history at the bottom |
|
|
55
|
+
| `tui.editor.historyPrevious` | None | Select the previous prompt history entry |
|
|
56
|
+
| `tui.editor.historyNext` | None | Select the next prompt history entry |
|
|
57
|
+
| `tui.editor.cursorLeft` | `left`, `ctrl+b` | Move cursor left |
|
|
58
|
+
| `tui.editor.cursorRight` | `right`, `ctrl+f` | Move cursor right |
|
|
59
|
+
| `tui.editor.cursorWordLeft` | `alt+left`, `ctrl+left`, `alt+b` | Move cursor word left |
|
|
60
|
+
| `tui.editor.cursorWordRight` | `alt+right`, `ctrl+right`, `alt+f` | Move cursor word right |
|
|
61
|
+
| `tui.editor.cursorLineStart` | `home`, `ctrl+a` | Move to line start |
|
|
62
|
+
| `tui.editor.cursorLineEnd` | `end`, `ctrl+e` | Move to line end |
|
|
63
|
+
| `tui.editor.jumpForward` | `ctrl+]` | Jump forward to character |
|
|
64
|
+
| `tui.editor.jumpBackward` | `ctrl+alt+]` | Jump backward to character |
|
|
65
|
+
| `tui.editor.pageUp` | `pageUp`, `ctrl+pageUp` | Scroll up by page |
|
|
66
|
+
| `tui.editor.pageDown` | `pageDown`, `ctrl+pageDown` | Scroll down by page |
|
|
67
|
+
|
|
68
|
+
The dedicated history actions browse prompt history regardless of cursor position and take precedence over application actions using the same key.
|
|
69
|
+
|
|
70
|
+
#### Text editing
|
|
71
|
+
|
|
72
|
+
| Keybinding id | Default | Description |
|
|
73
|
+
|---|---|---|
|
|
74
|
+
| `tui.editor.deleteCharBackward` | `backspace` | Delete character backward |
|
|
75
|
+
| `tui.editor.deleteCharForward` | `delete`, `ctrl+d` | Delete character forward |
|
|
76
|
+
| `tui.editor.deleteWordBackward` | `ctrl+w`, `alt+backspace` | Delete word backward |
|
|
77
|
+
| `tui.editor.deleteWordForward` | `alt+d`, `alt+delete` | Delete word forward |
|
|
78
|
+
| `tui.editor.deleteToLineStart` | `ctrl+u` | Delete to line start |
|
|
79
|
+
| `tui.editor.deleteToLineEnd` | `ctrl+k` | Delete to line end |
|
|
80
|
+
| `tui.editor.yank` | `ctrl+y` | Paste most recently deleted text |
|
|
81
|
+
| `tui.editor.yankPop` | `alt+y` | Cycle through deleted text after yank |
|
|
82
|
+
| `tui.editor.undo` | `ctrl+-` (`ctrl+z` on Windows; `alt+z` on WSL) | Undo last edit |
|
|
83
|
+
|
|
84
|
+
#### Input and selection
|
|
85
|
+
|
|
86
|
+
| Keybinding id | Default | Description |
|
|
87
|
+
|---|---|---|
|
|
88
|
+
| `tui.input.newLine` | `shift+enter`, `ctrl+j` | Insert new line |
|
|
89
|
+
| `tui.input.submit` | `enter` | Submit input |
|
|
90
|
+
| `tui.input.tab` | `tab` | Tab or autocomplete |
|
|
91
|
+
| `tui.input.copy` | `ctrl+c` | Copy selection |
|
|
92
|
+
| `tui.select.up` | `up` | Move selection up |
|
|
93
|
+
| `tui.select.down` | `down` | Move selection down |
|
|
94
|
+
| `tui.select.pageUp` | `pageUp` | Page up in list |
|
|
95
|
+
| `tui.select.pageDown` | `pageDown` | Page down in list |
|
|
96
|
+
| `tui.select.left` | `left` | Previous page of a selector, such as the previous question |
|
|
97
|
+
| `tui.select.right` | `right` | Next page of a selector, such as the next question |
|
|
98
|
+
| `tui.select.confirm` | `enter` | Confirm selection |
|
|
99
|
+
| `tui.select.cancel` | `escape`, `ctrl+c` | Cancel selection |
|
|
100
|
+
|
|
101
|
+
#### Fullscreen
|
|
102
|
+
|
|
103
|
+
In fullscreen mode, these actions control the transcript and take precedence over editor actions using the same key.
|
|
104
|
+
|
|
105
|
+
| Keybinding id | Default | Description |
|
|
106
|
+
|---|---|---|
|
|
107
|
+
| `tui.altScreen.pageUp` | `pageUp` | Scroll the transcript up by one page |
|
|
108
|
+
| `tui.altScreen.pageDown` | `pageDown` | Scroll the transcript down by one page |
|
|
109
|
+
| `tui.altScreen.halfPageUp` | None | Scroll the transcript up by half a page |
|
|
110
|
+
| `tui.altScreen.halfPageDown` | None | Scroll the transcript down by half a page |
|
|
111
|
+
| `tui.altScreen.lineUp` | None | Scroll the transcript up by one line |
|
|
112
|
+
| `tui.altScreen.lineDown` | None | Scroll the transcript down by one line |
|
|
113
|
+
| `tui.altScreen.previousPrompt` | `ctrl+shift+up`, `ctrl+up` (`ctrl+up` only on Windows and WSL) | Jump to the previous marked message |
|
|
114
|
+
| `tui.altScreen.nextPrompt` | `ctrl+shift+down`, `ctrl+down` (`ctrl+down` only on Windows and WSL) | Jump to the next marked message |
|
|
115
|
+
| `tui.altScreen.search` | `ctrl+shift+f` (`ctrl+f` on Windows and WSL) | Search the rendered transcript |
|
|
116
|
+
| `tui.altScreen.searchNext` | `enter`, `ctrl+g` | Select the next search match while searching |
|
|
117
|
+
| `tui.altScreen.searchPrevious` | `shift+enter`, `ctrl+shift+g` | Select the previous search match while searching |
|
|
118
|
+
| `tui.altScreen.searchClose` | `escape` | Close transcript search |
|
|
119
|
+
| `tui.altScreen.top` | `ctrl+home` | Scroll to the beginning of the transcript |
|
|
120
|
+
| `tui.altScreen.bottom` | `ctrl+end` | Scroll to the transcript end and follow new output |
|
|
121
|
+
|
|
122
|
+
### Application
|
|
123
|
+
|
|
124
|
+
| Keybinding id | Default | Description |
|
|
125
|
+
|--------|---------|-------------|
|
|
126
|
+
| `app.interrupt` | `escape` | Cancel / abort |
|
|
127
|
+
| `app.clear` | `ctrl+c` | Clear editor (first) / exit (second) |
|
|
128
|
+
| `app.exit` | `ctrl+d` | Exit (when editor empty) |
|
|
129
|
+
| `app.suspend` | `ctrl+z` (None on Windows) | Suspend to background |
|
|
130
|
+
| `app.editor.external` | `ctrl+g` | Open in external editor (`externalEditor`, `$VISUAL`, `$EDITOR`, Notepad on Windows, or `nano` elsewhere) |
|
|
131
|
+
| `app.clipboard.pasteImage` | `ctrl+v` (`alt+v` on Windows and WSL) | Paste files on macOS, images, or text from clipboard |
|
|
132
|
+
|
|
133
|
+
On native Windows, `app.suspend` has no default because Windows terminals do not support Unix job control. If you assign it manually, KnightCode shows a status message instead of suspending. WSL uses the normal `ctrl+z` and `fg` behavior.
|
|
134
|
+
|
|
135
|
+
### Sessions
|
|
136
|
+
|
|
137
|
+
| Keybinding id | Default | Description |
|
|
138
|
+
|--------|---------|-------------|
|
|
139
|
+
| `app.session.new` | None | Start a new session (`/new`) |
|
|
140
|
+
| `app.session.tree` | None | Open session tree navigator (`/tree`) |
|
|
141
|
+
| `app.session.fork` | None | Fork current session (`/fork`) |
|
|
142
|
+
| `app.session.resume` | None | Open session resume picker (`/resume`) |
|
|
143
|
+
| `app.session.togglePath` | `ctrl+p` | Toggle path display |
|
|
144
|
+
| `app.session.toggleSort` | `ctrl+s` | Toggle sort mode |
|
|
145
|
+
| `app.session.toggleNamedFilter` | `ctrl+n` | Toggle named-only filter |
|
|
146
|
+
| `app.session.rename` | `ctrl+r` | Rename session |
|
|
147
|
+
| `app.session.delete` | `ctrl+d` | Delete session |
|
|
148
|
+
| `app.session.deleteNoninvasive` | `ctrl+backspace` | Delete session when query is empty |
|
|
149
|
+
|
|
150
|
+
### Models and Thinking
|
|
151
|
+
|
|
152
|
+
| Keybinding id | Default | Description |
|
|
153
|
+
|--------|---------|-------------|
|
|
154
|
+
| `app.model.select` | `ctrl+l` | Open model selector |
|
|
155
|
+
| `app.model.cycleForward` | `ctrl+p` | Cycle to next model |
|
|
156
|
+
| `app.model.cycleBackward` | `shift+ctrl+p` (`alt+p` on Windows and WSL) | Cycle to previous model |
|
|
157
|
+
| `app.models.save` | `ctrl+s`, `ctrl+d` | Save the selected default model or scoped model configuration to settings (`ctrl+d` because many terminals swallow `ctrl+s`) |
|
|
158
|
+
| `app.thinking.cycle` | `shift+tab` | Cycle thinking level |
|
|
159
|
+
| `app.thinking.save` | `ctrl+s`, `ctrl+d` | Save current thinking level to settings (`ctrl+d` because many terminals swallow `ctrl+s`) |
|
|
160
|
+
| `app.thinking.toggle` | `ctrl+t` | Collapse or expand thinking blocks |
|
|
161
|
+
|
|
162
|
+
### Display and Message Queue
|
|
163
|
+
|
|
164
|
+
| Keybinding id | Default | Description |
|
|
165
|
+
|--------|---------|-------------|
|
|
166
|
+
| `app.tools.expand` | `ctrl+o` | Collapse or expand tool output |
|
|
167
|
+
| `app.message.copy` | `ctrl+x` | Copy the selected message in `/tree`; otherwise copy the active fullscreen text selection when `fullscreenCopyOnSelect` is disabled, falling back to the last assistant message. On OAuth sign-in screens, copy the sign-in URL |
|
|
168
|
+
| `app.message.followUp` | `alt+enter` (`ctrl+q` on Windows and WSL) | Queue follow-up message |
|
|
169
|
+
| `app.message.dequeue` | `alt+up` (`alt+q` on Windows and WSL) | Restore queued messages to editor |
|
|
170
|
+
|
|
171
|
+
### Tree Navigation
|
|
172
|
+
|
|
173
|
+
| Keybinding id | Default | Description |
|
|
174
|
+
|--------|---------|-------------|
|
|
175
|
+
| `app.tree.foldOrUp` | `ctrl+left`, `alt+left` | Fold current branch segment, or jump to the previous segment start |
|
|
176
|
+
| `app.tree.unfoldOrDown` | `ctrl+right`, `alt+right` | Unfold current branch segment, or jump to the next segment start or branch end |
|
|
177
|
+
| `app.tree.editLabel` | `shift+l` | Edit the label on the selected tree node |
|
|
178
|
+
| `app.tree.toggleLabelTimestamp` | `shift+t` | Toggle label timestamps in the tree |
|
|
179
|
+
| `app.tree.filter.default` | `ctrl+d` | Set tree filter to default view |
|
|
180
|
+
| `app.tree.filter.noTools` | `ctrl+t` | Toggle tree filter that hides tool results |
|
|
181
|
+
| `app.tree.filter.userOnly` | `ctrl+u` | Toggle tree filter that shows only user messages |
|
|
182
|
+
| `app.tree.filter.labeledOnly` | `ctrl+l` | Toggle tree filter that shows only labeled entries |
|
|
183
|
+
| `app.tree.filter.all` | `ctrl+a` | Toggle tree filter that shows all entries |
|
|
184
|
+
| `app.tree.filter.cycleForward` | `ctrl+o` | Cycle tree filter forward |
|
|
185
|
+
| `app.tree.filter.cycleBackward` | `shift+ctrl+o` | Cycle tree filter backward |
|
|
186
|
+
|
|
187
|
+
### Scoped Models Selector
|
|
188
|
+
|
|
189
|
+
Used inside the scoped models selector (opened via `/scoped-models`).
|
|
190
|
+
|
|
191
|
+
| Keybinding id | Default | Description |
|
|
192
|
+
|--------|---------|-------------|
|
|
193
|
+
| `app.models.enableAll` | `ctrl+a` | Enable all models (or all matching the current search) |
|
|
194
|
+
| `app.models.clearAll` | `ctrl+x` | Clear all models (or all matching the current search) |
|
|
195
|
+
| `app.models.toggleProvider` | `ctrl+p` | Toggle all models for the current provider |
|
|
196
|
+
| `app.models.reorderUp` | `alt+up` | Move the selected model up in the cycle order |
|
|
197
|
+
| `app.models.reorderDown` | `alt+down` | Move the selected model down in the cycle order |
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
# Local Models with llama.cpp
|
|
2
|
+
|
|
3
|
+
KnightCode supports the [llama.cpp](https://github.com/ggml-org/llama.cpp) router server. The router discovers multiple GGUF models and loads or unloads them on demand.
|
|
4
|
+
|
|
5
|
+
Use a current llama.cpp build with router support. Follow the [build instructions](https://github.com/ggml-org/llama.cpp/blob/master/docs/build.md) or install a [prebuilt release](https://github.com/ggml-org/llama.cpp/releases) for your platform.
|
|
6
|
+
|
|
7
|
+
## Start the router
|
|
8
|
+
|
|
9
|
+
Start `llama-server` without `--model` or `-m`. Passing a model starts single-model mode instead of router mode.
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
llama-server \
|
|
13
|
+
--models-dir ~/models \
|
|
14
|
+
--no-models-autoload \
|
|
15
|
+
--jinja \
|
|
16
|
+
--host 127.0.0.1 \
|
|
17
|
+
--port 8080 \
|
|
18
|
+
-ngl 999 \
|
|
19
|
+
-c 32768
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Important options:
|
|
23
|
+
|
|
24
|
+
- `--models-dir ~/models` discovers local GGUF files.
|
|
25
|
+
- `--no-models-autoload` keeps loading explicit through `/llama`.
|
|
26
|
+
- `--jinja` enables compatible chat templates and tool calling.
|
|
27
|
+
- `-ngl 999` offloads as many layers as possible to the GPU.
|
|
28
|
+
- `-c 32768` sets the context window for each loaded model. Omit it to use the model's native context, which may require substantially more memory.
|
|
29
|
+
|
|
30
|
+
A single-file model can sit directly in the model directory. Put multimodal and multi-shard models in separate subdirectories:
|
|
31
|
+
|
|
32
|
+
```text
|
|
33
|
+
~/models/
|
|
34
|
+
├── llama-3.2-1b-Q4_K_M.gguf
|
|
35
|
+
├── gemma-3-4b-it-Q4_K_M/
|
|
36
|
+
│ ├── gemma-3-4b-it-Q4_K_M.gguf
|
|
37
|
+
│ └── mmproj-F16.gguf
|
|
38
|
+
└── large-model-Q4_K_M/
|
|
39
|
+
├── large-model-Q4_K_M-00001-of-00003.gguf
|
|
40
|
+
├── large-model-Q4_K_M-00002-of-00003.gguf
|
|
41
|
+
└── large-model-Q4_K_M-00003-of-00003.gguf
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Restart the router after manually adding files. For per-model context sizes and other options, use [llama.cpp model presets](https://github.com/ggml-org/llama.cpp/blob/master/tools/server/README.md#model-presets). For settings tuned to a specific NVIDIA GPU and model, see [Run KnightCode with NVIDIA RTX and llama.cpp](nvidia-rtx-llama-cpp.md).
|
|
45
|
+
|
|
46
|
+
## Configure KnightCode
|
|
47
|
+
|
|
48
|
+
Start KnightCode and configure the provider:
|
|
49
|
+
|
|
50
|
+
```text
|
|
51
|
+
/login llama.cpp
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Enter the router URL and optional API key. The default URL is `http://127.0.0.1:8080`.
|
|
55
|
+
|
|
56
|
+
If you start the router with `--no-models-autoload`, `/login llama.cpp` only stores the connection. Run `/llama` to load a model, then `/model` to select the loaded model for the current session.
|
|
57
|
+
|
|
58
|
+
Environment variables can configure the same values without `/login`:
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
export LLAMA_BASE_URL=http://127.0.0.1:8080
|
|
62
|
+
export LLAMA_API_KEY=optional-secret
|
|
63
|
+
knightcode
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
If the server uses an API key, start `llama-server` with the matching `--api-key` value. Keep `--host 127.0.0.1` for local-only access.
|
|
67
|
+
|
|
68
|
+
## Manage models
|
|
69
|
+
|
|
70
|
+
Run:
|
|
71
|
+
|
|
72
|
+
```text
|
|
73
|
+
/llama
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
- Select an unloaded model to load it.
|
|
77
|
+
- Select a loaded model to unload it.
|
|
78
|
+
- Select **Download model…**, search Hugging Face, then choose a repository and quantization. Exact `owner/repository[:quant]` values also work.
|
|
79
|
+
- Press Escape during a load or download to confirm cancellation.
|
|
80
|
+
|
|
81
|
+
Hugging Face search uses `HF_TOKEN` when set, then checks `$HF_TOKEN_PATH`, `$HF_HOME/token`, `$XDG_CACHE_HOME/huggingface/token`, and `~/.cache/huggingface/token`. Search also works without authentication, subject to lower rate limits. KnightCode warns before downloading gated repositories and links to their access page. The llama.cpp server performs the download, so its process must also have `HF_TOKEN` when the selected repository requires access.
|
|
82
|
+
|
|
83
|
+
If other models are loaded, KnightCode asks whether to unload them first or keep them loaded. KnightCode does not silently unload models and never deletes model files. The router may be shared with other clients, so `/llama` always displays the router's current state.
|
|
84
|
+
|
|
85
|
+
Loaded and sleeping models appear in `/model`. Sleeping models wake automatically when selected. With router autoload enabled, unloaded preset models also appear and load when selected. With `--no-models-autoload`, load a model through `/llama` before selecting it.
|
|
86
|
+
|
|
87
|
+
If the router disconnects, `/llama` shows **Retry** and **Close**. Retry reconnects and refreshes model state without replaying the interrupted operation.
|
|
88
|
+
|
|
89
|
+
## Classification
|
|
90
|
+
|
|
91
|
+
Classifier models answer typed `choice`, `bool`, and `score` questions about JSON state, like TypeSafe's Jev models. The model reaches them from [`codemode`](cli.md#enable-codemode) scripts, and extensions through `ctx.modelRegistry.classify()`; see [Classifier models](models.md#use-classifier-models). KnightCode lists llama.cpp models as classifiers in two ways:
|
|
92
|
+
|
|
93
|
+
- **Decision models** such as [Julia-1, Laya, Kev, lev, and OpenJev](https://huggingface.co/collections/ggml-org/decision-models-6abf80cca3c83f127060a769) answer natively through llama.cpp's `/v1/systemone` endpoint. They appear only as classifiers, with the `typesafe-system-one` API, and not in `/model`.
|
|
94
|
+
- **Chat models** are also listed as classifiers with the same ID and the `llama-cpp-classify` API, which reads answers from next-token probabilities as described below.
|
|
95
|
+
|
|
96
|
+
llama.cpp 0.6.0 and later report decision models in the router's model list: their `architecture.output_modalities` contains `decisions`. The router reads this from the GGUF metadata without loading the model, so KnightCode recognizes unloaded and sleeping decision models too. Older llama.cpp builds do not report it, and KnightCode lists their decision models as chat models.
|
|
97
|
+
|
|
98
|
+
### Chat models as classifiers
|
|
99
|
+
|
|
100
|
+
The model does not generate an answer. Each question becomes one chat prompt: the state, every question of the request, the state again, and then the question with its answers under single-token labels. Labels are letters for a choice (up to 62 options), `Yes`/`No` for a bool, and digits for a score (up to 10 levels). The second copy of the state is read with the questions in view, which improved accuracy on JevBench with small models. KnightCode reads the probabilities of the labels as the next token and normalizes them. A choice returns every option's probability and a confidence of `(n * peak - 1) / (n - 1)`; a score returns the expected level.
|
|
101
|
+
|
|
102
|
+
- Raw label probabilities are usually overconfident. The per-request `temperature` option divides the label logits before normalizing; values above 1 soften the distribution. It changes no answer.
|
|
103
|
+
- Questions run one after another. Everything before the final question is the same for all questions of a request, so the server's prompt cache evaluates it once. The state appears twice, so it needs twice its size in context.
|
|
104
|
+
- Small models may follow instructions written inside the state. The prompt tells the model to judge the state as data, but that is not a guarantee.
|
|
105
|
+
- Hybrid models such as Qwen3.5 cannot rewind a partially cached prompt without context checkpoints. If each question reprocesses the whole state, start the router with `--ctx-checkpoints 32 --checkpoint-min-step 0`.
|
|
106
|
+
|
|
107
|
+
## Troubleshooting
|
|
108
|
+
|
|
109
|
+
Check that the router is reachable:
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
curl http://127.0.0.1:8080/health
|
|
113
|
+
curl http://127.0.0.1:8080/models
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
- **No models in `/llama`:** Check `--models-dir`, the directory layout, and restart the router.
|
|
117
|
+
- **Model missing from `/model` with `--no-models-autoload`:** Load it with `/llama` first.
|
|
118
|
+
- **Load fails or uses too much memory:** Lower `-c` or unload another model.
|
|
119
|
+
- **Server is not in router mode:** Start it without `--model`, `-m`, or `-hf`.
|
|
120
|
+
|
|
121
|
+
To remove the `llama.cpp` provider and `/llama`, disable `llama.cpp` under Built-in in `knightcode config`, or set `"extensions": ["-builtin:llama.cpp"]` in [settings](settings.md#resources).
|