import { activeQuestionRequest, questionPendingDocument } from "@opencode/session-ui/storybook" import type { FormInfo } from "@opencode/client/promise" import { SessionPreview } from "./story-model" import { SessionQuestionDockClassic } from "./requests/session-question-dock-classic" export default { title: "OpenCode/Session/Question switch", id: "session-question-switch", component: SessionPreview, parameters: { layout: "fullscreen", docs: { description: { component: "The question dock in its classic form and in the New question UI experiment, which answers from the composer.", }, }, }, } // Questions of different lengths, with and without answer descriptions, ending in a text-only one. const composerAnswerRequest = { ...activeQuestionRequest, fields: [ ...activeQuestionRequest.fields, { key: "open", type: "string", title: "Open automatically", description: "Open it automatically?", options: [ { value: "manual", label: "Only when I ask" }, { value: "ready", label: "When changes are ready", description: "Open it after a session edits files." }, ], custom: true, }, { key: "narrow", type: "string", title: "Small windows", description: "On a small window, the review panel competes with the transcript and the file tree for space. People may be reading a long diff, checking the session’s explanation, or jumping between files. How should the panel behave when there isn’t room to keep all three surfaces visible at once?", options: [ { value: "overlay", label: "Open review over the transcript", description: "Keep the file tree visible so people can move between changed files without leaving review.", }, { value: "replace", label: "Replace both the transcript and the file tree with a full-width review", description: "Give the diff the whole window. Back returns to the same transcript position and restores the file tree exactly as it was.", }, { value: "collapse", label: "Collapse the file tree" }, ], custom: true, }, { key: "filters", type: "multiselect", title: "Review filters", description: "Which filters should be available in the review panel?", options: [ { value: "staged", label: "Staged changes", description: "Show what will go into the next commit." }, { value: "unstaged", label: "Unstaged changes" }, { value: "added", label: "New files" }, { value: "deleted", label: "Deleted files" }, { value: "renamed", label: "Renamed files" }, { value: "generated", label: "Generated files and lockfiles", description: "Review these separately from hand-written changes.", }, { value: "tests", label: "Test files" }, { value: "docs", label: "Documentation" }, { value: "unread", label: "Files I haven’t reviewed yet" }, { value: "commented", label: "Files with unresolved comments" }, ], }, { key: "empty", type: "string", title: "Empty state", description: "What should the panel say when there’s nothing to review?", custom: true, }, ], } satisfies FormInfo export const ComposerAnswer = { name: "New question UI", globals: { theme: "dark" }, parameters: { docs: { description: { story: "Focus stays in the composer: ↑ and ↓ highlight an answer, Space or its number marks it, and typing writes a custom answer. Answering or dismissing restores the chat draft. Use Reset to try again.", }, }, }, render: () => ( ( finish( action.type === "reply" ? `Answered locally: ${JSON.stringify(action.answer)}` : "Dismissed the question locally", ) } /> )} /> ), } // Several questions of different lengths and kinds in a row. export const QuestionSeries = { render: () => ( ), } // A question whose text includes a URL to open before answering. export const LinkPrompt = { render: () => ( ), } // A pick-any question with more answers than the dock has room for, then a short one. export const LongList = { render: () => ( ), } const longMobileOptions = [ { value: "opt-1", label: "1. Incremental schema migration with dual-read verification (Recommended)", description: "Backfill every existing session row in bounded batches while reading from both tables and logging any mismatch before cutover.", }, { value: "opt-2", label: "2. Blue-green SQLite snapshot swap on daemon restart", description: "Build a fresh projected database beside the live file during idle windows and atomically swap file descriptors once parity holds.", }, { value: "opt-3", label: "3. Lazy per-session hydration on first transcript open", description: "Leave historical sessions untouched at startup and upgrade each transcript inside a single write transaction when opened.", }, { value: "opt-4", label: "4. Shadow journal replay from durable event log", description: "Replay ordered session aggregate events into a new read-model table in the background without blocking active prompt drains.", }, { value: "opt-5", label: "5. Read-only archive boundary for legacy schema versions", description: "Keep older transcripts viewable through a frozen decoder while writing all newly admitted prompts exclusively to the v4 tables.", }, { value: "opt-6", label: "6. Checkpoint compaction before running structural DDL", description: "Truncate the write-ahead log, vacuum dead pages, and verify foreign-key integrity prior to adding the new composite indexes.", }, { value: "opt-7", label: "7. Partitioned attachment metadata with external blob refs", description: "Move inline base64 tool outputs into content-addressed files on disk so mobile queries never scan oversized row payloads.", }, { value: "opt-8", label: "8. Staged rollout gated by workspace recovery marker", description: "Enable the new projection only after all claimed top-level sessions finish draining cleanly without pending inbox items.", }, { value: "opt-9", label: "9. Deterministic fixture verification before live migration", description: "Clone the workspace header and sample fifty recent conversations into a temporary file to benchmark query plans first.", }, { value: "opt-10", label: "10. Reversible trigger mirror between v3 and v4 columns", description: "Install temporary SQLite triggers that keep old and new columns synchronized so an older binary can still open the workspace.", }, { value: "opt-11", label: "11. Offline CLI migration subcommand with progress bar", description: "Require explicit operator confirmation via opencode db migrate and refuse automatic background writes on startup.", }, { value: "opt-12", label: "12. Clean slate rebuild of derived read projections only", description: "Drop disposable summary caches and rebuild every read projection directly from the canonical event history on boot.", }, ] const tallMobilePrompt = [ "Before I run the workspace storage migration on this repository, please review the full rollout plan and confirm how failure recovery should behave if the connection drops mid-run.", "Step 1 inspects the active SQLite write-ahead log, verifies that no other local coordinator currently holds a busy execution claim, and records the starting event sequence number in a durable checkpoint row.", "Step 2 scans session_inbox for any unconsumed user or synthetic items so steered prompts admitted right before shutdown remain preserved in exact enqueue order without duplicate delivery.", "Step 3 creates the new normalized message part tables beside the existing transcript projection, keeping every original row intact until row counts, byte checksums, and foreign-key constraints match across all sessions.", "Step 4 streams large diff and terminal output blobs out of inline JSON columns into content-addressed storage files, preventing multi-megabyte rows from stalling mobile timeline queries over remote tunnels.", "Step 5 rebuilds the full-text search index and session summary projections in slices of twenty-five conversations per transaction, yielding between slices so interactive HTTP requests and live SSE updates stay responsive.", "Step 6 validates cursor pagination from both ends of the longest session timeline, checking that sticky tool headers, collapsed reasoning blocks, and pending permission or question docks restore to identical state.", "Step 7 writes a reversible compatibility view so older CLI processes inspecting the same directory fail gracefully with a clear upgrade message rather than corrupting partially migrated state.", "Step 8 runs PRAGMA integrity_check and compares aggregate token, cost, and tool-call totals before and after the projection swap to catch any silent truncation in historical metadata.", "Step 9 retains the pre-migration backup snapshot in the cache directory for seven days so you can roll back with a single command if any downstream script or plugin depends on the legacy layout.", "Step 10 revalidates workspace permissions, active MCP server tool bindings, and pending form or elicitation state so an in-flight agent session resumes cleanly without re-prompting for completed answers.", "Step 11 checks disk free space on both the database volume and temporary directory before committing the final rename, ensuring low-storage mobile hosts and containers never wedge mid-checkpoint.", "Step 12 emits a structured migration summary event with elapsed wall time, migrated row counts, reclaimed page bytes, and fallback instructions for operators monitoring remote headless servers.", "If a power loss, SIGKILL, or mobile network timeout interrupts any of these steps before the final checkpoint commits, how should the server handle the unfinished migration when it starts back up?", ].join(" ") // Twelve verbose options followed by a question prompt taller than a phone viewport. export const LongPrompt = { render: () => ( ), } export const FreeResponse = { render: () => ( ), }