#!/usr/bin/env node
import {c,b}from'./chunk-5TAVYPOV.js';import*as r from'fs';import*as o from'path';var R={};c(R,{appendSessionWorkEntry:()=>E,clearActivityMetrics:()=>O,clearSessionWorkLog:()=>C,countNotebookReferences:()=>F,getAgentEntries:()=>m,getAgentVerdicts:()=>A,getContributingAgents:()=>M,getNotebookReferences:()=>S,getSessionActivitySummary:()=>B,readSessionWorkLog:()=>p,recordActivityMetric:()=>I,recordNotebookReference:()=>P});function E(i,e){try{let t=o.join(i,y),n=o.dirname(t);if(r.existsSync(n)||r.mkdirSync(n,{recursive:!0}),r.existsSync(t)&&r.readFileSync(t,"utf8").trim().split(`
`).filter(l=>l.trim()).length>=x)return;let a=JSON.stringify(e)+`
`;r.appendFileSync(t,a,"utf8"),e.type==="user-verdict"&&e.agent&&e.symbols?.length&&import('./agent-loader-A5FMBAFJ.js').then(({loadAgentProfile:c,saveAgentProfile:s})=>{try{let l=c(i,e.agent);if(l?.expertise){let u=e.verdict==="accepted"?.03:e.verdict==="dismissed"?-.02:e.verdict==="revised"?-.01:0;if(u!==0){for(let h of e.symbols){let f=l.expertise.find(v=>v.symbol===h);f&&(f.confidence=Math.max(0,Math.min(1,f.confidence+u)),f.sessions=(f.sessions||0)+1,f.lastTouch=new Date().toISOString());}s(e.agent,l,"global");}}}catch{}}).catch(()=>{});}catch{}}function p(i){try{let e=o.join(i,y);return r.existsSync(e)?r.readFileSync(e,"utf8").trim().split(`
`).filter(t=>t.trim()).map(t=>{try{return JSON.parse(t)}catch{return null}}).filter(t=>t!==null):[]}catch{return []}}function C(i){try{let e=o.join(i,y);r.existsSync(e)&&r.writeFileSync(e,"","utf8");}catch{}}function M(i){let e=p(i),t=new Set;for(let n of e)n.agent&&t.add(n.agent);return Array.from(t)}function m(i,e){return p(i).filter(t=>t.agent===e)}function A(i,e){let t=m(i,e),n=t.filter(s=>s.type==="agent-contribution"),a=t.filter(s=>s.type==="user-verdict"),c=[];for(let s of n)c.push({contribution:s});for(let s of a){let l=c.find(u=>!u.verdict&&u.contribution);l?l.verdict=s:c.push({verdict:s});}return c}function I(i,e){try{let t=o.join(i,d),n=o.dirname(t);r.existsSync(n)||r.mkdirSync(n,{recursive:!0});let a={timestamp:new Date().toISOString(),type:"activity",...e},c=JSON.stringify(a)+`
`;r.appendFileSync(t,c,"utf8");}catch{}}function N(i){try{let e=o.join(i,d);return r.existsSync(e)?r.readFileSync(e,"utf8").trim().split(`
`).filter(t=>t.trim()).map(t=>{try{return JSON.parse(t)}catch{return null}}).filter(t=>t!==null&&t.type==="activity"):[]}catch{return []}}function B(i){let e=N(i),t={toolCallCount:0,responsePayloadBytes:0,sessionDurationMs:0,agentBreakdown:{}};for(let n of e)if(n.toolCallCount!=null&&(t.toolCallCount+=n.toolCallCount),n.responsePayloadBytes!=null&&(t.responsePayloadBytes+=n.responsePayloadBytes),n.sessionDurationMs!=null&&(t.sessionDurationMs=Math.max(t.sessionDurationMs,n.sessionDurationMs)),n.agentId){t.agentBreakdown[n.agentId]||(t.agentBreakdown[n.agentId]={toolCalls:0,payloadBytes:0});let a=t.agentBreakdown[n.agentId];n.toolCallCount!=null&&(a.toolCalls+=n.toolCallCount),n.responsePayloadBytes!=null&&(a.payloadBytes+=n.responsePayloadBytes);}return t}function O(i){try{let e=o.join(i,d);r.existsSync(e)&&r.writeFileSync(e,"","utf8");}catch{}}function P(i,e,t,n){try{if(t.length===0)return;let a=o.join(i,g),c=o.dirname(a);r.existsSync(c)||r.mkdirSync(c,{recursive:!0});let s={timestamp:new Date().toISOString(),type:"notebook-reference",agentId:e,notebookEntryIds:t,...n?{orchestrationId:n}:{}},l=JSON.stringify(s)+`
`;r.appendFileSync(a,l,"utf8");}catch{}}function S(i){try{let e=o.join(i,g);return r.existsSync(e)?r.readFileSync(e,"utf8").trim().split(`
`).filter(t=>t.trim()).map(t=>{try{return JSON.parse(t)}catch{return null}}).filter(t=>t!==null&&t.type==="notebook-reference"):[]}catch{return []}}function F(i){return S(i).length}var y,d,x,g,W=b(()=>{y=".paradigm/events/session-log.jsonl",d=".paradigm/events/session-metrics.jsonl",x=200,g=".paradigm/events/notebook-refs.jsonl";});export{E as a,p as b,C as c,M as d,m as e,A as f,I as g,B as h,O as i,P as j,S as k,F as l,R as m,W as n};