module.exports=[65885,t=>{"use strict";var e=t.i(2157),a=t.i(60526),s=t.i(50227);t.i(66680),t.i(53533);let i=process.env.OPENCLAW_HOME??(0,s.join)((0,a.homedir)(),".openclaw");t.s(["buildPendingSessionKey",0,function(t,e){return`agent:${t}:${e}`},"findSessionBySessionId",0,function(t,a){let n=function(t){let a,n=(0,s.join)(i,"agents",t,"sessions","sessions.json");if(!(0,e.existsSync)(n))return[];try{a=JSON.parse((0,e.readFileSync)(n,"utf8"))}catch{return[]}let r=`agent:${t}:`,o=[];for(let[t,e]of Object.entries(a)){if(!e.sessionId)continue;let a=t.startsWith(r)?t.slice(r.length):t;o.push({sessionId:e.sessionId,label:a,sessionKey:t,lastInteractionAt:e.lastInteractionAt??e.updatedAt??0,pending:!1})}return o.sort((t,e)=>e.lastInteractionAt-t.lastInteractionAt),o}(t);return n.find(t=>t.label===a)??n.find(t=>t.sessionId===a)??null}])},97746,t=>{"use strict";var e=t.i(12714);t.i(2157);var a=t.i(60526),s=t.i(50227),i=t.i(66680);function n(t,e){return(0,s.join)(process.env.NOTFAIR_CMO_DATA_DIR??(0,s.join)((0,a.homedir)(),".notfair-cmo"),"agents",t,"shadow",`${e}.jsonl`)}async function r(t,a){await (0,e.mkdir)((0,s.dirname)(n(t,a)),{recursive:!0})}async function o(t,a){await r(t,a);let s=n(t,a),o="";async function l(t){await (0,e.appendFile)(s,`${JSON.stringify(t)}
`,"utf8")}async function d(){let t=o.trim();o="",t&&await l({type:"message",id:`shadow-${(0,i.randomUUID)()}`,timestamp:new Date().toISOString(),message:{role:"assistant",content:[{type:"text",text:t}]}})}return{appendDelta(t){o+=t},replaceAssistant(t){o=t},flushAssistant:d,async toolStart(t,e,a){await d(),await l({type:"message",id:`shadow-${(0,i.randomUUID)()}`,timestamp:new Date().toISOString(),message:{role:"assistant",content:[{type:"toolCall",id:t,name:e,...a?{arguments:{__label:a}}:{}}]}})},async toolResult(t,e,a,s){await l({type:"message",id:`shadow-${(0,i.randomUUID)()}`,timestamp:new Date().toISOString(),message:{role:"toolResult",toolCallId:t,toolName:e,isError:!a,content:s?[{type:"text",text:s}]:void 0}})},async close(){await d()}}}async function l(t,e){switch(e.kind){case"delta":t.appendDelta(e.text);return;case"final":t.replaceAssistant(e.text),await t.flushAssistant();return;case"tool":"start"===e.phase?await t.toolStart(e.toolCallId,e.name,e.label):"result"===e.phase&&await t.toolResult(e.toolCallId,e.name,!0,e.label);return;case"lifecycle":case"error":return}}async function d(t,a,s){let i,r,o=n(t,a);try{i=(await (0,e.stat)(o)).size}catch{return{bytes:"",byteOffset:s,fileSize:0}}if(s>i&&(s=0),s===i)return{bytes:"",byteOffset:s,fileSize:i};try{r=(await (0,e.readFile)(o)).slice(s).toString("utf8")}catch{return{bytes:"",byteOffset:s,fileSize:i}}let l=r.lastIndexOf("\n"),d=l<0?"":r.slice(0,l+1),c=s+Buffer.byteLength(d,"utf8");return{bytes:d,byteOffset:c,fileSize:i}}t.s(["openShadowWriter",0,o,"readShadowFromOffset",0,d,"shadowStreamEvent",0,l,"shadowTranscriptPath",0,n])},43940,t=>{"use strict";var e=t.i(66680);t.s(["buildTaskKickoffMessage",0,function(t){let e=["(task assignment)","",`project_slug: ${t.project_slug}`,`agent_id:     ${t.agent_id}`,`task_id:      ${t.id}`,`Title:        ${t.title??"(untitled)"}`,"","Brief:",t.brief,""];return t.success_criteria&&e.push("Success criteria:",t.success_criteria,""),e.push("Acknowledge this task in 1-2 sentences (what you'll do + roughly how","long), then start working. Use your domain tools to actually do the","thing — don't just describe what you'd do. Close the task out when","you're done."),e.join("\n")},"generateTaskThreadId",0,function(){return(0,e.randomUUID)()}])},14294,t=>{"use strict";var e=t.i(65885),a=t.i(82651),s=t.i(97746),i=t.i(60273),n=t.i(43940);async function r(t){let r=t;if(!r.thread_id){let e=(0,i.setTaskThreadIfMissing)(t.id,(0,n.generateTaskThreadId)());if(e&&(r=e),!r.thread_id)throw Error(`Failed to assign thread_id for task ${t.id}`)}let o=(0,e.buildPendingSessionKey)(r.agent_id,r.thread_id),l=(0,n.buildTaskKickoffMessage)(r),d=await (0,s.openShadowWriter)(r.agent_id,r.thread_id);console.log(`[run-task] kickoff start task=${r.id} agent=${r.agent_id} thread=${r.thread_id}`);let c=[2e3,4e3,8e3],u=null,f=!1;for(let t=0;t<=c.length;t+=1)try{for await(let t of(0,a.streamChatViaGateway)({sessionKey:o,sessionId:r.thread_id,message:l})){try{await (0,s.shadowStreamEvent)(d,t)}catch(t){console.error("[run-task] shadow write failed:",t)}if("error"===t.kind)throw Error(t.message)}f=!0;break}catch(a){if(u=a,!(a instanceof Error?a.message:String(a)).includes("no longer exists in configuration")||t>=c.length)break;let e=c[t];console.warn(`[run-task] gateway snapshot stale for ${r.agent_id}; retrying in ${e}ms (attempt ${t+1}/${c.length})`),await new Promise(t=>setTimeout(t,e))}if(f){await d.close(),console.log(`[run-task] kickoff stream done task=${r.id}`);return}await d.close().catch(()=>void 0);let g=u instanceof Error?u.message:String(u);console.error(`[run-task] kickoff failed task=${r.id} agent=${r.agent_id}: ${g}`),(0,i.updateTask)(r.id,{status:"failed",error_message:g})}t.s(["startTaskIfProposed",0,function(t){let e=(0,i.claimProposedTask)(t.id);return e?(r(e).catch(t=>{console.error("[start-task] kickoff failed:",t)}),e):t}])}];

//# sourceMappingURL=src_server_0ppp6my._.js.map