@polderlabs/bizar 4.4.2 → 4.4.4

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.
@@ -1,331 +0,0 @@
1
- var Wt=Object.defineProperty;var Kt=(s,a,t)=>a in s?Wt(s,a,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[a]=t;var Xs=(s,a,t)=>Kt(s,typeof a!="symbol"?a+"":a,t);import{c as Y,r,a as A,j as e,R as de,C as Bs,F as Be,b as Ae,d as Ue,M as Xe,B as Fe,S as Pe,A as ze,e as Me,f as Je,H as ts,g as ht,h as Oe,i as Z,u as ke,P as je,k as z,l as he,X as $e,m as Gt,T as Ee,n as ys,I as bs,o as ye,p as ge,q as Qe,s as mt,t as be,v as Fs,w as Yt,x as Xt,y as Jt,z as Qt,D as Zt,E as ea,G as sa,J as as,K as ut,L as Us,N as rs,O as pt,Q as ta,U as xt,V as jt,W as ps,Y as aa,Z as na,_ as ia,$ as la,a0 as ks,a1 as ra,a2 as Js,a3 as ca,a4 as Ye,a5 as Ge,a6 as Qs,a7 as oa,a8 as da,a9 as ha,aa as Hs,ab as es,ac as _s,ad as ma,ae as ua,af as pa,ag as ft,ah as xa,ai as gt,aj as ja,ak as fa,al as ga,am as va,an as ya,ao as ba}from"./mobile-Dvq2d53Y.js";/**
2
- * @license lucide-react v0.460.0 - ISC
3
- *
4
- * This source code is licensed under the ISC license.
5
- * See the LICENSE file in the root directory of this source tree.
6
- */const xs=Y("ArchiveRestore",[["rect",{width:"20",height:"5",x:"2",y:"3",rx:"1",key:"1wp1u1"}],["path",{d:"M4 8v11a2 2 0 0 0 2 2h2",key:"tvwodi"}],["path",{d:"M20 8v11a2 2 0 0 1-2 2h-2",key:"1gkqxj"}],["path",{d:"m9 15 3-3 3 3",key:"1pd0qc"}],["path",{d:"M12 12v9",key:"192myk"}]]);/**
7
- * @license lucide-react v0.460.0 - ISC
8
- *
9
- * This source code is licensed under the ISC license.
10
- * See the LICENSE file in the root directory of this source tree.
11
- */const vt=Y("ArrowLeft",[["path",{d:"m12 19-7-7 7-7",key:"1l729n"}],["path",{d:"M19 12H5",key:"x3x0zl"}]]);/**
12
- * @license lucide-react v0.460.0 - ISC
13
- *
14
- * This source code is licensed under the ISC license.
15
- * See the LICENSE file in the root directory of this source tree.
16
- */const ka=Y("Book",[["path",{d:"M4 19.5v-15A2.5 2.5 0 0 1 6.5 2H19a1 1 0 0 1 1 1v18a1 1 0 0 1-1 1H6.5a1 1 0 0 1 0-5H20",key:"k3hazp"}]]);/**
17
- * @license lucide-react v0.460.0 - ISC
18
- *
19
- * This source code is licensed under the ISC license.
20
- * See the LICENSE file in the root directory of this source tree.
21
- */const Na=Y("Brain",[["path",{d:"M12 5a3 3 0 1 0-5.997.125 4 4 0 0 0-2.526 5.77 4 4 0 0 0 .556 6.588A4 4 0 1 0 12 18Z",key:"l5xja"}],["path",{d:"M12 5a3 3 0 1 1 5.997.125 4 4 0 0 1 2.526 5.77 4 4 0 0 1-.556 6.588A4 4 0 1 1 12 18Z",key:"ep3f8r"}],["path",{d:"M15 13a4.5 4.5 0 0 1-3-4 4.5 4.5 0 0 1-3 4",key:"1p4c4q"}],["path",{d:"M17.599 6.5a3 3 0 0 0 .399-1.375",key:"tmeiqw"}],["path",{d:"M6.003 5.125A3 3 0 0 0 6.401 6.5",key:"105sqy"}],["path",{d:"M3.477 10.896a4 4 0 0 1 .585-.396",key:"ql3yin"}],["path",{d:"M19.938 10.5a4 4 0 0 1 .585.396",key:"1qfode"}],["path",{d:"M6 18a4 4 0 0 1-1.967-.516",key:"2e4loj"}],["path",{d:"M19.967 17.484A4 4 0 0 1 18 18",key:"159ez6"}]]);/**
22
- * @license lucide-react v0.460.0 - ISC
23
- *
24
- * This source code is licensed under the ISC license.
25
- * See the LICENSE file in the root directory of this source tree.
26
- */const yt=Y("Calendar",[["path",{d:"M8 2v4",key:"1cmpym"}],["path",{d:"M16 2v4",key:"4m81vk"}],["rect",{width:"18",height:"18",x:"3",y:"4",rx:"2",key:"1hopcy"}],["path",{d:"M3 10h18",key:"8toen8"}]]);/**
27
- * @license lucide-react v0.460.0 - ISC
28
- *
29
- * This source code is licensed under the ISC license.
30
- * See the LICENSE file in the root directory of this source tree.
31
- */const $s=Y("Check",[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]]);/**
32
- * @license lucide-react v0.460.0 - ISC
33
- *
34
- * This source code is licensed under the ISC license.
35
- * See the LICENSE file in the root directory of this source tree.
36
- */const wa=Y("ChevronLeft",[["path",{d:"m15 18-6-6 6-6",key:"1wnfg3"}]]);/**
37
- * @license lucide-react v0.460.0 - ISC
38
- *
39
- * This source code is licensed under the ISC license.
40
- * See the LICENSE file in the root directory of this source tree.
41
- */const Ca=Y("CircleCheckBig",[["path",{d:"M21.801 10A10 10 0 1 1 17 3.335",key:"yps3ct"}],["path",{d:"m9 11 3 3L22 4",key:"1pflzl"}]]);/**
42
- * @license lucide-react v0.460.0 - ISC
43
- *
44
- * This source code is licensed under the ISC license.
45
- * See the LICENSE file in the root directory of this source tree.
46
- */const Zs=Y("CirclePause",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["line",{x1:"10",x2:"10",y1:"15",y2:"9",key:"c1nkhi"}],["line",{x1:"14",x2:"14",y1:"15",y2:"9",key:"h65svq"}]]);/**
47
- * @license lucide-react v0.460.0 - ISC
48
- *
49
- * This source code is licensed under the ISC license.
50
- * See the LICENSE file in the root directory of this source tree.
51
- */const Rs=Y("CirclePlay",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["polygon",{points:"10 8 16 12 10 16 10 8",key:"1cimsy"}]]);/**
52
- * @license lucide-react v0.460.0 - ISC
53
- *
54
- * This source code is licensed under the ISC license.
55
- * See the LICENSE file in the root directory of this source tree.
56
- */const bt=Y("CircleX",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m15 9-6 6",key:"1uzhvr"}],["path",{d:"m9 9 6 6",key:"z0biqf"}]]);/**
57
- * @license lucide-react v0.460.0 - ISC
58
- *
59
- * This source code is licensed under the ISC license.
60
- * See the LICENSE file in the root directory of this source tree.
61
- */const Sa=Y("Circle",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}]]);/**
62
- * @license lucide-react v0.460.0 - ISC
63
- *
64
- * This source code is licensed under the ISC license.
65
- * See the LICENSE file in the root directory of this source tree.
66
- */const ws=Y("Cpu",[["rect",{width:"16",height:"16",x:"4",y:"4",rx:"2",key:"14l7u7"}],["rect",{width:"6",height:"6",x:"9",y:"9",rx:"1",key:"5aljv4"}],["path",{d:"M15 2v2",key:"13l42r"}],["path",{d:"M15 20v2",key:"15mkzm"}],["path",{d:"M2 15h2",key:"1gxd5l"}],["path",{d:"M2 9h2",key:"1bbxkp"}],["path",{d:"M20 15h2",key:"19e6y8"}],["path",{d:"M20 9h2",key:"19tzq7"}],["path",{d:"M9 2v2",key:"165o2o"}],["path",{d:"M9 20v2",key:"i2bqo8"}]]);/**
67
- * @license lucide-react v0.460.0 - ISC
68
- *
69
- * This source code is licensed under the ISC license.
70
- * See the LICENSE file in the root directory of this source tree.
71
- */const za=Y("Database",[["ellipse",{cx:"12",cy:"5",rx:"9",ry:"3",key:"msslwz"}],["path",{d:"M3 5V19A9 3 0 0 0 21 19V5",key:"1wlel7"}],["path",{d:"M3 12A9 3 0 0 0 21 12",key:"mv7ke4"}]]);/**
72
- * @license lucide-react v0.460.0 - ISC
73
- *
74
- * This source code is licensed under the ISC license.
75
- * See the LICENSE file in the root directory of this source tree.
76
- */const Ta=Y("Diamond",[["path",{d:"M2.7 10.3a2.41 2.41 0 0 0 0 3.41l7.59 7.59a2.41 2.41 0 0 0 3.41 0l7.59-7.59a2.41 2.41 0 0 0 0-3.41l-7.59-7.59a2.41 2.41 0 0 0-3.41 0Z",key:"1f1r0c"}]]);/**
77
- * @license lucide-react v0.460.0 - ISC
78
- *
79
- * This source code is licensed under the ISC license.
80
- * See the LICENSE file in the root directory of this source tree.
81
- */const De=Y("Download",[["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}],["polyline",{points:"7 10 12 15 17 10",key:"2ggqvy"}],["line",{x1:"12",x2:"12",y1:"15",y2:"3",key:"1vk2je"}]]);/**
82
- * @license lucide-react v0.460.0 - ISC
83
- *
84
- * This source code is licensed under the ISC license.
85
- * See the LICENSE file in the root directory of this source tree.
86
- */const Aa=Y("Ellipsis",[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"19",cy:"12",r:"1",key:"1wjl8i"}],["circle",{cx:"5",cy:"12",r:"1",key:"1pcz8c"}]]);/**
87
- * @license lucide-react v0.460.0 - ISC
88
- *
89
- * This source code is licensed under the ISC license.
90
- * See the LICENSE file in the root directory of this source tree.
91
- */const et=Y("EyeOff",[["path",{d:"M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49",key:"ct8e1f"}],["path",{d:"M14.084 14.158a3 3 0 0 1-4.242-4.242",key:"151rxh"}],["path",{d:"M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143",key:"13bj9a"}],["path",{d:"m2 2 20 20",key:"1ooewy"}]]);/**
92
- * @license lucide-react v0.460.0 - ISC
93
- *
94
- * This source code is licensed under the ISC license.
95
- * See the LICENSE file in the root directory of this source tree.
96
- */const ns=Y("Eye",[["path",{d:"M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0",key:"1nclc0"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]]);/**
97
- * @license lucide-react v0.460.0 - ISC
98
- *
99
- * This source code is licensed under the ISC license.
100
- * See the LICENSE file in the root directory of this source tree.
101
- */const Vs=Y("FileCode2",[["path",{d:"M4 22h14a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v4",key:"1pf5j1"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"m5 12-3 3 3 3",key:"oke12k"}],["path",{d:"m9 18 3-3-3-3",key:"112psh"}]]);/**
102
- * @license lucide-react v0.460.0 - ISC
103
- *
104
- * This source code is licensed under the ISC license.
105
- * See the LICENSE file in the root directory of this source tree.
106
- */const Ma=Y("FileCode",[["path",{d:"M10 12.5 8 15l2 2.5",key:"1tg20x"}],["path",{d:"m14 12.5 2 2.5-2 2.5",key:"yinavb"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7z",key:"1mlx9k"}]]);/**
107
- * @license lucide-react v0.460.0 - ISC
108
- *
109
- * This source code is licensed under the ISC license.
110
- * See the LICENSE file in the root directory of this source tree.
111
- */const $a=Y("File",[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}]]);/**
112
- * @license lucide-react v0.460.0 - ISC
113
- *
114
- * This source code is licensed under the ISC license.
115
- * See the LICENSE file in the root directory of this source tree.
116
- */const Ra=Y("Filter",[["polygon",{points:"22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3",key:"1yg77f"}]]);/**
117
- * @license lucide-react v0.460.0 - ISC
118
- *
119
- * This source code is licensed under the ISC license.
120
- * See the LICENSE file in the root directory of this source tree.
121
- */const Ia=Y("FlaskConical",[["path",{d:"M10 2v7.527a2 2 0 0 1-.211.896L4.72 20.55a1 1 0 0 0 .9 1.45h12.76a1 1 0 0 0 .9-1.45l-5.069-10.127A2 2 0 0 1 14 9.527V2",key:"pzvekw"}],["path",{d:"M8.5 2h7",key:"csnxdl"}],["path",{d:"M7 16h10",key:"wp8him"}]]);/**
122
- * @license lucide-react v0.460.0 - ISC
123
- *
124
- * This source code is licensed under the ISC license.
125
- * See the LICENSE file in the root directory of this source tree.
126
- */const Da=Y("FolderOpen",[["path",{d:"m6 14 1.5-2.9A2 2 0 0 1 9.24 10H20a2 2 0 0 1 1.94 2.5l-1.54 6a2 2 0 0 1-1.95 1.5H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H18a2 2 0 0 1 2 2v2",key:"usdka0"}]]);/**
127
- * @license lucide-react v0.460.0 - ISC
128
- *
129
- * This source code is licensed under the ISC license.
130
- * See the LICENSE file in the root directory of this source tree.
131
- */const La=Y("FolderPlus",[["path",{d:"M12 10v6",key:"1bos4e"}],["path",{d:"M9 13h6",key:"1uhe8q"}],["path",{d:"M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z",key:"1kt360"}]]);/**
132
- * @license lucide-react v0.460.0 - ISC
133
- *
134
- * This source code is licensed under the ISC license.
135
- * See the LICENSE file in the root directory of this source tree.
136
- */const Pa=Y("FolderSearch",[["path",{d:"M10.7 20H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H20a2 2 0 0 1 2 2v4.1",key:"1bw5m7"}],["path",{d:"m21 21-1.9-1.9",key:"1g2n9r"}],["circle",{cx:"17",cy:"17",r:"3",key:"18b49y"}]]);/**
137
- * @license lucide-react v0.460.0 - ISC
138
- *
139
- * This source code is licensed under the ISC license.
140
- * See the LICENSE file in the root directory of this source tree.
141
- */const Ea=Y("GitBranch",[["line",{x1:"6",x2:"6",y1:"3",y2:"15",key:"17qcm7"}],["circle",{cx:"18",cy:"6",r:"3",key:"1h7g24"}],["circle",{cx:"6",cy:"18",r:"3",key:"fqmcym"}],["path",{d:"M18 9a9 9 0 0 1-9 9",key:"n2h4wq"}]]);/**
142
- * @license lucide-react v0.460.0 - ISC
143
- *
144
- * This source code is licensed under the ISC license.
145
- * See the LICENSE file in the root directory of this source tree.
146
- */const is=Y("Globe",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20",key:"13o1zl"}],["path",{d:"M2 12h20",key:"9i4pu4"}]]);/**
147
- * @license lucide-react v0.460.0 - ISC
148
- *
149
- * This source code is licensed under the ISC license.
150
- * See the LICENSE file in the root directory of this source tree.
151
- */const Oa=Y("House",[["path",{d:"M15 21v-8a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v8",key:"5wwlr5"}],["path",{d:"M3 10a2 2 0 0 1 .709-1.528l7-5.999a2 2 0 0 1 2.582 0l7 5.999A2 2 0 0 1 21 10v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z",key:"1d0kgt"}]]);/**
152
- * @license lucide-react v0.460.0 - ISC
153
- *
154
- * This source code is licensed under the ISC license.
155
- * See the LICENSE file in the root directory of this source tree.
156
- */const Ba=Y("Inbox",[["polyline",{points:"22 12 16 12 14 15 10 15 8 12 2 12",key:"o97t9d"}],["path",{d:"M5.45 5.11 2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z",key:"oot6mr"}]]);/**
157
- * @license lucide-react v0.460.0 - ISC
158
- *
159
- * This source code is licensed under the ISC license.
160
- * See the LICENSE file in the root directory of this source tree.
161
- */const Fa=Y("KeyRound",[["path",{d:"M2.586 17.414A2 2 0 0 0 2 18.828V21a1 1 0 0 0 1 1h3a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h1a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h.172a2 2 0 0 0 1.414-.586l.814-.814a6.5 6.5 0 1 0-4-4z",key:"1s6t7t"}],["circle",{cx:"16.5",cy:"7.5",r:".5",fill:"currentColor",key:"w0ekpg"}]]);/**
162
- * @license lucide-react v0.460.0 - ISC
163
- *
164
- * This source code is licensed under the ISC license.
165
- * See the LICENSE file in the root directory of this source tree.
166
- */const kt=Y("Layers",[["path",{d:"m12.83 2.18a2 2 0 0 0-1.66 0L2.6 6.08a1 1 0 0 0 0 1.83l8.58 3.91a2 2 0 0 0 1.66 0l8.58-3.9a1 1 0 0 0 0-1.83Z",key:"8b97xw"}],["path",{d:"m22 17.65-9.17 4.16a2 2 0 0 1-1.66 0L2 17.65",key:"dd6zsq"}],["path",{d:"m22 12.65-9.17 4.16a2 2 0 0 1-1.66 0L2 12.65",key:"ep9fru"}]]);/**
167
- * @license lucide-react v0.460.0 - ISC
168
- *
169
- * This source code is licensed under the ISC license.
170
- * See the LICENSE file in the root directory of this source tree.
171
- */const Ua=Y("LayoutDashboard",[["rect",{width:"7",height:"9",x:"3",y:"3",rx:"1",key:"10lvy0"}],["rect",{width:"7",height:"5",x:"14",y:"3",rx:"1",key:"16une8"}],["rect",{width:"7",height:"9",x:"14",y:"12",rx:"1",key:"1hutg5"}],["rect",{width:"7",height:"5",x:"3",y:"16",rx:"1",key:"ldoo1y"}]]);/**
172
- * @license lucide-react v0.460.0 - ISC
173
- *
174
- * This source code is licensed under the ISC license.
175
- * See the LICENSE file in the root directory of this source tree.
176
- */const Is=Y("LayoutTemplate",[["rect",{width:"18",height:"7",x:"3",y:"3",rx:"1",key:"f1a2em"}],["rect",{width:"9",height:"7",x:"3",y:"14",rx:"1",key:"jqznyg"}],["rect",{width:"5",height:"7",x:"16",y:"14",rx:"1",key:"q5h2i8"}]]);/**
177
- * @license lucide-react v0.460.0 - ISC
178
- *
179
- * This source code is licensed under the ISC license.
180
- * See the LICENSE file in the root directory of this source tree.
181
- */const Nt=Y("Link2",[["path",{d:"M9 17H7A5 5 0 0 1 7 7h2",key:"8i5ue5"}],["path",{d:"M15 7h2a5 5 0 1 1 0 10h-2",key:"1b9ql8"}],["line",{x1:"8",x2:"16",y1:"12",y2:"12",key:"1jonct"}]]);/**
182
- * @license lucide-react v0.460.0 - ISC
183
- *
184
- * This source code is licensed under the ISC license.
185
- * See the LICENSE file in the root directory of this source tree.
186
- */const Ha=Y("LoaderCircle",[["path",{d:"M21 12a9 9 0 1 1-6.219-8.56",key:"13zald"}]]);/**
187
- * @license lucide-react v0.460.0 - ISC
188
- *
189
- * This source code is licensed under the ISC license.
190
- * See the LICENSE file in the root directory of this source tree.
191
- */const st=Y("MapPin",[["path",{d:"M20 10c0 4.993-5.539 10.193-7.399 11.799a1 1 0 0 1-1.202 0C9.539 20.193 4 14.993 4 10a8 8 0 0 1 16 0",key:"1r0f0z"}],["circle",{cx:"12",cy:"10",r:"3",key:"ilqhr7"}]]);/**
192
- * @license lucide-react v0.460.0 - ISC
193
- *
194
- * This source code is licensed under the ISC license.
195
- * See the LICENSE file in the root directory of this source tree.
196
- */const ls=Y("Map",[["path",{d:"M14.106 5.553a2 2 0 0 0 1.788 0l3.659-1.83A1 1 0 0 1 21 4.619v12.764a1 1 0 0 1-.553.894l-4.553 2.277a2 2 0 0 1-1.788 0l-4.212-2.106a2 2 0 0 0-1.788 0l-3.659 1.83A1 1 0 0 1 3 19.381V6.618a1 1 0 0 1 .553-.894l4.553-2.277a2 2 0 0 1 1.788 0z",key:"169xi5"}],["path",{d:"M15 5.764v15",key:"1pn4in"}],["path",{d:"M9 3.236v15",key:"1uimfh"}]]);/**
197
- * @license lucide-react v0.460.0 - ISC
198
- *
199
- * This source code is licensed under the ISC license.
200
- * See the LICENSE file in the root directory of this source tree.
201
- */const _a=Y("Maximize2",[["polyline",{points:"15 3 21 3 21 9",key:"mznyad"}],["polyline",{points:"9 21 3 21 3 15",key:"1avn1i"}],["line",{x1:"21",x2:"14",y1:"3",y2:"10",key:"ota7mn"}],["line",{x1:"3",x2:"10",y1:"21",y2:"14",key:"1atl0r"}]]);/**
202
- * @license lucide-react v0.460.0 - ISC
203
- *
204
- * This source code is licensed under the ISC license.
205
- * See the LICENSE file in the root directory of this source tree.
206
- */const Va=Y("Minus",[["path",{d:"M5 12h14",key:"1ays0h"}]]);/**
207
- * @license lucide-react v0.460.0 - ISC
208
- *
209
- * This source code is licensed under the ISC license.
210
- * See the LICENSE file in the root directory of this source tree.
211
- */const qa=Y("OctagonAlert",[["path",{d:"M12 16h.01",key:"1drbdi"}],["path",{d:"M12 8v4",key:"1got3b"}],["path",{d:"M15.312 2a2 2 0 0 1 1.414.586l4.688 4.688A2 2 0 0 1 22 8.688v6.624a2 2 0 0 1-.586 1.414l-4.688 4.688a2 2 0 0 1-1.414.586H8.688a2 2 0 0 1-1.414-.586l-4.688-4.688A2 2 0 0 1 2 15.312V8.688a2 2 0 0 1 .586-1.414l4.688-4.688A2 2 0 0 1 8.688 2z",key:"1fd625"}]]);/**
212
- * @license lucide-react v0.460.0 - ISC
213
- *
214
- * This source code is licensed under the ISC license.
215
- * See the LICENSE file in the root directory of this source tree.
216
- */const wt=Y("Palette",[["circle",{cx:"13.5",cy:"6.5",r:".5",fill:"currentColor",key:"1okk4w"}],["circle",{cx:"17.5",cy:"10.5",r:".5",fill:"currentColor",key:"f64h9f"}],["circle",{cx:"8.5",cy:"7.5",r:".5",fill:"currentColor",key:"fotxhn"}],["circle",{cx:"6.5",cy:"12.5",r:".5",fill:"currentColor",key:"qy21gx"}],["path",{d:"M12 2C6.5 2 2 6.5 2 12s4.5 10 10 10c.926 0 1.648-.746 1.648-1.688 0-.437-.18-.835-.437-1.125-.29-.289-.438-.652-.438-1.125a1.64 1.64 0 0 1 1.668-1.668h1.996c3.051 0 5.555-2.503 5.555-5.554C21.965 6.012 17.461 2 12 2z",key:"12rzf8"}]]);/**
217
- * @license lucide-react v0.460.0 - ISC
218
- *
219
- * This source code is licensed under the ISC license.
220
- * See the LICENSE file in the root directory of this source tree.
221
- */const Wa=Y("PanelLeftClose",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M9 3v18",key:"fh3hqa"}],["path",{d:"m16 15-3-3 3-3",key:"14y99z"}]]);/**
222
- * @license lucide-react v0.460.0 - ISC
223
- *
224
- * This source code is licensed under the ISC license.
225
- * See the LICENSE file in the root directory of this source tree.
226
- */const Ka=Y("PanelLeftOpen",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M9 3v18",key:"fh3hqa"}],["path",{d:"m14 9 3 3-3 3",key:"8010ee"}]]);/**
227
- * @license lucide-react v0.460.0 - ISC
228
- *
229
- * This source code is licensed under the ISC license.
230
- * See the LICENSE file in the root directory of this source tree.
231
- */const Ga=Y("PanelsTopLeft",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M3 9h18",key:"1pudct"}],["path",{d:"M9 21V9",key:"1oto5p"}]]);/**
232
- * @license lucide-react v0.460.0 - ISC
233
- *
234
- * This source code is licensed under the ISC license.
235
- * See the LICENSE file in the root directory of this source tree.
236
- */const js=Y("Plug",[["path",{d:"M12 22v-5",key:"1ega77"}],["path",{d:"M9 8V2",key:"14iosj"}],["path",{d:"M15 8V2",key:"18g5xt"}],["path",{d:"M18 8v5a4 4 0 0 1-4 4h-4a4 4 0 0 1-4-4V8Z",key:"osxo6l"}]]);/**
237
- * @license lucide-react v0.460.0 - ISC
238
- *
239
- * This source code is licensed under the ISC license.
240
- * See the LICENSE file in the root directory of this source tree.
241
- */const Ya=Y("PowerOff",[["path",{d:"M18.36 6.64A9 9 0 0 1 20.77 15",key:"dxknvb"}],["path",{d:"M6.16 6.16a9 9 0 1 0 12.68 12.68",key:"1x7qb5"}],["path",{d:"M12 2v4",key:"3427ic"}],["path",{d:"m2 2 20 20",key:"1ooewy"}]]);/**
242
- * @license lucide-react v0.460.0 - ISC
243
- *
244
- * This source code is licensed under the ISC license.
245
- * See the LICENSE file in the root directory of this source tree.
246
- */const fs=Y("Puzzle",[["path",{d:"M15.39 4.39a1 1 0 0 0 1.68-.474 2.5 2.5 0 1 1 3.014 3.015 1 1 0 0 0-.474 1.68l1.683 1.682a2.414 2.414 0 0 1 0 3.414L19.61 15.39a1 1 0 0 1-1.68-.474 2.5 2.5 0 1 0-3.014 3.015 1 1 0 0 1 .474 1.68l-1.683 1.682a2.414 2.414 0 0 1-3.414 0L8.61 19.61a1 1 0 0 0-1.68.474 2.5 2.5 0 1 1-3.014-3.015 1 1 0 0 0 .474-1.68l-1.683-1.682a2.414 2.414 0 0 1 0-3.414L4.39 8.61a1 1 0 0 1 1.68.474 2.5 2.5 0 1 0 3.014-3.015 1 1 0 0 1-.474-1.68l1.683-1.682a2.414 2.414 0 0 1 3.414 0z",key:"w46dr5"}]]);/**
247
- * @license lucide-react v0.460.0 - ISC
248
- *
249
- * This source code is licensed under the ISC license.
250
- * See the LICENSE file in the root directory of this source tree.
251
- */const Xa=Y("Radio",[["path",{d:"M4.9 19.1C1 15.2 1 8.8 4.9 4.9",key:"1vaf9d"}],["path",{d:"M7.8 16.2c-2.3-2.3-2.3-6.1 0-8.5",key:"u1ii0m"}],["circle",{cx:"12",cy:"12",r:"2",key:"1c9p78"}],["path",{d:"M16.2 7.8c2.3 2.3 2.3 6.1 0 8.5",key:"1j5fej"}],["path",{d:"M19.1 4.9C23 8.8 23 15.1 19.1 19",key:"10b0cb"}]]);/**
252
- * @license lucide-react v0.460.0 - ISC
253
- *
254
- * This source code is licensed under the ISC license.
255
- * See the LICENSE file in the root directory of this source tree.
256
- */const Ja=Y("Redo2",[["path",{d:"m15 14 5-5-5-5",key:"12vg1m"}],["path",{d:"M20 9H9.5A5.5 5.5 0 0 0 4 14.5A5.5 5.5 0 0 0 9.5 20H13",key:"6uklza"}]]);/**
257
- * @license lucide-react v0.460.0 - ISC
258
- *
259
- * This source code is licensed under the ISC license.
260
- * See the LICENSE file in the root directory of this source tree.
261
- */const Ct=Y("Settings2",[["path",{d:"M20 7h-9",key:"3s1dr2"}],["path",{d:"M14 17H5",key:"gfn3mx"}],["circle",{cx:"17",cy:"17",r:"3",key:"18b49y"}],["circle",{cx:"7",cy:"7",r:"3",key:"dfmy0x"}]]);/**
262
- * @license lucide-react v0.460.0 - ISC
263
- *
264
- * This source code is licensed under the ISC license.
265
- * See the LICENSE file in the root directory of this source tree.
266
- */const Qa=Y("Share2",[["circle",{cx:"18",cy:"5",r:"3",key:"gq8acd"}],["circle",{cx:"6",cy:"12",r:"3",key:"w7nqdw"}],["circle",{cx:"18",cy:"19",r:"3",key:"1xt0gg"}],["line",{x1:"8.59",x2:"15.42",y1:"13.51",y2:"17.49",key:"47mynk"}],["line",{x1:"15.41",x2:"8.59",y1:"6.51",y2:"10.49",key:"1n3mei"}]]);/**
267
- * @license lucide-react v0.460.0 - ISC
268
- *
269
- * This source code is licensed under the ISC license.
270
- * See the LICENSE file in the root directory of this source tree.
271
- */const gs=Y("ShieldCheck",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]]);/**
272
- * @license lucide-react v0.460.0 - ISC
273
- *
274
- * This source code is licensed under the ISC license.
275
- * See the LICENSE file in the root directory of this source tree.
276
- */const Za=Y("Shield",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}]]);/**
277
- * @license lucide-react v0.460.0 - ISC
278
- *
279
- * This source code is licensed under the ISC license.
280
- * See the LICENSE file in the root directory of this source tree.
281
- */const St=Y("Square",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]]);/**
282
- * @license lucide-react v0.460.0 - ISC
283
- *
284
- * This source code is licensed under the ISC license.
285
- * See the LICENSE file in the root directory of this source tree.
286
- */const zt=Y("Stethoscope",[["path",{d:"M11 2v2",key:"1539x4"}],["path",{d:"M5 2v2",key:"1yf1q8"}],["path",{d:"M5 3H4a2 2 0 0 0-2 2v4a6 6 0 0 0 12 0V5a2 2 0 0 0-2-2h-1",key:"rb5t3r"}],["path",{d:"M8 15a6 6 0 0 0 12 0v-3",key:"x18d4x"}],["circle",{cx:"20",cy:"10",r:"2",key:"ts1r5v"}]]);/**
287
- * @license lucide-react v0.460.0 - ISC
288
- *
289
- * This source code is licensed under the ISC license.
290
- * See the LICENSE file in the root directory of this source tree.
291
- */const Ds=Y("Tag",[["path",{d:"M12.586 2.586A2 2 0 0 0 11.172 2H4a2 2 0 0 0-2 2v7.172a2 2 0 0 0 .586 1.414l8.704 8.704a2.426 2.426 0 0 0 3.42 0l6.58-6.58a2.426 2.426 0 0 0 0-3.42z",key:"vktsd0"}],["circle",{cx:"7.5",cy:"7.5",r:".5",fill:"currentColor",key:"kqv944"}]]);/**
292
- * @license lucide-react v0.460.0 - ISC
293
- *
294
- * This source code is licensed under the ISC license.
295
- * See the LICENSE file in the root directory of this source tree.
296
- */const en=Y("Target",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["circle",{cx:"12",cy:"12",r:"6",key:"1vlfrh"}],["circle",{cx:"12",cy:"12",r:"2",key:"1c9p78"}]]);/**
297
- * @license lucide-react v0.460.0 - ISC
298
- *
299
- * This source code is licensed under the ISC license.
300
- * See the LICENSE file in the root directory of this source tree.
301
- */const sn=Y("Undo2",[["path",{d:"M9 14 4 9l5-5",key:"102s5s"}],["path",{d:"M4 9h10.5a5.5 5.5 0 0 1 5.5 5.5a5.5 5.5 0 0 1-5.5 5.5H11",key:"f3b9sd"}]]);/**
302
- * @license lucide-react v0.460.0 - ISC
303
- *
304
- * This source code is licensed under the ISC license.
305
- * See the LICENSE file in the root directory of this source tree.
306
- */const tn=Y("User",[["path",{d:"M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2",key:"975kel"}],["circle",{cx:"12",cy:"7",r:"4",key:"17ys0d"}]]);/**
307
- * @license lucide-react v0.460.0 - ISC
308
- *
309
- * This source code is licensed under the ISC license.
310
- * See the LICENSE file in the root directory of this source tree.
311
- */const an=Y("Wrench",[["path",{d:"M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.91 6.91a2.12 2.12 0 0 1-3-3l6.91-6.91a6 6 0 0 1 7.94-7.94l-3.76 3.76z",key:"cbrjhi"}]]);/**
312
- * @license lucide-react v0.460.0 - ISC
313
- *
314
- * This source code is licensed under the ISC license.
315
- * See the LICENSE file in the root directory of this source tree.
316
- */const nn=Y("Zap",[["path",{d:"M4 14a1 1 0 0 1-.78-1.63l9.9-10.2a.5.5 0 0 1 .86.46l-1.92 6.02A1 1 0 0 0 13 10h7a1 1 0 0 1 .78 1.63l-9.9 10.2a.5.5 0 0 1-.86-.46l1.92-6.02A1 1 0 0 0 11 14z",key:"1xq2db"}]]),ln=200,rn=5*60*1e3,_e=new Map;function cn(s){const a=_e.get(s);return a?Date.now()-a.ts>rn?(_e.delete(s),null):a.data:null}function Cs(s,a){_e.size>=ln&&[..._e.entries()].sort((i,n)=>i[1].ts-n[1].ts).slice(0,50).map(([i])=>i).forEach(i=>_e.delete(i)),_e.set(s,{data:a,ts:Date.now()})}function on(s){if(!s||s==="/")return[{label:"/",path:"/"}];const a=s.split("/").filter(Boolean),t=[];let i="";for(let n=0;n<a.length;n++)i+="/"+a[n],t.push({label:a[n],path:i});return t}function dn(s){return[...s].sort((a,t)=>a.isDir!==t.isDir?a.isDir?-1:1:a.name.localeCompare(t.name,void 0,{sensitivity:"base"}))}function hn(s){const a=s.trim();return a?a!==s?{ok:!1,reason:"Name cannot have leading or trailing whitespace."}:a==="."?{ok:!1,reason:"Name cannot be '.'."}:a===".."?{ok:!1,reason:"Name cannot be '..'."}:a.startsWith("-")?{ok:!1,reason:"Name cannot start with '-'."}:a.length>255?{ok:!1,reason:"Name cannot be longer than 255 characters."}:/[/\0:*?"<>|]/.test(a)?{ok:!1,reason:'Name cannot contain / \\ : * ? " < > |'}:{ok:!0}:{ok:!1,reason:"Name cannot be empty."}}function Tt({value:s,onChange:a,initialPath:t,projectsDirectory:i,rootLabel:n="Home",height:d=360}){const[o,l]=r.useState(t??i??""),[p,u]=r.useState(new Set),[g,h]=r.useState(-1),[c,x]=r.useState(null),[M,k]=r.useState({}),[S,b]=r.useState(!1),[v,y]=r.useState(null),[T,m]=r.useState(!1),[I,U]=r.useState(""),[R,G]=r.useState(null),[W,$]=r.useState(!1),q=r.useRef(null),X=r.useCallback(async P=>{try{const le=cn(P);if(le)return le;const ae=await A.get("/fs?path="+encodeURIComponent(P));return Cs(P,ae),ae}catch{return null}},[]),N=r.useCallback(async P=>{var le;b(!0),y(null);try{const ae=await A.get("/fs?path="+encodeURIComponent(P));Cs(P,ae),x(ae),h(-1)}catch(ae){const fe=((le=ae.data)==null?void 0:le.message)??ae.message??"Failed to load directory";y(fe)}finally{b(!1)}},[]);r.useEffect(()=>{o?N(o):A.get("/fs").then(P=>{Cs("",P),x(P),l(P.path),P.path!==s&&a(P.path)}).catch(()=>{y("Could not determine home directory."),b(!1)})},[o]),r.useEffect(()=>{s&&s!==o&&l(s)},[s]);const E=c?dn(c.entries):[],D=E.filter(P=>P.isDir),H=E,te=P=>{P.isDir&&(l(P.path),a(P.path))},ie=()=>{c!=null&&c.parent&&(l(c.parent),a(c.parent))},ue=P=>{P!==o&&(l(P),a(P))},B=async()=>{const P=await X("");P&&(l(P.path),a(P.path))},Q=async()=>{if(!i)return;const P=await X(i);P&&(l(P.path),a(P.path))},O=()=>{m(!0),U(""),G(null),setTimeout(()=>{var P;return(P=q.current)==null?void 0:P.focus()},0)},j=()=>{m(!1),U(""),G(null)},C=async()=>{var le;const P=hn(I);if(!P.ok){G(P.reason);return}$(!0),G(null);try{const ae=await A.post("/fs/mkdir",{parent:o,name:I.trim()});_e.delete(o),await N(o),a(ae.path),m(!1),U("")}catch(ae){const fe=ae;fe.status===409?G(`A folder named "${I.trim()}" already exists.`):G(((le=fe.data)==null?void 0:le.message)??ae.message??"Failed to create folder.")}finally{$(!1)}},L=P=>{P.key==="Enter"?(P.preventDefault(),C()):P.key==="Escape"&&(P.preventDefault(),j())},F=P=>{u(le=>{const ae=new Set(le);return ae.has(P)?ae.delete(P):ae.add(P),ae}),M[P]||X(P).then(le=>{le&&k(ae=>({...ae,[P]:le.entries.filter(fe=>fe.isDir)}))})},J=P=>{if(!c)return;const le=H.filter(ce=>ce.isDir),ae=H.filter(ce=>!ce.isDir),fe=[...le,...ae];if(P.key==="ArrowDown")P.preventDefault(),h(ce=>Math.min(ce+1,fe.length-1));else if(P.key==="ArrowUp")P.preventDefault(),h(ce=>Math.max(ce-1,0));else if(P.key==="Enter"||P.key===" "){P.preventDefault();const ce=fe[g];ce&&(P.key==="Enter"&&ce.isDir?te(ce):ce.isDir&&a(ce.path))}else P.key==="Backspace"&&(P.preventDefault(),ie())},V=on((c==null?void 0:c.path)??o??"/"),f=c==null?void 0:c.parent,_=f!=null,ee=o.split("/").filter(Boolean).at(-1)??"/";return e.jsxs("div",{className:"file-browser",onKeyDown:J,tabIndex:-1,children:[e.jsx("div",{className:"file-browser-breadcrumb",role:"navigation","aria-label":"Path breadcrumb",children:V.map((P,le)=>e.jsxs("span",{className:"file-browser-breadcrumb-item",children:[le>0&&e.jsx("span",{className:"file-browser-breadcrumb-sep","aria-hidden":!0,children:"/"}),e.jsx("button",{type:"button",className:"file-browser-breadcrumb-btn",onClick:()=>ue(P.path),title:P.path,children:le===0?P.path==="/"?"/":n:P.label})]},P.path))}),e.jsxs("div",{className:"file-browser-toolbar",children:[e.jsxs("div",{className:"file-browser-toolbar-left",children:[e.jsx("button",{type:"button",className:"file-browser-tool-btn",onClick:ie,disabled:!_,title:"Go up (Backspace)","aria-label":"Go up one level",children:e.jsx(vt,{size:13})}),e.jsx("button",{type:"button",className:"file-browser-tool-btn",onClick:()=>N(o),disabled:S,title:"Refresh","aria-label":"Refresh",children:e.jsx(de,{size:13,className:S?"spin":""})}),e.jsx("button",{type:"button",className:"file-browser-tool-btn",onClick:O,title:"New folder","aria-label":"Create new folder",children:e.jsx(La,{size:13})}),e.jsxs("div",{className:"file-browser-chips",children:[e.jsxs("button",{type:"button",className:"file-browser-chip",onClick:B,children:[e.jsx(Oa,{size:11})," ",n]}),i&&e.jsxs("button",{type:"button",className:"file-browser-chip",onClick:Q,title:i,children:[e.jsx(Da,{size:11})," ",i.split("/").filter(Boolean).at(-1)??"Projects"]})]})]}),T?e.jsxs("div",{className:"file-browser-mkdir",children:[e.jsx("input",{ref:q,type:"text",className:"file-browser-mkdir-input",placeholder:"Folder name",value:I,onChange:P=>{U(P.target.value),G(null)},onKeyDown:L,"aria-label":"New folder name","aria-invalid":R?"true":void 0,"aria-describedby":R?"mkdir-error":void 0,disabled:W,maxLength:255}),R?e.jsx("span",{id:"mkdir-error",className:"file-browser-mkdir-error",role:"alert",children:R}):e.jsx("span",{className:"file-browser-mkdir-hint",children:"Enter to create, Esc to cancel"})]}):e.jsx("span",{className:"file-browser-count-hint",children:S?"…":`${E.length} in ${ee}`})]}),v&&e.jsxs("div",{className:"file-browser-error",children:[e.jsx(Bs,{size:13}),e.jsx("span",{children:v}),e.jsx("button",{type:"button",className:"file-browser-retry",onClick:()=>N(o),children:"Retry"})]}),e.jsxs("div",{className:"file-browser-body",style:{height:d},children:[e.jsx("div",{className:"file-browser-pane file-browser-tree","aria-label":"Folder tree",children:S&&!c?e.jsx(mn,{}):e.jsx(At,{path:o,entries:D,expanded:p,childrenMap:M,onToggle:F,onNavigate:te,level:0})}),e.jsxs("div",{className:"file-browser-pane file-browser-flat","aria-label":"Directory contents",children:[e.jsxs("div",{className:"file-browser-flat-header",children:[e.jsx("span",{children:"Name"}),e.jsx("span",{children:"Type"})]}),S&&!c?e.jsx(un,{}):e.jsxs(e.Fragment,{children:[(c==null?void 0:c.truncated)&&e.jsxs("div",{className:"file-browser-truncated-banner",role:"status",children:["Showing first 500 of ",c.totalEntries," entries. Navigate into a subfolder to see more."]}),H.length===0?e.jsx("div",{className:"file-browser-empty",children:"This folder is empty"}):e.jsx("div",{className:"file-browser-flat-list",children:H.map((P,le)=>{const ae=P.isDir,fe=le===g,ce=P.path===s;return e.jsxs("div",{role:"option","aria-selected":ce,className:["file-browser-row",ae?"file-browser-row--dir":"file-browser-row--file",fe&&"file-browser-row--selected",ce&&ae&&"file-browser-row--active",!ae&&"file-browser-row--disabled"].filter(Boolean).join(" "),onClick:()=>{ae&&(h(le),a(P.path))},onDoubleClick:()=>{ae&&te(P)},title:P.path,children:[e.jsx("span",{className:"file-browser-row-icon",children:ae?e.jsx(Be,{size:13}):e.jsx($a,{size:13})}),e.jsx("span",{className:"file-browser-row-name",children:P.name}),e.jsx("span",{className:"file-browser-row-type",children:ae?"Folder":""})]},P.path)})})]})]})]}),e.jsxs("div",{className:"file-browser-footer-hint",children:["Select a folder, then click Add. Use ",e.jsx("kbd",{children:"↑"})," ",e.jsx("kbd",{children:"↓"})," to navigate, ",e.jsx("kbd",{children:"Enter"})," to confirm."]})]})}function At({path:s,entries:a,expanded:t,childrenMap:i,onToggle:n,onNavigate:d,level:o}){return e.jsx("ul",{className:"file-browser-tree-list",role:"group",children:a.map(l=>{const p=t.has(l.path),u=i[l.path]??[];return e.jsxs("li",{className:"file-browser-tree-node",children:[e.jsxs("div",{className:["file-browser-tree-row",p&&"file-browser-tree-row--expanded"].filter(Boolean).join(" "),style:{paddingLeft:`${o*16+8}px`},children:[e.jsx("button",{type:"button",className:"file-browser-tree-toggle",onClick:g=>{g.stopPropagation(),n(l.path)},"aria-label":p?"Collapse":"Expand",children:(u.length>0,p?e.jsx(Ae,{size:11}):e.jsx(Ue,{size:11}))}),e.jsxs("button",{type:"button",className:"file-browser-tree-name",onClick:()=>d(l),title:l.path,children:[e.jsx(Be,{size:12}),e.jsx("span",{children:l.name})]})]}),p&&u.length>0&&e.jsx(At,{path:l.path,entries:u,expanded:t,childrenMap:i,onToggle:n,onNavigate:d,level:o+1})]},l.path)})})}function mn(){return e.jsx("div",{className:"file-browser-skeleton-wrap",children:[80,60,90,55,70].map((s,a)=>e.jsx("div",{className:"file-browser-skeleton-row",style:{width:s}},a))})}function un(){return e.jsx("div",{className:"file-browser-skeleton-wrap",children:[60,90,70,50,80,65].map((s,a)=>e.jsx("div",{className:"file-browser-skeleton-row",style:{width:s}},a))})}const Ls=[{id:"overview",label:"Overview",icon:Ua},{id:"chat",label:"Chat",icon:Xe},{id:"agents",label:"Agents",icon:Fe},{id:"artifacts",label:"Glyphs",icon:ls},{id:"tasks",label:"Tasks",icon:Pe},{id:"activity",label:"Activity",icon:ze},{id:"background",label:"Active",icon:Xa},{id:"skills",label:"Skills",icon:Me},{id:"mods",label:"Mods",icon:fs},{id:"schedules",label:"Schedules",icon:Je},{id:"history",label:"History",icon:ts},{id:"config",label:"Config",icon:Ct},{id:"settings",label:"Settings",icon:ht}];function pn({activeTab:s,onTabChange:a,wsStatus:t,version:i,activeProject:n,projects:d,onProjectChange:o,onProjectsRefresh:l,onOpenSearch:p,settings:u,rightSlot:g,notificationsSlot:h,showTabs:c=!0,extraTabs:x}){return e.jsxs("header",{className:"topbar",children:[e.jsxs("div",{className:"topbar-row",children:[e.jsxs("div",{className:"brand",children:[e.jsx("span",{className:"brand-logo","aria-hidden":"true",children:"ᛒ"}),e.jsx("span",{className:"brand-title",children:"Bizar"}),e.jsx("span",{className:"brand-version",children:i})]}),e.jsx(xn,{activeProject:n,projects:d,onChange:o,onRefresh:l,settings:u??null}),e.jsxs("button",{type:"button",className:"topbar-search",onClick:p,title:"Search (Ctrl/Cmd+K)","aria-label":"Open search",children:[e.jsx(Oe,{size:14}),e.jsx("span",{className:"muted",children:"Search…"}),e.jsx("kbd",{children:"⌘K"})]}),e.jsx("div",{className:"topbar-spacer"}),e.jsxs("div",{className:"topbar-right",children:[h,g,e.jsxs("div",{className:Z("ws-status",`ws-${t}`),title:`WebSocket: ${t}`,children:[e.jsx("span",{className:"ws-dot"}),e.jsx("span",{className:"ws-label",children:t})]})]})]}),c&&e.jsxs("nav",{className:"tabs-row",role:"tablist",children:[Ls.map(M=>{const k=M.icon,S=M.id===s;return e.jsxs("button",{type:"button",role:"tab","aria-selected":S,className:Z("tab",S&&"tab-active"),onClick:()=>a(M.id),title:M.label,children:[e.jsx(k,{size:14,className:"tab-icon"}),e.jsx("span",{className:"tab-label",children:M.label})]},M.id)}),x&&x.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"tab-separator","aria-hidden":"true"}),x.map(M=>{const k=M.icon,S=M.id===s;return e.jsxs("button",{type:"button",role:"tab","aria-selected":S,className:Z("tab","tab-mod",S&&"tab-active"),onClick:()=>a(M.id),title:`${M.label} (mod)`,children:[e.jsx(k,{size:14,className:"tab-icon"}),e.jsx("span",{className:"tab-label",children:M.label}),e.jsx("span",{className:"tab-badge",children:"mod"})]},M.id)})]})]})]})}function xn({activeProject:s,projects:a,onChange:t,onRefresh:i,settings:n}){const[d,o]=r.useState(!1),l=ke();r.useEffect(()=>{if(!d)return;const u=()=>o(!1);return document.addEventListener("click",u),()=>document.removeEventListener("click",u)},[d]);const p=()=>{l.open({title:"Add project",children:e.jsx(jn,{settings:n,onAdd:async(u,g)=>{try{await A.post("/projects",{path:u,name:g}),i(),o(!1),l.close()}catch(h){alert(`Add failed: ${h.message}`)}}}),footer:e.jsx("div",{className:"modal-footer-actions",children:e.jsx(z,{variant:"ghost",onClick:()=>l.close(),children:"Cancel"})})})};return e.jsxs("div",{className:"project-selector",onClick:u=>u.stopPropagation(),children:[e.jsxs("button",{type:"button",className:"project-selector-btn",onClick:()=>o(u=>!u),title:"Switch active project","aria-haspopup":"menu","aria-expanded":d,children:[e.jsx(Be,{size:14}),e.jsx("span",{className:"project-selector-name",children:(s==null?void 0:s.name)||"(no project)"}),e.jsx(Ae,{size:12})]}),d&&e.jsxs("div",{className:"project-selector-menu",children:[e.jsxs("div",{className:"project-selector-menu-head",children:[e.jsxs("span",{className:"muted",children:[a.length," project",a.length===1?"":"s"]}),e.jsxs("div",{className:"project-selector-menu-actions",children:[e.jsx("button",{type:"button",className:"icon-btn",onClick:i,title:"Refresh","aria-label":"Refresh projects",children:e.jsx(de,{size:12})}),e.jsx("button",{type:"button",className:"icon-btn",onClick:p,title:"Add project","aria-label":"Add project",children:e.jsx(je,{size:12})})]})]}),e.jsxs("ul",{className:"project-selector-list",children:[a.length===0&&e.jsx("li",{className:"muted project-selector-empty",children:"No projects. Add one to start."}),a.map(u=>e.jsx("li",{children:e.jsxs("button",{type:"button",className:Z("project-selector-item",(s==null?void 0:s.id)===u.id&&"active"),onClick:()=>{t(u.id),o(!1)},children:[e.jsx("span",{className:"project-selector-item-name",children:u.name}),e.jsx("span",{className:"project-selector-item-status",children:u.status})]})},u.id))]})]})]})}function jn({settings:s,onAdd:a}){var h,c;const[t,i]=r.useState(((h=s==null?void 0:s.dashboard)==null?void 0:h.projectsDirectory)??""),[n,d]=r.useState(""),[o,l]=r.useState(!1),[p,u]=r.useState(null),g=async()=>{var x;if(t){l(!0),u(null);try{await A.get("/fs?path="+encodeURIComponent(t)),a(t,n||null)}catch(M){const k=M;k.status===404?u("That folder no longer exists. Pick another."):u(((x=k.data)==null?void 0:x.message)??M.message??"Validation failed.")}finally{l(!1)}}};return e.jsxs("div",{children:[e.jsx("label",{className:"field-label",children:"Folder"}),e.jsx(Tt,{value:t,onChange:x=>{i(x),u(null)},projectsDirectory:(c=s==null?void 0:s.dashboard)==null?void 0:c.projectsDirectory,height:320}),p&&e.jsx("p",{className:"field-help",style:{color:"var(--error)",marginTop:4},children:p}),e.jsxs("div",{style:{marginTop:"var(--space-3)"},children:[e.jsx("label",{className:"field-label",htmlFor:"topbar-add-project-name",children:"Name (optional)"}),e.jsx("input",{id:"topbar-add-project-name",className:"input",type:"text",placeholder:"My App",value:n,onChange:x=>d(x.target.value)})]}),e.jsx("div",{style:{marginTop:"var(--space-3)",display:"flex",justifyContent:"flex-end"},children:e.jsxs(z,{variant:"primary",onClick:g,disabled:!t||o,children:[o?e.jsx("span",{className:"btn-spinner"}):null,o?"Checking…":"Add"]})})]})}function fn({tabs:s,activeTab:a,onTabChange:t}){const i=s.filter(d=>!d.isMod),n=s.filter(d=>d.isMod);return e.jsx("aside",{className:"sidebar","aria-label":"Primary navigation",children:e.jsxs("nav",{className:"sidebar-nav",role:"tablist",children:[i.map(d=>{const o=d.icon,l=d.id===a;return e.jsxs("button",{type:"button",role:"tab","aria-selected":l,className:Z("sidebar-tab",l&&"sidebar-tab-active"),onClick:()=>t(d.id),title:d.label,children:[e.jsx(o,{size:18,"aria-hidden":!0}),e.jsx("span",{className:"sidebar-tab-label",children:d.label})]},d.id)}),n.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"sidebar-section-divider","aria-hidden":"true"}),e.jsx("div",{className:"sidebar-section-label",children:"Mods"}),n.map(d=>{const o=d.icon,l=d.id===a;return e.jsxs("button",{type:"button",role:"tab","aria-selected":l,className:Z("sidebar-tab","sidebar-tab-mod",l&&"sidebar-tab-active"),onClick:()=>t(d.id),title:`${d.label} (mod)`,children:[e.jsx(o,{size:18,"aria-hidden":!0}),e.jsx("span",{className:"sidebar-tab-label",children:d.label})]},d.id)})]})]})})}const Ss=[{id:"all",label:"All"},{id:"projects",label:"Projects"},{id:"agents",label:"Agents"},{id:"tasks",label:"Tasks"},{id:"mods",label:"Mods"},{id:"schedules",label:"Schedules"},{id:"commands",label:"Commands"},{id:"settings",label:"Settings"}],tt={all:null,projects:"project",agents:"agent",tasks:"task",mods:"mod",schedules:"schedule",commands:"command",settings:"setting"};function gn({open:s,onClose:a,onSelect:t}){const i=he(),[n,d]=r.useState(""),[o,l]=r.useState("all"),[p,u]=r.useState([]),[g,h]=r.useState(!1),[c,x]=r.useState(0),M=r.useRef(null),k=r.useRef(null);if(r.useEffect(()=>{let y;return s&&(k.current=document.activeElement instanceof HTMLElement?document.activeElement:null,d(""),u([]),x(0),y=window.setTimeout(()=>{var T;return(T=M.current)==null?void 0:T.focus()},30)),()=>{if(y&&window.clearTimeout(y),!s)return;const T=k.current;T&&T.isConnected&&T.focus()}},[s]),r.useEffect(()=>{if(!s)return;if(!n.trim()){u([]),x(0);return}let y=!1;h(!0);const T=setTimeout(()=>{A.get(`/search?q=${encodeURIComponent(n)}&scope=${o}`).then(m=>{y||(u(m.results||[]),x(0))}).catch(m=>{y||i.error(`Search failed: ${m.message}`)}).finally(()=>!y&&h(!1))},150);return()=>{y=!0,clearTimeout(T)}},[n,o,s,i]),!s)return null;const S={};for(const y of p){const T=y.type.toLowerCase();S[T]=S[T]||[],S[T].push(y)}const b=[];for(const y of Ss.map(T=>T.id)){const T=tt[y];T&&S[T]&&b.push(...S[T])}const v=y=>{if(y.key==="Escape")a();else if(y.key==="ArrowDown"){if(y.preventDefault(),b.length===0)return;x(T=>Math.min(T+1,b.length-1))}else if(y.key==="ArrowUp"){if(y.preventDefault(),b.length===0)return;x(T=>Math.max(T-1,0))}else y.key==="Enter"&&b[c]&&(y.preventDefault(),t(b[c]),a())};return e.jsx("div",{className:"search-modal-backdrop",onClick:a,children:e.jsxs("div",{className:"search-modal",role:"dialog","aria-modal":"true","aria-labelledby":"search-modal-title",onClick:y=>y.stopPropagation(),children:[e.jsxs("div",{className:"search-modal-head",children:[e.jsx(Oe,{size:14}),e.jsx("span",{id:"search-modal-title",className:"sr-only",children:"Search"}),e.jsx("input",{ref:M,className:"search-modal-input",placeholder:"Search tasks, agents, settings, projects…",value:n,onChange:y=>d(y.target.value),onKeyDown:v}),e.jsx("button",{type:"button",className:"icon-btn","aria-label":"Close",onClick:a,children:e.jsx($e,{size:14})})]}),e.jsx("div",{className:"search-modal-scopes",children:Ss.map(y=>e.jsx("button",{type:"button",className:Z("search-scope",o===y.id&&"search-scope-active"),onClick:()=>l(y.id),children:y.label},y.id))}),e.jsxs("div",{className:"search-modal-body",children:[g&&e.jsx("div",{className:"muted",children:"Searching…"}),!g&&n&&b.length===0&&e.jsx("div",{className:"muted",children:"No results."}),!g&&!n&&e.jsx("div",{className:"muted",children:"Type to search…"}),Ss.map(y=>{const T=tt[y.id];if(!T)return null;const m=S[T];return!m||m.length===0?null:e.jsxs("div",{className:"search-group",children:[e.jsx("div",{className:"search-group-head",children:y.label}),m.map(I=>{const U=b.indexOf(I);return e.jsxs("button",{type:"button",className:Z("search-result",U===c&&"search-result-active"),onMouseEnter:()=>x(U),onClick:()=>{t(I),a()},children:[e.jsx("span",{className:"search-result-type",children:I.type}),e.jsx("span",{className:"search-result-label",children:vn(I)})]},`${I.type}-${U}`)})]},y.id)})]}),e.jsx("div",{className:"search-modal-foot",children:e.jsx("span",{className:"muted",children:"↑↓ navigate · ↵ open · esc close"})})]})})}function vn(s){const a=s.item||{};if(s.type==="project")return`${a.name} — ${a.path}`;if(s.type==="agent")return`${a.name} — ${a.description||a.model||""}`;if(s.type==="task")return`${a.title} — ${a.status||""}`;if(s.type==="mod")return`${a.name} v${a.version} — ${a.description||""}`;if(s.type==="schedule")return`${a.name} (${a.type}: ${a.schedule})`;if(s.type==="command")return`${a.name} — ${a.description||""}`;if(s.type==="setting"){const t=a.value===null||a.value===void 0?"":typeof a.value=="string"?` = ${a.value}`:` = ${JSON.stringify(a.value)}`;return`${a.label}${t} — ${a.desc||""}`.trim()}return JSON.stringify(a).slice(0,80)}const yn={info:bs,success:ys,warning:Ee,error:Bs};function bn({onCountChange:s,wsSubscribe:a}){const t=he(),[i,n]=r.useState(!1),[d,o]=r.useState([]),[l,p]=r.useState(null),[u,g]=r.useState(!1),h=r.useRef(null),c=r.useRef(0),x=async()=>{var v;try{g(!0);const y=await A.get("/notifications?limit=200");o(y.notifications||[]),p(y.stats||null),c.current=((v=y.stats)==null?void 0:v.unread)||0,s==null||s(c.current)}catch(y){console.warn("[notifications] reload failed:",y.message)}finally{g(!1)}};r.useEffect(()=>{x()},[]),r.useEffect(()=>a?a(y=>{if(y.type==="notification:new"){const T=y.notification;o(m=>[T,...m.filter(I=>I.id!==T.id)]),T.read||(c.current+=1,p(m=>m?{...m,unread:(m.unread||0)+1}:{total:1,unread:1,lastTs:T.ts,counts:{[T.severity||"info"]:1}}),s==null||s(c.current))}else y.type==="notifications:change"&&x()}):void 0,[a]),r.useEffect(()=>{if(!i)return;const v=T=>{h.current&&(h.current.contains(T.target)||n(!1))},y=T=>{T.key==="Escape"&&n(!1)};return document.addEventListener("mousedown",v),document.addEventListener("keydown",y),()=>{document.removeEventListener("mousedown",v),document.removeEventListener("keydown",y)}},[i]);const M=async()=>{try{await A.post("/notifications/read-all",{}),o(v=>v.map(y=>({...y,read:!0}))),p(v=>v&&{...v,unread:0}),c.current=0,s==null||s(0),t.success("All notifications marked as read.",1500)}catch(v){t.error(`Failed: ${v.message}`)}},k=async v=>{try{await A.post(`/notifications/${encodeURIComponent(v)}/read`,{}),o(y=>y.map(T=>T.id===v?{...T,read:!0}:T)),p(y=>y&&{...y,unread:Math.max(0,(y.unread||1)-1)}),c.current=Math.max(0,c.current-1),s==null||s(c.current)}catch(y){t.error(`Failed: ${y.message}`)}},S=async v=>{try{await A.del(`/notifications/${encodeURIComponent(v)}`),o(y=>{const T=y.find(m=>m.id===v);return T&&!T.read&&(c.current=Math.max(0,c.current-1),p(m=>m&&{...m,unread:Math.max(0,m.unread-1)}),s==null||s(c.current)),y.filter(m=>m.id!==v)})}catch(y){t.error(`Failed: ${y.message}`)}},b=(l==null?void 0:l.unread)||0;return e.jsxs("div",{className:"notifications-root",ref:h,children:[e.jsxs("button",{type:"button",className:Z("topbar-icon-btn notifications-bell",i&&"is-open"),onClick:()=>n(v=>!v),title:"Notifications","aria-label":"Notifications","aria-haspopup":"true","aria-expanded":i,children:[e.jsx(Gt,{size:16}),b>0&&e.jsx("span",{className:"notifications-badge",children:b>99?"99+":b})]}),i&&e.jsxs("div",{className:"notifications-panel",role:"dialog","aria-label":"Notifications",children:[e.jsxs("header",{className:"notifications-panel-head",children:[e.jsxs("div",{children:[e.jsx("strong",{children:"Notifications"}),b>0&&e.jsxs("span",{className:"muted text-sm",children:[" · ",b," unread"]})]}),e.jsxs("div",{className:"notifications-panel-head-actions",children:[e.jsxs(z,{size:"sm",variant:"ghost",onClick:M,disabled:b===0,children:[e.jsx($s,{size:12})," Mark all read"]}),e.jsx("button",{type:"button",className:"icon-btn",onClick:()=>n(!1),"aria-label":"Close",title:"Close",children:e.jsx($e,{size:14})})]})]}),e.jsx("div",{className:"notifications-list",children:u&&d.length===0?e.jsx("div",{className:"notifications-empty muted",children:"Loading…"}):d.length===0?e.jsx("div",{className:"notifications-empty muted",children:"No notifications yet."}):d.map(v=>{const y=yn[v.severity]||bs;return e.jsxs("div",{className:Z("notification-item",!v.read&&"is-unread",`severity-${v.severity}`),children:[e.jsx(y,{size:14,className:`notification-icon severity-${v.severity}`}),e.jsxs("div",{className:"notification-body",children:[v.title&&e.jsx("div",{className:"notification-title",children:v.title}),e.jsx("div",{className:"notification-msg",children:v.message}),e.jsxs("div",{className:"notification-meta muted",children:[e.jsx("span",{className:"mono",children:v.source}),e.jsx("span",{children:"·"}),e.jsx("span",{children:ye(v.ts)})]})]}),e.jsxs("div",{className:"notification-actions",children:[!v.read&&e.jsx("button",{type:"button",className:"icon-btn",onClick:()=>k(v.id),title:"Mark as read","aria-label":"Mark as read",children:e.jsx($s,{size:12})}),e.jsx("button",{type:"button",className:"icon-btn icon-btn-danger",onClick:()=>S(v.id),title:"Remove","aria-label":"Remove",children:e.jsx($e,{size:12})})]})]},v.id)})}),e.jsx("footer",{className:"notifications-panel-foot",children:e.jsx("span",{className:"muted text-sm",children:l?`${l.total} total · last ${ye(l.lastTs||new Date().toISOString())}`:""})})]})]})}function kn({data:s,onClose:a}){const t=s==null?void 0:s.enabled;s==null||s.previousEnabled;const i=s==null?void 0:s.mode,n=s==null?void 0:s.defaultTemplate,d=s==null?void 0:s.lastUsedSlug,o=i==="toggle";return e.jsxs("div",{children:[o?e.jsxs("p",{style:{marginBottom:16,lineHeight:1.6},children:["Visual plan mode has been ",e.jsx("strong",{children:t?"enabled":"disabled"}),".",t?" The agent will create a plan and wait for your feedback on complex tasks.":" The agent will work without a visual plan canvas."]}):e.jsxs("div",{style:{marginBottom:16},children:[e.jsxs("p",{style:{marginBottom:8,fontWeight:600},children:["Visual Plan: ",e.jsx("span",{style:{color:t?"var(--color-success)":"var(--color-muted)"},children:t?"ON":"OFF"})]}),e.jsx("p",{style:{lineHeight:1.6,color:"var(--color-muted)",fontSize:13},children:"When enabled, the agent creates a visual plan and waits for your feedback before proceeding with complex tasks."}),n&&e.jsxs("p",{style:{marginTop:8,fontSize:13,color:"var(--color-muted)"},children:["Default template: ",e.jsx("code",{children:n})]}),d&&e.jsxs("p",{style:{fontSize:13,color:"var(--color-muted)"},children:["Last used plan: ",e.jsx("code",{children:d})]}),e.jsxs("p",{style:{marginTop:12,fontSize:13,color:"var(--color-muted)"},children:["Use ",e.jsx("code",{children:"/visual-plan on"})," or ",e.jsx("code",{children:"/visual-plan off"})," to toggle."]})]}),e.jsx("div",{style:{display:"flex",gap:8,justifyContent:"flex-end"},children:e.jsx(z,{variant:"ghost",onClick:a,children:"Close"})})]})}const Nn=["blank","feature-design","bug-investigation","decision-record","horizontal","vertical"];function wn({data:s,onClose:a}){const t=(s==null?void 0:s.templates)??Nn,i=(s==null?void 0:s.defaultTemplate)??"blank",[n,d]=r.useState(""),[o,l]=r.useState(i),[p,u]=r.useState(!1),[g,h]=r.useState(null),c=async()=>{if(!n.trim()){h("Slug is required.");return}if(!/^[a-z0-9][a-z0-9-]{0,63}$/.test(n)){h("Invalid slug. Use lowercase letters, numbers, and hyphens. Must start with an alphanumeric character.");return}u(!0),h(null);try{await A.post("/artifacts",{slug:n,template:o}),a()}catch(x){h(x.message),u(!1)}};return e.jsxs("div",{children:[e.jsxs("p",{style:{marginBottom:16,color:"var(--color-muted)",fontSize:13},children:["Create a new visual plan. Plans are stored in ",e.jsx("code",{children:"artifacts/"})," in your worktree."]}),e.jsxs("div",{style:{marginBottom:12},children:[e.jsx("label",{className:"field-label",htmlFor:"plan-slug",children:"Plan slug"}),e.jsx("input",{id:"plan-slug",className:"input",type:"text",placeholder:"e.g. my-feature",value:n,onChange:x=>{d(x.target.value),h(null)},autoFocus:!0})]}),e.jsxs("div",{style:{marginBottom:16},children:[e.jsx("label",{className:"field-label",htmlFor:"plan-template",children:"Template"}),e.jsx("select",{id:"plan-template",className:"select",value:o,onChange:x=>l(x.target.value),children:t.map(x=>e.jsx("option",{value:x,children:x},x))})]}),g&&e.jsx("p",{style:{marginBottom:12,color:"var(--color-danger)",fontSize:13},children:g}),e.jsxs("div",{style:{display:"flex",gap:8,justifyContent:"flex-end"},children:[e.jsx(z,{variant:"ghost",onClick:a,disabled:p,children:"Cancel"}),e.jsx(z,{variant:"primary",onClick:c,disabled:p||!n.trim(),children:p?"Creating…":"Create"})]})]})}function Cn({data:s,onClose:a}){const t=(s==null?void 0:s.plans)??[],i=(s==null?void 0:s.count)??t.length,n=d=>{window.open(`/artifacts/${d}/`,"_blank")};return e.jsxs("div",{children:[t.length===0?e.jsxs("p",{style:{marginBottom:16,color:"var(--color-muted)"},children:["No plans found in this worktree. Use ",e.jsx("code",{children:"/artifact new <slug>"})," to create one."]}):e.jsxs("div",{style:{marginBottom:16},children:[e.jsxs("p",{style:{marginBottom:12,fontSize:13,color:"var(--color-muted)"},children:[i," plan",i!==1?"s":""," in this worktree:"]}),e.jsx("ul",{style:{listStyle:"none",padding:0,margin:0},children:t.map(d=>e.jsxs("li",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"6px 0",borderBottom:"1px solid var(--color-border)"},children:[e.jsx("code",{style:{fontSize:13},children:d}),e.jsx(z,{variant:"ghost",size:"sm",onClick:()=>n(d),children:"Open"})]},d))})]}),e.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:e.jsx(z,{variant:"ghost",onClick:a,children:"Close"})})]})}function Sn({data:s,onClose:a}){const t=(s==null?void 0:s.commands)??[],i=(s==null?void 0:s.templates)??[],n=(s==null?void 0:s.statuses)??[];return e.jsxs("div",{children:[t.length>0?e.jsx("table",{style:{width:"100%",borderCollapse:"collapse",marginBottom:16,fontSize:13},children:e.jsx("tbody",{children:t.map(d=>e.jsxs("tr",{style:{borderBottom:"1px solid var(--color-border)"},children:[e.jsx("td",{style:{padding:"5px 8px 5px 0",whiteSpace:"nowrap"},children:e.jsx("code",{style:{fontSize:12},children:d.cmd})}),e.jsx("td",{style:{padding:"5px 0",color:"var(--color-muted)"},children:d.desc})]},d.cmd))})}):e.jsx("p",{style:{marginBottom:16,color:"var(--color-muted)"},children:"No commands available."}),i.length>0&&e.jsxs("div",{style:{marginBottom:12},children:[e.jsx("p",{style:{fontSize:12,color:"var(--color-muted)",marginBottom:4},children:"Available templates:"}),e.jsx("p",{style:{fontSize:13},children:i.join(", ")})]}),n.length>0&&e.jsxs("div",{style:{marginBottom:12},children:[e.jsx("p",{style:{fontSize:12,color:"var(--color-muted)",marginBottom:4},children:"Available statuses:"}),e.jsx("p",{style:{fontSize:13},children:n.join(", ")})]}),e.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:e.jsx(z,{variant:"ghost",onClick:a,children:"Close"})})]})}function zn({data:s,onClose:a}){const[t,i]=r.useState(!1),[n,d]=r.useState(null),o=async()=>{i(!0),d(null);try{const l=await A.post("/chat/audit",{});d(l)}catch(l){d({ok:!1,findings:[],error:l.message})}finally{i(!1)}};return e.jsx("div",{children:n===null?e.jsxs(e.Fragment,{children:[e.jsx("p",{style:{marginBottom:16,lineHeight:1.6},children:"Run a security audit of your Bizar agent configuration. The audit checks for common misconfigurations, exposed secrets, and insecure defaults."}),e.jsxs("div",{style:{display:"flex",gap:8,justifyContent:"flex-end"},children:[e.jsx(z,{variant:"ghost",onClick:a,children:"Cancel"}),e.jsx(z,{variant:"primary",onClick:o,disabled:t,children:t?"Running…":"Run Audit"})]})]}):e.jsxs(e.Fragment,{children:[n.ok?e.jsxs("div",{children:[e.jsx("p",{style:{marginBottom:12,fontWeight:600,color:"var(--color-success)"},children:"Audit passed — no issues found."}),n.findings.length>0&&e.jsx("ul",{style:{marginBottom:16,paddingLeft:20},children:n.findings.map((l,p)=>e.jsx("li",{style:{marginBottom:4,fontSize:13},children:l},p))})]}):e.jsxs("p",{style:{marginBottom:16,color:"var(--color-danger)"},children:["Audit failed: ",n.error??"unknown error"]}),e.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:e.jsx(z,{variant:"ghost",onClick:a,children:"Close"})})]})})}function Tn({dialog:s,onClose:a}){if(!s.data)return e.jsxs("div",{children:[e.jsx("p",{style:{marginBottom:16,lineHeight:1.6},children:`Command: ${s.command}`}),e.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:e.jsx("button",{type:"button",className:"btn",onClick:a,children:"Close"})})]});const{message:t,detail:i,url:n}=s.data;return e.jsxs("div",{children:[e.jsx("p",{style:{marginBottom:16,lineHeight:1.6},children:t??`Command: ${s.command}`}),i&&e.jsx("p",{style:{marginBottom:16,color:"var(--color-muted)",fontSize:13},children:i}),n&&e.jsx("p",{style:{marginBottom:16},children:e.jsx("a",{href:n,target:"_blank",rel:"noopener noreferrer",children:n})}),e.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:e.jsx("button",{type:"button",className:"btn",onClick:a,children:"Close"})})]})}function An({dialog:s,onClose:a}){switch(s.component){case"visual-artifact":return e.jsx(kn,{data:s.data,onClose:a});case"artifact-create":return e.jsx(wn,{data:s.data,onClose:a});case"artifact-list":return e.jsx(Cn,{data:s.data,onClose:a});case"help":return e.jsx(Sn,{data:s.data,onClose:a});case"audit":return e.jsx(zn,{data:s.data,onClose:a});default:return e.jsx(Tn,{dialog:s,onClose:a})}}function se({variant:s="elevated",interactive:a=!1,className:t,children:i,...n}){return e.jsx("div",{className:Z("card",`card-${s}`,a&&"card-interactive",t),...n,children:i})}function ne({children:s,className:a}){return e.jsx("h3",{className:Z("card-title",a),children:s})}function re({children:s,className:a}){return e.jsx("div",{className:Z("card-meta",a),children:s})}function Re({icon:s,title:a,message:t,action:i,className:n}){return e.jsxs("div",{className:Z("empty-state",n),children:[e.jsx("div",{className:"empty-icon",children:s??e.jsx(Ba,{size:32})}),e.jsx("div",{className:"empty-title",children:a}),t&&e.jsx("div",{className:"empty-message",children:t}),i&&e.jsx("div",{className:"empty-action",children:i})]})}function Mn({snapshot:s,settings:a,setActiveTab:t,refreshSnapshot:i}){var te,ie,ue;const n=he(),d=ke(),o=r.useRef(null),[l,p]=r.useState(s.overview??null),[u,g]=r.useState(!s.overview),[h,c]=r.useState(s.projects||[]),[x,M]=r.useState(((te=s.activeProject)==null?void 0:te.id)||null),[k,S]=r.useState(s.mods||[]),[b,v]=r.useState(!1),[y,T]=r.useState(((ie=s.overview)==null?void 0:ie.recentActivity)??[]),[m,I]=r.useState(!1),[U,R]=r.useState(new Set);r.useEffect(()=>{let B=!1;return(async()=>{try{const Q=await A.get("/activity/hidden");B||R(new Set(Q.hidden||[]))}catch{}})(),()=>{B=!0}},[]);const G=(B,Q)=>{const O=`${B.kind||""}|${B.ts||""}|${B.slug||B.title||""}|${Q}`;let j=0;for(let C=0;C<O.length;C++)j=(j<<5)-j+O.charCodeAt(C)|0;return Math.abs(j).toString(16).padStart(8,"0").slice(0,16)},W=async B=>{const Q=new Set(U);Q.add(B),R(Q);try{await A.post("/activity/hide",{keys:[B]})}catch(O){const j=new Set(U);R(j),n.error(`Hide failed: ${O.message}`)}},$=async()=>{if(!confirm("Hide every recent activity item from the overview? The full log stays in Settings → Activity Log."))return;const B=y.map((O,j)=>G(O,j)),Q=new Set(U);B.forEach(O=>Q.add(O)),R(Q);try{await A.post("/activity/hide",{keys:B}),n.success(`Hidden ${B.length} item(s). Restore them in Settings → Activity Log.`)}catch(O){n.error(`Clear failed: ${O.message}`)}},q=async()=>{R(new Set);try{await A.del("/activity/hide"),n.success("All hidden activity restored to the overview.")}catch(B){n.error(`Restore failed: ${B.message}`)}};r.useEffect(()=>{var B;s.overview&&(p(s.overview),T(s.overview.recentActivity??[]),g(!1)),c(s.projects||[]),M(((B=s.activeProject)==null?void 0:B.id)||null),S(s.mods||[])},[s.overview,s.projects,s.activeProject,s.mods]),r.useEffect(()=>{let B;try{const Q=A.getToken(),O=Q?`/api/activity/stream?token=${encodeURIComponent(Q)}`:"/api/activity/stream";B=new EventSource(O),B.addEventListener("snapshot",j=>{try{const C=JSON.parse(j.data);T(Array.isArray(C.events)?C.events.slice(0,50):[])}catch{}}),B.addEventListener("activity",j=>{try{const C=JSON.parse(j.data);T(L=>[C,...L].slice(0,50))}catch{}})}catch{}return()=>{try{B==null||B.close()}catch{}}},[]);const X=async()=>{n.info("Refreshing…",1500),await i();try{const B=await A.get("/projects");c(B.projects||[]),M(B.active||null)}catch{}},N=()=>{d.open({title:"Add project",children:e.jsx($n,{settings:a,onAdd:async(B,Q)=>{try{const O=await A.post("/projects",{path:B,name:Q});c(j=>[...j.filter(C=>C.id!==O.id),O]),n.success("Project added."),d.close()}catch(O){n.error(`Add failed: ${O.message}`)}}}),footer:e.jsx("div",{className:"modal-footer-actions",children:e.jsx(z,{variant:"ghost",onClick:()=>d.close(),children:"Cancel"})})})},E=async()=>{var B;try{const Q=await A.post("/projects/auto-detect");c(Q.projects||[]),M(Q.active||null);const O=(B=Q.projects)==null?void 0:B.find(j=>j.id===Q.active);n.success(O?`Active: ${O.name}`:"Projects refreshed."),await i()}catch(Q){n.error(`Auto-detect failed: ${Q.message}`)}},D=async B=>{try{await A.post(`/projects/${encodeURIComponent(B)}/activate`),M(B),n.success("Project activated."),await i()}catch(Q){n.error(`Activate failed: ${Q.message}`)}},H=async B=>{if(confirm(`Remove project "${B}" from the registry?`))try{await A.del(`/projects/${encodeURIComponent(B)}`),c(Q=>Q.filter(O=>O.id!==B)),x===B&&M(null),n.success("Project removed.")}catch(Q){n.error(`Remove failed: ${Q.message}`)}};return u||!l?e.jsxs("div",{className:"view-loading",children:[e.jsx(ge,{size:"lg"}),e.jsx("p",{children:"Loading overview…"})]}):e.jsxs("div",{className:"view view-overview",children:[e.jsxs("div",{className:"overview-hero-noframe",children:[e.jsx("h1",{children:"What do you want to do?"}),e.jsx("p",{className:"overview-hero-subtitle",children:"Describe what you want — Odin will split it into tasks, create a plan, delegate to background agents, and track progress in real time."}),e.jsxs("form",{className:"overview-hero-form-noframe",onSubmit:async B=>{var O,j;B.preventDefault();const Q=(((O=o.current)==null?void 0:O.value)||"").trim();if(Q){v(!0);try{const C=await A.post("/tasks/submit",{title:Q});n.success(`Odin split it into ${((j=C.subtasks)==null?void 0:j.length)||1} task(s)`),o.current&&(o.current.value=""),await i()}catch(C){n.error(`Failed: ${C.message}`)}finally{v(!1)}}},children:[e.jsx("textarea",{ref:o,className:"overview-input-hero",placeholder:"e.g. Implement user authentication with email + password, including registration, login, password reset, and integration tests. Use Bcrypt, JWT tokens, and the existing API style.",disabled:b}),e.jsxs("div",{style:{display:"flex",gap:"var(--space-2)",alignItems:"center",flexWrap:"wrap"},children:[e.jsxs(z,{type:"submit",variant:"primary",size:"lg",disabled:b,children:[b?e.jsx(ge,{size:"sm"}):e.jsx(Qe,{size:16}),"Submit to Odin"]}),e.jsxs("span",{className:"muted",style:{fontSize:12},children:[e.jsx(Me,{size:12,style:{display:"inline",verticalAlign:-2,color:"var(--accent)"}})," ","Odin + 12 specialist agents available"]})]})]}),e.jsx("div",{className:"overview-quick-actions-row",children:["Implement feature","Fix bug","Refactor","Investigate","Add tests","Document","Optimize","Deploy"].map(B=>e.jsx("button",{type:"button",className:"overview-quick-chip",onClick:()=>{o.current&&(o.current.value=B,o.current.focus())},children:B},B))})]}),e.jsxs("div",{className:"overview-feed",children:[e.jsxs("div",{className:"overview-feed-head",children:[e.jsx("h2",{children:"Recent activity"}),e.jsxs("div",{className:"overview-feed-head-actions",children:[U.size>0&&e.jsxs(z,{variant:"ghost",size:"sm",onClick:q,title:"Restore hidden items to this overview",children:[e.jsx(ns,{size:12})," Show ",U.size," hidden"]}),y.length>8&&e.jsx(z,{variant:"ghost",size:"sm",onClick:()=>I(B=>!B),children:m?"Show less":"Show all"}),y.length>0&&e.jsxs(z,{variant:"ghost",size:"sm",onClick:$,title:"Hide every item from the overview (full log kept)",children:[e.jsx(et,{size:12})," Hide all"]})]})]}),U.size>0&&e.jsxs("div",{className:"activity-hidden-banner",role:"status",children:[e.jsxs("span",{children:[e.jsx(et,{size:12,style:{verticalAlign:-2,marginRight:6}}),U.size," item",U.size===1?"":"s"," hidden from the overview."]}),e.jsxs(z,{variant:"ghost",size:"sm",onClick:q,children:[e.jsx(ns,{size:12})," Show them again"]})]}),y.length===0?e.jsx("div",{className:"muted",style:{padding:"24px 0",fontSize:13},children:"No activity yet. Use the chat above or invoke a Bizar command to start a feed."}):e.jsxs("div",{className:Z("activity-feed-list-wrap",!m&&"activity-feed-list-wrap-collapsed"),children:[e.jsx("div",{className:"activity-feed-list",children:y.slice(0,30).map((B,Q)=>{const O=G(B,Q);return U.has(O)?null:e.jsx(Fn,{item:B,activityKey:O,onNavigate:t,onHide:W},`${B.ts}-${Q}`)})}),!m&&y.length>8&&e.jsx("div",{className:"activity-feed-fade","aria-hidden":"true"})]})]}),e.jsxs(se,{className:"project-picker",children:[e.jsxs(ne,{children:[e.jsx(Be,{size:14})," Projects",e.jsxs(z,{variant:"ghost",size:"sm",style:{marginLeft:"auto"},onClick:N,children:[e.jsx(je,{size:12})," Add"]}),e.jsxs(z,{variant:"ghost",size:"sm",onClick:E,title:"Use the server's working directory",children:[e.jsx(je,{size:12})," Auto-detect"]}),((ue=a==null?void 0:a.dashboard)==null?void 0:ue.projectsDirectory)&&e.jsxs(z,{variant:"ghost",size:"sm",title:`Scan ${a.dashboard.projectsDirectory} for projects`,onClick:async()=>{try{const B=await A.post("/projects/scan");B.error?n.error(B.error):n.success(`Added ${B.added.length}, skipped ${B.skipped}.`),await i();const Q=await A.get("/projects");c(Q.projects||[]),M(Q.active||null)}catch(B){n.error(`Scan failed: ${B.message}`)}},children:[e.jsx(Pa,{size:12})," Scan"]}),e.jsx(z,{variant:"ghost",size:"sm",onClick:X,title:"Refresh",children:e.jsx(de,{size:12})})]}),e.jsxs(re,{children:[h.length," project",h.length===1?"":"s"," ·"," ",l.counts.agents," agents ·"," ",l.counts.sessions," session",l.counts.sessions===1?"":"s"]}),h.length===0?e.jsx(Re,{icon:e.jsx(Be,{size:32}),title:"No projects yet",message:"Add a project to start tracking its tasks, plans, and schedules.",action:e.jsxs("div",{className:"empty-state-actions",children:[e.jsxs(z,{variant:"primary",onClick:E,children:[e.jsx(je,{size:14})," Use current directory"]}),e.jsx(z,{variant:"secondary",onClick:N,children:"Add by path…"})]})}):e.jsx("div",{className:"project-grid",children:h.map(B=>e.jsx(Rn,{project:B,active:x===B.id,onOpen:()=>D(B.id),onRemove:()=>H(B.id)},B.id))})]}),e.jsxs("div",{className:"overview-cols",children:[e.jsxs(se,{children:[e.jsx(ne,{children:"Mods"}),e.jsxs(re,{children:["Extensions installed under ",e.jsx("code",{children:"~/.config/bizar/mods/"})]}),k.length===0?e.jsx("div",{className:"muted",children:"No mods installed."}):e.jsx("ul",{className:"mod-mini-list",children:k.map(B=>e.jsxs("li",{className:"mod-mini",children:[e.jsx("span",{className:"mod-mini-name",children:B.name}),e.jsxs("span",{className:"mod-mini-meta",children:["v",B.version," · ",B.type]}),e.jsx("span",{className:`mod-mini-pill ${B.enabled?"mod-mini-pill-on":"mod-mini-pill-off"}`,children:B.enabled?"on":"off"})]},B.id))})]}),e.jsxs(se,{children:[e.jsx(ne,{children:"Environment"}),e.jsx(re,{children:"Runtime + paths"}),e.jsxs("dl",{className:"env-table",children:[e.jsx("dt",{children:"Node"}),e.jsx("dd",{className:"mono",children:l.versions.node}),e.jsx("dt",{children:"Platform"}),e.jsx("dd",{className:"mono",children:l.versions.platform}),e.jsx("dt",{children:"Project root"}),e.jsx("dd",{className:"mono ellipsis",title:l.versions.projectRoot,children:l.versions.projectRoot}),e.jsx("dt",{children:"Bizar root"}),e.jsx("dd",{className:"mono ellipsis",title:l.versions.bizarRoot,children:l.versions.bizarRoot}),e.jsx("dt",{children:"Generated"}),e.jsx("dd",{className:"mono tabular-nums",children:mt(l.generatedAt)})]})]})]})]})}function $n({settings:s,onAdd:a}){var h,c;const[t,i]=r.useState(((h=s==null?void 0:s.dashboard)==null?void 0:h.projectsDirectory)??""),[n,d]=r.useState(""),[o,l]=r.useState(!1),[p,u]=r.useState(null),g=async()=>{var x;if(t){l(!0),u(null);try{await A.get("/fs?path="+encodeURIComponent(t)),a(t,n||null)}catch(M){const k=M;k.status===404?u("That folder no longer exists. Pick another."):u(((x=k.data)==null?void 0:x.message)??M.message??"Validation failed.")}finally{l(!1)}}};return e.jsxs("div",{children:[e.jsx("label",{className:"field-label",children:"Folder"}),e.jsx(Tt,{value:t,onChange:x=>{i(x),u(null)},projectsDirectory:(c=s==null?void 0:s.dashboard)==null?void 0:c.projectsDirectory,height:320}),p&&e.jsx("p",{className:"field-help",style:{color:"var(--error)",marginTop:4},children:p}),e.jsxs("div",{style:{marginTop:"var(--space-3)"},children:[e.jsx("label",{className:"field-label",htmlFor:"add-project-name",children:"Name (optional)"}),e.jsx("input",{id:"add-project-name",className:"input",type:"text",placeholder:"My App",value:n,onChange:x=>d(x.target.value)}),e.jsx("p",{className:"field-help",style:{marginTop:4},children:"Display name for this project. Defaults to the folder name."})]}),e.jsx("div",{style:{marginTop:"var(--space-3)",display:"flex",justifyContent:"flex-end"},children:e.jsxs(z,{variant:"primary",onClick:g,disabled:!t||o,children:[o?e.jsx("span",{className:"btn-spinner"}):null,o?"Checking…":"Add"]})})]})}function Rn({project:s,active:a,onOpen:t,onRemove:i}){const n={active:"status-on",inactive:"status-neutral",error:"status-error"}[s.status]||"status-neutral";return e.jsxs("div",{className:`project-card ${a?"project-card-active":""}`,children:[e.jsxs("div",{className:"project-card-head",children:[e.jsx("span",{className:`project-card-status ${n}`,children:s.status}),e.jsx("div",{className:"project-card-name",children:s.name}),e.jsx("button",{type:"button",className:"icon-btn","aria-label":"Remove project",title:"Remove",onClick:d=>{d.stopPropagation(),i()},children:e.jsx(be,{size:12})})]}),e.jsx("div",{className:"project-card-path mono ellipsis",title:s.path,children:s.path}),e.jsx("div",{className:"project-card-meta",children:s.lastAccessed&&e.jsxs("span",{className:"muted",children:["Last opened ",ye(s.lastAccessed)]})}),e.jsx("div",{className:"project-card-actions",children:e.jsx(z,{variant:a?"ghost":"primary",size:"sm",onClick:t,children:a?e.jsxs(e.Fragment,{children:[e.jsx(Fs,{size:12})," Active"]}):e.jsx(e.Fragment,{children:"Open"})})})]})}function In(s){return s&&s.charAt(0).toUpperCase()+s.slice(1)}function Dn(s){const a=s.trim().toLowerCase().replace(/[:_]/g,"."),[t,i="updated"]=a.split("."),n={settings:"Settings",task:"Task",tasks:"Task",agent:"Agent",agents:"Agent",plan:"Plan",plans:"Plan",bg:"Background job",background:"Background job",session:"Session",mod:"Mod",mods:"Mod",provider:"Provider",providers:"Provider"},d={create:"created",created:"created",add:"added",added:"added",update:"updated",updated:"updated",delegate:"delegated",delegated:"delegated",invoke:"invoked",invoked:"invoked",restart:"restarted",restarted:"restarted",delete:"deleted",deleted:"deleted",remove:"removed",removed:"removed",archive:"archived",archived:"archived",restore:"restored",restored:"restored",complete:"completed",completed:"completed",fail:"failed",failed:"failed",error:"errored",stuck:"marked stuck"},o=n[t]||In(t.replace(/-/g," ")),l=d[i]||i.replace(/-/g," ");return`${o} ${l}`.trim()}function ds(s,a){for(const t of a){const i=s[t];if(typeof i=="string"&&i.trim())return i.trim()}return""}function Ln(s){const a=ds(s,["message","text","prompt","title","name"]);if(a)return a;const t=[],i=ds(s,["slug"]),n=ds(s,["agent","author"]),d=ds(s,["status"]);return i&&t.push(`Plan ${i}`),n&&t.push(n),d&&t.push(d),t.length?t.join(" · "):"No additional details."}function Pn(s){return ye(s)}function En(s){const a=(s.kind||"").toLowerCase(),t=(s.status||"").toLowerCase();return a.includes("error")||t==="error"||t==="failure"?"error":a.includes("warn")||t==="blocked"?"warning":a.includes("done")||a.includes("success")||t==="done"?"success":"info"}function On(s){const a=s.toLowerCase();return a==="task"?Pe:a==="agent"?Fe:a==="plan"?ls:a.includes("bg")||a.includes("background")||a.includes("job")?nn:a==="mod"?fs:a==="skill"?Me:a.includes("error")||a.includes("failure")?qa:a.includes("warn")?Ee:ze}function Bn(s){const a=s.toLowerCase();return a==="task"?"tasks":a==="agent"?"agents":a==="plan"?"artifacts":a.includes("bg")||a.includes("background")?"activity":a==="mod"?"mods":a==="skill"?"skills":null}function Fn({item:s,activityKey:a,onNavigate:t,onHide:i}){const n=En(s),d=On(s.kind||""),o=Dn(s.kind||"activity"),l=Ln(s),p=Bn(s.kind||""),u=n==="error"?"var(--error)":n==="warning"?"var(--warning)":n==="success"?"var(--success)":"var(--accent)";return e.jsxs("div",{className:Z("activity-feed-row",`activity-feed-row-${n}`),children:[e.jsxs("button",{type:"button",className:"activity-feed-row-main",onClick:()=>{p&&t(p)},title:p?`Open ${p}`:o,children:[e.jsx("div",{className:"activity-feed-icon",style:{color:u},children:e.jsx(d,{size:14})}),e.jsxs("div",{className:"activity-feed-body",children:[e.jsxs("div",{className:"activity-feed-title-row",children:[e.jsx("div",{className:"activity-feed-title",children:o}),e.jsx("div",{className:"activity-feed-time text-xs muted tabular-nums",children:Pn(s.ts)})]}),e.jsx("div",{className:"activity-feed-summary text-sm",children:l})]})]}),e.jsx("button",{type:"button",className:"activity-feed-hide-btn",onClick:()=>i(a),title:"Hide this from the overview (kept in Settings → Activity Log)","aria-label":"Hide from overview",children:e.jsx($e,{size:12})})]})}function Un({snapshot:s,settings:a,setActiveTab:t,initialTaskId:i,onClearTaskId:n}){const d=he(),o=ke(),l=Yt(s,a,i??""),[p,u]=r.useState(""),[g,h]=r.useState(a.defaultAgent||"odin"),[c,x]=r.useState(a.defaultModel||""),[M,k]=r.useState([]),[S,b]=r.useState(!1),v=r.useRef(null);r.useRef(null);const{allCommands:y,suggestions:T,setQuery:m}=Xt(s);r.useEffect(()=>{m(p)},[p,m]);const I=()=>{var $;return($=v.current)==null?void 0:$.click()},U=$=>{const q=$.target.files;if(!q)return;const X=[];for(let N=0;N<q.length;N++)X.push(q[N].name);k(N=>{const E=X.filter(D=>!N.includes(D));return[...N,...E]}),v.current&&(v.current.value="")},R=()=>{const $=p.trim();$&&(u(""),m(""),l.onSend($,g,c,M))},G=async()=>{if(!S){if(!s.activeProject){d.warning("Pick a project in Overview to scope chat sessions.",4e3);return}b(!0);try{const $=await fetch("/chat/sessions",{method:"POST"}).then(q=>q.json());l.loadChat($.id),d.success(`Session ${$.id} created.`)}catch($){d.error(`Create failed: ${$.message}`)}finally{b(!1)}}},W=$=>{o.open({title:"Delete message?",children:e.jsx("p",{style:{margin:0},children:"This action cannot be undone."}),footer:e.jsxs("div",{style:{display:"flex",gap:8,justifyContent:"flex-end"},children:[e.jsx(z,{variant:"secondary",size:"sm",onClick:()=>o.close(),children:"Cancel"}),e.jsx(z,{variant:"danger",size:"sm",onClick:()=>{o.close(),l.deleteMessage($)},children:"Delete"})]})})};return e.jsxs("div",{className:"chat-shell",children:[e.jsx(Jt,{activeProject:s.activeProject,sessionCount:l.sessions.length,sessionsOpen:!0,infoOpen:!0,onToggleSessions:()=>{},onToggleInfo:()=>{},onOpenOverview:()=>t==null?void 0:t("overview")}),e.jsxs("div",{className:"chat-body",children:[e.jsx("aside",{className:"chat-sessions",children:e.jsx(Qt,{sessions:l.sessions,opencodeSessions:l.opencodeSessions,activeSessionId:l.sessionId,activeProject:s.activeProject,onCreateSession:G,onSelectSession:l.loadChat,creating:S})}),e.jsxs("main",{className:"chat-main",children:[e.jsx(Zt,{messages:l.messages,loading:l.loading,activeProject:s.activeProject,sessionId:l.sessionId,pinned:l.pinned,onPickSuggestion:$=>u($),onCopy:$=>l.copyMessage($),onDelete:W,onTogglePin:l.togglePin,onRegenerate:l.onRegenerate}),e.jsx(ea,{agent:g,setAgent:h,model:c,setModel:x,text:p,setText:u,sending:l.sending,onSend:R,attachments:M,setAttachments:k,suggestions:T,onPickSuggestion:$=>u(`${$.split(" ")[0]} `),agents:s.agents||[],onAttach:I,sessionsOpen:!0,infoOpen:!0}),e.jsx("input",{ref:v,type:"file",multiple:!0,style:{display:"none"},onChange:U})]}),e.jsx("aside",{className:"chat-info",children:e.jsx(sa,{sessionId:l.sessionId,messages:l.messages,pinned:l.pinned,agent:g,model:c,agents:s.agents||[],mcps:s.mcps||[],allCommands:y})})]})]})}function Le({kind:s="neutral",children:a,className:t,dot:i=!1}){return e.jsxs("span",{className:Z("badge",`badge-${s}`,t),children:[i&&e.jsx("span",{className:"badge-dot"}),a]})}const at=["bash","read","edit","write","webfetch","websearch","task","glob","grep"],nt=["anthropic/claude-3-5-sonnet","anthropic/claude-3-5-haiku","openai/gpt-4o","openai/gpt-4o-mini","openrouter/minimax/minimax-m3","openrouter/minimax/minimax-m2.7"],ms=[{id:"reasoning",label:"Reasoning",color:"var(--accent)"},{id:"code",label:"Code",color:"var(--info)"},{id:"design",label:"Design",color:"var(--success)"},{id:"planning",label:"Planning",color:"var(--warning)"},{id:"gitops",label:"GitOps",color:"var(--error)"},{id:"analysis",label:"Analysis",color:"var(--text-dim)"}];function Hn(s){var a;return((a=ms.find(t=>t.id===s))==null?void 0:a.color)||"var(--text-dim)"}function _n({status:s,isStuck:a}){const t=a?"var(--error)":s==="working"?"var(--info)":s==="error"?"var(--error)":"var(--text-dim)";return e.jsx("span",{className:"agent-status-dot",style:{background:t}})}function Vn({agent:s}){if(s.isStuck)return e.jsx(Le,{kind:"error",dot:!0,children:"stuck"});const a=s.status||"idle";return a==="working"?e.jsx(Le,{kind:"info",dot:!0,children:"working"}):a==="error"?e.jsx(Le,{kind:"error",dot:!0,children:"error"}):e.jsx(Le,{kind:"neutral",dot:!0,children:"idle"})}function qn({snapshot:s,refreshSnapshot:a}){const t=he(),i=ke(),[n,d]=r.useState(s.agents||[]),[o,l]=r.useState(!s.agents),[p,u]=r.useState(""),[g,h]=r.useState("");r.useEffect(()=>{d(s.agents||[]),l(!s.agents)},[s.agents]);const c=async()=>{try{const m=await A.get("/agents");d(m.agents||[])}catch(m){t.error(`Agents load failed: ${m.message}`)}finally{l(!1)}},x=r.useMemo(()=>{let m=[...n];if(p&&(m=m.filter(I=>p==="__none__"?!I.category:(I.category||"")===p)),g){const I=g.toLowerCase();m=m.filter(U=>U.name.toLowerCase().includes(I)||(U.description||"").toLowerCase().includes(I)||(U.tags||[]).some(R=>R.toLowerCase().includes(I)))}return m.sort((I,U)=>I.name.localeCompare(U.name))},[n,p,g]),M=r.useMemo(()=>{const m=new Set;for(const I of n)for(const U of I.tags||[])m.add(U);return Array.from(m).sort()},[n]),k=()=>{let m=null,I=null,U=null,R=null,G=null,W=null,$=null,q=null,X=null;i.open({title:"New agent",width:640,children:e.jsxs("div",{className:"agent-form",children:[e.jsx("label",{className:"field-label",children:"Name (a-z, 0-9, dashes)"}),e.jsx("input",{ref:N=>m=N,className:"input",type:"text",placeholder:"my-agent",autoFocus:!0}),e.jsx("label",{className:"field-label",children:"Description"}),e.jsx("input",{ref:N=>{I=N},className:"input",type:"text",placeholder:"What does this agent do?"}),e.jsxs("div",{className:"task-form-row",children:[e.jsxs("div",{className:"task-form-field",children:[e.jsx("label",{className:"field-label",children:"Model"}),e.jsxs("select",{ref:N=>U=N,className:"select",defaultValue:"",children:[e.jsx("option",{value:"",children:"(provider default)"}),nt.map(N=>e.jsx("option",{value:N,children:N},N))]})]}),e.jsxs("div",{className:"task-form-field",children:[e.jsx("label",{className:"field-label",children:"Mode"}),e.jsxs("select",{ref:N=>R=N,className:"select",defaultValue:"subagent",children:[e.jsx("option",{value:"primary",children:"primary"}),e.jsx("option",{value:"subagent",children:"subagent"}),e.jsx("option",{value:"all",children:"all"})]})]}),e.jsxs("div",{className:"task-form-field",style:{flex:"0 0 80px"},children:[e.jsx("label",{className:"field-label",children:"Color"}),e.jsx("input",{ref:N=>G=N,className:"input",type:"color",defaultValue:"#8b5cf6"})]})]}),e.jsxs("div",{className:"task-form-row",children:[e.jsxs("div",{className:"task-form-field",style:{flex:1},children:[e.jsx("label",{className:"field-label",children:"Category"}),e.jsxs("select",{ref:N=>X=N,className:"select",defaultValue:"",children:[e.jsx("option",{value:"",children:"(none)"}),ms.map(N=>e.jsx("option",{value:N.id,children:N.label},N.id))]})]}),e.jsxs("div",{className:"task-form-field",style:{flex:2},children:[e.jsx("label",{className:"field-label",children:"Tags (comma-separated)"}),e.jsx("input",{ref:N=>q=N,className:"input",type:"text",placeholder:"reasoning, code, planning"})]})]}),e.jsx("label",{className:"field-label",children:"Tools"}),e.jsx("div",{ref:N=>$=N,className:"agent-tools",children:at.map(N=>e.jsxs("label",{className:"checkbox-row",children:[e.jsx("input",{type:"checkbox",value:N}),e.jsx("span",{children:N})]},N))}),e.jsx("label",{className:"field-label",children:"System prompt"}),e.jsx("textarea",{ref:N=>W=N,className:"textarea",rows:6,placeholder:"You are a..."})]}),footer:e.jsxs("div",{className:"modal-footer-actions",children:[e.jsx(z,{variant:"ghost",onClick:()=>i.close(),children:"Cancel"}),e.jsxs(z,{variant:"primary",onClick:async()=>{const N=((m==null?void 0:m.value)||"").trim();if(!/^[a-z0-9][a-z0-9-]{0,63}$/i.test(N)){t.warning("Invalid name (a-z, 0-9, dashes).");return}const E=[];$&&$.querySelectorAll('input[type="checkbox"]:checked').forEach(H=>{E.push(H.value)});const D=((q==null?void 0:q.value)||"").split(",").map(H=>H.trim()).filter(Boolean);try{const H=await A.post("/agents",{name:N,description:((I==null?void 0:I.value)||"").trim(),model:(U==null?void 0:U.value)||"",mode:(R==null?void 0:R.value)||"subagent",color:(G==null?void 0:G.value)||"",tools:E,tags:D,category:(X==null?void 0:X.value)||"",prompt:(W==null?void 0:W.value)||""});d(te=>[...te,H]),t.success("Agent created."),i.close(),await a()}catch(H){t.error(`Create failed: ${H.message}`)}},children:[e.jsx(as,{size:12})," Create"]})]})})},S=async m=>{let I=null,U=null,R=null,G=null,W=null,$=null,q=null,X=null;try{const N=await A.get(`/agents/${encodeURIComponent(m.name)}`);i.open({title:`Edit ${m.name}`,width:640,children:e.jsxs("div",{className:"agent-form",children:[e.jsxs("div",{className:"muted",children:["File: ",e.jsx("code",{children:N.path})]}),e.jsx("label",{className:"field-label",children:"Description"}),e.jsx("input",{ref:E=>{I=E},className:"input",type:"text",defaultValue:N.description}),e.jsxs("div",{className:"task-form-row",children:[e.jsxs("div",{className:"task-form-field",children:[e.jsx("label",{className:"field-label",children:"Model"}),e.jsxs("select",{ref:E=>U=E,className:"select",defaultValue:N.model,children:[e.jsx("option",{value:"",children:"(provider default)"}),nt.map(E=>e.jsx("option",{value:E,children:E},E))]})]}),e.jsxs("div",{className:"task-form-field",children:[e.jsx("label",{className:"field-label",children:"Mode"}),e.jsxs("select",{ref:E=>R=E,className:"select",defaultValue:N.mode||"subagent",children:[e.jsx("option",{value:"primary",children:"primary"}),e.jsx("option",{value:"subagent",children:"subagent"}),e.jsx("option",{value:"all",children:"all"})]})]}),e.jsxs("div",{className:"task-form-field",style:{flex:"0 0 80px"},children:[e.jsx("label",{className:"field-label",children:"Color"}),e.jsx("input",{ref:E=>G=E,className:"input",type:"color",defaultValue:N.color||"#8b5cf6"})]})]}),e.jsxs("div",{className:"task-form-row",children:[e.jsxs("div",{className:"task-form-field",style:{flex:1},children:[e.jsx("label",{className:"field-label",children:"Category"}),e.jsxs("select",{ref:E=>X=E,className:"select",defaultValue:N.category||"",children:[e.jsx("option",{value:"",children:"(none)"}),ms.map(E=>e.jsx("option",{value:E.id,children:E.label},E.id))]})]}),e.jsxs("div",{className:"task-form-field",style:{flex:2},children:[e.jsx("label",{className:"field-label",children:"Tags (comma-separated)"}),e.jsx("input",{ref:E=>q=E,className:"input",type:"text",defaultValue:(N.tags||[]).join(", ")})]})]}),e.jsx("label",{className:"field-label",children:"Tools"}),e.jsx("div",{ref:E=>$=E,className:"agent-tools",children:at.map(E=>{var D;return e.jsxs("label",{className:"checkbox-row",children:[e.jsx("input",{type:"checkbox",value:E,defaultChecked:(D=N.tools)==null?void 0:D.includes(E)}),e.jsx("span",{children:E})]},E)})}),e.jsx("label",{className:"field-label",children:"System prompt"}),e.jsx("textarea",{ref:E=>W=E,className:"textarea",rows:8,defaultValue:N.prompt||""})]}),footer:e.jsxs("div",{className:"modal-footer-actions",children:[e.jsx(z,{variant:"ghost",onClick:()=>i.close(),children:"Cancel"}),e.jsxs(z,{variant:"primary",onClick:async()=>{const E=[];$&&$.querySelectorAll('input[type="checkbox"]:checked').forEach(H=>{E.push(H.value)});const D=((q==null?void 0:q.value)||"").split(",").map(H=>H.trim()).filter(Boolean);try{const H=await A.put(`/agents/${encodeURIComponent(m.name)}`,{description:((I==null?void 0:I.value)||"").trim(),model:(U==null?void 0:U.value)||"",mode:(R==null?void 0:R.value)||"subagent",color:(G==null?void 0:G.value)||"",tools:E,tags:D,category:(X==null?void 0:X.value)||"",prompt:(W==null?void 0:W.value)||""});d(te=>te.map(ie=>ie.name===m.name?H:ie)),t.success("Agent saved."),i.close(),await a()}catch(H){t.error(`Save failed: ${H.message}`)}},children:[e.jsx(as,{size:12})," Save"]})]})})}catch(N){t.error(`Load failed: ${N.message}`)}},b=async m=>{if(confirm(`Delete agent "${m.name}"? This removes ${m.path}.`))try{await A.del(`/agents/${encodeURIComponent(m.name)}`),d(I=>I.filter(U=>U.name!==m.name)),t.success("Agent deleted.")}catch(I){t.error(`Delete failed: ${I.message}`)}},v=async m=>{let I=null;i.open({title:`Invoke ${m.name}`,children:e.jsxs("div",{className:"invoke-form",children:[e.jsxs("p",{className:"muted invoke-form-meta mono",children:[m.model||"—"," · ",m.path]}),e.jsx("p",{className:"invoke-form-desc",children:m.description}),e.jsx("label",{className:"field-label",htmlFor:"invoke-prompt",children:"Prompt"}),e.jsx("textarea",{ref:U=>I=U,id:"invoke-prompt",className:"textarea",rows:5,placeholder:"What should this agent do?",autoFocus:!0})]}),footer:e.jsxs("div",{className:"modal-footer-actions",children:[e.jsx(z,{variant:"ghost",onClick:()=>i.close(),children:"Cancel"}),e.jsxs(z,{variant:"primary",onClick:async()=>{const U=((I==null?void 0:I.value)||"").trim();if(!U){t.warning("Prompt is required.");return}try{await A.post(`/agents/${encodeURIComponent(m.name)}/invoke`,{prompt:U}),t.success(`Invoked ${m.name}.`),i.close()}catch(R){t.error(`Invoke failed: ${R.message}`)}},children:[e.jsx(Us,{size:14})," Invoke"]})]})})},y=async m=>{try{const I=await A.post(`/agents/${encodeURIComponent(m.name)}/restart`);d(U=>U.map(R=>R.name===m.name?I:R)),t.success(`${m.name} restarted.`)}catch(I){t.error(`Restart failed: ${I.message}`)}},T=async(m,I)=>{try{const U=await A.post(`/agents/${encodeURIComponent(m.name)}/status`,{status:I});d(R=>R.map(G=>G.name===m.name?U:G))}catch(U){t.error(`Status update failed: ${U.message}`)}};return e.jsxs("div",{className:"view view-agents",children:[e.jsxs("header",{className:"view-header",children:[e.jsxs("div",{className:"view-header-text",children:[e.jsxs("h2",{className:"view-title",children:[e.jsx(Fe,{size:18})," Agents (",x.length,")"]}),e.jsxs("p",{className:"view-subtitle",children:["The Norse pantheon — click ",e.jsx("kbd",{children:"Edit"})," to modify or ",e.jsx("kbd",{children:"Invoke"})," to dispatch."]})]}),e.jsxs("div",{className:"view-actions",children:[e.jsx("div",{className:"search-input",children:e.jsx("input",{className:"input",type:"text",placeholder:"Search…",value:g,onChange:m=>h(m.target.value)})}),e.jsxs("select",{className:"select select-sm",value:p,onChange:m=>u(m.target.value),children:[e.jsx("option",{value:"",children:"All categories"}),ms.map(m=>e.jsx("option",{value:m.id,children:m.label},m.id)),e.jsx("option",{value:"__none__",children:"(no category)"})]}),e.jsxs(z,{variant:"secondary",size:"sm",onClick:c,children:[e.jsx(de,{size:14})," Refresh"]}),e.jsxs(z,{variant:"primary",size:"sm",onClick:k,children:[e.jsx(je,{size:14})," New agent"]})]})]}),M.length>0&&e.jsxs("div",{className:"agent-tags-row",children:[e.jsx(Ds,{size:12}),M.map(m=>e.jsx("span",{className:"tag",children:m},m))]}),o?e.jsx("div",{className:"view-loading",children:e.jsx(ge,{size:"lg"})}):x.length===0?e.jsx(Re,{icon:e.jsx(Fe,{size:32}),title:"No agents found",message:"Run bizar in the terminal to install Bizar."}):e.jsx("div",{className:"agent-grid",children:x.map(m=>e.jsx(Wn,{agent:m,onInvoke:()=>v(m),onEdit:()=>S(m),onDelete:()=>b(m),onRestart:()=>y(m),onSetStatus:I=>T(m,I)},m.name))})]})}function Wn({agent:s,onInvoke:a,onEdit:t,onDelete:i,onRestart:n,onSetStatus:d}){const[o,l]=r.useState(!1),p=Hn(s.category),u=(s.status==="working"||!!s.currentTaskId)&&!s.isStuck;return e.jsxs(se,{variant:"elevated",interactive:!0,className:Z("agent-card",u&&"is-working",s.isStuck&&"is-stuck"),children:[e.jsxs("div",{className:"agent-card-head",children:[e.jsxs("div",{className:"agent-card-name",children:[e.jsx(_n,{status:s.status,isStuck:s.isStuck}),s.name]}),e.jsxs("div",{className:"agent-card-badges",children:[s.category&&e.jsx("span",{className:"agent-card-category",style:{background:`color-mix(in srgb, ${p} 18%, transparent)`,color:p},children:s.category}),e.jsx(Vn,{agent:s})]})]}),e.jsx("p",{className:"agent-card-desc",children:ut(s.description,200)}),e.jsxs("div",{className:"agent-card-meta",children:[e.jsx("span",{className:"mono",title:s.model||"",children:s.model||"—"}),e.jsx("span",{className:"tabular-nums muted",children:ye(s.mtime)})]}),s.tags&&s.tags.length>0&&e.jsx("div",{className:"agent-card-tags",children:s.tags.map(g=>e.jsx("span",{className:"agent-card-tag",children:g},g))}),(u||s.lastTask)&&e.jsxs("div",{className:"agent-card-activity",children:[s.currentTaskId&&e.jsxs("div",{className:"agent-card-row",children:[e.jsx(ze,{size:12}),e.jsx("span",{className:"muted",children:"Working on"}),e.jsx("code",{className:"mono",children:s.currentTaskId})]}),s.lastTask&&!s.currentTaskId&&e.jsxs("div",{className:"agent-card-row",children:[e.jsx(ys,{size:12}),e.jsx("span",{className:"muted",children:"Last"}),e.jsx("code",{className:"mono",children:s.lastTask.id}),e.jsx("span",{className:"muted tabular-nums",children:ye(s.lastTask.finishedAt)})]}),s.tasksTotal!=null&&s.tasksTotal>0&&e.jsxs("div",{className:"agent-card-row",children:[e.jsx(Sa,{size:12}),e.jsx("span",{className:"muted",children:"Success rate"}),e.jsxs("span",{className:"tabular-nums",children:[Math.round((s.successRate||0)*100),"%"]}),e.jsxs("span",{className:"muted tabular-nums",children:["(",s.tasksSucceeded,"/",s.tasksTotal,")"]})]})]}),s.lastError&&e.jsxs("div",{className:"agent-card-error",children:[e.jsx(Ee,{size:12}),e.jsxs("span",{className:"muted",children:["Last error: ",s.lastError.message]})]}),e.jsxs("div",{className:"agent-card-actions",children:[e.jsxs(z,{variant:"primary",size:"sm",onClick:a,children:[e.jsx(Us,{size:12})," Invoke"]}),e.jsxs(z,{variant:"secondary",size:"sm",onClick:t,children:[e.jsx(rs,{size:12})," Edit"]}),(s.isStuck||s.status==="working"||s.status==="error")&&e.jsxs(z,{variant:"ghost",size:"sm",onClick:n,title:"Reset agent status",children:[e.jsx(pt,{size:12})," Restart"]}),e.jsx(z,{variant:"ghost",size:"sm",onClick:i,children:e.jsx(be,{size:12})}),e.jsx("button",{type:"button",className:"icon-btn","aria-label":o?"Collapse":"Expand",onClick:()=>l(g=>!g),style:{marginLeft:"auto"},children:o?e.jsx(Ae,{size:12}):e.jsx(Ue,{size:12})})]}),o&&e.jsxs("div",{className:"agent-card-expanded",children:[e.jsxs("div",{className:"agent-card-status-actions",children:[e.jsx("span",{className:"muted text-sm",children:"Set status:"}),e.jsx(z,{variant:s.status==="idle"?"primary":"ghost",size:"sm",onClick:()=>d("idle"),children:"Idle"}),e.jsx(z,{variant:s.status==="working"?"primary":"ghost",size:"sm",onClick:()=>d("working"),children:"Working"}),e.jsx(z,{variant:s.status==="error"?"primary":"ghost",size:"sm",onClick:()=>d("error"),children:"Error"})]}),e.jsxs("div",{className:"agent-card-meta",children:[e.jsx(Be,{size:11}),e.jsx("code",{className:"mono agent-card-path",children:s.path})]})]})]})}function Kn({id:s,children:a}){return e.jsx("div",{id:s,"data-block-id":s,className:Z("glyph-richtext"),style:Mt,children:e.jsx(xt,{remarkPlugins:[jt],children:a})})}const Gn={info:{bg:"var(--info-soft, rgba(96, 165, 250, 0.12))",border:"var(--info)",fg:"var(--info)",icon:bs,label:"Note"},warn:{bg:"var(--warning-soft, rgba(251, 191, 36, 0.15))",border:"var(--warning)",fg:"var(--warning)",icon:Ee,label:"Warning"},success:{bg:"var(--success-soft, rgba(52, 211, 153, 0.15))",border:"var(--success)",fg:"var(--success)",icon:ys,label:"Success"},danger:{bg:"var(--error-soft, rgba(248, 113, 113, 0.12))",border:"var(--error)",fg:"var(--error)",icon:bt,label:"Danger"}};function Yn({id:s,tone:a="info",children:t}){const i=Gn[a],n=i.icon;return e.jsxs("div",{id:s,"data-block-id":s,className:Z("glyph-callout",`glyph-callout-${a}`),style:{display:"flex",gap:12,padding:"12px 16px",margin:"12px 0",borderLeft:`3px solid ${i.border}`,background:i.bg,borderRadius:8,color:"var(--text)"},role:a==="danger"||a==="warn"?"alert":void 0,children:[e.jsx("div",{style:{flexShrink:0,color:i.fg,paddingTop:2},children:e.jsx(n,{size:18})}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsx("div",{style:{fontWeight:600,fontSize:13,color:i.fg,marginBottom:4},children:i.label}),e.jsx("div",{className:"glyph-richtext",style:{...Mt,fontSize:14},children:e.jsx(xt,{remarkPlugins:[jt],children:t})})]})]})}function Xn({id:s,items:a}){return e.jsx("ul",{id:s,"data-block-id":s,className:"glyph-checklist",style:{listStyle:"none",padding:0,margin:"12px 0",display:"flex",flexDirection:"column",gap:6},children:a.map(t=>e.jsxs("li",{style:{display:"flex",alignItems:"flex-start",gap:10,padding:"6px 10px",borderRadius:6,background:"var(--bg-elev)",border:"1px solid var(--border)",fontSize:14},children:[e.jsx("span",{"aria-hidden":!0,style:{flexShrink:0,marginTop:1,width:16,height:16,borderRadius:4,border:`1.5px solid ${t.checked?"var(--success)":"var(--border-strong)"}`,background:t.checked?"var(--success)":"transparent",color:"var(--bg)",display:"inline-flex",alignItems:"center",justifyContent:"center"},children:t.checked?e.jsx($s,{size:12,strokeWidth:3}):null}),e.jsx("span",{style:{color:t.checked?"var(--text-dim)":"var(--text)",textDecoration:t.checked?"line-through":"none",wordBreak:"break-word"},children:t.label})]},t.id))})}function Jn({id:s,columns:a,rows:t}){return e.jsx("div",{id:s,"data-block-id":s,className:"glyph-table-wrap",style:{margin:"12px 0",border:"1px solid var(--border)",borderRadius:8,overflow:"auto",background:"var(--bg-elev)"},children:e.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:13},children:[e.jsx("thead",{children:e.jsx("tr",{children:a.map((i,n)=>e.jsx("th",{style:{textAlign:"left",padding:"8px 12px",borderBottom:"1px solid var(--border-strong)",background:"var(--bg)",color:"var(--text-dim)",fontWeight:600,fontSize:12,textTransform:"uppercase",letterSpacing:.3,whiteSpace:"nowrap"},children:i},n))})}),e.jsx("tbody",{children:t.map((i,n)=>e.jsx("tr",{style:{borderTop:n===0?"none":"1px solid var(--border)"},children:i.map((d,o)=>e.jsx("td",{style:{padding:"8px 12px",color:"var(--text)",verticalAlign:"top",wordBreak:"break-word"},children:d},o))},n))})]})})}function Qn({id:s,tabs:a}){var d;const[t,i]=r.useState(((d=a[0])==null?void 0:d.id)??""),n=r.useMemo(()=>a.find(o=>o.id===t)??a[0],[a,t]);return e.jsxs("div",{id:s,"data-block-id":s,className:"glyph-codetabs",style:{margin:"12px 0",border:"1px solid var(--border)",borderRadius:8,overflow:"hidden",background:"var(--bg-elev)"},children:[e.jsx("div",{role:"tablist",style:{display:"flex",gap:2,padding:4,background:"var(--bg)",borderBottom:"1px solid var(--border)",overflowX:"auto"},children:a.map(o=>{const l=o.id===(n==null?void 0:n.id);return e.jsxs("button",{type:"button",role:"tab","aria-selected":l,onClick:()=>i(o.id),style:{padding:"6px 12px",fontSize:12,fontFamily:"var(--font-mono)",borderRadius:6,border:"none",cursor:"pointer",background:l?"var(--bg-elev)":"transparent",color:l?"var(--text-strong)":"var(--text-dim)",boxShadow:l?"0 0 0 1px var(--border)":"none",whiteSpace:"nowrap"},children:[e.jsx("span",{children:o.label}),o.language&&e.jsx("span",{style:{marginLeft:6,color:"var(--text-dim)",fontSize:11},children:o.language})]},o.id)})}),n&&e.jsxs(e.Fragment,{children:[e.jsx("pre",{style:{margin:0,padding:14,overflowX:"auto",fontFamily:"var(--font-mono)",fontSize:12.5,lineHeight:1.55,color:"var(--text)",background:"var(--bg-elev)"},children:e.jsx("code",{children:n.code})}),n.caption&&e.jsx("div",{style:{padding:"8px 14px",borderTop:"1px solid var(--border)",fontSize:12,color:"var(--text-dim)",background:"var(--bg)"},children:n.caption})]})]})}function Zn({id:s,title:a,question:t,options:i}){return e.jsxs("div",{id:s,"data-block-id":s,className:"glyph-decision",style:{margin:"16px 0",padding:16,border:"1px solid var(--border)",borderRadius:10,background:"var(--bg-elev)"},children:[a&&e.jsx("h3",{style:{margin:0,marginBottom:4,fontSize:15,fontWeight:600,color:"var(--text-strong)"},children:a}),t&&e.jsx("p",{style:{margin:0,marginBottom:12,fontSize:13,color:"var(--text-dim)"},children:t}),e.jsx("div",{style:{display:"grid",gap:10,gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))"},children:i.map(n=>{const d=!!n.recommended;return e.jsxs("div",{style:{position:"relative",padding:12,borderRadius:8,border:d?"2px solid var(--success)":"1px solid var(--border)",background:d?"var(--success-soft)":"var(--bg)"},children:[d&&e.jsx("span",{style:{position:"absolute",top:-10,right:10,padding:"2px 8px",fontSize:11,fontWeight:600,color:"var(--bg)",background:"var(--success)",borderRadius:999},children:"Recommended"}),e.jsx("div",{style:{fontWeight:600,fontSize:14,color:"var(--text-strong)",marginBottom:4},children:n.label}),e.jsx("div",{style:{fontSize:13,color:"var(--text)"},children:n.detail})]},n.id)})})]})}function ei({id:s,questions:a}){const[t,i]=r.useState({});function n(d,o){i(l=>({...l,[d]:o}))}return e.jsxs("div",{id:s,"data-block-id":s,className:"glyph-openquestions",style:{margin:"16px 0",padding:16,border:"1px solid var(--border)",borderRadius:10,background:"var(--bg-elev)",display:"flex",flexDirection:"column",gap:14},children:[e.jsx("div",{style:{fontSize:13,fontWeight:600,color:"var(--text-strong)"},children:"Open questions"}),a.map(d=>e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[e.jsx("label",{htmlFor:`oq-${d.id}`,style:{fontSize:13,color:"var(--text)",fontWeight:500},children:d.label}),d.kind==="choice"&&e.jsxs("select",{id:`oq-${d.id}`,value:t[d.id]??"",onChange:o=>n(d.id,o.target.value),style:it,children:[e.jsx("option",{value:"",children:"— select —"}),(d.options??[]).map(o=>e.jsx("option",{value:o,children:o},o))]}),d.kind==="text"&&e.jsx("input",{id:`oq-${d.id}`,type:"text",value:t[d.id]??"",onChange:o=>n(d.id,o.target.value),style:it}),d.kind==="multi"&&e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:4},children:(d.options??[]).map(o=>{const l=t[d.id]??[],p=l.includes(o);return e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,fontSize:13,color:"var(--text)",cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:p,onChange:()=>{const u=p?l.filter(g=>g!==o):[...l,o];n(d.id,u)}}),e.jsx("span",{children:o})]},o)})})]},d.id))]})}const it={padding:"6px 10px",fontSize:13,borderRadius:6,border:"1px solid var(--border-strong)",background:"var(--bg)",color:"var(--text)",fontFamily:"inherit"},si={added:{bg:"var(--success-soft)",fg:"var(--success)",label:"A"},modified:{bg:"var(--info-soft, rgba(96, 165, 250, 0.12))",fg:"var(--info)",label:"M"},removed:{bg:"var(--error-soft)",fg:"var(--error)",label:"D"},renamed:{bg:"rgba(139, 92, 246, 0.15)",fg:"var(--accent)",label:"R"}};function ti({id:s,title:a,entries:t}){return e.jsxs("div",{id:s,"data-block-id":s,className:"glyph-filetree",style:{margin:"12px 0",padding:a?14:8,border:"1px solid var(--border)",borderRadius:8,background:"var(--bg-elev)"},children:[a&&e.jsx("div",{style:{fontSize:12,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:.4,marginBottom:8},children:a}),e.jsx("ul",{style:{listStyle:"none",padding:0,margin:0,display:"flex",flexDirection:"column",gap:2},children:t.map(i=>{const n=si[i.change];return e.jsxs("li",{style:{display:"flex",alignItems:"center",gap:10,padding:"5px 8px",borderRadius:5,fontSize:13},children:[e.jsx("span",{"aria-label":i.change,title:i.change,style:{flexShrink:0,width:22,height:18,borderRadius:4,background:n.bg,color:n.fg,display:"inline-flex",alignItems:"center",justifyContent:"center",fontSize:10,fontWeight:700,fontFamily:"var(--font-mono)"},children:n.label}),e.jsx("span",{style:{fontFamily:"var(--font-mono)",color:"var(--text)",wordBreak:"break-all",flex:1},children:i.path}),i.note&&e.jsx("span",{style:{fontSize:12,color:"var(--text-dim)"},children:i.note})]},i.path)})})]})}function ai({id:s,filename:a,language:t,mode:i="unified",before:n,after:d}){const o=n.split(`
317
- `),l=d.split(`
318
- `),p=e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"6px 12px",background:"var(--bg)",borderBottom:"1px solid var(--border)",fontSize:12,color:"var(--text-dim)",fontFamily:"var(--font-mono)"},children:[e.jsx(Vs,{size:14}),e.jsx("span",{style:{color:"var(--text)"},children:a??"diff"}),t&&e.jsxs("span",{children:["· ",t]}),e.jsx("span",{style:{marginLeft:"auto",textTransform:"uppercase",letterSpacing:.3},children:i})]}),u={margin:0,padding:0,fontFamily:"var(--font-mono)",fontSize:12.5,lineHeight:1.55,color:"var(--text)",background:"var(--bg-elev)"},g=(h,c,x)=>{const M={del:"var(--error-soft)",add:"var(--success-soft)",ctx:"transparent"},k={del:"var(--error)",add:"var(--success)",ctx:"var(--text-dim)"};return e.jsxs("div",{style:{display:"flex",padding:"0 12px",background:M[x]},children:[e.jsx("span",{style:{width:18,color:k[x],userSelect:"none",flexShrink:0},children:h}),e.jsx("span",{style:{whiteSpace:"pre",flex:1,overflowX:"auto"},children:c||" "})]})};return e.jsxs("div",{id:s,"data-block-id":s,className:"glyph-diff",style:{margin:"12px 0",border:"1px solid var(--border)",borderRadius:8,overflow:"hidden",background:"var(--bg-elev)"},children:[p,i==="unified"?e.jsxs("pre",{style:u,children:[o.map((h,c)=>e.jsx("div",{children:g("-",h,"del")},`b${c}`)),l.map((h,c)=>e.jsx("div",{children:g("+",h,"add")},`a${c}`))]}):e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr"},children:[e.jsx("pre",{style:{...u,borderRight:"1px solid var(--border)"},children:o.map((h,c)=>e.jsx("div",{children:g("-",h,"del")},c))}),e.jsx("pre",{style:u,children:l.map((h,c)=>e.jsx("div",{children:g("+",h,"add")},c))})]})]})}const ni={up:{fg:"var(--success)",Icon:Ae,label:"trending up"},down:{fg:"var(--error)",Icon:Ae,label:"trending down"},flat:{fg:"var(--text-dim)",Icon:Va,label:"flat"}};function ii({id:s,label:a,value:t,trend:i,hint:n}){const d=i?ni[i]:null;return e.jsxs("div",{id:s,"data-block-id":s,className:"glyph-stat",style:{padding:14,border:"1px solid var(--border)",borderRadius:10,background:"var(--bg-elev)",display:"flex",flexDirection:"column",gap:4,minWidth:140},children:[e.jsx("div",{style:{fontSize:12,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:.4},children:a}),e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:8},children:[e.jsx("span",{style:{fontSize:24,fontWeight:700,color:"var(--text-strong)"},children:t}),d&&e.jsx("span",{"aria-label":d.label,style:{display:"inline-flex",alignItems:"center",color:d.fg,transform:d.Icon===Ae&&i==="up"?"rotate(180deg)":void 0},children:e.jsx(d.Icon,{size:14})})]}),n&&e.jsx("div",{style:{fontSize:12,color:"var(--text-dim)"},children:n})]})}const li={task:{stroke:"var(--info)",fill:"var(--bg-elev)",fg:"var(--text)"},decision:{stroke:"var(--warning)",fill:"var(--bg-elev)",fg:"var(--text)"},note:{stroke:"var(--border-strong)",fill:"var(--bg)",fg:"var(--text-dim)"}},Ne=160,Se=56,qe=60,We=80;function ri({id:s,steps:a,connections:t=[]}){if(a.length===0)return e.jsx("div",{id:s,"data-block-id":s,className:"glyph-workflow",children:e.jsx(ci,{id:s})});const i=new Map(a.map(g=>[g.id,g])),n=oi(a),d=Math.max(...n.map(g=>g.col))+1,o=Math.max(...n.map(g=>g.row))+1,l=d*(Ne+qe)+qe,p=o*(Se+We)+We;function u(g){if(!i.get(g))return null;const c=n.find(x=>x.id===g);return c?{x:qe+c.col*(Ne+qe)+Ne/2,y:We+c.row*(Se+We)+Se/2}:null}return e.jsx("div",{id:s,"data-block-id":s,className:"glyph-workflow",style:{margin:"12px 0",padding:12,border:"1px solid var(--border)",borderRadius:10,background:"var(--bg-elev)",overflow:"auto"},children:e.jsxs("svg",{role:"img","aria-label":"Workflow diagram",width:l,height:p,style:{display:"block",maxWidth:"100%"},children:[e.jsx("defs",{children:e.jsx("marker",{id:`arrow-${s}`,viewBox:"0 0 10 10",refX:"9",refY:"5",markerWidth:"6",markerHeight:"6",orient:"auto-start-reverse",children:e.jsx("path",{d:"M 0 0 L 10 5 L 0 10 z",fill:"var(--text-dim)"})})}),t.map((g,h)=>{const c=u(g.from),x=u(g.to);if(!c||!x)return null;const M=x.x-c.x,k=x.y-c.y,S=M>=0?c.x+Ne/2:c.x-Ne/2,b=M>=0?x.x-Ne/2:x.x+Ne/2,v=k>=0?c.y+Se/2:c.y-Se/2,y=k>=0?x.y-Se/2:x.y+Se/2,T=(S+b)/2,m=(v+y)/2;return e.jsxs("g",{children:[e.jsx("line",{x1:S,y1:v,x2:b,y2:y,stroke:"var(--text-dim)",strokeWidth:1.5,markerEnd:`url(#arrow-${s})`}),g.label&&e.jsx("text",{x:T,y:m-4,fontSize:10,fill:"var(--text-dim)",textAnchor:"middle",fontFamily:"var(--font-mono)",children:g.label})]},h)}),a.map(g=>{const h=n.find(S=>S.id===g.id);if(!h)return null;const c=qe+h.col*(Ne+qe),x=We+h.row*(Se+We),M=li[g.type];if(g.type==="decision"){const S=c+Ne/2,b=x+Se/2,v=[[S,x],[c+Ne,b],[S,x+Se],[c,b]].map(y=>y.join(",")).join(" ");return e.jsxs("g",{children:[e.jsx("polygon",{points:v,fill:M.fill,stroke:M.stroke,strokeWidth:2}),e.jsx("foreignObject",{x:c+8,y:b-14,width:Ne-16,height:28,children:e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",gap:4,fontSize:12,color:M.fg,textAlign:"center",lineHeight:1.2,fontStyle:"italic",height:"100%"},children:[e.jsx(Ta,{size:11}),g.label]})})]},g.id)}const k=g.type==="note";return e.jsxs("g",{children:[e.jsx("rect",{x:c,y:x,width:Ne,height:Se,rx:8,fill:M.fill,stroke:M.stroke,strokeWidth:k?1:2,strokeDasharray:k?"4 3":void 0}),e.jsx("foreignObject",{x:c+6,y:x+6,width:Ne-12,height:Se-12,children:e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",gap:6,fontSize:12,color:M.fg,textAlign:"center",lineHeight:1.25,fontStyle:k?"italic":"normal",height:"100%"},children:[k&&e.jsx(ta,{size:11}),g.label]})})]},g.id)})]})})}function ci({id:s}){return e.jsx("div",{id:s,style:{padding:20,textAlign:"center",color:"var(--text-dim)",fontSize:13},children:"No workflow steps."})}function oi(s){return s.length===0?[]:s.map((a,t)=>({id:a.id,col:t,row:0}))}const Mt={fontSize:14,lineHeight:1.6,color:"var(--text)"};function di({id:s,title:a,x:t,y:i,w:n,h:d,html:o}){return e.jsxs("figure",{id:s,"data-block-id":s,className:"glyph-mockup",style:{width:n,minHeight:d},children:[a&&e.jsx("figcaption",{className:"glyph-mockup-title",children:a}),e.jsxs("div",{className:"glyph-mockup-frame",children:[e.jsxs("div",{className:"glyph-mockup-chrome",children:[e.jsx("span",{}),e.jsx("span",{}),e.jsx("span",{})]}),e.jsx("div",{className:"glyph-mockup-body",dangerouslySetInnerHTML:{__html:o}})]})]})}const hi={overview:"Overview",implementation:"Implementation plan","implementation-plan":"Implementation plan",questions:"Open questions","open-questions":"Open questions","open-questions-for-you":"Open questions",comments:"Comments",handoff:"Handoff"};function mi(s){const a=[];let t={heading:null,blocks:[]};for(const i of s){const n=hi[i.id]??null;n?((t.blocks.length>0||t.heading!==null)&&a.push(t),t={heading:n,blocks:[i]}):t.blocks.push(i)}return(t.blocks.length>0||t.heading!==null)&&a.push(t),a}function ui({slug:s,onClose:a,onCommentAdded:t}){var ue,B,Q;const i=he(),[n,d]=r.useState(null),[o,l]=r.useState([]),[p,u]=r.useState(!0),[g,h]=r.useState(null),[c,x]=r.useState(null),[M,k]=r.useState(!1),[S,b]=r.useState(!1),[v,y]=r.useState(null),[T,m]=r.useState(null),[I,U]=r.useState(""),[R,G]=r.useState(null),W=r.useRef(null),$=r.useMemo(()=>n?mi(n.blocks):[],[n]);r.useEffect(()=>{let O=!1;const j=5e3;return(async()=>{u(!0),h(null);try{const C=new Promise((V,f)=>setTimeout(()=>f(new Error("Request timed out after 5s")),j)),[L,F]=await Promise.race([Promise.all([A.get(`/artifacts/${encodeURIComponent(s)}/render`),A.get(`/artifacts/${encodeURIComponent(s)}`)]),C]);if(O)return;d(L);const J=(F==null?void 0:F.comments)??[];l(Array.isArray(J)?J:[])}catch(C){if(!O){const L=C.message;h(L),x(L)}}finally{O||u(!1)}})(),()=>{O=!0}},[s]);function q(O){if(!W.current)return;O.preventDefault();const j=W.current.getBoundingClientRect();y({x:O.clientX,y:O.clientY,worldX:O.clientX-j.left,worldY:O.clientY-j.top})}async function X(){if(!(!T||!I.trim()))try{const O=await A.post(`/artifacts/${encodeURIComponent(s)}/comments`,{x:T.worldX,y:T.worldY,text:I.trim(),author:"drb0rk"});l(j=>[...j,{id:O.id??`cmt_${Date.now()}`,x:T.worldX,y:T.worldY,text:I.trim(),author:"drb0rk",created:new Date().toISOString()}]),m(null),U(""),y(null),t==null||t(),i.success("Comment added")}catch(O){i.error(`Failed to add comment: ${O.message}`)}}async function N(){if(!M){k(!0);try{const O=await A.post(`/artifacts/${encodeURIComponent(s)}/submit`,{answers:[],submitter:"drb0rk"});O!=null&&O.ok?(i.success("Sent to agent — feedback.md written, status=review"),t==null||t()):i.error("Submit failed: server did not return ok=true")}catch(O){i.error(`Submit failed: ${O.message}`)}finally{k(!1)}}}function E(){b(O=>!O)}const D=O=>{const j=O.id,C=O.data??{};switch(O.type){case"RichText":return e.jsx(Kn,{id:j,children:O.childrenMarkdown??""},j);case"Callout":return e.jsx(Yn,{id:j,tone:C.tone??"info",children:O.childrenMarkdown??""},j);case"Checklist":return e.jsx(Xn,{id:j,items:C.items??[]},j);case"Table":return e.jsx(Jn,{id:j,columns:C.columns??[],rows:C.rows??[]},j);case"CodeTabs":return e.jsx(Qn,{id:j,tabs:C.tabs??[]},j);case"Decision":return e.jsx(Zn,{id:j,title:C.title,question:C.question,options:C.options??[]},j);case"OpenQuestions":return e.jsx(ei,{id:j,questions:C.questions??[]},j);case"FileTree":return e.jsx(ti,{id:j,title:C.title,entries:C.entries??[]},j);case"Diff":return e.jsx(ai,{id:j,filename:C.filename,language:C.language,mode:C.mode??"unified",before:C.before??"",after:C.after??""},j);case"Stat":return e.jsx(ii,{id:j,label:C.label??"",value:C.value,trend:C.trend,hint:C.hint},j);case"Workflow":return e.jsx(ri,{id:j,steps:C.steps??[],connections:C.connections},j);case"Mockup":return e.jsx(di,{id:j,title:C.title,x:C.x,y:C.y,w:C.w,h:C.h,html:C.html??""},j);case"Diagram":return e.jsx("div",{id:j,className:"glyph-block-placeholder",children:e.jsxs("em",{children:["[Diagram] ",j]})},j)}};if(p)return e.jsx("div",{className:"glyph-renderer glyph-renderer--loading",children:c?e.jsxs(e.Fragment,{children:[e.jsx("strong",{children:"Failed to load glyph."}),e.jsx("pre",{children:c})]}):e.jsxs(e.Fragment,{children:[e.jsx(pi,{})," Loading glyph…"]})});if(g||!n)return e.jsxs("div",{className:"glyph-renderer glyph-renderer--error",children:[e.jsx("strong",{children:"Failed to load glyph."}),e.jsx("pre",{children:g??"unknown error"})]});const H=((ue=n.frontmatter)==null?void 0:ue.title)??s,te=((B=n.frontmatter)==null?void 0:B.status)??"draft",ie=o.length;return e.jsxs("div",{className:`glyph-canvas ${S?"glyph-canvas--fullscreen":""}`,ref:W,onContextMenu:q,children:[e.jsxs("div",{className:"glyph-toolbar-floating",children:[e.jsxs("button",{className:"glyph-btn glyph-btn--primary glyph-btn--send",onClick:N,disabled:M,title:"Send comments + question answers to the agent — writes feedback.md, status=review",children:[e.jsx(Qe,{size:14}),e.jsx("span",{children:"Send to agent"}),e.jsx("span",{className:"glyph-btn-badge",children:ie})]}),e.jsx("span",{className:"glyph-toolbar-divider"}),e.jsx("button",{className:"glyph-icon-btn",title:"Share",onClick:()=>{typeof window<"u"&&navigator.clipboard&&(navigator.clipboard.writeText(window.location.href).catch(()=>{}),i.success("Link copied"))},children:e.jsx(Qa,{size:15})}),e.jsx("button",{className:"glyph-icon-btn",title:"Undo",disabled:!0,children:e.jsx(sn,{size:15})}),e.jsx("button",{className:"glyph-icon-btn",title:"Redo",disabled:!0,children:e.jsx(Ja,{size:15})}),e.jsx("button",{className:"glyph-icon-btn",title:S?"Exit fullscreen":"Fullscreen",onClick:E,children:e.jsx(_a,{size:15})}),e.jsx("button",{className:"glyph-icon-btn",title:"More",children:e.jsx(Aa,{size:15})}),e.jsx("span",{className:"glyph-toolbar-divider"}),e.jsxs("button",{className:"glyph-icon-btn",title:"Comment count","aria-label":"Comment count",children:[e.jsx(Xe,{size:15}),e.jsx("span",{className:"glyph-icon-btn-count",children:ie})]}),a&&e.jsx("button",{className:"glyph-icon-btn glyph-icon-btn--close",title:"Close",onClick:a,"aria-label":"Close",children:e.jsx($e,{size:15})})]}),e.jsxs("div",{className:"glyph-canvas-content",children:[e.jsxs("header",{className:"glyph-canvas-title",children:[e.jsx("h1",{className:"glyph-title",children:H}),e.jsxs("div",{className:"glyph-meta",children:[e.jsx("span",{className:`glyph-status glyph-status--${te}`,children:te}),e.jsx("span",{className:"glyph-slug",children:s})]})]}),((Q=n.errors)==null?void 0:Q.length)>0&&e.jsxs("div",{className:"glyph-errors",children:[e.jsx("strong",{children:"Compiler warnings:"}),e.jsx("ul",{children:n.errors.map((O,j)=>e.jsx("li",{children:O},j))})]}),e.jsx("div",{className:"glyph-sections",children:$.map((O,j)=>e.jsxs("section",{className:`glyph-section ${O.heading?"glyph-section--headed":"glyph-section--plain"}`,children:[O.heading&&e.jsx("h2",{className:"glyph-section-heading",children:O.heading}),e.jsx("div",{className:"glyph-section-blocks",children:O.blocks.map(D)})]},`sec-${j}-${O.heading??"ungrouped"}`))})]}),o.map(O=>e.jsxs("button",{className:`glyph-pin ${R===O.id?"glyph-pin--active":""}`,style:{left:O.x,top:O.y},onClick:j=>{j.stopPropagation(),G(R===O.id?null:O.id)},title:O.text,children:[e.jsx(st,{size:14}),R===O.id&&e.jsxs("div",{className:"glyph-pin-thread",children:[e.jsx("div",{className:"glyph-pin-text",children:O.text}),e.jsxs("div",{className:"glyph-pin-meta",children:[O.author??"anonymous"," · ",O.created?new Date(O.created).toLocaleString():""]})]})]},O.id)),v&&e.jsx("div",{className:"glyph-ctx-menu",style:{left:v.x,top:v.y},onClick:O=>O.stopPropagation(),children:e.jsxs("button",{className:"glyph-ctx-item",onClick:()=>{m({worldX:v.worldX,worldY:v.worldY}),y(null)},children:[e.jsx(st,{size:14})," Add comment here"]})}),T&&e.jsx("div",{className:"glyph-modal-overlay",onClick:()=>m(null),children:e.jsxs("div",{className:"glyph-modal",onClick:O=>O.stopPropagation(),children:[e.jsxs("h3",{children:["Add comment at (",Math.round(T.worldX),", ",Math.round(T.worldY),")"]}),e.jsx("textarea",{autoFocus:!0,value:I,onChange:O=>U(O.target.value),placeholder:"What should the agent know about this area?",rows:4,className:"glyph-modal-textarea"}),e.jsxs("div",{className:"glyph-modal-actions",children:[e.jsx("button",{className:"glyph-btn glyph-btn--ghost",onClick:()=>m(null),children:"Cancel"}),e.jsx("button",{className:"glyph-btn glyph-btn--primary",onClick:X,disabled:!I.trim(),children:"Add comment"})]})]})})]})}function pi(){return e.jsx("span",{className:"glyph-spinner","aria-label":"loading",children:"…"})}function xi(s){switch(s){case"approved":case"done":return"success";case"in-progress":case"doing":return"info";case"rejected":return"error";case"archived":return"warning";case"draft":default:return"neutral"}}function ji({snapshot:s,refreshSnapshot:a}){const t=he(),[i,n]=r.useState(s.artifacts||[]),[d,o]=r.useState(!s.artifacts),[l,p]=r.useState(null),[u,g]=r.useState(""),[h,c]=r.useState(!1);r.useEffect(()=>{s.artifacts&&(n(s.artifacts),o(!1))},[s.artifacts]);const x=async()=>{try{const b=await A.get("/artifacts");n(b.artifacts||[]),o(!1)}catch(b){t.error(`Artifacts load failed: ${b.message}`),o(!1)}},M=r.useMemo(()=>{let b=i;if(u){const v=u.toLowerCase();b=b.filter(y=>(y.slug||"").toLowerCase().includes(v)||(y.title||"").toLowerCase().includes(v))}return h||(b=b.filter(v=>v.status!=="archived")),b},[i,u,h]),k=async(b,v)=>{try{const y=await A.post("/artifacts",{slug:b,title:v});t.success(`Artifact "${y.slug}" created.`),p(y.slug),await x()}catch(y){t.error(`Create failed: ${y.message}`)}},S=async b=>{if(confirm(`Delete artifact "${b}"? This removes the directory permanently.`))try{await A.del(`/artifacts/${encodeURIComponent(b)}`),t.success("Artifact deleted."),l===b&&p(null),await x()}catch(v){t.error(`Delete failed: ${v.message}`)}};return l?e.jsxs("div",{className:"artifact-glyph-overlay",children:[e.jsx("div",{className:"artifact-glyph-toolbar",children:e.jsxs(z,{variant:"ghost",onClick:()=>{p(null),x()},children:[e.jsx(vt,{size:14})," Back to artifacts"]})}),e.jsx(ui,{slug:l,onClose:()=>{p(null),x()},onCommentAdded:()=>x()})]}):e.jsxs("div",{className:"view view-artifacts",children:[e.jsxs("header",{className:"view-header",children:[e.jsxs("div",{className:"view-header-text",children:[e.jsxs("h2",{className:"view-title",children:[e.jsx(ls,{size:18})," Glyphs (",i.length,")"]}),e.jsx("p",{className:"view-subtitle",children:"Visual artifacts with elements, connections, and threaded comments."})]}),e.jsxs("div",{className:"view-actions",children:[e.jsxs("div",{className:"search-input",children:[e.jsx(Oe,{size:14}),e.jsx("input",{className:"input",type:"text",placeholder:"Search…",value:u,onChange:b=>g(b.target.value)})]}),e.jsxs(z,{variant:"ghost",size:"sm",onClick:()=>c(b=>!b),title:h?"Hide archived":"Show archived",children:[h?e.jsx(xs,{size:14}):e.jsx(ps,{size:14}),h?"Hide archived":"Show archived"]}),e.jsxs(z,{variant:"secondary",size:"sm",onClick:x,children:[e.jsx(de,{size:14})," Refresh"]})]})]}),e.jsx(fi,{onCreate:k}),d?e.jsx("div",{className:"view-loading",children:e.jsx(ge,{size:"lg"})}):M.length===0?e.jsx(Re,{icon:e.jsx(ls,{size:32}),title:h?"No artifacts":"No artifacts yet",message:h?"No artifacts match your filter (try Show archived off).":"Create one above to get started."}):e.jsx("div",{className:"artifacts-grid",children:M.map(b=>e.jsx(gi,{artifact:b,onOpen:()=>p(b.slug),onDelete:()=>S(b.slug)},b.slug))})]})}function fi({onCreate:s}){const[a,t]=r.useState(""),[i,n]=r.useState("");return e.jsxs(se,{className:"new-artifact",children:[e.jsxs(ne,{children:[e.jsx(je,{size:14})," New artifact"]}),e.jsx(re,{children:"Slug must be lowercase, may contain hyphens, 1–64 chars."}),e.jsxs("form",{className:"new-artifact-form",onSubmit:d=>{d.preventDefault(),a.trim()&&(s(a.trim(),i.trim()||void 0),t(""),n(""))},children:[e.jsx("input",{className:"input",type:"text",placeholder:"slug (e.g. dashboard-v3.1)",pattern:"[a-z0-9][a-z0-9-]{0,63}",required:!0,value:a,onChange:d=>t(d.target.value)}),e.jsx("input",{className:"input",type:"text",placeholder:"Title (optional)",value:i,onChange:d=>n(d.target.value)}),e.jsx(z,{variant:"primary",type:"submit",children:"Create"})]})]})}function gi({artifact:s,onOpen:a,onDelete:t}){const i=xi(s.status||"draft");return e.jsxs(se,{variant:"elevated",interactive:!0,className:"artifact-card",onClick:a,children:[e.jsxs("div",{className:"artifact-card-head",children:[e.jsx("div",{className:"artifact-card-title",children:s.title||s.slug}),e.jsx(Le,{kind:i,children:s.status||"draft"})]}),e.jsxs("div",{className:"artifact-card-slug mono",children:[s.slug," · ",s.source]}),e.jsxs("div",{className:"artifact-card-meta",children:[s.elementCount!=null&&e.jsxs("span",{children:[s.elementCount," elements"]}),s.commentCount!=null&&e.jsxs("span",{children:[" · ",s.commentCount," comments"]}),e.jsxs("span",{children:[" · edited ",ye(s.mtime)]})]}),e.jsxs("div",{className:"artifact-card-actions",children:[e.jsxs(z,{variant:"primary",size:"sm",onClick:n=>{n.stopPropagation(),a()},children:["Open",e.jsx(Ue,{size:12})]}),e.jsxs(z,{variant:"ghost",size:"sm",onClick:n=>{n.stopPropagation(),t()},children:[e.jsx(be,{size:12})," Delete"]})]})]})}function vi({children:s,className:a,onRemove:t}){return e.jsxs("span",{className:Z("tag",a),children:[s,t&&e.jsx("button",{type:"button",className:"tag-remove","aria-label":`Remove ${typeof s=="string"?s:"tag"}`,onClick:t,children:"×"})]})}const yi={pending:"info",running:"accent",done:"success",failed:"error",killed:"neutral",timed_out:"warning"},bi={pending:"Pending",running:"Running",done:"Done",failed:"Failed",killed:"Killed",timed_out:"Timed out"};function $t({status:s,dot:a}){const t=yi[s]||"neutral",i=bi[s]||s;return e.jsx(Le,{kind:t,dot:a,children:i})}function ki({instanceId:s,instanceName:a,onConfirm:t,onClose:i}){return e.jsxs("div",{children:[e.jsxs("p",{style:{marginBottom:16,lineHeight:1.6},children:["Instance ",e.jsx("code",{children:s}),a?e.jsxs(e.Fragment,{children:[" (",a,")"]}):null," will be terminated. This cannot be undone."]}),e.jsxs("div",{style:{display:"flex",gap:8,justifyContent:"flex-end"},children:[e.jsx(z,{variant:"ghost",onClick:i,children:"Cancel"}),e.jsx(z,{variant:"danger",onClick:async()=>{await t(),i()},children:"Kill"})]})]})}function Rt(s,a,t,i,n){s.open({title:"Kill instance?",width:400,children:e.jsx(ki,{instanceId:t,instanceName:i,onConfirm:async()=>{try{const o=await(await fetch(`/api/background/${encodeURIComponent(t)}`,{method:"DELETE"})).json();o.ok?(a.success(`Instance ${t} killed.`),n==null||n()):a.error(`Kill failed: ${o.error||"unknown error"}`)}catch(d){a.error(`Kill failed: ${d.message}`)}},onClose:()=>s.close()})})}function Ni(s){return A.urlWithToken(`/artifacts/${encodeURIComponent(s)}/content`)}function It(s,a){const t=Ni(a);window.open(t,"_blank","noopener,noreferrer")}const ss=[{id:"queued",label:"Queued",kind:"info"},{id:"doing",label:"Doing",kind:"accent"},{id:"blocked",label:"Blocked",kind:"warning"},{id:"done",label:"Done",kind:"success"}];function lt(s,a){const t=s.status==="archived"||s.archived===!0;return a==="done"?s.status==="done"||t:!t&&s.status===a}const qs=["low","normal","high"],wi=[{id:"updated",label:"Last updated"},{id:"created",label:"Created"},{id:"priority",label:"Priority"},{id:"due",label:"Due date"}];function Ci({snapshot:s,refreshSnapshot:a,setActiveTab:t}){const i=he(),n=ke(),[d,o]=r.useState(s.tasks||[]),[l,p]=r.useState(!s.tasks),[u,g]=r.useState(""),[h,c]=r.useState(""),[x,M]=r.useState(""),[k,S]=r.useState(""),[b,v]=r.useState("updated"),[y,T]=r.useState(!1),[m,I]=r.useState(new Set),[U,R]=r.useState(0),G=async(j={})=>{try{const C=j.archived?"?archived=only":"",L=await A.get(`/tasks${C}`);o(Array.isArray(L)?L:[])}catch(C){i.error(`Tasks load failed: ${C.message}`)}finally{p(!1)}};r.useEffect(()=>{s.tasks&&(o(s.tasks),p(!1))},[s.tasks]),r.useEffect(()=>{const j=setInterval(()=>R(C=>C+1),1e3);return()=>clearInterval(j)},[]);const W=r.useMemo(()=>{const j=new Set;for(const C of d)for(const L of C.tags||[])j.add(L);return Array.from(j).sort()},[d]),$=r.useMemo(()=>{let j=d;if(h&&(j=j.filter(C=>(C.assignee||"")===h)),x&&(j=j.filter(C=>(C.priority||"normal")===x)),k&&(j=j.filter(C=>(C.tags||[]).includes(k))),u.trim()){const C=u.toLowerCase();j=j.filter(L=>{const F=(L.title||"").toLowerCase(),J=(L.description||"").toLowerCase(),V=(L.tags||[]).join(" ").toLowerCase();return F.includes(C)||J.includes(C)||V.includes(C)})}return j},[d,u,h,x,k]),q=r.useMemo(()=>{const j=[...$],C={high:0,normal:1,low:2};switch(b){case"priority":j.sort((L,F)=>(C[L.priority]??1)-(C[F.priority]??1));break;case"created":j.sort((L,F)=>new Date(F.createdAt).getTime()-new Date(L.createdAt).getTime());break;case"due":j.sort((L,F)=>{const J=L.dueDate?new Date(L.dueDate).getTime():1/0,V=F.dueDate?new Date(F.dueDate).getTime():1/0;return J-V});break;case"updated":default:j.sort((L,F)=>new Date(F.updatedAt).getTime()-new Date(L.updatedAt).getTime());break}return j},[$,b]),X=async(j,C)=>{const L=d.find(J=>J.id===j);if(!L)return;const F=L.status;o(J=>J.map(V=>V.id===j?{...V,status:C}:V));try{await A.patch(`/tasks/${encodeURIComponent(j)}/status`,{status:C}),i.success(`Moved to ${C}.`,1500)}catch(J){o(V=>V.map(f=>f.id===j?{...f,status:F}:f)),i.error(`Move failed: ${J.message}`)}},N=async j=>{if(confirm("Delete this task?"))try{await A.del(`/tasks/${encodeURIComponent(j)}`),o(C=>C.filter(L=>L.id!==j)),i.success("Task deleted.",1500)}catch(C){i.error(`Delete failed: ${C.message}`)}},E=async j=>{try{const C=await A.post(`/tasks/${encodeURIComponent(j)}/archive`);o(L=>L.filter(F=>F.id!==j)),i.success("Task archived.",1500)}catch(C){i.error(`Archive failed: ${C.message}`)}},D=async j=>{try{const C=await A.post(`/tasks/${encodeURIComponent(j)}/unarchive`);o(L=>L.map(F=>F.id===j?C:F)),i.success("Task restored.",1500)}catch(C){i.error(`Restore failed: ${C.message}`)}},H=async(j,C={})=>{if(m.size===0)return;const L=Array.from(m);try{const F=await A.post("/tasks/bulk",{ids:L,action:j,params:C}),J=F.affected.filter(f=>f.ok).length,V=F.affected.length-J;j==="archive"||j==="delete"?o(f=>f.filter(_=>!L.includes(_.id))):await G(),i.success(`Bulk ${j}: ${J} ok${V?`, ${V} failed`:""}.`,2500),I(new Set)}catch(F){i.error(`Bulk failed: ${F.message}`)}},te=async j=>{try{const L=await A.put(`/tasks/${encodeURIComponent(j.id)}`,{assignee:"me"});o(F=>F.map(J=>J.id===j.id?L:J)),i.success("Assigned to me.",1200)}catch(C){i.error(`Assign failed: ${C.message}`)}},ie=async(j,C,L,F)=>{try{const J=await A.post(`/tasks/${encodeURIComponent(j.id)}/work`,{agent:C,status:L,complete:F});o(V=>V.map(f=>f.id===j.id?J:f)),i.success(`Marked ${L} by ${C}.`,1500)}catch(J){i.error(`Mark failed: ${J.message}`)}},ue=j=>{I(C=>{const L=new Set(C);return L.has(j)?L.delete(j):L.add(j),L})},B=j=>{I(C=>{const L=new Set(C);return j.length>0&&j.every(J=>L.has(J))?(j.forEach(J=>L.delete(J)),L):(j.forEach(J=>L.add(J)),L)})},Q=j=>{t("chat"),window.dispatchEvent(new CustomEvent("bizar:setChatTask",{detail:{taskId:j}}))},O=j=>{It(n,j)};return e.jsxs("div",{className:"view view-tasks",children:[e.jsx("header",{className:"view-header",children:e.jsxs("div",{className:"view-header-text",children:[e.jsxs("h2",{className:"view-title",children:[e.jsx(Pe,{size:18})," Tasks (",q.length,")"]}),e.jsx("p",{className:"view-subtitle",children:"Personal kanban. Click a card for details (subtasks, deps, timer, comments, activity)."})]})}),e.jsxs("div",{className:"tasks-toolbar",children:[e.jsx("div",{className:"tasks-toolbar-group",children:e.jsxs("div",{className:"search-input",style:{width:200},children:[e.jsx(Oe,{size:12}),e.jsx("input",{className:"input",type:"text",placeholder:"Search…",value:u,onChange:j=>g(j.target.value)}),u&&e.jsx("button",{type:"button",className:"icon-btn","aria-label":"Clear search",onClick:()=>g(""),children:e.jsx($e,{size:12})})]})}),e.jsx("div",{className:"tasks-toolbar-divider"}),e.jsxs("div",{className:"tasks-toolbar-group",children:[e.jsx("span",{className:"tasks-toolbar-label",children:"Filter"}),e.jsxs("select",{className:"select select-sm",value:h,onChange:j=>c(j.target.value),title:"Assignee",children:[e.jsx("option",{value:"",children:"All assignees"}),e.jsx("option",{value:"me",children:"Me"}),(s.agents||[]).map(j=>e.jsxs("option",{value:j.name,children:["@",j.name]},j.name))]}),e.jsxs("select",{className:"select select-sm",value:x,onChange:j=>M(j.target.value),title:"Priority",children:[e.jsx("option",{value:"",children:"All priorities"}),qs.map(j=>e.jsx("option",{value:j,children:j},j))]}),W.length>0&&e.jsxs("select",{className:"select select-sm",value:k,onChange:j=>S(j.target.value),title:"Tag",children:[e.jsx("option",{value:"",children:"All tags"}),W.map(j=>e.jsxs("option",{value:j,children:["#",j]},j))]})]}),e.jsx("div",{className:"tasks-toolbar-divider"}),e.jsxs("div",{className:"tasks-toolbar-group",children:[e.jsx("span",{className:"tasks-toolbar-label",children:"Sort"}),e.jsx("select",{className:"select select-sm",value:b,onChange:j=>v(j.target.value),title:"Sort by",children:wi.map(j=>e.jsx("option",{value:j.id,children:j.label},j.id))})]}),e.jsx("div",{className:"tasks-toolbar-spacer"}),e.jsxs("div",{className:"tasks-toolbar-group",children:[e.jsxs(z,{variant:y?"primary":"ghost",size:"sm",onClick:()=>{T(j=>!j),G({archived:!y})},title:y?"Showing archived":"Show archived",children:[y?e.jsx(xs,{size:14}):e.jsx(ps,{size:14}),y?"Active":"Archived"]}),e.jsx(z,{variant:"ghost",size:"sm",onClick:()=>G(),title:"Refresh","aria-label":"Refresh tasks",children:e.jsx(de,{size:14})}),e.jsxs(z,{variant:"accent",size:"sm",onClick:()=>Ai(n,i,o,G,a),children:[e.jsx(Qe,{size:14})," Odin"]}),e.jsxs(z,{variant:"primary",size:"sm",onClick:()=>Es(n,i,null,"queued",o,G,a,s.agents),children:[e.jsx(je,{size:14})," Add"]})]})]}),m.size>0&&e.jsxs("div",{className:"task-bulk-bar",children:[e.jsxs("span",{className:"text-sm",children:[e.jsx(Pe,{size:14})," ",m.size," selected"]}),e.jsxs("div",{className:"task-bulk-bar-actions",children:[e.jsx(z,{size:"sm",variant:"ghost",onClick:()=>H("move",{status:"queued"}),children:"Queued"}),e.jsx(z,{size:"sm",variant:"ghost",onClick:()=>H("move",{status:"doing"}),children:"Doing"}),e.jsx(z,{size:"sm",variant:"ghost",onClick:()=>H("move",{status:"done"}),children:"Done"}),e.jsx(z,{size:"sm",variant:"ghost",onClick:()=>H("priority",{priority:"high"}),children:"High"}),e.jsxs(z,{size:"sm",variant:"ghost",onClick:()=>H("archive"),children:[e.jsx(ps,{size:12})," Archive"]}),e.jsxs(z,{size:"sm",variant:"danger",onClick:()=>H("delete"),children:[e.jsx(be,{size:12})," Delete"]}),e.jsx(z,{size:"sm",variant:"ghost",onClick:()=>I(new Set),children:"Clear"})]})]}),l?e.jsx("div",{className:"view-loading",children:e.jsx(ge,{size:"lg"})}):e.jsx("div",{className:"kanban",children:ss.map(j=>e.jsx(Si,{column:j,tasks:q.filter(C=>lt(C,j.id)),selected:m,onToggleSelect:ue,onToggleSelectAll:B,allTaskIdsInCol:q.filter(C=>lt(C,j.id)).map(C=>C.id),onMove:X,onDelete:N,onArchive:E,onUnarchive:D,onEdit:C=>Ti(n,i,C,o,G,a,s.agents,U),onAdd:()=>Es(n,i,null,j.id,o,G,a,s.agents),onAssignMe:te,onMarkWorkedBy:ie,onOpenChat:Q,onOpenArtifact:O,isArchivedView:y},j.id))})]})}function Si({column:s,tasks:a,selected:t,onToggleSelect:i,onToggleSelectAll:n,allTaskIdsInCol:d,onMove:o,onDelete:l,onArchive:p,onUnarchive:u,onEdit:g,onAdd:h,onAssignMe:c,onMarkWorkedBy:x,onOpenChat:M,onOpenArtifact:k,isArchivedView:S}){const[b,v]=r.useState(!1),y=a.length>0&&d.every(T=>t.has(T));return e.jsxs("div",{className:Z("kanban-column",b&&"kanban-column-drop"),"data-column":s.id,onDragOver:T=>{T.preventDefault(),v(!0)},onDragLeave:()=>v(!1),onDrop:T=>{T.preventDefault(),v(!1);const m=T.dataTransfer.getData("text/task-id");m&&o(m,s.id)},children:[e.jsxs("div",{className:"kanban-col-header",children:[e.jsx("button",{type:"button",className:"icon-btn",onClick:()=>n(d),title:y?"Deselect all":"Select all","aria-label":y?"Deselect all":"Select all",children:y?e.jsx(Pe,{size:12}):e.jsx(St,{size:12})}),e.jsx(ne,{children:e.jsx(Le,{kind:s.kind,dot:!0,children:s.label})}),e.jsx("span",{className:"kanban-col-count tabular-nums",children:a.length})]}),e.jsx("div",{className:"kanban-col-body",children:a.length===0?e.jsx("div",{className:"kanban-empty",children:"No tasks"}):a.map(T=>e.jsx(zi,{task:T,focused:t.has(T.id),onFocus:()=>i(T.id),onMove:m=>{const U=ss.findIndex(R=>R.id===T.status)+m;U>=0&&U<ss.length&&o(T.id,ss[U].id)},onEdit:()=>g(T),onDelete:()=>l(T.id),onArchive:()=>p(T.id),onUnarchive:()=>u(T.id),onAssignMe:()=>c(T),onMarkWorkedBy:(m,I,U)=>x(T,m,I,U),onOpenChat:M,onOpenArtifact:k,isArchivedView:S},T.id))}),!S&&e.jsx("footer",{className:"kanban-col-footer",children:e.jsxs(z,{variant:"ghost",size:"sm",onClick:h,className:"w-full",children:[e.jsx(je,{size:12})," Add task"]})})]})}function zi({task:s,focused:a,onFocus:t,onMove:i,onEdit:n,onDelete:d,onArchive:o,onUnarchive:l,onAssignMe:p,onMarkWorkedBy:u,onOpenChat:g,onOpenArtifact:h,isArchivedView:c}){var m,I,U;const x=he(),M=ke(),k=s._timerStart,S=(s.workedBy||s.status==="doing")&&!c,b=s.metadata||{},v=!!(b.sessionId||b.bgInstanceId),T=(b.artifactIds||(b.artifactId?[b.artifactId]:[]))[0];return e.jsxs("div",{className:Z("task-card",`priority-${s.priority}`,a&&"task-card-focused",k?"task-card-timer is-working":null,S&&!k?"is-working":null),"data-task-id":s.id,"data-task-parent":s.parent||"",draggable:!c,onDragStart:R=>{R.dataTransfer.setData("text/task-id",s.id),R.dataTransfer.effectAllowed="move"},onClick:t,children:[e.jsxs("div",{className:"task-card-head",children:[e.jsx("button",{type:"button",className:Z("task-card-checkbox",a&&"task-card-checkbox-on"),"aria-label":a?"Deselect task":"Select task",title:a?"Deselect":"Select",onClick:R=>{R.stopPropagation(),t()},children:a?e.jsx(Pe,{size:13}):e.jsx(St,{size:13})}),e.jsx("span",{className:"priority-dot",style:{background:ia[s.priority]||"var(--info)"}}),e.jsx("div",{className:"task-card-title",children:s.title}),k&&e.jsxs("span",{className:"task-card-timer-pill",children:[e.jsx(Je,{size:10})," running"]}),s.workedBy&&s.status==="doing"&&!k&&e.jsxs("span",{className:"task-card-timer-pill",title:`@${s.workedBy}`,children:[e.jsx(Fe,{size:10})," @",s.workedBy]}),s.recurring&&e.jsx("span",{className:"task-card-timer-pill",title:"Recurring",children:e.jsx(pt,{size:10})})]}),s.description&&e.jsx("div",{className:"task-card-desc",children:s.description.slice(0,160)}),e.jsxs("div",{className:"task-card-badges",children:[s.assignee&&!s.workedBy&&e.jsxs("span",{className:"task-card-badge",children:[e.jsx(Ds,{size:10})," @",s.assignee]}),s.timeSpent?e.jsxs("span",{className:"task-card-badge",children:[e.jsx(Je,{size:10})," ",Ps(s.timeSpent)]}):null,(m=s.dependencies)!=null&&m.length?e.jsxs("span",{className:"task-card-badge",children:[e.jsx(Nt,{size:10})," ",s.dependencies.length]}):null,s.recurring?e.jsxs("span",{className:"task-card-badge",children:[e.jsx(yt,{size:10})," ",s.recurring.cron||s.recurring.freq||"recurring"]}):null,(I=s.comments)!=null&&I.length?e.jsxs("span",{className:"task-card-badge",children:[e.jsx(Xe,{size:10})," ",s.comments.length]}):null,(U=s.attachments)!=null&&U.length?e.jsxs("span",{className:"task-card-badge",children:[e.jsx(la,{size:10})," ",s.attachments.length]}):null,b.bgInstanceId?e.jsxs("span",{className:"task-card-badge",children:[e.jsx(ze,{size:10})," ",e.jsx($t,{status:b.status||"pending"})]}):null]}),s.tags&&s.tags.length>0&&e.jsx("div",{className:"task-card-tags",children:s.tags.map(R=>e.jsx(vi,{children:R},R))}),e.jsxs("div",{className:"task-card-footer",children:[e.jsx("span",{className:"task-card-time tabular-nums muted",children:ye(s.updatedAt||s.createdAt)}),e.jsxs("div",{className:"task-card-actions",onClick:R=>R.stopPropagation(),children:[!c&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:"icon-btn","aria-label":"Move left",title:"Move left",onClick:()=>i(-1),children:e.jsx(wa,{size:14})}),e.jsx("button",{type:"button",className:"icon-btn","aria-label":"Edit",title:"Open detail",onClick:n,children:e.jsx(Me,{size:14})}),e.jsx("button",{type:"button",className:"icon-btn","aria-label":"Assign me",title:"Assign to me",onClick:p,children:e.jsx(Ds,{size:14})}),v&&e.jsx("button",{type:"button",className:"icon-btn","aria-label":"Open chat",title:"Open in chat",onClick:()=>g(s.id),children:e.jsx(Xe,{size:14})}),T&&e.jsx("button",{type:"button",className:"icon-btn","aria-label":"Open artifact",title:"Open artifact",onClick:()=>h(T),children:e.jsx(ks,{size:14})}),c?e.jsx("button",{type:"button",className:"icon-btn","aria-label":"Restore",title:"Restore",onClick:l,children:e.jsx(xs,{size:14})}):e.jsx("button",{type:"button",className:"icon-btn","aria-label":"Archive",title:"Archive",onClick:o,children:e.jsx(ps,{size:14})}),b.bgInstanceId&&e.jsx("button",{type:"button",className:"icon-btn icon-btn-danger","aria-label":"Kill background instance",title:"Kill background instance",onClick:()=>{Rt(M,x,b.bgInstanceId,s.title,()=>{const R=new CustomEvent("bizar:taskKilled",{detail:{taskId:s.id,bgInstanceId:b.bgInstanceId}});window.dispatchEvent(R)})},children:e.jsx(ze,{size:14})}),e.jsx("button",{type:"button",className:"icon-btn icon-btn-danger","aria-label":"Delete",title:"Delete",onClick:d,children:e.jsx(be,{size:14})}),e.jsx("button",{type:"button",className:"icon-btn","aria-label":"Move right",title:"Move right",onClick:()=>i(1),children:e.jsx(Ue,{size:14})})]}),c&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:"icon-btn","aria-label":"Restore",title:"Restore",onClick:l,children:e.jsx(xs,{size:14})}),e.jsx("button",{type:"button",className:"icon-btn icon-btn-danger","aria-label":"Delete",title:"Delete",onClick:d,children:e.jsx(be,{size:14})})]})]})]})]})}function Ps(s){if(!s)return"0m";const a=Math.floor(s/3600),t=Math.floor(s%3600/60);return a>0?`${a}h ${t}m`:`${t}m`}function Es(s,a,t,i,n,d,o,l=[]){var v,y,T;let p=null,u=null,g=null,h=null,c=null,x=null,M=null,k=null,S=null;const b=async()=>{var D;const m=(p==null?void 0:p.value.trim())||"";if(!m){a.warning("Title is required."),p==null||p.focus();return}const I=(u==null?void 0:u.value.trim())||"",U=((D=h==null?void 0:h.querySelector('input[name="task-priority"]:checked'))==null?void 0:D.value)||"normal",R=(g==null?void 0:g.value.trim())||"",G=R?R.split(",").map(H=>H.trim()).filter(Boolean):[],W=(c==null?void 0:c.value)||i,$=((x==null?void 0:x.value)||"").trim()||null,q=(M==null?void 0:M.value)||"",X=(k==null?void 0:k.value.trim())||"",N=q==="custom"&&X?{freq:"custom",cron:X}:q&&q!=="none"?{freq:q}:null,E=(S==null?void 0:S.value)||null;try{if(t){const H=await A.put(`/tasks/${encodeURIComponent(t.id)}`,{title:m,description:I,tags:G,priority:U,status:W,assignee:$,recurring:N,dueDate:E});s.close(),typeof window<"u"&&window.dispatchEvent(new MouseEvent("mousedown")),n(te=>te.map(ie=>ie.id===t.id?H:ie)),a.success("Task updated.",1500)}else{const H=await A.post("/tasks",{title:m,description:I,status:W,tags:G,priority:U,assignee:$,recurring:N,dueDate:E});s.close(),typeof window<"u"&&window.dispatchEvent(new MouseEvent("mousedown")),n(te=>[H,...te]),a.success("Task created.",1500)}await o()}catch(H){a.error(`Save failed: ${H.message}`)}};s.open({title:t?"Edit task":"New task",width:560,children:e.jsxs("div",{className:"task-form",children:[e.jsx("label",{className:"field-label",htmlFor:"task-title",children:"Title *"}),e.jsx("input",{ref:m=>{p=m},id:"task-title",className:"input",type:"text",maxLength:200,placeholder:"What needs to be done?",defaultValue:(t==null?void 0:t.title)||"",autoFocus:!0}),e.jsx("label",{className:"field-label",htmlFor:"task-desc",children:"Description (markdown)"}),e.jsx("textarea",{ref:m=>{u=m},id:"task-desc",className:"textarea",rows:3,placeholder:"Markdown supported…",defaultValue:(t==null?void 0:t.description)||""}),e.jsxs("div",{className:"task-form-row",children:[e.jsxs("div",{className:"task-form-field",children:[e.jsx("label",{className:"field-label",htmlFor:"task-status",children:"Status"}),e.jsx("select",{ref:m=>{c=m},id:"task-status",className:"select",defaultValue:(t==null?void 0:t.status)||i,children:ss.map(m=>e.jsx("option",{value:m.id,children:m.label},m.id))})]}),e.jsxs("div",{className:"task-form-field",children:[e.jsx("label",{className:"field-label",children:"Priority"}),e.jsx("div",{className:"radio-row",ref:m=>{h=m},children:qs.map(m=>e.jsxs("label",{className:"radio-label",children:[e.jsx("input",{type:"radio",name:"task-priority",value:m,defaultChecked:((t==null?void 0:t.priority)||"normal")===m}),e.jsx("span",{className:"capitalize",children:m})]},m))})]})]}),e.jsxs("div",{className:"task-form-row",children:[e.jsxs("div",{className:"task-form-field",children:[e.jsx("label",{className:"field-label",htmlFor:"task-assignee",children:"Assignee"}),e.jsx("input",{ref:m=>{x=m},id:"task-assignee",className:"input",type:"text",placeholder:"odin, thor, me, …",list:"task-assignee-suggestions",defaultValue:(t==null?void 0:t.assignee)||""}),e.jsx("datalist",{id:"task-assignee-suggestions",children:l.map(m=>e.jsxs("option",{value:m.name,children:["@",m.name]},m.name))})]}),e.jsxs("div",{className:"task-form-field",children:[e.jsx("label",{className:"field-label",htmlFor:"task-due",children:"Due date"}),e.jsx("input",{ref:m=>{S=m},id:"task-due",className:"input",type:"date",defaultValue:((v=t==null?void 0:t.dueDate)==null?void 0:v.slice(0,10))||""})]})]}),e.jsx("label",{className:"field-label",htmlFor:"task-tags",children:"Tags"}),e.jsx("input",{ref:m=>{g=m},id:"task-tags",className:"input",type:"text",placeholder:"comma-separated, e.g. bug, frontend",defaultValue:((t==null?void 0:t.tags)||[]).join(", ")}),e.jsxs("div",{className:"task-form-row",children:[e.jsxs("div",{className:"task-form-field",children:[e.jsx("label",{className:"field-label",htmlFor:"task-recur",children:"Recurring"}),e.jsxs("select",{ref:m=>{M=m},id:"task-recur",className:"select",defaultValue:((y=t==null?void 0:t.recurring)==null?void 0:y.freq)||"none",children:[e.jsx("option",{value:"none",children:"None"}),e.jsx("option",{value:"daily",children:"Daily"}),e.jsx("option",{value:"weekly",children:"Weekly"}),e.jsx("option",{value:"monthly",children:"Monthly"}),e.jsx("option",{value:"custom",children:"Custom (cron)"})]})]}),e.jsxs("div",{className:"task-form-field",children:[e.jsx("label",{className:"field-label",htmlFor:"task-cron",children:"Cron expression"}),e.jsx("input",{ref:m=>{k=m},id:"task-cron",className:"input",type:"text",placeholder:"0 9 * * *",defaultValue:((T=t==null?void 0:t.recurring)==null?void 0:T.cron)||""})]})]})]}),footer:e.jsxs("div",{className:"modal-footer-actions",children:[e.jsx(z,{variant:"ghost",onClick:()=>s.close(),children:"Cancel"}),e.jsx(z,{variant:"primary",onClick:b,children:t?"Save":"Create"})]})})}function Ti(s,a,t,i,n,d,o=[],l=0){let p=null,u=null,g=null;const h=async()=>{const b=((p==null?void 0:p.value)||"").trim();if(b)try{const v=await A.post(`/tasks/${encodeURIComponent(t.id)}/comments`,{text:b});i(y=>y.map(T=>T.id===t.id?v:T)),p&&(p.value=""),a.success("Comment added.",1200)}catch(v){a.error(`Comment failed: ${v.message}`)}},c=async()=>{try{const b=await A.post(`/tasks/${encodeURIComponent(t.id)}/timer/start`);i(v=>v.map(y=>y.id===t.id?b:y)),a.success("Timer started.",1200)}catch(b){a.error(`Start failed: ${b.message}`)}},x=async()=>{try{const b=await A.post(`/tasks/${encodeURIComponent(t.id)}/timer/stop`);i(v=>v.map(y=>y.id===t.id?b:y)),a.success("Timer stopped.",1200)}catch(b){a.error(`Stop failed: ${b.message}`)}},M=async()=>{const b=((u==null?void 0:u.value)||"").trim();if(!b)return;const v=[...t.dependencies||[],b];try{const y=await A.put(`/tasks/${encodeURIComponent(t.id)}`,{dependencies:v});i(T=>T.map(m=>m.id===t.id?y:m)),u&&(u.value=""),a.success("Dependency added.",1200)}catch(y){a.error(`Failed: ${y.message}`)}},k=async(b,v)=>{const y=(g==null?void 0:g.value)||"";if(!y){a.warning("Pick an agent first.");return}try{const T=await A.post(`/tasks/${encodeURIComponent(t.id)}/work`,{agent:y,status:b,complete:v});i(m=>m.map(I=>I.id===t.id?T:I)),a.success(`${b} by @${y}.`,1200)}catch(T){a.error(`Failed: ${T.message}`)}},S=t._timerStart?Math.floor((Date.now()-t._timerStart)/1e3)+(t.timeSpent||0):t.timeSpent||0;s.open({title:`Task — ${t.title}`,width:640,children:e.jsxs("div",{className:"task-detail",children:[e.jsxs("div",{className:"task-detail-meta",children:[e.jsxs("span",{children:[e.jsx("strong",{children:"Status:"})," ",t.status]}),e.jsxs("span",{children:[e.jsx("strong",{children:"Priority:"})," ",t.priority]}),t.assignee&&e.jsxs("span",{children:[e.jsx("strong",{children:"Assignee:"})," @",t.assignee]}),t.workedBy&&e.jsxs("span",{children:[e.jsx("strong",{children:"Working:"})," ",e.jsxs("span",{className:"is-working",style:{display:"inline-block",padding:"0 6px"},children:["@",t.workedBy]})]}),t.dueDate&&e.jsxs("span",{children:[e.jsx("strong",{children:"Due:"})," ",t.dueDate.slice(0,10)]}),e.jsxs("span",{children:[e.jsx("strong",{children:"Time:"})," ",Ps(S)]})]}),t.description&&e.jsxs(se,{children:[e.jsx(ne,{children:"Description"}),e.jsx("div",{className:"task-detail-desc",children:t.description})]}),e.jsxs(se,{children:[e.jsxs(ne,{children:[e.jsx(Fe,{size:14})," Mark as worked on by"]}),e.jsxs("div",{className:"task-detail-row",children:[e.jsxs("select",{ref:b=>{g=b},className:"select",defaultValue:t.workedBy||"",children:[e.jsx("option",{value:"",children:"(pick an agent)"}),o.map(b=>e.jsxs("option",{value:b.name,children:["@",b.name]},b.name))]}),e.jsxs(z,{variant:"primary",size:"sm",onClick:()=>k("doing",!1),children:[e.jsx(Rs,{size:12})," Start working"]}),e.jsxs(z,{variant:"success",size:"sm",onClick:()=>k("done",!0),children:[e.jsx(Pe,{size:12})," Complete"]}),e.jsxs(z,{variant:"ghost",size:"sm",onClick:()=>k("idle",!1),children:[e.jsx(Zs,{size:12})," Stop"]})]})]}),e.jsxs(se,{children:[e.jsxs(ne,{children:[e.jsx(Je,{size:14})," Time tracking"]}),e.jsxs("div",{className:"task-detail-row",children:[t._timerStart?e.jsxs(z,{variant:"secondary",size:"sm",onClick:x,className:"is-working",children:[e.jsx(Zs,{size:12})," Stop"]}):e.jsxs(z,{variant:"secondary",size:"sm",onClick:c,children:[e.jsx(Rs,{size:12})," Start"]}),e.jsxs("span",{className:Z("muted",t._timerStart?"is-working":null),children:[Ps(S),t._timerStart&&" (running)"]})]})]}),e.jsxs(se,{children:[e.jsxs(ne,{children:[e.jsx(Nt,{size:14})," Dependencies"]}),e.jsxs("div",{className:"task-detail-row",children:[e.jsx("input",{ref:b=>{u=b},className:"input",type:"text",placeholder:"task id (e.g. tsk_abc12345)"}),e.jsx(z,{variant:"secondary",size:"sm",onClick:M,children:"Add"})]}),e.jsxs("ul",{children:[(t.dependencies||[]).map(b=>e.jsx("li",{children:e.jsx("code",{children:b})},b)),(t.dependencies||[]).length===0&&e.jsx("li",{className:"muted",children:"No dependencies."})]})]}),t.recurring&&e.jsxs(se,{children:[e.jsxs(ne,{children:[e.jsx(yt,{size:14})," Recurring"]}),e.jsxs("div",{className:"muted",children:["Frequency: ",e.jsx("code",{children:t.recurring.freq||"custom"})," ",t.recurring.cron&&e.jsx("code",{children:t.recurring.cron})]}),t.recurring.lastGenerated&&e.jsxs("div",{className:"muted text-sm",children:["Last spawned: ",ye(t.recurring.lastGenerated)]})]}),e.jsxs(se,{children:[e.jsxs(ne,{children:[e.jsx(Xe,{size:14})," Comments"]}),e.jsx("textarea",{ref:b=>{p=b},className:"textarea",rows:3,placeholder:"Add a comment…"}),e.jsx(z,{variant:"primary",size:"sm",onClick:h,children:"Post"}),e.jsxs("ul",{className:"task-comments",children:[(t.comments||[]).map(b=>e.jsxs("li",{children:[e.jsx("div",{className:"muted tabular-nums",children:ye(b.createdAt)}),e.jsx("div",{children:b.text})]},b.id)),(t.comments||[]).length===0&&e.jsx("li",{className:"muted",children:"No comments."})]})]}),e.jsxs(se,{children:[e.jsxs(ne,{children:[e.jsx(ze,{size:14})," Activity"]}),e.jsxs("ul",{className:"task-activity",children:[(t.activity||[]).slice().reverse().slice(0,20).map(b=>e.jsxs("li",{children:[e.jsx("span",{className:"muted tabular-nums",children:ye(b.ts)})," ",e.jsx("span",{className:"tag",children:b.type}),b.data&&typeof b.data=="object"?e.jsxs("code",{className:"muted",children:[" ",JSON.stringify(b.data)]}):null]},b.id)),(t.activity||[]).length===0&&e.jsx("li",{className:"muted",children:"No activity yet."})]})]})]}),footer:e.jsxs("div",{className:"modal-footer-actions",children:[e.jsx(z,{variant:"ghost",onClick:()=>s.close(),children:"Close"}),e.jsxs(z,{variant:"primary",onClick:()=>{s.close(),Es(s,a,t,t.status,i,n,d,o)},children:[e.jsx(Me,{size:12})," Edit basics"]})]})})}function Ai(s,a,t,i,n){let d=null,o=null,l=null,p=null;const u=async h=>{h&&typeof h.preventDefault=="function"&&h.preventDefault(),h&&typeof h.stopPropagation=="function"&&h.stopPropagation();const c=(o==null?void 0:o.value)||"";let x=((d==null?void 0:d.value)||"").trim();if(!x&&c.trim()&&(x=na(c),d&&(d.value=x)),!x){a.warning("Add a description so Odin knows what to do.");return}const M=(l==null?void 0:l.value)||"normal",k=((p==null?void 0:p.value)||"").split(",").map(S=>S.trim()).filter(Boolean);try{const S=await A.post("/tasks/submit",{title:x,description:c,priority:M,tags:k}),b=(S.subtasks||[]).length;a.success(b>1?`Odin split it into ${b} subtasks.`:"Task submitted to Odin."),s.close(),typeof window<"u"&&window.dispatchEvent(new MouseEvent("mousedown")),t&&t(v=>[S.main,...S.subtasks||[],...v]),i&&await i(),n&&await n()}catch(S){a.error(`Submit failed: ${S.message}`)}},g=h=>{h.key==="Enter"&&!h.shiftKey&&(h.preventDefault(),u(h))};s.open({title:"Submit Task to Odin",width:560,children:e.jsxs("div",{className:"submit-task-form",children:[e.jsxs("label",{htmlFor:"submit-task-title",children:["Title ",e.jsx("span",{className:"field-hint",children:"(optional — auto-generated from description)"}),e.jsx("input",{id:"submit-task-title",ref:h=>{d=h},className:"input",type:"text",placeholder:"Leave blank to derive from description",autoFocus:!0,onKeyDown:g}),e.jsx("span",{className:"field-hint",children:"Odin will analyze this and split it into subtasks assigned to the best agent."})]}),e.jsxs("label",{htmlFor:"submit-task-desc",children:["Description",e.jsxs("span",{style:{display:"flex",gap:6,alignItems:"flex-start"},children:[e.jsx("textarea",{id:"submit-task-desc",ref:h=>{o=h},className:"textarea",rows:5,placeholder:"Provide more detail (markdown ok)…",style:{flex:1}}),e.jsx("button",{type:"button",className:"btn btn-ghost btn-icon",style:{marginTop:0,flexShrink:0},title:"Enhance prompt with AI",onClick:async()=>{var c;if(!((c=o==null?void 0:o.value)!=null&&c.trim()))return;const h=await aa(o.value);h!==o.value&&(o.value=h)},children:e.jsx(Me,{size:14})})]})]}),e.jsxs("div",{className:"task-form-row",children:[e.jsxs("label",{htmlFor:"submit-task-priority",className:"task-form-field",children:["Priority",e.jsx("select",{id:"submit-task-priority",ref:h=>{l=h},className:"select",defaultValue:"normal",children:qs.map(h=>e.jsx("option",{value:h,children:h},h))})]}),e.jsxs("label",{htmlFor:"submit-task-tags",className:"task-form-field",style:{flex:2},children:["Tags ",e.jsx("span",{className:"field-hint",children:"(comma-separated)"}),e.jsx("input",{id:"submit-task-tags",ref:h=>{p=h},className:"input",type:"text",placeholder:"backend, auth"})]})]})]}),footer:e.jsxs("div",{className:"modal-footer-actions",children:[e.jsx(z,{variant:"ghost",onClick:()=>s.close(),children:"Cancel"}),e.jsxs(z,{variant:"primary",type:"button",onClick:h=>u(h),children:[e.jsx(Qe,{size:14})," Submit to Odin"]})]})})}const rt={"1m":60*1e3,"5m":5*60*1e3,"30m":30*60*1e3,"1h":60*60*1e3},we=56,Ie=32,Ke=22,Mi=4,$i=.9,zs={working:"var(--success)",running:"var(--success)",doing:"var(--info)",queued:"var(--info)",done:"var(--success)",success:"var(--success)",blocked:"var(--warning)",error:"var(--error)",failed:"var(--error)",stuck:"var(--warning)",killed:"var(--error)",idle:"var(--text-dim)",pending:"var(--info)",timed_out:"var(--warning)"};function Ts(s){return s&&zs[s]||zs.idle}function hs(s,a=24){return s?s.length<=a?s:s.slice(0,a-1)+"…":""}function vs(s){if(s==null)return 0;if(typeof s=="number")return s;const a=new Date(s).getTime();return Number.isNaN(a)?0:a}function As(s){const a=s._timerStart;return typeof a=="number"&&a>0?a:vs(s.createdAt)||Date.now()}function Ri(s,a){return(s.status==="done"||s.status==="archived"||s.status==="failed"||s.status==="killed")&&(vs(s.completedAt)||vs(s.updatedAt))||a}function Ii(s){return typeof s.startedAt=="number"&&s.startedAt>0?s.startedAt:Date.now()}function Di(s,a){return(s.status==="done"||s.status==="success"||s.status==="killed"||s.status==="failed"||s.status==="error"||s.status==="timed_out")&&(s.completedAt||s.lastEventAt)||a}function Li(s){return s<=6e4?1e4:s<=3e5?3e4:s<=18e5?3e5:6e5}function Pi(s,a){const t=new Date(s);return a<=3e5?t.toLocaleTimeString("en-GB",{hour12:!1}):t.toLocaleTimeString("en-GB",{hour12:!1,hour:"2-digit",minute:"2-digit"})}function Ei({snapshot:s,refreshSnapshot:a}){const t=he(),i=r.useRef(null),[n,d]=r.useState("live"),[o,l]=r.useState("5m"),[p,u]=r.useState(()=>typeof window>"u"?!0:window.innerWidth>900),[g,h]=r.useState([]),[c,x]=r.useState([]),[M,k]=r.useState(!0),[S,b]=r.useState(0),[v,y]=r.useState(Date.now()),[T,m]=r.useState(()=>Date.now()-rt["5m"]*.1),[I,U]=r.useState({width:800,height:400}),[R,G]=r.useState(null),[W,$]=r.useState(""),[q,X]=r.useState([]),[N,E]=r.useState(""),[D,H]=r.useState("normal"),[te,ie]=r.useState(""),[ue,B]=r.useState(""),[Q,O]=r.useState(!1),[j,C]=r.useState(!1),[L,F]=r.useState([]),J=ke(),V=s.agents||[],f=s.tasks||[],_=rt[o],ee=T,P=T+_,le=r.useCallback(async()=>{try{const[w,K]=await Promise.all([A.get("/background").catch(()=>({instances:[]})),A.get("/activity?limit=200").catch(()=>({events:[]}))]);h(w.instances||[]),x(K.events||[])}catch(w){console.warn("activity reload failed:",w)}finally{k(!1)}},[]);r.useEffect(()=>{le();const w=setInterval(le,3e3);return()=>clearInterval(w)},[le]),r.useEffect(()=>{b(w=>w+1)},[f.length,V.length]),r.useEffect(()=>{if(n==="pause")return;y(Date.now());const w=setInterval(()=>y(Date.now()),1e3);return()=>clearInterval(w)},[n,S]),r.useEffect(()=>{if(n==="pause")return;(v-T)/_>$i&&m(v-_*.1)},[v,T,_,n]),r.useEffect(()=>{m(Date.now()-_*.1)},[o]),r.useEffect(()=>{n==="live"&&m(Date.now()-_*.1)},[n]),r.useLayoutEffect(()=>{const w=i.current;if(!w)return;const K=new ResizeObserver(me=>{for(const pe of me){const{width:oe,height:xe}=pe.contentRect;U({width:Math.max(200,Math.floor(oe)),height:Math.max(120,Math.floor(xe))})}});return K.observe(w),()=>K.disconnect()},[]);const ae=r.useMemo(()=>{const w=[];let K=0;for(const oe of g){const xe=Ii(oe),Ce=Di(oe,v);Ce<ee||xe>P||w.push({kind:"bg",id:`bg:${oe.instanceId}`,index:K++,label:`BG ${hs(oe.promptPreview,20)||oe.instanceId.slice(0,10)}`,sub:oe.status||"pending",start:xe,end:Ce,data:oe})}const me=[...f].sort((oe,xe)=>As(oe)-As(xe)),pe=[];for(const oe of me){const xe=As(oe),Ce=Ri(oe,v);if(Ce<ee||xe>P)continue;let Ve=-1;for(let He=0;He<pe.length;He++)if(pe[He]<=xe){pe[He]=Ce,Ve=He;break}Ve===-1&&(pe.push(Ce),Ve=pe.length-1),w.push({kind:"task",id:`task:${oe.id}`,index:K+Ve,label:hs(oe.title,32),sub:oe.status,start:xe,end:Ce,data:oe})}return w},[g,f,v,ee,P]),fe=r.useMemo(()=>{const w=new Map;for(const K of ae)w.set(K.id,K);return w},[ae]),ce=r.useCallback(w=>_<=0?0:(w-ee)/_*I.width,[ee,_,I.width]),cs=r.useMemo(()=>{const w=Li(_),K=[],me=Math.floor(ee/w)*w;for(let pe=me;pe<=P+w;pe+=w){if(pe<ee-w)continue;if(pe>P)break;const oe=ce(pe);oe<-40||oe>I.width+40||K.push({t:pe,x:oe,label:Pi(pe,_)})}return K},[ee,P,_,I.width,ce]),Et=r.useMemo(()=>{const w=[];for(const K of ae){if(K.kind==="events")continue;const me=Math.max(K.start,ee),pe=Math.min(K.end,P);if(pe<ee||me>P)continue;const oe=ce(me),xe=ce(pe),Ce=Math.max(Mi,xe-oe),Ve=Ie+Ke+K.index*we+8,He=we-16;let Te="doing";if(K.kind==="bg"){const ve=K.data.status||"pending";ve==="done"||ve==="success"?Te="done":ve==="failed"||ve==="killed"||ve==="error"?Te="failed":ve==="queued"||ve==="pending"?Te="queued":ve==="blocked"||ve==="stuck"?Te="blocked":Te="doing"}else{const ve=K.data.status;ve==="done"||ve==="archived"?Te="done":ve==="failed"||ve==="killed"?Te="failed":ve==="queued"?Te="queued":ve==="blocked"?Te="blocked":Te="doing"}const qt=(R==null?void 0:R.id)===K.id;w.push({id:K.id,laneIndex:K.index,x:oe,y:Ve,w:Ce,h:He,label:K.label,statusClass:Te,selected:qt,data:K.data,kind:K.kind,start:K.start,end:K.end})}return w},[ae,ce,R,ee,P]),Ot=r.useMemo(()=>{const w=[];for(const K of c){const me=vs(K.ts);if(me<ee-5e3||me>P+5e3)continue;const pe=ce(me);let oe=Ie+12;if(K.taskId){const xe=fe.get(`task:${K.taskId}`);xe&&(oe=Ie+Ke+xe.index*we+we/2)}else if(K.nodeId){const xe=String(K.nodeId),Ce=fe.get(xe.startsWith("task:")||xe.startsWith("bg:")?xe:`task:${xe}`);Ce&&(oe=Ie+Ke+Ce.index*we+we/2)}w.push({id:`${K.ts}-${K.kind}-${K.author??""}-${K.taskId??""}`,x:pe,y:oe,kind:K.kind||"event",ts:me,text:String(K.text||K.kind||""),author:K.author})}return w},[c,ee,P,ce,fe]),Bt=r.useMemo(()=>ae.map(w=>({id:w.id,y:Ie+Ke+w.index*we,h:we})),[ae]),os=r.useMemo(()=>{const w=ce(v);return Math.max(0,Math.min(I.width,w))},[ce,v,I.width]),Ft=r.useCallback(w=>{const me={id:w.id,kind:w.kind,label:w.label,status:w.statusClass,data:w.data};G(me)},[]);r.useEffect(()=>{if(!R){X([]),B(""),F([]);return}$(""),E(""),ie(""),F([]),(async()=>{try{const w=await A.get(`/activity?nodeId=${encodeURIComponent(R.id)}&limit=50`);X(w.events||[])}catch{X([])}if(R.kind==="bg"){const w=R.data;try{const K=await A.get(`/background/${encodeURIComponent(w.instanceId)}/output?lines=80`);B(K.output||"")}catch{B("")}if(w.taskId)try{const K=await A.get(`/tasks/${encodeURIComponent(w.taskId)}/artifacts`);F((K.artifacts||[]).map(me=>me.id))}catch{F([])}}})()},[R]);const Gs=async()=>{if(!(!R||!W.trim())){C(!0);try{await A.post("/comments",{nodeId:R.id,text:W,author:"user"}),$("");const w=await A.get(`/activity?nodeId=${encodeURIComponent(R.id)}&limit=50`);X(w.events||[]),t.success("Comment added.")}catch(w){t.error(`Comment failed: ${w.message}`)}finally{C(!1)}}},Ut=async()=>{if(!(!R||!N.trim())){O(!0);try{await A.post(`/nodes/${encodeURIComponent(R.id)}/tasks`,{title:N,description:`Created from timeline selection ${R.id}.`,priority:D}),E(""),t.success("Task created."),await a()}catch(w){t.error(`Task create failed: ${w.message}`)}finally{O(!1)}}},Ys=async()=>{if(!R||R.kind!=="bg"||!te.trim())return;const w=R.data;try{const K=await A.post(`/background/${encodeURIComponent(w.instanceId)}/message`,{message:te});K.ok?(t.success("Message sent."),ie("")):t.warning(K.error||"Send failed")}catch(K){t.error(`Send failed: ${K.message}`)}},Ht=async()=>{if(!R||R.kind!=="bg"||!confirm("Kill this bg instance session?"))return;const w=R.data;try{const K=await A.del(`/background/${encodeURIComponent(w.instanceId)}`);K.ok?t.success("Session killed."):t.warning(K.error||"Kill failed"),await le()}catch(K){t.error(`Kill failed: ${K.message}`)}},_t=async()=>{if(!R||R.kind!=="bg")return;const w=R.data;try{const K=await A.get(`/background/${encodeURIComponent(w.instanceId)}/output?lines=80`);B(K.output||"")}catch{}};r.useEffect(()=>{const w=K=>{K.key==="Escape"&&G(null)};return window.addEventListener("keydown",w),()=>window.removeEventListener("keydown",w)},[]);const Vt=()=>{b(w=>w+1),le()},Ns=Ie+Ke+ae.length*we;return e.jsxs("div",{className:"view view-activity",children:[e.jsxs("header",{className:"view-header",children:[e.jsxs("div",{className:"view-header-text",children:[e.jsxs("h2",{className:"view-title",children:[e.jsx(ze,{size:18})," Activity"]}),e.jsx("p",{className:"view-subtitle",children:"Live timeline of agents, tasks, and background sessions. Active tasks pulse; the red line marks “now”."})]}),e.jsx("div",{className:"view-actions",children:e.jsxs("div",{className:"tl-mode-toggle",children:[e.jsxs(z,{variant:n==="live"?"primary":"secondary",size:"sm",onClick:()=>d(n==="live"?"pause":"live"),title:n==="live"?"Pause timeline":"Resume timeline",children:[n==="live"?e.jsx(ra,{size:14}):e.jsx(Us,{size:14}),n==="live"?"Live":"Paused"]}),e.jsx("div",{className:"tl-zoom-group",children:["1m","5m","30m","1h"].map(w=>e.jsx("button",{type:"button",className:Z("tl-zoom-btn",o===w&&"tl-zoom-btn-active"),onClick:()=>l(w),title:`Zoom to ${w}`,children:w},w))}),e.jsxs(z,{variant:"secondary",size:"sm",onClick:Vt,title:"Refresh",children:[e.jsx(de,{size:14})," Refresh"]})]})})]}),M&&e.jsx("div",{className:"view-loading",children:e.jsx(ge,{size:"lg"})}),!M&&V.length===0&&f.length===0&&g.length===0&&c.length===0?e.jsx(Re,{icon:e.jsx(ze,{size:32}),title:"No activity yet",message:"Once agents, tasks, or background instances exist, they'll show up here on the timeline."}):e.jsx("div",{className:Z("tl-view",R&&"tl-view-detail-open"),children:e.jsxs("div",{className:Z("tl-body",!p&&"tl-body-stream-collapsed"),children:[e.jsxs("aside",{className:Z("tl-stream",!p&&"tl-stream-collapsed"),children:[e.jsxs("div",{className:"tl-stream-head",children:[e.jsxs("h3",{children:[e.jsx(ts,{size:13})," Live events"]}),e.jsx("button",{type:"button",className:"icon-btn",onClick:()=>u(!1),title:"Hide event stream","aria-label":"Hide event stream",children:e.jsx(Wa,{size:14})})]}),e.jsx("div",{className:"tl-stream-list",children:c.length===0?e.jsx("div",{className:"tl-stream-empty",children:e.jsx("p",{children:"No events yet."})}):[...c].reverse().map((w,K)=>{const me=w.author?Fe:w.kind==="task"?Pe:w.kind==="bg"?ws:ze;return e.jsxs("div",{className:"tl-stream-event",children:[e.jsx("span",{className:"tl-stream-event-time",children:new Date(w.ts).toLocaleTimeString("en-GB",{hour12:!1})}),e.jsx("span",{className:"tl-stream-event-icon",style:{color:Ts(w.kind)},children:e.jsx(me,{size:12})}),e.jsx("span",{className:"tl-stream-event-text",children:w.author||w.text||w.kind})]},`${w.ts}-${K}`)})})]}),e.jsxs("div",{className:"tl-canvas-wrap",ref:i,children:[e.jsxs("div",{className:"tl-canvas-toolbar",children:[e.jsxs("div",{className:"tl-canvas-toolbar-left",children:[!p&&e.jsxs(z,{variant:"ghost",size:"sm",onClick:()=>u(!0),title:"Show event stream",children:[e.jsx(Ka,{size:14})," Events"]}),e.jsx("span",{className:"tl-canvas-mode",children:n==="live"?"● Live":"⏸ Paused"}),e.jsxs("span",{className:"tl-canvas-range",children:[new Date(ee).toLocaleTimeString("en-GB",{hour12:!1})," →"," ",new Date(P).toLocaleTimeString("en-GB",{hour12:!1})]})]}),e.jsxs("div",{className:"tl-canvas-legend",children:[e.jsxs("span",{className:"tl-legend-item",children:[e.jsx("span",{className:"tl-legend-dot",style:{background:"var(--success)"}})," active"]}),e.jsxs("span",{className:"tl-legend-item",children:[e.jsx("span",{className:"tl-legend-dot tl-legend-dot-dashed",style:{borderColor:"var(--info)"}})," queued"]}),e.jsxs("span",{className:"tl-legend-item",children:[e.jsx("span",{className:"tl-legend-dot",style:{background:"var(--warning)"}})," blocked"]}),e.jsxs("span",{className:"tl-legend-item",children:[e.jsx("span",{className:"tl-legend-dot",style:{background:"var(--error)"}})," error"]}),e.jsx("span",{className:"tl-legend-sep"}),e.jsxs("span",{className:"tl-legend-item",children:[e.jsx(kt,{size:11})," agent"]}),e.jsxs("span",{className:"tl-legend-item",children:[e.jsx(en,{size:11})," task"]}),e.jsxs("span",{className:"tl-legend-item",children:[e.jsx(ws,{size:11})," bg"]})]})]}),e.jsx("div",{className:"tl-canvas-scroll",children:e.jsxs("svg",{className:"tl-canvas",width:I.width,height:Math.max(I.height,Ns),role:"application","aria-label":"Activity timeline",children:[e.jsx("defs",{children:e.jsx("pattern",{id:"tl-canvas-grid",width:I.width,height:we,patternUnits:"userSpaceOnUse",children:e.jsx("path",{d:`M 0 0 L 0 ${we}`,fill:"none",stroke:"var(--border)",strokeWidth:.5,opacity:.35})})}),e.jsx("rect",{width:"100%",height:"100%",fill:"url(#tl-canvas-grid)"}),Bt.map(w=>e.jsx("rect",{className:"tl-lane-bg",x:0,y:w.y,width:I.width,height:w.h,fill:w.id.charCodeAt(w.id.length-1)%2===0?"var(--bg-elev-2)":"var(--bg-elev)",opacity:.4},`bg-${w.id}`)),e.jsx("g",{className:"tl-time-axis",children:cs.map(w=>e.jsxs("g",{children:[e.jsx("line",{x1:w.x,y1:0,x2:w.x,y2:Ns,stroke:"var(--border)",strokeWidth:.5,strokeDasharray:"2,4",opacity:.5}),e.jsx("text",{x:w.x+4,y:Ie-8,fontSize:10,fontFamily:"var(--font-mono)",fill:"var(--text-dim)",children:w.label})]},`tick-${w.t}`))}),ae.map(w=>{const K=Ie+Ke+w.index*we+we/2;return e.jsxs("g",{className:"tl-lane-label-group",children:[e.jsx("text",{x:6,y:K-2,className:"tl-lane-label",textAnchor:"start",children:hs(w.label,28)}),e.jsx("text",{x:6,y:K+10,className:"tl-lane-label-sub",textAnchor:"start",children:w.sub})]},`label-${w.id}`)}),Et.map(w=>{const K=Ts(w.statusClass),me=w.id===(R==null?void 0:R.id);return e.jsxs("g",{className:Z("tl-task-bar",`tl-task-bar-${w.statusClass}`,me&&"tl-task-bar-selected"),onClick:()=>Ft(w),children:[e.jsx("rect",{x:w.x,y:w.y,width:w.w,height:w.h,rx:6,fill:K,fillOpacity:w.statusClass==="done"?.35:w.statusClass==="queued"?.18:.85,stroke:K,strokeWidth:me?2.5:1.5,strokeOpacity:w.statusClass==="done"?.5:1,strokeDasharray:w.statusClass==="queued"?"4 4":void 0,style:{cursor:"pointer"}}),w.w>36&&e.jsx("text",{x:w.x+8,y:w.y+w.h/2+4,fontSize:11,fontFamily:"var(--font-sans)",fontWeight:500,fill:"var(--text-strong)",style:{pointerEvents:"none"},opacity:w.statusClass==="done"?.7:1,children:hs(w.label,Math.max(4,Math.floor(w.w/7)))})]},`bar-${w.id}`)}),Ot.map(w=>{const K=Ts(w.kind);return e.jsxs("g",{className:"tl-event-marker-group",children:[e.jsx("line",{x1:w.x,y1:w.y-6,x2:w.x,y2:w.y+6,stroke:K,strokeWidth:1.2,opacity:.7}),e.jsx("circle",{cx:w.x,cy:w.y,r:4,fill:K,opacity:.9,children:e.jsx("title",{children:`${w.kind}${w.author?` · ${w.author}`:""} · ${new Date(w.ts).toLocaleTimeString("en-GB",{hour12:!1})}`})})]},`ev-${w.id}`)}),e.jsx("line",{className:"tl-now-line",x1:os,y1:0,x2:os,y2:Ns,stroke:"var(--error)",strokeWidth:1.5,opacity:.9}),e.jsxs("g",{className:"tl-now-marker",children:[e.jsx("circle",{cx:os,cy:Ie-4,r:4,fill:"var(--error)"}),e.jsx("text",{x:os+6,y:Ie-4,fontSize:10,fontWeight:700,fill:"var(--error)",fontFamily:"var(--font-mono)",children:"now"})]})]})})]}),R&&e.jsx("aside",{className:"tl-detail tl-detail-enter",children:e.jsxs(se,{children:[e.jsxs(ne,{children:[R.kind==="agent"&&e.jsx(Fe,{size:14}),R.kind==="task"&&e.jsx(Pe,{size:14}),R.kind==="bg"&&e.jsx(ws,{size:14}),R.label,e.jsx("button",{type:"button",className:"icon-btn",onClick:()=>G(null),title:"Close","aria-label":"Close activity detail",style:{marginLeft:"auto"},children:e.jsx($e,{size:14})})]}),e.jsxs("div",{className:"tl-detail-meta",children:[e.jsxs("div",{children:[e.jsx("span",{className:"muted",children:"type"})," ",R.kind]}),e.jsxs("div",{children:[e.jsx("span",{className:"muted",children:"status"})," ",e.jsx("code",{children:R.status})]}),R.kind==="agent"&&(()=>{const w=R.data;return e.jsxs(e.Fragment,{children:[w.role&&e.jsxs("div",{children:[e.jsx("span",{className:"muted",children:"role"})," ",w.role]}),w.model&&e.jsxs("div",{children:[e.jsx("span",{className:"muted",children:"model"})," ",w.model]})]})})(),R.kind==="task"&&(()=>{const w=R.data;return e.jsxs(e.Fragment,{children:[w.assignee&&e.jsxs("div",{children:[e.jsx("span",{className:"muted",children:"assignee"})," @",w.assignee]}),w.priority&&e.jsxs("div",{children:[e.jsx("span",{className:"muted",children:"priority"})," ",w.priority]}),w.createdAt&&e.jsxs("div",{children:[e.jsx("span",{className:"muted",children:"created"})," ",new Date(w.createdAt).toLocaleString()]})]})})(),R.kind==="bg"&&(()=>{const w=R.data;return e.jsxs(e.Fragment,{children:[w.startedAt&&e.jsxs("div",{children:[e.jsx("span",{className:"muted",children:"started"})," ",new Date(w.startedAt).toLocaleString()]}),w.tmuxSession&&e.jsxs("div",{children:[e.jsx("span",{className:"muted",children:"tmux"})," ",e.jsx("code",{children:w.tmuxSession})," ",w.tmuxActive?e.jsx("span",{className:"tag tag-success",children:"active"}):e.jsx("span",{className:"tag",children:"inactive"})]})]})})()]}),R.kind==="task"&&R.data.description&&e.jsx("div",{className:"tl-detail-desc",children:R.data.description}),R.kind==="bg"&&R.data.promptPreview&&e.jsx("div",{className:"tl-detail-desc",children:R.data.promptPreview}),R.kind==="bg"&&e.jsxs("div",{className:"tl-detail-bg",children:[e.jsx("pre",{className:"tl-bg-output",children:ue||"(no output — start the session via tmux attach)"}),e.jsxs("div",{className:"tl-bg-output-actions",children:[e.jsxs(z,{variant:"ghost",size:"sm",onClick:_t,children:[e.jsx(de,{size:12})," Refresh output"]}),L.length>0&&e.jsxs(z,{variant:"secondary",size:"sm",onClick:()=>It(J,L[0]),children:[e.jsx(ks,{size:12})," Open artifact"]}),e.jsxs(z,{variant:"danger",size:"sm",onClick:Ht,children:[e.jsx(be,{size:12})," Kill session"]})]}),e.jsxs("div",{className:"tl-form-row",children:[e.jsx("input",{className:"input",placeholder:"Send a message to this bg session…",value:te,onChange:w=>ie(w.target.value),onKeyDown:w=>{w.key==="Enter"&&Ys()}}),e.jsxs(z,{variant:"primary",size:"sm",disabled:!te.trim(),onClick:Ys,children:[e.jsx(Qe,{size:12})," Send"]})]})]}),R.kind!=="bg"&&e.jsxs("div",{className:"tl-detail-create",children:[e.jsx("div",{className:"field-label",children:"Create follow-up task"}),e.jsx("input",{className:"input",placeholder:"Task title",value:N,onChange:w=>E(w.target.value)}),e.jsxs("div",{className:"tl-form-row",children:[e.jsxs("select",{className:"select",value:D,onChange:w=>H(w.target.value),children:[e.jsx("option",{value:"low",children:"Low"}),e.jsx("option",{value:"normal",children:"Normal"}),e.jsx("option",{value:"high",children:"High"})]}),e.jsxs(z,{variant:"primary",size:"sm",disabled:!N.trim()||Q,onClick:Ut,children:[e.jsx(je,{size:12})," Add task"]})]})]}),e.jsxs("div",{className:"tl-detail-comments",children:[e.jsxs("div",{className:"field-label",children:[e.jsx(Xe,{size:12})," Comments & activity"]}),e.jsxs("ul",{className:"comment-list",children:[q.length===0&&e.jsx("li",{className:"muted",children:"No comments yet."}),q.map((w,K)=>e.jsxs("li",{className:"comment-item",children:[e.jsxs("div",{className:"comment-head",children:[e.jsx("strong",{children:w.author||"system"}),e.jsxs("span",{className:"muted",children:[w.kind," · ",new Date(w.ts).toLocaleString()]})]}),w.text&&e.jsx("div",{className:"comment-text",children:w.text}),w.taskId&&e.jsxs("div",{className:"muted",children:["→ task ",e.jsx("code",{children:String(w.taskId)})]})]},`c-${K}`))]}),e.jsxs("div",{className:"comment-input-row",children:[e.jsx("input",{className:"input",placeholder:"Add a comment…",value:W,onChange:w=>$(w.target.value),onKeyDown:w=>{w.key==="Enter"&&!w.shiftKey&&Gs()}}),e.jsxs(z,{variant:"secondary",size:"sm",disabled:!W.trim()||j,onClick:Gs,children:[e.jsx(Qe,{size:12})," Post"]})]})]})]})},R.id)]})})]})}const Oi=[{id:"opencode",label:"OpenCode config",icon:Vs,desc:"Edit opencode.json directly"},{id:"providers",label:"Providers",icon:Ye,desc:"AI providers + API keys"},{id:"mcps",label:"MCPs",icon:js,desc:"Model Context Protocol servers"},{id:"diagnostics",label:"Diagnostics",icon:zt,desc:"Service health + counts"},{id:"export",label:"Export / Import",icon:De,desc:"Download diagnostics bundle"}];function Bi({snapshot:s,refreshSnapshot:a}){const t=he();ke();const i=s.config,[n,d]=r.useState("opencode"),[o,l]=r.useState((i==null?void 0:i.raw)||(i!=null&&i.data?JSON.stringify(i.data,null,2):"")),[p,u]=r.useState({raw:(i==null?void 0:i.raw)||"",data:(i==null?void 0:i.data)??null,error:null}),[g,h]=r.useState(!1),[c,x]=r.useState(!1),[M,k]=r.useState((i==null?void 0:i.path)||""),S=r.useRef(null),[b,v]=r.useState(null),[y,T]=r.useState(s.providers||[]),[m,I]=r.useState(s.mcps||[]),U=r.useMemo(()=>Js(o),[o]);r.useEffect(()=>{s.providers&&T(s.providers),s.mcps&&I(s.mcps)},[s.providers,s.mcps]);const R=async()=>{try{const D=await A.post("/config/reload"),H=D.raw||(D.data?JSON.stringify(D.data,null,2):"");l(H),u({raw:H,data:D.data??null,error:null}),h(!1),k(D.path||""),t.info("Config reloaded.",1500)}catch(D){t.error(`Reload failed: ${D.message}`)}},G=async()=>{try{const D=await A.get("/config/providers");T(D.providers||[])}catch(D){t.error(`Providers load failed: ${D.message}`)}},W=async()=>{try{const D=await A.get("/config/mcps");I(D.mcps||[])}catch(D){t.error(`MCPs load failed: ${D.message}`)}};r.useEffect(()=>{n==="providers"&&y.length===0&&G(),n==="mcps"&&m.length===0&&W(),n==="diagnostics"&&!b&&N()},[n]);const $=D=>{u(H=>{const te={raw:D,data:H.data,error:null};try{te.data=JSON.parse(D),te.error=null}catch(ie){te.data=null,te.error=ie.message}return te}),q(D)},q=r.useMemo(()=>ca(D=>{h(Js(D)!==U)},100),[U]),X=async()=>{if(!(!p.data||p.error||c)){x(!0);try{const D=await A.put("/config",p.data),H=D.raw||JSON.stringify(D.data,null,2);l(H),u({raw:H,data:D.data??null,error:null}),h(!1),t.success("Config saved."),await a(),await G(),await W()}catch(D){t.error(`Save failed: ${D.message}`)}finally{x(!1)}}},N=async()=>{try{const D=await A.get("/diagnostics");v(D)}catch(D){t.error(`Diagnostics load failed: ${D.message}`)}},E=()=>{const D={generatedAt:new Date().toISOString(),diagnostics:b,config:p.data,opencodeJsonPath:M,providers:y,mcps:m},H=new Blob([JSON.stringify(D,null,2)],{type:"application/json"}),te=URL.createObjectURL(H),ie=document.createElement("a");ie.href=te,ie.download=`bizar-diagnostics-${new Date().toISOString().replace(/[:.]/g,"-")}.json`,ie.click(),URL.revokeObjectURL(te),t.success("Bundle downloaded.")};return e.jsxs("div",{className:"view view-config",children:[e.jsx("header",{className:"view-header",children:e.jsxs("div",{className:"view-header-text",children:[e.jsxs("h2",{className:"view-title",children:[e.jsx(Ct,{size:18})," Config"]}),e.jsx("p",{className:"view-subtitle",children:"Manage OpenCode config, providers, MCPs, and diagnostics."})]})}),e.jsxs("div",{className:"config-layout",children:[e.jsx("nav",{className:"config-nav",role:"navigation","aria-label":"Config sections",children:Oi.map(D=>{const H=D.icon;return e.jsxs("button",{type:"button",className:Z("config-nav-item",n===D.id&&"config-nav-item-active"),onClick:()=>d(D.id),"aria-current":n===D.id?"page":void 0,children:[e.jsx(H,{size:14}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",minWidth:0,flex:1},children:[e.jsx("span",{children:D.label}),e.jsx("span",{style:{fontSize:10,color:"var(--text-dim)",fontWeight:400},children:D.desc})]})]},D.id)})}),e.jsxs("div",{className:"config-content",children:[n==="opencode"&&e.jsx(Ui,{parsed:p,dirty:g,saving:c,path:M,onReload:R,onSave:X,onChange:$,textareaRef:S}),n==="providers"&&e.jsx(Gi,{providers:y,onChange:T,onReload:G}),n==="mcps"&&e.jsx(Qi,{mcps:m,onChange:I,onReload:W}),n==="diagnostics"&&e.jsx(Ki,{diagnostics:b,loading:!b,onReload:N}),n==="export"&&e.jsx(Zi,{onDownload:E})]})]})]})}const Fi=[{id:"model",label:"Model"},{id:"plugins",label:"Plugins"},{id:"tools",label:"Tools"},{id:"permissions",label:"Permissions"},{id:"hooks",label:"Hooks"},{id:"advanced",label:"Advanced"}];function Ui({parsed:s,dirty:a,saving:t,path:i,onReload:n,onSave:d,onChange:o,textareaRef:l}){const[p,u]=r.useState("model"),g=s.data,h=c=>{if(!g)return;const x={...g,...c};o(JSON.stringify(x,null,2))};return e.jsxs(se,{children:[e.jsxs(ne,{children:[e.jsx(Vs,{size:14})," OpenCode config"]}),e.jsx(re,{children:e.jsx("code",{className:"mono ellipsis",style:{fontSize:11},children:i||"~/.config/opencode/opencode.json"})}),e.jsxs("div",{className:"view-actions",style:{marginBottom:12},children:[e.jsxs(z,{variant:"secondary",size:"sm",onClick:n,children:[e.jsx(de,{size:14})," Reload"]}),e.jsxs(z,{variant:"primary",size:"sm",disabled:!s.data||!!s.error||!a,onClick:d,children:[t?e.jsx("span",{className:"btn-spinner"}):e.jsx(as,{size:14}),"Save"]})]}),e.jsx("div",{className:"config-section-tabs",style:{display:"flex",gap:4,marginBottom:16,flexWrap:"wrap"},children:Fi.map(c=>e.jsx("button",{type:"button",className:Z("tab-btn",p===c.id&&"active"),onClick:()=>u(c.id),children:c.label},c.id))}),p==="model"&&e.jsx(Hi,{cfg:g,apply:h}),p==="plugins"&&e.jsx(_i,{cfg:g,apply:h}),p==="tools"&&e.jsx(Vi,{cfg:g,apply:h}),p==="permissions"&&e.jsx(qi,{cfg:g,apply:h}),p==="hooks"&&e.jsx(Wi,{cfg:g,apply:h}),p==="advanced"&&e.jsxs("div",{children:[e.jsx("div",{className:"config-grid-label",style:{marginBottom:8},children:s.error?e.jsx("span",{className:"text-error",children:s.error}):e.jsx("span",{className:"muted",children:"Raw JSON — edit with care"})}),e.jsx("textarea",{ref:l,className:Z("textarea config-textarea",s.error&&"invalid"),spellCheck:!1,value:s.raw,onChange:c=>o(c.target.value),style:{minHeight:300}})]})]})}function Hi({cfg:s,apply:a}){const t=(s==null?void 0:s.model)||{};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:12},children:[e.jsx("p",{className:"muted text-sm",children:"Configure the default model used by OpenCode agents."}),e.jsxs("div",{className:"field-row",children:[e.jsx("label",{className:"field-label",children:"Provider"}),e.jsx("input",{className:"input",value:String(t.provider||""),onChange:i=>a({model:{...t,provider:i.target.value}}),placeholder:"e.g. openai, anthropic, google"})]}),e.jsxs("div",{className:"field-row",children:[e.jsx("label",{className:"field-label",children:"Model ID"}),e.jsx("input",{className:"input",value:String(t.model||""),onChange:i=>a({model:{...t,model:i.target.value}}),placeholder:"e.g. gpt-4o, claude-sonnet-4-20250514"})]}),!!t.apiKey&&e.jsxs("div",{className:"field-row",children:[e.jsx("label",{className:"field-label",children:"API Key"}),e.jsx("input",{className:"input",type:"password",value:String(t.apiKey||""),onChange:i=>a({model:{...t,apiKey:i.target.value}}),placeholder:"sk-..."})]}),!!t.baseURL&&e.jsxs("div",{className:"field-row",children:[e.jsx("label",{className:"field-label",children:"Base URL"}),e.jsx("input",{className:"input",value:String(t.baseURL||""),onChange:i=>a({model:{...t,baseURL:i.target.value}}),placeholder:"https://api.openai.com/v1"})]})]})}function _i({cfg:s,apply:a}){const t=Array.isArray(s==null?void 0:s.plugins)?s.plugins:[],[i,n]=r.useState(null),[d,o]=r.useState({}),l=()=>{const g=[...t,{name:"",enabled:!0}];a({plugins:g})},p=g=>{const h=t.filter((c,x)=>x!==g);a({plugins:h})},u=(g,h)=>{const c=t.map((x,M)=>M===g?{...x,...h}:x);a({plugins:c}),n(null)};return e.jsxs("div",{children:[e.jsx("p",{className:"muted text-sm",style:{marginBottom:12},children:"Manage enabled plugins."}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[t.length===0&&e.jsx("p",{className:"muted text-sm",children:"No plugins configured."}),t.map((g,h)=>e.jsx("div",{className:"config-list-row",children:i===h?e.jsxs("div",{style:{display:"flex",gap:8,flex:1,alignItems:"center"},children:[e.jsx("input",{className:"input",value:String(d.name||""),onChange:c=>o({...d,name:c.target.value}),placeholder:"plugin-name"}),e.jsxs("label",{style:{display:"flex",gap:4,fontSize:12},children:[e.jsx("input",{type:"checkbox",checked:!!d.enabled,onChange:c=>o({...d,enabled:c.target.checked})}),"enabled"]}),e.jsx(z,{variant:"primary",size:"sm",onClick:()=>u(h,d),children:"Apply"}),e.jsx(z,{variant:"ghost",size:"sm",onClick:()=>n(null),children:e.jsx($e,{size:12})})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{fontFamily:"var(--font-mono)",fontSize:13},children:g.name||"unnamed"}),e.jsx("span",{className:Z("tag",g.enabled!==!1?"tag-success":"tag-neutral"),children:g.enabled!==!1?"enabled":"disabled"}),e.jsxs("div",{style:{marginLeft:"auto",display:"flex",gap:4},children:[e.jsx("button",{type:"button",className:"icon-btn",onClick:()=>{n(h),o(g)},title:"Edit",children:e.jsx(rs,{size:12})}),e.jsx("button",{type:"button",className:"icon-btn text-error",onClick:()=>p(h),title:"Remove",children:e.jsx(be,{size:12})})]})]})},h))]}),e.jsxs(z,{variant:"secondary",size:"sm",onClick:l,style:{marginTop:8},children:[e.jsx(je,{size:12})," Add plugin"]})]})}function Vi({cfg:s,apply:a}){const t=(s==null?void 0:s.tools)||{},i=o=>{a({tools:{...t,[o]:!t[o]}})},n=o=>{!o||t[o]!==void 0||a({tools:{...t,[o]:!0}})},d=o=>{const l={...t};delete l[o],a({tools:l})};return e.jsxs("div",{children:[e.jsx("p",{className:"muted text-sm",style:{marginBottom:12},children:"Enable or disable built-in tools."}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[Object.keys(t).length===0&&e.jsx("p",{className:"muted text-sm",children:"No tools configured."}),Object.entries(t).map(([o,l])=>e.jsxs("div",{className:"config-list-row",children:[e.jsx("span",{style:{fontFamily:"var(--font-mono)",fontSize:13},children:o}),e.jsxs("label",{style:{display:"flex",gap:4,alignItems:"center",fontSize:12},children:[e.jsx("input",{type:"checkbox",checked:!!l,onChange:()=>i(o)}),"enabled"]}),e.jsx("button",{type:"button",className:"icon-btn text-error",style:{marginLeft:"auto"},onClick:()=>d(o),title:"Remove",children:e.jsx(be,{size:12})})]},o))]}),e.jsxs("div",{style:{display:"flex",gap:8,marginTop:8},children:[e.jsx("input",{className:"input",placeholder:"tool-name",onKeyDown:o=>{o.key==="Enter"&&n(o.target.value.trim())}}),e.jsxs(z,{variant:"secondary",size:"sm",onClick:o=>{var l,p;return n(((p=(l=o.currentTarget.closest("div"))==null?void 0:l.querySelector("input"))==null?void 0:p.value.trim())||"")},children:[e.jsx(je,{size:12})," Add"]})]})]})}function qi({cfg:s,apply:a}){const t=(s==null?void 0:s.permissions)||{},[i,n]=r.useState("allow"),d=Array.isArray(t.allow)?t.allow:[],o=Array.isArray(t.deny)?t.deny:[],l=(g,h)=>c=>{c&&a({permissions:{...t,[h]:[...g,c]}})},p=(g,h,c)=>{a({permissions:{...t,[g]:h.filter((x,M)=>M!==c)}})},u=i==="allow"?d:o;return e.jsxs("div",{children:[e.jsx("p",{className:"muted text-sm",style:{marginBottom:12},children:"Allow or deny tool/scope rules."}),e.jsxs("div",{style:{display:"flex",gap:4,marginBottom:12},children:[e.jsxs("button",{type:"button",className:Z("tab-btn",i==="allow"&&"active"),onClick:()=>n("allow"),children:["Allow (",d.length,")"]}),e.jsxs("button",{type:"button",className:Z("tab-btn",i==="deny"&&"active"),onClick:()=>n("deny"),children:["Deny (",o.length,")"]})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[u.length===0&&e.jsxs("p",{className:"muted text-sm",children:["No ",i," rules."]}),u.map((g,h)=>e.jsxs("div",{className:"config-list-row",children:[e.jsx("span",{style:{fontFamily:"var(--font-mono)",fontSize:13},children:g}),e.jsx("button",{type:"button",className:"icon-btn text-error",style:{marginLeft:"auto"},onClick:()=>p(i,u,h),children:e.jsx(be,{size:12})})]},h))]}),e.jsxs("div",{style:{display:"flex",gap:8,marginTop:8},children:[e.jsx("input",{className:"input",placeholder:`${i} rule (e.g. tool:read, scope:filesystem)`,onKeyDown:g=>{if(g.key==="Enter"){const h=g.target.value.trim();h&&(l(u,i)(h),g.target.value="")}}}),e.jsxs(z,{variant:"secondary",size:"sm",onClick:g=>{var x;const h=(x=g.currentTarget.closest("div"))==null?void 0:x.querySelector("input"),c=h==null?void 0:h.value.trim();c&&(l(u,i)(c),h.value="")},children:[e.jsx(je,{size:12})," Add"]})]})]})}function Wi({cfg:s,apply:a}){const t=(s==null?void 0:s.hooks)||{},i=(n,d)=>{a({hooks:{...t,[n]:d}})};return e.jsxs("div",{children:[e.jsx("p",{className:"muted text-sm",style:{marginBottom:12},children:"Configure pre/post tool hooks."}),Object.keys(t).length===0&&e.jsx("p",{className:"muted text-sm",children:"No hooks configured."}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:12},children:["preTool","postTool","preAgent","postAgent"].map(n=>{const d=t[n];return e.jsxs("div",{className:"field-row",style:{alignItems:"flex-start"},children:[e.jsx("label",{className:"field-label",style:{minWidth:100},children:n}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:6,flex:1},children:e.jsx("input",{className:"input",value:typeof d=="object"&&d!==null&&"command"in d?String(d.command||""):"",onChange:o=>i(n,{command:o.target.value}),placeholder:`${n} command (e.g. node /path/to/hook.js)`})})]},n)})})]})}function Ki({diagnostics:s,loading:a,onReload:t}){return e.jsxs(se,{children:[e.jsxs(ne,{children:[e.jsx(zt,{size:14})," Diagnostics"]}),e.jsxs(re,{children:["System health, file counts, recent errors."," ",e.jsx("button",{type:"button",className:"link-btn",onClick:t,children:"Refresh"})]}),a&&e.jsx("p",{className:"muted",children:"Loading diagnostics…"}),s&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"diagnostics-grid",children:[e.jsxs("div",{className:"diagnostic-tile",children:[e.jsx("div",{className:"diagnostic-tile-label",children:"Version"}),e.jsx("div",{className:"diagnostic-tile-value mono",children:s.version})]}),e.jsxs("div",{className:"diagnostic-tile",children:[e.jsx("div",{className:"diagnostic-tile-label",children:"Uptime"}),e.jsxs("div",{className:"diagnostic-tile-value mono",children:[s.uptime,"s"]})]}),e.jsxs("div",{className:"diagnostic-tile",children:[e.jsx("div",{className:"diagnostic-tile-label",children:"Node"}),e.jsx("div",{className:"diagnostic-tile-value mono",children:s.nodeVersion})]}),e.jsxs("div",{className:"diagnostic-tile",children:[e.jsx("div",{className:"diagnostic-tile-label",children:"Platform"}),e.jsx("div",{className:"diagnostic-tile-value mono",children:s.platform})]}),e.jsxs("div",{className:"diagnostic-tile",children:[e.jsx("div",{className:"diagnostic-tile-label",children:"Memory (heap)"}),e.jsxs("div",{className:"diagnostic-tile-value mono",children:[Math.round(s.memory.heapUsed/1024/1024),"MB"]})]}),e.jsxs("div",{className:"diagnostic-tile",children:[e.jsx("div",{className:"diagnostic-tile-label",children:"Memory (RSS)"}),e.jsxs("div",{className:"diagnostic-tile-value mono",children:[Math.round(s.memory.rss/1024/1024),"MB"]})]}),e.jsxs("div",{className:"diagnostic-tile",children:[e.jsx("div",{className:"diagnostic-tile-label",children:"Service"}),e.jsx("div",{className:"diagnostic-tile-value",children:s.service.running?e.jsxs("span",{className:"tag tag-success",children:["running (pid ",s.service.pid,")"]}):e.jsx("span",{className:"tag tag-neutral",children:"stopped"})})]}),e.jsxs("div",{className:"diagnostic-tile",children:[e.jsx("div",{className:"diagnostic-tile-label",children:"Active project"}),e.jsx("div",{className:"diagnostic-tile-value mono",children:s.counts.activeProject||"—"})]})]}),e.jsxs("div",{className:"diagnostic-counts",children:[e.jsxs("span",{children:["agents: ",e.jsx("strong",{children:s.counts.agents})]}),e.jsxs("span",{children:["projects: ",e.jsx("strong",{children:s.counts.projects})]}),e.jsxs("span",{children:["mods: ",e.jsx("strong",{children:s.counts.mods})]}),e.jsxs("span",{children:["schedules: ",e.jsx("strong",{children:s.counts.schedules})]}),e.jsxs("span",{children:["tasks: ",e.jsx("strong",{children:s.counts.tasks})]}),e.jsxs("span",{children:["providers: ",e.jsx("strong",{children:s.counts.providers})]}),e.jsxs("span",{children:["mcps: ",e.jsx("strong",{children:s.counts.mcps})]})]}),e.jsxs("div",{className:"diagnostic-errors",children:[e.jsxs("div",{className:"muted",children:["Last ",s.errors.length," errors from service.log"]}),s.errors.length===0?e.jsx("p",{className:"muted",children:"No errors recorded."}):e.jsx("ul",{children:s.errors.map((i,n)=>e.jsxs("li",{className:"mono",children:[i.ts&&e.jsxs("span",{className:"muted",children:["[",i.ts,"] "]}),i.line]},n))})]})]})]})}function Gi({providers:s,onChange:a,onReload:t}){const i=he(),n=ke(),d=l=>{let p=null,u=null,g=null,h=null,c=null,x=null;const M=!!l,k=(l==null?void 0:l.id)||"",S=(l==null?void 0:l.name)||"",b=(l==null?void 0:l.baseURL)||"",v=(l==null?void 0:l.apiKey)||"",y=((l==null?void 0:l.models)||[]).join(", "),T=(l==null?void 0:l.enabled)!==!1;n.open({title:M?`Edit provider "${l.id}"`:"Add provider",children:e.jsxs("div",{children:[e.jsxs("div",{className:"modal-form-row",children:[e.jsx("label",{children:"ID (a-z, 0-9, dashes)"}),e.jsx("input",{ref:m=>p=m,className:"input",type:"text",defaultValue:k,placeholder:"anthropic",disabled:M})]}),e.jsxs("div",{className:"modal-form-row",children:[e.jsx("label",{children:"Display name"}),e.jsx("input",{ref:m=>u=m,className:"input",type:"text",defaultValue:S,placeholder:"Anthropic"})]}),e.jsxs("div",{className:"modal-form-row",children:[e.jsx("label",{children:"Base URL"}),e.jsx("input",{ref:m=>g=m,className:"input",type:"text",defaultValue:b,placeholder:"https://api.anthropic.com"})]}),e.jsxs("div",{className:"modal-form-row",children:[e.jsxs("label",{children:["API key",M&&" (leave masked value unchanged to keep)"]}),e.jsx("input",{ref:m=>h=m,className:"input",type:"password",defaultValue:v,placeholder:"sk-...",autoComplete:"off"})]}),e.jsxs("div",{className:"modal-form-row",children:[e.jsx("label",{children:"Models (comma-separated)"}),e.jsx("textarea",{ref:m=>c=m,className:"textarea",defaultValue:y,placeholder:"claude-sonnet-4-5, claude-opus-4-1",rows:3})]}),e.jsx("div",{className:"modal-form-row",children:e.jsxs("label",{className:"checkbox-row",children:[e.jsx("input",{ref:m=>x=m,type:"checkbox",defaultChecked:T}),"Enabled"]})})]}),footer:e.jsxs("div",{className:"modal-footer-actions",children:[e.jsx(z,{variant:"ghost",onClick:()=>n.close(),children:"Cancel"}),e.jsxs(z,{variant:"primary",onClick:async()=>{const m=((p==null?void 0:p.value)||"").trim(),I=((u==null?void 0:u.value)||"").trim(),U=((g==null?void 0:g.value)||"").trim(),R=(h==null?void 0:h.value)||"",W=((c==null?void 0:c.value)||"").split(/[,\n]/).map(q=>q.trim()).filter(Boolean),$=!!(x!=null&&x.checked);if(!m){i.warning("ID is required.");return}if(!/^[a-z0-9][a-z0-9_-]{0,63}$/i.test(m)){i.warning("ID must be a-z, 0-9, dashes.");return}try{const q={id:m,name:I||m,baseURL:U,apiKey:R,models:W,enabled:$};if(M){const X=await A.put(`/config/providers/${encodeURIComponent(m)}`,q);a(s.map(N=>N.id===m?X:N)),i.success(`Provider "${m}" updated.`)}else{const X=await A.post("/config/providers",q);a([...s,X]),i.success(`Provider "${m}" added.`)}n.close()}catch(q){i.error(`Save failed: ${q.message}`)}},children:[M?"Update":"Add"," provider"]})]})})},o=async l=>{if(confirm(`Remove provider "${l}"?`))try{await A.del(`/config/providers/${encodeURIComponent(l)}`),a(s.filter(p=>p.id!==l)),i.success("Provider removed.")}catch(p){i.error(`Remove failed: ${p.message}`)}};return e.jsxs(se,{children:[e.jsxs(ne,{children:[e.jsx(Ye,{size:14})," Providers (",s.length,")"]}),e.jsxs(re,{children:["AI providers configured under ",e.jsx("code",{children:"opencode.json#provider"}),". Each provider has a base URL, API key, and a list of model IDs."]}),e.jsx(el,{onAdd:(l,p,u,g)=>{d({id:l,name:p,baseURL:u,apiKey:g})}}),e.jsxs("div",{className:"view-actions",style:{marginBottom:12},children:[e.jsxs(z,{variant:"primary",size:"sm",onClick:()=>d(),children:[e.jsx(je,{size:14})," Add provider"]}),e.jsxs(z,{variant:"ghost",size:"sm",onClick:t,children:[e.jsx(de,{size:14})," Refresh"]})]}),s.length===0?e.jsx(Yi,{onAdd:()=>d()}):e.jsx("div",{className:"provider-list",children:s.map(l=>e.jsxs(se,{className:"provider-row",children:[e.jsxs("div",{className:"provider-row-head",children:[e.jsxs("div",{style:{minWidth:0,flex:1},children:[e.jsx("div",{className:"provider-name",children:l.name||l.id}),e.jsx("div",{className:"provider-id",children:l.id})]}),e.jsxs("div",{className:"provider-actions",children:[e.jsxs("label",{className:"toggle-row",title:"Enabled",children:[e.jsx("input",{type:"checkbox",checked:l.enabled!==!1,onChange:async p=>{try{const u=await A.put(`/config/providers/${encodeURIComponent(l.id)}`,{enabled:p.target.checked});a(s.map(g=>g.id===l.id?u:g))}catch(u){i.error(`Toggle failed: ${u.message}`)}}}),l.enabled!==!1?"on":"off"]}),e.jsx("button",{type:"button",className:"icon-btn","aria-label":"Edit",title:"Edit",onClick:()=>d(l),children:e.jsx(rs,{size:12})}),e.jsx("button",{type:"button",className:"icon-btn icon-btn-danger","aria-label":"Remove",title:"Remove",onClick:()=>o(l.id),children:e.jsx(be,{size:12})})]})]}),e.jsxs("div",{className:"provider-meta",children:[e.jsxs("div",{children:[e.jsx("span",{className:"muted",children:"Base URL:"})," ",e.jsx("code",{children:l.baseURL||"—"})]}),e.jsxs("div",{children:[e.jsx("span",{className:"muted",children:"API key:"})," ",e.jsx("code",{children:l.apiKey||"—"})]}),e.jsxs("div",{children:[e.jsx("span",{className:"muted",children:"Models:"})," ",(l.models||[]).join(", ")||"—"]})]})]},l.id))})]})}function Yi({onAdd:s}){return e.jsxs("div",{style:{padding:"32px 16px",textAlign:"center",color:"var(--text-dim)",border:"1px dashed var(--border)",borderRadius:"var(--radius-md)",display:"flex",flexDirection:"column",gap:8,alignItems:"center"},children:[e.jsx(Ye,{size:28}),e.jsx("div",{children:"No providers configured."}),e.jsx("div",{style:{fontSize:12},children:"Add a provider to connect an AI model."}),e.jsxs(z,{variant:"primary",size:"sm",onClick:s,children:[e.jsx(je,{size:14})," Add your first provider"]})]})}function Xi(s){const a={};for(const t of s.split(/\r?\n/)){const i=t.trim();if(!i||i.startsWith("#"))continue;const n=i.indexOf("=");if(n<=0)continue;const d=i.slice(0,n).trim(),o=i.slice(n+1).trim();d&&(a[d]=o)}return a}function Ji(s){const a={};for(const t of s.split(/\r?\n/)){const i=t.trim();if(!i||i.startsWith("#"))continue;const n=i.indexOf(":");if(n<=0)continue;const d=i.slice(0,n).trim(),o=i.slice(n+1).trim();d&&(a[d]=o)}return a}function Qi({mcps:s,onChange:a,onReload:t}){const i=he(),n=ke(),d=l=>{let p=null,u=null,g=null,h=null,c=null,x=null,M=null,k=null,S=null;const b=!!l;l==null||l.type;const v=(l==null?void 0:l.type)==="remote"?"remote":"local",y=(l==null?void 0:l.command)||"",T=((l==null?void 0:l.args)||[]).join(" "),m=l!=null&&l.env?Object.entries(l.env).map(([W,$])=>`${W}=${$}`).join(`
319
- `):"",I=(l==null?void 0:l.url)||"",U=l!=null&&l.headers?Object.entries(l.headers).map(([W,$])=>`${W}: ${$}`).join(`
320
- `):"",R=!!(l!=null&&l.oauth),G=(l==null?void 0:l.enabled)!==!1;n.open({title:b?`Edit MCP "${l.id}"`:"Add MCP",children:e.jsxs("div",{children:[e.jsxs("div",{className:"modal-form-row",children:[e.jsx("label",{children:"ID (a-z, 0-9, dashes)"}),e.jsx("input",{ref:W=>p=W,className:"input",type:"text",defaultValue:(l==null?void 0:l.id)||"",placeholder:"supabase",disabled:b})]}),e.jsxs("div",{className:"modal-form-row",children:[e.jsx("label",{children:"Type"}),e.jsxs("div",{style:{display:"flex",gap:12},children:[e.jsxs("label",{className:"radio-label",children:[e.jsx("input",{ref:W=>W,type:"radio",name:"mcp-type",value:"local",defaultChecked:v==="local"}),"Local (stdio)"]}),e.jsxs("label",{className:"radio-label",children:[e.jsx("input",{ref:W=>u=W,type:"radio",name:"mcp-type",value:"remote",defaultChecked:v==="remote"}),"Remote (HTTP)"]})]})]}),e.jsxs("div",{"data-mcp-section":"local",children:[e.jsxs("div",{className:"modal-form-row",children:[e.jsx("label",{children:"Command (binary to invoke)"}),e.jsx("input",{ref:W=>g=W,className:"input",type:"text",defaultValue:y,placeholder:"uvx --from semble[mcp] semble"})]}),e.jsxs("div",{className:"modal-form-row",children:[e.jsx("label",{children:"Extra args (space-separated)"}),e.jsx("input",{ref:W=>h=W,className:"input",type:"text",defaultValue:T,placeholder:"--port 8080"}),e.jsx("div",{className:"field-help",children:"These are appended after the command."})]}),e.jsxs("div",{className:"modal-form-row",children:[e.jsx("label",{children:"Environment variables"}),e.jsx("textarea",{ref:W=>c=W,className:"textarea",defaultValue:m,placeholder:`API_KEY=xxx
321
- DEBUG=true`,rows:3}),e.jsx("div",{className:"field-help",children:"One KEY=VALUE per line."})]})]}),e.jsxs("div",{"data-mcp-section":"remote",children:[e.jsxs("div",{className:"modal-form-row",children:[e.jsx("label",{children:"URL"}),e.jsx("input",{ref:W=>x=W,className:"input",type:"text",defaultValue:I,placeholder:"https://mcp.example.com/mcp"})]}),e.jsxs("div",{className:"modal-form-row",children:[e.jsx("label",{children:"Headers"}),e.jsx("textarea",{ref:W=>M=W,className:"textarea",defaultValue:U,placeholder:`Authorization: Bearer xxx
322
- Content-Type: application/json`,rows:3}),e.jsx("div",{className:"field-help",children:'One "Key: Value" per line.'})]}),e.jsx("div",{className:"modal-form-row",children:e.jsxs("label",{className:"checkbox-row",children:[e.jsx("input",{ref:W=>k=W,type:"checkbox",defaultChecked:R}),"Use OAuth (browser-based auth flow)"]})})]}),e.jsx("div",{className:"modal-form-row",children:e.jsxs("label",{className:"checkbox-row",children:[e.jsx("input",{ref:W=>S=W,type:"checkbox",defaultChecked:G}),"Enabled"]})})]}),footer:e.jsxs("div",{className:"modal-footer-actions",children:[e.jsx(z,{variant:"ghost",onClick:()=>n.close(),children:"Cancel"}),e.jsxs(z,{variant:"primary",onClick:async()=>{const W=((p==null?void 0:p.value)||"").trim(),$=!!(u!=null&&u.checked),q=((g==null?void 0:g.value)||"").trim(),X=((h==null?void 0:h.value)||"").trim(),N=X?X.split(/\s+/):[],E=Xi((c==null?void 0:c.value)||""),D=((x==null?void 0:x.value)||"").trim(),H=Ji((M==null?void 0:M.value)||""),te=!!(k!=null&&k.checked),ie=!!(S!=null&&S.checked);if(!W){i.warning("ID is required.");return}if(!/^[a-z0-9][a-z0-9_-]{0,63}$/i.test(W)){i.warning("ID must be a-z, 0-9, dashes.");return}try{const ue={id:W,type:$?"remote":"local",command:q,args:N,env:E,url:D,headers:H,oauth:te,enabled:ie};if(b){const B=await A.put(`/config/mcps/${encodeURIComponent(W)}`,ue);a(s.map(Q=>Q.id===W?B:Q)),i.success(`MCP "${W}" updated.`)}else{const B=await A.post("/config/mcps",ue);a([...s,B]),i.success(`MCP "${W}" added.`)}n.close()}catch(ue){i.error(`Save failed: ${ue.message}`)}},children:[b?"Update":"Add"," MCP"]})]})})},o=async l=>{if(confirm(`Remove MCP "${l}"?`))try{await A.del(`/config/mcps/${encodeURIComponent(l)}`),a(s.filter(p=>p.id!==l)),i.success("MCP removed.")}catch(p){i.error(`Remove failed: ${p.message}`)}};return e.jsxs(se,{children:[e.jsxs(ne,{children:[e.jsx(js,{size:14})," MCPs (",s.length,")"]}),e.jsxs(re,{children:["Model Context Protocol servers under ",e.jsx("code",{children:"opencode.json#mcp"}),". Local MCPs run as stdio subprocesses; remote MCPs are HTTP endpoints."]}),e.jsxs("div",{className:"view-actions",style:{marginBottom:12},children:[e.jsxs(z,{variant:"primary",size:"sm",onClick:()=>d(),children:[e.jsx(je,{size:14})," Add MCP"]}),e.jsxs(z,{variant:"ghost",size:"sm",onClick:t,children:[e.jsx(de,{size:14})," Refresh"]})]}),s.length===0?e.jsxs("div",{style:{padding:"32px 16px",textAlign:"center",color:"var(--text-dim)",border:"1px dashed var(--border)",borderRadius:"var(--radius-md)",display:"flex",flexDirection:"column",gap:8,alignItems:"center"},children:[e.jsx(js,{size:28}),e.jsx("div",{children:"No MCPs configured."}),e.jsxs(z,{variant:"primary",size:"sm",onClick:()=>d(),children:[e.jsx(je,{size:14})," Add your first MCP"]})]}):e.jsx("div",{className:"mcp-list",children:s.map(l=>e.jsxs(se,{className:"mcp-row",children:[e.jsxs("div",{className:"mcp-row-head",children:[e.jsxs("div",{style:{minWidth:0,flex:1},children:[e.jsx("div",{className:"mcp-name",children:l.id}),e.jsxs("div",{className:"mcp-id",children:[l.type==="remote"?"remote":"local"," ",l.enabled!==!1?"· enabled":"· disabled"]})]}),e.jsxs("div",{className:"mcp-actions",children:[e.jsxs("label",{className:"toggle-row",title:"Enabled",children:[e.jsx("input",{type:"checkbox",checked:l.enabled!==!1,onChange:async p=>{try{const u=await A.put(`/config/mcps/${encodeURIComponent(l.id)}`,{enabled:p.target.checked});a(s.map(g=>g.id===l.id?u:g))}catch(u){i.error(`Toggle failed: ${u.message}`)}}}),l.enabled!==!1?"on":"off"]}),e.jsx("button",{type:"button",className:"icon-btn","aria-label":"Edit",title:"Edit",onClick:()=>d(l),children:e.jsx(rs,{size:12})}),e.jsx("button",{type:"button",className:"icon-btn icon-btn-danger","aria-label":"Remove",title:"Remove",onClick:()=>o(l.id),children:e.jsx(be,{size:12})})]})]}),e.jsx("div",{className:"mcp-meta",children:l.type==="remote"?e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx("span",{className:"muted",children:"URL:"})," ",e.jsx("code",{children:l.url||"—"})]}),Object.keys(l.headers||{}).length>0&&e.jsxs("div",{children:[e.jsx("span",{className:"muted",children:"Headers:"})," ",e.jsxs("code",{children:[Object.keys(l.headers||{}).length," header(s)"]})]}),l.oauth&&e.jsxs("div",{children:[e.jsx("span",{className:"muted",children:"Auth:"})," ",e.jsx("code",{children:"OAuth"})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx("span",{className:"muted",children:"Command:"})," ",e.jsx("code",{children:l.command||"—"})]}),l.args&&l.args.length>0&&e.jsxs("div",{children:[e.jsx("span",{className:"muted",children:"Args:"})," ",e.jsx("code",{children:l.args.join(" ")})]}),l.env&&Object.keys(l.env).length>0&&e.jsxs("div",{children:[e.jsx("span",{className:"muted",children:"Env:"})," ",e.jsxs("code",{children:[Object.keys(l.env).length," var(s)"]})]})]})})]},l.id))})]})}function Zi({onDownload:s}){return e.jsxs(se,{children:[e.jsxs(ne,{children:[e.jsx(De,{size:14})," Export / Import"]}),e.jsx(re,{children:"Download a JSON bundle of diagnostics, configuration, providers, and MCPs for support requests or backup. Server-side imports are not yet implemented."}),e.jsx("div",{className:"view-actions",style:{marginTop:12},children:e.jsxs(z,{variant:"primary",onClick:s,children:[e.jsx(De,{size:14})," Download diagnostics bundle"]})}),e.jsxs("div",{style:{marginTop:16,fontSize:12,color:"var(--text-dim)"},children:[e.jsx(za,{size:12,style:{display:"inline",verticalAlign:-2}})," Bundles include: opencode.json snapshot, providers list (with masked API keys), MCP list, recent service log errors, and active project metadata."]})]})}function el({onAdd:s}){const a=he(),[t,i]=r.useState(null),[n,d]=r.useState(!1),[o,l]=r.useState(!1),p=async c=>{d(!0);try{const x=await A.get(`/providers/auto-detect${c?"":"?probe=0"}`);i(x.providers||[]);const M=(x.providers||[]).filter(k=>k.status==="configured");M.length>0?a.success(`Detected ${M.length} configured provider${M.length===1?"":"s"}.`):a.info("No configured providers detected in env or config.")}catch(x){a.error(`Auto-detect failed: ${x.message}`)}finally{d(!1)}},u=c=>c==="configured"?e.jsx(gs,{size:12,style:{color:"var(--success)"}}):c==="unknown"?e.jsx(Ee,{size:12,style:{color:"var(--warning)"}}):e.jsx($e,{size:12,style:{color:"var(--text-dim)"}}),g=(t||[]).filter(c=>c.status==="configured"),h=(t||[]).filter(c=>c.status!=="configured");return e.jsxs(se,{className:"autodetect-banner",children:[e.jsxs("div",{className:"autodetect-head",onClick:()=>l(c=>!c),children:[e.jsx(gs,{size:14}),e.jsx("span",{className:"autodetect-title",children:"Auto-detect providers"}),e.jsx("span",{className:"muted",style:{fontSize:11},children:t?`${g.length} configured · ${h.length} other`:"scan env vars + opencode.json for known keys"}),e.jsx("span",{className:"autodetect-spacer"}),e.jsxs(z,{variant:"ghost",size:"sm",onClick:c=>{c.stopPropagation(),p(!0)},disabled:n,title:"Probe each provider's /models endpoint",children:[n?e.jsx(ge,{size:"sm"}):e.jsx(de,{size:12})," Detect"]}),o?e.jsx(Ae,{size:14}):e.jsx(Ue,{size:14})]}),o&&e.jsx("div",{className:"autodetect-body",children:t?e.jsxs("table",{className:"autodetect-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Status"}),e.jsx("th",{children:"Provider"}),e.jsx("th",{children:"Source"}),e.jsx("th",{children:"Probe"}),e.jsx("th",{})]})}),e.jsx("tbody",{children:t.map(c=>{var x,M,k;return e.jsxs("tr",{children:[e.jsxs("td",{children:[u(c.status)," ",e.jsx("span",{className:"autodetect-status",children:c.status})]}),e.jsxs("td",{children:[e.jsx("strong",{children:c.name})," ",e.jsx("span",{className:"muted mono",children:c.id})]}),e.jsx("td",{className:"muted",children:c.keySource||"—"}),e.jsx("td",{className:"muted",children:((x=c.probed)==null?void 0:x.modelCount)!=null?`${c.probed.modelCount} models`:(M=c.probed)!=null&&M.reason?c.probed.reason:(k=c.probed)!=null&&k.ok?"ok":"—"}),e.jsx("td",{children:c.status==="configured"&&e.jsxs(z,{variant:"ghost",size:"sm",onClick:()=>s(c.id,c.name,c.baseURL||""),title:"Add this provider to opencode.json",children:[e.jsx(je,{size:10})," Add"]})})]},c.id)})})]}):e.jsxs("div",{className:"muted",style:{padding:12,fontSize:12},children:["Click ",e.jsx("strong",{children:"Detect"})," to scan env vars and opencode.json for known provider keys. Probes each provider's ",e.jsx("code",{children:"/models"})," endpoint with a 1.5s timeout."]})})]})}const sl=[{id:"dark",label:"Dark",Icon:oa},{id:"light",label:"Light",Icon:da},{id:"system",label:"System",Icon:ha}],tl=[{name:"Purple",accent:"#8b5cf6"},{name:"Blue",accent:"#3b82f6"},{name:"Green",accent:"#10b981"},{name:"Orange",accent:"#f97316"},{name:"Red",accent:"#ef4444"},{name:"Pink",accent:"#ec4899"},{name:"Cyan",accent:"#06b6d4"},{name:"Mono",accent:"#6b7280"}],al=["Inter","system-ui","Segoe UI","Roboto","JetBrains Mono","SF Mono","Cascadia Code"];function nl(s){if(s<=0)return"expired";const a=Math.floor(s/1e3),t=Math.floor(a/60),i=a%60;return`${t}:${String(i).padStart(2,"0")}`}function il(){const s=he(),[a,t]=r.useState(null),[i,n]=r.useState(!1),[d,o]=r.useState(null),[l,p]=r.useState(Date.now()),u=r.useCallback(async()=>{n(!0),o(null);try{const c=await A.post("/pair/start");t(c)}catch(c){o((c==null?void 0:c.message)||"Failed to start pairing"),s.error("Pairing failed.")}finally{n(!1)}},[s]);r.useEffect(()=>{if(!a)return;const c=setInterval(()=>p(Date.now()),1e3);return()=>clearInterval(c)},[a]);const g=a?a.expiresAt-l:0,h=a!=null&&g<=0;return e.jsxs(se,{id:"settings-updates","data-section":"updates",children:[e.jsxs(ne,{children:[e.jsx(ma,{size:14})," Companion App"]}),e.jsxs(re,{children:["Scan the QR with ",e.jsx("a",{href:"https://github.com/DrB0rk/BizarHarness",target:"_blank",rel:"noopener noreferrer",children:"Bizar Companion"})," to pair. Tokens expire after 5 minutes."]}),e.jsxs("div",{style:{display:"flex",gap:16,alignItems:"flex-start",flexWrap:"wrap"},children:[e.jsx("div",{style:{flex:"0 0 auto"},children:a&&!h?e.jsx("div",{style:{background:"#fff",padding:12,borderRadius:12},children:e.jsx(ua,{value:a.qrPayload,size:192,level:"M",includeMargin:!1})}):e.jsx("div",{style:{width:216,height:216,borderRadius:12,background:"var(--surface-2, #161b22)",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-muted, #8b949e)",fontSize:12,textAlign:"center",padding:16,border:"1px dashed var(--border, #30363d)"},children:a&&h?"QR expired":"No QR generated yet"})}),e.jsxs("div",{style:{flex:"1 1 240px",minWidth:220},children:[!a&&e.jsxs(z,{variant:"primary",onClick:u,disabled:i,children:[e.jsx(pa,{size:14})," ",i?"Generating…":"Generate QR Code"]}),a&&!h&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{marginBottom:10},children:[e.jsx("strong",{children:"Expires in"})," ",e.jsx("span",{className:"mono",children:nl(g)})]}),e.jsxs("div",{style:{marginBottom:6},children:[e.jsx("strong",{children:"URL:"})," ",e.jsx("span",{className:"mono",style:{wordBreak:"break-all"},children:a.publicUrl})]}),e.jsxs("div",{style:{marginBottom:12},children:[e.jsx("strong",{children:"Token:"})," ",e.jsxs("span",{className:"mono",style:{wordBreak:"break-all",fontSize:12},children:[a.token.slice(0,16),"…",a.token.slice(-6)]})]}),e.jsxs(z,{variant:"secondary",onClick:u,disabled:i,children:[e.jsx(de,{size:14})," Regenerate"]})]}),a&&h&&e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{marginBottom:12,color:"var(--error, #f85149)"},children:"Token expired — generate a fresh QR to pair again."}),e.jsxs(z,{variant:"primary",onClick:()=>{t(null),u()},children:[e.jsx(de,{size:14})," Generate new QR"]})]}),d&&e.jsx("div",{style:{marginTop:10,color:"var(--error, #f85149)",fontSize:12},children:d})]})]})]})}const ll=[{id:"topnav",label:"Top nav"},{id:"sidebar",label:"Sidebar"},{id:"both",label:"Both"}];function rl(){const s=he(),[a,t]=r.useState({current:{},latest:null,checking:!1,updating:!1,hasUpdates:!1,requiresRestart:!1,perPackage:{}});r.useEffect(()=>{const p=new _s;return p.on(u=>{(u.type==="update:progress"||u.type==="update:log"||u.type==="update:complete")&&t(g=>{if(u.type==="update:complete")return{...g,updating:!1,requiresRestart:!!u.requiresRestart};if(u.type==="update:log"){const c=u,x=g.perPackage[c.pkg]||{logs:[]};return{...g,perPackage:{...g.perPackage,[c.pkg]:{...x,logs:[...(x.logs||[]).slice(-50),c.line]}}}}const h=u;return{...g,perPackage:{...g.perPackage,[h.pkg]:{...g.perPackage[h.pkg],status:h.status,error:h.error,newVersion:h.newVersion}}}})}),()=>p.close()},[]),r.useEffect(()=>{A.get("/updates/status").then(p=>t(u=>({...u,current:p.current}))).catch(p=>t(u=>({...u,error:p.message})))},[]);const i=async()=>{t(p=>({...p,checking:!0,error:void 0}));try{const p=await A.get("/updates/check");t(u=>({...u,checking:!1,current:p.current,latest:p.latest,hasUpdates:p.hasUpdates}))}catch(p){t(u=>({...u,checking:!1,error:p.message}))}},n=async()=>{if(confirm("Update Bizar packages? The dashboard will restart automatically.")){t(p=>({...p,updating:!0,requiresRestart:!1,perPackage:{},error:void 0}));try{await A.post("/updates/apply",{packages:["bizar","bizar-dash","bizar-plugin"]})}catch(p){t(u=>({...u,updating:!1,error:p.message}))}}},d=async()=>{if(confirm("Restart the dashboard? You will be disconnected briefly."))try{await A.post("/restart"),s.info("Restarting…",3e3),setTimeout(()=>window.location.reload(),3e3)}catch{s.error("Restart failed")}},o=[{id:"bizar",name:"Bizar CLI"},{id:"bizar-dash",name:"Dashboard"},{id:"bizar-plugin",name:"Opencode Plugin"}],l=a.checking||a.updating;return e.jsxs(se,{id:"settings-updates","data-section":"updates",children:[e.jsxs(ne,{children:[e.jsx(De,{size:14})," Updates"]}),e.jsx(re,{children:"Check installed Bizar packages and apply dashboard updates."}),e.jsxs("div",{className:"updates-current",children:[e.jsx("h4",{children:"Installed versions"}),e.jsx("ul",{children:o.map(p=>e.jsxs("li",{children:[e.jsx("span",{children:p.name}),e.jsx("code",{className:"mono",children:a.current[p.id]||"—"})]},p.id))})]}),a.latest&&e.jsxs("div",{className:"updates-latest",children:[e.jsx("h4",{children:"Latest available"}),e.jsx("ul",{children:o.map(p=>{var c;const u=a.current[p.id],g=(c=a.latest)==null?void 0:c[p.id],h=u&&g&&u!==g;return e.jsxs("li",{className:h?"updates-outdated":"updates-current-version",children:[e.jsx("span",{children:p.name}),e.jsxs("code",{className:"mono",children:[g||"—",h&&e.jsx("span",{className:"updates-badge",children:"update available"})]})]},p.id)})})]}),a.updating&&e.jsx("div",{className:"updates-progress-rows",children:o.map(p=>{const u=a.perPackage[p.id]||{status:"idle",logs:[]};return e.jsxs("div",{className:"updates-pkg-row",children:[e.jsxs("div",{className:"updates-pkg-row-header",children:[e.jsx("span",{className:"updates-pkg-name",children:p.name}),e.jsxs("div",{className:"updates-pkg-status",children:[u.status==="starting"&&e.jsx("span",{className:"btn-spinner"}),u.status==="installing"&&e.jsx("span",{className:"btn-spinner"}),u.status==="done"&&e.jsx(Ca,{size:14,className:"icon-success"}),u.status==="error"&&e.jsx(Bs,{size:14,className:"icon-error"}),e.jsx("span",{children:u.status}),u.newVersion&&e.jsxs("code",{className:"mono",style:{fontSize:11},children:["→ ",u.newVersion]})]})]}),u.logs.length>0&&e.jsxs("details",{className:"updates-pkg-logs",children:[e.jsxs("summary",{children:["npm output (",u.logs.length," lines)"]}),e.jsx("pre",{children:u.logs.join(`
323
- `)})]}),u.status==="error"&&u.error&&e.jsxs("div",{className:"updates-pkg-error",children:[e.jsx(Ee,{size:12})," ",u.error]})]},p.id)})}),e.jsxs("div",{className:"updates-actions",children:[e.jsxs(z,{onClick:i,disabled:l,children:[a.checking?e.jsx("span",{className:"btn-spinner"}):e.jsx(de,{size:14}),"Check for updates"]}),e.jsxs(z,{variant:"primary",onClick:n,disabled:!a.hasUpdates||a.updating,children:[a.updating?e.jsx("span",{className:"btn-spinner"}):e.jsx(De,{size:14}),a.updating?"Updating…":a.hasUpdates?"Update now":"Up to date"]}),a.requiresRestart&&e.jsxs(z,{variant:"danger",onClick:d,children:[e.jsx(de,{size:14})," Restart Dashboard"]})]}),a.error&&e.jsxs("div",{className:"updates-error",children:[e.jsx(Ee,{size:14}),e.jsx("span",{children:a.error})]})]})}function cl({settings:s,refreshSnapshot:a}){var O,j,C,L,F,J,V;const t=he(),[i,n]=r.useState(s),[d,o]=r.useState(!1),[l,p]=r.useState(!1),[u,g]=r.useState(null),[h,c]=r.useState({port:4321,https:!0,hostname:""}),[x,M]=r.useState({});r.useEffect(()=>{n(s),o(!1),s.theme&&Ge(s.theme)},[s]),r.useEffect(()=>{u&&c({port:u.settings.port,https:u.settings.https!==!1,hostname:u.settings.hostname||""})},[u]),r.useEffect(()=>{A.get("/tailscale/status").then(g).catch(()=>{})},[]),r.useEffect(()=>{A.get("/settings/plugin-options").then(M).catch(()=>{})},[]);const k=f=>{n(_=>{const ee={..._,theme:{..._.theme,...f}};return Ge(ee.theme),ee}),o(!0)},S=f=>{n(_=>({..._,ui:{..._.ui,...f}})),o(!0)},b=(f,_)=>{n(ee=>({...ee,[f]:_})),o(!0)},v=f=>{n(_=>({..._,notifications:{..._.notifications,...f}})),o(!0)},y=f=>{n(_=>({..._,agents:{..._.agents,...f}})),o(!0)},T=[{id:"theme",label:"Theme"},{id:"layout",label:"Layout"},{id:"general",label:"General"},{id:"service",label:"Service"},{id:"tailscale",label:"Tailscale"},{id:"notifications",label:"Notifications"},{id:"auth",label:"Auth"},{id:"agents",label:"Agents"},{id:"dashboard",label:"Dashboard"},{id:"background",label:"Background"},{id:"system-llm",label:"System LLM"},{id:"updates",label:"Updates"},{id:"activity-log",label:"Activity"},{id:"about",label:"About"}],[m,I]=r.useState(()=>{if(typeof window>"u")return null;const f=window.location.hash.replace(/^#settings-/,"");return T.some(_=>_.id===f)?f:null}),U=f=>{I(f);try{const _=f?`#settings-${f}`:window.location.pathname;if(history.replaceState(null,"",_),f){const ee=document.getElementById(`settings-${f}`);ee&&ee.scrollIntoView({behavior:"smooth",block:"start"})}else window.scrollTo({top:0,behavior:"smooth"})}catch{}},R=f=>{n(_=>({..._,dashboard:{..._.dashboard,...f}})),o(!0)},G=async()=>{p(!0);try{const f=await A.put("/settings",i);n(f.data),o(!1),es(f.data.theme),Ge(f.data.theme),t.success("Settings saved."),await a()}catch(f){t.error(`Save failed: ${f.message}`)}finally{p(!1)}},W=async()=>{try{const f=await A.get("/settings");n(f.data),o(!1),es(f.data.theme),Ge(f.data.theme),t.info("Settings reloaded.",1500)}catch(f){t.error(`Reload failed: ${f.message}`)}},$=async()=>{if(confirm("Reset all settings to defaults?"))try{const f=await A.post("/settings/reset");n(f.data),o(!1),es(f.data.theme),Ge(f.data.theme),t.success("Settings reset."),await a()}catch(f){t.error(`Reset failed: ${f.message}`)}},q=async()=>{try{u!=null&&u.settings.enabled?(await A.post("/tailscale/disable"),t.success("Tailscale serve disabled.")):(await A.post("/tailscale/enable",{port:h.port||4321,https:h.https,hostname:h.hostname||""}),t.success("Tailscale serve enabled."));const f=await A.get("/tailscale/status");g(f)}catch(f){t.error(`Tailscale failed: ${f.message}`)}},X=i.about||{version:"3.0.4",homepage:"https://github.com/DrB0rk/BizarHarness",license:"MIT"},[N,E]=r.useState(A.getToken()),[D,H]=r.useState(null),[te,ie]=r.useState("");r.useEffect(()=>{let f=!1;return(async()=>{try{const _=await A.probeAuthStatus();f||H(_)}catch{f||H({required:!0,loopback:!1,peer:""})}})(),()=>{f=!0}},[]);const ue=async()=>{try{const f=await A.get("/auth/reveal");ie(f.token),E(f.token),A.setToken(f.token);try{await navigator.clipboard.writeText(f.token),t.success("Token copied to clipboard.")}catch{t.success("Token revealed — copy from the field below.")}}catch(f){t.error(`Reveal failed: ${f.message}`)}},B=async()=>{if(confirm("Regenerate the auth token? Anything still using the old token will start getting 401 errors immediately."))try{const f=await A.post("/auth/regenerate");ie(f.token),E(f.token),A.setToken(f.token);try{await navigator.clipboard.writeText(f.token),t.success("New token generated and copied to clipboard.")}catch{t.success("New token generated — copy from the field below. Old token is now invalid.")}}catch(f){t.error(`Regenerate failed: ${f.message}`)}},Q=()=>{A.setToken(N.trim()),t.success("Token saved. The dashboard will use it on the next request.")};return e.jsxs("div",{className:"view view-settings",children:[e.jsxs("header",{className:"view-header",children:[e.jsxs("div",{className:"view-header-text",children:[e.jsxs("h2",{className:"view-title",children:[e.jsx(ht,{size:18})," Settings"]}),e.jsxs("p",{className:"view-subtitle",children:["Personal preferences. Changes are saved to"," ",e.jsx("code",{children:"~/.config/bizar/settings.json"}),"."]})]}),e.jsxs("div",{className:"view-actions",children:[e.jsxs(z,{variant:"ghost",size:"sm",onClick:$,children:[e.jsx(Qs,{size:14})," Reset"]}),e.jsxs(z,{variant:"secondary",size:"sm",onClick:W,children:[e.jsx(de,{size:14})," Reload"]}),e.jsxs(z,{variant:"primary",size:"sm",disabled:!d||l,onClick:G,children:[l?e.jsx("span",{className:"btn-spinner"}):e.jsx(as,{size:14}),l?"Saving…":"Save"]})]})]}),e.jsxs("nav",{className:"settings-subnav","aria-label":"Settings sections",children:[e.jsx("button",{type:"button",className:Z("settings-subnav-button","settings-subnav-button-all",m===null&&"settings-subnav-button-active"),onClick:()=>U(null),title:"Show all settings sections",children:"All"}),T.map(f=>e.jsx("button",{type:"button",className:Z("settings-subnav-button",m===f.id&&"settings-subnav-button-active"),onClick:()=>U(f.id),children:f.label},f.id))]}),e.jsxs("div",{className:Z("settings-grid",m&&"settings-grid-filtered"),"data-active-section":m||void 0,children:[m&&e.jsxs("div",{className:"settings-filter-banner",children:[e.jsxs("span",{children:["Showing only ",e.jsx("strong",{children:(O=T.find(f=>f.id===m))==null?void 0:O.label}),"."]}),e.jsx("button",{type:"button",className:"settings-filter-clear",onClick:()=>U(null),children:"Show all sections"})]}),e.jsx("div",{"data-section":"theme",style:{display:m===null||m==="theme"?"block":"none"},children:e.jsxs(se,{id:"settings-theme","data-section":"theme",children:[e.jsxs(ne,{children:[e.jsx(wt,{size:14})," Theme"]}),e.jsx(re,{children:"Mode, accent, and colors. Live preview as you tweak."}),e.jsxs("div",{className:"field","data-setting-id":"theme.presets",children:[e.jsx("label",{className:"field-label",children:"Accent presets"}),e.jsx("div",{className:"theme-presets",children:tl.map(f=>e.jsxs("button",{type:"button",className:Z("theme-preset",i.theme.accent===f.accent&&"theme-preset-active"),onClick:()=>k({accent:f.accent}),title:f.name,children:[e.jsx("span",{className:"theme-preset-swatch",style:{background:f.accent}}),e.jsx("span",{className:"theme-preset-name",children:f.name})]},f.name))})]}),e.jsxs("div",{className:"field","data-setting-id":"theme.mode",children:[e.jsx("label",{className:"field-label",children:"Mode"}),e.jsx("div",{className:"theme-row",children:sl.map(({id:f,label:_,Icon:ee})=>{const P=i.theme.mode===f;return e.jsxs("button",{type:"button",className:Z("theme-card",P&&"theme-card-active"),onClick:()=>k({mode:f}),children:[e.jsx(ee,{size:16}),e.jsx("span",{className:"theme-card-label",children:_}),e.jsx("span",{className:Z("theme-card-swatch",`theme-card-swatch-${f}`)})]},f)})})]}),e.jsxs("div",{className:"theme-colors",children:[e.jsxs("div",{className:"field","data-setting-id":"theme.accent",children:[e.jsx("label",{className:"field-label",children:"Accent"}),e.jsxs("div",{className:"color-row",children:[e.jsx("input",{type:"color",className:"input color-input",value:i.theme.accent,onChange:f=>k({accent:f.target.value}),"aria-label":"Accent color"}),e.jsx("input",{type:"text",className:"input",value:i.theme.accent,onChange:f=>k({accent:f.target.value})})]})]}),e.jsxs("div",{className:"field","data-setting-id":"theme.success",children:[e.jsx("label",{className:"field-label",children:"Success"}),e.jsxs("div",{className:"color-row",children:[e.jsx("input",{type:"color",className:"input color-input",value:i.theme.success,onChange:f=>k({success:f.target.value}),"aria-label":"Success color"}),e.jsx("input",{type:"text",className:"input",value:i.theme.success,onChange:f=>k({success:f.target.value})})]})]}),e.jsxs("div",{className:"field","data-setting-id":"theme.warning",children:[e.jsx("label",{className:"field-label",children:"Warning"}),e.jsxs("div",{className:"color-row",children:[e.jsx("input",{type:"color",className:"input color-input",value:i.theme.warning,onChange:f=>k({warning:f.target.value}),"aria-label":"Warning color"}),e.jsx("input",{type:"text",className:"input",value:i.theme.warning,onChange:f=>k({warning:f.target.value})})]})]}),e.jsxs("div",{className:"field","data-setting-id":"theme.error",children:[e.jsx("label",{className:"field-label",children:"Error"}),e.jsxs("div",{className:"color-row",children:[e.jsx("input",{type:"color",className:"input color-input",value:i.theme.error,onChange:f=>k({error:f.target.value}),"aria-label":"Error color"}),e.jsx("input",{type:"text",className:"input",value:i.theme.error,onChange:f=>k({error:f.target.value})})]})]}),e.jsxs("div",{className:"field","data-setting-id":"theme.info",children:[e.jsx("label",{className:"field-label",children:"Info"}),e.jsxs("div",{className:"color-row",children:[e.jsx("input",{type:"color",className:"input color-input",value:i.theme.info,onChange:f=>k({info:f.target.value}),"aria-label":"Info color"}),e.jsx("input",{type:"text",className:"input",value:i.theme.info,onChange:f=>k({info:f.target.value})})]})]})]}),e.jsxs("div",{className:"field","data-setting-id":"theme.fontFamily",children:[e.jsx("label",{className:"field-label",children:"Font family"}),e.jsx("select",{className:"select",value:i.theme.fontFamily,onChange:f=>k({fontFamily:f.target.value}),children:al.map(f=>e.jsx("option",{value:f,children:f},f))})]}),e.jsxs("div",{className:"field","data-setting-id":"theme.fontSize",children:[e.jsxs("label",{className:"field-label",children:["Font size: ",i.theme.fontSize,"px"]}),e.jsx("input",{type:"range",min:12,max:20,value:i.theme.fontSize,onChange:f=>k({fontSize:Number(f.target.value)})})]}),e.jsxs("label",{className:"checkbox-row","data-setting-id":"theme.compactMode",children:[e.jsx("input",{type:"checkbox",checked:i.theme.compactMode,onChange:f=>k({compactMode:f.target.checked})}),e.jsx("span",{children:"Compact mode (denser UI)"})]}),e.jsxs("label",{className:"checkbox-row","data-setting-id":"theme.animations",children:[e.jsx("input",{type:"checkbox",checked:i.theme.animations,onChange:f=>k({animations:f.target.checked})}),e.jsx("span",{children:"Enable animations"})]})]})}),e.jsx("div",{"data-section":"updates",style:{display:m===null||m==="updates"?"block":"none"},children:e.jsx(rl,{})}),e.jsx("div",{"data-section":"layout",style:{display:m===null||m==="layout"?"block":"none"},children:e.jsxs(se,{id:"settings-layout","data-section":"layout",children:[e.jsxs(ne,{children:[e.jsx(Ga,{size:14})," UI layout"]}),e.jsx(re,{children:"Choose how the dashboard's navigation is presented."}),e.jsx("div",{className:"layout-row","data-setting-id":"ui.layout",children:ll.map(f=>e.jsx("button",{type:"button",className:Z("layout-card",i.ui.layout===f.id&&"layout-card-active"),onClick:()=>S({layout:f.id}),children:e.jsx("span",{className:"layout-card-label",children:f.label})},f.id))}),e.jsxs("label",{className:"checkbox-row","data-setting-id":"ui.showHeader",children:[e.jsx("input",{type:"checkbox",checked:i.ui.showHeader,onChange:f=>S({showHeader:f.target.checked})}),e.jsx("span",{children:"Show header"})]}),e.jsxs("label",{className:"checkbox-row","data-setting-id":"ui.showStatusBar",children:[e.jsx("input",{type:"checkbox",checked:i.ui.showStatusBar,onChange:f=>S({showStatusBar:f.target.checked})}),e.jsx("span",{children:"Show status bar"})]}),e.jsxs("div",{className:"field","data-setting-id":"ui.defaultTab",children:[e.jsx("label",{className:"field-label",children:"Default tab"}),e.jsxs("select",{className:"select",value:i.ui.defaultTab,onChange:f=>S({defaultTab:f.target.value}),children:[e.jsx("option",{value:"overview",children:"Overview"}),e.jsx("option",{value:"chat",children:"Chat"}),e.jsx("option",{value:"agents",children:"Agents"}),e.jsx("option",{value:"artifacts",children:"Plans"}),e.jsx("option",{value:"projects",children:"Projects"}),e.jsx("option",{value:"tasks",children:"Tasks"}),e.jsx("option",{value:"config",children:"Config"}),e.jsx("option",{value:"settings",children:"Settings"}),e.jsx("option",{value:"mods",children:"Mods"}),e.jsx("option",{value:"schedules",children:"Schedules"})]})]})]})}),e.jsx("div",{"data-section":"general",style:{display:m===null||m==="general"?"block":"none"},children:e.jsxs(se,{id:"settings-general","data-section":"general",children:[e.jsx(ne,{children:"General"}),e.jsx(re,{children:"Default agent + model override."}),e.jsxs("div",{className:"field","data-setting-id":"defaultAgent",children:[e.jsx("label",{className:"field-label",htmlFor:"set-default-agent",children:"Default agent"}),e.jsx("input",{id:"set-default-agent",className:"input",type:"text",placeholder:"e.g. odin",value:i.defaultAgent||"",onChange:f=>b("defaultAgent",f.target.value)})]}),e.jsxs("div",{className:"field","data-setting-id":"defaultModel",children:[e.jsx("label",{className:"field-label",htmlFor:"set-default-model",children:"Model override"}),e.jsx("input",{id:"set-default-model",className:"input",type:"text",placeholder:"(leave empty for provider default)",value:i.defaultModel||"",onChange:f=>b("defaultModel",f.target.value)})]})]})}),e.jsx("div",{"data-section":"service",style:{display:m===null||m==="service"?"block":"none"},children:e.jsxs(se,{id:"settings-service","data-section":"service",children:[e.jsxs(ne,{children:[e.jsx(Ye,{size:14})," Service"]}),e.jsx(re,{children:"Background daemon that runs schedules."}),e.jsx("div",{"data-setting-id":"service.enabled",children:u?e.jsxs("div",{className:"service-card",children:[e.jsxs("p",{children:["Status: ",e.jsx("strong",{children:u!=null&&u.settings.enabled?"enabled":"disabled"})," ","· Tailscale installed: ",e.jsx("strong",{children:u.installed?"yes":"no"})," ","· authenticated: ",e.jsx("strong",{children:u.authenticated?"yes":"no"})]}),e.jsxs("p",{className:"muted",children:["Use ",e.jsx("code",{children:"bizar service start"})," / ",e.jsx("code",{children:"bizar service stop"})," in your terminal to control the daemon."]})]}):e.jsx("p",{className:"muted",children:"Loading service status…"})})]})}),e.jsx("div",{"data-section":"tailscale",style:{display:m===null||m==="tailscale"?"block":"none"},children:e.jsxs(se,{id:"settings-tailscale","data-section":"tailscale",children:[e.jsxs(ne,{children:[e.jsx(js,{size:14})," Tailscale serve"]}),e.jsx(re,{children:"Expose the dashboard over your Tailscale network."}),u?e.jsxs(e.Fragment,{children:[e.jsxs("p",{children:["Installed: ",e.jsx("strong",{children:u.installed?"yes":"no"})," ",u.version&&e.jsxs("span",{className:"muted",children:["(",u.version,")"]})]}),e.jsxs("p",{children:["Authenticated: ",e.jsx("strong",{children:u.authenticated?"yes":"no"})]}),e.jsxs("p",{children:["Serve enabled: ",e.jsx("strong",{children:u.settings.enabled?"yes":"no"})]}),e.jsxs("div",{className:"task-form-row",children:[e.jsxs("div",{className:"task-form-field",children:[e.jsx("label",{className:"field-label",children:"Port"}),e.jsx("input",{type:"number",className:"input",value:h.port,onChange:f=>c(_=>({..._,port:Number(f.target.value)||4321}))})]}),e.jsxs("div",{className:"task-form-field",children:[e.jsx("label",{className:"field-label",children:"Use HTTPS"}),e.jsx("input",{type:"checkbox",checked:h.https,onChange:f=>c(_=>({..._,https:f.target.checked}))})]})]}),e.jsx(z,{variant:"primary",onClick:q,children:u.settings.enabled?"Disable serve":"Enable serve"})]}):e.jsx("p",{className:"muted",children:"Loading Tailscale status…"})]})}),e.jsx("div",{"data-section":"notifications",style:{display:m===null||m==="notifications"?"block":"none"},children:e.jsxs(se,{id:"settings-notifications","data-section":"notifications",children:[e.jsx(ne,{children:"Notifications"}),e.jsx(re,{children:"Toast triggers inside the dashboard."}),e.jsxs("label",{className:"checkbox-row","data-setting-id":"notifications.onAgentComplete",children:[e.jsx("input",{type:"checkbox",checked:!!i.notifications.onAgentComplete,onChange:f=>v({onAgentComplete:f.target.checked})}),e.jsx("span",{children:"Notify when an agent invocation completes"})]}),e.jsxs("label",{className:"checkbox-row","data-setting-id":"notifications.onPlanApproval",children:[e.jsx("input",{type:"checkbox",checked:!!i.notifications.onPlanApproval,onChange:f=>v({onPlanApproval:f.target.checked})}),e.jsx("span",{children:"Notify when a plan needs approval"})]})]})}),e.jsx("div",{"data-section":"auth",style:{display:m===null||m==="auth"?"block":"none"},children:e.jsxs(se,{id:"settings-auth","data-section":"auth",children:[e.jsxs(ne,{children:[e.jsx(Za,{size:14})," Authentication"]}),e.jsx(re,{children:"Localhost and Tailscale browser access are auto-trusted via loopback. A bearer token is still available for non-loopback clients and forced-auth mode."}),e.jsxs("div",{className:"field","data-setting-id":"auth.status",children:[e.jsx("label",{className:"field-label",children:"Server status"}),e.jsxs("p",{style:{margin:"4px 0"},children:["Auth required:"," ",e.jsx("strong",{children:D?D.required?"yes":"no":"probing…"})]}),e.jsxs("p",{style:{margin:"4px 0"},children:["Connection:"," ",e.jsx("strong",{children:D?D.loopback?"loopback (auto-trusted)":"remote":"probing…"})]}),e.jsxs("p",{style:{margin:"4px 0"},children:["Peer address:"," ",D!=null&&D.peer?e.jsx("code",{children:D.peer}):e.jsx("span",{className:"muted",children:"probing…"})]}),e.jsxs("p",{className:"muted",style:{fontSize:12,margin:"4px 0"},children:["Localhost and Tailscale browser access are auto-trusted because the dashboard sees a loopback peer. Paste a token only for non-loopback API clients/scripts, or if you force auth for every connection with"," ",e.jsx("code",{children:"BIZAR_DASHBOARD_REQUIRE_AUTH=1"}),"."]}),e.jsxs("p",{className:"muted",style:{fontSize:12,margin:"4px 0"},children:["Dashboard tokens are generated on first boot and saved to"," ",e.jsx("code",{children:"~/.config/bizar/dashboard-secret"})," (mode 0600)."]})]}),e.jsxs("div",{className:"field","data-setting-id":"auth.token",children:[e.jsx("label",{className:"field-label",children:"Token (this browser)"}),e.jsx("input",{type:"password",className:"input mono",value:N,onChange:f=>E(f.target.value),placeholder:"Paste token from server stderr or another browser",spellCheck:!1,autoComplete:"off"}),e.jsxs("div",{className:"task-form-row",style:{marginTop:8},children:[e.jsxs(z,{variant:"secondary",size:"sm",onClick:Q,children:[e.jsx(Fa,{size:14})," Save token"]}),e.jsxs(z,{variant:"ghost",size:"sm",onClick:ue,children:[e.jsx(Hs,{size:14})," Reveal & copy server token"]}),e.jsxs(z,{variant:"ghost",size:"sm",onClick:B,children:[e.jsx(Qs,{size:14})," Regenerate"]})]}),te?e.jsxs("p",{className:"muted",style:{fontSize:12,marginTop:8},children:["Last revealed token (one-time): ",e.jsx("code",{className:"mono",children:te})]}):null,e.jsx("p",{className:"muted",style:{fontSize:12,marginTop:8},children:"Regenerating invalidates the current token immediately. Anything still using the old token will see 401 until it's updated."})]})]})}),e.jsx("div",{"data-section":"agents",style:{display:m===null||m==="agents"?"block":"none"},children:e.jsxs(se,{id:"settings-agents","data-section":"agents",children:[e.jsxs(ne,{children:[e.jsx(Ye,{size:14})," Agent Behavior"]}),e.jsx(re,{children:"Limits and timeouts for background agent dispatch."}),e.jsxs("div",{className:"form-row",children:[e.jsxs("label",{htmlFor:"agents-maxParallel",children:["Max parallel agents",e.jsx("span",{className:"meta-badge",children:"default: 6"})]}),e.jsx("input",{id:"agents-maxParallel",type:"number",min:1,max:20,value:((j=i.agents)==null?void 0:j.maxParallel)??6,onChange:f=>y({maxParallel:Math.max(1,Math.min(20,parseInt(f.target.value,10)||6))})})]}),e.jsxs("div",{className:"form-row",children:[e.jsxs("label",{htmlFor:"agents-stuckThresholdMs",children:["Stuck threshold (ms)",e.jsx("span",{className:"meta-badge",children:"default: 600000 (10 min)"})]}),e.jsx("input",{id:"agents-stuckThresholdMs",type:"number",min:6e4,max:36e5,step:6e4,value:((C=i.agents)==null?void 0:C.stuckThresholdMs)??6e5,onChange:f=>y({stuckThresholdMs:Math.max(6e4,Math.min(36e5,parseInt(f.target.value,10)||6e5))})})]}),e.jsxs("label",{className:"checkbox-row","data-setting-id":"agents.autoRestart",children:[e.jsx("input",{type:"checkbox",checked:!!((L=i.agents)!=null&&L.autoRestart),onChange:f=>y({autoRestart:f.target.checked})}),e.jsx("span",{children:"Auto-restart stuck agents"})]})]})}),e.jsx("div",{"data-section":"dashboard",style:{display:m===null||m==="dashboard"?"block":"none"},children:e.jsxs(se,{id:"settings-dashboard","data-section":"dashboard",children:[e.jsxs(ne,{children:[e.jsx(is,{size:14})," Dashboard"]}),e.jsxs(re,{children:["Controls how ",e.jsx("code",{children:"bizar"})," starts up."]}),e.jsxs("label",{className:"checkbox-row","data-setting-id":"dashboard.autoLaunchWeb",children:[e.jsx("input",{type:"checkbox",checked:i.dashboard.autoLaunchWeb!==!1,onChange:f=>R({autoLaunchWeb:f.target.checked})}),e.jsx("span",{children:"Auto-launch web UI alongside TUI"})]}),e.jsxs("div",{className:"field","data-setting-id":"dashboard.projectsDirectory",style:{marginTop:"var(--space-4)"},children:[e.jsx("label",{className:"field-label",htmlFor:"set-projects-directory",children:"Projects directory"}),e.jsx("input",{id:"set-projects-directory",className:"input",type:"text",placeholder:"/home/user/projects",value:i.dashboard.projectsDirectory??"",onChange:f=>R({projectsDirectory:f.target.value})}),e.jsx("p",{className:"field-help",children:"New projects created via the dashboard will land here, and existing project directories inside this folder are auto-recognized on startup."}),i.dashboard.projectsDirectory&&e.jsxs(e.Fragment,{children:[!/^\/|^[A-Za-z]:/.test(i.dashboard.projectsDirectory)&&e.jsx("p",{style:{color:"var(--warning)",fontSize:11,marginTop:4},children:"Path should be absolute (start with / on Linux/Mac, or a drive letter on Windows)."}),i.dashboard.projectsDirectory.includes("..")&&e.jsx("p",{style:{color:"var(--error)",fontSize:11,marginTop:4},children:"Path traversal not allowed — this will be rejected server-side."})]})]}),e.jsxs("div",{className:"field","data-setting-id":"dashboard.allowedRoots",style:{marginTop:"var(--space-4)"},children:[e.jsxs("label",{className:"field-label",htmlFor:"set-allowed-roots",children:["Additional allowed roots ",e.jsx("span",{className:"muted",children:"(advanced)"})]}),e.jsx("textarea",{id:"set-allowed-roots",className:"textarea",rows:4,placeholder:`/workspace
324
- /srv/projects`,value:(i.dashboard.allowedRoots??[]).join(`
325
- `),onChange:f=>{const _=f.target.value.split(`
326
- `).map(ee=>ee.trim()).filter(Boolean);R({allowedRoots:_})}}),e.jsx("p",{className:"field-help",children:"Optional. Add filesystem roots beyond your home directory that the file browser and project scanner can access. Each path must be inside your home directory. One per line."}),(()=>{const f=(i.dashboard.allowedRoots??[]).join(`
327
- `).split(`
328
- `),_=[];return f.forEach((ee,P)=>{ee.trim()&&(/^\/|^[A-Za-z]:/.test(ee)||_.push({key:`noabs-${P}`,msg:e.jsxs("p",{style:{color:"var(--warning)",fontSize:11,marginTop:2},children:["Line ",P+1,': "',ee,'" — should be absolute (start with / or a drive letter).']})}),ee.includes("..")&&_.push({key:`dots-${P}`,msg:e.jsxs("p",{style:{color:"var(--error)",fontSize:11,marginTop:2},children:["Line ",P+1,': "',ee,`" — contains '..' (server will reject this).`]})}))}),_.map(ee=>ee.msg)})()]})]})}),e.jsx("div",{"data-section":"background",style:{display:m===null||m==="background"?"block":"none"},children:e.jsxs(se,{id:"settings-background","data-section":"background",children:[e.jsxs(ne,{children:[e.jsx(Ye,{size:14})," Background Agents"]}),e.jsx(re,{children:"Tune plugin options. Changes take effect on next plugin restart."}),e.jsxs("div",{className:"form-row",children:[e.jsxs("label",{htmlFor:"bg-maxConcurrent",children:["Max concurrent instances",e.jsx("span",{className:"meta-badge",children:"default: 8"})]}),e.jsx("input",{id:"bg-maxConcurrent",type:"number",min:1,max:32,value:x.maxConcurrentInstances??8,onChange:f=>M(_=>({..._,maxConcurrentInstances:Math.max(1,Math.min(32,parseInt(f.target.value,10)||8))}))}),e.jsxs("small",{className:"muted",children:["Plugin option: ",e.jsx("code",{children:"maxConcurrentInstances"})]})]}),e.jsxs("div",{className:"form-row",children:[e.jsxs("label",{htmlFor:"bg-toolCallCap",children:["Tool-call cap",e.jsx("span",{className:"meta-badge",children:"default: 500"})]}),e.jsx("input",{id:"bg-toolCallCap",type:"number",min:1,max:5e3,value:x.backgroundToolCallCap??500,onChange:f=>M(_=>({..._,backgroundToolCallCap:Math.max(1,Math.min(5e3,parseInt(f.target.value,10)||500))}))}),e.jsxs("small",{className:"muted",children:["Plugin option: ",e.jsx("code",{children:"backgroundToolCallCap"})]})]}),e.jsxs("div",{className:"form-row",children:[e.jsxs("label",{htmlFor:"bg-stallTimeout",children:["Stall timeout (ms)",e.jsx("span",{className:"meta-badge",children:"default: 180000"})]}),e.jsx("input",{id:"bg-stallTimeout",type:"number",min:1e4,max:6e5,step:1e3,value:x.backgroundStallTimeoutMs??18e4,onChange:f=>M(_=>({..._,backgroundStallTimeoutMs:Math.max(1e4,Math.min(6e5,parseInt(f.target.value,10)||18e4))}))}),e.jsxs("small",{className:"muted",children:["Plugin option: ",e.jsx("code",{children:"backgroundStallTimeoutMs"})]})]}),e.jsxs("div",{className:"form-row",children:[e.jsxs("label",{htmlFor:"bg-thinkingLoopTimeout",children:["Thinking-loop timeout (ms)",e.jsx("span",{className:"meta-badge",children:"default: 300000"})]}),e.jsx("input",{id:"bg-thinkingLoopTimeout",type:"number",min:3e4,max:9e5,step:1e3,value:x.backgroundThinkingLoopTimeoutMs??3e5,onChange:f=>M(_=>({..._,backgroundThinkingLoopTimeoutMs:Math.max(3e4,Math.min(9e5,parseInt(f.target.value,10)||3e5))}))}),e.jsxs("small",{className:"muted",children:["Plugin option: ",e.jsx("code",{children:"backgroundThinkingLoopTimeoutMs"})]})]}),e.jsxs("div",{className:"form-row",children:[e.jsxs("label",{htmlFor:"bg-maxInterventions",children:["Max interventions",e.jsx("span",{className:"meta-badge",children:"default: 1"})]}),e.jsx("input",{id:"bg-maxInterventions",type:"number",min:1,max:3,value:x.backgroundMaxInterventions??1,onChange:f=>M(_=>({..._,backgroundMaxInterventions:Math.max(1,Math.min(3,parseInt(f.target.value,10)||1))}))}),e.jsxs("small",{className:"muted",children:["Plugin option: ",e.jsx("code",{children:"backgroundMaxInterventions"})]})]}),e.jsxs("div",{className:"form-row",children:[e.jsxs(z,{variant:"secondary",size:"sm",onClick:async()=>{try{await A.put("/settings/plugin-options",x),t.success("Saved — restart opencode for changes to take effect.")}catch(f){t.error(`Save failed: ${f.message}`)}},children:[e.jsx(as,{size:14})," Save plugin options"]}),e.jsx(z,{variant:"secondary",size:"sm",onClick:async()=>{try{const _=await(await fetch("/api/background/cleanup",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({maxAgeDays:7})})).json();t.success(`Cleaned up ${_.deleted} old instances.`)}catch(f){t.error(`Cleanup failed: ${f.message}`)}},children:"Cleanup old instances (>7 days)"})]}),e.jsx("div",{className:"form-row",children:e.jsxs("small",{children:["Plugin options are read at startup. Save changes and run ",e.jsx("code",{children:"bizar update"})," to apply."]})})]})})]}),e.jsx("div",{"data-section":"system-llm",style:{display:m===null||m==="system-llm"?"block":"none"},children:e.jsxs(se,{id:"settings-system-llm","data-section":"system-llm",children:[e.jsxs(ne,{children:[e.jsx(Me,{size:14})," System LLM API"]}),e.jsx(re,{children:"Configures the LLM used for automatic title generation, prompt enhancement, summarization, and other system-level calls."}),e.jsxs("label",{className:"checkbox-row","data-setting-id":"systemLlm.enabled",children:[e.jsx("input",{type:"checkbox",checked:!!((F=i.systemLlm)!=null&&F.enabled),onChange:f=>{const _=i.systemLlm||{enabled:!0,provider:"opencode",model:"opencode/deepseek-v4-flash-free"};b("systemLlm",{..._,enabled:f.target.checked})}}),e.jsx("span",{children:"Enable system LLM calls"})]}),e.jsxs("div",{className:"field","data-setting-id":"systemLlm.provider",style:{marginTop:"var(--space-3)"},children:[e.jsx("label",{className:"field-label",htmlFor:"set-system-llm-provider",children:"Provider"}),e.jsxs("select",{id:"set-system-llm-provider",className:"select",value:((J=i.systemLlm)==null?void 0:J.provider)||"opencode",onChange:f=>{const _=i.systemLlm||{enabled:!0,provider:"opencode",model:"opencode/deepseek-v4-flash-free"};b("systemLlm",{..._,provider:f.target.value})},children:[e.jsx("option",{value:"opencode",children:"Opencode"}),e.jsx("option",{value:"openrouter",children:"OpenRouter"}),e.jsx("option",{value:"minimax",children:"MiniMax"})]})]}),e.jsxs("div",{className:"field","data-setting-id":"systemLlm.model",children:[e.jsx("label",{className:"field-label",htmlFor:"set-system-llm-model",children:"Model"}),e.jsx("input",{id:"set-system-llm-model",className:"input mono",type:"text",placeholder:"opencode/deepseek-v4-flash-free",value:((V=i.systemLlm)==null?void 0:V.model)||"opencode/deepseek-v4-flash-free",onChange:f=>{const _=i.systemLlm||{enabled:!0,provider:"opencode",model:"opencode/deepseek-v4-flash-free"};b("systemLlm",{..._,model:f.target.value})}}),e.jsxs("p",{className:"field-help",children:["The API key is read from ",e.jsx("code",{children:"auth.json"})," for the selected provider. Leave the default model for best results."]})]}),e.jsxs("div",{style:{marginTop:"var(--space-4)"},children:[e.jsx("h4",{style:{margin:"0 0 var(--space-2)"},children:"Features using this API"}),e.jsxs("ul",{className:"settings-feature-list",style:{margin:0,paddingLeft:"var(--space-4)",lineHeight:1.8},children:[e.jsx("li",{children:"Auto-title generation for new chat sessions"}),e.jsx("li",{children:"Auto-title generation for new tasks"}),e.jsx("li",{children:'"Enhance prompt" button in the task input'}),e.jsx("li",{children:'"Enhance prompt" button in the chat composer'}),e.jsx("li",{className:"muted",style:{fontSize:12},children:"Future: summarization, name generation, and more"})]})]})]})}),e.jsx(il,{}),e.jsx("div",{style:{display:m===null||m==="activity-log"?"block":"none"},children:e.jsx("div",{"data-section":"activity-log",style:{display:m===null||m==="activity-log"?"block":"none"},children:e.jsx("section",{id:"settings-activity-log","data-section":"activity-log",className:"settings-section-wrap",children:e.jsx(ol,{})})})}),e.jsx("div",{style:{display:m===null||m==="about"?"block":"none"},children:e.jsx("div",{"data-section":"about",style:{display:m===null||m==="about"?"block":"none"},children:e.jsxs(se,{id:"settings-about","data-section":"about",children:[e.jsxs(ne,{children:[e.jsx(bs,{size:14})," About"]}),e.jsx(re,{children:"Build metadata."}),e.jsxs("dl",{className:"about-table",children:[e.jsx("dt",{children:"Version"}),e.jsx("dd",{className:"mono",children:X.version}),e.jsx("dt",{children:"Homepage"}),e.jsx("dd",{children:e.jsx("a",{href:X.homepage,target:"_blank",rel:"noopener noreferrer",children:X.homepage})}),e.jsx("dt",{children:"License"}),e.jsx("dd",{children:X.license})]})]})})})]})}function ol(){const s=he(),[a,t]=r.useState([]),[i,n]=r.useState(new Set),[d,o]=r.useState(!0),[l,p]=r.useState(""),[u,g]=r.useState(!0),h=r.useCallback(async()=>{o(!0);try{const[S,b]=await Promise.all([A.get("/activity"),A.get("/activity/hidden")]);t(Array.isArray(S.items)?S.items:[]),n(new Set(b.hidden||[]))}catch(S){s.error(`Load failed: ${S.message}`)}finally{o(!1)}},[s]);r.useEffect(()=>{h()},[h]);const c=(S,b)=>{const v=`${S.kind||""}|${S.ts||""}|${S.slug||""}|${b}`;let y=0;for(let T=0;T<v.length;T++)y=(y<<5)-y+v.charCodeAt(T)|0;return Math.abs(y).toString(16).padStart(8,"0").slice(0,16)},x=async()=>{try{await A.del("/activity/hide"),n(new Set),s.success("All hidden activity restored.")}catch(S){s.error(`Restore failed: ${S.message}`)}},M=async S=>{try{await A.del(`/activity/hide/${encodeURIComponent(S)}`);const b=new Set(i);b.delete(S),n(b)}catch(b){s.error(`Restore failed: ${b.message}`)}},k=a.filter((S,b)=>{const v=c(S,b);if(!u&&i.has(v))return!1;if(!l)return!0;const y=l.toLowerCase();return[S.kind,S.slug,S.message].some(T=>typeof T=="string"&&T.toLowerCase().includes(y))});return e.jsxs(se,{id:"settings-diagnostics","data-section":"diagnostics",children:[e.jsxs(ne,{children:[e.jsx(ze,{size:14})," Activity log",e.jsxs("span",{className:"muted",style:{fontWeight:400,marginLeft:8,fontSize:12},children:[a.length," total · ",i.size," hidden"]}),e.jsx(z,{variant:"ghost",size:"sm",style:{marginLeft:"auto"},onClick:h,title:"Reload",children:e.jsx(de,{size:12})})]}),e.jsxs(re,{children:["Full history from ",e.jsx("code",{children:"~/.bizar/activity.log"}),". Hiding an item in the Overview only hides it there — the entry stays here."]}),e.jsxs("div",{className:"activity-log-toolbar",children:[e.jsxs("div",{className:"activity-log-search",children:[e.jsx(Oe,{size:12}),e.jsx("input",{type:"text",className:"input",placeholder:"Filter by kind, slug, or message…",value:l,onChange:S=>p(S.target.value)})]}),e.jsxs("label",{className:"activity-log-toggle",children:[e.jsx("input",{type:"checkbox",checked:u,onChange:S=>g(S.target.checked)}),"Show hidden"]}),e.jsxs(z,{variant:"ghost",size:"sm",disabled:i.size===0,onClick:x,title:"Restore all hidden items to the Overview",children:[e.jsx(ns,{size:12})," Restore all"]})]}),d?e.jsx("div",{className:"muted",style:{padding:"12px 0",fontSize:12},children:"Loading…"}):k.length===0?e.jsx("div",{className:"muted",style:{padding:"12px 0",fontSize:12},children:a.length===0?"No activity yet.":"No items match the current filter."}):e.jsxs("div",{className:"activity-log-table-wrap",children:[e.jsxs("table",{className:"activity-log-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Kind"}),e.jsx("th",{children:"Detail"}),e.jsx("th",{children:"Time"}),e.jsx("th",{})]})}),e.jsx("tbody",{children:k.slice(0,200).map((S,b)=>{const v=c(S,b),y=i.has(v);return e.jsxs("tr",{className:Z(y&&"activity-log-row-hidden"),children:[e.jsx("td",{className:"activity-log-kind",children:S.kind||"activity"}),e.jsx("td",{className:"activity-log-detail",children:S.message||S.slug||"—"}),e.jsx("td",{className:"activity-log-time mono",children:S.ts?new Date(S.ts).toLocaleString():"—"}),e.jsx("td",{children:y?e.jsx(z,{variant:"ghost",size:"sm",onClick:()=>M(v),title:"Restore to Overview",children:e.jsx(ns,{size:12})}):e.jsx("span",{className:"activity-log-state-tag",children:"shown"})})]},`${S.ts}-${b}`)})})]}),k.length>200&&e.jsxs("div",{className:"muted",style:{fontSize:11,padding:"8px 0"},children:["Showing first 200 of ",k.length,"."]})]})]})}function dl({snapshot:s,refreshSnapshot:a}){const t=he(),i=ke(),[n,d]=r.useState(Array.isArray(s.mods)?s.mods:[]),[o,l]=r.useState(!0),[p,u]=r.useState(null),[g,h]=r.useState([]),[c,x]=r.useState(null),[M,k]=r.useState(!1),[S,b]=r.useState(null),[v,y]=r.useState(!1),[T,m]=r.useState({}),I=async()=>{var N,E,D;y(!0);try{const H=await A.get("/mods/registry");b({source:((N=H.registry)==null?void 0:N.source)||"",version:(E=H.registry)==null?void 0:E.version,updatedAt:(D=H.registry)==null?void 0:D.updatedAt,mods:H.mods||[]})}catch(H){b({source:"",mods:[],error:H.message})}finally{y(!1)}},U=async N=>{m(E=>({...E,[N]:!0}));try{const E=await A.post("/mods",{id:N});d(D=>[...D.filter(H=>H.id!==E.id),E]),t.success(`Mod "${E.id}" installed from registry.`),await a()}catch(E){t.error(`Install failed: ${E.message}`)}finally{m(E=>({...E,[N]:!1}))}},R=async(N,E=!1)=>{m(D=>({...D,[N]:!0}));try{const D=await A.post(`/mods/${encodeURIComponent(N)}/upgrade`,{backup:E});d(te=>[...te.filter(ie=>ie.id!==D.mod.id),D.mod]);const H=D.backupPath?` (backup at ${D.backupPath})`:"";t.success(`Mod "${N}" upgraded v${D.from} → v${D.to}${H}.`),await a()}catch(D){t.error(`Upgrade failed: ${D.message}`)}finally{m(D=>({...D,[N]:!1}))}},G=async()=>{try{const N=await A.get("/mods");d(N.mods||[]);try{const E=await A.get("/mods/views");h(E.views||[])}catch{h([])}}catch(N){t.error(`Mods load failed: ${N.message}`)}finally{l(!1)}};r.useEffect(()=>{G()},[]),r.useEffect(()=>{Array.isArray(s.mods)&&s.mods!==n&&d(s.mods)},[s.mods]);const W=()=>{let N=null;i.open({title:"Install mod",children:e.jsxs("div",{children:[e.jsxs("p",{className:"muted",children:["Provide the absolute path to a mod folder (one that contains a ",e.jsx("code",{children:"mod.json"}),"). The folder will be copied to"," ",e.jsx("code",{children:"~/.config/bizar/mods/<id>/"}),"."]}),e.jsx("label",{className:"field-label",children:"Path"}),e.jsx("input",{ref:E=>N=E,className:"input",type:"text",placeholder:"/path/to/my-mod",autoFocus:!0})]}),footer:e.jsxs("div",{className:"modal-footer-actions",children:[e.jsx(z,{variant:"ghost",onClick:()=>i.close(),children:"Cancel"}),e.jsx(z,{variant:"primary",onClick:async()=>{const E=((N==null?void 0:N.value)||"").trim();if(!E){t.warning("Path is required.");return}try{const D=await A.post("/mods",{path:E});d(H=>[...H,D]),t.success(`Mod "${D.id}" installed.`),i.close(),await a()}catch(D){t.error(`Install failed: ${D.message}`)}},children:"Install"})]})})},$=async N=>{if(confirm(`Uninstall mod "${N}"? This removes the folder from ~/.config/bizar/mods/.`))try{await A.del(`/mods/${encodeURIComponent(N)}`),d(E=>E.filter(D=>D.id!==N)),p===N&&u(null),t.success("Mod uninstalled.")}catch(E){t.error(`Uninstall failed: ${E.message}`)}},q=async N=>{try{const E=await A.put(`/mods/${encodeURIComponent(N.id)}`,{enabled:!N.enabled});d(D=>D.map(H=>H.id===N.id?E:H)),t.success(`Mod ${E.enabled?"enabled":"disabled"}.`)}catch(E){t.error(`Toggle failed: ${E.message}`)}},X=n.find(N=>N.id===p)||null;return o?e.jsx("div",{className:"view-loading",children:e.jsx(ge,{size:"lg"})}):e.jsxs("div",{className:"view view-mods",children:[e.jsxs("header",{className:"view-header",children:[e.jsxs("div",{className:"view-header-text",children:[e.jsxs("h2",{className:"view-title",children:[e.jsx(fs,{size:18})," Mods (",n.length,")"]}),e.jsxs("p",{className:"view-subtitle",children:["Extensions installed in ",e.jsx("code",{children:"~/.config/bizar/mods/"}),". Mods can add agents, commands, routes, and views."]})]}),e.jsxs("div",{className:"view-actions",children:[e.jsxs(z,{variant:"secondary",size:"sm",onClick:G,children:[e.jsx(de,{size:14})," Refresh"]}),e.jsxs(z,{variant:"primary",size:"sm",onClick:W,children:[e.jsx(je,{size:14})," Install mod"]})]})]}),n.length===0?e.jsx(Re,{icon:e.jsx(fs,{size:32}),title:"No mods installed",message:"Mods are folders with a mod.json. Install one to extend Bizar with custom agents, commands, and views."}):e.jsxs("div",{className:"mods-layout",children:[e.jsx("div",{className:"mods-list",children:n.map(N=>e.jsxs("div",{className:Z("mod-list-item",p===N.id&&"mod-list-item-active"),onClick:()=>u(N.id),children:[e.jsxs("div",{className:"mod-list-item-head",children:[e.jsxs("div",{children:[e.jsx("div",{className:"mod-list-item-name",children:N.name}),e.jsxs("div",{className:"mod-list-item-meta",children:["v",N.version," · ",N.type," · ",N.author]})]}),e.jsxs("div",{className:"mod-list-item-actions",onClick:E=>E.stopPropagation(),children:[e.jsx("button",{type:"button",className:"icon-btn","aria-label":"Toggle enabled",title:N.enabled?"Disable":"Enable",onClick:()=>q(N),children:e.jsx(Fs,{size:12})}),e.jsx("button",{type:"button",className:"icon-btn icon-btn-danger","aria-label":"Uninstall",title:"Uninstall",onClick:()=>$(N.id),children:e.jsx(be,{size:12})})]})]}),e.jsx("div",{className:"mod-list-item-desc ellipsis-2",title:N.description,children:N.description}),e.jsx("div",{className:"mod-list-item-status",children:e.jsx("span",{className:`mod-mini-pill ${N.enabled?"mod-mini-pill-on":"mod-mini-pill-off"}`,children:N.enabled?"enabled":"disabled"})})]},N.id))}),X&&e.jsx(hl,{mod:X})]}),e.jsxs(se,{className:"mods-registry-card",children:[e.jsxs("div",{className:"mods-registry-head",onClick:()=>{!S&&!v&&I(),k(N=>!N)},children:[e.jsx(is,{size:14}),e.jsx("span",{className:"mods-registry-title",children:"Mod registry"}),e.jsx("span",{className:"muted",style:{fontSize:11},children:S!=null&&S.mods?`${S.mods.length} available`:"click to browse"}),e.jsx("span",{className:"mods-registry-spacer"}),M?e.jsx(Ae,{size:14}):e.jsx(Ue,{size:14})]}),M&&e.jsx("div",{className:"mods-registry-body",children:v?e.jsx("div",{className:"muted",style:{padding:12,fontSize:12},children:"Loading registry…"}):S!=null&&S.error?e.jsxs("div",{className:"mods-registry-error",children:[e.jsx(gs,{size:12})," Could not load registry: ",S.error]}):!S||S.mods.length===0?e.jsx("div",{className:"muted",style:{padding:12,fontSize:12},children:"No mods listed in the registry yet."}):e.jsxs(e.Fragment,{children:[S.source&&e.jsxs("div",{className:"muted",style:{fontSize:11,marginBottom:8},children:["Source: ",e.jsx("code",{children:S.source})]}),e.jsx("div",{className:"mods-registry-grid",children:S.mods.map(N=>{const E=n.some(H=>H.id===N.id),D=!!T[N.id];return e.jsxs("div",{className:"mod-registry-card",children:[e.jsxs("div",{className:"mod-registry-card-head",children:[e.jsx("div",{className:"mod-registry-card-name",children:N.name}),N.latest&&e.jsxs("span",{className:Z("mod-registry-version",N.upgradeAvailable&&"mod-registry-version-upgrade"),children:["v",N.latest,N.upgradeAvailable?" ↑":""]})]}),N.description&&e.jsx("div",{className:"mod-registry-card-desc",children:N.description}),e.jsxs("div",{className:"mod-registry-card-meta",children:[N.author&&e.jsxs("span",{className:"muted",children:["by ",N.author]}),N.homepage&&e.jsx("a",{href:N.homepage,target:"_blank",rel:"noopener noreferrer",className:"mod-registry-link",children:"homepage"})]}),(N.permissions||[]).length>0&&e.jsxs("div",{className:"mod-registry-perms",children:[e.jsx(gs,{size:10}),(N.permissions||[]).slice(0,4).map(H=>e.jsx("span",{className:"mod-registry-perm",children:H},H)),(N.permissions||[]).length>4&&e.jsxs("span",{className:"mod-registry-perm-more",children:["+",N.permissions.length-4]})]}),e.jsxs("div",{className:"mod-registry-card-actions",children:[!E&&e.jsx(z,{variant:"primary",size:"sm",disabled:D,onClick:()=>U(N.id),title:"Install from registry",children:D?e.jsx(ge,{size:"sm"}):e.jsxs(e.Fragment,{children:[e.jsx(De,{size:12})," Install"]})}),E&&N.upgradeAvailable&&e.jsx(z,{variant:"primary",size:"sm",disabled:D,onClick:()=>R(N.id),title:`Upgrade from v${N.installedVersion||"?"} to v${N.upgradeAvailable}`,children:D?e.jsx(ge,{size:"sm"}):e.jsxs(e.Fragment,{children:[e.jsx(De,{size:12})," Upgrade to v",N.upgradeAvailable]})}),E&&!N.upgradeAvailable&&e.jsxs(z,{variant:"ghost",size:"sm",disabled:!0,title:`Installed v${N.installedVersion||"?"}`,children:["Installed v",N.installedVersion||"?"]})]})]},N.id)})})]})})]}),g.length>0&&e.jsxs(se,{className:"mod-views-hint",children:[e.jsxs(ne,{children:[e.jsx(is,{size:14})," Mod views"]}),e.jsxs(re,{children:[g.length," mod-supplied view",g.length===1?"":"s"," are now available in the sidebar navigation. Look for the ",e.jsx("strong",{children:"Mods"})," section at the bottom of the sidebar."]})]}),c&&e.jsxs("div",{className:"mod-iframe-panel",children:[e.jsxs("div",{className:"mod-iframe-header",children:[e.jsxs("span",{children:["Mod view — ",e.jsx("a",{href:c,target:"_blank",rel:"noreferrer",children:c})]}),e.jsx("button",{type:"button",className:"icon-btn","aria-label":"Close iframe",onClick:()=>x(null),children:e.jsx($e,{size:14})})]}),e.jsx("iframe",{src:c,className:"mod-iframe",title:"Mod view",sandbox:"allow-scripts allow-same-origin allow-forms allow-popups"})]})]})}function hl({mod:s}){const a=he(),[t,i]=r.useState(null),[n,d]=r.useState(!1),[o,l]=r.useState(!1),[p,u]=r.useState(null),g=async()=>{d(!0);try{const c=await A.get(`/mods/${s.id}/instructions`);i(c),l(!0)}catch(c){a.error(`Failed to load instructions: ${c.message}`)}finally{d(!1)}},h=async()=>{try{const c=await A.post(`/mods/${s.id}/instructions/reinstall`,{});a.success(`Reinstalled: ${c.counts.agents} agents, ${c.counts.commands} commands, ${c.counts.skills} skills, ${c.counts.instructions} instructions.`),await g()}catch(c){a.error(`Reinstall failed: ${c.message}`)}};return e.jsxs(se,{className:"mod-details",children:[e.jsxs(ne,{children:[e.jsx(ks,{size:14})," Mod details — ",s.name]}),e.jsx(re,{children:e.jsx("code",{children:s.path})}),e.jsxs("dl",{className:"env-table",children:[e.jsx("dt",{children:"ID"}),e.jsx("dd",{className:"mono",children:s.id}),e.jsx("dt",{children:"Version"}),e.jsx("dd",{className:"mono",children:s.version}),e.jsx("dt",{children:"Type"}),e.jsx("dd",{className:"mono",children:s.type}),e.jsx("dt",{children:"Author"}),e.jsx("dd",{className:"mono",children:s.author||"—"}),e.jsx("dt",{children:"Bizar"}),e.jsx("dd",{className:"mono",children:s.bizar||"*"}),e.jsx("dt",{children:"Enabled"}),e.jsx("dd",{children:s.enabled?"yes":"no"}),e.jsx("dt",{children:"Permissions"}),e.jsxs("dd",{children:[(s.permissions||[]).map(c=>e.jsx("span",{className:"tag",children:c},c)),(s.permissions||[]).length===0&&e.jsx("span",{className:"muted",children:"(none)"})]})]}),e.jsxs("div",{className:"mod-files",children:[e.jsx("div",{className:"muted",children:"Files"}),e.jsx("ul",{children:(s.files||[]).map(c=>e.jsxs("li",{children:[e.jsx("span",{className:"mod-file-cat",children:c.category}),e.jsx("span",{className:"mono",children:c.path})]},c.path))})]}),e.jsxs("div",{className:"mod-instructions",children:[e.jsxs("div",{className:"mod-instructions-head",onClick:()=>{!t&&!n&&g(),l(c=>!c)},children:[e.jsx(Ma,{size:14}),e.jsx("span",{children:"Installed instructions"}),e.jsx("span",{className:"muted",style:{fontSize:11},children:t?`${t.total} files`:"click to view"}),e.jsx("span",{className:"mod-instructions-spacer"}),o?e.jsx(Ae,{size:14}):e.jsx(Ue,{size:14})]}),o&&t&&e.jsxs("div",{className:"mod-instructions-body",children:[t.agents.length>0&&e.jsxs("div",{className:"mod-instructions-section",children:[e.jsxs("div",{className:"mod-instructions-section-title",children:[e.jsx(tn,{size:11})," Agents (",t.agents.length,")"]}),t.agents.map(c=>e.jsxs("div",{className:"mod-instructions-file",children:[e.jsxs("div",{className:"mod-instructions-file-head",onClick:()=>u(x=>x===c.filename?null:c.filename),children:[e.jsx("span",{className:"mono",children:c.filename}),e.jsxs("span",{className:"muted",style:{fontSize:10},children:["installed at ",c.fullPath]})]}),p===c.filename&&e.jsx("pre",{className:"mod-instructions-content",children:c.content||e.jsx("em",{className:"muted",children:"(file missing on disk)"})})]},c.filename))]}),t.commands.length>0&&e.jsxs("div",{className:"mod-instructions-section",children:[e.jsxs("div",{className:"mod-instructions-section-title",children:[e.jsx(ft,{size:11})," Commands (",t.commands.length,")"]}),t.commands.map(c=>e.jsxs("div",{className:"mod-instructions-file",children:[e.jsxs("div",{className:"mod-instructions-file-head",onClick:()=>u(x=>x===c.filename?null:c.filename),children:[e.jsx("span",{className:"mono",children:c.filename}),e.jsxs("span",{className:"muted",style:{fontSize:10},children:["installed at ",c.fullPath]})]}),p===c.filename&&e.jsx("pre",{className:"mod-instructions-content",children:c.content||e.jsx("em",{className:"muted",children:"(file missing on disk)"})})]},c.filename))]}),t.skills.length>0&&e.jsxs("div",{className:"mod-instructions-section",children:[e.jsxs("div",{className:"mod-instructions-section-title",children:[e.jsx(xa,{size:11})," Skills (",t.skills.length,")"]}),t.skills.map(c=>e.jsxs("div",{className:"mod-instructions-file",children:[e.jsxs("div",{className:"mod-instructions-file-head",onClick:()=>u(x=>x===c.name?null:c.name),children:[e.jsx("span",{className:"mono",children:c.name}),e.jsxs("span",{className:"muted",style:{fontSize:10},children:["installed at ",c.fullPath]})]}),p===c.name&&e.jsx("pre",{className:"mod-instructions-content",children:c.content||e.jsx("em",{className:"muted",children:"(file missing on disk)"})})]},c.name))]}),t.total===0&&e.jsxs("div",{className:"muted",style:{padding:8,fontSize:12},children:["This mod did not install any instruction files. Mods install instructions by shipping a top-level ",e.jsx("code",{children:"INSTRUCTIONS.md"}),", an ",e.jsx("code",{children:"agents/"})," directory, a ",e.jsx("code",{children:"commands/"})," directory, or a ",e.jsx("code",{children:"skills/"})," directory."]}),e.jsx("div",{className:"mod-instructions-actions",children:e.jsxs(z,{variant:"ghost",size:"sm",onClick:h,children:[e.jsx(de,{size:11})," Reinstall from mod folder"]})})]})]})]})}function ml({viewId:s,reloadKey:a,setActiveTab:t}){const i=he(),[n,d]=r.useState(null),[o,l]=r.useState(!0),[p,u]=r.useState(0);if(r.useEffect(()=>{let g=!1;return(async()=>{try{const h=await A.get("/mods/views");if(g)return;const c=(h.views||[]).find(x=>x.id===s);d(c||null)}catch(h){i.error(`Failed to load mod view: ${h.message}`)}finally{g||l(!1)}})(),()=>{g=!0}},[s,i]),o)return e.jsx(Re,{title:"Loading mod view…"});if(!n)return e.jsx(Re,{title:"Mod view not found",message:`No view with id "${s}" is currently installed.`,action:e.jsx(z,{onClick:()=>t("mods"),variant:"primary",size:"sm",children:"Open Mods"})});if(n.kind==="iframe"){const g=`/api/mods/${n.modId}/web/index.html?t=${p+(a||0)}`;return e.jsxs("div",{className:"mod-view-iframe-pane",children:[e.jsxs("div",{className:"mod-view-iframe-header",children:[e.jsxs("span",{className:"mod-view-iframe-label",children:[e.jsx(is,{size:14}),n.label,e.jsxs("span",{className:"muted",style:{fontSize:11,fontWeight:400},children:["by ",n.modId]})]}),e.jsxs("div",{className:"mod-view-iframe-actions",children:[e.jsxs(z,{variant:"ghost",size:"sm",onClick:()=>u(h=>h+1),title:"Reload this view",children:[e.jsx(de,{size:11})," Reload"]}),e.jsx("a",{href:g,target:"_blank",rel:"noopener noreferrer",className:"icon-btn",title:"Open in new tab",children:e.jsx(gt,{size:12})})]})]}),e.jsx("iframe",{src:g,className:"mod-view-iframe",title:n.label},p+(a||0))]})}if(n.component){const g=n.component,h=n.modId,c=r.lazy(()=>ja(()=>import(`/api/mods/${encodeURIComponent(h)}/views/${encodeURIComponent(g)}`),[]).then(x=>({default:x.default??(()=>null)})));return e.jsxs("div",{className:"mod-view-tab-pane",children:[e.jsx("div",{className:"mod-view-iframe-header",children:e.jsxs("span",{className:"mod-view-iframe-label",children:[e.jsx(Is,{size:14}),n.label,e.jsxs("span",{className:"muted",style:{fontSize:11,fontWeight:400},children:["by ",n.modId]})]})}),e.jsx("div",{className:"mod-view-tab-body",children:e.jsx(ul,{modId:n.modId,component:n.component,children:e.jsx(r.Suspense,{fallback:e.jsxs("div",{style:{padding:24},children:[e.jsx(ge,{size:"md"})," ",e.jsx("span",{className:"muted",children:"Loading mod view…"})]}),children:e.jsx(c,{})})})})]})}return e.jsxs(se,{children:[e.jsxs(ne,{children:[e.jsx(Is,{size:14})," ",n.label]}),e.jsxs(re,{children:["by ",n.modId]}),n.description&&e.jsx("p",{className:"muted",style:{marginTop:8},children:n.description}),e.jsxs("p",{className:"muted",style:{fontSize:12,marginTop:12},children:["This mod declared a tab view but did not provide a component path in views/registry.json. Add a ",e.jsx("code",{children:"component"})," field (e.g. ",e.jsx("code",{children:'"MyView.js"'}),") and ship the file under ",e.jsx("code",{children:"views/"}),"."]}),e.jsx("div",{style:{marginTop:12},children:e.jsx(z,{variant:"secondary",size:"sm",onClick:()=>t("mods"),children:"Open Mods page"})})]})}class ul extends r.Component{constructor(){super(...arguments);Xs(this,"state",{error:null})}static getDerivedStateFromError(t){return{error:t}}componentDidCatch(){}render(){return this.state.error?e.jsxs("div",{className:"mod-view-error",children:[e.jsx(Ee,{size:16}),e.jsx("strong",{children:"Failed to render mod view"}),e.jsxs("div",{className:"muted",style:{fontSize:12,marginTop:6},children:[this.props.modId," → ",this.props.component,": ",this.state.error.message]})]}):this.props.children}}const pl=["interval","cron","once"],xl=["command","agent","webhook"],Os=[{value:"UTC",label:"UTC"},{value:"America/New_York",label:"America/New_York (ET)"},{value:"America/Los_Angeles",label:"America/Los_Angeles (PT)"},{value:"America/Chicago",label:"America/Chicago (CT)"},{value:"Europe/London",label:"Europe/London (UK)"},{value:"Europe/Berlin",label:"Europe/Berlin (CET)"},{value:"Asia/Tokyo",label:"Asia/Tokyo (JST)"}],jl=Array.from({length:12},(s,a)=>a*5),Ws=Array.from({length:24},(s,a)=>({value:a,label:a===0?"12 AM":a<12?`${a} AM`:a===12?"12 PM":`${a-12} PM`})),Ks=[{value:"*",label:"Every day"},{value:"0",label:"Sunday"},{value:"1",label:"Monday"},{value:"2",label:"Tuesday"},{value:"3",label:"Wednesday"},{value:"4",label:"Thursday"},{value:"5",label:"Friday"},{value:"6",label:"Saturday"}],Dt=[{value:"s",label:"seconds"},{value:"m",label:"minutes"},{value:"h",label:"hours"},{value:"d",label:"days"}];function Lt(s){if(typeof s!="string")return null;const a=s.trim().split(/\s+/);if(a.length!==5)return null;const[t,i,,,n]=a,d=parseInt(t,10),o=parseInt(i,10);if(!Number.isFinite(d)||!Number.isFinite(o)||t!==String(d)||i!==String(o))return null;const l=n==="*"?"*":parseInt(n,10);return l===null||n!=="*"&&!Number.isFinite(l)?null:{minute:d,hour:o,dow:n==="*"?"*":String(l)}}function fl(s){if(typeof s!="string")return null;const a=/^(\d+)\s*([smhd])$/i.exec(s.trim());return a?{n:parseInt(a[1],10),unit:a[2].toLowerCase()}:null}function gl(s){var d,o;if(!s)return{name:"",type:"cron",cronMinute:0,cronHour:13,cronDow:"0",showAdvanced:!1,rawCron:"0 13 * * 0",intervalN:30,intervalUnit:"m",onceAt:"",timezone:"UTC",customTimezone:"",actionType:"agent",actionTarget:"",actionPrompt:"",skipIfBudgetLow:!1,maxConcurrent:6,enabled:!0,humanLabel:""};const a=s.type==="cron"?Lt(s.schedule):null,t=s.type==="interval"?fl(s.schedule):null,i=s.timezone||"UTC",n=Os.some(l=>l.value===i);return{name:s.name||"",type:s.type,cronMinute:(a==null?void 0:a.minute)??0,cronHour:(a==null?void 0:a.hour)??9,cronDow:(a==null?void 0:a.dow)??"*",showAdvanced:!a,rawCron:s.schedule,intervalN:(t==null?void 0:t.n)??30,intervalUnit:(t==null?void 0:t.unit)??"m",onceAt:s.type==="once"?vl(s.schedule):"",timezone:n?i:"Other…",customTimezone:n?"":i,actionType:s.action.type,actionTarget:s.action.target||"",actionPrompt:s.action.prompt||"",skipIfBudgetLow:!!((d=s.budgetCheck)!=null&&d.skipIfBudgetLow),maxConcurrent:Number.isFinite((o=s.budgetCheck)==null?void 0:o.maxConcurrent)?s.budgetCheck.maxConcurrent:6,enabled:s.enabled!==!1,humanLabel:""}}function vl(s){if(!s)return"";try{const a=new Date(s);if(Number.isNaN(a.getTime()))return"";const t=i=>String(i).padStart(2,"0");return`${a.getFullYear()}-${t(a.getMonth()+1)}-${t(a.getDate())}T${t(a.getHours())}:${t(a.getMinutes())}`}catch{return""}}function yl(s){var t,i,n;if(s.type==="cron"){if(s.showAdvanced)return{schedule:s.rawCron.trim(),humanLabel:s.humanLabel||s.rawCron.trim()};const d=`${s.cronMinute} ${s.cronHour} * * ${s.cronDow}`,o=((t=Ks.find(g=>g.value===s.cronDow))==null?void 0:t.label)||"",l=((i=Ws.find(g=>g.value===s.cronHour))==null?void 0:i.label)||`${s.cronHour}`,p=String(s.cronMinute).padStart(2,"0"),u=o==="Every day"?`Every day at ${l.replace(" ","")} (min ${p})`:`Every ${o} at ${l.replace(" ","")} (min ${p})`;return{schedule:d,humanLabel:s.humanLabel||u}}if(s.type==="interval"){const d=((n=Dt.find(l=>l.value===s.intervalUnit))==null?void 0:n.label)||s.intervalUnit;return{schedule:`${s.intervalN}${s.intervalUnit}`,humanLabel:s.humanLabel||`Every ${s.intervalN} ${d}`}}return s.onceAt?{schedule:new Date(s.onceAt).toISOString(),humanLabel:s.humanLabel||new Date(s.onceAt).toLocaleString()}:{schedule:"",humanLabel:s.humanLabel||""}}function bl({snapshot:s,refreshSnapshot:a}){var c;const t=he(),i=ke(),[n,d]=r.useState(s.schedules||[]),[o,l]=r.useState(!s.schedules),p=async()=>{try{const x=await A.get("/projects/active/schedules");d(x.schedules||[])}catch(x){t.error(`Schedules load failed: ${x.message}`)}finally{l(!1)}};r.useEffect(()=>{var x;if((x=s.schedules)!=null&&x.length||s.schedules){d(s.schedules||[]),l(!1);return}p()},[s.schedules]);const u=x=>{i.open({title:x?`Edit schedule: ${x.name}`:"New schedule",width:640,children:e.jsx(kl,{initial:x,onClose:i.close,onSubmitted:async M=>{d(k=>{const S=k.findIndex(v=>v.id===M.id);if(S===-1)return[...k,M];const b=k.slice();return b[S]=M,b}),t.success(x?"Schedule updated.":"Schedule created."),i.close(),await a()},onError:M=>t.error(M)})})},g=async x=>{var M;try{const k=await A.post(`/schedules/${encodeURIComponent(x.id)}/run`);t.success(k.ok?"Schedule ran.":`Run failed: ${((M=k.runResult)==null?void 0:M.error)||"unknown"}`),await p()}catch(k){t.error(`Run failed: ${k.message}`)}},h=async x=>{if(confirm(`Delete schedule "${x.name}"?`))try{await A.del(`/schedules/${encodeURIComponent(x.id)}`),d(M=>M.filter(k=>k.id!==x.id)),t.success("Schedule deleted.")}catch(M){t.error(`Delete failed: ${M.message}`)}};return o?e.jsx("div",{className:"view-loading",children:e.jsx(ge,{size:"lg"})}):e.jsxs("div",{className:"view view-schedules",children:[e.jsxs("header",{className:"view-header",children:[e.jsxs("div",{className:"view-header-text",children:[e.jsxs("h2",{className:"view-title",children:[e.jsx(Je,{size:18})," Schedules (",n.length,")"]}),e.jsxs("p",{className:"view-subtitle",children:["Recurring tasks for the active project: ",e.jsx("strong",{children:((c=s.activeProject)==null?void 0:c.name)||"(none)"}),". Service daemon runs them at the right time."]})]}),e.jsxs("div",{className:"view-actions",children:[e.jsxs(z,{variant:"secondary",size:"sm",onClick:p,children:[e.jsx(de,{size:14})," Refresh"]}),e.jsxs(z,{variant:"primary",size:"sm",onClick:()=>u(),children:[e.jsx(je,{size:14})," New schedule"]})]})]}),n.length===0?e.jsx(Re,{icon:e.jsx(Je,{size:32}),title:"No schedules",message:s.activeProject?"Add a schedule to run commands, webhooks, or agent tasks on a cron / interval / one-shot basis.":"Activate a project first to scope schedules."}):e.jsx("div",{className:"schedule-grid",children:n.map(x=>{var M;return e.jsxs(se,{className:"schedule-card",children:[e.jsxs("div",{className:"schedule-card-head",children:[e.jsxs("div",{children:[e.jsx(ne,{children:x.name}),e.jsxs(re,{children:[e.jsx("code",{children:x.type})," ·"," ",e.jsx("span",{title:x.schedule,children:Nl(x)||x.schedule}),x.timezone&&x.timezone!=="UTC"?e.jsxs(e.Fragment,{children:[" · ",e.jsx("code",{children:x.timezone})]}):null," · ",e.jsx("span",{className:x.enabled?"status-on":"status-neutral",children:x.enabled?"enabled":"disabled"})]})]}),e.jsxs("div",{className:"schedule-card-actions",children:[e.jsxs(z,{variant:"secondary",size:"sm",onClick:()=>u(x),children:[e.jsx(rs,{size:12})," Edit"]}),e.jsxs(z,{variant:"secondary",size:"sm",onClick:()=>g(x),children:[e.jsx(Rs,{size:12})," Run now"]}),e.jsx("button",{type:"button",className:"icon-btn icon-btn-danger","aria-label":"Delete",title:"Delete",onClick:()=>h(x),children:e.jsx(be,{size:12})})]})]}),e.jsxs("div",{className:"schedule-card-action",children:[e.jsx("span",{className:"muted",children:"action:"})," ",e.jsxs("code",{children:[x.action.type," ",x.action.target]}),x.action.type==="agent"&&x.action.prompt&&e.jsxs("div",{className:"schedule-card-prompt",children:[e.jsx("span",{className:"muted",children:"prompt:"})," ",x.action.prompt]})]}),((M=x.budgetCheck)==null?void 0:M.skipIfBudgetLow)&&e.jsxs("div",{className:"schedule-card-budget",children:[e.jsx("span",{className:"muted",children:"budget gate:"})," ","skip if concurrent ≥ ",x.budgetCheck.maxConcurrent??6]}),e.jsxs("div",{className:"schedule-card-times",children:[e.jsxs("div",{children:[e.jsx("span",{className:"muted",children:"last"})," ",x.lastRun?ye(x.lastRun):"—",x.lastResult&&e.jsx("span",{className:`tag ${ct(x.lastResult)}`,children:x.lastResult}),x.lastError&&e.jsxs("span",{className:"muted schedule-card-error",title:x.lastError,children:[" ","— ",ot(x.lastError,80)]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"muted",children:"next"})," ",x.nextRun?e.jsx("span",{title:new Date(x.nextRun).toISOString(),children:wl(x.nextRun,x.timezone)}):"—",x.nextRun&&e.jsxs("span",{className:"muted",children:[" · ",ye(x.nextRun)]})]})]}),x.history&&x.history.length>0&&e.jsxs("details",{className:"schedule-card-history",children:[e.jsxs("summary",{children:[e.jsx(ts,{size:12})," ",x.history.length," run",x.history.length===1?"":"s"]}),e.jsx("ul",{children:x.history.slice(-10).reverse().map((k,S)=>e.jsxs("li",{children:[e.jsx("span",{className:"tabular-nums muted",children:ye(k.ts)})," ",e.jsx("span",{className:`tag ${ct(k.result)}`,children:k.result}),k.error&&e.jsxs("span",{className:"muted",children:[" — ",ot(k.error,80)]})]},S))})]})]},x.id)})})]})}function kl({initial:s,onClose:a,onSubmitted:t,onError:i}){const[n,d]=r.useState(()=>gl(s)),[o,l]=r.useState(!1),p=r.useMemo(()=>Os.some(h=>h.value===n.timezone)?n.timezone:"Other…",[n.timezone]),u=(h,c)=>{d(x=>({...x,[h]:c}))},g=async h=>{h.preventDefault();const c=n.name.trim();if(!c){i("Name is required.");return}const x=yl(n);if(!x.schedule){i("Schedule value is required.");return}if(!n.actionTarget.trim()){i("Action target is required.");return}const M=n.timezone==="Other…"?n.customTimezone.trim():n.timezone,k={type:n.actionType,target:n.actionTarget.trim()};n.actionType==="agent"&&n.actionPrompt.trim()&&(k.prompt=n.actionPrompt.trim());const S={name:c,type:n.type,schedule:x.schedule,timezone:M||"UTC",action:k,budgetCheck:{maxConcurrent:n.maxConcurrent,skipIfBudgetLow:n.skipIfBudgetLow},enabled:n.enabled};l(!0);try{const b=s?await A.put(`/schedules/${encodeURIComponent(s.id)}`,S):await A.post("/schedules",S);await t(b)}catch(b){i(`${s?"Update":"Create"} failed: ${b.message}`)}finally{l(!1)}};return e.jsxs("form",{className:"schedule-form",onSubmit:g,children:[e.jsx("label",{className:"field-label",children:"Name"}),e.jsx("input",{className:"input",type:"text",placeholder:"Weekly code review",value:n.name,onChange:h=>u("name",h.target.value),autoFocus:!0}),e.jsx("div",{className:"task-form-row",children:e.jsxs("div",{className:"task-form-field",children:[e.jsx("label",{className:"field-label",children:"Type"}),e.jsx("select",{className:"select",value:n.type,onChange:h=>u("type",h.target.value),children:pl.map(h=>e.jsx("option",{value:h,children:h},h))})]})}),n.type==="cron"&&e.jsxs("div",{className:"schedule-cron-group",children:[!n.showAdvanced&&e.jsx(e.Fragment,{children:e.jsxs("div",{className:"task-form-row",children:[e.jsxs("div",{className:"task-form-field",children:[e.jsx("label",{className:"field-label",children:"Day of week"}),e.jsx("select",{className:"select",value:n.cronDow,onChange:h=>u("cronDow",h.target.value),children:Ks.map(h=>e.jsx("option",{value:h.value,children:h.label},h.value))})]}),e.jsxs("div",{className:"task-form-field",children:[e.jsx("label",{className:"field-label",children:"Hour"}),e.jsx("select",{className:"select",value:String(n.cronHour),onChange:h=>u("cronHour",parseInt(h.target.value,10)),children:Ws.map(h=>e.jsx("option",{value:String(h.value),children:h.label},h.value))})]}),e.jsxs("div",{className:"task-form-field",children:[e.jsx("label",{className:"field-label",children:"Minute"}),e.jsx("select",{className:"select",value:String(n.cronMinute),onChange:h=>u("cronMinute",parseInt(h.target.value,10)),children:jl.map(h=>e.jsx("option",{value:String(h),children:String(h).padStart(2,"0")},h))})]})]})}),n.showAdvanced&&e.jsxs("div",{className:"task-form-field",children:[e.jsx("label",{className:"field-label",children:"Cron expression"}),e.jsx("input",{className:"input",type:"text",value:n.rawCron,onChange:h=>u("rawCron",h.target.value),placeholder:"0 13 * * 0"})]}),e.jsxs("button",{type:"button",className:"link-btn",onClick:()=>u("showAdvanced",!n.showAdvanced),children:[e.jsx(Ae,{size:12,style:{transform:n.showAdvanced?"rotate(180deg)":"none",transition:"transform 0.15s"}}),n.showAdvanced?"Hide advanced":"Advanced (raw cron)"]})]}),n.type==="interval"&&e.jsxs("div",{className:"task-form-row",children:[e.jsxs("div",{className:"task-form-field",style:{flex:1},children:[e.jsx("label",{className:"field-label",children:"Every"}),e.jsx("input",{className:"input",type:"number",min:1,value:n.intervalN,onChange:h=>u("intervalN",parseInt(h.target.value,10)||1)})]}),e.jsxs("div",{className:"task-form-field",style:{flex:1},children:[e.jsx("label",{className:"field-label",children:"Unit"}),e.jsx("select",{className:"select",value:n.intervalUnit,onChange:h=>u("intervalUnit",h.target.value),children:Dt.map(h=>e.jsx("option",{value:h.value,children:h.label},h.value))})]})]}),n.type==="once"&&e.jsxs("div",{className:"task-form-field",children:[e.jsx("label",{className:"field-label",children:"Run at"}),e.jsx("input",{className:"input",type:"datetime-local",value:n.onceAt,onChange:h=>u("onceAt",h.target.value)})]}),e.jsxs("div",{className:"task-form-row",children:[e.jsxs("div",{className:"task-form-field",style:{flex:1},children:[e.jsx("label",{className:"field-label",children:"Timezone"}),e.jsxs("select",{className:"select",value:p,onChange:h=>u("timezone",h.target.value),children:[Os.map(h=>e.jsx("option",{value:h.value,children:h.label},h.value)),e.jsx("option",{value:"Other…",children:"Other…"})]})]}),n.timezone==="Other…"&&e.jsxs("div",{className:"task-form-field",style:{flex:1},children:[e.jsx("label",{className:"field-label",children:"IANA name"}),e.jsx("input",{className:"input",type:"text",placeholder:"Europe/Paris",value:n.customTimezone,onChange:h=>u("customTimezone",h.target.value)})]})]}),e.jsxs("div",{className:"task-form-row",children:[e.jsxs("div",{className:"task-form-field",children:[e.jsx("label",{className:"field-label",children:"Action"}),e.jsx("select",{className:"select",value:n.actionType,onChange:h=>u("actionType",h.target.value),children:xl.map(h=>e.jsx("option",{value:h,children:h},h))})]}),e.jsxs("div",{className:"task-form-field",style:{flex:2},children:[e.jsx("label",{className:"field-label",children:"Target"}),e.jsx("input",{className:"input",type:"text",placeholder:n.actionType==="webhook"?"https://...":n.actionType==="agent"?"agent name or task ref":"echo hi",value:n.actionTarget,onChange:h=>u("actionTarget",h.target.value)})]})]}),n.actionType==="agent"&&e.jsxs("div",{className:"task-form-field",children:[e.jsx("label",{className:"field-label",children:"Prompt (what to send the agent)"}),e.jsx("textarea",{className:"input",rows:3,placeholder:"Review open PRs for stale code review comments and nudge reviewers.",value:n.actionPrompt,onChange:h=>u("actionPrompt",h.target.value)})]}),e.jsxs("fieldset",{className:"schedule-budget-card",children:[e.jsx("legend",{children:"Budget pre-flight"}),e.jsxs("label",{className:"checkbox-row",children:[e.jsx("input",{type:"checkbox",checked:n.skipIfBudgetLow,onChange:h=>u("skipIfBudgetLow",h.target.checked)}),e.jsx("span",{children:"Skip this run when too many background tasks are already running."})]}),e.jsxs("div",{className:"task-form-field",children:[e.jsx("label",{className:"field-label",children:"Max concurrent bg tasks"}),e.jsx("input",{className:"input",type:"number",min:1,max:64,value:n.maxConcurrent,onChange:h=>u("maxConcurrent",parseInt(h.target.value,10)||6),disabled:!n.skipIfBudgetLow})]})]}),e.jsxs("label",{className:"checkbox-row",children:[e.jsx("input",{type:"checkbox",checked:n.enabled,onChange:h=>u("enabled",h.target.checked)}),e.jsx("span",{children:"Enabled"})]}),e.jsxs("div",{className:"modal-footer-actions",children:[e.jsx(z,{variant:"ghost",type:"button",onClick:a,disabled:o,children:"Cancel"}),e.jsx(z,{variant:"primary",type:"submit",disabled:o,children:s?"Save":"Create"})]})]})}function Nl(s){var d,o;if(s.type!=="cron")return s.schedule;const a=Lt(s.schedule);if(!a)return s.schedule;const t=((d=Ks.find(l=>l.value===a.dow))==null?void 0:d.label)||"",i=((o=Ws.find(l=>l.value===a.hour))==null?void 0:o.label)||`${a.hour}`,n=String(a.minute).padStart(2,"0");return t==="Every day"?`Every day at ${i} :${n}`:`Every ${t} at ${i} :${n}`}function wl(s,a){try{return new Date(s).toLocaleString(void 0,{timeZone:a||void 0,weekday:"long",hour:"numeric",minute:"2-digit",month:"short",day:"numeric"})}catch{return new Date(s).toLocaleString()}}function ct(s){return s==="success"?"tag-success":s==="skipped"?"tag-warning":"tag-error"}function ot(s,a){return s.length<=a?s:s.slice(0,a-1)+"…"}const us={all:Me,languages:fa,frameworks:kt,tools:an,testing:Ia,design:wt,reasoning:Na,planning:ls,gitops:Ea,docs:ka};function Cl({snapshot:s,refreshSnapshot:a}){const t=he(),i=ke(),[n,d]=r.useState([]),[o,l]=r.useState([]),[p,u]=r.useState(!0),[g,h]=r.useState("all"),[c,x]=r.useState(""),[M,k]=r.useState(null),[S,b]=r.useState(!1),[v,y]=r.useState(null),[T,m]=r.useState(new Set(["all","languages","frameworks"])),I=async()=>{u(!0);try{const $=await A.get("/skills");d($.skills||[]),l($.categories||[])}catch($){t.error(`Skills load failed: ${$.message}`)}finally{u(!1)}};r.useEffect(()=>{I()},[]),r.useEffect(()=>{if(!c.trim()){k(null);return}b(!0);const $=setTimeout(async()=>{try{const q=await A.get(`/skills/search?q=${encodeURIComponent(c.trim())}`);k(q.results||[])}catch(q){t.error(`Search failed: ${q.message}`)}finally{b(!1)}},280);return()=>clearTimeout($)},[c,t]);const U=r.useMemo(()=>{let $=n;return g!=="all"&&($=$.filter(q=>(q.category||"tools")===g)),$},[n,g]),R=async $=>{if(confirm(`Install skill "${$.name}"?
329
-
330
- ${$.installCmd||`skills add ${$.id}`}`)){y($.id);try{await A.post("/skills/install",{name:$.name,source:$.id}),t.success(`Installed ${$.name}.`),k(q=>(q==null?void 0:q.filter(X=>X.id!==$.id))||q),await I()}catch(q){t.error(`Install failed: ${q.message}`)}finally{y(null)}}},G=async $=>{try{$.enabled!==!1?(await A.post(`/skills/${encodeURIComponent($.id)}/disable`),t.success(`Disabled ${$.name}.`)):(await A.post(`/skills/${encodeURIComponent($.id)}/enable`),t.success(`Enabled ${$.name}.`)),await I()}catch(q){t.error(`Toggle failed: ${q.message}`)}},W=$=>{let q;q=e.jsxs("div",{className:"skill-detail",children:[e.jsx("p",{className:"muted text-sm mono skill-detail-source",children:$.source}),e.jsx("p",{className:"skill-detail-desc",children:$.description||"No description."}),e.jsxs("div",{className:"skill-detail-meta",children:[e.jsxs("span",{children:[e.jsx("strong",{children:"Category:"})," ",$.category]}),e.jsxs("span",{children:[e.jsx("strong",{children:"Version:"})," ",e.jsx("code",{children:$.version})]}),$.path&&e.jsxs("span",{children:[e.jsx("strong",{children:"Path:"})," ",e.jsx("code",{children:$.path})]})]}),$.tags&&$.tags.length>0&&e.jsx("div",{className:"skill-detail-tags",children:$.tags.map(X=>e.jsx("span",{className:"tag",children:X},X))}),$.installCmd&&e.jsxs("div",{children:[e.jsx("label",{className:"field-label",children:"Install command"}),e.jsx("pre",{className:"skill-detail-cmd mono",children:$.installCmd})]})]}),i.open({title:$.name,width:560,children:q,footer:e.jsxs("div",{className:"modal-footer-actions",children:[e.jsx(z,{variant:"ghost",onClick:()=>i.close(),children:"Close"}),!$.installed&&e.jsxs(z,{variant:"primary",onClick:()=>{i.close(),R($)},loading:v===$.id,children:[e.jsx(De,{size:12})," Install"]})]})})};return e.jsxs("div",{className:"view view-skills",children:[e.jsxs("header",{className:"view-header",children:[e.jsxs("div",{className:"view-header-text",children:[e.jsxs("h2",{className:"view-title",children:[e.jsx(Me,{size:18})," Skills"]}),e.jsxs("p",{className:"view-subtitle",children:["Installed skills + browse the registry. Powered by the ",e.jsx("code",{children:"skills"})," CLI."]})]}),e.jsxs("div",{className:"view-actions",children:[e.jsxs("div",{className:"search-input",children:[e.jsx(Oe,{size:14}),e.jsx("input",{className:"input",type:"text",placeholder:"Browse new skills…",value:c,onChange:$=>x($.target.value)}),c&&e.jsx("button",{type:"button",className:"icon-btn","aria-label":"Clear search",onClick:()=>x(""),title:"Clear",children:e.jsx(bt,{size:12})})]}),e.jsxs(z,{variant:"secondary",size:"sm",onClick:I,children:[e.jsx(de,{size:14})," Refresh"]})]})]}),c.trim()&&e.jsxs("section",{className:"skills-section",children:[e.jsxs("h3",{className:"skills-section-title",children:[e.jsx(Oe,{size:14})," Search results",S&&e.jsx(ge,{size:"sm"})]}),S?e.jsx("div",{className:"skills-grid",children:[0,1,2].map($=>e.jsx("div",{className:"skill-card skill-card-skeleton"},$))}):M&&M.length===0?e.jsx(Re,{icon:e.jsx(Oe,{size:28}),title:"No matches",message:`No skills match "${c}".`}):e.jsx("div",{className:"skills-grid",children:(M||[]).map($=>e.jsx(dt,{skill:$,onShow:()=>W($),onInstall:()=>R($),installing:v===$.id,installed:!!n.find(q=>q.id===$.id)},`search-${$.id}`))})]}),!c.trim()&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"skills-categories",children:o.map($=>{const q=us[$.id]||Me,X=n.filter(N=>(N.category||"tools")===$.id).length;return e.jsxs("button",{type:"button",className:Z("skill-category",g===$.id&&"skill-category-active"),onClick:()=>h($.id),children:[e.jsx(q,{size:14}),e.jsx("span",{children:$.label}),X>0&&e.jsx("span",{className:"skill-category-count",children:X})]},$.id)})}),e.jsxs("section",{className:"skills-section",children:[e.jsxs("h3",{className:"skills-section-title",children:[e.jsx(ys,{size:14})," Installed"]}),p?e.jsx("div",{className:"view-loading",children:e.jsx(ge,{size:"lg"})}):e.jsx("div",{className:"skills-categories-list",children:o.map($=>{const q=U.filter(N=>(N.category||"tools")===$.id);if(q.length===0)return null;const X=T.has($.id);return e.jsxs("details",{className:"skills-category",open:X,onToggle:N=>{const E=N.currentTarget;m(D=>{const H=new Set(D);return E.open?H.add($.id):H.delete($.id),H})},children:[e.jsxs("summary",{className:"skills-category-summary",children:[e.jsxs("span",{className:"skills-category-name",children:[us[$.id]&&(()=>{const N=us[$.id];return e.jsx(N,{size:14})})(),$.label]}),e.jsx("span",{className:"skill-category-count",children:q.length})]}),e.jsx("div",{className:"skills-grid",children:q.map(N=>e.jsx(dt,{skill:N,onShow:()=>W(N),onToggle:()=>G(N)},N.id))})]},$.id)})})]})]})]})}function dt({skill:s,onShow:a,onInstall:t,onToggle:i,installing:n,installed:d}){const o=us[s.category]||Me,l=s.enabled!==!1;return e.jsxs(se,{variant:"elevated",interactive:!0,className:Z("skill-card",!l&&"skill-card-disabled"),children:[e.jsxs("div",{className:"skill-card-head",children:[e.jsx("div",{className:"skill-card-icon",style:{background:"color-mix(in srgb, var(--accent) 12%, transparent)"},children:e.jsx(o,{size:18})}),e.jsxs("div",{className:"skill-card-title-area",children:[e.jsx("div",{className:"skill-card-title",children:s.name}),e.jsx("div",{className:"skill-card-source mono",children:s.source})]}),d?e.jsx(Le,{kind:l?"success":"neutral",children:l?"on":"off"}):e.jsx(Le,{kind:"accent",children:"new"})]}),e.jsx("p",{className:"skill-card-desc",children:s.description||"No description."}),e.jsxs("div",{className:"skill-card-meta",children:[e.jsxs("span",{className:"mono text-sm",children:["v",s.version]}),s.category&&e.jsx("span",{className:"text-sm muted",children:s.category}),s.tags&&s.tags.length>0&&s.tags.slice(0,3).map(p=>e.jsx("span",{className:"skill-card-tag",children:p},p))]}),e.jsxs("div",{className:"skill-card-actions",children:[e.jsxs(z,{variant:"ghost",size:"sm",onClick:a,children:[e.jsx(gt,{size:12})," Details"]}),d&&i&&e.jsxs(z,{variant:l?"ghost":"secondary",size:"sm",onClick:i,title:l?"Disable":"Enable",children:[l?e.jsx(Ya,{size:12}):e.jsx(Fs,{size:12}),l?"Disable":"Enable"]}),!d&&t&&e.jsxs(z,{variant:"primary",size:"sm",onClick:t,loading:n,children:[e.jsx(De,{size:12})," Install"]})]})]})}const Ze=[{id:"1h",label:"Last hour",ms:60*60*1e3},{id:"1d",label:"Last day",ms:24*60*60*1e3},{id:"7d",label:"Last 7 days",ms:7*24*60*60*1e3},{id:"30d",label:"Last 30 days",ms:30*24*60*60*1e3},{id:"all",label:"All time",ms:0}];function Sl({snapshot:s}){var S,b;const a=he(),[t,i]=r.useState(null),[n,d]=r.useState(!0),[o,l]=r.useState("1d"),[p,u]=r.useState(new Set),[g,h]=r.useState(0),c=async v=>{try{const y=v?`?since=${encodeURIComponent(v)}&limit=1000`:"?limit=1000",T=await A.get(`/history${y}`);i(T),u(new Set(T.projects.filter(m=>T.events.some(I=>I.projectId===m.id)).map(m=>m.id)))}catch(y){a.error(`History load failed: ${y.message}`)}finally{d(!1)}};r.useEffect(()=>{d(!0);const v=Ze.find(y=>y.id===o)||Ze[1];if(v.ms>0){const y=new Date(Date.now()-v.ms).toISOString();c(y)}else c()},[o]),r.useEffect(()=>{const v=setInterval(()=>h(y=>y+1),3e4);return()=>clearInterval(v)},[]);const x=new Map;for(const v of(t==null?void 0:t.events)||[]){const y=v.projectId||"global";x.has(y)||x.set(y,[]),x.get(y).push(v)}const M=v=>{u(y=>{const T=new Set(y);return T.has(v)?T.delete(v):T.add(v),T})},k=()=>{if(!t)return;const v=new Blob([JSON.stringify(t,null,2)],{type:"application/json"}),y=URL.createObjectURL(v),T=document.createElement("a");T.href=y,T.download=`bizar-history-${new Date().toISOString().replace(/[:.]/g,"-")}.json`,T.click(),URL.revokeObjectURL(y),a.success("History exported.")};return e.jsxs("div",{className:"view view-history","data-tick":g,children:[e.jsxs("header",{className:"view-header",children:[e.jsxs("div",{className:"view-header-text",children:[e.jsxs("h2",{className:"view-title",children:[e.jsx(ts,{size:18})," History"]}),e.jsxs("p",{className:"view-subtitle",children:["Cross-project history of events, tasks, and plans.",((S=t==null?void 0:t.stats)==null?void 0:S.lastTs)&&e.jsxs(e.Fragment,{children:[" · last event ",ye(t.stats.lastTs)]})]})]}),e.jsxs("div",{className:"view-actions",children:[e.jsxs("div",{className:"tasks-toolbar-group",children:[e.jsx(Ra,{size:14,style:{color:"var(--text-dim)"}}),e.jsx("select",{className:"select select-sm",value:o,onChange:v=>l(v.target.value),title:"Time range",children:Ze.map(v=>e.jsx("option",{value:v.id,children:v.label},v.id))})]}),e.jsxs(z,{variant:"ghost",size:"sm",onClick:()=>{d(!0);const v=Ze.find(y=>y.id===o)||Ze[1];v.ms>0?c(new Date(Date.now()-v.ms).toISOString()):c()},children:[e.jsx(de,{size:14})," Refresh"]}),e.jsxs(z,{variant:"secondary",size:"sm",onClick:k,children:[e.jsx(De,{size:14})," Export"]})]})]}),n&&e.jsxs("div",{className:"view-loading",children:[e.jsx(ge,{size:"lg"}),e.jsx("p",{children:"Loading history…"})]}),!n&&t&&e.jsxs("div",{className:"history-list",children:[t.projects.length===0&&e.jsxs(se,{children:[e.jsxs(ne,{children:[e.jsx(Be,{size:14})," No projects"]}),e.jsx(re,{children:"Register a project in Overview to start tracking history."})]}),t.projects.map(v=>{const y=x.get(v.id)||[],T=p.has(v.id);return e.jsxs(se,{className:"history-project",children:[e.jsxs("div",{className:"history-project-head",children:[e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:4,minWidth:0,flex:1},children:[e.jsxs("div",{className:"history-project-name",children:[e.jsx(Be,{size:16})," ",v.name]}),e.jsx("div",{className:"history-project-meta",children:v.path})]}),e.jsxs("div",{className:"history-project-stats",children:[e.jsxs("span",{className:"history-project-stat",children:[e.jsx("span",{className:"history-project-stat-num",children:v.tasks.done}),e.jsxs("span",{className:"muted",children:["/ ",v.tasks.total," done"]})]}),v.tasks.doing>0&&e.jsxs("span",{className:"history-project-stat",children:[e.jsx("span",{className:"history-project-stat-num",children:v.tasks.doing}),e.jsx("span",{className:"muted",children:"doing"})]}),v.tasks.blocked>0&&e.jsxs("span",{className:"history-project-stat",children:[e.jsx("span",{className:"history-project-stat-num",children:v.tasks.blocked}),e.jsx("span",{className:"muted",children:"blocked"})]}),e.jsxs("span",{className:"history-project-stat",children:[e.jsx(ks,{size:11})," ",e.jsx("span",{className:"history-project-stat-num",children:v.plans}),e.jsxs("span",{className:"muted",children:[" plan",v.plans===1?"":"s"]})]}),v.lastAccessed&&e.jsx("span",{className:"history-project-stat",children:e.jsxs("span",{className:"muted",children:["last opened ",ye(v.lastAccessed)]})})]}),e.jsx("button",{type:"button",className:"icon-btn",onClick:()=>M(v.id),"aria-label":T?"Collapse":"Expand",children:T?e.jsx(Ae,{size:14}):e.jsx(Ue,{size:14})})]}),T&&e.jsx("div",{className:"history-timeline-mini",children:y.length===0?e.jsx("div",{className:"muted",style:{padding:"12px 8px",fontSize:12},children:"No events in this time range."}):y.slice(-100).reverse().map((m,I)=>e.jsxs("div",{className:"history-timeline-row",children:[e.jsx("span",{className:"history-timeline-ts",children:new Date(m.ts).toLocaleTimeString()}),e.jsx("span",{className:"history-timeline-kind",children:m.kind||"event"}),e.jsxs("span",{className:"history-timeline-msg",title:String(m.text||m.title||""),children:[m.author?`@${m.author} `:"",String(m.text??m.title??m.name??"")]})]},I))})]},v.id)}),x.has("global")&&e.jsxs(se,{className:"history-project",children:[e.jsx("div",{className:"history-project-head",children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:4,minWidth:0,flex:1},children:[e.jsxs("div",{className:"history-project-name",children:[e.jsx(ts,{size:16})," Global events"]}),e.jsx("div",{className:"history-project-meta",children:"Activity not tied to a specific project"})]})}),e.jsx("div",{className:"history-timeline-mini",children:(x.get("global")||[]).slice(-100).reverse().map((v,y)=>e.jsxs("div",{className:"history-timeline-row",children:[e.jsx("span",{className:"history-timeline-ts",children:new Date(v.ts).toLocaleTimeString()}),e.jsx("span",{className:"history-timeline-kind",children:v.kind||"event"}),e.jsxs("span",{className:"history-timeline-msg",title:String(v.text||v.title||""),children:[v.author?`@${v.author} `:"",String(v.text??v.title??v.name??"")]})]},y))})]}),((b=t.stats)==null?void 0:b.counts)&&Object.keys(t.stats.counts).length>0&&e.jsxs(se,{children:[e.jsx(ne,{children:"Event counts by kind"}),e.jsxs(re,{children:[t.stats.lines," total lines in log"]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:8,marginTop:8},children:Object.entries(t.stats.counts).sort((v,y)=>y[1]-v[1]).slice(0,30).map(([v,y])=>e.jsxs("span",{className:Z("tag","tag-neutral"),style:{fontFamily:"var(--font-mono)"},children:[v,": ",y]},v))})]})]})]})}const zl=5e3,Tl=2e3,Al=120;function Ml(s){return s.status==="pending"||s.status==="running"}function $l(s){if(!Number.isFinite(s)||s<0)return"—";const a=Math.floor(s/1e3),t=Math.floor(a/3600),i=Math.floor(a%3600/60),n=a%60;return t>0?`${t}h ${i}m ${n}s`:i>0?`${i}m ${n}s`:`${n}s`}function Rl(s){const a=he(),t=ke(),[i,n]=r.useState([]),[d,o]=r.useState(!0),[l,p]=r.useState(null),[,u]=r.useState(0),g=r.useCallback(async()=>{try{const k=await A.get("/background");n(Array.isArray(k==null?void 0:k.instances)?k.instances:[]),p(null)}catch(k){p((k==null?void 0:k.message)||"Failed to load background agents.")}finally{o(!1)}},[]);r.useEffect(()=>{g();const k=setInterval(g,zl);return()=>clearInterval(k)},[g]),r.useEffect(()=>{const k=setInterval(()=>u(S=>(S+1)%1e6),1e3);return()=>clearInterval(k)},[]),r.useEffect(()=>{const k=new _s,S=k.on(b=>{const v=b.type;(v==="background:change"||v==="background:cleanup")&&g()});return()=>{S(),k.close()}},[g]);const h=i.filter(Ml),c=k=>{Dl(t,k)},x=async k=>{try{const S=await A.get(`/background/${encodeURIComponent(k.instanceId)}/tmux`);Pl(t,S)}catch(S){a.error(`Tmux info failed: ${S.message}`)}},M=k=>{Rt(t,a,k.instanceId,k.agent||k.prompt,()=>{n(S=>S.filter(b=>b.instanceId!==k.instanceId))})};return d?e.jsx("div",{className:"bg-active-view",children:e.jsxs("div",{className:"bg-active-loading",children:[e.jsx(ge,{size:"md"}),e.jsx("span",{children:"Loading background agents…"})]})}):l?e.jsx("div",{className:"bg-active-view",children:e.jsx(Re,{icon:e.jsx(ze,{size:32}),title:"Couldn't load background agents",message:l,action:e.jsxs(z,{variant:"primary",onClick:g,children:[e.jsx(de,{size:14})," Retry"]})})}):e.jsxs("div",{className:"bg-active-view",children:[e.jsxs("div",{className:"bg-active-header",children:[e.jsxs("div",{className:"bg-active-header-text",children:[e.jsx("h2",{className:"bg-active-title",children:"Active Background Agents"}),e.jsxs("p",{className:"bg-active-subtitle muted",children:[h.length," active · ",i.length," total in store"]})]}),e.jsxs(z,{variant:"ghost",size:"sm",onClick:g,title:"Refresh now",children:[e.jsx(de,{size:14})," Refresh"]})]}),h.length===0?e.jsx(Re,{icon:e.jsx(ze,{size:32}),title:"No active background agents",message:"Spawn one from the Agents tab or via the bizar_spawn_background tool."}):e.jsx("div",{className:"bg-active-list",children:h.map(k=>e.jsx(Il,{inst:k,onViewOutput:()=>c(k),onOpenTmux:()=>x(k),onKill:()=>M(k)},k.instanceId))})]})}function Il({inst:s,onViewOutput:a,onOpenTmux:t,onKill:i}){const n=typeof s.startedAt=="number"?s.startedAt:0,d=n?mt(n):"—",o=n?Date.now()-n:0,l=ut(s.prompt,Al);return e.jsxs(se,{className:"bg-active-card",variant:"elevated",children:[e.jsxs("div",{className:"bg-active-card-top",children:[e.jsxs("div",{className:"bg-active-card-id",children:[e.jsx("code",{className:"mono",children:s.instanceId}),e.jsx($t,{status:s.status||"pending",dot:!0})]}),e.jsxs("div",{className:"bg-active-card-agent",children:[e.jsx("span",{className:"bg-active-card-agent-label",children:"Agent"}),e.jsx("span",{className:"bg-active-card-agent-name",children:s.agent||"unknown"})]})]}),l&&e.jsx("div",{className:"bg-active-prompt",children:l}),s.currentStep&&e.jsxs("div",{className:"bg-active-step",children:[e.jsx("span",{className:"bg-active-step-label",children:"Step:"}),e.jsx("span",{className:"bg-active-step-value",children:s.currentStep})]}),typeof s.progress=="number"&&e.jsxs("div",{className:"progress-bar","aria-label":"Progress",children:[e.jsx("div",{className:"progress-fill",style:{width:`${Math.max(0,Math.min(100,s.progress))}%`}}),e.jsxs("span",{className:"progress-label",children:[Math.round(s.progress),"%"]})]}),e.jsxs("div",{className:"bg-active-meta",children:[e.jsxs("span",{title:d,children:[e.jsx("strong",{children:"Started:"})," ",d]}),e.jsxs("span",{children:[e.jsx("strong",{children:"Duration:"})," ",$l(o)]}),e.jsxs("span",{children:[e.jsx("strong",{children:"Tool calls:"})," ",s.toolCallCount??0]}),s.tmuxSession&&e.jsxs("span",{className:Z(s.tmuxActive&&"bg-active-meta-tmux-live"),children:[e.jsx("strong",{children:"tmux:"})," ",e.jsx("code",{className:"mono",children:s.tmuxSession}),s.tmuxActive?" · live":""]})]}),e.jsxs("div",{className:"bg-active-actions",children:[e.jsxs(z,{variant:"secondary",size:"sm",onClick:a,children:[e.jsx(ns,{size:14})," View output"]}),e.jsxs(z,{variant:"ghost",size:"sm",onClick:t,children:[e.jsx(ft,{size:14})," Open in tmux"]}),e.jsxs(z,{variant:"danger",size:"sm",onClick:i,children:[e.jsx(be,{size:14})," Kill"]})]})]})}function Dl(s,a){s.open({title:`Output — ${a.agent||a.instanceId}`,width:720,children:e.jsx(Ll,{instanceId:a.instanceId})})}function Ll({instanceId:s}){const a=he(),[t,i]=r.useState(""),[n,d]=r.useState(!0),[o,l]=r.useState(null),[p,u]=r.useState(!0),g=r.useRef(null),h=r.useRef(!0),c=r.useCallback(async()=>{try{const k=await A.get(`/background/${encodeURIComponent(s)}/output?lines=200`);i((k==null?void 0:k.output)??""),u((k==null?void 0:k.available)!==!1),l(null)}catch(k){l((k==null?void 0:k.message)||"Failed to load output.")}finally{d(!1)}},[s]);r.useEffect(()=>{c();const k=setInterval(c,Tl);return()=>clearInterval(k)},[c]),r.useEffect(()=>{var k;h.current&&((k=g.current)==null||k.scrollIntoView({behavior:"auto",block:"end"}))},[t]);const x=k=>{const S=k.currentTarget,b=S.scrollHeight-S.scrollTop-S.clientHeight<24;h.current=b},M=async()=>{try{await navigator.clipboard.writeText(t),a.success("Output copied.")}catch{}};return e.jsxs("div",{className:"bg-output-modal",children:[e.jsxs("div",{className:"bg-output-toolbar",children:[e.jsx("span",{className:"muted",children:p?`${t.length} chars · auto-refresh 2s`:"Output unavailable"}),e.jsxs("div",{className:"bg-output-toolbar-actions",children:[e.jsxs(z,{variant:"ghost",size:"sm",onClick:c,title:"Refresh now",children:[e.jsx(de,{size:14})," Refresh"]}),e.jsxs(z,{variant:"ghost",size:"sm",onClick:M,disabled:!t,children:[e.jsx(Hs,{size:14})," Copy"]})]})]}),n&&!t?e.jsxs("div",{className:"bg-output-loading",children:[e.jsx(Ha,{size:16,className:"spin"})," Loading…"]}):o?e.jsx("div",{className:"bg-output-error",children:o}):t?e.jsxs("div",{className:"bg-output-scroll",onScroll:x,children:[e.jsx("pre",{className:"bg-output-pre mono",children:e.jsx("code",{children:t})}),e.jsx("div",{ref:g})]}):e.jsx("div",{className:"bg-output-empty muted",children:"No output captured yet."})]})}function Pl(s,a){const t=a.attachCommand||a.session||"";s.open({title:"Attach to tmux",width:520,children:e.jsx(El,{info:a,cmd:t})})}function El({info:s,cmd:a}){const[t,i]=r.useState(!1),n=async()=>{try{await navigator.clipboard.writeText(a),i(!0),window.setTimeout(()=>i(!1),1500)}catch{}};return e.jsx("div",{className:"bg-tmux-modal",children:a?e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"bg-tmux-meta",children:[s.exists?e.jsx("span",{className:"badge badge-success",children:"session live"}):e.jsxs("span",{className:"badge badge-warning",children:["session not running",s.reason?` — ${s.reason}`:""]}),s.session&&e.jsxs("span",{className:"bg-tmux-session muted",children:["· session ",e.jsx("code",{className:"mono",children:s.session})]})]}),e.jsx("label",{className:"field-label",children:"Attach command"}),e.jsxs("div",{className:"bg-tmux-command-row",children:[e.jsx("code",{className:"bg-tmux-command mono",children:a}),e.jsxs(z,{variant:"secondary",size:"sm",onClick:n,children:[e.jsx(Hs,{size:14})," ",t?"Copied":"Copy"]})]}),e.jsx("p",{className:"muted bg-tmux-hint",children:"Paste this into a terminal on the host running the dashboard. The dashboard itself does not open terminals."})]}):e.jsx("p",{className:"muted",children:"No tmux session attached to this instance."})})}const Ms={overview:Mn,chat:Un,agents:qn,artifacts:ji,tasks:Ci,activity:Ei,background:Rl,config:Bi,settings:cl,mods:dl,schedules:bl,skills:Cl,history:Sl},Ol="v3.21.0";function Bl(s,a,t,i){if(Ms[s]){const o=Ms[s];return e.jsx(o,{...a})}const n=t.find(o=>o.id===s);if(n)return e.jsx(ml,{viewId:n.id,reloadKey:i,activeTab:a.activeTab,setActiveTab:a.setActiveTab});const d=Ms.overview;return e.jsx(d,{...a})}function Fl(){return e.jsx(ga,{children:e.jsx(va,{children:e.jsx(Ul,{})})})}function Ul(){var B,Q,O;const s=he(),a=ke(),{isModalOpen:t}=a,i=r.useRef(!1),[n,d]=r.useState("overview"),[o,l]=r.useState(null),[p,u]=r.useState(null),[g,h]=r.useState("connecting"),[c,x]=r.useState(null),[M,k]=r.useState(!1),[S,b]=r.useState([]),[v,y]=r.useState(!1),[T,m]=r.useState([]),[I,U]=r.useState(0),R=r.useRef(null),[G,W]=r.useState(null);r.useEffect(()=>{let j=!1;return(async()=>{try{const C=await A.get("/mods/views");if(j)return;m(C.views||[])}catch{j||m([])}})(),()=>{j=!0}},[I,o==null?void 0:o.mods]),r.useEffect(()=>{if(!G)return;const j=G.on(C=>{((C==null?void 0:C.type)==="mod:change"||(C==null?void 0:C.type)==="mod:enabled"||(C==null?void 0:C.type)==="mod:installed")&&U(L=>L+1)});return()=>j()},[G]),r.useEffect(()=>{p!=null&&p.theme&&(es(p.theme),Ge(p.theme))},[p==null?void 0:p.theme]),r.useEffect(()=>{i.current=t},[t]),r.useEffect(()=>{var L;if(((L=p==null?void 0:p.theme)==null?void 0:L.mode)!=="system")return;const j=window.matchMedia("(prefers-color-scheme: light)"),C=()=>es(p.theme.mode);return j.addEventListener("change",C),()=>j.removeEventListener("change",C)},[(B=p==null?void 0:p.theme)==null?void 0:B.mode]),r.useEffect(()=>{let j=!1;const C=()=>Promise.all([A.get("/snapshot").catch(()=>null),A.get("/settings").catch(()=>null),A.get("/agents/stuck").catch(()=>null)]),L=(F,J,V)=>{F&&l(F),J!=null&&J.data&&u(J.data),V!=null&&V.stuck&&b(V.stuck)};return(async()=>{try{const F=await A.probeAuthStatus(),[J,V,f]=await C();if(j||(L(J,V,f),J||V))return;if(!F.loopback){x("Dashboard server unreachable.");return}if(await new Promise(le=>setTimeout(le,1e3)),j)return;const[_,ee,P]=await C();if(j)return;L(_,ee,P),!_&&!ee&&x("Dashboard server unreachable.")}catch(F){if(j)return;const J=(F==null?void 0:F.message)??"unknown error";x(J),s.error(`Failed to load: ${J}`)}})(),()=>{j=!0}},[s]),r.useEffect(()=>{let j=!1;return A.get("/settings").then(C=>{var F,J;if(j)return;const L=(J=(F=C==null?void 0:C.data)==null?void 0:F.ui)==null?void 0:J.defaultTab;L&&d(L)}).catch(()=>{}),()=>{j=!0}},[]),r.useEffect(()=>{let j=!1;const C=async()=>{try{const F=await A.get("/agents/stuck");j||b(J=>{const V=F.stuck||[];return J.length===0&&V.length>0&&s.warning(`${V.length} agent${V.length===1?"":"s"} stuck`,5e3),V})}catch{}},L=setInterval(C,3e4);return C(),()=>{j=!0,clearInterval(L)}},[]),r.useEffect(()=>{const j=new _s;R.current=j,W(j);const C=j.onStatus(F=>h(F)),L=j.on(F=>{var J;if(F.type==="snapshot"&&"data"in F&&F.data)l(V=>({...V??{},...F.data}));else if(F.type==="change"){const V=F,f=((J=V.path)==null?void 0:J.split("/").pop())||V.path||"";s.info(`File changed: ${f}`,2500),A.get("/snapshot").then(_=>l(ee=>({...ee??{},..._}))).catch(()=>{})}else if(F.type==="tasks:change"){const V=F;l(f=>{if(!f)return f;const _=(f.tasks||[]).map(P=>P.id===V.task.id?V.task:P),ee=_.some(P=>P.id===V.task.id);return{...f,tasks:ee?_:[V.task,..._]}})}else if(F.type==="tasks:delete"){const V=F;l(f=>f&&{...f,tasks:(f.tasks||[]).filter(_=>_.id!==V.id)})}else if(F.type==="settings:change"){const V=F;V.settings&&u(V.settings)}else if(F.type==="project:change")A.get("/snapshot").then(V=>l(f=>({...f??{},...V}))).catch(()=>{});else if(F.type==="agents:change"||F.type==="schedules:change")A.get("/snapshot").then(V=>l(f=>({...f??{},...V}))).catch(()=>{});else if(F.type==="agent:status"||F.type==="agent:restarted"){const V=F;l(f=>{if(!f)return f;const _=(f.agents||[]).map(ee=>ee.name===V.agent.name?V.agent:ee);return{...f,agents:_}})}else if(F.type==="artifact:change")A.get("/artifacts").then(V=>{l(f=>f&&{...f,artifacts:V.artifacts||[]})}).catch(()=>{});else if(F.type==="agent:stuck")b(F.agents||[]);else if(F.type==="dialog:show"){const V=F;V.dialog&&a.open({title:V.dialog.title,width:520,children:e.jsx(An,{dialog:V.dialog,onClose:()=>a.close()})})}});return()=>{C(),L(),j.close(),W(null)}},[s]);const $=r.useCallback(j=>G?G.on(j):()=>{},[G]),q=r.useRef(0);r.useEffect(()=>{const j=()=>{q.current=Date.now()+1500};return document.addEventListener("mousedown",j,!0),document.addEventListener("click",j,!0),document.addEventListener("focusin",j,!0),document.addEventListener("keydown",j,!0),()=>{document.removeEventListener("mousedown",j,!0),document.removeEventListener("click",j,!0),document.removeEventListener("focusin",j,!0),document.removeEventListener("keydown",j,!0)}},[]),r.useEffect(()=>{const j={};Ls.forEach((L,F)=>{j[String(F+1)]=L.id});const C=L=>{var le,ae,fe,ce;if((L.metaKey||L.ctrlKey)&&L.key.toLowerCase()==="k"){L.preventDefault(),k(!0);return}if(L.key==="/"&&!L.metaKey&&!L.ctrlKey){const cs=(ae=(le=L.target)==null?void 0:le.tagName)==null?void 0:ae.toLowerCase();if(cs!=="input"&&cs!=="textarea"&&!((fe=L.target)!=null&&fe.isContentEditable)){L.preventDefault(),k(!0);return}}const F=document.activeElement;if(!F||F===document.body||F===document.documentElement)return;const V=L.target,f=(ce=V==null?void 0:V.tagName)==null?void 0:ce.toLowerCase(),_=f==="input"||f==="textarea"||f==="select"||f==="button"||f==="option"||f==="label"||!!(V!=null&&V.isContentEditable);let ee=!1;if(V&&typeof V.closest=="function"&&(ee=!!V.closest('form, [role="dialog"], [contenteditable], [data-no-key]')),L.repeat||i.current||_||ee||L.metaKey||L.ctrlKey||L.altKey||L.shiftKey||Date.now()<q.current)return;const P=j[L.key];P&&(L.preventDefault(),d(P))};return document.addEventListener("keydown",C),()=>document.removeEventListener("keydown",C)},[]);const X=r.useMemo(()=>async()=>{try{const j=await A.get("/snapshot");l(C=>({...C??{},...j}))}catch(j){s.error(`Refresh failed: ${j.message}`)}},[s]),N=r.useMemo(()=>{const j=T.map(C=>({id:C.id,label:C.label,icon:C.kind==="iframe"?is:Is,isMod:!0,modId:C.modId}));return[...Ls,...j]},[T]),E=r.useMemo(()=>o&&p?Bl(n,{snapshot:o,settings:p,activeTab:n,setActiveTab:d,refreshSnapshot:X},T,I):null,[n,o,p,T,I,X]),D=async()=>{try{const j=await A.get("/projects");l(C=>{var L;return C&&{...C,projects:j.projects||[],activeProject:((L=j.projects)==null?void 0:L.find(F=>F.id===j.active))||null}})}catch(j){s.error(`Projects refresh failed: ${j.message}`)}},H=async j=>{try{await A.post(`/projects/${encodeURIComponent(j)}/activate`),l(C=>C&&{...C,activeProject:C.projects.find(L=>L.id===j)||null})}catch(C){s.error(`Activate failed: ${C.message}`)}},te=j=>{const C=j.type;if(C==="agent")d("agents");else if(C==="task")d("tasks");else if(C==="mod")d("mods");else if(C==="schedule")d("schedules");else if(C==="project"){const L=j.item.id;H(L)}else if(C==="command")s.info(`/${j.item.name} — run from the TUI`,2500);else if(C==="setting"){const L=j.item.id||j.item.path||"";d("settings");const F=J=>{if(J<=0)return;const V=L?document.querySelector(`[data-setting-id="${CSS.escape(L)}"]`):null;V?(V.scrollIntoView({behavior:"smooth",block:"center"}),V.classList.remove("setting-flash"),V.offsetWidth,V.classList.add("setting-flash"),window.setTimeout(()=>V.classList.remove("setting-flash"),1500)):window.setTimeout(()=>F(J-1),80)};window.setTimeout(()=>F(15),60)}},ie=((Q=p==null?void 0:p.ui)==null?void 0:Q.layout)||"topnav",ue=((O=p==null?void 0:p.ui)==null?void 0:O.showHeader)!==!1;return e.jsxs("div",{className:"app","data-layout":ie,"data-active-tab":n,children:[ue&&e.jsx(pn,{activeTab:n,onTabChange:d,wsStatus:g,version:Ol,activeProject:(o==null?void 0:o.activeProject)||null,projects:(o==null?void 0:o.projects)||[],onProjectChange:H,onProjectsRefresh:D,onOpenSearch:()=>k(!0),settings:p,notificationsSlot:e.jsx(bn,{wsSubscribe:$}),showTabs:ie==="topnav",extraTabs:N}),S.length>0&&!v&&e.jsxs("div",{className:"stuck-banner",role:"alert",children:[e.jsx(Ee,{size:16}),e.jsxs("span",{children:[e.jsx("strong",{children:S.length})," agent",S.length===1?"":"s"," stuck:"," ",e.jsx("span",{className:"mono",children:S.map(j=>j.name).join(", ")})]}),e.jsx(z,{variant:"secondary",size:"sm",onClick:()=>{d("agents"),y(!0)},children:"Review"}),e.jsx("button",{type:"button",className:"icon-btn","aria-label":"Dismiss",onClick:()=>y(!0),children:e.jsx($e,{size:14})})]}),e.jsxs("div",{className:"layout-body",children:[ie!=="topnav"&&e.jsx(fn,{tabs:N,activeTab:n,onTabChange:d}),e.jsxs("main",{className:"content",children:[c&&e.jsxs("div",{className:"boot-error",children:[e.jsx("h2",{children:"Dashboard unavailable"}),e.jsx("p",{children:c}),e.jsxs("p",{className:"boot-error-hint",children:["Make sure the Bizar dashboard server is running. Try"," ",e.jsx("code",{children:"bizar-dash start"})," in your terminal."]})]}),!c&&(!o||!p)&&e.jsxs("div",{className:"loading",children:[e.jsx(ge,{size:"lg"}),e.jsx("p",{children:"Loading Bizar…"})]}),E]})]}),e.jsx(gn,{open:M,onClose:()=>k(!1),onSelect:te})]})}function Hl(){const[s,a]=r.useState(()=>typeof window>"u"?!1:window.matchMedia("(max-width: 767px)").matches);return r.useEffect(()=>{const t=window.matchMedia("(max-width: 767px)"),i=n=>a(n.matches);return t.addEventListener("change",i),()=>t.removeEventListener("change",i)},[]),s?e.jsx(ba,{}):e.jsx(Fl,{})}const Pt=document.getElementById("root");if(!Pt)throw new Error("Root element #root not found");ya(Pt).render(e.jsx(r.StrictMode,{children:e.jsx(Hl,{})}));
331
- //# sourceMappingURL=main-B3RgW6FS.js.map