@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.
- package/bin/CHANGELOG.md +60 -0
- package/bin/README.md +52 -19
- package/bin/docs/cli-integration.md +106 -0
- package/bin/docs/cli.md +270 -0
- package/bin/docs/compaction.md +56 -37
- package/bin/docs/configuration.md +46 -0
- package/bin/docs/containerization.md +86 -54
- package/bin/docs/custom-provider.md +132 -785
- package/bin/docs/docs.json +143 -103
- package/bin/docs/environment-variables.md +5 -4
- package/bin/docs/extensions.md +134 -2956
- package/bin/docs/how-knightcode-works.md +49 -0
- package/bin/docs/index.md +24 -69
- package/bin/docs/json.md +193 -65
- package/bin/docs/keybindings.md +56 -101
- package/bin/docs/llama-cpp.md +3 -3
- package/bin/docs/message-types.md +261 -0
- package/bin/docs/models.md +64 -547
- package/bin/docs/packages.md +66 -167
- package/bin/docs/prompt-templates.md +31 -68
- package/bin/docs/providers.md +103 -241
- package/bin/docs/quickstart.md +61 -106
- package/bin/docs/rpc-commands.md +854 -0
- package/bin/docs/rpc-extension-ui.md +200 -0
- package/bin/docs/rpc.md +129 -1556
- package/bin/docs/sdk.md +76 -1160
- package/bin/docs/security.md +70 -32
- package/bin/docs/session-format.md +25 -216
- package/bin/docs/sessions.md +38 -143
- package/bin/docs/settings.md +111 -389
- package/bin/docs/shell-aliases.md +85 -5
- package/bin/docs/skills.md +51 -189
- package/bin/docs/slash-commands.md +63 -0
- package/bin/docs/terminal-setup.md +107 -79
- package/bin/docs/termux.md +74 -83
- package/bin/docs/themes.md +68 -280
- package/bin/docs/tmux.md +31 -39
- package/bin/docs/tui.md +69 -923
- package/bin/docs/usage.md +79 -286
- package/bin/docs/windows.md +43 -17
- package/bin/export-html/template.js +6 -1
- package/bin/knightcode +2 -2
- package/bin/package.json +6 -6
- package/package.json +1 -1
- package/bin/docs/development.md +0 -71
package/bin/docs/security.md
CHANGED
|
@@ -1,59 +1,97 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Run KnightCode safely
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Treat model-generated commands and code as untrusted. KnightCode can read, change, and execute files with the permissions of the account that started it, and it does not ask for approval before every tool call. Extensions, package installers, language servers, and other child processes run with those same permissions unless an operating-system or virtualization boundary restricts them.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Files, comments, instructions, command output, and model responses can steer the model through prompt injection. Project trust controls which project resources load at startup, but it does not make that content or the resulting actions safe.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Safety comes from limiting the files, credentials, processes, and network services KnightCode can access and affect if a generated action is wrong or hostile. Watching the transcript, using project trust, and reviewing changes do not create a security boundary.
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
## Choose how to run KnightCode
|
|
10
|
+
|
|
11
|
+
Different ways of running KnightCode place different limits on what generated commands can access:
|
|
12
|
+
|
|
13
|
+
| How KnightCode runs | What remains protected |
|
|
14
|
+
|---|---|
|
|
15
|
+
| Directly, with the permissions of its operating-system user | Anything that user cannot access. A dedicated user account can narrow those permissions, but KnightCode still shares the operating system and network with other users. |
|
|
16
|
+
| Entirely inside a container, virtual machine, or sandbox | Host files and processes that you do not expose to the environment. Credentials and network services remain accessible if you make them available inside it. This is usually the strongest practical option. |
|
|
17
|
+
| Outside the isolated environment, with only its built-in tools running inside | Host resources are protected from actions performed through those tools. KnightCode itself and other extensions remain outside the boundary, so this is a narrower form of isolation. |
|
|
18
|
+
|
|
19
|
+
The working folder controls resource discovery and the default location for tools, but it does not prevent commands from accessing other paths available to the KnightCode process.
|
|
20
|
+
|
|
21
|
+
Whichever option you choose, only provide the files and services required for the task. Keep credentials outside the environment where possible, or use narrowly scoped, short-lived credentials. Restrict network access when commands do not need it.
|
|
22
|
+
|
|
23
|
+
For setup instructions and the limitations of each isolation method, see [Run KnightCode in an isolated environment](containerization.md).
|
|
24
|
+
|
|
25
|
+
<a id="project-trust"></a>
|
|
26
|
+
|
|
27
|
+
## Understand project trust
|
|
28
|
+
|
|
29
|
+
Project trust controls whether KnightCode loads most settings and resources supplied by a working folder. It prevents a folder from silently loading executable extensions before you approve it.
|
|
30
|
+
|
|
31
|
+
Project trust is not a complete startup boundary. KnightCode reads the project `sessionDir` setting while selecting or creating a session, before it resolves project trust. Declining trust prevents the remaining project settings and protected resources from loading, but it cannot undo that initial session-directory lookup.
|
|
32
|
+
|
|
33
|
+
Project trust does not limit what tool calls can access or affect. After KnightCode starts, enabled tools still use the operating-system permissions of the KnightCode process. Instructions and other content in the folder can also influence the model.
|
|
34
|
+
|
|
35
|
+
### Resources protected by project trust
|
|
36
|
+
|
|
37
|
+
KnightCode requires a project-trust decision when it finds any of these resources from the current working directory:
|
|
10
38
|
|
|
11
39
|
- `.knightcode/settings.json`
|
|
12
40
|
- `.knightcode/extensions`, `.knightcode/skills`, `.knightcode/prompts`, or `.knightcode/themes`
|
|
13
41
|
- `.knightcode/SYSTEM.md` or `.knightcode/APPEND_SYSTEM.md`
|
|
14
42
|
- project `.agents/skills` in the current directory or an ancestor directory
|
|
15
43
|
|
|
16
|
-
A bare `.knightcode` directory does not
|
|
44
|
+
A bare `.knightcode` directory does not require project trust.
|
|
17
45
|
|
|
18
|
-
|
|
46
|
+
Granting project trust allows KnightCode to load:
|
|
19
47
|
|
|
20
|
-
|
|
48
|
+
- project settings
|
|
49
|
+
- extensions, skills, prompt templates, themes, and system-prompt files under `.knightcode`
|
|
50
|
+
- missing packages configured through project settings
|
|
51
|
+
- project-local and project-package extensions
|
|
21
52
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
53
|
+
Declining project trust skips those protected resources, except for the initial `sessionDir` lookup described above.
|
|
54
|
+
|
|
55
|
+
Context files such as `AGENTS.override.md`, `AGENTS.md`, and `CLAUDE.md` load regardless of project trust unless you disable context loading. Treat instructions in a folder as untrusted input even when you decline project trust.
|
|
56
|
+
|
|
57
|
+
### How KnightCode chooses a trust decision
|
|
58
|
+
|
|
59
|
+
A command-line `--approve` or `--no-approve` override applies first. When protected resources exist and there is no command-line override:
|
|
26
60
|
|
|
27
|
-
|
|
61
|
+
1. User-level and command-line extensions can handle the `project_trust` event. The first extension that returns yes or no owns the decision.
|
|
62
|
+
2. If no extension decides, KnightCode looks for a saved decision for the current directory or one of its parents. The closest decision applies.
|
|
63
|
+
3. If no saved decision applies, KnightCode follows the global `defaultProjectTrust` setting, whose default is `"ask"`.
|
|
28
64
|
|
|
29
|
-
|
|
65
|
+
Saved decisions use canonical directory paths and live in:
|
|
30
66
|
|
|
31
|
-
|
|
67
|
+
```text
|
|
68
|
+
~/.knightcode/agent/trust.json
|
|
69
|
+
```
|
|
32
70
|
|
|
33
|
-
|
|
71
|
+
Use `/trust` to save a decision for future KnightCode processes.
|
|
34
72
|
|
|
35
|
-
|
|
73
|
+
### Project trust without an interactive prompt
|
|
36
74
|
|
|
37
|
-
|
|
75
|
+
Print, JSON, and RPC modes cannot show the built-in trust prompt. If no command-line override, extension, or saved decision applies:
|
|
38
76
|
|
|
39
|
-
|
|
77
|
+
- `defaultProjectTrust: "always"` loads protected project resources.
|
|
78
|
+
- `defaultProjectTrust: "ask"` or `"never"` skips them.
|
|
40
79
|
|
|
41
|
-
|
|
80
|
+
Use `--approve` or `--no-approve` when an automated run needs an explicit one-time decision.
|
|
42
81
|
|
|
43
|
-
|
|
82
|
+
## Reduce impact and improve recovery
|
|
44
83
|
|
|
45
|
-
|
|
46
|
-
- run host knightcode while routing built-in tool execution into a Gondolin micro-VM
|
|
47
|
-
- mount only the workspace paths the agent should access
|
|
48
|
-
- avoid mounting host `~/.knightcode/agent` unless the container should access host sessions, settings, and credentials
|
|
49
|
-
- pass the minimum required API keys or use short-lived credentials
|
|
50
|
-
- restrict network access when the task does not need it
|
|
51
|
-
- review diffs and outputs before copying results back to trusted systems
|
|
84
|
+
These practices do not replace isolation, but they reduce exposure or make recovery easier:
|
|
52
85
|
|
|
53
|
-
|
|
86
|
+
- Give KnightCode access only to files and services required for the task.
|
|
87
|
+
- Use snapshots, backups, or version control before substantial changes.
|
|
88
|
+
- Review extensions and packages before loading them. Extensions execute inside the KnightCode process.
|
|
89
|
+
- Prefer narrowly scoped, short-lived credentials.
|
|
90
|
+
- Review diffs and generated output before applying results to another system.
|
|
91
|
+
- Review sessions before exporting or sharing them. They can contain prompts, tool arguments, command output, file contents, and credentials exposed during the conversation.
|
|
54
92
|
|
|
55
|
-
##
|
|
93
|
+
## Report a security issue
|
|
56
94
|
|
|
57
|
-
|
|
95
|
+
Follow the repository [Security Policy](https://github.com/KnightCodeAI/knightcode/blob/main/SECURITY.md). Do not open a public issue for a security-sensitive report.
|
|
58
96
|
|
|
59
|
-
Expected local-agent behavior, lack of a built-in sandbox,
|
|
97
|
+
Expected local-agent behavior, prompt injection from untrusted content, lack of a built-in sandbox, and behavior from user-installed extensions or skills are generally outside the security boundary unless the report demonstrates a privilege-boundary bypass or access that the local user did not already have.
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
Sessions are stored as JSONL (JSON Lines) files. Each line is a JSON object with a `type` field. Session entries form a tree structure via `id`/`parentId` fields, enabling in-place branching without creating new files.
|
|
4
4
|
|
|
5
|
+
For programmatic creation, persistence, and tree navigation, see the [`SessionManager` API](sdk.md#sessionmanager-api).
|
|
6
|
+
|
|
7
|
+
|
|
5
8
|
## File Location
|
|
6
9
|
|
|
7
10
|
```
|
|
@@ -30,169 +33,18 @@ Existing sessions are automatically migrated to the current version (v3) when lo
|
|
|
30
33
|
|
|
31
34
|
Source on GitHub ([knightcode](https://github.com/KnightCodeAI/knightcode)):
|
|
32
35
|
- [`packages/cli/src/core/session-manager.ts`](https://github.com/KnightCodeAI/knightcode/blob/main/packages/cli/src/core/session-manager.ts) - Session entry types and SessionManager
|
|
33
|
-
- [
|
|
34
|
-
- [`packages/
|
|
35
|
-
- [`packages/
|
|
36
|
+
- [Message Types](message-types.md) - Shared message and content-block reference
|
|
37
|
+
- [`packages/cli/src/core/messages.ts`](https://github.com/KnightCodeAI/knightcode/blob/main/packages/cli/src/core/messages.ts) - Extended message types
|
|
38
|
+
- [`packages/ai/src/types.ts`](https://github.com/KnightCodeAI/knightcode/blob/main/packages/ai/src/types.ts) - Base message and content-block types
|
|
39
|
+
- [`packages/agent/src/types.ts`](https://github.com/KnightCodeAI/knightcode/blob/main/packages/agent/src/types.ts) - Extensible `AgentMessage` union
|
|
36
40
|
|
|
37
41
|
For TypeScript definitions in your project, inspect `node_modules/@knightcodeai/cli/dist/` and `node_modules/@knightcode/ai/dist/`.
|
|
38
42
|
|
|
39
|
-
##
|
|
40
|
-
|
|
41
|
-
Session entries contain `AgentMessage` objects. Understanding these types is essential for parsing sessions and writing extensions.
|
|
42
|
-
|
|
43
|
-
### Content Blocks
|
|
44
|
-
|
|
45
|
-
Messages contain arrays of typed content blocks:
|
|
46
|
-
|
|
47
|
-
```typescript
|
|
48
|
-
interface TextContent {
|
|
49
|
-
type: "text";
|
|
50
|
-
text: string;
|
|
51
|
-
textSignature?: string;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
interface ImageContent {
|
|
55
|
-
type: "image";
|
|
56
|
-
data: string; // base64 encoded
|
|
57
|
-
mimeType: string; // e.g., "image/jpeg", "image/png"
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
interface ThinkingContent {
|
|
61
|
-
type: "thinking";
|
|
62
|
-
thinking: string;
|
|
63
|
-
thinkingSignature?: string;
|
|
64
|
-
redacted?: boolean;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
interface ToolCall {
|
|
68
|
-
type: "toolCall";
|
|
69
|
-
id: string;
|
|
70
|
-
name: string;
|
|
71
|
-
arguments: Record<string, any>;
|
|
72
|
-
thoughtSignature?: string;
|
|
73
|
-
namespace?: string;
|
|
74
|
-
}
|
|
75
|
-
```
|
|
76
|
-
|
|
77
|
-
### Base Message Types (from @knightcode/ai)
|
|
78
|
-
|
|
79
|
-
```typescript
|
|
80
|
-
interface SystemMessage {
|
|
81
|
-
role: "system";
|
|
82
|
-
content: string | TextContent[];
|
|
83
|
-
toolsAdded?: Tool[];
|
|
84
|
-
toolsRemoved?: Array<{ name: string }>;
|
|
85
|
-
timestamp: number; // Unix ms
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
interface UserMessage {
|
|
89
|
-
role: "user";
|
|
90
|
-
content: string | (TextContent | ImageContent)[];
|
|
91
|
-
timestamp: number; // Unix ms
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
interface AssistantMessage {
|
|
95
|
-
role: "assistant";
|
|
96
|
-
content: (TextContent | ThinkingContent | ToolCall)[];
|
|
97
|
-
api: string;
|
|
98
|
-
provider: string;
|
|
99
|
-
model: string;
|
|
100
|
-
responseModel?: string;
|
|
101
|
-
responseId?: string;
|
|
102
|
-
providerThinkingLevel?: string;
|
|
103
|
-
diagnostics?: AssistantMessageDiagnostic[];
|
|
104
|
-
usage: Usage;
|
|
105
|
-
stopReason: "pending" | "stop" | "length" | "toolUse" | "error" | "aborted" | "deferred";
|
|
106
|
-
deferred?: DeferredHandle;
|
|
107
|
-
errorMessage?: string;
|
|
108
|
-
rawStopReason?: string;
|
|
109
|
-
endTurn?: boolean;
|
|
110
|
-
timestamp: number;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
interface ToolResultMessage {
|
|
114
|
-
role: "toolResult";
|
|
115
|
-
toolCallId: string;
|
|
116
|
-
toolName: string;
|
|
117
|
-
content: (TextContent | ImageContent)[];
|
|
118
|
-
details?: any; // Tool-specific metadata
|
|
119
|
-
usage?: Usage; // Nested LLM work performed by the tool
|
|
120
|
-
isError: boolean;
|
|
121
|
-
timestamp: number;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
interface Usage {
|
|
125
|
-
input: number;
|
|
126
|
-
output: number;
|
|
127
|
-
cacheRead: number;
|
|
128
|
-
cacheWrite: number;
|
|
129
|
-
cacheWrite1h?: number;
|
|
130
|
-
reasoning?: number;
|
|
131
|
-
totalTokens: number;
|
|
132
|
-
cost: {
|
|
133
|
-
input: number;
|
|
134
|
-
output: number;
|
|
135
|
-
cacheRead: number;
|
|
136
|
-
cacheWrite: number;
|
|
137
|
-
total: number;
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
```
|
|
141
|
-
|
|
142
|
-
`"pending"` is reserved for partial messages in streaming events. Terminal events replace it with a completion reason before knightcode persists the assistant message, so `"pending"` should never appear in session JSONL. `"deferred"` is a terminal reason for a provider response that will complete later; its `deferred` handle contains the provider data needed to retrieve that response.
|
|
43
|
+
## Messages
|
|
143
44
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
```typescript
|
|
147
|
-
interface BashExecutionMessage {
|
|
148
|
-
role: "bashExecution";
|
|
149
|
-
command: string;
|
|
150
|
-
output: string;
|
|
151
|
-
exitCode: number | undefined;
|
|
152
|
-
cancelled: boolean;
|
|
153
|
-
truncated: boolean;
|
|
154
|
-
fullOutputPath?: string;
|
|
155
|
-
excludeFromContext?: boolean; // true for !! prefix commands
|
|
156
|
-
timestamp: number;
|
|
157
|
-
}
|
|
45
|
+
A `message` entry stores an [`AgentMessage`](message-types.md). Message content blocks, roles, usage, and message timestamps are defined in [Message Types](message-types.md).
|
|
158
46
|
|
|
159
|
-
|
|
160
|
-
role: "custom";
|
|
161
|
-
customType: string; // Extension identifier
|
|
162
|
-
content: string | (TextContent | ImageContent)[];
|
|
163
|
-
display: boolean; // Show in TUI
|
|
164
|
-
details?: any; // Extension-specific metadata
|
|
165
|
-
timestamp: number;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
interface BranchSummaryMessage {
|
|
169
|
-
role: "branchSummary";
|
|
170
|
-
summary: string;
|
|
171
|
-
fromId: string | null; // Previous leaf whose abandoned path was summarized
|
|
172
|
-
timestamp: number;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
interface CompactionSummaryMessage {
|
|
176
|
-
role: "compactionSummary";
|
|
177
|
-
summary: string;
|
|
178
|
-
tokensBefore: number;
|
|
179
|
-
timestamp: number;
|
|
180
|
-
}
|
|
181
|
-
```
|
|
182
|
-
|
|
183
|
-
### AgentMessage Union
|
|
184
|
-
|
|
185
|
-
```typescript
|
|
186
|
-
type AgentMessage =
|
|
187
|
-
| SystemMessage
|
|
188
|
-
| UserMessage
|
|
189
|
-
| AssistantMessage
|
|
190
|
-
| ToolResultMessage
|
|
191
|
-
| BashExecutionMessage
|
|
192
|
-
| CustomMessage
|
|
193
|
-
| BranchSummaryMessage
|
|
194
|
-
| CompactionSummaryMessage;
|
|
195
|
-
```
|
|
47
|
+
Session entry timestamps are ISO 8601 strings. The nested message timestamp is a Unix timestamp in milliseconds.
|
|
196
48
|
|
|
197
49
|
## Entry Base
|
|
198
50
|
|
|
@@ -274,7 +126,7 @@ Created when context is compacted. Stores a summary of earlier messages and a co
|
|
|
274
126
|
{"type":"compaction","id":"f6g7h8i9","parentId":"e5f6g7h8","timestamp":"2024-12-03T14:10:00.000Z","summary":"User discussed X, Y, Z...","firstKeptEntryId":"c3d4e5f6","tokensBefore":50000,"systemMessage":{"role":"system","content":"You are a coding assistant.","toolsAdded":[],"timestamp":1733235000000}}
|
|
275
127
|
```
|
|
276
128
|
|
|
277
|
-
`firstKeptEntryId` is required. It identifies the first entry retained from before the compaction entry. When rebuilding context, KnightCode replaces older summarized entries with the compaction summary and keeps the range beginning at this entry.
|
|
129
|
+
`firstKeptEntryId` is required. It identifies the first entry retained from before the compaction entry. When rebuilding context, KnightCode replaces older summarized entries with the compaction summary and keeps the range beginning at this entry. A retain-none compaction stores its own ID in this field, so no preceding entries are retained.
|
|
278
130
|
|
|
279
131
|
Optional fields:
|
|
280
132
|
- `systemMessage`: The replayed prompt sections and tool declarations at the compaction boundary; it becomes the leading system message of the compacted context, and system messages among the kept entries are dropped in its favor. It is absent on older session entries.
|
|
@@ -282,6 +134,16 @@ Optional fields:
|
|
|
282
134
|
- `details`: Implementation-specific data (e.g., `{ readFiles: string[], modifiedFiles: string[] }` for default, or custom data for extensions)
|
|
283
135
|
- `fromHook`: `true` if generated by an extension, `false`/`undefined` if knightcode-generated (legacy field name)
|
|
284
136
|
|
|
137
|
+
### ContextEditEntry
|
|
138
|
+
|
|
139
|
+
Append-only edit of one earlier context-producing entry. It changes only future model context; the target entry and its metadata remain unchanged in raw history, UI, exports, and session accounting.
|
|
140
|
+
|
|
141
|
+
```json
|
|
142
|
+
{"type":"context_edit","id":"g6h7i8j9","parentId":"f6g7h8i9","timestamp":"2024-12-03T14:11:00.000Z","targetId":"c3d4e5f6","replacement":null}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
Targets may be user, assistant, tool-result, or custom-message entries. `replacement: null` omits the target from model context. A non-null `replacement` replaces only the target message content. String replacements for assistant and tool-result entries are normalized to one text block because those roles require content arrays. If several edits target the same entry, the latest edit on the active branch wins. Edits are branch-relative: navigating to a point before the edit reveals the target's original contribution again.
|
|
146
|
+
|
|
285
147
|
### BranchSummaryEntry
|
|
286
148
|
|
|
287
149
|
Created when switching branches via `/tree` with an LLM generated summary of the left branch up to the common ancestor. Captures context from the abandoned path.
|
|
@@ -366,7 +228,9 @@ Entries normally form one tree, but navigation APIs can create multiple roots:
|
|
|
366
228
|
- Includes entries after the compaction entry
|
|
367
229
|
3. Preserves non-message entries in the selected range so interactive mode can render them
|
|
368
230
|
|
|
369
|
-
`
|
|
231
|
+
`buildSessionProjection()` then applies the latest `context_edit` for each selected target. It returns the model-visible messages together with their source entries. Omitted targets produce no message; replacements retain the source entry's role and metadata while changing only content. The raw selected entries are not modified.
|
|
232
|
+
|
|
233
|
+
`buildSessionContext()` builds on that projection to produce the message list for the LLM:
|
|
370
234
|
|
|
371
235
|
1. Extracts current model and thinking level settings from the full path
|
|
372
236
|
2. Converts selected entries to messages:
|
|
@@ -374,6 +238,7 @@ Entries normally form one tree, but navigation APIs can create multiple roots:
|
|
|
374
238
|
- `compaction` -> complete system checkpoint followed by `compactionSummary`
|
|
375
239
|
- `branch_summary` -> `branchSummary`
|
|
376
240
|
- `custom_message` -> `CustomMessage`
|
|
241
|
+
- `context_edit` -> no context message of its own
|
|
377
242
|
- `usage` and `custom` -> no context message
|
|
378
243
|
|
|
379
244
|
The compaction summary replaces entries before `firstKeptEntryId`. Pre-compaction system messages are folded into the complete checkpoint rather than replayed from the retained range. Retained non-system entries and all entries after the compaction remain available to the LLM.
|
|
@@ -422,59 +287,3 @@ for (const line of lines) {
|
|
|
422
287
|
}
|
|
423
288
|
}
|
|
424
289
|
```
|
|
425
|
-
|
|
426
|
-
## SessionManager API
|
|
427
|
-
|
|
428
|
-
Key methods for working with sessions programmatically.
|
|
429
|
-
|
|
430
|
-
### Static Creation Methods
|
|
431
|
-
- `SessionManager.create(cwd, sessionDir?, options?)` - New session; `options` can set `id` and `parentSession`
|
|
432
|
-
- `SessionManager.open(path, sessionDir?, cwdOverride?)` - Open existing session file
|
|
433
|
-
- `SessionManager.continueRecent(cwd, sessionDir?)` - Continue most recent or create new
|
|
434
|
-
- `SessionManager.inMemory(cwd?, options?, entries?)` - No file persistence, optionally initialized from entries
|
|
435
|
-
- `SessionManager.forkFrom(sourcePath, targetCwd, sessionDir?, options?)` - Fork session from another project
|
|
436
|
-
|
|
437
|
-
### Static Listing Methods
|
|
438
|
-
- `SessionManager.list(cwd, sessionDir?, onProgress?)` - List sessions for a directory
|
|
439
|
-
- `SessionManager.listAll(onProgress?)` - List all sessions across all projects
|
|
440
|
-
- `SessionManager.listAll(sessionDir?, onProgress?)` - List sessions from a custom session root
|
|
441
|
-
|
|
442
|
-
### Instance Methods - Session Management
|
|
443
|
-
- `newSession(options?)` - Start a new session (options: `{ id?: string, parentSession?: string }`)
|
|
444
|
-
- `setSessionFile(path)` - Switch to a different session file
|
|
445
|
-
- `createBranchedSession(leafId)` - Extract branch to new session file
|
|
446
|
-
|
|
447
|
-
### Instance Methods - Appending (all return entry ID)
|
|
448
|
-
- `appendMessage(message)` - Add message
|
|
449
|
-
- `appendThinkingLevelChange(level)` - Record thinking change
|
|
450
|
-
- `appendModelChange(provider, modelId)` - Record model change
|
|
451
|
-
- `appendUsage(kind, provider, model, usage)` - Record model-attributed usage outside the conversation
|
|
452
|
-
- `appendCompaction(summary, firstKeptEntryId, tokensBefore, details?, fromHook?, usage?)` - Add compaction
|
|
453
|
-
- `appendCustomEntry(customType, data?)` - Extension state (not in context)
|
|
454
|
-
- `appendSessionInfo(name)` - Set session display name
|
|
455
|
-
- `appendCustomMessageEntry(customType, content, display, details?)` - Extension message (in context)
|
|
456
|
-
- `appendLabelChange(targetId, label)` - Set/clear label
|
|
457
|
-
|
|
458
|
-
### Instance Methods - Tree Navigation
|
|
459
|
-
- `getLeafId()` - Current position
|
|
460
|
-
- `getLeafEntry()` - Get current leaf entry
|
|
461
|
-
- `getEntry(id)` - Get entry by ID
|
|
462
|
-
- `getBranch(fromId?)` - Walk from entry to root
|
|
463
|
-
- `getTree()` - Get full tree structure
|
|
464
|
-
- `getChildren(parentId)` - Get direct children
|
|
465
|
-
- `getLabel(id)` - Get label for entry
|
|
466
|
-
- `branch(entryId)` - Move leaf to earlier entry
|
|
467
|
-
- `resetLeaf()` - Reset leaf to null (before any entries)
|
|
468
|
-
- `branchWithSummary(entryId, summary, details?, fromHook?, usage?)` - Branch with context summary; `entryId` may be `null` to branch from the root
|
|
469
|
-
|
|
470
|
-
### Instance Methods - Context & Info
|
|
471
|
-
- `buildContextEntries()` - Get active branch entries with compaction applied
|
|
472
|
-
- `buildSessionContext()` - Get messages, thinkingLevel, and model for LLM
|
|
473
|
-
- `getEntries()` - All entries (excluding header)
|
|
474
|
-
- `getHeader()` - Session header metadata
|
|
475
|
-
- `getSessionName()` - Get display name from latest session_info entry
|
|
476
|
-
- `getCwd()` - Working directory
|
|
477
|
-
- `getSessionDir()` - Session storage directory
|
|
478
|
-
- `getSessionId()` - Session UUID
|
|
479
|
-
- `getSessionFile()` - Session file path (undefined for in-memory)
|
|
480
|
-
- `isPersisted()` - Whether session is saved to disk
|