"Always" on a path outside the project makes its external_directory rule (S11, S12)

permission/rules.md §3 (spec 3.15.0): an always answer to a call asked
about for reaching outside the project also makes an external_directory
rule per such path, for the session only, never saved to a project.
evaluate's Decision names those paths (outside); alwaysRules() is what the
engine and the conformance runner both make. A project rule that cannot be
saved no longer fails the approved call.

Conformance: rules.json `call` (+3).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
HomerandClaude Opus 5.5 committed 2026-12-03 07:49:48 +00:00
1 parent 22368bec1a
commit ead689301a
7 files changed
+125 -8

No files matched your search

+5
View File
@@ -93,6 +93,11 @@ All notable changes to LLeMbas CLI. The format follows
and `/decide` said "/trust creates it", and it did not — and says `/reload` loads the
project's config (it said to restart).
- A command that could not be started says why instead of "stopped (SIGTERM)".
- **"Always" on a file outside the project now holds.** It remembered the file for its tool but
not that the file may be reached outside the project, so the next identical call asked again.
The outside path is now remembered too, for the session only — it is never written into the
project's configuration. "Always in this project" no longer fails the approved call when the
project's configuration cannot be written; the rule then holds for the session.
- **The updater never moves to a new major version by itself.** The newest release of the
version's own major is installed; a later major (which may need a newer LLeMbas server) is
named — in `lembas update` and once an hour at most in the TUI — and installed only when you
+5
View File
@@ -137,6 +137,11 @@ page *Harness-parity* in LLeMbas CLI's wiki.
`remote.files_that_run_code` off, `_lembas/fs/*` wrote `.lembas/config.yaml` and its commands.
The CLI's edit mode reads the same list (one definition). **Both implementations; the key was
renamed**, so a reader of `project_dir` must read `project_dirs`.
- **"Always" makes what the card asked about** (`permission/rules.md` §3; `conformance/rules.json`
`call`): a call asked about because it reaches outside the project is remembered with an
`external_directory` rule for each such path as well, for the session only and never saved to
a project. **Both implementations**: before, "always" on a file outside the project left the
next identical call asked.
- **One answer to "inside a directory"** (`conformance/paths.json`, `op: within`): by whole names;
a child named `..cache` is a child.
- Conformance: every case of `conformance/terminal.json` is in the new names; cases of `env`,
+71 -1
View File
@@ -1,5 +1,5 @@
{
"about": "Which permission rule decides (permission/rules.md, spec 3.8.0; rule 2's set-aside 3.9.0). The rules by layer: `defaults` true — permission/defaults.json as the `default` layer; `user` and `project` — a configuration's permission map (a key's value an action, or a map of pattern → action, read in the order written); `made` — rules made during the session, in order, each `by` an `always` answer or a `menu`. With `request` (`permission`, `pattern`: what one call asks for): expect the action that decides, or null where no rule matches. With `set` (a rule a person makes now, by a menu): expect `result` — `unchanged` (the action is already in force), `refused` with the rule in its way as `by`, or `made` with `still`, the stricter narrower rules that still apply, in the order read. The same answers for a rule typed into a file as for one a menu wrote. LLeMbas: security/permission rules; CLI: src/permission/evaluate.ts. Spec 3.15.0: a user-only permission (defaults.json `user_only`) is decided by the defaults and the user layer alone.",
"about": "Which permission rule decides (permission/rules.md, spec 3.8.0; rule 2's set-aside 3.9.0). The rules by layer: `defaults` true — permission/defaults.json as the `default` layer; `user` and `project` — a configuration's permission map (a key's value an action, or a map of pattern → action, read in the order written); `made` — rules made during the session, in order, each `by` an `always` answer or a `menu`. With `request` (`permission`, `pattern`: what one call asks for): expect the action that decides, or null where no rule matches. With `set` (a rule a person makes now, by a menu): expect `result` — `unchanged` (the action is already in force), `refused` with the rule in its way as `by`, or `made` with `still`, the stricter narrower rules that still apply, in the order read. The same answers for a rule typed into a file as for one a menu wrote. LLeMbas: security/permission rules; CLI: src/permission/evaluate.ts. Spec 3.15.0: a user-only permission (defaults.json `user_only`) is decided by the defaults and the user layer alone. With `call` (spec 3.15.0; a file tool's call in `mode`, the project root /project, `path` absolute) and `answer: always`: expect `first` (the action before), `made` (the rules the answer makes, each with `save`) and `then` (the same call after).",
"cases": [
{
"about": "The defaults alone: a file is read, a .env asks.",
@@ -762,6 +762,76 @@
"pattern": "get mode"
},
"expect": "allow"
},
{
"about": "Always on a file outside the project makes the outside path's rule too, never saved to the project; the same call is then allowed.",
"defaults": true,
"call": {
"permission": "read",
"class": "read",
"path": "/srv/notes/todo.txt",
"mode": "manual"
},
"answer": "always",
"expect": {
"first": "ask",
"made": [
{
"permission": "read",
"pattern": "/srv/notes/todo.txt",
"save": true
},
{
"permission": "external_directory",
"pattern": "/srv/notes/todo.txt",
"save": false
}
],
"then": "allow"
}
},
{
"about": "Inside the project only the call's own rule.",
"defaults": true,
"call": {
"permission": "read",
"class": "read",
"path": "/project/.env",
"mode": "manual"
},
"answer": "always",
"expect": {
"first": "ask",
"made": [
{
"permission": "read",
"pattern": ".env",
"save": true
}
],
"then": "allow"
}
},
{
"about": "A written deny of the outside path still holds: nothing is asked, nothing made.",
"defaults": true,
"user": {
"external_directory": {
"/srv/*": "deny"
}
},
"call": {
"permission": "read",
"class": "read",
"path": "/srv/notes/todo.txt",
"mode": "manual"
},
"answer": "always",
"expect": {
"first": "deny",
"made": [],
"then": "deny"
}
}
]
}
+6
View File
@@ -84,6 +84,12 @@ When a person makes a rule — an "always" answer, or one set in a menu:
trusted project's configuration) — saved as a `project` rule. Because §2 treats `made` and
`project` alike, the session it was made in and the next start from the saved file decide
every call the same way.
- **An "always" answer makes what the card asked about** (spec 3.15.0). A call asked about
because it reaches outside the project (`external_directory`) is remembered with an
`external_directory` rule for each such path besides the rule for the call's own permission —
the latter alone left the next identical call asked. That path rule is made for the session
and never saved to a project's file: a machine's paths are not the project's. Where the card
offers no "always", none is made.
- The person is told what it did: where it holds, whether it was saved, and **which stricter
rules still apply** — every rule of the `default`, `user` or `project` layer that is narrower
than the new rule and stricter than it. (A rule set aside for every call it could decide is
+16 -1
View File
@@ -58,6 +58,21 @@ export interface Decision {
reason: string
/** Suggested "always allow" patterns for this request. */
always: string[]
/** The paths outside the project that the call is asked about (`external_directory`): an
* "always" answer makes a rule for each of them too (rules.md §3), or it would change nothing. */
outside?: string[]
}
/** The rules an "always" answer to `d` makes (permission/rules.md §3, spec 3.15.0): one per
* offered pattern under the call's permission, and one `external_directory` rule per path outside
* the project the call was asked about. `save`: whether it may be written to a project's
* configuration — never for a path outside the project (a machine's paths are not the project's). */
export function alwaysRules(req: Pick<PermissionRequest, "permission">, d: Decision): { rule: Rule; save: boolean }[] {
const made = d.always.map((pattern) => ({ rule: { permission: req.permission, pattern, action: "allow" as const, learned: true }, save: true }))
// Without a rule of its permission, an outside path stays asked whatever was remembered for the call.
if (!made.length) return []
for (const pattern of d.outside ?? []) made.push({ rule: { permission: "external_directory", pattern, action: "allow" as const, learned: true }, save: false })
return made
}
// The rules every session starts from: the harness spec's (harness/permission/defaults.json).
@@ -364,7 +379,7 @@ function evaluateRules(req: PermissionRequest, ctx: Context): Decision {
function withExternal(ruled: Action, ext: Action, external: string[], always: string[]): Decision {
const action = strictest(ruled, ext)
const reason = action === "allow" ? "allowed by rules" : ext !== "allow" ? `outside the project: ${external.join(", ")}` : "needs approval"
return { action, reason, always }
return { action, reason, always, ...(action === "ask" && ext === "ask" && always.length ? { outside: external } : {}) }
}
/** Commands that run another command, or can: approving one with `*` would approve anything. */
+10 -5
View File
@@ -8,7 +8,7 @@ import { isAbsolute, relative } from "node:path"
import type { Asker, AttachmentInfo, Bus } from "../bus/index.ts"
import type { Mode } from "../config/schema.ts"
import type { Level } from "../provider/effort.ts"
import { evaluate, judgeNewRule, ruleAction, shadowsDeny, type Context as PermContext, type PermissionRequest, type Rule } from "../permission/evaluate.ts"
import { alwaysRules, evaluate, judgeNewRule, ruleAction, shadowsDeny, type Context as PermContext, type PermissionRequest, type Rule } from "../permission/evaluate.ts"
import { ProviderError, type Client, type ImagePart, type Message, type ResolvedModel, type ToolCallPart, type Usage } from "../provider/types.ts"
import type { Plan } from "../plan/plan.ts"
import { LOOP } from "../harness.ts"
@@ -1381,13 +1381,18 @@ export class Engine {
edited = line
}
if (reply.kind === "session" || reply.kind === "project") {
for (const pattern of decision.always) {
// Learned: an approval never overrides a deny somebody wrote (see evaluate).
const rule: Rule = { permission: request.permission, pattern, action: "allow", learned: true }
// Learned: an approval never overrides a deny somebody wrote (see evaluate). A path outside
// the project gets its external_directory rule too, for this session only (rules.md §3).
for (const { rule, save } of alwaysRules(request, decision)) {
this.sessionRules.push(rule)
// Written to the project, it would come back as an ordinary rule and win over such a
// deny by coming last; it stays for this session only instead.
if (reply.kind === "project" && !shadowsDeny(rule, this.o.perm.rules)) this.o.persistRule?.({ permission: rule.permission, pattern, action: "allow" })
// A project file that cannot be written (a link, read-only) keeps the rule for the session:
// the approved call still runs.
if (reply.kind === "project" && save && !shadowsDeny(rule, this.o.perm.rules))
try {
this.o.persistRule?.({ permission: rule.permission, pattern: rule.pattern, action: "allow" })
} catch {}
}
}
}
+12 -1
View File
@@ -3,7 +3,7 @@
// this with each case's `expect`; `bun run harness record` fills in an `expect` a new case lacks.
import { within } from "../src/within.ts"
import { openUnder } from "../src/acp/agent.ts"
import { alwaysPatterns, toRules, evaluate, judgeNewRule, ruleAction, DEFAULT_RULES, type PermissionRequest, type Rule } from "../src/permission/evaluate.ts"
import { alwaysPatterns, alwaysRules, toRules, evaluate, judgeNewRule, ruleAction, DEFAULT_RULES, type PermissionRequest, type Rule } from "../src/permission/evaluate.ts"
import { terminalEnv } from "../src/terminal/env.ts"
import { contextPercent, plainValue, stateOf, userVar } from "../src/terminal/uservars.ts"
import { chip, judgeFile, parseContext, terminalBlock, TerminalContextError } from "../src/terminal/context.ts"
@@ -402,6 +402,17 @@ export const AREAS: Record<string, (c: Case) => unknown> = {
const j = judgeNewRule(c.set as Rule, written, [...written, ...made])
return j.result === "made" ? { result: "made", still: j.still.map(bare) } : j.result === "refused" ? { result: "refused", by: bare(j.by) } : { result: "unchanged" }
}
if (c.call) {
// A file tool's call, answered "always" (rules.md §3): what it makes, and the call again.
const k = c.call as { permission: string; class: PermissionRequest["class"]; path: string; mode: Mode }
const pattern = k.path.startsWith("/project/") ? k.path.slice("/project/".length) : k.path
const req: PermissionRequest = { permission: k.permission, class: k.class, patterns: [pattern], paths: [k.path] }
const ctx = { mode: k.mode, hardline: BUILTIN_HARDLINE, root: "/project", planDir: "/project/.agent/plans", projectDir: "/project/.agent" }
const first = evaluate(req, { ...ctx, rules: [...written, ...made] })
const answer = first.action === "ask" && c.answer === "always" ? alwaysRules(req, first) : []
const then = evaluate(req, { ...ctx, rules: [...written, ...made, ...answer.map((a) => a.rule)] })
return { first: first.action, made: answer.map((a) => ({ permission: a.rule.permission, pattern: a.rule.pattern, save: a.save })), then: then.action }
}
const q = c.request as { permission: string; pattern: string }
return ruleAction(q.permission, q.pattern, [...written, ...made]) ?? null
},