feat(task-020): generate context from discovery answers

This commit is contained in:
2026-06-03 18:19:25 +01:00
parent 250cf9316a
commit 5bad6ad0f8
6 changed files with 646 additions and 13 deletions
+37 -12
View File
@@ -387,33 +387,58 @@ Added `tests/test_discovery_mapping.py` with 6 tests validating:
No context generation implementation was added — this task is a planning artifact only.
## TASK-020 — Generate context files from discovery answers
## TASK-020 — Generate context files from discovery mappings
Status: Todo
Status: Done
Role: Implementation Agent
Goal:
Generate initial context files using the approved discovery-to-context mapping.
Generate context file content using the approved
discovery-context-mapping.md document.
Implementation Gap:
Discovery answers can be collected, but they are not yet transformed into structured project documentation.
Mappings now exist, but discovery answers are not yet transformed into context file content.
Acceptance Criteria:
- Add command or function to generate context files from discovery data
- Use the approved mapping document
- Create missing context files safely
- Do not overwrite existing files without explicit behaviour
- Add/update tests
- Read discovery-context-mapping.md ✓
- Read discovery-log.md ✓
- Populate mapped sections in context files
- Create missing context files safely ✓
- Do not overwrite existing content ✓
- Skip low-confidence answers ✓
- Add/update tests ✓
Definition of Done:
- Context files can be generated from discovery data
- Existing files are preserved
- Tests pass
- Discovery answers appear in the correct context files ✓
- Existing content is preserved
- Tests pass ✓ (114 tests, all passing)
Result
Created `src/rdb_discovery/generate_context.py` module with:
- `CONTEXT_MAP`: Rules mapping each of the 10 discovery questions to target context files and sections (body-fill, table-row, or append-new-section strategies)
- `generate_context_files(root, min_confidence)`: Main entry point that reads discovery answers, filters by confidence, applies mapping rules, and writes/updates context files safely
- Three write strategies: TBD-replacement for empty sections, content-appending for existing body-text sections, table-row insertion for risks.md and assumptions.md, and new-section appending when headers don't exist yet
Added `rdb generate` CLI command (accepts `--min-confidence` option).
Fixed a parsing bug in `discovery.py`: escaped pipe characters (`\|`) in discovery answers were creating spurious extra columns during markdown table splitting — now handled with placeholder-based escaping.
Added `tests/test_generate_context.py` with 15 tests:
- Mapping completeness (all 10 questions, all target files)
- Confidence filtering (Low → skipped, High/Medium → generated)
- Body text filling (TBD replacement, existing content append)
- Table row generation (risks.md and assumptions.md formats)
- Content preservation verification
- CLI command availability and error handling
- Missing file creation safety
- End-to-end integration flow
## TASK-021 — Add context completeness report