(options: RunCliOptions)
| 246 | } |
| 247 | |
| 248 | async function runPlannotatorCli(options: RunCliOptions): Promise<RunCliResult> { |
| 249 | const readyFile = path.join( |
| 250 | tmpdir(), |
| 251 | `plannotator-opencode-${process.pid}-${Date.now()}-${randomUUID()}.jsonl`, |
| 252 | ); |
| 253 | const loggedUrls = new Set<string>(); |
| 254 | const cwd = options.cwd || process.cwd(); |
| 255 | const env = { |
| 256 | ...process.env, |
| 257 | ...options.extraEnv, |
| 258 | ...buildCliBridgeEnv(options.bridge), |
| 259 | OPENCODE: "1", |
| 260 | PLANNOTATOR_ORIGIN: "opencode", |
| 261 | PLANNOTATOR_CWD: cwd, |
| 262 | PLANNOTATOR_READY_FILE: readyFile, |
| 263 | }; |
| 264 | |
| 265 | const bin = getPlannotatorBin(); |
| 266 | const spawnConfig = buildCliSpawnConfig(bin, options.args); |
| 267 | log(options.client, "info", `[Plannotator] Starting ${options.readyLabel}...`); |
| 268 | |
| 269 | return await new Promise((resolve, reject) => { |
| 270 | const child = spawn(spawnConfig.command, spawnConfig.args, { |
| 271 | cwd, |
| 272 | env, |
| 273 | shell: spawnConfig.shell, |
| 274 | stdio: ["pipe", "pipe", "pipe"], |
| 275 | }); |
| 276 | |
| 277 | let stdout = ""; |
| 278 | let stderr = ""; |
| 279 | const stderrForwarder = createCliStderrForwarder(options.client); |
| 280 | const interval = setInterval( |
| 281 | () => logReadyFile(options.client, readyFile, options.readyLabel, loggedUrls), |
| 282 | 250, |
| 283 | ); |
| 284 | |
| 285 | if (!child.stdin || !child.stdout || !child.stderr) { |
| 286 | clearInterval(interval); |
| 287 | rmSync(readyFile, { force: true }); |
| 288 | reject(new Error("Failed to open pipes for the plannotator CLI process.")); |
| 289 | return; |
| 290 | } |
| 291 | |
| 292 | child.stdout.setEncoding("utf-8"); |
| 293 | child.stderr.setEncoding("utf-8"); |
| 294 | child.stdout.on("data", (chunk) => { |
| 295 | stdout += chunk; |
| 296 | }); |
| 297 | child.stderr.on("data", (chunk) => { |
| 298 | stderr += chunk; |
| 299 | stderrForwarder.push(chunk); |
| 300 | }); |
| 301 | child.on("error", (error: NodeJS.ErrnoException) => { |
| 302 | clearInterval(interval); |
| 303 | stderrForwarder.flush(); |
| 304 | logReadyFile(options.client, readyFile, options.readyLabel, loggedUrls); |
| 305 | rmSync(readyFile, { force: true }); |
no test coverage detected