Files
orca/src/main/ssh/ssh-remote-cli-format.ts
T
Brennan BensonandMerge Sim aabcc57366 fix(runtime): publish remote control outages to host surfaces (#17531)
* fix(runtime): publish remote control diagnostics to renderer

* test(runtime): account for diagnostics bridge listener

* fix(i18n): add runtime connection state labels

* test(runtime): clean up shared control connection

* fix(runtime): fence diagnostics by shared-control capability

* fix(runtime): preserve authoritative transport state

* fix(runtime): preserve diagnostic overlay lifecycle

* fix(runtime): avoid publishing unchanged diagnostics state

---------

Co-authored-by: Merge Sim <sim@local>
2026-08-31 12:25:17 -07:00

51 lines
1.9 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}`,
`runtimeConnectionState: ${status.runtime.connectionState ?? 'unknown'}`,
`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'
}