Files
roboco/roboco/api/routes/v2/do.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

246 lines
6.2 KiB
Python

"""Content-tool HTTP endpoints. Thin handlers; delegate to ContentActions."""
from typing import Annotated
from uuid import UUID
from fastapi import APIRouter, Depends, Header, Request
from roboco.api.deps import get_content_actions
from roboco.api.routes.v2._role_dep import envelope_to_response
from roboco.api.schemas.v2.do import (
ChannelsRequest,
CommitRequest,
DmRequest,
EvidenceRequest,
LinkSessionRequest,
NoteRequest,
NotifyAckRequest,
NotifyGetRequest,
NotifyListRequest,
NotifyRequest,
OpenSessionRequest,
ProgressRequest,
SayRequest,
)
from roboco.services.gateway.content_actions import ContentActions
router = APIRouter(prefix="/api/v2/do", tags=["v2-do"])
_AgentIdHeader = Annotated[UUID, Header(alias="X-Agent-ID")]
_ContentActionsDep = Annotated[ContentActions, Depends(get_content_actions)]
@router.post("/commit")
async def do_commit(
request: Request,
body: CommitRequest,
x_agent_id: _AgentIdHeader,
actions: _ContentActionsDep,
) -> dict:
env = await actions.commit(
agent_id=x_agent_id,
message=body.message,
files=body.files,
)
return envelope_to_response(env, request)
@router.post("/note")
async def do_note(
request: Request,
body: NoteRequest,
x_agent_id: _AgentIdHeader,
actions: _ContentActionsDep,
) -> dict:
env = await actions.note(
agent_id=x_agent_id,
text=body.text,
scope=body.scope,
task_id=body.task_id,
structured={
"title": body.title,
"context": body.context,
"options": body.options,
"chosen": body.chosen,
"rationale": body.rationale,
"consequences": body.consequences,
"what_done": body.what_done,
"what_learned": body.what_learned,
"what_struggled": body.what_struggled,
"next_steps": body.next_steps,
},
)
return envelope_to_response(env, request)
@router.post("/say")
async def do_say(
request: Request,
body: SayRequest,
x_agent_id: _AgentIdHeader,
actions: _ContentActionsDep,
) -> dict:
env = await actions.say(
agent_id=x_agent_id,
channel=body.channel,
text=body.text,
task_id=body.task_id,
)
return envelope_to_response(env, request)
@router.post("/dm")
async def do_dm(
request: Request,
body: DmRequest,
x_agent_id: _AgentIdHeader,
actions: _ContentActionsDep,
) -> dict:
env = await actions.dm(
agent_id=x_agent_id,
recipient=body.recipient,
text=body.text,
task_id=body.task_id,
skill=body.skill,
)
return envelope_to_response(env, request)
@router.post("/notify")
async def do_notify(
request: Request,
body: NotifyRequest,
x_agent_id: _AgentIdHeader,
actions: _ContentActionsDep,
) -> dict:
env = await actions.notify(
agent_id=x_agent_id,
target=body.target,
text=body.text,
priority=body.priority,
task_id=body.task_id,
)
return envelope_to_response(env, request)
@router.post("/evidence")
async def do_evidence(
request: Request,
body: EvidenceRequest,
x_agent_id: _AgentIdHeader,
actions: _ContentActionsDep,
) -> dict:
env = await actions.evidence(agent_id=x_agent_id, task_id=body.task_id)
return envelope_to_response(env, request)
# ---------------------------------------------------------------------------
# Wave 1 — pre-gateway parity
# ---------------------------------------------------------------------------
@router.post("/progress")
async def do_progress(
request: Request,
body: ProgressRequest,
x_agent_id: _AgentIdHeader,
actions: _ContentActionsDep,
) -> dict:
env = await actions.progress(
agent_id=x_agent_id,
task_id=body.task_id,
message=body.message,
percentage=body.percentage,
)
return envelope_to_response(env, request)
@router.post("/open_session")
async def do_open_session(
request: Request,
body: OpenSessionRequest,
x_agent_id: _AgentIdHeader,
actions: _ContentActionsDep,
) -> dict:
env = await actions.open_session(
agent_id=x_agent_id,
task_id=body.task_id,
channel=body.channel,
topic=body.topic,
relationship_type=body.relationship_type,
group_id=body.group_id,
)
return envelope_to_response(env, request)
@router.post("/link_session")
async def do_link_session(
request: Request,
body: LinkSessionRequest,
x_agent_id: _AgentIdHeader,
actions: _ContentActionsDep,
) -> dict:
env = await actions.link_session(
agent_id=x_agent_id,
session_id=body.session_id,
task_id=body.task_id,
is_primary=body.is_primary,
relationship_type=body.relationship_type,
)
return envelope_to_response(env, request)
@router.post("/notify_list")
async def do_notify_list(
request: Request,
body: NotifyListRequest,
x_agent_id: _AgentIdHeader,
actions: _ContentActionsDep,
) -> dict:
env = await actions.notify_list(
agent_id=x_agent_id,
unread_only=body.unread_only,
pending_ack_only=body.pending_ack_only,
limit=body.limit,
)
return envelope_to_response(env, request)
@router.post("/notify_get")
async def do_notify_get(
request: Request,
body: NotifyGetRequest,
x_agent_id: _AgentIdHeader,
actions: _ContentActionsDep,
) -> dict:
env = await actions.notify_get(
agent_id=x_agent_id,
notification_id=body.notification_id,
)
return envelope_to_response(env, request)
@router.post("/notify_ack")
async def do_notify_ack(
request: Request,
body: NotifyAckRequest,
x_agent_id: _AgentIdHeader,
actions: _ContentActionsDep,
) -> dict:
env = await actions.notify_ack(
agent_id=x_agent_id,
notification_id=body.notification_id,
)
return envelope_to_response(env, request)
@router.post("/channels")
async def do_channels(
request: Request,
_body: ChannelsRequest,
x_agent_id: _AgentIdHeader,
actions: _ContentActionsDep,
) -> dict:
env = await actions.channels(agent_id=x_agent_id)
return envelope_to_response(env, request)