| 1 | import type { DecisionSurfaceKind as MockDecisionSurfaceKind } from "../lib/decisionSurfaceMock"; |
| 2 | import type { State } from "../lib/useController"; |
| 3 | import type { ActiveWorkView, WorkspaceConflictView } from "../lib/types"; |
| 4 | |
| 5 | export type AppDecisionSurfaceKind = MockDecisionSurfaceKind | "extension_form"; |
| 6 | |
| 7 | type PendingClose = { tabId: string; work: ActiveWorkView; stopping: boolean } | null; |
| 8 | |
| 9 | /** |
| 10 | * Single footer decision surface precedence. Composer stays mounted |
| 11 | * underneath and is only visually/a11y-hidden so per-session draft caches |
| 12 | * survive. |
| 13 | */ |
| 14 | export function projectDecisionSurface(input: { |
| 15 | approval: State["approval"]; |
| 16 | ask: State["ask"]; |
| 17 | mcpInteraction: State["mcpInteraction"]; |
| 18 | extensionForm: State["extensionForm"]; |
| 19 | workspaceConflict: WorkspaceConflictView | null; |
| 20 | pendingClose: PendingClose; |
| 21 | clearContextPending: boolean; |
| 22 | remote?: boolean; |
| 23 | }): AppDecisionSurfaceKind | null { |
| 24 | // A remote session's prompts and forms are answered by RemoteSessionSurface, |
| 25 | // the one owner of the serve's exact prompt route; a footer copy would be a |
| 26 | // second card whose answer has no local session to reach. |
| 27 | if (!input.remote) { |
| 28 | const prompt = projectPromptSurface(input); |
| 29 | if (prompt) return prompt; |
| 30 | } |
| 31 | if (input.workspaceConflict) return "workspace_conflict"; |
| 32 | if (input.pendingClose) return "close_active"; |
| 33 | if (input.clearContextPending) return "clear_context"; |
| 34 | return null; |
| 35 | } |
| 36 | |
| 37 | function projectPromptSurface(input: { |
| 38 | approval: State["approval"]; |
| 39 | ask: State["ask"]; |
| 40 | mcpInteraction: State["mcpInteraction"]; |
| 41 | extensionForm: State["extensionForm"]; |
| 42 | }): AppDecisionSurfaceKind | null { |
| 43 | if (input.approval) { |
| 44 | return input.approval.tool === "exit_plan_mode" ? "plan_approval" : "tool_approval"; |
| 45 | } |
| 46 | if (input.ask) return "ask"; |
| 47 | if (input.mcpInteraction) return "mcp_interaction"; |
| 48 | if (input.extensionForm) return "extension_form"; |
| 49 | return null; |
| 50 | } |
| 51 |