Skip to content

feat: preserve user edits in CLAUDE.md/AGENTS.md via auto/user blocks#43

Merged
benwu95 merged 4 commits into
mainfrom
preserve-agent-config-edits
Jun 22, 2026
Merged

feat: preserve user edits in CLAUDE.md/AGENTS.md via auto/user blocks#43
benwu95 merged 4 commits into
mainfrom
preserve-agent-config-edits

Conversation

@benwu95

@benwu95 benwu95 commented Jun 22, 2026

Copy link
Copy Markdown
Owner

Summary

prospec agent sync previously overwrote CLAUDE.md / AGENTS.md unconditionally, and prospec init skipped an existing AGENTS.md entirely — destroying or ignoring any hand-written content. This change applies the same prospec:auto / prospec:user block contract that _index.md already uses, so user edits survive init / agent sync / quickstart / upgrade.

What changed

  • lib/content-merger: new mergeManagedDoc(generated, existing) — in-place auto-block swap preserving the user block; migrates a marker-less existing file into the user block instead of discarding it; idempotent. Plus shared hasAutoBlock / replaceAutoBlock (single-source auto-block matcher, function-replacer so $-sequences stay literal).
  • lib/fs-utils: new readFileIfExists (ENOENT → '', other read errors propagate).
  • services: agent-sync.generateEntryConfig and init's write loop route through the merge; init merges the managed AGENTS.md while curated trust-zone docs keep skip-if-exists.
  • templates: entry.md.hbs and init/agents.md.hbs wrapped in the blocks.

Behavior

  • A marker-less hand-written CLAUDE.md / AGENTS.md → content migrated into the user block on first sync.
  • Subsequent syncs refresh only the auto block; the user block is preserved byte-for-byte.
  • Two syncs in a row are byte-identical (idempotent).
  • Trust-zone files (CONSTITUTION.md / _conventions.md / _index.md) unchanged — still skip-if-exists.

SDD trail

Full Prospec lifecycle (story → plan → tasks → implement → review → verify → archive → learn):

commit step
6d20b16 feat — the block-merge feature
099eb18 refactor — DRY follow-up (shared auto-block helper + readFileIfExists adoption across knowledge services)
eba90fa docs(archive) — REQ graduation (agent-integration / project-setup) + knowledge sync + test-count reconciliation
d1a2c7d docs(learn) — promote PB-006 (single-source helper for parallel modules)

Verification

  • 1786 tests passing; coverage 96%; typecheck + lint clean.
  • prospec check: 8/8 structural checks pass (0 fail / 0 warn).
  • Verify grade: S.
  • Real-CLI e2e confirmed: brownfield CLAUDE.md / AGENTS.md migrated into the user block and preserved across init → agent sync; idempotent on re-sync.

🤖 Generated with Claude Code

benwu95 added 4 commits June 22, 2026 10:35
- add lib/content-merger mergeManagedDoc: in-place auto-block swap, migrate
  unmarked existing content into the user block, idempotent (function replacers)
- add lib/fs-utils readFileIfExists (ENOENT -> '', other errors propagate)
- agent-sync generateEntryConfig reads existing -> mergeManagedDoc -> atomicWrite
  instead of unconditional overwrite (REQ-AGNT-008 / REQ-AGNT-023)
- init merges the managed AGENTS.md while trust-zone docs keep skip-if-exists
  (REQ-SETUP-018)
- wrap entry.md.hbs and init/agents.md.hbs in prospec:auto / prospec:user blocks
  (REQ-TEMPLATES-104)
- tests: mergeManagedDoc, readFileIfExists, agent-sync/init merge, init->sync
  integration (+22)
- docs: note block preservation in README.md / README.zh-TW.md
…dge services

- export hasAutoBlock/replaceAutoBlock from lib/content-merger as the single
  source for the prospec:auto block matcher; mergeManagedDoc reuses them
- knowledge-update.service: drop the duplicated literal auto-block regex for the
  shared helpers
- knowledge.service + knowledge-update.service: replace 4 inline read-or-empty
  try/catch sites with fs-utils readFileIfExists, so non-ENOENT read errors
  propagate instead of being masked as an absent file (created/updated unchanged)
- tests: unit-cover hasAutoBlock/replaceAutoBlock
…ledge

- graduate REQs: agent-integration (US-435 + REQ-AGNT-027/LIB-021/TEMPLATES-123
  added, REQ-AGNT-008 modified), project-setup (REQ-SETUP-018 modified);
  renumbered from colliding LIB-014/AGNT-023/TEMPLATES-104
- add lib to agent-integration feature-map modules (REQ-LIB-021 ownership)
- sync lib/services/templates module READMEs to the merge behavior
- reconcile drifted test counts to 1786 across README x2 + _index + tests README
- harvest lessons ledger (refactor/duplicated-helper -> suggest-promote)
- refresh raw-scan; add _archived-history record
- promote refactor/duplicated-helper-parallel-sites to _playbook PB-006
  (freq=3, modules=2 lib+services; kind convention; approved benwu95)
- flip ledger entry suggest-promote -> promoted with provenance
@github-actions

Copy link
Copy Markdown

Prospec Check

Prospec drift check (structural — deterministic, zero LLM)

  PASS  req-references
  PASS  file-paths
  PASS  import-direction
  PASS  knowledge-health
  SKIP  task-completion — source unavailable: .prospec/changes/ not found (not version-controlled)
  PASS  dangling-prefix
  PASS  feature-modules
  PASS  readme-counts

Knowledge coverage: 6/6 modules documented

Checked 7/8 checks: 0 fail, 0 warn, 1 skipped (not counted as pass)
Semantic consistency: not-checked (run /prospec-review)
Report written: prospec-report.json

@github-actions

Copy link
Copy Markdown

Test Coverage

Metric Coverage Covered / Total
lines 96.44% 2904 / 3011
statements 95.99% 3190 / 3323
functions 95.87% 535 / 558
branches 94.24% 1753 / 1860

@benwu95 benwu95 merged commit 7b116eb into main Jun 22, 2026
4 checks passed
@benwu95 benwu95 deleted the preserve-agent-config-edits branch June 22, 2026 04:24
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.

1 participant