fix: honor trans backend config for ssh

This commit is contained in:
Codex
2026-06-29 14:56:01 +00:00
parent 350aa68174
commit 1cdcf3c9a8
4 changed files with 202 additions and 41 deletions
+9 -36
View File
@@ -6,11 +6,10 @@
// Exposes AgentRun lane-scoped policy, AipodSpec SecretRef binding, cancel lifecycle, and bounded default output in the UniDesk CLI.
import { chmodSync, copyFileSync, existsSync, readFileSync, statSync, writeFileSync } from "node:fs";
import { join } from "node:path";
import { spawnSync } from "node:child_process";
import { rootPath, type UniDeskConfig } from "../config";
import type { RenderedCliResult } from "../output";
import { applyLocalCaddyManagedSite } from "../pk01-caddy";
import { runSshCommandCapture, type SshCaptureResult } from "../ssh";
import { runSshCommandCapture, sshCaptureBackendPlan, type SshCaptureBackendPlan, type SshCaptureResult } from "../ssh";
import { runRemoteSshCommandCapture } from "../remote";
import { startJob } from "../jobs";
import {
@@ -114,11 +113,7 @@ export interface AgentRunSessionPolicyTarget {
export type AgentRunBridgeCaptureBackend = "local-backend-core-broker" | "remote-frontend-websocket";
export interface LocalBackendCoreStatus {
dockerExecutable: boolean;
backendCoreContainer: boolean;
error: string | null;
}
export type LocalBackendCoreStatus = SshCaptureBackendPlan["localBackendCore"];
export interface AgentRunBridgeCapturePlan {
backend: AgentRunBridgeCaptureBackend;
@@ -174,36 +169,14 @@ export function attachBridgeExecution(result: SshCaptureResult, plan: AgentRunBr
}
export function agentRunBridgeCapturePlan(config: UniDeskConfig, target: string, env: NodeJS.ProcessEnv = process.env): AgentRunBridgeCapturePlan {
const localBackendCore = detectLocalBackendCoreStatus();
const remoteHost = agentRunBridgeRemoteHost(config, env);
const runnerEnv = isAgentRunRunnerEnvironment(env);
if (runnerEnv && remoteHost !== null) {
return { backend: "remote-frontend-websocket", route: target, reason: "runner-environment", remoteHost, localBackendCore };
}
if (!localBackendCore.backendCoreContainer && remoteHost !== null) {
return { backend: "remote-frontend-websocket", route: target, reason: "local-backend-core-unavailable", remoteHost, localBackendCore };
}
return { backend: "local-backend-core-broker", route: target, reason: "main-server-local-backend-core", remoteHost: null, localBackendCore };
}
export function detectLocalBackendCoreStatus(): LocalBackendCoreStatus {
if (localBackendCoreStatusCache !== null) return localBackendCoreStatusCache;
const result = spawnSync("docker", ["ps", "--format", "{{.Names}}"], { encoding: "utf8", timeout: 2000 });
if (result.error !== undefined) {
localBackendCoreStatusCache = {
dockerExecutable: false,
backendCoreContainer: false,
error: result.error.message,
};
return localBackendCoreStatusCache;
}
const output = `${result.stdout ?? ""}\n${result.stderr ?? ""}`.trim();
localBackendCoreStatusCache = {
dockerExecutable: result.status === 0,
backendCoreContainer: result.status === 0 && String(result.stdout ?? "").split(/\r?\n/u).includes("unidesk-backend-core"),
error: result.status === 0 ? null : output || `docker ps exited ${result.status ?? "unknown"}`,
const plan = sshCaptureBackendPlan(config, env);
return {
backend: plan.backend,
route: target,
reason: plan.reason,
remoteHost: plan.remoteHost,
localBackendCore: plan.localBackendCore,
};
return localBackendCoreStatusCache;
}
export function isAgentRunRunnerEnvironment(env: NodeJS.ProcessEnv): boolean {