mirror of
https://github.com/stablyai/orca.git
synced 2026-09-26 08:02:38 +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>
113 lines
3.5 KiB
TypeScript
113 lines
3.5 KiB
TypeScript
import type { CliStatusResult, RuntimeStatus } from '../../shared/runtime-types'
|
|
import { runtimeHostConnectionState } from '../../shared/runtime-host-connection-state'
|
|
import { findTransport } from '../../shared/runtime-bootstrap'
|
|
import { tryReadMetadata } from './metadata'
|
|
import { sendRequest } from './transport'
|
|
import {
|
|
projectRemoteAppStatus,
|
|
resolveDesktopWindowStatus
|
|
} from '../../shared/cli-app-status-projection'
|
|
import { RuntimeRpcFailureError, type RuntimeRpcSuccess } from './types'
|
|
|
|
export { projectRemoteAppStatus, resolveDesktopWindowStatus }
|
|
|
|
export async function getCliStatus(
|
|
userDataPath: string
|
|
): Promise<RuntimeRpcSuccess<CliStatusResult>> {
|
|
const metadata = tryReadMetadata(userDataPath)
|
|
const transport = metadata ? findTransport(metadata, 'unix', 'named-pipe') : null
|
|
if (!transport || !metadata?.authToken) {
|
|
return buildCliStatusResponse({
|
|
app: {
|
|
running: false,
|
|
pid: null
|
|
},
|
|
runtime: {
|
|
// Why: distinguishing "never started" from "was running but died"
|
|
// gives the user a better signal about what happened. If the metadata
|
|
// file exists, Orca was running at some point.
|
|
state: metadata ? 'stale_bootstrap' : 'not_running',
|
|
reachable: false,
|
|
runtimeId: null
|
|
},
|
|
graph: {
|
|
state: 'not_running'
|
|
}
|
|
})
|
|
}
|
|
|
|
try {
|
|
const response = await sendRequest<RuntimeStatus>(metadata, 'status.get', undefined, 1000)
|
|
if (response.ok === false) {
|
|
throw new RuntimeRpcFailureError(response)
|
|
}
|
|
const graphState = response.result.graphStatus
|
|
const desktopWindowStatus = resolveDesktopWindowStatus(response.result)
|
|
return buildCliStatusResponse({
|
|
app: {
|
|
running: true,
|
|
pid: metadata.pid,
|
|
...(desktopWindowStatus ? { desktopWindowStatus } : {})
|
|
},
|
|
runtime: {
|
|
state: graphState === 'ready' ? 'ready' : 'graph_not_ready',
|
|
reachable: true,
|
|
connectionState: runtimeHostConnectionState({
|
|
hasStatusEntry: true,
|
|
status: response.result
|
|
}),
|
|
runtimeId: response.result.runtimeId,
|
|
...(response.result.appVersion ? { appVersion: response.result.appVersion } : {}),
|
|
...(response.result.remoteUpdateSupport
|
|
? { remoteUpdateSupport: response.result.remoteUpdateSupport }
|
|
: {}),
|
|
...(response.result.capabilities ? { capabilities: response.result.capabilities } : {}),
|
|
...(response.result.degradations ? { degradations: response.result.degradations } : {})
|
|
},
|
|
graph: {
|
|
state: graphState
|
|
}
|
|
})
|
|
} catch {
|
|
const running = isProcessRunning(metadata.pid)
|
|
return buildCliStatusResponse({
|
|
app: {
|
|
running,
|
|
pid: running ? metadata.pid : null
|
|
},
|
|
runtime: {
|
|
state: running ? 'starting' : 'stale_bootstrap',
|
|
reachable: false,
|
|
connectionState: 'disconnected',
|
|
runtimeId: null
|
|
},
|
|
graph: {
|
|
state: running ? 'starting' : 'not_running'
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
function buildCliStatusResponse(result: CliStatusResult): RuntimeRpcSuccess<CliStatusResult> {
|
|
return {
|
|
id: 'local-status',
|
|
ok: true,
|
|
result: { target: { kind: 'local' }, ...result },
|
|
_meta: {
|
|
runtimeId: result.runtime.runtimeId ?? 'none'
|
|
}
|
|
}
|
|
}
|
|
|
|
function isProcessRunning(pid: number | null | undefined): boolean {
|
|
if (!pid || pid <= 0) {
|
|
return false
|
|
}
|
|
try {
|
|
process.kill(pid, 0)
|
|
return true
|
|
} catch {
|
|
return false
|
|
}
|
|
}
|