/** * Fixture data for the web-console visual harness (`scripts/ui-mock-server.mjs` * + `scripts/ui-shots.mjs`). * * Shapes are taken from `web/src/lib/api.ts` and `src/protocol/types.ts` — the * wire contract, not a UI model. Two families deliberately coexist: * * - REST history entries are **raw pi entries** (`message` / `toolResult` / * `custom`), which `web/src/lib/entry-projection.ts` projects. That is the * real `GET /api/v1/sessions/:sid/entries` payload. * - `state.entries` (only used by the legacy session) carries **Block-shaped** * entries, including the pre-0.2 tool DTO (`input` / `result` / `text` / * `diff`) that `tools/adapt.ts` has to keep working. * * Nothing here talks to a daemon, a plugin or the network. */ /** Local CLI token the mock accepts for `POST /api/v1/console/session`. */ export const MOCK_CLI_TOKEN = "mock-cli-token-0000000000000000000000"; /** Device token the mock mints for the local browser (base64url-ish, ≥20 chars). */ export const MOCK_DEVICE_TOKEN = "mock-device-token-0000000000000000000000"; /** Second device token (a phone that paired earlier). */ export const MOCK_PHONE_TOKEN = "mock-phone-token-11111111111111111111111"; export const MOCK_DAEMON_ID = "d-mock-0f3a9c"; const MINUTE = 60_000; /** * 21×21 module grid for the mock pairing code (`rows` are `"0"`/`"1"` strings, * no quiet zone). This is **not** a real QR encoding — the daemon's encoder * lives in `src/core/qr.ts`; the harness only needs a plausible grid with the * three finder patterns so the status page renders a real matrix. */ function mockQrRows(text, size = 21) { const grid = Array.from({ length: size }, () => Array.from({ length: size }, () => "0")); const finder = (ox, oy) => { for (let y = 0; y < 7; y += 1) { for (let x = 0; x < 7; x += 1) { const ring = x === 0 || y === 0 || x === 6 || y === 6; const core = x >= 2 && x <= 4 && y >= 2 && y <= 4; grid[oy + y][ox + x] = ring || core ? "1" : "0"; } } }; finder(0, 0); finder(size - 7, 0); finder(0, size - 7); let state = 2166136261; for (const char of text) state = (state * 31 + char.charCodeAt(0)) >>> 0; for (let y = 0; y < size; y += 1) { for (let x = 0; x < size; x += 1) { const inFinder = (x < 8 && y < 8) || (x > size - 9 && y < 8) || (x < 8 && y > size - 9); if (inFinder) continue; state = (state * 1103515245 + 12345) >>> 0; grid[y][x] = state % 100 < 48 ? "1" : "0"; } } return grid.map((row) => row.join("")); } /** Fixed "now" for the running instance; callers may override. */ export function buildFixtures(now = Date.now()) { const iso = (ts) => new Date(ts).toISOString(); const t0 = now - 42 * MINUTE; /* ---------------------------------------------------------------- */ /* raw pi entries: helpers */ /* ---------------------------------------------------------------- */ const userEntry = (id, ts, text) => ({ type: "message", id, timestamp: iso(ts), message: { role: "user", timestamp: ts, content: [{ type: "text", text }] }, }); const assistantEntry = (id, ts, content, extra = {}) => ({ type: "message", id, timestamp: iso(ts), message: { role: "assistant", timestamp: ts, content, ...extra }, }); const toolCall = (id, name, args) => ({ type: "toolCall", id, name, arguments: args }); const toolResult = (id, ts, { toolCallId, toolName, text, isError = false, details }) => ({ type: "message", id, timestamp: iso(ts), message: { role: "toolResult", toolCallId, toolName, timestamp: ts, content: [{ type: "text", text }], isError, ...(details !== undefined ? { details } : {}), }, }); const todoCheckpoint = (id, ts, todos) => ({ type: "custom", id, timestamp: iso(ts), customType: "pi2-todo", data: { todos, completed: todos.filter((todo) => todo.status === "completed").length, total: todos.length, }, }); /* ---------------------------------------------------------------- */ /* todo / task / batch / subagent state */ /* ---------------------------------------------------------------- */ const MAIN_TODOS = [ { content: "Port v0.1.1 tokens (light/dark)", status: "completed", activeForm: "Porting tokens" }, { content: "Replace .tabbar with the 56px nav rail", status: "in_progress", activeForm: "Replacing .tabbar" }, { content: "Tool family renderer for 22 tools", status: "in_progress", activeForm: "Rendering tool families" }, { content: "Visual harness: mock API + screenshots", status: "pending", activeForm: "Building the visual harness" }, ]; const MAIN_TASKS = [ { id: "task-1", command: "pnpm --dir web build", status: "running", startTime: now - 38_000, durationMs: 38_000, exitCode: null, outputFile: "/tmp/pi2-mock/tasks/task-1.log", }, { id: "task-2", command: "bash scripts/smoke.sh", status: "completed", startTime: now - 9 * MINUTE, durationMs: 41_200, exitCode: 0, outputFile: "/tmp/pi2-mock/tasks/task-2.log", }, { id: "task-3", command: "pnpm --dir web exec vitest run tests/tools.kind.test.tsx", status: "failed", startTime: now - 21 * MINUTE, durationMs: 7_640, exitCode: 1, }, ]; const MAIN_BATCHES = [ { batchId: "batch-1", status: "running", items: [ { ref: "sa-shell", name: "WS-A shell", status: "running" }, { ref: "sa-workspaces", name: "WS-B pages", status: "ok" }, { ref: "sa-tools", name: "WS-C tools", status: "failed", error: "typecheck: 2 errors" }, { ref: "sa-stream", name: "WS-E stream", status: "queued" }, ], summary: { total: 4, done: 2, ok: 1, failed: 1, cancelled: 0, running: 1 }, }, { batchId: "batch-0", status: "partial", items: [ { ref: "sa-audit", name: "contract audit", status: "ok" }, { ref: "sa-digest", name: "digest pass", status: "cancelled" }, ], summary: { total: 2, done: 2, ok: 1, failed: 0, cancelled: 1, running: 0 }, }, ]; const MAIN_SUBAGENTS = [ { id: "sa-shell", name: "WS-A shell", status: "active", model: "claude-sonnet-4.5", thinking: "high", task: "Rewrite tokens + nav rail, drop .tabbar", createdAt: t0 + 2 * MINUTE, lastActiveAt: now - 12_000, live: true, visible: true, parentId: "s-main", children: [ { id: "sa-tokens", name: "tokens.css", status: "completed", model: "claude-sonnet-4.5", task: "Swap the three-stage token set", createdAt: t0 + 3 * MINUTE, lastActiveAt: now - 14 * MINUTE, visible: true, }, { id: "sa-palette", name: "⌘K palette", status: "failed", model: "claude-sonnet-4.5", task: "Esc must restore focus to the trigger", createdAt: t0 + 5 * MINUTE, lastActiveAt: now - 8 * MINUTE, visible: true, }, ], }, { id: "sa-tools", name: "WS-C tools", status: "dormant", model: "gpt-5.1-codex", thinking: "medium", task: "22 tool names → 4 display states", createdAt: t0 + 9 * MINUTE, lastActiveAt: now - 6 * MINUTE, live: false, visible: false, parentId: "s-main", }, { id: "sa-stream", name: "WS-E stream", status: "interrupted", task: "queued messages render once", createdAt: t0 + 12 * MINUTE, lastActiveAt: now - 3 * MINUTE, visible: true, }, ]; /** * Pending `confirm` attention. It hangs off `s-attention` (never the session * the screenshot matrix opens) because the console's attention modal is * blocking by design: putting it on `s-main` would hide the chat page behind * a dialog that only an answer or a timeout can close. */ const MAIN_ATTENTION = [ { requestId: "att-1", method: "confirm", title: "Allow `write` to docs/ui-parity.md?", message: "The agent wants to create the harness documentation inside the repo.", options: [ { id: "allow_once", label: "Allow once" }, { id: "allow_session", label: "Allow for this session" }, { id: "deny", label: "Deny" }, ], createdAt: now - 40_000, receivedAt: now - 39_500, timeoutSec: 120, }, ]; const MAIN_QUEUE = [ { id: "q-1", text: "Also assert the /connect page has no server chip.", steer: false }, { id: "q-2", text: "Re-run the matrix once WS-A lands.", steer: true }, ]; /* ---------------------------------------------------------------- */ /* history: the main session */ /* ---------------------------------------------------------------- */ const mainEntries = [ userEntry("e-01", t0, "Port the v0.1.1 shell. Do not touch the wire protocol, and keep the old DTO working."), assistantEntry("e-02", t0 + 20_000, [ { type: "thinking", thinking: "Three invariants decide this: the protocol stays put, tools degrade on old fields, and the nav rail replaces .tabbar below 600px.", }, { type: "text", text: "Plan: tokens first, then the shell, then the tool families. I re-read `docs/protocol.md` §3.3 before touching anything.", }, toolCall("call-bash-1", "bash", { command: "pnpm --dir web typecheck", description: "baseline typecheck", timeout: 120_000, }), ]), toolResult("e-03", t0 + 26_000, { toolCallId: "call-bash-1", toolName: "bash", text: "> tsc --noEmit\n\n(no output)\nexit 0", details: { exitCode: 0, durationMs: 5_420 }, }), assistantEntry("e-04", t0 + 30_000, [ { type: "text", text: "Baseline is green. Now the token swap — the shorthand names stay, only the values move.", }, toolCall("call-edit-1", "edit", { path: "web/src/styles/tokens.css", oldText: " --tabbar-h: 3.75rem;\n --topbar-h: 3.25rem;", newText: " --topbar-h: 3.25rem;\n --rail-w: 3.5rem;", }), ]), toolResult("e-05", t0 + 31_500, { toolCallId: "call-edit-1", toolName: "edit", text: "Applied 1 edit to web/src/styles/tokens.css", details: { path: "web/src/styles/tokens.css", additions: 1, deletions: 1 }, }), assistantEntry("e-06", t0 + 40_000, [ { type: "text", text: "Removing the tabbar variable breaks three rules; let me find every consumer.", }, toolCall("call-grep-1", "grep", { pattern: "tabbar", path: "web/src", ignoreCase: true, }), ]), toolResult("e-07", t0 + 41_000, { toolCallId: "call-grep-1", toolName: "grep", text: [ "web/src/styles/app.css:106 /* tabbar <600 */", "web/src/styles/app.css:107 .tabbar {", "web/src/styles/app.css:131 .main { padding-bottom: calc(var(--tabbar-h) + var(--space-6)); }", "web/src/styles/pages/chat.css:1079 height: calc(100dvh - var(--topbar-h) - var(--tabbar-h));", "web/src/components/app-shell.tsx:251