Files
LLeMbas-CLI/src/runs-code.ts
T
HomerandClaude Opus 5.5 9945b76f74 The settings tool is the person's alone; files that run code have one definition (S9, S10)
- permission/rules.md §1, defaults.json user_only (spec 3.15.0): for a call
  of the settings tool only the default and user layers are read. A
  project's key that matches it (settings, sett*, *) and a rule made in the
  session are not read for it; the loader drops a project key that matches
  the name and says so.
- loop.json files.runs_code.project_dirs (was project_dir): .agent and
  .lembas. src/runs-code.ts is the one definition; edit mode's guarded files
  and device files both read it.

Conformance: rules.json +7, device_files.json +6.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 07:43:22 +00:00

25 lines
1.5 KiB
TypeScript

// The files of a project that run code (harness loop.json `files.runs_code`; acp.md, *Files that
// run code*): git's own directory — hooks and config run programs — and the agent's own
// configuration in the project: its config (rules, MCP servers), agents, commands and skills.
// One definition, for the two places that ask: edit mode, which does not change them unasked
// (permission/evaluate.ts), and device files, which change them only where the device says so
// (acp/files.ts). They differed: the second knew the directory by one of its two names.
import { LOOP } from "./harness.ts"
import { within } from "./within.ts"
const R = LOOP.files.runs_code
/** Whether a change at `p` (absolute) would change what runs in its project: a path with a
* `.git` in it; or, under a project's agent directory — any directory named `.agent` or
* `.lembas`, and `projectDir` when the caller knows the real one — the directory itself or one
* of the names that run. */
export function projectRunsCode(p: string, projectDir?: string, spec: typeof R = R): boolean {
const parts = p.split("/")
if (parts.some((x) => spec.segments.includes(x))) return true
const under = (rest: string[]) => !rest.length || spec.project.includes(rest[0]!)
const at = Math.max(...spec.project_dirs.map((d) => parts.lastIndexOf(d)))
if (at >= 0 && under(parts.slice(at + 1))) return true
if (projectDir && within(p, projectDir)) return under(p.slice(projectDir.length).split("/").filter(Boolean))
return false
}