Repository navigation
feat(context-engine): D3 P0-A — surface cold-item slug + record injected slugs (attribution substrate) - #44
Merged
Conversation
…ted slugs (attribution substrate)
Substrate for D3 attribution scheme A (explicit Context-Used: <slug> citation).
Two focused, non-breaking changes to the context engine, no promotion-gate
behavior change:
- cold.py surface_cold: prefix each surfaced cold line with a machine-parseable
[<slug>] citation token; human "topic — glob — finding" content unchanged.
- route.py telemetry: _log_injection_event now records cold_slugs
([{slug, ts}] per surfaced cold item, ts = injection time) in ADDITION to the
legacy cold_surfaced count and all existing fields. Slugs recovered from the
surfaced lines via _cold_slug_from_line (skips the ...(N more) note).
Tests: parse-back + updated exact-line assertions (test_cold_store.py);
cold_slugs recorded with legacy fields intact + truncation-note exclusion
(test_context_router.py). Full suite 412 pass; ruff clean.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What & why
The P0-A substrate for D3 "attribution scheme A" — explicit
Context-Used: <slug>citation. Before an acting agent can cite the cold memory it used, two things must exist: (1) the slug must be visible in the injected context, and (2) the system must have a record of which slugs were injected (and when) to match a later citation against. This PR adds both. It is groundwork only — no consumer of the citation yet, and no promotion-gate behavior change.Changes (two focused, non-breaking edits)
A. Surface the slug (
context_engine/cold.py)surface_coldnow prefixes each surfaced cold line with a machine-parseable[<slug>]citation token:[projection] projection — src/x/** — Redaction must run before validation.The human
topic — glob — findingcontent after the token is unchanged. What surfaces, and when, is untouched.B. Record injected slugs + ts (
context_engine/route.py)_log_injection_eventwrites a newcold_slugsfield to the injection telemetry JSONL —[{"slug": ..., "ts": ...}]per surfaced cold item,ts= injection time — in addition to the existingcold_surfacedcount and every current field. Slugs are recovered from the surfaced lines by a new_cold_slug_from_linehelper that skips the...(N more)truncation note. Fully backward compatible: existing telemetry consumers/tests read the same old fields.Test coverage
tests/test_cold_store.py: updated the two exact-line assertions to include the token; added a parse-back test (line carries a[slug]that parses to the slug and the human content is preserved intact).tests/test_context_router.py:cold_slugsrecorded (slug + ts) with the legacycold_surfacedcount and all other fields unchanged; the...(N more)truncation note is excluded fromcold_slugs.ruff check .clean; SPDX headers present. Custodian pre-push audit: 0 findings, clean.🤖 Generated with Claude Code