* 通过 stdin 发送数据启动进程 * 用于需要通过 stdin 传递结构化数据的场景(如图片) * * 注意:这里使用临时文件方式,因为 PTY 不适合传递大量结构化数据
(
config: ExecutorSpawnConfig,
commandParts: CommandParts,
stdinData: string
)
| 384 | }); |
| 385 | |
| 386 | shell.onExit(({ exitCode, signal }) => { |
| 387 | offData.dispose(); |
| 388 | ptyLog(shell.pid, `PTY exited code=${exitCode} signal=${signal}`); |
| 389 | if (exitCode !== 0) { |
| 390 | const cleaned = stripAnsiSequences(outputBuffer).replace(/\s+/g, ' ').trim(); |
| 391 | if (cleaned) { |
| 392 | ptyLog(shell.pid, `full output: ${cleaned.slice(0, 1000)}`); |
| 393 | } |
| 394 | writeErrorLog({ |
| 395 | level: 'warn', |
| 396 | source: 'executor.exit', |
| 397 | message: `${this.displayName} exited with non-zero code ${exitCode}`, |
| 398 | metadata: { |
| 399 | agentType: this.agentType, |
| 400 | displayName: this.displayName, |
| 401 | pid: shell.pid, |
| 402 | exitCode, |
| 403 | signal, |
| 404 | workingDir: config.workingDir, |
| 405 | output: cleaned ? cleaned.slice(0, 2000) : undefined, |
| 406 | }, |
| 407 | }); |
| 408 | } |
| 409 | }); |
| 410 | |
| 411 | // 监听取消信号 |
| 412 | cancel.onCancelled(() => { |
| 413 | // 发送 SIGINT 进行优雅关闭 |
| 414 | shell.kill('SIGINT'); |
| 415 | }); |
| 416 | |
| 417 | return { |
| 418 | pid: shell.pid, |
| 419 | pty: shell, |
| 420 | cancel, |
| 421 | takeEarlyEvents, |
| 422 | }; |
| 423 | } |
| 424 | |
| 425 | /** |
| 426 | * 通过 stdin 发送数据启动进程 |
| 427 | * 用于需要通过 stdin 传递结构化数据的场景(如图片) |
| 428 | * |
| 429 | * 注意:这里使用临时文件方式,因为 PTY 不适合传递大量结构化数据 |
| 430 | */ |
| 431 | protected async spawnWithStdin( |
| 432 | config: ExecutorSpawnConfig, |
| 433 | commandParts: CommandParts, |
| 434 | stdinData: string |
| 435 | ): Promise<SpawnedChild> { |
| 436 | const { programPath, args } = await resolveCommandParts(commandParts); |
| 437 | const env = config.env.withProfile(this.cmdOverrides); |
| 438 | |
| 439 | const cancel = new CancellationToken(); |
| 440 | |
| 441 | // 不添加 prompt 到参数列表,因为会通过 stdin 发送 |
| 442 | const fullArgs = [...args]; |
| 443 |
nothing calls this directly
no test coverage detected