Repository navigation
Description
Summary
Plan mode is read-only today: Write, Edit, MultiEdit, Delete and Bash stay advertised to the model but return tool not allowed ... disabled in plan mode at execution time (internal/tools/service.go, toolUnavailableError). That makes plans guesswork for anything the model cannot verify by reading alone: does this refactor compile, does this regex match, does this migration script parse. The model has to either guess or ask the user to leave plan mode.
Give plan mode a scratchpad: one directory the model may write to and run commands in while every other path stays read-only. The model can copy a file in, try the change, build or test it, and write a plan backed by evidence. The real working tree is never touched until the plan is approved.
Design
Location. Reuse the existing per-project scratch dir instead of adding a new one: config.ProjectTmpDir() (~/.infer/projects/<slug>/tmp), under a fixed scratchpad/ subdirectory. It is already a writable sandbox carve-out (internal/sandbox/paths.go, isWithinRuntimeDirs), already outside the git working tree so nothing leaks into commits or needs a .gitignore entry, already wiped by /reset, and already readable in plan mode through Read, Grep and Tree. Created lazily on the first write.
Open decision for the author: the title asks for the scratchpad "in the project dir" (for example ./.infer/scratchpad/). That variant needs a new carve-out in implicitAccess (the default policy denies .infer/ with on_violation: approval), a .gitignore story, and an exclusion from Tree/Grep so the scratch copies do not pollute investigation results. The runtime dir avoids all three, so this issue specifies the runtime dir unless the author objects.
Enforcement. One chokepoint, not per-tool checks: sandbox.ValidateWrite learns the agent mode (from the context the tool loop already carries, agentdomain.AgentModeFromContext). In plan mode it allows a write only when the resolved path is inside the scratchpad and rejects everything else with a DeniedError whose message names the scratchpad path. The plan-mode check runs before Granted and before the configured allowed list, so a grant or allow entry the user gave in another mode cannot widen plan mode. Denied entries and protectedPolicyPath still apply inside the scratchpad.
Tool availability. Add plan to the modes: list of Write.yaml, Edit.yaml, MultiEdit.yaml, Delete.yaml and Bash.yaml. The tool-use definitions sent to the provider do not change (all tools are already advertised in every mode to keep the prompt cache warm), only the execution-time gate does.
Bash. Plan mode already resolves its own allow-list, tools.bash.mode.plan.allow, which defaults to empty (config/tools.go, sandbox.BashAllowedCommands). Keep that default: Bash in plan mode runs only commands on that list, with the working directory pinned to the scratchpad, and everything else goes through the normal approval prompt. Users who want unattended builds opt in with entries like go build.* or go test.*. Known limit, same as every other mode: an allow-listed command can still reach paths outside the scratchpad through absolute arguments. The file tools are the hard boundary, the shell is policy plus approval.
Model guidance. Extend the built-in plan guidance in config/reminders.go (defaultModeChangeGuidance): name the scratchpad path, state that it is the only writable location, and tell the model to copy files in rather than edit the originals, to record what it verified in the plan's ## Verification section, and to leave the scratchpad out of ## Files to Modify. Add a matching subsection to docs/plan-mode.md and the tools reference.
Edge cases
- Path traversal and symlinks:
../out of the scratchpad and a symlink inside it that points outside are both rejected, resolved through the existingconfig.RealPathas the rest of the sandbox does. - A prior "always" grant on the project directory (
~/.infer/sandbox.yaml) does not unlock writes in plan mode. Deleteof a path outside the scratchpad is rejected like any other write.- Plan-mode
Agentsubagents inherit the same mode context, so they get the same scratchpad-only rule with no extra handling. - Approving a plan starts a fresh session; the scratchpad is left in place until
/resetso the executing agent can still read what was verified. readonlymode is unchanged: no scratchpad, writes stay rejected.
Acceptance Criteria
- In plan mode,
Write,Edit,MultiEditandDeletesucceed on paths under<ProjectTmpDir>/scratchpad/and are rejected everywhere else with an error that names the scratchpad path, regardless of configuredallowedentries or runtime grants. - The restriction lives in
sandbox.ValidateWrite(one chokepoint), with unit tests ininternal/sandboxfor the in-scratchpad, outside,../traversal, symlink-escape and granted-but-plan-mode cases. -
Bashruns in plan mode with cwd pinned to the scratchpad and thetools.bash.mode.plan.allowallow-list; the default list stays empty. - The built-in plan-mode guidance names the scratchpad and instructs the model to verify there and report results under
## Verification;docs/plan-mode.mddocuments the scratchpad. - The tool definitions sent to the provider are byte-identical before and after the change (prompt-cache invariant).
-
readonlymode, standard mode and the other modes keep their current write behaviour, covered by the existing tests.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
edenreich commentedon Oct 20, 2026
@infer can you work on this? use /ponytail:ponytail /go /go-concurrency /clean-code /clean-architecture /domain-driven-design
inference-gateway-maintainer commentedon Oct 20, 2026
Model:
ollama_cloud/glm-5.3-flash· Action:v0.57.0· CLI:v0.231.1· View JobTodos
Pull Request
#1577
✅ Infer Result: Success
Done. All work is committed, pushed, and PR #1577 is ready for review. Final state:
PR #1577: "feat(plan): add a plan-mode scratchpad and restrict writes to it" (fix/issue-1576, on the Roadmap 2026 board in QA)
What changed
config.ProjectScratchpadDir()resolves to the existing per-project runtime dir plusscratchpad/(~/.infer/projects/<slug>/tmp/scratchpad) - already a writable sandbox carve-out, outside git, wiped by/reset, created lazily.sandbox.ValidateWritenow takes the tool-loop context, reads the agent mode viaAgentModeFromContext, and in plan mode allows a write only when the resolved path is inside the scratchpad. The plan gate runs before grants and the configuredallowedlist, and is re-applied to the symlink-resolved target, so../traversal, symlink escapes, and prior "always" grants cannot widen plan mode. Denied entries and policy pins still win inside the scratchpad. Plan rejections are plain errors naming the scratchpad path (deviation from the issue:DeniedErrorwould offer a grant the gate can never honor - noted in the PR body).planadded to themodes:list ofWrite,Edit,MultiEdit,DeleteandBash; only the execution gate changes - the golden tool-definitions test confirms the provider-facing JSON is byte-identical.tools.bash.mode.plan.allowstays empty by default over the shared baseline; the shell path check stays mode-unaware (file tools are the hard boundary).## Verification, and keep the scratchpad out of## Files to Modify;docs/plan-mode.mdgot a scratchpad section,docs/tools-reference.mda plan-mode note for the write tools and the Bash pinning.../traversal, symlink escape, granted-but-plan-mode, and unchanged standard/readonly behavior; Bash work-dir and plan availability/approval-policy tests updated;task precommit:rungreen on both commits.Skipped: the project-dir scratchpad variant (
./.infer/scratchpad/) - the issue's open decision favored the runtime dir and so do I. Risk: an allow-listed plan-mode Bash command can still touch outside paths via absolute arguments (same known limit as other modes, documented); plan-mode rejections don't offer the grant prompt by design.Model:
ollama_cloud/glm-5.3-flash· Action:v0.57.0· CLI:v0.231.1· Exit Code:0· Duration: 17m 37sTokens: 20,863,641 in · 86,574 out · 20,950,215 total (120 requests)
Tool calls: 176 total · 100% success rate
Traces
Stats
Triggered by edenreich · Infer Action · OSS
inference-gateway-releaser commentedon Oct 20, 2026
🎉 This issue has been resolved in version 0.233.0 🎉
The release is available on:
Your semantic-release bot 📦🚀