You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Promote develop to main: Whole-File Global CLAUDE.md Ownership - #2425
Promotes develop to main with four pull requests, each already reviewed and merged into develop:
#2424 Render the Whole Global CLAUDE.md and Back Up a Hand Edit.
The host-safety installer now owns all of ~/.claude/CLAUDE.md. It renders a header, the two existing blocks, and a shared host-local file, agent-fleet/local.md.
It replaces an earlier render silently. A file edited by hand, or one written before this change, is copied to a timestamped .bak first.
merge-and-release step 7 now also runs this kit's --report, so a release flags a stale host.
#2427 Render CLAUDE.md First and Let the Real Write Be the Check, the fix for this PR's Copilot finding.
#2428 Read the Local Instruction File Only When It Is a Regular File, the fix for this PR's previously-missed Copilot finding.
#2429 Refuse a Local Instruction Path Whose Parent Is a File, the fix for this PR's third-round Copilot finding.
On a host's next install, the existing CLAUDE.md is backed up and replaced. Anything host-specific moves into the local file.
## Summary
The host-safety installer only managed two marker blocks in
`~/.claude/CLAUDE.md`. Content outside them was never written and never
checked. One host ran for three weeks on hand-written sections that
restated fleet rules in older wording. On the same day, one of those
sections described `pr_review.py reply` behavior that #2419 had just
changed.
The installer now owns the whole file.
- **What it renders:** a header, the two existing blocks, then one
shared host-local file, `~/.config/agent-fleet/local.md` (under
`XDG_CONFIG_HOME` when that is absolute). The local file is appended
under a `host-local` marker, and the installer never edits it.
- **Telling an old version from a hand edit:** the stamp gains
`instructionsDigest`, the digest of what the install rendered.
- A file whose digest matches the stamp is an earlier render, and it is
replaced silently.
- Any other file is copied to `CLAUDE.md.<UTC>.bak` first. That covers a
hand edit, a file from before this change, and a stamp with no digest.
The backup is created exclusively and keeps the raw bytes, so a file
that isn't valid UTF-8 is backed up too.
- **Local file checked first:** if it can't be read, isn't UTF-8, or
contains this kit's own markers, the run stops before anything changes.
The last case is what happens when someone copies an old backup into the
local file.
- **`--report`:** it compares the whole file and says whether it is an
earlier render or a hand edit. When the local file is the problem, it
says to fix that file first.
- **`merge-and-release` step 7:** it now also runs this kit's
`--report`, so a release flags a stale host. It reports rather than
re-runs the install, because the installer rewrites hooks and settings.
- **Docs:** the kit README, the root README, `docs/host-setup.md` and
`docs/fleet-map.md` describe the whole-file ownership.
**Codex and opencode:** rendering doesn't depend on which file it
targets, so their global files (`~/.codex/AGENTS.md`,
`~/.config/opencode/AGENTS.md`) can be added later from the same parts
and the same local file. That isn't part of this PR. The loader behavior
verified against the installed binaries is recorded on #2423. Two points
matter: Codex's `AGENTS.override.md` replaces the global file rather
than adding to it, and opencode falls back to `~/.claude/CLAUDE.md`.
Refs #2423
## Verification
- `python3 -m unittest test_install` (in
`host-setup/agent-safety/claude`): 106 tests OK.
- The 9 original whole-file cases all fail against the old installer.
- The rendered-digest case fails when `main()` stops passing the digest.
- That case passes with `TMPDIR` behind a symlink.
- Every test points the local file at its throwaway home, so none reads
the developer's own.
- The local strict review ran four rounds and found 12, 4, 1 and then 0
issues.
- Not taken: three STALE lines for one cause. They repeat the cause but
don't contradict each other.
- The third round's single finding came after the two-round edit budget
was spent. It was taken with the maintainer's go-ahead.
- This adds code comments, hence the `comments` label.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Opus 5.5 <[email protected]>
✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 58.47%. Comparing base (fffd6c7) to head (70dc872). ⚠️ Report is 312 commits behind head on main.
This PR updates the Claude agent-safety installer to take whole-file ownership of ~/.claude/CLAUDE.md by rendering it entirely from kit blocks plus a host-local instructions file, backing up any pre-existing/hand-edited file, and recording a digest in the install stamp to improve drift detection.
Changes:
Render CLAUDE.md as a complete file (header + kit blocks + optional host-local block) and back up prior content when it can’t be proven to be the last installer render.
Add support for a host-local instructions file (defaulting under XDG config, with an override env var) and refuse installs when the local file is unreadable/invalid.
Expand installer --report and tests/docs to account for whole-file ownership, backups, and the new local instructions behavior.
File
Description
host-setup/agent-safety/claude/test_install.py
Adds extensive test coverage for whole-file rendering, backups, local instructions path/validation, and digest stamping.
host-setup/agent-safety/claude/install.py
Implements whole-file rendering of CLAUDE.md, local instructions discovery/validation, backup writing, and stamps a rendered digest; enhances --report.
## Summary
This fixes Copilot's finding on promotion PR #2425. If
`~/.claude/CLAUDE.md` wasn't something the installer could read and
write, the install crashed partway: after the hooks and `settings.json`
had already been replaced, and with no stamp written. `--report` crashed
too.
- **The `CLAUDE.md` step runs first.** It now comes before any hook or
settings change, so a file that can't be read, backed up or written
stops the run with "Nothing was installed".
- **The real write is the check.** An earlier attempt tried to predict
writability with an access probe. Each round missed a case the write
then raised on, and the probe refused a read-only file that was already
current.
- **Nothing is written when nothing would change.** A read-only
`CLAUDE.md` that's already current still installs and reports CURRENT.
- **Anything at the path that isn't a regular file is refused before the
write.** That covers a directory, a FIFO (which hung) and a link to a
device (which swallowed the render).
- A dangling link still writes through to its target, so a dotfiles link
whose target doesn't exist yet keeps working.
- A link to a regular file installs through the link, which is the
dotfiles case.
- **No reader crashes any more.** Every reader of `CLAUDE.md` goes
through one helper that returns `None` instead of raising.
- `--report` names a `CLAUDE.md` that exists but can't be read, instead
of calling it missing.
- Hook staging and self-test failures now say no hook was replaced,
since `CLAUDE.md` has been rendered by then.
Two low-severity gaps are deferred to #2426: the wording after a partial
write on a full disk, and `.bak` files piling up from refused re-runs.
Refs #2423
## Verification
- `python3 -m unittest test_install`: 120 tests OK on Python 3.13. The
edge cases also pass on 3.11 and 3.14.
- Each refusal case asserts that no hook, `settings.json` or stamp is
left behind. The cases are: a directory, a FIFO, a link to a device, a
dangling link into a missing directory, a link loop, an unreadable file,
and a read-only edited file (its backup is kept).
- The local strict review ran 4 rounds and found 5, 5, 4 and then 0
issues.
- After round 2 the maintainer approved the restructure, replacing the
probe with the real write.
- After round 3 the maintainer set the stop point: fix the two issues
the restructure introduced, file the other two, and run one final
verification pass.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Opus 5.5 <[email protected]>
Reject non-regular local instruction paths before reading
host-setup/agent-safety/claude/install.py:446
Avoid blocking on non-regular local paths. read_local_instructions only calls lstat, then reads the path directly, so a FIFO or character device at AGENT_FLEET_LOCAL_INSTRUCTIONS makes both the installer and --report block indefinitely instead of returning the documented refusal before changes. Check that the target resolves to a regular file before reading it.
## Summary
This fixes the finding Copilot flagged on promotion PR #2425 as
"previously missed". `read_local_instructions` checked the local
instruction file with `lstat` and then read it directly. A FIFO or a
character device at that path blocked the read forever, which hung both
the install and `--report`.
- **A new `read_regular_file()` opens the path once and judges the open
descriptor.** It opens with `O_RDONLY|O_NONBLOCK` and checks the
descriptor with `fstat` and `S_ISREG`, so a FIFO or a device returns
`None` without blocking. The check and the read are one operation, so
nothing can swap the path between them.
- **The descriptor is closed in a `finally` on every path.** An
intermediate version leaked one per directory read, because `fdopen`
raised without closing what it was handed.
- **Refusal messages:**
| Local path | Message |
| --- | --- |
| Not a regular file (a FIFO, a device, a directory) | "is not a regular
file" |
| A dangling link | "is a link that leads to nothing" |
| A file deleted between the probe and the open | "no longer exists" |
| Any other open failure | "cannot be read" |
The same message appears on Python 3.11, 3.13 and 3.14. An `is_file()`
check would have differed on 3.14, which swallows every `OSError`.
- **The FIFO cases run with a bound,** so a regression fails the test
rather than hanging the suite. The report case installs first and then
asserts the refusal.
The same FIFO gap exists, from before this change, at `settings.json`
and the stamp. It's recorded on #2426, with `read_regular_file()` as the
shape to reuse.
Refs #2423
## Verification
- `python3 -m unittest test_install`: 123 tests OK on 3.13 and on 3.14.
The edge cases also pass on 3.11.
- The local strict review ran 3 rounds: 6 findings, then 2, then none.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Opus 5.5 <[email protected]>
Avoid blocking on non-regular local paths. read_local_instructions only calls lstat, then reads the path directly, so a FIFO or character device at AGENT_FLEET_LOCAL_INSTRUCTIONS makes both the installer and --report block indefinitely instead of returning the documented refusal before changes.
Fixed in c23a2a7 (#2428): the local file is now read through read_regular_file(), which opens once with O_NONBLOCK, judges the open descriptor with fstat/S_ISREG, and closes it in a finally. A FIFO, device, or directory is refused as "is not a regular file" with nothing changed, identically on Python 3.11, 3.13, and 3.14. The FIFO cases for both the install and --report run bounded so a regression fails rather than hangs. The same pre-existing gap at settings.json and the stamp is recorded on #2426.
Treat only FileNotFoundError as an absent local file here. When a parent component is a regular file (for example, an absolute XDG_CONFIG_HOME points at a file), lstat raises NotADirectoryError, and this branch silently proceeds without the configured host-local instructions. The installer and --report then render/report as if the local file were absent instead of refusing an unreadable path as documented.
## Summary
This fixes the third-round Copilot finding on promotion PR #2425.
`read_local_instructions` treated `NotADirectoryError` from `lstat` as
"no local file". That error comes up when a parent component of the
local instruction path is a regular file, for example an absolute
`XDG_CONFIG_HOME` pointing at a file. The configured local text was then
dropped silently. Now only a missing path counts as absent. Anything
else is refused as "cannot be read", and nothing is installed.
**Deliberate behavior:**
- The refusal also covers the default path when `~/.config` itself is a
regular file, even though nothing was configured. That is a broken home
directory, so a loud refusal that names the path is preferred over
silently skipping.
- On Windows, `lstat` raises `FileNotFoundError` for a file parent, so
the path still reads as absent there, and the new case skips on
non-POSIX like its neighbors. I haven't confirmed this on Windows.
Refs #2423
## Verification
- `python3 -m unittest test_install`: 124 tests OK on 3.13, and the edge
cases also pass on 3.14.
- With the old tuple restored, the new case fails.
- The local strict review ran one pass, as the maintainer allowed, plus
a verification of the test-only skip that came out of it.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Opus 5.5 <[email protected]>
Treat only FileNotFoundError as an absent local file here. When a parent component is a regular file (for example, an absolute XDG_CONFIG_HOME points at a file), lstat raises NotADirectoryError, and this branch silently proceeds without the configured host-local instructions.
Fixed in 70dc872 (#2429): only a missing path is absent now, and a parent that is a file is refused as "cannot be read" with nothing installed. On Windows a file parent raises FileNotFoundError instead, so that platform still reads it as absent. The limit and a fix that works on both are recorded on #2426.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Promotes
developtomainwith four pull requests, each already reviewed and merged intodevelop:~/.claude/CLAUDE.md. It renders a header, the two existing blocks, and a shared host-local file,agent-fleet/local.md..bakfirst.merge-and-releasestep 7 now also runs this kit's--report, so a release flags a stale host.On a host's next install, the existing
CLAUDE.mdis backed up and replaced. Anything host-specific moves into the local file.Closes #2423
🤖 Generated with Claude Code