Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/secfoo/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,20 @@
STDERR_EXCERPT_LIMIT = 2000


def _git_head_commit(path: Path) -> str | None:
"""Return the HEAD commit SHA for a git repo at `path`, or None if
the directory isn't a git repo or git isn't available."""
import subprocess
try:
result = subprocess.run(
["git", "-C", str(path), "rev-parse", "HEAD"],
capture_output=True, text=True, timeout=10,
)
return result.stdout.strip() if result.returncode == 0 else None
except Exception:
return None


@dataclass
class RunOutcome:
run_uuid: str
Expand Down Expand Up @@ -206,6 +220,8 @@ def _run_single_skill(

adapter = get_adapter(agent_id)
result = adapter.run(prompt, workdir=target_ctx.local_path, timeout=timeout)
# Memory Bank: capture HEAD SHA so future runs can diff against this baseline.
target_commit = _git_head_commit(target_ctx.local_path)

if on_skill_complete:
on_skill_complete(skill.name, result.status)
Expand Down Expand Up @@ -233,6 +249,7 @@ def _run_single_skill(
input_tokens=result.input_tokens,
output_tokens=result.output_tokens,
cost_usd=result.cost_usd,
target_commit=target_commit, # Memory Bank: persisted for incremental diff rescans.
)

if result.status == "success":
Expand Down
2 changes: 1 addition & 1 deletion src/secfoo/storage/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class RunRecord:
output_tokens: int | None = None
cost_usd: float | None = None
project_display_name: str | None = None
cost_usd: float | None = None
target_commit: str | None = None # Memory Bank: git HEAD SHA at scan time.


@dataclass(frozen=True)
Expand Down
6 changes: 5 additions & 1 deletion src/secfoo/storage/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ def use_db_path(path: Path):
"input_tokens": "ALTER TABLE runs ADD COLUMN input_tokens INTEGER",
"output_tokens": "ALTER TABLE runs ADD COLUMN output_tokens INTEGER",
"cost_usd": "ALTER TABLE runs ADD COLUMN cost_usd REAL",
# Memory Bank: git HEAD SHA at scan time; foundation for incremental diff-based rescans.
"target_commit": "ALTER TABLE runs ADD COLUMN target_commit TEXT",
}

_ASSESSMENTS_MIGRATIONS = {
Expand Down Expand Up @@ -290,12 +292,13 @@ def complete_run(
input_tokens: int | None = None,
output_tokens: int | None = None,
cost_usd: float | None = None,
target_commit: str | None = None, # Memory Bank: HEAD SHA of the scanned repo.
) -> None:
self._conn.execute(
"UPDATE runs SET status = ?, exit_code = ?, finished_at = ?, duration_seconds = ?, "
"report_path = ?, prompt_path = ?, stderr_excerpt = ?, critical_count = ?, high_count = ?, "
"medium_count = ?, low_count = ?, info_count = ?, input_tokens = ?, output_tokens = ?, "
"cost_usd = ? WHERE run_uuid = ?",
"cost_usd = ?, target_commit = ? WHERE run_uuid = ?",
(
status,
exit_code,
Expand All @@ -312,6 +315,7 @@ def complete_run(
input_tokens,
output_tokens,
cost_usd,
target_commit,
run_uuid,
),
)
Expand Down
4 changes: 3 additions & 1 deletion src/secfoo/storage/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ CREATE TABLE IF NOT EXISTS runs (
cost_usd REAL,
-- Set once `secfoo cloud` has pushed this run to the enterprise
-- portal. NULL means never synced (offline, or no `cloud login` yet).
cloud_synced_at TEXT
cloud_synced_at TEXT,
-- Memory Bank: git HEAD SHA at scan time; enables future incremental diff-based rescans.
target_commit TEXT
);

-- Files manually uploaded to an assessment (AI-BOM inventories, or other
Expand Down
Loading