module.exports=[53974,a=>{"use strict";var b=a.i(66680),c=a.i(80026);function d(a){return(0,c.getDb)().prepare("SELECT * FROM questions WHERE id = ?").get(a)??null}a.s(["answerQuestion",0,function(a){let b=(0,c.getDb)(),e=new Date().toISOString();return 0===b.prepare(`UPDATE questions
          SET status = 'answered',
              answer_option_index = ?,
              answer_text = ?,
              resolved_by_kind = 'user',
              resolved_at = ?
        WHERE id = ? AND status = 'pending'`).run(a.answer_option_index??null,a.answer_text??null,e,a.id).changes?null:d(a.id)},"cancelQuestion",0,function(a){let b=(0,c.getDb)(),e=new Date().toISOString();return 0===b.prepare(`UPDATE questions
          SET status = 'cancelled',
              resolved_by_kind = 'user',
              resolved_at = ?
        WHERE id = ? AND status = 'pending'`).run(e,a).changes?null:d(a)},"createQuestion",0,function(a){let e=(0,c.getDb)(),f=(0,b.randomUUID)(),g=new Date().toISOString();return e.prepare(`INSERT INTO questions
       (id, project_slug, agent_id, task_id, prompt, options_json,
        status, answer_option_index, answer_text, resolved_by_kind,
        created_at, resolved_at)
     VALUES (?, ?, ?, ?, ?, ?, 'pending', NULL, NULL, NULL, ?, NULL)`).run(f,a.project_slug,a.agent_id,a.task_id??null,a.prompt,JSON.stringify(a.options??[]),g),d(f)},"getQuestion",0,d,"listQuestionsForTask",0,function(a){return(0,c.getDb)().prepare(`SELECT * FROM questions
        WHERE task_id = ?
        ORDER BY created_at DESC, rowid DESC`).all(a)},"parseQuestionOptions",0,function(a){try{let b=JSON.parse(a.options_json);if(Array.isArray(b)&&b.every(a=>"string"==typeof a))return b}catch{}return[]}])},65454,a=>{"use strict";var b=a.i(22486),c=a.i(48836),d=a.i(12714);a.i(2157);var e=a.i(60526),f=a.i(50227),g=a.i(66680);function h(a,b){return(0,f.join)(process.env.NOTFAIR_CMO_DATA_DIR??(0,f.join)((0,e.homedir)(),".notfair-cmo"),"agents",a,"shadow",`${b}.jsonl`)}async function i(a,b){await (0,d.mkdir)((0,f.dirname)(h(a,b)),{recursive:!0})}async function j(a,b){await i(a,b);let c=h(a,b),e="";async function f(a){await (0,d.appendFile)(c,`${JSON.stringify(a)}
`,"utf8")}async function j(){let a=e.trim();e="",a&&await f({type:"message",id:`shadow-${(0,g.randomUUID)()}`,timestamp:new Date().toISOString(),message:{role:"assistant",content:[{type:"text",text:a}]}})}return{appendDelta(a){e+=a},replaceAssistant(a){e=a},flushAssistant:j,async toolStart(a,b,c){await j(),await f({type:"message",id:`shadow-${(0,g.randomUUID)()}`,timestamp:new Date().toISOString(),message:{role:"assistant",content:[{type:"toolCall",id:a,name:b,...c?{arguments:{__label:c}}:{}}]}})},async toolResult(a,b,c,d){await f({type:"message",id:`shadow-${(0,g.randomUUID)()}`,timestamp:new Date().toISOString(),message:{role:"toolResult",toolCallId:a,toolName:b,isError:!c,content:d?[{type:"text",text:d}]:void 0}})},async close(){await j()}}}async function k(a,b){switch(b.kind){case"delta":a.appendDelta(b.text);return;case"final":a.replaceAssistant(b.text),await a.flushAssistant();return;case"tool":"start"===b.phase?await a.toolStart(b.toolCallId,b.name,b.label):"result"===b.phase&&await a.toolResult(b.toolCallId,b.name,!0,b.label);return;case"lifecycle":case"error":return}}var l=a.i(19078),m=a.i(26341);async function n(a){let d=a;if(!d.thread_id){let b=(0,l.setTaskThreadIfMissing)(a.id,(0,m.generateTaskThreadId)());if(b&&(d=b),!d.thread_id)throw Error(`Failed to assign thread_id for task ${a.id}`)}let e=(0,b.buildPendingSessionKey)(d.agent_id,d.thread_id),f=(0,m.buildTaskKickoffMessage)(d),g=await j(d.agent_id,d.thread_id);console.log(`[run-task] kickoff start task=${d.id} agent=${d.agent_id} thread=${d.thread_id}`);let h=[2e3,4e3,8e3],i=null,n=!1;for(let a=0;a<=h.length;a+=1)try{for await(let a of(0,c.streamChatViaGateway)({sessionKey:e,sessionId:d.thread_id,message:f})){try{await k(g,a)}catch(a){console.error("[run-task] shadow write failed:",a)}if("error"===a.kind)throw Error(a.message)}n=!0;break}catch(c){if(i=c,!(c instanceof Error?c.message:String(c)).includes("no longer exists in configuration")||a>=h.length)break;let b=h[a];console.warn(`[run-task] gateway snapshot stale for ${d.agent_id}; retrying in ${b}ms (attempt ${a+1}/${h.length})`),await new Promise(a=>setTimeout(a,b))}if(n){await g.close(),console.log(`[run-task] kickoff stream done task=${d.id}`);return}await g.close().catch(()=>void 0);let o=i instanceof Error?i.message:String(i);console.error(`[run-task] kickoff failed task=${d.id} agent=${d.agent_id}: ${o}`),(0,l.updateTask)(d.id,{status:"failed",error_message:o})}a.s(["runTaskKickoffServerSide",0,n,"startTaskIfProposed",0,function(a){let b=(0,l.claimProposedTask)(a.id);return b?(n(b).catch(a=>{console.error("[start-task] kickoff failed:",a)}),b):a}],65454)},26341,a=>{"use strict";var b=a.i(66680);a.s(["buildTaskKickoffMessage",0,function(a){let b=["(task assignment)","",`project_slug: ${a.project_slug}`,`agent_id:     ${a.agent_id}`,`task_id:      ${a.id}`,`Title:        ${a.title??"(untitled)"}`,"","Brief:",a.brief,""];return a.success_criteria&&b.push("Success criteria:",a.success_criteria,""),b.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."),b.join("\n")},"generateTaskThreadId",0,function(){return(0,b.randomUUID)()}])},74799,a=>{"use strict";var b=a.i(22486),c=a.i(48836),d=a.i(81181),e=a.i(19078),f=a.i(26341);async function g(a){if(!a.task_id)return;let g=(0,e.getTask)(a.task_id);if(!g||"done"===g.status||"failed"===g.status||"cancelled"===g.status)return;("approved"===a.status||"rejected"===a.status)&&(0,e.unblockTask)(g.id);let h=g.thread_id;if(!h){let a=(0,e.setTaskThreadIfMissing)(g.id,(0,f.generateTaskThreadId)());a?.thread_id&&(h=a.thread_id)}if(!h)return void console.error(`[approval-wakeup] no thread_id for task ${g.id}`);let i=(0,b.findSessionBySessionId)(g.agent_id,h),j=i?.sessionKey??(0,b.buildPendingSessionKey)(g.agent_id,h),k=function(a){let b="user"===a.decided_by_kind?"the user":"agent"===a.decided_by_kind?`another agent (${a.decided_by_id??"unknown"})`:"policy"===a.decided_by_kind?"an auto-approval policy":"an unknown party",c=a.decision_note?.trim();switch(a.status){case"approved":return[`[SYSTEM] Approval #${a.id.slice(0,8)} has been APPROVED by ${b}.`,`Action: ${a.action_summary}`,c?`Note: ${c}`:null,"","You may now proceed with the action. When you're finished, call the `submit_task_status` MCP tool with status `done` (or `working` if you're posting an interim update). Do NOT invent new status values."].filter(Boolean).join("\n");case"rejected":return[`[SYSTEM] Approval #${a.id.slice(0,8)} has been REJECTED by ${b}.`,`Action: ${a.action_summary}`,c?`Reason: ${c}`:null,"","Do NOT perform the rejected action. Decide whether to propose an alternative or stop here. Either way, call the `submit_task_status` MCP tool — use status `done` if you have nothing further to do, or `working` if you're proposing an alternative. The valid statuses are exactly: working, done, blocked, failed."].filter(Boolean).join("\n");case"revision_requested":return[`[SYSTEM] Approval #${a.id.slice(0,8)} needs revision per ${b}.`,`Action: ${a.action_summary}`,c?`Feedback: ${c}`:"Feedback: (no note left — re-read the request and propose a refined version)","","Re-evaluate the request given the feedback, then call the notfair-orchestration `request_approval` MCP tool again with the revised plan. Keep status `working` via `submit_task_status` in the meantime. Do NOT emit pseudo-XML blocks."].filter(Boolean).join("\n");default:return`[SYSTEM] Approval #${a.id.slice(0,8)} resolved (${a.status}). Continue.`}}(a);(0,d.appendComment)({approval_id:a.id,author_kind:"system",body:`Delivered to ${g.agent_id} on thread ${h}.`});try{for await(let a of(0,c.streamChatViaGateway)({sessionKey:j,sessionId:h,message:k}))if("error"===a.kind)throw Error(a.message)}catch(a){console.error(`[approval-wakeup] gateway stream failed for task ${g.id}:`,a)}}a.s(["wakeTaskOnApprovalResolution",0,g])},28561,a=>{"use strict";var b=a.i(75211),c=a.i(15069),d=a.i(81181),e=a.i(74799);async function f(a,b,g={}){let h=(0,d.getApproval)(a);if(!h)return{ok:!1,error:"Approval not found."};if("pending"!==h.status&&"revision_requested"!==h.status)return{ok:!1,error:`Approval is already ${h.status}.`};let i=(0,d.resolveApproval)(a,b,{decision_note:g.decision_note??null,decided_by_kind:"user",decided_by_id:g.decided_by_id??null});return i?((0,d.appendComment)({approval_id:a,author_kind:"user",author_id:g.decided_by_id??null,body:g.decision_note?.trim()||("approved"===b?"Approved.":"Rejected.")}),(0,e.wakeTaskOnApprovalResolution)(i).catch(a=>{console.error("[approve-action] wake-up failed:",a)}),(0,c.revalidatePath)("/","layout"),{ok:!0}):{ok:!1,error:"Approval row vanished."}}async function g(a,b){return f(a,"approved",{decision_note:b})}async function h(a,b){return f(a,"rejected",{decision_note:b})}async function i(a,b){if(!b.trim())return{ok:!1,error:"A note is required when requesting revision."};let f=(0,d.getApproval)(a);if(!f)return{ok:!1,error:"Approval not found."};if("pending"!==f.status)return{ok:!1,error:`Can only request revision on a pending approval (got ${f.status}).`};let g=(0,d.requestApprovalRevision)(a,{decision_note:b,decided_by_kind:"user"});return g?((0,d.appendComment)({approval_id:a,author_kind:"user",body:b}),(0,e.wakeTaskOnApprovalResolution)(g).catch(a=>{console.error("[request-revision-action] wake-up failed:",a)}),(0,c.revalidatePath)("/","layout"),{ok:!0}):{ok:!1,error:"Revision request failed."}}async function j(a,b){let e=b.trim();return e?(0,d.getApproval)(a)?((0,d.appendComment)({approval_id:a,author_kind:"user",body:e}),(0,c.revalidatePath)("/","layout"),{ok:!0}):{ok:!1,error:"Approval not found."}:{ok:!1,error:"Comment cannot be empty."}}async function k(a){if(!a.project_slug||!a.action_type)return{ok:!1,error:"project_slug and action_type are required."};let b=(0,d.createPolicy)({project_slug:a.project_slug,action_type:a.action_type,agent_id:a.agent_id??null,max_cost_usd:a.max_cost_usd??null,auto_decision:a.auto_decision,note:a.note??null,created_by_kind:"user"});return(0,c.revalidatePath)("/","layout"),{ok:!0,policy_id:b.id}}async function l(a){return(0,d.deletePolicy)(a)?((0,c.revalidatePath)("/","layout"),{ok:!0}):{ok:!1,error:"Policy not found."}}(0,a.i(57648).ensureServerEntryExports)([g,h,i,j,k,l]),(0,b.registerServerReference)(g,"60cc1c7430629ef7d5c95c15232f7f9b794ffb64ca",null),(0,b.registerServerReference)(h,"60523ddab47a89e7970fef18c0036305557d267c0e",null),(0,b.registerServerReference)(i,"600c005ae7cd76bc9cbbc5778e521f6535e0bd0567",null),(0,b.registerServerReference)(j,"608c109b94c0d3490a6a77e2fad4d96bb9228325df",null),(0,b.registerServerReference)(k,"40c5a09bc914bf068156ea2f4f8883e7e0f7cf8b1c",null),(0,b.registerServerReference)(l,"407eb6dd875657acca4dea2665aa4d82ce0f9f1926",null),a.s(["approveAction",0,g,"createPolicyAction",0,k,"deletePolicyAction",0,l,"rejectAction",0,h])},44792,a=>{"use strict";var b=a.i(56963),c=a.i(31806),d=a.i(28561),e=a.i(75211),f=a.i(15069),g=a.i(53974),h=a.i(22486),i=a.i(48836),j=a.i(19078),k=a.i(26341);async function l(a){var b;let c,d,e,f;if(!a.task_id||"cancelled"===a.status||"answered"!==a.status)return;let l=(0,j.getTask)(a.task_id);if(!l||"done"===l.status||"failed"===l.status||"cancelled"===l.status)return;(0,j.unblockTask)(l.id);let m=l.thread_id;if(!m){let a=(0,j.setTaskThreadIfMissing)(l.id,(0,k.generateTaskThreadId)());a?.thread_id&&(m=a.thread_id)}if(!m)return void console.error(`[question-wakeup] no thread_id for task ${l.id}`);let n=(0,h.findSessionBySessionId)(l.agent_id,m),o=n?.sessionKey??(0,h.buildPendingSessionKey)(l.agent_id,m),p=(b=a,d=(0,g.parseQuestionOptions)(b),e=null!=b.answer_option_index?d[b.answer_option_index]??null:null,f=b.answer_text?.trim()||null,c=e&&f?`Answer: ${e} — ${f}`:e?`Answer: ${e}`:f?`Answer: ${f}`:"Answer: (the user submitted an empty response — re-ask if needed)",[`[SYSTEM] The user answered question #${b.id.slice(0,8)}.`,`Question: ${b.prompt}`,c,"\nThe task has been unblocked. Continue your work using this answer. End your turn with `submit_task_status` (working / done / failed / blocked) when appropriate."].join("\n"));try{for await(let a of(0,i.streamChatViaGateway)({sessionKey:o,sessionId:m,message:p}))if("error"===a.kind)throw Error(a.message)}catch(a){console.error(`[question-wakeup] gateway stream failed for task ${l.id}:`,a)}}var m=a.i(57648);async function n(a,b){let c=(0,g.getQuestion)(a);if(!c)return{ok:!1,error:"Question not found."};if("pending"!==c.status)return{ok:!1,error:`Question is already ${c.status}.`};let d=b.text?.trim()||null,e=null;if(null!=b.option_index){let a=(0,g.parseQuestionOptions)(c);if(!Number.isInteger(b.option_index)||b.option_index<0||b.option_index>=a.length)return{ok:!1,error:"Selected option is out of range."};e=b.option_index}if(null==e&&!d)return{ok:!1,error:"Pick an option or type an answer."};let h=(0,g.answerQuestion)({id:a,answer_option_index:e,answer_text:d});return h?(l(h).catch(a=>{console.error("[answer-question-action] wake-up failed:",a)}),(0,f.revalidatePath)("/","layout"),{ok:!0}):{ok:!1,error:"Question row vanished."}}async function o(a){let b=(0,g.getQuestion)(a);return b?"pending"!==b.status?{ok:!1,error:`Question is already ${b.status}.`}:(0,g.cancelQuestion)(a)?((0,f.revalidatePath)("/","layout"),{ok:!0}):{ok:!1,error:"Question row vanished."}:{ok:!1,error:"Question not found."}}(0,m.ensureServerEntryExports)([n,o]),(0,e.registerServerReference)(n,"603893595c9e840f480fc97d80400848182091996e",null),(0,e.registerServerReference)(o,"406ac503d6f03e984da2e635f1700e28b981f690cc",null);var p=a.i(92555),q=a.i(65454);async function r(a){if(!a.trim())return{ok:!1,error:"agentId is required"};let b=await (0,p.getActiveProject)();if(!b)return{ok:!1,error:"No active project."};let c=(0,j.listTasksByAgent)(a,"proposed");if(0===c.length)return{ok:!0,data:{started:0,task_ids:[]}};let d=c.filter(a=>a.project_slug===b.slug);if(0===d.length)return{ok:!1,error:`Agent ${a} has no proposed tasks in the active project.`};let e=d.map(a=>(0,j.claimProposedTask)(a.id)).filter(a=>null!==a);for(let a of e)(0,q.runTaskKickoffServerSide)(a).catch(b=>console.error(`[start-all] kickoff failed for ${a.id}:`,b));return(0,f.revalidatePath)("/agents","layout"),(0,f.revalidatePath)("/tasks","layout"),{ok:!0,data:{started:e.length,task_ids:e.map(a=>a.id)}}}async function s(a){let b=await (0,p.getActiveProject)();if(!b)return{ok:!1,error:"No active project."};let c=(0,j.getTask)(a);return c?c.project_slug!==b.slug?{ok:!1,error:"Task isn't in the active project."}:"done"===c.status||"failed"===c.status||"cancelled"===c.status?{ok:!1,error:`Task is already ${c.status}.`}:((0,j.updateTask)(c.id,{status:"cancelled",error_message:"Cancelled by user"}),(0,f.revalidatePath)("/agents","layout"),(0,f.revalidatePath)("/tasks","layout"),{ok:!0}):{ok:!1,error:"Task not found."}}(0,m.ensureServerEntryExports)([r,s]),(0,e.registerServerReference)(r,"40f9891a7187d3dd893a06439b5a4ffb87f1065c93",null),(0,e.registerServerReference)(s,"408a3dbf91d3bb409de37e5dee627d17555b28c111",null),a.s([],44289),a.i(44289),a.s(["003b2f2b7aa811e2a0171d110c2fea96ef3c8752fd",()=>c.listProjectAgentsAction,"0080551f846a8a446405ef54005e5ee92cb1170cea",()=>c.listOpenClawAgentsAction,"4001f3d2265bf9517aef1249ed9fedb18f85bb0bb6",()=>c.createAgentAction,"406ac503d6f03e984da2e635f1700e28b981f690cc",0,o,"40874ac941afbf59ecef4f3ffd8d323bc44d8dc1bd",()=>c.disableCronsAction,"408a3dbf91d3bb409de37e5dee627d17555b28c111",0,s,"409960037ddbb851eb634b8fdbb6fe7cc9cb749ae9",()=>b.switchProjectAction,"40c5a09bc914bf068156ea2f4f8883e7e0f7cf8b1c",()=>d.createPolicyAction,"40f3f75ea52bd131779b5f0a148c4344e062e2c1b5",()=>c.cloneAgentAction,"40f9891a7187d3dd893a06439b5a4ffb87f1065c93",0,r,"603893595c9e840f480fc97d80400848182091996e",0,n,"60523ddab47a89e7970fef18c0036305557d267c0e",()=>d.rejectAction,"60cc1c7430629ef7d5c95c15232f7f9b794ffb64ca",()=>d.approveAction],44792)},54786,a=>{a.v(a=>Promise.resolve().then(()=>a(69482)))},30859,a=>{a.v(a=>Promise.resolve().then(()=>a(6105)))},64708,a=>{a.v(b=>Promise.all(["server/chunks/ssr/src_server_onboarding_cmo-task-brief_ts_0gatf~b._.js"].map(b=>a.l(b))).then(()=>b(77469)))},9043,a=>{a.v(a=>Promise.resolve().then(()=>a(19078)))},45689,a=>{a.v(a=>Promise.resolve().then(()=>a(65454)))}];

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