import{appendFileSync as p,readFileSync as _,existsSync as c,mkdirSync as S}from"node:fs";import{join as r}from"node:path";var i=".zibby/output";var u="run-index.jsonl";function O(t,n=i){let o=r(t,n);return r(o,u)}function x(t){if(!t||!t.sessionId)return;let n=t.cwd||process.cwd(),o=t.outputBase||i,s=r(n,o);c(s)||S(s,{recursive:!0});let e=r(s,u),I=`${JSON.stringify(t)}
`;p(e,I,"utf8")}function a(t){if(!t||!c(t))return[];let n;try{n=_(t,"utf8")}catch{return[]}let o=[];for(let s of n.split(`
`)){let e=s.trim();if(e)try{o.push(JSON.parse(e))}catch{}}return o}function d(t){let n=new Map;for(let o of t){if(!o?.sessionId)continue;let s=n.get(o.sessionId),e=Number(o.ts)||0;(!s||e>=(Number(s.ts)||0))&&n.set(o.sessionId,o)}return n}export{u as RUN_INDEX_FILENAME,x as appendRunIndexRecord,d as latestRunRecordsBySession,a as readRunIndexRecordsFromFile,O as resolveRunIndexPath};
