refactor(auto): rename promptParts → promptCacheSplit in run-unit path
The cache-split signal {before, after} was named promptParts in the
autonomous-unit dispatch path, overloading the same term that
.agent.yaml uses for declarative prompt-section composition. With the
prompt-parts runtime landing as canonical (`aiSafety`,
`toolInstructions`, ...), the overload becomes confusing —
promptParts now means "list of declarative section keys", not
"before/after cache-split tuple".
Renames in run-unit.js, phases-unit.js (call site), and
run-unit.test.mjs. No behavior change.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
289bf9e264
commit
6851869c00
3 changed files with 20 additions and 17 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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 },
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue