refactor: simplify scaffold-rules to write AGENTS.md directly#24
refactor: simplify scaffold-rules to write AGENTS.md directly#24EdwardIrby merged 3 commits intomainfrom
Conversation
- Remove symlink/copy logic and --dirs flag entirely - Write rules inline into AGENTS.md with HTML comment markers - Add @AGENTS.md reference to CLAUDE.md if present - Move .agents/rules/ and .agents/skills/ to project root - Update symlinks (.claude/, .cursor/) to new paths - Update package.json files array, AGENTS.md references - Rewrite tests for new AGENTS.md-based approach (57 passing)
Code Review: PR #24SummaryThis PR simplifies the ✅ Strengths
🔍 Code QualityGood practices observed:
src/scaffold-rules.ts:88-102 - CLAUDE.md integration:
src/scaffold-rules.ts:70 - String concatenation could be cleaner: // Current
const after = content.slice(endIdx + RULES_END.length)
// More explicit
const endMarkerEnd = endIdx + RULES_END.length
const after = content.slice(endMarkerEnd)🔒 SecurityNo security concerns identified:
|
- Rewrite skill-activation.md to match professional tone of other rules - Add tests for mismatched markers (start-only, end-only) - Add troubleshooting section to scaffold-rules SKILL.md
Independent Code Review: PR #24SummaryThis PR simplifies the ✅ StrengthsArchitecture & Design
Code Quality
Testing
🔍 Code Analysissrc/scaffold-rules.tsLines 88-102 - CLAUDE.md detection: if (content.includes('@AGENTS.md')) {
actions.push('skip: CLAUDE.md (already references @AGENTS.md)')
}Concern: Simple substring matching could produce false positives (e.g., matching in code blocks, comments, or URLs like Recommendation: Consider more precise detection: // Check if @AGENTS.md appears at start of line (actual reference)
if (/^@AGENTS\.md/m.test(content)) {
actions.push('skip: CLAUDE.md (already references @AGENTS.md)')
}Lines 63-70 - Marker parsing: const startIdx = content.indexOf(RULES_START)
const endIdx = content.indexOf(RULES_END)
if (startIdx !== -1 && endIdx !== -1) {
const before = content.slice(0, startIdx)
const after = content.slice(endIdx + RULES_END.length)
}Good: Correctly preserves user content before/after markers. Potential issue: If if (startIdx !== -1 && endIdx !== -1 && endIdx > startIdx) {
// ... existing logic
} else if (startIdx !== -1 || endIdx !== -1) {
// Warn about malformed markers
}
|
- Use regex for @AGENTS.md detection (start-of-line only, avoids inline false positives) - Add guard for reversed markers (endIdx > startIdx) - Add tests: reversed markers, inline @AGENTS.md false positive
Code Review: PR #24 - Fresh AnalysisOverviewThis PR refactors ✅ StrengthsArchitecture:
Code Quality:
Testing:
Documentation:
🔍 Code Analysissrc/scaffold-rules.ts:460 - CLAUDE.md Detectionif (/^@AGENTS\.md/m.test(content)) {✅ GOOD: Uses regex with multiline flag to check for src/scaffold-rules.ts:415 - Marker Validationif (startIdx !== -1 && endIdx !== -1 && endIdx > startIdx) {✅ GOOD: Validates that both markers exist AND that end comes after start. This prevents reversed markers from causing malformed output. Well-designed defensive programming. src/scaffold-rules.ts:392 - Rules Section Constructionconst rulesSection = `RULES_START\n\n## Rules\n\nrulesContent\n\nRULES_END`Minor observation: The 🔒 SecurityNo security concerns identified:
|
Summary
Simplifies
scaffold-rulesfrom a copy+symlink approach to writing rules directly intoAGENTS.md. Also movesrules/andskills/from.agents/to the project root for better discoverability.Changes
scaffold-rules rewrite
--dirsflag,SYMLINK_AGENTS/ALL_AGENTSconstantsAGENTS.mdbetween<!-- PLAITED-RULES-START -->/<!-- PLAITED-RULES-END -->markers@AGENTS.mdreference toCLAUDE.mdif it exists without oneDirectory restructure
.agents/rules/→rules/.agents/skills/→skills/.claude/and.cursor/to point to new locationspackage.jsonfilesarray@references inAGENTS.mdTests
Verification
bun run check— passes cleanbun test— 57/57 passingbun bin/cli.ts scaffold-rules --list— works correctly