feat(TASK-005): wire project state and agent handoff into start/complete commands
- Add update_project_state() helper: updates Current Task + Last Updated in PROJECT_STATE.md via regex sub, preserving all surrounding formatting. - Add update_agent_handoff() helper: updates Current Stage + Current Task sections in AGENT_HANDOFF.md, auto-detected from project_stage(). - Wire both helpers into rdb start TASK-ID and rdb complete TASK-ID CLI commands so task lifecycle transitions propagate to all control files. - ADDING test_status.py with 5 tests: update_project_state task/timestamp updates, missing-file false return, agent handoff update and miss. Acceptance criteria met: - rdb start/complete now update PROJECT_STATE.md - rdb start/complete now update AGENT_HANDOFF.md - RUN_LOG.md already updated (pre-existing) - Task formatting preserved (regex sub targets single line only)
This commit is contained in:
@@ -9,7 +9,7 @@ from rich.table import Table
|
||||
|
||||
from .discovery import append_discovery_answer, append_followup_answer, core_questions, read_discovery_answers
|
||||
from .handoff import build_handoff
|
||||
from .status import project_stage, task_counts
|
||||
from .status import project_stage, task_counts, update_project_state, update_agent_handoff
|
||||
from .tasks import generate_agent_prompt, get_next_task, update_task_status
|
||||
from .templates import CONTEXT_FILES, write_file_if_missing
|
||||
|
||||
@@ -155,6 +155,8 @@ def start(task_id: str) -> None:
|
||||
console.print(f"[red]Task not found:[/red] {task_id}")
|
||||
raise typer.Exit(code=1)
|
||||
append_run_log(root, "Task started", task_id=task_id)
|
||||
update_project_state(root, task_id)
|
||||
update_agent_handoff(root, task_id)
|
||||
console.print(f"[green]Started {task_id}.[/green]")
|
||||
|
||||
|
||||
@@ -167,6 +169,8 @@ def complete(task_id: str) -> None:
|
||||
console.print(f"[red]Task not found:[/red] {task_id}")
|
||||
raise typer.Exit(code=1)
|
||||
append_run_log(root, "Task completed", task_id=task_id, notes=notes)
|
||||
update_project_state(root, task_id)
|
||||
update_agent_handoff(root, task_id)
|
||||
console.print(f"[green]Completed {task_id}.[/green]")
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import date
|
||||
from pathlib import Path
|
||||
import re
|
||||
|
||||
from .tasks import read_tasks
|
||||
|
||||
@@ -23,3 +25,38 @@ def task_counts(root: Path) -> dict[str, int]:
|
||||
for task in read_tasks(root):
|
||||
counts[task.status] = counts.get(task.status, 0) + 1
|
||||
return counts
|
||||
|
||||
|
||||
_CURRENT_TASK_RE = re.compile(r"^(Current Task): .+$", re.MULTILINE)
|
||||
_UPDATED_RE = re.compile(r"^(Last Updated): .+$", re.MULTILINE)
|
||||
|
||||
|
||||
def update_project_state(root: Path, task_id: str = "None") -> bool:
|
||||
"""Update PROJECT_STATE.md current task and timestamp."""
|
||||
path = root / "PROJECT_STATE.md"
|
||||
if not path.exists():
|
||||
return False
|
||||
|
||||
text = path.read_text(encoding="utf-8")
|
||||
text = _CURRENT_TASK_RE.sub(f"Current Task: {task_id}", text, count=1)
|
||||
text = _UPDATED_RE.sub(f"Last Updated: {date.today().isoformat()}", text, count=1)
|
||||
path.write_text(text, encoding="utf-8")
|
||||
return True
|
||||
|
||||
|
||||
_STAGE_RE = re.compile(r"(## Current Stage\n\n)[\s\S]+?(?=\n)", re.MULTILINE | re.DOTALL)
|
||||
_TASK_RE = re.compile(r"(## Current Task\n\n)[\s\S]+?(?=\n)", re.MULTILINE | re.DOTALL)
|
||||
|
||||
|
||||
def update_agent_handoff(root: Path, task_id: str = "None") -> bool:
|
||||
"""Update AGENT_HANDOFF.md current stage and task."""
|
||||
path = root / "AGENT_HANDOFF.md"
|
||||
if not path.exists():
|
||||
return False
|
||||
|
||||
text = path.read_text(encoding="utf-8")
|
||||
stage = project_stage(root)
|
||||
text = _STAGE_RE.sub(f"## Current Stage\n\n{stage}", text, count=1)
|
||||
text = _TASK_RE.sub(f"## Current Task\n\n{task_id}", text, count=1)
|
||||
path.write_text(text, encoding="utf-8")
|
||||
return True
|
||||
|
||||
Reference in New Issue
Block a user