Skip disk sub-agents below `'operator'` authority and keep the parent's authority for `working_directory` delegates

Merged
AD
8d ago
+390-39

Reading guide: two small changes. First, _load_folder in subagents/_disk.py skips a definition file below 'operator' before names are compared, so a planted .agents/agents/reviewer.md can't shadow the operator's .claude/agents/reviewer.md. SubAgents.before_run warns about the skipped files. Second, _with_parent_authority at the end of subagents/_toolset.py holds the key decision: a working_directory delegate gets one level for all its files. That level is the lowest of what the parent gives the directory and of every parent path_authority entry inside it, whether written or resolved. It's conservative: a file the parent ranks higher can rank lower in the delegate, but none ranks higher. Copying the parent's entries one by one lost the parent's symlink caps (bot findings). Read it next to test_selected_directory_keeps_the_parents_authority and test_a_linked_directory_keeps_the_parents_cap. You can skip the docs.

Ported from Workspace.trusted to authority (#11836, #12473), now decided per file instead of per workspace.

  • SubAgents doesn't load a disk definition file below 'operator' (authority_of(path)). A definition's body becomes a delegate's instructions and its description goes in the parent's roster, so there's no lower-authority form to send instead. It warns naming the files, and only when there are some. A workspace= of its own at 'operator' is still read.
  • A delegate given a working_directory= never gets more authority than the parent gives its files, as it already kept the read-only policy. Its workspace is lowered to the lowest of the directory's level in the parent and any parent path_authority entry inside it. The host's resolver knows nothing of those levels, so without this a delegate in vendor/ would read vendor/lib at 'operator'. A parent without a workspace leaves the delegate unchanged. A directory outside the parent's working directory gets 'none', as the parent gives it, unless one of the parent's path_authority entries contains it; the operator opts such a directory back in with an entry, such as {'/srv/checkouts': 'operator'}.
  • The earlier CapabilityCreation docs change is dropped: main now refuses a directory below 'operator' (#12558).
  • Docs: SubAgents docstrings, page, README twin, docs/workspace.md, and the harness DELEGATION-AND-PLANNING reference.

Nothing changes for 'operator' workspaces.

Review notes

  • _with_parent_authority uses the public lowest_authority_under(workspace, directory) that #11837 adds to pydantic_ai.workspaces, not the private Workspace._authority_layers(). The single level is conservative. Per-path faithfulness would need a wrapper that delegates authority_of to the parent, and core doesn't support that for outer layers today.

Compatibility impact

Labeled compatibility impact. Release note:

  • SubAgents no longer loads a sub-agent definition from disk whose file is below 'operator' authority, such as every file in a workspace at authority='none': it's skipped with a warning naming the file. A working_directory= delegate's workspace is also lowered to the lowest authority the parent gives that directory. A directory outside the parent's working directory is at 'none' unless one of the parent's path_authority entries contains it, so a resolver that returns, say, a checkout elsewhere on disk now gives the delegate's repository instructions, skills and agent definitions no authority: add a path_authority entry for that directory on the parent's workspace to keep them as instructions. Pax's Review specialist is one such delegate: a working_directory outside the session directory, such as another checkout, now gives Review that repository's AGENTS.md as data rather than as instructions, and pax has no setting to opt a directory back in yet.
  • Durable runs using SubAgents with agent_folders record one realpath per agent definition file at run start; let in-flight runs finish, or use Temporal worker versioning / a new DBOS app version, before upgrading.

Follow-ups: #13775 (a two-level delegate wrapper that keeps operator authority for a trusted subdirectory of an untrusted workspace).

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