Skip to content

Patch tool should fail fast on paths outside workspace #11113

@ilepn

Description

@ilepn

Summary

When patch/apply_patch receives a file path outside the current workspace root, it should fail fast with a clear error and non-zero status instead of silently "succeeding" or writing to the wrong location.

Repro (Windows, but should be general)

  1. Start OpenCode in a workspace on C:
    opencode C:/Users/me/project
  2. Apply a patch targeting an absolute path on D:
    *** Update File: D:/.toolbox/docs/uv-install.md

Observed: patch reports success but no file is created/updated under D:, or paths are mis-interpreted.
Expected: validation error indicating path outside workspace root.

Expected behavior

  • Normalize each patch target path.
  • If target path resolves outside workspace root, abort before making changes.
  • Return a non-zero tool error status, e.g. EOUTSIDE_ROOT, with a clear message:
    "Path outside workspace root. Start OpenCode in that directory or use an allowed root."

Nice-to-have (optional)

  • Configurable allowlist of additional roots (multi-root).
  • Or prompt for explicit approval when patch targets a path outside root.

Related

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions