fix: persist and select device-pod profiles
This commit is contained in:
@@ -6,9 +6,16 @@ import https from 'node:https';
|
||||
import path from 'node:path';
|
||||
|
||||
const VERSION = '0.1.0-mvp';
|
||||
const PROFILE_DIR = process.env.DEVICE_POD_PROFILE_DIR || path.resolve(process.cwd(), '.device-pod');
|
||||
const DEFAULT_TIMEOUT_MS = 30000;
|
||||
|
||||
function defaultProfileDir() {
|
||||
if (process.env.DEVICE_POD_PROFILE_DIR) return process.env.DEVICE_POD_PROFILE_DIR;
|
||||
const candidates = ['/workspace/hwlab/.device-pod', path.resolve(process.cwd(), '.device-pod'), '/app/.device-pod'];
|
||||
return candidates.find((dir) => fs.existsSync(dir)) || path.resolve(process.cwd(), '.device-pod');
|
||||
}
|
||||
|
||||
const PROFILE_DIR = defaultProfileDir();
|
||||
|
||||
function nowIso() { return new Date().toISOString(); }
|
||||
function stripSlash(value) { return String(value || '').replace(/\/+$/u, ''); }
|
||||
function sha256(text) { return createHash('sha256').update(text).digest('hex'); }
|
||||
@@ -93,6 +100,10 @@ function cmdQuote(value) {
|
||||
return `"${text.replace(/"/g, '\\"')}"`;
|
||||
}
|
||||
|
||||
function hostProfilePath(profile) {
|
||||
return profile.hostProfilePath || `.device-pod\\${profile.podId}.json`;
|
||||
}
|
||||
|
||||
const CONTROL_OPTION_KEYS = new Set([
|
||||
'approved',
|
||||
'reason',
|
||||
@@ -181,7 +192,8 @@ async function invoke(profile, command, parsed) {
|
||||
});
|
||||
const dispatch = response.body?.result?.dispatch || response.body?.result || {};
|
||||
const hostJson = parseMaybeJson(dispatch.stdout);
|
||||
const status = response.body?.error || dispatch.exitCode !== 0 || dispatch.status === 'failed' ? 'failed' : 'succeeded';
|
||||
const hostFailed = hostJson && hostJson.ok === false;
|
||||
const status = response.body?.error || dispatch.exitCode !== 0 || dispatch.status === 'failed' || hostFailed ? 'failed' : 'succeeded';
|
||||
return { requestId, operationId, traceId, httpStatus: response.status, status, dispatch, hostJson, gatewayBody: response.body };
|
||||
}
|
||||
|
||||
@@ -236,7 +248,8 @@ async function main() {
|
||||
const profile = readProfile(selector.podId || parsed.podId);
|
||||
if (selector.kind === 'health') return print({ ok: true, action: 'health', status: 'succeeded', ...profileSummary(profile), route: routeSummary(profile) });
|
||||
const built = await buildHostCommand(selector, parsed);
|
||||
const command = `${profile.hostCli} ${built.commandArgs.map(cmdQuote).join(' ')}`;
|
||||
const hostArgs = ['--profile', hostProfilePath(profile), '--pod-id', profile.podId, ...built.commandArgs];
|
||||
const command = `${profile.hostCli} ${hostArgs.map(cmdQuote).join(' ')}`;
|
||||
if (parsed.dryRun) return print({ ok: true, action: 'device-pod.plan', status: 'planned', selector, operation: built.operation, mutating: built.mutating, command, ...profileSummary(profile), route: routeSummary(profile) });
|
||||
const result = await invoke(profile, command, parsed);
|
||||
const ok = result.status === 'succeeded';
|
||||
|
||||
Reference in New Issue
Block a user