Files
orca/src/main/ssh/ssh-remote-cli-format.ts
T
Jinjingandbbingz 1d2aaf1bf5 Fix recipe serve desktop promotion (#8646)
* fix(runtime): preserve terminals during headless desktop activation

* rm design doc

* Fix desktop activation launch ordering and blocked-window status resolut

- Check desktopWindowStatus before spawning the Orca app so a blocked
  runtime no longer launches a doomed second instance.
- Reuse resolveDesktopWindowStatus for remote runtime status so it
  honors the same authoritativeWindowId fallback as local status.
- Re-check the authoritative window at spawn time instead of trusting
  a possibly-stale snapshot, since it can be destroyed mid-await.
- Harden the e2e activation spec against silent spawn failures.

---------

Co-authored-by: bbingz <zzb@gxsmjx.com>
2026-07-13 19:41:24 -07:00

50 lines
1.8 KiB
TypeScript

import type { CliStatusResult } from '../../shared/runtime-types'
import type { RpcResponse } from '../runtime/rpc/core'
import { formatRemoteLinearCli } from './ssh-remote-linear-output'
export function formatRemoteCli(response: RpcResponse): { stdout: string; stderr: string } {
if (!response.ok) {
return { stdout: '', stderr: `${formatRemoteCliError(response.error)}\n` }
}
const result = response.result
if (isRecord(result) && 'app' in result && 'runtime' in result && 'graph' in result) {
const record = result as Record<string, unknown>
return formatStatusResult(record as CliStatusResult)
}
const linear = formatRemoteLinearCli(result)
if (linear) {
return linear
}
return { stdout: `${JSON.stringify(result)}\n`, stderr: '' }
}
function formatRemoteCliError(error: { message: string; data?: unknown }): string {
const nextSteps =
isRecord(error.data) && Array.isArray(error.data.nextSteps)
? error.data.nextSteps.filter((step): step is string => typeof step === 'string')
: []
if (nextSteps.length === 0) {
return error.message
}
return `${error.message}\n${nextSteps.map((step) => `Next step: ${step}`).join('\n')}`
}
function formatStatusResult(status: CliStatusResult): { stdout: string; stderr: string } {
return {
stdout: `${[
`appRunning: ${status.app.running}`,
`pid: ${status.app.pid ?? 'none'}`,
`desktopWindowStatus: ${status.app.desktopWindowStatus ?? 'unknown'}`,
`runtimeState: ${status.runtime.state}`,
`runtimeReachable: ${status.runtime.reachable}`,
`runtimeId: ${status.runtime.runtimeId ?? 'none'}`,
`graphState: ${status.graph.state}`
].join('\n')}\n`,
stderr: ''
}
}
function isRecord(value: unknown): value is Record<string, unknown> {
return Boolean(value) && typeof value === 'object'
}