Skip to content

feat: task-scoped guard profiles (command/agent) and guard lock - #51

Merged
jflowers merged 6 commits into
mainfrom
opsx/agent-guard-overrides
Nov 13, 2026
Merged

jflowers merged 6 commits into
mainfrom
opsx/agent-guard-overrides

Conversation

@jflowers

@jflowers jflowers commented Nov 12, 2026 •

Copy link
Copy Markdown
Owner

Closes #48. Closes #47. Part of unbound-force/dewey#153.

Summary

Guard settings were all-or-nothing per project, and project config outranks global config. The curation workaround, a committed requireStepReferenceInTools: false, turned the trace check off for every agent in the repo, and anywhere that file was copied.

Fleet dispatch makes per-instance settings the wrong unit. gh-hud starts every unattended session as autonomy and picks the task with a slash command. Config is deployed once per machine, and instances aren't restarted per task. So this change picks grants per session, from what the session is doing:

  • The slash command it ran, recorded by command.execute.before. It stays until another command runs.
  • Its agent, from the latest user message.
  • Its ancestry. Subagent sessions inherit their parents' grants.

OpenSpec change: openspec/changes/agent-guard-overrides/. The spec artifacts were pushed before each implementation commit.

// ~/.config/opencode/supervisor/config.json  (deployed per machine)
{
  "lockGuards": true,
  "profiles": [
    { "name": "distill", "match": { "command": "dewey-distill" },
      "traceCheck": { "exemptTools": ["dewey_*", "read", "grep", "glob"] } },
    { "name": "curator", "match": { "agent": "curator" },
      "traceCheck": { "exemptTools": ["dewey_*"] } }
  ]
}
FR Behaviour
FR-072 Per-session context: agent (chat.message), slash command (command.execute.before, without the /, kept until the next command), and parent (session.created/session.updated events). If the parent is unknown, it falls back to one session.get lookup (2 s limit, cached; a failed lookup counts as no parent).
FR-073 profiles is honored only from the global file. In the project file or plugin options it's ignored with a warning. A bad profile is dropped with a warning; the rest of the global file, including lockGuards, stays in force. At most 64 profiles.
FR-074 A profile applies when every match key (agent and/or command) equals the session's value or an ancestor's, up to 8 levels. Matching traceCheck.exemptTools calls skip only the file-path trace check. Reward-hacking, directive, protected-state and approve/review gate checks still run. Globs that match bash, edit, write, patch, multiedit or apply_patch (so * too) are rejected, as are unknown keys. Globs are capped at 512 characters and 32 wildcards.
FR-075 lockGuards: true in the global file strips blockRewardHacking: false, requireStepReferenceInTools: false and mode: "repair-only" from the project file and plugin options, with a warning. The environment and the global file stay authoritative.

The identity log line now also reports lockGuards=<bool> and the profile names. An applied exemption logs once per profile and tool.

History on this branch

  • 7d9e089: the first cut, with per-agent agentOverrides.
  • d0f23ce: review-council round 1, committed as the OpenCode run left it:
    • the lock also strips a lower-tier repair-only mode;
    • exemptions are logged;
    • glob bounds;
    • protected-state and gate scenarios.
  • ca473f3 + acbf641: per-agent overrides replaced with task-scoped profiles (command and/or agent, with inheritance), following the fleet-dispatch discussion. The review round's guarantees are kept.

Scope decisions

  • No rewardHackingScope knob. FR-071 (fix: scope reward-hacking markers to execution surfaces (#46) #49) already made execution-surface scanning the default.
  • feat: configurable trace-check exemptions for knowledge-store MCP tools #47's open question: read-only tools aren't exempt unless a profile lists them.
  • No environment-variable form. Grants live in the per-machine global file.
  • Deliberate exception to whole-file rejection (FR-057). A bad profile doesn't reject the global file, which would also drop lockGuards.
  • The command persists for the session, so a task's follow-up messages keep its grant. This also means nothing depends on whether command.execute.before fires before or after the command's chat.message.

Residual risks

  • A repo-defined agent or command that reuses a granted name gets the grant. Grants only narrow, and gates and directives still apply.
  • Not verified against a live OpenCode: that command.execute.before fires for a TUI started with --prompt "/<command> <args>" (gh-hud's dispatch_mode = "tui") before the command's first tool call. If the prompt is sent as plain text instead of running the command, or the hook fires late, those sessions get no command grant (fail closed).

Verification

  • bun test: 421 pass, 0 fail.
  • node --test test/*.test.ts: 421 pass, 0 fail (Node 26).
  • Both runs used an isolated XDG_CONFIG_HOME.
  • Mutation checks:
    • Removing ancestor walking fails both inheritance tests.
    • Removing command recording fails 5 tests: the command-recording test, the command grant, matching on both keys, and both inheritance tests.

Not done (repo process)

🤖 Generated with Claude Code

jflowers and others added 2 commits November 12, 2026 13:41
Per-agent trace-check exemptions from the global config file
only (FR-072..FR-074) and a global guard lock (FR-075).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
FR-072: record each session's agent from the latest user message.
FR-073: agentOverrides honored only from the global config file;
project file and plugin options lose the key with a warning; bad
entries drop individually without rejecting the global file.
FR-074: traceCheck.exemptTools tool-name globs skip the file-path
trace check for that agent only; entries matching a file-mutating
builtin are rejected; reward-hacking, directives, and gates still
apply.
FR-075: global lockGuards strips guard-disabling false values from
the project file and plugin options; env and global stay
authoritative.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@jflowers jflowers left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Council Verdict: APPROVE WITH ADVISORIES

Reviewers: divisor-adversary, divisor-architect, divisor-curator, divisor-guard, divisor-sre
Iterations: 2

Input: origin/main@5c9c50a...opsx/agent-guard-overrides@7d9e089e plus uncommitted working-tree fixes from iteration 1 — this verdict covers the working tree, not the pushed head. The pushed head still carries the two HIGH findings fixed in iteration 1; commit and push before merging.

Council approved with advisories — no unresolved HIGH/CRITICAL findings; one MEDIUM advisory remains (below).

Dispatch Provenance

Run Agent Source Requested Resolved parent Reported
9882f6be divisor-adversary advisor enmaas/rits/zai-org/glm-5-3 — enmaas/rits/zai-org/glm-5-3
98610cc1 divisor-architect advisor enmaas/rits/zai-org/glm-5-3 — enmaas/rits/zai-org/glm-5-3
a33edbd4 divisor-curator advisor enmaas/rits/zai-org/glm-5-3 — enmaas/rits/zai-org/glm-5-3
19ae5ff5 divisor-guard advisor enmaas/rits/zai-org/glm-5-3 — enmaas/rits/zai-org/glm-5-3
83203602 divisor-sre advisor enmaas/rits/zai-org/glm-5-3 — enmaas/rits/zai-org/glm-5-3

Iteration 1 — REQUEST CHANGES (resolved in the working tree)

19 findings (2 HIGH, 7 MEDIUM, 10 LOW); 15 fixed, 3 left as advisories. Key fixes: the guard lock now also strips mode: "repair-only" from project config and plugin options; applied exemptions log once per agent+tool per session; protected-state, approve-gate, and enforce-directive survival of an exempt call is pinned by tests; __proto__-keyed entries warn-drop; exempt-tool globs carry complexity caps; test:node includes the new test file; the delta spec gained a Purpose section and a Principle V assessment; website capabilities issue unbound-force/website#412 and blog issue #52 are filed and pinned.

divisor-sre (APPROVE WITH ADVISORIES)

  • [MEDIUM] config-management — index.ts:1502: the guard lock fails open when the global config file has any malformed sibling key. validateSupervisorConfig rejects the whole file and returns an empty config, so lockGuards: true next to a typo'd memoLimits (or a trailing comma) silently drops the lock and the agent overrides, after which a committed project config can disable the guards and set mode: "repair-only". The warning says only "file ignored" and never states the lock is inactive. Resolving the lock key independently of whole-file validation, or naming the inactive lock in the warning, closes the gap.
  • 1 LOW finding omitted.

divisor-adversary (APPROVE WITH ADVISORIES)

  • 1 LOW finding omitted.

divisor-architect (APPROVE WITH ADVISORIES)

  • 4 LOW findings omitted (one shared with divisor-guard).

divisor-curator (APPROVE WITH ADVISORIES)

  • 1 LOW finding omitted.

divisor-guard (APPROVE WITH ADVISORIES)

  • 1 LOW finding omitted.

Full finding text for the omitted LOWs is in the local terminal report and the dispatch artifact.

Linked Issues

Issue Title
#48 feat: per-agent guard overrides (global-config only, narrowing only) and guard lock
#47 feat: configurable trace-check exemptions for knowledge-store MCP tools

This review was generated by /uf.review-council (AI-assisted).

jflowers and others added 3 commits November 12, 2026 16:06
Fixes from the /uf.review-council run in OpenCode (committed as left):
- lockGuards also drops a lower-tier mode: "repair-only", so a project
  config cannot unregister the guards under the lock
- applied trace-check exemptions log once per agent+tool per session
- exemptTools globs bounded (512 chars, 32 wildcards); "__proto__"
  agent key dropped
- spec: protected-state check (FR-061) still applies to exempt calls;
  Purpose section; constitution V assessment
- test:node script includes test/agent-overrides.test.ts; docs follow

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Replace per-agent agentOverrides with global profiles matched on
slash command and/or agent, inherited by subagent sessions through
parentID (FR-072..FR-074, design D1/D2/D4/D7). gh-hud dispatches every
unattended task as the autonomy agent, so the command is the only
in-session signal that identifies the task.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Replace per-agent agentOverrides with global `profiles` matched on the
session's slash command and/or agent, inherited by subagent sessions
(FR-072..FR-074). gh-hud dispatches every unattended task as the
autonomy agent, so the command is what identifies the task.

- command.execute.before records the session's latest slash command
  (sticky until another command runs)
- session.created/updated events record parentID; an unknown parent is
  looked up once via session.get (2 s bound, cached; failure = root)
- profiles apply when they match the session or an ancestor (8 levels);
  grants union; review-round guarantees kept (builtin rejection, glob
  bounds, protected state, gates, lock incl. repair-only mode)
- src/agent-overrides.ts -> src/guard-profiles.ts (+ test rename)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@jflowers jflowers changed the title feat: per-agent trace-check exemptions and guard lock feat: task-scoped guard profiles (command/agent) and guard lock Nov 12, 2026
@jflowers
jflowers marked this pull request as ready for review November 13, 2026 14:40
- lockGuards fails closed: a global file rejected for another key (or
  malformed JSON) still keeps lockGuards: true
- the lock also ignores guard-disabling environment variables, which
  per-directory env tools (mise.toml [env], .envrc) let a repo set;
  XDG_CONFIG_HOME cannot point around a lock in the home-directory
  file (home from the OS account, not HOME)
- a slash command scopes one task: cleared by the first human-typed
  message after the session goes idle; plugin-injected messages during
  the task keep it
- failed parent lookups are retried after a 30 s backoff instead of
  being cached as a root session
- lineage resolves only when some profile could exempt the tool;
  exempt-tool globs compile once
- the exemption notice logs only when the exemption decided the call
- wildcard exempt globs must start with an MCP server prefix
- command.execute.before no longer sits under dispose's JSDoc

Tests for each fix on Bun and Node, each confirmed by a mutation check.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@jflowers
jflowers merged commit d3cd814 into main Nov 13, 2026
jflowers added a commit to jflowers/dewey that referenced this pull request Nov 15, 2026
…ll automation

Apply 21 findings (6 HIGH + 15 LOW/MEDIUM) from iteration 1:
- spec.md: harden supervisor-prerequisite to fail-closed (no tightest-achievable fallback, unattended mode disabled until jflowers/opencode-supervisor#51 ships, records no-op artifact + notice)
- contracts/scope.md: bound distill-policy.yaml (16 KiB, depth 3, 100 entries), deny overly-broad ["*"], define durable no-op artifact path and provenance persistence
- contracts/rolling-pr.md: define branch sanitization charset/length/collision (FR-011), sanitization gate for critical/high findings, human-commit preservation guard (FR-015), concurrency CAS via force-with-lease
- contracts/distiller-allowlist.md: enumerate execution surface (filesystem/git/GitHub/MCP registration), deny push --force and non-distill writes, clarify global-only widening remains fail-closed

Fulfills manual-apply directive from iteration 1 human decisions (all APPLY).

Co-Authored-By: internal-model
jflowers added a commit to jflowers/dewey that referenced this pull request Nov 15, 2026
… (T036-T039)

Phase 7 / US5: the unattended pipeline's three server-side stages
(scope, group_learners, rolling_pr) registered as MCP tools
(tools/distill_tools.go) so the distiller agent drives the pipeline
entirely through the guarded server surface; new
dewey gate distill-unattended startup gate (gate.go) enforces the
FR-016 global-only widening rule — only the global
opencode-supervisor command: dewey-distill-auto profile may widen,
repo-local .opencode/supervisor.yaml is never read, refusal is
fail-closed until jflowers/opencode-supervisor#51 ships and records
the FR-021 no-op artifact; distiller frontmatter gains the
distill-unattended bash allow and both gate copies (tracked file +
agents.go mirror) stay byte-identical, guarded by shape and parity
tests in cli_test.go; interactive /dewey-distill verified unchanged
(T038). Handler-level tests cover the MCP surface including the
no-op artifact recording; CRAPload 48/48, GazeCRAPload 41/45.
jflowers added a commit to unbound-force/dewey that referenced this pull request Nov 16, 2026
…ll automation

Apply 21 findings (6 HIGH + 15 LOW/MEDIUM) from iteration 1:
- spec.md: harden supervisor-prerequisite to fail-closed (no tightest-achievable fallback, unattended mode disabled until jflowers/opencode-supervisor#51 ships, records no-op artifact + notice)
- contracts/scope.md: bound distill-policy.yaml (16 KiB, depth 3, 100 entries), deny overly-broad ["*"], define durable no-op artifact path and provenance persistence
- contracts/rolling-pr.md: define branch sanitization charset/length/collision (FR-011), sanitization gate for critical/high findings, human-commit preservation guard (FR-015), concurrency CAS via force-with-lease
- contracts/distiller-allowlist.md: enumerate execution surface (filesystem/git/GitHub/MCP registration), deny push --force and non-distill writes, clarify global-only widening remains fail-closed

Fulfills manual-apply directive from iteration 1 human decisions (all APPLY).

Co-Authored-By: internal-model
jflowers added a commit to unbound-force/dewey that referenced this pull request Nov 16, 2026
… (T036-T039)

Phase 7 / US5: the unattended pipeline's three server-side stages
(scope, group_learners, rolling_pr) registered as MCP tools
(tools/distill_tools.go) so the distiller agent drives the pipeline
entirely through the guarded server surface; new
dewey gate distill-unattended startup gate (gate.go) enforces the
FR-016 global-only widening rule — only the global
opencode-supervisor command: dewey-distill-auto profile may widen,
repo-local .opencode/supervisor.yaml is never read, refusal is
fail-closed until jflowers/opencode-supervisor#51 ships and records
the FR-021 no-op artifact; distiller frontmatter gains the
distill-unattended bash allow and both gate copies (tracked file +
agents.go mirror) stay byte-identical, guarded by shape and parity
tests in cli_test.go; interactive /dewey-distill verified unchanged
(T038). Handler-level tests cover the MCP surface including the
no-op artifact recording; CRAPload 48/48, GazeCRAPload 41/45.
jflowers added a commit to unbound-force/dewey that referenced this pull request Nov 27, 2026
…issue notice

`dewey gate distill-unattended` probed
~/.config/opencode-supervisor/supervisor.yaml for a YAML
`commands.dewey-distill-auto` key — a placeholder written before
jflowers/opencode-supervisor#51 shipped. The supervisor (v2.9.1) reads
profiles only from opencode/supervisor/config.json under an absolute
XDG_CONFIG_HOME, else under $HOME/.config, as strict JSON with a
`profiles` array, so the gate refused on every machine.

The gate now checks exactly that one file and passes iff a profile's
`match.command` (trimmed, leading "/" stripped) is dewey-distill-auto.
Absent file or no matching profile refuses as supervisor-unavailable;
unreadable, invalid JSON or a non-array `profiles` refuses naming the
file. The Fix shows the profile to add. Refusals still record the no-op
artifact; the `Notice:` line is gone.

`/dewey-distill-auto` and the `distiller` agent drop the `#N` issue
argument and the issue-comment step (a stray argument is ignored), and
`gh issue comment` leaves the distiller's bash allowlist. Tracked
scaffold copies are regenerated with fresh markers so untouched copies
refresh on re-init.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant