Phase 6: add compaction coexistence hint — one-time notify when both compactors run.

Shows ui.notify once when pi-auto-compact is detected while Pi compaction.enabled stays true.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-06-17 11:47:27 +07:00
parent 2e6d36a855
commit bf862656ae
3 changed files with 112 additions and 1 deletions
+56 -1
View File
@@ -1,4 +1,5 @@
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
import { SettingsManager, getAgentDir } from "@earendil-works/pi-coding-agent";
import {
effectiveIntegration,
type ReinjectDeliveryMode,
@@ -33,3 +34,57 @@ export const PI_AUTO_COMPACT_FOLLOW_UP_PREFIXES = [
"Emergency auto-compact ran.",
"Auto-compact ran on session resume.",
] as const;
const PI_DEFAULT_COMPACTION_ENABLED = true;
function readCompactionEnabled(settings: object): boolean | undefined {
const compaction = (settings as Record<string, unknown>).compaction;
if (!compaction || typeof compaction !== "object" || Array.isArray(compaction)) {
return undefined;
}
const enabled = (compaction as Record<string, unknown>).enabled;
return typeof enabled === "boolean" ? enabled : undefined;
}
/** Merged Pi compaction.enabled with project-over-global semantics (SPEC §16.7). */
export function resolvePiDefaultCompactionEnabled(
globalSettings: object,
projectSettings: object,
): boolean {
return (
readCompactionEnabled(projectSettings) ??
readCompactionEnabled(globalSettings) ??
PI_DEFAULT_COMPACTION_ENABLED
);
}
export function isPiDefaultCompactionEnabled(ctx: ExtensionContext): boolean {
const manager = SettingsManager.create(ctx.cwd, getAgentDir(), {
projectTrusted: ctx.isProjectTrusted(),
});
return resolvePiDefaultCompactionEnabled(
manager.getGlobalSettings(),
manager.getProjectSettings(),
);
}
/** One-time ui.notify when Pi default compaction and pi-auto-compact are both active (SPEC §16.7). */
export function maybeNotifyCompactionCoexistenceHint(
ctx: ExtensionContext,
runtime: RuntimeFlags,
piDefaultCompactionEnabled = isPiDefaultCompactionEnabled(ctx),
): void {
if (runtime.compactionCoexistenceHintShown || !runtime.autoCompactDetected) {
return;
}
if (!piDefaultCompactionEnabled) {
return;
}
if (ctx.hasUI) {
ctx.ui.notify(
"Pi built-in auto-compaction and pi-auto-compact are both enabled. Consider setting compaction.enabled to false in settings.json.",
"info",
);
}
runtime.compactionCoexistenceHintShown = true;
}
+3
View File
@@ -31,6 +31,8 @@ export interface ExtensionState {
export interface RuntimeFlags {
autoCompactDetected: boolean;
autoCompactIntegration: AutoCompactIntegration;
/** One-time hint when Pi default compaction coexists with pi-auto-compact (SPEC §16.7). */
compactionCoexistenceHintShown: boolean;
}
export const STATE_ENTRY_TYPE = "skill-reinject:state";
@@ -84,6 +86,7 @@ export function createRuntimeFlags(): RuntimeFlags {
return {
autoCompactDetected: false,
autoCompactIntegration: "auto",
compactionCoexistenceHintShown: false,
};
}