Skip to content

fix: preserve content after frontmatter in parse_instinct_file()#161

Merged
affaan-m merged 1 commit intoaffaan-m:mainfrom
ericcai0814:fix/instinct-import-content-loss
Feb 6, 2026
Merged

fix: preserve content after frontmatter in parse_instinct_file()#161
affaan-m merged 1 commit intoaffaan-m:mainfrom
ericcai0814:fix/instinct-import-content-loss

Conversation

@ericcai0814
Copy link
Contributor

@ericcai0814 ericcai0814 commented Feb 6, 2026

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.
  • Fix: only set in_frontmatter = False at frontmatter close; defer append to next frontmatter start or EOF, where the logic already exists.
  • Added pytest test covering multi-section instincts, single instinct, and empty content edge case.

Fixes #148

Reproduction

from parse_instinct_file import ...

content = """
---
id: test-1
trigger: "when coding"
confidence: 0.9
---

## Action
Always write tests first.

## Evidence
TDD improves quality.
"""

# Before fix: [{'id': 'test-1', 'content': ''}]
# After fix:  [{'id': 'test-1', 'content': '## Action\nAlways write tests first.\n\n## Evidence\nTDD improves quality.'}]

Test plan

  • pytest skills/continuous-learning-v2/scripts/test_parse_instinct.py -v — 3 passed
  • Manual verification with multi-instinct file — all content preserved
  • Empty content edge case — no error

Summary by CodeRabbit

  • Bug Fixes

    • Improved frontmatter parsing to correctly handle instinct boundary processing and content finalization
  • Tests

    • Added comprehensive unit tests for instinct parsing covering multiple instincts, single instinct, and empty content scenarios to ensure parsing reliability

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
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 6, 2026

📝 Walkthrough

Walkthrough

The 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

Cohort / File(s) Summary
Bug Fix
skills/continuous-learning-v2/scripts/instinct-cli.py
Modified parse_instinct_file() to defer appending instincts until the next frontmatter boundary or EOF, rather than immediately when closing frontmatter is detected. This preserves content that follows the --- delimiter.
Tests
skills/continuous-learning-v2/scripts/test_parse_instinct.py
Added comprehensive unit tests validating parse_instinct_file() correctly preserves content across multiple instincts, single instincts, and empty content scenarios.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 A parser's quest, oh what a tale,
Where frontmatter ends and content would pale,
But now with deference, 'til boundaries end,
Each instinct's wisdom flows without bend,
Tests verify this fix rings true and clear! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main fix: deferring content preservation in parse_instinct_file() to prevent loss of sections after frontmatter closure.
Linked Issues check ✅ Passed The PR implementation directly addresses issue #148 by deferring in_frontmatter state change to preserve post-frontmatter content during instinct file imports.
Out of Scope Changes check ✅ Passed All changes are scoped to fixing the parse_instinct_file() function and adding corresponding unit tests; no unrelated modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Owner

@affaan-m affaan-m left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved

Excellent fix. Verified the parsing logic end-to-end:

Fix correctness

The state machine flow is now:

  1. --- (start frontmatter) → append previous instinct if exists, reset state, in_frontmatter = True
  2. YAML key:value lines → populate current dict
  3. --- (end frontmatter) → in_frontmatter = False (fix: no longer appends here)
  4. Content lines → collect into content_lines
  5. Next --- → back to step 1, which appends with collected content
  6. 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 importlib to 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.

@affaan-m affaan-m merged commit e4e94a7 into affaan-m:main Feb 6, 2026
2 checks passed
524y added a commit to 524y/everything-claude-code-japanese that referenced this pull request Feb 7, 2026
…aan-m#161) / parse_instinct_file() で frontmatter 後の content を保持
Copy link
Contributor

@maurez83630-cmyk maurez83630-cmyk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Bug: instinct-cli.py import loses content after frontmatter

3 participants

Comments