clawdi 0.14.65 → 0.14.66
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +2 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -16,9 +16,9 @@ ${r}`:""}`)}}function T9(e){return $S(e,"table"),$9("nft",["list","table","inet"
|
|
|
16
16
|
`,{mode:r,dirMode:493})}function eK(e){return[e.configurationRoot,e.serviceStateRoot,e.cacheRoot,e.runRoot]}function nu(e,t){let n=J9(t);return eK(e).map((r)=>J9(r)).filter((r)=>{let i=Hke(r,n);return i===""||!i.startsWith("..")&&!zke(i)}).sort((r,i)=>i.length-r.length)[0]??null}function jh(e){for(let t of eK(e))vh(t,"platform directory")}function jS(e,t,n={}){let r=nu(e,t);if(!r)throw Error(`runtime platform directory is outside platform roots: ${t}`);zi(r,t,n)}function Jt(e,t,n,r={}){let i=nu(e,t);if(!i)throw Error(`runtime platform file is outside platform roots: ${t}`);ue(t,n,{...r,trustedRoot:i})}function cO(e=we()){for(let[t,n,r]of[[e.configurationRoot,Oh,448],[e.serviceStateRoot,tu,448],[e.cacheRoot,aO,448],[e.runRoot,Dh,457]]){let i=!Y9(t);if(i){if(t===n)throw Error(`platform directory must be created by systemd: ${t}`);Uke(t,{recursive:!0,mode:r})}if(vh(t,"platform directory"),i)Lke(t,r)}for(let[t,n]of[[e.statusRoot,493],[e.runConfigRoot,493],[e.egressProfileRoot,457],[e.systemdSystemRoot,493],[e.systemdEnvRoot,457],[e.managedSecretRoot,457]]){let r=nu(e,t);if(r)zi(r,t,{mode:n});else vh(t,"systemd platform directory")}jh(e)}function tK(e,t=we()){Q9(t,t.bootStatus,e,420)}function nK(e,t=we()){Q9(t,t.runtimeWatchStatus,{schemaVersion:"clawdi.runtimeWatchStatus.v1",timestamp:new Date().toISOString(),event:e},420)}function Vke(e){return JSON.parse(Fke(e,"utf-8"))}function Nh(e=we()){let t={exists:!1};if(Y9(e.bootStatus))try{t.exists=!0,t.source=e.bootStatus,t.status=Vke(e.bootStatus)}catch(n){return{exists:!0,source:e.bootStatus,error:n instanceof Error?n.message:String(n)}}return t}var cr=b(()=>{kt();wh();rn()});import{cpSync as qke,existsSync as oK,lstatSync as Wke,mkdirSync as Kke,mkdtempSync as Gke,readFileSync as Zke,renameSync as Jke,rmSync as Yke}from"node:fs";import{basename as ws,dirname as Xke,join as Pp,resolve as $o}from"node:path";function Rp(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}function pa(){if(dt()==="hosted")return Pp(we({mode:"hosted"}).managedResourceRoot,rK);return Pp(he(),"managed-resources",rK)}function eEe(){return{schemaVersion:uO,reservations:{},pendingReservations:{},localSetupMigrations:{}}}function dO(e,t){return ws(e)===t.id}function iK(e,t){if(!Rp(t)||t.target!==e||$o(e)!==e||typeof t.id!=="string"||!dO(e,t)||!Mh.test(t.id)||t.version!==void 0&&(typeof t.version!=="number"||!Number.isSafeInteger(t.version)||t.version<=0)||!mO(t)||t.manager!=="hosted-manifest"&&t.manager!=="local-setup")return console.warn(`ignoring invalid managed Skill ownership entry at ${e}`),null;return{target:e,id:t.id,version:t.version,digest:typeof t.digest==="string"?t.digest:void 0,sourceIdentity:typeof t.sourceIdentity==="string"?t.sourceIdentity:void 0,manager:t.manager}}function ma(e){if(!oK(e))return eEe();let t;try{let o=Wke(e);if(!o.isFile()||o.isSymbolicLink())throw Error("not a regular file");t=JSON.parse(Zke(e,"utf8"))}catch{throw Error("managed Skill ownership state is invalid")}if(!Rp(t)||t.schemaVersion!==uO||!Rp(t.reservations)||t.pendingReservations!==void 0&&!Rp(t.pendingReservations)||t.localSetupMigrations!==void 0&&!Rp(t.localSetupMigrations))throw Error("managed Skill ownership state is invalid");let n={};for(let[o,s]of Object.entries(t.reservations)){let a=iK(o,s);if(a)n[o]=a}let r={};for(let[o,s]of Object.entries(t.pendingReservations??{})){let a=iK(o,s);if(a)r[o]=a}let i={};for(let[o,s]of Object.entries(t.localSetupMigrations??{})){if(!Rp(s)||s.target!==o||$o(o)!==o||typeof s.id!=="string"||ws(o)!==s.id||!Mh.test(s.id))throw Error("managed Skill ownership state is invalid");i[o]={target:o,id:s.id}}return{schemaVersion:uO,reservations:n,pendingReservations:r,localSetupMigrations:i}}function da(e,t){let n=`${JSON.stringify(t,null,2)}
|
|
17
17
|
`,r=we({mode:"hosted"}),i={mode:420,dirMode:493};if(nu(r,e))Jt(r,e,n,i);else ue(e,n,i)}function Lh(e,t){if(e==="hosted-manifest")return t();return Bn(Pp(he(),"locks","managed-skills.lock"),()=>t())}function aK(e,t=ws(e)){let n=pO(e,t);return n==="unreserved"||n==="indeterminate"?n:"reserved"}function pO(e,t=ws(e)){let n=pa();try{let r=ma(n).reservations[$o(e)];return r?.id===t?r.manager:"unreserved"}catch{return"indeterminate"}}function ru(e){let t=ma(pa());return Object.values(t.reservations).filter((n)=>n.manager===e).map((n)=>({targetDir:n.target,id:n.id,version:n.version,digest:n.digest,sourceIdentity:n.sourceIdentity})).sort((n,r)=>n.targetDir.localeCompare(r.targetDir))}function NS(e){return Object.values(ma(pa()).pendingReservations).filter((t)=>t.manager===e).map((t)=>({targetDir:t.target,id:t.id,version:t.version,digest:t.digest,sourceIdentity:t.sourceIdentity})).sort((t,n)=>t.targetDir.localeCompare(n.targetDir))}function mO(e){let t=typeof e.digest==="string"&&sK.test(e.digest),n=e.digest!==void 0&&!t,r=typeof e.sourceIdentity==="string"&&(e.sourceIdentity.startsWith("github\x00")||e.sourceIdentity.startsWith("project\x00"))&&e.sourceIdentity.length<=2048,i=e.sourceIdentity!==void 0&&!r;if(n||i)return!1;return e.manager==="local-setup"?t&&!r:t||r}function tEe(e,t){return e.id===t.id&&e.version===t.version&&e.digest===t.digest&&e.sourceIdentity===t.sourceIdentity&&e.manager===t.manager}function Vn(e,t=ws(e)){let n;try{let r=ma(pa());n=r.reservations[$o(e)]??r.pendingReservations[$o(e)]}catch{throw Error("managed Skill ownership state is invalid")}if(!n)return!1;if(n.id!==t&&ws($o(e))===n.id)return!1;return!0}function nEe(e,t=ws(e)){if(Vn(e,t))throw Error(`Skill ${t} is reserved by a managed Skill owner`)}function wi(e,t,n){let r=()=>(nEe(e,t),n());if(dt()==="hosted")return k9(we({mode:"hosted"}),r);return Bn(Pp(he(),"locks","managed-skills.lock"),r)}function qn(e){if(dt()==="hosted")return"hosted";let t=pa(),n=$o(e.targetDir);if(e.id!=="clawdi"||ws(n)!==e.id||!Mh.test(e.id)||!Number.isSafeInteger(e.version)||e.version<=0)throw Error("managed Skill migration identity is invalid");return Lh("local-setup",()=>{let r=ma(t);if(r.localSetupMigrations[n])return"already_migrated";let i=r.reservations[n],o="absent";if(!i&&oK(n)){let s;try{s=e.digest(n)}catch{o="unmanaged"}if(s!==void 0&&!sK.test(s))throw Error("managed Skill migration digest is invalid");if(s!==void 0&&Qke.has(s))r.reservations[n]={target:n,id:e.id,version:e.version,digest:s,manager:"local-setup"},o="adopted";else if(s!==void 0)o="unmanaged"}return r.localSetupMigrations[n]={target:n,id:e.id},da(t,r),o})}function lK(e){let t=pa(),n=$o(e.targetDir);if(!dO(n,e)||!Mh.test(e.id)||e.version!==void 0&&(!Number.isSafeInteger(e.version)||e.version<=0)||!mO(e))throw Error("managed Skill reservation identity is invalid");return Lh(e.manager,()=>{let r=ma(t),i=r.reservations[n],o=r.pendingReservations[n],s=e.manager;if(i&&(i.manager!==s||i.id!==e.id))throw Error(`managed Skill ${e.id} is owned by a different manager`);if(o)throw Error(`managed Skill ${e.id} has a pending installation that requires recovery`);return r.reservations[n]={target:n,id:e.id,version:e.version,digest:e.digest,sourceIdentity:e.sourceIdentity,manager:s},da(t,r),i?"existing":"created"})}function MS(e,t,n){let r=pa(),i=$o(e.targetDir);if(!dO(i,e)||!Mh.test(e.id)||e.version!==void 0&&(!Number.isSafeInteger(e.version)||e.version<=0)||!mO(e))throw Error("managed Skill reservation identity is invalid");return Lh(e.manager,()=>{let o=ma(r),s=o.reservations[i],a=o.pendingReservations[i];if(s&&(s.manager!==e.manager||s.id!==e.id))throw Error(`managed Skill ${e.id} is owned by a different manager`);if(a&&!tEe(a,e))throw Error(`managed Skill ${e.id} is pending for a different installation`);o.pendingReservations[i]={target:i,id:e.id,version:e.version,digest:e.digest,sourceIdentity:e.sourceIdentity,manager:e.manager},da(r,o);let l;try{l=t()}catch(c){if(n.nativeMutation&&(a||!(c instanceof Ct)||c.targetMutationStarted!==!1))throw c;throw delete o.pendingReservations[i],da(r,o),c}if(!n.verify()){if(n.nativeMutation)throw new Ct(`managed Skill ${e.id} native installation requires retry`);if(n.discard(),s?.id===e.id&&s.manager===e.manager)delete o.reservations[i];throw delete o.pendingReservations[i],da(r,o),new Ct(`managed Skill ${e.id} installation could not be verified`)}return o.reservations[i]={target:i,id:e.id,version:e.version,digest:e.digest,sourceIdentity:e.sourceIdentity,manager:e.manager},delete o.pendingReservations[i],da(r,o),l})}function cK(e){let t=pa(),n=$o(e.targetDir);return Lh(e.manager,()=>{let r=ma(t),i=r.pendingReservations[n];if(!i)return"absent";if(i.id!==e.id||i.manager!==e.manager)throw Error("pending managed Skill reservation identity mismatch");if(e.verify())return r.reservations[n]={target:n,id:i.id,version:i.version,digest:i.digest,sourceIdentity:i.sourceIdentity,manager:i.manager},delete r.pendingReservations[n],da(t,r),"promoted";if(e.retryNative)return"retry";let o=r.reservations[n];if(o&&o.id===i.id&&o.manager===i.manager)delete r.reservations[n];return e.discard(),delete r.pendingReservations[n],da(t,r),"discarded"})}function LS(e,t,n={}){let r=Xke(t);Kke(r,{recursive:!0});let i=Gke(Pp(r,`.${ws(t)}-stage-`)),o=Pp(i,ws(t));try{qke(e,o,{recursive:!0}),Ep({target:t,beforeRestore:n.beforeRestore,beforeCleanup:n.beforeCleanup,restoreFailure:(s,a)=>{let l=s instanceof Error?s.message:String(s),c=a instanceof Error?a.message:String(a);return Error(`Skill activation failed: ${l}; restoring the previous version failed: ${c}; previous version retained as a recovery artifact`,{cause:s})},operation:()=>{n.beforeActivate?.(),Jke(o,t),n.afterActivate?.()}})}finally{Yke(i,{recursive:!0,force:!0})}}function US(e){let t=pa(),n=$o(e.targetDir);return Lh(e.manager,()=>{let r=ma(t),i=r.reservations[n];if(!i)return"absent";if(i.id!==e.id||i.manager!==e.manager)throw Error("managed Skill reservation identity mismatch");return e.removeTarget(),delete r.reservations[n],da(t,r),"removed"})}var rK="managed-skills.json",uO="clawdi.managedSkillReservations.v1",Mh,sK,Qke;var xo=b(()=>{Ce();ys();kt();GI();eu();rn();cr();Mh=/^[a-z0-9][a-z0-9._-]{0,63}$/,sK=/^[a-f0-9]{64}$/,Qke=new Set(["d71c123874e7b43b5d182bf9367af372dc3e3a5c9ed1f0b273478a06204b1299","aa26ff9fe7784855e220aa35a7c0e84c131b5c7e470b308c9faab1bcd3e77079","2ca7b416cc72e101d1a117eda67043c31043bcbe6987ce8f52f797042bfde3f9","0d4a6e0091493116211bbfd767ede540b510f627138c4e6714c1f3209ffa881c","3337f4aca269a9ff3fd5e1b086607092052799bc88ecb599da57b9888f4d9230","f8b4f8a999a46c7599771cda089d6d056c9abe65dc8b37411fa8f2080a13b9f6","4f635dd155cb3a67a2955c5a83954b24514d8e40c5d72a36e2e3c60f4e495ca1","cfce9adc538b4538829a23767fc171db62e474e28fd89ef5ce494b26223d31a0","4aee715a987cad84716ca71a6e1d7da80e9c1eca103c0c41aefdee31ed77974d","a6114f592aca24f0cd556c6929980151e83f062759e484771dca87fb74ab21ca","af4fff56451253a3d9f6ab1b1c9dbf6dceeba0ff7a22707eed668b7fdee75b57","27230fda71e178f7301bec27e428047558321afd71ec6d1ebaf8ea8a9659f5e4"])});import{existsSync as uK}from"node:fs";import{homedir as rEe}from"node:os";import{isAbsolute as dK,join as qr,relative as iEe}from"node:path";function _s(e,t){return t.some((n)=>{let r=iEe(n,e);return r===""||!r.startsWith("..")&&!dK(r)})}function iu(){return process.env.HOME||rEe()}function $p(){return process.env.CLAUDE_CONFIG_DIR?.trim()||qr(iu(),".claude")}function xp(){return process.env.CODEX_HOME?.trim()||qr(iu(),".codex")}function pK(){let e=process.env.GH_CONFIG_DIR?.trim();if(e)return e;let t=process.env.XDG_CONFIG_HOME?.trim();if(t)return qr(t,"gh");let n=process.env.APPDATA?.trim()||process.env.AppData?.trim();if(process.platform==="win32"&&n)return qr(n,"GitHub CLI");return qr(iu(),".config","gh")}function Ip(){return process.env.HERMES_HOME?.trim()||qr(iu(),".hermes")}function Uh(){return process.env.PI_CODING_AGENT_DIR?.trim()||qr(iu(),".pi","agent")}function Fh(){return qr(Uh(),"sessions")}function Cp(){let e=process.env.XDG_DATA_HOME?.trim()||qr(iu(),".local","share");return qr(e,"opencode")}function zh(){let e=process.env.OPENCODE_DB?.trim();if(!e)return qr(Cp(),"opencode.db");return e===":memory:"||dK(e)?e:qr(Cp(),e)}function FS(){let e=process.env.OPENCLAW_STATE_DIR?.trim();if(e)return e;let t=iu();for(let n of[".openclaw",".clawdbot",".moltbot"]){let r=qr(t,n);if(uK(r))return r}for(let n of["/data/openclaw","/var/openclaw"])if(uK(n))return n;return qr(t,".openclaw")}var Io;var bs=b(()=>{Io=new Set(["node_modules",".git","dist","build","__pycache__"])});import{createHash as gK}from"node:crypto";import{isIP as oEe}from"node:net";import{basename as sEe}from"node:path";function ye(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)?e:null}function T(e){return typeof e==="string"&&e.length>0?e:null}function fa(e){let t=[],n=e.split(`
|
|
18
18
|
`);for(let r=0;r<n.length;r++){let i=n[r]?.trim();if(!i)continue;try{let o=ye(JSON.parse(i));if(o)t.push({data:o,recordSeq:r})}catch{}}return t}function br(e){if(e===void 0)return;if(typeof e==="string")try{let n=Hh(JSON.parse(e));return n===void 0?void 0:ln(n)}catch{return ln(e)}let t=Hh(e);return t===void 0?void 0:ln(t)}function Op(e,t){for(let n of[e.uuid,e.id,ye(e.payload)?.id]){let r=T(n);if(r)return r}return`line-${t}-${gK("sha256").update(ln(e),"ascii").digest("hex").slice(0,16)}`}function mK(e){return gK("sha256").update(e).digest("hex")}function cEe(e){if(!e)return null;try{let t=new URL(e);if(t.protocol!=="https:"||t.username||t.password||t.search||t.hash||oEe(t.hostname)!==0||t.hostname==="localhost"||t.hostname.endsWith(".localhost")||t.hostname.endsWith(".local"))return null;return e}catch{return null}}function fO(e){if(!e)return null;let t=e.replaceAll("\\","/"),n=sEe(t);return n&&n!=="."&&n!=="/"?n:null}function uEe(e){if(!e)return null;try{return fO(decodeURIComponent(new URL(e,"https://invalid.local").pathname))}catch{return fO(e)}}function fK(...e){for(let t of e)if(typeof t==="number"&&Number.isSafeInteger(t)&&t>=0)return t;return null}function dEe(e){let t=ye(e.source),n=ye(e.image_url),r=T(e.uri)??T(e.url)??T(e.image_url)??T(n?.url)??T(t?.url),i=T(e.path)??T(t?.path),o=T(e.provider_ref)??T(e.file_id)??T(e.fileId)??T(t?.file_id),s=o?encodeURIComponent(o):null,a=s&&s.length<=4000?`provider-ref:${s}`:null,l=cEe(r)??a,c=T(e.data)??T(t?.data),u=c?Buffer.from(c,"base64"):null,d=u?mK(u):T(e.sha256),p=T(e.media_type)??T(e.mime_type)??T(e.mimeType)??T(t?.media_type),m=T(e.name)??T(e.filename)??fO(i)??uEe(r),f=fK(e.size_bytes,e.size,u?.length),g=T(e.id)??o??(d?`content:${d}`:null)??i??r??ln({name:m,media_type:p,size_bytes:fK(e.size_bytes,e.size)});return{type:"attachment",attachment_id:`sha256:${mK(g)}`,availability:l?"external":"metadata_only",...l?{uri:l}:{},...m?{name:m}:{},...p?{media_type:p}:{},...f===null?{}:{size_bytes:f},...d&&/^[0-9a-f]{64}$/.test(d)?{sha256:d}:{}}}function Wn(e){if(typeof e==="string")return e?[{type:"text",text:e}]:[];let t=Array.isArray(e)?e:ye(e)?[e]:[],n=[];for(let r of t){let i=ye(r);if(!i)continue;if((i.type==="text"||i.type==="input_text"||i.type==="output_text")&&typeof i.text==="string"&&i.text){n.push({type:"text",text:i.text});continue}if(!["image","image_url","input_image","file","document"].includes(String(i.type)))continue;n.push(dEe(i))}return n}function pEe(e){let t=ye(e),n=[];for(let r of[t?.thinking,t?.reasoning,t?.text])if(typeof r==="string"&&r)n.push(r);for(let r of[t?.summary,t?.content]){if(!Array.isArray(r))continue;for(let i of r){let o=ye(i),s=T(o?.text);if(s)n.push(s)}}return n.map((r)=>({type:"text",text:r}))}function Sr(e){let t=ye(e);if(!t)return null;let n=T(t.type);if(n!=="thinking"&&n!=="reasoning"&&n!=="redacted_thinking"&&n!=="encrypted_content")return null;let r=n==="encrypted_content"||n==="redacted_thinking"?[]:pEe(t),i=T(t.signature)??T(t.thinkingSignature)??T(t.thoughtSignature),o=T(t.encrypted_content)??T(t.encryptedContent)??(n==="encrypted_content"?T(t.data)??T(t.text):null),s=n==="redacted_thinking"?T(t.data):null,a=t.reasoning_details??t.reasoningDetails,l=t.codex_reasoning_items??t.codexReasoningItems,c={...i?{signature:i}:{},...o?{encrypted_content:o}:{},...s?{redacted_data:s}:{},...a===void 0?{}:{details:a},...l===void 0?{}:{items:l}},u=Object.keys(c).length>0?ln(c):void 0;if(r.length===0&&u===void 0)return null;return{kind:n==="redacted_thinking"||n==="encrypted_content"?"redacted":n==="reasoning"?"reasoning":"thinking",parts:r,...u?{payload_json:u}:{}}}function Hh(e){if(Array.isArray(e)){let i=e.map((o)=>Hh(o)).filter((o)=>o!==void 0);return e.length>0&&i.length===0?void 0:i}let t=ye(e);if(!t)return e;let n=T(t.type);if(n&&aEe.has(n))return;let r={};for(let[i,o]of Object.entries(t)){let s=i.replaceAll(/[^a-zA-Z0-9]/g,"").toLowerCase();if(lEe.has(s))continue;let a=Hh(o);if(a!==void 0)r[i]=a}return Object.keys(t).length>0&&Object.keys(r).length===0?void 0:r}function kr(e,t=void 0){let n=Wn(e);if(n.length===0&&typeof t==="string"&&t)n.push({type:"text",text:t});let r=t===void 0?e:t;if(typeof r==="string"||r===void 0)return{parts:n};let i=Hh(r);return i===void 0?{parts:n}:{parts:n,result_json:ln(i)}}var aEe,lEe;var ou=b(()=>{ta();aEe=new Set(["text","input_text","output_text","image","input_image","file","document","thinking","redacted_thinking","reasoning"]),lEe=new Set(["encryptedcontent","encryptedreasoning","redactedthinking","reasoning","signature","thinking","thinkingsignature"])});import{execFileSync as mEe}from"node:child_process";function _i(e,t){try{return mEe(e,t,{encoding:"utf-8",stdio:"pipe",timeout:fEe,windowsHide:!0}).trim().split(`
|
|
19
|
-
`)[0]||null}catch{return null}}var fEe=1500;var su=()=>{};import{existsSync as bi,readdirSync as Dp,readFileSync as hK,rmSync as gEe}from"node:fs";import{basename as gO,join as gn,relative as hEe,resolve as hO}from"node:path";function Oo(){return $p()}function ga(){return gn(Oo(),"projects")}function yEe(e,t,n){let r=ye(e.message);if(!r)return[];let i=T(r.role),o=T(e.timestamp)??void 0,s=T(r.model)??void 0,a=Op(e,n),l=(d)=>({adapter:"claude_code",session_key:t,record_id:a,record_seq:n,...d===void 0?{}:{part_index:d}}),c=[];if(i==="user"||i==="assistant"||i==="system"||i==="developer"){let d=Wn(r.content);if(d.length>0)c.push({type:"message",role:i,parts:d,source:l(0),...o?{timestamp:o}:{},...i==="assistant"&&s?{model:s}:{}})}let u=Array.isArray(r.content)?r.content:[];for(let d=0;d<u.length;d++){let p=ye(u[d]);if(!p)continue;let m=i==="assistant"?Sr(p):null;if(m)c.push({type:"reasoning",...m,source:l(d+1),...o?{timestamp:o}:{},...s?{model:s}:{}});if(i==="assistant"&&p.type==="tool_use"){let f=T(p.id),g=T(p.name);if(!f||!g)continue;c.push({type:"tool_call",call_id:f,name:g,arguments_json:br(p.input),source:l(d+1),...o?{timestamp:o}:{},...s?{model:s}:{}})}if(i==="user"&&p.type==="tool_result"){let f=T(p.tool_use_id);if(!f)continue;let g=kr(p.content);c.push({type:"tool_result",call_id:f,status:p.is_error===!0?"error":"completed",...g,source:l(d+1),...o?{timestamp:o}:{}})}}return c}class yO{agentType="claude_code";sessions={contentProtocol:async()=>"events-v1",collect:(e)=>this.collectSessions(e),resolve:(e)=>this.resolveSession(e),watchPaths:()=>this.getSessionsWatchPaths()};skills={collect:()=>this.collectSkills(),listKeys:()=>this.listSkillKeys(),path:(e)=>this.getSkillPath(e),rootDir:()=>this.getSkillsRootDir(),sharedPath:(e,t)=>this.getSharedSkillPath(e,t),writeArchive:(e,t)=>this.writeSkillArchive(e,t),writeSharedArchive:(e,t,n)=>this.writeSharedSkillArchive(e,t,n),remove:(e)=>this.removeLocalSkill(e)};async detect(){if(bi(Oo())&&(bi(ga())||bi(gn(Oo(),"settings.json"))||bi(gn(Oo(),"CLAUDE.md"))))return!0;return await this.getVersion()!==null}async getVersion(){return _i("claude",["--version"])}pathToProjectDir(e){return e.replace(/\//g,"-")}async collectSessions(e){if(!bi(ga()))return{sessions:[],dedupedCount:0,coverage:"complete"};let{projectFilter:t}=e,n=t?hO(t):null;if(e.kind==="paths"){let i=hO(ga()),o=new Set;for(let s of e.paths){let a=hO(s),l=hEe(i,a).split(/[\\/]/);if(!_s(a,[i])||l.length!==2||!l[1].endsWith(".jsonl"))return this.collectSessions({kind:"complete",projectFilter:t});o.add(l[0])}if(o.size>0)return this.collectProjectSessions([...o],n,"partial")}let r=Dp(ga(),{withFileTypes:!0}).filter((i)=>i.isDirectory());if(n){let i=this.pathToProjectDir(n);r=r.filter((o)=>o.name===i||o.name.startsWith(`${i}-`))}return this.collectProjectSessions(r.map((i)=>i.name),n,"complete")}async resolveSession(e){if(!bi(ga())||gO(e)!==e)return null;let t=[];for(let n of Dp(ga(),{withFileTypes:!0})){if(!n.isDirectory())continue;let r=gn(ga(),n.name,`${e}.jsonl`);if(bi(r))t.push({filePath:r,projectDirName:n.name})}if(t.length!==1){if(t.length===0)return null;return(await this.collectSessions({kind:"complete"})).sessions.find((n)=>n.localSessionId===e)??null}return this.collectProjectSessions([t[0].projectDirName],null,"partial").sessions.find((n)=>n.localSessionId===e)??null}collectProjectSessions(e,t,n){let r=[],i=new Map;for(let o of e){let s=gn(ga(),o);if(!bi(s))continue;for(let a of Dp(s).filter((l)=>l.endsWith(".jsonl")))try{let l=this.parseRawSession(gn(s,a),o);if(!l)continue;let c=l.session.projectPath;if(t&&(!c||c!==t&&!c.startsWith(`${t}/`)))continue;r.push(l.session),i.set(l.session,l.uuidSet)}catch{}}return vEe(r,i,n)}parseRawSession(e,t){let n=this.parseSessionJsonl(e,t);if(!n)return null;let{uuidSet:r,...i}=n;return{session:{...i,localSessionId:gO(e,".jsonl"),rawFilePath:e},uuidSet:r}}parseSessionJsonl(e,t){let n=hK(e,"utf-8"),r=fa(n);if(r.length<3)return null;let i=0,o=0,s=0,a=null,l=null,c=null,u=new Set,d=null,p=null,m=[],f=new Set;for(let{data:S,recordSeq:k}of r)try{let E=S;m.push({raw:S,recordSeq:k});let A=E.message,x=A?.role;if(E.uuid)f.add(E.uuid);if(E.timestamp){let j=new Date(E.timestamp);if(!a)a=j;l=j}if(E.cwd&&!d)d=E.cwd;if(x==="user"&&!p){let j=A?.content;if(typeof j==="string")p=or(j,200);else if(Array.isArray(j)){let M=j.find((q)=>q.type==="text"&&q.text);if(M?.text)p=or(M.text,200)}}if(x==="assistant"&&A?.model)u.add(A.model),c=A.model;if(A?.usage)i+=A.usage.input_tokens??0,o+=A.usage.output_tokens??0,s+=A.usage.cache_read_input_tokens??0}catch{}let g=gO(e,".jsonl"),y=fi(m.flatMap(({raw:S,recordSeq:k})=>yEe(S,g,k))),w=gi(y);if(!a||w.length===0)return null;let _=mi(a,l);return{projectPath:d,startedAt:a,endedAt:l,messageCount:w.length,inputTokens:i,outputTokens:o,cacheReadTokens:s,model:c,modelsUsed:[...u],summary:p,messages:w,events:y,durationSeconds:_,uuidSet:f}}async collectSkills(){let e=gn(Oo(),"skills");if(qn({targetDir:gn(e,"clawdi"),id:"clawdi",version:1,digest:tn}),!bi(e))return[];let t=[];for(let n of Dp(e,{withFileTypes:!0})){if(!n.isDirectory())continue;if(n.name.startsWith("."))continue;if(Io.has(n.name))continue;let r=gn(e,n.name);if(Vn(r,n.name))continue;let i=gn(r,"SKILL.md");if(!bi(i))continue;let o=hK(i,"utf-8"),s=Dp(r,{recursive:!0}).length;t.push({skillKey:n.name,name:n.name,content:o,filePath:i,directoryPath:r,isDirectory:s>1})}return t}getSkillPath(e){return gn(Oo(),"skills",e,"SKILL.md")}getSkillsRootDir(){return gn(Oo(),"skills")}getSharedSkillPath(e,t){return gn(Oo(),"skills",`${e}__${t}`)}async listSkillKeys(){let e=gn(Oo(),"skills");if(qn({targetDir:gn(e,"clawdi"),id:"clawdi",version:1,digest:tn}),!bi(e))return[];let t=[];for(let n of Dp(e,{withFileTypes:!0})){if(!n.isDirectory())continue;if(n.name.startsWith("."))continue;if(Io.has(n.name))continue;if(Vn(gn(e,n.name),n.name))continue;let r=gn(e,n.name,"SKILL.md");if(!bi(r))continue;t.push(n.name)}return t}getSessionsWatchPaths(){return[ga()]}async removeLocalSkill(e){let t=gn(Oo(),"skills",e);wi(t,e,()=>{if(bi(t))gEe(t,{recursive:!0,force:!0})})}async writeSkillArchive(e,t){let n=gn(Oo(),"skills"),r=gn(n,e);await la(e,n,r,t,void 0,(i)=>wi(r,e,i))}async writeSharedSkillArchive(e,t,n){await la(e,this.getSkillsRootDir(),this.getSharedSkillPath(e,t),n)}}function vEe(e,t,n){let r=new Map;for(let o of e){let s=o.projectPath??"<no-project>",a=r.get(s);if(a)a.push(o);else r.set(s,[o])}let i=new Set;for(let o of r.values()){if(o.length<2)continue;let s=o.filter((a)=>(t.get(a)?.size??0)>=10).sort((a,l)=>(t.get(a)?.size??0)-(t.get(l)?.size??0));for(let a=0;a<s.length;a++){let l=s[a],c=t.get(l);if(!c)continue;
|
|
19
|
+
`)[0]||null}catch{return null}}var fEe=1500;var su=()=>{};import{existsSync as bi,readdirSync as Dp,readFileSync as hK,rmSync as gEe}from"node:fs";import{basename as gO,join as gn,relative as hEe,resolve as hO}from"node:path";function Oo(){return $p()}function ga(){return gn(Oo(),"projects")}function yEe(e,t,n){let r=ye(e.message);if(!r)return[];let i=T(r.role),o=T(e.timestamp)??void 0,s=T(r.model)??void 0,a=Op(e,n),l=(d)=>({adapter:"claude_code",session_key:t,record_id:a,record_seq:n,...d===void 0?{}:{part_index:d}}),c=[];if(i==="user"||i==="assistant"||i==="system"||i==="developer"){let d=Wn(r.content);if(d.length>0)c.push({type:"message",role:i,parts:d,source:l(0),...o?{timestamp:o}:{},...i==="assistant"&&s?{model:s}:{}})}let u=Array.isArray(r.content)?r.content:[];for(let d=0;d<u.length;d++){let p=ye(u[d]);if(!p)continue;let m=i==="assistant"?Sr(p):null;if(m)c.push({type:"reasoning",...m,source:l(d+1),...o?{timestamp:o}:{},...s?{model:s}:{}});if(i==="assistant"&&p.type==="tool_use"){let f=T(p.id),g=T(p.name);if(!f||!g)continue;c.push({type:"tool_call",call_id:f,name:g,arguments_json:br(p.input),source:l(d+1),...o?{timestamp:o}:{},...s?{model:s}:{}})}if(i==="user"&&p.type==="tool_result"){let f=T(p.tool_use_id);if(!f)continue;let g=kr(p.content);c.push({type:"tool_result",call_id:f,status:p.is_error===!0?"error":"completed",...g,source:l(d+1),...o?{timestamp:o}:{}})}}return c}class yO{agentType="claude_code";sessions={contentProtocol:async()=>"events-v1",collect:(e)=>this.collectSessions(e),resolve:(e)=>this.resolveSession(e),watchPaths:()=>this.getSessionsWatchPaths()};skills={collect:()=>this.collectSkills(),listKeys:()=>this.listSkillKeys(),path:(e)=>this.getSkillPath(e),rootDir:()=>this.getSkillsRootDir(),sharedPath:(e,t)=>this.getSharedSkillPath(e,t),writeArchive:(e,t)=>this.writeSkillArchive(e,t),writeSharedArchive:(e,t,n)=>this.writeSharedSkillArchive(e,t,n),remove:(e)=>this.removeLocalSkill(e)};async detect(){if(bi(Oo())&&(bi(ga())||bi(gn(Oo(),"settings.json"))||bi(gn(Oo(),"CLAUDE.md"))))return!0;return await this.getVersion()!==null}async getVersion(){return _i("claude",["--version"])}pathToProjectDir(e){return e.replace(/\//g,"-")}async collectSessions(e){if(!bi(ga()))return{sessions:[],dedupedCount:0,coverage:"complete"};let{projectFilter:t}=e,n=t?hO(t):null;if(e.kind==="paths"){let i=hO(ga()),o=new Set;for(let s of e.paths){let a=hO(s),l=hEe(i,a).split(/[\\/]/);if(!_s(a,[i])||l.length!==2||!l[1].endsWith(".jsonl"))return this.collectSessions({kind:"complete",projectFilter:t});o.add(l[0])}if(o.size>0)return this.collectProjectSessions([...o],n,"partial")}let r=Dp(ga(),{withFileTypes:!0}).filter((i)=>i.isDirectory());if(n){let i=this.pathToProjectDir(n);r=r.filter((o)=>o.name===i||o.name.startsWith(`${i}-`))}return this.collectProjectSessions(r.map((i)=>i.name),n,"complete")}async resolveSession(e){if(!bi(ga())||gO(e)!==e)return null;let t=[];for(let n of Dp(ga(),{withFileTypes:!0})){if(!n.isDirectory())continue;let r=gn(ga(),n.name,`${e}.jsonl`);if(bi(r))t.push({filePath:r,projectDirName:n.name})}if(t.length!==1){if(t.length===0)return null;return(await this.collectSessions({kind:"complete"})).sessions.find((n)=>n.localSessionId===e)??null}return this.collectProjectSessions([t[0].projectDirName],null,"partial").sessions.find((n)=>n.localSessionId===e)??null}collectProjectSessions(e,t,n){let r=[],i=new Map;for(let o of e){let s=gn(ga(),o);if(!bi(s))continue;for(let a of Dp(s).filter((l)=>l.endsWith(".jsonl")))try{let l=this.parseRawSession(gn(s,a),o);if(!l)continue;let c=l.session.projectPath;if(t&&(!c||c!==t&&!c.startsWith(`${t}/`)))continue;r.push(l.session),i.set(l.session,l.uuidSet)}catch{}}return vEe(r,i,n)}parseRawSession(e,t){let n=this.parseSessionJsonl(e,t);if(!n)return null;let{uuidSet:r,...i}=n;return{session:{...i,localSessionId:gO(e,".jsonl"),rawFilePath:e},uuidSet:r}}parseSessionJsonl(e,t){let n=hK(e,"utf-8"),r=fa(n);if(r.length<3)return null;let i=0,o=0,s=0,a=null,l=null,c=null,u=new Set,d=null,p=null,m=[],f=new Set;for(let{data:S,recordSeq:k}of r)try{let E=S;m.push({raw:S,recordSeq:k});let A=E.message,x=A?.role;if(E.uuid)f.add(E.uuid);if(E.timestamp){let j=new Date(E.timestamp);if(!a)a=j;l=j}if(E.cwd&&!d)d=E.cwd;if(x==="user"&&!p){let j=A?.content;if(typeof j==="string")p=or(j,200);else if(Array.isArray(j)){let M=j.find((q)=>q.type==="text"&&q.text);if(M?.text)p=or(M.text,200)}}if(x==="assistant"&&A?.model)u.add(A.model),c=A.model;if(A?.usage)i+=A.usage.input_tokens??0,o+=A.usage.output_tokens??0,s+=A.usage.cache_read_input_tokens??0}catch{}let g=gO(e,".jsonl"),y=fi(m.flatMap(({raw:S,recordSeq:k})=>yEe(S,g,k))),w=gi(y);if(!a||w.length===0)return null;let _=mi(a,l);return{projectPath:d,startedAt:a,endedAt:l,messageCount:w.length,inputTokens:i,outputTokens:o,cacheReadTokens:s,model:c,modelsUsed:[...u],summary:p,messages:w,events:y,durationSeconds:_,uuidSet:f}}async collectSkills(){let e=gn(Oo(),"skills");if(qn({targetDir:gn(e,"clawdi"),id:"clawdi",version:1,digest:tn}),!bi(e))return[];let t=[];for(let n of Dp(e,{withFileTypes:!0})){if(!n.isDirectory())continue;if(n.name.startsWith("."))continue;if(Io.has(n.name))continue;let r=gn(e,n.name);if(Vn(r,n.name))continue;let i=gn(r,"SKILL.md");if(!bi(i))continue;let o=hK(i,"utf-8"),s=Dp(r,{recursive:!0}).length;t.push({skillKey:n.name,name:n.name,content:o,filePath:i,directoryPath:r,isDirectory:s>1})}return t}getSkillPath(e){return gn(Oo(),"skills",e,"SKILL.md")}getSkillsRootDir(){return gn(Oo(),"skills")}getSharedSkillPath(e,t){return gn(Oo(),"skills",`${e}__${t}`)}async listSkillKeys(){let e=gn(Oo(),"skills");if(qn({targetDir:gn(e,"clawdi"),id:"clawdi",version:1,digest:tn}),!bi(e))return[];let t=[];for(let n of Dp(e,{withFileTypes:!0})){if(!n.isDirectory())continue;if(n.name.startsWith("."))continue;if(Io.has(n.name))continue;if(Vn(gn(e,n.name),n.name))continue;let r=gn(e,n.name,"SKILL.md");if(!bi(r))continue;t.push(n.name)}return t}getSessionsWatchPaths(){return[ga()]}async removeLocalSkill(e){let t=gn(Oo(),"skills",e);wi(t,e,()=>{if(bi(t))gEe(t,{recursive:!0,force:!0})})}async writeSkillArchive(e,t){let n=gn(Oo(),"skills"),r=gn(n,e);await la(e,n,r,t,void 0,(i)=>wi(r,e,i))}async writeSharedSkillArchive(e,t,n){await la(e,this.getSkillsRootDir(),this.getSharedSkillPath(e,t),n)}}function vEe(e,t,n){let r=new Map;for(let o of e){let s=o.projectPath??"<no-project>",a=r.get(s);if(a)a.push(o);else r.set(s,[o])}let i=new Set;for(let o of r.values()){if(o.length<2)continue;let s=o.filter((a)=>(t.get(a)?.size??0)>=10).sort((a,l)=>(t.get(a)?.size??0)-(t.get(l)?.size??0));for(let a=0;a<s.length;a++){let l=s[a],c=t.get(l);if(!c)continue;for(let u=a+1;u<s.length;u++){let d=s[u],p=t.get(d);if(!p||p.size<=c.size)continue;let m=!0;for(let f of c)if(!p.has(f)){m=!1;break}if(m){i.add(l.localSessionId);break}}}}return{sessions:e.filter((o)=>!i.has(o.localSessionId)),dedupedCount:i.size,coverage:n}}var yK=b(()=>{sr();ta();Hr();Ro();xo();bs();ou();su()});import{existsSync as Si,readdirSync as zS,readFileSync as vK,rmSync as wEe}from"node:fs";import{join as Er,resolve as _O}from"node:path";function Bh(){return xp()}function bO(){return Er(Bh(),"sessions")}function wK(){return Er(Bh(),"archived_sessions")}function vO(){return[bO(),wK()]}function Wr(){return Er(Bh(),"skills")}function _Ee(e,t,n){if(e.type!=="response_item")return[];let r=ye(e.payload);if(!r)return[];let i=T(r.type),o=T(e.timestamp)??void 0,s=T(r.id)??T(r.call_id)??Op(e,n),a=(l)=>({adapter:"codex",session_key:t,record_id:s,record_seq:n,...l===void 0?{}:{part_index:l}});if(i==="message"){let l=T(r.role);if(l!=="user"&&l!=="assistant"&&l!=="system"&&l!=="developer")return[];let c=Wn(r.content);return c.length>0?[{type:"message",role:l,parts:c,source:a(),...o?{timestamp:o}:{}}]:[]}if(i==="reasoning"){let l=Sr(r);return l?[{type:"reasoning",...l,source:a(),...o?{timestamp:o}:{}}]:[]}if(i==="function_call"||i==="custom_tool_call"){let l=T(r.call_id)??T(r.id),c=T(r.name);if(!l||!c)return[];return[{type:"tool_call",call_id:l,name:c,arguments_json:br(i==="function_call"?r.arguments:r.input),source:a(),...o?{timestamp:o}:{}}]}if(i==="function_call_output"||i==="custom_tool_call_output"){let l=T(r.call_id)??T(r.id);if(!l)return[];let c=kr(r.output);return[{type:"tool_result",call_id:l,status:r.status==="failed"?"error":"completed",...c,source:a(),...o?{timestamp:o}:{}}]}if(i==="tool_search_call"){let l=T(r.call_id)??T(r.id);if(!l)return[];return[{type:"tool_call",call_id:l,name:"tool_search",arguments_json:br({execution:r.execution,arguments:r.arguments}),source:a(),...o?{timestamp:o}:{}}]}if(i==="tool_search_output"){let l=T(r.call_id)??T(r.id);if(!l)return[];return[{type:"tool_result",call_id:l,name:"tool_search",status:r.status==="failed"?"error":"completed",...kr(void 0,{execution:r.execution,tools:r.tools}),source:a(),...o?{timestamp:o}:{}}]}if(i==="image_generation_call"){let l=T(r.id)??s,c=kr([{type:"image",data:r.result,media_type:"image/png",name:"generated-image.png"}]);return[{type:"tool_call",call_id:l,name:"image_generation",arguments_json:br({revised_prompt:r.revised_prompt}),source:a(0),...o?{timestamp:o}:{}},{type:"tool_result",call_id:l,name:"image_generation",status:r.status==="failed"?"error":"completed",...c,source:a(1),...o?{timestamp:o}:{}}]}if(i==="agent_message"){let l=Array.isArray(r.content)?r.content:[],c=l.map((m)=>ye(m)).filter((m)=>m?.type==="input_text").map((m)=>T(m.text)).filter((m)=>m!==null).join(`
|
|
20
20
|
`),u=T(r.author),d=T(r.recipient),p=[];if(c&&u&&d)p.push({type:"message",role:"developer",parts:[{type:"text",text:`[Agent message from ${u} to ${d}]
|
|
21
|
-
${c}`}],source:a(),...o?{timestamp:o}:{}});for(let m=0;m<l.length;m++){let f=Sr(l[m]);if(!f)continue;p.push({type:"reasoning",...f,source:a(m+1),...o?{timestamp:o}:{}})}return p}if(i==="local_shell_call"){let l=T(r.call_id)??T(r.id);if(!l)return[];return[{type:"tool_call",call_id:l,name:"shell",arguments_json:br(r.action),source:a(),...o?{timestamp:o}:{}}]}if(i==="web_search_call"){let l=T(r.id);if(!l)return[];return[{type:"tool_call",call_id:l,name:"web_search",arguments_json:br(r.action),source:a(),...o?{timestamp:o}:{}}]}return[]}function bEe(e,t){if(!t||e.type==="tool_result"||e.type==="message"&&e.role!=="assistant")return e;return{...e,model:t}}function SEe(e){let t=[];if(!Si(e))return t;let n=(r)=>{let i;try{i=zS(r,{withFileTypes:!0})}catch{return}for(let o of i){if(o.name.startsWith("."))continue;let s=Er(r,o.name);if(o.isDirectory())n(s);else if(o.isFile()&&o.name.endsWith(".jsonl"))t.push(s)}};return n(e),t}function kEe(e){return e?_O(e):null}function wO(e,t){let n;try{n=vK(e,"utf-8")}catch{return null}let r=fa(n);if(r.length===0)return null;let i=null,o=null,s=null,a=null,l=null,c=new Set,u=[],d=0,p=0,m=0;for(let{data:w,recordSeq:_}of r){let S=w,k=S.timestamp?new Date(S.timestamp):null;if(k&&!Number.isNaN(k.getTime())){if(!s)s=k;a=k}if(S.type==="session_meta"){if(i=S.payload?.id??i,o=S.payload?.cwd??o,S.payload?.timestamp){let E=new Date(S.payload.timestamp);if(!Number.isNaN(E.getTime()))s=E}continue}if(S.type==="turn_context"){let E=S.payload?.model;if(E)l=E,c.add(E);continue}if(S.type==="event_msg"&&S.payload?.type==="token_count"){let E=S.payload.info?.total_token_usage;if(E)d=E.input_tokens??d,p=E.output_tokens??p,m=E.cached_input_tokens??m}u.push({raw:w,recordSeq:_,model:l})}if(!i)return null;let f=fi(u.flatMap(({raw:w,recordSeq:_,model:S})=>_Ee(w,i,_).map((k)=>bEe(k,S)))),g=gi(f);if(g.length===0||!s)return null;
|
|
21
|
+
${c}`}],source:a(),...o?{timestamp:o}:{}});for(let m=0;m<l.length;m++){let f=Sr(l[m]);if(!f)continue;p.push({type:"reasoning",...f,source:a(m+1),...o?{timestamp:o}:{}})}return p}if(i==="local_shell_call"){let l=T(r.call_id)??T(r.id);if(!l)return[];return[{type:"tool_call",call_id:l,name:"shell",arguments_json:br(r.action),source:a(),...o?{timestamp:o}:{}}]}if(i==="web_search_call"){let l=T(r.id);if(!l)return[];return[{type:"tool_call",call_id:l,name:"web_search",arguments_json:br(r.action),source:a(),...o?{timestamp:o}:{}}]}return[]}function bEe(e,t){if(!t||e.type==="tool_result"||e.type==="message"&&e.role!=="assistant")return e;return{...e,model:t}}function SEe(e){let t=[];if(!Si(e))return t;let n=(r)=>{let i;try{i=zS(r,{withFileTypes:!0})}catch{return}for(let o of i){if(o.name.startsWith("."))continue;let s=Er(r,o.name);if(o.isDirectory())n(s);else if(o.isFile()&&o.name.endsWith(".jsonl"))t.push(s)}};return n(e),t}function kEe(e){return e?_O(e):null}function wO(e,t){let n;try{n=vK(e,"utf-8")}catch{return null}let r=fa(n);if(r.length===0)return null;let i=null,o=null,s=null,a=null,l=null,c=new Set,u=[],d=0,p=0,m=0;for(let{data:w,recordSeq:_}of r){let S=w,k=S.timestamp?new Date(S.timestamp):null;if(k&&!Number.isNaN(k.getTime())){if(!s)s=k;a=k}if(S.type==="session_meta"){if(i=S.payload?.id??i,o=S.payload?.cwd??o,S.payload?.timestamp){let E=new Date(S.payload.timestamp);if(!Number.isNaN(E.getTime()))s=E}continue}if(S.type==="turn_context"){let E=S.payload?.model;if(E)l=E,c.add(E);continue}if(S.type==="event_msg"&&S.payload?.type==="token_count"){let E=S.payload.info?.total_token_usage;if(E)d=E.input_tokens??d,p=E.output_tokens??p,m=E.cached_input_tokens??m}u.push({raw:w,recordSeq:_,model:l})}if(!i)return null;if(t){if(typeof o!=="string")return null;if(o!==t&&!o.startsWith(`${t}/`))return null}let f=fi(u.flatMap(({raw:w,recordSeq:_,model:S})=>_Ee(w,i,_).map((k)=>bEe(k,S)))),g=gi(f);if(g.length===0||!s)return null;a??=s;let y=g.find((w)=>w.role==="user"&&!w.content.startsWith("<environment_context>"));return{localSessionId:i,projectPath:o,startedAt:s,endedAt:a,messageCount:g.length,inputTokens:d,outputTokens:p,cacheReadTokens:m,model:l,modelsUsed:[...c],durationSeconds:mi(s,a),summary:y?or(y.content,200):null,messages:g,events:f,rawFilePath:e}}class SO{agentType="codex";sessionPaths=new Map;sessions={contentProtocol:async()=>"events-v1",collect:(e)=>this.collectSessions(e),resolve:(e)=>this.resolveSession(e),watchPaths:()=>this.getSessionsWatchPaths()};skills={collect:()=>this.collectSkills(),listKeys:()=>this.listSkillKeys(),path:(e)=>this.getSkillPath(e),rootDir:()=>this.getSkillsRootDir(),sharedPath:(e,t)=>this.getSharedSkillPath(e,t),writeArchive:(e,t)=>this.writeSkillArchive(e,t),writeSharedArchive:(e,t,n)=>this.writeSharedSkillArchive(e,t,n),remove:(e)=>this.removeLocalSkill(e)};async detect(){if(!Si(Bh()))return!1;return Si(bO())||Si(wK())||Si(Er(Bh(),"config.toml"))}async getVersion(){return _i("codex",["--version"])}async collectSessions(e){let t=kEe(e.projectFilter);if(e.kind==="paths"){if(e.paths.length===0)return this.collectSessions({kind:"complete",projectFilter:e.projectFilter});let i=vO().map((a)=>_O(a)),o=new Set;for(let a of e.paths.map((l)=>_O(l))){if(!_s(a,i)||!a.endsWith(".jsonl"))return this.collectSessions({kind:"complete",projectFilter:e.projectFilter});for(let[l,c]of this.sessionPaths)if(c===a&&!Si(a))this.sessionPaths.delete(l);if(Si(a))o.add(a)}let s=new Map;for(let a of o){let l=wO(a,t);if(l)s.set(l.localSessionId,l),this.sessionPaths.set(l.localSessionId,a)}return{sessions:[...s.values()],dedupedCount:0,coverage:"partial"}}let n=new Map,r=new Map;for(let i of vO())for(let o of SEe(i)){let s=wO(o,t);if(s&&!n.has(s.localSessionId))n.set(s.localSessionId,s),r.set(s.localSessionId,o)}if(e.projectFilter)for(let[i,o]of r)this.sessionPaths.set(i,o);else this.sessionPaths=r;return{sessions:[...n.values()],dedupedCount:0,coverage:"complete"}}async resolveSession(e){let t=this.sessionPaths.get(e);if(t){let n=wO(t,null);if(n?.localSessionId===e)return n;this.sessionPaths.delete(e)}return(await this.collectSessions({kind:"complete"})).sessions.find((n)=>n.localSessionId===e)??null}async collectSkills(){if(qn({targetDir:Er(Wr(),"clawdi"),id:"clawdi",version:1,digest:tn}),!Si(Wr()))return[];let e=[];for(let t of zS(Wr(),{withFileTypes:!0})){if(!t.isDirectory())continue;if(t.name.startsWith("."))continue;if(Io.has(t.name))continue;let n=Er(Wr(),t.name);if(Vn(n,t.name))continue;let r=Er(n,"SKILL.md");if(!Si(r))continue;let i=vK(r,"utf-8"),o=zS(n,{recursive:!0}).length;e.push({skillKey:t.name,name:t.name,content:i,filePath:r,directoryPath:n,isDirectory:o>1})}return e}getSkillPath(e){return Er(Wr(),e,"SKILL.md")}async listSkillKeys(){if(qn({targetDir:Er(Wr(),"clawdi"),id:"clawdi",version:1,digest:tn}),!Si(Wr()))return[];let e=[];for(let t of zS(Wr(),{withFileTypes:!0})){if(!t.isDirectory())continue;if(t.name.startsWith("."))continue;if(Io.has(t.name))continue;if(Vn(Er(Wr(),t.name),t.name))continue;let n=Er(Wr(),t.name,"SKILL.md");if(!Si(n))continue;e.push(t.name)}return e}getSkillsRootDir(){return Wr()}getSharedSkillPath(e,t){return Er(Wr(),`${e}__${t}`)}getSessionsWatchPaths(){let e=vO().filter((t)=>Si(t));return e.length>0?e:[bO()]}async removeLocalSkill(e){let t=Er(Wr(),e);wi(t,e,()=>{if(Si(t))wEe(t,{recursive:!0,force:!0})})}async writeSkillArchive(e,t){let n=Wr(),r=Er(n,e);await la(e,n,r,t,void 0,(i)=>wi(r,e,i))}async writeSharedSkillArchive(e,t,n){await la(e,this.getSkillsRootDir(),this.getSharedSkillPath(e,t),n)}}var _K=b(()=>{sr();ta();Hr();Ro();xo();bs();ou();su()});async function Tp(e){if(typeof globalThis.Bun<"u"){let{Database:r}=await import("bun:sqlite"),i=new r(e,{readonly:!0});return{prepare:(o)=>{let s=i.prepare(o);return{all:(...a)=>s.all(...a),get:(...a)=>s.get(...a)}},close:()=>i.close()}}let{DatabaseSync:t}=await import("node:sqlite"),n=new t(e,{readOnly:!0});return{prepare:(r)=>{let i=n.prepare(r);return{all:(...o)=>i.all(...o),get:(...o)=>i.get(...o)}},close:()=>n.close()}}import{createHash as EEe}from"node:crypto";import{existsSync as ha,readdirSync as kO,readFileSync as AEe,rmSync as REe}from"node:fs";import{join as ki,relative as PEe}from"node:path";function EO(e){return e.prepare("PRAGMA table_info(messages)").all()}function kK(e){let t=e.find((n)=>n.name==="id");return t?.pk===1&&t.type.trim().toUpperCase()==="INTEGER"&&CEe.every((n)=>e.some((r)=>r.name===n))}function IEe(e){let t=new Set(e.map((n)=>n.name));return["id","role","content",...$Ee.map(([n,r])=>t.has(n)?n:`${r} AS ${n}`),"timestamp"].join(", ")}function OEe(e){let t=new Set(e.map((r)=>r.name)),n=(r,i)=>t.has(r)?r:`${i} AS ${r}`;return`
|
|
22
22
|
SELECT json_group_array(
|
|
23
23
|
json_array(
|
|
24
24
|
id, timestamp, active, compacted, display_kind, display_metadata,
|
package/package.json
CHANGED