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) {
const triggerCompaction = (ctx: ExtensionContext, customInstructions?: string) => {
if (ctx.hasUI) {
ctx.ui.notify("Compaction started", "info");
}
ctx.compact({
customInstructions,
onComplete: () => {
if (ctx.hasUI) {
ctx.ui.notify("Compaction completed", "info");
}
},
onError: (error) => {
if (ctx.hasUI) {
ctx.ui.notify(`Compaction failed: ${error.message}`, "error");

View file

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