fix: preserve content after frontmatter in parse_instinct_file()#161
Conversation
parse_instinct_file() was appending the instinct and resetting state when frontmatter ended (second ---), before any content lines could be collected. This caused all content (Action, Evidence, Examples) to be lost during import. Fix: only set in_frontmatter=False when frontmatter ends. The existing logic at the start of next frontmatter (or EOF) correctly appends the instinct with its collected content. Fixes affaan-m#148
📝 WalkthroughWalkthroughThe changes fix a bug in the instinct file parser where content following frontmatter boundaries was lost during import. The parser now defers instinct finalization until the next frontmatter boundary or end-of-file, ensuring all content is preserved. Unit tests validate the fix across multiple scenarios. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
affaan-m
left a comment
There was a problem hiding this comment.
Approved
Excellent fix. Verified the parsing logic end-to-end:
Fix correctness
The state machine flow is now:
---(start frontmatter) → append previous instinct if exists, reset state,in_frontmatter = True- YAML key:value lines → populate
currentdict ---(end frontmatter) →in_frontmatter = False(fix: no longer appends here)- Content lines → collect into
content_lines - Next
---→ back to step 1, which appends with collected content - EOF → append final instinct with collected content
The bug was step 3 duplicating step 1's append logic, but before step 4 could run. Removing it is the correct fix.
Test quality
- 3 focused test cases covering multi-instinct, single instinct, and empty content
- Smart use of
importlibto handle the hyphenated filename - Assertions check for specific content strings, not just non-empty
- Tests are self-contained with inline fixtures
PR quality
- Minimal diff (-5 lines of logic)
- Clear commit message with conventional format
- Links to issue (#148)
- Includes reproduction steps and before/after comparison
Well done @ericcai0814.
…aan-m#161) / parse_instinct_file() で frontmatter 後の content を保持
Summary
parse_instinct_file()appended the instinct and reset state when frontmatter ended (---), before content lines could be collected — causing silent data loss of Action, Evidence, Examples sections during import.in_frontmatter = Falseat frontmatter close; defer append to next frontmatter start or EOF, where the logic already exists.Fixes #148
Reproduction
Test plan
pytest skills/continuous-learning-v2/scripts/test_parse_instinct.py -v— 3 passedSummary by CodeRabbit
Bug Fixes
Tests