@arcforge/types 2.0.191 → 2.0.193

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcforge/types",
3
- "version": "2.0.191",
3
+ "version": "2.0.193",
4
4
  "type": "module",
5
5
  "private": false,
6
6
  "main": "./src/index.ts",
@@ -318,6 +318,22 @@ export function intersect(
318
318
  }
319
319
 
320
320
 
321
+ /**
322
+ * The raw-shell switch under a ceiling.
323
+ *
324
+ * Returns a `{ raw }` fragment or nothing at all, because the ABSENCE of the
325
+ * key is meaningful downstream: `decideShell` escalates on an undeclared `raw`
326
+ * and refuses only on an explicit `false`. Writing `raw: false` when nobody
327
+ * said so would turn "ask" into "refuse".
328
+ */
329
+ function resolveRaw(profile: boolean | undefined, agent: boolean | undefined): { raw?: boolean } {
330
+ // Either layer's refusal stands — it is a decision somebody wrote.
331
+ if (profile === false || agent === false) return { raw: false }
332
+ if (profile === undefined && agent === undefined) return {}
333
+ // One side silent defers to the other; both present must agree.
334
+ return { raw: (profile ?? agent) === true && (agent ?? profile) === true }
335
+ }
336
+
321
337
  /**
322
338
  * Two allowlists under a ceiling: what BOTH layers admit.
323
339
  *
@@ -392,9 +408,27 @@ function mergeShell(
392
408
  ...(profile?.args || agent?.args
393
409
  ? { args: pairRules(profile?.args, agent?.args) }
394
410
  : {}),
395
- // Both must permit it. Absent means "no opinion", which for the one
396
- // switch that disarms every other rule defaults CLOSED.
397
- raw: (profile?.raw ?? false) && (agent?.raw ?? false),
411
+ /*
412
+ * Silence DEFERS; an explicit `false` refuses; two explicit `true`s agree.
413
+ *
414
+ * This read `(profile?.raw ?? false) && (agent?.raw ?? false)`, which
415
+ * treated an absent value as a written `false` — the one place in this
416
+ * file where silence is a verdict rather than "no opinion" (compare
417
+ * `intersectLists` directly below, and `pairRule`).
418
+ *
419
+ * The consequence was that a profile-level `raw: true` could not be
420
+ * expressed AT ALL. A user granting raw shell on their own machine had
421
+ * it ANDed away by every agent that simply had no `policy` block —
422
+ * which is every scaffolded agent — and the denial then said "raw shell
423
+ * is off" about a switch they had just turned on.
424
+ *
425
+ * Deferring matches how the ceiling treats every other surface: a
426
+ * profile that says nothing imposes no ceiling, and an agent that says
427
+ * nothing accepts the profile's. Both silent leaves `raw` ABSENT rather
428
+ * than false, so `decideShell` asks instead of refusing — the same rule
429
+ * the rest of the policy surface follows.
430
+ */
431
+ ...resolveRaw(profile?.raw, agent?.raw),
398
432
  spawn: {
399
433
  rule: pairRule(asRule(spawnRule(profile)), asRule(spawnRule(agent))),
400
434
  // The tighter cap wins; no cap on either side means unlimited.
@@ -139,34 +139,45 @@ export type ShellDecision = {
139
139
  /**
140
140
  * Decide one execution against the resolved `shell` policy.
141
141
  *
142
+ * ── One rule ────────────────────────────────────────────────────────────────
143
+ *
144
+ * **An explicit allow allows. An explicit deny denies. Silence asks.**
145
+ *
146
+ * Every branch below is an application of that sentence, and the sentence is
147
+ * what makes the surface predictable: a user reading their own policy can
148
+ * answer "what happens to a program I have not mentioned?" without knowing
149
+ * which of four code paths their command takes.
150
+ *
142
151
  * Order is deliberate and each step is a different question:
143
152
  * 1. Is this a shell, and is `raw` off? A shell defeats every rule below it,
144
153
  * so it is answered first and separately.
145
154
  * 2. Does `deny` name the program? Deny always beats allow.
146
- * 3. Does `allow` admit it? An allowlist that names nothing matching is a
147
- * denial — the same "declared, matched nothing" rule the glob resolver uses.
155
+ * 3. Does `allow` admit it? An allowlist that names nothing matching has said
156
+ * nothing about this program, so it asks.
148
157
  * 4. Do the argument patterns object? Advisory, and last.
158
+ * 5. Nothing spoke at all → ask.
159
+ *
160
+ * ── Why there is no `fallback` parameter any more ───────────────────────────
161
+ *
162
+ * There used to be one, because two callers wanted opposite answers for an
163
+ * undeclared surface: the capsule denied (it runs foreign, model-emitted code
164
+ * and must never grant by omission) and Axon allowed ("I did not set a policy"
165
+ * meaning a personal tool with the user's own privileges, not a brick).
166
+ *
167
+ * Both stances are now produced by ESCALATION plus its degradation, without a
168
+ * knob. A bare `Capsule()` has no decider, so `Escalation` answers false
169
+ * immediately and it still runs nothing. A user at a TUI is asked, and
170
+ * answering "always" writes the grant. The parameter was a second way to
171
+ * express something the escalation path already expresses correctly, and the
172
+ * two could drift.
173
+ *
174
+ * The cost of the old shape was concrete: an agent with no policy — which is
175
+ * every agent in its first minutes — got `shell.run:axon denied · no rule
176
+ * permits it` and had nowhere to go but the docs.
149
177
  */
150
178
  export function decideShell(
151
179
  shell: ResolvedCapsulePolicy["shell"],
152
180
  argv: string[],
153
- /**
154
- * What an UNDECLARED `shell` surface means.
155
- *
156
- * The two callers sit on opposite sides of a trust boundary and need
157
- * opposite answers, which is why this is a parameter rather than a constant:
158
- *
159
- * "deny" — the CAPSULE. It runs foreign, model-emitted code and must
160
- * never grant capability by omission. A bare `Capsule()` with no
161
- * policy can run nothing.
162
- * "allow" — AXON. It is wiring a box for its own declared blueprint, and
163
- * "I did not set a security policy" means a personal tool with
164
- * the user's own privileges, not a brick.
165
- *
166
- * Getting this wrong in either direction is silent: one bricks every
167
- * unconfigured capsule, the other hands an unconfigured sandbox a shell.
168
- */
169
- fallback: "allow" | "deny" = "deny",
170
181
  /**
171
182
  * The command as the caller received it, before splitting.
172
183
  *
@@ -177,11 +188,27 @@ export function decideShell(
177
188
  */
178
189
  command?: string,
179
190
  ): ShellDecision {
180
- // No shell block at all: the caller's own default posture decides.
181
- if (!shell) return { verdict: fallback, program: programName(argv[0] ?? ""), reason: "no-policy" }
191
+ // No shell block at all — nobody has spoken, so ask. Identical to a block
192
+ // that declares nothing (`shell: {}`), which is the point: whether a user
193
+ // omitted the key or wrote an empty object is not a security decision, and
194
+ // reading those two as different postures is how `{}` came to mean "allow
195
+ // everything" while omitting it meant "deny everything".
196
+ if (!shell) return { verdict: "escalate", program: programName(argv[0] ?? ""), reason: "no-policy" }
182
197
 
183
198
  const { program, shell: resolvedShell } = resolveProgram(argv)
184
199
 
200
+ /*
201
+ * Did any rule actually PERMIT this program, as opposed to merely failing
202
+ * to object to it?
203
+ *
204
+ * The function used to end with a bare `return allow`, which answered both
205
+ * questions the same way — an allowlist that named the program, and a
206
+ * policy that had never heard of it. The first is a grant somebody wrote;
207
+ * the second is silence. Collapsing them is what made an undeclared
208
+ * program run without anyone deciding it should.
209
+ */
210
+ let permitted = false
211
+
185
212
  // A chained/redirected/substituted command line is a SHELL PROGRAM, whatever
186
213
  // its first token is — see isShellCommand. Without this the decision was
187
214
  // made about `pwd` while `/bin/sh -c` ran `pwd && git push --force`.
@@ -199,9 +226,12 @@ export function decideShell(
199
226
  * author had never written. Asking is the honest answer to a question
200
227
  * nobody has answered, and the prompt can say what a shell actually is.
201
228
  */
202
- if (isShell && shell.raw !== true) {
229
+ if (isShell) {
203
230
  if (shell.raw === false) return { verdict: "deny", program, reason: "raw-shell" }
204
- return { verdict: "escalate", program, reason: "raw-shell" }
231
+ // `raw: true` is somebody writing "yes, shell lines are fine" — an
232
+ // explicit grant, so the program does not have to be named again below.
233
+ if (shell.raw !== true) return { verdict: "escalate", program, reason: "raw-shell" }
234
+ permitted = true
205
235
  }
206
236
 
207
237
  // Deny always beats allow, and always means DENY: this one is a rule
@@ -227,6 +257,7 @@ export function decideShell(
227
257
  */
228
258
  const admitted = shell.allow.some(pattern => policyGlobMatch(pattern, program))
229
259
  if (!admitted) return { verdict: "escalate", program, reason: "not-allowed" }
260
+ permitted = true
230
261
  }
231
262
 
232
263
  // Argument patterns — advisory, and only consulted once the program itself
@@ -253,6 +284,15 @@ export function decideShell(
253
284
  }
254
285
  }
255
286
 
287
+ // Nothing objected — but nothing permitted it either. Ask.
288
+ //
289
+ // This is the case that reaches a new user: an agent with no `policy` block
290
+ // at all, running its first command. Answering "allow" here is a grant
291
+ // nobody made; answering "deny" is a refusal nobody made and leaves them
292
+ // reading docs. The honest answer to a question no one has answered is to
293
+ // ask it, and "always" writes the rule they would have gone looking for.
294
+ if (!permitted) return { verdict: "escalate", program, reason: "no-policy" }
295
+
256
296
  return { verdict: "allow", program, reason: "allowed" }
257
297
  }
258
298
 
package/src/policy.ts CHANGED
@@ -515,6 +515,16 @@ export type PolicyResponseCommand = {
515
515
  id: string
516
516
  type: "policy:response"
517
517
  allow: boolean
518
+ /**
519
+ * Why a refusal was a refusal, when it was not a person saying no.
520
+ *
521
+ * "headless" means there was nobody to ask — a script, CI, a deployment.
522
+ * Without it every such denial recorded `escalation-denied`, which reads as
523
+ * a decision someone made and sends whoever is debugging a blocked agent
524
+ * looking for the person who made it. Absent on an allow, and absent when a
525
+ * decider genuinely declined.
526
+ */
527
+ reason?: "headless"
518
528
  }
519
529
 
520
530
  export type PolicyCall = {