Add per-path workspace authority with `Workspace.authority_of`

Merged
DO
1mo ago
+547-34

LocalWorkspace and AuthorityWorkspace take path_authority={path: level}, and Workspace.authority_of(path) gives the authority of one file, so a capability that loads workspace files can decide each file's voice. This is the case where one run reads a third-party clone and also the operator's own instruction files, such as ~/.config/my-app/AGENTS.md, through one workspace.

LocalWorkspace('./checkout', authority='none', path_authority={'~/.config/my-app': 'operator', 'docs/upload': 'user'})

How authority_of resolves a path:

  • The longest matching path wins, in both directions: a lower directory inside a higher one, or a higher one inside a lower one.
  • Keys resolve against the working directory. A key that is a link applies at its written location and at its target, but its target gets no more than the link's location would have without that key, so a link inside a lower path can't raise what it points at. A link outside the workspace, such as ~/.claude pointing into dotfiles, has no such cap. LocalWorkspace expands ~, and AuthorityWorkspace refuses a key starting with ~. If two keys resolve to the same path, the lower level wins.
  • Keys also match case-folded, and the lower level wins, so on a case-insensitive filesystem Vendor/ can't escape vendor: 'none'. Folding never raises a level.
  • A path outside the working directory is outside the workspace, so it gets 'none', unless a path_authority key contains it. LocalWorkspace doesn't refuse paths outside its directory, so returning 'none' matches its existing containment behaviour.
  • Symlinks: the result is the lower of the target's level and the level of every link along the path, including directory links part-way. A link reached only through another link's target in a chain isn't seen, because realpath resolves a chain in one call. This is documented, and left open as a design question. A link that sits outside every zone, such as a system directory above the workspace (macOS /tmp → /private/tmp), is the machine's, not the workspace's, and doesn't lower the level. Each call costs one realpath per path_authority key, plus one for the path, plus one per path component when the path goes through a link. Under DurableWorkspace, each of those runs as a unit.
  • With no path_authority, it returns authority for every file in the working directory.
  • Wrappers: each AuthorityWorkspace layer contributes (authority, path_authority), and the result is the lowest level any layer gives the location, so wrapping never raises a level. Workspace.authority is now derived from the same layers, with no change in behaviour.

path_authority is not access control. It sets the authority of text that capabilities put in the prompt, and read_file results are tool output whatever the file's level. The docs and the skill say this plainly. They also say a capability should call authority_of when it reads a file and keep the level with the text, so rendering is byte-stable and a symlink changed later can't change requests already sent.

Scope: this PR is core only. No capability reader changes. RepoContext global_files and #11935 will build on authority_of separately.

  • Durable execution: authority_of lives on the base Workspace and does all its I/O through self.working_dir(), self.resolve() and self.realpath(). Called from workflow code, its realpath calls therefore run as units through DurableWorkspace, which a test checks. path_authority is part of AuthorityWorkspace.durable_policy(), so a workspace= whose mapping differs from the capability's is rejected, like a different authority is.
  • Backends: nothing needs forwarding. Remote and sandbox backends only supply realpath, natively or through the shell fallback. The harness BubblewrapWorkspace wrapper inherits authority_of.

Checklist

  • No breaking changes in accordance with the version policy.
  • Any permitted compatibility impact has a label, warning, migration and release note, and an exact API-check waiver if the gate reports it.
  • PR title is fit for the release changelog.

šŸ¤– Generated with Claude Code