agent-log-viewer 0.1.1 → 0.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 (131) hide show
  1. package/README.md +171 -51
  2. package/bin/cli.mjs +89 -22
  3. package/bin/tailscale.mjs +101 -41
  4. package/dist/standalone/.next/BUILD_ID +1 -1
  5. package/dist/standalone/.next/app-path-routes-manifest.json +10 -5
  6. package/dist/standalone/.next/build-manifest.json +2 -2
  7. package/dist/standalone/.next/prerender-manifest.json +3 -3
  8. package/dist/standalone/.next/routes-manifest.json +36 -0
  9. package/dist/standalone/.next/server/app/_global-error/page.js +3 -3
  10. package/dist/standalone/.next/server/app/_global-error/page_client-reference-manifest.js +1 -1
  11. package/dist/standalone/.next/server/app/_global-error.html +1 -1
  12. package/dist/standalone/.next/server/app/_global-error.rsc +1 -1
  13. package/dist/standalone/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  14. package/dist/standalone/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
  15. package/dist/standalone/.next/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
  16. package/dist/standalone/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  17. package/dist/standalone/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  18. package/dist/standalone/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  19. package/dist/standalone/.next/server/app/_not-found/page.js +2 -2
  20. package/dist/standalone/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  21. package/dist/standalone/.next/server/app/_not-found.html +1 -1
  22. package/dist/standalone/.next/server/app/_not-found.rsc +4 -4
  23. package/dist/standalone/.next/server/app/_not-found.segments/_full.segment.rsc +4 -4
  24. package/dist/standalone/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
  25. package/dist/standalone/.next/server/app/_not-found.segments/_index.segment.rsc +2 -2
  26. package/dist/standalone/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
  27. package/dist/standalone/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
  28. package/dist/standalone/.next/server/app/_not-found.segments/_tree.segment.rsc +2 -2
  29. package/dist/standalone/.next/server/app/api/access/route.js +1 -1
  30. package/dist/standalone/.next/server/app/api/answer/route.js +1 -1
  31. package/dist/standalone/.next/server/app/api/files/route.js +1 -1
  32. package/dist/standalone/.next/server/app/api/flows/[id]/route.js +1 -1
  33. package/dist/standalone/.next/server/app/api/flows/[id]/route.js.nft.json +1 -1
  34. package/dist/standalone/.next/server/app/api/flows/route.js +1 -1
  35. package/dist/standalone/.next/server/app/api/flows/route.js.nft.json +1 -1
  36. package/dist/standalone/.next/server/app/api/inbox/route.js +1 -1
  37. package/dist/standalone/.next/server/app/api/limits/route.js +1 -1
  38. package/dist/standalone/.next/server/app/api/log/route.js +1 -1
  39. package/dist/standalone/.next/server/app/api/proc/route.js +1 -1
  40. package/dist/standalone/.next/server/app/api/push/route.js +1 -1
  41. package/dist/standalone/.next/server/app/api/spawn/route.js +1 -1
  42. package/dist/standalone/.next/server/app/api/tasks/[id]/route.js +1 -0
  43. package/dist/standalone/.next/server/app/api/tasks/[id]/route.js.nft.json +1 -0
  44. package/dist/standalone/.next/server/app/api/tasks/[id]/route_client-reference-manifest.js +1 -0
  45. package/dist/standalone/.next/server/app/api/tasks/[id]/send/route.js +2 -0
  46. package/dist/standalone/.next/server/app/api/tasks/[id]/send/route.js.nft.json +1 -0
  47. package/dist/standalone/.next/server/app/api/tasks/[id]/send/route_client-reference-manifest.js +1 -0
  48. package/dist/standalone/.next/server/app/api/tasks/[id]/spawn/route.js +1 -0
  49. package/dist/standalone/.next/server/app/api/tasks/[id]/spawn/route.js.nft.json +1 -0
  50. package/dist/standalone/.next/server/app/api/tasks/[id]/spawn/route_client-reference-manifest.js +1 -0
  51. package/dist/standalone/.next/server/app/api/tasks/route.js +1 -0
  52. package/dist/standalone/.next/server/app/api/tasks/route.js.nft.json +1 -0
  53. package/dist/standalone/.next/server/app/api/tasks/route_client-reference-manifest.js +1 -0
  54. package/dist/standalone/.next/server/app/api/timeline/route.js +1 -1
  55. package/dist/standalone/.next/server/app/api/tmux/route.js +2 -2
  56. package/dist/standalone/.next/server/app/api/transcribe/route.js +1 -1
  57. package/dist/standalone/.next/server/app/api/transcribe/token/route.js +1 -0
  58. package/dist/standalone/.next/server/app/api/transcribe/token/route.js.nft.json +1 -0
  59. package/dist/standalone/.next/server/app/api/transcribe/token/route_client-reference-manifest.js +1 -0
  60. package/dist/standalone/.next/server/app/favicon.ico/route.js +1 -1
  61. package/dist/standalone/.next/server/app/index.html +1 -1
  62. package/dist/standalone/.next/server/app/index.rsc +5 -5
  63. package/dist/standalone/.next/server/app/index.segments/__PAGE__.segment.rsc +2 -2
  64. package/dist/standalone/.next/server/app/index.segments/_full.segment.rsc +5 -5
  65. package/dist/standalone/.next/server/app/index.segments/_head.segment.rsc +1 -1
  66. package/dist/standalone/.next/server/app/index.segments/_index.segment.rsc +2 -2
  67. package/dist/standalone/.next/server/app/index.segments/_tree.segment.rsc +2 -2
  68. package/dist/standalone/.next/server/app/page.js +3 -6
  69. package/dist/standalone/.next/server/app/page_client-reference-manifest.js +1 -1
  70. package/dist/standalone/.next/server/app-paths-manifest.json +10 -5
  71. package/dist/standalone/.next/server/chunks/289.js +2 -0
  72. package/dist/standalone/.next/server/chunks/871.js +2 -3
  73. package/dist/standalone/.next/server/functions-config-manifest.json +6 -1
  74. package/dist/standalone/.next/server/middleware-build-manifest.js +1 -1
  75. package/dist/standalone/.next/server/pages/404.html +1 -1
  76. package/dist/standalone/.next/server/pages/500.html +1 -1
  77. package/dist/standalone/.next/server/server-reference-manifest.json +1 -1
  78. package/dist/standalone/.next/static/chunks/258-a0398b569708ffc3.js +1 -0
  79. package/dist/standalone/.next/static/chunks/app/_global-error/page-f4e3cd62c5cbfd22.js +1 -0
  80. package/dist/standalone/.next/static/chunks/app/api/access/route-f4e3cd62c5cbfd22.js +1 -0
  81. package/dist/standalone/.next/static/chunks/app/api/answer/route-f4e3cd62c5cbfd22.js +1 -0
  82. package/dist/standalone/.next/static/chunks/app/api/files/route-f4e3cd62c5cbfd22.js +1 -0
  83. package/dist/standalone/.next/static/chunks/app/api/flows/[id]/route-f4e3cd62c5cbfd22.js +1 -0
  84. package/dist/standalone/.next/static/chunks/app/api/flows/route-f4e3cd62c5cbfd22.js +1 -0
  85. package/dist/standalone/.next/static/chunks/app/api/inbox/route-f4e3cd62c5cbfd22.js +1 -0
  86. package/dist/standalone/.next/static/chunks/app/api/limits/route-f4e3cd62c5cbfd22.js +1 -0
  87. package/dist/standalone/.next/static/chunks/app/api/log/route-f4e3cd62c5cbfd22.js +1 -0
  88. package/dist/standalone/.next/static/chunks/app/api/proc/route-f4e3cd62c5cbfd22.js +1 -0
  89. package/dist/standalone/.next/static/chunks/app/api/push/route-f4e3cd62c5cbfd22.js +1 -0
  90. package/dist/standalone/.next/static/chunks/app/api/spawn/route-f4e3cd62c5cbfd22.js +1 -0
  91. package/dist/standalone/.next/static/chunks/app/api/tasks/[id]/route-f4e3cd62c5cbfd22.js +1 -0
  92. package/dist/standalone/.next/static/chunks/app/api/tasks/[id]/send/route-f4e3cd62c5cbfd22.js +1 -0
  93. package/dist/standalone/.next/static/chunks/app/api/tasks/[id]/spawn/route-f4e3cd62c5cbfd22.js +1 -0
  94. package/dist/standalone/.next/static/chunks/app/api/tasks/route-f4e3cd62c5cbfd22.js +1 -0
  95. package/dist/standalone/.next/static/chunks/app/api/timeline/route-f4e3cd62c5cbfd22.js +1 -0
  96. package/dist/standalone/.next/static/chunks/app/api/tmux/route-f4e3cd62c5cbfd22.js +1 -0
  97. package/dist/standalone/.next/static/chunks/app/api/transcribe/route-f4e3cd62c5cbfd22.js +1 -0
  98. package/dist/standalone/.next/static/chunks/app/api/transcribe/token/route-f4e3cd62c5cbfd22.js +1 -0
  99. package/dist/standalone/.next/static/chunks/app/page-cd0f70a472e144bd.js +2 -0
  100. package/dist/standalone/.next/static/chunks/next/dist/client/components/builtin/app-error-f4e3cd62c5cbfd22.js +1 -0
  101. package/dist/standalone/.next/static/chunks/next/dist/client/components/builtin/forbidden-f4e3cd62c5cbfd22.js +1 -0
  102. package/dist/standalone/.next/static/chunks/next/dist/client/components/builtin/not-found-f4e3cd62c5cbfd22.js +1 -0
  103. package/dist/standalone/.next/static/chunks/next/dist/client/components/builtin/unauthorized-f4e3cd62c5cbfd22.js +1 -0
  104. package/dist/standalone/.next/static/css/3f6c482d54e91e64.css +1 -0
  105. package/dist/standalone/.next/static/dxjlPz3fKtXT-7BfdVO_q/_buildManifest.js +1 -0
  106. package/dist/standalone/package.json +4 -2
  107. package/package.json +4 -2
  108. package/dist/standalone/.next/static/0YxRBiEgYCSV92_fZOmmC/_buildManifest.js +0 -1
  109. package/dist/standalone/.next/static/chunks/703-1f675e3bf3e228de.js +0 -1
  110. package/dist/standalone/.next/static/chunks/app/_global-error/page-b58291c8001879c8.js +0 -1
  111. package/dist/standalone/.next/static/chunks/app/api/access/route-b58291c8001879c8.js +0 -1
  112. package/dist/standalone/.next/static/chunks/app/api/answer/route-b58291c8001879c8.js +0 -1
  113. package/dist/standalone/.next/static/chunks/app/api/files/route-b58291c8001879c8.js +0 -1
  114. package/dist/standalone/.next/static/chunks/app/api/flows/[id]/route-b58291c8001879c8.js +0 -1
  115. package/dist/standalone/.next/static/chunks/app/api/flows/route-b58291c8001879c8.js +0 -1
  116. package/dist/standalone/.next/static/chunks/app/api/inbox/route-b58291c8001879c8.js +0 -1
  117. package/dist/standalone/.next/static/chunks/app/api/limits/route-b58291c8001879c8.js +0 -1
  118. package/dist/standalone/.next/static/chunks/app/api/log/route-b58291c8001879c8.js +0 -1
  119. package/dist/standalone/.next/static/chunks/app/api/proc/route-b58291c8001879c8.js +0 -1
  120. package/dist/standalone/.next/static/chunks/app/api/push/route-b58291c8001879c8.js +0 -1
  121. package/dist/standalone/.next/static/chunks/app/api/spawn/route-b58291c8001879c8.js +0 -1
  122. package/dist/standalone/.next/static/chunks/app/api/timeline/route-b58291c8001879c8.js +0 -1
  123. package/dist/standalone/.next/static/chunks/app/api/tmux/route-b58291c8001879c8.js +0 -1
  124. package/dist/standalone/.next/static/chunks/app/api/transcribe/route-b58291c8001879c8.js +0 -1
  125. package/dist/standalone/.next/static/chunks/app/page-169f116d08445993.js +0 -5
  126. package/dist/standalone/.next/static/chunks/next/dist/client/components/builtin/app-error-b58291c8001879c8.js +0 -1
  127. package/dist/standalone/.next/static/chunks/next/dist/client/components/builtin/forbidden-b58291c8001879c8.js +0 -1
  128. package/dist/standalone/.next/static/chunks/next/dist/client/components/builtin/not-found-b58291c8001879c8.js +0 -1
  129. package/dist/standalone/.next/static/chunks/next/dist/client/components/builtin/unauthorized-b58291c8001879c8.js +0 -1
  130. package/dist/standalone/.next/static/css/e3457e19c8be328e.css +0 -1
  131. /package/dist/standalone/.next/static/{0YxRBiEgYCSV92_fZOmmC → dxjlPz3fKtXT-7BfdVO_q}/_ssgManifest.js +0 -0
@@ -1,5 +0,0 @@
1
- (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[974],{5039:(e,t,n)=>{Promise.resolve().then(n.bind(n,8015))},8015:(e,t,n)=>{"use strict";n.d(t,{Viewer:()=>ro});var r=n(5155),l=n(9005),i=n(2115);function s(e,t=160){let n=e.replace(/\[([^\]]+)\]\(([^)]+)\)/g,"$1").replace(/`([^`]+)`/g,"$1").replace(/[*_~#>]+/g,"").replace(/\s+/g," ").trim().replace(/(?:\/[^\s)]+){3,}/g,e=>{if(e.length<=40)return e;let t=e.split("/").filter(Boolean);return t.length>=2?".../"+t.slice(-2).join("/"):e}).replace(/\s+/g," ").trim();return n.length>t?n.slice(0,t-1).trimEnd()+"…":n}let a="__overview__",o=e=>Math.floor(e/300);function c(e){return"live"===e.activity?0:"recent"===e.activity?1:"stalled"===e.activity?2:3}function d(e){return"claude-projects"===e.root?"сесія"===e.kind&&!e.parent:"codex-sessions"===e.root&&!e.parent}function u(e){return"claude-projects"===e.root&&"субагент"===e.kind}function x(e){return!!u(e)||!!e.handoff&&!!e.parent||"codex-sessions"===e.root&&!!e.parent}function p(e){return"shell"===e.engine||"codex-jobs"===e.root}function f(e){return e.project||"інше"}function m(e){let t=new Map;for(let n of e){let e=f(n),r=t.get(e);r||(r={project:e,liveCount:0,attentionCount:0,conversations:0,smt:0},t.set(e,r)),"live"===n.activity&&(r.liveCount+=1),(n.pendingQuestion||n.waitingInput)&&(r.attentionCount+=1),d(n)&&(r.conversations+=1),r.smt=Math.max(r.smt,n.mtime)}return[...t.values()].sort((e,t)=>{let n=e.attentionCount>0;return n!==t.attentionCount>0?n?-1:1:e.liveCount!==t.liveCount?t.liveCount-e.liveCount:o(t.smt)-o(e.smt)||e.project.localeCompare(t.project)})}function h(e){let t=new Map;for(let n of e){if(!n.parent)continue;let e=t.get(n.parent);e?e.push(n):t.set(n.parent,[n])}return t}function b(e,t){let n=[],r=[...t.get(e.path)??[]],l=new Set([e.path]);for(;r.length;){let e=r.pop();l.has(e.path)||(l.add(e.path),n.push(e),r.push(...t.get(e.path)??[]))}return n}function g(e){return!p(e)&&("live"===e.activity||"recent"===e.activity&&x(e))}function v(e,t){let n=new Map(e.map(e=>[e.path,e])),r=h(e),l=new Map,i=new Map;for(let r of e)if(f(r)===t){if("live"===r.activity||"recent"===r.activity&&x(r)){let e=function(e,t){let n=new Set,r=e;for(;r.parent&&!n.has(r.path);){n.add(r.path);let e=t.get(r.parent);if(!e)break;r=e}return r}(r,n);p(e)?i.set(e.path,e):l.set(e.path,e);continue}"recent"===r.activity&&d(r)&&l.set(r.path,r)}let s=[...l.values()].map(e=>(function(e,t,n){let r=b(e,t),l=r.filter(g).sort((e,t)=>("live"!==e.activity)-("live"!==t.activity)||o(t.mtime)-o(e.mtime)||e.path.localeCompare(t.path)),i=r.filter(e=>p(e)&&"live"===e.activity).sort((e,t)=>o(t.mtime)-o(e.mtime)||e.path.localeCompare(t.path)),s=[e,...l].map(e=>({file:e,tasks:[]})),a=new Map(s.map(e=>[e.file.path,e]));for(let e of i)(e.parent&&a.get(e.parent)||s[0]).tasks.push(e);let c=new Set([...a.keys(),...i.map(e=>e.path)]),d=r.filter(e=>!c.has(e.path)).sort((e,t)=>t.mtime-e.mtime),u=d.filter(e=>x(e)&&function(e,t){let n=new Set([e.path]),r=e;for(;r.parent&&!n.has(r.parent);){let e=t.get(r.parent);if(!e)break;if(n.add(e.path),"сесія"===e.kind)return"live"===e.activity||"recent"===e.activity;r=e}return!1}(e,n)),f=new Set(u.map(e=>e.path)),m=d.filter(e=>!f.has(e.path)),h=Math.max(...s.map(e=>e.file.mtime),...i.map(e=>e.mtime));return{key:e.path,columns:s,returnable:u,finished:m,smt:h,orphanTask:!1}})(e,r,n));for(let e of i.values())s.push({key:e.path,columns:[{file:e,tasks:[]}],returnable:[],finished:[],smt:e.mtime,orphanTask:!0});return s.sort((e,t)=>e.orphanTask!==t.orphanTask?e.orphanTask?1:-1:o(t.smt)-o(e.smt)||e.key.localeCompare(t.key))}function w(e){let t=new Map;for(let n of e){if("closed"===n.state)continue;let e=t.get(n.implementerPath);(!e||n.createdAt>e.createdAt)&&t.set(n.implementerPath,n)}return t}function j(e){let t=new Set;for(let n of e)for(let e of n.rounds)e.reviewerPath&&t.add(e.reviewerPath);return t}let y={waiting_ready:"чекає READY",spawn_pending:"готовий спавнити ревʼюера",spawning:"запускаю ревʼюера",reviewing:"ревью",relay_pending:"вердикт є — передати?",relaying:"передаю зауваження",fixing:"фікси",approved:"затверджено",done_comment:"готово із зауваженнями",needs_decision:"потребує рішення",paused:"пауза",closed:"закрито"},N=new Set(["spawn_pending","relay_pending","needs_decision","paused","approved"]),k={APPROVE:"✓",REQUEST_CHANGES:"✖",COMMENT:"◆"};function S(e){return"APPROVE"===e?{color:"#1a8a3e",soft:"#e7f4ea"}:"REQUEST_CHANGES"===e?{color:"#c62828",soft:"#fbeaea"}:"COMMENT"===e?{color:"#b07d1f",soft:"#fdf3dd"}:{color:"#8b8b95",soft:"#efeff3"}}async function C(e,t){try{let n=await fetch(`/api/flows/${encodeURIComponent(e)}`,{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify(t)});if(n.ok)return null;let r=await n.json().catch(()=>null);return r?.error??`не вдалося (${n.status})`}catch{return"сервер недоступний"}}function $(e){let t=Date.now()/1e3-e;return t<90?Math.round(t)+" с тому":t<5400?Math.round(t/60)+" хв тому":t<129600?Math.round(t/3600)+" год тому":Math.round(t/86400)+" д тому"}function A(e){if("string"!=typeof e&&"number"!=typeof e)return"";let t=new Date(e);return Number.isNaN(t.getTime())?"":t.toLocaleTimeString("uk",{hour12:!1})}function E(e,t,n,r){let l=e%10,i=e%100;return 1===l&&11!==i?t:l>=2&&l<=4&&(i<12||i>14)?n:r}function M(e){return"live"===e?"animate-pulse bg-ok":"recent"===e?"bg-[#d29a2f]":"stalled"===e?"bg-err":"bg-[#c9c9d1]"}let R={codex:{color:"#2f6fd0",soft:"#e8f0fb"},claude:{color:"#d97757",soft:"#faeee9"}},T={color:"#9a9aa4",soft:"#ececf1"},P=[[/fable|mythos/,{color:"#c2410c",soft:"#fbeade"}],[/opus/,{color:"#8a5ad6",soft:"#f1ebfb"}],[/sonnet/,{color:"#e0913f",soft:"#fbf1e4"}],[/haiku/,{color:"#d9a58c",soft:"#f9f1ec"}]],_=[[/spark/,{color:"#5ea3e4",soft:"#ecf4fd"}],[/mini|nano/,{color:"#7fb1e8",soft:"#eff6fd"}],[/codex/,{color:"#1d55ab",soft:"#e4edfa"}]];function I(e){let t=R[e.engine];if(!t)return T;let n=(e.model??"").toLowerCase();for(let[t,r]of"codex"===e.engine?_:P)if(t.test(n))return r;return t}let z={minimal:{dl:20,ds:-32},low:{dl:12,ds:-20},medium:{dl:0,ds:0},high:{dl:-8,ds:12},xhigh:{dl:-14,ds:22},max:{dl:-19,ds:30}};function L(e,t,n){let[r,l,i]=function(e){let t=parseInt(e.slice(1),16),n=(t>>16&255)/255,r=(t>>8&255)/255,l=(255&t)/255,i=Math.max(n,r,l),s=Math.min(n,r,l),a=(i+s)/2,o=i-s;if(0===o)return[0,0,100*a];let c=o/(1-Math.abs(2*a-1));return[60*(i===n?((r-l)/o+6)%6:i===r?(l-n)/o+2:(n-r)/o+4),100*c,100*a]}(e),s=e=>Math.min(100,Math.max(0,e));return`hsl(${Math.round(r)} ${Math.round(s(l+n))}% ${Math.round(s(i+t))}%)`}function D(e){let t=I(e),n=z[e.effort??""];return n?{color:L(t.color,n.dl,n.ds),soft:L(t.soft,Math.round(n.dl/3),Math.round(n.ds/2))}:t}function O(e){return e.effort?`Зусилля міркування: ${e.effort}`:void 0}function F(e){let t={codex:"Codex",claude:"Claude",shell:"Bash"}[e.engine]??e.engine,n=R[e.engine]??T;return{label:t,style:{backgroundColor:n.soft,color:n.color}}}function U(e,t){return Math.floor(t.smt/300)-Math.floor(e.smt/300)||e.file.path.localeCompare(t.file.path)}function q(e){return u(e)&&"running"!==e.proc}function J(e,t=Date.now()/1e3){return!!e.pendingQuestion||!!e.waitingInput||("stalled"===e.activity?!q(e)&&t-e.mtime<=7200:"recent"===e.activity&&("claude"===e.engine||"codex"===e.engine)&&d(e)&&!u(e))}function H(e,t,n,r,l=Y,a=B){return(0,i.useMemo)(()=>{let i=function(e){let t=h(e),n=new Map;for(let r of e){let e=[...t.get(r.path)??[]],l=new Set,i=0;for(;e.length;){let n=e.pop();l.has(n.path)||(l.add(n.path),i+=1,e.push(...t.get(n.path)??[]))}n.set(r.path,i)}return n}(e),o=new Map;for(let e of t){let t=o.get(e.file);(!t||e.ts>t.ts)&&o.set(e.file,e)}let c=w(a),u=j(a),x=n.trim().toLowerCase(),m=e.filter(e=>!l.has(e.path)&&!u.has(e.path)&&(d(e)||"live"===e.activity||"stalled"===e.activity||"recent"===e.activity&&!p(e))).map(e=>{let t=f(e),n=s(e.title),l=r-e.mtime,a=c.get(e.path),d=e.pendingQuestion||e.waitingInput?"waiting":"live"===e.activity?"working":J(e,r)?"waiting":l<=86400?"recent":"older",u=function(e,t){if(e.pendingQuestion)return"plan"===e.pendingQuestion.kind?"чекає затвердження плану":"чекає відповіді на питання";if(e.waitingInput)return"чекає на відповідь у терміналі";if("live"===e.activity&&e.plan?.current)return`${e.plan.done}/${e.plan.total} \xb7 ${e.plan.current}`;let n=t.get(e.path);return n?`${n.label} \xb7 ${$(n.ts)}`:"live"===e.activity?"працює…":q(e)?"повернувся з результатом":"stalled"===e.activity?"перервано або чекає дозволу":J(e)?"закінчив хід — чекає відповіді":""}(e,o);return a&&(N.has(a.state)?d="waiting":("reviewing"===a.state||"relaying"===a.state||"spawning"===a.state)&&(d="working"),u=`флоу: ${y[a.state]}${a.stateDetail?` — ${a.stateDetail}`:""}`),{file:e,project:t,title:n,descendants:i.get(e.path)??0,smt:e.mtime,kind:d,statusLine:u}}).filter(e=>!x||`${e.title} ${e.project}`.toLowerCase().includes(x)),b=(e,t)=>t.smt-e.smt||e.file.path.localeCompare(t.file.path),g=m.filter(e=>"waiting"===e.kind).sort(b),v=m.filter(e=>"working"===e.kind).sort(b);return{waiting:g,working:v,recent:m.filter(e=>"recent"===e.kind).sort(U),older:m.filter(e=>"older"===e.kind).sort(U),livePreview:v.slice(0,3)}},[e,t,n,r,l,a])}let Y=new Set,B=[];function X(e,t=Date.now()/1e3){return e.pendingQuestion||e.waitingInput?"waiting":"live"===e.activity?"live":"recent"===e.activity&&x(e)&&"running"!==e.proc?"returned":J(e,t)?"stalled"===e.activity?"stalled":"waiting":"done"}let W="llvSound";function Q(){try{return"off"!==localStorage.getItem(W)}catch{return!0}}let K=new Map,V=null;function G(){if(!V){let e=window.AudioContext??window.webkitAudioContext;if(!e)return null;V=new e}return V}let Z={waiting:[{freq:784,at:0,dur:.5},{freq:1175,at:.16,dur:.75}],returned:[{freq:659,at:0,dur:.3},{freq:784,at:.09,dur:.3},{freq:988,at:.18,dur:.65}],stalled:[{freq:880,at:0,dur:.35},{freq:587,at:.14,dur:.7}],question:[{freq:1047,at:0,dur:.28},{freq:1319,at:.12,dur:.35},{freq:1568,at:.24,dur:.6}]};function ee(e,t,n=0){if(!Q())return;let r=G();if(!r)return;if("running"!==r.state)return void r.resume().catch(()=>void 0);let l=r.currentTime+.02+n/1e3,i=r.destination;if("function"==typeof r.createStereoPanner){let e=r.createStereoPanner();e.pan.value=Math.max(-1,Math.min(1,t)),e.connect(r.destination),i=e}for(let t of Z[e])!function(e,t,n,r){let l=r+n.at,i=e.createOscillator();i.type="sine",i.frequency.value=n.freq;let s=e.createGain();s.gain.setValueAtTime(0,l),s.gain.linearRampToValueAtTime(.07,l+.012),s.gain.exponentialRampToValueAtTime(4e-4,l+n.dur),i.connect(s).connect(t),i.start(l),i.stop(l+n.dur+.05);let a=e.createOscillator();a.type="sine",a.frequency.value=2*n.freq;let o=e.createGain();o.gain.setValueAtTime(0,l),o.gain.linearRampToValueAtTime(.0126,l+.012),o.gain.exponentialRampToValueAtTime(3e-4,l+.7*n.dur),a.connect(o).connect(t),a.start(l),a.stop(l+n.dur)}(r,i,t,l)}let et={waiting:"waiting",returned:"returned",stalled:"stalled"},en="llvArchivedProjects";function er(e){try{window.localStorage.setItem(en,JSON.stringify([...e]))}catch{}}let el={files:[],flows:[]},ei=[[1920,4],[1440,3],[1024,2]];function es({files:e,archivedProjects:t,onSelectProject:n,onSelectFile:l}){let a=function(){let[e,t]=(0,i.useState)(3);return(0,i.useEffect)(()=>{let e=()=>t(function(){for(let[e,t]of ei)if(window.innerWidth>=e)return t;return 1}());return window.addEventListener("resize",e),e(),()=>window.removeEventListener("resize",e)},[]),e}(),o=(0,i.useMemo)(()=>m(e),[e]),c=(0,i.useMemo)(()=>o.filter(e=>!t.has(e.project)),[o,t]),d=o.length-c.length,u=(0,i.useMemo)(()=>c.reduce((e,t)=>e+t.liveCount,0),[c]),x=c.filter(e=>e.liveCount>0).length,p=(0,i.useMemo)(()=>c.map(t=>{let n=v(e,t.project).flatMap(e=>e.columns.flatMap(e=>[e.file,...e.tasks])).filter(e=>"live"===e.activity),r=n.slice(0,4),l=e.filter(e=>f(e)===t.project).sort((e,t)=>t.mtime-e.mtime)[0];return{summary:t,liveBranches:r,moreLive:n.length-r.length,latest:l}}),[e,c]);return(0,r.jsxs)("div",{className:"flex min-h-0 min-w-0 flex-1 flex-col",children:[(0,r.jsxs)("div",{className:"flex h-10 shrink-0 items-center gap-2.5 border-b border-line bg-panel px-4",children:[(0,r.jsx)("h1",{className:"text-[13.5px] font-bold",children:"Огляд"}),(0,r.jsxs)("span",{className:"text-[11.5px] text-dim",children:[u?`${u} ${E(u,"гілка працює","гілки працюють","гілок працюють")} у ${x} ${E(x,"проєкті","проєктах","проєктах")}`:"зараз нічого не працює",d?` \xb7 ${d} в архіві`:""]})]}),(0,r.jsxs)("div",{className:"grid flex-1 auto-rows-min gap-2.5 overflow-y-auto p-3",style:{gridTemplateColumns:`repeat(${a}, minmax(0, 1fr))`},children:[p.map(({summary:e,liveBranches:t,moreLive:i,latest:a})=>(0,r.jsxs)("button",{className:"flex flex-col gap-1.5 rounded-[10px] border border-line bg-panel p-3 text-left shadow-card hover:border-accent/40 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40",onClick:()=>n(e.project),children:[(0,r.jsxs)("span",{className:"flex items-center gap-2",children:[(0,r.jsx)("span",{className:`h-2 w-2 shrink-0 rounded-full ${e.liveCount?"animate-pulse bg-ok":"bg-[#d6d6dd]"}`}),(0,r.jsx)("span",{className:"min-w-0 flex-1 truncate text-[13px] font-bold",children:e.project}),e.liveCount?(0,r.jsx)("span",{className:"shrink-0 rounded-full bg-[#e5f6ea] px-1.5 py-0.5 text-[10.5px] font-bold text-ok",children:e.liveCount}):null,(0,r.jsx)("span",{className:"shrink-0 text-[11px] font-semibold text-dim",children:e.conversations})]}),t.length?(0,r.jsxs)("span",{className:"flex flex-col gap-1",children:[t.map(e=>{let t=F(e);return(0,r.jsxs)("span",{className:"flex cursor-pointer items-center gap-1.5 rounded-[8px] px-1 py-0.5 text-[11.5px] hover:bg-bg",role:"link",tabIndex:0,title:s(e.title),onClick:t=>{t.stopPropagation(),l(e)},onKeyDown:t=>{"Enter"===t.key&&(t.stopPropagation(),l(e))},children:[(0,r.jsx)("span",{className:`h-1.5 w-1.5 shrink-0 rounded-full ${M(e.activity)}`}),(0,r.jsx)("span",{className:"shrink-0 rounded-full px-1.5 text-[9px] font-bold",style:t.style,children:t.label}),(0,r.jsx)("span",{className:"truncate font-semibold",children:s(e.title,70)})]},e.path)}),i>0?(0,r.jsxs)("span",{className:"px-1 text-[10.5px] font-semibold text-dim",children:["ще ",i," live"]}):null]}):(0,r.jsxs)("span",{className:"text-[11px] text-dim",children:["тихо \xb7 остання активність ",a?$(a.mtime):"—"]})]},e.project)),c.length?null:(0,r.jsx)("div",{className:"col-span-full mt-[20vh] text-center text-dim",children:"Логів поки нема"})]})]})}var ea=n(5480),eo=n(6408),ec=n(2159),ed=n(7218),eu=n(9805),ex=n(467),ep=n(99),ef=n(7381),em=n(5045),eh=n(4577),eb=n(6721),eg=n(4088),ev=n(4962),ew=n(5222),ej=n(6210),ey=n(5796),eN=n(4551),ek=n(5688),eS=n(6619),eC=n(6851),e$=n(852),eA=n(4179),eE=n(5738),eM=n(7990),eR=n(6449),eT=n(8910),eP=n(7979),e_=n(5561),eI=n(966),ez=n(2750),eL=n(2571);let eD={shell:eb.A,tool:eM.A,"cmd-group":eR.A,codex:ew.A,claude:eC.A,image:ej.A,blob:eT.A,note:eP.A,citation:e_.A,message:ey.A,shutdown:eI.A,plan:ez.A};function eO({name:e,className:t}){let n=eD[e];return(0,r.jsx)(n,{className:t??"h-3.5 w-3.5","aria-hidden":!0})}var eF=n(8747),eU=n(7650);let eq="#0d9488",eJ=new Map;function eH(){for(let e of document.querySelectorAll("[data-link-hover]"))e.removeAttribute("data-link-hover")}function eY(e,t,n,r){let l=Math.max(48,.45*Math.abs(n-e));return`M ${e} ${t} C ${e+l} ${t}, ${n-l} ${r}, ${n} ${r}`}function eB({source:e,drop:t,onClose:n}){let a=(0,i.useRef)(null),[o,c]=(0,i.useState)(""),[d,u]=(0,i.useState)(!1),[x,p]=(0,i.useState)(null),f=t.file,m=F(f);(0,i.useEffect)(()=>{let e=e=>{"Escape"===e.key&&n()},t=e=>{a.current&&!a.current.contains(e.target)&&n()};return window.addEventListener("keydown",e),window.addEventListener("pointerdown",t),()=>{window.removeEventListener("keydown",e),window.removeEventListener("pointerdown",t)}},[n]),(0,i.useEffect)(()=>{if(x?.kind!=="ok")return;let e=window.setTimeout(n,1800);return()=>window.clearTimeout(e)},[x,n]);let h=Math.max(8,Math.min(t.to.x+14,window.innerWidth-340-8)),b=Math.max(8,Math.min(t.to.y+12,window.innerHeight-320)),g=async()=>{if(d||!o.trim())return;u(!0),p(null);let t=`Тобі передали контекст іншого агента — розмову \xab${s(e.title,80)}\xbb. Її транскрипт: ${e.path} — спочатку прочитай цей файл, щоб мати повний контекст, а тоді виконай прохання нижче.
2
-
3
- ${o.trim()}`;try{let e=await fetch("/api/tmux",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({...null!==f.pid?{pid:f.pid}:{},path:f.path,text:t})}),n=await e.json();if(!e.ok||!n.ok)return void p({kind:"err",text:n.error??"не вдалося надіслати"});p({kind:"ok",text:n.spawned?`агент прокинувся у tmux ${n.target??""}`:`надіслано у tmux ${n.target??""}`})}catch{p({kind:"err",text:"сервер недоступний"})}finally{u(!1)}};return(0,r.jsxs)("div",{ref:a,className:"pointer-events-auto fixed flex w-[340px] cursor-default flex-col gap-2.5 rounded-[12px] border border-line bg-panel p-3 shadow-[0_8px_28px_rgba(20,20,30,0.14)]",style:{left:h,top:b},children:[(0,r.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,r.jsx)(eF.A,{className:"h-3.5 w-3.5 shrink-0",style:{color:eq},"aria-hidden":!0}),(0,r.jsx)("span",{className:"min-w-0 flex-1 truncate text-[12px] font-bold",children:"звʼязати агентів"}),(0,r.jsx)("button",{type:"button","aria-label":"Закрити картку звʼязування",onClick:n,className:"inline-flex shrink-0 items-center rounded-[8px] border border-line bg-bg px-1.5 py-0.5 text-dim hover:text-ink focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40",children:(0,r.jsx)(l.A,{className:"h-3 w-3","aria-hidden":!0})})]}),(0,r.jsxs)("div",{className:"flex flex-col gap-1.5 rounded-[8px] border border-line bg-bg px-2 py-2",children:[(0,r.jsxs)("div",{className:"flex min-w-0 items-center gap-1.5",children:[(0,r.jsx)("span",{className:"w-[64px] shrink-0 text-[10px] font-semibold text-dim",children:"кому"}),(0,r.jsx)("span",{className:"shrink-0 rounded-full px-1.5 py-0.5 text-[9.5px] font-bold",style:m.style,children:m.label}),(0,r.jsx)("span",{className:"min-w-0 flex-1 truncate text-[10.5px] font-semibold",title:s(f.title),children:s(f.title,60)})]}),(0,r.jsxs)("div",{className:"flex min-w-0 items-center gap-1.5",children:[(0,r.jsx)("span",{className:"w-[64px] shrink-0 text-[10px] font-semibold text-dim",children:"контекст"}),(0,r.jsx)("span",{className:"min-w-0 flex-1 truncate font-mono text-[10px] text-ink",title:e.path,children:e.path})]})]}),(0,r.jsx)("p",{className:"text-[10.5px] text-dim",children:"Агент отримає шлях до цього транскрипта з пропозицією прочитати розмову. Додай, що саме в нього попросити:"}),(0,r.jsx)("textarea",{value:o,onChange:e=>c(e.target.value),rows:4,autoFocus:!0,placeholder:"що зробити з цим контекстом…","aria-label":"Прохання для звʼязаного агента",className:"resize-y rounded-[8px] border border-line bg-bg px-2 py-1.5 text-[12px] text-ink focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40"}),(0,r.jsx)("div",{className:"flex items-center",children:(0,r.jsx)("button",{type:"button",disabled:d||!o.trim(),onClick:()=>void g(),className:"ml-auto rounded-[8px] border px-3 py-1.5 text-[12px] font-bold text-white hover:opacity-90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/50 disabled:opacity-40",style:{backgroundColor:eq,borderColor:eq},children:d?"звʼязую…":"▶ Звʼязати"})}),d?(0,r.jsx)("span",{className:"text-[10.5px] text-dim",children:"якщо агент не запущений — резюмую його вікно (до хвилини)…"}):null,x?(0,r.jsx)("span",{className:`text-[11px] font-semibold ${"ok"===x.kind?"text-ok":"text-err"}`,children:x.text}):null]})}function eX({file:e,onDeleted:t}){let[n,l]=(0,i.useState)(!1),[s,a]=(0,i.useState)(!1),[o,c]=(0,i.useState)("");if((0,i.useEffect)(()=>{if(!n)return;let e=window.setTimeout(()=>l(!1),5e3);return()=>window.clearTimeout(e)},[n]),"running"===e.proc)return null;let d=async()=>{a(!0),c("");try{let n=await fetch(`/api/log?path=${encodeURIComponent(e.path)}`,{method:"DELETE"}),r=await n.json();if(!n.ok||!r.ok)return void c(r.error??"не вдалося видалити");l(!1),t?.()}catch{c("сервер недоступний")}finally{a(!1)}};return n?(0,r.jsxs)("span",{className:"inline-flex shrink-0 items-center gap-1 rounded-[10px] border border-err/30 bg-[#fff5f5] px-1.5 py-0.5 text-[11px]",children:[(0,r.jsx)("span",{className:"px-0.5 font-semibold text-err",children:"Видалити з диска?"}),(0,r.jsx)("button",{type:"button",className:"rounded-lg bg-err px-2 py-0.5 font-bold text-white disabled:opacity-60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-err/50",disabled:s,onClick:d,children:s?"…":"Так"}),(0,r.jsx)("button",{type:"button",className:"rounded-lg border border-line bg-panel px-2 py-0.5 font-semibold text-dim focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40",onClick:()=>l(!1),children:"Ні"})]}):(0,r.jsxs)("span",{className:"inline-flex shrink-0 items-center gap-1",children:[(0,r.jsx)("button",{type:"button",className:"inline-flex items-center rounded-[8px] border border-line bg-bg px-1.5 py-0.5 text-dim hover:border-err/40 hover:text-err focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40","aria-label":"Видалити розмову з диска",title:"Видалити розмову з диска",onClick:()=>l(!0),children:(0,r.jsx)(eE.A,{className:"h-3 w-3","aria-hidden":!0})}),o?(0,r.jsx)("span",{className:"max-w-[160px] truncate text-[10.5px] font-semibold text-err",title:o,children:o}):null]})}function eW({className:e,style:t,enter:n="scale",children:l}){let s=(0,i.useRef)(null);return!function(e,t="scale"){let n=(0,i.useRef)(new Map),r=(0,i.useRef)(new WeakMap),l=(0,i.useRef)(!0);(0,i.useLayoutEffect)(()=>{let i=e.current;if(!i)return;let s="u">typeof matchMedia&&matchMedia("(prefers-reduced-motion: reduce)").matches,a=i.getBoundingClientRect(),o=[...i.children].filter(e=>e instanceof HTMLElement&&void 0!==e.dataset.flipKey),c=new Map;for(let e of o){let o=e.dataset.flipKey,d=e.getBoundingClientRect(),u=r.current.get(e);u&&(u.cancel(),r.current.delete(e));let x=e.getBoundingClientRect(),p={x:x.left-a.left+i.scrollLeft,y:x.top-a.top+i.scrollTop},f=n.current.get(o);if(c.set(o,p),s||l.current||void 0!==e.dataset.flipSkip)continue;if(!f){if("none"===t)continue;let n="fade"===t?[{opacity:0},{opacity:1}]:[{opacity:0,transform:"scale(0.96)"},{opacity:1,transform:"scale(1)"}],l=e.animate(n,{duration:"fade"===t?120:240,easing:"ease-out"});r.current.set(e,l),l.addEventListener("finish",()=>r.current.delete(e));continue}let m=f.x-p.x+(d.left-x.left),h=f.y-p.y+(d.top-x.top);if(2>Math.abs(m)&&2>Math.abs(h))continue;let b=e.animate([{transform:`translate(${m}px, ${h}px)`},{transform:"translate(0px, 0px)"}],{duration:280,easing:"cubic-bezier(0.22, 0.72, 0.3, 1)"});r.current.set(e,b),b.addEventListener("finish",()=>r.current.delete(e))}n.current=c,l.current=!1})}(s,n),(0,r.jsx)("div",{ref:s,className:e,style:t,children:l})}var eQ=n(8617),eK=n(9314);function eV({file:e}){return"running"===e.proc?(0,r.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full bg-[#e5f6ea] px-2 py-0.5 text-[11px] font-bold text-ok",children:[(0,r.jsx)(eS.A,{className:"h-3 w-3","aria-hidden":!0})," PID ",e.pid]}):"killed"===e.proc||"stalled"===e.activity?(0,r.jsx)("span",{className:"inline-flex items-center gap-1 rounded-full bg-[#f7e8e8] px-2 py-0.5 text-[11px] font-bold text-err",children:"перервано"}):"done"===e.proc?(0,r.jsx)("span",{className:"inline-flex items-center gap-1 rounded-full bg-chip px-2 py-0.5 text-[11px] font-bold text-dim",children:"завершено"}):null}function eG({file:e,compact:t=!1}){let[n,l]=(0,i.useState)(!1),[s,a]=(0,i.useState)(!1),[o,c]=(0,i.useState)(""),[d,u]=(0,i.useState)(!1);(0,i.useEffect)(()=>{if(!n)return;let e=window.setTimeout(()=>l(!1),5e3);return()=>window.clearTimeout(e)},[n]);let x=(0,r.jsx)(eV,{file:e}),p=async()=>{a(!0),c("");try{let t=await fetch("/api/proc",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({path:e.path,force:d})}),n=await t.json();if(!t.ok||!n.ok){c(n.error??"помилка зупинки"),u(!0);return}c(`надіслано ${d?"SIGKILL":"SIGTERM"} PID ${n.pid}`),l(!1)}catch{c("сервер недоступний"),u(!0)}finally{a(!1)}};return(0,r.jsxs)("span",{className:`inline-flex min-w-0 flex-wrap items-center gap-1.5 ${t?"text-[10.5px]":"text-xs"}`,children:[x,"running"===e.proc?n?(0,r.jsxs)("span",{className:"inline-flex max-w-full items-center gap-1 rounded-[10px] border border-err/30 bg-[#fff5f5] px-1.5 py-0.5",children:[t?null:(0,r.jsxs)("span",{className:"truncate px-1 text-[11px] font-semibold text-err",children:["Точно вбити PID ",e.pid,"?"]}),(0,r.jsx)("button",{className:"rounded-lg bg-err px-2 py-0.5 text-[11px] font-bold text-white disabled:opacity-60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-err/50",disabled:s,onClick:p,children:d?"SIGKILL":t?`Вбити ${e.pid}`:"Так, вбити"}),(0,r.jsx)("button",{className:"rounded-lg border border-line bg-panel px-2 py-0.5 text-[11px] font-semibold text-dim focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40",onClick:()=>l(!1),children:t?"Ні":"Скасувати"})]}):(0,r.jsx)("button",{className:"rounded-full border border-line bg-panel px-2 py-0.5 text-[11px] font-semibold text-dim hover:border-err/40 hover:text-err focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40","aria-label":`Зупинити процес PID ${e.pid}`,onClick:()=>l(!0),children:"Вбити"}):null,o?(0,r.jsx)("span",{className:"max-w-[220px] truncate text-[11px] font-semibold text-dim",children:o}):null]})}function eZ({file:e,files:t,onSelect:n}){if("codex-jobs"===e.root){let l=t.find(t=>"codex-sessions"===t.root&&t.parent===e.path);return(0,r.jsxs)("div",{className:"mb-4 mt-1 rounded-[14px] border border-line bg-panel px-4 py-3 shadow-card",children:[(0,r.jsx)("div",{className:"mb-2 flex flex-wrap items-center gap-2",children:(0,r.jsx)(eV,{file:e})}),l?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{className:"mb-2 whitespace-pre-line text-[13.5px] font-semibold",children:"Це короткий джоб-лог (лише службові події). Реальна робота Codex — у повній сесії:"}),(0,r.jsxs)("button",{className:"inline-flex items-center gap-1.5 rounded-[10px] border border-line bg-bg px-3 py-1.5 text-[13px] font-semibold text-codex hover:bg-codex-soft",onClick:()=>n(l),children:[(0,r.jsx)(ew.A,{className:"h-3.5 w-3.5","aria-hidden":!0})," Відкрити сесію Codex (",(l.size/1024).toFixed(0)," kB","live"===l.activity?", працює":"stalled"===l.activity?", перервано":"recent"===l.activity?", закінчив":"",")"]})]}):(0,r.jsx)("div",{className:"text-[13.5px] text-dim",children:"Це короткий джоб-лог. Повна rollout-сесія Codex ще не з'явилась у списку"})]})}return"claude-tasks"!==e.root?null:(0,r.jsxs)("div",{className:"mb-4 mt-1 rounded-[14px] border border-line bg-panel px-4 py-3 shadow-card",children:[(0,r.jsx)("div",{className:"mb-2 flex flex-wrap items-center gap-2",children:(0,r.jsx)(eV,{file:e})}),e.cmd?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{className:"mb-1 text-[13.5px] font-semibold",children:e.cmdDesc||"Фонова команда"}),(0,r.jsxs)("code",{className:"block whitespace-pre-wrap break-words rounded-lg border border-line bg-[#fafafc] px-2.5 py-2 font-mono text-[12.5px]",children:["$ ",e.cmd]})]}):(0,r.jsx)("div",{className:"text-[13.5px] text-dim",children:"Команду, що запустила цю фонову задачу, не знайдено у транскриптах сесії"})]})}let e0=[{key:"claude",label:"Claude"},{key:"codex",label:"Codex"}];function e1({file:e,paneRef:t}){let n=(0,i.useRef)(null),a=(0,i.useRef)({target:88,current:88,raf:0}),o=(0,i.useRef)(!1),c=(0,i.useRef)(null),d=(0,i.useRef)(null),[u,x]=(0,i.useState)(!1),[p,f]=(0,i.useState)({top:-18,maxH:480}),[m,h]=(0,i.useState)(!1),[b,g]=(0,i.useState)("codex"===e.engine?"codex":"claude"),[v,w]=(0,i.useState)(""),[j,y]=(0,i.useState)([]),[N,k]=(0,i.useState)(()=>`Прочитай розмову агента у файлі ${e.path} і продовж роботу звідти: `),[S,C]=(0,i.useState)(!1),[$,A]=(0,i.useState)(null),[E,M]=(0,i.useState)(!1),P=(0,i.useId)(),_=function(e,t){let[n,l]=(0,i.useState)(!1),[s,a]=(0,i.useState)(null),[o,c]=(0,i.useState)(null),d=(0,i.useRef)(null),u=(0,i.useRef)(!1),x=(0,i.useRef)(!1),p=(0,i.useRef)(null),f="link-arrow-"+(0,i.useId)().replace(/[^a-zA-Z0-9-]/g,"");return(0,i.useEffect)(()=>()=>{d.current?.detach(),d.current=null,document.body.style.cursor="",eH()},[]),{onPillPointerDown:n=>{if("mouse"===n.pointerType&&0!==n.button||d.current)return;let r=n.currentTarget.getBoundingClientRect(),i=n=>{let r=d.current;if(!r)return;if(r.lastX=n.clientX,r.lastY=n.clientY,!r.active){if(7>Math.hypot(n.clientX-r.startX,n.clientY-r.startY))return;r.active=!0,u.current=!0,x.current=!0,document.body.style.cursor="crosshair",eH(),c(null),a({x:r.anchorX,y:r.anchorY}),l(!0),t?.()}p.current?.setAttribute("d",eY(r.anchorX,r.anchorY,n.clientX,n.clientY));let i=function(e,t,n){let r=document.elementFromPoint(e,t)?.closest("[data-link-path]"),l=r?.getAttribute("data-link-path");if(!r||!l||l===n)return null;let i=eJ.get(l);return i&&i.el===r?i:null}(n.clientX,n.clientY,e.path);i?.el!==r.hover?.el&&(r.hover?.el.removeAttribute("data-link-hover"),i?.el.setAttribute("data-link-hover","1"),r.hover=i)},s=e=>{let t=d.current;d.current=null,t?.detach(),u.current=!1,document.body.style.cursor="",t?.active&&(l(!1),t.hover?c({file:t.hover.file,from:{x:t.anchorX,y:t.anchorY},to:{x:e.clientX,y:e.clientY}}):eH())};d.current={startX:n.clientX,startY:n.clientY,anchorX:r.right,anchorY:r.top+r.height/2,lastX:n.clientX,lastY:n.clientY,active:!1,hover:null,detach:()=>{window.removeEventListener("pointermove",i),window.removeEventListener("pointerup",s),window.removeEventListener("pointercancel",s)}},window.addEventListener("pointermove",i),window.addEventListener("pointerup",s),window.addEventListener("pointercancel",s)},consumeClick:()=>{let e=x.current;return x.current=!1,e},draggingRef:u,overlay:n||o?(0,eU.createPortal)((0,r.jsxs)("div",{className:"pointer-events-none fixed inset-0 z-[95]",children:[(0,r.jsxs)("svg",{className:"block h-full w-full",children:[(0,r.jsx)("defs",{children:(0,r.jsx)("marker",{id:f,markerWidth:"9",markerHeight:"9",refX:"7",refY:"4.5",orient:"auto",children:(0,r.jsx)("path",{d:"M0,0 L8,4.5 L0,9 Z",fill:eq})})}),(0,r.jsx)("path",{ref:e=>{p.current=e;let t=d.current;e&&t?.active&&e.setAttribute("d",eY(t.anchorX,t.anchorY,t.lastX,t.lastY))},d:o?eY(o.from.x,o.from.y,o.to.x,o.to.y):void 0,fill:"none",stroke:eq,strokeWidth:2.5,strokeLinecap:"round",markerEnd:`url(#${f})`}),(0,r.jsx)("circle",{cx:o?o.from.x:s?.x??0,cy:o?o.from.y:s?.y??0,r:4,fill:eq})]}),o?(0,r.jsx)(eB,{source:e,drop:o,onClose:()=>{eH(),c(null)}},o.file.path):null]}),document.body):null}}(e,()=>{c.current&&window.clearTimeout(c.current),c.current=null,o.current=!1,x(!1)}),{draggingRef:z}=_;(0,i.useEffect)(()=>{let e=window.matchMedia("(hover: hover) and (pointer: fine)");h(e.matches);let t=e=>h(e.matches);return e.addEventListener("change",t),()=>e.removeEventListener("change",t)},[]),(0,i.useEffect)(()=>{let e=t.current,r=n.current;if(!e||!r||!m)return;let l=a.current,i=()=>{r.style.transform=`translate3d(0, ${l.current}px, 0)`},s=()=>{let e=l.target-l.current;if(.4>Math.abs(e)){l.current=l.target,i(),l.raf=0;return}l.current+=.18*e,i(),l.raf=requestAnimationFrame(s)},c=t=>{if(o.current||z.current)return;let n=e.getBoundingClientRect();l.target=Math.min(Math.max(56,(r.previousElementSibling?.getBoundingClientRect().top??n.bottom)-n.top-24),Math.max(56,t.clientY-n.top)),l.raf||(l.raf=requestAnimationFrame(s))};return i(),e.addEventListener("pointermove",c,{passive:!0}),()=>{e.removeEventListener("pointermove",c),l.raf&&cancelAnimationFrame(l.raf),l.raf=0,l.target=88,l.current=88,r.style.transform="translate3d(0, 88px, 0)"}},[t,m,z]),(0,i.useEffect)(()=>()=>{c.current&&window.clearTimeout(c.current),d.current&&window.clearTimeout(d.current)},[]);let L=e=>{o.current=e,x(e)},D=()=>{if(o.current)return;let e=t.current;if(e){let t=e.getBoundingClientRect().height,n=a.current.current;if(n>.55*t){let e=Math.min(n+18,t-8);f({bottom:n-e,maxH:e-8})}else{let e=Math.max(8,n-18);f({top:e-n,maxH:t-e-8})}}L(!0)};(0,i.useEffect)(()=>{if(!u)return;let e=e=>{"Escape"===e.key&&L(!1)},t=e=>{n.current&&!n.current.contains(e.target)&&L(!1)};return window.addEventListener("keydown",e),window.addEventListener("pointerdown",t),()=>{window.removeEventListener("keydown",e),window.removeEventListener("pointerdown",t)}},[u]),(0,i.useEffect)(()=>{if(!u)return;let t=!1;return fetch("/api/spawn?project="+encodeURIComponent(e.project)+"&src="+encodeURIComponent(e.path)).then(e=>e.json()).then(e=>{if(t)return;Array.isArray(e.dirs)&&y(e.dirs);let n="string"==typeof e.cwd?e.cwd:"";w(t=>t||n||e.dirs?.[0]||"")}).catch(()=>{}),()=>{t=!0}},[u,e.project,e.path]);let O=async()=>{if(!S&&v.trim()){C(!0),A(null);try{let t=await fetch("/api/spawn",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({engine:b,cwd:v.trim(),prompt:N,src:e.path})}),n=await t.json();if(!t.ok||!n.ok)return void A({kind:"err",text:n.error??"не вдалося запустити"});A({kind:"ok",text:`запущено в tmux ${n.target??""} — з'явиться гілкою поруч із цією колонкою`})}catch{A({kind:"err",text:"сервер недоступний"})}finally{C(!1)}}},U=F(e);return(0,r.jsxs)("div",{ref:n,className:"pointer-events-none absolute left-1.5 top-0 z-40 h-0 w-0",style:{transform:"translate3d(0, 88px, 0)",willChange:"transform"},children:[(0,r.jsx)("button",{type:"button","aria-expanded":u,"aria-label":"Перекинути розмову іншому агенту або потягнути стрілку на його панель",title:"клік — перекинути новому агенту \xb7 потягни стрілку — звʼязати з наявним",onPointerDown:_.onPillPointerDown,onPointerEnter:()=>{m&&!o.current&&(c.current&&window.clearTimeout(c.current),c.current=window.setTimeout(D,130))},onPointerLeave:()=>{c.current&&window.clearTimeout(c.current),c.current=null},onClick:()=>{_.consumeClick()||(c.current&&window.clearTimeout(c.current),o.current?L(!1):D())},className:`pointer-events-auto absolute left-0 top-0 flex h-9 w-6 -translate-y-1/2 touch-none items-center justify-center rounded-full border bg-panel shadow-card transition-[opacity,border-color,color] duration-150 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40 ${u?"border-accent/50 text-accent opacity-100":"border-line text-dim opacity-60 hover:border-accent/45 hover:text-accent hover:opacity-100"}`,children:(0,r.jsx)(eQ.A,{className:"h-3.5 w-3.5","aria-hidden":!0})}),u?(0,r.jsxs)("div",{className:"pointer-events-auto absolute left-8 z-50 flex w-[340px] cursor-default flex-col gap-2.5 overflow-y-auto rounded-[12px] border border-line bg-panel p-3 shadow-[0_8px_28px_rgba(20,20,30,0.14)] [&>*]:shrink-0",style:{top:p.top,bottom:p.bottom,maxHeight:p.maxH},children:[(0,r.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,r.jsx)(eQ.A,{className:"h-3.5 w-3.5 shrink-0 text-accent","aria-hidden":!0}),(0,r.jsx)("span",{className:"min-w-0 flex-1 truncate text-[12px] font-bold",children:"перекинути розмову іншому агенту"}),(0,r.jsx)("button",{type:"button","aria-label":"Закрити картку передачі",onClick:()=>L(!1),className:"inline-flex shrink-0 items-center rounded-[8px] border border-line bg-bg px-1.5 py-0.5 text-dim hover:text-ink focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40",children:(0,r.jsx)(l.A,{className:"h-3 w-3","aria-hidden":!0})})]}),(0,r.jsx)("div",{className:"truncate text-[10.5px] font-semibold text-dim",title:s(e.title),children:s(e.title,70)}),(0,r.jsxs)("div",{className:"flex flex-col gap-1.5 rounded-[8px] border border-line bg-bg px-2 py-2",children:[(0,r.jsxs)("div",{className:"flex min-w-0 items-center gap-1.5",children:[(0,r.jsx)("span",{className:"w-[64px] shrink-0 text-[10px] font-semibold text-dim",children:"агент"}),(0,r.jsx)("span",{className:"shrink-0 rounded-full px-1.5 py-0.5 text-[9.5px] font-bold",style:U.style,children:U.label}),e.model?(0,r.jsx)("span",{className:"min-w-0 truncate rounded-full px-1.5 py-0.5 font-mono text-[9px] font-semibold",style:{backgroundColor:I(e).soft,color:I(e).color},children:e.model}):null,(0,r.jsx)(eV,{file:e})]}),(0,r.jsxs)("div",{className:"flex min-w-0 items-center gap-1.5",children:[(0,r.jsx)("span",{className:"w-[64px] shrink-0 text-[10px] font-semibold text-dim",children:"транскрипт"}),(0,r.jsx)("span",{className:"min-w-0 flex-1 truncate font-mono text-[10px] text-ink",title:e.path,children:e.path}),(0,r.jsx)("button",{type:"button","aria-label":"Скопіювати шлях транскрипта",onClick:()=>{navigator.clipboard?.writeText(e.path).then(()=>{M(!0),d.current&&window.clearTimeout(d.current),d.current=window.setTimeout(()=>M(!1),1500)}).catch(()=>{})},className:`inline-flex shrink-0 items-center rounded-[8px] border border-line bg-panel px-1.5 py-0.5 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40 ${E?"text-ok":"text-dim hover:text-accent"}`,children:E?(0,r.jsx)(eh.A,{className:"h-3 w-3","aria-hidden":!0}):(0,r.jsx)(eK.A,{className:"h-3 w-3","aria-hidden":!0})})]}),e.kind?(0,r.jsxs)("div",{className:"flex min-w-0 items-center gap-1.5",children:[(0,r.jsx)("span",{className:"w-[64px] shrink-0 text-[10px] font-semibold text-dim",children:"тип"}),(0,r.jsx)("span",{className:"min-w-0 truncate text-[10.5px] font-semibold text-ink",children:e.kind})]}):null]}),(0,r.jsx)("div",{className:"flex items-center gap-1.5",role:"radiogroup","aria-label":"Кому передати розмову",children:e0.map(({key:e,label:t})=>{let n;return(0,r.jsx)("button",{type:"button",role:"radio","aria-checked":b===e,onClick:()=>g(e),style:b===e?{backgroundColor:(n=R[e]??T).soft,color:n.color,borderColor:n.color}:void 0,className:`flex-1 rounded-[8px] border px-2 py-1.5 text-[12px] font-bold focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40 ${b===e?"":"border-line bg-bg text-dim hover:text-ink"}`,children:t},e)})}),(0,r.jsxs)("label",{className:"flex flex-col gap-1 text-[10.5px] font-semibold text-dim",children:["директорія (успадкована)",(0,r.jsx)("input",{value:v,onChange:e=>w(e.target.value),list:P,placeholder:"/home/…/Projects/…","aria-label":"Робоча директорія нового агента",className:"rounded-[8px] border border-line bg-bg px-2 py-1.5 font-mono text-[11.5px] font-normal text-ink focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40"}),(0,r.jsx)("datalist",{id:P,children:j.map(e=>(0,r.jsx)("option",{value:e},e))})]}),(0,r.jsxs)("label",{className:"flex flex-col gap-1 text-[10.5px] font-semibold text-dim",children:["промпт для нового агента",(0,r.jsx)("textarea",{value:N,onChange:e=>k(e.target.value),rows:4,placeholder:"що зробити далі…","aria-label":"Промпт для нового агента",className:"resize-y rounded-[8px] border border-line bg-bg px-2 py-1.5 text-[12px] font-normal text-ink focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40"})]}),(0,r.jsx)("div",{className:"flex items-center",children:(0,r.jsx)("button",{type:"button",disabled:S||!v.trim(),onClick:()=>void O(),className:"ml-auto rounded-[8px] border border-accent bg-accent px-3 py-1.5 text-[12px] font-bold text-white hover:opacity-90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/50 disabled:opacity-40",children:S?"перекидаю…":"▶ Перекинути"})}),S?(0,r.jsx)("span",{className:"text-[10.5px] text-dim",children:"чекаю, поки CLI підніметься (до хвилини)…"}):null,$?(0,r.jsx)("span",{className:`text-[11px] font-semibold ${"ok"===$.kind?"text-ok":"text-err"}`,children:$.text}):null]}):null,_.overlay]})}var e5=n(4760);let e2=e=>new TextEncoder().encode(e).length,e3=/^\s*(?:VERDICT:\s*)?(REQUEST_CHANGES|APPROVE|COMMENT)\b/m,e4=/^\s*(\d+)[.)]\s+(.*)$/,e8=/(?:\[(P[0-3])\]|\b(Critical|High|Medium|Low|Info|P[0-3])\b)/i,e6=/((?:\.{1,2}\/|\/|~\/)?[\w@.+-][\w@.+\-/]*\.(?:tsx?|jsx?|mjs|cjs|mts|cts|py|go|rs|md|json|ya?ml|toml|css|scss|html|sql|sh|env|ftl|txt))(?::(\d+))?/i,e9=/\[([^\]]+)\]\(([^)\s]+)\)/,e7=/([\w.-]*(?:api[_-]?key|access[_-]?token|refresh[_-]?token|authorization|bearer|secret|password|passwd|pwd|token))\b(\s*[:=]\s*)(["']?)[^\s"',}]+/gi;function te(e){return e.replace(e7,(e,t,n,r)=>`${t}${n}${r}[redacted]`)}function tt(e){let t=te(e);return{raw:t.slice(0,24e3),truncated:t.length>24e3}}function tn(e){let t=e.match(/^(.*?):(\d+(?:-\d+)?)$/);return t?{target:t[1]??e,line:t[2]}:{target:e}}function tr(e,t){let n=e.match(e3)?.[1];if(!n)return null;let r=[],l=[],i=null,s=()=>{let e,t,n,l=i?.trim();l&&r.push((e=function(e){let t=e.toUpperCase();if("P0"===t||"P1"===t||"P2"===t||"P3"===t)return t;let n=e.toLowerCase();return"critical"===n?"Critical":"high"===n?"High":"medium"===n?"Medium":"low"===n?"Low":"Info"}(l.match(e8)?.[1]??l.match(e8)?.[2]??"Info"),t=function(e){let t=e.match(e9);if(t){let e=tn((t[2]??"").replace(/^file:\/\//,"")),n=e.line?Number(e.line.split("-",1)[0]):void 0;return{file:e.target||t[1],line:Number.isFinite(n)?n:void 0}}let n=e.match(e6);if(!n)return{};let r=n[2]?Number(n[2]):void 0;return{file:n[1],line:Number.isFinite(r)?r:void 0}}(l),n=function(e){let t=e,n=t.match(e8);if(n&&void 0!==n.index){let e=t.slice(n.index+n[0].length).replace(/^[\s.:–—-]+/,"");e&&(t=e)}return t.replace(e9,"$1").replace(/`([^`]*)`/g,"$1").replace(/\s+/g," ").trim().slice(0,200)}(l)||l.slice(0,200)||"Finding",{severity:e,file:t.file,line:t.line,title:n,body:tt(l).raw})),i=null};for(let t of e.split("\n")){let e=t.trimEnd(),n=e.match(e4);if(n){s(),i=n[2]??"";continue}let a=e.trim();if(null!==i){a?i=`${i}
4
- ${a}`:s();continue}!(!a||e3.test(e)||/^(findings?|summary|open questions?|tests?|residual risk)\s*:?\s*$/i.test(a))&&0===r.length&&l.length<3&&a.length<=240&&l.push(a)}s();let a=r.filter(e=>e8.test(e.body)).length;return n||/^findings?\s*:?$/im.test(e)||a>=2||a>=1&&/\b(review|request_changes|approve|comment)\b/i.test(e)?{kind:"review",ts:t,verdict:n,findings:r,summary:l,raw:tt(e).raw}:null}var tl=n(6565),ti=n(2125);function ts({src:e,alt:t,caption:n,onClose:s}){let[a,o]=(0,i.useState)(1),[c,d]=(0,i.useState)(0),[u,x]=(0,i.useState)(0),[p,f]=(0,i.useState)(!1),m=(0,i.useRef)(null);(0,i.useEffect)(()=>{let e=e=>{"Escape"===e.key&&s()};window.addEventListener("keydown",e);let t=document.body.style.overflow;return document.body.style.overflow="hidden",()=>{window.removeEventListener("keydown",e),document.body.style.overflow=t}},[s]);let h=(e,t=0,n=0)=>{let r=Math.min(8,Math.max(.25,a*e)),l=r/a;o(r),d(t-(t-c)*l),x(n-(n-u)*l)},b=()=>{o(1),d(0),x(0)};return(0,eU.createPortal)((0,r.jsxs)("div",{className:"fixed inset-0 z-50 flex flex-col bg-black/85 backdrop-blur-sm",role:"dialog","aria-modal":"true","aria-label":t,onClick:s,children:[(0,r.jsxs)("div",{className:"flex items-center gap-2 px-4 py-2.5",onClick:e=>e.stopPropagation(),children:[(0,r.jsx)("span",{className:"min-w-0 truncate text-[12.5px] font-semibold text-white/85",children:n??t}),(0,r.jsxs)("span",{className:"ml-auto flex items-center gap-1.5",children:[(0,r.jsx)("button",{className:"inline-flex items-center rounded-lg border border-white/25 bg-white/10 px-2.5 py-1 text-white hover:bg-white/20 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-white/60","aria-label":"Зменшити",onClick:()=>h(1/1.4),children:(0,r.jsx)(tl.A,{className:"h-4 w-4","aria-hidden":!0})}),(0,r.jsxs)("button",{className:"rounded-lg border border-white/25 bg-white/10 px-2 py-1 text-[11.5px] font-semibold text-white hover:bg-white/20 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-white/60","aria-label":"Скинути масштаб",onClick:b,children:[Math.round(100*a),"%"]}),(0,r.jsx)("button",{className:"inline-flex items-center rounded-lg border border-white/25 bg-white/10 px-2.5 py-1 text-white hover:bg-white/20 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-white/60","aria-label":"Збільшити",onClick:()=>h(1.4),children:(0,r.jsx)(ti.A,{className:"h-4 w-4","aria-hidden":!0})}),(0,r.jsx)("button",{className:"ml-1 inline-flex items-center rounded-lg border border-white/25 bg-white/10 px-2.5 py-1 text-white hover:bg-white/20 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-white/60","aria-label":"Закрити",onClick:s,children:(0,r.jsx)(l.A,{className:"h-4 w-4","aria-hidden":!0})})]})]}),(0,r.jsx)("div",{className:"min-h-0 flex-1 touch-none overflow-hidden",onClick:e=>e.stopPropagation(),onWheel:e=>{let t=e.currentTarget.getBoundingClientRect(),n=e.clientX-t.left-t.width/2,r=e.clientY-t.top-t.height/2;h(e.deltaY<0?1.18:1/1.18,n,r)},onPointerDown:e=>{e.currentTarget.setPointerCapture(e.pointerId),m.current={x:e.clientX,y:e.clientY,tx:c,ty:u},f(!0)},onPointerMove:e=>{m.current&&(d(m.current.tx+(e.clientX-m.current.x)),x(m.current.ty+(e.clientY-m.current.y)))},onPointerUp:()=>{m.current=null,f(!1)},onPointerCancel:()=>{m.current=null,f(!1)},onDoubleClick:()=>1===a?h(2):b(),children:(0,r.jsx)("div",{className:"flex h-full items-center justify-center",children:(0,r.jsx)("img",{src:e,alt:t,draggable:!1,className:`max-h-full max-w-full select-none ${p?"":"transition-transform duration-75"} ${a>1?"cursor-grab active:cursor-grabbing":"cursor-zoom-in"}`,style:{transform:`translate(${c}px, ${u}px) scale(${a})`}})})})]}),document.body)}function ta({name:e,path:t}){let[n,l]=(0,i.useState)("thumb"),[s,a]=(0,i.useState)(null),[o,c]=(0,i.useState)(!1),[d,u]=(0,i.useState)(!1),[x,p]=(0,i.useState)("");(0,i.useEffect)(()=>{if(!o)return;let e=window.setTimeout(()=>c(!1),5e3);return()=>window.clearTimeout(e)},[o]);let f=`/api/inbox?name=${encodeURIComponent(e)}`,m=async()=>{u(!0),p("");try{let e=await fetch(f,{method:"DELETE"}),t=await e.json();if(!e.ok||!t.ok)return void p(t.error??"не вдалося видалити");a("deleted")}catch{p("сервер недоступний")}finally{u(!1),c(!1)}};return s?(0,r.jsx)("div",{className:"my-2 flex justify-end",children:(0,r.jsxs)("span",{className:"inline-flex max-w-[75%] items-center gap-1.5 rounded-full border border-line bg-chip px-2.5 py-1 text-[11.5px] font-semibold text-dim",title:t,children:[(0,r.jsx)(eO,{name:"image",className:"h-3.5 w-3.5"}),(0,r.jsx)("span",{className:"truncate",children:e}),(0,r.jsxs)("span",{className:"shrink-0",children:["\xb7 ","deleted"===s?"видалено з диска":"файла вже немає на диску"]})]})}):"chip"===n?(0,r.jsx)("div",{className:"my-2 flex justify-end",children:(0,r.jsxs)("button",{type:"button",onClick:()=>l("thumb"),className:"inline-flex max-w-[75%] items-center gap-2 rounded-[14px] border border-line bg-panel px-3.5 py-2 text-[13px] shadow-card",title:t,children:[(0,r.jsx)("span",{className:"flex h-6.5 w-6.5 shrink-0 items-center justify-center rounded-lg bg-chip",children:(0,r.jsx)(eO,{name:"image",className:"h-4 w-4"})}),(0,r.jsx)("span",{className:"truncate font-mono text-[12px]",children:e}),(0,r.jsx)("span",{className:"shrink-0 text-[12px] font-semibold text-accent",children:"показати"})]})}):(0,r.jsxs)("div",{className:"my-2 flex justify-end",children:[(0,r.jsxs)("div",{className:"max-w-[75%]",children:[(0,r.jsx)("img",{src:f,alt:`вкладена картинка ${e}`,onClick:()=>l("full"),onError:()=>a("missing"),className:"ml-auto block max-h-[240px] cursor-zoom-in rounded-[14px] border border-line"}),(0,r.jsxs)("div",{className:"mt-1 flex flex-wrap items-center justify-end gap-1.5 text-[11px]",children:[(0,r.jsx)("span",{className:"min-w-0 truncate font-mono text-dim",title:t,children:e}),(0,r.jsx)("button",{type:"button",onClick:()=>l("chip"),className:"shrink-0 text-dim hover:text-ink",children:"згорнути"}),o?(0,r.jsxs)("span",{className:"inline-flex shrink-0 items-center gap-1 rounded-[10px] border border-err/30 bg-[#fff5f5] px-1.5 py-0.5",children:[(0,r.jsx)("span",{className:"px-1 font-semibold text-err",children:"Видалити файл з диска?"}),(0,r.jsx)("button",{type:"button",className:"rounded-lg bg-err px-2 py-0.5 font-bold text-white disabled:opacity-60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-err/50",disabled:d,onClick:m,children:d?"видаляю…":"Так, видалити"}),(0,r.jsx)("button",{type:"button",className:"rounded-lg border border-line bg-panel px-2 py-0.5 font-semibold text-dim focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40",onClick:()=>c(!1),children:"Скасувати"})]}):(0,r.jsxs)("button",{type:"button",onClick:()=>c(!0),"aria-label":`Видалити ${e} з диска`,className:"inline-flex shrink-0 items-center gap-1 rounded-full border border-line bg-panel px-2 py-0.5 font-semibold text-dim hover:border-err/40 hover:text-err focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40",children:[(0,r.jsx)(eE.A,{className:"h-3 w-3","aria-hidden":!0})," видалити з диска"]}),x?(0,r.jsx)("span",{className:"shrink-0 font-semibold text-err",children:x}):null]})]}),"full"===n?(0,r.jsx)(ts,{src:f,alt:`вкладена картинка ${e}`,caption:t,onClose:()=>l("thumb")}):null]})}let to=/<oai-mem-citation>\s*<citation_entries>([\s\S]*?)<\/citation_entries>\s*<rollout_ids>([\s\S]*?)<\/rollout_ids>\s*<\/oai-mem-citation>/g,tc=/(?:\/\.codex\/sessions\/|\/\.claude\/projects\/|\/\.claude\/plugins\/data\/codex-openai-codex\/state\/|^\/tmp\/claude-\d+\/)/;function td(e){return"number"==typeof e&&Number.isFinite(e)?e:void 0}let tu=/<(teammate-message|agent-message)\b([^>]*)>([\s\S]*?)<\/\1>/g,tx=/\S*\/\.claude\/viewer-inbox\/([A-Za-z0-9._-]+\.(?:png|jpe?g|gif|webp))/gi;function tp(e){if(!e.includes("/.claude/viewer-inbox/"))return{cleaned:e,images:[]};let t=[],n=new Set,r=[];for(let l of e.split("\n"))l.replace(tx,(e,r)=>(n.has(e)||(n.add(e),t.push({name:r,path:e})),"")).trim()&&r.push(l);return{cleaned:r.join("\n").trim(),images:t}}let tf=/^\s*(?:<[a-zA-Z][\w:-]*|Caveat: The messages below|\[Request interrupted|This came from another Claude session)/;function tm(e){let t=e.match(/^\s*<([a-zA-Z][\w:-]*)/)?.[1];return t||(/^\s*Caveat:/.test(e)?"caveat":"системне")}function th(e,t){return e.match(RegExp(`${t}="([^"]*)"`))?.[1]??""}function tb(e){return"string"==typeof e?e:""}function tg(e){return e&&"object"==typeof e&&!Array.isArray(e)?e:{}}function tv(e){return Array.isArray(e)?e.filter(e=>e&&"object"==typeof e&&!Array.isArray(e)):[]}let tw=/(`[^`]+`|\*\*[^*]+\*\*|\[[^\]]+\]\([^)\s]+\)|https?:\/\/[^\s<>"')\]]+)/g;function tj({href:e,label:t}){return(0,r.jsx)("a",{href:e,target:"_blank",rel:"noreferrer",title:e,className:"break-all text-accent underline decoration-accent/40 underline-offset-2 hover:decoration-accent",children:t})}function ty(e){return e.split(tw).map((e,t)=>{if(!e)return null;if(e.startsWith("`")&&e.endsWith("`"))return(0,r.jsx)("span",{className:"rounded-md bg-chip px-1.5 py-0.5 font-mono",children:e.slice(1,-1)},t);if(e.startsWith("**")&&e.endsWith("**"))return(0,r.jsx)("b",{children:e.slice(2,-2)},t);let n=e.match(/^\[([^\]]+)\]\(([^)\s]+)\)$/);if(n){let e=n[2].replace(/\\([()])/g,"$1");return/^https?:\/\//.test(e)?(0,r.jsx)(tj,{href:e,label:n[1]},t):(0,r.jsx)("span",{className:"rounded-md bg-chip px-1.5 py-0.5 font-mono",children:n[1]},t)}if(/^https?:\/\//.test(e)){let n=e.replace(/[.,;:!?…»)]+$/,""),l=e.slice(n.length),i=n.length>72?n.slice(0,69)+"…":n;return(0,r.jsxs)("span",{children:[(0,r.jsx)(tj,{href:n,label:i}),l]},t)}return e})}let tN=/^\s*\|.*\|\s*$/,tk=/^:?-{1,}:?$/;function tS({rows:e}){let t=e.map(e=>e.trim().replace(/^\|/,"").replace(/\|$/,"").split("|").map(e=>e.trim())),n=t.length>1&&t[1].every(e=>tk.test(e)),l=n?t[0]:null,i=n?t.slice(2):t;return(0,r.jsx)("div",{className:"my-1.5 max-w-full overflow-x-auto",children:(0,r.jsxs)("table",{className:"border-collapse text-[12.5px]",children:[l?(0,r.jsx)("thead",{children:(0,r.jsx)("tr",{children:l.map((e,t)=>(0,r.jsx)("th",{className:"border border-line bg-chip px-2.5 py-1 text-left font-semibold",children:ty(e)},t))})}):null,(0,r.jsx)("tbody",{children:i.map((e,t)=>(0,r.jsx)("tr",{children:e.map((e,t)=>(0,r.jsx)("td",{className:"border border-line px-2.5 py-1 align-top",children:ty(e)},t))},t))})]})})}function tC(e){let t=e.split("\n"),n=[],l=0;for(;l<t.length;){if(/^\s*```/.test(t[l])){let e=l;for(l++;l<t.length&&!/^\s*```\s*$/.test(t[l]);)l++;let i=t.slice(e+1,l).join("\n");l<t.length&&l++,"\n"===n[n.length-1]&&n.pop(),n.push((0,r.jsx)("pre",{className:"my-1.5 max-w-full overflow-x-auto rounded-[10px] border border-line bg-bg px-3 py-2 font-mono text-[11.5px]",children:i},`c${e}`));continue}if(tN.test(t[l])){let e=l;for(;l<t.length&&tN.test(t[l]);)l++;"\n"===n[n.length-1]&&n.pop(),n.push((0,r.jsx)(tS,{rows:t.slice(e,l)},`t${e}`));continue}let e=t[l],s=e.match(/^#{1,6}\s+(.*)$/),a=e.match(/^>\s?(.*)$/);s?n.push((0,r.jsx)("span",{className:"text-[14px] font-bold",children:ty(s[1])},l)):a?n.push((0,r.jsx)("span",{className:"border-l-2 border-line pl-2 text-dim",children:ty(a[1])},l)):n.push((0,r.jsx)(i.Fragment,{children:ty(e)},l)),++l<t.length&&n.push("\n")}return n}function t$(e,t,n){let r=t.split("\n").map(e=>e.trim()).filter(Boolean).map(e=>{let t=e.match(/\|note=\[(.*)\]$/)?.[1],n=tn(e.replace(/\|note=\[.*\]$/,""));return{target:n.target,line:n.line,note:t,raw:e}}),l=n.split(/\s+/).map(e=>e.trim()).filter(e=>/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(e)),i=tt(e);return{kind:"mem-citation",entries:r,rolloutIds:l,raw:i.raw,truncated:i.truncated}}function tA(e,t,n){if(!e)return null;let r=t.match(/exited with code (\d+)/)?.[1],l=t.replace(/^Chunk ID:[^\n]*\n/,"").replace(/Wall time:[^\n]*\n/,"").replace(/Original token count:[^\n]*\n?/,"").trim(),i=!0===n||void 0!==r&&"0"!==r;return e.status=i?"err":"ok",e.label=i?r&&"0"!==r?"exit "+r:"помилка":"ok",e.open||=i,l&&(e.output=(e.output+"\n"+te(l)).trim().slice(-(i?6e4:12e3))),e}function tE({media:e,data:t,w:n,h:l,bytes:s}){let[a,o]=(0,i.useState)("thumb"),c=Math.round((s??3*t.length/4)/1024),d=n&&l?`${n}\xd7${l}`:"зображення";if("chip"===a)return(0,r.jsxs)("button",{type:"button",onClick:()=>o("thumb"),className:"my-2 ml-9 flex items-center gap-2 rounded-[14px] border border-line bg-panel px-3.5 py-2 text-[13px] shadow-card",children:[(0,r.jsx)("span",{className:"flex h-6.5 w-6.5 items-center justify-center rounded-lg bg-chip",children:(0,r.jsx)(eO,{name:"image",className:"h-4 w-4"})}),(0,r.jsx)("span",{className:"font-semibold",children:d}),(0,r.jsxs)("span",{className:"text-dim",children:["\xb7 ",c," КБ"]}),(0,r.jsx)("span",{className:"ml-1 text-[12px] font-semibold text-accent",children:"показати"})]});let u=`data:${e};base64,${t}`;return(0,r.jsxs)("div",{className:"my-2 ml-9",children:[(0,r.jsx)("img",{src:u,alt:`зображення ${d}`,onClick:()=>o("full"),className:"max-h-[240px] cursor-zoom-in rounded-[14px] border border-line"}),(0,r.jsx)("button",{type:"button",onClick:()=>o("chip"),className:"mt-1 block text-[12px] text-dim",children:"згорнути"}),"full"===a?(0,r.jsx)(ts,{src:u,alt:`зображення ${d}`,caption:`${d} \xb7 ${c} КБ`,onClose:()=>o("thumb")}):null]})}function tM({label:e,text:t}){let n=t.length>=2048?`${(t.length/1024).toFixed(1)} кБ`:`${t.length} симв.`;return(0,r.jsxs)("details",{className:"group my-1.5 ml-9",children:[(0,r.jsxs)("summary",{className:"flex cursor-pointer list-none items-center gap-1.5 text-[11px] font-semibold text-dim hover:text-ink [&::-webkit-details-marker]:hidden",children:[(0,r.jsx)("span",{className:"flex h-4.5 w-4.5 items-center justify-center rounded-md bg-chip",children:(0,r.jsx)(eO,{name:"cmd-group",className:"h-3 w-3"})}),(0,r.jsx)("span",{className:"rounded-full bg-chip px-1.5 py-0.5 font-mono text-[9.5px]",children:e}),(0,r.jsxs)("span",{children:["системне \xb7 ",n]}),(0,r.jsx)("span",{className:"text-accent group-open:hidden",children:"показати"}),(0,r.jsx)("span",{className:"hidden text-dim group-open:inline",children:"згорнути"})]}),(0,r.jsx)("pre",{className:"mt-1 max-h-[320px] overflow-auto whitespace-pre-wrap break-words rounded-[10px] border border-line bg-bg px-3 py-2 font-mono text-[11px] text-[#555]",children:t})]})}function tR({bytes:e,text:t}){let[n,l]=(0,i.useState)(!1),s=Math.round(e/1024);return n?(0,r.jsxs)("div",{className:"my-2 ml-9 overflow-hidden rounded-[14px] border border-line bg-panel shadow-card",children:[(0,r.jsx)("pre",{className:"max-h-[340px] overflow-auto whitespace-pre-wrap break-all bg-[#fafafc] px-3.5 py-2.5 font-mono text-[11.5px]",children:t}),(0,r.jsx)("button",{type:"button",onClick:()=>l(!1),className:"block w-full border-t border-line px-3.5 py-1.5 text-[12px] text-dim",children:"згорнути"})]}):(0,r.jsxs)("button",{type:"button",onClick:()=>l(!0),className:"my-2 ml-9 flex items-center gap-2 rounded-[14px] border border-line bg-panel px-3.5 py-2 text-[13px] shadow-card",children:[(0,r.jsx)("span",{className:"flex h-6.5 w-6.5 items-center justify-center rounded-lg bg-chip",children:(0,r.jsx)(eO,{name:"blob",className:"h-4 w-4"})}),(0,r.jsxs)("span",{className:"font-semibold",children:["даних ",s," КБ"]}),(0,r.jsx)("span",{className:"ml-1 text-[12px] font-semibold text-accent",children:"показати"})]})}function tT({verdict:e}){let t="REQUEST_CHANGES"===e?ef.A:"APPROVE"===e?ev.A:eN.A;return(0,r.jsxs)("span",{className:"inline-flex items-center gap-1",children:[(0,r.jsx)(t,{className:"h-3.5 w-3.5","aria-hidden":!0}),"REQUEST_CHANGES"===e?"REQUEST_CHANGES":"APPROVE"===e?"APPROVE":"COMMENT"]})}function tP({status:e,className:t}){let n=t??"h-3.5 w-3.5";return"ok"===e?(0,r.jsx)(eh.A,{className:n,"aria-hidden":!0}):"err"===e?(0,r.jsx)(l.A,{className:n,"aria-hidden":!0}):(0,r.jsx)(eL.A,{className:`${n} animate-spin`,"aria-hidden":!0})}function t_({file:e,line:t}){let n=t?`${e}:${t}`:e,l="inline-block min-w-0 max-w-full truncate rounded-md bg-chip px-1.5 py-0.5 align-bottom font-mono text-[11.5px]";return tc.test(e)?(0,r.jsx)("a",{href:`#f=${encodeURIComponent(e)}`,className:`${l} text-accent underline decoration-dotted`,title:n,children:n}):(0,r.jsx)("code",{className:l,title:n,children:n})}function tI({item:e}){let t=Object.entries(e.byTool).map(([e,t])=>`${e} \xd7${t}`).join(" \xb7 "),n=A(e.t0),i=A(e.t1),s=n&&i&&n!==i?`${n}–${i}`:n||i;return(0,r.jsxs)("details",{className:`my-2.5 ml-9 overflow-hidden rounded-[14px] border shadow-card ${e.hasErr?"border-err/35 bg-[#fff4f4]":"border-line bg-panel"}`,open:e.hasErr,children:[(0,r.jsxs)("summary",{className:"flex cursor-pointer list-none items-center gap-2.5 px-3.5 py-2",children:[(0,r.jsx)("span",{className:"flex h-6.5 w-6.5 shrink-0 items-center justify-center rounded-lg bg-chip",children:(0,r.jsx)(eO,{name:"cmd-group",className:"h-4 w-4"})}),(0,r.jsxs)("span",{className:"flex min-w-0 flex-1 items-center gap-1 truncate text-[12.5px]",children:[e.calls.length," ",E(e.calls.length,"команда","команди","команд"),t?" \xb7 "+t:""," \xb7",(0,r.jsxs)("span",{className:"inline-flex items-center gap-0.5 text-ok",children:[(0,r.jsx)(eh.A,{className:"h-3.5 w-3.5","aria-hidden":!0}),e.okCount]}),e.errCount?(0,r.jsxs)("span",{className:"inline-flex items-center gap-0.5 text-err",children:[(0,r.jsx)(l.A,{className:"h-3.5 w-3.5","aria-hidden":!0}),e.errCount]}):null]}),s?(0,r.jsx)("span",{className:"ml-auto shrink-0 text-[11px] text-dim",children:s}):null]}),(0,r.jsx)("div",{className:"space-y-1 border-t border-line bg-[#fafafc] px-2 py-1.5",children:e.calls.map((t,n)=>{let l="ok"===t.status?"text-ok":"err"===t.status?"text-err":"text-dim";return(0,r.jsxs)("details",{className:"overflow-hidden rounded-[10px] border border-line bg-panel",open:t.open,children:[(0,r.jsxs)("summary",{className:"flex h-6 cursor-pointer list-none items-center gap-2 px-2.5 text-[11.5px]",children:[(0,r.jsx)("span",{className:"flex h-4.5 w-4.5 shrink-0 items-center justify-center rounded-md bg-chip",children:(0,r.jsx)(eO,{name:t.icon,className:"h-3 w-3"})}),(0,r.jsx)("code",{className:"min-w-0 flex-1 overflow-hidden text-ellipsis whitespace-nowrap rounded-md bg-chip px-1.5 py-0.5 font-mono text-[11px]",children:t.display}),(0,r.jsxs)("span",{className:`ml-auto inline-flex shrink-0 items-center gap-1 text-[10.5px] font-semibold ${l}`,children:[(0,r.jsx)(tP,{status:t.status,className:"h-3 w-3"}),t.label]})]}),(0,r.jsx)("pre",{className:"max-h-[280px] overflow-auto whitespace-pre-wrap border-t border-line bg-[#fafafc] px-3 py-2 font-mono text-[11.5px]",children:"$ "+t.cmd+(t.output?"\n"+t.output:"")})]},e.ids[n])})})]})}function tz({item:e}){var t;let n=e.findings.length,l=e.findings.slice(0,12);return(0,r.jsxs)("div",{className:"my-3.5 ml-9 overflow-hidden rounded-[14px] border border-codex/20 bg-panel shadow-card",children:[(0,r.jsxs)("div",{className:"flex flex-wrap items-center gap-2 border-b border-line px-3.5 py-2.5",children:[(0,r.jsx)("span",{className:"flex h-6.5 w-6.5 shrink-0 items-center justify-center rounded-lg bg-codex-soft text-codex",children:(0,r.jsx)(ew.A,{className:"h-4 w-4","aria-hidden":!0})}),(0,r.jsx)("span",{className:"text-[13.5px] font-bold",children:"Codex review"}),e.verdict?(0,r.jsx)("span",{className:`rounded-full border px-2.5 py-0.5 text-[11.5px] font-extrabold ${"REQUEST_CHANGES"===(t=e.verdict)?"bg-[#fff0f0] text-err border-err/25":"APPROVE"===t?"bg-[#eefaf1] text-ok border-ok/25":"bg-chip text-[#555] border-line"}`,children:(0,r.jsx)(tT,{verdict:e.verdict})}):null,(0,r.jsx)("span",{className:"text-[11px] text-dim",children:n?`${n} finding${1===n?"":"s"}`:"без findings"}),A(e.ts)?(0,r.jsx)("span",{className:"ml-auto text-[11px] text-dim",children:A(e.ts)}):null]}),(0,r.jsxs)("div",{className:"px-3.5 py-2.5",children:[e.summary.length?(0,r.jsx)("div",{className:"mb-2 whitespace-pre-wrap break-words text-[13px] text-[#444]",children:tC(e.summary.join("\n"))}):null,l.length?(0,r.jsx)("div",{className:"space-y-2",children:l.map((e,t)=>{var n;return(0,r.jsxs)("div",{className:"rounded-[10px] border border-line bg-[#fbfbfd] px-3 py-2",children:[(0,r.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,r.jsx)("span",{className:`rounded-full border px-2 py-0.5 text-[10.5px] font-extrabold ${"Critical"===(n=e.severity)||"High"===n||"P0"===n||"P1"===n?"border-err/30 bg-[#fff4f4] text-err":"Medium"===n||"P2"===n?"border-[#d89b21]/35 bg-[#fff9ea] text-[#9a6500]":"Low"===n||"P3"===n?"border-line bg-chip text-[#555]":"border-line bg-panel text-dim"}`,children:e.severity}),e.file?(0,r.jsx)(t_,{file:e.file,line:e.line}):null]}),(0,r.jsx)("div",{className:"mt-1.5 whitespace-pre-wrap break-words text-[13px]",children:ty(e.title)}),e.body&&e.body!==e.title?(0,r.jsxs)("details",{className:"mt-1 text-[12px] text-dim",children:[(0,r.jsx)("summary",{className:"cursor-pointer list-none font-semibold text-accent",children:"details"}),(0,r.jsx)("div",{className:"mt-1 whitespace-pre-wrap break-words",children:tC(e.body)})]}):null]},t)})}):null,e.findings.length>l.length?(0,r.jsxs)("div",{className:"mt-2 text-[12px] text-dim",children:["ще ",e.findings.length-l.length," findings у raw"]}):null,(0,r.jsxs)("details",{className:"mt-2 rounded-[10px] border border-line bg-[#fafafc] text-[12px]",children:[(0,r.jsx)("summary",{className:"cursor-pointer list-none px-3 py-1.5 font-semibold text-dim",children:"raw review text"}),(0,r.jsx)("pre",{className:"max-h-[320px] overflow-auto whitespace-pre-wrap border-t border-line px-3 py-2 font-mono text-[11.5px] text-[#555]",children:e.raw})]})]})]})}function tL({item:e}){let t=e.entries.slice(0,8),n=e.rolloutIds.slice(0,6);return(0,r.jsxs)("details",{className:"group my-2 ml-9 overflow-hidden rounded-[14px] border border-line bg-panel text-[12px] shadow-card",children:[(0,r.jsxs)("summary",{className:"flex cursor-pointer list-none items-center gap-2 px-3.5 py-2",children:[(0,r.jsx)("span",{className:"flex h-6.5 w-6.5 shrink-0 items-center justify-center rounded-lg bg-chip",children:(0,r.jsx)(eO,{name:"citation",className:"h-4 w-4"})}),(0,r.jsxs)("span",{className:"text-[13px] font-semibold",children:["цитати пам'яті (",e.entries.length,")"]}),(0,r.jsx)("span",{className:"ml-auto text-[11px] font-semibold text-accent group-open:hidden",children:"показати"}),(0,r.jsx)("span",{className:"ml-auto hidden text-[11px] font-semibold text-accent group-open:inline",children:"згорнути"})]}),(0,r.jsxs)("div",{className:"border-t border-line px-3.5 py-2.5",children:[t.length?(0,r.jsx)("div",{className:"space-y-1.5",children:t.map((e,t)=>(0,r.jsxs)("div",{className:"min-w-0 rounded-[9px] bg-[#fbfbfd] px-2.5 py-1.5",children:[(0,r.jsx)(t_,{file:e.target,line:e.line?Number(e.line.split("-",1)[0]):void 0}),e.note?(0,r.jsx)("div",{className:"mt-1 whitespace-pre-wrap break-words text-[12px] text-[#555]",children:e.note}):null]},t))}):(0,r.jsx)("div",{className:"text-[12px] text-dim",children:"без citation entries"}),e.entries.length>t.length?(0,r.jsxs)("div",{className:"mt-1.5 text-[12px] text-dim",children:["ще ",e.entries.length-t.length," entries у raw"]}):null,n.length?(0,r.jsxs)("div",{className:"mt-2 flex flex-wrap items-center gap-1.5",children:[(0,r.jsx)("span",{className:"text-[11px] text-dim",children:"rollout:"}),n.map(e=>(0,r.jsx)("code",{className:"rounded-full bg-chip px-2 py-0.5 font-mono text-[10.5px] text-dim",title:e,children:e.slice(0,8)},e)),e.rolloutIds.length>n.length?(0,r.jsxs)("span",{className:"text-[11px] text-dim",children:["+",e.rolloutIds.length-n.length]}):null]}):null,(0,r.jsxs)("details",{className:"mt-2 rounded-[10px] border border-line bg-[#fafafc] text-[12px]",children:[(0,r.jsxs)("summary",{className:"cursor-pointer list-none px-3 py-1.5 font-semibold text-dim",children:["raw citation block",e.truncated?" \xb7 обрізано":""]}),(0,r.jsx)("pre",{className:"max-h-[260px] overflow-auto whitespace-pre-wrap border-t border-line px-3 py-2 font-mono text-[11.5px] text-[#555]",children:e.raw})]})]})]})}let tD={shutdown_request:{icon:"shutdown",label:"запит на завершення",tone:"amber"},shutdown_response:{icon:"shutdown",label:"відповідь на завершення",tone:"amber"},plan_approval_request:{icon:"plan",label:"запит на затвердження плану",tone:"accent"},plan_approval_response:{icon:"plan",label:"вердикт по плану",tone:"accent"}};function tO(e){return"string"==typeof e&&e.length?e:void 0}function tF({approve:e}){return(0,r.jsx)("span",{className:`rounded-full border px-2 py-0.5 text-[10.5px] font-extrabold ${e?"border-ok/25 bg-[#eefaf1] text-ok":"border-err/25 bg-[#fff0f0] text-err"}`,children:e?"схвалено":"відхилено"})}function tU({payload:e}){let t=tO(e.from),n=tO(e.requestId),l=A(e.timestamp);return t||n||l?(0,r.jsxs)("div",{className:"mt-1.5 flex flex-wrap items-center gap-x-2.5 gap-y-1 text-[11px] text-dim",children:[t?(0,r.jsxs)("span",{children:["від ",t]}):null,n?(0,r.jsx)("span",{className:"truncate font-mono",title:n,children:n.length>40?n.slice(0,40)+"…":n}):null,l?(0,r.jsx)("span",{children:l}):null]}):null}function tq({payload:e}){let t=tO(e.type),n=t?tD[t]:void 0;if(!n)return(0,r.jsxs)("div",{className:"text-[13px]",children:[(0,r.jsx)("div",{className:"text-dim",children:"структуроване повідомлення"}),(0,r.jsxs)("details",{className:"mt-1 text-[12px]",children:[(0,r.jsx)("summary",{className:"cursor-pointer list-none font-semibold text-accent",children:"показати JSON"}),(0,r.jsx)("pre",{className:"mt-1 max-h-[280px] overflow-auto whitespace-pre-wrap rounded-md bg-chip px-2.5 py-2 font-mono text-[11.5px]",children:JSON.stringify(e,null,2)})]})]});let l="boolean"==typeof e.approve?e.approve:void 0,i=tO(e.reason)??tO(e.feedback);return(0,r.jsxs)("div",{className:"text-[13px]",children:[(0,r.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,r.jsxs)("span",{className:`inline-flex items-center gap-1 rounded-full border px-2.5 py-0.5 text-[11.5px] font-bold ${"amber"===n.tone?"border-[#d89b21]/35 bg-[#fff9ea] text-[#9a6500]":"border-accent/25 bg-accent/10 text-accent"}`,children:[(0,r.jsx)(eO,{name:n.icon,className:"h-3.5 w-3.5"}),n.label]}),void 0!==l?(0,r.jsx)(tF,{approve:l}):null]}),i?(0,r.jsx)("div",{className:"mt-1.5 whitespace-pre-wrap break-words",children:tC(i)}):null,(0,r.jsx)(tU,{payload:e})]})}let tJ=(0,i.memo)(function({item:e}){if("image"===e.kind)return(0,r.jsx)(tE,{media:e.media,data:e.data,w:e.w,h:e.h,bytes:e.bytes});if("inbox-image"===e.kind)return(0,r.jsx)(ta,{name:e.name,path:e.path});if("blob"===e.kind)return(0,r.jsx)(tR,{bytes:e.bytes,text:e.text});if("sysmsg"===e.kind)return(0,r.jsx)(tM,{label:e.label,text:e.text});if("review"===e.kind)return(0,r.jsx)(tz,{item:e});if("mem-citation"===e.kind)return(0,r.jsx)(tL,{item:e});if("prose"===e.kind){let t="codex"===e.engine?"bg-codex":"bg-claude",n="codex"===e.engine?ew.A:eC.A;return(0,r.jsxs)("div",{className:"my-3.5 flex gap-2.5",children:[(0,r.jsx)("div",{className:`mt-1 flex h-6.5 w-6.5 shrink-0 items-center justify-center rounded-full text-white ${t}`,children:(0,r.jsx)(n,{className:"h-3.5 w-3.5","aria-hidden":!0})}),(0,r.jsxs)("div",{className:"min-w-0 flex-1 whitespace-pre-wrap break-words",children:[A(e.ts)?(0,r.jsx)("div",{className:"mb-0.5 text-[11px] text-dim",children:A(e.ts)}):null,tC(e.text)]})]})}if("user"===e.kind){let t=e.text.length>500;return(0,r.jsx)("div",{className:"my-3.5 flex justify-end",children:(0,r.jsx)("div",{className:"max-w-[75%] whitespace-pre-wrap break-words rounded-2xl bg-user px-4 py-2.5",children:t?(0,r.jsxs)("details",{className:"group/usr",children:[(0,r.jsxs)("summary",{className:"cursor-pointer list-none [&::-webkit-details-marker]:hidden",children:[(0,r.jsxs)("span",{className:"group-open/usr:hidden",children:[e.text.slice(0,180),"… ",(0,r.jsxs)("span",{className:"font-semibold text-accent",children:["(",e.text.length," симв.)"]})]}),(0,r.jsxs)("span",{className:"hidden items-center gap-1 text-[11px] font-semibold text-dim group-open/usr:inline-flex",children:["згорнути ",(0,r.jsx)(eg.A,{className:"h-3 w-3","aria-hidden":!0})]})]}),tC(e.text)]}):tC(e.text)})})}if("cmd"===e.kind){let t="ok"===e.call.status?"text-ok":"err"===e.call.status?"text-err":"text-dim";return(0,r.jsxs)("details",{className:"my-2.5 ml-9 overflow-hidden rounded-[14px] border border-line bg-panel shadow-card",open:e.call.open,children:[(0,r.jsxs)("summary",{className:"flex cursor-pointer list-none items-center gap-2.5 px-3.5 py-2",children:[(0,r.jsx)("span",{className:"flex h-6.5 w-6.5 shrink-0 items-center justify-center rounded-lg bg-chip",children:(0,r.jsx)(eO,{name:e.call.icon,className:"h-4 w-4"})}),(0,r.jsx)("code",{className:"max-w-[70%] overflow-hidden text-ellipsis whitespace-nowrap rounded-md bg-chip px-2 py-0.5 font-mono text-[12.5px]",children:e.call.display}),(0,r.jsxs)("span",{className:`ml-auto inline-flex shrink-0 items-center gap-1 text-xs font-semibold ${t}`,children:[(0,r.jsx)(tP,{status:e.call.status}),e.call.label]})]}),(0,r.jsx)("pre",{className:"max-h-[340px] overflow-auto whitespace-pre-wrap border-t border-line bg-[#fafafc] px-3.5 py-2.5 font-mono text-[12.5px]",children:"$ "+e.call.cmd+(e.call.output?"\n"+e.call.output:"\n(вивід у цьому лог-файлі відсутній — повний є в rollout-сесії Codex)")})]})}if("cmd-group"===e.kind)return(0,r.jsx)(tI,{item:e});if("edit"===e.kind)return(0,r.jsxs)("div",{className:"my-2.5 ml-9 flex items-center gap-3 rounded-[14px] border border-line bg-panel px-3.5 py-2.5 shadow-card",children:[(0,r.jsx)("span",{className:"flex h-7.5 w-7.5 items-center justify-center rounded-lg bg-chip",children:(0,r.jsx)(eO,{name:"note",className:"h-4 w-4"})}),(0,r.jsxs)("div",{children:[(0,r.jsx)("div",{className:"text-[13.5px] font-semibold",children:e.files}),(0,r.jsx)("div",{className:"text-xs text-dim",children:"файли змінені"})]})]});if("tmsg"===e.kind){let t=function(e){let t=e.trim();if((t.startsWith('"')&&t.endsWith('"')||t.startsWith("'")&&t.endsWith("'"))&&(t=t.slice(1,-1).trim()),!t.startsWith("{"))return null;try{let e=JSON.parse(t);if(null!==e&&"object"==typeof e&&!Array.isArray(e))return e}catch{}return null}(e.text),n=e.text.length>420||e.text.split("\n").length>6;return(0,r.jsxs)("div",{className:"my-2.5 ml-9 overflow-hidden rounded-[14px] border border-accent/25 bg-[#f8f8fd] shadow-card",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2 px-3.5 pt-2",children:[(0,r.jsx)("span",{className:"flex h-6.5 w-6.5 shrink-0 items-center justify-center rounded-lg bg-[#ecebfb] text-accent",children:(0,r.jsx)(ey.A,{className:"h-3.5 w-3.5","aria-hidden":!0})}),(0,r.jsx)("span",{className:"text-[11px] font-semibold text-dim",children:"out"===e.dir?"до":"від"}),(0,r.jsx)("span",{className:"rounded-full bg-accent/10 px-2 py-0.5 text-[11px] font-bold text-accent",children:e.peer}),e.delivery?(0,r.jsxs)("span",{className:`inline-flex shrink-0 items-center gap-1 text-[10.5px] font-semibold ${"ok"===e.delivery?"text-ok":"text-err"}`,title:e.msgId?`msg_id: ${e.msgId}`:void 0,children:["ok"===e.delivery?(0,r.jsx)(eh.A,{className:"h-3 w-3","aria-hidden":!0}):(0,r.jsx)(l.A,{className:"h-3 w-3","aria-hidden":!0}),"ok"===e.delivery?"доставлено":"не доставлено"]}):null,A(e.ts)?(0,r.jsx)("span",{className:"ml-auto shrink-0 text-[11px] text-dim",children:A(e.ts)}):null]}),(0,r.jsx)("div",{className:"px-3.5 pb-2.5 pt-1",children:t?(0,r.jsx)(tq,{payload:t}):(0,r.jsxs)(r.Fragment,{children:[e.summary?(0,r.jsx)("div",{className:"text-[13px] font-bold",children:ty(e.summary)}):null,n?(0,r.jsxs)("details",{className:"group/tmsg mt-0.5 whitespace-pre-wrap break-words text-[13px]",children:[(0,r.jsxs)("summary",{className:"cursor-pointer list-none text-[12.5px] text-[#555] [&::-webkit-details-marker]:hidden",children:[(0,r.jsxs)("span",{className:"group-open/tmsg:hidden",children:[e.text.slice(0,260).trimEnd(),"… ",(0,r.jsx)("span",{className:"font-semibold text-accent",children:"показати все"})]}),(0,r.jsxs)("span",{className:"hidden items-center gap-1 text-[11px] font-semibold text-dim group-open/tmsg:inline-flex",children:["згорнути ",(0,r.jsx)(eg.A,{className:"h-3 w-3","aria-hidden":!0})]})]}),tC(e.text)]}):(0,r.jsx)("div",{className:"mt-0.5 whitespace-pre-wrap break-words text-[13px]",children:tC(e.text)})]})})]})}if("tnote"===e.kind)return(0,r.jsxs)("div",{className:"my-1 ml-9 flex items-center gap-1.5 text-[11.5px] text-dim",children:[(0,r.jsx)(ey.A,{className:"h-3 w-3 shrink-0","aria-hidden":!0}),e.text]});if("think"===e.kind){let t=e.text.length>150;return(0,r.jsxs)("details",{className:"my-1 ml-9 text-[11.5px] italic text-dim",children:[(0,r.jsxs)("summary",{className:`flex list-none items-center gap-1.5 truncate ${t?"cursor-pointer":""}`,title:"міркування агента",children:[(0,r.jsx)(em.A,{className:"h-3.5 w-3.5 shrink-0","aria-hidden":!0}),(0,r.jsxs)("span",{className:"truncate",children:[e.text.slice(0,150),t?"…":""]})]}),t?(0,r.jsx)("div",{className:"whitespace-pre-wrap break-words pt-1 not-italic",children:tC(e.text)}):null]})}return"svc"===e.kind?(0,r.jsx)("div",{className:"my-1 break-words text-[11.5px] text-dim",children:e.text}):"note"===e.kind?(0,r.jsx)("div",{className:"my-2 break-words text-[12.5px] text-dim",children:ty(e.text)}):(0,r.jsx)("div",{className:`my-0.5 break-words text-[12.5px] ${e.err?"text-err":"text-[#555]"}`,children:e.text})});var tH=n(9267),tY=n(9383);function tB({file:e}){let t=e.pendingQuestion,[n,s]=(0,i.useState)("pending"),[a,o]=(0,i.useState)(""),[c,d]=(0,i.useState)({}),[u,x]=(0,i.useState)(""),[p,f]=(0,i.useState)(""),[m,h]=(0,i.useState)(!1),b=t?null!==t.paneTarget:null!==e.pid&&"running"===e.proc,g=(0,i.useMemo)(()=>t?.questions?t.questions.map((e,t)=>(c[t]??[]).map(t=>e.options[t]?.label??String(t+1)).join(", ")).filter(Boolean).join(" \xb7 "):"",[c,t]);if(!t)return e.waitingInput?(0,r.jsxs)("div",{id:"question",className:"my-4 rounded-[8px] border border-[#e0ae45]/45 bg-[#fff9ed] p-4 shadow-card",children:[(0,r.jsxs)("div",{className:"mb-2 inline-flex items-center gap-1.5 rounded-full bg-[#f5dfae] px-2 py-0.5 text-[11px] font-bold text-[#8a5a00]",children:[(0,r.jsx)(tH.A,{className:"h-3.5 w-3.5","aria-hidden":!0})," чекає на відповідь"]}),(0,r.jsxs)("div",{className:"text-[13px] font-semibold text-ink",children:["Пейн ",e.waitingInput.target," \xb7 ",function(e){let t=Math.max(0,Math.floor(Date.now()/1e3-e));if(t<60)return`${t} с`;let n=Math.floor(t/60);return n<60?`${n} хв`:`${Math.floor(n/60)} год`}(e.waitingInput.since)]}),(0,r.jsx)("pre",{className:"mt-2 whitespace-pre-wrap break-words rounded-[8px] border border-line bg-bg px-3 py-2 text-[12px] text-dim",children:e.waitingInput.screenTail}),(0,r.jsx)("div",{className:"mt-3 text-[12px] text-dim",children:"Можна відповісти через композер нижче."})]}):null;let v=async(e,n)=>{s("delivering"),o("");try{let r=await fetch("/api/answer",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({transcriptPath:t.transcriptPath,toolUseId:t.toolUseId,kind:t.kind,...e})}),l=await r.json();if(!r.ok||!l.ok){if(409===r.status&&(l.superseded||l.answer)){s("superseded"),o(l.answer??l.error??"відповідь уже записана");return}s("failed"),o(l.error??"не вдалося надіслати");return}s("answered"),o(l.answer??n)}catch{s("failed"),o("сервер недоступний")}},w=(e=c)=>t.questions?.map((t,n)=>e[n]??[])??[],j=t.questions?.length??0,y=j>1||(t.questions?.some(e=>e.multiSelect)??!1),N=t.questions?.every((e,t)=>(c[t]??[]).length>0)??!1,k=async()=>{h(!0),o("");try{let t=await fetch("/api/tmux",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({action:"resume",path:e.path})}),n=await t.json();if(!t.ok||!n.ok)return void o(n.error??"не вдалося відкрити сесію");o(`відкрито ${n.target??"tmux"}`)}catch{o("сервер недоступний")}finally{h(!1)}},S="delivering"===n||!b;return"answered"===n?(0,r.jsxs)("div",{id:"question",className:"my-4 rounded-[8px] border border-ok/25 bg-[#eefaf1] px-4 py-3 text-[13px] font-semibold text-ok",children:["Відповідено: ",a||g]}):"superseded"===n?(0,r.jsxs)("div",{id:"question",className:"my-4 rounded-[8px] border border-line bg-chip px-4 py-3 text-[13px] font-semibold text-dim",children:["Відповідено в іншому місці: ",a]}):t&&!b?(0,r.jsxs)("div",{id:"question",className:"my-4 rounded-[8px] border border-[#e0ae45]/45 bg-[#fff9ed] p-4 shadow-card",children:[(0,r.jsxs)("div",{className:"mb-2 inline-flex items-center gap-1.5 rounded-full bg-[#f5dfae] px-2 py-0.5 text-[11px] font-bold text-[#8a5a00]",children:[(0,r.jsx)(tH.A,{className:"h-3.5 w-3.5","aria-hidden":!0})," чекає на відповідь"]}),(0,r.jsx)("div",{className:"text-[13px] font-semibold text-err",children:"tmux-пейн недоступний"}),"plan"===t.kind?(0,r.jsx)("pre",{className:"mt-2 max-h-[320px] overflow-auto whitespace-pre-wrap break-words rounded-[8px] border border-line bg-bg px-3 py-2 text-[13px]",children:t.plan}):t.questions?.map((e,t)=>(0,r.jsxs)("div",{className:"mt-2",children:[(0,r.jsx)("div",{className:"text-[12px] font-bold text-dim",children:e.header}),(0,r.jsx)("div",{className:"text-[13px] font-semibold text-ink",children:e.question})]},t)),(0,r.jsx)("button",{className:"mt-3 rounded-[8px] bg-accent px-3 py-1.5 text-[13px] font-bold text-white disabled:opacity-60",disabled:m,onClick:k,children:"відкрити сесію"}),a?(0,r.jsx)("div",{className:"mt-2 text-[12px] font-semibold text-dim",children:a}):null]}):(0,r.jsxs)("div",{id:"question",className:"my-4 rounded-[8px] border border-[#e0ae45]/45 bg-[#fff9ed] p-4 shadow-card",children:[(0,r.jsxs)("div",{className:"mb-3 flex flex-wrap items-center gap-2",children:[(0,r.jsxs)("span",{className:"inline-flex items-center gap-1.5 rounded-full bg-[#f5dfae] px-2 py-0.5 text-[11px] font-bold text-[#8a5a00]",children:[(0,r.jsx)(tH.A,{className:"h-3.5 w-3.5","aria-hidden":!0})," чекає на відповідь"]}),b?null:(0,r.jsx)("span",{className:"text-[12px] font-semibold text-err",children:"tmux-пейн недоступний"})]}),"plan"===t.kind?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("pre",{className:"max-h-[420px] overflow-auto whitespace-pre-wrap break-words rounded-[8px] border border-line bg-bg px-3 py-2 text-[13px]",children:t.plan}),(0,r.jsx)("textarea",{className:"mt-3 min-h-20 w-full resize-y rounded-[8px] border border-line bg-bg px-3 py-2 text-[13px] outline-none focus-visible:ring-2 focus-visible:ring-accent/35",placeholder:"Коментар до відхилення…",value:p,onChange:e=>f(e.target.value)}),(0,r.jsxs)("div",{className:"mt-3 flex flex-wrap gap-2",children:[(0,r.jsxs)("button",{className:"inline-flex items-center gap-1.5 rounded-[8px] bg-ok px-3 py-1.5 text-[13px] font-bold text-white disabled:opacity-60",disabled:S,onClick:()=>v({approve:!0},"затверджено"),children:[(0,r.jsx)(eh.A,{className:"h-4 w-4","aria-hidden":!0})," Затвердити"]}),(0,r.jsxs)("button",{className:"inline-flex items-center gap-1.5 rounded-[8px] bg-err px-3 py-1.5 text-[13px] font-bold text-white disabled:opacity-60",disabled:S,onClick:()=>v({approve:!1,text:p},"відхилено"),children:[(0,r.jsx)(l.A,{className:"h-4 w-4","aria-hidden":!0})," Відхилити"]})]})]}):(0,r.jsxs)(r.Fragment,{children:[t.questions?.map((e,t)=>(0,r.jsxs)("section",{className:"mt-3 first:mt-0",children:[(0,r.jsx)("div",{className:"mb-1 inline-flex rounded-full bg-bg px-2 py-0.5 text-[11px] font-bold text-dim",children:e.header}),(0,r.jsx)("div",{className:"mb-2 text-[14px] font-bold text-ink",children:e.question}),(0,r.jsx)("div",{className:"space-y-1.5",children:e.options.map((n,l)=>{let i=(c[t]??[]).includes(l);return(0,r.jsxs)("button",{className:`flex w-full items-start gap-2 rounded-[8px] border px-3 py-2 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/35 ${i?"border-accent/45 bg-accent/10":n.recommended?"border-[#e0ae45]/45 bg-[#fff5dc]":"border-line bg-bg"}`,disabled:S,onClick:()=>{var r;let i={...c,[t]:[l]};r=e.multiSelect,d(e=>{let n=e[t]??[],i=r?n.includes(l)?n.filter(e=>e!==l):[...n,l]:[l];return{...e,[t]:i}}),e.multiSelect||1!==j||v({answers:w(i)},n.label)},children:[(0,r.jsx)("span",{className:"mt-0.5 flex h-4 w-4 shrink-0 items-center justify-center rounded border border-line bg-panel text-[10px] font-bold",children:i?"✓":l+1}),(0,r.jsxs)("span",{className:"min-w-0",children:[(0,r.jsx)("span",{className:"block text-[13px] font-bold",children:n.label}),n.description?(0,r.jsx)("span",{className:"block text-[12px] text-dim",children:n.description}):null]})]},l)})})]},t)),j<=1?(0,r.jsxs)("div",{className:"mt-3 flex gap-2",children:[(0,r.jsx)("input",{className:"min-w-0 flex-1 rounded-[8px] border border-line bg-bg px-3 py-1.5 text-[13px] outline-none focus-visible:ring-2 focus-visible:ring-accent/35",placeholder:"Своя відповідь…",value:u,onChange:e=>x(e.target.value)}),(0,r.jsxs)("button",{className:"inline-flex items-center gap-1.5 rounded-[8px] bg-accent px-3 py-1.5 text-[13px] font-bold text-white disabled:opacity-60",disabled:S||!u.trim(),onClick:()=>v({text:u},u),children:[(0,r.jsx)(tY.A,{className:"h-4 w-4","aria-hidden":!0})," Надіслати"]})]}):null,y?(0,r.jsxs)("button",{className:"mt-3 inline-flex items-center gap-1.5 rounded-[8px] bg-accent px-3 py-1.5 text-[13px] font-bold text-white disabled:opacity-60",disabled:S||!N,onClick:()=>v({answers:w()},g),children:[(0,r.jsx)(tY.A,{className:"h-4 w-4","aria-hidden":!0})," Надіслати"]}):null]}),"delivering"===n?(0,r.jsxs)("div",{className:"mt-3 inline-flex items-center gap-1.5 text-[12px] font-semibold text-dim",children:[(0,r.jsx)(eL.A,{className:"h-3.5 w-3.5 animate-spin","aria-hidden":!0})," надсилаю…"]}):null,"failed"===n?(0,r.jsx)("div",{className:"mt-3 text-[12px] font-semibold text-err",children:a}):null]})}function tX({icon:e,label:t}){return(0,r.jsxs)("div",{className:"mt-2 flex items-center gap-2 text-[12px] font-semibold text-ok",children:[(0,r.jsxs)("span",{className:"flex items-center gap-0.5","aria-hidden":!0,children:[(0,r.jsx)("span",{className:"h-1.5 w-1.5 animate-bounce rounded-full bg-ok"}),(0,r.jsx)("span",{className:"h-1.5 w-1.5 animate-bounce rounded-full bg-ok [animation-delay:150ms]"}),(0,r.jsx)("span",{className:"h-1.5 w-1.5 animate-bounce rounded-full bg-ok [animation-delay:300ms]"})]}),(0,r.jsx)(e,{className:"h-3.5 w-3.5","aria-hidden":!0}),t]})}function tW({file:e,files:t,onSelect:n,showSvc:l,lineFilter:s,onStatus:a,paused:o,follow:c,setFollow:d,compact:x=!1}){let[p,f]=(0,i.useState)(c),m=function(e,t=!1,n=2500){let r=(0,i.useRef)(n),[l,s]=(0,i.useState)([]),[a,o]=(0,i.useState)(0),[c,d]=(0,i.useState)(!1),[u,x]=(0,i.useState)(null),[p,f]=(0,i.useState)(null),[m,h]=(0,i.useState)(!1),[b,g]=(0,i.useState)(!1),[v,w]=(0,i.useState)(!1),[j,y]=(0,i.useState)(0),N=(0,i.useRef)(0),k=(0,i.useRef)(0),S=(0,i.useRef)(""),C=(0,i.useRef)(!0),$=(0,i.useRef)(0),A=(0,i.useRef)(!1),E=(0,i.useRef)(!1);(0,i.useEffect)(()=>{r.current=n},[n]),(0,i.useEffect)(()=>{A.current=m||t},[m,t]);let M=()=>{N.current=0,k.current=0,S.current="",C.current=!0,g(!1)},R=(0,i.useCallback)(()=>{s([]),M()},[]);return(0,i.useEffect)(()=>{$.current+=1,M(),s([]),o(e?.size??0),x(null),d(!!e)},[e?.path]),(0,i.useEffect)(()=>{if(!e)return;let t=!0,n=$.current,l=async()=>{if(t&&!A.current)try{let l=await fetch(`/api/log?path=${encodeURIComponent(e.path)}&offset=${N.current}`),i=await l.json();if(!t||n!==$.current)return;if("error"in i&&i.error){x(i.error),d(!1);return}if(N.current>i.size&&(M(),s([])),i.data){let e=S.current+i.data;if(S.current="",C.current){if(k.current=i.start,i.start>0){let t=e.indexOf("\n");k.current=i.start+(t>=0?e2(e.slice(0,t+1)):e2(e)),e=t>=0?e.slice(t+1):""}g(k.current>0)}let t=e.split("\n");S.current=t.pop()??"";let n=t.map(e=>e.trim()).filter(Boolean);0===N.current?s(n):n.length&&s(e=>r.current>0?e.concat(n).slice(-r.current):e.concat(n)),C.current=!1}N.current=i.offset,o(i.size),x(null),i.data&&f(new Date),d(!1)}catch{t&&n===$.current&&(x("сервер недоступний"),d(!1))}};l();let i=setInterval(l,1200);return()=>{t=!1,clearInterval(i)}},[e?.path]),{lines:l,size:a,loading:c,error:u,tickTime:p,paused:m,setPaused:h,clear:R,hasMore:b,loadingOlder:v,loadOlder:(0,i.useCallback)(async()=>{if(!e||E.current||k.current<=0)return 0;E.current=!0,w(!0);let t=$.current;try{let n="",r=k.current;for(let l=0;l<4;l+=1){let l=await fetch(`/api/log?path=${encodeURIComponent(e.path)}&before=${r}`),i=await l.json();if(t!==$.current||"error"in i&&i.error)return 0;if(n=i.data+n,r=i.start,0===r||n.slice(0,-1).includes("\n"))break}let l=r;if(r>0){let e=n.indexOf("\n");if(e<0||e===n.length-1)return 0;l=r+e2(n.slice(0,e+1)),n=n.slice(e+1)}let i=n.split("\n");""===i.at(-1)&&i.pop();let a=i.map(e=>e.trim()).filter(Boolean);return k.current=l,g(l>0),a.length&&(s(e=>a.concat(e)),y(e=>e+1)),a.length}catch{return 0}finally{E.current=!1,w(!1)}},[e?.path]),prependGen:j}}(e,o,p&&x?2500:0),h=(0,i.useRef)(null),b=(0,i.useRef)(null),g=(0,i.useRef)(null),v=x?300:1500,w=x?500:1500,[j,y]=(0,i.useState)(v),[N,k]=(0,i.useState)(0),[S,C]=(0,i.useState)(!1),[$,E]=(0,i.useState)(null),M=(0,i.useRef)(!1),R=(0,i.useRef)(p),T=(0,i.useRef)(0),P=(0,i.useRef)(0),_=(0,i.useRef)(null),I=(e,t=!1)=>{R.current=e,f(e),d(e),e&&k(0),t&&(C(!0),_.current&&window.clearTimeout(_.current),_.current=window.setTimeout(()=>C(!1),450))};(0,i.useEffect)(()=>y(v),[e?.path,v]),(0,i.useEffect)(()=>{c!==R.current&&(R.current=c,f(c),c&&k(0))},[c]),(0,i.useEffect)(()=>()=>{_.current&&window.clearTimeout(_.current)},[]),(0,i.useEffect)(()=>{M.current=!1,queueMicrotask(()=>E(null))},[e?.path]),(0,i.useEffect)(()=>{if(e){if(e.pendingQuestion){M.current=!0,queueMicrotask(()=>E(null));return}M.current&&e.proc&&"running"!==e.proc&&(queueMicrotask(()=>E("агент завершився")),M.current=!1)}},[e?.pendingQuestion?.toolUseId,e?.proc,e]);let z=(0,i.useMemo)(()=>e?function(e,t,n,r){let l=new Map,i=new Map,s=[],a=0,o="",c=e=>!!(!(e.length<=2e4)&&(e.match(/\s/g)?.length??0)/e.length<.02)&&(s.push({kind:"blob",bytes:e.length,text:te(e).slice(0,2e5)}),!0),d=(e,t)=>{let n=tg(e.source),r=tb(n.data)||tb(t.base64);if(!r)return;let l=tb(n.media_type)||tb(t.type),i=l.startsWith("image/")?l:"image/png",a=tg(t.dimensions);s.push({kind:"image",media:i,data:r,w:td(a.originalWidth),h:td(a.originalHeight),bytes:td(t.originalSize)})},u=(e,t,n)=>{to.lastIndex=0;let r=to.test(t);if(to.lastIndex=0,!r){let n=tr(t.trim(),e);return!!n&&(s.push(n),!0)}let l=!1,i=0,a=t=>{let r=t.trim();if(!r)return;let i=tr(r,e);i?(s.push(i),l=!0):n(r)};for(let e of t.matchAll(to)){let n=e[0],r=e.index??0;a(t.slice(i,r)),s.push(t$(n,e[1]??"",e[2]??"")),l=!0,i=r+n.length}return a(t.slice(i)),l},x=e=>{let t=[];return to.lastIndex=0,{cleaned:e.replace(to,(e,n,r)=>(t.push(t$(e,n,r)),"")).trim(),cites:t}},p=(t,n)=>{if(!n.trim()||n===o||(o=n,c(n)))return;let r="codex"===e.engine?"codex":"claude";u(t,n,e=>s.push({kind:"prose",ts:t,text:e,engine:r}))||s.push({kind:"prose",ts:t,text:n,engine:r})},f=(e,t,n,r)=>{let i=n||"plain-"+s.length+"-"+String(e??""),a=function(e,t="shell"){let n=te(e);return{cmd:n,display:function(e){let t,n=e.match(/^([A-Za-z][\w.]*): /),r=n?n[0]:"",l=r?e.slice(r.length):e;do t=l,l=(l=(l=(l=l.replace(/^export PATH=[^;]+;\s*/,"")).replace(/^cd\s+\S+\s*&&\s*/,"")).replace(/^\/usr\/bin\/zsh -lc\s+/,"")).replace(/^(["'])([\s\S]*)\1$/,(e,t,n)=>RegExp(`(?<!\\\\)${t}`).test(n)?e:n);while(l!==t);let i=l.match(/^([\w./-]+(?:\s+-)?)\s*<<\s*['"]?(\w+)['"]?/);return i&&(l=`${i[1].trim()} \xabheredoc\xbb`),(r+(l=l.replace(/\s+/g," ").trim())).slice(0,160)}(n),icon:t,output:"",status:"run",label:"виконується…",open:!1}}(t,r);return l.set(i,a),s.push({kind:"cmd",id:i,call:a,ts:e}),a},m=(e,t,r)=>{if(!e)return;let a=i.get(e);if(a){a.delivery=r||/"success"\s*:\s*false/.test(t)?"err":"ok",a.msgId=t.match(/"msg_id"\s*:\s*"([^"]+)"/)?.[1];return}!tA(l.get(e),t,r)&&t&&n&&s.push({kind:"svc",text:"output: "+te(t).slice(0,200)})},h=e=>{n?s.push({kind:"svc",text:e.slice(0,300)}):a+=1},b=e=>{s.push({kind:"note",text:e})},g=(e,t)=>{let n=t.replace(tu,(t,n,r,l)=>{let i=th(r,"teammate_id")||th(r,"from")||"тімейт",a=th(r,"summary"),o=l.trim();if(o.startsWith("{"))try{let e=JSON.parse(o);if("idle_notification"===e.type){let t=A(e.timestamp);return s.push({kind:"tnote",text:`${i}: звільнився${t?" \xb7 "+t:""}`}),""}}catch{}let{cleaned:c,cites:d}=x(o),u=e3.test(c)?tr(c,e):null;for(let t of(s.push({kind:"tmsg",ts:e,dir:"in",peer:i,summary:a,text:u?"":c}),u&&s.push(u),d))s.push(t);return""}).replace(/Another Claude session sent a message:\s*/g,"").trim();if(!n||c(n))return;if(tf.test(n))return void s.push({kind:"sysmsg",label:tm(n),text:n});let{cleaned:r,images:l}=tp(n);for(let t of(r&&!u(e,r,t=>s.push({kind:"user",ts:e,text:t}))&&s.push({kind:"user",ts:e,text:r}),l))s.push({kind:"inbox-image",name:t.name,path:t.path})},v=(e,t)=>{let{cleaned:n,images:r}=tp(t);for(let t of(n&&s.push({kind:"user",ts:e,text:n}),r))s.push({kind:"inbox-image",name:t.name,path:t.path})},w=e=>{let t=tg(e.payload),n=e.timestamp;if("session_meta"===e.type)return b(`Сесія Codex створена \xb7 ${tb(t.model)} \xb7 ${tb(t.cwd)}`);if("event_msg"===e.type){if("agent_message"===t.type&&t.message)return p(n,tb(t.message));if("user_message"===t.type&&t.message){let e=tb(t.message);return tf.test(e)?s.push({kind:"sysmsg",label:tm(e),text:e}):v(n,e)}return"task_started"===t.type?b("Задача стартувала"+(n?" \xb7 "+A(n):"")):"task_complete"===t.type?b("Задачу завершено"+(n?" \xb7 "+A(n):"")):h(tb(t.type)||"event")}if("response_item"===e.type){if("message"===t.type){let e=tv(t.content).map(e=>tb(e.text)||tb(e.input_text)).join(" ").trim();return e?"user"!==t.role?p(n,e):tf.test(e)?s.push({kind:"sysmsg",label:tm(e),text:e}):v(n,e):h("message "+tb(t.role))}if("function_call"===t.type){let e={};try{e=JSON.parse(tb(t.arguments)||"{}")}catch{e={}}let r=tb(t.name);if("exec_command"===r||"shell"===r)return f(n,String(e.cmd??e.command??"").replace(/^\/usr\/bin\/zsh -lc /,""),tb(t.call_id));if("apply_patch"===r){let t=String(e.input??"").match(/(Add|Update|Delete) File: [^\n]+/g);s.push({kind:"edit",files:t?t.join(", ").replace(/(Add|Update|Delete) File: /g,""):"патч"});return}return"write_stdin"===r?h("stdin → сесія "+String(e.session_id??"")):f(n,r+" "+JSON.stringify(e).slice(0,120),tb(t.call_id),"tool")}if("function_call_output"===t.type)return m(tb(t.call_id),"string"==typeof t.output?t.output:JSON.stringify(t.output??""));if("custom_tool_call"===t.type&&"apply_patch"===tb(t.name)){let e=tb(t.input).match(/(Add|Update|Delete) File: [^\n]+/g);s.push({kind:"edit",files:e?e.join(", ").replace(/(Add|Update|Delete) File: /g,""):"патч"});return}return"custom_tool_call_output"===t.type?m(tb(t.call_id),"string"==typeof t.output?t.output:JSON.stringify(t.output??"")):"reasoning"===t.type?h("reasoning"):h(tb(t.type)||"item")}h(tb(e.type)||"запис")},j=e=>{let t=e.timestamp;if("user"===e.type&&e.message){let n=tg(e.message).content,r=tg(tg(e.toolUseResult).file);if("string"==typeof n)g(t,n);else for(let e of tv(n))if("text"===e.type)g(t,tb(e.text));else if("image"===e.type)d(e,r);else if("tool_result"===e.type){let t=tv(e.content);for(let e of t)"image"===e.type&&d(e,r);let n="string"==typeof e.content?e.content:t.filter(e=>"image"!==e.type).map(e=>tb(e.text)).join(" ");m(tb(e.tool_use_id),n,!0===e.is_error)}return}if("assistant"===e.type&&e.message){for(let n of tv(tg(e.message).content))if("text"===n.type&&tb(n.text).trim())p(t,tb(n.text));else if("thinking"===n.type&&tb(n.thinking).trim())s.push({kind:"think",text:tb(n.thinking).replace(/\s+/g," ").trim()});else if("tool_use"===n.type&&"SendMessage"===tb(n.name)){let e=tg(n.input),r=e.message;if("string"==typeof r){let{cleaned:l,cites:a}=x(r),o=e3.test(l)?tr(l,t):null,c={kind:"tmsg",ts:t,dir:"out",peer:String(e.to??""),summary:String(e.summary??""),text:o?"":l};for(let e of(s.push(c),o&&s.push(o),a))s.push(e);tb(n.id)&&i.set(tb(n.id),c)}else h(`SendMessage → ${String(e.to??"")} \xb7 ${tb(tg(r).type)||"протокол"}`)}else if("tool_use"===n.type){let e=tg(n.input),r=String(e.command??e.file_path??e.prompt??JSON.stringify(e));f(t,tb(n.name)+": "+r.slice(0,160),tb(n.id),"tool")}return}h(tb(e.type)||"запис")},y=null,N=()=>{if(!y)return;let e=y.join("\n").trim();if(y=null,!e)return;let t=e=>{for(let t of e.split("\n"))t.trim()&&s.push({kind:"raw",text:te(t),err:/error|failed|traceback|exception/i.test(t)})};u(null,e,t)||t(e)},k=e=>{let t=e.replace(/\x1b\][^\x07]*(\x07|\x1b\\)/g,"").replace(/\x1b\[[0-9;?]*[A-Za-z]/g,"");if(y)if(!/^\[codex\]/.test(t))return void y.push(t);else N();if(/Assistant message$/.test(t))return;let n=t.match(/^\[([^\]]+)\]\s*(.*)$/),r=n?.[1]??null,i=n?.[2]??t;if(!(!i||/^Assistant message captured/.test(i))){if(!n&&(e3.test(t)||t.startsWith("<oai-mem-citation>"))){y=[t];return}if(/^Running command: /.test(i))return f(r,i.replace(/^Running command: /,"").replace(/^\/usr\/bin\/zsh -lc /,""));if(/^Command (completed|failed)/.test(i)){let e=[...l.values()].at(-1);e&&tA(e,/^Command failed/.test(i)?i+"\n(це джоб-лог: він не містить stdout команд; повний вивід — у rollout-сесії Codex у списку зліва)":i,/^Command failed/.test(i));return}return/^Applying \d+ file/.test(i)?s.push({kind:"edit",files:i}):n&&!/^(Running|Command|Applying)/.test(i)?p(r,i):void(!c(t)&&s.push({kind:"raw",text:te(t),err:/error|failed|traceback|exception/i.test(t)}))}};for(let n of t)if(!r||n.toLowerCase().includes(r))if("claude"===e.fmt||"codex"===e.fmt)try{let t=JSON.parse(n);t&&"object"==typeof t&&!Array.isArray(t)&&("claude"===e.fmt?j(t):w(t))}catch{k(n)}else k(n);return N(),{items:function(e,t){let n=[],r=0;for(;r<e.length;){if("cmd"!==e[r].kind){n.push(e[r]),r+=1;continue}let i=r,s=[];for(;i<e.length;){let t=e[i];if("cmd"===t.kind)s.push(t);else if("think"!==t.kind)break;i+=1}let a=i===e.length;if(s.length>=4&&!(t&&a)){let e={},t=0,a=0;for(let n of s){var l;let r=(l=n.call.cmd,l.match(/^([A-Za-z][\w.]*): /)?.[1]??"cmd");e[r]=(e[r]??0)+1,"ok"===n.call.status?t+=1:"err"===n.call.status&&(a+=1)}n.push({kind:"cmd-group",ids:s.map(e=>e.id),calls:s.map(e=>e.call),t0:s[0]?.ts,t1:s.at(-1)?.ts,byTool:e,okCount:t,errCount:a,hasErr:a>0}),r=i}else n.push(e[r]),r+=1}return n}(s,"live"===e.activity),hiddenServiceCount:a}}(e,m.lines,l,s.toLowerCase()):{items:[],hiddenServiceCount:0},[e?.path,e?.engine,e?.fmt,e?.activity,m.lines,l,s]),L=Math.max(0,z.items.length-j),D=L?z.items.slice(-j):z.items;(0,i.useEffect)(()=>{let t=m.tickTime?.toLocaleTimeString("uk",{hour12:!1})??"";m.error?a(m.error):e?a(`${(m.size/1024).toFixed(0)} kB${t?" \xb7 "+t:""}`):a("")},[m.error,m.size,m.tickTime,e,a]),(0,i.useLayoutEffect)(()=>{let e=h.current,t=g.current;e&&t&&(g.current=null,e.scrollTop=t.top+(e.scrollHeight-t.height))},[m.prependGen,j]),(0,i.useLayoutEffect)(()=>{let e=z.items.length,t=m.prependGen!==P.current;P.current=m.prependGen;let n=e-T.current;T.current=e,p?h.current&&(h.current.scrollTop=h.current.scrollHeight):!t&&n>0&&k(e=>e+n)},[z.items,p,m.prependGen]),(0,i.useEffect)(()=>{let e=h.current,t=b.current;if(!e||!t)return;let n=new ResizeObserver(()=>{R.current&&(e.scrollTop=e.scrollHeight)});return n.observe(t),n.observe(e),()=>n.disconnect()},[]);let O=()=>{let e=h.current;e&&(g.current={top:e.scrollTop,height:e.scrollHeight}),L?y(e=>e+w):m.hasMore&&m.loadOlder().then(()=>y(e=>e+w))},F=L>0||m.hasMore,U=z.items.at(-1),q=U?.kind==="cmd"&&"run"===U.call.status?{icon:eM.A,label:`виконує ${U.call.cmd.split(/[\s:]/,1)[0]||"інструмент"}…`}:U?.kind==="think"?{icon:eC.A,label:"думає…"}:{icon:eC.A,label:"працює…"};return(0,r.jsxs)("div",{className:"relative flex min-h-0 flex-1 flex-col",children:[e&&z.items.length?p?"live"===e.activity?(0,r.jsxs)("div",{className:`pointer-events-none absolute bottom-2 right-3 z-10 inline-flex items-center gap-1 rounded-full bg-ok px-2 py-0.5 text-[10px] font-bold text-white shadow-card transition-transform duration-200 ${S?"scale-125":"scale-100"}`,children:[(0,r.jsx)(e5.A,{className:"h-3 w-3","aria-hidden":!0})," живий хвіст"]}):null:(0,r.jsxs)("button",{className:"absolute bottom-2 right-3 z-10 inline-flex items-center gap-1 rounded-full border border-line bg-panel px-2.5 py-1 text-[11px] font-semibold text-ink shadow-card hover:border-accent/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40","aria-label":"Повернутись до живого хвоста",onClick:()=>{let e=h.current;e&&(e.scrollTop=e.scrollHeight),I(!0,!0)},children:[(0,r.jsx)(eu.A,{className:"h-3.5 w-3.5","aria-hidden":!0})," ",N?`${N} нових`:"вниз"]}):null,(0,r.jsx)("div",{ref:h,className:x?"min-h-0 flex-1 overflow-y-auto py-3":"min-h-0 flex-1 overflow-y-auto py-6",onScroll:e=>{let t=e.currentTarget,n=t.scrollTop+t.clientHeight>=t.scrollHeight-50;n&&!R.current?I(!0,!0):!n&&R.current&&I(!1),t.scrollTop<120&&F&&!m.loadingOlder&&!m.loading&&O()},children:(0,r.jsx)("div",{ref:b,className:x?"px-3 pb-4 text-[13px]":"mx-auto w-full max-w-[1060px] px-6 pb-16",children:e?(0,r.jsxs)(r.Fragment,{children:[x&&F?(0,r.jsx)("button",{className:"mb-2 flex w-full items-center justify-center gap-1.5 rounded-[8px] border border-dashed border-line bg-bg px-2 py-1 text-[11px] font-semibold text-dim hover:text-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40",disabled:m.loadingOlder,onClick:O,children:m.loadingOlder?"завантаження…":(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(eg.A,{className:"h-3.5 w-3.5","aria-hidden":!0})," показати раніше"]})}):null,!x&&F&&z.items.length?(0,r.jsx)("button",{className:"mb-3 flex w-full items-center justify-center gap-1.5 rounded-[10px] border border-dashed border-line bg-panel px-3 py-1.5 text-[12px] font-semibold text-dim hover:text-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40",disabled:m.loadingOlder,onClick:O,children:m.loadingOlder?"завантаження…":L?`показати раніше (сховано ${L})`:"завантажити раніше з файлу"}):null,x||F||!z.items.length?null:(0,r.jsx)("div",{className:"mb-3 text-center text-[11px] text-dim",children:"початок розмови"}),x?null:(0,r.jsx)(eZ,{file:e,files:t,onSelect:n}),z.items.length?(0,r.jsxs)(r.Fragment,{children:[D.map((e,t)=>{let n=t+z.items.length-D.length;return x?(0,r.jsx)("div",{className:"feed-cv",children:(0,r.jsx)(tJ,{item:e})},n):(0,r.jsx)(tJ,{item:e},n)}),e.pendingQuestion||e.waitingInput?(0,r.jsx)(tB,{file:e},e.pendingQuestion?.toolUseId??"waiting"):null,e.pendingQuestion||e.waitingInput||!$?null:(0,r.jsx)("div",{className:"my-4 rounded-[8px] border border-line bg-chip px-4 py-3 text-[13px] font-semibold text-dim",children:$}),"live"===e.activity?(0,r.jsx)(tX,{icon:q.icon,label:q.label}):null,"recent"===e.activity&&J(e)?(0,r.jsxs)("div",{className:"mt-2 flex items-center gap-1.5 text-[11.5px] font-semibold text-[#b8860b]",children:[(0,r.jsx)("span",{className:"h-1.5 w-1.5 animate-pulse rounded-full bg-[#d29a2f]","aria-hidden":!0})," закінчив хід — чекає відповіді"]}):"recent"===e.activity&&u(e)&&"running"!==e.proc?(0,r.jsxs)("div",{className:"mt-2 flex items-center gap-1 text-[11.5px] font-semibold text-accent",children:[(0,r.jsx)(eo.A,{className:"h-3.5 w-3.5","aria-hidden":!0})," повернувся з результатом"]}):null]}):(0,r.jsxs)("div",{className:"mt-[14vh] text-center text-dim",children:[m.loading?"Завантаження…":0===m.size?"Ще без виводу — файл поки порожній":z.hiddenServiceCount?`Видимих повідомлень нема — лише службові записи (${z.hiddenServiceCount}). Натисни \xabСлужбові\xbb`:"Порожньо (немає рядків для показу)",!m.loading&&(e.cmdDesc||e.cmd)?(0,r.jsxs)("div",{className:"mx-auto mt-3 max-w-[560px]",children:[e.cmdDesc?(0,r.jsx)("div",{className:"text-[12.5px] font-semibold text-ink",children:e.cmdDesc}):null,e.cmd?(0,r.jsx)("pre",{className:"mt-1.5 overflow-x-auto whitespace-pre-wrap break-words rounded-[10px] border border-line bg-bg px-3 py-2 text-left font-mono text-[11.5px] text-ink",children:e.cmd}):null]}):null]}),z.items.length?null:e.pendingQuestion||e.waitingInput?(0,r.jsx)(tB,{file:e},e.pendingQuestion?.toolUseId??"waiting"):null]}):(0,r.jsx)("div",{className:"mt-[20vh] text-center text-dim",children:"Вибери лог зліва — стрічка оновлюється сама"})})})]})}let tQ={completed:"✓",in_progress:"▸",pending:"○"};function tK({plan:e}){let t=e.total?Math.round(e.done/e.total*100):0;return(0,r.jsxs)("span",{className:"inline-flex shrink-0 items-center gap-1 rounded-full bg-[#f1f0fc] px-1.5 py-0.5 font-mono text-[9.5px] font-semibold text-accent",title:["План агента:",...e.steps.map(e=>`${tQ[e.status]} ${e.text}`)].join("\n"),"aria-label":`План: ${e.done} з ${e.total} кроків${e.current?`, зараз: ${e.current}`:""}`,children:[e.done,"/",e.total,(0,r.jsx)("span",{className:"h-1 w-6 overflow-hidden rounded-full bg-accent/20","aria-hidden":!0,children:(0,r.jsx)("span",{className:"block h-full rounded-full bg-accent",style:{width:`${t}%`}})})]})}let tV={active:{label:"ціль",className:"bg-[#f1f0fc] text-accent"},complete:{label:"ціль ✓",className:"bg-[#e7f4ea] text-ok"},blocked:{label:"ціль ✖",className:"bg-[#fbeaea] text-err"}};function tG({ctx:e}){var t;return(0,r.jsxs)("span",{className:`inline-flex shrink-0 items-center rounded-full px-1.5 py-0.5 font-mono text-[9.5px] font-semibold ${(t=e.pct)>=90?"bg-[#fbeaea] text-err":t>=70?"bg-[#fff7e6] text-[#b07d18]":"bg-chip text-dim"}`,title:`Контекстне вікно: використано ${e.pct}%
5
- ${e.usedTokens.toLocaleString("uk-UA")} з ${e.windowTokens.toLocaleString("uk-UA")} токенів`,"aria-label":`Контекст: використано ${e.pct} відсотків вікна`,children:["ctx ",e.pct,"%"]})}function tZ({goal:e}){let t,n=tV[e.status];return(0,r.jsx)("span",{className:`inline-flex shrink-0 items-center rounded-full px-1.5 py-0.5 text-[9.5px] font-semibold ${n.className}`,title:(t=[e.objective??"(objective не записаний у хвості транскрипта)"],null!==e.tokensUsed&&t.push(`токенів: ${e.tokensUsed.toLocaleString("uk-UA")}`),null!==e.timeUsedSeconds&&t.push(`часу: ${Math.round(e.timeUsedSeconds/60)} хв`),t.join("\n")),"aria-label":`Ціль сесії: ${e.status}${e.objective?` — ${e.objective.slice(0,120)}`:""}`,children:n.label})}function t0({onError:e,onUnclaimedText:t}){let[n,r]=(0,i.useState)("idle"),[l,s]=(0,i.useState)(0),a=(0,i.useRef)(null),o=(0,i.useRef)([]),c=(0,i.useRef)(!1),d=(0,i.useRef)(null),u=(0,i.useRef)(null),x=(0,i.useRef)(null),p=(0,i.useRef)(null),f=(0,i.useRef)(!1),m=()=>{null!==d.current&&(clearInterval(d.current),d.current=null)},h=()=>{let e=x.current;x.current=null,e&&(cancelAnimationFrame(e.raf),e.ctx.close().catch(()=>void 0))};(0,i.useEffect)(()=>()=>{m(),h(),c.current=!0;let e=a.current;e&&"inactive"!==e.state&&e.stop(),e?.stream.getTracks().forEach(e=>e.stop())},[]);let b=async()=>{m(),h();let n=a.current;a.current=null,n?.stream.getTracks().forEach(e=>e.stop());let l=new Blob(o.current,{type:"audio/webm"});o.current=[];let i=p.current;if(p.current=null,c.current||l.size<2e3){r("idle"),i?.(null);return}r("busy");try{let n=new FormData;n.append("file",l,"dictation.webm");let r=await fetch("/api/transcribe",{method:"POST",body:n}),s=await r.json();if(!r.ok||"string"!=typeof s.text){e(s.error??"не вдалося розпізнати"),i?.(null);return}let a=s.text.trim();a?i?i(a):t(a):(e("тиша — нічого не розпізналось"),i?.(null))}catch{e("сервер недоступний"),i?.(null)}finally{r("idle")}},g=async()=>{let t;if(f.current||a.current)return;f.current=!0;try{t=await navigator.mediaDevices.getUserMedia({audio:{channelCount:1}})}catch{e("немає доступу до мікрофона");return}finally{f.current=!1}let n=MediaRecorder.isTypeSupported("audio/webm;codecs=opus")?"audio/webm;codecs=opus":"audio/webm",l=new MediaRecorder(t,{mimeType:n});o.current=[],c.current=!1,l.ondataavailable=e=>{e.data.size&&o.current.push(e.data)},l.onstop=()=>{b()},l.start(250),a.current=l,(e=>{let t;try{t=new AudioContext}catch{return}let n=t.createAnalyser();n.fftSize=128,n.smoothingTimeConstant=.7,t.createMediaStreamSource(e).connect(n);let r=new Uint8Array(n.frequencyBinCount),l=()=>{if(!x.current)return;x.current.raf=requestAnimationFrame(l),n.getByteFrequencyData(r);let e=u.current;e&&function(e,t){let n=window.devicePixelRatio||1;(e.width!==56*n||e.height!==16*n)&&(e.width=56*n,e.height=16*n);let r=e.getContext("2d");if(!r)return;r.setTransform(n,0,0,n,0,0),r.clearRect(0,0,56,16);let l=Math.max(13,Math.floor(.65*t.length))/13;for(let e=0;e<13;e+=1){let n=Math.floor(e*l),i=Math.max(n+1,Math.floor((e+1)*l)),s=0;for(let e=n;e<i;e+=1)s+=t[e]??0;let a=s/(i-n)/255,o=Math.max(1.5,16*a);r.fillStyle=`rgba(198, 40, 40, ${(.35+.65*a).toFixed(3)})`,r.fillRect(4.3076923076923075*e+1,(16-o)/2,2.3076923076923075,o)}}(e,r)};x.current={ctx:t,raf:requestAnimationFrame(l)}})(t),s(0),r("rec"),d.current=window.setInterval(()=>{s(e=>{let t=e+1;return t>=120&&a.current?.state==="recording"&&a.current.stop(),t})},1e3)};return{phase:n,elapsed:l,canvasRef:u,start:g,stop:()=>new Promise(e=>{let t=a.current;t&&"recording"===t.state?(p.current=e,t.stop()):e(null)}),discard:()=>{c.current=!0,a.current?.state==="recording"&&a.current.stop()}}}let t1={"image/png":"png","image/jpeg":"jpg","image/jpg":"jpg","image/gif":"gif","image/webp":"webp"};function t5(e){return new Promise((t,n)=>{let r=new FileReader;r.onload=()=>{let l=String(r.result),i=l.indexOf(",");i<0?n(Error("не вдалося прочитати картинку")):t({base64:l.slice(i+1),mime:e.type||"image/png",preview:l})},r.onerror=()=>n(r.error??Error("не вдалося прочитати картинку")),r.onabort=()=>n(Error("читання картинки перервано")),r.readAsDataURL(e)})}function t2(e){let[t,n]=(0,i.useState)([]),r=t=>{if(!t.length)return;let r=[];for(let n of t){if(null===(t1[n.type]??null)){e.onError(`непідтримуваний формат картинки: ${n.name||n.type||"невідомий файл"}`);continue}if(n.size>0xa00000){e.onError(`${n.name||"картинка"}: завелика (ліміт 10 МБ)`);continue}r.push(n)}if(!r.length)return;let l=r.length<t.length;Promise.all(r.map(t5)).then(t=>{n(e=>[...e,...t]),l||e.onAdded?.()}).catch(t=>{e.onError(t instanceof Error?t.message:"помилка картинки")})};return{images:t,addFiles:r,handlePaste:e=>{let t=Array.from(e.clipboardData.items).filter(e=>e.type.startsWith("image/")).map(e=>e.getAsFile()).filter(e=>null!==e);t.length&&(e.preventDefault(),r(t))},removeAt:e=>n(t=>t.filter((t,n)=>n!==e)),clear:()=>n([])}}function t3({images:e,onRemove:t}){return e.length?(0,r.jsxs)("div",{className:"flex flex-wrap items-center gap-1.5",children:[e.map((e,n)=>(0,r.jsxs)("div",{className:"group/img relative",children:[(0,r.jsx)("img",{src:e.preview,alt:`прев'ю картинки ${n+1}`,className:"h-10 w-10 rounded border border-line object-cover"}),(0,r.jsx)("button",{type:"button",onClick:()=>t(n),"aria-label":`Прибрати картинку ${n+1}`,className:"absolute -right-1 -top-1 hidden h-4 w-4 items-center justify-center rounded-full border border-line bg-panel text-dim shadow-card hover:text-err group-hover/img:flex focus-visible:flex focus-visible:outline-none",children:(0,r.jsx)(l.A,{className:"h-2.5 w-2.5","aria-hidden":!0})})]},n)),(0,r.jsxs)("span",{className:"inline-flex items-center gap-1 text-[10.5px] font-semibold text-dim",children:[e.length," ",1===e.length?"картинка":"картинки"," ",(0,r.jsx)(ex.A,{className:"h-3 w-3","aria-hidden":!0})," шляхами до файлів"]})]}):null}function t4({onFiles:e,ariaLabel:t,className:n}){let l=(0,i.useRef)(null);return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("input",{ref:l,type:"file",accept:"image/*",multiple:!0,className:"hidden",onChange:t=>{e(Array.from(t.target.files??[])),t.target.value=""}}),(0,r.jsx)("button",{type:"button","aria-label":t,onClick:()=>l.current?.click(),className:n,children:(0,r.jsx)(ej.A,{className:"h-4 w-4","aria-hidden":!0})})]})}function t8({phase:e,elapsed:t,canvasRef:n,start:i,stop:s,discard:a,onText:o,busy:c=!1}){let d=()=>{c||("idle"===e?i():"rec"===e&&s().then(e=>{e&&o(e)}))};if("rec"===e)return(0,r.jsxs)("span",{className:"flex shrink-0 items-center gap-1",children:[(0,r.jsxs)("button",{type:"button","aria-label":"Зупинити запис і розпізнати",onClick:d,className:"flex items-center gap-1.5 rounded-[8px] border border-err/50 bg-[#fff2f2] px-2 py-2 text-[11px] font-bold text-err focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-err/40",children:[(0,r.jsx)("canvas",{ref:n,width:56,height:16,className:"h-4 w-14","aria-hidden":!0}),`${Math.floor(t/60)}:${String(t%60).padStart(2,"0")}`]}),(0,r.jsx)("button",{type:"button","aria-label":"Скасувати запис",onClick:a,className:"inline-flex items-center justify-center rounded-[8px] border border-line bg-panel p-2 text-dim hover:text-err focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40",children:(0,r.jsx)(l.A,{className:"h-3.5 w-3.5","aria-hidden":!0})})]});return(0,r.jsx)("button",{type:"button","aria-label":"busy"===e?"Розпізнаю…":"Надиктувати",title:"busy"===e?"розпізнаю…":"надиктувати (до 2 хв)",disabled:"busy"===e||c,onClick:d,className:"inline-flex shrink-0 items-center justify-center rounded-[8px] border border-line bg-panel p-2 text-dim hover:text-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40 disabled:opacity-60",children:"busy"===e?(0,r.jsx)(eL.A,{className:"h-4 w-4 animate-spin","aria-hidden":!0}):(0,r.jsx)(ek.A,{className:"h-4 w-4","aria-hidden":!0})})}function t6(e){return"claude-projects"===e.root?"сесія"===e.kind||"субагент"===e.kind:"codex-sessions"===e.root}function t9({file:e}){let t=function(e,t){let[n,r]=(0,i.useState)(null);return(0,i.useEffect)(()=>{if(null===e&&!t)return;let n=!0,l=async()=>{try{let l=new URLSearchParams;null!==e&&l.set("pid",String(e)),t&&l.set("path",t);let i=await fetch(`/api/tmux?${l.toString()}`);if(!i.ok)return;let s=await i.json();n&&r(s.target??null)}catch{}};l();let i=setInterval(l,5e3);return()=>{n=!1,clearInterval(i)}},[e,t]),null!==e||t?n:null}(e.pid,t6(e)?e.path:void 0),[n,s]=(0,i.useState)(()=>sessionStorage.getItem("llvDraft:"+e.path)??""),a=(0,i.useRef)(n),o=t=>{let n="function"==typeof t?t(a.current):t;(a.current=n,s(n),n)?sessionStorage.setItem("llvDraft:"+e.path,n):sessionStorage.removeItem("llvDraft:"+e.path)},[c,d]=(0,i.useState)(!1),[u,x]=(0,i.useState)(!1),[p,f]=(0,i.useState)(!1),[m,h]=(0,i.useState)(null),[b,g]=(0,i.useState)([]),v=(0,i.useRef)(null),w=t2({onError:e=>h({kind:"err",text:e}),onAdded:()=>h(null)}),j=e=>{o(t=>t?t.trimEnd()+" "+e:e),h(null),v.current?.focus()},y=t0({onError:e=>h({kind:"err",text:e}),onUnclaimedText:j});(0,i.useLayoutEffect)(()=>{let e=v.current;e&&(e.style.height="0px",e.style.height=Math.min(e.scrollHeight+2,160)+"px")},[n]),(0,i.useEffect)(()=>g(function(e){try{let t=JSON.parse(sessionStorage.getItem("llvSent:"+e)??"[]");return Array.isArray(t)?t:[]}catch{return[]}}(e.path)),[e.path]),(0,i.useEffect)(()=>{let t=()=>g(t=>{let n=t.filter(t=>"pane"===t.via?1e3*e.mtime<t.at+2e3&&Date.now()-t.at<6e5:Date.now()-t.at<9e4);return n.length!==t.length&&sessionStorage.setItem("llvSent:"+e.path,JSON.stringify(n)),n.length!==t.length?n:t});t();let n=setInterval(t,5e3);return()=>clearInterval(n)},[e.mtime,e.path]);let N=t6(e);if(null===t&&!N)return null;let k=null===t,S=k&&"claude-projects"===e.root&&"субагент"===e.kind,C=t=>{g(t),sessionStorage.setItem("llvSent:"+e.path,JSON.stringify(t))},$=async t=>{let r=t??n;if(!c&&!u&&(r.trim()||w.images.length)){d(!0),h(null);try{let t=await fetch("/api/tmux",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({pid:e.pid??void 0,path:e.path,text:r,images:w.images.map(e=>({base64:e.base64,mime:e.mime}))})}),n=await t.json();if(!t.ok||!n.ok)return void h({kind:"err",text:n.error??"не вдалося надіслати"});let l=w.images.length,i={id:Date.now(),text:r.trim()||(l?`${l} ${1===l?"картинка":"картинки"}`:""),at:Date.now(),via:n.spawned?"spawn":"pane"};C([...b,i].slice(-8)),o(""),w.clear(),h({kind:"ok",text:n.spawned?`запущено агента в tmux ${n.target??""}`:n.imagePaths?.length?`надіслано ${n.imagePaths.length} шлях(и)`:"надіслано"}),v.current?.focus()}catch{h({kind:"err",text:"сервер недоступний"})}finally{d(!1)}}},A=async()=>{if(!c&&!u){x(!0);try{let e=await y.stop();if(null===e)return;let t=a.current?a.current.trimEnd()+" "+e:e;o(t),await $(t)}finally{x(!1)}}},E=async()=>{if(!p){f(!0),h(null);try{let t=await fetch("/api/tmux",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({action:"interrupt",path:e.path})}),n=await t.json();if(!t.ok||!n.ok)return void h({kind:"err",text:n.error??"не вдалося перервати"});h({kind:"ok",text:"надіслано Escape — агент перервано"})}catch{h({kind:"err",text:"сервер недоступний"})}finally{f(!1)}}},M="rec"===y.phase,R="busy"===y.phase,T=!c&&!u&&!R&&(M||!!n.trim()||w.images.length>0),P=c||u;return(0,r.jsxs)("form",{onSubmit:e=>{e.preventDefault(),$()},className:"flex shrink-0 flex-col gap-1.5 border-t border-line bg-[#fbfbfd] px-2.5 py-2","aria-label":k?"Запустити агента з промптом у tmux":`Надіслати повідомлення агенту в tmux ${t}`,children:[b.length?(0,r.jsx)("div",{className:"flex flex-col gap-0.5","aria-label":"Черга надісланих повідомлень",children:b.map(e=>(0,r.jsxs)("div",{className:"flex items-center justify-end gap-1.5",children:[(0,r.jsx)("span",{className:"min-w-0 max-w-[85%] truncate rounded-[10px] rounded-br-[3px] bg-[#ecebfb] px-2 py-0.5 text-[11px] text-[#333]",title:e.text,children:e.text}),(0,r.jsxs)("span",{className:"inline-flex shrink-0 items-center gap-0.5 text-[9.5px] text-dim",children:["spawn"===e.via?(0,r.jsx)(eS.A,{className:"h-2.5 w-2.5","aria-hidden":!0}):(0,r.jsx)(ex.A,{className:"h-2.5 w-2.5","aria-hidden":!0}),new Date(e.at).toLocaleTimeString("uk",{hour12:!1,hour:"2-digit",minute:"2-digit"})]}),(0,r.jsx)("button",{type:"button","aria-label":"Прибрати з черги",className:"inline-flex shrink-0 items-center rounded px-0.5 text-dim hover:text-err focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40",onClick:()=>C(b.filter(t=>t.id!==e.id)),children:(0,r.jsx)(l.A,{className:"h-3 w-3","aria-hidden":!0})})]},e.id))}):null,(0,r.jsx)("textarea",{ref:v,value:n,rows:1,onChange:e=>o(e.target.value),onPaste:w.handlePaste,onKeyDown:e=>{"Enter"!==e.key||e.shiftKey||e.nativeEvent.isComposing||(e.preventDefault(),"rec"===y.phase?A():$())},placeholder:S?"написати — передам через кореневу сесію…":k?"промпт — агент запуститься в tmux…":"написати агенту…","aria-label":"Текст для агента",disabled:P,className:"w-full resize-none overflow-y-auto rounded-[10px] border border-line bg-panel px-2.5 py-1.5 text-[12.5px] leading-[18px] text-[#222] placeholder:text-dim focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40 disabled:opacity-60"}),(0,r.jsxs)("div",{className:"flex items-center justify-between gap-1.5",children:[(0,r.jsxs)("div",{className:"flex min-w-0 items-center gap-1.5",children:[(0,r.jsx)("span",{className:"inline-flex min-w-0 items-center gap-1 rounded-full bg-chip px-1.5 py-1 font-mono text-[9.5px] font-semibold text-[#555]",title:S?"передасться через кореневу сесію гілки":k?"нове tmux-вікно з відновленим агентом":`tmux ${t}`,children:S?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(ep.A,{className:"h-3 w-3 shrink-0","aria-hidden":!0})," корінь"]}):k?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(eS.A,{className:"h-3 w-3 shrink-0","aria-hidden":!0})," resume"]}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(eA.A,{className:"h-3 w-3 shrink-0","aria-hidden":!0})," ",(0,r.jsx)("span",{className:"truncate",children:t})]})}),k?null:(0,r.jsx)("button",{type:"button","aria-label":"Перервати агента (Escape)",title:"надіслати Escape у пейн агента",disabled:p,onClick:()=>void E(),className:"inline-flex shrink-0 items-center justify-center rounded-[8px] border border-line bg-panel p-2 text-dim hover:border-err/40 hover:text-err focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40 disabled:opacity-50",children:p?(0,r.jsx)(eL.A,{className:"h-4 w-4 animate-spin","aria-hidden":!0}):(0,r.jsx)(e$.A,{className:"h-4 w-4",fill:"currentColor","aria-hidden":!0})})]}),(0,r.jsxs)("div",{className:"flex shrink-0 items-center gap-1.5",children:[(0,r.jsx)(t8,{...y,busy:u,onText:j}),(0,r.jsx)(t4,{ariaLabel:"Додати картинки",className:"inline-flex shrink-0 items-center justify-center rounded-[8px] border border-line bg-panel p-2 text-dim hover:text-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40",onFiles:w.addFiles}),(0,r.jsx)("button",{type:M?"button":"submit",onClick:M?()=>void A():void 0,disabled:!T,"aria-label":M?"Зупинити запис і надіслати":k?"Запустити агента":"Надіслати агенту",title:M?"зупинити запис і надіслати":void 0,className:`inline-flex shrink-0 items-center justify-center rounded-[8px] border p-2 text-white focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/50 disabled:opacity-40 ${M?"border-err bg-err hover:opacity-90":"border-accent bg-accent hover:opacity-90"}`,children:c||u?(0,r.jsx)(eL.A,{className:"h-4 w-4 animate-spin","aria-hidden":!0}):(0,r.jsx)(eS.A,{className:"h-4 w-4","aria-hidden":!0})})]})]}),(0,r.jsx)(t3,{images:w.images,onRemove:w.removeAt}),m?(0,r.jsx)("span",{className:`truncate text-[10.5px] font-semibold ${"ok"===m.kind?"text-ok":"text-err"}`,children:m.text}):null]})}let t7=()=>void 0,ne={live:{section:"border-ok/60 shadow-[0_0_0_3px_rgba(47,158,68,0.16)]",header:"bg-[#eef8f0]"},waiting:{section:"border-[#e0ae45]/60 shadow-[0_0_0_3px_rgba(224,174,69,0.2)]",header:"bg-[#fff7e6]",glow:"#e0ae45"},returned:{section:"border-accent/50 shadow-[0_0_0_3px_rgba(90,81,224,0.15)]",header:"bg-[#f1f0fc]",glow:"#7a6ff0"},stalled:{section:"border-err/50 shadow-[0_0_0_3px_rgba(198,40,40,0.13)]",header:"bg-[#fdf0f0]",glow:"#d76a6a"},done:{section:"border-line",header:"bg-[#f4f4f6] text-dim opacity-80 saturate-50"}},nt={live:"працює",waiting:"закінчив хід — чекає відповіді",returned:"повернувся з результатом",stalled:"перервано або чекає дозволу",done:"завершено — можна прибрати"};function nn({file:e,files:t,tasks:n,onSelect:a,isRoot:o,onClose:c,dragHandle:d,noComposer:u,banner:x}){let p=(0,i.useRef)(null),f=F(e),m=X(e),h=ne[m];return(0,i.useEffect)(()=>{if(p.current){var t,n;return t=e.path,n=p.current,K.set(t,n),()=>{K.get(t)===n&&K.delete(t)}}},[e.path]),(0,i.useEffect)(()=>{if(p.current){var t;return t=p.current,eJ.set(e.path,{el:t,file:e}),()=>{eJ.get(e.path)?.el===t&&eJ.delete(e.path)}}},[e]),(0,r.jsxs)("section",{ref:p,"data-pan-ignore":!0,"data-link-path":e.path,className:`relative flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden rounded-[10px] border bg-panel shadow-card ${o?"border-t-4":"border-t-2"} ${h.section} ${h.glow?"pane-attention":""}`,style:{..."done"===m?{borderTopColor:"#c9c9d1"}:{borderTopColor:I(e).color},...h.glow?{"--pane-glow":h.glow}:null},children:[(0,r.jsxs)("header",{className:`flex h-10 shrink-0 items-center gap-1.5 border-b border-line px-2.5 ${h.header} ${d?"cursor-grab active:cursor-grabbing":""}`,...d,children:[(0,r.jsx)("span",{className:`h-2 w-2 shrink-0 rounded-full ${M(e.activity)}`,title:nt[m]}),e.model?(0,r.jsx)("span",{className:"shrink-0 rounded-full px-1.5 py-0.5 font-mono text-[9.5px] font-semibold",style:{backgroundColor:D(e).soft,color:D(e).color},title:[f.label,O(e)].filter(Boolean).join(" \xb7 "),children:e.model}):(0,r.jsx)("span",{className:"inline-flex shrink-0 items-center rounded-full px-2 py-0.5 text-[10px] font-bold",style:f.style,children:f.label}),e.ctx?(0,r.jsx)(tG,{ctx:e.ctx}):null,e.worktree?(0,r.jsxs)("span",{className:"inline-flex shrink-0 items-center gap-0.5 rounded-full border border-line/80 px-1.5 py-0.5 font-mono text-[9.5px] text-dim",title:`Ворк-дерево ${e.worktree}`,children:[(0,r.jsx)(ea.A,{className:"h-2.5 w-2.5","aria-hidden":!0})," ",e.worktree]}):null,e.plan?(0,r.jsx)(tK,{plan:e.plan}):null,e.goal?(0,r.jsx)(tZ,{goal:e.goal}):null,o?null:(0,r.jsxs)("span",{className:"inline-flex shrink-0 items-center gap-0.5 text-[10px] text-dim",title:e.handoff?"агент, породжений хендоффом цієї розмови":"гілка цієї розмови",children:[(0,r.jsx)(eo.A,{className:"h-3 w-3","aria-hidden":!0})," ",e.handoff?"хендофф":e.kind]}),(0,r.jsx)("span",{className:"min-w-0 flex-1 truncate text-[12px] font-semibold",title:s(e.title),children:s(e.title,90)}),(0,r.jsx)(eG,{file:e,compact:!0}),(0,r.jsx)(eX,{file:e,onDeleted:c}),c?(0,r.jsx)("button",{className:"inline-flex shrink-0 items-center rounded-[8px] border border-line bg-bg px-1.5 py-0.5 text-dim hover:border-err/40 hover:text-err focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40","aria-label":`Прибрати колонку ${s(e.title,60)}`,onClick:c,children:(0,r.jsx)(l.A,{className:"h-3 w-3","aria-hidden":!0})}):null]}),x??null,n.length?(0,r.jsx)(eW,{className:"shrink-0 border-b border-line bg-[#fbfbfd]",enter:"fade",children:n.map(e=>(0,r.jsx)("div",{"data-flip-key":e.path,children:(0,r.jsx)(nr,{file:e,files:t,onSelect:a})},e.path))}):null,(0,r.jsx)(tW,{file:e,files:t,onSelect:a,showSvc:!1,lineFilter:"",onStatus:t7,paused:!1,follow:!0,setFollow:t7,compact:!0}),u?null:(0,r.jsx)(t9,{file:e}),("claude-projects"===e.root||"codex-sessions"===e.root)&&e.path.endsWith(".jsonl")?(0,r.jsx)(e1,{file:e,paneRef:p}):null]})}function nr({file:e,files:t,onSelect:n}){let[l,a]=(0,i.useState)(!1),o=s(e.cmdDesc||e.title,80);return(0,r.jsxs)("div",{className:"border-t border-line first:border-t-0",children:[(0,r.jsxs)("div",{className:"flex h-7 items-center gap-1.5 pl-2 pr-2.5",children:[(0,r.jsxs)("button",{className:"flex h-full min-w-0 flex-1 items-center gap-1.5 rounded-[6px] text-left hover:bg-bg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40","aria-expanded":l,"aria-label":`${l?"Згорнути":"Розгорнути"} фонову задачу ${o}`,onClick:()=>a(e=>!e),children:[(0,r.jsx)(eb.A,{className:`h-3.5 w-3.5 shrink-0 text-dim transition-transform ${l?"rotate-90":""}`,"aria-hidden":!0}),(0,r.jsx)("span",{className:`h-1.5 w-1.5 shrink-0 rounded-full ${M(e.activity)}`}),(0,r.jsx)("span",{className:"min-w-0 flex-1 truncate text-[11.5px] font-semibold",title:s(e.title),children:o})]}),(0,r.jsx)(eG,{file:e,compact:!0})]}),l?(0,r.jsx)("div",{className:"flex h-[220px] flex-col border-t border-dashed border-line bg-bg/60",children:(0,r.jsx)(tW,{file:e,files:t,onSelect:n,showSvc:!1,lineFilter:"",onStatus:t7,paused:!1,follow:!0,setFollow:t7,compact:!0})}):null]})}let nl=[{key:"claude",label:"Claude"},{key:"codex",label:"Codex"}],ni=(e,t)=>`llvDraftPane:${e}:${t}`;function ns(e,t){return sessionStorage.getItem(ni(e,t))??""}function na(e,t,n){n?sessionStorage.setItem(ni(e,t),n):sessionStorage.removeItem(ni(e,t))}function no({draftId:e,project:t,files:n,onClose:s,onSpawned:a}){let[o,c]=(0,i.useState)(()=>"codex"===ns(e,"engine")?"codex":"claude"),[d,u]=(0,i.useState)(()=>ns(e,"cwd")),[x,p]=(0,i.useState)([]),[f,m]=(0,i.useState)(()=>ns(e,"text")),[h,b]=(0,i.useState)(()=>(function(e){try{let t=JSON.parse(ns(e,"boot")||"null");return t&&"number"==typeof t.at&&"string"==typeof t.prompt?t:null}catch{return null}})(e)),[g,v]=(0,i.useState)(!1),[w,j]=(0,i.useState)(!1),[y,N]=(0,i.useState)(!1),[k,S]=(0,i.useState)(null),C=(0,i.useRef)(null),$=(0,i.useRef)(null),A=(0,i.useRef)(f),E=t=>{let n="function"==typeof t?t(A.current):t;A.current=n,m(n),na(e,"text",n)},M=t2({onError:e=>S({kind:"err",text:e}),onAdded:()=>S(null)}),P=e=>{E(t=>t?t.trimEnd()+" "+e:e),S(null),C.current?.focus()},_=t0({onError:e=>S({kind:"err",text:e}),onUnclaimedText:P});(0,i.useEffect)(()=>{let n=!1;return fetch("/api/spawn?project="+encodeURIComponent(t)).then(e=>e.json()).then(t=>{!n&&Array.isArray(t.dirs)&&(p(t.dirs),u(n=>{let r=n||t.dirs?.[0]||"";return r!==n&&na(e,"cwd",r),r}))}).catch(()=>{}),()=>{n=!0}},[t,e]),(0,i.useLayoutEffect)(()=>{let e=C.current;e&&(e.style.height="0px",e.style.height=Math.min(e.scrollHeight+2,160)+"px")},[f]),(0,i.useEffect)(()=>{if(!h)return;let e=$.current,t=h.path?n.find(e=>e.path===h.path):n.find(t=>"codex"===t.engine&&"codex-sessions"===t.root&&!t.parent&&t.mtime>=h.at/1e3-30&&(!e||!e.has(t.path)));t&&a(t)},[n,h,a]),(0,i.useEffect)(()=>{if(!h)return;let e=h.at+9e4-Date.now();if(e<=0)return void N(!0);let t=window.setTimeout(()=>N(!0),e);return()=>window.clearTimeout(t)},[h]);let I=async t=>{let r=t??f;if(!g&&!w&&!h){if(!d.trim())return void S({kind:"err",text:"вкажи робочу директорію"});if(r.trim()||M.images.length){v(!0),S(null);try{var l;let t=await fetch("/api/spawn",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({engine:o,cwd:d.trim(),prompt:r,images:M.images.map(e=>({base64:e.base64,mime:e.mime}))})}),i=await t.json();if(!t.ok||!i.ok)return void S({kind:"err",text:i.error??"не вдалося запустити"});$.current=new Set(n.map(e=>e.path)),l={at:Date.now(),target:i.target??"",path:i.path??null,prompt:r.trim()},b(l),na(e,"boot",l?JSON.stringify(l):""),E(""),M.clear()}catch{S({kind:"err",text:"сервер недоступний"})}finally{v(!1)}}}},z=async()=>{if(!g&&!w){j(!0);try{let e=await _.stop();if(null===e)return;let t=A.current?A.current.trimEnd()+" "+e:e;E(t),await I(t)}finally{j(!1)}}},L=R[o]??T,D="rec"===_.phase,O="busy"===_.phase,F=g||w||!!h,U=!F&&!O&&(D||!!f.trim()||M.images.length>0),q="draft-dirs-"+e;return(0,r.jsxs)("section",{"data-pan-ignore":!0,className:"relative flex h-full min-h-0 min-w-0 flex-1 flex-col overflow-hidden rounded-[10px] border border-t-4 border-line bg-panel shadow-card",style:{borderTopColor:L.color},"aria-label":"Чернетка нової розмови з агентом",children:[(0,r.jsxs)("header",{className:"flex h-10 shrink-0 items-center gap-1.5 border-b border-line px-2.5",style:{backgroundColor:L.soft},children:[(0,r.jsx)("span",{className:"h-2 w-2 shrink-0 rounded-full bg-[#c9c9d1]",title:"агент ще не запущений"}),(0,r.jsx)("div",{className:"flex shrink-0 items-center gap-1",role:"radiogroup","aria-label":"Двигун агента",children:nl.map(({key:t,label:n})=>{let l=o===t,i=R[t]??T;return(0,r.jsx)("button",{type:"button",role:"radio","aria-checked":l,disabled:F,onClick:()=>{c(t),na(e,"engine",t)},style:l?{backgroundColor:"#fff",color:i.color,borderColor:i.color}:void 0,className:`rounded-full border px-2 py-0.5 text-[10.5px] font-bold focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40 disabled:opacity-60 ${l?"":"border-transparent bg-transparent text-dim hover:text-ink"}`,children:n},t)})}),(0,r.jsx)("span",{className:"min-w-0 flex-1 truncate text-[12px] font-semibold text-dim",children:"нова розмова"}),(0,r.jsx)("button",{className:"inline-flex shrink-0 items-center rounded-[8px] border border-line bg-bg px-1.5 py-0.5 text-dim hover:border-err/40 hover:text-err focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40","aria-label":"Прибрати чернетку розмови",onClick:s,children:(0,r.jsx)(l.A,{className:"h-3 w-3","aria-hidden":!0})})]}),(0,r.jsxs)("div",{className:"flex shrink-0 items-center gap-1.5 border-b border-line bg-[#fbfbfd] px-2.5 py-1.5",children:[(0,r.jsx)("span",{className:"shrink-0 text-[10px] font-semibold text-dim",children:"директорія"}),(0,r.jsx)("input",{value:d,disabled:F,onChange:t=>{var n;u(n=t.target.value),na(e,"cwd",n)},list:q,placeholder:"/home/…/Projects/…","aria-label":"Робоча директорія агента",className:"min-w-0 flex-1 rounded-[6px] border border-line bg-panel px-2 py-1 font-mono text-[11px] text-ink focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40 disabled:opacity-60"}),(0,r.jsx)("datalist",{id:q,children:x.map(e=>(0,r.jsx)("option",{value:e},e))})]}),(0,r.jsx)("div",{className:"flex min-h-0 flex-1 flex-col overflow-y-auto px-4 py-4",children:h?(0,r.jsxs)("div",{className:"flex flex-1 flex-col justify-end gap-3",children:[(0,r.jsx)("div",{className:"flex justify-end",children:(0,r.jsx)("span",{className:"min-w-0 max-w-[85%] whitespace-pre-wrap rounded-[10px] rounded-br-[3px] bg-[#ecebfb] px-2.5 py-1.5 text-[12px] text-[#333]",children:h.prompt||"(картинки)"})}),(0,r.jsxs)("div",{className:"flex items-center gap-2 text-[11.5px] font-semibold text-dim",children:[(0,r.jsx)(eL.A,{className:"h-3.5 w-3.5 animate-spin","aria-hidden":!0}),(0,r.jsxs)("span",{children:["агент запущений у tmux ",h.target,"— чекаю, поки розмова з'явиться тут…"]})]}),y?(0,r.jsxs)("div",{className:"text-[11px] text-dim",children:["Щось довго. Перевір вікно tmux ",h.target,"— щойно транскрипт з'явиться, панель підхопить його сама."]}):null]}):(0,r.jsxs)("div",{className:"flex flex-1 flex-col items-center justify-center gap-2 text-center",children:[(0,r.jsx)("span",{className:"rounded-full px-3 py-1 text-[13px] font-bold",style:{backgroundColor:L.soft,color:L.color},children:"claude"===o?"Claude":"Codex"}),(0,r.jsx)("div",{className:"max-w-[360px] text-[12px] text-dim",children:"Обери двигун і директорію, напиши перший промпт — агент запуститься в tmux, і розмова продовжиться в цій самій панелі."})]})}),(0,r.jsxs)("form",{onSubmit:e=>{e.preventDefault(),I()},className:"flex shrink-0 flex-col gap-1.5 border-t border-line bg-[#fbfbfd] px-2.5 py-2","aria-label":"Перший промпт для нового агента",children:[(0,r.jsx)("textarea",{ref:C,value:f,rows:1,onChange:e=>E(e.target.value),onPaste:M.handlePaste,onKeyDown:e=>{"Enter"!==e.key||e.shiftKey||e.nativeEvent.isComposing||(e.preventDefault(),"rec"===_.phase?z():I())},placeholder:"перший промпт — агент запуститься в tmux…","aria-label":"Текст першого промпта",disabled:F,className:"w-full resize-none overflow-y-auto rounded-[10px] border border-line bg-panel px-2.5 py-1.5 text-[12.5px] leading-[18px] text-[#222] placeholder:text-dim focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40 disabled:opacity-60"}),(0,r.jsxs)("div",{className:"flex items-center justify-between gap-1.5",children:[(0,r.jsxs)("span",{className:"inline-flex min-w-0 items-center gap-1 rounded-full bg-chip px-1.5 py-1 font-mono text-[9.5px] font-semibold text-[#555]",title:"нове tmux-вікно зі свіжим агентом",children:[(0,r.jsx)(eS.A,{className:"h-3 w-3 shrink-0","aria-hidden":!0})," новий агент"]}),(0,r.jsxs)("div",{className:"flex shrink-0 items-center gap-1.5",children:[(0,r.jsx)(t8,{..._,busy:w,onText:P}),(0,r.jsx)(t4,{ariaLabel:"Додати картинки до промпта",className:"inline-flex shrink-0 items-center justify-center rounded-[8px] border border-line bg-panel p-2 text-dim hover:text-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40",onFiles:M.addFiles}),(0,r.jsx)("button",{type:D?"button":"submit",onClick:D?()=>void z():void 0,disabled:!U,"aria-label":D?"Зупинити запис і запустити агента":"Запустити агента",style:D?void 0:{backgroundColor:L.color,borderColor:L.color},className:`inline-flex shrink-0 items-center justify-center rounded-[8px] border p-2 text-white focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/50 disabled:opacity-40 ${D?"border-err bg-err hover:opacity-90":"hover:opacity-90"}`,children:g||w?(0,r.jsx)(eL.A,{className:"h-4 w-4 animate-spin","aria-hidden":!0}):(0,r.jsx)(eS.A,{className:"h-4 w-4","aria-hidden":!0})})]})]}),(0,r.jsx)(t3,{images:M.images,onRemove:M.removeAt}),k?(0,r.jsx)("span",{className:`truncate text-[10.5px] font-semibold ${"ok"===k.kind?"text-ok":"text-err"}`,children:k.text}):null]})]})}var nc=n(9707),nd=n(1906),nu=n(1285),nx=n(8962);let np=["low","medium","high","xhigh"],nf={implementer:{engine:"claude",model:null,effort:null},reviewer:{engine:"codex",model:null,effort:"xhigh"}};function nm({label:e,role:t,onChange:n}){return(0,r.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,r.jsx)("span",{className:"w-[86px] shrink-0 text-[10.5px] font-semibold text-dim",children:e}),(0,r.jsxs)("select",{value:t.engine,"aria-label":`Двигун: ${e}`,className:"h-7 rounded-[8px] border border-line bg-bg px-1.5 text-[11.5px] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40",onChange:e=>n({...t,engine:e.target.value,effort:null}),children:[(0,r.jsx)("option",{value:"claude",children:"Claude"}),(0,r.jsx)("option",{value:"codex",children:"Codex"})]}),(0,r.jsx)("input",{value:t.model??"",placeholder:"модель (дефолт)","aria-label":`Модель: ${e}`,className:"h-7 w-0 min-w-0 flex-1 rounded-[8px] border border-line bg-bg px-1.5 font-mono text-[11px] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40",onChange:e=>n({...t,model:e.target.value.trim()||null})}),"codex"===t.engine?(0,r.jsxs)("select",{value:t.effort??"","aria-label":`Reasoning effort: ${e}`,className:"h-7 rounded-[8px] border border-line bg-bg px-1.5 text-[11.5px] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40",onChange:e=>n({...t,effort:e.target.value||null}),children:[(0,r.jsx)("option",{value:"",children:"effort: дефолт"}),np.map(e=>(0,r.jsx)("option",{value:e,children:e},e))]}):null]})}function nh({file:e,onClose:t}){let[n,l]=(0,i.useState)([]),[s,a]=(0,i.useState)(null),[o,c]=(0,i.useState)(nf),[d,u]=(0,i.useState)(!1),[x,p]=(0,i.useState)("head"),[f,m]=(0,i.useState)("auto"),[h,b]=(0,i.useState)("headless"),[g,v]=(0,i.useState)(5),[w,j]=(0,i.useState)(!1),[y,N]=(0,i.useState)(null);(0,i.useEffect)(()=>{let e=!1;return fetch("/api/flows").then(e=>e.json()).then(t=>{!e&&Array.isArray(t.presets)&&t.presets.length&&(l(t.presets),a(e=>e??t.presets[0].name),c({implementer:t.presets[0].implementer,reviewer:t.presets[0].reviewer}))}).catch(()=>{}),()=>{e=!0}},[]);let k=async()=>{if(!w){j(!0),N(null);try{let n=await fetch("/api/flows",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({implementerPath:e.path,...d||!s?{roles:o}:{preset:s},baseMode:x,mode:f,reviewerMode:h,roundLimit:g})});if(!n.ok){let e=await n.json().catch(()=>null);N(e?.error??`не вдалося створити флоу (${n.status})`);return}t()}catch{N("сервер недоступний")}finally{j(!1)}}};return(0,r.jsxs)("div",{"data-scheme-ui":!0,className:"flex w-[420px] flex-col gap-2.5 rounded-[12px] border border-line bg-panel p-3 shadow-[0_10px_36px_rgb(20_20_30/0.18)]",onKeyDown:e=>{"Escape"===e.key&&t()},children:[(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("span",{className:"text-[12.5px] font-bold",children:"Запустити флоу"}),(0,r.jsx)("span",{className:"min-w-0 flex-1 truncate text-[10.5px] text-dim",children:"implement → review \xb7 ця розмова стає виконавцем"})]}),n.length?(0,r.jsxs)("label",{className:"flex flex-col gap-1 text-[10.5px] font-semibold text-dim",children:["пресет",(0,r.jsx)("select",{value:s??"",className:"h-8 rounded-[8px] border border-line bg-bg px-2 text-[12px] font-normal text-ink focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40",onChange:e=>{var t;let r;return a(t=e.target.value),void((r=n.find(e=>e.name===t))&&c({implementer:r.implementer,reviewer:r.reviewer}))},children:n.map(e=>(0,r.jsx)("option",{value:e.name,children:e.name},e.name))})]}):null,(0,r.jsx)("button",{className:"self-start text-[10.5px] font-semibold text-dim hover:text-accent focus-visible:outline-none","aria-expanded":d,onClick:()=>u(e=>!e),children:d?"▾ ролі вручну":"▸ ролі вручну (модель / effort)"}),d?(0,r.jsxs)("div",{className:"flex flex-col gap-1.5 rounded-[10px] border border-dashed border-line bg-bg/50 p-2",children:[(0,r.jsx)(nm,{label:"виконавець",role:o.implementer,onChange:e=>c(t=>({...t,implementer:e}))}),(0,r.jsx)(nm,{label:"ревʼюер",role:o.reviewer,onChange:e=>c(t=>({...t,reviewer:e}))})]}):null,(0,r.jsxs)("div",{className:"grid grid-cols-2 gap-2",children:[(0,r.jsxs)("label",{className:"flex flex-col gap-1 text-[10.5px] font-semibold text-dim",children:["база діфу",(0,r.jsxs)("select",{value:x,className:"h-8 rounded-[8px] border border-line bg-bg px-2 text-[11.5px] font-normal text-ink focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40",onChange:e=>p(e.target.value),children:[(0,r.jsx)("option",{value:"head",children:"від поточного HEAD"}),(0,r.jsx)("option",{value:"merge-base",children:"від merge-base з main"})]})]}),(0,r.jsxs)("label",{className:"flex flex-col gap-1 text-[10.5px] font-semibold text-dim",children:["ревʼюер",(0,r.jsxs)("select",{value:h,className:"h-8 rounded-[8px] border border-line bg-bg px-2 text-[11.5px] font-normal text-ink focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40",onChange:e=>b(e.target.value),children:[(0,r.jsx)("option",{value:"headless",children:"headless (без панелі)"}),(0,r.jsx)("option",{value:"pane",children:"tmux-панель"})]})]}),(0,r.jsxs)("label",{className:"flex flex-col gap-1 text-[10.5px] font-semibold text-dim",children:["переходи",(0,r.jsxs)("select",{value:f,className:"h-8 rounded-[8px] border border-line bg-bg px-2 text-[11.5px] font-normal text-ink focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40",onChange:e=>m(e.target.value),children:[(0,r.jsx)("option",{value:"auto",children:"авто"}),(0,r.jsx)("option",{value:"manual",children:"вручну (гейт на кожен крок)"})]})]}),(0,r.jsxs)("label",{className:"flex flex-col gap-1 text-[10.5px] font-semibold text-dim",children:["ліміт раундів",(0,r.jsx)("input",{type:"number",min:1,max:20,value:g,className:"h-8 rounded-[8px] border border-line bg-bg px-2 text-[11.5px] font-normal text-ink focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40",onChange:e=>v(Math.max(1,Math.min(20,Number(e.target.value)||5)))})]})]}),(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[y?(0,r.jsx)("span",{className:"min-w-0 flex-1 truncate text-[10.5px] font-semibold text-err",children:y}):(0,r.jsx)("span",{className:"flex-1"}),(0,r.jsx)("button",{className:"rounded-[8px] border border-line bg-bg px-2.5 py-1.5 text-[11.5px] font-semibold text-dim hover:text-ink focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40",onClick:t,children:"Скасувати"}),(0,r.jsx)("button",{className:"rounded-[8px] border border-accent bg-accent px-3 py-1.5 text-[12px] font-bold text-white hover:opacity-90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/50 disabled:opacity-40",disabled:w,onClick:()=>void k(),children:w?"створюю…":"▶ Запустити"})]})]})}var nb=n(2749);let ng={waiting_ready:{label:"Почати ревью",action:"advance"},spawn_pending:{label:"Заспавнити ревʼюера",action:"advance"},relay_pending:{label:"Передати зауваження",action:"advance"},needs_decision:{label:"Повторити раунд",action:"retry-round"},done_comment:{label:"Ще коло",action:"another-round"}},nv=new Set(["spawning","reviewing","relaying","fixing"]);function nw({flow:e,onFocusRound:t}){let[n,s]=(0,i.useState)(!1),[a,o]=(0,i.useState)(null),c=async(t,r)=>{if(n)return;s(!0),o(null);let l=await C(e.id,{action:t,...r});l&&o(l),s(!1)},d=ng[e.state],u=N.has(e.state),x="closed"===e.state||"approved"===e.state;return(0,r.jsxs)("div",{"data-scheme-ui":!0,className:`pointer-events-auto flex h-8 max-w-full items-center gap-1.5 overflow-x-auto rounded-full border bg-panel px-2 shadow-card ${u?"border-[#e0ae45]/70":"border-line"}`,children:[(0,r.jsx)("span",{className:`h-2 w-2 shrink-0 rounded-full ${"approved"===e.state?"bg-ok":"needs_decision"===e.state?"bg-err":"paused"===e.state?"bg-[#e0ae45]":nv.has(e.state)?"bg-ok animate-pulse":"bg-[#9a9aa4]"}`,"aria-hidden":!0}),(0,r.jsx)("span",{className:"shrink-0 text-[10.5px] font-bold tracking-wide text-dim",children:"ФЛОУ"}),(0,r.jsxs)("span",{className:"shrink-0 text-[11px] font-semibold",title:e.stateDetail??void 0,children:[y[e.state],e.stateDetail?(0,r.jsxs)("span",{className:"text-dim",children:[" \xb7 ",e.stateDetail]}):null]}),e.rounds.length?(0,r.jsx)("span",{className:"flex shrink-0 items-center gap-1","aria-label":"Раунди ревью",children:e.rounds.map(e=>{let n=S(e.verdict),l=null===e.verdict&&!e.error;return(0,r.jsxs)("button",{className:`inline-flex h-5 items-center gap-0.5 rounded-full px-1.5 text-[10px] font-bold focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40 ${l?"animate-pulse":""}`,style:{backgroundColor:n.soft,color:n.color},title:e.error?`Раунд ${e.n}: ${e.error}`:e.verdict?`Раунд ${e.n}: ${e.verdict}${null!=e.findingsCount?` \xb7 ${e.findingsCount} знахідок`:""}`:`Раунд ${e.n}: триває`,onClick:()=>t?.(e.n),children:["R",e.n,e.verdict?(0,r.jsx)("span",{children:k[e.verdict]}):l?(0,r.jsx)("span",{children:"⏳"}):(0,r.jsx)("span",{children:"!"}),null!=e.findingsCount&&e.findingsCount>0?(0,r.jsx)("span",{children:e.findingsCount}):null]},e.n)})}):null,d?(0,r.jsx)("button",{className:"shrink-0 rounded-full border border-accent bg-accent px-2.5 py-0.5 text-[11px] font-bold text-white hover:opacity-90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/50 disabled:opacity-40",disabled:n,onClick:()=>void c(d.action),children:d.label}):null,"needs_decision"===e.state?(0,r.jsx)("button",{className:"shrink-0 rounded-full border border-line bg-bg px-2 py-0.5 text-[10.5px] font-semibold text-ink hover:border-accent/40 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40 disabled:opacity-40",disabled:n,title:"Додати ще раунди до ліміту",onClick:()=>void c("extend",{rounds:2}),children:"+2 раунди"}):null,x?null:(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("button",{className:`shrink-0 rounded-full border px-2 py-0.5 text-[10px] font-bold focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40 disabled:opacity-40 ${"auto"===e.mode?"border-ok/40 bg-[#eef8f0] text-ok":"border-line bg-bg text-dim hover:text-ink"}`,disabled:n,title:"auto"===e.mode?"Авто: переходи самі. Клік — вручну.":"Вручну: кожен перехід чекає кліку. Клік — авто.",onClick:()=>void c("set-mode",{mode:"auto"===e.mode?"manual":"auto"}),children:"auto"===e.mode?"авто":"вручну"}),"paused"===e.state?(0,r.jsx)("button",{className:"inline-flex h-5 w-5 shrink-0 items-center justify-center rounded-full text-ok hover:bg-bg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40 disabled:opacity-40",disabled:n,title:"Продовжити флоу","aria-label":"Продовжити флоу",onClick:()=>void c("resume"),children:(0,r.jsx)(eS.A,{className:"h-3.5 w-3.5","aria-hidden":!0})}):(0,r.jsx)("button",{className:"inline-flex h-5 w-5 shrink-0 items-center justify-center rounded-full text-dim hover:bg-bg hover:text-ink focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40 disabled:opacity-40",disabled:n,title:"Пауза","aria-label":"Пауза",onClick:()=>void c("pause"),children:(0,r.jsx)(tH.A,{className:"h-3.5 w-3.5","aria-hidden":!0})})]}),n?(0,r.jsx)(nb.A,{className:"h-3 w-3 shrink-0 animate-spin text-dim","aria-hidden":!0}):null,a?(0,r.jsx)("span",{className:"shrink-0 text-[10.5px] font-semibold text-err",children:a}):null,(0,r.jsx)("button",{className:"inline-flex h-5 w-5 shrink-0 items-center justify-center rounded-full text-dim hover:bg-bg hover:text-err focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40 disabled:opacity-40",disabled:n,title:"Закрити флоу","aria-label":"Закрити флоу",onClick:()=>void c("close"),children:(0,r.jsx)(l.A,{className:"h-3 w-3","aria-hidden":!0})})]})}function nj(e){return e.error?`Раунд ${e.n} \xb7 перервано`:e.verdict?`Раунд ${e.n} \xb7 ${k[e.verdict]} ${e.verdict}`:`Раунд ${e.n} \xb7 триває`}function ny({round:e,depth:t,pulse:n,onPull:l}){let i=S(e.verdict);return(0,r.jsxs)("button",{className:`deck-tab absolute inset-x-0 flex items-center gap-1.5 rounded-[9px] border bg-panel px-2.5 text-left shadow-card focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40 ${n?"deck-tab-live border-ok/50":"border-line hover:border-accent/45"}`,style:{height:36,bottom:-(30*t)-10,zIndex:10-t,transform:`scale(${1-.035*t}) translateZ(${-(34*t)}px)`},title:e.error?`${nj(e)}: ${e.error}`:nj(e),onClick:l,children:[(0,r.jsxs)("span",{className:"inline-flex h-4 shrink-0 items-center gap-1 rounded-full px-1.5 text-[9.5px] font-bold",style:{backgroundColor:i.soft,color:i.color},children:["R",e.n," ",e.verdict?k[e.verdict]:e.error?"!":"⏳"]}),(0,r.jsxs)("span",{className:"min-w-0 flex-1 truncate text-[10.5px] font-semibold text-dim",children:[e.error?"перервано":e.verdict?e.verdict:"ревью триває",null!=e.findingsCount&&e.findingsCount>0?` \xb7 ${e.findingsCount} знахідок`:""]}),n?(0,r.jsx)("span",{className:"h-1.5 w-1.5 shrink-0 animate-pulse rounded-full bg-ok","aria-hidden":!0}):null]})}function nN({flow:e,rounds:t,files:n,onSelect:l,focusRound:s}){let a=t.length?t[t.length-1]:null,[o,c]=(0,i.useState)(null),[d,u]=(0,i.useState)(null);null!=s&&s!==d&&(u(s),c(Math.round(s)));let[x,p]=(0,i.useState)(null);a&&a.round.n!==x&&(p(a.round.n),null!=o&&a.round.n>o&&null===a.round.verdict&&c(null));let f=(0,i.useMemo)(()=>t.find(e=>e.round.n===o)??a,[t,o,a]);if(!f)return(0,r.jsx)("div",{className:"flex h-full items-center justify-center rounded-[10px] border border-dashed border-[#c9c9d1] bg-panel/60",children:(0,r.jsx)("span",{className:"text-[12px] font-semibold text-dim",children:"чекаю на перший раунд ревью…"})});let m=t.filter(e=>e.round.n!==f.round.n).reverse(),h=m.slice(0,5),b=m.length-h.length,g=S(f.round.verdict),v=null!==f.round.verdict||!!f.round.error,w=a&&f.round.n!==a.round.n&&null===a.round.verdict&&!a.round.error?a:null;return(0,r.jsxs)("div",{className:"deck-3d relative h-full",style:{paddingBottom:30*Math.min(m.length,5+ +!!b)},children:[(0,r.jsx)("div",{className:"scheme-enter relative z-[11] flex h-full flex-col",children:f.file?(0,r.jsx)(nn,{file:f.file,files:n,tasks:[],onSelect:l,isRoot:!1,noComposer:"headless"===e.reviewerMode||v,banner:(0,r.jsxs)("div",{className:"flex h-6 shrink-0 items-center gap-1.5 border-b border-line px-2.5 text-[10.5px] font-bold",style:{backgroundColor:g.soft,color:g.color},children:[nj(f.round),null!=f.round.findingsCount&&f.round.findingsCount>0?(0,r.jsxs)("span",{className:"font-semibold opacity-80",children:["\xb7 ",f.round.findingsCount," знахідок"]}):null,f.round.readyNote?(0,r.jsxs)("span",{className:"min-w-0 flex-1 truncate font-semibold opacity-70",title:f.round.readyNote,children:["\xb7 ",f.round.readyNote]}):null]})}):(0,r.jsxs)("div",{className:"flex h-full flex-col items-center justify-center gap-1 rounded-[10px] border border-line bg-panel shadow-card",children:[(0,r.jsx)("span",{className:"text-[12px] font-semibold text-dim",children:nj(f.round)}),(0,r.jsx)("span",{className:"text-[11px] text-dim",children:f.round.error?f.round.error:"запускаю ревʼюера — транскрипт зʼявиться за мить…"})]})},f.round.n),h.map((e,t)=>(0,r.jsx)(ny,{round:e.round,depth:t,pulse:w?.round.n===e.round.n,onPull:()=>c(e.round.n)},e.round.n)),b>0?(0,r.jsxs)("div",{className:"pointer-events-none absolute inset-x-6 flex items-center justify-center rounded-[9px] border border-line bg-panel/70 text-[10px] font-semibold text-dim shadow-card",style:{height:26,bottom:-(30*h.length)-8,zIndex:10-h.length},"aria-hidden":!0,children:["ще ",b," раунд(и) — клікни чипи на стрічці флоу"]}):null]})}let nk=new Set(["spawning","reviewing","relaying"]);function nS({layout:e,cam:t,vp:n,onJump:l}){let s=(0,i.useRef)(null),a=(0,i.useRef)(!1),o=Math.min(216/e.width,148/e.height),c=(216-e.width*o)/2,d=(148-e.height*o)/2,u=e=>{let t=s.current?.getBoundingClientRect();t&&l((e.clientX-t.left-c)/o,(e.clientY-t.top-d)/o)};return(0,r.jsx)("div",{ref:s,"data-scheme-ui":!0,className:"absolute bottom-3 right-3 z-40 cursor-pointer overflow-hidden rounded-[10px] border border-line bg-panel/95 shadow-card",style:{width:216,height:148},title:"Мінімапа — клікни або тягни, щоб перейти",onPointerDown:e=>{e.stopPropagation(),a.current=!0,u(e);try{e.currentTarget.setPointerCapture(e.pointerId)}catch{}},onPointerMove:e=>{a.current&&u(e)},onPointerUp:e=>{a.current=!1;try{e.currentTarget.releasePointerCapture(e.pointerId)}catch{}},onPointerCancel:()=>{a.current=!1},children:(0,r.jsx)("svg",{width:216,height:148,"aria-hidden":!0,children:(0,r.jsxs)("g",{transform:`translate(${c} ${d}) scale(${o})`,children:[e.stacks.map(e=>(0,r.jsx)("rect",{x:e.x,y:e.y,width:e.w,height:e.h,rx:18,fill:"#c9c9d1",opacity:.45},e.key)),e.drafts.map(e=>(0,r.jsx)("rect",{x:e.x,y:e.y,width:e.w,height:e.h,rx:18,fill:"#9a9aa4",opacity:.3},e.key)),e.nodes.map(e=>(0,r.jsx)("rect",{x:e.x,y:e.y,width:e.w,height:e.h,rx:18,fill:I(e.file).color,opacity:"live"===e.file.activity?.85:.35},e.file.path)),(0,r.jsx)("rect",{x:-t.x/t.z,y:-t.y/t.z,width:n.w/t.z,height:n.h/t.z,fill:"rgba(90,81,224,0.08)",stroke:"#5a51e0",strokeWidth:2.5/o})]})})})}let nC="cubic-bezier(.22,.8,.36,1)",n$=`transform 380ms ${nC}`,nA="llvSchemeMode",nE=(0,i.memo)(function({edges:e,width:t,height:n}){return(0,r.jsx)("svg",{width:t,height:n,className:"absolute left-0 top-0","aria-hidden":!0,children:e.map(e=>{let t=Math.max(36,(e.y2-e.y1)*.5),n=`M ${e.x1} ${e.y1} C ${e.x1} ${e.y1+t}, ${e.x2} ${e.y2-t}, ${e.x2} ${e.y2-7}`,l=`M ${e.x2-5} ${e.y2-9} L ${e.x2+5} ${e.y2-9} L ${e.x2} ${e.y2-1} Z`;return(0,r.jsxs)("g",{opacity:e.live?.9:.5,children:[(0,r.jsx)("path",{d:n,style:{d:`path("${n}")`,transition:`d 380ms ${nC}`},fill:"none",stroke:e.color,strokeWidth:2.5,strokeLinecap:"round",strokeDasharray:e.dashed?"5 7":void 0}),(0,r.jsx)("circle",{cx:e.x1,cy:e.y1,r:3.5,fill:e.color,style:{cx:`${e.x1}px`,cy:`${e.y1}px`,transition:`cx 380ms ${nC}, cy 380ms ${nC}`}}),(0,r.jsx)("path",{d:l,style:{d:`path("${l}")`,transition:`d 380ms ${nC}`},fill:e.color})]},e.to)})})});function nM({file:e,onSelect:t}){let n=F(e);return(0,r.jsxs)("button",{className:"flex h-8 w-full min-w-0 items-center gap-1.5 rounded-[8px] px-2 text-left hover:bg-bg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40",title:s(e.title),onClick:()=>t(e),children:[(0,r.jsx)("span",{className:`h-1.5 w-1.5 shrink-0 rounded-full ${M(e.activity)}`}),(0,r.jsx)("span",{className:"shrink-0 rounded-full px-1.5 text-[9px] font-bold",style:n.style,children:n.label}),(0,r.jsx)("span",{className:"min-w-0 flex-1 truncate text-[11.5px] font-semibold",children:s(e.cmdDesc||e.title,80)}),(0,r.jsx)("span",{className:"shrink-0 text-[10.5px] text-dim",children:$(e.mtime)})]})}function nR({file:e}){let t=F(e);return(0,r.jsx)("div",{className:"pointer-events-none absolute inset-0 z-[3] flex items-center justify-center",style:{opacity:"var(--label-o, 0)",transition:"opacity .25s"},"aria-hidden":!0,children:(0,r.jsxs)("div",{className:"flex max-w-[94%] items-center gap-[0.5em] rounded-[0.55em] border border-line bg-panel/95 px-[0.75em] py-[0.45em] shadow-[0_2px_14px_rgb(20_20_30/0.14)]",style:{fontSize:"calc(13px * min(var(--inv-z, 1), 2.6))"},children:[(0,r.jsx)("span",{className:`h-[0.6em] w-[0.6em] shrink-0 rounded-full ${M(e.activity)}`}),(0,r.jsx)("span",{className:"shrink-0 rounded-full px-[0.45em] font-bold",style:{...t.style,fontSize:"0.72em"},children:t.label}),(0,r.jsx)("span",{className:"line-clamp-2 min-w-0 font-bold",children:s(e.title,70)})]})})}function nT({stack:e,onSelect:t}){return(0,r.jsx)("div",{"data-scheme-node":e.key,className:"scheme-enter absolute",style:{transform:`translate(${e.x}px, ${e.y}px)`,width:e.w,height:e.h,transition:n$},children:(0,r.jsx)("div",{className:"flex h-full flex-col gap-1.5 overflow-y-auto rounded-[10px] border border-dashed border-[#c9c9d1] bg-panel/60 p-2",children:e.items.map(({file:e,branches:n})=>{let l=F(e);return(0,r.jsxs)("button",{className:"flex min-h-[52px] w-full min-w-0 flex-col justify-center gap-0.5 rounded-[8px] border border-line bg-panel px-2 py-1 text-left shadow-card hover:border-accent/40 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40",title:s(e.title),onClick:()=>t(e),children:[(0,r.jsxs)("span",{className:"flex min-w-0 items-center gap-1.5",children:[(0,r.jsx)("span",{className:`h-1.5 w-1.5 shrink-0 rounded-full ${M(e.activity)}`}),(0,r.jsx)("span",{className:"shrink-0 rounded-full px-1.5 text-[9px] font-bold",style:l.style,children:l.label}),(0,r.jsx)("span",{className:"min-w-0 flex-1 truncate text-[11.5px] font-semibold",children:s(e.title,70)})]}),(0,r.jsxs)("span",{className:"flex items-center gap-2 pl-3 text-[10.5px] text-dim",children:[(0,r.jsx)("span",{children:e.kind}),(0,r.jsx)("span",{children:$(e.mtime)}),n?(0,r.jsxs)("span",{children:["⤷ ",n]}):null]})]},e.path)})})})}function nP({node:e,files:t,ringed:n,flow:l,canFlow:s,onSelect:a,onClose:o,onFocusRound:c}){let[d,u]=(0,i.useState)(!1),[x,p]=(0,i.useState)(!1);return(0,r.jsxs)("div",{"data-scheme-node":e.file.path,className:`scheme-enter absolute ${d||x?"z-20":""}`,style:{transform:`translate(${e.x}px, ${e.y}px)`,width:e.w,height:e.h,transition:n$},children:[l?(0,r.jsx)("div",{className:"absolute inset-x-0 -top-10 z-[4] flex justify-center",children:(0,r.jsx)(nw,{flow:l,onFocusRound:e=>c(l.id,e)})}):s?(0,r.jsx)("div",{className:"absolute -top-10 left-0 z-[4]",children:(0,r.jsxs)("button",{"data-scheme-ui":!0,className:"inline-flex h-7 items-center gap-1 rounded-full border border-line bg-panel px-2.5 text-[11px] font-semibold text-dim shadow-card hover:border-accent/45 hover:text-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40","aria-expanded":x,title:"Запустити цикл implement → review для цієї розмови",onClick:()=>p(e=>!e),children:[(0,r.jsx)("span",{className:"text-[13px] leading-none text-accent",children:"⟳"})," Флоу"]})}):null,x?(0,r.jsx)("div",{className:"absolute left-0 top-[-8px] z-40 -translate-y-full",children:(0,r.jsx)(nh,{file:e.file,onClose:()=>p(!1)})}):null,e.under.length?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{className:"absolute inset-x-4 -bottom-4 h-5 rounded-[10px] border border-line bg-panel/70 shadow-card","aria-hidden":!0}),(0,r.jsx)("div",{className:"absolute inset-x-2 -bottom-2 h-5 rounded-[10px] border border-line bg-panel/90 shadow-card","aria-hidden":!0})]}):null,(0,r.jsx)("div",{className:`relative z-[1] flex h-full ${n?"rounded-[10px] ring-2 ring-accent/60":""}`,children:(0,r.jsx)(nn,{file:e.file,tasks:e.tasks,files:t,onSelect:a,isRoot:e.isRoot,onClose:()=>o(e.file.path)})}),(0,r.jsx)(nR,{file:e.file}),e.under.length?(0,r.jsxs)("button",{className:"absolute -bottom-11 left-1/2 z-[2] inline-flex h-7 -translate-x-1/2 items-center gap-1.5 whitespace-nowrap rounded-full border border-line bg-panel px-2.5 text-[11px] font-semibold text-dim shadow-card hover:border-accent/40 hover:text-ink focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40","aria-expanded":d,title:"Згорнуті гілки й задачі цієї розмови",onClick:()=>u(e=>!e),children:[(0,r.jsx)(nc.A,{className:"h-3.5 w-3.5","aria-hidden":!0}),e.under.length," під сподом",(0,r.jsx)(eb.A,{className:`h-3 w-3 transition-transform ${d?"rotate-90":""}`,"aria-hidden":!0})]}):null,d?(0,r.jsx)("div",{className:"absolute left-0 top-[calc(100%+52px)] z-30 max-h-[280px] w-full overflow-y-auto rounded-[10px] border border-line bg-panel p-1.5 shadow-[0_10px_36px_rgb(20_20_30/0.18)]",children:e.under.map(e=>(0,r.jsx)(nM,{file:e,onSelect:a},e.path))}):null]})}function n_({draft:e,project:t,files:n,ringed:l,onDraftClose:i,onDraftSpawned:s}){return(0,r.jsx)("div",{"data-scheme-node":e.key,className:"scheme-enter absolute",style:{transform:`translate(${e.x}px, ${e.y}px)`,width:e.w,height:e.h,transition:n$},children:(0,r.jsx)("div",{className:`flex h-full ${l?"rounded-[10px] ring-2 ring-accent/60":""}`,children:(0,r.jsx)(no,{draftId:e.id,project:t,files:n,onClose:()=>i(e.id),onSpawned:t=>s(e.id,t)})})})}function nI({deck:e,files:t,focus:n,onSelect:l}){let i=n&&n.flowId===e.flow.id?n.round+n.nonce/1e3:null;return(0,r.jsx)("div",{"data-scheme-node":e.key,className:"scheme-enter absolute",style:{transform:`translate(${e.x}px, ${e.y}px)`,width:e.w,height:e.h,transition:n$},children:(0,r.jsx)(nN,{flow:e.flow,rounds:e.rounds,files:t,onSelect:l,focusRound:i})})}let nz=(0,i.memo)(function({layout:e,project:t,files:n,interactive:l,selected:i,focus:s,flowsByImpl:a,deckFocus:o,onSelect:c,onClose:u,onFocusRound:x,onDraftClose:p,onDraftSpawned:f}){return(0,r.jsxs)("div",{className:l?void 0:"pointer-events-none select-none",children:[e.stacks.map(e=>(0,r.jsx)(nT,{stack:e,onSelect:c},e.key)),e.decks.map(e=>(0,r.jsx)(nI,{deck:e,files:n,focus:o,onSelect:c},e.key)),e.drafts.map(e=>(0,r.jsx)(n_,{draft:e,project:t,files:n,ringed:i===e.key||s===e.key,onDraftClose:p,onDraftSpawned:f},e.key)),e.nodes.map(e=>{var t;return(0,r.jsx)(nP,{node:e,files:n,ringed:i===e.file.path||s===e.file.path,flow:a.get(e.file.path)??null,canFlow:(t=e.file,!a.has(t.path)&&("claude"===t.engine||"codex"===t.engine)&&d(t)),onSelect:c,onClose:u,onFocusRound:x},e.file.path)})]})});function nL({active:e,title:t,onClick:n,children:l}){return(0,r.jsx)("button",{className:`inline-flex h-7 w-7 items-center justify-center rounded-[8px] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40 ${e?"bg-accent/10 text-accent":"text-dim hover:bg-bg hover:text-ink"}`,title:t,"aria-label":t,"aria-pressed":e,onClick:n,children:l})}let nD=(e,t)=>Math.hypot(e.x-t.x,e.y-t.y);function nO({project:e,groups:t,manual:n,files:l,flows:s,drafts:a,focus:o,onSelect:d,onClose:u,onDraftClose:p,onDraftSpawned:f}){let m=(0,i.useRef)(null),[b,g]=(0,i.useState)({x:0,y:0,z:.5}),[v,y]=(0,i.useState)("select"),[N,k]=(0,i.useState)(!1),[S,C]=(0,i.useState)(!1),[$,A]=(0,i.useState)(!1),[E,M]=(0,i.useState)(null),[R,T]=(0,i.useState)({w:1,h:1}),P=(0,i.useRef)(null),_=(0,i.useRef)(new Map),z=(0,i.useRef)(null),L=(0,i.useRef)(v),D=(0,i.useRef)(N),O=(0,i.useRef)(null),F=(0,i.useRef)(null),U=(0,i.useRef)(null);(0,i.useEffect)(()=>{L.current=v},[v]),(0,i.useEffect)(()=>{D.current=N},[N]),(0,i.useEffect)(()=>{let e=localStorage.getItem(nA);"hand"===e||"select"===e?y(e):window.matchMedia("(pointer: coarse)").matches&&y("hand")},[]);let q=(0,i.useCallback)(e=>{y(e),localStorage.setItem(nA,e)},[]),J=(0,i.useMemo)(()=>(function(e,t,n,r=[],l=[]){let i=new Map(n.map(e=>[e.path,e])),s=h(n),a=[],o=[],d=[],u=[],p=w(r),f=j(r),m=100,b=e=>({file:e,branches:s.get(e.path)?.length??0}),g=(e,t,n,r,l)=>{let s=(e,c,x,m)=>{let h=0===m?780:680;a.push({file:e.file,tasks:e.tasks,under:r.get(e.file.path)??[],x:c,y:x,w:600,h,isRoot:e.file.path===l});let g=t.get(e.file.path)??[],v=c+64;for(let e of g)o.push({to:e.file.path,x1:c+40,y1:x+h,x2:v+300,y2:x+h+130,color:I(e.file).color,live:"live"===e.file.activity}),v+=s(e,v,x+h+130,m+1)+48;let w=p.get(e.file.path);if(w){var j,y,N;let e,t,n=(j=w,y=v,N=x+h+130,e=j.rounds.map(e=>({round:e,file:e.reviewerPath?i.get(e.reviewerPath)??null:null})),t={key:"deck::"+j.id,flow:j,rounds:e,x:y,y:N,w:600,h:680+30*Math.min(Math.max(j.rounds.length-1,0),6)},u.push(t),t);o.push({to:n.key,x1:c+40,y1:x+h,x2:v+300,y2:x+h+130,color:"#5a51e0",live:nk.has(w.state)}),v+=648}let k=n.get(e.file.path)?.filter(e=>!f.has(e.path));if(k?.length){let t=x+h+130;d.push({key:e.file.path+"::stack",parent:e.file.path,items:k.map(b),x:v,y:t,w:360,h:16+58*Math.min(k.length,8)-6}),o.push({to:e.file.path+"::stack",x1:c+40,y1:x+h,x2:v+180,y2:t,color:"#9a9aa4",live:!1,dashed:!0}),v+=408}let S=v-48-(c+64);return S>0?Math.max(600,64+S):600};return s(e,m,100,0)};for(let t of e){let e=t.columns;if(!e.length)continue;let n=e[0].file.path,r=new Set(e.map(e=>e.file.path)),l=e=>{let t=e.parent,l=new Set([e.path]);for(;t&&!l.has(t)&&!r.has(t);)l.add(t),t=i.get(t)?.parent??null;return t&&r.has(t)&&t!==e.path?t:n},s=new Map;for(let t of e){if(t.file.path===n)continue;let e=l(t.file),r=s.get(e);r?r.push(t):s.set(e,[t])}let a=new Map,o=[];for(let e of[...t.returnable,...t.finished])if(!f.has(e.path))if(x(e)){let t=l(e),n=a.get(t);n?n.push(e):a.set(t,[e])}else o.push(e);let c=new Map([[n,o]]);m+=g(e[0],s,a,c,t.key)+150}for(let e of t){let t=(function(e,t){if(!e)return[];let n=h(t),r=[],l=new Set([e.path]),i=(e,t)=>{for(let s of(n.get(e.path)??[]).filter(e=>!l.has(e.path)).sort((e,t)=>c(e)-c(t)||t.mtime-e.mtime))l.add(s.path),r.push({file:s,depth:t}),i(s,t+1)};return i(e,1),r})(e,n).map(e=>e.file).filter(e=>!f.has(e.path)),r=t.filter(e=>x(e)),l=t.filter(e=>!x(e));m+=g({file:e,tasks:[]},new Map,new Map(r.length?[[e.path,r]]:[]),new Map([[e.path,l]]),e.parent?"":e.path)+150}let v=[];for(let e of l)v.push({key:"draft::"+e,id:e,x:m,y:100,w:600,h:780}),m+=750;let y=0;for(let e of a)y=Math.max(y,e.y+e.h);for(let e of d)y=Math.max(y,e.y+e.h);for(let e of u)y=Math.max(y,e.y+e.h);for(let e of v)y=Math.max(y,e.y+e.h);return{nodes:a,edges:o,stacks:d,decks:u,drafts:v,byPath:new Map([...a.map(e=>[e.file.path,e]),...v.map(e=>[e.key,e])]),width:Math.max(m-150+100,800),height:y+100+140}})(t,n,l,s,a),[t,n,l,s,a]),H=(0,i.useMemo)(()=>w(s),[s]),[Y,B]=(0,i.useState)(null),X=(0,i.useCallback)((e,t)=>{B(n=>({flowId:e,round:t,nonce:(n?.nonce??0)+1}))},[]),W=(0,i.useRef)(d),Q=(0,i.useRef)(u),K=(0,i.useRef)(p),V=(0,i.useRef)(f);(0,i.useEffect)(()=>{W.current=d,Q.current=u,K.current=p,V.current=f});let G=(0,i.useCallback)(e=>W.current(e),[]),Z=(0,i.useCallback)(e=>Q.current(e),[]),ee=(0,i.useCallback)(e=>K.current(e),[]),et=(0,i.useCallback)((e,t)=>V.current(e,t),[]);(0,i.useEffect)(()=>{let e=m.current;if(!e)return;let t=new ResizeObserver(()=>{let t=e.getBoundingClientRect();T({w:Math.max(1,t.width),h:Math.max(1,t.height)})});return t.observe(e),()=>t.disconnect()},[]);let en=(0,i.useCallback)(e=>{let t=Math.min(Math.max(e.x,120-J.width*e.z),R.w-120),n=Math.min(Math.max(e.y,120-J.height*e.z),R.h-120);return t===e.x&&n===e.y?e:{...e,x:t,y:n}},[J.width,J.height,R]),er=(0,i.useRef)([]),el=(0,i.useRef)(null),ei=(0,i.useCallback)(e=>{er.current.push(e),null==el.current&&(el.current=requestAnimationFrame(()=>{el.current=null;let e=er.current;er.current=[],g(t=>e.reduce((e,t)=>t(e),t))}))},[]);(0,i.useEffect)(()=>()=>{null!=el.current&&cancelAnimationFrame(el.current)},[]);let es=(0,i.useCallback)((e,t,n)=>{ei(r=>{let l=Math.min(1.6,Math.max(.12,r.z*n));if(l===r.z)return r;let i=l/r.z;return en({z:l,x:e-(e-r.x)*i,y:t-(t-r.y)*i})})},[en,ei]),ea=(0,i.useCallback)(e=>{let t=m.current?.getBoundingClientRect();t&&es(t.width/2,t.height/2,e)},[es]),eo=(0,i.useCallback)(e=>{let t=m.current?.getBoundingClientRect();t&&g(n=>{let r=Math.min(1.6,Math.max(.12,e));if(r===n.z)return n;let l=r/n.z,i=t.width/2,s=t.height/2;return en({z:r,x:i-(i-n.x)*l,y:s-(s-n.y)*l})})},[en]),ec=(0,i.useCallback)(()=>{let e=m.current?.getBoundingClientRect();if(!e||!J.nodes.length&&!J.drafts.length)return null;let t=Math.min(1.6,Math.max(.12,Math.min((e.width-48)/J.width,(e.height-48)/J.height,1)));return{z:t,x:(e.width-J.width*t)/2,y:(e.height-J.height*t)/2}},[J]),ed=(0,i.useCallback)(e=>{A(!0),g(e),O.current&&window.clearTimeout(O.current),O.current=window.setTimeout(()=>A(!1),500)},[]);(0,i.useEffect)(()=>()=>{O.current&&window.clearTimeout(O.current)},[]);let eu=(0,i.useCallback)(()=>{let e=ec();e&&ed(e)},[ec,ed]),ex=(0,i.useCallback)((e,t)=>{let n=m.current?.getBoundingClientRect();n&&ed(r=>{let l=Math.min(1.6,Math.max(r.z,t));return{z:l,x:n.width/2-(e.x+e.w/2)*l,y:Math.min(n.height/2-e.y*l,.08*n.height-(e.y-40)*l)}})},[ed]);(0,i.useEffect)(()=>{if(F.current===e||!J.nodes.length&&!J.drafts.length)return;F.current=e;try{let t=sessionStorage.getItem("llvCam:"+e);if(t){let e=JSON.parse(t);if(Number.isFinite(e.x)&&Number.isFinite(e.y)&&Number.isFinite(e.z)&&e.z>=.12&&e.z<=1.6)return void g(e)}}catch{}let t=ec();t&&g(t)},[e,J,ec]),(0,i.useEffect)(()=>{if(F.current!==e)return;let t=window.setTimeout(()=>sessionStorage.setItem("llvCam:"+e,JSON.stringify(b)),300);return()=>window.clearTimeout(t)},[b,e]),(0,i.useEffect)(()=>{if(!o){U.current=null;return}if(U.current===o)return;let e=J.byPath.get(o);e&&(U.current=o,ex(e,.55))},[o,J,ex]),(0,i.useEffect)(()=>{let e=m.current;if(!e)return;let t=t=>{if(t.target.closest("[data-scheme-ui]"))return;let n=e.getBoundingClientRect();if(t.ctrlKey||t.metaKey){t.preventDefault(),es(t.clientX-n.left,t.clientY-n.top,Math.exp(-(.0022*t.deltaY)));return}if("select"===L.current&&!D.current){for(let n=t.target;n&&n!==e;n=n.parentElement)if(n.scrollHeight>n.clientHeight+1){let e=getComputedStyle(n).overflowY;if("auto"===e||"scroll"===e)return}}t.preventDefault();let r=t.shiftKey&&!t.deltaX?t.deltaY:t.deltaX,l=t.shiftKey&&!t.deltaX?0:t.deltaY;ei(e=>en({...e,x:e.x-r,y:e.y-l}))};return e.addEventListener("wheel",t,{passive:!1}),()=>e.removeEventListener("wheel",t)},[es,en,ei]),(0,i.useEffect)(()=>{let e=e=>{var t;if(!((t=e.target)&&t.tagName&&(["INPUT","TEXTAREA","SELECT","BUTTON"].includes(t.tagName)||t.isContentEditable))){if(" "===e.key){e.preventDefault(),e.repeat||k(!0);return}if(!e.metaKey&&!e.ctrlKey&&!e.altKey){if("h"===e.key||"H"===e.key)q("hand");else if("v"===e.key||"V"===e.key)q("select");else if("Escape"===e.key)M(null);else if("0"===e.key)eu();else if("1"===e.key)eo(1);else if("+"===e.key||"="===e.key)ea(1.25);else if("-"===e.key)ea(.8);else if(e.key.startsWith("Arrow")){e.preventDefault();let t="ArrowLeft"===e.key?160:"ArrowRight"===e.key?-160:0,n="ArrowUp"===e.key?160:"ArrowDown"===e.key?-160:0;g(e=>en({...e,x:e.x+t,y:e.y+n}))}}}},t=e=>{" "===e.key&&k(!1)};return window.addEventListener("keydown",e),window.addEventListener("keyup",t),()=>{window.removeEventListener("keydown",e),window.removeEventListener("keyup",t)}},[eu,ea,eo,q,en]);let ep=e=>{let t=m.current?.getBoundingClientRect();return t?{x:e.clientX-t.left,y:e.clientY-t.top}:{x:e.clientX,y:e.clientY}},ef=e=>{P.current={sx:e.clientX,sy:e.clientY,cx:b.x,cy:b.y},C(!0);try{m.current?.setPointerCapture(e.pointerId)}catch{}};(0,i.useEffect)(()=>{let e=e=>{_.current.delete(e.pointerId),_.current.size<2&&(z.current=null),P.current=null,C(!1)};return window.addEventListener("pointerup",e),window.addEventListener("pointercancel",e),()=>{window.removeEventListener("pointerup",e),window.removeEventListener("pointercancel",e)}},[]);let em="hand"===v||N,eh=(0,i.useCallback)((e,t)=>g(n=>en({...n,x:R.w/2-e*n.z,y:R.h/2-t*n.z})),[R,en]),eb=24*b.z;return(0,r.jsxs)("div",{ref:m,className:`relative min-h-0 flex-1 overflow-hidden ${S?"cursor-grabbing select-none":em?"cursor-grab":""} ${em?"touch-none":""}`,onPointerDown:e=>{let t=e.target;if(!t.closest("[data-scheme-ui]")){if("touch"===e.pointerType&&(_.current.set(e.pointerId,ep(e)),2===_.current.size)){let[e,t]=[..._.current.values()];z.current={d:nD(e,t),cx:(e.x+t.x)/2,cy:(e.y+t.y)/2},P.current=null,C(!1);return}if(1===e.button){e.preventDefault(),ef(e);return}if(0===e.button){if(!("hand"===v||N)){let e=t.closest("[data-scheme-node]");if(e)return void M(e.getAttribute("data-scheme-node"));if(M(null),t.closest("button, a, input, textarea, select"))return}ef(e)}}},onPointerMove:e=>{if("touch"===e.pointerType&&_.current.has(e.pointerId)){_.current.set(e.pointerId,ep(e));let t=z.current;if(t&&_.current.size>=2){let[e,n]=[..._.current.values()],r=nD(e,n),l=(e.x+n.x)/2,i=(e.y+n.y)/2,s=t.d>0?r/t.d:1;ei(e=>{let n=Math.min(1.6,Math.max(.12,e.z*s)),r=n/e.z;return en({z:n,x:l-(t.cx-e.x)*r,y:i-(t.cy-e.y)*r})}),z.current={d:r,cx:l,cy:i};return}}let t=P.current;if(!t)return;let n=e.clientX-t.sx,r=e.clientY-t.sy;ei(e=>en({...e,x:t.cx+n,y:t.cy+r}))},onDoubleClick:e=>{let t=e.target;if(t.closest("[data-scheme-ui]"))return;let n=t.closest("[data-scheme-node]");if(!n)return void eu();if("hand"!==v&&!N)return;let r=J.byPath.get(n.getAttribute("data-scheme-node")??"");r&&ex(r,.9)},children:[(0,r.jsx)("div",{"aria-hidden":!0,className:"pointer-events-none absolute",style:{inset:-eb,backgroundImage:"radial-gradient(rgba(28,28,34,0.09) 1px, transparent 1px)",backgroundSize:`${eb}px ${eb}px`,transform:`translate(${(b.x%eb+eb)%eb}px, ${(b.y%eb+eb)%eb}px)`,willChange:"transform"}}),(0,r.jsxs)("div",{className:`absolute left-0 top-0 ${S?"scheme-panning":""}`,style:{width:J.width,height:J.height,transform:`translate(${b.x}px, ${b.y}px) scale(${b.z})`,transformOrigin:"0 0",transition:$?`transform .45s ${nC}`:void 0,willChange:"transform","--inv-z":String(1/b.z),"--label-o":b.z<.45?"1":"0"},children:[(0,r.jsx)(nE,{edges:J.edges,width:J.width,height:J.height}),(0,r.jsx)(nz,{layout:J,project:e,files:l,interactive:!em,selected:E,focus:o,flowsByImpl:H,deckFocus:Y,onSelect:G,onClose:Z,onFocusRound:X,onDraftClose:ee,onDraftSpawned:et})]},e),(0,r.jsxs)("div",{"data-scheme-ui":!0,className:"absolute left-3 top-3 z-40 flex items-center gap-1 rounded-[10px] border border-line bg-panel/95 p-1 shadow-card",children:[(0,r.jsx)(nL,{active:em,title:"Рука — тягнути полотно (H, або тримай Space)",onClick:()=>q("hand"),children:(0,r.jsx)(nd.A,{className:"h-4 w-4","aria-hidden":!0})}),(0,r.jsx)(nL,{active:!em,title:"Виділення — клік і робота з розмовами (V)",onClick:()=>q("select"),children:(0,r.jsx)(nu.A,{className:"h-4 w-4","aria-hidden":!0})}),(0,r.jsx)("div",{className:"mx-0.5 h-5 w-px bg-line","aria-hidden":!0}),(0,r.jsx)(nL,{title:"Віддалити (−)",onClick:()=>ea(.8),children:(0,r.jsx)(tl.A,{className:"h-4 w-4","aria-hidden":!0})}),(0,r.jsxs)("button",{className:"min-w-[46px] rounded-[8px] px-1 text-center text-[11px] font-semibold text-dim hover:bg-bg hover:text-ink focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40",title:"Масштаб 100% (1)",onClick:()=>eo(1),children:[Math.round(100*b.z),"%"]}),(0,r.jsx)(nL,{title:"Наблизити (+)",onClick:()=>ea(1.25),children:(0,r.jsx)(ti.A,{className:"h-4 w-4","aria-hidden":!0})}),(0,r.jsx)(nL,{title:"Вписати все (0, або подвійний клік по фону)",onClick:eu,children:(0,r.jsx)(nx.A,{className:"h-4 w-4","aria-hidden":!0})})]}),(0,r.jsx)(nS,{layout:J,cam:b,vp:R,onJump:eh})]})}let nF="llvArchived";function nU(e){try{window.localStorage.setItem(nF,JSON.stringify([...e]))}catch{}}function nq({data:e,onOpen:t}){let n=e.waiting.length,l=(0,i.useRef)(n),[s,a]=(0,i.useState)(!1);return(0,i.useEffect)(()=>{if(n>l.current){a(!0);let e=window.setTimeout(()=>a(!1),900);return l.current=n,()=>window.clearTimeout(e)}l.current=n},[n]),(0,r.jsxs)("div",{className:"group absolute bottom-3 right-3 z-20",children:[e.livePreview.length?(0,r.jsx)("div",{className:"pointer-events-none mb-1.5 hidden w-[300px] rounded-[8px] border border-line bg-panel/95 px-3 py-2 shadow-card backdrop-blur group-focus-within:block group-hover:block",children:e.livePreview.map(e=>(0,r.jsxs)("div",{className:"flex min-w-0 gap-1.5 py-0.5 text-[10.5px]",children:[(0,r.jsx)("span",{className:"min-w-0 flex-1 truncate font-semibold",children:e.title}),(0,r.jsx)("span",{className:"min-w-0 flex-1 truncate text-dim",children:e.statusLine||"працює…"})]},e.file.path))}):null,(0,r.jsxs)("button",{className:`ml-auto flex items-center gap-1.5 rounded-full border border-line bg-panel/95 px-2.5 py-1 text-[11.5px] font-bold shadow-card backdrop-blur transition-transform hover:border-accent/45 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/50 ${s?"scale-110 border-[#e0ae45]/70":""} motion-reduce:transition-none`,"aria-label":"Відкрити пульт агентів",onClick:t,children:[(0,r.jsx)("span",{className:`h-2 w-2 rounded-full ${e.working.length?"animate-pulse bg-ok":"bg-dim"}`}),(0,r.jsx)("span",{children:e.working.length}),(0,r.jsxs)("span",{className:n?"text-[#b8860b]":"text-dim",children:["\xb7 ",n," чекають"]})]})]})}function nJ({file:e,title:t,project:n,currentProject:i,descendants:a,statusLine:o,size:c,tone:d,onOpen:u,onArchive:x}){let p=F(e),f="large"===c;return(0,r.jsxs)("article",{className:`group relative flex ${f?"h-[150px] w-[300px]":"h-[108px] w-[220px]"} shrink-0 flex-col rounded-[8px] border p-3 shadow-card transition-colors hover:border-accent/45 ${"working"===d?"border-ok/40 bg-[#f3fbf5] shadow-[0_0_0_3px_rgba(26,138,62,0.12)]":"stalled"===d?"border-err/35 bg-[#fff5f5]":"waiting"===d?"border-[#e0ae45]/45 bg-[#fff9ed]":"border-line bg-panel"}`,role:"button",tabIndex:0,"aria-label":`Відкрити колонкою ${s(t,80)}`,onClick:()=>u(e),onKeyDown:t=>{"Enter"===t.key&&u(e)},children:["live"===e.activity?null:(0,r.jsx)("button",{type:"button",className:"absolute right-1.5 top-1.5 z-10 hidden h-5 w-5 items-center justify-center rounded-full border border-line bg-bg text-dim hover:border-err/50 hover:text-err focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40 group-hover:flex group-focus-within:flex","aria-label":"Прибрати з пульта",onClick:t=>{t.stopPropagation(),x(e)},onKeyDown:e=>e.stopPropagation(),children:(0,r.jsx)(l.A,{className:"h-3 w-3","aria-hidden":!0})}),(0,r.jsxs)("div",{className:"relative flex min-w-0 items-center gap-1.5",children:[(0,r.jsx)("span",{className:`h-2 w-2 shrink-0 rounded-full ${M(e.activity)}`}),e.model?(0,r.jsx)("span",{className:"min-w-0 truncate rounded-full px-1.5 py-0.5 font-mono text-[9px] font-semibold",style:{backgroundColor:D(e).soft,color:D(e).color},title:[p.label,O(e)].filter(Boolean).join(" \xb7 "),children:e.model}):(0,r.jsx)("span",{className:"shrink-0 rounded-full px-1.5 py-0.5 text-[9.5px] font-bold",style:p.style,children:p.label}),(0,r.jsx)("span",{className:`ml-auto min-w-0 truncate rounded-full border border-line bg-bg px-1.5 py-0.5 text-[9.5px] font-semibold ${n===i?"text-dim":"text-ink"}`,title:n,children:n})]}),(0,r.jsx)("div",{className:`relative mt-2 min-w-0 ${f?"text-[14px]":"text-[12.5px]"} font-bold leading-snug`,title:t,children:(0,r.jsx)("span",{className:"line-clamp-2",children:t})}),(0,r.jsxs)("div",{className:"relative mt-auto flex min-w-0 items-center gap-2 text-[10.5px] font-semibold text-dim",children:[(0,r.jsx)("span",{className:"shrink-0",children:$(e.mtime)}),e.ctx?(0,r.jsx)(tG,{ctx:e.ctx}):null,a?(0,r.jsxs)("span",{className:"inline-flex shrink-0 items-center gap-0.5",children:[(0,r.jsx)(eo.A,{className:"h-3 w-3","aria-hidden":!0})," ",a]}):null]}),o?(0,r.jsx)("div",{className:`relative mt-1 min-w-0 truncate ${f?"text-[11.5px]":"text-[10.5px]"} font-semibold text-ink/75`,children:o}):null,e.pid&&"running"===e.proc?(0,r.jsx)("div",{className:"relative mt-2",onClick:e=>e.stopPropagation(),onKeyDown:e=>e.stopPropagation(),children:(0,r.jsx)(eG,{file:e,compact:!0})}):null]})}function nH({title:e,items:t,size:n,currentProject:l,onOpenFile:i,onArchive:s}){return t.length?(0,r.jsxs)("section",{className:"shrink-0",children:[(0,r.jsxs)("div",{className:"mb-2 flex items-baseline gap-2",children:[(0,r.jsx)("h2",{className:"text-[13px] font-bold",children:e}),(0,r.jsx)("span",{className:"text-[11px] font-semibold text-dim",children:t.length})]}),(0,r.jsx)(eW,{className:"flex flex-wrap gap-2.5",enter:"fade",children:t.map(e=>(0,r.jsx)("div",{"data-flip-key":e.file.path,children:(0,r.jsx)(nJ,{file:e.file,title:e.title,project:e.project,currentProject:l,descendants:e.descendants,statusLine:e.statusLine,size:n,tone:"working"===e.kind?"working":"waiting"===e.kind&&"stalled"===e.file.activity?"stalled":"waiting"===e.kind?"waiting":"quiet",onOpen:i,onArchive:s})},e.file.path))})]}):null}function nY({files:e,flows:t,project:n,onOpenFile:a}){let[o,c]=(0,i.useState)(!1),[d,u]=(0,i.useState)(""),[x,p]=(0,i.useState)(!1),[m,h]=(0,i.useState)(!1),[b,g]=(0,i.useState)(0),v=(0,i.useRef)(null),w=function(e,t){let[n,r]=(0,i.useState)([]),[l,s]=(0,i.useState)(!1);return(0,i.useEffect)(()=>{if(!t||!e)return;let n=!0;s(!0);let l=async()=>{try{let t=await fetch(`/api/timeline?project=${encodeURIComponent(e)}`),l=await t.json();n&&Array.isArray(l.events)&&r(l.events)}catch{}finally{n&&s(!1)}};l();let i=setInterval(l,7e3);return()=>{n=!1,clearInterval(i)}},[e,t]),{events:n,loading:l}}(n,o),{archivedPaths:j,archive:y,unarchive:N}=function(e){let[t,n]=(0,i.useState)(()=>new Set),r=(0,i.useRef)(t);return(0,i.useEffect)(()=>{let e=function(){try{let e=window.localStorage.getItem(nF),t=e?JSON.parse(e):[];return new Set(Array.isArray(t)?t.filter(e=>"string"==typeof e):[])}catch{return new Set}}();r.current=e,n(e)},[]),(0,i.useEffect)(()=>{let t=r.current;if(!t.size)return;let l=new Set(t);for(let t of e)"live"===t.activity&&l.delete(t.path);l.size!==t.size&&(r.current=l,n(l),nU(l))},[e]),{archivedPaths:t,archive:(0,i.useCallback)(e=>{n(t=>{if(t.has(e))return t;let n=new Set(t);return n.add(e),r.current=n,nU(n),n})},[]),unarchive:(0,i.useCallback)(e=>{n(t=>{if(!t.has(e))return t;let n=new Set(t);return n.delete(e),r.current=n,nU(n),n})},[])}}(e),k=H(e,w.events,d,b,j,t),S=H(e,[],"",b,j,t),C=(0,i.useMemo)(()=>e.filter(e=>j.has(e.path)).map(e=>({file:e,title:s(e.title),project:f(e)})).sort((e,t)=>t.file.mtime-e.file.mtime),[e,j]);(0,i.useEffect)(()=>{let e=()=>g(Date.now()/1e3);e();let t=window.setInterval(e,3e4);return()=>window.clearInterval(t)},[]),(0,i.useEffect)(()=>{if(!o)return;let e=e=>{"Escape"===e.key&&c(!1)};return window.addEventListener("keydown",e),window.setTimeout(()=>v.current?.focus(),0),()=>window.removeEventListener("keydown",e)},[o]);let $=e=>{a(e),c(!1)},A=e=>y(e.path);return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(nq,{data:S,onOpen:()=>c(!0)}),o?(0,r.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-ink/28 p-[2.5vh]",onMouseDown:()=>c(!1),children:(0,r.jsxs)("div",{className:"flex h-[95vh] w-[95vw] flex-col overflow-hidden rounded-[8px] border border-line bg-bg shadow-[0_18px_70px_rgb(20_20_30/0.28)]",role:"dialog","aria-modal":"true","aria-label":"Пульт агентів",onMouseDown:e=>e.stopPropagation(),children:[(0,r.jsxs)("header",{className:"flex h-14 shrink-0 items-center gap-3 border-b border-line bg-panel px-4",children:[(0,r.jsx)("div",{className:"text-[15px] font-bold",children:"Пульт"}),(0,r.jsx)("input",{ref:v,value:d,onChange:e=>u(e.target.value),placeholder:"Пошук за назвою або проєктом",className:"h-9 min-w-0 flex-1 rounded-[8px] border border-line bg-bg px-3 text-[13px] outline-none focus-visible:ring-2 focus-visible:ring-accent/40"}),w.loading?(0,r.jsx)("span",{className:"text-[11px] font-semibold text-dim",children:"оновлення…"}):null,(0,r.jsx)("button",{className:"inline-flex h-8 w-8 items-center justify-center rounded-[8px] border border-line bg-bg text-dim hover:text-ink focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40","aria-label":"Закрити пульт",onClick:()=>c(!1),children:(0,r.jsx)(l.A,{className:"h-4 w-4","aria-hidden":!0})})]}),(0,r.jsxs)("div",{className:"min-h-0 flex-1 space-y-5 overflow-y-auto px-4 py-4",children:[(0,r.jsx)(nH,{title:"Чекає тебе",items:k.waiting,size:"large",currentProject:n,onOpenFile:$,onArchive:A}),(0,r.jsx)(nH,{title:"Працюють",items:k.working,size:"large",currentProject:n,onOpenFile:$,onArchive:A}),(0,r.jsx)(nH,{title:"Нещодавні",items:k.recent,size:"small",currentProject:n,onOpenFile:$,onArchive:A}),(0,r.jsxs)("section",{className:"shrink-0",children:[(0,r.jsxs)("button",{className:"flex h-10 w-full items-center justify-between rounded-[8px] border border-line bg-panel px-3 text-left text-[12.5px] font-bold hover:border-accent/40 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40","aria-expanded":x,onClick:()=>p(e=>!e),children:[(0,r.jsx)("span",{children:"Старіше"}),(0,r.jsx)("span",{className:"text-dim",children:k.older.length})]}),x?(0,r.jsx)("div",{className:"mt-2",children:(0,r.jsx)(nH,{title:"",items:k.older,size:"small",currentProject:n,onOpenFile:$,onArchive:A})}):null]}),k.waiting.length||k.working.length||k.recent.length||k.older.length?null:(0,r.jsx)("div",{className:"pt-[18vh] text-center text-[13px] font-semibold text-dim",children:"Нічого не знайдено"}),C.length?(0,r.jsxs)("section",{className:"shrink-0",children:[(0,r.jsxs)("button",{className:"flex h-9 w-full items-center justify-between rounded-[8px] border border-line bg-panel px-3 text-left text-[12px] font-bold text-dim hover:border-accent/40 hover:text-ink focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40","aria-expanded":m,onClick:()=>h(e=>!e),children:[(0,r.jsxs)("span",{children:["Приховані (",C.length,")"]}),(0,r.jsx)("span",{children:m?"сховати":"показати"})]}),m?(0,r.jsx)("div",{className:"mt-2 space-y-1",children:C.map(e=>(0,r.jsxs)("div",{className:"flex min-w-0 items-center gap-2 rounded-[8px] border border-line bg-panel/60 px-3 py-1.5 text-[11.5px] text-dim",children:[(0,r.jsx)("span",{className:"min-w-0 flex-1 truncate",children:e.title}),(0,r.jsx)("span",{className:"shrink-0 truncate text-[10.5px]",children:e.project}),(0,r.jsx)("button",{className:"shrink-0 rounded-full border border-line bg-bg px-2 py-0.5 text-[10.5px] font-semibold text-ink hover:border-accent/40 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40",onClick:()=>N(e.file.path),children:"повернути"})]},e.file.path))}):null]}):null]})]})}):null]})}function nB(){location.hash="#p="+encodeURIComponent(a)}function nX({files:e,onOpen:t}){return(0,r.jsx)("div",{className:"min-h-0 flex-1 overflow-y-auto px-4 py-5",children:(0,r.jsxs)("div",{className:"mx-auto w-full max-w-[760px]",children:[(0,r.jsx)("div",{className:"text-[13.5px] font-semibold text-dim",children:"На схемі порожньо, але в проєкті є записи"}),(0,r.jsx)("div",{className:"mb-3 mt-0.5 text-[12px] text-dim",children:"Клік по рядку відкриває розмову нодою; смітник видаляє її файл з диска назавжди."}),(0,r.jsx)("div",{className:"space-y-1.5",children:e.map(e=>(0,r.jsx)(nW,{file:e,onOpen:t},e.path))})]})})}function nW({file:e,onOpen:t}){let[n,l]=(0,i.useState)(!1),a=F(e);return n?(0,r.jsxs)("div",{className:"flex items-center gap-2 rounded-[8px] border border-line bg-chip/60 px-3 py-1.5 text-[11.5px] font-semibold text-dim",children:[(0,r.jsx)(eE.A,{className:"h-3 w-3 shrink-0","aria-hidden":!0}),(0,r.jsx)("span",{className:"min-w-0 truncate",children:s(e.title,80)}),(0,r.jsx)("span",{className:"shrink-0",children:"\xb7 видалено з диска"})]}):(0,r.jsxs)("div",{className:"flex min-w-0 items-center gap-2 rounded-[8px] border border-line bg-panel px-3 py-1.5 shadow-card",children:[(0,r.jsxs)("button",{type:"button",className:"flex h-full min-w-0 flex-1 items-center gap-2 rounded-[6px] text-left hover:bg-bg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40","aria-label":`Відкрити ${s(e.title,60)}`,onClick:()=>t(e),children:[(0,r.jsx)("span",{className:`h-2 w-2 shrink-0 rounded-full ${M(e.activity)}`}),(0,r.jsx)("span",{className:"shrink-0 rounded-full px-1.5 py-0.5 text-[9.5px] font-bold",style:a.style,children:a.label}),(0,r.jsx)("span",{className:"min-w-0 flex-1 truncate text-[12.5px] font-semibold",title:e.path,children:s(e.title,90)}),(0,r.jsx)("span",{className:"shrink-0 text-[10.5px] font-semibold text-dim",children:$(e.mtime)}),(0,r.jsxs)("span",{className:"shrink-0 text-[10.5px] text-dim",children:[(e.size/1024).toFixed(0)," кБ"]})]}),(0,r.jsx)(eX,{file:e,onDeleted:()=>l(!0)})]})}function nQ({files:e,onArchive:t}){return!e.length||e.some(e=>"running"===e.proc||"live"===e.activity)?null:(0,r.jsxs)("button",{type:"button",className:"inline-flex shrink-0 items-center gap-1 rounded-full border border-line bg-bg px-2 py-0.5 text-[11px] font-semibold text-dim hover:border-accent/40 hover:text-ink focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40",onClick:()=>{t(),nB()},children:[(0,r.jsx)(ec.A,{className:"h-3 w-3","aria-hidden":!0})," В архів"]})}function nK({files:e}){let[t,n]=(0,i.useState)(!1),[l,s]=(0,i.useState)(!1),[a,o]=(0,i.useState)("");if((0,i.useEffect)(()=>{if(!t)return;let e=window.setTimeout(()=>n(!1),6e3);return()=>window.clearTimeout(e)},[t]),!e.length||e.some(e=>"running"===e.proc||"live"===e.activity))return null;let c=async()=>{s(!0),o("");let t=0;for(let n of e)try{let e=await fetch(`/api/log?path=${encodeURIComponent(n.path)}`,{method:"DELETE"}),r=await e.json();e.ok&&r.ok||(t+=1)}catch{t+=1}(s(!1),n(!1),t)?o(`не видалено ${t} з ${e.length}`):nB()};return t?(0,r.jsxs)("span",{className:"inline-flex shrink-0 items-center gap-1 rounded-[10px] border border-err/30 bg-[#fff5f5] px-1.5 py-0.5 text-[11px]",children:[(0,r.jsxs)("span",{className:"px-0.5 font-semibold text-err",children:["Видалити з диска ",e.length," ",E(e.length,"файл","файли","файлів")," проєкту?"]}),(0,r.jsx)("button",{type:"button",className:"rounded-lg bg-err px-2 py-0.5 font-bold text-white disabled:opacity-60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-err/50",disabled:l,onClick:c,children:l?"видаляю…":"Так, видалити"}),(0,r.jsx)("button",{type:"button",className:"rounded-lg border border-line bg-panel px-2 py-0.5 font-semibold text-dim focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40",onClick:()=>n(!1),children:"Скасувати"})]}):(0,r.jsxs)("span",{className:"inline-flex shrink-0 items-center gap-1.5",children:[(0,r.jsx)("button",{type:"button",className:"inline-flex items-center rounded-full border border-line bg-bg p-1 text-dim hover:border-err/40 hover:text-err focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40","aria-label":"Видалити проєкт з диска",title:"Видалити проєкт з диска",onClick:()=>n(!0),children:(0,r.jsx)(eE.A,{className:"h-3 w-3","aria-hidden":!0})}),a?(0,r.jsx)("span",{className:"max-w-[180px] truncate text-[10.5px] font-semibold text-err",children:a}):null]})}var nV=n(4614),nG=n(8980);function nZ(){let[e,t]=(0,i.useState)(!0);return(0,i.useEffect)(()=>t(Q()),[]),(0,r.jsx)("button",{className:"ml-auto inline-flex h-[26px] w-[26px] shrink-0 items-center justify-center rounded-full border border-line bg-panel text-dim hover:text-ink focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40",title:e?"Звукові сповіщення увімкнено":"Звукові сповіщення вимкнено","aria-label":e?"Вимкнути звукові сповіщення":"Увімкнути звукові сповіщення","aria-pressed":e,onClick:()=>{let n=!e;t(n);try{localStorage.setItem(W,n?"on":"off")}catch{}n&&ee("returned",0)},children:e?(0,r.jsx)(nV.A,{className:"h-3.5 w-3.5","aria-hidden":!0}):(0,r.jsx)(nG.A,{className:"h-3.5 w-3.5","aria-hidden":!0})})}function n0({items:e,onSelect:t}){let[n,l]=(0,i.useState)(!1);return(0,r.jsxs)("div",{className:"shrink-0 border-t border-line bg-panel",children:[(0,r.jsxs)("button",{className:"flex h-8 items-center gap-2 px-4 text-[10px] font-bold uppercase tracking-[.6px] text-dim hover:text-ink focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40","aria-expanded":n,onClick:()=>l(e=>!e),children:[(0,r.jsx)(eb.A,{className:`h-3.5 w-3.5 transition-transform ${n?"rotate-90":""}`,"aria-hidden":!0}),"Тихі розмови й задачі",(0,r.jsx)("span",{className:"font-semibold normal-case tracking-normal",children:e.length})]}),n?(0,r.jsx)(eW,{className:"flex max-h-44 flex-wrap items-start gap-1.5 overflow-y-auto px-3 pb-2.5",children:e.map(e=>{let n=F(e),l=s(e.cmdDesc||e.title,70);return(0,r.jsxs)("button",{"data-flip-key":e.path,className:"inline-flex h-7 max-w-[360px] items-center gap-1.5 rounded-full border border-line bg-bg px-2 text-[11px] font-semibold text-ink hover:border-accent/40 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40",title:s(e.title),onClick:()=>t(e),children:[(0,r.jsx)("span",{className:`h-1.5 w-1.5 shrink-0 rounded-full ${M(e.activity)}`}),(0,r.jsx)("span",{className:"shrink-0 rounded-full px-1.5 text-[9px]",style:n.style,children:n.label}),(0,r.jsx)("span",{className:"truncate",children:l}),(0,r.jsx)("span",{className:"shrink-0 font-normal text-dim",children:$(e.mtime)})]},e.path)})}):null]})}let n1=e=>`llvCols:${e}`,n5=e=>`llvDrafts:${e}`;function n2(e){try{let t=JSON.parse(localStorage.getItem(n1(e))??"{}");return{manual:t.manual??[],hidden:t.hidden??[]}}catch{return{manual:[],hidden:[]}}}function n3(e,t){let n=n2(e);n.manual.includes(t)||n.manual.push(t),n.hidden=n.hidden.filter(e=>e!==t),localStorage.setItem(n1(e),JSON.stringify(n))}function n4({files:e,flows:t,project:n,openNonce:l,archived:s,onArchive:a,onUnarchive:o}){let u=(0,i.useRef)(null),x=(0,i.useRef)(null),[p,m]=(0,i.useState)({manual:[],hidden:[]}),[g,w]=(0,i.useState)([]),[y,N]=(0,i.useState)(null),k=(0,i.useRef)(p);(0,i.useEffect)(()=>{let e=n2(n);k.current=e,m(e),w(function(e){try{let t=JSON.parse(sessionStorage.getItem(n5(e))??"[]");return Array.isArray(t)?t.filter(e=>"string"==typeof e):[]}catch{return[]}}(n))},[n,l]),(0,i.useEffect)(()=>()=>{u.current&&window.clearTimeout(u.current)},[]);let S=e=>{k.current=e,m(e),localStorage.setItem(n1(n),JSON.stringify(e))},C=(0,i.useMemo)(()=>{let n=j(t);return n.size?e.filter(e=>!n.has(e.path)):e},[e,t]),$=(0,i.useMemo)(()=>v(C,n),[C,n]),A=(0,i.useMemo)(()=>new Set($.map(e=>e.key)),[$]),M=(0,i.useMemo)(()=>(function(e,t,n){let r=h(e),l=[];for(let i of e){if(f(i)!==t||!d(i)||n.has(i.path))continue;let e=b(i,r);if(!e.length)continue;let s=i.mtime,a=c(i);for(let t of e)s=Math.max(s,t.mtime),a=Math.min(a,c(t));l.push({root:i,branchCount:e.length,smt:s,band:a})}return l.sort((e,t)=>e.band-t.band||t.smt-e.smt)})(C,n,A),[C,n,A]),R=(0,i.useMemo)(()=>{let e;return e=h(C),C.filter(t=>!(f(t)!==n||t.parent||A.has(t.path)||e.get(t.path)?.length)&&"live"!==t.activity).sort((e,t)=>c(e)-c(t)||t.mtime-e.mtime)},[C,n,A]),T=(0,i.useMemo)(()=>new Set($.flatMap(e=>e.columns.map(e=>e.file.path))),[$]),P=(0,i.useMemo)(()=>new Set(p.hidden),[p.hidden]),_=(0,i.useMemo)(()=>{let e=new Map(C.map(e=>[e.path,e]));return p.manual.map(t=>e.get(t)).filter(e=>void 0!==e&&f(e)===n&&!T.has(e.path)&&!P.has(e.path))},[p.manual,C,n,T,P]),I=(0,i.useMemo)(()=>$.reduce((e,t)=>e+t.columns.reduce((e,t)=>e+ +("live"===t.file.activity)+t.tasks.filter(e=>"live"===e.activity).length,0),0),[$]),z=$.filter(e=>!e.orphanTask).length,L=e=>{N(e),u.current&&window.clearTimeout(u.current),u.current=window.setTimeout(()=>N(null),1800)};(0,i.useEffect)(()=>{let e=x.current;e&&(x.current=null,L(e))});let D=e=>{w(e),sessionStorage.setItem(n5(n),JSON.stringify(e))},O=e=>{for(let t of["engine","cwd","text","boot"])sessionStorage.removeItem(ni(e,t));D(g.filter(t=>t!==e))};(0,i.useEffect)(()=>{let e=k.current,t=[...T].filter(t=>!e.manual.includes(t)&&!e.hidden.includes(t));if(!t.length)return;let r={...e,manual:[...e.manual,...t].slice(-40)};k.current=r,m(r),localStorage.setItem(n1(n),JSON.stringify(r))},[T,n]);let F=e=>{let t=f(e);if(t!==n){n3(t,e.path),location.hash="#p="+encodeURIComponent(t);return}if(T.has(e.path)&&!P.has(e.path)||_.some(t=>t.path===e.path))return void L(e.path);let r=p.hidden.filter(t=>t!==e.path);S({manual:T.has(e.path)?p.manual:[...new Set([...p.manual,e.path])],hidden:r}),x.current=e.path},U=[];I?U.push(`${I} ${E(I,"гілка працює","гілки працюють","гілок працюють")} \xb7 ${z} ${E(z,"дерево","дерева","дерев")}`):z&&U.push(`${z} ${E(z,"нещодавня розмова","нещодавні розмови","нещодавніх розмов")}`),M.length&&U.push(`${M.length} ${E(M.length,"тихе дерево","тихі дерева","тихих дерев")}`);let q=$.map(e=>({...e,columns:e.columns.filter(e=>!P.has(e.file.path))})).filter(e=>e.columns.length),J=q.filter(e=>e.orphanTask).map(e=>e.columns[0].file),H=q.filter(e=>!e.orphanTask),Y=H.length>0||_.length>0||g.length>0,B=(0,i.useMemo)(()=>e.filter(e=>f(e)===n).sort((e,t)=>t.mtime-e.mtime),[e,n]);return(0,r.jsxs)("div",{className:"relative flex min-h-0 min-w-0 flex-1 flex-col",children:[(0,r.jsxs)("div",{className:"flex h-10 shrink-0 items-center gap-2.5 border-b border-line bg-panel px-4",children:[(0,r.jsx)("h1",{className:"truncate text-[13.5px] font-bold",children:n}),(0,r.jsx)("span",{className:"truncate text-[11.5px] text-dim",children:U.length?U.join(" \xb7 "):"зараз нічого не працює"}),(0,r.jsx)(nZ,{}),s?(0,r.jsxs)("button",{type:"button",className:"inline-flex shrink-0 items-center gap-1 rounded-full border border-line bg-bg px-2 py-0.5 text-[11px] font-semibold text-dim hover:border-accent/40 hover:text-ink focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40",onClick:()=>o(n),children:[(0,r.jsx)(ed.A,{className:"h-3 w-3","aria-hidden":!0})," Повернути з архіву"]}):(0,r.jsx)(nQ,{files:B,onArchive:()=>a(n)}),(0,r.jsx)(nK,{files:B}),(0,r.jsxs)("button",{type:"button",onClick:()=>{let e="function"==typeof crypto.randomUUID?crypto.randomUUID():Date.now().toString(36)+Math.random().toString(36).slice(2,10);D([...g,e]),x.current="draft::"+e},"aria-label":"Нова розмова з агентом",className:"ml-auto flex shrink-0 items-center gap-1 rounded-[8px] border border-line bg-panel px-2.5 py-1 text-[11.5px] font-bold text-ink shadow-card hover:border-accent/45 hover:text-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40",children:[(0,r.jsx)("span",{className:"text-[13px] leading-none text-accent",children:"+"})," Агент"]})]}),J.length?(0,r.jsx)("div",{className:"shrink-0 border-b border-line bg-[#fbfbfd]",children:J.map(t=>(0,r.jsx)("div",{className:`border-l-4 ${"live"===t.activity?"border-l-ok bg-[#f2faf4]":"border-l-[#9a9aa4]"}`,children:(0,r.jsx)(nr,{file:t,files:e,onSelect:F})},t.path))}):null,Y?(0,r.jsx)(nO,{project:n,groups:H,manual:_,files:e,flows:t,drafts:g,focus:y,onSelect:F,onClose:e=>{fetch("/api/tmux",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({action:"kill",path:e})}).catch(()=>{}),S({manual:p.manual.filter(t=>t!==e),hidden:T.has(e)?[...new Set([...p.hidden,e])]:p.hidden})},onDraftClose:O,onDraftSpawned:(e,t)=>{O(e),F(t)}}):B.length?(0,r.jsx)(nX,{files:B,onOpen:F}):(0,r.jsx)("div",{className:"flex flex-1 items-center justify-center px-4 py-5 text-center",children:(0,r.jsxs)("div",{children:[(0,r.jsx)("div",{className:"text-[13.5px] font-semibold text-dim",children:"На схемі поки порожньо"}),(0,r.jsx)("div",{className:"mt-0.5 text-[12px] text-dim",children:"Відкрий пульт у правому нижньому куті і клікни розмову — вона з'явиться тут"})]})}),(0,r.jsx)(nY,{files:e,flows:t,project:n,onOpenFile:F}),R.length?(0,r.jsx)(n0,{items:R,onSelect:F}):null]})}var n8=n(908);function n6(){let[e,t]=(0,i.useState)(!1),[l,s]=(0,i.useState)({status:"idle"}),[a,o]=(0,i.useState)(null),[c,d]=(0,i.useState)(!1),u=(0,i.useRef)(null);(0,i.useEffect)(()=>{if(!e||"idle"!==l.status)return;let t=!1;return fetch("/api/access").then(e=>e.json()).then(e=>{t||s(e.tailnetUrl?{status:"ready",url:e.tailnetUrl}:{status:"unavailable"})}).catch(()=>{t||s({status:"error"})}),()=>{t=!0}},[e,l.status]),(0,i.useEffect)(()=>{if("ready"!==l.status)return;let e=!1,t=l.url;return n.e(768).then(n.t.bind(n,768,19)).then(({toDataURL:e})=>e(t,{margin:1,width:220})).then(n=>{e||o({url:t,dataUrl:n})}).catch(()=>{}),()=>{e=!0}},[l]);let x="ready"===l.status&&a&&a.url===l.url?a.dataUrl:null;(0,i.useEffect)(()=>{if(!e)return;let n=e=>{"Escape"===e.key&&t(!1)},r=e=>{u.current&&!u.current.contains(e.target)&&t(!1)};return window.addEventListener("keydown",n),window.addEventListener("pointerdown",r),()=>{window.removeEventListener("keydown",n),window.removeEventListener("pointerdown",r)}},[e]);let p=(0,i.useCallback)(()=>{"ready"===l.status&&navigator.clipboard.writeText(l.url).then(()=>{d(!0),window.setTimeout(()=>d(!1),2e3)}).catch(()=>{})},[l]);return(0,r.jsxs)("div",{ref:u,className:"relative ml-auto shrink-0",children:[(0,r.jsx)("button",{type:"button","aria-expanded":e,"aria-label":"Показати QR для входу з телефона",onClick:()=>{e||s({status:"idle"}),t(!e)},className:"flex items-center justify-center rounded-[8px] border border-line bg-panel p-1.5 text-dim hover:border-accent/45 hover:text-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40",children:(0,r.jsx)(n8.A,{className:"h-4 w-4","aria-hidden":!0})}),e?(0,r.jsx)("div",{className:"fixed left-1/2 top-12 z-50 flex w-[260px] -translate-x-1/2 flex-col gap-2.5 rounded-[12px] border border-line bg-panel p-3 shadow-[0_8px_28px_rgba(20,20,30,0.14)] sm:absolute sm:left-0 sm:right-auto sm:top-full sm:mt-1.5 sm:translate-x-0",children:"idle"===l.status?(0,r.jsx)("span",{className:"text-[12px] text-ink",children:"завантаження…"}):"error"===l.status?(0,r.jsx)("span",{className:"text-[12px] font-semibold text-err",children:"не вдалося отримати посилання"}):"unavailable"===l.status?(0,r.jsxs)("span",{className:"text-[12px] leading-relaxed text-ink",children:["Запустіть viewer з доступом через Tailscale:"," ",(0,r.jsx)("code",{className:"break-all rounded bg-chip px-1 py-0.5 font-mono text-[11px]",children:"bunx agent-log-viewer --tailscale"})]}):(0,r.jsxs)(r.Fragment,{children:[x?(0,r.jsx)("img",{src:x,alt:"QR код для входу з телефона",className:"mx-auto h-[220px] w-[220px]"}):(0,r.jsx)("span",{className:"text-[12px] text-ink",children:"генерую QR…"}),(0,r.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,r.jsx)("input",{readOnly:!0,value:l.url,"aria-label":"Посилання для входу з телефона",onFocus:e=>e.currentTarget.select(),className:"min-w-0 flex-1 truncate rounded-[8px] border border-line bg-bg px-2 py-1.5 font-mono text-[10.5px] text-ink focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40"}),(0,r.jsx)("button",{type:"button","aria-label":"Копіювати посилання",onClick:p,className:"flex shrink-0 items-center gap-1 rounded-[8px] border border-line bg-panel px-2 py-1.5 text-[11px] font-semibold text-dim hover:border-accent/45 hover:text-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40",children:c?(0,r.jsx)(eh.A,{className:"h-3.5 w-3.5","aria-hidden":!0}):(0,r.jsx)(eK.A,{className:"h-3.5 w-3.5","aria-hidden":!0})})]}),(0,r.jsx)("span",{className:"text-[10.5px] text-dim",children:"скануй з телефона в тому ж tailnet"})]})}):null]})}function n9({label:e,window:t,engineColor:n,now:l}){var i;let s,a,o;if(!t)return null;let c=Math.max(0,Math.min(100,100-t.usedPercent)),d=c<=10?"#c62828":c<=30?"#d29a2f":n;return(0,r.jsxs)("div",{className:"mt-1.5",children:[(0,r.jsxs)("div",{className:"flex items-baseline justify-between",children:[(0,r.jsx)("span",{className:"text-[11px] font-semibold text-ink",children:e}),(0,r.jsxs)("span",{className:"text-[11px] text-dim",children:["лишилось ",(0,r.jsxs)("span",{className:`font-bold tabular-nums ${c<=30?"":"text-ink"}`,style:c<=30?{color:d}:void 0,children:[Math.round(c),"%"]})]})]}),(0,r.jsx)("div",{className:"mt-1 h-[4px] overflow-hidden rounded-full bg-chip",children:(0,r.jsx)("div",{className:"h-full rounded-full transition-[width] duration-700 ease-out",style:{width:Math.max(c,1.5)+"%",backgroundColor:d}})}),t.resetsAt?(0,r.jsxs)("div",{className:"mt-[3px] text-[10px] leading-none text-dim",children:["скид ",(s=t.resetsAt-l)<=60?"зараз":s<5400?"через "+Math.round(s/60)+" хв":s<129600?"через "+Math.round(s/3600)+" год":"через "+Math.round(s/86400)+" д"," \xb7 ",(i=t.resetsAt,o=(a=new Date(1e3*i)).toLocaleTimeString("uk",{hour:"2-digit",minute:"2-digit",hour12:!1}),i-l<86400?o:a.toLocaleDateString("uk",{day:"numeric",month:"short"})+" "+o)]}):null]})}function n7({label:e,engine:t,limits:n,now:l,staleHint:i}){if(!n||!n.session&&!n.weekly)return null;let s=R[t]??T,a=n.capturedAt&&l-n.capturedAt>1200?$(n.capturedAt):null;return(0,r.jsxs)("div",{className:`mt-2.5 first:mt-0 ${i?"opacity-60":""}`,children:[(0,r.jsxs)("div",{className:"flex items-baseline gap-1.5",children:[(0,r.jsx)("span",{className:"text-[11.5px] font-bold",style:{color:s.color},children:e}),n.plan?(0,r.jsx)("span",{className:"truncate text-[10px] text-dim",children:n.plan}):null,i?(0,r.jsx)("span",{className:"truncate text-[10px] text-dim",children:i}):null,a?(0,r.jsx)("span",{className:"h-1.5 w-1.5 shrink-0 self-center rounded-full bg-[#d29a2f]",title:`дані застарілі: ${a}`}):null]}),(0,r.jsx)(n9,{label:"5 год",window:n.session,engineColor:s.color,now:l}),(0,r.jsx)(n9,{label:"Тиждень",window:n.weekly,engineColor:s.color,now:l})]})}function re(){let[e,t]=(0,i.useState)(null);if((0,i.useEffect)(()=>{let e=!0,n=async()=>{try{let n=await fetch("/api/limits");if(!n.ok)return;let r=await n.json();e&&t(e=>{var t;return{data:(t=e?.data??null,r.claude||r.codex||!t?{claude:r.claude??t?.claude??null,codex:r.codex??t?.codex??null,staleSince:r.staleSince??null}:{...t,staleSince:r.staleSince??t.staleSince??null}),at:Date.now()/1e3}})}catch{}};n();let r=setInterval(n,6e4);return()=>{e=!1,clearInterval(r)}},[]),!e||!e.data.claude&&!e.data.codex)return null;let n=function(e){if(!e)return null;let t=new Date(e);return Number.isNaN(t.getTime())?null:"станом на "+t.toLocaleTimeString("uk",{hour:"2-digit",minute:"2-digit",hour12:!1})}(e.data.staleSince);return(0,r.jsxs)("div",{className:"shrink-0 border-t border-line px-3.5 pb-3 pt-2.5",children:[(0,r.jsx)(n7,{label:"Claude",engine:"claude",limits:e.data.claude,now:e.at,staleHint:n}),(0,r.jsx)(n7,{label:"Codex",engine:"codex",limits:e.data.codex,now:e.at,staleHint:n})]})}var rt=n(5298),rn=n(4526);function rr(){let[e,t]=(0,i.useState)(!1),[n,l]=(0,i.useState)(!1);(0,i.useEffect)(()=>{let e="serviceWorker"in navigator&&"PushManager"in window&&window.isSecureContext;queueMicrotask(()=>l(e)),e&&navigator.serviceWorker.getRegistration("/question-push-sw.js").then(e=>e?.pushManager.getSubscription().then(e=>t(null!==e)))},[]);let s=async()=>{if(!n||"default"===Notification.permission&&"granted"!==await Notification.requestPermission()||"granted"!==Notification.permission)return;let e=await navigator.serviceWorker.register("/question-push-sw.js"),r=await e.pushManager.getSubscription();if(r){await r.unsubscribe(),t(!1);return}let l=await (await fetch("/api/push")).json(),i=await e.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:function(e){let t=atob((e+"=".repeat((4-e.length%4)%4)).replace(/-/g,"+").replace(/_/g,"/")),n=new Uint8Array(t.length);for(let e=0;e<t.length;e+=1)n[e]=t.charCodeAt(e);return n.buffer.slice(0)}(l.publicKey)});await fetch("/api/push",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(i)}),t(!0)};return(0,r.jsx)("button",{className:"inline-flex h-[26px] w-[26px] shrink-0 items-center justify-center rounded-full border border-line bg-panel text-dim hover:text-ink disabled:opacity-45 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40",title:n?e?"Push-сповіщення увімкнено":"Увімкнути push-сповіщення":"Push потребує HTTPS","aria-label":n?e?"Вимкнути push-сповіщення":"Увімкнути push-сповіщення":"Push потребує HTTPS","aria-pressed":e,disabled:!n,onClick:s,children:e?(0,r.jsx)(rt.A,{className:"h-3.5 w-3.5","aria-hidden":!0}):(0,r.jsx)(rn.A,{className:"h-3.5 w-3.5","aria-hidden":!0})})}function rl({files:e,archivedProjects:t,selected:n,onSelect:l}){let[s,o]=(0,i.useState)(""),[c,d]=(0,i.useState)(!1),u=(0,i.useMemo)(()=>m(e),[e]),x=(0,i.useMemo)(()=>{let e=s.trim().toLowerCase();return e?u.filter(t=>t.project.toLowerCase().includes(e)):u},[u,s]),p=(0,i.useMemo)(()=>x.filter(e=>!t.has(e.project)),[x,t]),f=(0,i.useMemo)(()=>x.filter(e=>t.has(e.project)),[x,t]),h=(0,i.useMemo)(()=>u.reduce((e,t)=>e+t.liveCount,0),[u]),b=(0,i.useMemo)(()=>u.reduce((e,t)=>e+t.attentionCount,0),[u]);return(0,r.jsxs)("aside",{className:"flex w-[248px] shrink-0 flex-col border-r border-line bg-panel",children:[(0,r.jsxs)("header",{className:"flex h-10 shrink-0 items-center gap-2 border-b border-line px-4 text-[13.5px] font-bold",children:["Логи агентів",h?(0,r.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full bg-[#e5f6ea] px-2 py-0.5 text-[10.5px] font-bold text-ok",children:[(0,r.jsx)("span",{className:"h-1.5 w-1.5 animate-pulse rounded-full bg-ok"}),h]}):null,b?(0,r.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full bg-[#fff1ca] px-2 py-0.5 text-[10.5px] font-bold text-[#8a5a00]",children:["⏸ ",b]}):null,(0,r.jsx)(n6,{}),(0,r.jsx)(rr,{})]}),(0,r.jsx)("div",{className:"px-2.5 pb-1 pt-2.5",children:(0,r.jsx)("input",{className:"w-full rounded-[9px] border border-line bg-bg px-2.5 py-1.5 text-[12px] outline-none focus-visible:ring-2 focus-visible:ring-accent/40",placeholder:"Фільтр проєктів…",value:s,onChange:e=>o(e.target.value)})}),(0,r.jsxs)("nav",{className:"flex-1 overflow-y-auto px-2 pb-3 pt-1","aria-label":"Проєкти",children:[(0,r.jsx)(ri,{label:"Огляд",live:0,attention:0,total:null,age:"",active:n===a,hasLive:!1,onClick:()=>l(a)}),(0,r.jsx)("div",{className:"mx-2.5 my-1.5 border-t border-line"}),(0,r.jsx)(eW,{children:p.map(e=>(0,r.jsx)("div",{"data-flip-key":e.project,children:(0,r.jsx)(ri,{label:e.project,live:e.liveCount,attention:e.attentionCount,total:e.conversations,age:$(e.smt),active:n===e.project,hasLive:e.liveCount>0,onClick:()=>l(e.project)})},e.project))}),f.length?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{className:"mx-2.5 my-1.5 border-t border-line"}),(0,r.jsxs)("button",{type:"button",className:"mb-0.5 flex w-full items-center gap-1.5 rounded-[10px] px-2.5 py-1.5 text-left text-[11.5px] font-bold text-dim hover:bg-bg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40","aria-expanded":c,onClick:()=>d(e=>!e),children:[(0,r.jsx)(eb.A,{className:`h-3 w-3 shrink-0 transition-transform ${c?"rotate-90":""}`,"aria-hidden":!0}),(0,r.jsx)(ec.A,{className:"h-3 w-3 shrink-0","aria-hidden":!0}),"Архів",(0,r.jsx)("span",{className:"font-semibold",children:f.length})]}),c?f.map(e=>(0,r.jsx)(ri,{label:e.project,live:e.liveCount,attention:e.attentionCount,total:e.conversations,age:$(e.smt),active:n===e.project,hasLive:e.liveCount>0,onClick:()=>l(e.project)},e.project)):null]}):null,p.length||f.length?null:(0,r.jsx)("div",{className:"px-3 py-4 text-center text-[12px] text-dim",children:"Нічого не знайдено"})]}),(0,r.jsx)(re,{})]})}function ri({label:e,live:t,attention:n,total:l,age:i,active:s,hasLive:a,onClick:o}){return(0,r.jsxs)("button",{className:["mb-0.5 flex w-full items-center gap-2 rounded-[10px] border px-2.5 py-2 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40",s?"border-line bg-bg shadow-card":"border-transparent hover:bg-bg"].join(" "),"aria-current":s?"page":void 0,onClick:o,children:[(0,r.jsx)("span",{className:["h-2 w-2 shrink-0 rounded-full",a?"animate-pulse bg-ok":"bg-[#d6d6dd]"].join(" ")}),(0,r.jsxs)("span",{className:"min-w-0 flex-1",children:[(0,r.jsx)("span",{className:`block truncate text-[13px] ${s?"font-bold":"font-semibold"}`,children:e}),i?(0,r.jsx)("span",{className:"block text-[10.5px] text-dim",children:i}):null]}),t>0?(0,r.jsx)("span",{className:"shrink-0 rounded-full bg-[#e5f6ea] px-1.5 py-0.5 text-[10.5px] font-bold text-ok",children:t}):null,n>0?(0,r.jsxs)("span",{className:"shrink-0 rounded-full bg-[#fff1ca] px-1.5 py-0.5 text-[10.5px] font-bold text-[#8a5a00]",children:["⏸ ",n]}):null,null!==l?(0,r.jsx)("span",{className:"shrink-0 text-[11px] font-semibold text-dim",children:l}):null]})}let rs="llvProject";function ra(){let e=location.hash.match(/^#f=(.+)$/);if(e){let t=(e[1]??"").replace(/#question$/,"");try{return{filePath:decodeURIComponent(t),project:null}}catch{return{filePath:t,project:null}}}let t=location.hash.match(/^#p=(.+)$/);if(t)try{return{filePath:null,project:decodeURIComponent(t[1])}}catch{return{filePath:null,project:t[1]}}return{filePath:null,project:null}}function ro(){let e,{files:t,flows:n}=function(){let[e,t]=(0,i.useState)(el);return(0,i.useEffect)(()=>{let e=!0,n="",r=async()=>{try{let r=await fetch("/api/files"),l=await r.text();if(!e||l===n)return;n=l;let i=JSON.parse(l);Array.isArray(i)?t({files:i,flows:[]}):t({files:i.files??[],flows:i.flows??[]})}catch{}};r();let l=setInterval(r,1e4);return()=>{e=!1,clearInterval(l)}},[]),e}();e=(0,i.useRef)(null),(0,i.useEffect)(()=>{let e;return e=()=>{let e=G();e&&"running"!==e.state&&e.resume().catch(()=>void 0)},window.addEventListener("pointerdown",e,{passive:!0}),window.addEventListener("keydown",e),()=>{window.removeEventListener("pointerdown",e),window.removeEventListener("keydown",e)}},[]),(0,i.useEffect)(()=>{if(!t.length)return;let n=new Map;for(let e of t)p(e)||n.set(e.path,X(e));let r=e.current;if(e.current=n,!r)return;let l=0;for(let[e,i]of n){let n=t.find(t=>t.path===e),s=n?.pendingQuestion||n?.waitingInput?"question":et[i];if(!s)continue;let a=r.get(e);("live"===a||void 0===a)&&ee(s,function(e){let t=K.get(e);if(!t)return 0;let n=t.getBoundingClientRect();return n.width?Math.max(-1,Math.min(1,(n.left+n.width/2)/window.innerWidth*2-1)):0}(e),220*l++)}},[t]);let{archivedProjects:s,archiveProject:o,unarchiveProject:c}=function(e){let[t,n]=(0,i.useState)(()=>new Set),r=(0,i.useRef)(t);return(0,i.useEffect)(()=>{let e=function(){try{let e=window.localStorage.getItem(en),t=e?JSON.parse(e):[];return new Set(Array.isArray(t)?t.filter(e=>"string"==typeof e):[])}catch{return new Set}}();r.current=e,n(e)},[]),(0,i.useEffect)(()=>{let t=r.current;if(!t.size)return;let l=new Set(t);for(let t of e)"live"===t.activity&&l.delete(f(t));l.size!==t.size&&(r.current=l,n(l),er(l))},[e]),{archivedProjects:t,archiveProject:(0,i.useCallback)(e=>{n(t=>{if(t.has(e))return t;let n=new Set(t);return n.add(e),r.current=n,er(n),n})},[]),unarchiveProject:(0,i.useCallback)(e=>{n(t=>{if(!t.has(e))return t;let n=new Set(t);return n.delete(e),r.current=n,er(n),n})},[])}}(t),[d,u]=(0,i.useState)(a),[x,m]=(0,i.useState)(null),[h,b]=(0,i.useState)(null),g=(0,i.useRef)(null),[v,w]=(0,i.useState)(0);(0,i.useEffect)(()=>{let e=ra();e.filePath&&m(e.filePath);let t=e.project??localStorage.getItem(rs);t&&u(t)},[]),(0,i.useEffect)(()=>{let e=()=>{let e=ra();e.filePath?m(e.filePath):e.project&&u(e.project)};return window.addEventListener("hashchange",e),()=>window.removeEventListener("hashchange",e)},[]);let j=(0,i.useCallback)(e=>{u(e),localStorage.setItem(rs,e),e!==a?history.replaceState(null,"","#p="+encodeURIComponent(e)):history.replaceState(null,"",location.pathname)},[]),y=(0,i.useCallback)(e=>{let t=f(e);n3(t,e.path),j(t),w(e=>e+1)},[j]);(0,i.useEffect)(()=>{if(!x||0===t.length)return;let e=t.find(e=>e.path===x);e&&y(e),m(null)},[x,t,y]),(0,i.useEffect)(()=>{let e=t.filter(e=>e.pendingQuestion||e.waitingInput).length;document.title=e?`(${e}) Agent Log Viewer`:"Agent Log Viewer"},[t]),(0,i.useEffect)(()=>{let e=t.map(e=>({file:e,id:e.pendingQuestion?.toolUseId??(e.waitingInput?`${e.path}:waiting:${Math.floor(e.waitingInput.since)}`:null)})).filter(e=>null!==e.id);if(null===g.current){g.current=new Set(e.map(e=>e.id));return}let n=e.find(e=>!g.current.has(e.id));for(let t of e)g.current.add(t.id);n&&queueMicrotask(()=>b(n.file.path))},[t]);let N=h?t.find(e=>e.path===h):null;return(0,r.jsxs)("div",{className:"flex h-full",children:[(0,r.jsx)(rl,{files:t,archivedProjects:s,selected:d,onSelect:j}),(0,r.jsxs)("main",{className:"flex min-w-0 flex-1 flex-col",children:[N?(0,r.jsxs)("div",{className:"fixed right-4 top-4 z-50 flex max-w-[360px] gap-2 rounded-[8px] border border-[#e0ae45]/45 bg-[#fff9ed] px-4 py-3 text-[13px] font-semibold text-ink shadow-card",children:[(0,r.jsxs)("button",{className:"min-w-0 flex-1 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40",onClick:()=>{y(N),b(null)},children:[(0,r.jsx)("span",{className:"block text-[11px] font-bold text-[#8a5a00]",children:"Агент чекає відповіді"}),(0,r.jsx)("span",{className:"line-clamp-2",children:N.title})]}),(0,r.jsx)("button",{className:"mt-0.5 flex h-6 w-6 shrink-0 items-center justify-center rounded-full border border-line bg-bg text-dim hover:text-ink focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40","aria-label":"Закрити сповіщення",onClick:()=>b(null),children:(0,r.jsx)(l.A,{className:"h-3.5 w-3.5","aria-hidden":!0})})]}):null,d===a?(0,r.jsx)(es,{files:t,archivedProjects:s,onSelectProject:j,onSelectFile:y}):(0,r.jsx)(n4,{files:t,flows:n,project:d,openNonce:v,archived:s.has(d),onArchive:o,onUnarchive:c})]})]})}}},e=>{e.O(0,[703,441,794,358],()=>e(e.s=5039)),_N_E=e.O()}]);