Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion src/main/ipc/pty-buffer-snapshot-dispatch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ describe('registerPtyHandlers', () => {
type SerializeController = {
serializeBuffer: (
ptyId: string,
opts?: { scrollbackRows?: number; altScreenForcesZeroRows?: boolean }
opts?: { scrollbackRows?: number }
) => Promise<{ data: string; cols: number; rows: number; lastTitle?: string } | null>
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/ipc/pty/ipc/serialize-buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export function installPtySerializeBufferIpc(session: PtyIpcSession): void {
export function requestSerializedBuffer(
session: PtyIpcSession,
ptyId: string,
opts?: { scrollbackRows?: number; altScreenForcesZeroRows?: boolean }
opts?: { scrollbackRows?: number }
): Promise<SerializeResult> {
if (session.mainWindow.isDestroyed()) {
return Promise.resolve(null)
Expand All @@ -101,7 +101,7 @@ export function requestSerializedBuffer(
const payload: {
requestId: string
ptyId: string
opts?: { scrollbackRows?: number; altScreenForcesZeroRows?: boolean }
opts?: { scrollbackRows?: number }
} = { requestId, ptyId }
if (opts) {
payload.opts = opts
Expand Down
2 changes: 1 addition & 1 deletion src/main/ipc/pty/runtime/controller-deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export type PtyRuntimeControllerDeps = {
) => string | undefined
requestSerializedBuffer: (
ptyId: string,
opts?: { scrollbackRows?: number; altScreenForcesZeroRows?: boolean }
opts?: { scrollbackRows?: number }
) => Promise<{
data: string
cols: number
Expand Down
2 changes: 1 addition & 1 deletion src/main/ipc/pty/runtime/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ export function getSizeFromRuntimeController(ptyId: string) {

export async function serializeProviderBufferFromRuntimeController(
ptyId: string,
opts?: { scrollbackRows?: number; altScreenForcesZeroRows?: boolean }
opts?: { scrollbackRows?: number }
) {
try {
// Why: restored daemon PTYs can be live while their desktop pane is unmounted; query the provider model so phone-local navigation works.
Expand Down
2 changes: 1 addition & 1 deletion src/main/ipc/pty/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export type PtyIpcSession = {
sendPtySpawnedToRenderer: (id: string) => void
requestSerializedBuffer: (
ptyId: string,
opts?: { scrollbackRows?: number; altScreenForcesZeroRows?: boolean }
opts?: { scrollbackRows?: number }
) => Promise<SerializeResult>
shutdownProviderAndDetectExit: (
provider: IPtyProvider,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,11 @@ export class OrcaRuntimeWithMaybeHydrateHeadlessFromRenderer extends OrcaRuntime
// state and the seed-resolve would overwrite it, dropping live bytes.
state.writeChain = state.writeChain.then(async () => {
try {
// Why the scrollback is not suppressed mid-TUI: the seed IS the model's
// normal buffer, so zeroing it while an alt-screen agent was up left the
// model with no pre-TUI history to restore from (#6106).
const rendered = await controller.serializeBuffer!(ptyId, {
scrollbackRows: MOBILE_SUBSCRIBE_SCROLLBACK_ROWS,
altScreenForcesZeroRows: true
scrollbackRows: MOBILE_SUBSCRIBE_SCROLLBACK_ROWS
})
if (!rendered || rendered.data.length === 0) {
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,8 @@ export class OrcaRuntimeWithSerializeTerminalBufferFromAvailableState extends Or
kittyKeyboardFlags?: number
} | null = null
try {
// Why: recovery/read fallback wants visible alt-screen content (e.g. an
// active TUI), so altScreenForcesZeroRows is FALSE here. Hydration is
// the only path that suppresses alt-screen scrollback.
rendererSnapshot = await (this.ptyController?.serializeBuffer?.(ptyId, {
scrollbackRows: opts.scrollbackRows,
altScreenForcesZeroRows: false
scrollbackRows: opts.scrollbackRows
}) ?? Promise.resolve(null))
} catch {
// Why: terminal snapshots should not depend on a mounted renderer pane.
Expand Down
39 changes: 35 additions & 4 deletions src/main/runtime/orca-runtime-tests/headless-snapshots.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,39 @@ describe('OrcaRuntimeService', () => {
}
})

it('keeps pre-TUI shell scrollback when hydrating from a renderer on the alternate screen (#6106)', async () => {
// The real renderer serializer emits the normal buffer first and the `?1049h`
// alt frame after it; asking it to zero the scrollback while a TUI is up drops
// the shell history, not the TUI bytes. Model that contract here.
const serializeBuffer = vi.fn(async (_ptyId: string, opts?: { scrollbackRows?: number }) => {
const suppressesScrollback =
(opts as Record<string, unknown> | undefined)?.altScreenForcesZeroRows === true
const scrollback = suppressesScrollback ? '' : 'PRE_CODEX_START\r\nAGENTS.md\r\n'
return {
data: `${scrollback}\x1b[?1049h\x1b[HCodex TUI frame`,
cols: 80,
rows: 24
}
})
const runtime = createRuntime()
runtime.setPtyController({
write: () => true,
kill: () => true,
getForegroundProcess: async () => null,
serializeBuffer,
hasRendererSerializer: () => true,
getSize: () => ({ cols: 80, rows: 24 })
})
syncSinglePty(runtime, 'pty-1')

runtime.onPtyData('pty-1', 'live byte', 100)

const snapshot = await runtime.serializeMainTerminalBuffer('pty-1', { scrollbackRows: 1000 })
const restored = `${snapshot?.scrollbackAnsi ?? ''}${snapshot?.data ?? ''}`
expect(restored).toContain('PRE_CODEX_START')
expect(restored).toContain('AGENTS.md')
})

it('adopts renderer-seeded titles into headless main terminal snapshots', async () => {
const artifactPath = '/tmp/renderer-seeded-artifact.json'
const serializeBuffer = vi.fn().mockResolvedValue({
Expand Down Expand Up @@ -139,8 +172,7 @@ describe('OrcaRuntimeService', () => {
lastTitle: 'Renderer seeded Codex'
})
expect(serializeBuffer).toHaveBeenCalledWith('pty-1', {
scrollbackRows: expect.any(Number),
altScreenForcesZeroRows: true
scrollbackRows: expect.any(Number)
})
expect(runtime.hasRecentTerminalOutputPath(terminal.handle, artifactPath, artifactPath)).toBe(
true
Expand Down Expand Up @@ -412,8 +444,7 @@ describe('OrcaRuntimeService', () => {
source: 'renderer'
})
expect(serializeBuffer).toHaveBeenCalledWith('pty-1', {
scrollbackRows: 5000,
altScreenForcesZeroRows: false
scrollbackRows: 5000
})
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -472,8 +472,7 @@ describe('OrcaRuntimeService', () => {

expect(read.tail).toEqual(['Claude Code', 'Working on fix', 'Tool: Read'])
expect(serializeBuffer).toHaveBeenCalledWith('pty-1', {
scrollbackRows: 0,
altScreenForcesZeroRows: false
scrollbackRows: 0
})
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -532,8 +532,7 @@ describe('OrcaRuntimeService', () => {
draft: 'proceed with the release'
})
expect(serializeBuffer).toHaveBeenCalledWith('pty-1', {
scrollbackRows: 0,
altScreenForcesZeroRows: false
scrollbackRows: 0
})
})

Expand Down Expand Up @@ -595,8 +594,7 @@ describe('OrcaRuntimeService', () => {

expect(read.tail).toEqual([''])
expect(serializeBuffer).not.toHaveBeenCalledWith('pty-1', {
scrollbackRows: 0,
altScreenForcesZeroRows: false
scrollbackRows: 0
})
})

Expand All @@ -623,8 +621,7 @@ describe('OrcaRuntimeService', () => {

expect(read.tail).toEqual(['', ''])
expect(serializeBuffer).not.toHaveBeenCalledWith('pty-1', {
scrollbackRows: 0,
altScreenForcesZeroRows: false
scrollbackRows: 0
})
})
})
5 changes: 1 addition & 4 deletions src/main/runtime/orca-runtime-visible-snapshot-preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,7 @@ export class OrcaRuntimeWithVisibleSnapshotPreview extends OrcaRuntimeWithCaptur
// visibly nonblank in renderer xterm. Ask the renderer for the active
// screen instead of reusing the headless transcript path.
const snapshot = await withTimeout(
controller.serializeBuffer(ptyId, {
scrollbackRows: 0,
altScreenForcesZeroRows: false
}),
controller.serializeBuffer(ptyId, { scrollbackRows: 0 }),
VISIBLE_TERMINAL_SNAPSHOT_TIMEOUT_MS,
null
)
Expand Down
2 changes: 1 addition & 1 deletion src/main/runtime/runtime-pty-controller-contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export type RuntimePtyController = {
}>
serializeBuffer?(
ptyId: string,
opts?: { scrollbackRows?: number; altScreenForcesZeroRows?: boolean }
opts?: { scrollbackRows?: number }
): Promise<{
data: string
cols: number
Expand Down
70 changes: 70 additions & 0 deletions src/main/ssh/ssh-remote-node-probe-script.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// POSIX `sh` probe listing every plausible remote Node binary, one per line.
// Kept out of the resolver so the shell text can grow without pushing that file
// past its line budget.

// Why the dotfile scrape: sshd's exec channel runs without the user's profile, so
// MISE_DATA_DIR / NVM_DIR set in ~/.zshrc are not in this environment. Reading the
// assignment out of the dotfiles is the only way to see a relocated data dir.
export const REMOTE_NODE_PATH_PROBE_SCRIPT = `
command -v node 2>/dev/null
orca_dotfile_dirs() {
orca_var_name=$1
orca_dirs=$2
for orca_file in "$HOME/.profile" "$HOME/.bash_profile" "$HOME/.bashrc" "$HOME/.zprofile" "$HOME/.zshrc"
do
[ -r "$orca_file" ] || continue
orca_dir_from_file=$(sed -n "s/^[[:space:]]*export[[:space:]][[:space:]]*$orca_var_name[[:space:]]*=[[:space:]]*//p; s/^[[:space:]]*$orca_var_name[[:space:]]*=[[:space:]]*//p" "$orca_file" | tail -n 1)
case "$orca_dir_from_file" in
\\"*\\") orca_dir_from_file=\${orca_dir_from_file#\\"}; orca_dir_from_file=\${orca_dir_from_file%%\\"*} ;;
\\'*\\') orca_dir_from_file=\${orca_dir_from_file#\\'}; orca_dir_from_file=\${orca_dir_from_file%%\\'*} ;;
*) orca_dir_from_file=\${orca_dir_from_file%%[[:space:]]*} ;;
esac
case "$orca_dir_from_file" in
'$XDG_DATA_HOME'*) orca_dir_from_file="\${XDG_DATA_HOME:-$HOME/.local/share}\${orca_dir_from_file#'$XDG_DATA_HOME'}" ;;
'$HOME'*) orca_dir_from_file="$HOME\${orca_dir_from_file#'$HOME'}" ;;
"~/"*) orca_dir_from_file="$HOME/\${orca_dir_from_file#\\~/}" ;;
esac
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
[ -n "$orca_dir_from_file" ] && orca_dirs="$orca_dirs
$orca_dir_from_file"
done
printf '%s\\n' "$orca_dirs"
}
nvm_dirs=\${NVM_DIR:-"$HOME/.nvm"}
nvm_dirs=$(orca_dotfile_dirs NVM_DIR "$nvm_dirs")
printf '%s\\n' "$nvm_dirs" | while IFS= read -r nvm_dir
do
[ -n "$nvm_dir" ] || continue
for candidate in "$nvm_dir"/versions/node/*/bin/node
do
[ -x "$candidate" ] && printf '%s\\n' "$candidate"
done
done
mise_dirs=\${MISE_DATA_DIR:-\${XDG_DATA_HOME:-$HOME/.local/share}/mise}
mise_dirs=$(orca_dotfile_dirs MISE_DATA_DIR "$mise_dirs")
printf '%s\\n' "$mise_dirs" | while IFS= read -r mise_dir
do
[ -n "$mise_dir" ] || continue
[ -x "$mise_dir/shims/node" ] && printf '%s\\n' "$mise_dir/shims/node"
for candidate in "$mise_dir"/installs/node/*/bin/node
do
[ -x "$candidate" ] && printf '%s\\n' "$candidate"
done
done
for candidate in \\
/usr/local/bin/node \\
/opt/homebrew/bin/node \\
"$HOME/.local/bin/node" \\
"$HOME/.fnm/aliases/default/bin/node" \\
"$HOME/.fnm/node-versions"/*/installation/bin/node \\
"$HOME/.local/share/fnm/node-versions"/*/installation/bin/node \\
"$HOME/.local/share/mise/shims/node" \\
"$HOME/.local/share/mise/installs/node"/*/bin/node \\
"$HOME/.asdf/shims/node" \\
"$HOME/.asdf/installs/nodejs"/*/bin/node \\
"$HOME/.volta/bin/node" \\
/usr/local/n/versions/node/*/bin/node
do
[ -x "$candidate" ] && printf '%s\\n' "$candidate"
done
true
`
Loading