Skip to content

Commit 3964060

Browse files
ericcai0814bus1029
authored andcommitted
fix: preserve content after frontmatter in parse_instinct_file() (affaan-m#161)
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
1 parent a41102c commit 3964060

2 files changed

Lines changed: 83 additions & 6 deletions

File tree

skills/continuous-learning-v2/scripts/instinct-cli.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,8 @@ def parse_instinct_file(content: str) -> list[dict]:
5050
for line in content.split('\n'):
5151
if line.strip() == '---':
5252
if in_frontmatter:
53-
# End of frontmatter
53+
# End of frontmatter - content comes next, don't append yet
5454
in_frontmatter = False
55-
if current:
56-
current['content'] = '\n'.join(content_lines).strip()
57-
instincts.append(current)
58-
current = {}
59-
content_lines = []
6055
else:
6156
# Start of frontmatter
6257
in_frontmatter = True
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
"""Tests for parse_instinct_file() — verifies content after frontmatter is preserved."""
2+
3+
import importlib.util
4+
import os
5+
6+
# Load instinct-cli.py (hyphenated filename requires importlib)
7+
_spec = importlib.util.spec_from_file_location(
8+
"instinct_cli",
9+
os.path.join(os.path.dirname(__file__), "instinct-cli.py"),
10+
)
11+
_mod = importlib.util.module_from_spec(_spec)
12+
_spec.loader.exec_module(_mod)
13+
parse_instinct_file = _mod.parse_instinct_file
14+
15+
16+
MULTI_SECTION = """\
17+
---
18+
id: instinct-a
19+
trigger: "when coding"
20+
confidence: 0.9
21+
domain: general
22+
---
23+
24+
## Action
25+
Do thing A.
26+
27+
## Examples
28+
- Example A1
29+
30+
---
31+
id: instinct-b
32+
trigger: "when testing"
33+
confidence: 0.7
34+
domain: testing
35+
---
36+
37+
## Action
38+
Do thing B.
39+
"""
40+
41+
42+
def test_multiple_instincts_preserve_content():
43+
result = parse_instinct_file(MULTI_SECTION)
44+
assert len(result) == 2
45+
assert "Do thing A." in result[0]["content"]
46+
assert "Example A1" in result[0]["content"]
47+
assert "Do thing B." in result[1]["content"]
48+
49+
50+
def test_single_instinct_preserves_content():
51+
content = """\
52+
---
53+
id: solo
54+
trigger: "when reviewing"
55+
confidence: 0.8
56+
domain: review
57+
---
58+
59+
## Action
60+
Check for security issues.
61+
62+
## Evidence
63+
Prevents vulnerabilities.
64+
"""
65+
result = parse_instinct_file(content)
66+
assert len(result) == 1
67+
assert "Check for security issues." in result[0]["content"]
68+
assert "Prevents vulnerabilities." in result[0]["content"]
69+
70+
71+
def test_empty_content_no_error():
72+
content = """\
73+
---
74+
id: empty
75+
trigger: "placeholder"
76+
confidence: 0.5
77+
domain: general
78+
---
79+
"""
80+
result = parse_instinct_file(content)
81+
assert len(result) == 1
82+
assert result[0]["content"] == ""

0 commit comments

Comments
 (0)