Skip to content

The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.

feat(code): the Code tab plans multi-step tasks (C59 A4)

purpleb48e69911d9a
diff --git a/src/hooks/useCodex.ts b/src/hooks/useCodex.ts
index 58c002d2..0e2bb9f3 100644
--- a/src/hooks/useCodex.ts
+++ b/src/hooks/useCodex.ts
@@ -126,7 +126,7 @@ import { codexToolDiff, codexEventKind } from './codex/tool-result-view'
import { capHiddenToolHistory } from './codex/hidden-history'
import { withHouseConduct } from '../lib/system-prompt'
import { yieldSilentRunsTo } from '../lib/silent-runs-yield'
-import { gatePlanTool, planToolAllowed } from '../lib/plan-gate'
+import { gatePlanTool, codePlanAllowed, planNudgeDue, PLAN_NUDGE } from '../lib/plan-gate'
/** A name the model wrote in its text is a call only when it is one of the
* agent's tools, after the usual name repair (GH #147). */
@@ -181,7 +181,7 @@ AUTONOMY CONTRACT (read carefully):
- Narrative "I'm about to do X" text with no tool call after it = premature stop. Don't do it.
Workflow per task:
-1. Understand the task (optional brief sentence)
+1. Understand the task. If it takes more than three steps, send todo_write with the whole plan together with your first exploring calls, and keep it current together with later calls.
2. Explore the codebase, file_list / file_read / file_search
3. Implement ALL required changes, file_edit to change existing files, file_write for new ones
4. Verify, shell_execute to run tests, lint, or build
@@ -226,6 +226,7 @@ const CODEX_SYSTEM_PROMPT_LEAN = `You are a coding agent in LU. Use tools to do
Rules:
- Put independent tool calls into one response (several reads or edits at once). Every step costs the user money.
- Read a file before you edit it.
+- A task of more than three steps: send todo_write with the plan together with your first calls, update it together with later calls.
- To change an existing file use file_edit (replace a unique old_string with new_string), not file_write. Use file_write only to create a new file.
- PATHS: use relative paths (e.g. \`package.json\`, \`.\`). Never start with \`/\` or a drive letter, it escapes the workspace and fails.
- Emit the tool call as your FIRST output, no "Okay, let me…" preamble. Valid JSON.
@@ -1296,6 +1297,8 @@ export function useCodex() {
// from the nudges above, because a nudge fires on an EMPTY turn while
// this fires on a turn that claims to be done.
let planReconcilesRemaining = PLAN_RECONCILE_BUDGET
+ let codeToolRounds = 0
+ let planNudged = false
// Raised from 20 → 50 (v2.3.7): large refactors across 10+ files
// legitimately need >20 tool calls. Budget still caps via
// agentMaxToolCalls/agentMaxIterations.
@@ -1605,10 +1608,11 @@ export function useCodex() {
// request or an open plan, todo_write is not offered at all.
const gatedDefs = gatePlanTool(
gateCreateTools(routedDefs, lastUserMsg, createGateOpened),
- planToolAllowed({
+ codePlanAllowed({
mode: codexMode,
userText: lastUserMsg,
todos: convId ? useTodoStore.getState().getTodos(convId) : [],
+ reviewMode,
}),
)
// C59 A2: on the compact profile the cut tools stay reachable
@@ -2687,6 +2691,19 @@ export function useCodex() {
if (failVerdict.action === 'steer') {
messages.push({ role: 'user', content: failVerdict.message })
}
+ // C59 A4: three tool rounds in and still no plan: ask for it, once.
+ codeToolRounds++
+ if (convId && planNudgeDue({
+ rounds: codeToolRounds,
+ todos: useTodoStore.getState().getTodos(convId),
+ alreadyNudged: planNudged,
+ readOnly: readOnlyTurn,
+ reviewMode,
+ })) {
+ planNudged = true
+ diagLog('plan-nudge', { iter: i })
+ messages.push({ role: 'user', content: PLAN_NUDGE })
+ }
}
// The bubble carries the MODEL'S answer or nothing. This used to build
diff --git a/src/lib/__tests__/code-tab-plans.test.ts b/src/lib/__tests__/code-tab-plans.test.ts
new file mode 100644
index 00000000..701dc1b5
--- /dev/null
+++ b/src/lib/__tests__/code-tab-plans.test.ts
@@ -0,0 +1,35 @@
+/** C59 A4: the Code tab offers todo_write always (outside a review) and asks for the plan once. */
+import { describe, it, expect } from 'vitest'
+import { readFileSync } from 'node:fs'
+import { resolve } from 'node:path'
+import { codePlanAllowed, planNudgeDue, PLAN_NUDGE, PLAN_NUDGE_AFTER_ROUNDS, planToolAllowed } from '../plan-gate'
+
+const base = { mode: 'bypass', userText: 'fix the failing test', todos: [] }
+
+describe('the Code tab plans', () => {
+ it('offers todo_write without the word "plan", but not in a review', () => {
+ expect(planToolAllowed(base)).toBe(false)
+ expect(codePlanAllowed({ ...base, reviewMode: false })).toBe(true)
+ expect(codePlanAllowed({ ...base, reviewMode: true })).toBe(false)
+ })
+
+ it('asks once, after three rounds, only without a plan and only when it may write', () => {
+ const due = (o: Partial<Parameters<typeof planNudgeDue>[0]>) =>
+ planNudgeDue({ rounds: PLAN_NUDGE_AFTER_ROUNDS, todos: [], alreadyNudged: false, readOnly: false, reviewMode: false, ...o })
+ expect(due({})).toBe(true)
+ expect(due({ rounds: 2 })).toBe(false)
+ expect(due({ alreadyNudged: true })).toBe(false)
+ expect(due({ readOnly: true })).toBe(false)
+ expect(due({ reviewMode: true })).toBe(false)
+ expect(due({ todos: [{ id: '1', content: 'x', status: 'pending' }] as never })).toBe(false)
+ expect(PLAN_NUDGE).toMatch(/together with your next real tool call/)
+ })
+
+ it('the loop and both prompts carry it', () => {
+ const src = readFileSync(resolve(__dirname, '../../hooks/useCodex.ts'), 'utf8')
+ expect(src).toMatch(/codePlanAllowed\(\{/)
+ expect(src).toMatch(/planNudgeDue\(\{/)
+ expect(src).toMatch(/send todo_write with the whole plan together with your first exploring calls/)
+ expect(src).toMatch(/A task of more than three steps: send todo_write with the plan together with your first calls/)
+ })
+})
diff --git a/src/lib/plan-gate.ts b/src/lib/plan-gate.ts
index 0f4de5db..0c976e80 100644
--- a/src/lib/plan-gate.ts
+++ b/src/lib/plan-gate.ts
@@ -63,3 +63,36 @@ export function planToolAllowed(input: PlanToolInput): boolean {
export function gatePlanTool<T extends { name: string }>(defs: T[], allowed: boolean): T[] {
return allowed ? defs : defs.filter((d) => d.name !== PLAN_TOOL)
}
+
+/**
+ * The Code tab plans (C59 A4, owner's decision 09.11.2026: the plan duty holds
+ * in the Code tab only). Fan et al. 2026 (arXiv 2609.20804) measured the one
+ * planning ablation with a ~30B model: Nemotron-3-30B went from 13.6 % to
+ * 25.2 % on SWE-bench Verified, and without a plan 68.6 % of its tasks ended
+ * with no edit at all after a median of five turns, the "stops too early"
+ * failure. For 128B-550B models planning changed little. So: todo_write is
+ * always offered in the Code tab (outside a review), the prompt asks for the
+ * plan with the first calls, and a run that is three tool rounds in without
+ * one is told once to write it.
+ */
+export function codePlanAllowed(input: PlanToolInput & { reviewMode: boolean }): boolean {
+ return !input.reviewMode || planToolAllowed(input)
+}
+
+/** Tool rounds a Code run may take before it is asked for its plan. */
+export const PLAN_NUDGE_AFTER_ROUNDS = 3
+
+export const PLAN_NUDGE =
+ 'This task has several steps and there is no plan yet. Send todo_write with every remaining step now, '
+ + 'together with your next real tool call (finished steps completed, the current one in_progress).'
+
+export function planNudgeDue(input: {
+ rounds: number
+ todos: TodoItem[]
+ alreadyNudged: boolean
+ readOnly: boolean
+ reviewMode: boolean
+}): boolean {
+ return !input.alreadyNudged && !input.readOnly && !input.reviewMode
+ && input.rounds >= PLAN_NUDGE_AFTER_ROUNDS && input.todos.length === 0
+}