* Pop the `-s` / `--system-prompt` flag (and its value) out of `args`. * Unlike `takeFlagValue` this accepts a value that starts with `-`, because * a system-prompt override is free-form text. Supports three forms: * -s " " --value in next arg * --system-prompt " " *
(args: string[])
| 102 | * --system-prompt=-<text> |
| 103 | */ |
| 104 | function takeSystemPrompt(args: string[]): string | undefined { |
| 105 | const longWithEq = args.findIndex((a) => a.startsWith("--system-prompt=")) |
| 106 | if (longWithEq !== -1) { |
| 107 | const value = args[longWithEq].slice("--system-prompt=".length) |
| 108 | args.splice(longWithEq, 1) |
| 109 | return value.length > 0 ? value : undefined |
| 110 | } |
| 111 | const index = args.findIndex((a) => a === "-s" || a === "--system-prompt") |
| 112 | if (index === -1) return undefined |
| 113 | const value = args[index + 1] |
| 114 | if (value === undefined) { |
| 115 | console.error("Missing value after -s / --system-prompt") |
| 116 | process.exit(1) |
| 117 | } |
| 118 | args.splice(index, 2) |
| 119 | return value |
| 120 | } |
| 121 | |
| 122 | async function main(): Promise<void> { |
| 123 | // Override Node's default process title so terminals (iTerm2 "current job |