Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"capturedAt": "2026-09-30T08:40:33.073309Z",
"platform": "darwin",
"command": ["opencode"],
"cols": 120,
"rows": 40,
"note": "1.18.32 on macOS 26.6.2 arm64, 120x40, alternate screen. Why this run: answered like a hidden Orca pane (silent on OSC colour queries), as a background worker pane is. Recorded with a Python PTY driver rather than the repo recorder, because the driver stamps every read with its time and answers the terminal queries OpenCode sends; responder 'headless' = Orca's hidden-pane replies, silent on OSC colour queries. Isolated HOME and XDG dirs, OPENCODE_DISABLE_AUTOUPDATE=1, OPENCODE_CONFIG_CONTENT {\"autoupdate\":false}, no model configured, env -i (no ORCA_*); version and binary sha256 unchanged before and after. No input typed. Recording ran 42.8 s; no bytes after the last chunk. <name>.timing.json holds each PTY read as [ms since spawn, UTF-16 length] and recordedUntilMs.",
"exitCode": null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"recordedUntilMs":42761.8,"chunks":[[785.0,205],[786.9,71],[791.9,8],[793.5,57],[793.9,32],[794.0,16],[794.0,16],[794.1,24],[794.2,24],[794.2,24],[794.3,36],[794.4,24],[794.5,24],[795.2,1024],[795.8,1024],[796.3,1024],[796.7,1024],[796.9,1024],[797.2,961],[811.9,1024],[812.5,1024],[813.1,1024],[813.6,1024],[814.1,1024],[814.7,937],[2523.9,1024],[2524.9,1024],[2525.2,1024],[2525.5,1024],[2525.8,1024],[2526.1,1024],[2526.3,353],[2541.6,13],[2609.5,934],[2610.0,938],[2610.6,871],[2611.3,584]]}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"capturedAt": "2026-09-30T08:39:12.532885Z",
"platform": "darwin",
"command": ["opencode"],
"cols": 120,
"rows": 40,
"note": "1.18.32 on macOS 26.6.2 arm64, 120x40, alternate screen. Why this run: the slowest recorded boot: 3.9 s of silence after bracketed paste is enabled, and the longest gap (161 ms) between the bare OpenCode title and the input box. Recorded with a Python PTY driver rather than the repo recorder, because the driver stamps every read with its time and answers the terminal queries OpenCode sends; responder 'xterm' = xterm.js 6.0 replies incl. OSC 10/11/12/4 colours (a visible Orca pane). Isolated HOME and XDG dirs, OPENCODE_DISABLE_AUTOUPDATE=1, OPENCODE_CONFIG_CONTENT {\"autoupdate\":false}, no model configured, env -i (no ORCA_*); version and binary sha256 unchanged before and after. No input typed. Recording ran 76.9 s; no bytes after the last chunk. <name>.timing.json holds each PTY read as [ms since spawn, UTF-16 length] and recordedUntilMs.",
"exitCode": null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"recordedUntilMs":76886.4,"chunks":[[2454.9,276],[2478.3,8],[2513.8,1024],[2518.9,1024],[2531.6,1024],[2539.1,1024],[2581.2,1024],[2583.9,1024],[2587.4,411],[2593.0,1024],[2602.3,1024],[2607.8,1024],[2621.8,1024],[2622.5,1024],[2623.3,937],[6479.2,1024],[6485.0,1024],[6487.5,1024],[6490.0,1024],[6499.8,1024],[6502.7,1024],[6509.0,353],[6538.4,13],[6685.0,934],[6686.4,938],[6697.9,871],[6699.1,584]]}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"capturedAt": "2026-09-30T08:33:44.169427Z",
"platform": "darwin",
"command": ["opencode"],
"cols": 120,
"rows": 40,
"note": "1.18.32 on macOS 26.6.2 arm64, 120x40, alternate screen. Why this run: first launch on an empty home: no first-run dialog appears before the input box. Recorded with a Python PTY driver rather than the repo recorder, because the driver stamps every read with its time and answers the terminal queries OpenCode sends; responder 'xterm' = xterm.js 6.0 replies incl. OSC 10/11/12/4 colours (a visible Orca pane). Isolated HOME and XDG dirs, OPENCODE_DISABLE_AUTOUPDATE=1, OPENCODE_CONFIG_CONTENT {\"autoupdate\":false}, no model configured, env -i (no ORCA_*); version and binary sha256 unchanged before and after. No input typed. Recording ran 14.9 s; no bytes after the last chunk. <name>.timing.json holds each PTY read as [ms since spawn, UTF-16 length] and recordedUntilMs.",
"exitCode": null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"recordedUntilMs":14932.3,"chunks":[[894.6,205],[897.3,71],[906.1,8],[909.0,57],[909.3,32],[909.4,16],[909.5,16],[909.6,24],[909.6,24],[909.8,24],[909.9,36],[910.0,24],[910.1,24],[911.8,134],[915.0,1024],[916.4,1024],[917.0,1024],[917.5,1024],[918.0,1024],[918.6,1024],[933.4,1024],[934.1,1024],[934.7,1024],[935.3,1024],[935.8,1024],[936.4,937],[2731.2,1024],[2731.8,1024],[2732.2,1024],[2732.7,1024],[2733.1,1024],[2734.0,1024],[2734.4,353],[2766.9,13],[2847.0,934],[2847.6,938],[2848.1,871],[2848.6,584]]}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"capturedAt": "2026-09-30T08:50:47.405221Z",
"platform": "darwin",
"command": ["opencode", "--standalone"],
"cols": 120,
"rows": 40,
"note": "opencode v2.0.18 on macOS 26.6.2 arm64, 120x40, alternate screen. Why this run: OpenCode 2 answered like a hidden Orca pane; show-cursor repeats on every frame after the box. Recorded with a Python PTY driver rather than the repo recorder, because the driver stamps every read with its time and answers the terminal queries OpenCode sends; responder 'headless' = Orca's hidden-pane replies, silent on OSC colour queries. Isolated HOME and XDG dirs, OPENCODE_DISABLE_AUTOUPDATE=1, OPENCODE_CONFIG_CONTENT {\"autoupdate\":false}, no model configured, env -i (no ORCA_*); version and binary sha256 unchanged before and after. No input typed. Recording ran 41.5 s; no bytes after the last chunk. Run as `opencode --standalone` from a 2.0.18 binary; Orca's opencode2 row launches `opencode2 --standalone`. <name>.timing.json holds each PTY read as [ms since spawn, UTF-16 length] and recordedUntilMs.",
"exitCode": null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"recordedUntilMs":41502.8,"chunks":[[307.5,280],[316.3,1024],[316.7,1024],[317.0,1024],[317.4,1024],[317.7,1024],[318.0,1022],[318.3,164],[318.3,24],[318.3,24],[326.8,1024],[327.5,1024],[328.0,1024],[328.6,1024],[329.1,1024],[329.7,937],[1339.7,1024],[1340.4,1024],[1341.1,1024],[1341.8,1024],[1342.5,1024],[1343.1,1024],[1343.8,353],[1348.0,13],[1387.9,934],[1388.4,938],[1388.7,832],[1418.2,483],[1436.2,483],[1453.8,488],[1471.8,497],[1489.7,498],[1508.0,504],[1525.8,504],[1543.2,504],[1560.9,504]]}

Large diffs are not rendered by default.

35 changes: 35 additions & 0 deletions src/main/runtime/agent-transcript-replay-test-harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,41 @@ export function readRuntimeFixture(name: string): string {
return readFileSync(join(__dirname, '__fixtures__', `${name}.txt`), 'utf8')
}

export type TimedRuntimeFixture = {
/** The recorded PTY reads, in order; they concatenate to the whole `.txt`. */
chunks: string[]
/** ms since spawn at which each read arrived. */
times: number[]
promptSentAtMs?: number
/** When recording stopped; no bytes arrived between the last read and this. */
recordedUntilMs?: number
}

/** `<name>.timing.json` holds each read as [ms since spawn, UTF-16 length]. */
export function readTimedRuntimeFixture(name: string): TimedRuntimeFixture {
const data = readRuntimeFixture(name)
const timing: {
chunks: [number, number][]
promptSentAtMs?: number
recordedUntilMs?: number
} = JSON.parse(readFileSync(join(__dirname, '__fixtures__', `${name}.timing.json`), 'utf8'))
const chunks: string[] = []
let offset = 0
for (const [, length] of timing.chunks) {
chunks.push(data.slice(offset, offset + length))
offset += length
}
if (offset !== data.length) {
throw new Error(`${name}.timing.json covers ${offset} of ${data.length} chars`)
}
return {
chunks,
times: timing.chunks.map(([at]) => at),
...(timing.promptSentAtMs !== undefined ? { promptSentAtMs: timing.promptSentAtMs } : {}),
...(timing.recordedUntilMs !== undefined ? { recordedUntilMs: timing.recordedUntilMs } : {})
}
}

/** A string is cut into fixed 64-char chunks; an array replays the recorded PTY chunks as-is. */
export async function* replayTranscript(
data: string | readonly string[],
Expand Down
20 changes: 5 additions & 15 deletions src/main/runtime/codex-quiet-ready-screen.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { readFileSync } from 'node:fs'
import { join } from 'node:path'
import { afterEach, describe, expect, it, vi } from 'vitest'
import type { TuiAgent } from '../../shared/tui-agent'
import { createTranscriptPane } from './agent-transcript-pane-test-harness'
import {
readRuntimeFixture,
readTimedRuntimeFixture,
replayTranscript,
type TranscriptReplayFrame
} from './agent-transcript-replay-test-harness'
Expand Down Expand Up @@ -204,21 +203,12 @@ describe('Codex composer ready screen, frame by frame', () => {
})
})

type Timing = { promptSentAtMs: number; chunks: [number, number][] }

function readTimedFixture(name: string): { chunks: string[]; times: number[]; promptAt: number } {
const data = readRuntimeFixture(name)
const timing: Timing = JSON.parse(
readFileSync(join(__dirname, '__fixtures__', `${name}.timing.json`), 'utf8')
)
const chunks: string[] = []
let offset = 0
for (const [, length] of timing.chunks) {
chunks.push(data.slice(offset, offset + length))
offset += length
const { chunks, times, promptSentAtMs } = readTimedRuntimeFixture(name)
if (promptSentAtMs === undefined) {
throw new Error(`${name}.timing.json has no promptSentAtMs`)
}
expect(offset).toBe(data.length)
return { chunks, times: timing.chunks.map(([at]) => at), promptAt: timing.promptSentAtMs }
return { chunks, times, promptAt: promptSentAtMs }
}

describe('the quiet lane over recorded chunk timing (default animations)', () => {
Expand Down
191 changes: 191 additions & 0 deletions src/main/runtime/draft-paste-ready-scanner-chunking.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
/**
* The draft-paste scanner must answer the same way however the PTY splits a stream into reads.
* Every committed capture whose signal revokes its anchor is replayed whole, one char at a time,
* in its recorded reads (where timed) and in seeded random chunkings, and each must turn ready on
* the read holding the offset a plain string walk finds. A regression guard for grok, DSH and
* ZCode (their markers are one char, so the seam fix cannot move them), and the proof for OpenCode.
*/

import { readFileSync } from 'node:fs'
import { join } from 'node:path'
import { describe, expect, it } from 'vitest'
import { createDraftPasteReadyScanner } from '../../shared/draft-paste-ready-scanner'
import type { DraftPasteReadySignal } from '../../shared/tui-agent-config'
import { GROK_STARTUP_PTY_TRACE } from '../../shared/__fixtures__/grok-startup-pty-trace'
import { GROK_INLINE_STARTUP_PTY_TRACE } from '../../shared/__fixtures__/grok-inline-startup-pty-trace'
import type { GrokStartupTraceChunk } from '../../shared/__fixtures__/grok-startup-pty-trace'
import { readRuntimeFixture, readTimedRuntimeFixture } from './agent-transcript-replay-test-harness'

type Walk = { anchor: string; end: string; marker: string }

const ALT_SCREEN: Walk = { anchor: '\x1b[?1049h', end: '\x1b[?1049l', marker: '' }
const WALKS: Partial<Record<DraftPasteReadySignal, Walk>> = {
'render-cursor-after-bracketed-paste': {
anchor: '\x1b[?2004h',
end: '\x1b[?2004l',
marker: '\x1b[?25h'
},
'grok-composer-prompt': { ...ALT_SCREEN, marker: '❯' },
'dsh-composer-prompt': { ...ALT_SCREEN, marker: '❯' },
'zcode-composer-prompt': { ...ALT_SCREEN, marker: '╭' }
}

// Recorded zsh shape: the prompt enables bracketed paste and accept-line disables it before exec.
// The launcher's cursor toggle after that is synthetic, standing in for any spinner.
const ZSH_LAUNCH_PROLOGUE =
'\x1b[?2004h% opencode\x1b[?2004l\r\n\x1b]2;opencode\x07\x1b[?25lresolving\x1b[?25h\r\n'

const OPENCODE_TIMED = [
'opencode-1-18-32-timed-boot-slow',
'opencode-1-18-32-timed-boot-hidden-pane',
'opencode-1-18-32-timed-first-launch',
'opencode-2-0-18-timed-boot-hidden-pane'
]

type Case = { name: string; signal: DraftPasteReadySignal; data: string; reads?: string[] }

function readPtyTranscript(name: string): string {
return readFileSync(
join(__dirname, '..', 'daemon', '__fixtures__', 'pty-transcripts', name),
'utf8'
)
}

function grokCase(name: string, trace: GrokStartupTraceChunk[]): Case {
const reads = trace.map((chunk) => chunk.data ?? 'x'.repeat(chunk.bytes ?? 0))
return { name, signal: 'grok-composer-prompt', data: reads.join(''), reads }
}

const CASES: Case[] = [
grokCase('grok 1.0.0 alt screen', GROK_STARTUP_PTY_TRACE),
grokCase('grok 1.0.0 inline', GROK_INLINE_STARTUP_PTY_TRACE),
{
name: 'dsh-tui-ready-no-key',
signal: 'dsh-composer-prompt',
data: readRuntimeFixture('dsh-tui-ready-no-key')
},
{
name: 'zcode-composer-ready',
signal: 'zcode-composer-prompt',
data: readRuntimeFixture('zcode-composer-ready')
},
{
name: 'opencode (untimed pty transcript)',
signal: 'render-cursor-after-bracketed-paste',
data: readPtyTranscript('opencode.txt')
},
...OPENCODE_TIMED.flatMap((name): Case[] => {
const { chunks } = readTimedRuntimeFixture(name)
return [
{ name, signal: 'render-cursor-after-bracketed-paste', data: chunks.join(''), reads: chunks },
{
name: `${name} behind a zsh launch`,
signal: 'render-cursor-after-bracketed-paste',
data: ZSH_LAUNCH_PROLOGUE + chunks.join(''),
reads: [ZSH_LAUNCH_PROLOGUE, ...chunks]
}
]
})
]

/** End offset of the first marker seen while the anchor is held, walking the whole string. */
function walkReadyEnd(data: string, { anchor, end, marker }: Walk): number | null {
let cursor = 0
for (;;) {
const enter = data.indexOf(anchor, cursor)
if (enter === -1) {
return null
}
cursor = enter + anchor.length
const leave = data.indexOf(end, cursor)
const found = data.indexOf(marker, cursor)
if (found !== -1 && (leave === -1 || found + marker.length <= leave)) {
return found + marker.length
}
if (leave === -1) {
return null
}
cursor = leave + end.length
}
}

/** [start, end) of the first read the scanner reports ready on, or null. */
function scanReadyRead(signal: DraftPasteReadySignal, reads: string[]): [number, number] | null {
const scanner = createDraftPasteReadyScanner(signal)
let offset = 0
for (const read of reads) {
if (scanner.observe(read).ready) {
return [offset, offset + read.length]
}
offset += read.length
}
return null
}

function splitAt(data: string, sizes: () => number): string[] {
const reads: string[] = []
for (let offset = 0; offset < data.length;) {
const size = sizes()
reads.push(data.slice(offset, offset + size))
offset += size
}
return reads
}

// mulberry32: a fixed seed keeps every chunking reproducible.
function seededSizes(seed: number, max: number): () => number {
let state = seed
return () => {
state = (state + 0x6d2b79f5) | 0
let t = Math.imul(state ^ (state >>> 15), 1 | state)
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t
return 1 + Math.floor((((t ^ (t >>> 14)) >>> 0) / 4294967296) * max)
}
}

function chunkings(testCase: Case): Map<string, string[]> {
const { data } = testCase
const result = new Map<string, string[]>([
['whole', [data]],
['one char per read', splitAt(data, () => 1)]
])
if (testCase.reads) {
result.set('recorded reads', testCase.reads)
}
for (let seed = 0; seed < 12; seed += 1) {
const max = seed % 2 === 0 ? 16 : 2048
result.set(`random chunking ${seed}`, splitAt(data, seededSizes(seed + 1, max)))
}
return result
}

describe('draft-paste readiness does not depend on how the stream is chunked', () => {
it.each(CASES.map((testCase) => [testCase.name, testCase] as const))('%s', (_, testCase) => {
const walk = WALKS[testCase.signal]
if (!walk) {
throw new Error(`no reference walk for ${testCase.signal}`)
}
const expected = walkReadyEnd(testCase.data, walk)
for (const [label, reads] of chunkings(testCase)) {
const readyRead = scanReadyRead(testCase.signal, reads)
if (expected === null) {
expect(readyRead, label).toBeNull()
continue
}
expect(readyRead, label).not.toBeNull()
const [start, end] = readyRead!
expect(
start < expected && expected <= end,
`${label}: [${start}, ${end}) vs ${expected}`
).toBe(true)
}
})

it.each(OPENCODE_TIMED)('%s: a zsh launch in front moves nothing but the offset', (name) => {
const walk = WALKS['render-cursor-after-bracketed-paste']!
const data = readTimedRuntimeFixture(name).chunks.join('')
const alone = walkReadyEnd(data, walk)
expect(alone).not.toBeNull()
expect(walkReadyEnd(ZSH_LAUNCH_PROLOGUE + data, walk)).toBe(ZSH_LAUNCH_PROLOGUE.length + alone!)
})
})
Loading
Loading