Files
roboco/roboco/api/routes/v2/flow_cell_pm.py
T
Renn F 72e01a7f13 feat(gateway): Wave 2 pre-gateway parity — structured note, sub_tasks, channels
Three Wave 2 gaps from the 2026-05-11 pre-gateway parity design:

G4 — note() decision/reflect now require structured fields at the gateway
(pre-gateway `Field(...)` parity). Returns `incomplete_input` envelope
with field-by-field hints when any required field is missing.
  - decision: context (str), options (list[{name,pros,cons}] min len 2),
    chosen (str), rationale (str). `consequences` and `next_steps` are
    now list[str] (was str). Renderer emits each option as a "### Name
    + Pros / Cons" block instead of a bullet — matches the pre-gateway
    DecisionOption sub-shape exposed in `roboco/mcp/schemas/__init__.py`
    at `254cc93`.
  - reflect: what_done, what_learned, what_struggled (each non-empty
    str). next_steps stays optional.
  - Bumped tests/unit/gateway/test_content_actions.py with explicit
    pass-with-N-options coverage (≥2 floor; 3-option case green).

G5 — i_will_plan now persists sub_tasks alongside approach / risks /
open_questions / technical_considerations. The Plan tab's Sub-Tasks
section was empty because the verb didn't accept the field. Choreographer
server-assigns id + order to each sub_task (pre-gateway build_plan_data
parity) and normalizes every list entry to the EXACT shape
`panel/src/types/index.ts::TaskPlan` consumes:
  - SubTask: {id, title, description, completed:false, order,
    estimated_hours:null, notes:null}
  - Risk: {description, mitigation, severity:null} — accepts the
    {risk, mitigation} pre-gateway shape too
  - OpenQuestion: {question, answer:null, answered_by:null,
    answered_at:null} — accepts a bare string fallback
The normalization lives in three small module-level helpers
(_normalize_sub_task / _normalize_risk / _normalize_open_question)
called from _build_panel_shaped_plan, keeping i_will_plan's branch
count under PLR0912.

G6 — new `channels()` verb returns the agent's readable + writable
channel slugs from foundation.policy.communications. Stops invented
slugs ("backend-dev", "backend") that we kept seeing in smoke runs.
Added to every role's manifest including auditor (read-only access).

Wired through:
- roboco/api/schemas/v2/do.py — list-typed consequences/next_steps,
  dict-typed options, ChannelsRequest
- roboco/api/schemas/v2/flow.py — IWillPlanRequest.sub_tasks
- roboco/api/routes/v2/do.py — /channels endpoint
- roboco/api/routes/v2/flow_*.py — pass sub_tasks through
- roboco/services/gateway/content_actions.py — channels() method;
  _check_scope_required_fields enforces decision/reflect structure;
  _render_option_block emits per-option markdown blocks
- roboco/services/gateway/choreographer/_impl.py — _build_panel_shaped_plan
  helper used by i_will_plan
- roboco/services/gateway/role_config.py — _CHANNEL_DISCOVERY tuple
  on every role
- roboco/mcp/do_server.py — channels() tool + note() signature with
  options as list[dict[str,str]]
- roboco/mcp/flow_server.py — i_will_plan signature with sub_tasks

Frontend: no code change. panel/src/types/index.ts already declares
the exact shape we now write; panel/src/components/tasks/task-detail/
{tab-plan,tab-progress,tab-sessions,tab-notes}.tsx already reads it.
The empty panels we observed were a backend write-side problem, not
a frontend read-side problem — Wave 1 + Wave 2 close it.

Quality: ruff + mypy clean. 505 unit tests pass (added 2 new tests on
decision-scope requirements, updated 3 existing tests to fit the
pre-gateway-parity contract).

Spec ref: docs/superpowers/specs/2026-05-11-pre-gateway-parity-design.md
2026-05-11 05:57:57 +02:00

176 lines
4.7 KiB
Python

"""Cell PM intent-verb HTTP endpoints. Thin handlers; delegate to Choreographer."""
from typing import Annotated
from uuid import UUID
from fastapi import APIRouter, Depends, Header, Request
from roboco.api.deps import get_choreographer
from roboco.api.routes.v2._role_dep import envelope_to_response, require_cell_pm
from roboco.api.schemas.v2.flow import (
CompleteRequest,
DelegateRequest,
EscalateUpRequest,
GiveMeWorkRequest,
IAmIdleRequest,
IWillPlanRequest,
ResumeRequest,
SubmitUpRequest,
TriageRequest,
UnblockRequest,
UnclaimRequest,
)
from roboco.services.gateway.choreographer import Choreographer, DelegateInputs
router = APIRouter(
prefix="/api/v2/flow/cell_pm",
tags=["v2-flow-cell-pm"],
dependencies=[require_cell_pm],
)
_AgentIdHeader = Annotated[UUID, Header(alias="X-Agent-ID")]
_ChoreographerDep = Annotated[Choreographer, Depends(get_choreographer)]
@router.post("/give_me_work")
async def give_me_work(
request: Request,
_body: GiveMeWorkRequest,
x_agent_id: _AgentIdHeader,
choreographer: _ChoreographerDep,
) -> dict:
env = await choreographer.pm_give_me_work(x_agent_id)
return envelope_to_response(env, request)
@router.post("/i_will_plan")
async def i_will_plan(
request: Request,
body: IWillPlanRequest,
x_agent_id: _AgentIdHeader,
choreographer: _ChoreographerDep,
) -> dict:
env = await choreographer.i_will_plan(
x_agent_id,
body.task_id,
body.plan,
rich_plan={
"approach": body.approach,
"sub_tasks": body.sub_tasks,
"technical_considerations": body.technical_considerations,
"risks": body.risks,
"open_questions": body.open_questions,
},
)
return envelope_to_response(env, request)
@router.post("/delegate")
async def delegate(
request: Request,
body: DelegateRequest,
x_agent_id: _AgentIdHeader,
choreographer: _ChoreographerDep,
) -> dict:
inputs = DelegateInputs(
title=body.title,
description=body.description,
assigned_to=body.assigned_to,
team=body.team,
task_type=body.task_type,
nature=body.nature,
acceptance_criteria=body.acceptance_criteria,
estimated_complexity=body.estimated_complexity,
)
env = await choreographer.delegate(x_agent_id, body.parent_task_id, inputs)
return envelope_to_response(env, request)
@router.post("/submit_up")
async def submit_up(
request: Request,
body: SubmitUpRequest,
x_agent_id: _AgentIdHeader,
choreographer: _ChoreographerDep,
) -> dict:
env = await choreographer.submit_up(x_agent_id, body.task_id, body.notes)
return envelope_to_response(env, request)
@router.post("/triage")
async def triage(
request: Request,
_body: TriageRequest,
x_agent_id: _AgentIdHeader,
choreographer: _ChoreographerDep,
) -> dict:
env = await choreographer.triage(x_agent_id)
return envelope_to_response(env, request)
@router.post("/unblock")
async def unblock(
request: Request,
body: UnblockRequest,
x_agent_id: _AgentIdHeader,
choreographer: _ChoreographerDep,
) -> dict:
env = await choreographer.unblock(x_agent_id, body.task_id, restore=body.restore)
return envelope_to_response(env, request)
@router.post("/complete")
async def complete(
request: Request,
body: CompleteRequest,
x_agent_id: _AgentIdHeader,
choreographer: _ChoreographerDep,
) -> dict:
env = await choreographer.complete(x_agent_id, body.task_id, body.notes)
return envelope_to_response(env, request)
@router.post("/escalate_up")
async def escalate_up(
request: Request,
body: EscalateUpRequest,
x_agent_id: _AgentIdHeader,
choreographer: _ChoreographerDep,
) -> dict:
env = await choreographer.escalate_up(x_agent_id, body.task_id, body.reason)
return envelope_to_response(env, request)
@router.post("/unclaim")
async def unclaim(
request: Request,
body: UnclaimRequest,
x_agent_id: _AgentIdHeader,
choreographer: _ChoreographerDep,
) -> dict:
env = await choreographer.unclaim(x_agent_id, body.task_id)
return envelope_to_response(env, request)
@router.post("/resume")
async def resume(
request: Request,
body: ResumeRequest,
x_agent_id: _AgentIdHeader,
choreographer: _ChoreographerDep,
) -> dict:
env = await choreographer.resume(x_agent_id, body.task_id)
return envelope_to_response(env, request)
@router.post("/i_am_idle")
async def i_am_idle(
request: Request,
_body: IAmIdleRequest,
x_agent_id: _AgentIdHeader,
choreographer: _ChoreographerDep,
) -> dict:
env = await choreographer.i_am_idle(x_agent_id)
return envelope_to_response(env, request)