titan-agent 5.2.0 → 5.3.0

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 (112) hide show
  1. package/README.md +38 -8
  2. package/dist/eval/harness.js +49 -0
  3. package/dist/eval/harness.js.map +1 -1
  4. package/dist/eval/parity.js +148 -0
  5. package/dist/eval/parity.js.map +1 -0
  6. package/dist/eval/record.js +96 -0
  7. package/dist/eval/record.js.map +1 -0
  8. package/dist/gateway/metrics.js +20 -1
  9. package/dist/gateway/metrics.js.map +1 -1
  10. package/dist/gateway/server.js +5 -1
  11. package/dist/gateway/server.js.map +1 -1
  12. package/dist/utils/constants.js +1 -1
  13. package/dist/utils/constants.js.map +1 -1
  14. package/dist/utils/safety.js +31 -1
  15. package/dist/utils/safety.js.map +1 -1
  16. package/package.json +5 -1
  17. package/scripts/eval-gate.sh +189 -0
  18. package/scripts/eval-record.ts +133 -0
  19. package/ui/dist/assets/{AuditPanel-DLy0WJQZ.js → AuditPanel-C31LRHZX.js} +1 -1
  20. package/ui/dist/assets/{AutonomyPanel-DjFAQGns.js → AutonomyPanel-CxQU72ZY.js} +1 -1
  21. package/ui/dist/assets/{AutopilotPanel-nBluaHA4.js → AutopilotPanel-D4FnBwJm.js} +1 -1
  22. package/ui/dist/assets/{AutoresearchPanel-BDy8y_Cs.js → AutoresearchPanel-BYHXZ9AO.js} +1 -1
  23. package/ui/dist/assets/{BackupPanel-B_Fv2pJA.js → BackupPanel-C4CQKf2P.js} +1 -1
  24. package/ui/dist/assets/{BrowserPanel-DOCT3-Rq.js → BrowserPanel-C-OFYyLm.js} +1 -1
  25. package/ui/dist/assets/{CPAgents-CpkHf0b8.js → CPAgents-CvkZDm_3.js} +1 -1
  26. package/ui/dist/assets/{CPDashboard-CnMd6qNK.js → CPDashboard-JmBLBbj7.js} +1 -1
  27. package/ui/dist/assets/{CPFiles-BDRjJpYl.js → CPFiles-BDToRw0a.js} +1 -1
  28. package/ui/dist/assets/{CPGoals-2DrwHk62.js → CPGoals-Dh9qJNWa.js} +1 -1
  29. package/ui/dist/assets/{CPInbox-C6l2o4FD.js → CPInbox-B6iaIbNG.js} +1 -1
  30. package/ui/dist/assets/{CPSocial-Cea6NptR.js → CPSocial-CsFrwZRC.js} +1 -1
  31. package/ui/dist/assets/{ChannelsPanel-5EhhyXeg.js → ChannelsPanel-D-S4ktFn.js} +1 -1
  32. package/ui/dist/assets/{CheckpointsPanel-BVt2oEUe.js → CheckpointsPanel-D-sP9ZuS.js} +1 -1
  33. package/ui/dist/assets/{CommandPostHub-PXKE62DN.js → CommandPostHub-BhlNyeDH.js} +3 -3
  34. package/ui/dist/assets/{CronPanel-lAsoKavq.js → CronPanel-Bf3rV7N2.js} +1 -1
  35. package/ui/dist/assets/{DaemonPanel-xt08Rs10.js → DaemonPanel-GGBWjTG2.js} +1 -1
  36. package/ui/dist/assets/{DataTable-BHOu7fZP.js → DataTable-D2Px4o6f.js} +1 -1
  37. package/ui/dist/assets/{EmptyState-Dk7BBthD.js → EmptyState-DH6-Jy6A.js} +1 -1
  38. package/ui/dist/assets/EvalHarnessPanel-Cz9dRg61.js +2 -0
  39. package/ui/dist/assets/{EvalPanel-D9rDf1bk.js → EvalPanel-CdjxzHlJ.js} +1 -1
  40. package/ui/dist/assets/{FilesPanel-CNrDLmix.js → FilesPanel-Dz8TFydL.js} +1 -1
  41. package/ui/dist/assets/{FleetPanel-DP_ji0AE.js → FleetPanel-CWwWWTD4.js} +1 -1
  42. package/ui/dist/assets/{HomelabPanel-B4bCsrBw.js → HomelabPanel-C7VBV7AC.js} +1 -1
  43. package/ui/dist/assets/{InfraView-C5OYx_9s.js → InfraView-B1TgXARJ.js} +2 -2
  44. package/ui/dist/assets/{InlineEditableField-DyBCbIoN.js → InlineEditableField-DOJNOL8m.js} +1 -1
  45. package/ui/dist/assets/{Input-DWnbv1Yh.js → Input-BgyHgQ3D.js} +1 -1
  46. package/ui/dist/assets/{IntegrationsPanel-DsB6hjvE.js → IntegrationsPanel-O26b4nhv.js} +1 -1
  47. package/ui/dist/assets/{IntelligenceView-PIFGvIg_.js → IntelligenceView-DUhTQ8f_.js} +2 -2
  48. package/ui/dist/assets/{LearningPanel-D_S4HFX5.js → LearningPanel-DX5S9ovg.js} +1 -1
  49. package/ui/dist/assets/{LogsPanel-BnWNREPX.js → LogsPanel-DdeTnATQ.js} +1 -1
  50. package/ui/dist/assets/{McpPanel-CIMxZ2Am.js → McpPanel-BpXWrP1a.js} +1 -1
  51. package/ui/dist/assets/{MemoryGraphPanel-DD7x4rrm.js → MemoryGraphPanel-CNkZmTUy.js} +1 -1
  52. package/ui/dist/assets/{MemoryWikiPanel-BPPVAH0b.js → MemoryWikiPanel-o4L8Df-n.js} +1 -1
  53. package/ui/dist/assets/{MeshPanel-CiuwR3oV.js → MeshPanel-DMBQJFCC.js} +1 -1
  54. package/ui/dist/assets/{NvidiaPanel-DVntoRrH.js → NvidiaPanel-C8P-tJFG.js} +1 -1
  55. package/ui/dist/assets/{OrganismPanel-pqIKtHrW.js → OrganismPanel-CcfHDWDk.js} +1 -1
  56. package/ui/dist/assets/OverviewPanel-BSotI1Zv.js +1 -0
  57. package/ui/dist/assets/{PageHeader-CF75km05.js → PageHeader-DPJuAgJk.js} +1 -1
  58. package/ui/dist/assets/{PaperclipPanel-CwN5-cKg.js → PaperclipPanel-aXoXUjo6.js} +1 -1
  59. package/ui/dist/assets/{PersonasPanel-ClC_TTGX.js → PersonasPanel-DdPZxz2C.js} +1 -1
  60. package/ui/dist/assets/{RecipesPanel-Di2l-eOe.js → RecipesPanel-D7qffXQN.js} +1 -1
  61. package/ui/dist/assets/{SecurityPanel-DjC4pXGM.js → SecurityPanel-BDRK5el7.js} +1 -1
  62. package/ui/dist/assets/{SelfImprovePanel-CNpCp5N4.js → SelfImprovePanel-oYiMwFnA.js} +1 -1
  63. package/ui/dist/assets/{SelfProposalsPanel-BJL6Fjxo.js → SelfProposalsPanel-DOpNU_rr.js} +1 -1
  64. package/ui/dist/assets/{SessionsPanel-EAGKDQp0.js → SessionsPanel-eRbM3D9P.js} +1 -1
  65. package/ui/dist/assets/{SessionsTab-tc0njI15.js → SessionsTab-Jq3UKQCI.js} +1 -1
  66. package/ui/dist/assets/{SettingsPanel-BdSGImIa.js → SettingsPanel-DBIvKUYY.js} +1 -1
  67. package/ui/dist/assets/{SettingsView-DQB64bjy.js → SettingsView-yfSY4OLt.js} +2 -2
  68. package/ui/dist/assets/{SkeletonLoader-P8SFCyGi.js → SkeletonLoader-D1d-Gyyg.js} +1 -1
  69. package/ui/dist/assets/{SkillsPanel-lDMl_8da.js → SkillsPanel-bubl9nag.js} +1 -1
  70. package/ui/dist/assets/{SomaView-BG7YvBu2.js → SomaView-D3aFL8Tw.js} +1 -1
  71. package/ui/dist/assets/{StatCard-Cv2u-yqA.js → StatCard-CEVFsz7t.js} +1 -1
  72. package/ui/dist/assets/{StatusBadge-JJeoEdCm.js → StatusBadge-DxeA9LNd.js} +1 -1
  73. package/ui/dist/assets/{TeamsPanel-D-iCyyYd.js → TeamsPanel-D6IJJIR_.js} +1 -1
  74. package/ui/dist/assets/{TelemetryPanel-DHNFyCwn.js → TelemetryPanel-SMPebdjQ.js} +1 -1
  75. package/ui/dist/assets/{TitanCanvas-BhurNMK3.js → TitanCanvas-BQU1yxqf.js} +3 -3
  76. package/ui/dist/assets/ToolsView-DgP4uRPr.js +2 -0
  77. package/ui/dist/assets/{Tooltip-D4IeQDJL.js → Tooltip-CNPQr7IO.js} +1 -1
  78. package/ui/dist/assets/{TraceViewer-CMd-Wi0z.js → TraceViewer-BbISy_ET.js} +1 -1
  79. package/ui/dist/assets/{TrainingPanel-CLtiBq2h.js → TrainingPanel-BdCHcv6t.js} +1 -1
  80. package/ui/dist/assets/{VoiceOverlay-BXPVdnJc.js → VoiceOverlay-l6yoasVz.js} +1 -1
  81. package/ui/dist/assets/{VramPanel-DjuwGUzA.js → VramPanel-XLhmen92.js} +1 -1
  82. package/ui/dist/assets/{WatchView-B7sDnMpl.js → WatchView-Bt-lNNWJ.js} +1 -1
  83. package/ui/dist/assets/{WorkTab-B5nQ4Y7A.js → WorkTab-IG-F6Qll.js} +1 -1
  84. package/ui/dist/assets/{WorkflowsPanel-2z0TeXyR.js → WorkflowsPanel-DsMpnwLK.js} +1 -1
  85. package/ui/dist/assets/{arrow-left-BKOkzkae.js → arrow-left-C_H9Z2Tm.js} +1 -1
  86. package/ui/dist/assets/{chart-column-D39PCk17.js → chart-column-rR6tb72l.js} +1 -1
  87. package/ui/dist/assets/{circle-check-big-CMz0QouP.js → circle-check-big-B1hMwau0.js} +1 -1
  88. package/ui/dist/assets/{dollar-sign-Bu8fZOQl.js → dollar-sign-DhYwsTnR.js} +1 -1
  89. package/ui/dist/assets/{download-vvx6zJ-U.js → download-UDDcAlZC.js} +1 -1
  90. package/ui/dist/assets/{eye-off-BPXFIzlW.js → eye-off-Cx0M_VQb.js} +1 -1
  91. package/ui/dist/assets/{funnel-Bqns-i8I.js → funnel-B7YvM1ei.js} +1 -1
  92. package/ui/dist/assets/{git-branch-CdmeqL8d.js → git-branch-BhTBN3J6.js} +1 -1
  93. package/ui/dist/assets/index-D0RJ8701.css +1 -0
  94. package/ui/dist/assets/{index-C6oarzis.js → index-D7Clon2u.js} +2 -2
  95. package/ui/dist/assets/layers-B6jDzitD.js +6 -0
  96. package/ui/dist/assets/{legacy-DFIaZTiF.js → legacy-av079XKu.js} +1 -1
  97. package/ui/dist/assets/{lightbulb-DOL6Q-iP.js → lightbulb-DRuQ3Chf.js} +1 -1
  98. package/ui/dist/assets/{pause-B0XymOnS.js → pause-DqkRWPB_.js} +1 -1
  99. package/ui/dist/assets/{play-Dwp2l5HG.js → play-hUyR3CVS.js} +1 -1
  100. package/ui/dist/assets/{plug-DRlTjWqQ.js → plug-CvpyjJt_.js} +1 -1
  101. package/ui/dist/assets/{proxy-sXxWK7WF.js → proxy-Cc5bR828.js} +1 -1
  102. package/ui/dist/assets/{square-yh0jffQZ.js → square-CdiC0J8Z.js} +1 -1
  103. package/ui/dist/assets/{target-GxtNG2RW.js → target-DemL8_0v.js} +1 -1
  104. package/ui/dist/assets/{toggle-right-CYQd_Ux1.js → toggle-right-Dsk892k5.js} +1 -1
  105. package/ui/dist/assets/{trash-2-B4jp_pAQ.js → trash-2-Byj4OvKB.js} +1 -1
  106. package/ui/dist/assets/{trending-up-B26tNhFP.js → trending-up-Dh_CffGX.js} +1 -1
  107. package/ui/dist/assets/{trophy-Bf3ZeSeb.js → trophy-DDr2AePx.js} +1 -1
  108. package/ui/dist/index.html +2 -2
  109. package/ui/dist/assets/EvalHarnessPanel-CJv8CUDy.js +0 -1
  110. package/ui/dist/assets/OverviewPanel-gqYRhmpF.js +0 -6
  111. package/ui/dist/assets/ToolsView-C8sWxLny.js +0 -2
  112. package/ui/dist/assets/index-DsFoD9SP.css +0 -1
@@ -1 +1 @@
1
- import{r as t,aP as c,j as e,C as n,M as x}from"./index-C6oarzis.js";import{P as m}from"./PageHeader-CF75km05.js";import{R as o}from"./TitanCanvas-BhurNMK3.js";import"./VoiceOverlay-BXPVdnJc.js";function g(){const[s,r]=t.useState(null),[l,i]=t.useState(!0),d=t.useCallback(async()=>{i(!0);try{const a=await c();r(a)}catch{}i(!1)},[]);return t.useEffect(()=>{d()},[d]),e.jsxs("div",{className:"space-y-4",children:[e.jsx(m,{title:"VRAM Monitor",breadcrumbs:[{label:"Admin",href:"/overview"},{label:"Infra"},{label:"VRAM"}]}),e.jsx("div",{className:"flex gap-2",children:e.jsxs("button",{onClick:d,disabled:l,className:"flex items-center gap-2 px-3 py-2 rounded-lg bg-[#27272a] text-[#a1a1aa] text-sm font-medium hover:bg-[#3f3f46] disabled:opacity-50",children:[e.jsx(o,{className:`w-4 h-4 ${l?"animate-spin":""}`})," Refresh"]})}),(s==null?void 0:s.gpu)&&e.jsxs("div",{className:"p-3 rounded-lg bg-[#0a0a0f] border border-[#27272a]",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(n,{className:"w-4 h-4 text-[#6366f1]"}),e.jsx("span",{className:"text-sm font-medium text-[#e4e4e7]",children:s.gpu.gpuName}),e.jsxs("span",{className:"text-xs text-[#52525b]",children:["(",s.gpu.vendor,")"]})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-2 text-xs",children:[e.jsxs("div",{className:"p-2 rounded bg-[#27272a]/50",children:[e.jsx("div",{className:"text-[#52525b]",children:"Total"}),e.jsxs("div",{className:"text-[#e4e4e7]",children:[(s.gpu.totalMB/1024).toFixed(1)," GB"]})]}),e.jsxs("div",{className:"p-2 rounded bg-[#27272a]/50",children:[e.jsx("div",{className:"text-[#52525b]",children:"Used"}),e.jsxs("div",{className:"text-[#e4e4e7]",children:[(s.gpu.usedMB/1024).toFixed(1)," GB"]})]}),e.jsxs("div",{className:"p-2 rounded bg-[#27272a]/50",children:[e.jsx("div",{className:"text-[#52525b]",children:"Free"}),e.jsxs("div",{className:"text-[#e4e4e7]",children:[(s.gpu.freeMB/1024).toFixed(1)," GB"]})]})]}),e.jsx("div",{className:"mt-2 h-2 rounded-full bg-[#27272a] overflow-hidden",children:e.jsx("div",{className:"h-full bg-[#6366f1] rounded-full",style:{width:`${s.gpu.usedMB/s.gpu.totalMB*100}%`}})})]}),s&&s.activeLeases.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-sm font-medium text-[#e4e4e7]",children:"Active Leases"}),s.activeLeases.map(a=>e.jsxs("div",{className:"flex items-center justify-between p-2 rounded-lg bg-[#0a0a0f] border border-[#27272a]",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(x,{className:"w-3.5 h-3.5 text-[#6366f1]"}),e.jsx("span",{className:"text-xs text-[#e4e4e7]",children:a.service})]}),e.jsxs("span",{className:"text-xs text-[#52525b]",children:[(a.reservedMB/1024).toFixed(1)," GB"]})]},a.id))]})]})}export{g as default};
1
+ import{r as t,aP as c,j as e,C as n,M as x}from"./index-D7Clon2u.js";import{P as m}from"./PageHeader-DPJuAgJk.js";import{R as o}from"./TitanCanvas-BQU1yxqf.js";import"./VoiceOverlay-l6yoasVz.js";function g(){const[s,r]=t.useState(null),[l,i]=t.useState(!0),d=t.useCallback(async()=>{i(!0);try{const a=await c();r(a)}catch{}i(!1)},[]);return t.useEffect(()=>{d()},[d]),e.jsxs("div",{className:"space-y-4",children:[e.jsx(m,{title:"VRAM Monitor",breadcrumbs:[{label:"Admin",href:"/overview"},{label:"Infra"},{label:"VRAM"}]}),e.jsx("div",{className:"flex gap-2",children:e.jsxs("button",{onClick:d,disabled:l,className:"flex items-center gap-2 px-3 py-2 rounded-lg bg-[#27272a] text-[#a1a1aa] text-sm font-medium hover:bg-[#3f3f46] disabled:opacity-50",children:[e.jsx(o,{className:`w-4 h-4 ${l?"animate-spin":""}`})," Refresh"]})}),(s==null?void 0:s.gpu)&&e.jsxs("div",{className:"p-3 rounded-lg bg-[#0a0a0f] border border-[#27272a]",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(n,{className:"w-4 h-4 text-[#6366f1]"}),e.jsx("span",{className:"text-sm font-medium text-[#e4e4e7]",children:s.gpu.gpuName}),e.jsxs("span",{className:"text-xs text-[#52525b]",children:["(",s.gpu.vendor,")"]})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-2 text-xs",children:[e.jsxs("div",{className:"p-2 rounded bg-[#27272a]/50",children:[e.jsx("div",{className:"text-[#52525b]",children:"Total"}),e.jsxs("div",{className:"text-[#e4e4e7]",children:[(s.gpu.totalMB/1024).toFixed(1)," GB"]})]}),e.jsxs("div",{className:"p-2 rounded bg-[#27272a]/50",children:[e.jsx("div",{className:"text-[#52525b]",children:"Used"}),e.jsxs("div",{className:"text-[#e4e4e7]",children:[(s.gpu.usedMB/1024).toFixed(1)," GB"]})]}),e.jsxs("div",{className:"p-2 rounded bg-[#27272a]/50",children:[e.jsx("div",{className:"text-[#52525b]",children:"Free"}),e.jsxs("div",{className:"text-[#e4e4e7]",children:[(s.gpu.freeMB/1024).toFixed(1)," GB"]})]})]}),e.jsx("div",{className:"mt-2 h-2 rounded-full bg-[#27272a] overflow-hidden",children:e.jsx("div",{className:"h-full bg-[#6366f1] rounded-full",style:{width:`${s.gpu.usedMB/s.gpu.totalMB*100}%`}})})]}),s&&s.activeLeases.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-sm font-medium text-[#e4e4e7]",children:"Active Leases"}),s.activeLeases.map(a=>e.jsxs("div",{className:"flex items-center justify-between p-2 rounded-lg bg-[#0a0a0f] border border-[#27272a]",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(x,{className:"w-3.5 h-3.5 text-[#6366f1]"}),e.jsx("span",{className:"text-xs text-[#e4e4e7]",children:a.service})]}),e.jsxs("span",{className:"text-xs text-[#52525b]",children:[(a.reservedMB/1024).toFixed(1)," GB"]})]},a.id))]})]})}export{g as default};
@@ -1,4 +1,4 @@
1
- import{r as d,j as e,X as ee,b as Q,aG as te}from"./index-C6oarzis.js";import{A as q,m as G}from"./proxy-sXxWK7WF.js";const ne={purpose:"#a78bfa",hunger:"#fbbf24",curiosity:"#22d3ee",safety:"#34d399",social:"#f472b6"},ie={purpose:"Purpose",hunger:"Hunger",curiosity:"Curiosity",safety:"Safety",social:"Social"};function Y(t){return ne[t==null?void 0:t.toLowerCase()]||"#a1a1aa"}const se=new Set(["soma:proposal","turn:pre","tool:call","goal:subtask:ready","initiative:start","initiative:complete","pressure:threshold","goal:completed"]);function J(t,i=Date.now()){let n;if(typeof t=="number"&&!Number.isNaN(t)&&t>0)n=t;else if(typeof t=="string"){const h=Date.parse(t);n=Number.isNaN(h)?i:h}else n=i;const r=Math.max(0,Math.floor((i-n)/1e3));if(r<10)return"just now";if(r<60)return`${r}s ago`;const l=Math.floor(r/60);if(l<60)return`${l}m ago`;const o=Math.floor(l/60);return o<24?`${o}h ago`:`${Math.floor(o/24)}d ago`}const O=100,re=500;function X(){try{return localStorage.getItem("titan-token")||localStorage.getItem("titan_token")||""}catch{return""}}function ae(){const[t,i]=d.useState([]),[n,r]=d.useState([]),[l,o]=d.useState(!1),[h,y]=d.useState(!1),[s,m]=d.useState(0),[w,g]=d.useState(null),f=d.useRef(null),R=d.useCallback(x=>{if(!Array.isArray(x))return;const j=x.map(a=>{var S;return{id:a.id,label:a.label||ie[(S=a.id)==null?void 0:S.toLowerCase()]||a.id,satisfaction:a.satisfaction??1,setpoint:a.setpoint??.7,pressure:a.pressure??0,weight:a.weight,description:a.description}});i(j)},[]),M=d.useCallback(()=>{f.current&&f.current.close();const x=X(),j=`/api/watch/stream${x?`?token=${encodeURIComponent(x)}`:""}`,a=new EventSource(j);f.current=a;const S=Date.now();a.onopen=()=>{o(!0),y(!1)},a.onerror=()=>{o(!1),Date.now()-S>re&&y(!0)},a.onmessage=H=>{var T,N;try{const c=JSON.parse(H.data);if(c.type==="snapshot"){g({drives:c.drives||[],totalPressure:c.totalPressure||0,dominantDrives:c.dominantDrives||[],timestamp:c.timestamp||Date.now()}),R(c.drives);return}if(c.type==="event"){if(c.topic==="drive:tick"){const A=((T=c.raw)==null?void 0:T.drives)??[];R(A),m(Date.now());return}if(c.topic==="initiative:round"){const A=(N=c.raw)==null?void 0:N.subtaskTitle,F={id:c.id,timestamp:c.timestamp,topic:c.topic,kind:c.kind,icon:c.icon,captionTitan:c.captionTitan,captionControl:c.captionControl,detail:c.detail,raw:c.raw};r(v=>{const p=A?v.filter(b=>{var k;return!(b.topic==="initiative:round"&&((k=b.raw)==null?void 0:k.subtaskTitle)===A)}):v.filter(b=>b.topic!=="initiative:round"),D=[F,...p];return D.length>O&&(D.length=O),D}),m(Date.now());return}const $={id:c.id,timestamp:c.timestamp,topic:c.topic,kind:c.kind,icon:c.icon,captionTitan:c.captionTitan,captionControl:c.captionControl,detail:c.detail,raw:c.raw};r(A=>{const F=[$,...A];return F.length>O&&(F.length=O),F}),m(Date.now())}}catch{}}},[R]),I=d.useCallback(()=>{f.current&&f.current.close(),M()},[M]);return d.useEffect(()=>{const x=X(),j={};x&&(j.Authorization=`Bearer ${x}`),fetch("/api/watch/snapshot",{headers:j}).then(a=>a.status===401?(localStorage.removeItem("titan-token"),localStorage.removeItem("titan_token"),window.location.reload(),null):a.ok?a.json():null).then(a=>{a&&!a.error&&(g(a),R(a.drives))}).catch(()=>{})},[R]),d.useEffect(()=>(M(),()=>{var x;(x=f.current)==null||x.close(),f.current=null}),[M]),{drives:t,events:n,connected:l,reconnecting:h,lastActivity:s,snapshot:w,reconnect:I}}function oe(t){for(const i of t)if(se.has(i.topic))return i;return t[0]||null}function le({events:t,voice:i}){const n=d.useMemo(()=>oe(t),[t]),r=n?i==="titan"?n.captionTitan:n.captionControl:null;return e.jsxs("div",{style:{position:"relative",minHeight:80},children:[e.jsx("div",{style:{fontSize:10,textTransform:"uppercase",letterSpacing:"0.15em",color:"rgba(255, 255, 255, 0.35)",marginBottom:10,fontWeight:600},children:"What I'm doing"}),e.jsx(q,{mode:"wait",initial:!1,children:e.jsx(G.div,{initial:{opacity:0,y:4},animate:{opacity:1,y:0},exit:{opacity:0,y:-4},transition:{duration:.3},style:{fontSize:"clamp(18px, 2.4vw, 24px)",fontWeight:500,lineHeight:1.35,color:r?"rgba(255, 255, 255, 0.95)":"rgba(255, 255, 255, 0.45)"},children:r||"Standing by."},(n==null?void 0:n.id)||"idle")}),n&&e.jsxs("div",{style:{display:"flex",gap:12,marginTop:12,fontSize:11,color:"rgba(255, 255, 255, 0.35)",flexWrap:"wrap"},children:[e.jsx("span",{children:J(n.timestamp)}),n.detail&&e.jsxs("span",{children:["· ",n.detail]})]})]})}const ce={drive:"var(--color-purple-light)",soma:"#c084fc",tool:"#60a5fa",goal:"var(--color-emerald)",channel:"#fb7185",agent:"#c084fc",health:"#fbbf24",memory:"#e879f9",system:"#9ca3af"};function de({events:t,voice:i,onEventClick:n}){const[,r]=d.useState(0);d.useEffect(()=>{const o=setInterval(()=>r(h=>h+1),2e4);return()=>clearInterval(o)},[]);const l=d.useMemo(()=>t.slice(0,80),[t]);return l.length===0?e.jsx("div",{style:{color:"rgba(255,255,255,0.35)",fontSize:13,fontStyle:"italic",padding:"24px 16px",textAlign:"center"},children:"Listening for TITAN to do something…"}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:4,overflow:"hidden"},children:e.jsx(q,{initial:!1,children:l.map((o,h)=>{const y=i==="titan"?o.captionTitan:o.captionControl,s=ce[o.kind]||"#9ca3af",m=h===0;return e.jsxs(G.div,{initial:{opacity:0,y:-6},animate:{opacity:1,y:0},exit:{opacity:0,y:4},transition:{duration:.35,ease:"easeOut"},onClick:()=>n==null?void 0:n(o),style:{display:"flex",alignItems:"flex-start",gap:12,padding:"10px 12px",borderRadius:10,background:m?`${s}14`:"rgba(255, 255, 255, 0.015)",borderLeft:`2px solid ${s}`,fontSize:13,lineHeight:1.35,transition:"background 0.2s, transform 0.15s",cursor:n?"pointer":"default"},onMouseEnter:w=>{n&&(w.currentTarget.style.background=`${s}22`)},onMouseLeave:w=>{w.currentTarget.style.background=m?`${s}14`:"rgba(255, 255, 255, 0.015)"},title:`Click for details · ${o.topic}`,children:[e.jsx("div",{style:{fontSize:15,flexShrink:0,width:20,textAlign:"center",marginTop:1},children:o.icon}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsx("div",{style:{color:"rgba(255,255,255,0.92)"},children:y}),o.detail&&e.jsx("div",{style:{color:"rgba(255,255,255,0.45)",fontSize:11,marginTop:2,lineHeight:1.3},children:o.detail})]}),e.jsx("div",{style:{color:"rgba(255,255,255,0.35)",fontSize:11,flexShrink:0,fontVariantNumeric:"tabular-nums",whiteSpace:"nowrap",marginTop:1},children:J(o.timestamp)})]},o.id)})})})}function P(t,i){const n=t.match(/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i);return n?`rgba(${parseInt(n[1],16)}, ${parseInt(n[2],16)}, ${parseInt(n[3],16)}, ${i})`:`rgba(160, 160, 160, ${i})`}function pe({drives:t,excited:i=!1,reducedMotion:n=!1}){const r=d.useRef(null),l=d.useRef(t),o=d.useRef(i),h=d.useRef(null);return d.useEffect(()=>{l.current=t},[t]),d.useEffect(()=>{o.current=i},[i]),d.useEffect(()=>{const y=r.current;if(!y)return;const s=y.getContext("2d",{alpha:!0});if(!s)return;const m=Math.min(window.devicePixelRatio||1,2),w=()=>{const I=y.getBoundingClientRect();y.width=Math.max(2,I.width*m),y.height=Math.max(2,I.height*m),s.setTransform(m,0,0,m,0,0)};w();const g=new ResizeObserver(w);g.observe(y);const f=[],R=60,M=()=>{h.current=requestAnimationFrame(M);const I=y.getBoundingClientRect(),x=I.width,j=I.height;if(x<10||j<10)return;const a=x/2,S=j/2,H=Math.min(x,j)*.11,T=Math.min(x,j)*.34,N=performance.now()/1e3,c=l.current;s.clearRect(0,0,x,j);const $=s.createRadialGradient(a,S,0,a,S,Math.min(x,j)*.55),A=n?.08:.08+.03*Math.sin(N*.5);$.addColorStop(0,`rgba(255, 255, 255, ${A*2})`),$.addColorStop(.3,`rgba(167, 139, 250, ${A})`),$.addColorStop(1,"rgba(167, 139, 250, 0)"),s.fillStyle=$,s.fillRect(0,0,x,j);const F=Math.max(c.length,5);for(let v=0;v<c.length;v++){const p=c[v],D=v/F*Math.PI*2-Math.PI/2,b=a+Math.cos(D)*T,k=S+Math.sin(D)*T,W=Math.min(1,(p.pressure||0)*3),V=n?0:.35+W*1.4,_=n?0:.04+W*.15,z=H*(.75+_*Math.sin(N*V+v*1.3)),C=Y(p.id),E=z*2.8,B=s.createRadialGradient(b,k,0,b,k,E);B.addColorStop(0,P(C,.35)),B.addColorStop(.35,P(C,.18)),B.addColorStop(1,P(C,0)),s.fillStyle=B,s.beginPath(),s.arc(b,k,E,0,Math.PI*2),s.fill();const L=s.createRadialGradient(b-z*.3,k-z*.3,0,b,k,z);L.addColorStop(0,P(C,.95)),L.addColorStop(.55,P(C,.55)),L.addColorStop(1,P(C,.2)),s.fillStyle=L,s.beginPath(),s.arc(b,k,z,0,Math.PI*2),s.fill(),W>.1&&(s.strokeStyle=P(C,.6+.3*Math.sin(N*3+v)),s.lineWidth=1.5,s.beginPath(),s.arc(b,k,z*1.05,0,Math.PI*2),s.stroke()),s.font='600 10px -apple-system, BlinkMacSystemFont, "Inter", system-ui, sans-serif',s.textAlign="center",s.fillStyle="rgba(255,255,255,0.65)",s.fillText(p.label.toUpperCase(),b,k+z+18),s.font="11px -apple-system, system-ui",s.fillStyle="rgba(255,255,255,0.35)",s.fillText(`${Math.round((p.satisfaction||0)*100)}%`,b,k+z+32);const Z=W*.25+(o.current?.03:0);!n&&f.length<R&&Math.random()<Z&&f.push({sourceIdx:v,phase:0,color:C,size:2+Math.random()*2})}if(!n)for(let v=f.length-1;v>=0;v--){const p=f[v];if(p.phase+=.012,p.phase>=1){f.splice(v,1);continue}if(!c[p.sourceIdx]){f.splice(v,1);continue}const b=p.sourceIdx/F*Math.PI*2-Math.PI/2,k=a+Math.cos(b)*T,W=S+Math.sin(b)*T,V=(k+a)/2+Math.sin(b+Math.PI/2)*20,_=(W+S)/2+Math.cos(b+Math.PI/2)*20,z=(1-p.phase)*(1-p.phase)*k+2*(1-p.phase)*p.phase*V+p.phase*p.phase*a,C=(1-p.phase)*(1-p.phase)*W+2*(1-p.phase)*p.phase*_+p.phase*p.phase*S,E=Math.sin(p.phase*Math.PI)*.9;s.fillStyle=P(p.color,E),s.beginPath(),s.arc(z,C,p.size,0,Math.PI*2),s.fill()}if(!n){const p=N%20/20;if(p<.18){const D=H+p*Math.min(x,j)*2.5,b=(1-p/.18)*.18;s.strokeStyle=`rgba(167, 139, 250, ${b})`,s.lineWidth=1.5,s.beginPath(),s.arc(a,S,D,0,Math.PI*2),s.stroke()}}};return h.current=requestAnimationFrame(M),()=>{g.disconnect(),h.current&&cancelAnimationFrame(h.current)}},[n]),e.jsx("canvas",{ref:r,style:{width:"100%",height:"100%",display:"block"},"aria-label":"TITAN organism — 5 drives breathing"})}function he({event:t,voice:i,onClose:n}){return e.jsx(q,{children:t&&e.jsxs(e.Fragment,{children:[e.jsx(G.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:{duration:.18},onClick:n,style:{position:"fixed",inset:0,background:"rgba(0, 0, 0, 0.55)",backdropFilter:"blur(4px)",WebkitBackdropFilter:"blur(4px)",zIndex:99}},"backdrop"),e.jsx(G.aside,{initial:{x:"100%"},animate:{x:0},exit:{x:"100%"},transition:{duration:.28,ease:[.32,.72,0,1]},style:{position:"fixed",top:0,right:0,bottom:0,width:"min(540px, 100vw)",background:"rgba(10, 12, 20, 0.96)",backdropFilter:"blur(24px)",WebkitBackdropFilter:"blur(24px)",borderLeft:"1px solid rgba(167, 139, 250, 0.15)",display:"flex",flexDirection:"column",zIndex:100,color:"#f8f9fc",boxShadow:"-20px 0 60px rgba(0,0,0,0.5)"},role:"dialog","aria-modal":"true",children:e.jsx(ue,{event:t,voice:i,onClose:n})},"panel")]})})}function ue({event:t,voice:i,onClose:n}){const r=i==="titan"?t.captionTitan:t.captionControl,l=t.raw||{};return d.useEffect(()=>{const o=h=>{h.key==="Escape"&&n()};return window.addEventListener("keydown",o),()=>window.removeEventListener("keydown",o)},[n]),e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{padding:"20px 24px",borderBottom:"1px solid rgba(255,255,255,0.06)",display:"flex",alignItems:"flex-start",gap:12},children:[e.jsx("div",{style:{fontSize:22,width:36,height:36,borderRadius:10,background:"rgba(255,255,255,0.04)",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:t.icon}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsx("div",{style:{fontSize:17,fontWeight:600,lineHeight:1.3,marginBottom:4},children:r}),e.jsxs("div",{style:{fontSize:11,color:"rgba(255,255,255,0.35)",display:"flex",gap:10},children:[e.jsx("span",{children:J(t.timestamp)}),e.jsx("span",{style:{opacity:.5},children:"·"}),e.jsx("span",{style:{textTransform:"uppercase",letterSpacing:"0.1em"},children:t.kind}),e.jsx("span",{style:{opacity:.5},children:"·"}),e.jsx("span",{style:{fontFamily:"ui-monospace, monospace",fontSize:10},children:t.topic})]})]}),e.jsx("button",{onClick:n,"aria-label":"Close",style:{background:"transparent",border:0,color:"rgba(255,255,255,0.55)",cursor:"pointer",padding:6,borderRadius:8,display:"flex",alignItems:"center",justifyContent:"center"},children:e.jsx(ee,{size:18})})]}),e.jsxs("div",{style:{flex:1,overflowY:"auto",padding:"20px 24px",minHeight:0},children:[t.detail&&e.jsx(u,{label:"Detail",children:e.jsx("div",{style:{fontSize:13,color:"rgba(255,255,255,0.75)",lineHeight:1.5},children:t.detail})}),t.kind==="soma"&&e.jsx(ge,{raw:l}),t.kind==="goal"&&e.jsx(fe,{raw:l}),t.kind==="tool"&&e.jsx(xe,{raw:l,topic:t.topic}),t.kind==="channel"&&e.jsx(me,{raw:l,topic:t.topic}),t.kind==="drive"&&e.jsx(be,{raw:l,topic:t.topic}),(t.kind==="system"||t.kind==="agent"||t.kind==="memory"||t.kind==="health")&&e.jsx(ye,{raw:l,topic:t.topic})]}),e.jsx(ve,{label:"Raw event data",raw:l})]})}function u({label:t,children:i}){return e.jsxs("div",{style:{marginBottom:20},children:[e.jsx("div",{style:{fontSize:10,textTransform:"uppercase",letterSpacing:"0.15em",color:"rgba(255,255,255,0.35)",fontWeight:600,marginBottom:8},children:t}),i]})}function ge({raw:t}){const i=t.approvalId,n=t.dominantDrives||[],r=t.shadowVerdict;return e.jsxs(e.Fragment,{children:[e.jsx(u,{label:"What drove this",children:e.jsxs("div",{style:{fontSize:13,color:"rgba(255,255,255,0.75)"},children:[n.length?n.map(l=>l[0].toUpperCase()+l.slice(1)).join(", "):"an unspecified drive"," ","was below its setpoint. Soma filed this proposal autonomously."]})}),i&&e.jsx(u,{label:"Command Post approval",children:e.jsx("code",{style:{fontSize:11,color:"rgba(167, 139, 250, 0.9)"},children:i})}),r&&e.jsx(u,{label:"Shadow rehearsal verdict",children:e.jsx("pre",{style:{fontSize:11,lineHeight:1.4,color:"rgba(255,255,255,0.7)",whiteSpace:"pre-wrap",wordBreak:"break-word",background:"rgba(255,255,255,0.02)",padding:12,borderRadius:8},children:JSON.stringify(r,null,2)})})]})}function fe({raw:t}){const i=t.goalId,[n,r]=d.useState(null),[l,o]=d.useState(!1);if(d.useEffect(()=>{i&&(o(!0),Q(`/api/goals/${i}`).then(s=>s.ok?s.json():null).then(s=>r((s==null?void 0:s.goal)||s||null)).catch(()=>{}).finally(()=>o(!1)))},[i]),!i)return null;if(l)return e.jsx(u,{label:"Goal",children:e.jsx("div",{style:{color:"rgba(255,255,255,0.4)",fontSize:12},children:"Loading…"})});if(!n)return e.jsx(u,{label:"Goal",children:e.jsx("div",{style:{color:"rgba(255,255,255,0.4)",fontSize:12},children:"Goal not found (may have been deleted)."})});const h=n.subtasks||[],y=h.filter(s=>s.status==="done"||s.status==="skipped").length;return e.jsxs(u,{label:"Goal",children:[e.jsx("div",{style:{fontSize:14,fontWeight:600,marginBottom:6},children:String(n.title||"")}),e.jsxs("div",{style:{fontSize:11,color:"rgba(255,255,255,0.4)",marginBottom:12},children:[String(n.status||"")," · ",y,"/",h.length," subtasks"]}),h.length>0&&e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:6},children:h.map((s,m)=>e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,padding:"8px 10px",borderRadius:8,background:"rgba(255,255,255,0.02)",fontSize:12},children:[e.jsx("span",{style:{width:8,height:8,borderRadius:"50%",background:K(s.status),boxShadow:`0 0 6px ${K(s.status)}`,flexShrink:0}}),e.jsx("span",{style:{flex:1},children:String(s.title||"")}),e.jsx("span",{style:{fontSize:10,color:"rgba(255,255,255,0.35)",textTransform:"uppercase",letterSpacing:"0.1em"},children:String(s.status||"")})]},m))})]})}function K(t){switch(t){case"done":return"var(--color-emerald)";case"running":return"var(--color-cyan)";case"failed":return"var(--color-error)";case"skipped":return"var(--color-text-secondary)";case"pending":return"#fbbf24";default:return"#9ca3af"}}function xe({raw:t,topic:i}){const n=t.tool,r=t.argsPreview,l=t.durationMs,o=t.success;return e.jsxs(e.Fragment,{children:[n&&e.jsx(u,{label:"Tool",children:e.jsx("code",{style:{fontSize:12,color:"rgba(96, 165, 250, 0.9)"},children:n})}),r!==void 0&&e.jsx(u,{label:"Arguments",children:e.jsx("pre",{style:{fontSize:11,lineHeight:1.4,color:"rgba(255,255,255,0.7)",whiteSpace:"pre-wrap",wordBreak:"break-word",background:"rgba(255,255,255,0.02)",padding:12,borderRadius:8,maxHeight:300,overflowY:"auto"},children:typeof r=="string"?r:JSON.stringify(r,null,2)})}),i==="tool:result"&&e.jsx(u,{label:"Result",children:e.jsxs("div",{style:{fontSize:13,color:o?"rgba(52,211,153,0.9)":"rgba(239,68,68,0.9)"},children:[o?"✓ Completed":"✗ Failed",l!==void 0&&e.jsxs("span",{style:{color:"rgba(255,255,255,0.5)",marginLeft:8},children:["in ",l,"ms"]})]})})]})}function me({raw:t,topic:i}){const n=t.sessionId,r=t.channel,l=t.userId,o=t.message,h=t.toolsUsed||[],y=t.model,s=t.durationMs,[m,w]=d.useState(null);return d.useEffect(()=>{n&&Q(`/api/sessions/${n}`).then(g=>g.ok?g.json():null).then(g=>{const f=Array.isArray(g)?g:(g==null?void 0:g.messages)||[];w(f)}).catch(()=>{})},[n]),e.jsxs(e.Fragment,{children:[r&&e.jsx(u,{label:"Channel",children:e.jsxs("div",{style:{fontSize:13},children:[r,l&&e.jsxs("span",{style:{color:"rgba(255,255,255,0.4)"},children:[" · ",l]})]})}),o&&e.jsx(u,{label:i==="turn:pre"?"What they said":"Message",children:e.jsx("div",{style:{fontSize:13,lineHeight:1.5,color:"rgba(255,255,255,0.8)",padding:12,background:"rgba(255,255,255,0.02)",borderRadius:8},children:o})}),i==="turn:post"&&e.jsx(u,{label:"Turn stats",children:e.jsxs("div",{style:{fontSize:12,color:"rgba(255,255,255,0.55)",lineHeight:1.6},children:[s!==void 0&&e.jsxs("div",{children:["Took ",(s/1e3).toFixed(1),"s"]}),y&&e.jsxs("div",{children:["Model: ",y]}),h.length>0&&e.jsxs("div",{children:["Used: ",h.join(", ")]})]})}),m&&m.length>0&&e.jsx(u,{label:"Session messages",children:e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:10,maxHeight:400,overflowY:"auto"},children:m.slice(-8).map((g,f)=>e.jsxs("div",{style:{padding:10,borderRadius:8,background:g.role==="assistant"?"rgba(167, 139, 250, 0.06)":"rgba(255,255,255,0.02)",borderLeft:`2px solid ${g.role==="assistant"?"var(--color-purple-light)":"rgba(255,255,255,0.2)"}`,fontSize:12},children:[e.jsx("div",{style:{fontSize:10,textTransform:"uppercase",letterSpacing:"0.1em",color:"rgba(255,255,255,0.35)",marginBottom:4},children:String(g.role||"?")}),e.jsxs("div",{style:{color:"rgba(255,255,255,0.85)",lineHeight:1.5,whiteSpace:"pre-wrap"},children:[String(g.content||"").slice(0,400),String(g.content||"").length>400&&"…"]})]},f))})})]})}function be({raw:t,topic:i}){const n=t.drives||[],r=t.totalPressure,l=t.dominantDrives||[];return e.jsxs(e.Fragment,{children:[r!==void 0&&e.jsx(u,{label:"Pressure snapshot",children:e.jsxs("div",{style:{fontSize:13,color:"rgba(255,255,255,0.75)"},children:["Total: ",e.jsx("strong",{children:r.toFixed(3)}),l.length>0&&e.jsxs("span",{children:[" · Dominant: ",l.map(o=>o[0].toUpperCase()+o.slice(1)).join(", ")]})]})}),n.length>0&&i==="drive:tick"&&e.jsx(u,{label:"All drives this tick",children:e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:6},children:n.map((o,h)=>e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,padding:"8px 10px",borderRadius:8,background:"rgba(255,255,255,0.02)",fontSize:12},children:[e.jsx("span",{style:{flex:1,fontWeight:500},children:String(o.label||o.id)}),e.jsxs("span",{style:{color:"rgba(255,255,255,0.55)",fontVariantNumeric:"tabular-nums"},children:["sat ",(Number(o.satisfaction)*100).toFixed(0),"% · sp ",(Number(o.setpoint)*100).toFixed(0),"%"]}),e.jsx("span",{style:{color:Number(o.pressure)>0?"#fbbf24":"rgba(255,255,255,0.25)",fontVariantNumeric:"tabular-nums",width:50,textAlign:"right"},children:Number(o.pressure).toFixed(2)})]},h))})})]})}function ye({raw:t,topic:i}){if(i==="initiative:round"){const n=t.round,r=t.maxRounds,l=t.subtaskTitle;return e.jsx(u,{label:"What's happening",children:e.jsxs("div",{style:{fontSize:13,color:"rgba(255,255,255,0.8)",lineHeight:1.6},children:["TITAN is reasoning through round ",e.jsx("strong",{children:n})," of ",e.jsx("strong",{children:r}),l&&e.jsxs(e.Fragment,{children:[" on the subtask ",e.jsxs("em",{style:{color:"rgba(167, 139, 250, 0.9)"},children:['"',l,'"']})]}),".",e.jsx("br",{}),e.jsx("br",{}),"Each round is one tool-calling cycle — the agent thinks, picks a tool, runs it, then thinks again with the result. The cycle continues until the subtask is complete or the round budget runs out."]})})}if(i==="initiative:start"){const n=t.subtaskTitle,r=t.goalTitle;return e.jsx(u,{label:"What's happening",children:e.jsxs("div",{style:{fontSize:13,color:"rgba(255,255,255,0.8)",lineHeight:1.6},children:["TITAN picked up a task and started working.",n&&e.jsxs(e.Fragment,{children:[" Subtask: ",e.jsxs("em",{style:{color:"rgba(167, 139, 250, 0.9)"},children:['"',n,'"']}),"."]}),r&&e.jsxs(e.Fragment,{children:[" Part of goal: ",e.jsxs("em",{style:{color:"rgba(52, 211, 153, 0.9)"},children:['"',r,'"']}),"."]})]})})}if(i==="initiative:complete"){const n=t.success,r=t.toolsUsed||[],l=t.summary;return e.jsxs(u,{label:"Result",children:[e.jsxs("div",{style:{fontSize:13,color:"rgba(255,255,255,0.8)",lineHeight:1.6},children:[n===!1?"The task ran but ended without full success.":"Task complete.",r.length>0&&e.jsxs(e.Fragment,{children:[" Tools used: ",r.join(", "),"."]})]}),l&&e.jsx("div",{style:{marginTop:8,padding:10,borderRadius:8,background:"rgba(255,255,255,0.02)",fontSize:12,lineHeight:1.5,color:"rgba(255,255,255,0.7)"},children:l})]})}if(i==="initiative:no_progress"){const n=t.reason;return e.jsx(u,{label:"Why it paused",children:e.jsx("div",{style:{fontSize:13,color:"rgba(251, 191, 36, 0.9)",lineHeight:1.6},children:n||"Ran but couldn't advance."})})}if(i==="dreaming:consolidated")return e.jsx(u,{label:"What's happening",children:e.jsx("div",{style:{fontSize:13,color:"rgba(255,255,255,0.8)",lineHeight:1.6},children:"TITAN periodically consolidates recent memories — merging related facts, pruning stale ones, strengthening frequently-accessed associations. It's how it keeps the memory graph fast without losing useful context."})});if(i==="daemon:started"||i==="daemon:resumed")return e.jsx(u,{label:"What's happening",children:e.jsx("div",{style:{fontSize:13,color:"rgba(255,255,255,0.8)",lineHeight:1.6},children:"TITAN's background daemon came online. All watchers (goals, cron, health, memory, drive ticks, Facebook autopilot) are active."})});if(i==="daemon:paused")return e.jsx(u,{label:"What's happening",children:e.jsx("div",{style:{fontSize:13,color:"rgba(255,255,255,0.8)",lineHeight:1.6},children:"Background work is paused. Chat still works; cron, autopilot, and Soma ticks are halted until resumed."})});if(i.startsWith("health:"))return e.jsx(u,{label:"Health alert",children:e.jsx("div",{style:{fontSize:13,color:"rgba(251, 191, 36, 0.9)",lineHeight:1.6},children:"A subsystem reported a health issue. Check the Console tab for diagnostics."})});if(i==="agent:spawned"||i==="agent:stopped"){const n=t.name,r=t.model;return e.jsx(u,{label:"What's happening",children:e.jsxs("div",{style:{fontSize:13,color:"rgba(255,255,255,0.8)",lineHeight:1.6},children:[i==="agent:spawned"?"Spawned":"Stopped"," sub-agent",n&&e.jsxs(e.Fragment,{children:[" ",e.jsx("strong",{children:n})]}),r&&i==="agent:spawned"&&e.jsxs(e.Fragment,{children:[" running ",r]}),"."]})})}if(i==="agent:task:completed"||i==="agent:task:failed"){const n=t.agentId,r=t.reason,l=t.success;return e.jsx(u,{label:"Sub-agent result",children:e.jsxs("div",{style:{fontSize:13,color:"rgba(255,255,255,0.8)",lineHeight:1.6},children:[n&&e.jsxs(e.Fragment,{children:["Sub-agent ",e.jsx("strong",{children:n})," "]}),i==="agent:task:completed"&&l!==!1?"finished its task successfully.":r?`couldn't complete: ${r}.`:"did not complete its task."]})})}return e.jsx(je,{raw:t})}function je({raw:t}){const i=Object.entries(t||{}).filter(([n])=>n!=="timestamp");return i.length===0?null:e.jsx(u,{label:"Details",children:e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:6},children:i.slice(0,8).map(([n,r])=>e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",gap:12,padding:"6px 10px",borderRadius:6,background:"rgba(255,255,255,0.02)",fontSize:11},children:[e.jsx("span",{style:{color:"rgba(255,255,255,0.4)"},children:n}),e.jsx("span",{style:{color:"rgba(255,255,255,0.8)",fontFamily:"ui-monospace, monospace",textAlign:"right",wordBreak:"break-all"},children:Se(r)})]},n))})})}function Se(t){if(t==null)return"—";if(typeof t=="string")return t.length>80?t.slice(0,77)+"…":t;if(typeof t=="number"||typeof t=="boolean")return String(t);try{return JSON.stringify(t).slice(0,80)}catch{return"[object]"}}function ve({label:t,raw:i}){const[n,r]=d.useState(!1);return e.jsxs("div",{style:{borderTop:"1px solid rgba(255,255,255,0.06)"},children:[e.jsxs("button",{onClick:()=>r(l=>!l),style:{width:"100%",padding:"14px 24px",background:"transparent",border:0,color:"rgba(255,255,255,0.5)",fontSize:11,textTransform:"uppercase",letterSpacing:"0.15em",fontWeight:600,textAlign:"left",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsx("span",{children:t}),e.jsx("span",{style:{fontSize:14},children:n?"−":"+"})]}),n&&e.jsx("pre",{style:{margin:0,padding:"0 24px 20px",fontSize:10,lineHeight:1.4,color:"rgba(255,255,255,0.5)",whiteSpace:"pre-wrap",wordBreak:"break-word",maxHeight:300,overflowY:"auto"},children:JSON.stringify(i,null,2)})]})}function Ie(){var x,j;const[t]=te(),i=t.get("kiosk")==="1",n=t.get("voice")==="control"?"control":"titan",[r,l]=d.useState(n),[o,h]=d.useState(null),{drives:y,events:s,connected:m,reconnecting:w,lastActivity:g}=ae(),f=g>0&&Date.now()-g<1e4,R=typeof window<"u"&&((j=(x=window.matchMedia)==null?void 0:x.call(window,"(prefers-reduced-motion: reduce)"))==null?void 0:j.matches);d.useEffect(()=>{if(!i)return;let a=null;const S=async()=>{try{"wakeLock"in navigator&&(a=await navigator.wakeLock.request("screen"))}catch{}};S();const H=()=>{document.visibilityState==="visible"&&S()};return document.addEventListener("visibilitychange",H),()=>{var T;document.removeEventListener("visibilitychange",H),(T=a==null?void 0:a.release)==null||T.call(a)}},[i]);const M=d.useMemo(()=>m?"live":w?"reconnecting…":"connecting…",[m,w]),I=m?"var(--color-emerald)":w?"#fbbf24":"#6b7280";return e.jsxs("div",{style:{position:i?"fixed":"relative",inset:i?0:void 0,height:"100%",width:"100%",minHeight:i?"100vh":"100%",background:"radial-gradient(ellipse at 20% 30%, rgba(167, 139, 250, 0.06) 0%, transparent 55%), radial-gradient(ellipse at 80% 70%, rgba(34, 211, 238, 0.05) 0%, transparent 55%), radial-gradient(ellipse at 50% 50%, rgba(52, 211, 153, 0.03) 0%, transparent 60%), #05060a",color:"#f8f9fc",overflow:"hidden",fontFamily:'-apple-system, BlinkMacSystemFont, "SF Pro Text", Inter, system-ui, sans-serif',display:"flex",flexDirection:"column",zIndex:i?9999:void 0},children:[e.jsx("div",{"aria-hidden":!0,style:{position:"absolute",inset:0,opacity:.03,pointerEvents:"none",backgroundImage:`url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='200' height='200'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2'/></filter><rect width='200' height='200' filter='url(%23n)' opacity='0.8'/></svg>")`}}),e.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column",padding:i?"32px 40px":"20px 24px",minHeight:0,zIndex:1},children:[!i&&e.jsxs("header",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:16,fontSize:13},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,color:"rgba(255,255,255,0.5)",fontWeight:600,letterSpacing:"0.02em"},children:[e.jsx("div",{style:{width:8,height:8,borderRadius:"50%",background:I,boxShadow:`0 0 10px ${I}`,animation:"watch-pulse 2s ease-in-out infinite"}}),e.jsx("span",{children:"TITAN"}),e.jsx("span",{style:{opacity:.4},children:"·"}),e.jsx("span",{children:M})]}),e.jsx("div",{style:{display:"flex",gap:2,background:"rgba(20, 24, 36, 0.6)",border:"1px solid rgba(80, 90, 120, 0.25)",borderRadius:999,padding:2},children:["titan","control"].map(a=>e.jsx("button",{onClick:()=>l(a),style:{background:r===a?"#f8f9fc":"transparent",color:r===a?"#05060a":"rgba(255,255,255,0.55)",border:0,padding:"6px 14px",borderRadius:999,cursor:"pointer",fontSize:11,fontWeight:600,letterSpacing:"0.02em",transition:"all 0.15s",textTransform:"uppercase"},children:a==="titan"?"TITAN":"Mission"},a))})]}),e.jsxs("main",{style:{display:"grid",gridTemplateColumns:"minmax(0, 1.05fr) minmax(0, 1fr)",gridTemplateRows:"auto 1fr",gridTemplateAreas:'"focus activity" "organism activity"',gap:i?28:18,flex:1,minHeight:0},className:"watch-grid",children:[e.jsx(U,{gridArea:"focus",excited:f,children:e.jsx(le,{events:s,voice:r})}),e.jsxs(U,{gridArea:"organism",excited:f,padding:i?24:16,children:[e.jsx("div",{style:{fontSize:10,textTransform:"uppercase",letterSpacing:"0.15em",color:"rgba(255,255,255,0.35)",fontWeight:600,marginBottom:6},children:"How I'm feeling"}),e.jsx("div",{style:{flex:1,minHeight:i?320:220},children:e.jsx(pe,{drives:y,excited:f,reducedMotion:R})}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(90px, 1fr))",gap:8,marginTop:10,fontSize:11},children:y.map(a=>{const S=(a.pressure||0)>.01;return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,padding:"6px 10px",borderRadius:8,background:S?"rgba(251, 191, 36, 0.08)":"rgba(255,255,255,0.02)",border:`1px solid ${S?"rgba(251, 191, 36, 0.3)":"rgba(255,255,255,0.04)"}`},title:a.description||`${a.label}: satisfaction ${a.satisfaction.toFixed(2)}, setpoint ${a.setpoint.toFixed(2)}`,children:[e.jsx("div",{style:{width:8,height:8,borderRadius:"50%",background:Y(a.id),boxShadow:`0 0 8px ${Y(a.id)}`}}),e.jsx("div",{style:{flex:1,color:"rgba(255,255,255,0.65)",fontWeight:500},children:a.label}),e.jsxs("div",{style:{color:"rgba(255,255,255,0.35)",fontVariantNumeric:"tabular-nums"},children:[Math.round((a.satisfaction||0)*100),"%"]})]},a.id)})})]}),e.jsxs(U,{gridArea:"activity",excited:f,children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:12},children:[e.jsx("div",{style:{fontSize:10,textTransform:"uppercase",letterSpacing:"0.15em",color:"rgba(255,255,255,0.35)",fontWeight:600},children:"Recent activity"}),e.jsxs("div",{style:{fontSize:11,color:"rgba(255,255,255,0.35)",fontVariantNumeric:"tabular-nums"},children:[s.length," ",s.length===1?"event":"events"]})]}),e.jsx("div",{style:{flex:1,overflowY:"auto",minHeight:0,maskImage:"linear-gradient(to bottom, transparent 0, black 16px, black calc(100% - 16px), transparent 100%)",WebkitMaskImage:"linear-gradient(to bottom, transparent 0, black 16px, black calc(100% - 16px), transparent 100%)",paddingRight:4},children:e.jsx(de,{events:s,voice:r,onEventClick:h})})]})]})]}),e.jsx(he,{event:o,voice:r,onClose:()=>h(null)}),e.jsx("style",{children:`
1
+ import{r as d,j as e,X as ee,b as Q,aG as te}from"./index-D7Clon2u.js";import{A as q,m as G}from"./proxy-Cc5bR828.js";const ne={purpose:"#a78bfa",hunger:"#fbbf24",curiosity:"#22d3ee",safety:"#34d399",social:"#f472b6"},ie={purpose:"Purpose",hunger:"Hunger",curiosity:"Curiosity",safety:"Safety",social:"Social"};function Y(t){return ne[t==null?void 0:t.toLowerCase()]||"#a1a1aa"}const se=new Set(["soma:proposal","turn:pre","tool:call","goal:subtask:ready","initiative:start","initiative:complete","pressure:threshold","goal:completed"]);function J(t,i=Date.now()){let n;if(typeof t=="number"&&!Number.isNaN(t)&&t>0)n=t;else if(typeof t=="string"){const h=Date.parse(t);n=Number.isNaN(h)?i:h}else n=i;const r=Math.max(0,Math.floor((i-n)/1e3));if(r<10)return"just now";if(r<60)return`${r}s ago`;const l=Math.floor(r/60);if(l<60)return`${l}m ago`;const o=Math.floor(l/60);return o<24?`${o}h ago`:`${Math.floor(o/24)}d ago`}const O=100,re=500;function X(){try{return localStorage.getItem("titan-token")||localStorage.getItem("titan_token")||""}catch{return""}}function ae(){const[t,i]=d.useState([]),[n,r]=d.useState([]),[l,o]=d.useState(!1),[h,y]=d.useState(!1),[s,m]=d.useState(0),[w,g]=d.useState(null),f=d.useRef(null),R=d.useCallback(x=>{if(!Array.isArray(x))return;const j=x.map(a=>{var S;return{id:a.id,label:a.label||ie[(S=a.id)==null?void 0:S.toLowerCase()]||a.id,satisfaction:a.satisfaction??1,setpoint:a.setpoint??.7,pressure:a.pressure??0,weight:a.weight,description:a.description}});i(j)},[]),M=d.useCallback(()=>{f.current&&f.current.close();const x=X(),j=`/api/watch/stream${x?`?token=${encodeURIComponent(x)}`:""}`,a=new EventSource(j);f.current=a;const S=Date.now();a.onopen=()=>{o(!0),y(!1)},a.onerror=()=>{o(!1),Date.now()-S>re&&y(!0)},a.onmessage=H=>{var T,N;try{const c=JSON.parse(H.data);if(c.type==="snapshot"){g({drives:c.drives||[],totalPressure:c.totalPressure||0,dominantDrives:c.dominantDrives||[],timestamp:c.timestamp||Date.now()}),R(c.drives);return}if(c.type==="event"){if(c.topic==="drive:tick"){const A=((T=c.raw)==null?void 0:T.drives)??[];R(A),m(Date.now());return}if(c.topic==="initiative:round"){const A=(N=c.raw)==null?void 0:N.subtaskTitle,F={id:c.id,timestamp:c.timestamp,topic:c.topic,kind:c.kind,icon:c.icon,captionTitan:c.captionTitan,captionControl:c.captionControl,detail:c.detail,raw:c.raw};r(v=>{const p=A?v.filter(b=>{var k;return!(b.topic==="initiative:round"&&((k=b.raw)==null?void 0:k.subtaskTitle)===A)}):v.filter(b=>b.topic!=="initiative:round"),D=[F,...p];return D.length>O&&(D.length=O),D}),m(Date.now());return}const $={id:c.id,timestamp:c.timestamp,topic:c.topic,kind:c.kind,icon:c.icon,captionTitan:c.captionTitan,captionControl:c.captionControl,detail:c.detail,raw:c.raw};r(A=>{const F=[$,...A];return F.length>O&&(F.length=O),F}),m(Date.now())}}catch{}}},[R]),I=d.useCallback(()=>{f.current&&f.current.close(),M()},[M]);return d.useEffect(()=>{const x=X(),j={};x&&(j.Authorization=`Bearer ${x}`),fetch("/api/watch/snapshot",{headers:j}).then(a=>a.status===401?(localStorage.removeItem("titan-token"),localStorage.removeItem("titan_token"),window.location.reload(),null):a.ok?a.json():null).then(a=>{a&&!a.error&&(g(a),R(a.drives))}).catch(()=>{})},[R]),d.useEffect(()=>(M(),()=>{var x;(x=f.current)==null||x.close(),f.current=null}),[M]),{drives:t,events:n,connected:l,reconnecting:h,lastActivity:s,snapshot:w,reconnect:I}}function oe(t){for(const i of t)if(se.has(i.topic))return i;return t[0]||null}function le({events:t,voice:i}){const n=d.useMemo(()=>oe(t),[t]),r=n?i==="titan"?n.captionTitan:n.captionControl:null;return e.jsxs("div",{style:{position:"relative",minHeight:80},children:[e.jsx("div",{style:{fontSize:10,textTransform:"uppercase",letterSpacing:"0.15em",color:"rgba(255, 255, 255, 0.35)",marginBottom:10,fontWeight:600},children:"What I'm doing"}),e.jsx(q,{mode:"wait",initial:!1,children:e.jsx(G.div,{initial:{opacity:0,y:4},animate:{opacity:1,y:0},exit:{opacity:0,y:-4},transition:{duration:.3},style:{fontSize:"clamp(18px, 2.4vw, 24px)",fontWeight:500,lineHeight:1.35,color:r?"rgba(255, 255, 255, 0.95)":"rgba(255, 255, 255, 0.45)"},children:r||"Standing by."},(n==null?void 0:n.id)||"idle")}),n&&e.jsxs("div",{style:{display:"flex",gap:12,marginTop:12,fontSize:11,color:"rgba(255, 255, 255, 0.35)",flexWrap:"wrap"},children:[e.jsx("span",{children:J(n.timestamp)}),n.detail&&e.jsxs("span",{children:["· ",n.detail]})]})]})}const ce={drive:"var(--color-purple-light)",soma:"#c084fc",tool:"#60a5fa",goal:"var(--color-emerald)",channel:"#fb7185",agent:"#c084fc",health:"#fbbf24",memory:"#e879f9",system:"#9ca3af"};function de({events:t,voice:i,onEventClick:n}){const[,r]=d.useState(0);d.useEffect(()=>{const o=setInterval(()=>r(h=>h+1),2e4);return()=>clearInterval(o)},[]);const l=d.useMemo(()=>t.slice(0,80),[t]);return l.length===0?e.jsx("div",{style:{color:"rgba(255,255,255,0.35)",fontSize:13,fontStyle:"italic",padding:"24px 16px",textAlign:"center"},children:"Listening for TITAN to do something…"}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:4,overflow:"hidden"},children:e.jsx(q,{initial:!1,children:l.map((o,h)=>{const y=i==="titan"?o.captionTitan:o.captionControl,s=ce[o.kind]||"#9ca3af",m=h===0;return e.jsxs(G.div,{initial:{opacity:0,y:-6},animate:{opacity:1,y:0},exit:{opacity:0,y:4},transition:{duration:.35,ease:"easeOut"},onClick:()=>n==null?void 0:n(o),style:{display:"flex",alignItems:"flex-start",gap:12,padding:"10px 12px",borderRadius:10,background:m?`${s}14`:"rgba(255, 255, 255, 0.015)",borderLeft:`2px solid ${s}`,fontSize:13,lineHeight:1.35,transition:"background 0.2s, transform 0.15s",cursor:n?"pointer":"default"},onMouseEnter:w=>{n&&(w.currentTarget.style.background=`${s}22`)},onMouseLeave:w=>{w.currentTarget.style.background=m?`${s}14`:"rgba(255, 255, 255, 0.015)"},title:`Click for details · ${o.topic}`,children:[e.jsx("div",{style:{fontSize:15,flexShrink:0,width:20,textAlign:"center",marginTop:1},children:o.icon}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsx("div",{style:{color:"rgba(255,255,255,0.92)"},children:y}),o.detail&&e.jsx("div",{style:{color:"rgba(255,255,255,0.45)",fontSize:11,marginTop:2,lineHeight:1.3},children:o.detail})]}),e.jsx("div",{style:{color:"rgba(255,255,255,0.35)",fontSize:11,flexShrink:0,fontVariantNumeric:"tabular-nums",whiteSpace:"nowrap",marginTop:1},children:J(o.timestamp)})]},o.id)})})})}function P(t,i){const n=t.match(/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i);return n?`rgba(${parseInt(n[1],16)}, ${parseInt(n[2],16)}, ${parseInt(n[3],16)}, ${i})`:`rgba(160, 160, 160, ${i})`}function pe({drives:t,excited:i=!1,reducedMotion:n=!1}){const r=d.useRef(null),l=d.useRef(t),o=d.useRef(i),h=d.useRef(null);return d.useEffect(()=>{l.current=t},[t]),d.useEffect(()=>{o.current=i},[i]),d.useEffect(()=>{const y=r.current;if(!y)return;const s=y.getContext("2d",{alpha:!0});if(!s)return;const m=Math.min(window.devicePixelRatio||1,2),w=()=>{const I=y.getBoundingClientRect();y.width=Math.max(2,I.width*m),y.height=Math.max(2,I.height*m),s.setTransform(m,0,0,m,0,0)};w();const g=new ResizeObserver(w);g.observe(y);const f=[],R=60,M=()=>{h.current=requestAnimationFrame(M);const I=y.getBoundingClientRect(),x=I.width,j=I.height;if(x<10||j<10)return;const a=x/2,S=j/2,H=Math.min(x,j)*.11,T=Math.min(x,j)*.34,N=performance.now()/1e3,c=l.current;s.clearRect(0,0,x,j);const $=s.createRadialGradient(a,S,0,a,S,Math.min(x,j)*.55),A=n?.08:.08+.03*Math.sin(N*.5);$.addColorStop(0,`rgba(255, 255, 255, ${A*2})`),$.addColorStop(.3,`rgba(167, 139, 250, ${A})`),$.addColorStop(1,"rgba(167, 139, 250, 0)"),s.fillStyle=$,s.fillRect(0,0,x,j);const F=Math.max(c.length,5);for(let v=0;v<c.length;v++){const p=c[v],D=v/F*Math.PI*2-Math.PI/2,b=a+Math.cos(D)*T,k=S+Math.sin(D)*T,W=Math.min(1,(p.pressure||0)*3),V=n?0:.35+W*1.4,_=n?0:.04+W*.15,z=H*(.75+_*Math.sin(N*V+v*1.3)),C=Y(p.id),E=z*2.8,B=s.createRadialGradient(b,k,0,b,k,E);B.addColorStop(0,P(C,.35)),B.addColorStop(.35,P(C,.18)),B.addColorStop(1,P(C,0)),s.fillStyle=B,s.beginPath(),s.arc(b,k,E,0,Math.PI*2),s.fill();const L=s.createRadialGradient(b-z*.3,k-z*.3,0,b,k,z);L.addColorStop(0,P(C,.95)),L.addColorStop(.55,P(C,.55)),L.addColorStop(1,P(C,.2)),s.fillStyle=L,s.beginPath(),s.arc(b,k,z,0,Math.PI*2),s.fill(),W>.1&&(s.strokeStyle=P(C,.6+.3*Math.sin(N*3+v)),s.lineWidth=1.5,s.beginPath(),s.arc(b,k,z*1.05,0,Math.PI*2),s.stroke()),s.font='600 10px -apple-system, BlinkMacSystemFont, "Inter", system-ui, sans-serif',s.textAlign="center",s.fillStyle="rgba(255,255,255,0.65)",s.fillText(p.label.toUpperCase(),b,k+z+18),s.font="11px -apple-system, system-ui",s.fillStyle="rgba(255,255,255,0.35)",s.fillText(`${Math.round((p.satisfaction||0)*100)}%`,b,k+z+32);const Z=W*.25+(o.current?.03:0);!n&&f.length<R&&Math.random()<Z&&f.push({sourceIdx:v,phase:0,color:C,size:2+Math.random()*2})}if(!n)for(let v=f.length-1;v>=0;v--){const p=f[v];if(p.phase+=.012,p.phase>=1){f.splice(v,1);continue}if(!c[p.sourceIdx]){f.splice(v,1);continue}const b=p.sourceIdx/F*Math.PI*2-Math.PI/2,k=a+Math.cos(b)*T,W=S+Math.sin(b)*T,V=(k+a)/2+Math.sin(b+Math.PI/2)*20,_=(W+S)/2+Math.cos(b+Math.PI/2)*20,z=(1-p.phase)*(1-p.phase)*k+2*(1-p.phase)*p.phase*V+p.phase*p.phase*a,C=(1-p.phase)*(1-p.phase)*W+2*(1-p.phase)*p.phase*_+p.phase*p.phase*S,E=Math.sin(p.phase*Math.PI)*.9;s.fillStyle=P(p.color,E),s.beginPath(),s.arc(z,C,p.size,0,Math.PI*2),s.fill()}if(!n){const p=N%20/20;if(p<.18){const D=H+p*Math.min(x,j)*2.5,b=(1-p/.18)*.18;s.strokeStyle=`rgba(167, 139, 250, ${b})`,s.lineWidth=1.5,s.beginPath(),s.arc(a,S,D,0,Math.PI*2),s.stroke()}}};return h.current=requestAnimationFrame(M),()=>{g.disconnect(),h.current&&cancelAnimationFrame(h.current)}},[n]),e.jsx("canvas",{ref:r,style:{width:"100%",height:"100%",display:"block"},"aria-label":"TITAN organism — 5 drives breathing"})}function he({event:t,voice:i,onClose:n}){return e.jsx(q,{children:t&&e.jsxs(e.Fragment,{children:[e.jsx(G.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:{duration:.18},onClick:n,style:{position:"fixed",inset:0,background:"rgba(0, 0, 0, 0.55)",backdropFilter:"blur(4px)",WebkitBackdropFilter:"blur(4px)",zIndex:99}},"backdrop"),e.jsx(G.aside,{initial:{x:"100%"},animate:{x:0},exit:{x:"100%"},transition:{duration:.28,ease:[.32,.72,0,1]},style:{position:"fixed",top:0,right:0,bottom:0,width:"min(540px, 100vw)",background:"rgba(10, 12, 20, 0.96)",backdropFilter:"blur(24px)",WebkitBackdropFilter:"blur(24px)",borderLeft:"1px solid rgba(167, 139, 250, 0.15)",display:"flex",flexDirection:"column",zIndex:100,color:"#f8f9fc",boxShadow:"-20px 0 60px rgba(0,0,0,0.5)"},role:"dialog","aria-modal":"true",children:e.jsx(ue,{event:t,voice:i,onClose:n})},"panel")]})})}function ue({event:t,voice:i,onClose:n}){const r=i==="titan"?t.captionTitan:t.captionControl,l=t.raw||{};return d.useEffect(()=>{const o=h=>{h.key==="Escape"&&n()};return window.addEventListener("keydown",o),()=>window.removeEventListener("keydown",o)},[n]),e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{padding:"20px 24px",borderBottom:"1px solid rgba(255,255,255,0.06)",display:"flex",alignItems:"flex-start",gap:12},children:[e.jsx("div",{style:{fontSize:22,width:36,height:36,borderRadius:10,background:"rgba(255,255,255,0.04)",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:t.icon}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsx("div",{style:{fontSize:17,fontWeight:600,lineHeight:1.3,marginBottom:4},children:r}),e.jsxs("div",{style:{fontSize:11,color:"rgba(255,255,255,0.35)",display:"flex",gap:10},children:[e.jsx("span",{children:J(t.timestamp)}),e.jsx("span",{style:{opacity:.5},children:"·"}),e.jsx("span",{style:{textTransform:"uppercase",letterSpacing:"0.1em"},children:t.kind}),e.jsx("span",{style:{opacity:.5},children:"·"}),e.jsx("span",{style:{fontFamily:"ui-monospace, monospace",fontSize:10},children:t.topic})]})]}),e.jsx("button",{onClick:n,"aria-label":"Close",style:{background:"transparent",border:0,color:"rgba(255,255,255,0.55)",cursor:"pointer",padding:6,borderRadius:8,display:"flex",alignItems:"center",justifyContent:"center"},children:e.jsx(ee,{size:18})})]}),e.jsxs("div",{style:{flex:1,overflowY:"auto",padding:"20px 24px",minHeight:0},children:[t.detail&&e.jsx(u,{label:"Detail",children:e.jsx("div",{style:{fontSize:13,color:"rgba(255,255,255,0.75)",lineHeight:1.5},children:t.detail})}),t.kind==="soma"&&e.jsx(ge,{raw:l}),t.kind==="goal"&&e.jsx(fe,{raw:l}),t.kind==="tool"&&e.jsx(xe,{raw:l,topic:t.topic}),t.kind==="channel"&&e.jsx(me,{raw:l,topic:t.topic}),t.kind==="drive"&&e.jsx(be,{raw:l,topic:t.topic}),(t.kind==="system"||t.kind==="agent"||t.kind==="memory"||t.kind==="health")&&e.jsx(ye,{raw:l,topic:t.topic})]}),e.jsx(ve,{label:"Raw event data",raw:l})]})}function u({label:t,children:i}){return e.jsxs("div",{style:{marginBottom:20},children:[e.jsx("div",{style:{fontSize:10,textTransform:"uppercase",letterSpacing:"0.15em",color:"rgba(255,255,255,0.35)",fontWeight:600,marginBottom:8},children:t}),i]})}function ge({raw:t}){const i=t.approvalId,n=t.dominantDrives||[],r=t.shadowVerdict;return e.jsxs(e.Fragment,{children:[e.jsx(u,{label:"What drove this",children:e.jsxs("div",{style:{fontSize:13,color:"rgba(255,255,255,0.75)"},children:[n.length?n.map(l=>l[0].toUpperCase()+l.slice(1)).join(", "):"an unspecified drive"," ","was below its setpoint. Soma filed this proposal autonomously."]})}),i&&e.jsx(u,{label:"Command Post approval",children:e.jsx("code",{style:{fontSize:11,color:"rgba(167, 139, 250, 0.9)"},children:i})}),r&&e.jsx(u,{label:"Shadow rehearsal verdict",children:e.jsx("pre",{style:{fontSize:11,lineHeight:1.4,color:"rgba(255,255,255,0.7)",whiteSpace:"pre-wrap",wordBreak:"break-word",background:"rgba(255,255,255,0.02)",padding:12,borderRadius:8},children:JSON.stringify(r,null,2)})})]})}function fe({raw:t}){const i=t.goalId,[n,r]=d.useState(null),[l,o]=d.useState(!1);if(d.useEffect(()=>{i&&(o(!0),Q(`/api/goals/${i}`).then(s=>s.ok?s.json():null).then(s=>r((s==null?void 0:s.goal)||s||null)).catch(()=>{}).finally(()=>o(!1)))},[i]),!i)return null;if(l)return e.jsx(u,{label:"Goal",children:e.jsx("div",{style:{color:"rgba(255,255,255,0.4)",fontSize:12},children:"Loading…"})});if(!n)return e.jsx(u,{label:"Goal",children:e.jsx("div",{style:{color:"rgba(255,255,255,0.4)",fontSize:12},children:"Goal not found (may have been deleted)."})});const h=n.subtasks||[],y=h.filter(s=>s.status==="done"||s.status==="skipped").length;return e.jsxs(u,{label:"Goal",children:[e.jsx("div",{style:{fontSize:14,fontWeight:600,marginBottom:6},children:String(n.title||"")}),e.jsxs("div",{style:{fontSize:11,color:"rgba(255,255,255,0.4)",marginBottom:12},children:[String(n.status||"")," · ",y,"/",h.length," subtasks"]}),h.length>0&&e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:6},children:h.map((s,m)=>e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,padding:"8px 10px",borderRadius:8,background:"rgba(255,255,255,0.02)",fontSize:12},children:[e.jsx("span",{style:{width:8,height:8,borderRadius:"50%",background:K(s.status),boxShadow:`0 0 6px ${K(s.status)}`,flexShrink:0}}),e.jsx("span",{style:{flex:1},children:String(s.title||"")}),e.jsx("span",{style:{fontSize:10,color:"rgba(255,255,255,0.35)",textTransform:"uppercase",letterSpacing:"0.1em"},children:String(s.status||"")})]},m))})]})}function K(t){switch(t){case"done":return"var(--color-emerald)";case"running":return"var(--color-cyan)";case"failed":return"var(--color-error)";case"skipped":return"var(--color-text-secondary)";case"pending":return"#fbbf24";default:return"#9ca3af"}}function xe({raw:t,topic:i}){const n=t.tool,r=t.argsPreview,l=t.durationMs,o=t.success;return e.jsxs(e.Fragment,{children:[n&&e.jsx(u,{label:"Tool",children:e.jsx("code",{style:{fontSize:12,color:"rgba(96, 165, 250, 0.9)"},children:n})}),r!==void 0&&e.jsx(u,{label:"Arguments",children:e.jsx("pre",{style:{fontSize:11,lineHeight:1.4,color:"rgba(255,255,255,0.7)",whiteSpace:"pre-wrap",wordBreak:"break-word",background:"rgba(255,255,255,0.02)",padding:12,borderRadius:8,maxHeight:300,overflowY:"auto"},children:typeof r=="string"?r:JSON.stringify(r,null,2)})}),i==="tool:result"&&e.jsx(u,{label:"Result",children:e.jsxs("div",{style:{fontSize:13,color:o?"rgba(52,211,153,0.9)":"rgba(239,68,68,0.9)"},children:[o?"✓ Completed":"✗ Failed",l!==void 0&&e.jsxs("span",{style:{color:"rgba(255,255,255,0.5)",marginLeft:8},children:["in ",l,"ms"]})]})})]})}function me({raw:t,topic:i}){const n=t.sessionId,r=t.channel,l=t.userId,o=t.message,h=t.toolsUsed||[],y=t.model,s=t.durationMs,[m,w]=d.useState(null);return d.useEffect(()=>{n&&Q(`/api/sessions/${n}`).then(g=>g.ok?g.json():null).then(g=>{const f=Array.isArray(g)?g:(g==null?void 0:g.messages)||[];w(f)}).catch(()=>{})},[n]),e.jsxs(e.Fragment,{children:[r&&e.jsx(u,{label:"Channel",children:e.jsxs("div",{style:{fontSize:13},children:[r,l&&e.jsxs("span",{style:{color:"rgba(255,255,255,0.4)"},children:[" · ",l]})]})}),o&&e.jsx(u,{label:i==="turn:pre"?"What they said":"Message",children:e.jsx("div",{style:{fontSize:13,lineHeight:1.5,color:"rgba(255,255,255,0.8)",padding:12,background:"rgba(255,255,255,0.02)",borderRadius:8},children:o})}),i==="turn:post"&&e.jsx(u,{label:"Turn stats",children:e.jsxs("div",{style:{fontSize:12,color:"rgba(255,255,255,0.55)",lineHeight:1.6},children:[s!==void 0&&e.jsxs("div",{children:["Took ",(s/1e3).toFixed(1),"s"]}),y&&e.jsxs("div",{children:["Model: ",y]}),h.length>0&&e.jsxs("div",{children:["Used: ",h.join(", ")]})]})}),m&&m.length>0&&e.jsx(u,{label:"Session messages",children:e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:10,maxHeight:400,overflowY:"auto"},children:m.slice(-8).map((g,f)=>e.jsxs("div",{style:{padding:10,borderRadius:8,background:g.role==="assistant"?"rgba(167, 139, 250, 0.06)":"rgba(255,255,255,0.02)",borderLeft:`2px solid ${g.role==="assistant"?"var(--color-purple-light)":"rgba(255,255,255,0.2)"}`,fontSize:12},children:[e.jsx("div",{style:{fontSize:10,textTransform:"uppercase",letterSpacing:"0.1em",color:"rgba(255,255,255,0.35)",marginBottom:4},children:String(g.role||"?")}),e.jsxs("div",{style:{color:"rgba(255,255,255,0.85)",lineHeight:1.5,whiteSpace:"pre-wrap"},children:[String(g.content||"").slice(0,400),String(g.content||"").length>400&&"…"]})]},f))})})]})}function be({raw:t,topic:i}){const n=t.drives||[],r=t.totalPressure,l=t.dominantDrives||[];return e.jsxs(e.Fragment,{children:[r!==void 0&&e.jsx(u,{label:"Pressure snapshot",children:e.jsxs("div",{style:{fontSize:13,color:"rgba(255,255,255,0.75)"},children:["Total: ",e.jsx("strong",{children:r.toFixed(3)}),l.length>0&&e.jsxs("span",{children:[" · Dominant: ",l.map(o=>o[0].toUpperCase()+o.slice(1)).join(", ")]})]})}),n.length>0&&i==="drive:tick"&&e.jsx(u,{label:"All drives this tick",children:e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:6},children:n.map((o,h)=>e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,padding:"8px 10px",borderRadius:8,background:"rgba(255,255,255,0.02)",fontSize:12},children:[e.jsx("span",{style:{flex:1,fontWeight:500},children:String(o.label||o.id)}),e.jsxs("span",{style:{color:"rgba(255,255,255,0.55)",fontVariantNumeric:"tabular-nums"},children:["sat ",(Number(o.satisfaction)*100).toFixed(0),"% · sp ",(Number(o.setpoint)*100).toFixed(0),"%"]}),e.jsx("span",{style:{color:Number(o.pressure)>0?"#fbbf24":"rgba(255,255,255,0.25)",fontVariantNumeric:"tabular-nums",width:50,textAlign:"right"},children:Number(o.pressure).toFixed(2)})]},h))})})]})}function ye({raw:t,topic:i}){if(i==="initiative:round"){const n=t.round,r=t.maxRounds,l=t.subtaskTitle;return e.jsx(u,{label:"What's happening",children:e.jsxs("div",{style:{fontSize:13,color:"rgba(255,255,255,0.8)",lineHeight:1.6},children:["TITAN is reasoning through round ",e.jsx("strong",{children:n})," of ",e.jsx("strong",{children:r}),l&&e.jsxs(e.Fragment,{children:[" on the subtask ",e.jsxs("em",{style:{color:"rgba(167, 139, 250, 0.9)"},children:['"',l,'"']})]}),".",e.jsx("br",{}),e.jsx("br",{}),"Each round is one tool-calling cycle — the agent thinks, picks a tool, runs it, then thinks again with the result. The cycle continues until the subtask is complete or the round budget runs out."]})})}if(i==="initiative:start"){const n=t.subtaskTitle,r=t.goalTitle;return e.jsx(u,{label:"What's happening",children:e.jsxs("div",{style:{fontSize:13,color:"rgba(255,255,255,0.8)",lineHeight:1.6},children:["TITAN picked up a task and started working.",n&&e.jsxs(e.Fragment,{children:[" Subtask: ",e.jsxs("em",{style:{color:"rgba(167, 139, 250, 0.9)"},children:['"',n,'"']}),"."]}),r&&e.jsxs(e.Fragment,{children:[" Part of goal: ",e.jsxs("em",{style:{color:"rgba(52, 211, 153, 0.9)"},children:['"',r,'"']}),"."]})]})})}if(i==="initiative:complete"){const n=t.success,r=t.toolsUsed||[],l=t.summary;return e.jsxs(u,{label:"Result",children:[e.jsxs("div",{style:{fontSize:13,color:"rgba(255,255,255,0.8)",lineHeight:1.6},children:[n===!1?"The task ran but ended without full success.":"Task complete.",r.length>0&&e.jsxs(e.Fragment,{children:[" Tools used: ",r.join(", "),"."]})]}),l&&e.jsx("div",{style:{marginTop:8,padding:10,borderRadius:8,background:"rgba(255,255,255,0.02)",fontSize:12,lineHeight:1.5,color:"rgba(255,255,255,0.7)"},children:l})]})}if(i==="initiative:no_progress"){const n=t.reason;return e.jsx(u,{label:"Why it paused",children:e.jsx("div",{style:{fontSize:13,color:"rgba(251, 191, 36, 0.9)",lineHeight:1.6},children:n||"Ran but couldn't advance."})})}if(i==="dreaming:consolidated")return e.jsx(u,{label:"What's happening",children:e.jsx("div",{style:{fontSize:13,color:"rgba(255,255,255,0.8)",lineHeight:1.6},children:"TITAN periodically consolidates recent memories — merging related facts, pruning stale ones, strengthening frequently-accessed associations. It's how it keeps the memory graph fast without losing useful context."})});if(i==="daemon:started"||i==="daemon:resumed")return e.jsx(u,{label:"What's happening",children:e.jsx("div",{style:{fontSize:13,color:"rgba(255,255,255,0.8)",lineHeight:1.6},children:"TITAN's background daemon came online. All watchers (goals, cron, health, memory, drive ticks, Facebook autopilot) are active."})});if(i==="daemon:paused")return e.jsx(u,{label:"What's happening",children:e.jsx("div",{style:{fontSize:13,color:"rgba(255,255,255,0.8)",lineHeight:1.6},children:"Background work is paused. Chat still works; cron, autopilot, and Soma ticks are halted until resumed."})});if(i.startsWith("health:"))return e.jsx(u,{label:"Health alert",children:e.jsx("div",{style:{fontSize:13,color:"rgba(251, 191, 36, 0.9)",lineHeight:1.6},children:"A subsystem reported a health issue. Check the Console tab for diagnostics."})});if(i==="agent:spawned"||i==="agent:stopped"){const n=t.name,r=t.model;return e.jsx(u,{label:"What's happening",children:e.jsxs("div",{style:{fontSize:13,color:"rgba(255,255,255,0.8)",lineHeight:1.6},children:[i==="agent:spawned"?"Spawned":"Stopped"," sub-agent",n&&e.jsxs(e.Fragment,{children:[" ",e.jsx("strong",{children:n})]}),r&&i==="agent:spawned"&&e.jsxs(e.Fragment,{children:[" running ",r]}),"."]})})}if(i==="agent:task:completed"||i==="agent:task:failed"){const n=t.agentId,r=t.reason,l=t.success;return e.jsx(u,{label:"Sub-agent result",children:e.jsxs("div",{style:{fontSize:13,color:"rgba(255,255,255,0.8)",lineHeight:1.6},children:[n&&e.jsxs(e.Fragment,{children:["Sub-agent ",e.jsx("strong",{children:n})," "]}),i==="agent:task:completed"&&l!==!1?"finished its task successfully.":r?`couldn't complete: ${r}.`:"did not complete its task."]})})}return e.jsx(je,{raw:t})}function je({raw:t}){const i=Object.entries(t||{}).filter(([n])=>n!=="timestamp");return i.length===0?null:e.jsx(u,{label:"Details",children:e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:6},children:i.slice(0,8).map(([n,r])=>e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",gap:12,padding:"6px 10px",borderRadius:6,background:"rgba(255,255,255,0.02)",fontSize:11},children:[e.jsx("span",{style:{color:"rgba(255,255,255,0.4)"},children:n}),e.jsx("span",{style:{color:"rgba(255,255,255,0.8)",fontFamily:"ui-monospace, monospace",textAlign:"right",wordBreak:"break-all"},children:Se(r)})]},n))})})}function Se(t){if(t==null)return"—";if(typeof t=="string")return t.length>80?t.slice(0,77)+"…":t;if(typeof t=="number"||typeof t=="boolean")return String(t);try{return JSON.stringify(t).slice(0,80)}catch{return"[object]"}}function ve({label:t,raw:i}){const[n,r]=d.useState(!1);return e.jsxs("div",{style:{borderTop:"1px solid rgba(255,255,255,0.06)"},children:[e.jsxs("button",{onClick:()=>r(l=>!l),style:{width:"100%",padding:"14px 24px",background:"transparent",border:0,color:"rgba(255,255,255,0.5)",fontSize:11,textTransform:"uppercase",letterSpacing:"0.15em",fontWeight:600,textAlign:"left",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsx("span",{children:t}),e.jsx("span",{style:{fontSize:14},children:n?"−":"+"})]}),n&&e.jsx("pre",{style:{margin:0,padding:"0 24px 20px",fontSize:10,lineHeight:1.4,color:"rgba(255,255,255,0.5)",whiteSpace:"pre-wrap",wordBreak:"break-word",maxHeight:300,overflowY:"auto"},children:JSON.stringify(i,null,2)})]})}function Ie(){var x,j;const[t]=te(),i=t.get("kiosk")==="1",n=t.get("voice")==="control"?"control":"titan",[r,l]=d.useState(n),[o,h]=d.useState(null),{drives:y,events:s,connected:m,reconnecting:w,lastActivity:g}=ae(),f=g>0&&Date.now()-g<1e4,R=typeof window<"u"&&((j=(x=window.matchMedia)==null?void 0:x.call(window,"(prefers-reduced-motion: reduce)"))==null?void 0:j.matches);d.useEffect(()=>{if(!i)return;let a=null;const S=async()=>{try{"wakeLock"in navigator&&(a=await navigator.wakeLock.request("screen"))}catch{}};S();const H=()=>{document.visibilityState==="visible"&&S()};return document.addEventListener("visibilitychange",H),()=>{var T;document.removeEventListener("visibilitychange",H),(T=a==null?void 0:a.release)==null||T.call(a)}},[i]);const M=d.useMemo(()=>m?"live":w?"reconnecting…":"connecting…",[m,w]),I=m?"var(--color-emerald)":w?"#fbbf24":"#6b7280";return e.jsxs("div",{style:{position:i?"fixed":"relative",inset:i?0:void 0,height:"100%",width:"100%",minHeight:i?"100vh":"100%",background:"radial-gradient(ellipse at 20% 30%, rgba(167, 139, 250, 0.06) 0%, transparent 55%), radial-gradient(ellipse at 80% 70%, rgba(34, 211, 238, 0.05) 0%, transparent 55%), radial-gradient(ellipse at 50% 50%, rgba(52, 211, 153, 0.03) 0%, transparent 60%), #05060a",color:"#f8f9fc",overflow:"hidden",fontFamily:'-apple-system, BlinkMacSystemFont, "SF Pro Text", Inter, system-ui, sans-serif',display:"flex",flexDirection:"column",zIndex:i?9999:void 0},children:[e.jsx("div",{"aria-hidden":!0,style:{position:"absolute",inset:0,opacity:.03,pointerEvents:"none",backgroundImage:`url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='200' height='200'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2'/></filter><rect width='200' height='200' filter='url(%23n)' opacity='0.8'/></svg>")`}}),e.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column",padding:i?"32px 40px":"20px 24px",minHeight:0,zIndex:1},children:[!i&&e.jsxs("header",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:16,fontSize:13},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,color:"rgba(255,255,255,0.5)",fontWeight:600,letterSpacing:"0.02em"},children:[e.jsx("div",{style:{width:8,height:8,borderRadius:"50%",background:I,boxShadow:`0 0 10px ${I}`,animation:"watch-pulse 2s ease-in-out infinite"}}),e.jsx("span",{children:"TITAN"}),e.jsx("span",{style:{opacity:.4},children:"·"}),e.jsx("span",{children:M})]}),e.jsx("div",{style:{display:"flex",gap:2,background:"rgba(20, 24, 36, 0.6)",border:"1px solid rgba(80, 90, 120, 0.25)",borderRadius:999,padding:2},children:["titan","control"].map(a=>e.jsx("button",{onClick:()=>l(a),style:{background:r===a?"#f8f9fc":"transparent",color:r===a?"#05060a":"rgba(255,255,255,0.55)",border:0,padding:"6px 14px",borderRadius:999,cursor:"pointer",fontSize:11,fontWeight:600,letterSpacing:"0.02em",transition:"all 0.15s",textTransform:"uppercase"},children:a==="titan"?"TITAN":"Mission"},a))})]}),e.jsxs("main",{style:{display:"grid",gridTemplateColumns:"minmax(0, 1.05fr) minmax(0, 1fr)",gridTemplateRows:"auto 1fr",gridTemplateAreas:'"focus activity" "organism activity"',gap:i?28:18,flex:1,minHeight:0},className:"watch-grid",children:[e.jsx(U,{gridArea:"focus",excited:f,children:e.jsx(le,{events:s,voice:r})}),e.jsxs(U,{gridArea:"organism",excited:f,padding:i?24:16,children:[e.jsx("div",{style:{fontSize:10,textTransform:"uppercase",letterSpacing:"0.15em",color:"rgba(255,255,255,0.35)",fontWeight:600,marginBottom:6},children:"How I'm feeling"}),e.jsx("div",{style:{flex:1,minHeight:i?320:220},children:e.jsx(pe,{drives:y,excited:f,reducedMotion:R})}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(90px, 1fr))",gap:8,marginTop:10,fontSize:11},children:y.map(a=>{const S=(a.pressure||0)>.01;return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,padding:"6px 10px",borderRadius:8,background:S?"rgba(251, 191, 36, 0.08)":"rgba(255,255,255,0.02)",border:`1px solid ${S?"rgba(251, 191, 36, 0.3)":"rgba(255,255,255,0.04)"}`},title:a.description||`${a.label}: satisfaction ${a.satisfaction.toFixed(2)}, setpoint ${a.setpoint.toFixed(2)}`,children:[e.jsx("div",{style:{width:8,height:8,borderRadius:"50%",background:Y(a.id),boxShadow:`0 0 8px ${Y(a.id)}`}}),e.jsx("div",{style:{flex:1,color:"rgba(255,255,255,0.65)",fontWeight:500},children:a.label}),e.jsxs("div",{style:{color:"rgba(255,255,255,0.35)",fontVariantNumeric:"tabular-nums"},children:[Math.round((a.satisfaction||0)*100),"%"]})]},a.id)})})]}),e.jsxs(U,{gridArea:"activity",excited:f,children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:12},children:[e.jsx("div",{style:{fontSize:10,textTransform:"uppercase",letterSpacing:"0.15em",color:"rgba(255,255,255,0.35)",fontWeight:600},children:"Recent activity"}),e.jsxs("div",{style:{fontSize:11,color:"rgba(255,255,255,0.35)",fontVariantNumeric:"tabular-nums"},children:[s.length," ",s.length===1?"event":"events"]})]}),e.jsx("div",{style:{flex:1,overflowY:"auto",minHeight:0,maskImage:"linear-gradient(to bottom, transparent 0, black 16px, black calc(100% - 16px), transparent 100%)",WebkitMaskImage:"linear-gradient(to bottom, transparent 0, black 16px, black calc(100% - 16px), transparent 100%)",paddingRight:4},children:e.jsx(de,{events:s,voice:r,onEventClick:h})})]})]})]}),e.jsx(he,{event:o,voice:r,onClose:()=>h(null)}),e.jsx("style",{children:`
2
2
  @keyframes watch-pulse {
3
3
  0%, 100% { opacity: 1; transform: scale(1); }
4
4
  50% { opacity: 0.6; transform: scale(0.85); }
@@ -1 +1 @@
1
- import{r as o,j as e,X as L,b as S,f as J,b7 as q}from"./index-C6oarzis.js";import{A as D,m as $}from"./proxy-sXxWK7WF.js";import{E as K,q as B,P as U}from"./TitanCanvas-BhurNMK3.js";import{P as F}from"./play-Dwp2l5HG.js";import{T as M}from"./trash-2-B4jp_pAQ.js";import{P as _}from"./pause-B0XymOnS.js";import"./VoiceOverlay-BXPVdnJc.js";function V({open:a,approval:s,onClose:l}){var N,k,w;const[c,n]=o.useState(null),[p,r]=o.useState(!1),[y,m]=o.useState(!1),u=(N=s==null?void 0:s.payload)==null?void 0:N.goalId;if(o.useEffect(()=>{if(!a||!u){n(null),m(!1);return}let b=!1;const C=async()=>{try{const f=await S(`/api/goals/${u}`);if(!f.ok){b||(m(!0),r(!1));return}const h=await f.json();if(b)return;n(h.goal||h),m(!1),r(!1)}catch{b||(m(!0),r(!1))}};r(!0),C();const d=setInterval(C,5e3);return()=>{b=!0,clearInterval(d)}},[a,u]),o.useEffect(()=>{if(!a)return;const b=C=>{C.key==="Escape"&&l()};return window.addEventListener("keydown",b),()=>window.removeEventListener("keydown",b)},[a,l]),!s)return null;const j=s.title||((k=s.payload)==null?void 0:k.title)||"Approval",x=(w=s.payload)==null?void 0:w.rationale;return e.jsx(D,{children:a&&e.jsxs(e.Fragment,{children:[e.jsx($.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:{duration:.18},onClick:l,style:{position:"fixed",inset:0,background:"rgba(0, 0, 0, 0.55)",backdropFilter:"blur(4px)",WebkitBackdropFilter:"blur(4px)",zIndex:99}},"backdrop"),e.jsxs($.aside,{initial:{x:"100%"},animate:{x:0},exit:{x:"100%"},transition:{duration:.28,ease:[.32,.72,0,1]},style:{position:"fixed",top:0,right:0,bottom:0,width:"min(540px, 100vw)",background:"rgba(10, 12, 20, 0.96)",backdropFilter:"blur(24px)",WebkitBackdropFilter:"blur(24px)",borderLeft:"1px solid rgba(167, 139, 250, 0.15)",display:"flex",flexDirection:"column",zIndex:100,color:"#f8f9fc",boxShadow:"-20px 0 60px rgba(0,0,0,0.5)"},role:"dialog","aria-modal":"true",children:[e.jsxs("div",{style:{padding:"20px 24px",borderBottom:"1px solid rgba(255,255,255,0.06)",display:"flex",alignItems:"flex-start",gap:12},children:[e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsx("div",{style:{fontSize:10,textTransform:"uppercase",letterSpacing:"0.15em",color:"rgba(255,255,255,0.35)",fontWeight:600,marginBottom:6},children:"Proposal"}),e.jsx("div",{style:{fontSize:17,fontWeight:600,lineHeight:1.3,marginBottom:6},children:j}),e.jsx("div",{style:{fontSize:11,color:"rgba(255,255,255,0.35)"},children:e.jsx(G,{status:s.status})})]}),e.jsx("button",{onClick:l,"aria-label":"Close",style:{background:"transparent",border:0,color:"rgba(255,255,255,0.55)",cursor:"pointer",padding:6,borderRadius:8},children:e.jsx(L,{size:18})})]}),e.jsxs("div",{style:{flex:1,overflowY:"auto",padding:"20px 24px"},children:[x&&e.jsx(z,{label:"Why this",children:e.jsx("div",{style:{fontSize:13,color:"rgba(255,255,255,0.75)",lineHeight:1.5},children:x})}),!u&&s.status==="pending"&&e.jsx(z,{label:"Status",children:e.jsx("div",{style:{fontSize:13,color:"rgba(251, 191, 36, 0.9)"},children:"Waiting for approval. Once approved, a goal will be created and TITAN will start working on it."})}),!u&&s.status==="rejected"&&e.jsx(z,{label:"Status",children:e.jsx("div",{style:{fontSize:13,color:"rgba(255,255,255,0.5)"},children:"Rejected. No work started."})}),u&&e.jsxs(e.Fragment,{children:[p&&!c&&e.jsx(z,{label:"Progress",children:e.jsx("div",{style:{fontSize:13,color:"rgba(255,255,255,0.4)"},children:"Loading goal…"})}),y&&e.jsx(z,{label:"Progress",children:e.jsx("div",{style:{fontSize:13,color:"rgba(255,255,255,0.4)"},children:"Goal linked to this approval wasn't found (may have been deleted)."})}),c&&e.jsx(X,{goal:c})]})]}),e.jsxs("div",{style:{padding:"14px 24px",borderTop:"1px solid rgba(255,255,255,0.06)",display:"flex",gap:10},children:[u&&e.jsxs("a",{href:"/command-post",onClick:b=>{b.preventDefault(),window.location.hash="#watch",l()},style:{display:"inline-flex",alignItems:"center",gap:6,padding:"8px 14px",borderRadius:8,background:"rgba(167, 139, 250, 0.12)",color:"#c4b5fd",fontSize:12,fontWeight:500,textDecoration:"none",cursor:"pointer"},children:[e.jsx(K,{size:12})," Watch live"]}),e.jsx("button",{onClick:l,style:{padding:"8px 14px",borderRadius:8,background:"rgba(255,255,255,0.04)",border:0,color:"rgba(255,255,255,0.55)",fontSize:12,cursor:"pointer"},children:"Close"})]})]},"panel")]})})}function X({goal:a}){const s=a.subtasks||[],l=s.filter(r=>r.status==="done"||r.status==="skipped").length,c=s.filter(r=>r.status==="failed").length,n=s.filter(r=>r.status==="running").length,p=s.length?l/s.length*100:a.progress||0;return e.jsxs(e.Fragment,{children:[e.jsxs(z,{label:"Progress",children:[e.jsxs("div",{style:{marginBottom:10},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",fontSize:12,marginBottom:6},children:[e.jsxs("span",{style:{color:"rgba(255,255,255,0.6)"},children:[l," / ",s.length," complete"]}),e.jsxs("span",{style:{color:"rgba(255,255,255,0.4)",fontVariantNumeric:"tabular-nums"},children:[p.toFixed(0),"%"]})]}),e.jsx("div",{style:{height:6,borderRadius:3,background:"rgba(255,255,255,0.04)",overflow:"hidden"},children:e.jsx("div",{style:{width:`${p}%`,height:"100%",background:c>0?"linear-gradient(to right, #34d399, #fbbf24)":"var(--color-emerald)",transition:"width 0.5s"}})})]}),e.jsxs("div",{style:{fontSize:11,color:"rgba(255,255,255,0.4)",display:"flex",gap:12},children:[e.jsx(G,{status:a.status}),n>0&&e.jsxs("span",{children:["· ",n," running"]}),c>0&&e.jsxs("span",{style:{color:"rgba(239, 68, 68, 0.9)"},children:["· ",c," failed"]})]})]}),s.length>0&&e.jsx(z,{label:"Subtasks",children:e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:8},children:s.map(r=>e.jsx(Y,{goalId:a.id,subtask:r},r.id))})})]})}function Y({goalId:a,subtask:s}){const l=O(s.status),c=s.status==="running",[n,p]=o.useState(!1),r=async()=>{p(!0);try{await S(`/api/goals/${a}/subtasks/${s.id}/retry`,{method:"POST"})}catch(m){alert(`Retry failed: ${m.message}`)}p(!1)},y=async()=>{p(!0);try{await S(`/api/goals/${a}/subtasks/${s.id}/complete`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({result:"Marked complete from Command Post"})})}catch(m){alert(`Mark-done failed: ${m.message}`)}p(!1)};return e.jsxs("div",{style:{padding:"10px 12px",borderRadius:8,background:"rgba(255,255,255,0.02)",borderLeft:`2px solid ${l}`,fontSize:12},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,marginBottom:s.error||s.result?6:0},children:[e.jsx("span",{style:{width:8,height:8,borderRadius:"50%",background:l,boxShadow:`0 0 ${c?10:5}px ${l}`,animation:c?"subtask-pulse 1.4s ease-in-out infinite":"none",flexShrink:0}}),e.jsx("span",{style:{flex:1,color:"rgba(255,255,255,0.85)",lineHeight:1.4},children:s.title}),s.status==="failed"&&e.jsx("button",{onClick:r,disabled:n,title:"Reset + retry",style:{background:"transparent",border:0,padding:4,borderRadius:4,color:"#fbbf24",cursor:"pointer",opacity:n?.4:.8},children:e.jsx(B,{size:12})}),s.status==="pending"&&e.jsx("button",{onClick:y,disabled:n,title:"Mark done",style:{background:"transparent",border:0,padding:4,borderRadius:4,color:"var(--color-emerald)",cursor:"pointer",opacity:n?.4:.8},children:e.jsx(J,{size:12})}),e.jsx("span",{style:{fontSize:10,textTransform:"uppercase",letterSpacing:"0.1em",color:l,fontWeight:600,flexShrink:0},children:s.status})]}),s.error&&e.jsx("div",{style:{fontSize:11,color:"rgba(239, 68, 68, 0.85)",padding:"6px 8px",borderRadius:6,background:"rgba(239, 68, 68, 0.06)",marginLeft:18},children:s.error}),s.result&&s.status==="done"&&e.jsxs("div",{style:{fontSize:11,color:"rgba(255,255,255,0.55)",lineHeight:1.4,marginLeft:18,marginTop:4},children:[s.result.slice(0,240),s.result.length>240?"…":""]}),e.jsx("style",{children:"@keyframes subtask-pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.35; } }"})]})}function G({status:a}){const s=O(a);return e.jsx("span",{style:{display:"inline-block",padding:"2px 8px",borderRadius:999,background:`${s}15`,color:s,fontSize:10,fontWeight:600,textTransform:"uppercase",letterSpacing:"0.1em"},children:a})}function O(a){switch(a){case"done":case"completed":case"approved":case"active":return"var(--color-emerald)";case"running":return"var(--color-cyan)";case"failed":case"rejected":return"var(--color-error)";case"skipped":return"var(--color-text-secondary)";case"pending":case"paused":return"#fbbf24";default:return"#9ca3af"}}function z({label:a,children:s}){return e.jsxs("div",{style:{marginBottom:20},children:[e.jsx("div",{style:{fontSize:10,textTransform:"uppercase",letterSpacing:"0.15em",color:"rgba(255,255,255,0.35)",fontWeight:600,marginBottom:8},children:a}),s]})}function oe(){const[a,s]=o.useState([]),[l,c]=o.useState(!0),[n,p]=o.useState(null),[r,y]=o.useState(null),[m,u]=o.useState(!1),[j,x]=o.useState(null),[N,k]=o.useState(null),{toast:w}=q(),b=async()=>{try{const t=await S("/api/goals");if(t.ok){const i=await t.json();s(i.goals||[])}}catch{}},C=async t=>{k(t.id);const i=t.status==="paused"?"active":"paused";try{await S(`/api/goals/${t.id}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({status:i})}),await b()}catch(g){w("error",`Update failed: ${g.message}`)}k(null)},d=async t=>{k(t.id);try{await S(`/api/goals/${t.id}`,{method:"DELETE"}),await b()}catch(i){w("error",`Delete failed: ${i.message}`)}k(null),x(null)},f=async t=>{k(t.id);try{const i=(t.subtasks||[]).filter(g=>g.status==="failed");for(const g of i)await S(`/api/goals/${t.id}/subtasks/${g.id}/retry`,{method:"POST"});t.status!=="active"&&await S(`/api/goals/${t.id}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({status:"active"})}),await b()}catch(i){w("error",`Restart failed: ${i.message}`)}k(null)};o.useEffect(()=>{let t=!0;const i=async()=>{try{const v=await S("/api/goals");if(!v.ok)return;const T=await v.json();if(!t)return;s(T.goals||[]),c(!1)}catch{}};i();const g=setInterval(i,1e4);return()=>{t=!1,clearInterval(g)}},[]),o.useEffect(()=>{const t=localStorage.getItem("titan-token")||localStorage.getItem("titan_token")||"",i=`/api/watch/stream${t?`?token=${encodeURIComponent(t)}`:""}`,g=new EventSource(i);return g.onmessage=v=>{try{const T=JSON.parse(v.data);if(T.type!=="event")return;if(T.topic==="initiative:start"||T.topic==="initiative:round"){const I=T.raw||{};y({goalTitle:I.goalTitle||"",subtaskTitle:I.subtaskTitle||"",round:I.round,maxRounds:I.maxRounds})}(T.topic==="initiative:complete"||T.topic==="initiative:no_progress")&&y(null)}catch{}},g.onerror=()=>{},()=>g.close()},[]);const h=o.useMemo(()=>a.filter(t=>t.status==="active").sort((t,i)=>(t.priority||5)-(i.priority||5)),[a]),A=o.useMemo(()=>a.filter(t=>t.status==="paused"),[a]),P=o.useMemo(()=>a.filter(t=>t.status==="completed").sort((t,i)=>(i.completedAt||i.updatedAt||"").localeCompare(t.completedAt||t.updatedAt||"")).slice(0,5),[a]),R=o.useMemo(()=>{const t=[];for(const i of h){const g=new Set((i.subtasks||[]).filter(v=>v.status==="done"||v.status==="skipped").map(v=>v.id));for(const v of i.subtasks||[]){if(v.status!=="pending")continue;(v.dependsOn||[]).every(H=>g.has(H))&&t.push({goal:i,subtask:v})}}return t},[h]),W=o.useMemo(()=>{const t=[];for(const i of a)if(!(i.status!=="active"&&i.status!=="paused"))for(const g of i.subtasks||[])g.status==="failed"&&t.push({goal:i,subtask:g});return t.slice(0,5)},[a]);return l?e.jsx("div",{className:"flex items-center justify-center h-64 text-sm text-text-muted",children:"Loading work…"}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"text-[11px] text-text-muted",children:[a.filter(t=>t.status==="active").length," active · ",a.filter(t=>t.status==="paused").length," paused · ",a.filter(t=>t.status==="completed").length," completed"]}),e.jsxs("button",{onClick:()=>u(!0),className:"flex items-center gap-1.5 px-3 py-1.5 text-[12px] font-medium rounded-lg bg-indigo-600 text-white hover:bg-indigo-500 transition-colors",children:[e.jsx(U,{size:13})," New goal"]})]}),e.jsx(E,{label:"Now",count:r?1:0,children:e.jsx(D,{mode:"wait",children:r?e.jsxs($.div,{initial:{opacity:0,y:-4},animate:{opacity:1,y:0},exit:{opacity:0},transition:{duration:.25},className:"p-4 rounded-xl border border-cyan-500/20 bg-cyan-500/[0.04]",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx("span",{className:"w-2.5 h-2.5 rounded-full bg-cyan-400 animate-pulse",style:{boxShadow:"0 0 12px #22d3ee"}}),e.jsx("span",{className:"text-[11px] text-cyan-300 uppercase tracking-wider font-semibold",children:"executing"}),r.round&&r.maxRounds&&e.jsxs("span",{className:"text-[11px] text-text-muted",children:["round ",r.round,"/",r.maxRounds]})]}),e.jsx("div",{className:"text-[15px] font-medium text-white/95 mb-1",children:r.subtaskTitle||"(unnamed subtask)"}),r.goalTitle&&e.jsxs("div",{className:"text-[11px] text-text-muted",children:["in goal: ",r.goalTitle]})]},`${r.goalTitle}-${r.subtaskTitle}`):e.jsxs($.div,{initial:{opacity:0},animate:{opacity:1},className:"p-6 rounded-xl border border-border text-center",children:[e.jsx("div",{className:"text-[13px] text-text-muted",children:"Nothing running right now."}),e.jsx("div",{className:"text-[11px] text-text-muted mt-1",children:R.length>0?`${R.length} task${R.length===1?"":"s"} queued — TITAN will start within 10 seconds`:h.length>0?`${h.length} goal${h.length===1?"":"s"} active — waiting for driver to begin`:"No work in queue. Approve a proposal from the Inbox to get started."})]},"idle")})}),R.length>0&&e.jsx(E,{label:"Up next",count:R.length,children:e.jsx("div",{className:"space-y-2",children:R.slice(0,3).map(({goal:t,subtask:i},g)=>e.jsxs("div",{onClick:()=>p(t),className:"flex items-center gap-3 p-3 rounded-lg bg-bg-secondary/30 border border-border/30 hover:bg-bg-secondary cursor-pointer transition-colors",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-amber-400/60"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-[13px] text-white/85 truncate",children:i.title}),e.jsx("div",{className:"text-[11px] text-text-muted truncate",children:t.title})]}),g===0&&e.jsx("span",{className:"text-[10px] text-cyan-300/70 uppercase tracking-wider",children:"next"})]},`${t.id}-${i.id}`))})}),e.jsx(E,{label:"Active goals",count:h.length,children:h.length===0?e.jsx("div",{className:"p-6 rounded-xl border border-border text-center text-[12px] text-text-muted",children:"No active goals. TITAN is idle. (Soma may propose one shortly.)"}):e.jsx("div",{className:"space-y-2",children:h.map(t=>e.jsx(Z,{goal:t,busy:N===t.id,onClick:()=>p(t),onPauseToggle:()=>C(t),onDelete:()=>x(t),onRestart:()=>f(t)},t.id))})}),P.length>0&&e.jsx(E,{label:"Recently done",count:P.length,children:e.jsx("div",{className:"space-y-2",children:P.map(t=>e.jsxs("div",{onClick:()=>p(t),className:"flex items-center gap-3 p-3 rounded-lg bg-emerald-500/[0.03] border border-emerald-500/10 hover:bg-emerald-500/[0.06] cursor-pointer",children:[e.jsx("span",{className:"text-emerald-400",children:"✓"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-[13px] text-white/85 truncate",children:t.title}),e.jsxs("div",{className:"text-[11px] text-text-muted",children:["completed ",ee(t.completedAt||t.updatedAt)]})]})]},t.id))})}),(A.length>0||W.length>0)&&e.jsx(E,{label:"Needs attention",count:A.length+W.length,children:e.jsxs("div",{className:"space-y-2",children:[A.map(t=>e.jsxs("div",{className:"flex items-center gap-3 p-3 rounded-lg bg-amber-500/[0.03] border border-amber-500/15 hover:bg-amber-500/[0.06]",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-amber-400"}),e.jsxs("div",{className:"flex-1 min-w-0 cursor-pointer",onClick:()=>p(t),children:[e.jsx("div",{className:"text-[13px] text-white/85 truncate",children:t.title}),e.jsx("div",{className:"text-[11px] text-text-muted",children:"paused"})]}),e.jsx("button",{onClick:i=>{i.stopPropagation(),C(t)},disabled:N===t.id,title:"Resume",className:"p-1.5 rounded hover:bg-bg-tertiary text-emerald-400/70 hover:text-emerald-400 disabled:opacity-40",children:e.jsx(F,{size:12})}),e.jsx("button",{onClick:i=>{i.stopPropagation(),x(t)},disabled:N===t.id,title:"Delete",className:"p-1.5 rounded hover:bg-bg-tertiary text-text-muted hover:text-red-400 disabled:opacity-40",children:e.jsx(M,{size:12})})]},t.id)),W.map(({goal:t,subtask:i})=>e.jsxs("div",{onClick:()=>p(t),className:"flex items-start gap-3 p-3 rounded-lg bg-red-500/[0.03] border border-red-500/15 hover:bg-red-500/[0.06] cursor-pointer",children:[e.jsx("span",{className:"text-red-400 mt-0.5",children:"✗"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-[13px] text-white/85 truncate",children:i.title}),e.jsxs("div",{className:"text-[11px] text-text-muted truncate",children:["in ",t.title]}),i.error&&e.jsx("div",{className:"text-[11px] text-red-300/70 mt-1 truncate",children:i.error})]})]},`${t.id}-${i.id}`))]})}),e.jsx(V,{open:n!==null,approval:n?{id:n.id,title:n.title,status:n.status,payload:{goalId:n.id,title:n.title,description:n.description,rationale:n.description}}:null,onClose:()=>p(null)}),e.jsx(Q,{open:m,onClose:()=>u(!1),onCreated:async()=>{u(!1),await b()}}),e.jsx(D,{children:j&&e.jsx($.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},style:{position:"fixed",inset:0,background:"rgba(0,0,0,0.7)",backdropFilter:"blur(6px)",zIndex:200,display:"flex",alignItems:"center",justifyContent:"center"},onClick:()=>x(null),children:e.jsxs($.div,{initial:{scale:.96,y:8},animate:{scale:1,y:0},exit:{scale:.96,y:8},onClick:t=>t.stopPropagation(),style:{background:"rgba(15, 17, 26, 0.98)",border:"1px solid rgba(239, 68, 68, 0.25)",borderRadius:16,padding:24,maxWidth:440,width:"calc(100% - 32px)",color:"#f8f9fc"},children:[e.jsx("div",{className:"text-[16px] font-semibold mb-2",children:"Delete this goal?"}),e.jsx("div",{className:"text-[13px] text-white/55 mb-1",children:j.title}),e.jsxs("div",{className:"text-[11px] text-text-muted mb-5",children:["All ",(j.subtasks||[]).length," subtasks will be removed. Can't undo."]}),e.jsxs("div",{className:"flex gap-2 justify-end",children:[e.jsx("button",{onClick:()=>x(null),className:"px-4 py-2 rounded-lg text-[12px] text-text-secondary hover:bg-bg-tertiary",children:"Cancel"}),e.jsx("button",{onClick:()=>d(j),disabled:N===j.id,className:"px-4 py-2 rounded-lg text-[12px] font-medium bg-red-600 text-white hover:bg-red-500 disabled:opacity-50",children:"Delete goal"})]})]})})})]})}function Q({open:a,onClose:s,onCreated:l}){const[c,n]=o.useState(""),[p,r]=o.useState(""),[y,m]=o.useState([]),[u,j]=o.useState(""),[x,N]=o.useState(!1),[k,w]=o.useState(null);o.useEffect(()=>{a||(n(""),r(""),m([]),j(""),w(null))},[a]),o.useEffect(()=>{if(!a)return;const d=f=>{f.key==="Escape"&&s()};return window.addEventListener("keydown",d),()=>window.removeEventListener("keydown",d)},[a,s]);const b=()=>{const d=u.trim();d&&(m(f=>[...f,d]),j(""))},C=async()=>{if(!c.trim()){w("Title is required");return}N(!0),w(null);try{const d={title:c.trim(),description:p.trim()||c.trim(),subtasks:y.map(h=>({title:h,description:h}))},f=await S("/api/goals",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(d)});if(!f.ok){const h=await f.text().catch(()=>"");throw new Error(h||`HTTP ${f.status}`)}l()}catch(d){w(d.message)}N(!1)};return e.jsx(D,{children:a&&e.jsx($.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},style:{position:"fixed",inset:0,background:"rgba(0,0,0,0.7)",backdropFilter:"blur(6px)",zIndex:200,display:"flex",alignItems:"center",justifyContent:"center",padding:16},onClick:s,children:e.jsxs($.div,{initial:{scale:.96,y:8},animate:{scale:1,y:0},exit:{scale:.96,y:8},onClick:d=>d.stopPropagation(),style:{background:"rgba(15, 17, 26, 0.98)",border:"1px solid rgba(99, 102, 241, 0.25)",borderRadius:16,padding:24,maxWidth:520,width:"100%",color:"#f8f9fc"},children:[e.jsxs("div",{className:"flex items-center justify-between mb-5",children:[e.jsx("h2",{className:"text-[16px] font-semibold",children:"New goal"}),e.jsx("button",{onClick:s,className:"text-white/55 hover:text-text p-1",children:e.jsx(L,{size:18})})]}),e.jsx("label",{className:"text-[10px] uppercase tracking-wider text-text-muted font-semibold block mb-1.5",children:"Title"}),e.jsx("input",{value:c,onChange:d=>n(d.target.value),placeholder:"Build the Polymarket monitor",autoFocus:!0,className:"w-full bg-bg-tertiary border border-border rounded-lg px-3 py-2 text-[14px] text-white/95 placeholder-white/25 focus:outline-none focus:border-indigo-500/50 mb-4"}),e.jsx("label",{className:"text-[10px] uppercase tracking-wider text-text-muted font-semibold block mb-1.5",children:"Description (optional)"}),e.jsx("textarea",{value:p,onChange:d=>r(d.target.value),placeholder:"What should TITAN accomplish? Why?",rows:3,className:"w-full bg-bg-tertiary border border-border rounded-lg px-3 py-2 text-[13px] text-white/85 placeholder-white/25 focus:outline-none focus:border-indigo-500/50 resize-none mb-4"}),e.jsx("label",{className:"text-[10px] uppercase tracking-wider text-text-muted font-semibold block mb-1.5",children:"Subtasks (optional)"}),e.jsx("div",{className:"space-y-1.5 mb-2",children:y.map((d,f)=>e.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 rounded-lg bg-bg-tertiary/30 border border-border/50",children:[e.jsxs("span",{className:"text-[11px] text-text-muted tabular-nums",children:[f+1,"."]}),e.jsx("span",{className:"flex-1 text-[12px] text-text",children:d}),e.jsx("button",{onClick:()=>m(h=>h.filter((A,P)=>P!==f)),className:"text-text-muted hover:text-red-400","aria-label":"Remove",children:e.jsx(L,{size:12})})]},f))}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{value:u,onChange:d=>j(d.target.value),onKeyDown:d=>{d.key==="Enter"&&(d.preventDefault(),b())},placeholder:"Add a subtask (press Enter)",className:"flex-1 bg-bg-tertiary border border-border rounded-lg px-3 py-1.5 text-[12px] text-white/85 placeholder-white/25 focus:outline-none focus:border-indigo-500/50"}),e.jsx("button",{onClick:b,disabled:!u.trim(),className:"px-3 rounded-lg text-[12px] bg-bg-tertiary text-text-secondary hover:bg-bg-tertiary disabled:opacity-30",children:"Add"})]}),y.length===0&&e.jsx("p",{className:"text-[10px] text-text-muted italic mt-2",children:"Leaving subtasks empty is fine — TITAN can plan them itself."}),k&&e.jsx("div",{className:"mt-4 p-2 rounded-lg bg-red-500/[0.08] border border-red-500/20 text-[12px] text-red-300",children:k}),e.jsxs("div",{className:"flex gap-2 justify-end mt-6",children:[e.jsx("button",{onClick:s,className:"px-4 py-2 rounded-lg text-[12px] text-text-secondary hover:bg-bg-tertiary",children:"Cancel"}),e.jsx("button",{onClick:C,disabled:x||!c.trim(),className:"px-4 py-2 rounded-lg text-[12px] font-medium bg-indigo-600 text-white hover:bg-indigo-500 disabled:opacity-50",children:x?"Creating…":"Create goal"})]})]})})})}function Z({goal:a,busy:s,onClick:l,onPauseToggle:c,onDelete:n,onRestart:p}){const r=a.subtasks||[],y=r.filter(x=>x.status==="done"||x.status==="skipped").length,m=r.filter(x=>x.status==="running").length,u=r.filter(x=>x.status==="failed").length,j=r.length?y/r.length*100:a.progress||0;return e.jsxs("div",{className:"group p-3 rounded-lg bg-bg-secondary/30 border border-border/50 hover:bg-bg-secondary transition-colors",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 mb-1.5",children:[e.jsx("div",{onClick:l,className:"flex-1 min-w-0 cursor-pointer",children:e.jsx("div",{className:"text-[13px] text-text truncate font-medium",children:a.title})}),e.jsxs("span",{className:"text-[10px] text-text-muted flex-shrink-0 tabular-nums",children:[y,"/",r.length]}),e.jsxs("div",{className:"flex items-center gap-0.5 flex-shrink-0",children:[u>0&&e.jsx("button",{onClick:x=>{x.stopPropagation(),p()},disabled:s,title:`Retry ${u} failed subtask${u===1?"":"s"}`,className:"p-1.5 rounded hover:bg-bg-tertiary text-amber-300/70 hover:text-amber-300 disabled:opacity-40",children:e.jsx(B,{size:12})}),e.jsx("button",{onClick:x=>{x.stopPropagation(),c()},disabled:s,title:a.status==="paused"?"Resume":"Pause",className:"p-1.5 rounded hover:bg-bg-tertiary text-text-muted hover:text-text disabled:opacity-40",children:a.status==="paused"?e.jsx(F,{size:12}):e.jsx(_,{size:12})}),e.jsx("button",{onClick:x=>{x.stopPropagation(),n()},disabled:s,title:"Delete",className:"p-1.5 rounded hover:bg-bg-tertiary text-text-muted hover:text-red-400 disabled:opacity-40",children:e.jsx(M,{size:12})})]})]}),e.jsx("div",{className:"h-1 rounded-full bg-bg-tertiary overflow-hidden mb-2 cursor-pointer",onClick:l,children:e.jsx("div",{className:"h-full transition-all duration-500",style:{width:`${j}%`,background:u>0?"linear-gradient(to right, #34d399, #fbbf24)":"var(--color-emerald)"}})}),e.jsxs("div",{className:"flex items-center gap-3 text-[11px] text-text-muted cursor-pointer",onClick:l,children:[m>0&&e.jsxs("span",{className:"text-cyan-300/80",children:["▶ ",m," running"]}),u>0&&e.jsxs("span",{className:"text-red-300/80",children:["✗ ",u," failed"]}),m===0&&u===0&&r.length>0&&e.jsxs("span",{children:[r.length-y," pending"]}),r.length===0&&e.jsx("span",{className:"italic text-text-muted",children:"no subtasks yet"})]})]})}function E({label:a,count:s,children:l}){return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx("h3",{className:"text-[11px] uppercase tracking-wider text-text-muted font-semibold",children:a}),s!==void 0&&s>0&&e.jsx("span",{className:"text-[10px] text-text-muted tabular-nums",children:s})]}),l]})}function ee(a){if(!a)return"";const s=Date.parse(a);if(isNaN(s))return"";const l=Math.max(0,Math.floor((Date.now()-s)/1e3));if(l<60)return`${l}s ago`;const c=Math.floor(l/60);if(c<60)return`${c}m ago`;const n=Math.floor(c/60);return n<24?`${n}h ago`:`${Math.floor(n/24)}d ago`}export{oe as default};
1
+ import{r as o,j as e,X as L,b as S,f as J,b7 as q}from"./index-D7Clon2u.js";import{A as D,m as $}from"./proxy-Cc5bR828.js";import{E as K,q as B,P as U}from"./TitanCanvas-BQU1yxqf.js";import{P as F}from"./play-hUyR3CVS.js";import{T as M}from"./trash-2-Byj4OvKB.js";import{P as _}from"./pause-DqkRWPB_.js";import"./VoiceOverlay-l6yoasVz.js";function V({open:a,approval:s,onClose:l}){var N,k,w;const[c,n]=o.useState(null),[p,r]=o.useState(!1),[y,m]=o.useState(!1),u=(N=s==null?void 0:s.payload)==null?void 0:N.goalId;if(o.useEffect(()=>{if(!a||!u){n(null),m(!1);return}let b=!1;const C=async()=>{try{const f=await S(`/api/goals/${u}`);if(!f.ok){b||(m(!0),r(!1));return}const h=await f.json();if(b)return;n(h.goal||h),m(!1),r(!1)}catch{b||(m(!0),r(!1))}};r(!0),C();const d=setInterval(C,5e3);return()=>{b=!0,clearInterval(d)}},[a,u]),o.useEffect(()=>{if(!a)return;const b=C=>{C.key==="Escape"&&l()};return window.addEventListener("keydown",b),()=>window.removeEventListener("keydown",b)},[a,l]),!s)return null;const j=s.title||((k=s.payload)==null?void 0:k.title)||"Approval",x=(w=s.payload)==null?void 0:w.rationale;return e.jsx(D,{children:a&&e.jsxs(e.Fragment,{children:[e.jsx($.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:{duration:.18},onClick:l,style:{position:"fixed",inset:0,background:"rgba(0, 0, 0, 0.55)",backdropFilter:"blur(4px)",WebkitBackdropFilter:"blur(4px)",zIndex:99}},"backdrop"),e.jsxs($.aside,{initial:{x:"100%"},animate:{x:0},exit:{x:"100%"},transition:{duration:.28,ease:[.32,.72,0,1]},style:{position:"fixed",top:0,right:0,bottom:0,width:"min(540px, 100vw)",background:"rgba(10, 12, 20, 0.96)",backdropFilter:"blur(24px)",WebkitBackdropFilter:"blur(24px)",borderLeft:"1px solid rgba(167, 139, 250, 0.15)",display:"flex",flexDirection:"column",zIndex:100,color:"#f8f9fc",boxShadow:"-20px 0 60px rgba(0,0,0,0.5)"},role:"dialog","aria-modal":"true",children:[e.jsxs("div",{style:{padding:"20px 24px",borderBottom:"1px solid rgba(255,255,255,0.06)",display:"flex",alignItems:"flex-start",gap:12},children:[e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsx("div",{style:{fontSize:10,textTransform:"uppercase",letterSpacing:"0.15em",color:"rgba(255,255,255,0.35)",fontWeight:600,marginBottom:6},children:"Proposal"}),e.jsx("div",{style:{fontSize:17,fontWeight:600,lineHeight:1.3,marginBottom:6},children:j}),e.jsx("div",{style:{fontSize:11,color:"rgba(255,255,255,0.35)"},children:e.jsx(G,{status:s.status})})]}),e.jsx("button",{onClick:l,"aria-label":"Close",style:{background:"transparent",border:0,color:"rgba(255,255,255,0.55)",cursor:"pointer",padding:6,borderRadius:8},children:e.jsx(L,{size:18})})]}),e.jsxs("div",{style:{flex:1,overflowY:"auto",padding:"20px 24px"},children:[x&&e.jsx(z,{label:"Why this",children:e.jsx("div",{style:{fontSize:13,color:"rgba(255,255,255,0.75)",lineHeight:1.5},children:x})}),!u&&s.status==="pending"&&e.jsx(z,{label:"Status",children:e.jsx("div",{style:{fontSize:13,color:"rgba(251, 191, 36, 0.9)"},children:"Waiting for approval. Once approved, a goal will be created and TITAN will start working on it."})}),!u&&s.status==="rejected"&&e.jsx(z,{label:"Status",children:e.jsx("div",{style:{fontSize:13,color:"rgba(255,255,255,0.5)"},children:"Rejected. No work started."})}),u&&e.jsxs(e.Fragment,{children:[p&&!c&&e.jsx(z,{label:"Progress",children:e.jsx("div",{style:{fontSize:13,color:"rgba(255,255,255,0.4)"},children:"Loading goal…"})}),y&&e.jsx(z,{label:"Progress",children:e.jsx("div",{style:{fontSize:13,color:"rgba(255,255,255,0.4)"},children:"Goal linked to this approval wasn't found (may have been deleted)."})}),c&&e.jsx(X,{goal:c})]})]}),e.jsxs("div",{style:{padding:"14px 24px",borderTop:"1px solid rgba(255,255,255,0.06)",display:"flex",gap:10},children:[u&&e.jsxs("a",{href:"/command-post",onClick:b=>{b.preventDefault(),window.location.hash="#watch",l()},style:{display:"inline-flex",alignItems:"center",gap:6,padding:"8px 14px",borderRadius:8,background:"rgba(167, 139, 250, 0.12)",color:"#c4b5fd",fontSize:12,fontWeight:500,textDecoration:"none",cursor:"pointer"},children:[e.jsx(K,{size:12})," Watch live"]}),e.jsx("button",{onClick:l,style:{padding:"8px 14px",borderRadius:8,background:"rgba(255,255,255,0.04)",border:0,color:"rgba(255,255,255,0.55)",fontSize:12,cursor:"pointer"},children:"Close"})]})]},"panel")]})})}function X({goal:a}){const s=a.subtasks||[],l=s.filter(r=>r.status==="done"||r.status==="skipped").length,c=s.filter(r=>r.status==="failed").length,n=s.filter(r=>r.status==="running").length,p=s.length?l/s.length*100:a.progress||0;return e.jsxs(e.Fragment,{children:[e.jsxs(z,{label:"Progress",children:[e.jsxs("div",{style:{marginBottom:10},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",fontSize:12,marginBottom:6},children:[e.jsxs("span",{style:{color:"rgba(255,255,255,0.6)"},children:[l," / ",s.length," complete"]}),e.jsxs("span",{style:{color:"rgba(255,255,255,0.4)",fontVariantNumeric:"tabular-nums"},children:[p.toFixed(0),"%"]})]}),e.jsx("div",{style:{height:6,borderRadius:3,background:"rgba(255,255,255,0.04)",overflow:"hidden"},children:e.jsx("div",{style:{width:`${p}%`,height:"100%",background:c>0?"linear-gradient(to right, #34d399, #fbbf24)":"var(--color-emerald)",transition:"width 0.5s"}})})]}),e.jsxs("div",{style:{fontSize:11,color:"rgba(255,255,255,0.4)",display:"flex",gap:12},children:[e.jsx(G,{status:a.status}),n>0&&e.jsxs("span",{children:["· ",n," running"]}),c>0&&e.jsxs("span",{style:{color:"rgba(239, 68, 68, 0.9)"},children:["· ",c," failed"]})]})]}),s.length>0&&e.jsx(z,{label:"Subtasks",children:e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:8},children:s.map(r=>e.jsx(Y,{goalId:a.id,subtask:r},r.id))})})]})}function Y({goalId:a,subtask:s}){const l=O(s.status),c=s.status==="running",[n,p]=o.useState(!1),r=async()=>{p(!0);try{await S(`/api/goals/${a}/subtasks/${s.id}/retry`,{method:"POST"})}catch(m){alert(`Retry failed: ${m.message}`)}p(!1)},y=async()=>{p(!0);try{await S(`/api/goals/${a}/subtasks/${s.id}/complete`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({result:"Marked complete from Command Post"})})}catch(m){alert(`Mark-done failed: ${m.message}`)}p(!1)};return e.jsxs("div",{style:{padding:"10px 12px",borderRadius:8,background:"rgba(255,255,255,0.02)",borderLeft:`2px solid ${l}`,fontSize:12},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,marginBottom:s.error||s.result?6:0},children:[e.jsx("span",{style:{width:8,height:8,borderRadius:"50%",background:l,boxShadow:`0 0 ${c?10:5}px ${l}`,animation:c?"subtask-pulse 1.4s ease-in-out infinite":"none",flexShrink:0}}),e.jsx("span",{style:{flex:1,color:"rgba(255,255,255,0.85)",lineHeight:1.4},children:s.title}),s.status==="failed"&&e.jsx("button",{onClick:r,disabled:n,title:"Reset + retry",style:{background:"transparent",border:0,padding:4,borderRadius:4,color:"#fbbf24",cursor:"pointer",opacity:n?.4:.8},children:e.jsx(B,{size:12})}),s.status==="pending"&&e.jsx("button",{onClick:y,disabled:n,title:"Mark done",style:{background:"transparent",border:0,padding:4,borderRadius:4,color:"var(--color-emerald)",cursor:"pointer",opacity:n?.4:.8},children:e.jsx(J,{size:12})}),e.jsx("span",{style:{fontSize:10,textTransform:"uppercase",letterSpacing:"0.1em",color:l,fontWeight:600,flexShrink:0},children:s.status})]}),s.error&&e.jsx("div",{style:{fontSize:11,color:"rgba(239, 68, 68, 0.85)",padding:"6px 8px",borderRadius:6,background:"rgba(239, 68, 68, 0.06)",marginLeft:18},children:s.error}),s.result&&s.status==="done"&&e.jsxs("div",{style:{fontSize:11,color:"rgba(255,255,255,0.55)",lineHeight:1.4,marginLeft:18,marginTop:4},children:[s.result.slice(0,240),s.result.length>240?"…":""]}),e.jsx("style",{children:"@keyframes subtask-pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.35; } }"})]})}function G({status:a}){const s=O(a);return e.jsx("span",{style:{display:"inline-block",padding:"2px 8px",borderRadius:999,background:`${s}15`,color:s,fontSize:10,fontWeight:600,textTransform:"uppercase",letterSpacing:"0.1em"},children:a})}function O(a){switch(a){case"done":case"completed":case"approved":case"active":return"var(--color-emerald)";case"running":return"var(--color-cyan)";case"failed":case"rejected":return"var(--color-error)";case"skipped":return"var(--color-text-secondary)";case"pending":case"paused":return"#fbbf24";default:return"#9ca3af"}}function z({label:a,children:s}){return e.jsxs("div",{style:{marginBottom:20},children:[e.jsx("div",{style:{fontSize:10,textTransform:"uppercase",letterSpacing:"0.15em",color:"rgba(255,255,255,0.35)",fontWeight:600,marginBottom:8},children:a}),s]})}function oe(){const[a,s]=o.useState([]),[l,c]=o.useState(!0),[n,p]=o.useState(null),[r,y]=o.useState(null),[m,u]=o.useState(!1),[j,x]=o.useState(null),[N,k]=o.useState(null),{toast:w}=q(),b=async()=>{try{const t=await S("/api/goals");if(t.ok){const i=await t.json();s(i.goals||[])}}catch{}},C=async t=>{k(t.id);const i=t.status==="paused"?"active":"paused";try{await S(`/api/goals/${t.id}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({status:i})}),await b()}catch(g){w("error",`Update failed: ${g.message}`)}k(null)},d=async t=>{k(t.id);try{await S(`/api/goals/${t.id}`,{method:"DELETE"}),await b()}catch(i){w("error",`Delete failed: ${i.message}`)}k(null),x(null)},f=async t=>{k(t.id);try{const i=(t.subtasks||[]).filter(g=>g.status==="failed");for(const g of i)await S(`/api/goals/${t.id}/subtasks/${g.id}/retry`,{method:"POST"});t.status!=="active"&&await S(`/api/goals/${t.id}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({status:"active"})}),await b()}catch(i){w("error",`Restart failed: ${i.message}`)}k(null)};o.useEffect(()=>{let t=!0;const i=async()=>{try{const v=await S("/api/goals");if(!v.ok)return;const T=await v.json();if(!t)return;s(T.goals||[]),c(!1)}catch{}};i();const g=setInterval(i,1e4);return()=>{t=!1,clearInterval(g)}},[]),o.useEffect(()=>{const t=localStorage.getItem("titan-token")||localStorage.getItem("titan_token")||"",i=`/api/watch/stream${t?`?token=${encodeURIComponent(t)}`:""}`,g=new EventSource(i);return g.onmessage=v=>{try{const T=JSON.parse(v.data);if(T.type!=="event")return;if(T.topic==="initiative:start"||T.topic==="initiative:round"){const I=T.raw||{};y({goalTitle:I.goalTitle||"",subtaskTitle:I.subtaskTitle||"",round:I.round,maxRounds:I.maxRounds})}(T.topic==="initiative:complete"||T.topic==="initiative:no_progress")&&y(null)}catch{}},g.onerror=()=>{},()=>g.close()},[]);const h=o.useMemo(()=>a.filter(t=>t.status==="active").sort((t,i)=>(t.priority||5)-(i.priority||5)),[a]),A=o.useMemo(()=>a.filter(t=>t.status==="paused"),[a]),P=o.useMemo(()=>a.filter(t=>t.status==="completed").sort((t,i)=>(i.completedAt||i.updatedAt||"").localeCompare(t.completedAt||t.updatedAt||"")).slice(0,5),[a]),R=o.useMemo(()=>{const t=[];for(const i of h){const g=new Set((i.subtasks||[]).filter(v=>v.status==="done"||v.status==="skipped").map(v=>v.id));for(const v of i.subtasks||[]){if(v.status!=="pending")continue;(v.dependsOn||[]).every(H=>g.has(H))&&t.push({goal:i,subtask:v})}}return t},[h]),W=o.useMemo(()=>{const t=[];for(const i of a)if(!(i.status!=="active"&&i.status!=="paused"))for(const g of i.subtasks||[])g.status==="failed"&&t.push({goal:i,subtask:g});return t.slice(0,5)},[a]);return l?e.jsx("div",{className:"flex items-center justify-center h-64 text-sm text-text-muted",children:"Loading work…"}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"text-[11px] text-text-muted",children:[a.filter(t=>t.status==="active").length," active · ",a.filter(t=>t.status==="paused").length," paused · ",a.filter(t=>t.status==="completed").length," completed"]}),e.jsxs("button",{onClick:()=>u(!0),className:"flex items-center gap-1.5 px-3 py-1.5 text-[12px] font-medium rounded-lg bg-indigo-600 text-white hover:bg-indigo-500 transition-colors",children:[e.jsx(U,{size:13})," New goal"]})]}),e.jsx(E,{label:"Now",count:r?1:0,children:e.jsx(D,{mode:"wait",children:r?e.jsxs($.div,{initial:{opacity:0,y:-4},animate:{opacity:1,y:0},exit:{opacity:0},transition:{duration:.25},className:"p-4 rounded-xl border border-cyan-500/20 bg-cyan-500/[0.04]",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx("span",{className:"w-2.5 h-2.5 rounded-full bg-cyan-400 animate-pulse",style:{boxShadow:"0 0 12px #22d3ee"}}),e.jsx("span",{className:"text-[11px] text-cyan-300 uppercase tracking-wider font-semibold",children:"executing"}),r.round&&r.maxRounds&&e.jsxs("span",{className:"text-[11px] text-text-muted",children:["round ",r.round,"/",r.maxRounds]})]}),e.jsx("div",{className:"text-[15px] font-medium text-white/95 mb-1",children:r.subtaskTitle||"(unnamed subtask)"}),r.goalTitle&&e.jsxs("div",{className:"text-[11px] text-text-muted",children:["in goal: ",r.goalTitle]})]},`${r.goalTitle}-${r.subtaskTitle}`):e.jsxs($.div,{initial:{opacity:0},animate:{opacity:1},className:"p-6 rounded-xl border border-border text-center",children:[e.jsx("div",{className:"text-[13px] text-text-muted",children:"Nothing running right now."}),e.jsx("div",{className:"text-[11px] text-text-muted mt-1",children:R.length>0?`${R.length} task${R.length===1?"":"s"} queued — TITAN will start within 10 seconds`:h.length>0?`${h.length} goal${h.length===1?"":"s"} active — waiting for driver to begin`:"No work in queue. Approve a proposal from the Inbox to get started."})]},"idle")})}),R.length>0&&e.jsx(E,{label:"Up next",count:R.length,children:e.jsx("div",{className:"space-y-2",children:R.slice(0,3).map(({goal:t,subtask:i},g)=>e.jsxs("div",{onClick:()=>p(t),className:"flex items-center gap-3 p-3 rounded-lg bg-bg-secondary/30 border border-border/30 hover:bg-bg-secondary cursor-pointer transition-colors",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-amber-400/60"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-[13px] text-white/85 truncate",children:i.title}),e.jsx("div",{className:"text-[11px] text-text-muted truncate",children:t.title})]}),g===0&&e.jsx("span",{className:"text-[10px] text-cyan-300/70 uppercase tracking-wider",children:"next"})]},`${t.id}-${i.id}`))})}),e.jsx(E,{label:"Active goals",count:h.length,children:h.length===0?e.jsx("div",{className:"p-6 rounded-xl border border-border text-center text-[12px] text-text-muted",children:"No active goals. TITAN is idle. (Soma may propose one shortly.)"}):e.jsx("div",{className:"space-y-2",children:h.map(t=>e.jsx(Z,{goal:t,busy:N===t.id,onClick:()=>p(t),onPauseToggle:()=>C(t),onDelete:()=>x(t),onRestart:()=>f(t)},t.id))})}),P.length>0&&e.jsx(E,{label:"Recently done",count:P.length,children:e.jsx("div",{className:"space-y-2",children:P.map(t=>e.jsxs("div",{onClick:()=>p(t),className:"flex items-center gap-3 p-3 rounded-lg bg-emerald-500/[0.03] border border-emerald-500/10 hover:bg-emerald-500/[0.06] cursor-pointer",children:[e.jsx("span",{className:"text-emerald-400",children:"✓"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-[13px] text-white/85 truncate",children:t.title}),e.jsxs("div",{className:"text-[11px] text-text-muted",children:["completed ",ee(t.completedAt||t.updatedAt)]})]})]},t.id))})}),(A.length>0||W.length>0)&&e.jsx(E,{label:"Needs attention",count:A.length+W.length,children:e.jsxs("div",{className:"space-y-2",children:[A.map(t=>e.jsxs("div",{className:"flex items-center gap-3 p-3 rounded-lg bg-amber-500/[0.03] border border-amber-500/15 hover:bg-amber-500/[0.06]",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-amber-400"}),e.jsxs("div",{className:"flex-1 min-w-0 cursor-pointer",onClick:()=>p(t),children:[e.jsx("div",{className:"text-[13px] text-white/85 truncate",children:t.title}),e.jsx("div",{className:"text-[11px] text-text-muted",children:"paused"})]}),e.jsx("button",{onClick:i=>{i.stopPropagation(),C(t)},disabled:N===t.id,title:"Resume",className:"p-1.5 rounded hover:bg-bg-tertiary text-emerald-400/70 hover:text-emerald-400 disabled:opacity-40",children:e.jsx(F,{size:12})}),e.jsx("button",{onClick:i=>{i.stopPropagation(),x(t)},disabled:N===t.id,title:"Delete",className:"p-1.5 rounded hover:bg-bg-tertiary text-text-muted hover:text-red-400 disabled:opacity-40",children:e.jsx(M,{size:12})})]},t.id)),W.map(({goal:t,subtask:i})=>e.jsxs("div",{onClick:()=>p(t),className:"flex items-start gap-3 p-3 rounded-lg bg-red-500/[0.03] border border-red-500/15 hover:bg-red-500/[0.06] cursor-pointer",children:[e.jsx("span",{className:"text-red-400 mt-0.5",children:"✗"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-[13px] text-white/85 truncate",children:i.title}),e.jsxs("div",{className:"text-[11px] text-text-muted truncate",children:["in ",t.title]}),i.error&&e.jsx("div",{className:"text-[11px] text-red-300/70 mt-1 truncate",children:i.error})]})]},`${t.id}-${i.id}`))]})}),e.jsx(V,{open:n!==null,approval:n?{id:n.id,title:n.title,status:n.status,payload:{goalId:n.id,title:n.title,description:n.description,rationale:n.description}}:null,onClose:()=>p(null)}),e.jsx(Q,{open:m,onClose:()=>u(!1),onCreated:async()=>{u(!1),await b()}}),e.jsx(D,{children:j&&e.jsx($.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},style:{position:"fixed",inset:0,background:"rgba(0,0,0,0.7)",backdropFilter:"blur(6px)",zIndex:200,display:"flex",alignItems:"center",justifyContent:"center"},onClick:()=>x(null),children:e.jsxs($.div,{initial:{scale:.96,y:8},animate:{scale:1,y:0},exit:{scale:.96,y:8},onClick:t=>t.stopPropagation(),style:{background:"rgba(15, 17, 26, 0.98)",border:"1px solid rgba(239, 68, 68, 0.25)",borderRadius:16,padding:24,maxWidth:440,width:"calc(100% - 32px)",color:"#f8f9fc"},children:[e.jsx("div",{className:"text-[16px] font-semibold mb-2",children:"Delete this goal?"}),e.jsx("div",{className:"text-[13px] text-white/55 mb-1",children:j.title}),e.jsxs("div",{className:"text-[11px] text-text-muted mb-5",children:["All ",(j.subtasks||[]).length," subtasks will be removed. Can't undo."]}),e.jsxs("div",{className:"flex gap-2 justify-end",children:[e.jsx("button",{onClick:()=>x(null),className:"px-4 py-2 rounded-lg text-[12px] text-text-secondary hover:bg-bg-tertiary",children:"Cancel"}),e.jsx("button",{onClick:()=>d(j),disabled:N===j.id,className:"px-4 py-2 rounded-lg text-[12px] font-medium bg-red-600 text-white hover:bg-red-500 disabled:opacity-50",children:"Delete goal"})]})]})})})]})}function Q({open:a,onClose:s,onCreated:l}){const[c,n]=o.useState(""),[p,r]=o.useState(""),[y,m]=o.useState([]),[u,j]=o.useState(""),[x,N]=o.useState(!1),[k,w]=o.useState(null);o.useEffect(()=>{a||(n(""),r(""),m([]),j(""),w(null))},[a]),o.useEffect(()=>{if(!a)return;const d=f=>{f.key==="Escape"&&s()};return window.addEventListener("keydown",d),()=>window.removeEventListener("keydown",d)},[a,s]);const b=()=>{const d=u.trim();d&&(m(f=>[...f,d]),j(""))},C=async()=>{if(!c.trim()){w("Title is required");return}N(!0),w(null);try{const d={title:c.trim(),description:p.trim()||c.trim(),subtasks:y.map(h=>({title:h,description:h}))},f=await S("/api/goals",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(d)});if(!f.ok){const h=await f.text().catch(()=>"");throw new Error(h||`HTTP ${f.status}`)}l()}catch(d){w(d.message)}N(!1)};return e.jsx(D,{children:a&&e.jsx($.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},style:{position:"fixed",inset:0,background:"rgba(0,0,0,0.7)",backdropFilter:"blur(6px)",zIndex:200,display:"flex",alignItems:"center",justifyContent:"center",padding:16},onClick:s,children:e.jsxs($.div,{initial:{scale:.96,y:8},animate:{scale:1,y:0},exit:{scale:.96,y:8},onClick:d=>d.stopPropagation(),style:{background:"rgba(15, 17, 26, 0.98)",border:"1px solid rgba(99, 102, 241, 0.25)",borderRadius:16,padding:24,maxWidth:520,width:"100%",color:"#f8f9fc"},children:[e.jsxs("div",{className:"flex items-center justify-between mb-5",children:[e.jsx("h2",{className:"text-[16px] font-semibold",children:"New goal"}),e.jsx("button",{onClick:s,className:"text-white/55 hover:text-text p-1",children:e.jsx(L,{size:18})})]}),e.jsx("label",{className:"text-[10px] uppercase tracking-wider text-text-muted font-semibold block mb-1.5",children:"Title"}),e.jsx("input",{value:c,onChange:d=>n(d.target.value),placeholder:"Build the Polymarket monitor",autoFocus:!0,className:"w-full bg-bg-tertiary border border-border rounded-lg px-3 py-2 text-[14px] text-white/95 placeholder-white/25 focus:outline-none focus:border-indigo-500/50 mb-4"}),e.jsx("label",{className:"text-[10px] uppercase tracking-wider text-text-muted font-semibold block mb-1.5",children:"Description (optional)"}),e.jsx("textarea",{value:p,onChange:d=>r(d.target.value),placeholder:"What should TITAN accomplish? Why?",rows:3,className:"w-full bg-bg-tertiary border border-border rounded-lg px-3 py-2 text-[13px] text-white/85 placeholder-white/25 focus:outline-none focus:border-indigo-500/50 resize-none mb-4"}),e.jsx("label",{className:"text-[10px] uppercase tracking-wider text-text-muted font-semibold block mb-1.5",children:"Subtasks (optional)"}),e.jsx("div",{className:"space-y-1.5 mb-2",children:y.map((d,f)=>e.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 rounded-lg bg-bg-tertiary/30 border border-border/50",children:[e.jsxs("span",{className:"text-[11px] text-text-muted tabular-nums",children:[f+1,"."]}),e.jsx("span",{className:"flex-1 text-[12px] text-text",children:d}),e.jsx("button",{onClick:()=>m(h=>h.filter((A,P)=>P!==f)),className:"text-text-muted hover:text-red-400","aria-label":"Remove",children:e.jsx(L,{size:12})})]},f))}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{value:u,onChange:d=>j(d.target.value),onKeyDown:d=>{d.key==="Enter"&&(d.preventDefault(),b())},placeholder:"Add a subtask (press Enter)",className:"flex-1 bg-bg-tertiary border border-border rounded-lg px-3 py-1.5 text-[12px] text-white/85 placeholder-white/25 focus:outline-none focus:border-indigo-500/50"}),e.jsx("button",{onClick:b,disabled:!u.trim(),className:"px-3 rounded-lg text-[12px] bg-bg-tertiary text-text-secondary hover:bg-bg-tertiary disabled:opacity-30",children:"Add"})]}),y.length===0&&e.jsx("p",{className:"text-[10px] text-text-muted italic mt-2",children:"Leaving subtasks empty is fine — TITAN can plan them itself."}),k&&e.jsx("div",{className:"mt-4 p-2 rounded-lg bg-red-500/[0.08] border border-red-500/20 text-[12px] text-red-300",children:k}),e.jsxs("div",{className:"flex gap-2 justify-end mt-6",children:[e.jsx("button",{onClick:s,className:"px-4 py-2 rounded-lg text-[12px] text-text-secondary hover:bg-bg-tertiary",children:"Cancel"}),e.jsx("button",{onClick:C,disabled:x||!c.trim(),className:"px-4 py-2 rounded-lg text-[12px] font-medium bg-indigo-600 text-white hover:bg-indigo-500 disabled:opacity-50",children:x?"Creating…":"Create goal"})]})]})})})}function Z({goal:a,busy:s,onClick:l,onPauseToggle:c,onDelete:n,onRestart:p}){const r=a.subtasks||[],y=r.filter(x=>x.status==="done"||x.status==="skipped").length,m=r.filter(x=>x.status==="running").length,u=r.filter(x=>x.status==="failed").length,j=r.length?y/r.length*100:a.progress||0;return e.jsxs("div",{className:"group p-3 rounded-lg bg-bg-secondary/30 border border-border/50 hover:bg-bg-secondary transition-colors",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 mb-1.5",children:[e.jsx("div",{onClick:l,className:"flex-1 min-w-0 cursor-pointer",children:e.jsx("div",{className:"text-[13px] text-text truncate font-medium",children:a.title})}),e.jsxs("span",{className:"text-[10px] text-text-muted flex-shrink-0 tabular-nums",children:[y,"/",r.length]}),e.jsxs("div",{className:"flex items-center gap-0.5 flex-shrink-0",children:[u>0&&e.jsx("button",{onClick:x=>{x.stopPropagation(),p()},disabled:s,title:`Retry ${u} failed subtask${u===1?"":"s"}`,className:"p-1.5 rounded hover:bg-bg-tertiary text-amber-300/70 hover:text-amber-300 disabled:opacity-40",children:e.jsx(B,{size:12})}),e.jsx("button",{onClick:x=>{x.stopPropagation(),c()},disabled:s,title:a.status==="paused"?"Resume":"Pause",className:"p-1.5 rounded hover:bg-bg-tertiary text-text-muted hover:text-text disabled:opacity-40",children:a.status==="paused"?e.jsx(F,{size:12}):e.jsx(_,{size:12})}),e.jsx("button",{onClick:x=>{x.stopPropagation(),n()},disabled:s,title:"Delete",className:"p-1.5 rounded hover:bg-bg-tertiary text-text-muted hover:text-red-400 disabled:opacity-40",children:e.jsx(M,{size:12})})]})]}),e.jsx("div",{className:"h-1 rounded-full bg-bg-tertiary overflow-hidden mb-2 cursor-pointer",onClick:l,children:e.jsx("div",{className:"h-full transition-all duration-500",style:{width:`${j}%`,background:u>0?"linear-gradient(to right, #34d399, #fbbf24)":"var(--color-emerald)"}})}),e.jsxs("div",{className:"flex items-center gap-3 text-[11px] text-text-muted cursor-pointer",onClick:l,children:[m>0&&e.jsxs("span",{className:"text-cyan-300/80",children:["▶ ",m," running"]}),u>0&&e.jsxs("span",{className:"text-red-300/80",children:["✗ ",u," failed"]}),m===0&&u===0&&r.length>0&&e.jsxs("span",{children:[r.length-y," pending"]}),r.length===0&&e.jsx("span",{className:"italic text-text-muted",children:"no subtasks yet"})]})]})}function E({label:a,count:s,children:l}){return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx("h3",{className:"text-[11px] uppercase tracking-wider text-text-muted font-semibold",children:a}),s!==void 0&&s>0&&e.jsx("span",{className:"text-[10px] text-text-muted tabular-nums",children:s})]}),l]})}function ee(a){if(!a)return"";const s=Date.parse(a);if(isNaN(s))return"";const l=Math.max(0,Math.floor((Date.now()-s)/1e3));if(l<60)return`${l}s ago`;const c=Math.floor(l/60);if(c<60)return`${c}m ago`;const n=Math.floor(c/60);return n<24?`${n}h ago`:`${Math.floor(n/24)}d ago`}export{oe as default};
@@ -1,4 +1,4 @@
1
- import{c as O,r as d,j as e,b as _,Z as $,h as z,f as D,T as B}from"./index-C6oarzis.js";import{P as Z}from"./PageHeader-CF75km05.js";import"./Input-DWnbv1Yh.js";import{I as q}from"./InlineEditableField-DyBCbIoN.js";import{R as N,P as J,C as P,d as A}from"./TitanCanvas-BhurNMK3.js";import{T as E}from"./target-GxtNG2RW.js";import{a as U,C as X}from"./VoiceOverlay-BXPVdnJc.js";import{P as R}from"./play-Dwp2l5HG.js";import{P as I}from"./pause-B0XymOnS.js";import{T as F}from"./trash-2-B4jp_pAQ.js";import{T as L,a as H}from"./toggle-right-CYQd_Ux1.js";/**
1
+ import{c as O,r as d,j as e,b as _,Z as $,h as z,f as D,T as B}from"./index-D7Clon2u.js";import{P as Z}from"./PageHeader-DPJuAgJk.js";import"./Input-BgyHgQ3D.js";import{I as q}from"./InlineEditableField-DOJNOL8m.js";import{R as N,P as J,C as P,d as A}from"./TitanCanvas-BQU1yxqf.js";import{T as E}from"./target-DemL8_0v.js";import{a as U,C as X}from"./VoiceOverlay-l6yoasVz.js";import{P as R}from"./play-hUyR3CVS.js";import{P as I}from"./pause-DqkRWPB_.js";import{T as F}from"./trash-2-Byj4OvKB.js";import{T as L,a as H}from"./toggle-right-Dsk892k5.js";/**
2
2
  * @license lucide-react v0.513.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -1,4 +1,4 @@
1
- import{c as o}from"./index-C6oarzis.js";/**
1
+ import{c as o}from"./index-D7Clon2u.js";/**
2
2
  * @license lucide-react v0.513.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -1,4 +1,4 @@
1
- import{c as t}from"./index-C6oarzis.js";/**
1
+ import{c as t}from"./index-D7Clon2u.js";/**
2
2
  * @license lucide-react v0.513.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -1,4 +1,4 @@
1
- import{c}from"./index-C6oarzis.js";/**
1
+ import{c}from"./index-D7Clon2u.js";/**
2
2
  * @license lucide-react v0.513.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -1,4 +1,4 @@
1
- import{c as o}from"./index-C6oarzis.js";/**
1
+ import{c as o}from"./index-D7Clon2u.js";/**
2
2
  * @license lucide-react v0.513.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -1,4 +1,4 @@
1
- import{c as o}from"./index-C6oarzis.js";/**
1
+ import{c as o}from"./index-D7Clon2u.js";/**
2
2
  * @license lucide-react v0.513.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -1,4 +1,4 @@
1
- import{c as e}from"./index-C6oarzis.js";/**
1
+ import{c as e}from"./index-D7Clon2u.js";/**
2
2
  * @license lucide-react v0.513.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -1,4 +1,4 @@
1
- import{c}from"./index-C6oarzis.js";/**
1
+ import{c}from"./index-D7Clon2u.js";/**
2
2
  * @license lucide-react v0.513.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -1,4 +1,4 @@
1
- import{c}from"./index-C6oarzis.js";/**
1
+ import{c}from"./index-D7Clon2u.js";/**
2
2
  * @license lucide-react v0.513.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.