// Extra command-line arguments as editable flag/value rows. Pure; shared by the runtime and // deployment forms. The stored form stays a token list (one argv entry per item). export type ArgRow = { flag: string; value: string }; const isFlag = (t: string) => t.startsWith("-") && !/^-\d/.test(t); /** Tokens → rows: a flag takes the following non-flag token as its value. */ export function argsToRows(tokens: string[]): ArgRow[] { const rows: ArgRow[] = []; for (const t of tokens) { const last = rows.at(-1); // "--flag=value" stays one token, so it is shown (and passed) exactly as written. if (!isFlag(t) && last && last.flag && !last.value && !last.flag.includes("=")) last.value = t; else if (isFlag(t)) rows.push({ flag: t, value: "" }); else rows.push({ flag: "", value: t }); } return rows; } /** Rows → tokens, skipping empty rows. */ export function rowsToArgs(rows: ArgRow[]): string[] { return rows.flatMap((r) => [r.flag.trim(), r.value.trim()].filter(Boolean)); }