Extract shared buildRunAgentInput() (chat#1813)
PR 3 (api) of the async chat-generation migration tracked in recoupable/chat#1813. Independent of the others — mergeable in parallel.
What
Extracts the RunAgentWorkflowInput construction from handleChatWorkflowStream into a pure, shared lib/chat/buildRunAgentInput.ts. The interactive handler now delegates to it; the upcoming headless /api/chat/generate re-point will call the same builder, so both paths can't drift.
- Repo identifiers (
repoOwner/repoName) andrecoupOrgIdare derived fromclone_urlinside the builder — one source of truth (the handler no longer computes them). recoupAccessTokenis included only when present, preserving the exfiltration boundary (x-api-key callers omit it).
Behavior-preserving
Pure refactor of a live path. The interactive /api/chat/workflow builds identical input as before.
Tests (TDD, RED→GREEN)
- 4 new
buildRunAgentInputunit tests (field pass-through, clone_url-derived ids/org, recoupAccessToken include/omit, null clone_url). - Existing
handleChatWorkflowStreamsuite stays green (20).tsc+ lint clean on touched files.
Done-when (issue item)
- Both callers construct workflow input through one function; no duplication. (Headless caller wired in the re-point PR.)
🤖 Generated with Claude Code
Summary by cubic
Extracted a shared buildRunAgentInput to unify how we construct RunAgentWorkflowInput for interactive /api/chat/workflow and the upcoming headless /api/chat/generate, preventing drift. No behavior changes to the live path; this supports chat#1813.
- Refactors
- Moved input-building logic from
handleChatWorkflowStreamtolib/chat/buildRunAgentInput.ts; the handler now delegates to it. - Derived
repoOwner/repoNameandrecoupOrgIdfromcloneUrlinside the builder as the single source of truth. - Forwarded
recoupAccessTokenonly when provided to preserve the exfiltration boundary (x-api-key callers omit it).
- Moved input-building logic from