diff --git a/host-setup/agent-safety/claude/README.md b/host-setup/agent-safety/claude/README.md index 57a9ead1d..588d14782 100644 --- a/host-setup/agent-safety/claude/README.md +++ b/host-setup/agent-safety/claude/README.md @@ -27,7 +27,7 @@ Into `~/.claude/` (or `%USERPROFILE%\.claude\` on Windows): - **The permission rules this kit owns, merged into `settings.json`** beside the hook registration. Each is declared as a prefix and a rule. A re-run drops every rule the prefix owns before adding the current one. So a rule whose spelling changes updates in place rather than accumulating beside the version it replaced. Ownership requires a rule-syntax delimiter after the prefix. That is because the prefix ends at the script name and a bare prefix test would also claim a longer path such as `pr_review.py-custom`. With the delimiter required, a rule written by hand for a different script is never touched. These widen rather than restrict. That is why they are their own component, for the same reason the `fleet-bootstrap` block is separate from the `agent-safety` one. Today the list holds the rules for `scripts/pr_review.py`, one for each spelling it runs under, `python3` and `uv run --no-project --script`. They cover the review loop's `reply` and resolve, and the `merge` squash merge into `develop`, which checks the gate's readable items in code. They also cover the `cleanup` delete of a merged pull request's head branch. Driving that loop by hand needs a raw GraphQL mutation carrying a node id, the shape that reached a stranger's repository. The script queries the id itself and takes no argument an id fits in. The `:*` rule approves any arguments, so it approves any `merge` or `cleanup` call. Every check the merge or the delete makes therefore lives inside its subcommand rather than in the rule. What the rule decides is which command runs without a prompt. It matches the command text rather than the directory the command runs in. So it reaches a `scripts/pr_review.py` in any checkout that carries one. An absolute path would not narrow that. That is because the hub is reached as a checkout of the caller's own and its location differs per task. So pinning one path would name a checkout the next task does not use. What bounds it is the rule that an agent reaches the hub as a checkout of its own, fetched immediately before it is read. That rule excludes a copy the agent happens to find on disk. The `fleet-bootstrap` block beside this carries that rule, and [`GOVERNANCE.md`][governance] "Hub-Hosted Tooling" states it in full. - **The `autoMode` rules this kit owns, merged into `settings.json`** in the same pass. Claude Code reads `autoMode` from user or managed settings alone and never from a repository's `.claude/settings*.json`. So the block is host-wide, and with nothing owning it, one repository's rules written there would apply to every repository. The kit owns an entry by the tag `[agent-safety]` followed by a space, one constant in `install.py`, rather than by its text. Each run removes every tagged entry from `environment`, `allow`, `soft_deny`, and `hard_deny`, then appends the current ones from one table. An entry without the tag is the machine's own, such as a rule a host keeps for its local hardware. It keeps its exact text and its order relative to the other entries, and the kit never removes or rewrites it. The owned rules state what `scripts/pr_review.py merge` and `cleanup` check in code, and allow running either where a skill the session follows prescribes it. Each `environment` rule says that the session's CLAUDE.md rules and the skill running it decide whether its write is authorized, never the command. The kit owns nothing in `soft_deny` or `hard_deny`, and it never touches `classifyAllShell`. The literal `"$defaults"` splices Claude Code's built-in rules into a list, and a list without it replaces them. So after an install every `autoMode` list in the file starts with `"$defaults"` exactly once, whether or not the kit writes rules into it. The install adds it first where absent, which restores the built-in rules. It moves it first where it sits elsewhere and keeps one where it repeats, which the kit requires but Claude Code does not. It names each list it changed. Every other entry keeps its exact text and relative order. A list that does not exist stays absent, and the kit creates only the ones it owns rules in. Claude Code's offer to learn rules can create a list without `"$defaults"`, which silently drops the built-in rules. A malformed shape is refused the way a malformed `hooks` or `permissions` key is, with the file left unchanged. That covers `autoMode` as something other than an object and a list as something other than a list. An entry that is not a string carries no tag, so it is kept untouched as the machine's own. The owned rules are in the stamp's digest, so `--report` says stale when the machine's tagged entries differ from what the checkout writes. `--report` also counts the untagged entries in each list. A list that does not start with `"$defaults"` exactly once is named and makes the machine STALE. That check reads `settings.json` live. It is not in the digest, which covers only what the kit writes. - **The AGENTS.md plugin's `instructionFiles` setting, written into `settings.json`** in the same pass, with the value `claude-md-and-agents-md`. Claude Code reads `AGENTS.md` only where no `CLAUDE.md`, `.claude/CLAUDE.md`, or `CLAUDE.local.md` sits in the working directory or above it. A repository's rules can reach Claude Code through `AGENTS.md` alone. Without this setting, a stray `CLAUDE.local.md` there would silently stop them loading. The setting makes it read both, each directory's `CLAUDE.md` files first, and it never reads one `AGENTS.md` twice. Claude Code reads the setting from user, `--settings`, or managed settings, and ignores it in a repository's settings files. So the host is where it has to be set. It sits under `pluginConfigs..options`, and the kit writes it under both plugin IDs, `agents-md@builtin` and `cc-plugin-agents-md@builtin`. Claude Code before 2.1.285 reads only the first and ignores the second, and 2.1.285 or later reads either. Writing one value under both leaves no version from the fleet floor of 2.1.281 up meeting a conflict, whichever ID it prefers. The kit owns that one key under each ID, so a re-run restores it and names the value it replaced. Every other key under `pluginConfigs` is kept. A `pluginConfigs`, plugin entry, or `options` that is not an object is refused, with the file left unchanged, as a malformed `hooks` key is. `--report` reads the setting live and says STALE where either ID holds another value or none. It names a malformed shape as one a re-run refuses. -- **`attribution.sessionUrl` set to `false` in `settings.json`**, in the same pass. Without it, a web or Remote Control session adds a link to itself to the commits and pull requests it writes. Fleet text never carries a session link. The kit writes that one key and no other under `attribution`, so `commit` and `pr` keep Claude Code's defaults. A value the host already holds there is the host's own, whether under `sessionUrl` or as an `attribution` that is not an object. Claude Code reads `attribution: false` as every attribution hidden, the session link included. A re-run leaves the host's value as it stands and says so. `--report` says STALE only where the key is absent, and prints a note where the host's own value leaves the link on. +- **`attribution.sessionUrl` set to `false` in `settings.json`**, in the same pass. Without it, a web or Remote Control session adds a link to itself to the commits and pull requests it writes. Fleet text never carries a session link. The kit writes that one key and no other under `attribution`, so `commit` and `pr` keep Claude Code's defaults. A value the host already holds there is the host's own, whether under `sessionUrl` or as an `attribution` that is not an object. Claude Code reads `attribution: false` as every attribution hidden, the session link included. A re-run leaves the host's value as it stands and says so. `--report` says STALE only where the key is absent. Where the host's own value is anything but false, it prints a WARNING line before a CURRENT or STALE verdict and the verdict is unchanged. A host with no usable stamp gets none. Fixing that value is the host's to do. See [`../README.md`][spec] "Requirements" for which of these each rule implements. See [`../README.md`][spec] "Auditing an Implementation Against This Spec" for how to check this hook still satisfies them after a change. diff --git a/host-setup/agent-safety/claude/install.py b/host-setup/agent-safety/claude/install.py index c2d1721c8..5f49302a6 100755 --- a/host-setup/agent-safety/claude/install.py +++ b/host-setup/agent-safety/claude/install.py @@ -1614,7 +1614,8 @@ def judge_sweep(group, hook): f"pluginConfigs.{plugin}.options.instructionFiles {why} rather than " f"{INSTRUCTION_FILES}, so a CLAUDE.local.md stops AGENTS.md loading" ) - # Only an absence is drift, since a value the host set is one a re-run leaves alone, which the report notes instead. + # Only an absence is drift, since a re-run clears it. + # A host-set value is one a re-run leaves alone, so --report warns of it. if session_url_state(data)[0] == "absent": out.append( "attribution.sessionUrl is absent rather than false, so a web or Remote Control " @@ -1778,8 +1779,13 @@ def report(claude_home): state, words = session_url_state(settings_data) if state == "foreign": print( - f"Note: {words}, which this kit does not own, so this kit does not turn the " - "session link off." + f"WARNING: {words}. The host set it, so a re-run leaves it alone. " + "It may leave a session link on the commits and pull requests a web or Remote Control " + "session writes, which fleet rules never allow. Claude Code's reading of a value " + "that is neither a boolean nor an object is not established here. To fix it, set attribution.sessionUrl " + "to false, first replacing attribution with an object where it is not one. Setting " + "attribution itself to false also works, but it hides every attribution, the " + "commit and pull request ones included." ) # Read from the file rather than compared against the stamp. # An install onto a corrupted file writes the corruption into the stamp, and the two then agree. @@ -2250,7 +2256,9 @@ def reject(where, held, want): elif state == "off": done.append(f"{words}: already current") else: - done.append(f"{words}, which this host set, so this kit leaves it and adds no opt-out") + done.append( + f"{words}, which this host set, so this kit leaves it and adds no opt-out, and --report warns of it" + ) # 4. The autoMode rules, stripped by their tag and appended again. # A list the kit creates splices in the built-ins, and a list that exists is made to lead with the splice. diff --git a/host-setup/agent-safety/claude/test_install.py b/host-setup/agent-safety/claude/test_install.py index 326efa601..f6ed5e848 100755 --- a/host-setup/agent-safety/claude/test_install.py +++ b/host-setup/agent-safety/claude/test_install.py @@ -1590,7 +1590,42 @@ def test_a_session_link_setting_the_host_made_is_left_as_it_stands(self): self.assertIn(f"attribution.sessionUrl is {held!r}, which this host set", r.stdout) report = run(self.home, "--report") self.assertEqual(report.returncode, 0, report.stdout + report.stderr) - self.assertIn(f"Note: attribution.sessionUrl is {held!r}", report.stdout) + self.assertIn(f"WARNING: attribution.sessionUrl is {held!r}.", report.stdout) + self.assertNotIn("STALE", report.stdout) + + def test_the_report_warns_of_a_session_link_the_host_leaves_on_without_a_verdict_change(self): + """A host `true` is left in place and warned of, the verdict stays CURRENT, and `false` draws no warning.""" + for data, warns in ( + ({"attribution": {"sessionUrl": True}}, True), + ({"attribution": True}, True), + ({"attribution": False}, False), + ({"attribution": {"sessionUrl": False}}, False), + ): + with self.subTest(data=data): + self.home.mkdir(parents=True, exist_ok=True) + self._write(data) + self.install() + self.assertEqual(self._settings()["attribution"], data["attribution"]) + report = run(self.home, "--report") + self.assertEqual(report.returncode, 0, report.stdout) + self.assertIn("CURRENT", report.stdout) + self.assertEqual("WARNING:" in report.stdout, warns, report.stdout) + if warns: + self.assertLess(report.stdout.index("WARNING:"), report.stdout.index("CURRENT")) + + def test_the_session_link_warning_precedes_stale_and_never_follows_a_missing_stamp(self): + self.install() + data = self._settings() + data["attribution"] = {"sessionUrl": True} + data["pluginConfigs"]["agents-md@builtin"]["options"]["instructionFiles"] = "other" + self._write(data) + stale = run(self.home, "--report") + self.assertEqual(stale.returncode, 1, stale.stdout + stale.stderr) + self.assertLess(stale.stdout.index("WARNING:"), stale.stdout.index("STALE:")) + self.stamp.unlink() + bare = run(self.home, "--report") + self.assertEqual(bare.returncode, 2, bare.stdout + bare.stderr) + self.assertNotIn("WARNING:", bare.stdout + bare.stderr) def test_a_non_object_attribution_is_left_as_it_stands(self): """The key is the host's own, so the install goes ahead without it rather than refusing the file. @@ -1613,7 +1648,7 @@ def test_a_non_object_attribution_is_left_as_it_stands(self): self.assertIn("which this host set" if foreign else "already current", r.stdout) report = run(self.home, "--report") self.assertEqual(report.returncode, 0, report.stdout + report.stderr) - self.assertEqual(f"Note: {words}" in report.stdout, foreign) + self.assertEqual("WARNING: attribution" in report.stdout, foreign) def test_a_host_installed_before_the_session_link_setting_reports_it_absent(self): for strip in ("attribution", "sessionUrl"):