@knightcodeai/cli-linux-arm64 0.9.1 → 0.9.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/bin/CHANGELOG.md +60 -0
  2. package/bin/README.md +52 -19
  3. package/bin/docs/cli-integration.md +106 -0
  4. package/bin/docs/cli.md +270 -0
  5. package/bin/docs/compaction.md +56 -37
  6. package/bin/docs/configuration.md +46 -0
  7. package/bin/docs/containerization.md +86 -54
  8. package/bin/docs/custom-provider.md +132 -785
  9. package/bin/docs/docs.json +143 -103
  10. package/bin/docs/environment-variables.md +5 -4
  11. package/bin/docs/extensions.md +134 -2956
  12. package/bin/docs/how-knightcode-works.md +49 -0
  13. package/bin/docs/index.md +24 -69
  14. package/bin/docs/json.md +193 -65
  15. package/bin/docs/keybindings.md +56 -101
  16. package/bin/docs/llama-cpp.md +3 -3
  17. package/bin/docs/message-types.md +261 -0
  18. package/bin/docs/models.md +64 -547
  19. package/bin/docs/packages.md +66 -167
  20. package/bin/docs/prompt-templates.md +31 -68
  21. package/bin/docs/providers.md +103 -241
  22. package/bin/docs/quickstart.md +61 -106
  23. package/bin/docs/rpc-commands.md +854 -0
  24. package/bin/docs/rpc-extension-ui.md +200 -0
  25. package/bin/docs/rpc.md +129 -1556
  26. package/bin/docs/sdk.md +76 -1160
  27. package/bin/docs/security.md +70 -32
  28. package/bin/docs/session-format.md +25 -216
  29. package/bin/docs/sessions.md +38 -143
  30. package/bin/docs/settings.md +111 -389
  31. package/bin/docs/shell-aliases.md +85 -5
  32. package/bin/docs/skills.md +51 -189
  33. package/bin/docs/slash-commands.md +63 -0
  34. package/bin/docs/terminal-setup.md +107 -79
  35. package/bin/docs/termux.md +74 -83
  36. package/bin/docs/themes.md +68 -280
  37. package/bin/docs/tmux.md +31 -39
  38. package/bin/docs/tui.md +69 -923
  39. package/bin/docs/usage.md +79 -286
  40. package/bin/docs/windows.md +43 -17
  41. package/bin/export-html/template.js +6 -1
  42. package/bin/knightcode +2 -2
  43. package/bin/package.json +6 -6
  44. package/package.json +1 -1
  45. package/bin/docs/development.md +0 -71
@@ -1,13 +1,13 @@
1
- # Compaction & Branch Summarization
1
+ # Compaction Reference
2
2
 
3
- LLMs have limited context windows. When conversations grow too long, KnightCode uses compaction to summarize older content while preserving recent work. This page covers both auto-compaction and branch summarization.
3
+ This reference describes automatic compaction, branch summarization, persisted entries, and extension hooks. For the user workflow, see [Sessions and Context](sessions.md#manage-conversation-context).
4
4
 
5
5
  **Source files** ([knightcode](https://github.com/KnightCodeAI/knightcode)):
6
- - [`packages/coding-agent/src/core/compaction/compaction.ts`](https://github.com/KnightCodeAI/knightcode/blob/main/packages/coding-agent/src/core/compaction/compaction.ts) - Auto-compaction logic
7
- - [`packages/coding-agent/src/core/compaction/branch-summarization.ts`](https://github.com/KnightCodeAI/knightcode/blob/main/packages/coding-agent/src/core/compaction/branch-summarization.ts) - Branch summarization
8
- - [`packages/coding-agent/src/core/compaction/utils.ts`](https://github.com/KnightCodeAI/knightcode/blob/main/packages/coding-agent/src/core/compaction/utils.ts) - Shared utilities (file tracking, serialization)
9
- - [`packages/coding-agent/src/core/session-manager.ts`](https://github.com/KnightCodeAI/knightcode/blob/main/packages/coding-agent/src/core/session-manager.ts) - Entry types (`CompactionEntry`, `BranchSummaryEntry`)
10
- - [`packages/coding-agent/src/core/extensions/types.ts`](https://github.com/KnightCodeAI/knightcode/blob/main/packages/coding-agent/src/core/extensions/types.ts) - Extension event types
6
+ - [`packages/cli/src/core/compaction/compaction.ts`](https://github.com/KnightCodeAI/knightcode/blob/main/packages/cli/src/core/compaction/compaction.ts) - Auto-compaction logic
7
+ - [`packages/cli/src/core/compaction/branch-summarization.ts`](https://github.com/KnightCodeAI/knightcode/blob/main/packages/cli/src/core/compaction/branch-summarization.ts) - Branch summarization
8
+ - [`packages/cli/src/core/compaction/utils.ts`](https://github.com/KnightCodeAI/knightcode/blob/main/packages/cli/src/core/compaction/utils.ts) - Shared utilities (file tracking, serialization)
9
+ - [`packages/cli/src/core/session-manager.ts`](https://github.com/KnightCodeAI/knightcode/blob/main/packages/cli/src/core/session-manager.ts) - Entry types (`CompactionEntry`, `BranchSummaryEntry`)
10
+ - [`packages/cli/src/core/extensions/types.ts`](https://github.com/KnightCodeAI/knightcode/blob/main/packages/cli/src/core/extensions/types.ts) - Extension event types
11
11
 
12
12
  For TypeScript definitions in your project, inspect `node_modules/@knightcodeai/cli/dist/`.
13
13
 
@@ -20,7 +20,7 @@ KnightCode has two summarization mechanisms:
20
20
  | Compaction | Context exceeds threshold, or `/compact` | Summarize old messages to free up context |
21
21
  | Branch summarization | `/tree` navigation | Preserve context when switching branches |
22
22
 
23
- Both use the same structured summary format and track file operations cumulatively. Compaction and branch-summary requests use fresh routing session IDs and, where supported by the provider, disable prompt-cache writes because these one-off prompts are unlikely to be reused.
23
+ Both use closely related structured formats and track file operations cumulatively. Summarization requests disable prompt-cache writes because these one-off prompts are unlikely to be reused.
24
24
 
25
25
  ## Compaction
26
26
 
@@ -34,14 +34,16 @@ contextTokens > contextWindow - reserveTokens
34
34
 
35
35
  By default, `reserveTokens` is 16384 tokens (configurable in `~/.knightcode/agent/settings.json` or `<project-dir>/.knightcode/settings.json`). This leaves room for the LLM's response.
36
36
 
37
- During a multi-turn agent run, KnightCode checks this threshold after tools finish and their results are appended, before starting the next assistant response. If the threshold is crossed, KnightCode compacts inside the same agent run and resumes with the summary and retained messages. It skips this between-turn check when the completed tool batch terminates the run and no queued message requires another response. KnightCode also checks the threshold before a new user prompt and after a low-level agent run ends.
37
+ During a multi-turn agent run, KnightCode checks the canonical projected context after tools finish and their results are appended, before starting the next assistant response. If the threshold is crossed, KnightCode compacts during `prepareNextTurn`, then performs the existing catch-up steering poll before `turn_start`. It skips this between-turn check when the completed tool batch terminates the run and no queued message requires another response. KnightCode also checks before a new user prompt and performs final-attempt overflow recovery after the low-level run ends.
38
+
39
+ A provider context-overflow error or an early final `stopReason: "length"` can select one compact-and-retry recovery attempt. Length responses with tool calls retain their synthetic failed tool results and follow the ordinary tool/queue scheduler rather than forcing the run to end.
38
40
 
39
41
  You can also trigger manually with `/compact [instructions]`, where optional instructions focus the summary.
40
42
 
41
43
  ### How It Works
42
44
 
43
- 1. **Find cut point**: Walk backwards from newest message, accumulating token estimates until `keepRecentTokens` (default 20k, configurable in `~/.knightcode/agent/settings.json` or `<project-dir>/.knightcode/settings.json`) is reached
44
- 2. **Extract messages**: Collect messages from the previous kept boundary (or session start) up to the cut point
45
+ 1. **Find cut point**: Walk backwards through the finalized session projection, accumulating token estimates until `keepRecentTokens` (default 20k, configurable in `~/.knightcode/agent/settings.json` or `<project-dir>/.knightcode/settings.json`) is reached
46
+ 2. **Extract messages**: Collect projected messages from the previous kept boundary (or session start) up to the cut point
45
47
  3. **Generate summary**: Call LLM to summarize with structured format, passing the previous summary as iterative context when present
46
48
  4. **Append entry**: Save `CompactionEntry` with summary and `firstKeptEntryId`
47
49
  5. **Rebuilds context**: Session rebuilds the context for the next request, using summary + messages from `firstKeptEntryId` onwards
@@ -78,16 +80,31 @@ What the LLM sees:
78
80
  prompt from cmp messages from firstKeptEntryId
79
81
  ```
80
82
 
81
- On repeated compactions, the summarized span starts at the previous compaction's kept boundary (`firstKeptEntryId`), not at the compaction entry itself, falling back to the entry after the previous compaction if that kept entry cannot be found in the path. This preserves messages that survived the earlier compaction by including them in the next summarization pass as well. KnightCode also recalculates `tokensBefore` from the rebuilt session context before writing the new `CompactionEntry`, so the token count reflects the actual pre-compaction context being replaced.
83
+ On repeated compactions, the summarized span starts at the previous compaction's kept boundary (`firstKeptEntryId`), not at the compaction entry itself, falling back to the entry after the previous compaction if that kept entry cannot be found in the path. A retain-none compaction records its own ID as `firstKeptEntryId`; repeated compaction starts after that entry. This preserves messages that survived the earlier compaction by including them in the next summarization pass as well. KnightCode also recalculates `tokensBefore` from the rebuilt, context-edited session projection before writing the new `CompactionEntry`, so the token count reflects the actual pre-compaction context being replaced. Omitted raw entries remain stored but do not affect cut selection, summaries, checkpoints, or token estimates.
84
+
85
+ ### Overflow and Length Recovery Ordering
86
+
87
+ Recovery preserves the existing lifecycle and queue order. The completed attempt remains visible to `turn_end` and `agent_end`; post-run recovery then repairs persisted model context before a fresh retry:
88
+
89
+ ```text
90
+ persist final assistant response
91
+ → extension/public turn_end
92
+ → extension/public agent_end
93
+ → append context_edit omissions for the selected attempt
94
+ → for overflow/length: run session_before_compact and append compaction on success
95
+ → start the retry as a fresh run
96
+ ```
97
+
98
+ If recovery compaction fails or is cancelled, KnightCode keeps the omission edits, appends no compaction, and schedules no internal retry. Existing queued work remains governed by ordinary steering and follow-up rules. `agent_before_settle` sees the repaired projection after recovery processing. Raw transcript history, exports, billing totals, and history-search extensions can still inspect the omitted attempt.
82
99
 
83
- ### Split Turns
100
+ ### Split user-message spans
84
101
 
85
- A "turn" starts with a user message and includes all assistant responses and tool calls until the next user message. Normally, compaction cuts at turn boundaries.
102
+ A user-message span starts with a user message and includes all turns until the next user message. Normally, compaction cuts at user-message boundaries.
86
103
 
87
- When a single turn exceeds `keepRecentTokens`, the cut point lands mid-turn at an assistant message. This is a "split turn":
104
+ When one user-message span exceeds `keepRecentTokens`, the cut point lands within that span at an assistant message. This is a split user-message span:
88
105
 
89
106
  ```
90
- Split turn (one huge turn exceeds budget):
107
+ Split user-message span (one span exceeds budget):
91
108
 
92
109
  entry: 0 1 2 3 4 5 6 7 8
93
110
  ┌─────┬─────┬─────┬──────┬─────┬──────┬──────┬─────┬──────┐
@@ -100,13 +117,13 @@ Split turn (one huge turn exceeds budget):
100
117
  └── kept (7-8)
101
118
 
102
119
  isSplitTurn = true
103
- messagesToSummarize = [] (no complete turns before)
120
+ messagesToSummarize = [] (no earlier user-message spans)
104
121
  turnPrefixMessages = [usr, ass, tool, ass, tool, tool]
105
122
  ```
106
123
 
107
- For split turns, KnightCode generates two summaries and merges them:
124
+ For split user-message spans, KnightCode generates two summaries and merges them:
108
125
  1. **History summary**: Previous context (if any)
109
- 2. **Turn prefix summary**: The early part of the split turn
126
+ 2. **User-message-span prefix summary**: The early part of the split user-message span
110
127
 
111
128
  ### Cut Point Rules
112
129
 
@@ -118,16 +135,18 @@ Valid cut points are:
118
135
 
119
136
  Never cut at tool results (they must stay with their tool call).
120
137
 
138
+ Preparation advances the kept boundary into a context-invisible suffix only when that suffix contains an omitted assistant attempt and no unomitted context-producing entries. Recovery `context_edit` omissions satisfy this rule; intrinsically context-invisible metadata may coexist with them. Metadata alone and newly appended custom messages do not move the cut. A replacement edit affecting the candidate input or summarized prefix also blocks advancement because the omitted assistant answered the pre-edit input; replacements of suffix entries that are ultimately omitted remain safe. This allows an over-budget recovered input to be summarized while retaining the edits that keep the abandoned attempt omitted, without making bookkeeping change whether new model input is preserved verbatim.
139
+
121
140
  ### CompactionEntry Structure
122
141
 
123
- Defined in [`session-manager.ts`](https://github.com/KnightCodeAI/knightcode/blob/main/packages/coding-agent/src/core/session-manager.ts):
142
+ Defined in [`session-manager.ts`](https://github.com/KnightCodeAI/knightcode/blob/main/packages/cli/src/core/session-manager.ts):
124
143
 
125
144
  ```typescript
126
145
  interface CompactionEntry<T = unknown> {
127
146
  type: "compaction";
128
147
  id: string;
129
- parentId: string;
130
- timestamp: number;
148
+ parentId: string | null;
149
+ timestamp: string;
131
150
  summary: string;
132
151
  firstKeptEntryId: string;
133
152
  tokensBefore: number;
@@ -145,7 +164,7 @@ interface CompactionDetails {
145
164
 
146
165
  Extensions can store any JSON-serializable data in `details`. The default compaction tracks file operations, but custom extension implementations can use their own structure. Generated and extension-provided summaries store their LLM `usage` when available so session totals include summarization work.
147
166
 
148
- See [`prepareCompaction()`](https://github.com/KnightCodeAI/knightcode/blob/main/packages/coding-agent/src/core/compaction/compaction.ts) and [`compact()`](https://github.com/KnightCodeAI/knightcode/blob/main/packages/coding-agent/src/core/compaction/compaction.ts) for the implementation. For direct programmatic summarization, `generateSummary()` returns the summary text and `generateSummaryWithUsage()` returns `{ text, usage }`.
167
+ See [`prepareCompaction()`](https://github.com/KnightCodeAI/knightcode/blob/main/packages/cli/src/core/compaction/compaction.ts) and [`compact()`](https://github.com/KnightCodeAI/knightcode/blob/main/packages/cli/src/core/compaction/compaction.ts) for the implementation. For direct programmatic summarization, `generateSummary()` returns the summary text and `generateSummaryWithUsage()` returns `{ text, usage }`.
149
168
 
150
169
  ## Branch Summarization
151
170
 
@@ -180,22 +199,20 @@ After navigation with summary:
180
199
 
181
200
  ### Cumulative File Tracking
182
201
 
183
- Both compaction and branch summarization track files cumulatively. When generating a summary, knightcode extracts file operations from:
184
- - Tool calls in the messages being summarized
185
- - Previous compaction or branch summary `details` (if any)
202
+ Default compaction and branch summarization track files cumulatively. Both extract file operations from tool calls in the messages being summarized. Compaction also carries file lists from the previous KnightCode-generated compaction. Branch summarization carries file lists from KnightCode-generated branch summaries in the entries it summarizes.
186
203
 
187
- This means file tracking accumulates across multiple compactions or nested branch summaries, preserving the full history of read and modified files.
204
+ File tracking therefore accumulates across default compactions and nested default branch summaries. KnightCode does not automatically carry file lists from extension-generated summaries whose `fromHook` field is `true`; extensions manage their own `details` format.
188
205
 
189
206
  ### BranchSummaryEntry Structure
190
207
 
191
- Defined in [`session-manager.ts`](https://github.com/KnightCodeAI/knightcode/blob/main/packages/coding-agent/src/core/session-manager.ts):
208
+ Defined in [`session-manager.ts`](https://github.com/KnightCodeAI/knightcode/blob/main/packages/cli/src/core/session-manager.ts):
192
209
 
193
210
  ```typescript
194
211
  interface BranchSummaryEntry<T = unknown> {
195
212
  type: "branch_summary";
196
213
  id: string;
197
- parentId: string;
198
- timestamp: number;
214
+ parentId: string | null;
215
+ timestamp: string;
199
216
  summary: string;
200
217
  fromId: string; // Entry we navigated from
201
218
  usage?: Usage; // LLM usage that generated the summary
@@ -212,11 +229,13 @@ interface BranchSummaryDetails {
212
229
 
213
230
  Same as compaction, extensions can store custom data in `details`.
214
231
 
215
- See [`collectEntriesForBranchSummary()`](https://github.com/KnightCodeAI/knightcode/blob/main/packages/coding-agent/src/core/compaction/branch-summarization.ts), [`prepareBranchEntries()`](https://github.com/KnightCodeAI/knightcode/blob/main/packages/coding-agent/src/core/compaction/branch-summarization.ts), and [`generateBranchSummary()`](https://github.com/KnightCodeAI/knightcode/blob/main/packages/coding-agent/src/core/compaction/branch-summarization.ts) for the implementation.
232
+ See [`collectEntriesForBranchSummary()`](https://github.com/KnightCodeAI/knightcode/blob/main/packages/cli/src/core/compaction/branch-summarization.ts), [`prepareBranchEntries()`](https://github.com/KnightCodeAI/knightcode/blob/main/packages/cli/src/core/compaction/branch-summarization.ts), and [`generateBranchSummary()`](https://github.com/KnightCodeAI/knightcode/blob/main/packages/cli/src/core/compaction/branch-summarization.ts) for the implementation.
216
233
 
217
234
  ## Summary Format
218
235
 
219
- Both compaction and branch summarization use the same structured format:
236
+ Both formats include Goal, Constraints & Preferences, Progress, Key Decisions, and Next Steps. Compaction summaries also include Critical Context. Branch summaries stop after Next Steps. KnightCode appends file lists to either format when relevant.
237
+
238
+ Compaction summaries use this format:
220
239
 
221
240
  ```markdown
222
241
  ## Goal
@@ -256,7 +275,7 @@ path/to/changed.ts
256
275
 
257
276
  ### Message Serialization
258
277
 
259
- Before summarization, messages are serialized to text via [`serializeConversation()`](https://github.com/KnightCodeAI/knightcode/blob/main/packages/coding-agent/src/core/compaction/utils.ts):
278
+ Before summarization, messages are serialized to text via [`serializeConversation()`](https://github.com/KnightCodeAI/knightcode/blob/main/packages/cli/src/core/compaction/utils.ts):
260
279
 
261
280
  ```
262
281
  [User]: What they said
@@ -272,7 +291,7 @@ Tool results are truncated to 2000 characters during serialization. Content beyo
272
291
 
273
292
  ## Custom Summarization via Extensions
274
293
 
275
- Extensions can intercept and customize both compaction and branch summarization. See [`extensions/types.ts`](https://github.com/KnightCodeAI/knightcode/blob/main/packages/coding-agent/src/core/extensions/types.ts) for event type definitions.
294
+ Extensions can intercept and customize both compaction and branch summarization. See [`extensions/types.ts`](https://github.com/KnightCodeAI/knightcode/blob/main/packages/cli/src/core/extensions/types.ts) for event type definitions.
276
295
 
277
296
  ### session_before_compact
278
297
 
@@ -283,7 +302,7 @@ knightcode.on("session_before_compact", async (event, ctx) => {
283
302
  const { preparation, branchEntries, customInstructions, reason, willRetry, signal } = event;
284
303
 
285
304
  // preparation.messagesToSummarize - messages to summarize
286
- // preparation.turnPrefixMessages - split turn prefix (if isSplitTurn)
305
+ // preparation.turnPrefixMessages - user-message-span prefix (if isSplitTurn)
287
306
  // preparation.previousSummary - previous compaction summary
288
307
  // preparation.fileOps - extracted file operations
289
308
  // preparation.tokensBefore - context tokens before compaction
@@ -357,7 +376,7 @@ knightcode.on("session_compact_failed", async (event, ctx) => {
357
376
  const { reason, errorMessage, aborted, willRetry, fromExtension } = event;
358
377
  // reason - "manual" (/compact), "threshold", or "overflow"
359
378
  // errorMessage - present for non-abort failures
360
- // aborted - true for cancelled/aborted compactions
379
+ // aborted - true for canceled/aborted compactions
361
380
  // willRetry - whether the aborted turn would have retried after compaction
362
381
  // fromExtension - whether extension-provided compaction content was being used
363
382
  });
@@ -441,4 +460,4 @@ Keys are exact, case-sensitive `provider/modelId` values, including any slashes
441
460
 
442
461
  These resolved values are used for manual compaction, all automatic threshold checks, overflow recovery, and extension-visible `preparation.settings`. Model switches affect subsequent checks and compactions without changing ordinary settings. Compaction already in progress uses the model and settings captured for that operation. Branch summarization settings are unaffected.
443
462
 
444
- Overrides work in both global and project settings. The files merge recursively before lookup, so a global model-specific value beats a project-wide fallback; a project must override that model entry to change it. See [settings.md](settings.md#per-model-compaction-overrides) for details.
463
+ Overrides work in both global and project settings. The files merge recursively before lookup, so a global model-specific value beats a project-wide fallback; a project must override that model entry to change it. See [Settings](settings.md#per-model-compaction-overrides) for details.
@@ -0,0 +1,46 @@
1
+ # Configuration
2
+
3
+ KnightCode supports user-level and project configuration. User-level configuration lives in the agent directory, which defaults to `~/.knightcode/agent`. Project configuration lives in `.knightcode` under the working directory and loads after [project trust](security.md#understand-project-trust) is granted. The only exception is `sessionDir`, which KnightCode reads before resolving trust so it can locate sessions.
4
+
5
+ In interactive mode, use `/settings` to change common preferences. For other options, ask KnightCode to update the configuration or edit the relevant files directly. Run `/reload` after manually changing settings, keybindings, instructions, or resources.
6
+
7
+ ## Agent directory
8
+
9
+ The agent directory is shown as `<agent-dir>` below. Set its location with the `KNIGHTCODE_CODING_AGENT_DIR` environment variable or the SDK's [`agentDir`](sdk.md) option.
10
+
11
+ | Path | Responsibility |
12
+ |---|---|
13
+ | `<agent-dir>/settings.json` | User-level [settings](settings.md), including preferences, defaults, resource paths, and KnightCode package declarations. |
14
+ | `<agent-dir>/keybindings.json` | Custom terminal UI and application [keybindings](keybindings.md). |
15
+ | `<agent-dir>/models.json` | [Compatible endpoints, models, and model overrides](models.md#configure-a-compatible-endpoint). |
16
+ | `<agent-dir>/auth.json` | Saved API keys and OAuth credentials. |
17
+ | `<agent-dir>/tools.json` | [Web tool](usage.md#web-tools) and scratchpad settings written by `/tools`, including the Brave Search key. |
18
+ | `<agent-dir>/AGENTS.override.md`, `AGENTS.md`, `AGENTS.MD`, `CLAUDE.md`, or `CLAUDE.MD` | User instructions applied across working directories. |
19
+ | `<agent-dir>/SYSTEM.md` | Replaces KnightCode’s default system prompt. |
20
+ | `<agent-dir>/APPEND_SYSTEM.md` | Adds instructions to KnightCode’s system prompt. |
21
+ | `<agent-dir>/extensions/` | User [extensions](extensions.md). |
22
+ | `<agent-dir>/skills/` | User [skills](skills.md) and supporting files. |
23
+ | `<agent-dir>/prompts/` | User [prompt templates](prompt-templates.md) exposed as slash commands. |
24
+ | `<agent-dir>/themes/` | User [theme](themes.md) files. |
25
+
26
+ ## Project `.knightcode` directory
27
+
28
+ | Path | Responsibility |
29
+ |---|---|
30
+ | `.knightcode/settings.json` | Project-level [settings](settings.md), resource paths, and KnightCode package declarations. |
31
+ | `.knightcode/SYSTEM.md` | Replaces the system prompt for the project. |
32
+ | `.knightcode/APPEND_SYSTEM.md` | Adds project-specific instructions to the system prompt. |
33
+ | `.knightcode/extensions/` | Project extensions. |
34
+ | `.knightcode/skills/` | Project skills and supporting files. |
35
+ | `.knightcode/prompts/` | Project prompt templates exposed as slash commands. |
36
+ | `.knightcode/themes/` | Project theme files. |
37
+
38
+ For `SYSTEM.md` and `APPEND_SYSTEM.md`, the trusted project file takes precedence over the corresponding agent-directory file. Files with the same name are not combined.
39
+
40
+ ## Context files
41
+
42
+ Context files are separate from project `.knightcode` configuration. KnightCode loads them from the agent directory, the working directory, and its parent directories. A context file applies whenever KnightCode runs in its directory or anywhere below it.
43
+
44
+ An `AGENTS.override.md` replaces `AGENTS.md` or `CLAUDE.md` only in the same directory. It does not suppress context files from the agent directory or other directories.
45
+
46
+ Context-file discovery does not require project trust.
@@ -1,52 +1,38 @@
1
- # Containerization
1
+ # Run KnightCode in an isolated environment
2
2
 
3
- KnightCode runs with all permissions by default, but in some cases, you will want to have more control over what directories KnightCode can write to and which accesses it has.
3
+ Use an isolated environment to limit the files, credentials, processes, and network services that generated commands can access or affect.
4
4
 
5
- There are two general options. You can either
6
- 1. run the whole `knightcode` process inside an isolated environment, or
7
- 2. run `knightcode` on the host and route tool execution into an isolated environment.
5
+ You can isolate the complete KnightCode process or keep KnightCode on the host and route selected tools into an isolated environment.
8
6
 
9
- ## Choose a pattern
7
+ ## Choose an isolation method
10
8
 
11
- | Pattern | What is isolated | Best for | Notes |
12
- | --- | --- | --- | --- |
13
- | Gondolin extension | Built-in tools and `!` commands | Local micro-VM isolation while keeping auth on host | See [`examples/extensions/gondolin/`](../examples/extensions/gondolin/). |
14
- | Plain Docker | Whole `knightcode` process in a local container | Simple local isolation | Provider API keys enter the container. |
15
- | OpenShell | Whole `knightcode` process in a policy-controlled sandbox | Local or remote managed sandbox | Requires an OpenShell gateway |
9
+ | Method | Where KnightCode runs | What is isolated | Credential handling | Best for |
10
+ |---|---|---|---|---|
11
+ | Plain Docker | Container | KnightCode, built-in tools, `!` commands, and extensions | Credentials passed into the container | A straightforward local container boundary |
12
+ | OpenShell | Local or remote sandbox | KnightCode, built-in tools, `!` commands, and extensions | Policy-controlled credentials and inference routing | Filesystem, process, network, and credential policies |
13
+ | Gondolin extension | Host | Built-in tools and `!` commands | Stored KnightCode credentials remain on the host, but commands inherit host environment variables | A local micro-VM for tool execution while retaining the host interface |
16
14
 
17
- Extensions run wherever the `knightcode` process runs. If you run host `knightcode` with a tool-routing extension, other custom extension tools still run on the host unless they also delegate their operations.
15
+ The method changes where extensions run. When the complete KnightCode process runs inside an isolated environment, its extensions run there too. When host KnightCode delegates built-in tools through Gondolin, other extension tools still run on the host unless they also delegate their work.
18
16
 
19
- ## Gondolin
17
+ ## Decide what KnightCode can access
20
18
 
21
- [Gondolin](https://github.com/KnightCodeAI/gondolin) is a local Linux micro-VM.
22
- Use the [example extension](../examples/extensions/gondolin) when you want `knightcode` on the host but all built-in tools routed into the VM.
19
+ An isolated process can still affect resources you expose to it:
23
20
 
24
- Setup:
21
+ - A read-write host mount lets KnightCode modify those host files.
22
+ - Mounting `~/.knightcode/agent` exposes your KnightCode credentials, settings, extensions, and sessions.
23
+ - Environment variables passed into a container are available to processes inside it.
24
+ - Network access may allow code or tool output to leave the environment.
25
+ - Tool-only isolation does not constrain the host KnightCode process or extension tools that do not use the isolated backend.
25
26
 
26
- ```bash
27
- cp -R packages/coding-agent/examples/extensions/gondolin ~/.knightcode/agent/extensions/gondolin
28
- cd ~/.knightcode/agent/extensions/gondolin
29
- npm install --ignore-scripts
30
- ```
31
-
32
- Run from the project you want mounted:
33
-
34
- ```bash
35
- cd /path/to/project
36
- knightcode -e ~/.knightcode/agent/extensions/gondolin
37
- ```
38
-
39
- The extension mounts the host cwd at `/workspace` in the VM and overrides `read`, `write`, `edit`, `bash`, `grep`, `find`, and `ls`.
40
- User `!` commands are routed into the VM, as well.
41
- File changes under `/workspace` write through to the host.
27
+ Expose only the working folder, credentials, and network destinations needed for the task. Use read-only mounts or copy files into and out of the environment when you do not want writes to affect the host.
42
28
 
43
- Requirements: Node.js >= 23.6.0 for `@KnightCodeAI/gondolin`, plus QEMU (requires installation through your package manager).
29
+ ## Run KnightCode in plain Docker
44
30
 
45
- ## Plain Docker
31
+ Plain Docker provides the simplest whole-process container boundary.
46
32
 
47
- Run the whole `knightcode` process in Docker when you want the simplest local container boundary.
33
+ ### Build the image
48
34
 
49
- `Dockerfile.knightcode`:
35
+ Create `Dockerfile.knightcode`:
50
36
 
51
37
  ```dockerfile
52
38
  FROM node:24-bookworm-slim
@@ -60,11 +46,17 @@ WORKDIR /workspace
60
46
  ENTRYPOINT ["knightcode"]
61
47
  ```
62
48
 
63
- Build and run:
49
+ Build it from the directory containing the file:
64
50
 
65
51
  ```bash
66
52
  docker build -t knightcode-sandbox -f Dockerfile.knightcode .
53
+ ```
54
+
55
+ ### Start KnightCode
56
+
57
+ From the working folder you want KnightCode to access, run:
67
58
 
59
+ ```bash
68
60
  docker run --rm -it \
69
61
  -e ANTHROPIC_API_KEY \
70
62
  -v "$PWD:/workspace" \
@@ -72,40 +64,80 @@ docker run --rm -it \
72
64
  knightcode-sandbox
73
65
  ```
74
66
 
75
- The `-v "$PWD:/workspace"` mounts your current directory into the container at /workspace such that reads and writes in `/workspace` inside Docker directly affect your host files, like in the Gondolin example.
67
+ Replace `ANTHROPIC_API_KEY` with the credential required by your provider. The named `knightcode-agent-home` volume keeps container-local settings, credentials, and sessions between runs.
68
+
69
+ Do not mount the host's `~/.knightcode/agent` unless the container should have access to your host KnightCode configuration and credentials.
70
+
71
+ ### Verify the workspace
72
+
73
+ Inside KnightCode, run:
74
+
75
+ ```text
76
+ !pwd
77
+ ```
78
+
79
+ The command should report `/workspace`. Changes under `/workspace` write through to the mounted host folder. Remove the bind mount or use a read-only mount when that is not acceptable.
76
80
 
77
- Use a named volume for `/root/.knightcode/agent` if you want container-local settings and sessions. Mounting your host `~/.knightcode/agent` exposes host auth and session files to the container.
81
+ ## Run KnightCode with OpenShell
78
82
 
79
- ## OpenShell
83
+ [NVIDIA OpenShell](https://docs.nvidia.com/openshell/about/overview) provides local or remote sandboxes with filesystem, process, network, credential, and inference policies.
80
84
 
81
- Use [NVIDIA OpenShell](https://docs.nvidia.com/openshell/about/overview) when you want a policy-controlled sandbox with filesystem, process, network, credential, and inference controls.
82
- OpenShell can run sandboxes through a local gateway backed by Docker, Podman, or a VM runtime, or through a remote Kubernetes gateway.
85
+ ### Select a gateway
83
86
 
84
- Every sandbox requires an active gateway.
85
- Register and select one before creating a sandbox:
87
+ Every sandbox requires an active gateway:
86
88
 
87
89
  ```bash
88
90
  openshell gateway add <gateway-url> --name <name>
89
91
  openshell gateway select <name>
90
92
  ```
91
93
 
92
- Launch `knightcode` inside an OpenShell sandbox:
94
+ ### Create the sandbox
93
95
 
94
96
  ```bash
95
97
  openshell sandbox create --name knightcode-sandbox --from knightcode -- knightcode
96
98
  ```
97
99
 
98
- In this pattern, the whole `knightcode` process runs inside the sandbox.
99
- Built-in tools, `!` commands, and extension tools execute inside the OpenShell boundary.
100
+ KnightCode, its built-in tools, `!` commands, and extension tools run inside the OpenShell boundary.
100
101
 
101
- If the gateway is remote, project files are not bind-mounted from the host, meaning writes in the sandbox are not reflected on your machine.
102
- Clone the repository inside the sandbox or use OpenShell file transfer commands:
102
+ ### Transfer files to a remote sandbox
103
+
104
+ A remote gateway does not bind-mount your host working folder. Clone the repository inside the sandbox or transfer files explicitly:
105
+
106
+ ```bash
107
+ openshell sandbox upload knightcode-sandbox ./working-folder /workspace
108
+ openshell sandbox download knightcode-sandbox /workspace/working-folder ./working-folder-out
109
+ ```
110
+
111
+ OpenShell inference routing can keep raw model credentials outside the sandbox. When configured, point KnightCode at the corresponding OpenAI-compatible or Anthropic-compatible endpoint exposed by the gateway.
112
+
113
+ ## Route tools through Gondolin
114
+
115
+ [Gondolin](https://github.com/KnightCodeAI/gondolin) is a local Linux micro-VM. Its example extension keeps the KnightCode process and file-based provider credentials on the host while routing the built-in tools and user `!` commands into the VM.
116
+
117
+ Commands inside the VM inherit the host process environment. Provider keys supplied through environment variables can therefore be visible inside the VM. Do not use this pattern as a credential boundary unless you remove sensitive variables or change the extension's environment handling.
118
+
119
+ Gondolin requires Node.js 23.6 or newer and QEMU installed through your operating-system package manager.
120
+
121
+ ### Install the extension
122
+
123
+ From a KnightCode source checkout:
124
+
125
+ ```bash
126
+ mkdir -p ~/.knightcode/agent/extensions
127
+ cp -R packages/cli/examples/extensions/gondolin ~/.knightcode/agent/extensions/gondolin
128
+ cd ~/.knightcode/agent/extensions/gondolin
129
+ npm install --ignore-scripts
130
+ ```
131
+
132
+ ### Start KnightCode
133
+
134
+ Run KnightCode from the working folder you want mounted:
103
135
 
104
136
  ```bash
105
- openshell sandbox upload knightcode-sandbox ./repo /workspace
106
- openshell sandbox download knightcode-sandbox /workspace/repo ./repo-out
137
+ cd /path/to/working-folder
138
+ knightcode -e ~/.knightcode/agent/extensions/gondolin
107
139
  ```
108
140
 
109
- OpenShell providers can keep raw model API keys outside the sandbox.
110
- When inference routing is configured, code inside the sandbox can call `https://inference.local`, and the gateway injects the configured provider credentials upstream.
111
- Configure KnightCode to use the corresponding OpenAI-compatible or Anthropic-compatible endpoint if you want model traffic to use this route.
141
+ The extension mounts the host working folder at `/workspace` in the VM and overrides `read`, `write`, `edit`, `bash`, `grep`, `find`, and `ls`. File changes under `/workspace` write through to the host.
142
+
143
+ Other extension tools still run on the host unless they explicitly delegate their operations. Review the [Gondolin example](../examples/extensions/gondolin/) before adding tools that could bypass the VM boundary.