Skip to content

Promote develop to main: Whole-File Global CLAUDE.md Ownership - #2425

Merged
ptr727 merged 4 commits into
mainfrom
develop
Oct 6, 2026
Merged

ptr727 merged 4 commits into
mainfrom
develop

Conversation

@ptr727

@ptr727 ptr727 commented Oct 5, 2026 •

Copy link
Copy Markdown
Owner

Summary

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.

Closes #2423

🤖 Generated with Claude Code

## 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]>
Copilot AI lite review requested due to automatic review settings October 5, 2026 23:33
@coderabbitai

coderabbitai Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration
  • Configuration used: Repository: ptr727/ProjectTemplate/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f224671d-83ab-4b13-a50b-4dc0b63e8c90
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ 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.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2425   +/-   ##
=======================================
  Coverage   58.47%   58.47%           
=======================================
  Files          16       16           
  Lines        8062     8062           
=======================================
  Hits         4714     4714           
  Misses       3348     3348           
Flag Coverage Δ
python-3.13 58.47% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Note

Copilot was unable to run its full agentic suite in this review.

Copilot review overview

Review effort: Lite
Findings: 1 Medium severity

Open (1)
What changed in this PR

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.
host-setup/​agent-safety/​claude/​README.md Documents whole-file ownership, host-local file location, backup semantics, and failure modes.
docs/​host-setup.md Updates wording to reflect rendered CLAUDE.md behavior.
docs/​fleet-map.md Updates diagram label from “blocks” to rendered CLAUDE.md.
README.md Updates top-level install notes to describe rendered CLAUDE.md, backups, and local instructions location.
.github/​skills/​merge-and-release/​SKILL.md Extends skill instructions to also run install.py --report and report STALE.
.claude-plugin/​fleet-skills/​skills/​merge-and-release/​SKILL.md Mirrors the skill doc update for the plugin copy.
.claude-plugin/​fleet-skills/​.source-digests/​merge-and-release Updates source digest to match the skill doc content change.
.agents/​skills/​merge-and-release/​SKILL.md Mirrors the skill doc update for the agents copy.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

## 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]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🔵 Needs a closer look

Resolve the two outstanding local-path handling findings in install.py.

Review effort: Lite
Findings: None

Resolved since last review (1)
Previously missed (1)

In code that hasn't changed since last review

Medium severity 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]>
@ptr727

ptr727 commented Oct 6, 2026

Copy link
Copy Markdown
Owner Author

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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

Unresolved backup-integrity and invalid-path handling issues remain in the installer.

Review effort: Lite
Findings: 2 High severity

Open (2)
Previously missed (1)

In code that hasn't changed since last review

Medium severity Refuse unreadable local instruction paths

host-setup/​agent-safety/​claude/​install.py:462

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]>
@ptr727

ptr727 commented Oct 6, 2026

Copy link
Copy Markdown
Owner Author

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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

Unresolved critical and moderate findings remain in install.py.

Review effort: Lite
Findings: 1 High severity

Open (1)
Resolved since last review (2)

@ptr727
ptr727 merged commit fbc6ae3 into main Oct 6, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Own Each Agent's Whole Global Instruction File From One Source, and Report a Local Edit

2 participants