Add per-path workspace authority with `Workspace.authority_of`
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
~/.claudepointing into dotfiles, has no such cap.LocalWorkspaceexpands~, andAuthorityWorkspacerefuses 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 escapevendor: 'none'. Folding never raises a level. - A path outside the working directory is outside the workspace, so it gets
'none', unless apath_authoritykey contains it.LocalWorkspacedoesn'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
realpathresolves 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 onerealpathperpath_authoritykey, plus one for the path, plus one per path component when the path goes through a link. UnderDurableWorkspace, each of those runs as a unit. - With no
path_authority, it returnsauthorityfor every file in the working directory. - Wrappers: each
AuthorityWorkspacelayer contributes(authority, path_authority), and the result is the lowest level any layer gives the location, so wrapping never raises a level.Workspace.authorityis 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_oflives on the baseWorkspaceand does all its I/O throughself.working_dir(),self.resolve()andself.realpath(). Called from workflow code, itsrealpathcalls therefore run as units throughDurableWorkspace, which a test checks.path_authorityis part ofAuthorityWorkspace.durable_policy(), so aworkspace=whose mapping differs from the capability's is rejected, like a differentauthorityis. - Backends: nothing needs forwarding. Remote and sandbox backends only supply
realpath, natively or through the shell fallback. The harnessBubblewrapWorkspacewrapper inheritsauthority_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