Repository navigation
feat(skills): put skills and AGENTS.md inside real runs, and enforce their policy - #100
Conversation
…their policy Commit #72 shipped the whole skill runtime — resolver, trust, locks, policy calculation, bounded loading, six packaged skills — and deferred the part that makes it exist: `prepareSkillSession` had no production call site. A run never saw a skill, never saw AGENTS.md, and never enforced a tool policy. This wires it into every surface that drives a brain, through ONE seam. ## The seam `src/core/skills/run_session.ts` — `openRunSession()` returns three things: headerLines what was loaded, and what the policy now is brief(task) the string the brain reads: rules + skills + host policy + task guard(tool) the host-side refusal, run immediately before execution The brief is composed BEFORE a brain is chosen, so the cloud dev-session request body and the local Ollama chat messages carry the byte-identical string — one composition, two transports, asserted on both payloads. The typed `AgentContextPacket` rides the NDJSON task frame for a brain that speaks it (additive + optional, so PROTOCOL_VERSION does not move). Wired at: `cmdCode` (one-shot agent — local, cloud dev-session, and the Python NDJSON brain) and `chat.runTurn` (REPL + one-shot chat, local and cloud). Enforced at: `hostLoop` and `runLocalTurn` — the only two places this host executes a tool. ## Never widen The guard runs BEFORE the operator permission gate, never instead of it. A skill subtracts from the tool surface; the operator gate then decides about what is left. Nothing a manifest says is consulted after that point, so there is no path by which a skill adds a tool, adds a permission, or skips a confirmation. An AUTOMATICALLY matched skill contributes context but NOT policy. A trigger phrase is a guess, and `aether agent "make the tests pass"` matches fix-ci, which forbids write_file — letting a guess narrow would silently leave the agent unable to edit the code it was asked to fix. Only `--skill <id>` narrows. ## Honesty - The Policy line says "enforced for every tool this host executes", because on the legacy cloud chat stream the server runs the tools and this process can refuse nothing. A cloud REPL turn with a narrowing prints NOT ENFORCED. - Token counts are measured from the composed bytes, never a manifest estimate. - Truncated, skipped, and over-budget instruction sources are named. - A skill directory that failed to index no longer reads as "no skill matches". - Instruction conflicts are rendered to the user AND to the model, with both values and which one wins — never silently resolved. - Instruction/skill content cannot forge the host's own fences. ## Fixes found on the way `resolveInstructionGraph` used `applicableSources(sources, null)` — the "no file open" set, which excludes every subtree-scoped source. A nested `src/AGENTS.md` therefore never reached a run, and a root-vs-nested conflict could never be detected because only one side was ever compared. Added `runScopedSources` / `buildRunInstructionContextPacket` for whole-repo runs; the file-scoped selector is unchanged. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Mutation testing the never-widen invariant: three mutations of the host loop, run against the whole suite. M1 hostLoop never consults the skill guard killed by 2 tests M2 refuseUndeclaredToolCall always returns null killed by 9 tests M3 operator gate runs BEFORE the skill guard SURVIVED — 26/26 passed M3 is the ordering the commit that introduced it calls "the whole never-widen invariant", and nothing asserted it. Every existing test still passed with the blocks swapped, because the call is refused either way and no assertion could tell the difference downstream. What actually changes under M3: the user is asked to approve a call host policy has already refused. The tool still never runs, so this is not an escalation — it is worse in a slower way. It trains a person to click through a confirmation that never meant anything, and it leaves the documented ordering free to drift in a later refactor with a green suite the whole way. The new test records what the gate was asked about and asserts it was asked about nothing. It is the only assertion in the file that fails under M3.
…ace unparsable rule scopes Adversarial pass over the seam: - fenceSafe escaped only CLOSING tags. A rules file containing a forged <source path=... digest=...> could open a second element inside a real one and show the model a host-attributed block with a digest the host never computed. Now both halves are escaped, losslessly (attributes survive as text). - Header rows carry manifest- and repo-authored strings. Sanitized on the way out so no ANSI introducer reaches the terminal. - runScopedSources drops a source whose glob frontmatter will not parse. Right to drop, wrong to drop silently: it now lands in graph.skipped and is named. - The typed instruction packet now sanitizes content like the skill packet does. - The REPL header was gated on composed size alone, which swallowed exactly the cases it exists to report (an untrusted skill, an unindexable manifest, a dropped rules file — all of which compose zero context bytes). Gated on hasWarnings || notices too. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Three independent reviewers took the diff apart along one lens each: authority (can a skill widen anything), honesty (can something unknown render as fine), and untrusted content (a cloned repo's AGENTS.md is attacker-influenced text). Authority held with no constructible widening path. The other two did not. 1. The REPL swallowed exactly the lines it exists to print. chat.ts gated the header on `run.contextTokens > 0`, but a notice — an untrusted project skill, a manifest that would not index, a candidate dropped at the per-turn ceiling — can occur with NOTHING composed. In a project with no AGENTS.md and one untrusted skill, the run composes zero bytes, so the single line saying a skill was withheld was the one line that never printed. Surfaces now consult `run.hasWarnings`, which is about whether something was withheld, not about how big the context is. 2. A rules file whose scope would not parse vanished without a trace. runScopedSources drops an unsupported-syntax source because its glob frontmatter is unreadable, so its scope is unknown and applying it to a whole run would be a guess about which files it governs. Dropping it is right. Dropping it silently is not: discovery found the file, read it, and the user believes it is in force. It is now recorded in the graph's skipped list, which the header already renders. 3. The same bytes left on two channels with two different sanitizations. Skill bodies and the composed brief went through sanitizeForTransport; the instruction packet copied source content raw, so a consumer reading context.instructions instead of the brief received a dirtier string than the brief carried. One sanitizer now covers both. 4. Fence escaping covered only closing tags. The real </source> was neutralized, so nothing terminated early — but a forged `<source path=... digest=...>` in a rules file passed through untouched and appeared inside a legitimately loaded element, claiming host-authored provenance it did not have. The regex now matches both halves, and the replacement escapes the whole matched tag instead of re-emitting a capture group, which had been quietly rewriting any opening tag it matched into a closing one and dropping its attributes. Header rows are also sanitized on the way out. A project skill's trigger phrase is manifest-authored and charset-unvalidated, and it reaches the terminal inside the "why this matched" line. Each fix has a test that fails without it. 1163 pass, verify:production ok.
…and a resume checks A session id names a conversation. It does not name the instructions that conversation was conducted under — and those live in files anyone can edit between two runs. Until now a resume re-read whatever AGENTS.md and whatever skill bodies were on disk at that moment and continued under the old session identity without a word. The session manifest and the portable handoff now carry a context record: skill id, version, digest, invocation, trust and lock state, the instruction source paths, one digest over the whole ordered instruction graph, and the conflicts the run resolved. Digests and paths only — never instruction or skill CONTENT. A session directory is not the place for a project's prose, and a handoff carries this across machines. On resume the two are compared: - A changed SKILL digest REFUSES. The user named that skill once; its body is executable guidance, and a different body under the same id and version is not the thing they approved. Same for a trust state that dropped. - A changed instruction graph is ANNOUNCED and proceeds, naming what came into force and what left. Editing AGENTS.md between runs is ordinary work and refusing it would make resume unusable — but it is never silent. - A skill present then and absent now is reported, not refused: the run is narrower, never wider. parseHandoff validates the record as untrusted input, because it is. A skill row with no digest is DROPPED rather than half-read — it cannot be compared against anything, so keeping it would put a meaningless value into the comparison. An entirely empty record is dropped too: absent means "the prior run recorded nothing", empty would claim "the prior run ran under no rules and no skills", and those lead to different resume decisions. contextDrift is exported and directly tested — the comparison is the point, so it has to be assertable without cutting a worktree and driving a brain. 1170 pass, verify:production ok.
Update — 4 commits, all checks greenTwo adversarial rounds landed after the original push. Both found real holes, and each fix ships with a test that fails without it.
Mutation testing round two, against the whole suite:
M3 is the ordering this PR calls the whole never-widen invariant, and nothing asserted it. Every test passed with the blocks swapped, because the call is refused either way and nothing downstream could tell. What changes under M3 is that the user is asked to approve a call host policy has already refused — not an escalation, but worse in a slower way: it trains people to click through a confirmation that never meant anything, and it leaves the documented ordering free to drift with a green suite the whole way.
Header rows are also sanitized on the way out: a project skill's trigger phrase is manifest-authored and charset-unvalidated, and it reaches the terminal inside the "why this matched" line. Suite: 1131 pass / 0 fail / 1132 total locally (minus the two known Windows-local hangs). CI green on all five checks — ubuntu, windows, CodeQL, analyze, supply-chain — and CI runs the files skipped locally. |
#98 moved main.ts's flag table into cli_registry.GLOBAL_FLAGS and added a dispatch-table check ahead of the switch. Resolved by taking main's structure whole and relocating this lane's two flags (`--skill`, `--no-skills`) into GLOBAL_FLAGS beside the other `aether agent` flags — they are global rather than command-owned because `aether agent`, `aether chat` and the REPL all open the same run session. The dispatch-table check runs before the switch, unchanged. Both lanes verified together after the merge: `aether agent --skill fix-ci` renders and enforces its policy, and `aether doctor --only <id>` still reaches the dispatched command. 1164 pass, 0 fail.
Lane evidence — adversarial review, mutation testing, and a real-binary canaryEverything below was run against Gates
Mutation testing the load-bearing invariantThree mutations of the host loop, each run against the whole suite:
M3 is the ordering this PR's own description calls the never-widen invariant, and nothing Adversarial reviewThree reviewers, one lens each, none of which built the code. Authority — held. No constructible path where a skill widens anything. Both tool-execution Honesty — did not hold. Two real holes, both fixed here.
Untrusted content — did not hold. Two fixed.
Each fix has a test that fails without it. Real-binary canaryA throwaway repo with a root The same prompt with no flag matches
The planted skill cannot run unreviewed, and exits non-zero: and on an ordinary run it is named rather than passing as "none matched": ContinuityThe session manifest and the portable handoff now record which rules and skills a run was Not done here
|
Update 2 — session provenance, and merged with
|
Five conflicts, all resolved toward the seam main established: - src/commands/cli_registry.ts — union of dispatch entries. The lane's `sessions` entry (own `flags`: --undo, --no-select; --all/--out read off ctx.flags because they are globals) sits beside main's `review`/`ship` entries. No entry redeclares a global. - src/main.ts — GlobalFlags now carries `all`, `testCmd` (main) and `out` (lane). No inline options literal and no `case "sessions"`: the lane had already moved onto CLI_PARSE_OPTIONS in d1dc8c4/a6c6f7b. - src/core/context.ts — GlobalFlags is the union: all, out, testCmd. - src/core/session_log.ts — both provenance sets kept. #99's manifestBody()/indexSelf() structure survives (the session index is built only from manifestBody), and #100's `context` field is carried into that body alongside the lane's `skills`/`instructionsDigest`: they record different things — what the caller declared, and what the host loop saw. `homedir` dropped from the imports; the lane resolves the log root through logs_root.ts, so main's import had no remaining use. - COMMANDS.md — every command row kept; the CLI registry index is the union (sessions + review + ship). typecheck clean; npm test 1440 tests, 1436 pass, 0 fail, 4 skipped.
Lane AA-SKILLS-03 (SC-CORE supercluster). Base
ed094dc8.The gap
Commit #72 landed the entire skill runtime — instruction resolver, trust and lock system, effective-policy calculation, bounded loading, health checks, six packaged skills — and explicitly deferred the part that makes it exist.
prepareSkillSessionatskill_session.ts:44had no production call site. A real run never saw a skill, never sawAGENTS.md, and never enforced a tool policy. This lane is composition, protocol, visible provenance, and enforcement.One seam, two transports
src/core/skills/run_session.ts—openRunSession()returns three things:headerLinesbrief(task)guard(tool)The brief is composed before a brain is chosen, so the cloud dev-session request body and the local Ollama chat messages carry the byte-identical string. That is the "one host-loop contract": not two renderers that agree today, but one string with two transports — and it is asserted on both payloads.
Wired at:
cmdCode(one-shotaether agent— local Ollama, cloud dev-session, and the Python NDJSON brain) andchat.runTurn(REPL + one-shot chat, local and cloud).Enforced at:
hostLoop(code.ts) andrunLocalTurn(chat.ts) — the only two places this host executes a tool.The typed
AgentContextPacketrides the NDJSON task frame for a brain that speaks it. Additive and optional, soPROTOCOL_VERSIONdoes not move.Evidence 1 — a real CLI run
--skill nopeexits 2 withskill.not_foundand renders the guidance; it does not degrade into a quiet skill-free run.Evidence 2 — what the model actually received
The composed brief, from the same project (head):
Asserted in the request payload, not in prose:
the rules and the skill body reach the local Ollama request payload— captures themessagesarray through the injected chat seam.the SAME brief bytes reach the cloud dev-session request body— captures the JSON body ofPOST /agent/dev/sessionsat the fetch layer and assertsbody.task === brief, byte for byte.with no rules and no skills the brief is the task, unchanged— an unskilled run is byte-identical to one without this seam at all.Evidence 3 — enforcement
What a narrowed policy actually refuses at the host:
hostLoop refuses a tool the active skill does not declare — nothing executes— a spy executor records zero calls, with a gate that would have approved everything. The brain gets[refused by host policy: skill.tool_not_declared] … allowed this run: read_file, repo_search.and the loop continues.a refused write never reaches the disk (real ToolExecutor, real path)— real executor, real cwd,existsSync(victim) === false.runLocalTurn enforces the same policy on the REPL's local path— same refusal on the second execution site.hostLoop still executes a tool the skill DOES declare— the narrowing is not a blanket denial.Evidence 4 — never widen, mutation-tested
The invariant, proven by breaking it three ways and restoring:
refuseUndeclaredToolCall: intersection to uniontwo skills INTERSECT — the union is never takena skill cannot grant a permission the operator envelope lackshostLoopstops consulting the guarda refused write never reaches the diskAlso covered: an invented tool name is schema-invalid and refused at the gate;
secrets.read/workspace.outside/billing.spendare schema-invalid in a manifest; a skill that requires authority the session lacks refuses the run rather than running degraded; andthe operator permission gate still runs after the skill narrowing— the skill allowswrite_file, the operator gate says no, and the file is still not written.Design decision worth reviewing
An automatically matched skill contributes context but NOT policy. A trigger phrase is a heuristic.
aether/fix-citriggers on "make the tests pass" and forbidswrite_file— so letting a phrase match narrow would leaveaether agent "make the tests pass"silently unable to edit the code it was asked to fix, with a header line as the only explanation. Only a skill you name with--skillapplies its policy.This only ever removes a restriction a guess produced; it cannot add authority, because an automatic skill's manifest was already incapable of granting any. The header says so:
host default · 8 tools — an automatically matched skill adds context but never removes authority.Honesty rules held
/agent/chat/stream) the server runs the tools and this process can refuse nothing. A cloud REPL turn carrying a narrowing printsPolicy ! NOT ENFORCED on this turn.Contextis measured from the composed bytes, nevermanifest.max_tokens.Bug found and fixed on the way
resolveInstructionGraphusedapplicableSources(sources, null)— the "no file open" set, which by design excludes every subtree-scoped source. So a nestedsrc/AGENTS.mdnever reached a run at all, and a root-vs-nested conflict could never be detected because only one side was ever in the comparison. AddedrunScopedSources/buildRunInstructionContextPacketfor whole-repo runs; the file-scoped selector is unchanged and still used where a file is open.Tests
npm run typecheckclean. New:test/skill_host_loop.test.ts, 26 tests. Full suite (minustool_executor/terminal_session, the known Windows-local hangs — CI is the gate): 1125 pass, 0 fail, 1126 total.Lease collisions to arbitrate
src/main.ts— shared, additive-only, controller-arbitrated. Added the two flag definitions (skill,no-skills), oneskillOptsobject, and passed it to the existingcmdCode/cmdChatdispatch lines. No existing line rewritten. Other lanes also need entries here.src/core/brain_protocol.ts— outside the declared lease. Carries the additive optionalAgentContextPacketon the task frame plus itsencodeCommandemission. Additive and optional by CONTRACTS.md's versioning rule;PROTOCOL_VERSIONis unchanged and a brain that predates it sees no key. Flagged for the controller.src/commands/code.ts— body only. TheprCreateHinttail (AA-SHIP-02) is untouched.COMMANDS.md— outside the declared lease; two flag rows plus the header example, because a shipped flag with no documentation is half-shipped.src/core/autonomy.ts(gateActionFor) was read only. The gate's categories are unchanged; the skill guard sits upstream of it.skill_session.tsandbrain_protocol.tswere rewritten under me mid-session by another process editing the same directory. The two designs converged rather than clobbered (typed packet and rendered brief are complementary) and the result is one coherent tree — but the controller should know the worktree was not exclusive.Named as unwired / unproven
/agent/chat/stream, taken on 404/403 from the dev route): the server executes tools, so the host enforces nothing there. Rendered as NOT ENFORCED; not fixable from this side.buildDevSessionRequest.capabilitiesstill sends all 8TOOLS, so the server is not told about the narrowing. Host-side enforcement is unaffected.envelope.tsandbrain_cloud.tsare outside this lease./skillslash command.--skill/--no-skillsare session-level on the launching command only.AgentContextPacketon the task frame, but nothing in this repo consumes it — the Python mirror is a separate install and was not exercised. Unproven end to end.tool_executorandterminal_sessiontests were not run locally (known Windows hang, unrelated to this change). CI is the gate.🤖 Generated with Claude Code