| 29 | } |
| 30 | |
| 31 | function logTurnItems(items: ThreadItem[], options: Agent.RunOptions): void { |
| 32 | for (const item of items) { |
| 33 | try { |
| 34 | process.stdout.write(`${options.logger.format(JSON.stringify(item))}\n`); |
| 35 | } catch (error) { |
| 36 | const sanitizedItem = |
| 37 | item.type === "command_execution" |
| 38 | ? { ...item, aggregated_output: "<omitted>" } |
| 39 | : item; |
| 40 | process.stdout.write( |
| 41 | `${options.logger.format(JSON.stringify(sanitizedItem))}\n`, |
| 42 | ); |
| 43 | if (error instanceof Error) { |
| 44 | process.stderr.write( |
| 45 | `${options.logger.format( |
| 46 | `Failed to serialize Codex item: ${error.message}`, |
| 47 | )}\n`, |
| 48 | ); |
| 49 | } |
| 50 | } |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | function getOrCreateThread(model: string, cwd: string): Thread { |
| 55 | const key = sessionKey(model, cwd); |