spec-kitty / spec-kitty/spec-kitty
[Phase 4] WP4.8 — spec-kitty explain: query surface with citations
- Dominant language
- Python
- Stars
- 1.6k
- Forks
- 165
- Avg merge
- 14h 52m
- Merged PRs (30d)
- 303
Description
**Parent**: #466 (Phase 4)
**Inspired by**: Karpathy wiki pattern — query mode with citations.
**Architecture**: §7 (profile-as-entry-point), §9 (provenance)
**Depends on**: WP4.4 (advise/execute), WP4.5 (profiles list), Phase 3 WP3.6 (provenance), Phase 5 WP5.1 (glossary in DRG)
## Goal
Add a read-optimized query surface to complement the write-heavy substrate the rebuild creates. Spec Kitty now has the event stream, provenance, DRG, and bundle — but no command for the questions humans and host LLMs ask each other every day:
- *"Why did we choose strict TDD?"*
- *"Where did this 'no fallback' rule come from?"*
- *"Who picked this paradigm and against which corpus?"*
- *"What was the reasoning for the workspace-per-WP branching strategy?"*
Without a query surface, host LLMs either fabricate answers or refuse to engage when users ask "why" questions. The host-LLM advise/execute model from Phase 4 needs a symmetric counterpart for *understanding*.
## Why this matters
\`spec-kitty advise\` is for **doing**: you give it a request, it routes to a profile + action and returns governance context.
\`spec-kitty explain\` is for **understanding**: you give it a question, it walks the artifact graph and event stream and returns a structured answer with **inline citations** to artifact URNs, event ids, and provenance entries. Every claim is hyperlinked to its source — no hallucination room for the host LLM.
This is also the natural surface for the FR4 retrospective profile when it asks "why was directive X added?" — it calls explain and gets a cited answer, not a guess.
## CLI surface
\`\`\`
spec-kitty explain "why are we using strict TDD?" # human-readable + citations
spec-kitty explain "why TDD?" --json # structured output for host LLMs
spec-kitty explain --topic "branch strategy" # topic-scoped exploration
spec-kitty explain --artifact directive:rd-001-tdd # explain a specific artifact's history
\`\`\`
## What it queries
For each question, the explainer walks:
1. **Merged DRG**: relevant directives, paradigms, ADRs, glossary terms via topic + relation traversal
2. **Provenance**: synthesizer source inputs (interview answers, code samples, URLs, corpus snapshots) for each cited artifact
3. **Event stream**: retrospective findings, drift triggers, glossary resolutions that reference the topic
4. **Charter sections**: charter.md passages that introduced or motivated the artifact
5. **WP / mission history**: closed WPs and missions whose context pulled the artifact
## Output shape (JSON)
\`\`\`json
{
"question": "why are we using strict TDD?",
"answer": "Strict TDD was adopted via [directive:rd-001-tdd](urn) during the initial charter interview on [2026-03-12](provenance:p-1234) because the user explicitly requested 'test-first discipline' [interview-answer:q-007](urn). It was reinforced by [retrospective finding](event:evt-9821) in mission 042 where the agent caught two regressions before commit, and again in [mission 051's debrief](event:evt-1102) where the team explicitly recommended keeping it.",
"citations": [
{"id": "directive:rd-001-tdd", "kind": "directive", "url": "..."},
{"id": "provenance:p-1234", "kind": "provenance", "url": "..."},
{"id": "interview-answer:q-007", "kind": "interview", "url": "..."},
{"id": "evt-9821", "kind": "event", "url": "..."},
{"id": "evt-1102", "kind": "event", "url": "..."}
],
"confidence": "high",
"uncited_claims": []
}
\`\`\`
## Hard rules
- **Every claim in the answer is cited**, or the claim is moved to \`uncited_claims\` with a flag
- **No fabrication**: if no cited evidence exists for a claim, it does not appear in the answer
- **Read-only**: the explainer never writes events, mutates state, or triggers synthesis — it is purely a query surface
- **Deterministic-where-possible**: the graph walk is deterministic; the LLM call is only for synthesizing the cited evidence into prose, not for inferring facts
## Acceptance gates
1. A fixture question against a fixture project produces an answer where every claim is cited to a real artifact / event / provenance entry
2. \`--json\` output is parseable and host-LLM friendly
3. The Spec Kitty skill (WP4.7) teaches host LLMs to call \`spec-kitty explain\` for any "why" question instead of guessing
4. The retrospective profile (Phase 6 WP6.6) uses explain as a tool when investigating doctrine effectiveness
5. A negative test: a question that has no graph evidence returns "I have no evidence for this in the project history" rather than fabricating
6. Performance: explain returns in under 10s p95 for typical questions on a medium-sized project
## Source
Suggested by user 2026-04-07 from Karpathy wiki design feedback. Top-3 priority tip: closes the read/write asymmetry of the rebuild and gives host LLMs a fabrication-free surface for "why" questions.
Contributor guide
Assessment
This issue has not been assessed yet.