@useorgx/openclaw-plugin 0.3.0 → 0.3.2

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.
Files changed (87) hide show
  1. package/README.md +48 -1
  2. package/dashboard/dist/assets/MissionControlView-CthHdl6R.js +1 -0
  3. package/dashboard/dist/assets/SessionInspector-Dq0Z5WMo.js +1 -0
  4. package/dashboard/dist/assets/index-CoLgC4zE.js +11 -0
  5. package/dashboard/dist/assets/index-jfEYE0kO.css +1 -0
  6. package/dashboard/dist/assets/motion-CVDprFZg.js +9 -0
  7. package/dashboard/dist/assets/orgx-logo-Fm0FhtnV.png +0 -0
  8. package/dashboard/dist/assets/react-vendor-C2t2w4r2.js +32 -0
  9. package/dashboard/dist/assets/tanstack-C-KIc3Wc.js +1 -0
  10. package/dashboard/dist/assets/vendor-C-AHK0Ly.js +9 -0
  11. package/dashboard/dist/index.html +6 -2
  12. package/dist/adapters/outbox.d.ts +8 -0
  13. package/dist/adapters/outbox.d.ts.map +1 -0
  14. package/dist/adapters/outbox.js +6 -0
  15. package/dist/adapters/outbox.js.map +1 -0
  16. package/dist/agent-context-store.d.ts +24 -0
  17. package/dist/agent-context-store.d.ts.map +1 -0
  18. package/dist/agent-context-store.js +111 -0
  19. package/dist/agent-context-store.js.map +1 -0
  20. package/dist/agent-run-store.d.ts +31 -0
  21. package/dist/agent-run-store.d.ts.map +1 -0
  22. package/dist/agent-run-store.js +159 -0
  23. package/dist/agent-run-store.js.map +1 -0
  24. package/dist/api.d.ts +4 -139
  25. package/dist/api.d.ts.map +1 -1
  26. package/dist/api.js +4 -347
  27. package/dist/api.js.map +1 -1
  28. package/dist/auth-store.d.ts.map +1 -1
  29. package/dist/auth-store.js +56 -35
  30. package/dist/auth-store.js.map +1 -1
  31. package/dist/byok-store.d.ts +11 -0
  32. package/dist/byok-store.d.ts.map +1 -0
  33. package/dist/byok-store.js +98 -0
  34. package/dist/byok-store.js.map +1 -0
  35. package/dist/contracts/client.d.ts +154 -0
  36. package/dist/contracts/client.d.ts.map +1 -0
  37. package/dist/contracts/client.js +422 -0
  38. package/dist/contracts/client.js.map +1 -0
  39. package/dist/contracts/types.d.ts +430 -0
  40. package/dist/contracts/types.d.ts.map +1 -0
  41. package/dist/contracts/types.js +8 -0
  42. package/dist/contracts/types.js.map +1 -0
  43. package/dist/fs-utils.d.ts +7 -0
  44. package/dist/fs-utils.d.ts.map +1 -0
  45. package/dist/fs-utils.js +63 -0
  46. package/dist/fs-utils.js.map +1 -0
  47. package/dist/http-handler.d.ts +27 -1
  48. package/dist/http-handler.d.ts.map +1 -1
  49. package/dist/http-handler.js +2520 -92
  50. package/dist/http-handler.js.map +1 -1
  51. package/dist/index.d.ts.map +1 -1
  52. package/dist/index.js +352 -27
  53. package/dist/index.js.map +1 -1
  54. package/dist/local-openclaw.d.ts.map +1 -1
  55. package/dist/local-openclaw.js +57 -15
  56. package/dist/local-openclaw.js.map +1 -1
  57. package/dist/mcp-apps/orgx-live.html +690 -0
  58. package/dist/openclaw.plugin.json +3 -3
  59. package/dist/outbox.d.ts +7 -0
  60. package/dist/outbox.d.ts.map +1 -1
  61. package/dist/outbox.js +150 -17
  62. package/dist/outbox.js.map +1 -1
  63. package/dist/paths.d.ts +23 -0
  64. package/dist/paths.d.ts.map +1 -0
  65. package/dist/paths.js +50 -0
  66. package/dist/paths.js.map +1 -0
  67. package/dist/reporting/outbox-replay.d.ts +2 -0
  68. package/dist/reporting/outbox-replay.d.ts.map +1 -0
  69. package/dist/reporting/outbox-replay.js +17 -0
  70. package/dist/reporting/outbox-replay.js.map +1 -0
  71. package/dist/reporting/rollups.d.ts +21 -0
  72. package/dist/reporting/rollups.d.ts.map +1 -0
  73. package/dist/reporting/rollups.js +85 -0
  74. package/dist/reporting/rollups.js.map +1 -0
  75. package/dist/snapshot-store.d.ts +10 -0
  76. package/dist/snapshot-store.d.ts.map +1 -0
  77. package/dist/snapshot-store.js +68 -0
  78. package/dist/snapshot-store.js.map +1 -0
  79. package/dist/types.d.ts +5 -410
  80. package/dist/types.d.ts.map +1 -1
  81. package/dist/types.js +5 -4
  82. package/dist/types.js.map +1 -1
  83. package/openclaw.plugin.json +3 -3
  84. package/package.json +13 -3
  85. package/dashboard/dist/assets/index-BrAP-X_H.css +0 -1
  86. package/dashboard/dist/assets/index-cOk6qwh-.js +0 -56
  87. package/dashboard/dist/assets/orgx-logo-QSE5QWy4.png +0 -0
package/README.md CHANGED
@@ -30,7 +30,7 @@ Or manually add to your OpenClaw config:
30
30
  "orgx": {
31
31
  "enabled": true,
32
32
  "config": {
33
- "apiKey": "oxk-your-api-key"
33
+ "apiKey": "oxk_..."
34
34
  }
35
35
  }
36
36
  }
@@ -70,6 +70,7 @@ Shows:
70
70
  - Agent status and current tasks
71
71
  - Pending decisions requiring approval
72
72
  - Activity stream
73
+ - Outbox replay visibility for buffered offline events
73
74
 
74
75
  ### 🎯 Model Routing
75
76
 
@@ -95,6 +96,20 @@ Returns: { allowed: true, modelTier: "sonnet" }
95
96
  Agent spawns with recommended model
96
97
  ```
97
98
 
99
+ ## Feature Matrix
100
+
101
+ | Capability | Status | Notes |
102
+ |-----------|--------|-------|
103
+ | Browser pairing onboarding | ✅ | `POST /orgx/api/onboarding/start` + polling flow |
104
+ | Manual API key fallback | ✅ | In onboarding gate and `manual-key` endpoint |
105
+ | Live sessions + activity + handoffs | ✅ | SSE with local fallback paths |
106
+ | Mission Control hierarchy view | ✅ | Initiative → workstream → milestone → task |
107
+ | Run control shortcuts | ✅ | Pause/resume/cancel/checkpoint/rollback in Session Detail |
108
+ | Outbox buffering + replay | ✅ | Local queue + auto replay on sync |
109
+ | Outbox observability in dashboard | ✅ | Pending/replay indicators in header/notifications |
110
+ | Plugin diagnostics (`doctor`) | ✅ | CLI + `GET /orgx/api/health` |
111
+ | Full-auto codex dispatch | ✅ | `npm run job:dispatch` with retries + rollups |
112
+
98
113
  ## CLI Commands
99
114
 
100
115
  ```bash
@@ -103,8 +118,39 @@ openclaw orgx status
103
118
 
104
119
  # Manual sync
105
120
  openclaw orgx sync --memory "..." --daily-log "..."
121
+
122
+ # Diagnostics (local + remote probe)
123
+ openclaw orgx doctor
124
+
125
+ # Diagnostics JSON without remote probe
126
+ openclaw orgx doctor --json --no-remote
127
+ ```
128
+
129
+ ## Full-Auto Codex Dispatch Job
130
+
131
+ Reusable orchestration job to dispatch/monitor parallel `codex --full-auto` workers against OrgX tasks and report progress back through the reporting control plane (`/api/client/live/activity` + `/api/client/live/changesets/apply`).
132
+
133
+ ```bash
134
+ export ORGX_API_KEY=oxk_...
135
+
136
+ npm run job:dispatch -- \
137
+ --initiative_id=aa6d16dc-d450-417f-8a17-fd89bd597195 \
138
+ --plan_file=/Users/hopeatina/Code/orgx-openclaw-plugin/docs/orgx-openclaw-launch-workstreams-plan-2026-02-14.md \
139
+ --codex_args="--full-auto" \
140
+ --concurrency=6
106
141
  ```
107
142
 
143
+ Key behavior:
144
+ - Pulls tasks from OrgX for selected workstreams
145
+ - Spawns parallel Codex workers per task
146
+ - Retries failures with backoff up to `--max_attempts`
147
+ - Emits activity and task status transitions into OrgX DB
148
+ - Persists resumable state to `.orgx-codex-jobs/<job-id>/job-state.json`
149
+
150
+ Notes:
151
+ - `ORGX_USER_ID` is legacy and only needed with legacy service-key flows.
152
+ - User-scoped `oxk_...` API keys should not send `X-Orgx-User-Id`.
153
+
108
154
  ## API Endpoints
109
155
 
110
156
  When the plugin is loaded, these HTTP endpoints are available:
@@ -116,6 +162,7 @@ When the plugin is loaded, these HTTP endpoints are available:
116
162
  | `GET /orgx/api/agents` | Agent states |
117
163
  | `GET /orgx/api/activity` | Activity feed |
118
164
  | `GET /orgx/api/initiatives` | Initiative data |
165
+ | `GET /orgx/api/health` | Plugin diagnostics + outbox/sync health |
119
166
  | `GET /orgx/api/onboarding` | Config/setup state |
120
167
  | `POST /orgx/api/onboarding/start` | Start browser pairing flow |
121
168
  | `GET /orgx/api/onboarding/status` | Poll pairing status / auto-connect |
@@ -0,0 +1 @@
1
+ import{r as h,u as Ve,b as Ue,c as pe,j as e}from"./react-vendor-C2t2w4r2.js";import{q as Ne,b as ke,c as et,a as B,A as Qe,d as tt,S as He,u as Ae,P as st,M as nt,e as rt}from"./index-CoLgC4zE.js";import{A as Ce,m as ie}from"./motion-CVDprFZg.js";import"./tanstack-C-KIc3Wc.js";import"./vendor-C-AHK0Ly.js";function it({activities:t,agents:s,initiatives:i}){return h.useMemo(()=>{const d=new Map,r=(a,o,m,x)=>{const g=d.get(a)??[];g.some(c=>c.id===o)||(g.push({id:o,name:m,confidence:x}),d.set(a,g))};return t.forEach(a=>{const o="metadata"in a&&a.metadata&&typeof a.metadata=="object"?a.metadata:null,m=o&&typeof o=="object"?o:{},x=("initiativeId"in a&&typeof a.initiativeId=="string"?a.initiativeId:void 0)??m.initiativeId??void 0,g=a.agentId??void 0,c=("agentName"in a&&typeof a.agentName=="string"?a.agentName:"agent"in a&&typeof a.agent=="string"?a.agent:void 0)??g??"Unknown";x&&g&&r(x,g,c,"high")}),i.forEach(a=>{var o;(o=a.avatars)!=null&&o.length&&a.avatars.forEach(m=>{const x=s.find(g=>g.name.toLowerCase()===m.toLowerCase());x?r(a.id,x.id,x.name,"medium"):r(a.id,`avatar:${m}`,m,"medium")})}),s.forEach(a=>{if(!a.task)return;const o=a.task.toLowerCase();i.forEach(m=>{m.name.toLowerCase().split(/\s+/).filter(f=>f.length>3).some(f=>o.includes(f))&&r(m.id,a.id,a.name,"low")})}),d},[t,s,i])}function at({initiativeId:t=null,authToken:s=null,embedMode:i=!1,enabled:d=!0}){var v,k,y;const r=Ve(),a=h.useMemo(()=>Ne.autoContinueStatus({initiativeId:t??"__global__",authToken:s,embedMode:i}),[t,s,i]),o=Ue({queryKey:a,enabled:d&&(!!t||t===null),queryFn:async()=>{const N=new URLSearchParams;t&&N.set("initiative_id",t);const p=await fetch(`/orgx/api/mission-control/auto-continue/status?${N.toString()}`,{headers:ke({authToken:s,embedMode:i})}),b=await p.json().catch(()=>null);if(!p.ok){const D=typeof(b==null?void 0:b.error)=="string"&&b.error||typeof(b==null?void 0:b.message)=="string"&&b.message||`Failed to load auto-continue status (${p.status})`;return{ok:!1,initiativeId:t,run:null,defaults:{tokenBudget:0,tickMs:0},error:D}}return b},refetchInterval:N=>{var l,M;const p=N.state.data;if(((l=p==null?void 0:p.error)==null?void 0:l.toLowerCase().includes("404"))??!1)return!1;const D=((M=p==null?void 0:p.run)==null?void 0:M.status)??null;return D==="running"||D==="stopping"?2500:12e3}}),m=async()=>{await r.invalidateQueries({queryKey:a}),await r.invalidateQueries({queryKey:Ne.missionControlGraph({initiativeId:t,authToken:s,embedMode:i})}),await r.invalidateQueries({queryKey:Ne.liveData({authToken:s,embedMode:i})})},x=pe({mutationFn:async N=>{const p={};t&&(p.initiativeId=t),N&&typeof N=="object"&&(typeof N.tokenBudgetTokens=="number"&&(p.tokenBudgetTokens=N.tokenBudgetTokens),typeof N.agentId=="string"&&N.agentId.trim().length>0&&(p.agentId=N.agentId.trim()));const b=await fetch("/orgx/api/mission-control/auto-continue/start",{method:"POST",headers:ke({authToken:s,embedMode:i,contentTypeJson:!0}),body:JSON.stringify(p)}),D=await b.json().catch(()=>null);if(!b.ok){const l=typeof(D==null?void 0:D.error)=="string"&&D.error||typeof(D==null?void 0:D.message)=="string"&&D.message||`Failed to start auto-continue (${b.status})`;throw new Error(l)}if(D&&typeof D=="object"&&"run"in D){const l=o.data??null;return{ok:!0,initiativeId:t,run:D.run??null,defaults:(l==null?void 0:l.defaults)??{tokenBudget:0,tickMs:0}}}return D},onSuccess:()=>{m()}}),g=pe({mutationFn:async()=>{const N={};t&&(N.initiativeId=t);const p=await fetch("/orgx/api/mission-control/auto-continue/stop",{method:"POST",headers:ke({authToken:s,embedMode:i,contentTypeJson:!0}),body:JSON.stringify(N)}),b=await p.json().catch(()=>null);if(!p.ok){const D=typeof(b==null?void 0:b.error)=="string"&&b.error||typeof(b==null?void 0:b.message)=="string"&&b.message||`Failed to stop auto-continue (${p.status})`;throw new Error(D)}if(b&&typeof b=="object"&&"run"in b){const D=o.data??null;return{ok:!0,initiativeId:t,run:b.run??null,defaults:(D==null?void 0:D.defaults)??{tokenBudget:0,tickMs:0}}}return b},onSuccess:()=>{m()}}),c=((v=o.data)==null?void 0:v.run)??null,f=(c==null?void 0:c.status)==="running"||(c==null?void 0:c.status)==="stopping";return{status:o.data??null,run:c,isRunning:f,isLoading:o.isLoading,error:((k=o.data)==null?void 0:k.error)??((y=o.error)==null?void 0:y.message)??null,start:x.mutateAsync,stop:g.mutateAsync,isStarting:x.isPending,isStopping:g.isPending,refetch:o.refetch}}function fe({className:t=""}){return e.jsx("div",{className:et("shimmer-skeleton",t),"aria-hidden":"true"})}async function be(t){if(!t.ok){const s=await t.json().catch(()=>null),i=typeof(s==null?void 0:s.error)=="string"&&s.error||typeof(s==null?void 0:s.message)=="string"&&s.message||`Request failed (${t.status})`;throw new Error(i)}return t}function lt(t){const s=Ve(),i=ke({authToken:t.authToken,embedMode:t.embedMode,contentTypeJson:!0}),d=()=>{s.invalidateQueries({queryKey:["live-data"]}),s.invalidateQueries({queryKey:["initiative-details"]}),s.invalidateQueries({queryKey:["entities"]}),s.invalidateQueries({queryKey:["mission-control-graph"]})},r=pe({mutationFn:async x=>{const{type:g,...c}=x,f=await fetch("/orgx/api/entities",{method:"POST",headers:i,body:JSON.stringify({type:g,...c})});return await be(f),f.json()},onSuccess:d}),a=pe({mutationFn:async x=>{const{type:g,id:c,...f}=x,v=await fetch("/orgx/api/entities",{method:"PATCH",headers:i,body:JSON.stringify({type:g,id:c,...f})});return await be(v),v.json()},onSuccess:d}),o=pe({mutationFn:async x=>{const g=await fetch(`/orgx/api/entities/${encodeURIComponent(x.type)}/${encodeURIComponent(x.id)}/delete`,{method:"POST",headers:i,body:"{}"});return await be(g),g.json()},onSuccess:d}),m=pe({mutationFn:async x=>{const g=await fetch(`/orgx/api/entities/${encodeURIComponent(x.type)}/${encodeURIComponent(x.id)}/${encodeURIComponent(x.action)}`,{method:"POST",headers:i,body:JSON.stringify({force:x.force??!1})});return await be(g),g.json()},onSuccess:d});return{createEntity:r,updateEntity:a,deleteEntity:o,entityAction:m}}const Ge=h.createContext(null);function ue(){const t=h.useContext(Ge);if(!t)throw new Error("useMissionControl must be used within MissionControlProvider");return t}function ot({children:t,agentEntityMap:s,authToken:i,embedMode:d}){const[r,a]=h.useState(new Set),[o,m]=h.useState(null),[x,g]=h.useState(""),[c,f]=h.useState([]),[v,k]=h.useState("target"),[y,N]=h.useState("any"),[p,b]=h.useState(""),[D,l]=h.useState(""),[M,I]=h.useState("status"),[G,te]=h.useState("default"),U=lt({authToken:i,embedMode:d}),X=h.useCallback(T=>{a(O=>{const L=new Set(O);return L.has(T)?L.delete(T):L.add(T),L})},[]),se=h.useCallback(T=>{a(O=>{if(O.has(T))return O;const L=new Set(O);return L.add(T),L})},[]),Z=h.useCallback(T=>{a(new Set(T))},[]),E=h.useCallback(()=>{a(new Set)},[]),Y=h.useCallback(T=>{m(T)},[]),J=h.useCallback(()=>{m(null)},[]),K=h.useCallback(T=>{f(O=>{const L=T.trim().toLowerCase();return L?O.includes(L)?O.filter(ne=>ne!==L):[...O,L]:O})},[]),Q=h.useCallback(()=>{g(""),f([]),k("target"),N("any"),b(""),l("")},[]),z=c.length+(v!=="target"?1:0)+(y!=="any"?1:0),w=x.trim().length>0||z>0,P=h.useMemo(()=>({agentEntityMap:s,expandedInitiatives:r,modalTarget:o,searchQuery:x,statusFilters:c,dateField:v,datePreset:y,dateStart:p,dateEnd:D,activeFilterCount:z,hasActiveFilters:w,groupBy:M,sortBy:G,authToken:i,embedMode:d,mutations:U,toggleExpanded:X,expandInitiative:se,expandAll:Z,collapseAll:E,openModal:Y,closeModal:J,setSearchQuery:g,setStatusFilters:f,toggleStatusFilter:K,setDateField:k,setDatePreset:N,setDateStart:b,setDateEnd:l,setGroupBy:I,setSortBy:te,clearFilters:Q}),[s,r,o,x,c,v,y,p,D,z,w,M,G,i,d,U,X,se,Z,E,Y,J,f,K,k,N,b,l,I,te,Q]);return e.jsx(Ge.Provider,{value:P,children:t})}const Ye={active:"text-[#BFFF00] bg-[#BFFF00]/10 border-[#BFFF00]/20",paused:"text-[#F5B700] bg-[#F5B700]/10 border-[#F5B700]/20",blocked:"text-[#FF6B88] bg-[#FF6B88]/10 border-[#FF6B88]/20",completed:"text-[#14B8A6] bg-[#14B8A6]/10 border-[#14B8A6]/20"},ct={done:"text-[#14B8A6] bg-[#14B8A6]/10 border-[#14B8A6]/20",completed:"text-[#14B8A6] bg-[#14B8A6]/10 border-[#14B8A6]/20",in_progress:"text-[#BFFF00] bg-[#BFFF00]/10 border-[#BFFF00]/20",active:"text-[#BFFF00] bg-[#BFFF00]/10 border-[#BFFF00]/20",blocked:"text-[#FF6B88] bg-[#FF6B88]/10 border-[#FF6B88]/20",todo:"text-white/60 bg-white/5 border-white/10"},Ee=t=>ct[t.toLowerCase()]??"text-white/60 bg-white/5 border-white/10",Je=t=>{const s=t.toLowerCase();return s==="active"||s==="in_progress"?"text-[#BFFF00] bg-[#BFFF00]/10 border-[#BFFF00]/20":s==="blocked"?"text-[#FF6B88] bg-[#FF6B88]/10 border-[#FF6B88]/20":s==="completed"||s==="done"?"text-[#14B8A6] bg-[#14B8A6]/10 border-[#14B8A6]/20":"text-white/60 bg-white/5 border-white/10"},Ke=t=>{const s=t.toLowerCase();return s==="done"||s==="completed"?"text-[#14B8A6] bg-[#14B8A6]/10 border-[#14B8A6]/20":s==="active"||s==="in_progress"?"text-[#BFFF00] bg-[#BFFF00]/10 border-[#BFFF00]/20":"text-white/60 bg-white/5 border-white/10"},re=t=>t.replace(/[_-]+/g," ").replace(/\s+/g," ").trim().replace(/\b\w/g,s=>s.toUpperCase()),Fe=t=>{const s=t.toLowerCase();return s==="blocked"?0:s==="in_progress"||s==="active"?1:s==="todo"||s==="planned"?2:s==="done"||s==="completed"?3:4},_e=t=>{const s=t.toLowerCase();return s==="blocked"?B.red:s==="active"||s==="in_progress"?B.lime:s==="done"||s==="completed"?B.teal:s==="paused"?B.amber:"rgba(255,255,255,0.35)"};function dt(t){if(!t)return null;const s=Date.parse(t);if(!Number.isFinite(s))return null;const i=new Date,d=new Date(i.getFullYear(),i.getMonth(),i.getDate()).getTime(),r=new Date(s),a=new Date(r.getFullYear(),r.getMonth(),r.getDate()).getTime();return Math.round((a-d)/864e5)}function ut(t){const s=dt(t);return s===null?{label:"No target date",tone:"neutral"}:s<0?{label:`Overdue ${Math.abs(s)}d`,tone:"danger"}:s===0?{label:"Due today",tone:"warning"}:s<=7?{label:`Due in ${s}d`,tone:"warning"}:{label:`Due in ${s}d`,tone:"success"}}function Be({agents:t,max:s=4}){if(!t.length)return null;const i=t.slice(0,s),d=t.length-s;return e.jsxs("div",{className:"flex items-center -space-x-1.5",children:[i.map(r=>e.jsx("div",{className:"relative",title:`${r.name} (${r.confidence} confidence)`,style:{borderRadius:"9999px",border:r.confidence==="high"?"1.5px solid rgba(255,255,255,0.25)":r.confidence==="medium"?"1.5px dashed rgba(255,255,255,0.15)":"1.5px dotted rgba(255,255,255,0.10)"},children:e.jsx(Qe,{name:r.name,size:"xs"})},r.id)),d>0&&e.jsxs("span",{className:"ml-1 text-[9px] text-white/40",children:["+",d]})]})}function Me(t){return{initiative:{id:t,title:"Initiative",status:"active",summary:null,assignedAgents:[]},nodes:[],edges:[],recentTodos:[]}}function xt({initiativeId:t,authToken:s=null,embedMode:i=!1,enabled:d=!0}){var x,g;const r=tt(t),a=h.useMemo(()=>Ne.missionControlGraph({initiativeId:t,authToken:s,embedMode:i}),[t,s,i]),o=Ue({queryKey:a,enabled:d&&!!t&&r,queryFn:async()=>{if(!t)throw new Error("initiativeId is required");if(!r)return Me(t);const c=new URLSearchParams({initiative_id:t}),f={};i&&(f["X-Orgx-Embed"]="true"),s&&(f.Authorization=`Bearer ${s}`);const v=Object.keys(f).length>0?f:void 0,k=await fetch(`/orgx/api/mission-control/graph?${c.toString()}`,{headers:v});if(!k.ok){const y=await k.json().catch(()=>null),N=typeof(y==null?void 0:y.error)=="string"&&y.error||typeof(y==null?void 0:y.message)=="string"&&y.message||`Failed to fetch Mission Control graph (${k.status})`;return console.warn(`[useMissionControlGraph] ${N}`),{...Me(t),degraded:[N]}}return await k.json()}});return{graph:o.data??(t?Me(t):null),isLoading:r?o.isLoading:!1,error:r?((x=o.error)==null?void 0:x.message)??null:null,degraded:r?((g=o.data)==null?void 0:g.degraded)??[]:[],refetch:o.refetch}}function Se({type:t,className:s=""}){return t==="initiative"?e.jsxs("svg",{className:s,width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:B.iris,strokeWidth:"1.8",children:[e.jsx("circle",{cx:"12",cy:"12",r:"9",fill:`${B.iris}1A`}),e.jsx("circle",{cx:"12",cy:"12",r:"5"}),e.jsx("circle",{cx:"12",cy:"12",r:"1.5",fill:B.iris,stroke:"none"})]}):t==="workstream"?e.jsxs("svg",{className:s,width:"14",height:"14",viewBox:"0 0 24 24",fill:`${B.lime}1A`,stroke:B.lime,strokeWidth:"1.8",strokeLinecap:"round",children:[e.jsx("rect",{x:"3",y:"4",width:"18",height:"16",rx:"3",fill:`${B.lime}1A`,stroke:"none"}),e.jsx("line",{x1:"5",y1:"8",x2:"15",y2:"8"}),e.jsx("polyline",{points:"15,6 17,8 15,10",fill:"none"}),e.jsx("line",{x1:"5",y1:"12",x2:"15",y2:"12"}),e.jsx("polyline",{points:"15,10 17,12 15,14",fill:"none"}),e.jsx("line",{x1:"5",y1:"16",x2:"15",y2:"16"}),e.jsx("polyline",{points:"15,14 17,16 15,18",fill:"none"})]}):t==="milestone"?e.jsxs("svg",{className:s,width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:B.teal,strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M4 15s1-1 4-1 5 2 8 2 4-1 4-1V3s-1 1-4 1-5-2-8-2-4 1-4 1z",fill:`${B.teal}1A`}),e.jsx("line",{x1:"4",y1:"22",x2:"4",y2:"15"})]}):e.jsxs("svg",{className:s,width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"rgba(255,255,255,0.72)",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"4",y:"4",width:"16",height:"16",rx:"4",fill:"rgba(255,255,255,0.10)"}),e.jsx("path",{d:"M9 12l2 2 4-4"})]})}function pt(t){return t==="initiative"?"Initiatives":t==="workstream"?"Workstreams":t==="milestone"?"Milestones":"Tasks"}function ht({nodes:t,edges:s,selectedNodeId:i,focusedWorkstreamId:d,onSelectNode:r}){const a=h.useMemo(()=>new Map(t.map(l=>[l.id,l])),[t]),[o,m]=h.useState(""),[x,g]=h.useState(!1),c=o.trim().toLowerCase(),f=h.useMemo(()=>{if(!d)return new Set(t.map(I=>I.id));const l=new Set;for(const I of t)(I.type==="initiative"||I.id===d||I.workstreamId===d)&&l.add(I.id);let M=!0;for(;M;){M=!1;for(const I of s)(l.has(I.from)||l.has(I.to))&&(!l.has(I.from)||!l.has(I.to))&&(l.add(I.from),l.add(I.to),M=!0)}return l},[d,t,s]),v=t.filter(l=>f.has(l.id)),k=s.filter(l=>f.has(l.from)&&f.has(l.to)),y=h.useMemo(()=>{if(!i)return new Set;const l=new Set([i]);for(const M of k)M.from===i&&l.add(M.to),M.to===i&&l.add(M.from);return l},[i,k]),N=h.useMemo(()=>{let l=new Set(Array.from(f));return x&&i&&(l=new Set(Array.from(l).filter(M=>y.has(M)))),c.length>0&&(l=new Set(Array.from(l).filter(M=>{const I=a.get(M);return I?I.title.toLowerCase().includes(c):!1}))),l},[a,c,y,x,i,f]),p=t.filter(l=>N.has(l.id)),b=s.filter(l=>N.has(l.from)&&N.has(l.to)),D={initiative:p.filter(l=>l.type==="initiative"),workstream:p.filter(l=>l.type==="workstream"),milestone:p.filter(l=>l.type==="milestone"),task:p.filter(l=>l.type==="task")};return v.length===0?null:e.jsxs("section",{className:"space-y-2.5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("span",{className:"text-[10px] uppercase tracking-[0.08em] text-white/42",children:[p.length," nodes · ",b.length," links"]}),d&&e.jsx("span",{className:"status-pill","data-tone":"active",children:"Focused workstream"})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("input",{value:o,onChange:l=>m(l.target.value),placeholder:"Filter nodes...",className:"h-9 flex-1 min-w-[200px] rounded-lg border border-white/[0.12] bg-black/30 px-3 text-[11px] text-white/80 placeholder:text-white/25 transition-colors focus:border-[#BFFF00]/35 focus:outline-none"}),i&&e.jsx("button",{type:"button",onClick:()=>g(l=>!l),"aria-pressed":x,"data-state":x?"active":"idle",className:"control-pill px-3 text-[11px] font-semibold",title:"Show only the selected node and its direct neighbors",children:"Related only"}),(o.trim().length>0||x)&&e.jsx("button",{type:"button",onClick:()=>{m(""),g(!1)},className:"control-pill px-3 text-[11px]",children:"Reset"})]}),p.length===0?e.jsx("div",{className:"table-shell px-3 py-3 text-[11px] text-white/48",children:"No nodes match this view. Clear filters or select a different node to see connected work."}):e.jsx("div",{className:`grid gap-2 ${Object.values(D).filter(l=>l.length>0).length<=2?"grid-cols-1 sm:grid-cols-2":"md:grid-cols-2 xl:grid-cols-4"}`,children:Object.keys(D).filter(l=>D[l].length>0).map(l=>e.jsxs("div",{className:"table-shell p-2.5",children:[e.jsxs("div",{className:"mb-1.5 text-[10px] uppercase tracking-[0.09em] text-white/45",children:[pt(l)," (",D[l].length,")"]}),e.jsxs("div",{className:"space-y-1",children:[D[l].slice(0,10).map(M=>{const I=i===M.id,G=!I&&y.has(M.id);return e.jsxs("button",{type:"button",onClick:()=>r(M.id),title:M.title,className:`flex w-full items-center gap-1.5 rounded-md border px-2 py-1 text-left transition-colors ${I?"border-[#BFFF00]/35 bg-[#BFFF00]/12":G?"border-[#14B8A6]/35 bg-[#14B8A6]/12":"border-white/[0.12] bg-white/[0.03] hover:bg-white/[0.08]"}`,children:[e.jsx(Se,{type:M.type}),e.jsx("span",{className:"truncate text-[11px] text-white/80",children:M.title})]},M.id)}),D[l].length>10&&e.jsxs("div",{className:"px-1 text-[10px] text-white/35",children:["+",D[l].length-10," more"]})]})]},l))}),b.length>0&&e.jsxs("div",{className:"table-shell px-2.5 py-2",children:[e.jsx("div",{className:"mb-1 text-[10px] uppercase tracking-[0.08em] text-white/35",children:"Dependency links"}),e.jsx("div",{className:"max-h-[110px] space-y-1 overflow-auto pr-1",children:b.slice(0,36).map(l=>{const M=a.get(l.from),I=a.get(l.to);if(!M||!I)return null;const G=i===M.id||i===I.id;return e.jsxs("button",{type:"button",onClick:()=>r(I.id),className:"flex w-full items-center gap-1 rounded-md px-1.5 py-1 text-left hover:bg-white/[0.06]",children:[e.jsx("span",{className:"h-1.5 w-1.5 rounded-full",style:{backgroundColor:G?B.lime:"rgba(255,255,255,0.35)"}}),e.jsx("span",{className:"truncate text-[10px] text-white/70",children:M.title}),e.jsx("span",{className:"text-[10px] text-white/30",children:"→"}),e.jsx("span",{className:"truncate text-[10px] text-white/70",children:I.title})]},`${l.from}-${l.to}`)})})]})]})}function mt(t){return t.trim().toLowerCase().replace(/[\s-]+/g,"_")}const gt=new Set(["done","completed","complete","cancelled","canceled","archived","deleted"]);function ae(t){return gt.has(mt(t))}function De(t){return Number.isFinite(t)?Math.max(0,Math.min(100,Math.round(t))):0}function de(t,s){return s<=0?0:De(t/s*100)}function ft({dependencies:t,allNodes:s,disabled:i=!1,onSave:d}){const[r,a]=h.useState(!1),[o,m]=h.useState(""),[x,g]=h.useState(t),c=h.useMemo(()=>new Map(s.map(y=>[y.id,y])),[s]),f=h.useMemo(()=>{const y=o.trim().toLowerCase(),N=[...s].sort((p,b)=>p.title.localeCompare(b.title));return y?N.filter(p=>p.title.toLowerCase().includes(y)||p.id.toLowerCase().includes(y)).slice(0,16):N.slice(0,16)},[s,o]),v=()=>{d(Array.from(new Set(x))),a(!1)},k=y=>{g(N=>N.includes(y)?N.filter(p=>p!==y):[...N,y])};return e.jsxs("div",{className:"relative",children:[e.jsx("button",{type:"button",disabled:i,onClick:()=>{m(""),g(t),a(y=>!y)},className:"rounded-md border border-white/[0.12] bg-white/[0.04] px-2 py-1 text-[10px] text-white/70 transition-colors hover:bg-white/[0.08] disabled:opacity-40",children:t.length>0?`${t.length} linked`:"Set links"}),r&&e.jsxs("div",{className:"surface-tier-2 absolute right-0 z-20 mt-1.5 w-[320px] rounded-xl p-2.5 shadow-[0_20px_40px_rgba(0,0,0,0.45)]",children:[e.jsx("label",{className:"text-[10px] uppercase tracking-[0.08em] text-white/45",children:"Link dependencies"}),e.jsx("input",{value:o,onChange:y=>m(y.target.value),placeholder:"Search by title or id...",className:"mt-1.5 h-9 w-full rounded-md border border-white/[0.12] bg-black/25 px-2.5 text-[11px] text-white/85 outline-none transition-colors placeholder:text-white/35 focus:border-[#BFFF00]/35"}),e.jsx("div",{className:"mt-2 flex max-h-[84px] flex-wrap gap-1.5 overflow-y-auto rounded-md border border-white/[0.08] bg-black/20 p-1.5",children:x.length===0?e.jsx("span",{className:"text-[10px] text-white/40",children:"No links selected"}):x.map(y=>{var p;const N=((p=c.get(y))==null?void 0:p.title)??y;return e.jsxs("button",{type:"button",onClick:()=>k(y),className:"inline-flex items-center gap-1 rounded-full border border-white/[0.16] bg-white/[0.05] px-2 py-0.5 text-[10px] text-white/70 transition-colors hover:bg-white/[0.1]",title:N,children:[e.jsx("span",{className:"max-w-[180px] truncate",children:N}),e.jsx("span",{className:"text-white/45",children:"×"})]},y)})}),e.jsx("div",{className:"mt-2 max-h-[150px] space-y-1 overflow-y-auto rounded-md border border-white/[0.08] bg-black/20 p-1.5",children:f.length===0?e.jsx("div",{className:"px-1 text-[10px] text-white/40",children:"No matching nodes"}):f.map(y=>{const N=x.includes(y.id);return e.jsxs("button",{type:"button",onClick:()=>k(y.id),className:`flex w-full items-center justify-between rounded-md border px-2 py-1 text-left text-[10px] transition-colors ${N?"border-[#BFFF00]/32 bg-[#BFFF00]/12 text-[#D8FFA1]":"border-white/[0.1] bg-white/[0.03] text-white/70 hover:bg-white/[0.08]"}`,children:[e.jsxs("span",{className:"min-w-0 pr-2",children:[e.jsx("span",{className:"block truncate",children:y.title}),e.jsxs("span",{className:"block truncate text-white/40",children:[y.id.slice(0,8),"…"]})]}),e.jsx("span",{className:"font-semibold",children:N?"Linked":"Link"})]},y.id)})}),e.jsxs("div",{className:"mt-2 flex items-center justify-end gap-1.5",children:[e.jsx("button",{type:"button",onClick:()=>a(!1),className:"rounded-md border border-white/[0.12] px-2 py-1 text-[10px] text-white/60 transition-colors hover:bg-white/[0.08]",children:"Cancel"}),e.jsx("button",{type:"button",onClick:v,className:"rounded-md border border-[#BFFF00]/30 bg-[#BFFF00]/15 px-2 py-1 text-[10px] text-[#D8FFA1] transition-colors hover:bg-[#BFFF00]/22",children:"Save links"})]})]})]})}function bt(t){if(!t)return"";const s=new Date(t);if(Number.isNaN(s.getTime()))return"";const i=s.getFullYear(),d=String(s.getMonth()+1).padStart(2,"0"),r=String(s.getDate()).padStart(2,"0"),a=String(s.getHours()).padStart(2,"0"),o=String(s.getMinutes()).padStart(2,"0");return`${i}-${d}-${r}T${a}:${o}`}const Pe=["not_started","planned","todo","in_progress","active","blocked","done"];function wt(t){const s=t.trim().toLowerCase();return s==="blocked"?"blocked":s==="done"||s==="completed"?"done":s==="in_progress"||s==="active"||s==="running"||s==="queued"?"active":"planned"}function we(t){const s=t.trim().toLowerCase();return s==="completed"?"done":s==="running"||s==="queued"?"active":s==="pending"||s==="backlog"?"todo":s}function yt(t,s){return s==="all"?!0:s==="blocked"?t==="blocked":s==="done"?t==="done":t!=="blocked"&&t!=="done"}function jt(t,s){const i=new Map(s.map(a=>[a.id,a])),d=new Set,r=[t];for(;r.length>0;){const a=r.shift(),o=i.get(a);o&&(o.parentId&&!d.has(o.parentId)&&(d.add(o.parentId),r.push(o.parentId)),o.workstreamId&&!d.has(o.workstreamId)&&(d.add(o.workstreamId),r.push(o.workstreamId)),o.milestoneId&&!d.has(o.milestoneId)&&(d.add(o.milestoneId),r.push(o.milestoneId)))}return d}function vt(t,s,i,d){let r=0;if(i==="title")r=t.title.localeCompare(s.title);else if(i==="status")r=Fe(t.status)-Fe(s.status);else if(i==="priority")r=t.priorityNum-s.priorityNum;else if(i==="eta"){const a=t.etaEndAt?Date.parse(t.etaEndAt):1/0,o=s.etaEndAt?Date.parse(s.etaEndAt):1/0;r=a-o}return d==="desc"?-r:r}function Nt({nodes:t,edges:s,selectedNodeId:i,highlightedNodeIds:d,editMode:r,onToggleEditMode:a,onSelectNode:o,onFocusWorkstream:m,onOpenNode:x,onUpdateNode:g,mutations:c}){const[f,v]=h.useState(""),[k,y]=h.useState(new Set),[N,p]=h.useState("all"),[b,D]=h.useState(!1),[l,M]=h.useState(null),[I,G]=h.useState("asc"),te=h.useMemo(()=>new Map(t.map(n=>[n.id,n])),[t]),U=h.useMemo(()=>t.map(n=>({id:n.id,title:n.title})),[t]),X=h.useMemo(()=>{const n=new Map;for(const S of t){const u=we(S.status);n.set(u,(n.get(u)??0)+1)}return n},[t]),se=h.useMemo(()=>{let n=0,S=0,u=0;for(const C of t){const A=we(C.status);A==="blocked"?S+=1:A==="done"?u+=1:n+=1}return{all:t.length,open:n,blocked:S,done:u}},[t]),Z=h.useMemo(()=>{const n=f.trim().toLowerCase(),S=n.length>0,u=k.size>0;if(!S&&!u&&!(N!=="all"))return null;const A=new Set;for(const q of t){const H=we(q.status),R=!S||q.title.toLowerCase().includes(n)||q.assignedAgents.some(_=>_.name.toLowerCase().includes(n)),W=!u||k.has(H),F=yt(H,N);R&&W&&F&&A.add(q.id)}const $=new Set(A);for(const q of A)for(const H of jt(q,t))$.add(H);return $},[k,t,f,N]),E=h.useMemo(()=>t.filter(n=>n.type==="workstream").sort((n,S)=>n.priorityNum-S.priorityNum||n.title.localeCompare(S.title)),[t]),Y=h.useMemo(()=>{const n=new Map;for(const S of t.filter(u=>u.type==="milestone")){const u=S.workstreamId??"unscoped",C=n.get(u)??[];C.push(S),n.set(u,C)}for(const S of n.values())S.sort((u,C)=>u.priorityNum-C.priorityNum||u.title.localeCompare(C.title));return n},[t]),J=h.useMemo(()=>{const n=new Map;for(const S of t.filter(u=>u.type==="task"&&u.milestoneId)){const u=S.milestoneId??"unscoped",C=n.get(u)??[];C.push(S),n.set(u,C)}for(const S of n.values())S.sort((u,C)=>u.priorityNum-C.priorityNum||u.title.localeCompare(C.title));return n},[t]),K=h.useMemo(()=>{const n=new Map;for(const S of t.filter(u=>u.type==="task"&&!u.milestoneId)){const u=S.workstreamId??"unscoped",C=n.get(u)??[];C.push(S),n.set(u,C)}for(const S of n.values())S.sort((u,C)=>u.priorityNum-C.priorityNum||u.title.localeCompare(C.title));return n},[t]),Q=h.useMemo(()=>{const n=new Set;for(const S of E)n.add(S.id);for(const S of t.filter(u=>u.type==="milestone"))n.add(S.id);return n},[t,E]),[z,w]=h.useState(Q);h.useEffect(()=>{w(Q)},[Q]);const P=n=>l?[...n].sort((S,u)=>vt(S,u,l,I)):n,T=h.useMemo(()=>{const n=[],S=A=>Z===null||Z.has(A);for(const A of P(E)){if(!S(A.id))continue;const $=P(Y.get(A.id)??[]),q=P(K.get(A.id)??[]),H=$.length>0||q.length>0;if(n.push({node:A,depth:0,canCollapse:H}),!!z.has(A.id)){for(const R of $){if(!S(R.id))continue;const W=P(J.get(R.id)??[]);if(n.push({node:R,depth:1,canCollapse:W.length>0}),z.has(R.id))for(const F of W)S(F.id)&&n.push({node:F,depth:2,canCollapse:!1})}for(const R of q)S(R.id)&&n.push({node:R,depth:1,canCollapse:!1})}}const u=P(Y.get("unscoped")??[]),C=P(K.get("unscoped")??[]);for(const A of u)if(S(A.id)&&(n.push({node:A,depth:0,canCollapse:(J.get(A.id)??[]).length>0}),z.has(A.id)))for(const $ of P(J.get(A.id)??[]))S($.id)&&n.push({node:$,depth:1,canCollapse:!1});for(const A of C)S(A.id)&&n.push({node:A,depth:0,canCollapse:!1});return n},[K,z,Z,Y,l,I,J,E]),O=n=>n.dependencyIds.length,L=h.useMemo(()=>{const n=new Map,S=(u,C)=>{if(u.length>0){const A=u.filter($=>ae($.status)).length;return de(A,u.length)}return ae(C)?100:0};for(const u of t.filter(C=>C.type==="milestone")){const C=J.get(u.id)??[];n.set(u.id,S(C,u.status))}for(const u of E){const A=(Y.get(u.id)??[]).flatMap(q=>J.get(q.id)??[]),$=K.get(u.id)??[];n.set(u.id,S([...$,...A],u.status))}return n},[K,Y,t,J,E]),ne=n=>{l===n?G(S=>S==="asc"?"desc":"asc"):(M(n),G("asc"))},ce=n=>{y(S=>{const u=new Set(S);return u.has(n)?u.delete(n):u.add(n),u})},le=()=>{v(""),p("all"),y(new Set)},oe=({field:n})=>l!==n?e.jsx("span",{className:"text-white/20 ml-0.5",children:"↕"}):e.jsx("span",{className:"text-[#BFFF00] ml-0.5",children:I==="asc"?"↑":"↓"});return e.jsxs("section",{className:"space-y-2",children:[e.jsxs("div",{className:"mb-2 flex flex-col gap-2 lg:flex-row lg:items-center",children:[e.jsx("div",{className:"w-full lg:max-w-[340px]",children:e.jsx(He,{value:f,onChange:v,placeholder:"Search items or agents..."})}),e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[[{id:"all",label:"All",count:se.all},{id:"open",label:"Open",count:se.open},{id:"blocked",label:"Blocked",count:se.blocked},{id:"done",label:"Done",count:se.done}].map(n=>{const S=N===n.id;return e.jsxs("button",{type:"button",onClick:()=>p(n.id),className:`inline-flex items-center gap-1.5 rounded-full border px-2.5 py-1 text-[10px] font-semibold transition-colors ${S?"border-[#BFFF00]/30 bg-[#BFFF00]/10 text-[#D8FFA1]":"border-white/[0.12] bg-white/[0.03] text-white/60 hover:bg-white/[0.07] hover:text-white/82"}`,children:[e.jsx("span",{children:n.label}),e.jsx("span",{className:"text-[9px] text-current/80",children:n.count})]},n.id)}),e.jsxs("button",{type:"button",onClick:()=>D(n=>!n),className:`inline-flex items-center gap-1.5 rounded-full border px-2.5 py-1 text-[10px] transition-colors ${b||k.size>0?"border-white/[0.2] bg-white/[0.06] text-white/82":"border-white/[0.12] bg-white/[0.03] text-white/55 hover:text-white/75"}`,children:["Status",k.size>0&&e.jsx("span",{className:"rounded-full bg-white/[0.08] px-1.5 py-[1px] text-[9px]",children:k.size})]}),(f.trim().length>0||N!=="all"||k.size>0)&&e.jsx("button",{type:"button",onClick:le,className:"rounded-full px-2 py-1 text-[10px] text-white/45 transition-colors hover:text-white/75",children:"Clear"}),a&&e.jsxs("button",{type:"button",onClick:a,className:`inline-flex items-center gap-1.5 rounded-full border px-2.5 py-1 text-[10px] transition-colors ${r?"border-[#BFFF00]/28 bg-[#BFFF00]/12 text-[#D8FFA1]":"border-white/[0.12] bg-white/[0.03] text-white/55 hover:text-white/82"}`,children:[e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{d:"M17 3a2.828 2.828 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5L17 3z"})}),r?"Editing":"Edit"]})]})]}),b&&e.jsxs("div",{className:"mb-2 table-shell px-2.5 py-2",children:[e.jsx("div",{className:"mb-1.5 text-[10px] uppercase tracking-[0.08em] text-white/38",children:"Advanced status filters"}),e.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[Pe.map(n=>{const S=k.has(n),u=X.get(n)??0;return e.jsxs("button",{type:"button",onClick:()=>ce(n),className:`inline-flex items-center gap-1 rounded-full border px-2 py-1 text-[10px] transition-colors ${S?"border-[#14B8A6]/35 bg-[#14B8A6]/12 text-[#8FF7EC]":"border-white/[0.12] bg-white/[0.03] text-white/58 hover:bg-white/[0.07] hover:text-white/85"}`,children:[e.jsx("span",{children:re(n)}),e.jsx("span",{className:"text-[9px] text-current/75",children:u})]},n)}),k.size>0&&e.jsx("button",{type:"button",onClick:()=>y(new Set),className:"rounded-full px-2 py-1 text-[10px] text-white/45 transition-colors hover:text-white/75",children:"Reset status"})]})]}),r&&e.jsx("div",{className:"mb-2 text-[10px] text-white/45",children:"Edit mode: select a row to edit its fields inline."}),e.jsx("div",{className:"table-shell overflow-x-auto p-2",children:e.jsxs("table",{className:"w-full min-w-[1180px] border-separate border-spacing-y-1.5",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-left text-[10px] uppercase tracking-[0.08em] text-white/42",children:[e.jsxs("th",{className:"px-2 py-1.5 cursor-pointer select-none",onClick:()=>ne("title"),children:["Item ",e.jsx(oe,{field:"title"})]}),e.jsx("th",{className:"w-[188px] px-2 py-1.5",children:"Assigned"}),e.jsxs("th",{className:"px-2 py-1.5 cursor-pointer select-none",onClick:()=>ne("status"),children:["Status ",e.jsx(oe,{field:"status"})]}),e.jsx("th",{className:"px-2 py-1.5",children:"Progress"}),e.jsxs("th",{className:"px-2 py-1.5 cursor-pointer select-none",onClick:()=>ne("priority"),children:["Priority ",e.jsx(oe,{field:"priority"})]}),e.jsxs("th",{className:"px-2 py-1.5 cursor-pointer select-none",onClick:()=>ne("eta"),children:["ETA ",e.jsx(oe,{field:"eta"})]}),e.jsx("th",{className:"px-2 py-1.5",children:"Duration (h)"}),e.jsx("th",{className:"px-2 py-1.5",children:"Budget ($)"}),e.jsx("th",{className:"px-2 py-1.5",children:"Dependencies"})]})}),e.jsx("tbody",{children:T.map(({node:n,depth:S,canCollapse:u})=>{var W;const C=i===n.id,A=d.has(n.id),$=n.assignedAgents.map(F=>F.name).join(", "),q=n.dependencyIds.map(F=>{var _;return((_=te.get(F))==null?void 0:_.title)??F}).slice(0,3).join(", "),H=L.get(n.id),R=r&&C;return e.jsxs("tr",{onClick:()=>{o(n.id),n.type==="workstream"&&m(n.id)},className:`group/row cursor-pointer rounded-lg border transition-colors ${C?"border-[#BFFF00]/[0.22] bg-[#BFFF00]/[0.08]":A?"border-[#14B8A6]/[0.2] bg-[#14B8A6]/[0.08]":"border-white/[0.06] bg-white/[0.02] hover:border-white/[0.14] hover:bg-white/[0.05]"}`,children:[e.jsx("td",{className:"rounded-l-lg px-2 py-1.5",children:e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("div",{style:{width:S*14}}),u?e.jsx("button",{type:"button",onClick:F=>{F.stopPropagation(),w(_=>{const ee=new Set(_);return ee.has(n.id)?ee.delete(n.id):ee.add(n.id),ee})},"aria-label":`${z.has(n.id)?"Collapse":"Expand"} ${n.type}: ${n.title}`,className:"rounded text-white/50 focus:outline-none focus-visible:ring-2 focus-visible:ring-[#BFFF00]/35 focus-visible:ring-offset-2 focus-visible:ring-offset-[#02040A]",children:z.has(n.id)?"▾":"▸"}):e.jsx("span",{className:"w-2.5"}),e.jsx(Se,{type:n.type}),e.jsx("button",{type:"button",onClick:F=>{F.stopPropagation(),x(n)},"aria-label":`Open ${n.type} details: ${n.title}`,className:"max-w-[320px] truncate rounded text-[12px] text-white/88 hover:text-white focus:outline-none focus-visible:ring-2 focus-visible:ring-[#BFFF00]/35 focus-visible:ring-offset-2 focus-visible:ring-offset-[#02040A]",children:n.title}),n.type==="task"&&c&&!r&&e.jsx("div",{className:"flex items-center gap-0.5 opacity-0 group-hover/row:opacity-100 transition-opacity ml-1",children:["not_started","todo","planned","pending","backlog"].includes(n.status.toLowerCase())?e.jsx("button",{type:"button",title:"Start",onClick:F=>{F.stopPropagation(),g(n,{status:"in_progress"})},"aria-label":`Start task: ${n.title}`,className:"flex items-center justify-center w-5 h-5 rounded text-white/40 transition-colors hover:text-[#BFFF00] hover:bg-white/[0.06] focus:outline-none focus-visible:ring-2 focus-visible:ring-[#BFFF00]/35 focus-visible:ring-offset-2 focus-visible:ring-offset-[#02040A]",children:e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"currentColor",children:e.jsx("path",{d:"M8 5v14l11-7z"})})}):["in_progress","active"].includes(n.status.toLowerCase())?e.jsx("button",{type:"button",title:"Mark done",onClick:F=>{F.stopPropagation(),g(n,{status:"done"})},"aria-label":`Mark task done: ${n.title}`,className:"flex items-center justify-center w-5 h-5 rounded text-white/40 transition-colors hover:text-emerald-400 hover:bg-white/[0.06] focus:outline-none focus-visible:ring-2 focus-visible:ring-[#BFFF00]/35 focus-visible:ring-offset-2 focus-visible:ring-offset-[#02040A]",children:e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",children:e.jsx("path",{d:"M20 6 9 17l-5-5"})})}):null})]})}),e.jsx("td",{className:"px-2 py-1.5 text-[11px] text-white/75 whitespace-nowrap",children:R?e.jsx("input",{type:"text",defaultValue:$,placeholder:"Agent A, Agent B",onClick:F=>F.stopPropagation(),onBlur:F=>{const _=F.currentTarget.value.split(",").map(ee=>ee.trim()).filter(Boolean);g(n,{assigned_agent_names:_,assigned_agent_ids:_.map(ee=>`name:${ee}`),assignment_source:"manual"})},className:"w-[190px] rounded border border-white/[0.16] bg-white/[0.06] px-2 py-1 text-[10px] text-white/82"}):e.jsx("div",{className:"flex items-center gap-2",children:n.assignedAgents.length>0?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex items-center -space-x-1.5",children:n.assignedAgents.slice(0,3).map(F=>e.jsx("div",{title:F.name,className:"rounded-full ring-1 ring-[#02040A]",children:e.jsx(Qe,{name:F.name,hint:`${F.id} ${n.title}`,size:"xs"})},`${n.id}:${F.id}`))}),e.jsxs("span",{className:"max-w-[110px] truncate text-[10px] text-white/62",title:$,children:[(W=n.assignedAgents[0])==null?void 0:W.name,n.assignedAgents.length>1?` +${n.assignedAgents.length-1}`:""]})]}):e.jsx("span",{className:"text-white/35",children:"Unassigned"})})}),e.jsx("td",{className:"px-2 py-1.5 text-[11px] text-white/75",children:R?e.jsx("select",{defaultValue:we(n.status),onClick:F=>F.stopPropagation(),onChange:F=>{g(n,{status:F.target.value})},className:"rounded border border-white/[0.16] bg-white/[0.06] px-2 py-1 text-[10px] text-white/82",children:Pe.map(F=>e.jsx("option",{value:F,children:re(F)},F))}):e.jsx("span",{className:"status-pill whitespace-nowrap","data-tone":wt(n.status),children:re(n.status)})}),e.jsx("td",{className:"px-2 py-1.5 text-[11px] text-white/75",children:H!==void 0&&(n.type==="workstream"||n.type==="milestone")?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"h-1 w-[72px] rounded-full bg-white/[0.06] overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full transition-all",style:{width:`${H}%`,backgroundColor:n.type==="milestone"?B.teal:B.lime}})}),e.jsxs("span",{className:"text-[10px] text-white/60",style:{fontVariantNumeric:"tabular-nums"},children:[H,"%"]})]}):e.jsx("span",{className:"text-white/35",children:"—"})}),e.jsx("td",{className:"px-2 py-1.5 text-[11px] text-white/75",children:R?e.jsx("input",{type:"number",min:1,max:100,defaultValue:n.priorityNum,onClick:F=>F.stopPropagation(),onBlur:F=>{const _=Number(F.currentTarget.value);Number.isFinite(_)&&g(n,{priority_num:_})},className:"w-[72px] rounded border border-white/[0.16] bg-white/[0.06] px-2 py-1 text-[10px] text-white/82"}):e.jsxs("span",{children:["P",n.priorityNum]})}),e.jsx("td",{className:"px-2 py-1.5 text-[11px] text-white/75",children:R?e.jsx("input",{type:"datetime-local",defaultValue:bt(n.etaEndAt),onClick:F=>F.stopPropagation(),onBlur:F=>{const _=F.currentTarget.value;g(n,{eta_end_at:_?new Date(_).toISOString():null})},className:"w-[176px] rounded border border-white/[0.16] bg-white/[0.06] px-2 py-1 text-[10px] text-white/82"}):e.jsx("span",{children:n.etaEndAt?new Date(n.etaEndAt).toLocaleString():"—"})}),e.jsx("td",{className:"px-2 py-1.5 text-[11px] text-white/75",children:R&&n.type!=="task"?e.jsx("input",{type:"number",min:0,step:.5,defaultValue:n.expectedDurationHours,onClick:F=>F.stopPropagation(),onBlur:F=>{const _=Number(F.currentTarget.value);Number.isFinite(_)&&g(n,{expected_duration_hours:_})},className:"w-[82px] rounded border border-white/[0.16] bg-white/[0.06] px-2 py-1 text-[10px] text-white/82"}):e.jsx("span",{children:n.expectedDurationHours})}),e.jsx("td",{className:"px-2 py-1.5 text-[11px] text-white/75",children:R&&n.type!=="task"?e.jsx("input",{type:"number",min:0,step:1,defaultValue:n.expectedBudgetUsd,onClick:F=>F.stopPropagation(),onBlur:F=>{const _=Number(F.currentTarget.value);Number.isFinite(_)&&g(n,{expected_budget_usd:_})},className:"w-[92px] rounded border border-white/[0.16] bg-white/[0.06] px-2 py-1 text-[10px] text-white/82"}):e.jsxs("span",{children:["$",n.expectedBudgetUsd.toLocaleString(),R&&n.type==="task"?" (from task spec)":""]})}),e.jsx("td",{className:"rounded-r-lg px-2 py-1.5 text-[11px] text-white/75",children:R?e.jsx("div",{onClick:F=>F.stopPropagation(),children:e.jsx(ft,{dependencies:n.dependencyIds,allNodes:U,onSave:F=>void g(n,{depends_on:F})})}):e.jsx("div",{className:"max-w-[250px] truncate",children:O(n)>0?`${O(n)} · ${q}`:"—"})})]},n.id)})})]})}),T.length===0&&e.jsxs("div",{className:"flex flex-col items-center py-10",children:[e.jsxs("svg",{width:"32",height:"32",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:"text-white/20",children:[e.jsx("path",{d:"M9 5H7a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V7a2 2 0 0 0-2-2h-2"}),e.jsx("rect",{x:"9",y:"3",width:"6",height:"4",rx:"1"}),e.jsx("path",{d:"M9 14h6M9 18h4"})]}),e.jsx("div",{className:"mt-3 text-[13px] font-medium text-white/50",children:f||k.size>0||N!=="all"?"No items match the current filters":"No work items yet"}),e.jsx("div",{className:"mt-1 text-[11px] text-white/30",children:f||k.size>0||N!=="all"?"Try adjusting your search or filter criteria.":"Workstreams, milestones, and tasks will appear here."})]})]})}function kt({recentTodoIds:t,nodesById:s,selectedNodeId:i,onSelectNode:d}){const r=t.map(m=>s.get(m)).filter(m=>!!m).sort((m,x)=>{if(m.priorityNum!==x.priorityNum)return m.priorityNum-x.priorityNum;const g=m.dueDate?Date.parse(m.dueDate):Number.POSITIVE_INFINITY,c=x.dueDate?Date.parse(x.dueDate):Number.POSITIVE_INFINITY;return g-c}).slice(0,14);if(r.length===0)return null;const a=r[0],o=r.slice(1,7);return e.jsxs("section",{className:"space-y-2",children:[e.jsx("div",{className:"flex items-center justify-end gap-2",children:e.jsxs("span",{className:"rounded-full border border-white/15 bg-black/20 px-2 py-0.5 text-[10px] text-white/65",children:[r.length," in queue"]})}),e.jsx("button",{type:"button",onClick:()=>d(a.id),className:`surface-hero group w-full rounded-xl border px-3.5 py-3 text-left transition-colors ${i===a.id?"border-[#BFFF00]/35 bg-[#BFFF00]/14":"border-white/15 bg-black/25 hover:border-white/30 hover:bg-white/[0.08]"}`,children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"inline-flex items-center gap-1.5 text-[10px] uppercase tracking-[0.1em] text-white/50",children:[e.jsx(Se,{type:a.type}),e.jsx("span",{children:"Priority task"})]}),e.jsx("p",{className:"mt-1 line-clamp-2 text-[13px] font-semibold leading-snug text-white",children:a.title}),e.jsx("p",{className:"mt-1 text-[11px] text-white/60",children:a.dueDate?`Due ${new Date(a.dueDate).toLocaleDateString()}`:"No target date set"})]}),e.jsxs("span",{className:"rounded-full border px-2 py-0.5 text-[10px] font-semibold",style:{borderColor:`${B.amber}44`,backgroundColor:`${B.amber}22`,color:B.amber},children:["P",a.priorityNum]})]})}),e.jsx("div",{className:"flex items-center gap-1.5 overflow-x-auto pb-1",children:o.map(m=>e.jsxs("button",{type:"button",onClick:()=>d(m.id),className:`flex flex-shrink-0 items-center gap-1.5 rounded-lg border px-2.5 py-1.5 text-left transition-colors ${i===m.id?"border-[#BFFF00]/30 bg-[#BFFF00]/12":"border-white/[0.14] bg-black/20 hover:bg-white/[0.08]"}`,children:[e.jsx(Se,{type:m.type}),e.jsx("span",{className:"max-w-[220px] truncate text-[11px] text-white/82",children:m.title}),e.jsxs("span",{className:"rounded-full px-1.5 py-0.5 text-[9px]",style:{backgroundColor:`${B.amber}22`,color:`${B.amber}`},children:["P",m.priorityNum]})]},m.id))})]})}function Ct(t,s){try{const i=localStorage.getItem(`orgx.section.${t}`);if(i==="0")return!1;if(i==="1")return!0}catch{}return s}function Ft(t,s){try{localStorage.setItem(`orgx.section.${t}`,s?"1":"0")}catch{}}function ye({title:t,defaultOpen:s=!0,storageKey:i,children:d}){const[r,a]=h.useState(()=>i?Ct(i,s):s),o=()=>{const m=!r;a(m),i&&Ft(i,m)};return e.jsxs("div",{children:[e.jsxs("button",{type:"button",onClick:o,className:"flex w-full items-center gap-2 rounded-lg border border-transparent px-2 py-2 text-left transition-colors hover:border-white/[0.06] hover:bg-white/[0.03]",children:[e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",className:`text-white/30 transition-transform duration-200 ${r?"rotate-180":""}`,children:e.jsx("path",{d:"m6 9 6 6 6-6"})}),e.jsx("span",{className:"text-[11px] font-semibold tracking-[0.02em] text-white/68",children:t})]}),e.jsx(Ce,{initial:!1,children:r&&e.jsx(ie.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{type:"spring",stiffness:400,damping:35},className:"overflow-hidden",children:d})})]})}function St(t){if(!t)return{priorityNum:60,priorityLabel:null};const s=t.trim().toLowerCase();if(s==="urgent"||s==="p0")return{priorityNum:10,priorityLabel:"urgent"};if(s==="high"||s==="p1")return{priorityNum:25,priorityLabel:"high"};if(s==="medium"||s==="p2")return{priorityNum:50,priorityLabel:"medium"};if(s==="low"||s==="p3"||s==="p4")return{priorityNum:75,priorityLabel:"low"};const i=Number(s.replace(/^p/,""));return Number.isFinite(i)?{priorityNum:Math.max(1,Math.min(100,Math.round(i))),priorityLabel:null}:{priorityNum:60,priorityLabel:null}}function At(t){const s=t.toLowerCase();return["todo","not_started","planned","pending","backlog"].includes(s)}function Bt(t){const s=t.toLowerCase();return["in_progress","active","running","queued"].includes(s)}function Dt(t,s){const i={id:t.id,type:"initiative",title:t.name,status:t.rawStatus??t.status,parentId:null,initiativeId:t.id,workstreamId:null,milestoneId:null,priorityNum:60,priorityLabel:null,dependencyIds:[],dueDate:t.targetDate??null,etaEndAt:t.targetDate??null,expectedDurationHours:40,expectedBudgetUsd:1500,assignedAgents:[],updatedAt:t.updatedAt??t.createdAt??null},r=(s.workstreams.length>0?s.workstreams:(t.workstreams??[]).map(c=>({id:c.id,name:c.name,summary:null,status:c.status,progress:null,initiativeId:t.id,createdAt:null}))).map(c=>({id:c.id,type:"workstream",title:c.name,status:c.status,parentId:t.id,initiativeId:t.id,workstreamId:c.id,milestoneId:null,priorityNum:50,priorityLabel:"medium",dependencyIds:[],dueDate:null,etaEndAt:null,expectedDurationHours:16,expectedBudgetUsd:300,assignedAgents:[],updatedAt:c.createdAt})),a=new Set(r.map(c=>c.id)),o=s.milestones.map(c=>({id:c.id,type:"milestone",title:c.title,status:c.status,parentId:c.workstreamId&&a.has(c.workstreamId)?c.workstreamId:t.id,initiativeId:t.id,workstreamId:c.workstreamId&&a.has(c.workstreamId)?c.workstreamId:null,milestoneId:c.id,priorityNum:50,priorityLabel:"medium",dependencyIds:[],dueDate:c.dueDate,etaEndAt:c.dueDate,expectedDurationHours:6,expectedBudgetUsd:120,assignedAgents:[],updatedAt:c.createdAt})),m=new Set(o.map(c=>c.id)),x=s.tasks.map(c=>{const f=St(c.priority),v=c.milestoneId&&m.has(c.milestoneId),k=c.workstreamId&&a.has(c.workstreamId);return{id:c.id,type:"task",title:c.title,status:c.status,parentId:v?c.milestoneId:k?c.workstreamId:t.id,initiativeId:t.id,workstreamId:k?c.workstreamId:null,milestoneId:v?c.milestoneId:null,priorityNum:f.priorityNum,priorityLabel:f.priorityLabel,dependencyIds:[],dueDate:c.dueDate,etaEndAt:c.dueDate,expectedDurationHours:2,expectedBudgetUsd:40,assignedAgents:[],updatedAt:c.createdAt}}),g=x.filter(c=>["todo","not_started","planned","pending","backlog"].includes(c.status.toLowerCase())).sort((c,f)=>{const v=c.priorityNum-f.priorityNum;if(v!==0)return v;const k=c.etaEndAt?Date.parse(c.etaEndAt):1/0,y=f.etaEndAt?Date.parse(f.etaEndAt):1/0;if(k!==y)return k-y;const N=c.updatedAt?Date.parse(c.updatedAt):0;return(f.updatedAt?Date.parse(f.updatedAt):0)-N}).map(c=>c.id);return{nodes:[i,...r,...o,...x],edges:[],recentTodos:g}}function Mt(t,s){if(!t)return new Set;const i=new Map(s.map(o=>[o.id,o])),d=new Map;for(const o of s)for(const m of o.dependencyIds){const x=d.get(m)??[];x.push(o.id),d.set(m,x)}const r=new Set,a=[t];for(;a.length>0;){const o=a.shift();if(r.has(o))continue;r.add(o);const m=i.get(o);if(m){for(const x of m.dependencyIds)r.has(x)||a.push(x);for(const x of d.get(o)??[])r.has(x)||a.push(x)}}return r}function It(t,s){return{id:t.id,name:t.title,summary:null,status:t.status,progress:null,initiativeId:s.id,createdAt:t.updatedAt}}function $t(t,s){return{id:t.id,title:t.title,description:null,status:t.status,dueDate:t.dueDate,initiativeId:s.id,workstreamId:t.workstreamId,createdAt:t.updatedAt}}function Et(t,s){return{id:t.id,title:t.title,description:null,status:t.status,priority:t.priorityLabel??`p${t.priorityNum}`,dueDate:t.dueDate,initiativeId:s.id,milestoneId:t.milestoneId,workstreamId:t.workstreamId,createdAt:t.updatedAt}}function Lt(t){return/unknown api endpoint/i.test(t)?"Graph API unavailable — showing session-derived data":/401|unauthorized/i.test(t)?"Auth expired — reconnect to load full data":/failed to list initiative/i.test(t)?"Initiative data unavailable":/failed to list workstream/i.test(t)?"Workstream data unavailable":/failed to list milestone/i.test(t)?"Milestone data unavailable":/failed to list task/i.test(t)?"Task data unavailable":/500 internal server/i.test(t)?"Server error — some data may be incomplete":/entity data partially unavailable/i.test(t)?"Entity data partially unavailable":t.length>80?t.slice(0,72).replace(/[^a-zA-Z0-9]$/,"")+"...":t}const he={hidden:{opacity:0,y:6},show:{opacity:1,y:0}};function je({label:t,value:s}){return e.jsxs("div",{className:"rounded-lg border border-white/[0.08] bg-white/[0.03] px-2.5 py-2",children:[e.jsx("div",{className:"text-[10px] text-white/45",children:t}),e.jsx("div",{className:"mt-0.5 text-[12px] font-semibold text-white/85",children:s})]})}function Tt({initiative:t}){var Te;const{expandedInitiatives:s,toggleExpanded:i,openModal:d,agentEntityMap:r,authToken:a,embedMode:o,mutations:m}=ue(),[x,g]=h.useState(!1),[c,f]=h.useState(null),[v,k]=h.useState(null),[y,N]=h.useState(!1),p=s.has(t.id),{graph:b,isLoading:D,degraded:l,error:M}=xt({initiativeId:t.id,authToken:a,embedMode:o,enabled:p}),{details:I,isLoading:G,error:te}=Ae({initiativeId:t.id,authToken:a,embedMode:o,enabled:p}),U=h.useMemo(()=>Dt(t,I),[t,I]),X=!!(b&&b.nodes.length>0),se=U.nodes.length>0,Z=!X&&se,E=Z?U.nodes:X?(b==null?void 0:b.nodes)??[]:U.nodes,Y=Z?U.edges:X?(b==null?void 0:b.edges)??[]:U.edges,J=Z?U.recentTodos:X?(b==null?void 0:b.recentTodos)??[]:U.recentTodos,K=l.some(j=>/401|unauthorized/i.test(j))||!!(M&&/401|unauthorized/i.test(M))||!!(te&&/401|unauthorized/i.test(te)),Q=M&&/unknown api endpoint/i.test(M)?"Graph API unavailable. Showing session-derived data.":M,z=te,w=[...l,...Q?[Q]:[],...z?[`Entity data partially unavailable: ${z}`]:[],...K?["OrgX auth is missing or expired in this local plugin instance. Reconnect in onboarding to load full workstreams/milestones/tasks."]:[]],P=h.useMemo(()=>new Map(E.map(j=>[j.id,j])),[E]),T=h.useMemo(()=>Mt(c,E),[c,E]),O=h.useMemo(()=>J.some(j=>P.has(j)),[P,J]);h.useEffect(()=>{var j;p&&!c&&E.length>0&&f(((j=E[0])==null?void 0:j.id)??null)},[p,E,c]);const L=((b==null?void 0:b.initiative.assignedAgents)??[]).map(j=>({id:j.id,name:j.name,confidence:"high"})),ne=r.get(t.id)??[],ce=L.length>0?L:ne,le=E.filter(j=>j.type==="task"),oe=le.filter(j=>Bt(j.status)).length,n=le.filter(j=>At(j.status)).length,S=le.filter(j=>ae(j.status)).length,u=t.status==="active"&&oe===0&&n>0?"paused":t.status,C=le.length>0?le:E.some(j=>j.type==="milestone")?E.filter(j=>j.type==="milestone"):E.filter(j=>j.type==="workstream"),A=Math.round(C.reduce((j,V)=>j+(V.expectedDurationHours||0),0)*10)/10,$=Math.round(C.reduce((j,V)=>j+(V.expectedBudgetUsd||0),0)*100)/100,q=E.filter(j=>j.type==="milestone"),H=E.filter(j=>j.type==="workstream"),R=p&&(X||I.workstreams.length>0||I.milestones.length>0||I.tasks.length>0),W=le.length>0?de(S,le.length):q.length>0?de(q.filter(j=>ae(j.status)).length,q.length):R&&H.length>0?de(H.filter(j=>ae(j.status)).length,H.length):null,F=De(W===null?t.health:W),_=ut(t.targetDate),ee=_.tone==="danger"?"border-rose-400/35 bg-rose-500/10 text-rose-200":_.tone==="warning"?"border-amber-400/35 bg-amber-500/10 text-amber-200":_.tone==="success"?"border-emerald-400/35 bg-emerald-500/10 text-emerald-200":"border-white/[0.12] bg-white/[0.03] text-white/50",Xe=j=>{if(j.type==="initiative"){d({type:"initiative",entity:t});return}if(j.type==="workstream"){d({type:"workstream",entity:It(j,t),initiative:t});return}if(j.type==="milestone"){d({type:"milestone",entity:$t(j,t),initiative:t});return}d({type:"task",entity:Et(j,t),initiative:t})},Ze=async(j,V)=>{await m.updateEntity.mutateAsync({type:j.type,id:j.id,...V})},Le=j=>V=>{V.stopPropagation(),m.entityAction.mutate({type:"initiative",id:t.id,action:j})};return e.jsxs("div",{id:`initiative-${t.id}`,className:`surface-tier-1 overflow-hidden rounded-2xl transition-[background-color,border-color] duration-200 ${p?"bg-[--orgx-surface-elevated]":"bg-[--orgx-surface]"}`,children:[e.jsxs("div",{role:"button",tabIndex:0,"aria-expanded":p,onClick:()=>i(t.id),onKeyDown:j=>{(j.key==="Enter"||j.key===" ")&&(j.preventDefault(),i(t.id))},className:"group flex w-full cursor-pointer items-center gap-2.5 px-4 py-3 text-left transition-colors hover:bg-white/[0.035]",children:[e.jsx(ie.div,{animate:{rotate:p?90:0},transition:{type:"spring",stiffness:400,damping:25},className:"flex-shrink-0 flex items-center justify-center w-6 h-6 rounded-md transition-colors group-hover:bg-white/[0.06]",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",className:"text-white/40",children:e.jsx("path",{d:"m9 18 6-6-6-6"})})}),e.jsx("span",{className:`w-2 h-2 rounded-full flex-shrink-0 ${u==="active"?"status-breathe":""}`,style:{backgroundColor:_e(u)}}),e.jsx("button",{type:"button",onClick:j=>{j.stopPropagation(),d({type:"initiative",entity:t})},className:"min-w-0 flex-1 truncate text-[14px] font-semibold text-white transition-colors hover:text-white/80",title:t.name,children:t.name}),e.jsx("span",{className:`text-[10px] px-2 py-0.5 rounded-full border uppercase tracking-[0.08em] flex-shrink-0 ${Ye[u]}`,children:re(u)}),e.jsx("span",{className:`hidden md:inline-flex text-[10px] px-2 py-0.5 rounded-full border tracking-[0.06em] flex-shrink-0 ${ee}`,title:t.targetDate?new Date(t.targetDate).toLocaleDateString():"No target date",children:_.label}),e.jsxs("div",{className:"ml-2 flex min-w-[104px] items-center justify-end gap-1.5 sm:min-w-[220px] sm:gap-2",children:[e.jsx("div",{className:"w-[92px] sm:w-[156px]",children:e.jsx("div",{className:"h-[2px] w-full overflow-hidden rounded-full bg-white/[0.06]",children:e.jsx("div",{className:"h-full rounded-full transition-all",style:{width:`${F}%`,backgroundColor:_e(u)}})})}),e.jsxs("span",{className:"w-8 text-right text-[10px] text-white/40 sm:w-10 sm:text-[11px]",style:{fontVariantNumeric:"tabular-nums"},children:[F,"%"]})]}),e.jsx("div",{className:"ml-1 flex w-[64px] flex-shrink-0 items-center justify-end sm:w-[80px]",children:ce.length>0?e.jsx(Be,{agents:ce,max:5}):e.jsx("span",{className:"text-[10px] text-white/28",children:"—"})}),e.jsxs("div",{className:"flex w-[52px] flex-shrink-0 items-center justify-end gap-1 opacity-0 transition-opacity group-hover:opacity-100 group-focus-within:opacity-100 sm:w-[58px]",children:[u==="active"&&e.jsx("button",{type:"button",onClick:Le("pause"),title:"Pause",className:"flex items-center justify-center w-6 h-6 rounded-lg text-white/50 hover:text-white hover:bg-white/[0.08] transition-colors",children:e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"currentColor",children:[e.jsx("rect",{x:"6",y:"4",width:"4",height:"16",rx:"1"}),e.jsx("rect",{x:"14",y:"4",width:"4",height:"16",rx:"1"})]})}),u==="paused"&&e.jsx("button",{type:"button",onClick:Le("resume"),title:"Resume",className:"flex items-center justify-center w-6 h-6 rounded-lg text-white/50 hover:text-white hover:bg-white/[0.08] transition-colors",children:e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"currentColor",children:e.jsx("path",{d:"M8 5v14l11-7z"})})}),e.jsx("button",{type:"button",onClick:j=>{j.stopPropagation(),d({type:"initiative",entity:t})},title:"Details",className:"flex items-center justify-center w-6 h-6 rounded-lg text-white/50 hover:text-white hover:bg-white/[0.08] transition-colors",children:e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("path",{d:"M12 16v-4M12 8h.01"})]})})]})]}),e.jsx(Ce,{children:p&&e.jsx(ie.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{type:"spring",stiffness:400,damping:35},className:"overflow-hidden",children:e.jsxs("div",{className:"space-y-2.5 px-4 pb-4 pt-2.5",children:[e.jsx("div",{className:"section-divider"}),D||!X&&G?e.jsx("div",{className:"space-y-2",children:Array.from({length:3}).map((j,V)=>e.jsx(fe,{className:"h-24 w-full rounded-xl"},`mc-loading-${V}`))}):e.jsxs(ie.div,{initial:"hidden",animate:"show",variants:{hidden:{},show:{transition:{staggerChildren:.08}}},className:"space-y-3.5",children:[w.length>0&&e.jsxs(ie.div,{variants:he,className:"overflow-hidden rounded-lg border border-amber-300/15 bg-amber-500/[0.06]",children:[e.jsxs("button",{type:"button",onClick:()=>N(j=>!j),className:"flex w-full items-center justify-between px-3 py-2 text-left transition-colors hover:bg-white/[0.03]",children:[e.jsxs("span",{className:"text-[11px] text-amber-100/85",children:[w.length," data source",w.length>1?"s":""," unavailable"]}),e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",className:`text-amber-100/55 transition-transform ${y?"rotate-180":""}`,children:e.jsx("path",{d:"m6 9 6 6 6-6"})})]}),e.jsx(Ce,{children:y&&e.jsx(ie.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{duration:.15},className:"overflow-hidden",children:e.jsx("div",{className:"px-3 pb-2 space-y-1",children:w.map((j,V)=>e.jsx("div",{className:"text-[10px] text-amber-100/72",children:Lt(j)},V))})})})]}),(n>0||oe>0||A>0||$>0)&&e.jsx(ie.div,{variants:he,children:e.jsx(ye,{title:"Stats",storageKey:`stats.${t.id}`,defaultOpen:!0,children:e.jsxs("div",{className:"grid gap-2 py-0.5 sm:grid-cols-2 lg:grid-cols-4",children:[e.jsx(je,{label:"Queue",value:`${n} todo · ${oe} active`}),e.jsx(je,{label:"Completed",value:`${S}/${le.length||0}`}),e.jsx(je,{label:"Duration",value:`${A}h`}),e.jsx(je,{label:"Budget",value:`$${$.toLocaleString()}`})]})})}),v&&e.jsxs("div",{className:"subsection-shell flex items-center justify-between rounded-lg px-3 py-2 text-[11px] text-[#D8FFA1]",children:[e.jsxs("span",{children:["Focused on workstream ",((Te=P.get(v))==null?void 0:Te.title)??v]}),e.jsx("button",{type:"button",onClick:()=>k(null),className:"text-[10px] underline underline-offset-2",children:"Clear focus"})]}),e.jsx(ie.div,{variants:he,children:e.jsx(ye,{title:"Dependency Map",storageKey:`depmap.${t.id}`,defaultOpen:!0,children:e.jsx(ht,{nodes:E,edges:Y,selectedNodeId:c,focusedWorkstreamId:v,onSelectNode:j=>{f(j);const V=P.get(j);(V==null?void 0:V.type)==="workstream"&&k(V.id)}})})}),O&&e.jsx(ie.div,{variants:he,children:e.jsx(ye,{title:"Next Up",storageKey:`nextup.${t.id}`,defaultOpen:!0,children:e.jsx(kt,{recentTodoIds:J,nodesById:P,selectedNodeId:c,onSelectNode:j=>{f(j);const V=P.get(j);(V==null?void 0:V.type)==="workstream"&&k(V.id)}})})}),e.jsx(ie.div,{variants:he,children:e.jsx(ye,{title:"Hierarchy",storageKey:`hierarchy.${t.id}`,defaultOpen:!0,children:e.jsx(Nt,{nodes:E,edges:Y,selectedNodeId:c,highlightedNodeIds:T,editMode:x,onSelectNode:f,onFocusWorkstream:k,onOpenNode:Xe,onUpdateNode:Ze,onToggleEditMode:()=>g(j=>!j),mutations:m})})})]}),e.jsxs("button",{type:"button",onClick:()=>i(t.id),className:"flex w-full items-center justify-center gap-1.5 py-1.5 text-[10px] text-white/35 transition-colors hover:text-white/65",children:[e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:e.jsx("path",{d:"m18 15-6-6-6 6"})}),"Collapse"]})]})})})]})}const _t={hidden:{opacity:0},show:{opacity:1,transition:{staggerChildren:.04}}},Pt={hidden:{opacity:0,y:12},show:{opacity:1,y:0,transition:{type:"spring",stiffness:300,damping:30}}};function Oe({initiatives:t}){return e.jsx(ie.div,{variants:_t,initial:"hidden",animate:"show",className:"space-y-2",children:t.map(s=>e.jsx(ie.div,{variants:Pt,children:e.jsx(Tt,{initiative:s})},s.id))})}function Ot(){return e.jsx("div",{className:"flex-1 flex items-center justify-center p-12",children:e.jsx(st,{className:"max-w-sm p-8",children:e.jsxs("div",{className:"flex flex-col items-center text-center gap-4",children:[e.jsx("div",{className:"relative flex items-center justify-center h-16 w-16 rounded-2xl",style:{backgroundColor:`${B.iris}1a`,border:`1px solid ${B.iris}33`},children:e.jsxs("svg",{width:"28",height:"28",viewBox:"0 0 24 24",fill:"none",stroke:B.iris,strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("path",{d:"M12 6v6l4 2"})]})}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("h3",{className:"text-[14px] font-semibold text-white",children:"No initiatives yet"}),e.jsx("p",{className:"text-[12px] text-white/50 leading-relaxed",children:"Create initiatives in OrgX to see them here. Mission Control shows your full initiative hierarchy with workstreams, milestones, and tasks."})]})]})})})}function zt({initiative:t}){const{agentEntityMap:s,openModal:i,authToken:d,embedMode:r,mutations:a}=ue(),o=s.get(t.id)??[],[m,x]=h.useState(!1),[g,c]=h.useState(""),{details:f,isLoading:v}=Ae({initiativeId:t.id,authToken:d,embedMode:r}),k=f.tasks.filter(p=>["active","in_progress"].includes(p.status.toLowerCase())).length,y=f.tasks.filter(p=>p.status.toLowerCase()==="blocked").length,N=f.tasks.filter(p=>ae(p.status)).length;return e.jsxs("div",{className:"flex h-full w-full min-h-0 flex-col",children:[e.jsxs("div",{className:"min-h-0 flex-1 space-y-5 overflow-y-auto p-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("h2",{className:"text-[16px] font-semibold text-white",children:t.name}),e.jsx("span",{className:`text-[10px] px-2.5 py-0.5 rounded-full border uppercase tracking-[0.08em] ${Ye[t.status]}`,children:re(t.status)})]}),t.description&&e.jsx("p",{className:"text-[13px] text-white/50 leading-relaxed",children:t.description}),o.length>0&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[10px] text-white/30 uppercase tracking-wider",children:"Agents"}),e.jsx(Be,{agents:o,max:6})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3 sm:grid-cols-4",children:[e.jsx(ve,{label:"Workstreams",value:`${f.workstreams.length}`}),e.jsx(ve,{label:"Milestones",value:`${f.milestones.length}`}),e.jsx(ve,{label:"Active Tasks",value:`${k}`,accent:k>0?B.lime:void 0}),e.jsx(ve,{label:"Blocked",value:`${y}`,accent:y>0?B.red:void 0})]}),v?e.jsx("div",{className:"space-y-2",children:Array.from({length:3}).map((p,b)=>e.jsx(fe,{className:"h-14 w-full rounded-lg"},`init-detail-${b}`))}):e.jsxs(e.Fragment,{children:[f.workstreams.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(ze,{title:"Workstreams",count:f.workstreams.length}),f.workstreams.map(p=>{const b=f.tasks.filter(M=>M.workstreamId===p.id),D=b.filter(M=>ae(M.status)).length,l=b.length>0?de(D,b.length):typeof p.progress=="number"?De(p.progress<=1?p.progress*100:p.progress):ae(p.status)?100:null;return e.jsxs("button",{onClick:()=>i({type:"workstream",entity:p,initiative:t}),className:"w-full text-left rounded-xl border border-white/[0.08] bg-white/[0.03] p-3.5 transition-colors hover:bg-white/[0.06]",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-[12px] text-white/90 break-words",children:p.name}),e.jsx("span",{className:`text-[9px] px-1.5 py-0.5 rounded-full border uppercase tracking-[0.08em] ${Je(p.status)}`,children:re(p.status)})]}),e.jsxs("div",{className:"mt-1.5 flex items-center gap-3 text-[10px] text-white/35 uppercase tracking-[0.08em]",children:[e.jsxs("span",{children:[b.length," tasks"]}),l!==null&&e.jsxs("span",{children:[l,"%"]})]})]},p.id)})]}),f.milestones.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(ze,{title:"Milestones",count:f.milestones.length}),f.milestones.map(p=>e.jsxs("button",{onClick:()=>i({type:"milestone",entity:p,initiative:t}),className:"w-full text-left rounded-xl border border-white/[0.08] bg-white/[0.03] p-3 transition-colors hover:bg-white/[0.06]",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[12px] text-white/90 break-words",children:p.title}),e.jsx("span",{className:"text-[10px] text-white/40 uppercase tracking-[0.08em]",children:re(p.status)})]}),p.dueDate&&e.jsxs("span",{className:"text-[10px] text-white/30 mt-0.5 block",children:["Due: ",new Date(p.dueDate).toLocaleDateString()]})]},p.id))]}),e.jsxs("div",{className:"text-[10px] uppercase tracking-[0.08em] text-white/30 pt-2 border-t border-white/[0.06]",children:[f.tasks.length," total tasks · ",N," done"]})]})]}),e.jsx("div",{className:"border-t border-white/[0.06] bg-[#070b12]/85 px-6 py-3 backdrop-blur",children:e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.status==="active"&&e.jsx("button",{onClick:()=>a.entityAction.mutate({type:"initiative",id:t.id,action:"pause"}),disabled:a.entityAction.isPending,className:"text-[11px] px-3 py-1.5 rounded-lg border transition-colors disabled:opacity-50",style:{backgroundColor:`${B.amber}20`,color:B.amber,borderColor:`${B.amber}30`},children:"Pause"}),t.status==="paused"&&e.jsx("button",{onClick:()=>a.entityAction.mutate({type:"initiative",id:t.id,action:"resume"}),disabled:a.entityAction.isPending,className:"text-[11px] px-3 py-1.5 rounded-lg border transition-colors disabled:opacity-50",style:{backgroundColor:B.lime,color:"#05060A",borderColor:`${B.lime}CC`},children:"Resume"}),e.jsx("div",{className:"flex-1"}),m?e.jsxs("form",{className:"flex flex-wrap items-center gap-2",onSubmit:p=>{p.preventDefault(),g.trim()&&a.createEntity.mutate({type:"workstream",title:g.trim(),initiative_id:t.id,status:"not_started"},{onSuccess:()=>{c(""),x(!1)}})},children:[e.jsx("input",{type:"text",value:g,onChange:p=>c(p.target.value),placeholder:"Workstream name...",autoFocus:!0,className:"text-[12px] bg-white/5 border border-white/10 rounded-lg px-2.5 py-1.5 text-white/80 placeholder-white/30 w-[180px] outline-none focus:border-white/25"}),e.jsx("button",{type:"submit",disabled:!g.trim()||a.createEntity.isPending,className:"text-[11px] px-2.5 py-1 rounded-lg border disabled:opacity-50",style:{backgroundColor:`${B.lime}20`,color:B.lime,borderColor:`${B.lime}30`},children:"Add"}),e.jsx("button",{type:"button",onClick:()=>{x(!1),c("")},className:"text-[11px] px-2.5 py-1 rounded-lg bg-white/5 text-white/40 border border-white/10",children:"Cancel"})]}):e.jsx("button",{onClick:()=>x(!0),className:"text-[11px] px-3 py-1.5 rounded-lg border bg-white/5 text-white/50 border-white/10 hover:bg-white/10 transition-colors",children:"+ Workstream"})]})})]})}function ve({label:t,value:s,accent:i}){return e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-white/[0.03] px-3 py-2.5",style:i?{borderTopColor:`${i}50`,borderTopWidth:2}:void 0,children:[e.jsx("div",{className:"text-[10px] uppercase tracking-[0.08em] text-white/35",children:t}),e.jsx("div",{className:"text-[15px] font-medium mt-0.5",style:{color:i??"rgba(255,255,255,0.8)"},children:s})]})}function ze({title:t,count:s}){return e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-[11px] uppercase tracking-[0.08em] text-white/35",children:t}),e.jsx("span",{className:"text-[10px] text-white/30",children:s})]})}function Rt({workstream:t,initiative:s}){const{agentEntityMap:i,openModal:d,authToken:r,embedMode:a,mutations:o}=ue(),m=i.get(t.id)??i.get(s.id)??[],[x,g]=h.useState(!1),[c,f]=h.useState(""),{details:v,isLoading:k}=Ae({initiativeId:s.id,authToken:r,embedMode:a}),y=h.useMemo(()=>v.milestones.filter(l=>l.workstreamId===t.id),[v.milestones,t.id]),N=h.useMemo(()=>new Set(y.map(l=>l.id)),[y]),p=h.useMemo(()=>v.tasks.filter(l=>l.workstreamId===t.id||l.milestoneId!==null&&N.has(l.milestoneId)).sort((l,M)=>{const I=Fe(l.status)-Fe(M.status);if(I!==0)return I;const G=l.createdAt?Date.parse(l.createdAt):0;return(M.createdAt?Date.parse(M.createdAt):0)-G}),[v.tasks,N,t.id]),b=p.filter(l=>ae(l.status)).length,D=p.length>0?de(b,p.length):typeof t.progress=="number"?De(t.progress<=1?t.progress*100:t.progress):ae(t.status)?100:null;return e.jsxs("div",{className:"flex h-full w-full min-h-0 flex-col",children:[e.jsxs("div",{className:"min-h-0 flex-1 space-y-5 overflow-y-auto p-6",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-[11px]",children:[e.jsx("button",{onClick:()=>d({type:"initiative",entity:s}),className:"break-words text-white/45 transition-colors hover:text-white",children:s.name}),e.jsx("svg",{width:"8",height:"8",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"text-white/20",children:e.jsx("path",{d:"m9 18 6-6-6-6"})}),e.jsx("span",{className:"break-words font-medium text-white/70",children:t.name})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("h2",{className:"text-[16px] font-semibold text-white",children:t.name}),e.jsx("span",{className:`text-[10px] px-2.5 py-0.5 rounded-full border uppercase tracking-[0.08em] ${Je(t.status)}`,children:re(t.status)})]}),t.summary&&e.jsx("p",{className:"text-[13px] text-white/50 leading-relaxed",children:t.summary}),m.length>0&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[10px] text-white/30 uppercase tracking-wider",children:"Agents"}),e.jsx(Be,{agents:m,max:6})]})]}),D!==null&&e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx("span",{className:"text-[10px] text-white/30 uppercase tracking-wider",children:"Progress"}),e.jsxs("span",{className:"text-[12px] text-white/60",children:[D,"%"]})]}),e.jsx("div",{className:"h-1.5 w-full rounded-full bg-white/[0.06] overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full transition-all",style:{width:`${D}%`,backgroundColor:B.lime}})})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-3",children:[e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-white/[0.03] px-3 py-2.5",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-[0.08em] text-white/35",children:"Tasks"}),e.jsx("div",{className:"text-[15px] font-medium text-white/80 mt-0.5",children:p.length})]}),e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-white/[0.03] px-3 py-2.5",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-[0.08em] text-white/35",children:"Milestones"}),e.jsx("div",{className:"text-[15px] font-medium text-white/80 mt-0.5",children:y.length})]}),e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-white/[0.03] px-3 py-2.5",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-[0.08em] text-white/35",children:"Progress"}),e.jsx("div",{className:"text-[15px] font-medium text-white/80 mt-0.5",children:D!==null?`${D}%`:"—"})]})]}),k?e.jsx("div",{className:"space-y-2",children:Array.from({length:3}).map((l,M)=>e.jsx(fe,{className:"h-12 w-full rounded-lg"},`ws-detail-${M}`))}):e.jsxs(e.Fragment,{children:[y.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("span",{className:"text-[11px] uppercase tracking-[0.08em] text-white/35",children:"Milestones"}),y.map(l=>e.jsx("button",{onClick:()=>d({type:"milestone",entity:l,initiative:s}),className:"w-full text-left rounded-xl border border-white/[0.08] bg-white/[0.03] p-3 transition-colors hover:bg-white/[0.06]",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[12px] text-white/90",children:l.title}),e.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-full border uppercase tracking-[0.08em] ${Ke(l.status)}`,children:re(l.status)})]})},l.id))]}),p.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("span",{className:"text-[11px] uppercase tracking-[0.08em] text-white/35",children:["Tasks (",p.length,")"]}),p.map(l=>e.jsxs("button",{onClick:()=>d({type:"task",entity:l,initiative:s}),className:"w-full text-left rounded-xl border border-white/[0.08] bg-white/[0.03] p-3 transition-colors hover:bg-white/[0.06]",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-[12px] text-white/90",children:l.title}),e.jsx("span",{className:`text-[9px] px-1.5 py-0.5 rounded-full border uppercase tracking-[0.08em] flex-shrink-0 ${Ee(l.status)}`,children:re(l.status)})]}),l.priority&&e.jsxs("span",{className:"text-[10px] text-white/30 mt-0.5 block uppercase tracking-wider",children:["Priority: ",l.priority]})]},l.id))]})]})]}),e.jsx("div",{className:"border-t border-white/[0.06] bg-[#070b12]/85 px-6 py-3 backdrop-blur",children:e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.status==="not_started"&&e.jsx(xe,{label:"Start",color:B.lime,variant:"primary",onClick:()=>o.entityAction.mutate({type:"workstream",id:t.id,action:"start"}),disabled:o.entityAction.isPending}),t.status==="active"&&e.jsxs(e.Fragment,{children:[e.jsx(xe,{label:"Complete",color:B.teal,variant:"primary",onClick:()=>o.entityAction.mutate({type:"workstream",id:t.id,action:"complete"}),disabled:o.entityAction.isPending}),e.jsx(xe,{label:"Pause",color:B.amber,onClick:()=>o.entityAction.mutate({type:"workstream",id:t.id,action:"pause"}),disabled:o.entityAction.isPending}),e.jsx(xe,{label:"Block",color:B.red,variant:"destructive",onClick:()=>o.entityAction.mutate({type:"workstream",id:t.id,action:"block"}),disabled:o.entityAction.isPending})]}),(t.status==="paused"||t.status==="blocked")&&e.jsx(xe,{label:"Resume",color:B.lime,variant:"primary",onClick:()=>o.entityAction.mutate({type:"workstream",id:t.id,action:"resume"}),disabled:o.entityAction.isPending}),e.jsx("div",{className:"flex-1"}),x?e.jsxs("form",{className:"flex flex-wrap items-center gap-2",onSubmit:l=>{l.preventDefault(),c.trim()&&o.createEntity.mutate({type:"task",title:c.trim(),workstream_id:t.id,initiative_id:s.id,status:"todo"},{onSuccess:()=>{f(""),g(!1)}})},children:[e.jsx("input",{type:"text",value:c,onChange:l=>f(l.target.value),placeholder:"Task title...",autoFocus:!0,className:"text-[12px] bg-white/5 border border-white/10 rounded-lg px-2.5 py-1.5 text-white/80 placeholder-white/30 w-[160px] outline-none focus:border-white/25"}),e.jsx(xe,{label:"Add",color:B.lime,onClick:()=>{},disabled:!c.trim()||o.createEntity.isPending}),e.jsx("button",{type:"button",onClick:()=>{g(!1),f("")},className:"text-[11px] px-2.5 py-1 rounded-lg bg-white/5 text-white/40 border border-white/10",children:"Cancel"})]}):e.jsx("button",{onClick:()=>g(!0),className:"text-[11px] px-3 py-1.5 rounded-lg border bg-white/5 text-white/50 border-white/10 hover:bg-white/10 transition-colors",children:"+ Task"})]})})]})}function xe({label:t,color:s,onClick:i,disabled:d,variant:r="secondary"}){const a=r==="primary"?{backgroundColor:s,color:"#05060A",borderColor:`${s}CC`}:r==="destructive"?{backgroundColor:`${s}14`,color:s,borderColor:`${s}40`}:{backgroundColor:`${s}20`,color:s,borderColor:`${s}30`};return e.jsx("button",{onClick:i,disabled:d,className:"rounded-lg border px-3 py-1.5 text-[11px] transition-colors disabled:opacity-50",style:a,children:t})}function Wt({milestone:t,initiative:s}){var f;const{openModal:i,authToken:d,embedMode:r,mutations:a}=ue(),{details:o}=Ae({initiativeId:s.id,authToken:d,embedMode:r}),m=o.tasks.filter(v=>v.milestoneId===t.id),x=t.status.toLowerCase()==="done"||t.status.toLowerCase()==="completed",g=m.filter(v=>ae(v.status)).length,c=m.length>0?de(g,m.length):x?100:0;return e.jsxs("div",{className:"flex h-full w-full min-h-0 flex-col",children:[e.jsxs("div",{className:"min-h-0 flex-1 space-y-5 overflow-y-auto p-6",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-[11px]",children:[e.jsx("button",{onClick:()=>i({type:"initiative",entity:s}),className:"break-words text-white/45 transition-colors hover:text-white",children:s.name}),e.jsx("svg",{width:"8",height:"8",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"text-white/20",children:e.jsx("path",{d:"m9 18 6-6-6-6"})}),e.jsx("span",{className:"break-words font-medium text-white/70",children:t.title})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-3 h-3 rounded-full border flex-shrink-0",style:{backgroundColor:x?`${B.teal}99`:"rgba(255,255,255,0.1)",borderColor:x?`${B.teal}66`:"rgba(255,255,255,0.2)"}}),e.jsx("h2",{className:"text-[16px] font-semibold text-white",children:t.title}),e.jsx("span",{className:`text-[10px] px-2.5 py-0.5 rounded-full border uppercase tracking-[0.08em] ${Ke(t.status)}`,children:re(t.status)})]}),t.description&&e.jsx("p",{className:"text-[13px] text-white/50 leading-relaxed",children:t.description})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-3",children:[t.dueDate&&e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-white/[0.03] px-3 py-2.5",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-[0.08em] text-white/35",children:"Due Date"}),e.jsx("div",{className:"text-[13px] text-white/80 mt-0.5",children:new Date(t.dueDate).toLocaleDateString()})]}),e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-white/[0.03] px-3 py-2.5",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-[0.08em] text-white/35",children:"Associated Tasks"}),e.jsx("div",{className:"text-[15px] font-medium text-white/80 mt-0.5",children:m.length})]}),e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-white/[0.03] px-3 py-2.5",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-[0.08em] text-white/35",children:"Completion"}),e.jsxs("div",{className:"mt-1 flex items-center gap-2",children:[e.jsx("div",{className:"h-1.5 flex-1 rounded-full bg-white/[0.06] overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full transition-all",style:{width:`${c}%`,backgroundColor:B.teal}})}),e.jsxs("div",{className:"text-[12px] text-white/75",style:{fontVariantNumeric:"tabular-nums"},children:[c,"%"]})]}),e.jsxs("div",{className:"mt-1 text-[10px] text-white/35",children:[g,"/",m.length," done"]})]})]}),m.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("span",{className:"text-[11px] uppercase tracking-[0.08em] text-white/35",children:"Tasks"}),m.map(v=>e.jsx("button",{onClick:()=>i({type:"task",entity:v,initiative:s}),className:"w-full text-left rounded-xl border border-white/[0.08] bg-white/[0.03] p-3 transition-colors hover:bg-white/[0.06]",children:e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-[12px] text-white/90",children:v.title}),e.jsx("span",{className:`text-[9px] px-1.5 py-0.5 rounded-full border uppercase tracking-[0.08em] flex-shrink-0 ${Ee(v.status)}`,children:re(v.status)})]})},v.id))]})]}),e.jsx("div",{className:"border-t border-white/[0.06] bg-[#070b12]/85 px-6 py-3 backdrop-blur",children:e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[!x&&t.status.toLowerCase()==="planned"&&e.jsx("button",{onClick:()=>a.entityAction.mutate({type:"milestone",id:t.id,action:"start"}),disabled:a.entityAction.isPending,className:"text-[11px] px-3 py-1.5 rounded-lg border transition-colors disabled:opacity-50",style:{backgroundColor:B.lime,color:"#05060A",borderColor:`${B.lime}CC`},children:"Start"}),!x&&(t.status.toLowerCase()==="in_progress"||t.status.toLowerCase()==="at_risk")&&e.jsx("button",{onClick:()=>{const v=m.length===0||m.every(k=>ae(k.status));a.entityAction.mutate({type:"milestone",id:t.id,action:"complete",force:!v})},disabled:a.entityAction.isPending,className:"text-[11px] px-3 py-1.5 rounded-lg border transition-colors disabled:opacity-50",style:{backgroundColor:B.teal,color:"#05060A",borderColor:`${B.teal}CC`},children:m.length>0&&!m.every(v=>ae(v.status))?"Complete (force)":"Complete"}),x&&e.jsx("span",{className:"text-[11px] text-white/50",children:"Milestone is complete."}),a.entityAction.error&&e.jsx("span",{className:"text-[11px] ml-2",style:{color:`${B.red}b3`},children:(f=a.entityAction.error)==null?void 0:f.message})]})})]})}function qt({task:t,initiative:s}){var k,y;const{agentEntityMap:i,openModal:d,mutations:r,closeModal:a}=ue(),o=i.get(t.id)??i.get(s.id)??[],[m,x]=h.useState(!1),g=t.status.toLowerCase(),c=N=>{r.entityAction.mutate({type:"task",id:t.id,action:N},{onSuccess:()=>a()})},f=()=>{r.deleteEntity.mutate({type:"task",id:t.id},{onSuccess:()=>a()})},v=r.entityAction.isPending||r.deleteEntity.isPending;return e.jsxs("div",{className:"flex h-full w-full min-h-0 flex-col",children:[e.jsxs("div",{className:"min-h-0 flex-1 space-y-5 overflow-y-auto p-6",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-[11px]",children:[e.jsx("button",{onClick:()=>d({type:"initiative",entity:s}),className:"break-words text-white/45 transition-colors hover:text-white",children:s.name}),e.jsx("svg",{width:"8",height:"8",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"text-white/20",children:e.jsx("path",{d:"m9 18 6-6-6-6"})}),e.jsx("span",{className:"break-words font-medium text-white/70",children:t.title})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsx("h2",{className:"break-words text-[16px] font-semibold text-white",children:t.title}),e.jsx("span",{className:`text-[10px] px-2.5 py-0.5 rounded-full border uppercase tracking-[0.08em] ${Ee(t.status)}`,children:re(t.status)})]}),t.description&&e.jsx(nt,{text:t.description,mode:"block",className:"text-[13px] text-white/50 leading-relaxed"}),o.length>0&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[10px] text-white/30 uppercase tracking-wider",children:"Agents"}),e.jsx(Be,{agents:o,max:4})]})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-3",children:[e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-white/[0.03] px-3 py-2.5",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-[0.08em] text-white/35",children:"Status"}),e.jsx("div",{className:"text-[13px] text-white/80 mt-0.5",children:re(t.status)})]}),e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-white/[0.03] px-3 py-2.5",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-[0.08em] text-white/35",children:"Priority"}),e.jsx("div",{className:"text-[13px] text-white/80 mt-0.5",children:t.priority??"—"})]}),t.dueDate&&e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-white/[0.03] px-3 py-2.5",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-[0.08em] text-white/35",children:"Due Date"}),e.jsx("div",{className:"text-[13px] text-white/80 mt-0.5",children:new Date(t.dueDate).toLocaleDateString()})]})]}),(r.entityAction.error||r.deleteEntity.error)&&e.jsx("div",{className:"text-[11px] px-1",style:{color:`${B.red}b3`},children:((k=r.entityAction.error)==null?void 0:k.message)??((y=r.deleteEntity.error)==null?void 0:y.message)})]}),e.jsx("div",{className:"border-t border-white/[0.06] bg-[#070b12]/85 px-6 py-3 backdrop-blur",children:e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[g==="todo"&&e.jsx(me,{label:"Start",color:B.lime,variant:"primary",onClick:()=>c("start"),disabled:v}),(g==="in_progress"||g==="active")&&e.jsx(me,{label:"Complete",color:B.teal,variant:"primary",onClick:()=>c("complete"),disabled:v}),(g==="todo"||g==="in_progress"||g==="active")&&e.jsx(me,{label:"Block",color:B.red,variant:"destructive",onClick:()=>c("block"),disabled:v}),g==="blocked"&&e.jsx(me,{label:"Unblock",color:B.amber,onClick:()=>c("unblock"),disabled:v}),e.jsx("div",{className:"flex-1"}),m?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[11px]",style:{color:`${B.red}b3`},children:"Delete?"}),e.jsx(me,{label:"Yes",color:B.red,onClick:f,disabled:v}),e.jsx("button",{onClick:()=>x(!1),disabled:v,className:"text-[11px] px-3 py-1.5 rounded-lg border bg-white/5 text-white/50 border-white/10 hover:bg-white/10 transition-colors disabled:opacity-50",children:"No"})]}):e.jsx("button",{onClick:()=>x(!0),disabled:v,className:"text-[11px] px-3 py-1.5 rounded-lg border bg-white/5 text-white/40 border-white/10 transition-colors disabled:opacity-50",style:{"--hover-bg":`${B.red}20`},children:"Delete"})]})})]})}function me({label:t,color:s,onClick:i,disabled:d,variant:r="secondary"}){const a=r==="primary"?{backgroundColor:s,color:"#05060A",borderColor:`${s}CC`}:r==="destructive"?{backgroundColor:`${s}14`,color:s,borderColor:`${s}40`}:{backgroundColor:`${s}20`,color:s,borderColor:`${s}30`};return e.jsx("button",{onClick:i,disabled:d,className:"text-[11px] px-3 py-1.5 rounded-lg border transition-colors disabled:opacity-50 disabled:cursor-not-allowed",style:a,children:t})}function Vt(t){const s=[];return t.type!=="initiative"&&t.initiative&&s.push(t.initiative.name),t.type==="initiative"||t.type==="workstream"?s.push(t.entity.name):(t.type==="milestone"||t.type==="task")&&s.push(t.entity.title),s}function Ut({target:t,onClose:s}){return e.jsx(rt,{open:t!==null,onClose:s,maxWidth:"max-w-5xl",children:t&&e.jsxs("div",{className:"flex h-full w-full min-h-0 flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-white/[0.06] px-5 py-3 sm:px-6",children:[e.jsxs("div",{className:"flex items-center gap-1.5 min-w-0 text-[12px] text-white/50",children:[Vt(t).map((i,d,r)=>e.jsxs("span",{className:"flex items-center gap-1.5 min-w-0",children:[d>0&&e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",className:"flex-shrink-0 text-white/25",children:e.jsx("path",{d:"m9 18 6-6-6-6"})}),e.jsx("span",{className:`truncate ${d===r.length-1?"text-white/80 font-medium":""}`,children:i})]},d)),e.jsx("span",{className:"ml-1 rounded-full border border-white/[0.1] bg-white/[0.04] px-2 py-0.5 text-[10px] uppercase tracking-[0.06em] text-white/40",children:t.type})]}),e.jsx("button",{type:"button",onClick:s,"aria-label":"Close detail",className:"inline-flex h-9 w-9 flex-shrink-0 items-center justify-center rounded-full border border-white/[0.12] bg-white/[0.03] text-white/70 transition-colors hover:bg-white/[0.08] hover:text-white",children:e.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M18 6L6 18"}),e.jsx("path",{d:"M6 6l12 12"})]})})]}),e.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto",children:[t.type==="initiative"&&e.jsx(zt,{initiative:t.entity}),t.type==="workstream"&&e.jsx(Rt,{workstream:t.entity,initiative:t.initiative}),t.type==="milestone"&&e.jsx(Wt,{milestone:t.entity,initiative:t.initiative}),t.type==="task"&&e.jsx(qt,{task:t.entity,initiative:t.initiative})]})]})})}function Re(t){return(t??"").trim().toLowerCase().replace(/[\s-]+/g,"_")}function Qt(t){return t.split("_").map(s=>s.slice(0,1).toUpperCase()+s.slice(1)).join(" ")}const Ie=["active","in_progress","not_started","planned","blocked","at_risk","paused","completed","done","backlog","todo","pending","draft"],Ht=[{value:"target",label:"Target date"},{value:"created",label:"Created at"},{value:"updated",label:"Updated at"}],Gt=[{value:"any",label:"Any time"},{value:"missing",label:"No target date"},{value:"overdue",label:"Overdue"},{value:"today",label:"Today"},{value:"next_7_days",label:"Next 7 days"},{value:"next_30_days",label:"Next 30 days"},{value:"custom_range",label:"Custom range"}],Yt=[{value:"any",label:"Any time"},{value:"missing",label:"No timestamp"},{value:"today",label:"Today"},{value:"past_7_days",label:"Past 7 days"},{value:"past_30_days",label:"Past 30 days"},{value:"custom_range",label:"Custom range"}];function Jt({initiatives:t,visibleCount:s}){const{statusFilters:i,dateField:d,datePreset:r,dateStart:a,dateEnd:o,activeFilterCount:m,groupBy:x,setGroupBy:g,sortBy:c,setSortBy:f,setStatusFilters:v,toggleStatusFilter:k,setDateField:y,setDatePreset:N,setDateStart:p,setDateEnd:b,clearFilters:D}=ue(),[l,M]=h.useState(!1),[I,G]=h.useState(!1),te=h.useRef(null);h.useEffect(()=>{if(!l)return;const w=T=>{var L;const O=T.target;O&&((L=te.current)!=null&&L.contains(O)||M(!1))},P=T=>{T.key==="Escape"&&M(!1)};return document.addEventListener("mousedown",w),document.addEventListener("keydown",P),()=>{document.removeEventListener("mousedown",w),document.removeEventListener("keydown",P)}},[l]);const U=h.useMemo(()=>{const w=new Map;for(const T of t){const O=new Set([Re(T.status),Re(T.rawStatus)]);for(const L of O)L&&w.set(L,(w.get(L)??0)+1)}for(const T of Ie)w.has(T)||w.set(T,0);return Array.from(w.entries()).sort((T,O)=>{const L=Ie.indexOf(T[0]),ne=Ie.indexOf(O[0]);return L>=0&&ne>=0?L-ne:L>=0?-1:ne>=0?1:T[0].localeCompare(O[0])}).map(([T,O])=>({key:T,count:O}))},[t]),X=i.length,se=h.useMemo(()=>U.filter(w=>I||w.count>0||i.includes(w.key)),[I,i,U]),Z=U.length-se.length,E=h.useMemo(()=>d==="target"?Gt:Yt,[d]);h.useEffect(()=>{E.some(w=>w.value===r)||N("any")},[r,E,N]);const Y=[{value:"none",label:"None"},{value:"status",label:"Status"},{value:"date",label:"Date"},{value:"category",label:"Category"}],J=[{value:"default",label:"Default"},{value:"date_asc",label:"Date (earliest)"},{value:"date_desc",label:"Date (latest)"}],Q=m+(x!=="none"||c!=="default"?1:0),z=Q>0;return e.jsxs("div",{ref:te,className:"relative flex items-center gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>{M(w=>{const P=!w;return P||G(!1),P})},"data-state":l||Q>0?"active":"idle",className:"control-pill flex items-center gap-1.5 px-3 text-[11px] font-semibold",children:[e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{d:"M22 3H2l8 9.46V19l4 2v-8.54L22 3z"})}),e.jsx("span",{children:"Filters"}),Q>0&&e.jsx("span",{className:"inline-flex min-w-[16px] items-center justify-center rounded-full border border-current/30 bg-black/25 px-1 text-[10px] leading-4",children:Q})]}),s<t.length&&e.jsxs("span",{className:"text-[10px] text-white/35 whitespace-nowrap",children:[s,"/",t.length]}),z&&e.jsx("button",{type:"button",onClick:D,className:"text-[10px] text-white/40 hover:text-white/70 transition-colors whitespace-nowrap",children:"Clear"}),e.jsx(Ce,{children:l&&e.jsxs(ie.div,{initial:{opacity:0,y:-4,scale:.97},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:-4,scale:.97},transition:{duration:.16,ease:[.22,1,.36,1]},className:"surface-tier-2 absolute right-0 top-12 z-30 w-[360px] max-w-[94vw] rounded-xl p-3.5 shadow-[0_16px_40px_rgba(0,0,0,0.45)] backdrop-blur-xl",children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx("div",{className:"text-[11px] font-semibold tracking-[0.01em] text-white/85",children:"Filters"}),e.jsx("div",{className:"text-[10px] text-white/45",children:"Scope the Mission Control list view"})]}),e.jsxs("span",{className:"rounded-full border border-white/[0.12] bg-white/[0.04] px-2 py-0.5 text-[10px] text-white/70",children:[Q," active"]})]}),e.jsxs("div",{className:"subsection-shell p-2.5",children:[e.jsx("div",{className:"section-kicker mb-2",children:"Layout"}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("label",{className:"flex flex-col gap-1",children:[e.jsx("span",{className:"text-[10px] uppercase tracking-[0.08em] text-white/35",children:"Group"}),e.jsx("select",{value:x,onChange:w=>g(w.target.value),className:"h-9 rounded-lg border border-white/[0.08] bg-black/30 px-2 text-[11px] text-white/80 focus:border-[#BFFF00]/40 focus:outline-none",children:Y.map(w=>e.jsx("option",{value:w.value,children:w.label},w.value))})]}),e.jsxs("label",{className:"flex flex-col gap-1",children:[e.jsx("span",{className:"text-[10px] uppercase tracking-[0.08em] text-white/35",children:"Sort"}),e.jsx("select",{value:c,onChange:w=>f(w.target.value),className:"h-9 rounded-lg border border-white/[0.08] bg-black/30 px-2 text-[11px] text-white/80 focus:border-[#BFFF00]/40 focus:outline-none",children:J.map(w=>e.jsx("option",{value:w.value,children:w.label},w.value))})]})]})]}),e.jsxs("div",{className:"mt-2.5 subsection-shell p-2.5",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[e.jsx("div",{className:"section-kicker",children:"Status"}),Z>0&&e.jsx("button",{type:"button",onClick:()=>G(w=>!w),className:"text-[10px] text-white/42 transition-colors hover:text-white/72",children:I?"Hide empty":`Show empty (${Z})`})]}),e.jsx("div",{className:"max-h-40 space-y-1 overflow-auto pr-1",children:se.map(w=>{const P=i.includes(w.key);return e.jsxs("label",{className:`flex cursor-pointer items-center justify-between rounded-md border px-2.5 py-1.5 text-[11px] transition-colors ${P?"border-[#BFFF00]/30 bg-[#BFFF00]/10 text-white/88":"border-white/[0.08] bg-white/[0.02] text-white/78 hover:border-white/[0.15]"}`,children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"checkbox",checked:P,onChange:()=>k(w.key),className:"h-3.5 w-3.5 accent-[#BFFF00]"}),e.jsx("span",{children:Qt(w.key)})]}),e.jsx("span",{className:"text-[10px] text-white/48",children:w.count})]},w.key)})}),e.jsxs("div",{className:"mt-2 flex items-center justify-between",children:[e.jsx("button",{type:"button",onClick:()=>v([]),className:`text-[10px] uppercase tracking-[0.08em] ${X>0?"text-white/70 hover:text-white":"text-white/35"}`,disabled:X===0,children:"Clear status"}),e.jsxs("div",{className:"text-[10px] text-white/45",children:[X," selected"]})]})]}),e.jsxs("div",{className:"mt-2.5 subsection-shell p-2.5",children:[e.jsx("div",{className:"section-kicker mb-2",children:"Date"}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("label",{className:"flex flex-col gap-1",children:[e.jsx("span",{className:"text-[10px] uppercase tracking-[0.08em] text-white/45",children:"Field"}),e.jsx("select",{value:d,onChange:w=>y(w.target.value),className:"h-9 rounded-lg border border-white/[0.12] bg-black/30 px-2 text-[11px] text-white focus:border-[#BFFF00]/40 focus:outline-none",children:Ht.map(w=>e.jsx("option",{value:w.value,children:w.label},w.value))})]}),e.jsxs("label",{className:"flex flex-col gap-1",children:[e.jsx("span",{className:"text-[10px] uppercase tracking-[0.08em] text-white/45",children:"Condition"}),e.jsx("select",{value:r,onChange:w=>N(w.target.value),className:"h-9 rounded-lg border border-white/[0.12] bg-black/30 px-2 text-[11px] text-white focus:border-[#BFFF00]/40 focus:outline-none",children:E.map(w=>e.jsx("option",{value:w.value,children:w.label},w.value))})]})]}),r==="custom_range"&&e.jsxs("div",{className:"mt-2 grid grid-cols-2 gap-2",children:[e.jsxs("label",{className:"flex flex-col gap-1",children:[e.jsx("span",{className:"text-[10px] uppercase tracking-[0.08em] text-white/45",children:"Start"}),e.jsx("input",{type:"date",value:a,onChange:w=>p(w.target.value),className:"h-9 rounded-lg border border-white/[0.12] bg-black/30 px-2 text-[11px] text-white focus:border-[#BFFF00]/40 focus:outline-none"})]}),e.jsxs("label",{className:"flex flex-col gap-1",children:[e.jsx("span",{className:"text-[10px] uppercase tracking-[0.08em] text-white/45",children:"End"}),e.jsx("input",{type:"date",value:o,onChange:w=>b(w.target.value),className:"h-9 rounded-lg border border-white/[0.12] bg-black/30 px-2 text-[11px] text-white focus:border-[#BFFF00]/40 focus:outline-none"})]})]})]}),z&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"mt-2 section-divider"}),e.jsx("div",{className:"mt-2 flex justify-end",children:e.jsx("button",{type:"button",onClick:D,className:"text-[10px] uppercase tracking-[0.09em] text-white/55 transition-colors hover:text-white/85",children:"Clear all filters"})})]})]})})]})}function We(t){return(t??"").trim().toLowerCase().replace(/[\s-]+/g,"_")}function $e(t){return new Date(t.getFullYear(),t.getMonth(),t.getDate()).getTime()}function qe(t){if(!t)return null;const s=Date.parse(`${t}T00:00:00`);return Number.isFinite(s)?s:null}function Kt(t,s){return s==="target"?t.targetDate??null:s==="created"?t.createdAt??null:t.updatedAt??t.createdAt??null}function Xt(t,s){if(s==="status"){const i=new Map,d=["active","blocked","paused","completed"];for(const r of t){const a=r.status??"active",o=i.get(a)??[];o.push(r),i.set(a,o)}return d.filter(r=>i.has(r)).concat(Array.from(i.keys()).filter(r=>!d.includes(r))).map(r=>{var a;return{key:r,label:r.charAt(0).toUpperCase()+r.slice(1),count:((a=i.get(r))==null?void 0:a.length)??0,initiatives:i.get(r)??[]}})}if(s==="category"){const i=new Map;for(const d of t){const r=d.category??"Uncategorized",a=i.get(r)??[];a.push(d),i.set(r,a)}return Array.from(i.entries()).sort((d,r)=>d[0].localeCompare(r[0])).map(([d,r])=>({key:d,label:d,count:r.length,initiatives:r}))}if(s==="date"){const d=$e(new Date),r=d+7*864e5,a=d+30*864e5,o={overdue:[],this_week:[],this_month:[],later:[],no_date:[]};for(const x of t){const g=x.targetDate?Date.parse(x.targetDate):null;g===null||!Number.isFinite(g)?o.no_date.push(x):g<d?o.overdue.push(x):g<r?o.this_week.push(x):g<a?o.this_month.push(x):o.later.push(x)}const m={overdue:"Overdue",this_week:"This Week",this_month:"This Month",later:"Later",no_date:"No Date"};return["overdue","this_week","this_month","later","no_date"].filter(x=>o[x].length>0).map(x=>({key:x,label:m[x],count:o[x].length,initiatives:o[x]}))}return[]}function ge(t,s){return`${t}:${s}`}function Zt(t){return`mc-group-${t}`.toLowerCase().replace(/[^a-z0-9_-]+/g,"-")}function es(t,s){if(t.size!==s.size)return!1;for(const i of t)if(!s.has(i))return!1;return!0}function os({initiatives:t,activities:s,agents:i,isLoading:d,authToken:r,embedMode:a,initialInitiativeId:o,connection:m,lastSnapshotAt:x,error:g,hasApiKey:c,onOpenSettings:f,onRefresh:v}){const k=it({activities:s,agents:i,initiatives:t});return e.jsx(ot,{agentEntityMap:k,authToken:r,embedMode:a,children:e.jsx(ss,{initiatives:t,isLoading:d,initialInitiativeId:o,connection:m,lastSnapshotAt:x,error:g,hasApiKey:c,onOpenSettings:f,onRefresh:v})})}function ts(t){if(!t)return"unknown";const s=Date.parse(t);if(!Number.isFinite(s))return"unknown";try{return new Date(s).toLocaleString()}catch{return"unknown"}}function ss({initiatives:t,isLoading:s,initialInitiativeId:i,connection:d,lastSnapshotAt:r,error:a,hasApiKey:o,onOpenSettings:m,onRefresh:x}){var S;const{searchQuery:g,setSearchQuery:c,statusFilters:f,dateField:v,datePreset:k,dateStart:y,dateEnd:N,hasActiveFilters:p,groupBy:b,sortBy:D,expandedInitiatives:l,expandAll:M,collapseAll:I,modalTarget:G,closeModal:te,expandInitiative:U,authToken:X,embedMode:se}=ue(),Z=h.useRef(!1),E=at({initiativeId:null,authToken:X,embedMode:se,enabled:!0}),Y=((S=E.error)==null?void 0:S.toLowerCase().includes("404"))??!1,[J,K]=h.useState(new Set),Q=h.useMemo(()=>{const C=$e(new Date),A=g.toLowerCase().trim().split(/\s+/).filter(Boolean);return t.filter($=>{if(f.length>0&&![We($.status),We($.rawStatus)].filter(Boolean).some(ee=>f.includes(ee)))return!1;const q=Kt($,v),H=q?Date.parse(q):Number.NaN,R=Number.isFinite(H)?$e(new Date(H)):null,W=R===null?null:Math.round((R-C)/864e5);if(k==="missing"&&R!==null||k==="overdue"&&!(W!==null&&W<0)||k==="today"&&W!==0||k==="next_7_days"&&!(W!==null&&W>=0&&W<=7)||k==="next_30_days"&&!(W!==null&&W>=0&&W<=30)||k==="past_7_days"&&!(W!==null&&W<=0&&W>=-7)||k==="past_30_days"&&!(W!==null&&W<=0&&W>=-30))return!1;if(k==="custom_range"){const _=qe(y),ee=qe(N);if(R===null||_!==null&&R<_||ee!==null&&R>ee)return!1}if(A.length===0)return!0;const F=[$.name,$.description??"",$.status,$.rawStatus??"",$.category??""].join(" ").toLowerCase();return A.every(_=>F.includes(_))})},[t,g,f,v,k,y,N]),z=h.useMemo(()=>D==="default"?Q:[...Q].sort((u,C)=>{const A=u.targetDate?Date.parse(u.targetDate):Number.NaN,$=C.targetDate?Date.parse(C.targetDate):Number.NaN,q=Number.isFinite(A),H=Number.isFinite($);return!q&&!H?0:q?H?D==="date_asc"?A-$:$-A:-1:1}),[Q,D]),w=h.useMemo(()=>b!=="none"?Xt(z,b):null,[z,b]),P=h.useMemo(()=>(w==null?void 0:w.map(u=>ge(b,u.key)))??[],[b,w]),T=h.useCallback(u=>{K(C=>{const A=new Set(C);return A.has(u)?A.delete(u):A.add(u),A})},[]);h.useEffect(()=>{if(!w||w.length===0){K(C=>C.size===0?C:new Set);return}const u=new Set(w.map(C=>ge(b,C.key)));K(C=>{const A=new Set(Array.from(C).filter($=>u.has($)));return A.size===0&&A.add(ge(b,w[0].key)),es(A,C)?C:A})},[b,w]),h.useEffect(()=>{if(i&&!Z.current&&!s&&t.length>0){if(U(i),w){const u=w.find(C=>C.initiatives.some(A=>A.id===i));if(u){const C=ge(b,u.key);K(A=>{if(A.has(C))return A;const $=new Set(A);return $.add(C),$})}}Z.current=!0,requestAnimationFrame(()=>{const u=document.getElementById(`initiative-${i}`);u==null||u.scrollIntoView({behavior:"smooth",block:"start"})})}},[i,s,t.length,U,b,w]);const O=z.length>0&&l.size>=z.length,L=h.useMemo(()=>z.find(u=>u.status!=="completed")??z[0]??null,[z]),ne=!!(!s&&(d==="reconnecting"||d==="disconnected"||a)),ce=d==="disconnected"?"error":d==="reconnecting"||a?"warn":"info",le=o?d==="disconnected"?"Offline":d==="reconnecting"?"Reconnecting":a?"Live stream degraded":"Status":"Connect OrgX",oe=o?a||(d==="disconnected"?"Mission Control is offline. Data may be stale until OrgX reconnects.":"Live data is recovering. Some sections may lag."):"No OrgX API key configured. Connect to see Mission Control live updates.",n=ce==="error"?"border-red-400/25 bg-red-500/10 text-red-100":ce==="warn"?"border-amber-400/25 bg-amber-500/10 text-amber-100":"border-white/[0.08] bg-white/[0.03] text-white/70";return e.jsxs("div",{className:"flex-1 min-h-0 flex flex-col overflow-hidden",children:[e.jsxs("div",{className:"relative flex-1 min-h-0",children:[e.jsx("div",{className:"pointer-events-none absolute top-0 left-0 right-0 h-6 bg-gradient-to-b from-[#02040A] to-transparent z-10"}),e.jsx("div",{className:"pointer-events-none absolute bottom-0 left-0 right-0 h-12 bg-gradient-to-t from-[#02040A] to-transparent z-10"}),e.jsx("div",{className:"h-full overflow-y-auto overflow-x-hidden",children:e.jsxs("div",{className:"mx-auto max-w-6xl px-4 sm:px-6",children:[e.jsxs("div",{className:"sticky top-0 z-20 -mx-4 border-b border-white/[0.05] bg-[#02040A]/78 px-4 pb-2.5 pt-3.5 backdrop-blur-xl sm:-mx-6 sm:px-6",children:[ne&&e.jsx("div",{className:`mb-3 rounded-2xl border px-4 py-3 ${n}`,children:e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-2",children:[e.jsxs("div",{className:"min-w-[220px]",children:[e.jsx("div",{className:"text-[12px] font-semibold tracking-[-0.01em]",children:le}),e.jsx("div",{className:"mt-0.5 text-[12px] leading-relaxed opacity-90",children:oe}),e.jsxs("div",{className:"mt-1 text-[11px] opacity-70",children:["Last snapshot: ",ts(r)]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[x&&e.jsx("button",{type:"button",onClick:x,className:"h-9 rounded-full border border-white/[0.14] bg-white/[0.05] px-3 text-[11px] font-semibold text-white/80 transition-colors hover:bg-white/[0.1]",children:"Refresh"}),m&&e.jsx("button",{type:"button",onClick:m,className:"h-9 rounded-full border border-[#BFFF00]/30 bg-[#BFFF00]/15 px-3 text-[11px] font-semibold text-[#D8FFA1] transition-colors hover:bg-[#BFFF00]/20",children:"Settings"})]})]})}),e.jsxs("div",{className:"toolbar-shell flex flex-wrap items-center gap-2.5",children:[e.jsx("div",{className:"min-w-[240px] flex-1",children:e.jsx(He,{value:g,onChange:c,placeholder:"Search initiatives..."})}),e.jsx(Jt,{initiatives:t,visibleCount:Q.length}),e.jsxs("button",{type:"button",onClick:()=>{if(Y)return;(E.isRunning?E.stop:E.start)().catch(C=>{console.warn("[autopilot] toggle failed",C)})},disabled:Y||E.isStarting||E.isStopping,title:Y?"Autopilot unavailable in this environment":E.isRunning?"Stop Autopilot":"Start Autopilot","data-state":E.isRunning?"active":"idle","data-tone":"teal",className:"control-pill flex items-center gap-1.5 px-3 text-[11px] font-semibold disabled:opacity-40",children:[e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:E.isRunning?"status-breathe":"",children:e.jsx("path",{d:"M18.178 8c5.096 0 5.096 8 0 8-5.095 0-7.133-8-12.739-8-4.585 0-4.585 8 0 8 5.606 0 7.644-8 12.74-8Z"})}),e.jsx("span",{children:"Autopilot"}),Y&&e.jsx("span",{className:"text-[9px] uppercase tracking-[0.08em] text-white/45",children:"Off"}),E.isRunning&&e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-[#0AD4C4] status-breathe"})]}),z.length>0&&e.jsx("button",{type:"button",onClick:()=>{O?(I(),w&&P.length>0&&K(new Set)):(M(z.map(u=>u.id)),w&&P.length>0&&K(new Set(P)))},title:O?"Collapse all":"Expand all",className:"control-pill flex h-8 w-8 items-center justify-center text-white/55",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:O?e.jsxs(e.Fragment,{children:[e.jsx("path",{d:"M4 14h16"}),e.jsx("path",{d:"M4 10h16"})]}):e.jsxs(e.Fragment,{children:[e.jsx("path",{d:"M4 12h16"}),e.jsx("path",{d:"M12 4v16"})]})})})]})]}),!s&&L&&e.jsx("div",{className:"surface-hero mb-3.5 rounded-2xl p-3.5",children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-[220px]",children:[e.jsx("p",{className:"section-kicker",children:"Next action"}),e.jsx("p",{className:"mt-1 text-[14px] font-semibold text-white",children:L.name}),e.jsx("p",{className:"mt-1 text-[12px] text-white/65",children:L.status==="blocked"?"Blocked work needs a decision. Open this initiative and clear dependencies first.":L.status==="paused"?"Resume this initiative to restart queued workstreams and task execution.":"Open this initiative and work the top items in Next Up."})]}),e.jsx("button",{type:"button",onClick:()=>{U(L.id),requestAnimationFrame(()=>{const u=document.getElementById(`initiative-${L.id}`);u==null||u.scrollIntoView({behavior:"smooth",block:"start"})})},className:"control-pill px-3 text-[11px] font-semibold","data-state":"active",children:"Open initiative"})]})}),s?e.jsx("div",{className:"space-y-3 pb-8",children:Array.from({length:4}).map((u,C)=>e.jsxs("div",{className:"bg-[--orgx-surface] border border-[--orgx-border] soft-shadow rounded-2xl p-4",children:[e.jsx(fe,{className:"h-4 w-2/5 rounded"}),e.jsx(fe,{className:"h-1 w-full rounded mt-3"})]},`mc-skeleton-${C}`))}):t.length===0?o?e.jsx("div",{className:"pb-8",children:e.jsx(Ot,{})}):e.jsx("div",{className:"pb-8",children:e.jsxs("div",{className:"rounded-2xl border border-white/[0.08] bg-white/[0.02] px-6 py-8 text-center",children:[e.jsx("div",{className:"text-[14px] font-semibold text-white/85",children:"Connect OrgX to get started"}),e.jsx("div",{className:"mt-1 text-[12px] text-white/55",children:"Mission Control shows your initiative hierarchy once a user-scoped API key is configured."}),m&&e.jsx("div",{className:"mt-4 flex items-center justify-center",children:e.jsx("button",{type:"button",onClick:m,className:"h-10 rounded-full border border-[#BFFF00]/30 bg-[#BFFF00]/15 px-4 text-[12px] font-semibold text-[#D8FFA1] transition-colors hover:bg-[#BFFF00]/20",children:"Open settings"})})]})}):z.length===0?e.jsxs("div",{className:"rounded-2xl border border-white/[0.08] bg-white/[0.02] px-4 py-8 text-center pb-8",children:[e.jsx("div",{className:"text-[13px] font-medium text-white/85",children:"No initiatives match the current filters"}),e.jsx("div",{className:"mt-1 text-[12px] text-white/50",children:p?"Try adjusting status/date filters or clear them.":"Try a broader search phrase."})]}):w?e.jsx("div",{className:"space-y-4 pb-8",children:w.map(u=>{const C=ge(b,u.key),A=Zt(C),$=J.has(C);return e.jsxs("div",{children:[e.jsxs("button",{type:"button","aria-expanded":$,"aria-controls":A,onClick:()=>T(C),className:"mb-2 flex w-full items-center gap-2 rounded-xl border border-white/[0.075] bg-white/[0.016] px-3 py-2.5 text-left transition-colors hover:border-white/[0.16] hover:bg-white/[0.04]",children:[e.jsx("span",{"aria-hidden":!0,className:`inline-flex h-5 w-5 items-center justify-center rounded-md border border-white/[0.12] bg-white/[0.04] text-[11px] text-white/55 transition-transform ${$?"rotate-90":""}`,children:"▶"}),e.jsx("span",{className:"text-[12px] font-semibold text-white/80",children:u.label}),e.jsx("span",{className:"rounded-full border border-white/[0.1] bg-white/[0.04] px-2 py-0.5 text-[10px] text-white/55",children:u.count}),e.jsx("span",{className:"ml-auto text-[10px] uppercase tracking-[0.08em] text-white/45",children:$?"Hide":"Show"})]}),$&&e.jsx("div",{id:A,children:e.jsx(Oe,{initiatives:u.initiatives})})]},u.key)})}):e.jsx("div",{className:"pb-8",children:e.jsx(Oe,{initiatives:z})})]})})]}),e.jsx(Ut,{target:G,onClose:te})]})}export{os as MissionControlView};
@@ -0,0 +1 @@
1
+ import{r as o,j as e}from"./react-vendor-C2t2w4r2.js";import{r as P,P as T,c as C,f as D,g as K,a as _}from"./index-CoLgC4zE.js";import"./tanstack-C-KIc3Wc.js";import"./vendor-C-AHK0Ly.js";import"./motion-CVDprFZg.js";const O=/^[0-9a-f-]{20,}$/i;function X(h){if(h.runId)return h.runId;const t=h.metadata;if(!t)return null;const u=["runId","run_id","sessionId","session_id","agentRunId"];for(const p of u){const c=t[p];if(typeof c=="string"&&c.trim().length>0)return c.trim()}return null}const ee=o.memo(function({session:t,activity:u,initiatives:p=[],onContinueHighestPriority:c,onDispatchSession:b,onPauseSession:g,onResumeSession:f,onCancelSession:w,onCreateCheckpoint:j,onRollbackSession:v,onStartInitiative:B,onStartWorkstream:N}){const[i,L]=o.useState(null),[y,E]=o.useState(null),[m,q]=o.useState(!1),x=o.useMemo(()=>t?u.filter(r=>X(r)===t.runId).sort((r,l)=>Date.parse(l.timestamp)-Date.parse(r.timestamp)).slice(0,8):[],[u,t]),A=o.useMemo(()=>{var n;if(!t)return[];const r=[],l=t.initiativeId??t.groupId;if(l){const a=p.find(M=>M.id===l);a?r.push({label:"Initiative",value:a.name}):t.groupLabel&&t.groupLabel.trim().length>0&&r.push({label:"Initiative",value:t.groupLabel})}if(t.workstreamId){let a=null;for(const M of p){const U=(n=M.workstreams)==null?void 0:n.find(J=>J.id===t.workstreamId);if(U){a=U.name;break}}!a&&!O.test(t.workstreamId)&&(a=t.workstreamId),a&&r.push({label:"Workstream",value:a})}const d=t.phase??null;return d&&r.push({label:"Milestone",value:String(d)}),t.title&&r.push({label:"Task",value:t.title}),r},[p,t]),k=o.useMemo(()=>{var n,a;if(!t)return null;const r=((n=x[0])==null?void 0:n.summary)??((a=x[0])==null?void 0:a.description)??null,d=t.lastEventSummary??r??null;return d&&d.trim().length>0?d.trim():null},[x,t]),R=o.useMemo(()=>{var r;return t?P(t.agentName,t.title,t.lastEventSummary,k,(r=x[0])==null?void 0:r.metadata):P()},[x,t,k]),s=async(r,l,d)=>{if(!(!d||i)){L(r),E(null);try{await d(),E(`${l} requested.`)}catch(n){E(n instanceof Error?n.message:`${l} failed.`)}finally{L(null)}}};if(!t)return e.jsxs(T,{className:"flex h-full min-h-0 flex-col card-enter",children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-white/[0.06] px-4 py-3.5",children:[e.jsx("h2",{className:"text-[14px] font-semibold text-white",children:"Session Detail"}),e.jsx("button",{onClick:()=>q(r=>!r),className:"text-white/40 transition-colors hover:text-white/70","aria-label":m?"Expand session detail":"Collapse session detail",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:C("transition-transform",m?"-rotate-90":"rotate-0"),children:e.jsx("path",{d:"m6 9 6 6 6-6"})})})]}),e.jsx("div",{className:C("transition-all",m?"max-h-0 overflow-hidden":"min-h-0 flex-1"),children:e.jsxs("div",{className:"space-y-2 overflow-y-auto p-4 text-[12px] text-white/45",children:[e.jsx("p",{children:"Select a session to inspect summary, breadcrumbs, blockers, and recent messages."}),e.jsx("button",{onClick:()=>s("continue-priority","Continue highest priority",c),disabled:!c||!!i,className:"rounded-md border border-white/[0.12] bg-white/[0.04] px-3 py-1.5 text-[11px] text-white/70 transition-colors hover:bg-white/[0.08] disabled:opacity-45",children:i==="continue-priority"?"Dispatching…":"Continue highest priority"}),y&&e.jsx("p",{className:"text-[11px] text-white/55",children:y})]})})]});const $=t.progress===null?null:Math.round(t.progress),I=t.status.toLowerCase(),z=["running","active","queued","pending"].includes(I),Q=["paused","blocked","queued","pending"].includes(I),V=!["completed","archived","cancelled"].includes(I),F=!["archived","cancelled"].includes(I),G=[{label:"Started",value:t.startedAt?D(t.startedAt):"—"},{label:"Updated",value:t.updatedAt?D(t.updatedAt):"—"},{label:"ETA",value:t.eta??"—"},{label:"Checkpoints",value:t.checkpointCount!==null&&t.checkpointCount!==void 0?String(t.checkpointCount):"—"}];return e.jsxs(T,{className:"flex h-full min-h-0 flex-col card-enter",children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-white/[0.06] px-4 py-3.5",children:[e.jsx("h2",{className:"text-[14px] font-semibold text-white",children:"Session Detail"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"chip text-[11px] uppercase",children:t.status}),e.jsx("button",{onClick:()=>q(r=>!r),className:"text-white/40 transition-colors hover:text-white/70","aria-label":m?"Expand session detail":"Collapse session detail",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:C("transition-transform",m?"-rotate-90":"rotate-0"),children:e.jsx("path",{d:"m6 9 6 6 6-6"})})})]})]}),e.jsx("div",{className:C("transition-all",m?"max-h-0 overflow-hidden":"min-h-0 flex-1"),children:e.jsxs("div",{className:"space-y-3 overflow-y-auto p-4",children:[e.jsxs("div",{className:"flex items-start gap-2.5",children:[e.jsx(K,{provider:R.id,size:"sm"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"truncate text-[13px] font-medium text-white",children:t.title}),e.jsxs("p",{className:"mt-0.5 text-[11px] text-white/45",children:[t.agentName??"Unassigned"," · ",R.label]})]})]}),A.length>0&&e.jsxs("div",{className:"rounded-xl border border-white/[0.06] bg-white/[0.02] p-2.5",children:[e.jsx("p",{className:"mb-1.5 text-[10px] uppercase tracking-[0.1em] text-white/35",children:"Breadcrumb"}),e.jsx("div",{className:"flex flex-wrap items-center gap-1.5 text-[11px]",children:A.map((r,l)=>e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx("span",{className:"rounded-full border border-white/[0.12] bg-white/[0.02] px-1.5 py-0.5 text-white/65",children:r.value}),l<A.length-1&&e.jsx("span",{className:"text-[11px] text-white/40",children:"›"})]},`${r.label}-${r.value}`))})]}),k&&e.jsx("p",{className:"rounded-xl border border-white/[0.06] bg-white/[0.02] px-3 py-2 text-[12px] leading-relaxed text-white/65",children:k}),$!==null&&e.jsxs("div",{children:[e.jsxs("div",{className:"mb-1 flex items-center justify-between text-[11px] text-white/55",children:[e.jsx("span",{children:"Progress"}),e.jsxs("span",{children:[$,"%"]})]}),e.jsx("div",{className:"h-2 rounded-full bg-white/[0.08]",children:e.jsx("div",{className:"h-2 rounded-full",style:{width:`${$}%`,background:`linear-gradient(90deg, ${_.lime}, ${_.teal})`}})})]}),e.jsx("dl",{className:"grid grid-cols-1 gap-1 text-[11px] text-white/55 sm:grid-cols-2",children:G.map(r=>e.jsxs("div",{children:[e.jsx("dt",{className:"text-white/35",children:r.label}),e.jsx("dd",{className:"font-medium",children:r.value})]},r.label))}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"mb-1 text-[10px] uppercase tracking-[0.12em] text-white/40",children:"Quick actions"}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx("button",{onClick:()=>s("continue-priority","Continue highest priority",c),disabled:!c||!!i,className:"rounded-md border border-white/[0.12] bg-white/[0.03] px-3 py-2 text-[11px] text-white/75 transition-colors hover:bg-white/[0.08] disabled:opacity-45",children:i==="continue-priority"?"Dispatching…":"Continue Priority"}),e.jsx("button",{onClick:()=>s("dispatch-session","Dispatch session",()=>b==null?void 0:b(t)),disabled:!b||!!i,className:"rounded-md border border-lime/25 bg-lime/10 px-3 py-2 text-[11px] font-semibold text-lime transition-colors hover:bg-lime/20 disabled:opacity-45",children:i==="dispatch-session"?"Dispatching…":"Dispatch Session"})]})]}),e.jsxs("div",{children:[e.jsx("p",{className:"mb-1 text-[10px] uppercase tracking-[0.12em] text-white/40",children:"Session controls"}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx("button",{onClick:()=>s("pause-session","Pause session",()=>g==null?void 0:g(t)),disabled:!g||!z||!!i,className:"rounded-md border border-amber-400/30 bg-amber-400/10 px-3 py-2 text-[11px] font-semibold text-amber-300 transition-colors hover:bg-amber-400/20 disabled:opacity-45",children:i==="pause-session"?"Pausing…":"Pause"}),e.jsx("button",{onClick:()=>s("resume-session","Resume session",()=>f==null?void 0:f(t)),disabled:!f||!Q||!!i,className:"rounded-md border border-lime/25 bg-lime/10 px-3 py-2 text-[11px] font-semibold text-lime transition-colors hover:bg-lime/20 disabled:opacity-45",children:i==="resume-session"?"Resuming…":"Resume"}),e.jsx("button",{onClick:()=>s("checkpoint-session","Checkpoint created",()=>j==null?void 0:j(t)),disabled:!j||!!i,className:"rounded-md border border-sky-400/30 bg-sky-400/10 px-3 py-2 text-[11px] font-semibold text-sky-300 transition-colors hover:bg-sky-400/20 disabled:opacity-45",children:i==="checkpoint-session"?"Creating…":"Checkpoint"}),e.jsx("button",{onClick:()=>s("rollback-session","Rollback requested",()=>v==null?void 0:v(t)),disabled:!v||!F||!!i,className:"rounded-md border border-fuchsia-400/30 bg-fuchsia-400/10 px-3 py-2 text-[11px] font-semibold text-fuchsia-300 transition-colors hover:bg-fuchsia-400/20 disabled:opacity-45",children:i==="rollback-session"?"Rolling back…":"Rollback"}),e.jsx("button",{onClick:()=>s("cancel-session","Cancel session",()=>w==null?void 0:w(t)),disabled:!w||!V||!!i,className:"col-span-2 rounded-md border border-red-400/30 bg-red-400/10 px-3 py-2 text-[11px] font-semibold text-red-300 transition-colors hover:bg-red-400/20 disabled:opacity-45",children:i==="cancel-session"?"Cancelling…":"Cancel session"})]})]}),e.jsxs("div",{children:[e.jsx("p",{className:"mb-1 text-[10px] uppercase tracking-[0.12em] text-white/40",children:"Planning"}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx("button",{onClick:()=>s("start-initiative","Start initiative",B),disabled:!B||!!i,className:"rounded-md border border-white/[0.12] bg-white/[0.03] px-3 py-2 text-[11px] text-white/75 transition-colors hover:bg-white/[0.08] disabled:opacity-45",children:i==="start-initiative"?"Creating…":"New initiative"}),e.jsx("button",{onClick:()=>s("start-workstream","Start workstream",()=>N==null?void 0:N(t.initiativeId)),disabled:!N||!!i,className:"rounded-md border border-white/[0.12] bg-white/[0.03] px-3 py-2 text-[11px] text-white/75 transition-colors hover:bg-white/[0.08] disabled:opacity-45",children:i==="start-workstream"?"Creating…":"New workstream"})]})]})]}),y&&e.jsx("p",{className:"rounded-md border border-white/[0.08] bg-white/[0.02] px-2.5 py-1.5 text-[11px] text-white/55",children:y}),t.blockers.length>0&&e.jsxs("div",{className:"rounded-xl border border-red-500/30 bg-red-500/10 p-3",children:[e.jsx("h3",{className:"mb-1 text-[11px] uppercase tracking-[0.12em] text-red-200/70",children:"Blockers"}),e.jsx("ul",{className:"space-y-1 text-[12px] text-red-100/90",children:t.blockers.map(r=>e.jsxs("li",{children:["• ",r]},r))})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"mb-2 text-[11px] uppercase tracking-[0.12em] text-white/45",children:"Recent Messages"}),x.length===0&&e.jsx("p",{className:"text-[12px] text-white/45",children:"No recent messages for this run."}),e.jsx("div",{className:"space-y-2",children:x.map(r=>e.jsxs("article",{className:"rounded-lg border border-white/[0.06] bg-white/[0.02] px-2.5 py-2",children:[e.jsx("p",{className:"text-[11px] text-white/85",children:r.title}),(r.summary||r.description)&&e.jsx("p",{className:"mt-0.5 line-clamp-2 text-[11px] text-white/55",children:r.summary??r.description}),e.jsxs("p",{className:"mt-1 text-[10px] text-white/35",children:[new Date(r.timestamp).toLocaleString()," · ",D(r.timestamp)]})]},r.id))})]})]})})]})});export{ee as SessionInspector};