MCPcopy Index your code
hub / github.com/ChinaSiro/claude-code-sourcemap / om

Function om

package/cli.js:7683–7683  ·  view source on GitHub ↗
(q)

Source from the content-addressed store, hash-verified

7681`).join("");return await gS6($,A,{encoding:"utf8",mode:384}),N(`Hydrated ${z.length} entries from remote`),z.length>0}catch(z){return N(`Error hydrating session from remote: ${z}`),c8("error","hydrate_remote_session_fail"),!1}finally{_.setRemoteIngressUrl(K)}}async function g97(q){let K=Date.now();Of(EX(q));let _=dY(),z=_.getInternalEventReader();if(!z)return N("No internal event reader registered for CCR v2 resume"),!1;try{let Y=await z();if(!Y)return N("Failed to read internal events for resume"),c8("error","hydrate_ccr_v2_read_fail"),!1;let $=_2(r1());await BS6($,{recursive:!0,mode:448});let A=JT(q),O=Y.map((H)=>g6(H.payload)+`
7682`).join("");await gS6(A,O,{encoding:"utf8",mode:384}),N(`Hydrated ${Y.length} foreground entries from CCR v2 internal events`);let w=0,j=_.getInternalSubagentEventReader();if(j){let H=await j();if(H&&H.length>0){w=H.length;let J=new Map;for(let M of H){let X=M.agent_id||"";if(!X)continue;let P=J.get(X);if(!P)P=[],J.set(X,P);P.push(M.payload)}for(let[M,X]of J){let P=c0(pO(M));await BS6(Iq8(P),{recursive:!0,mode:448});let W=X.map((D)=>g6(D)+`
7683`).join("");await gS6(P,W,{encoding:"utf8",mode:384})}N(`Hydrated ${H.length} subagent entries across ${J.size} agents`)}}return c8("info","hydrate_ccr_v2_completed",{duration_ms:Date.now()-K,event_count:Y.length,subagent_event_count:w}),Y.length>0}catch(Y){if(Y instanceof Error&&Y.message==="CCRClient: Epoch mismatch (409)")throw Y;return N(`Error hydrating session from CCR v2: ${Y}`),c8("error","hydrate_ccr_v2_fail"),!1}}function F97(q){let K=wq8(q);if(K){let _=K.replace(/\n/g," ").trim();if(_.length>200)_=_.slice(0,200).trim()+"…";return _}return"No prompt"}function wq8(q){for(let K of q){if(K.type!=="user"||K.isMeta)continue;if("isCompactSummary"in K&&K.isCompactSummary)continue;let _=K.message?.content;if(!_)continue;let z=[];if(typeof _==="string")z.push(_);else if(Array.isArray(_)){for(let Y of _)if(Y.type==="text"&&Y.text)z.push(Y.text)}for(let Y of z){if(!Y)continue;let $=o4(Y,CZ);if($){let O=$.replace(/^\//,"");if(RQ().has(O))continue;else{let w=o4(Y,"command-args")?.trim();if(!w)continue;return`${$} ${w}`}}let A=o4(Y,"bash-input");if(A)return`! ${A}`;if(NBK.test(Y))continue;return Y}}return}function KL6(q){return q.map((K)=>{let{isSidechain:_,parentUuid:z,...Y}=K;return Y})}function xRY(q){let K,_=-1,z=-1,Y=new Map,$=0;for(let j of q.values()){if(Y.set(j.uuid,$),bD(j)){z=$;let H=j.compactMetadata?.preservedSegment;if(H)K=H,_=$}$++}if(!K)return;let A=_===z,O=new Set;if(A){let j=new Set,H=q.get(K.tailUuid),J=!1;while(H&&!j.has(H.uuid)){if(j.add(H.uuid),O.add(H.uuid),H.uuid===K.headUuid){J=!0;break}H=H.parentUuid?q.get(H.parentUuid):void 0}if(!J){d("tengu_relink_walk_broken",{tailInTranscript:q.has(K.tailUuid),headInTranscript:q.has(K.headUuid),anchorInTranscript:q.has(K.anchorUuid),walkSteps:j.size,transcriptSize:q.size});return}}if(A){let j=q.get(K.headUuid);if(j)q.set(K.headUuid,{...j,parentUuid:K.anchorUuid});for(let[H,J]of q)if(J.parentUuid===K.anchorUuid&&H!==K.headUuid)q.set(H,{...J,parentUuid:K.tailUuid});for(let H of O){let J=q.get(H);if(J?.type!=="assistant")continue;q.set(H,{...J,message:{...J.message,usage:{...J.message.usage,input_tokens:0,output_tokens:0,cache_creation_input_tokens:0,cache_read_input_tokens:0}}})}}let w=[];for(let[j]of q){let H=Y.get(j);if(H!==void 0&&H<z&&!O.has(j))w.push(j)}for(let j of w)q.delete(j)}function IRY(q){let K=new Set;for(let A of q.values()){let O=A.snipMetadata?.removedUuids;if(!O)continue;for(let w of O)K.add(w)}if(K.size===0)return;let _=new Map,z=0;for(let A of K){let O=q.get(A);if(!O)continue;_.set(A,O.parentUuid),q.delete(A),z++}let Y=(A)=>{let O=[],w=A;while(w&&K.has(w))if(O.push(w),w=_.get(w),w===void 0){w=null;break}for(let j of O)_.set(j,w);return w},$=0;for(let[A,O]of q){if(!O.parentUuid||!K.has(O.parentUuid))continue;q.set(A,{...O,parentUuid:Y(O.parentUuid)}),$++}d("tengu_snip_resume_filtered",{removed_count:z,relinked_count:$})}function JQ8(q,K){let _,z=-1/0;for(let Y of q){if(!K(Y))continue;let $=Date.parse(Y.timestamp);if($>z)z=$,_=Y}return _}function XK6(q,K){let _=[],z=new Set,Y=K;while(Y){if(z.has(Y.uuid)){H6(Error(`Cycle detected in parentUuid chain at message ${Y.uuid}. Returning partial transcript.`)),d("tengu_chain_parent_cycle",{});break}z.add(Y.uuid),_.push(Y),Y=Y.parentUuid?q.get(Y.parentUuid):void 0}return _.reverse(),uRY(q,_,z)}function uRY(q,K,_){let z=K.filter((J)=>J.type==="assistant");if(z.length===0)return K;let Y=new Map;for(let J of z)if(J.message.id)Y.set(J.message.id,J);let $=new Map,A=new Map;for(let J of q.values())if(J.type==="assistant"&&J.message.id){let M=$.get(J.message.id);if(M)M.push(J);else $.set(J.message.id,[J])}else if(J.type==="user"&&J.parentUuid&&Array.isArray(J.message.content)&&J.message.content.some((M)=>M.type==="tool_result")){let M=A.get(J.parentUuid);if(M)M.push(J);else A.set(J.parentUuid,[J])}let O=new Set,w=new Map,j=0;for(let J of z){let M=J.message.id;if(!M||O.has(M))continue;O.add(M);let X=$.get(M)??[J],P=X.filter((G)=>!_.has(G.uuid)),W=[];for(let G of X){let Z=A.get(G.uuid);if(!Z)continue;for(let T of Z)if(!_.has(T.uuid))W.push(T)}if(P.length===0&&W.length===0)continue;P.sort((G,Z)=>G.timestamp.localeCompare(Z.timestamp)),W.sort((G,Z)=>G.timestamp.localeCompare(Z.timestamp));let D=Y.get(M),f=[...P,...W];for(let G of f)_.add(G.uuid);j+=f.length,w.set(D.uuid,f)}if(j===0)return K;d("tengu_chain_parallel_tr_recovered",{recovered_count:j});let H=[];for(let J of K){H.push(J);let M=w.get(J.uuid);if(M)H.push(...M)}return H}function Po1(q){for(let K=q.length-1;K>=0;K--){let _=q[K];if(_.type!=="system"||_.subtype!=="turn_duration")continue;let z=_.messageCount;if(z===void 0)return;let Y=K;d("tengu_resume_consistency_delta",{expected:z,actual:Y,delta:Y-z,chain_length:q.length,checkpoint_age_entries:q.length-1-K});return}}function MQ8(q,K){let _=[],z=new Map;for(let Y of K){let $=q.get(Y.uuid);if(!$)continue;let{snapshot:A,isSnapshotUpdate:O}=$,w=O?z.get(A.messageId):void 0;if(w===void 0)z.set(A.messageId,_.length),_.push(A);else _[w]=A}return _}function XQ8(q,K){return Array.from(q.values())}async function mRY(q){if(q.endsWith(".jsonl")){let{messages:Y,summaries:$,customTitles:A,tags:O,fileHistorySnapshots:w,attributionSnapshots:j,contextCollapseCommits:H,contextCollapseSnapshot:J,leafUuids:M,contentReplacements:X,worktreeStates:P}=await $a(q);if(Y.size===0)throw Error("No messages found in JSONL file");let W=JQ8(Y.values(),(v)=>M.has(v.uuid));if(!W)throw Error("No valid conversation chain found in JSONL file");let D=XK6(Y,W),f=$.get(W.uuid),G=A.get(W.sessionId),Z=O.get(W.sessionId),T=W.sessionId;return{...S97(D,0,f,G,MQ8(w,D),Z,q,XQ8(j,D),void 0,X.get(T)??[]),contextCollapseCommits:H.filter((v)=>v.sessionId===T),contextCollapseSnapshot:J?.sessionId===T?J:void 0,worktreeSession:P.has(T)?P.get(T):void 0}}let K=await dS6(q,{encoding:"utf-8"}),_;try{_=r8(K)}catch(Y){throw Error(`Invalid JSON in transcript file: ${Y}`)}let z;if(Array.isArray(_))z=_;else if(_&&typeof _==="object"&&"messages"in _){if(!Array.isArray(_.messages))throw Error("Transcript messages must be an array");z=_.messages}else throw Error("Transcript must be an array of messages or an object with a messages array");return S97(z,0,void 0,void 0,void 0,void 0,q)}function pRY(q){if(q.type!=="user")return!1;if(q.isMeta)return!1;let K=q.message?.content;if(!K)return!1;if(typeof K==="string")return K.trim().length>0;if(Array.isArray(K))return K.some((_)=>_.type==="text"||_.type==="image"||_.type==="document");return!1}function BRY(q){if(q.type!=="assistant")return!1;let K=q.message?.content;if(!K||!Array.isArray(K))return!1;return K.some((_)=>_.type==="text"&&typeof _.text==="string"&&_.text.trim().length>0)}function U97(q){let K=0;for(let _ of q)switch(_.type){case"user":if(pRY(_))K++;break;case"assistant":if(BRY(_))K++;break;case"attachment":case"system":case"progress":break}return K}function S97(q,K=0,_,z,Y,$,A,O,w,j){let H=q.at(-1),J=q[0],M=F97(q),X=new Date(J.timestamp),P=new Date(H.timestamp);return{date:H.timestamp,messages:KL6(q),fullPath:A,value:K,created:X,modified:P,firstPrompt:M,messageCount:U97(q),isSidechain:J.isSidechain,teamName:J.teamName,agentName:J.agentName,agentSetting:w,leafUuid:H.uuid,summary:_,customTitle:z,tag:$,fileHistorySnapshots:Y,attributionSnapshots:O,contentReplacements:j,gitBranch:H.gitBranch,projectPath:J.cwd}}async function gRY(q){let K=new Map,_=0;for(let A of q){let O=SA(A);if(O){let w=(K.get(O)||0)+1;K.set(O,w),_=Math.max(w,_)}}if(_<=1)return;let z=Array.from(K.values()).filter((A)=>A>1),Y=z.length,$=z.reduce((A,O)=>A+O,0);d("tengu_session_forked_branches_fetched",{total_sessions:K.size,sessions_with_branches:Y,max_branches_per_session:Math.max(...z),avg_branches_per_session:Math.round($/Y),total_transcript_count:q.length})}async function hBK(q){let K=_2(r1()),_=await pS6(K,q,r1());return await gRY(_),_}function jZ(q,K){let _=X8(),z=g6(K)+`
7684`;try{_.appendFileSync(q,z,{mode:384})}catch{_.mkdirSync(Iq8(q),{mode:448}),_.appendFileSync(q,z,{mode:384})}}function FRY(q){let K;try{K=WRY(q,"r");let _=PRY(K),z=Math.max(0,_.size-ue),Y=Buffer.allocUnsafe(Math.min(ue,_.size-z)),$=DRY(K,Y,0,Y.length,z);return Y.toString("utf8",0,$)}catch{return""}finally{if(K!==void 0)try{XRY(K)}catch{}}}async function $s(q,K,_,z="user"){let Y=_??JT(q);if(jZ(Y,{type:"custom-title",customTitle:K,sessionId:q}),q===N8())dY().currentSessionTitle=K;d("tengu_session_renamed",{source:z})}function Q97(q,K){jZ(JT(q),{type:"ai-title",aiTitle:K,sessionId:q})}function URY(q,K){jZ(JT(q),{type:"task-summary",summary:K,sessionId:q,timestamp:new Date().toISOString()})}async function nU8(q,K,_){let z=_??JT(q);if(jZ(z,{type:"tag",tag:K,sessionId:q}),q===N8())dY().currentSessionTag=K;d("tengu_session_tagged",{})}async function QRY(q,K,_,z,Y){let $=Y??JT(q);if(jZ($,{type:"pr-link",sessionId:q,prNumber:K,prUrl:_,prRepository:z,timestamp:new Date().toISOString()}),q===N8()){let A=dY();A.currentSessionPrNumber=K,A.currentSessionPrUrl=_,A.currentSessionPrRepository=z}d("tengu_session_linked_to_pr",{prNumber:K})}function q97(q){if(q===N8())return dY().currentSessionTag;return}function k0(q){if(q===N8())return dY().currentSessionTitle;return}function d97(){return dY().currentSessionAgentColor}function Ld(q){let K=dY();if(q.customTitle)K.currentSessionTitle??=q.customTitle;if(q.tag!==void 0)K.currentSessionTag=q.tag||void 0;if(q.agentName)K.currentSessionAgentName=q.agentName;if(q.agentColor)K.currentSessionAgentColor=q.agentColor;if(q.agentSetting)K.currentSessionAgentSetting=q.agentSetting;if(q.mode)K.currentSessionMode=q.mode;if(q.worktreeSession!==void 0)K.currentSessionWorktree=q.worktreeSession;if(q.prNumber!==void 0)K.currentSessionPrNumber=q.prNumber;if(q.prUrl)K.currentSessionPrUrl=q.prUrl;if(q.prRepository)K.currentSessionPrRepository=q.prRepository}function j78(){let q=dY();q.currentSessionTitle=void 0,q.currentSessionTag=void 0,q.currentSessionAgentName=void 0,q.currentSessionAgentColor=void 0,q.currentSessionLastPrompt=void 0,q.currentSessionAgentSetting=void 0,q.currentSessionMode=void 0,q.currentSessionWorktree=void 0,q.currentSessionPrNumber=void 0,q.currentSessionPrUrl=void 0,q.currentSessionPrRepository=void 0}function xp8(){dY().reAppendSessionMetadata()}async function o78(q,K,_,z="user"){let Y=_??JT(q);if(jZ(Y,{type:"agent-name",agentName:K,sessionId:q}),q===N8())dY().currentSessionAgentName=K,cQ(K);d("tengu_agent_name_set",{source:z})}async function Gg8(q,K,_){let z=_??JT(q);if(jZ(z,{type:"agent-color",agentColor:K,sessionId:q}),q===N8())dY().currentSessionAgentColor=K;d("tengu_agent_color_set",{})}function uq8(q){dY().currentSessionAgentSetting=q}function c97(q){dY().currentSessionTitle=q}function dRY(q){dY().currentSessionMode=q}function Oy(q){let K=q?{originalCwd:q.originalCwd,worktreePath:q.worktreePath,worktreeName:q.worktreeName,worktreeBranch:q.worktreeBranch,originalBranch:q.originalBranch,originalHeadCommit:q.originalHeadCommit,sessionId:q.sessionId,tmuxSessionName:q.tmuxSessionName,hookBased:q.hookBased}:null,_=dY();if(_.currentSessionWorktree=K,_.sessionFile)jZ(_.sessionFile,{type:"worktree-state",worktreeSession:K,sessionId:N8()})}function SA(q){if(q.sessionId)return q.sessionId;return q.messages[0]?.sessionId}function qR(q){return q.messages.length===0&&q.sessionId!==void 0}async function om(q){if(!qR(q))return q;let K=q.fullPath;if(!K)return q;try{let{messages:_,summaries:z,customTitles:Y,tags:$,agentNames:A,agentColors:O,agentSettings:w,prNumbers:j,prUrls:H,prRepositories:J,modes:M,worktreeStates:X,fileHistorySnapshots:P,attributionSnapshots:W,contentReplacements:D,contextCollapseCommits:f,contextCollapseSnapshot:G,leafUuids:Z}=await $a(K);if(_.size===0)return q;let T=JQ8(_.values(),(E)=>Z.has(E.uuid)&&(E.type==="user"||E.type==="assistant"));if(!T)return q;let v=XK6(_,T),V=T.sessionId;return{...q,messages:KL6(v),firstPrompt:F97(v),messageCount:U97(v),summary:T?z.get(T.uuid):q.summary,customTitle:V?Y.get(V):q.customTitle,tag:V?$.get(V):q.tag,agentName:V?A.get(V):q.agentName,agentColor:V?O.get(V):q.agentColor,agentSetting:V?w.get(V):q.agentSetting,mode:V?M.get(V):q.mode,worktreeSession:V&&X.has(V)?X.get(V):q.worktreeSession,prNumber:V?j.get(V):q.prNumber,prUrl:V?H.get(V):q.prUrl,prRepository:V?J.get(V):q.prRepository,gitBranch:T?.gitBranch??q.gitBranch,isSidechain:v[0]?.isSidechain??q.isSidechain,teamName:v[0]?.teamName??q.teamName,leafUuid:T?.uuid??q.leafUuid,fileHistorySnapshots:MQ8(P,v),attributionSnapshots:XQ8(W,v),contentReplacements:V?D.get(V)??[]:q.contentReplacements,contextCollapseCommits:V?f.filter((E)=>E.sessionId===V):void 0,contextCollapseSnapshot:V&&G?.sessionId===V?G:void 0}}catch{return q}}async function kd(q,K){let{limit:_,exact:z}=K||{},Y=await As(r1()),$=await CBK(Y),{logs:A}=await kJ6($,0,$.length),O=q.toLowerCase().trim(),w=A.filter((J)=>{let M=J.customTitle?.toLowerCase().trim();if(!M)return!1;return z?M===O:M.includes(O)}),j=new Map;for(let J of w){let M=SA(J);if(M){let X=j.get(M);if(!X||J.modified>X.modified)j.set(M,J)}}let H=Array.from(j.values());if(H.sort((J,M)=>M.modified.getTime()-J.modified.getTime()),_)return H.slice(0,_);return H}function nRY(q,K){if(q===null||q.length===0)return K;if(q.length<lRY)return Buffer.concat([q,K]);if(q[0]===123){for(let z of jQ8)if(q.compare(z,0,z.length,1,1+z.length)===0)return Buffer.concat([q,K])}let _=K.indexOf(10);return _===-1?null:K.subarray(_+1)}async function iRY(q,K){let{createReadStream:_}=await import("fs"),z=10,Y=_(q,{end:K-1}),$=[],A=null;for await(let O of Y){let j=nRY(A,O);if(j===null){A=null;continue}let H=!1;for(let J of jQ8)if(j.includes(J)){H=!0;break}if(H){let J=0,M=j.indexOf(10);while(M!==-1){for(let X of jQ8){let P=j.indexOf(X,J);if(P!==-1&&P<M){$.push(j.toString("utf-8",J,M));break}}J=M+1,M=j.indexOf(10,J)}A=j.subarray(J)}else{let J=j.lastIndexOf(10);A=J>=0?j.subarray(J+1):j}if(A.length>65536)A=null}if(A!==null&&A.length>0){for(let O of jQ8)if(A.includes(O)){$.push(A.toString("utf-8"));break}}return $}function rRY(q,K,_){let O=0,w=!1,j=!1,H=0;for(let J=K;H<_.length;J++){if(J===_[H]){if(O===1&&!w)return _[H];H++}let M=q[J];if(j)j=!1;else if(w){if(M===92)j=!0;else if(M===34)w=!1}else if(M===34)w=!0;else if(M===123)O++;else if(M===125)O--}return _.at(-1)}function oRY(q){let Y=Buffer.from('{"parentUuid":'),$=Buffer.from('"uuid":"'),A=Buffer.from('"isSidechain":true'),O=36,w=Buffer.from('","timestamp":"'),j=w.length,H=Y.length,J=$.length,M=[],X=[],P=new Map,W=0,D=q.length;while(W<D){let S=q.indexOf(10,W),R=S===-1?D:S+1;if(R-W>H&&q[W]===123&&q.compare(Y,0,H,W,W+H)===0){let x=q[W+H]===34?W+H+1:-1,I=-1,B=-1,p,C=W;for(;;){let F=q.indexOf($,C);if(F<0||F>=R)break;if(I<0)I=F;let U=F+J+36;if(U+j<=R&&q.compare(w,0,j,U,U+j)===0)if(B<0)B=F;else(p??=[B]).push(F);C=F+J}let g=p?rRY(q,W,p):B>=0?B:I;if(g>=0){let F=g+J,U=q.toString("latin1",F,F+36);P.set(U,M.length),M.push(W,R,x)}else X.push(W,R)}else X.push(W,R);W=R}let f=-1;for(let S=M.length-3;S>=0;S-=3){let R=q.indexOf(A,M[S]);if(R===-1||R>=M[S+1]){f=S;break}}if(f<0)return q;let G=new Set,Z=new Set,T=0,v=f;while(v!==void 0){if(G.has(v))break;G.add(v),Z.add(M[v]),T+=M[v+1]-M[v];let S=M[v+2];if(S<0)break;let R=q.toString("latin1",S,S+36);v=P.get(R)}if(D-T<D>>1)return q;let V=[],E=0;for(let S=0;S<M.length;S+=3){let R=M[S];while(E<X.length&&X[E]<R)V.push(q.subarray(X[E],X[E+1])),E+=2;if(Z.has(R))V.push(q.subarray(R,M[S+1]))}while(E<X.length)V.push(q.subarray(X[E],X[E+1])),E+=2;return Buffer.concat(V)}async function $a(q,K){let _=new Map,z=new Map,Y=new Map,$=new Map,A=new Map,O=new Map,w=new Map,j=new Map,H=new Map,J=new Map,M=new Map,X=new Map,P=new Map,W=new Map,D=new Map,f=new Map,G=[],Z;try{let R=null,x=null,I=!1;if(!i6(process.env.CLAUDE_CODE_DISABLE_PRECOMPACT_SKIP)){let{size:C}=await C97(q);if(C>D41){let g=await g$8(q,C);if(R=g.postBoundaryBuf,I=g.hasPreservedSegment,g.boundaryStartOffset>0)x=await iRY(q,g.boundaryStartOffset)}}if(R??=await dS6(q),!K?.keepAllLeaves&&!I&&!i6(process.env.CLAUDE_CODE_DISABLE_PRECOMPACT_SKIP)&&R.length>D41)R=oRY(R);if(x&&x.length>0){let C=LB(Buffer.from(x.join(`
7685`)));for(let g of C)if(g.type==="summary"&&g.leafUuid)z.set(g.leafUuid,g.summary);else if(g.type==="custom-title"&&g.sessionId)Y.set(g.sessionId,g.customTitle);else if(g.type==="tag"&&g.sessionId)$.set(g.sessionId,g.tag);else if(g.type==="agent-name"&&g.sessionId)A.set(g.sessionId,g.agentName);else if(g.type==="agent-color"&&g.sessionId)O.set(g.sessionId,g.agentColor);else if(g.type==="agent-setting"&&g.sessionId)w.set(g.sessionId,g.agentSetting);else if(g.type==="mode"&&g.sessionId)M.set(g.sessionId,g.mode);else if(g.type==="worktree-state"&&g.sessionId)X.set(g.sessionId,g.worktreeSession);else if(g.type==="pr-link"&&g.sessionId)j.set(g.sessionId,g.prNumber),H.set(g.sessionId,g.prUrl),J.set(g.sessionId,g.prRepository)}let B=LB(R),p=new Map;for(let C of B){if(kRY(C)){let g=C.parentUuid;p.set(C.uuid,g&&p.has(g)?p.get(g)??null:g);continue}if(Oa(C)){if(C.parentUuid&&p.has(C.parentUuid))C.parentUuid=p.get(C.parentUuid)??null;if(_.set(C.uuid,C),bD(C))G.length=0,Z=void 0}else if(C.type==="summary"&&C.leafUuid)z.set(C.leafUuid,C.summary);else if(C.type==="custom-title"&&C.sessionId)Y.set(C.sessionId,C.customTitle);else if(C.type==="tag"&&C.sessionId)$.set(C.sessionId,C.tag);else if(C.type==="agent-name"&&C.sessionId)A.set(C.sessionId,C.agentName);else if(C.type==="agent-color"&&C.sessionId)O.set(C.sessionId,C.agentColor);else if(C.type==="agent-setting"&&C.sessionId)w.set(C.sessionId,C.agentSetting);else if(C.type==="mode"&&C.sessionId)M.set(C.sessionId,C.mode);else if(C.type==="worktree-state"&&C.sessionId)X.set(C.sessionId,C.worktreeSession);else if(C.type==="pr-link"&&C.sessionId)j.set(C.sessionId,C.prNumber),H.set(C.sessionId,C.prUrl),J.set(C.sessionId,C.prRepository);else if(C.type==="file-history-snapshot")P.set(C.messageId,C);else if(C.type==="attribution-snapshot")W.set(C.messageId,C);else if(C.type==="content-replacement")if(C.agentId){let g=f.get(C.agentId)??[];f.set(C.agentId,g),g.push(...C.replacements)}else{let g=D.get(C.sessionId)??[];D.set(C.sessionId,g),g.push(...C.replacements)}else if(C.type==="marble-origami-commit")G.push(C);else if(C.type==="marble-origami-snapshot")Z=C}}catch{}xRY(_),IRY(_);let T=[..._.values()],v=new Set(T.map((R)=>R.parentUuid).filter((R)=>R!==null)),V=T.filter((R)=>!v.has(R.uuid)),E=new Set,S=!1;if(g8("tengu_pebble_leaf_prune",!1)){let R=new Set;for(let x of T)if(x.parentUuid&&(x.type==="user"||x.type==="assistant"))R.add(x.parentUuid);for(let x of V){let I=new Set,B=x;while(B){if(I.has(B.uuid)){S=!0;break}if(I.add(B.uuid),B.type==="user"||B.type==="assistant"){if(!R.has(B.uuid))E.add(B.uuid);break}B=B.parentUuid?_.get(B.parentUuid):void 0}}}else for(let R of V){let x=new Set,I=R;while(I){if(x.has(I.uuid)){S=!0;break}if(x.add(I.uuid),I.type==="user"||I.type==="assistant"){E.add(I.uuid);break}I=I.parentUuid?_.get(I.parentUuid):void 0}}if(S)d("tengu_transcript_parent_cycle",{});return{messages:_,summaries:z,customTitles:Y,tags:$,agentNames:A,agentColors:O,agentSettings:w,prNumbers:j,prUrls:H,prRepositories:J,modes:M,worktreeStates:X,fileHistorySnapshots:P,attributionSnapshots:W,contentReplacements:D,agentContentReplacements:f,contextCollapseCommits:G,contextCollapseSnapshot:Z,leafUuids:E}}async function SBK(q){let K=HZ(Q36()??_2(r1()),`${q}.jsonl`);return $a(K)}function u87(){US6.cache.clear?.()}async function l97(q,K){return(await US6(q)).has(K)}async function f68(q){let{messages:K,summaries:_,customTitles:z,tags:Y,agentSettings:$,worktreeStates:A,fileHistorySnapshots:O,attributionSnapshots:w,contentReplacements:j,contextCollapseCommits:H,contextCollapseSnapshot:J}=await SBK(q);if(K.size===0)return null;if(!US6.cache.has(q))US6.cache.set(q,Promise.resolve(new Set(K.keys())));let M=JQ8(K.values(),(G)=>!G.isSidechain);if(!M)return null;let X=XK6(K,M),P=_.get(M.uuid),W=z.get(M.sessionId),D=Y.get(M.sessionId),f=$.get(q);return{...S97(X,0,P,W,MQ8(O,X),D,JT(q),XQ8(w,X),f,j.get(q)??[]),worktreeSession:A.get(q),contextCollapseCommits:H.filter((G)=>G.sessionId===q),contextCollapseSnapshot:J?.sessionId===q?J:void 0}}async function _L6(q){let K=await hBK(q),{logs:_}=await kJ6(K,0,K.length),z=hW6(_);return z.forEach((Y,$)=>{Y.value=$}),z}async function I57(q,K){if(K?.skipIndex)return aRY(q);return(await PQ8(q,K?.initialEnrichCount??DQ8)).logs}async function aRY(q){let K=Rp(),_;try{_=await QS6(K,{withFileTypes:!0})}catch{return[]}let z=_.filter((w)=>w.isDirectory()).map((w)=>HZ(K,w.name)),$=(await Promise.all(z.map((w)=>qhY(w,q)))).flat(),A=new Map;for(let w of $){let j=`${w.sessionId??""}:${w.leafUuid??""}`,H=A.get(j);if(!H||w.modified.getTime()>H.modified.getTime())A.set(j,w)}let O=hW6([...A.values()]);return O.forEach((w,j)=>{w.value=j}),O}async function PQ8(q,K=DQ8){let _=Rp(),z;try{z=await QS6(_,{withFileTypes:!0})}catch{return{logs:[],allStatLogs:[],nextIndex:0}}let Y=z.filter((j)=>j.isDirectory()).map((j)=>HZ(_,j.name)),$=[];for(let j of Y)$.push(...await pS6(j,q));let A=bBK($),{logs:O,nextIndex:w}=await kJ6(A,0,K);return O.forEach((j,H)=>{j.value=H}),{logs:O,allStatLogs:A,nextIndex:w}}async function YU8(q,K,_=DQ8){return(await mq8(q,K,_)).logs}async function mq8(q,K,_=DQ8){N(`/resume: loading sessions for cwd=${r1()}, worktrees=[${q.join(", ")}]`);let z=await CBK(q,K);N(`/resume: found ${z.length} session files on disk`);let{logs:Y,nextIndex:$}=await kJ6(z,0,_);return Y.forEach((A,O)=>{A.value=O}),{logs:Y,allStatLogs:z,nextIndex:$}}async function CBK(q,K){let _=Rp();if(q.length<=1){let w=r1(),j=_2(w);return pS6(j,void 0,w)}let z=process.platform==="win32",Y=q.map((w)=>{let j=JP(w);return{path:w,prefix:z?j.toLowerCase():j}});Y.sort((w,j)=>j.prefix.length-w.prefix.length);let $=[],A=new Set,O;try{O=await QS6(_,{withFileTypes:!0})}catch(w){N(`Failed to read projects dir ${_}, falling back to current project: ${w}`);let j=_2(r1());return pS6(j,K,r1())}for(let w of O){if(!w.isDirectory())continue;let j=z?w.name.toLowerCase():w.name;if(A.has(j))continue;for(let{path:H,prefix:J}of Y)if(j===J||j.startsWith(J+"-")){A.add(j),$.push(...await pS6(HZ(_,w.name),void 0,H));break}}return bBK($)}async function AK6(q){let K=c0(q);try{let{messages:_,agentContentReplacements:z}=await $a(K),Y=Array.from(_.values()).filter((j)=>j.agentId===q&&j.isSidechain);if(Y.length===0)return null;let $=new Set(Y.map((j)=>j.parentUuid)),A=JQ8(Y,(j)=>!$.has(j.uuid));if(!A)return null;return{messages:XK6(_,A).filter((j)=>j.agentId===q).map(({isSidechain:j,parentUuid:H,...J})=>J),contentReplacements:z.get(q)??[]}}catch{return null}}function n97(q){let K=[];for(let _ of q)if(_.type==="progress"&&_.data&&typeof _.data==="object"&&"type"in _.data&&(_.data.type==="agent_progress"||_.data.type==="skill_progress")&&"agentId"in _.data&&typeof _.data.agentId==="string")K.push(_.data.agentId);return cJ(K)}function Mq7(q){let K={};for(let _ of Object.values(q))if(_.type==="in_process_teammate"&&_.identity?.agentId&&_.messages&&_.messages.length>0)K[_.identity.agentId]=_.messages;return K}async function WQ8(q){let K=await Promise.all(q.map(async(z)=>{try{let Y=await AK6(pO(z));if(Y&&Y.messages.length>0)return{agentId:z,transcript:Y.messages};return null}catch{return null}})),_={};for(let z of K)if(z)_[z.agentId]=z.transcript;return _}async function Xq7(){let q=HZ(Q36()??_2(r1()),N8(),"subagents"),K;try{K=await QS6(q,{withFileTypes:!0})}catch{return{}}let _=K.filter((z)=>z.isFile()&&z.name.startsWith("agent-")&&z.name.endsWith(".jsonl")).map((z)=>z.name.slice(6,-6));return WQ8(_)}function pq8(q){if(q.type==="progress")return!1;if(q.type==="attachment"&&HQ8()!=="ant"){if(q.attachment.type==="hook_additional_context"&&i6(process.env.CLAUDE_CODE_SAVE_HOOK_ADDITIONAL_CONTEXT))return!0;return!1}return!0}function sRY(q){let K=new Set;for(let _ of q)if(_.type==="assistant"&&Array.isArray(_.message.content)){for(let z of _.message.content)if(z.type==="tool_use"&&z.name===FS)K.add(z.id)}return K}function tRY(q,K){return q.flatMap((_)=>{if(_.type==="assistant"&&Array.isArray(_.message.content)){let z=_.message.content,$=z.some((A)=>A.type==="tool_use"&&A.name===FS)?z.filter((A)=>!(A.type==="tool_use"&&A.name===FS)):z;if($.length===0)return[];if(_.isVirtual){let{isVirtual:A,...O}=_;return[{...O,message:{..._.message,content:$}}]}if($!==z)return[{..._,message:{..._.message,content:$}}];return[_]}if(_.type==="user"&&Array.isArray(_.message.content)){let z=_.message.content,$=z.some((A)=>A.type==="tool_result"&&K.has(A.tool_use_id))?z.filter((A)=>!(A.type==="tool_result"&&K.has(A.tool_use_id))):z;if($.length===0)return[];if(_.isVirtual){let{isVirtual:A,...O}=_;return[{...O,message:{..._.message,content:$}}]}if($!==z)return[{..._,message:{..._.message,content:$}}];return[_]}if("isVirtual"in _&&_.isVirtual){let{isVirtual:z,...Y}=_;return[Y]}return[_]})}function Bq8(q,K=q){let _=q.filter(pq8);return HQ8()!=="ant"?tRY(_,sRY(K)):_}async function eRY(q){return(await _L6())[q]||null}async function i97(q){try{let K=Y$(),{messages:_}=await $a(K),z=null;for(let Y of _.values())if(Y.type==="assistant"){let $=Y.message.content;if(Array.isArray($)){for(let A of $)if(A.type==="tool_use"&&A.id===q){z=Y;break}}}else if(Y.type==="user"){let $=Y.message.content;if(Array.isArray($)){for(let A of $)if(A.type==="tool_result"&&A.tool_use_id===q)return null}}return z}catch{return null}}async function Cq8(q){let K=new Map,_;try{_=await QS6(q,{withFileTypes:!0})}catch{return K}let z=[];for(let Y of _){if(!Y.isFile()||!Y.name.endsWith(".jsonl"))continue;let $=BL(GRY(Y.name,".jsonl"));if(!$)continue;z.push({sessionId:$,filePath:HZ(q,Y.name)})}return await Promise.all(z.map(async({sessionId:Y,filePath:$})=>{try{let A=await C97($);K.set(Y,{path:$,mtime:A.mtime.getTime(),ctime:A.birthtime.getTime(),size:A.size})}catch{N(`Failed to stat session file: ${$}`)}})),K}async function AQ8(q,K){let{messages:_,summaries:z,customTitles:Y,tags:$,agentNames:A,agentColors:O,agentSettings:w,prNumbers:j,prUrls:H,prRepositories:J,modes:M,fileHistorySnapshots:X,attributionSnapshots:P,contentReplacements:W,leafUuids:D}=await $a(q,{keepAllLeaves:!0});if(_.size===0)return[];let f=[],G=new Map;for(let T of _.values())if(D.has(T.uuid))f.push(T);else if(T.parentUuid){let v=G.get(T.parentUuid);if(v)v.push(T);else G.set(T.parentUuid,[T])}let Z=[];for(let T of f){let v=XK6(_,T);if(v.length===0)continue;let V=G.get(T.uuid);if(V)V.sort((R,x)=>R.timestamp<x.timestamp?-1:R.timestamp>x.timestamp?1:0),v.push(...V);let E=v[0],S=T.sessionId;Z.push({date:T.timestamp,messages:KL6(v),fullPath:q,value:0,created:new Date(E.timestamp),modified:new Date(T.timestamp),firstPrompt:F97(v),messageCount:U97(v),isSidechain:E.isSidechain??!1,sessionId:S,leafUuid:T.uuid,summary:z.get(T.uuid),customTitle:Y.get(S),tag:$.get(S),agentName:A.get(S),agentColor:O.get(S),agentSetting:w.get(S),mode:M.get(S),prNumber:j.get(S),prUrl:H.get(S),prRepository:J.get(S),gitBranch:T.gitBranch,projectPath:K??E.cwd,fileHistorySnapshots:MQ8(X,v),attributionSnapshots:XQ8(P,v),contentReplacements:W.get(S)??[]})}return Z}async function qhY(q,K){let _=await Cq8(q);if(_.size===0)return[];let z;if(K&&_.size>K)z=[..._.values()].sort(($,A)=>A.mtime-$.mtime).slice(0,K);else z=[..._.values()];let Y=[];for(let $ of z)try{let A=await AQ8($.path);Y.push(...A)}catch{N(`Failed to load session file: ${$.path}`)}return Y}async function KhY(q,K,_){let{head:z,tail:Y}=await HR7(q,K,_);if(!z)return{firstPrompt:"",isSidechain:!1};let $=z.includes('"isSidechain":true')||z.includes('"isSidechain": true'),A=UW6(z,"cwd"),O=UW6(z,"teamName"),w=UW6(z,"agentSetting"),j=UT(Y,"lastPrompt")||_hY(z)||VBK(z,"content",200)||VBK(z,"text",200)||"",H=UT(Y,"customTitle")??UT(z,"customTitle")??UT(Y,"aiTitle")??UT(z,"aiTitle"),J=UT(Y,"summary"),M=UT(Y,"tag"),X=UT(Y,"gitBranch")??UW6(z,"gitBranch"),P=UT(Y,"prUrl"),W=UT(Y,"prRepository"),D,f=UT(Y,"prNumber");if(f)D=parseInt(f,10)||void 0;if(!D){let G=Y.lastIndexOf('"prNumber":');if(G>=0){let Z=Y.slice(G+11,G+25),T=parseInt(Z.trim(),10);if(T>0)D=T}}return{firstPrompt:j,gitBranch:X,isSidechain:$,projectPath:A,teamName:O,customTitle:H,summary:J,tag:M,agentSetting:w,prNumber:D,prUrl:P,prRepository:W}}function _hY(q){let K=0,_=!1,z="";while(K<q.length){let Y=q.indexOf(`
7686`,K),$=Y>=0?q.slice(K,Y):q.slice(K);if(K=Y>=0?Y+1:q.length,!$.includes('"type":"user"')&&!$.includes('"type": "user"'))continue;if($.includes('"tool_result"'))continue;if($.includes('"isMeta":true')||$.includes('"isMeta": true'))continue;try{let A=r8($);if(A.type!=="user")continue;let O=A.message;if(!O)continue;let w=O.content,j=[];if(typeof w==="string")j.push(w);else if(Array.isArray(w))for(let H of w){let J=H;if(J.type==="text"&&typeof J.text==="string")j.push(J.text)}for(let H of j){if(!H)continue;let J=H.replace(/\n/g," ").trim(),M=o4(J,CZ);if(M){let P=M.replace(/^\//,""),W=o4(J,"command-args")?.trim()||"";if(RQ().has(P)||!W){if(!z)z=M;continue}return W?`${M} ${W}`:M}let X=o4(J,"bash-input");if(X)return`! ${X}`;if(NBK.test(J))continue;if(J.length>200)J=J.slice(0,200).trim()+"…";return J}}catch{continue}}if(z)return z;return""}function VBK(q,K,_){let z=[`"${K}":"`,`"${K}": "`];for(let Y of z){let $=q.indexOf(Y);if($<0)continue;let A=$+Y.length,O=A,w=0;while(O<q.length&&w<_){if(q[O]==="\\"){O+=2,w++;continue}if(q[O]==='"')break;O++,w++}return q.slice(A,O).replace(/\\n/g," ").replace(/\\t/g," ").trim()}return""}function bBK(q){let K=new Map;for(let _ of q){if(!_.sessionId)continue;let z=K.get(_.sessionId);if(!z||_.modified.getTime()>z.modified.getTime())K.set(_.sessionId,_)}return hW6([...K.values()]).map((_,z)=>({..._,value:z}))}async function pS6(q,K,_){let Y=[...(await Cq8(q)).entries()].sort((O,w)=>w[1].mtime-O[1].mtime);if(K&&Y.length>K)Y=Y.slice(0,K);let $=[];for(let[O,w]of Y)$.push({date:new Date(w.mtime).toISOString(),messages:[],isLite:!0,fullPath:w.path,value:0,created:new Date(w.ctime),modified:new Date(w.mtime),firstPrompt:"",messageCount:0,fileSize:w.size,isSidechain:!1,sessionId:O,projectPath:_});let A=hW6($);return A.forEach((O,w)=>{O.value=w}),A}async function zhY(q,K){if(!q.isLite||!q.fullPath)return q;let _=await KhY(q.fullPath,q.fileSize??0,K),z={...q,isLite:!1,firstPrompt:_.firstPrompt,gitBranch:_.gitBranch,isSidechain:_.isSidechain,teamName:_.teamName,customTitle:_.customTitle,summary:_.summary,tag:_.tag,agentSetting:_.agentSetting,prNumber:_.prNumber,prUrl:_.prUrl,prRepository:_.prRepository,projectPath:_.projectPath??q.projectPath};if(!z.firstPrompt&&!z.customTitle)z.firstPrompt="(session)";if(z.isSidechain)return N(`Session ${q.sessionId} filtered from /resume: isSidechain=true`),null;if(z.teamName)return N(`Session ${q.sessionId} filtered from /resume: teamName=${z.teamName}`),null;return z}async function kJ6(q,K,_){let z=[],Y=Buffer.alloc(ue),$=K;while($<q.length&&z.length<_){let w=q[$];$++;let j=await zhY(w,Y);if(j)z.push(j)}let A=$-K,O=A-z.length;if(O>0)N(`/resume: enriched ${A} sessions, ${O} filtered out, ${z.length} visible (${q.length-$} remaining on disk)`);return{logs:z,nextIndex:$}}var TRY,vRY=52428800,NBK,VRY,$78=52428800,x97,_2,TJ6=null,vBK=!1,kBK=10,cRY,jQ8,lRY=25,US6,DQ8=50;var _K=y(()=>{F4();k8();v8();yA();RY();o1();Ax8();k16();M0();c9();lQ();I7();_8();oY();m8();y8();U7();e7();a78();E5();RA();vO();E8();i1();dz();QW6();U1();l8();jm();TRY={ISSUES_EXPLAINER:"report the issue at https://github.com/anthropics/claude-code/issues",PACKAGE_URL:"@anthropic-ai/claude-code",README_URL:"https://code.claude.com/docs/en/overview",VERSION:"2.1.88",FEEDBACK_CHANNEL:"https://github.com/anthropics/claude-code/issues",BUILD_TIME:"2026-03-30T21:59:52Z"}.VERSION,NBK=/^(?:\s*<[a-z][\w-]*[\s>]|\[Request interrupted by user[^\]]*\])/;VRY=new Set(["bash_progress","powershell_progress","mcp_progress",...[]]);x97=new Map;_2=_1((q)=>{return HZ(Rp(),JP(q))});cRY=['"type":"summary"','"type":"custom-title"','"type":"tag"','"type":"agent-name"','"type":"agent-color"','"type":"agent-setting"','"type":"mode"','"type":"worktree-state"','"type":"pr-link"'],jQ8=cRY.map((q)=>Buffer.from(q));US6=_1(async(q)=>{let{messages:K}=await SBK(q);return new Set(K.keys())},(q)=>q)});var xBK={};T8(xBK,{buildCombinedMemoryPrompt:()=>YhY});function YhY(q,K=!1){let _=Vj(),z=wu(),Y=K?["## How to save memories","","Write each memory to its own file in the chosen directory (private or team, per the type's scope guidance) using this frontmatter format:","",...jp,"","- Keep the name, description, and type fields in memory files up-to-date with the content","- Organize memory semantically by topic, not chronologically","- Update or remove memories that turn out to be wrong or outdated","- Do not write duplicate memories. First check if there is an existing memory you can update before writing a new one."]:["## How to save memories","","Saving a memory is a two-step process:","","**Step 1** — write the memory to its own file in the chosen directory (private or team, per the type's scope guidance) using this frontmatter format:","",...jp,"",`**Step 2** — add a pointer to that file in the same directory's \`${oP}\`. Each directory (private and team) has its own \`${oP}\` index — each entry should be one line, under ~150 characters: \`- [Title](file.md) — one-line hook\`. They have no frontmatter. Never write memory content directly into a \`${oP}\`.`,"",`- Both \`${oP}\` indexes are loaded into your conversation context — lines after ${nK6} will be truncated, so keep them concise`,"- Keep the name, description, and type fields in memory files up-to-date with the content","- Organize memory semantically by topic, not chronologically","- Update or remove memories that turn out to be wrong or outdated","- Do not write duplicate memories. First check if there is an existing memory you can update before writing a new one."];return["# Memory","",`You have a persistent, file-based memory system with two directories: a private directory at \`${_}\` and a shared team directory at \`${z}\`. ${uBK}`,"","You should build up this memory system over time so that future conversations can have a complete picture of who the user is, how they'd like to collaborate with you, what behaviors to avoid or repeat, and the context behind the work the user gives you.","","If the user explicitly asks you to remember something, save it immediately as whichever type fits best. If they ask you to forget something, find and remove the relevant entry.","","## Memory scope","","There are two scope levels:","",`- private: memories that are private between you and the current user. They persist across conversations with only this specific user and are stored at the root \`${_}\`.`,`- team: memories that are shared with and contributed by all of the users who work within this project directory. Team memories are synced at the beginning of every session and they are stored at \`${z}\`.`,"",...Hp8,...XH6,"- You MUST avoid saving sensitive data within shared team memories. For example, never save API keys or user credentials.","",...Y,"","## When to access memories","- When memories (personal or team) seem relevant, or the user references prior work with them or others in their organization.","- You MUST access memory when the user explicitly asks you to check, recall, or remember.","- If the user says to *ignore* or *not use* memory: proceed as if MEMORY.md were empty. Do not apply remembered facts, cite, compare against, or mention memory content.",X87,"",...Mp8,"","## Memory and other forms of persistence","Memory is one of several persistence mechanisms available to you as you assist the user in a given conversation. The distinction is often that memory can be recalled in future conversations and should not be used for persisting information that is only useful within the scope of the current conversation.","- When to use or update a plan instead of memory: If you are about to start a non-trivial implementation task and would like to reach alignment with the user on your approach you should use a Plan rather than saving this information to memory. Similarly, if you already have a plan within the conversation and you have changed your approach persist that change by updating the plan rather than saving a memory.","- When to use or update tasks instead of memory: When you need to break your work in current conversation into discrete steps or keep track of your progress use tasks instead of saving to memory. Tasks are great for persisting information about the work that needs to be done in the current conversation, but memory should be reserved for information that will be useful in future conversations.",...q??[],"",...r97(_)].join(`

Callers 5

MK6Function · 0.85
ohKFunction · 0.85
_U8Function · 0.85
DFunction · 0.85
PGYFunction · 0.85

Calls 13

qRFunction · 0.85
$aFunction · 0.85
JQ8Function · 0.85
XK6Function · 0.85
KL6Function · 0.85
F97Function · 0.85
U97Function · 0.85
MQ8Function · 0.85
XQ8Function · 0.85
filterMethod · 0.80
valuesMethod · 0.45
hasMethod · 0.45

Tested by

no test coverage detected