Improve frontmatter persistence across str-replace/write#25
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (7)
📝 WalkthroughWalkthroughThis PR implements transparent frontmatter preservation for block and skill files. A new utility module detects which paths require frontmatter and parses delimited sections. The str-replace and write tools now use these utilities to isolate text operations to file bodies while preserving existing frontmatter during overwrites. ChangesFrontmatter preservation for block and skill files
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
ee1f9d1 to
f571f28
Compare
f571f28 to
c315934
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/runtime/src/engine/tools/str-replace.ts`:
- Around line 62-75: The code suppresses the prefer-destructuring lint rule when
assigning frontmatter and body from splitFrontmatter; replace the manual
assignment with a destructuring assignment to avoid the linter suppression: when
split = splitFrontmatter(...) returns a value, use ({ frontmatter, body:
searchContent } = split) instead of assigning split.frontmatter and split.body
separately; update the block around requiresFrontmatter, splitFrontmatter,
frontmatter and searchContent to use this destructuring and remove the
oxlint-disable-next-line comment.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 519d6989-8b03-4ab6-a4d4-f3f40ad46451
📒 Files selected for processing (6)
packages/runtime/src/engine/tools/str-replace.test.tspackages/runtime/src/engine/tools/str-replace.tspackages/runtime/src/engine/tools/write.test.tspackages/runtime/src/engine/tools/write.tspackages/runtime/src/util/frontmatter.test.tspackages/runtime/src/util/frontmatter.ts
When str-replace or write preserves frontmatter (blocks: TOML, skills: YAML), validate it against the Valibot schema before persisting. Catches corruption early with an actionable error rather than a mysterious load failure later. - Move BlockFrontmatterSchema and SkillFrontmatterSchema from load.ts to frontmatter.ts so validation and parsing share one source of truth. - Add validateFrontmatter(content, isBlock) to frontmatter.ts — parses with smol-toml / yaml and runs vb.parse against the matching schema. - Wire into str-replace.ts (preserved frontmatter) and write.ts (preserved + agent-provided frontmatter for new files). - Also: replace prefer-destructuring lint suppression with proper destructuring in str-replace.ts. Tests: 13 new (11 validateFrontmatter unit tests, 4 tool integration tests).
f078377 to
9fe6d0d
Compare
There's been some issues with the frontmatter getting decimated by agents.
Well, no more. This PR should un-fuck most cases where it can happen. There are still obviously cases where it can, but we can only cover so much surface-area when it's infinite.
Security-Critical Analysis — Updated
The prior validation gap has been addressed: frontmatter is now parsed and semantically validated before being preserved or accepted.
What changed (security-relevant):
Impact:
Other security notes:
Recommendation: