Expand description
Git-derived recency and staleness — a port of the git touchpoint in
src/asdecided/services/recency.py, per PORT-CONTRACT.d/08 §4.
Recency is derived from git log, never stored (ADR-045). This module
shells out to the real git binary with the exact argv the oracle uses and
reproduces its degrade-to-None posture: outside a repo, with no git
binary, or for an untracked file, every value is None — no error crosses
the boundary.
Landmines (PORT-CONTRACT.d/08 §4.2–4.3):
git log --format=%cIrenders the committer’s stored timezone offset and ignoresTZ.last_committedis kept verbatim (offset preserved, never normalized to UTC).age_days = (reference - last_committed).daysuses Pythontimedelta.days, which floors toward negative infinity (a future commit yields a negative age). This is whole-day truncation, not rounding.stale = age_days > threshold_days— strictly greater-than, so exactly at the threshold is not stale.- Unknown date ->
Staleness { None, None, None }.
Structs§
- Staleness
- One artifact’s freshness: its verbatim last-committed date and the derived
indicators. All-
Nonewhen the date is unknown. MirrorsStaleness.
Constants§
- DEFAULT_
STALE_ AFTER_ DAYS - The default “stale after” window (
DEFAULT_STALE_AFTER_DAYS).
Functions§
- first_
committed - The earliest commit time for
pathas the verbatim%cIstring of the first non-blank line (committer offset preserved), orNonewhen the file is untracked / uncommitted / outside a repo. Mirrorsgit log --reverse --format=%cI -- <path>(oldest first, first line is the creation commit) — used by the OKF export’screatedfield. - isoformat_
roundtrip - Python
datetime.fromisoformat(stamp).isoformat()round trip of a git%cIstamp: verbatim for the±HH:MMform git emits; a trailingZre-serializes as+00:00, a colonless±HHMMgains its colon,±HHbecomes±HH:00, and a space separator becomesT. - last_
committed - The most recent commit time for
pathas the verbatim%cIstring (committer offset preserved), orNonewhen the file is untracked / uncommitted / outside a repo. Mirrorsgit log -1 --format=%cI -- <path>. - last_
committed_ for_ paths - Last-committed time for each of
paths(the raw recency primitive). Every path maps toNonewhendirectoryis not a repo. Order preserved. - last_
committed_ for_ paths_ in_ repo - Batched form of
last_committed_for_pathsfor callers that already resolved the repository root. A newest-firstgit log --name-onlywalk assigns the first observed commit stamp to each path, reproducinggit log -1 --format=%cI -- <path>without one subprocess per artifact. - parse_
iso8601_ epoch - Parse a strict ISO-8601 timestamp with an explicit offset (
%cIform:YYYY-MM-DDTHH:MM:SS[.ffffff](Z|±HH:MM|±HHMM)) into Unix epoch seconds (UTC). Fractional seconds are ignored for whole-day math (git%cIhas none). ReturnsNoneon any structural surprise (treated as “unknown”, matching the oracle’sfromisoformatValueError->None). - pathspec
pathmade relative torepo_root(viacanonicalize, like Python’sPath.resolve()); if it lies outside the work tree, the absolute path is passed through unchanged.- repository_
root - The work-tree root containing
directory, orNoneif it is not a repo / git is unavailable. Mirrorsgit rev-parse --show-toplevel. - run_
git_ text run_gitwith Pythontext=Trueuniversal-newline decoding (\r\nand lone\r→\n). The recency callers in this module only trim%cIstamps and the toplevel path, so they stay on the raw form; the decided-mcp provenance surface parsesgit showfile content, where the normalization is load-bearing.- staleness
- Staleness of one last-committed date against
threshold_days, evaluated atreference_epoch_secs(Unix seconds, UTC). An unknown / unparseable date yields the all-Noneresult.