Phase 14: defer reinject plan without registry at compaction — B-002 stage 1
planDeferredReinject locks pending by kept-window only; defer path in index uses it while immediate keeps registered filter at compact time. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+5
-1
@@ -23,6 +23,7 @@ import {
|
||||
import {
|
||||
applyPendingReinjectAfterCompact,
|
||||
clearPendingReinjectOnUserPrompt,
|
||||
planDeferredReinject,
|
||||
planReinject,
|
||||
sendImmediateReinjectAllFollowUp,
|
||||
sendImmediateReinjectIdle,
|
||||
@@ -102,7 +103,6 @@ export default function skillReinject(pi: ExtensionAPI): void {
|
||||
const trackedNames = state.skills.map((skill) => skill.name);
|
||||
const keptEntries = getKeptEntries(branch, event.compactionEntry.firstKeptEntryId);
|
||||
const keptPresent = skillsPresentInKeptWindow(keptEntries, trackedNames);
|
||||
const planned = planReinject(state, settings, ctx, event, skills);
|
||||
const shouldReinject = consumeCompactionOnSessionCompact(
|
||||
compactionRuntime,
|
||||
state,
|
||||
@@ -110,6 +110,10 @@ export default function skillReinject(pi: ExtensionAPI): void {
|
||||
settings,
|
||||
);
|
||||
const deliveryMode = resolveDeliveryMode(settings, runtime, state.sessionIntegrationOverride);
|
||||
const planned =
|
||||
deliveryMode === "defer"
|
||||
? planDeferredReinject(state, ctx, event)
|
||||
: planReinject(state, settings, ctx, event, skills);
|
||||
|
||||
applyPendingReinjectAfterCompact(state, compactionRuntime, shouldReinject, planned);
|
||||
notifyReinjectDiag(
|
||||
|
||||
+30
-13
@@ -9,6 +9,7 @@ import { existsSync } from "node:fs";
|
||||
import { expandSkill } from "./expand.js";
|
||||
import {
|
||||
filterSkillsNeedingReinject,
|
||||
filterSkillsNeedingReinjectByKept,
|
||||
getKeptEntries,
|
||||
skillsPresentInKeptWindow,
|
||||
} from "./kept.js";
|
||||
@@ -57,6 +58,31 @@ export function registeredSkillNames(skills: readonly Pick<Skill, "name">[]): Re
|
||||
return new Set(skills.map((skill) => skill.name));
|
||||
}
|
||||
|
||||
/** Kept-window skill names present after compaction (shared by plan helpers). */
|
||||
function keptPresentAfterCompaction(
|
||||
state: ExtensionState,
|
||||
ctx: ExtensionContext,
|
||||
compactionEvent: SessionCompactEvent,
|
||||
): Set<string> {
|
||||
const branch = ctx.sessionManager.getBranch();
|
||||
const keptEntries = getKeptEntries(branch, compactionEvent.compactionEntry.firstKeptEntryId);
|
||||
const trackedNames = state.skills.map((skill) => skill.name);
|
||||
return skillsPresentInKeptWindow(keptEntries, trackedNames);
|
||||
}
|
||||
|
||||
/**
|
||||
* Defer planning at compaction: tracked skills absent from kept window only (SPEC §6.5.1).
|
||||
* Registry filter runs later on before_agent_start (Phase 14 / B-002).
|
||||
*/
|
||||
export function planDeferredReinject(
|
||||
state: ExtensionState,
|
||||
ctx: ExtensionContext,
|
||||
compactionEvent: SessionCompactEvent,
|
||||
): string[] {
|
||||
const keptPresent = keptPresentAfterCompaction(state, ctx, compactionEvent);
|
||||
return filterSkillsNeedingReinjectByKept(state.skills, keptPresent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Skill names to re-inject after compaction: tracked, absent from kept window, still registered (SPEC §5.2).
|
||||
* `registeredSkills` comes from resourceLoader — ExtensionContext has no getSkills(); wired in index.ts.
|
||||
@@ -68,10 +94,7 @@ export function planReinject(
|
||||
compactionEvent: SessionCompactEvent,
|
||||
registeredSkills: readonly Pick<Skill, "name">[],
|
||||
): string[] {
|
||||
const branch = ctx.sessionManager.getBranch();
|
||||
const keptEntries = getKeptEntries(branch, compactionEvent.compactionEntry.firstKeptEntryId);
|
||||
const trackedNames = state.skills.map((skill) => skill.name);
|
||||
const keptPresent = skillsPresentInKeptWindow(keptEntries, trackedNames);
|
||||
const keptPresent = keptPresentAfterCompaction(state, ctx, compactionEvent);
|
||||
return filterSkillsNeedingReinject(
|
||||
state.skills,
|
||||
keptPresent,
|
||||
@@ -82,18 +105,12 @@ export function planReinject(
|
||||
/** Defer path on session_compact: queue planned skills without sendUserMessage (SPEC §6.5.1, §16.2). */
|
||||
export function enqueueDeferredReinjectFromCompact(
|
||||
state: ExtensionState,
|
||||
settings: SkillReinjectSettings,
|
||||
_settings: SkillReinjectSettings,
|
||||
ctx: ExtensionContext,
|
||||
compactionEvent: SessionCompactEvent,
|
||||
registeredSkills: readonly Pick<Skill, "name">[],
|
||||
_registeredSkills: readonly Pick<Skill, "name">[],
|
||||
): void {
|
||||
state.pendingReinject = planReinject(
|
||||
state,
|
||||
settings,
|
||||
ctx,
|
||||
compactionEvent,
|
||||
registeredSkills,
|
||||
);
|
||||
state.pendingReinject = planDeferredReinject(state, ctx, compactionEvent);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user