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

Function contextModifier

package/cli.js:2491–2491  ·  view source on GitHub ↗
(R)

Source from the content-addressed store, hash-verified

2489Remote review did not produce output (${K}). Tell the user to retry /ultrareview, or use /review for a local review instead.`;IO({value:z,mode:"task-notification"})}function fdz(q){let K=q.findLast((Y)=>Y.type==="assistant"&&Y.message.content.some(($)=>$.type==="tool_use"&&$.name===im.name));if(!K)return[];let _=K.message.content.find((Y)=>Y.type==="tool_use"&&Y.name===im.name)?.input;if(!_)return[];let z=im.inputSchema.safeParse(_);if(!z.success)return[];return z.data.todos}function mx8(q){let{remoteTaskType:K,session:_,command:z,context:Y,toolUseId:$,isRemoteReview:A,isUltraplan:O,isLongRunning:w,remoteTaskMetadata:j}=q,H=aL("remote_agent");px8(H);let J={...C0(H,"remote_agent",_.title,$),type:"remote_agent",remoteTaskType:K,status:"running",sessionId:_.id,command:z,title:_.title,todoList:[],log:[],isRemoteReview:A,isUltraplan:O,isLongRunning:w,pollStartedAt:Date.now(),remoteTaskMetadata:j};H0(J,Y.setAppState),Xdz({taskId:H,remoteTaskType:K,sessionId:_.id,title:_.title,command:z,spawnedAt:Date.now(),toolUseId:$,isUltraplan:O,isRemoteReview:A,isLongRunning:w,remoteTaskMetadata:j});let M=w3K(H,Y);return{taskId:H,sessionId:_.id,cleanup:M}}async function ko1(q){try{await Zdz(q)}catch(K){N(`restoreRemoteAgentTasks failed: ${String(K)}`)}}async function Zdz(q){let K=await yo1();if(K.length===0)return;for(let _ of K){let z;try{z=(await s46(_.sessionId)).session_status}catch($){if($ instanceof Error&&$.message.startsWith("Session not found:"))N(`restoreRemoteAgentTasks: dropping ${_.taskId} (404: ${String($)})`),wa(_.taskId);else N(`restoreRemoteAgentTasks: skipping ${_.taskId} (recoverable: ${String($)})`);continue}if(z==="archived"){wa(_.taskId);continue}let Y={...C0(_.taskId,"remote_agent",_.title,_.toolUseId),type:"remote_agent",remoteTaskType:Jdz(_.remoteTaskType)?_.remoteTaskType:"remote-agent",status:"running",sessionId:_.sessionId,command:_.command,title:_.title,todoList:[],log:[],isRemoteReview:_.isRemoteReview,isUltraplan:_.isUltraplan,isLongRunning:_.isLongRunning,startTime:_.spawnedAt,pollStartedAt:Date.now(),remoteTaskMetadata:_.remoteTaskMetadata};H0(Y,q.setAppState),px8(_.taskId),w3K(_.taskId,q)}}function w3K(q,K){let _=!0,z=1000,Y=1800000,$=5,A=0,O=null,w=[],j=null,H=async()=>{if(!_)return;try{let M=K.getAppState().tasks?.[q];if(!M||M.status!=="running")return;let X=await T68(M.sessionId,O);O=X.lastEventId;let P=X.newEvents.length>0;if(P){w=[...w,...X.newEvents];let x=X.newEvents.map((I)=>{if(I.type==="assistant")return I.message.content.filter((B)=>B.type==="text").map((B)=>("text"in B)?B.text:"").join(`
2490`);return g6(I)}).join(`
2491`);if(x)j3K(q,x+`
2492`)}if(X.sessionStatus==="archived"){A3(q,K.setAppState,(x)=>x.status==="running"?{...x,status:"completed",endTime:Date.now()}:x),To1(q,M.title,"completed",K.setAppState,M.toolUseId),Zw(q),wa(q);return}let W=Mdz.get(M.remoteTaskType);if(W){let x=await W(M.remoteTaskMetadata);if(x!==null){A3(q,K.setAppState,(I)=>I.status==="running"?{...I,status:"completed",endTime:Date.now()}:I),To1(q,x,"completed",K.setAppState,M.toolUseId),Zw(q),wa(q);return}}let D=M.isUltraplan||M.isLongRunning?void 0:w.findLast((x)=>x.type==="result");if(M.isRemoteReview&&P&&j===null)j=Wdz(X.newEvents);let f;if(M.isRemoteReview&&P){let x=`<${tq1}>`,I=`</${tq1}>`;for(let B of X.newEvents)if(B.type==="system"&&(B.subtype==="hook_progress"||B.subtype==="hook_response")){let p=B.stdout,C=p.lastIndexOf(I),g=C===-1?-1:p.lastIndexOf(x,C);if(g!==-1&&C>g)try{let F=JSON.parse(p.slice(g+x.length,C));f={stage:F.stage,bugsFound:F.bugs_found??0,bugsVerified:F.bugs_verified??0,bugsRefuted:F.bugs_refuted??0}}catch{}}}let G=w.some((x)=>x.type==="assistant"||M.isRemoteReview&&x.type==="system"&&(x.subtype==="hook_progress"||x.subtype==="hook_response"));if(X.sessionStatus==="idle"&&!P&&G)A++;else A=0;let Z=A>=$,T=w.some((x)=>x.type==="system"&&(x.subtype==="hook_started"||x.subtype==="hook_progress"||x.subtype==="hook_response")&&x.hook_event==="SessionStart"),v=w.some((x)=>x.type==="assistant"),V=M.isRemoteReview&&(j!==null||!T&&Z&&v),E=M.isRemoteReview&&Date.now()-M.pollStartedAt>Y,S=D?D.subtype==="success"?"completed":"failed":V||E?"completed":w.length>0?"running":"starting",R=!1;if(A3(q,K.setAppState,(x)=>{if(x.status!=="running")return R=!0,x;if(!P&&(S==="running"||S==="starting"))return x;return{...x,status:S==="starting"?"running":S,log:w,todoList:P?fdz(w):x.todoList,reviewProgress:f??x.reviewProgress,endTime:D||V||E?Date.now():void 0}}),R)return;if(D||V||E){let x=D&&D.subtype!=="success"?"failed":"completed";if(M.isRemoteReview){let I=j??Pdz(w);if(I&&x==="completed"){Ddz(q,I,K.setAppState),Zw(q),wa(q);return}A3(q,K.setAppState,(p)=>({...p,status:"failed"}));let B=D&&D.subtype!=="success"?"remote session returned an error":E&&!V?"remote session exceeded 30 minutes":"no review output — orchestrator may have exited early";O3K(q,B,K.setAppState),Zw(q),wa(q);return}To1(q,M.title,x,K.setAppState,M.toolUseId),Zw(q),wa(q);return}}catch(J){H6(J),A=0;try{let X=K.getAppState().tasks?.[q];if(X?.isRemoteReview&&X.status==="running"&&Date.now()-X.pollStartedAt>Y){A3(q,K.setAppState,(P)=>({...P,status:"failed",endTime:Date.now()})),O3K(q,"remote session exceeded 30 minutes",K.setAppState),Zw(q),wa(q);return}}catch{}}if(_)setTimeout(H,z)};return H(),()=>{_=!1}}function Rj6(q){return MM(q,process.env.SESSION_INGRESS_URL)}var Hdz,Mdz,AL6;var PK6=y(()=>{RY();GN();q68();M5K();_8();E8();p2();i1();pC();_K();l8();Ij();J0();VM();am();Hdz=["remote-agent","ultraplan","ultrareview","autofix-pr","background-pr"];Mdz=new Map;AL6={name:"RemoteAgentTask",type:"remote_agent",async kill(q,K){let _,z,Y,$=!1;if(A3(q,K,(A)=>{if(A.status!=="running")return A;return _=A.toolUseId,z=A.description,Y=A.sessionId,$=!0,{...A,status:"killed",notified:!0,endTime:Date.now()}}),$){if(ZN(q,"stopped",{toolUseId:_,summary:z}),Y)$L6(Y).catch((A)=>N(`RemoteAgentTask archive failed: ${String(A)}`))}Zw(q),wa(q),N(`RemoteAgentTask ${q} killed, archiving session ${Y??"unknown"}`)}}});function H3K(q,K){if(!K)return q;return q.map((_)=>{if(_.type==="user")return{..._,sourceToolUseID:K};return _})}function J3K(q,K){let _=q.message.content.find((z)=>z.type==="tool_use"&&z.name===K);return _&&_.type==="tool_use"?_.id:void 0}function M3K(q){if("status"in q&&q.status==="forked")return K_.createElement(s8,{height:1},K_.createElement(k,null,K_.createElement(I1,null,["Done"])));let K=["Successfully loaded skill"];if("allowedTools"in q&&q.allowedTools&&q.allowedTools.length>0){let _=q.allowedTools.length;K.push(`${_} ${A7(_,"tool")} allowed`)}if("model"in q&&q.model)K.push(q.model);return K_.createElement(s8,{height:1},K_.createElement(k,null,K_.createElement(I1,null,K)))}function X3K({skill:q},{commands:K}){if(!q)return null;return K?.find((Y)=>Y.name===q)?.loadedFrom==="commands_DEPRECATED"?`/${q}`:q}function Bx8(q,{tools:K,verbose:_}){if(!q.length)return K_.createElement(s8,{height:1},K_.createElement(k,{dimColor:!0},Tdz));let z=_?q:q.slice(-Gdz),Y=q.length-z.length,{inProgressToolUseIDs:$}=re6(q.map((A)=>A.data));return K_.createElement(s8,null,K_.createElement(u,{flexDirection:"column"},K_.createElement(lo6,null,z.map((A)=>K_.createElement(u,{key:A.uuid,height:1,overflow:"hidden"},K_.createElement(Xb,{message:A.data.message,lookups:za,addMargin:!1,tools:K,commands:[],verbose:_,inProgressToolUseIDs:$,progressMessagesForMessage:[],shouldAnimate:!1,shouldShowDot:!1,style:"condensed",isTranscriptMode:!1,isStatic:!0})))),Y>0&&K_.createElement(k,{dimColor:!0},"+",Y," more tool ",A7(Y,"use"))))}function P3K(q,{progressMessagesForMessage:K,tools:_,verbose:z}){return K_.createElement(K_.Fragment,null,Bx8(K,{tools:_,verbose:z}),K_.createElement(FU,null))}function W3K(q,{progressMessagesForMessage:K,tools:_,verbose:z}){return K_.createElement(K_.Fragment,null,Bx8(K,{tools:_,verbose:z}),K_.createElement(Y2,{result:q,verbose:z}))}var K_,Gdz=3,Tdz="Initializing…";var D3K=y(()=>{rv();bN();oa6();QK();dE6();gK();s6();i1();K_=O6(D6(),1)});async function Eo1(q){let K=q.getAppState().mcp.commands.filter((z)=>z.type==="prompt"&&z.loadedFrom==="mcp");if(K.length===0)return u0(Fz());let _=await u0(Fz());return u2([..._,...K],"name")}async function vdz(q,K,_,z,Y,$,A){let O=Date.now(),w=wm(),j=RQ().has(K),H=f3K(q),J=q.source==="bundled",M=j||J||H?K:"custom",X={},P=q.pluginInfo?Z4(q.pluginInfo.repository).marketplace:void 0,W=z.queryTracking?.depth??0,D=Au()?.agentId;d("tengu_skill_tool_invocation",{command_name:M,_PROTO_skill_name:K,execution_context:"fork",invocation_trigger:W>0?"nested-skill":"claude-proactive",query_depth:W,...D&&{parent_agent_id:D},...X,...!1,...q.pluginInfo&&{_PROTO_plugin_name:q.pluginInfo.pluginManifest.name,...P&&{_PROTO_marketplace_name:P},plugin_name:H?q.pluginInfo.pluginManifest.name:"third-party",plugin_repository:H?q.pluginInfo.repository:"third-party",...Zj6(q.pluginInfo)}});let{modifiedGetAppState:f,baseAgent:G,promptMessages:Z,skillContent:T}=await Kx8(q,_||"",z),v=q.effort!==void 0?{...G,effort:q.effort}:G,V=[];N(`SkillTool executing forked skill ${K} with agent ${v.agentType}`);try{for await(let R of iN({agentDefinition:v,promptMessages:Z,toolUseContext:{...z,getAppState:f},canUseTool:Y,isAsync:!1,querySource:"agent:custom",model:q.model,availableTools:z.options.tools,override:{agentId:w}}))if(V.push(R),(R.type==="assistant"||R.type==="user")&&A){let x=yX([R]);for(let I of x)if(I.message.content.some((p)=>p.type==="tool_use"||p.type==="tool_result"))A({toolUseID:`skill_${$.message.id}`,data:{message:I,type:"skill_progress",prompt:T,agentId:w}})}let E=_x8(V,"Skill execution completed");V.length=0;let S=Date.now()-O;return N(`SkillTool forked skill ${K} completed in ${S}ms`),{data:{success:!0,commandName:K,status:"forked",agentId:w,result:E}}}finally{ut(w)}}function ydz(q){for(let K of Object.keys(q)){if(Ndz.has(K))continue;let _=q[K];if(_===void 0||_===null)continue;if(Array.isArray(_)&&_.length===0)continue;if(typeof _==="object"&&!Array.isArray(_)&&Object.keys(_).length===0)continue;return!1}return!0}function f3K(q){if(q.source!=="plugin"||!q.pluginInfo?.repository)return!1;return Ru(Z4(q.pluginInfo.repository).marketplace)}var kdz,Vdz,WK6,Ndz;var Fx8=y(()=>{Fu();v8();yA();Bq();_8();Fj();hP();lE6();x7();v8();RY();k8();Ou();y8();nv();rV();i1();aq();tb8();jm();i46();yO6();D3K();kdz=B6(()=>L.object({skill:L.string().describe('The skill name. E.g., "commit", "review-pr", or "pdf"'),args:L.string().optional().describe("Optional arguments for the skill")})),Vdz=B6(()=>{let q=L.object({success:L.boolean().describe("Whether the skill is valid"),commandName:L.string().describe("The name of the skill"),allowedTools:L.array(L.string()).optional().describe("Tools allowed by this skill"),model:L.string().optional().describe("Model override if specified"),status:L.literal("inline").optional().describe("Execution status")}),K=L.object({success:L.boolean().describe("Whether the skill completed successfully"),commandName:L.string().describe("The name of the skill"),status:L.literal("forked").describe("Execution status"),agentId:L.string().describe("The ID of the sub-agent that executed the skill"),result:L.string().describe("The result from the forked skill execution")});return L.union([q,K])}),WK6=sq({name:JM,searchHint:"invoke a slash-command skill",maxResultSizeChars:1e5,get inputSchema(){return kdz()},get outputSchema(){return Vdz()},description:async({skill:q})=>`Execute skill: ${q}`,prompt:async()=>fk8(Fz()),toAutoClassifierInput:({skill:q})=>q??"",async validateInput({skill:q},K){let _=q.trim();if(!_)return{result:!1,message:`Invalid skill format: ${q}`,errorCode:1};let z=_.startsWith("/");if(z)d("tengu_skill_tool_slash_prefix",{});let Y=z?_.substring(1):_,$=await Eo1(K),A=hQ(Y,$);if(!A)return{result:!1,message:`Unknown skill: ${Y}`,errorCode:2};if(A.disableModelInvocation)return{result:!1,message:`Skill ${Y} cannot be used with ${JM} tool due to disable-model-invocation`,errorCode:4};if(A.type!=="prompt")return{result:!1,message:`Skill ${Y} is not a prompt-based skill`,errorCode:5};return{result:!0}},async checkPermissions({skill:q,args:K},_){let z=q.trim(),Y=z.startsWith("/")?z.substring(1):z,A=_.getAppState().toolPermissionContext,O=await Eo1(_),w=hQ(Y,O),j=(X)=>{let P=X.startsWith("/")?X.substring(1):X;if(P===Y)return!0;if(P.endsWith(":*")){let W=P.slice(0,-2);return Y.startsWith(W)}return!1},H=sm(A,WK6,"deny");for(let[X,P]of H.entries())if(j(X))return{behavior:"deny",message:"Skill execution blocked by permission rules",decisionReason:{type:"rule",rule:P}};let J=sm(A,WK6,"allow");for(let[X,P]of J.entries())if(j(X))return{behavior:"allow",updatedInput:{skill:q,args:K},decisionReason:{type:"rule",rule:P}};if(w?.type==="prompt"&&ydz(w))return{behavior:"allow",updatedInput:{skill:q,args:K},decisionReason:void 0};let M=[{type:"addRules",rules:[{toolName:JM,ruleContent:Y}],behavior:"allow",destination:"localSettings"},{type:"addRules",rules:[{toolName:JM,ruleContent:`${Y}:*`}],behavior:"allow",destination:"localSettings"}];return{behavior:"ask",message:`Execute skill: ${Y}`,decisionReason:void 0,suggestions:M,updatedInput:{skill:q,args:K},metadata:w?{command:w}:void 0}},async call({skill:q,args:K},_,z,Y,$){let A=q.trim(),O=A.startsWith("/")?A.substring(1):A,w=await Eo1(_),j=hQ(O,w);if(sb8(O),j?.type==="prompt"&&j.context==="fork")return vdz(j,O,K,_,z,Y,$);let{processPromptSlashCommand:H}=await Promise.resolve().then(() => (qx8(),eb8)),J=await H(O,K||"",w,_);if(!J.shouldQuery)throw Error("Command processing failed");let M=J.allowedTools||[],X=J.model,P=j?.type==="prompt"?j.effort:void 0,W=RQ().has(O),D=j?.type==="prompt"&&j.source==="bundled",f=j?.type==="prompt"&&f3K(j),G=W||D||f?O:"custom",Z={},T=j?.type==="prompt"&&j.pluginInfo?Z4(j.pluginInfo.repository).marketplace:void 0,v=_.queryTracking?.depth??0,V=Au()?.agentId;d("tengu_skill_tool_invocation",{command_name:G,_PROTO_skill_name:O,execution_context:"inline",invocation_trigger:v>0?"nested-skill":"claude-proactive",query_depth:v,...V&&{parent_agent_id:V},...Z,...!1,...j?.type==="prompt"&&j.pluginInfo&&{_PROTO_plugin_name:j.pluginInfo.pluginManifest.name,...T&&{_PROTO_marketplace_name:T},plugin_name:f?j.pluginInfo.pluginManifest.name:"third-party",plugin_repository:f?j.pluginInfo.repository:"third-party",...Zj6(j.pluginInfo)}});let E=J3K(Y,JM),S=H3K(J.messages.filter((R)=>{if(R.type==="progress")return!1;if(R.type==="user"&&"message"in R){let x=R.message.content;if(typeof x==="string"&&x.includes(`<${wP}>`))return!1}return!0}),E);return N(`SkillTool returning ${S.length} newMessages for skill ${O}`),{data:{success:!0,commandName:O,allowedTools:M.length>0?M:void 0,model:X},newMessages:S,contextModifier(R){let x=R;if(M.length>0){let I=x.getAppState;x={...x,getAppState(){let B=I();return{...B,toolPermissionContext:{...B.toolPermissionContext,alwaysAllowRules:{...B.toolPermissionContext.alwaysAllowRules,command:[...new Set([...B.toolPermissionContext.alwaysAllowRules.command||[],...M])]}}}}}}if(X)x={...x,options:{...x.options,mainLoopModel:cF6(X,R.options.mainLoopModel)}};if(P!==void 0){let I=x.getAppState;x={...x,getAppState(){return{...I(),effortValue:P}}}}return x}}},mapToolResultToToolResultBlockParam(q,K){if("status"in q&&q.status==="forked")return{type:"tool_result",tool_use_id:K,content:`Skill "${q.commandName}" completed (forked execution).
2493
2494Result:

Callers

nothing calls this directly

Calls 1

cF6Function · 0.85

Tested by

no test coverage detected