@draht/coding-agent 2026.4.5 → 2026.4.25-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +804 -625
- package/README.md +24 -15
- package/dist/cli/args.d.ts +7 -10
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +44 -46
- package/dist/cli/args.js.map +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +1 -0
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts +9 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +18 -0
- package/dist/config.js.map +1 -1
- package/dist/core/agent-session-runtime.d.ts +53 -106
- package/dist/core/agent-session-runtime.d.ts.map +1 -1
- package/dist/core/agent-session-runtime.js +116 -147
- package/dist/core/agent-session-runtime.js.map +1 -1
- package/dist/core/agent-session-services.d.ts +86 -0
- package/dist/core/agent-session-services.d.ts.map +1 -0
- package/dist/core/agent-session-services.js +116 -0
- package/dist/core/agent-session-services.js.map +1 -0
- package/dist/core/agent-session.d.ts +8 -12
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +134 -45
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/bash-executor.d.ts.map +1 -1
- package/dist/core/bash-executor.js +19 -7
- package/dist/core/bash-executor.js.map +1 -1
- package/dist/core/compaction/compaction.d.ts +1 -1
- package/dist/core/compaction/compaction.d.ts.map +1 -1
- package/dist/core/compaction/compaction.js +18 -17
- package/dist/core/compaction/compaction.js.map +1 -1
- 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.map +1 -1
- package/dist/core/extensions/loader.js +7 -7
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/runner.d.ts +1 -0
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +4 -0
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/types.d.ts +15 -14
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/index.d.ts +2 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +2 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/keybindings.d.ts +14 -1
- package/dist/core/keybindings.d.ts.map +1 -1
- package/dist/core/keybindings.js +13 -14
- package/dist/core/keybindings.js.map +1 -1
- package/dist/core/model-registry.d.ts.map +1 -1
- package/dist/core/model-registry.js +31 -1
- package/dist/core/model-registry.js.map +1 -1
- package/dist/core/package-manager.d.ts +21 -1
- package/dist/core/package-manager.d.ts.map +1 -1
- package/dist/core/package-manager.js +108 -43
- package/dist/core/package-manager.js.map +1 -1
- package/dist/core/prompt-templates.d.ts.map +1 -1
- package/dist/core/prompt-templates.js +22 -21
- package/dist/core/prompt-templates.js.map +1 -1
- package/dist/core/resource-loader.d.ts +0 -2
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +26 -8
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/sdk.d.ts +2 -2
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +2 -2
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/session-cwd.d.ts +19 -0
- package/dist/core/session-cwd.d.ts.map +1 -0
- package/dist/core/session-cwd.js +38 -0
- package/dist/core/session-cwd.js.map +1 -0
- package/dist/core/session-manager.d.ts +5 -1
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +16 -8
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/settings-manager.d.ts +6 -4
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +5 -1
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/skills.d.ts +1 -1
- package/dist/core/skills.d.ts.map +1 -1
- package/dist/core/skills.js +3 -3
- package/dist/core/skills.js.map +1 -1
- package/dist/core/system-prompt.d.ts.map +1 -1
- package/dist/core/system-prompt.js +6 -6
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/core/timings.d.ts +1 -0
- package/dist/core/timings.d.ts.map +1 -1
- package/dist/core/timings.js +6 -0
- package/dist/core/timings.js.map +1 -1
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +19 -9
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/edit-diff.d.ts +23 -1
- package/dist/core/tools/edit-diff.d.ts.map +1 -1
- package/dist/core/tools/edit-diff.js +150 -57
- package/dist/core/tools/edit-diff.js.map +1 -1
- package/dist/core/tools/edit.d.ts +13 -11
- package/dist/core/tools/edit.d.ts.map +1 -1
- package/dist/core/tools/edit.js +55 -77
- package/dist/core/tools/edit.js.map +1 -1
- package/dist/core/tools/file-mutation-queue.d.ts.map +1 -1
- package/dist/core/tools/file-mutation-queue.js +4 -4
- package/dist/core/tools/file-mutation-queue.js.map +1 -1
- package/dist/core/tools/index.d.ts +9 -6
- package/dist/core/tools/index.d.ts.map +1 -1
- package/dist/core/tools/tool-definition-wrapper.d.ts.map +1 -1
- package/dist/core/tools/tool-definition-wrapper.js +2 -0
- package/dist/core/tools/tool-definition-wrapper.js.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -5
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +252 -451
- package/dist/main.js.map +1 -1
- package/dist/migrations.d.ts +3 -3
- package/dist/migrations.d.ts.map +1 -1
- package/dist/migrations.js +25 -5
- package/dist/migrations.js.map +1 -1
- 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 +14 -3
- package/dist/modes/interactive/components/assistant-message.js.map +1 -1
- package/dist/modes/interactive/components/earendil-announcement.d.ts +5 -0
- package/dist/modes/interactive/components/earendil-announcement.d.ts.map +1 -0
- package/dist/modes/interactive/components/earendil-announcement.js +40 -0
- package/dist/modes/interactive/components/earendil-announcement.js.map +1 -0
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector.js +1 -0
- package/dist/modes/interactive/components/settings-selector.js.map +1 -1
- package/dist/modes/interactive/components/thinking-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/thinking-selector.js +1 -0
- package/dist/modes/interactive/components/thinking-selector.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts +0 -1
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +2 -7
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/components/tree-selector.d.ts +4 -2
- package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/tree-selector.js +48 -15
- package/dist/modes/interactive/components/tree-selector.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +12 -3
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +237 -125
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/theme/dark.json +8 -5
- package/dist/modes/interactive/theme/light.json +8 -5
- package/dist/modes/interactive/theme/theme-schema.json +6 -1
- package/dist/modes/interactive/theme/theme.d.ts +2 -2
- package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
- package/dist/modes/interactive/theme/theme.js +13 -1
- package/dist/modes/interactive/theme/theme.js.map +1 -1
- package/dist/modes/print-mode.d.ts +4 -4
- package/dist/modes/print-mode.d.ts.map +1 -1
- package/dist/modes/print-mode.js +6 -2
- package/dist/modes/print-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-client.js +1 -0
- package/dist/modes/rpc/rpc-client.js.map +1 -1
- package/dist/modes/rpc/rpc-mode.d.ts +2 -2
- package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-mode.js +26 -15
- package/dist/modes/rpc/rpc-mode.js.map +1 -1
- package/dist/package-manager-cli.d.ts +4 -0
- package/dist/package-manager-cli.d.ts.map +1 -0
- package/dist/package-manager-cli.js +234 -0
- package/dist/package-manager-cli.js.map +1 -0
- package/dist/prompts/commands/atomic-commit.md +17 -0
- package/dist/prompts/commands/discuss-phase.md +15 -0
- package/dist/prompts/commands/execute-phase.md +14 -0
- package/dist/prompts/commands/fix.md +14 -0
- package/dist/prompts/commands/init-project.md +16 -0
- package/dist/prompts/commands/map-codebase.md +16 -0
- package/dist/prompts/commands/new-project.md +16 -0
- package/dist/prompts/commands/next-milestone.md +16 -0
- package/dist/prompts/commands/orchestrate.md +57 -0
- package/dist/prompts/commands/pause-work.md +13 -0
- package/dist/prompts/commands/plan-phase.md +15 -0
- package/dist/prompts/commands/progress.md +13 -0
- package/dist/prompts/commands/quick.md +14 -0
- package/dist/prompts/commands/resume-work.md +13 -0
- package/dist/prompts/commands/review.md +15 -0
- package/dist/prompts/commands/verify-work.md +15 -0
- package/dist/utils/paths.d.ts +7 -0
- package/dist/utils/paths.d.ts.map +1 -0
- package/dist/utils/paths.js +19 -0
- package/dist/utils/paths.js.map +1 -0
- package/docs/compaction.md +5 -3
- package/docs/custom-provider.md +1 -1
- package/docs/development.md +3 -1
- package/docs/extensions.md +150 -54
- package/docs/json.md +5 -2
- package/docs/keybindings.md +2 -0
- package/docs/models.md +55 -4
- package/docs/rpc.md +21 -7
- package/docs/sdk.md +116 -48
- package/docs/session.md +3 -3
- package/docs/settings.md +12 -0
- package/docs/skills.md +3 -2
- package/docs/tree.md +5 -2
- package/examples/README.md +1 -1
- package/examples/extensions/README.md +1 -0
- package/examples/extensions/antigravity-image-gen.ts +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/index.ts +1 -1
- package/examples/extensions/doom-overlay/doom/build.sh +2 -2
- package/examples/extensions/hidden-thinking-label.ts +53 -0
- package/examples/extensions/overlay-qa-tests.ts +2 -2
- package/examples/extensions/sandbox/index.ts +8 -4
- package/examples/extensions/subagent/index.ts +5 -5
- package/examples/extensions/trigger-compact.ts +11 -1
- package/examples/sdk/13-session-runtime.ts +30 -12
- package/examples/sdk/README.md +4 -2
- package/package.json +7 -8
- package/prompts/commands/atomic-commit.md +17 -0
- package/prompts/commands/discuss-phase.md +15 -0
- package/prompts/commands/execute-phase.md +14 -0
- package/prompts/commands/fix.md +14 -0
- package/prompts/commands/init-project.md +16 -0
- package/prompts/commands/map-codebase.md +16 -0
- package/prompts/commands/new-project.md +16 -0
- package/prompts/commands/next-milestone.md +16 -0
- package/prompts/commands/orchestrate.md +57 -0
- package/prompts/commands/pause-work.md +13 -0
- package/prompts/commands/plan-phase.md +15 -0
- package/prompts/commands/progress.md +13 -0
- package/prompts/commands/quick.md +14 -0
- package/prompts/commands/resume-work.md +13 -0
- package/prompts/commands/review.md +15 -0
- package/prompts/commands/verify-work.md +15 -0
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
*/
|
|
15
15
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
16
16
|
import { basename, dirname, join, resolve } from "node:path";
|
|
17
|
-
import { isContextOverflow, modelsAreEqual, resetApiProviders, supportsXhigh } from "@draht/ai";
|
|
17
|
+
import { isContextOverflow, modelsAreEqual, resetApiProviders, supportsMax, supportsXhigh } from "@draht/ai";
|
|
18
18
|
import { getDocsPath } from "../config.js";
|
|
19
19
|
import { theme } from "../modes/interactive/theme/theme.js";
|
|
20
20
|
import { stripFrontmatter } from "../utils/frontmatter.js";
|
|
@@ -54,6 +54,8 @@ export function parseSkillBlock(text) {
|
|
|
54
54
|
const THINKING_LEVELS = ["off", "minimal", "low", "medium", "high"];
|
|
55
55
|
/** Thinking levels including xhigh (for supported models) */
|
|
56
56
|
const THINKING_LEVELS_WITH_XHIGH = ["off", "minimal", "low", "medium", "high", "xhigh"];
|
|
57
|
+
/** Thinking levels including xhigh and max (Anthropic Opus only) */
|
|
58
|
+
const THINKING_LEVELS_WITH_MAX = ["off", "minimal", "low", "medium", "high", "xhigh", "max"];
|
|
57
59
|
// ============================================================================
|
|
58
60
|
// AgentSession Class
|
|
59
61
|
// ============================================================================
|
|
@@ -163,7 +165,7 @@ export class AgentSession {
|
|
|
163
165
|
* happens here instead of in wrappers.
|
|
164
166
|
*/
|
|
165
167
|
_installAgentToolHooks() {
|
|
166
|
-
this.agent.
|
|
168
|
+
this.agent.beforeToolCall = async ({ toolCall, args }) => {
|
|
167
169
|
const runner = this._extensionRunner;
|
|
168
170
|
if (!runner?.hasHandlers("tool_call")) {
|
|
169
171
|
return undefined;
|
|
@@ -183,8 +185,8 @@ export class AgentSession {
|
|
|
183
185
|
}
|
|
184
186
|
throw new Error(`Extension failed, blocking execution: ${String(err)}`);
|
|
185
187
|
}
|
|
186
|
-
}
|
|
187
|
-
this.agent.
|
|
188
|
+
};
|
|
189
|
+
this.agent.afterToolCall = async ({ toolCall, args, result, isError }) => {
|
|
188
190
|
const runner = this._extensionRunner;
|
|
189
191
|
if (!runner?.hasHandlers("tool_result")) {
|
|
190
192
|
return undefined;
|
|
@@ -205,7 +207,7 @@ export class AgentSession {
|
|
|
205
207
|
content: hookResult.content,
|
|
206
208
|
details: hookResult.details,
|
|
207
209
|
};
|
|
208
|
-
}
|
|
210
|
+
};
|
|
209
211
|
}
|
|
210
212
|
// =========================================================================
|
|
211
213
|
// Event Subscription
|
|
@@ -216,6 +218,13 @@ export class AgentSession {
|
|
|
216
218
|
l(event);
|
|
217
219
|
}
|
|
218
220
|
}
|
|
221
|
+
_emitQueueUpdate() {
|
|
222
|
+
this._emit({
|
|
223
|
+
type: "queue_update",
|
|
224
|
+
steering: [...this._steeringMessages],
|
|
225
|
+
followUp: [...this._followUpMessages],
|
|
226
|
+
});
|
|
227
|
+
}
|
|
219
228
|
// Track last assistant message for auto-compaction check
|
|
220
229
|
_lastAssistantMessage = undefined;
|
|
221
230
|
/** Internal handler for agent events - shared by subscribe and reconnect */
|
|
@@ -266,12 +275,14 @@ export class AgentSession {
|
|
|
266
275
|
const steeringIndex = this._steeringMessages.indexOf(messageText);
|
|
267
276
|
if (steeringIndex !== -1) {
|
|
268
277
|
this._steeringMessages.splice(steeringIndex, 1);
|
|
278
|
+
this._emitQueueUpdate();
|
|
269
279
|
}
|
|
270
280
|
else {
|
|
271
281
|
// Check follow-up queue
|
|
272
282
|
const followUpIndex = this._followUpMessages.indexOf(messageText);
|
|
273
283
|
if (followUpIndex !== -1) {
|
|
274
284
|
this._followUpMessages.splice(followUpIndex, 1);
|
|
285
|
+
this._emitQueueUpdate();
|
|
275
286
|
}
|
|
276
287
|
}
|
|
277
288
|
}
|
|
@@ -544,10 +555,10 @@ export class AgentSession {
|
|
|
544
555
|
validToolNames.push(name);
|
|
545
556
|
}
|
|
546
557
|
}
|
|
547
|
-
this.agent.
|
|
558
|
+
this.agent.state.tools = tools;
|
|
548
559
|
// Rebuild base system prompt with new tool set
|
|
549
560
|
this._baseSystemPrompt = this._rebuildSystemPrompt(validToolNames);
|
|
550
|
-
this.agent.
|
|
561
|
+
this.agent.state.systemPrompt = this._baseSystemPrompt;
|
|
551
562
|
}
|
|
552
563
|
/** Whether compaction or branch summarization is currently running */
|
|
553
564
|
get isCompacting() {
|
|
@@ -561,11 +572,11 @@ export class AgentSession {
|
|
|
561
572
|
}
|
|
562
573
|
/** Current steering mode */
|
|
563
574
|
get steeringMode() {
|
|
564
|
-
return this.agent.
|
|
575
|
+
return this.agent.steeringMode;
|
|
565
576
|
}
|
|
566
577
|
/** Current follow-up mode */
|
|
567
578
|
get followUpMode() {
|
|
568
|
-
return this.agent.
|
|
579
|
+
return this.agent.followUpMode;
|
|
569
580
|
}
|
|
570
581
|
/** Current session file path, or undefined if sessions are disabled */
|
|
571
582
|
get sessionFile() {
|
|
@@ -756,11 +767,11 @@ export class AgentSession {
|
|
|
756
767
|
}
|
|
757
768
|
// Apply extension-modified system prompt, or reset to base
|
|
758
769
|
if (result?.systemPrompt) {
|
|
759
|
-
this.agent.
|
|
770
|
+
this.agent.state.systemPrompt = result.systemPrompt;
|
|
760
771
|
}
|
|
761
772
|
else {
|
|
762
773
|
// Ensure we're using the base prompt (in case previous turn had modifications)
|
|
763
|
-
this.agent.
|
|
774
|
+
this.agent.state.systemPrompt = this._baseSystemPrompt;
|
|
764
775
|
}
|
|
765
776
|
}
|
|
766
777
|
await this.agent.prompt(messages);
|
|
@@ -865,6 +876,7 @@ export class AgentSession {
|
|
|
865
876
|
*/
|
|
866
877
|
async _queueSteer(text, images) {
|
|
867
878
|
this._steeringMessages.push(text);
|
|
879
|
+
this._emitQueueUpdate();
|
|
868
880
|
const content = [{ type: "text", text }];
|
|
869
881
|
if (images) {
|
|
870
882
|
content.push(...images);
|
|
@@ -880,6 +892,7 @@ export class AgentSession {
|
|
|
880
892
|
*/
|
|
881
893
|
async _queueFollowUp(text, images) {
|
|
882
894
|
this._followUpMessages.push(text);
|
|
895
|
+
this._emitQueueUpdate();
|
|
883
896
|
const content = [{ type: "text", text }];
|
|
884
897
|
if (images) {
|
|
885
898
|
content.push(...images);
|
|
@@ -939,7 +952,7 @@ export class AgentSession {
|
|
|
939
952
|
await this.agent.prompt(appMessage);
|
|
940
953
|
}
|
|
941
954
|
else {
|
|
942
|
-
this.agent.
|
|
955
|
+
this.agent.state.messages.push(appMessage);
|
|
943
956
|
this.sessionManager.appendCustomMessageEntry(message.customType, message.content, message.display, message.details);
|
|
944
957
|
this._emit({ type: "message_start", message: appMessage });
|
|
945
958
|
this._emit({ type: "message_end", message: appMessage });
|
|
@@ -993,6 +1006,7 @@ export class AgentSession {
|
|
|
993
1006
|
this._steeringMessages = [];
|
|
994
1007
|
this._followUpMessages = [];
|
|
995
1008
|
this.agent.clearAllQueues();
|
|
1009
|
+
this._emitQueueUpdate();
|
|
996
1010
|
return { steering, followUp };
|
|
997
1011
|
}
|
|
998
1012
|
/** Number of pending messages (includes both steering and follow-up) */
|
|
@@ -1044,7 +1058,7 @@ export class AgentSession {
|
|
|
1044
1058
|
}
|
|
1045
1059
|
const previousModel = this.model;
|
|
1046
1060
|
const thinkingLevel = this._getThinkingLevelForModelSwitch();
|
|
1047
|
-
this.agent.
|
|
1061
|
+
this.agent.state.model = model;
|
|
1048
1062
|
this.sessionManager.appendModelChange(model.provider, model.id);
|
|
1049
1063
|
this.settingsManager.setDefaultModelAndProvider(model.provider, model.id);
|
|
1050
1064
|
// Re-clamp thinking level for new model's capabilities
|
|
@@ -1076,7 +1090,7 @@ export class AgentSession {
|
|
|
1076
1090
|
const next = scopedModels[nextIndex];
|
|
1077
1091
|
const thinkingLevel = this._getThinkingLevelForModelSwitch(next.thinkingLevel);
|
|
1078
1092
|
// Apply model
|
|
1079
|
-
this.agent.
|
|
1093
|
+
this.agent.state.model = next.model;
|
|
1080
1094
|
this.sessionManager.appendModelChange(next.model.provider, next.model.id);
|
|
1081
1095
|
this.settingsManager.setDefaultModelAndProvider(next.model.provider, next.model.id);
|
|
1082
1096
|
// Apply thinking level.
|
|
@@ -1099,7 +1113,7 @@ export class AgentSession {
|
|
|
1099
1113
|
const nextIndex = direction === "forward" ? (currentIndex + 1) % len : (currentIndex - 1 + len) % len;
|
|
1100
1114
|
const nextModel = availableModels[nextIndex];
|
|
1101
1115
|
const thinkingLevel = this._getThinkingLevelForModelSwitch();
|
|
1102
|
-
this.agent.
|
|
1116
|
+
this.agent.state.model = nextModel;
|
|
1103
1117
|
this.sessionManager.appendModelChange(nextModel.provider, nextModel.id);
|
|
1104
1118
|
this.settingsManager.setDefaultModelAndProvider(nextModel.provider, nextModel.id);
|
|
1105
1119
|
// Re-clamp thinking level for new model's capabilities
|
|
@@ -1120,7 +1134,7 @@ export class AgentSession {
|
|
|
1120
1134
|
const effectiveLevel = availableLevels.includes(level) ? level : this._clampThinkingLevel(level, availableLevels);
|
|
1121
1135
|
// Only persist if actually changing
|
|
1122
1136
|
const isChanging = effectiveLevel !== this.agent.state.thinkingLevel;
|
|
1123
|
-
this.agent.
|
|
1137
|
+
this.agent.state.thinkingLevel = effectiveLevel;
|
|
1124
1138
|
if (isChanging) {
|
|
1125
1139
|
this.sessionManager.appendThinkingLevelChange(effectiveLevel);
|
|
1126
1140
|
if (this.supportsThinking() || effectiveLevel !== "off") {
|
|
@@ -1149,6 +1163,8 @@ export class AgentSession {
|
|
|
1149
1163
|
getAvailableThinkingLevels() {
|
|
1150
1164
|
if (!this.supportsThinking())
|
|
1151
1165
|
return ["off"];
|
|
1166
|
+
if (this.supportsMaxThinking())
|
|
1167
|
+
return THINKING_LEVELS_WITH_MAX;
|
|
1152
1168
|
return this.supportsXhighThinking() ? THINKING_LEVELS_WITH_XHIGH : THINKING_LEVELS;
|
|
1153
1169
|
}
|
|
1154
1170
|
/**
|
|
@@ -1157,6 +1173,12 @@ export class AgentSession {
|
|
|
1157
1173
|
supportsXhighThinking() {
|
|
1158
1174
|
return this.model ? supportsXhigh(this.model) : false;
|
|
1159
1175
|
}
|
|
1176
|
+
/**
|
|
1177
|
+
* Check if current model supports the `max` thinking level (Anthropic Opus 4.6/4.7 only).
|
|
1178
|
+
*/
|
|
1179
|
+
supportsMaxThinking() {
|
|
1180
|
+
return this.model ? supportsMax(this.model) : false;
|
|
1181
|
+
}
|
|
1160
1182
|
/**
|
|
1161
1183
|
* Check if current model supports thinking/reasoning.
|
|
1162
1184
|
*/
|
|
@@ -1173,7 +1195,7 @@ export class AgentSession {
|
|
|
1173
1195
|
return this.thinkingLevel;
|
|
1174
1196
|
}
|
|
1175
1197
|
_clampThinkingLevel(level, availableLevels) {
|
|
1176
|
-
const ordered =
|
|
1198
|
+
const ordered = THINKING_LEVELS_WITH_MAX;
|
|
1177
1199
|
const available = new Set(availableLevels);
|
|
1178
1200
|
const requestedIndex = ordered.indexOf(level);
|
|
1179
1201
|
if (requestedIndex === -1) {
|
|
@@ -1199,7 +1221,7 @@ export class AgentSession {
|
|
|
1199
1221
|
* Saves to settings.
|
|
1200
1222
|
*/
|
|
1201
1223
|
setSteeringMode(mode) {
|
|
1202
|
-
this.agent.
|
|
1224
|
+
this.agent.steeringMode = mode;
|
|
1203
1225
|
this.settingsManager.setSteeringMode(mode);
|
|
1204
1226
|
}
|
|
1205
1227
|
/**
|
|
@@ -1207,7 +1229,7 @@ export class AgentSession {
|
|
|
1207
1229
|
* Saves to settings.
|
|
1208
1230
|
*/
|
|
1209
1231
|
setFollowUpMode(mode) {
|
|
1210
|
-
this.agent.
|
|
1232
|
+
this.agent.followUpMode = mode;
|
|
1211
1233
|
this.settingsManager.setFollowUpMode(mode);
|
|
1212
1234
|
}
|
|
1213
1235
|
// =========================================================================
|
|
@@ -1222,6 +1244,7 @@ export class AgentSession {
|
|
|
1222
1244
|
this._disconnectFromAgent();
|
|
1223
1245
|
await this.abort();
|
|
1224
1246
|
this._compactionAbortController = new AbortController();
|
|
1247
|
+
this._emit({ type: "compaction_start", reason: "manual" });
|
|
1225
1248
|
try {
|
|
1226
1249
|
if (!this.model) {
|
|
1227
1250
|
throw new Error("No model selected");
|
|
@@ -1281,7 +1304,7 @@ export class AgentSession {
|
|
|
1281
1304
|
this.sessionManager.appendCompaction(summary, firstKeptEntryId, tokensBefore, details, fromExtension);
|
|
1282
1305
|
const newEntries = this.sessionManager.getEntries();
|
|
1283
1306
|
const sessionContext = this.sessionManager.buildSessionContext();
|
|
1284
|
-
this.agent.
|
|
1307
|
+
this.agent.state.messages = sessionContext.messages;
|
|
1285
1308
|
// Get the saved compaction entry for the extension event
|
|
1286
1309
|
const savedCompactionEntry = newEntries.find((e) => e.type === "compaction" && e.summary === summary);
|
|
1287
1310
|
if (this._extensionRunner && savedCompactionEntry) {
|
|
@@ -1291,12 +1314,33 @@ export class AgentSession {
|
|
|
1291
1314
|
fromExtension,
|
|
1292
1315
|
});
|
|
1293
1316
|
}
|
|
1294
|
-
|
|
1317
|
+
const compactionResult = {
|
|
1295
1318
|
summary,
|
|
1296
1319
|
firstKeptEntryId,
|
|
1297
1320
|
tokensBefore,
|
|
1298
1321
|
details,
|
|
1299
1322
|
};
|
|
1323
|
+
this._emit({
|
|
1324
|
+
type: "compaction_end",
|
|
1325
|
+
reason: "manual",
|
|
1326
|
+
result: compactionResult,
|
|
1327
|
+
aborted: false,
|
|
1328
|
+
willRetry: false,
|
|
1329
|
+
});
|
|
1330
|
+
return compactionResult;
|
|
1331
|
+
}
|
|
1332
|
+
catch (error) {
|
|
1333
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1334
|
+
const aborted = message === "Compaction cancelled" || (error instanceof Error && error.name === "AbortError");
|
|
1335
|
+
this._emit({
|
|
1336
|
+
type: "compaction_end",
|
|
1337
|
+
reason: "manual",
|
|
1338
|
+
result: undefined,
|
|
1339
|
+
aborted,
|
|
1340
|
+
willRetry: false,
|
|
1341
|
+
errorMessage: aborted ? undefined : `Compaction failed: ${message}`,
|
|
1342
|
+
});
|
|
1343
|
+
throw error;
|
|
1300
1344
|
}
|
|
1301
1345
|
finally {
|
|
1302
1346
|
this._compactionAbortController = undefined;
|
|
@@ -1352,7 +1396,8 @@ export class AgentSession {
|
|
|
1352
1396
|
if (sameModel && isContextOverflow(assistantMessage, contextWindow)) {
|
|
1353
1397
|
if (this._overflowRecoveryAttempted) {
|
|
1354
1398
|
this._emit({
|
|
1355
|
-
type: "
|
|
1399
|
+
type: "compaction_end",
|
|
1400
|
+
reason: "overflow",
|
|
1356
1401
|
result: undefined,
|
|
1357
1402
|
aborted: false,
|
|
1358
1403
|
willRetry: false,
|
|
@@ -1365,7 +1410,7 @@ export class AgentSession {
|
|
|
1365
1410
|
// but we don't want it in context for the retry)
|
|
1366
1411
|
const messages = this.agent.state.messages;
|
|
1367
1412
|
if (messages.length > 0 && messages[messages.length - 1].role === "assistant") {
|
|
1368
|
-
this.agent.
|
|
1413
|
+
this.agent.state.messages = messages.slice(0, -1);
|
|
1369
1414
|
}
|
|
1370
1415
|
await this._runAutoCompaction("overflow", true);
|
|
1371
1416
|
return;
|
|
@@ -1375,9 +1420,19 @@ export class AgentSession {
|
|
|
1375
1420
|
// This ensures sessions that hit persistent API errors (e.g. 529) can still compact.
|
|
1376
1421
|
let contextTokens;
|
|
1377
1422
|
if (assistantMessage.stopReason === "error") {
|
|
1378
|
-
const
|
|
1423
|
+
const messages = this.agent.state.messages;
|
|
1424
|
+
const estimate = estimateContextTokens(messages);
|
|
1379
1425
|
if (estimate.lastUsageIndex === null)
|
|
1380
1426
|
return; // No usage data at all
|
|
1427
|
+
// Verify the usage source is post-compaction. Kept pre-compaction messages
|
|
1428
|
+
// have stale usage reflecting the old (larger) context and would falsely
|
|
1429
|
+
// trigger compaction right after one just finished.
|
|
1430
|
+
const usageMsg = messages[estimate.lastUsageIndex];
|
|
1431
|
+
if (compactionEntry &&
|
|
1432
|
+
usageMsg.role === "assistant" &&
|
|
1433
|
+
usageMsg.timestamp <= new Date(compactionEntry.timestamp).getTime()) {
|
|
1434
|
+
return;
|
|
1435
|
+
}
|
|
1381
1436
|
contextTokens = estimate.tokens;
|
|
1382
1437
|
}
|
|
1383
1438
|
else {
|
|
@@ -1392,23 +1447,41 @@ export class AgentSession {
|
|
|
1392
1447
|
*/
|
|
1393
1448
|
async _runAutoCompaction(reason, willRetry) {
|
|
1394
1449
|
const settings = this.settingsManager.getCompactionSettings();
|
|
1395
|
-
this._emit({ type: "
|
|
1450
|
+
this._emit({ type: "compaction_start", reason });
|
|
1396
1451
|
this._autoCompactionAbortController = new AbortController();
|
|
1397
1452
|
try {
|
|
1398
1453
|
if (!this.model) {
|
|
1399
|
-
this._emit({
|
|
1454
|
+
this._emit({
|
|
1455
|
+
type: "compaction_end",
|
|
1456
|
+
reason,
|
|
1457
|
+
result: undefined,
|
|
1458
|
+
aborted: false,
|
|
1459
|
+
willRetry: false,
|
|
1460
|
+
});
|
|
1400
1461
|
return;
|
|
1401
1462
|
}
|
|
1402
1463
|
const authResult = await this._modelRegistry.getApiKeyAndHeaders(this.model);
|
|
1403
1464
|
if (!authResult.ok || !authResult.apiKey) {
|
|
1404
|
-
this._emit({
|
|
1465
|
+
this._emit({
|
|
1466
|
+
type: "compaction_end",
|
|
1467
|
+
reason,
|
|
1468
|
+
result: undefined,
|
|
1469
|
+
aborted: false,
|
|
1470
|
+
willRetry: false,
|
|
1471
|
+
});
|
|
1405
1472
|
return;
|
|
1406
1473
|
}
|
|
1407
1474
|
const { apiKey, headers } = authResult;
|
|
1408
1475
|
const pathEntries = this.sessionManager.getBranch();
|
|
1409
1476
|
const preparation = prepareCompaction(pathEntries, settings);
|
|
1410
1477
|
if (!preparation) {
|
|
1411
|
-
this._emit({
|
|
1478
|
+
this._emit({
|
|
1479
|
+
type: "compaction_end",
|
|
1480
|
+
reason,
|
|
1481
|
+
result: undefined,
|
|
1482
|
+
aborted: false,
|
|
1483
|
+
willRetry: false,
|
|
1484
|
+
});
|
|
1412
1485
|
return;
|
|
1413
1486
|
}
|
|
1414
1487
|
let extensionCompaction;
|
|
@@ -1422,7 +1495,13 @@ export class AgentSession {
|
|
|
1422
1495
|
signal: this._autoCompactionAbortController.signal,
|
|
1423
1496
|
}));
|
|
1424
1497
|
if (extensionResult?.cancel) {
|
|
1425
|
-
this._emit({
|
|
1498
|
+
this._emit({
|
|
1499
|
+
type: "compaction_end",
|
|
1500
|
+
reason,
|
|
1501
|
+
result: undefined,
|
|
1502
|
+
aborted: true,
|
|
1503
|
+
willRetry: false,
|
|
1504
|
+
});
|
|
1426
1505
|
return;
|
|
1427
1506
|
}
|
|
1428
1507
|
if (extensionResult?.compaction) {
|
|
@@ -1450,13 +1529,19 @@ export class AgentSession {
|
|
|
1450
1529
|
details = compactResult.details;
|
|
1451
1530
|
}
|
|
1452
1531
|
if (this._autoCompactionAbortController.signal.aborted) {
|
|
1453
|
-
this._emit({
|
|
1532
|
+
this._emit({
|
|
1533
|
+
type: "compaction_end",
|
|
1534
|
+
reason,
|
|
1535
|
+
result: undefined,
|
|
1536
|
+
aborted: true,
|
|
1537
|
+
willRetry: false,
|
|
1538
|
+
});
|
|
1454
1539
|
return;
|
|
1455
1540
|
}
|
|
1456
1541
|
this.sessionManager.appendCompaction(summary, firstKeptEntryId, tokensBefore, details, fromExtension);
|
|
1457
1542
|
const newEntries = this.sessionManager.getEntries();
|
|
1458
1543
|
const sessionContext = this.sessionManager.buildSessionContext();
|
|
1459
|
-
this.agent.
|
|
1544
|
+
this.agent.state.messages = sessionContext.messages;
|
|
1460
1545
|
// Get the saved compaction entry for the extension event
|
|
1461
1546
|
const savedCompactionEntry = newEntries.find((e) => e.type === "compaction" && e.summary === summary);
|
|
1462
1547
|
if (this._extensionRunner && savedCompactionEntry) {
|
|
@@ -1472,12 +1557,12 @@ export class AgentSession {
|
|
|
1472
1557
|
tokensBefore,
|
|
1473
1558
|
details,
|
|
1474
1559
|
};
|
|
1475
|
-
this._emit({ type: "
|
|
1560
|
+
this._emit({ type: "compaction_end", reason, result, aborted: false, willRetry });
|
|
1476
1561
|
if (willRetry) {
|
|
1477
1562
|
const messages = this.agent.state.messages;
|
|
1478
1563
|
const lastMsg = messages[messages.length - 1];
|
|
1479
1564
|
if (lastMsg?.role === "assistant" && lastMsg.stopReason === "error") {
|
|
1480
|
-
this.agent.
|
|
1565
|
+
this.agent.state.messages = messages.slice(0, -1);
|
|
1481
1566
|
}
|
|
1482
1567
|
setTimeout(() => {
|
|
1483
1568
|
this.agent.continue().catch(() => { });
|
|
@@ -1494,7 +1579,8 @@ export class AgentSession {
|
|
|
1494
1579
|
catch (error) {
|
|
1495
1580
|
const errorMessage = error instanceof Error ? error.message : "compaction failed";
|
|
1496
1581
|
this._emit({
|
|
1497
|
-
type: "
|
|
1582
|
+
type: "compaction_end",
|
|
1583
|
+
reason,
|
|
1498
1584
|
result: undefined,
|
|
1499
1585
|
aborted: false,
|
|
1500
1586
|
willRetry: false,
|
|
@@ -1551,7 +1637,7 @@ export class AgentSession {
|
|
|
1551
1637
|
};
|
|
1552
1638
|
this._resourceLoader.extendResources(extensionPaths);
|
|
1553
1639
|
this._baseSystemPrompt = this._rebuildSystemPrompt(this.getActiveToolNames());
|
|
1554
|
-
this.agent.
|
|
1640
|
+
this.agent.state.systemPrompt = this._baseSystemPrompt;
|
|
1555
1641
|
}
|
|
1556
1642
|
buildExtensionResourcePaths(entries) {
|
|
1557
1643
|
return entries.map((entry) => {
|
|
@@ -1593,7 +1679,7 @@ export class AgentSession {
|
|
|
1593
1679
|
if (!refreshedModel || refreshedModel === currentModel) {
|
|
1594
1680
|
return;
|
|
1595
1681
|
}
|
|
1596
|
-
this.agent.
|
|
1682
|
+
this.agent.state.model = refreshedModel;
|
|
1597
1683
|
}
|
|
1598
1684
|
_bindExtensionCore(runner) {
|
|
1599
1685
|
const getCommands = () => {
|
|
@@ -1664,6 +1750,7 @@ export class AgentSession {
|
|
|
1664
1750
|
}, {
|
|
1665
1751
|
getModel: () => this.model,
|
|
1666
1752
|
isIdle: () => !this.isStreaming,
|
|
1753
|
+
getSignal: () => this.agent.signal,
|
|
1667
1754
|
abort: () => this.abort(),
|
|
1668
1755
|
hasPendingMessages: () => this.pendingMessageCount > 0,
|
|
1669
1756
|
shutdown: () => {
|
|
@@ -1803,7 +1890,7 @@ export class AgentSession {
|
|
|
1803
1890
|
async reload() {
|
|
1804
1891
|
const previousFlagValues = this._extensionRunner?.getFlagValues();
|
|
1805
1892
|
await this._extensionRunner?.emit({ type: "session_shutdown" });
|
|
1806
|
-
this.settingsManager.reload();
|
|
1893
|
+
await this.settingsManager.reload();
|
|
1807
1894
|
resetApiProviders();
|
|
1808
1895
|
await this._resourceLoader.reload();
|
|
1809
1896
|
this._buildRuntime({
|
|
@@ -1835,8 +1922,8 @@ export class AgentSession {
|
|
|
1835
1922
|
if (isContextOverflow(message, contextWindow))
|
|
1836
1923
|
return false;
|
|
1837
1924
|
const err = message.errorMessage;
|
|
1838
|
-
// Match: overloaded_error, provider returned error, rate limit, 429, 500, 502, 503, 504, service unavailable, network/connection errors, fetch failed, terminated, retry delay exceeded
|
|
1839
|
-
return /overloaded|provider.?returned.?error|rate.?limit|too many requests|429|500|502|503|504|service.?unavailable|server.?error|internal.?error|network.?error|connection.?error|connection.?refused|other side closed|fetch failed|upstream.?connect|reset before headers|socket hang up|timed? out|timeout|terminated|retry delay/i.test(err);
|
|
1925
|
+
// Match: overloaded_error, provider returned error, rate limit, 429, 500, 502, 503, 504, service unavailable, network/connection errors, fetch failed, request ended without sending chunks, terminated, retry delay exceeded, peer-closed/incomplete-chunked stream truncations
|
|
1926
|
+
return /overloaded|provider.?returned.?error|rate.?limit|too many requests|429|500|502|503|504|service.?unavailable|server.?error|internal.?error|network.?error|connection.?error|connection.?refused|connection.?reset|peer closed|other side closed|fetch failed|upstream.?connect|reset before headers|socket hang up|ended without|incomplete.?chunked.?read|chunked.?read|premature.?close|timed? out|timeout|terminated|retry delay/i.test(err);
|
|
1840
1927
|
}
|
|
1841
1928
|
/**
|
|
1842
1929
|
* Handle retryable errors with exponential backoff.
|
|
@@ -1879,7 +1966,7 @@ export class AgentSession {
|
|
|
1879
1966
|
// Remove error message from agent state (keep in session for history)
|
|
1880
1967
|
const messages = this.agent.state.messages;
|
|
1881
1968
|
if (messages.length > 0 && messages[messages.length - 1].role === "assistant") {
|
|
1882
|
-
this.agent.
|
|
1969
|
+
this.agent.state.messages = messages.slice(0, -1);
|
|
1883
1970
|
}
|
|
1884
1971
|
// Wait with exponential backoff (abortable)
|
|
1885
1972
|
this._retryAbortController = new AbortController();
|
|
@@ -1922,9 +2009,11 @@ export class AgentSession {
|
|
|
1922
2009
|
* Returns immediately if no retry is in progress.
|
|
1923
2010
|
*/
|
|
1924
2011
|
async waitForRetry() {
|
|
1925
|
-
if (this._retryPromise) {
|
|
1926
|
-
|
|
2012
|
+
if (!this._retryPromise) {
|
|
2013
|
+
return;
|
|
1927
2014
|
}
|
|
2015
|
+
await this._retryPromise;
|
|
2016
|
+
await this.agent.waitForIdle();
|
|
1928
2017
|
}
|
|
1929
2018
|
/** Whether auto-retry is currently in progress */
|
|
1930
2019
|
get isRetrying() {
|
|
@@ -1991,7 +2080,7 @@ export class AgentSession {
|
|
|
1991
2080
|
}
|
|
1992
2081
|
else {
|
|
1993
2082
|
// Add to agent state immediately
|
|
1994
|
-
this.agent.
|
|
2083
|
+
this.agent.state.messages.push(bashMessage);
|
|
1995
2084
|
// Save to session
|
|
1996
2085
|
this.sessionManager.appendMessage(bashMessage);
|
|
1997
2086
|
}
|
|
@@ -2019,7 +2108,7 @@ export class AgentSession {
|
|
|
2019
2108
|
return;
|
|
2020
2109
|
for (const bashMessage of this._pendingBashMessages) {
|
|
2021
2110
|
// Add to agent state
|
|
2022
|
-
this.agent.
|
|
2111
|
+
this.agent.state.messages.push(bashMessage);
|
|
2023
2112
|
// Save to session
|
|
2024
2113
|
this.sessionManager.appendMessage(bashMessage);
|
|
2025
2114
|
}
|
|
@@ -2189,7 +2278,7 @@ export class AgentSession {
|
|
|
2189
2278
|
}
|
|
2190
2279
|
// Update agent state
|
|
2191
2280
|
const sessionContext = this.sessionManager.buildSessionContext();
|
|
2192
|
-
this.agent.
|
|
2281
|
+
this.agent.state.messages = sessionContext.messages;
|
|
2193
2282
|
// Emit session_tree event
|
|
2194
2283
|
if (this._extensionRunner) {
|
|
2195
2284
|
await this._extensionRunner.emit({
|