mirror of
https://github.com/stablyai/orca.git
synced 2026-09-29 08:03:20 +00:00
* 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>
51 lines
1.9 KiB
TypeScript
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'
|
|
}
|