#!/usr/bin/env node
import"./suppress-stderr.mjs";import"./ensure-deps.mjs";import{readStdin as N,getSessionId as Q,getSessionDBPath as V}from"./session-helpers.mjs";import{createSessionLoaders as W}from"./session-loaders.mjs";import{dirname as X}from"node:path";import{fileURLToPath as Y}from"node:url";var Z=X(Y(import.meta.url)),{loadSessionDB:$,loadExtract:w}=W(Z);try{let A=await N(),q=JSON.parse(A),{extractEvents:C}=await w(),{SessionDB:F}=await $(),G=V(),y=new F({dbPath:G}),z=Q(q);y.ensureSession(z,process.env.PUKU_PROJECT_DIR||process.cwd());let J=C({tool_name:q.tool_name,tool_input:q.tool_input??{},tool_response:typeof q.tool_response==="string"?q.tool_response:JSON.stringify(q.tool_response??""),tool_output:q.tool_output});for(let M of J)y.insertEvent(z,M,"PostToolUse");y.close()}catch{}
