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

Function Ed

package/cli.js:7833–7833  ·  view source on GitHub ↗
({messages:q,systemPrompt:K,thinkingConfig:_,tools:z,signal:Y,options:$})

Source from the content-addressed store, hash-verified

7831
7832 IMPORTANT: this context may or may not be relevant to your tasks. You should not respond to this context unless it is highly relevant to your task.
7833</system-reminder>
7834`,isMeta:!0}),...q]}async function rgK(q,K){if(j16())return;let[{tools:_},z,Y,$]=await Promise.all([Ua6(q),gD(K),bO(),tw()]),A=$.gitStatus?.length??0,O=Y.claudeMd?.length??0,w=A+O,j=Z8(),H=aL6(K),J=oL6(H,j),M=await FG8(j,AbortSignal.timeout(1000),J),X=0,P=0,W=0,D=0,f=0,G=z.filter((T)=>!T.isMcp);X=_.length,D=G.length;let Z=new Set;for(let T of _){let v=T.name.split("__");if(v.length>=3&&v[1])Z.add(v[1])}P=Z.size;for(let T of _){let v="inputJSONSchema"in T&&T.inputJSONSchema?T.inputJSONSchema:ua(T.inputSchema);W+=E3(g6(v))}for(let T of G){let v="inputJSONSchema"in T&&T.inputJSONSchema?T.inputJSONSchema:ua(T.inputSchema);f+=E3(g6(v))}d("tengu_context_size",{git_status_size:A,claude_md_size:O,total_context_size:w,project_file_count_rounded:M,mcp_tools_count:X,mcp_servers_count:P,mcp_tools_tokens:W,non_mcp_tools_count:D,non_mcp_tools_tokens:f})}function zZK(q,K,_){switch(q.name){case kX:{let z=mX(_),Y=nP(_);return fx8(),z!==null?{...K,plan:z,planFilePath:Y}:K}case R4.name:{let z=R4.inputSchema.parse(K),{command:Y,timeout:$,description:A}=z,O=Z8(),w=Y.replace(`cd ${O} && `,"");if(Z1()==="windows")w=w.replace(`cd ${ff(O)} && `,"");if(w=w.replace(/\\\\;/g,"\\;"),/^echo\s+["']?[^|&;><]*["']?$/i.test(w.trim()))d("tengu_bash_tool_simple_echo",{});let j="run_in_background"in z?z.run_in_background:void 0;return{command:w,description:A,...$!==void 0&&{timeout:$},...A!==void 0&&{description:A},...j!==void 0&&{run_in_background:j},..."dangerouslyDisableSandbox"in z&&z.dangerouslyDisableSandbox!==void 0&&{dangerouslyDisableSandbox:z.dangerouslyDisableSandbox}}}case UX.name:{let z=UX.inputSchema.parse(K),{file_path:Y,edits:$}=g$K({file_path:z.file_path,edits:[{old_string:z.old_string,new_string:z.new_string,replace_all:z.replace_all}]});return{replace_all:$[0].replace_all,file_path:Y,old_string:$[0].old_string,new_string:$[0].new_string}}case QX.name:{let z=QX.inputSchema.parse(K),Y=/\.(md|mdx)$/i.test(z.file_path);return{file_path:z.file_path,content:Y?z.content:Ls1(z.content)}}case ak:{let z=K,Y=z.task_id??z.agentId??z.bash_id,$=z.timeout??(typeof z.wait_up_to==="number"?z.wait_up_to*1000:void 0);return{task_id:Y??"",block:z.block??!0,timeout:$??30000}}default:return K}}function YZK(q,K){switch(q.name){case kX:{if(K&&typeof K==="object"&&(("plan"in K)||("planFilePath"in K))){let{plan:_,planFilePath:z,...Y}=K;return Y}return K}case UX.name:{if(K&&typeof K==="object"&&"edits"in K){let{old_string:_,new_string:z,replace_all:Y,...$}=K;return $}return K}default:return K}}var xSY,ngK=!1;var fH6=y(()=>{rL();jN();H16();o1();k8();PD();p0();LK6();Uj6();ka();BD();pf8();ON();Z$();i$();HG();I7();_8();m8();i1();Az();Tz();SJ();vK();KC();l8();VD8();NB();dp8();xSY={[kX]:["launchSwarm","teammateCount"],[v4]:["name","team_name","mode"]}});import{createHash as mSY}from"crypto";function BSY(q){let K=q.find((z)=>z.type==="user");if(!K)return"";let _=K.message.content;if(typeof _==="string")return _;if(Array.isArray(_)){let z=_.find((Y)=>Y.type==="text");if(z&&z.type==="text")return z.text}return""}function k_7(q,K){let z=[4,7,20].map((A)=>q[A]||"0").join(""),Y=`${pSY}${z}${K}`;return mSY("sha256").update(Y).digest("hex").slice(0,3)}function ogK(q){let K=BSY(q);return k_7(K,{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)}var pSY="59cf53e54c78";var V_7=()=>{};function tgK(q){let{hasThinking:K=!1,isRedactThinkingActive:_=!1,clearAllThinking:z=!1}=q??{},Y=[];if(K&&!_)Y.push({type:"clear_thinking_20251015",keep:z?{type:"thinking_turns",value:1}:"all"});return Y.length>0?{edits:Y}:void 0}var agK=180000,sgK=40000,gSY,FSY;var egK=y(()=>{IY();E2();qM();NO6();Hr();m8();gSY=[...jr,i9,n3,Cq,Sj,$N],FSY=[X4,tK,nW]});function N_7(q,K){let _=-1;for(let z=0;z<q.length;z++){let Y=q[z];if(Y&&typeof Y==="object"&&"type"in Y&&Y.type==="tool_result")_=z}if(_>=0){let z=_+1;if(q.splice(z,0,K),z===q.length-1)q.push({type:"text",text:"."})}else{let z=Math.max(0,q.length-1);q.splice(z,0,K)}}import{randomUUID as IQ8}from"crypto";function np8(q){let K=process.env.CLAUDE_CODE_EXTRA_BODY,_={};if(K)try{let z=m5(K);if(z&&typeof z==="object"&&!Array.isArray(z))_={...z};else N(`CLAUDE_CODE_EXTRA_BODY env var must be a JSON object, but was given ${K}`,{level:"error"})}catch(z){N(`Error parsing CLAUDE_CODE_EXTRA_BODY: ${d6(z)}`,{level:"error"})}if(q&&q.length>0)if(_.anthropic_beta&&Array.isArray(_.anthropic_beta)){let z=_.anthropic_beta,Y=q.filter(($)=>!z.includes($));_.anthropic_beta=[...z,...Y]}else _.anthropic_beta=q;return _}function qFK(q){if(i6(process.env.DISABLE_PROMPT_CACHING))return!1;if(i6(process.env.DISABLE_PROMPT_CACHING_HAIKU)){let K=PH();if(q===K)return!1}if(i6(process.env.DISABLE_PROMPT_CACHING_SONNET)){let K=Av();if(q===K)return!1}if(i6(process.env.DISABLE_PROMPT_CACHING_OPUS)){let K=NV();if(q===K)return!1}return!0}function pU({scope:q,querySource:K}={}){return{type:"ephemeral",...QSY(K)&&{ttl:"1h"},...q==="global"&&{scope:q}}}function QSY(q){if(E7()==="bedrock"&&i6(process.env.ENABLE_PROMPT_CACHING_1H_BEDROCK))return!0;let K=ti8();if(K===null)K=d7()&&!WN.isUsingOverage,ei8(K);if(!K)return!1;let _=ai8();if(_===null)_=g8("tengu_prompt_cache_1h_config",{}).allowlist??[],si8(_);return q!==void 0&&_.some((z)=>z.endsWith("*")?q.startsWith(z.slice(0,-1)):q===z)}function dSY(q,K,_,z,Y){if(!fL(Y)||"effort"in K)return;if(q===void 0)z.push(EX1);else if(typeof q==="string")K.effort=q,z.push(EX1)}function cSY(q,K,_){if(!q||"task_budget"in K||!q16())return;if(K.task_budget={type:"tokens",total:q.total,...q.remaining!==void 0&&{remaining:q.remaining}},!_.includes(LX1))_.push(LX1)}function Pq6(){let q={},K=process.env.CLAUDE_CODE_EXTRA_METADATA;if(K){let _=m5(K,!1);if(_&&typeof _==="object"&&!Array.isArray(_))q=_;else N(`CLAUDE_CODE_EXTRA_METADATA env var must be a JSON object, but was given ${K}`,{level:"error"})}return{user_id:g6({...q,device_id:CS(),account_uuid:B_()?.accountUuid??"",session_id:N8()})}}async function zFK(q,K){if(K)return!0;try{let _=PH(),z=qL(_);return await Vy4(dk8(()=>eE({apiKey:q,maxRetries:3,model:_,source:"verify_api_key"}),async(Y)=>{let $=[{role:"user",content:"test"}];return await Y.beta.messages.create({model:_,max_tokens:1,messages:$,temperature:1,...z.length>0&&{betas:z},metadata:Pq6(),...np8()}),!0},{maxRetries:2,model:_,thinkingConfig:{type:"disabled"}}))}catch(_){let z=_;if(_ instanceof Uu)z=_.originalError;if(H6(z),z instanceof Error&&z.message.includes('{"type":"error","error":{"type":"authentication_error","message":"invalid x-api-key"}}'))return!1;throw z}}function lSY(q,K=!1,_,z){if(K)if(typeof q.message.content==="string")return{role:"user",content:[{type:"text",text:q.message.content,..._&&{cache_control:pU({querySource:z})}}]};else return{role:"user",content:q.message.content.map((Y,$)=>({...Y,...$===q.message.content.length-1?_?{cache_control:pU({querySource:z})}:{}:{}}))};return{role:"user",content:Array.isArray(q.message.content)?[...q.message.content]:q.message.content}}function nSY(q,K=!1,_,z){if(K)if(typeof q.message.content==="string")return{role:"assistant",content:[{type:"text",text:q.message.content,..._&&{cache_control:pU({querySource:z})}}]};else return{role:"assistant",content:q.message.content.map((Y,$)=>({...Y,...$===q.message.content.length-1&&Y.type!=="thinking"&&Y.type!=="redacted_thinking"?_?{cache_control:pU({querySource:z})}:{}:{}}))};return{role:"assistant",content:q.message.content}}async function Ed({messages:q,systemPrompt:K,thinkingConfig:_,tools:z,signal:Y,options:$}){let A;for await(let O of e87(q,async function*(){yield*YFK(q,K,_,z,Y,$)}))if(O.type==="assistant")A=O;if(!A){if(Y.aborted)throw new V_;throw Error("No assistant message found")}return A}async function*fR6({messages:q,systemPrompt:K,thinkingConfig:_,tools:z,signal:Y,options:$}){return yield*e87(q,async function*(){yield*YFK(q,K,_,z,Y,$)})}function iSY(q){if(!("isLsp"in q)||!q.isLsp)return!1;let K=WL6();return K.status==="pending"||K.status==="not-started"}function rSY(){let q=parseInt(process.env.API_TIMEOUT_MS||"",10);if(q)return q;return i6(process.env.CLAUDE_CODE_REMOTE)?120000:300000}async function*KFK(q,K,_,z,Y,$){let A=rSY(),O=dk8(()=>eE({maxRetries:0,model:q.model,fetchOverride:q.fetchOverride,source:q.source}),async(j,H,J)=>{let M=Date.now(),X=_(J);Y(X),z(H,M,X.max_tokens);let P=_CY(X,KCY);try{return await j.beta.messages.create({...P,model:uf(P.model)},{signal:K.signal,timeout:A})}catch(W){if(W instanceof V_)throw W;throw c8("error","cli_nonstreaming_fallback_error"),d("tengu_nonstreaming_fallback_error",{model:q.model,error:W instanceof Error?W.name:"unknown",attempt:H,timeout_ms:A,request_id:$??"unknown"}),W}},{model:K.model,fallbackModel:K.fallbackModel,thinkingConfig:K.thinkingConfig,...BK()&&{fastMode:K.fastMode},signal:K.signal,initialConsecutive529Errors:K.initialConsecutive529Errors,querySource:K.querySource}),w;do if(w=await O.next(),!w.done&&w.value.type==="system")yield w.value;while(!w.done);return w.value}function oSY(q){for(let K=q.length-1;K>=0;K--){let _=q[K];if(_.type==="assistant"&&_.requestId)return _.requestId}return}function uQ8(q){return q.type==="image"||q.type==="document"}function _FK(q){return q.type==="tool_result"}function aSY(q,K){let _=0;for(let z of q){if(!Array.isArray(z.message.content))continue;for(let Y of z.message.content){if(uQ8(Y))_++;if(_FK(Y)&&Array.isArray(Y.content)){for(let $ of Y.content)if(uQ8($))_++}}}if(_-=K,_<=0)return q;return q.map((z)=>{if(_<=0)return z;let Y=z.message.content;if(!Array.isArray(Y))return z;let $=_,A=Y.map((O)=>{if(_<=0||!_FK(O)||!Array.isArray(O.content))return O;let w=O.content.filter((j)=>{if(_>0&&uQ8(j))return _--,!1;return!0});return w.length===O.content.length?O:{...O,content:w}}).filter((O)=>{if(_>0&&uQ8(O))return _--,!1;return!0});return $===_?z:{...z,message:{...z.message,content:A}}})}async function*YFK(q,K,_,z,Y,$){if(!d7()&&Uz6($.model)&&(await gS("tengu-off-switch",{activated:!1})).activated){d("tengu_off_switch_query",{}),yield bB8(Error(Aj6),$.model);return}let A=oSY(q),O=E7()==="bedrock"&&$.model.includes("application-inference-profile")?await eH8($.model)??$.model:$.model;g3("query_tool_schema_build_start");let w=$.querySource.startsWith("repl_main_thread")||$.querySource.startsWith("agent:")||$.querySource==="sdk"||$.querySource==="hook_agent"||$.querySource==="verification_agent",j=OD8($.model,{isAgenticQuery:w});if(UU())j.push(hX1);let H;if(w&&UU()){let x6=$.advisorModel,b6=Zx4();if(b6!==void 0){if(uf(b6.baseModel)===uf($.model))x6=b6.advisorModel}if(x6){let Q6=uf(A5(x6));if(!nw6($.model))N(`[AdvisorTool] Skipping advisor - base model ${$.model} does not support advisor`);else if(!QN6(Q6))N(`[AdvisorTool] Skipping advisor - ${Q6} is not a valid advisor model`);else H=Q6,N(`[AdvisorTool] Server-side tool enabled with ${H} as the advisor model`)}}let J=await W18($.model,z,$.getToolPermissionContext,$.agents,"query"),M=new Set;if(J){for(let x6 of z)if(yC(x6))M.add(x6.name)}if(J&&M.size===0&&!$.hasPendingMcpServers)N("Tool search disabled: no deferred tools available to search"),J=!1;let X;if(J){let x6=iQ(q);X=z.filter((b6)=>{if(!M.has(b6.name))return!0;if(g_(b6,CP))return!0;return x6.has(b6.name)})}else X=z.filter((x6)=>!g_(x6,CP));let P=J?eSq():null;if(P&&E7()!=="bedrock"){if(!j.includes(P))j.push(P)}let W=!1,D="",f=fG6(),G=(x6)=>J&&(M.has(x6.name)||iSY(x6)),Z=f&&X.some((x6)=>x6.isMcp===!0&&!G(x6));if(f&&!j.includes(pF6))j.push(pF6);let T=f?Z?"none":"system_prompt":"none",v=await Promise.all(X.map((x6)=>Qp8(x6,{getToolPermissionContext:$.getToolPermissionContext,tools:z,agents:$.agents,allowedAgentTypes:$.allowedAgentTypes,model:$.model,deferLoading:G(x6)})));if(J){let x6=$7(X,(b6)=>M.has(b6.name));N(`Dynamic tool loading: ${x6}/${M.size} deferred tools included`)}g3("query_tool_schema_build_end"),d("tengu_api_before_normalize",{preNormalizedMessageCount:q.length}),g3("query_message_normalization_start");let V=bP(q,X);if(g3("query_message_normalization_end"),!J)V=V.map((x6)=>{switch(x6.type){case"user":return O77(x6);case"assistant":return n0K(x6);default:return x6}});if(V=KZK(V),!j.includes(hX1))V=_ZK(V);V=aSY(V,Yj4),d("tengu_api_after_normalize",{postNormalizedMessageCount:V.length});let E=ogK(V);if(J&&!V18()){let x6=z.filter((b6)=>M.has(b6.name)).map(si6).sort().join(`
7835`);if(x6)V=[U8({content:`<available-deferred-tools>
7836${x6}

Callers 5

sxKFunction · 0.85
AgKFunction · 0.85
RGFunction · 0.85
OQ8Function · 0.85
PrKFunction · 0.85

Calls 2

e87Function · 0.85
YFKFunction · 0.85

Tested by

no test coverage detected