@mndrk/agx 1.4.35 → 1.4.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -139,6 +139,18 @@ agx run <task_id> # Run a specific task
139
139
  agx status # Show current status
140
140
  ```
141
141
 
142
+ ### Project Management
143
+
144
+ ```bash
145
+ agx project create --name "My Project" \
146
+ --slug my-project \
147
+ --description "Agent work" \
148
+ --ci "CI pipeline notes" \
149
+ --workflow 00000000-0000-0000-0000-000000000001 \
150
+ --metadata team=core \
151
+ --repo '{"name":"api","path":"/code/api"}'
152
+ ```
153
+
142
154
  ### Board Server
143
155
 
144
156
  ```bash
@@ -3,4 +3,4 @@ exports.id=9773,exports.ids=[9773],exports.modules={5620:(a,b,c)=>{Promise.resol
3
3
  function gtag(){dataLayer.push(arguments);}
4
4
  gtag('js', new Date());
5
5
  gtag('config', 'G-DVQQG95LNL');
6
- `}})]})}c(82704);let h={title:"AGX Board - Agent Task Orchestration",description:"Orchestrate and manage AI agent tasks on AGX Board"};function i({children:a}){return(0,d.jsxs)("html",{lang:"en",className:"dark",children:[(0,d.jsx)("head",{children:(0,d.jsx)(g,{})}),(0,d.jsxs)("body",{className:"antialiased min-h-screen bg-[var(--background)] text-[var(--foreground)] selection:bg-[var(--primary)] selection:text-[var(--primary-foreground)]",children:[(0,d.jsx)("div",{className:"fixed inset-0 -z-10 h-full w-full bg-[radial-gradient(#27272a_1px,transparent_1px)] [background-size:16px_16px] opacity-20"}),(0,d.jsx)(e.AuthProvider,{children:a})]})]})}},20302:(a,b,c)=>{Promise.resolve().then(c.t.bind(c,81170,23)),Promise.resolve().then(c.t.bind(c,23597,23)),Promise.resolve().then(c.t.bind(c,36893,23)),Promise.resolve().then(c.t.bind(c,89748,23)),Promise.resolve().then(c.t.bind(c,6060,23)),Promise.resolve().then(c.t.bind(c,7184,23)),Promise.resolve().then(c.t.bind(c,69576,23)),Promise.resolve().then(c.t.bind(c,73041,23)),Promise.resolve().then(c.t.bind(c,51384,23))},29588:(a,b,c)=>{Promise.resolve().then(c.bind(c,43185)),Promise.resolve().then(c.t.bind(c,27532,23))},33409:(a,b,c)=>{"use strict";c.d(b,{O:()=>e});var d=c(39537);function e(){return{auth:{getSession:async()=>({data:{session:{access_token:"local-token",refresh_token:"local-refresh",expires_in:3600,user:{id:d.g.id,email:d.g.email,user_metadata:{name:d.g.name,full_name:d.g.name}}}},error:null}),signInWithOAuth:async()=>({error:Error("Auth disabled in AGX Board local mode")}),signOut:async()=>({error:null}),onAuthStateChange:()=>({data:{subscription:{unsubscribe(){}}}})},channel:()=>({on(){return this},subscribe(){return this}}),removeChannel(){}}}},36937:(a,b,c)=>{"use strict";c.d(b,{LU:()=>f,dF:()=>h,si:()=>e,zH:()=>g});var d=c(38301);function e(a={}){process.env.NEXT_PUBLIC_AGX_BOARD_DISABLE_AUTH;let[b,c]=(0,d.useState)([]),[f,g]=(0,d.useState)(!0),[h,i]=(0,d.useState)(null),[j,k]=(0,d.useState)(null),[l,m]=(0,d.useState)(null),n=(0,d.useCallback)(async()=>{try{let b=new URLSearchParams;a.project&&b.set("project",a.project),a.status&&b.set("status",a.status);let d=await fetch(`/api/tasks?${b.toString()}`);if(!d.ok)throw Error("Failed to fetch tasks");let e=await d.json();c(e.tasks||[]),i(null)}catch(a){i(a instanceof Error?a:Error("Unknown error"))}finally{g(!1)}},[a.project,a.status]),o=(0,d.useCallback)(async(a,b)=>{let d=await fetch("/api/tasks",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:a,swarm_models:b})});if(!d.ok)throw Error((await d.json()).error||"Failed to create task");let{task:e}=await d.json();return c(a=>a.some(a=>a.id===e.id)?a:[e,...a]),e},[a.realtime]),p=(0,d.useCallback)(async(a,b)=>{let d=await fetch(`/api/tasks/${a}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(b)});if(!d.ok){let a=null;throw"function"==typeof d.json&&(a=await d.json().catch(()=>null)),Error(a?.error||a?.details||`Failed to update task (${d.status} ${d.statusText||"Error"})`)}let{task:e}=await d.json();return c(b=>b.map(b=>b.id===a?{...b,...e}:b)),e},[a.realtime]),q=(0,d.useCallback)(async a=>{if(!(await fetch(`/api/tasks/${a}`,{method:"DELETE"})).ok)throw Error("Failed to delete task");c(b=>b.filter(b=>b.id!==a))},[a.realtime]),r=(0,d.useCallback)(async a=>{let b=await fetch("/api/queue/complete",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)});if(!b.ok)throw Error((await b.json().catch(()=>({}))).error||"Failed to complete task stage");let{task:d}=await b.json();return c(b=>b.map(b=>b.id===a.taskId?{...b,...d}:b)),d},[a.realtime]);return{tasks:b,isLoading:f,error:h,cancellingTaskId:j,isCancelling:!!j,cancelError:l,refetch:n,createTask:o,updateTask:p,deleteTask:q,completeTaskStage:r,cancelWorkflow:(0,d.useCallback)(async a=>{k(a.taskId),m(null);try{let b=await fetch(`/api/orchestrator/tasks/${a.taskId}/cancel`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(a.reason?{reason:a.reason}:{})});if(!b.ok){let a=await b.json().catch(()=>({})),c=a?.error||"Failed to cancel workflow";throw Error(c)}return b.json()}catch(b){let a=b instanceof Error?b:Error("Failed to cancel workflow");throw m(a),a}finally{k(null)}},[]),fetchTask:(0,d.useCallback)(async a=>{let b=await fetch(`/api/tasks/${a}`),c=await b.json().catch(()=>null);if(!b.ok)throw Error(c?.error||"Failed to fetch task details");return c?.task},[])}}function f(a){process.env.NEXT_PUBLIC_AGX_BOARD_DISABLE_AUTH;let[b,c]=(0,d.useState)([]),[e,f]=(0,d.useState)(!1),g=(0,d.useCallback)(async()=>{if(a){f(!0);try{let b=await fetch(`/api/tasks/${a}/comments`);if(b.ok){let a=await b.json();c(a.comments||[])}}finally{f(!1)}}},[a]);return{comments:b,isLoading:e,refetch:g,addComment:(0,d.useCallback)(async b=>{if(!a)return;let c=await fetch(`/api/tasks/${a}/comments`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:b})});if(c.ok){let{comment:a}=await c.json();return a}},[a]),deleteComment:(0,d.useCallback)(async b=>{a&&(await fetch(`/api/tasks/${a}/comments/${b}`,{method:"DELETE"})).ok&&c(a=>a.filter(a=>a.id!==b))},[a])}}function g(a,b={}){let c=b.enabled??!0,e=Number.isFinite(b.tail)&&b.tail>0?b.tail:500,f=Number.isFinite(b.maxChars)&&b.maxChars>0?b.maxChars:2e5,[h,i]=(0,d.useState)(""),[j,k]=(0,d.useState)(!1),[l,m]=(0,d.useState)(!1),n=(0,d.useRef)(null);(0,d.useRef)(0);let o=(0,d.useRef)(null),p=(0,d.useCallback)(a=>{let b=(a.log_type||"output").toLowerCase();return"output"===b?a.content||"":`[${b}] ${a.content||""}`},[]);return(0,d.useCallback)(async(b=!1)=>{if(a&&c){b||k(!0);try{let c=new URLSearchParams;if(b){let a=o.current;a?.created_at&&c.set("after",a.created_at),c.set("limit","500")}else c.set("tail",String(e));let d=await fetch(`/api/tasks/${a}/logs?${c.toString()}`);if(d.ok){let a=((await d.json()).logs||[]).slice().sort((a,b)=>a.created_at===b.created_at?a.id.localeCompare(b.id):a.created_at.localeCompare(b.created_at));if(b){let b=o.current,c=b?a.filter(a=>a.created_at>b.created_at||!(a.created_at<b.created_at)&&a.id>b.id):a;if(c.length){let a=c.map(a=>p(a)).join("");a&&i(b=>{let c=b+a;return c.length>f?c.slice(-f):c}),m(!0),n.current&&clearTimeout(n.current),n.current=setTimeout(()=>{m(!1)},5e3)}}else{let b=a.map(a=>p(a)).join("");i(b.length>f?b.slice(-f):b)}if(a.length){let b=a[a.length-1];o.current={created_at:b.created_at,id:b.id}}}}finally{b||k(!1)}}},[c,p,f,e,a]),{output:h,isLoading:j,isStreaming:l}}function h(a,b){let[c,e]=(0,d.useState)([]),[f,g]=(0,d.useState)(!1),h=(0,d.useCallback)(async()=>{g(!0);try{let c=new URLSearchParams;a&&c.set("scope",a),b&&c.set("scopeId",b);let d=await fetch(`/api/learnings?${c.toString()}`);if(d.ok){let a=await d.json();e(a.learnings||[])}}finally{g(!1)}},[a,b]);return{learnings:c,isLoading:f,refetch:h,addLearning:(0,d.useCallback)(async(a,b,c)=>{let d=await fetch("/api/learnings",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({scope:b,scopeId:c,content:a})});if(d.ok){let{learning:a}=await d.json();return e(b=>[a,...b]),a}},[]),deleteLearning:(0,d.useCallback)(async a=>{(await fetch(`/api/learnings?id=${a}`,{method:"DELETE"})).ok&&e(b=>b.filter(b=>b.id!==a))},[])}}c(33409)},39537:(a,b,c)=>{"use strict";c.d(b,{g:()=>d}),"1"===process.env.AGX_BOARD_DISABLE_AUTH||"1"===process.env.NEXT_PUBLIC_AGX_BOARD_DISABLE_AUTH||"1"!==process.env.AGX_BOARD_ENABLE_AUTH&&process.env.NEXT_PUBLIC_AGX_BOARD_ENABLE_AUTH;let d={id:"2c3cc1ca-956d-4b62-b295-4d2d3374103f",email:process.env.AGX_BOARD_USER_EMAIL||"local@agx.board",name:process.env.AGX_BOARD_USER_NAME||"Local Board User"}},43185:(a,b,c)=>{"use strict";c.d(b,{AuthProvider:()=>e});var d=c(97954);let e=(0,d.registerClientReference)(function(){throw Error("Attempted to call AuthProvider() from the server but AuthProvider is on the client. It's not possible to invoke a client function from the server, it can only be rendered as a Component or passed to props of a Client Component.")},"/Users/mendrika/Projects/Agents/agx-cloud/components/AuthProvider.tsx","AuthProvider");(0,d.registerClientReference)(function(){throw Error("Attempted to call useAuth() from the server but useAuth is on the client. It's not possible to invoke a client function from the server, it can only be rendered as a Component or passed to props of a Client Component.")},"/Users/mendrika/Projects/Agents/agx-cloud/components/AuthProvider.tsx","useAuth")},60054:(a,b,c)=>{Promise.resolve().then(c.t.bind(c,54160,23)),Promise.resolve().then(c.t.bind(c,31603,23)),Promise.resolve().then(c.t.bind(c,68495,23)),Promise.resolve().then(c.t.bind(c,75170,23)),Promise.resolve().then(c.t.bind(c,77526,23)),Promise.resolve().then(c.t.bind(c,78922,23)),Promise.resolve().then(c.t.bind(c,29234,23)),Promise.resolve().then(c.t.bind(c,12263,23)),Promise.resolve().then(c.bind(c,82146))},75747:(a,b,c)=>{"use strict";c.d(b,{A:()=>i,AuthProvider:()=>h});var d=c(21124),e=c(38301),f=c(33409);let g=(0,e.createContext)({user:null,loading:!0,signOut:async()=>{}});function h({children:a}){let b="1"===process.env.NEXT_PUBLIC_AGX_BOARD_DISABLE_AUTH,[c,h]=(0,e.useState)(null),[i,j]=(0,e.useState)(!0),k=async()=>{if(b)return;let a=(0,f.O)();await a.auth.signOut(),h(null)};return(0,d.jsx)(g.Provider,{value:{user:c,loading:i,signOut:k},children:a})}function i(){return(0,e.useContext)(g)}},82704:()=>{},82997:(a,b,c)=>{"use strict";c.d(b,{Y:()=>e});var d=c(38301);function e(){let[a,b]=(0,d.useState)([]),[c,e]=(0,d.useState)(!1),[f,g]=(0,d.useState)(null),h=(0,d.useCallback)(async()=>{e(!0);try{let a=await fetch("/api/projects");if(!a.ok)throw Error("Failed to fetch projects");let c=await a.json();b(c.projects??[]),g(null)}catch(a){g(a instanceof Error?a:Error("Unknown error"))}finally{e(!1)}},[]),i=(0,d.useCallback)(async a=>{let c=await fetch("/api/projects",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)});if(!c.ok)throw Error((await c.json().catch(()=>({}))).error||"Failed to create project");let d=(await c.json()).project;return b(a=>[d,...a]),d},[]);return{projects:a,isLoading:c,error:f,refetch:h,createProject:i,updateProject:(0,d.useCallback)(async(a,c)=>{let d=await fetch(`/api/projects/${a}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(c)});if(!d.ok)throw Error((await d.json().catch(()=>({}))).error||"Failed to update project");let e=(await d.json()).project;return b(b=>b.map(b=>b.id===a?e:b)),e},[]),deleteProject:(0,d.useCallback)(async a=>{let c=await fetch(`/api/projects/${a}`,{method:"DELETE"});if(!c.ok)throw Error((await c.json().catch(()=>({}))).error||"Failed to delete project");b(b=>b.filter(b=>b.id!==a))},[])}}}};
6
+ `}})]})}c(82704);let h={title:"AGX Board - Agent Task Orchestration",description:"Orchestrate and manage AI agent tasks on AGX Board"};function i({children:a}){return(0,d.jsxs)("html",{lang:"en",className:"dark",children:[(0,d.jsx)("head",{children:(0,d.jsx)(g,{})}),(0,d.jsxs)("body",{className:"antialiased min-h-screen bg-[var(--background)] text-[var(--foreground)] selection:bg-[var(--primary)] selection:text-[var(--primary-foreground)]",children:[(0,d.jsx)("div",{className:"fixed inset-0 -z-10 h-full w-full bg-[radial-gradient(#27272a_1px,transparent_1px)] [background-size:16px_16px] opacity-20"}),(0,d.jsx)(e.AuthProvider,{children:a})]})]})}},20302:(a,b,c)=>{Promise.resolve().then(c.t.bind(c,81170,23)),Promise.resolve().then(c.t.bind(c,23597,23)),Promise.resolve().then(c.t.bind(c,36893,23)),Promise.resolve().then(c.t.bind(c,89748,23)),Promise.resolve().then(c.t.bind(c,6060,23)),Promise.resolve().then(c.t.bind(c,7184,23)),Promise.resolve().then(c.t.bind(c,69576,23)),Promise.resolve().then(c.t.bind(c,73041,23)),Promise.resolve().then(c.t.bind(c,51384,23))},29588:(a,b,c)=>{Promise.resolve().then(c.bind(c,43185)),Promise.resolve().then(c.t.bind(c,27532,23))},33409:(a,b,c)=>{"use strict";c.d(b,{O:()=>e});var d=c(39537);function e(){return{auth:{getSession:async()=>({data:{session:{access_token:"local-token",refresh_token:"local-refresh",expires_in:3600,user:{id:d.g.id,email:d.g.email,user_metadata:{name:d.g.name,full_name:d.g.name}}}},error:null}),signInWithOAuth:async()=>({error:Error("Auth disabled in AGX Board local mode")}),signOut:async()=>({error:null}),onAuthStateChange:()=>({data:{subscription:{unsubscribe(){}}}})},channel:()=>({on(){return this},subscribe(){return this}}),removeChannel(){}}}},36937:(a,b,c)=>{"use strict";c.d(b,{LU:()=>f,dF:()=>h,si:()=>e,zH:()=>g});var d=c(38301);function e(a={}){process.env.NEXT_PUBLIC_AGX_BOARD_DISABLE_AUTH;let[b,c]=(0,d.useState)([]),[f,g]=(0,d.useState)(!0),[h,i]=(0,d.useState)(null),[j,k]=(0,d.useState)(null),[l,m]=(0,d.useState)(null),n=(0,d.useCallback)(async()=>{try{let b=new URLSearchParams;a.project&&b.set("project",a.project),a.status&&b.set("status",a.status);let d=await fetch(`/api/tasks?${b.toString()}`);if(!d.ok)throw Error("Failed to fetch tasks");let e=await d.json();c(e.tasks||[]),i(null)}catch(a){i(a instanceof Error?a:Error("Unknown error"))}finally{g(!1)}},[a.project,a.status]),o=(0,d.useCallback)(async(a,b)=>{let d=await fetch("/api/tasks",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:a,swarm_models:b})});if(!d.ok)throw Error((await d.json()).error||"Failed to create task");let{task:e}=await d.json();c(a=>a.some(a=>a.id===e.id)?a:[e,...a]);n().catch(a=>console.error("Failed to refresh tasks:",a));return e},[a.realtime,n]),p=(0,d.useCallback)(async(a,b)=>{let d=await fetch(`/api/tasks/${a}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(b)});if(!d.ok){let a=null;throw"function"==typeof d.json&&(a=await d.json().catch(()=>null)),Error(a?.error||a?.details||`Failed to update task (${d.status} ${d.statusText||"Error"})`)}let{task:e}=await d.json();c(b=>b.map(b=>b.id===a?{...b,...e}:b));n().catch(a=>console.error("Failed to refresh tasks:",a));return e},[a.realtime,n]),q=(0,d.useCallback)(async a=>{if(!(await fetch(`/api/tasks/${a}`,{method:"DELETE"})).ok)throw Error("Failed to delete task");c(b=>b.filter(b=>b.id!==a));n().catch(a=>console.error("Failed to refresh tasks:",a))},[a.realtime,n]),r=(0,d.useCallback)(async a=>{let b=await fetch("/api/queue/complete",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)});if(!b.ok)throw Error((await b.json().catch(()=>({}))).error||"Failed to complete task stage");let{task:d}=await b.json();c(b=>b.map(b=>b.id===a.taskId?{...b,...d}:b));n().catch(a=>console.error("Failed to refresh tasks:",a));return d},[a.realtime,n]);return{tasks:b,isLoading:f,error:h,cancellingTaskId:j,isCancelling:!!j,cancelError:l,refetch:n,createTask:o,updateTask:p,deleteTask:q,completeTaskStage:r,cancelWorkflow:(0,d.useCallback)(async a=>{k(a.taskId),m(null);try{let b=await fetch(`/api/orchestrator/tasks/${a.taskId}/cancel`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(a.reason?{reason:a.reason}:{})});if(!b.ok){let a=await b.json().catch(()=>({})),c=a?.error||"Failed to cancel workflow";throw Error(c)}return b.json()}catch(b){let a=b instanceof Error?b:Error("Failed to cancel workflow");throw m(a),a}finally{k(null)}},[]),fetchTask:(0,d.useCallback)(async a=>{let b=await fetch(`/api/tasks/${a}`),c=await b.json().catch(()=>null);if(!b.ok)throw Error(c?.error||"Failed to fetch task details");return c?.task},[])}}function f(a){process.env.NEXT_PUBLIC_AGX_BOARD_DISABLE_AUTH;let[b,c]=(0,d.useState)([]),[e,f]=(0,d.useState)(!1),g=(0,d.useCallback)(async()=>{if(a){f(!0);try{let b=await fetch(`/api/tasks/${a}/comments`);if(b.ok){let a=await b.json();c(a.comments||[])}}finally{f(!1)}}},[a]);return{comments:b,isLoading:e,refetch:g,addComment:(0,d.useCallback)(async b=>{if(!a)return;let c=await fetch(`/api/tasks/${a}/comments`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:b})});if(c.ok){let{comment:a}=await c.json();return a}},[a]),deleteComment:(0,d.useCallback)(async b=>{a&&(await fetch(`/api/tasks/${a}/comments/${b}`,{method:"DELETE"})).ok&&c(a=>a.filter(a=>a.id!==b))},[a])}}function g(a,b={}){let c=b.enabled??!0,e=Number.isFinite(b.tail)&&b.tail>0?b.tail:500,f=Number.isFinite(b.maxChars)&&b.maxChars>0?b.maxChars:2e5,[h,i]=(0,d.useState)(""),[j,k]=(0,d.useState)(!1),[l,m]=(0,d.useState)(!1),n=(0,d.useRef)(null);(0,d.useRef)(0);let o=(0,d.useRef)(null),p=(0,d.useCallback)(a=>{let b=(a.log_type||"output").toLowerCase();return"output"===b?a.content||"":`[${b}] ${a.content||""}`},[]);return(0,d.useCallback)(async(b=!1)=>{if(a&&c){b||k(!0);try{let c=new URLSearchParams;if(b){let a=o.current;a?.created_at&&c.set("after",a.created_at),c.set("limit","500")}else c.set("tail",String(e));let d=await fetch(`/api/tasks/${a}/logs?${c.toString()}`);if(d.ok){let a=((await d.json()).logs||[]).slice().sort((a,b)=>a.created_at===b.created_at?a.id.localeCompare(b.id):a.created_at.localeCompare(b.created_at));if(b){let b=o.current,c=b?a.filter(a=>a.created_at>b.created_at||!(a.created_at<b.created_at)&&a.id>b.id):a;if(c.length){let a=c.map(a=>p(a)).join("");a&&i(b=>{let c=b+a;return c.length>f?c.slice(-f):c}),m(!0),n.current&&clearTimeout(n.current),n.current=setTimeout(()=>{m(!1)},5e3)}}else{let b=a.map(a=>p(a)).join("");i(b.length>f?b.slice(-f):b)}if(a.length){let b=a[a.length-1];o.current={created_at:b.created_at,id:b.id}}}}finally{b||k(!1)}}},[c,p,f,e,a]),{output:h,isLoading:j,isStreaming:l}}function h(a,b){let[c,e]=(0,d.useState)([]),[f,g]=(0,d.useState)(!1),h=(0,d.useCallback)(async()=>{g(!0);try{let c=new URLSearchParams;a&&c.set("scope",a),b&&c.set("scopeId",b);let d=await fetch(`/api/learnings?${c.toString()}`);if(d.ok){let a=await d.json();e(a.learnings||[])}}finally{g(!1)}},[a,b]);return{learnings:c,isLoading:f,refetch:h,addLearning:(0,d.useCallback)(async(a,b,c)=>{let d=await fetch("/api/learnings",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({scope:b,scopeId:c,content:a})});if(d.ok){let{learning:a}=await d.json();return e(b=>[a,...b]),a}},[]),deleteLearning:(0,d.useCallback)(async a=>{(await fetch(`/api/learnings?id=${a}`,{method:"DELETE"})).ok&&e(b=>b.filter(b=>b.id!==a))},[])}}c(33409)},39537:(a,b,c)=>{"use strict";c.d(b,{g:()=>d}),"1"===process.env.AGX_BOARD_DISABLE_AUTH||"1"===process.env.NEXT_PUBLIC_AGX_BOARD_DISABLE_AUTH||"1"!==process.env.AGX_BOARD_ENABLE_AUTH&&process.env.NEXT_PUBLIC_AGX_BOARD_ENABLE_AUTH;let d={id:"2c3cc1ca-956d-4b62-b295-4d2d3374103f",email:process.env.AGX_BOARD_USER_EMAIL||"local@agx.board",name:process.env.AGX_BOARD_USER_NAME||"Local Board User"}},43185:(a,b,c)=>{"use strict";c.d(b,{AuthProvider:()=>e});var d=c(97954);let e=(0,d.registerClientReference)(function(){throw Error("Attempted to call AuthProvider() from the server but AuthProvider is on the client. It's not possible to invoke a client function from the server, it can only be rendered as a Component or passed to props of a Client Component.")},"/Users/mendrika/Projects/Agents/agx-cloud/components/AuthProvider.tsx","AuthProvider");(0,d.registerClientReference)(function(){throw Error("Attempted to call useAuth() from the server but useAuth is on the client. It's not possible to invoke a client function from the server, it can only be rendered as a Component or passed to props of a Client Component.")},"/Users/mendrika/Projects/Agents/agx-cloud/components/AuthProvider.tsx","useAuth")},60054:(a,b,c)=>{Promise.resolve().then(c.t.bind(c,54160,23)),Promise.resolve().then(c.t.bind(c,31603,23)),Promise.resolve().then(c.t.bind(c,68495,23)),Promise.resolve().then(c.t.bind(c,75170,23)),Promise.resolve().then(c.t.bind(c,77526,23)),Promise.resolve().then(c.t.bind(c,78922,23)),Promise.resolve().then(c.t.bind(c,29234,23)),Promise.resolve().then(c.t.bind(c,12263,23)),Promise.resolve().then(c.bind(c,82146))},75747:(a,b,c)=>{"use strict";c.d(b,{A:()=>i,AuthProvider:()=>h});var d=c(21124),e=c(38301),f=c(33409);let g=(0,e.createContext)({user:null,loading:!0,signOut:async()=>{}});function h({children:a}){let b="1"===process.env.NEXT_PUBLIC_AGX_BOARD_DISABLE_AUTH,[c,h]=(0,e.useState)(null),[i,j]=(0,e.useState)(!0),k=async()=>{if(b)return;let a=(0,f.O)();await a.auth.signOut(),h(null)};return(0,d.jsx)(g.Provider,{value:{user:c,loading:i,signOut:k},children:a})}function i(){return(0,e.useContext)(g)}},82704:()=>{},82997:(a,b,c)=>{"use strict";c.d(b,{Y:()=>e});var d=c(38301);function e(){let[a,b]=(0,d.useState)([]),[c,e]=(0,d.useState)(!1),[f,g]=(0,d.useState)(null),h=(0,d.useCallback)(async()=>{e(!0);try{let a=await fetch("/api/projects");if(!a.ok)throw Error("Failed to fetch projects");let c=await a.json();b(c.projects??[]),g(null)}catch(a){g(a instanceof Error?a:Error("Unknown error"))}finally{e(!1)}},[]),i=(0,d.useCallback)(async a=>{let c=await fetch("/api/projects",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)});if(!c.ok)throw Error((await c.json().catch(()=>({}))).error||"Failed to create project");let d=(await c.json()).project;return b(a=>[d,...a]),d},[]);return{projects:a,isLoading:c,error:f,refetch:h,createProject:i,updateProject:(0,d.useCallback)(async(a,c)=>{let d=await fetch(`/api/projects/${a}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(c)});if(!d.ok)throw Error((await d.json().catch(()=>({}))).error||"Failed to update project");let e=(await d.json()).project;return b(b=>b.map(b=>b.id===a?e:b)),e},[]),deleteProject:(0,d.useCallback)(async a=>{let c=await fetch(`/api/projects/${a}`,{method:"DELETE"});if(!c.ok)throw Error((await c.json().catch(()=>({}))).error||"Failed to delete project");b(b=>b.filter(b=>b.id!==a))},[])}}}};
@@ -1 +1 @@
1
- "use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[9719],{91:(e,t,a)=>{a.d(t,{Y:()=>n});var r=a(2115);function n(){let[e,t]=(0,r.useState)([]),[a,n]=(0,r.useState)(!1),[o,l]=(0,r.useState)(null),s=(0,r.useCallback)(async()=>{n(!0);try{var e;let a=await fetch("/api/projects");if(!a.ok)throw Error("Failed to fetch projects");let r=await a.json();t(null!=(e=r.projects)?e:[]),l(null)}catch(e){l(e instanceof Error?e:Error("Unknown error"))}finally{n(!1)}},[]);(0,r.useEffect)(()=>{s()},[s]);let c=(0,r.useCallback)(async e=>{let a=await fetch("/api/projects",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!a.ok)throw Error((await a.json().catch(()=>({}))).error||"Failed to create project");let r=(await a.json()).project;return t(e=>[r,...e]),r},[]);return{projects:e,isLoading:a,error:o,refetch:s,createProject:c,updateProject:(0,r.useCallback)(async(e,a)=>{let r=await fetch("/api/projects/".concat(e),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)});if(!r.ok)throw Error((await r.json().catch(()=>({}))).error||"Failed to update project");let n=(await r.json()).project;return t(t=>t.map(t=>t.id===e?n:t)),n},[]),deleteProject:(0,r.useCallback)(async e=>{let a=await fetch("/api/projects/".concat(e),{method:"DELETE"});if(!a.ok)throw Error((await a.json().catch(()=>({}))).error||"Failed to delete project");t(t=>t.filter(t=>t.id!==e))},[])}}},577:(e,t,a)=>{a.d(t,{LU:()=>s,dF:()=>i,si:()=>l,zH:()=>c});var r=a(2115),n=a(1483),o=a(5704);function l(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t="1"===o.env.NEXT_PUBLIC_AGX_BOARD_DISABLE_AUTH,[a,l]=(0,r.useState)([]),[s,c]=(0,r.useState)(!0),[i,u]=(0,r.useState)(null),[d,f]=(0,r.useState)(null),[h,p]=(0,r.useState)(null),m=(0,r.useCallback)(async()=>{try{let t=new URLSearchParams;e.project&&t.set("project",e.project),e.status&&t.set("status",e.status);let a=await fetch("/api/tasks?".concat(t.toString()));if(!a.ok)throw Error("Failed to fetch tasks");let r=await a.json();l(r.tasks||[]),u(null)}catch(e){u(e instanceof Error?e:Error("Unknown error"))}finally{c(!1)}},[e.project,e.status]);(0,r.useEffect)(()=>{m()},[m]),(0,r.useEffect)(()=>{if(t||!e.realtime)return;let a=(0,n.O)(),r=a.channel("tasks-changes").on("postgres_changes",{event:"*",schema:"public",table:"tasks"},e=>{"INSERT"===e.eventType?l(t=>{let a=e.new;return t.some(e=>e.id===a.id)?t:[a,...t]}):"UPDATE"===e.eventType?l(t=>t.map(t=>t.id===e.new.id?e.new:t)):"DELETE"===e.eventType&&l(t=>t.filter(t=>t.id!==e.old.id))}).subscribe();return()=>{a.removeChannel(r)}},[e.realtime,t]);let k=(0,r.useCallback)(async(e,t)=>{let a=await fetch("/api/tasks",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:e,swarm_models:t})});if(!a.ok)throw Error((await a.json()).error||"Failed to create task");let{task:r}=await a.json();return l(e=>e.some(e=>e.id===r.id)?e:[r,...e]),r},[e.realtime]),w=(0,r.useCallback)(async(e,t)=>{let a=await fetch("/api/tasks/".concat(e),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!a.ok){let e=null;throw"function"==typeof a.json&&(e=await a.json().catch(()=>null)),Error((null==e?void 0:e.error)||(null==e?void 0:e.details)||"Failed to update task (".concat(a.status," ").concat(a.statusText||"Error",")"))}let{task:r}=await a.json();return l(t=>t.map(t=>t.id===e?{...t,...r}:t)),r},[e.realtime]),E=(0,r.useCallback)(async e=>{if(!(await fetch("/api/tasks/".concat(e),{method:"DELETE"})).ok)throw Error("Failed to delete task");l(t=>t.filter(t=>t.id!==e))},[e.realtime]),y=(0,r.useCallback)(async e=>{let t=await fetch("/api/queue/complete",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!t.ok)throw Error((await t.json().catch(()=>({}))).error||"Failed to complete task stage");let{task:a}=await t.json();return l(t=>t.map(t=>t.id===e.taskId?{...t,...a}:t)),a},[e.realtime]);return{tasks:a,isLoading:s,error:i,cancellingTaskId:d,isCancelling:!!d,cancelError:h,refetch:m,createTask:k,updateTask:w,deleteTask:E,completeTaskStage:y,cancelWorkflow:(0,r.useCallback)(async e=>{f(e.taskId),p(null);try{let t=await fetch("/api/orchestrator/tasks/".concat(e.taskId,"/cancel"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e.reason?{reason:e.reason}:{})});if(!t.ok){let e=await t.json().catch(()=>({})),a=(null==e?void 0:e.error)||"Failed to cancel workflow";throw Error(a)}return t.json()}catch(t){let e=t instanceof Error?t:Error("Failed to cancel workflow");throw p(e),e}finally{f(null)}},[]),fetchTask:(0,r.useCallback)(async e=>{let t=await fetch("/api/tasks/".concat(e)),a=await t.json().catch(()=>null);if(!t.ok)throw Error((null==a?void 0:a.error)||"Failed to fetch task details");return null==a?void 0:a.task},[])}}function s(e){let t="1"===o.env.NEXT_PUBLIC_AGX_BOARD_DISABLE_AUTH,[a,l]=(0,r.useState)([]),[s,c]=(0,r.useState)(!1),i=(0,r.useCallback)(async()=>{if(e){c(!0);try{let t=await fetch("/api/tasks/".concat(e,"/comments"));if(t.ok){let e=await t.json();l(e.comments||[])}}finally{c(!1)}}},[e]);return(0,r.useEffect)(()=>{i()},[i]),(0,r.useEffect)(()=>{if(t||!e)return;let a=(0,n.O)(),r=a.channel("task-comments-".concat(e)).on("postgres_changes",{event:"*",schema:"public",table:"task_comments",filter:"task_id=eq.".concat(e)},e=>{if("INSERT"===e.eventType){let t=e.new;(null==t?void 0:t.deleted_at)||l(e=>[...e,t])}else if("UPDATE"===e.eventType){let t=e.new;(null==t?void 0:t.deleted_at)?l(e=>e.filter(e=>e.id!==t.id)):l(e=>e.map(e=>e.id===t.id?t:e))}else"DELETE"===e.eventType&&l(t=>t.filter(t=>t.id!==e.old.id))}).subscribe();return()=>{a.removeChannel(r)}},[e,t]),{comments:a,isLoading:s,refetch:i,addComment:(0,r.useCallback)(async t=>{if(!e)return;let a=await fetch("/api/tasks/".concat(e,"/comments"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:t})});if(a.ok){let{comment:e}=await a.json();return e}},[e]),deleteComment:(0,r.useCallback)(async t=>{e&&(await fetch("/api/tasks/".concat(e,"/comments/").concat(t),{method:"DELETE"})).ok&&l(e=>e.filter(e=>e.id!==t))},[e])}}function c(e){var t;let a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=null==(t=a.enabled)||t,o=Number.isFinite(a.tail)&&a.tail>0?a.tail:500,l=Number.isFinite(a.maxChars)&&a.maxChars>0?a.maxChars:2e5,[s,c]=(0,r.useState)(""),[i,u]=(0,r.useState)(!1),[d,f]=(0,r.useState)(!1),h=(0,r.useRef)(null),p=(0,r.useRef)(0),m=(0,r.useRef)(null),k=(0,r.useCallback)(e=>{let t=(e.log_type||"output").toLowerCase();return"output"===t?e.content||"":"[".concat(t,"] ").concat(e.content||"")},[]),w=(0,r.useCallback)(async function(){let t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];if(e&&n){t||u(!0);try{let a=new URLSearchParams;if(t){let e=m.current;(null==e?void 0:e.created_at)&&a.set("after",e.created_at),a.set("limit","500")}else a.set("tail",String(o));let r=await fetch("/api/tasks/".concat(e,"/logs?").concat(a.toString()));if(r.ok){let e=((await r.json()).logs||[]).slice().sort((e,t)=>e.created_at===t.created_at?e.id.localeCompare(t.id):e.created_at.localeCompare(t.created_at));if(t){let t=m.current,a=t?e.filter(e=>e.created_at>t.created_at||!(e.created_at<t.created_at)&&e.id>t.id):e;if(a.length){let e=a.map(e=>k(e)).join("");e&&c(t=>{let a=t+e;return a.length>l?a.slice(-l):a}),f(!0),h.current&&clearTimeout(h.current),h.current=setTimeout(()=>{f(!1)},5e3)}}else{let t=e.map(e=>k(e)).join("");c(t.length>l?t.slice(-l):t)}if(e.length){let t=e[e.length-1];m.current={created_at:t.created_at,id:t.id}}}}finally{t||u(!1)}}},[n,k,l,o,e]);return(0,r.useEffect)(()=>{c(""),f(!1),u(!1),m.current=null,h.current&&(clearTimeout(h.current),h.current=null),n&&w()},[n,w,e]),(0,r.useEffect)(()=>{if(!e||!n)return;let t=new EventSource("/api/logs/stream?taskId=".concat(e)),a=()=>{let e=Date.now();e-p.current<5e3||(p.current=e,w(!0))};return t.onopen=()=>{a()},t.onmessage=e=>{try{let t=JSON.parse(e.data);if((null==t?void 0:t.type)!=="log"||!t.log)return;let a=t.log,r=k(a);if(!r)return;c(e=>e+r),f(!0),h.current&&clearTimeout(h.current),h.current=setTimeout(()=>{f(!1)},5e3)}catch(e){}},t.onerror=()=>{a()},()=>{t.close(),h.current&&(clearTimeout(h.current),h.current=null)}},[n,w,k,e]),{output:s,isLoading:i,isStreaming:d}}function i(e,t){let[a,n]=(0,r.useState)([]),[o,l]=(0,r.useState)(!1),s=(0,r.useCallback)(async()=>{l(!0);try{let a=new URLSearchParams;e&&a.set("scope",e),t&&a.set("scopeId",t);let r=await fetch("/api/learnings?".concat(a.toString()));if(r.ok){let e=await r.json();n(e.learnings||[])}}finally{l(!1)}},[e,t]);return(0,r.useEffect)(()=>{s()},[s]),{learnings:a,isLoading:o,refetch:s,addLearning:(0,r.useCallback)(async(e,t,a)=>{let r=await fetch("/api/learnings",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({scope:t,scopeId:a,content:e})});if(r.ok){let{learning:e}=await r.json();return n(t=>[e,...t]),e}},[]),deleteLearning:(0,r.useCallback)(async e=>{(await fetch("/api/learnings?id=".concat(e),{method:"DELETE"})).ok&&n(t=>t.filter(t=>t.id!==e))},[])}}},1483:(e,t,a)=>{a.d(t,{O:()=>n});var r=a(7559);function n(){return{auth:{getSession:async()=>({data:{session:{access_token:"local-token",refresh_token:"local-refresh",expires_in:3600,user:{id:r.g.id,email:r.g.email,user_metadata:{name:r.g.name,full_name:r.g.name}}}},error:null}),signInWithOAuth:async()=>({error:Error("Auth disabled in AGX Board local mode")}),signOut:async()=>({error:null}),onAuthStateChange:()=>({data:{subscription:{unsubscribe(){}}}})},channel:()=>({on(){return this},subscribe(){return this}}),removeChannel(){}}}},7559:(e,t,a)=>{a.d(t,{g:()=>n});var r=a(5704);"1"===r.env.AGX_BOARD_DISABLE_AUTH||"1"===r.env.NEXT_PUBLIC_AGX_BOARD_DISABLE_AUTH||"1"!==r.env.AGX_BOARD_ENABLE_AUTH&&r.env.NEXT_PUBLIC_AGX_BOARD_ENABLE_AUTH;let n={id:"2c3cc1ca-956d-4b62-b295-4d2d3374103f",email:r.env.AGX_BOARD_USER_EMAIL||"local@agx.board",name:r.env.AGX_BOARD_USER_NAME||"Local Board User"}}}]);
1
+ "use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[9719],{91:(e,t,a)=>{a.d(t,{Y:()=>n});var r=a(2115);function n(){let[e,t]=(0,r.useState)([]),[a,n]=(0,r.useState)(!1),[o,l]=(0,r.useState)(null),s=(0,r.useCallback)(async()=>{n(!0);try{var e;let a=await fetch("/api/projects");if(!a.ok)throw Error("Failed to fetch projects");let r=await a.json();t(null!=(e=r.projects)?e:[]),l(null)}catch(e){l(e instanceof Error?e:Error("Unknown error"))}finally{n(!1)}},[]);(0,r.useEffect)(()=>{s()},[s]);let c=(0,r.useCallback)(async e=>{let a=await fetch("/api/projects",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!a.ok)throw Error((await a.json().catch(()=>({}))).error||"Failed to create project");let r=(await a.json()).project;return t(e=>[r,...e]),r},[]);return{projects:e,isLoading:a,error:o,refetch:s,createProject:c,updateProject:(0,r.useCallback)(async(e,a)=>{let r=await fetch("/api/projects/".concat(e),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)});if(!r.ok)throw Error((await r.json().catch(()=>({}))).error||"Failed to update project");let n=(await r.json()).project;return t(t=>t.map(t=>t.id===e?n:t)),n},[]),deleteProject:(0,r.useCallback)(async e=>{let a=await fetch("/api/projects/".concat(e),{method:"DELETE"});if(!a.ok)throw Error((await a.json().catch(()=>({}))).error||"Failed to delete project");t(t=>t.filter(t=>t.id!==e))},[])}}},577:(e,t,a)=>{a.d(t,{LU:()=>s,dF:()=>i,si:()=>l,zH:()=>c});var r=a(2115),n=a(1483),o=a(5704);function l(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t="1"===o.env.NEXT_PUBLIC_AGX_BOARD_DISABLE_AUTH,[a,l]=(0,r.useState)([]),[s,c]=(0,r.useState)(!0),[i,u]=(0,r.useState)(null),[d,f]=(0,r.useState)(null),[h,p]=(0,r.useState)(null),m=(0,r.useCallback)(async()=>{try{let t=new URLSearchParams;e.project&&t.set("project",e.project),e.status&&t.set("status",e.status);let a=await fetch("/api/tasks?".concat(t.toString()));if(!a.ok)throw Error("Failed to fetch tasks");let r=await a.json();l(r.tasks||[]),u(null)}catch(e){u(e instanceof Error?e:Error("Unknown error"))}finally{c(!1)}},[e.project,e.status]);(0,r.useEffect)(()=>{m()},[m]),(0,r.useEffect)(()=>{if(t||!e.realtime)return;let a=(0,n.O)(),r=a.channel("tasks-changes").on("postgres_changes",{event:"*",schema:"public",table:"tasks"},e=>{"INSERT"===e.eventType?l(t=>{let a=e.new;return t.some(e=>e.id===a.id)?t:[a,...t]}):"UPDATE"===e.eventType?l(t=>t.map(t=>t.id===e.new.id?e.new:t)):"DELETE"===e.eventType&&l(t=>t.filter(t=>t.id!==e.old.id))}).subscribe();return()=>{a.removeChannel(r)}},[e.realtime,t]);(0,r.useEffect)(()=>{if(!e.realtime)return;if("undefined"===typeof EventSource)return;const o=new EventSource("/api/tasks/stream"),d=a=>{try{const n=JSON.parse(a.data);if(!n||"UPDATE"!==n.type||!n.task)return;const t=n.task;return l(r=>{if(!r.some(e=>e.id===t.id))return[t,...r];return r.map(e=>e.id===t.id?t:e)})}catch{}};o.onmessage=d,o.onerror=()=>{};return()=>o.close()},[e.realtime]);let k=(0,r.useCallback)(async(e,t)=>{let a=await fetch("/api/tasks",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:e,swarm_models:t})});if(!a.ok)throw Error((await a.json()).error||"Failed to create task");let{task:r}=await a.json();return l(e=>e.some(e=>e.id===r.id)?e:[r,...e]),r},[e.realtime]),w=(0,r.useCallback)(async(e,t)=>{let a=await fetch("/api/tasks/".concat(e),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!a.ok){let e=null;throw"function"==typeof a.json&&(e=await a.json().catch(()=>null)),Error((null==e?void 0:e.error)||(null==e?void 0:e.details)||"Failed to update task (".concat(a.status," ").concat(a.statusText||"Error",")"))}let{task:r}=await a.json();return l(t=>t.map(t=>t.id===e?{...t,...r}:t)),r},[e.realtime]),E=(0,r.useCallback)(async e=>{if(!(await fetch("/api/tasks/".concat(e),{method:"DELETE"})).ok)throw Error("Failed to delete task");l(t=>t.filter(t=>t.id!==e))},[e.realtime]),y=(0,r.useCallback)(async e=>{let t=await fetch("/api/queue/complete",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!t.ok)throw Error((await t.json().catch(()=>({}))).error||"Failed to complete task stage");let{task:a}=await t.json();return l(t=>t.map(t=>t.id===e.taskId?{...t,...a}:t)),a},[e.realtime]);return{tasks:a,isLoading:s,error:i,cancellingTaskId:d,isCancelling:!!d,cancelError:h,refetch:m,createTask:k,updateTask:w,deleteTask:E,completeTaskStage:y,cancelWorkflow:(0,r.useCallback)(async e=>{f(e.taskId),p(null);try{let t=await fetch("/api/orchestrator/tasks/".concat(e.taskId,"/cancel"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e.reason?{reason:e.reason}:{})});if(!t.ok){let e=await t.json().catch(()=>({})),a=(null==e?void 0:e.error)||"Failed to cancel workflow";throw Error(a)}return t.json()}catch(t){let e=t instanceof Error?t:Error("Failed to cancel workflow");throw p(e),e}finally{f(null)}},[]),fetchTask:(0,r.useCallback)(async e=>{let t=await fetch("/api/tasks/".concat(e)),a=await t.json().catch(()=>null);if(!t.ok)throw Error((null==a?void 0:a.error)||"Failed to fetch task details");return null==a?void 0:a.task},[])}}function s(e){let t="1"===o.env.NEXT_PUBLIC_AGX_BOARD_DISABLE_AUTH,[a,l]=(0,r.useState)([]),[s,c]=(0,r.useState)(!1),i=(0,r.useCallback)(async()=>{if(e){c(!0);try{let t=await fetch("/api/tasks/".concat(e,"/comments"));if(t.ok){let e=await t.json();l(e.comments||[])}}finally{c(!1)}}},[e]);return(0,r.useEffect)(()=>{i()},[i]),(0,r.useEffect)(()=>{if(t||!e)return;let a=(0,n.O)(),r=a.channel("task-comments-".concat(e)).on("postgres_changes",{event:"*",schema:"public",table:"task_comments",filter:"task_id=eq.".concat(e)},e=>{if("INSERT"===e.eventType){let t=e.new;(null==t?void 0:t.deleted_at)||l(e=>[...e,t])}else if("UPDATE"===e.eventType){let t=e.new;(null==t?void 0:t.deleted_at)?l(e=>e.filter(e=>e.id!==t.id)):l(e=>e.map(e=>e.id===t.id?t:e))}else"DELETE"===e.eventType&&l(t=>t.filter(t=>t.id!==e.old.id))}).subscribe();return()=>{a.removeChannel(r)}},[e,t]),{comments:a,isLoading:s,refetch:i,addComment:(0,r.useCallback)(async t=>{if(!e)return;let a=await fetch("/api/tasks/".concat(e,"/comments"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:t})});if(a.ok){let{comment:e}=await a.json();return e}},[e]),deleteComment:(0,r.useCallback)(async t=>{e&&(await fetch("/api/tasks/".concat(e,"/comments/").concat(t),{method:"DELETE"})).ok&&l(e=>e.filter(e=>e.id!==t))},[e])}}function c(e){var t;let a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=null==(t=a.enabled)||t,o=Number.isFinite(a.tail)&&a.tail>0?a.tail:500,l=Number.isFinite(a.maxChars)&&a.maxChars>0?a.maxChars:2e5,[s,c]=(0,r.useState)(""),[i,u]=(0,r.useState)(!1),[d,f]=(0,r.useState)(!1),h=(0,r.useRef)(null),p=(0,r.useRef)(0),m=(0,r.useRef)(null),k=(0,r.useCallback)(e=>{let t=(e.log_type||"output").toLowerCase();return"output"===t?e.content||"":"[".concat(t,"] ").concat(e.content||"")},[]),w=(0,r.useCallback)(async function(){let t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];if(e&&n){t||u(!0);try{let a=new URLSearchParams;if(t){let e=m.current;(null==e?void 0:e.created_at)&&a.set("after",e.created_at),a.set("limit","500")}else a.set("tail",String(o));let r=await fetch("/api/tasks/".concat(e,"/logs?").concat(a.toString()));if(r.ok){let e=((await r.json()).logs||[]).slice().sort((e,t)=>e.created_at===t.created_at?e.id.localeCompare(t.id):e.created_at.localeCompare(t.created_at));if(t){let t=m.current,a=t?e.filter(e=>e.created_at>t.created_at||!(e.created_at<t.created_at)&&e.id>t.id):e;if(a.length){let e=a.map(e=>k(e)).join("");e&&c(t=>{let a=t+e;return a.length>l?a.slice(-l):a}),f(!0),h.current&&clearTimeout(h.current),h.current=setTimeout(()=>{f(!1)},5e3)}}else{let t=e.map(e=>k(e)).join("");c(t.length>l?t.slice(-l):t)}if(e.length){let t=e[e.length-1];m.current={created_at:t.created_at,id:t.id}}}}finally{t||u(!1)}}},[n,k,l,o,e]);return(0,r.useEffect)(()=>{c(""),f(!1),u(!1),m.current=null,h.current&&(clearTimeout(h.current),h.current=null),n&&w()},[n,w,e]),(0,r.useEffect)(()=>{if(!e||!n)return;let t=new EventSource("/api/logs/stream?taskId=".concat(e)),a=()=>{let e=Date.now();e-p.current<5e3||(p.current=e,w(!0))};return t.onopen=()=>{a()},t.onmessage=e=>{try{let t=JSON.parse(e.data);if((null==t?void 0:t.type)!=="log"||!t.log)return;let a=t.log,r=k(a);if(!r)return;c(e=>e+r),f(!0),h.current&&clearTimeout(h.current),h.current=setTimeout(()=>{f(!1)},5e3)}catch(e){}},t.onerror=()=>{a()},()=>{t.close(),h.current&&(clearTimeout(h.current),h.current=null)}},[n,w,k,e]),{output:s,isLoading:i,isStreaming:d}}function i(e,t){let[a,n]=(0,r.useState)([]),[o,l]=(0,r.useState)(!1),s=(0,r.useCallback)(async()=>{l(!0);try{let a=new URLSearchParams;e&&a.set("scope",e),t&&a.set("scopeId",t);let r=await fetch("/api/learnings?".concat(a.toString()));if(r.ok){let e=await r.json();n(e.learnings||[])}}finally{l(!1)}},[e,t]);return(0,r.useEffect)(()=>{s()},[s]),{learnings:a,isLoading:o,refetch:s,addLearning:(0,r.useCallback)(async(e,t,a)=>{let r=await fetch("/api/learnings",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({scope:t,scopeId:a,content:e})});if(r.ok){let{learning:e}=await r.json();return n(t=>[e,...t]),e}},[]),deleteLearning:(0,r.useCallback)(async e=>{(await fetch("/api/learnings?id=".concat(e),{method:"DELETE"})).ok&&n(t=>t.filter(t=>t.id!==e))},[])}}},1483:(e,t,a)=>{a.d(t,{O:()=>n});var r=a(7559);function n(){return{auth:{getSession:async()=>({data:{session:{access_token:"local-token",refresh_token:"local-refresh",expires_in:3600,user:{id:r.g.id,email:r.g.email,user_metadata:{name:r.g.name,full_name:r.g.name}}}},error:null}),signInWithOAuth:async()=>({error:Error("Auth disabled in AGX Board local mode")}),signOut:async()=>({error:null}),onAuthStateChange:()=>({data:{subscription:{unsubscribe(){}}}})},channel:()=>({on(){return this},subscribe(){return this}}),removeChannel(){}}}},7559:(e,t,a)=>{a.d(t,{g:()=>n});var r=a(5704);"1"===r.env.AGX_BOARD_DISABLE_AUTH||"1"===r.env.NEXT_PUBLIC_AGX_BOARD_DISABLE_AUTH||"1"!==r.env.AGX_BOARD_ENABLE_AUTH&&r.env.NEXT_PUBLIC_AGX_BOARD_ENABLE_AUTH;let n={id:"2c3cc1ca-956d-4b62-b295-4d2d3374103f",email:r.env.AGX_BOARD_USER_EMAIL||"local@agx.board",name:r.env.AGX_BOARD_USER_NAME||"Local Board User"}}}]);
@@ -1 +1 @@
1
- (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[5105],{63:(e,a,s)=>{"use strict";var t=s(7260);s.o(t,"usePathname")&&s.d(a,{usePathname:function(){return t.usePathname}}),s.o(t,"useRouter")&&s.d(a,{useRouter:function(){return t.useRouter}}),s.o(t,"useSearchParams")&&s.d(a,{useSearchParams:function(){return t.useSearchParams}})},415:(e,a,s)=>{"use strict";s.r(a),s.d(a,{default:()=>f});var t=s(5155),r=s(2115),l=s(63),n=s(1460),o=s(2888),d=s(6779),i=s(2835),c=s(5826),u=s(2325),m=s(8545);function x(e){let{onClose:a,workflowId:s}=e,{workflow:l,isLoading:n,refetch:o}=(0,u.mP)({workflowId:s}),{providers:d}=(0,m.u)(),[i,c]=(0,r.useState)([]),[x,p]=(0,r.useState)(null),[h,v]=(0,r.useState)(!1),[g,b]=(0,r.useState)({}),f=e=>u.ls[e]||{icon:"\uD83D\uDCCC",label:e.charAt(0).toUpperCase()+e.slice(1),color:"var(--primary)"};(0,r.useEffect)(()=>{let e=(Array.isArray(null==l?void 0:l.nodes)?l.nodes:[]).slice().sort((e,a)=>(e.position||0)-(a.position||0)).map(e=>{var a,s;return{id:e.id,name:e.name,label:e.label||e.name,prompt:e.prompt||"",provider:e.provider||"codex",model:e.model||"",swarm:!!(null==e||null==(a=e.metadata)?void 0:a.swarm),swarm_models:Array.isArray(null==e||null==(s=e.metadata)?void 0:s.swarm_models)?e.metadata.swarm_models:[],metadata:(null==e?void 0:e.metadata)&&"object"==typeof e.metadata?e.metadata:{}}});c(e),b({}),p(a=>a&&e.some(e=>e.id===a)?a:e.length?e[0].id:null)},[null==l?void 0:l.id,null==l?void 0:l.nodes]);let j=i.findIndex(e=>e.id===x),w=j>=0?i[j]:null,N=w?{...w,...g[w.id]||{}}:null,y=(e,a)=>{w&&b(s=>({...s,[w.id]:{...s[w.id]||{},[e]:a}}))},k=async()=>{if(l){v(!0);try{let e=i.map(e=>{let a={...e,...g[e.id]||{}};return{...a,metadata:{...a.metadata||{},swarm:!!a.swarm,swarm_models:a.swarm_models||[]}}}),s=await fetch("/api/workflows/".concat(l.id,"/nodes"),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({nodes:e.map(e=>({id:e.id,prompt:e.prompt,provider:e.provider,model:e.model,metadata:e.metadata}))})});if(!s.ok)throw Error("Failed to save workflow");await s.json(),o(),b({}),a()}catch(e){console.error("Error saving workflow:",e)}finally{v(!1)}}};return n&&!l?(0,t.jsx)("div",{className:"modal-backdrop p-4 flex items-center justify-center",children:(0,t.jsx)("span",{className:"spinner w-8 h-8 border-2 border-white/20 border-t-white"})}):(0,t.jsx)("div",{className:"modal-backdrop p-4",onClick:e=>e.target===e.currentTarget&&a(),children:(0,t.jsxs)("div",{className:"modal-content w-full max-w-5xl h-[85vh] flex flex-col animate-scale-in p-0 bg-[var(--card-bg)] overflow-hidden rounded-xl border border-[var(--card-border)] shadow-2xl",children:[(0,t.jsxs)("div",{className:"px-6 py-4 border-b border-[var(--border)] flex items-center justify-between bg-[var(--background)]",children:[(0,t.jsxs)("div",{children:[(0,t.jsxs)("h2",{className:"text-lg font-bold flex items-center gap-2",children:[(0,t.jsx)("span",{children:"⚙️"})," Workflow Configuration"]}),(0,t.jsxs)("p",{className:"text-xs text-[var(--muted-foreground)] mt-0.5",children:["Editing: ",(0,t.jsx)("span",{className:"font-mono text-[var(--foreground)]",children:(null==l?void 0:l.name)||"Loading..."})]})]}),(0,t.jsx)("button",{onClick:a,className:"btn-ghost p-2 rounded",children:(0,t.jsx)("svg",{className:"w-5 h-5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,t.jsxs)("div",{className:"flex flex-1 overflow-hidden",children:[(0,t.jsxs)("div",{className:"w-64 bg-[var(--muted)]/30 border-r border-[var(--border)] overflow-y-auto p-4 flex flex-col gap-1",children:[(0,t.jsx)("div",{className:"flex items-center justify-between mb-2 px-2",children:(0,t.jsx)("span",{className:"text-xs font-bold uppercase tracking-wider text-[var(--muted-foreground)]",children:"Steps"})}),0===i.length&&(0,t.jsx)("div",{className:"text-sm text-[var(--muted-foreground)] px-2 italic",children:"No steps defined in this workflow."}),i.map(e=>{let a=f(e.name),s=!!g[e.id];return(0,t.jsxs)("button",{onClick:()=>p(e.id),className:"w-full text-left px-3 py-2.5 rounded-lg text-sm font-medium transition-all flex items-center gap-3 ".concat(x===e.id?"bg-[var(--card-bg)] text-[var(--foreground)] shadow-sm border border-[var(--border)]":"text-[var(--muted-foreground)] hover:bg-[var(--card-bg)]/50"),children:[(0,t.jsx)("span",{className:"text-base",children:a.icon}),(0,t.jsx)("span",{className:"flex-1 truncate",children:e.label||a.label}),s&&(0,t.jsx)("span",{className:"w-1.5 h-1.5 rounded-full bg-[var(--accent)]"})]},e.id)})]}),(0,t.jsxs)("div",{className:"flex-1 overflow-y-auto p-8 relative bg-[var(--card-bg)]",children:[N?(0,t.jsxs)("div",{className:"max-w-3xl mx-auto space-y-8 animate-fade-in",children:[(0,t.jsxs)("div",{className:"flex items-center gap-4 pb-6 border-b border-[var(--border)]",children:[(0,t.jsx)("div",{className:"w-12 h-12 rounded-xl bg-[var(--muted)]/50 flex items-center justify-center text-2xl shadow-inner",children:f(N.name).icon}),(0,t.jsxs)("div",{children:[(0,t.jsx)("h3",{className:"text-xl font-bold",children:N.label}),(0,t.jsxs)("p",{className:"text-sm text-[var(--muted-foreground)] font-mono opacity-70",children:["ID: ",N.id," • Key: ",N.name]})]})]}),(0,t.jsxs)("div",{className:"space-y-3",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between",children:[(0,t.jsx)("label",{className:"text-sm font-semibold uppercase tracking-wider text-[var(--muted-foreground)]",children:"System Prompt"}),(0,t.jsx)("span",{className:"text-xs text-[var(--muted-foreground)] bg-[var(--muted)]/50 px-2 py-0.5 rounded",children:"Markdown Supported"})]}),(0,t.jsx)("textarea",{value:N.prompt||"",onChange:e=>y("prompt",e.target.value),className:"input w-full h-64 font-mono text-sm leading-relaxed resize-y p-4",placeholder:"Define the agent's behavior, constraints, and output format for this stage..."})]}),(0,t.jsxs)("div",{className:"p-6 rounded-xl bg-[var(--muted)]/20 border border-[var(--border)] space-y-6",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between",children:[(0,t.jsxs)("h4",{className:"font-semibold flex items-center gap-2",children:[(0,t.jsx)("span",{children:"\uD83E\uDD16"})," Model Settings"]}),(0,t.jsxs)("div",{className:"flex items-center gap-3 bg-[var(--card-bg)] px-3 py-1.5 rounded-lg border border-[var(--border)]",children:[(0,t.jsx)("span",{className:"text-sm font-medium",children:"Swarm Mode"}),(0,t.jsx)("button",{onClick:()=>y("swarm",!N.swarm),className:"w-9 h-5 rounded-full transition-colors relative ".concat(N.swarm?"bg-[var(--primary)]":"bg-[var(--muted-foreground)]/30"),children:(0,t.jsx)("span",{className:"absolute top-0.5 left-0.5 w-4 h-4 bg-white rounded-full transition-transform ".concat(N.swarm?"translate-x-4":"translate-x-0")})})]})]}),N.swarm?(0,t.jsxs)("div",{className:"space-y-4 animate-fade-in",children:[(0,t.jsxs)("div",{className:"flex justify-between items-center",children:[(0,t.jsx)("span",{className:"text-sm font-medium text-[var(--muted-foreground)]",children:"Swarm Models"}),(0,t.jsx)("button",{onClick:()=>{y("swarm_models",[...N.swarm_models||[],{provider:"gemini",model:""}])},className:"btn-secondary text-xs px-2 py-1",children:"+ Add Model"})]}),(0,t.jsxs)("div",{className:"space-y-2",children:[0===(N.swarm_models||[]).length&&(0,t.jsx)("div",{className:"text-center py-8 border-2 border-dashed border-[var(--border)] rounded-lg text-sm text-[var(--muted-foreground)]",children:"No models configured for swarm. Add one to enable."}),(N.swarm_models||[]).map((e,a)=>(0,t.jsxs)("div",{className:"flex gap-2 items-center group",children:[(0,t.jsx)("select",{value:e.provider,onChange:e=>{let s=[...N.swarm_models||[]];s[a].provider=e.target.value,y("swarm_models",s)},className:"input text-sm py-1.5 w-32",children:d.map(e=>(0,t.jsx)("option",{value:e.id,children:e.label},e.id))}),(0,t.jsx)("input",{value:e.model,onChange:e=>{let s=[...N.swarm_models||[]];s[a].model=e.target.value,y("swarm_models",s)},placeholder:"Model name (e.g. gemini-1.5-pro)",className:"input text-sm py-1.5 flex-1"}),(0,t.jsx)("button",{onClick:()=>{y("swarm_models",(N.swarm_models||[]).filter((e,s)=>s!==a))},className:"text-[var(--muted-foreground)] hover:text-[var(--destructive)] hover:bg-[var(--destructive)]/10 p-1.5 rounded opacity-0 group-hover:opacity-100 transition-all",children:"✕"})]},a))]})]}):(0,t.jsxs)("div",{className:"grid grid-cols-2 gap-4 animate-fade-in",children:[(0,t.jsxs)("div",{className:"space-y-1.5",children:[(0,t.jsx)("label",{className:"text-xs font-semibold text-[var(--muted-foreground)] uppercase",children:"Provider"}),(0,t.jsx)("select",{value:N.provider||"gemini",onChange:e=>y("provider",e.target.value),className:"input w-full text-sm py-2",children:d.map(e=>(0,t.jsx)("option",{value:e.id,children:e.label},e.id))})]}),(0,t.jsxs)("div",{className:"space-y-1.5",children:[(0,t.jsx)("label",{className:"text-xs font-semibold text-[var(--muted-foreground)] uppercase",children:"Model"}),(0,t.jsx)("input",{value:N.model||"",onChange:e=>y("model",e.target.value),placeholder:"e.g. gemini-2.0-flash",className:"input w-full text-sm py-2"})]})]})]})]}):null,!w&&i.length>0&&(0,t.jsxs)("div",{className:"flex flex-col items-center justify-center h-full text-[var(--muted-foreground)]",children:[(0,t.jsx)("span",{className:"text-4xl mb-4 opacity-30",children:"\uD83D\uDC48"}),(0,t.jsx)("p",{children:"Select a step from the sidebar to configure it."})]})]})]}),(0,t.jsxs)("div",{className:"px-6 py-4 border-t border-[var(--border)] bg-[var(--background)] flex justify-end gap-3",children:[(0,t.jsx)("button",{onClick:a,className:"btn-ghost px-4 py-2",children:"Cancel"}),(0,t.jsxs)("button",{onClick:k,disabled:h||0===Object.keys(g).length,className:"btn-primary px-6 py-2 flex items-center gap-2",children:[h&&(0,t.jsx)("span",{className:"spinner w-4 h-4 border-2 border-white/20 border-t-white"}),h?"Saving...":"Save Changes"]})]})]})})}var p=s(577),h=s(91);function v(){return(0,t.jsxs)("div",{className:"p-4 rounded-xl bg-[var(--card-bg)] border border-[var(--card-border)]",children:[(0,t.jsxs)("div",{className:"flex items-start justify-between mb-3",children:[(0,t.jsxs)("div",{className:"flex-1",children:[(0,t.jsxs)("div",{className:"flex gap-2 mb-2",children:[(0,t.jsx)("div",{className:"skeleton h-4 w-8 rounded"}),(0,t.jsx)("div",{className:"skeleton h-4 w-16 rounded"})]}),(0,t.jsx)("div",{className:"skeleton h-5 w-3/4 rounded"})]}),(0,t.jsx)("div",{className:"skeleton h-5 w-20 rounded-full"})]}),(0,t.jsxs)("div",{className:"flex justify-between",children:[(0,t.jsx)("div",{className:"skeleton h-4 w-24 rounded"}),(0,t.jsx)("div",{className:"skeleton h-4 w-12 rounded"})]})]})}function g(){return(0,t.jsx)("div",{className:"flex gap-4 overflow-x-auto pb-4 px-4",children:[1,2,3,4,5].map(e=>(0,t.jsxs)("div",{className:"flex-shrink-0 w-72 kanban-column",children:[(0,t.jsx)("div",{className:"kanban-column-header",children:(0,t.jsxs)("div",{className:"flex items-center justify-between",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)("div",{className:"skeleton h-6 w-6 rounded"}),(0,t.jsx)("div",{className:"skeleton h-5 w-20 rounded"})]}),(0,t.jsx)("div",{className:"skeleton h-5 w-6 rounded-full"})]})}),(0,t.jsx)("div",{className:"p-2 space-y-2",children:[1,2].map(e=>(0,t.jsxs)("div",{className:"p-3 rounded-lg bg-[var(--background)] border-l-2 border-[var(--card-border)]",children:[(0,t.jsx)("div",{className:"skeleton h-3 w-12 rounded mb-2"}),(0,t.jsx)("div",{className:"skeleton h-4 w-full rounded mb-2"}),(0,t.jsx)("div",{className:"skeleton h-3 w-20 rounded"})]},e))})]},e))})}function b(){let e=(0,l.useRouter)(),a=(0,l.useSearchParams)(),s=(0,l.usePathname)(),b=(null==a?void 0:a.get("project"))||void 0,f=a.get("view")||"kanban",j=a.get("sort")||"newest",[w,N]=(0,r.useState)(f),[y,k]=(0,r.useState)(j),[C,_]=(0,r.useState)("all"),[S,A]=(0,r.useState)(""),[T,D]=(0,r.useState)(null),[E,P]=(0,r.useState)(!1),[L,R]=(0,r.useState)(null),[M,I]=(0,r.useState)(!1),[B,q]=(0,r.useState)(""),[U,F]=(0,r.useState)(!1),[O,X]=(0,r.useState)("single"),[z,W]=(0,r.useState)("gemini"),[G,V]=(0,r.useState)(""),[K,Q]=(0,r.useState)([]),[H,Y]=(0,r.useState)("gemini"),[J,Z]=(0,r.useState)(""),[$,ee]=(0,r.useState)(null),[ea,es]=(0,r.useState)(!1),[et,er]=(0,r.useState)(!1),[el,en]=(0,r.useState)(null),{providers:eo}=(0,m.u)();(0,r.useEffect)(()=>{let e=e=>{let a=e.target,s=["INPUT","TEXTAREA","SELECT"].includes(a.tagName)||a.isContentEditable;if("n"!==e.key||s||(e.preventDefault(),I(!0)),"/"===e.key&&!s){var t;e.preventDefault(),null==(t=document.getElementById("task-search"))||t.focus()}};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[]);let{tasks:ed,isLoading:ei,createTask:ec,updateTask:eu,deleteTask:em,completeTaskStage:ex,cancelWorkflow:ep,refetch:eh,cancellingTaskId:ev,fetchTask:eg}=(0,p.si)({realtime:!0,project:b}),{projects:eb,isLoading:ef}=(0,h.Y)(),{comments:ej,addComment:ew,deleteComment:eN}=(0,p.LU)((null==T?void 0:T.id)||null),{learnings:ey,addLearning:ek}=(0,p.dF)((null==T?void 0:T.id)||void 0),{workflow:eC,stages:e_,stageConfig:eS,isValidTransition:eA,isLoading:eT}=(0,u.mP)(),eD=(0,r.useMemo)(()=>e_.map(e=>{var a;let s=eS[e],t=null==eC||null==(a=eC.nodes)?void 0:a.find(a=>a.name===e);return{id:e,label:(null==s?void 0:s.label)||e,icon:(null==s?void 0:s.icon)||"\uD83D\uDCCC",color:(null==s?void 0:s.color)||"var(--primary)",prompt:(null==t?void 0:t.prompt)||void 0}}),[e_,eS,eC]),eE=t=>{N(t);let r=new URLSearchParams(a);r.set("view",t),e.push("".concat(s,"?").concat(r.toString()))},eP=(0,r.useMemo)(()=>{let e=[...ed];if(S){let a=S.toLowerCase();e=e.filter(e=>{var s,t,r;return(null==(s=e.title)?void 0:s.toLowerCase().includes(a))||(null==(t=e.description)?void 0:t.toLowerCase().includes(a))||e.id.toLowerCase().includes(a)||(null==(r=e.project)?void 0:r.toLowerCase().includes(a))})}return"all"!==C&&(e="active"===C?e.filter(e=>"completed"!==e.status&&"failed"!==e.status):e.filter(e=>e.status===C)),e.sort((e,a)=>{switch(y){case"newest":return new Date(a.created_at).getTime()-new Date(e.created_at).getTime();case"oldest":return new Date(e.created_at).getTime()-new Date(a.created_at).getTime();case"priority":return(e.priority||0)-(a.priority||0);case"updated":return new Date(a.updated_at).getTime()-new Date(e.updated_at).getTime();default:return 0}}),e},[ed,S,C,y]),eL=(0,r.useCallback)(async(e,a)=>{a&&D(a);try{let a=await eg(e);return D(a),a}catch(e){return console.error("Failed to load task details:",e),a||D(null),null!=a?a:null}},[eg]),eR=(0,r.useCallback)(async e=>{await eL(e.id,e)},[eL]),eM=(0,r.useCallback)(async e=>{var a;er(!0),en(e);let s="ideation"===e?"queued":"in_progress",t=(null==eS||null==(a=eS[e])?void 0:a.label)||e,r=["status: ".concat(s),"stage: ".concat(e)],l="---\n".concat(r.join("\n"),"\n---\n\n# New Task (").concat(t,")\n");try{let e=await ec(l,null);await eL(e.id,e)}catch(e){console.error("Failed to create task:",e)}finally{er(!1),en(null)}},[ec,eL,eS]),eI=(0,r.useCallback)(async(e,a)=>{await eu(e,a)},[eu]),eB=async e=>{let a=ed.find(a=>a.id===e);R(null);try{var s;await ep({taskId:e}),await eh(),R({type:"success",message:"Cancellation requested for ".concat((null==a?void 0:a.title)||(null==a||null==(s=a.content)?void 0:s.slice(0,30))||e,".")})}catch(t){console.error("Failed to stop task",t);let s=t instanceof Error?t.message:"unknown error";R({type:"error",message:"Unable to stop ".concat((null==a?void 0:a.title)||e,": ").concat(s,".")})}},eq=async e=>{try{await ex({taskId:e,decision:"not_done",final_result:"Manual retry requested.",explanation:"Manual retry requested."})}catch(e){console.error("Failed to retry task",e)}};(0,r.useEffect)(()=>{if(!L)return;let e=setTimeout(()=>R(null),5e3);return()=>clearTimeout(e)},[L]);let eU=async()=>{if(B.trim()&&!U){F(!0);try{var e;let a=["status: queued","stage: ideation"];"single"!==O&&a.push("swarm: true");let s=$||(b?null==(e=eb.find(e=>e.slug===b))?void 0:e.id:null);if(s){let e=eb.find(e=>e.id===s);e&&(a.push("project: ".concat(e.slug)),a.push("project_id: ".concat(e.id)),a.push("workflow_id: ".concat(e.workflow_id||u.ou)))}let t="---\n".concat(a.join("\n"),"\n---\n\n# ").concat(B,"\n");await ec(t,"swarm"===O?K:null),q(""),X("single"),W("gemini"),V(""),Q([]),Y("gemini"),Z(""),I(!1),ee(null)}catch(e){console.error("Failed to create task:",e)}finally{F(!1)}}},eF=async(e,a)=>{let s="---\n".concat(["status: ".concat("ideation"===a?"queued":"in_progress"),"stage: ".concat(a)].join("\n"),"\n---\n\n# ").concat(e,"\n");await ec(s,null),es(!1)},eO=async e=>{T&&await ew(e)},eX=async(e,a,s)=>{var t,r;let l=(null==T||null==(r=T.project_context)||null==(t=r.project)?void 0:t.id)||(null==T?void 0:T.project_id)||(null==T?void 0:T.project)||void 0,n=null!=s?s:"global"===a?void 0:"task"===a?null==T?void 0:T.id:l;await ek(e,a,n)},ez=async e=>{T&&(D(a=>a?{...a,...e}:null),await eu(T.id,e))};return(ed.length,ed.filter(e=>"in_progress"===e.status).length,ed.filter(e=>"queued"===e.status).length,ed.filter(e=>"completed"===e.status).length,(ei||eT)&&0===ed.length)?(0,t.jsxs)("div",{className:"h-full flex flex-col p-6 animate-pulse",children:[(0,t.jsxs)("div",{className:"flex justify-between items-center mb-8",children:[(0,t.jsx)("div",{className:"h-8 w-48 bg-[var(--card-border)] rounded"}),(0,t.jsx)("div",{className:"h-10 w-32 bg-[var(--card-border)] rounded"})]}),(0,t.jsx)("div",{className:"h-12 w-full bg-[var(--card-border)] rounded mb-8"}),"kanban"===w?(0,t.jsx)(g,{}):(0,t.jsx)("div",{className:"space-y-4",children:[1,2,3].map(e=>(0,t.jsx)(v,{},e))})]}):(0,t.jsx)(n.A,{fullWidth:!0,noFooter:!0,children:(0,t.jsxs)("div",{className:"flex flex-col h-full ".concat("kanban"===w?"max-w-full":"max-w-6xl mx-auto w-full px-4"),children:[(0,t.jsxs)("div",{className:"relative flex items-center justify-center gap-4 py-3 px-4 border-b border-[var(--border)] bg-[var(--background)] flex-shrink-0 z-20",children:[(0,t.jsxs)("div",{className:"flex items-center gap-4",children:[(0,t.jsxs)("div",{className:"relative w-80",children:[(0,t.jsx)("div",{className:"absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none",children:(0,t.jsx)("svg",{className:"h-5 w-5 text-gray-400",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:(0,t.jsx)("path",{fillRule:"evenodd",d:"M9 3.5a5.5 5.5 0 100 11 5.5 5.5 0 000-11zM2 9a7 7 0 1112.452 4.391l3.328 3.329a.75.75 0 11-1.06 1.06l-3.329-3.328A7 7 0 012 9z",clipRule:"evenodd"})})}),(0,t.jsx)("input",{id:"task-search",type:"text",placeholder:"Search tasks... (/)",className:"block w-full rounded-md border-0 py-1.5 pl-10 text-gray-900 ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6 bg-white shadow-sm",value:S,onChange:e=>A(e.target.value)})]}),(0,t.jsxs)("div",{className:"flex items-center bg-gray-100 p-1 rounded-lg border border-gray-200",children:[(0,t.jsx)("button",{onClick:()=>eE("list"),className:"px-3 py-1 text-xs font-medium rounded transition-all ".concat("list"===w?"bg-white shadow-sm text-gray-900":"text-gray-500 hover:text-gray-700"),children:"List"}),(0,t.jsx)("button",{onClick:()=>eE("kanban"),className:"px-3 py-1 text-xs font-medium rounded transition-all ".concat("kanban"===w?"bg-white shadow-sm text-gray-900":"text-gray-500 hover:text-gray-700"),children:"Board"})]}),(0,t.jsxs)("button",{onClick:()=>P(!0),className:"flex items-center gap-2 px-3 py-1.5 text-xs font-medium text-gray-700 bg-white border border-gray-200 rounded-lg shadow-sm hover:bg-gray-50 transition-all",title:"Configure Workflow",children:[(0,t.jsx)("span",{className:"text-base leading-none",children:"⚙️"}),(0,t.jsx)("span",{children:"Workflow"})]})]}),(0,t.jsx)("div",{className:"absolute right-4 flex items-center gap-3"})]}),L&&(0,t.jsx)("div",{className:"px-4 mt-3",children:(0,t.jsx)("div",{role:"status",className:"rounded-xl px-4 py-2 text-xs font-semibold ".concat("success"===L.type?"bg-[var(--success-muted)] text-[var(--success)]":"bg-[var(--destructive-muted)] text-[var(--destructive)]"),children:L.message})}),(0,t.jsx)("div",{className:"flex-shrink-0 mt-2 px-4",children:(0,t.jsx)(i.A,{tasks:ed,onTaskClick:D,onStop:eB,onRetry:eq,cancellingTaskId:ev})}),(0,t.jsx)("div",{className:"flex-1 min-h-0 overflow-hidden flex flex-col pt-2",children:"list"===w?(0,t.jsx)("div",{className:"overflow-y-auto h-full px-4",children:(0,t.jsx)(o.A,{tasks:eP,onSelectTask:eR})}):(0,t.jsx)(d.A,{tasks:eP,onSelectTask:eR,onTasksChange:()=>{},onTaskUpdate:eI,onAddTask:eM,stages:e_,stageConfig:eS,isValidTransition:eA,isCreatingTask:et,creatingStage:el})}),T&&(0,t.jsx)(c.A,{task:T,comments:T?ej:[],learnings:ey,projectContext:T.project_context,projects:eb,stages:eD,onClose:()=>D(null),onAddComment:eO,onDeleteComment:eN,onAddLearning:eX,onUpdate:ez,onDelete:async()=>{await em(T.id),D(null)}}),ea&&(0,t.jsx)("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50",children:(0,t.jsxs)("div",{className:"bg-[var(--card-bg)] p-6 rounded-xl w-full max-w-md shadow-2xl border border-[var(--card-border)] animate-scale-in",children:[(0,t.jsx)("h3",{className:"text-lg font-bold mb-4",children:"New Task"}),(0,t.jsxs)("form",{onSubmit:e=>{e.preventDefault();let a=e.target;eF(a.elements.namedItem("title").value,a.elements.namedItem("stage").value)},children:[(0,t.jsx)("input",{name:"title",autoFocus:!0,placeholder:"Task title...",className:"w-full mb-4 px-3 py-2 bg-[var(--background)] border border-[var(--card-border)] rounded focus:border-[var(--primary)] outline-none",required:!0}),(0,t.jsx)("select",{name:"stage",className:"w-full mb-6 px-3 py-2 bg-[var(--background)] border border-[var(--card-border)] rounded focus:border-[var(--primary)] outline-none",children:e_.map(e=>{var a;return(0,t.jsx)("option",{value:e,children:(null==(a=eS[e])?void 0:a.label)||e},e)})}),(0,t.jsxs)("div",{className:"flex justify-end gap-2",children:[(0,t.jsx)("button",{type:"button",onClick:()=>es(!1),className:"btn-ghost",children:"Cancel"}),(0,t.jsx)("button",{type:"submit",className:"btn-primary",children:"Create Task"})]})]})]})}),E&&(0,t.jsx)(x,{onClose:()=>P(!1),workflowId:null==eC?void 0:eC.id}),M&&(0,t.jsx)("div",{className:"modal-backdrop p-4",onClick:e=>e.target===e.currentTarget&&I(!1),children:(0,t.jsxs)("div",{className:"modal-content w-full max-w-lg p-6 animate-scale-in",children:[(0,t.jsxs)("h2",{className:"text-xl font-bold mb-4 flex items-center gap-2",children:[(0,t.jsx)("span",{children:"✨"})," New Task"]}),(0,t.jsxs)("div",{className:"flex items-center gap-2 mb-4",children:[(0,t.jsx)("button",{onClick:()=>X("single"),className:"px-3 py-1.5 text-xs font-semibold rounded-md uppercase tracking-wide transition-all ".concat("single"===O?"bg-[var(--card-bg)] text-[var(--primary)] shadow-sm border border-[var(--border)]":"text-[var(--muted-foreground)] hover:text-[var(--foreground)] border border-transparent"),children:"Single Agent"}),(0,t.jsx)("button",{onClick:()=>X("swarm"),className:"px-3 py-1.5 text-xs font-semibold rounded-md uppercase tracking-wide transition-all ".concat("swarm"===O?"bg-[var(--card-bg)] text-[var(--primary)] shadow-sm border border-[var(--border)]":"text-[var(--muted-foreground)] hover:text-[var(--foreground)] border border-transparent"),children:"Swarm"})]}),(0,t.jsx)("textarea",{value:B,onChange:e=>q(e.target.value),placeholder:"Describe what needs to be done...",className:"input h-32 resize-none mb-4",autoFocus:!0,disabled:U}),(0,t.jsxs)("label",{className:"text-xs font-semibold mb-3 block",children:["Attach to project",(0,t.jsxs)("select",{value:null!=$?$:"",onChange:e=>ee(e.target.value||null),className:"input text-sm mt-1",disabled:ef,children:[(0,t.jsxs)("option",{value:"",children:["None (Current: ",b||"All",")"]}),eb.map(e=>(0,t.jsx)("option",{value:e.id,children:e.name},e.id))]})]}),"single"===O?(0,t.jsxs)("div",{className:"grid gap-3 sm:grid-cols-2 mb-4",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"block text-[11px] font-medium text-[var(--muted-foreground)] mb-1",children:"Provider"}),(0,t.jsx)("select",{value:z,onChange:e=>W(e.target.value),className:"input text-xs py-1.5 appearance-none",children:eo.map(e=>(0,t.jsx)("option",{value:e.id,children:e.label},e.id))})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"block text-[11px] font-medium text-[var(--muted-foreground)] mb-1",children:"Model"}),(0,t.jsx)("input",{value:G,onChange:e=>V(e.target.value),placeholder:"e.g. gpt-4.1-mini",className:"input text-xs py-1.5"})]})]}):(0,t.jsx)("div",{className:"mb-4 space-y-3",children:(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"block text-[11px] font-medium text-[var(--muted-foreground)] mb-2",children:"Swarm Models"}),(0,t.jsxs)("div",{className:"grid gap-2",children:[(0,t.jsxs)("div",{className:"grid grid-cols-[1fr_1.2fr_auto] gap-2",children:[(0,t.jsx)("select",{value:H,onChange:e=>Y(e.target.value),className:"input text-xs py-1.5 appearance-none",children:eo.map(e=>(0,t.jsx)("option",{value:e.id,children:e.label},e.id))}),(0,t.jsx)("input",{value:J,onChange:e=>Z(e.target.value),placeholder:"model name",className:"input text-xs py-1.5"}),(0,t.jsx)("button",{type:"button",onClick:()=>{let e=J.trim();if(!e)return;let a={provider:H,model:e};K.some(e=>e.provider.toLowerCase()===a.provider.toLowerCase()&&e.model.toLowerCase()===a.model.toLowerCase())||(Q(e=>[...e,a]),Z(""))},className:"btn-ghost px-3 py-1.5 text-xs",children:"Add"})]}),K.length>0&&(0,t.jsx)("div",{className:"space-y-1",children:K.map((e,a)=>(0,t.jsxs)("div",{className:"flex items-center justify-between px-3 py-1.5 rounded-md border text-xs bg-[var(--background)] border-[var(--border)]",children:[(0,t.jsxs)("span",{className:"truncate",children:[(0,t.jsx)("span",{className:"text-[var(--muted-foreground)]",children:e.provider}),(0,t.jsx)("span",{className:"mx-1",children:"\xb7"}),(0,t.jsx)("span",{children:e.model})]}),(0,t.jsx)("button",{type:"button",onClick:()=>{Q(e=>e.filter((e,s)=>s!==a))},className:"text-[var(--destructive)] hover:underline",children:"Remove"})]},"".concat(e.provider,"-").concat(e.model,"-").concat(a)))})]})]})}),(0,t.jsxs)("div",{className:"flex justify-end gap-3",children:[(0,t.jsx)("button",{onClick:()=>{I(!1),q(""),X("single"),W("gemini"),V(""),Q([]),Y("gemini"),Z("")},disabled:U,className:"btn-ghost px-4 py-2",children:"Cancel"}),(0,t.jsx)("button",{onClick:eU,disabled:!B.trim()||U||"swarm"===O&&0===K.length,className:"btn-primary px-4 py-2 flex items-center gap-2",children:U?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("span",{className:"spinner w-4 h-4 border-2 border-white/20 border-t-white"}),"Creating..."]}):"Create Task"})]})]})})]})})}function f(){return(0,t.jsx)(r.Suspense,{fallback:(0,t.jsx)("div",{className:"p-8",children:"Loading..."}),children:(0,t.jsx)(b,{})})}},1460:(e,a,s)=>{"use strict";s.d(a,{A:()=>m});var t=s(5155),r=s(2619),l=s.n(r),n=s(63),o=s(4647),d=s(91),i=s(2115);function c(e){let{children:a,fullWidth:s=!1,noFooter:r=!1}=e;(0,n.usePathname)(),(0,n.useRouter)();let c=(0,n.useSearchParams)(),{user:u,loading:m,signOut:x}=(0,o.A)(),{projects:p,isLoading:h}=(0,d.Y)(),v=null==c?void 0:c.get("project");return(0,i.useMemo)(()=>v?p.find(e=>e.slug===v):null,[p,v]),(0,t.jsxs)("div",{className:"h-screen flex flex-col overflow-hidden",children:[(0,t.jsx)("nav",{className:"flex-shrink-0 border-b border-[var(--card-border)] bg-[var(--card-bg)]/80 backdrop-blur-lg z-30",children:(0,t.jsx)("div",{className:"max-w-7xl mx-auto px-4 sm:px-6 lg:px-8",children:(0,t.jsxs)("div",{className:"flex items-center justify-between h-16",children:[(0,t.jsx)("div",{className:"flex items-center gap-8",children:(0,t.jsxs)(l(),{href:"/",className:"flex items-center gap-3 group",children:[(0,t.jsx)("div",{className:"w-8 h-8 rounded-lg bg-gradient-to-br from-[var(--primary)] to-[var(--accent)] flex items-center justify-center text-white font-bold text-sm shadow-lg shadow-[var(--primary)]/20 group-hover:shadow-[var(--primary)]/40 transition-shadow",children:"A"}),(0,t.jsx)("span",{className:"text-lg font-bold tracking-tight gradient-text hidden sm:block",children:"AGX Board"})]})}),(0,t.jsx)("div",{className:"flex items-center gap-3",children:(0,t.jsx)(l(),{href:"/settings",className:"text-sm font-medium text-[var(--muted-foreground)] hover:text-[var(--foreground)] transition-colors",children:"Settings"})})]})})}),(0,t.jsx)("main",{className:"flex-1 min-h-0 flex flex-col ".concat(s?"p-0":"p-4 sm:p-6 lg:p-8 overflow-y-auto"),children:a}),!r&&(0,t.jsx)("footer",{className:"flex-shrink-0 border-t border-[var(--card-border)] bg-[var(--card-bg)]/50 py-4",children:(0,t.jsxs)("div",{className:"max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 flex items-center justify-between text-xs text-[var(--muted-foreground)]",children:[(0,t.jsx)("span",{children:"AGX Board • Autonomous Agent Orchestration"}),(0,t.jsx)("span",{className:"hidden sm:inline",children:"Built with Next.js + Db"})]})})]})}function u(e){return(0,t.jsx)(i.Suspense,{fallback:(0,t.jsx)("div",{className:"h-screen flex items-center justify-center bg-[var(--background)]",children:(0,t.jsx)("span",{className:"spinner w-8 h-8 border-3 border-[var(--primary)] border-t-transparent rounded-full"})}),children:(0,t.jsx)(c,{...e})})}function m(e){let{children:a,fullWidth:s=!1,noFooter:r=!1}=e;return(0,t.jsx)(u,{fullWidth:s,noFooter:r,children:a})}},2888:(e,a,s)=>{"use strict";s.d(a,{A:()=>d});var t=s(5155);let r={queued:{className:"badge-status-queued",label:"Queued",dotColor:"bg-[var(--status-queued)]"},in_progress:{className:"badge-status-in_progress",label:"In Progress",dotColor:"bg-[var(--status-in-progress)]"},blocked:{className:"badge-status-blocked",label:"Blocked",dotColor:"bg-[var(--status-blocked)]"},completed:{className:"badge-status-completed",label:"Completed",dotColor:"bg-[var(--status-completed)]"},failed:{className:"badge-status-failed",label:"Failed",dotColor:"bg-[var(--status-failed)]"}},l={ideation:{icon:"\uD83D\uDCA1",label:"Ideation",prompt:"Research and scope. Define approach, estimate effort."},planning:{icon:"\uD83D\uDCCB",label:"Planning",prompt:"Create detailed plan with tasks, milestones, and dependencies."},execution:{icon:"\uD83D\uDCBB",label:"Execution",prompt:"Implement based on all the context/history/research/plan. Write clean, tested code."},verification:{icon:"\uD83E\uDDEA",label:"Verification",prompt:"Test thoroughly. Find edge cases. Fix bugs. Verify requirements are met."},coding:{icon:"\uD83D\uDCBB",label:"Coding",prompt:"Write clean, tested code based on plan."},qa:{icon:"\uD83E\uDDEA",label:"QA",prompt:"Test thoroughly. Find edge cases. Fix bugs."},acceptance:{icon:"✓",label:"Acceptance",prompt:"Demo to user. Get sign-off. Address feedback."},pr:{icon:"\uD83D\uDD00",label:"PR",prompt:"Create and review pull request. Ensure all checks pass and merge."},pr_review:{icon:"\uD83D\uDC40",label:"PR Review",prompt:"Review the PR. Verify code quality and functionality. Approve or request changes."},merge:{icon:"\uD83D\uDE80",label:"Merge",prompt:"Merge the PR and verify deployment."},done:{icon:"✅",label:"Done",prompt:"Task finished and shipped."}};function n(e){let{task:a,onClick:s,compact:n=!1}=e,o=r[a.status||"queued"],d=a.stage?l[a.stage]:null,i=function(e){let a=new Date(e),s=Math.floor((new Date().getTime()-a.getTime())/1e3);return s<60?"just now":s<3600?"".concat(Math.floor(s/60),"m"):s<86400?"".concat(Math.floor(s/3600),"h"):"".concat(Math.floor(s/86400),"d")}(a.created_at);return n?(0,t.jsx)("div",{onClick:s,role:"button",tabIndex:0,onKeyDown:e=>"Enter"===e.key&&(null==s?void 0:s()),className:"group relative p-3 rounded-lg bg-[var(--card-bg)] border \n ".concat("failed"===a.status?"border-[var(--status-failed)] bg-[var(--status-failed-bg)]":"border-[var(--card-border)]","\n hover:border-[color-mix(in_srgb,var(--primary)_40%,var(--card-border))] \n hover:shadow-[var(--shadow-md)] \n transition-all duration-200 cursor-pointer\n focus-visible:outline-2 focus-visible:outline-[var(--ring)] focus-visible:outline-offset-2"),children:(0,t.jsxs)("div",{className:"flex items-center gap-3",children:[(0,t.jsx)("div",{className:"w-2 h-2 rounded-full ".concat(o.dotColor," flex-shrink-0")}),(0,t.jsx)("div",{className:"flex-1 min-w-0",children:(0,t.jsx)("h3",{className:"text-sm font-medium text-[var(--foreground)] truncate group-hover:text-[var(--primary)] transition-colors",children:a.title||"Untitled Task"})}),"failed"===a.status?(0,t.jsx)("span",{className:"text-xs text-[var(--status-failed)]",title:a.error,children:"⚠️"}):d&&(0,t.jsx)("span",{className:"text-xs opacity-60 flex-shrink-0",children:d.icon})]})}):(0,t.jsx)("div",{onClick:s,role:"button",tabIndex:0,onKeyDown:e=>"Enter"===e.key&&(null==s?void 0:s()),className:"group relative p-4 rounded-lg bg-[var(--card-bg)] border \n ".concat("failed"===a.status?"border-[var(--status-failed)] shadow-[0_0_0_1px_var(--status-failed)]":"border-[var(--card-border)]","\n hover:border-[var(--primary)] \n hover:shadow-sm\n transition-all duration-200 cursor-pointer\n focus-visible:outline-2 focus-visible:outline-[var(--ring)] focus-visible:outline-offset-2\n animate-fade-in-up"),children:(0,t.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,t.jsxs)("div",{className:"flex justify-between items-start gap-2",children:[(0,t.jsx)("h3",{className:"text-base font-semibold text-[var(--foreground)] leading-snug group-hover:text-[var(--primary)] transition-colors line-clamp-3",children:a.title||"Untitled Task"}),"failed"===a.status&&(0,t.jsx)("span",{className:"text-xs px-1.5 py-0.5 rounded bg-[var(--status-failed-bg)] text-[var(--status-failed)] font-bold border border-[var(--status-failed)]",children:"FAILED"})]}),(0,t.jsxs)("div",{className:"flex items-center gap-3 text-xs text-[var(--muted-foreground)] mt-1",children:[void 0!==a.priority&&(0,t.jsxs)("span",{className:"font-mono font-medium ".concat(0===a.priority?"text-[var(--primary)]":""),children:["P",a.priority]}),(0,t.jsx)("span",{className:"w-0.5 h-0.5 rounded-full bg-[var(--muted-foreground)] opacity-50"}),(0,t.jsx)("span",{className:"truncate max-w-[100px]",children:a.project||"No Project"}),(0,t.jsx)("span",{className:"w-0.5 h-0.5 rounded-full bg-[var(--muted-foreground)] opacity-50"}),(0,t.jsx)("span",{className:"capitalize",children:a.swarm?"Swarm":a.provider||a.engine||"No Provider"}),(0,t.jsx)("span",{className:"w-0.5 h-0.5 rounded-full bg-[var(--muted-foreground)] opacity-50"}),(0,t.jsx)("span",{children:i})]})]})})}let o={in_progress:{title:"In Progress",icon:"\uD83D\uDD04",color:"var(--status-in-progress)",description:"Currently being worked on by the daemon"},blocked:{title:"Blocked",icon:"\uD83D\uDEA7",color:"var(--status-blocked)",description:"Waiting for input or resolution"},queued:{title:"Queued",icon:"\uD83D\uDCCB",color:"var(--status-queued)",description:"Ready to be picked up"},completed:{title:"Completed",icon:"✅",color:"var(--status-completed)",description:"Successfully finished"}};function d(e){let{tasks:a,onSelectTask:s}=e;if(0===a.length)return(0,t.jsxs)("div",{className:"text-center py-20 animate-fade-in",children:[(0,t.jsx)("div",{className:"inline-flex items-center justify-center w-16 h-16 rounded-2xl bg-[var(--card-bg)] border border-[var(--card-border)] mb-4",children:(0,t.jsx)("span",{className:"text-3xl",children:"\uD83D\uDCCB"})}),(0,t.jsx)("h3",{className:"text-lg font-semibold mb-2",children:"No tasks yet"}),(0,t.jsx)("p",{className:"text-[var(--muted-foreground)] text-sm max-w-md mx-auto",children:"Create your first task to get started. Tasks will appear here organized by status."})]});let r=a.filter(e=>"in_progress"===e.status),l=a.filter(e=>"queued"===e.status),d=a.filter(e=>"blocked"===e.status),i=a.filter(e=>"completed"===e.status||"failed"===e.status),c=(e,a)=>{if(0===a.length)return null;let r=o[e];return(0,t.jsxs)("section",{className:"mb-8 animate-fade-in-up",children:[(0,t.jsxs)("div",{className:"flex items-center gap-3 mb-4",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2 px-3 py-1.5 rounded-lg",style:{backgroundColor:"color-mix(in srgb, ".concat(r.color," 10%, transparent)")},children:[(0,t.jsx)("span",{className:"text-lg",children:r.icon}),(0,t.jsx)("h3",{className:"text-sm font-semibold",style:{color:r.color},children:r.title}),(0,t.jsx)("span",{className:"px-2 py-0.5 rounded-full text-xs font-medium",style:{backgroundColor:"color-mix(in srgb, ".concat(r.color," 15%, transparent)"),color:r.color},children:a.length})]}),(0,t.jsx)("p",{className:"text-xs text-[var(--muted-foreground)] hidden sm:block",children:r.description})]}),(0,t.jsx)("div",{className:"grid gap-3 sm:grid-cols-2 lg:grid-cols-3",children:a.map((e,a)=>(0,t.jsx)("div",{className:"animate-fade-in-up",style:{animationDelay:"".concat(50*a,"ms")},children:(0,t.jsx)(n,{task:e,onClick:()=>null==s?void 0:s(e)})},e.id))})]})};return(0,t.jsxs)("div",{children:[c("in_progress",r),c("blocked",d),c("queued",l),c("completed",i)]})}},4647:(e,a,s)=>{"use strict";s.d(a,{A:()=>i,AuthProvider:()=>d});var t=s(5155),r=s(2115),l=s(1483),n=s(5704);let o=(0,r.createContext)({user:null,loading:!0,signOut:async()=>{}});function d(e){let{children:a}=e,s="1"===n.env.NEXT_PUBLIC_AGX_BOARD_DISABLE_AUTH,[d,i]=(0,r.useState)(null),[c,u]=(0,r.useState)(!0);(0,r.useEffect)(()=>{if(s){i({id:n.env.NEXT_PUBLIC_AGX_BOARD_USER_ID||"00000000-0000-0000-0000-000000000001",email:n.env.NEXT_PUBLIC_AGX_BOARD_USER_EMAIL||"local@agx.board",user_metadata:{name:n.env.NEXT_PUBLIC_AGX_BOARD_USER_NAME||"Local Board User",full_name:n.env.NEXT_PUBLIC_AGX_BOARD_USER_NAME||"Local Board User"},app_metadata:{},aud:"authenticated",created_at:new Date().toISOString()}),u(!1);return}let e=(0,l.O)();e.auth.getSession().then(e=>{var a,s;i(null!=(s=null==(a=e.data.session)?void 0:a.user)?s:null),u(!1)});let{data:{subscription:a}}=e.auth.onAuthStateChange((e,a)=>{var s;i(null!=(s=null==a?void 0:a.user)?s:null),u(!1)});return()=>a.unsubscribe()},[s]);let m=async()=>{if(s)return;let e=(0,l.O)();await e.auth.signOut(),i(null)};return(0,t.jsx)(o.Provider,{value:{user:d,loading:c,signOut:m},children:a})}function i(){return(0,r.useContext)(o)}},9620:(e,a,s)=>{Promise.resolve().then(s.bind(s,415))}},e=>{e.O(0,[5004,277,2619,650,9027,9719,2456,9337,8441,1255,7358],()=>e(e.s=9620)),_N_E=e.O()}]);
1
+ (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[5105],{63:(e,a,s)=>{"use strict";var t=s(7260);s.o(t,"usePathname")&&s.d(a,{usePathname:function(){return t.usePathname}}),s.o(t,"useRouter")&&s.d(a,{useRouter:function(){return t.useRouter}}),s.o(t,"useSearchParams")&&s.d(a,{useSearchParams:function(){return t.useSearchParams}})},415:(e,a,s)=>{"use strict";s.r(a),s.d(a,{default:()=>f});var t=s(5155),r=s(2115),l=s(63),n=s(1460),o=s(2888),d=s(6779),i=s(2835),c=s(5826),u=s(2325),m=s(8545);function x(e){let{onClose:a,workflowId:s}=e,{workflow:l,isLoading:n,refetch:o}=(0,u.mP)({workflowId:s}),{providers:d}=(0,m.u)(),[i,c]=(0,r.useState)([]),[x,p]=(0,r.useState)(null),[h,v]=(0,r.useState)(!1),[g,b]=(0,r.useState)({}),f=e=>u.ls[e]||{icon:"\uD83D\uDCCC",label:e.charAt(0).toUpperCase()+e.slice(1),color:"var(--primary)"};(0,r.useEffect)(()=>{let e=(Array.isArray(null==l?void 0:l.nodes)?l.nodes:[]).slice().sort((e,a)=>(e.position||0)-(a.position||0)).map(e=>{var a,s;return{id:e.id,name:e.name,label:e.label||e.name,prompt:e.prompt||"",provider:e.provider||"codex",model:e.model||"",swarm:!!(null==e||null==(a=e.metadata)?void 0:a.swarm),swarm_models:Array.isArray(null==e||null==(s=e.metadata)?void 0:s.swarm_models)?e.metadata.swarm_models:[],metadata:(null==e?void 0:e.metadata)&&"object"==typeof e.metadata?e.metadata:{}}});c(e),b({}),p(a=>a&&e.some(e=>e.id===a)?a:e.length?e[0].id:null)},[null==l?void 0:l.id,null==l?void 0:l.nodes]);let j=i.findIndex(e=>e.id===x),w=j>=0?i[j]:null,N=w?{...w,...g[w.id]||{}}:null,y=(e,a)=>{w&&b(s=>({...s,[w.id]:{...s[w.id]||{},[e]:a}}))},k=async()=>{if(l){v(!0);try{let e=i.map(e=>{let a={...e,...g[e.id]||{}};return{...a,metadata:{...a.metadata||{},swarm:!!a.swarm,swarm_models:a.swarm_models||[]}}}),s=await fetch("/api/workflows/".concat(l.id,"/nodes"),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({nodes:e.map(e=>({id:e.id,prompt:e.prompt,provider:e.provider,model:e.model,metadata:e.metadata}))})});if(!s.ok)throw Error("Failed to save workflow");await s.json(),o(),b({}),a()}catch(e){console.error("Error saving workflow:",e)}finally{v(!1)}}};return n&&!l?(0,t.jsx)("div",{className:"modal-backdrop p-4 flex items-center justify-center",children:(0,t.jsx)("span",{className:"spinner w-8 h-8 border-2 border-white/20 border-t-white"})}):(0,t.jsx)("div",{className:"modal-backdrop p-4",onClick:e=>e.target===e.currentTarget&&a(),children:(0,t.jsxs)("div",{className:"modal-content w-full max-w-5xl h-[85vh] flex flex-col animate-scale-in p-0 bg-[var(--card-bg)] overflow-hidden rounded-xl border border-[var(--card-border)] shadow-2xl",children:[(0,t.jsxs)("div",{className:"px-6 py-4 border-b border-[var(--border)] flex items-center justify-between bg-[var(--background)]",children:[(0,t.jsxs)("div",{children:[(0,t.jsxs)("h2",{className:"text-lg font-bold flex items-center gap-2",children:[(0,t.jsx)("span",{children:"⚙️"})," Workflow Configuration"]}),(0,t.jsxs)("p",{className:"text-xs text-[var(--muted-foreground)] mt-0.5",children:["Editing: ",(0,t.jsx)("span",{className:"font-mono text-[var(--foreground)]",children:(null==l?void 0:l.name)||"Loading..."})]})]}),(0,t.jsx)("button",{onClick:a,className:"btn-ghost p-2 rounded",children:(0,t.jsx)("svg",{className:"w-5 h-5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,t.jsxs)("div",{className:"flex flex-1 overflow-hidden",children:[(0,t.jsxs)("div",{className:"w-64 bg-[var(--muted)]/30 border-r border-[var(--border)] overflow-y-auto p-4 flex flex-col gap-1",children:[(0,t.jsx)("div",{className:"flex items-center justify-between mb-2 px-2",children:(0,t.jsx)("span",{className:"text-xs font-bold uppercase tracking-wider text-[var(--muted-foreground)]",children:"Steps"})}),0===i.length&&(0,t.jsx)("div",{className:"text-sm text-[var(--muted-foreground)] px-2 italic",children:"No steps defined in this workflow."}),i.map(e=>{let a=f(e.name),s=!!g[e.id];return(0,t.jsxs)("button",{onClick:()=>p(e.id),className:"w-full text-left px-3 py-2.5 rounded-lg text-sm font-medium transition-all flex items-center gap-3 ".concat(x===e.id?"bg-[var(--card-bg)] text-[var(--foreground)] shadow-sm border border-[var(--border)]":"text-[var(--muted-foreground)] hover:bg-[var(--card-bg)]/50"),children:[(0,t.jsx)("span",{className:"text-base",children:a.icon}),(0,t.jsx)("span",{className:"flex-1 truncate",children:e.label||a.label}),s&&(0,t.jsx)("span",{className:"w-1.5 h-1.5 rounded-full bg-[var(--accent)]"})]},e.id)})]}),(0,t.jsxs)("div",{className:"flex-1 overflow-y-auto p-8 relative bg-[var(--card-bg)]",children:[N?(0,t.jsxs)("div",{className:"max-w-3xl mx-auto space-y-8 animate-fade-in",children:[(0,t.jsxs)("div",{className:"flex items-center gap-4 pb-6 border-b border-[var(--border)]",children:[(0,t.jsx)("div",{className:"w-12 h-12 rounded-xl bg-[var(--muted)]/50 flex items-center justify-center text-2xl shadow-inner",children:f(N.name).icon}),(0,t.jsxs)("div",{children:[(0,t.jsx)("h3",{className:"text-xl font-bold",children:N.label}),(0,t.jsxs)("p",{className:"text-sm text-[var(--muted-foreground)] font-mono opacity-70",children:["ID: ",N.id," • Key: ",N.name]})]})]}),(0,t.jsxs)("div",{className:"space-y-3",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between",children:[(0,t.jsx)("label",{className:"text-sm font-semibold uppercase tracking-wider text-[var(--muted-foreground)]",children:"System Prompt"}),(0,t.jsx)("span",{className:"text-xs text-[var(--muted-foreground)] bg-[var(--muted)]/50 px-2 py-0.5 rounded",children:"Markdown Supported"})]}),(0,t.jsx)("textarea",{value:N.prompt||"",onChange:e=>y("prompt",e.target.value),className:"input w-full h-64 font-mono text-sm leading-relaxed resize-y p-4",placeholder:"Define the agent's behavior, constraints, and output format for this stage..."})]}),(0,t.jsxs)("div",{className:"p-6 rounded-xl bg-[var(--muted)]/20 border border-[var(--border)] space-y-6",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between",children:[(0,t.jsxs)("h4",{className:"font-semibold flex items-center gap-2",children:[(0,t.jsx)("span",{children:"\uD83E\uDD16"})," Model Settings"]}),(0,t.jsxs)("div",{className:"flex items-center gap-3 bg-[var(--card-bg)] px-3 py-1.5 rounded-lg border border-[var(--border)]",children:[(0,t.jsx)("span",{className:"text-sm font-medium",children:"Swarm Mode"}),(0,t.jsx)("button",{onClick:()=>y("swarm",!N.swarm),className:"w-9 h-5 rounded-full transition-colors relative ".concat(N.swarm?"bg-[var(--primary)]":"bg-[var(--muted-foreground)]/30"),children:(0,t.jsx)("span",{className:"absolute top-0.5 left-0.5 w-4 h-4 bg-white rounded-full transition-transform ".concat(N.swarm?"translate-x-4":"translate-x-0")})})]})]}),N.swarm?(0,t.jsxs)("div",{className:"space-y-4 animate-fade-in",children:[(0,t.jsxs)("div",{className:"flex justify-between items-center",children:[(0,t.jsx)("span",{className:"text-sm font-medium text-[var(--muted-foreground)]",children:"Swarm Models"}),(0,t.jsx)("button",{onClick:()=>{y("swarm_models",[...N.swarm_models||[],{provider:"gemini",model:""}])},className:"btn-secondary text-xs px-2 py-1",children:"+ Add Model"})]}),(0,t.jsxs)("div",{className:"space-y-2",children:[0===(N.swarm_models||[]).length&&(0,t.jsx)("div",{className:"text-center py-8 border-2 border-dashed border-[var(--border)] rounded-lg text-sm text-[var(--muted-foreground)]",children:"No models configured for swarm. Add one to enable."}),(N.swarm_models||[]).map((e,a)=>(0,t.jsxs)("div",{className:"flex gap-2 items-center group",children:[(0,t.jsx)("select",{value:e.provider,onChange:e=>{let s=[...N.swarm_models||[]];s[a].provider=e.target.value,y("swarm_models",s)},className:"input text-sm py-1.5 w-32",children:d.map(e=>(0,t.jsx)("option",{value:e.id,children:e.label},e.id))}),(0,t.jsx)("input",{value:e.model,onChange:e=>{let s=[...N.swarm_models||[]];s[a].model=e.target.value,y("swarm_models",s)},placeholder:"Model name (e.g. gemini-1.5-pro)",className:"input text-sm py-1.5 flex-1"}),(0,t.jsx)("button",{onClick:()=>{y("swarm_models",(N.swarm_models||[]).filter((e,s)=>s!==a))},className:"text-[var(--muted-foreground)] hover:text-[var(--destructive)] hover:bg-[var(--destructive)]/10 p-1.5 rounded opacity-0 group-hover:opacity-100 transition-all",children:"✕"})]},a))]})]}):(0,t.jsxs)("div",{className:"grid grid-cols-2 gap-4 animate-fade-in",children:[(0,t.jsxs)("div",{className:"space-y-1.5",children:[(0,t.jsx)("label",{className:"text-xs font-semibold text-[var(--muted-foreground)] uppercase",children:"Provider"}),(0,t.jsx)("select",{value:N.provider||"gemini",onChange:e=>y("provider",e.target.value),className:"input w-full text-sm py-2",children:d.map(e=>(0,t.jsx)("option",{value:e.id,children:e.label},e.id))})]}),(0,t.jsxs)("div",{className:"space-y-1.5",children:[(0,t.jsx)("label",{className:"text-xs font-semibold text-[var(--muted-foreground)] uppercase",children:"Model"}),(0,t.jsx)("input",{value:N.model||"",onChange:e=>y("model",e.target.value),placeholder:"e.g. gemini-2.0-flash",className:"input w-full text-sm py-2"})]})]})]})]}):null,!w&&i.length>0&&(0,t.jsxs)("div",{className:"flex flex-col items-center justify-center h-full text-[var(--muted-foreground)]",children:[(0,t.jsx)("span",{className:"text-4xl mb-4 opacity-30",children:"\uD83D\uDC48"}),(0,t.jsx)("p",{children:"Select a step from the sidebar to configure it."})]})]})]}),(0,t.jsxs)("div",{className:"px-6 py-4 border-t border-[var(--border)] bg-[var(--background)] flex justify-end gap-3",children:[(0,t.jsx)("button",{onClick:a,className:"btn-ghost px-4 py-2",children:"Cancel"}),(0,t.jsxs)("button",{onClick:k,disabled:h||0===Object.keys(g).length,className:"btn-primary px-6 py-2 flex items-center gap-2",children:[h&&(0,t.jsx)("span",{className:"spinner w-4 h-4 border-2 border-white/20 border-t-white"}),h?"Saving...":"Save Changes"]})]})]})})}var p=s(577),h=s(91);function v(){return(0,t.jsxs)("div",{className:"p-4 rounded-xl bg-[var(--card-bg)] border border-[var(--card-border)]",children:[(0,t.jsxs)("div",{className:"flex items-start justify-between mb-3",children:[(0,t.jsxs)("div",{className:"flex-1",children:[(0,t.jsxs)("div",{className:"flex gap-2 mb-2",children:[(0,t.jsx)("div",{className:"skeleton h-4 w-8 rounded"}),(0,t.jsx)("div",{className:"skeleton h-4 w-16 rounded"})]}),(0,t.jsx)("div",{className:"skeleton h-5 w-3/4 rounded"})]}),(0,t.jsx)("div",{className:"skeleton h-5 w-20 rounded-full"})]}),(0,t.jsxs)("div",{className:"flex justify-between",children:[(0,t.jsx)("div",{className:"skeleton h-4 w-24 rounded"}),(0,t.jsx)("div",{className:"skeleton h-4 w-12 rounded"})]})]})}function g(){return(0,t.jsx)("div",{className:"flex gap-4 overflow-x-auto pb-4 px-4",children:[1,2,3,4,5].map(e=>(0,t.jsxs)("div",{className:"flex-shrink-0 w-72 kanban-column",children:[(0,t.jsx)("div",{className:"kanban-column-header",children:(0,t.jsxs)("div",{className:"flex items-center justify-between",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)("div",{className:"skeleton h-6 w-6 rounded"}),(0,t.jsx)("div",{className:"skeleton h-5 w-20 rounded"})]}),(0,t.jsx)("div",{className:"skeleton h-5 w-6 rounded-full"})]})}),(0,t.jsx)("div",{className:"p-2 space-y-2",children:[1,2].map(e=>(0,t.jsxs)("div",{className:"p-3 rounded-lg bg-[var(--background)] border-l-2 border-[var(--card-border)]",children:[(0,t.jsx)("div",{className:"skeleton h-3 w-12 rounded mb-2"}),(0,t.jsx)("div",{className:"skeleton h-4 w-full rounded mb-2"}),(0,t.jsx)("div",{className:"skeleton h-3 w-20 rounded"})]},e))})]},e))})}function b(){let e=(0,l.useRouter)(),a=(0,l.useSearchParams)(),s=(0,l.usePathname)(),b=(null==a?void 0:a.get("project"))||void 0,f=a.get("view")||"kanban",j=a.get("sort")||"newest",[w,N]=(0,r.useState)(f),[y,k]=(0,r.useState)(j),[C,_]=(0,r.useState)("all"),[S,A]=(0,r.useState)(""),[T,D]=(0,r.useState)(null),[E,P]=(0,r.useState)(!1),[L,R]=(0,r.useState)(null),[M,I]=(0,r.useState)(!1),[B,q]=(0,r.useState)(""),[U,F]=(0,r.useState)(!1),[O,X]=(0,r.useState)("single"),[z,W]=(0,r.useState)("gemini"),[G,V]=(0,r.useState)(""),[K,Q]=(0,r.useState)([]),[H,Y]=(0,r.useState)("gemini"),[J,Z]=(0,r.useState)(""),[$,ee]=(0,r.useState)(null),[ea,es]=(0,r.useState)(!1),[et,er]=(0,r.useState)(!1),[el,en]=(0,r.useState)(null),{providers:eo}=(0,m.u)();(0,r.useEffect)(()=>{let e=e=>{let a=e.target,s=["INPUT","TEXTAREA","SELECT"].includes(a.tagName)||a.isContentEditable;if("n"!==e.key||s||(e.preventDefault(),I(!0)),"/"===e.key&&!s){var t;e.preventDefault(),null==(t=document.getElementById("task-search"))||t.focus()}};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[]);let{tasks:ed,isLoading:ei,createTask:ec,updateTask:eu,deleteTask:em,completeTaskStage:ex,cancelWorkflow:ep,refetch:eh,cancellingTaskId:ev,fetchTask:eg}=(0,p.si)({realtime:!0,project:b}),{projects:eb,isLoading:ef}=(0,h.Y)(),{comments:ej,addComment:ew,deleteComment:eN}=(0,p.LU)((null==T?void 0:T.id)||null),{learnings:ey,addLearning:ek}=(0,p.dF)((null==T?void 0:T.id)||void 0),{workflow:eC,stages:e_,stageConfig:eS,isValidTransition:eA,isLoading:eT}=(0,u.mP)(),eD=(0,r.useMemo)(()=>e_.map(e=>{var a;let s=eS[e],t=null==eC||null==(a=eC.nodes)?void 0:a.find(a=>a.name===e);return{id:e,label:(null==s?void 0:s.label)||e,icon:(null==s?void 0:s.icon)||"\uD83D\uDCCC",color:(null==s?void 0:s.color)||"var(--primary)",prompt:(null==t?void 0:t.prompt)||void 0}}),[e_,eS,eC]),eE=t=>{N(t);let r=new URLSearchParams(a);r.set("view",t),e.push("".concat(s,"?").concat(r.toString()))},eP=(0,r.useMemo)(()=>{let e=[...ed];if(S){let a=S.toLowerCase();e=e.filter(e=>{var s,t,r;return(null==(s=e.title)?void 0:s.toLowerCase().includes(a))||(null==(t=e.description)?void 0:t.toLowerCase().includes(a))||e.id.toLowerCase().includes(a)||(null==(r=e.project)?void 0:r.toLowerCase().includes(a))})}return"all"!==C&&(e="active"===C?e.filter(e=>"completed"!==e.status&&"failed"!==e.status):e.filter(e=>e.status===C)),e.sort((e,a)=>{switch(y){case"newest":return new Date(a.created_at).getTime()-new Date(e.created_at).getTime();case"oldest":return new Date(e.created_at).getTime()-new Date(a.created_at).getTime();case"priority":return(e.priority||0)-(a.priority||0);case"updated":return new Date(a.updated_at).getTime()-new Date(e.updated_at).getTime();default:return 0}}),e},[ed,S,C,y]),eL=(0,r.useCallback)(async(e,a)=>{a&&D(a);try{let a=await eg(e);return D(a),a}catch(e){return console.error("Failed to load task details:",e),a||D(null),null!=a?a:null}},[eg]),eR=(0,r.useCallback)(async e=>{await eL(e.id,e)},[eL]),eM=(0,r.useCallback)(e=>{D(null),er(!1),en(e)},[]),eG=(0,r.useCallback)(async(e,a)=>{var s;er(!0);let t=(null==eS||null==(s=eS[a])?void 0:s.label)||a,r=e.split("\n")[0].replace(/^#\s*/,"")||"New Task (".concat(t,")"),l=["status: ".concat("ideation"===a?"queued":"in_progress"),"stage: ".concat(a)],d=$||(b?null==(s=eb.find(e=>e.slug===b))?void 0:s.id:null);if(d){let e=eb.find(e=>e.id===d);e&&(l.push("project: ".concat(e.slug)),l.push("project_id: ".concat(e.id)),l.push("workflow_id: ".concat(e.workflow_id||u.ou)))}let c="---\n".concat(l.join("\n"),"\n---\n\n# ").concat(r,"\n\n").concat(e);try{let e=await ec(c,null);en(null),await eL(e.id,e)}catch(e){console.error("Failed to create task:",e)}finally{er(!1)}},[ec,eL,eS,eb,b,$]),eI=(0,r.useCallback)(async(e,a)=>{await eu(e,a)},[eu]),eB=async e=>{let a=ed.find(a=>a.id===e);R(null);try{var s;await ep({taskId:e}),await eh(),R({type:"success",message:"Cancellation requested for ".concat((null==a?void 0:a.title)||(null==a||null==(s=a.content)?void 0:s.slice(0,30))||e,".")})}catch(t){console.error("Failed to stop task",t);let s=t instanceof Error?t.message:"unknown error";R({type:"error",message:"Unable to stop ".concat((null==a?void 0:a.title)||e,": ").concat(s,".")})}},eq=async e=>{try{await ex({taskId:e,decision:"not_done",final_result:"Manual retry requested.",explanation:"Manual retry requested."})}catch(e){console.error("Failed to retry task",e)}};(0,r.useEffect)(()=>{if(!L)return;let e=setTimeout(()=>R(null),5e3);return()=>clearTimeout(e)},[L]);let eU=async()=>{if(B.trim()&&!U){F(!0);try{var e;let a=["status: queued","stage: ideation"];"single"!==O&&a.push("swarm: true");let s=$||(b?null==(e=eb.find(e=>e.slug===b))?void 0:e.id:null);if(s){let e=eb.find(e=>e.id===s);e&&(a.push("project: ".concat(e.slug)),a.push("project_id: ".concat(e.id)),a.push("workflow_id: ".concat(e.workflow_id||u.ou)))}let t="---\n".concat(a.join("\n"),"\n---\n\n# ").concat(B,"\n");await ec(t,"swarm"===O?K:null),q(""),X("single"),W("gemini"),V(""),Q([]),Y("gemini"),Z(""),I(!1),ee(null)}catch(e){console.error("Failed to create task:",e)}finally{F(!1)}}},eF=async(e,a)=>{let s="---\n".concat(["status: ".concat("ideation"===a?"queued":"in_progress"),"stage: ".concat(a)].join("\n"),"\n---\n\n# ").concat(e,"\n");await ec(s,null),es(!1)},eO=async e=>{T&&await ew(e)},eX=async(e,a,s)=>{var t,r;let l=(null==T||null==(r=T.project_context)||null==(t=r.project)?void 0:t.id)||(null==T?void 0:T.project_id)||(null==T?void 0:T.project)||void 0,n=null!=s?s:"global"===a?void 0:"task"===a?null==T?void 0:T.id:l;await ek(e,a,n)},ez=async e=>{T&&(D(a=>a?{...a,...e}:null),await eu(T.id,e))};return(ed.length,ed.filter(e=>"in_progress"===e.status).length,ed.filter(e=>"queued"===e.status).length,ed.filter(e=>"completed"===e.status).length,(ei||eT)&&0===ed.length)?(0,t.jsxs)("div",{className:"h-full flex flex-col p-6 animate-pulse",children:[(0,t.jsxs)("div",{className:"flex justify-between items-center mb-8",children:[(0,t.jsx)("div",{className:"h-8 w-48 bg-[var(--card-border)] rounded"}),(0,t.jsx)("div",{className:"h-10 w-32 bg-[var(--card-border)] rounded"})]}),(0,t.jsx)("div",{className:"h-12 w-full bg-[var(--card-border)] rounded mb-8"}),"kanban"===w?(0,t.jsx)(g,{}):(0,t.jsx)("div",{className:"space-y-4",children:[1,2,3].map(e=>(0,t.jsx)(v,{},e))})]}):(0,t.jsx)(n.A,{fullWidth:!0,noFooter:!0,children:(0,t.jsxs)("div",{className:"flex flex-col h-full ".concat("kanban"===w?"max-w-full":"max-w-6xl mx-auto w-full px-4"),children:[(0,t.jsxs)("div",{className:"relative flex items-center justify-center gap-4 py-3 px-4 border-b border-[var(--border)] bg-[var(--background)] flex-shrink-0 z-20",children:[(0,t.jsxs)("div",{className:"flex items-center gap-4",children:[(0,t.jsxs)("div",{className:"relative w-80",children:[(0,t.jsx)("div",{className:"absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none",children:(0,t.jsx)("svg",{className:"h-5 w-5 text-gray-400",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:(0,t.jsx)("path",{fillRule:"evenodd",d:"M9 3.5a5.5 5.5 0 100 11 5.5 5.5 0 000-11zM2 9a7 7 0 1112.452 4.391l3.328 3.329a.75.75 0 11-1.06 1.06l-3.329-3.328A7 7 0 012 9z",clipRule:"evenodd"})})}),(0,t.jsx)("input",{id:"task-search",type:"text",placeholder:"Search tasks... (/)",className:"block w-full rounded-md border-0 py-1.5 pl-10 text-gray-900 ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6 bg-white shadow-sm",value:S,onChange:e=>A(e.target.value)})]}),(0,t.jsxs)("div",{className:"flex items-center bg-gray-100 p-1 rounded-lg border border-gray-200",children:[(0,t.jsx)("button",{onClick:()=>eE("list"),className:"px-3 py-1 text-xs font-medium rounded transition-all ".concat("list"===w?"bg-white shadow-sm text-gray-900":"text-gray-500 hover:text-gray-700"),children:"List"}),(0,t.jsx)("button",{onClick:()=>eE("kanban"),className:"px-3 py-1 text-xs font-medium rounded transition-all ".concat("kanban"===w?"bg-white shadow-sm text-gray-900":"text-gray-500 hover:text-gray-700"),children:"Board"})]}),(0,t.jsxs)("button",{onClick:()=>P(!0),className:"flex items-center gap-2 px-3 py-1.5 text-xs font-medium text-gray-700 bg-white border border-gray-200 rounded-lg shadow-sm hover:bg-gray-50 transition-all",title:"Configure Workflow",children:[(0,t.jsx)("span",{className:"text-base leading-none",children:"⚙️"}),(0,t.jsx)("span",{children:"Workflow"})]})]}),(0,t.jsx)("div",{className:"absolute right-4 flex items-center gap-3"})]}),L&&(0,t.jsx)("div",{className:"px-4 mt-3",children:(0,t.jsx)("div",{role:"status",className:"rounded-xl px-4 py-2 text-xs font-semibold ".concat("success"===L.type?"bg-[var(--success-muted)] text-[var(--success)]":"bg-[var(--destructive-muted)] text-[var(--destructive)]"),children:L.message})}),(0,t.jsx)("div",{className:"flex-shrink-0 mt-2 px-4",children:(0,t.jsx)(i.A,{tasks:ed,onTaskClick:D,onStop:eB,onRetry:eq,cancellingTaskId:ev})}),(0,t.jsx)("div",{className:"flex-1 min-h-0 overflow-hidden flex flex-col pt-2",children:"list"===w?(0,t.jsx)("div",{className:"overflow-y-auto h-full px-4",children:(0,t.jsx)(o.A,{tasks:eP,onSelectTask:eR})}):(0,t.jsx)(d.A,{tasks:eP,onSelectTask:eR,onTasksChange:()=>{},onTaskUpdate:eI,onAddTask:eM,stages:e_,stageConfig:eS,isValidTransition:eA,isCreatingTask:et,creatingStage:el})}),T&&(0,t.jsx)(c.A,{task:T,comments:T?ej:[],learnings:ey,projectContext:T.project_context,projects:eb,stages:eD,onClose:()=>D(null),onAddComment:eO,onDeleteComment:eN,onAddLearning:eX,onUpdate:ez,onDelete:async()=>{await em(T.id),D(null)}}),el&&(0,t.jsx)(c.A,{task:{id:"draft",title:"",description:"",content:"",stage:el,status:"ideation"===el?"queued":"in_progress",created_at:new Date().toISOString()},comments:[],learnings:[],projectContext:null,projects:eb,stages:eD,isDraft:!0,isCreating:et,onClose:()=>{en(null),er(!1)},onAddComment:()=>{},onAddLearning:()=>{},onUpdate:async e=>{(e.description||e.title)&&await eG(e.description||e.title||"",e.stage||el)}}),ea&&(0,t.jsx)("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50",children:(0,t.jsxs)("div",{className:"bg-[var(--card-bg)] p-6 rounded-xl w-full max-w-md shadow-2xl border border-[var(--card-border)] animate-scale-in",children:[(0,t.jsx)("h3",{className:"text-lg font-bold mb-4",children:"New Task"}),(0,t.jsxs)("form",{onSubmit:e=>{e.preventDefault();let a=e.target;eF(a.elements.namedItem("title").value,a.elements.namedItem("stage").value)},children:[(0,t.jsx)("input",{name:"title",autoFocus:!0,placeholder:"Task title...",className:"w-full mb-4 px-3 py-2 bg-[var(--background)] border border-[var(--card-border)] rounded focus:border-[var(--primary)] outline-none",required:!0}),(0,t.jsx)("select",{name:"stage",className:"w-full mb-6 px-3 py-2 bg-[var(--background)] border border-[var(--card-border)] rounded focus:border-[var(--primary)] outline-none",children:e_.map(e=>{var a;return(0,t.jsx)("option",{value:e,children:(null==(a=eS[e])?void 0:a.label)||e},e)})}),(0,t.jsxs)("div",{className:"flex justify-end gap-2",children:[(0,t.jsx)("button",{type:"button",onClick:()=>es(!1),className:"btn-ghost",children:"Cancel"}),(0,t.jsx)("button",{type:"submit",className:"btn-primary",children:"Create Task"})]})]})]})}),E&&(0,t.jsx)(x,{onClose:()=>P(!1),workflowId:null==eC?void 0:eC.id}),M&&(0,t.jsx)("div",{className:"modal-backdrop p-4",onClick:e=>e.target===e.currentTarget&&I(!1),children:(0,t.jsxs)("div",{className:"modal-content w-full max-w-lg p-6 animate-scale-in",children:[(0,t.jsxs)("h2",{className:"text-xl font-bold mb-4 flex items-center gap-2",children:[(0,t.jsx)("span",{children:"✨"})," New Task"]}),(0,t.jsxs)("div",{className:"flex items-center gap-2 mb-4",children:[(0,t.jsx)("button",{onClick:()=>X("single"),className:"px-3 py-1.5 text-xs font-semibold rounded-md uppercase tracking-wide transition-all ".concat("single"===O?"bg-[var(--card-bg)] text-[var(--primary)] shadow-sm border border-[var(--border)]":"text-[var(--muted-foreground)] hover:text-[var(--foreground)] border border-transparent"),children:"Single Agent"}),(0,t.jsx)("button",{onClick:()=>X("swarm"),className:"px-3 py-1.5 text-xs font-semibold rounded-md uppercase tracking-wide transition-all ".concat("swarm"===O?"bg-[var(--card-bg)] text-[var(--primary)] shadow-sm border border-[var(--border)]":"text-[var(--muted-foreground)] hover:text-[var(--foreground)] border border-transparent"),children:"Swarm"})]}),(0,t.jsx)("textarea",{value:B,onChange:e=>q(e.target.value),placeholder:"Describe what needs to be done...",className:"input h-32 resize-none mb-4",autoFocus:!0,disabled:U}),(0,t.jsxs)("label",{className:"text-xs font-semibold mb-3 block",children:["Attach to project",(0,t.jsxs)("select",{value:null!=$?$:"",onChange:e=>ee(e.target.value||null),className:"input text-sm mt-1",disabled:ef,children:[(0,t.jsxs)("option",{value:"",children:["None (Current: ",b||"All",")"]}),eb.map(e=>(0,t.jsx)("option",{value:e.id,children:e.name},e.id))]})]}),"single"===O?(0,t.jsxs)("div",{className:"grid gap-3 sm:grid-cols-2 mb-4",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"block text-[11px] font-medium text-[var(--muted-foreground)] mb-1",children:"Provider"}),(0,t.jsx)("select",{value:z,onChange:e=>W(e.target.value),className:"input text-xs py-1.5 appearance-none",children:eo.map(e=>(0,t.jsx)("option",{value:e.id,children:e.label},e.id))})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"block text-[11px] font-medium text-[var(--muted-foreground)] mb-1",children:"Model"}),(0,t.jsx)("input",{value:G,onChange:e=>V(e.target.value),placeholder:"e.g. gpt-4.1-mini",className:"input text-xs py-1.5"})]})]}):(0,t.jsx)("div",{className:"mb-4 space-y-3",children:(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"block text-[11px] font-medium text-[var(--muted-foreground)] mb-2",children:"Swarm Models"}),(0,t.jsxs)("div",{className:"grid gap-2",children:[(0,t.jsxs)("div",{className:"grid grid-cols-[1fr_1.2fr_auto] gap-2",children:[(0,t.jsx)("select",{value:H,onChange:e=>Y(e.target.value),className:"input text-xs py-1.5 appearance-none",children:eo.map(e=>(0,t.jsx)("option",{value:e.id,children:e.label},e.id))}),(0,t.jsx)("input",{value:J,onChange:e=>Z(e.target.value),placeholder:"model name",className:"input text-xs py-1.5"}),(0,t.jsx)("button",{type:"button",onClick:()=>{let e=J.trim();if(!e)return;let a={provider:H,model:e};K.some(e=>e.provider.toLowerCase()===a.provider.toLowerCase()&&e.model.toLowerCase()===a.model.toLowerCase())||(Q(e=>[...e,a]),Z(""))},className:"btn-ghost px-3 py-1.5 text-xs",children:"Add"})]}),K.length>0&&(0,t.jsx)("div",{className:"space-y-1",children:K.map((e,a)=>(0,t.jsxs)("div",{className:"flex items-center justify-between px-3 py-1.5 rounded-md border text-xs bg-[var(--background)] border-[var(--border)]",children:[(0,t.jsxs)("span",{className:"truncate",children:[(0,t.jsx)("span",{className:"text-[var(--muted-foreground)]",children:e.provider}),(0,t.jsx)("span",{className:"mx-1",children:"\xb7"}),(0,t.jsx)("span",{children:e.model})]}),(0,t.jsx)("button",{type:"button",onClick:()=>{Q(e=>e.filter((e,s)=>s!==a))},className:"text-[var(--destructive)] hover:underline",children:"Remove"})]},"".concat(e.provider,"-").concat(e.model,"-").concat(a)))})]})]})}),(0,t.jsxs)("div",{className:"flex justify-end gap-3",children:[(0,t.jsx)("button",{onClick:()=>{I(!1),q(""),X("single"),W("gemini"),V(""),Q([]),Y("gemini"),Z("")},disabled:U,className:"btn-ghost px-4 py-2",children:"Cancel"}),(0,t.jsx)("button",{onClick:eU,disabled:!B.trim()||U||"swarm"===O&&0===K.length,className:"btn-primary px-4 py-2 flex items-center gap-2",children:U?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("span",{className:"spinner w-4 h-4 border-2 border-white/20 border-t-white"}),"Creating..."]}):"Create Task"})]})]})})]})})}function f(){return(0,t.jsx)(r.Suspense,{fallback:(0,t.jsx)("div",{className:"p-8",children:"Loading..."}),children:(0,t.jsx)(b,{})})}},1460:(e,a,s)=>{"use strict";s.d(a,{A:()=>m});var t=s(5155),r=s(2619),l=s.n(r),n=s(63),o=s(4647),d=s(91),i=s(2115);function c(e){let{children:a,fullWidth:s=!1,noFooter:r=!1}=e;(0,n.usePathname)(),(0,n.useRouter)();let c=(0,n.useSearchParams)(),{user:u,loading:m,signOut:x}=(0,o.A)(),{projects:p,isLoading:h}=(0,d.Y)(),v=null==c?void 0:c.get("project");return(0,i.useMemo)(()=>v?p.find(e=>e.slug===v):null,[p,v]),(0,t.jsxs)("div",{className:"h-screen flex flex-col overflow-hidden",children:[(0,t.jsx)("nav",{className:"flex-shrink-0 border-b border-[var(--card-border)] bg-[var(--card-bg)]/80 backdrop-blur-lg z-30",children:(0,t.jsx)("div",{className:"max-w-7xl mx-auto px-4 sm:px-6 lg:px-8",children:(0,t.jsxs)("div",{className:"flex items-center justify-between h-16",children:[(0,t.jsx)("div",{className:"flex items-center gap-8",children:(0,t.jsxs)(l(),{href:"/",className:"flex items-center gap-3 group",children:[(0,t.jsx)("div",{className:"w-8 h-8 rounded-lg bg-gradient-to-br from-[var(--primary)] to-[var(--accent)] flex items-center justify-center text-white font-bold text-sm shadow-lg shadow-[var(--primary)]/20 group-hover:shadow-[var(--primary)]/40 transition-shadow",children:"A"}),(0,t.jsx)("span",{className:"text-lg font-bold tracking-tight gradient-text hidden sm:block",children:"AGX Board"})]})}),(0,t.jsx)("div",{className:"flex items-center gap-3",children:(0,t.jsx)(l(),{href:"/settings",className:"text-sm font-medium text-[var(--muted-foreground)] hover:text-[var(--foreground)] transition-colors",children:"Settings"})})]})})}),(0,t.jsx)("main",{className:"flex-1 min-h-0 flex flex-col ".concat(s?"p-0":"p-4 sm:p-6 lg:p-8 overflow-y-auto"),children:a}),!r&&(0,t.jsx)("footer",{className:"flex-shrink-0 border-t border-[var(--card-border)] bg-[var(--card-bg)]/50 py-4",children:(0,t.jsxs)("div",{className:"max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 flex items-center justify-between text-xs text-[var(--muted-foreground)]",children:[(0,t.jsx)("span",{children:"AGX Board • Autonomous Agent Orchestration"}),(0,t.jsx)("span",{className:"hidden sm:inline",children:"Built with Next.js + Db"})]})})]})}function u(e){return(0,t.jsx)(i.Suspense,{fallback:(0,t.jsx)("div",{className:"h-screen flex items-center justify-center bg-[var(--background)]",children:(0,t.jsx)("span",{className:"spinner w-8 h-8 border-3 border-[var(--primary)] border-t-transparent rounded-full"})}),children:(0,t.jsx)(c,{...e})})}function m(e){let{children:a,fullWidth:s=!1,noFooter:r=!1}=e;return(0,t.jsx)(u,{fullWidth:s,noFooter:r,children:a})}},2888:(e,a,s)=>{"use strict";s.d(a,{A:()=>d});var t=s(5155);let r={queued:{className:"badge-status-queued",label:"Queued",dotColor:"bg-[var(--status-queued)]"},in_progress:{className:"badge-status-in_progress",label:"In Progress",dotColor:"bg-[var(--status-in-progress)]"},blocked:{className:"badge-status-blocked",label:"Blocked",dotColor:"bg-[var(--status-blocked)]"},completed:{className:"badge-status-completed",label:"Completed",dotColor:"bg-[var(--status-completed)]"},failed:{className:"badge-status-failed",label:"Failed",dotColor:"bg-[var(--status-failed)]"}},l={ideation:{icon:"\uD83D\uDCA1",label:"Ideation",prompt:"Research and scope. Define approach, estimate effort."},planning:{icon:"\uD83D\uDCCB",label:"Planning",prompt:"Create detailed plan with tasks, milestones, and dependencies."},execution:{icon:"\uD83D\uDCBB",label:"Execution",prompt:"Implement based on all the context/history/research/plan. Write clean, tested code."},verification:{icon:"\uD83E\uDDEA",label:"Verification",prompt:"Test thoroughly. Find edge cases. Fix bugs. Verify requirements are met."},coding:{icon:"\uD83D\uDCBB",label:"Coding",prompt:"Write clean, tested code based on plan."},qa:{icon:"\uD83E\uDDEA",label:"QA",prompt:"Test thoroughly. Find edge cases. Fix bugs."},acceptance:{icon:"✓",label:"Acceptance",prompt:"Demo to user. Get sign-off. Address feedback."},pr:{icon:"\uD83D\uDD00",label:"PR",prompt:"Create and review pull request. Ensure all checks pass and merge."},pr_review:{icon:"\uD83D\uDC40",label:"PR Review",prompt:"Review the PR. Verify code quality and functionality. Approve or request changes."},merge:{icon:"\uD83D\uDE80",label:"Merge",prompt:"Merge the PR and verify deployment."},done:{icon:"✅",label:"Done",prompt:"Task finished and shipped."}};function n(e){let{task:a,onClick:s,compact:n=!1}=e,o=r[a.status||"queued"],d=a.stage?l[a.stage]:null,i=function(e){let a=new Date(e),s=Math.floor((new Date().getTime()-a.getTime())/1e3);return s<60?"just now":s<3600?"".concat(Math.floor(s/60),"m"):s<86400?"".concat(Math.floor(s/3600),"h"):"".concat(Math.floor(s/86400),"d")}(a.created_at);return n?(0,t.jsx)("div",{onClick:s,role:"button",tabIndex:0,onKeyDown:e=>"Enter"===e.key&&(null==s?void 0:s()),className:"group relative p-3 rounded-lg bg-[var(--card-bg)] border \n ".concat("failed"===a.status?"border-[var(--status-failed)] bg-[var(--status-failed-bg)]":"border-[var(--card-border)]","\n hover:border-[color-mix(in_srgb,var(--primary)_40%,var(--card-border))] \n hover:shadow-[var(--shadow-md)] \n transition-all duration-200 cursor-pointer\n focus-visible:outline-2 focus-visible:outline-[var(--ring)] focus-visible:outline-offset-2"),children:(0,t.jsxs)("div",{className:"flex items-center gap-3",children:[(0,t.jsx)("div",{className:"w-2 h-2 rounded-full ".concat(o.dotColor," flex-shrink-0")}),(0,t.jsx)("div",{className:"flex-1 min-w-0",children:(0,t.jsx)("h3",{className:"text-sm font-medium text-[var(--foreground)] truncate group-hover:text-[var(--primary)] transition-colors",children:a.title||"Untitled Task"})}),"failed"===a.status?(0,t.jsx)("span",{className:"text-xs text-[var(--status-failed)]",title:a.error,children:"⚠️"}):d&&(0,t.jsx)("span",{className:"text-xs opacity-60 flex-shrink-0",children:d.icon})]})}):(0,t.jsx)("div",{onClick:s,role:"button",tabIndex:0,onKeyDown:e=>"Enter"===e.key&&(null==s?void 0:s()),className:"group relative p-4 rounded-lg bg-[var(--card-bg)] border \n ".concat("failed"===a.status?"border-[var(--status-failed)] shadow-[0_0_0_1px_var(--status-failed)]":"border-[var(--card-border)]","\n hover:border-[var(--primary)] \n hover:shadow-sm\n transition-all duration-200 cursor-pointer\n focus-visible:outline-2 focus-visible:outline-[var(--ring)] focus-visible:outline-offset-2\n animate-fade-in-up"),children:(0,t.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,t.jsxs)("div",{className:"flex justify-between items-start gap-2",children:[(0,t.jsx)("h3",{className:"text-base font-semibold text-[var(--foreground)] leading-snug group-hover:text-[var(--primary)] transition-colors line-clamp-3",children:a.title||"Untitled Task"}),"failed"===a.status&&(0,t.jsx)("span",{className:"text-xs px-1.5 py-0.5 rounded bg-[var(--status-failed-bg)] text-[var(--status-failed)] font-bold border border-[var(--status-failed)]",children:"FAILED"})]}),(0,t.jsxs)("div",{className:"flex items-center gap-3 text-xs text-[var(--muted-foreground)] mt-1",children:[void 0!==a.priority&&(0,t.jsxs)("span",{className:"font-mono font-medium ".concat(0===a.priority?"text-[var(--primary)]":""),children:["P",a.priority]}),(0,t.jsx)("span",{className:"w-0.5 h-0.5 rounded-full bg-[var(--muted-foreground)] opacity-50"}),(0,t.jsx)("span",{className:"truncate max-w-[100px]",children:a.project||"No Project"}),(0,t.jsx)("span",{className:"w-0.5 h-0.5 rounded-full bg-[var(--muted-foreground)] opacity-50"}),(0,t.jsx)("span",{className:"capitalize",children:a.swarm?"Swarm":a.provider||a.engine||"No Provider"}),(0,t.jsx)("span",{className:"w-0.5 h-0.5 rounded-full bg-[var(--muted-foreground)] opacity-50"}),(0,t.jsx)("span",{children:i})]})]})})}let o={in_progress:{title:"In Progress",icon:"\uD83D\uDD04",color:"var(--status-in-progress)",description:"Currently being worked on by the daemon"},blocked:{title:"Blocked",icon:"\uD83D\uDEA7",color:"var(--status-blocked)",description:"Waiting for input or resolution"},queued:{title:"Queued",icon:"\uD83D\uDCCB",color:"var(--status-queued)",description:"Ready to be picked up"},completed:{title:"Completed",icon:"✅",color:"var(--status-completed)",description:"Successfully finished"}};function d(e){let{tasks:a,onSelectTask:s}=e;if(0===a.length)return(0,t.jsxs)("div",{className:"text-center py-20 animate-fade-in",children:[(0,t.jsx)("div",{className:"inline-flex items-center justify-center w-16 h-16 rounded-2xl bg-[var(--card-bg)] border border-[var(--card-border)] mb-4",children:(0,t.jsx)("span",{className:"text-3xl",children:"\uD83D\uDCCB"})}),(0,t.jsx)("h3",{className:"text-lg font-semibold mb-2",children:"No tasks yet"}),(0,t.jsx)("p",{className:"text-[var(--muted-foreground)] text-sm max-w-md mx-auto",children:"Create your first task to get started. Tasks will appear here organized by status."})]});let r=a.filter(e=>"in_progress"===e.status),l=a.filter(e=>"queued"===e.status),d=a.filter(e=>"blocked"===e.status),i=a.filter(e=>"completed"===e.status||"failed"===e.status),c=(e,a)=>{if(0===a.length)return null;let r=o[e];return(0,t.jsxs)("section",{className:"mb-8 animate-fade-in-up",children:[(0,t.jsxs)("div",{className:"flex items-center gap-3 mb-4",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2 px-3 py-1.5 rounded-lg",style:{backgroundColor:"color-mix(in srgb, ".concat(r.color," 10%, transparent)")},children:[(0,t.jsx)("span",{className:"text-lg",children:r.icon}),(0,t.jsx)("h3",{className:"text-sm font-semibold",style:{color:r.color},children:r.title}),(0,t.jsx)("span",{className:"px-2 py-0.5 rounded-full text-xs font-medium",style:{backgroundColor:"color-mix(in srgb, ".concat(r.color," 15%, transparent)"),color:r.color},children:a.length})]}),(0,t.jsx)("p",{className:"text-xs text-[var(--muted-foreground)] hidden sm:block",children:r.description})]}),(0,t.jsx)("div",{className:"grid gap-3 sm:grid-cols-2 lg:grid-cols-3",children:a.map((e,a)=>(0,t.jsx)("div",{className:"animate-fade-in-up",style:{animationDelay:"".concat(50*a,"ms")},children:(0,t.jsx)(n,{task:e,onClick:()=>null==s?void 0:s(e)})},e.id))})]})};return(0,t.jsxs)("div",{children:[c("in_progress",r),c("blocked",d),c("queued",l),c("completed",i)]})}},4647:(e,a,s)=>{"use strict";s.d(a,{A:()=>i,AuthProvider:()=>d});var t=s(5155),r=s(2115),l=s(1483),n=s(5704);let o=(0,r.createContext)({user:null,loading:!0,signOut:async()=>{}});function d(e){let{children:a}=e,s="1"===n.env.NEXT_PUBLIC_AGX_BOARD_DISABLE_AUTH,[d,i]=(0,r.useState)(null),[c,u]=(0,r.useState)(!0);(0,r.useEffect)(()=>{if(s){i({id:n.env.NEXT_PUBLIC_AGX_BOARD_USER_ID||"00000000-0000-0000-0000-000000000001",email:n.env.NEXT_PUBLIC_AGX_BOARD_USER_EMAIL||"local@agx.board",user_metadata:{name:n.env.NEXT_PUBLIC_AGX_BOARD_USER_NAME||"Local Board User",full_name:n.env.NEXT_PUBLIC_AGX_BOARD_USER_NAME||"Local Board User"},app_metadata:{},aud:"authenticated",created_at:new Date().toISOString()}),u(!1);return}let e=(0,l.O)();e.auth.getSession().then(e=>{var a,s;i(null!=(s=null==(a=e.data.session)?void 0:a.user)?s:null),u(!1)});let{data:{subscription:a}}=e.auth.onAuthStateChange((e,a)=>{var s;i(null!=(s=null==a?void 0:a.user)?s:null),u(!1)});return()=>a.unsubscribe()},[s]);let m=async()=>{if(s)return;let e=(0,l.O)();await e.auth.signOut(),i(null)};return(0,t.jsx)(o.Provider,{value:{user:d,loading:c,signOut:m},children:a})}function i(){return(0,r.useContext)(o)}},9620:(e,a,s)=>{Promise.resolve().then(s.bind(s,415))}},e=>{e.O(0,[5004,277,2619,650,9027,9719,2456,9337,8441,1255,7358],()=>e(e.s=9620)),_N_E=e.O()}]);
@@ -1 +1 @@
1
- (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[8419],{2707:(e,n,a)=>{"use strict";a.r(n),a.d(n,{default:()=>u});var l=a(5155),t=a(2115),s=a(577),o=a(91),i=a(2325),r=a(6779),c=a(5826),d=a(2835);function u(e){let{params:n}=e,{slug:a}=(0,t.use)(n),{tasks:u,isLoading:p,createTask:m,updateTask:v,deleteTask:g,completeTaskStage:f,cancelWorkflow:j,refetch:k,cancellingTaskId:x,fetchTask:h}=(0,s.si)({realtime:!0,project:a}),{projects:w}=(0,o.Y)(),{workflow:y,stages:C,stageConfig:_,isValidTransition:b,isLoading:N}=(0,i.mP)(),[A,S]=(0,t.useState)(null),[T,L]=(0,t.useState)(!1),[q,D]=(0,t.useState)(!1),[E,U]=(0,t.useState)(null),[F,M]=(0,t.useState)(null),{comments:O,addComment:I,deleteComment:P}=(0,s.LU)((null==A?void 0:A.id)||null),{learnings:R,addLearning:V}=(0,s.dF)((null==A?void 0:A.id)||void 0),Y=(0,t.useMemo)(()=>C.map(e=>{var n;let a=_[e],l=null==y||null==(n=y.nodes)?void 0:n.find(n=>n.name===e);return{id:e,label:(null==a?void 0:a.label)||e,icon:(null==a?void 0:a.icon)||"\uD83D\uDCCC",color:(null==a?void 0:a.color)||"var(--primary)",prompt:(null==l?void 0:l.prompt)||void 0}}),[C,_,y]),z=w.find(e=>e.slug===a),B=(0,t.useCallback)(async(e,n)=>{n&&S(n);try{let n=await h(e);return S(n),n}catch(e){return console.error("Failed to load task details:",e),n||S(null),null!=n?n:null}},[h]),G=(0,t.useCallback)(async e=>{await B(e.id,e)},[B]),H=(0,t.useCallback)(async e=>{M({stage:e})},[]),J=(0,t.useCallback)(async(e,n)=>{var a;D(!0);let l=(null==_||null==(a=_[n])?void 0:a.label)||n,t=e.split("\n")[0].replace(/^#\s*/,"")||"New Task (".concat(l,")"),s=["status: ".concat("ideation"===n?"queued":"in_progress"),"stage: ".concat(n)];z&&(s.push("project: ".concat(z.slug)),s.push("project_id: ".concat(z.id)),s.push("workflow_id: ".concat(z.workflow_id||i.ou)));let o="---\n".concat(s.join("\n"),"\n---\n\n# ").concat(t,"\n\n").concat(e);try{let e=await m(o,null);M(null),await B(e.id,e)}catch(e){console.error("Failed to create task:",e)}finally{D(!1)}},[m,z,B,_]),K=(0,t.useCallback)(async(e,n)=>{await v(e,n)},[v]),Q=async e=>{A&&await I(e)},W=async(e,n,a)=>{var l,t;let s=(null==A||null==(t=A.project_context)||null==(l=t.project)?void 0:l.id)||(null==A?void 0:A.project_id)||(null==A?void 0:A.project)||void 0,o=null!=a?a:"global"===n?void 0:"task"===n?null==A?void 0:A.id:s;await V(e,n,o)},X=async e=>{A&&(S(n=>n?{...n,...e}:null),await v(A.id,e))};return p||N?(0,l.jsx)("div",{className:"h-full flex items-center justify-center",children:(0,l.jsxs)("div",{className:"flex flex-col items-center gap-4",children:[(0,l.jsx)("span",{className:"spinner w-8 h-8 border-3 border-[var(--primary)] border-t-transparent rounded-full"}),(0,l.jsx)("p",{className:"text-sm text-[var(--muted-foreground)]",children:"Loading board..."})]})}):(0,l.jsxs)("div",{className:"h-full flex flex-col p-4",children:[(0,l.jsx)("div",{className:"flex-shrink-0 mb-4",children:(0,l.jsx)(d.A,{tasks:u,onTaskClick:S,onStop:async e=>{await j({taskId:e}),await k()},onRetry:async e=>{await f({taskId:e,decision:"not_done",final_result:"Manual retry requested.",explanation:"Manual retry requested."})},cancellingTaskId:x})}),(0,l.jsx)("div",{className:"flex-1 min-h-0 overflow-hidden",children:(0,l.jsx)(r.A,{tasks:u,onSelectTask:G,onTasksChange:()=>{},onTaskUpdate:K,onAddTask:H,stages:C,stageConfig:_,isValidTransition:b})}),A&&(0,l.jsx)(c.A,{task:A,comments:A?O:[],learnings:R,projectContext:A.project_context,projects:w,stages:Y,onClose:()=>S(null),onAddComment:Q,onDeleteComment:P,onAddLearning:W,onUpdate:X,onDelete:async()=>{await g(A.id),S(null)}}),F&&(0,l.jsx)(c.A,{task:{id:"draft",title:"",description:"",content:"",stage:F.stage,status:"ideation"===F.stage?"queued":"in_progress",created_at:new Date().toISOString(),project:null==z?void 0:z.slug,project_id:null==z?void 0:z.id},comments:[],learnings:[],projectContext:null,projects:w,stages:Y,isDraft:!0,isCreating:q,onClose:()=>M(null),onAddComment:()=>{},onAddLearning:()=>{},onUpdate:async e=>{(e.description||e.title)&&await J(e.description||e.title||"",e.stage||F.stage)}})]})}},6190:(e,n,a)=>{Promise.resolve().then(a.bind(a,2707))}},e=>{e.O(0,[5004,277,2619,650,9027,9719,2456,9337,8441,1255,7358],()=>e(e.s=6190)),_N_E=e.O()}]);
1
+ (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[8419],{2707:(e,n,a)=>{"use strict";a.r(n),a.d(n,{default:()=>u});var l=a(5155),t=a(2115),s=a(577),o=a(91),i=a(2325),r=a(6779),c=a(5826),d=a(2835);function u(e){let{params:n}=e,{slug:a}=(0,t.use)(n),{tasks:u,isLoading:p,createTask:m,updateTask:v,deleteTask:g,completeTaskStage:f,cancelWorkflow:j,refetch:k,cancellingTaskId:x,fetchTask:h}=(0,s.si)({realtime:!0,project:a}),{projects:w}=(0,o.Y)(),{workflow:y,stages:C,stageConfig:_,isValidTransition:b,isLoading:N}=(0,i.mP)(),[A,S]=(0,t.useState)(null),[T,L]=(0,t.useState)(!1),[q,D]=(0,t.useState)(!1),[E,U]=(0,t.useState)(null),[F,M]=(0,t.useState)(null),{comments:O,addComment:I,deleteComment:P}=(0,s.LU)((null==A?void 0:A.id)||null),{learnings:R,addLearning:V}=(0,s.dF)((null==A?void 0:A.id)||void 0),Y=(0,t.useMemo)(()=>C.map(e=>{var n;let a=_[e],l=null==y||null==(n=y.nodes)?void 0:n.find(n=>n.name===e);return{id:e,label:(null==a?void 0:a.label)||e,icon:(null==a?void 0:a.icon)||"\uD83D\uDCCC",color:(null==a?void 0:a.color)||"var(--primary)",prompt:(null==l?void 0:l.prompt)||void 0}}),[C,_,y]),z=w.find(e=>e.slug===a),B=(0,t.useCallback)(async(e,n)=>{n&&S(n);try{let n=await h(e);return S(n),n}catch(e){return console.error("Failed to load task details:",e),n||S(null),null!=n?n:null}},[h]),G=(0,t.useCallback)(async e=>{await B(e.id,e)},[B]),H=(0,t.useCallback)(async e=>{S(null),D(!1),M({stage:e})},[]),J=(0,t.useCallback)(async(e,n)=>{var a;D(!0);let l=(null==_||null==(a=_[n])?void 0:a.label)||n,t=e.split("\n")[0].replace(/^#\s*/,"")||"New Task (".concat(l,")"),s=["status: ".concat("ideation"===n?"queued":"in_progress"),"stage: ".concat(n)];z&&(s.push("project: ".concat(z.slug)),s.push("project_id: ".concat(z.id)),s.push("workflow_id: ".concat(z.workflow_id||i.ou)));let o="---\n".concat(s.join("\n"),"\n---\n\n# ").concat(t,"\n\n").concat(e);try{let e=await m(o,null);M(null),await B(e.id,e)}catch(e){console.error("Failed to create task:",e)}finally{D(!1)}},[m,z,B,_]),K=(0,t.useCallback)(async(e,n)=>{await v(e,n)},[v]),Q=async e=>{A&&await I(e)},W=async(e,n,a)=>{var l,t;let s=(null==A||null==(t=A.project_context)||null==(l=t.project)?void 0:l.id)||(null==A?void 0:A.project_id)||(null==A?void 0:A.project)||void 0,o=null!=a?a:"global"===n?void 0:"task"===n?null==A?void 0:A.id:s;await V(e,n,o)},X=async e=>{A&&(S(n=>n?{...n,...e}:null),await v(A.id,e))};return p||N?(0,l.jsx)("div",{className:"h-full flex items-center justify-center",children:(0,l.jsxs)("div",{className:"flex flex-col items-center gap-4",children:[(0,l.jsx)("span",{className:"spinner w-8 h-8 border-3 border-[var(--primary)] border-t-transparent rounded-full"}),(0,l.jsx)("p",{className:"text-sm text-[var(--muted-foreground)]",children:"Loading board..."})]})}):(0,l.jsxs)("div",{className:"h-full flex flex-col p-4",children:[(0,l.jsx)("div",{className:"flex-shrink-0 mb-4",children:(0,l.jsx)(d.A,{tasks:u,onTaskClick:S,onStop:async e=>{await j({taskId:e}),await k()},onRetry:async e=>{await f({taskId:e,decision:"not_done",final_result:"Manual retry requested.",explanation:"Manual retry requested."})},cancellingTaskId:x})}),(0,l.jsx)("div",{className:"flex-1 min-h-0 overflow-hidden",children:(0,l.jsx)(r.A,{tasks:u,onSelectTask:G,onTasksChange:()=>{},onTaskUpdate:K,onAddTask:H,stages:C,stageConfig:_,isValidTransition:b})}),A&&(0,l.jsx)(c.A,{task:A,comments:A?O:[],learnings:R,projectContext:A.project_context,projects:w,stages:Y,onClose:()=>S(null),onAddComment:Q,onDeleteComment:P,onAddLearning:W,onUpdate:X,onDelete:async()=>{await g(A.id),S(null)}}),F&&(0,l.jsx)(c.A,{task:{id:"draft",title:"",description:"",content:"",stage:F.stage,status:"ideation"===F.stage?"queued":"in_progress",created_at:new Date().toISOString(),project:null==z?void 0:z.slug,project_id:null==z?void 0:z.id},comments:[],learnings:[],projectContext:null,projects:w,stages:Y,isDraft:!0,isCreating:q,onClose:()=>M(null),onAddComment:()=>{},onAddLearning:()=>{},onUpdate:async e=>{(e.description||e.title)&&await J(e.description||e.title||"",e.stage||F.stage)}})]})}},6190:(e,n,a)=>{Promise.resolve().then(a.bind(a,2707))}},e=>{e.O(0,[5004,277,2619,650,9027,9719,2456,9337,8441,1255,7358],()=>e(e.s=6190)),_N_E=e.O()}]);
package/lib/cli/runCli.js CHANGED
@@ -71,19 +71,20 @@ const { handleSkillCommand } = require('./skills');
71
71
  const { runOnboarding, showConfigStatus, runConfigMenu } = require('./onboarding');
72
72
  const { runInteractiveMenu } = require('./interactiveMenu');
73
73
  const cloudArtifacts = require('./cloudArtifacts');
74
- const extractSectionSafe = typeof cloudArtifacts.extractSection === 'function'
74
+ const fallbackExtractSection = (markdown, heading) => {
75
+ if (!markdown) return '';
76
+ const pattern = new RegExp(`^##\\s+${heading}\\s*$`, 'im');
77
+ const match = pattern.exec(markdown);
78
+ if (!match) return '';
79
+ const start = match.index + match[0].length;
80
+ const rest = markdown.slice(start);
81
+ const next = rest.search(/^##\\s+/im);
82
+ const section = next === -1 ? rest : rest.slice(0, next);
83
+ return section.trim();
84
+ };
85
+ const extractSection = typeof cloudArtifacts.extractSection === 'function'
75
86
  ? cloudArtifacts.extractSection
76
- : (markdown, heading) => {
77
- if (!markdown) return '';
78
- const pattern = new RegExp(`^##\\s+${heading}\\s*$`, 'im');
79
- const match = pattern.exec(markdown);
80
- if (!match) return '';
81
- const start = match.index + match[0].length;
82
- const rest = markdown.slice(start);
83
- const next = rest.search(/^##\s+/im);
84
- const section = next === -1 ? rest : rest.slice(0, next);
85
- return section.trim();
86
- };
87
+ : fallbackExtractSection;
87
88
  const {
88
89
  sleep,
89
90
  appendTail,
@@ -151,7 +152,6 @@ const {
151
152
  createDaemonArtifactsRecorder,
152
153
  buildLocalRunIndexEntry,
153
154
  saveAugmentedPrompt,
154
- extractSection,
155
155
  buildFullDaemonPromptContext,
156
156
  resolveTaskTicketType,
157
157
  parseList,
@@ -787,8 +787,25 @@ async function checkOnboarding() {
787
787
  let decisionPayload;
788
788
  try {
789
789
  if (localArtifacts) {
790
- projectSlug = await resolveLocalProjectSlugForCloudTask(storage, task);
791
- taskSlug = await resolveLocalTaskSlugForCloudTask(storage, projectSlug, task);
790
+ try {
791
+ projectSlug = await resolveLocalProjectSlugForCloudTask(storage, task);
792
+ } catch {
793
+ projectSlug = null;
794
+ }
795
+ if (!projectSlug || typeof projectSlug !== 'string') {
796
+ projectSlug = storage.slugify(
797
+ (task?.project_slug || task?.project?.slug || task?.project_name || task?.project?.name || 'cloud'),
798
+ { maxLength: 64 }
799
+ ) || 'cloud';
800
+ }
801
+ try {
802
+ taskSlug = await resolveLocalTaskSlugForCloudTask(storage, projectSlug, task);
803
+ } catch {
804
+ taskSlug = null;
805
+ }
806
+ if (!taskSlug || typeof taskSlug !== 'string') {
807
+ taskSlug = storage.slugify(task?.slug || taskId || 'untitled', { maxLength: 64 }) || 'untitled';
808
+ }
792
809
 
793
810
  const cloudProject = extractCloudProjectIdentity(task);
794
811
  await storage.writeProjectState(projectSlug, {
@@ -2955,10 +2972,14 @@ EXAMPLES:
2955
2972
  let stageRequirement = '';
2956
2973
 
2957
2974
  if (!hasTaskPrompt) {
2958
- plan = extractSectionSafe(task.content, 'Plan');
2959
- todo = extractSectionSafe(task.content, 'Todo') || extractSectionSafe(task.content, 'TODO');
2960
- checkpoints = extractSectionSafe(task.content, 'Checkpoints');
2961
- learnings = extractSectionSafe(task.content, 'Learnings');
2975
+ const sectionExtractor = (typeof extractSection === 'function')
2976
+ ? extractSection
2977
+ : fallbackExtractSection;
2978
+
2979
+ plan = sectionExtractor(task.content, 'Plan');
2980
+ todo = sectionExtractor(task.content, 'Todo') || sectionExtractor(task.content, 'TODO');
2981
+ checkpoints = sectionExtractor(task.content, 'Checkpoints');
2982
+ learnings = sectionExtractor(task.content, 'Learnings');
2962
2983
 
2963
2984
  const stageKey = task?.stage || 'unknown';
2964
2985
  stagePrompt = resolveStageObjective(task, stageKey, '');
@@ -83,20 +83,32 @@ function collectProjectFlags(argv = []) {
83
83
  switch (arg) {
84
84
  case '--name':
85
85
  case '-n':
86
+ if (typeof value === 'undefined') {
87
+ throw new Error('Missing value for --name');
88
+ }
86
89
  parsed.name = value;
87
90
  i++;
88
91
  break;
89
92
  case '--slug':
93
+ if (typeof value === 'undefined') {
94
+ throw new Error('Missing value for --slug');
95
+ }
90
96
  parsed.slug = value;
91
97
  i++;
92
98
  break;
93
99
  case '--description':
94
100
  case '--desc':
101
+ if (typeof value === 'undefined') {
102
+ throw new Error('Missing value for --description');
103
+ }
95
104
  parsed.description = value;
96
105
  i++;
97
106
  break;
98
107
  case '--ci':
99
108
  case '--ci-info':
109
+ if (typeof value === 'undefined') {
110
+ throw new Error('Missing value for --ci');
111
+ }
100
112
  parsed.ci_cd_info = value;
101
113
  i++;
102
114
  break;
@@ -29,6 +29,50 @@ const LOCK_STALE_MS = process.env.AGX_LOCK_STALE_MS
29
29
  // Process start time - used to detect PID reuse
30
30
  const PROCESS_STARTED_AT = Date.now();
31
31
 
32
+ // ============================================================
33
+ // Lock Registry — track all held locks for cleanup on exit
34
+ // ============================================================
35
+
36
+ /** @type {Set<LockHandle>} */
37
+ const _heldLocks = new Set();
38
+ let _exitHandlerRegistered = false;
39
+
40
+ function _registerExitHandler() {
41
+ if (_exitHandlerRegistered) return;
42
+ _exitHandlerRegistered = true;
43
+
44
+ // Synchronous cleanup on exit — best-effort delete of lock files.
45
+ // This fires for normal exit, SIGINT, SIGTERM — but NOT SIGKILL.
46
+ const cleanup = () => {
47
+ for (const handle of _heldLocks) {
48
+ if (handle.released) continue;
49
+ try {
50
+ // Verify ownership before deleting (sync read + unlink)
51
+ const raw = fs.readFileSync(handle.lockPath, 'utf8');
52
+ const lock = JSON.parse(raw);
53
+ if (lock.pid === handle.pid && lock.at === handle.at) {
54
+ fs.unlinkSync(handle.lockPath);
55
+ }
56
+ } catch {
57
+ // Best-effort — ignore errors during shutdown
58
+ }
59
+ handle.released = true;
60
+ }
61
+ _heldLocks.clear();
62
+ };
63
+
64
+ process.on('exit', cleanup);
65
+
66
+ // For signals, run cleanup then re-raise so the process actually exits
67
+ for (const sig of ['SIGINT', 'SIGTERM']) {
68
+ process.on(sig, () => {
69
+ cleanup();
70
+ // Re-raise signal with default handler
71
+ process.kill(process.pid, sig);
72
+ });
73
+ }
74
+ }
75
+
32
76
  // ============================================================
33
77
  // Lock Management
34
78
  // ============================================================
@@ -80,48 +124,37 @@ async function acquireTaskLock(taskRootPath, options = {}) {
80
124
  const lockPath = path.join(taskRootPath, '.lock');
81
125
  const force = options.force || false;
82
126
 
83
- // Check existing lock
127
+ // Proactively clean stale locks before attempting acquisition
128
+ // This handles the common case where a previous process died without cleanup
84
129
  const existingLock = await readJsonSafe(lockPath);
85
130
 
86
131
  if (existingLock && !force) {
87
- // First check: is this our own lock from a previous run that wasn't released?
88
- // This handles the case where the same process crashed/restarted mid-task.
89
- if (existingLock.pid === process.pid) {
90
- // Same PID - check if it's truly from this process instance
91
- if (!isCurrentProcessLock(existingLock)) {
92
- // Lock is from a previous instance of this PID (PID was reused)
93
- // or from before this process started - safe to take over
94
- // This is the key fix: we clean up our own stale locks
95
- } else {
96
- // Lock is from current process instance - we already hold it
97
- // This shouldn't happen in normal operation, but return the existing lock
98
- // Actually, this would be a programming error, so let's throw
99
- throw new Error(
100
- `Lock already held by this process instance. ` +
101
- `This indicates a logic error - lock should be released before re-acquiring.`
102
- );
103
- }
104
- } else {
105
- // Different PID - check if the process is still alive and lock is fresh
106
- const isAlive = isProcessAlive(existingLock.pid);
107
- const isStale = isLockStale(existingLock);
108
-
109
- if (isAlive && !isStale) {
110
- // Also check process start time if available
111
- const startTimeValid = !existingLock.startedAt ||
112
- isProcessStartTimeValid(existingLock.pid, existingLock.startedAt);
113
-
114
- if (startTimeValid) {
115
- throw new Error(
116
- `Task is locked by process ${existingLock.pid} since ${existingLock.at}. ` +
117
- `Use --force to override if you're sure the lock is stale.`
118
- );
119
- }
120
- // Process has same PID but different start time (PID reuse) - lock is stale
132
+ const { valid, reason } = isLockValid(existingLock);
133
+ if (!valid) {
134
+ // Lock is stale/dead — clean it up silently
135
+ try { await fs.promises.unlink(lockPath); } catch (e) {
136
+ if (e.code !== 'ENOENT') throw e;
121
137
  }
138
+ // Fall through to acquire below
139
+ }
140
+ }
141
+
142
+ // Re-read after potential cleanup
143
+ const currentLock = existingLock ? await readJsonSafe(lockPath) : null;
122
144
 
123
- // Lock is stale or process is dead - we can take it
145
+ if (currentLock && !force) {
146
+ // If we get here, the lock survived the stale cleanup above — it's genuinely held.
147
+ if (currentLock.pid === process.pid && isCurrentProcessLock(currentLock)) {
148
+ throw new Error(
149
+ `Lock already held by this process instance. ` +
150
+ `This indicates a logic error - lock should be released before re-acquiring.`
151
+ );
124
152
  }
153
+ // Lock is held by a live process — reject
154
+ throw new Error(
155
+ `Task is locked by process ${currentLock.pid} since ${currentLock.at}. ` +
156
+ `Use --force to override if you're sure the lock is stale.`
157
+ );
125
158
  }
126
159
 
127
160
  const now = new Date().toISOString();
@@ -156,6 +189,10 @@ async function acquireTaskLock(taskRootPath, options = {}) {
156
189
  released: false,
157
190
  };
158
191
 
192
+ // Track for cleanup on process exit
193
+ _heldLocks.add(handle);
194
+ _registerExitHandler();
195
+
159
196
  return handle;
160
197
  }
161
198
 
@@ -212,7 +249,8 @@ async function releaseTaskLock(handle) {
212
249
  }
213
250
 
214
251
  handle.released = true;
215
-
252
+ _heldLocks.delete(handle);
253
+
216
254
  // Return status for debugging (callers typically ignore this)
217
255
  return { deleted, ownershipVerified };
218
256
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mndrk/agx",
3
- "version": "1.4.35",
3
+ "version": "1.4.36",
4
4
  "description": "Autonomous AI Agent Orchestrator for Claude, Gemini, and Ollama",
5
5
  "main": "lib/index.js",
6
6
  "exports": {