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

Function Sp8

package/cli.js:4666–4666  ·  view source on GitHub ↗
(q,K,_,z)

Source from the content-addressed store, hash-verified

4664- If there are no memories in the list that would clearly be useful, feel free to return an empty list.
4665- If a list of recently-used tools is provided, do not select memories that are usage reference or API documentation for those tools (Claude Code is already exercising them). DO still select memories containing warnings, gotchas, or known issues about those tools — active use is exactly when those matter.
4666`;var HfK=y(()=>{_8();y8();aq();nq6();l8();P87()});import{readdir as PfK,stat as WfK}from"fs/promises";import{dirname as W17,parse as zB8,relative as ma,resolve as DfK}from"path";import{randomUUID as O_Y}from"crypto";async function H_Y(q,K,_,z,Y,$,A){if(i6(process.env.CLAUDE_CODE_DISABLE_ATTACHMENTS)||i6(process.env.CLAUDE_CODE_SIMPLE))return AB8(z);let O=P3(),w=setTimeout((f)=>f.abort(),1000,O),j={...K,abortController:O},H=!K.agentId,J=q?[w$("at_mentioned_files",()=>S_Y(q,j)),w$("mcp_resources",()=>b_Y(q,j)),w$("agent_mentions",()=>Promise.resolve(C_Y(q,K.options.agentDefinitions.activeAgents))),...[]]:[],M=await Promise.all(J),X=[w$("queued_commands",()=>AB8(z)),w$("date_change",()=>Promise.resolve(k_Y(Y))),w$("ultrathink_effort",()=>Promise.resolve(V_Y(q))),w$("deferred_tools_delta",()=>Promise.resolve(Sp8(K.options.tools,K.options.mainLoopModel,Y,{callSite:H?"attachments_main":"attachments_subagent",querySource:$}))),w$("agent_listing_delta",()=>Promise.resolve(Cp8(K,Y))),w$("mcp_instructions_delta",()=>Promise.resolve(bp8(K.options.mcpClients,K.options.tools,K.options.mainLoopModel,Y))),w$("changed_files",()=>x_Y(j)),w$("nested_memory",()=>I_Y(j)),w$("dynamic_skill",()=>g_Y(j)),w$("skill_listing",()=>F_Y(j)),w$("plan_mode",()=>D_Y(Y,K)),w$("plan_mode_exit",()=>f_Y(K)),w$("auto_mode",()=>T_Y(Y,K)),w$("auto_mode_exit",()=>v_Y(K)),w$("todo_reminders",()=>IH()?a_Y(Y,K):r_Y(Y,K)),...nq()?[...$==="session_memory"?[]:[w$("teammate_mailbox",async()=>e_Y(K))],w$("team_context",async()=>qzY(Y??[]))]:[],w$("agent_pending_messages",async()=>M_Y(K)),w$("critical_system_reminder",()=>Promise.resolve(N_Y(K)))],P=H?[w$("ide_selection",async()=>E_Y(_,K)),w$("ide_opened_file",async()=>h_Y(_,K)),w$("output_style",async()=>Promise.resolve(y_Y())),w$("diagnostics",async()=>c_Y(K)),w$("lsp_diagnostics",async()=>l_Y(K)),w$("unified_tasks",async()=>s_Y(K)),w$("async_hook_responses",async()=>t_Y()),w$("token_usage",async()=>Promise.resolve(KzY(Y??[],K.options.mainLoopModel))),w$("budget_usd",async()=>Promise.resolve(zzY(K.options.maxBudgetUsd))),w$("output_token_usage",async()=>Promise.resolve(_zY())),w$("verify_plan_reminder",async()=>$zY(Y,K))]:[],[W,D]=await Promise.all([Promise.all(X),Promise.all(P)]);return clearTimeout(w),[...M.flat(),...W.flat(),...D.flat()].filter((f)=>f!==void 0&&f!==null)}async function w$(q,K){let _=Date.now();try{let z=await K(),Y=Date.now()-_;if(Math.random()<0.05){let $=z.filter((A)=>A!==void 0&&A!==null).reduce((A,O)=>{return A+g6(O).length},0);d("tengu_attachment_compute_duration",{label:q,duration_ms:Y,attachment_size_bytes:$,attachment_count:z.length})}return z}catch(z){let Y=Date.now()-_;if(Math.random()<0.05)d("tengu_attachment_compute_duration",{label:q,duration_ms:Y,error:!0});return H6(z),OE(`Attachment error in ${q}`,z),[]}}async function AB8(q){if(!q)return[];let K=q.filter((_)=>J_Y.has(_.mode));return Promise.all(K.map(async(_)=>{let z=await X_Y(_.pastedContents),Y=_.value;if(z.length>0)Y=[{type:"text",text:typeof _.value==="string"?_.value:L3(_.value,`
4667`)},...z];return{type:"queued_command",prompt:Y,source_uuid:_.uuid,imagePasteIds:eDK(_.pastedContents),commandMode:_.mode,origin:_.origin,isMeta:_.isMeta}}))}function M_Y(q){let K=q.agentId;if(!K)return[];return QXK(K,q.getAppState,q.setAppStateForTasks??q.setAppState).map((z)=>({type:"queued_command",prompt:z,origin:{kind:"coordinator"},isMeta:!0}))}async function X_Y(q){if(!q)return[];let K=Object.values(q).filter(vH6);if(K.length===0)return[];return await Promise.all(K.map(async(z)=>{let Y={type:"image",source:{type:"base64",media_type:z.mediaType||"image/png",data:z.content}};return(await Tr(Y)).block}))}function P_Y(q){let K=0,_=!1;for(let z=q.length-1;z>=0;z--){let Y=q[z];if(Y?.type==="user"&&!Y.isMeta&&!TfK(Y.message.content))K++;else if(Y?.type==="attachment"&&(Y.attachment.type==="plan_mode"||Y.attachment.type==="plan_mode_reentry")){_=!0;break}}return{turnCount:K,foundPlanModeAttachment:_}}function W_Y(q){let K=0;for(let _=q.length-1;_>=0;_--){let z=q[_];if(z?.type==="attachment"){if(z.attachment.type==="plan_mode_exit")break;if(z.attachment.type==="plan_mode")K++}}return K}async function D_Y(q,K){if(K.getAppState().toolPermissionContext.mode!=="plan")return[];if(q&&q.length>0){let{turnCount:j,foundPlanModeAttachment:H}=P_Y(q);if(H&&j<JfK.TURNS_BETWEEN_ATTACHMENTS)return[]}let Y=nP(K.agentId),$=mX(K.agentId),A=[];if(sb6()&&$!==null)A.push({type:"plan_mode_reentry",planFilePath:Y}),qE(!1);let w=(W_Y(q??[])+1)%JfK.FULL_REMINDER_EVERY_N_ATTACHMENTS===1?"full":"sparse";return A.push({type:"plan_mode",reminderType:w,isSubAgent:!!K.agentId,planFilePath:Y,planExists:$!==null}),A}async function f_Y(q){if(!Bi8())return[];if(q.getAppState().toolPermissionContext.mode==="plan")return Ex(!1),[];Ex(!1);let _=nP(q.agentId),z=mX(q.agentId)!==null;return[{type:"plan_mode_exit",planFilePath:_,planExists:z}]}function Z_Y(q){let K=0,_=!1;for(let z=q.length-1;z>=0;z--){let Y=q[z];if(Y?.type==="user"&&!Y.isMeta&&!TfK(Y.message.content))K++;else if(Y?.type==="attachment"&&Y.attachment.type==="auto_mode"){_=!0;break}else if(Y?.type==="attachment"&&Y.attachment.type==="auto_mode_exit")break}return{turnCount:K,foundAutoModeAttachment:_}}function G_Y(q){let K=0;for(let _=q.length-1;_>=0;_--){let z=q[_];if(z?.type==="attachment"){if(z.attachment.type==="auto_mode_exit")break;if(z.attachment.type==="auto_mode")K++}}return K}async function T_Y(q,K){let z=K.getAppState().toolPermissionContext,Y=z.mode==="auto",$=z.mode==="plan"&&(ffK?.isAutoModeActive()??!1);if(!Y&&!$)return[];if(q&&q.length>0){let{turnCount:w,foundAutoModeAttachment:j}=Z_Y(q);if(j&&w<MfK.TURNS_BETWEEN_ATTACHMENTS)return[]}return[{type:"auto_mode",reminderType:(G_Y(q??[])+1)%MfK.FULL_REMINDER_EVERY_N_ATTACHMENTS===1?"full":"sparse"}]}async function v_Y(q){if(!gi8())return[];if(q.getAppState().toolPermissionContext.mode==="auto"||(ffK?.isAutoModeActive()??!1))return VZ(!1),[];return VZ(!1),[{type:"auto_mode_exit"}]}function k_Y(q){let K=Qi6(),_=oi8();if(_===null)return BX6(K),[];if(K===_)return[];return BX6(K),[{type:"date_change",newDate:K}]}function V_Y(q){if(!qr()||!q||!o54(q))return[];return d("tengu_ultrathink",{}),[{type:"ultrathink_effort",level:"high"}]}function Sp8(q,K,_,z){if(!V18())return[];if(!yL())return[];if(!k18(K))return[];if(!JH6(q))return[];let Y=a87(q,_??[],z);if(!Y)return[];return[{type:"deferred_tools_delta",...Y}]}function Cp8(q,K){if(!Z67())return[];if(!q.options.tools.some((J)=>g_(J,v4)))return[];let{activeAgents:_,allowedAgentTypes:z}=q.options.agentDefinitions,Y=new Set;for(let J of q.options.tools){let M=nT(J.name);if(M)Y.add(M.serverName)}let $=q.getAppState().toolPermissionContext,A=d88(ri6(_,[...Y]),$,v4);if(z)A=A.filter((J)=>z.includes(J.agentType));let O=new Set;for(let J of K??[]){if(J.type!=="attachment")continue;if(J.attachment.type!=="agent_listing_delta")continue;for(let M of J.attachment.addedTypes)O.add(M);for(let M of J.attachment.removedTypes)O.delete(M)}let w=new Set(A.map((J)=>J.agentType)),j=A.filter((J)=>!O.has(J.agentType)),H=[];for(let J of O)if(!w.has(J))H.push(J);if(j.length===0&&H.length===0)return[];return j.sort((J,M)=>J.agentType.localeCompare(M.agentType)),H.sort(),[{type:"agent_listing_delta",addedTypes:j.map((J)=>J.agentType),addedLines:j.map(f67),removedTypes:H,isInitial:O.size===0,showConcurrencyNote:yK()!=="pro"}]}function bp8(q,K,_,z){if(!_h6())return[];let Y=[];if(yL()&&k18(_)&&JH6(K))Y.push({serverName:yN,block:ep8});let $=qfK(q,z??[],Y);if(!$)return[];return[{type:"mcp_instructions_delta",...$}]}function N_Y(q){let K=q.criticalSystemReminder_EXPERIMENTAL;if(!K)return[];return[{type:"critical_system_reminder",content:K}]}function y_Y(){let K=Z7()?.outputStyle||"default";if(K==="default")return[];return[{type:"output_style",style:K}]}async function E_Y(q,K){let _=LE8(K.options.mcpClients);if(!_||q?.lineStart===void 0||!q.text||!q.filePath)return[];let z=K.getAppState();if(Yh6(q.filePath,z.toolPermissionContext))return[];return[{type:"selected_lines_in_ide",ideName:_,lineStart:q.lineStart,lineEnd:q.lineStart+q.lineCount-1,filename:q.filePath,content:q.text,displayPath:ma(Z8(),q.filePath)}]}function L_Y(q,K){let _=W17(DfK(q)),z=[],Y=_;while(Y!==K&&Y!==zB8(Y).root){if(Y.startsWith(K))z.push(Y);Y=W17(Y)}z.reverse();let $=[];Y=K;while(Y!==zB8(Y).root)$.push(Y),Y=W17(Y);return $.reverse(),{nestedDirs:z,cwdLevelDirs:$}}function R_Y(q){return q==="User"||q==="Project"||q==="Local"||q==="Managed"}function f17(q,K,_){let z=[],Y=Wr6();for(let $ of q){if(K.loadedNestedMemoryPaths?.has($.path))continue;if(!K.readFileState.has($.path)){if(z.push({type:"nested_memory",path:$.path,content:$,displayPath:ma(Z8(),$.path)}),K.loadedNestedMemoryPaths?.add($.path),K.readFileState.set($.path,{content:$.contentDiffersFromDisk?$.rawContent??$.content:$.content,timestamp:Date.now(),offset:void 0,limit:void 0,isPartialView:$.contentDiffersFromDisk}),Y&&R_Y($.type)){let A=$.globs?"path_glob_match":$.parent?"include":"nested_traversal";Dr6($.path,$.type,A,{globs:$.globs,triggerFilePath:_,parentFilePath:$.parent})}}}return z}async function ZfK(q,K,_){let z=[];try{if(!XL(q,_.toolPermissionContext))return z;let Y=new Set,$=r1(),A=await AI1(q,Y);z.push(...f17(A,K,q));let{nestedDirs:O,cwdLevelDirs:w}=L_Y(q,$),j=g8("tengu_paper_halyard",!1);for(let H of O){let J=(await OI1(H,q,Y)).filter((M)=>!j||M.type!=="Project"&&M.type!=="Local");z.push(...f17(J,K,q))}for(let H of w){let J=(await wI1(H,q,Y)).filter((M)=>!j||M.type!=="Project"&&M.type!=="Local");z.push(...f17(J,K,q))}}catch(Y){H6(Y)}return z}async function h_Y(q,K){if(!q?.filePath||q.text)return[];let _=K.getAppState();if(Yh6(q.filePath,_.toolPermissionContext))return[];return[...await ZfK(q.filePath,K,_),{type:"opened_file_in_ide",filename:q.filePath}]}async function S_Y(q,K){let _=U_Y(q);if(_.length===0)return[];let z=K.getAppState();return(await Promise.all(_.map(async($)=>{try{let{filename:A,lineStart:O,lineEnd:w}=d_Y($),j=lq(A);if(Yh6(j,z.toolPermissionContext))return null;try{if((await WfK(j)).isDirectory())try{let J=await PfK(j,{withFileTypes:!0}),M=1000,X=J.length>1000,P=J.slice(0,1000).map((D)=>D.name);if(X)P.push(`… and ${J.length-1000} more entries`);let W=P.join(`
4668`);return d("tengu_at_mention_extracting_directory_success",{}),{type:"directory",path:j,content:W,displayPath:ma(Z8(),j)}}catch{return null}}catch{}return await I87(j,K,"tengu_at_mention_extracting_filename_success","tengu_at_mention_extracting_filename_error","at-mention",{offset:O,limit:w&&O?w-O+1:void 0})}catch{d("tengu_at_mention_extracting_filename_error",{})}}))).filter(Boolean)}function C_Y(q,K){let _=vfK(q);if(_.length===0)return[];return _.map((Y)=>{let $=Y.replace("agent-",""),A=K.find((O)=>O.agentType===$);if(!A)return d("tengu_at_mention_agent_not_found",{}),null;return d("tengu_at_mention_agent_success",{}),{type:"agent_mention",agentType:A.agentType}}).filter((Y)=>Y!==null)}async function b_Y(q,K){let _=Q_Y(q);if(_.length===0)return[];let z=K.options.mcpClients||[];return(await Promise.all(_.map(async($)=>{try{let[A,...O]=$.split(":"),w=O.join(":");if(!A||!w)return d("tengu_at_mention_mcp_resource_error",{}),null;let j=z.find((M)=>M.name===A);if(!j||j.type!=="connected")return d("tengu_at_mention_mcp_resource_error",{}),null;let J=(K.options.mcpResources?.[A]||[]).find((M)=>M.uri===w);if(!J)return d("tengu_at_mention_mcp_resource_error",{}),null;try{let M=await j.client.readResource({uri:w});return d("tengu_at_mention_mcp_resource_success",{}),{type:"mcp_resource",server:A,uri:w,name:J.name||w,description:J.description,content:M}}catch(M){return d("tengu_at_mention_mcp_resource_error",{}),H6(M),null}}catch{return d("tengu_at_mention_mcp_resource_error",{}),null}}))).filter(($)=>$!==null)}async function x_Y(q){let K=d76(q.readFileState);if(K.length===0)return[];let _=q.getAppState();return(await Promise.all(K.map(async(Y)=>{let $=q.readFileState.get(Y);if(!$)return null;if($.offset!==void 0||$.limit!==void 0)return null;let A=lq(Y);if(Yh6(A,_.toolPermissionContext))return null;try{if(await zp6(A)<=$.timestamp)return null;let w={file_path:A};if(!(await i_.validateInput(w,q)).result)return null;let H=await i_.call(w,q);if(H.data.type==="text"){let J=p$K($.content,H.data.file.content);if(J==="")return null;return{type:"edited_text_file",filename:A,snippet:J}}if(H.data.type==="image")try{let J=await w17(A);return{type:"edited_image_file",filename:A,content:J}}catch(J){return H6(J),d("tengu_watched_file_compression_failed",{file:A}),null}return null}catch(O){if(_7(O))q.readFileState.delete(Y);return null}}))).filter((Y)=>Y!=null)}async function I_Y(q){if(!q.nestedMemoryAttachmentTriggers||q.nestedMemoryAttachmentTriggers.size===0)return[];let K=q.getAppState(),_=[];for(let z of q.nestedMemoryAttachmentTriggers){let Y=await ZfK(z,q,K);_.push(...Y)}return q.nestedMemoryAttachmentTriggers.clear(),_}async function u_Y(q,K,_,z,Y,$){let A=vfK(q).flatMap((J)=>{let M=J.replace("agent-",""),X=K.find((P)=>P.agentType===M);return X?.memory?[Nk6(M,X.memory)]:[]}),O=A.length>0?A:[Vj()],j=(await Promise.all(O.map((J)=>jfK(q,J,Y,z,$).catch(()=>[])))).flat().filter((J)=>!_.has(J.path)&&!$.has(J.path)).slice(0,5),H=await p_Y(j,Y);if(H.length===0)return[];return[{type:"relevant_memories",memories:H}]}function m_Y(q){let K=new Set,_=0;for(let z of q)if(z.type==="attachment"&&z.attachment.type==="relevant_memories")for(let Y of z.attachment.memories)K.add(Y.path),_+=Y.content.length;return{paths:K,totalBytes:_}}async function p_Y(q,K){return(await Promise.all(q.map(async({path:z,mtimeMs:Y})=>{try{let $=await lK6(z,0,D17,XfK,K,{truncateOnByteLimit:!0}),A=$.totalLines>D17||$.truncatedByBytes,O=A?$.content+`
4669

Callers 3

LE6Function · 0.85
zDKFunction · 0.85
H_YFunction · 0.85

Calls 5

V18Function · 0.85
yLFunction · 0.85
k18Function · 0.85
JH6Function · 0.85
a87Function · 0.85

Tested by

no test coverage detected