Expand description
Card context injection — resolves Card summaries for prompt injection.
Phase 3-F MVP: alc.llm(prompt, {card_context = ...}) opts key wires
a small set of prior Cards into the LLM system prompt as an XML-like
<past_cards> block. This module is the pure-Rust core: Lua bridge
wiring lives in bridge/llm.rs.
§Public API
CardContextSpec— 2-form spec (CardIdorQuery { pkg, limit }) received from the Lua bridge after opts extraction.resolve— spec →Vec<Json>full Card resolution against aCardStore. Silent Ok(empty) on not-found / empty query.format_past_cards— infallible fixed-template renderer producing the<past_cards>...</past_cards>block.
§Fixed format template (MVP)
<past_cards>
Card MM/DD pkg=<pkg> card_id=<id> [run.status=<status>] Rating <val> reason=<reason>
...
</past_cards>- Each Card on 1 line,
created_atdesc order (newest first) [run.status=...]emitted only when the Card JSON carriesrun.statusRating <val>emitted only whenstats.pass_rateis present (formatted with 1 decimal digit)reason=<reason>emitted only whenrun.reasonis presentMM/DDderived from RFC 3339created_at(&s[5..10]with the-separator rewritten to/); omitted whencreated_atis missing or too short- Empty input slice → empty string (no
<past_cards>wrapper)
§Error handling
resolve returns Result<Vec<Json>, String>. Underlying
card::get_with_store / card::find_with_store errors are re-wrapped
with a "card_context resolve: " prefix so the bridge layer can
surface them via tracing::warn! before silently dropping the inject
(Phase 3-F Done Criteria #4: silent no-op on resolution failure).
Enums§
- Card
Context Spec - Card context specification extracted from the Lua
card_contextopt.
Functions§
- format_
past_ cards - Render a slice of resolved Card JSON values as the fixed
<past_cards>XML-like block. - resolve
- Resolve a
CardContextSpecagainststore, returning full Card JSON documents.