Skip to content

core: tell the model about its scratch directory - #459

Merged
mohitranka merged 1 commit into
mainfrom
ao/forge-15/scratch-directory
Aug 28, 2026
Merged

mohitranka merged 1 commit into
mainfrom
ao/forge-15/scratch-directory

Conversation

@mohitranka

Copy link
Copy Markdown
Contributor

Summary

The model had no designated place for throwaway files (scratch scripts, notes, intermediate output), so it wrote them directly into the workspace, dirtying the project tree.

Forge already creates a private SessionTempDir per session — writable by write_file/edit/apply_patch and by sandboxed shell commands alike (both resolve_write_path and the OS sandbox profile already treat it as a second writable root alongside the workspace). It just was never surfaced to the model, and the system prompt actively told the model to "stay inside the workspace" for writes.

  • assemble_system_prompt now takes the session's scratch directory path and substitutes it into a {{SCRATCH_DIR}} placeholder in system_prompt.md.
  • The sandbox section of the system prompt now names the concrete path and instructs the model to prefer it over the workspace for anything that isn't part of the deliverable.
  • SessionTempDir::create() is reordered ahead of prompt assembly in all four session-construction paths (fresh session, resume, subagent create, subagent resume) so the real path is always available to embed, and the previous double-creation is removed in favor of reusing one instance.

A workspace-local alternative (e.g. .forge/scratch/) was considered and rejected: .forge is currently masked entirely read-only in the OS sandbox for spawned shell commands, with no per-subpath carve-out, so making a workspace-local scratch dir usable by shell commands too would require new, more security-sensitive sandbox-profile work for comparatively little benefit over the existing session-temp mechanism.

Test plan

  • cargo fmt --all
  • cargo clippy --all-targets --workspace
  • cargo test --workspace --no-fail-fast — green aside from 3 pre-existing failures unrelated to this change (confirmed one against a clean HEAD snapshot; the other two are in forge-tools/sandbox_enforcement.rs, a crate untouched by this PR, and fail due to this dev machine missing Xcode CLI tools / a macOS Seatbelt permission quirk)
  • Added system_prompt_embeds_the_scratch_directory_path asserting the placeholder is substituted and doesn't leak into the prompt verbatim

Every session already creates a private SessionTempDir, writable by
every tool (write_file/edit/apply_patch and sandboxed shell commands
alike) alongside the workspace root. Its path was never surfaced to
the model, so throwaway files it created — scratch scripts, notes,
intermediate output — had nowhere to go but the project tree.

assemble_system_prompt now takes the session's scratch directory and
substitutes it into the system prompt, with guidance to prefer it
over the workspace for anything that isn't part of the deliverable.
SessionTempDir creation is reordered ahead of prompt assembly across
all four session-construction paths (fresh, resume, subagent create,
subagent resume) so the real path is always available to embed.
@mohitranka
mohitranka merged commit 3ace431 into main Aug 28, 2026
7 checks passed
mohitranka added a commit that referenced this pull request Sep 11, 2026
Every session already creates a private SessionTempDir, writable by
every tool (write_file/edit/apply_patch and sandboxed shell commands
alike) alongside the workspace root. Its path was never surfaced to
the model, so throwaway files it created — scratch scripts, notes,
intermediate output — had nowhere to go but the project tree.

assemble_system_prompt now takes the session's scratch directory and
substitutes it into the system prompt, with guidance to prefer it
over the workspace for anything that isn't part of the deliverable.
SessionTempDir creation is reordered ahead of prompt assembly across
all four session-construction paths (fresh, resume, subagent create,
subagent resume) so the real path is always available to embed.
mohitranka added a commit that referenced this pull request Sep 11, 2026
Every session already creates a private SessionTempDir, writable by
every tool (write_file/edit/apply_patch and sandboxed shell commands
alike) alongside the workspace root. Its path was never surfaced to
the model, so throwaway files it created — scratch scripts, notes,
intermediate output — had nowhere to go but the project tree.

assemble_system_prompt now takes the session's scratch directory and
substitutes it into the system prompt, with guidance to prefer it
over the workspace for anything that isn't part of the deliverable.
SessionTempDir creation is reordered ahead of prompt assembly across
all four session-construction paths (fresh, resume, subagent create,
subagent resume) so the real path is always available to embed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant