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
//! Where and how this runtime runs commands — the execution half of
//! [`RuntimeBuilder`](super::RuntimeBuilder).
//!
//! The knobs: how patiently a command is waited out, the fixed environment
//! every spawned process receives, and the named executors `!@<target>`
//! routes to (ADR-0021). And the derivations `build` reaches for from them:
//! the name validation a routable target has to pass, the two
//! `RuntimePolicy` recipes — one bound to a single workspace, one for
//! everything on the runtime that belongs to no workspace — and the
//! [`PolicyShaping`] both of them pass through.
//!
//! Grouped because they answer one question between them and are read
//! together: a target name is validated against the same rule the `!@`
//! parser applies, and the policies are where a command timeout and a shell
//! posture actually land.
use ;
use RuntimePolicy;
use crate::;
use ;
/// Refuses a target name basis cannot route on, before a runtime is built
/// around it.
///
/// Two rules, and both are about what the name has to survive downstream. It
/// is glob-matched inside a serialized rule pattern and printed into refusals
/// the model reads, so a name carrying a quote, a slash or a space would mean
/// one thing to the operator who wrote the rule and another to the matcher
/// reading it — hence the charset, which is the same predicate the `!@` parser
/// applies, from the same function, so the two can never disagree about which
/// names exist. And `local` is the wire word for *here*
/// ([`LOCAL_TARGET`]), so a target answering to it would make
/// `"target":"local"` mean two things in one field.
///
/// Dormant while nothing can register a target — `with_command_target` was
/// withdrawn unadopted — kept beside the table it validates for the day a
/// registration seam returns.
pub
/// The policy one workspace runs under:
/// `git_protected(workspace_bounded(path))`, the caller's shell posture, and
/// the memory roots.
///
/// One recipe for both runtime shapes. A private runtime bakes it at build,
/// and every workspace — private or sharing — also hands it to its own
/// sessions through
/// [`SessionOptions::policy`](mentra::runtime::SessionOptions), which is what
/// makes a shared runtime enforce a per-workspace posture in mentra's own
/// words rather than in a hook of basis's.
///
/// Path roots are hygiene, not a boundary: per ADR-0004 that is the kernel's
/// job, and per ADR-0013 basis ships no instance of one. What the caller said
/// about commands is passed through as written.
///
/// The memory roots ([`crate::memory`]) sit outside the workspace — that is
/// what makes them memory rather than working files — so recall (`read`,
/// `grep`) and writing a memory (`write`, `edit`) need them stated here, on
/// both the read and the write lists. Stated whether or not a directory
/// exists yet: the first memory is written by exactly the run that finds none
/// to read.
///
/// # The shell posture is enforced *inside* the call, and that has a cost
///
/// `allow_shell_commands(shell.is_granted())` is where a workspace's answer
/// about commands stops being a guard of basis's own and becomes a statement
/// in mentra's policy — which is the whole point of this recipe, because a
/// policy is the only thing a shared runtime can carry per session. Mentra's
/// admission order is hooks, then the schema, then the
/// [`ToolAuthorizer`](mentra::tool::ToolAuthorizer); the shell check fires
/// later still, inside the tool's own execution. So on a
/// [`ShellAccess::Denied`] workspace a command reaches
/// [`Approver`](crate::Approver) **first** and is refused **after** it is
/// answered.
///
/// For a `Prompt`-mode approver that is a real cost, and it is not a bug to be
/// fixed here: the person is shown `!curl … | sh` and asked whether to allow
/// it, their yes is recorded, and the model is then told commands are
/// disabled — a prompt about something that could never have run. Nothing is
/// weakened by it (the command does not run either way, and a *deny* is still
/// a deny), and the alternative is worse: refusing before the authorizer takes
/// a second implementation of the shell posture — the pre-hook guard the
/// dispatcher used to carry — which is exactly the duplicate this recipe
/// removed, and which a shared runtime could only apply by routing on a
/// directory. A host that wants the prompt suppressed can read the posture
/// itself and answer [`ApprovalDecision::Deny`](crate::ApprovalDecision)
/// without asking, or refuse in an
/// [`Interceptor`](crate::hooks::Interceptor), which does run before the
/// authorizer. Pinned by `a_denied_command_is_put_to_the_approver_before_the
/// _policy_refuses_it` in `basis/tests/hooks/guarded.rs`.
pub
/// What a shared runtime falls back to for anything running on it that belongs
/// to no workspace: shell and background on, `workspace_bounded`'s timeouts,
/// and no path roots of its own.
///
/// Every session basis mints carries its workspace's own
/// [`workspace_policy`] instead, so this governs only what a host reaches
/// through [`Runtime::mentra_runtime`](crate::Runtime::mentra_runtime) and
/// creates for itself. Commands are on because ADR-0013 grants them by
/// default. No roots, because mentra's file bounding always allows under the
/// calling agent's `base_dir`: with the list empty, such an agent is confined
/// to its own directory and no workspace's root widens it.
pub
/// What a runtime's builder says about *every* policy it hands out, whichever
/// recipe produced it.
///
/// A per-session policy replaces the runtime's wholesale — mentra's
/// [`SessionOptions::policy`](mentra::runtime::SessionOptions) does not merge
/// or intersect — so a knob a host set on the builder has to be re-applied to
/// each workspace's policy or it silently stops holding for every session on
/// the runtime. Carried as one value, and applied through one function, so the
/// runtime's own policy and a workspace's cannot come to disagree about what
/// the builder was told.
pub
/// Applies a host's chosen command timeout, raising the ceiling to match.
///
/// The ceiling moves with the default because the two mean different things to
/// mentra — one is what a command gets when it asks for nothing, the other is
/// the most it may ask for — and a host setting the first past the second
/// would otherwise be silently clamped back to a number it did not choose.
/// Keeps the parts of `.git` that decide what *runs* out of reach.
///
/// `.git/hooks` holds programs git executes on ordinary operations, and
/// `.git/config` can name more of them (`core.hooksPath`, and the `filter`/
/// `diff` drivers that run on checkout). Writing either turns a file edit into
/// code execution outside anything basis's policy or approval covers, which is
/// why they are singled out rather than denying `.git` wholesale — an agent
/// legitimately reads `.git`, and `git` itself must keep writing objects and
/// refs underneath it.
///
/// **This binds the builtin file tools, not the shell.** A command like
/// `sh -c 'echo … > .git/hooks/pre-commit'` still reaches the path, because
/// nothing here parses shell. It closes the route a model actually takes and
/// remains hygiene; per ADR-0004 and ADR-0013 the boundary is the OS's, and
/// basis does not ship one.