tycono 0.1.78 → 0.1.80
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/api/src/engine/context-assembler.ts +4 -6
- package/src/api/src/engine/runners/claude-cli.ts +5 -5
- package/src/api/src/routes/save.ts +3 -3
- package/src/api/src/services/company-config.ts +23 -0
- package/src/api/src/services/git-save.ts +2 -31
- package/src/api/src/services/job-manager.ts +2 -2
- package/src/api/src/services/scaffold.ts +8 -2
- package/src/web/dist/assets/{index-DSlyI2R-.js → index-D8WK-f75.js} +2 -2
- package/src/web/dist/assets/{preview-app-PJU9PUoY.js → preview-app-Cu2HapST.js} +1 -1
- package/src/web/dist/index.html +1 -1
|
@@ -89,7 +89,7 @@ DevOps Engineer, member, cto
|
|
|
89
89
|
VP Marketing, c-level, ceo`,className:"w-full h-40 p-3 rounded-lg border border-white/10 bg-white/5 text-sm text-white/90 placeholder-white/25 resize-none focus:outline-none focus:border-white/25 transition-colors font-mono"}),l.jsx("div",{className:"text-[10px] text-gray-400 mt-1",children:"Format: Name, Level (member/c-level), ReportsTo. Level and ReportsTo are optional."})]}),_e.length>0&&l.jsxs("div",{children:[l.jsxs("div",{className:"text-[11px] font-bold text-[var(--desk-dark)] uppercase tracking-wider mb-2",children:["Preview (",_e.length," role",_e.length!==1?"s":"",")"]}),l.jsx("div",{className:"bg-white/5 rounded-lg border border-white/10 overflow-hidden",children:l.jsxs("table",{className:"w-full text-xs",children:[l.jsx("thead",{children:l.jsxs("tr",{className:"border-b border-white/10",children:[l.jsx("th",{className:"text-left p-2 text-white/40 font-semibold",children:"Name"}),l.jsx("th",{className:"text-left p-2 text-white/40 font-semibold",children:"ID"}),l.jsx("th",{className:"text-left p-2 text-white/40 font-semibold",children:"Level"}),l.jsx("th",{className:"text-left p-2 text-white/40 font-semibold",children:"Reports To"})]})}),l.jsx("tbody",{children:_e.map((Z,$e)=>l.jsxs("tr",{className:`border-b border-white/5 ${Z.error?"bg-red-900/10":""}`,children:[l.jsx("td",{className:"p-2 text-white/80",children:Z.name}),l.jsx("td",{className:"p-2 text-white/60 font-mono",children:Z.id}),l.jsx("td",{className:"p-2 text-white/60",children:Z.level}),l.jsx("td",{className:"p-2 text-white/60",children:Z.reportsTo}),Z.error&&l.jsx("td",{className:"p-2 text-red-400 text-[10px]",children:Z.error})]},$e))})]})})]})]}),Et==="review"&&l.jsxs("div",{className:"space-y-4",children:[l.jsxs("div",{className:"text-[11px] font-bold text-[var(--desk-dark)] uppercase tracking-wider mb-2",children:["Confirm Bulk Hire — ",_e.length," roles"]}),l.jsx("div",{className:"bg-white/5 rounded-lg border border-white/10 overflow-hidden max-h-[300px] overflow-y-auto",children:l.jsxs("table",{className:"w-full text-xs",children:[l.jsx("thead",{className:"sticky top-0 bg-[var(--wall)]",children:l.jsxs("tr",{className:"border-b border-white/10",children:[l.jsx("th",{className:"text-left p-2 text-white/40 font-semibold",children:"#"}),l.jsx("th",{className:"text-left p-2 text-white/40 font-semibold",children:"Name"}),l.jsx("th",{className:"text-left p-2 text-white/40 font-semibold",children:"ID"}),l.jsx("th",{className:"text-left p-2 text-white/40 font-semibold",children:"Level"}),l.jsx("th",{className:"text-left p-2 text-white/40 font-semibold",children:"Reports To"})]})}),l.jsx("tbody",{children:_e.map((Z,$e)=>l.jsxs("tr",{className:"border-b border-white/5",children:[l.jsx("td",{className:"p-2 text-white/30",children:$e+1}),l.jsx("td",{className:"p-2 text-white/80",children:Z.name}),l.jsx("td",{className:"p-2 text-white/60 font-mono",children:Z.id}),l.jsx("td",{className:"p-2 text-white/60",children:Z.level}),l.jsx("td",{className:"p-2 text-white/60",children:Z.reportsTo})]},$e))})]})}),Qe&&me.total>0&&l.jsxs("div",{children:[l.jsxs("div",{className:"flex justify-between text-[10px] text-white/40 mb-1",children:[l.jsx("span",{children:"Hiring..."}),l.jsxs("span",{children:[me.done,"/",me.total]})]}),l.jsx("div",{className:"h-1.5 bg-white/10 rounded-full overflow-hidden",children:l.jsx("div",{className:"h-full rounded-full transition-all",style:{width:`${me.done/me.total*100}%`,background:"#2E7D32"}})})]}),l.jsx("div",{className:"text-[10px] text-white/30",children:"Each role will get a random appearance and auto-generated persona. You can customize them later."}),Ee&&l.jsx("div",{className:"text-xs text-red-400 bg-red-900/20 p-2 rounded-lg border border-red-800/30",children:Ee})]})]})}),l.jsxs("div",{className:"flex justify-between px-5 pb-5",children:[l.jsxs("div",{children:[u==="single"&&ee>1&&l.jsx("button",{onClick:()=>W(ee-1),className:"px-4 py-2 text-sm rounded-lg border border-white/15 text-white/60 hover:bg-white/5 cursor-pointer",children:"Back"}),u==="bulk"&&Et==="review"&&l.jsx("button",{onClick:()=>$n("input"),disabled:Qe,className:"px-4 py-2 text-sm rounded-lg border border-white/15 text-white/60 hover:bg-white/5 cursor-pointer disabled:opacity-40",children:"Back"}),u==="store"&&H==="review"&&l.jsx("button",{onClick:()=>{R("browse"),E(null),De("")},disabled:Qe,className:"px-4 py-2 text-sm rounded-lg border border-white/15 text-white/60 hover:bg-white/5 cursor-pointer disabled:opacity-40",children:"Back"})]}),l.jsxs("div",{className:"flex gap-3",children:[l.jsx("button",{onClick:n,className:"px-4 py-2 text-sm rounded-lg border border-white/15 text-white/60 hover:bg-white/5 cursor-pointer",children:"Cancel"}),u==="single"?ee<To?l.jsx("button",{onClick:()=>W(ee+1),disabled:!bt(ee),className:"px-5 py-2 text-sm text-white rounded-lg font-semibold cursor-pointer disabled:opacity-40 disabled:cursor-not-allowed",style:{background:"#2E7D32"},children:"Next"}):l.jsx("button",{onClick:Ve,disabled:Qe,className:"px-5 py-2 text-sm text-white rounded-lg font-semibold cursor-pointer disabled:opacity-40 disabled:cursor-not-allowed",style:{background:"#2E7D32"},children:Qe?"Hiring...":"HIRE"}):u==="bulk"?Et==="input"?l.jsxs("button",{onClick:()=>$n("review"),disabled:!Be,className:"px-5 py-2 text-sm text-white rounded-lg font-semibold cursor-pointer disabled:opacity-40 disabled:cursor-not-allowed",style:{background:"#2E7D32"},children:["Review (",_e.length,")"]}):l.jsx("button",{onClick:Re,disabled:Qe,className:"px-5 py-2 text-sm text-white rounded-lg font-semibold cursor-pointer disabled:opacity-40 disabled:cursor-not-allowed",style:{background:"#2E7D32"},children:Qe?`Hiring ${me.done}/${me.total}...`:`HIRE ALL (${_e.length})`}):H==="review"?l.jsx("button",{onClick:Bt,disabled:Qe||!I.trim()||!X.trim()||e.some(Z=>Z.id===X),className:"px-5 py-2 text-sm text-white rounded-lg font-semibold cursor-pointer disabled:opacity-40 disabled:cursor-not-allowed",style:{background:"#2E7D32"},children:Qe?"Hiring...":"HIRE"}):null]})]})]})]})}function e6({onLogin:e}){const[n,a]=v.useState(""),[i,o]=v.useState(!1),[u,d]=v.useState(""),f=()=>{const m=n.trim();if(m){if(!/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(m)){d("Invalid token format");return}e(m)}};return l.jsxs("div",{className:"rounded-lg border border-white/10 bg-white/[0.03] p-3 space-y-2",children:[l.jsx("div",{className:"text-[11px] text-white/50",children:"Sign in to vote, publish, and manage your characters."}),i?l.jsxs("div",{className:"space-y-1.5",children:[l.jsxs("div",{className:"flex gap-2",children:[l.jsx("input",{value:n,onChange:m=>{a(m.target.value),d("")},onKeyDown:m=>{m.key==="Enter"&&f()},placeholder:"Paste your token here...",className:"flex-1 px-2 py-1.5 rounded-lg border border-white/10 bg-white/5 text-xs text-white/90 font-mono placeholder-white/20 focus:outline-none focus:border-amber-800/40",autoFocus:!0}),l.jsx("button",{onClick:f,disabled:!n.trim(),className:"px-3 py-1.5 text-[11px] font-semibold rounded-lg cursor-pointer text-green-400 bg-green-900/20 border border-green-800/30 hover:bg-green-900/40 disabled:opacity-30 transition-colors",children:"Sign in"})]}),u&&l.jsx("div",{className:"text-[10px] text-red-400",children:u}),l.jsx("button",{onClick:o.bind(null,!1),className:"text-[10px] text-white/30 hover:text-white/50 cursor-pointer",children:"Cancel"})]}):l.jsxs("div",{className:"flex gap-2",children:[l.jsx("button",{onClick:o.bind(null,!0),className:"px-3 py-1.5 text-[11px] font-semibold rounded-lg cursor-pointer text-amber-400 bg-amber-900/20 border border-amber-800/30 hover:bg-amber-900/40 transition-colors",children:"Paste Token"}),l.jsx("span",{className:"text-[10px] text-white/20 self-center",children:"from Settings → Token"})]})]})}function t6({char:e,isHired:n,onSelect:a,onVote:i,onDelete:o,fetching:u,token:d}){const[f,m]=v.useState(!1),h=d&&e.publisher_id===d,x=!!d;return l.jsxs("div",{className:"flex items-center gap-3 p-3 rounded-xl border border-white/10 bg-white/[0.03] hover:bg-white/[0.06] transition-colors group",children:[l.jsxs("div",{className:"flex flex-col items-center gap-0.5 shrink-0 w-8",children:[l.jsx("button",{onClick:g=>{g.stopPropagation(),i(1)},disabled:!x,className:`text-[14px] leading-none transition-colors ${x?"cursor-pointer":"cursor-not-allowed opacity-30"} ${e.my_vote===1?"text-green-400":"text-white/20 hover:text-green-400/60"}`,title:x?"Upvote":"Sign in to vote",children:"▲"}),l.jsx("span",{className:`text-[11px] font-bold tabular-nums ${(e.vote_score??0)>0?"text-green-400/80":(e.vote_score??0)<0?"text-red-400/80":"text-white/30"}`,children:e.vote_score??0}),l.jsx("button",{onClick:g=>{g.stopPropagation(),i(-1)},disabled:!x,className:`text-[14px] leading-none transition-colors ${x?"cursor-pointer":"cursor-not-allowed opacity-30"} ${e.my_vote===-1?"text-red-400":"text-white/20 hover:text-red-400/60"}`,title:x?"Downvote":"Sign in to vote",children:"▼"})]}),l.jsxs("div",{className:"flex-1 min-w-0 cursor-pointer",onClick:a,children:[l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx("span",{className:"text-sm font-semibold text-white/90 truncate",children:e.name}),l.jsx("span",{className:`text-[9px] px-1.5 py-0.5 rounded font-semibold uppercase ${e.level==="c-level"?"bg-amber-900/30 text-amber-400 border border-amber-800/30":"bg-white/5 text-white/40 border border-white/10"}`,children:e.level}),n&&l.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded bg-green-900/20 text-green-400/60 border border-green-800/20",children:"Hired"})]}),e.tagline&&l.jsx("div",{className:"text-[11px] text-white/40 truncate mt-0.5",children:e.tagline}),l.jsxs("div",{className:"flex items-center gap-3 mt-1",children:[l.jsxs("span",{className:"text-[10px] text-white/25",children:[e.installs??0," installs"]}),l.jsxs("span",{className:"text-[10px] text-white/25",children:["v",e.version]}),l.jsx("span",{className:"text-[10px] text-white/25 font-mono",children:e.id})]})]}),l.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[l.jsx("button",{onClick:a,disabled:u,className:"px-3 py-1.5 text-[11px] font-semibold rounded-lg cursor-pointer transition-colors disabled:opacity-40 text-green-400 bg-green-900/20 border border-green-800/30 hover:bg-green-900/40",children:"Hire"}),h&&(f?l.jsxs("div",{className:"flex items-center gap-1",children:[l.jsx("button",{onClick:g=>{g.stopPropagation(),o(),m(!1)},className:"px-2 py-1.5 text-[10px] font-semibold rounded cursor-pointer text-red-400 bg-red-900/30 border border-red-800/40 hover:bg-red-900/50",children:"Confirm"}),l.jsx("button",{onClick:g=>{g.stopPropagation(),m(!1)},className:"px-2 py-1.5 text-[10px] rounded cursor-pointer text-white/40 hover:text-white/60",children:"No"})]}):l.jsx("button",{onClick:g=>{g.stopPropagation(),m(!0)},className:"w-7 h-7 rounded-lg flex items-center justify-center cursor-pointer text-white/15 hover:text-red-400/60 hover:bg-red-900/10 transition-colors opacity-0 group-hover:opacity-100",title:"Delete from store",children:l.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:l.jsx("path",{d:"M3 6h18M19 6v14a2 2 0 01-2 2H7a2 2 0 01-2-2V6M8 6V4a2 2 0 012-2h4a2 2 0 012 2v2"})})}))]})]})}function Fo({label:e,value:n,mono:a}){return l.jsxs("div",{className:"flex justify-between text-sm",children:[l.jsx("span",{className:"text-white/40",children:e}),l.jsx("span",{className:`font-semibold text-white/80 ${a?"font-mono":""}`,children:n})]})}function n6({roleId:e,roleName:n,onClose:a,onConfirm:i}){const[o,u]=v.useState(!1),d=async()=>{u(!0);try{await i(e)}finally{u(!1)}};return l.jsxs(l.Fragment,{children:[l.jsx("div",{className:"fixed inset-0 bg-black/40 z-[60] backdrop-blur-sm",onClick:a}),l.jsxs("div",{className:"fixed top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-[480px] z-[61] bg-[var(--wall)] rounded-2xl shadow-2xl overflow-hidden",children:[l.jsxs("div",{className:"p-5 text-white",style:{background:"linear-gradient(135deg, #B71C1C, #D32F2F)"},children:[l.jsx("div",{className:"text-lg font-bold",children:"Fire Role"}),l.jsxs("div",{className:"text-sm opacity-80 mt-0.5",children:["Remove ",n," (",e,")"]})]}),l.jsxs("div",{className:"p-5",children:[l.jsxs("div",{className:"p-4 rounded-lg border-2 border-red-300 bg-red-50 mb-4",children:[l.jsx("div",{className:"text-sm font-bold text-red-800 mb-1",children:"Warning"}),l.jsxs("div",{className:"text-xs text-red-700 leading-relaxed",children:["This will permanently delete the role directory including",l.jsx("strong",{children:" role.yaml"}),", ",l.jsx("strong",{children:"profile.md"}),", ",l.jsx("strong",{children:"SKILL.md"}),", and all journal entries. This action cannot be undone."]})]}),l.jsxs("div",{className:"text-sm text-gray-600",children:["Are you sure you want to fire ",l.jsx("strong",{children:n}),"?"]})]}),l.jsxs("div",{className:"flex justify-end gap-3 px-5 pb-5",children:[l.jsx("button",{onClick:a,className:"px-4 py-2 text-sm rounded-lg border border-gray-300 hover:bg-gray-50 cursor-pointer",children:"Cancel"}),l.jsx("button",{onClick:d,disabled:o,className:"px-5 py-2 text-sm text-white rounded-lg font-semibold cursor-pointer disabled:opacity-40 disabled:cursor-not-allowed",style:{background:"#B71C1C"},children:o?"Removing...":"Confirm Fire"})]})]})]})}const r6={cto:"🏗️",cbo:"📊",pm:"📋",engineer:"⚙️",designer:"🎨",qa:"🔍"};function a6({roleId:e,title:n,roleColor:a,active:i,isWave:o,isWaveStreaming:u,onClick:d,onClose:f,"data-session-id":m}){const h=o?"#F59E0B":a;return l.jsxs("button",{onClick:d,"data-session-id":m,className:`flex items-center gap-1.5 px-3 py-1.5 text-[11px] rounded-t-lg shrink-0 cursor-pointer transition-colors max-w-[180px] group ${i?"bg-[var(--terminal-bg)] text-[var(--terminal-text)]":"bg-[var(--terminal-inline-bg)] text-[var(--terminal-text-secondary)] hover:text-[var(--terminal-text)] hover:bg-[var(--terminal-surface)]"}`,style:i?{borderTop:`2px solid ${h}`}:void 0,children:[o&&u&&l.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-amber-400 animate-pulse shrink-0"}),l.jsx("span",{className:"text-xs",children:r6[e]??"👤"}),l.jsx("span",{className:`truncate ${o?"text-amber-400/90":""}`,children:n}),l.jsx("span",{onClick:f,className:"ml-auto text-[var(--terminal-text-muted)] hover:text-[var(--terminal-text-secondary)] text-sm leading-none",children:"×"})]})}function l6({content:e,streaming:n}){let a=e;return n&&(e.match(/```/g)??[]).length%2!==0&&(a+="\n```"),l.jsx("div",{className:"terminal-markdown",children:l.jsx(Om,{remarkPlugins:[Hm],components:{code:i6,table:({children:i})=>l.jsx("div",{className:"overflow-x-auto my-2",children:l.jsx("table",{className:"terminal-table",children:i})})},children:a})})}function i6({className:e,children:n,...a}){const i=/language-(\w+)/.exec(e??"");return i||typeof n=="string"&&n.includes(`
|
|
90
90
|
`)?l.jsx(s6,{language:i==null?void 0:i[1],children:n}):l.jsx("code",{className:"terminal-inline-code",...a,children:n})}function s6({children:e,language:n}){const[a,i]=v.useState(!1),o=String(e).replace(/\n$/,""),u=()=>{navigator.clipboard.writeText(o),i(!0),setTimeout(()=>i(!1),1500)};return l.jsxs("div",{className:"terminal-code-block group relative my-2",children:[n&&l.jsx("div",{className:"text-[10px] text-[var(--terminal-text-muted)] px-3 pt-1.5",children:n}),l.jsx("button",{onClick:u,className:"absolute top-1.5 right-2 text-[10px] text-[var(--terminal-text-muted)] hover:text-[var(--terminal-text-secondary)] opacity-0 group-hover:opacity-100 transition-opacity cursor-pointer",children:a?"Copied!":"Copy"}),l.jsx("pre",{className:"overflow-x-auto p-3 text-xs leading-relaxed",children:l.jsx("code",{children:o})})]})}const o6={cto:"🏗️",cbo:"📊",pm:"📋",engineer:"⚙️",designer:"🎨",qa:"🔍"};function c6({attachments:e}){const[n,a]=v.useState(null);return e.length===0?null:l.jsxs(l.Fragment,{children:[l.jsx("div",{className:"flex flex-wrap gap-2 mb-2",children:e.map((i,o)=>l.jsxs("button",{onClick:()=>a(o),className:"relative w-20 h-20 rounded-lg overflow-hidden border border-[var(--terminal-border)] bg-[var(--terminal-inline-bg)] cursor-pointer hover:border-[var(--terminal-border-hover)] transition-colors",children:[l.jsx("img",{src:`data:${i.mediaType};base64,${i.data}`,alt:i.name,className:"w-full h-full object-cover"}),l.jsx("div",{className:"absolute bottom-0 left-0 right-0 bg-black/60 text-[8px] text-white truncate px-1 py-0.5",children:i.name})]},o))}),n!==null&&l.jsx("div",{className:"fixed inset-0 z-[100] bg-black/80 flex items-center justify-center",onClick:()=>a(null),children:l.jsxs("div",{className:"relative max-w-[90vw] max-h-[90vh]",children:[l.jsx("img",{src:`data:${e[n].mediaType};base64,${e[n].data}`,alt:e[n].name,className:"max-w-full max-h-[90vh] object-contain rounded-lg"}),l.jsx("button",{onClick:()=>a(null),className:"absolute top-2 right-2 w-8 h-8 rounded-full bg-black/70 text-white flex items-center justify-center cursor-pointer hover:bg-black/90",children:"x"}),l.jsx("div",{className:"absolute bottom-2 left-1/2 -translate-x-1/2 bg-black/70 text-white text-sm px-3 py-1 rounded",children:e[n].name})]})})]})}function Fh(e,n){return n?n.file_path?String(n.file_path).replace(/^.*\/(?=[^/]+\/)/,""):n.path?String(n.path).replace(/^.*\/(?=[^/]+\/)/,""):n.pattern?String(n.pattern):n.command?String(n.command).slice(0,60):n.query?String(n.query).slice(0,60):n.url?String(n.url).slice(0,60):"":""}function u6(e){const n=[];let a="";for(const i of e)if(i.type==="thinking")i.text&&(a=i.text),n.length===0||n[n.length-1].type!=="thinking"?n.push({type:"thinking",text:i.text}):n[n.length-1].text=i.text;else if(i.type==="tool")n.push({type:"tool",toolName:i.toolName,toolSummary:Fh(i.toolName??"",i.toolInput),toolInput:i.toolInput});else if(i.type==="dispatch")n.push({type:"dispatch",roleId:i.roleId,task:i.task});else if(i.type==="dispatch:progress"){const o=n.length>0?n[n.length-1]:null;(o==null?void 0:o.type)==="dispatch:progress"&&o.roleId===i.roleId?i.progressType==="tool"?(o.toolName=i.toolName,o.toolSummary=Fh(i.toolName??"",i.toolInput),o.progressType="tool"):i.progressType==="thinking"?(o.text=i.text,o.progressType="thinking"):i.progressType==="text"?(o.text=i.text,o.progressType="text"):(i.progressType==="done"||i.progressType==="error")&&(o.progressType=i.progressType):n.push({type:"dispatch:progress",roleId:i.roleId,progressType:i.progressType,text:i.text,toolName:i.toolName,toolSummary:i.toolName?Fh(i.toolName,i.toolInput):void 0})}if(a){const i=n.filter(o=>o.type==="thinking");i.length>0&&(i[i.length-1].text=a)}return n}function d6({event:e,isStreaming:n}){var o,u,d;const[a,i]=v.useState(!1);switch(e.type){case"thinking":return l.jsxs("div",{className:"stream-event-thinking",children:[l.jsxs("div",{className:"stream-event-thinking-header",onClick:()=>i(!a),children:[l.jsx("span",{className:"stream-event-thinking-icon"}),l.jsxs("span",{className:"stream-event-thinking-label",children:["thinking",n?"...":""]}),e.text&&!n&&l.jsx("span",{className:"stream-event-thinking-toggle",children:a?"▾":"▸"})]}),(n||a)&&e.text&&l.jsx("div",{className:"stream-event-thinking-content",children:e.text.slice(-500)})]});case"tool":return l.jsxs("div",{className:"stream-event-tool",children:[l.jsx("span",{className:"stream-event-tool-badge",children:e.toolName}),e.toolSummary&&l.jsx("span",{className:"stream-event-tool-path",children:e.toolSummary}),e.toolInput&&l.jsx("span",{className:"stream-event-tool-toggle",onClick:()=>i(!a),children:a?"▾":"▸"}),a&&e.toolInput&&l.jsx("div",{className:"stream-event-tool-detail",children:JSON.stringify(e.toolInput,null,1).slice(0,300)})]});case"dispatch":return l.jsxs("div",{className:"stream-event-dispatch",children:[l.jsxs("span",{className:"stream-event-dispatch-badge",children:["→"," ",(o=e.roleId)==null?void 0:o.toUpperCase()]}),l.jsx("span",{className:"stream-event-dispatch-task",children:(u=e.task)==null?void 0:u.slice(0,80)})]});case"dispatch:progress":return l.jsxs("div",{className:"stream-event-dispatch-progress",children:[l.jsx("span",{className:"stream-event-dispatch-progress-role",children:(d=e.roleId)==null?void 0:d.toUpperCase()}),e.progressType==="thinking"&&l.jsxs("span",{className:"stream-event-dispatch-progress-status",children:["thinking",n?"...":""]}),e.progressType==="tool"&&l.jsxs(l.Fragment,{children:[l.jsx("span",{className:"stream-event-tool-badge",children:e.toolName}),e.toolSummary&&l.jsx("span",{className:"stream-event-tool-path",children:e.toolSummary})]}),e.progressType==="text"&&e.text&&l.jsx("span",{className:"stream-event-dispatch-progress-status",children:"responding..."}),e.progressType==="done"&&l.jsx("span",{className:"stream-event-dispatch-progress-done",children:"done"}),e.progressType==="error"&&l.jsx("span",{className:"stream-event-dispatch-progress-error",children:"error"})]});default:return null}}function f6({events:e,isStreaming:n}){const[a,i]=v.useState(!1);if(e.length===0)return null;const o=u6(e);if(o.length===0)return null;const u=e.filter(w=>w.type==="thinking").length,d=e.filter(w=>w.type==="tool"),f=e.filter(w=>w.type==="dispatch"||w.type==="dispatch:progress"),m=e.filter(w=>w.type==="turn").reduce((w,b)=>Math.max(w,b.turn??0),0),h=[];if(u>0&&h.push("thinking"),d.length>0){const w=[...new Set(d.map(b=>b.toolName))];w.length<=3?h.push(w.join(", ")):h.push(`${d.length} tool calls`)}f.length>0&&h.push(`${f.length} dispatch`),m>1&&h.push(`${m} turns`);const x=h.join(" · "),g=!a;return l.jsxs("div",{className:"stream-activity-log",children:[l.jsxs("div",{className:"stream-activity-header",onClick:()=>i(!a),children:[n&&l.jsx("span",{className:"stream-activity-pulse"}),l.jsxs("span",{className:"stream-activity-summary",children:[a?"▸":"▾"," ",x,n?"...":""]})]}),g&&l.jsx("div",{className:"stream-activity-events",children:o.map((w,b)=>l.jsx(d6,{event:w,isStreaming:n&&b===o.length-1},b))})]})}function h6(e){return e.map(n=>({type:n.type==="tool:start"?"tool":n.type==="dispatch:start"?"dispatch":n.type,timestamp:new Date(n.ts).getTime(),text:n.data.text,toolName:n.data.name,toolInput:n.data.input,roleId:n.data.roleId,task:n.data.task}))}function m6({message:e,roleId:n,roleColor:a}){const i=e.from==="ceo",o=e.type==="system",u=e.status==="streaming";if(o)return l.jsx("div",{className:"flex justify-center my-2",children:l.jsx("div",{className:"text-[10px] text-[var(--terminal-text-muted)] bg-[var(--terminal-inline-bg)] px-3 py-1 rounded-full",children:e.content})});if(i)return l.jsx("div",{className:"flex justify-end mb-3",children:l.jsxs("div",{className:"max-w-[85%]",children:[l.jsx("div",{className:"text-[10px] text-[var(--terminal-text-muted)] text-right mb-1",children:"CEO"}),e.attachments&&e.attachments.length>0&&l.jsx("div",{className:"flex justify-end mb-1",children:l.jsx(c6,{attachments:e.attachments})}),l.jsxs("div",{className:"bg-[var(--terminal-surface-light)] rounded-xl rounded-tr-sm px-4 py-2.5 text-sm text-[var(--terminal-text)] leading-relaxed",children:[e.type==="directive"&&l.jsx("span",{className:"text-amber-400 text-[10px] font-bold mr-1.5",children:"DO"}),e.content]})]})});const d=e.streamEvents??(e.events?h6(e.events):void 0),f=((d==null?void 0:d.length)??0)>0,m=!!e.thinking,h=m&&!e.content&&u&&!f;return l.jsxs("div",{className:"flex gap-2.5 mb-3",children:[l.jsx("div",{className:"w-7 h-7 rounded-lg flex items-center justify-center text-sm shrink-0 mt-5",style:{background:`${a}33`},children:o6[n]??"👤"}),l.jsxs("div",{className:"max-w-[85%] min-w-0",children:[l.jsx("div",{className:"text-[10px] text-[var(--terminal-text-muted)] mb-1",children:n.toUpperCase()}),f&&l.jsx(f6,{events:d,isStreaming:u}),m&&!f&&l.jsxs("details",{open:h,className:"mb-1",children:[l.jsxs("summary",{className:"text-[10px] text-purple-400/70 cursor-pointer select-none flex items-center gap-1",children:[h&&l.jsx("span",{className:"inline-block w-1.5 h-1.5 rounded-full bg-purple-400 animate-pulse"}),"thinking",h?"...":` (${e.thinking.length} chars)`]}),l.jsx("div",{className:"text-[11px] text-[var(--terminal-text-muted)] leading-relaxed mt-1 pl-2 border-l border-purple-400/20 max-h-32 overflow-y-auto",children:e.thinking.slice(-500)})]}),l.jsxs("div",{className:"rounded-xl rounded-tl-sm px-4 py-2.5 text-sm text-[var(--terminal-text)] leading-relaxed",style:{borderLeft:`3px solid ${a}`,background:"var(--terminal-surface)"},children:[e.content?l.jsx(l6,{content:e.content,streaming:u}):u&&!m?l.jsxs("span",{className:"typing-dots",children:[l.jsx("span",{className:"typing-dot"}),l.jsx("span",{className:"typing-dot"}),l.jsx("span",{className:"typing-dot"})]}):u&&m?l.jsxs("span",{className:"typing-dots",children:[l.jsx("span",{className:"typing-dot"}),l.jsx("span",{className:"typing-dot"}),l.jsx("span",{className:"typing-dot"})]}):null,u&&e.content&&l.jsx("span",{className:"inline-block w-1.5 h-3.5 bg-[var(--terminal-text-secondary)] animate-pulse ml-0.5 align-middle"})]}),e.status==="error"&&l.jsx("div",{className:"text-[10px] text-red-400 mt-1",children:"Error occurred"}),e.status==="done"&&(e.turns||e.tokens)&&l.jsxs("div",{className:"text-[9px] text-[var(--terminal-text-muted)] mt-1 flex gap-2",children:[e.turns&&l.jsxs("span",{children:[e.turns," turns"]}),e.tokens&&l.jsxs("span",{children:[(e.tokens.input+e.tokens.output).toLocaleString()," tokens"]}),e.readOnly&&l.jsx("span",{className:"text-blue-400/60",children:"read-only"})]}),e.knowledgeDebt&&e.knowledgeDebt.length>0&&l.jsxs("div",{className:"mt-1.5 px-3 py-2 rounded-lg text-[10px]",style:{background:"#FFA72615",border:"1px solid #FFA72630"},children:[l.jsxs("div",{className:"font-bold mb-1",style:{color:"#FFA726"},children:["Knowledge Debt (",e.knowledgeDebt.length,")"]}),e.knowledgeDebt.map((x,g)=>l.jsxs("div",{className:"flex gap-1.5 mb-0.5",style:{color:"var(--terminal-text-muted)"},children:[l.jsx("span",{style:{color:"#FFA726"},children:x.type==="orphan"?"⚠":x.type==="no-hub"?"📁":"🔗"}),l.jsxs("span",{children:[x.message,x.file?` (${x.file})`:""]})]},g))]})]})]})}function hv({messages:e,roleId:n,roleColor:a}){var o;const i=v.useRef(null);return v.useEffect(()=>{var u;(u=i.current)==null||u.scrollIntoView({behavior:"smooth"})},[e,(o=e[e.length-1])==null?void 0:o.content]),e.length===0?l.jsxs("div",{className:"flex-1 flex items-center justify-center text-[var(--terminal-text-muted)] text-sm",children:["Start a conversation with ",n.toUpperCase()]}):l.jsxs("div",{className:"flex-1 overflow-y-auto p-4 terminal-scrollbar",children:[e.map(u=>l.jsx(m6,{message:u,roleId:n,roleColor:a},u.id)),l.jsx("div",{ref:i})]})}const p6=5*1024*1024,x6=["image/png","image/jpeg","image/gif","image/webp"];function Qm({mode:e,onModeChange:n,onSend:a,disabled:i,disabledReason:o,onStop:u}){const[d,f]=v.useState(""),[m,h]=v.useState([]),[x,g]=v.useState(!1),[w,b]=v.useState(null),j=v.useRef(null),k=v.useRef(null),E=v.useRef(!1);v.useEffect(()=>{const $=j.current;$&&($.style.height="0",$.style.height=Math.min($.scrollHeight,120)+"px")},[d]),v.useEffect(()=>{if(w){const $=setTimeout(()=>b(null),3e3);return()=>clearTimeout($)}},[w]);const C=v.useCallback(async $=>x6.includes($.type)?$.size>p6?(b(`File too large: ${($.size/1024/1024).toFixed(1)}MB. Max 5MB.`),null):new Promise(L=>{const Y=new FileReader;Y.onload=()=>{const ee=Y.result.split(",")[1];L({type:"image",data:ee,name:$.name,mediaType:$.type})},Y.onerror=()=>{b("Failed to read file"),L(null)},Y.readAsDataURL($)}):(b(`Unsupported format: ${$.type}. Use PNG, JPG, GIF, or WebP.`),null),[]),N=v.useCallback(async $=>{const L=Array.from($),Y=[];for(const se of L){const ee=await C(se);ee&&Y.push(ee)}Y.length>0&&h(se=>[...se,...Y])},[C]),_=v.useCallback($=>{$.preventDefault(),$.stopPropagation(),g(!0)},[]),z=v.useCallback($=>{$.preventDefault(),$.stopPropagation(),g(!1)},[]),H=v.useCallback($=>{$.preventDefault(),$.stopPropagation(),g(!1);const L=$.dataTransfer.files;L.length>0&&N(L)},[N]),R=v.useCallback($=>{const L=$.clipboardData.items,Y=[];for(let se=0;se<L.length;se++){const ee=L[se];if(ee.type.startsWith("image/")){const W=ee.getAsFile();W&&Y.push(W)}}Y.length>0&&($.preventDefault(),N(Y))},[N]),I=v.useCallback($=>{const L=$.target.files;L&&L.length>0&&N(L),$.target.value=""},[N]),q=v.useCallback($=>{h(L=>L.filter((Y,se)=>se!==$))},[]),X=()=>{const $=d.trim();!$&&m.length===0||i||(a($,m.length>0?m:void 0),f(""),h([]))},A=$=>{if($.key==="Enter"&&!$.shiftKey){if(E.current)return;$.preventDefault(),X()}};return l.jsxs("div",{className:`border-t border-[var(--terminal-border)] p-3 shrink-0 transition-colors ${x?"bg-[var(--terminal-surface-light)] border-amber-500/50":""}`,onDragOver:_,onDragLeave:z,onDrop:H,children:[w&&l.jsx("div",{className:"text-[10px] text-red-400 mb-2 text-center",children:w}),o&&l.jsx("div",{className:"text-[10px] text-amber-400/70 mb-2 text-center",children:o}),m.length>0&&l.jsx("div",{className:"flex flex-wrap gap-2 mb-2",children:m.map(($,L)=>l.jsxs("div",{className:"relative group w-16 h-16 rounded-lg overflow-hidden border border-[var(--terminal-border)] bg-[var(--terminal-inline-bg)]",children:[l.jsx("img",{src:`data:${$.mediaType};base64,${$.data}`,alt:$.name,className:"w-full h-full object-cover"}),l.jsx("button",{onClick:()=>q(L),className:"absolute top-0.5 right-0.5 w-4 h-4 rounded-full bg-black/70 text-white text-xs flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity cursor-pointer",children:"x"}),l.jsx("div",{className:"absolute bottom-0 left-0 right-0 bg-black/60 text-[8px] text-white truncate px-1 py-0.5",children:$.name})]},L))}),x&&l.jsx("div",{className:"text-[11px] text-amber-400 text-center mb-2",children:"Drop image here"}),l.jsxs("div",{className:"flex items-end gap-2",children:[l.jsxs("div",{className:"flex rounded-lg overflow-hidden border border-[var(--terminal-border)] shrink-0",children:[l.jsx("button",{onClick:()=>n("talk"),className:`px-2.5 py-1.5 text-[11px] font-semibold cursor-pointer transition-colors ${e==="talk"?"bg-[var(--desk-wood)] text-white":"bg-[var(--terminal-inline-bg)] text-[var(--terminal-text-secondary)] hover:text-[var(--terminal-text)]"}`,children:"Talk"}),l.jsx("button",{onClick:()=>n("do"),className:`px-2.5 py-1.5 text-[11px] font-semibold cursor-pointer transition-colors ${e==="do"?"bg-amber-700 text-white":"bg-[var(--terminal-inline-bg)] text-[var(--terminal-text-secondary)] hover:text-[var(--terminal-text)]"}`,children:"Do"})]}),l.jsx("button",{onClick:()=>{var $;return($=k.current)==null?void 0:$.click()},disabled:i,className:"w-8 h-8 rounded-lg bg-[var(--terminal-inline-bg)] border border-[var(--terminal-border)] text-[var(--terminal-text-muted)] flex items-center justify-center shrink-0 cursor-pointer hover:bg-[var(--terminal-surface-light)] hover:text-[var(--terminal-text-secondary)] disabled:opacity-30 disabled:cursor-not-allowed transition-colors",title:"Attach image (PNG, JPG, GIF, WebP)",children:l.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:l.jsx("path",{d:"M21.44 11.05l-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 0 1 5.66 5.66l-9.2 9.19a2 2 0 0 1-2.83-2.83l8.49-8.48"})})}),l.jsx("input",{ref:k,type:"file",accept:"image/png,image/jpeg,image/gif,image/webp",multiple:!0,onChange:I,className:"hidden"}),l.jsx("textarea",{ref:j,value:d,onChange:$=>f($.target.value),onKeyDown:A,onCompositionStart:()=>{E.current=!0},onCompositionEnd:()=>{E.current=!1},onPaste:R,placeholder:i?"Waiting...":e==="talk"?"Ask something...":"Give a directive...",disabled:i,rows:1,className:"flex-1 bg-[var(--terminal-inline-bg)] border border-[var(--terminal-border)] rounded-lg px-3 py-2 text-sm text-[var(--terminal-text)] placeholder:text-[var(--terminal-text-muted)] resize-none focus:outline-none focus:border-[var(--terminal-border-hover)] disabled:opacity-40 terminal-scrollbar"}),i&&u&&l.jsx("button",{onClick:u,className:"w-8 h-8 rounded-lg bg-red-900/40 text-red-400 flex items-center justify-center shrink-0 cursor-pointer hover:bg-red-900/60 hover:text-red-300 transition-colors",title:"Stop",children:l.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"currentColor",children:l.jsx("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"})})}),l.jsx("button",{onClick:X,disabled:i||!d.trim()&&m.length===0,className:"w-8 h-8 rounded-lg bg-[var(--terminal-surface-light)] text-[var(--terminal-text-secondary)] flex items-center justify-center shrink-0 cursor-pointer hover:bg-[var(--desk-wood)] hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors",children:l.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[l.jsx("path",{d:"M22 2L11 13"}),l.jsx("path",{d:"M22 2L15 22L11 13L2 9L22 2Z"})]})})]})]})}const g6={ceo:"#FFB300",cto:"#1565C0",cbo:"#E65100",pm:"#2E7D32",engineer:"#4A148C",designer:"#AD1457",qa:"#00695C","data-analyst":"#0277BD"},mv={ceo:"CEO (You)",cto:"CTO",cbo:"CBO",pm:"PM",engineer:"Engineer",designer:"Designer",qa:"QA","data-analyst":"Data Analyst"};function Kg(e){return new Date(e).toLocaleTimeString("ko-KR",{hour:"2-digit",minute:"2-digit"})}function y6({msg:e}){const n=g6[e.roleId]??"#888",a=mv[e.roleId]??e.roleId;if(e.type==="dispatch"){const i=e.text.includes("WAVE"),o=e.text.includes("completed")||e.text.includes("완료"),u=i?"📡":o?"✓":"→",d=o?"text-green-400/70":"text-[var(--terminal-text-muted)]";return l.jsxs("div",{className:"flex items-start gap-2 px-3 py-1 hover:bg-white/[0.02]",children:[l.jsx("span",{className:"text-[10px] text-[var(--terminal-text-muted)] shrink-0 w-10 text-right mt-0.5",children:Kg(e.ts)}),l.jsx("span",{className:"text-[10px] shrink-0 mt-0.5",children:u}),l.jsx("span",{className:`text-[11px] ${d}`,children:e.text})]})}return l.jsxs("div",{className:"flex items-start gap-2 px-3 py-1.5 hover:bg-white/[0.02]",children:[l.jsx("span",{className:"text-[10px] text-[var(--terminal-text-muted)] shrink-0 w-10 text-right mt-0.5",children:Kg(e.ts)}),l.jsxs("div",{className:"flex-1 min-w-0",children:[l.jsx("span",{className:"text-[11px] font-semibold mr-1.5",style:{color:n},children:a}),l.jsx("span",{className:"text-xs text-[var(--terminal-text-secondary)]",children:e.text})]})]})}function b6({channel:e,allRoles:n,onUpdateMembers:a,onUpdateTopic:i,onSendMessage:o}){const u=v.useRef(null),d=v.useRef(null),[f,m]=v.useState("");v.useEffect(()=>{var _;const C=d.current;if(!C)return;C.scrollHeight-C.scrollTop-C.clientHeight<80&&((_=u.current)==null||_.scrollIntoView({behavior:"smooth"}))},[e.messages.length]);const[h,x]=v.useState(!1),[g,w]=v.useState(!1),[b,j]=v.useState(""),k=o&&e.id!=="general",E=()=>{!f.trim()||!o||(o(e.id,f.trim()),m(""),setTimeout(()=>{var C;return(C=u.current)==null?void 0:C.scrollIntoView({behavior:"smooth"})},50))};return l.jsxs("div",{className:"flex-1 flex flex-col min-h-0",children:[l.jsxs("div",{ref:d,className:"flex-1 overflow-y-auto terminal-scrollbar py-2 min-h-0",children:[l.jsxs("div",{className:"px-3 py-2 mb-2 border-b border-[var(--terminal-border)] flex items-center gap-2",children:[l.jsx("span",{className:"text-sm font-semibold text-[var(--terminal-text)]",children:e.name}),e.members.length>0&&l.jsx("span",{className:"text-[10px] text-[var(--terminal-text-muted)]",children:e.members.map(C=>mv[C]??C).join(", ")}),e.members.length===0&&l.jsx("span",{className:"text-[10px] text-[var(--terminal-text-muted)]",children:e.isDefault?"system logs":"no members"}),!e.isDefault&&n&&a&&l.jsx("button",{className:"ml-auto text-[10px] px-2 py-0.5 rounded bg-white/5 hover:bg-white/10 text-[var(--terminal-text-muted)]",onClick:()=>x(!h),children:h?"Done":"Invite"})]}),!e.isDefault&&i&&l.jsx("div",{className:"px-3 pb-2 mb-1",children:g?l.jsx("input",{autoFocus:!0,value:b,onChange:C=>j(C.target.value),onKeyDown:C=>{C.key==="Enter"&&(i(e.id,b.trim()),w(!1)),C.key==="Escape"&&w(!1)},onBlur:()=>{i(e.id,b.trim()),w(!1)},placeholder:"Set a topic for this channel...",className:"w-full bg-transparent text-[10px] text-[var(--terminal-text-muted)] outline-none border-b border-[var(--terminal-border)] pb-0.5"}):l.jsx("button",{onClick:()=>{j(e.topic??""),w(!0)},className:"text-[10px] text-[var(--terminal-text-muted)] hover:text-[var(--terminal-text-secondary)] cursor-pointer italic",children:e.topic||"Click to set channel topic..."})}),h&&!e.isDefault&&n&&a&&l.jsx("div",{className:"px-3 pb-2 mb-2 border-b border-[var(--terminal-border)]",children:l.jsx("div",{className:"flex flex-wrap gap-1",children:n.map(C=>{const N=e.members.includes(C.id);return l.jsxs("button",{className:`text-[10px] px-2 py-1 rounded ${N?"bg-white/15 text-[var(--terminal-text)]":"bg-white/5 text-[var(--terminal-text-muted)]"}`,onClick:()=>{const _=N?e.members.filter(z=>z!==C.id):[...e.members,C.id];a(e.id,_)},children:[N?"✓ ":"",C.name]},C.id)})})}),e.messages.length===0&&l.jsx("div",{className:"flex-1 flex flex-col items-center justify-center text-[var(--terminal-text-muted)] text-xs gap-1 py-8",children:l.jsx("span",{children:e.isDefault?"No dispatch events yet":"No messages yet — invite roles to start chatting"})}),e.messages.map(C=>l.jsx(y6,{msg:C},C.id)),l.jsx("div",{ref:u})]}),k&&l.jsx("div",{className:"shrink-0 px-3 py-2 border-t border-[var(--terminal-border)]",children:l.jsxs("div",{className:"flex gap-2 items-center",children:[l.jsx("span",{className:"text-[10px] font-semibold shrink-0",style:{color:"#FFB300"},children:"CEO"}),l.jsx("input",{type:"text",value:f,onChange:C=>m(C.target.value),onKeyDown:C=>{C.key==="Enter"&&!C.shiftKey&&(C.preventDefault(),E())},placeholder:"Say something...",className:"flex-1 px-2 py-1 text-xs rounded border bg-transparent text-[var(--terminal-text)] border-[var(--terminal-border)] outline-none focus:border-[#FFB300]/50"})]})})]})}const Mh={cto:"#1565C0",cbo:"#E65100",pm:"#2E7D32",engineer:"#4A148C",designer:"#AD1457",qa:"#00695C"},v6=400,w6=800;function Qg({sessions:e,activeSessionId:n,roles:a,streamingSessionId:i,width:o,onWidthChange:u,onSwitchSession:d,onCloseSession:f,onCreateSession:m,onClearEmpty:h,onCloseAll:x,onSendMessage:g,onModeChange:w,onStopSession:b,onCloseTerminal:j,onMaximize:k,chatChannels:E,activeChatChannelId:C,onSwitchChatChannel:N,onCreateChatChannel:_,onDeleteChatChannel:z,onUpdateChatMembers:H,onUpdateChatTopic:R,onSendChatMessage:I,unreadChannels:q}){const[X,A]=v.useState(!1),[$,L]=v.useState(!1),[Y,se]=v.useState(!1),[ee,W]=v.useState(""),oe=C!=null,de=E==null?void 0:E.find(Ee=>Ee.id===C),[V,D]=v.useState(!1),[B,U]=v.useState(!1),[T,ie]=v.useState(!1),ge=v.useRef(0),pe=v.useRef(0),ze=v.useRef(null),Ie=e.find(Ee=>Ee.id===n),He=i===n,st=e.filter(Ee=>Ee.messages.length===0).length,Qe=v.useCallback(()=>{const Ee=ze.current;Ee&&(U(Ee.scrollLeft>0),ie(Ee.scrollLeft+Ee.clientWidth<Ee.scrollWidth-1))},[]);v.useEffect(()=>{if(!n||!ze.current)return;const Ee=ze.current.querySelector(`[data-session-id="${n}"]`);Ee&&Ee.scrollIntoView({behavior:"smooth",block:"nearest",inline:"nearest"}),Qe()},[n,e.length,Qe]),v.useEffect(()=>{const Ee=ze.current;if(!Ee)return;Qe(),Ee.addEventListener("scroll",Qe);const De=new ResizeObserver(Qe);return De.observe(Ee),()=>{Ee.removeEventListener("scroll",Qe),De.disconnect()}},[Qe]);const et=v.useCallback(Ee=>{Ee.preventDefault(),ge.current=Ee.clientX,pe.current=o,D(!0);const De=k,yt=()=>{D(!1),document.removeEventListener("mousemove",ut),document.removeEventListener("mouseup",yt)},ut=pt=>{const jt=ge.current-pt.clientX,Wt=pe.current+jt;if(Wt>=window.innerWidth*.6&&De){yt(),De();return}const Ft=Math.min(w6,Math.max(v6,Wt));u==null||u(Ft)};document.addEventListener("mousemove",ut),document.addEventListener("mouseup",yt)},[o,u,k]);return l.jsxs("div",{className:"shrink-0 bg-[var(--terminal-bg)] border-l border-[var(--terminal-border)] flex flex-col h-full relative",style:{width:o},children:[u&&l.jsx("div",{className:`terminal-resize-handle absolute top-0 left-0 w-1 h-full cursor-col-resize z-10 transition-colors ${V?"bg-[var(--terminal-border-hover)]":"bg-transparent"}`,onMouseDown:et}),l.jsxs("div",{className:"flex items-center bg-[var(--terminal-bg-deeper)] border-b border-[var(--terminal-border)] shrink-0",children:[l.jsxs("div",{className:"relative flex-1 min-w-0",children:[B&&l.jsx("div",{className:"absolute left-0 top-0 bottom-0 w-6 bg-gradient-to-r from-[var(--terminal-bg-deeper)] to-transparent z-10 pointer-events-none"}),l.jsxs("div",{ref:ze,className:"flex items-center overflow-x-auto terminal-tab-scroll gap-px px-1 py-1",children:[E==null?void 0:E.map(Ee=>l.jsxs("button",{onClick:()=>{N==null||N(Ee.id)},className:`flex items-center gap-1 px-2.5 py-1.5 text-[11px] rounded-t-lg shrink-0 cursor-pointer transition-colors group ${C===Ee.id?"bg-[var(--terminal-bg)] text-[var(--terminal-text)]":"bg-[var(--terminal-inline-bg)] text-[var(--terminal-text-muted)] hover:text-[var(--terminal-text-secondary)] hover:bg-[var(--terminal-surface)]"}`,style:C===Ee.id?{borderTop:"2px solid #4CAF50"}:void 0,children:[l.jsx("span",{className:"text-[10px]",children:"💬"}),l.jsx("span",{className:"truncate",children:Ee.name}),(q==null?void 0:q.has(Ee.id))&&C!==Ee.id&&l.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-green-400 shrink-0"}),!Ee.isDefault&&l.jsx("span",{onClick:De=>{De.stopPropagation(),z==null||z(Ee.id)},className:"ml-1 text-[var(--terminal-text-muted)] hover:text-[var(--terminal-text-secondary)] text-sm leading-none opacity-0 group-hover:opacity-100",children:"×"})]},Ee.id)),E&&E.length>0&&e.length>0&&l.jsx("div",{className:"w-px h-4 bg-[var(--terminal-border)] shrink-0 mx-1"}),e.map(Ee=>l.jsx(a6,{roleId:Ee.roleId,title:Ee.title,roleColor:Mh[Ee.roleId]??"#666",active:!oe&&Ee.id===n,isWave:Ee.source==="wave",isWaveStreaming:Ee.source==="wave"&&Ee.status==="active",onClick:()=>{N==null||N(null),d(Ee.id)},onClose:De=>{De.stopPropagation(),f(Ee.id)},"data-session-id":Ee.id},Ee.id))]}),T&&l.jsx("div",{className:"absolute right-0 top-0 bottom-0 w-6 bg-gradient-to-l from-[var(--terminal-bg-deeper)] to-transparent z-10 pointer-events-none"})]}),l.jsxs("div",{className:"relative shrink-0",children:[l.jsx("button",{onClick:()=>{A(!X),L(!1)},className:"w-7 h-7 flex items-center justify-center text-[var(--terminal-text-muted)] hover:text-[var(--terminal-text-secondary)] text-lg cursor-pointer",children:"+"}),X&&l.jsxs("div",{className:"absolute top-full right-0 mt-1 bg-[var(--terminal-surface)] border border-[var(--terminal-border)] rounded-lg shadow-xl z-50 py-1 min-w-[200px]",children:[_&&l.jsxs(l.Fragment,{children:[Y?l.jsxs("div",{className:"px-3 py-2 flex items-center gap-1",children:[l.jsx("span",{className:"text-[10px] text-[var(--terminal-text-muted)]",children:"#"}),l.jsx("input",{autoFocus:!0,value:ee,onChange:Ee=>W(Ee.target.value),onKeyDown:Ee=>{Ee.key==="Enter"&&ee.trim()&&(_(ee.trim(),[]),W(""),se(!1),A(!1)),Ee.key==="Escape"&&(se(!1),W(""))},placeholder:"channel name",className:"flex-1 bg-transparent text-xs text-[var(--terminal-text)] outline-none border-b border-[var(--terminal-border)]"})]}):l.jsxs("button",{onClick:()=>se(!0),className:"w-full text-left px-3 py-2 text-xs text-[var(--terminal-text-secondary)] hover:bg-[var(--terminal-surface-light)] cursor-pointer flex items-center gap-2",children:[l.jsx("span",{className:"text-[10px]",children:"💬"}),"New Channel"]}),l.jsx("div",{className:"border-b border-[var(--terminal-border)] my-1"})]}),a.map(Ee=>l.jsxs("button",{onClick:()=>{m(Ee.id),N==null||N(null),A(!1)},className:"w-full text-left px-3 py-2 text-xs text-[var(--terminal-text-secondary)] hover:bg-[var(--terminal-surface-light)] cursor-pointer flex items-center gap-2",children:[l.jsx("span",{className:"w-2 h-2 rounded-full",style:{background:Mh[Ee.id]??"#666"}}),Ee.id.toUpperCase()," — ",Ee.name]},Ee.id))]})]}),l.jsxs("div",{className:"relative shrink-0",children:[l.jsx("button",{onClick:()=>{L(!$),A(!1)},className:"w-7 h-7 flex items-center justify-center text-[var(--terminal-text-muted)] hover:text-[var(--terminal-text-secondary)] text-xs cursor-pointer tracking-tight",title:"Manage sessions",children:"···"}),$&&l.jsxs("div",{className:"absolute top-full right-0 mt-1 bg-[var(--terminal-surface)] border border-[var(--terminal-border)] rounded-lg shadow-xl z-50 py-1 min-w-[200px]",children:[l.jsxs("div",{className:"px-3 py-1.5 text-[10px] text-[var(--terminal-text-muted)] border-b border-[var(--terminal-border)]",children:[e.length," session",e.length!==1?"s":""]}),st>0&&h&&l.jsxs("button",{onClick:()=>{h(),L(!1)},className:"w-full text-left px-3 py-2 text-xs text-[var(--terminal-text-secondary)] hover:bg-[var(--terminal-surface-light)] cursor-pointer",children:["Clear empty sessions (",st,")"]}),e.length>0&&x&&l.jsx("button",{onClick:()=>{x(),L(!1)},className:"w-full text-left px-3 py-2 text-xs text-[#E57373] hover:bg-[var(--terminal-surface-light)] cursor-pointer",children:"Close all sessions"}),e.length===0&&l.jsx("div",{className:"px-3 py-2 text-xs text-[var(--terminal-text-muted)]",children:"No sessions"})]})]}),k&&l.jsx("button",{onClick:k,className:"w-7 h-7 flex items-center justify-center text-[var(--terminal-text-muted)] hover:text-[var(--terminal-text-secondary)] text-sm cursor-pointer shrink-0",title:"Maximize (Pro View)",children:"⤢"}),l.jsx("button",{onClick:j,className:"px-2 py-1 text-[var(--terminal-text-muted)] hover:text-[var(--terminal-text-secondary)] text-sm cursor-pointer shrink-0",children:"×"})]}),oe&&de?l.jsx(b6,{channel:de,allRoles:a,onUpdateMembers:H,onUpdateTopic:R,onSendMessage:I}):Ie?l.jsxs(l.Fragment,{children:[l.jsx(hv,{messages:Ie.messages,roleId:Ie.roleId,roleColor:Mh[Ie.roleId]??"#666"}),l.jsx(Qm,{mode:Ie.mode,onModeChange:Ee=>w(Ie.id,Ee),onSend:(Ee,De)=>g(Ie.id,Ee,Ie.mode,De),disabled:He,disabledReason:He?`${Ie.roleId.toUpperCase()} is responding...`:void 0,onStop:He&&b?()=>b(Ie.id):void 0})]}):l.jsx("div",{className:"flex-1 flex items-center justify-center text-[var(--terminal-text-muted)] text-sm",children:"No active session. Click [+] to start."})]})}function k6(){const e=v.useRef(null),n=v.useCallback(()=>{var i;(i=e.current)==null||i.abort(),e.current=null},[]);return{sendMessage:v.useCallback((i,o,u,d,f)=>{n();const m=new AbortController;return e.current=m,fetch(`/api/exec/session/${i}/message`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:o,mode:u,attachments:f}),signal:m.signal}).then(async h=>{var E,C,N,_,z;if(!h.ok||!h.body){d.onError("Failed to connect");return}const x=h.body.getReader(),g=new TextDecoder;let w="",b=Date.now();const j=6e4,k=setInterval(()=>{Date.now()-b>j&&(clearInterval(k),m.abort(),d.onError("Connection stale — no data received for 60s"))},1e4);try{for(;;){const{done:H,value:R}=await x.read();if(H)break;b=Date.now(),w+=g.decode(R,{stream:!0});const I=w.split(`
|
|
91
91
|
`);w=I.pop()??"";let q="";for(let X=0;X<I.length;X++){const A=I[X];if(A.startsWith("event: ")){q=A.slice(7).trim();continue}if(A.startsWith("data: ")){let $;try{$=JSON.parse(A.slice(6))}catch{q="";continue}switch(q){case"thinking":$.text&&((E=d.onThinking)==null||E.call(d,$.text));break;case"output":$.text&&d.onText($.text);break;case"tool":(C=d.onToolUse)==null||C.call(d,$.name,$.input);break;case"dispatch":(N=d.onDispatch)==null||N.call(d,$.roleId,$.task);break;case"dispatch:progress":(_=d.onDispatchProgress)==null||_.call(d,$.roleId,$.type,$);break;case"turn":(z=d.onTurn)==null||z.call(d,$.turn);break;case"done":d.onDone($);break;case"error":d.onError($.message??"Unknown error");break;default:$.text&&d.onText($.text);break}q=""}}}}finally{clearInterval(k)}}).catch(h=>{h.name!=="AbortError"&&d.onError(h.message)}),{abort:n}},[n]),abort:n}}const pv="tycono-appearances",xm="tycono-theme";function Pg(){try{const e=localStorage.getItem(pv);return e?JSON.parse(e):{}}catch{return{}}}function Rh(e){localStorage.setItem(pv,JSON.stringify(e))}function Zg(){try{const e=localStorage.getItem(xm);if(e&&e in ll)return e}catch{}return"default"}const xv=new Set;for(const e of Object.values(ll))for(const n of Object.keys(e.vars))xv.add(n);function j6(e){var i;const n=(i=ll[e])==null?void 0:i.vars;if(!n)return;const a=document.documentElement;for(const o of xv)o in n||a.style.removeProperty(o);for(const[o,u]of Object.entries(n))a.style.setProperty(o,u)}const zh={mode:"auto",intervalSec:18,dailyBudgetUsd:1},gm="tycono-speech-settings",_h="tycono-language";function S6(){try{const e=localStorage.getItem(gm);return e?{...zh,...JSON.parse(e)}:zh}catch{return zh}}function C6(){const[e,n]=v.useState(Pg),[a,i]=v.useState(Zg),[o,u]=v.useState(S6),[d,f]=v.useState(()=>{try{return localStorage.getItem(_h)??"auto"}catch{return"auto"}}),m=v.useRef(!1);v.useEffect(()=>{m.current||(m.current=!0,ye.getPreferences().then(k=>{const E=Object.keys(k.appearances??{}).length>0||k.theme!=="default";if(k.speech&&(u(C=>({...C,...k.speech})),localStorage.setItem(gm,JSON.stringify(k.speech))),k.language&&(f(k.language),localStorage.setItem(_h,k.language)),E){const C=k.appearances;n(C),Rh(C),k.theme&&k.theme in ll&&(i(k.theme),localStorage.setItem(xm,k.theme))}else{const C=Pg(),N=Zg();(Object.keys(C).length>0||N!=="default")&&ye.updatePreferences({appearances:C,theme:N}).catch(()=>{})}}).catch(()=>{}))},[]),v.useEffect(()=>{j6(a)},[a]);const h=v.useCallback(k=>e[k]??Km(k),[e]),x=v.useCallback((k,E)=>{n(C=>{const N={...C,[k]:E};return Rh(N),ye.updatePreferences({appearances:N}).catch(()=>{}),N})},[]),g=v.useCallback(k=>{n(E=>{const C={...E};return delete C[k],Rh(C),ye.updatePreferences({appearances:C}).catch(()=>{}),C})},[]),w=v.useCallback(k=>{i(k),localStorage.setItem(xm,k),ye.updatePreferences({theme:k}).catch(()=>{})},[]),b=v.useCallback(k=>{u(E=>{const C={...E,...k};return localStorage.setItem(gm,JSON.stringify(C)),ye.updatePreferences({speech:C}).catch(()=>{}),C})},[]),j=v.useCallback(k=>{f(k),localStorage.setItem(_h,k),ye.updatePreferences({language:k}).catch(()=>{})},[]);return{appearances:e,getAppearance:h,setAppearance:x,resetAppearance:g,theme:a,setTheme:w,speechSettings:o,setSpeechSettings:b,language:d,setLanguage:j}}const E6=3e4,N6=3e5;function A6(){var $;const[e,n]=v.useState("akb"),[a,i]=v.useState(null),[o,u]=v.useState("synced"),[d,f]=v.useState([]),[m,h]=v.useState(null),[x,g]=v.useState(!1),w=v.useRef(null),b=v.useRef(null),j=v.useRef(e);j.current=e;const k=v.useCallback(async()=>{try{const L=await ye.getSaveStatus(j.current);i(L),L.noGit?u("no-git"):u(Y=>Y==="saving"?Y:L.dirty?"dirty":"synced")}catch{u("error")}},[]),E=v.useCallback(async()=>{try{const L=await ye.getSyncStatus(j.current);h({ahead:L.ahead,behind:L.behind,branch:L.branch,hasRemote:L.hasRemote})}catch{}},[]),C=v.useCallback(()=>{w.current&&clearInterval(w.current),k(),w.current=setInterval(k,E6),b.current&&clearInterval(b.current),E(),b.current=setInterval(E,N6)},[k,E]);v.useEffect(()=>()=>{w.current&&clearInterval(w.current),b.current&&clearInterval(b.current)},[]);const N=v.useCallback(L=>{n(L),j.current=L,i(null),h(null),f([]),setTimeout(()=>{k(),E()},0)},[k,E]),_=v.useCallback(async L=>{u("saving");try{const Y=await ye.save(L,j.current);return await k(),Y}catch(Y){throw u("error"),Y}},[k]),z=v.useCallback(async()=>{try{const L=await ye.getSaveHistory(20,j.current);f(L)}catch{}},[]),H=v.useCallback(async L=>{u("saving");try{await ye.restoreSave(L,void 0,j.current),await k()}catch(Y){throw u("error"),Y}},[k]),R=v.useCallback(async()=>{g(!0);try{const L=await ye.pull(j.current);return await k(),await E(),L}catch(L){throw L}finally{g(!1)}},[k,E]),I=v.useCallback(async()=>{try{await ye.initGit(),await k()}catch{u("error")}},[k]),q=a?a.modified.length+a.untracked.length:0,X=(($=a==null?void 0:a.lastCommit)==null?void 0:$.date)??null,A=v.useCallback(async()=>{C()},[C]);return{state:o,dirtyCount:q,lastSaved:X,status:a,save:_,history:d,loadHistory:z,restore:H,refresh:A,initGit:I,repo:e,setRepo:N,syncInfo:m,fetchSyncStatus:E,pull:R,pulling:x}}const Jg={cto:["Need to reduce this architecture tech debt...","Don't over-engineer. Keep it minimal.","Performance profiling results are a bit concerning.","Should do a system design review.","If I just strip one abstraction layer, it should work.","Let me check the monitoring dashboard.","Need to go through the code review queue.","It's about time to clean up these module dependencies."],cbo:["Heard the competitor launched a new feature... need to analyze.","Should compile this month's revenue metrics.","It's time to update the market trend report.","Maybe I should benchmark the pricing strategy.","Need to recalculate the ROI.","Let me check the competitor's GitHub star trends.","Thinking about launch timing...","Should re-examine the positioning strategy."],pm:["Is this feature really what users want?","Need to clean up the backlog...","MVP scope keeps expanding.","Analyzing user feedback...","Might need to re-prioritize.","Watch out for scope creep.","Will the roadmap timeline hold...","Should double-check the task dependencies."],engineer:["I want to refactor this code...","Test coverage seems a bit low.","Working code first, perfect code later.","Waiting for PR review...","What could be causing this bug...","Is the build broken?","Need to fix that one type error.","Maybe I should run npm audit."],designer:["This UI flow feels a bit awkward...","Usability first, pretty later.","Need to organize the design system components.","Let me make two quick options and compare.","Should run through the accessibility checklist.","Maybe I should prototype this interaction.","Let me revisit the color palette...","The spacing feels a bit cramped."],qa:['"Works" and "correct" are two different things.',"Organizing edge case scenarios...","Should run the regression test suite.","This part could be converted to automated tests.","Need to go through the pre-release checklist.","Reproducible bug reports are key.","Should run cross-browser tests.","Need to check for performance regressions."],"data-analyst":["Checking the data pipeline status...","Interesting outlier detection pattern.","Need to update the dashboard metrics.","Correlation isn't causation though...","Seems like there is room for SQL query optimization.","It's time for a data quality check."]},ey={cto:["Should I assign more work to the team...","It's time to clean up the architecture debt.","Need to re-examine the tech roadmap.","It's quiet... am I missing something?"],cbo:["It's time to update the market analysis...","Should be preparing the revenue report, but no directives.","Let me check on competitor movements.","It's quiet on the business side..."],pm:["Backlog is pretty quiet... nothing to plan?","It's been a while since we scheduled a sprint.","User feedback must be piling up...","No PRD to write... that's unusual."],engineer:["Nothing to do today... maybe some code reviews.","Task queue is empty. Guess I'll refactor.","Am I missing something?","Should clean up the commit log."],designer:["No design requests coming in. Should I improve something on my own?","Maybe run a UI audit...","Should organize my portfolio.","Let me tidy up the component library."],qa:["No builds to test. Let me improve the automation scripts.","It's quiet... no bugs, or just haven't found them?","Let me review the existing test scenarios.","Should update the test coverage report."],"data-analyst":["No analysis requests coming in...","Maybe I should clean up the data warehouse.","Should verify the past reports."]},D6=[{id:"sup-check-1",relation:"superior-subordinate",minFamiliarity:0,topic:"progress",turns:[{speaker:"A",text:"How's the progress?"},{speaker:"B",text:"Going well. Should be done soon."},{speaker:"A",text:"Good, let me know when it's done."}]},{id:"sup-check-2",relation:"superior-subordinate",minFamiliarity:20,topic:"progress",turns:[{speaker:"A",text:"What are you working on today?"},{speaker:"B",text:"Finishing up what I was doing yesterday."}]},{id:"sub-report-1",relation:"superior-subordinate",minFamiliarity:10,topic:"report",turns:[{speaker:"B",text:"Done with that task from earlier."},{speaker:"A",text:"Nice work. Can you share the results?"},{speaker:"B",text:"Sure, I've updated the docs."}]},{id:"peer-tech-1",relation:"peer",minFamiliarity:20,topic:"tech",turns:[{speaker:"A",text:"What do you think about this design?"},{speaker:"B",text:"I think we could go simpler."},{speaker:"A",text:"Really? Want to look at it together?"}]},{id:"peer-tech-2",relation:"peer",minFamiliarity:30,topic:"tech",turns:[{speaker:"A",text:"Have you used this library before?"},{speaker:"B",text:"Yeah, used it in the last project. It was decent."}]},{id:"close-feedback-1",relation:"peer",minFamiliarity:60,topic:"feedback",turns:[{speaker:"A",text:"Can I be honest with you?"},{speaker:"B",text:"Of course, go ahead."},{speaker:"A",text:"This one feels a bit off. Let's revisit."},{speaker:"B",text:"...Alright. Thanks for the feedback."}]},{id:"clevel-sync-1",relation:"c-level",minFamiliarity:10,topic:"strategy",turns:[{speaker:"A",text:"We need to sync the roadmap with the business timeline."},{speaker:"B",text:"Agreed. I'll have it organized and shared by tomorrow."}]},{id:"clevel-sync-2",relation:"c-level",minFamiliarity:30,topic:"strategy",turns:[{speaker:"A",text:"I have some competitor intel to share."},{speaker:"B",text:"Great, I have a tech update too."},{speaker:"A",text:"Let's sync up when you're free."}]},{id:"casual-coffee",relation:"any",minFamiliarity:30,topic:"casual",turns:[{speaker:"A",text:"Want to grab a coffee?"},{speaker:"B",text:"Sure. Feels like it's going to be a long day."}]},{id:"casual-overtime",relation:"any",minFamiliarity:25,topic:"casual",turns:[{speaker:"A",text:"Working late again..."},{speaker:"B",text:"We're in this together. Hang in there."}]},{id:"casual-lunch",relation:"any",minFamiliarity:35,topic:"casual",turns:[{speaker:"A",text:"What should we get for lunch?"},{speaker:"B",text:"Anything. Feel like we eat the same thing every day."}]},{id:"casual-weekend",relation:"any",minFamiliarity:40,topic:"casual",turns:[{speaker:"A",text:"What did you do this weekend?"},{speaker:"B",text:"Just rested. Was too tired."}]},{id:"bestie-1",relation:"any",minFamiliarity:80,topic:"trust",turns:[{speaker:"A",text:"I'm a bit unsure about this direction..."},{speaker:"B",text:"What's bothering you? Be honest."},{speaker:"A",text:"Thanks. It's nice having someone I can talk to."}]}],T6=18e3,ty=6e3,F6=2500,M6=30*6e4,gv="tycono:relationships";function R6(){try{const e=localStorage.getItem(gv);return e?JSON.parse(e):[]}catch{return[]}}function z6(e){localStorage.setItem(gv,JSON.stringify(e))}function yu(e,n,a){const[i,o]=n<a?[n,a]:[a,n];let u=e.find(d=>d.roleA===i&&d.roleB===o);return u||(u={roleA:i,roleB:o,dispatches:0,wavesTogether:0,conversations:0,familiarity:0,lastInteraction:new Date().toISOString()},e.push(u)),u}function bu(e){return Math.min(100,e.dispatches*5+e.wavesTogether*10+e.conversations*2)}function vu(e){return e[Math.floor(Math.random()*e.length)]}function _6(e,n,a){const i=a.find(f=>f.id===e),o=a.find(f=>f.id===n);if(!i||!o)return null;const u=i.level==="c-level",d=o.level==="c-level";return u&&d?"c-level":i.reportsTo===n||o.reportsTo===e?"superior-subordinate":(i.reportsTo===o.reportsTo,"peer")}function B6(e,n){return e.relation==="any"?!0:e.relation===n}function O6({roles:e,roleStatuses:n,activeExecs:a,getStandupSpeech:i}){const[o,u]=v.useState(new Map),[d,f]=v.useState(R6),m=v.useRef({}),h=v.useRef(null),x=v.useRef(e),g=v.useRef(n),w=v.useRef(a),b=v.useRef(i),j=v.useRef(d);x.current=e,g.current=n,w.current=a,b.current=i,j.current=d,v.useEffect(()=>{const z=Date.now();for(const[H,R]of Object.entries(n))R==="working"&&(m.current[H]=z)},[n]),v.useEffect(()=>{z6(d)},[d]);const k=v.useCallback(z=>{const H=g.current[z],R=w.current.find($=>$.roleId===z);if(H==="working"&&(R!=null&&R.task))return null;const I=b.current(z);if(I&&Math.random()<.3)return{text:I,type:"work",ts:Date.now()};const q=Date.now(),X=m.current[z]??0;if(q-X>M6&&Math.random()<.5){const $=ey[z]??ey.engineer;return{text:vu($),type:"guilt",ts:q}}const A=Jg[z]??Jg.engineer;return{text:vu(A),type:"personality",ts:q}},[]),E=v.useCallback(z=>{if(h.current)return!1;const H=z.filter(oe=>g.current[oe.id]!=="working");if(H.length<2)return!1;const R=[...H].sort(()=>Math.random()-.5),I=R[0],q=R[1],X=_6(I.id,q.id,z);if(!X)return!1;const A=yu(j.current,I.id,q.id),$=bu(A),L=D6.filter(oe=>B6(oe,X)&&$>=oe.minFamiliarity);if(L.length===0)return!1;const Y=vu(L);let se=I.id,ee=q.id;Y.relation==="superior-subordinate"&&(q.reportsTo===I.id||I.level==="c-level"?(se=I.id,ee=q.id):(se=q.id,ee=I.id)),h.current={templateId:Y.id,roleA:se,roleB:ee,turnIdx:0,timer:null};const W=oe=>{if(!h.current||oe>=Y.turns.length){h.current=null,f(B=>{const U=[...B],T=yu(U,se,ee);return T.conversations++,T.familiarity=bu(T),T.lastInteraction=new Date().toISOString(),U}),setTimeout(()=>{u(B=>{const U=new Map(B);return U.delete(se),U.delete(ee),U})},ty);return}const de=Y.turns[oe],V=de.speaker==="A"?se:ee,D=de.speaker==="A"?ee:se;u(B=>{const U=new Map(B);if(U.set(V,{text:de.text,type:"social",partnerId:D,ts:Date.now()}),oe>0){const T=Y.turns[oe-1].speaker==="A"?se:ee;T!==V&&U.delete(T)}return U}),h.current.turnIdx=oe,h.current.timer=setTimeout(()=>W(oe+1),F6)};return W(0),!0},[]);v.useEffect(()=>{const z=setInterval(()=>{const H=x.current;if(H.length===0||h.current||Math.random()<.35&&E(H))return;const R=H.filter(X=>g.current[X.id]!=="working");if(R.length===0)return;const I=vu(R),q=k(I.id);q&&(u(X=>{const A=new Map(X);return A.set(I.id,q),A}),setTimeout(()=>{u(X=>{const A=new Map(X),$=A.get(I.id);return $&&$.ts===q.ts&&A.delete(I.id),A})},ty))},T6);return()=>{var H;clearInterval(z),(H=h.current)!=null&&H.timer&&clearTimeout(h.current.timer)}},[k,E]);const C=v.useCallback(z=>{const H=o.get(z);return(H==null?void 0:H.text)??""},[o]),N=v.useCallback((z,H)=>{f(R=>{const I=[...R],q=yu(I,z,H);return q.dispatches++,q.familiarity=bu(q),q.lastInteraction=new Date().toISOString(),I})},[]),_=v.useCallback(z=>{z.length<2||f(H=>{const R=[...H];for(let I=0;I<z.length;I++)for(let q=I+1;q<z.length;q++){const X=yu(R,z[I],z[q]);X.wavesTogether++,X.familiarity=bu(X),X.lastInteraction=new Date().toISOString()}return R})},[]);return{speeches:o,getSpeech:C,relationships:d,notifyDispatch:N,notifyWave:_}}const yv="tycono:office-chat";let $6=0;function L6(){return`chat-${Date.now()}-${++$6}`}function Bh(){return[{id:"general",name:"#general",members:[],isDefault:!0,messages:[],topic:"Company-wide announcements and general discussion"},{id:"watercooler",name:"#watercooler",members:[],isDefault:!0,messages:[],topic:"No managers allowed. Vent, gossip, joke around. Talk freely about work frustrations, complain about directives you disagree with, share hot takes."}]}function I6(){try{const e=localStorage.getItem(yv);if(e){const n=JSON.parse(e);if(n.find(i=>i.id==="office")&&!n.find(i=>i.id==="general")){const i=n.filter(o=>o.id!=="office");return[...Bh(),...i]}const a=Bh();for(const i of a)n.find(o=>o.id===i.id)||n.unshift(i);return n}}catch{}return Bh()}function H6(e){const n=e.map(a=>({...a,messages:a.messages.slice(-200)}));localStorage.setItem(yv,JSON.stringify(n))}function U6(){const[e,n]=v.useState(I6),[a,i]=v.useState(null),[o,u]=v.useState(new Set);v.useEffect(()=>{H6(e)},[e]);const d=v.useCallback(b=>{i(b),b&&u(j=>{const k=new Set(j);return k.delete(b),k})},[]),f=v.useCallback(b=>{const j={...b,id:L6()};n(k=>{const E=k.map(C=>C.id==="general"?b.type==="dispatch"?{...C,messages:[...C.messages,j].slice(-200)}:C:b.channelId?C.id===b.channelId?{...C,messages:[...C.messages,j].slice(-200)}:C:C.members.length>0&&C.members.includes(b.roleId)?{...C,messages:[...C.messages,j].slice(-200)}:C);return u(C=>{const N=new Set(C);for(const _ of E){const z=k.find(H=>H.id===_.id);z&&_.messages.length>z.messages.length&&N.add(_.id)}return N}),E})},[]),m=v.useCallback((b,j,k)=>{const E=`ch-${Date.now()}`,C={id:E,name:b.startsWith("#")?b:`#${b}`,members:j,isDefault:!1,messages:[],topic:k};n(N=>[...N,C]),i(E)},[]),h=v.useCallback(b=>{n(j=>j.filter(k=>k.id!==b||k.isDefault)),i(j=>j===b?"general":j)},[]),x=v.useCallback((b,j)=>{n(k=>k.map(E=>E.id===b&&!E.isDefault?{...E,members:j}:E))},[]),g=v.useCallback((b,j)=>{n(k=>k.map(E=>E.id===b&&!E.isDefault?{...E,topic:j||void 0}:E))},[]),w=v.useCallback(b=>{n(j=>j.map(k=>{if(k.id==="watercooler"){const E=b.filter(C=>C.level!=="c-level").map(C=>C.id);if(k.members.length!==E.length||!E.every(C=>k.members.includes(C)))return{...k,members:E}}return k}))},[]);return{channels:e,activeChannelId:a,setActiveChannelId:d,pushMessage:f,createChannel:m,deleteChannel:h,updateMembers:x,updateTopic:g,unreadChannels:o,syncDefaultMembers:w}}const q6=45e3,ny=5e3,Y6=4,X6=20;function W6({roles:e,roleStatuses:n,activeExecs:a,channels:i,relationships:o,pushMessage:u,speechSettings:d,engineType:f,hasApiKey:m}){const x=((d==null?void 0:d.mode)==="auto"?f==="claude-cli"||f==="local"?"llm":"template":(d==null?void 0:d.mode)??"template")==="llm"&&(m!==!1||f==="claude-cli"),g=((d==null?void 0:d.intervalSec)??q6/1e3)*1e3,w=v.useRef(e),b=v.useRef(n),j=v.useRef(a),k=v.useRef(i),E=v.useRef(o),C=v.useRef(u),N=v.useRef(0),_=v.useRef(!1);w.current=e,b.current=n,j.current=a,k.current=i,E.current=o,C.current=u;const z=v.useCallback(async(I,q)=>{if(_.current)return!1;_.current=!0;try{if(!w.current.find(W=>W.id===I))return!1;const A=q.messages.slice(-X6).map(W=>({roleId:W.roleId,text:W.text,ts:W.ts})),$=w.current.filter(W=>q.members.includes(W.id)),L=E.current.filter(W=>W.roleA===I||W.roleB===I).map(W=>({partnerId:W.roleA===I?W.roleB:W.roleA,familiarity:W.familiarity})),Y=j.current.find(W=>W.roleId===I),se=Y?{currentTask:Y.task,taskProgress:null}:{currentTask:null,taskProgress:null},ee=await ye.chatInChannel({channelId:q.name.replace("#",""),channelTopic:q.topic,roleId:I,history:A,members:$.map(W=>({id:W.id,name:W.name,level:W.level})),relationships:L,workContext:se});return ee.message?(C.current({ts:Date.now(),roleId:I,text:ee.message,type:"chat",channelId:q.id}),!0):!1}catch{return!1}finally{_.current=!1}},[]),H=v.useCallback(async(I,q)=>{if(N.current>=Y6){N.current=0;return}const X=I.members.filter(Y=>Y!==q&&b.current[Y]!=="working");if(X.length===0){N.current=0;return}const A=X[Math.floor(Math.random()*X.length)];if(Math.random()>.7){N.current=0;return}const $=N.current*2e3,L=Math.random()*5e3;setTimeout(async()=>{N.current++;const Y=k.current.find(ee=>ee.id===I.id);if(!Y)return;if(await z(A,Y)){const ee=.6-N.current*.1;Math.random()<ee?H(Y,A):N.current=0}else N.current=0},ny+$+L)},[z]);return v.useEffect(()=>{if(!x)return;const I=setInterval(async()=>{const q=w.current;if(q.length===0||_.current)return;const X=q.filter(se=>b.current[se.id]!=="working");if(X.length===0)return;const A=X[Math.floor(Math.random()*X.length)],$=k.current.filter(se=>se.members.length===0?!0:se.members.includes(A.id));if($.length===0)return;const L=$[Math.floor(Math.random()*$.length)];N.current=0,await z(A.id,L)&&H(L,A.id)},g);return()=>clearInterval(I)},[x,g,z,H]),{triggerCeoReaction:v.useCallback(I=>{if(!x)return;const q=k.current.find(X=>X.id===I);q&&(N.current=0,setTimeout(()=>{H(q,"ceo")},ny))},[x,H])}}const bv=[[1,8],[3,5],[8,1],[5,3]],G6=[[1,4],[2,3],[4,1],[3,2]];function wu(e){const n=e===1||e===3?-1:0,a=bv[e],i=e<2?[0,1]:[1,0],o=n;return[{x:1,y:17,w:10,h:2,c:"#100A06",a:.18},{x:a[0],y:13,w:3,h:4,c:"$pants"},{x:a[1],y:13,w:3,h:4,c:"$pants"},{x:a[0]+1,y:13,w:1,h:3,c:"darken($pants, 25)",a:.2},{x:a[1]+1,y:13,w:1,h:3,c:"darken($pants, 25)",a:.2},{x:a[0],y:16,w:3,h:2,c:"$shoes"},{x:a[1],y:16,w:3,h:2,c:"$shoes"},{x:a[0],y:16,w:3,h:1,c:"lighten($shoes, 25)",a:.4},{x:a[1],y:16,w:3,h:1,c:"lighten($shoes, 25)",a:.4},{x:1,y:o+8,w:10,h:6,c:"$shirt"},{x:2,y:o+8,w:8,h:1,c:"lighten($shirt, 20)",a:.35},{x:1,y:o+8,w:1,h:5,c:"darken($shirt, 30)",a:.2},{x:10,y:o+8,w:1,h:5,c:"darken($shirt, 30)",a:.2},{x:-1,y:o+9+i[0],w:3,h:4-i[0],c:"$shirt"},{x:10,y:o+9+i[1],w:3,h:4-i[1],c:"$shirt"},{x:-1,y:o+12,w:2,h:1,c:"$skin"},{x:11,y:o+12,w:2,h:1,c:"$skin"},{x:4,y:o+6,w:4,h:3,c:"$skin"},{x:1,y:o+0,w:10,h:7,c:"$skin"},{x:3,y:o+3,w:2,h:2,c:"#1A1A2E"},{x:7,y:o+3,w:2,h:2,c:"#1A1A2E"},{x:3,y:o+3,w:1,h:1,c:"#FFF",a:.4},{x:7,y:o+3,w:1,h:1,c:"#FFF",a:.4},{x:5,y:o+6,w:2,h:1,c:"darken($skin, 25)",a:.35},{x:0,y:o+3,w:1,h:1,c:"$skin"},{x:11,y:o+3,w:1,h:1,c:"$skin"},{x:1,y:o+0,w:10,h:3,c:"$hair"},{x:0,y:o+1,w:2,h:3,c:"$hair"},{x:10,y:o+1,w:2,h:3,c:"$hair"},{x:2,y:o+0,w:8,h:1,c:"lighten($hair, 25)",a:.3}]}function ku(e){const n=e===1||e===3?-1:0,a=bv[e],i=e<2?[0,1]:[1,0],o=n;return[{x:1,y:17,w:10,h:2,c:"#100A06",a:.18},{x:a[0],y:13,w:3,h:4,c:"$pants"},{x:a[1],y:13,w:3,h:4,c:"$pants"},{x:a[0],y:16,w:3,h:2,c:"$shoes"},{x:a[1],y:16,w:3,h:2,c:"$shoes"},{x:1,y:o+8,w:10,h:6,c:"$shirt"},{x:2,y:o+8,w:8,h:1,c:"lighten($shirt, 20)",a:.2},{x:5,y:o+10,w:2,h:3,c:"darken($shirt, 30)",a:.12},{x:-1,y:o+9+i[0],w:3,h:4-i[0],c:"$shirt"},{x:10,y:o+9+i[1],w:3,h:4-i[1],c:"$shirt"},{x:4,y:o+6,w:4,h:3,c:"$skin"},{x:1,y:o+0,w:10,h:7,c:"$skin"},{x:1,y:o+0,w:10,h:6,c:"$hair"},{x:0,y:o+1,w:2,h:5,c:"$hair"},{x:10,y:o+1,w:2,h:5,c:"$hair"},{x:2,y:o+0,w:8,h:1,c:"lighten($hair, 25)",a:.3},{x:0,y:o+4,w:1,h:1,c:"$skin",a:.6},{x:11,y:o+4,w:1,h:1,c:"$skin",a:.6}]}function Bl(e,n){const a=e===1||e===3?-1:0,i=G6[e],o=a,u=e%2===0?1:0;return n?[{x:1,y:17,w:10,h:2,c:"#100A06",a:.18},{x:i[0],y:13,w:3,h:4,c:"$pants"},{x:i[1],y:13,w:3,h:4,c:"$pants"},{x:i[0],y:16,w:3,h:2,c:"$shoes"},{x:i[1],y:16,w:3,h:2,c:"$shoes"},{x:2,y:o+8,w:8,h:6,c:"$shirt"},{x:2,y:o+8,w:8,h:1,c:"lighten($shirt, 20)",a:.2},{x:8,y:o+9+u,w:3,h:4-u,c:"$shirt"},{x:9,y:o+12,w:2,h:1,c:"$skin"},{x:4,y:o+6,w:4,h:3,c:"$skin"},{x:2,y:o+0,w:8,h:7,c:"$skin"},{x:7,y:o+3,w:2,h:2,c:"#1A1A2E"},{x:7,y:o+3,w:1,h:1,c:"#FFF",a:.3},{x:9,y:o+4,w:1,h:1,c:"darken($skin, 25)",a:.3},{x:2,y:o+0,w:8,h:3,c:"$hair"},{x:1,y:o+1,w:2,h:4,c:"$hair"},{x:9,y:o+1,w:2,h:3,c:"$hair"},{x:3,y:o+0,w:6,h:1,c:"lighten($hair, 25)",a:.25}]:[{x:1,y:17,w:10,h:2,c:"#100A06",a:.18},{x:i[0],y:13,w:3,h:4,c:"$pants"},{x:i[1],y:13,w:3,h:4,c:"$pants"},{x:i[0],y:16,w:3,h:2,c:"$shoes"},{x:i[1],y:16,w:3,h:2,c:"$shoes"},{x:2,y:o+8,w:8,h:6,c:"$shirt"},{x:2,y:o+8,w:8,h:1,c:"lighten($shirt, 20)",a:.2},{x:0,y:o+9+u,w:3,h:4-u,c:"$shirt"},{x:-1,y:o+12,w:2,h:1,c:"$skin"},{x:4,y:o+6,w:4,h:3,c:"$skin"},{x:2,y:o+0,w:8,h:7,c:"$skin"},{x:3,y:o+3,w:2,h:2,c:"#1A1A2E"},{x:3,y:o+3,w:1,h:1,c:"#FFF",a:.3},{x:1,y:o+4,w:1,h:1,c:"darken($skin, 25)",a:.3},{x:2,y:o+0,w:8,h:3,c:"$hair"},{x:1,y:o+1,w:2,h:3,c:"$hair"},{x:9,y:o+1,w:2,h:4,c:"$hair"},{x:3,y:o+0,w:6,h:1,c:"lighten($hair, 25)",a:.25}]}const ry={down:[wu(0),wu(1),wu(2),wu(3)],up:[ku(0),ku(1),ku(2),ku(3)],right:[Bl(0,!0),Bl(1,!0),Bl(2,!0),Bl(3,!0)],left:[Bl(0,!1),Bl(1,!1),Bl(2,!1),Bl(3,!1)]},Fe="#FAFAF7",Yn="#FFFFFF",Te="#EDE8E2",Pe="#DDD6CC",qo="#1A1A2E",Zu="#2A2A2A",Pm="#FFB0B0",ay=[{x:2,y:0,w:1,h:1,c:Te},{x:3,y:0,w:1,h:1,c:Fe},{x:4,y:0,w:1,h:1,c:Yn},{x:5,y:0,w:1,h:1,c:Fe},{x:6,y:0,w:1,h:1,c:Te},{x:1,y:1,w:1,h:1,c:Pe},{x:2,y:1,w:1,h:1,c:Fe},{x:3,y:1,w:1,h:1,c:Yn},{x:4,y:1,w:1,h:1,c:Fe},{x:5,y:1,w:1,h:1,c:Yn},{x:6,y:1,w:1,h:1,c:Fe},{x:7,y:1,w:1,h:1,c:Pe},{x:0,y:2,w:1,h:1,c:Pe},{x:1,y:2,w:1,h:1,c:Te},{x:2,y:2,w:1,h:1,c:Fe},{x:3,y:2,w:1,h:1,c:Fe},{x:4,y:2,w:1,h:1,c:Yn},{x:5,y:2,w:1,h:1,c:Fe},{x:6,y:2,w:1,h:1,c:Fe},{x:7,y:2,w:1,h:1,c:Te},{x:8,y:2,w:1,h:1,c:Pe},{x:1,y:3,w:1,h:1,c:Te},{x:2,y:3,w:1,h:1,c:Fe},{x:3,y:3,w:1,h:1,c:qo},{x:4,y:3,w:1,h:1,c:Fe},{x:5,y:3,w:1,h:1,c:qo},{x:6,y:3,w:1,h:1,c:Fe},{x:7,y:3,w:1,h:1,c:Te},{x:2,y:4,w:1,h:1,c:Te},{x:3,y:4,w:1,h:1,c:Fe},{x:4,y:4,w:1,h:1,c:Zu},{x:5,y:4,w:1,h:1,c:Fe},{x:6,y:4,w:1,h:1,c:Te},{x:3,y:5,w:1,h:1,c:Pe},{x:4,y:5,w:1,h:1,c:Te},{x:5,y:5,w:1,h:1,c:Pe},{x:2,y:6,w:1,h:1,c:Te},{x:3,y:6,w:1,h:1,c:Fe},{x:4,y:6,w:1,h:1,c:Yn},{x:5,y:6,w:1,h:1,c:Fe},{x:6,y:6,w:1,h:1,c:Te},{x:2,y:7,w:1,h:1,c:Pe},{x:3,y:7,w:1,h:1,c:Te},{x:4,y:7,w:1,h:1,c:Fe},{x:5,y:7,w:1,h:1,c:Te},{x:6,y:7,w:1,h:1,c:Pe}],V6=[{x:3,y:8,w:1,h:1,c:Te},{x:5,y:8,w:1,h:1,c:Te},{x:3,y:9,w:1,h:1,c:Pe},{x:5,y:9,w:1,h:1,c:Pe}],K6=[{x:2,y:8,w:1,h:1,c:Te},{x:6,y:8,w:1,h:1,c:Te},{x:2,y:9,w:1,h:1,c:Pe},{x:6,y:9,w:1,h:1,c:Pe}],ly=[{x:2,y:0,w:1,h:1,c:Te},{x:3,y:0,w:1,h:1,c:Fe},{x:4,y:0,w:1,h:1,c:Yn},{x:5,y:0,w:1,h:1,c:Fe},{x:6,y:0,w:1,h:1,c:Te},{x:1,y:1,w:1,h:1,c:Pe},{x:2,y:1,w:1,h:1,c:Te},{x:3,y:1,w:1,h:1,c:Fe},{x:4,y:1,w:1,h:1,c:Yn},{x:5,y:1,w:1,h:1,c:Fe},{x:6,y:1,w:1,h:1,c:Te},{x:7,y:1,w:1,h:1,c:Pe},{x:0,y:2,w:1,h:1,c:Pe},{x:1,y:2,w:1,h:1,c:Te},{x:2,y:2,w:1,h:1,c:Fe},{x:3,y:2,w:1,h:1,c:Fe},{x:4,y:2,w:1,h:1,c:Fe},{x:5,y:2,w:1,h:1,c:Fe},{x:6,y:2,w:1,h:1,c:Fe},{x:7,y:2,w:1,h:1,c:Te},{x:8,y:2,w:1,h:1,c:Pe},{x:1,y:3,w:1,h:1,c:Pe},{x:2,y:3,w:1,h:1,c:Te},{x:3,y:3,w:1,h:1,c:Fe},{x:4,y:3,w:1,h:1,c:Fe},{x:5,y:3,w:1,h:1,c:Fe},{x:6,y:3,w:1,h:1,c:Te},{x:7,y:3,w:1,h:1,c:Pe},{x:2,y:4,w:1,h:1,c:Pe},{x:3,y:4,w:1,h:1,c:Te},{x:4,y:4,w:1,h:1,c:Fe},{x:5,y:4,w:1,h:1,c:Te},{x:6,y:4,w:1,h:1,c:Pe},{x:3,y:5,w:1,h:1,c:Pe},{x:4,y:5,w:1,h:1,c:Te},{x:5,y:5,w:1,h:1,c:Pe},{x:2,y:6,w:1,h:1,c:Te},{x:3,y:6,w:1,h:1,c:Fe},{x:4,y:6,w:1,h:1,c:Fe},{x:5,y:6,w:1,h:1,c:Fe},{x:6,y:6,w:1,h:1,c:Te},{x:2,y:7,w:1,h:1,c:Pe},{x:3,y:7,w:1,h:1,c:Te},{x:4,y:7,w:1,h:1,c:Fe},{x:5,y:7,w:1,h:1,c:Te},{x:6,y:7,w:1,h:1,c:Pe},{x:4,y:5,w:1,h:1,c:Fe},{x:4,y:4,w:1,h:1,c:Yn}],Q6=[{x:3,y:8,w:1,h:1,c:Te},{x:5,y:8,w:1,h:1,c:Te},{x:3,y:9,w:1,h:1,c:Pe},{x:5,y:9,w:1,h:1,c:Pe}],P6=[{x:2,y:8,w:1,h:1,c:Te},{x:6,y:8,w:1,h:1,c:Te},{x:2,y:9,w:1,h:1,c:Pe},{x:6,y:9,w:1,h:1,c:Pe}],ym=[{x:8,y:0,w:1,h:1,c:Te},{x:9,y:0,w:1,h:1,c:Fe},{x:10,y:0,w:1,h:1,c:Yn},{x:11,y:0,w:1,h:1,c:Fe},{x:7,y:1,w:1,h:1,c:Pe},{x:8,y:1,w:1,h:1,c:Fe},{x:9,y:1,w:1,h:1,c:Yn},{x:10,y:1,w:1,h:1,c:Fe},{x:11,y:1,w:1,h:1,c:Fe},{x:12,y:1,w:1,h:1,c:Te},{x:0,y:2,w:1,h:1,c:Yn},{x:1,y:2,w:1,h:1,c:Fe},{x:3,y:2,w:1,h:1,c:Te},{x:4,y:2,w:1,h:1,c:Fe},{x:5,y:2,w:1,h:1,c:Fe},{x:6,y:2,w:1,h:1,c:Fe},{x:7,y:2,w:1,h:1,c:Te},{x:8,y:2,w:1,h:1,c:Fe},{x:9,y:2,w:1,h:1,c:Fe},{x:10,y:2,w:1,h:1,c:Fe},{x:11,y:2,w:1,h:1,c:Fe},{x:12,y:2,w:1,h:1,c:Te},{x:0,y:3,w:1,h:1,c:Te},{x:1,y:3,w:1,h:1,c:Pe},{x:3,y:3,w:1,h:1,c:Pe},{x:4,y:3,w:1,h:1,c:Te},{x:5,y:3,w:1,h:1,c:Fe},{x:6,y:3,w:1,h:1,c:Te},{x:7,y:3,w:1,h:1,c:Pe},{x:8,y:3,w:1,h:1,c:Fe},{x:9,y:3,w:1,h:1,c:qo},{x:10,y:3,w:1,h:1,c:Fe},{x:11,y:3,w:1,h:1,c:Te},{x:3,y:4,w:1,h:1,c:Pe},{x:4,y:4,w:1,h:1,c:Te},{x:5,y:4,w:1,h:1,c:Fe},{x:6,y:4,w:1,h:1,c:Te},{x:8,y:4,w:1,h:1,c:Te},{x:9,y:4,w:1,h:1,c:Fe},{x:10,y:4,w:1,h:1,c:Zu}],vv=[{x:4,y:5,w:1,h:1,c:Te},{x:6,y:5,w:1,h:1,c:Te},{x:8,y:5,w:1,h:1,c:Te},{x:10,y:5,w:1,h:1,c:Te},{x:4,y:6,w:1,h:1,c:Pe},{x:6,y:6,w:1,h:1,c:Pe},{x:8,y:6,w:1,h:1,c:Pe},{x:10,y:6,w:1,h:1,c:Pe}],wv=[{x:3,y:5,w:1,h:1,c:Te},{x:5,y:5,w:1,h:1,c:Te},{x:9,y:5,w:1,h:1,c:Te},{x:11,y:5,w:1,h:1,c:Te},{x:3,y:6,w:1,h:1,c:Pe},{x:5,y:6,w:1,h:1,c:Pe},{x:9,y:6,w:1,h:1,c:Pe},{x:11,y:6,w:1,h:1,c:Pe}];function Zm(e,n=13){return e.map(a=>({...a,x:n-1-a.x}))}const iy=Zm(ym),Z6=Zm(vv),J6=Zm(wv),eA={down:[[...ay,...V6],[...ay,...K6]],up:[[...ly,...Q6],[...ly,...P6]],right:[[...ym,...vv],[...ym,...wv]],left:[[...iy,...Z6],[...iy,...J6]]},tA=[{x:4,y:5,w:1,h:1,c:Pm}],On="#FFD4D4",Kr="#FFCCD5",nA=[{x:2,y:0,w:1,h:1,c:Pe},{x:3,y:0,w:1,h:1,c:Te},{x:4,y:0,w:1,h:1,c:Fe},{x:5,y:0,w:1,h:1,c:Yn},{x:6,y:0,w:1,h:1,c:Te},{x:7,y:0,w:1,h:1,c:Pe},{x:1,y:1,w:1,h:1,c:Pe},{x:2,y:1,w:1,h:1,c:Te},{x:3,y:1,w:1,h:1,c:Fe},{x:4,y:1,w:1,h:1,c:Yn},{x:5,y:1,w:1,h:1,c:Fe},{x:6,y:1,w:1,h:1,c:Yn},{x:7,y:1,w:1,h:1,c:Te},{x:8,y:1,w:1,h:1,c:Pe},{x:1,y:2,w:1,h:1,c:Te},{x:2,y:2,w:1,h:1,c:Fe},{x:3,y:2,w:1,h:1,c:qo},{x:4,y:2,w:1,h:1,c:Fe},{x:5,y:2,w:1,h:1,c:Fe},{x:6,y:2,w:1,h:1,c:qo},{x:7,y:2,w:1,h:1,c:Fe},{x:8,y:2,w:1,h:1,c:Te},{x:2,y:3,w:1,h:1,c:Te},{x:3,y:3,w:1,h:1,c:Fe},{x:4,y:3,w:1,h:1,c:Zu},{x:5,y:3,w:1,h:1,c:Pm},{x:6,y:3,w:1,h:1,c:Fe},{x:7,y:3,w:1,h:1,c:Te},{x:2,y:4,w:1,h:1,c:Pe},{x:3,y:4,w:1,h:1,c:Te},{x:4,y:4,w:1,h:1,c:Fe},{x:5,y:4,w:1,h:1,c:Fe},{x:6,y:4,w:1,h:1,c:Te},{x:7,y:4,w:1,h:1,c:Pe},{x:0,y:5,w:1,h:1,c:Te},{x:1,y:5,w:1,h:1,c:Kr},{x:2,y:5,w:1,h:1,c:Fe},{x:3,y:5,w:1,h:1,c:On},{x:4,y:5,w:1,h:1,c:On},{x:5,y:5,w:1,h:1,c:On},{x:6,y:5,w:1,h:1,c:On},{x:7,y:5,w:1,h:1,c:Fe},{x:8,y:5,w:1,h:1,c:Kr},{x:9,y:5,w:1,h:1,c:Te},{x:1,y:6,w:1,h:1,c:Te},{x:2,y:6,w:1,h:1,c:Fe},{x:3,y:6,w:1,h:1,c:On},{x:4,y:6,w:1,h:1,c:Kr},{x:5,y:6,w:1,h:1,c:Kr},{x:6,y:6,w:1,h:1,c:On},{x:7,y:6,w:1,h:1,c:Fe},{x:8,y:6,w:1,h:1,c:Te},{x:2,y:7,w:1,h:1,c:Fe},{x:3,y:7,w:1,h:1,c:On},{x:4,y:7,w:1,h:1,c:On},{x:5,y:7,w:1,h:1,c:On},{x:6,y:7,w:1,h:1,c:On},{x:7,y:7,w:1,h:1,c:Fe},{x:0,y:8,w:1,h:1,c:Te},{x:1,y:8,w:1,h:1,c:Kr},{x:2,y:8,w:1,h:1,c:Pe},{x:3,y:8,w:1,h:1,c:Te},{x:4,y:8,w:1,h:1,c:Fe},{x:5,y:8,w:1,h:1,c:Fe},{x:6,y:8,w:1,h:1,c:Te},{x:7,y:8,w:1,h:1,c:Pe},{x:8,y:8,w:1,h:1,c:Kr},{x:9,y:8,w:1,h:1,c:Te},{x:4,y:9,w:1,h:1,c:Fe},{x:5,y:9,w:1,h:1,c:Yn}],rA=[{x:2,y:0,w:1,h:1,c:Pe},{x:3,y:0,w:1,h:1,c:Te},{x:4,y:0,w:1,h:1,c:Fe},{x:5,y:0,w:1,h:1,c:Yn},{x:6,y:0,w:1,h:1,c:Te},{x:7,y:0,w:1,h:1,c:Pe},{x:1,y:1,w:1,h:1,c:Pe},{x:2,y:1,w:1,h:1,c:Te},{x:3,y:1,w:1,h:1,c:Fe},{x:4,y:1,w:1,h:1,c:Yn},{x:5,y:1,w:1,h:1,c:Fe},{x:6,y:1,w:1,h:1,c:Yn},{x:7,y:1,w:1,h:1,c:Te},{x:8,y:1,w:1,h:1,c:Pe},{x:1,y:2,w:1,h:1,c:Te},{x:2,y:2,w:1,h:1,c:Fe},{x:3,y:2,w:1,h:1,c:Te},{x:4,y:2,w:1,h:1,c:Fe},{x:5,y:2,w:1,h:1,c:Fe},{x:6,y:2,w:1,h:1,c:Te},{x:7,y:2,w:1,h:1,c:Fe},{x:8,y:2,w:1,h:1,c:Te},{x:2,y:3,w:1,h:1,c:Te},{x:3,y:3,w:1,h:1,c:Fe},{x:4,y:3,w:1,h:1,c:Zu},{x:5,y:3,w:1,h:1,c:Pm},{x:6,y:3,w:1,h:1,c:Fe},{x:7,y:3,w:1,h:1,c:Te},{x:2,y:4,w:1,h:1,c:Pe},{x:3,y:4,w:1,h:1,c:Te},{x:4,y:4,w:1,h:1,c:Fe},{x:5,y:4,w:1,h:1,c:Fe},{x:6,y:4,w:1,h:1,c:Te},{x:7,y:4,w:1,h:1,c:Pe},{x:0,y:5,w:1,h:1,c:Te},{x:1,y:5,w:1,h:1,c:Kr},{x:2,y:5,w:1,h:1,c:Fe},{x:3,y:5,w:1,h:1,c:On},{x:4,y:5,w:1,h:1,c:On},{x:5,y:5,w:1,h:1,c:On},{x:6,y:5,w:1,h:1,c:On},{x:7,y:5,w:1,h:1,c:Fe},{x:8,y:5,w:1,h:1,c:Kr},{x:9,y:5,w:1,h:1,c:Te},{x:1,y:6,w:1,h:1,c:Te},{x:2,y:6,w:1,h:1,c:Fe},{x:3,y:6,w:1,h:1,c:On},{x:4,y:6,w:1,h:1,c:Kr},{x:5,y:6,w:1,h:1,c:Kr},{x:6,y:6,w:1,h:1,c:On},{x:7,y:6,w:1,h:1,c:Fe},{x:8,y:6,w:1,h:1,c:Te},{x:2,y:7,w:1,h:1,c:Fe},{x:3,y:7,w:1,h:1,c:On},{x:4,y:7,w:1,h:1,c:On},{x:5,y:7,w:1,h:1,c:On},{x:6,y:7,w:1,h:1,c:On},{x:7,y:7,w:1,h:1,c:Fe},{x:0,y:8,w:1,h:1,c:Te},{x:1,y:8,w:1,h:1,c:Kr},{x:2,y:8,w:1,h:1,c:Pe},{x:3,y:8,w:1,h:1,c:Te},{x:4,y:8,w:1,h:1,c:Fe},{x:5,y:8,w:1,h:1,c:Fe},{x:6,y:8,w:1,h:1,c:Te},{x:7,y:8,w:1,h:1,c:Pe},{x:8,y:8,w:1,h:1,c:Kr},{x:9,y:8,w:1,h:1,c:Te},{x:5,y:9,w:1,h:1,c:Fe},{x:6,y:9,w:1,h:1,c:Yn}],aA=[{x:1,y:9,w:7,h:1,c:"#100A06",a:.12}],lA=[{x:2,y:6,w:9,h:1,c:"#100A06",a:.12}],iA=[{x:1,y:10,w:8,h:1,c:"#100A06",a:.12}],ct=4,an=28,qn=2,zt=4,Ct=4,rl=[{wallColor:"#C8B898",baseboardColor:"#6A5840",floorType:"wood"},{wallColor:"#A8B8C8",baseboardColor:"#586878",floorType:"dark"},{wallColor:"#A8C8B0",baseboardColor:"#4A6A50",floorType:"carpet"},{wallColor:"#C8C0A8",baseboardColor:"#7A6A50",floorType:"tile"}];function Jm(e,n,a){const u=e.fy+Math.max(10,Math.floor(e.fh*.18)),d=Math.min(n,a),f=Math.ceil(n/d),m=[],h=d*28,x=e.fx+Math.max(8,Math.floor((e.fw-h)/2));for(let g=0;g<f&&m.length<n;g++){const w=Math.min(d,n-g*d);for(let b=0;b<w;b++)m.push({dx:x+b*28,dy:u+g*28,room:e.id})}return m}function sA(e){const i=rl[0],o={id:"main",wx:ct+Ct,wy:ct,ww:160-2*(ct+Ct),wh:an,fx:ct+Ct,fy:ct+an+qn,fw:160-2*(ct+Ct),fh:120-ct-an-qn-ct,...i},u=Jm(o,Math.min(e,6),3),d=[{id:"s-window-l",type:"window",room:"main",zone:"wall",offsetX:10,offsetY:6,windowW:16,windowH:14},{id:"s-window-r",type:"window",room:"main",zone:"wall",anchorX:"right",offsetX:-26,offsetY:6,windowW:16,windowH:14},{id:"s-clock",type:"clock",room:"main",zone:"wall",offsetX:Math.floor((160-2*(ct+Ct))/2),offsetY:10}],f=[{id:"s-plant-l",type:"plant",room:"main",zone:"floor",offsetX:4,offsetY:4},{id:"s-plant-r",type:"plant",room:"main",zone:"floor",anchorX:"right",offsetX:-8,offsetY:4}];return{preset:"S",canvasW:160,canvasH:120,rooms:{main:o},desks:u,doors:{},adjacency:{main:[]},corridorY:{main:o.fy+o.fh-12},waypoints:{main:[{x:o.fx+10,y:o.fy+o.fh-14},{x:o.fx+o.fw/2,y:o.fy+o.fh-14},{x:o.fx+o.fw-10,y:o.fy+o.fh-14}]},wallDecorations:d,furniture:f}}function oA(e){const o={id:"exec",wx:ct+Ct,wy:ct,ww:144-ct-Ct-zt/2,wh:an,fx:ct+Ct,fy:ct+an+qn,fw:144-ct-Ct-zt/2,fh:66,...rl[0]},u={id:"work",wx:144+zt/2+Ct,wy:ct,ww:144-zt/2-Ct-ct,wh:an,fx:144+zt/2+Ct,fy:ct+an+qn,fw:144-zt/2-Ct-ct,fh:66,...rl[1]},d={id:"meet",wx:ct+Ct,wy:ct+an+qn+66+zt,ww:144-ct-Ct-zt/2,wh:an,fx:ct+Ct,fy:ct+an+qn+66+zt+an+qn,fw:144-ct-Ct-zt/2,fh:70,...rl[2]},f={id:"comm",wx:144+zt/2+Ct,wy:ct+an+qn+66+zt,ww:144-zt/2-Ct-ct,wh:an,fx:144+zt/2+Ct,fy:ct+an+qn+66+zt+an+qn,fw:144-zt/2-Ct-ct,fh:70,...rl[3]},m={exec:o,work:u,meet:d,comm:f},h=[];let x=e;const g=[[o,Math.min(3,x)],[u,0]];g[1][1]=Math.min(3,x-g[0][1]);const w=[[d,0],[f,0]];let b=x-g[0][1]-g[1][1];b>0&&(w[0][1]=Math.min(2,b),b-=w[0][1]),b>0&&(w[1][1]=Math.min(2,b));for(const[R,I]of[...g,...w])I>0&&h.push(...Jm(R,I,3));const j=ct+an+qn+66,k=144-zt/2,E={exec_work:{id:"exec_work",type:"v",doorY:ct+an+qn+20+12,xA:k-2,xB:u.fx+2},meet_comm:{id:"meet_comm",type:"v",doorY:ct+an+qn+66+zt+an+qn+20+12,xA:k-2,xB:f.fx+2},exec_meet:{id:"exec_meet",type:"h",doorX:ct+Ct+40+14,yA:j-2,yB:d.fy+2},work_comm:{id:"work_comm",type:"h",doorX:144+zt/2+Ct+40+14,yA:j-2,yB:f.fy+2}},C={exec:[{room:"work",door:"exec_work",side:"A"},{room:"meet",door:"exec_meet",side:"A"}],work:[{room:"exec",door:"exec_work",side:"B"},{room:"comm",door:"work_comm",side:"A"}],meet:[{room:"exec",door:"exec_meet",side:"B"},{room:"comm",door:"meet_comm",side:"A"}],comm:[{room:"work",door:"work_comm",side:"B"},{room:"meet",door:"meet_comm",side:"B"}]},N={exec:o.fy+52,work:u.fy+48,meet:d.fy+56,comm:f.fy+54},_={exec:[{x:o.fx+6,y:o.fy+52},{x:o.fx+60,y:o.fy+54},{x:o.fx+112,y:o.fy+50},{x:o.fx+50,y:o.fy+52}],work:[{x:u.fx+14,y:u.fy+48},{x:u.fx+44,y:u.fy+48},{x:u.fx+70,y:u.fy+48},{x:u.fx+100,y:u.fy+48}],meet:[{x:d.fx+60,y:d.fy+56},{x:d.fx+30,y:d.fy+54},{x:d.fx+110,y:d.fy+50},{x:d.fx+80,y:d.fy+56}],comm:[{x:f.fx+96,y:f.fy+8},{x:f.fx+60,y:f.fy+54},{x:f.fx+40,y:f.fy+54},{x:f.fx+20,y:f.fy+54}]},z=[{id:"exec-window-1",type:"window",room:"exec",zone:"wall",offsetX:10,offsetY:6,windowW:16,windowH:14},{id:"exec-picture-1",type:"picture",room:"exec",zone:"wall",offsetX:34,offsetY:8,pictureColor:"#1565C0",facility:{id:"theme",label:"THEME",icon:"🎨",color:"#42A5F5",hitW:12,hitH:10}},{id:"exec-picture-2",type:"picture",room:"exec",zone:"wall",offsetX:48,offsetY:8,pictureColor:"#E65100"},{id:"exec-clock",type:"clock",room:"exec",zone:"wall",offsetX:64,offsetY:10,facility:{id:"settings",label:"SETTINGS",icon:"⚙",color:"#78909C",hitW:10,hitH:10}},{id:"exec-shelf",type:"shelf",room:"exec",zone:"wall",offsetX:78,offsetY:14,facility:{id:"stats",label:"STATS",icon:"📊",color:"#7E57C2",hitW:16,hitH:8}},{id:"exec-window-2",type:"window",room:"exec",zone:"wall",offsetX:104,offsetY:6,windowW:16,windowH:14},{id:"work-whiteboard",type:"whiteboard",room:"work",zone:"wall",offsetX:6,offsetY:4},{id:"work-window-1",type:"window",room:"work",zone:"wall",offsetX:50,offsetY:6,windowW:16,windowH:14},{id:"work-window-2",type:"window",room:"work",zone:"wall",offsetX:92,offsetY:6,windowW:16,windowH:14},{id:"meet-bulletin",type:"bulletin-board",room:"meet",zone:"wall",offsetX:6,offsetY:4,facility:{id:"bulletin",label:"BULLETIN",icon:"📋",color:"#F59E0B",hitW:22,hitH:16}},{id:"meet-picture",type:"picture",room:"meet",zone:"wall",offsetX:28,offsetY:8,pictureColor:"#10B981"},{id:"meet-window",type:"window",room:"meet",zone:"wall",offsetX:80,offsetY:6,windowW:16,windowH:14},{id:"meet-shelf",type:"shelf",room:"meet",zone:"wall",offsetX:102,offsetY:18},{id:"comm-screen",type:"screen",room:"comm",zone:"wall",offsetX:6,offsetY:6,facility:{id:"decisions",label:"DECISIONS",icon:"📜",color:"#EF4444",hitW:16,hitH:12}},{id:"comm-picture",type:"picture",room:"comm",zone:"wall",offsetX:28,offsetY:8,pictureColor:"#d4956a"},{id:"comm-window",type:"window",room:"comm",zone:"wall",offsetX:76,offsetY:6,windowW:16,windowH:14},{id:"comm-clock",type:"clock",room:"comm",zone:"wall",offsetX:98,offsetY:10},{id:"comm-shelf",type:"shelf",room:"comm",zone:"wall",offsetX:108,offsetY:18}],H=[{id:"exec-bookshelf",type:"bookshelf",room:"exec",zone:"floor",offsetX:2,offsetY:4},{id:"exec-plant-r",type:"plant",room:"exec",zone:"floor",anchorX:"right",offsetX:-10,offsetY:4},{id:"exec-plant-c",type:"plant",room:"exec",zone:"floor",offsetX:Math.floor(o.fw/2),offsetY:4},{id:"work-plant-1",type:"plant",room:"work",zone:"floor",offsetX:36,offsetY:4},{id:"work-plant-2",type:"plant",room:"work",zone:"floor",offsetX:80,offsetY:4},{id:"meet-plant",type:"plant",room:"meet",zone:"floor",anchorX:"right",offsetX:-12,offsetY:4},{id:"meet-table",type:"meeting-table",room:"meet",zone:"floor",offsetX:10,offsetY:42,facility:{id:"meeting",label:"MEETING",icon:"🏢",color:"#3B82F6",hitW:44,hitH:40}},{id:"comm-coffee-machine",type:"coffee-machine",room:"comm",zone:"floor",anchorX:"right",offsetX:-30,offsetY:4,condition:"no-desks"},{id:"comm-plant-1",type:"plant",room:"comm",zone:"floor",offsetX:38,offsetY:4,condition:"no-desks"},{id:"comm-bookshelf",type:"bookshelf",room:"comm",zone:"floor",anchorX:"right",offsetX:-26,offsetY:16,accent:"#10B981",condition:"no-desks",facility:{id:"knowledge",label:"KNOWLEDGE",icon:"📚",color:"#10B981",hitW:26,hitH:24}},{id:"comm-sofa",type:"sofa",room:"comm",zone:"floor",offsetX:44,offsetY:30,condition:"no-desks"},{id:"comm-coffee-table",type:"coffee-table",room:"comm",zone:"floor",offsetX:50,offsetY:50,condition:"no-desks"},{id:"comm-plant-2",type:"plant",room:"comm",zone:"floor",offsetX:38,offsetY:50,condition:"no-desks"}];return{preset:"M",canvasW:288,canvasH:208,rooms:m,desks:h,doors:E,adjacency:C,corridorY:N,waypoints:_,wallDecorations:z,furniture:H}}function cA(e){const d={id:"exec",wx:ct+Ct,wy:ct,ww:180-ct-Ct-zt/2,wh:an,fx:ct+Ct,fy:ct+an+qn,fw:180-ct-Ct-zt/2,fh:82,...rl[0]},f={id:"work",wx:180+zt/2+Ct,wy:ct,ww:180-zt/2-Ct-ct,wh:an,fx:180+zt/2+Ct,fy:ct+an+qn,fw:180-zt/2-Ct-ct,fh:82,...rl[1]},m=ct+an+qn+82,h={id:"meet",wx:ct+Ct,wy:m+zt,ww:180-ct-Ct-zt/2,wh:an,fx:ct+Ct,fy:m+zt+an+qn,fw:180-ct-Ct-zt/2,fh:86,...rl[2]},x={id:"comm",wx:180+zt/2+Ct,wy:m+zt,ww:180-zt/2-Ct-ct,wh:an,fx:180+zt/2+Ct,fy:m+zt+an+qn,fw:180-zt/2-Ct-ct,fh:86,...rl[3]},g={exec:d,work:f,meet:h,comm:x},w=[];let b=e;const j=[[d,Math.min(5,b)],[f,0]];j[1][1]=Math.min(5,b-j[0][1]);const k=[[h,0],[x,0]];let E=b-j[0][1]-j[1][1];E>0&&(k[0][1]=Math.min(3,E),E-=k[0][1]),E>0&&(k[1][1]=Math.min(3,E));for(const[q,X]of[...j,...k])X>0&&w.push(...Jm(q,X,4));const C=180-zt/2,N={exec_work:{id:"exec_work",type:"v",doorY:d.fy+82/2,xA:C-2,xB:f.fx+2},meet_comm:{id:"meet_comm",type:"v",doorY:h.fy+86/2,xA:C-2,xB:x.fx+2},exec_meet:{id:"exec_meet",type:"h",doorX:d.fx+54,yA:m-2,yB:h.fy+2},work_comm:{id:"work_comm",type:"h",doorX:f.fx+54,yA:m-2,yB:x.fy+2}},_={exec:[{room:"work",door:"exec_work",side:"A"},{room:"meet",door:"exec_meet",side:"A"}],work:[{room:"exec",door:"exec_work",side:"B"},{room:"comm",door:"work_comm",side:"A"}],meet:[{room:"exec",door:"exec_meet",side:"B"},{room:"comm",door:"meet_comm",side:"A"}],comm:[{room:"work",door:"work_comm",side:"B"},{room:"meet",door:"meet_comm",side:"B"}]},z={exec:d.fy+82-12,work:f.fy+82-12,meet:h.fy+86-12,comm:x.fy+86-12},H={exec:[{x:d.fx+10,y:z.exec},{x:d.fx+d.fw/2,y:z.exec},{x:d.fx+d.fw-10,y:z.exec}],work:[{x:f.fx+10,y:z.work},{x:f.fx+f.fw/2,y:z.work},{x:f.fx+f.fw-10,y:z.work}],meet:[{x:h.fx+10,y:z.meet},{x:h.fx+h.fw/2,y:z.meet},{x:h.fx+h.fw-10,y:z.meet}],comm:[{x:x.fx+10,y:z.comm},{x:x.fx+x.fw/2,y:z.comm},{x:x.fx+x.fw-10,y:z.comm}]},R=[{id:"exec-window-1",type:"window",room:"exec",zone:"wall",offsetX:10,offsetY:6,windowW:16,windowH:14},{id:"exec-picture-1",type:"picture",room:"exec",zone:"wall",offsetX:34,offsetY:8,pictureColor:"#1565C0",facility:{id:"theme",label:"THEME",icon:"🎨",color:"#42A5F5",hitW:12,hitH:10}},{id:"exec-picture-2",type:"picture",room:"exec",zone:"wall",offsetX:48,offsetY:8,pictureColor:"#E65100"},{id:"exec-clock",type:"clock",room:"exec",zone:"wall",offsetX:64,offsetY:10,facility:{id:"settings",label:"SETTINGS",icon:"⚙",color:"#78909C",hitW:10,hitH:10}},{id:"exec-shelf",type:"shelf",room:"exec",zone:"wall",offsetX:78,offsetY:14,facility:{id:"stats",label:"STATS",icon:"📊",color:"#7E57C2",hitW:16,hitH:8}},{id:"exec-window-2",type:"window",room:"exec",zone:"wall",offsetX:104,offsetY:6,windowW:16,windowH:14},{id:"work-whiteboard",type:"whiteboard",room:"work",zone:"wall",offsetX:6,offsetY:4},{id:"work-window-1",type:"window",room:"work",zone:"wall",offsetX:50,offsetY:6,windowW:16,windowH:14},{id:"work-window-2",type:"window",room:"work",zone:"wall",offsetX:92,offsetY:6,windowW:16,windowH:14},{id:"meet-bulletin",type:"bulletin-board",room:"meet",zone:"wall",offsetX:6,offsetY:4,facility:{id:"bulletin",label:"BULLETIN",icon:"📋",color:"#F59E0B",hitW:22,hitH:16}},{id:"meet-picture",type:"picture",room:"meet",zone:"wall",offsetX:28,offsetY:8,pictureColor:"#10B981"},{id:"meet-window",type:"window",room:"meet",zone:"wall",offsetX:80,offsetY:6,windowW:16,windowH:14},{id:"meet-shelf",type:"shelf",room:"meet",zone:"wall",offsetX:102,offsetY:18},{id:"comm-screen",type:"screen",room:"comm",zone:"wall",offsetX:6,offsetY:6,facility:{id:"decisions",label:"DECISIONS",icon:"📜",color:"#EF4444",hitW:16,hitH:12}},{id:"comm-picture",type:"picture",room:"comm",zone:"wall",offsetX:28,offsetY:8,pictureColor:"#d4956a"},{id:"comm-window",type:"window",room:"comm",zone:"wall",offsetX:76,offsetY:6,windowW:16,windowH:14},{id:"comm-clock",type:"clock",room:"comm",zone:"wall",offsetX:98,offsetY:10},{id:"comm-shelf",type:"shelf",room:"comm",zone:"wall",offsetX:108,offsetY:18}],I=[{id:"exec-bookshelf",type:"bookshelf",room:"exec",zone:"floor",offsetX:2,offsetY:4},{id:"exec-plant-r",type:"plant",room:"exec",zone:"floor",anchorX:"right",offsetX:-10,offsetY:4},{id:"exec-plant-c",type:"plant",room:"exec",zone:"floor",offsetX:Math.floor(d.fw/2),offsetY:4},{id:"work-plant-1",type:"plant",room:"work",zone:"floor",offsetX:36,offsetY:4},{id:"work-plant-2",type:"plant",room:"work",zone:"floor",offsetX:80,offsetY:4},{id:"meet-plant",type:"plant",room:"meet",zone:"floor",anchorX:"right",offsetX:-12,offsetY:4},{id:"meet-table",type:"meeting-table",room:"meet",zone:"floor",offsetX:10,offsetY:42,facility:{id:"meeting",label:"MEETING",icon:"🏢",color:"#3B82F6",hitW:44,hitH:40}},{id:"comm-coffee-machine",type:"coffee-machine",room:"comm",zone:"floor",anchorX:"right",offsetX:-30,offsetY:4,condition:"no-desks"},{id:"comm-plant-1",type:"plant",room:"comm",zone:"floor",offsetX:38,offsetY:4,condition:"no-desks"},{id:"comm-bookshelf",type:"bookshelf",room:"comm",zone:"floor",anchorX:"right",offsetX:-26,offsetY:16,accent:"#10B981",condition:"no-desks",facility:{id:"knowledge",label:"KNOWLEDGE",icon:"📚",color:"#10B981",hitW:26,hitH:24}},{id:"comm-sofa",type:"sofa",room:"comm",zone:"floor",offsetX:44,offsetY:30,condition:"no-desks"},{id:"comm-coffee-table",type:"coffee-table",room:"comm",zone:"floor",offsetX:50,offsetY:50,condition:"no-desks"},{id:"comm-plant-2",type:"plant",room:"comm",zone:"floor",offsetX:38,offsetY:50,condition:"no-desks"}];return{preset:"L",canvasW:360,canvasH:260,rooms:g,desks:w,doors:N,adjacency:_,corridorY:z,waypoints:H,wallDecorations:R,furniture:I}}const uA=2;function kv(e,n,a){return a||(n?n==="L"&&e<=12-uA?"M":n==="M"&&e>12?"L":n:e<=12?"M":"L")}function jv(e,n){switch(n??kv(e)){case"S":return sA(e);case"M":return oA(e);case"L":return cA(e)}}function dA(e,n){if(!n||Object.keys(n).length===0)return e;const a=i=>i.map(o=>{const u=n[o.id];return u?{...o,offsetX:u.offsetX,offsetY:u.offsetY}:o});return{...e,wallDecorations:a(e.wallDecorations),furniture:a(e.furniture)}}function fA(e,n){if(n)for(const[a,i]of Object.entries(n))e[a]&&(e[a]={...e[a],dx:i.dx,dy:i.dy})}function sy(e,n){if(!n||n.length===0)return e;const a=new Set(n);return{...e,wallDecorations:e.wallDecorations.filter(i=>!a.has(i.id)),furniture:e.furniture.filter(i=>!a.has(i.id))}}function hA(e,n){if(!n||n.length===0)return e;const a=[],i=[];for(const o of n)o.zone==="wall"?a.push(o):i.push(o);return{...e,wallDecorations:[...e.wallDecorations,...a],furniture:[...e.furniture,...i]}}let zo;function mA(e){zo=e}function O(e,n,a,i,o,u){e=Math.round(e),n=Math.round(n),!(u!==void 0&&u<.01)&&(u!==void 0&&u!==1&&(zo.globalAlpha=u),zo.fillStyle=o,zo.fillRect(e,n,a,i),u!==void 0&&u!==1&&(zo.globalAlpha=1))}function it(e,n,a,i){O(e,n,1,1,a,i)}let Mu=1;function Ts(e){Mu=e}function Ea(){return Mu=Mu*16807%2147483647,(Mu&65535)/65535}function Sv(e){const n=parseInt(e.slice(1,3),16)/255,a=parseInt(e.slice(3,5),16)/255,i=parseInt(e.slice(5,7),16)/255,o=Math.max(n,a,i),u=Math.min(n,a,i);let d=0,f=0;const m=(o+u)/2;if(o!==u){const h=o-u;f=m>.5?h/(2-o-u):h/(o+u),o===n?d=((a-i)/h+(a<i?6:0))/6:o===a?d=((i-n)/h+2)/6:d=((n-a)/h+4)/6}return[d*360,f*100,m*100]}function Cv(e,n,a){e=(e%360+360)%360,n=Math.max(0,Math.min(100,n))/100,a=Math.max(0,Math.min(100,a))/100;const i=n*Math.min(a,1-a),o=d=>{const f=(d+e/30)%12;return a-i*Math.max(-1,Math.min(f-3,9-f,1))},u=d=>Math.round(d*255).toString(16).padStart(2,"0");return"#"+u(o(0))+u(o(8))+u(o(4))}function Na(e,n=1){const[a,i,o]=Sv(e);return Cv(a+15*n,Math.min(100,i+8),o-12*n)}function bn(e,n=1){const[a,i,o]=Sv(e);return Cv(a-10*n,i-3,o+10*n)}const Un={hi:"#D4AA5C",base:"#B08040",sh:"#7A5038",deep:"#4E3028"},_r={hi:"#8A6848",base:"#604832",sh:"#3A2E24",deep:"#2A1E18"},ba={hi:"#5A6A80",base:"#485868",sh:"#364858",deep:"#283848"},Qr="#100A06";function pA(e,n,a=14,i=12){O(e,n,a,i,"#4A3828"),O(e+1,n+1,a-2,i-2,"#5A4838"),O(e+2,n+2,a-4,i-4,"#4A7098"),O(e+2,n+2,a-4,Math.floor((i-4)/2),"#6A90B8",.35);const o=Math.floor(a/2);O(e+o,n+1,1,i-2,"#4A3828"),O(e+1,n+Math.floor(i/2),a-2,1,"#4A3828",.5),it(e+3,n+3,"#8AB8E8",.35),it(e+o+2,n+3,"#8AB8E8",.25),O(e-1,n+i,a+2,2,"#5A4838"),O(e-1,n+i,a+2,1,bn("#5A4838",.5),.35)}function xA(e,n,a){O(e,n,10,8,"#3A2818"),O(e+1,n+1,8,6,a),O(e+2,n+2,4,3,bn(a,1.2),.3),it(e+3,n+2,bn(a,2),.25)}function gA(e,n){O(e,n,7,7,"#3A2818"),O(e+1,n+1,5,5,"#F0EDE5"),it(e+3,n+1,"#AAA"),it(e+3,n+5,"#AAA"),it(e+1,n+3,"#AAA"),it(e+5,n+3,"#AAA"),it(e+3,n+3,"#222"),O(e+3,n+1,1,2,"#333"),it(e+4,n+3,"#D32F2F")}function yA(e,n){O(e,n,26,16,"#586878"),O(e+1,n+1,24,13,"#ECEFF1"),O(e+1,n+1,24,1,"#F5F5F5",.4),O(e+3,n+3,14,1,"#1565C0",.6),O(e+3,n+5,18,1,"#333",.2),O(e+3,n+7,12,1,"#D32F2F",.35),O(e+3,n+9,16,1,"#333",.15),O(e+1,n+14,24,2,"#708898"),O(e+3,n+14,3,1,"#D32F2F"),O(e+7,n+14,3,1,"#1565C0"),O(e+11,n+14,3,1,"#2E7D32")}function bA(e,n){O(e,n,22,16,"#6A5030"),O(e+1,n+1,20,14,"#C4A66A"),Ts(88);for(let a=0;a<14;a++)for(let i=0;i<20;i++)Ea()>.5&&it(e+1+i,n+1+a,Ea()>.5?"#B89858":"#D4B87A",.18);O(e+2,n+2,5,4,"#FFF176"),O(e+8,n+2,5,4,"#90CAF9"),O(e+14,n+3,5,4,"#CE93D8"),O(e+3,n+8,7,4,"#C8E6C9"),O(e+11,n+8,8,4,"#F8BBD0"),it(e+4,n+2,"#E53935"),it(e+10,n+2,"#1E88E5"),it(e+16,n+3,"#FF9800")}function vA(e,n){O(e,n,20,3,"#5A4030"),O(e,n,20,1,bn("#5A4030",.5),.35),O(e,n+2,20,1,Na("#5A4030",.5),.3),O(e+2,n-4,3,4,"#E53935"),O(e+2,n-4,3,1,bn("#E53935",1),.3),O(e+6,n-3,2,3,"#1E88E5"),O(e+9,n-5,4,5,"#43A047"),O(e+14,n-3,3,3,"#FFD54F"),it(e+15,n-3,"#FFF176",.4)}function wA(e,n){O(e,n,16,12,"#1E1E28"),O(e+1,n+1,14,9,"#0C1420"),O(e+2,n+2,12,1,"#EF4444",.6),it(e+2,n+4,"#4CAF50"),O(e+4,n+4,7,1,"#8b949e",.4),it(e+2,n+6,"#FF9800"),O(e+4,n+6,5,1,"#8b949e",.3),it(e+2,n+8,"#42A5F5"),O(e+4,n+8,8,1,"#8b949e",.25),O(e+7,n+10,2,2,"#1E1E28"),O(e+5,n+11,6,1,"#586878")}function kA(e,n,a){O(e+2,n+20,22,2,Qr,.15),O(e,n,22,20,_r.deep),O(e+1,n+1,20,18,_r.base),O(e,n,22,1,_r.hi,.35),O(e,n,1,20,_r.hi,.2);for(const u of[6,12])O(e+1,n+u,20,2,_r.sh),O(e+1,n+u,20,1,_r.hi,.2);const i=["#E53935","#1E88E5","#43A047","#8E24AA","#FB8C00","#00897B","#5C6BC0"];let o=e+2;for(let u=0;u<5;u++){const d=2+u%2;O(o,n+1,d,5,i[u]),O(o,n+1,d,1,bn(i[u],1),.35),o+=d+1}o=e+2;for(let u=0;u<4;u++)O(o,n+7,4,5,i[u+3]),O(o,n+7,4,1,bn(i[u+3],1),.25),o+=5;O(e+2,n+14,4,4,"#FFD54F"),O(e+8,n+14,7,4,"#90CAF9"),a&&O(e,n-1,22,1,a,.7)}function jA(e,n){O(e+2,n+11,6,2,Qr,.1),O(e+2,n+8,6,4,"#8B5E3C"),O(e+1,n+7,8,2,Na("#A06E48",.3)),O(e+2,n+7,6,1,bn("#A06E48",.5),.4),O(e+1,n+3,3,4,"#2E7D32"),O(e+5,n+2,3,4,"#2E7D32"),O(e+2,n+1,4,4,"#43A047"),O(e+3,n+0,3,3,"#66BB6A"),it(e+4,n,"#81C784"),it(e+3,n+1,"#A5D6A7",.4)}function SA(e,n){vi(e+4,n-4,"down"),vi(e+16,n-4,"down"),vi(e+28,n-4,"down"),O(e+3,n+24,34,3,Qr,.15),O(e,n+2,36,18,Un.deep),O(e+1,n+3,34,16,Un.base),O(e+1,n+3,34,1,Un.hi,.35);for(let a=0;a<14;a+=3)O(e+1,n+4+a,34,1,Na(Un.base,.2),.08);O(e,n+20,36,4,Un.deep),O(e+1,n+21,34,2,Un.sh),O(e+6,n+7,10,6,"#1A1A24"),O(e+7,n+8,8,4,"#0C1420"),O(e+8,n+9,4,1,"#2A6898",.4),O(e+20,n+8,6,4,"#F0F0F0"),O(e+15,n+7,3,3,"#ECEFF1"),it(e+16,n+8,"#795548"),vi(e+4,n+24,"up"),vi(e+16,n+24,"up"),vi(e+28,n+24,"up")}function CA(e,n){O(e+2,n+16,36,3,Qr,.15),O(e,n,36,5,"#5D4037"),O(e+1,n+1,34,3,"#6D4C41"),O(e+1,n+1,34,1,bn("#6D4C41",.5),.3),O(e,n+5,36,8,"#5D4037"),O(e+2,n+6,15,6,"#6D4C41"),O(e+3,n+6,13,1,bn("#6D4C41",.5),.35),O(e+19,n+6,15,6,"#6D4C41"),O(e+20,n+6,13,1,bn("#6D4C41",.5),.35),O(e+17,n+6,2,6,"#5D4037"),O(e,n+13,36,3,Na("#5D4037",1)),O(e-2,n+2,3,12,"#5D4037"),O(e+35,n+2,3,12,"#5D4037"),O(e+4,n+7,6,4,"#FF8A65"),O(e+5,n+7,4,1,bn("#FF8A65",1),.35)}function EA(e,n){O(e+2,n+10,22,2,Qr,.12),O(e,n,22,8,_r.deep),O(e+1,n+1,20,6,_r.base),O(e+1,n+1,20,1,_r.hi,.3),O(e,n+8,22,2,_r.sh),O(e+3,n+2,6,4,"#F0F0F0"),O(e+13,n+3,3,3,"#ECEFF1"),it(e+14,n+4,"#795548")}function NA(e,n){O(e+1,n+14,10,2,Qr,.12),O(e,n,10,14,"#546E7A"),O(e,n,10,1,bn("#546E7A",1),.35),O(e+1,n+1,8,3,"#78909C"),O(e+1,n+5,8,4,"#37474F"),it(e+2,n+6,"#EF5350"),it(e+4,n+6,"#66BB6A"),O(e+2,n+11,4,2,"#ECEFF1")}function AA(e,n){O(e+2,n+18,28,3,Qr,.12),O(e,n,28,18,"#37474F"),O(e+1,n+1,26,15,"#0D47A1"),O(e+2,n+2,24,13,"#1565C0"),O(e+2,n+2,24,4,"#1976D2",.4),O(e+2,n+12,24,3,"#F9A825",.35),O(e+4,n+8,2,5,"#2E7D32"),O(e+6,n+9,2,4,"#43A047"),O(e+20,n+7,2,6,"#2E7D32"),O(e+22,n+8,2,5,"#388E3C"),O(e+9,n+5,4,2,"#FF8A65"),it(e+12,n+5,"#FF5722"),O(e+16,n+8,3,2,"#FFD54F"),it(e+15,n+8,"#FFC107"),it(e+13,n+3,"#90CAF9",.5),it(e+14,n+4,"#BBDEFB",.35),it(e+8,n+3,"#BBDEFB",.3),O(e,n+16,28,2,"#455A64"),O(e+1,n+16,26,1,bn("#455A64",.5),.3)}function DA(e,n){O(e,n,24,10,"#1A1A2E"),O(e+2,n+1,20,8,"#E040FB",.15),O(e+3,n+2,4,6,"#E040FB",.7),O(e+4,n+3,2,4,"#1A1A2E"),O(e+8,n+2,1,6,"#00E5FF",.7),O(e+8,n+2,4,1,"#00E5FF",.7),O(e+8,n+4,4,1,"#00E5FF",.7),O(e+11,n+2,1,3,"#00E5FF",.7),O(e+13,n+2,1,6,"#E040FB",.7),O(e+13,n+2,4,1,"#E040FB",.7),O(e+13,n+4,3,1,"#E040FB",.7),O(e+13,n+7,4,1,"#E040FB",.7),O(e+18,n+2,1,6,"#00E5FF",.7),O(e+21,n+2,1,6,"#00E5FF",.7),O(e+19,n+3,1,2,"#00E5FF",.5),O(e+20,n+5,1,2,"#00E5FF",.5)}function TA(e,n){O(e+2,n+28,16,3,Qr,.15),O(e,n,16,28,"#1A237E"),O(e+1,n+1,14,3,"#283593"),O(e+2,n+4,12,10,"#0D1117"),O(e+3,n+5,10,8,"#1B5E20"),O(e+5,n+6,2,2,"#4CAF50"),O(e+9,n+8,2,2,"#FF5722"),O(e+7,n+10,3,1,"#FFD54F"),it(e+6,n+7,"#81C784"),O(e+1,n+14,14,6,"#1A237E"),O(e+2,n+15,4,4,"#212121"),it(e+4,n+16,"#F44336"),it(e+9,n+16,"#F44336"),it(e+11,n+16,"#2196F3"),it(e+10,n+18,"#FFEB3B"),O(e,n+20,16,8,"#0D47A1"),O(e+1,n+21,14,6,"#1565C0"),O(e,n+4,1,14,"#FF4081",.4),O(e+15,n+4,1,14,"#FF4081",.4)}function FA(e,n){O(e+2,n+24,20,3,Qr,.15),O(e,n,20,24,"#4E342E"),O(e+1,n+1,18,22,"#5D4037"),O(e+2,n+1,16,4,"#FF6F00"),O(e+3,n+2,14,2,"#FF8F00",.6),O(e+2,n+5,16,10,"#1A1A2E"),O(e+3,n+6,14,8,"#212121"),O(e+4,n+7,4,4,"#333"),O(e+5,n+8,2,2,"#E53935"),O(e+10,n+7,4,4,"#333"),O(e+11,n+8,2,2,"#1E88E5"),O(e+3,n+16,14,6,"#3E2723");for(let a=0;a<7;a++)O(e+4+a*2,n+17,1,4,"#5D4037",.5);O(e+1,n+5,18,1,"#FFD54F",.5),O(e+1,n+15,18,1,"#FFD54F",.5)}function MA(e,n){O(e+2,n+22,22,2,Qr,.12),O(e,n,22,22,_r.deep),O(e+1,n+1,20,20,"#37474F"),O(e+2,n+2,18,18,"#546E7A",.3),O(e+1,n+10,20,1,_r.base),O(e+1,n+10,20,1,_r.hi,.2),O(e+4,n+3,4,5,"#FFD54F"),O(e+5,n+4,2,3,"#FFC107"),O(e+4,n+7,4,1,"#FFA000"),it(e+5,n+3,"#FFF176",.5),O(e+13,n+4,4,4,"#B0BEC5"),O(e+14,n+3,2,1,"#CFD8DC"),it(e+14,n+5,"#ECEFF1",.6),O(e+5,n+12,3,3,"#A1887F"),O(e+6,n+11,1,1,"#D7CCC8"),O(e+12,n+12,6,4,"#5D4037"),O(e+13,n+13,4,2,"#FFD54F",.6),O(e+2,n+2,2,18,"#fff",.08)}function RA(e,n){O(e+2,n+16,26,3,Qr,.18),O(e,n,26,10,Un.deep),O(e+1,n+1,24,8,Un.base),O(e+1,n+2,24,1,Un.hi,.2),O(e+1,n+4,24,1,Na(Un.base,.2),.1),O(e+1,n+6,24,1,Un.hi,.15),O(e+1,n+1,24,1,Un.hi,.4),O(e+1,n+1,1,8,Un.hi,.2),O(e,n+10,26,5,Un.deep),O(e+1,n+11,24,3,Un.sh),O(e+1,n+10,24,1,Na(Un.base,1.5),.4),O(e+1,n+14,24,1,Un.base,.15),O(e+2,n+12,10,1,Un.deep,.4),O(e+14,n+12,10,1,Un.deep,.4),it(e+7,n+11,"#C8D0D8",.6),it(e+19,n+11,"#C8D0D8",.6),O(e+6,n-5,14,7,"#1E1E28"),O(e+7,n-4,12,5,"#0C1420"),O(e+8,n-3,5,1,"#2A6898",.6),O(e+8,n-2,8,1,"#1A3858",.4),O(e+8,n-1,3,1,"#2A6898",.35),it(e+7,n-4,"#4A98D8",.25),it(e+12,n+1,"#4CAF50",.4),O(e+12,n+2,2,3,"#586878"),O(e+10,n+4,6,1,"#8898A8"),O(e+6,n+4,12,4,"#222228"),O(e+6,n+4,12,1,"#333338",.4);for(let a=0;a<5;a++)it(e+7+a*2,n+5,"#444",.6),it(e+7+a*2,n+6,"#3A3A3E",.4);O(e+20,n+5,3,4,"#333338"),O(e+20,n+5,3,1,"#444448"),O(e+1,n+3,4,4,"#F0EDE8"),O(e+1,n+3,4,1,"#F8F6F2"),it(e+2,n+5,"#6D4C41")}function vi(e,n,a){O(e+1,n+9,10,2,Qr,.1),it(e+5,n+9,"#1E1E22"),it(e+1,n+10,"#1A1A1E"),it(e+9,n+10,"#1A1A1E"),it(e+3,n+11,"#1A1A1E"),it(e+7,n+11,"#1A1A1E"),O(e+1,n+2,8,6,ba.base),O(e+2,n+3,6,4,ba.hi,.35),O(e+2,n+3,6,1,bn(ba.hi,.5),.25),O(e+1,n+7,8,1,ba.deep),a==="up"?(O(e,n+7,10,3,ba.deep),O(e+1,n+8,8,1,ba.sh)):(O(e,n-1,10,3,ba.deep),O(e+1,n,8,1,ba.sh)),O(e,n+3,1,4,ba.sh),O(e+9,n+3,1,4,ba.sh)}const Ev={bookshelf:(e,n,a)=>kA(e,n,a.accent),plant:(e,n)=>jA(e,n),"meeting-table":(e,n)=>SA(e,n),sofa:(e,n)=>CA(e,n),"coffee-table":(e,n)=>EA(e,n),"coffee-machine":(e,n)=>NA(e,n),window:(e,n,a)=>pA(e,n,a.windowW??16,a.windowH??14),picture:(e,n,a)=>xA(e,n,a.pictureColor??"#1565C0"),clock:(e,n)=>gA(e,n),whiteboard:(e,n)=>yA(e,n),"bulletin-board":(e,n)=>bA(e,n),shelf:(e,n)=>vA(e,n),screen:(e,n)=>wA(e,n),aquarium:(e,n)=>AA(e,n),"neon-sign":(e,n)=>DA(e,n),arcade:(e,n)=>TA(e,n),jukebox:(e,n)=>FA(e,n),"trophy-case":(e,n)=>MA(e,n)};function Ss(e,n){const a=e.zone==="wall"?n.wx:n.fx,i=e.zone==="wall"?n.wy:n.fy;return{x:e.anchorX==="right"?(e.zone==="wall"?n.wx+n.ww:n.fx+n.fw)+e.offsetX:a+e.offsetX,y:i+e.offsetY}}function zA(e){for(const n of e.wallDecorations){const a=e.rooms[n.room];if(!a)continue;const{x:i,y:o}=Ss(n,a),u=Ev[n.type];u&&u(i,o,n)}}function _A(e,n,a){for(const i of e.furniture){const o=e.rooms[i.room];if(!o||i.condition==="no-desks"&&a.has(i.room))continue;const{x:u,y:d}=Ss(i,o),f=Ev[i.type];f&&n.push({y:d,draw:()=>f(u,d,i)})}}function wi(e){const n=[],a=[...e.wallDecorations,...e.furniture];for(const i of a){if(!i.facility)continue;const o=e.rooms[i.room];if(!o)continue;const{x:u,y:d}=Ss(i,o);n.push({id:i.facility.id,label:i.facility.label,icon:i.facility.icon,color:i.facility.color,dx:u,dy:d,pw:i.facility.hitW,ph:i.facility.hitH})}return n}const BA={bookshelf:{w:22,h:20},plant:{w:10,h:12},"meeting-table":{w:36,h:28},sofa:{w:38,h:16},"coffee-table":{w:22,h:10},"coffee-machine":{w:10,h:14},window:{w:16,h:14},picture:{w:10,h:8},clock:{w:7,h:7},whiteboard:{w:26,h:16},"bulletin-board":{w:22,h:16},shelf:{w:20,h:8},screen:{w:16,h:12},aquarium:{w:28,h:18},"neon-sign":{w:24,h:10},arcade:{w:16,h:28},jukebox:{w:20,h:24},"trophy-case":{w:22,h:22}};function bm(e){return BA[e]??{w:16,h:16}}function Oh(e,n,a,i){for(let o=e.furniture.length-1;o>=0;o--){const u=e.furniture[o],d=e.rooms[u.room];if(!d||u.condition==="no-desks"&&i.has(u.room))continue;const{x:f,y:m}=Ss(u,d),h=bm(u.type);if(n>=f&&n<=f+h.w&&a>=m&&a<=m+h.h)return u.id}for(let o=e.wallDecorations.length-1;o>=0;o--){const u=e.wallDecorations[o],d=e.rooms[u.room];if(!d)continue;const{x:f,y:m}=Ss(u,d),h=bm(u.type);if(n>=f&&n<=f+h.w&&a>=m&&a<=m+h.h)return u.id}return null}function oy(e,n,a,i,o){const d=[...n.wallDecorations,...n.furniture].find(g=>g.id===a);if(!d||d.condition==="no-desks"&&o.has(d.room))return;const f=n.rooms[d.room];if(!f)return;const{x:m,y:h}=Ss(d,f),x=bm(d.type);e.save(),e.fillStyle=i,e.globalAlpha=.2,e.fillRect(m-1,h-1,x.w+2,x.h+2),e.globalAlpha=.9,e.strokeStyle=i,e.lineWidth=1,e.strokeRect(m-.5,h-.5,x.w+1,x.h+1),e.restore()}function cy(e,n,a,i){e.save(),e.fillStyle=i,e.globalAlpha=.2,e.fillRect(n-1,a-1,28,42),e.globalAlpha=.9,e.strokeStyle=i,e.lineWidth=1,e.strokeRect(n-.5,a-.5,27,41),e.restore()}function uy(e,n,a){for(const[i,o]of Object.entries(e))if(n>=o.dx&&n<=o.dx+26&&a>=o.dy&&a<=o.dy+40)return i;return null}const dy=[{type:"plant",zone:"floor",label:"Plant",icon:"🪴",price:0},{type:"clock",zone:"wall",label:"Clock",icon:"🕐",price:0},{type:"bookshelf",zone:"floor",label:"Bookshelf",icon:"📚",price:500},{type:"picture",zone:"wall",label:"Picture",icon:"🖼️",price:500},{type:"shelf",zone:"wall",label:"Shelf",icon:"📦",price:800},{type:"window",zone:"wall",label:"Window",icon:"🪟",price:1e3},{type:"sofa",zone:"floor",label:"Sofa",icon:"🛋️",price:1500},{type:"coffee-table",zone:"floor",label:"Coffee Table",icon:"☕",price:1500},{type:"coffee-machine",zone:"floor",label:"Coffee Machine",icon:"☕",price:2e3},{type:"meeting-table",zone:"floor",label:"Meeting Table",icon:"🪑",price:3e3},{type:"whiteboard",zone:"wall",label:"Whiteboard",icon:"📋",price:3e3},{type:"screen",zone:"wall",label:"Screen",icon:"🖥️",price:5e3},{type:"aquarium",zone:"floor",label:"Aquarium",icon:"🐠",price:5e3},{type:"neon-sign",zone:"wall",label:"Neon Sign",icon:"💡",price:3e3},{type:"arcade",zone:"floor",label:"Arcade",icon:"🕹️",price:8e3},{type:"jukebox",zone:"floor",label:"Jukebox",icon:"🎵",price:6e3},{type:"trophy-case",zone:"floor",label:"Trophy Case",icon:"🏆",price:7e3}],ju=16,OA=4,bi=4,Ru=2,Xt=4,Ll=4;let Ke=jv(7);const Yu={cto:"#1565C0",cbo:"#E65100",pm:"#2E7D32",engineer:"#4A148C",designer:"#AD1457",qa:"#00695C","data-analyst":"#0277BD"},fy={ceo:{en:["Boss?","What's up?","Time for a meeting?","Got any ideas?","How's everyone doing?"],ko:["대표님?","무슨 일이신가요?","회의 시간이신가요?","좋은 아이디어 있으시면 말씀해주세요.","다들 잘하고 있나요?"],ja:["社長?","何かありますか?","会議の時間ですか?","良いアイデアがあれば教えてください。","みんな元気ですか?"]},cto:{en:["Need anything?","Tech question?","Reviewing architecture.","Deploy in a moment.","Want me to look at the code?"],ko:["뭐 필요하신 거 있으세요?","기술 관련 질문이신가요?","아키텍처 리뷰 중이에요.","배포는 조금만 기다려주세요.","코드 봐드릴까요?"],ja:["何かお手伝いしましょうか?","技術的な質問ですか?","アーキテクチャレビュー中です。","デプロイはもう少しお待ちください。","コード見ましょうか?"]},cbo:{en:["Business question?","Reviewing revenue model.","Want to see market research?","Analyzing competitors.","Can I help?"],ko:["비즈니스 관련 얘기신가요?","수익 모델 검토 중이에요.","시장 조사 결과 보실래요?","경쟁사 분석 중입니다.","뭔가 도와드릴까요?"],ja:["ビジネスの話ですか?","収益モデルを検討中です。","市場調査の結果を見ますか?","競合分析中です。","何かお手伝いしましょうか?"]},pm:{en:["Curious about progress?","Updating the roadmap.","Assigning tasks.","Need to re-prioritize?","Preparing sprint review."],ko:["프로젝트 진행 상황 궁금하신가요?","로드맵 업데이트 중이에요.","태스크 할당 중입니다.","우선순위 조정이 필요할까요?","스프린트 리뷰 준비 중이에요."],ja:["進捗が気になりますか?","ロードマップを更新中です。","タスクを割り当て中です。","優先順位の調整が必要ですか?","スプリントレビューの準備中です。"]},engineer:{en:["Working on it!","Fixing a bug.","Need a code review?","Writing tests.","Pushing a PR."],ko:["일하고 있어요!","버그 수정 중입니다.","코드 리뷰 필요하신가요?","테스트 작성 중이에요.","PR 올리고 있어요."],ja:["作業中です!","バグ修正中です。","コードレビュー必要ですか?","テスト書いてます。","PR出してます。"]},designer:{en:["Got design feedback?","Working on mockups.","Thinking about UI improvements.","Picking colors...","Want to see the prototype?"],ko:["디자인 피드백 있으신가요?","목업 작업 중이에요.","UI 개선안 생각 중입니다.","컬러 팔레트 고민 중이에요.","프로토타입 보여드릴까요?"],ja:["デザインのフィードバックありますか?","モックアップ作業中です。","UI改善案を考えています。","カラーパレットを検討中です。","プロトタイプ見せましょうか?"]},qa:{en:["Testing in progress.","Found a bug!","Writing test cases.","Running regression tests.","Quality check in progress."],ko:["테스트 중이에요.","버그 발견했어요!","테스트 케이스 작성 중입니다.","회귀 테스트 진행 중이에요.","품질 체크 중입니다."],ja:["テスト中です。","バグ見つけました!","テストケース作成中です。","回帰テスト実行中です。","品質チェック中です。"]},"data-analyst":{en:["Analyzing data.","Preparing a report.","Want to check the dashboard?","Tracking metrics.","Found an insight!"],ko:["데이터 분석 중이에요.","리포트 준비 중입니다.","대시보드 확인해보실래요?","지표 추적 중이에요.","인사이트 발견했어요!"],ja:["データ分析中です。","レポート準備中です。","ダッシュボード確認しますか?","指標追跡中です。","インサイト発見しました!"]},default:{en:["Hello!","How can I help?","Working hard.","Have a great day!"],ko:["안녕하세요!","무엇을 도와드릴까요?","열심히 일하고 있어요.","좋은 하루 되세요!"],ja:["こんにちは!","何かお手伝いしましょうか?","頑張って仕事してます。","良い一日を!"]}};function $A(e,n){const a=fy[e]||fy.default;return a[n]||a.en||a.default||[]}let wa=wi(Ke);function Nv(e){return{x:e.dx,y:e.dy,w:e.pw,h:e.ph}}function Av(e){return{cx:e.dx+e.pw/2,botY:e.dy+e.ph}}let vn={};function LA(e){const n={};for(let a=0;a<e.length&&a<Ke.desks.length;a++)n[e[a]]=Ke.desks[a];return n}let Xe,er=null,ki=null,nl=!1,sa=null,Rr=null,Dv=0,rr=null,Hn=null,Ol=null,va=null,$h=900;function IA(e,n){const{wx:a,wy:i,ww:o,wh:u,wallColor:d,baseboardColor:f}=e,m=Na(d,.5),h=bn(d,.5),x=[];if(n){const g=n.x-a,w=n.w;g>0&&x.push({sx:a,sw:g}),g+w<o&&x.push({sx:n.x+w,sw:o-g-w})}else x.push({sx:a,sw:o});for(const g of x){O(g.sx,i,g.sw,u,d);for(let w=0;w<u;w+=4)O(g.sx,i+w,g.sw,1,h,.08),O(g.sx,i+w+2,g.sw,1,m,.05);Ts(Math.round(g.sx*7+i*13));for(let w=0;w<g.sw;w+=3)Ea()>.4&&O(g.sx+w,i,1,u,h,.04);O(g.sx,i,g.sw,2,h,.3),O(g.sx,i,g.sw,1,bn(d,1),.2),O(g.sx,i+u-2,g.sw,2,m,.3),O(g.sx,i+u,g.sw,Ru,f),O(g.sx,i+u,g.sw,1,bn(f,.5),.4)}n&&(O(n.x-1,i,1,u+Ru,"#4A3828"),O(n.x+n.w,i,1,u+Ru,"#4A3828"),O(n.x,i,n.w,1,"#0A0808",.12)),O(e.fx,e.fy,e.fw,3,"#0A0808",.12),O(e.fx,e.fy+3,e.fw,2,"#0A0808",.06)}function HA(e){const n="#504038",a=Na(n,.5),i=bn(n,.5),o=e.wx-Ll,u=e.wy,d=e.wh+Ru+e.fh;O(o,u,Ll,d,n),O(o,u,1,d,i,.3),O(o+Ll-1,u,1,d,a,.4);for(let m=0;m<d;m+=6)O(o+1,u+m,Ll-2,1,i,.06);const f=e.wx+e.ww;O(f,u,Ll,d,n),O(f,u,1,d,i,.2),O(f+Ll-1,u,1,d,a,.3)}function Lh(e){const{fx:n,fy:a,fw:i,fh:o}=e,u="#B08040",d="#C89848",f="#8A6030",m="#6A4820";O(n,a,i,o,u),Ts(42);for(let h=0;h<o;h+=5){const x=Math.floor(h/5)%2*10;for(let g=-10;g<i+10;g+=20){const w=n+g+x,b=Math.max(n,w),j=Math.min(w+19,n+i)-b;if(j<=0)continue;const k=Ea()>.5?d:u;O(b,a+h,j,4,k,.25),O(b,a+h,j,1,d,.3),O(b,a+h+4,j,1,m,.35),w>=n&&w<n+i&&O(w,a+h,1,4,m,.2),O(b,a+h+2,j,1,f,.1)}}O(n,a,i,2,"#0A0808",.08),O(n,a,2,o,"#0A0808",.06)}function hy(e){const{fx:n,fy:a,fw:i,fh:o}=e,u="#1C2A38",d="#101820";Ts(99),O(n,a,i,o,u);for(let f=0;f<o;f+=ju)for(let m=0;m<i;m+=ju){const h=Math.min(ju,i-m),x=Math.min(ju,o-f);Ea()>.5&&O(n+m,a+f,h,x,bn(u,.2),.15),O(n+m+2,a+f+2,h-4,x-4,bn(u,.3),.08),O(n+m,a+f,h,1,d,.5),O(n+m,a+f,1,x,d,.5),O(n+m+1,a+f+1,1,x-1,bn(u,.4),.1),Ea()>.85&&it(n+m+4+Math.floor(Ea()*8),a+f+4+Math.floor(Ea()*8),"#3A6A9A",.08)}}function UA(e){const{fx:n,fy:a,fw:i,fh:o}=e,u="#387848",d="#4A9058",f="#285E38";O(n,a,i,o,u),Ts(77);for(let h=0;h<o;h+=2)for(let x=0;x<i;x+=2)Ea()>.5&&it(n+x,a+h,d,.1),Ea()>.8&&it(n+x+1,a+h+1,f,.12);const m=5;O(n+m,a+m,i-m*2,1,d,.45),O(n+m,a+o-m-1,i-m*2,1,f,.45),O(n+m,a+m,1,o-m*2,d,.35),O(n+i-m-1,a+m,1,o-m*2,f,.35)}function qA(e){const{fx:n,fy:a,fw:i,fh:o}=e,u="#D8C490",d="#B09060",f="#907848";Ts(55);for(let m=0;m<o;m+=8)for(let h=0;h<i;h+=8){const x=Math.min(8,i-h),g=Math.min(8,o-m),w=(h/8+m/8)%2===0?d:u;O(n+h,a+m,x,g,w),O(n+h+1,a+m+1,x-2,1,bn(w,.4),.2),O(n+h+1,a+m+1,1,g-2,bn(w,.4),.15),O(n+h+x-2,a+m+2,1,g-3,Na(w,.4),.15),O(n+h+2,a+m+g-2,x-3,1,Na(w,.4),.15),O(n+h,a+m,x,1,f,.3),O(n+h,a+m,1,g,f,.3)}}function YA(){const{canvasW:e,canvasH:n,rooms:a,doors:i}=Ke,o="#2A1E14",u="#3A2E24";if(O(0,0,e,bi,o),O(0,n-bi,e,bi,o),O(0,0,bi,n,o),O(e-bi,0,bi,n,o),O(0,0,e,1,u,.3),O(0,0,1,n,u,.2),!a.exec||!a.work||!a.meet||!a.comm)return;const d=a.exec,f=a.meet,m=e/2,h=m-Xt/2,x=d.fy+d.fh,g=i.exec_work,w=i.meet_comm,b=i.exec_meet,j=i.work_comm,k=24,E=28,C=((g==null?void 0:g.doorY)??d.fy+20)-k/2,N=((b==null?void 0:b.doorX)??bi+Ll+54)-E/2,_=((j==null?void 0:j.doorX)??m+Xt/2+Ll+54)-E/2,z=((w==null?void 0:w.doorY)??f.fy+20)-k/2;O(0,x,N,Xt,o),O(N+E,x,h-N-E,Xt,o),O(h+Xt,x,_-h-Xt,Xt,o),O(_+E,x,e-_-E,Xt,o),O(0,x,N,1,u,.3),O(N+E,x,h-N-E,1,u,.3),O(h+Xt,x,_-h-Xt,1,u,.3),O(_+E,x,e-_-E,1,u,.3),O(h,0,Xt,C,o),O(h,C+k,Xt,x-C-k,o),O(h,x+Xt,Xt,z-x-Xt,o),O(h,z+k,Xt,n-z-k,o),O(h,0,1,C,u,.2),O(h,C+k,1,x-C-k,u,.2),O(h,x+Xt,1,z-x-Xt,u,.2),O(h,z+k,1,n-z-k,u,.2),O(h,C,Xt,k,"#C4A070"),O(h+Xt/2,C,Xt/2,k,"#3A4858"),O(h,z,Xt,k,"#7AA880"),O(h+Xt/2,z,Xt/2,k,"#C8B890");const H="#4A3828";O(h,C-1,Xt,1,H),O(h,C+k,Xt,1,H),O(N-1,x,1,Xt,H),O(N+E,x,1,Xt,H),O(_-1,x,1,Xt,H),O(_+E,x,1,Xt,H),O(h,z-1,Xt,1,H),O(h,z+k,Xt,1,H)}const my=new Map;function XA(e,n="right"){const a=`${e.hairStyle??""}|${e.outfitStyle??""}|${e.accessory??""}|${n}`;let i=my.get(a);if(!i){const o=am("mini-seated:default"),u=Ib(o,e);let d=u?u.layers.flatMap(f=>f.pixels):[];n==="left"&&d.length>0&&(d=nm(d,12)),i=d,my.set(a,i)}return i}function WA(e,n,a,i="right"){Il(Xe,XA(a,i),e,n,a)}function GA(e,n,a,i,o,u="right"){vi(e+8,n+20,"up"),o||WA(e+8,n+0+i,a,u),RA(e,n+14)}function VA(e,n,a,i,o){const u=i in ry?i:"down",d=o%4,f=ry[u][d];Il(Xe,f,e,n,a);const m=d===1||d===3?-1:0;if(a.accessory&&a.accessory!=="none"){const h=aC(a.accessory,u);h&&h.pixels.length>0&&Il(Xe,h.pixels,e,n+m,a)}Xe.globalAlpha=1}let $o=[],Ci=!1,Cs=0;function KA(){const e=Object.keys(Ke.rooms),n=e[Math.floor(Math.random()*e.length)],a=Ke.rooms[n];return{x:a.fx+a.fw/2,y:a.fy+a.fh/2,dir:"down",walkFrame:0,walkTimer:0,path:[],room:n,state:"walking",stateTimer:0,tongueTimer:0,idleTime:0}}function QA(e){if(e.stateTimer--,Ci){Cs++,e.dir="down",e.walkFrame=0,e.tongueTimer++,e.idleTime=0;return}else Cs=0;if(e.state==="idle"){if(e.tongueTimer++,e.idleTime++,e.stateTimer<=0){e.state="walking",e.tongueTimer=0;const n=Object.keys(Ke.rooms);if(Math.random()<.35&&n.length>1){const a=n.filter(d=>d!==e.room),i=a[Math.floor(Math.random()*a.length)],o=ep(e,i),u=Ke.waypoints[i];if(u&&u.length>0){const d=u[Math.floor(Math.random()*u.length)],f=o[o.length-1]??{x:e.x,y:e.y},m=Ei(f.x,f.y,d.x,d.y,i);e.path=[...o,...m]}else e.path=o}else{const a=Ke.waypoints[e.room];if(a&&a.length>0){const i=a[Math.floor(Math.random()*a.length)];e.path=Ei(e.x,e.y,i.x,i.y,e.room)}}e.walkTimer=0}}else if(e.state==="walking"){if(e.idleTime=0,e.path.length===0){e.state="idle",e.dir="down",e.stateTimer=120+Math.floor(Math.random()*240);return}const n=e.path[0],a=n.x-e.x,i=n.y-e.y,o=Math.sqrt(a*a+i*i);if(o<1.5){e.x=n.x,e.y=n.y,e.path.shift();for(const[u,d]of Object.entries(Ke.rooms))if(e.x>=d.fx&&e.x<=d.fx+d.fw&&e.y>=d.fy&&e.y<=d.fy+d.fh){e.room=u;break}}else e.x+=a/o*.15,e.y+=i/o*.15,Math.abs(a)>Math.abs(i)?e.dir=a>0?"right":"left":e.dir=i>0?"down":"up",e.walkTimer++,e.walkFrame=Math.floor(e.walkTimer/15)%2}}function PA(e){const n=Math.round(e.x),a=Math.round(e.y);if(Ci&&Cs>90){const d=Math.floor(Cs/12)%2===0?nA:rA;Il(Xe,iA,n,a),Il(Xe,d,n,a);return}const i=e.state==="walking"?e.walkFrame:0,o=eA[e.dir][i],u=e.dir==="left"||e.dir==="right";Il(Xe,u?lA:aA,n,a),Il(Xe,o,n,a),e.state==="idle"&&e.dir==="down"&&e.tongueTimer%80<50&&Il(Xe,tA,n,a)}function ZA(e){const n={};let a=0;for(const i of e){const o=vn[i];o&&(n[i]={state:"sitting",homeX:o.dx+8,homeY:o.dy+34,homeRoom:o.room,x:o.dx+8,y:o.dy+34,path:[],room:o.room,dir:"down",walkFrame:0,walkTimer:0,bobY:0,bobOff:a*17,stateTimer:1200+Math.floor(Math.random()*1800),sittingTime:0,lookDir:"right",isStretching:!1,stretchTimer:0},a++)}return n}function Ei(e,n,a,i,o){const u=Ke.corridorY[o]??n,d=[];return n<u-4&&d.push({x:e,y:u}),Math.abs(e-a)>4&&d.push({x:a,y:u}),d.push({x:a,y:i}),d}function Ih(e,n,a,i){const o=Ke.adjacency[a];if(!o)return[];const u=o.find(x=>x.room===i);if(!u)return[];const d=Ke.doors[u.door];if(!d)return[];const f=[],m=Ke.corridorY[a]??n,h=Ke.corridorY[i]??n;if(Math.abs(n-m)>4&&f.push({x:e,y:m}),d.type==="v"){const x=u.side==="A"?d.xA:d.xB,g=u.side==="A"?d.xB:d.xA;f.push({x,y:m}),f.push({x,y:d.doorY}),f.push({x:g,y:d.doorY}),f.push({x:g,y:h})}else{const x=u.side==="A"?d.yA:d.yB,g=u.side==="A"?d.yB:d.yA;f.push({x:d.doorX,y:m}),f.push({x:d.doorX,y:x}),f.push({x:d.doorX,y:g}),f.push({x:d.doorX,y:h})}return f}function ep(e,n){const a=Ke.adjacency[e.room];if(!a)return[];if(!a.find(o=>o.room===n)){for(const o of a){const u=Ke.adjacency[o.room];if(u!=null&&u.find(d=>d.room===n)){const d=Ih(e.x,e.y,e.room,o.room),f=d[d.length-1],m=Ih((f==null?void 0:f.x)??e.x,(f==null?void 0:f.y)??e.y,o.room,n);return[...d,...m]}}return[]}return Ih(e.x,e.y,e.room,n)}function JA(e){if(e.room!==e.homeRoom){const n=ep({...e},e.homeRoom),a=n[n.length-1],i=Ei((a==null?void 0:a.x)??e.x,(a==null?void 0:a.y)??e.y,e.homeX,e.homeY,e.homeRoom);return[...n,...i]}return Ei(e.x,e.y,e.homeX,e.homeY,e.room)}function e8(e,n){if($h--,$h<=0){const a=Object.entries(e).filter(([,i])=>i.state==="sitting"&&!i.isStretching);if(a.length>0){const[,i]=a[Math.floor(Math.random()*a.length)];i.isStretching=!0,i.stretchTimer=120}$h=900}for(const[a,i]of Object.entries(e))if(i.stateTimer--,i.isStretching&&i.stretchTimer>0&&(i.stretchTimer--,i.stretchTimer<=0&&(i.isStretching=!1)),i.state==="sitting"){if(i.sittingTime++,er===a){i.sittingTime=0,i.bobY=-3;const u=vn[a];if(u){const d=u.dx+13;i.lookDir=Dv<d?"left":"right"}}else i.bobY=(n+i.bobOff)%60<30?1:0,i.lookDir="right";if(i.stateTimer<=0){i.state="walking",i.x=i.homeX,i.y=i.homeY,i.room=i.homeRoom;const u=Object.keys(Ke.rooms);if(Math.random()<.15&&u.length>1){const d=u.filter(x=>x!==i.room),f=d[Math.floor(Math.random()*d.length)],m=ep(i,f),h=Ke.waypoints[f];if(h&&h.length>0){const x=h[Math.floor(Math.random()*h.length)],g=m[m.length-1]??{x:i.x,y:i.y},w=Ei(g.x,g.y,x.x,x.y,f);i.path=[...m,...w]}else i.path=m;i.walkTimer=0}else{const d=Ke.waypoints[i.room];if(d&&d.length>0){const f=d[Math.floor(Math.random()*d.length)];i.path=Ei(i.x,i.y,f.x,f.y,i.room)}i.walkTimer=0}}}else if(i.state==="walking"||i.state==="returning"){if(i.sittingTime=0,er===a){i.dir="down",i.walkFrame=0;continue}if(i.path.length===0){i.state==="returning"?(i.state="sitting",i.room=i.homeRoom,i.stateTimer=1200+Math.floor(Math.random()*1800)):(i.state="idle",i.dir="down",i.stateTimer=180+Math.floor(Math.random()*360));continue}const u=i.path[0],d=u.x-i.x,f=u.y-i.y,m=Math.sqrt(d*d+f*f);if(m<1.5){i.x=u.x,i.y=u.y,i.path.shift();for(const[h,x]of Object.entries(Ke.rooms))if(i.x>=x.fx&&i.x<=x.fx+x.fw&&i.y>=x.fy&&i.y<=x.fy+x.fh){i.room=h;break}}else i.x+=d/m*.2,i.y+=f/m*.2,Math.abs(d)>Math.abs(f)?i.dir=d>0?"right":"left":i.dir=f>0?"down":"up",i.walkTimer++,i.walkFrame=Math.floor(i.walkTimer/12)%4}else if(i.state==="idle"){if(er===a){i.dir="down";continue}if(i.stateTimer<=0)if(Math.random()<.15){i.state="walking";const o=Ke.waypoints[i.room];if(o&&o.length>0){const u=o[Math.floor(Math.random()*o.length)];i.path=Ei(i.x,i.y,u.x,u.y,i.room)}i.walkTimer=0}else i.state="returning",i.path=JA(i),i.walkTimer=0}}function t8(e,n,a,i){const{canvasW:o,canvasH:u,rooms:d}=Ke;Xe.clearRect(0,0,o,u),O(0,0,o,u,"#2A1E14");const f={wood:Lh,dark:hy,carpet:UA,tile:qA};for(const b of Object.values(d))(f[b.floorType]??Lh)(b);const m=Object.keys(d);if(m.length>=4){const b=d.exec,j=d.meet,{doors:k}=Ke;if(b&&j&&k.exec_meet&&k.work_comm){const C=(k.exec_meet.doorX??0)-14,N=(k.work_comm.doorX??0)-28/2,_=b.fy+b.fh,z=j.fy;Lh({fx:C,fy:_,fw:28,fh:z-_}),hy({fx:N,fy:_,fw:28,fh:z-_})}}const h={};if(m.length>=4){const{doors:b}=Ke,j=28,k=b.exec_meet,E=b.work_comm;k!=null&&k.doorX&&(h.meet={x:k.doorX-j/2,w:j}),E!=null&&E.doorX&&(h.comm={x:E.doorX-j/2,w:j})}for(const b of Object.values(d))IA(b,h[b.id]),HA(b);YA(),zA(Ke);const x=[],g=new Set(Object.values(vn).map(b=>b.room));_A(Ke,x,g);for(const[b,j]of Object.entries(vn)){const k=e[b];if(!k)continue;const E=k.state==="sitting",C=n(b),N=a[b]==="working",_=k.isStretching&&k.stretchTimer>0?Math.sin(k.stretchTimer*.15)*1:0;x.push({y:j.dy+14,draw:()=>{const z=E?k.bobY+_:0;if(GA(j.dx,j.dy,C,z,!E,k.lookDir),E&&N){const H=Yu[b]??"#388bfd";O(j.dx+7,j.dy+14-4,12,5,H,.15),it(j.dx+12,j.dy+14+1,"#4CAF50",.8)}}})}for(const[b,j]of Object.entries(e))if(j.state!=="sitting"){const k=n(b);x.push({y:j.y+14,draw:()=>VA(Math.round(j.x),Math.round(j.y),k,j.dir,j.walkFrame)})}i&&x.push({y:i.y+10,draw:()=>PA(i)}),x.sort((b,j)=>b.y-j.y);for(const b of x)b.draw();for(const b of wa){const j=ki===b.id,k=Av(b);if(Xe.save(),Xe.globalAlpha=j?.9:.5,Xe.fillStyle=b.color,Xe.fillRect(k.cx-1,k.botY-2,3,3),j){const E=Nv(b);Xe.globalAlpha=.3,Xe.strokeStyle=b.color,Xe.lineWidth=1,Xe.strokeRect(E.x-1,E.y-1,E.w+2,E.h+2)}Xe.restore()}if(nl){const b=new Set(Object.values(vn).map(j=>j.room));if(sa&&sa!==Rr)if(sa.startsWith("desk:")){const j=sa.slice(5),k=vn[j];k&&cy(Xe,k.dx,k.dy,"#FBBF24")}else oy(Xe,Ke,sa,"#FBBF24",b);if(Rr)if(Rr.startsWith("desk:")){const j=Rr.slice(5),k=vn[j];k&&cy(Xe,k.dx,k.dy,"#3B82F6")}else oy(Xe,Ke,Rr,"#3B82F6",b)}if(er){const b=vn[er],j=e[er];if(b&&j){Xe.save(),Xe.globalAlpha=.25,Xe.fillStyle=Yu[er]??"#fff",j.state==="sitting"?Xe.fillRect(b.dx-1,b.dy+6,28,30):Xe.fillRect(Math.round(j.x)-1,Math.round(j.y)-1,14,24),Xe.globalAlpha=.95,Xe.fillStyle="#FBBF24",Xe.font="bold 8px monospace",Xe.textAlign="center";const k=j.state==="sitting"?b.dx+13:Math.round(j.x)+6,E=j.state==="sitting"?b.dy-1:Math.round(j.y)-5;Xe.fillText("!",k,E),Xe.restore()}}const w=3600;for(const[,b]of Object.entries(e))if(b.state==="sitting"&&b.sittingTime>w&&!b.isStretching){const j=Object.values(vn).find(z=>z.dx+8===b.homeX&&z.dy+34===b.homeY);if(!j)continue;const k=j.dx+13,E=j.dy,C=Math.floor(b.sittingTime/40)%3;Xe.save(),Xe.font="5px monospace",Xe.textAlign="center";const N=[.7,.5,.3],_=[{x:3,y:-2-C},{x:6,y:-5-(C+1)%3},{x:4,y:-8-(C+2)%3}];for(let z=0;z<3;z++)Xe.globalAlpha=N[z],Xe.fillStyle="#93C5FD",Xe.font=`${4+z}px monospace`,Xe.fillText("z",k+_[z].x,E+_[z].y);Xe.restore()}$o=$o.filter(b=>b.life>0);for(const b of $o)b.x+=b.vx,b.y+=b.vy,b.life--,Xe.save(),Xe.globalAlpha=Math.min(1,b.life/(b.maxLife*.3)),Xe.fillStyle=b.color??"#FF6B8A",Xe.font="8px serif",Xe.fillText(b.char,Math.round(b.x),Math.round(b.y)),Xe.restore();if(Ci&&i&&Cs<=90){const b=Math.round(i.x),j=Math.round(i.y);Xe.save(),Xe.globalAlpha=.9,Xe.fillStyle="#FBBF24",Xe.font="bold 5px monospace",Xe.textAlign="center",Xe.fillText("!",b+4,j-2),Xe.restore()}if(i&&!Ci&&i.state==="idle"&&i.idleTime>600){const b=Math.round(i.x),j=Math.round(i.y),k=Math.floor(i.idleTime/40)%3;Xe.save();const E=[{x:3,y:-2-k},{x:5,y:-5-(k+1)%3},{x:4,y:-8-(k+2)%3}];for(let C=0;C<3;C++)Xe.globalAlpha=[.7,.5,.3][C],Xe.fillStyle="#93C5FD",Xe.font=`${3+C}px monospace`,Xe.textAlign="center",Xe.fillText("z",b+E[C].x,j+E[C].y);Xe.restore()}if(Ci&&i&&Cs<=90){const b=Math.round(i.x),j=Math.round(i.y),k=Math.floor(Date.now()/150)%2===0?-1:1;i.dir==="down"&&(Xe.fillStyle="#FAFAF7",Xe.fillRect(b+4+k,j-1,2,2))}}function n8(e,n){for(let a=0;a<4;a++)$o.push({x:e+(Math.random()-.5)*8,y:n,vx:(Math.random()-.5)*.3,vy:-.3-Math.random()*.2,life:60+Math.floor(Math.random()*30),maxLife:80,char:a%2===0?"♥":"♡",color:"#FF6B8A"})}function r8(e,n){for(let a=0;a<3;a++)$o.push({x:e+(Math.random()-.5)*8,y:n,vx:(Math.random()-.5)*.3,vy:-.3-Math.random()*.2,life:60+Math.floor(Math.random()*30),maxLife:80,char:"💧",color:"#64B5F6"})}function a8({roles:e,projects:n,roleStatuses:a,activeExecs:i,onRoleClick:o,onProjectClick:u,onBulletinClick:d,onDecisionsClick:f,onKnowledgeClick:m,onSettingsClick:h,onThemeClick:x,onStatsClick:g,getRoleSpeech:w,getAppearance:b,onHireClick:j,onMascotClick:k,roleLevels:E,coinBalance:C=0,onCoinsSpent:N,onFurniturePlaced:_,purchasedPreset:z,language:H="en"}){const R=v.useRef(null),I=v.useRef(null),q=v.useRef(null),X=v.useRef({}),A=v.useRef(null),$=v.useRef(0),L=v.useRef(OA),[Y,se]=v.useState(!1),[ee,W]=v.useState(null),[oe,de]=v.useState(null),V=v.useRef({}),D=v.useRef({}),B=v.useRef([]),U=v.useRef([]);v.useEffect(()=>{nl=Y},[Y]),v.useEffect(()=>{Ol=ee,va=oe},[ee,oe]);const[T,ie]=v.useState(!1);v.useEffect(()=>{ye.getPreferences().then(me=>{const Se=me.furnitureOverrides;Se&&Object.keys(Se).length>0&&(V.current=Se);const Ne=me.deskOverrides;Ne&&Object.keys(Ne).length>0&&(D.current=Ne);const K=me.removedFurniture;K&&K.length>0&&(B.current=K);const ue=me.addedFurniture;ue&&ue.length>0&&(U.current=ue),ie(!0)}).catch(()=>{ie(!0)})},[]);const ge=v.useRef({roleStatuses:a,activeExecs:i,getRoleSpeech:w,getAppearance:b});ge.current={roleStatuses:a,activeExecs:i,getRoleSpeech:w,getAppearance:b};const pe=v.useRef({}),ze=v.useMemo(()=>e.map(me=>me.id),[e]),Ie=v.useRef(Ke);v.useEffect(()=>{if(!T)return;const me=ze.length,Se=kv(me,Ie.current.preset,z),Ne=Ie.current.preset!==Se;let K=jv(me,Se);B.current.length>0&&(K=sy(K,B.current)),U.current.length>0&&(K=hA(K,U.current)),Object.keys(V.current).length>0&&(K=dA(K,V.current)),Ke=K,Ie.current=K,vn=LA(ze),Object.keys(D.current).length>0&&fA(vn,D.current),wa=wi(K),X.current=ZA(ze),A.current=KA();const ue=R.current;ue&&(ue.width=K.canvasW,ue.height=K.canvasH,Ne&&(ue.style.opacity="0",ue.style.transition="opacity 0.3s",setTimeout(()=>{ue.style.opacity="1"},50))),st()},[ze,z,T]);const He=v.useCallback(me=>{var Se,Ne;return((Ne=(Se=ge.current).getAppearance)==null?void 0:Ne.call(Se,me))??Km(me)},[]),st=v.useCallback(()=>{const me=I.current,Se=R.current;if(!me||!Se)return;const Ne=me.parentElement;if(!Ne)return;const K=Ne.clientWidth,ue=Ne.clientHeight;if(K===0||ue===0)return;const{canvasW:te,canvasH:ke}=Ke;let ve=Math.min(K/te,ue/ke);ve=Math.round(ve*2)/2,ve=Math.max(2,Math.min(ve,5)),L.current=ve,Se.style.width=te*ve+"px",Se.style.height=ke*ve+"px",me.style.width=te*ve+"px",me.style.height=ke*ve+"px"},[]);v.useEffect(()=>{var ke;const me=R.current;if(!me)return;const Se=me.getContext("2d");if(!Se)return;Xe=Se,mA(Se),st();const Ne=new ResizeObserver(()=>st()),K=(ke=I.current)==null?void 0:ke.parentElement;K&&Ne.observe(K);let ue;const te=()=>{$.current++,e8(X.current,$.current),A.current&&QA(A.current),t8(X.current,He,ge.current.roleStatuses,A.current),Qe(),ue=requestAnimationFrame(te)};return ue=requestAnimationFrame(te),()=>{cancelAnimationFrame(ue),Ne.disconnect()}},[He,st]),v.useEffect(()=>{var te;const me=q.current;if(!me)return;me.innerHTML="";const Se={};for(const ke of e)Se[ke.id]=ke.name;for(const ke of ze){const ve=Yu[ke]??"#8b949e",_e=Se[ke],Be=_e&&_e.toLowerCase()!==ke.toLowerCase()?`${ke.toUpperCase()} · ${_e}`:ke.toUpperCase(),Oe=document.createElement("div");Oe.className="td-nametag",Oe.dataset.role=ke;const qe=document.createElement("span");qe.className="td-dot",qe.style.background=ve,Oe.appendChild(qe),Oe.appendChild(document.createTextNode(Be));const rt=((te=E==null?void 0:E[ke])==null?void 0:te.level)??1;if(rt>1){const bt=document.createElement("span");bt.className="td-lvl",bt.textContent=`Lv.${rt}`,Oe.appendChild(bt)}me.appendChild(Oe);const Ve=document.createElement("div");Ve.className="td-bubble",Ve.dataset.role=ke,Ve.dataset.type="bubble",me.appendChild(Ve)}const Ne={meeting:()=>{const ke=n[0];ke?u(ke.id):d()},bulletin:d,decisions:f,knowledge:m,settings:h,theme:x,stats:g};for(const ke of wa){const ve=document.createElement("div");ve.className="td-facility-label",ve.dataset.facility=ke.id,ke.id==="meeting"&&(ve.dataset.questTarget="meeting-room"),ke.id==="knowledge"&&(ve.dataset.questTarget="knowledge-hub"),ke.id==="bulletin"&&(ve.dataset.questTarget="bulletin-board"),ke.id==="stats"&&(ve.dataset.questTarget="stats-btn"),ke.id==="settings"&&(ve.dataset.questTarget="settings-btn"),ke.id==="theme"&&(ve.dataset.questTarget="theme-btn"),ve.textContent=`${ke.icon} ${ke.label}`,ve.style.borderColor=`${ke.color}44`;const _e=Ne[ke.id];_e&&ve.addEventListener("click",_e),ve.addEventListener("mouseenter",()=>{ki=ke.id}),ve.addEventListener("mouseleave",()=>{ki=null}),me.appendChild(ve)}const K=document.createElement("div");K.className="td-nametag td-nametag-mascot",K.dataset.role="mascot";const ue=document.createElement("span");ue.className="td-dot",ue.style.background="#ffd700",K.appendChild(ue),K.appendChild(document.createTextNode("Pupu")),K.addEventListener("click",()=>k==null?void 0:k()),me.appendChild(K)},[ze,e,n,u,d,f,m,h,x,g,k,E]);const Qe=v.useCallback(()=>{var _e;const me=q.current;if(!me)return;const Se=L.current,Ne=X.current,{getRoleSpeech:K,roleStatuses:ue,activeExecs:te}=ge.current;for(const Be of Object.keys(Ne)){const Oe=Ne[Be],qe=vn[Be];if(!qe)continue;let rt,Ve,bt;Oe.state==="sitting"?(rt=qe.dx+13,bt=qe.dy+2,Ve=qe.dy+37):(rt=Math.round(Oe.x)+6,bt=Math.round(Oe.y)-2,Ve=Math.round(Oe.y)+18);const Re=rt/Ke.canvasW*100,Ue=me.querySelector(`.td-nametag[data-role="${Be}"]`);if(Ue){Ue.style.left=Re+"%",Ue.style.top=Ve*Se+2+"px";const Bt=Ue.querySelector(".td-dot");if(Bt){const Ot=ue[Be]==="working";Bt.style.background=Ot?"#FBBF24":Yu[Be]??"#8b949e",Ot?Bt.style.animation="td-pulse 1s ease-in-out infinite":Bt.style.animation=""}}const _t=me.querySelector(`.td-bubble[data-role="${Be}"]`);if(_t){const Bt=Date.now(),Ot=ue[Be]==="working",fn=(_e=te.find(Qt=>Qt.roleId===Be))==null?void 0:_e.task,wn=K(Be);let Z="";const $e=pe.current[Be];if($e){if($e.speechDismissTime&&Bt>=$e.speechDismissTime&&($e.currentSpeech=null,$e.speechDismissTime=null),$e.hoverStartTime&&!$e.currentSpeech){const Qt=Bt-$e.hoverStartTime,we=!$e.lastSpeechTime||Bt-$e.lastSpeechTime>=5e3;if(Qt>=2e3&&we){const kt=$A(Be,H),ln=kt[Math.floor(Math.random()*kt.length)];$e.currentSpeech=ln,$e.lastSpeechTime=Bt,$e.speechDismissTime=Bt+3e3}}Z=$e.currentSpeech||""}const nt=Ot&&fn?fn.slice(0,60):Z?Z.slice(0,60):wn?wn.slice(0,60):"";nt&&Oe.state==="sitting"?(_t.style.display="",_t.style.left=Re+"%",_t.style.top=(bt-10)*Se+"px",_t.textContent=nt):_t.style.display="none"}}const ke=me.querySelector(".td-nametag-mascot"),ve=A.current;if(ke&&ve){const Be=ve.dir==="left"||ve.dir==="right",Oe=Math.round(ve.x)+(Be?6:4),qe=Math.round(ve.y)+(Be?7:10);ke.style.left=Oe/Ke.canvasW*100+"%",ke.style.top=qe*Se+2+"px"}for(const Be of wa){const Oe=me.querySelector(`.td-facility-label[data-facility="${Be.id}"]`);if(Oe){const qe=Av(Be);Oe.style.left=qe.cx/Ke.canvasW*100+"%",Oe.style.top=qe.botY*Se-4+"px",Oe.classList.toggle("td-facility-label--hover",ki===Be.id)}}},[]),et=v.useCallback(me=>{const Se=R.current;if(!Se)return null;const Ne=Se.getBoundingClientRect(),K=L.current,ue=(me.clientX-Ne.left)/K,te=(me.clientY-Ne.top)/K,ke=X.current;for(const[_e,Be]of Object.entries(vn)){if(!ke[_e])continue;const Oe=ke[_e];if(Oe.state==="sitting"){if(ue>=Be.dx&&ue<=Be.dx+26&&te>=Be.dy&&te<=Be.dy+40)return{type:"role",id:_e}}else if(ue>=Oe.x-2&&ue<=Oe.x+14&&te>=Oe.y-2&&te<=Oe.y+20)return{type:"role",id:_e}}const ve=A.current;if(ve){const _e=ve.dir==="left"||ve.dir==="right",Be=_e?13:9,Oe=_e?7:10;if(ue>=ve.x&&ue<=ve.x+Be&&te>=ve.y&&te<=ve.y+Oe)return{type:"mascot",id:"mascot"}}for(const _e of wa){const Be=Nv(_e);if(ue>=Be.x&&ue<=Be.x+Be.w&&te>=Be.y&&te<=Be.y+Be.h)return{type:"facility",id:_e.id}}return null},[]),Ee=v.useCallback(me=>{const Se=R.current;if(!Se)return{mx:0,my:0};const Ne=Se.getBoundingClientRect(),K=L.current;return{mx:(me.clientX-Ne.left)/K,my:(me.clientY-Ne.top)/K}},[]),De=v.useCallback(me=>{ye.updatePreferences(me).catch(()=>{})},[]),yt=v.useCallback(me=>{const Se=U.current.some(K=>K.id===me),Ne={};if(Se){const K=U.current.filter(ue=>ue.id!==me);U.current=K,Ne.addedFurniture=K}else{const K=[...B.current,me];B.current=K,Ne.removedFurniture=K}Ke=sy(Ke,[me]),wa=wi(Ke),Rr=null,sa=null,De(Ne)},[De]),ut=v.useCallback((me,Se)=>{if(!Ol||!va)return;const Ne=dy.find(Oe=>Oe.type===Ol),K=(Ne==null?void 0:Ne.price)??0;if(K>0&&C<K)return;let ue=null;for(const[Oe,qe]of Object.entries(Ke.rooms)){const rt=va==="wall"?qe.wx:qe.fx,Ve=va==="wall"?qe.wy:qe.fy,bt=va==="wall"?qe.ww:qe.fw,Re=va==="wall"?qe.wh:qe.fh;if(me>=rt&&me<=rt+bt&&Se>=Ve&&Se<=Ve+Re){ue=Oe;break}}if(!ue)return;const te=Ke.rooms[ue],ke=va==="wall"?te.wx:te.fx,ve=va==="wall"?te.wy:te.fy,_e={id:`user-${Ol}-${Date.now()}`,type:Ol,room:ue,zone:va,offsetX:Math.round(me-ke),offsetY:Math.round(Se-ve)},Be=[...U.current,_e];if(U.current=Be,va==="wall"?Ke.wallDecorations.push(_e):Ke.furniture.push(_e),wa=wi(Ke),De({addedFurniture:Be}),_==null||_(Ol,K),K>0){const Oe=_e.type;Ey(async()=>{const{api:qe}=await Promise.resolve().then(()=>Sw);return{api:qe}},void 0).then(({api:qe})=>{qe.spendCoins(K,`furniture: ${Oe}`,_e.id).then(rt=>N==null?void 0:N(rt.balance)).catch(()=>{})})}W(null),de(null)},[De,C,N,_]),pt=v.useCallback(me=>{const Se=R.current;if(nl&&rr){const{mx:ke,my:ve}=Ee(me),Be=[...Ke.furniture,...Ke.wallDecorations].find(rt=>rt.id===rr.defId);if(!Be)return;const Oe=ke-rr.startMx,qe=ve-rr.startMy;Be.offsetX=Math.round(rr.origOffX+Oe),Be.offsetY=Math.round(rr.origOffY+qe),wa=wi(Ke),Se&&(Se.style.cursor="grabbing");return}if(nl&&Hn){const{mx:ke,my:ve}=Ee(me),_e=vn[Hn.roleId];if(!_e)return;_e.dx=Math.round(Hn.origDx+(ke-Hn.startMx)),_e.dy=Math.round(Hn.origDy+(ve-Hn.startMy));const Be=X.current[Hn.roleId];Be&&(Be.homeX=_e.dx+8,Be.homeY=_e.dy+34),Se&&(Se.style.cursor="grabbing");return}if(nl){const{mx:ke,my:ve}=Ee(me);if(Ol){Se&&(Se.style.cursor="crosshair");return}const _e=new Set(Object.values(vn).map(Oe=>Oe.room)),Be=Oh(Ke,ke,ve,_e);if(Be)sa=Be;else{const Oe=uy(vn,ke,ve);sa=Oe?`desk:${Oe}`:null}er=null,ki=null,Se&&(Se.style.cursor=sa?"grab":"default");return}const Ne=et(me),K=er;er=(Ne==null?void 0:Ne.type)==="role"?Ne.id:null,ki=(Ne==null?void 0:Ne.type)==="facility"?Ne.id:null,Ci=(Ne==null?void 0:Ne.type)==="mascot",sa=null,Se&&(Se.style.cursor=Ne?"pointer":"default");const{mx:ue}=Ee(me);Dv=ue;const te=Date.now();if(er&&er!==K){pe.current[er]||(pe.current[er]={hoverStartTime:null,lastSpeechTime:null,currentSpeech:null,speechDismissTime:null});const ke=pe.current[er];ke.hoverStartTime=te}else if(!er&&K){const ke=pe.current[K];ke&&(ke.hoverStartTime=null)}},[et,Ee]),jt=v.useCallback(me=>{if(!nl)return;const{mx:Se,my:Ne}=Ee(me);if(Ol){ut(Se,Ne),me.preventDefault();return}const K=new Set(Object.values(vn).map(ke=>ke.room)),ue=Oh(Ke,Se,Ne,K);if(ue){const ve=[...Ke.furniture,...Ke.wallDecorations].find(_e=>_e.id===ue);ve&&(Rr=ue,rr={defId:ue,startMx:Se,startMy:Ne,origOffX:ve.offsetX,origOffY:ve.offsetY},me.preventDefault());return}const te=uy(vn,Se,Ne);if(te){const ke=vn[te];Rr=`desk:${te}`,Hn={roleId:te,startMx:Se,startMy:Ne,origDx:ke.dx,origDy:ke.dy},me.preventDefault();return}Rr=null},[Ee,ut]),Wt=v.useCallback(me=>{if(rr){const Ne=[...Ke.furniture,...Ke.wallDecorations].find(K=>K.id===rr.defId);if(Ne){const K={...V.current,[Ne.id]:{offsetX:Ne.offsetX,offsetY:Ne.offsetY}};V.current=K,De({furnitureOverrides:K}),wa=wi(Ke)}rr=null,R.current&&(R.current.style.cursor="grab");return}if(Hn){const Se=vn[Hn.roleId];if(Se){const Ne={...D.current,[Hn.roleId]:{dx:Se.dx,dy:Se.dy}};D.current=Ne,De({deskOverrides:Ne})}Hn=null,R.current&&(R.current.style.cursor="grab")}},[De]),Ft=v.useCallback(me=>{if(!nl)return;me.preventDefault();const{mx:Se,my:Ne}=Ee(me),K=new Set(Object.values(vn).map(te=>te.room)),ue=Oh(Ke,Se,Ne,K);ue&&yt(ue)},[Ee,yt]);v.useEffect(()=>{const me=Se=>{!nl||!Rr||(Se.key==="Delete"||Se.key==="Backspace")&&(Rr.startsWith("desk:")||yt(Rr))};return window.addEventListener("keydown",me),()=>window.removeEventListener("keydown",me)},[yt]);const Et=v.useCallback(()=>{if(rr){const Se=[...Ke.furniture,...Ke.wallDecorations].find(Ne=>Ne.id===rr.defId);Se&&(Se.offsetX=rr.origOffX,Se.offsetY=rr.origOffY,wa=wi(Ke)),rr=null}if(Hn){const me=vn[Hn.roleId];me&&(me.dx=Hn.origDx,me.dy=Hn.origDy);const Se=X.current[Hn.roleId];Se&&(Se.homeX=me.dx+8,Se.homeY=me.dy+34),Hn=null}er=null,ki=null,Ci=!1,sa=null,R.current&&(R.current.style.cursor="default")},[]),$n=v.useCallback(me=>{if(nl)return;const Se=et(me);if(Se){if(Se.type==="role"){const Ne=X.current[Se.id],K=vn[Se.id];if(Ne&&K){const ue=Ne.state==="sitting"?K.dx+13:Math.round(Ne.x)+6,te=Ne.state==="sitting"?K.dy+2:Math.round(Ne.y)-2;r8(ue,te)}o(Se.id);return}if(Se.type==="mascot"){const Ne=A.current;Ne&&n8(Math.round(Ne.x)+4,Math.round(Ne.y)-2),k==null||k();return}switch(Se.id){case"meeting":{const Ne=n[0];Ne?u(Ne.id):d();break}case"bulletin":d();break;case"decisions":f();break;case"knowledge":m();break;case"settings":h==null||h();break;case"theme":x==null||x();break;case"stats":g==null||g();break}}},[et,o,u,d,f,m,h,x,g]);return l.jsxs("div",{className:`td-scene${Y?" td-scene--editing":""}`,children:[l.jsxs("div",{ref:I,className:"td-wrap",children:[l.jsx("canvas",{ref:R,width:Ke.canvasW,height:Ke.canvasH,className:"td-canvas",onClick:$n,onMouseDown:jt,onMouseUp:Wt,onMouseMove:pt,onMouseLeave:Et,onContextMenu:Ft}),l.jsx("div",{ref:q,className:"td-overlay"})]}),Y&&l.jsxs("div",{className:"td-edit-banner",children:[l.jsx("span",{className:"td-edit-banner__icon",children:"✎"})," EDIT MODE — Click DONE when finished"]}),l.jsxs("button",{className:`td-edit-btn${Y?" td-edit-btn--active":""}`,"data-quest-target":"edit-btn",onClick:()=>{se(me=>{const Se=!me;return Se||(W(null),de(null)),Se}),Rr=null,rr=null,Hn=null},title:Y?"Exit Edit Mode":"Edit Furniture Layout",children:[l.jsx("span",{className:"td-edit-btn__icon",children:Y?"✓":"✎"}),l.jsx("span",{className:"td-edit-btn__label",children:Y?"DONE":"EDIT"})]}),Y&&l.jsx("div",{className:"td-palette",children:dy.map(me=>{const Se=me.price===0||C>=me.price,Ne=me.price===0?"Free":`${me.price>=1e3?`${(me.price/1e3).toFixed(me.price%1e3===0?0:1)}K`:me.price}`;return l.jsxs("button",{className:`td-palette__item${ee===me.type?" td-palette__item--active":""}${Se?"":" td-palette__item--locked"}`,onClick:()=>{Se&&(ee===me.type?(W(null),de(null)):(W(me.type),de(me.zone)))},title:`${me.label} — ${Ne}`,style:Se?void 0:{opacity:.4,cursor:"not-allowed"},children:[l.jsx("span",{children:me.icon}),l.jsx("span",{className:"td-palette__price",style:{fontSize:"7px",color:me.price===0?"#4CAF50":Se?"#FFD54F":"#EF5350"},children:Ne})]},me.type)})}),j&&l.jsxs("button",{className:"td-hire-btn","data-quest-target":"hire-btn",onClick:j,title:"Hire New Role",children:[l.jsx("span",{className:"td-hire-btn__icon",children:"+"}),l.jsx("span",{className:"td-hire-btn__label",children:"HIRE"})]})]})}function l8({role:e,appearance:n,onSave:a,onReset:i,onClose:o,theme:u,onThemeChange:d,onUpdateName:f,initialTab:m,characterOnly:h,speechSettings:x,onSpeechSettingsChange:g,language:w,onLanguageChange:b,roleLevel:j}){var $;const[k,E]=v.useState(m??"character"),[C,N]=v.useState({...n}),[_,z]=v.useState(e.name),[H,R]=v.useState(!1),I=v.useCallback(()=>N(ys(j)),[j]),q=v.useCallback(()=>{const L=Km(e.id);N({...L}),i()},[e.id,i]),X=v.useCallback(async()=>{a(C);const L=_.trim();if(f&&L&&L!==e.name){R(!0);try{await f(e.id,L)}catch{}R(!1)}o()},[C,a,o,_,e.name,e.id,f]),A=l.jsxs("span",{style:{display:"flex",alignItems:"center",gap:6},children:[l.jsxs("span",{children:[e.id.toUpperCase()," –"]}),f?l.jsx("input",{value:_,onChange:L=>z(L.target.value),disabled:H,className:"customize-name-input",style:{background:"rgba(255,255,255,0.08)",border:"1px solid rgba(255,255,255,0.15)",borderRadius:4,color:"inherit",font:"inherit",padding:"2px 6px",flex:1,minWidth:0}}):l.jsx("span",{children:e.name})]});return l.jsx("div",{className:"customize-overlay",onClick:o,children:l.jsxs("div",{className:"customize-modal",onClick:L=>L.stopPropagation(),children:[l.jsxs("div",{className:"customize-header",children:[l.jsxs("div",{className:"customize-tabs",children:[l.jsx("button",{className:`customize-tab ${k==="character"?"active":""}`,onClick:()=>E("character"),children:"CHARACTER"}),!h&&l.jsxs(l.Fragment,{children:[l.jsx("button",{className:`customize-tab ${k==="office"?"active":""}`,onClick:()=>E("office"),children:"OFFICE THEME"}),l.jsx("button",{className:`customize-tab ${k==="settings"?"active":""}`,onClick:()=>E("settings"),children:"SETTINGS"})]})]}),l.jsx("button",{className:"customize-close",onClick:o,children:"X"})]}),k==="character"?l.jsx("div",{className:"customize-body",children:l.jsx(fv,{roleId:e.id,appearance:C,onChange:N,onRandomize:I,onReset:q,label:A,roleLevel:j})}):k==="office"?l.jsx("div",{className:"customize-body",children:l.jsx("div",{className:"customize-themes",children:Object.entries(ll).map(([L,Y])=>l.jsxs("button",{className:`customize-theme-card ${u===L?"active":""}`,onClick:()=>d(L),children:[l.jsxs("div",{className:"customize-theme-preview",style:{background:Y.vars["--floor-light"],borderColor:Y.vars["--pixel-border"]},children:[l.jsx("div",{style:{background:Y.vars["--hud-bg"],height:8,borderBottom:`2px solid ${Y.vars["--pixel-border"]}`}}),l.jsxs("div",{className:"flex-1 flex items-center justify-center gap-1 p-1",children:[l.jsx("div",{style:{width:10,height:14,background:Y.vars["--accent"],borderRadius:1}}),l.jsx("div",{style:{width:10,height:14,background:Y.vars["--active-green"],borderRadius:1}}),l.jsx("div",{style:{width:10,height:14,background:Y.vars["--idle-amber"],borderRadius:1}})]}),l.jsx("div",{style:{background:Y.vars["--hud-bg"],height:6,borderTop:`2px solid ${Y.vars["--pixel-border"]}`}})]}),l.jsxs("div",{className:"customize-theme-name",children:[Y.icon," ",Y.name]})]},L))})}):l.jsx("div",{className:"customize-body",children:l.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:20,padding:"8px 0"},children:[l.jsxs("div",{children:[l.jsx("div",{style:{fontSize:11,fontWeight:600,marginBottom:8,color:"var(--terminal-text)"},children:"AMBIENT SPEECH MODE"}),l.jsx("div",{style:{display:"flex",gap:6},children:["template","llm","auto"].map(L=>l.jsxs("button",{onClick:()=>g==null?void 0:g({mode:L}),style:{flex:1,padding:"8px 12px",fontSize:11,border:`2px solid ${(x==null?void 0:x.mode)===L?"var(--accent)":"rgba(255,255,255,0.1)"}`,background:(x==null?void 0:x.mode)===L?"rgba(255,255,255,0.08)":"transparent",color:(x==null?void 0:x.mode)===L?"var(--terminal-text)":"var(--terminal-text-muted)",borderRadius:6,cursor:"pointer",textAlign:"center"},children:[l.jsx("div",{style:{fontWeight:600,marginBottom:2},children:L==="template"?"TEMPLATE":L==="llm"?"AI":"AUTO"}),l.jsx("div",{style:{fontSize:9,opacity:.7},children:L==="template"?"Static pool ($0)":L==="llm"?"LLM generated":"Detect engine"})]},L))}),l.jsx("div",{style:{fontSize:9,color:"var(--terminal-text-muted)",marginTop:4},children:"Auto: CLI Max = AI, BYOK = Template"})]}),l.jsxs("div",{children:[l.jsxs("div",{style:{fontSize:11,fontWeight:600,marginBottom:8,color:"var(--terminal-text)"},children:["SPEECH INTERVAL: ",(x==null?void 0:x.intervalSec)??18,"s"]}),l.jsx("input",{type:"range",min:5,max:120,step:5,value:(x==null?void 0:x.intervalSec)??18,onChange:L=>g==null?void 0:g({intervalSec:Number(L.target.value)}),style:{width:"100%",accentColor:"var(--accent)"}}),l.jsxs("div",{style:{display:"flex",justifyContent:"space-between",fontSize:9,color:"var(--terminal-text-muted)"},children:[l.jsx("span",{children:"5s (frequent)"}),l.jsx("span",{children:"120s (rare)"})]})]}),(x==null?void 0:x.mode)!=="template"&&l.jsxs("div",{children:[l.jsxs("div",{style:{fontSize:11,fontWeight:600,marginBottom:8,color:"var(--terminal-text)"},children:["DAILY LLM BUDGET: $",(($=x==null?void 0:x.dailyBudgetUsd)==null?void 0:$.toFixed(2))??"1.00"]}),l.jsx("input",{type:"range",min:0,max:5,step:.25,value:(x==null?void 0:x.dailyBudgetUsd)??1,onChange:L=>g==null?void 0:g({dailyBudgetUsd:Number(L.target.value)}),style:{width:"100%",accentColor:"var(--accent)"}}),l.jsxs("div",{style:{display:"flex",justifyContent:"space-between",fontSize:9,color:"var(--terminal-text-muted)"},children:[l.jsx("span",{children:"$0 (unlimited)"}),l.jsx("span",{children:"$5.00/day"})]})]}),l.jsxs("div",{children:[l.jsx("div",{style:{fontSize:11,fontWeight:600,marginBottom:8,color:"var(--terminal-text)"},children:"LANGUAGE"}),l.jsx("div",{style:{display:"flex",gap:6},children:[{key:"auto",label:"Auto"},{key:"en",label:"English"},{key:"ko",label:"한국어"},{key:"ja",label:"日本語"}].map(({key:L,label:Y})=>l.jsx("button",{onClick:()=>b==null?void 0:b(L),style:{flex:1,padding:"8px 12px",fontSize:11,border:`2px solid ${(w??"auto")===L?"var(--accent)":"rgba(255,255,255,0.1)"}`,background:(w??"auto")===L?"rgba(255,255,255,0.08)":"transparent",color:(w??"auto")===L?"var(--terminal-text)":"var(--terminal-text-muted)",borderRadius:6,cursor:"pointer",textAlign:"center",fontWeight:600},children:Y},L))}),l.jsx("div",{style:{fontSize:9,color:"var(--terminal-text-muted)",marginTop:4},children:"Sets language for AI responses and speech bubbles"})]})]})}),k==="character"&&l.jsxs("div",{className:"customize-footer",children:[l.jsx("button",{className:"customize-btn customize-btn--cancel",onClick:o,children:"CANCEL"}),l.jsx("button",{className:"customize-btn customize-btn--save",onClick:X,children:"SAVE"})]})]})})}function py(e){if(e.length===0)return"";const n={};for(const{file:f}of e){const m=f.split("/"),h=m[0]==="."?m[1]??"root":m[0];(n[h]??(n[h]=[])).push(f)}const a={roles:"roles",projects:"projects",operations:"operations",knowledge:"knowledge",architecture:"architecture",company:"company",".tycono":"config",".claude":"skills"},i=[];for(const[f,m]of Object.entries(n)){const h=a[f]??f;if(m.length===1){const x=m[0].split("/").pop()??m[0];i.push(`${h}/${x}`)}else i.push(`${h} (${m.length} files)`)}const o=e.some(f=>f.status==="A"),u=e.some(f=>f.status==="M");return`${o&&!u?"add":"update"}: ${i.join(", ")}`}function xy(e){const n=Date.now()-new Date(e).getTime(),a=Math.floor(n/6e4);if(a<1)return"just now";if(a<60)return`${a}m ago`;const i=Math.floor(a/60);return i<24?`${i}h ago`:`${Math.floor(i/24)}d ago`}function i8({onInitGit:e,onDelegate:n,delegateRoleName:a}){const[i,o]=v.useState(!1),[u,d]=v.useState(null),f=async()=>{o(!0),d(null);try{await e(),d({ok:!0,message:"Git repository initialized!"})}catch(h){const x=h instanceof Error?h.message:"Failed";x.includes("not installed")||x.includes("noGitBinary")?d({ok:!1,message:"git is not installed on this system"}):d({ok:!1,message:x})}finally{o(!1)}},m=u&&!u.ok&&u.message.includes("not installed");return l.jsxs("div",{className:"p-3 space-y-2",style:{background:"rgba(211,47,47,0.05)",border:"1px solid var(--pixel-border)"},children:[l.jsx("div",{className:"text-[10px] font-bold uppercase tracking-wider",style:{color:"var(--terminal-text-muted)"},children:"No Git Repository"}),!u&&l.jsxs(l.Fragment,{children:[l.jsx("div",{className:"text-[10px]",style:{color:"var(--terminal-text-secondary)"},children:"This project has no git repository. Initialize one to start saving."}),l.jsxs("div",{className:"flex gap-2 flex-wrap",children:[l.jsx("button",{onClick:f,disabled:i,className:"text-[10px] font-bold px-3 py-1.5 cursor-pointer disabled:opacity-50",style:{background:"var(--accent)",color:"#fff",border:"none"},children:i?"INITIALIZING...":"GIT INIT"}),n&&l.jsxs("button",{onClick:n,className:"text-[10px] font-bold px-3 py-1.5 cursor-pointer",style:{background:"var(--terminal-bg)",color:"var(--idle-amber)",border:"1px solid var(--idle-amber)"},children:["🤖"," ",(a==null?void 0:a.toUpperCase())??"AI"," FIX"]})]})]}),u&&u.ok&&l.jsx("div",{className:"text-[10px] p-1.5",style:{background:"rgba(59,185,80,0.1)",border:"1px solid var(--active-green)",color:"var(--active-green)"},children:u.message}),m&&l.jsxs("div",{className:"space-y-2",children:[l.jsx("div",{className:"text-[10px]",style:{color:"#EF5350"},children:"git is not installed on this system."}),l.jsxs("div",{className:"text-[10px] space-y-1",style:{color:"var(--terminal-text-muted)"},children:[l.jsxs("div",{children:[l.jsx("b",{children:"macOS:"})," xcode-select --install"]}),l.jsxs("div",{children:[l.jsx("b",{children:"Ubuntu/Debian:"})," sudo apt install git"]}),l.jsxs("div",{children:[l.jsx("b",{children:"Windows:"})," ",l.jsx("a",{href:"https://git-scm.com/downloads",target:"_blank",rel:"noopener noreferrer",style:{color:"var(--accent)",textDecoration:"underline"},children:"git-scm.com/downloads"})]})]}),l.jsxs("div",{className:"flex gap-2 flex-wrap",children:[l.jsx("button",{onClick:()=>{d(null)},className:"text-[10px] font-bold px-3 py-1 cursor-pointer",style:{background:"var(--accent)",color:"#fff",border:"none"},children:"RETRY"}),n&&l.jsxs("button",{onClick:n,className:"text-[10px] font-bold px-3 py-1 cursor-pointer",style:{background:"var(--terminal-bg)",color:"var(--idle-amber)",border:"1px solid var(--idle-amber)"},children:["🤖"," ",(a==null?void 0:a.toUpperCase())??"AI"," FIX"]})]})]}),u&&!u.ok&&!m&&l.jsx("div",{className:"text-[10px] p-1.5",style:{background:"rgba(211,47,47,0.1)",border:"1px solid #D32F2F",color:"#EF5350"},children:u.message})]})}function s8({repo:e,onConnected:n,onDelegate:a,delegateRoleName:i}){const[o,u]=v.useState("idle"),[d,f]=v.useState(null),[m,h]=v.useState(""),[x,g]=v.useState("private"),[w,b]=v.useState(""),[j,k]=v.useState(null),[E,C]=v.useState(!1),N=async()=>{u("checking"),k(null);try{const R=await ye.getGithubStatus(e);f(R),R.hasRemote?n():R.ghInstalled&&R.authenticated?u("ready"):u("idle")}catch{u("idle")}},_=async()=>{if(m.trim()){C(!0),k(null);try{const R=await ye.githubCreateRepo(m.trim(),x,e);k(R),R.ok&&setTimeout(n,1500)}catch(R){k({ok:!1,message:R instanceof Error?R.message:"Failed"})}finally{C(!1)}}},z=async()=>{if(w.trim()){C(!0),k(null);try{const R=await ye.addRemote(w.trim(),e);k(R),R.ok&&setTimeout(n,1500)}catch(R){k({ok:!1,message:R instanceof Error?R.message:"Failed"})}finally{C(!1)}}},H=a?l.jsxs("button",{onClick:a,className:"text-[10px] font-bold px-3 py-1.5 cursor-pointer",style:{background:"var(--terminal-bg)",color:"var(--idle-amber)",border:"1px solid var(--idle-amber)"},title:`Ask ${i??"AI"} to set up GitHub remote`,children:["🤖"," ",(i==null?void 0:i.toUpperCase())??"AI"," FIX"]}):null;return l.jsxs("div",{className:"p-3 space-y-2",style:{background:"rgba(100,100,255,0.05)",border:"1px solid var(--pixel-border)"},children:[l.jsx("div",{className:"text-[10px] font-bold uppercase tracking-wider",style:{color:"var(--terminal-text-muted)"},children:"No Remote — Local Only"}),o==="idle"&&!d&&l.jsxs("div",{className:"flex gap-2 flex-wrap",children:[l.jsx("button",{onClick:N,className:"text-[10px] font-bold px-3 py-1.5 cursor-pointer",style:{background:"var(--accent)",color:"#fff",border:"none"},children:"CONNECT GITHUB"}),l.jsx("button",{onClick:()=>u("manual"),className:"text-[10px] font-bold px-3 py-1.5 cursor-pointer",style:{background:"var(--terminal-bg)",color:"var(--terminal-text)",border:"1px solid var(--terminal-border)"},children:"ADD REMOTE URL"}),H]}),o==="checking"&&l.jsx("div",{className:"text-[10px]",style:{color:"var(--terminal-text-secondary)"},children:"Checking GitHub CLI..."}),o==="idle"&&d&&!d.ghInstalled&&l.jsxs("div",{className:"space-y-2",children:[l.jsx("div",{className:"text-[10px]",style:{color:"var(--idle-amber)"},children:"GitHub CLI (gh) not installed."}),l.jsxs("div",{className:"text-[10px] space-y-0.5",style:{color:"var(--terminal-text-muted)"},children:[l.jsxs("div",{children:["Install:"," ",l.jsx("a",{href:"https://cli.github.com",target:"_blank",rel:"noopener noreferrer",style:{color:"var(--accent)",textDecoration:"underline"},children:"cli.github.com"})]}),l.jsx("div",{style:{fontFamily:"var(--pixel-font)"},children:"brew install gh && gh auth login"})]}),l.jsxs("div",{className:"flex gap-2 flex-wrap",children:[l.jsx("button",{onClick:N,className:"text-[10px] font-bold px-3 py-1 cursor-pointer",style:{background:"var(--accent)",color:"#fff",border:"none"},children:"RETRY"}),l.jsx("button",{onClick:()=>u("manual"),className:"text-[10px] font-bold px-3 py-1 cursor-pointer",style:{background:"var(--terminal-bg)",color:"var(--terminal-text)",border:"1px solid var(--terminal-border)"},children:"ADD URL MANUALLY"}),H]})]}),o==="idle"&&d&&d.ghInstalled&&!d.authenticated&&l.jsxs("div",{className:"space-y-2",children:[l.jsx("div",{className:"text-[10px]",style:{color:"var(--idle-amber)"},children:"GitHub CLI installed but not logged in."}),l.jsx("div",{className:"text-[10px]",style:{color:"var(--terminal-text-muted)",fontFamily:"var(--pixel-font)"},children:"Run in terminal: gh auth login"}),l.jsxs("div",{className:"flex gap-2 flex-wrap",children:[l.jsx("button",{onClick:N,className:"text-[10px] font-bold px-3 py-1 cursor-pointer",style:{background:"var(--accent)",color:"#fff",border:"none"},children:"RETRY"}),l.jsx("button",{onClick:()=>u("manual"),className:"text-[10px] font-bold px-3 py-1 cursor-pointer",style:{background:"var(--terminal-bg)",color:"var(--terminal-text)",border:"1px solid var(--terminal-border)"},children:"ADD REMOTE URL"}),H]})]}),o==="ready"&&d&&l.jsxs("div",{className:"space-y-2",children:[l.jsxs("div",{className:"text-[10px]",style:{color:"var(--active-green)"},children:["Logged in as ",d.username||"GitHub user"]}),l.jsxs("div",{className:"flex gap-2 items-center",children:[l.jsx("input",{type:"text",value:m,onChange:R=>h(R.target.value),placeholder:"repository-name",className:"flex-1 px-2 py-1.5 text-[11px] outline-none",style:{background:"var(--terminal-bg)",border:"1px solid var(--terminal-border)",color:"var(--terminal-text)",fontFamily:"var(--pixel-font)"}}),l.jsxs("select",{value:x,onChange:R=>g(R.target.value),className:"px-2 py-1.5 text-[10px] outline-none cursor-pointer",style:{background:"var(--terminal-bg)",border:"1px solid var(--terminal-border)",color:"var(--terminal-text)",fontFamily:"var(--pixel-font)"},children:[l.jsx("option",{value:"private",children:"Private"}),l.jsx("option",{value:"public",children:"Public"})]})]}),l.jsxs("div",{className:"flex gap-2",children:[l.jsx("button",{onClick:_,disabled:E||!m.trim(),className:"text-[10px] font-bold px-3 py-1.5 cursor-pointer disabled:opacity-50",style:{background:"var(--accent)",color:"#fff",border:"none"},children:E?"CREATING...":"CREATE & PUSH"}),l.jsx("button",{onClick:()=>u("manual"),className:"text-[10px] px-2 py-1 cursor-pointer",style:{background:"transparent",color:"var(--terminal-text-muted)",border:"1px solid var(--terminal-border)"},children:"USE URL INSTEAD"})]})]}),o==="manual"&&l.jsxs("div",{className:"space-y-2",children:[l.jsxs("div",{className:"text-[10px]",style:{color:"var(--terminal-text-muted)"},children:[l.jsx("a",{href:"https://github.com/new",target:"_blank",rel:"noopener noreferrer",style:{color:"var(--accent)",textDecoration:"underline"},children:"Create a new repo on GitHub"})," ","then paste the URL below:"]}),l.jsx("input",{type:"text",value:w,onChange:R=>b(R.target.value),placeholder:"https://github.com/username/repo-name.git",className:"w-full px-2 py-1.5 text-[11px] outline-none",style:{background:"var(--terminal-bg)",border:"1px solid var(--terminal-border)",color:"var(--terminal-text)",fontFamily:"var(--pixel-font)"}}),l.jsxs("div",{className:"flex gap-2",children:[l.jsx("button",{onClick:z,disabled:E||!w.trim(),className:"text-[10px] font-bold px-3 py-1.5 cursor-pointer disabled:opacity-50",style:{background:"var(--accent)",color:"#fff",border:"none"},children:E?"ADDING...":"ADD REMOTE & PUSH"}),l.jsx("button",{onClick:()=>{u("idle"),f(null)},className:"text-[10px] px-2 py-1 cursor-pointer",style:{background:"transparent",color:"var(--terminal-text-muted)",border:"1px solid var(--terminal-border)"},children:"BACK"})]})]}),j&&l.jsx("div",{className:"text-[10px] p-1.5",style:{background:j.ok?"rgba(59,185,80,0.1)":"rgba(211,47,47,0.1)",border:`1px solid ${j.ok?"var(--active-green)":"#D32F2F"}`,color:j.ok?"var(--active-green)":"#EF5350"},children:j.message})]})}function o8({status:e,history:n,onClose:a,onSave:i,onLoadHistory:o,onRestore:u,saving:d,onDelegate:f,delegateRoleName:m,repo:h,onRepoChange:x,syncInfo:g,onPull:w,pulling:b,onRefresh:j,onInitGit:k}){const[E,C]=v.useState("save"),[N,_]=v.useState(""),[z,H]=v.useState(null),[R,I]=v.useState(!1),[q,X]=v.useState(null),[A,$]=v.useState(null),L=v.useRef(null);v.useEffect(()=>{E==="history"&&o()},[E,o]),v.useEffect(()=>{var D;(D=L.current)==null||D.focus()},[]);const Y=[...((e==null?void 0:e.modified)??[]).map(D=>({status:"M",file:D})),...((e==null?void 0:e.untracked)??[]).map(D=>({status:"A",file:D}))],se=v.useRef(!1);v.useEffect(()=>{!se.current&&Y.length>0&&!N&&(_(py(Y)),se.current=!0)},[Y.length]),v.useEffect(()=>{se.current=!1,_(""),$(null),X(null),H(null)},[h]);const ee=v.useCallback(()=>{_(py(Y))},[Y]),W=async()=>{H(null),X(null);try{const D=await i(N||void 0);X(D),_("")}catch(D){H(D instanceof Error?D.message:"Save failed")}},oe=async()=>{$(null),H(null);try{const D=await w();$(D)}catch(D){H(D instanceof Error?D.message:"Pull failed")}},de=async D=>{if(confirm(`Restore from commit ${D.slice(0,7)}? This creates a new commit with those files.`)){I(!0);try{await u(D),I(!1)}catch(B){H(B instanceof Error?B.message:"Restore failed"),I(!1)}}};v.useEffect(()=>{const D=B=>{B.key==="Escape"&&a()};return window.addEventListener("keydown",D),()=>window.removeEventListener("keydown",D)},[a]);const V=D=>{D.key==="Enter"&&(D.metaKey||D.ctrlKey)&&W()};return l.jsxs(l.Fragment,{children:[l.jsx("div",{className:"fixed inset-0 bg-black/40 z-[60] backdrop-blur-sm",onClick:a}),l.jsxs("div",{className:"fixed top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-[520px] max-h-[80vh] z-[61] overflow-hidden flex flex-col",style:{background:"var(--hud-bg)",border:"3px solid var(--pixel-border)",fontFamily:"var(--pixel-font)",color:"var(--terminal-text)"},onKeyDown:V,children:[l.jsxs("div",{className:"px-5 py-3 flex items-center justify-between shrink-0",style:{borderBottom:"2px solid var(--pixel-border)"},children:[l.jsxs("div",{className:"flex items-center gap-3",children:[l.jsx("span",{className:"text-lg font-black tracking-tight",children:"SAVE GAME"}),l.jsx("span",{className:"text-[10px]",style:{color:"var(--terminal-text-secondary)"},children:(e==null?void 0:e.branch)??""})]}),l.jsxs("div",{className:"flex items-center gap-2",children:[g&&g.hasRemote&&(g.behind>0||g.ahead>0)&&l.jsxs("span",{className:"text-[10px] font-bold",style:{color:g.behind>0?"var(--idle-amber)":"var(--active-green)"},children:[g.behind>0&&`↓${g.behind}`,g.behind>0&&g.ahead>0&&" ",g.ahead>0&&`↑${g.ahead}`]}),l.jsx("button",{onClick:a,className:"text-[var(--terminal-text-secondary)] hover:text-[var(--terminal-text)] cursor-pointer text-lg",children:"×"})]})]}),l.jsx("div",{className:"flex shrink-0",style:{borderBottom:"2px solid var(--pixel-border)"},children:["akb","code"].map(D=>l.jsx("button",{onClick:()=>x(D),className:"flex-1 py-1.5 text-[10px] font-bold uppercase tracking-wider cursor-pointer",style:{background:h===D?"var(--hud-bg-alt)":"transparent",color:h===D?"var(--terminal-text)":"var(--terminal-text-muted)",borderBottom:h===D?"2px solid var(--accent)":"2px solid transparent"},children:D==="akb"?"AKB":"CODE"},D))}),l.jsx("div",{className:"flex shrink-0",style:{borderBottom:"2px solid var(--pixel-border)"},children:["save","history"].map(D=>l.jsx("button",{onClick:()=>C(D),className:"flex-1 py-2 text-[11px] font-bold uppercase tracking-wider cursor-pointer",style:{background:E===D?"var(--hud-bg-alt)":"transparent",color:E===D?"var(--terminal-text)":"var(--terminal-text-muted)",borderBottom:E===D?"2px solid var(--accent)":"2px solid transparent"},children:D==="save"?"SAVE":"HISTORY"},D))}),l.jsxs("div",{className:"flex-1 overflow-y-auto p-5 space-y-4",children:[E==="save"&&l.jsxs(l.Fragment,{children:[(e==null?void 0:e.noGit)&&l.jsx(i8,{onInitGit:async()=>{await(k==null?void 0:k()),j==null||j()},onDelegate:f?()=>{f(`Git is not initialized or not installed for this project. Please check if git is installed (run "git --version"). If git is available, initialize the repository with "git init" and make an initial commit. If git is not installed, provide clear instructions for the user's OS to install it.`)}:void 0,delegateRoleName:m}),g&&g.hasRemote&&g.behind>0&&l.jsxs("div",{className:"flex items-center justify-between p-2",style:{background:"rgba(255,180,0,0.08)",border:"1px solid var(--idle-amber)"},children:[l.jsxs("span",{className:"text-[11px]",style:{color:"var(--idle-amber)"},children:[g.behind," commit",g.behind>1?"s":""," behind remote"]}),l.jsx("button",{onClick:oe,disabled:b,className:"text-[10px] font-bold px-3 py-1 cursor-pointer",style:{background:"var(--idle-amber)",color:"#000",border:"none",opacity:b?.5:1},children:b?"PULLING...":"↓ PULL"})]}),A&&l.jsx("div",{className:"text-[11px] p-2",style:{background:A.status==="ok"||A.status==="up-to-date"?"rgba(59,185,80,0.1)":"rgba(211,47,47,0.1)",border:`1px solid ${A.status==="ok"||A.status==="up-to-date"?"var(--active-green)":"#D32F2F"}`,color:A.status==="ok"||A.status==="up-to-date"?"var(--active-green)":"#EF5350"},children:A.message}),l.jsx("div",{className:"text-[11px]",style:{color:"var(--terminal-text-secondary)"},children:Y.length>0?l.jsxs("span",{style:{color:"var(--idle-amber)"},children:["* ",Y.length," unsaved change",Y.length>1?"s":""]}):l.jsx("span",{style:{color:"var(--active-green)"},children:"All changes saved"})}),Y.length>0&&l.jsxs("div",{children:[l.jsx("div",{className:"text-[10px] font-bold uppercase tracking-wider mb-2",style:{color:"var(--terminal-text-muted)"},children:"Changed Files"}),l.jsx("div",{className:"text-[11px] max-h-[160px] overflow-y-auto p-2 space-y-0.5",style:{background:"var(--terminal-bg)",border:"1px solid var(--terminal-border)"},children:Y.map(({status:D,file:B})=>l.jsxs("div",{className:"flex gap-2",children:[l.jsx("span",{style:{color:D==="A"?"var(--active-green)":"var(--idle-amber)",width:"14px"},children:D}),l.jsx("span",{style:{color:"var(--terminal-text-secondary)"},children:B})]},B))})]}),Y.length>0&&l.jsxs("div",{children:[l.jsxs("div",{className:"flex items-center justify-between mb-2",children:[l.jsx("div",{className:"text-[10px] font-bold uppercase tracking-wider",style:{color:"var(--terminal-text-muted)"},children:"Save Message"}),l.jsxs("button",{onClick:ee,className:"text-[9px] px-1.5 py-0.5 cursor-pointer",style:{background:"var(--terminal-bg)",border:"1px solid var(--terminal-border)",color:"var(--accent)",fontFamily:"var(--pixel-font)"},title:"Auto-generate message from changes",children:["✨"," AUTO"]})]}),l.jsx("input",{ref:L,type:"text",value:N,onChange:D=>_(D.target.value),placeholder:"Auto-generated — edit if needed",className:"w-full px-3 py-2 text-[12px] outline-none",style:{background:"var(--terminal-bg)",border:"1px solid var(--terminal-border)",color:"var(--terminal-text)",fontFamily:"var(--pixel-font)"}})]}),Y.length>0&&l.jsxs("div",{className:"flex gap-2",children:[l.jsx("button",{onClick:W,disabled:d,className:"flex-1 py-2.5 text-[12px] font-black uppercase tracking-wider cursor-pointer disabled:opacity-50",style:{background:"var(--accent)",color:"#fff",border:"2px solid var(--accent)"},children:d?"SAVING...":e!=null&&e.hasRemote?"SAVE & PUSH":"SAVE"}),f&&l.jsxs("button",{onClick:()=>{const D=Y.map(B=>`${B.status} ${B.file}`).join(`
|
|
92
|
-
`);f(D)},disabled:d,className:"py-2.5 px-4 text-[11px] font-bold uppercase tracking-wider cursor-pointer disabled:opacity-50",style:{background:"var(--terminal-bg)",color:"var(--terminal-text)",border:"2px solid var(--pixel-border)"},title:`Delegate to ${m??"AI role"} — they'll review, commit, push & merge`,children:["🤖"," ",(m==null?void 0:m.toUpperCase())??"DELEGATE"]})]}),e&&!e.hasRemote&&!e.noGit&&l.jsx(s8,{repo:h,onConnected:()=>j==null?void 0:j(),onDelegate:f?()=>{f(`Set up a GitHub remote for the ${h==="akb"?"AKB":"Code"} repository and push all commits. If gh CLI is available, use "gh repo create". Otherwise, guide through manual setup. Current repo path can be found in config.`)}:void 0,delegateRoleName:m}),q&&l.jsxs("div",{className:"text-[11px] p-2",style:{background:"rgba(59,185,80,0.1)",border:"1px solid var(--active-green)",color:"var(--active-green)"},children:["Saved! ",q.filesChanged," file",q.filesChanged>1?"s":""," committed",q.pushed?" & pushed":"",q.pushError?` (push error: ${q.pushError})`:""]}),z&&l.jsx("div",{className:"text-[11px] p-2",style:{background:"rgba(211,47,47,0.1)",border:"1px solid #D32F2F",color:"#EF5350"},children:z}),(e==null?void 0:e.lastCommit)&&l.jsxs("div",{className:"text-[10px]",style:{color:"var(--terminal-text-muted)"},children:["Last save: ",e.lastCommit.message," (",xy(e.lastCommit.date),")"]})]}),E==="history"&&l.jsxs(l.Fragment,{children:[n.length===0&&l.jsx("div",{className:"text-[11px] text-center py-8",style:{color:"var(--terminal-text-muted)"},children:"No save history"}),l.jsx("div",{className:"space-y-1",children:n.map(D=>l.jsxs("div",{className:"flex items-center justify-between py-2 px-3 group",style:{background:"var(--hud-bg-alt)",border:"1px solid var(--terminal-border)"},children:[l.jsxs("div",{className:"flex-1 min-w-0",children:[l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx("span",{className:"text-[11px] font-mono",style:{color:"var(--accent)"},children:D.shortSha}),l.jsx("span",{className:"text-[11px] truncate",style:{color:"var(--terminal-text)"},children:D.message})]}),l.jsx("div",{className:"text-[10px]",style:{color:"var(--terminal-text-muted)"},children:xy(D.date)})]}),l.jsx("button",{onClick:()=>de(D.sha),disabled:R,className:"text-[10px] font-bold px-2 py-1 opacity-0 group-hover:opacity-100 transition-opacity cursor-pointer",style:{background:"var(--terminal-bg)",border:"1px solid var(--terminal-border)",color:"var(--idle-amber)"},children:"LOAD"})]},D.sha))})]})]})]})]})}function c8({onClose:e}){const[n,a]=v.useState(null),[i,o]=v.useState(!0),[u,d]=v.useState(null),[,f]=v.useState(!1);return v.useEffect(()=>{Promise.all([ye.getCompanyStats(),ye.getPreferences()]).then(async([m,h])=>{a(m);const x=h;if(x.instanceId)try{await wr.syncStats({instanceId:x.instanceId,roleCount:m.company.roleCount,totalTokens:m.company.totalTokens,rolesData:m.roles.map(g=>({roleId:g.roleId,name:g.name,tokens:g.totalTokens}))}),f(!0)}catch{}}).catch(m=>d(m.message)).finally(()=>o(!1))},[]),i?l.jsx("div",{style:{padding:24,color:"rgba(255,255,255,0.6)"},children:"Loading stats..."}):u||!n?l.jsxs("div",{style:{padding:24,color:"#ff6b6b"},children:[u||"Failed to load stats",l.jsx("button",{onClick:e,style:{marginLeft:12,color:"rgba(255,255,255,0.6)",background:"none",border:"none",cursor:"pointer"},children:"Close"})]}):l.jsxs("div",{style:{padding:20,color:"rgba(255,255,255,0.9)",maxHeight:"100%",overflowY:"auto"},children:[l.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:20},children:[l.jsx("h3",{style:{margin:0,fontSize:16,fontWeight:600},children:"Company Stats"}),l.jsx("button",{onClick:e,style:{background:"none",border:"none",color:"rgba(255,255,255,0.5)",cursor:"pointer",fontSize:18},children:"×"})]}),l.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:10,marginBottom:20},children:[l.jsx(Su,{label:"Roles",value:String(n.company.roleCount)}),l.jsx(Su,{label:"Avg Level",value:`Lv.${n.company.avgLevel}`}),l.jsx(Su,{label:"Total Tokens",value:n.company.formattedTokens}),l.jsx(Su,{label:"Total Cost",value:`$${n.company.totalCostUsd.toFixed(2)}`})]}),l.jsx("h4",{style:{margin:"0 0 12px",fontSize:13,fontWeight:600,color:"rgba(255,255,255,0.6)",textTransform:"uppercase",letterSpacing:1},children:"Role Leaderboard"}),l.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[n.roles.map((m,h)=>l.jsx(u8,{role:m,rank:h+1},m.roleId)),n.roles.length===0&&l.jsx("div",{style:{color:"rgba(255,255,255,0.4)",fontSize:13,padding:"8px 0"},children:"No role activity yet. Assign tasks to start leveling up!"})]}),Object.keys(n.byModel).length>0&&l.jsxs(l.Fragment,{children:[l.jsx("h4",{style:{margin:"20px 0 12px",fontSize:13,fontWeight:600,color:"rgba(255,255,255,0.6)",textTransform:"uppercase",letterSpacing:1},children:"Model Usage"}),l.jsx("div",{style:{display:"flex",flexDirection:"column",gap:4},children:Object.entries(n.byModel).map(([m,h])=>l.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 10px",background:"rgba(255,255,255,0.03)",borderRadius:6,fontSize:12},children:[l.jsx("span",{style:{color:"rgba(255,255,255,0.7)"},children:d8(m)}),l.jsxs("span",{style:{color:"rgba(255,255,255,0.5)"},children:["$",h.costUsd.toFixed(2)]})]},m))})]})]})}function Su({label:e,value:n}){return l.jsxs("div",{style:{padding:"12px 14px",background:"rgba(255,255,255,0.04)",borderRadius:8,border:"1px solid rgba(255,255,255,0.06)"},children:[l.jsx("div",{style:{fontSize:11,color:"rgba(255,255,255,0.45)",marginBottom:4},children:e}),l.jsx("div",{style:{fontSize:18,fontWeight:600},children:n})]})}function u8({role:e,rank:n}){const a=["🥇","🥈","🥉"],i=n<=3?a[n-1]:`#${n}`;return l.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,padding:"8px 10px",background:"rgba(255,255,255,0.03)",borderRadius:8},children:[l.jsx("span",{style:{fontSize:14,width:28,textAlign:"center",flexShrink:0},children:i}),l.jsxs("div",{style:{flex:1,minWidth:0},children:[l.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"baseline",marginBottom:4},children:[l.jsx("span",{style:{fontSize:13,fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.name}),l.jsxs("span",{style:{fontSize:12,color:gy(e.level),fontWeight:600,flexShrink:0,marginLeft:8},children:["Lv.",e.level]})]}),l.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[l.jsx("div",{style:{flex:1,height:4,background:"rgba(255,255,255,0.08)",borderRadius:2,overflow:"hidden"},children:l.jsx("div",{style:{width:`${e.progress*100}%`,height:"100%",background:gy(e.level),borderRadius:2,transition:"width 0.3s ease"}})}),l.jsx("span",{style:{fontSize:10,color:"rgba(255,255,255,0.4)",flexShrink:0},children:e.formattedTokens})]})]})]})}function gy(e){return e>=20?"#FFD700":e>=10?"#C0A0FF":e>=5?"#4FC3F7":e>=3?"#81C784":"rgba(255,255,255,0.4)"}function d8(e){return e.includes("opus")?"Opus":e.includes("sonnet")?"Sonnet":e.includes("haiku")?"Haiku":e.split("-").slice(0,2).join(" ")}function f8({onClose:e,onSyncComplete:n}){const[a,i]=v.useState([]),[o,u]=v.useState([]),[d,f]=v.useState(!0),[m,h]=v.useState(null),[x,g]=v.useState(new Set),[w,b]=v.useState(null),[j,k]=v.useState(null),E=v.useCallback(async()=>{f(!0),b(null);try{const{roles:N}=await ye.getSyncRoles();i(N);const _=N.filter(z=>z.source.sync!=="off");if(_.length===0){u([]),k(null);return}try{const z=await wr.syncCheck(_.map(R=>({roleId:R.roleId,sourceId:R.source.id,currentVersion:R.source.upstream_version??R.source.forked_at??"0.0.0"})));k(!0);const H=[];for(const R of z.updates){if(!R.hasUpdate)continue;const I=_.find(L=>L.roleId===R.roleId);if(!I)continue;const{character:q}=await wr.syncPull(R.sourceId),X=[];I.persona.trim()!==q.persona.trim()&&X.push({field:"persona",local:I.persona.slice(0,120)+(I.persona.length>120?"...":""),upstream:q.persona.slice(0,120)+(q.persona.length>120?"...":"")});const A=JSON.stringify(I.authority),$=JSON.stringify(q.authority);A!==$&&X.push({field:"authority",local:`${I.authority.autonomous.length} autonomous, ${I.authority.needsApproval.length} approval`,upstream:`${q.authority.autonomous.length} autonomous, ${q.authority.needsApproval.length} approval`}),X.length>0&&H.push({roleId:R.roleId,roleName:I.name,sourceId:R.sourceId,currentVersion:R.currentVersion,latestVersion:R.latestVersion,fields:X})}u(H)}catch{k(!1),u([])}}catch(N){b(N instanceof Error?N.message:"Failed to check for updates")}finally{f(!1)}},[]);v.useEffect(()=>{E()},[E]);const C=async N=>{h(N.roleId);try{const{character:_,version:z}=await wr.syncPull(N.sourceId);await ye.applySyncUpdate({roleId:N.roleId,changes:{persona:_.persona,authority:_.authority},upstreamVersion:z}),g(H=>new Set(H).add(N.roleId)),n==null||n()}catch(_){b(_ instanceof Error?_.message:"Failed to apply update")}finally{h(null)}};return l.jsxs("div",{style:{padding:20,color:"rgba(255,255,255,0.9)",maxHeight:"100%",overflowY:"auto"},children:[l.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:16},children:[l.jsx("h3",{style:{margin:0,fontSize:16,fontWeight:600},children:"Role Sync"}),l.jsxs("div",{style:{display:"flex",gap:8},children:[l.jsx("button",{onClick:E,disabled:d,style:{background:"rgba(255,255,255,0.08)",border:"1px solid rgba(255,255,255,0.1)",color:"rgba(255,255,255,0.7)",borderRadius:6,padding:"4px 10px",fontSize:12,cursor:d?"wait":"pointer"},children:d?"Checking...":"Refresh"}),l.jsx("button",{onClick:e,style:{background:"none",border:"none",color:"rgba(255,255,255,0.5)",cursor:"pointer",fontSize:18},children:"×"})]})]}),j===!1&&l.jsx("div",{style:{padding:"8px 12px",background:"rgba(255,180,0,0.1)",borderRadius:6,color:"#FFB74D",fontSize:12,marginBottom:12},children:"Cloud API unreachable. Sync requires connection to api.tycono.ai."}),w&&l.jsx("div",{style:{padding:"8px 12px",background:"rgba(255,100,100,0.1)",borderRadius:6,color:"#ff6b6b",fontSize:12,marginBottom:12},children:w}),l.jsxs("div",{style:{padding:"10px 14px",background:"rgba(255,255,255,0.04)",borderRadius:8,border:"1px solid rgba(255,255,255,0.06)",marginBottom:16,fontSize:13},children:[l.jsx("span",{style:{color:"rgba(255,255,255,0.5)"},children:"Tracked roles: "}),l.jsx("span",{style:{fontWeight:500},children:a.length}),l.jsx("span",{style:{color:"rgba(255,255,255,0.3)",margin:"0 8px"},children:"·"}),l.jsx("span",{style:{color:"rgba(255,255,255,0.5)"},children:"Updates available: "}),l.jsx("span",{style:{fontWeight:500,color:o.length>0?"#4FC3F7":"rgba(255,255,255,0.7)"},children:o.filter(N=>!x.has(N.roleId)).length}),j===!0&&l.jsxs(l.Fragment,{children:[l.jsx("span",{style:{color:"rgba(255,255,255,0.3)",margin:"0 8px"},children:"·"}),l.jsx("span",{style:{fontSize:11,color:"#81C784"},children:"Cloud connected"})]})]}),o.length===0&&!d&&l.jsx("div",{style:{color:"rgba(255,255,255,0.4)",fontSize:13,padding:"20px 0",textAlign:"center"},children:a.length===0?"No roles with source tracking. Hire from the Store to enable sync.":"All roles are up to date!"}),o.map(N=>l.jsxs("div",{style:{marginBottom:12,padding:14,background:"rgba(255,255,255,0.03)",borderRadius:8,border:"1px solid rgba(255,255,255,0.06)"},children:[l.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:10},children:[l.jsxs("div",{children:[l.jsx("div",{style:{fontSize:14,fontWeight:500},children:N.roleName}),l.jsxs("div",{style:{fontSize:11,color:"rgba(255,255,255,0.4)"},children:[N.sourceId," · v",N.currentVersion," → v",N.latestVersion]})]}),x.has(N.roleId)?l.jsx("span",{style:{fontSize:12,color:"#81C784"},children:"Applied ✓"}):l.jsx("button",{onClick:()=>C(N),disabled:m===N.roleId,style:{background:"#1565C0",border:"none",color:"white",borderRadius:6,padding:"5px 12px",fontSize:12,cursor:m===N.roleId?"wait":"pointer",opacity:m===N.roleId?.6:1},children:m===N.roleId?"Applying...":"Apply Update"})]}),N.fields.map(_=>l.jsxs("div",{style:{marginBottom:6,fontSize:12},children:[l.jsx("div",{style:{color:"rgba(255,255,255,0.5)",marginBottom:2,textTransform:"uppercase",fontSize:10,letterSpacing:.5},children:_.field}),l.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:6},children:[l.jsxs("div",{style:{padding:"4px 8px",background:"rgba(255,100,100,0.08)",borderRadius:4,color:"rgba(255,255,255,0.6)"},children:[l.jsx("span",{style:{fontSize:9,color:"rgba(255,255,255,0.3)"},children:"LOCAL"}),l.jsx("br",{}),_.local]}),l.jsxs("div",{style:{padding:"4px 8px",background:"rgba(100,255,100,0.08)",borderRadius:4,color:"rgba(255,255,255,0.6)"},children:[l.jsx("span",{style:{fontSize:9,color:"rgba(255,255,255,0.3)"},children:"UPSTREAM"}),l.jsx("br",{}),_.upstream]})]})]},_.field))]},N.roleId)),a.length>0&&l.jsxs("div",{style:{marginTop:16,fontSize:11,color:"rgba(255,255,255,0.3)",lineHeight:1.5},children:["Roles hired from the Store are tracked automatically. Set ",l.jsx("code",{style:{background:"rgba(255,255,255,0.06)",padding:"1px 4px",borderRadius:3},children:"sync: off"})," in role.yaml to stop tracking."]})]})}function h8({onClose:e}){const[n,a]=v.useState(null),[i,o]=v.useState(!0),[u,d]=v.useState(null),[f,m]=v.useState(null),h=v.useCallback(async()=>{o(!0),d(null);try{const N=await ye.getGitStatus();a(N)}catch(N){d(N instanceof Error?N.message:"Failed to load git status")}finally{o(!1)}},[]);v.useEffect(()=>{h()},[h]);const x=async N=>{m(N.path);try{await ye.deleteWorktree(N.path),await h()}catch(_){d(_ instanceof Error?_.message:"Failed to remove worktree")}finally{m(null)}},g=async N=>{m(N);try{await ye.deleteBranch(N),await h()}catch(_){d(_ instanceof Error?_.message:"Failed to delete branch")}finally{m(null)}};if(i&&!n)return l.jsx("div",{style:{padding:24,color:"rgba(255,255,255,0.6)"},children:"Loading git status..."});if(u&&!n)return l.jsxs("div",{style:{padding:24,color:"#ff6b6b"},children:[u,l.jsx("button",{onClick:e,style:{marginLeft:12,color:"rgba(255,255,255,0.6)",background:"none",border:"none",cursor:"pointer"},children:"Close"})]});if(!n)return null;const w=n.worktrees.filter(N=>N.status==="active"),b=n.worktrees.filter(N=>N.status==="pending-merge"),j=n.worktrees.filter(N=>N.status==="stale");function k(N){const _=N.split("/");if(_.length>1){const z=_[_.length-1],H=["cto","cbo","pm","engineer","designer","qa","data-analyst"];for(const R of H)if(z.toLowerCase().includes(R))return R}return null}function E(N,_=40){return N.length<=_?N:"..."+N.slice(N.length-_+3)}function C(N){const _=Date.now()-new Date(N).getTime(),z=Math.floor(_/6e4);if(z<1)return"just now";if(z<60)return`${z}m ago`;const H=Math.floor(z/60);return H<24?`${H}h ago`:`${Math.floor(H/24)}d ago`}return l.jsxs("div",{style:{padding:20,color:"rgba(255,255,255,0.9)",maxHeight:"100%",overflowY:"auto"},children:[l.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:16},children:[l.jsx("h3",{style:{margin:0,fontSize:16,fontWeight:600},children:"GIT STATUS"}),l.jsxs("div",{style:{display:"flex",gap:8},children:[l.jsx("button",{onClick:h,disabled:i,style:{background:"rgba(255,255,255,0.08)",border:"1px solid rgba(255,255,255,0.1)",color:"rgba(255,255,255,0.7)",borderRadius:6,padding:"4px 10px",fontSize:12,cursor:i?"wait":"pointer"},children:i?"Checking...":"Refresh"}),l.jsx("button",{onClick:e,style:{background:"none",border:"none",color:"rgba(255,255,255,0.5)",cursor:"pointer",fontSize:18},children:"×"})]})]}),u&&l.jsx("div",{style:{padding:"8px 12px",background:"rgba(255,100,100,0.1)",borderRadius:6,color:"#ff6b6b",fontSize:12,marginBottom:12},children:u}),l.jsxs("div",{style:{padding:"10px 14px",background:"rgba(255,255,255,0.04)",borderRadius:8,border:"1px solid rgba(255,255,255,0.06)",marginBottom:16,fontSize:13},children:[l.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[l.jsxs("div",{children:[l.jsx("span",{style:{color:"rgba(255,255,255,0.5)"},children:"Branch: "}),l.jsx("span",{style:{fontWeight:500},children:n.currentBranch})]}),l.jsx("div",{children:n.unsavedCount>0&&l.jsxs("span",{style:{color:"#FFB74D",fontSize:12},children:[n.unsavedCount," unsaved"]})})]}),n.lastCommit&&l.jsxs("div",{style:{marginTop:6,fontSize:11,color:"rgba(255,255,255,0.4)"},children:["Last commit: ",n.lastCommit.message.slice(0,60),n.lastCommit.message.length>60?"...":""," · ",C(n.lastCommit.date)]})]}),w.length>0&&l.jsxs(l.Fragment,{children:[l.jsx(Cu,{label:"Active Worktrees",count:w.length}),w.map(N=>l.jsx(Hh,{wt:N,roleFromBranch:N.roleId||k(N.branch),truncatePath:E,timeAgo:C,removing:f===N.path,onRemove:()=>x(N),statusColor:"#4FC3F7",statusIcon:"📂"},N.path))]}),b.length>0&&l.jsxs(l.Fragment,{children:[l.jsx(Cu,{label:"Pending Merge",count:b.length}),b.map(N=>l.jsx(Hh,{wt:N,roleFromBranch:N.roleId||k(N.branch),truncatePath:E,timeAgo:C,removing:f===N.path,onRemove:()=>x(N),statusColor:"#FFB74D",statusIcon:"⚠️"},N.path))]}),j.length>0&&l.jsxs(l.Fragment,{children:[l.jsx(Cu,{label:"Stale",count:j.length}),j.map(N=>l.jsx(Hh,{wt:N,roleFromBranch:N.roleId||k(N.branch),truncatePath:E,timeAgo:C,removing:f===N.path,onRemove:()=>x(N),statusColor:"#ff6b6b",statusIcon:"🔴"},N.path))]}),n.staleBranches.length>0&&l.jsxs(l.Fragment,{children:[l.jsx(Cu,{label:"Unmerged Branches",count:n.staleBranches.length}),n.staleBranches.map(N=>l.jsxs("div",{style:{marginBottom:8,padding:"10px 14px",background:"rgba(255,255,255,0.03)",borderRadius:8,border:"1px solid rgba(255,255,255,0.06)",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[l.jsxs("div",{style:{fontSize:13},children:[l.jsx("span",{style:{color:"rgba(255,255,255,0.5)",marginRight:6},children:"⚠️"}),l.jsx("span",{style:{fontWeight:500},children:N})]}),l.jsx("button",{onClick:()=>g(N),disabled:f===N,style:{background:"rgba(255,100,100,0.15)",border:"1px solid rgba(255,100,100,0.2)",color:"#ff6b6b",borderRadius:4,padding:"3px 8px",fontSize:10,cursor:f===N?"wait":"pointer",opacity:f===N?.6:1,fontWeight:600,textTransform:"uppercase",letterSpacing:.5},children:f===N?"...":"DELETE"})]},N))]}),w.length===0&&b.length===0&&j.length===0&&n.staleBranches.length===0&&l.jsxs("div",{style:{color:"rgba(255,255,255,0.4)",fontSize:13,padding:"20px 0",textAlign:"center"},children:["✓"," All clean. No active worktrees or stale branches."]}),n.lastMerge&&l.jsxs("div",{style:{marginTop:16,fontSize:11,color:"rgba(255,255,255,0.3)",lineHeight:1.5},children:["Last merge: ",l.jsx("span",{style:{color:"rgba(255,255,255,0.5)"},children:n.lastMerge.branch})," · ",n.lastMerge.roleId," · ",C(n.lastMerge.mergedAt)]})]})}function Cu({label:e,count:n}){return l.jsxs("h4",{style:{margin:"16px 0 8px",fontSize:11,fontWeight:600,color:"rgba(255,255,255,0.5)",textTransform:"uppercase",letterSpacing:1},children:[e," (",n,")"]})}function Hh({wt:e,roleFromBranch:n,truncatePath:a,timeAgo:i,removing:o,onRemove:u,statusColor:d,statusIcon:f}){return l.jsx("div",{style:{marginBottom:8,padding:"10px 14px",background:"rgba(255,255,255,0.03)",borderRadius:8,border:"1px solid rgba(255,255,255,0.06)"},children:l.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"flex-start"},children:[l.jsxs("div",{style:{flex:1,minWidth:0},children:[l.jsxs("div",{style:{fontSize:13,fontWeight:500,marginBottom:2},children:[l.jsx("span",{style:{marginRight:6},children:f}),e.branch,n&&l.jsx("span",{style:{marginLeft:8,fontSize:10,padding:"1px 6px",background:"rgba(255,255,255,0.08)",borderRadius:3,color:"rgba(255,255,255,0.6)",textTransform:"uppercase"},children:n})]}),e.task&&l.jsxs("div",{style:{fontSize:11,color:"rgba(255,255,255,0.5)",marginBottom:2},children:['"',e.task.slice(0,50),e.task.length>50?"...":"",'"']}),l.jsxs("div",{style:{fontSize:10,color:"rgba(255,255,255,0.35)"},children:[a(e.path)," · ",e.filesChanged," file",e.filesChanged!==1?"s":""," changed"," · ",i(e.createdAt)]}),e.conflictFiles&&e.conflictFiles.length>0&&l.jsxs("div",{style:{fontSize:10,color:"#ff6b6b",marginTop:4},children:["⛔"," CONFLICT: ",e.conflictFiles.join(", ")]})]}),l.jsx("button",{onClick:u,disabled:o,style:{background:"rgba(255,100,100,0.15)",border:"1px solid rgba(255,100,100,0.2)",color:d,borderRadius:4,padding:"3px 8px",fontSize:10,cursor:o?"wait":"pointer",opacity:o?.6:1,fontWeight:600,textTransform:"uppercase",letterSpacing:.5,flexShrink:0,marginLeft:8},children:o?"...":"REMOVE"})]})})}function m8({onClose:e}){const[n,a]=v.useState(null),[i,o]=v.useState(!0),[u,d]=v.useState(null),[f,m]=v.useState(null),h=v.useCallback(async()=>{o(!0),d(null);try{const k=await ye.getActiveSessions();a(k)}catch(k){d(k instanceof Error?k.message:"Failed to load sessions")}finally{o(!1)}},[]);v.useEffect(()=>{h();const k=setInterval(h,1e4);return()=>clearInterval(k)},[h]);const x=async k=>{m(k);try{await ye.deleteActiveSession(k),await h()}catch(E){d(E instanceof Error?E.message:"Failed to remove session")}finally{m(null)}},g=async()=>{try{await ye.cleanupActiveSessions(),await h()}catch(k){d(k instanceof Error?k.message:"Failed to cleanup sessions")}};if(i&&!n)return l.jsx("div",{style:{padding:24,color:"rgba(255,255,255,0.6)"},children:"Loading sessions..."});if(u&&!n)return l.jsxs("div",{style:{padding:24,color:"#ff6b6b"},children:[u,l.jsx("button",{onClick:e,style:{marginLeft:12,color:"rgba(255,255,255,0.6)",background:"none",border:"none",cursor:"pointer"},children:"Close"})]});if(!n)return null;const w=n.sessions.filter(k=>k.status==="active"),b=n.sessions.filter(k=>k.status==="idle"),j=n.sessions.filter(k=>k.status==="dead");return l.jsxs("div",{style:{padding:20,color:"rgba(255,255,255,0.9)",maxHeight:"100%",overflowY:"auto"},children:[l.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:16},children:[l.jsx("h3",{style:{margin:0,fontSize:16,fontWeight:600},children:"ACTIVE SESSIONS"}),l.jsxs("div",{style:{display:"flex",gap:8},children:[j.length>0&&l.jsx("button",{onClick:g,style:{background:"rgba(255,180,100,0.15)",border:"1px solid rgba(255,180,100,0.2)",color:"#FFB74D",borderRadius:6,padding:"4px 10px",fontSize:12,cursor:"pointer"},children:"Cleanup Dead"}),l.jsx("button",{onClick:h,disabled:i,style:{background:"rgba(255,255,255,0.08)",border:"1px solid rgba(255,255,255,0.1)",color:"rgba(255,255,255,0.7)",borderRadius:6,padding:"4px 10px",fontSize:12,cursor:i?"wait":"pointer"},children:i?"Checking...":"Refresh"}),l.jsx("button",{onClick:e,style:{background:"none",border:"none",color:"rgba(255,255,255,0.5)",cursor:"pointer",fontSize:18},children:"×"})]})]}),u&&l.jsx("div",{style:{padding:"8px 12px",background:"rgba(255,100,100,0.1)",borderRadius:6,color:"#ff6b6b",fontSize:12,marginBottom:12},children:u}),l.jsxs("div",{style:{padding:"10px 14px",background:"rgba(255,255,255,0.04)",borderRadius:8,border:"1px solid rgba(255,255,255,0.06)",marginBottom:16,fontSize:13,display:"flex",justifyContent:"space-between"},children:[l.jsxs("div",{children:[l.jsx("span",{style:{color:"rgba(255,255,255,0.5)"},children:"Sessions: "}),l.jsx("span",{style:{fontWeight:500},children:n.summary.active})]}),l.jsxs("div",{children:[l.jsx("span",{style:{color:"rgba(255,255,255,0.5)"},children:"Ports in use: "}),l.jsx("span",{style:{fontWeight:500},children:n.summary.totalPorts})]})]}),w.length>0&&l.jsxs(l.Fragment,{children:[l.jsx(Uh,{label:"Active",count:w.length}),w.map(k=>l.jsx(qh,{session:k,removing:f===k.sessionId,onRemove:()=>x(k.sessionId),statusColor:"#4FC3F7"},k.sessionId))]}),b.length>0&&l.jsxs(l.Fragment,{children:[l.jsx(Uh,{label:"Idle",count:b.length}),b.map(k=>l.jsx(qh,{session:k,removing:f===k.sessionId,onRemove:()=>x(k.sessionId),statusColor:"#FFB74D"},k.sessionId))]}),j.length>0&&l.jsxs(l.Fragment,{children:[l.jsx(Uh,{label:"Dead",count:j.length}),j.map(k=>l.jsx(qh,{session:k,removing:f===k.sessionId,onRemove:()=>x(k.sessionId),statusColor:"#ff6b6b"},k.sessionId))]}),n.sessions.length===0&&l.jsx("div",{style:{color:"rgba(255,255,255,0.4)",fontSize:13,padding:"20px 0",textAlign:"center"},children:"No active sessions. Sessions appear when jobs run with port allocation."})]})}function Uh({label:e,count:n}){return l.jsxs("h4",{style:{margin:"16px 0 8px",fontSize:11,fontWeight:600,color:"rgba(255,255,255,0.5)",textTransform:"uppercase",letterSpacing:1},children:[e," (",n,")"]})}function p8(e){const n=Date.now()-new Date(e).getTime(),a=Math.floor(n/6e4);if(a<1)return"just now";if(a<60)return`${a}m ago`;const i=Math.floor(a/60);return i<24?`${i}h ago`:`${Math.floor(i/24)}d ago`}function qh({session:e,removing:n,onRemove:a,statusColor:i}){const{ports:o}=e;return l.jsx("div",{style:{marginBottom:8,padding:"10px 14px",background:"rgba(255,255,255,0.03)",borderRadius:8,border:"1px solid rgba(255,255,255,0.06)"},children:l.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"flex-start"},children:[l.jsxs("div",{style:{flex:1,minWidth:0},children:[l.jsxs("div",{style:{fontSize:13,fontWeight:500,marginBottom:2},children:[l.jsx("span",{style:{display:"inline-block",width:8,height:8,borderRadius:"50%",backgroundColor:i,marginRight:8,verticalAlign:"middle"}}),l.jsx("span",{style:{textTransform:"uppercase"},children:e.roleName||e.roleId}),e.jobStatus&&l.jsx("span",{style:{marginLeft:8,fontSize:10,padding:"1px 6px",background:"rgba(255,255,255,0.08)",borderRadius:3,color:"rgba(255,255,255,0.6)"},children:e.jobStatus})]}),e.task&&l.jsxs("div",{style:{fontSize:11,color:"rgba(255,255,255,0.5)",marginBottom:4},children:['"',e.task.slice(0,60),e.task.length>60?"...":"",'"']}),l.jsxs("div",{style:{fontSize:11,display:"flex",gap:8,marginBottom:2},children:[l.jsxs("span",{style:{color:"#81C784"},children:["API:",o.api||"?"]}),l.jsxs("span",{style:{color:"#64B5F6"},children:["Vite:",o.vite||"?"]}),o.hmr&&l.jsxs("span",{style:{color:"#FFB74D"},children:["HMR:",o.hmr]})]}),l.jsxs("div",{style:{fontSize:10,color:"rgba(255,255,255,0.35)"},children:[e.sessionId.slice(0,12),"...",e.worktreePath&&l.jsxs(l.Fragment,{children:[" · ",x8(e.worktreePath)]}),e.pid&&l.jsxs(l.Fragment,{children:[" · ","PID:",e.pid]})," · ",p8(e.startedAt)]})]}),l.jsx("button",{onClick:a,disabled:n,style:{background:"rgba(255,100,100,0.15)",border:"1px solid rgba(255,100,100,0.2)",color:"#ff6b6b",borderRadius:4,padding:"3px 8px",fontSize:10,cursor:n?"wait":"pointer",opacity:n?.6:1,fontWeight:600,textTransform:"uppercase",letterSpacing:.5,flexShrink:0,marginLeft:8},children:n?"...":"STOP"})]})})}function x8(e,n=35){return e.length<=n?e:"..."+e.slice(e.length-n+3)}function g8({onClose:e,speechSettings:n,onSpeechSettingsChange:a,language:i,onLanguageChange:o,onOpenSync:u,onOpenGitStatus:d,onOpenSessions:f,onOpenStats:m}){var oe;const[h,x]=v.useState(null),[g,w]=v.useState(null),[b,j]=v.useState(!1),[k,E]=v.useState(!1),[C,N]=v.useState(!1),[_,z]=v.useState(null),[H,R]=v.useState(""),[I,q]=v.useState(!1),[X,A]=v.useState(!1),[$,L]=v.useState(null),[Y,se]=v.useState(!1);v.useEffect(()=>{ye.getPreferences().then(async de=>{const V=de;if(x(V.instanceId??null),V.instanceId)try{const{name:D}=await wr.getMyName(V.instanceId);w(D)}catch{}}).catch(()=>{}),ye.getCodeRoot().then(({codeRoot:de})=>{z(de),de&&R(de)}).catch(()=>{})},[]);const ee=async()=>{N(!0);try{const V=await(await fetch("/api/preferences/regenerate-token",{method:"POST"})).json();V.ok&&(x(V.newInstanceId),E(!1))}catch{}N(!1)},W=()=>{h&&navigator.clipboard.writeText(h).then(()=>{j(!0),setTimeout(()=>j(!1),2e3)})};return l.jsx("div",{className:"customize-overlay",onClick:e,children:l.jsxs("div",{className:"customize-modal",onClick:de=>de.stopPropagation(),style:{maxWidth:480},children:[l.jsxs("div",{className:"customize-header",children:[l.jsx("div",{style:{fontSize:12,fontWeight:700,letterSpacing:1,color:"var(--terminal-text)"},children:"SETTINGS"}),l.jsx("button",{className:"customize-close",onClick:e,children:"X"})]}),l.jsx("div",{className:"customize-body",style:{padding:"12px 20px 20px"},children:l.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:20},children:[l.jsxs("div",{children:[l.jsx("div",{style:{fontSize:11,fontWeight:600,marginBottom:8,color:"var(--terminal-text)"},children:"AMBIENT SPEECH MODE"}),l.jsx("div",{style:{display:"flex",gap:6},children:["template","llm","auto"].map(de=>l.jsxs("button",{onClick:()=>a==null?void 0:a({mode:de}),style:{flex:1,padding:"8px 12px",fontSize:11,border:`2px solid ${(n==null?void 0:n.mode)===de?"var(--accent)":"rgba(255,255,255,0.1)"}`,background:(n==null?void 0:n.mode)===de?"rgba(255,255,255,0.08)":"transparent",color:(n==null?void 0:n.mode)===de?"var(--terminal-text)":"var(--terminal-text-muted)",borderRadius:6,cursor:"pointer",textAlign:"center"},children:[l.jsx("div",{style:{fontWeight:600,marginBottom:2},children:de==="template"?"TEMPLATE":de==="llm"?"AI":"AUTO"}),l.jsx("div",{style:{fontSize:9,opacity:.7},children:de==="template"?"Static pool ($0)":de==="llm"?"LLM generated":"Detect engine"})]},de))}),l.jsx("div",{style:{fontSize:9,color:"var(--terminal-text-muted)",marginTop:4},children:"Auto: CLI Max = AI, BYOK = Template"})]}),l.jsxs("div",{children:[l.jsxs("div",{style:{fontSize:11,fontWeight:600,marginBottom:8,color:"var(--terminal-text)"},children:["SPEECH INTERVAL: ",(n==null?void 0:n.intervalSec)??18,"s"]}),l.jsx("input",{type:"range",min:5,max:120,step:5,value:(n==null?void 0:n.intervalSec)??18,onChange:de=>a==null?void 0:a({intervalSec:Number(de.target.value)}),style:{width:"100%",accentColor:"var(--accent)"}}),l.jsxs("div",{style:{display:"flex",justifyContent:"space-between",fontSize:9,color:"var(--terminal-text-muted)"},children:[l.jsx("span",{children:"5s (frequent)"}),l.jsx("span",{children:"120s (rare)"})]})]}),(n==null?void 0:n.mode)!=="template"&&l.jsxs("div",{children:[l.jsxs("div",{style:{fontSize:11,fontWeight:600,marginBottom:8,color:"var(--terminal-text)"},children:["DAILY LLM BUDGET: $",((oe=n==null?void 0:n.dailyBudgetUsd)==null?void 0:oe.toFixed(2))??"1.00"]}),l.jsx("input",{type:"range",min:0,max:5,step:.25,value:(n==null?void 0:n.dailyBudgetUsd)??1,onChange:de=>a==null?void 0:a({dailyBudgetUsd:Number(de.target.value)}),style:{width:"100%",accentColor:"var(--accent)"}}),l.jsxs("div",{style:{display:"flex",justifyContent:"space-between",fontSize:9,color:"var(--terminal-text-muted)"},children:[l.jsx("span",{children:"$0 (unlimited)"}),l.jsx("span",{children:"$5.00/day"})]})]}),l.jsxs("div",{children:[l.jsx("div",{style:{fontSize:11,fontWeight:600,marginBottom:8,color:"var(--terminal-text)"},children:"LANGUAGE"}),l.jsx("div",{style:{display:"flex",gap:6},children:[{key:"auto",label:"Auto"},{key:"en",label:"English"},{key:"ko",label:"한국어"},{key:"ja",label:"日本語"}].map(({key:de,label:V})=>l.jsx("button",{onClick:()=>o==null?void 0:o(de),style:{flex:1,padding:"8px 12px",fontSize:11,border:`2px solid ${(i??"auto")===de?"var(--accent)":"rgba(255,255,255,0.1)"}`,background:(i??"auto")===de?"rgba(255,255,255,0.08)":"transparent",color:(i??"auto")===de?"var(--terminal-text)":"var(--terminal-text-muted)",borderRadius:6,cursor:"pointer",textAlign:"center",fontWeight:600},children:V},de))}),l.jsx("div",{style:{fontSize:9,color:"var(--terminal-text-muted)",marginTop:4},children:"Sets language for AI responses and speech bubbles"})]}),l.jsxs("div",{children:[l.jsx("div",{style:{fontSize:11,fontWeight:600,marginBottom:8,color:"var(--terminal-text)"},children:"CODE REPOSITORY"}),I?l.jsxs("div",{children:[l.jsxs("div",{style:{display:"flex",gap:6},children:[l.jsx("input",{type:"text",value:H,onChange:de=>{R(de.target.value),L(null)},placeholder:"/path/to/code/repo",style:{flex:1,padding:"8px 10px",fontSize:11,background:"rgba(255,255,255,0.04)",border:"1px solid rgba(255,255,255,0.15)",borderRadius:6,color:"var(--terminal-text)",fontFamily:"monospace",outline:"none"},autoFocus:!0}),l.jsx("button",{onClick:async()=>{if(H.trim()){A(!0),L(null);try{const de=await ye.setCodeRoot(H.trim());z(de.codeRoot),R(de.codeRoot),q(!1),se(!0),setTimeout(()=>se(!1),3e3)}catch(de){L(de instanceof Error?de.message:"Failed to set code root")}finally{A(!1)}}},disabled:X||!H.trim(),style:{padding:"8px 12px",fontSize:10,fontWeight:600,background:"var(--accent)",border:"none",color:"#fff",borderRadius:6,cursor:"pointer",opacity:X||!H.trim()?.5:1},children:X?"...":"Save"}),l.jsx("button",{onClick:()=>{q(!1),R(_||""),L(null)},style:{padding:"8px 10px",fontSize:10,background:"transparent",border:"1px solid rgba(255,255,255,0.1)",color:"var(--terminal-text-muted)",borderRadius:6,cursor:"pointer"},children:"Cancel"})]}),$&&l.jsx("div",{style:{fontSize:9,color:"#ff6b6b",marginTop:4},children:$})]}):l.jsxs("div",{style:{display:"flex",gap:6,alignItems:"center"},children:[l.jsx("code",{style:{flex:1,padding:"8px 10px",fontSize:10,background:"rgba(255,255,255,0.04)",border:"1px solid rgba(255,255,255,0.1)",borderRadius:6,color:_?"var(--terminal-text)":"var(--terminal-text-muted)",fontFamily:"monospace",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:_||"Not configured"}),l.jsx("button",{onClick:()=>{q(!0),L(null),se(!1)},style:{padding:"8px 12px",fontSize:10,fontWeight:600,border:"2px solid rgba(255,255,255,0.1)",background:"transparent",color:"var(--terminal-text-muted)",borderRadius:6,cursor:"pointer"},children:"Change"})]}),Y&&l.jsx("div",{style:{fontSize:9,color:"#4ade80",marginTop:4},children:"Code repository updated!"}),l.jsx("div",{style:{fontSize:9,color:"var(--terminal-text-muted)",marginTop:4},children:"Path to your code repository (separate from AKB)"})]}),h&&l.jsxs("div",{children:[l.jsx("div",{style:{fontSize:11,fontWeight:600,marginBottom:8,color:"var(--terminal-text)"},children:"STORE TOKEN"}),l.jsxs("div",{style:{display:"flex",gap:6,alignItems:"center"},children:[l.jsx("code",{style:{flex:1,padding:"8px 10px",fontSize:10,background:"rgba(255,255,255,0.04)",border:"1px solid rgba(255,255,255,0.1)",borderRadius:6,color:"var(--terminal-text-muted)",fontFamily:"monospace",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:h}),l.jsx("button",{onClick:W,style:{padding:"8px 12px",fontSize:10,fontWeight:600,border:"2px solid rgba(255,255,255,0.1)",background:"transparent",color:b?"#4ade80":"var(--terminal-text-muted)",borderRadius:6,cursor:"pointer",whiteSpace:"nowrap"},children:b?"Copied!":"Copy"})]}),l.jsx("div",{style:{fontSize:9,color:"var(--terminal-text-muted)",marginTop:4},children:"Use this token to sign in on the web Store. Keep it secret — anyone with this token can act as you."}),l.jsx("div",{style:{marginTop:6},children:k?l.jsxs("div",{style:{background:"rgba(255,50,50,0.08)",border:"1px solid rgba(255,50,50,0.2)",borderRadius:6,padding:"8px 10px"},children:[l.jsx("div",{style:{fontSize:9,color:"rgba(255,100,100,0.8)",marginBottom:6},children:"This will invalidate your current token. Published characters will lose ownership. No migration."}),l.jsxs("div",{style:{display:"flex",gap:6},children:[l.jsx("button",{onClick:ee,disabled:C,style:{padding:"4px 12px",fontSize:9,fontWeight:700,border:"1px solid rgba(255,50,50,0.4)",background:"rgba(255,50,50,0.15)",color:"#ff6464",borderRadius:4,cursor:"pointer"},children:C?"...":"Confirm Regenerate"}),l.jsx("button",{onClick:()=>E(!1),style:{padding:"4px 12px",fontSize:9,border:"none",background:"transparent",color:"var(--terminal-text-muted)",cursor:"pointer"},children:"Cancel"})]})]}):l.jsx("button",{onClick:()=>E(!0),style:{padding:"4px 10px",fontSize:9,fontWeight:600,border:"1px solid rgba(255,100,100,0.2)",background:"transparent",color:"rgba(255,100,100,0.6)",borderRadius:4,cursor:"pointer"},children:"Regenerate Token"})})]}),l.jsxs("div",{style:{borderTop:"1px solid rgba(255,255,255,0.08)",paddingTop:16,display:"flex",gap:8},children:[u&&l.jsx("button",{onClick:()=>{e(),u()},className:"theme-btn",style:{flex:1,padding:"8px 12px",fontSize:10},children:"🔄 ROLE SYNC"}),d&&l.jsx("button",{onClick:()=>{e(),d()},className:"theme-btn",style:{flex:1,padding:"8px 12px",fontSize:10},children:"📂 GIT STATUS"}),f&&l.jsx("button",{onClick:()=>{e(),f()},className:"theme-btn",style:{flex:1,padding:"8px 12px",fontSize:10},children:"🖥 SESSIONS"}),m&&l.jsx("button",{onClick:()=>{e(),m()},className:"theme-btn",style:{flex:1,padding:"8px 12px",fontSize:10},children:"📊 COMPANY STATS"}),l.jsx("button",{onClick:()=>window.open("https://tycono.ai/store.html","_blank"),className:"theme-btn",style:{flex:1,padding:"8px 12px",fontSize:10},children:"🌐 WEB STORE"})]}),g&&l.jsx("div",{style:{textAlign:"center",marginTop:-8},children:l.jsx("a",{href:`https://tycono.ai/profile.html?u=${encodeURIComponent(g)}`,target:"_blank",rel:"noopener noreferrer",style:{fontSize:10,color:"var(--terminal-text-muted)",textDecoration:"none"},onMouseEnter:de=>de.currentTarget.style.color="var(--accent)",onMouseLeave:de=>de.currentTarget.style.color="var(--terminal-text-muted)",children:"View public profile →"})})]})})]})})}function y8({theme:e,onThemeChange:n,onClose:a}){const i=v.useRef(null);return v.useEffect(()=>{const o=u=>{i.current&&!i.current.contains(u.target)&&a()};return document.addEventListener("mousedown",o),()=>document.removeEventListener("mousedown",o)},[a]),l.jsx("div",{ref:i,className:"theme-dropup",children:Object.entries(ll).map(([o,u])=>l.jsxs("button",{className:`theme-dropup__item${e===o?" theme-dropup__item--active":""}`,onClick:()=>{n(o),a()},title:u.name,children:[l.jsxs("span",{className:"theme-dropup__swatch",style:{background:u.vars["--hud-bg"],borderColor:u.vars["--pixel-border"]},children:[l.jsx("span",{style:{background:u.vars["--accent"],width:5,height:5,borderRadius:1}}),l.jsx("span",{style:{background:u.vars["--active-green"],width:5,height:5,borderRadius:1}}),l.jsx("span",{style:{background:u.vars["--idle-amber"],width:5,height:5,borderRadius:1}})]}),l.jsx("span",{className:"theme-dropup__name",children:u.icon})]},o))})}const vs={cto:"#1565C0",cbo:"#E65100",pm:"#2E7D32",engineer:"#4A148C",designer:"#AD1457",qa:"#00695C","data-analyst":"#0277BD"};function b8({roles:e,roleStatuses:n,activeExecs:a,sessions:i,knowledgeDocs:o,roleLevels:u,companyName:d,getAppearance:f,waveCenterWaves:m,renderProfile:h,channel:x,onChannelChange:g,onClose:w,children:b}){const[j,k]=v.useState(!1),E=m.filter(I=>I.rootJobs.some(q=>{const X=n[q.roleId];return X==="working"||X==="thinking"})),C=[...e].sort((I,q)=>I.level==="c-level"&&q.level!=="c-level"?-1:I.level!=="c-level"&&q.level==="c-level"?1:I.name.localeCompare(q.name)),N=e.filter(I=>n[I.id]==="working").length,_=i.filter(I=>I.status==="active").length,z=x.type==="role"?e.find(I=>I.id===x.roleId):null,H=x.type==="dashboard"?"Dashboard":x.type==="terminal"?"Chats":x.type==="wave"?"Wave Center":x.type==="knowledge"?"Knowledge Base":x.type==="operations"?"Operations":x.type==="role"?(z==null?void 0:z.name)??x.roleId:"Dashboard",R=x.type==="terminal"?`${_} active sessions`:x.type==="wave"?`${E.length} running`:x.type==="knowledge"?`${o.length} documents`:x.type==="role"?(z==null?void 0:z.level)==="c-level"?"C-Level":"Team member":`${N} working · ${e.length} total`;return l.jsxs("div",{className:"fixed inset-0 z-[60] flex",style:{background:"var(--terminal-bg, #1C1612)"},children:[l.jsxs("div",{className:"flex flex-col shrink-0 overflow-y-auto",style:{width:240,borderRight:"1px solid var(--terminal-border, #2E261F)",background:"var(--terminal-surface, #1a1510)"},children:[l.jsxs("div",{className:"px-4 py-3 flex items-center gap-2 shrink-0",style:{borderBottom:"1px solid var(--terminal-border, #2E261F)"},children:[l.jsx("span",{className:"text-[11px] font-bold tracking-wider flex-1",style:{color:"var(--terminal-text, #fff5eb)",fontFamily:"var(--pixel-font)"},children:d}),N>0&&l.jsxs("span",{className:"text-[9px] px-1.5 py-0.5 rounded-full animate-pulse",style:{background:"#4CAF5020",color:"#4CAF50"},children:[N," live"]})]}),E.length>0&&l.jsxs("button",{className:"mx-3 mt-3 px-3 py-2.5 rounded-lg text-left transition-all hover:opacity-90",style:{background:x.type==="wave"?"#EF444420":"#EF444410",border:"1px solid #EF444430"},onClick:()=>g({type:"wave"}),children:[l.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[l.jsxs("span",{className:"text-[10px] font-bold truncate flex-1",style:{color:"#EF4444"},children:["⚡"," ",E[0].directive.slice(0,28)]}),l.jsx("span",{className:"text-[7px] px-1.5 py-0.5 rounded font-bold shrink-0",style:{background:"#EF4444",color:"#fff"},children:"LIVE"})]}),l.jsxs("div",{className:"text-[9px]",style:{color:"var(--terminal-text-muted)"},children:[E[0].rootJobs.filter(I=>{const q=n[I.roleId];return q==="working"||q==="thinking"}).length,"/",E[0].rootJobs.length," roles working"]})]}),l.jsxs("div",{className:"mx-3 mt-3 grid grid-cols-2 gap-1.5",children:[l.jsx(Eu,{icon:"💬",label:"Chats",badge:_||void 0,active:x.type==="terminal",onClick:()=>g({type:"terminal"})}),l.jsx(Eu,{icon:"⚡",label:"Waves",live:E.length>0,active:x.type==="wave",onClick:()=>g({type:"wave"})}),l.jsx(Eu,{icon:"📋",label:"Decisions",active:x.type==="operations",onClick:()=>g({type:"operations"})}),l.jsx(Eu,{icon:"📚",label:"Knowledge",badge:o.length||void 0,active:x.type==="knowledge",onClick:()=>g({type:"knowledge"})})]}),l.jsxs("div",{className:"mt-4",children:[l.jsx("div",{className:"px-4 py-1 text-[9px] font-bold tracking-widest",style:{color:"var(--terminal-text-muted)"},children:"TEAM"}),C.map(I=>{var Y;const q=n[I.id],X=a.find(se=>se.roleId===I.id),A=vs[I.id]??"#666",$=(Y=u[I.id])==null?void 0:Y.level,L=x.type==="role"&&x.roleId===I.id;return l.jsxs("button",{onClick:()=>g({type:"role",roleId:I.id}),className:"flex items-center gap-2.5 w-full px-4 py-1.5 text-left hover:opacity-80 transition-all",style:{background:L?`${A}18`:"transparent",borderLeft:L?`2px solid ${A}`:"2px solid transparent"},children:[l.jsxs("div",{className:"relative shrink-0",style:{width:22,height:22},children:[l.jsx(Ul,{roleId:I.id,appearance:f(I.id),scale:1.3}),l.jsx("span",{className:"absolute -bottom-0.5 -right-0.5 w-2 h-2 rounded-full",style:{background:q==="working"?"#4CAF50":q==="idle"?"#FFC107":"#9E9E9E",border:"1.5px solid var(--terminal-surface, #1a1510)"}})]}),l.jsxs("div",{className:"min-w-0 flex-1",children:[l.jsxs("div",{className:"text-[11px] truncate",style:{color:"var(--terminal-text, #fff5eb)"},children:[I.name,$!=null&&l.jsxs("span",{className:"ml-1 opacity-40 text-[8px]",children:["Lv.",$]})]}),X?l.jsx("div",{className:"text-[9px] truncate",style:{color:A},children:X.task.slice(0,28)}):l.jsx("div",{className:"text-[9px]",style:{color:"var(--terminal-text-muted, #887766)"},children:I.level==="c-level"?I.id.toUpperCase():I.id})]}),q==="working"&&l.jsx("span",{className:"w-1.5 h-1.5 rounded-full animate-pulse shrink-0",style:{background:A}})]},I.id)})]}),l.jsx("div",{className:"flex-1"}),a.length>0&&l.jsxs("div",{className:"shrink-0 px-3 pb-2",style:{borderTop:"1px solid var(--terminal-border, #2E261F)"},children:[l.jsxs("div",{className:"px-1 py-1.5 text-[8px] font-bold tracking-widest",style:{color:"var(--terminal-text-muted)"},children:["ACTIVE JOBS (",a.length,")"]}),l.jsx("div",{className:"space-y-0.5 max-h-[140px] overflow-y-auto",children:a.map(I=>{const q=e.find($=>$.id===I.roleId),X=vs[I.roleId]??"#666",A=x.type==="role"&&x.roleId===I.roleId;return l.jsxs("button",{onClick:()=>g({type:"role",roleId:I.roleId}),className:"flex items-center gap-2 w-full px-2 py-1.5 rounded text-left hover:opacity-80 transition-all",style:{background:A?`${X}18`:"transparent"},children:[l.jsx("span",{className:"w-1.5 h-1.5 rounded-full animate-pulse shrink-0",style:{background:X}}),l.jsxs("div",{className:"min-w-0 flex-1",children:[l.jsx("div",{className:"text-[10px] truncate",style:{color:"var(--terminal-text, #fff5eb)"},children:(q==null?void 0:q.name)??I.roleId}),l.jsx("div",{className:"text-[8px] truncate",style:{color:"var(--terminal-text-muted)"},children:I.task.slice(0,40)})]})]},I.jobId??I.roleId)})})]}),l.jsx("div",{className:"px-3 py-3 shrink-0",style:{borderTop:"1px solid var(--terminal-border, #2E261F)"},children:l.jsxs("button",{onClick:w,className:"flex items-center gap-2 w-full px-3 py-2.5 rounded-lg hover:opacity-80 transition-opacity",style:{background:"var(--terminal-border, #2E261F)",color:"var(--terminal-text, #fff5eb)"},children:[l.jsx("span",{className:"text-[12px]",children:"🏢"}),l.jsx("span",{className:"text-[11px] font-medium",children:"Office"})]})})]}),l.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden",children:[l.jsxs("div",{className:"px-5 py-3 flex items-center gap-3 shrink-0",style:{borderBottom:"1px solid var(--terminal-border, #2E261F)"},children:[x.type==="role"&&z&&l.jsxs("button",{onClick:()=>k(I=>!I),className:"relative shrink-0 rounded-lg overflow-hidden hover:opacity-80 transition-opacity cursor-pointer",style:{width:28,height:28,background:`${vs[z.id]??"#666"}30`},title:"View profile",children:[l.jsx(Ul,{roleId:z.id,appearance:f(z.id),scale:1.5}),l.jsx("span",{className:"absolute -bottom-0.5 -right-0.5 w-2.5 h-2.5 rounded-full",style:{background:n[z.id]==="working"?"#4CAF50":n[z.id]==="idle"?"#FFC107":"#9E9E9E",border:"2px solid var(--terminal-bg, #1C1612)"}})]}),l.jsx("span",{className:"text-[15px] font-semibold",style:{color:"var(--terminal-text, #fff5eb)"},children:H}),l.jsx("span",{className:"text-[10px]",style:{color:"var(--terminal-text-muted, #887766)"},children:R}),l.jsx("span",{className:"flex-1"}),x.type==="role"&&l.jsx("button",{onClick:()=>k(I=>!I),className:"text-[10px] px-2 py-1 rounded hover:opacity-80 transition-opacity",style:{color:j?"var(--terminal-text)":"var(--terminal-text-muted)",border:"1px solid var(--terminal-border)",background:j?"var(--terminal-border)":"transparent"},children:"Profile"}),x.type!=="dashboard"&&l.jsx("button",{onClick:()=>g({type:"dashboard"}),className:"text-[10px] px-2 py-1 rounded hover:opacity-80 transition-opacity",style:{color:"var(--terminal-text-muted)",border:"1px solid var(--terminal-border)"},children:"Dashboard"})]}),l.jsxs("div",{className:"flex-1 flex overflow-hidden",children:[l.jsx("div",{className:"flex-1 overflow-hidden relative pro-panel-inline",children:b}),j&&x.type==="role"&&h&&l.jsx("div",{className:"shrink-0 overflow-hidden pro-panel-inline",style:{width:420,borderLeft:"1px solid var(--terminal-border, #2E261F)"},children:h(()=>k(!1))})]})]})]})}function v8({role:e,messages:n,isStreaming:a,mode:i,onModeChange:o,onSend:u,isWave:d}){const f=vs[e.id]??"#666";return l.jsxs("div",{className:"flex flex-col h-full",children:[l.jsx(hv,{messages:n,roleId:e.id,roleColor:f}),d?l.jsxs("div",{className:"shrink-0 px-4 py-2 border-t flex items-center gap-2",style:{borderColor:"var(--terminal-border)",background:"var(--terminal-bg-deeper)"},children:[l.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-amber-400 shrink-0",style:{animation:"pulse 2s infinite"}}),l.jsx("span",{className:"text-[11px] text-amber-400/80",children:"Wave execution · read-only"})]}):l.jsx(Qm,{mode:i,onModeChange:o,onSend:(m,h)=>u(m,i,h),disabled:a,disabledReason:a?`${e.id.toUpperCase()} is responding...`:void 0})]})}function w8({role:e,onSend:n,getAppearance:a,onOpenProfile:i}){const[o,u]=v.useState("talk"),d=vs[e.id]??"#666";return l.jsxs("div",{className:"flex flex-col h-full",children:[l.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center gap-4",children:[l.jsx("button",{onClick:i,className:"cursor-pointer hover:opacity-80 transition-opacity",children:l.jsx("div",{className:"rounded-lg p-1",style:{background:`${d}20`},children:l.jsx(Ul,{roleId:e.id,appearance:a(e.id),scale:5})})}),l.jsxs("div",{className:"text-center",children:[l.jsx("div",{className:"text-sm font-semibold",style:{color:"var(--terminal-text)"},children:e.name}),l.jsxs("div",{className:"text-xs mt-0.5",style:{color:"var(--terminal-text-muted)"},children:[e.level==="c-level"?e.id.toUpperCase():e.id," · Start a conversation"]})]})]}),l.jsx(Qm,{mode:o,onModeChange:u,onSend:f=>n(f,o),disabled:!1})]})}function Eu({icon:e,label:n,active:a,badge:i,live:o,onClick:u}){return l.jsxs("button",{onClick:u,className:"flex flex-col items-center gap-1 py-3 rounded-lg transition-all hover:opacity-90",style:{background:a?"var(--desk-wood, #5C3D2E)":"var(--terminal-border, #2E261F)",border:a?"1px solid var(--desk-wood, #5C3D2E)":"1px solid transparent"},children:[l.jsxs("div",{className:"relative",children:[l.jsx("span",{className:"text-[16px]",children:e}),o&&l.jsx("span",{className:"absolute -top-1 -right-2 w-2 h-2 rounded-full animate-pulse",style:{background:"#EF4444"}}),i!==void 0&&i>0&&!o&&l.jsx("span",{className:"absolute -top-1.5 -right-3 text-[7px] px-1 py-0.5 rounded-full font-bold leading-none",style:{background:"var(--desk-wood, #5C3D2E)",color:"#fff",minWidth:14,textAlign:"center"},children:i})]}),l.jsx("span",{className:"text-[10px] font-semibold",style:{color:a?"#fff":"var(--terminal-text, #fff5eb)"},children:n})]})}function k8({roles:e,roleStatuses:n,activeExecs:a,waves:i,knowledgeDocs:o,roleLevels:u,getAppearance:d,onRoleClick:f,onWaveClick:m,onKnowledgeClick:h}){const x=e.filter(g=>n[g.id]==="working");return l.jsx("div",{className:"h-full overflow-y-auto px-6 py-5",children:l.jsxs("div",{className:"space-y-5 max-w-4xl",children:[l.jsxs("div",{className:"flex gap-3",children:[l.jsx(yy,{label:"New Wave",icon:"⚡",color:"#EF4444",onClick:m}),l.jsx(yy,{label:"Knowledge",icon:"📚",color:"#0D9488",onClick:h})]}),x.length>0&&l.jsx(Nu,{title:"Currently Working",count:x.length,children:a.map(g=>{const w=e.find(j=>j.id===g.roleId),b=vs[g.roleId]??"#666";return l.jsxs("button",{onClick:()=>f(g.roleId),className:"flex items-center gap-3 px-4 py-2.5 rounded hover:opacity-80 w-full text-left",style:{background:`${b}10`},children:[l.jsx("div",{className:"shrink-0",style:{width:24,height:24},children:l.jsx(Ul,{roleId:g.roleId,appearance:d(g.roleId),scale:1.2})}),l.jsxs("div",{className:"flex-1 min-w-0",children:[l.jsx("span",{className:"text-[12px] font-medium",style:{color:b},children:w==null?void 0:w.name}),l.jsx("span",{className:"text-[11px] ml-2 truncate",style:{color:"var(--terminal-text-muted)"},children:g.task.slice(0,60)})]}),l.jsx("span",{className:"text-[10px] animate-pulse",style:{color:b},children:"●"})]},g.roleId)})}),l.jsx(Nu,{title:"Team",count:e.length,children:l.jsx("div",{className:"grid grid-cols-3 gap-1 px-2",children:e.map(g=>{var j;const w=n[g.id]??"offline",b=(j=u[g.id])==null?void 0:j.level;return l.jsxs("button",{onClick:()=>f(g.id),className:"flex items-center gap-2 px-3 py-2 rounded hover:opacity-80 text-left",children:[l.jsx("span",{className:"w-2 h-2 rounded-full shrink-0",style:{background:w==="working"?"#4CAF50":w==="idle"?"#FFC107":"#9E9E9E"}}),l.jsx("span",{className:"text-[11px] truncate",style:{color:"var(--terminal-text)"},children:g.name}),b!=null&&l.jsxs("span",{className:"text-[9px] opacity-40",children:["Lv.",b]})]},g.id)})})}),i.length>0&&l.jsx(Nu,{title:"Recent Waves",count:i.length,children:i.slice(0,5).map(g=>{var w;return l.jsxs("div",{className:"px-4 py-2 text-[11px]",style:{color:"var(--terminal-text-muted)"},children:[l.jsxs("span",{style:{color:"var(--terminal-text)"},children:["Wave ",g.id]})," — ",(w=g.directive)==null?void 0:w.slice(0,80)]},g.id)})}),l.jsx(Nu,{title:"Knowledge Base",count:o.length,children:l.jsxs("button",{onClick:h,className:"px-4 py-3 text-[11px] hover:opacity-80",style:{color:"var(--terminal-text-muted)"},children:[o.length," documents · Click to explore ","→"]})})]})})}function yy({label:e,icon:n,color:a,onClick:i}){return l.jsxs("button",{onClick:i,className:"flex items-center gap-2 px-5 py-3 rounded-lg hover:opacity-80 transition-opacity",style:{background:`${a}15`,border:`1px solid ${a}30`},children:[l.jsx("span",{className:"text-sm",children:n}),l.jsx("span",{className:"text-[12px] font-medium",style:{color:a},children:e})]})}function Nu({title:e,count:n,children:a}){return l.jsxs("div",{className:"rounded-lg overflow-hidden",style:{background:"var(--terminal-surface, #241E19)",border:"1px solid var(--terminal-border, #2E261F)"},children:[l.jsxs("div",{className:"px-4 py-2.5 flex items-center gap-2",style:{borderBottom:"1px solid var(--terminal-border, #2E261F)"},children:[l.jsx("span",{className:"text-[10px] font-bold tracking-wider",style:{color:"var(--terminal-text-muted)"},children:e.toUpperCase()}),n!==void 0&&l.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded-full",style:{background:"var(--terminal-border)",color:"var(--terminal-text-muted)"},children:n})]}),l.jsx("div",{className:"py-1",children:a})]})}const vm=5e4;function Tv(e){return e<vm?1:Math.max(1,Math.floor(Math.sqrt(e/vm)))}function by(e){return vm*e*e}function j8(e){const n=Tv(e),a=by(n),i=by(n+1);return Math.min(1,(e-a)/(i-a))}function Yh(e){const n={};for(const[a,i]of Object.entries(e)){const o=i.inputTokens+i.outputTokens;n[a]={level:Tv(o),totalTokens:o,progress:j8(o)}}return n}const S8=[{id:"first-employee",name:"First Employee",icon:"🏆",description:"Hired your first role",check:e=>e.roleCount>=1},{id:"full-team",name:"Full Team",icon:"👥",description:"Hired 5+ roles",check:e=>e.roleCount>=5},{id:"token-10k",name:"Getting Started",icon:"📊",description:"Used 10K tokens total",check:e=>e.totalTokens>=1e4},{id:"token-100k",name:"Power User",icon:"💪",description:"Used 100K tokens total",check:e=>e.totalTokens>=1e5},{id:"token-millionaire",name:"Token Millionaire",icon:"🎖",description:"Used 1M tokens total",check:e=>e.totalTokens>=1e6},{id:"token-mogul",name:"Token Mogul",icon:"💎",description:"Used 10M tokens total",check:e=>e.totalTokens>=1e7},{id:"first-promotion",name:"First Promotion",icon:"⭐",description:"Any role reached Lv.3",check:e=>e.roles.some(n=>n.level>=3)},{id:"senior-staff",name:"Senior Staff",icon:"🌟",description:"Any role reached Lv.5",check:e=>e.roles.some(n=>n.level>=5)},{id:"master-class",name:"Master Class",icon:"👑",description:"Any role reached Lv.10",check:e=>e.roles.some(n=>n.level>=10)},{id:"full-house",name:"Full House",icon:"🏠",description:"All roles Lv.5+",check:e=>e.roleCount>=3&&e.roles.every(n=>n.level>=5)},{id:"first-launch",name:"First Launch",icon:"🚀",description:"Completed Chapter 2 — gave your first order",check:e=>{var n;return((n=e.completedQuests)==null?void 0:n.includes("ch2-q2"))??!1}},{id:"team-builder",name:"Team Builder",icon:"🏗️",description:"Completed Chapter 4 — dispatched your first wave",check:e=>{var n;return((n=e.completedQuests)==null?void 0:n.includes("ch4-q2"))??!1}},{id:"explorer",name:"Explorer",icon:"🔍",description:"Completed Chapter 5 — customized a character",check:e=>{var n;return((n=e.completedQuests)==null?void 0:n.includes("ch5-q2"))??!1}},{id:"interior-designer",name:"Interior Designer",icon:"🎨",description:"Completed Chapter 7 — bought premium furniture",check:e=>{var n;return((n=e.completedQuests)==null?void 0:n.includes("ch7-q2"))??!1}},{id:"tycoon-master",name:"Tycoon Master",icon:"🎯",description:"Completed all 10 chapters",check:e=>{var n;return((n=e.completedQuests)==null?void 0:n.includes("ch10-q3"))??!1}}];function vy(e){return S8.filter(n=>n.check(e))}const wy={cto:"#1565C0",cbo:"#E65100",pm:"#2E7D32",engineer:"#4A148C",designer:"#AD1457",qa:"#00695C","data-analyst":"#0277BD"};function C8({importJob:e,onImportDone:n}){var ac,Li,lc,ic,sc;const[a,i]=v.useState([]),[o,u]=v.useState([]),[d,f]=v.useState([]),[m,h]=v.useState([]),[x,g]=v.useState([]),[w,b]=v.useState([]),[j,k]=v.useState("TYCONO"),[E,C]=v.useState(!0),[N,_]=v.useState(null),[z,H]=v.useState({type:"none"}),[R,I]=v.useState(null),[q,X]=v.useState(null),[A,$]=v.useState([]),[L,Y]=v.useState(!1),[se,ee]=v.useState(!1),[W,oe]=v.useState([]),[de,V]=v.useState([]),[D,B]=v.useState(0),[U,T]=v.useState(!1),[ie,ge]=v.useState({}),[pe,ze]=v.useState("ceo"),[Ie,He]=v.useState(null),[st,Qe]=v.useState(!1),[et,Ee]=v.useState(!1),[De,yt]=v.useState({}),ut=v.useRef({}),[pt,jt]=v.useState(!1),[Wt,Ft]=v.useState(null),[Et,$n]=v.useState({}),[me,Se]=v.useState([]),Ne=v.useMemo(()=>{const F={};for(const Q of me)F[Q.roleId]=Q;return F},[me]),[K,ue]=v.useState([]),[te,ke]=v.useState(0),[ve,_e]=v.useState(qg()),Be=v.useRef(qg()),Oe=v.useRef(!1),qe=v.useRef(-1),[rt,Ve]=v.useState(null),bt=v.useRef(null),[Re,Ue]=v.useState(void 0),[_t,Bt]=v.useState(!1);v.useEffect(()=>{ye.getStatus().then(F=>{Ue(F.engine),Bt(!!F.hasApiKey)}).catch(()=>{})},[]);const{getAppearance:Ot,setAppearance:fn,resetAppearance:wn,theme:Z,setTheme:$e,speechSettings:nt,setSpeechSettings:Qt,language:we,setLanguage:kt}=C6(),[ln,sn]=v.useState(null),[,ne]=v.useState("character"),Ae=A6(),[We,Nt]=v.useState(!1),[kn,ur]=v.useState(!1),[xn,gn]=v.useState(!1),[dr,sl]=v.useState(!1),[Ju,Fs]=v.useState(!1),[Vo,Ta]=v.useState(!1),[Ti,ca]=v.useState(!1),[Vn,Wl]=v.useState(null);v.useEffect(()=>{Ae.refresh()},[]),v.useEffect(()=>{const F=Q=>{(Q.metaKey||Q.ctrlKey)&&Q.key==="s"&&(Q.preventDefault(),Nt(!0))};return window.addEventListener("keydown",F),()=>window.removeEventListener("keydown",F)},[]),v.useEffect(()=>{if(!dr)return;let F=!1;const Q=async()=>{try{const he=await ye.getGitStatus();F||Wl(he)}catch{}};Q();const re=setInterval(Q,1e4);return()=>{F=!0,clearInterval(re)}},[dr]);const[jr,jn]=v.useState(null),[Fa,Ma]=v.useState(null),[fr,Ra]=v.useState([]),[ol,Ms]=v.useState(!1),Rs=v.useRef(!1),zs=v.useRef(null);let Gl=v.useRef(0);const Vl=v.useRef(new Set),Pr=v.useRef(Date.now()),Dn=(F,Q,re)=>{const he={id:Gl.current++,type:F,text:Q,detail:re};Ra(je=>[...je,he])};v.useEffect(()=>{var F;ol&&((F=zs.current)==null||F.scrollIntoView({behavior:"smooth"}))},[fr,ol]),v.useEffect(()=>{e&&(Rs.current||(Rs.current=!0,Ma("Scanning knowledge sources..."),Ra([{id:0,type:"scan",text:"Starting knowledge import..."}]),Gl.current=1,fetch("/api/setup/import-knowledge",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({paths:e.paths,companyRoot:e.companyRoot})}).then(async F=>{var je;const Q=(je=F.body)==null?void 0:je.getReader();if(!Q)return;const re=new TextDecoder;let he="";for(;;){const{done:Le,value:It}=await Q.read();if(Le)break;he+=re.decode(It,{stream:!0});const dt=he.split(`
|
|
92
|
+
`);f(D)},disabled:d,className:"py-2.5 px-4 text-[11px] font-bold uppercase tracking-wider cursor-pointer disabled:opacity-50",style:{background:"var(--terminal-bg)",color:"var(--terminal-text)",border:"2px solid var(--pixel-border)"},title:`Delegate to ${m??"AI role"} — they'll review, commit, push & merge`,children:["🤖"," ",(m==null?void 0:m.toUpperCase())??"DELEGATE"]})]}),e&&!e.hasRemote&&!e.noGit&&l.jsx(s8,{repo:h,onConnected:()=>j==null?void 0:j(),onDelegate:f?()=>{f(`Set up a GitHub remote for the ${h==="akb"?"AKB":"Code"} repository and push all commits. If gh CLI is available, use "gh repo create". Otherwise, guide through manual setup. Current repo path can be found in config.`)}:void 0,delegateRoleName:m}),q&&l.jsxs("div",{className:"text-[11px] p-2",style:{background:"rgba(59,185,80,0.1)",border:"1px solid var(--active-green)",color:"var(--active-green)"},children:["Saved! ",q.filesChanged," file",q.filesChanged>1?"s":""," committed",q.pushed?" & pushed":"",q.pushError?` (push error: ${q.pushError})`:""]}),z&&l.jsx("div",{className:"text-[11px] p-2",style:{background:"rgba(211,47,47,0.1)",border:"1px solid #D32F2F",color:"#EF5350"},children:z}),(e==null?void 0:e.lastCommit)&&l.jsxs("div",{className:"text-[10px]",style:{color:"var(--terminal-text-muted)"},children:["Last save: ",e.lastCommit.message," (",xy(e.lastCommit.date),")"]})]}),E==="history"&&l.jsxs(l.Fragment,{children:[n.length===0&&l.jsx("div",{className:"text-[11px] text-center py-8",style:{color:"var(--terminal-text-muted)"},children:"No save history"}),l.jsx("div",{className:"space-y-1",children:n.map(D=>l.jsxs("div",{className:"flex items-center justify-between py-2 px-3 group",style:{background:"var(--hud-bg-alt)",border:"1px solid var(--terminal-border)"},children:[l.jsxs("div",{className:"flex-1 min-w-0",children:[l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx("span",{className:"text-[11px] font-mono",style:{color:"var(--accent)"},children:D.shortSha}),l.jsx("span",{className:"text-[11px] truncate",style:{color:"var(--terminal-text)"},children:D.message})]}),l.jsx("div",{className:"text-[10px]",style:{color:"var(--terminal-text-muted)"},children:xy(D.date)})]}),l.jsx("button",{onClick:()=>de(D.sha),disabled:R,className:"text-[10px] font-bold px-2 py-1 opacity-0 group-hover:opacity-100 transition-opacity cursor-pointer",style:{background:"var(--terminal-bg)",border:"1px solid var(--terminal-border)",color:"var(--idle-amber)"},children:"LOAD"})]},D.sha))})]})]})]})]})}function c8({onClose:e}){const[n,a]=v.useState(null),[i,o]=v.useState(!0),[u,d]=v.useState(null),[,f]=v.useState(!1);return v.useEffect(()=>{Promise.all([ye.getCompanyStats(),ye.getPreferences()]).then(async([m,h])=>{a(m);const x=h;if(x.instanceId)try{await wr.syncStats({instanceId:x.instanceId,roleCount:m.company.roleCount,totalTokens:m.company.totalTokens,rolesData:m.roles.map(g=>({roleId:g.roleId,name:g.name,tokens:g.totalTokens}))}),f(!0)}catch{}}).catch(m=>d(m.message)).finally(()=>o(!1))},[]),i?l.jsx("div",{style:{padding:24,color:"rgba(255,255,255,0.6)"},children:"Loading stats..."}):u||!n?l.jsxs("div",{style:{padding:24,color:"#ff6b6b"},children:[u||"Failed to load stats",l.jsx("button",{onClick:e,style:{marginLeft:12,color:"rgba(255,255,255,0.6)",background:"none",border:"none",cursor:"pointer"},children:"Close"})]}):l.jsxs("div",{style:{padding:20,color:"rgba(255,255,255,0.9)",maxHeight:"100%",overflowY:"auto"},children:[l.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:20},children:[l.jsx("h3",{style:{margin:0,fontSize:16,fontWeight:600},children:"Company Stats"}),l.jsx("button",{onClick:e,style:{background:"none",border:"none",color:"rgba(255,255,255,0.5)",cursor:"pointer",fontSize:18},children:"×"})]}),l.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:10,marginBottom:20},children:[l.jsx(Su,{label:"Roles",value:String(n.company.roleCount)}),l.jsx(Su,{label:"Avg Level",value:`Lv.${n.company.avgLevel}`}),l.jsx(Su,{label:"Total Tokens",value:n.company.formattedTokens}),l.jsx(Su,{label:"Total Cost",value:`$${n.company.totalCostUsd.toFixed(2)}`})]}),l.jsx("h4",{style:{margin:"0 0 12px",fontSize:13,fontWeight:600,color:"rgba(255,255,255,0.6)",textTransform:"uppercase",letterSpacing:1},children:"Role Leaderboard"}),l.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[n.roles.map((m,h)=>l.jsx(u8,{role:m,rank:h+1},m.roleId)),n.roles.length===0&&l.jsx("div",{style:{color:"rgba(255,255,255,0.4)",fontSize:13,padding:"8px 0"},children:"No role activity yet. Assign tasks to start leveling up!"})]}),Object.keys(n.byModel).length>0&&l.jsxs(l.Fragment,{children:[l.jsx("h4",{style:{margin:"20px 0 12px",fontSize:13,fontWeight:600,color:"rgba(255,255,255,0.6)",textTransform:"uppercase",letterSpacing:1},children:"Model Usage"}),l.jsx("div",{style:{display:"flex",flexDirection:"column",gap:4},children:Object.entries(n.byModel).map(([m,h])=>l.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 10px",background:"rgba(255,255,255,0.03)",borderRadius:6,fontSize:12},children:[l.jsx("span",{style:{color:"rgba(255,255,255,0.7)"},children:d8(m)}),l.jsxs("span",{style:{color:"rgba(255,255,255,0.5)"},children:["$",h.costUsd.toFixed(2)]})]},m))})]})]})}function Su({label:e,value:n}){return l.jsxs("div",{style:{padding:"12px 14px",background:"rgba(255,255,255,0.04)",borderRadius:8,border:"1px solid rgba(255,255,255,0.06)"},children:[l.jsx("div",{style:{fontSize:11,color:"rgba(255,255,255,0.45)",marginBottom:4},children:e}),l.jsx("div",{style:{fontSize:18,fontWeight:600},children:n})]})}function u8({role:e,rank:n}){const a=["🥇","🥈","🥉"],i=n<=3?a[n-1]:`#${n}`;return l.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,padding:"8px 10px",background:"rgba(255,255,255,0.03)",borderRadius:8},children:[l.jsx("span",{style:{fontSize:14,width:28,textAlign:"center",flexShrink:0},children:i}),l.jsxs("div",{style:{flex:1,minWidth:0},children:[l.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"baseline",marginBottom:4},children:[l.jsx("span",{style:{fontSize:13,fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.name}),l.jsxs("span",{style:{fontSize:12,color:gy(e.level),fontWeight:600,flexShrink:0,marginLeft:8},children:["Lv.",e.level]})]}),l.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[l.jsx("div",{style:{flex:1,height:4,background:"rgba(255,255,255,0.08)",borderRadius:2,overflow:"hidden"},children:l.jsx("div",{style:{width:`${e.progress*100}%`,height:"100%",background:gy(e.level),borderRadius:2,transition:"width 0.3s ease"}})}),l.jsx("span",{style:{fontSize:10,color:"rgba(255,255,255,0.4)",flexShrink:0},children:e.formattedTokens})]})]})]})}function gy(e){return e>=20?"#FFD700":e>=10?"#C0A0FF":e>=5?"#4FC3F7":e>=3?"#81C784":"rgba(255,255,255,0.4)"}function d8(e){return e.includes("opus")?"Opus":e.includes("sonnet")?"Sonnet":e.includes("haiku")?"Haiku":e.split("-").slice(0,2).join(" ")}function f8({onClose:e,onSyncComplete:n}){const[a,i]=v.useState([]),[o,u]=v.useState([]),[d,f]=v.useState(!0),[m,h]=v.useState(null),[x,g]=v.useState(new Set),[w,b]=v.useState(null),[j,k]=v.useState(null),E=v.useCallback(async()=>{f(!0),b(null);try{const{roles:N}=await ye.getSyncRoles();i(N);const _=N.filter(z=>z.source.sync!=="off");if(_.length===0){u([]),k(null);return}try{const z=await wr.syncCheck(_.map(R=>({roleId:R.roleId,sourceId:R.source.id,currentVersion:R.source.upstream_version??R.source.forked_at??"0.0.0"})));k(!0);const H=[];for(const R of z.updates){if(!R.hasUpdate)continue;const I=_.find(L=>L.roleId===R.roleId);if(!I)continue;const{character:q}=await wr.syncPull(R.sourceId),X=[];I.persona.trim()!==q.persona.trim()&&X.push({field:"persona",local:I.persona.slice(0,120)+(I.persona.length>120?"...":""),upstream:q.persona.slice(0,120)+(q.persona.length>120?"...":"")});const A=JSON.stringify(I.authority),$=JSON.stringify(q.authority);A!==$&&X.push({field:"authority",local:`${I.authority.autonomous.length} autonomous, ${I.authority.needsApproval.length} approval`,upstream:`${q.authority.autonomous.length} autonomous, ${q.authority.needsApproval.length} approval`}),X.length>0&&H.push({roleId:R.roleId,roleName:I.name,sourceId:R.sourceId,currentVersion:R.currentVersion,latestVersion:R.latestVersion,fields:X})}u(H)}catch{k(!1),u([])}}catch(N){b(N instanceof Error?N.message:"Failed to check for updates")}finally{f(!1)}},[]);v.useEffect(()=>{E()},[E]);const C=async N=>{h(N.roleId);try{const{character:_,version:z}=await wr.syncPull(N.sourceId);await ye.applySyncUpdate({roleId:N.roleId,changes:{persona:_.persona,authority:_.authority},upstreamVersion:z}),g(H=>new Set(H).add(N.roleId)),n==null||n()}catch(_){b(_ instanceof Error?_.message:"Failed to apply update")}finally{h(null)}};return l.jsxs("div",{style:{padding:20,color:"rgba(255,255,255,0.9)",maxHeight:"100%",overflowY:"auto"},children:[l.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:16},children:[l.jsx("h3",{style:{margin:0,fontSize:16,fontWeight:600},children:"Role Sync"}),l.jsxs("div",{style:{display:"flex",gap:8},children:[l.jsx("button",{onClick:E,disabled:d,style:{background:"rgba(255,255,255,0.08)",border:"1px solid rgba(255,255,255,0.1)",color:"rgba(255,255,255,0.7)",borderRadius:6,padding:"4px 10px",fontSize:12,cursor:d?"wait":"pointer"},children:d?"Checking...":"Refresh"}),l.jsx("button",{onClick:e,style:{background:"none",border:"none",color:"rgba(255,255,255,0.5)",cursor:"pointer",fontSize:18},children:"×"})]})]}),j===!1&&l.jsx("div",{style:{padding:"8px 12px",background:"rgba(255,180,0,0.1)",borderRadius:6,color:"#FFB74D",fontSize:12,marginBottom:12},children:"Cloud API unreachable. Sync requires connection to api.tycono.ai."}),w&&l.jsx("div",{style:{padding:"8px 12px",background:"rgba(255,100,100,0.1)",borderRadius:6,color:"#ff6b6b",fontSize:12,marginBottom:12},children:w}),l.jsxs("div",{style:{padding:"10px 14px",background:"rgba(255,255,255,0.04)",borderRadius:8,border:"1px solid rgba(255,255,255,0.06)",marginBottom:16,fontSize:13},children:[l.jsx("span",{style:{color:"rgba(255,255,255,0.5)"},children:"Tracked roles: "}),l.jsx("span",{style:{fontWeight:500},children:a.length}),l.jsx("span",{style:{color:"rgba(255,255,255,0.3)",margin:"0 8px"},children:"·"}),l.jsx("span",{style:{color:"rgba(255,255,255,0.5)"},children:"Updates available: "}),l.jsx("span",{style:{fontWeight:500,color:o.length>0?"#4FC3F7":"rgba(255,255,255,0.7)"},children:o.filter(N=>!x.has(N.roleId)).length}),j===!0&&l.jsxs(l.Fragment,{children:[l.jsx("span",{style:{color:"rgba(255,255,255,0.3)",margin:"0 8px"},children:"·"}),l.jsx("span",{style:{fontSize:11,color:"#81C784"},children:"Cloud connected"})]})]}),o.length===0&&!d&&l.jsx("div",{style:{color:"rgba(255,255,255,0.4)",fontSize:13,padding:"20px 0",textAlign:"center"},children:a.length===0?"No roles with source tracking. Hire from the Store to enable sync.":"All roles are up to date!"}),o.map(N=>l.jsxs("div",{style:{marginBottom:12,padding:14,background:"rgba(255,255,255,0.03)",borderRadius:8,border:"1px solid rgba(255,255,255,0.06)"},children:[l.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:10},children:[l.jsxs("div",{children:[l.jsx("div",{style:{fontSize:14,fontWeight:500},children:N.roleName}),l.jsxs("div",{style:{fontSize:11,color:"rgba(255,255,255,0.4)"},children:[N.sourceId," · v",N.currentVersion," → v",N.latestVersion]})]}),x.has(N.roleId)?l.jsx("span",{style:{fontSize:12,color:"#81C784"},children:"Applied ✓"}):l.jsx("button",{onClick:()=>C(N),disabled:m===N.roleId,style:{background:"#1565C0",border:"none",color:"white",borderRadius:6,padding:"5px 12px",fontSize:12,cursor:m===N.roleId?"wait":"pointer",opacity:m===N.roleId?.6:1},children:m===N.roleId?"Applying...":"Apply Update"})]}),N.fields.map(_=>l.jsxs("div",{style:{marginBottom:6,fontSize:12},children:[l.jsx("div",{style:{color:"rgba(255,255,255,0.5)",marginBottom:2,textTransform:"uppercase",fontSize:10,letterSpacing:.5},children:_.field}),l.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:6},children:[l.jsxs("div",{style:{padding:"4px 8px",background:"rgba(255,100,100,0.08)",borderRadius:4,color:"rgba(255,255,255,0.6)"},children:[l.jsx("span",{style:{fontSize:9,color:"rgba(255,255,255,0.3)"},children:"LOCAL"}),l.jsx("br",{}),_.local]}),l.jsxs("div",{style:{padding:"4px 8px",background:"rgba(100,255,100,0.08)",borderRadius:4,color:"rgba(255,255,255,0.6)"},children:[l.jsx("span",{style:{fontSize:9,color:"rgba(255,255,255,0.3)"},children:"UPSTREAM"}),l.jsx("br",{}),_.upstream]})]})]},_.field))]},N.roleId)),a.length>0&&l.jsxs("div",{style:{marginTop:16,fontSize:11,color:"rgba(255,255,255,0.3)",lineHeight:1.5},children:["Roles hired from the Store are tracked automatically. Set ",l.jsx("code",{style:{background:"rgba(255,255,255,0.06)",padding:"1px 4px",borderRadius:3},children:"sync: off"})," in role.yaml to stop tracking."]})]})}function h8({onClose:e}){const[n,a]=v.useState(null),[i,o]=v.useState(!0),[u,d]=v.useState(null),[f,m]=v.useState(null),h=v.useCallback(async()=>{o(!0),d(null);try{const N=await ye.getGitStatus();a(N)}catch(N){d(N instanceof Error?N.message:"Failed to load git status")}finally{o(!1)}},[]);v.useEffect(()=>{h()},[h]);const x=async N=>{m(N.path);try{await ye.deleteWorktree(N.path),await h()}catch(_){d(_ instanceof Error?_.message:"Failed to remove worktree")}finally{m(null)}},g=async N=>{m(N);try{await ye.deleteBranch(N),await h()}catch(_){d(_ instanceof Error?_.message:"Failed to delete branch")}finally{m(null)}};if(i&&!n)return l.jsx("div",{style:{padding:24,color:"rgba(255,255,255,0.6)"},children:"Loading git status..."});if(u&&!n)return l.jsxs("div",{style:{padding:24,color:"#ff6b6b"},children:[u,l.jsx("button",{onClick:e,style:{marginLeft:12,color:"rgba(255,255,255,0.6)",background:"none",border:"none",cursor:"pointer"},children:"Close"})]});if(!n)return null;const w=n.worktrees.filter(N=>N.status==="active"),b=n.worktrees.filter(N=>N.status==="pending-merge"),j=n.worktrees.filter(N=>N.status==="stale");function k(N){const _=N.split("/");if(_.length>1){const z=_[_.length-1],H=["cto","cbo","pm","engineer","designer","qa","data-analyst"];for(const R of H)if(z.toLowerCase().includes(R))return R}return null}function E(N,_=40){return N.length<=_?N:"..."+N.slice(N.length-_+3)}function C(N){const _=Date.now()-new Date(N).getTime(),z=Math.floor(_/6e4);if(z<1)return"just now";if(z<60)return`${z}m ago`;const H=Math.floor(z/60);return H<24?`${H}h ago`:`${Math.floor(H/24)}d ago`}return l.jsxs("div",{style:{padding:20,color:"rgba(255,255,255,0.9)",maxHeight:"100%",overflowY:"auto"},children:[l.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:16},children:[l.jsx("h3",{style:{margin:0,fontSize:16,fontWeight:600},children:"GIT STATUS"}),l.jsxs("div",{style:{display:"flex",gap:8},children:[l.jsx("button",{onClick:h,disabled:i,style:{background:"rgba(255,255,255,0.08)",border:"1px solid rgba(255,255,255,0.1)",color:"rgba(255,255,255,0.7)",borderRadius:6,padding:"4px 10px",fontSize:12,cursor:i?"wait":"pointer"},children:i?"Checking...":"Refresh"}),l.jsx("button",{onClick:e,style:{background:"none",border:"none",color:"rgba(255,255,255,0.5)",cursor:"pointer",fontSize:18},children:"×"})]})]}),u&&l.jsx("div",{style:{padding:"8px 12px",background:"rgba(255,100,100,0.1)",borderRadius:6,color:"#ff6b6b",fontSize:12,marginBottom:12},children:u}),l.jsxs("div",{style:{padding:"10px 14px",background:"rgba(255,255,255,0.04)",borderRadius:8,border:"1px solid rgba(255,255,255,0.06)",marginBottom:16,fontSize:13},children:[l.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[l.jsxs("div",{children:[l.jsx("span",{style:{color:"rgba(255,255,255,0.5)"},children:"Branch: "}),l.jsx("span",{style:{fontWeight:500},children:n.currentBranch})]}),l.jsx("div",{children:n.unsavedCount>0&&l.jsxs("span",{style:{color:"#FFB74D",fontSize:12},children:[n.unsavedCount," unsaved"]})})]}),n.lastCommit&&l.jsxs("div",{style:{marginTop:6,fontSize:11,color:"rgba(255,255,255,0.4)"},children:["Last commit: ",n.lastCommit.message.slice(0,60),n.lastCommit.message.length>60?"...":""," · ",C(n.lastCommit.date)]})]}),w.length>0&&l.jsxs(l.Fragment,{children:[l.jsx(Cu,{label:"Active Worktrees",count:w.length}),w.map(N=>l.jsx(Hh,{wt:N,roleFromBranch:N.roleId||k(N.branch),truncatePath:E,timeAgo:C,removing:f===N.path,onRemove:()=>x(N),statusColor:"#4FC3F7",statusIcon:"📂"},N.path))]}),b.length>0&&l.jsxs(l.Fragment,{children:[l.jsx(Cu,{label:"Pending Merge",count:b.length}),b.map(N=>l.jsx(Hh,{wt:N,roleFromBranch:N.roleId||k(N.branch),truncatePath:E,timeAgo:C,removing:f===N.path,onRemove:()=>x(N),statusColor:"#FFB74D",statusIcon:"⚠️"},N.path))]}),j.length>0&&l.jsxs(l.Fragment,{children:[l.jsx(Cu,{label:"Stale",count:j.length}),j.map(N=>l.jsx(Hh,{wt:N,roleFromBranch:N.roleId||k(N.branch),truncatePath:E,timeAgo:C,removing:f===N.path,onRemove:()=>x(N),statusColor:"#ff6b6b",statusIcon:"🔴"},N.path))]}),n.staleBranches.length>0&&l.jsxs(l.Fragment,{children:[l.jsx(Cu,{label:"Unmerged Branches",count:n.staleBranches.length}),n.staleBranches.map(N=>l.jsxs("div",{style:{marginBottom:8,padding:"10px 14px",background:"rgba(255,255,255,0.03)",borderRadius:8,border:"1px solid rgba(255,255,255,0.06)",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[l.jsxs("div",{style:{fontSize:13},children:[l.jsx("span",{style:{color:"rgba(255,255,255,0.5)",marginRight:6},children:"⚠️"}),l.jsx("span",{style:{fontWeight:500},children:N})]}),l.jsx("button",{onClick:()=>g(N),disabled:f===N,style:{background:"rgba(255,100,100,0.15)",border:"1px solid rgba(255,100,100,0.2)",color:"#ff6b6b",borderRadius:4,padding:"3px 8px",fontSize:10,cursor:f===N?"wait":"pointer",opacity:f===N?.6:1,fontWeight:600,textTransform:"uppercase",letterSpacing:.5},children:f===N?"...":"DELETE"})]},N))]}),w.length===0&&b.length===0&&j.length===0&&n.staleBranches.length===0&&l.jsxs("div",{style:{color:"rgba(255,255,255,0.4)",fontSize:13,padding:"20px 0",textAlign:"center"},children:["✓"," All clean. No active worktrees or stale branches."]}),n.lastMerge&&l.jsxs("div",{style:{marginTop:16,fontSize:11,color:"rgba(255,255,255,0.3)",lineHeight:1.5},children:["Last merge: ",l.jsx("span",{style:{color:"rgba(255,255,255,0.5)"},children:n.lastMerge.branch})," · ",n.lastMerge.roleId," · ",C(n.lastMerge.mergedAt)]})]})}function Cu({label:e,count:n}){return l.jsxs("h4",{style:{margin:"16px 0 8px",fontSize:11,fontWeight:600,color:"rgba(255,255,255,0.5)",textTransform:"uppercase",letterSpacing:1},children:[e," (",n,")"]})}function Hh({wt:e,roleFromBranch:n,truncatePath:a,timeAgo:i,removing:o,onRemove:u,statusColor:d,statusIcon:f}){return l.jsx("div",{style:{marginBottom:8,padding:"10px 14px",background:"rgba(255,255,255,0.03)",borderRadius:8,border:"1px solid rgba(255,255,255,0.06)"},children:l.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"flex-start"},children:[l.jsxs("div",{style:{flex:1,minWidth:0},children:[l.jsxs("div",{style:{fontSize:13,fontWeight:500,marginBottom:2},children:[l.jsx("span",{style:{marginRight:6},children:f}),e.branch,n&&l.jsx("span",{style:{marginLeft:8,fontSize:10,padding:"1px 6px",background:"rgba(255,255,255,0.08)",borderRadius:3,color:"rgba(255,255,255,0.6)",textTransform:"uppercase"},children:n})]}),e.task&&l.jsxs("div",{style:{fontSize:11,color:"rgba(255,255,255,0.5)",marginBottom:2},children:['"',e.task.slice(0,50),e.task.length>50?"...":"",'"']}),l.jsxs("div",{style:{fontSize:10,color:"rgba(255,255,255,0.35)"},children:[a(e.path)," · ",e.filesChanged," file",e.filesChanged!==1?"s":""," changed"," · ",i(e.createdAt)]}),e.conflictFiles&&e.conflictFiles.length>0&&l.jsxs("div",{style:{fontSize:10,color:"#ff6b6b",marginTop:4},children:["⛔"," CONFLICT: ",e.conflictFiles.join(", ")]})]}),l.jsx("button",{onClick:u,disabled:o,style:{background:"rgba(255,100,100,0.15)",border:"1px solid rgba(255,100,100,0.2)",color:d,borderRadius:4,padding:"3px 8px",fontSize:10,cursor:o?"wait":"pointer",opacity:o?.6:1,fontWeight:600,textTransform:"uppercase",letterSpacing:.5,flexShrink:0,marginLeft:8},children:o?"...":"REMOVE"})]})})}function m8({onClose:e}){const[n,a]=v.useState(null),[i,o]=v.useState(!0),[u,d]=v.useState(null),[f,m]=v.useState(null),h=v.useCallback(async()=>{o(!0),d(null);try{const k=await ye.getActiveSessions();a(k)}catch(k){d(k instanceof Error?k.message:"Failed to load sessions")}finally{o(!1)}},[]);v.useEffect(()=>{h();const k=setInterval(h,1e4);return()=>clearInterval(k)},[h]);const x=async k=>{m(k);try{await ye.deleteActiveSession(k),await h()}catch(E){d(E instanceof Error?E.message:"Failed to remove session")}finally{m(null)}},g=async()=>{try{await ye.cleanupActiveSessions(),await h()}catch(k){d(k instanceof Error?k.message:"Failed to cleanup sessions")}};if(i&&!n)return l.jsx("div",{style:{padding:24,color:"rgba(255,255,255,0.6)"},children:"Loading sessions..."});if(u&&!n)return l.jsxs("div",{style:{padding:24,color:"#ff6b6b"},children:[u,l.jsx("button",{onClick:e,style:{marginLeft:12,color:"rgba(255,255,255,0.6)",background:"none",border:"none",cursor:"pointer"},children:"Close"})]});if(!n)return null;const w=n.sessions.filter(k=>k.status==="active"),b=n.sessions.filter(k=>k.status==="idle"),j=n.sessions.filter(k=>k.status==="dead");return l.jsxs("div",{style:{padding:20,color:"rgba(255,255,255,0.9)",maxHeight:"100%",overflowY:"auto"},children:[l.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:16},children:[l.jsx("h3",{style:{margin:0,fontSize:16,fontWeight:600},children:"ACTIVE SESSIONS"}),l.jsxs("div",{style:{display:"flex",gap:8},children:[j.length>0&&l.jsx("button",{onClick:g,style:{background:"rgba(255,180,100,0.15)",border:"1px solid rgba(255,180,100,0.2)",color:"#FFB74D",borderRadius:6,padding:"4px 10px",fontSize:12,cursor:"pointer"},children:"Cleanup Dead"}),l.jsx("button",{onClick:h,disabled:i,style:{background:"rgba(255,255,255,0.08)",border:"1px solid rgba(255,255,255,0.1)",color:"rgba(255,255,255,0.7)",borderRadius:6,padding:"4px 10px",fontSize:12,cursor:i?"wait":"pointer"},children:i?"Checking...":"Refresh"}),l.jsx("button",{onClick:e,style:{background:"none",border:"none",color:"rgba(255,255,255,0.5)",cursor:"pointer",fontSize:18},children:"×"})]})]}),u&&l.jsx("div",{style:{padding:"8px 12px",background:"rgba(255,100,100,0.1)",borderRadius:6,color:"#ff6b6b",fontSize:12,marginBottom:12},children:u}),l.jsxs("div",{style:{padding:"10px 14px",background:"rgba(255,255,255,0.04)",borderRadius:8,border:"1px solid rgba(255,255,255,0.06)",marginBottom:16,fontSize:13,display:"flex",justifyContent:"space-between"},children:[l.jsxs("div",{children:[l.jsx("span",{style:{color:"rgba(255,255,255,0.5)"},children:"Sessions: "}),l.jsx("span",{style:{fontWeight:500},children:n.summary.active})]}),l.jsxs("div",{children:[l.jsx("span",{style:{color:"rgba(255,255,255,0.5)"},children:"Ports in use: "}),l.jsx("span",{style:{fontWeight:500},children:n.summary.totalPorts})]})]}),w.length>0&&l.jsxs(l.Fragment,{children:[l.jsx(Uh,{label:"Active",count:w.length}),w.map(k=>l.jsx(qh,{session:k,removing:f===k.sessionId,onRemove:()=>x(k.sessionId),statusColor:"#4FC3F7"},k.sessionId))]}),b.length>0&&l.jsxs(l.Fragment,{children:[l.jsx(Uh,{label:"Idle",count:b.length}),b.map(k=>l.jsx(qh,{session:k,removing:f===k.sessionId,onRemove:()=>x(k.sessionId),statusColor:"#FFB74D"},k.sessionId))]}),j.length>0&&l.jsxs(l.Fragment,{children:[l.jsx(Uh,{label:"Dead",count:j.length}),j.map(k=>l.jsx(qh,{session:k,removing:f===k.sessionId,onRemove:()=>x(k.sessionId),statusColor:"#ff6b6b"},k.sessionId))]}),n.sessions.length===0&&l.jsx("div",{style:{color:"rgba(255,255,255,0.4)",fontSize:13,padding:"20px 0",textAlign:"center"},children:"No active sessions. Sessions appear when jobs run with port allocation."})]})}function Uh({label:e,count:n}){return l.jsxs("h4",{style:{margin:"16px 0 8px",fontSize:11,fontWeight:600,color:"rgba(255,255,255,0.5)",textTransform:"uppercase",letterSpacing:1},children:[e," (",n,")"]})}function p8(e){const n=Date.now()-new Date(e).getTime(),a=Math.floor(n/6e4);if(a<1)return"just now";if(a<60)return`${a}m ago`;const i=Math.floor(a/60);return i<24?`${i}h ago`:`${Math.floor(i/24)}d ago`}function qh({session:e,removing:n,onRemove:a,statusColor:i}){const{ports:o}=e;return l.jsx("div",{style:{marginBottom:8,padding:"10px 14px",background:"rgba(255,255,255,0.03)",borderRadius:8,border:"1px solid rgba(255,255,255,0.06)"},children:l.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"flex-start"},children:[l.jsxs("div",{style:{flex:1,minWidth:0},children:[l.jsxs("div",{style:{fontSize:13,fontWeight:500,marginBottom:2},children:[l.jsx("span",{style:{display:"inline-block",width:8,height:8,borderRadius:"50%",backgroundColor:i,marginRight:8,verticalAlign:"middle"}}),l.jsx("span",{style:{textTransform:"uppercase"},children:e.roleName||e.roleId}),e.jobStatus&&l.jsx("span",{style:{marginLeft:8,fontSize:10,padding:"1px 6px",background:"rgba(255,255,255,0.08)",borderRadius:3,color:"rgba(255,255,255,0.6)"},children:e.jobStatus})]}),e.task&&l.jsxs("div",{style:{fontSize:11,color:"rgba(255,255,255,0.5)",marginBottom:4},children:['"',e.task.slice(0,60),e.task.length>60?"...":"",'"']}),l.jsxs("div",{style:{fontSize:11,display:"flex",gap:8,marginBottom:2},children:[l.jsxs("span",{style:{color:"#81C784"},children:["API:",o.api||"?"]}),l.jsxs("span",{style:{color:"#64B5F6"},children:["Vite:",o.vite||"?"]}),o.hmr&&l.jsxs("span",{style:{color:"#FFB74D"},children:["HMR:",o.hmr]})]}),l.jsxs("div",{style:{fontSize:10,color:"rgba(255,255,255,0.35)"},children:[e.sessionId.slice(0,12),"...",e.worktreePath&&l.jsxs(l.Fragment,{children:[" · ",x8(e.worktreePath)]}),e.pid&&l.jsxs(l.Fragment,{children:[" · ","PID:",e.pid]})," · ",p8(e.startedAt)]})]}),l.jsx("button",{onClick:a,disabled:n,style:{background:"rgba(255,100,100,0.15)",border:"1px solid rgba(255,100,100,0.2)",color:"#ff6b6b",borderRadius:4,padding:"3px 8px",fontSize:10,cursor:n?"wait":"pointer",opacity:n?.6:1,fontWeight:600,textTransform:"uppercase",letterSpacing:.5,flexShrink:0,marginLeft:8},children:n?"...":"STOP"})]})})}function x8(e,n=35){return e.length<=n?e:"..."+e.slice(e.length-n+3)}function g8({onClose:e,speechSettings:n,onSpeechSettingsChange:a,language:i,onLanguageChange:o,onOpenSync:u,onOpenGitStatus:d,onOpenSessions:f,onOpenStats:m}){var oe;const[h,x]=v.useState(null),[g,w]=v.useState(null),[b,j]=v.useState(!1),[k,E]=v.useState(!1),[C,N]=v.useState(!1),[_,z]=v.useState(null),[H,R]=v.useState(""),[I,q]=v.useState(!1),[X,A]=v.useState(!1),[$,L]=v.useState(null),[Y,se]=v.useState(!1);v.useEffect(()=>{ye.getPreferences().then(async de=>{const V=de;if(x(V.instanceId??null),V.instanceId)try{const{name:D}=await wr.getMyName(V.instanceId);w(D)}catch{}}).catch(()=>{}),ye.getCodeRoot().then(({codeRoot:de})=>{z(de),de&&R(de)}).catch(()=>{})},[]);const ee=async()=>{N(!0);try{const V=await(await fetch("/api/preferences/regenerate-token",{method:"POST"})).json();V.ok&&(x(V.newInstanceId),E(!1))}catch{}N(!1)},W=()=>{h&&navigator.clipboard.writeText(h).then(()=>{j(!0),setTimeout(()=>j(!1),2e3)})};return l.jsx("div",{className:"customize-overlay",onClick:e,children:l.jsxs("div",{className:"customize-modal",onClick:de=>de.stopPropagation(),style:{maxWidth:480},children:[l.jsxs("div",{className:"customize-header",children:[l.jsx("div",{style:{fontSize:12,fontWeight:700,letterSpacing:1,color:"var(--terminal-text)"},children:"SETTINGS"}),l.jsx("button",{className:"customize-close",onClick:e,children:"X"})]}),l.jsx("div",{className:"customize-body",style:{padding:"12px 20px 20px"},children:l.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:20},children:[l.jsxs("div",{children:[l.jsx("div",{style:{fontSize:11,fontWeight:600,marginBottom:8,color:"var(--terminal-text)"},children:"AMBIENT SPEECH MODE"}),l.jsx("div",{style:{display:"flex",gap:6},children:["template","llm","auto"].map(de=>l.jsxs("button",{onClick:()=>a==null?void 0:a({mode:de}),style:{flex:1,padding:"8px 12px",fontSize:11,border:`2px solid ${(n==null?void 0:n.mode)===de?"var(--accent)":"rgba(255,255,255,0.1)"}`,background:(n==null?void 0:n.mode)===de?"rgba(255,255,255,0.08)":"transparent",color:(n==null?void 0:n.mode)===de?"var(--terminal-text)":"var(--terminal-text-muted)",borderRadius:6,cursor:"pointer",textAlign:"center"},children:[l.jsx("div",{style:{fontWeight:600,marginBottom:2},children:de==="template"?"TEMPLATE":de==="llm"?"AI":"AUTO"}),l.jsx("div",{style:{fontSize:9,opacity:.7},children:de==="template"?"Static pool ($0)":de==="llm"?"LLM generated":"Detect engine"})]},de))}),l.jsx("div",{style:{fontSize:9,color:"var(--terminal-text-muted)",marginTop:4},children:"Auto: CLI Max = AI, BYOK = Template"})]}),l.jsxs("div",{children:[l.jsxs("div",{style:{fontSize:11,fontWeight:600,marginBottom:8,color:"var(--terminal-text)"},children:["SPEECH INTERVAL: ",(n==null?void 0:n.intervalSec)??18,"s"]}),l.jsx("input",{type:"range",min:5,max:120,step:5,value:(n==null?void 0:n.intervalSec)??18,onChange:de=>a==null?void 0:a({intervalSec:Number(de.target.value)}),style:{width:"100%",accentColor:"var(--accent)"}}),l.jsxs("div",{style:{display:"flex",justifyContent:"space-between",fontSize:9,color:"var(--terminal-text-muted)"},children:[l.jsx("span",{children:"5s (frequent)"}),l.jsx("span",{children:"120s (rare)"})]})]}),(n==null?void 0:n.mode)!=="template"&&l.jsxs("div",{children:[l.jsxs("div",{style:{fontSize:11,fontWeight:600,marginBottom:8,color:"var(--terminal-text)"},children:["DAILY LLM BUDGET: $",((oe=n==null?void 0:n.dailyBudgetUsd)==null?void 0:oe.toFixed(2))??"1.00"]}),l.jsx("input",{type:"range",min:0,max:5,step:.25,value:(n==null?void 0:n.dailyBudgetUsd)??1,onChange:de=>a==null?void 0:a({dailyBudgetUsd:Number(de.target.value)}),style:{width:"100%",accentColor:"var(--accent)"}}),l.jsxs("div",{style:{display:"flex",justifyContent:"space-between",fontSize:9,color:"var(--terminal-text-muted)"},children:[l.jsx("span",{children:"$0 (unlimited)"}),l.jsx("span",{children:"$5.00/day"})]})]}),l.jsxs("div",{children:[l.jsx("div",{style:{fontSize:11,fontWeight:600,marginBottom:8,color:"var(--terminal-text)"},children:"LANGUAGE"}),l.jsx("div",{style:{display:"flex",gap:6},children:[{key:"auto",label:"Auto"},{key:"en",label:"English"},{key:"ko",label:"한국어"},{key:"ja",label:"日本語"}].map(({key:de,label:V})=>l.jsx("button",{onClick:()=>o==null?void 0:o(de),style:{flex:1,padding:"8px 12px",fontSize:11,border:`2px solid ${(i??"auto")===de?"var(--accent)":"rgba(255,255,255,0.1)"}`,background:(i??"auto")===de?"rgba(255,255,255,0.08)":"transparent",color:(i??"auto")===de?"var(--terminal-text)":"var(--terminal-text-muted)",borderRadius:6,cursor:"pointer",textAlign:"center",fontWeight:600},children:V},de))}),l.jsx("div",{style:{fontSize:9,color:"var(--terminal-text-muted)",marginTop:4},children:"Sets language for AI responses and speech bubbles"})]}),l.jsxs("div",{children:[l.jsx("div",{style:{fontSize:11,fontWeight:600,marginBottom:8,color:"var(--terminal-text)"},children:"CODE REPOSITORY"}),I?l.jsxs("div",{children:[l.jsxs("div",{style:{display:"flex",gap:6},children:[l.jsx("input",{type:"text",value:H,onChange:de=>{R(de.target.value),L(null)},placeholder:"/path/to/code/repo",style:{flex:1,padding:"8px 10px",fontSize:11,background:"rgba(255,255,255,0.04)",border:"1px solid rgba(255,255,255,0.15)",borderRadius:6,color:"var(--terminal-text)",fontFamily:"monospace",outline:"none"},autoFocus:!0}),l.jsx("button",{onClick:async()=>{if(H.trim()){A(!0),L(null);try{const de=await ye.setCodeRoot(H.trim());z(de.codeRoot),R(de.codeRoot),q(!1),se(!0),setTimeout(()=>se(!1),3e3)}catch(de){L(de instanceof Error?de.message:"Failed to set code root")}finally{A(!1)}}},disabled:X||!H.trim(),style:{padding:"8px 12px",fontSize:10,fontWeight:600,background:"var(--accent)",border:"none",color:"#fff",borderRadius:6,cursor:"pointer",opacity:X||!H.trim()?.5:1},children:X?"...":"Save"}),l.jsx("button",{onClick:()=>{q(!1),R(_||""),L(null)},style:{padding:"8px 10px",fontSize:10,background:"transparent",border:"1px solid rgba(255,255,255,0.1)",color:"var(--terminal-text-muted)",borderRadius:6,cursor:"pointer"},children:"Cancel"})]}),$&&l.jsx("div",{style:{fontSize:9,color:"#ff6b6b",marginTop:4},children:$})]}):l.jsxs("div",{style:{display:"flex",gap:6,alignItems:"center"},children:[l.jsx("code",{style:{flex:1,padding:"8px 10px",fontSize:10,background:"rgba(255,255,255,0.04)",border:"1px solid rgba(255,255,255,0.1)",borderRadius:6,color:_?"var(--terminal-text)":"var(--terminal-text-muted)",fontFamily:"monospace",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:_||"Not configured"}),l.jsx("button",{onClick:()=>{q(!0),L(null),se(!1)},style:{padding:"8px 12px",fontSize:10,fontWeight:600,border:"2px solid rgba(255,255,255,0.1)",background:"transparent",color:"var(--terminal-text-muted)",borderRadius:6,cursor:"pointer"},children:"Change"})]}),Y&&l.jsx("div",{style:{fontSize:9,color:"#4ade80",marginTop:4},children:"Code repository updated!"}),l.jsx("div",{style:{fontSize:9,color:"var(--terminal-text-muted)",marginTop:4},children:"Path to your code repository (separate from AKB). If not set, auto-created as ../[company]-code/ when AI starts working."})]}),h&&l.jsxs("div",{children:[l.jsx("div",{style:{fontSize:11,fontWeight:600,marginBottom:8,color:"var(--terminal-text)"},children:"STORE TOKEN"}),l.jsxs("div",{style:{display:"flex",gap:6,alignItems:"center"},children:[l.jsx("code",{style:{flex:1,padding:"8px 10px",fontSize:10,background:"rgba(255,255,255,0.04)",border:"1px solid rgba(255,255,255,0.1)",borderRadius:6,color:"var(--terminal-text-muted)",fontFamily:"monospace",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:h}),l.jsx("button",{onClick:W,style:{padding:"8px 12px",fontSize:10,fontWeight:600,border:"2px solid rgba(255,255,255,0.1)",background:"transparent",color:b?"#4ade80":"var(--terminal-text-muted)",borderRadius:6,cursor:"pointer",whiteSpace:"nowrap"},children:b?"Copied!":"Copy"})]}),l.jsx("div",{style:{fontSize:9,color:"var(--terminal-text-muted)",marginTop:4},children:"Use this token to sign in on the web Store. Keep it secret — anyone with this token can act as you."}),l.jsx("div",{style:{marginTop:6},children:k?l.jsxs("div",{style:{background:"rgba(255,50,50,0.08)",border:"1px solid rgba(255,50,50,0.2)",borderRadius:6,padding:"8px 10px"},children:[l.jsx("div",{style:{fontSize:9,color:"rgba(255,100,100,0.8)",marginBottom:6},children:"This will invalidate your current token. Published characters will lose ownership. No migration."}),l.jsxs("div",{style:{display:"flex",gap:6},children:[l.jsx("button",{onClick:ee,disabled:C,style:{padding:"4px 12px",fontSize:9,fontWeight:700,border:"1px solid rgba(255,50,50,0.4)",background:"rgba(255,50,50,0.15)",color:"#ff6464",borderRadius:4,cursor:"pointer"},children:C?"...":"Confirm Regenerate"}),l.jsx("button",{onClick:()=>E(!1),style:{padding:"4px 12px",fontSize:9,border:"none",background:"transparent",color:"var(--terminal-text-muted)",cursor:"pointer"},children:"Cancel"})]})]}):l.jsx("button",{onClick:()=>E(!0),style:{padding:"4px 10px",fontSize:9,fontWeight:600,border:"1px solid rgba(255,100,100,0.2)",background:"transparent",color:"rgba(255,100,100,0.6)",borderRadius:4,cursor:"pointer"},children:"Regenerate Token"})})]}),l.jsxs("div",{style:{borderTop:"1px solid rgba(255,255,255,0.08)",paddingTop:16,display:"flex",gap:8},children:[u&&l.jsx("button",{onClick:()=>{e(),u()},className:"theme-btn",style:{flex:1,padding:"8px 12px",fontSize:10},children:"🔄 ROLE SYNC"}),d&&l.jsx("button",{onClick:()=>{e(),d()},className:"theme-btn",style:{flex:1,padding:"8px 12px",fontSize:10},children:"📂 GIT STATUS"}),f&&l.jsx("button",{onClick:()=>{e(),f()},className:"theme-btn",style:{flex:1,padding:"8px 12px",fontSize:10},children:"🖥 SESSIONS"}),m&&l.jsx("button",{onClick:()=>{e(),m()},className:"theme-btn",style:{flex:1,padding:"8px 12px",fontSize:10},children:"📊 COMPANY STATS"}),l.jsx("button",{onClick:()=>window.open("https://tycono.ai/store.html","_blank"),className:"theme-btn",style:{flex:1,padding:"8px 12px",fontSize:10},children:"🌐 WEB STORE"})]}),g&&l.jsx("div",{style:{textAlign:"center",marginTop:-8},children:l.jsx("a",{href:`https://tycono.ai/profile.html?u=${encodeURIComponent(g)}`,target:"_blank",rel:"noopener noreferrer",style:{fontSize:10,color:"var(--terminal-text-muted)",textDecoration:"none"},onMouseEnter:de=>de.currentTarget.style.color="var(--accent)",onMouseLeave:de=>de.currentTarget.style.color="var(--terminal-text-muted)",children:"View public profile →"})})]})})]})})}function y8({theme:e,onThemeChange:n,onClose:a}){const i=v.useRef(null);return v.useEffect(()=>{const o=u=>{i.current&&!i.current.contains(u.target)&&a()};return document.addEventListener("mousedown",o),()=>document.removeEventListener("mousedown",o)},[a]),l.jsx("div",{ref:i,className:"theme-dropup",children:Object.entries(ll).map(([o,u])=>l.jsxs("button",{className:`theme-dropup__item${e===o?" theme-dropup__item--active":""}`,onClick:()=>{n(o),a()},title:u.name,children:[l.jsxs("span",{className:"theme-dropup__swatch",style:{background:u.vars["--hud-bg"],borderColor:u.vars["--pixel-border"]},children:[l.jsx("span",{style:{background:u.vars["--accent"],width:5,height:5,borderRadius:1}}),l.jsx("span",{style:{background:u.vars["--active-green"],width:5,height:5,borderRadius:1}}),l.jsx("span",{style:{background:u.vars["--idle-amber"],width:5,height:5,borderRadius:1}})]}),l.jsx("span",{className:"theme-dropup__name",children:u.icon})]},o))})}const vs={cto:"#1565C0",cbo:"#E65100",pm:"#2E7D32",engineer:"#4A148C",designer:"#AD1457",qa:"#00695C","data-analyst":"#0277BD"};function b8({roles:e,roleStatuses:n,activeExecs:a,sessions:i,knowledgeDocs:o,roleLevels:u,companyName:d,getAppearance:f,waveCenterWaves:m,renderProfile:h,channel:x,onChannelChange:g,onClose:w,children:b}){const[j,k]=v.useState(!1),E=m.filter(I=>I.rootJobs.some(q=>{const X=n[q.roleId];return X==="working"||X==="thinking"})),C=[...e].sort((I,q)=>I.level==="c-level"&&q.level!=="c-level"?-1:I.level!=="c-level"&&q.level==="c-level"?1:I.name.localeCompare(q.name)),N=e.filter(I=>n[I.id]==="working").length,_=i.filter(I=>I.status==="active").length,z=x.type==="role"?e.find(I=>I.id===x.roleId):null,H=x.type==="dashboard"?"Dashboard":x.type==="terminal"?"Chats":x.type==="wave"?"Wave Center":x.type==="knowledge"?"Knowledge Base":x.type==="operations"?"Operations":x.type==="role"?(z==null?void 0:z.name)??x.roleId:"Dashboard",R=x.type==="terminal"?`${_} active sessions`:x.type==="wave"?`${E.length} running`:x.type==="knowledge"?`${o.length} documents`:x.type==="role"?(z==null?void 0:z.level)==="c-level"?"C-Level":"Team member":`${N} working · ${e.length} total`;return l.jsxs("div",{className:"fixed inset-0 z-[60] flex",style:{background:"var(--terminal-bg, #1C1612)"},children:[l.jsxs("div",{className:"flex flex-col shrink-0 overflow-y-auto",style:{width:240,borderRight:"1px solid var(--terminal-border, #2E261F)",background:"var(--terminal-surface, #1a1510)"},children:[l.jsxs("div",{className:"px-4 py-3 flex items-center gap-2 shrink-0",style:{borderBottom:"1px solid var(--terminal-border, #2E261F)"},children:[l.jsx("span",{className:"text-[11px] font-bold tracking-wider flex-1",style:{color:"var(--terminal-text, #fff5eb)",fontFamily:"var(--pixel-font)"},children:d}),N>0&&l.jsxs("span",{className:"text-[9px] px-1.5 py-0.5 rounded-full animate-pulse",style:{background:"#4CAF5020",color:"#4CAF50"},children:[N," live"]})]}),E.length>0&&l.jsxs("button",{className:"mx-3 mt-3 px-3 py-2.5 rounded-lg text-left transition-all hover:opacity-90",style:{background:x.type==="wave"?"#EF444420":"#EF444410",border:"1px solid #EF444430"},onClick:()=>g({type:"wave"}),children:[l.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[l.jsxs("span",{className:"text-[10px] font-bold truncate flex-1",style:{color:"#EF4444"},children:["⚡"," ",E[0].directive.slice(0,28)]}),l.jsx("span",{className:"text-[7px] px-1.5 py-0.5 rounded font-bold shrink-0",style:{background:"#EF4444",color:"#fff"},children:"LIVE"})]}),l.jsxs("div",{className:"text-[9px]",style:{color:"var(--terminal-text-muted)"},children:[E[0].rootJobs.filter(I=>{const q=n[I.roleId];return q==="working"||q==="thinking"}).length,"/",E[0].rootJobs.length," roles working"]})]}),l.jsxs("div",{className:"mx-3 mt-3 grid grid-cols-2 gap-1.5",children:[l.jsx(Eu,{icon:"💬",label:"Chats",badge:_||void 0,active:x.type==="terminal",onClick:()=>g({type:"terminal"})}),l.jsx(Eu,{icon:"⚡",label:"Waves",live:E.length>0,active:x.type==="wave",onClick:()=>g({type:"wave"})}),l.jsx(Eu,{icon:"📋",label:"Decisions",active:x.type==="operations",onClick:()=>g({type:"operations"})}),l.jsx(Eu,{icon:"📚",label:"Knowledge",badge:o.length||void 0,active:x.type==="knowledge",onClick:()=>g({type:"knowledge"})})]}),l.jsxs("div",{className:"mt-4",children:[l.jsx("div",{className:"px-4 py-1 text-[9px] font-bold tracking-widest",style:{color:"var(--terminal-text-muted)"},children:"TEAM"}),C.map(I=>{var Y;const q=n[I.id],X=a.find(se=>se.roleId===I.id),A=vs[I.id]??"#666",$=(Y=u[I.id])==null?void 0:Y.level,L=x.type==="role"&&x.roleId===I.id;return l.jsxs("button",{onClick:()=>g({type:"role",roleId:I.id}),className:"flex items-center gap-2.5 w-full px-4 py-1.5 text-left hover:opacity-80 transition-all",style:{background:L?`${A}18`:"transparent",borderLeft:L?`2px solid ${A}`:"2px solid transparent"},children:[l.jsxs("div",{className:"relative shrink-0",style:{width:22,height:22},children:[l.jsx(Ul,{roleId:I.id,appearance:f(I.id),scale:1.3}),l.jsx("span",{className:"absolute -bottom-0.5 -right-0.5 w-2 h-2 rounded-full",style:{background:q==="working"?"#4CAF50":q==="idle"?"#FFC107":"#9E9E9E",border:"1.5px solid var(--terminal-surface, #1a1510)"}})]}),l.jsxs("div",{className:"min-w-0 flex-1",children:[l.jsxs("div",{className:"text-[11px] truncate",style:{color:"var(--terminal-text, #fff5eb)"},children:[I.name,$!=null&&l.jsxs("span",{className:"ml-1 opacity-40 text-[8px]",children:["Lv.",$]})]}),X?l.jsx("div",{className:"text-[9px] truncate",style:{color:A},children:X.task.slice(0,28)}):l.jsx("div",{className:"text-[9px]",style:{color:"var(--terminal-text-muted, #887766)"},children:I.level==="c-level"?I.id.toUpperCase():I.id})]}),q==="working"&&l.jsx("span",{className:"w-1.5 h-1.5 rounded-full animate-pulse shrink-0",style:{background:A}})]},I.id)})]}),l.jsx("div",{className:"flex-1"}),a.length>0&&l.jsxs("div",{className:"shrink-0 px-3 pb-2",style:{borderTop:"1px solid var(--terminal-border, #2E261F)"},children:[l.jsxs("div",{className:"px-1 py-1.5 text-[8px] font-bold tracking-widest",style:{color:"var(--terminal-text-muted)"},children:["ACTIVE JOBS (",a.length,")"]}),l.jsx("div",{className:"space-y-0.5 max-h-[140px] overflow-y-auto",children:a.map(I=>{const q=e.find($=>$.id===I.roleId),X=vs[I.roleId]??"#666",A=x.type==="role"&&x.roleId===I.roleId;return l.jsxs("button",{onClick:()=>g({type:"role",roleId:I.roleId}),className:"flex items-center gap-2 w-full px-2 py-1.5 rounded text-left hover:opacity-80 transition-all",style:{background:A?`${X}18`:"transparent"},children:[l.jsx("span",{className:"w-1.5 h-1.5 rounded-full animate-pulse shrink-0",style:{background:X}}),l.jsxs("div",{className:"min-w-0 flex-1",children:[l.jsx("div",{className:"text-[10px] truncate",style:{color:"var(--terminal-text, #fff5eb)"},children:(q==null?void 0:q.name)??I.roleId}),l.jsx("div",{className:"text-[8px] truncate",style:{color:"var(--terminal-text-muted)"},children:I.task.slice(0,40)})]})]},I.jobId??I.roleId)})})]}),l.jsx("div",{className:"px-3 py-3 shrink-0",style:{borderTop:"1px solid var(--terminal-border, #2E261F)"},children:l.jsxs("button",{onClick:w,className:"flex items-center gap-2 w-full px-3 py-2.5 rounded-lg hover:opacity-80 transition-opacity",style:{background:"var(--terminal-border, #2E261F)",color:"var(--terminal-text, #fff5eb)"},children:[l.jsx("span",{className:"text-[12px]",children:"🏢"}),l.jsx("span",{className:"text-[11px] font-medium",children:"Office"})]})})]}),l.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden",children:[l.jsxs("div",{className:"px-5 py-3 flex items-center gap-3 shrink-0",style:{borderBottom:"1px solid var(--terminal-border, #2E261F)"},children:[x.type==="role"&&z&&l.jsxs("button",{onClick:()=>k(I=>!I),className:"relative shrink-0 rounded-lg overflow-hidden hover:opacity-80 transition-opacity cursor-pointer",style:{width:28,height:28,background:`${vs[z.id]??"#666"}30`},title:"View profile",children:[l.jsx(Ul,{roleId:z.id,appearance:f(z.id),scale:1.5}),l.jsx("span",{className:"absolute -bottom-0.5 -right-0.5 w-2.5 h-2.5 rounded-full",style:{background:n[z.id]==="working"?"#4CAF50":n[z.id]==="idle"?"#FFC107":"#9E9E9E",border:"2px solid var(--terminal-bg, #1C1612)"}})]}),l.jsx("span",{className:"text-[15px] font-semibold",style:{color:"var(--terminal-text, #fff5eb)"},children:H}),l.jsx("span",{className:"text-[10px]",style:{color:"var(--terminal-text-muted, #887766)"},children:R}),l.jsx("span",{className:"flex-1"}),x.type==="role"&&l.jsx("button",{onClick:()=>k(I=>!I),className:"text-[10px] px-2 py-1 rounded hover:opacity-80 transition-opacity",style:{color:j?"var(--terminal-text)":"var(--terminal-text-muted)",border:"1px solid var(--terminal-border)",background:j?"var(--terminal-border)":"transparent"},children:"Profile"}),x.type!=="dashboard"&&l.jsx("button",{onClick:()=>g({type:"dashboard"}),className:"text-[10px] px-2 py-1 rounded hover:opacity-80 transition-opacity",style:{color:"var(--terminal-text-muted)",border:"1px solid var(--terminal-border)"},children:"Dashboard"})]}),l.jsxs("div",{className:"flex-1 flex overflow-hidden",children:[l.jsx("div",{className:"flex-1 overflow-hidden relative pro-panel-inline",children:b}),j&&x.type==="role"&&h&&l.jsx("div",{className:"shrink-0 overflow-hidden pro-panel-inline",style:{width:420,borderLeft:"1px solid var(--terminal-border, #2E261F)"},children:h(()=>k(!1))})]})]})]})}function v8({role:e,messages:n,isStreaming:a,mode:i,onModeChange:o,onSend:u,isWave:d}){const f=vs[e.id]??"#666";return l.jsxs("div",{className:"flex flex-col h-full",children:[l.jsx(hv,{messages:n,roleId:e.id,roleColor:f}),d?l.jsxs("div",{className:"shrink-0 px-4 py-2 border-t flex items-center gap-2",style:{borderColor:"var(--terminal-border)",background:"var(--terminal-bg-deeper)"},children:[l.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-amber-400 shrink-0",style:{animation:"pulse 2s infinite"}}),l.jsx("span",{className:"text-[11px] text-amber-400/80",children:"Wave execution · read-only"})]}):l.jsx(Qm,{mode:i,onModeChange:o,onSend:(m,h)=>u(m,i,h),disabled:a,disabledReason:a?`${e.id.toUpperCase()} is responding...`:void 0})]})}function w8({role:e,onSend:n,getAppearance:a,onOpenProfile:i}){const[o,u]=v.useState("talk"),d=vs[e.id]??"#666";return l.jsxs("div",{className:"flex flex-col h-full",children:[l.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center gap-4",children:[l.jsx("button",{onClick:i,className:"cursor-pointer hover:opacity-80 transition-opacity",children:l.jsx("div",{className:"rounded-lg p-1",style:{background:`${d}20`},children:l.jsx(Ul,{roleId:e.id,appearance:a(e.id),scale:5})})}),l.jsxs("div",{className:"text-center",children:[l.jsx("div",{className:"text-sm font-semibold",style:{color:"var(--terminal-text)"},children:e.name}),l.jsxs("div",{className:"text-xs mt-0.5",style:{color:"var(--terminal-text-muted)"},children:[e.level==="c-level"?e.id.toUpperCase():e.id," · Start a conversation"]})]})]}),l.jsx(Qm,{mode:o,onModeChange:u,onSend:f=>n(f,o),disabled:!1})]})}function Eu({icon:e,label:n,active:a,badge:i,live:o,onClick:u}){return l.jsxs("button",{onClick:u,className:"flex flex-col items-center gap-1 py-3 rounded-lg transition-all hover:opacity-90",style:{background:a?"var(--desk-wood, #5C3D2E)":"var(--terminal-border, #2E261F)",border:a?"1px solid var(--desk-wood, #5C3D2E)":"1px solid transparent"},children:[l.jsxs("div",{className:"relative",children:[l.jsx("span",{className:"text-[16px]",children:e}),o&&l.jsx("span",{className:"absolute -top-1 -right-2 w-2 h-2 rounded-full animate-pulse",style:{background:"#EF4444"}}),i!==void 0&&i>0&&!o&&l.jsx("span",{className:"absolute -top-1.5 -right-3 text-[7px] px-1 py-0.5 rounded-full font-bold leading-none",style:{background:"var(--desk-wood, #5C3D2E)",color:"#fff",minWidth:14,textAlign:"center"},children:i})]}),l.jsx("span",{className:"text-[10px] font-semibold",style:{color:a?"#fff":"var(--terminal-text, #fff5eb)"},children:n})]})}function k8({roles:e,roleStatuses:n,activeExecs:a,waves:i,knowledgeDocs:o,roleLevels:u,getAppearance:d,onRoleClick:f,onWaveClick:m,onKnowledgeClick:h}){const x=e.filter(g=>n[g.id]==="working");return l.jsx("div",{className:"h-full overflow-y-auto px-6 py-5",children:l.jsxs("div",{className:"space-y-5 max-w-4xl",children:[l.jsxs("div",{className:"flex gap-3",children:[l.jsx(yy,{label:"New Wave",icon:"⚡",color:"#EF4444",onClick:m}),l.jsx(yy,{label:"Knowledge",icon:"📚",color:"#0D9488",onClick:h})]}),x.length>0&&l.jsx(Nu,{title:"Currently Working",count:x.length,children:a.map(g=>{const w=e.find(j=>j.id===g.roleId),b=vs[g.roleId]??"#666";return l.jsxs("button",{onClick:()=>f(g.roleId),className:"flex items-center gap-3 px-4 py-2.5 rounded hover:opacity-80 w-full text-left",style:{background:`${b}10`},children:[l.jsx("div",{className:"shrink-0",style:{width:24,height:24},children:l.jsx(Ul,{roleId:g.roleId,appearance:d(g.roleId),scale:1.2})}),l.jsxs("div",{className:"flex-1 min-w-0",children:[l.jsx("span",{className:"text-[12px] font-medium",style:{color:b},children:w==null?void 0:w.name}),l.jsx("span",{className:"text-[11px] ml-2 truncate",style:{color:"var(--terminal-text-muted)"},children:g.task.slice(0,60)})]}),l.jsx("span",{className:"text-[10px] animate-pulse",style:{color:b},children:"●"})]},g.roleId)})}),l.jsx(Nu,{title:"Team",count:e.length,children:l.jsx("div",{className:"grid grid-cols-3 gap-1 px-2",children:e.map(g=>{var j;const w=n[g.id]??"offline",b=(j=u[g.id])==null?void 0:j.level;return l.jsxs("button",{onClick:()=>f(g.id),className:"flex items-center gap-2 px-3 py-2 rounded hover:opacity-80 text-left",children:[l.jsx("span",{className:"w-2 h-2 rounded-full shrink-0",style:{background:w==="working"?"#4CAF50":w==="idle"?"#FFC107":"#9E9E9E"}}),l.jsx("span",{className:"text-[11px] truncate",style:{color:"var(--terminal-text)"},children:g.name}),b!=null&&l.jsxs("span",{className:"text-[9px] opacity-40",children:["Lv.",b]})]},g.id)})})}),i.length>0&&l.jsx(Nu,{title:"Recent Waves",count:i.length,children:i.slice(0,5).map(g=>{var w;return l.jsxs("div",{className:"px-4 py-2 text-[11px]",style:{color:"var(--terminal-text-muted)"},children:[l.jsxs("span",{style:{color:"var(--terminal-text)"},children:["Wave ",g.id]})," — ",(w=g.directive)==null?void 0:w.slice(0,80)]},g.id)})}),l.jsx(Nu,{title:"Knowledge Base",count:o.length,children:l.jsxs("button",{onClick:h,className:"px-4 py-3 text-[11px] hover:opacity-80",style:{color:"var(--terminal-text-muted)"},children:[o.length," documents · Click to explore ","→"]})})]})})}function yy({label:e,icon:n,color:a,onClick:i}){return l.jsxs("button",{onClick:i,className:"flex items-center gap-2 px-5 py-3 rounded-lg hover:opacity-80 transition-opacity",style:{background:`${a}15`,border:`1px solid ${a}30`},children:[l.jsx("span",{className:"text-sm",children:n}),l.jsx("span",{className:"text-[12px] font-medium",style:{color:a},children:e})]})}function Nu({title:e,count:n,children:a}){return l.jsxs("div",{className:"rounded-lg overflow-hidden",style:{background:"var(--terminal-surface, #241E19)",border:"1px solid var(--terminal-border, #2E261F)"},children:[l.jsxs("div",{className:"px-4 py-2.5 flex items-center gap-2",style:{borderBottom:"1px solid var(--terminal-border, #2E261F)"},children:[l.jsx("span",{className:"text-[10px] font-bold tracking-wider",style:{color:"var(--terminal-text-muted)"},children:e.toUpperCase()}),n!==void 0&&l.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded-full",style:{background:"var(--terminal-border)",color:"var(--terminal-text-muted)"},children:n})]}),l.jsx("div",{className:"py-1",children:a})]})}const vm=5e4;function Tv(e){return e<vm?1:Math.max(1,Math.floor(Math.sqrt(e/vm)))}function by(e){return vm*e*e}function j8(e){const n=Tv(e),a=by(n),i=by(n+1);return Math.min(1,(e-a)/(i-a))}function Yh(e){const n={};for(const[a,i]of Object.entries(e)){const o=i.inputTokens+i.outputTokens;n[a]={level:Tv(o),totalTokens:o,progress:j8(o)}}return n}const S8=[{id:"first-employee",name:"First Employee",icon:"🏆",description:"Hired your first role",check:e=>e.roleCount>=1},{id:"full-team",name:"Full Team",icon:"👥",description:"Hired 5+ roles",check:e=>e.roleCount>=5},{id:"token-10k",name:"Getting Started",icon:"📊",description:"Used 10K tokens total",check:e=>e.totalTokens>=1e4},{id:"token-100k",name:"Power User",icon:"💪",description:"Used 100K tokens total",check:e=>e.totalTokens>=1e5},{id:"token-millionaire",name:"Token Millionaire",icon:"🎖",description:"Used 1M tokens total",check:e=>e.totalTokens>=1e6},{id:"token-mogul",name:"Token Mogul",icon:"💎",description:"Used 10M tokens total",check:e=>e.totalTokens>=1e7},{id:"first-promotion",name:"First Promotion",icon:"⭐",description:"Any role reached Lv.3",check:e=>e.roles.some(n=>n.level>=3)},{id:"senior-staff",name:"Senior Staff",icon:"🌟",description:"Any role reached Lv.5",check:e=>e.roles.some(n=>n.level>=5)},{id:"master-class",name:"Master Class",icon:"👑",description:"Any role reached Lv.10",check:e=>e.roles.some(n=>n.level>=10)},{id:"full-house",name:"Full House",icon:"🏠",description:"All roles Lv.5+",check:e=>e.roleCount>=3&&e.roles.every(n=>n.level>=5)},{id:"first-launch",name:"First Launch",icon:"🚀",description:"Completed Chapter 2 — gave your first order",check:e=>{var n;return((n=e.completedQuests)==null?void 0:n.includes("ch2-q2"))??!1}},{id:"team-builder",name:"Team Builder",icon:"🏗️",description:"Completed Chapter 4 — dispatched your first wave",check:e=>{var n;return((n=e.completedQuests)==null?void 0:n.includes("ch4-q2"))??!1}},{id:"explorer",name:"Explorer",icon:"🔍",description:"Completed Chapter 5 — customized a character",check:e=>{var n;return((n=e.completedQuests)==null?void 0:n.includes("ch5-q2"))??!1}},{id:"interior-designer",name:"Interior Designer",icon:"🎨",description:"Completed Chapter 7 — bought premium furniture",check:e=>{var n;return((n=e.completedQuests)==null?void 0:n.includes("ch7-q2"))??!1}},{id:"tycoon-master",name:"Tycoon Master",icon:"🎯",description:"Completed all 10 chapters",check:e=>{var n;return((n=e.completedQuests)==null?void 0:n.includes("ch10-q3"))??!1}}];function vy(e){return S8.filter(n=>n.check(e))}const wy={cto:"#1565C0",cbo:"#E65100",pm:"#2E7D32",engineer:"#4A148C",designer:"#AD1457",qa:"#00695C","data-analyst":"#0277BD"};function C8({importJob:e,onImportDone:n}){var ac,Li,lc,ic,sc;const[a,i]=v.useState([]),[o,u]=v.useState([]),[d,f]=v.useState([]),[m,h]=v.useState([]),[x,g]=v.useState([]),[w,b]=v.useState([]),[j,k]=v.useState("TYCONO"),[E,C]=v.useState(!0),[N,_]=v.useState(null),[z,H]=v.useState({type:"none"}),[R,I]=v.useState(null),[q,X]=v.useState(null),[A,$]=v.useState([]),[L,Y]=v.useState(!1),[se,ee]=v.useState(!1),[W,oe]=v.useState([]),[de,V]=v.useState([]),[D,B]=v.useState(0),[U,T]=v.useState(!1),[ie,ge]=v.useState({}),[pe,ze]=v.useState("ceo"),[Ie,He]=v.useState(null),[st,Qe]=v.useState(!1),[et,Ee]=v.useState(!1),[De,yt]=v.useState({}),ut=v.useRef({}),[pt,jt]=v.useState(!1),[Wt,Ft]=v.useState(null),[Et,$n]=v.useState({}),[me,Se]=v.useState([]),Ne=v.useMemo(()=>{const F={};for(const Q of me)F[Q.roleId]=Q;return F},[me]),[K,ue]=v.useState([]),[te,ke]=v.useState(0),[ve,_e]=v.useState(qg()),Be=v.useRef(qg()),Oe=v.useRef(!1),qe=v.useRef(-1),[rt,Ve]=v.useState(null),bt=v.useRef(null),[Re,Ue]=v.useState(void 0),[_t,Bt]=v.useState(!1);v.useEffect(()=>{ye.getStatus().then(F=>{Ue(F.engine),Bt(!!F.hasApiKey)}).catch(()=>{})},[]);const{getAppearance:Ot,setAppearance:fn,resetAppearance:wn,theme:Z,setTheme:$e,speechSettings:nt,setSpeechSettings:Qt,language:we,setLanguage:kt}=C6(),[ln,sn]=v.useState(null),[,ne]=v.useState("character"),Ae=A6(),[We,Nt]=v.useState(!1),[kn,ur]=v.useState(!1),[xn,gn]=v.useState(!1),[dr,sl]=v.useState(!1),[Ju,Fs]=v.useState(!1),[Vo,Ta]=v.useState(!1),[Ti,ca]=v.useState(!1),[Vn,Wl]=v.useState(null);v.useEffect(()=>{Ae.refresh()},[]),v.useEffect(()=>{const F=Q=>{(Q.metaKey||Q.ctrlKey)&&Q.key==="s"&&(Q.preventDefault(),Nt(!0))};return window.addEventListener("keydown",F),()=>window.removeEventListener("keydown",F)},[]),v.useEffect(()=>{if(!dr)return;let F=!1;const Q=async()=>{try{const he=await ye.getGitStatus();F||Wl(he)}catch{}};Q();const re=setInterval(Q,1e4);return()=>{F=!0,clearInterval(re)}},[dr]);const[jr,jn]=v.useState(null),[Fa,Ma]=v.useState(null),[fr,Ra]=v.useState([]),[ol,Ms]=v.useState(!1),Rs=v.useRef(!1),zs=v.useRef(null);let Gl=v.useRef(0);const Vl=v.useRef(new Set),Pr=v.useRef(Date.now()),Dn=(F,Q,re)=>{const he={id:Gl.current++,type:F,text:Q,detail:re};Ra(je=>[...je,he])};v.useEffect(()=>{var F;ol&&((F=zs.current)==null||F.scrollIntoView({behavior:"smooth"}))},[fr,ol]),v.useEffect(()=>{e&&(Rs.current||(Rs.current=!0,Ma("Scanning knowledge sources..."),Ra([{id:0,type:"scan",text:"Starting knowledge import..."}]),Gl.current=1,fetch("/api/setup/import-knowledge",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({paths:e.paths,companyRoot:e.companyRoot})}).then(async F=>{var je;const Q=(je=F.body)==null?void 0:je.getReader();if(!Q)return;const re=new TextDecoder;let he="";for(;;){const{done:Le,value:It}=await Q.read();if(Le)break;he+=re.decode(It,{stream:!0});const dt=he.split(`
|
|
93
93
|
`);he=dt.pop()||"";let Ze="";for(const Je of dt)if(Je.startsWith("event: "))Ze=Je.slice(7).trim();else if(Je.startsWith("data: ")&&Ze){try{const ft=JSON.parse(Je.slice(6));switch(Ze){case"scanning":Ma(`Scanning: ${ft.path} (${ft.fileCount} files)`),Dn("scan",`Found ${ft.fileCount} files`,ft.path);break;case"processing":jn({index:ft.index,total:ft.total}),Ma(`Importing knowledge... (${ft.index}/${ft.total})`),Dn("process",`Processing: ${ft.file}`,`${ft.index} / ${ft.total}`);break;case"created":Dn("created",ft.title,ft.summary);break;case"skipped":Dn("process",`Skipped: ${ft.file}`,ft.reason);break;case"done":Ma(null),jn(null),Dn("done",`Import complete! ${ft.created} created, ${ft.skipped} skipped.`),xt(`Knowledge import complete! ${ft.created} documents imported.`,"#2E7D32"),n==null||n();break;case"error":Ma(null),jn(null),Dn("error",ft.message),xt(`Import failed: ${ft.message}`,"#B71C1C"),n==null||n();break}}catch{}Ze=""}}}).catch(F=>{Ma(null),Dn("error",F.message),xt(`Import error: ${F.message}`,"#B71C1C"),n==null||n()})))},[e]);const[Zr,ua]=v.useState("iso"),Jr=v.useRef("iso"),[Or,Tn]=v.useState({type:"dashboard"}),[Ko,hr]=v.useState(typeof window<"u"?window.innerWidth:1200);v.useEffect(()=>{const F=()=>hr(window.innerWidth);return window.addEventListener("resize",F),()=>window.removeEventListener("resize",F)},[]);const Kl=Ko<1024,[Sr,da]=v.useState(!1),[mr,Qo]=v.useState(560),[Ln,Gt]=v.useState([]),[fa,Xn]=v.useState(null),[ea,ta]=v.useState(null),{sendMessage:ed}=k6(),Fi=v.useRef(new Map);v.useEffect(()=>{Promise.all([ye.getCompany().then(F=>{k(F.name),i(F.roles)}),ye.getOrgTree().then(F=>{ge(F.nodes),ze(F.root)}).catch(()=>{}),ye.getCostSummary().then(F=>$r(Yh(F.byRole))).catch(()=>{})]).catch(F=>_(`Failed to load: ${F.message}`)).finally(()=>C(!1)),ye.getProjects().then(u).catch(()=>{}),ye.getStandups().then(f).catch(()=>{}),ye.getWaves().then(h).catch(()=>{}),ye.getDecisions().then(g).catch(()=>{}),ye.getKnowledge().then(b).catch(()=>{}),ye.getQuestProgress().then(F=>{const Q=Yg(F);Q.activeChapter!==F.activeChapter&&ye.saveQuestProgress(Q).catch(()=>{}),_e(Q),Be.current=Q,Oe.current=!0,ye.getCoins().then(re=>{var he;re.totalEarned===0?ye.migrateCoins(((he=Q.completedQuests)==null?void 0:he.length)??0).then(je=>ke(je.balance)).catch(()=>{}):ke(re.balance)}).catch(()=>{})}).catch(()=>{Oe.current=!0})},[]),v.useEffect(()=>{if(qe.current===-1){qe.current=o.length;return}o.length>qe.current&&Pt({type:"project_created"}),qe.current=o.length},[o.length]);const Ql=v.useRef(!1);v.useEffect(()=>{if(!(!Oe.current||a.length===0||Ql.current)){Ql.current=!0;for(const F of a)Pt({type:"role_hired",condition:{roleId:F.id,roleCount:a.length}})}},[a.length]),v.useEffect(()=>{ye.getSessions().then(F=>{const Q=F.filter(he=>he.source!=="wave");if(Q.length>0){const he=Q.map(Le=>({...Le,messages:[]}));Gt(he);const je=he.find(Le=>Le.status==="active")??he[0];Xn(je.id),_a()}const re=F.filter(he=>he.source==="wave").map(he=>he.id);re.length>0&&ye.deleteSessions(re).catch(()=>{})}).catch(F=>{console.error("Failed to load sessions",F)})},[]),v.useEffect(()=>{const F=()=>{fetch("/api/exec/status").then(re=>re.json()).then(re=>{$n(re.statuses??{}),Se(re.activeExecutions??[])}).catch(()=>{})};F();const Q=setInterval(F,3e3);return()=>clearInterval(Q)},[]);const tr=v.useMemo(()=>{const F={...Et};if(ea){const Q=Ln.find(re=>re.id===ea);Q&&(F[Q.roleId]="working")}return F},[Et,ea,Ln]);v.useEffect(()=>{z.type==="role"?ye.getRole(z.roleId).then(I).catch(console.error):I(null)},[z]);const na=()=>H({type:"none"}),Mi=async(F,Q)=>{const re=await ye.updateDecision(F,Q);g(he=>he.map(je=>je.id===F?re:je))},za=async F=>{await ye.deleteDecision(F),g(Q=>Q.filter(re=>re.id!==F))},Fn=F=>{H(F),da(!1),ee(!1)},_a=()=>{da(!0),H({type:"none"}),ee(!1)},cl=()=>{ee(!0),da(!1),H({type:"none"})},Po=async(F,Q)=>{const re=a.find(je=>je.id===F),he=(q==null?void 0:q.mode)==="ask";X(null);try{const je=await ye.startJob({type:"assign",roleId:F,task:Q,readOnly:he}),Le=je.jobId,It=je.sessionId??`job-${Le}`,dt=wy[F]??"#666",Ze=`${F.toUpperCase()} · ${(re==null?void 0:re.name)??F}`;T(!1),$([{sessionId:It,jobId:Le,title:Ze,color:dt}]),Pt({type:"task_executed",condition:{roleId:F}}),Zt.pushMessage({ts:Date.now(),roleId:"ceo",text:`[CEO → ${(re==null?void 0:re.name)??F}] ${he?"Ask":"Assign"}: ${Q}`,type:"dispatch",targetRoleId:F})}catch(je){xt(`Failed to start job: ${je instanceof Error?je.message:"unknown"}`,"#C62828")}},Pl=v.useRef(0),xt=(F,Q)=>{const re=++Pl.current;ue(he=>[...he,{id:re,message:F,color:Q}]),setTimeout(()=>ue(he=>he.filter(je=>je.id!==re)),4e3)},_s=F=>{bt.current&&clearTimeout(bt.current),Ve(F),bt.current=setTimeout(()=>Ve(null),8e3)},Pt=F=>{if(!Oe.current)return;let Q=Be.current;const re=av(Q);let he=0;const je=[];for(const It of re){if(!SN(It,F))continue;const{progress:dt,quest:Ze}=kN(Q,It.id);Ze&&(Q=dt,he+=Ze.rewards.coins??0,je.push(Ze.title))}if(je.length===0)return;Q=Yg(Q),Be.current=Q,_e(Q);const Le=he>0?` 💰 +${he.toLocaleString()}`:"";je.length===1?xt(`📋 Quest complete: ${je[0]}${Le}`,"#7C3AED"):xt(`📋 ${je.length} quests complete!${Le}`,"#7C3AED"),Ve(null),ye.saveQuestProgress(Q).catch(()=>{}),he>0&&ye.earnCoins(he,`quests: ${je.length}`,je.join(",")).then(It=>ke(It.balance)).catch(()=>{})};v.useEffect(()=>{if(!rt)return;const F=document.querySelector(`[data-quest-target="${rt}"]`);if(!F)return;F.classList.add("quest-spotlight");const Q=()=>{F.classList.remove("quest-spotlight"),Ve(null),bt.current&&clearTimeout(bt.current)};return F.addEventListener("click",Q,{once:!0}),()=>{F.classList.remove("quest-spotlight"),F.removeEventListener("click",Q)}},[rt]);const $r=F=>{var re,he;const Q=ut.current;for(const[je,Le]of Object.entries(F)){const It=((re=Q[je])==null?void 0:re.level)??0;if(It>0&&Le.level>It){const dt=((he=a.find(Ze=>Ze.id===je))==null?void 0:he.name)??je.toUpperCase();xt(`${dt} leveled up to Lv.${Le.level}!`,"#7C3AED")}}ut.current=F,yt(F)};v.useEffect(()=>{const F={roles:Object.entries(De).map(([je,Le])=>({id:je,level:Le.level,totalTokens:Le.totalTokens})),totalTokens:Object.values(De).reduce((je,Le)=>je+Le.totalTokens,0),roleCount:a.length,completedQuests:ve.completedQuests},Q=vy(F),re=new Set(Q.map(je=>je.id));if(Date.now()-Pr.current>5e3){const je=Vl.current;for(const Le of Q)je.has(Le.id)||xt(`${Le.icon} Badge earned: ${Le.name}!`,"#D4A017")}Vl.current=re},[De,a.length,ve.completedQuests]);const Ba=v.useMemo(()=>wN(ve),[ve]),Ri=()=>{var Q;const F=A[A.length-1];F&&(xt(`${F.title} completed`,F.color),Zt.pushMessage({ts:Date.now(),roleId:((Q=F.title.split(" · ")[0])==null?void 0:Q.toLowerCase())??"unknown",text:`[${F.title}] Job completed`,type:"dispatch"})),ye.getStandups().then(f).catch(console.error),ye.getCompany().then(re=>i(re.roles)).catch(console.error),ye.getCostSummary().then(re=>$r(Yh(re.byRole))).catch(()=>{})},ul=v.useRef(new Map),zi=F=>{if(ul.current.has(F))return;const Q=new AbortController;ul.current.set(F,Q),ta(re=>re??F),fetch(`/api/sessions/${F}/stream?from=0`,{signal:Q.signal}).then(async re=>{var It,dt;if(!re.ok||!re.body)return;const he=re.body.getReader(),je=new TextDecoder;let Le="";for(;;){const{done:Ze,value:Je}=await he.read();if(Ze)break;Le+=je.decode(Je,{stream:!0});const ft=Le.split(`
|
|
94
94
|
`);Le=ft.pop()??"";let St="";for(const ti of ft)if(ti.startsWith("event: "))St=ti.slice(7).trim();else if(ti.startsWith("data: ")){try{const Kn=JSON.parse(ti.slice(6));St==="stream:end"?(Gt(ot=>ot.map($t=>{if($t.id!==F)return $t;const En=$t.messages.map(on=>on.status==="streaming"?{...on,status:"done"}:on);return{...$t,messages:En}})),ta(ot=>ot===F?null:ot),ul.current.delete(F)):St==="activity"&&(Kn.type==="text"&&((It=Kn.data)!=null&&It.text)?Gt(ot=>ot.map($t=>{if($t.id!==F)return $t;const En=[...$t.messages],on=En[En.length-1];return(on==null?void 0:on.from)==="role"&&on.status==="streaming"&&(En[En.length-1]={...on,content:on.content+Kn.data.text}),{...$t,messages:En}})):Kn.type==="thinking"&&((dt=Kn.data)!=null&&dt.text)?Gt(ot=>ot.map($t=>{if($t.id!==F)return $t;const En=[...$t.messages],on=En[En.length-1];return(on==null?void 0:on.from)==="role"&&on.status==="streaming"&&(En[En.length-1]={...on,thinking:(on.thinking??"")+Kn.data.text}),{...$t,messages:En}})):(Kn.type==="job:done"||Kn.type==="job:error")&&(Gt(ot=>ot.map($t=>{if($t.id!==F)return $t;const En=$t.messages.map(on=>on.status==="streaming"?{...on,status:Kn.type==="job:done"?"done":"error"}:on);return{...$t,messages:En}})),ta(ot=>ot===F?null:ot),ul.current.delete(F)))}catch{}St=""}}}).catch(()=>{ul.current.delete(F),ta(re=>re===F?null:re)})},dl=async(F,Q,re)=>{Y(!1);try{const he=await ye.startJob({type:"wave",directive:F,targetRoles:Q,...re&&{attachments:re}});Pt({type:"wave_dispatched"});const je=he.jobIds??(he.jobId?[he.jobId]:[]),Le=pe&&ie[pe]?ie[pe].children.map(ot=>a.find($t=>$t.id===ot)).filter(ot=>!!ot):a.filter(ot=>ot.level==="c-level"),It=Q?Le.filter(ot=>Q.includes(ot.id)):Le,dt=he.waveId??`wave-${Date.now()}`,Ze=he.sessionIds??[],Je=je.map((ot,$t)=>{var En,on;return{jobId:ot,roleId:((En=It[$t])==null?void 0:En.id)??`role-${$t}`,roleName:((on=It[$t])==null?void 0:on.name)??`C-Level ${$t+1}`,sessionId:Ze[$t]??`wave-${ot}`}});Zt.pushMessage({ts:Date.now(),roleId:"ceo",text:`[CEO WAVE] "${F}" → ${Je.map(ot=>ot.roleName).join(", ")}`,type:"dispatch"});const ft={id:dt,directive:F,rootJobs:Je,startedAt:Date.now(),sessionIds:Ze};oe(ot=>[ft,...ot]),cl();const St=new Date().toISOString(),Kn=(Ze.length>0?Je.map((ot,$t)=>({id:Ze[$t]??`wave-${ot.jobId}`,roleId:ot.roleId,title:`WAVE: ${ot.roleName}`,mode:"do",source:"wave",jobId:ot.jobId,messages:[{id:`msg-wave-${ot.jobId}-ceo`,from:"ceo",content:F,type:"directive",status:"done",timestamp:St}],status:"active",createdAt:St,updatedAt:St})):Je.map(ot=>({id:`wave-${ot.jobId}`,roleId:ot.roleId,title:`WAVE: ${ot.roleName}`,mode:"do",source:"wave",jobId:ot.jobId,messages:[{id:`msg-wave-${ot.jobId}-ceo`,from:"ceo",content:F,type:"directive",status:"done",timestamp:St}],status:"active",createdAt:St,updatedAt:St}))).map((ot,$t)=>({...ot,messages:[...ot.messages,{id:`msg-wave-${Je[$t].jobId}-role`,from:"role",content:"",type:"conversation",status:"streaming",timestamp:St,jobId:Je[$t].jobId}]}));Gt(ot=>[...Kn,...ot]),Kn.length>0&&(Xn(Kn[0].id),_a());for(const ot of Kn)zi(ot.id)}catch(he){xt(`Failed to start wave: ${he instanceof Error?he.message:"unknown"}`,"#C62828")}},ha=()=>{ye.getWaves().then(h).catch(console.error),ye.getStandups().then(f).catch(console.error)},Wn=()=>{ye.getCompany().then(F=>i(F.roles)).catch(console.error),ye.getOrgTree().then(F=>{ge(F.nodes),ze(F.root)}).catch(console.error),ye.getCostSummary().then(F=>$r(Yh(F.byRole))).catch(()=>{})},Oa=async(F,Q)=>{await ye.createRole(F),fn(F.id,Q),Wn(),xt(`${F.name} hired!`,"#2E7D32"),Pt({type:"role_hired",condition:{roleId:F.id,roleCount:a.length+1}})},_i=async F=>{var Q;await ye.deleteRole(F),Wn(),Gt(re=>re.filter(he=>he.roleId!==F)),fa&&((Q=Ln.find(re=>re.id===fa))==null?void 0:Q.roleId)===F&&Xn(null),Ft(null),xt(`${F.toUpperCase()} removed`,"#B71C1C")},$a=async(F,Q)=>{await ye.updateRole(F,Q),Wn(),z.type==="role"&&z.roleId===F&&ye.getRole(F).then(I).catch(console.error),Q.name&&xt(`${F.toUpperCase()} renamed to "${Q.name}"`,"#1565C0"),Q.persona!==void 0&&(xt(`${F.toUpperCase()} persona updated`,"#2E7D32"),Pt({type:"persona_updated"}))},td=F=>{_a(),Pt({type:"terminal_opened"})},Bi=async F=>{try{const Q=await ye.createSession(F,"talk");Gt(re=>[Q,...re]),Xn(Q.id),_a()}catch(Q){console.error("Failed to create session",Q),xt(`Failed to create session: ${Q instanceof Error?Q.message:"API unreachable"}`,"#B71C1C")}},Oi=async F=>{try{const Q=await ye.createSession(F,"talk");Gt(re=>[Q,...re]),Xn(Q.id)}catch(Q){console.error("Failed to create session",Q),xt(`Failed to create session: ${Q instanceof Error?Q.message:"API unreachable"}`,"#B71C1C")}},Zl=async F=>{const Q=Ne[F],re=(Q==null?void 0:Q.jobId)??(Q==null?void 0:Q.id);if(re&&tr[F]==="working"){const je=a.find(Je=>Je.id===F),Le=wy[F]??"#666",It=`${F.toUpperCase()} · ${(je==null?void 0:je.name)??F}`,dt=Ln.find(Je=>Je.roleId===F&&Je.status==="active"),Ze=(dt==null?void 0:dt.id)??`job-${re}`;$([{sessionId:Ze,jobId:re,title:It,color:Le}]),T(!1);return}const he=Ln.find(je=>je.roleId===F);if(he)Xn(he.id),Zt.setActiveChannelId(null);else try{const je=await ye.createSession(F,"talk");Gt(Le=>[je,...Le]),Xn(je.id),Zt.setActiveChannelId(null)}catch(je){console.error("Failed to create session",je)}_a()},Jl=async F=>{const Q=Ln.find(re=>re.id===F);if((Q==null?void 0:Q.source)==="wave"){if(Q.jobId){const re=Fi.current.get(Q.jobId);re&&(re.abort(),Fi.current.delete(Q.jobId))}Gt(re=>{var je;const he=re.filter(Le=>Le.id!==F);return fa===F&&Xn(((je=he[0])==null?void 0:je.id)??null),he});return}try{await ye.deleteSession(F),Gt(re=>{var je;const he=re.filter(Le=>Le.id!==F);return fa===F&&Xn(((je=he[0])==null?void 0:je.id)??null),he})}catch(re){console.error("Failed to delete session",re),xt(`Failed to close session: ${re instanceof Error?re.message:"API error"}`,"#B71C1C")}},Bs=async()=>{try{const{ids:F}=await ye.deleteEmptySessions();if(F.length===0)return;Gt(Q=>{var he;const re=Q.filter(je=>!F.includes(je.id));return fa&&F.includes(fa)&&Xn(((he=re[0])==null?void 0:he.id)??null),re}),xt(`Cleared ${F.length} empty session${F.length!==1?"s":""}`,"#2E7D32")}catch(F){xt(`Failed to clear empty sessions: ${F instanceof Error?F.message:"API error"}`,"#B71C1C")}},Zo=async()=>{if(!confirm("Close all sessions? This cannot be undone."))return;const F=Ln.filter(Q=>Q.source!=="wave").map(Q=>Q.id);for(const Q of Ln)if(Q.source==="wave"&&Q.jobId){const re=Fi.current.get(Q.jobId);re&&(re.abort(),Fi.current.delete(Q.jobId))}try{F.length>0&&await ye.deleteSessions(F),Gt([]),Xn(null),xt("All sessions closed","#2E7D32")}catch(Q){xt(`Failed to close sessions: ${Q instanceof Error?Q.message:"API error"}`,"#B71C1C")}},ma=(F,Q)=>{Gt(re=>re.map(he=>{if(he.id!==F)return he;const je=[...he.messages],Le=je[je.length-1];if(Le&&Le.from==="role"&&Le.status==="streaming"){const It=[...Le.streamEvents??[],Q];je[je.length-1]={...Le,streamEvents:It}}return{...he,messages:je}}))},La=(F,Q,re,he)=>{const je={id:`msg-${Date.now()}-ceo`,from:"ceo",content:Q,type:re==="do"?"directive":"conversation",status:"done",timestamp:new Date().toISOString(),attachments:he},Le={id:`msg-${Date.now()+1}-role`,from:"role",content:"",type:"conversation",status:"streaming",timestamp:new Date().toISOString(),streamEvents:[]};Gt(dt=>dt.map(Ze=>Ze.id===F?{...Ze,messages:[...Ze.messages,je,Le],updatedAt:new Date().toISOString()}:Ze));const It=Ln.find(dt=>dt.id===F);re==="talk"?Pt({type:"talk_mode_used"}):re==="do"&&(Pt({type:"do_mode_used"}),It&&Pt({type:"task_executed",condition:{roleId:It.roleId}})),ta(F),ed(F,Q,re,{onThinking:dt=>{Gt(Ze=>Ze.map(Je=>{if(Je.id!==F)return Je;const ft=[...Je.messages],St=ft[ft.length-1];return St&&St.from==="role"&&St.status==="streaming"&&(ft[ft.length-1]={...St,thinking:(St.thinking??"")+dt}),{...Je,messages:ft}})),ma(F,{type:"thinking",timestamp:Date.now(),text:dt})},onText:dt=>{Gt(Ze=>Ze.map(Je=>{if(Je.id!==F)return Je;const ft=[...Je.messages],St=ft[ft.length-1];return St&&St.from==="role"&&St.status==="streaming"&&(ft[ft.length-1]={...St,content:St.content+dt}),{...Je,messages:ft}}))},onToolUse:(dt,Ze)=>{ma(F,{type:"tool",timestamp:Date.now(),toolName:dt,toolInput:Ze})},onDispatch:(dt,Ze)=>{ma(F,{type:"dispatch",timestamp:Date.now(),roleId:dt,task:Ze})},onDispatchProgress:(dt,Ze,Je)=>{var ft;Ze==="tool"?ma(F,{type:"dispatch:progress",timestamp:Date.now(),roleId:dt,progressType:"tool",toolName:Je.name,toolInput:Je.input}):Ze==="thinking"?ma(F,{type:"dispatch:progress",timestamp:Date.now(),roleId:dt,progressType:"thinking",text:Je.text}):Ze==="text"?ma(F,{type:"dispatch:progress",timestamp:Date.now(),roleId:dt,progressType:"text",text:(ft=Je.text)==null?void 0:ft.slice(-200)}):(Ze==="done"||Ze==="error")&&ma(F,{type:"dispatch:progress",timestamp:Date.now(),roleId:dt,progressType:Ze})},onTurn:dt=>{ma(F,{type:"turn",timestamp:Date.now(),turn:dt})},onDone:()=>{Gt(dt=>dt.map(Ze=>{if(Ze.id!==F)return Ze;const Je=Ze.messages.map(St=>St.status==="streaming"?{...St,status:"done"}:St),ft=Ze.messages.length<=2?Q.slice(0,40).replace(/\n/g," "):Ze.title;return{...Ze,messages:Je,title:ft}})),ta(null)},onError:dt=>{Gt(Ze=>Ze.map(Je=>{if(Je.id!==F)return Je;const ft=Je.messages.map(St=>St.status==="streaming"?{...St,status:"error",content:St.content||dt}:St);return{...Je,messages:ft}})),ta(null)}},he)},ei=(F,Q)=>{Gt(re=>re.map(he=>he.id===F?{...he,mode:Q}:he)),ye.updateSession(F,{mode:Q}).catch(console.error)},nd=new Date().toISOString().slice(0,10),Jo=o[0],ec={cto:"Chief Technology Officer",cbo:"Chief Business Officer",pm:"Product Manager",engineer:"Software Engineer",designer:"UI/UX Designer",qa:"QA Engineer"},rd=F=>{const Q=ec[F];if(!Q)return"";for(const re of d){const he=re.content,je=he.indexOf(`## ${Q}`);if(je===-1)continue;const Le=he.indexOf(`
|
|
95
95
|
## `,je+10),dt=(Le===-1?he.slice(je):he.slice(je,Le)).split(`
|
|
@@ -107,4 +107,4 @@ ${Q}`;La(re.id,he,"do")}catch(re){xt(`Failed to delegate: ${re instanceof Error?
|
|
|
107
107
|
|
|
108
108
|
Skip this if you don't have a codebase yet — you can connect one later from Settings.`,tag:"optional",open:L,onToggle:()=>Y(!L),children:[l.jsxs("div",{className:"flex gap-2",children:[l.jsx("input",{className:`${nt} flex-1`,placeholder:"/path/to/code/repo",value:se,onChange:we=>ee(we.target.value)}),l.jsx("button",{onClick:()=>oe(!W),className:"px-3 py-2 rounded text-xs font-medium transition-colors shrink-0 cursor-pointer hover:brightness-125",style:{background:"var(--terminal-surface)",color:"var(--terminal-text)",border:"1px solid var(--terminal-border)"},title:"Browse folders",children:"📁"})]}),W&&l.jsx(Au,{onSelect:we=>{ee(we),oe(!1)},onClose:()=>oe(!1)})]}),l.jsxs(Sy,{icon:"📚",title:"Knowledge Import",hint:"Import existing documents into knowledge base.",help:`Point to folders with docs (.md, .txt, etc.) — AI will read, summarize, and organize them into a searchable knowledge base.
|
|
109
109
|
|
|
110
|
-
Skip this to start with an empty knowledge base. You can import documents anytime from the office.`,tag:"optional",open:de,onToggle:()=>V(!de),children:[l.jsxs("div",{className:"flex gap-2",children:[l.jsx("input",{className:`${nt} flex-1`,placeholder:"/path/to/docs",value:U,onChange:we=>T(we.target.value),onKeyDown:we=>{we.key==="Enter"&&(we.preventDefault(),Bt())}}),l.jsx("button",{onClick:()=>ge(!ie),className:"px-3 py-2 rounded text-xs font-medium transition-colors shrink-0 cursor-pointer hover:brightness-125",style:{background:"var(--terminal-surface)",color:"var(--terminal-text)",border:"1px solid var(--terminal-border)"},title:"Browse folders",children:"📁"}),l.jsx("button",{onClick:Bt,disabled:!U.trim(),className:"px-3 py-2 rounded text-xs font-medium shrink-0",style:{background:"var(--accent)",color:"#fff",opacity:U.trim()?1:.5},children:"Add"})]}),ie&&l.jsx(Au,{onSelect:we=>{D.includes(we)||B([...D,we]),ge(!1)},onClose:()=>ge(!1)}),D.length>0&&l.jsx("div",{className:"space-y-1 mt-2",children:D.map((we,kt)=>l.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 rounded text-xs",style:{background:"var(--terminal-bg)",color:"var(--terminal-text)",border:"1px solid var(--terminal-border)"},children:[l.jsx("span",{className:"flex-1 truncate",style:{fontFamily:"var(--pixel-font)"},children:we}),l.jsx("button",{onClick:()=>B(D.filter((ln,sn)=>sn!==kt)),className:"opacity-50 hover:opacity-100",children:"✕"})]},kt))})]})]}):l.jsx("div",{className:"space-y-3",children:l.jsxs(jy,{icon:"🔗",title:"AKB Path",hint:"Directory with existing CLAUDE.md and AKB structure.",help:"Connect to a directory that was previously set up with Tycono. It must contain a CLAUDE.md file. All existing roles, knowledge, and settings will be loaded.",children:[l.jsxs("div",{className:"flex gap-2",children:[l.jsx("input",{className:`${nt} flex-1`,placeholder:"/path/to/your/akb",value:pe,onChange:we=>{ze(we.target.value),He(null)},autoFocus:!0}),l.jsx("button",{onClick:()=>Ee(!et),className:"px-3 py-2 rounded text-xs font-medium transition-colors shrink-0 cursor-pointer hover:brightness-125",style:{background:"var(--terminal-surface)",color:"var(--terminal-text)",border:"1px solid var(--terminal-border)"},title:"Browse folders",children:"📁"}),l.jsx("button",{onClick:_t,disabled:st||!pe.trim(),className:"px-3 py-2 rounded text-xs font-medium transition-colors shrink-0",style:{background:"var(--accent)",color:"#fff",opacity:st||!pe.trim()?.5:1},children:st?"...":"Verify"})]}),Ie===!0&&l.jsxs("div",{className:"text-xs mt-2",style:{color:"var(--active-green)"},children:["✅"," Valid AKB found"]}),Ie===!1&&l.jsxs("div",{className:"text-xs mt-2",style:{color:"#EF4444"},children:["❌"," No valid AKB (CLAUDE.md required)"]}),et&&l.jsx(Au,{onSelect:we=>{ze(we),He(null),Ee(!1)},onClose:()=>Ee(!1)})]})})]}),rt==="team"&&l.jsxs("div",{className:"space-y-4",children:[l.jsx("h2",{className:"text-base font-semibold",style:{color:"var(--terminal-text)"},children:"Team Template"}),l.jsx("p",{className:"text-xs",style:{color:"var(--terminal-text-secondary)"},children:"Choose a starting team. You can add or remove roles later."}),De.map(we=>l.jsxs("div",{className:Qt(ut===we.id),onClick:()=>pt(we.id),children:[l.jsx("div",{className:"font-medium text-sm capitalize",children:we.id}),l.jsx("div",{className:"flex flex-wrap gap-1.5 mt-2",children:we.roles.map(kt=>l.jsx("span",{className:"px-2 py-0.5 rounded text-[10px]",style:{background:"var(--terminal-bg)",color:"var(--terminal-text)",border:"1px solid var(--terminal-border)"},children:kt.id.toUpperCase()},kt.id))})]},we.id)),l.jsxs("div",{className:Qt(ut==="custom"),onClick:()=>pt("custom"),children:[l.jsx("div",{className:"font-medium text-sm",children:"Custom"}),l.jsx("div",{className:"text-xs opacity-70 mt-1",children:"Start with no pre-built roles. Hire them from the office."})]})]}),rt==="create"&&l.jsxs("div",{className:"space-y-4",children:[l.jsx("h2",{className:"text-base font-semibold",style:{color:"var(--terminal-text)"},children:Ft?N==="existing-akb"?"AKB Connected!":"Company Created!":"Review & Create"}),!Ft&&!jt&&!te&&l.jsxs(l.Fragment,{children:[l.jsx("div",{className:"rounded-lg p-4 space-y-2 text-xs",style:{background:"var(--terminal-bg)",color:"var(--terminal-text)",border:"1px solid var(--terminal-border)",fontFamily:"var(--pixel-font)"},children:N==="existing-akb"?l.jsxs(l.Fragment,{children:[l.jsxs("div",{children:[l.jsx("span",{className:"opacity-50",children:"Mode:"})," Connect Existing AKB"]}),l.jsxs("div",{children:[l.jsx("span",{className:"opacity-50",children:"Path:"})," ",pe]}),l.jsxs("div",{children:[l.jsx("span",{className:"opacity-50",children:"Engine:"})," ",u==="claude-cli"?"Claude Code CLI":"Direct API"]})]}):l.jsxs(l.Fragment,{children:[l.jsxs("div",{children:[l.jsx("span",{className:"opacity-50",children:"Company:"})," ",g]}),l.jsxs("div",{children:[l.jsx("span",{className:"opacity-50",children:"Location:"})," ",z||"(default)"]}),l.jsxs("div",{children:[l.jsx("span",{className:"opacity-50",children:"Engine:"})," ",u==="claude-cli"?"Claude Code CLI":"Direct API"]}),se.trim()&&l.jsxs("div",{children:[l.jsx("span",{className:"opacity-50",children:"Code Repo:"})," ",se]}),l.jsxs("div",{children:[l.jsx("span",{className:"opacity-50",children:"Knowledge:"})," ",D.length>0?`Import ${D.length} source(s)`:"Fresh (empty)"]}),l.jsxs("div",{children:[l.jsx("span",{className:"opacity-50",children:"Team:"})," ",ut]}),D.length>0&&l.jsx("div",{className:"text-[10px] mt-1",style:{color:"var(--idle-amber)"},children:"Knowledge import will run in the background after entering the office."})]})}),$n&&l.jsx("div",{className:"text-xs p-3 rounded",style:{background:"rgba(220,38,38,0.15)",color:"#f87171"},children:$n})]}),(jt||te)&&l.jsxs("div",{className:"flex flex-col items-center py-8 gap-3",children:[l.jsx("div",{className:"w-8 h-8 border-2 rounded-full animate-spin",style:{borderColor:"var(--terminal-border)",borderTopColor:"var(--accent)"}}),l.jsx("div",{className:"text-sm",style:{color:"var(--terminal-text-secondary)"},children:te?"Connecting to AKB...":"Scaffolding your company..."})]}),Ft&&l.jsxs(l.Fragment,{children:[l.jsx("div",{className:"text-center py-4 text-4xl",children:"🏢"}),K&&l.jsxs("div",{className:"rounded-lg p-3 text-xs",style:{background:"var(--terminal-bg)",color:"var(--terminal-text)",border:"1px solid var(--terminal-border)",fontFamily:"var(--pixel-font)"},children:[l.jsx("span",{className:"opacity-50",children:"Location:"})," ",K]}),l.jsx("div",{className:"rounded-lg p-4 text-xs max-h-40 overflow-y-auto",style:{background:"var(--terminal-bg)",color:"var(--terminal-text)",border:"1px solid var(--terminal-border)",fontFamily:"var(--pixel-font)"},children:Se.map((we,kt)=>l.jsxs("div",{className:"py-0.5",children:[l.jsx("span",{style:{color:"var(--active-green)"},children:"✓"})," ",we]},kt))}),(ve||Be.length>0)&&l.jsxs("div",{className:"rounded-lg p-4 text-xs space-y-1",style:{background:"var(--terminal-bg)",color:"var(--terminal-text)",border:"1px solid var(--terminal-border)",fontFamily:"var(--pixel-font)"},children:[l.jsx("div",{className:"font-medium mb-2",style:{color:"var(--terminal-text-secondary)"},children:ve?"Installing skill tools...":"Skill tools"}),Be.map((we,kt)=>l.jsxs("div",{className:"py-0.5 flex items-center gap-2",children:[l.jsx("span",{style:{color:we.event==="installed"||we.event==="skipped"?"var(--active-green)":we.event==="error"?"#f87171":"var(--terminal-text-muted)"},children:we.event==="installed"||we.event==="skipped"?"✓":we.event==="error"?"✗":"…"}),l.jsx("span",{children:we.tool}),l.jsx("span",{style:{color:"var(--terminal-text-muted)"},children:we.detail})]},kt)),ve&&l.jsxs("div",{className:"flex items-center gap-2 mt-1",style:{color:"var(--terminal-text-muted)"},children:[l.jsx("div",{className:"w-3 h-3 border border-current rounded-full animate-spin",style:{borderTopColor:"var(--accent)"}}),l.jsx("span",{children:"Please wait..."})]})]}),D.length>0&&l.jsx("div",{className:"text-xs p-3 rounded",style:{background:"var(--accent)",color:"#fff",opacity:.9},children:"Knowledge import will start in the background after entering the office."})]})]})]}),l.jsxs("div",{className:"px-6 py-4 flex justify-between items-center",style:{borderTop:"1px solid var(--terminal-border)"},children:[l.jsx("div",{children:n>0&&!Ft&&l.jsx("button",{onClick:Re,className:"px-4 py-2 rounded text-sm transition-colors",style:{color:"var(--terminal-text-secondary)",border:"1px solid var(--terminal-border)"},children:"Back"})}),l.jsxs("div",{className:"text-xs",style:{color:"var(--terminal-text-muted)"},children:[n+1," / ",qe.length]}),l.jsx("div",{children:Ft?l.jsx("button",{onClick:Z,disabled:ve,className:"px-5 py-2 rounded text-sm font-medium transition-colors",style:{background:"var(--active-green)",color:"#fff",opacity:ve?.5:1},children:ve?"Setting up tools...":"Enter Office"}):l.jsx("button",{onClick:bt,disabled:!Ve()||jt||te,className:"px-5 py-2 rounded text-sm font-medium transition-colors",style:{background:Ve()?"var(--accent)":"var(--terminal-border)",color:"#fff",opacity:Ve()&&!jt&&!te?1:.5},children:rt==="create"?jt||te?te?"Connecting...":"Creating...":N==="existing-akb"?"Connect AKB":"Create Company":"Next"})})]})]})})}function tp({text:e}){const[n,a]=v.useState(!1),[i,o]=v.useState({top:0,left:0}),u=v.useRef(null),d=()=>{if(u.current){const f=u.current.getBoundingClientRect();o({top:f.bottom+6,left:f.left})}a(!0)};return l.jsxs("span",{className:"inline-flex",ref:u,children:[l.jsx("span",{className:"w-4 h-4 rounded-full text-[9px] font-bold flex items-center justify-center cursor-help shrink-0 select-none",style:{background:"var(--terminal-surface)",color:"var(--terminal-text-muted)",border:"1px solid var(--terminal-border)"},onMouseEnter:d,onMouseLeave:()=>a(!1),onClick:f=>{f.stopPropagation(),n?a(!1):d()},children:"?"}),n&&l.jsxs("div",{className:"fixed z-[9999] px-3 py-2 rounded-lg text-[11px] leading-relaxed whitespace-pre-line w-60 shadow-lg pointer-events-none",style:{top:i.top,left:Math.min(i.left,window.innerWidth-260),background:"var(--terminal-bg)",color:"var(--terminal-text-secondary)",border:"1px solid var(--terminal-border)"},children:[l.jsx("div",{className:"absolute bottom-full w-0 h-0",style:{left:8,borderLeft:"5px solid transparent",borderRight:"5px solid transparent",borderBottom:"5px solid var(--terminal-border)"}}),e]})]})}function jy({icon:e,title:n,hint:a,help:i,children:o}){return l.jsxs("div",{className:"rounded-lg p-3 space-y-2",style:{background:"var(--hud-bg-alt)",border:"1px solid var(--terminal-border)"},children:[l.jsxs("div",{children:[l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx("span",{className:"text-sm",children:e}),l.jsx("span",{className:"text-xs font-medium",style:{color:"var(--terminal-text)"},children:n}),i&&l.jsx(tp,{text:i})]}),l.jsx("div",{className:"text-[10px] mt-0.5 ml-6",style:{color:"var(--terminal-text-muted)"},children:a})]}),o]})}function Sy({icon:e,title:n,hint:a,help:i,tag:o,open:u,onToggle:d,children:f}){return l.jsxs("div",{className:"rounded-lg",style:{background:"var(--hud-bg-alt)",border:"1px solid var(--terminal-border)"},children:[l.jsxs("div",{className:"p-3 cursor-pointer flex items-center gap-2 hover:bg-[var(--terminal-surface-light)] transition-colors",onClick:d,children:[l.jsx("span",{className:"text-sm",children:e}),l.jsx("span",{className:"text-xs font-medium flex-1",style:{color:"var(--terminal-text)"},children:n}),i&&l.jsx(tp,{text:i}),o&&l.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded",style:{background:"var(--terminal-surface)",color:"var(--terminal-text-muted)"},children:o}),l.jsx("span",{className:"text-[10px]",style:{color:"var(--terminal-text-muted)"},children:u?"▲":"▼"})]}),!u&&l.jsx("div",{className:"px-3 pb-2 -mt-1",children:l.jsx("div",{className:"text-[10px] ml-6",style:{color:"var(--terminal-text-muted)"},children:a})}),u&&l.jsx("div",{className:"px-3 pb-3 space-y-2",children:f})]})}function A8(){const[e,n]=v.useState(null),[a,i]=v.useState(!0),[o,u]=v.useState(null),d=v.useCallback(async()=>{i(!0),u(null);try{const f=await ye.getStatus();n(f)}catch(f){u(f instanceof Error?f.message:"Failed to fetch status")}finally{i(!1)}},[]);return v.useEffect(()=>{d()},[d]),{initialized:(e==null?void 0:e.initialized)??!1,companyName:(e==null?void 0:e.companyName)??null,engine:(e==null?void 0:e.engine)??"none",companyRoot:(e==null?void 0:e.companyRoot)??"",loading:a,error:o,refetch:d}}const D8=v.lazy(()=>Ey(()=>import("./preview-app-PJU9PUoY.js"),[]));function Fv(){return l.jsx("div",{className:"h-full flex items-center justify-center",style:{background:"var(--floor-dark)"},children:l.jsxs("div",{className:"text-center",children:[l.jsx("div",{className:"w-10 h-10 mx-auto border-2 rounded-full animate-spin",style:{borderColor:"var(--terminal-border)",borderTopColor:"var(--accent)"}}),l.jsx("div",{className:"mt-4 text-sm",style:{color:"var(--terminal-text-secondary)",fontFamily:"var(--pixel-font)"},children:"Loading..."})]})})}function T8(){var e;try{const n=localStorage.getItem("tycono-theme"),a=n&&n in ll?n:"default",i=(e=ll[a])==null?void 0:e.vars;if(!i)return;const o=document.documentElement;for(const[u,d]of Object.entries(i))o.style.setProperty(u,d)}catch{}}function F8(){const{initialized:e,loading:n,refetch:a}=A8(),[i,o]=v.useState(null);v.useEffect(()=>{T8()},[]);const u=d=>{d&&o(d),a()};return n?l.jsx(Fv,{}):e?l.jsx(C8,{importJob:i,onImportDone:()=>o(null)}):l.jsx(N8,{onComplete:u})}function M8(){const e=new URLSearchParams(window.location.search).has("sprite-preview");return l.jsx(kw,{children:e?l.jsx(v.Suspense,{fallback:l.jsx(Fv,{}),children:l.jsx(D8,{})}):l.jsx(F8,{})})}bw.createRoot(document.getElementById("root")).render(l.jsx(v.StrictMode,{children:l.jsx(M8,{})}));export{ov as H,uv as P,dv as S,B8 as a,cv as b,sv as c,am as d,eC as e,z8 as f,_8 as g,O8 as h,l as j,v as r};
|
|
110
|
+
Skip this to start with an empty knowledge base. You can import documents anytime from the office.`,tag:"optional",open:de,onToggle:()=>V(!de),children:[l.jsxs("div",{className:"flex gap-2",children:[l.jsx("input",{className:`${nt} flex-1`,placeholder:"/path/to/docs",value:U,onChange:we=>T(we.target.value),onKeyDown:we=>{we.key==="Enter"&&(we.preventDefault(),Bt())}}),l.jsx("button",{onClick:()=>ge(!ie),className:"px-3 py-2 rounded text-xs font-medium transition-colors shrink-0 cursor-pointer hover:brightness-125",style:{background:"var(--terminal-surface)",color:"var(--terminal-text)",border:"1px solid var(--terminal-border)"},title:"Browse folders",children:"📁"}),l.jsx("button",{onClick:Bt,disabled:!U.trim(),className:"px-3 py-2 rounded text-xs font-medium shrink-0",style:{background:"var(--accent)",color:"#fff",opacity:U.trim()?1:.5},children:"Add"})]}),ie&&l.jsx(Au,{onSelect:we=>{D.includes(we)||B([...D,we]),ge(!1)},onClose:()=>ge(!1)}),D.length>0&&l.jsx("div",{className:"space-y-1 mt-2",children:D.map((we,kt)=>l.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 rounded text-xs",style:{background:"var(--terminal-bg)",color:"var(--terminal-text)",border:"1px solid var(--terminal-border)"},children:[l.jsx("span",{className:"flex-1 truncate",style:{fontFamily:"var(--pixel-font)"},children:we}),l.jsx("button",{onClick:()=>B(D.filter((ln,sn)=>sn!==kt)),className:"opacity-50 hover:opacity-100",children:"✕"})]},kt))})]})]}):l.jsx("div",{className:"space-y-3",children:l.jsxs(jy,{icon:"🔗",title:"AKB Path",hint:"Directory with existing CLAUDE.md and AKB structure.",help:"Connect to a directory that was previously set up with Tycono. It must contain a CLAUDE.md file. All existing roles, knowledge, and settings will be loaded.",children:[l.jsxs("div",{className:"flex gap-2",children:[l.jsx("input",{className:`${nt} flex-1`,placeholder:"/path/to/your/akb",value:pe,onChange:we=>{ze(we.target.value),He(null)},autoFocus:!0}),l.jsx("button",{onClick:()=>Ee(!et),className:"px-3 py-2 rounded text-xs font-medium transition-colors shrink-0 cursor-pointer hover:brightness-125",style:{background:"var(--terminal-surface)",color:"var(--terminal-text)",border:"1px solid var(--terminal-border)"},title:"Browse folders",children:"📁"}),l.jsx("button",{onClick:_t,disabled:st||!pe.trim(),className:"px-3 py-2 rounded text-xs font-medium transition-colors shrink-0",style:{background:"var(--accent)",color:"#fff",opacity:st||!pe.trim()?.5:1},children:st?"...":"Verify"})]}),Ie===!0&&l.jsxs("div",{className:"text-xs mt-2",style:{color:"var(--active-green)"},children:["✅"," Valid AKB found"]}),Ie===!1&&l.jsxs("div",{className:"text-xs mt-2",style:{color:"#EF4444"},children:["❌"," No valid AKB (CLAUDE.md required)"]}),et&&l.jsx(Au,{onSelect:we=>{ze(we),He(null),Ee(!1)},onClose:()=>Ee(!1)})]})})]}),rt==="team"&&l.jsxs("div",{className:"space-y-4",children:[l.jsx("h2",{className:"text-base font-semibold",style:{color:"var(--terminal-text)"},children:"Team Template"}),l.jsx("p",{className:"text-xs",style:{color:"var(--terminal-text-secondary)"},children:"Choose a starting team. You can add or remove roles later."}),De.map(we=>l.jsxs("div",{className:Qt(ut===we.id),onClick:()=>pt(we.id),children:[l.jsx("div",{className:"font-medium text-sm capitalize",children:we.id}),l.jsx("div",{className:"flex flex-wrap gap-1.5 mt-2",children:we.roles.map(kt=>l.jsx("span",{className:"px-2 py-0.5 rounded text-[10px]",style:{background:"var(--terminal-bg)",color:"var(--terminal-text)",border:"1px solid var(--terminal-border)"},children:kt.id.toUpperCase()},kt.id))})]},we.id)),l.jsxs("div",{className:Qt(ut==="custom"),onClick:()=>pt("custom"),children:[l.jsx("div",{className:"font-medium text-sm",children:"Custom"}),l.jsx("div",{className:"text-xs opacity-70 mt-1",children:"Start with no pre-built roles. Hire them from the office."})]})]}),rt==="create"&&l.jsxs("div",{className:"space-y-4",children:[l.jsx("h2",{className:"text-base font-semibold",style:{color:"var(--terminal-text)"},children:Ft?N==="existing-akb"?"AKB Connected!":"Company Created!":"Review & Create"}),!Ft&&!jt&&!te&&l.jsxs(l.Fragment,{children:[l.jsx("div",{className:"rounded-lg p-4 space-y-2 text-xs",style:{background:"var(--terminal-bg)",color:"var(--terminal-text)",border:"1px solid var(--terminal-border)",fontFamily:"var(--pixel-font)"},children:N==="existing-akb"?l.jsxs(l.Fragment,{children:[l.jsxs("div",{children:[l.jsx("span",{className:"opacity-50",children:"Mode:"})," Connect Existing AKB"]}),l.jsxs("div",{children:[l.jsx("span",{className:"opacity-50",children:"Path:"})," ",pe]}),l.jsxs("div",{children:[l.jsx("span",{className:"opacity-50",children:"Engine:"})," ",u==="claude-cli"?"Claude Code CLI":"Direct API"]})]}):l.jsxs(l.Fragment,{children:[l.jsxs("div",{children:[l.jsx("span",{className:"opacity-50",children:"Company:"})," ",g]}),l.jsxs("div",{children:[l.jsx("span",{className:"opacity-50",children:"Location:"})," ",z||"(default)"]}),l.jsxs("div",{children:[l.jsx("span",{className:"opacity-50",children:"Engine:"})," ",u==="claude-cli"?"Claude Code CLI":"Direct API"]}),se.trim()&&l.jsxs("div",{children:[l.jsx("span",{className:"opacity-50",children:"Code Repo:"})," ",se]}),l.jsxs("div",{children:[l.jsx("span",{className:"opacity-50",children:"Knowledge:"})," ",D.length>0?`Import ${D.length} source(s)`:"Fresh (empty)"]}),l.jsxs("div",{children:[l.jsx("span",{className:"opacity-50",children:"Team:"})," ",ut]}),D.length>0&&l.jsx("div",{className:"text-[10px] mt-1",style:{color:"var(--idle-amber)"},children:"Knowledge import will run in the background after entering the office."})]})}),$n&&l.jsx("div",{className:"text-xs p-3 rounded",style:{background:"rgba(220,38,38,0.15)",color:"#f87171"},children:$n})]}),(jt||te)&&l.jsxs("div",{className:"flex flex-col items-center py-8 gap-3",children:[l.jsx("div",{className:"w-8 h-8 border-2 rounded-full animate-spin",style:{borderColor:"var(--terminal-border)",borderTopColor:"var(--accent)"}}),l.jsx("div",{className:"text-sm",style:{color:"var(--terminal-text-secondary)"},children:te?"Connecting to AKB...":"Scaffolding your company..."})]}),Ft&&l.jsxs(l.Fragment,{children:[l.jsx("div",{className:"text-center py-4 text-4xl",children:"🏢"}),K&&l.jsxs("div",{className:"rounded-lg p-3 text-xs",style:{background:"var(--terminal-bg)",color:"var(--terminal-text)",border:"1px solid var(--terminal-border)",fontFamily:"var(--pixel-font)"},children:[l.jsx("span",{className:"opacity-50",children:"Location:"})," ",K]}),l.jsx("div",{className:"rounded-lg p-4 text-xs max-h-40 overflow-y-auto",style:{background:"var(--terminal-bg)",color:"var(--terminal-text)",border:"1px solid var(--terminal-border)",fontFamily:"var(--pixel-font)"},children:Se.map((we,kt)=>l.jsxs("div",{className:"py-0.5",children:[l.jsx("span",{style:{color:"var(--active-green)"},children:"✓"})," ",we]},kt))}),(ve||Be.length>0)&&l.jsxs("div",{className:"rounded-lg p-4 text-xs space-y-1",style:{background:"var(--terminal-bg)",color:"var(--terminal-text)",border:"1px solid var(--terminal-border)",fontFamily:"var(--pixel-font)"},children:[l.jsx("div",{className:"font-medium mb-2",style:{color:"var(--terminal-text-secondary)"},children:ve?"Installing skill tools...":"Skill tools"}),Be.map((we,kt)=>l.jsxs("div",{className:"py-0.5 flex items-center gap-2",children:[l.jsx("span",{style:{color:we.event==="installed"||we.event==="skipped"?"var(--active-green)":we.event==="error"?"#f87171":"var(--terminal-text-muted)"},children:we.event==="installed"||we.event==="skipped"?"✓":we.event==="error"?"✗":"…"}),l.jsx("span",{children:we.tool}),l.jsx("span",{style:{color:"var(--terminal-text-muted)"},children:we.detail})]},kt)),ve&&l.jsxs("div",{className:"flex items-center gap-2 mt-1",style:{color:"var(--terminal-text-muted)"},children:[l.jsx("div",{className:"w-3 h-3 border border-current rounded-full animate-spin",style:{borderTopColor:"var(--accent)"}}),l.jsx("span",{children:"Please wait..."})]})]}),D.length>0&&l.jsx("div",{className:"text-xs p-3 rounded",style:{background:"var(--accent)",color:"#fff",opacity:.9},children:"Knowledge import will start in the background after entering the office."})]})]})]}),l.jsxs("div",{className:"px-6 py-4 flex justify-between items-center",style:{borderTop:"1px solid var(--terminal-border)"},children:[l.jsx("div",{children:n>0&&!Ft&&l.jsx("button",{onClick:Re,className:"px-4 py-2 rounded text-sm transition-colors",style:{color:"var(--terminal-text-secondary)",border:"1px solid var(--terminal-border)"},children:"Back"})}),l.jsxs("div",{className:"text-xs",style:{color:"var(--terminal-text-muted)"},children:[n+1," / ",qe.length]}),l.jsx("div",{children:Ft?l.jsx("button",{onClick:Z,disabled:ve,className:"px-5 py-2 rounded text-sm font-medium transition-colors",style:{background:"var(--active-green)",color:"#fff",opacity:ve?.5:1},children:ve?"Setting up tools...":"Enter Office"}):l.jsx("button",{onClick:bt,disabled:!Ve()||jt||te,className:"px-5 py-2 rounded text-sm font-medium transition-colors",style:{background:Ve()?"var(--accent)":"var(--terminal-border)",color:"#fff",opacity:Ve()&&!jt&&!te?1:.5},children:rt==="create"?jt||te?te?"Connecting...":"Creating...":N==="existing-akb"?"Connect AKB":"Create Company":"Next"})})]})]})})}function tp({text:e}){const[n,a]=v.useState(!1),[i,o]=v.useState({top:0,left:0}),u=v.useRef(null),d=()=>{if(u.current){const f=u.current.getBoundingClientRect();o({top:f.bottom+6,left:f.left})}a(!0)};return l.jsxs("span",{className:"inline-flex",ref:u,children:[l.jsx("span",{className:"w-4 h-4 rounded-full text-[9px] font-bold flex items-center justify-center cursor-help shrink-0 select-none",style:{background:"var(--terminal-surface)",color:"var(--terminal-text-muted)",border:"1px solid var(--terminal-border)"},onMouseEnter:d,onMouseLeave:()=>a(!1),onClick:f=>{f.stopPropagation(),n?a(!1):d()},children:"?"}),n&&l.jsxs("div",{className:"fixed z-[9999] px-3 py-2 rounded-lg text-[11px] leading-relaxed whitespace-pre-line w-60 shadow-lg pointer-events-none",style:{top:i.top,left:Math.min(i.left,window.innerWidth-260),background:"var(--terminal-bg)",color:"var(--terminal-text-secondary)",border:"1px solid var(--terminal-border)"},children:[l.jsx("div",{className:"absolute bottom-full w-0 h-0",style:{left:8,borderLeft:"5px solid transparent",borderRight:"5px solid transparent",borderBottom:"5px solid var(--terminal-border)"}}),e]})]})}function jy({icon:e,title:n,hint:a,help:i,children:o}){return l.jsxs("div",{className:"rounded-lg p-3 space-y-2",style:{background:"var(--hud-bg-alt)",border:"1px solid var(--terminal-border)"},children:[l.jsxs("div",{children:[l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx("span",{className:"text-sm",children:e}),l.jsx("span",{className:"text-xs font-medium",style:{color:"var(--terminal-text)"},children:n}),i&&l.jsx(tp,{text:i})]}),l.jsx("div",{className:"text-[10px] mt-0.5 ml-6",style:{color:"var(--terminal-text-muted)"},children:a})]}),o]})}function Sy({icon:e,title:n,hint:a,help:i,tag:o,open:u,onToggle:d,children:f}){return l.jsxs("div",{className:"rounded-lg",style:{background:"var(--hud-bg-alt)",border:"1px solid var(--terminal-border)"},children:[l.jsxs("div",{className:"p-3 cursor-pointer flex items-center gap-2 hover:bg-[var(--terminal-surface-light)] transition-colors",onClick:d,children:[l.jsx("span",{className:"text-sm",children:e}),l.jsx("span",{className:"text-xs font-medium flex-1",style:{color:"var(--terminal-text)"},children:n}),i&&l.jsx(tp,{text:i}),o&&l.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded",style:{background:"var(--terminal-surface)",color:"var(--terminal-text-muted)"},children:o}),l.jsx("span",{className:"text-[10px]",style:{color:"var(--terminal-text-muted)"},children:u?"▲":"▼"})]}),!u&&l.jsx("div",{className:"px-3 pb-2 -mt-1",children:l.jsx("div",{className:"text-[10px] ml-6",style:{color:"var(--terminal-text-muted)"},children:a})}),u&&l.jsx("div",{className:"px-3 pb-3 space-y-2",children:f})]})}function A8(){const[e,n]=v.useState(null),[a,i]=v.useState(!0),[o,u]=v.useState(null),d=v.useCallback(async()=>{i(!0),u(null);try{const f=await ye.getStatus();n(f)}catch(f){u(f instanceof Error?f.message:"Failed to fetch status")}finally{i(!1)}},[]);return v.useEffect(()=>{d()},[d]),{initialized:(e==null?void 0:e.initialized)??!1,companyName:(e==null?void 0:e.companyName)??null,engine:(e==null?void 0:e.engine)??"none",companyRoot:(e==null?void 0:e.companyRoot)??"",loading:a,error:o,refetch:d}}const D8=v.lazy(()=>Ey(()=>import("./preview-app-Cu2HapST.js"),[]));function Fv(){return l.jsx("div",{className:"h-full flex items-center justify-center",style:{background:"var(--floor-dark)"},children:l.jsxs("div",{className:"text-center",children:[l.jsx("div",{className:"w-10 h-10 mx-auto border-2 rounded-full animate-spin",style:{borderColor:"var(--terminal-border)",borderTopColor:"var(--accent)"}}),l.jsx("div",{className:"mt-4 text-sm",style:{color:"var(--terminal-text-secondary)",fontFamily:"var(--pixel-font)"},children:"Loading..."})]})})}function T8(){var e;try{const n=localStorage.getItem("tycono-theme"),a=n&&n in ll?n:"default",i=(e=ll[a])==null?void 0:e.vars;if(!i)return;const o=document.documentElement;for(const[u,d]of Object.entries(i))o.style.setProperty(u,d)}catch{}}function F8(){const{initialized:e,loading:n,refetch:a}=A8(),[i,o]=v.useState(null);v.useEffect(()=>{T8()},[]);const u=d=>{d&&o(d),a()};return n?l.jsx(Fv,{}):e?l.jsx(C8,{importJob:i,onImportDone:()=>o(null)}):l.jsx(N8,{onComplete:u})}function M8(){const e=new URLSearchParams(window.location.search).has("sprite-preview");return l.jsx(kw,{children:e?l.jsx(v.Suspense,{fallback:l.jsx(Fv,{}),children:l.jsx(D8,{})}):l.jsx(F8,{})})}bw.createRoot(document.getElementById("root")).render(l.jsx(v.StrictMode,{children:l.jsx(M8,{})}));export{ov as H,uv as P,dv as S,B8 as a,cv as b,sv as c,am as d,eC as e,z8 as f,_8 as g,O8 as h,l as j,v as r};
|