// The made-up workspace the README's screens show: no real session, person, path or address. // `bun fixtures.ts` writes it to ./fake (OUT=… for elsewhere); `bun serve.ts` serves it. import {mkdirSync, writeFileSync} from 'fs' const OUT = process.env.OUT ?? 'fake', now = Math.floor(Date.now() / 1000), H = 3600, D = 86400 mkdirSync(OUT, {recursive: true}) let seed = 7; const rnd = () => ((seed = (seed * 16807) % 2147483647) / 2147483647) const pick = (a: T[]) => a[Math.floor(rnd() * a.length)] const hex = (n = 40) => Array.from({length: n}, () => '0123456789abcdef'[Math.floor(rnd() * 16)]).join('') const iso = (t: number) => new Date(t * 1000).toISOString() const w = (name: string, v: unknown) => writeFileSync(`${OUT}/${name}.json`, JSON.stringify(v)) const PROJECTS = ['storefront', 'mobile', 'docs'] const NODES = [ {id: 'build-1', machine: 'server', address: '10.10.0.1', renderer: 'llvmpipe (CPU), midas node', gpu: false, cpus: 8, free: 64e9, load: 3.1}, {id: 'mac-1', machine: 'studio', address: '10.10.0.2', renderer: 'Apple M4 Pro (VM)', gpu: false, cpus: 8, free: 112e9, load: 2.4}, {id: 'mac-2', machine: 'studio', address: '10.10.0.2', renderer: 'Apple M4 Pro (VM)', gpu: false, cpus: 8, free: 108e9, load: 0.3}, {id: 'gpu-1', machine: 'tower', address: '10.10.0.3', renderer: 'AMD Radeon RX 7800 (RADV) -- hardware GPU', gpu: true, cpus: 12, free: 240e9, load: 0.1}, ] const MAIN = hex() // [id, title, project, status, doing, node, created ago, active ago] const RUNNING: [string, string, string, string, string | null, string | null, number, number][] = [ ['s212', 'Remember the last delivery address at checkout', 'storefront', 'working', 'Running the tests on build-1', 'build-1', 40 * 60, 20], ['s211', 'Faster product search', 'storefront', 'waiting', null, null, 2 * H, 3 * 60], ['s210', 'Dark mode for the order history', 'mobile', 'needs_permission', 'Waiting for you', 'mac-1', 90 * 60, 6 * 60], ['s209', 'Getting-started guide for the API', 'docs', 'working', 'Editing docs/api/quickstart.md', null, 25 * 60, 40], ] const DONE: [string, string, string, number][] = [ ['s208', 'Round invoice prices to the cent, not per line', 'storefront', 5 * H], ['s207', 'Push notifications when an order ships', 'mobile', 9 * H], ['s206', 'Fix the broken links in the changelog', 'docs', 20 * H], ['s205', 'Coupon codes that expire', 'storefront', 30 * H], ['s204', 'Smaller app icons on Android', 'mobile', 2 * D], ['s203', 'Stock levels on the product page', 'storefront', 3 * D], ['s202', 'Translate the FAQ into Dutch', 'docs', 4 * D], ['s201', 'Retry failed payments once', 'storefront', 5 * D], ] const entities: Record = {} const hosted = (id: string, title: string, project: string, status: string, doing: string | null, created: number, active: number, finished: unknown) => (entities[`hosted:${id}`] = {active, archived: null, back: null, base: 'main', branch: `session/${id}`, by: 'web:sam', created, deploys: [], doing, finish: null, finished, handed: null, id, imported: null, kind: 'hosted', local: null, owner: `session-${id}`, queue: [], status, title, updated: active, repo: `acme/${project}`}) for (const [id, title, project, status, doing, node, ago, act] of RUNNING) { hosted(id, title, project, status, doing, now - ago, now - act, null) entities[`card:session-${id}`] = {active: now - act, badges: {decisions: [], notes: 0, overlaps: 0}, branch: `session/${id}`, busy: status === 'working', gate: false, intent: null, kind: 'card', label: title, last_command: node ? 'cargo test --workspace' : null, link: null, node, node_gate: false, position: null, purpose: null, repo: `acme/${project}`, session: `session-${id}`, since: now - ago, stage: node ? 'on_node' : 'working'} } // The sessions runner (runners.rs): up, or with AWAY=1 away for the last nine minutes, its sessions paused. const AWAY = process.env.AWAY ? now - 9 * 60 : null entities['runner:runner@server'] = {away: AWAY, id: 'runner@server', kind: 'runner', name: 'runner@server'} if (AWAY) for (const [id, , , status] of RUNNING) if (status !== 'stopped') (entities[`hosted:${id}`] as Record).runner_away = AWAY for (const [id, title, project, ago] of DONE) { const sha = hex(), at = now - ago hosted(id, title, project, 'stopped', null, at - 3 * H, at, {at, live_at: at + 600, outcome: 'landed', sha}) if (ago < D) entities[`card:session-${id}`] = {active: null, badges: {decisions: [], notes: 0, overlaps: 0}, branch: `session/${id}`, kind: 'card', label: title, link: null, live: true, node: null, position: null, repo: `acme/${project}`, session: `session-${id}`, sha, since: at, stage: 'landed'} } const lease = (n: string, owner: string) => ({branch: `session/${owner.slice(8)}`, builds: 3, claimed_at: now - 30 * 60, contact_at: now - 30, last_active: now - 20, last_command: 'cargo test --workspace', mode: 'build', owner, renewed_at: now - 20, ttl: 7200}) const leases = {'build-1': lease('build-1', 'session-s212'), 'mac-1': lease('mac-1', 'session-s210')} for (const n of NODES) entities[`node:${n.id}`] = {drained: null, holder: (leases as any)[n.id]?.owner ?? null, id: n.id, kind: 'node', load: n.load, machine: n.machine, online: true, renderer: n.renderer, service: false, since: now - 30 * 60, version: 'a1b2c3d4'} const snapshot = {entities, type: 'snapshot', version: 1} // The conversation of s208, which asked to land. let n = 0; const T0 = now - 5 * H - 3 * H const item = (dt: number, o: Record) => ({at: T0 + dt, n: ++n, ...o}) const tool = (dt: number, title: string, output: string) => { const id = 'toolu_' + hex(20) return [item(dt, {id, input: {}, kind: 'tool', parent: null, status: 'pending', title}), item(dt + 2, {id, kind: 'tool_update', output, status: 'completed'})] } const log = [ item(0, {kind: 'mode', current: 'acceptEdits'}), item(1, {kind: 'user', by: 'web:sam', text: 'Invoices round every line to the cent, so a 3-line order can be a cent off the total. Round once, at the end.'}), ...tool(5, 'Read src/invoice/total.rs', ''), ...tool(9, 'Grep: round\\( in src/invoice', ''), item(15, {kind: 'agent', text: 'Each line goes through `round_cents` before the sum, in `total.rs`. I\'ll keep lines exact and round the total once, and add a test with the three-line order from the bug report.'}), ...tool(20, 'Edit src/invoice/total.rs', ''), ...tool(26, 'Edit src/invoice/tests.rs', ''), ...tool(40, 'Bash: ssh build-1 \'cargo test -p invoice\'', 'test result: ok. 48 passed; 0 failed'), item(60, {kind: 'agent', text: 'The totals now round once. 48 tests pass on build-1, the new one among them; it failed before the change.'}), item(62, {kind: 'question', request: '1', message: 'Shall it land? Invoice totals round once, at the end, instead of per line. Tests pass on build-1.', schema: {properties: {question_0: {oneOf: [ {const: 'Land it and finish (Recommended)', title: 'Land it and finish (Recommended)', description: 'Lands after the check passes; this session ends once it is live'}, {const: 'Land it, keep working', title: 'Land it, keep working', description: 'Lands; this session stays open'}, {const: 'Not yet', title: 'Not yet', description: 'Tell me what to change first'}, ], title: 'Land', type: 'string'}}, required: ['question_0'], type: 'object'}}), item(200, {kind: 'answered', action: 'accept', by: 'web:sam', request: '1', content: {question_0: 'Land it and finish (Recommended)'}}), ...tool(205, 'Bash: ~/.claude/skills/finish-branch/land --finish', 'landed: main is at ' + MAIN.slice(0, 8)), item(400, {kind: 'agent', text: 'Landed on main. The storefront deploys with the next batch.'}), item(401, {kind: 'turn_end', reason: 'end_turn'}), item(500, {kind: 'finishing', sha: MAIN}), item(1000, {kind: 'finished', live_at: T0 + 1000, outcome: 'landed', sha: MAIN}), ] const logMsg = {items: log, next: n + 1, session: 's208', type: 'log'} w('stream', [JSON.stringify(snapshot), JSON.stringify(logMsg)]) // HTTP reads. w('_v1_caller', {account: 'sam', caller: null, role: 'admin'}) w('_v1_health', {disk_free: 80e9, ok: true, recipe: 'a1b2c3d4', version: 'a1b2c3d4'}) w('_v1_hosted_discuss', {available: true}) w('_v1_decisions', []) w('_v1_todos', [{at: now - 3 * H, by: 'web:sam', for: 'agent', id: 't4', text: 'Add a sitemap to the docs site'}]) w('_v1_hosted_projects', PROJECTS.map((p) => ({git: `ssh://git@git.example.org/acme/${p}.git`, name: p, repo: `acme/${p}`}))) w('_v1_reservations', {migration: {by: {'31': {at: now - D, owner: 'session-s205', why: 'coupon expiry'}}, last: 31}}) const names: Record = {} for (const [id, title] of [...RUNNING, ...DONE]) names[`session-${id}`] = {branch: `session/${id}`, label: title, last: now - 60, link: null, notes: 0, overlaps: [], files: 0, changed: []} w('_v1_names', names) w('_v1_state', {landing: {holder: null, pushed: {}, queue: []}, leases, nodes: NODES.map((x, i) => ({address: x.address, enabled: true, gpu: x.gpu, id: x.id, machine: x.machine, node: true, renderer: x.renderer, transport: 'ssh', ssh_port: 2222 + i, reading: {at: now - 10, cpus: x.cpus, disk_free: x.free, disk_total: 500e9, load: x.load, mem_max: 16e9, mem_used: 4e9, oom_kills: 0, sessions: 0, version: 'a1b2c3d4', recipe: 'a1b2c3d4', warm_age_s: 3600, head: MAIN, warm: MAIN, from: x.address, heard_since: now - D}})), waiters: {}}) const TARGETS = [['web', 'server', 'storefront'], ['api', 'server', 'storefront'], ['app', 'studio', 'mobile'], ['docs', 'server', 'docs']] w('_v1_deploys', {recent: TARGETS.map(([t], i) => ({actor: 'hub', deploy: `d-${t}`, kind: 'deploy_published', seconds: 30 + i * 10, sha: MAIN, target: t, ts: iso(now - 4 * H + i * 300)})), ships: PROJECTS.map((p) => ({repo: `acme/${p}`, held: null, landed_at: now - 5 * H, max_wait_s: 1800, tip: MAIN, targets: TARGETS.filter(([, , q]) => q === p).map(([t]) => ({asked: MAIN, published: MAIN, state: 'live', target: t, words: 'the tip is live'}))})), targets: TARGETS.map(([t, m, p]) => ({after_landing: true, machine: m, publishes: [`/srv/${t}`], repo: `acme/${p}`, target: t}))}) // Focus (focus.rs): a day two thirds into its cap, a week with one heavy day, the autopilot's answers, a rule it proposes. const day = (back: number, points: number, decisions: number, switches: number, interruptions: number, checkin: number | null) => ({checkin, date: new Date((now - back * D) * 1000).toISOString().slice(0, 10), decisions, interruptions, landings: Math.floor(decisions / 6), late: back === 2 ? 5 : 0, own_words: Math.floor(decisions / 5), peak: 3 + (back % 4), points, switches}) const week = [day(6, 22, 14, 6, 3, 2), day(5, 37, 22, 11, 7, 4), day(4, 7, 5, 1, 0, null), day(3, 2, 2, 0, 0, null), day(2, 44, 31, 19, 12, 5), day(1, 30, 19, 9, 6, 3), day(0, 27, 11, 7, 2, null)] const pilot = (back: number, session: string, n: number, question: string, answer: unknown, basis: string, why: string, sure = true) => ({answer, at: now - back, basis, kind: 'question', n, question, rule: basis === 'rule' ? 'r2' : null, saved: 1, session, sure, undo_until: now - back + 1800, undone: false, why}) w('_v1_focus', { at_work: 3, block: null, checkin: null, held: 1, holding: true, next_block: now - (now % H) + 2 * H, now, person: 'sam', quiet: false, pilot: [ pilot(9 * 60, 's211', 41, 'Rename login_attempts to sign_in_attempts?', 'Yes, rename it', 'judgement', 'The docs call it signing in; the person asked for the docs’ words.', false), pilot(40 * 60, 's212', 77, 'Rebase onto main before building?', 'Yes', 'rule', 'Rule r2: rebase onto main before building.'), pilot(2 * H, 's209', 12, 'Keep the old endpoint for one release?', 'Yes, one release', 'precedent', 'They answered the same for the price list on Tuesday.'), ], rules: [ {at: now - 9 * D, by: 'web:sam', id: 'r2', state: 'approved', text: 'Rebase onto main before building', uses: 22}, {at: now - 12 * D, by: 'web:sam', id: 'r1', state: 'approved', text: 'Split a commit by topic when it mixes two changes', uses: 9}, {at: now - 3 * H, by: 'autopilot', evidence: 'They took the recommended option 15 of 15 times in two weeks, in six sessions.', id: 'r3', state: 'suggested', text: 'Take a free build node when one is needed', uses: 0}, ], saved: 21, settings: {blocks: ['10:00', '15:00'], cap_points: 40, cap_sessions: 3, hold: true, quiet_from: '18:30', quiet_until: '07:00', rules_everywhere: false, tz_min: 60, undo_min: 30}, suggested_cap: {cap: 34, fresh: 22, fresh_days: 2, fried: 44, fried_days: 2}, today: {...week[6], at_cap: false, near_cap: false}, week, }) const ask = (n: number, kind: string, extra: Record) => ({at: now - 6 * 60 - (30 - n), kind, n, ...extra}) w('_v1_hosted_s210_log', {next: 4, items: [ ask(1, 'user', {by: 'web:sam', text: 'Dark mode for the order history'}), ask(2, 'agent', {text: 'The order history follows the system theme now. One choice is left: how the order status chips look in the dark.'}), ask(3, 'question', {message: 'How should the status chips look in dark mode?', request: '7', schema: {properties: { question_0: {oneOf: [{const: 'Muted fills (Recommended)', description: 'the same colours, darker; readable on the dark list', title: 'Muted fills (Recommended)'}, {const: 'Outlined', description: 'coloured border, no fill', title: 'Outlined'}], title: 'Chips', type: 'string'}, question_0_custom: {description: 'Your own answer, or a note to the one picked (optional).', title: 'Other', type: 'string'}}, type: 'object'}}), ]}) // History: a month of made-up sessions, landings, builds and takes. const sessions: unknown[] = [], landings: unknown[] = [], stats: unknown[] = [], builds: unknown[] = [], takes: unknown[] = [], pool: unknown[] = [] const verbs = ['Fix', 'Add', 'Speed up', 'Tidy', 'Test'] const things = ['the basket', 'search', 'the order page', 'sign-in', 'the release notes', 'image uploads', 'the price list', 'shipping rates'] for (let i = 0; i < 70; i++) { const start = now - Math.floor(rnd() * 30 * D), span = Math.floor((0.5 + rnd() * 5) * H), landed = rnd() < 0.8, project = pick(PROJECTS) const id = `h${100 + i}`, actor = `session-${id}`, title = `${pick(verbs)} ${pick(things)}`, ttl = Math.floor(span * (0.6 + rnd() * 0.4)) sessions.push({actor, branch: `session/${id}`, build_s: Math.floor(rnd() * 1500), builds: 1 + Math.floor(rnd() * 8), commands: 20 + Math.floor(rnd() * 80), end: start + span, failed_builds: Math.floor(rnd() * 2), gate_s: landed ? 60 + Math.floor(rnd() * 400) : null, label: title, land_wait_s: landed ? Math.floor(rnd() * 300) : null, landed_at: landed ? start + ttl : null, landing_attempts: landed ? 1 : 0, link: null, nodes: [pick(NODES).id], open: false, outcome: landed ? 'landed' : null, repo: `acme/${project}`, sha: landed ? hex() : null, span_s: span, start, start_from: 'hook', takes: 1 + Math.floor(rnd() * 3), time_to_land_s: landed ? ttl : null, waited_s: Math.floor(rnd() * 200)}) if (landed) landings.push({actor, branch: `session/${id}`, held_s: 60 + Math.floor(rnd() * 900), outcome: rnd() < 0.92 ? 'landed' : 'failed', sha: hex(), ts: iso(start + ttl), waited_s: Math.floor(rnd() * 120)}) const work = Math.floor(span * (0.3 + rnd() * 0.3)), said = [start, start + Math.floor(span * 0.4), start + Math.floor(span * 0.8)] stats.push({active_s: work, archived: false, cargo: {}, commands: {cargo: 10, git: 8}, end: start + span, failed: 0, files: {}, finished: true, id, imported: null, replies: 4, repo: `acme/${project}`, said, skills: {}, start, title, tool_calls: 40, tools: {Bash: 20, Edit: 10, Read: 10}}) for (let b = 0; b < 8; b++) { const node = pick(NODES), ts = start + Math.floor(rnd() * span) builds.push({actor, command: pick(['cargo test --workspace', 'cargo check', 'bun test', 'cargo build --release']), exit: rnd() < 0.9 ? 0 : 101, first_build_in_lease: b === 0, machine: node.machine, node: node.id, oom_kills: null, seconds: Math.floor(10 + rnd() * 400), shape: 'cargo', ts: iso(ts)}) if (b < 2) takes.push({actor, node: node.id, ts: iso(ts - 5), waited_s: rnd() < 0.8 ? 0 : Math.floor(rnd() * 600)}) } } for (let t = now - 30 * D; t < now; t += 1800) pool.push({in_pool: 2 + Math.floor(rnd() * 3), nodes: 4, ts: iso(t)}) const by = (a: any[], k: string) => a.sort((x, y) => (x[k] < y[k] ? -1 : 1)) w('_v1_sessions', by(sessions, 'start')); w('_v1_landings', by(landings, 'ts')); w('_v1_hosted_stats', by(stats, 'start')) // A week of the runner: a stop for each new build, one SIGTERM sent by a session, one death only its supervisor saw. const stops: Record[] = [] for (let d = 6; d >= 0; d--) for (let i = 0; i < 1 + Math.floor(rnd() * 3); i++) stops.push({runner: 'runner@server', at: now - d * D - Math.floor(rnd() * 20 * H), reason: 'build', version: hex(8), sessions: 3}) stops.push({runner: 'runner@server', at: now - 2 * D - 3 * H, reason: 'signal', signal: 'SIGTERM', by_pid: 41203, by_cmd: 'pkill -xf midas sessions run', by_owner: 'session-s205', sessions: 4}) stops.push({runner: 'runner@server', at: now - 4 * D - 5 * H, reason: 'killed', signal: 'SIGKILL', lived_s: 9 * H, seen_by: 'supervisor'}) const awayRanges = [{runner: 'runner@server', from: now - 2 * D - 3 * H, to: now - 2 * D - 3 * H + 70, sessions: 4}, ...(AWAY ? [{runner: 'runner@server', from: AWAY, to: null, sessions: 3}] : [])] if (AWAY) stops.push({runner: 'runner@server', at: AWAY, reason: 'unexplained', sessions: 3}) w('_v1_runners', {now, since: now - 7 * D, runners: [{name: 'runner@server', polled: AWAY ?? now - 4, away: AWAY, up_since: now - 3 * H, sessions: 3}], stops: stops.sort((a, b) => (a.at as number) - (b.at as number)), starts: [{runner: 'runner@server', at: now - 3 * H, by: 'build'}], away: awayRanges, panics: []}) w('_v1_builds', by(builds, 'ts')); w('_v1_history', {pool, takes: by(takes, 'ts')}) w('_v1_history_use', {pool: pool.slice(-48), takes: takes.slice(-10), use: {'build-1': {busy_s: 9000, held_s: 14000}, 'mac-1': {busy_s: 5200, held_s: 9000}, 'mac-2': {busy_s: 1800, held_s: 2600}, 'gpu-1': {busy_s: 600, held_s: 900}}}) w('_v1_hosted_s208_files', {at: now - 5 * H, base: 'main', clean: true, commits: 1, files: [{add: 9, binary: false, del: 4, patch: '', path: 'src/invoice/total.rs', status: 'M'}, {add: 22, binary: false, del: 0, patch: '', path: 'src/invoice/tests.rs', status: 'M'}]}) // Each machine's chip power (power.rs): idle most of the time, builds in working hours; the server has no sensor. const POWER: [string, string, number, number][] = [['studio', 'powermetrics', 5, 38], ['tower', 'amdgpu', 14, 95]] for (const step of [300, 3600]) { const since = step === 300 ? D : 7 * D, from = now - since, machines: Record = {} for (const [m, source, idle, busy] of POWER) { const points: [number, number, number][] = [] for (let t = from; t < now; t += step) { const hour = new Date(t * 1000).getHours(), work = hour >= 9 && hour < 19 && rnd() < 0.45 const watts = Math.round((work ? idle + (busy - idle) * (0.4 + 0.6 * rnd()) : idle * (0.8 + 0.4 * rnd())) * 10) / 10 points.push([t, watts, Math.round((watts * step) / 36) / 100]) } machines[m] = {now: {w: points[points.length - 1]![1], at: now - 20}, source, points} } w(`_v1_power_${step}`, {from, to: now, step, machines}) }