feat(task-018): add role-based context selection

This commit is contained in:
2026-06-02 18:09:11 +01:00
parent 34f7364c86
commit 1c2faa3162
6 changed files with 197 additions and 23 deletions
+49 -13
View File
@@ -11,9 +11,11 @@ Requires-Dist: pytest>=8.0.0; extra == "dev"
# rdb-discovery
A small CLI-first tool for repeatable software project discovery and delivery.
A small CLI-first tool that helps you generate and maintain useful project context files for AI-assisted development.
It creates markdown files that help humans and AI coding agents understand:
## Purpose
rdb-discovery exists to make it easier for humans and AI coding agents to understand:
- what is being built
- why it exists
@@ -21,6 +23,20 @@ It creates markdown files that help humans and AI coding agents understand:
- what task should be done next
- what stage the project is currently in
The tool creates and manages a set of markdown files — your project's source-of-truth context.
## Core workflow
1. **Ask discovery questions** — `rdb discover` captures answers about the product, architecture, risks, and open questions.
2. **Capture answers** — Structured responses are stored in `context/discovery-log.md` alongside confidence scores and follow-ups.
3. **Generate context files** — `rdb init` creates standardised project files (`product-brief.md`, `architecture.md`, `decisions.md`, etc.).
4. **Support agent implementation** — `rdb prompt` produces ready-to-paste implementation prompts for Claude Code or Cline, and `rdb start` / `rdb complete` manage task lifecycles.
## Support features (not the product)
- **Telemetry** records structured agent activity events in `.rdb/session-log.jsonl`. It enables future analysis but is not the main offering.
- **Guardrails** detect agent stalls, repeated reads, and inconsistent state to keep projects on track. They support the workflow but are secondary.
## Install for local development
```bash
@@ -32,23 +48,43 @@ pip install -e '.[dev]'
## Commands
```bash
rdb init
rdb discover
rdb status
rdb next
rdb start TASK-001
rdb complete TASK-001
rdb handoff
rdb init # Create standard project structure and context files
rdb discover # Ask 10 core discovery questions, record answers
rdb guardrails # Check for agent stalls and state inconsistencies
rdb prompt # Generate implementation prompt for the next task
rdb start TASK-001 # Mark a task as in progress
rdb complete TASK-001# Mark a task as done
rdb status # Show current stage and active task
rdb next # Print the next task to work on
rdb handoff # Generate agent handoff notes
```
## Bootstrap workflow
1. Run `rdb init`
2. Run `rdb discover`
3. Run `rdb status`
4. Run `rdb next`
5. Give the next task to Claude Code or Cline
6. Commit after each completed task
3. Review `rdb status` and `rdb next`
4. Give the next prompt to Claude Code or Cline via `rdb prompt`
5. Commit after each completed task
## Project structure
`rdb init` creates the following files (skips existing ones):
- context/discovery-log.md
- context/product-brief.md
- context/architecture.md
- context/decisions.md
- context/risks.md
- context/assumptions.md
- context/open-questions.md
- context/repository-context.md
- TASKS.md
- TEST_PLAN.md
- RUN_LOG.md
- PROJECT_STATE.md
- AGENT_HANDOFF.md
- .rdb/project.json
## Principle
+7
View File
@@ -3,9 +3,11 @@ pyproject.toml
src/rdb_discovery/__init__.py
src/rdb_discovery/cli.py
src/rdb_discovery/discovery.py
src/rdb_discovery/guardrails.py
src/rdb_discovery/handoff.py
src/rdb_discovery/status.py
src/rdb_discovery/tasks.py
src/rdb_discovery/telemetry.py
src/rdb_discovery/templates.py
src/rdb_discovery.egg-info/PKG-INFO
src/rdb_discovery.egg-info/SOURCES.txt
@@ -13,5 +15,10 @@ src/rdb_discovery.egg-info/dependency_links.txt
src/rdb_discovery.egg-info/entry_points.txt
src/rdb_discovery.egg-info/requires.txt
src/rdb_discovery.egg-info/top_level.txt
tests/test_discovery.py
tests/test_guardrails.py
tests/test_prompt.py
tests/test_status.py
tests/test_tasks.py
tests/test_telemetry.py
tests/test_templates.py
+44 -9
View File
@@ -109,7 +109,7 @@ def update_task_status(root: Path, task_id: str, new_status: str) -> bool:
return False
CONTEXT_FILES_TO_READ = [
DEFAULT_CONTEXT_FILES = [
"README.md",
"TASKS.md",
"PROJECT_STATE.md",
@@ -117,6 +117,38 @@ CONTEXT_FILES_TO_READ = [
"context/agent-guidelines.md",
]
ROLE_CONTEXT_FILES: dict[str, list[str]] = {
"Architecture Agent": [
"README.md",
"TASKS.md",
"PROJECT_STATE.md",
"context/architecture.md",
"context/product-brief.md",
"context/decisions.md",
],
"Implementation Agent": [
"README.md",
"TASKS.md",
"PROJECT_STATE.md",
"AGENT_HANDOFF.md",
"context/agent-guidelines.md",
"CLAUDE.md",
],
"Documentation Agent": [
"README.md",
"TASKS.md",
"PROJECT_STATE.md",
"AGENT_HANDOFF.md",
"context/agent-guidelines.md",
"TEST_PLAN.md",
],
}
def _context_files_for_role(role: str) -> list[str]:
"""Return the context file list for a given role, falling back to default."""
return ROLE_CONTEXT_FILES.get(role, DEFAULT_CONTEXT_FILES)
TEST_CMD_SECTION_RE = re.compile(
r"^##\s*Test Commands\s*\n([\s\S]*?)(?=^##|\Z)",
re.MULTILINE,
@@ -186,6 +218,7 @@ def generate_agent_prompt(root: Path) -> str:
return "No Todo task found."
role_text, article = task.role(root)
context_files = _context_files_for_role(role_text)
sections = [
f"You are {article} {role_text.lower()}.",
@@ -194,13 +227,15 @@ def generate_agent_prompt(root: Path) -> str:
"",
"# Read these files first",
"",
f"""- README.md
- TASKS.md
- PROJECT_STATE.md
- AGENT_HANDOFF.md""",
"",
"- context/agent-guidelines.md",
"",
]
for i, f in enumerate(context_files):
line = f"- {f}"
if i == len(context_files) - 1:
sections.append(line)
else:
sections.append(line)
sections.extend([
"---",
"",
"# Task",
@@ -210,7 +245,7 @@ def generate_agent_prompt(root: Path) -> str:
f"Status: {task.status}",
"",
f"Goal:\n{task.goal(root)}",
]
])
gap = task.implementation_gap(root)
if gap: