@draht/coding-agent 2026.6.11 → 2026.7.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/README.md +1 -4
- package/dist/bun/register-bedrock.d.ts.map +1 -1
- package/dist/bun/register-bedrock.js +1 -1
- package/dist/bun/register-bedrock.js.map +1 -1
- package/dist/bun/restore-sandbox-env.d.ts +4 -0
- package/dist/bun/restore-sandbox-env.d.ts.map +1 -1
- package/dist/bun/restore-sandbox-env.js +4 -0
- package/dist/bun/restore-sandbox-env.js.map +1 -1
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +4 -4
- package/dist/cli/args.js.map +1 -1
- package/dist/cli/config-selector.d.ts +4 -2
- package/dist/cli/config-selector.d.ts.map +1 -1
- package/dist/cli/config-selector.js +1 -1
- package/dist/cli/config-selector.js.map +1 -1
- package/dist/cli/file-processor.d.ts.map +1 -1
- package/dist/cli/file-processor.js +13 -25
- package/dist/cli/file-processor.js.map +1 -1
- package/dist/cli/session-picker.d.ts +2 -1
- package/dist/cli/session-picker.d.ts.map +1 -1
- package/dist/cli/session-picker.js +5 -4
- package/dist/cli/session-picker.js.map +1 -1
- package/dist/cli/startup-ui.d.ts +5 -1
- package/dist/cli/startup-ui.d.ts.map +1 -1
- package/dist/cli/startup-ui.js +94 -22
- package/dist/cli/startup-ui.js.map +1 -1
- package/dist/config.d.ts +6 -2
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +35 -16
- package/dist/config.js.map +1 -1
- package/dist/core/agent-session.d.ts +10 -4
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +124 -83
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/auth-storage.d.ts +11 -12
- package/dist/core/auth-storage.d.ts.map +1 -1
- package/dist/core/auth-storage.js +25 -26
- package/dist/core/auth-storage.js.map +1 -1
- package/dist/core/compaction/branch-summarization.d.ts +3 -1
- package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
- package/dist/core/compaction/branch-summarization.js +3 -3
- package/dist/core/compaction/branch-summarization.js.map +1 -1
- package/dist/core/compaction/compaction.d.ts +5 -4
- package/dist/core/compaction/compaction.d.ts.map +1 -1
- package/dist/core/compaction/compaction.js +23 -20
- package/dist/core/compaction/compaction.js.map +1 -1
- package/dist/core/export-html/vendor/marked.min.js +75 -3
- package/dist/core/extensions/index.d.ts +1 -1
- package/dist/core/extensions/index.d.ts.map +1 -1
- package/dist/core/extensions/index.js.map +1 -1
- package/dist/core/extensions/loader.d.ts +2 -3
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js +77 -14
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/runner.d.ts +2 -1
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +33 -1
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/types.d.ts +29 -2
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/http-dispatcher.d.ts +1 -0
- package/dist/core/http-dispatcher.d.ts.map +1 -1
- package/dist/core/http-dispatcher.js +45 -2
- package/dist/core/http-dispatcher.js.map +1 -1
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/keybindings.d.ts +1 -1
- package/dist/core/keybindings.d.ts.map +1 -1
- package/dist/core/keybindings.js +3 -6
- package/dist/core/keybindings.js.map +1 -1
- package/dist/core/model-registry.d.ts +2 -1
- package/dist/core/model-registry.d.ts.map +1 -1
- package/dist/core/model-registry.js +32 -67
- package/dist/core/model-registry.js.map +1 -1
- package/dist/core/model-resolver.d.ts +11 -1
- package/dist/core/model-resolver.d.ts.map +1 -1
- package/dist/core/model-resolver.js +37 -19
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/package-manager.d.ts +5 -2
- package/dist/core/package-manager.d.ts.map +1 -1
- package/dist/core/package-manager.js +99 -43
- package/dist/core/package-manager.js.map +1 -1
- package/dist/core/project-trust.d.ts.map +1 -1
- package/dist/core/project-trust.js +4 -3
- package/dist/core/project-trust.js.map +1 -1
- package/dist/core/provider-attribution.d.ts +2 -2
- package/dist/core/provider-attribution.d.ts.map +1 -1
- package/dist/core/provider-attribution.js.map +1 -1
- package/dist/core/provider-display-names.d.ts.map +1 -1
- package/dist/core/provider-display-names.js +1 -1
- package/dist/core/provider-display-names.js.map +1 -1
- package/dist/core/resolve-config-value.d.ts +7 -8
- package/dist/core/resolve-config-value.d.ts.map +1 -1
- package/dist/core/resolve-config-value.js +24 -26
- package/dist/core/resolve-config-value.js.map +1 -1
- package/dist/core/resource-loader.d.ts +3 -2
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +16 -6
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/sdk.d.ts +9 -9
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +3 -1
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/session-manager.d.ts +21 -2
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +121 -77
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/settings-manager.d.ts +10 -1
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +29 -3
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/system-prompt.d.ts.map +1 -1
- package/dist/core/system-prompt.js +7 -7
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/core/timings.d.ts +4 -2
- package/dist/core/timings.d.ts.map +1 -1
- package/dist/core/timings.js +24 -14
- package/dist/core/timings.js.map +1 -1
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +32 -8
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/edit-diff.d.ts +23 -4
- package/dist/core/tools/edit-diff.d.ts.map +1 -1
- package/dist/core/tools/edit-diff.js +99 -20
- package/dist/core/tools/edit-diff.js.map +1 -1
- package/dist/core/tools/edit.d.ts.map +1 -1
- package/dist/core/tools/edit.js +2 -2
- package/dist/core/tools/edit.js.map +1 -1
- package/dist/core/tools/find.d.ts.map +1 -1
- package/dist/core/tools/find.js +19 -11
- package/dist/core/tools/find.js.map +1 -1
- package/dist/core/tools/read.d.ts.map +1 -1
- package/dist/core/tools/read.js +12 -25
- package/dist/core/tools/read.js.map +1 -1
- package/dist/core/trust-manager.d.ts +8 -3
- package/dist/core/trust-manager.d.ts.map +1 -1
- package/dist/core/trust-manager.js +26 -11
- package/dist/core/trust-manager.js.map +1 -1
- package/dist/index.d.ts +6 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -3
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts +2 -2
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +47 -15
- package/dist/main.js.map +1 -1
- package/dist/migrations.d.ts.map +1 -1
- package/dist/migrations.js +1 -123
- package/dist/migrations.js.map +1 -1
- package/dist/modes/interactive/assets/clankolas.png +0 -0
- package/dist/modes/interactive/components/assistant-message.d.ts +3 -1
- package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/assistant-message.js +23 -15
- package/dist/modes/interactive/components/assistant-message.js.map +1 -1
- package/dist/modes/interactive/components/config-selector.d.ts +34 -3
- package/dist/modes/interactive/components/config-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/config-selector.js +284 -29
- package/dist/modes/interactive/components/config-selector.js.map +1 -1
- package/dist/modes/interactive/components/custom-entry.d.ts +19 -0
- package/dist/modes/interactive/components/custom-entry.d.ts.map +1 -0
- package/dist/modes/interactive/components/custom-entry.js +52 -0
- package/dist/modes/interactive/components/custom-entry.js.map +1 -0
- package/dist/modes/interactive/components/extension-editor.d.ts +3 -1
- package/dist/modes/interactive/components/extension-editor.d.ts.map +1 -1
- package/dist/modes/interactive/components/extension-editor.js +12 -3
- package/dist/modes/interactive/components/extension-editor.js.map +1 -1
- package/dist/modes/interactive/components/footer.d.ts +2 -2
- package/dist/modes/interactive/components/footer.d.ts.map +1 -1
- package/dist/modes/interactive/components/footer.js +4 -0
- package/dist/modes/interactive/components/footer.js.map +1 -1
- package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -1
- package/dist/modes/interactive/components/login-dialog.js +0 -1
- package/dist/modes/interactive/components/login-dialog.js.map +1 -1
- package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/model-selector.js +2 -1
- package/dist/modes/interactive/components/model-selector.js.map +1 -1
- package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/scoped-models-selector.js +4 -1
- package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -1
- package/dist/modes/interactive/components/session-selector.d.ts +0 -1
- package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/session-selector.js +14 -8
- package/dist/modes/interactive/components/session-selector.js.map +1 -1
- package/dist/modes/interactive/components/settings-selector.d.ts +4 -0
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector.js +188 -16
- package/dist/modes/interactive/components/settings-selector.js.map +1 -1
- package/dist/modes/interactive/components/status-indicator.d.ts +28 -0
- package/dist/modes/interactive/components/status-indicator.d.ts.map +1 -0
- package/dist/modes/interactive/components/status-indicator.js +60 -0
- package/dist/modes/interactive/components/status-indicator.js.map +1 -0
- package/dist/modes/interactive/components/tree-selector.d.ts +1 -1
- package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/tree-selector.js +130 -15
- package/dist/modes/interactive/components/tree-selector.js.map +1 -1
- package/dist/modes/interactive/components/trust-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/trust-selector.js +4 -4
- package/dist/modes/interactive/components/trust-selector.js.map +1 -1
- package/dist/modes/interactive/components/user-message.d.ts +6 -2
- package/dist/modes/interactive/components/user-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/user-message.js +19 -6
- package/dist/modes/interactive/components/user-message.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +13 -11
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +252 -233
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/model-search.d.ts +12 -0
- package/dist/modes/interactive/model-search.d.ts.map +1 -0
- package/dist/modes/interactive/model-search.js +15 -0
- package/dist/modes/interactive/model-search.js.map +1 -0
- package/dist/modes/interactive/theme/theme-controller.d.ts +29 -0
- package/dist/modes/interactive/theme/theme-controller.d.ts.map +1 -0
- package/dist/modes/interactive/theme/theme-controller.js +102 -0
- package/dist/modes/interactive/theme/theme-controller.js.map +1 -0
- package/dist/modes/interactive/theme/theme-schema.json +2 -1
- package/dist/modes/interactive/theme/theme.d.ts +27 -8
- package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
- package/dist/modes/interactive/theme/theme.js +64 -42
- package/dist/modes/interactive/theme/theme.js.map +1 -1
- package/dist/modes/rpc/rpc-client.d.ts +19 -4
- package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-client.js +14 -0
- package/dist/modes/rpc/rpc-client.js.map +1 -1
- package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-mode.js +17 -1
- package/dist/modes/rpc/rpc-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-types.d.ts +26 -0
- package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-types.js.map +1 -1
- package/dist/package-manager-cli.d.ts +2 -2
- package/dist/package-manager-cli.d.ts.map +1 -1
- package/dist/package-manager-cli.js +152 -48
- package/dist/package-manager-cli.js.map +1 -1
- package/dist/prompts/commands/brainstorm.md +148 -0
- package/dist/rpc-entry.d.ts +3 -0
- package/dist/rpc-entry.d.ts.map +1 -0
- package/dist/rpc-entry.js +10 -0
- package/dist/rpc-entry.js.map +1 -0
- package/dist/utils/child-process.d.ts +7 -4
- package/dist/utils/child-process.d.ts.map +1 -1
- package/dist/utils/child-process.js +23 -5
- package/dist/utils/child-process.js.map +1 -1
- package/dist/utils/image-convert.d.ts +1 -0
- package/dist/utils/image-convert.d.ts.map +1 -1
- package/dist/utils/image-convert.js +21 -15
- package/dist/utils/image-convert.js.map +1 -1
- package/dist/utils/image-process.d.ts +18 -0
- package/dist/utils/image-process.d.ts.map +1 -0
- package/dist/utils/image-process.js +83 -0
- package/dist/utils/image-process.js.map +1 -0
- package/dist/utils/mime.d.ts.map +1 -1
- package/dist/utils/mime.js +41 -0
- package/dist/utils/mime.js.map +1 -1
- package/dist/utils/shell.d.ts +1 -0
- package/dist/utils/shell.d.ts.map +1 -1
- package/dist/utils/shell.js +12 -5
- package/dist/utils/shell.js.map +1 -1
- package/dist/utils/version-check.d.ts.map +1 -1
- package/dist/utils/version-check.js +4 -27
- package/dist/utils/version-check.js.map +1 -1
- package/docs/extensions.md +55 -8
- package/docs/keybindings.md +1 -1
- package/docs/packages.md +2 -2
- package/docs/providers.md +2 -1
- package/docs/rpc.md +58 -0
- package/docs/sdk.md +50 -0
- package/docs/session-format.md +18 -8
- package/docs/settings.md +10 -0
- package/docs/usage.md +2 -2
- package/examples/extensions/README.md +1 -0
- package/examples/extensions/custom-compaction.ts +2 -1
- package/examples/extensions/custom-provider-anthropic/index.ts +1 -1
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/index.ts +9 -5
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/test.ts +1 -1
- package/examples/extensions/entry-renderer.ts +41 -0
- package/examples/extensions/gondolin/package-lock.json +2 -2
- package/examples/extensions/gondolin/package.json +1 -1
- package/examples/extensions/handoff.ts +2 -2
- package/examples/extensions/plan-mode/index.ts +87 -37
- package/examples/extensions/preset.ts +10 -4
- package/examples/extensions/provider-payload.ts +5 -5
- package/examples/extensions/qna.ts +2 -2
- package/examples/extensions/question.ts +32 -18
- package/examples/extensions/questionnaire.ts +41 -28
- package/examples/extensions/sandbox/index.ts +2 -2
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/subagent/agents.ts +2 -2
- package/examples/extensions/subagent/index.ts +9 -3
- package/examples/extensions/summarize.ts +2 -1
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/examples/sdk/02-custom-model.ts +1 -1
- package/examples/sdk/12-full-control.ts +2 -2
- package/package.json +14 -15
- package/prompts/commands/brainstorm.md +148 -0
|
@@ -112,46 +112,40 @@ export function getLatestCompactionEntry(entries) {
|
|
|
112
112
|
}
|
|
113
113
|
return null;
|
|
114
114
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
// Build uuid index if not available
|
|
122
|
-
if (!byId) {
|
|
123
|
-
byId = new Map();
|
|
124
|
-
for (const entry of entries) {
|
|
125
|
-
byId.set(entry.id, entry);
|
|
126
|
-
}
|
|
115
|
+
function buildEntryIndex(entries, byId) {
|
|
116
|
+
if (byId)
|
|
117
|
+
return byId;
|
|
118
|
+
const index = new Map();
|
|
119
|
+
for (const entry of entries) {
|
|
120
|
+
index.set(entry.id, entry);
|
|
127
121
|
}
|
|
128
|
-
|
|
122
|
+
return index;
|
|
123
|
+
}
|
|
124
|
+
function buildSessionPath(entries, leafId, byId) {
|
|
125
|
+
const index = buildEntryIndex(entries, byId);
|
|
129
126
|
let leaf;
|
|
130
127
|
if (leafId === null) {
|
|
131
|
-
|
|
132
|
-
return { messages: [], thinkingLevel: "off", model: null };
|
|
128
|
+
return [];
|
|
133
129
|
}
|
|
134
130
|
if (leafId) {
|
|
135
|
-
leaf =
|
|
136
|
-
}
|
|
137
|
-
if (!leaf) {
|
|
138
|
-
// Fallback to last entry (when leafId is undefined)
|
|
139
|
-
leaf = entries[entries.length - 1];
|
|
131
|
+
leaf = index.get(leafId);
|
|
140
132
|
}
|
|
133
|
+
leaf ??= entries[entries.length - 1];
|
|
141
134
|
if (!leaf) {
|
|
142
|
-
return
|
|
135
|
+
return [];
|
|
143
136
|
}
|
|
144
|
-
// Walk from leaf to root, collecting path
|
|
145
137
|
const path = [];
|
|
146
138
|
let current = leaf;
|
|
147
139
|
while (current) {
|
|
148
|
-
path.
|
|
149
|
-
current = current.parentId ?
|
|
140
|
+
path.push(current);
|
|
141
|
+
current = current.parentId ? index.get(current.parentId) : undefined;
|
|
150
142
|
}
|
|
151
|
-
|
|
143
|
+
path.reverse();
|
|
144
|
+
return path;
|
|
145
|
+
}
|
|
146
|
+
function getSessionContextSettings(path) {
|
|
152
147
|
let thinkingLevel = "off";
|
|
153
148
|
let model = null;
|
|
154
|
-
let compaction = null;
|
|
155
149
|
for (const entry of path) {
|
|
156
150
|
if (entry.type === "thinking_level_change") {
|
|
157
151
|
thinkingLevel = entry.thinkingLevel;
|
|
@@ -162,55 +156,83 @@ export function buildSessionContext(entries, leafId, byId) {
|
|
|
162
156
|
else if (entry.type === "message" && entry.message.role === "assistant") {
|
|
163
157
|
model = { provider: entry.message.provider, modelId: entry.message.model };
|
|
164
158
|
}
|
|
165
|
-
else if (entry.type === "compaction") {
|
|
166
|
-
compaction = entry;
|
|
167
|
-
}
|
|
168
159
|
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
messages.push(createBranchSummaryMessage(entry.summary, entry.fromId, entry.timestamp));
|
|
184
|
-
}
|
|
185
|
-
};
|
|
186
|
-
if (compaction) {
|
|
187
|
-
// Emit summary first
|
|
188
|
-
messages.push(createCompactionSummaryMessage(compaction.summary, compaction.tokensBefore, compaction.timestamp));
|
|
189
|
-
// Find compaction index in path
|
|
190
|
-
const compactionIdx = path.findIndex((e) => e.type === "compaction" && e.id === compaction.id);
|
|
191
|
-
// Emit kept messages (before compaction, starting from firstKeptEntryId)
|
|
192
|
-
let foundFirstKept = false;
|
|
193
|
-
for (let i = 0; i < compactionIdx; i++) {
|
|
194
|
-
const entry = path[i];
|
|
195
|
-
if (entry.id === compaction.firstKeptEntryId) {
|
|
196
|
-
foundFirstKept = true;
|
|
197
|
-
}
|
|
198
|
-
if (foundFirstKept) {
|
|
199
|
-
appendMessage(entry);
|
|
200
|
-
}
|
|
160
|
+
return { thinkingLevel, model };
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Project one selected session entry into LLM/runtime messages.
|
|
164
|
+
* Plain custom entries are display/state entries and do not participate in context.
|
|
165
|
+
*/
|
|
166
|
+
export function sessionEntryToContextMessages(entry) {
|
|
167
|
+
if (entry.type === "message") {
|
|
168
|
+
const message = entry.message;
|
|
169
|
+
// Session files are parsed without validation; old versions, forks, or
|
|
170
|
+
// hand-edited files can contain messages with null/missing content.
|
|
171
|
+
if ((message.role === "user" || message.role === "assistant" || message.role === "toolResult") &&
|
|
172
|
+
message.content == null) {
|
|
173
|
+
return [{ ...message, content: [] }];
|
|
201
174
|
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
175
|
+
return [message];
|
|
176
|
+
}
|
|
177
|
+
if (entry.type === "custom_message") {
|
|
178
|
+
return [
|
|
179
|
+
createCustomMessage(entry.customType, entry.content ?? [], entry.display, entry.details, entry.timestamp),
|
|
180
|
+
];
|
|
181
|
+
}
|
|
182
|
+
if (entry.type === "branch_summary" && entry.summary) {
|
|
183
|
+
return [createBranchSummaryMessage(entry.summary, entry.fromId, entry.timestamp)];
|
|
184
|
+
}
|
|
185
|
+
if (entry.type === "compaction") {
|
|
186
|
+
return [createCompactionSummaryMessage(entry.summary, entry.tokensBefore, entry.timestamp)];
|
|
187
|
+
}
|
|
188
|
+
return [];
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Build the active, compaction-aware session entry list.
|
|
192
|
+
*
|
|
193
|
+
* This follows the current leaf path. If the path contains compaction entries,
|
|
194
|
+
* the latest compaction is represented by the compaction entry itself, followed
|
|
195
|
+
* by the kept entries starting at firstKeptEntryId and all entries after the
|
|
196
|
+
* compaction entry. Older summarized entries are omitted.
|
|
197
|
+
*/
|
|
198
|
+
export function buildContextEntries(entries, leafId, byId) {
|
|
199
|
+
const path = buildSessionPath(entries, leafId, byId);
|
|
200
|
+
let compaction = null;
|
|
201
|
+
for (const entry of path) {
|
|
202
|
+
if (entry.type === "compaction") {
|
|
203
|
+
compaction = entry;
|
|
206
204
|
}
|
|
207
205
|
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
206
|
+
if (!compaction) {
|
|
207
|
+
return path;
|
|
208
|
+
}
|
|
209
|
+
const compactionIdx = path.findIndex((entry) => entry.id === compaction.id);
|
|
210
|
+
if (compactionIdx < 0) {
|
|
211
|
+
return path;
|
|
212
|
+
}
|
|
213
|
+
const contextEntries = [compaction];
|
|
214
|
+
let foundFirstKept = false;
|
|
215
|
+
for (let i = 0; i < compactionIdx; i++) {
|
|
216
|
+
const entry = path[i];
|
|
217
|
+
if (entry.id === compaction.firstKeptEntryId) {
|
|
218
|
+
foundFirstKept = true;
|
|
219
|
+
}
|
|
220
|
+
if (foundFirstKept) {
|
|
221
|
+
contextEntries.push(entry);
|
|
212
222
|
}
|
|
213
223
|
}
|
|
224
|
+
contextEntries.push(...path.slice(compactionIdx + 1));
|
|
225
|
+
return contextEntries;
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Build the session context from entries using tree traversal.
|
|
229
|
+
* If leafId is provided, walks from that entry to root.
|
|
230
|
+
* Handles compaction and branch summaries along the path.
|
|
231
|
+
*/
|
|
232
|
+
export function buildSessionContext(entries, leafId, byId) {
|
|
233
|
+
const path = buildSessionPath(entries, leafId, byId);
|
|
234
|
+
const { thinkingLevel, model } = getSessionContextSettings(path);
|
|
235
|
+
const messages = buildContextEntries(entries, leafId, byId).flatMap(sessionEntryToContextMessages);
|
|
214
236
|
return { messages, thinkingLevel, model };
|
|
215
237
|
}
|
|
216
238
|
/**
|
|
@@ -532,10 +554,13 @@ export class SessionManager {
|
|
|
532
554
|
this.sessionFile = resolvePath(sessionFile);
|
|
533
555
|
if (existsSync(this.sessionFile)) {
|
|
534
556
|
this.fileEntries = loadEntriesFromFile(this.sessionFile);
|
|
535
|
-
// If file was empty
|
|
536
|
-
//
|
|
557
|
+
// If file was empty, initialize it with a valid session header. If it was
|
|
558
|
+
// non-empty but did not parse as a pi session, fail without modifying it.
|
|
537
559
|
if (this.fileEntries.length === 0) {
|
|
538
560
|
const explicitPath = this.sessionFile;
|
|
561
|
+
if (statSync(explicitPath).size > 0) {
|
|
562
|
+
throw new Error(`Session file is not a valid pi session: ${explicitPath}`);
|
|
563
|
+
}
|
|
539
564
|
this.newSession();
|
|
540
565
|
this.sessionFile = explicitPath;
|
|
541
566
|
this._rewriteFile();
|
|
@@ -573,6 +598,7 @@ export class SessionManager {
|
|
|
573
598
|
this.fileEntries = [header];
|
|
574
599
|
this.byId.clear();
|
|
575
600
|
this.labelsById.clear();
|
|
601
|
+
this.labelTimestampsById.clear();
|
|
576
602
|
this.leafId = null;
|
|
577
603
|
this.flushed = false;
|
|
578
604
|
if (this.persist) {
|
|
@@ -743,12 +769,13 @@ export class SessionManager {
|
|
|
743
769
|
}
|
|
744
770
|
/** Append a session info entry (e.g., display name). Returns entry id. */
|
|
745
771
|
appendSessionInfo(name) {
|
|
772
|
+
const sanitizedName = name.replace(/[\r\n]+/g, " ").trim();
|
|
746
773
|
const entry = {
|
|
747
774
|
type: "session_info",
|
|
748
775
|
id: generateId(this.byId),
|
|
749
776
|
parentId: this.leafId,
|
|
750
777
|
timestamp: new Date().toISOString(),
|
|
751
|
-
name:
|
|
778
|
+
name: sanitizedName,
|
|
752
779
|
};
|
|
753
780
|
this._appendEntry(entry);
|
|
754
781
|
return entry.id;
|
|
@@ -856,11 +883,19 @@ export class SessionManager {
|
|
|
856
883
|
const startId = fromId ?? this.leafId;
|
|
857
884
|
let current = startId ? this.byId.get(startId) : undefined;
|
|
858
885
|
while (current) {
|
|
859
|
-
path.
|
|
886
|
+
path.push(current);
|
|
860
887
|
current = current.parentId ? this.byId.get(current.parentId) : undefined;
|
|
861
888
|
}
|
|
889
|
+
path.reverse();
|
|
862
890
|
return path;
|
|
863
891
|
}
|
|
892
|
+
/**
|
|
893
|
+
* Build the active, compaction-aware entry list for context/rendering.
|
|
894
|
+
* Uses tree traversal from current leaf.
|
|
895
|
+
*/
|
|
896
|
+
buildContextEntries() {
|
|
897
|
+
return buildContextEntries(this.getEntries(), this.leafId, this.byId);
|
|
898
|
+
}
|
|
864
899
|
/**
|
|
865
900
|
* Build the session context (what gets sent to the LLM).
|
|
866
901
|
* Uses tree traversal from current leaf.
|
|
@@ -982,8 +1017,17 @@ export class SessionManager {
|
|
|
982
1017
|
if (path.length === 0) {
|
|
983
1018
|
throw new Error(`Entry ${leafId} not found`);
|
|
984
1019
|
}
|
|
985
|
-
// Filter out LabelEntry from path - we'll recreate them from the resolved map
|
|
986
|
-
|
|
1020
|
+
// Filter out LabelEntry from path - we'll recreate them from the resolved map.
|
|
1021
|
+
// Because labels are real tree entries, later entries can be children of labels;
|
|
1022
|
+
// removing labels requires re-chaining the retained path to avoid orphaned subtrees.
|
|
1023
|
+
const pathWithoutLabels = [];
|
|
1024
|
+
let pathParentId = null;
|
|
1025
|
+
for (const entry of path) {
|
|
1026
|
+
if (entry.type === "label")
|
|
1027
|
+
continue;
|
|
1028
|
+
pathWithoutLabels.push({ ...entry, parentId: pathParentId });
|
|
1029
|
+
pathParentId = entry.id;
|
|
1030
|
+
}
|
|
987
1031
|
const newSessionId = createSessionId();
|
|
988
1032
|
const timestamp = new Date().toISOString();
|
|
989
1033
|
const fileTimestamp = timestamp.replace(/[:.]/g, "-");
|
|
@@ -1101,8 +1145,8 @@ export class SessionManager {
|
|
|
1101
1145
|
return new SessionManager(cwd, dir, undefined, true);
|
|
1102
1146
|
}
|
|
1103
1147
|
/** Create an in-memory session (no file persistence) */
|
|
1104
|
-
static inMemory(cwd = process.cwd()) {
|
|
1105
|
-
return new SessionManager(cwd, "", undefined, false);
|
|
1148
|
+
static inMemory(cwd = process.cwd(), options) {
|
|
1149
|
+
return new SessionManager(cwd, "", undefined, false, options);
|
|
1106
1150
|
}
|
|
1107
1151
|
/**
|
|
1108
1152
|
* Fork a session from another project directory into the current project.
|