feat(secretary): wire task name→id search as a Secretary tool (#304)

The GET /secretary/tasks?q= route (name→id resolution) shipped in wave 1
but no tool called it, so the Secretary could read a task only by UUID —
yet the CEO always refers to tasks by name. This adds search_tasks to
both runtimes (Claude SDK build_secretary_options + the grok
roboco-secretary MCP server) over a shared _do_search_tasks helper, so
'the task about X' resolves to concrete ids the CEO can then act on via
read_task or a control_task directive.

_call_backend gains query-param support and now returns the decoded JSON
(object or list) so the search route's list response flows through;
_do_search_tasks wraps matches under 'tasks' and passes error envelopes
straight through. Persona + RAG role doc updated (the RAG doc had
explicitly flagged this gap). Tests cover the helper and both wrappers.

Co-authored-by: Renn F <rennf93@users.noreply.github.com>
This commit is contained in:
Renzo F
2026-07-03 20:07:28 +02:00
committed by GitHub
co-authored by Renn F
parent 3ccc723cd4
commit 607e13f3dd
7 changed files with 122 additions and 17 deletions
@@ -51,6 +51,34 @@ async def test_read_task_calls_backend(monkeypatch: pytest.MonkeyPatch) -> None:
assert out["id"] == "abc"
@pytest.mark.asyncio
async def test_search_tasks_sends_query_and_wraps_list(
monkeypatch: pytest.MonkeyPatch,
) -> None:
_env(monkeypatch)
def handler(request: httpx.Request) -> httpx.Response:
assert request.url.path == "/api/secretary/tasks"
assert request.url.params["q"] == "x account"
assert request.url.params["limit"] == "20"
return httpx.Response(200, json=[{"id": "abc", "title": "X account"}])
out = await sd._do_search_tasks("x account", client=_client(handler))
assert out == {"tasks": [{"id": "abc", "title": "X account"}]}
@pytest.mark.asyncio
async def test_search_tasks_passes_error_through(
monkeypatch: pytest.MonkeyPatch,
) -> None:
_env(monkeypatch)
out = await sd._do_search_tasks(
"q", client=_client(lambda _r: httpx.Response(422, text="too short"))
)
assert "tasks" not in out
assert out["error"] == "http_422"
@pytest.mark.asyncio
async def test_submit_directive_posts_kind_and_payload(
monkeypatch: pytest.MonkeyPatch,
@@ -40,6 +40,23 @@ async def test_read_task_forwards_the_id(monkeypatch: pytest.MonkeyPatch) -> Non
assert json.loads(out)["title"] == "T"
@pytest.mark.asyncio
async def test_search_tasks_forwards_query_and_limit(
monkeypatch: pytest.MonkeyPatch,
) -> None:
seen: dict[str, Any] = {}
async def _search(q: str, limit: int = 20) -> dict[str, Any]:
seen["q"] = q
seen["limit"] = limit
return {"tasks": [{"id": "t1"}]}
monkeypatch.setattr(secretary_server, "_do_search_tasks", _search)
out = await secretary_server.search_tasks("x account", 5)
assert seen == {"q": "x account", "limit": 5}
assert json.loads(out) == {"tasks": [{"id": "t1"}]}
@pytest.mark.asyncio
async def test_submit_directive_forwards_kind_and_payload(
monkeypatch: pytest.MonkeyPatch,