profile drill-down/source-link preservation

This commit is contained in:
2026-04-26 00:13:45 +02:00
parent e8fdfe6e17
commit 5aa76af78c
8 changed files with 88 additions and 11 deletions

View File

@@ -40,6 +40,7 @@ class RegistryStore:
migration_path = Path(__file__).parents[3] / "migrations" / "0001_initial.sql"
with self.connect() as connection:
connection.executescript(migration_path.read_text(encoding="utf-8"))
self._ensure_approved_source_ref_columns(connection)
def connect(self) -> sqlite3.Connection:
connection = sqlite3.connect(self.database_path)
@@ -47,6 +48,20 @@ class RegistryStore:
connection.execute("PRAGMA foreign_keys = ON")
return connection
def _ensure_approved_source_ref_columns(
self,
connection: sqlite3.Connection,
) -> None:
for table in ("approved_features", "approved_evidence"):
columns = {
row["name"]
for row in connection.execute(f"PRAGMA table_info({table})").fetchall()
}
if "source_refs" not in columns:
connection.execute(
f"ALTER TABLE {table} ADD COLUMN source_refs TEXT NOT NULL DEFAULT '[]'"
)
def create_repository(
self,
*,
@@ -1153,15 +1168,24 @@ class RegistryStore:
type: str,
location: str,
confidence: float,
source_refs: list[SourceReference] | None = None,
) -> int:
with self.connect() as connection:
cursor = connection.execute(
"""
INSERT INTO approved_features
(repository_id, capability_id, name, type, location, confidence)
VALUES (?, ?, ?, ?, ?, ?)
(repository_id, capability_id, name, type, location, confidence, source_refs)
VALUES (?, ?, ?, ?, ?, ?, ?)
""",
(repository_id, capability_id, name, type, location, confidence),
(
repository_id,
capability_id,
name,
type,
location,
confidence,
self._source_refs_to_json(source_refs or []),
),
)
return int(cursor.lastrowid)
@@ -1173,15 +1197,23 @@ class RegistryStore:
type: str,
reference: str,
strength: str,
source_refs: list[SourceReference] | None = None,
) -> int:
with self.connect() as connection:
cursor = connection.execute(
"""
INSERT INTO approved_evidence
(repository_id, capability_id, type, reference, strength)
VALUES (?, ?, ?, ?, ?)
(repository_id, capability_id, type, reference, strength, source_refs)
VALUES (?, ?, ?, ?, ?, ?)
""",
(repository_id, capability_id, type, reference, strength),
(
repository_id,
capability_id,
type,
reference,
strength,
self._source_refs_to_json(source_refs or []),
),
)
return int(cursor.lastrowid)
@@ -1208,7 +1240,7 @@ class RegistryStore:
).fetchall()
feature_rows = connection.execute(
"""
SELECT id, capability_id, name, type, location, confidence
SELECT id, capability_id, name, type, location, confidence, source_refs
FROM approved_features
WHERE repository_id = ?
ORDER BY id
@@ -1217,7 +1249,7 @@ class RegistryStore:
).fetchall()
evidence_rows = connection.execute(
"""
SELECT id, capability_id, type, reference, strength
SELECT id, capability_id, type, reference, strength, source_refs
FROM approved_evidence
WHERE repository_id = ?
ORDER BY id
@@ -1234,6 +1266,7 @@ class RegistryStore:
type=row["type"],
location=row["location"],
confidence=row["confidence"],
source_refs=self._source_refs_from_json(row["source_refs"]),
)
)
@@ -1245,6 +1278,7 @@ class RegistryStore:
type=row["type"],
reference=row["reference"],
strength=row["strength"],
source_refs=self._source_refs_from_json(row["source_refs"]),
)
)
@@ -1608,6 +1642,7 @@ class RegistryStore:
"path": source_ref.path,
"kind": source_ref.kind,
"name": source_ref.name,
"line": source_ref.line,
}
for source_ref in source_refs
]
@@ -1620,6 +1655,7 @@ class RegistryStore:
path=item.get("path", ""),
kind=item.get("kind", ""),
name=item.get("name", ""),
line=item.get("line"),
)
for item in json.loads(value)
]