Phase 8: add shouldReinject gate and consume on session_compact — SPEC §8.
Evaluates enabled layer and compaction source, records lastCompactionSource, clears pending flag. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+33
-1
@@ -1,4 +1,5 @@
|
|||||||
import type { CompactionSource } from "./state.js";
|
import { effectiveEnabled, type SkillReinjectSettings } from "./settings.js";
|
||||||
|
import type { CompactionSource, ExtensionState } from "./state.js";
|
||||||
|
|
||||||
/** Runtime compaction-source detection between input → before_compact → session_compact (SPEC §8). */
|
/** Runtime compaction-source detection between input → before_compact → session_compact (SPEC §8). */
|
||||||
export interface CompactionRuntime {
|
export interface CompactionRuntime {
|
||||||
@@ -24,3 +25,34 @@ export function markAutoCompactionBeforeCompact(runtime: CompactionRuntime): voi
|
|||||||
runtime.pendingCompactionSource = "auto";
|
runtime.pendingCompactionSource = "auto";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Gate re-inject on session_compact from enabled layer and compaction source (SPEC §8). */
|
||||||
|
export function shouldReinjectAfterCompaction(
|
||||||
|
sessionOverride: boolean | null,
|
||||||
|
settings: SkillReinjectSettings,
|
||||||
|
runtime: CompactionRuntime,
|
||||||
|
): boolean {
|
||||||
|
if (!effectiveEnabled(sessionOverride, settings)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
runtime.pendingCompactionSource === "auto" ||
|
||||||
|
settings.reinjectOnManualCompaction
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* session_compact: evaluate gate, persist lastCompactionSource, clear pending (SPEC §8).
|
||||||
|
* Call before enqueueing deferred/immediate re-inject.
|
||||||
|
*/
|
||||||
|
export function consumeCompactionOnSessionCompact(
|
||||||
|
runtime: CompactionRuntime,
|
||||||
|
state: ExtensionState,
|
||||||
|
sessionOverride: boolean | null,
|
||||||
|
settings: SkillReinjectSettings,
|
||||||
|
): boolean {
|
||||||
|
const shouldReinject = shouldReinjectAfterCompaction(sessionOverride, settings, runtime);
|
||||||
|
state.lastCompactionSource = runtime.pendingCompactionSource;
|
||||||
|
runtime.pendingCompactionSource = null;
|
||||||
|
return shouldReinject;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user