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:
@@ -30,6 +30,7 @@ CREATE TABLE IF NOT EXISTS prompt_artifacts (
|
||||
artifact_type TEXT NOT NULL,
|
||||
content_digest TEXT NOT NULL,
|
||||
content_size INTEGER DEFAULT 0,
|
||||
content TEXT DEFAULT '',
|
||||
metadata JSON,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
@@ -59,6 +60,13 @@ def initialize_artifact_tables(db_path: str) -> None:
|
||||
conn = sqlite3.connect(db_path)
|
||||
try:
|
||||
conn.executescript(ARTIFACT_TABLES_SQL)
|
||||
# Migration: add content column to existing databases
|
||||
try:
|
||||
conn.execute(
|
||||
"ALTER TABLE prompt_artifacts ADD COLUMN content TEXT DEFAULT ''"
|
||||
)
|
||||
except sqlite3.OperationalError:
|
||||
pass # Column already exists
|
||||
conn.commit()
|
||||
finally:
|
||||
conn.close()
|
||||
@@ -107,8 +115,8 @@ class SQLiteArtifactRepository(IArtifactRepository):
|
||||
"""
|
||||
INSERT INTO prompt_artifacts (
|
||||
id, space_id, name, artifact_type, content_digest,
|
||||
content_size, metadata, created_at, updated_at
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
content_size, content, metadata, created_at, updated_at
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
""",
|
||||
(
|
||||
artifact.id,
|
||||
@@ -117,6 +125,7 @@ class SQLiteArtifactRepository(IArtifactRepository):
|
||||
artifact.artifact_type.value,
|
||||
artifact.content_digest,
|
||||
artifact.content_size,
|
||||
artifact.content,
|
||||
json.dumps(artifact.metadata.to_dict()),
|
||||
artifact.created_at.isoformat(),
|
||||
artifact.updated_at.isoformat(),
|
||||
@@ -251,12 +260,14 @@ class SQLiteArtifactRepository(IArtifactRepository):
|
||||
cursor = conn.execute(
|
||||
"""
|
||||
UPDATE prompt_artifacts
|
||||
SET content_digest = ?, content_size = ?, metadata = ?, updated_at = ?
|
||||
SET content_digest = ?, content_size = ?, content = ?,
|
||||
metadata = ?, updated_at = ?
|
||||
WHERE id = ?
|
||||
""",
|
||||
(
|
||||
artifact.content_digest,
|
||||
artifact.content_size,
|
||||
artifact.content,
|
||||
json.dumps(artifact.metadata.to_dict()),
|
||||
artifact.updated_at.isoformat(),
|
||||
artifact.id,
|
||||
@@ -326,6 +337,7 @@ class SQLiteArtifactRepository(IArtifactRepository):
|
||||
artifact_type=ArtifactType(row["artifact_type"]),
|
||||
content_digest=row["content_digest"],
|
||||
content_size=row["content_size"],
|
||||
content=row["content"] or "",
|
||||
metadata=ArtifactMetadata.from_dict(metadata_dict),
|
||||
created_at=datetime.fromisoformat(row["created_at"]),
|
||||
updated_at=datetime.fromisoformat(row["updated_at"]),
|
||||
|
||||
Reference in New Issue
Block a user