1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
//! Working-tree isolation policy for native Agent-tool dispatches (#4480).
//!
//! Why: an in-conversation `Agent`/`Task` subagent inherits the dispatching
//! PM's working directory. Two concurrent file-mutating subagents in that one
//! directory fight over a single git HEAD, and git does not stop them: a
//! `git checkout -b` refuses only when a *tracked* file differs between both
//! branches' committed versions AND carries an uncommitted local change.
//! Untracked new files, and edits to files not tracked-differently between the
//! branches, transfer onto the other agent's branch silently — which is exactly
//! the shape two mostly-disjoint feature branches have. The observed failure is
//! `git status` reporting the PM on agent A's branch with agent B's changes
//! staged alongside it, with no error at any step.
//!
//! What: the pure classifiers both halves of the guard share — the daemon, which
//! records what each dispatch declared, and `tm hook --pm-guard`, which decides.
//! Two questions, deliberately separate:
//!
//! * [`isolation_separates_working_tree`] — did this dispatch ask for its own
//! tree? `isolation: "worktree"` (a private git worktree) and
//! `isolation: "remote"` (a different machine entirely) both do; nothing else
//! does, including the absent field, which is the default and the whole
//! problem.
//! * [`agent_mutates_files`] — is the named agent one that writes to its cwd?
//!
//! **Both classifiers fail toward ALLOW, and that direction is not negotiable.**
//! A false DENY lands on the PM and halts every dispatch in the system; a false
//! ALLOW merely reproduces the behaviour that shipped before this module. So
//! [`agent_mutates_files`] answers `true` only for an agent this binary ships
//! and can positively identify as file-mutating — an unknown name, a custom
//! project agent, a renamed agent, or an unparseable frontmatter all answer
//! `false` and the dispatch proceeds.
//!
//! What the classifier covers, and why not more: an agent counts when its own
//! bundled definition tells it to write to the tree it is dispatched into.
//! #4480 shipped engineer-tier alone on the theory that the adjacent tiers need
//! to see the engineer's work in the shared tree; #5650 found that reasoning
//! backwards for three of them. `documentation` creates and reorganises files,
//! `git mv`s them, and commits; `version-control` branches, commits, and pushes;
//! `qa` writes test files. Wanting to read the engineer's work does not make
//! writing alongside it safe — a `documentation` agent dispatched next to a
//! `rust-engineer`, both unisolated, is the same single-HEAD collision the module
//! exists to stop, and it passed with no deny at all until #5650.
//!
//! A dispatch that only reads — research, code analysis, adversarial review,
//! ticketing — still answers `false` and still parallelises freely. That is where
//! the line sits now: writes, not proximity to writes.
//!
//! **The fail-open direction is scoped to the shared-tree race, not to the
//! main checkout (ADR-0048).** Everything above is #4480's calculus, and it
//! still governs [`agent_mutates_files`] and [`shares_the_callers_tree`]. It
//! does NOT govern a session standing in a project's MAIN CHECKOUT, where
//! ADR-0044 forbids source writes outright: there an unknown agent is the exact
//! reported harm — a custom or renamed agent answers `false` here and would
//! keep writing to the tree three sessions share. So
//! [`requires_own_worktree_in_main_checkout`] reads the same bundle through
//! [`agent_write_risk`] and treats `Unknown` as a writer. The two directions do
//! not conflict because the costs are not symmetric between them: in a worktree
//! a false deny halts dispatch and a false allow costs nothing new, while in a
//! main checkout a false allow corrupts another session's branch and a false
//! deny costs one worktree.
//!
//! **One role is granted the shared checkout outright (ADR-0056).** Both
//! policies above ask whether an agent writes. `version-control` does — and the
//! writes are a merge into main, a branch delete, and the removal of a merged
//! worktree, none of which can be performed from inside a worktree. Isolating
//! it removes the tree the work needs, so the guard was denying the work rather
//! than protecting anything. [`permitted_in_shared_checkout`] names that grant,
//! [`requires_own_worktree_in_main_checkout`] and [`blocked_by_shared_tree`]
//! honour it, and [`agent_write_risk`] does NOT: the agent still answers
//! `Writes`, so it still OCCUPIES a tree and an engineer dispatched beside it is
//! still denied. Admission and occupancy are separate questions from here on.
//! The grant is keyed by name and reaches exactly one agent; engineer
//! source-write confinement is untouched.
//!
//! **The roster is runtime content (#9011), and without it the classifiers
//! fail CLOSED (owner ruling 09(a)).** Every classifier takes the agent roster
//! as `Option<&AgentRoster>`; `None` means the content could not be resolved.
//! Then no agent can be positively identified as read-only, so
//! [`agent_mutates_files`] answers `true` for everything but the read-only
//! harness built-ins. That reverses #4480's fail-open for this one cause on
//! purpose: a missing roster is not an unknown CUSTOM agent, it is every
//! bundled engineer becoming invisible to the race check at once.
//! `tm hook --pm-guard` goes further and refuses the dispatch outright.
//!
//! Test: the `#[cfg(test)]` suite below.
//!
//! [`isolation_separates_working_tree`]: crate::core::dispatch_isolation::isolation_separates_working_tree
//! [`agent_mutates_files`]: crate::core::dispatch_isolation::agent_mutates_files
//! [`shares_the_callers_tree`]: crate::core::dispatch_isolation::shares_the_callers_tree
//! [`agent_write_risk`]: crate::core::dispatch_isolation::agent_write_risk
//! [`requires_own_worktree_in_main_checkout`]: crate::core::dispatch_isolation::requires_own_worktree_in_main_checkout
//! [`permitted_in_shared_checkout`]: crate::core::dispatch_isolation::permitted_in_shared_checkout
//! [`blocked_by_shared_tree`]: crate::core::dispatch_isolation::blocked_by_shared_tree
use Value;
use agent_metadata_from_str;
use crateAgentRoster;
/// `isolation` values that give a dispatched subagent a working tree of its own.
///
/// Why: the guard's entire question is "does this subagent get its own tree?",
/// and only the harness can answer it. These are the two `isolation` modes the
/// Agent tool documents as producing one — a private git worktree, and a remote
/// cloud environment. An unrecognised value is treated as no isolation rather
/// than assumed safe, because a typo (`"worktrees"`, `"Worktree"`) must not
/// silently buy an exemption.
/// What: exact, case-sensitive values matched by
/// [`isolation_separates_working_tree`]; the harness emits the literal it was
/// given, so an exact match is correct.
/// Test: `isolation_values_that_separate_the_tree`,
/// `unrecognised_isolation_does_not_separate_the_tree`.
pub const ISOLATING_DISPATCH_MODES: & = &;
/// Frontmatter `role:` values whose agents mutate files in their cwd.
///
/// Why: `role:` is the declared domain every bundled agent carries, so this is a
/// property of the agent definition rather than a name-shaped guess that a
/// rename would silently invalidate. A role belongs here only when EVERY bundled
/// agent declaring it writes files; a role with a read-only member is keyed by
/// name in [`FILE_MUTATING_NAMES`] instead.
/// What: matched case-sensitively against [`crate::core::agent_metadata::AgentMetadata::role`].
/// `data-engineer` is listed explicitly because it declares that role rather
/// than plain `engineer` while still extending `base-engineer`. `documentation`
/// and `version-control` each have exactly one bundled agent, and both write —
/// docs and `git mv`s for one, branches and commits for the other.
/// Test: `engineer_tier_agents_mutate_files`, `file_writing_non_engineer_agents_mutate_files`,
/// `non_engineer_agents_do_not`.
// #5650: documentation and version-control demonstrably write files; omitting
// them let two unisolated writers share one HEAD with no deny.
const FILE_MUTATING_ROLES: & = &;
/// Bundled agent `name:`s that mutate files but whose `role:` cannot say so.
///
/// Why: this list is keyed on NAME rather than role, and that is deliberate —
/// do not fold it back into [`FILE_MUTATING_ROLES`]. All four bundled agents
/// declaring `role: qa` also declare `extends: base-qa`, but they do not agree
/// about writing: `qa`, `web-qa`, and `api-qa` author test files, while
/// `code-critic` is a pure reviewer that reads code and returns a verdict
/// (`code-critic.md` — "You did not write this code"). Adding `qa` to the role
/// list would classify `code-critic` as mutating and deny a review dispatched
/// alongside an engineer, which is the ordinary workflow.
/// What: matched case-sensitively against the agent's declared `name:`.
/// Test: `file_writing_non_engineer_agents_mutate_files`,
/// `code_critic_is_not_file_mutating`.
// #5650: role: qa is not homogeneous — code-critic shares it and only reviews.
const FILE_MUTATING_NAMES: & = &;
/// Harness built-in agents that read but never write, and so ship in no bundle.
///
/// Why: `Explore` and `Plan` are Claude Code's own dispatch targets, not
/// trusty-mpm artifacts, so [`agent_write_risk`]'s bundle scan cannot find them
/// and answered [`AgentWriteRisk::Unknown`] — which
/// [`requires_own_worktree_in_main_checkout`] treats as a writer and grants a
/// worktree to. A granted worktree is cut from a COMMIT, so a reader dispatched
/// into one reads a tree WITHOUT the session's uncommitted work and answers
/// confidently about the wrong tree. For a writer that cost is a worktree; for a
/// reader it is a wrong answer, which is why the Unknown-is-a-writer rule
/// (ADR-0048 decision 3) must not reach them.
///
/// The list is exactly the built-ins whose published tool set excludes every
/// write tool (`Edit`, `Write`, `NotebookEdit`). `claude-code-guide` qualifies
/// on the same test as `Explore` and `Plan`: Claude Code 2.1.281 gives it
/// `Read`/`Glob`/`Grep`/`WebFetch`/`WebSearch`, or `Bash` in place of
/// `Glob`/`Grep`, and `Explore` and `Plan` carry `Bash` too. `general-purpose`
/// and `claude` are deliberately NOT here: both carry the full tool set, and
/// `general-purpose` is also the identity a failed named-agent dispatch
/// degrades into (#4451), so a `general-purpose` delegation is routinely an
/// engineer's work under another name. `statusline-setup` carries `Edit`. All
/// three stay `Unknown`, and stay isolated.
/// What: matched case-sensitively, ahead of the bundle scan, so a bundled agent
/// could never be shadowed by one of these names without also colliding on it.
/// Every entry is also in [`HARNESS_BUILTIN_AGENTS`].
/// Test: `read_only_harness_builtins_are_not_isolated`.
const READ_ONLY_HARNESS_AGENTS: & = &;
/// Every agent type the Claude Code harness itself provides, readers and
/// writers alike (#8547).
///
/// Why: a dispatch in a main checkout is refused when its `subagent_type` is a
/// name nothing defines. These six ship in no trusty-mpm bundle and in no
/// deployed agent directory, yet Claude Code resolves them, so they are known
/// names and must never be refused as unknown. Knowing a name is a separate
/// question from whether it writes: [`READ_ONLY_HARNESS_AGENTS`] is the subset
/// that reads only, and the rest still get a worktree.
/// What: matched case-sensitively by [`agent_known_without_roster`].
/// Test: `harness_builtins_are_known_names`.
pub const HARNESS_BUILTIN_AGENTS: & = &;
/// Bundled agent `name:`s that write, and are still permitted to do so in a
/// checkout they do not own (ADR-0056).
///
/// Why: every other entry in this module classifies an agent by WHETHER it
/// writes. This one is the exception the ruling of 2026-08-31 carved out, and it
/// turns on WHAT the write is. `version-control` merges into main, deletes
/// merged branches, and reclaims merged worktrees — operations on the
/// repository the checkout points at, not edits to the source tree the write
/// boundary protects. None of them can be performed from inside a worktree: a
/// merge into main needs main's checkout, and a tree cannot remove itself. The
/// observed harm is the guard denying the work rather than protecting it —
/// `version-control` was denied twice on 2026-08-31 for pure push/PR dispatches
/// and had to be worked around with isolation, whose fences hid a branch ref
/// badly enough that the push had to be issued by SHA.
///
/// Keyed by NAME, not by role, and deliberately not folded into
/// [`FILE_MUTATING_ROLES`]. This is a grant, so it must not widen by accident:
/// a future agent that declares `role: version-control` inherits nothing from
/// this list, and [`agent_write_risk`] still answers
/// [`AgentWriteRisk::Writes`] for every name here — the exemption changes who
/// may be dispatched into an occupied tree, never what the agent is.
/// What: matched case-sensitively against the dispatch's `subagent_type`, by
/// [`permitted_in_shared_checkout`].
/// Test: `version_control_operates_without_a_worktree_of_its_own`.
// ADR-0056 narrows #4480 and #5650 for this one name; engineer source-write
// confinement (ADR-0044, ADR-0048) is untouched.
//
// See ADR-0057 — `pm_guard_bash::worktree_remove` reads this same list, through
// [`permitted_in_shared_checkout`], to decide who may run `git worktree remove`.
// The two guard layers fire at different points (dispatch time and Bash time)
// and must never disagree about the name, so neither keeps its own copy.
const SHARED_CHECKOUT_PERMITTED_NAMES: & = &;
/// The `extends:` base whose descendants are engineer-tier regardless of role.
///
/// Why: a bundled agent could declare a new role spelling and still inherit the
/// whole engineer contract. Checking the inheritance edge as well as the role
/// means adding such an agent does not silently drop it out of the guard.
/// What: matched case-sensitively against
/// [`crate::core::agent_metadata::AgentMetadata::extends`].
/// Test: `engineer_tier_agents_mutate_files`.
const FILE_MUTATING_BASE: &str = "base-engineer";
/// Does this dispatch's `isolation` declaration give it its own working tree?
///
/// Why: this is the one thing that makes a concurrent file-mutating dispatch
/// safe, so it is also the one thing the guard accepts as an exemption.
/// What: `true` when `isolation` is present and is a member of
/// [`ISOLATING_DISPATCH_MODES`]. `None` — the default, and the case the whole
/// issue is about — is `false`.
/// Test: `isolation_values_that_separate_the_tree`,
/// `unrecognised_isolation_does_not_separate_the_tree`.
/// Is `agent` a bundled agent that mutates files in its working directory?
///
/// Why: the guard must not fire on a read-only research, review, or planning
/// dispatch — those share a cwd harmlessly and are dispatched in parallel all
/// the time. Resolving the answer from the agent's own declared frontmatter
/// keeps one authority for it instead of a name list that drifts as agents are
/// added.
/// What: scans the content roster for the agent whose declared `name:`
/// equals `agent`, and reports whether its `role:` is in
/// [`FILE_MUTATING_ROLES`], its `extends:` is [`FILE_MUTATING_BASE`], or its
/// name is in [`FILE_MUTATING_NAMES`]. A name this binary does not ship — a
/// project-local or custom agent — answers `false`, the fail-open direction
/// this module's doc commits to. With no roster (`None`, #9011) every agent but
/// a read-only harness built-in answers `true`: the fail-closed direction.
///
/// No caching: the caller resolves the content roster (#9011) once per
/// invocation and passes it in; a process-lifetime cache would be global state.
/// Test: `engineer_tier_agents_mutate_files`,
/// `file_writing_non_engineer_agents_mutate_files`, `non_engineer_agents_do_not`,
/// `unknown_agent_fails_open`, `a_missing_roster_fails_closed`.
/// What this binary can say about whether `agent` writes to its cwd.
///
/// Why: [`agent_mutates_files`] collapses two different answers into `false` —
/// "this bundled agent reads only" and "this binary has never heard of this
/// agent". #4480 was right to treat both as ALLOW, because its question was
/// whether to halt a dispatch over a race. ADR-0044's question is different:
/// may this agent write to a checkout other sessions are standing in? There,
/// the two answers must diverge, so the classifier has to keep them apart
/// before anything collapses them.
/// What: `Writes` when the bundled definition says it writes, `ReadsOnly` when
/// the bundled definition says it does not, `Unknown` for an empty name and for
/// any name this binary does not ship — a custom project agent, a renamed
/// agent, or an unparseable definition.
/// Test: `write_risk_separates_unknown_from_read_only`.
/// Classify `agent` against the content roster (#9011).
///
/// Why: one bundle scan feeding both policies, so the shared-tree race and the
/// main-checkout boundary can never disagree about what an agent is.
/// What: scans the content roster for the agent whose declared `name:`
/// equals `agent` and reports whether its `role:` is in [`FILE_MUTATING_ROLES`],
/// its `extends:` is [`FILE_MUTATING_BASE`], or its name is in
/// [`FILE_MUTATING_NAMES`]. A name not in the bundle is
/// [`AgentWriteRisk::Unknown`], never `ReadsOnly` — the distinction the whole
/// enum exists for.
///
/// No caching: the caller resolves the content roster (#9011) once per
/// invocation and passes it in; a process-lifetime cache would be global state.
/// Test: `write_risk_separates_unknown_from_read_only`,
/// `engineer_tier_agents_mutate_files`, `non_engineer_agents_do_not`,
/// `read_only_harness_builtins_are_not_isolated`.
/// The declared frontmatter of the bundled agent named `agent`, if this binary
/// ships one.
///
/// Why: [`agent_write_risk`] and [`agent_known_without_roster`] ask different
/// questions of the SAME table, and a second scan is a second place the two
/// could disagree about which artifact is which agent. The builder classifier
/// that also read it retired with the dispatch-time cap (#8261 round 3).
/// What: scans the content roster (#9011) for the file whose declared `name:`
/// equals `agent`, and parses it. `None` for a name this binary
/// does not ship — a custom project agent, a renamed agent, or an unparseable
/// definition.
///
/// No caching: the caller resolves the content roster (#9011) once per
/// invocation and passes it in; a process-lifetime cache would be global state.
/// Test: `write_risk_separates_unknown_from_read_only`,
/// `harness_builtins_are_known_names`.
/// Is `agent` a name this binary knows without reading any agent directory
/// (#8547)?
///
/// Why: the #8547 refusal must not reach a name that something defines. Two of
/// the three sources that define names need no I/O — the content roster and
/// the harness built-ins — so they are checked here, and the caller reads the
/// deployed roster only when both answer no.
/// What: `true` when `agent` is in [`HARNESS_BUILTIN_AGENTS`] or names a bundled
/// agent. Exact, case-sensitive match; an empty name is `false`.
/// Test: `harness_builtins_are_known_names`.
/// Must this dispatch get a working tree of its own before it may run in a
/// project's main checkout (ADR-0048)?
///
/// Why: ADR-0044 makes the main checkout read-only except for documents and
/// configuration, for the PM and for every agent it dispatches. An agent that
/// might write therefore needs somewhere else to write, and the only somewhere
/// else is its own worktree. The predicate is separate from
/// [`shares_the_callers_tree`] because it answers a different question and
/// resolves the indeterminate case the other way: this one has no concurrent
/// sibling in it at all, so the FIRST unisolated writer is already a violation.
/// What: `true` when the declared isolation does not
/// [`isolation_separates_working_tree`] AND [`agent_write_risk`] is anything
/// other than [`AgentWriteRisk::ReadsOnly`]. `Unknown` is included
/// deliberately — see the module doc for why the fail-open direction does not
/// carry across this boundary.
/// Test: `main_checkout_isolation_is_required_for_writers_and_unknowns`.
/// May `agent` be dispatched into a checkout it does not own (ADR-0056)?
///
/// Why: the two policies above ask whether an agent writes. This asks whether
/// its writing is a reason to move it, and for one role the answer is no.
/// `version-control` merges into main and reclaims merged worktrees; both need
/// the checkout it was handed, so isolating it removes the tree the work
/// requires. Kept as its own predicate rather than a third
/// [`AgentWriteRisk`] variant so the classification stays honest: the agent
/// still `Writes`, and every consumer that asks what it is gets the true
/// answer.
/// What: `true` when `agent` is in [`SHARED_CHECKOUT_PERMITTED_NAMES`].
/// Test: `version_control_operates_without_a_worktree_of_its_own`.
/// Must this dispatch be DENIED because another writer holds the caller's tree?
///
/// Why: [`shares_the_callers_tree`] answers who OCCUPIES a tree, and the guard
/// used that one answer for two questions — who is standing here, and who may
/// be admitted. ADR-0056 separates them, because `version-control` is both an
/// occupant (it commits, so an engineer beside it is still denied) and
/// admissible (its work is the merge into the tree it was given). Composed
/// here so the guard and the daemon cannot compose it differently.
/// What: `true` when the dispatch [`shares_the_callers_tree`] AND the agent is
/// not [`permitted_in_shared_checkout`].
/// Test: `version_control_operates_without_a_worktree_of_its_own`,
/// `allows_version_control_alongside_a_live_writer`,
/// `denies_a_file_writing_non_engineer_alongside_an_engineer`.
/// The `subagent_type` an Agent-tool `tool_input` names, when it names one.
///
/// Why: one extraction shared by the daemon's tracker and the guard, so the two
/// can never read different fields and disagree about which agent was
/// dispatched.
/// What: `tool_input.subagent_type` as a non-empty `&str`. An untyped
/// dispatch — no `subagent_type` at all — yields `None`. The shared-tree race
/// lets it through; a main checkout refuses it (#8547, see
/// `pm_guard_worktree_grant`).
/// Test: `reads_subagent_type_and_isolation`.
/// The `isolation` mode an Agent-tool `tool_input` declares, when it declares one.
///
/// Why: as [`dispatch_agent`] — one reader for the field the whole policy turns on.
/// What: `tool_input.isolation` as a non-empty `&str`.
/// Test: `reads_subagent_type_and_isolation`.
/// Read one non-empty string field from an Agent-tool `tool_input`.
/// Would this dispatch put a second file-mutating agent into the caller's tree?
///
/// Why: the composed question every caller actually asks, kept here so the
/// daemon (recording) and the guard (deciding) cannot compose the two
/// classifiers differently.
/// What: `true` when the named agent [`agent_mutates_files`] AND the declared
/// isolation does not [`isolation_separates_working_tree`].
/// Test: `shares_the_callers_tree_only_for_unisolated_engineers`.