fix(prompts): fix three infrastructure bugs in prompt dependency resolution

- ContentMacro: add __post_init__ to auto-derive raw_text when built
  programmatically, preventing str.replace("", X) corruption
- MacroParser: add @{target} shorthand syntax support mapped to REQUIRED kind,
  updating parse, has_macros, count_macros, and find_macro_positions
- Artifact: store content in model and SQLite DB, replace resolver placeholder
  with actual artifact content, add migration for existing databases

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-11 20:53:02 +01:00
parent 01b9596ce6
commit 706981c39f
9 changed files with 191 additions and 10 deletions

View File

@@ -38,6 +38,9 @@ class MacroParser:
re.IGNORECASE
)
# Shorthand pattern: @{target} — maps to MacroKind.REQUIRED
SHORTHAND_PATTERN = re.compile(r'@\{([^}]+)\}')
# Parameter pattern: |key=value
PARAM_PATTERN = re.compile(r'\|([^=]+)=([^|]+)')
@@ -95,6 +98,19 @@ class MacroParser:
f"Line {line_number}: {e}"
) from e
# Scan for @{target} shorthand syntax
for match in self.SHORTHAND_PATTERN.finditer(line):
target = match.group(1).strip()
raw_text = match.group(0)
if target:
macros.append(ContentMacro(
kind=MacroKind.REQUIRED,
target=target,
parameters={},
raw_text=raw_text,
line_number=line_number,
))
return macros
def _parse_match(self, match: re.Match, line_number: int) -> ContentMacro:
@@ -172,7 +188,7 @@ class MacroParser:
content: Template content
Returns:
List of (start_pos, end_pos, macro_text) tuples
List of (start_pos, end_pos, macro_text) tuples sorted by position
"""
positions = []
for match in self.MACRO_PATTERN.finditer(content):
@@ -181,6 +197,13 @@ class MacroParser:
match.end(),
match.group(0)
))
for match in self.SHORTHAND_PATTERN.finditer(content):
positions.append((
match.start(),
match.end(),
match.group(0)
))
positions.sort(key=lambda p: p[0])
return positions
def count_macros(self, content: str) -> dict:
@@ -211,4 +234,4 @@ class MacroParser:
Returns:
True if any macros found
"""
return bool(self.MACRO_PATTERN.search(content))
return bool(self.MACRO_PATTERN.search(content) or self.SHORTHAND_PATTERN.search(content))