| 675 | } |
| 676 | |
| 677 | function writeStatusSnapshots(payload, writeDir) { |
| 678 | if (!writeDir) { |
| 679 | return null; |
| 680 | } |
| 681 | |
| 682 | const outputDir = path.resolve(writeDir); |
| 683 | fs.mkdirSync(outputDir, { recursive: true }); |
| 684 | |
| 685 | const usedNames = new Set(['index.json']); |
| 686 | const sessions = payload.sessions.map(session => { |
| 687 | const snapshotPath = getSnapshotPath(outputDir, session, usedNames); |
| 688 | atomicWriteJson(snapshotPath, { |
| 689 | generatedAt: payload.generatedAt, |
| 690 | schemaVersion: 'ecc.loop-status.session.v1', |
| 691 | session, |
| 692 | }); |
| 693 | |
| 694 | return { |
| 695 | lastEventAt: session.lastEventAt, |
| 696 | sessionId: session.sessionId, |
| 697 | signalTypes: session.signals.map(signal => signal.type), |
| 698 | snapshotPath, |
| 699 | state: session.state, |
| 700 | transcriptPath: session.transcriptPath, |
| 701 | }; |
| 702 | }); |
| 703 | |
| 704 | const indexPath = path.join(outputDir, 'index.json'); |
| 705 | atomicWriteJson(indexPath, { |
| 706 | errors: payload.errors, |
| 707 | generatedAt: payload.generatedAt, |
| 708 | schemaVersion: 'ecc.loop-status.index.v1', |
| 709 | sessionCount: payload.sessions.length, |
| 710 | sessions, |
| 711 | source: payload.source, |
| 712 | }); |
| 713 | |
| 714 | return { |
| 715 | indexPath, |
| 716 | sessionCount: payload.sessions.length, |
| 717 | }; |
| 718 | } |
| 719 | |
| 720 | function tryWriteStatusSnapshots(payload, options) { |
| 721 | if (!options.writeDir) { |