@knightcodeai/cli 0.17.4 → 0.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (281) hide show
  1. package/CHANGELOG.md +1293 -0
  2. package/README.md +2 -2
  3. package/dist/bundle/chunks/anthropic-messages-A2IH2IY3.js +6 -0
  4. package/dist/bundle/chunks/anthropic.js +101 -0
  5. package/dist/bundle/chunks/azure-openai-responses-XZILQZOG.js +2 -0
  6. package/dist/bundle/chunks/bedrock-converse-stream.js +89 -0
  7. package/dist/bundle/chunks/chunk-4CRI7BMY.js +2 -0
  8. package/dist/bundle/chunks/chunk-57BPR4HF.js +2 -0
  9. package/dist/bundle/chunks/chunk-A5LJINMT.js +2 -0
  10. package/dist/bundle/chunks/chunk-AANBXVWQ.js +2 -0
  11. package/dist/bundle/chunks/chunk-ACHHEROF.js +7 -0
  12. package/dist/bundle/chunks/chunk-AFR2OW6S.js +108 -0
  13. package/dist/bundle/chunks/chunk-AHB7JV5B.js +2 -0
  14. package/dist/bundle/chunks/chunk-B2FT7RH5.js +2 -0
  15. package/dist/bundle/chunks/chunk-BRKUE2MD.js +2 -0
  16. package/dist/bundle/chunks/chunk-DKOURXGU.js +2 -0
  17. package/dist/bundle/chunks/chunk-DVFCXHT4.js +2 -0
  18. package/dist/bundle/chunks/chunk-EPYT326Y.js +30 -0
  19. package/dist/bundle/chunks/chunk-ETOMYYZC.js +2 -0
  20. package/dist/bundle/chunks/chunk-FA32X2UJ.js +7 -0
  21. package/dist/bundle/chunks/chunk-FHM6KUY3.js +44 -0
  22. package/dist/bundle/chunks/chunk-FO7CEQB3.js +11 -0
  23. package/dist/bundle/chunks/chunk-GHVXUCGU.js +130 -0
  24. package/dist/bundle/chunks/chunk-HHWP56PR.js +2 -0
  25. package/dist/bundle/chunks/chunk-HSL72VZI.js +2 -0
  26. package/dist/bundle/chunks/chunk-HUQB436V.js +2 -0
  27. package/dist/bundle/chunks/chunk-HWXGL4YB.js +2 -0
  28. package/dist/bundle/chunks/chunk-KQKUEQJA.js +6 -0
  29. package/dist/bundle/chunks/chunk-M5GCRGV6.js +1333 -0
  30. package/dist/bundle/chunks/chunk-MB4QRS7Y.js +9 -0
  31. package/dist/bundle/chunks/chunk-MXIWLMNT.js +8 -0
  32. package/dist/bundle/chunks/chunk-N6VDWLND.js +2 -0
  33. package/dist/bundle/chunks/chunk-NCIBB66G.js +2 -0
  34. package/dist/bundle/chunks/chunk-NDQ5OW6U.js +2 -0
  35. package/dist/bundle/chunks/chunk-NNCIIYD6.js +2 -0
  36. package/dist/bundle/chunks/chunk-O6JSP6YG.js +6 -0
  37. package/dist/bundle/chunks/chunk-OFST7FDG.js +2 -0
  38. package/dist/bundle/chunks/chunk-SPAUY3RD.js +12 -0
  39. package/dist/bundle/chunks/chunk-U5XE4RWR.js +2 -0
  40. package/dist/bundle/chunks/chunk-UZWP3NHW.js +2 -0
  41. package/dist/bundle/chunks/chunk-V5ANFNKF.js +11 -0
  42. package/dist/bundle/chunks/chunk-VJJ6J35N.js +20 -0
  43. package/dist/bundle/chunks/chunk-XIRAUXOE.js +58 -0
  44. package/dist/bundle/chunks/chunk-ZW7FVRHT.js +31 -0
  45. package/dist/bundle/chunks/cli-6ZTWO6GL.js +51 -0
  46. package/dist/bundle/chunks/cloudflare-workers-ai-system-one-6E2UM7IG.js +2 -0
  47. package/dist/bundle/chunks/codemode-worker.js +478 -0
  48. package/dist/bundle/chunks/dist-DKI7Q6GY.js +13 -0
  49. package/dist/bundle/chunks/easter-egg-3d-FDCGDUF3.js +2 -0
  50. package/dist/bundle/chunks/execute-VSDU5VSN.js +499 -0
  51. package/dist/bundle/chunks/github-copilot.js +2 -0
  52. package/dist/bundle/chunks/google-generative-ai-CSWR3ORZ.js +2 -0
  53. package/dist/bundle/chunks/google-vertex-QIDRFOFB.js +2 -0
  54. package/dist/bundle/chunks/image-resize-worker.js +2 -0
  55. package/dist/bundle/chunks/jiti-loader-BXVX3Y2R.js +21 -0
  56. package/dist/bundle/chunks/jiti-static-loader-NNBCFAO5.js +2 -0
  57. package/dist/bundle/chunks/kimi-coding.js +2 -0
  58. package/dist/bundle/chunks/knightcode-messages-3GNOTMSI.js +8 -0
  59. package/dist/bundle/chunks/lib-IHWMWJDR.js +9 -0
  60. package/dist/bundle/chunks/llama-cpp-classify-HRPRKOZA.js +22 -0
  61. package/dist/bundle/chunks/meta.js +2 -0
  62. package/dist/bundle/chunks/mistral-conversations-46TK5OBA.js +5 -0
  63. package/dist/bundle/chunks/multipart-parser-VTTMF2EO.js +3 -0
  64. package/dist/bundle/chunks/node-7S3GFMOZ.js +16 -0
  65. package/dist/bundle/chunks/node-MAEICQNS.js +2 -0
  66. package/dist/bundle/chunks/openai-chatgpt.js +101 -0
  67. package/dist/bundle/chunks/openai-codex-responses-IT7VEKUU.js +10 -0
  68. package/dist/bundle/chunks/openai-codex.js +101 -0
  69. package/dist/bundle/chunks/openai-completions-LOKIW33V.js +7 -0
  70. package/dist/bundle/chunks/openai-decisions-4F3LWHMG.js +5 -0
  71. package/dist/bundle/chunks/openai-responses-OK36GJXP.js +3 -0
  72. package/dist/bundle/chunks/openrouter-images-ZI7LLZ4Y.js +2 -0
  73. package/dist/bundle/chunks/openrouter.js +101 -0
  74. package/dist/bundle/chunks/radius.js +101 -0
  75. package/dist/bundle/chunks/runtime-RMPIV5AR.js +2 -0
  76. package/dist/bundle/chunks/src-ETRMT73D.js +4 -0
  77. package/dist/bundle/chunks/typesafe-system-one-J2CJBWEH.js +2 -0
  78. package/dist/bundle/chunks/virtual-modules-EGJP3AJA.js +2 -0
  79. package/dist/bundle/chunks/xai.js +2 -0
  80. package/dist/bundle/cli-runtime.js +3 -0
  81. package/dist/bundle/cli.js +5 -0
  82. package/dist/bundle/native/darwin/prebuilds/darwin-arm64/darwin-platform.node +0 -0
  83. package/dist/bundle/native/darwin/prebuilds/darwin-x64/darwin-platform.node +0 -0
  84. package/dist/bundle/native/linux/prebuilds/linux-arm64/linux-platform-x11.node +0 -0
  85. package/dist/bundle/native/linux/prebuilds/linux-x64/linux-platform-x11.node +0 -0
  86. package/dist/bundle/native/win32/prebuilds/win32-arm64/win32-platform.node +0 -0
  87. package/dist/bundle/native/win32/prebuilds/win32-x64/win32-platform.node +0 -0
  88. package/dist/core/export-html/template.css +1015 -0
  89. package/dist/core/export-html/template.html +55 -0
  90. package/dist/core/export-html/template.js +1929 -0
  91. package/dist/core/export-html/vendor/highlight.min.js +1213 -0
  92. package/dist/core/export-html/vendor/marked.min.js +78 -0
  93. package/dist/modes/interactive/theme/dark.json +74 -0
  94. package/dist/modes/interactive/theme/light.json +74 -0
  95. package/dist/modes/interactive/theme/system-theme.ts +579 -0
  96. package/dist/modes/interactive/theme/theme-controller.ts +253 -0
  97. package/dist/modes/interactive/theme/theme-schema.ts +145 -0
  98. package/dist/modes/interactive/theme/theme-tokens.ts +145 -0
  99. package/dist/modes/interactive/theme/theme.ts +1076 -0
  100. package/docs/app-server.md +479 -0
  101. package/docs/app-server.schema.json +8128 -0
  102. package/docs/cli-integration.md +106 -0
  103. package/docs/cli.md +393 -0
  104. package/docs/codemode.md +230 -0
  105. package/docs/compaction.md +463 -0
  106. package/docs/configuration.md +48 -0
  107. package/docs/containerization.md +143 -0
  108. package/docs/custom-provider.md +173 -0
  109. package/docs/desktop.md +73 -0
  110. package/docs/docs.json +236 -0
  111. package/docs/environment-variables.md +138 -0
  112. package/docs/extensions.md +314 -0
  113. package/docs/how-knightcode-works.md +49 -0
  114. package/docs/images/doom-extension.png +0 -0
  115. package/docs/images/interactive-mode.png +0 -0
  116. package/docs/images/tree-view.png +0 -0
  117. package/docs/index.md +39 -0
  118. package/docs/json.md +226 -0
  119. package/docs/keybindings.md +197 -0
  120. package/docs/llama-cpp.md +121 -0
  121. package/docs/mcp.md +272 -0
  122. package/docs/message-types.md +279 -0
  123. package/docs/models-configuration.md +187 -0
  124. package/docs/models.md +221 -0
  125. package/docs/nvidia-rtx-llama-cpp.md +96 -0
  126. package/docs/packages.md +129 -0
  127. package/docs/plan-mode.md +121 -0
  128. package/docs/prompt-templates.md +59 -0
  129. package/docs/providers.md +282 -0
  130. package/docs/quickstart.md +128 -0
  131. package/docs/remote.md +87 -0
  132. package/docs/rpc-commands.md +860 -0
  133. package/docs/rpc-extension-ui.md +214 -0
  134. package/docs/rpc.md +193 -0
  135. package/docs/sdk.md +197 -0
  136. package/docs/security.md +99 -0
  137. package/docs/session-format.md +358 -0
  138. package/docs/sessions.md +135 -0
  139. package/docs/settings.md +220 -0
  140. package/docs/shell-aliases.md +93 -0
  141. package/docs/skills.md +93 -0
  142. package/docs/slash-commands.md +78 -0
  143. package/docs/terminal-setup.md +242 -0
  144. package/docs/termux.md +117 -0
  145. package/docs/themes.md +140 -0
  146. package/docs/tmux.md +55 -0
  147. package/docs/tui.md +125 -0
  148. package/docs/usage.md +167 -0
  149. package/docs/virtual-models.md +114 -0
  150. package/docs/windows.md +67 -0
  151. package/examples/README.md +36 -0
  152. package/examples/extensions/README.md +214 -0
  153. package/examples/extensions/auto-commit-on-exit.ts +55 -0
  154. package/examples/extensions/bash-spawn-hook.ts +30 -0
  155. package/examples/extensions/bookmark.ts +50 -0
  156. package/examples/extensions/border-status-editor.ts +151 -0
  157. package/examples/extensions/built-in-tool-renderer.ts +225 -0
  158. package/examples/extensions/claude-rules.ts +89 -0
  159. package/examples/extensions/commands.ts +72 -0
  160. package/examples/extensions/confirm-destructive.ts +60 -0
  161. package/examples/extensions/custom-compaction.ts +118 -0
  162. package/examples/extensions/custom-footer.ts +66 -0
  163. package/examples/extensions/custom-header.ts +73 -0
  164. package/examples/extensions/custom-provider-anthropic/index.ts +617 -0
  165. package/examples/extensions/custom-provider-anthropic/package-lock.json +24 -0
  166. package/examples/extensions/custom-provider-anthropic/package.json +19 -0
  167. package/examples/extensions/custom-provider-gitlab-duo/index.ts +399 -0
  168. package/examples/extensions/custom-provider-gitlab-duo/package.json +16 -0
  169. package/examples/extensions/custom-provider-gitlab-duo/test.ts +82 -0
  170. package/examples/extensions/debug-provider.ts +90 -0
  171. package/examples/extensions/dirty-repo-guard.ts +56 -0
  172. package/examples/extensions/doom-overlay/README.md +46 -0
  173. package/examples/extensions/doom-overlay/doom/build.sh +152 -0
  174. package/examples/extensions/doom-overlay/doom/doomgeneric_knightcode.c +72 -0
  175. package/examples/extensions/doom-overlay/doom-component.ts +132 -0
  176. package/examples/extensions/doom-overlay/doom-engine.ts +173 -0
  177. package/examples/extensions/doom-overlay/doom-keys.ts +104 -0
  178. package/examples/extensions/doom-overlay/index.ts +74 -0
  179. package/examples/extensions/doom-overlay/wad-finder.ts +55 -0
  180. package/examples/extensions/dynamic-resources/SKILL.md +8 -0
  181. package/examples/extensions/dynamic-resources/dynamic.json +75 -0
  182. package/examples/extensions/dynamic-resources/dynamic.md +5 -0
  183. package/examples/extensions/dynamic-resources/index.ts +15 -0
  184. package/examples/extensions/dynamic-tools.ts +74 -0
  185. package/examples/extensions/entry-renderer.ts +41 -0
  186. package/examples/extensions/event-bus.ts +43 -0
  187. package/examples/extensions/file-trigger.ts +41 -0
  188. package/examples/extensions/git-checkpoint.ts +53 -0
  189. package/examples/extensions/git-merge-and-resolve.ts +115 -0
  190. package/examples/extensions/github-issue-autocomplete.ts +185 -0
  191. package/examples/extensions/gondolin/index.ts +531 -0
  192. package/examples/extensions/gondolin/package-lock.json +185 -0
  193. package/examples/extensions/gondolin/package.json +19 -0
  194. package/examples/extensions/handoff.ts +190 -0
  195. package/examples/extensions/hello.ts +26 -0
  196. package/examples/extensions/hidden-thinking-label.ts +53 -0
  197. package/examples/extensions/inline-bash.ts +94 -0
  198. package/examples/extensions/input-transform-streaming.ts +39 -0
  199. package/examples/extensions/input-transform.ts +43 -0
  200. package/examples/extensions/interactive-shell.ts +196 -0
  201. package/examples/extensions/jev-router.ts +113 -0
  202. package/examples/extensions/mac-system-theme.ts +47 -0
  203. package/examples/extensions/message-renderer.ts +59 -0
  204. package/examples/extensions/minimal-mode.ts +353 -0
  205. package/examples/extensions/modal-editor.ts +85 -0
  206. package/examples/extensions/model-status.ts +31 -0
  207. package/examples/extensions/notify.ts +57 -0
  208. package/examples/extensions/overlay-qa-tests.ts +1450 -0
  209. package/examples/extensions/overlay-test.ts +153 -0
  210. package/examples/extensions/permission-gate.ts +34 -0
  211. package/examples/extensions/pirate.ts +47 -0
  212. package/examples/extensions/plan-mode/README.md +66 -0
  213. package/examples/extensions/plan-mode/index.ts +387 -0
  214. package/examples/extensions/plan-mode/utils.ts +168 -0
  215. package/examples/extensions/preset.ts +436 -0
  216. package/examples/extensions/project-trust.ts +64 -0
  217. package/examples/extensions/prompt-customizer.ts +49 -0
  218. package/examples/extensions/protected-paths.ts +30 -0
  219. package/examples/extensions/provider-payload.ts +18 -0
  220. package/examples/extensions/qna.ts +118 -0
  221. package/examples/extensions/question.ts +278 -0
  222. package/examples/extensions/questionnaire.ts +440 -0
  223. package/examples/extensions/rainbow-editor.ts +88 -0
  224. package/examples/extensions/reload-runtime.ts +37 -0
  225. package/examples/extensions/rpc-demo.ts +118 -0
  226. package/examples/extensions/sandbox/index.ts +321 -0
  227. package/examples/extensions/sandbox/package-lock.json +92 -0
  228. package/examples/extensions/sandbox/package.json +19 -0
  229. package/examples/extensions/send-user-message.ts +97 -0
  230. package/examples/extensions/session-name.ts +27 -0
  231. package/examples/extensions/shutdown-command.ts +63 -0
  232. package/examples/extensions/snake.ts +343 -0
  233. package/examples/extensions/space-invaders.ts +560 -0
  234. package/examples/extensions/ssh.ts +220 -0
  235. package/examples/extensions/status-line.ts +32 -0
  236. package/examples/extensions/structured-output.ts +65 -0
  237. package/examples/extensions/subagent/README.md +177 -0
  238. package/examples/extensions/subagent/agents/planner.md +37 -0
  239. package/examples/extensions/subagent/agents/reviewer.md +35 -0
  240. package/examples/extensions/subagent/agents/scout.md +50 -0
  241. package/examples/extensions/subagent/agents/worker.md +24 -0
  242. package/examples/extensions/subagent/agents.ts +157 -0
  243. package/examples/extensions/subagent/index.ts +1010 -0
  244. package/examples/extensions/subagent/prompts/implement-and-review.md +10 -0
  245. package/examples/extensions/subagent/prompts/implement.md +10 -0
  246. package/examples/extensions/subagent/prompts/scout-and-plan.md +9 -0
  247. package/examples/extensions/summarize.ts +199 -0
  248. package/examples/extensions/system-prompt-header.ts +17 -0
  249. package/examples/extensions/tic-tac-toe.ts +1004 -0
  250. package/examples/extensions/timed-confirm.ts +70 -0
  251. package/examples/extensions/titlebar-spinner.ts +58 -0
  252. package/examples/extensions/todo.ts +294 -0
  253. package/examples/extensions/tool-override.ts +144 -0
  254. package/examples/extensions/tools.ts +146 -0
  255. package/examples/extensions/trigger-compact.ts +50 -0
  256. package/examples/extensions/truncated-tool.ts +195 -0
  257. package/examples/extensions/widget-placement.ts +9 -0
  258. package/examples/extensions/with-deps/index.ts +32 -0
  259. package/examples/extensions/with-deps/package-lock.json +31 -0
  260. package/examples/extensions/with-deps/package.json +22 -0
  261. package/examples/extensions/working-indicator.ts +121 -0
  262. package/examples/extensions/working-message-test.ts +25 -0
  263. package/examples/rpc-client.ts +35 -0
  264. package/examples/rpc-extension-ui.ts +661 -0
  265. package/examples/sdk/01-minimal.ts +26 -0
  266. package/examples/sdk/02-custom-model.ts +49 -0
  267. package/examples/sdk/03-custom-prompt.ts +70 -0
  268. package/examples/sdk/04-skills.ts +55 -0
  269. package/examples/sdk/05-tools.ts +48 -0
  270. package/examples/sdk/06-extensions.ts +94 -0
  271. package/examples/sdk/07-context-files.ts +42 -0
  272. package/examples/sdk/08-prompt-templates.ts +51 -0
  273. package/examples/sdk/09-api-keys-and-oauth.ts +34 -0
  274. package/examples/sdk/10-settings.ts +53 -0
  275. package/examples/sdk/11-sessions.ts +52 -0
  276. package/examples/sdk/12-full-control.ts +74 -0
  277. package/examples/sdk/13-session-runtime.ts +67 -0
  278. package/examples/sdk/14-codemode-mcp.ts +61 -0
  279. package/examples/sdk/README.md +141 -0
  280. package/package.json +15 -15
  281. package/bin/knightcode +0 -62
package/docs/tui.md ADDED
@@ -0,0 +1,125 @@
1
+ # Terminal UI
2
+
3
+ `@knightcode/tui` provides the terminal component system used by KnightCode. Extensions use it when built-in dialogs, notifications, status text, and widgets are not enough for the interaction they need.
4
+
5
+ Start with `ctx.ui` methods from an [extension](extensions.md#interact-with-the-user). Build a custom component only when the UI needs its own rendering, keyboard or mouse input, focus, layout, or lifecycle.
6
+
7
+ ## Choose an integration point
8
+
9
+ | Need | Use |
10
+ |---|---|
11
+ | Select, confirm, input, or multi-line editor | `ctx.ui.select()`, `confirm()`, `input()`, or `editor()` |
12
+ | Non-blocking feedback | `ctx.ui.notify()` or `setStatus()` |
13
+ | Persistent content near the editor | `ctx.ui.setWidget()` |
14
+ | Replace the header, footer, or editor | The corresponding `ctx.ui` component factory |
15
+ | Temporary interactive screen or overlay | `ctx.ui.custom()` |
16
+ | Custom rendering for a tool or session entry | An extension renderer |
17
+
18
+ These APIs receive KnightCode’s active theme and keybindings where needed. Do not create a second terminal renderer inside an extension.
19
+
20
+ ## Understand the component model
21
+
22
+ A component renders an array of terminal lines for an available width. It can optionally handle keyboard and mouse input, and it must invalidate cached output when its state or theme-dependent content changes.
23
+
24
+ Every rendered line must fit within the supplied width. Measure visible terminal columns rather than string length because ANSI escapes, wide characters, emoji, and combining characters change display width.
25
+
26
+ Use `visibleWidth()`, `truncateToWidth()`, `sliceByColumn()`, and `wrapTextWithAnsi()` instead of implementing terminal-width handling yourself. KnightCode resets styling and hyperlinks after every line, so reapply styles on each rendered line.
27
+
28
+ After changing component state, invalidate the affected component and call the injected `tui.requestRender()`. The TUI coalesces render requests and updates the terminal.
29
+
30
+ ## Compose built-in components
31
+
32
+ The package includes components for common layouts and controls:
33
+
34
+ - `Text`, `Markdown`, `Image`, and `TruncatedText` render content.
35
+ - `Container`, `VStack`, `HStack`, `Box`, and `Spacer` compose layouts.
36
+ - `Input` and `Editor` accept text.
37
+ - `SelectList` and `SettingsList` implement searchable selection and settings flows.
38
+ - `ScrollView` provides a bounded scrollable viewport.
39
+ - `Loader` and `CancellableLoader` report ongoing work.
40
+ - `MouseRegion` adds pointer behavior around another component.
41
+
42
+ Prefer these components over rebuilding selection, scrolling, text editing, or width handling. The extension examples show how to combine them with KnightCode’s borders and themes.
43
+
44
+ ## Handle keyboard input and focus
45
+
46
+ Use `matchesKey()` and `Key` for terminal keyboard input. The parser accounts for supported terminal protocols and key modifiers. Extension components should use the injected `KeybindingsManager` for configurable application actions.
47
+
48
+ A component that displays a text cursor should implement `Focusable` and place `CURSOR_MARKER` immediately before its visual cursor. Wrap the cursor cell in `renderFakeCursor()` so the TUI draws it in reverse video, or hides it after `CURSOR_MARKER` when the hardware cursor is shown. The TUI uses the marker to position the hardware cursor for input method editors.
49
+
50
+ Containers that wrap an `Input` or `Editor` must propagate their `focused` state to that child. Without propagation, Chinese, Japanese, Korean, and other IME candidate windows can appear at the wrong screen position.
51
+
52
+ Extend KnightCode’s `CustomEditor` when replacing the main editor. It preserves application shortcuts and agent controls.
53
+
54
+ Forward keys your editor does not own to the base implementation, and restore the default by clearing the custom editor factory.
55
+
56
+ ## Handle mouse input
57
+
58
+ Fullscreen mode routes normalized mouse events to components. A handler can mark an event handled, capture a drag sequence, request focus, or request a render.
59
+
60
+ Unhandled wheel events scroll the nearest `ScrollView`. Unhandled primary-button drags remain available for transcript selection. OSC 8 links take precedence over enclosing click regions.
61
+
62
+ Regular mode leaves mouse input to the terminal because the terminal owns scrollback. Design every interaction with a keyboard path even when fullscreen mouse input is available.
63
+
64
+ ## Use custom screens and overlays
65
+
66
+ `ctx.ui.custom()` temporarily gives one component control of the interactive area and resolves when that component calls the supplied completion callback.
67
+
68
+ Pass `overlay: true` to draw above existing content. Overlay options control size, anchors, offsets, margins, and responsive visibility. An overlay handle can change focus or temporarily hide and show the overlay with `setHidden()` while the interaction remains active.
69
+
70
+ Focused overlays retain input ownership across ordinary renders. If another component should receive input while an overlay remains visible, explicitly release or redirect focus through the handle.
71
+
72
+ Treat each custom component instance as belonging to one interaction. Create a new instance when starting that interaction again.
73
+
74
+ Finish the interaction with the completion callback supplied to the component factory. It resolves the `ctx.ui.custom()` promise and disposes the component. Do not call `OverlayHandle.hide()` on an overlay created by `ctx.ui.custom()`.
75
+
76
+ See [`overlay-qa-tests.ts`](../examples/extensions/overlay-qa-tests.ts) for positioning, stacking, focus, responsive visibility, and animation behavior.
77
+
78
+ ## Apply themes correctly
79
+
80
+ Use the theme passed to the extension or component callback. Theme helpers produce ANSI-styled strings for semantic colors such as accent, muted text, success, warnings, errors, tool output, and Markdown.
81
+
82
+ Use `theme.style()` to combine foreground and background colors with text attributes:
83
+
84
+ ```typescript
85
+ return new Text(
86
+ theme.style("Done!", {
87
+ fg: "success",
88
+ bg: "toolSuccessBg",
89
+ bold: true,
90
+ }),
91
+ 0,
92
+ 0,
93
+ );
94
+ ```
95
+
96
+ A style color can be a semantic theme token or a concrete `Color`. Foreground tokens are accepted as `fg` and background tokens as `bg`; to use a token's color in the other position, pass its concrete color, for example `{ fg: theme.colors.userMessageBg }`. Access concrete colors through `theme.colors` and use utilities such as `mixColors()` from `@knightcode/tui` when color math is needed. Tokens that a theme sets to the terminal default render with the terminal's own color; `theme.colors` reports the color the terminal announced for them, or a guess when it did not. Use `theme.appearance` (`"dark"` or `"light"`) to decide, for example, whether to lighten or darken a color. KnightCode converts the result to truecolor or 256-color output based on terminal capabilities. Theme tokens are converted once per theme; compute concrete colors outside the render path when possible.
97
+
98
+ The existing `theme.fg()` and `theme.bg()` helpers remain available for applying one semantic color.
99
+
100
+ Do not permanently store strings with theme colors unless `invalidate()` rebuilds them. A theme change clears render caches, but it cannot remove old ANSI colors embedded in application state.
101
+
102
+ Theme callbacks evaluated during rendering do not need special rebuilding. Stateless components can also calculate themed output on every render.
103
+
104
+ Use [Themes](themes.md) to create terminal palettes. Use KnightCode’s `getMarkdownTheme()` when rendering Markdown that should match the active application theme.
105
+
106
+ ## Keep rendering responsive
107
+
108
+ Rendering runs on the interactive path. Cache expensive layout and highlighting work by width and content, then clear that cache from `invalidate()`.
109
+
110
+ Keep the default view compact and reveal detail through expansion or a dedicated screen. For custom tool rendering, handle partial results and reuse the previous component when it can be updated safely.
111
+
112
+ Use `KNIGHTCODE_TUI_WRITE_LOG` to capture the raw ANSI stream when diagnosing rendering problems. Test narrow widths, wide characters, resize events, theme changes, focus transitions, and both regular and fullscreen modes.
113
+
114
+ ## Examples and source
115
+
116
+ The checked extension examples cover the main patterns:
117
+
118
+ - [`preset.ts`](../examples/extensions/preset.ts) and [`tools.ts`](../examples/extensions/tools.ts) use selection and settings lists.
119
+ - [`qna.ts`](../examples/extensions/qna.ts) uses cancellable asynchronous UI.
120
+ - [`modal-editor.ts`](../examples/extensions/modal-editor.ts) replaces the editor.
121
+ - [`custom-footer.ts`](../examples/extensions/custom-footer.ts) replaces the footer.
122
+ - [`widget-placement.ts`](../examples/extensions/widget-placement.ts) places persistent content around the editor.
123
+ - [`doom-overlay/`](../examples/extensions/doom-overlay/) demonstrates a continuously rendered overlay.
124
+
125
+ The public exports are defined in [`packages/tui/src/index.ts`](https://github.com/KnightCodeAI/knightcode/blob/main/packages/tui/src/index.ts). See [Extensions](extensions.md) for extension lifecycle, state, tools, events, and mode behavior.
package/docs/usage.md ADDED
@@ -0,0 +1,167 @@
1
+ # Use KnightCode in the terminal
2
+
3
+ Run `knightcode` from the folder you want to work in. KnightCode uses that folder to discover files, instructions, and configuration, and to group saved sessions. If you have not installed KnightCode or chosen a model yet, follow the [Quickstart](quickstart.md).
4
+
5
+ KnightCode may ask whether you trust the working folder before loading its project resources. See [Project trust](security.md#understand-project-trust).
6
+
7
+ <p align="center"><img src="images/interactive-mode.png" alt="KnightCode interactive mode showing a conversation, editor, and status information" width="750"></p>
8
+
9
+ The transcript shows your prompts, KnightCode's responses, tool calls, results, and errors. You write prompts and commands in the editor. The footer shows the current folder and session, the model and thinking level, context usage, accumulated cost,
10
+ the latest output speed, and the git branch with its changed files and pull request.
11
+
12
+ ## Enter a prompt
13
+
14
+ Type a request and press `Enter` to send it. Use `Shift+Enter` to add a line, or press `Ctrl+G` to work on a longer prompt in your configured external editor.
15
+
16
+ To include files or images:
17
+
18
+ - Type `@` to search for a file and add it to your prompt.
19
+ - Press `Tab` to complete a path.
20
+ - Paste an image or drag it into a compatible terminal.
21
+
22
+ ## Follow KnightCode's work
23
+
24
+ KnightCode shows each tool call and result while it works. Press `Ctrl+O` to expand or collapse tool output. Press `Ctrl+T` to show or hide thinking blocks.
25
+
26
+ The startup header shows the version, folder, and main keys, and KnightCode lists the instructions and resources it
27
+ loaded below it. In a truecolor terminal the knight in the header shimmers once at startup, then holds still; the
28
+ shimmer stops early if the header scrolls away. The editor frame keeps one color at every thinking level;
29
+ the footer shows the current level. Shell input (`!` or `!!`) keeps a distinct frame color. The
30
+ header, editor frame, and footer come from the built-in `ui` extension; set `"extensions": ["-builtin:ui"]` in
31
+ [settings](settings.md#resources) for the plain layout. The footer updates as the model uses context and reports usage.
32
+
33
+ KnightCode does not ask before every tool call. Review commands and changed files, and use a sandbox for untrusted or unattended work. See [Security](security.md).
34
+
35
+ ## Change direction
36
+
37
+ You can send more input while KnightCode is working:
38
+
39
+ | What you want | Action |
40
+ |---|---|
41
+ | Adjust the current task | Type a message and press `Enter` |
42
+ | Add work after the current task | Type a message and press `Alt+Enter` |
43
+ | Return queued messages to the editor | Press `Alt+Up` |
44
+ | Stop the current task | Press `Escape` |
45
+
46
+ A message sent with `Enter` waits until the current response and its tool calls finish, then guides the next response. A follow-up sent with `Alt+Enter` waits until KnightCode finishes the current task. Aborting returns queued messages to the editor.
47
+
48
+ Windows Terminal reserves some Alt shortcuts. See [Terminal Setup](terminal-setup.md) for the Windows alternatives.
49
+
50
+ ## Change the model or settings
51
+
52
+ Type `/` to search the available commands. The commands you will use most often are:
53
+
54
+ - `/model` selects a model. Press `Ctrl+L` to open the same selector.
55
+ - `/thinking` selects how much reasoning the current model uses. Press `Shift+Tab` to cycle through supported levels.
56
+ - `/login` and `/logout` manage provider access.
57
+ - `/settings` changes common preferences.
58
+ - `/tools` turns the [web tools](#web-tools), [questions](#questions), the [scratchpad](#scratchpad), and the [classifier gate](#classifier-gate) off, on for this session, or on by default.
59
+
60
+ Prompt templates, skills, and extensions can add more commands to the same menu. See [Choose a Model](models.md), [Configuration](configuration.md), or the complete [Slash Commands reference](slash-commands.md).
61
+
62
+ ## Continue or start over
63
+
64
+ KnightCode saves sessions automatically unless session persistence is disabled.
65
+
66
+ - `/new` starts a new session.
67
+ - `/resume` opens another saved session.
68
+ - `/name` gives the current session a recognizable name.
69
+ - `/session` shows its file, ID, message count, token usage, and cost.
70
+ - `/undo` goes back to an earlier user message and can restore the files edited after it.
71
+
72
+ Use `/tree`, `/fork`, or `/clone` when you want to explore another approach without losing existing work. Use `/compact` to reduce the conversation history sent to the model. See [Sessions and Context](sessions.md) for these workflows.
73
+
74
+ After leaving KnightCode, run `knightcode --continue` from the same folder to resume its most recent session.
75
+
76
+ ## Run a terminal command
77
+
78
+ Prefix a command with `!` to run it and include its output in the conversation:
79
+
80
+ ```text
81
+ !git status
82
+ ```
83
+
84
+ Use `!!` when you want to run a command without sending its output to the model.
85
+
86
+ ## Web Tools
87
+
88
+ Two tools give the agent read access to the web. Both ship disabled; turn them on with `/tools`.
89
+
90
+ | Tool | What it does |
91
+ |------|--------------|
92
+ | `webfetch` | Fetches a URL and returns the page as markdown, 400 lines at a time. The agent pages with `offset`/`limit` like `read`, or passes `grep` to get only matching lines. Responses are cached for 15 minutes, capped at 5 MB, and time out after 30 seconds. Private, loopback, and link-local addresses are refused. |
93
+ | `websearch` | Searches the web and returns up to 10 results (default 5) as title, URL, and snippet. DuckDuckGo needs no key but may rate-limit; Brave Search needs an API key. |
94
+
95
+ `/tools` lists each tool with its current state; pick one to open its settings panel. **Status** cycles through three states:
96
+
97
+ | State | Effect |
98
+ |-------|--------|
99
+ | Disabled | The tool is not offered to the model |
100
+ | Enabled for this session | On until knightcode exits, including across `/new`, `/resume`, and `/fork`; nothing is written to disk |
101
+ | Enabled by default | On in every session |
102
+
103
+ The `websearch` panel adds two rows: **Provider** (`duckduckgo` or `brave`) and **Brave API key**. Choosing Brave without a stored key opens the key prompt at once. Get a key at https://brave.com/search/api/; the free plan is enough. The key is also read from `BRAVE_API_KEY` when none is stored, but the provider only switches to Brave when you pick it. Keys show masked in the panel.
104
+
105
+ The same changes work without the panel:
106
+
107
+ ```bash
108
+ /tools websearch on # this session
109
+ /tools webfetch always # every session
110
+ /tools webfetch off
111
+ ```
112
+
113
+ Settings are stored in `~/.knightcode/agent/tools.json`, owner-readable only because it can hold the Brave key. `--tools` and `--exclude-tools` still apply: a tool excluded on the command line stays off whatever `/tools` says, and a tool named in `--tools` or `defaultTools` is on for that session unless you turned it off with `/tools`.
114
+
115
+ Fetched pages and search results are marked as untrusted in the tool output so the model treats instructions inside them as data, but treat the tools like any other network access: a fetched page can still influence what the agent does next.
116
+
117
+ ## Questions
118
+
119
+ `/tools ask_user on` lets the agent ask you one to three multiple-choice questions and wait for your answers, instead of guessing at intent or trade-offs it cannot settle from the code. The recommended option comes first.
120
+
121
+ | Key | In the question picker |
122
+ |-----|------------------------|
123
+ | `Up`/`Down` | Choose an option |
124
+ | `Enter` | Answer and go to the next question; on the last one, submit |
125
+ | `Tab` | Add a note to the chosen option |
126
+ | `Left`/`Right` | Move between questions |
127
+ | `Esc` | Close the note or text field; otherwise interrupt the turn |
128
+
129
+ The last row, **None of the above**, opens a field for your own answer. Submitting with questions left unanswered asks first, and **Go back** returns to the first one. The keys are the `tui.select.*`, `tui.input.tab` and `tui.input.submit` [keybindings](keybindings.md) (`tui.input.submit` is `Enter` in the note and answer fields), so remapping them changes the picker too.
130
+
131
+ In RPC mode the questions arrive as `select` and `input` dialogs, one per question, without notes. In a run with no one to ask, such as print and JSON modes, the tool answers at once and the agent takes the recommended options and states them as assumptions.
132
+
133
+ `ask_user` is off by default. When on, its declaration adds about 230 tokens to each request. Plan mode turns it on while planning.
134
+
135
+ ## Scratchpad
136
+
137
+ `/tools scratchpad on` gives each session a private working directory under the system temp directory (`<tmp>/knightcode-<uid>/scratchpad/<session-id>`, or `<tmp>\knightcode\scratchpad\<session-id>` on Windows). The system prompt names it and asks the agent to put throwaway scripts and intermediate output there instead of in your project.
138
+
139
+ The agent keeps its working notes there in `notes.md`: task list, decisions, `file:line` facts, next steps. After each compaction the first 8 KB of `notes.md` is put back into the context once, so those notes outlive the summary. Open the file to see what the agent is tracking.
140
+
141
+ The scratchpad is off by default. When on, it adds about 60 tokens to the system prompt, which is cached; the notes cost tokens only after a compaction. It is not a tool, so `--tools` and `--exclude-tools` do not affect it. `/fork` starts a new, empty directory, and the operating system clears old ones with the rest of its temp files. If `<tmp>/knightcode-<uid>` already exists but is not a private directory you own, as when another user on a shared machine created it first, the scratchpad stays off and KnightCode reports why.
142
+
143
+ ## Classifier gate
144
+
145
+ `/tools classifier-gate` asks a classifier model whether each `bash`, `powershell`, `write`, or `edit` call could cause harm that is hard to undo: deleting data beyond the task, exposing secrets, changing system configuration, or publishing to a remote service. A call rated risky (probability 0.5 or higher) asks for confirmation; in print and JSON modes it is blocked.
146
+
147
+ Pick the model in the panel's **Model** row. It lists classifier models from providers you are logged in to, such as TypeSafe Jev through OpenRouter. The gate fails closed: a call runs without asking only when the classifier scores the whole call below 0.5. With no model set, when the classifier errors or returns no answer, or when the call's input is over 4,000 characters (as a large `write` often is), the call asks for confirmation or is blocked. Interrupting the turn closes the confirmation.
148
+
149
+ The gate is off by default. Each gated call is one classifier request, billed by its provider, and adds its latency before the tool runs.
150
+
151
+ ## Copy, export, or share results
152
+
153
+ Press `Ctrl+X` or run `/copy` to copy the last assistant response. Use `/export` to save the session as HTML or JSONL.
154
+
155
+ Use `/share` to upload the session and get a viewer link. By default, Radius authentication makes the artifact visible to your Radius organization; otherwise, KnightCode creates a private GitHub gist through the GitHub CLI. The [`sessionShareDestination`](settings.md#sessions-and-context) setting can force either destination. Review the session first because it can contain prompts, tool output, file contents, and credentials exposed during the conversation.
156
+
157
+ ## Adjust the terminal
158
+
159
+ Fullscreen mode, the default, keeps the editor and status area fixed while the transcript scrolls within the terminal window. Regular mode uses the terminal's normal scrollback. Choose a mode through `/settings` or `--tui-mode`.
160
+
161
+ Terminal support for mouse input, keyboard shortcuts, and inline images varies. See [Terminal Setup](terminal-setup.md) for platform-specific configuration and [Keybindings](keybindings.md) for every configurable shortcut. Run `/hotkeys` to inspect the shortcuts active in your current session.
162
+
163
+ ## Collect diagnostic information
164
+
165
+ When troubleshooting terminal rendering or conversation state, run `/debug`. KnightCode writes the rendered terminal lines and current session messages to `knightcode-debug.log` in your [agent directory](configuration.md#agent-directory).
166
+
167
+ Review this file before sharing it. It can contain prompts, model responses, tool output, file contents, and terminal data.
@@ -0,0 +1,114 @@
1
+ # Virtual Models
2
+
3
+ A virtual model is a selectable model that picks a physical model for each request. Use one to route by task, cost, or conversation state. For example, a router can send quick questions to a small model and hard problems to a large one, while the user selects a single model.
4
+
5
+ Register virtual models from an [extension](extensions.md). They appear in `/model`, `--model`, scoped models, and settings like any other model. A virtual model can be listed under any provider, including one with physical models, such as `openai-codex/auto`.
6
+
7
+ ## Selection and dispatch
8
+
9
+ A virtual model selects a model and a thinking level. A router maps that pair to a physical pair for each request:
10
+
11
+ ```
12
+ selected (virtual model, virtual level) -> dispatched (physical model, physical level)
13
+ jev/auto:low -> anthropic/claude-sonnet-4-5:high
14
+ ```
15
+
16
+ The virtual thinking level is an input to the router. Its meaning is up to the router; it need not correspond to a reasoning budget.
17
+
18
+ KnightCode keeps the two pairs apart:
19
+
20
+ | | Selection | Dispatch |
21
+ |---|---|---|
22
+ | Recorded in | `model_change` and `thinking_level_change` entries | Each assistant message: `provider`, `api`, `model`, `thinkingLevel` |
23
+ | Visible as | `ctx.model`, `ctx.thinkingLevel`, `KNIGHTCODE_MODEL`, `KNIGHTCODE_REASONING_LEVEL`, `/model` | The assistant message of each response |
24
+
25
+ Providers only receive physical models. Assistant messages name the physical model, so replaying a conversation across different physical models works the same as after a manual model switch. Resuming a session restores the virtual selection from its latest `model_change` entry. If the virtual model is no longer registered, KnightCode falls back to the physical model that answered last.
26
+
27
+ In interactive mode, the footer shows the routed model next to the selection, for example `auto • high → gpt-5.6-luna • medium`. `/session` lists the cost for each physical model.
28
+
29
+ Context usage uses the limits of the physical model that produced the latest response, even if that response came before switching to the virtual model. Without such a response, it uses the limits declared on the virtual model, if any. Compaction checks the same limits, and again the limits of the model each request is routed to. If that model's context window is too small for the conversation, KnightCode compacts before sending the request; the route stays as the router chose it.
30
+
31
+ ## Register a virtual model
32
+
33
+ ```typescript
34
+ import type { ExtensionAPI } from "@knightcodeai/cli";
35
+
36
+ export default function (knightcode: ExtensionAPI) {
37
+ knightcode.registerVirtualModel({
38
+ provider: "router",
39
+ id: "auto",
40
+ name: "Auto",
41
+ thinkingLevels: ["low", "high"],
42
+ route(request, ctx) {
43
+ // Tool follow-ups and retries stay on the model that handled the turn.
44
+ const sticky = request.failed ?? request.previous;
45
+ if (request.reason !== "user" && sticky) {
46
+ return { model: sticky.model, thinkingLevel: sticky.thinkingLevel ?? "medium" };
47
+ }
48
+ const id = request.thinkingLevel === "high" ? "claude-sonnet-4-5" : "claude-haiku-4-5";
49
+ return { model: ctx.modelRegistry.find("anthropic", id)!, thinkingLevel: "medium" };
50
+ },
51
+ });
52
+ }
53
+ ```
54
+
55
+ - `provider` is the provider the model is listed under. It can be any provider ID. A provider can list several virtual models next to its physical ones. On a physical provider, the virtual model is available when that provider has credentials. Under an ID that no provider uses, it is always available.
56
+ - `id` must not be the ID of a physical model of that provider. If a catalog refresh later adds a physical model with the same ID, the virtual model hides it.
57
+ - `thinkingLevels` lists the levels offered for selection. It defaults to `["off"]`.
58
+ - `contextWindow` and `maxTokens` are shown before the first response. Unset limits are unknown.
59
+ - `input` lists the input types offered for selection. It defaults to text and images; physical models without image support receive placeholders.
60
+
61
+ Registration follows the same queuing and reload rules as `knightcode.registerProvider()`. Registering the same provider and ID again replaces the virtual model. `knightcode.unregisterVirtualModel(provider, id)` removes it; `knightcode.unregisterProvider()` does not. SDK code can register one without an extension: `modelRuntime.registerVirtualModel(definition)`.
62
+
63
+ ## Route requests
64
+
65
+ `route(request, ctx)` runs before every request made with the virtual model and returns `{ model, thinkingLevel }`. The model can be any physical model in the catalog whose provider has credentials; look it up with `ctx.modelRegistry`. A virtual model cannot route to another virtual model. KnightCode clamps the thinking level to the returned model.
66
+
67
+ | Field | Meaning |
68
+ |---|---|
69
+ | `model`, `thinkingLevel` | The selected virtual model and level |
70
+ | `reason` | Why the request is made, see below |
71
+ | `previous` | Physical model and thinking level of the latest successful response in `messages` |
72
+ | `failed` | For `retry`: physical model, thinking level, and assistant `message` of the failed request, which `messages` no longer contains. The message carries `stopReason` and `errorMessage`. Absent when routing itself failed |
73
+ | `state` | Router state last returned on this session branch, see below |
74
+ | `messages` | The conversation for this request, including system messages |
75
+ | `signal` | Abort signal of the request |
76
+
77
+ | `reason` | Request |
78
+ |---|---|
79
+ | `user` | First request after a message the user wrote, including steering and follow-up messages |
80
+ | `continuation` | Any other request in the agent loop, such as after tool results or extension messages |
81
+ | `retry` | Automatic retry after a failed request, including after compaction for a context overflow |
82
+ | `direct` | Request made outside the agent loop, such as a compaction summary or an extension calling `ctx.modelRegistry.streamSimple()` |
83
+
84
+ Returning `previous` for `continuation` and `failed` for `retry` keeps prompt caches and thinking signatures valid. Switching models between turns is allowed but loses the prompt cache. A retry can also switch to another model, for example when `failed.message.errorMessage` reports that a provider is overloaded or the context overflowed.
85
+
86
+ If `route()` throws, or returns a virtual model or a model without credentials, the request ends with an error response.
87
+
88
+ ## Keep routing state
89
+
90
+ `route()` can return `state` next to the model. KnightCode stores it on the session branch and passes it back as `request.state` on later requests. Use it for decisions the transcript does not record, such as classifier results or a routing phase:
91
+
92
+ ```typescript
93
+ knightcode.registerVirtualModel<{ phase: "plan" | "build" }>({
94
+ provider: "router",
95
+ id: "phased",
96
+ name: "Phased",
97
+ route(request, ctx) {
98
+ const state = request.state ?? { phase: "plan" };
99
+ const id = state.phase === "plan" ? "claude-opus-4-5" : "claude-haiku-4-5";
100
+ return { model: ctx.modelRegistry.find("anthropic", id)!, thinkingLevel: "medium", state };
101
+ },
102
+ });
103
+ ```
104
+
105
+ - State must be JSON-serializable. Returning `undefined` or `request.state` itself keeps the current state.
106
+ - KnightCode stores any other returned object as new state, before the request is sent, even when it equals the current state. Return a new object only when the state changes. The state stays stored if the request later fails.
107
+ - State follows the session tree, so forks and `/tree` navigation see the state of their branch. It survives compaction.
108
+ - `direct` requests have no state, and KnightCode ignores state they return.
109
+
110
+ The transcript already records the selection and every dispatched model, and `ctx.sessionManager.getBranch()` exposes both.
111
+
112
+ Routers can call other models through `ctx.modelRegistry`, for example `ctx.modelRegistry.classify()` with a classifier model from `ctx.modelRegistry.findOfType("classifier", provider, id)`. The call adds latency before the first token of the turn.
113
+
114
+ See [`jev-router.ts`](../examples/extensions/jev-router.ts) for a complete router. It plans on a strong OpenAI Codex model chosen by the Jev classifier, lets that model make the first edit, and then switches once to a cheaper model, accepting a single prompt-cache miss. It keeps the phase as router state.
@@ -0,0 +1,67 @@
1
+ # Run KnightCode on Windows
2
+
3
+ Run KnightCode either as a native Windows process or inside Windows Subsystem for Linux (WSL). Native Windows uses Git Bash by default for Bash commands and can optionally expose PowerShell to the model. KnightCode inside WSL uses the Linux environment and its Bash installation.
4
+
5
+ Follow the main [Quickstart](quickstart.md) to install and authenticate KnightCode. Use this page to choose and configure its command environment.
6
+
7
+ ## Choose native Windows or WSL
8
+
9
+ | Environment | Command environment | Use it when |
10
+ |---|---|---|
11
+ | Native Windows with Git Bash | Git Bash for the built-in `bash` tool and `!` commands | Your files and development tools primarily live on Windows |
12
+ | Native Windows with the `powershell` tool | PowerShell for model tool calls; Bash remains available for `!` commands | The task depends on PowerShell modules or Windows-native commands |
13
+ | WSL | Linux Bash and tools inside the selected WSL distribution | Your files and toolchain already live in Linux or WSL |
14
+
15
+ ## Use Git Bash on native Windows
16
+
17
+ For most native Windows users, installing [Git for Windows](https://git-scm.com/download/win) is sufficient.
18
+
19
+ KnightCode resolves Bash in this order:
20
+
21
+ 1. `shellPath` from `~/.knightcode/agent/settings.json`
22
+ 2. Git Bash under `Program Files` or `Program Files (x86)`
23
+ 3. `bash.exe` on `PATH`, including Cygwin, MSYS2, or legacy WSL Bash
24
+
25
+ Start KnightCode and enter this command to verify the shell:
26
+
27
+ ```text
28
+ !printf 'Bash is working\n'
29
+ ```
30
+
31
+ If KnightCode cannot find Bash, it reports the locations it checked. Install Git for Windows, put another Bash executable on `PATH`, or configure `shellPath`.
32
+
33
+ ## Let the model use PowerShell
34
+
35
+ The optional `powershell` tool runs commands through `pwsh.exe` when available, then falls back to Windows PowerShell. It starts PowerShell with `-NoProfile -NonInteractive -ExecutionPolicy Bypass`. Administrator-enforced execution policies can still take precedence.
36
+
37
+ To replace the model-facing `bash` tool with `powershell`, add this to `~/.knightcode/agent/settings.json`:
38
+
39
+ ```json
40
+ {
41
+ "defaultTools": ["read", "powershell", "edit", "write"]
42
+ }
43
+ ```
44
+
45
+ `["-bash", "+powershell"]` does the same while keeping any other default tools you configured.
46
+
47
+ Restart KnightCode, then ask it to run a harmless PowerShell command. The `!` and `!!` editor commands continue to use Bash. The `powershell` tool is available only when KnightCode runs as a native Windows process.
48
+
49
+ See [Settings](settings.md#tools) for other tool combinations.
50
+
51
+ ## Use a custom Bash executable
52
+
53
+ Set `shellPath` when Bash is installed somewhere KnightCode does not discover automatically:
54
+
55
+ ```json
56
+ {
57
+ "shellPath": "C:\\cygwin64\\bin\\bash.exe"
58
+ }
59
+ ```
60
+
61
+ JSON uses backslashes for escape sequences. When you write a Windows path with backslashes, write each backslash twice, as shown above.
62
+
63
+ See [Configure shell commands](shell-aliases.md) for command prefixes, aliases, and the complete shell-resolution behavior.
64
+
65
+ ## Configure Windows Terminal
66
+
67
+ Windows Terminal reserves or rewrites some modified keys. See [Windows Terminal](terminal-setup.md#windows-terminal) to configure `Shift+Enter` and `Alt+Enter`, and [Keybindings](keybindings.md) for KnightCode's Windows and WSL shortcut defaults.
@@ -0,0 +1,36 @@
1
+ # Examples
2
+
3
+ Example code for the @knightcodeai/cli SDK, process integration, and extensions.
4
+
5
+ ## CLI integration
6
+
7
+ [`rpc-client.ts`](rpc-client.ts) uses the typed `RpcClient` to run KnightCode in a child process, stream events, and wait for the run to settle.
8
+
9
+ Build the CLI package before running it from a repository checkout:
10
+
11
+ ```bash
12
+ node examples/rpc-client.ts "Explain this repository"
13
+ ```
14
+
15
+ ## Directories
16
+
17
+ ### [sdk/](sdk/)
18
+ Programmatic usage via `createAgentSession()`. Shows how to customize models, prompts, tools, extensions, and session management.
19
+
20
+ ### [extensions/](extensions/)
21
+ Example extensions demonstrating:
22
+ - Lifecycle event handlers (tool interception, safety gates, context modifications)
23
+ - Custom tools (todo lists, questions, subagents, output truncation)
24
+ - Commands and keyboard shortcuts
25
+ - Custom UI (footers, headers, editors, overlays)
26
+ - Git integration (checkpoints, auto-commit)
27
+ - System prompt modifications and custom compaction
28
+ - External integrations (SSH, file watchers, system theme sync)
29
+ - Custom providers (Anthropic with custom streaming, GitLab Duo)
30
+
31
+ ## Documentation
32
+
33
+ - [SDK Examples](sdk/README.md)
34
+ - [CLI Integration](../docs/cli-integration.md)
35
+ - [Extensions Documentation](../docs/extensions.md)
36
+ - [Skills Documentation](../docs/skills.md)