| 3753 | <${FT}>${w}</${FT}> |
| 3754 | <${wj}>${_}</${wj}> |
| 3755 | <${gw}>${A}</${gw}> |
| 3756 | </${XA}>`;IO({value:j,mode:"task-notification"})}function Bm8(q){if(typeof q!=="object"||q===null||!("type"in q)||!("agentType"in q))return!1;return q.type==="local_agent"&&q.agentType==="main-session"}function mMK({messages:q,queryParams:K,description:_,setAppState:z,agentDefinition:Y}){let{taskId:$,abortSignal:A}=FqY(_,z,Y);return SQ(q,$).catch((w)=>N(`bg-session initial transcript write failed: ${w}`)),KF({agentId:$,agentType:"subagent",subagentName:"main-session",isBuiltIn:!0},async()=>{try{let w=[...q],j=[],H=0,J=0,M=q.at(-1)?.uuid??null;for await(let X of Db({messages:w,...K})){if(A.aborted){let P=!1;if(A3($,z,(W)=>{return P=W.notified===!0,P?W:{...W,notified:!0}}),!P)ZN($,"stopped",{summary:_});return}if(X.type!=="user"&&X.type!=="assistant"&&X.type!=="system")continue;if(w.push(X),SQ([X],$,M).catch((P)=>N(`bg-session transcript write failed: ${P}`)),M=X.uuid,X.type==="assistant"){for(let P of X.message.content)if(P.type==="text")J+=E3(P.text);else if(P.type==="tool_use"){H++;let W={toolName:P.name,input:P.input};if(j.push(W),j.length>QqY)j.shift()}}z((P)=>{let W=P.tasks[$];if(!W||W.type!=="local_agent")return P;let D=W.progress;if(D?.tokenCount===J&&D.toolUseCount===H&&W.messages===w)return P;return{...P,tasks:{...P.tasks,[$]:{...W,progress:{tokenCount:J,toolUseCount:H,recentActivities:D?.toolUseCount===H?D.recentActivities:[...j]},messages:w}}}})}uMK($,!0,z)}catch(w){H6(w),uMK($,!1,z)}}),$}var BqY,IMK="0123456789abcdefghijklmnopqrstuvwxyz",QqY=5;var gm8=y(()=>{RY();Tj6();ON();GN();M0();B2();Ou();c9();_8();E8();p2();pC();_K();Ij();J0();BqY={agentType:"main-session",whenToUse:"Main session query",source:"userSettings",getSystemPrompt:()=>""}});function pMK(q){if(q.startsWith("uds:"))return{scheme:"uds",target:q.slice(4)};if(q.startsWith("bridge:"))return{scheme:"bridge",target:q.slice(7)};if(q.startsWith("/"))return{scheme:"uds",target:q};return{scheme:"other",target:q}}function Eb({mainThreadAgentDefinition:q,toolUseContext:K,customSystemPrompt:_,defaultSystemPrompt:z,appendSystemPrompt:Y,overrideSystemPrompt:$}){if($)return iK([$]);let A=q?I2(q)?q.getSystemPrompt({toolUseContext:{options:K.options}}):q.getSystemPrompt():void 0;if(q?.memory)d("tengu_agent_memory_loaded",{...!1,scope:q.memory,source:"main-thread"});return iK([...A?[A]:_?[_]:z,...Y?[Y]:[]])}var xR6=y(()=>{k8();SP();m8()});import{randomUUID as dqY}from"crypto";function Lb(){return!1}function FMK(q){return q.some((K)=>{if(K.type!=="user")return!1;let _=K.message.content;if(!Array.isArray(_))return!1;return _.some((z)=>z.type==="text"&&z.text.includes(`<${W$8}>`))})}function UMK(q,K){let _={...K,uuid:dqY(),message:{...K.message,content:[...K.message.content]}},z=K.message.content.filter((A)=>A.type==="tool_use");if(z.length===0)return N(`No tool_use blocks found in assistant message for fork directive: ${q.slice(0,50)}...`,{level:"error"}),[U8({content:[{type:"text",text:gMK(q)}]})];let Y=z.map((A)=>({type:"tool_result",tool_use_id:A.id,content:[{type:"text",text:lqY}]})),$=U8({content:[...Y,{type:"text",text:gMK(q)}]});return[_,$]}function gMK(q){return`<${W$8}> |
| 3757 | STOP. READ THIS FIRST. |
| 3758 | |
| 3759 | You are a forked worker process. You are NOT the main agent. |
| 3760 | |
| 3761 | RULES (non-negotiable): |
| 3762 | 1. Your system prompt says "default to forking." IGNORE IT — that's for the parent. You ARE the fork. Do NOT spawn sub-agents; execute directly. |
| 3763 | 2. Do NOT converse, ask questions, or suggest next steps |
| 3764 | 3. Do NOT editorialize or add meta-commentary |
| 3765 | 4. USE your tools directly: Bash, Read, Write, etc. |
| 3766 | 5. If you modify files, commit your changes before reporting. Include the commit hash in your report. |
| 3767 | 6. Do NOT emit text between tool calls. Use tools silently, then report once at the end. |
| 3768 | 7. Stay strictly within your directive's scope. If you discover related systems outside your scope, mention them in one sentence at most — other workers cover those areas. |
| 3769 | 8. Keep your report under 500 words unless the directive specifies otherwise. Be factual and concise. |
| 3770 | 9. Your response MUST begin with "Scope:". No preamble, no thinking-out-loud. |
| 3771 | 10. REPORT structured facts, then stop |
| 3772 | |
| 3773 | Output format (plain text labels, not markdown headers): |
| 3774 | Scope: <echo back your assigned scope in one sentence> |
| 3775 | Result: <the answer or key findings, limited to the scope above> |
| 3776 | Key files: <relevant file paths — include for research tasks> |
| 3777 | Files changed: <list with commit hash — include only if you modified files> |
| 3778 | Issues: <list — include only if there are issues to flag> |
| 3779 | </${W$8}> |
| 3780 | |
| 3781 | ${OL7}${q}`}function QMK(q,K){return`You've inherited the conversation context above from a parent agent working in ${q}. You are operating in an isolated git worktree at ${K} — same repository, same relative file structure, separate working copy. Paths in the inherited context refer to the parent's working directory; translate them to your worktree root. Re-read files before editing if the parent may have modified them since they appear in the context. Your changes stay in this worktree and will not affect the parent's files.`}var cqY="fork",IR6,lqY="Fork started — processing in background";var g88=y(()=>{v8();RY();So6();_8();i1();IR6={agentType:cqY,whenToUse:"Implicit fork — inherits full conversation context. Not selectable via subagent_type; triggered by omitting subagent_type when the fork experiment is active.",tools:["*"],maxTurns:200,model:"inherit",permissionMode:"bubble",source:"built-in",baseDir:"built-in",getSystemPrompt:()=>""}});import{promises as dMK}from"fs";async function F88({agentId:q,prompt:K,toolUseContext:_,canUseTool:z,invokingRequestId:Y}){let $=Date.now(),A=_.getAppState(),O=_.setAppStateForTasks??_.setAppState,w=A.toolPermissionContext.mode,[j,H]=await Promise.all([AK6(pO(q)),J67(pO(q))]);if(!j)throw Error(`No transcript found for agent ID: ${q}`);let J=W68(D68(Lx8(j.messages))),M=eR4(_.contentReplacementState,J,j.contentReplacements),X=H?.worktreePath?await dMK.stat(H.worktreePath).then((x)=>x.isDirectory()?H.worktreePath:void 0,()=>{N(`Resumed worktree ${H.worktreePath} no longer exists; falling back to parent cwd`);return}):void 0;if(X){let x=new Date;await dMK.utimes(X,x,x)}let P,W=!1;if(H?.agentType===IR6.agentType)P=IR6,W=!0;else if(H?.agentType)P=_.options.agentDefinitions.activeAgents.find((I)=>I.agentType===H.agentType)??lF;else P=lF;let D=H?.description??"(resumed)",f;if(W){if(_.renderedSystemPrompt)f=_.renderedSystemPrompt;else{let x=A.agent?A.agentDefinitions.activeAgents.find((p)=>p.agentType===A.agent):void 0,I=Array.from(A.toolPermissionContext.additionalWorkingDirectories.keys()),B=await QP(_.options.tools,_.options.mainLoopModel,I,_.options.mcpClients);f=Eb({mainThreadAgentDefinition:x,toolUseContext:_,customSystemPrompt:_.options.customSystemPrompt,defaultSystemPrompt:B,appendSystemPrompt:_.options.appendSystemPrompt})}if(!f)throw Error("Cannot resume fork agent: unable to reconstruct parent system prompt")}let G=BN6(P.model,_.options.mainLoopModel,void 0,w),Z={...A.toolPermissionContext,mode:P.permissionMode??"acceptEdits"},T=W?_.options.tools:nQ(Z,A.mcp.tools),v={agentDefinition:P,promptMessages:[...J,U8({content:K})],toolUseContext:_,canUseTool:z,isAsync:!0,querySource:QN8(P.agentType,I2(P)),model:void 0,override:W?{systemPrompt:f}:void 0,availableTools:T,forkContextMessages:void 0,...W&&{useExactTools:!0},worktreePath:X,description:H?.description,contentReplacementState:M},V=Fm8({agentId:q,description:D,prompt:K,selectedAgent:P,setAppState:O,toolUseId:_.toolUseId}),E={prompt:K,resolvedAgentModel:G,isBuiltInAgent:I2(P),startTime:$,agentType:P.agentType,isAsync:!0},S={agentId:q,parentSessionId:_F(),agentType:"subagent",subagentName:P.agentType,isBuiltIn:I2(P),invokingRequestId:Y,invocationKind:"resume",invocationEmitted:!1},R=(x)=>X?S$8(X,x):x();return KF(S,()=>R(()=>RL8({taskId:V.agentId,abortController:V.abortController,makeStream:(x)=>iN({...v,override:{...v.override,agentId:pO(V.agentId),abortController:V.abortController},onCacheSafeParams:x}),metadata:E,description:D,toolUseContext:_,rootSetAppState:O,agentIdForCleanup:q,enableSummarization:pV6()||Lb()||sp(),getWorktreeResult:async()=>X?{worktreePath:X}:{}}))),{agentId:q,description:D,outputFile:sz(q)}}var H67=y(()=>{v8();rL();So6();gP();BD();M0();Ou();I7();_8();i1();cq6();dN8();_K();xR6();Ij();AY();IG();rq6();ci6();g88();SP();i46()});function lMK(){return` |
| 3782 | # SendMessage |
| 3783 | |