Skip to content

feat(context-engine): D3 P0-B — self-describing citation instruction in the injected cold block - #46

Merged
ProtocolWarden merged 1 commit into
mainfrom
feat/d3-p0b-citation-instruction
Jul 17, 2026
Merged

ProtocolWarden merged 1 commit into
mainfrom
feat/d3-p0b-citation-instruction

Conversation

@ProtocolWarden

Copy link
Copy Markdown
Owner

What

The injected cold block is now SELF-DESCRIBING: when at least one real cold item line is surfaced, build_context closes the cold section with one instruction line teaching the reading agent the D3 citation protocol:

(cite: if you act on a [slug] item above, add the git trailer "Context-Used: <slug>" to that commit)

Why

D3 attribution scheme A (explicit citation) needs the ACTING agent to know the protocol. Rather than changing every consumer's prompt, the protocol travels with the data — any consumer that receives the injected block automatically receives the instruction. Builds directly on #44 (slug tokens + cold_slugs telemetry).

Design constraints honoured

  • One line, only when cold items surface: gated on cold_slugs (at least one real slug-bearing line — never on warm-only injections, never appended to a note-only block, never when the block is empty).
  • Telemetry unaffected: the line is appended to the rendered block string AFTER telemetry assembly; cold_surfaced and cold_slugs are byte-identical to before.
  • Not parseable as a slug line: the note does not start with [, so _cold_slug_from_line returns None for it.
  • cold.py surface_cold stays pure — the change lives where the block is assembled (route.py).

Tests

  • test_cold_block_is_self_describing: instruction present exactly once, names the Context-Used: trailer key, is the LAST line of the block; _cold_slug_from_line(COLD_CITATION_NOTE) is None; cold_surfaced/cold_slugs telemetry unchanged.
  • test_no_citation_instruction_without_cold_items: warm-only injection carries no instruction.

Full suite: 434 passed (was 432). ruff check . clean.

🤖 Generated with Claude Code

…in the injected cold block

The D3 attribution design (scheme A, explicit citation) needs the ACTING
agent to know the protocol: when it acts on an injected cold item, cite it
via a `Context-Used: <slug>` git trailer on that commit. Rather than
changing every consumer's prompt, the protocol travels with the data — the
injected cold block itself now closes with one instruction line.

- route.py `build_context`: append `COLD_CITATION_NOTE` as the last line of
  the cold section, ONLY when at least one real slug-bearing cold line is
  surfaced (gated on `cold_slugs` — never on warm-only injections, never on
  an empty block).
- Rendered-only: the line is appended to the block string after telemetry
  assembly, so `cold_surfaced` and `cold_slugs` are unchanged; it does not
  start with `[`, so `_cold_slug_from_line` returns None for it.
- cold.py `surface_cold` stays pure (no change).
- Tests: instruction present as the last line iff a real cold item surfaced,
  absent on warm-only injection, not parseable as a slug line, telemetry
  count/slugs unaffected. Full suite 434 pass; ruff clean.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@ProtocolWarden
ProtocolWarden merged commit 8af6e35 into main Jul 17, 2026
7 checks passed
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.

1 participant