From 45ccc31cf18b3e9cbdc1ae83783435030edb42f7 Mon Sep 17 00:00:00 2001 From: Satyam Khanna Date: Mon, 23 Nov 2026 15:50:52 +0530 Subject: [PATCH 1/2] fix(agents): stop lean workspace prompts referencing write_todos Workspace roots drop write_todos from their toolset, but a lean compaction policy still appended guidance telling them to write a todo plan. Pass the workspace flag through and keep the plan in the transcript instead. Fixes #1692. --- agents/__tests__/base3.test.ts | 14 ++++++++++++++ agents/base3.ts | 4 +++- agents/lean-context.ts | 20 ++++++++++++++++---- 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/agents/__tests__/base3.test.ts b/agents/__tests__/base3.test.ts index c719d4c2c4..f155575610 100644 --- a/agents/__tests__/base3.test.ts +++ b/agents/__tests__/base3.test.ts @@ -379,6 +379,20 @@ describe('a lean compaction policy', () => { test('keeps `lean` out of compactContext, whose schema is strict', () => { expect(lean.compactContext).toEqual(runtimePolicy) }) + + test('workspace roots get the budget without the todo tool they lack', () => { + // Desktop/Cloud workspace roots drop write_todos (agents/base3.ts), so + // telling them to write a todo plan leaves the guidance unactionable. + const workspaceLean = createBase3('anthropic/claude-haiku-5.5', { + compaction: LEAN_COMPACTION_POLICY, + workspace: true, + }) + expect(workspaceLean.systemPrompt).toContain('# Context budget') + expect(workspaceLean.systemPrompt).not.toContain('write_todos') + expect(workspaceLean.systemPrompt).not.toContain('your todos') + expect(workspaceLean.systemPrompt).toContain('keep a short plan in your reply') + expect(lean.systemPrompt).toContain('write_todos') + }) }) describe('working in batches', () => { diff --git a/agents/base3.ts b/agents/base3.ts index 25e52f4567..f0762e35f8 100644 --- a/agents/base3.ts +++ b/agents/base3.ts @@ -154,7 +154,9 @@ export function createBase3( options.compaction ?? compactionPolicyForModel(model) const leanGuidance = lean && compactContext.maxContextLength - ? `\n${leanContextGuidance(compactContext.maxContextLength)}\n` + ? `\n${leanContextGuidance(compactContext.maxContextLength, { + workspace: options.workspace, + })}\n` : '' const batching = options.batching === true && batchingModel && !lean return { diff --git a/agents/lean-context.ts b/agents/lean-context.ts index 11fdb0f3de..1752bc1796 100644 --- a/agents/lean-context.ts +++ b/agents/lean-context.ts @@ -9,10 +9,22 @@ import { compactionThreshold } from '@codebuff/common/constants/compaction-polic * often a run compacted. Telling the model to save context made it do less * work until the second paragraph said it must not, and the write_todos line * is what lets it resume after a pass (remaining todos survive in the - * summary). + * summary). Workspace roots have no write_todos, so for them that line is a + * short plan in the transcript instead. */ -export function leanContextGuidance(maxContextLength: number): string { +export function leanContextGuidance( + maxContextLength: number, + options: { workspace?: boolean } = {}, +): string { const condensedAt = Math.round(compactionThreshold(maxContextLength) / 1000) + // Desktop and Cloud workspace roots have no write_todos tool + // (agents/base3.ts drops it), so their plan has to live in the transcript. + const planGuidance = options.workspace + ? `- For any task with more than a couple of steps, keep a short plan in your reply and update it as you go. This workspace has no to-do tool; the plan in the transcript is what you check after condensing.` + : `- For any task with more than a couple of steps, write the plan with write_todos before editing and keep it current. Your remaining todos survive condensing, so they are how you pick up where you left off; without them you lose track of what is done.` + const stayGuidance = options.workspace + ? `- Stay within the request. After condensing, check your plan and the request before starting anything new rather than broadening the change.` + : `- Stay within the request. After condensing, check your todos and the request before starting anything new rather than broadening the change.` return `# Context budget Your context is small: everything you read or run stays in this conversation. When it grows past ~${condensedAt}k tokens it is condensed automatically: you keep the user's request, a log of your earlier messages and tool calls, the most recent file reads, and an outline with line numbers of the other files you read. Old tool output is gone after that, and files you edited are not carried over; re-read only the window you need, using the outline's line numbers. @@ -24,7 +36,7 @@ The budget limits how you read, never how much of the task you do. Do every part - Don't re-read lines you have already seen unless the file changed since. - Keep terminal output short: filter long output (grep, head, tail -n 50) while preserving the exit status. Still run the typecheck and the tests that cover your change. - Edit with str_replace rather than rewriting whole files. -- For any task with more than a couple of steps, write the plan with write_todos before editing and keep it current. Your remaining todos survive condensing, so they are how you pick up where you left off; without them you lose track of what is done. -- Stay within the request. After condensing, check your todos and the request before starting anything new rather than broadening the change. +${planGuidance} +${stayGuidance} - Before finishing, code_search for remaining references to anything you renamed, removed or changed the signature of, including tests, and update them.` } From 40e3d0de56933a0574d89afdfafb5223385abe19 Mon Sep 17 00:00:00 2001 From: Satyam Khanna Date: Tue, 24 Nov 2026 11:42:10 +0530 Subject: [PATCH 2/2] refactor(agents): build the lean guidance from one skeleton The workspace and non-workspace plan/stay bullets duplicated most of their wording, so a future edit could drift one branch. Both now come from a single sentence skeleton with the root-specific parts as values. The CLI text is unchanged byte for byte. --- agents/lean-context.ts | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/agents/lean-context.ts b/agents/lean-context.ts index 1752bc1796..8f07ad0736 100644 --- a/agents/lean-context.ts +++ b/agents/lean-context.ts @@ -19,12 +19,23 @@ export function leanContextGuidance( const condensedAt = Math.round(compactionThreshold(maxContextLength) / 1000) // Desktop and Cloud workspace roots have no write_todos tool // (agents/base3.ts drops it), so their plan has to live in the transcript. - const planGuidance = options.workspace - ? `- For any task with more than a couple of steps, keep a short plan in your reply and update it as you go. This workspace has no to-do tool; the plan in the transcript is what you check after condensing.` - : `- For any task with more than a couple of steps, write the plan with write_todos before editing and keep it current. Your remaining todos survive condensing, so they are how you pick up where you left off; without them you lose track of what is done.` - const stayGuidance = options.workspace - ? `- Stay within the request. After condensing, check your plan and the request before starting anything new rather than broadening the change.` - : `- Stay within the request. After condensing, check your todos and the request before starting anything new rather than broadening the change.` + const plan = options.workspace + ? { + write: 'keep a short plan in your reply and update it as you go', + survives: + 'This workspace has no to-do tool; the plan in the transcript is what you check after condensing.', + check: 'your plan', + } + : { + write: + 'write the plan with write_todos before editing and keep it current', + survives: + 'Your remaining todos survive condensing, so they are how you pick up where you left off; without them you lose track of what is done.', + check: 'your todos', + } + // One sentence skeleton, two variants: the non-workspace text stays as it was. + const planGuidance = `- For any task with more than a couple of steps, ${plan.write}. ${plan.survives}` + const stayGuidance = `- Stay within the request. After condensing, check ${plan.check} and the request before starting anything new rather than broadening the change.` return `# Context budget Your context is small: everything you read or run stays in this conversation. When it grows past ~${condensedAt}k tokens it is condensed automatically: you keep the user's request, a log of your earlier messages and tool calls, the most recent file reads, and an outline with line numbers of the other files you read. Old tool output is gone after that, and files you edited are not carried over; re-read only the window you need, using the outline's line numbers.