fix(coding-agent): show compaction UI for extensions

This commit is contained in:
Mario Zechner 2026-01-17 11:48:54 +01:00
parent 9d3f8117a4
commit 05ee8e3334
2 changed files with 22 additions and 6 deletions

View file

@ -4,8 +4,16 @@ const COMPACT_THRESHOLD_TOKENS = 100_000;
export default function (pi: ExtensionAPI) { export default function (pi: ExtensionAPI) {
const triggerCompaction = (ctx: ExtensionContext, customInstructions?: string) => { const triggerCompaction = (ctx: ExtensionContext, customInstructions?: string) => {
if (ctx.hasUI) {
ctx.ui.notify("Compaction started", "info");
}
ctx.compact({ ctx.compact({
customInstructions, customInstructions,
onComplete: () => {
if (ctx.hasUI) {
ctx.ui.notify("Compaction completed", "info");
}
},
onError: (error) => { onError: (error) => {
if (ctx.hasUI) { if (ctx.hasUI) {
ctx.ui.notify(`Compaction failed: ${error.message}`, "error"); ctx.ui.notify(`Compaction failed: ${error.message}`, "error");

View file

@ -44,6 +44,7 @@ import {
import { spawn, spawnSync } from "child_process"; import { spawn, spawnSync } from "child_process";
import { APP_NAME, getAuthPath, getDebugLogPath, isBunBinary, isBunRuntime, VERSION } from "../../config.js"; import { APP_NAME, getAuthPath, getDebugLogPath, isBunBinary, isBunRuntime, VERSION } from "../../config.js";
import type { AgentSession, AgentSessionEvent } from "../../core/agent-session.js"; import type { AgentSession, AgentSessionEvent } from "../../core/agent-session.js";
import type { CompactionResult } from "../../core/compaction/index.js";
import type { import type {
ExtensionContext, ExtensionContext,
ExtensionRunner, ExtensionRunner,
@ -693,8 +694,10 @@ export class InteractiveMode {
compact: (options) => { compact: (options) => {
void (async () => { void (async () => {
try { try {
const result = await this.session.compact(options?.customInstructions); const result = await this.executeCompaction(options?.customInstructions, false);
options?.onComplete?.(result); if (result) {
options?.onComplete?.(result);
}
} catch (error) { } catch (error) {
const err = error instanceof Error ? error : new Error(String(error)); const err = error instanceof Error ? error : new Error(String(error));
options?.onError?.(err); options?.onError?.(err);
@ -829,8 +832,10 @@ export class InteractiveMode {
compact: (options) => { compact: (options) => {
void (async () => { void (async () => {
try { try {
const result = await this.session.compact(options?.customInstructions); const result = await this.executeCompaction(options?.customInstructions, false);
options?.onComplete?.(result); if (result) {
options?.onComplete?.(result);
}
} catch (error) { } catch (error) {
const err = error instanceof Error ? error : new Error(String(error)); const err = error instanceof Error ? error : new Error(String(error));
options?.onError?.(err); options?.onError?.(err);
@ -3677,7 +3682,7 @@ export class InteractiveMode {
await this.executeCompaction(customInstructions, false); await this.executeCompaction(customInstructions, false);
} }
private async executeCompaction(customInstructions?: string, isAuto = false): Promise<void> { private async executeCompaction(customInstructions?: string, isAuto = false): Promise<CompactionResult | undefined> {
// Stop loading animation // Stop loading animation
if (this.loadingAnimation) { if (this.loadingAnimation) {
this.loadingAnimation.stop(); this.loadingAnimation.stop();
@ -3704,8 +3709,10 @@ export class InteractiveMode {
this.statusContainer.addChild(compactingLoader); this.statusContainer.addChild(compactingLoader);
this.ui.requestRender(); this.ui.requestRender();
let result: CompactionResult | undefined;
try { try {
const result = await this.session.compact(customInstructions); result = await this.session.compact(customInstructions);
// Rebuild UI // Rebuild UI
this.rebuildChatFromMessages(); this.rebuildChatFromMessages();
@ -3728,6 +3735,7 @@ export class InteractiveMode {
this.defaultEditor.onEscape = originalOnEscape; this.defaultEditor.onEscape = originalOnEscape;
} }
void this.flushCompactionQueue({ willRetry: false }); void this.flushCompactionQueue({ willRetry: false });
return result;
} }
stop(): void { stop(): void {