Skip to content

feat(archaeology): Code Archaeology Agent — reconstruct why decisions were made - #936

Merged
AmitoVrito merged 13 commits into
SynapseKit:mainfrom
DhruvGarg111:feat/issue-744-code-archaeology
Aug 22, 2026
Merged

AmitoVrito merged 13 commits into
SynapseKit:mainfrom
DhruvGarg111:feat/issue-744-code-archaeology

Conversation

@DhruvGarg111

Copy link
Copy Markdown
Collaborator

Closes #744

Summary

Implements the Code Archaeology Agent (issue #744) that fuses git log, markdown notes, and (opt-in) Slack/email archives to reconstruct why code exists in its current form.

Components

  • ArchaeologyAgent — orchestrates multi-source evidence extraction and narrative synthesis
  • TimelineReconstructor — merges multi-source events chronologically across git, local markdown, Slack, and email
  • CausalLinker — extracts and verifies causal claims using LLM + optional \NeuroSymbolicAgent\ for plausibility checks
  • EvolutionDiff — tracks how code evolved with rationale extracted from commit context and diffs

Design

  • Reuses existing \ imetravel\ (\GitBackend, \EvolutionIndex), \loaders\ (\SlackLoader, \EmailLoader), and \symbolic\ (\NeuroSymbolicAgent) modules
  • Zero new hard dependencies (external loaders are behind existing optional extras)
  • All public APIs are async-first with full type hints

Testing

  • Unit & integration tests in \ ests/archaeology/test_archaeology.py\ (23 tests, all passing)
  • Full regression suite: 1986 passed, 63 skipped in test suite
  • Ruff lint checks clean

DhruvGarg111 and others added 13 commits August 20, 2026 09:13
…erm-extraction helper

Additive-only groundwork for follow-up fixes: EvolutionIndex.ensure_built()
lets callers share one built index instead of each re-walking git history,
and archaeology/_terms.py centralizes the query-term-extraction/matching
snippet that was duplicated across timeline_reconstructor.py and
evolution_diff.py. No existing behavior changes yet.

Co-authored-by: Dhruv Garg <[email protected]>
EmailLoader stores the raw RFC 2822 "Date" header, but _email_events parsed
it with datetime.fromisoformat(), which raises on every real email and
silently substitutes datetime.now(UTC) — corrupting the chronological
ordering CausalLinker relies on to infer cause vs. effect. Now parsed with
email.utils.parsedate_to_datetime.

Also switches _git_events/_slack_events/_email_events/_markdown_events to
the shared extract_terms()/matches() helper (previously four near-identical,
already-inconsistent copies of the same snippet), and lets the reconstructor
accept a pre-built EvolutionIndex to avoid re-walking git history when one
is already available.

Co-authored-by: Dhruv Garg <[email protected]>
…history

When no search term matched, trace() fell back to all_entries — the entire
unfiltered commit history — instead of an empty result. ArchaeologyAgent.explain()
calls trace(query) with the raw natural-language question (the common case),
so any query whose terms don't literally match a file path/symbol/commit
subject silently returned every commit in the repo into the narrative prompt.

Also accepts a pre-built EvolutionIndex (shared with TimelineReconstructor
via ArchaeologyAgent) to avoid a second full git-history walk per explain()
call, and switches to the shared extract_terms() helper.

Co-authored-by: Dhruv Garg <[email protected]>
… build

ArchaeologyAgent.__init__ caught LLM construction errors with a bare
`except Exception: self.llm = None` and no logging — a typo'd provider or
missing API key silently degraded the agent to timeline-only mode with zero
diagnostic trail. Now logs a warning with the traceback.

Also builds one EvolutionIndex and passes it into both TimelineReconstructor
and EvolutionDiff, so explain() walks git history (log/diff/AST-parse) once
instead of twice — the two previously built entirely independent indexes.

Co-authored-by: Dhruv Garg <[email protected]>
…n as best-effort

_verify_claims awaited NeuroSymbolicAgent.solve() sequentially, one claim at
a time — now runs via asyncio.gather so N claims cost one round-trip's
latency instead of N.

NeuroSymbolicAgent.solve() formalizes its input into an SMT/Prolog/MiniZinc/
Sympy constraint program and checks it with a solver — built for problems
with decidable formal structure, not prose plausibility judgments. Free-text
causal claims have no reliable formalization, so the resulting `verified`
flag is a best-effort signal, not a formal proof. Documented that limitation
on _verify_claims and logged it at call time so it isn't mistaken for a
verified/formal guarantee.

Co-authored-by: Dhruv Garg <[email protected]>
…n fakes

Tests used unittest.mock (MagicMock/AsyncMock/patch) to stub SlackLoader,
EmailLoader, and a NeuroSymbolicAgent-shaped verifier — mocks silently
accept any call shape, so a real interface drift wouldn't be caught here.
Replaced with a hand-written FakeLoader (monkeypatched onto .aload) and a
FakeVerifier/FakeVerificationResult pair, matching this repo's no-mocking
testing standard.

Also strengthens regression coverage for the two correctness fixes in this
series: asserts the exact parsed timestamp for an RFC 2822 email date, and
asserts EvolutionDiff.trace() returns [] (not the full repo history) for
both an unmatched file path and an unmatched natural-language query.

Co-authored-by: Dhruv Garg <[email protected]>
@AmitoVrito

Copy link
Copy Markdown
Collaborator

Ran a multi-angle review (correctness, cleanup, altitude, testing conventions) and pushed 6 fix commits directly to this branch to address the confirmed findings:

  1. Email timestamps silently corrupted — _email_events parsed RFC 2822 dates with datetime.fromisoformat(), which raises on every real email and fell back to "now", breaking chronological ordering that CausalLinker relies on. Now uses email.utils.parsedate_to_datetime.
  2. EvolutionDiff.trace() fell back to the entire unfiltered repo history when no search term matched — and that's the exact path explain()'s natural-language queries hit. Now returns [] instead.
  3. CausalLinker verifier misuse — routes free-text causal claims through NeuroSymbolicAgent.solve(), which is built for formal SMT/Prolog/MiniZinc/Sympy problems, not prose plausibility. Documented as best-effort (not a formal guarantee) and logged accordingly.
  4. Silent LLM-construction failure — except Exception: self.llm = None had zero logging; now warns with the traceback.
  5. Tests used MagicMock/AsyncMock/patch — replaced with hand-written FakeLoader/FakeVerifier per this repo's no-mocking testing standard.
  6. Duplicate full git-history walk — TimelineReconstructor and EvolutionDiff each built their own EvolutionIndex; now share one via ArchaeologyAgent, roughly halving explain()'s dominant cost.
  7. Term-extraction logic duplicated 5x across two files, already inconsistent — extracted into a shared _terms.py helper.
  8. Sequential N+1 loop in causal-claim verification — now uses asyncio.gather.

Full suite (5070 tests) + archaeology suite (24 tests) pass, ruff clean. Great feature — thanks for building this, @DhruvGarg111!

@AmitoVrito
AmitoVrito merged commit 4e22e70 into SynapseKit:main Aug 22, 2026
14 checks passed
AmitoVrito added a commit that referenced this pull request Aug 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

v2.1: Code Archaeology Agent — reconstruct *why* every decision was made

2 participants