|
| 1 | +# supekku.scripts.lib.memory.staleness |
| 2 | + |
| 3 | +Batched staleness computation for memory artifacts. |
| 4 | + |
| 5 | +Computes staleness by counting git commits that touched scoped paths |
| 6 | +since a memory's last verified SHA. Uses a single git invocation for |
| 7 | +all scoped memories (DEC-086-06). |
| 8 | + |
| 9 | +## Constants |
| 10 | + |
| 11 | +- `__all__` |
| 12 | + |
| 13 | +## Functions |
| 14 | + |
| 15 | +- `_assign_commit_counts(results, attested, commit_data) -> None`: Count commits affecting each attested memory's scope paths. |
| 16 | +- `_collect_all_pathspecs(attested) -> list[str]`: Collect deduplicated pathspecs from all attested records. |
| 17 | +- `_collect_scope_paths(record) -> list[str]`: Collect all scope paths and converted globs for a record. |
| 18 | +- `_days_since(record, today) -> <BinOp>`: Compute days since the most relevant date on a record. |
| 19 | +- `_find_oldest_sha(attested) -> str`: Find the verified_sha from the record with the oldest verified date. |
| 20 | +- `_parse_git_log_output(output) -> list[_CommitEntry]`: Parse ``git log --oneline --name-only`` output into commit entries. |
| 21 | +- `_path_matches_scope(file_path, scope_paths) -> bool`: Check whether a file path matches any scope path (prefix match). |
| 22 | +- `_query_git_log(attested, root) -> <BinOp>`: Run a single git log and parse commits with affected paths. |
| 23 | + |
| 24 | +Returns None if git is unavailable or the command fails, so callers |
| 25 | +can distinguish "no commits found" from "unable to query." |
| 26 | +- `compute_batch_staleness(records, root) -> list[StalenessInfo]`: Compute staleness for multiple memories using a single git invocation. |
| 27 | + |
| 28 | +For scoped+attested memories, runs one ``git log`` from the oldest |
| 29 | +verified SHA and counts commits per memory's scope paths. |
| 30 | + |
| 31 | +Unscoped and unattested memories fall back to ``days_since`` from |
| 32 | +their verified or updated date. |
| 33 | + |
| 34 | +Args: |
| 35 | + records: Memory records to evaluate. |
| 36 | + root: Repository root for git commands. |
| 37 | + |
| 38 | +Returns: |
| 39 | + StalenessInfo for each input record, in the same order. |
| 40 | +- `glob_to_pathspec(glob) -> str`: Convert a scope glob pattern to a git pathspec. |
| 41 | + |
| 42 | +Strips trailing ``/**`` (directory wildcard) to produce a directory |
| 43 | +prefix that git understands. Other patterns pass through as-is. |
| 44 | +Leading ``./`` is also stripped. |
| 45 | + |
| 46 | +Args: |
| 47 | + glob: Scope glob pattern (e.g. ``supekku/cli/**``). |
| 48 | + |
| 49 | +Returns: |
| 50 | + Git-compatible pathspec string. |
| 51 | + |
| 52 | +## Classes |
| 53 | + |
| 54 | +### StalenessInfo |
| 55 | + |
| 56 | +Staleness data for a single memory. |
| 57 | + |
| 58 | +### _CommitEntry |
| 59 | + |
| 60 | +A parsed commit from git log output. |
0 commit comments