- Problem: Plugin 更新
auto-loop.md時,若使用者已客製化同一##section(如 Auto-Trigger table),smart merge 會觸發CONFLICT狀態,需手動解決。使用者無法在不觸碰 plugin-managed 檔案的情況下客製化 auto-loop 行為。 - Goals:
- 使用者可在獨立檔案中定義 project-specific auto-loop 行為
- Plugin 更新 base rules 時不會與使用者客製化衝突
/install-rules安裝時自動建立客製化 template,不需手動操作/claude-health提供 4 項 safeguard 檢查
- Scope:
- v1: 僅
auto-loop-project.md(最常客製化的規則) - 命名慣例
*-project.md保留給未來擴展
- v1: 僅
- Non-goals:
- 不修改 smart merge 演算法本身
- 不重新命名現有
auto-loop.md(避免大量 blast radius) - 不通用化到所有 rules(v1 scope)
| File | Purpose | Impact |
|---|---|---|
rules/auto-loop.md |
Plugin source auto-loop rule | Add redirect comment at bottom |
.claude/rules/auto-loop.md |
Local installed copy | Same redirect comment |
commands/install-rules.md |
Rule installation flow | Add project override file creation |
skills/claude-health/SKILL.md |
Health check + sync | Add 4 safeguards |
skills/project-setup/SKILL.md |
Project onboarding | Add override file to setup flow |
CLAUDE.md / .claude/CLAUDE.md |
Rule reference list | Add @rules/auto-loop-project.md |
CLAUDE.template.md |
Template for new projects | Add project override reference |
- Smart merge 8-state classification(reuse
FRESH_INSTALLfor project file creation) - Manifest
.claude/.sd0x-install-state.json(project file explicitly NOT tracked) /claude-healthS2 component classification(extend with override-aware checks)
sequenceDiagram
participant U as User
participant IR as /install-rules
participant CH as /claude-health
participant CM as CLAUDE.md
IR->>IR: Install auto-loop.md (managed, smart merge)
IR->>IR: Create auto-loop-project.md (unmanaged template)
IR->>CM: Add @rules/auto-loop-project.md reference
Note over U: User edits auto-loop-project.md
U->>CH: /claude-health
CH->>CH: Check 4 safeguards
alt Override drift
CH->>U: Warn: base updated since override authored
end
alt Wrong-layer edit
CH->>U: Warn: base auto-loop.md locally modified
end
.claude/rules/
├── auto-loop.md ← plugin-managed (smart merge tracked)
├── auto-loop-project.md ← user-owned (NOT manifest-tracked)
├── codex-invocation.md ← plugin-managed
└── ...
| File | Owner | Manifest Tracked | Smart Merge |
|---|---|---|---|
auto-loop.md |
Plugin | Yes | Yes (8-state) |
auto-loop-project.md |
User | No | No (unmanaged) |
Note: Template source exists in
rules/for/install-rulesto copy from, but the installed copy is explicitly excluded from manifest hash tracking.
# Auto-Loop Project Overrides
<!-- Precedence: When this file conflicts with auto-loop.md, this file takes precedence. -->
<!-- Based on: auto-loop.md @ <sha7> (<date>) -->
## Auto-Trigger
<!-- To override the Auto-Trigger table from auto-loop.md,
restate the FULL section here (section-level replacement).
Delete this section if you don't need to override. -->Override semantics: Section-level full replacement(使用者重寫完整 ## section 來覆蓋 base)。
Note: Override section headings must exactly match base section headings for clear section-level replacement semantics.
| Design Decision | Choice | Rationale |
|---|---|---|
| Override granularity | Section-level (##) |
LLM 更容易理解完整 section;避免 row-level delta 的歧義 |
| Precedence mechanism | Self-contained header text | 不依賴 CLAUDE.md load order(@ 引用無保證順序) |
| Manifest tracking | Not tracked | 避免 plugin 更新觸碰 user 檔案 |
Phase 3.5 extension — after managed rule classification, add:
# Exclusion: *-project.md files are NOT part of the managed install set.
# They are copied as templates only, with no manifest hash entry written.
managed_rules = rules/*.md EXCLUDING *-project.md
# Explicit override template mapping (not suffix-derived from managed_rules)
override_templates = { "auto-loop.md": "auto-loop-project.md" }
For each (base_rule, project_file) in override_templates:
if project_file NOT exists in .claude/rules/:
Copy from rules/{project_file} as template
Do NOT write manifest entry for project_file
Log: "Created project override template: {project_file}"
else:
Skip (user already has it)
Important:
/install-rulesmust explicitly exclude*-project.mdfrom the managed rule enumeration (rules/*.md) to prevent accidental manifest tracking. The template sourcerules/auto-loop-project.mdis only a copy source, never a managed rule.
New flag: --customize <rule-name> — creates fuller template with examples.
4 new checks in S2 component classification:
| # | Check | Severity | Detection | Recommendation |
|---|---|---|---|---|
| 1 | Override drift | P2 | based_on hash in project file vs current base hash |
"Base auto-loop updated; review your overrides" |
| 2 | Policy contradiction | P1 | Override disables required check that hook enforces | "Override conflicts with stop-guard enforcement" |
| 3 | Missing reference | P1 | CLAUDE.md references @rules/auto-loop-project.md but file missing, OR file exists but not referenced in CLAUDE.md |
/install-rules to recreate or add reference |
| 4 | Wrong-layer edit | P2 | Base auto-loop.md has LOCAL_MODIFIED, CONFLICT, or LEGACY doctor state (user modified base) |
"Move customization to auto-loop-project.md" |
Policy contradiction detection contract: Parse the project override's Auto-Trigger table for required check commands. Cross-reference against hook-enforced sentinels (from hooks/stop-guard.sh): if override omits a command that stop-guard requires (e.g., removing /codex-review-fast for code changes), flag as P1 contradiction.
Add at bottom of rules/auto-loop.md:
## Project Customization
Project-specific overrides belong in `auto-loop-project.md` (not this file).
See `@rules/auto-loop-project.md` for your project's custom auto-loop behavior.## Rules
- @rules/auto-loop.md -- Auto review loop (highest priority)
- @rules/auto-loop-project.md -- Project-specific auto-loop overrides (user-owned)Backfill for existing projects: /install-rules must perform idempotent missing-reference repair: if @rules/auto-loop.md reference exists in ## Rules but @rules/auto-loop-project.md is absent, insert only the missing line. This ensures existing projects receive the reference on next /install-rules run without requiring manual CLAUDE.md edits.
| User State | Migration Path |
|---|---|
| No customization (base == manifest) | /install-rules creates empty project file → no behavioral change |
| Has local modifications (LOCAL_MODIFIED) | /claude-health detects wrong-layer → suggests moving to project file |
| Has CONFLICT state | Resolve conflict first, then move customizations to project file |
| Risk | Probability | Impact | Mitigation |
|---|---|---|---|
| LLM ignores precedence instruction | Low | Medium | Section-level replacement (no overlapping content) + explicit header |
| User edits base instead of project file | Medium | Low | /claude-health wrong-layer detection + base redirect comment |
| Override drift (base updated, project stale) | Medium | Medium | based_on hash + health check warning |
| Scope creep to all rules | Low | Medium | v1 scoped to auto-loop; convention reserved |
| Dependency | Status | Risk |
|---|---|---|
@rules/ flat include semantics in Claude Code |
Verified | Low — well-tested |
| Smart merge 8-state classification | Existing | None |
/claude-health S2 classification |
Existing | Low — extend, not rewrite |
| # | Task | Files | Effort | Depends On |
|---|---|---|---|---|
| 1 | Create template source rules/auto-loop-project.md (installed as unmanaged — no manifest entry) |
rules/auto-loop-project.md (new) |
S | — |
| 2 | Add redirect section to auto-loop.md |
rules/auto-loop.md |
S | — |
| 3 | Update /install-rules to create project file |
commands/install-rules.md |
M | 1 |
| 4 | Update /claude-health with 4 safeguards |
skills/claude-health/SKILL.md |
M | 1 |
| 5 | Update CLAUDE.md + template references | CLAUDE.md, CLAUDE.template.md, .claude/CLAUDE.md |
S | 1 |
| 6 | Update /project-setup flow |
skills/project-setup/SKILL.md |
S | 1, 3 |
| 7 | Tests for override detection | test/ |
M | 3, 4 |
| Type | Scope | File |
|---|---|---|
| Unit | Override file detection (exists/missing/drift) | test/scripts/install-rules-override.test.js |
| Unit | Wrong-layer detection (base modified + project exists) | test/scripts/claude-health-override.test.js |
| Unit | Policy contradiction detection (override removes required review step) | test/scripts/claude-health-override.test.js |
| Unit | Manifest exclusion (no auto-loop-project.md entry in .claude/.sd0x-install-state.json) |
test/commands/install-rules-override.test.js |
| Integration | /install-rules creates project file on fresh install |
Manual |
| Integration | Plugin update doesn't touch project file | Manual |
| # | Question | Decision Owner |
|---|---|---|
| 1 | Should --customize flag be on /install-rules or a separate command? |
Plugin maintainer |
| 2 | Should the project file template include all sections as commented-out stubs? | UX decision |
| 3 | v2: Extend to codex-invocation-project.md, testing-project.md? |
Based on user demand |