Repository navigation
feat(plan): add a plan-mode scratchpad and restrict writes to it - #1577
Conversation
Plan mode is executable again for the file tools and Bash: sandbox.ValidateWrite reads the agent mode from the tool-loop context and in plan mode allows writes only inside the per-project scratchpad before grants and the configured allowed list, rejecting traversal and symlink escapes like any other path outside it. Write, Edit, MultiEdit, Delete and Bash advertise plan in their modes, Bash pins its working directory to the scratchpad which is created lazily, and the built-in plan guidance names the scratchpad and tells the model to verify there and report it in the Verification section of the plan. The tool definitions sent to the provider are unchanged.
The plan-mode guide gets a scratchpad section covering its location, what may write there, the bash allow-list and the traversal and symlink rules, and the tools reference points the write tools and Bash at it, including the scratchpad-pinned working directory in plan mode.
|
@infer please follow the YAML instructions from the AGENTS.md - fix the styling. |
|
Model: Todos
Pull Request✅ Infer Result: SuccessAll checks passed, the worktree is clean, and the branch is in sync with origin. Done - the YAML styling is fixed per the AGENTS.md rule (block style only, never flow style). What changed The plan-mode modes:
- standard
- auto
- auto-with-judge
- planApplied to: Validation
Note: the pre-existing Model: Tokens: 505,988 in · 7,676 out · 513,664 total (14 requests) Tool calls: 27 total · 100% success rate TracesStatsTriggered by edenreich · Infer Action · OSS |
…ll writes The baseline bash allow-list auto-approves mkdir and ln -s in every mode, and the shell path check validated writes without an agent mode, so a plan-mode mkdir with an absolute path could create directories in the working tree with no approval. The check now carries the mode, anchors relative paths to the scratchpad where plan-mode commands run, and rejects creating paths outside it. Also drop the remaining read-only wording for plan mode in the mode-guard error, the AgentModePlan comment and the docs, and inline the single-use scratchpad directory constant.
|
🎉 This PR is included in version 0.233.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Resolves #1576
Docs follow-up: inference-gateway/docs#1020
Summary
Plan mode gains a scratchpad: the per-project runtime directory now includes a
scratchpad/subdir, and plan mode is the one mode allowed to write there. Write, Edit, MultiEdit, Delete and Bash stay advertised to the model but execute in plan mode under a single chokepoint insandbox.ValidateWrite, which reads the agent mode from the tool-loop context and allows a write only when the path sits inside the scratchpad, before grants and the configured allowed list. The working tree stays read-only until the plan is approved, and the tool definition JSON sent to the provider is unchanged.Changes
ProjectScratchpadDir()-><ProjectTmpDir>/scratchpad(~/.infer/projects/<slug>/tmp/scratchpad), already a writable runtime carve-out, outside git, wiped by/reset.ValidateWrite(ctx, cfg, path)gates onagentdomain.AgentModeFromContext; in plan mode the gate runs beforeGrantedand theallowedentries (a prior always-grant cannot widen plan mode), is re-applied to the symlink-resolved target (traversal and link escapes rejected), and denied entries plus the policy/custom-tool pins still win inside the scratchpad.modes: [standard, auto, auto-with-judge, plan]on Write, Edit, MultiEdit, Delete and Bash - only the execution gate changes; readonly mode and the other modes keep their behaviour.tools.bash.mode.plan.allowbucket stays empty by default over the shared baseline. The allow-listed path check carries the agent mode too: the baseline auto-approvesmkdirandln -s, so in plan mode those follow the scratchpad gate (relative paths anchored to the scratchpad, absolute paths outside it fall through to approval) instead of creating directories in the working tree unprompted.{scratchpad}is substituted at render time from the live project), tells the model to copy files in rather than edit originals, run verification there, report what it verified under## Verification, and keep the scratchpad out of## Files to Modify.../traversal, symlink escape, granted-but-plan-mode, standard/readonly unchanged), plan-mode allow-list cases formkdir/ln -s(in-pad relative and absolute allowed, project-absolute and../rejected), Bash work-dir test, plan-mode tool availability and approval-policy rows updated, golden tool definitions regenerated (per-mode lists only - the definition JSON is untouched).docs/plan-mode.mdanddocs/tools-reference.mdgain the scratchpad documentation; the remaining "read-only" plan-mode wording in the mode-guard error, theAgentModePlancomment,docs/commands-reference.md,docs/configuration-reference.mdandexamples/tools/README.mdis updated to match.Deviations from the issue text
DeniedErroron plan-mode rejections. I used a plain error instead: aDeniedErrormakes the tool loop offer the user a sandbox grant approval that can never unlock plan mode (the gate runs before grants), which would look broken in the chat UI. Plain errors match the existing house pattern for non-grantable rejections (excluded for security, read-only library dirs). Tests assert the message names the scratchpad path, satisfying the acceptance criterion.mkdirandln -sand a plan-modemkdir <absolute project path>would otherwise have run with no approval at all. Commands whose arguments the check cannot predict still fall through to approval as in every other mode; the file tools remain the hard boundary.Follow-ups (not in this PR)
git status/git diff/git logrun in the scratchpad cwd in plan mode and fail with "not a git repository". Not a regression (Bash was fully disabled in plan mode before), worth a guidance line or a-Callowance.