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
//! The **writable root** (VISION §4.11 item 3, §4.10 item 1) and the path
//! algebra every containment question is asked through.
//!
//! The root is two directories: the agent's own worktree (`agents/<agent-id>/`
//! under the workspace, litany ARCH §2.2) and the **bound attempt worktree** —
//! the balls `work/<id>` checkout the ball this workspace claimed materialized.
//! Inside either, writing is the job; outside, a write leaves the world.
//!
//! **The root is derived from facts yog owns, never from a fact the agent
//! controls.** That distinction is the whole security content of this module:
//!
//! - The **cwd** comes from litany's own mark (`refs/litany/cwd/<agent-id>`),
//! because relative operands must resolve where the executor will run them.
//! The mark is written by the agent's `cd` — so it is read to *interpret*
//! operands and never to widen the root. An agent that could widen its root
//! by `cd`-ing would have no root at all.
//! - The **bound worktree** is computed by the bl-delivery formula
//! ([`work_worktree_path`]) over a claim yog itself made and logged. The
//! claimant is the workspace name (§3.2), which is the workspace directory's
//! own leaf — so the join needs no store read and no subprocess.
//!
//! A ball an agent claimed for itself mid-conversation leaves no yog-side row
//! (§3.2 states that limit), so its worktree is not in the root and writing
//! there classifies open-world — never a target write, so a workspace override
//! or a raised floor still catches it.
//!
//! **Containment is lexical, not canonical.** `..` is folded textually and `~`
//! expands against `$HOME`; symlinks are not resolved. A `canonicalize` would
//! touch disk on every operand of every tool call and would answer `None` for
//! the paths that matter most (files a patch is about to create). Symlink
//! escape is out of the threat model by construction — VISION §4.11 item 8:
//! rule classification bounds accident and drift, not adversarial evasion.
use ;
use cratework_worktree_path;
use crateOpEntry;
/// Workspace subdirectory holding the per-agent worktrees (litany ARCH §2.2).
/// Mirrored here rather than imported, the convention every module that names
/// it already follows (`git_tree`, `files_view`, `transcript`).
const AGENTS_DIR: &str = "agents";
/// The logical binary an ops row's `argv[0]` names for a balls verb.
const BL: &str = "bl";
/// The `bl` verb whose logged row carries a claim yog made.
const CLAIM: &str = "claim";
/// The flag that stamps a claim with its claimant identity.
const AS_FLAG: &str = "--as";
/// Where an invocation may write, and where its relative operands resolve.
/// `~` / `~/…` expanded against `home`; anything else is taken as written.
/// Fold `..` textually. A `..` above the root simply drops, exactly as the
/// kernel treats `/..`. There is no `.` arm: `components()` already drops every
/// interior `.`, and the only one it keeps leads a RELATIVE path, which
/// [`Root::resolve`] never hands here.
/// The agent's own worktree under `workspace`.
/// Workspace subdirectory holding the bare repository (litany ARCH §2.2).
const REPO_DIR: &str = "repo.git";
/// The per-agent working-directory mark's ref namespace (litany ARCH §3.3).
const CWD_REF: &str = "refs/litany/cwd/";
/// The agent's working directory as litany's own mark records it — the ref names
/// a blob whose bytes are the absolute path. `None` when the mark is unset
/// (the ordinary state of an agent that never called `cd`), when the repo is not
/// there, or when git will not run: in every one of those the caller's default
/// applies, which is the agent worktree the executor would have used anyway.
///
/// **Read to interpret operands, never to widen the root.** The mark is written
/// by the agent's own `cd` — and a `cd` out of the writable root is itself an
/// open-world invocation this control holds, so the mark can only ever name a
/// directory the operator let it name.
/// The bound attempt worktree candidates for `claimant`, computed from the `bl
/// claim` rows yog's own trail carries (§3.2 join, §8.1 formula). The **last**
/// matching row wins — a re-claim supersedes — and that row's `cwd` is the
/// project the formula mirrors. Both leaf spellings are returned: the canonical
/// `<id>` and the `<id>-<claimant>` disambiguation balls mints when the
/// canonical leaf is already taken. Which one exists is a disk question the
/// containment check does not need to ask — a candidate that was never minted
/// contains nothing. Empty when this workspace never claimed through yog.
/// The §4.10 **fan candidates'** worktrees for `claimant` — the other half of
/// the writable root once a delivery obligation is fanned. With N > 1 no work
/// happens in `work/<id>`: each candidate writes in its own attempt worktree,
/// so a root that named the claim alone would classify every candidate's edit
/// as open-world. Derived from the same two yog-owned facts the claim join
/// uses — the trail's own claim row for the project, and its own fire rows for
/// the bindings ([`crate::fan::cohort`]) — never from the agent's `cd` mark.
/// Empty for an ordinary N = 1 start, which binds no attempt at all.
/// The claim this workspace last made: the project the row ran in and the ball
/// id it named. The **last** matching row wins — a re-claim supersedes — and a
/// workspace that never claimed through yog has none. `pub(crate)` since
/// bl-c2bd: the work-diff's candidate rows read the fan's obligation from this
/// same rule rather than keeping a second copy of it, and since bl-34b1 so does
/// the §8.6 confinement backend's writable set — the project half of this pair
/// is the one member of that set outside the world, and a revived driver has no
/// other way to know it.
pub
/// The ball id a `bl claim <id> --as <claimant>` row names, when its claimant
/// is ours. Any other argv shape contributes nothing.