"use strict";exports.id=9179,exports.ids=[126,9179],exports.modules={60126:(a,b,c)=>{c.a(a,async(a,d)=>{try{c.d(b,{O:()=>l,createWorktree:()=>o,hasGhCli:()=>n,hasRemote:()=>m,isGitRepo:()=>k,listWorktrees:()=>s,mergeWorktree:()=>p,removeWorktree:()=>r});var e=c(7206),f=c(73024),g=c(76760),h=c.n(g),i=a([e]);e=(i.then?(await i)():i)[0];let w=h().join(".reflex","worktrees"),x=".reflex/worktrees/";async function j(a,b){let c=await (0,e.execa)("git",b,{cwd:a,timeout:3e4,reject:!1});return{stdout:"string"==typeof c.stdout?c.stdout:"",stderr:"string"==typeof c.stderr?c.stderr:"",code:"number"==typeof c.exitCode?c.exitCode:1}}async function k(a){let b=await j(a,["rev-parse","--is-inside-work-tree"]);return 0===b.code&&"true"===b.stdout.trim()}async function l(a){let b=await j(a,["symbolic-ref","--short","refs/remotes/origin/HEAD"]);return 0===b.code&&b.stdout.trim()?b.stdout.trim().replace(/^origin\//,""):(await j(a,["rev-parse","--abbrev-ref","HEAD"])).stdout.trim()||"main"}async function m(a){let b=await j(a,["remote"]);return 0===b.code&&b.stdout.trim().length>0}async function n(){let a=await (0,e.execa)("gh",["--version"],{timeout:5e3,reject:!1});return"number"==typeof a.exitCode&&0===a.exitCode}async function o(a){if(!await k(a.rootPath))throw Error("createWorktree: project root is not a git repo");let b=h().join(a.rootPath,w,a.slug),c=a.baseRef??await l(a.rootPath);try{throw await f.promises.stat(b),Error(`createWorktree: ${b} already exists`)}catch(a){if("ENOENT"!==a.code)throw a}let d=await j(a.rootPath,["rev-parse","--verify",`refs/heads/${a.branch}`]);if(0===d.code)throw Error(`createWorktree: branch ${a.branch} already exists; remove it first`);await f.promises.mkdir(h().dirname(b),{recursive:!0});let e=await j(a.rootPath,["worktree","add","-b",a.branch,b,c]);if(0!==e.code)throw Error(`git worktree add failed (${e.code}): ${e.stderr.trim()||e.stdout.trim()}`);return await u(a.rootPath,b),await v(a.rootPath),{dir:b,branch:a.branch,baseRef:c}}async function p(a){let b=a.intoRef??await l(a.rootPath),c=(await j(a.rootPath,["rev-parse","--abbrev-ref","HEAD"])).stdout.trim(),d=await j(a.rootPath,["checkout",b]);if(0!==d.code)return{ok:!1,conflicts:[],error:`checkout ${b} failed: ${d.stderr.trim()}`};let e=!1===a.noFf?[]:["--no-ff"],f=await j(a.rootPath,["merge",...e,a.branch]);if(0!==f.code){let b=await q(a.rootPath);return{ok:!1,conflicts:b,error:f.stderr.trim()||f.stdout.trim()||"merge failed"}}return c&&c!==b&&await j(a.rootPath,["checkout",c]),{ok:!0,mergedInto:b}}async function q(a){let b=await j(a,["diff","--name-only","--diff-filter=U"]);return 0!==b.code?[]:b.stdout.split("\n").map(a=>a.trim()).filter(Boolean)}async function r(a){let b=h().join(a.rootPath,w,a.slug),c=a.force?["--force"]:[],d=await j(a.rootPath,["worktree","remove",...c,b]);if(0!==d.code)try{return await f.promises.stat(b),{ok:!1,error:d.stderr.trim()||d.stdout.trim()||"worktree remove failed"}}catch{}if(a.deleteBranch??!0){let b=a.force?"-D":"-d";await j(a.rootPath,["branch",b,a.branch])}return await j(a.rootPath,["worktree","prune"]),{ok:!0}}async function s(a){let b=await j(a,["worktree","list","--porcelain"]);if(0!==b.code)return[];let c=[],d=null;for(let e of b.stdout.split("\n")){let b=e.trimEnd();if(!b){d?.dir&&c.push(t(d,a)),d=null;continue}b.startsWith("worktree ")?(d?.dir&&c.push(t(d,a)),d={dir:b.slice(9)}):d&&(b.startsWith("HEAD ")?d.head=b.slice(5):b.startsWith("branch refs/heads/")?d.branch=b.slice(18):"detached"===b?d.detached=!0:"bare"===b&&(d.bare=!0))}return d?.dir&&c.push(t(d,a)),c}function t(a,b){return{dir:a.dir,...a.branch?{branch:a.branch}:{},head:a.head??"",detached:!!a.detached,bare:!!a.bare,isMain:h().resolve(a.dir)===h().resolve(b)}}async function u(a,b){let c=h().join(a,".reflex","memory");await f.promises.mkdir(h().dirname(c),{recursive:!0}),await f.promises.mkdir(h().join(b,".reflex"),{recursive:!0});let d=h().join(b,".reflex","memory");try{if((await f.promises.lstat(d)).isSymbolicLink()&&await f.promises.readlink(d)===c)return;await f.promises.rm(d,{recursive:!0,force:!0})}catch(a){if("ENOENT"!==a.code)throw a}await f.promises.symlink(c,d,"dir")}async function v(a){let b=h().join(a,".reflexignore"),c="";try{c=await f.promises.readFile(b,"utf8")}catch{}if(c.split("\n").map(a=>a.trim()).filter(Boolean).includes(x))return;let d=c?`${c.replace(/\n*$/,"")}
${x}
`:`${x}
`;await f.promises.writeFile(b,d,"utf8")}d()}catch(a){d(a)}})},99179:(a,b,c)=>{c.a(a,async(a,d)=>{try{c.d(b,{dispatchTask:()=>n});var e=c(53905),f=c(36017),g=c(5492),h=c(51021),i=c(55143),j=c(26380),k=c(60126),l=c(51872),m=a([h,i,k]);async function n(a){let b=await (0,e.getRoot)(a.rootId);if(!b)return{ok:!1,error:"root not found"};let c=await (0,j.getTask)(b.path,a.taskId);if(!c)return{ok:!1,error:"task not found"};if("in-progress"===c.status)return{ok:!1,error:"task already dispatched (topic "+c.topicId+")"};let d=l.Yj[c.type],i=await (0,f.loadSettings)(),m=i.assignments.chat,n=a.harness??c.agentRequested??m.harness,p=a.model??m.model,q=c.worktree;if(d.isCode&&!q&&await (0,k.isGitRepo)(b.path))try{let a=`task/${c.title.normalize("NFKD").toLowerCase().replace(/[^a-z0-9-/]+/g,"-").replace(/^-+|-+$/g,"").slice(0,60)||c.id}`,d=await (0,k.O)(b.path);q=await (0,k.createWorktree)({rootPath:b.path,slug:c.id,branch:a,baseRef:d})}catch(a){return{ok:!1,error:"worktree create failed: "+(a instanceof Error?a.message:String(a))}}let r=[];for(let b of c.pre){let c=await o(a.rootId,b);c&&r.push(c)}let s=d.defaultSkill?`/skill ${d.defaultSkill}

`:"",t=[`${s}You are now working on task ${c.id}: "${c.title}".`,"","## Task description",c.body||"(no description)"];r.length>0&&t.push("","## Pre-task context (from hooks)",...r),q&&t.push("","## Working directory",`You are inside a git worktree at \`${q.dir}\` on branch \`${q.branch}\`. Commit changes here; main branch is untouched until the user clicks Merge.`),t.push("",'When done, mark the task as `done` via `<<reflex:task-update>>{"id":"'+c.id+'","status":"done"}<</reflex:task-update>>`.');let u=t.join("\n"),v=q?.dir??b.path,w=await (0,g.createTopic)({root:v,firstMessage:c.title,harness:n,model:p,language:i.language,taskId:c.id}),x=await (0,h.startOrchestratorTurn)({rootId:a.rootId,topicId:w.meta.id,message:u,attachments:[]});return"error"in x?{ok:!1,error:x.error}:(await (0,j.updateTask)(b.path,c.id,{topicId:w.meta.id,agentRequested:n,worktree:q,status:"in-progress"}),{ok:!0,taskId:c.id,topicId:w.meta.id,...q?{worktree:{dir:q.dir,branch:q.branch}}:{}})}async function o(a,b){if("chat"===b.kind)return b.prompt??null;if("workflow"===b.kind&&b.id)try{let c=await (0,i.runWorkflow)(a,b.id);if(!c.ok)return null;let d=[];for(let a of c.run.steps){let b=a.output;null!=b&&d.push("string"==typeof b?b:JSON.stringify(b,null,2))}let e=d.join("\n\n").trim();return e?`### workflow:${b.id}
${e}`:null}catch{}return null}[h,i,k]=m.then?(await m)():m,d()}catch(a){d(a)}})}};