Skip to content

Commit e7993f7

Browse files
engineerCopilot
andcommitted
fix: clean up set_reflection implementation (#134)
- Remove unused toolReflectionPrompt parameter from buildSelfAssessmentPrompt - Add truncation warning in executeSetReflection when guidance exceeds 4000 chars - Rename resolveReflectionPrompt → resolveReflectionPromptPrecedence for consistency - Add unit tests for buildToolReflectionGuidanceSection edge cases Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 3b00fa8 commit e7993f7

2 files changed

Lines changed: 39 additions & 8 deletions

File tree

‎reflection-3.ts‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ function buildToolReflectionGuidanceSection(toolReflectionPrompt: string | null)
210210
return `\n## Tool Reflection Guidance\n${toolReflectionPrompt.slice(0, 4000)}\n`
211211
}
212212

213-
function resolveReflectionPrompt(
213+
function resolveReflectionPromptPrecedence(
214214
filePrompt: string | null,
215215
toolReflectionPrompt: string | null,
216216
defaultPrompt: string
@@ -1054,8 +1054,7 @@ function buildSelfAssessmentPrompt(
10541054
context: TaskContext,
10551055
agents: string,
10561056
lastAssistantText?: string,
1057-
attemptCount?: number,
1058-
toolReflectionPrompt?: string | null
1057+
attemptCount?: number
10591058
): string {
10601059
const safeContext = {
10611060
...context,
@@ -1080,8 +1079,6 @@ function buildSelfAssessmentPrompt(
10801079
const attemptSection = currentAttempt > 0
10811080
? `\n## Reflection History\n- This is reflection attempt ${currentAttempt + 1}/${MAX_ATTEMPTS} for this task.\n- Previous reflections found the task incomplete.\n- If you are repeating the same actions without progress, set "stuck": true and explain what is blocking you.\n`
10821081
: ""
1083-
const toolGuidanceSection = buildToolReflectionGuidanceSection(toolReflectionPrompt || null)
1084-
10851082
return `SELF-ASSESS REFLECTION-3
10861083
10871084
You are evaluating an agent's work against workflow requirements.
@@ -1097,7 +1094,6 @@ Analyze the task context, the agent's last response, and the tool signals to det
10971094
## Tool Commands Run
10981095
${safeContext.toolsSummary}
10991096
${assistantSection}${attemptSection}
1100-
${toolGuidanceSection}
11011097
${agents ? `## Project Instructions\n${agents.slice(0, 800)}\n\n` : ""}Return JSON only:
11021098
{
11031099
"task_summary": "brief description of what was done",
@@ -1571,7 +1567,9 @@ export const Reflection3Plugin: Plugin = async ({ client, directory }) => {
15711567
return `Current tool-provided reflection guidance:\n${toolReflectionPrompt}`
15721568
}
15731569
toolReflectionPrompt = guidance
1574-
return "Set tool-provided reflection guidance for this runtime. It will be used when no .reflection.md/reflection.md file override exists."
1570+
const msg = "Set tool-provided reflection guidance for this runtime. It will be used when no .reflection.md/reflection.md file override exists."
1571+
if (guidance.length > 4000) return `${msg}\n\nNote: guidance exceeds 4000 chars and will be truncated when applied to reflection prompts.`
1572+
return msg
15751573
}
15761574

15771575
let setReflectionTool: any = null
@@ -1650,7 +1648,7 @@ export const Reflection3Plugin: Plugin = async ({ client, directory }) => {
16501648
lastAssistantText,
16511649
currentAttemptCount
16521650
)
1653-
const resolvedPrompt = resolveReflectionPrompt(customPrompt, toolReflectionPrompt, defaultReflectionPrompt)
1651+
const resolvedPrompt = resolveReflectionPromptPrecedence(customPrompt, toolReflectionPrompt, defaultReflectionPrompt)
16541652
const reflectionPrompt = resolvedPrompt.prompt
16551653
const effectiveToolReflectionPrompt = resolvedPrompt.effectiveToolReflectionPrompt
16561654

‎test/reflection-3.unit.test.ts‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,39 @@ describe("reflection-3 unit", () => {
9696
assert.ok(!resolved.prompt.includes("TOOL REFLECTION OVERRIDE"))
9797
})
9898

99+
describe("set_reflection tool helpers", () => {
100+
it("buildToolReflectionGuidanceSection(null) => empty string", () => {
101+
assert.strictEqual(buildToolReflectionGuidanceSection(null), "")
102+
})
103+
104+
it("buildToolReflectionGuidanceSection(\"\") => empty string", () => {
105+
assert.strictEqual(buildToolReflectionGuidanceSection(""), "")
106+
})
107+
108+
it("wraps guidance in section header", () => {
109+
const section = buildToolReflectionGuidanceSection("Check tests and CI")
110+
assert.ok(section.startsWith("\n## Tool Reflection Guidance\n"))
111+
assert.ok(section.includes("Check tests and CI"))
112+
})
113+
114+
it("truncates guidance at 4000 chars", () => {
115+
const longGuidance = "x".repeat(5000)
116+
const section = buildToolReflectionGuidanceSection(longGuidance)
117+
assert.ok(section.startsWith("\n## Tool Reflection Guidance\n"))
118+
assert.ok(section.endsWith("\n"))
119+
const body = section.replace("\n## Tool Reflection Guidance\n", "").slice(0, -1)
120+
assert.strictEqual(body.length, 4000)
121+
assert.strictEqual(body, "x".repeat(4000))
122+
})
123+
124+
it("resolveReflectionPromptPrecedence returns default when no file/tool guidance", () => {
125+
const resolved = resolveReflectionPromptPrecedence(null, null, "DEFAULT REFLECTION PROMPT")
126+
assert.strictEqual(resolved.source, "default")
127+
assert.strictEqual(resolved.prompt, "DEFAULT REFLECTION PROMPT")
128+
assert.strictEqual(resolved.effectiveToolReflectionPrompt, null)
129+
})
130+
})
131+
99132
it("evaluates missing tests and build requirements", () => {
100133
const assessment = {
101134
status: "complete" as const,

0 commit comments

Comments
 (0)