import{execFileSync as N}from"node:child_process";import{createHash as G}from"node:crypto";import{join as C}from"node:path";import{mkdirSync as J}from"node:fs";import{homedir as L}from"node:os";function M(){let b=process.env.CONTEXT_MODE_SESSION_SUFFIX;if(b!==void 0)return b?`__${b}`:"";try{let q=process.cwd(),z=N("git",["worktree","list","--porcelain"],{encoding:"utf-8",timeout:2000,stdio:["ignore","pipe","ignore"]}).split(/\r?\n/).find((B)=>B.startsWith("worktree "))?.replace("worktree ","")?.trim();if(z&&q!==z)return`__${G("sha256").update(q).digest("hex").slice(0,8)}`}catch{}return""}var E={configDir:process.env.PUKU_CONFIG_DIR??process.env.CONTEXT_MODE_CONFIG_DIR??".puku-cli",projectDirEnv:"PUKU_PROJECT_DIR",sessionIdEnv:"PUKU_SESSION_ID"},$={configDir:".gemini",projectDirEnv:"GEMINI_PROJECT_DIR",sessionIdEnv:void 0},A={configDir:".vscode",projectDirEnv:"VSCODE_CWD",sessionIdEnv:void 0},F={configDir:".cursor",projectDirEnv:"CURSOR_CWD",sessionIdEnv:"CURSOR_SESSION_ID"},R={configDir:".codex",projectDirEnv:void 0,sessionIdEnv:void 0},w={configDir:".kiro",projectDirEnv:void 0,sessionIdEnv:void 0};function y(){return new Promise((b,q)=>{let z="";process.stdin.setEncoding("utf-8"),process.stdin.on("data",(B)=>{z+=B}),process.stdin.on("end",()=>b(z.replace(/^\uFEFF/,""))),process.stdin.on("error",q),process.stdin.resume()})}function I(b=E){return process.env[b.projectDirEnv]||process.cwd()}function H(b,q=E){if(typeof b?.cwd==="string"&&b.cwd.length>0)return b.cwd;if(Array.isArray(b?.workspace_roots)&&b.workspace_roots.length>0)return String(b.workspace_roots[0]);return I(q)}function W(b,q=E){if(b.transcript_path){let z=b.transcript_path.match(/([a-f0-9-]{36})\.jsonl$/);if(z)return z[1]}if(b.conversation_id)return b.conversation_id;if(b.sessionId)return b.sessionId;if(b.session_id)return b.session_id;if(q.sessionIdEnv&&process.env[q.sessionIdEnv])return process.env[q.sessionIdEnv];return`pid-${process.ppid}`}function v(b=E){let q=I(b),z=G("sha256").update(q).digest("hex").slice(0,16),B=C(L(),b.configDir,"context-mode","sessions");return J(B,{recursive:!0}),C(B,`${z}${M()}.db`)}function K(b=E){let q=I(b),z=G("sha256").update(q).digest("hex").slice(0,16),B=C(L(),b.configDir,"context-mode","sessions");return J(B,{recursive:!0}),C(B,`${z}${M()}-events.md`)}function O(b=E){let q=I(b),z=G("sha256").update(q).digest("hex").slice(0,16),B=C(L(),b.configDir,"context-mode","sessions");return J(B,{recursive:!0}),C(B,`${z}${M()}.cleanup`)}export{y as readStdin,W as getSessionId,K as getSessionEventsPath,v as getSessionDBPath,I as getProjectDir,H as getInputProjectDir,O as getCleanupFlagPath,A as VSCODE_OPTS,w as KIRO_OPTS,$ as GEMINI_OPTS,F as CURSOR_OPTS,R as CODEX_OPTS};
