diff --git a/src/resources/extensions/sf/auto/phases-unit.js b/src/resources/extensions/sf/auto/phases-unit.js index e7818a0c1..6227605c4 100644 --- a/src/resources/extensions/sf/auto/phases-unit.js +++ b/src/resources/extensions/sf/auto/phases-unit.js @@ -522,11 +522,11 @@ export async function runUnitPhase(ic, iterData, loopState, sidecarItem) { } // Cache-optimize prompt section ordering; split at the semi-static→dynamic // boundary so providers can mark the stable prefix with cache_control:ephemeral. - let promptParts = null; + let promptCacheSplit = null; try { - promptParts = deps.reorderAndSplitForCaching?.(finalPrompt) ?? null; - if (promptParts) { - finalPrompt = promptParts.before + "\n" + promptParts.after; + promptCacheSplit = deps.reorderAndSplitForCaching?.(finalPrompt) ?? null; + if (promptCacheSplit) { + finalPrompt = promptCacheSplit.before + "\n" + promptCacheSplit.after; } else { finalPrompt = deps.reorderForCaching(finalPrompt); } @@ -729,7 +729,7 @@ export async function runUnitPhase(ic, iterData, loopState, sidecarItem) { unitId, }); const unitResult = await runUnit(ctx, pi, s, unitType, unitId, finalPrompt, { - promptParts: promptParts ?? undefined, + promptCacheSplit: promptCacheSplit ?? undefined, }); s.lastUnitAgentEndMessages = unitResult.event?.messages ?? null; let currentUnitResult = unitResult; diff --git a/src/resources/extensions/sf/auto/run-unit.js b/src/resources/extensions/sf/auto/run-unit.js index 6aca7f81c..3e4e54781 100644 --- a/src/resources/extensions/sf/auto/run-unit.js +++ b/src/resources/extensions/sf/auto/run-unit.js @@ -40,15 +40,15 @@ let sessionSwitchGeneration = 0; * * Consumer: runUnit before pi.sendMessage dispatches the autonomous unit turn. */ -export function buildUnitPromptMessageContent(prompt, promptParts) { - if (!promptParts) return prompt; +export function buildUnitPromptMessageContent(prompt, promptCacheSplit) { + if (!promptCacheSplit) return prompt; return [ { type: "text", - text: `${promptParts.before}\n`, + text: `${promptCacheSplit.before}\n`, cache_control: { type: "ephemeral" }, }, - { type: "text", text: promptParts.after }, + { type: "text", text: promptCacheSplit.after }, ]; } @@ -98,10 +98,10 @@ export function scopeActiveToolsForRunUnit( */ export async function runUnit(ctx, pi, s, unitType, unitId, prompt, options) { const keepSession = options?.keepSession === true; - // promptParts: {before, after} — stable prefix (to cache) + dynamic suffix. + // promptCacheSplit: {before, after} — stable prefix (to cache) + dynamic suffix. // When present, passes the content as a two-block array so providers can mark // the stable prefix with cache_control:ephemeral. - const promptParts = options?.promptParts ?? null; + const promptCacheSplit = options?.promptCacheSplit ?? null; debugLog("runUnit", { phase: "start", unitType, unitId, keepSession }); // GAP-10: Ensure cwd matches basePath BEFORE newSession() captures it. The // new session reads process.cwd() during construction to anchor its tool @@ -313,10 +313,13 @@ export async function runUnit(ctx, pi, s, unitType, unitId, prompt, options) { } } try { - // When promptParts is available, send structured content so the provider can - // apply cache_control:ephemeral to the stable prefix (before) while leaving - // the dynamic suffix (after) uncached. - const messageContent = buildUnitPromptMessageContent(prompt, promptParts); + // When a cache split is available, send structured content so the provider + // can apply cache_control:ephemeral to the stable prefix while leaving the + // dynamic suffix uncached. + const messageContent = buildUnitPromptMessageContent( + prompt, + promptCacheSplit, + ); await pi.sendMessage( { customType: "sf-auto", content: messageContent, display: s.verbose }, { triggerTurn: true }, diff --git a/src/resources/extensions/sf/tests/run-unit.test.mjs b/src/resources/extensions/sf/tests/run-unit.test.mjs index 92675b13b..adeb45e01 100644 --- a/src/resources/extensions/sf/tests/run-unit.test.mjs +++ b/src/resources/extensions/sf/tests/run-unit.test.mjs @@ -6,7 +6,7 @@ import { scopeActiveToolsForRunUnit, } from "../auto/run-unit.js"; -test("buildUnitPromptMessageContent_when_prompt_parts_present_preserves_join_boundary", () => { +test("buildUnitPromptMessageContent_when_cache_split_present_preserves_join_boundary", () => { const content = buildUnitPromptMessageContent("flat", { before: "## Working Directory\n/repo", after: "## Inlined Task Plan\nDo it.", @@ -28,7 +28,7 @@ test("buildUnitPromptMessageContent_when_prompt_parts_present_preserves_join_bou ); }); -test("buildUnitPromptMessageContent_when_no_prompt_parts_returns_flat_prompt", () => { +test("buildUnitPromptMessageContent_when_no_cache_split_returns_flat_prompt", () => { assert.equal(buildUnitPromptMessageContent("flat", null), "flat"); });