fix: support device-pod flash-vector launch

This commit is contained in:
Codex
2026-05-27 23:24:14 +08:00
parent 91f1eb30e6
commit 078ca04941
4 changed files with 204 additions and 14 deletions
+37 -9
View File
@@ -93,25 +93,53 @@ function cmdQuote(value) {
return `"${text.replace(/"/g, '\\"')}"`;
}
const CONTROL_OPTION_KEYS = new Set([
'approved',
'reason',
'dryRun',
'full',
'timeoutMs',
'traceId',
'podId',
'patch',
'patchB64',
]);
function camelToKebab(value) {
return String(value).replace(/[A-Z]/gu, (match) => `-${match.toLowerCase()}`);
}
function hostOptionArgs(parsed) {
const out = [];
for (const [key, value] of Object.entries(parsed)) {
if (key === '_' || CONTROL_OPTION_KEYS.has(key) || value === undefined || value === false) continue;
const name = `--${camelToKebab(key)}`;
if (value === true) out.push(name);
else out.push(name, String(value));
}
return out;
}
async function buildHostCommand(selector, parsed) {
const args = [];
const options = hostOptionArgs(parsed);
const operation = parsed._[0] || (selector.surface === 'workspace' ? 'ls' : selector.surface === 'debug-probe' ? 'status' : 'read');
const mutating = isMutating(selector.surface, operation);
if (mutating) requireApproval(parsed, `${selector.surface}.${operation}`);
if (selector.surface === 'workspace') {
const workspacePath = selector.path.replace(/^\/+/, '') || '.';
if (operation === 'ls' || operation === 'cat') args.push('workspace', operation, parsed._[1] ? path.posix.join(workspacePath, parsed._[1]) : workspacePath, ...parsed._.slice(2));
else if (operation === 'rg') args.push('workspace', 'rg', parsed._[1] || '', workspacePath, ...parsed._.slice(2));
if (operation === 'ls' || operation === 'cat') args.push('workspace', operation, parsed._[1] ? path.posix.join(workspacePath, parsed._[1]) : workspacePath, ...parsed._.slice(2), ...options);
else if (operation === 'rg') args.push('workspace', 'rg', parsed._[1] || '', workspacePath, ...parsed._.slice(2), ...options);
else if (operation === 'apply-patch') args.push('workspace', 'apply-patch', workspacePath, '--patch-b64', Buffer.from(await resolvePatchText(parsed), 'utf8').toString('base64'));
else if (operation === 'build') args.push('workspace', 'build', ...(parsed._.slice(1).length ? parsed._.slice(1) : ['start']));
else if (operation === 'build') args.push('workspace', 'build', ...(parsed._.slice(1).length ? parsed._.slice(1) : ['start']), ...options);
else throw new Error(`unsupported workspace command: ${operation}`);
} else if (selector.surface === 'debug-probe') {
args.push('debug-probe', operation, ...parsed._.slice(1));
args.push('debug-probe', operation, ...parsed._.slice(1), ...options);
} else if (selector.surface === 'io-probe') {
const probePath = selector.path.replace(/^\/+/, '') || 'uart/1';
if (probePath.startsWith('inner/')) throw new Error(`unsupported io-probe path in MVP: ${probePath}`);
args.push('io-probe', probePath, operation, ...parsed._.slice(1));
args.push('io-probe', probePath, operation, ...parsed._.slice(1), ...options);
} else {
throw new Error(`unsupported surface: ${selector.surface}`);
}
@@ -120,8 +148,8 @@ async function buildHostCommand(selector, parsed) {
function isMutating(surface, operation) {
return (surface === 'workspace' && operation === 'apply-patch')
|| (surface === 'debug-probe' && (operation === 'download' || operation === 'reset'))
|| (surface === 'io-probe' && operation === 'write');
|| (surface === 'debug-probe' && (operation === 'download' || operation === 'reset' || operation === 'launch-flash'))
|| (surface === 'io-probe' && (operation === 'write' || operation === 'read-after-launch-flash'));
}
function requireApproval(parsed, operation) {
if (parsed.approved === true && typeof parsed.reason === 'string' && parsed.reason.trim()) return;
@@ -195,8 +223,8 @@ function help() {
'node tools/device-pod-cli.mjs device-pod-71-freq:workspace:/firmware cat main.c',
'node tools/device-pod-cli.mjs device-pod-71-freq:workspace:/ apply-patch --approved --reason "DEV edit" < patch.diff',
'node tools/device-pod-cli.mjs device-pod-71-freq:workspace:/ build start|status <jobId>',
'node tools/device-pod-cli.mjs device-pod-71-freq:debug-probe chip-id|status|download|reset --approved --reason "DEV smoke"',
'node tools/device-pod-cli.mjs device-pod-71-freq:io-probe:/uart/1 ports|read|write --approved --reason "DEV io"'
'node tools/device-pod-cli.mjs device-pod-71-freq:debug-probe chip-id|status|download|reset|launch-flash --approved --reason "DEV smoke"',
'node tools/device-pod-cli.mjs device-pod-71-freq:io-probe:/uart/1 ports|read|read-after-launch-flash|write --approved --reason "DEV io"'
] });
}