@runfusion/fusion 0.2.7 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/dist/bin.js +55392 -51635
  2. package/dist/client/assets/{AgentDetailView-BMrHuWGs.css → AgentDetailView-C1b9PC5l.css} +1 -1
  3. package/dist/client/assets/{AgentDetailView-B4lRk--v.js → AgentDetailView-DJwWfkpv.js} +1 -1
  4. package/dist/client/assets/{AgentsView-yCYBY2km.js → AgentsView-DegK8aw-.js} +5 -5
  5. package/dist/client/assets/ChatView-CYpEShLS.js +1 -0
  6. package/dist/client/assets/{DevServerView-jXXtoQUx.js → DevServerView-DfCTA9fx.js} +2 -2
  7. package/dist/client/assets/{DirectoryPicker-izgMlS27.js → DirectoryPicker-B0qNpfLW.js} +1 -1
  8. package/dist/client/assets/DirectoryPicker-DzKVmxOf.css +1 -0
  9. package/dist/client/assets/{DocumentsView-DkkoHRwL.js → DocumentsView-CsQxuyz3.js} +1 -1
  10. package/dist/client/assets/{InsightsView-DaRtUPHX.js → InsightsView-Bzs7A2jv.js} +2 -2
  11. package/dist/client/assets/MemoryView-Cl5ASqjW.js +2 -0
  12. package/dist/client/assets/MemoryView-DiajLXby.css +1 -0
  13. package/dist/client/assets/{NodesView-BsUk_oiU.js → NodesView-BpiqRlvc.js} +1 -1
  14. package/dist/client/assets/PiExtensionsManager-Cr6EoC7S.js +11 -0
  15. package/dist/client/assets/PiExtensionsManager-kgTOHPE9.css +1 -0
  16. package/dist/client/assets/PluginManager-DRiIqol2.css +1 -0
  17. package/dist/client/assets/PluginManager-DXtQdfns.js +1 -0
  18. package/dist/client/assets/{RoadmapsView-SQol126Y.js → RoadmapsView-CYPLTTB0.js} +2 -2
  19. package/dist/client/assets/SettingsModal-CDWvhvrd.css +1 -0
  20. package/dist/client/assets/SettingsModal-CNdVTVqD.js +1 -0
  21. package/dist/client/assets/SettingsModal-CyCC7MzL.js +31 -0
  22. package/dist/client/assets/SettingsModal-G0ESQXRD.css +1 -0
  23. package/dist/client/assets/{SetupWizardModal-CQc1uGSq.js → SetupWizardModal-BLiljNn7.js} +1 -1
  24. package/dist/client/assets/SetupWizardModal-BMa6p24b.css +1 -0
  25. package/dist/client/assets/SkillsView-Dlpw5LKI.js +1 -0
  26. package/dist/client/assets/{folder-open-CI4TCD7P.js → folder-open-B_38R5AA.js} +1 -1
  27. package/dist/client/assets/index-DQKtk17v.js +616 -0
  28. package/dist/client/assets/index-DjOxzdj3.css +1 -0
  29. package/dist/client/assets/{upload-CAlKC4qI.js → upload-DNQF7XCK.js} +1 -1
  30. package/dist/client/assets/users-CG2_rCdk.js +6 -0
  31. package/dist/client/index.html +2 -2
  32. package/dist/client/version.json +1 -0
  33. package/dist/extension.js +3222 -937
  34. package/dist/pi-claude-cli/index.ts +72 -28
  35. package/dist/pi-claude-cli/package.json +1 -1
  36. package/dist/pi-claude-cli/src/__tests__/event-bridge.test.ts +34 -0
  37. package/dist/pi-claude-cli/src/__tests__/mcp-config.test.ts +22 -0
  38. package/dist/pi-claude-cli/src/__tests__/prompt-builder.test.ts +72 -10
  39. package/dist/pi-claude-cli/src/__tests__/provider.test.ts +9 -9
  40. package/dist/pi-claude-cli/src/event-bridge.ts +17 -6
  41. package/dist/pi-claude-cli/src/mcp-config.ts +36 -3
  42. package/dist/pi-claude-cli/src/prompt-builder.ts +111 -7
  43. package/dist/pi-claude-cli/src/provider.ts +17 -2
  44. package/package.json +17 -16
  45. package/skill/fusion/SKILL.md +6 -1
  46. package/skill/fusion/references/engine-tools.md +54 -0
  47. package/skill/fusion/references/extension-tools.md +83 -84
  48. package/skill/fusion/references/fusion-capabilities.md +33 -31
  49. package/LICENSE +0 -21
  50. package/dist/client/assets/ChatView-CH9T0dDs.js +0 -1
  51. package/dist/client/assets/MemoryView-85NKuU3h.js +0 -2
  52. package/dist/client/assets/MemoryView-DhinauGs.css +0 -1
  53. package/dist/client/assets/PiExtensionsManager-BF5pxrSE.js +0 -11
  54. package/dist/client/assets/PiExtensionsManager-K7HQ08L4.css +0 -1
  55. package/dist/client/assets/PluginManager-ccq3uK50.css +0 -1
  56. package/dist/client/assets/PluginManager-s6btydh5.js +0 -1
  57. package/dist/client/assets/SkillsView-BtUhs_QW.js +0 -1
  58. package/dist/client/assets/index-Ct-OqLpP.css +0 -1
  59. package/dist/client/assets/index-rNf7s96d.js +0 -649
@@ -0,0 +1 @@
1
+ import{r as s,j as e}from"./vendor-react-K0fH_qHe.js";import{i as _e,aw as ut,g as ht,ax as mt,a as gt,ay as ft,az as pt,aA as xt,aB as St,aC as bt,aD as vt,s as wt,aE as kt,aF as Nt,f as Ct,a5 as jt,a6 as Mt,w as Re,S as yt,I as He,ai as Tt,aG as At,B as je,a2 as Ge,a3 as Ue,aH as $t,aI as Et,aJ as Pt,aK as Dt,aL as Rt,aM as Lt,h as _t,j as zt}from"./index-DQKtk17v.js";import"./vendor-xterm-DzcZoU0P.js";const Le="kb-chat-active-session";function It(n){const i=n?.toolCalls;if(!Array.isArray(i))return;const c=i.map(l=>{if(!l||typeof l!="object")return null;const r=l,f=typeof r.toolName=="string"?r.toolName:"";if(!f)return null;const v=r.args;return{toolName:f,...v&&typeof v=="object"?{args:v}:{},isError:!!r.isError,result:r.result,status:"completed"}}).filter(l=>l!==null);return c.length>0?c:void 0}function qe(n){return{id:n.id,sessionId:n.sessionId,role:n.role,content:n.content,thinkingOutput:n.thinkingOutput,toolCalls:It(n.metadata),createdAt:n.createdAt}}function Ft(n){const[i,c]=s.useState([]),[l,r]=s.useState(null),[f,v]=s.useState(!0),[M,w]=s.useState([]),[X,I]=s.useState(!1),[F,R]=s.useState(!1),[ce,E]=s.useState(""),[O,T]=s.useState(""),[pe,P]=s.useState([]),[p,D]=s.useState(""),[Z,U]=s.useState(""),[A,V]=s.useState(!0),[q,ne]=s.useState(new Map),N=s.useRef(null),J=s.useRef(!1),K=s.useRef(""),xe=s.useRef(i),B=s.useRef(l),ke=s.useRef(F);xe.current=i,B.current=l,ke.current=F,s.useEffect(()=>{K.current=p},[p]);const ae=s.useRef(new Set),ee=s.useRef(0),Ne=s.useRef(n);Ne.current!==n&&(Ne.current=n,ee.current++),s.useEffect(()=>{const u=ee.current;_e(void 0,n).then(m=>{if(ee.current!==u)return;const h=new Map;for(const k of m)h.set(k.id,k);ne(h)}).catch(()=>{})},[n]);const te=s.useCallback(async()=>{v(!0);try{const m=[...(await ut(n)).sessions].sort((h,k)=>new Date(k.updatedAt).getTime()-new Date(h.updatedAt).getTime());c(m)}catch{}finally{v(!1)}},[n]);s.useEffect(()=>{te()},[te]);const Q=s.useRef(()=>{});s.useEffect(()=>{if(f)return;const u=ht(Le,n);u&&i.find(h=>h.id===u)&&Q.current(u)},[f,i,n]);const _=s.useCallback(async(u,m)=>{I(!0);try{const h=await mt(u,{limit:50,...m},n),k=h.messages.map(qe);m?.offset&&m.offset>0?w(W=>[...k,...W]):w(k),V(h.messages.length>=50)}catch{}finally{I(!1)}},[n]),oe=s.useCallback(u=>{N.current&&(N.current.close(),N.current=null);const m=i.find(h=>h.id===u);r(m||null),E(""),T(""),P([]),R(!1),V(!0),u?_(u):w([]),u?gt(Le,u,n):ft(Le,n)},[i,_,n]);Q.current=oe;const de=s.useCallback(async u=>{const m=await pt(u,n),h={id:m.session.id,title:m.session.title,agentId:m.session.agentId,status:m.session.status,modelProvider:m.session.modelProvider,modelId:m.session.modelId,createdAt:m.session.createdAt,updatedAt:m.session.updatedAt};return c(k=>[h,...k]),r(h),w([]),E(""),T(""),P([]),R(!1),V(!0),h},[n]),ue=s.useCallback(async u=>{await xt(u,{status:"archived"},n),c(m=>m.filter(h=>h.id!==u)),l?.id===u&&(r(null),w([]))},[l,n]),ie=s.useCallback(async u=>{l?.id===u&&N.current&&(N.current.close(),N.current=null),await St(u,n),c(m=>m.filter(h=>h.id!==u)),l?.id===u&&(r(null),w([]))},[l,n]),he=s.useCallback(async()=>{!l||!A||await _(l.id,{offset:M.length})},[l,A,_,M.length]),se=s.useCallback(()=>{l&&(J.current=!0,N.current?.close(),N.current=null,bt(l.id,n).catch(()=>{}),R(!1),E(""),T(""),P([]))},[l,n]),H=s.useCallback(()=>{K.current="",D("")},[]),G=s.useCallback(u=>{if(!l)return;if(F){K.current=u,D(u);return}J.current=!1,N.current&&(N.current.close(),N.current=null);const m=`temp-${Date.now()}`,h={id:m,sessionId:l.id,role:"user",content:u,createdAt:new Date().toISOString()};w(x=>[...x,h]),E(""),T(""),P([]),R(!0);let k="",W="",j=[];const be={onThinking:x=>{W+=x,T(W)},onText:x=>{k+=x,E(k)},onToolStart:x=>{j=[...j,{toolName:x.toolName,args:x.args,isError:!1,status:"running"}],P(j)},onToolEnd:x=>{const d=[...j];for(let S=d.length-1;S>=0;S--){const b=d[S];if(b?.toolName===x.toolName&&b.status==="running"){d[S]={...b,status:"completed",isError:x.isError,result:x.result},j=d,P(d);return}}j=[...d,{toolName:x.toolName,isError:x.isError,result:x.result,status:"completed"}],P(j)},onDone:x=>{const d={id:x.messageId||`msg-${Date.now()}`,sessionId:l.id,role:"assistant",content:k,thinkingOutput:W,toolCalls:j.length>0?j:void 0,createdAt:new Date().toISOString()};ae.current.add(d.id),w(b=>[...b,d]),E(""),T(""),P([]),R(!1),N.current=null,setTimeout(()=>{ae.current.delete(d.id)},1e3),te();const S=K.current.trim();S&&(K.current="",D(""),G(S))},onError:x=>{if(w(d=>d.filter(S=>S.id!==m)),E(""),T(""),P([]),R(!1),N.current=null,console.error("[useChat] Stream error:",x),!J.current){const d=K.current.trim();d&&(K.current="",D(""),G(d))}}};N.current=vt(l.id,u,be,n)},[l,F,n,te]),Se=Z?i.filter(u=>u.title?.toLowerCase().includes(Z.toLowerCase())||u.agentId.toLowerCase().includes(Z.toLowerCase())):i;return s.useEffect(()=>{const u=ee.current,m=n?`?projectId=${encodeURIComponent(n)}`:"",h=()=>ee.current!==u,k=S=>{if(h())return;const b=JSON.parse(S.data);c(g=>g.some(L=>L.id===b.id)?g:[b,...g])},W=S=>{if(h())return;const b=JSON.parse(S.data);c(g=>[...g.map(C=>C.id===b.id?b:C)]),B.current?.id===b.id&&r(b)},j=S=>{if(h())return;const{id:b}=JSON.parse(S.data);c(g=>g.filter(L=>L.id!==b)),B.current?.id===b&&(r(null),w([]))},be=S=>{if(h())return;const b=JSON.parse(S.data),g=qe(b);ae.current.has(g.id)||B.current?.id===g.sessionId&&!ke.current&&w(L=>L.some(C=>C.id===g.id)?L:[...L,g])},x=S=>{if(h())return;const{id:b}=JSON.parse(S.data);w(g=>g.filter(L=>L.id!==b))};return wt(`/api/events${m}`,{events:{"chat:session:created":k,"chat:session:updated":W,"chat:session:deleted":j,"chat:message:added":be,"chat:message:deleted":x}})},[n]),s.useEffect(()=>()=>{N.current&&(N.current.close(),N.current=null)},[]),{sessions:i,activeSession:l,sessionsLoading:f,messages:M,messagesLoading:X,isStreaming:F,streamingText:ce,streamingThinking:O,streamingToolCalls:pe,pendingMessage:p,selectSession:oe,createSession:de,archiveSession:ue,deleteSession:ie,sendMessage:G,stopStreaming:se,clearPendingMessage:H,loadMoreMessages:he,hasMoreMessages:A,searchQuery:Z,setSearchQuery:U,filteredSessions:Se,refreshSessions:te,agentsMap:q}}function Je(n){const i=new Date(n),l=new Date().getTime()-i.getTime(),r=Math.floor(l/1e3),f=Math.floor(r/60),v=Math.floor(f/60),M=Math.floor(v/24);return r<60?"just now":f<60?`${f}m ago`:v<24?`${v}h ago`:M<7?`${M}d ago`:i.toLocaleDateString()}function Ke(n,i){if(!n||!i)return null;const c=i.toLowerCase();if(c.includes("claude")){let r=i.replace(/^claude[- ]/i,"Claude ").replace(/sonnet[- ](\d+)[- ](\d+)/i,"Sonnet $1.$2").replace(/sonnet[- ](\d+)/i,"Sonnet $1").replace(/haiku[- ](\d+)/i,"Haiku $1").replace(/opus[- ](\d+)/i,"Opus $1").replace(/sonnet/i,"Sonnet").replace(/haiku/i,"Haiku").replace(/opus/i,"Opus").replace(/-/g," ").trim();return r=r.replace(/\s+/g," "),r.length>30?r.slice(0,30)+"…":r}if(c.includes("gpt")||c.includes("openai")){const r=i.replace(/^gpt-4-turbo$/i,"GPT-4 Turbo").replace(/^gpt-4o-mini$/i,"GPT-4o Mini").replace(/^gpt-4o$/i,"GPT-4o").replace(/^gpt-4$/i,"GPT-4").replace(/^gpt-o1-preview$/i,"GPT-o1 Preview").replace(/^gpt-o1-mini$/i,"GPT-o1 Mini").replace(/^gpt-o1$/i,"GPT-o1").replace(/^gpt/i,"GPT").trim();return r.length>30?r.slice(0,30)+"…":r}if(c.includes("gemini")){const r=i.replace(/^gemini[- ]/i,"Gemini ").replace(/pro[- ](\d+)[- ](\d+)/i,"Pro $1.$2").replace(/pro[- ](\d+)/i,"Pro $1").replace(/-/g," ").replace(/\s+/g," ").trim();return r.length>30?r.slice(0,30)+"…":r}const l=i.replace(/-/g," ").replace(/^\w/,r=>r.toUpperCase()).replace(/\s+/g," ").trim();return l.length>30?l.slice(0,30)+"…":l}function Me(n,i){return n.length>i?`${n.slice(0,i)}…`:n}function Ot(n){if(!n)return null;const i=Object.entries(n);return i.length===0?null:i.map(([c,l])=>{let r="";if(typeof l=="string")r=l;else try{r=JSON.stringify(l)}catch{r=String(l)}return`${c}=${Me(r,50)}`}).join(", ")}function Vt(n){if(n===void 0)return null;if(typeof n=="string")return Me(n,200);try{return Me(JSON.stringify(n),200)}catch{return Me(String(n),200)}}function Qe(n){return!n||n.length===0?null:e.jsxs("div",{className:"chat-tool-calls","data-testid":"chat-tool-calls",children:[e.jsxs("div",{className:"chat-tool-calls-header",children:[e.jsx(Lt,{size:12,"aria-hidden":"true"}),e.jsx("span",{children:"Tool calls"})]}),n.map((i,c)=>{const l=i.status==="running",r=i.status==="completed"&&i.isError,f=Ot(i.args),v=Vt(i.result),M=l?f:v?`result: ${v}`:f?`args: ${f}`:null,w=l?"running":r?"error":"completed";return e.jsxs("details",{className:`chat-tool-call${l?" chat-tool-call--running":""}${r?" chat-tool-call--error":""}`,open:l,children:[e.jsxs("summary",{children:[e.jsx("span",{className:"chat-tool-call-status-dot","aria-hidden":"true"}),e.jsx("span",{className:"chat-tool-call-name",children:i.toolName}),M&&e.jsx("span",{className:"chat-tool-call-preview",title:M,children:M}),e.jsx("span",{className:"chat-tool-call-status-text",children:w})]}),e.jsxs("div",{className:"chat-tool-call-content",children:[f&&e.jsxs("div",{className:"chat-tool-call-row",children:[e.jsx("span",{className:"chat-tool-call-label",children:"args"}),e.jsx("span",{className:"chat-tool-call-value",children:f})]}),v&&e.jsxs("div",{className:`chat-tool-call-row${r?" chat-tool-call-row--error":""}`,children:[e.jsx("span",{className:"chat-tool-call-label",children:"result"}),e.jsx("span",{className:"chat-tool-call-value",children:v})]})]})]},`${i.toolName}-${c}`)})]})}const Bt={pre:({children:n,...i})=>e.jsx("pre",{...i,className:"chat-markdown-pre",children:n}),table:({children:n,...i})=>e.jsx("table",{...i,className:"chat-markdown-table",children:n})},ye="__fn_agent__";function We(n){const i=/(^|[\s])\/([^\s]*)$/.exec(n);if(!i)return null;const c=i[1]??"",l=i[2]??"",r=i.index+c.length;return{filter:l,start:r,end:n.length}}function Ht(n,i){const c=n.slice(0,i),l=/(^|[\s\n])@([\w-]*)$/.exec(c);if(!l)return null;const r=l[2]??"",f=c.length-r.length-1;return{filter:r,start:f,end:i}}function Gt({projectId:n,onClose:i,onCreate:c}){const[l,r]=s.useState("agent"),[f,v]=s.useState([]),[M,w]=s.useState(!0),[X,I]=s.useState(""),[F,R]=s.useState([]),[ce,E]=s.useState(!0),[O,T]=s.useState("");s.useEffect(()=>{let p=!1;return w(!0),_e(void 0,n).then(D=>{p||v(D)}).catch(()=>{p||v([])}).finally(()=>{p||w(!1)}),()=>{p=!0}},[n]),s.useEffect(()=>{E(!0),_t().then(p=>{R(p.models)}).catch(()=>{R([])}).finally(()=>{E(!1)})},[]);const pe=p=>{if(p.preventDefault(),l==="agent"){if(!X)return;c({agentId:X});return}if(!O)return;const D=O.indexOf("/");if(D<=0)return;const Z=O.slice(0,D),U=O.slice(D+1);c({agentId:ye,modelProvider:Z,modelId:U})},P=l==="agent"?!X:!O;return e.jsx("div",{className:"chat-new-dialog-backdrop",onClick:i,role:"dialog","aria-modal":"true",children:e.jsxs("div",{className:"chat-new-dialog",onClick:p=>p.stopPropagation(),children:[e.jsx("h3",{children:"New Chat"}),e.jsxs("div",{className:"chat-new-dialog-mode-toggle","data-testid":"chat-new-dialog-mode-toggle",children:[e.jsx("button",{type:"button",className:`chat-new-dialog-mode-btn${l==="agent"?" chat-new-dialog-mode-btn--active":""}`,"data-testid":"chat-new-dialog-mode-agent",onClick:()=>{r("agent"),T("")},children:"Agent"}),e.jsx("button",{type:"button",className:`chat-new-dialog-mode-btn${l==="model"?" chat-new-dialog-mode-btn--active":""}`,"data-testid":"chat-new-dialog-mode-model",onClick:()=>{r("model"),I("")},children:"Model"})]}),e.jsxs("form",{onSubmit:pe,children:[l==="agent"&&e.jsxs("label",{className:"chat-new-dialog-model-label",children:["Agent",M?e.jsx("div",{className:"chat-new-dialog-loading",children:"Loading agents..."}):f.length===0?e.jsx("div",{className:"chat-new-dialog-empty",children:"No agents available"}):e.jsx("div",{className:"chat-new-dialog-agent-list",children:f.map(p=>e.jsxs("button",{type:"button",className:`chat-new-dialog-agent-item${X===p.id?" chat-new-dialog-agent-item--selected":""}`,onClick:()=>I(p.id),"data-testid":`agent-option-${p.id}`,children:[e.jsx(je,{size:16}),e.jsx("span",{className:"chat-new-dialog-agent-name",children:p.name}),e.jsx("span",{className:"chat-new-dialog-agent-role",children:p.role})]},p.id))})]}),l==="model"&&e.jsx("div",{className:"chat-new-dialog-model-dropdown","data-testid":"chat-new-dialog-model-section",children:ce?e.jsx("div",{className:"chat-new-dialog-loading",children:"Loading models..."}):e.jsx(zt,{models:F,value:O,onChange:T,label:"Model",placeholder:"Select a model"})}),e.jsxs("div",{className:"chat-new-dialog-actions",children:[e.jsx("button",{type:"button",className:"btn btn-sm",onClick:i,children:"Cancel"}),e.jsx("button",{type:"submit",className:"btn btn-sm btn-primary",disabled:P,children:"Create"})]})]})]})})}function Qt({projectId:n,addToast:i}){const{activeSession:c,sessionsLoading:l,messages:r,messagesLoading:f,isStreaming:v,streamingText:M,streamingThinking:w,streamingToolCalls:X,selectSession:I,createSession:F,archiveSession:R,deleteSession:ce,sendMessage:E,stopStreaming:O,pendingMessage:T,clearPendingMessage:pe,searchQuery:P,setSearchQuery:p,filteredSessions:D}=Ft(n),[Z,U]=s.useState(!1),[A,V]=s.useState(""),[q,ne]=s.useState(null),[N,J]=s.useState(null),[K,xe]=s.useState(!0),[B,ke]=s.useState(new Map),[ae,ee]=s.useState([]),[Ne,te]=s.useState(!0),[Q,_]=s.useState(!1),[oe,de]=s.useState(""),[ue,ie]=s.useState(0),[he,se]=s.useState(""),[H,G]=s.useState(!1),[Se,u]=s.useState(0),[m,h]=s.useState(-1),[k,W]=s.useState(()=>new Set),[,j]=s.useState(!1),[be,x]=s.useState({top:0,left:0}),d=kt({projectId:n}),S=s.useCallback(t=>{if(!t||!d.mentionActive)return;const a=t.getBoundingClientRect();x({top:a.top-260,left:a.left+8})},[d.mentionActive]),b=s.useRef(null),g=s.useRef(null),L=s.useRef(null),C=s.useRef(null),ve=s.useRef(0),me=Nt()==="mobile",z=s.useMemo(()=>{const t=oe.trim().toLowerCase();return(t?ae.filter(o=>o.name.toLowerCase().includes(t)):ae).slice(0,10)},[ae,oe]),ge=s.useMemo(()=>Array.from(B.values()),[B]),le=s.useMemo(()=>{const t=he.trim().toLowerCase();return t?ge.filter(a=>a.name.toLowerCase().includes(t)):ge},[ge,he]),ze=s.useMemo(()=>{const t=new Map;for(const a of ge)t.set(a.name.toLowerCase(),a);return t},[ge]);s.useEffect(()=>{ie(0)},[z]),s.useEffect(()=>{u(0)},[he,H]),s.useEffect(()=>()=>{g.current!==null&&window.clearTimeout(g.current)},[]),s.useEffect(()=>{b.current?.scrollIntoView({behavior:"smooth"})},[r,M]),s.useEffect(()=>{const t=()=>ne(null);if(q)return document.addEventListener("click",t),()=>document.removeEventListener("click",t)},[q]),s.useEffect(()=>{let t=!1;const a=n;return _e(void 0,n).then(o=>{if(t||a!==n)return;const y=new Map;for(const $ of o)y.set($.id,$);ke(y)}).catch(()=>{}),()=>{t=!0}},[n]),s.useEffect(()=>{let t=!1;return te(!0),Ct(n).then(a=>{t||ee(a)}).catch(()=>{t||ee([])}).finally(()=>{t||te(!1)}),()=>{t=!0}},[n]);const Ye=s.useCallback(async t=>{try{await F(t),U(!1),me&&xe(!1)}catch{i("Failed to create chat session","error")}},[F,i,me]),Te=s.useCallback(()=>{const t=A.trim();!t||!c||(V(""),_(!1),de(""),G(!1),se(""),h(-1),E(t))},[A,c,E]),Ae=s.useCallback(t=>{V(a=>{const o=We(a);if(!o)return a;const y=`/skill:${t.name} `,$=a.slice(0,o.start)+y+a.slice(o.end);return window.requestAnimationFrame(()=>{C.current&&(C.current.style.height="auto",C.current.style.height=`${Math.min(C.current.scrollHeight,120)}px`,C.current.focus())}),$}),_(!1),de(""),ie(0)},[]),$e=s.useCallback(t=>{const a=C.current;if(!a||m<0)return;const o=a.selectionStart??ve.current,y=a.selectionEnd??o,$=Math.max(o,y),we=Math.min(m,$),re=`${`@${t.name.replace(/\s+/g,"_")}`} `,De=A.slice(0,we)+re+A.slice($),fe=we+re.length;V(De),G(!1),se(""),u(0),h(-1),window.requestAnimationFrame(()=>{C.current&&(C.current.style.height="auto",C.current.style.height=`${Math.min(C.current.scrollHeight,120)}px`,C.current.focus(),C.current.setSelectionRange(fe,fe))})},[m,A]),Xe=s.useCallback(t=>{const a=/@([\w-]+)/g,o=[];let y=0,$=a.exec(t);for(;$;){const[we,Be=""]=$,re=$.index;re>y&&o.push(t.slice(y,re));const De=Be.replace(/_/g," ").toLowerCase(),fe=ze.get(De);fe?o.push(e.jsxs("span",{className:"chat-mention-chip",children:["@",fe.name.replace(/\s+/g,"_")]},`${fe.id}-${re}`)):o.push(we),y=re+we.length,$=a.exec(t)}return y<t.length&&o.push(t.slice(y)),o.length===0?t:o},[ze]),Ze=s.useCallback(t=>{if(ve.current=t.currentTarget.selectionStart??ve.current,d.mentionActive&&d.files.length>0){if(d.handleKeyDown(t,A),t.key==="Enter"||t.key==="Tab"){const a=d.files[d.selectedIndex];if(a){const o=d.selectFile(a,A);V(o),d.dismissMention(),j(!1)}}return}if(H&&t.key==="ArrowDown"){t.preventDefault(),le.length>0&&u(a=>(a+1)%le.length);return}if(H&&t.key==="ArrowUp"){t.preventDefault(),le.length>0&&u(a=>a===0?le.length-1:a-1);return}if(H&&t.key==="Enter"){t.preventDefault();const a=le[Se]??le[0];a&&$e(a);return}if(H&&t.key==="Escape"){t.preventDefault(),G(!1),se(""),h(-1);return}if(Q&&t.key==="ArrowDown"){t.preventDefault(),z.length>0&&ie(a=>(a+1)%z.length);return}if(Q&&t.key==="ArrowUp"){t.preventDefault(),z.length>0&&ie(a=>a===0?z.length-1:a-1);return}if(Q&&(t.key==="Enter"||t.key==="Tab")&&z.length>0){t.preventDefault();const a=z[ue]??z[0];a&&Ae(a);return}if(Q&&t.key==="Escape"){t.preventDefault(),_(!1);return}t.key==="Enter"&&!t.shiftKey&&(t.preventDefault(),Te())},[H,le,Se,$e,Q,z,ue,Ae,Te,d,A]),Ce=s.useCallback((t,a)=>{const o=Ht(t,a);if(o){G(!0),se(o.filter),h(o.start);return}G(!1),se(""),h(-1)},[]),et=s.useCallback(t=>{const a=t.target,o=a.value,y=a.selectionStart??o.length;ve.current=y,V(o);const $=We(o);$?(_(!0),de($.filter)):(_(!1),de("")),Ce(o,y),d.detectMention(o,y),j(d.mentionActive),d.mentionActive&&S(a),a.style.height="auto",a.style.height=`${Math.min(a.scrollHeight,120)}px`},[Ce]),Ee=s.useCallback(t=>{const a=t.currentTarget,o=a.selectionStart??a.value.length;ve.current=o,Ce(a.value,o),d.detectMention(a.value,o),j(d.mentionActive),d.mentionActive&&S(a)},[Ce,d,S]),tt=s.useCallback(t=>{t.key!=="Escape"&&Ee(t)},[Ee]),st=s.useCallback(()=>{g.current!==null&&window.clearTimeout(g.current),g.current=window.setTimeout(()=>{_(!1),G(!1),se(""),h(-1),j(!1),d.dismissMention(),g.current=null},120)},[d]),nt=s.useCallback(()=>{g.current!==null&&(window.clearTimeout(g.current),g.current=null)},[]),at=s.useCallback(async t=>{ne(null);try{await R(t),i("Conversation archived","success")}catch{i("Failed to archive conversation","error")}},[R,i]),it=s.useCallback(async t=>{J(null),ne(null);try{await ce(t),i("Conversation deleted","success")}catch{i("Failed to delete conversation","error")}},[ce,i]),lt=s.useCallback(t=>{I(t),me&&xe(!1)},[I,me]),rt=s.useCallback(()=>{I(""),xe(!0)},[I]),ct=()=>e.jsxs("div",{className:"chat-empty-state",children:[e.jsx(Rt,{size:48,strokeWidth:1.5}),e.jsx("h2",{children:"Start a new conversation"}),e.jsxs("button",{className:"btn btn-primary",onClick:()=>U(!0),children:[e.jsx(Re,{size:16}),"New Chat"]})]}),Y=Ke(c?.modelProvider,c?.modelId),Ie=c?.agentId===ye?Y??"Fusion":c?.title||B.get(c?.agentId??"")?.name||c?.agentId||"Chat",ot=!!(Y&&Y!==Ie),Pe=B.get(c?.agentId??"")?.name||(c?.agentId===ye?Y??"Fusion":c?.agentId?.slice(0,30)??"Fusion"),Fe=!!(Y&&Y!==Pe),dt=T.length>50?`${T.slice(0,50)}…`:T,Oe=s.useCallback(t=>{W(a=>{const o=new Set(a);return o.has(t)?o.delete(t):o.add(t),o})},[]),Ve=s.useCallback((t,a=!1)=>a?e.jsx("div",{className:"chat-message-content chat-message-content--plain",children:t}):e.jsx("div",{className:"chat-message-content chat-message-content--markdown",children:e.jsx(jt,{remarkPlugins:[Mt],components:Bt,children:t})}),[]);return e.jsxs("div",{className:"chat-view",children:[e.jsxs("div",{className:`chat-sidebar${K?"":" chat-sidebar--hidden"}`,children:[e.jsx("div",{className:"chat-sidebar-header",children:e.jsxs("button",{className:"btn btn-sm btn-primary",onClick:()=>U(!0),"data-testid":"chat-new-btn",children:[e.jsx(Re,{size:14}),"New Chat"]})}),e.jsx("div",{className:"chat-sidebar-search",children:e.jsxs("div",{className:"chat-sidebar-search-wrapper",children:[e.jsx(yt,{size:14,className:"chat-sidebar-search-icon"}),e.jsx("input",{type:"text",className:"chat-sidebar-search",placeholder:"Search conversations...",value:P,onChange:t=>p(t.target.value),"data-testid":"chat-search-input"})]})}),e.jsx("div",{className:"chat-session-list chat-sidebar-list",children:l?e.jsx("div",{style:{padding:"12px",color:"var(--text-secondary)",fontSize:"13px"},children:"Loading..."}):D.length===0?e.jsx("div",{style:{padding:"12px",color:"var(--text-secondary)",fontSize:"13px"},children:"No conversations yet"}):D.map(t=>e.jsxs("div",{className:`chat-session-item${c?.id===t.id?" chat-session-item--active":""}`,onClick:()=>lt(t.id),onContextMenu:a=>{a.preventDefault(),ne({sessionId:t.id,x:a.clientX,y:a.clientY})},"data-testid":`chat-session-${t.id}`,children:[e.jsx("button",{className:"chat-session-delete-btn",onClick:a=>{a.stopPropagation(),J(t.id)},"data-testid":"chat-session-delete-btn","aria-label":"Delete conversation",children:e.jsx(He,{size:14})}),e.jsx("div",{className:"chat-session-title",children:t.title||"Untitled"}),e.jsx("div",{className:"chat-session-preview",children:t.lastMessagePreview||"No messages"}),e.jsxs("div",{className:"chat-session-meta",children:[e.jsx("span",{children:B.get(t.agentId)?.name||(t.agentId===ye?Ke(t.modelProvider,t.modelId)??"Fusion":t.agentId.slice(0,30))}),e.jsx("span",{children:t.updatedAt?Je(t.updatedAt):""})]})]},t.id))}),e.jsx("div",{className:"chat-sidebar-footer",children:e.jsxs("button",{className:"btn btn-sm btn-primary chat-sidebar-footer-btn",onClick:()=>U(!0),"data-testid":"chat-new-btn-mobile",children:[e.jsx(Re,{size:14}),"New Chat"]})})]}),q&&e.jsxs("div",{className:"chat-session-context-menu",style:{top:q.y,left:q.x},onClick:t=>t.stopPropagation(),children:[e.jsxs("button",{onClick:()=>at(q.sessionId),"data-testid":"chat-context-archive",children:[e.jsx(Tt,{size:14}),"Archive"]}),e.jsxs("button",{onClick:()=>{ne(null),J(q.sessionId)},"data-testid":"chat-context-delete",children:[e.jsx(He,{size:14}),"Delete"]})]}),N&&e.jsx("div",{className:"chat-new-dialog-backdrop",onClick:()=>J(null),children:e.jsxs("div",{className:"chat-new-dialog",onClick:t=>t.stopPropagation(),children:[e.jsx("h3",{children:"Delete Conversation?"}),e.jsx("p",{style:{fontSize:"14px",color:"var(--text-secondary)",marginBottom:"16px"},children:"This action cannot be undone. All messages in this conversation will be permanently deleted."}),e.jsxs("div",{className:"chat-new-dialog-actions",children:[e.jsx("button",{className:"btn btn-sm",onClick:()=>J(null),children:"Cancel"}),e.jsx("button",{className:"btn btn-sm btn-danger",onClick:()=>void it(N),children:"Delete"})]})]})}),e.jsxs("div",{className:"chat-thread",children:[(c||!me)&&e.jsxs("div",{className:"chat-thread-header",children:[me&&c&&e.jsx("button",{className:"btn-icon",onClick:rt,"data-testid":"chat-back-btn",children:e.jsx(At,{size:16})}),e.jsx(je,{size:16}),e.jsx("span",{className:"chat-thread-header-title",children:Ie}),ot&&e.jsx("span",{className:"chat-model-tag",children:Y})]}),e.jsxs("div",{className:"chat-messages",ref:L,children:[f?e.jsx("div",{style:{color:"var(--text-secondary)",fontSize:"13px"},children:"Loading messages..."}):r.length===0&&!c?ct():r.length===0&&c?e.jsx("div",{style:{color:"var(--text-secondary)",fontSize:"13px"},children:"No messages yet. Start the conversation!"}):e.jsxs(e.Fragment,{children:[r.map(t=>{const a=t.role==="assistant",o=k.has(t.id);return e.jsxs("div",{className:`chat-message chat-message--${t.role}`,"data-testid":`chat-message-${t.id}`,children:[a&&e.jsxs("div",{className:"chat-message-avatar",children:[e.jsx(je,{size:14}),e.jsx("span",{children:Pe}),Fe&&e.jsx("span",{className:"chat-model-tag",children:Y}),e.jsx("button",{type:"button",className:`btn btn-icon chat-message-render-toggle${o?" chat-message-render-toggle--plain":""}`,"data-testid":"chat-message-render-toggle","aria-label":o?"Show rendered markdown":"Show plain text",onClick:()=>Oe(t.id),children:o?e.jsx(Ge,{size:14}):e.jsx(Ue,{size:14})})]}),a?Ve(t.content,o):e.jsx("div",{className:"chat-message-content",children:Xe(t.content)}),Qe(t.toolCalls),t.thinkingOutput&&e.jsxs("details",{className:"chat-message-thinking",children:[e.jsx("summary",{children:"Thinking"}),e.jsx("pre",{className:"chat-message-thinking-content",children:t.thinkingOutput})]}),e.jsx("div",{className:"chat-message-time",children:Je(t.createdAt)})]},t.id)}),v&&e.jsxs("div",{className:"chat-message chat-message--assistant chat-message--streaming",children:[e.jsxs("div",{className:"chat-message-avatar",children:[e.jsx(je,{size:14}),e.jsx("span",{children:Pe}),Fe&&e.jsx("span",{className:"chat-model-tag",children:Y}),e.jsx("button",{type:"button",className:`btn btn-icon chat-message-render-toggle${k.has("__streaming__")?" chat-message-render-toggle--plain":""}`,"data-testid":"chat-message-render-toggle","aria-label":k.has("__streaming__")?"Show rendered markdown":"Show plain text",onClick:()=>Oe("__streaming__"),children:k.has("__streaming__")?e.jsx(Ge,{size:14}):e.jsx(Ue,{size:14})})]}),M?Ve(M,k.has("__streaming__")):e.jsx("div",{className:"chat-message-content chat-message-content--waiting",children:w?"Thinking…":"Connecting…"}),Qe(X),w&&e.jsxs("details",{className:"chat-message-thinking",children:[e.jsx("summary",{children:"Thinking"}),e.jsx("pre",{className:"chat-message-thinking-content",children:w})]}),e.jsxs("div",{className:"chat-typing-indicator",children:[e.jsx("span",{}),e.jsx("span",{}),e.jsx("span",{})]})]})]}),e.jsx("div",{ref:b})]}),c&&e.jsxs("div",{className:"chat-input-area",children:[Q&&e.jsx("div",{className:"chat-skill-menu","data-testid":"chat-skill-menu",role:"listbox","aria-label":"Skill suggestions",children:Ne?e.jsx("div",{className:"chat-skill-menu-empty",children:"Loading skills…"}):z.length===0?e.jsx("div",{className:"chat-skill-menu-empty",children:oe?"No skills found":"No skills available"}):z.map((t,a)=>e.jsxs("button",{type:"button",role:"option","aria-selected":a===ue,className:`chat-skill-menu-item${a===ue?" chat-skill-menu-item--highlighted":""}`,onMouseDown:o=>o.preventDefault(),onMouseEnter:()=>ie(a),onClick:()=>Ae(t),children:[e.jsx("span",{className:"chat-skill-menu-item-name",children:t.name}),e.jsx("span",{className:"chat-skill-menu-item-description",title:t.relativePath,children:t.relativePath})]},t.id))}),e.jsxs("div",{className:"chat-input-wrapper",children:[e.jsx("textarea",{ref:C,className:"chat-input-textarea",placeholder:"Type a message...",value:A,onChange:et,onKeyDown:Ze,onKeyUp:tt,onClick:Ee,onBlur:st,onFocus:nt,rows:1,"data-testid":"chat-input"}),e.jsx($t,{agents:ge,filter:he,highlightedIndex:Se,visible:H,onSelect:$e,position:"below"}),e.jsx(Et,{visible:d.mentionActive&&!H,position:be,files:d.files,selectedIndex:d.selectedIndex,onSelect:t=>{const a=d.selectFile(t,A);V(a),d.dismissMention(),j(!1),C.current?.focus()},loading:d.loading}),T&&e.jsxs("div",{className:"chat-pending-message","data-testid":"chat-pending-indicator",children:[e.jsx("span",{children:`Queued: ${dt}`}),e.jsx("button",{type:"button",className:"chat-pending-message-dismiss","aria-label":"Dismiss queued message","data-testid":"chat-pending-dismiss",onClick:pe,children:"×"})]})]}),v?e.jsx("button",{className:"chat-input-stop",onClick:O,"aria-label":"Stop generation","data-testid":"chat-stop-btn",children:e.jsx(Pt,{size:14})}):e.jsx("button",{className:"chat-input-send",onClick:()=>void Te(),disabled:!A.trim(),"data-testid":"chat-send-btn",children:e.jsx(Dt,{size:16})})]})]}),Z&&e.jsx(Gt,{projectId:n,onClose:()=>U(!1),onCreate:Ye})]})}export{Qt as ChatView};
@@ -1,4 +1,4 @@
1
- import{r,j as t}from"./vendor-react-K0fH_qHe.js";import{c as De,bo as Me,bp as de,bq as et,br as ue,s as Ue,bs as ge,bt as we,bu as xe,bv as ye,bw as tt,bx as ae,by as rt,bz as st,bA as nt,bB as at,bC as it,bD as ie,L as ee,S as lt,bE as ct,bF as ot,K as dt,T as Ae,bG as ut,E as vt,aK as mt,a3 as ft,ai as pt,R as ht}from"./index-rNf7s96d.js";import"./vendor-xterm-DzcZoU0P.js";/**
1
+ import{r,j as t}from"./vendor-react-K0fH_qHe.js";import{c as De,bm as Me,bn as de,bo as et,bp as ue,s as Ue,bq as ge,br as we,bs as xe,bt as ye,bu as tt,bv as ae,bw as rt,bx as st,by as nt,bz as at,bA as it,bB as ie,L as ee,S as lt,bC as ct,bD as ot,K as dt,T as Ae,bE as ut,E as vt,aJ as mt,a3 as ft,ah as pt,R as ht}from"./index-DQKtk17v.js";import"./vendor-xterm-DzcZoU0P.js";/**
2
2
  * @license lucide-react v1.7.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -8,4 +8,4 @@ import{r,j as t}from"./vendor-react-K0fH_qHe.js";import{c as De,bo as Me,bp as d
8
8
  *
9
9
  * This source code is licensed under the ISC license.
10
10
  * See the LICENSE file in the root directory of this source tree.
11
- */const wt=[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"M12 8v4",key:"1got3b"}],["path",{d:"M12 16h.01",key:"1drbdi"}]],Pe=De("shield-alert",wt),ve=500,xt=3e3;function B(e){return e instanceof Error?e.message:String(e)}function Te(e){return e.length<=ve?e:e.slice(-ve)}function le(e,i){return Te([...e,i])}function I(e){try{return JSON.parse(e)}catch{return null}}function Q(e){const i=e.text??"";return e.stream==="stderr"?`[stderr] ${i}`:i}function yt(e){return e?.previewUrl??null}async function Ne(e){return rt(e)}async function Se(e,i){return st(e,i)}async function Nt(e){return nt(e)}async function St(e){return at(e)}async function ke(e){return it(e)}function V(e){try{return e()}catch{return null}}function ce(){return typeof V(()=>de)=="function"&&typeof V(()=>Me)=="function"}function W(e){return{config:{id:e.id??"default",name:e.name??"Dev Server",command:e.command??"",cwd:e.cwd??"."},status:e.status,runtime:e.pid?{pid:e.pid,startedAt:e.startedAt??new Date().toISOString(),exitCode:e.exitCode??void 0,previewUrl:e.previewUrl}:void 0,previewUrl:e.previewUrl??e.detectedUrl??e.manualUrl??void 0,logHistory:(e.logs??[]).map(i=>({timestamp:new Date().toISOString(),stream:i.startsWith("[stderr]")?"stderr":"stdout",text:i.replace(/^\[stderr\]\s*/,"")}))}}function kt(e){const[i,o]=r.useState(null),[b,y]=r.useState([]),[w,f]=r.useState([]),[j,M]=r.useState([]),[C,P]=r.useState(!0),[N,u]=r.useState(null),n=r.useRef(0),[d,U]=r.useState(null),R=r.useCallback(a=>{if(o(a),a?.logHistory){const s=a.logHistory.slice(-ve).map(Q);f(s)}},[]),A=r.useCallback(async()=>{const a=n.current;try{if(ce())if(d){const s=await Me(d,e);if(n.current!==a)return;R(s)}else{const s=await de(e);if(n.current!==a)return;y(s),s.length>0&&(U(s[0].config.id),R(s[0]))}else{const s=await Ne(e);if(n.current!==a)return;const c=W(s);y([c]),R(c)}u(null)}catch(s){if(n.current!==a)return;u(B(s))}},[R,e,d]);r.useEffect(()=>{n.current+=1;const a=n.current;o(null),y([]),f([]),M([]),P(!0),u(null),U(null),(async()=>{try{const[c,l]=await Promise.allSettled([ce()?de(e):Ne(e).then(S=>[W(S)]),typeof V(()=>ae)=="function"?ae(e):ke(e).then(S=>S.map(g=>({name:g.name,command:g.command,cwd:g.cwd,scriptName:g.scriptName,packagePath:g.packagePath})))]);if(n.current!==a)return;let v=null;if(c.status==="fulfilled"){const S=c.value;if(y(S),S.length>0){const g=S[0];ce()&&U(g.config.id),R(g)}}else v=B(c.reason);l.status==="fulfilled"&&M(l.value),v&&u(v)}catch(c){if(n.current!==a)return;u(B(c))}finally{n.current===a&&P(!1)}})()},[R,e]),r.useEffect(()=>{const a=d?et(d,e):typeof V(()=>ue)=="function"?ue(e):null;if(!a)return;const s=n.current,c=Ue(a,{events:{history:l=>{if(n.current!==s)return;const v=I(l.data);if(v?.lines){const S=v.lines.map(Q);f(Te(S))}},log:l=>{if(n.current!==s)return;const v=I(l.data);if(v){const S=typeof v.line=="string"?v.line:Q(v);f(g=>le(g,S))}},"dev-server:log":l=>{if(n.current!==s)return;const v=I(l.data);if(v){const S=typeof v.line=="string"?v.line:Q(v);f(g=>le(g,S))}},"dev-server:output":l=>{if(n.current!==s)return;const v=I(l.data);v?.line&&f(S=>le(S,v.line))},status:l=>{if(n.current!==s)return;const v=I(l.data),S=v?.status;S&&o(g=>g&&{...g,status:S,runtime:v.pid?{...g.runtime??{startedAt:new Date().toISOString()},pid:v.pid}:g.runtime})},"dev-server:status":l=>{if(n.current!==s)return;const v=I(l.data);if(v?.status){const S=W(v);o(S),y([S])}},stopped:()=>{n.current},failed:()=>{n.current}},onReconnect:()=>{n.current===s&&A()},onError:()=>{n.current===s&&u(l=>l??"Lost log stream connection.")}});return()=>{c()}},[e,A,d]),r.useEffect(()=>{if(i?.status!=="running"&&i?.status!=="starting")return;const a=setInterval(()=>{A()},xt);return()=>{clearInterval(a)}},[A,i?.status]);const _=r.useCallback(async(a,s)=>{n.current+=1;const c=n.current;try{let l;if(d&&typeof V(()=>ge)=="function")l=await ge(d,e);else{const v=await Se({command:a,cwd:s},e);l=W(v)}if(n.current!==c)return;o(l),u(null)}catch(l){if(n.current!==c)return;throw u(B(l)),l}},[e,d]),D=r.useCallback(async()=>{n.current+=1;const a=n.current;try{let s;if(d&&typeof V(()=>we)=="function")s=await we(d,e);else{const c=await Nt(e);s=W(c)}if(n.current!==a)return;o(s),u(null)}catch(s){if(n.current!==a)return;throw u(B(s)),s}},[e,d]),k=r.useCallback(async()=>{n.current+=1;const a=n.current;try{let s;if(d&&typeof V(()=>xe)=="function")s=await xe(d,e);else{const c=await St(e);s=W(c)}if(n.current!==a)return;o(s),u(null)}catch(s){if(n.current!==a)return;throw u(B(s)),s}},[e,d]),T=r.useCallback(async a=>{n.current+=1;const s=n.current;try{let c;if(d&&typeof V(()=>ye)=="function")c=await ye(d,a,e);else{const l=await tt({url:a},e);c={url:l.manualUrl??l.previewUrl??l.detectedUrl??null,source:l.manualUrl?"manual":"auto"}}if(n.current!==s)return;o(l=>l?{...l,previewUrl:c.url??void 0}:null),u(null)}catch(c){if(n.current!==s)return;throw u(B(c)),c}},[e,d]),h=r.useCallback(async()=>{n.current+=1;const a=n.current;try{let s;try{s=await ae(e)}catch{s=(await ke(e)).map(l=>({name:l.name,command:l.command,cwd:l.cwd,scriptName:l.scriptName,packagePath:l.packagePath}))}if(n.current!==a)return;M(s),u(null)}catch(s){if(n.current!==a)return;throw u(B(s)),s}},[e]),p=r.useCallback(async(a,s)=>{if(typeof a!="string"&&!d)try{const v=a,S=await Se({command:v.command,cwd:v.cwd,scriptName:v.scriptName,packagePath:v.packagePath??v.cwd},e),g=W(S);o(g),y([g]),u(null);return}catch(v){throw u(B(v)),v}const c=typeof a=="string"?a:a.command,l=typeof a=="string"?s:a.cwd;await _(c,l)},[e,_,d]),E=r.useCallback(async()=>{await D()},[D]),L=r.useCallback(async()=>{await k()},[k]),z=r.useCallback(async a=>{await T(a)},[T]),$=r.useCallback(async()=>{await h()},[h]),O=r.useCallback(async()=>{await A()},[A]),H=yt(i),x=i?{...i,pid:i.runtime?.pid}:null;return{session:i,sessions:b,logs:w,detectedCommands:j,previewUrl:H,isLoading:C,error:N,startServer:_,stopServer:D,restartServer:k,setPreviewUrl:T,detectCommands:h,refresh:A,candidates:j,serverState:x,loading:C,start:p,stop:E,restart:L,setManualUrl:z,detect:$,refreshStatus:O}}const je=500,Ce=100;function ze(e){return e.length>je?e.slice(-je):e}function Fe(e){return e==="stderr"?"stderr":"stdout"}function Y(e){try{return JSON.parse(e.data)}catch{return null}}function Z(e,i){return{id:typeof e.id=="number"&&Number.isFinite(e.id)?e.id:i,text:typeof e.text=="string"?e.text:"",stream:Fe(e.stream),timestamp:typeof e.timestamp=="string"?e.timestamp:""}}function jt(e,i){return{id:i,text:e,stream:"stdout",timestamp:""}}function oe(e,i){if(i.length===0)return e;const o=[...e],b=new Set(e.map(y=>y.id));for(const y of i)b.has(y.id)||(b.add(y.id),o.push(y));return o.sort((y,w)=>y.id-w.id),ze(o)}function Ct(e,i){const[o,b]=r.useState([]),[y,w]=r.useState(!1),[f,j]=r.useState(!1),[M,C]=r.useState(!1),[P,N]=r.useState(null),u=r.useRef(null),n=r.useRef(!1),d=r.useRef(0),U=r.useRef(0),R=r.useRef(e),A=r.useRef(i),_=r.useRef(0),D=r.useRef(1);(R.current!==e||A.current!==i)&&(R.current=e,A.current=i,d.current++,n.current=!0,_.current=0,D.current=1,b([]),w(!1),j(!1),C(!1),N(null),u.current&&(u.current(),u.current=null)),r.useEffect(()=>{if(!i){u.current&&(u.current(),u.current=null);return}const E=d.current,L=++U.current;n.current=!1,w(!0);const z=(x,a)=>{const s=ze(x);b(s),N(a),C(a!==null?a>s.length:!1);const c=s.length>0?s[s.length-1].id:0;_.current=c,D.current=c+1},$=x=>{if(n.current||d.current!==E||!x||typeof x!="object")return;const a=x.lines;if(!Array.isArray(a))return;if(a.length>0&&typeof a[0]=="string"){const c=a.filter(l=>typeof l=="string").map((l,v)=>jt(l,v+1));z(c,c.length);return}const s=a.filter(c=>!!c&&typeof c=="object").map((c,l)=>Z(c,l+1));z(s,s.length)},O=x=>{if(n.current||d.current!==E)return;const a=typeof x.text=="string"?x.text:typeof x.line=="string"?x.line:null;if(!a)return;const s=D.current,c=typeof x.id=="number"&&Number.isFinite(x.id)?x.id:s,l={id:c,text:a,stream:Fe(x.stream),timestamp:typeof x.timestamp=="string"?x.timestamp:""};_.current=Math.max(_.current,c),D.current=Math.max(D.current,c+1),b(v=>oe(v,[l])),N(v=>v===null?v:Math.max(v+1,l.id))};async function H(){try{const a=await ie({maxLines:Ce},e);if(n.current||d.current!==E||U.current!==L)return;const s=a.lines.map((c,l)=>Z(c,l+1));z(s,a.totalLines)}catch{if(n.current||d.current!==E||U.current!==L)return;z([],null)}finally{!n.current&&d.current===E&&U.current===L&&w(!1)}const x=ue(e);u.current=Ue(x,{events:{"dev-server:log":a=>{const s=Y(a);s&&O(s)},log:a=>{const s=Y(a);s&&O(s)},history:a=>{const s=Y(a);$(s)},"dev-server:history":a=>{const s=Y(a);$(s)}},onReconnect:()=>{n.current||d.current!==E||ie({lastEventId:_.current,maxLines:50},e).then(a=>{if(n.current||d.current!==E)return;const s=a.lines.map((c,l)=>Z(c,D.current+l));if(s.length>0){const c=s[s.length-1].id;_.current=Math.max(_.current,c),D.current=Math.max(D.current,c+1)}b(c=>oe(c,s)),N(a.totalLines)}).catch(()=>{})}})}return H(),()=>{n.current=!0,u.current&&(u.current(),u.current=null)}},[i,e]);const T=r.useCallback(async()=>{if(!i||f)return;const E=d.current,L=o.length;j(!0);try{const z=await ie({maxLines:Ce,offset:L},e);if(n.current||d.current!==E)return;const $=z.lines.map((O,H)=>Z(O,H+1));b(O=>oe($,O)),C(z.totalLines>L+$.length),N(z.totalLines)}catch{}finally{j(!1)}},[i,o.length,f,e]),h=r.useCallback(()=>{b([])},[]),p=u.current!==null&&!y&&!n.current;return{entries:o,loading:y,loadingMore:f,hasMore:M,total:P,loadMore:T,clear:h,logs:o,isStreaming:p,clearLogs:h}}const Et="This preview appears to block iframe embedding. Open it in a new tab instead.",Lt="The preview URL could not be loaded. Verify the server is running and the URL is correct.",Rt="Preview is taking longer than expected and may block iframe embedding.";function _t(e){return e==="blocked"?Et:e==="error"?Lt:null}function Dt(e,i={}){const{loadTimeoutMs:o=1e4,detectionMethod:b=null}=i,y=r.useRef(null),w=r.useRef(null),[f,j]=r.useState("unknown"),[M,C]=r.useState(null),[P]=r.useState(b),N=r.useCallback(()=>{w.current!==null&&(window.clearTimeout(w.current),w.current=null)},[]),u=r.useCallback(k=>{j(k),C(_t(k))},[]),n=r.useCallback(()=>{j("blocked"),C(Rt)},[]);r.useEffect(()=>{if(N(),!e){j("unknown"),C(null);return}j("unknown"),C(null);let k=!1;return queueMicrotask(()=>{k||(j("loading"),C(null))}),()=>{k=!0,N()}},[N,e]),r.useEffect(()=>{if(f!=="loading"){N();return}const k=setTimeout(()=>{w.current=null,n()},o);return w.current=k,()=>{clearTimeout(k),w.current===k&&(w.current=null)}},[N,f,o,n]);const d=r.useCallback(()=>{const k=y.current;if(!k){u("embedded");return}try{if(k.contentWindow?.location?.href==="about:blank"&&k.src!=="about:blank"){u("blocked");return}}catch{}u("embedded")},[u]),U=r.useCallback(()=>{u("error")},[u]);r.useEffect(()=>{if(N(),!e){j("unknown"),C(null);return}j("unknown"),C(null)},[N]);const R=r.useCallback(()=>{N(),j("unknown"),C(null)},[N]),A=R,_=r.useMemo(()=>f==="embedded",[f]),D=r.useMemo(()=>f==="blocked"||f==="error",[f]);return{embedStatus:f,isEmbedded:_,isBlocked:D,blockReason:M,detectionMethod:P,iframeRef:y,resetEmbedStatus:R,setEmbedStatus:u,retry:A,embedContext:M,handleIframeLoad:d,handleIframeError:U}}const Mt=/\x1b\[[0-9;]*m/g;function me(e){return e.replace(Mt,"")}function Ut(e){if(!e)return"";const i=new Date(e);return Number.isNaN(i.getTime())?"":i.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1})}function At(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Pt(e){if(e.stream==="stderr")return"error";const i=me(e.text).toLowerCase();return/\b(warn|warning)\b/.test(i)?"warn":/\b(error|fatal)\b/.test(i)?"error":"info"}function Tt(e,i){if(!i)return e;const o=new RegExp(`(${At(i)})`,"ig"),b=e.split(o),y=i.toLowerCase();return t.jsx(t.Fragment,{children:b.map((w,f)=>w.toLowerCase()===y?t.jsx("mark",{children:w},`${w}-${f}`):t.jsx("span",{children:w},`${w}-${f}`))})}function zt({entries:e,loading:i,loadingMore:o,hasMore:b,total:y,onLoadMore:w,isRunning:f}){const j=r.useRef(null),M=r.useRef(e.length),C=r.useRef(f),[P,N]=r.useState(!1),[u,n]=r.useState(!1),[d,U]=r.useState(""),[R,A]=r.useState("all"),_=r.useMemo(()=>R==="all"?e:e.filter(p=>Pt(p)===R),[e,R]),D=r.useMemo(()=>{const p=d.trim().toLowerCase();return p?_.filter(E=>me(E.text).toLowerCase().includes(p)):_},[_,d]),k=D.length,T=r.useCallback(()=>{const p=j.current;p&&(p.scrollTop=p.scrollHeight,n(!1))},[]);r.useEffect(()=>{const p=C.current,E=M.current,L=e.length>E;f&&(!p||!u&&L)&&T(),C.current=f,M.current=e.length},[e.length,f,u,T]);const h=r.useCallback(()=>{const p=j.current;if(!p)return;const L=p.scrollTop+p.clientHeight>=p.scrollHeight-50;n(!L)},[]);return r.useEffect(()=>{i||e.length===0||!u&&f&&T()},[e,f,u,i,T]),i&&e.length===0?t.jsx("section",{className:"devserver-log-viewer","data-testid":"devserver-log-viewer",children:t.jsxs("div",{className:"devserver-log-viewer__loading","data-testid":"devserver-log-loading",children:[t.jsx(ee,{size:16,className:"devserver-log-viewer__spinner"}),t.jsx("span",{children:"Loading logs…"})]})}):t.jsxs("section",{className:`devserver-log-viewer${P?" devserver-log-viewer--fullscreen":""}`,"data-testid":"devserver-log-viewer",children:[t.jsxs("header",{className:"devserver-log-viewer__toolbar",children:[t.jsxs("div",{className:"devserver-log-viewer__toolbar-meta",children:[t.jsx("span",{className:"devserver-log-viewer__title",children:"Logs"}),t.jsxs("span",{className:"devserver-log-viewer__count","data-testid":"devserver-log-count",children:[y!==null?`${e.length}/${y}`:`${e.length}`," lines"]})]}),t.jsxs("div",{className:"devserver-log-viewer__toolbar-actions",children:[t.jsxs("label",{className:"devserver-log-viewer__severity",htmlFor:"devserver-log-severity-filter",children:[t.jsx("span",{className:"visually-hidden",children:"Filter logs by severity"}),t.jsxs("select",{id:"devserver-log-severity-filter",className:"select devserver-log-viewer__severity-select",value:R,onChange:p=>A(p.target.value),"data-testid":"devserver-log-severity-filter","aria-label":"Filter logs by severity",children:[t.jsx("option",{value:"all",children:"All severities"}),t.jsx("option",{value:"info",children:"Info"}),t.jsx("option",{value:"warn",children:"Warn"}),t.jsx("option",{value:"error",children:"Error"})]})]}),t.jsxs("label",{className:"devserver-log-viewer__search",htmlFor:"devserver-log-search",children:[t.jsx("span",{className:"visually-hidden",children:"Search logs"}),t.jsx(lt,{size:14}),t.jsx("input",{id:"devserver-log-search",className:"input devserver-log-viewer__search-input",type:"text",value:d,onChange:p=>U(p.target.value),placeholder:"Search logs","data-testid":"devserver-log-search-input","aria-label":"Search logs"})]}),d.trim().length>0&&t.jsxs("span",{className:"devserver-log-viewer__matches","data-testid":"devserver-log-match-count",children:[k," match",k===1?"":"es"]}),t.jsx("button",{type:"button",className:"btn btn-sm btn-icon",onClick:()=>N(p=>!p),"data-testid":"devserver-log-fullscreen-toggle","aria-label":P?"Exit fullscreen logs":"Enter fullscreen logs",children:P?t.jsx(ct,{size:14}):t.jsx(ot,{size:14})})]})]}),t.jsxs("div",{className:"devserver-log-viewer__body",children:[b&&t.jsx("div",{className:"devserver-log-viewer__load-more","data-testid":"devserver-log-load-more",children:t.jsx("button",{type:"button",className:"btn btn-sm touch-target",onClick:w,disabled:o,"data-testid":"devserver-log-load-more-button",children:o?t.jsxs(t.Fragment,{children:[t.jsx(ee,{size:14,className:"devserver-log-viewer__spinner"}),"Loading older logs…"]}):"Load older logs"})}),t.jsxs("div",{ref:j,className:"devserver-log-viewer__content",onScroll:h,"data-testid":"devserver-log-content",children:[!i&&D.length===0&&t.jsx("p",{className:"devserver-log-viewer__empty","data-testid":"devserver-log-empty",children:e.length===0?"No logs yet. Start the dev server to see output.":_.length===0?"No log lines match the selected severity.":"No log lines match your search."}),D.map(p=>{const E=me(p.text),L=Ut(p.timestamp);return t.jsxs("div",{className:"devserver-log-line",children:[L&&t.jsx("span",{className:"devserver-log-timestamp","data-testid":"devserver-log-timestamp",children:L}),p.stream==="stderr"&&t.jsx("span",{className:"devserver-log-stream-badge","data-testid":"devserver-log-stderr-badge",children:"ERR"}),t.jsx("span",{className:"devserver-log-text",children:Tt(E,d.trim())})]},p.id)})]}),u&&f&&t.jsxs("button",{type:"button",className:"btn btn-sm devserver-log-viewer__new-logs-button",onClick:T,"data-testid":"devserver-log-jump-button",children:[t.jsx(dt,{size:14}),"New logs"]})]})]})}const Ft="devserver-preview-iframe";function $t({url:e,embedStatus:i,onEmbedStatusChange:o,iframeRef:b,blockReason:y,onRetry:w,className:f=Ft,embedContext:j}){const M=y??j??null,[C,P]=r.useState(0);r.useEffect(()=>{!e||i!=="unknown"||(P(d=>d+1),o("loading"))},[i,o,e]);const N=r.useCallback(()=>{const d=b.current;if(!d){o("embedded");return}try{if(d.contentWindow?.location?.href==="about:blank"&&d.src!=="about:blank"){o("blocked");return}}catch{}o("embedded")},[b,o]),u=r.useCallback(d=>{d.stopPropagation(),o("error")},[o]),n=r.useCallback(()=>{e&&window.open(e,"_blank","noopener,noreferrer")},[e]);return e?t.jsxs("div",{className:"devserver-preview-iframe-shell",children:[t.jsx("iframe",{src:e,ref:b,sandbox:"allow-scripts allow-same-origin allow-forms allow-popups allow-popups-to-escape-sandbox",className:f,title:"Dev server preview",onLoad:N,onError:u,onErrorCapture:u,"data-testid":"devserver-preview-iframe"},`${e}-${C}`),i==="loading"&&t.jsxs("div",{className:"devserver-preview-overlay","data-testid":"devserver-preview-loading",children:[t.jsx(ee,{size:16,className:"dev-server-spin"}),t.jsx("span",{children:"Loading preview..."})]}),i==="blocked"&&t.jsxs("div",{className:"devserver-preview-blocked-panel",role:"alert","data-testid":"devserver-preview-blocked-panel",children:[t.jsx(Pe,{className:"devserver-preview-blocked-icon","aria-hidden":"true"}),t.jsxs("div",{children:[t.jsx("p",{className:"devserver-preview-blocked-title",children:"Preview cannot be embedded"}),M&&t.jsx("p",{className:"devserver-preview-blocked-context",children:M})]}),t.jsx("p",{className:"devserver-preview-blocked-description",children:"You can view the preview in a separate browser tab."}),t.jsxs("div",{className:"devserver-preview-blocked-actions",children:[t.jsx("button",{type:"button",className:"btn btn-primary",onClick:n,children:"Open in new tab"}),w&&t.jsx("button",{type:"button",className:"btn btn-sm",onClick:w,children:"Retry"})]})]}),i==="error"&&t.jsxs("div",{className:"devserver-preview-error-panel",role:"alert","data-testid":"devserver-preview-error-panel",children:[t.jsx(Ae,{className:"devserver-preview-blocked-icon","aria-hidden":"true"}),t.jsxs("div",{children:[t.jsx("p",{className:"devserver-preview-blocked-title",children:"Unable to load preview"}),M&&t.jsx("p",{className:"devserver-preview-blocked-context",children:M})]}),t.jsx("p",{className:"devserver-preview-blocked-description",children:"You can view the preview in a separate browser tab."}),t.jsxs("div",{className:"devserver-preview-blocked-actions",children:[t.jsx("button",{type:"button",className:"btn btn-primary",onClick:n,children:"Open in new tab"}),w&&t.jsx("button",{type:"button",className:"btn btn-sm",onClick:w,children:"Retry"})]})]})]}):null}const Ee={stopped:{className:"dev-server-status-badge--stopped",label:"Stopped"},starting:{className:"dev-server-status-badge--starting",label:"Starting..."},running:{className:"dev-server-status-badge--running",label:"Running"},stopping:{className:"dev-server-status-badge--starting",label:"Stopping..."},failed:{className:"dev-server-status-badge--failed",label:"Failed"}};function Le(e){return e instanceof Error?e.message:String(e)}function $e(e){return e==="."?"root":e}function Re(e){return e?e==="root"?".":e:null}function _e(e,i,o){return!i||e.scriptName!==i?!1:o?$e(e.cwd)===o:!0}function Ot(e){return e.cwd==="."?"root":e.cwd}function Bt(e){return e.length<=60?e:`${e.slice(0,60)}…`}function Wt({addToast:e,projectId:i}){const{session:o,detectedCommands:b,previewUrl:y,isLoading:w,error:f,startServer:j,stopServer:M,restartServer:C,setPreviewUrl:P,detectCommands:N,refresh:u}=kt(i),n=o?.status??"stopped",d=n==="running"||n==="starting",U=Ee[n]??Ee.stopped,{entries:R,loading:A,loadingMore:_,hasMore:D,total:k,loadMore:T}=Ct(i,!!i),h=y,p=o?.config?.cwd??null,[E,L]=r.useState(!0),[z,$]=r.useState(""),[O,H]=r.useState(""),[x,a]=r.useState(null),[s,c]=r.useState(null),[l,v]=r.useState("embedded"),S=l==="embedded"?h:null,{embedStatus:g,setEmbedStatus:Oe,resetEmbedStatus:X,iframeRef:G,isEmbedded:Be,isBlocked:te,blockReason:re,retry:fe}=Dt(S),[pe,q]=r.useState(!1),he=r.useRef(g);r.useEffect(()=>{const m=he.current!==g;te&&m&&q(!0),g==="embedded"&&q(!1),he.current=g},[g,te]),r.useEffect(()=>{q(!1)},[h]);const J=r.useMemo(()=>{if(!x)return null;const m=Re(p);return b.find(F=>!(F.scriptName!==x||m&&F.cwd!==m||o?.config?.command&&F.command!==o.config.command))??b.find(F=>_e(F,x,p))??null},[b,o?.config?.command,x,p]);r.useEffect(()=>{typeof N=="function"&&N().catch(m=>{e(Le(m),"error")})},[e,N]),r.useEffect(()=>{if(x){L(!1);return}L(!0)},[x]),r.useEffect(()=>{if(o?.status==="running"||o?.status==="starting"){o.config?.command?.trim().length>0&&$(o.config.command);return}if(J){$(J.command);return}b.length>0&&$(m=>m.trim().length>0?m:b[0]?.command??"")},[b,J,o?.config?.command,o?.status]),r.useEffect(()=>{H(h??"")},[h]);const se=r.useCallback(()=>{h&&window.open(h,"_blank","noopener,noreferrer")},[h]),be=r.useCallback(()=>{q(!1),fe()},[fe]),He=r.useCallback(()=>{try{const m=G.current;if(m?.contentWindow){m.contentWindow.location.reload(),q(!1),X();return}}catch{}if(!(!h||!G.current))try{const m=new URL(h);m.searchParams.set("_t",Date.now().toString()),G.current.src=m.toString(),q(!1),X()}catch{G.current.src=h,q(!1),X()}},[h,G,X]),K=r.useCallback(async(m,F,ne)=>{c(m);try{await F(),e(ne,"success")}catch(Ze){e(Le(Ze),"error")}finally{c(null)}},[e]),Ve=r.useCallback(m=>{a(m.scriptName),L(!1),$(m.command),e(`Selected ${m.scriptName} script.`,"success")},[e]),qe=r.useCallback(()=>{a(null),L(!0),e("Cleared selected dev server script.","success")},[e]),We=()=>{const m=z.trim();if(m.length===0){e("Enter a command before starting the dev server.","warning");return}const F=Re(p)??".",ne=J?.cwd??F;K("start",()=>j(m,ne),"Dev server started.")},Ge=()=>{K("stop",M,"Dev server stopped.")},Ie=()=>{K("restart",C,"Dev server restarted.")},Xe=()=>{const m=O.trim(),F=m.length>0?m:null;K("preview",()=>P(F),F?"Preview URL updated.":"Preview URL override cleared.")},Je=r.useCallback(()=>{f&&u()},[f,u]),Ke=n==="starting"||n==="running"||s!==null,Qe=n==="stopped"||s!==null,Ye=n==="stopped"||n==="starting"||s!==null;return t.jsxs("div",{className:"dev-server-view","data-testid":"dev-server-view",children:[t.jsxs("section",{className:"dev-server-header","aria-label":"Dev server controls header",children:[t.jsxs("div",{className:"dev-server-header-title",children:[t.jsx(ut,{size:16}),t.jsx("h2",{children:"Dev Server"}),t.jsx("span",{className:`dev-server-status-badge ${U.className}`,"data-testid":"dev-server-status-badge",children:U.label})]}),t.jsxs("div",{className:"dev-server-header-actions",children:[t.jsxs("button",{type:"button",className:"btn btn-primary btn-sm",onClick:We,disabled:Ke,"data-testid":"dev-server-start-button",children:[t.jsx(vt,{size:14}),t.jsx("span",{children:s==="start"?"Starting...":"Start"})]}),t.jsxs("button",{type:"button",className:"btn btn-danger btn-sm",onClick:Ge,disabled:Qe,"data-testid":"dev-server-stop-button",children:[t.jsx(mt,{size:14}),t.jsx("span",{children:s==="stop"?"Stopping...":"Stop"})]}),t.jsxs("button",{type:"button",className:"btn btn-sm",onClick:Ie,disabled:Ye,"data-testid":"dev-server-restart-button",children:[t.jsx(gt,{size:14}),t.jsx("span",{children:s==="restart"?"Restarting...":"Restart"})]})]})]}),t.jsxs("section",{className:"dev-server-panel dev-server-config","aria-label":"Dev server configuration",children:[t.jsxs("div",{className:"dev-server-section-header",children:[t.jsx("h3",{children:"Configuration"}),w&&t.jsx("span",{className:"dev-server-muted",children:"Loading..."})]}),w&&!o&&b.length===0&&t.jsxs("div",{className:"dev-server-loading-state","data-testid":"dev-server-loading-state",children:[t.jsx(ee,{size:16,className:"dev-server-spin"}),t.jsx("span",{children:"Loading dev server configuration..."})]}),f&&t.jsxs("div",{className:"dev-server-error-box",role:"alert","data-testid":"dev-server-error-box",children:[t.jsx("p",{children:f}),t.jsx("button",{type:"button",className:"btn btn-sm",onClick:Je,children:"Retry"})]}),t.jsxs("div",{className:"dev-server-section",children:[t.jsx("h3",{children:"Script Selection"}),x&&t.jsxs("div",{className:"dev-server-selected","data-testid":"dev-server-selected-summary",children:[t.jsx("span",{className:"dev-server-candidate-name",children:x}),t.jsx("span",{className:"dev-server-candidate-source",children:p??"root"}),t.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>L(!0),"data-testid":"dev-server-change-selection",children:"Change"}),t.jsx("button",{type:"button",className:"btn btn-danger btn-sm",onClick:qe,"data-testid":"dev-server-clear-selection",children:"Clear"})]}),E&&b.length===0&&t.jsxs("p",{className:"dev-server-empty-state","data-testid":"dev-server-empty-candidates",children:["No dev server scripts detected. Check that your project has a ",t.jsx("code",{children:"package.json"})," with a ",t.jsx("code",{children:"dev"}),", ",t.jsx("code",{children:"start"}),", or similar script."]}),E&&b.length>0&&t.jsx("div",{className:"dev-server-candidates","data-testid":"dev-server-candidates",children:b.map(m=>{const F=_e(m,x,p);return t.jsxs("button",{type:"button",className:`dev-server-candidate ${F?"dev-server-candidate--selected":""}`,onClick:()=>Ve(m),"data-testid":`dev-server-candidate-${m.scriptName}-${$e(m.cwd)}`,children:[t.jsx("span",{className:"dev-server-candidate-name",children:m.scriptName}),t.jsx("span",{className:"dev-server-candidate-command",children:Bt(m.command)}),t.jsx("span",{className:"dev-server-candidate-source",children:Ot(m)})]},`${m.cwd}::${m.scriptName}::${m.command}`)})})]}),t.jsxs("div",{className:"dev-server-field-group",children:[t.jsx("label",{htmlFor:"dev-server-command",className:"dev-server-label",children:"Command"}),t.jsx("input",{id:"dev-server-command",className:"input",value:z,onChange:m=>$(m.target.value),placeholder:"pnpm dev","data-testid":"dev-server-command-input",readOnly:n==="running"||n==="starting"})]}),(n==="running"||n==="starting")&&o&&t.jsxs("div",{className:"dev-server-current-command","data-testid":"dev-server-current-command",children:[t.jsx("span",{className:"dev-server-label",children:"Running command"}),t.jsx("code",{children:o.config?.command??z})]}),t.jsxs("div",{className:"dev-server-preview-override",children:[t.jsx("label",{htmlFor:"dev-server-preview-input",className:"dev-server-label",children:"Preview URL Override"}),t.jsx("input",{id:"dev-server-preview-input",className:"input",type:"url",value:O,onChange:m=>H(m.target.value),placeholder:"http://localhost:3000","data-testid":"dev-server-preview-input"}),t.jsx("button",{type:"button",className:"btn btn-primary btn-sm",onClick:Xe,disabled:s==="preview","data-testid":"dev-server-set-preview",children:"Save"})]}),h&&t.jsxs("p",{className:"dev-server-preview-hint",children:["Auto-detected: ",h]})]}),t.jsxs("div",{className:"dev-server-content",children:[t.jsxs("section",{className:"dev-server-panel dev-server-logs-panel","data-testid":"dev-server-logs-panel","aria-label":"Dev server logs",children:[t.jsxs("div",{className:"dev-server-section-header",children:[t.jsx("h3",{children:"Logs"}),t.jsxs("span",{className:"dev-server-muted",children:[k??R.length," lines"]})]}),t.jsx("div",{className:"dev-server-logs-viewer","data-testid":"dev-server-log-viewer",children:t.jsx(zt,{entries:R,loading:A,loadingMore:_,hasMore:D,total:k,onLoadMore:T,isRunning:d})})]}),t.jsxs("section",{className:"dev-server-panel devserver-preview-panel","data-testid":"devserver-preview-panel","aria-label":"Dev server preview",children:[t.jsxs("div",{className:"devserver-preview-header",children:[t.jsxs("div",{className:"devserver-preview-title",children:[t.jsx(ft,{size:14}),t.jsx("span",{children:"Preview"})]}),t.jsxs("span",{className:"devserver-preview-url-badge devserver-preview-url-badge--auto",title:h??"No preview URL","data-testid":"devserver-preview-url-badge",children:["Auto",h?` · ${h}`:" · Not available"]}),t.jsxs("div",{className:"devserver-preview-actions",children:[t.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>v(m=>m==="embedded"?"external":"embedded"),"data-testid":"devserver-preview-mode-toggle",children:l==="embedded"?"External only":"Embedded"}),t.jsx("button",{type:"button",className:"btn btn-sm btn-icon",title:"Open in new tab",onClick:se,disabled:!h,"data-testid":"devserver-preview-open-tab",children:t.jsx(pt,{size:14})}),t.jsx("button",{type:"button",className:"btn btn-sm btn-icon",title:"Refresh preview",onClick:He,disabled:!h,"data-testid":"devserver-preview-refresh",children:t.jsx(ht,{size:14})})]})]}),t.jsxs("div",{className:"devserver-preview-container","data-embed-status":g,"data-embedded":Be?"true":"false",children:[!h&&!d&&t.jsx("p",{className:"devserver-preview-empty",children:"Start a dev server to see a live preview here."}),!h&&d&&t.jsx("p",{className:"devserver-preview-empty",children:"No preview URL detected. Start the dev server or set a manual URL to preview your app."}),h&&l==="external"&&t.jsxs("div",{className:"devserver-preview-external-only","data-testid":"devserver-preview-external-only",children:[t.jsx("p",{children:"Embedded preview is disabled. Open your app in a separate browser tab."}),t.jsx("button",{type:"button",className:"btn btn-primary btn-sm touch-target",onClick:se,"data-testid":"devserver-preview-external-open-tab",children:"Open in new tab"})]}),h&&l==="embedded"&&pe&&te&&t.jsxs("div",{className:g==="error"?"devserver-preview-error-panel":"devserver-preview-blocked-panel","data-testid":"devserver-preview-fallback",role:"alert",children:[g==="error"?t.jsx(Ae,{className:"devserver-preview-blocked-icon","aria-hidden":"true"}):t.jsx(Pe,{className:"devserver-preview-blocked-icon","aria-hidden":"true"}),t.jsxs("div",{children:[t.jsx("p",{className:"devserver-preview-blocked-title",children:g==="error"?"Preview failed":"Preview blocked"}),re&&t.jsx("p",{className:"devserver-preview-blocked-context",children:re})]}),t.jsx("p",{className:"devserver-preview-blocked-description",children:"Open the preview in a new tab, or retry embedded mode after checking your server settings."}),t.jsxs("div",{className:"devserver-preview-blocked-actions",children:[t.jsx("button",{type:"button",className:"btn btn-primary",onClick:se,"data-testid":"devserver-preview-fallback-open-tab",children:"Open preview in new tab"}),t.jsx("button",{type:"button",className:"btn btn-sm",onClick:be,"data-testid":"devserver-preview-fallback-retry",children:"Retry embedded preview"})]})]}),h&&l==="embedded"&&!pe&&t.jsx($t,{url:h,embedStatus:g,onEmbedStatusChange:Oe,iframeRef:G,blockReason:re,onRetry:be})]})]})]})]})}export{Wt as DevServerView};
11
+ */const wt=[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"M12 8v4",key:"1got3b"}],["path",{d:"M12 16h.01",key:"1drbdi"}]],Pe=De("shield-alert",wt),ve=500,xt=3e3;function B(e){return e instanceof Error?e.message:String(e)}function Te(e){return e.length<=ve?e:e.slice(-ve)}function le(e,i){return Te([...e,i])}function X(e){try{return JSON.parse(e)}catch{return null}}function Q(e){const i=e.text??"";return e.stream==="stderr"?`[stderr] ${i}`:i}function yt(e){return e?.previewUrl??null}async function Ne(e){return rt(e)}async function Se(e,i){return st(e,i)}async function Nt(e){return nt(e)}async function St(e){return at(e)}async function ke(e){return it(e)}function V(e){try{return e()}catch{return null}}function ce(){return typeof V(()=>de)=="function"&&typeof V(()=>Me)=="function"}function W(e){return{config:{id:e.id??"default",name:e.name??"Dev Server",command:e.command??"",cwd:e.cwd??"."},status:e.status,runtime:e.pid?{pid:e.pid,startedAt:e.startedAt??new Date().toISOString(),exitCode:e.exitCode??void 0,previewUrl:e.previewUrl}:void 0,previewUrl:e.previewUrl??e.detectedUrl??e.manualUrl??void 0,logHistory:(e.logs??[]).map(i=>({timestamp:new Date().toISOString(),stream:i.startsWith("[stderr]")?"stderr":"stdout",text:i.replace(/^\[stderr\]\s*/,"")}))}}function kt(e){const[i,o]=r.useState(null),[b,y]=r.useState([]),[w,f]=r.useState([]),[j,M]=r.useState([]),[C,P]=r.useState(!0),[N,u]=r.useState(null),n=r.useRef(0),[d,U]=r.useState(null),R=r.useCallback(a=>{if(o(a),a?.logHistory){const s=a.logHistory.slice(-ve).map(Q);f(s)}},[]),A=r.useCallback(async()=>{const a=n.current;try{if(ce())if(d){const s=await Me(d,e);if(n.current!==a)return;R(s)}else{const s=await de(e);if(n.current!==a)return;y(s),s.length>0&&(U(s[0].config.id),R(s[0]))}else{const s=await Ne(e);if(n.current!==a)return;const c=W(s);y([c]),R(c)}u(null)}catch(s){if(n.current!==a)return;u(B(s))}},[R,e,d]);r.useEffect(()=>{n.current+=1;const a=n.current;o(null),y([]),f([]),M([]),P(!0),u(null),U(null),(async()=>{try{const[c,l]=await Promise.allSettled([ce()?de(e):Ne(e).then(S=>[W(S)]),typeof V(()=>ae)=="function"?ae(e):ke(e).then(S=>S.map(g=>({name:g.name,command:g.command,cwd:g.cwd,scriptName:g.scriptName,packagePath:g.packagePath})))]);if(n.current!==a)return;let v=null;if(c.status==="fulfilled"){const S=c.value;if(y(S),S.length>0){const g=S[0];ce()&&U(g.config.id),R(g)}}else v=B(c.reason);l.status==="fulfilled"&&M(l.value),v&&u(v)}catch(c){if(n.current!==a)return;u(B(c))}finally{n.current===a&&P(!1)}})()},[R,e]),r.useEffect(()=>{const a=d?et(d,e):typeof V(()=>ue)=="function"?ue(e):null;if(!a)return;const s=n.current,c=Ue(a,{events:{history:l=>{if(n.current!==s)return;const v=X(l.data);if(v?.lines){const S=v.lines.map(Q);f(Te(S))}},log:l=>{if(n.current!==s)return;const v=X(l.data);if(v){const S=typeof v.line=="string"?v.line:Q(v);f(g=>le(g,S))}},"dev-server:log":l=>{if(n.current!==s)return;const v=X(l.data);if(v){const S=typeof v.line=="string"?v.line:Q(v);f(g=>le(g,S))}},"dev-server:output":l=>{if(n.current!==s)return;const v=X(l.data);v?.line&&f(S=>le(S,v.line))},status:l=>{if(n.current!==s)return;const v=X(l.data),S=v?.status;S&&o(g=>g&&{...g,status:S,runtime:v.pid?{...g.runtime??{startedAt:new Date().toISOString()},pid:v.pid}:g.runtime})},"dev-server:status":l=>{if(n.current!==s)return;const v=X(l.data);if(v?.status){const S=W(v);o(S),y([S])}},stopped:()=>{n.current},failed:()=>{n.current}},onReconnect:()=>{n.current===s&&A()},onError:()=>{n.current===s&&u(l=>l??"Lost log stream connection.")}});return()=>{c()}},[e,A,d]),r.useEffect(()=>{if(i?.status!=="running"&&i?.status!=="starting")return;const a=setInterval(()=>{A()},xt);return()=>{clearInterval(a)}},[A,i?.status]);const _=r.useCallback(async(a,s)=>{n.current+=1;const c=n.current;try{let l;if(d&&typeof V(()=>ge)=="function")l=await ge(d,e);else{const v=await Se({command:a,cwd:s},e);l=W(v)}if(n.current!==c)return;o(l),u(null)}catch(l){if(n.current!==c)return;throw u(B(l)),l}},[e,d]),D=r.useCallback(async()=>{n.current+=1;const a=n.current;try{let s;if(d&&typeof V(()=>we)=="function")s=await we(d,e);else{const c=await Nt(e);s=W(c)}if(n.current!==a)return;o(s),u(null)}catch(s){if(n.current!==a)return;throw u(B(s)),s}},[e,d]),k=r.useCallback(async()=>{n.current+=1;const a=n.current;try{let s;if(d&&typeof V(()=>xe)=="function")s=await xe(d,e);else{const c=await St(e);s=W(c)}if(n.current!==a)return;o(s),u(null)}catch(s){if(n.current!==a)return;throw u(B(s)),s}},[e,d]),T=r.useCallback(async a=>{n.current+=1;const s=n.current;try{let c;if(d&&typeof V(()=>ye)=="function")c=await ye(d,a,e);else{const l=await tt({url:a},e);c={url:l.manualUrl??l.previewUrl??l.detectedUrl??null,source:l.manualUrl?"manual":"auto"}}if(n.current!==s)return;o(l=>l?{...l,previewUrl:c.url??void 0}:null),u(null)}catch(c){if(n.current!==s)return;throw u(B(c)),c}},[e,d]),h=r.useCallback(async()=>{n.current+=1;const a=n.current;try{let s;try{s=await ae(e)}catch{s=(await ke(e)).map(l=>({name:l.name,command:l.command,cwd:l.cwd,scriptName:l.scriptName,packagePath:l.packagePath}))}if(n.current!==a)return;M(s),u(null)}catch(s){if(n.current!==a)return;throw u(B(s)),s}},[e]),p=r.useCallback(async(a,s)=>{if(typeof a!="string"&&!d)try{const v=a,S=await Se({command:v.command,cwd:v.cwd,scriptName:v.scriptName,packagePath:v.packagePath??v.cwd},e),g=W(S);o(g),y([g]),u(null);return}catch(v){throw u(B(v)),v}const c=typeof a=="string"?a:a.command,l=typeof a=="string"?s:a.cwd;await _(c,l)},[e,_,d]),E=r.useCallback(async()=>{await D()},[D]),L=r.useCallback(async()=>{await k()},[k]),z=r.useCallback(async a=>{await T(a)},[T]),F=r.useCallback(async()=>{await h()},[h]),O=r.useCallback(async()=>{await A()},[A]),H=yt(i),x=i?{...i,pid:i.runtime?.pid}:null;return{session:i,sessions:b,logs:w,detectedCommands:j,previewUrl:H,isLoading:C,error:N,startServer:_,stopServer:D,restartServer:k,setPreviewUrl:T,detectCommands:h,refresh:A,candidates:j,serverState:x,loading:C,start:p,stop:E,restart:L,setManualUrl:z,detect:F,refreshStatus:O}}const je=500,Ce=100;function ze(e){return e.length>je?e.slice(-je):e}function $e(e){return e==="stderr"?"stderr":"stdout"}function Y(e){try{return JSON.parse(e.data)}catch{return null}}function Z(e,i){return{id:typeof e.id=="number"&&Number.isFinite(e.id)?e.id:i,text:typeof e.text=="string"?e.text:"",stream:$e(e.stream),timestamp:typeof e.timestamp=="string"?e.timestamp:""}}function jt(e,i){return{id:i,text:e,stream:"stdout",timestamp:""}}function oe(e,i){if(i.length===0)return e;const o=[...e],b=new Set(e.map(y=>y.id));for(const y of i)b.has(y.id)||(b.add(y.id),o.push(y));return o.sort((y,w)=>y.id-w.id),ze(o)}function Ct(e,i){const[o,b]=r.useState([]),[y,w]=r.useState(!1),[f,j]=r.useState(!1),[M,C]=r.useState(!1),[P,N]=r.useState(null),u=r.useRef(null),n=r.useRef(!1),d=r.useRef(0),U=r.useRef(0),R=r.useRef(e),A=r.useRef(i),_=r.useRef(0),D=r.useRef(1);(R.current!==e||A.current!==i)&&(R.current=e,A.current=i,d.current++,n.current=!0,_.current=0,D.current=1,b([]),w(!1),j(!1),C(!1),N(null),u.current&&(u.current(),u.current=null)),r.useEffect(()=>{if(!i){u.current&&(u.current(),u.current=null);return}const E=d.current,L=++U.current;n.current=!1,w(!0);const z=(x,a)=>{const s=ze(x);b(s),N(a),C(a!==null?a>s.length:!1);const c=s.length>0?s[s.length-1].id:0;_.current=c,D.current=c+1},F=x=>{if(n.current||d.current!==E||!x||typeof x!="object")return;const a=x.lines;if(!Array.isArray(a))return;if(a.length>0&&typeof a[0]=="string"){const c=a.filter(l=>typeof l=="string").map((l,v)=>jt(l,v+1));z(c,c.length);return}const s=a.filter(c=>!!c&&typeof c=="object").map((c,l)=>Z(c,l+1));z(s,s.length)},O=x=>{if(n.current||d.current!==E)return;const a=typeof x.text=="string"?x.text:typeof x.line=="string"?x.line:null;if(!a)return;const s=D.current,c=typeof x.id=="number"&&Number.isFinite(x.id)?x.id:s,l={id:c,text:a,stream:$e(x.stream),timestamp:typeof x.timestamp=="string"?x.timestamp:""};_.current=Math.max(_.current,c),D.current=Math.max(D.current,c+1),b(v=>oe(v,[l])),N(v=>v===null?v:Math.max(v+1,l.id))};async function H(){try{const a=await ie({maxLines:Ce},e);if(n.current||d.current!==E||U.current!==L)return;const s=a.lines.map((c,l)=>Z(c,l+1));z(s,a.totalLines)}catch{if(n.current||d.current!==E||U.current!==L)return;z([],null)}finally{!n.current&&d.current===E&&U.current===L&&w(!1)}const x=ue(e);u.current=Ue(x,{events:{"dev-server:log":a=>{const s=Y(a);s&&O(s)},log:a=>{const s=Y(a);s&&O(s)},history:a=>{const s=Y(a);F(s)},"dev-server:history":a=>{const s=Y(a);F(s)}},onReconnect:()=>{n.current||d.current!==E||ie({lastEventId:_.current,maxLines:50},e).then(a=>{if(n.current||d.current!==E)return;const s=a.lines.map((c,l)=>Z(c,D.current+l));if(s.length>0){const c=s[s.length-1].id;_.current=Math.max(_.current,c),D.current=Math.max(D.current,c+1)}b(c=>oe(c,s)),N(a.totalLines)}).catch(()=>{})}})}return H(),()=>{n.current=!0,u.current&&(u.current(),u.current=null)}},[i,e]);const T=r.useCallback(async()=>{if(!i||f)return;const E=d.current,L=o.length;j(!0);try{const z=await ie({maxLines:Ce,offset:L},e);if(n.current||d.current!==E)return;const F=z.lines.map((O,H)=>Z(O,H+1));b(O=>oe(F,O)),C(z.totalLines>L+F.length),N(z.totalLines)}catch{}finally{j(!1)}},[i,o.length,f,e]),h=r.useCallback(()=>{b([])},[]),p=u.current!==null&&!y&&!n.current;return{entries:o,loading:y,loadingMore:f,hasMore:M,total:P,loadMore:T,clear:h,logs:o,isStreaming:p,clearLogs:h}}const Et="This preview appears to block iframe embedding. Open it in a new tab instead.",Lt="The preview URL could not be loaded. Verify the server is running and the URL is correct.",Rt="Preview is taking longer than expected and may block iframe embedding.";function _t(e){return e==="blocked"?Et:e==="error"?Lt:null}function Dt(e,i={}){const{loadTimeoutMs:o=1e4,detectionMethod:b=null}=i,y=r.useRef(null),w=r.useRef(null),[f,j]=r.useState("unknown"),[M,C]=r.useState(null),[P]=r.useState(b),N=r.useCallback(()=>{w.current!==null&&(window.clearTimeout(w.current),w.current=null)},[]),u=r.useCallback(k=>{j(k),C(_t(k))},[]),n=r.useCallback(()=>{j("blocked"),C(Rt)},[]);r.useEffect(()=>{if(N(),!e){j("unknown"),C(null);return}j("unknown"),C(null);let k=!1;return queueMicrotask(()=>{k||(j("loading"),C(null))}),()=>{k=!0,N()}},[N,e]),r.useEffect(()=>{if(f!=="loading"){N();return}const k=setTimeout(()=>{w.current=null,n()},o);return w.current=k,()=>{clearTimeout(k),w.current===k&&(w.current=null)}},[N,f,o,n]);const d=r.useCallback(()=>{const k=y.current;if(!k){u("embedded");return}try{if(k.contentWindow?.location?.href==="about:blank"&&k.src!=="about:blank"){u("blocked");return}}catch{}u("embedded")},[u]),U=r.useCallback(()=>{u("error")},[u]);r.useEffect(()=>{if(N(),!e){j("unknown"),C(null);return}j("unknown"),C(null)},[N]);const R=r.useCallback(()=>{N(),j("unknown"),C(null)},[N]),A=R,_=r.useMemo(()=>f==="embedded",[f]),D=r.useMemo(()=>f==="blocked"||f==="error",[f]);return{embedStatus:f,isEmbedded:_,isBlocked:D,blockReason:M,detectionMethod:P,iframeRef:y,resetEmbedStatus:R,setEmbedStatus:u,retry:A,embedContext:M,handleIframeLoad:d,handleIframeError:U}}const Mt=/\x1b\[[0-9;]*m/g;function me(e){return e.replace(Mt,"")}function Ut(e){if(!e)return"";const i=new Date(e);return Number.isNaN(i.getTime())?"":i.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1})}function At(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Pt(e){if(e.stream==="stderr")return"error";const i=me(e.text).toLowerCase();return/\b(warn|warning)\b/.test(i)?"warn":/\b(error|fatal)\b/.test(i)?"error":"info"}function Tt(e,i){if(!i)return e;const o=new RegExp(`(${At(i)})`,"ig"),b=e.split(o),y=i.toLowerCase();return t.jsx(t.Fragment,{children:b.map((w,f)=>w.toLowerCase()===y?t.jsx("mark",{children:w},`${w}-${f}`):t.jsx("span",{children:w},`${w}-${f}`))})}function zt({entries:e,loading:i,loadingMore:o,hasMore:b,total:y,onLoadMore:w,isRunning:f}){const j=r.useRef(null),M=r.useRef(e.length),C=r.useRef(f),[P,N]=r.useState(!1),[u,n]=r.useState(!1),[d,U]=r.useState(""),[R,A]=r.useState("all"),_=r.useMemo(()=>R==="all"?e:e.filter(p=>Pt(p)===R),[e,R]),D=r.useMemo(()=>{const p=d.trim().toLowerCase();return p?_.filter(E=>me(E.text).toLowerCase().includes(p)):_},[_,d]),k=D.length,T=r.useCallback(()=>{const p=j.current;p&&(p.scrollTop=p.scrollHeight,n(!1))},[]);r.useEffect(()=>{const p=C.current,E=M.current,L=e.length>E;f&&(!p||!u&&L)&&T(),C.current=f,M.current=e.length},[e.length,f,u,T]);const h=r.useCallback(()=>{const p=j.current;if(!p)return;const L=p.scrollTop+p.clientHeight>=p.scrollHeight-50;n(!L)},[]);return r.useEffect(()=>{i||e.length===0||!u&&f&&T()},[e,f,u,i,T]),i&&e.length===0?t.jsx("section",{className:"devserver-log-viewer","data-testid":"devserver-log-viewer",children:t.jsxs("div",{className:"devserver-log-viewer__loading","data-testid":"devserver-log-loading",children:[t.jsx(ee,{size:16,className:"devserver-log-viewer__spinner"}),t.jsx("span",{children:"Loading logs…"})]})}):t.jsxs("section",{className:`devserver-log-viewer${P?" devserver-log-viewer--fullscreen":""}`,"data-testid":"devserver-log-viewer",children:[t.jsxs("header",{className:"devserver-log-viewer__toolbar",children:[t.jsxs("div",{className:"devserver-log-viewer__toolbar-meta",children:[t.jsx("span",{className:"devserver-log-viewer__title",children:"Logs"}),t.jsxs("span",{className:"devserver-log-viewer__count","data-testid":"devserver-log-count",children:[y!==null?`${e.length}/${y}`:`${e.length}`," lines"]})]}),t.jsxs("div",{className:"devserver-log-viewer__toolbar-actions",children:[t.jsxs("label",{className:"devserver-log-viewer__severity",htmlFor:"devserver-log-severity-filter",children:[t.jsx("span",{className:"visually-hidden",children:"Filter logs by severity"}),t.jsxs("select",{id:"devserver-log-severity-filter",className:"select devserver-log-viewer__severity-select",value:R,onChange:p=>A(p.target.value),"data-testid":"devserver-log-severity-filter","aria-label":"Filter logs by severity",children:[t.jsx("option",{value:"all",children:"All severities"}),t.jsx("option",{value:"info",children:"Info"}),t.jsx("option",{value:"warn",children:"Warn"}),t.jsx("option",{value:"error",children:"Error"})]})]}),t.jsxs("label",{className:"devserver-log-viewer__search",htmlFor:"devserver-log-search",children:[t.jsx("span",{className:"visually-hidden",children:"Search logs"}),t.jsx(lt,{size:14}),t.jsx("input",{id:"devserver-log-search",className:"input devserver-log-viewer__search-input",type:"text",value:d,onChange:p=>U(p.target.value),placeholder:"Search logs","data-testid":"devserver-log-search-input","aria-label":"Search logs"})]}),d.trim().length>0&&t.jsxs("span",{className:"devserver-log-viewer__matches","data-testid":"devserver-log-match-count",children:[k," match",k===1?"":"es"]}),t.jsx("button",{type:"button",className:"btn btn-sm btn-icon",onClick:()=>N(p=>!p),"data-testid":"devserver-log-fullscreen-toggle","aria-label":P?"Exit fullscreen logs":"Enter fullscreen logs",children:P?t.jsx(ct,{size:14}):t.jsx(ot,{size:14})})]})]}),t.jsxs("div",{className:"devserver-log-viewer__body",children:[b&&t.jsx("div",{className:"devserver-log-viewer__load-more","data-testid":"devserver-log-load-more",children:t.jsx("button",{type:"button",className:"btn btn-sm touch-target",onClick:w,disabled:o,"data-testid":"devserver-log-load-more-button",children:o?t.jsxs(t.Fragment,{children:[t.jsx(ee,{size:14,className:"devserver-log-viewer__spinner"}),"Loading older logs…"]}):"Load older logs"})}),t.jsxs("div",{ref:j,className:"devserver-log-viewer__content",onScroll:h,"data-testid":"devserver-log-content",children:[!i&&D.length===0&&t.jsx("p",{className:"devserver-log-viewer__empty","data-testid":"devserver-log-empty",children:e.length===0?"No logs yet. Start the dev server to see output.":_.length===0?"No log lines match the selected severity.":"No log lines match your search."}),D.map(p=>{const E=me(p.text),L=Ut(p.timestamp);return t.jsxs("div",{className:"devserver-log-line",children:[L&&t.jsx("span",{className:"devserver-log-timestamp","data-testid":"devserver-log-timestamp",children:L}),p.stream==="stderr"&&t.jsx("span",{className:"devserver-log-stream-badge","data-testid":"devserver-log-stderr-badge",children:"ERR"}),t.jsx("span",{className:"devserver-log-text",children:Tt(E,d.trim())})]},p.id)})]}),u&&f&&t.jsxs("button",{type:"button",className:"btn btn-sm devserver-log-viewer__new-logs-button",onClick:T,"data-testid":"devserver-log-jump-button",children:[t.jsx(dt,{size:14}),"New logs"]})]})]})}const $t="devserver-preview-iframe";function Ft({url:e,embedStatus:i,onEmbedStatusChange:o,iframeRef:b,blockReason:y,onRetry:w,className:f=$t,embedContext:j}){const M=y??j??null,[C,P]=r.useState(0);r.useEffect(()=>{!e||i!=="unknown"||(P(d=>d+1),o("loading"))},[i,o,e]);const N=r.useCallback(()=>{const d=b.current;if(!d){o("embedded");return}try{if(d.contentWindow?.location?.href==="about:blank"&&d.src!=="about:blank"){o("blocked");return}}catch{}o("embedded")},[b,o]),u=r.useCallback(d=>{d.stopPropagation(),o("error")},[o]),n=r.useCallback(()=>{e&&window.open(e,"_blank","noopener,noreferrer")},[e]);return e?t.jsxs("div",{className:"devserver-preview-iframe-shell",children:[t.jsx("iframe",{src:e,ref:b,sandbox:"allow-scripts allow-same-origin allow-forms allow-popups allow-popups-to-escape-sandbox",className:f,title:"Dev server preview",onLoad:N,onError:u,onErrorCapture:u,"data-testid":"devserver-preview-iframe"},`${e}-${C}`),i==="loading"&&t.jsxs("div",{className:"devserver-preview-overlay","data-testid":"devserver-preview-loading",children:[t.jsx(ee,{size:16,className:"dev-server-spin"}),t.jsx("span",{children:"Loading preview..."})]}),i==="blocked"&&t.jsxs("div",{className:"devserver-preview-blocked-panel",role:"alert","data-testid":"devserver-preview-blocked-panel",children:[t.jsx(Pe,{className:"devserver-preview-blocked-icon","aria-hidden":"true"}),t.jsxs("div",{children:[t.jsx("p",{className:"devserver-preview-blocked-title",children:"Preview cannot be embedded"}),M&&t.jsx("p",{className:"devserver-preview-blocked-context",children:M})]}),t.jsx("p",{className:"devserver-preview-blocked-description",children:"You can view the preview in a separate browser tab."}),t.jsxs("div",{className:"devserver-preview-blocked-actions",children:[t.jsx("button",{type:"button",className:"btn btn-primary",onClick:n,children:"Open in new tab"}),w&&t.jsx("button",{type:"button",className:"btn btn-sm",onClick:w,children:"Retry"})]})]}),i==="error"&&t.jsxs("div",{className:"devserver-preview-error-panel",role:"alert","data-testid":"devserver-preview-error-panel",children:[t.jsx(Ae,{className:"devserver-preview-blocked-icon","aria-hidden":"true"}),t.jsxs("div",{children:[t.jsx("p",{className:"devserver-preview-blocked-title",children:"Unable to load preview"}),M&&t.jsx("p",{className:"devserver-preview-blocked-context",children:M})]}),t.jsx("p",{className:"devserver-preview-blocked-description",children:"You can view the preview in a separate browser tab."}),t.jsxs("div",{className:"devserver-preview-blocked-actions",children:[t.jsx("button",{type:"button",className:"btn btn-primary",onClick:n,children:"Open in new tab"}),w&&t.jsx("button",{type:"button",className:"btn btn-sm",onClick:w,children:"Retry"})]})]})]}):null}const Ee={stopped:{className:"dev-server-status-badge--stopped",label:"Stopped"},starting:{className:"dev-server-status-badge--starting",label:"Starting..."},running:{className:"dev-server-status-badge--running",label:"Running"},stopping:{className:"dev-server-status-badge--starting",label:"Stopping..."},failed:{className:"dev-server-status-badge--failed",label:"Failed"}};function Le(e){return e instanceof Error?e.message:String(e)}function Fe(e){return e==="."?"root":e}function Re(e){return e?e==="root"?".":e:null}function _e(e,i,o){return!i||e.scriptName!==i?!1:o?Fe(e.cwd)===o:!0}function Ot(e){return e.cwd==="."?"root":e.cwd}function Bt(e){return e.length<=60?e:`${e.slice(0,60)}…`}function Wt({addToast:e,projectId:i}){const{session:o,detectedCommands:b,previewUrl:y,isLoading:w,error:f,startServer:j,stopServer:M,restartServer:C,setPreviewUrl:P,detectCommands:N,refresh:u}=kt(i),n=o?.status??"stopped",d=n==="running"||n==="starting",U=Ee[n]??Ee.stopped,{entries:R,loading:A,loadingMore:_,hasMore:D,total:k,loadMore:T}=Ct(i,!!i),h=y,p=o?.config?.cwd??null,[E,L]=r.useState(!0),[z,F]=r.useState(""),[O,H]=r.useState(""),[x,a]=r.useState(null),[s,c]=r.useState(null),[l,v]=r.useState("embedded"),S=l==="embedded"?h:null,{embedStatus:g,setEmbedStatus:Oe,resetEmbedStatus:G,iframeRef:I,isEmbedded:Be,isBlocked:te,blockReason:re,retry:fe}=Dt(S),[pe,q]=r.useState(!1),he=r.useRef(g);r.useEffect(()=>{const m=he.current!==g;te&&m&&q(!0),g==="embedded"&&q(!1),he.current=g},[g,te]),r.useEffect(()=>{q(!1)},[h]);const J=r.useMemo(()=>{if(!x)return null;const m=Re(p);return b.find($=>!($.scriptName!==x||m&&$.cwd!==m||o?.config?.command&&$.command!==o.config.command))??b.find($=>_e($,x,p))??null},[b,o?.config?.command,x,p]);r.useEffect(()=>{typeof N=="function"&&N().catch(m=>{e(Le(m),"error")})},[e,N]),r.useEffect(()=>{if(x){L(!1);return}L(!0)},[x]),r.useEffect(()=>{if(o?.status==="running"||o?.status==="starting"){o.config?.command?.trim().length>0&&F(o.config.command);return}if(J){F(J.command);return}b.length>0&&F(m=>m.trim().length>0?m:b[0]?.command??"")},[b,J,o?.config?.command,o?.status]),r.useEffect(()=>{H(h??"")},[h]);const se=r.useCallback(()=>{h&&window.open(h,"_blank","noopener,noreferrer")},[h]),be=r.useCallback(()=>{q(!1),fe()},[fe]),He=r.useCallback(()=>{try{const m=I.current;if(m?.contentWindow){m.contentWindow.location.reload(),q(!1),G();return}}catch{}if(!(!h||!I.current))try{const m=new URL(h);m.searchParams.set("_t",Date.now().toString()),I.current.src=m.toString(),q(!1),G()}catch{I.current.src=h,q(!1),G()}},[h,I,G]),K=r.useCallback(async(m,$,ne)=>{c(m);try{await $(),e(ne,"success")}catch(Ze){e(Le(Ze),"error")}finally{c(null)}},[e]),Ve=r.useCallback(m=>{a(m.scriptName),L(!1),F(m.command),e(`Selected ${m.scriptName} script.`,"success")},[e]),qe=r.useCallback(()=>{a(null),L(!0),e("Cleared selected dev server script.","success")},[e]),We=()=>{const m=z.trim();if(m.length===0){e("Enter a command before starting the dev server.","warning");return}const $=Re(p)??".",ne=J?.cwd??$;K("start",()=>j(m,ne),"Dev server started.")},Ie=()=>{K("stop",M,"Dev server stopped.")},Xe=()=>{K("restart",C,"Dev server restarted.")},Ge=()=>{const m=O.trim(),$=m.length>0?m:null;K("preview",()=>P($),$?"Preview URL updated.":"Preview URL override cleared.")},Je=r.useCallback(()=>{f&&u()},[f,u]),Ke=n==="starting"||n==="running"||s!==null,Qe=n==="stopped"||s!==null,Ye=n==="stopped"||n==="starting"||s!==null;return t.jsxs("div",{className:"dev-server-view","data-testid":"dev-server-view",children:[t.jsxs("section",{className:"dev-server-header","aria-label":"Dev server controls header",children:[t.jsxs("div",{className:"dev-server-header-title",children:[t.jsx(ut,{size:16}),t.jsx("h2",{children:"Dev Server"}),t.jsx("span",{className:`dev-server-status-badge ${U.className}`,"data-testid":"dev-server-status-badge",children:U.label})]}),t.jsxs("div",{className:"dev-server-header-actions",children:[t.jsxs("button",{type:"button",className:"btn btn-primary btn-sm",onClick:We,disabled:Ke,"data-testid":"dev-server-start-button",children:[t.jsx(vt,{size:14}),t.jsx("span",{children:s==="start"?"Starting...":"Start"})]}),t.jsxs("button",{type:"button",className:"btn btn-danger btn-sm",onClick:Ie,disabled:Qe,"data-testid":"dev-server-stop-button",children:[t.jsx(mt,{size:14}),t.jsx("span",{children:s==="stop"?"Stopping...":"Stop"})]}),t.jsxs("button",{type:"button",className:"btn btn-sm",onClick:Xe,disabled:Ye,"data-testid":"dev-server-restart-button",children:[t.jsx(gt,{size:14}),t.jsx("span",{children:s==="restart"?"Restarting...":"Restart"})]})]})]}),t.jsxs("section",{className:"dev-server-panel dev-server-config","aria-label":"Dev server configuration",children:[t.jsxs("div",{className:"dev-server-section-header",children:[t.jsx("h3",{children:"Configuration"}),w&&t.jsx("span",{className:"dev-server-muted",children:"Loading..."})]}),w&&!o&&b.length===0&&t.jsxs("div",{className:"dev-server-loading-state","data-testid":"dev-server-loading-state",children:[t.jsx(ee,{size:16,className:"dev-server-spin"}),t.jsx("span",{children:"Loading dev server configuration..."})]}),f&&t.jsxs("div",{className:"dev-server-error-box",role:"alert","data-testid":"dev-server-error-box",children:[t.jsx("p",{children:f}),t.jsx("button",{type:"button",className:"btn btn-sm",onClick:Je,children:"Retry"})]}),t.jsxs("div",{className:"dev-server-section",children:[t.jsx("h3",{children:"Script Selection"}),x&&t.jsxs("div",{className:"dev-server-selected","data-testid":"dev-server-selected-summary",children:[t.jsx("span",{className:"dev-server-candidate-name",children:x}),t.jsx("span",{className:"dev-server-candidate-source",children:p??"root"}),t.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>L(!0),"data-testid":"dev-server-change-selection",children:"Change"}),t.jsx("button",{type:"button",className:"btn btn-danger btn-sm",onClick:qe,"data-testid":"dev-server-clear-selection",children:"Clear"})]}),E&&b.length===0&&t.jsxs("p",{className:"dev-server-empty-state","data-testid":"dev-server-empty-candidates",children:["No dev server scripts detected. Check that your project has a ",t.jsx("code",{children:"package.json"})," with a ",t.jsx("code",{children:"dev"}),", ",t.jsx("code",{children:"start"}),", or similar script."]}),E&&b.length>0&&t.jsx("div",{className:"dev-server-candidates","data-testid":"dev-server-candidates",children:b.map(m=>{const $=_e(m,x,p);return t.jsxs("button",{type:"button",className:`dev-server-candidate ${$?"dev-server-candidate--selected":""}`,onClick:()=>Ve(m),"data-testid":`dev-server-candidate-${m.scriptName}-${Fe(m.cwd)}`,children:[t.jsx("span",{className:"dev-server-candidate-name",children:m.scriptName}),t.jsx("span",{className:"dev-server-candidate-command",children:Bt(m.command)}),t.jsx("span",{className:"dev-server-candidate-source",children:Ot(m)})]},`${m.cwd}::${m.scriptName}::${m.command}`)})})]}),t.jsxs("div",{className:"dev-server-field-group",children:[t.jsx("label",{htmlFor:"dev-server-command",className:"dev-server-label",children:"Command"}),t.jsx("input",{id:"dev-server-command",className:"input",value:z,onChange:m=>F(m.target.value),placeholder:"pnpm dev","data-testid":"dev-server-command-input",readOnly:n==="running"||n==="starting"})]}),(n==="running"||n==="starting")&&o&&t.jsxs("div",{className:"dev-server-current-command","data-testid":"dev-server-current-command",children:[t.jsx("span",{className:"dev-server-label",children:"Running command"}),t.jsx("code",{children:o.config?.command??z})]}),t.jsxs("div",{className:"dev-server-preview-override",children:[t.jsx("label",{htmlFor:"dev-server-preview-input",className:"dev-server-label",children:"Preview URL Override"}),t.jsx("input",{id:"dev-server-preview-input",className:"input",type:"url",value:O,onChange:m=>H(m.target.value),placeholder:"http://localhost:3000","data-testid":"dev-server-preview-input"}),t.jsx("button",{type:"button",className:"btn btn-primary btn-sm",onClick:Ge,disabled:s==="preview","data-testid":"dev-server-set-preview",children:"Save"})]}),h&&t.jsxs("p",{className:"dev-server-preview-hint",children:["Auto-detected: ",h]})]}),t.jsxs("div",{className:"dev-server-content",children:[t.jsxs("section",{className:"dev-server-panel dev-server-logs-panel","data-testid":"dev-server-logs-panel","aria-label":"Dev server logs",children:[t.jsxs("div",{className:"dev-server-section-header",children:[t.jsx("h3",{children:"Logs"}),t.jsxs("span",{className:"dev-server-muted",children:[k??R.length," lines"]})]}),t.jsx("div",{className:"dev-server-logs-viewer","data-testid":"dev-server-log-viewer",children:t.jsx(zt,{entries:R,loading:A,loadingMore:_,hasMore:D,total:k,onLoadMore:T,isRunning:d})})]}),t.jsxs("section",{className:"dev-server-panel devserver-preview-panel","data-testid":"devserver-preview-panel","aria-label":"Dev server preview",children:[t.jsxs("div",{className:"devserver-preview-header",children:[t.jsxs("div",{className:"devserver-preview-title",children:[t.jsx(ft,{size:14}),t.jsx("span",{children:"Preview"})]}),t.jsxs("span",{className:"devserver-preview-url-badge devserver-preview-url-badge--auto",title:h??"No preview URL","data-testid":"devserver-preview-url-badge",children:["Auto",h?` · ${h}`:" · Not available"]}),t.jsxs("div",{className:"devserver-preview-actions",children:[t.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>v(m=>m==="embedded"?"external":"embedded"),"data-testid":"devserver-preview-mode-toggle",children:l==="embedded"?"External only":"Embedded"}),t.jsx("button",{type:"button",className:"btn btn-sm btn-icon",title:"Open in new tab",onClick:se,disabled:!h,"data-testid":"devserver-preview-open-tab",children:t.jsx(pt,{size:14})}),t.jsx("button",{type:"button",className:"btn btn-sm btn-icon",title:"Refresh preview",onClick:He,disabled:!h,"data-testid":"devserver-preview-refresh",children:t.jsx(ht,{size:14})})]})]}),t.jsxs("div",{className:"devserver-preview-container","data-embed-status":g,"data-embedded":Be?"true":"false",children:[!h&&!d&&t.jsx("p",{className:"devserver-preview-empty",children:"Start a dev server to see a live preview here."}),!h&&d&&t.jsx("p",{className:"devserver-preview-empty",children:"No preview URL detected. Start the dev server or set a manual URL to preview your app."}),h&&l==="external"&&t.jsxs("div",{className:"devserver-preview-external-only","data-testid":"devserver-preview-external-only",children:[t.jsx("p",{children:"Embedded preview is disabled. Open your app in a separate browser tab."}),t.jsx("button",{type:"button",className:"btn btn-primary btn-sm touch-target",onClick:se,"data-testid":"devserver-preview-external-open-tab",children:"Open in new tab"})]}),h&&l==="embedded"&&pe&&te&&t.jsxs("div",{className:g==="error"?"devserver-preview-error-panel":"devserver-preview-blocked-panel","data-testid":"devserver-preview-fallback",role:"alert",children:[g==="error"?t.jsx(Ae,{className:"devserver-preview-blocked-icon","aria-hidden":"true"}):t.jsx(Pe,{className:"devserver-preview-blocked-icon","aria-hidden":"true"}),t.jsxs("div",{children:[t.jsx("p",{className:"devserver-preview-blocked-title",children:g==="error"?"Preview failed":"Preview blocked"}),re&&t.jsx("p",{className:"devserver-preview-blocked-context",children:re})]}),t.jsx("p",{className:"devserver-preview-blocked-description",children:"Open the preview in a new tab, or retry embedded mode after checking your server settings."}),t.jsxs("div",{className:"devserver-preview-blocked-actions",children:[t.jsx("button",{type:"button",className:"btn btn-primary",onClick:se,"data-testid":"devserver-preview-fallback-open-tab",children:"Open preview in new tab"}),t.jsx("button",{type:"button",className:"btn btn-sm",onClick:be,"data-testid":"devserver-preview-fallback-retry",children:"Retry embedded preview"})]})]}),h&&l==="embedded"&&!pe&&t.jsx(Ft,{url:h,embedStatus:g,onEmbedStatusChange:Oe,iframeRef:I,blockReason:re,onRetry:be})]})]})]})]})}export{Wt as DevServerView};
@@ -1 +1 @@
1
- import{r as i,j as r}from"./vendor-react-K0fH_qHe.js";import{bV as f,bW as m,D as y,a7 as g,a2 as P,a3 as C,L as H,ae as O}from"./index-rNf7s96d.js";import{F as v}from"./folder-open-CI4TCD7P.js";function S({value:d,onChange:l,placeholder:x,onInputKeyDown:j,nodeId:h,localNodeId:p}){const[e,n]=i.useState({isOpen:!1,loading:!1,error:null,currentPath:"",parentPath:null,entries:[],showHidden:!1}),a=i.useCallback(async(s,c=!1)=>{n(t=>({...t,loading:!0,error:null}));try{const t=await f(s,c,h,p);n(b=>({...b,loading:!1,currentPath:t.currentPath,parentPath:t.parentPath,entries:t.entries}))}catch(t){n(b=>({...b,loading:!1,error:t instanceof Error?t.message:"Failed to browse directory"}))}},[h,p]),k=i.useCallback(()=>{n(s=>s.isOpen?{...s,isOpen:!1}:{...s,isOpen:!0})},[]);i.useEffect(()=>{e.isOpen&&!e.loading&&e.entries.length===0&&!e.error&&a(d||void 0,e.showHidden)},[e.isOpen,e.loading,e.entries.length,e.error,d,e.showHidden,a,h,p]);const o=i.useCallback(s=>{a(s,e.showHidden)},[a,e.showHidden]),w=i.useCallback(()=>{l(e.currentPath),n(s=>({...s,isOpen:!1}))},[e.currentPath,l]),N=i.useCallback(()=>{n(s=>{const c=!s.showHidden;return{...s,showHidden:c}})},[]);i.useEffect(()=>{e.isOpen&&e.currentPath&&a(e.currentPath,e.showHidden)},[e.showHidden]);const u=e.currentPath?e.currentPath.split("/").filter(Boolean):[];return r.jsxs("div",{className:"directory-picker",children:[r.jsxs("div",{className:"directory-picker-input-row",children:[r.jsx("input",{type:"text",className:"input directory-picker-input",value:d,onChange:s=>l(s.target.value),onKeyDown:j,placeholder:x||"/path/to/your/project"}),r.jsxs("button",{type:"button",className:"btn btn-secondary btn-sm directory-picker-browse-btn",onClick:k,"aria-label":e.isOpen?"Close directory browser":"Browse directories",children:[e.isOpen?r.jsx(v,{size:16}):r.jsx(m,{size:16}),r.jsx("span",{children:"Browse"})]})]}),e.isOpen&&r.jsxs("div",{className:"directory-picker-browser",role:"tree","aria-label":"Directory browser",children:[r.jsxs("div",{className:"directory-picker-breadcrumbs",children:[r.jsx("button",{type:"button",className:"directory-picker-breadcrumb",onClick:()=>o("/"),title:"Root",children:"/"}),u.map((s,c)=>{const t="/"+u.slice(0,c+1).join("/");return r.jsxs("span",{className:"directory-picker-breadcrumb-item",children:[r.jsx(y,{size:12,className:"directory-picker-breadcrumb-sep"}),r.jsx("button",{type:"button",className:"directory-picker-breadcrumb",onClick:()=>o(t),title:t,children:s})]},t)})]}),r.jsxs("div",{className:"directory-picker-toolbar",children:[e.parentPath&&r.jsxs("button",{type:"button",className:"btn btn-sm btn-secondary directory-picker-up-btn",onClick:()=>o(e.parentPath),"aria-label":"Go to parent directory",title:"Parent directory",children:[r.jsx(g,{size:14}),r.jsx("span",{children:"Up"})]}),r.jsxs("button",{type:"button",className:"btn btn-sm btn-secondary directory-picker-hidden-toggle",onClick:N,"aria-label":e.showHidden?"Hide hidden directories":"Show hidden directories",title:e.showHidden?"Hide hidden":"Show hidden",children:[e.showHidden?r.jsx(P,{size:14}):r.jsx(C,{size:14}),r.jsx("span",{children:e.showHidden?"Hide hidden":"Show hidden"})]})]}),e.loading?r.jsxs("div",{className:"directory-picker-loading",children:[r.jsx(H,{size:20,className:"animate-spin"}),r.jsx("span",{children:"Loading…"})]}):e.error?r.jsxs("div",{className:"directory-picker-error",children:[r.jsx(O,{size:16}),r.jsx("span",{children:e.error})]}):r.jsx("div",{className:"directory-picker-entries",children:e.entries.length===0?r.jsx("div",{className:"directory-picker-empty",children:"No subdirectories"}):e.entries.map(s=>r.jsxs("button",{type:"button",className:"directory-picker-entry",onClick:()=>o(s.path),role:"treeitem",title:s.path,children:[r.jsx(m,{size:16,className:"directory-picker-entry-icon"}),r.jsx("span",{className:"directory-picker-entry-name",children:s.name}),s.hasChildren&&r.jsx(y,{size:14,className:"directory-picker-entry-arrow"})]},s.path))}),r.jsxs("div",{className:"directory-picker-actions",children:[r.jsx("span",{className:"directory-picker-selected-path",title:e.currentPath,children:e.currentPath}),r.jsx("button",{type:"button",className:"btn btn-primary directory-picker-select-btn",onClick:w,children:"Select"})]})]})]})}export{S as D};
1
+ import{r as i,j as r}from"./vendor-react-K0fH_qHe.js";import{cY as f,c4 as m,D as y,a7 as g,a2 as P,a3 as C,L as H,ae as O}from"./index-DQKtk17v.js";import{F as v}from"./folder-open-B_38R5AA.js";function S({value:d,onChange:l,placeholder:x,onInputKeyDown:j,nodeId:h,localNodeId:p}){const[e,n]=i.useState({isOpen:!1,loading:!1,error:null,currentPath:"",parentPath:null,entries:[],showHidden:!1}),a=i.useCallback(async(s,c=!1)=>{n(t=>({...t,loading:!0,error:null}));try{const t=await f(s,c,h,p);n(b=>({...b,loading:!1,currentPath:t.currentPath,parentPath:t.parentPath,entries:t.entries}))}catch(t){n(b=>({...b,loading:!1,error:t instanceof Error?t.message:"Failed to browse directory"}))}},[h,p]),k=i.useCallback(()=>{n(s=>s.isOpen?{...s,isOpen:!1}:{...s,isOpen:!0})},[]);i.useEffect(()=>{e.isOpen&&!e.loading&&e.entries.length===0&&!e.error&&a(d||void 0,e.showHidden)},[e.isOpen,e.loading,e.entries.length,e.error,d,e.showHidden,a,h,p]);const o=i.useCallback(s=>{a(s,e.showHidden)},[a,e.showHidden]),w=i.useCallback(()=>{l(e.currentPath),n(s=>({...s,isOpen:!1}))},[e.currentPath,l]),N=i.useCallback(()=>{n(s=>{const c=!s.showHidden;return{...s,showHidden:c}})},[]);i.useEffect(()=>{e.isOpen&&e.currentPath&&a(e.currentPath,e.showHidden)},[e.showHidden]);const u=e.currentPath?e.currentPath.split("/").filter(Boolean):[];return r.jsxs("div",{className:"directory-picker",children:[r.jsxs("div",{className:"directory-picker-input-row",children:[r.jsx("input",{type:"text",className:"input directory-picker-input",value:d,onChange:s=>l(s.target.value),onKeyDown:j,placeholder:x||"/path/to/your/project"}),r.jsxs("button",{type:"button",className:"btn btn-secondary btn-sm directory-picker-browse-btn",onClick:k,"aria-label":e.isOpen?"Close directory browser":"Browse directories",children:[e.isOpen?r.jsx(v,{size:16}):r.jsx(m,{size:16}),r.jsx("span",{children:"Browse"})]})]}),e.isOpen&&r.jsxs("div",{className:"directory-picker-browser",role:"tree","aria-label":"Directory browser",children:[r.jsxs("div",{className:"directory-picker-breadcrumbs",children:[r.jsx("button",{type:"button",className:"directory-picker-breadcrumb",onClick:()=>o("/"),title:"Root",children:"/"}),u.map((s,c)=>{const t="/"+u.slice(0,c+1).join("/");return r.jsxs("span",{className:"directory-picker-breadcrumb-item",children:[r.jsx(y,{size:12,className:"directory-picker-breadcrumb-sep"}),r.jsx("button",{type:"button",className:"directory-picker-breadcrumb",onClick:()=>o(t),title:t,children:s})]},t)})]}),r.jsxs("div",{className:"directory-picker-toolbar",children:[e.parentPath&&r.jsxs("button",{type:"button",className:"btn btn-sm btn-secondary directory-picker-up-btn",onClick:()=>o(e.parentPath),"aria-label":"Go to parent directory",title:"Parent directory",children:[r.jsx(g,{size:14}),r.jsx("span",{children:"Up"})]}),r.jsxs("button",{type:"button",className:"btn btn-sm btn-secondary directory-picker-hidden-toggle",onClick:N,"aria-label":e.showHidden?"Hide hidden directories":"Show hidden directories",title:e.showHidden?"Hide hidden":"Show hidden",children:[e.showHidden?r.jsx(P,{size:14}):r.jsx(C,{size:14}),r.jsx("span",{children:e.showHidden?"Hide hidden":"Show hidden"})]})]}),e.loading?r.jsxs("div",{className:"directory-picker-loading",children:[r.jsx(H,{size:20,className:"animate-spin"}),r.jsx("span",{children:"Loading…"})]}):e.error?r.jsxs("div",{className:"directory-picker-error",children:[r.jsx(O,{size:16}),r.jsx("span",{children:e.error})]}):r.jsx("div",{className:"directory-picker-entries",children:e.entries.length===0?r.jsx("div",{className:"directory-picker-empty",children:"No subdirectories"}):e.entries.map(s=>r.jsxs("button",{type:"button",className:"directory-picker-entry",onClick:()=>o(s.path),role:"treeitem",title:s.path,children:[r.jsx(m,{size:16,className:"directory-picker-entry-icon"}),r.jsx("span",{className:"directory-picker-entry-name",children:s.name}),s.hasChildren&&r.jsx(y,{size:14,className:"directory-picker-entry-arrow"})]},s.path))}),r.jsxs("div",{className:"directory-picker-actions",children:[r.jsx("span",{className:"directory-picker-selected-path",title:e.currentPath,children:e.currentPath}),r.jsx("button",{type:"button",className:"btn btn-primary directory-picker-select-btn",onClick:w,children:"Select"})]})]})]})}export{S as D};
@@ -0,0 +1 @@
1
+ .directory-picker{display:flex;flex-direction:column;gap:var(--space-sm)}.directory-picker-input-row{display:flex;gap:var(--space-sm)}.directory-picker-input{flex:1;min-width:0}.directory-picker-browse-btn{flex-shrink:0;white-space:nowrap}.directory-picker-browser{display:flex;flex-direction:column;background:var(--card);border:1px solid var(--border);border-radius:var(--radius-lg);overflow:hidden;animation:fadeIn var(--transition-fast)}.directory-picker-breadcrumbs{display:flex;align-items:center;gap:var(--space-xs);padding:var(--space-sm) var(--space-md);background:var(--surface);border-bottom:1px solid var(--border);overflow-x:auto;white-space:nowrap}.directory-picker-breadcrumb{background:none;border:none;padding:var(--space-xs);border-radius:var(--radius-sm);color:var(--todo);cursor:pointer;font-family:var(--font-mono)}.directory-picker-breadcrumb:hover{background:var(--card-hover);text-decoration:underline}.directory-picker-breadcrumb:focus-visible{outline:none;box-shadow:var(--focus-ring-strong)}.directory-picker-breadcrumb-item{display:inline-flex;align-items:center}.directory-picker-breadcrumb-sep{color:var(--text-dim);flex-shrink:0}.directory-picker-toolbar{display:flex;align-items:center;gap:var(--space-sm);padding:var(--space-xs) var(--space-md);border-bottom:1px solid var(--border)}.directory-picker-up-btn,.directory-picker-hidden-toggle{color:var(--text-muted)}.directory-picker-up-btn:hover,.directory-picker-hidden-toggle:hover{color:var(--text)}.directory-picker-up-btn:focus-visible,.directory-picker-hidden-toggle:focus-visible{outline:none;box-shadow:var(--focus-ring-strong)}.directory-picker-entries{max-height:calc(var(--space-2xl) * 8);overflow-y:auto;padding:var(--space-xs) 0}.directory-picker-entry{display:flex;align-items:center;gap:var(--space-sm);width:100%;padding:var(--space-xs) var(--space-md);background:none;border:none;color:var(--text);cursor:pointer;text-align:left;transition:background-color var(--transition-fast)}.directory-picker-entry:hover{background:var(--card-hover)}.directory-picker-entry:focus-visible{outline:none;box-shadow:var(--focus-ring-strong)}.directory-picker-entry-icon{color:var(--todo);flex-shrink:0}.directory-picker-entry-name{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.directory-picker-entry-arrow{color:var(--text-dim);flex-shrink:0}.directory-picker-loading,.directory-picker-empty{display:flex;align-items:center;justify-content:center;gap:var(--space-sm);padding:var(--space-xl);color:var(--text-muted)}.directory-picker-error{display:flex;align-items:center;gap:var(--space-sm);padding:var(--space-md);margin:var(--space-sm) var(--space-md);background:color-mix(in srgb,var(--color-error) 10%,transparent);border:1px solid var(--color-error);border-radius:var(--radius-md);color:var(--color-error)}.directory-picker-actions{display:flex;align-items:center;justify-content:space-between;gap:var(--space-md);padding:var(--space-sm) var(--space-md);border-top:1px solid var(--border);background:var(--surface)}.directory-picker-selected-path{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-family:var(--font-mono);color:var(--text-muted)}.directory-picker-select-btn{flex-shrink:0;padding:var(--space-sm) var(--space-lg)}
@@ -1 +1 @@
1
- import{r as s,j as e}from"./vendor-react-K0fH_qHe.js";import{Y as oe,$ as G,a0 as le,a1 as ie,F as z,a2 as de,a3 as ue,S as me,X as he,R as pe,a4 as fe,a5 as W,a6 as V,K as X,D as je,a7 as xe}from"./index-rNf7s96d.js";import"./vendor-xterm-DzcZoU0P.js";function we(n){const{projectId:c,searchQuery:u,includeProjectFiles:a=!0}=n??{},[x,l]=s.useState([]),[h,i]=s.useState([]),[o,p]=s.useState(!0),[k,b]=s.useState(null),f=s.useRef(null),g=s.useRef(!1),m=s.useRef(null),j=s.useCallback(async()=>{f.current&&f.current.abort();const C=new AbortController;f.current=C;const E=!g.current;E&&p(!0),b(null);const L=oe(u?{q:u}:void 0,c),y=a?G(c):Promise.resolve({files:[]}),[v,F]=await Promise.allSettled([L,y]);if(C.signal.aborted)return;let R=null;if(v.status==="fulfilled"?(l(v.value),g.current=!0):R=v.reason instanceof Error?v.reason.message:String(v.reason),F.status==="fulfilled"){const M=F.value.files,P=u?.trim().toLowerCase(),T=P?M.filter(N=>N.name.toLowerCase().includes(P)||N.path.toLowerCase().includes(P)):M;i(T)}b(R),E&&p(!1)},[a,c,u]);return s.useEffect(()=>(m.current&&clearTimeout(m.current),m.current=setTimeout(()=>{j()},300),()=>{m.current&&clearTimeout(m.current)}),[j]),s.useEffect(()=>(j(),()=>{f.current&&f.current.abort()}),[]),{documents:x,projectFiles:h,loading:o,error:k,refresh:j}}function ke(n,c){const[u,a]=s.useState([]),[x,l]=s.useState(!0),[h,i]=s.useState(null),o=s.useRef(null),p=s.useRef(!1),k=c?.showHidden??!1,b=s.useCallback(async f=>{o.current&&o.current.abort();const g=new AbortController;o.current=g;const m=!p.current;m&&l(!0),i(null);try{const j=await G(n,{showHidden:f?.showHidden??k});if(g.signal.aborted)return;a(j.files),p.current=!0}catch(j){if(g.signal.aborted)return;i(j instanceof Error?j.message:String(j))}finally{!g.signal.aborted&&m&&l(!1)}},[n,k]);return s.useEffect(()=>(p.current=!1,b({showHidden:k}),()=>{o.current&&o.current.abort()}),[b,k]),{files:u,loading:x,error:h,refresh:b}}const be=768;function Y(n){return n?new Date(n).toLocaleString():""}function ge(n){return n<1024?`${n} B`:n<1024*1024?`${(n/1024).toFixed(n>=10*1024?0:1)} KB`:`${(n/(1024*1024)).toFixed(1)} MB`}function ve(n,c=200){return n.length<=c?n:`${n.substring(0,c)}…`}function Ne({document:n,renderMarkdown:c,onToggleMarkdown:u}){const[a,x]=s.useState(!1),l=ve(n.content),h=n.content.length>200;return e.jsxs("div",{className:"document-card",children:[e.jsxs("div",{className:"document-card-header",children:[e.jsxs("div",{className:"document-card-key",children:[e.jsx(z,{size:14}),e.jsx("span",{className:"document-card-key-text",children:n.key}),e.jsxs("span",{className:"document-card-revision-badge",children:["v",n.revision]})]}),e.jsx("div",{className:"document-card-actions",children:e.jsx("button",{className:"btn btn-sm document-card-expand-btn",onClick:()=>x(i=>!i),title:a?"Collapse":"Expand","aria-label":a?"Collapse content":"Expand content",children:a?e.jsx(xe,{size:14}):e.jsx(X,{size:14})})})]}),e.jsxs("div",{className:"document-card-meta",children:[e.jsx("span",{className:"document-card-author",children:n.author}),e.jsx("span",{className:"document-card-separator",children:"·"}),e.jsx("span",{className:"document-card-date",children:Y(n.updatedAt)})]}),e.jsxs("div",{className:`document-card-content${a?" document-card-content--expanded":""}`,children:[a?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"document-card-content-header",children:e.jsx("button",{className:"btn btn-sm document-mode-toggle",onClick:u,"aria-label":c?"Switch to plain text":"Switch to markdown","aria-pressed":c,title:c?"Switch to plain text":"Switch to markdown",children:c?"Markdown":"Plain"})}),c?e.jsx("div",{className:"document-card-content-markdown",children:e.jsx("div",{className:"markdown-body",children:e.jsx(W,{remarkPlugins:[V],children:n.content})})}):e.jsx("pre",{className:"document-card-content-text",children:n.content})]}):e.jsx("p",{className:"document-card-preview",children:l}),h&&!a&&e.jsx("p",{className:"document-card-preview-truncated",children:"…"})]})]})}function Se({taskId:n,taskTitle:c,documents:u,onOpenTask:a,renderMarkdownStates:x,onToggleMarkdown:l}){const[h,i]=s.useState(!1);return e.jsxs("div",{className:"documents-group",children:[e.jsxs("div",{className:"documents-group-header",children:[e.jsxs("button",{className:"documents-group-toggle-btn",onClick:()=>i(o=>!o),"aria-expanded":h,"aria-label":`${h?"Collapse":"Expand"} documents for task ${n}`,children:[e.jsx("span",{className:"documents-group-toggle","aria-hidden":"true",children:h?e.jsx(X,{size:16}):e.jsx(je,{size:16})}),e.jsx("span",{className:"documents-group-task-id",children:n}),e.jsx("span",{className:"documents-group-task-title",children:c||"Untitled"})]}),e.jsxs("span",{className:"documents-group-count",children:[u.length," doc",u.length!==1?"s":""]}),e.jsx("button",{className:"documents-group-task-link",onClick:()=>a(n),"aria-label":`Open task ${n}: ${c||"Untitled"}`,children:"Open task"})]}),h&&e.jsx("div",{className:"documents-group-content",children:u.map(o=>e.jsx(Ne,{document:o,renderMarkdown:x.get(o.id)??!1,onToggleMarkdown:()=>l(o.id)},o.id))})]})}function ye({projectId:n,addToast:c,onOpenDetail:u}){const[a,x]=s.useState("project"),[l,h]=s.useState(""),[i,o]=s.useState(null),[p,k]=s.useState(!1),[b,f]=s.useState(null),[g,m]=s.useState(!1),[j,C]=s.useState(null),[E,L]=s.useState(!1),y=s.useRef(0),v=s.useRef(!1),[F,R]=s.useState(!1),[M,P]=s.useState(new Map),T=a==="tasks"?l.trim():"",{documents:N,loading:D,error:_,refresh:B}=we({projectId:n,searchQuery:T||void 0,includeProjectFiles:!1}),{files:S,loading:$,error:J,refresh:O}=ke(n,{showHidden:p});s.useEffect(()=>{const t=()=>{L(window.innerWidth<=be)};return t(),window.addEventListener("resize",t),()=>{window.removeEventListener("resize",t)}},[]),s.useEffect(()=>{v.current=!1,x("project"),o(null),k(!1),f(null),C(null),m(!1),R(!1),P(new Map)},[n]),s.useEffect(()=>{v.current||D||$||(S.length>0?x("project"):N.length>0&&x("tasks"),v.current=!0)},[N.length,D,S.length,$]);const H=s.useMemo(()=>{const t=new Map;for(const r of N){const d=t.get(r.taskId)||[];t.set(r.taskId,[...d,r])}return Array.from(t.entries()).map(([r,d])=>{const w=[...d].sort((re,ce)=>ce.updatedAt.localeCompare(re.updatedAt));return{taskId:r,taskTitle:w[0]?.taskTitle,documents:w,latestUpdated:w[0]?.updatedAt??""}}).sort((r,d)=>d.latestUpdated.localeCompare(r.latestUpdated))},[N]),A=s.useMemo(()=>{const t=l.trim().toLowerCase();return t?S.filter(r=>{const d=r.path.toLowerCase(),w=r.name.toLowerCase();return d.includes(t)||w.includes(t)}):S},[S,l]);s.useEffect(()=>{if(!i)return;S.some(r=>r.path===i.path)||(o(null),f(null),C(null),m(!1))},[S,i]);const Z=s.useCallback(t=>{h(t.target.value)},[]),I=s.useCallback(()=>{h("")},[]),Q=s.useCallback(t=>{x(t)},[]),ee=s.useCallback(async t=>{try{const r=await le(t,n);u(r)}catch{c(`Failed to open task ${t}`,"error")}},[n,u,c]),se=s.useCallback(async t=>{o(t),m(!0),C(null),f(null);const r=y.current+1;y.current=r;try{const d=await ie("project",t.path,n);if(y.current!==r)return;f(d.content)}catch(d){if(y.current!==r)return;const w=d instanceof Error?d.message:`Failed to open ${t.path}`;C(w),c(w,"error")}finally{y.current===r&&m(!1)}},[n,c]),te=s.useCallback(()=>{o(null),f(null),C(null),m(!1)},[]),ne=s.useCallback(t=>{P(r=>{const d=new Map(r),w=d.get(t)??!1;return d.set(t,!w),d})},[]),U=a==="project"?J:_,ae=s.useCallback(async()=>{if(a==="project"){await O();return}await B()},[a,O,B]),q=a==="project"?A.length:N.length,K=a==="project"?"Search project markdown files…":"Search task documents…";return e.jsxs("div",{className:"documents-view",children:[e.jsxs("div",{className:"documents-view-header",children:[e.jsxs("div",{className:"documents-view-title-row",children:[e.jsxs("h2",{className:"documents-view-title",children:[e.jsx(z,{size:20}),"Documents"]}),e.jsxs("span",{className:"documents-view-count",children:[q," result",q!==1?"s":""]})]}),e.jsxs("div",{className:"documents-tab-bar",role:"tablist","aria-label":"Documents sections",children:[e.jsxs("button",{className:`btn documents-tab${a==="project"?" active":""}`,role:"tab","aria-selected":a==="project","aria-label":"Show project markdown files",onClick:()=>Q("project"),children:["Project Files",e.jsx("span",{className:"documents-tab-count",children:S.length})]}),e.jsxs("button",{className:`btn documents-tab${a==="tasks"?" active":""}`,role:"tab","aria-selected":a==="tasks","aria-label":"Show task documents",onClick:()=>Q("tasks"),children:["Task Documents",e.jsx("span",{className:"documents-tab-count",children:H.length})]})]}),a==="project"&&e.jsxs("button",{className:"btn btn-sm documents-hidden-toggle",onClick:()=>k(t=>!t),"aria-pressed":p,"aria-label":p?"Hide hidden project files":"Show hidden project files",title:p?"Hide hidden files":"Show hidden files",children:[p?e.jsx(de,{size:14}):e.jsx(ue,{size:14}),p?"Hide Hidden":"Show Hidden"]}),e.jsxs("div",{className:"documents-search",children:[e.jsx(me,{size:16,className:"documents-search-icon"}),e.jsx("input",{type:"text",className:"documents-search-input",placeholder:K,value:l,onChange:Z,"aria-label":K}),l&&e.jsx("button",{className:"documents-search-clear",onClick:I,"aria-label":"Clear search",children:e.jsx(he,{size:16})})]})]}),e.jsx("div",{className:"documents-view-content",children:U?e.jsxs("div",{className:"documents-view-error",children:[e.jsxs("p",{children:["Failed to load ",a==="project"?"project files":"task documents",": ",U]}),e.jsxs("button",{className:"btn btn-primary",onClick:()=>void ae(),"aria-label":"Retry loading documents",children:[e.jsx(pe,{size:16}),"Retry"]})]}):a==="project"?$&&S.length===0?e.jsx("div",{className:"documents-view-loading",children:e.jsx("p",{children:"Loading project markdown files…"})}):A.length===0?e.jsx("div",{className:"documents-view-empty",children:l.trim()?e.jsxs("p",{children:['No project markdown files match "',l.trim(),'".']}):e.jsxs(e.Fragment,{children:[e.jsx(z,{size:48,className:"documents-view-empty-icon"}),e.jsx("p",{children:"No Markdown files found in this project."})]})}):e.jsxs("div",{className:`documents-project-layout${E?" documents-project-layout--mobile":""}`,children:[(!E||!i)&&e.jsx("aside",{className:"documents-view-sidebar","aria-label":"Project markdown files",children:e.jsx("ul",{className:"markdown-file-list",children:A.map(t=>{const r=i?.path===t.path;return e.jsx("li",{className:"markdown-file-list-item",children:e.jsxs("button",{className:`markdown-file-item${r?" markdown-file-item--selected":""}`,onClick:()=>void se(t),"aria-label":`Open ${t.path}`,"aria-current":r?"true":void 0,children:[e.jsx("span",{className:"markdown-file-item-name",children:t.name}),e.jsx("span",{className:"markdown-file-item-path",children:t.path}),e.jsxs("span",{className:"markdown-file-item-meta",children:[ge(t.size)," · ",Y(t.mtime)]})]})},t.path)})})}),(!E||i)&&e.jsxs("section",{className:"documents-view-main","aria-label":"Project file content preview",children:[E&&i&&e.jsxs("button",{className:"btn btn-sm documents-mobile-back",onClick:te,"aria-label":"Back to project files list",children:[e.jsx(fe,{size:14}),"Back to files"]}),i?e.jsxs("div",{className:"documents-content-viewer",children:[e.jsxs("div",{className:"documents-content-header",children:[e.jsx("p",{className:"documents-file-path-header",children:i.path}),e.jsx("button",{className:"btn btn-sm document-mode-toggle",onClick:()=>R(t=>!t),"aria-label":F?"Switch to plain text":"Switch to markdown","aria-pressed":F,title:F?"Switch to plain text":"Switch to markdown",children:F?"Markdown":"Plain"})]}),g?e.jsx("p",{className:"documents-content-state",children:"Loading file content…"}):j?e.jsx("p",{className:"documents-content-state documents-content-state--error",children:j}):F?e.jsx("div",{className:"documents-content-markdown",children:e.jsx("div",{className:"markdown-body",children:e.jsx(W,{remarkPlugins:[V],children:b??""})})}):e.jsx("pre",{className:"document-card-content-text documents-content-viewer-text",children:b??""})]}):e.jsx("div",{className:"documents-view-empty",children:e.jsx("p",{children:"Select a Markdown file to view its content."})})]})]}):D&&N.length===0?e.jsx("div",{className:"documents-view-loading",children:e.jsx("p",{children:"Loading task documents…"})}):H.length===0?e.jsx("div",{className:"documents-view-empty",children:l.trim()?e.jsxs("p",{children:['No task documents match "',l.trim(),'".']}):e.jsxs(e.Fragment,{children:[e.jsx(z,{size:48,className:"documents-view-empty-icon"}),e.jsx("p",{children:"No task documents yet."}),e.jsx("p",{className:"documents-view-empty-hint",children:"Documents are created in task detail tabs."})]})}):e.jsx("div",{className:"documents-task-list-wrap",children:e.jsx("div",{className:"documents-view-list",children:H.map(({taskId:t,taskTitle:r,documents:d})=>e.jsx(Se,{taskId:t,taskTitle:r,documents:d,onOpenTask:ee,renderMarkdownStates:M,onToggleMarkdown:ne},t))})})})]})}export{ye as DocumentsView};
1
+ import{r as s,j as e}from"./vendor-react-K0fH_qHe.js";import{Y as oe,$ as G,a0 as le,a1 as ie,F as z,a2 as de,a3 as ue,S as me,X as he,R as pe,a4 as fe,a5 as W,a6 as V,K as X,D as je,a7 as xe}from"./index-DQKtk17v.js";import"./vendor-xterm-DzcZoU0P.js";function we(n){const{projectId:c,searchQuery:u,includeProjectFiles:a=!0}=n??{},[x,l]=s.useState([]),[h,i]=s.useState([]),[o,p]=s.useState(!0),[k,b]=s.useState(null),f=s.useRef(null),g=s.useRef(!1),m=s.useRef(null),j=s.useCallback(async()=>{f.current&&f.current.abort();const C=new AbortController;f.current=C;const E=!g.current;E&&p(!0),b(null);const L=oe(u?{q:u}:void 0,c),y=a?G(c):Promise.resolve({files:[]}),[v,F]=await Promise.allSettled([L,y]);if(C.signal.aborted)return;let R=null;if(v.status==="fulfilled"?(l(v.value),g.current=!0):R=v.reason instanceof Error?v.reason.message:String(v.reason),F.status==="fulfilled"){const M=F.value.files,P=u?.trim().toLowerCase(),T=P?M.filter(N=>N.name.toLowerCase().includes(P)||N.path.toLowerCase().includes(P)):M;i(T)}b(R),E&&p(!1)},[a,c,u]);return s.useEffect(()=>(m.current&&clearTimeout(m.current),m.current=setTimeout(()=>{j()},300),()=>{m.current&&clearTimeout(m.current)}),[j]),s.useEffect(()=>(j(),()=>{f.current&&f.current.abort()}),[]),{documents:x,projectFiles:h,loading:o,error:k,refresh:j}}function ke(n,c){const[u,a]=s.useState([]),[x,l]=s.useState(!0),[h,i]=s.useState(null),o=s.useRef(null),p=s.useRef(!1),k=c?.showHidden??!1,b=s.useCallback(async f=>{o.current&&o.current.abort();const g=new AbortController;o.current=g;const m=!p.current;m&&l(!0),i(null);try{const j=await G(n,{showHidden:f?.showHidden??k});if(g.signal.aborted)return;a(j.files),p.current=!0}catch(j){if(g.signal.aborted)return;i(j instanceof Error?j.message:String(j))}finally{!g.signal.aborted&&m&&l(!1)}},[n,k]);return s.useEffect(()=>(p.current=!1,b({showHidden:k}),()=>{o.current&&o.current.abort()}),[b,k]),{files:u,loading:x,error:h,refresh:b}}const be=768;function Y(n){return n?new Date(n).toLocaleString():""}function ge(n){return n<1024?`${n} B`:n<1024*1024?`${(n/1024).toFixed(n>=10*1024?0:1)} KB`:`${(n/(1024*1024)).toFixed(1)} MB`}function ve(n,c=200){return n.length<=c?n:`${n.substring(0,c)}…`}function Ne({document:n,renderMarkdown:c,onToggleMarkdown:u}){const[a,x]=s.useState(!1),l=ve(n.content),h=n.content.length>200;return e.jsxs("div",{className:"document-card",children:[e.jsxs("div",{className:"document-card-header",children:[e.jsxs("div",{className:"document-card-key",children:[e.jsx(z,{size:14}),e.jsx("span",{className:"document-card-key-text",children:n.key}),e.jsxs("span",{className:"document-card-revision-badge",children:["v",n.revision]})]}),e.jsx("div",{className:"document-card-actions",children:e.jsx("button",{className:"btn btn-sm document-card-expand-btn",onClick:()=>x(i=>!i),title:a?"Collapse":"Expand","aria-label":a?"Collapse content":"Expand content",children:a?e.jsx(xe,{size:14}):e.jsx(X,{size:14})})})]}),e.jsxs("div",{className:"document-card-meta",children:[e.jsx("span",{className:"document-card-author",children:n.author}),e.jsx("span",{className:"document-card-separator",children:"·"}),e.jsx("span",{className:"document-card-date",children:Y(n.updatedAt)})]}),e.jsxs("div",{className:`document-card-content${a?" document-card-content--expanded":""}`,children:[a?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"document-card-content-header",children:e.jsx("button",{className:"btn btn-sm document-mode-toggle",onClick:u,"aria-label":c?"Switch to plain text":"Switch to markdown","aria-pressed":c,title:c?"Switch to plain text":"Switch to markdown",children:c?"Markdown":"Plain"})}),c?e.jsx("div",{className:"document-card-content-markdown",children:e.jsx("div",{className:"markdown-body",children:e.jsx(W,{remarkPlugins:[V],children:n.content})})}):e.jsx("pre",{className:"document-card-content-text",children:n.content})]}):e.jsx("p",{className:"document-card-preview",children:l}),h&&!a&&e.jsx("p",{className:"document-card-preview-truncated",children:"…"})]})]})}function Se({taskId:n,taskTitle:c,documents:u,onOpenTask:a,renderMarkdownStates:x,onToggleMarkdown:l}){const[h,i]=s.useState(!1);return e.jsxs("div",{className:"documents-group",children:[e.jsxs("div",{className:"documents-group-header",children:[e.jsxs("button",{className:"documents-group-toggle-btn",onClick:()=>i(o=>!o),"aria-expanded":h,"aria-label":`${h?"Collapse":"Expand"} documents for task ${n}`,children:[e.jsx("span",{className:"documents-group-toggle","aria-hidden":"true",children:h?e.jsx(X,{size:16}):e.jsx(je,{size:16})}),e.jsx("span",{className:"documents-group-task-id",children:n}),e.jsx("span",{className:"documents-group-task-title",children:c||"Untitled"})]}),e.jsxs("span",{className:"documents-group-count",children:[u.length," doc",u.length!==1?"s":""]}),e.jsx("button",{className:"documents-group-task-link",onClick:()=>a(n),"aria-label":`Open task ${n}: ${c||"Untitled"}`,children:"Open task"})]}),h&&e.jsx("div",{className:"documents-group-content",children:u.map(o=>e.jsx(Ne,{document:o,renderMarkdown:x.get(o.id)??!1,onToggleMarkdown:()=>l(o.id)},o.id))})]})}function ye({projectId:n,addToast:c,onOpenDetail:u}){const[a,x]=s.useState("project"),[l,h]=s.useState(""),[i,o]=s.useState(null),[p,k]=s.useState(!1),[b,f]=s.useState(null),[g,m]=s.useState(!1),[j,C]=s.useState(null),[E,L]=s.useState(!1),y=s.useRef(0),v=s.useRef(!1),[F,R]=s.useState(!1),[M,P]=s.useState(new Map),T=a==="tasks"?l.trim():"",{documents:N,loading:D,error:_,refresh:B}=we({projectId:n,searchQuery:T||void 0,includeProjectFiles:!1}),{files:S,loading:$,error:J,refresh:O}=ke(n,{showHidden:p});s.useEffect(()=>{const t=()=>{L(window.innerWidth<=be)};return t(),window.addEventListener("resize",t),()=>{window.removeEventListener("resize",t)}},[]),s.useEffect(()=>{v.current=!1,x("project"),o(null),k(!1),f(null),C(null),m(!1),R(!1),P(new Map)},[n]),s.useEffect(()=>{v.current||D||$||(S.length>0?x("project"):N.length>0&&x("tasks"),v.current=!0)},[N.length,D,S.length,$]);const H=s.useMemo(()=>{const t=new Map;for(const r of N){const d=t.get(r.taskId)||[];t.set(r.taskId,[...d,r])}return Array.from(t.entries()).map(([r,d])=>{const w=[...d].sort((re,ce)=>ce.updatedAt.localeCompare(re.updatedAt));return{taskId:r,taskTitle:w[0]?.taskTitle,documents:w,latestUpdated:w[0]?.updatedAt??""}}).sort((r,d)=>d.latestUpdated.localeCompare(r.latestUpdated))},[N]),A=s.useMemo(()=>{const t=l.trim().toLowerCase();return t?S.filter(r=>{const d=r.path.toLowerCase(),w=r.name.toLowerCase();return d.includes(t)||w.includes(t)}):S},[S,l]);s.useEffect(()=>{if(!i)return;S.some(r=>r.path===i.path)||(o(null),f(null),C(null),m(!1))},[S,i]);const Z=s.useCallback(t=>{h(t.target.value)},[]),I=s.useCallback(()=>{h("")},[]),Q=s.useCallback(t=>{x(t)},[]),ee=s.useCallback(async t=>{try{const r=await le(t,n);u(r)}catch{c(`Failed to open task ${t}`,"error")}},[n,u,c]),se=s.useCallback(async t=>{o(t),m(!0),C(null),f(null);const r=y.current+1;y.current=r;try{const d=await ie("project",t.path,n);if(y.current!==r)return;f(d.content)}catch(d){if(y.current!==r)return;const w=d instanceof Error?d.message:`Failed to open ${t.path}`;C(w),c(w,"error")}finally{y.current===r&&m(!1)}},[n,c]),te=s.useCallback(()=>{o(null),f(null),C(null),m(!1)},[]),ne=s.useCallback(t=>{P(r=>{const d=new Map(r),w=d.get(t)??!1;return d.set(t,!w),d})},[]),U=a==="project"?J:_,ae=s.useCallback(async()=>{if(a==="project"){await O();return}await B()},[a,O,B]),q=a==="project"?A.length:N.length,K=a==="project"?"Search project markdown files…":"Search task documents…";return e.jsxs("div",{className:"documents-view",children:[e.jsxs("div",{className:"documents-view-header",children:[e.jsxs("div",{className:"documents-view-title-row",children:[e.jsxs("h2",{className:"documents-view-title",children:[e.jsx(z,{size:20}),"Documents"]}),e.jsxs("span",{className:"documents-view-count",children:[q," result",q!==1?"s":""]})]}),e.jsxs("div",{className:"documents-tab-bar",role:"tablist","aria-label":"Documents sections",children:[e.jsxs("button",{className:`btn documents-tab${a==="project"?" active":""}`,role:"tab","aria-selected":a==="project","aria-label":"Show project markdown files",onClick:()=>Q("project"),children:["Project Files",e.jsx("span",{className:"documents-tab-count",children:S.length})]}),e.jsxs("button",{className:`btn documents-tab${a==="tasks"?" active":""}`,role:"tab","aria-selected":a==="tasks","aria-label":"Show task documents",onClick:()=>Q("tasks"),children:["Task Documents",e.jsx("span",{className:"documents-tab-count",children:H.length})]})]}),a==="project"&&e.jsxs("button",{className:"btn btn-sm documents-hidden-toggle",onClick:()=>k(t=>!t),"aria-pressed":p,"aria-label":p?"Hide hidden project files":"Show hidden project files",title:p?"Hide hidden files":"Show hidden files",children:[p?e.jsx(de,{size:14}):e.jsx(ue,{size:14}),p?"Hide Hidden":"Show Hidden"]}),e.jsxs("div",{className:"documents-search",children:[e.jsx(me,{size:16,className:"documents-search-icon"}),e.jsx("input",{type:"text",className:"documents-search-input",placeholder:K,value:l,onChange:Z,"aria-label":K}),l&&e.jsx("button",{className:"documents-search-clear",onClick:I,"aria-label":"Clear search",children:e.jsx(he,{size:16})})]})]}),e.jsx("div",{className:"documents-view-content",children:U?e.jsxs("div",{className:"documents-view-error",children:[e.jsxs("p",{children:["Failed to load ",a==="project"?"project files":"task documents",": ",U]}),e.jsxs("button",{className:"btn btn-primary",onClick:()=>void ae(),"aria-label":"Retry loading documents",children:[e.jsx(pe,{size:16}),"Retry"]})]}):a==="project"?$&&S.length===0?e.jsx("div",{className:"documents-view-loading",children:e.jsx("p",{children:"Loading project markdown files…"})}):A.length===0?e.jsx("div",{className:"documents-view-empty",children:l.trim()?e.jsxs("p",{children:['No project markdown files match "',l.trim(),'".']}):e.jsxs(e.Fragment,{children:[e.jsx(z,{size:48,className:"documents-view-empty-icon"}),e.jsx("p",{children:"No Markdown files found in this project."})]})}):e.jsxs("div",{className:`documents-project-layout${E?" documents-project-layout--mobile":""}`,children:[(!E||!i)&&e.jsx("aside",{className:"documents-view-sidebar","aria-label":"Project markdown files",children:e.jsx("ul",{className:"markdown-file-list",children:A.map(t=>{const r=i?.path===t.path;return e.jsx("li",{className:"markdown-file-list-item",children:e.jsxs("button",{className:`markdown-file-item${r?" markdown-file-item--selected":""}`,onClick:()=>void se(t),"aria-label":`Open ${t.path}`,"aria-current":r?"true":void 0,children:[e.jsx("span",{className:"markdown-file-item-name",children:t.name}),e.jsx("span",{className:"markdown-file-item-path",children:t.path}),e.jsxs("span",{className:"markdown-file-item-meta",children:[ge(t.size)," · ",Y(t.mtime)]})]})},t.path)})})}),(!E||i)&&e.jsxs("section",{className:"documents-view-main","aria-label":"Project file content preview",children:[E&&i&&e.jsxs("button",{className:"btn btn-sm documents-mobile-back",onClick:te,"aria-label":"Back to project files list",children:[e.jsx(fe,{size:14}),"Back to files"]}),i?e.jsxs("div",{className:"documents-content-viewer",children:[e.jsxs("div",{className:"documents-content-header",children:[e.jsx("p",{className:"documents-file-path-header",children:i.path}),e.jsx("button",{className:"btn btn-sm document-mode-toggle",onClick:()=>R(t=>!t),"aria-label":F?"Switch to plain text":"Switch to markdown","aria-pressed":F,title:F?"Switch to plain text":"Switch to markdown",children:F?"Markdown":"Plain"})]}),g?e.jsx("p",{className:"documents-content-state",children:"Loading file content…"}):j?e.jsx("p",{className:"documents-content-state documents-content-state--error",children:j}):F?e.jsx("div",{className:"documents-content-markdown",children:e.jsx("div",{className:"markdown-body",children:e.jsx(W,{remarkPlugins:[V],children:b??""})})}):e.jsx("pre",{className:"document-card-content-text documents-content-viewer-text",children:b??""})]}):e.jsx("div",{className:"documents-view-empty",children:e.jsx("p",{children:"Select a Markdown file to view its content."})})]})]}):D&&N.length===0?e.jsx("div",{className:"documents-view-loading",children:e.jsx("p",{children:"Loading task documents…"})}):H.length===0?e.jsx("div",{className:"documents-view-empty",children:l.trim()?e.jsxs("p",{children:['No task documents match "',l.trim(),'".']}):e.jsxs(e.Fragment,{children:[e.jsx(z,{size:48,className:"documents-view-empty-icon"}),e.jsx("p",{children:"No task documents yet."}),e.jsx("p",{className:"documents-view-empty-hint",children:"Documents are created in task detail tabs."})]})}):e.jsx("div",{className:"documents-task-list-wrap",children:e.jsx("div",{className:"documents-view-list",children:H.map(({taskId:t,taskTitle:r,documents:d})=>e.jsx(Se,{taskId:t,taskTitle:r,documents:d,onOpenTask:ee,renderMarkdownStates:M,onToggleMarkdown:ne},t))})})})]})}export{ye as DocumentsView};
@@ -1,4 +1,4 @@
1
- import{r as c,j as s}from"./vendor-react-K0fH_qHe.js";import{c as U,a8 as Q,a9 as V,aa as W,ab as X,ac as J,ad as x,X as T,R as j,C as q,ae as F,af as G,ag as _,ah as K,w as B,ai as Z,aj as ss,ak as P}from"./index-rNf7s96d.js";import"./vendor-xterm-DzcZoU0P.js";/**
1
+ import{r as c,j as s}from"./vendor-react-K0fH_qHe.js";import{c as U,a8 as Q,a9 as V,aa as W,ab as X,ac as J,ad as x,X as T,R as j,C as q,ae as F,af as G,ag as K,w as B,ah as Z,ai as ss,aj as P}from"./index-DQKtk17v.js";import{U as _}from"./users-CG2_rCdk.js";import"./vendor-xterm-DzcZoU0P.js";/**
2
2
  * @license lucide-react v1.7.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -8,4 +8,4 @@ import{r as c,j as s}from"./vendor-react-K0fH_qHe.js";import{c as U,a8 as Q,a9 a
8
8
  *
9
9
  * This source code is licensed under the ISC license.
10
10
  * See the LICENSE file in the root directory of this source tree.
11
- */const is=[["path",{d:"M3 3v16a2 2 0 0 0 2 2h16",key:"c24i48"}],["path",{d:"m19 9-5 5-4-4-3 3",key:"2osh9i"}]],as=U("chart-line",is),A=["architecture","quality","workflow","performance","reliability","security","ux","testability","documentation","dependency","features","competitive_analysis","research","trends","other"],O={quality:"Quality",performance:"Performance",architecture:"Architecture",security:"Security",reliability:"Reliability",ux:"User Experience",testability:"Testability",documentation:"Documentation",dependency:"Dependencies",workflow:"Workflow",other:"Other",features:"Features",competitive_analysis:"Competitive Analysis",research:"Research",trends:"Trends"};function ns(h){const[l,b]=c.useState(()=>A.map(t=>({category:t,label:O[t]??t,items:[],isLoading:!1,error:null}))),[k,S]=c.useState(!0),[N,v]=c.useState(null),[u,w]=c.useState(null),[M,C]=c.useState(!1),[I,p]=c.useState(null),[R,f]=c.useState(new Map),[z,y]=c.useState(new Map),m=c.useCallback(async()=>{S(!0),v(null);try{const t=await Q({status:void 0,limit:1e3},h),a=new Map;for(const i of A)a.set(i,[]);for(const i of t.insights)if(i.status!=="dismissed"){const r=a.get(i.category)??[];a.set(i.category,[...r,i])}b(A.map(i=>({category:i,label:O[i]??i,items:a.get(i)??[],isLoading:!1,error:null})));const e=await V(h);e.runs.length>0&&w(e.runs[0])}catch(t){const a=t instanceof Error?t.message:"Failed to fetch insights";v(a)}finally{S(!1)}},[h]),o=c.useCallback(async()=>{C(!0),p(null);try{const t=await W("manual",void 0,h);w(t),t.status==="completed"?await m():t.status==="failed"&&t.error&&p(t.error)}catch(t){const a=t instanceof Error?t.message:"Failed to generate insights";throw p(a),t}finally{C(!1)}},[h,m]),g=c.useCallback(async t=>{f(a=>{const e=new Map(a);return e.set(t,{running:!0,error:null}),e});try{await X(t,h),b(a=>a.map(e=>({...e,items:e.items.filter(i=>i.id!==t)}))),f(a=>{const e=new Map(a);return e.set(t,{running:!1,error:null}),e})}catch(a){const e=a instanceof Error?a.message:"Failed to dismiss insight";throw f(i=>{const r=new Map(i);return r.set(t,{running:!1,error:e}),r}),a}},[h]),d=c.useCallback(async t=>{y(a=>{const e=new Map(a);return e.set(t,{running:!0,error:null}),e});try{const a=await J(t,h);return y(e=>{const i=new Map(e);return i.set(t,{running:!1,error:null}),i}),{title:a.suggestedTitle,description:a.suggestedDescription}}catch(a){const e=a instanceof Error?a.message:"Failed to create task";throw y(i=>{const r=new Map(i);return r.set(t,{running:!1,error:e}),r}),a}},[h]),E=c.useMemo(()=>l.reduce((t,a)=>t+a.items.length,0),[l]),D=c.useMemo(()=>0,[l]);return c.useMemo(()=>{m()},[]),{sections:l,loading:k,error:N,latestRun:u,isRunInFlight:M,runError:I,refresh:m,runInsights:o,dismiss:g,createTask:d,dismissStates:R,createTaskStates:z,totalCount:E,dismissedCount:D}}const rs={architecture:ts,quality:q,workflow:P,performance:G,reliability:j,security:F,ux:_,testability:ss,documentation:Z,dependency:B,features:K,competitive_analysis:_,research:as,trends:G,other:x};function hs({projectId:h,addToast:l,onClose:b,onCreateTask:k}){const{sections:S,loading:N,error:v,latestRun:u,isRunInFlight:w,runError:M,refresh:C,runInsights:I,dismiss:p,createTask:R,dismissStates:f,createTaskStates:z,totalCount:y}=ns(h),[m,o]=c.useState(null),[g,d]=c.useState("info");c.useEffect(()=>{if(m){const e=setTimeout(()=>o(null),5e3);return()=>clearTimeout(e)}},[m]);const E=c.useCallback(async()=>{try{o("Generating insights..."),d("info"),await I(),o("Insight generation started"),d("success"),l("Insight generation started","success")}catch(e){const i=e instanceof Error?e.message:"Failed to start generation";o(i),d("error"),l(i,"error")}},[I,l]),D=c.useCallback(async(e,i)=>{try{o(`Dismissing "${i}"...`),d("info"),await p(e),o(`Dismissed "${i}"`),d("success"),l(`Insight dismissed: ${i}`,"success")}catch(r){const n=r instanceof Error?r.message:"Failed to dismiss insight";o(n),d("error"),l(n,"error")}},[p,l]),t=c.useCallback(async(e,i)=>{try{o(`Creating task from "${i}"...`),d("info");const r=await R(e);r&&k&&k(r.title,r.description),o(`Task created from "${i}"`),d("success"),l(`Task created: ${r?.title??i}`,"success")}catch(r){const n=r instanceof Error?r.message:"Failed to create task";o(n),d("error"),l(n,"error")}},[R,k,l]),a=e=>{const i=rs[e.category]??x,r=e.items.some(n=>f.get(n.id)?.running||z.get(n.id)?.running)??!1;return s.jsxs("section",{className:"insights-section","data-testid":`insights-section-${e.category}`,children:[s.jsx("div",{className:"insights-section-header",children:s.jsxs("div",{className:"insights-section-title",children:[s.jsx(i,{size:18,className:"insights-section-icon"}),s.jsx("h3",{children:e.label}),s.jsx("span",{className:"insights-section-count",children:e.items.length})]})}),s.jsx("div",{className:"insights-section-content",children:e.items.length===0?s.jsx("div",{className:"insights-empty-section","data-testid":`insights-empty-${e.category}`,children:s.jsx("p",{children:"No insights in this category"})}):s.jsx("ul",{className:"insights-list",children:e.items.map(n=>{const Y=f.get(n.id),H=z.get(n.id),L=Y?.running??!1,$=H?.running??!1;return s.jsxs("li",{className:"insight-item","data-insight-id":n.id,children:[s.jsxs("div",{className:"insight-item-header",children:[s.jsx("h4",{className:"insight-item-title",children:n.title}),s.jsxs("div",{className:"insight-item-actions",children:[s.jsx("button",{className:"btn btn-sm btn-icon",onClick:()=>void t(n.id,n.title),disabled:$||r,title:"Create task from this insight","aria-label":"Create task from this insight","data-testid":`create-task-${n.id}`,children:$?s.jsx(j,{size:14,className:"spin"}):s.jsx(B,{size:14})}),s.jsx("button",{className:"btn btn-sm btn-icon",onClick:()=>void D(n.id,n.title),disabled:L||r,title:"Dismiss this insight","aria-label":"Dismiss this insight","data-testid":`dismiss-${n.id}`,children:L?s.jsx(j,{size:14,className:"spin"}):s.jsx(T,{size:14})})]})]}),n.content&&s.jsx("p",{className:"insight-item-content",children:n.content}),s.jsxs("div",{className:"insight-item-meta",children:[s.jsx("span",{className:`insight-item-status insight-item-status--${n.status}`,children:n.status}),n.createdAt&&s.jsxs("span",{className:"insight-item-date",children:[s.jsx(P,{size:12}),new Date(n.createdAt).toLocaleDateString()]})]})]},n.id)})})})]},e.category)};return s.jsxs("div",{className:"insights-view","data-testid":"insights-view",children:[s.jsxs("div",{className:"insights-view-header",children:[s.jsxs("div",{className:"insights-view-title",children:[s.jsxs("h2",{children:[s.jsx(x,{size:20}),"Insights"]}),s.jsxs("span",{className:"insights-view-count",children:[y," total"]})]}),s.jsxs("div",{className:"insights-view-actions",children:[b&&s.jsx("button",{className:"btn btn-icon insights-view-close",onClick:b,"aria-label":"Close insights view",children:s.jsx(T,{size:16})}),s.jsxs("button",{className:"btn btn-sm",onClick:()=>void C(),disabled:N,"aria-label":"Refresh insights","data-testid":"refresh-insights",children:[s.jsx(j,{size:14,className:N?"spin":""}),"Refresh"]}),s.jsx("button",{className:"btn btn-primary btn-sm",onClick:()=>void E(),disabled:w,"aria-label":"Generate new insights","data-testid":"run-insights",children:w?s.jsxs(s.Fragment,{children:[s.jsx(j,{size:14,className:"spin"}),"Generating..."]}):s.jsxs(s.Fragment,{children:[s.jsx(x,{size:14}),"Generate Insights"]})})]})]}),s.jsx("div",{className:"insights-status-region","aria-live":"polite","data-testid":"insights-status",children:m&&s.jsxs("div",{className:`insights-status-message insights-status-message--${g}`,role:g==="error"?"alert":void 0,children:[g==="success"&&s.jsx(q,{size:16}),g==="error"&&s.jsx(F,{size:16}),g==="info"&&s.jsx(x,{size:16}),s.jsx("span",{children:m})]})}),M&&s.jsxs("div",{className:"insights-error-callout",role:"alert","data-testid":"run-error",children:[s.jsx(F,{size:16}),s.jsx("span",{children:M})]}),u&&s.jsx("div",{className:"insights-run-info","data-testid":"latest-run",children:s.jsxs("span",{className:"insights-run-status",children:["Latest run: ",u.status,u.status==="completed"&&s.jsxs(s.Fragment,{children:[" — ",u.insightsCreated," created, ",u.insightsUpdated," updated"]}),u.status==="failed"&&u.error&&s.jsxs(s.Fragment,{children:[" — ",u.error]})]})}),N?s.jsxs("div",{className:"insights-loading","data-testid":"insights-loading",children:[s.jsx(j,{size:24,className:"spin"}),s.jsx("p",{children:"Loading insights..."})]}):v?s.jsxs("div",{className:"insights-error","data-testid":"insights-error",children:[s.jsx(F,{size:24}),s.jsx("p",{children:v}),s.jsx("button",{className:"btn btn-sm",onClick:()=>void C(),children:"Retry"})]}):y===0?s.jsxs("div",{className:"insights-empty","data-testid":"insights-empty",children:[s.jsx(x,{size:48}),s.jsx("h3",{children:"No insights yet"}),s.jsx("p",{children:"Generate insights to get AI-powered recommendations for your project."}),s.jsxs("button",{className:"btn btn-primary",onClick:()=>void E(),children:[s.jsx(x,{size:14}),"Generate First Insights"]})]}):s.jsx("div",{className:"insights-sections",children:S.map(a)})]})}export{hs as InsightsView};
11
+ */const is=[["path",{d:"M3 3v16a2 2 0 0 0 2 2h16",key:"c24i48"}],["path",{d:"m19 9-5 5-4-4-3 3",key:"2osh9i"}]],as=U("chart-line",is),A=["architecture","quality","workflow","performance","reliability","security","ux","testability","documentation","dependency","features","competitive_analysis","research","trends","other"],O={quality:"Quality",performance:"Performance",architecture:"Architecture",security:"Security",reliability:"Reliability",ux:"User Experience",testability:"Testability",documentation:"Documentation",dependency:"Dependencies",workflow:"Workflow",other:"Other",features:"Features",competitive_analysis:"Competitive Analysis",research:"Research",trends:"Trends"};function ns(h){const[l,b]=c.useState(()=>A.map(t=>({category:t,label:O[t]??t,items:[],isLoading:!1,error:null}))),[k,S]=c.useState(!0),[N,v]=c.useState(null),[u,w]=c.useState(null),[M,C]=c.useState(!1),[I,p]=c.useState(null),[R,f]=c.useState(new Map),[z,y]=c.useState(new Map),m=c.useCallback(async()=>{S(!0),v(null);try{const t=await Q({status:void 0,limit:1e3},h),a=new Map;for(const i of A)a.set(i,[]);for(const i of t.insights)if(i.status!=="dismissed"){const r=a.get(i.category)??[];a.set(i.category,[...r,i])}b(A.map(i=>({category:i,label:O[i]??i,items:a.get(i)??[],isLoading:!1,error:null})));const e=await V(h);e.runs.length>0&&w(e.runs[0])}catch(t){const a=t instanceof Error?t.message:"Failed to fetch insights";v(a)}finally{S(!1)}},[h]),o=c.useCallback(async()=>{C(!0),p(null);try{const t=await W("manual",void 0,h);w(t),t.status==="completed"?await m():t.status==="failed"&&t.error&&p(t.error)}catch(t){const a=t instanceof Error?t.message:"Failed to generate insights";throw p(a),t}finally{C(!1)}},[h,m]),g=c.useCallback(async t=>{f(a=>{const e=new Map(a);return e.set(t,{running:!0,error:null}),e});try{await X(t,h),b(a=>a.map(e=>({...e,items:e.items.filter(i=>i.id!==t)}))),f(a=>{const e=new Map(a);return e.set(t,{running:!1,error:null}),e})}catch(a){const e=a instanceof Error?a.message:"Failed to dismiss insight";throw f(i=>{const r=new Map(i);return r.set(t,{running:!1,error:e}),r}),a}},[h]),d=c.useCallback(async t=>{y(a=>{const e=new Map(a);return e.set(t,{running:!0,error:null}),e});try{const a=await J(t,h);return y(e=>{const i=new Map(e);return i.set(t,{running:!1,error:null}),i}),{title:a.suggestedTitle,description:a.suggestedDescription}}catch(a){const e=a instanceof Error?a.message:"Failed to create task";throw y(i=>{const r=new Map(i);return r.set(t,{running:!1,error:e}),r}),a}},[h]),E=c.useMemo(()=>l.reduce((t,a)=>t+a.items.length,0),[l]),D=c.useMemo(()=>0,[l]);return c.useMemo(()=>{m()},[]),{sections:l,loading:k,error:N,latestRun:u,isRunInFlight:M,runError:I,refresh:m,runInsights:o,dismiss:g,createTask:d,dismissStates:R,createTaskStates:z,totalCount:E,dismissedCount:D}}const rs={architecture:ts,quality:q,workflow:P,performance:G,reliability:j,security:F,ux:_,testability:ss,documentation:Z,dependency:B,features:K,competitive_analysis:_,research:as,trends:G,other:x};function ds({projectId:h,addToast:l,onClose:b,onCreateTask:k}){const{sections:S,loading:N,error:v,latestRun:u,isRunInFlight:w,runError:M,refresh:C,runInsights:I,dismiss:p,createTask:R,dismissStates:f,createTaskStates:z,totalCount:y}=ns(h),[m,o]=c.useState(null),[g,d]=c.useState("info");c.useEffect(()=>{if(m){const e=setTimeout(()=>o(null),5e3);return()=>clearTimeout(e)}},[m]);const E=c.useCallback(async()=>{try{o("Generating insights..."),d("info"),await I(),o("Insight generation started"),d("success"),l("Insight generation started","success")}catch(e){const i=e instanceof Error?e.message:"Failed to start generation";o(i),d("error"),l(i,"error")}},[I,l]),D=c.useCallback(async(e,i)=>{try{o(`Dismissing "${i}"...`),d("info"),await p(e),o(`Dismissed "${i}"`),d("success"),l(`Insight dismissed: ${i}`,"success")}catch(r){const n=r instanceof Error?r.message:"Failed to dismiss insight";o(n),d("error"),l(n,"error")}},[p,l]),t=c.useCallback(async(e,i)=>{try{o(`Creating task from "${i}"...`),d("info");const r=await R(e);r&&k&&k(r.title,r.description),o(`Task created from "${i}"`),d("success"),l(`Task created: ${r?.title??i}`,"success")}catch(r){const n=r instanceof Error?r.message:"Failed to create task";o(n),d("error"),l(n,"error")}},[R,k,l]),a=e=>{const i=rs[e.category]??x,r=e.items.some(n=>f.get(n.id)?.running||z.get(n.id)?.running)??!1;return s.jsxs("section",{className:"insights-section","data-testid":`insights-section-${e.category}`,children:[s.jsx("div",{className:"insights-section-header",children:s.jsxs("div",{className:"insights-section-title",children:[s.jsx(i,{size:18,className:"insights-section-icon"}),s.jsx("h3",{children:e.label}),s.jsx("span",{className:"insights-section-count",children:e.items.length})]})}),s.jsx("div",{className:"insights-section-content",children:e.items.length===0?s.jsx("div",{className:"insights-empty-section","data-testid":`insights-empty-${e.category}`,children:s.jsx("p",{children:"No insights in this category"})}):s.jsx("ul",{className:"insights-list",children:e.items.map(n=>{const Y=f.get(n.id),H=z.get(n.id),L=Y?.running??!1,$=H?.running??!1;return s.jsxs("li",{className:"insight-item","data-insight-id":n.id,children:[s.jsxs("div",{className:"insight-item-header",children:[s.jsx("h4",{className:"insight-item-title",children:n.title}),s.jsxs("div",{className:"insight-item-actions",children:[s.jsx("button",{className:"btn btn-sm btn-icon",onClick:()=>void t(n.id,n.title),disabled:$||r,title:"Create task from this insight","aria-label":"Create task from this insight","data-testid":`create-task-${n.id}`,children:$?s.jsx(j,{size:14,className:"spin"}):s.jsx(B,{size:14})}),s.jsx("button",{className:"btn btn-sm btn-icon",onClick:()=>void D(n.id,n.title),disabled:L||r,title:"Dismiss this insight","aria-label":"Dismiss this insight","data-testid":`dismiss-${n.id}`,children:L?s.jsx(j,{size:14,className:"spin"}):s.jsx(T,{size:14})})]})]}),n.content&&s.jsx("p",{className:"insight-item-content",children:n.content}),s.jsxs("div",{className:"insight-item-meta",children:[s.jsx("span",{className:`insight-item-status insight-item-status--${n.status}`,children:n.status}),n.createdAt&&s.jsxs("span",{className:"insight-item-date",children:[s.jsx(P,{size:12}),new Date(n.createdAt).toLocaleDateString()]})]})]},n.id)})})})]},e.category)};return s.jsxs("div",{className:"insights-view","data-testid":"insights-view",children:[s.jsxs("div",{className:"insights-view-header",children:[s.jsxs("div",{className:"insights-view-title",children:[s.jsxs("h2",{children:[s.jsx(x,{size:20}),"Insights"]}),s.jsxs("span",{className:"insights-view-count",children:[y," total"]})]}),s.jsxs("div",{className:"insights-view-actions",children:[b&&s.jsx("button",{className:"btn btn-icon insights-view-close",onClick:b,"aria-label":"Close insights view",children:s.jsx(T,{size:16})}),s.jsxs("button",{className:"btn btn-sm",onClick:()=>void C(),disabled:N,"aria-label":"Refresh insights","data-testid":"refresh-insights",children:[s.jsx(j,{size:14,className:N?"spin":""}),"Refresh"]}),s.jsx("button",{className:"btn btn-primary btn-sm",onClick:()=>void E(),disabled:w,"aria-label":"Generate new insights","data-testid":"run-insights",children:w?s.jsxs(s.Fragment,{children:[s.jsx(j,{size:14,className:"spin"}),"Generating..."]}):s.jsxs(s.Fragment,{children:[s.jsx(x,{size:14}),"Generate Insights"]})})]})]}),s.jsx("div",{className:"insights-status-region","aria-live":"polite","data-testid":"insights-status",children:m&&s.jsxs("div",{className:`insights-status-message insights-status-message--${g}`,role:g==="error"?"alert":void 0,children:[g==="success"&&s.jsx(q,{size:16}),g==="error"&&s.jsx(F,{size:16}),g==="info"&&s.jsx(x,{size:16}),s.jsx("span",{children:m})]})}),M&&s.jsxs("div",{className:"insights-error-callout",role:"alert","data-testid":"run-error",children:[s.jsx(F,{size:16}),s.jsx("span",{children:M})]}),u&&s.jsx("div",{className:"insights-run-info","data-testid":"latest-run",children:s.jsxs("span",{className:"insights-run-status",children:["Latest run: ",u.status,u.status==="completed"&&s.jsxs(s.Fragment,{children:[" — ",u.insightsCreated," created, ",u.insightsUpdated," updated"]}),u.status==="failed"&&u.error&&s.jsxs(s.Fragment,{children:[" — ",u.error]})]})}),N?s.jsxs("div",{className:"insights-loading","data-testid":"insights-loading",children:[s.jsx(j,{size:24,className:"spin"}),s.jsx("p",{children:"Loading insights..."})]}):v?s.jsxs("div",{className:"insights-error","data-testid":"insights-error",children:[s.jsx(F,{size:24}),s.jsx("p",{children:v}),s.jsx("button",{className:"btn btn-sm",onClick:()=>void C(),children:"Retry"})]}):y===0?s.jsxs("div",{className:"insights-empty","data-testid":"insights-empty",children:[s.jsx(x,{size:48}),s.jsx("h3",{children:"No insights yet"}),s.jsx("p",{children:"Generate insights to get AI-powered recommendations for your project."}),s.jsxs("button",{className:"btn btn-primary",onClick:()=>void E(),children:[s.jsx(x,{size:14}),"Generate First Insights"]})]}):s.jsx("div",{className:"insights-sections",children:S.map(a)})]})}export{ds as InsightsView};
@@ -0,0 +1,2 @@
1
+ import{r as a,j as e}from"./vendor-react-K0fH_qHe.js";import{u as Ae}from"./SettingsModal-CNdVTVqD.js";import{b8 as Se,b9 as Ne,ba as Fe,o as De,bb as ze,bc as Ie,bd as Le,be as Ce,bf as ke,bg as Re,bh as qe,bi as Ee,bj as Pe,n as Te,bk as We,L as A,bl as Me}from"./index-DQKtk17v.js";import"./vendor-xterm-DzcZoU0P.js";const U=".fusion/memory/MEMORY.md",_e=5e4,Oe="0 3 * * *",Ue="0 4 * * *";function me(l){return{memoryEnabled:l.memoryEnabled!==!1,memoryAutoSummarizeEnabled:l.memoryAutoSummarizeEnabled??!1,memoryAutoSummarizeThresholdChars:l.memoryAutoSummarizeThresholdChars??_e,memoryAutoSummarizeSchedule:l.memoryAutoSummarizeSchedule??Oe,memoryDreamsEnabled:l.memoryDreamsEnabled??!1,memoryDreamsSchedule:l.memoryDreamsSchedule??Ue}}function we(l,t){return l.some(c=>c.path===t)?t:l.find(c=>c.path===U)?.path??l[0]?.path??U}function Qe(l={}){const{projectId:t}=l,[c,p]=a.useState(""),[F,k]=a.useState(!0),[S,N]=a.useState(!1),[y,g]=a.useState(!1),[i,b]=a.useState(null),[Q,J]=a.useState(!0),[X,D]=a.useState(!1),[f,q]=a.useState(()=>me({})),[E,ee]=a.useState(!0),[ce,H]=a.useState(!1),[o,j]=a.useState([]),[se,z]=a.useState(!0),[m,C]=a.useState(U),[P,u]=a.useState(""),[d,te]=a.useState(!1),[$,x]=a.useState(!1),[ae,Y]=a.useState(!1),[ne,B]=a.useState(!1),[G,T]=a.useState(null),[M,W]=a.useState(!0),[oe,I]=a.useState(!1),[de,V]=a.useState(!1),[ie,Z]=a.useState(null),{status:K,loading:v,refresh:re}=Ae({projectId:t}),L=a.useCallback(n=>{u(n),x(!0)},[]),_=a.useCallback(async n=>{te(!0);try{const{content:s}=await Se(n,t);C(n),u(s),x(!1)}finally{te(!1)}},[t]),w=a.useCallback(async()=>{z(!0);try{const{files:n}=await Ne(t);if(j(n),n.length===0){C(U),u(""),x(!1);return}const s=we(n,m);s!==m&&await _(s)}finally{z(!1)}},[t,m,_]);a.useEffect(()=>{let n=!1;async function s(){try{const r=await Pe(t);n||(p(r.content),k(!1))}catch{n||(p(""),k(!1))}}return s(),()=>{n=!0}},[t]),a.useEffect(()=>{let n=!1;async function s(){try{const r=await ke(t);n||(b(r.content),D(r.exists),J(!1))}catch{n||(b(null),D(!1),J(!1))}}return s(),()=>{n=!0}},[t]),a.useEffect(()=>{let n=!1;async function s(){ee(!0);try{const r=await Te(t);n||q(me(r))}catch{n||q(me({}))}finally{n||ee(!1)}}return s(),()=>{n=!0}},[t]),a.useEffect(()=>{let n=!1;async function s(){z(!0);try{const{files:r}=await Ne(t);if(n)return;if(j(r),r.length===0){C(U),u(""),x(!1);return}const h=we(r,m),{content:ve}=await Se(h,t);if(n)return;C(h),u(ve),x(!1)}catch{n||(j([]),C(U),u(""),x(!1))}finally{n||z(!1)}}return s(),()=>{n=!0}},[t,m]),a.useEffect(()=>{let n=!1;async function s(){try{const r=await Ce(t);n||(T(r),W(!1))}catch{n||(T(null),W(!1))}}return s(),()=>{n=!0}},[t]),a.useEffect(()=>{let n=!1;async function s(){try{const r=await We(t);n||Z(r)}catch{n||Z(null)}}return s(),()=>{n=!0}},[t]);const le=a.useCallback(n=>{p(n),N(!0)},[]),he=a.useCallback(async()=>{if(S){g(!0);try{await Fe(c,t),N(!1)}finally{g(!1)}}},[c,S,t]),ue=a.useCallback(async n=>{H(!0);try{const s=await De(n,t);q(me(s))}finally{H(!1)}},[t]),ye=a.useCallback(async n=>{await _(n)},[_]),ge=a.useCallback(async()=>{if($){Y(!0);try{await ze(m,P,t),x(!1),await w()}finally{Y(!1)}}},[P,$,m,t,w]),be=a.useCallback(async()=>{V(!0);try{const n=await Ie(t);return await re(),n}finally{V(!1)}},[t,re]),xe=a.useCallback(async n=>Le(n,t),[t]),O=a.useCallback(async()=>{try{const n=await Ce(t);T(n)}catch{T(null)}},[t]),R=a.useCallback(async()=>{try{const n=await ke(t);b(n.content),D(n.exists)}catch{b(null),D(!1)}},[t]),pe=a.useCallback(async n=>{await Re(n,t),await R()},[t,R]),fe=a.useCallback(async()=>{B(!0);try{const n=await qe(t);return await Promise.all([R(),O()]),{success:n.success,summary:n.summary}}finally{B(!1)}},[t,R,O]),je=a.useCallback(async n=>{I(!0);try{const s=n?await Ee(n,t):await Ee(t);if(n){const r=s.path??n;C(r),u(s.content),x(!1),await w();return}p(s.content),N(!0)}finally{I(!1)}},[t,w]);return{workingMemory:c,workingMemoryLoading:F,workingMemoryDirty:S,setWorkingMemory:le,saveWorkingMemory:he,savingWorkingMemory:y,insightsContent:i,insightsLoading:Q,insightsExists:X,refreshInsights:R,saveInsights:pe,memorySettings:f,settingsLoading:E,savingMemorySettings:ce,saveMemorySettings:ue,memoryFiles:o,memoryFilesLoading:se,selectedFilePath:m,selectedFileContent:P,selectedFileLoading:d,selectedFileDirty:$,setSelectedFileContent:L,selectFile:ye,saveSelectedFile:ge,savingSelectedFile:ae,reloadMemoryFiles:w,backendStatus:K,backendLoading:v,extractInsights:fe,extracting:ne,auditReport:G,auditLoading:M,refreshAudit:O,compactMemory:je,compacting:oe,installQmdAction:be,installingQmd:de,testRetrieval:xe,stats:ie}}const He={Patterns:"pattern",Principles:"principle",Conventions:"convention",Pitfalls:"pitfall",Context:"context"},$e={"long-term":"Long-term",daily:"Daily",dreams:"Dreams"},Ye={"long-term":"Curated durable decisions, conventions, constraints, and pitfalls promoted from dreams.",daily:"Raw daily observations, open loops, and running context for dream processing.",dreams:"Synthesized patterns and open loops promoted from daily memory."};function Be(l){if(!l)return[];const t=[],c=l.split(/(?=^## )/m);for(const p of c){const F=p.trim();if(!F)continue;const k=F.match(/^##\s+(.+?)(\n|$)/);if(k){const S=k[1].trim(),N=He[S]??S.toLowerCase(),y=F.slice(k[0].length).trim(),g=y.split(`
2
+ `).map(i=>i.replace(/^-\s+/,"").trim()).filter(i=>i.length>0&&(i.startsWith("- ")||i.startsWith("* ")));(g.length>0||y.length>0)&&t.push({name:S,key:N,items:g.length>0?g:y.length>0?[y]:[],expanded:!0})}}return t}function Ge(l){if(!l)return null;const t=l.match(/##\s+Last\s+Updated:\s*(\d{4}-\d{2}-\d{2})/i);return t?t[1]:null}function Ve(l){return l.reduce((t,c)=>t+c.items.length,0)}function Ze(l){switch(l){case"file":return"File (.fusion/memory/)";case"readonly":return"Read-Only";case"qmd":return"QMD (Quantized Memory Distillation)";default:return l}}function Ke(l){switch(l){case"healthy":return"Healthy";case"warning":return"Warning";case"issues":return"Issues Found"}}function ts({projectId:l,addToast:t}){const[c,p]=a.useState("working"),[F,k]=a.useState(new Set),[S,N]=a.useState(!1),[y,g]=a.useState(null),[i,b]=a.useState({memoryEnabled:!0,memoryAutoSummarizeEnabled:!1,memoryAutoSummarizeThresholdChars:5e4,memoryAutoSummarizeSchedule:"0 3 * * *",memoryDreamsEnabled:!1,memoryDreamsSchedule:"0 4 * * *"}),[Q,J]=a.useState(""),[X,D]=a.useState(!1),[f,q]=a.useState(null),{insightsContent:E,insightsLoading:ee,insightsExists:ce,saveInsights:H,memorySettings:o,settingsLoading:j,saveMemorySettings:se,savingMemorySettings:z,backendStatus:m,backendLoading:C,extractInsights:P,extracting:u,auditReport:d,auditLoading:te,refreshAudit:$,compactMemory:x,compacting:ae,installQmdAction:Y,installingQmd:ne,testRetrieval:B,memoryFiles:G,memoryFilesLoading:T,selectedFilePath:M,selectedFileContent:W,selectedFileLoading:oe,selectedFileDirty:I,setSelectedFileContent:de,selectFile:V,saveSelectedFile:ie,savingSelectedFile:Z}=Qe({projectId:l});a.useEffect(()=>{b(o)},[o]);const K=a.useMemo(()=>i.memoryEnabled!==o.memoryEnabled||i.memoryAutoSummarizeEnabled!==o.memoryAutoSummarizeEnabled||i.memoryAutoSummarizeThresholdChars!==o.memoryAutoSummarizeThresholdChars||i.memoryAutoSummarizeSchedule!==o.memoryAutoSummarizeSchedule||i.memoryDreamsEnabled!==o.memoryDreamsEnabled||i.memoryDreamsSchedule!==o.memoryDreamsSchedule,[i,o]),v=a.useMemo(()=>G.find(s=>s.path===M),[G,M]),re=v?Ye[v.layer]:"Edits the selected memory file.",L=a.useMemo(()=>Be(E),[E]),_=a.useMemo(()=>Ve(L),[L]),w=a.useMemo(()=>Ge(E),[E]),le=a.useCallback(s=>{k(r=>{const h=new Set(r);return h.has(s)?h.delete(s):h.add(s),h})},[]),he=a.useCallback(async s=>{try{await V(s)}catch{t("Failed to load memory file","error")}},[V,t]),ue=a.useCallback(async()=>{try{await ie(),t("Memory saved","success")}catch{t("Failed to save memory","error")}},[ie,t]),ye=a.useCallback(async()=>{if(!K)return;const s={};i.memoryEnabled!==o.memoryEnabled&&(s.memoryEnabled=i.memoryEnabled),i.memoryAutoSummarizeEnabled!==o.memoryAutoSummarizeEnabled&&(s.memoryAutoSummarizeEnabled=i.memoryAutoSummarizeEnabled),i.memoryAutoSummarizeThresholdChars!==o.memoryAutoSummarizeThresholdChars&&(s.memoryAutoSummarizeThresholdChars=i.memoryAutoSummarizeThresholdChars),i.memoryAutoSummarizeSchedule!==o.memoryAutoSummarizeSchedule&&(s.memoryAutoSummarizeSchedule=i.memoryAutoSummarizeSchedule),i.memoryDreamsEnabled!==o.memoryDreamsEnabled&&(s.memoryDreamsEnabled=i.memoryDreamsEnabled),i.memoryDreamsSchedule!==o.memoryDreamsSchedule&&(s.memoryDreamsSchedule=i.memoryDreamsSchedule);try{await se(s),t("Memory settings saved","success")}catch{t("Failed to save memory settings","error")}},[K,i,o,se,t]),ge=a.useCallback(async()=>{try{const s=await Y();t(s.qmdAvailable?"qmd installed successfully":"qmd install finished, but qmd is still unavailable",s.qmdAvailable?"success":"info")}catch{t("Failed to install qmd","error")}},[Y,t]),be=a.useCallback(async()=>{D(!0),q(null);try{const s=await B(Q);q(s),t(s.qmdAvailable?"Memory retrieval test complete":"qmd is not installed; local fallback was used",s.qmdAvailable?"success":"info")}catch{t("Failed to test memory retrieval","error")}finally{D(!1)}},[Q,B,t]),xe=a.useCallback(async()=>{try{await x(M),t("Memory file compacted","success")}catch{t("Failed to compact memory","error")}},[x,M,t]),O=a.useCallback(async()=>{try{const s=await P();t(s.summary,"success")}catch(s){t(s instanceof Error?s.message:"Failed to extract insights","error")}},[P,t]),R=a.useCallback(async()=>{if(y!==null)try{await H(y),N(!1),g(null),t("Insights saved","success")}catch{t("Failed to save insights","error")}},[y,H,t]),pe=a.useCallback(()=>{g(E??""),N(!0)},[E]),fe=a.useCallback(()=>{N(!1),g(null)},[]),je=!C&&m!==null,n=m?.capabilities?.writable??!1;return e.jsxs("div",{className:"memory-view",children:[e.jsx("div",{className:"memory-view-header",children:e.jsxs("div",{children:[e.jsx("h2",{children:"Memory"}),e.jsx("p",{className:"memory-view-description",children:"Working memory, long-term insights, and engine status"})]})}),e.jsxs("div",{className:"memory-view-tabs",role:"tablist",children:[e.jsx("button",{type:"button",role:"tab","aria-selected":c==="working",className:`memory-view-tab${c==="working"?" memory-view-tab--active":""}`,onClick:()=>p("working"),"data-testid":"memory-tab-working",children:"Working Memory"}),e.jsx("button",{type:"button",role:"tab","aria-selected":c==="insights",className:`memory-view-tab${c==="insights"?" memory-view-tab--active":""}`,onClick:()=>p("insights"),"data-testid":"memory-tab-insights",children:"Insights"}),e.jsx("button",{type:"button",role:"tab","aria-selected":c==="engines",className:`memory-view-tab${c==="engines"?" memory-view-tab--active":""}`,onClick:()=>p("engines"),"data-testid":"memory-tab-engines",children:"Engines"})]}),e.jsxs("div",{className:"memory-view-content",children:[c==="working"&&e.jsxs("div",{className:"memory-working-tab",children:[je&&!n&&e.jsx("div",{className:"memory-readonly-banner",children:"This memory backend is read-only. Changes cannot be saved."}),T||oe?e.jsxs("div",{className:"memory-empty-state",children:[e.jsx(A,{size:20,className:"animate-spin"}),e.jsx("span",{children:"Loading memory file…"})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"memory-editor-section",children:[e.jsxs("div",{className:"form-group",children:[e.jsx("label",{htmlFor:"memoryViewFilePath",children:"Memory File"}),e.jsx("select",{id:"memoryViewFilePath",className:"select",value:M,onChange:s=>{he(s.target.value)},disabled:I,children:G.map(s=>e.jsxs("option",{value:s.path,children:[s.label," - ",s.path]},s.path))}),e.jsx("small",{children:I?"Save or discard the current edits before switching files.":"Choose any project memory file to view or edit."})]}),v&&e.jsxs("div",{className:"memory-file-summary",children:[e.jsx("span",{children:$e[v.layer]}),e.jsx("strong",{children:v.path}),e.jsxs("small",{children:[v.size.toLocaleString()," bytes · updated ",new Date(v.updatedAt).toLocaleString()]})]}),e.jsxs("div",{className:"form-group",children:[e.jsx("label",{children:v?.label||"Memory Editor"}),e.jsx("small",{children:re}),e.jsx("div",{className:"memory-editor-container",children:e.jsx(Me,{content:W,onChange:de,readOnly:!n,filePath:M})})]})]}),e.jsxs("div",{className:"memory-action-bar",children:[e.jsxs("span",{className:"memory-char-count",children:[W.length," characters"]}),e.jsx("div",{className:"memory-flex-spacer"}),n&&W.length>0&&e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:xe,disabled:ae||I,children:ae?e.jsxs(e.Fragment,{children:[e.jsx(A,{size:14,className:"animate-spin"}),"Compacting…"]}):"Compact Selected File"}),I&&n&&e.jsx("button",{type:"button",className:"btn btn-primary btn-sm",onClick:ue,disabled:Z,children:Z?e.jsxs(e.Fragment,{children:[e.jsx(A,{size:14,className:"animate-spin"}),"Saving…"]}):"Save"})]}),e.jsxs("div",{className:"memory-config-section",children:[e.jsxs("div",{className:"memory-settings-group",children:[e.jsxs("div",{className:"form-group",children:[e.jsxs("label",{htmlFor:"memoryDreamsEnabled",className:"checkbox-label",children:[e.jsx("input",{id:"memoryDreamsEnabled",type:"checkbox",checked:i.memoryDreamsEnabled,onChange:s=>{b(r=>({...r,memoryDreamsEnabled:s.target.checked}))},disabled:!i.memoryEnabled||j}),"Process dreams from daily memory"]}),e.jsx("small",{children:"Turns daily notes into DREAMS.md and promotes reusable lessons into MEMORY.md."})]}),i.memoryEnabled&&i.memoryDreamsEnabled&&e.jsxs("div",{className:"form-group",children:[e.jsx("label",{htmlFor:"memoryDreamsSchedule",children:"Dream Schedule"}),e.jsx("input",{id:"memoryDreamsSchedule",type:"text",className:"input",value:i.memoryDreamsSchedule,onChange:s=>{b(r=>({...r,memoryDreamsSchedule:s.target.value}))},placeholder:"0 4 * * *",disabled:j}),e.jsx("small",{children:"Cron expression for dream processing."})]})]}),e.jsxs("div",{className:"memory-settings-group",children:[e.jsxs("div",{className:"form-group",children:[e.jsxs("label",{htmlFor:"memoryAutoSummarizeEnabled",className:"checkbox-label",children:[e.jsx("input",{id:"memoryAutoSummarizeEnabled",type:"checkbox",checked:i.memoryAutoSummarizeEnabled,onChange:s=>{b(r=>({...r,memoryAutoSummarizeEnabled:s.target.checked}))},disabled:!i.memoryEnabled||j}),"Auto-Summarize Memory"]}),e.jsx("small",{children:"Automatically compact memory when it exceeds the threshold on a schedule"})]}),i.memoryEnabled&&i.memoryAutoSummarizeEnabled&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"form-group",children:[e.jsx("label",{htmlFor:"memoryAutoSummarizeThresholdChars",children:"Compaction Threshold (chars)"}),e.jsx("input",{id:"memoryAutoSummarizeThresholdChars",type:"number",className:"input",value:i.memoryAutoSummarizeThresholdChars,onChange:s=>{b(r=>({...r,memoryAutoSummarizeThresholdChars:parseInt(s.target.value,10)||5e4}))},min:1e3,disabled:j}),e.jsx("small",{children:"Memory will be compacted when it exceeds this character count"})]}),e.jsxs("div",{className:"form-group",children:[e.jsx("label",{htmlFor:"memoryAutoSummarizeSchedule",children:"Schedule (cron)"}),e.jsx("input",{id:"memoryAutoSummarizeSchedule",type:"text",className:"input",value:i.memoryAutoSummarizeSchedule,onChange:s=>{b(r=>({...r,memoryAutoSummarizeSchedule:s.target.value}))},placeholder:"0 3 * * *",disabled:j}),e.jsx("small",{children:"Cron expression for auto-summarize schedule (default: daily at 3 AM)"})]})]})]}),!i.memoryEnabled&&e.jsx("div",{className:"settings-empty-state memory-status-message",children:"Memory is currently disabled. Enable memory tools in Settings to edit these automations."}),K&&e.jsx("div",{className:"memory-action-bar",children:e.jsx("button",{type:"button",className:"btn btn-primary btn-sm",onClick:ye,disabled:z||j,children:z?e.jsxs(e.Fragment,{children:[e.jsx(A,{size:14,className:"animate-spin"}),"Saving…"]}):"Save Settings"})})]})]})]}),c==="insights"&&e.jsx("div",{className:"memory-insights-tab",children:ee?e.jsxs("div",{className:"memory-empty-state",children:[e.jsx(A,{size:20,className:"animate-spin"}),e.jsx("span",{children:"Loading insights…"})]}):S?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"memory-editor-container",children:e.jsx(Me,{content:y??"",onChange:g,readOnly:!1,filePath:".fusion/memory/INSIGHTS.md"})}),e.jsxs("div",{className:"memory-action-bar",children:[e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:fe,children:"Cancel"}),e.jsx("button",{type:"button",className:"btn btn-primary btn-sm",onClick:R,children:"Save Insights"})]})]}):!ce||L.length===0?e.jsxs("div",{className:"memory-empty-state",children:[e.jsx("p",{children:"No insights extracted yet."}),e.jsx("p",{children:'Insights are automatically extracted from working memory. Click "Extract Now" to trigger extraction manually.'}),e.jsx("button",{type:"button",className:"btn btn-primary btn-sm memory-empty-extract-button",onClick:O,disabled:u,children:u?e.jsxs(e.Fragment,{children:[e.jsx(A,{size:14,className:"animate-spin"}),"Extracting…"]}):"Extract Now"})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"memory-stats-row",children:[e.jsxs("div",{className:"memory-stat-card",children:[e.jsx("div",{className:"memory-stat-value",children:_}),e.jsx("div",{className:"memory-stat-label",children:"Total Insights"})]}),e.jsxs("div",{className:"memory-stat-card",children:[e.jsx("div",{className:"memory-stat-value",children:L.length}),e.jsx("div",{className:"memory-stat-label",children:"Categories"})]}),w&&e.jsxs("div",{className:"memory-stat-card",children:[e.jsx("div",{className:"memory-stat-value memory-stat-value--updated",children:w}),e.jsx("div",{className:"memory-stat-label",children:"Last Updated"})]})]}),e.jsxs("div",{className:"memory-action-bar",children:[e.jsx("button",{type:"button",className:"btn btn-primary btn-sm",onClick:O,disabled:u,children:u?e.jsxs(e.Fragment,{children:[e.jsx(A,{size:14,className:"animate-spin"}),"Extracting…"]}):"Extract Now"}),e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:pe,children:"Edit Raw"})]}),e.jsx("div",{className:"memory-categories-list",children:L.map(s=>{const r=!F.has(s.key);return e.jsxs("div",{className:"memory-category-section",children:[e.jsxs("div",{className:"memory-category-header",onClick:()=>le(s.key),role:"button",tabIndex:0,onKeyDown:h=>{(h.key==="Enter"||h.key===" ")&&(h.preventDefault(),le(s.key))},children:[e.jsx("h4",{children:s.name}),e.jsx("span",{className:"memory-category-count",children:s.items.length})]}),r&&e.jsx("div",{className:"memory-category-items",children:s.items.map((h,ve)=>e.jsx("div",{className:"memory-insight-item",children:h.replace(/^-\s+/,"").replace(/^\*\s+/,"")},ve))})]},s.key)})})]})}),c==="engines"&&e.jsx("div",{className:"memory-engines-tab",children:C||te?e.jsxs("div",{className:"memory-empty-state",children:[e.jsx(A,{size:20,className:"animate-spin"}),e.jsx("span",{children:"Loading engine status…"})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"memory-engine-card memory-qmd-card",children:[e.jsx("h3",{children:"QMD Integration"}),m?.qmdAvailable===!0?e.jsxs("div",{className:"memory-engine-status",children:[e.jsx("span",{className:"memory-health-badge memory-health-badge--healthy",children:"Installed"}),e.jsx("span",{className:"memory-char-count",children:"qmd is available on PATH."})]}):m?.qmdAvailable===!1?e.jsxs("div",{className:"settings-empty-state memory-status-message",children:[e.jsxs("span",{children:["qmd is not installed. Search will use local files. Install indexed retrieval: ",e.jsx("code",{children:m.qmdInstallCommand||"bun install -g @tobilu/qmd"})]}),e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:ge,disabled:ne,children:ne?"Installing…":"Install qmd"})]}):e.jsxs("div",{className:"memory-engine-status",children:[e.jsx("span",{className:"memory-health-badge",children:"Checking"}),e.jsx("span",{className:"memory-char-count",children:"Checking qmd availability…"})]}),e.jsxs("div",{className:"memory-capability-row",children:[m?.capabilities?.readable&&e.jsx("span",{className:"memory-capability-badge",children:"Readable"}),m?.capabilities?.writable&&e.jsx("span",{className:"memory-capability-badge",children:"Writable"}),m?.capabilities?.supportsAtomicWrite&&e.jsx("span",{className:"memory-capability-badge",children:"Atomic Writes"}),m?.capabilities?.persistent&&e.jsx("span",{className:"memory-capability-badge",children:"Persistent"})]})]}),e.jsxs("div",{className:"memory-engine-card memory-retrieval-card",children:[e.jsx("h3",{children:"Test Memory Search"}),e.jsxs("div",{className:"memory-retrieval-input-row",children:[e.jsx("input",{type:"text",className:"input",value:Q,onChange:s=>J(s.target.value),placeholder:"Search memory with qmd"}),e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:be,disabled:X,children:X?"Testing…":"Test Retrieval"})]}),e.jsx("small",{className:"settings-muted",children:"Runs the same qmd-backed memory_search path agents use."}),f&&e.jsxs("div",{className:"memory-test-result",children:[e.jsxs("strong",{children:[f.results.length," result",f.results.length===1?"":"s"," ",'for "',f.query,'"']}),e.jsxs("small",{children:["qmd ",f.qmdAvailable?"available":"missing"," · ",f.usedFallback?"local fallback used":"qmd path used"]}),f.results.length>0?e.jsx("ul",{children:f.results.map((s,r)=>e.jsxs("li",{children:[e.jsxs("span",{children:[s.path,":",s.lineStart]}),e.jsx("p",{children:s.snippet})]},`${s.path}-${s.lineStart}-${r}`))}):e.jsx("small",{children:"No matching memory found."})]})]}),e.jsxs("div",{className:"memory-engine-card",children:[e.jsx("h3",{children:"Current Backend"}),e.jsx("div",{className:"memory-engine-status",children:e.jsx("span",{className:"memory-emphasis-text",children:Ze(m?.currentBackend??"unknown")})}),e.jsxs("div",{className:"memory-capability-row",children:[m?.capabilities?.readable&&e.jsx("span",{className:"memory-capability-badge",children:"Readable"}),m?.capabilities?.writable&&e.jsx("span",{className:"memory-capability-badge",children:"Writable"}),m?.capabilities?.supportsAtomicWrite&&e.jsx("span",{className:"memory-capability-badge",children:"Atomic Writes"}),m?.capabilities?.persistent&&e.jsx("span",{className:"memory-capability-badge",children:"Persistent"})]})]}),d&&e.jsxs("div",{className:"memory-engine-card",children:[e.jsxs("div",{className:"memory-health-header",children:[e.jsx("h3",{children:"Health Status"}),e.jsx("span",{className:`memory-health-badge memory-health-badge--${d.health}`,children:Ke(d.health)})]}),e.jsxs("div",{className:"memory-health-grid",children:[e.jsxs("div",{children:[e.jsx("div",{className:"memory-health-label",children:"Working Memory"}),e.jsxs("div",{className:"memory-emphasis-text",children:[d.workingMemory.size," chars"]}),e.jsxs("div",{className:"memory-health-detail",children:[d.workingMemory.sectionCount," sections"]})]}),e.jsxs("div",{children:[e.jsx("div",{className:"memory-health-label",children:"Insights Memory"}),e.jsxs("div",{className:"memory-emphasis-text",children:[d.insightsMemory.size," chars"]}),e.jsxs("div",{className:"memory-health-detail",children:[d.insightsMemory.insightCount," insights"]})]})]}),e.jsxs("div",{className:"memory-health-section",children:[e.jsx("div",{className:"memory-health-label",children:"Last Extraction"}),e.jsx("div",{className:"memory-emphasis-text",children:d.extraction.success?e.jsx("span",{className:"memory-status-text memory-status-text--success",children:"Success"}):e.jsx("span",{className:"memory-status-text memory-status-text--error",children:"Failed"})}),e.jsx("div",{className:"memory-health-detail",children:d.extraction.summary||`${d.extraction.insightCount} insights extracted`})]}),e.jsxs("div",{className:"memory-health-section",children:[e.jsx("div",{className:"memory-health-label",children:"Pruning"}),e.jsx("div",{className:"memory-emphasis-text",children:d.pruning.applied?e.jsx("span",{className:"memory-status-text memory-status-text--warning",children:"Applied"}):e.jsx("span",{className:"memory-status-text memory-status-text--muted",children:"Not needed"})}),d.pruning.applied&&e.jsx("div",{className:"memory-health-detail",children:d.pruning.reason})]})]}),d&&d.checks.length>0&&e.jsxs("div",{className:"memory-engine-card",children:[e.jsx("h3",{children:"Audit Checks"}),e.jsx("div",{children:d.checks.map(s=>e.jsxs("div",{className:"memory-audit-check",children:[e.jsx("span",{className:s.passed?"memory-audit-check-passed":"memory-audit-check-failed",children:s.passed?"✓":"✗"}),e.jsxs("div",{className:"memory-audit-check-content",children:[e.jsx("div",{className:"memory-emphasis-text",children:s.name}),e.jsx("div",{className:"memory-health-detail",children:s.details})]})]},s.id))})]}),e.jsx("div",{className:"memory-action-bar",children:e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:()=>$(),children:"Run Audit"})}),e.jsxs("div",{className:"memory-settings-note",children:[e.jsx("span",{children:"Note: Change backend type in"}),e.jsx("button",{type:"button",className:"memory-settings-note-button",onClick:()=>{t("Open Settings → Memory to change backend type","info")},children:"Settings → Memory"})]})]})})]})]})}export{ts as MemoryView};
@@ -0,0 +1 @@
1
+ .memory-view{display:flex;flex-direction:column;height:100%;padding:var(--space-lg);overflow:hidden}.memory-view-header{display:flex;flex-direction:row;justify-content:space-between;align-items:flex-start;margin-bottom:var(--space-lg)}.memory-view-header h2{font-size:18px;color:var(--text);margin:0}.memory-view-description{color:var(--text-muted);font-size:13px;margin:var(--space-xs) 0 0 0}.memory-view-tabs{display:flex;flex-direction:row;gap:var(--space-xs);border-bottom:1px solid var(--border);margin-bottom:var(--space-lg)}.memory-view-tab{padding:var(--space-sm) var(--space-md);border-radius:var(--radius-sm) var(--radius-sm) 0 0;color:var(--text-muted);background:transparent;border:none;cursor:pointer;font-size:13px;transition:background var(--transition-fast),color var(--transition-fast)}.memory-view-tab:hover{background:var(--card-hover);color:var(--text)}.memory-view-tab:focus-visible{outline:none;box-shadow:var(--focus-ring)}.memory-view-tab--active{color:var(--text);border-bottom:2px solid var(--todo);font-weight:500}.memory-view-content{flex:1;overflow-y:auto}.memory-editor-container{border:1px solid var(--border);border-radius:var(--radius-md);overflow:hidden;display:flex;flex-direction:column;height:calc(100vh - var(--header-height) - 180px)}.memory-category-section{margin-bottom:var(--space-lg)}.memory-category-header{display:flex;flex-direction:row;justify-content:space-between;align-items:center;cursor:pointer;padding:var(--space-sm) 0;border-bottom:1px solid var(--border);transition:opacity var(--transition-fast)}.memory-category-header:hover{opacity:.8}.memory-category-header h4{font-size:14px;font-weight:500;margin:0;color:var(--text)}.memory-category-count{font-size:calc(var(--space-sm) + var(--space-xs) * .75);color:var(--text-muted);background:color-mix(in srgb,var(--text-muted) 15%,transparent);padding:2px 8px;border-radius:var(--radius-pill)}.memory-category-items{padding-top:var(--space-sm)}.memory-insight-item{padding:var(--space-xs) var(--space-sm);margin-bottom:var(--space-xs);border-left:3px solid var(--border);font-size:13px;color:var(--text);line-height:1.5}.memory-engine-card{background:var(--card);border:1px solid var(--border);border-radius:var(--radius-lg);padding:var(--space-xl);margin-bottom:var(--space-lg)}.memory-engine-card h3{font-size:14px;font-weight:500;margin:0 0 var(--space-md) 0;color:var(--text)}.memory-engine-status{display:flex;flex-direction:row;align-items:center;gap:var(--space-sm)}.memory-health-badge{display:inline-block;padding:2px 10px;border-radius:var(--radius-pill);font-size:12px}.memory-health-badge--healthy{background:color-mix(in srgb,var(--color-success) 15%,transparent);color:var(--color-success)}.memory-health-badge--warning{background:color-mix(in srgb,var(--color-warning) 15%,transparent);color:var(--color-warning)}.memory-health-badge--issues{background:color-mix(in srgb,var(--color-error) 15%,transparent);color:var(--color-error)}.memory-action-bar{display:flex;flex-direction:row;gap:var(--space-sm);margin-top:var(--space-md);align-items:center}.memory-empty-extract-button{margin-top:var(--space-md)}.memory-stat-value--updated{font-size:var(--space-lg)}.memory-capability-row{display:flex;gap:var(--space-xs);margin-top:var(--space-sm);flex-wrap:wrap}.memory-emphasis-text{font-weight:500}.memory-health-header{display:flex;justify-content:space-between;align-items:center;margin-bottom:var(--space-md)}.memory-health-grid{display:grid;grid-template-columns:1fr 1fr;gap:var(--space-md)}.memory-health-label{font-size:var(--space-md);color:var(--text-muted);text-transform:uppercase;margin-bottom:var(--space-xs)}.memory-health-detail{font-size:var(--space-md);color:var(--text-muted)}.memory-health-section{margin-top:var(--space-md);padding-top:var(--space-md);border-top:1px solid var(--border)}.memory-status-text--success{color:var(--color-success)}.memory-status-text--error{color:var(--color-error)}.memory-status-text--warning{color:var(--color-warning)}.memory-status-text--muted{color:var(--text-muted)}.memory-audit-check-content{flex:1}.memory-settings-note{margin-top:var(--space-lg);font-size:var(--space-md);color:var(--text-muted);display:flex;align-items:center;gap:var(--space-xs);flex-wrap:wrap}.memory-settings-note-button{background:none;border:none;color:inherit;cursor:pointer;font:inherit;padding:0;text-decoration:underline}.memory-settings-note-button:focus-visible{outline:none;border-radius:var(--radius-sm);box-shadow:var(--focus-ring-strong)}.memory-empty-state{color:var(--text-muted);padding:var(--space-2xl);text-align:center;display:flex;flex-direction:column;align-items:center;gap:var(--space-sm)}.memory-stats-row{display:flex;flex-direction:row;gap:var(--space-lg);margin-bottom:var(--space-lg)}.memory-stat-card{background:var(--card);border:1px solid var(--border);border-radius:var(--radius-md);padding:var(--space-md) var(--space-lg);flex:1}.memory-stat-value{font-size:24px;font-weight:600;color:var(--text);margin-bottom:var(--space-xs)}.memory-stat-label{font-size:12px;color:var(--text-muted);text-transform:uppercase;letter-spacing:.5px}.memory-audit-check{display:flex;flex-direction:row;padding:var(--space-sm) 0;border-bottom:1px solid var(--border);gap:var(--space-sm)}.memory-audit-check:last-child{border-bottom:none}.memory-audit-check-passed{color:var(--color-success);font-weight:600}.memory-audit-check-failed{color:var(--color-error);font-weight:600}.memory-capability-badge{font-size:11px;padding:2px 8px;border-radius:var(--radius-pill);background:color-mix(in srgb,var(--todo) 15%,transparent);color:var(--text-muted)}.memory-readonly-banner{background:color-mix(in srgb,var(--color-warning) 10%,transparent);border:1px solid color-mix(in srgb,var(--color-warning) 30%,transparent);border-radius:var(--radius-md);padding:var(--space-md);color:var(--color-warning);font-size:13px;margin-bottom:var(--space-md)}.memory-char-count{font-size:12px;color:var(--text-muted)}.memory-categories-list{margin-top:var(--space-lg)}.memory-config-section{margin-top:var(--space-lg);padding-top:var(--space-lg);border-top:1px solid var(--border);display:flex;flex-direction:column;gap:var(--space-md)}.memory-settings-group{border:1px solid var(--border);border-radius:var(--radius-md);background:var(--surface);padding:var(--space-sm) 0}.memory-flex-spacer{flex:1}.memory-qmd-card{border-style:solid}.memory-retrieval-card{display:flex;flex-direction:column;gap:var(--space-sm)}.memory-retrieval-input-row{display:flex;align-items:center;gap:var(--space-sm)}.memory-retrieval-input-row .input{flex:1}.memory-retrieval-card .memory-test-result{margin-top:var(--space-sm)}@media(max-width:768px){.memory-view{padding:var(--space-md)}.memory-view-header{flex-direction:column;gap:var(--space-sm)}.memory-editor-container{height:calc(100vh - var(--header-height) - var(--mobile-nav-height) - 200px)}.memory-stats-row{flex-wrap:wrap}.memory-stat-card{min-width:calc(50% - var(--space-sm))}.memory-view-tab{min-height:36px;padding:var(--space-sm)}.memory-engine-card{padding:var(--space-md)}.memory-retrieval-input-row{flex-direction:column;align-items:stretch}.memory-settings-group{padding:var(--space-xs) 0}.memory-health-grid{grid-template-columns:1fr}.memory-config-section{margin-top:var(--space-md);padding-top:var(--space-md)}}
@@ -1,4 +1,4 @@
1
- import{r as n,j as e}from"./vendor-react-K0fH_qHe.js";import{c as Y,al as xe,am as ge,an as pe,ao as je,ap as Z,aq as Q,A as T,ar as _e,I as Ne,K as be,as as ee,at as ve,au as Ce,X as B,av as ke,aw as Se,R as J,w as G,G as we}from"./index-rNf7s96d.js";import{U as se}from"./upload-CAlKC4qI.js";import"./vendor-xterm-DzcZoU0P.js";/**
1
+ import{r as n,j as e}from"./vendor-react-K0fH_qHe.js";import{c as Y,ak as xe,al as ge,am as pe,an as je,ao as Z,ap as Q,A as T,aq as _e,I as Ne,K as be,ar as ee,as as ve,at as Ce,X as B,au as ke,av as Se,R as J,w as G,G as we}from"./index-DQKtk17v.js";import{U as se}from"./upload-DNQF7XCK.js";import"./vendor-xterm-DzcZoU0P.js";/**
2
2
  * @license lucide-react v1.7.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.