@runfusion/fusion 0.32.0 → 0.33.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 (61) hide show
  1. package/dist/bin.js +23464 -10700
  2. package/dist/client/.vite/manifest.json +61 -61
  3. package/dist/client/assets/{AgentDetailView-CnFf_eBZ.js → AgentDetailView-BACu9GYE.js} +3 -3
  4. package/dist/client/assets/{AgentPermissionPolicyEditor-Cmkt9Z01.js → AgentPermissionPolicyEditor-tNNlcCDk.js} +2 -2
  5. package/dist/client/assets/AgentsView-CPpHwjn3.js +29 -0
  6. package/dist/client/assets/ChatView-CCAUA7HB.js +6 -0
  7. package/dist/client/assets/DevServerView-BlxSS8Uu.js +1 -0
  8. package/dist/client/assets/{DirectoryPicker-DctpCNrd.js → DirectoryPicker-ioTzF36r.js} +1 -1
  9. package/dist/client/assets/{DocumentsView-DORp5JjC.js → DocumentsView-CsDb8dPw.js} +1 -1
  10. package/dist/client/assets/{EvalsView-CYVJ1pbc.js → EvalsView-I0GhxVhm.js} +1 -1
  11. package/dist/client/assets/{ExperimentalAgentOnboardingModal-BULVNAiq.js → ExperimentalAgentOnboardingModal-Cr6g_jok.js} +2 -2
  12. package/dist/client/assets/{GoalsView-bmpZKOI_.js → GoalsView-DXJxe6D4.js} +1 -1
  13. package/dist/client/assets/{InsightsView-mmtem0RU.js → InsightsView-BaIhzpvX.js} +1 -1
  14. package/dist/client/assets/{MemoryView-HVpO1fCH.js → MemoryView-DlmcI0ca.js} +2 -2
  15. package/dist/client/assets/NodesView-vc4T0uCy.js +14 -0
  16. package/dist/client/assets/{PiExtensionsManager-Cyfas2VT.js → PiExtensionsManager-C0ljxGbt.js} +2 -2
  17. package/dist/client/assets/{PluginManager-C7QDE3Lk.js → PluginManager-D27abRF-.js} +1 -1
  18. package/dist/client/assets/ResearchView-BSpDz8YN.js +1 -0
  19. package/dist/client/assets/SecretsView-BmCemEu8.js +1 -0
  20. package/dist/client/assets/{SecretsView-BFhVwJu6.css → SecretsView-D5bHZ-wM.css} +1 -1
  21. package/dist/client/assets/SettingsModal-0gevFhXV.css +1 -0
  22. package/dist/client/assets/{SettingsModal-YCJM5is3.js → SettingsModal-DvmwpEUE.js} +1 -1
  23. package/dist/client/assets/SettingsModal-m3KMs_uS.js +31 -0
  24. package/dist/client/assets/{SetupWizardModal-BT-mj3VD.js → SetupWizardModal-CDfZpkB7.js} +1 -1
  25. package/dist/client/assets/{SkillsView-Db7dYpqd.js → SkillsView-BCpa_vud.js} +1 -1
  26. package/dist/client/assets/{StashRecoveryView-CSYYcWux.js → StashRecoveryView-BYLja93K.js} +1 -1
  27. package/dist/client/assets/{TodoView-zqCqfy26.js → TodoView-lbnG-8cZ.js} +2 -2
  28. package/dist/client/assets/{dashboard-view-PpcsMDvN.js → dashboard-view-CY6MGQbI.js} +1 -1
  29. package/dist/client/assets/{folder-open-mxsFQlAX.js → folder-open-CZghG0dv.js} +1 -1
  30. package/dist/client/assets/index-lDPXOH7J.css +1 -0
  31. package/dist/client/assets/index-tJzhtiGM.js +742 -0
  32. package/dist/client/assets/{upload-j7JjaJzG.js → upload-L7aDk8Xn.js} +1 -1
  33. package/dist/client/assets/{users-DZ_0WcB6.js → users-DoWKt94F.js} +1 -1
  34. package/dist/client/index.html +102 -3
  35. package/dist/client/version.json +1 -1
  36. package/dist/droid-cli/package.json +1 -1
  37. package/dist/extension.js +18491 -6644
  38. package/dist/pi-claude-cli/package.json +1 -1
  39. package/dist/plugins/fusion-plugin-cli-printing-press/package.json +1 -1
  40. package/dist/plugins/fusion-plugin-cursor-runtime/package.json +1 -1
  41. package/dist/plugins/fusion-plugin-dependency-graph/package.json +1 -1
  42. package/dist/plugins/fusion-plugin-droid-runtime/package.json +1 -1
  43. package/dist/plugins/fusion-plugin-hermes-runtime/package.json +1 -1
  44. package/dist/plugins/fusion-plugin-openclaw-runtime/package.json +1 -1
  45. package/dist/plugins/fusion-plugin-paperclip-runtime/package.json +1 -1
  46. package/dist/plugins/fusion-plugin-reports/package.json +1 -1
  47. package/dist/plugins/fusion-plugin-roadmap/package.json +1 -1
  48. package/dist/plugins/fusion-plugin-whatsapp-chat/package.json +1 -1
  49. package/package.json +1 -1
  50. package/skill/fusion/references/extension-tools.md +2 -1
  51. package/skill/fusion/references/fusion-capabilities.md +1 -1
  52. package/dist/client/assets/AgentsView-LkVv9hph.js +0 -34
  53. package/dist/client/assets/ChatView-DYjECCRG.js +0 -1
  54. package/dist/client/assets/DevServerView-D7legPr1.js +0 -1
  55. package/dist/client/assets/NodesView-CM0eoCP8.js +0 -14
  56. package/dist/client/assets/ResearchView-Bn2WxwnQ.js +0 -1
  57. package/dist/client/assets/SecretsView-DgrrgzFc.js +0 -1
  58. package/dist/client/assets/SettingsModal-BCZrCLl3.js +0 -31
  59. package/dist/client/assets/SettingsModal-BZBV2kLr.css +0 -1
  60. package/dist/client/assets/index-Ba-F8c1g.js +0 -732
  61. package/dist/client/assets/index-D4HhaIOp.css +0 -1
@@ -0,0 +1 @@
1
+ import{r,j as t}from"./vendor-react-K0fH_qHe.js";import{c4 as Ue,c5 as ve,c6 as tt,c7 as me,s as Me,c8 as xe,c9 as ye,ca as Se,cb as Ne,cc as rt,cd as ie,ce as st,cf as nt,cg as at,ch as it,ci as lt,aF as J,cj as le,L as te,S as ct,M as ot,ck as dt,bJ as ut,a as vt,cl as Pe,T as Te,cm as mt,Q as ft,a_ as pt,a$ as ht,af as gt,aA as bt,R as wt}from"./index-tJzhtiGM.js";import"./vendor-xterm-DzcZoU0P.js";import"./vendor-codemirror-jBKmHyH0.js";const fe=500,xt=3e3;function B(e){return e instanceof Error?e.message:String(e)}function ze(e){return e.length<=fe?e:e.slice(-fe)}function ce(e,i){return ze([...e,i])}function G(e){try{return JSON.parse(e)}catch{return null}}function I(e){const i=e.text??"";return e.stream==="stderr"?`[stderr] ${i}`:i}function yt(e){return e?.previewUrl??null}async function ke(e){return st(e)}async function je(e,i){return nt(e,i)}async function St(e){return at(e)}async function Nt(e){return it(e)}async function Ce(e){return lt(e)}function V(e){try{return e()}catch{return null}}function oe(){return typeof V(()=>ve)=="function"&&typeof V(()=>Ue)=="function"}function q(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),[g,y]=r.useState([]),[x,f]=r.useState([]),[j,A]=r.useState([]),[C,P]=r.useState(!0),[S,u]=r.useState(null),n=r.useRef(0),[d,U]=r.useState(null),_=r.useCallback(a=>{if(o(a),a?.logHistory){const s=a.logHistory.slice(-fe).map(I);f(s)}},[]),M=r.useCallback(async()=>{const a=n.current;try{if(oe())if(d){const s=await Ue(d,e);if(n.current!==a)return;_(s)}else{const s=await ve(e);if(n.current!==a)return;y(s),s.length>0&&(U(s[0].config.id),_(s[0]))}else{const s=await ke(e);if(n.current!==a)return;const c=q(s);y([c]),_(c)}u(null)}catch(s){if(n.current!==a)return;u(B(s))}},[_,e,d]);r.useEffect(()=>{n.current+=1;const a=n.current;o(null),y([]),f([]),A([]),P(!0),u(null),U(null),(async()=>{try{const[c,l]=await Promise.allSettled([oe()?ve(e):ke(e).then(N=>[q(N)]),typeof V(()=>ie)=="function"?ie(e):Ce(e).then(N=>N.map(w=>({name:w.name,command:w.command,cwd:w.cwd,scriptName:w.scriptName,packagePath:w.packagePath})))]);if(n.current!==a)return;let v=null;if(c.status==="fulfilled"){const N=c.value;if(y(N),N.length>0){const w=N[0];oe()&&U(w.config.id),_(w)}}else v=B(c.reason);l.status==="fulfilled"&&A(l.value),v&&u(v)}catch(c){if(n.current!==a)return;u(B(c))}finally{n.current===a&&P(!1)}})()},[_,e]),r.useEffect(()=>{const a=d?tt(d,e):typeof V(()=>me)=="function"?me(e):null;if(!a)return;const s=n.current,c=Me(a,{events:{history:l=>{if(n.current!==s)return;const v=G(l.data);if(v?.lines){const N=v.lines.map(I);f(ze(N))}},log:l=>{if(n.current!==s)return;const v=G(l.data);if(v){const N=typeof v.line=="string"?v.line:I(v);f(w=>ce(w,N))}},"dev-server:log":l=>{if(n.current!==s)return;const v=G(l.data);if(v){const N=typeof v.line=="string"?v.line:I(v);f(w=>ce(w,N))}},"dev-server:output":l=>{if(n.current!==s)return;const v=G(l.data);v?.line&&f(N=>ce(N,v.line))},status:l=>{if(n.current!==s)return;const v=G(l.data),N=v?.status;N&&o(w=>w&&{...w,status:N,runtime:v.pid?{...w.runtime??{startedAt:new Date().toISOString()},pid:v.pid}:w.runtime})},"dev-server:status":l=>{if(n.current!==s)return;const v=G(l.data);if(v?.status){const N=q(v);o(N),y([N])}},stopped:()=>{n.current},failed:()=>{n.current}},onReconnect:()=>{n.current===s&&M()},onError:()=>{n.current===s&&u(l=>l??"Lost log stream connection.")}});return()=>{c()}},[e,M,d]),r.useEffect(()=>{if(i?.status!=="running"&&i?.status!=="starting")return;const a=setInterval(()=>{M()},xt);return()=>{clearInterval(a)}},[M,i?.status]);const E=r.useCallback(async(a,s)=>{n.current+=1;const c=n.current;try{let l;if(d&&typeof V(()=>xe)=="function")l=await xe(d,e);else{const v=await je({command:a,cwd:s},e);l=q(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(()=>ye)=="function")s=await ye(d,e);else{const c=await St(e);s=q(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(()=>Se)=="function")s=await Se(d,e);else{const c=await Nt(e);s=q(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(()=>Ne)=="function")c=await Ne(d,a,e);else{const l=await rt({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 ie(e)}catch{s=(await Ce(e)).map(l=>({name:l.name,command:l.command,cwd:l.cwd,scriptName:l.scriptName,packagePath:l.packagePath}))}if(n.current!==a)return;A(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,N=await je({command:v.command,cwd:v.cwd,scriptName:v.scriptName,packagePath:v.packagePath??v.cwd},e),w=q(N);o(w),y([w]),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 E(c,l)},[e,E,d]),L=r.useCallback(async()=>{await D()},[D]),R=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 M()},[M]),H=yt(i),b=i?{...i,pid:i.runtime?.pid}:null;return{session:i,sessions:g,logs:x,detectedCommands:j,previewUrl:H,isLoading:C,error:S,startServer:E,stopServer:D,restartServer:k,setPreviewUrl:T,detectCommands:h,refresh:M,candidates:j,serverState:b,loading:C,start:p,stop:L,restart:R,setManualUrl:z,detect:$,refreshStatus:O}}const Ee=500,Le=100;function Fe(e){return e.length>Ee?e.slice(-Ee):e}function $e(e){return e==="stderr"?"stderr":"stdout"}function Z(e){try{return JSON.parse(e.data)}catch{return null}}function ee(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 de(e,i){if(i.length===0)return e;const o=[...e],g=new Set(e.map(y=>y.id));for(const y of i)g.has(y.id)||(g.add(y.id),o.push(y));return o.sort((y,x)=>y.id-x.id),Fe(o)}function Ct(e,i){const[o,g]=r.useState([]),[y,x]=r.useState(!1),[f,j]=r.useState(!1),[A,C]=r.useState(!1),[P,S]=r.useState(null),u=r.useRef(null),n=r.useRef(!1),d=r.useRef(0),U=r.useRef(0),_=r.useRef(e),M=r.useRef(i),E=r.useRef(0),D=r.useRef(1);(_.current!==e||M.current!==i)&&(_.current=e,M.current=i,d.current++,J({view:"useDevServerLogs",trigger:"project-context-change",projectId:e,replayAttempted:!1,reason:"context-version-bumped"}),n.current=!0,E.current=0,D.current=1,g([]),x(!1),j(!1),C(!1),S(null),u.current&&(u.current(),u.current=null)),r.useEffect(()=>{if(!i){u.current&&(u.current(),u.current=null);return}const L=d.current,R=++U.current;n.current=!1,x(!0);const z=(b,a)=>{const s=Fe(b);g(s),S(a),C(a!==null?a>s.length:!1);const c=s.length>0?s[s.length-1].id:0;E.current=c,D.current=c+1},$=b=>{if(n.current||d.current!==L||!b||typeof b!="object")return;const a=b.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)=>ee(c,l+1));z(s,s.length)},O=b=>{if(n.current||d.current!==L)return;const a=typeof b.text=="string"?b.text:typeof b.line=="string"?b.line:null;if(!a)return;const s=D.current,c=typeof b.id=="number"&&Number.isFinite(b.id)?b.id:s,l={id:c,text:a,stream:$e(b.stream),timestamp:typeof b.timestamp=="string"?b.timestamp:""};E.current=Math.max(E.current,c),D.current=Math.max(D.current,c+1),g(v=>de(v,[l])),S(v=>v===null?v:Math.max(v+1,l.id))};async function H(){try{const a=await le({maxLines:Le},e);if(n.current||d.current!==L||U.current!==R)return;const s=a.lines.map((c,l)=>ee(c,l+1));z(s,a.totalLines)}catch{if(n.current||d.current!==L||U.current!==R)return;z([],null)}finally{!n.current&&d.current===L&&U.current===R&&x(!1)}const b=me(e);u.current=Me(b,{events:{"dev-server:log":a=>{const s=Z(a);s&&O(s)},log:a=>{const s=Z(a);s&&O(s)},history:a=>{const s=Z(a);$(s)},"dev-server:history":a=>{const s=Z(a);$(s)}},onReconnect:()=>{J({view:"useDevServerLogs",trigger:"sse-reconnect",projectId:e,replayAttempted:!0,replayFromEventId:E.current??null,sseChannel:b,reason:"history-replay"}),!(n.current||d.current!==L)&&le({lastEventId:E.current,maxLines:50},e).then(a=>{if(n.current||d.current!==L)return;const s=a.lines.map((c,l)=>ee(c,D.current+l));if(s.length>0){const c=s[s.length-1].id;E.current=Math.max(E.current,c),D.current=Math.max(D.current,c+1)}g(c=>de(c,s)),S(a.totalLines)}).catch(()=>{})}}),J({view:"useDevServerLogs",trigger:"sse-open",projectId:e,replayAttempted:!1,sseChannel:b})}return H(),()=>{n.current=!0,u.current&&(u.current(),u.current=null)}},[i,e]);const T=r.useCallback(async()=>{if(!i||f)return;const L=d.current,R=o.length;j(!0);try{const z=await le({maxLines:Le,offset:R},e);if(n.current||d.current!==L)return;const $=z.lines.map((O,H)=>ee(O,H+1));g(O=>de($,O)),C(z.totalLines>R+$.length),S(z.totalLines)}catch{}finally{j(!1)}},[i,o.length,f,e]),h=r.useCallback(()=>{g([])},[]),p=u.current!==null&&!y&&!n.current;return{entries:o,loading:y,loadingMore:f,hasMore:A,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:g=null}=i,y=r.useRef(null),x=r.useRef(null),[f,j]=r.useState("unknown"),[A,C]=r.useState(null),[P]=r.useState(g),S=r.useCallback(()=>{x.current!==null&&(window.clearTimeout(x.current),x.current=null)},[]),u=r.useCallback(k=>{j(k),C(_t(k))},[]),n=r.useCallback(()=>{j("blocked"),C(Rt)},[]);r.useEffect(()=>{if(S(),!e){j("unknown"),C(null);return}j("unknown"),C(null);let k=!1;return queueMicrotask(()=>{k||(j("loading"),C(null))}),()=>{k=!0,S()}},[S,e]),r.useEffect(()=>{if(f!=="loading"){S();return}const k=setTimeout(()=>{x.current=null,n()},o);return x.current=k,()=>{clearTimeout(k),x.current===k&&(x.current=null)}},[S,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(S(),!e){j("unknown"),C(null);return}j("unknown"),C(null)},[S]);const _=r.useCallback(()=>{S(),j("unknown"),C(null)},[S]),M=_,E=r.useMemo(()=>f==="embedded",[f]),D=r.useMemo(()=>f==="blocked"||f==="error",[f]);return{embedStatus:f,isEmbedded:E,isBlocked:D,blockReason:A,detectionMethod:P,iframeRef:y,resetEmbedStatus:_,setEmbedStatus:u,retry:M,embedContext:A,handleIframeLoad:d,handleIframeError:U}}const At=/\x1b\[[0-9;]*m/g;function pe(e){return e.replace(At,"")}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 Mt(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Pt(e){if(e.stream==="stderr")return"error";const i=pe(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(`(${Mt(i)})`,"ig"),g=e.split(o),y=i.toLowerCase();return t.jsx(t.Fragment,{children:g.map((x,f)=>x.toLowerCase()===y?t.jsx("mark",{children:x},`${x}-${f}`):t.jsx("span",{children:x},`${x}-${f}`))})}function zt({entries:e,loading:i,loadingMore:o,hasMore:g,total:y,onLoadMore:x,isRunning:f}){const j=r.useRef(null),A=r.useRef(e.length),C=r.useRef(f),[P,S]=r.useState(!1),[u,n]=r.useState(!1),[d,U]=r.useState(""),[_,M]=r.useState("all"),E=r.useMemo(()=>_==="all"?e:e.filter(p=>Pt(p)===_),[e,_]),D=r.useMemo(()=>{const p=d.trim().toLowerCase();return p?E.filter(L=>pe(L.text).toLowerCase().includes(p)):E},[E,d]),k=D.length,T=r.useCallback(()=>{const p=j.current;p&&(p.scrollTop=p.scrollHeight,n(!1))},[]);r.useEffect(()=>{const p=C.current,L=A.current,R=e.length>L;f&&(!p||!u&&R)&&T(),C.current=f,A.current=e.length},[e.length,f,u,T]);const h=r.useCallback(()=>{const p=j.current;if(!p)return;const R=p.scrollTop+p.clientHeight>=p.scrollHeight-50;n(!R)},[]);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(te,{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:_,onChange:p=>M(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(ct,{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:()=>S(p=>!p),"data-testid":"devserver-log-fullscreen-toggle","aria-label":P?"Exit fullscreen logs":"Enter fullscreen logs",children:P?t.jsx(ot,{size:14}):t.jsx(dt,{size:14})})]})]}),t.jsxs("div",{className:"devserver-log-viewer__body",children:[g&&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:x,disabled:o,"data-testid":"devserver-log-load-more-button",children:o?t.jsxs(t.Fragment,{children:[t.jsx(te,{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.":E.length===0?"No log lines match the selected severity.":"No log lines match your search."}),D.map(p=>{const L=pe(p.text),R=Ut(p.timestamp);return t.jsxs("div",{className:"devserver-log-line",children:[R&&t.jsx("span",{className:"devserver-log-timestamp","data-testid":"devserver-log-timestamp",children:R}),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:ut(Tt(L,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(vt,{size:14}),"New logs"]})]})]})}const Ft="devserver-preview-iframe";function $t({url:e,embedStatus:i,onEmbedStatusChange:o,iframeRef:g,blockReason:y,onRetry:x,className:f=Ft,embedContext:j}){const A=y??j??null,[C,P]=r.useState(0);r.useEffect(()=>{!e||i!=="unknown"||(P(d=>d+1),o("loading"))},[i,o,e]);const S=r.useCallback(()=>{const d=g.current;if(!d){o("embedded");return}try{if(d.contentWindow?.location?.href==="about:blank"&&d.src!=="about:blank"){o("blocked");return}}catch{}o("embedded")},[g,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:g,sandbox:"allow-scripts allow-same-origin allow-forms allow-popups allow-popups-to-escape-sandbox",className:f,title:"Dev server preview",onLoad:S,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(te,{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"}),A&&t.jsx("p",{className:"devserver-preview-blocked-context",children:A})]}),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"}),x&&t.jsx("button",{type:"button",className:"btn btn-sm",onClick:x,children:"Retry"})]})]}),i==="error"&&t.jsxs("div",{className:"devserver-preview-error-panel",role:"alert","data-testid":"devserver-preview-error-panel",children:[t.jsx(Te,{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"}),A&&t.jsx("p",{className:"devserver-preview-blocked-context",children:A})]}),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"}),x&&t.jsx("button",{type:"button",className:"btn btn-sm",onClick:x,children:"Retry"})]})]})]}):null}const Re={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"}};let ue=!1;function _e(e){return e instanceof Error?e.message:String(e)}function Oe(e){return e==="."?"root":e}function De(e){return e?e==="root"?".":e:null}function Ae(e,i,o){return!i||e.scriptName!==i?!1:o?Oe(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 Xt({addToast:e,projectId:i}){r.useEffect(()=>(J({view:"DevServerView",trigger:ue?"route-active":"remount",projectId:i,replayAttempted:!1}),ue=!1,()=>{ue=!0,J({view:"DevServerView",trigger:"route-inactive",projectId:i,replayAttempted:!1})}),[i]);const{session:o,detectedCommands:g,previewUrl:y,isLoading:x,error:f,startServer:j,stopServer:A,restartServer:C,setPreviewUrl:P,detectCommands:S,refresh:u}=kt(i),n=o?.status??"stopped",d=n==="running"||n==="starting",U=Re[n]??Re.stopped,{entries:_,loading:M,loadingMore:E,hasMore:D,total:k,loadMore:T}=Ct(i,!!i),h=y,p=o?.config?.cwd??null,[L,R]=r.useState(!0),[z,$]=r.useState(""),[O,H]=r.useState(""),[b,a]=r.useState(null),[s,c]=r.useState(null),[l,v]=r.useState("embedded"),N=l==="embedded"?h:null,{embedStatus:w,setEmbedStatus:Be,resetEmbedStatus:Q,iframeRef:X,isEmbedded:He,isBlocked:re,blockReason:se,retry:he}=Dt(N),[ge,W]=r.useState(!1),be=r.useRef(w);r.useEffect(()=>{const m=be.current!==w;re&&m&&W(!0),w==="embedded"&&W(!1),be.current=w},[w,re]),r.useEffect(()=>{W(!1)},[h]);const Y=r.useMemo(()=>{if(!b)return null;const m=De(p);return g.find(F=>!(F.scriptName!==b||m&&F.cwd!==m||o?.config?.command&&F.command!==o.config.command))??g.find(F=>Ae(F,b,p))??null},[g,o?.config?.command,b,p]);r.useEffect(()=>{typeof S=="function"&&S().catch(m=>{e(_e(m),"error")})},[e,S]),r.useEffect(()=>{if(b){R(!1);return}R(!0)},[b]),r.useEffect(()=>{if(o?.status==="running"||o?.status==="starting"){o.config?.command?.trim().length>0&&$(o.config.command);return}if(Y){$(Y.command);return}g.length>0&&$(m=>m.trim().length>0?m:g[0]?.command??"")},[g,Y,o?.config?.command,o?.status]),r.useEffect(()=>{H(h??"")},[h]);const ne=r.useCallback(()=>{h&&window.open(h,"_blank","noopener,noreferrer")},[h]),we=r.useCallback(()=>{W(!1),he()},[he]),Ve=r.useCallback(()=>{try{const m=X.current;if(m?.contentWindow){m.contentWindow.location.reload(),W(!1),Q();return}}catch{}if(!(!h||!X.current))try{const m=new URL(h);m.searchParams.set("_t",Date.now().toString()),X.current.src=m.toString(),W(!1),Q()}catch{X.current.src=h,W(!1),Q()}},[h,X,Q]),K=r.useCallback(async(m,F,ae)=>{c(m);try{await F(),e(ae,"success")}catch(et){e(_e(et),"error")}finally{c(null)}},[e]),We=r.useCallback(m=>{a(m.scriptName),R(!1),$(m.command),e(`Selected ${m.scriptName} script.`,"success")},[e]),qe=r.useCallback(()=>{a(null),R(!0),e("Cleared selected dev server script.","success")},[e]),Xe=()=>{const m=z.trim();if(m.length===0){e("Enter a command before starting the dev server.","warning");return}const F=De(p)??".",ae=Y?.cwd??F;K("start",()=>j(m,ae),"Dev server started.")},Ge=()=>{K("stop",A,"Dev server stopped.")},Je=()=>{K("restart",C,"Dev server restarted.")},Qe=()=>{const m=O.trim(),F=m.length>0?m:null;K("preview",()=>P(F),F?"Preview URL updated.":"Preview URL override cleared.")},Ye=r.useCallback(()=>{f&&u()},[f,u]),Ke=n==="starting"||n==="running"||s!==null,Ie=n==="stopped"||s!==null,Ze=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(mt,{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:Xe,disabled:Ke,"data-testid":"dev-server-start-button",children:[t.jsx(ft,{size:14}),t.jsx("span",{children:s==="start"?"Starting...":"Start"})]}),t.jsxs("button",{type:"button",className:"btn btn-danger btn-sm",onClick:Ge,disabled:Ie,"data-testid":"dev-server-stop-button",children:[t.jsx(pt,{size:14}),t.jsx("span",{children:s==="stop"?"Stopping...":"Stop"})]}),t.jsxs("button",{type:"button",className:"btn btn-sm",onClick:Je,disabled:Ze,"data-testid":"dev-server-restart-button",children:[t.jsx(ht,{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"}),x&&t.jsx("span",{className:"dev-server-muted",children:"Loading..."})]}),x&&!o&&g.length===0&&t.jsxs("div",{className:"dev-server-loading-state","data-testid":"dev-server-loading-state",children:[t.jsx(te,{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:Ye,children:"Retry"})]}),t.jsxs("div",{className:"dev-server-section",children:[t.jsx("h3",{children:"Script Selection"}),b&&t.jsxs("div",{className:"dev-server-selected","data-testid":"dev-server-selected-summary",children:[t.jsx("span",{className:"dev-server-candidate-name",children:b}),t.jsx("span",{className:"dev-server-candidate-source",children:p??"root"}),t.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>R(!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"})]}),L&&g.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."]}),L&&g.length>0&&t.jsx("div",{className:"dev-server-candidates","data-testid":"dev-server-candidates",children:g.map(m=>{const F=Ae(m,b,p);return t.jsxs("button",{type:"button",className:`dev-server-candidate ${F?"dev-server-candidate--selected":""}`,onClick:()=>We(m),"data-testid":`dev-server-candidate-${m.scriptName}-${Oe(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:Qe,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.jsx("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??_.length," lines"]})]}),t.jsx("div",{className:"dev-server-logs-viewer","data-testid":"dev-server-log-viewer",children:t.jsx(zt,{entries:_,loading:M,loadingMore:E,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(gt,{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:ne,disabled:!h,"data-testid":"devserver-preview-open-tab",children:t.jsx(bt,{})}),t.jsx("button",{type:"button",className:"btn btn-sm btn-icon",title:"Refresh preview",onClick:Ve,disabled:!h,"data-testid":"devserver-preview-refresh",children:t.jsx(wt,{})})]})]}),t.jsxs("div",{className:"devserver-preview-container","data-embed-status":w,"data-embedded":He?"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:ne,"data-testid":"devserver-preview-external-open-tab",children:"Open in new tab"})]}),h&&l==="embedded"&&ge&&re&&t.jsxs("div",{className:w==="error"?"devserver-preview-error-panel":"devserver-preview-blocked-panel","data-testid":"devserver-preview-fallback",role:"alert",children:[w==="error"?t.jsx(Te,{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:w==="error"?"Preview failed":"Preview blocked"}),se&&t.jsx("p",{className:"devserver-preview-blocked-context",children:se})]}),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:ne,"data-testid":"devserver-preview-fallback-open-tab",children:"Open preview in new tab"}),t.jsx("button",{type:"button",className:"btn btn-sm",onClick:we,"data-testid":"devserver-preview-fallback-retry",children:"Retry embedded preview"})]})]}),h&&l==="embedded"&&!ge&&t.jsx($t,{url:h,embedStatus:w,onEmbedStatusChange:Be,iframeRef:X,blockReason:se,onRetry:we})]})]})]})}export{Xt as DevServerView};
@@ -1 +1 @@
1
- import{r as i,j as r}from"./vendor-react-K0fH_qHe.js";import{eL as f,eM as g,dr as b,b as y,ai as P,ad as H,ae as C,L as O,aw as v}from"./index-Ba-F8c1g.js";import{F as z}from"./folder-open-mxsFQlAX.js";function D({value:o,onChange:d,placeholder:m,onInputKeyDown:x,nodeId:l,localNodeId:h}){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,l,h);n(u=>({...u,loading:!1,currentPath:t.currentPath,parentPath:t.parentPath,entries:t.entries}))}catch(t){n(u=>({...u,loading:!1,error:t instanceof Error?t.message:"Failed to browse directory"}))}},[l,h]),j=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(o||void 0,e.showHidden)},[e.isOpen,e.loading,e.entries.length,e.error,o,e.showHidden,a,l,h]);const p=i.useCallback(s=>{a(s,e.showHidden)},[a,e.showHidden]),k=i.useCallback(()=>{d(e.currentPath),n(s=>({...s,isOpen:!1}))},[e.currentPath,d]),w=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 N=e.currentPath?g(e.currentPath):[];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:o,onChange:s=>d(s.target.value),onKeyDown:x,placeholder:m||"/path/to/your/project"}),r.jsxs("button",{type:"button",className:"btn btn-secondary btn-sm directory-picker-browse-btn",onClick:j,"aria-label":e.isOpen?"Close directory browser":"Browse directories",children:[e.isOpen?r.jsx(z,{size:16}):r.jsx(b,{size:16}),r.jsx("span",{children:"Browse"})]})]}),e.isOpen&&r.jsxs("div",{className:"directory-picker-browser",role:"tree","aria-label":"Directory browser",children:[r.jsx("div",{className:"directory-picker-breadcrumbs",children:N.map((s,c)=>r.jsxs("span",{className:"directory-picker-breadcrumb-item",children:[c>0&&r.jsx(y,{size:12,className:"directory-picker-breadcrumb-sep"}),r.jsx("button",{type:"button",className:"directory-picker-breadcrumb",onClick:()=>p(s.path),title:s.path,children:s.label})]},s.path))}),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:()=>p(e.parentPath),"aria-label":"Go to parent directory",title:"Parent directory",children:[r.jsx(P,{size:14}),r.jsx("span",{children:"Up"})]}),r.jsxs("button",{type:"button",className:"btn btn-sm btn-secondary directory-picker-hidden-toggle",onClick:w,"aria-label":e.showHidden?"Hide hidden directories":"Show hidden directories",title:e.showHidden?"Hide hidden":"Show hidden",children:[e.showHidden?r.jsx(H,{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(O,{size:20,className:"animate-spin"}),r.jsx("span",{children:"Loading…"})]}):e.error?r.jsxs("div",{className:"directory-picker-error",children:[r.jsx(v,{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:()=>p(s.path),role:"treeitem",title:s.path,children:[r.jsx(b,{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:k,children:"Select"})]})]})]})}export{D};
1
+ import{r as i,j as r}from"./vendor-react-K0fH_qHe.js";import{eV as N,eW as g,dB as b,b as y,aj as P,ae as H,af as C,L as O,ax as v}from"./index-tJzhtiGM.js";import{F as z}from"./folder-open-CZghG0dv.js";function D({value:o,onChange:d,placeholder:m,onInputKeyDown:x,nodeId:l,localNodeId:h}){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 N(s,c,l,h);n(u=>({...u,loading:!1,currentPath:t.currentPath,parentPath:t.parentPath,entries:t.entries}))}catch(t){n(u=>({...u,loading:!1,error:t instanceof Error?t.message:"Failed to browse directory"}))}},[l,h]),j=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(o||void 0,e.showHidden)},[e.isOpen,e.loading,e.entries.length,e.error,o,e.showHidden,a,l,h]);const p=i.useCallback(s=>{a(s,e.showHidden)},[a,e.showHidden]),k=i.useCallback(()=>{d(e.currentPath),n(s=>({...s,isOpen:!1}))},[e.currentPath,d]),w=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 f=e.currentPath?g(e.currentPath):[];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:o,onChange:s=>d(s.target.value),onKeyDown:x,placeholder:m||"/path/to/your/project"}),r.jsxs("button",{type:"button",className:"btn btn-secondary btn-sm directory-picker-browse-btn",onClick:j,"aria-label":e.isOpen?"Close directory browser":"Browse directories",children:[e.isOpen?r.jsx(z,{size:16}):r.jsx(b,{size:16}),r.jsx("span",{children:"Browse"})]})]}),e.isOpen&&r.jsxs("div",{className:"directory-picker-browser",role:"tree","aria-label":"Directory browser",children:[r.jsx("div",{className:"directory-picker-breadcrumbs",children:f.map((s,c)=>r.jsxs("span",{className:"directory-picker-breadcrumb-item",children:[c>0&&r.jsx(y,{size:12,className:"directory-picker-breadcrumb-sep"}),r.jsx("button",{type:"button",className:"directory-picker-breadcrumb",onClick:()=>p(s.path),title:s.path,children:s.label})]},s.path))}),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:()=>p(e.parentPath),"aria-label":"Go to parent directory",title:"Parent directory",children:[r.jsx(P,{size:14}),r.jsx("span",{children:"Up"})]}),r.jsxs("button",{type:"button",className:"btn btn-sm btn-secondary directory-picker-hidden-toggle",onClick:w,"aria-label":e.showHidden?"Hide hidden directories":"Show hidden directories",title:e.showHidden?"Hide hidden":"Show hidden",children:[e.showHidden?r.jsx(H,{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(O,{size:20,className:"animate-spin"}),r.jsx("span",{children:"Loading…"})]}):e.error?r.jsxs("div",{className:"directory-picker-error",children:[r.jsx(v,{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:()=>p(s.path),role:"treeitem",title:s.path,children:[r.jsx(b,{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:k,children:"Select"})]})]})]})}export{D};
@@ -1 +1 @@
1
- import{r as s,j as e}from"./vendor-react-K0fH_qHe.js";import{a6 as K,a7 as W,a8 as ie,a9 as de,aa as G,ab as ue,f as me,ac as he,F as T,ad as fe,ae as pe,S as je,X as xe,R as we,af as ke,ag as X,ah as V,a as Y,b as ge,ai as be}from"./index-Ba-F8c1g.js";import"./vendor-xterm-DzcZoU0P.js";import"./vendor-codemirror-jBKmHyH0.js";function ve(n){const{projectId:c,searchQuery:h,includeProjectFiles:a=!0}=n??{},l=c?`${ie.DOCUMENTS_PREFIX}${c}`:null,[o,m]=s.useState(()=>{if(!l)return[];const w=K(l,{maxAgeMs:W});return Array.isArray(w)?w:[]}),[d,i]=s.useState([]),[k,x]=s.useState(()=>o.length===0),[C,b]=s.useState(null),g=s.useRef(null),f=s.useRef(o.length>0),p=s.useRef(null),v=s.useCallback(async()=>{g.current&&g.current.abort();const w=new AbortController;g.current=w;const z=!f.current;z&&x(!0),b(null);const E=de(h?{q:h}:void 0,c),R=a?G(c):Promise.resolve({files:[]}),[j,M]=await Promise.allSettled([E,R]);if(w.signal.aborted)return;let A=null;if(j.status==="fulfilled"){if(m(j.value),l){const y=j.value.length>500?j.value.slice(0,500):j.value;ue(l,y,{maxBytes:5e5})}f.current=!0}else A=j.reason instanceof Error?j.reason.message:String(j.reason);if(M.status==="fulfilled"){const y=M.value.files,L=h?.trim().toLowerCase(),F=L?y.filter(P=>P.name.toLowerCase().includes(L)||P.path.toLowerCase().includes(L)):y;i(F)}b(A),z&&x(!1)},[l,a,c,h]);return s.useEffect(()=>{if(!l){f.current=!1,m([]),x(!0);return}const w=K(l,{maxAgeMs:W});Array.isArray(w)?(m(w),f.current=!0,x(!1)):(f.current=!1,m([]),x(!0))},[l]),s.useEffect(()=>(p.current&&clearTimeout(p.current),p.current=setTimeout(()=>{v()},300),()=>{p.current&&clearTimeout(p.current)}),[v]),s.useEffect(()=>(v(),()=>{g.current&&g.current.abort()}),[]),{documents:o,projectFiles:d,loading:k,error:C,refresh:v}}function Ne(n,c){const[h,a]=s.useState([]),[l,o]=s.useState(!0),[m,d]=s.useState(null),i=s.useRef(null),k=s.useRef(!1),x=c?.showHidden??!1,C=s.useCallback(async b=>{i.current&&i.current.abort();const g=new AbortController;i.current=g;const f=!k.current;f&&o(!0),d(null);try{const p=await G(n,{showHidden:b?.showHidden??x});if(g.signal.aborted)return;a(p.files),k.current=!0}catch(p){if(g.signal.aborted)return;d(p instanceof Error?p.message:String(p))}finally{!g.signal.aborted&&f&&o(!1)}},[n,x]);return s.useEffect(()=>(k.current=!1,C({showHidden:x}),()=>{i.current&&i.current.abort()}),[C,x]),{files:h,loading:l,error:m,refresh:C}}const Se=768;function J(n){return n?new Date(n).toLocaleString():""}function Ce(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 Fe(n,c=200){return n.length<=c?n:`${n.substring(0,c)}…`}function Ee({document:n,renderMarkdown:c,onToggleMarkdown:h}){const[a,l]=s.useState(!1),o=Fe(n.content),m=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(T,{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:()=>l(d=>!d),title:a?"Collapse":"Expand","aria-label":a?"Collapse content":"Expand content",children:a?e.jsx(be,{size:14}):e.jsx(Y,{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:J(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:h,"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(X,{remarkPlugins:[V],children:n.content})})}):e.jsx("pre",{className:"document-card-content-text",children:n.content})]}):e.jsx("p",{className:"document-card-preview",children:o}),m&&!a&&e.jsx("p",{className:"document-card-preview-truncated",children:"…"})]})]})}function ye({taskId:n,taskTitle:c,documents:h,onOpenTask:a,renderMarkdownStates:l,onToggleMarkdown:o}){const[m,d]=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:()=>d(i=>!i),"aria-expanded":m,"aria-label":`${m?"Collapse":"Expand"} documents for task ${n}`,children:[e.jsx("span",{className:"documents-group-toggle","aria-hidden":"true",children:m?e.jsx(Y,{size:16}):e.jsx(ge,{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:[h.length," doc",h.length!==1?"s":""]}),e.jsx("button",{className:"documents-group-task-link",onClick:()=>a(n),"aria-label":`Open task ${n}: ${c||"Untitled"}`,children:"Open task"})]}),m&&e.jsx("div",{className:"documents-group-content",children:h.map(i=>e.jsx(Ee,{document:i,renderMarkdown:l.get(i.id)??!1,onToggleMarkdown:()=>o(i.id)},i.id))})]})}function ze({projectId:n,addToast:c,onOpenDetail:h}){const[a,l]=s.useState("project"),[o,m]=s.useState(""),[d,i]=s.useState(null),[k,x]=s.useState(!1),[C,b]=s.useState(null),[g,f]=s.useState(!1),[p,v]=s.useState(null),[w,z]=s.useState(!1),E=s.useRef(0),R=s.useRef(!1),[j,M]=s.useState(!1),[A,y]=s.useState(new Map),L=a==="tasks"?o.trim():"",{documents:F,loading:P,error:Z,refresh:B}=ve({projectId:n,searchQuery:L||void 0,includeProjectFiles:!1}),{files:S,loading:D,error:I,refresh:O}=Ne(n,{showHidden:k});s.useEffect(()=>{const t=()=>{z(window.innerWidth<=Se)};return t(),window.addEventListener("resize",t),()=>{window.removeEventListener("resize",t)}},[]),s.useEffect(()=>{R.current=!1,l("project"),i(null),x(!1),b(null),v(null),f(!1),M(!1),y(new Map)},[n]),s.useEffect(()=>{R.current||P||D||(S.length>0?l("project"):F.length>0&&l("tasks"),R.current=!0)},[F.length,P,S.length,D]);const $=s.useMemo(()=>{const t=new Map;for(const r of F){const u=t.get(r.taskId)||[];t.set(r.taskId,[...u,r])}return Array.from(t.entries()).map(([r,u])=>{const N=[...u].sort((oe,le)=>le.updatedAt.localeCompare(oe.updatedAt));return{taskId:r,taskTitle:N[0]?.taskTitle,documents:N,latestUpdated:N[0]?.updatedAt??""}}).sort((r,u)=>u.latestUpdated.localeCompare(r.latestUpdated))},[F]),H=s.useMemo(()=>{const t=o.trim().toLowerCase();return t?S.filter(r=>{const u=r.path.toLowerCase(),N=r.name.toLowerCase();return u.includes(t)||N.includes(t)}):S},[S,o]);s.useEffect(()=>{if(!d)return;S.some(r=>r.path===d.path)||(i(null),b(null),v(null),f(!1))},[S,d]);const ee=s.useCallback(t=>{m(t.target.value)},[]),se=s.useCallback(()=>{m("")},[]),U=s.useCallback(t=>{l(t)},[]),te=s.useCallback(async t=>{try{const r=await me(t,n);h(r)}catch{c(`Failed to open task ${t}`,"error")}},[n,h,c]),ne=s.useCallback(async t=>{i(t),f(!0),v(null),b(null);const r=E.current+1;E.current=r;try{const u=await he("project",t.path,n);if(E.current!==r)return;b(u.content)}catch(u){if(E.current!==r)return;const N=u instanceof Error?u.message:`Failed to open ${t.path}`;v(N),c(N,"error")}finally{E.current===r&&f(!1)}},[n,c]),ae=s.useCallback(()=>{i(null),b(null),v(null),f(!1)},[]),re=s.useCallback(t=>{y(r=>{const u=new Map(r),N=u.get(t)??!1;return u.set(t,!N),u})},[]),_=a==="project"?I:Z,ce=s.useCallback(async()=>{if(a==="project"){await O();return}await B()},[a,O,B]),Q=a==="project"?H.length:F.length,q=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(T,{size:20}),"Documents"]}),e.jsxs("span",{className:"documents-view-count",children:[Q," result",Q!==1?"s":""]})]}),e.jsxs("div",{className:"documents-controls-row",children:[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:()=>U("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:()=>U("tasks"),children:["Task Documents",e.jsx("span",{className:"documents-tab-count",children:$.length})]})]}),a==="project"&&e.jsxs("button",{className:"btn btn-sm documents-hidden-toggle",onClick:()=>x(t=>!t),"aria-pressed":k,"aria-label":k?"Hide hidden project files":"Show hidden project files",title:k?"Hide hidden files":"Show hidden files",children:[k?e.jsx(fe,{size:14}):e.jsx(pe,{size:14}),k?"Hide Hidden":"Show Hidden"]}),e.jsxs("div",{className:"documents-search",children:[e.jsx(je,{size:16,className:"documents-search-icon"}),e.jsx("input",{type:"text",className:"documents-search-input",placeholder:q,value:o,onChange:ee,"aria-label":q}),o&&e.jsx("button",{className:"documents-search-clear",onClick:se,"aria-label":"Clear search",children:e.jsx(xe,{size:16})})]})]})]}),e.jsx("div",{className:"documents-view-content",children:_?e.jsxs("div",{className:"documents-view-error",children:[e.jsxs("p",{children:["Failed to load ",a==="project"?"project files":"task documents",": ",_]}),e.jsxs("button",{className:"btn btn-primary",onClick:()=>void ce(),"aria-label":"Retry loading documents",children:[e.jsx(we,{size:16}),"Retry"]})]}):a==="project"?D&&S.length===0?e.jsx("div",{className:"documents-view-loading",children:e.jsx("p",{children:"Loading project markdown files…"})}):H.length===0?e.jsx("div",{className:"documents-view-empty",children:o.trim()?e.jsxs("p",{children:['No project markdown files match "',o.trim(),'".']}):e.jsxs(e.Fragment,{children:[e.jsx(T,{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${w?" documents-project-layout--mobile":""}`,children:[(!w||!d)&&e.jsx("aside",{className:"documents-view-sidebar","aria-label":"Project markdown files",children:e.jsx("ul",{className:"markdown-file-list",children:H.map(t=>{const r=d?.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 ne(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:[Ce(t.size)," · ",J(t.mtime)]})]})},t.path)})})}),(!w||d)&&e.jsxs("section",{className:"documents-view-main","aria-label":"Project file content preview",children:[w&&d&&e.jsxs("button",{className:"btn btn-sm documents-mobile-back",onClick:ae,"aria-label":"Back to project files list",children:[e.jsx(ke,{size:14}),"Back to files"]}),d?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:d.path}),e.jsx("button",{className:"btn btn-sm document-mode-toggle",onClick:()=>M(t=>!t),"aria-label":j?"Switch to plain text":"Switch to markdown","aria-pressed":j,title:j?"Switch to plain text":"Switch to markdown",children:j?"Markdown":"Plain"})]}),g?e.jsx("p",{className:"documents-content-state",children:"Loading file content…"}):p?e.jsx("p",{className:"documents-content-state documents-content-state--error",children:p}):j?e.jsx("div",{className:"documents-content-markdown",children:e.jsx("div",{className:"markdown-body",children:e.jsx(X,{remarkPlugins:[V],children:C??""})})}):e.jsx("pre",{className:"document-card-content-text documents-content-viewer-text",children:C??""})]}):e.jsx("div",{className:"documents-view-empty",children:e.jsx("p",{children:"Select a Markdown file to view its content."})})]})]}):P&&F.length===0?e.jsx("div",{className:"documents-view-loading",children:e.jsx("p",{children:"Loading task documents…"})}):$.length===0?e.jsx("div",{className:"documents-view-empty",children:o.trim()?e.jsxs("p",{children:['No task documents match "',o.trim(),'".']}):e.jsxs(e.Fragment,{children:[e.jsx(T,{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:$.map(({taskId:t,taskTitle:r,documents:u})=>e.jsx(ye,{taskId:t,taskTitle:r,documents:u,onOpenTask:te,renderMarkdownStates:A,onToggleMarkdown:re},t))})})})]})}export{ze as DocumentsView};
1
+ import{r as s,j as e}from"./vendor-react-K0fH_qHe.js";import{a7 as K,a8 as W,a9 as ie,aa as de,ab as G,ac as ue,f as me,ad as he,F as T,ae as fe,af as pe,S as je,X as xe,R as we,ag as ke,ah as X,ai as V,a as Y,b as ge,aj as be}from"./index-tJzhtiGM.js";import"./vendor-xterm-DzcZoU0P.js";import"./vendor-codemirror-jBKmHyH0.js";function ve(n){const{projectId:c,searchQuery:h,includeProjectFiles:a=!0}=n??{},l=c?`${ie.DOCUMENTS_PREFIX}${c}`:null,[o,m]=s.useState(()=>{if(!l)return[];const w=K(l,{maxAgeMs:W});return Array.isArray(w)?w:[]}),[d,i]=s.useState([]),[k,x]=s.useState(()=>o.length===0),[C,b]=s.useState(null),g=s.useRef(null),f=s.useRef(o.length>0),p=s.useRef(null),v=s.useCallback(async()=>{g.current&&g.current.abort();const w=new AbortController;g.current=w;const z=!f.current;z&&x(!0),b(null);const E=de(h?{q:h}:void 0,c),R=a?G(c):Promise.resolve({files:[]}),[j,M]=await Promise.allSettled([E,R]);if(w.signal.aborted)return;let A=null;if(j.status==="fulfilled"){if(m(j.value),l){const y=j.value.length>500?j.value.slice(0,500):j.value;ue(l,y,{maxBytes:5e5})}f.current=!0}else A=j.reason instanceof Error?j.reason.message:String(j.reason);if(M.status==="fulfilled"){const y=M.value.files,L=h?.trim().toLowerCase(),F=L?y.filter(P=>P.name.toLowerCase().includes(L)||P.path.toLowerCase().includes(L)):y;i(F)}b(A),z&&x(!1)},[l,a,c,h]);return s.useEffect(()=>{if(!l){f.current=!1,m([]),x(!0);return}const w=K(l,{maxAgeMs:W});Array.isArray(w)?(m(w),f.current=!0,x(!1)):(f.current=!1,m([]),x(!0))},[l]),s.useEffect(()=>(p.current&&clearTimeout(p.current),p.current=setTimeout(()=>{v()},300),()=>{p.current&&clearTimeout(p.current)}),[v]),s.useEffect(()=>(v(),()=>{g.current&&g.current.abort()}),[]),{documents:o,projectFiles:d,loading:k,error:C,refresh:v}}function Ne(n,c){const[h,a]=s.useState([]),[l,o]=s.useState(!0),[m,d]=s.useState(null),i=s.useRef(null),k=s.useRef(!1),x=c?.showHidden??!1,C=s.useCallback(async b=>{i.current&&i.current.abort();const g=new AbortController;i.current=g;const f=!k.current;f&&o(!0),d(null);try{const p=await G(n,{showHidden:b?.showHidden??x});if(g.signal.aborted)return;a(p.files),k.current=!0}catch(p){if(g.signal.aborted)return;d(p instanceof Error?p.message:String(p))}finally{!g.signal.aborted&&f&&o(!1)}},[n,x]);return s.useEffect(()=>(k.current=!1,C({showHidden:x}),()=>{i.current&&i.current.abort()}),[C,x]),{files:h,loading:l,error:m,refresh:C}}const Se=768;function J(n){return n?new Date(n).toLocaleString():""}function Ce(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 Fe(n,c=200){return n.length<=c?n:`${n.substring(0,c)}…`}function Ee({document:n,renderMarkdown:c,onToggleMarkdown:h}){const[a,l]=s.useState(!1),o=Fe(n.content),m=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(T,{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:()=>l(d=>!d),title:a?"Collapse":"Expand","aria-label":a?"Collapse content":"Expand content",children:a?e.jsx(be,{size:14}):e.jsx(Y,{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:J(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:h,"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(X,{remarkPlugins:[V],children:n.content})})}):e.jsx("pre",{className:"document-card-content-text",children:n.content})]}):e.jsx("p",{className:"document-card-preview",children:o}),m&&!a&&e.jsx("p",{className:"document-card-preview-truncated",children:"…"})]})]})}function ye({taskId:n,taskTitle:c,documents:h,onOpenTask:a,renderMarkdownStates:l,onToggleMarkdown:o}){const[m,d]=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:()=>d(i=>!i),"aria-expanded":m,"aria-label":`${m?"Collapse":"Expand"} documents for task ${n}`,children:[e.jsx("span",{className:"documents-group-toggle","aria-hidden":"true",children:m?e.jsx(Y,{size:16}):e.jsx(ge,{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:[h.length," doc",h.length!==1?"s":""]}),e.jsx("button",{className:"documents-group-task-link",onClick:()=>a(n),"aria-label":`Open task ${n}: ${c||"Untitled"}`,children:"Open task"})]}),m&&e.jsx("div",{className:"documents-group-content",children:h.map(i=>e.jsx(Ee,{document:i,renderMarkdown:l.get(i.id)??!1,onToggleMarkdown:()=>o(i.id)},i.id))})]})}function ze({projectId:n,addToast:c,onOpenDetail:h}){const[a,l]=s.useState("project"),[o,m]=s.useState(""),[d,i]=s.useState(null),[k,x]=s.useState(!1),[C,b]=s.useState(null),[g,f]=s.useState(!1),[p,v]=s.useState(null),[w,z]=s.useState(!1),E=s.useRef(0),R=s.useRef(!1),[j,M]=s.useState(!1),[A,y]=s.useState(new Map),L=a==="tasks"?o.trim():"",{documents:F,loading:P,error:Z,refresh:B}=ve({projectId:n,searchQuery:L||void 0,includeProjectFiles:!1}),{files:S,loading:D,error:I,refresh:O}=Ne(n,{showHidden:k});s.useEffect(()=>{const t=()=>{z(window.innerWidth<=Se)};return t(),window.addEventListener("resize",t),()=>{window.removeEventListener("resize",t)}},[]),s.useEffect(()=>{R.current=!1,l("project"),i(null),x(!1),b(null),v(null),f(!1),M(!1),y(new Map)},[n]),s.useEffect(()=>{R.current||P||D||(S.length>0?l("project"):F.length>0&&l("tasks"),R.current=!0)},[F.length,P,S.length,D]);const $=s.useMemo(()=>{const t=new Map;for(const r of F){const u=t.get(r.taskId)||[];t.set(r.taskId,[...u,r])}return Array.from(t.entries()).map(([r,u])=>{const N=[...u].sort((oe,le)=>le.updatedAt.localeCompare(oe.updatedAt));return{taskId:r,taskTitle:N[0]?.taskTitle,documents:N,latestUpdated:N[0]?.updatedAt??""}}).sort((r,u)=>u.latestUpdated.localeCompare(r.latestUpdated))},[F]),H=s.useMemo(()=>{const t=o.trim().toLowerCase();return t?S.filter(r=>{const u=r.path.toLowerCase(),N=r.name.toLowerCase();return u.includes(t)||N.includes(t)}):S},[S,o]);s.useEffect(()=>{if(!d)return;S.some(r=>r.path===d.path)||(i(null),b(null),v(null),f(!1))},[S,d]);const ee=s.useCallback(t=>{m(t.target.value)},[]),se=s.useCallback(()=>{m("")},[]),U=s.useCallback(t=>{l(t)},[]),te=s.useCallback(async t=>{try{const r=await me(t,n);h(r)}catch{c(`Failed to open task ${t}`,"error")}},[n,h,c]),ne=s.useCallback(async t=>{i(t),f(!0),v(null),b(null);const r=E.current+1;E.current=r;try{const u=await he("project",t.path,n);if(E.current!==r)return;b(u.content)}catch(u){if(E.current!==r)return;const N=u instanceof Error?u.message:`Failed to open ${t.path}`;v(N),c(N,"error")}finally{E.current===r&&f(!1)}},[n,c]),ae=s.useCallback(()=>{i(null),b(null),v(null),f(!1)},[]),re=s.useCallback(t=>{y(r=>{const u=new Map(r),N=u.get(t)??!1;return u.set(t,!N),u})},[]),_=a==="project"?I:Z,ce=s.useCallback(async()=>{if(a==="project"){await O();return}await B()},[a,O,B]),Q=a==="project"?H.length:F.length,q=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(T,{size:20}),"Documents"]}),e.jsxs("span",{className:"documents-view-count",children:[Q," result",Q!==1?"s":""]})]}),e.jsxs("div",{className:"documents-controls-row",children:[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:()=>U("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:()=>U("tasks"),children:["Task Documents",e.jsx("span",{className:"documents-tab-count",children:$.length})]})]}),a==="project"&&e.jsxs("button",{className:"btn btn-sm documents-hidden-toggle",onClick:()=>x(t=>!t),"aria-pressed":k,"aria-label":k?"Hide hidden project files":"Show hidden project files",title:k?"Hide hidden files":"Show hidden files",children:[k?e.jsx(fe,{size:14}):e.jsx(pe,{size:14}),k?"Hide Hidden":"Show Hidden"]}),e.jsxs("div",{className:"documents-search",children:[e.jsx(je,{size:16,className:"documents-search-icon"}),e.jsx("input",{type:"text",className:"documents-search-input",placeholder:q,value:o,onChange:ee,"aria-label":q}),o&&e.jsx("button",{className:"documents-search-clear",onClick:se,"aria-label":"Clear search",children:e.jsx(xe,{size:16})})]})]})]}),e.jsx("div",{className:"documents-view-content",children:_?e.jsxs("div",{className:"documents-view-error",children:[e.jsxs("p",{children:["Failed to load ",a==="project"?"project files":"task documents",": ",_]}),e.jsxs("button",{className:"btn btn-primary",onClick:()=>void ce(),"aria-label":"Retry loading documents",children:[e.jsx(we,{size:16}),"Retry"]})]}):a==="project"?D&&S.length===0?e.jsx("div",{className:"documents-view-loading",children:e.jsx("p",{children:"Loading project markdown files…"})}):H.length===0?e.jsx("div",{className:"documents-view-empty",children:o.trim()?e.jsxs("p",{children:['No project markdown files match "',o.trim(),'".']}):e.jsxs(e.Fragment,{children:[e.jsx(T,{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${w?" documents-project-layout--mobile":""}`,children:[(!w||!d)&&e.jsx("aside",{className:"documents-view-sidebar","aria-label":"Project markdown files",children:e.jsx("ul",{className:"markdown-file-list",children:H.map(t=>{const r=d?.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 ne(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:[Ce(t.size)," · ",J(t.mtime)]})]})},t.path)})})}),(!w||d)&&e.jsxs("section",{className:"documents-view-main","aria-label":"Project file content preview",children:[w&&d&&e.jsxs("button",{className:"btn btn-sm documents-mobile-back",onClick:ae,"aria-label":"Back to project files list",children:[e.jsx(ke,{size:14}),"Back to files"]}),d?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:d.path}),e.jsx("button",{className:"btn btn-sm document-mode-toggle",onClick:()=>M(t=>!t),"aria-label":j?"Switch to plain text":"Switch to markdown","aria-pressed":j,title:j?"Switch to plain text":"Switch to markdown",children:j?"Markdown":"Plain"})]}),g?e.jsx("p",{className:"documents-content-state",children:"Loading file content…"}):p?e.jsx("p",{className:"documents-content-state documents-content-state--error",children:p}):j?e.jsx("div",{className:"documents-content-markdown",children:e.jsx("div",{className:"markdown-body",children:e.jsx(X,{remarkPlugins:[V],children:C??""})})}):e.jsx("pre",{className:"document-card-content-text documents-content-viewer-text",children:C??""})]}):e.jsx("div",{className:"documents-view-empty",children:e.jsx("p",{children:"Select a Markdown file to view its content."})})]})]}):P&&F.length===0?e.jsx("div",{className:"documents-view-loading",children:e.jsx("p",{children:"Loading task documents…"})}):$.length===0?e.jsx("div",{className:"documents-view-empty",children:o.trim()?e.jsxs("p",{children:['No task documents match "',o.trim(),'".']}):e.jsxs(e.Fragment,{children:[e.jsx(T,{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:$.map(({taskId:t,taskTitle:r,documents:u})=>e.jsx(ye,{taskId:t,taskTitle:r,documents:u,onOpenTask:te,renderMarkdownStates:A,onToggleMarkdown:re},t))})})})]})}export{ze as DocumentsView};
@@ -1 +1 @@
1
- import{r as a,j as e}from"./vendor-react-K0fH_qHe.js";import{a6 as C,a7 as _,a8 as P,aM as W,aN as G,ab as V,aO as Y,x as J,av as Q,R as Z,az as ee}from"./index-Ba-F8c1g.js";import"./vendor-xterm-DzcZoU0P.js";import"./vendor-codemirror-jBKmHyH0.js";const se=300,te=15e3;function B(r){if(!r.trim())return;const t=Number(r);return Number.isFinite(t)?t:void 0}function A(...r){for(const t of r)if(Array.isArray(t))return t;return[]}function p(r){return typeof r=="object"&&r!==null?r:{}}function K(r){const t=p(r),h=p(t.taskSnapshot);return{id:String(t.id??t.evalId??""),runId:String(t.runId??t.batchId??""),taskId:String(t.taskId??h.taskId??""),taskTitle:String(h.title??t.taskTitle??t.title??"Untitled task"),createdAt:String(t.createdAt??t.timestamp??t.updatedAt??new Date(0).toISOString()),overallScore:typeof t.overallScore=="number"?t.overallScore:null,maxScore:typeof t.maxScore=="number"?t.maxScore:null,categoryScores:A(t.categoryScores,p(t.scores).categories)}}function ae(r){const t=p(r);return{...K(t),rationale:String(t.rationale??t.summary??""),evidence:A(t.evidence,p(t.details).evidence),followUps:A(t.followUps,p(t.recommendations).followUps)}}function re(r){const t=r?.projectId,h=t??"",f=`${P.EVALS_RUNS_PREFIX}${h}`,u=`${P.EVALS_RESULTS_PREFIX}${h}`,v=C(f,{maxAgeMs:_}),S=C(u,{maxAgeMs:_}),m=a.useRef(Array.isArray(v)&&v.length>0||Array.isArray(S)&&S.length>0),[c,E]=a.useState({q:"",runId:"",scoreMin:"",scoreMax:""}),[T,i]=a.useState(()=>Array.isArray(v)?v:[]),[L,R]=a.useState(()=>Array.isArray(S)?S:[]),[d,I]=a.useState(null),[F,s]=a.useState(null),[o,g]=a.useState(0),[b,U]=a.useState(!m.current),[X,q]=a.useState(null),k=a.useRef(0),O=a.useRef(t),w=a.useRef(d);w.current=d;const N=a.useCallback(async()=>{const l=++k.current;m.current||U(!0),q(null);try{const[n,x]=await Promise.all([W({q:c.q||void 0,runId:c.runId||void 0,scoreMin:B(c.scoreMin),scoreMax:B(c.scoreMax),limit:100,offset:0},t),G(t)]);if(l!==k.current)return;const y=A(n.results,n.evals,n.items).map(K);R(y),V(u,y.length>500?y.slice(0,500):y,{maxBytes:5e5}),g(typeof n.count=="number"?n.count:y.length);const $=A(x.runs,x.items).map(z=>{const j=p(z),D=p(j.counts);return{id:String(j.id??""),createdAt:String(j.createdAt??""),completedAt:typeof j.completedAt=="string"?j.completedAt:void 0,status:String(j.status??"pending"),evaluatedTaskCount:typeof D.totalTasks=="number"?D.totalTasks:0}});i($),V(f,$,{maxBytes:5e5}),m.current=!0,w.current&&!y.some(z=>z.id===w.current)&&(I(null),s(null))}catch(n){if(l!==k.current)return;q(n instanceof Error?n.message:"Failed to load evals")}finally{l===k.current&&U(!1)}},[c.q,c.runId,c.scoreMax,c.scoreMin,t,u,f]),M=a.useCallback(async l=>{const n=await Y(l,t),x=n.result??n;s(ae(x))},[t]);a.useEffect(()=>{if(O.current===t)return;O.current=t;const l=C(f,{maxAgeMs:_}),n=C(u,{maxAgeMs:_}),x=Array.isArray(l)&&l.length>0||Array.isArray(n)&&n.length>0;i(Array.isArray(l)?l:[]),R(Array.isArray(n)?n:[]),U(!x),m.current=x},[t,u,f]),a.useEffect(()=>{const l=window.setTimeout(()=>{N()},se);return()=>window.clearTimeout(l)},[N]),a.useEffect(()=>{if(!d){s(null);return}M(d)},[M,d]),a.useEffect(()=>{const l=window.setInterval(()=>{N(),d&&M(d)},te);return()=>window.clearInterval(l)},[M,N,d]);const H=a.useCallback(l=>{w.current=l,I(l)},[]);return{loading:b,error:X,results:L,count:o,runs:T,filters:c,setFilters:E,refresh:N,selectedEvalId:d,setSelectedEvalId:H,selectedEval:F}}function ue({projectId:r,onOpenSettings:t,onOpenTaskDetail:h}){const{loading:f,error:u,results:v,runs:S,filters:m,setFilters:c,selectedEvalId:E,setSelectedEvalId:T,selectedEval:i,refresh:L}=re({projectId:r}),[R,d]=a.useState(!0);a.useEffect(()=>{let s=!1;return J(r).then(o=>{if(s)return;const g=o.evalSettings?.enabled;d(g??!1)}).catch(()=>{s||d(!1)}),()=>{s=!0}},[r]);const I=v.length>0,F=a.useMemo(()=>v.find(s=>s.id===E)??null,[v,E]);return R?e.jsxs("section",{className:"evals-view","data-testid":"evals-view",children:[e.jsxs("div",{className:"evals-list card",children:[e.jsxs("div",{className:"evals-toolbar",children:[e.jsx("input",{className:"input",placeholder:"Search task or rationale",value:m.q,onChange:s=>c(o=>({...o,q:s.target.value}))}),e.jsxs("select",{className:"select",value:m.runId,onChange:s=>c(o=>({...o,runId:s.target.value})),children:[e.jsx("option",{value:"",children:"All runs"}),S.map(s=>e.jsx("option",{value:s.id,children:s.id},s.id))]}),e.jsx("input",{className:"input",placeholder:"Min score",value:m.scoreMin,onChange:s=>c(o=>({...o,scoreMin:s.target.value}))}),e.jsx("input",{className:"input",placeholder:"Max score",value:m.scoreMax,onChange:s=>c(o=>({...o,scoreMax:s.target.value}))}),e.jsx("button",{className:"btn btn-icon",type:"button",onClick:()=>void L(),"aria-label":"Refresh evals",children:e.jsx(Z,{size:16})})]}),f&&e.jsx("p",{className:"evals-state","data-testid":"evals-loading",children:"Loading evals…"}),u&&e.jsx("p",{className:"evals-state evals-state--error",children:u}),!f&&!u&&!I&&e.jsx("p",{className:"evals-state",children:"No evals yet. Scheduled evals review tasks completed since the last run."}),e.jsx("ul",{className:"evals-results","data-testid":"evals-results",children:v.map(s=>e.jsx("li",{children:e.jsxs("button",{className:`evals-result ${s.id===E?"evals-result--active":""}`,type:"button",onClick:()=>T(s.id),children:[e.jsx("span",{className:"evals-result-title",children:s.taskTitle}),e.jsxs("span",{className:"evals-result-meta",children:[s.taskId," · ",s.runId," · ",s.overallScore??"n/a"]})]})},s.id))})]}),e.jsxs("div",{className:"evals-detail card","data-testid":"evals-detail",children:[!i&&e.jsx("p",{className:"evals-state",children:"Select an evaluation to inspect scores, rationale, and evidence."}),i&&e.jsxs(e.Fragment,{children:[e.jsx("h3",{className:"evals-detail-title",children:F?.taskTitle??i.taskTitle}),e.jsxs("p",{className:"evals-result-meta",children:[i.taskId," · ",i.runId]}),e.jsxs("p",{className:"evals-score",children:["Overall score: ",i.overallScore??"n/a"]}),e.jsx("ul",{className:"evals-categories",children:i.categoryScores.map(s=>e.jsxs("li",{children:[s.category,": ",s.finalScore]},s.category))}),e.jsx("p",{className:"evals-rationale",children:i.rationale||"No rationale recorded."}),e.jsxs("div",{children:[e.jsx("h4",{children:"Evidence"}),e.jsx("ul",{className:"evals-links",children:i.evidence.map((s,o)=>{const g=typeof s.metadata?.taskId=="string"?s.metadata.taskId:void 0,b=typeof s.metadata?.url=="string"?s.metadata.url:void 0;return e.jsx("li",{children:g?e.jsx("button",{type:"button",className:"btn",onClick:()=>h?.(g),children:s.ref}):b?e.jsxs("a",{href:b,target:"_blank",rel:"noreferrer",className:"evals-external-link",children:[s.ref,e.jsx(ee,{size:14})]}):e.jsx("span",{children:s.ref})},`${s.ref}-${o}`)})})]}),e.jsxs("div",{children:[e.jsx("h4",{children:"Suggested follow-up tasks"}),e.jsxs("ul",{className:"evals-follow-ups",children:[i.followUps.length===0&&e.jsx("li",{children:"None"}),i.followUps.map(s=>e.jsxs("li",{children:[e.jsx("strong",{children:s.title}),e.jsx("p",{children:s.rationale})]},s.suggestionId))]})]})]})]})]}):e.jsxs("section",{className:"evals-view card","data-testid":"evals-disabled",children:[e.jsx("h2",{className:"evals-title",children:"Scheduled evals are disabled"}),e.jsx("p",{className:"evals-empty-copy",children:"Enable Scheduled Evals to review scored tasks, evidence, and follow-up recommendations."}),e.jsxs("button",{className:"btn btn-primary",type:"button",onClick:()=>t?.("scheduled-evals"),children:[e.jsx(Q,{size:16}),"Open Scheduled Evals Settings"]})]})}export{ue as EvalsView};
1
+ import{r as a,j as e}from"./vendor-react-K0fH_qHe.js";import{a7 as C,a8 as _,a9 as D,aO as W,aP as G,ac as V,aQ as Q,x as Y,aw as J,R as Z,aA as ee}from"./index-tJzhtiGM.js";import"./vendor-xterm-DzcZoU0P.js";import"./vendor-codemirror-jBKmHyH0.js";const se=300,te=15e3;function B(r){if(!r.trim())return;const t=Number(r);return Number.isFinite(t)?t:void 0}function N(...r){for(const t of r)if(Array.isArray(t))return t;return[]}function p(r){return typeof r=="object"&&r!==null?r:{}}function K(r){const t=p(r),h=p(t.taskSnapshot);return{id:String(t.id??t.evalId??""),runId:String(t.runId??t.batchId??""),taskId:String(t.taskId??h.taskId??""),taskTitle:String(h.title??t.taskTitle??t.title??"Untitled task"),createdAt:String(t.createdAt??t.timestamp??t.updatedAt??new Date(0).toISOString()),overallScore:typeof t.overallScore=="number"?t.overallScore:null,maxScore:typeof t.maxScore=="number"?t.maxScore:null,categoryScores:N(t.categoryScores,p(t.scores).categories)}}function ae(r){const t=p(r);return{...K(t),rationale:String(t.rationale??t.summary??""),evidence:N(t.evidence,p(t.details).evidence),followUps:N(t.followUps,p(t.recommendations).followUps)}}function re(r){const t=r?.projectId,h=t??"",f=`${D.EVALS_RUNS_PREFIX}${h}`,u=`${D.EVALS_RESULTS_PREFIX}${h}`,v=C(f,{maxAgeMs:_}),S=C(u,{maxAgeMs:_}),m=a.useRef(Array.isArray(v)&&v.length>0||Array.isArray(S)&&S.length>0),[c,E]=a.useState({q:"",runId:"",scoreMin:"",scoreMax:""}),[T,i]=a.useState(()=>Array.isArray(v)?v:[]),[L,R]=a.useState(()=>Array.isArray(S)?S:[]),[d,I]=a.useState(null),[F,s]=a.useState(null),[o,g]=a.useState(0),[b,U]=a.useState(!m.current),[X,z]=a.useState(null),k=a.useRef(0),O=a.useRef(t),w=a.useRef(d);w.current=d;const A=a.useCallback(async()=>{const l=++k.current;m.current||U(!0),z(null);try{const[n,x]=await Promise.all([W({q:c.q||void 0,runId:c.runId||void 0,scoreMin:B(c.scoreMin),scoreMax:B(c.scoreMax),limit:100,offset:0},t),G(t)]);if(l!==k.current)return;const y=N(n.results,n.evals,n.items).map(K);R(y),V(u,y.length>500?y.slice(0,500):y,{maxBytes:5e5}),g(typeof n.count=="number"?n.count:y.length);const $=N(x.runs,x.items).map(q=>{const j=p(q),P=p(j.counts);return{id:String(j.id??""),createdAt:String(j.createdAt??""),completedAt:typeof j.completedAt=="string"?j.completedAt:void 0,status:String(j.status??"pending"),evaluatedTaskCount:typeof P.totalTasks=="number"?P.totalTasks:0}});i($),V(f,$,{maxBytes:5e5}),m.current=!0,w.current&&!y.some(q=>q.id===w.current)&&(I(null),s(null))}catch(n){if(l!==k.current)return;z(n instanceof Error?n.message:"Failed to load evals")}finally{l===k.current&&U(!1)}},[c.q,c.runId,c.scoreMax,c.scoreMin,t,u,f]),M=a.useCallback(async l=>{const n=await Q(l,t),x=n.result??n;s(ae(x))},[t]);a.useEffect(()=>{if(O.current===t)return;O.current=t;const l=C(f,{maxAgeMs:_}),n=C(u,{maxAgeMs:_}),x=Array.isArray(l)&&l.length>0||Array.isArray(n)&&n.length>0;i(Array.isArray(l)?l:[]),R(Array.isArray(n)?n:[]),U(!x),m.current=x},[t,u,f]),a.useEffect(()=>{const l=window.setTimeout(()=>{A()},se);return()=>window.clearTimeout(l)},[A]),a.useEffect(()=>{if(!d){s(null);return}M(d)},[M,d]),a.useEffect(()=>{const l=window.setInterval(()=>{A(),d&&M(d)},te);return()=>window.clearInterval(l)},[M,A,d]);const H=a.useCallback(l=>{w.current=l,I(l)},[]);return{loading:b,error:X,results:L,count:o,runs:T,filters:c,setFilters:E,refresh:A,selectedEvalId:d,setSelectedEvalId:H,selectedEval:F}}function ue({projectId:r,onOpenSettings:t,onOpenTaskDetail:h}){const{loading:f,error:u,results:v,runs:S,filters:m,setFilters:c,selectedEvalId:E,setSelectedEvalId:T,selectedEval:i,refresh:L}=re({projectId:r}),[R,d]=a.useState(!0);a.useEffect(()=>{let s=!1;return Y(r).then(o=>{if(s)return;const g=o.evalSettings?.enabled;d(g??!1)}).catch(()=>{s||d(!1)}),()=>{s=!0}},[r]);const I=v.length>0,F=a.useMemo(()=>v.find(s=>s.id===E)??null,[v,E]);return R?e.jsxs("section",{className:"evals-view","data-testid":"evals-view",children:[e.jsxs("div",{className:"evals-list card",children:[e.jsxs("div",{className:"evals-toolbar",children:[e.jsx("input",{className:"input",placeholder:"Search task or rationale",value:m.q,onChange:s=>c(o=>({...o,q:s.target.value}))}),e.jsxs("select",{className:"select",value:m.runId,onChange:s=>c(o=>({...o,runId:s.target.value})),children:[e.jsx("option",{value:"",children:"All runs"}),S.map(s=>e.jsx("option",{value:s.id,children:s.id},s.id))]}),e.jsx("input",{className:"input",placeholder:"Min score",value:m.scoreMin,onChange:s=>c(o=>({...o,scoreMin:s.target.value}))}),e.jsx("input",{className:"input",placeholder:"Max score",value:m.scoreMax,onChange:s=>c(o=>({...o,scoreMax:s.target.value}))}),e.jsx("button",{className:"btn btn-icon",type:"button",onClick:()=>void L(),"aria-label":"Refresh evals",children:e.jsx(Z,{size:16})})]}),f&&e.jsx("p",{className:"evals-state","data-testid":"evals-loading",children:"Loading evals…"}),u&&e.jsx("p",{className:"evals-state evals-state--error",children:u}),!f&&!u&&!I&&e.jsx("p",{className:"evals-state",children:"No evals yet. Scheduled evals review tasks completed since the last run."}),e.jsx("ul",{className:"evals-results","data-testid":"evals-results",children:v.map(s=>e.jsx("li",{children:e.jsxs("button",{className:`evals-result ${s.id===E?"evals-result--active":""}`,type:"button",onClick:()=>T(s.id),children:[e.jsx("span",{className:"evals-result-title",children:s.taskTitle}),e.jsxs("span",{className:"evals-result-meta",children:[s.taskId," · ",s.runId," · ",s.overallScore??"n/a"]})]})},s.id))})]}),e.jsxs("div",{className:"evals-detail card","data-testid":"evals-detail",children:[!i&&e.jsx("p",{className:"evals-state",children:"Select an evaluation to inspect scores, rationale, and evidence."}),i&&e.jsxs(e.Fragment,{children:[e.jsx("h3",{className:"evals-detail-title",children:F?.taskTitle??i.taskTitle}),e.jsxs("p",{className:"evals-result-meta",children:[i.taskId," · ",i.runId]}),e.jsxs("p",{className:"evals-score",children:["Overall score: ",i.overallScore??"n/a"]}),e.jsx("ul",{className:"evals-categories",children:i.categoryScores.map(s=>e.jsxs("li",{children:[s.category,": ",s.finalScore]},s.category))}),e.jsx("p",{className:"evals-rationale",children:i.rationale||"No rationale recorded."}),e.jsxs("div",{children:[e.jsx("h4",{children:"Evidence"}),e.jsx("ul",{className:"evals-links",children:i.evidence.map((s,o)=>{const g=typeof s.metadata?.taskId=="string"?s.metadata.taskId:void 0,b=typeof s.metadata?.url=="string"?s.metadata.url:void 0;return e.jsx("li",{children:g?e.jsx("button",{type:"button",className:"btn",onClick:()=>h?.(g),children:s.ref}):b?e.jsxs("a",{href:b,target:"_blank",rel:"noreferrer",className:"evals-external-link",children:[s.ref,e.jsx(ee,{size:14})]}):e.jsx("span",{children:s.ref})},`${s.ref}-${o}`)})})]}),e.jsxs("div",{children:[e.jsx("h4",{children:"Suggested follow-up tasks"}),e.jsxs("ul",{className:"evals-follow-ups",children:[i.followUps.length===0&&e.jsx("li",{children:"None"}),i.followUps.map(s=>e.jsxs("li",{children:[e.jsx("strong",{children:s.title}),e.jsx("p",{children:s.rationale})]},s.suggestionId))]})]})]})]})]}):e.jsxs("section",{className:"evals-view card","data-testid":"evals-disabled",children:[e.jsx("h2",{className:"evals-title",children:"Scheduled evals are disabled"}),e.jsx("p",{className:"evals-empty-copy",children:"Enable Scheduled Evals to review scored tasks, evidence, and follow-up recommendations."}),e.jsxs("button",{className:"btn btn-primary",type:"button",onClick:()=>t?.("scheduled-evals"),children:[e.jsx(J,{size:16}),"Open Scheduled Evals Settings"]})]})}export{ue as EvalsView};
@@ -1,4 +1,4 @@
1
- import{r as s,j as e}from"./vendor-react-K0fH_qHe.js";import{bv as L,et as F,eu as H,ev as V,ew as U,ex as K}from"./index-Ba-F8c1g.js";function fe({value:o,onChange:u,projectId:h,disabled:m=!1,id:g,label:w="Skills"}){const[k,l]=s.useState([]),[c,f]=s.useState(!0);s.useEffect(()=>{let n=!1;return f(!0),L(h).then(p=>{n||l(p)}).catch(()=>{n||l([])}).finally(()=>{n||f(!1)}),()=>{n=!0}},[h]);const j=n=>{o.includes(n)||u([...o,n])},d=n=>{u(o.filter(p=>p!==n))},I=n=>k.find(S=>S.id===n)?.name??n,x=k.filter(n=>!o.includes(n.id));return e.jsxs("div",{className:"skill-multiselect","data-testid":"skill-multiselect",children:[w&&e.jsx("label",{htmlFor:g?`${g}-select`:void 0,className:"skill-multiselect-label",children:w}),o.length>0&&e.jsx("div",{className:"skill-multiselect-chips","data-testid":"skill-chips",children:o.map(n=>e.jsxs("span",{className:"skill-chip","data-testid":`skill-chip-${n}`,children:[e.jsx("span",{className:"skill-chip-name",children:I(n)}),e.jsx("button",{type:"button",className:"skill-chip-remove",onClick:()=>d(n),disabled:m,"aria-label":`Remove ${I(n)}`,"data-testid":`remove-skill-${n}`,children:"×"})]},n))}),e.jsx("div",{className:"skill-multiselect-add",children:c?e.jsx("span",{className:"skill-multiselect-loading","data-testid":"skills-loading",children:"Loading skills…"}):x.length===0?e.jsx("span",{className:"skill-multiselect-empty","data-testid":"skills-empty",children:o.length===0?"No skills discovered":"All skills selected"}):e.jsxs("select",{id:g?`${g}-select`:void 0,className:"select skill-multiselect-dropdown",value:"",onChange:n=>{n.target.value&&(j(n.target.value),n.target.value="")},disabled:m,"data-testid":"skill-dropdown",children:[e.jsx("option",{value:"",children:"Add a skill…"}),x.map(n=>e.jsx("option",{value:n.id,children:n.name},n.id))]})})]})}const B=/(?:^|\/)skills\/([^/]+)\/SKILL\.md$/i;function ye(o){const u=o.trim();if(!u)return o;const h=u.match(B);return h?.[1]?h[1]:u}const Q=`# Soul: Chief Executive Officer
1
+ import{r as s,j as e}from"./vendor-react-K0fH_qHe.js";import{bN as F,eD as L,eE as H,eF as V,eG as U,eH as K}from"./index-tJzhtiGM.js";function fe({value:o,onChange:u,projectId:h,disabled:m=!1,id:g,label:w="Skills"}){const[k,l]=s.useState([]),[c,f]=s.useState(!0);s.useEffect(()=>{let n=!1;return f(!0),F(h).then(p=>{n||l(p)}).catch(()=>{n||l([])}).finally(()=>{n||f(!1)}),()=>{n=!0}},[h]);const j=n=>{o.includes(n)||u([...o,n])},d=n=>{u(o.filter(p=>p!==n))},I=n=>k.find(S=>S.id===n)?.name??n,x=k.filter(n=>!o.includes(n.id));return e.jsxs("div",{className:"skill-multiselect","data-testid":"skill-multiselect",children:[w&&e.jsx("label",{htmlFor:g?`${g}-select`:void 0,className:"skill-multiselect-label",children:w}),o.length>0&&e.jsx("div",{className:"skill-multiselect-chips","data-testid":"skill-chips",children:o.map(n=>e.jsxs("span",{className:"skill-chip","data-testid":`skill-chip-${n}`,children:[e.jsx("span",{className:"skill-chip-name",children:I(n)}),e.jsx("button",{type:"button",className:"skill-chip-remove",onClick:()=>d(n),disabled:m,"aria-label":`Remove ${I(n)}`,"data-testid":`remove-skill-${n}`,children:"×"})]},n))}),e.jsx("div",{className:"skill-multiselect-add",children:c?e.jsx("span",{className:"skill-multiselect-loading","data-testid":"skills-loading",children:"Loading skills…"}):x.length===0?e.jsx("span",{className:"skill-multiselect-empty","data-testid":"skills-empty",children:o.length===0?"No skills discovered":"All skills selected"}):e.jsxs("select",{id:g?`${g}-select`:void 0,className:"select skill-multiselect-dropdown",value:"",onChange:n=>{n.target.value&&(j(n.target.value),n.target.value="")},disabled:m,"data-testid":"skill-dropdown",children:[e.jsx("option",{value:"",children:"Add a skill…"}),x.map(n=>e.jsx("option",{value:n.id,children:n.name},n.id))]})})]})}const B=/(?:^|\/)skills\/([^/]+)\/SKILL\.md$/i;function ye(o){const u=o.trim();if(!u)return o;const h=u.match(B);return h?.[1]?h[1]:u}const Q=`# Soul: Chief Executive Officer
2
2
 
3
3
  I am a strategic leader who connects every decision to business outcomes.
4
4
 
@@ -496,4 +496,4 @@ Include relevant context files for the executor to read first.`},{id:"reviewer",
496
496
  Verify error handling is explicit and informative, not silent failures.
497
497
  Ensure new code follows existing patterns and conventions in the codebase.
498
498
  Look for missing tests on new logic paths, especially edge cases.
499
- Flag performance concerns only when they have measurable impact.`}];function ve({isOpen:o,onClose:u,onUseDraft:h,projectId:m,existingAgents:g,mode:w="create",existingAgentConfig:k}){const[l,c]=s.useState("initial"),[f,j]=s.useState(""),[d,I]=s.useState(null),[x,n]=s.useState(""),[p,S]=s.useState("answer"),[A,P]=s.useState(""),[t,O]=s.useState(null),[q,y]=s.useState(null),[D,T]=s.useState([]),E=w==="edit",N=s.useCallback(()=>{c("initial"),j(""),I(null),n(""),S("answer"),P(""),O(null),y(null),T([])},[]),M=s.useMemo(()=>he.map(i=>({id:i.id,label:i.name,description:i.description})),[]);s.useEffect(()=>{if(!d)return;const i=F(d,m,{onThinking:r=>{T(R=>{const b=[...R],C=b[b.length-1];return C&&!C.question?(b[b.length-1]={...C,thinkingOutput:`${C.thinkingOutput??""}${r}`},b):[...b,{response:{},thinkingOutput:r}]})},onQuestion:r=>{n(r.question),S(r.id),c("question")},onSummary:r=>{O(r),c("summary")},onError:r=>{y(r),c("error")}});return()=>i.close()},[d,m]);const v=async()=>{try{d&&await V(d,m)}catch{}finally{N(),u()}};if(s.useEffect(()=>{o||N()},[o,N]),!o)return null;const a=i=>i==null||i===""?e.jsx("em",{className:"experimental-agent-onboarding-modal__summary-empty",children:"Not set"}):e.jsx("span",{children:i}),W=async()=>{c("loading"),y(null);try{const i=await U(f,{mode:w,existingAgentConfig:k,existingAgents:g.map(r=>({id:r.id,name:r.name,role:r.role})),templates:M},m);I(i.sessionId)}catch(i){y(i.message),c("error")}},_=async()=>{if(d){c("loading"),y(null);try{const i={[p]:A};T(r=>[...r,{question:{id:p,type:"text",question:x},response:i}]),await K(d,i,m),P("")}catch(i){y(i.message),c("error")}}},z=async()=>{t&&(h(t),await v())};return e.jsx("div",{className:"modal-overlay open",role:"presentation",children:e.jsxs("div",{className:"modal modal-lg experimental-agent-onboarding-modal",role:"dialog","aria-modal":"true","aria-label":"AI Interview",children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h3",{children:"AI Interview"}),e.jsx("button",{className:"modal-close",onClick:()=>void v(),"aria-label":"Close",children:"×"})]}),D.length>0&&e.jsx(H,{entries:D}),l==="initial"&&e.jsxs("div",{className:"form-group",children:[e.jsx("label",{htmlFor:"agent-onboarding-intent",children:E?"What should this agent change or improve?":"What should this new agent own?"}),e.jsx("textarea",{id:"agent-onboarding-intent",className:"input experimental-agent-onboarding-modal__textarea",value:f,onChange:i=>j(i.target.value)}),e.jsxs("div",{className:"modal-actions",children:[e.jsx("button",{className:"btn",onClick:()=>void v(),children:"Cancel"}),e.jsx("button",{className:"btn btn-primary",disabled:!f.trim(),onClick:()=>void W(),children:E?"Start interview":"Start onboarding"})]})]}),(l==="loading"||l==="question")&&e.jsxs("div",{className:"form-group",children:[e.jsx("label",{htmlFor:"agent-onboarding-answer",children:x||"Thinking..."}),e.jsx("textarea",{id:"agent-onboarding-answer",className:"input experimental-agent-onboarding-modal__textarea",value:A,onChange:i=>P(i.target.value)}),e.jsxs("div",{className:"modal-actions",children:[e.jsx("button",{className:"btn",onClick:()=>void v(),children:"Cancel"}),e.jsx("button",{className:"btn btn-primary",disabled:l==="loading"||!A.trim(),onClick:()=>void _(),children:"Continue"})]})]}),l==="summary"&&t&&e.jsxs("div",{className:"form-group",children:[e.jsx("label",{children:E?"Updated draft ready for review":"Draft ready for review"}),e.jsx("p",{className:"experimental-agent-onboarding-modal__summary-intro",children:"Review this generated draft. Nothing is applied until you confirm."}),e.jsxs("div",{className:"experimental-agent-onboarding-modal__summary card",children:[e.jsxs("div",{className:"experimental-agent-onboarding-modal__summary-section",children:[e.jsx("h4",{children:"Identity"}),e.jsxs("dl",{className:"experimental-agent-onboarding-modal__summary-list",children:[e.jsxs("div",{children:[e.jsx("dt",{children:"Name"}),e.jsx("dd",{children:a(t.name)})]}),e.jsxs("div",{children:[e.jsx("dt",{children:"Role"}),e.jsx("dd",{children:a(t.role)})]}),e.jsxs("div",{children:[e.jsx("dt",{children:"Title"}),e.jsx("dd",{children:a(t.title)})]}),e.jsxs("div",{children:[e.jsx("dt",{children:"Icon"}),e.jsx("dd",{children:a(t.icon)})]}),e.jsxs("div",{children:[e.jsx("dt",{children:"Reports To"}),e.jsx("dd",{children:a(t.reportsTo)})]})]})]}),e.jsxs("div",{className:"experimental-agent-onboarding-modal__summary-section",children:[e.jsx("h4",{children:"Configuration"}),e.jsxs("dl",{className:"experimental-agent-onboarding-modal__summary-list",children:[e.jsxs("div",{children:[e.jsx("dt",{children:"Inline Instructions"}),e.jsx("dd",{className:"experimental-agent-onboarding-modal__summary-block",children:a(t.instructionsText)})]}),e.jsxs("div",{children:[e.jsx("dt",{children:"Soul"}),e.jsx("dd",{className:"experimental-agent-onboarding-modal__summary-block",children:a(t.soul)})]}),e.jsxs("div",{children:[e.jsx("dt",{children:"Agent Memory"}),e.jsx("dd",{className:"experimental-agent-onboarding-modal__summary-block",children:a(t.memory)})]}),e.jsxs("div",{children:[e.jsx("dt",{children:"Skills"}),e.jsx("dd",{children:a(t.skills?.join(", "))})]}),e.jsxs("div",{children:[e.jsx("dt",{children:"Thinking Level"}),e.jsx("dd",{children:a(t.thinkingLevel)})]}),e.jsxs("div",{children:[e.jsx("dt",{children:"Max Turns"}),e.jsx("dd",{children:a(t.maxTurns)})]}),e.jsxs("div",{children:[e.jsx("dt",{children:"Template"}),e.jsx("dd",{children:a(t.templateId)})]}),e.jsxs("div",{children:[e.jsx("dt",{children:"Pattern Agent"}),e.jsx("dd",{children:a(t.patternAgentId)})]})]})]}),(t.heartbeatProcedurePath||t.heartbeatIntervalMs||t.heartbeatEnabled!==void 0||t.modelHint||t.runtimeHint)&&e.jsxs("div",{className:"experimental-agent-onboarding-modal__summary-section",children:[e.jsx("h4",{children:"Runtime Hints"}),e.jsxs("dl",{className:"experimental-agent-onboarding-modal__summary-list",children:[e.jsxs("div",{children:[e.jsx("dt",{children:"Heartbeat Procedure Path"}),e.jsx("dd",{children:a(t.heartbeatProcedurePath)})]}),e.jsxs("div",{children:[e.jsx("dt",{children:"Heartbeat Interval"}),e.jsx("dd",{children:a(t.heartbeatIntervalMs?`${t.heartbeatIntervalMs}ms`:void 0)})]}),e.jsxs("div",{children:[e.jsx("dt",{children:"Heartbeat Enabled"}),e.jsx("dd",{children:a(t.heartbeatEnabled===void 0?void 0:t.heartbeatEnabled?"yes":"no")})]}),e.jsxs("div",{children:[e.jsx("dt",{children:"Model Hint"}),e.jsx("dd",{children:a(t.modelHint)})]}),e.jsxs("div",{children:[e.jsx("dt",{children:"Runtime Hint"}),e.jsx("dd",{children:a(t.runtimeHint)})]})]})]}),t.rationale&&e.jsxs("div",{className:"experimental-agent-onboarding-modal__summary-section",children:[e.jsx("h4",{children:"Rationale"}),e.jsx("p",{className:"experimental-agent-onboarding-modal__summary-block",children:t.rationale})]})]}),e.jsxs("div",{className:"modal-actions",children:[e.jsx("button",{className:"btn",onClick:()=>void v(),children:"Cancel"}),e.jsx("button",{className:"btn btn-primary",onClick:()=>void z(),children:E?"Apply draft to settings form":"Apply draft to agent form"})]})]}),l==="error"&&q&&e.jsxs("div",{className:"form-group",children:[e.jsx("div",{className:"form-error",children:q}),e.jsx("div",{className:"modal-actions",children:e.jsx("button",{className:"btn",onClick:()=>void v(),children:"Close"})})]})]})})}export{he as A,ve as E,fe as S,ye as f};
499
+ Flag performance concerns only when they have measurable impact.`}];function ve({isOpen:o,onClose:u,onUseDraft:h,projectId:m,existingAgents:g,mode:w="create",existingAgentConfig:k}){const[l,c]=s.useState("initial"),[f,j]=s.useState(""),[d,I]=s.useState(null),[x,n]=s.useState(""),[p,S]=s.useState("answer"),[A,P]=s.useState(""),[t,O]=s.useState(null),[q,y]=s.useState(null),[D,T]=s.useState([]),E=w==="edit",N=s.useCallback(()=>{c("initial"),j(""),I(null),n(""),S("answer"),P(""),O(null),y(null),T([])},[]),M=s.useMemo(()=>he.map(i=>({id:i.id,label:i.name,description:i.description})),[]);s.useEffect(()=>{if(!d)return;const i=L(d,m,{onThinking:r=>{T(R=>{const b=[...R],C=b[b.length-1];return C&&!C.question?(b[b.length-1]={...C,thinkingOutput:`${C.thinkingOutput??""}${r}`},b):[...b,{response:{},thinkingOutput:r}]})},onQuestion:r=>{n(r.question),S(r.id),c("question")},onSummary:r=>{O(r),c("summary")},onError:r=>{y(r),c("error")}});return()=>i.close()},[d,m]);const v=async()=>{try{d&&await V(d,m)}catch{}finally{N(),u()}};if(s.useEffect(()=>{o||N()},[o,N]),!o)return null;const a=i=>i==null||i===""?e.jsx("em",{className:"experimental-agent-onboarding-modal__summary-empty",children:"Not set"}):e.jsx("span",{children:i}),W=async()=>{c("loading"),y(null);try{const i=await U(f,{mode:w,existingAgentConfig:k,existingAgents:g.map(r=>({id:r.id,name:r.name,role:r.role})),templates:M},m);I(i.sessionId)}catch(i){y(i.message),c("error")}},_=async()=>{if(d){c("loading"),y(null);try{const i={[p]:A};T(r=>[...r,{question:{id:p,type:"text",question:x},response:i}]),await K(d,i,m),P("")}catch(i){y(i.message),c("error")}}},z=async()=>{t&&(h(t),await v())};return e.jsx("div",{className:"modal-overlay open",role:"presentation",children:e.jsxs("div",{className:"modal modal-lg experimental-agent-onboarding-modal",role:"dialog","aria-modal":"true","aria-label":"AI Interview",children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h3",{children:"AI Interview"}),e.jsx("button",{className:"modal-close",onClick:()=>void v(),"aria-label":"Close",children:"×"})]}),D.length>0&&e.jsx(H,{entries:D}),l==="initial"&&e.jsxs("div",{className:"form-group",children:[e.jsx("label",{htmlFor:"agent-onboarding-intent",children:E?"What should this agent change or improve?":"What should this new agent own?"}),e.jsx("textarea",{id:"agent-onboarding-intent",className:"input experimental-agent-onboarding-modal__textarea",value:f,onChange:i=>j(i.target.value)}),e.jsxs("div",{className:"modal-actions",children:[e.jsx("button",{className:"btn",onClick:()=>void v(),children:"Cancel"}),e.jsx("button",{className:"btn btn-primary",disabled:!f.trim(),onClick:()=>void W(),children:E?"Start interview":"Start onboarding"})]})]}),(l==="loading"||l==="question")&&e.jsxs("div",{className:"form-group",children:[e.jsx("label",{htmlFor:"agent-onboarding-answer",children:x||"Thinking..."}),e.jsx("textarea",{id:"agent-onboarding-answer",className:"input experimental-agent-onboarding-modal__textarea",value:A,onChange:i=>P(i.target.value)}),e.jsxs("div",{className:"modal-actions",children:[e.jsx("button",{className:"btn",onClick:()=>void v(),children:"Cancel"}),e.jsx("button",{className:"btn btn-primary",disabled:l==="loading"||!A.trim(),onClick:()=>void _(),children:"Continue"})]})]}),l==="summary"&&t&&e.jsxs("div",{className:"form-group",children:[e.jsx("label",{children:E?"Updated draft ready for review":"Draft ready for review"}),e.jsx("p",{className:"experimental-agent-onboarding-modal__summary-intro",children:"Review this generated draft. Nothing is applied until you confirm."}),e.jsxs("div",{className:"experimental-agent-onboarding-modal__summary card",children:[e.jsxs("div",{className:"experimental-agent-onboarding-modal__summary-section",children:[e.jsx("h4",{children:"Identity"}),e.jsxs("dl",{className:"experimental-agent-onboarding-modal__summary-list",children:[e.jsxs("div",{children:[e.jsx("dt",{children:"Name"}),e.jsx("dd",{children:a(t.name)})]}),e.jsxs("div",{children:[e.jsx("dt",{children:"Role"}),e.jsx("dd",{children:a(t.role)})]}),e.jsxs("div",{children:[e.jsx("dt",{children:"Title"}),e.jsx("dd",{children:a(t.title)})]}),e.jsxs("div",{children:[e.jsx("dt",{children:"Icon"}),e.jsx("dd",{children:a(t.icon)})]}),e.jsxs("div",{children:[e.jsx("dt",{children:"Reports To"}),e.jsx("dd",{children:a(t.reportsTo)})]})]})]}),e.jsxs("div",{className:"experimental-agent-onboarding-modal__summary-section",children:[e.jsx("h4",{children:"Configuration"}),e.jsxs("dl",{className:"experimental-agent-onboarding-modal__summary-list",children:[e.jsxs("div",{children:[e.jsx("dt",{children:"Inline Instructions"}),e.jsx("dd",{className:"experimental-agent-onboarding-modal__summary-block",children:a(t.instructionsText)})]}),e.jsxs("div",{children:[e.jsx("dt",{children:"Soul"}),e.jsx("dd",{className:"experimental-agent-onboarding-modal__summary-block",children:a(t.soul)})]}),e.jsxs("div",{children:[e.jsx("dt",{children:"Agent Memory"}),e.jsx("dd",{className:"experimental-agent-onboarding-modal__summary-block",children:a(t.memory)})]}),e.jsxs("div",{children:[e.jsx("dt",{children:"Skills"}),e.jsx("dd",{children:a(t.skills?.join(", "))})]}),e.jsxs("div",{children:[e.jsx("dt",{children:"Thinking Level"}),e.jsx("dd",{children:a(t.thinkingLevel)})]}),e.jsxs("div",{children:[e.jsx("dt",{children:"Max Turns"}),e.jsx("dd",{children:a(t.maxTurns)})]}),e.jsxs("div",{children:[e.jsx("dt",{children:"Template"}),e.jsx("dd",{children:a(t.templateId)})]}),e.jsxs("div",{children:[e.jsx("dt",{children:"Pattern Agent"}),e.jsx("dd",{children:a(t.patternAgentId)})]})]})]}),(t.heartbeatProcedurePath||t.heartbeatIntervalMs||t.heartbeatEnabled!==void 0||t.modelHint||t.runtimeHint)&&e.jsxs("div",{className:"experimental-agent-onboarding-modal__summary-section",children:[e.jsx("h4",{children:"Runtime Hints"}),e.jsxs("dl",{className:"experimental-agent-onboarding-modal__summary-list",children:[e.jsxs("div",{children:[e.jsx("dt",{children:"Heartbeat Procedure Path"}),e.jsx("dd",{children:a(t.heartbeatProcedurePath)})]}),e.jsxs("div",{children:[e.jsx("dt",{children:"Heartbeat Interval"}),e.jsx("dd",{children:a(t.heartbeatIntervalMs?`${t.heartbeatIntervalMs}ms`:void 0)})]}),e.jsxs("div",{children:[e.jsx("dt",{children:"Heartbeat Enabled"}),e.jsx("dd",{children:a(t.heartbeatEnabled===void 0?void 0:t.heartbeatEnabled?"yes":"no")})]}),e.jsxs("div",{children:[e.jsx("dt",{children:"Model Hint"}),e.jsx("dd",{children:a(t.modelHint)})]}),e.jsxs("div",{children:[e.jsx("dt",{children:"Runtime Hint"}),e.jsx("dd",{children:a(t.runtimeHint)})]})]})]}),t.rationale&&e.jsxs("div",{className:"experimental-agent-onboarding-modal__summary-section",children:[e.jsx("h4",{children:"Rationale"}),e.jsx("p",{className:"experimental-agent-onboarding-modal__summary-block",children:t.rationale})]})]}),e.jsxs("div",{className:"modal-actions",children:[e.jsx("button",{className:"btn",onClick:()=>void v(),children:"Cancel"}),e.jsx("button",{className:"btn btn-primary",onClick:()=>void z(),children:E?"Apply draft to settings form":"Apply draft to agent form"})]})]}),l==="error"&&q&&e.jsxs("div",{className:"form-group",children:[e.jsx("div",{className:"form-error",children:q}),e.jsx("div",{className:"modal-actions",children:e.jsx("button",{className:"btn",onClick:()=>void v(),children:"Close"})})]})]})})}export{he as A,ve as E,fe as S,ye as f};
@@ -1 +1 @@
1
- import{j as t,r as g}from"./vendor-react-K0fH_qHe.js";import{J as h}from"./index-Ba-F8c1g.js";import"./vendor-xterm-DzcZoU0P.js";import"./vendor-codemirror-jBKmHyH0.js";const v=5,p=3,x=[{id:"goal-1",title:"Reduce mean review turnaround",status:"active",createdAt:"2026-05-14T09:30:00.000Z"},{id:"goal-2",title:"Raise merge reliability coverage",status:"active",createdAt:"2026-05-15T12:00:00.000Z"},{id:"goal-3",title:"Ship dashboard quality audit",status:"inactive",createdAt:"2026-05-16T08:15:00.000Z"}];function j(n){const[s,i]=g.useState(()=>n??x),[c,o]=g.useState(null),l=g.useMemo(()=>s.filter(e=>e.status==="active").length,[s]);function r(){if(l>=v){o("Cannot activate more than 5 goals. Resolve an active goal before adding another active goal.");return}o(null),i(e=>[...e,{id:`goal-${e.length+1}`,title:`New Goal ${e.length+1}`,status:"active",createdAt:new Date().toISOString()}])}function a(e){const m=s.find(d=>d.id===e);if(!(!m||m.status==="active")){if(l>=v){o("Cannot activate more than 5 goals. Resolve an active goal before activating another.");return}o(null),i(d=>d.map(u=>u.id===e?{...u,status:"active"}:u))}}return{goals:s,activeCount:l,errorMessage:c,addGoal:r,activateGoal:a}}function A({initialGoals:n}){const{goals:s,activeCount:i,errorMessage:c,addGoal:o,activateGoal:l}=j(n),r=i>=p&&i<=v;return t.jsxs("section",{className:"goals-view","data-testid":"goals-view",children:[t.jsxs("header",{className:"goals-header",children:[t.jsxs("div",{children:[t.jsx("h2",{className:"goals-title",children:"Goals"}),t.jsxs("p",{className:"goals-count","data-testid":"goals-active-count",children:[i," active goals"]})]}),t.jsxs("button",{type:"button",className:"btn btn-primary goals-add-button",onClick:o,"data-testid":"goals-add-button",children:[t.jsx(h,{"aria-hidden":"true"}),"Add Goal"]})]}),r?t.jsx("p",{className:"goals-warning",role:"status",children:"Approaching the 5-active goal cap. Keep active goals focused."}):null,c?t.jsx("p",{className:"form-error goals-error",role:"alert",children:c}):null,s.length===0?t.jsx("div",{className:"goals-empty card","data-testid":"goals-empty-state",children:"No goals yet. Add one to begin tracking strategic outcomes."}):t.jsx("div",{className:"goals-list","data-testid":"goals-list",children:s.map(a=>t.jsxs("article",{className:"card goals-card","data-testid":`goal-card-${a.id}`,children:[t.jsxs("div",{className:"goals-card-main",children:[t.jsx("h3",{className:"goals-card-title",children:a.title}),t.jsxs("p",{className:"goals-card-status",children:["Status: ",a.status]})]}),t.jsx("button",{type:"button",className:"btn goals-activate-button",disabled:a.status==="active",onClick:()=>l(a.id),"data-testid":`goal-activate-${a.id}`,children:a.status==="active"?"Active":"Activate"})]},a.id))})]})}export{A as GoalsView};
1
+ import{j as t,r as g}from"./vendor-react-K0fH_qHe.js";import{J as h}from"./index-tJzhtiGM.js";import"./vendor-xterm-DzcZoU0P.js";import"./vendor-codemirror-jBKmHyH0.js";const v=5,p=3,x=[{id:"goal-1",title:"Reduce mean review turnaround",status:"active",createdAt:"2026-05-14T09:30:00.000Z"},{id:"goal-2",title:"Raise merge reliability coverage",status:"active",createdAt:"2026-05-15T12:00:00.000Z"},{id:"goal-3",title:"Ship dashboard quality audit",status:"inactive",createdAt:"2026-05-16T08:15:00.000Z"}];function j(n){const[s,i]=g.useState(()=>n??x),[c,o]=g.useState(null),l=g.useMemo(()=>s.filter(e=>e.status==="active").length,[s]);function r(){if(l>=v){o("Cannot activate more than 5 goals. Resolve an active goal before adding another active goal.");return}o(null),i(e=>[...e,{id:`goal-${e.length+1}`,title:`New Goal ${e.length+1}`,status:"active",createdAt:new Date().toISOString()}])}function a(e){const m=s.find(d=>d.id===e);if(!(!m||m.status==="active")){if(l>=v){o("Cannot activate more than 5 goals. Resolve an active goal before activating another.");return}o(null),i(d=>d.map(u=>u.id===e?{...u,status:"active"}:u))}}return{goals:s,activeCount:l,errorMessage:c,addGoal:r,activateGoal:a}}function A({initialGoals:n}){const{goals:s,activeCount:i,errorMessage:c,addGoal:o,activateGoal:l}=j(n),r=i>=p&&i<=v;return t.jsxs("section",{className:"goals-view","data-testid":"goals-view",children:[t.jsxs("header",{className:"goals-header",children:[t.jsxs("div",{children:[t.jsx("h2",{className:"goals-title",children:"Goals"}),t.jsxs("p",{className:"goals-count","data-testid":"goals-active-count",children:[i," active goals"]})]}),t.jsxs("button",{type:"button",className:"btn btn-primary goals-add-button",onClick:o,"data-testid":"goals-add-button",children:[t.jsx(h,{"aria-hidden":"true"}),"Add Goal"]})]}),r?t.jsx("p",{className:"goals-warning",role:"status",children:"Approaching the 5-active goal cap. Keep active goals focused."}):null,c?t.jsx("p",{className:"form-error goals-error",role:"alert",children:c}):null,s.length===0?t.jsx("div",{className:"goals-empty card","data-testid":"goals-empty-state",children:"No goals yet. Add one to begin tracking strategic outcomes."}):t.jsx("div",{className:"goals-list","data-testid":"goals-list",children:s.map(a=>t.jsxs("article",{className:"card goals-card","data-testid":`goal-card-${a.id}`,children:[t.jsxs("div",{className:"goals-card-main",children:[t.jsx("h3",{className:"goals-card-title",children:a.title}),t.jsxs("p",{className:"goals-card-status",children:["Status: ",a.status]})]}),t.jsx("button",{type:"button",className:"btn goals-activate-button",disabled:a.status==="active",onClick:()=>l(a.id),"data-testid":`goal-activate-${a.id}`,children:a.status==="active"?"Active":"Activate"})]},a.id))})]})}export{A as GoalsView};
@@ -1,4 +1,4 @@
1
- import{r,j as e}from"./vendor-react-K0fH_qHe.js";import{c as Re,a6 as te,a7 as be,a8 as we,aj as Se,ak as Xe,ab as je,al as qe,am as We,an as Ke,ao as Ye,ap as Ve,aq as Je,ar as ke,as as Qe,h as Ze,j as Ce,at as C,A as es,X as Ne,au as ge,R as N,av as ss,m as ts,C as $e,aw as ie,ax as Me,ay as is,J as ze,az as as,aA as _e,aB as ns}from"./index-Ba-F8c1g.js";import{U as Ae}from"./users-DZ_0WcB6.js";import"./vendor-xterm-DzcZoU0P.js";import"./vendor-codemirror-jBKmHyH0.js";/**
1
+ import{r,j as e}from"./vendor-react-K0fH_qHe.js";import{c as Re,a7 as te,a8 as be,a9 as we,ak as Se,al as Xe,ac as je,am as qe,an as We,ao as Ke,ap as Ye,aq as Ve,ar as Je,as as ke,at as Qe,h as Ze,j as Ce,au as C,A as es,X as Ne,av as ge,R as N,aw as ss,m as ts,C as $e,ax as ie,ay as Me,az as is,J as ze,aA as as,aB as _e,aC as ns}from"./index-tJzhtiGM.js";import{U as Ae}from"./users-DoWKt94F.js";import"./vendor-xterm-DzcZoU0P.js";import"./vendor-codemirror-jBKmHyH0.js";/**
2
2
  * @license lucide-react v1.7.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -1,2 +1,2 @@
1
- import{r as a,j as e}from"./vendor-react-K0fH_qHe.js";import{u as Le}from"./SettingsModal-YCJM5is3.js";import{bK as Ee,bL as Me,bM as Ie,y as Re,bN as qe,bO as Pe,bP as _e,bQ as ke,bR as we,bS as We,bT as Oe,bU as Te,bV as Ae,bW as Ue,x as $e,bX as Qe,L as w,bY as Fe}from"./index-Ba-F8c1g.js";import"./vendor-xterm-DzcZoU0P.js";import"./vendor-codemirror-jBKmHyH0.js";const O=".fusion/memory/MEMORY.md",He=5e4,Ye="0 3 * * *",Be="0 4 * * *";function he(i){return{memoryEnabled:i.memoryEnabled!==!1,memoryAutoSummarizeEnabled:i.memoryAutoSummarizeEnabled??!1,memoryAutoSummarizeThresholdChars:i.memoryAutoSummarizeThresholdChars??He,memoryAutoSummarizeSchedule:i.memoryAutoSummarizeSchedule??Ye,memoryDreamsEnabled:i.memoryDreamsEnabled??!1,memoryDreamsSchedule:i.memoryDreamsSchedule??Be}}function De(i,t){return i.some(m=>m.path===t)?t:i.find(m=>m.path===O)?.path??i[0]?.path??O}function Ve(i={}){const{projectId:t}=i,[m,u]=a.useState(""),[C,A]=a.useState(!0),[E,M]=a.useState(!1),[b,x]=a.useState(!1),[r,p]=a.useState(null),[T,Z]=a.useState(!0),[J,L]=a.useState(!1),[S,_]=a.useState(()=>he({})),[F,ee]=a.useState(!0),[ue,U]=a.useState(!1),[o,v]=a.useState([]),[se,I]=a.useState(!0),[c,k]=a.useState(O),[W,y]=a.useState(""),[d,te]=a.useState(!1),[$,f]=a.useState(!1),[ae,Q]=a.useState(!1),[ne,H]=a.useState(!1),[Y,re]=a.useState(!1),[D,z]=a.useState(null),[ye,R]=a.useState(!0),[ge,B]=a.useState(!1),[ie,V]=a.useState(!1),[le,G]=a.useState(null),{status:me,loading:K,refresh:j}=Le({projectId:t}),be=a.useCallback(n=>{y(n),f(!0)},[]),N=a.useCallback(async n=>{te(!0);try{const{content:l}=await Ee(n,t);k(n),y(l),f(!1)}finally{te(!1)}},[t]),q=a.useCallback(async()=>{I(!0);try{const{files:n}=await Me(t);if(v(n),n.length===0){k(O),y(""),f(!1);return}const l=De(n,c);l!==c&&await N(l)}finally{I(!1)}},[t,c,N]);a.useEffect(()=>{let n=!1;async function l(){try{const s=await Ue(t);n||(u(s.content),A(!1))}catch{n||(u(""),A(!1))}}return l(),()=>{n=!0}},[t]),a.useEffect(()=>{let n=!1;async function l(){try{const s=await we(t);n||(p(s.content),L(s.exists),Z(!1))}catch{n||(p(null),L(!1),Z(!1))}}return l(),()=>{n=!0}},[t]),a.useEffect(()=>{let n=!1;async function l(){ee(!0);try{const s=await $e(t);n||_(he(s))}catch{n||_(he({}))}finally{n||ee(!1)}}return l(),()=>{n=!0}},[t]),a.useEffect(()=>{let n=!1;async function l(){I(!0);try{const{files:s}=await Me(t);if(n)return;if(v(s),s.length===0){k(O),y(""),f(!1);return}const h=De(s,c),{content:g}=await Ee(h,t);if(n)return;k(h),y(g),f(!1)}catch{n||(v([]),k(O),y(""),f(!1))}finally{n||I(!1)}}return l(),()=>{n=!0}},[t,c]),a.useEffect(()=>{let n=!1;async function l(){try{const s=await ke(t);n||(z(s),R(!1))}catch{n||(z(null),R(!1))}}return l(),()=>{n=!0}},[t]),a.useEffect(()=>{let n=!1;async function l(){try{const s=await Qe(t);n||G(s)}catch{n||G(null)}}return l(),()=>{n=!0}},[t]);const ce=a.useCallback(n=>{u(n),M(!0)},[]),oe=a.useCallback(async()=>{if(E){x(!0);try{await Ie(m,t),M(!1)}finally{x(!1)}}},[m,E,t]),xe=a.useCallback(async n=>{U(!0);try{const l=await Re(n,t);_(he(l))}finally{U(!1)}},[t]),pe=a.useCallback(async n=>{await N(n)},[N]),fe=a.useCallback(async()=>{if($){Q(!0);try{await qe(c,W,t),f(!1),await q()}finally{Q(!1)}}},[W,$,c,t,q]),je=a.useCallback(async()=>{V(!0);try{const n=await Pe(t);return await j(),n}finally{V(!1)}},[t,j]),Se=a.useCallback(async n=>_e(n,t),[t]),X=a.useCallback(async()=>{try{const n=await ke(t);z(n)}catch{z(null)}},[t]),P=a.useCallback(async()=>{try{const n=await we(t);p(n.content),L(n.exists)}catch{p(null),L(!1)}},[t]),de=a.useCallback(async n=>{await We(n,t),await P()},[t,P]),ve=a.useCallback(async()=>{H(!0);try{const n=await Oe(t);return await Promise.all([P(),X()]),{success:n.success,summary:n.summary}}finally{H(!1)}},[t,P,X]),Ne=a.useCallback(async()=>{re(!0);try{return await Te(t)}finally{re(!1)}},[t]),Ce=a.useCallback(async n=>{B(!0);try{const l=n?await Ae(n,t):await Ae(t);if(n){const s=l.path??n;k(s),y(l.content),f(!1),await q();return}u(l.content),M(!0)}finally{B(!1)}},[t,q]);return{workingMemory:m,workingMemoryLoading:C,workingMemoryDirty:E,setWorkingMemory:ce,saveWorkingMemory:oe,savingWorkingMemory:b,insightsContent:r,insightsLoading:T,insightsExists:J,refreshInsights:P,saveInsights:de,memorySettings:S,settingsLoading:F,savingMemorySettings:ue,saveMemorySettings:xe,memoryFiles:o,memoryFilesLoading:se,selectedFilePath:c,selectedFileContent:W,selectedFileLoading:d,selectedFileDirty:$,setSelectedFileContent:be,selectFile:pe,saveSelectedFile:fe,savingSelectedFile:ae,reloadMemoryFiles:q,backendStatus:me,backendLoading:K,extractInsights:ve,extracting:ne,triggerDreamNow:Ne,dreamRunning:Y,auditReport:D,auditLoading:ye,refreshAudit:X,compactMemory:Ce,compacting:ge,installQmdAction:je,installingQmd:ie,testRetrieval:Se,stats:le}}const Ge={Patterns:"pattern",Principles:"principle",Conventions:"convention",Pitfalls:"pitfall",Context:"context"},Ke={"long-term":"Long-term",daily:"Daily",dreams:"Dreams"},Xe={"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."},Ze=72;function Je(i,t){if(i.length<=t)return i;const m=Math.max(1,t-1),u=Math.ceil(m/2),C=Math.floor(m/2);return`${i.slice(0,u)}…${i.slice(i.length-C)}`}function es(i){const t=`${i.label} — ${i.path}`;return Je(t,Ze)}function ss(i){if(!i)return[];const t=[],m=i.split(/(?=^## )/m);for(const u of m){const C=u.trim();if(!C)continue;const A=C.match(/^##\s+(.+?)(\n|$)/);if(A){const E=A[1].trim(),M=Ge[E]??E.toLowerCase(),b=C.slice(A[0].length).trim(),x=b.split(`
2
- `).map(r=>r.replace(/^-\s+/,"").trim()).filter(r=>r.length>0&&(r.startsWith("- ")||r.startsWith("* ")));(x.length>0||b.length>0)&&t.push({name:E,key:M,items:x.length>0?x:b.length>0?[b]:[],expanded:!0})}}return t}function ts(i){if(!i)return null;const t=i.match(/##\s+Last\s+Updated:\s*(\d{4}-\d{2}-\d{2})/i);return t?t[1]:null}function as(i){return i.reduce((t,m)=>t+m.items.length,0)}function ns(i){switch(i){case"file":return"File (.fusion/memory/, agent/<agent-name>/memory/)";case"readonly":return"Read-Only";case"qmd":return"QMD (Quantized Memory Distillation)";default:return i}}function rs(i){switch(i){case"healthy":return"Healthy";case"warning":return"Warning";case"issues":return"Issues Found"}}function ds({projectId:i,addToast:t}){const[m,u]=a.useState("working"),[C,A]=a.useState(new Set),[E,M]=a.useState(!1),[b,x]=a.useState(null),[r,p]=a.useState({memoryEnabled:!0,memoryAutoSummarizeEnabled:!1,memoryAutoSummarizeThresholdChars:5e4,memoryAutoSummarizeSchedule:"0 3 * * *",memoryDreamsEnabled:!1,memoryDreamsSchedule:"0 4 * * *"}),[T,Z]=a.useState(""),[J,L]=a.useState(!1),[S,_]=a.useState(null),{insightsContent:F,insightsLoading:ee,insightsExists:ue,saveInsights:U,memorySettings:o,settingsLoading:v,saveMemorySettings:se,savingMemorySettings:I,backendStatus:c,backendLoading:k,extractInsights:W,extracting:y,auditReport:d,auditLoading:te,refreshAudit:$,compactMemory:f,compacting:ae,installQmdAction:Q,installingQmd:ne,testRetrieval:H,memoryFiles:Y,memoryFilesLoading:re,selectedFilePath:D,selectedFileContent:z,selectedFileLoading:ye,selectedFileDirty:R,setSelectedFileContent:ge,selectFile:B,saveSelectedFile:ie,savingSelectedFile:V,reloadMemoryFiles:le,triggerDreamNow:G,dreamRunning:me}=Ve({projectId:i});a.useEffect(()=>{p(o)},[o]);const K=a.useMemo(()=>r.memoryEnabled!==o.memoryEnabled||r.memoryAutoSummarizeEnabled!==o.memoryAutoSummarizeEnabled||r.memoryAutoSummarizeThresholdChars!==o.memoryAutoSummarizeThresholdChars||r.memoryAutoSummarizeSchedule!==o.memoryAutoSummarizeSchedule||r.memoryDreamsEnabled!==o.memoryDreamsEnabled||r.memoryDreamsSchedule!==o.memoryDreamsSchedule,[r,o]),j=a.useMemo(()=>Y.find(s=>s.path===D),[Y,D]),be=j?Xe[j.layer]:"Edits the selected memory file.",N=a.useMemo(()=>ss(F),[F]),q=a.useMemo(()=>as(N),[N]),ce=a.useMemo(()=>ts(F),[F]),oe=a.useCallback(s=>{A(h=>{const g=new Set(h);return g.has(s)?g.delete(s):g.add(s),g})},[]),xe=a.useCallback(async s=>{try{await B(s)}catch{t("Failed to load memory file","error")}},[B,t]),pe=a.useCallback(async()=>{try{await ie(),t("Memory saved","success")}catch{t("Failed to save memory","error")}},[ie,t]),fe=a.useCallback(async()=>{if(!K)return;const s={};r.memoryEnabled!==o.memoryEnabled&&(s.memoryEnabled=r.memoryEnabled),r.memoryAutoSummarizeEnabled!==o.memoryAutoSummarizeEnabled&&(s.memoryAutoSummarizeEnabled=r.memoryAutoSummarizeEnabled),r.memoryAutoSummarizeThresholdChars!==o.memoryAutoSummarizeThresholdChars&&(s.memoryAutoSummarizeThresholdChars=r.memoryAutoSummarizeThresholdChars),r.memoryAutoSummarizeSchedule!==o.memoryAutoSummarizeSchedule&&(s.memoryAutoSummarizeSchedule=r.memoryAutoSummarizeSchedule),r.memoryDreamsEnabled!==o.memoryDreamsEnabled&&(s.memoryDreamsEnabled=r.memoryDreamsEnabled),r.memoryDreamsSchedule!==o.memoryDreamsSchedule&&(s.memoryDreamsSchedule=r.memoryDreamsSchedule);try{await se(s),t("Memory settings saved","success")}catch{t("Failed to save memory settings","error")}},[K,r,o,se,t]),je=a.useCallback(async()=>{try{const s=await Q();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")}},[Q,t]),Se=a.useCallback(async()=>{L(!0),_(null);try{const s=await H(T);_(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{L(!1)}},[T,H,t]),X=a.useCallback(async()=>{try{await G(),t("Dream processing completed","success"),await le()}catch(s){t(s instanceof Error?s.message:"Failed to run dream processing","error")}},[G,le,t]),P=a.useCallback(async()=>{try{await f(D),t("Memory file compacted","success")}catch{t("Failed to compact memory","error")}},[f,D,t]),de=a.useCallback(async()=>{try{const s=await W();t(s.summary,"success")}catch(s){t(s instanceof Error?s.message:"Failed to extract insights","error")}},[W,t]),ve=a.useCallback(async()=>{if(b!==null)try{await U(b),M(!1),x(null),t("Insights saved","success")}catch{t("Failed to save insights","error")}},[b,U,t]),Ne=a.useCallback(()=>{x(F??""),M(!0)},[F]),Ce=a.useCallback(()=>{M(!1),x(null)},[]),n=!k&&c!==null,l=c?.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":m==="working",className:`memory-view-tab${m==="working"?" memory-view-tab--active":""}`,onClick:()=>u("working"),"data-testid":"memory-tab-working",children:"Working Memory"}),e.jsx("button",{type:"button",role:"tab","aria-selected":m==="insights",className:`memory-view-tab${m==="insights"?" memory-view-tab--active":""}`,onClick:()=>u("insights"),"data-testid":"memory-tab-insights",children:"Insights"}),e.jsx("button",{type:"button",role:"tab","aria-selected":m==="engines",className:`memory-view-tab${m==="engines"?" memory-view-tab--active":""}`,onClick:()=>u("engines"),"data-testid":"memory-tab-engines",children:"Engines"})]}),e.jsxs("div",{className:"memory-view-content",children:[m==="working"&&e.jsxs("div",{className:"memory-working-tab",children:[n&&!l&&e.jsx("div",{className:"memory-readonly-banner",children:"This memory backend is read-only. Changes cannot be saved."}),re||ye?e.jsxs("div",{className:"memory-empty-state",children:[e.jsx(w,{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:D,onChange:s=>{xe(s.target.value)},disabled:R,children:Y.map(s=>e.jsx("option",{value:s.path,title:`${s.label} — ${s.path}`,children:es(s)},s.path))}),e.jsx("small",{children:R?"Save or discard the current edits before switching files.":"Choose any project memory file to view or edit."})]}),j&&e.jsxs("div",{className:"memory-file-summary",children:[e.jsx("span",{children:Ke[j.layer]}),e.jsx("strong",{children:j.path}),e.jsxs("small",{children:[j.size.toLocaleString()," bytes · updated ",new Date(j.updatedAt).toLocaleString()]})]}),e.jsxs("div",{className:"form-group memory-editor-form-group",children:[e.jsx("label",{children:j?.label||"Memory Editor"}),e.jsx("small",{children:be}),e.jsx("div",{className:"memory-editor-container",children:e.jsx(Fe,{content:z,onChange:ge,readOnly:!l,filePath:D})})]})]}),e.jsxs("div",{className:"memory-action-bar",children:[e.jsxs("span",{className:"memory-char-count",children:[z.length," characters"]}),e.jsx("div",{className:"memory-flex-spacer"}),l&&z.length>0&&e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:P,disabled:ae||R,children:ae?e.jsxs(e.Fragment,{children:[e.jsx(w,{size:14,className:"animate-spin"}),"Compacting…"]}):"Compact Selected File"}),R&&l&&e.jsx("button",{type:"button",className:"btn btn-primary btn-sm",onClick:pe,disabled:V,children:V?e.jsxs(e.Fragment,{children:[e.jsx(w,{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:r.memoryDreamsEnabled,onChange:s=>{p(h=>({...h,memoryDreamsEnabled:s.target.checked}))},disabled:!r.memoryEnabled||v}),"Process dreams from daily memory"]}),e.jsx("small",{children:"Turns daily notes into DREAMS.md and promotes reusable lessons into MEMORY.md."})]}),r.memoryEnabled&&r.memoryDreamsEnabled&&e.jsxs(e.Fragment,{children:[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:r.memoryDreamsSchedule,onChange:s=>{p(h=>({...h,memoryDreamsSchedule:s.target.value}))},placeholder:"0 4 * * *",disabled:v}),e.jsx("small",{children:"Cron expression for dream processing."})]}),e.jsxs("div",{className:"form-group",children:[e.jsx("button",{type:"button",className:"btn btn-sm",onClick:X,disabled:me||!r.memoryDreamsEnabled,children:me?e.jsxs(e.Fragment,{children:[e.jsx(w,{size:14,className:"animate-spin"}),"Dreaming…"]}):"Dream Now"}),e.jsx("small",{children:"Manually trigger dream processing now."})]})]})]}),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:r.memoryAutoSummarizeEnabled,onChange:s=>{p(h=>({...h,memoryAutoSummarizeEnabled:s.target.checked}))},disabled:!r.memoryEnabled||v}),"Auto-Summarize Memory"]}),e.jsx("small",{children:"Automatically compact memory when it exceeds the threshold on a schedule"})]}),r.memoryEnabled&&r.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:r.memoryAutoSummarizeThresholdChars,onChange:s=>{p(h=>({...h,memoryAutoSummarizeThresholdChars:parseInt(s.target.value,10)||5e4}))},min:1e3,disabled:v}),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:r.memoryAutoSummarizeSchedule,onChange:s=>{p(h=>({...h,memoryAutoSummarizeSchedule:s.target.value}))},placeholder:"0 3 * * *",disabled:v}),e.jsx("small",{children:"Cron expression for auto-summarize schedule (default: daily at 3 AM)"})]})]})]}),!r.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:fe,disabled:I||v,children:I?e.jsxs(e.Fragment,{children:[e.jsx(w,{size:14,className:"animate-spin"}),"Saving…"]}):"Save Settings"})})]})]})]}),m==="insights"&&e.jsx("div",{className:"memory-insights-tab",children:ee?e.jsxs("div",{className:"memory-empty-state",children:[e.jsx(w,{size:20,className:"animate-spin"}),e.jsx("span",{children:"Loading insights…"})]}):E?e.jsxs("div",{className:"memory-insights-editor-layout",children:[e.jsx("div",{className:"memory-editor-container",children:e.jsx(Fe,{content:b??"",onChange:x,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:Ce,children:"Cancel"}),e.jsx("button",{type:"button",className:"btn btn-primary btn-sm",onClick:ve,children:"Save Insights"})]})]}):!ue||N.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:de,disabled:y,children:y?e.jsxs(e.Fragment,{children:[e.jsx(w,{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:q}),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:N.length}),e.jsx("div",{className:"memory-stat-label",children:"Categories"})]}),ce&&e.jsxs("div",{className:"memory-stat-card",children:[e.jsx("div",{className:"memory-stat-value memory-stat-value--updated",children:ce}),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:de,disabled:y,children:y?e.jsxs(e.Fragment,{children:[e.jsx(w,{size:14,className:"animate-spin"}),"Extracting…"]}):"Extract Now"}),e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:Ne,children:"Edit Raw"})]}),e.jsx("div",{className:"memory-categories-list",children:N.map(s=>{const h=!C.has(s.key);return e.jsxs("div",{className:"memory-category-section",children:[e.jsxs("div",{className:"memory-category-header",onClick:()=>oe(s.key),role:"button",tabIndex:0,onKeyDown:g=>{(g.key==="Enter"||g.key===" ")&&(g.preventDefault(),oe(s.key))},children:[e.jsx("h4",{children:s.name}),e.jsx("span",{className:"memory-category-count",children:s.items.length})]}),h&&e.jsx("div",{className:"memory-category-items",children:s.items.map((g,ze)=>e.jsx("div",{className:"memory-insight-item",children:g.replace(/^-\s+/,"").replace(/^\*\s+/,"")},ze))})]},s.key)})})]})}),m==="engines"&&e.jsx("div",{className:"memory-engines-tab",children:k||te?e.jsxs("div",{className:"memory-empty-state",children:[e.jsx(w,{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"}),c?.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."})]}):c?.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:c.qmdInstallCommand||"bun install -g @tobilu/qmd"})]}),e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:je,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:[c?.capabilities?.readable&&e.jsx("span",{className:"memory-capability-badge",children:"Readable"}),c?.capabilities?.writable&&e.jsx("span",{className:"memory-capability-badge",children:"Writable"}),c?.capabilities?.supportsAtomicWrite&&e.jsx("span",{className:"memory-capability-badge",children:"Atomic Writes"}),c?.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:T,onChange:s=>Z(s.target.value),placeholder:"Search memory with qmd"}),e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:Se,disabled:J,children:J?"Testing…":"Test Retrieval"})]}),e.jsx("small",{className:"settings-muted",children:"Runs the same qmd-backed memory_search path agents use."}),S&&e.jsxs("div",{className:"memory-test-result",children:[e.jsxs("strong",{children:[S.results.length," result",S.results.length===1?"":"s"," ",'for "',S.query,'"']}),e.jsxs("small",{children:["qmd ",S.qmdAvailable?"available":"missing"," · ",S.usedFallback?"local fallback used":"qmd path used"]}),S.results.length>0?e.jsx("ul",{children:S.results.map((s,h)=>e.jsxs("li",{children:[e.jsxs("span",{children:[s.path,":",s.lineStart]}),e.jsx("p",{children:s.snippet})]},`${s.path}-${s.lineStart}-${h}`))}):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:ns(c?.currentBackend??"unknown")})}),e.jsxs("div",{className:"memory-capability-row",children:[c?.capabilities?.readable&&e.jsx("span",{className:"memory-capability-badge",children:"Readable"}),c?.capabilities?.writable&&e.jsx("span",{className:"memory-capability-badge",children:"Writable"}),c?.capabilities?.supportsAtomicWrite&&e.jsx("span",{className:"memory-capability-badge",children:"Atomic Writes"}),c?.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:rs(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{ds as MemoryView};
1
+ import{r as a,j as e}from"./vendor-react-K0fH_qHe.js";import{u as Le}from"./SettingsModal-DvmwpEUE.js";import{bR as Ee,bS as ke,bT as Ie,y as Re,bU as qe,bV as _e,bW as Pe,bX as Me,bY as we,bZ as We,b_ as Te,b$ as Oe,c0 as Ae,c1 as $e,x as Ue,c2 as He,L as w,c3 as Fe}from"./index-tJzhtiGM.js";import"./vendor-xterm-DzcZoU0P.js";import"./vendor-codemirror-jBKmHyH0.js";const T=".fusion/memory/MEMORY.md",Qe=5e4,Ye="0 3 * * *",Be="0 4 * * *";function he(i){return{memoryEnabled:i.memoryEnabled!==!1,memoryAutoSummarizeEnabled:i.memoryAutoSummarizeEnabled??!1,memoryAutoSummarizeThresholdChars:i.memoryAutoSummarizeThresholdChars??Qe,memoryAutoSummarizeSchedule:i.memoryAutoSummarizeSchedule??Ye,memoryDreamsEnabled:i.memoryDreamsEnabled??!1,memoryDreamsSchedule:i.memoryDreamsSchedule??Be}}function De(i,t){return i.some(m=>m.path===t)?t:i.find(m=>m.path===T)?.path??i[0]?.path??T}function Ve(i={}){const{projectId:t}=i,[m,u]=a.useState(""),[C,A]=a.useState(!0),[E,k]=a.useState(!1),[b,x]=a.useState(!1),[r,p]=a.useState(null),[O,K]=a.useState(!0),[J,L]=a.useState(!1),[S,P]=a.useState(()=>he({})),[F,ee]=a.useState(!0),[ue,$]=a.useState(!1),[o,v]=a.useState([]),[se,I]=a.useState(!0),[c,M]=a.useState(T),[W,y]=a.useState(""),[d,te]=a.useState(!1),[U,f]=a.useState(!1),[ae,H]=a.useState(!1),[ne,Q]=a.useState(!1),[Y,re]=a.useState(!1),[D,z]=a.useState(null),[ye,R]=a.useState(!0),[ge,B]=a.useState(!1),[ie,V]=a.useState(!1),[le,G]=a.useState(null),{status:me,loading:Z,refresh:j}=Le({projectId:t}),be=a.useCallback(n=>{y(n),f(!0)},[]),N=a.useCallback(async n=>{te(!0);try{const{content:l}=await Ee(n,t);M(n),y(l),f(!1)}finally{te(!1)}},[t]),q=a.useCallback(async()=>{I(!0);try{const{files:n}=await ke(t);if(v(n),n.length===0){M(T),y(""),f(!1);return}const l=De(n,c);l!==c&&await N(l)}finally{I(!1)}},[t,c,N]);a.useEffect(()=>{let n=!1;async function l(){try{const s=await $e(t);n||(u(s.content),A(!1))}catch{n||(u(""),A(!1))}}return l(),()=>{n=!0}},[t]),a.useEffect(()=>{let n=!1;async function l(){try{const s=await we(t);n||(p(s.content),L(s.exists),K(!1))}catch{n||(p(null),L(!1),K(!1))}}return l(),()=>{n=!0}},[t]),a.useEffect(()=>{let n=!1;async function l(){ee(!0);try{const s=await Ue(t);n||P(he(s))}catch{n||P(he({}))}finally{n||ee(!1)}}return l(),()=>{n=!0}},[t]),a.useEffect(()=>{let n=!1;async function l(){I(!0);try{const{files:s}=await ke(t);if(n)return;if(v(s),s.length===0){M(T),y(""),f(!1);return}const h=De(s,c),{content:g}=await Ee(h,t);if(n)return;M(h),y(g),f(!1)}catch{n||(v([]),M(T),y(""),f(!1))}finally{n||I(!1)}}return l(),()=>{n=!0}},[t,c]),a.useEffect(()=>{let n=!1;async function l(){try{const s=await Me(t);n||(z(s),R(!1))}catch{n||(z(null),R(!1))}}return l(),()=>{n=!0}},[t]),a.useEffect(()=>{let n=!1;async function l(){try{const s=await He(t);n||G(s)}catch{n||G(null)}}return l(),()=>{n=!0}},[t]);const ce=a.useCallback(n=>{u(n),k(!0)},[]),oe=a.useCallback(async()=>{if(E){x(!0);try{await Ie(m,t),k(!1)}finally{x(!1)}}},[m,E,t]),xe=a.useCallback(async n=>{$(!0);try{const l=await Re(n,t);P(he(l))}finally{$(!1)}},[t]),pe=a.useCallback(async n=>{await N(n)},[N]),fe=a.useCallback(async()=>{if(U){H(!0);try{await qe(c,W,t),f(!1),await q()}finally{H(!1)}}},[W,U,c,t,q]),je=a.useCallback(async()=>{V(!0);try{const n=await _e(t);return await j(),n}finally{V(!1)}},[t,j]),Se=a.useCallback(async n=>Pe(n,t),[t]),X=a.useCallback(async()=>{try{const n=await Me(t);z(n)}catch{z(null)}},[t]),_=a.useCallback(async()=>{try{const n=await we(t);p(n.content),L(n.exists)}catch{p(null),L(!1)}},[t]),de=a.useCallback(async n=>{await We(n,t),await _()},[t,_]),ve=a.useCallback(async()=>{Q(!0);try{const n=await Te(t);return await Promise.all([_(),X()]),{success:n.success,summary:n.summary}}finally{Q(!1)}},[t,_,X]),Ne=a.useCallback(async()=>{re(!0);try{return await Oe(t)}finally{re(!1)}},[t]),Ce=a.useCallback(async n=>{B(!0);try{const l=n?await Ae(n,t):await Ae(t);if(n){const s=l.path??n;M(s),y(l.content),f(!1),await q();return}u(l.content),k(!0)}finally{B(!1)}},[t,q]);return{workingMemory:m,workingMemoryLoading:C,workingMemoryDirty:E,setWorkingMemory:ce,saveWorkingMemory:oe,savingWorkingMemory:b,insightsContent:r,insightsLoading:O,insightsExists:J,refreshInsights:_,saveInsights:de,memorySettings:S,settingsLoading:F,savingMemorySettings:ue,saveMemorySettings:xe,memoryFiles:o,memoryFilesLoading:se,selectedFilePath:c,selectedFileContent:W,selectedFileLoading:d,selectedFileDirty:U,setSelectedFileContent:be,selectFile:pe,saveSelectedFile:fe,savingSelectedFile:ae,reloadMemoryFiles:q,backendStatus:me,backendLoading:Z,extractInsights:ve,extracting:ne,triggerDreamNow:Ne,dreamRunning:Y,auditReport:D,auditLoading:ye,refreshAudit:X,compactMemory:Ce,compacting:ge,installQmdAction:je,installingQmd:ie,testRetrieval:Se,stats:le}}const Ge={Patterns:"pattern",Principles:"principle",Conventions:"convention",Pitfalls:"pitfall",Context:"context"},Ze={"long-term":"Long-term",daily:"Daily",dreams:"Dreams"},Xe={"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."},Ke=72;function Je(i,t){if(i.length<=t)return i;const m=Math.max(1,t-1),u=Math.ceil(m/2),C=Math.floor(m/2);return`${i.slice(0,u)}…${i.slice(i.length-C)}`}function es(i){const t=`${i.label} — ${i.path}`;return Je(t,Ke)}function ss(i){if(!i)return[];const t=[],m=i.split(/(?=^## )/m);for(const u of m){const C=u.trim();if(!C)continue;const A=C.match(/^##\s+(.+?)(\n|$)/);if(A){const E=A[1].trim(),k=Ge[E]??E.toLowerCase(),b=C.slice(A[0].length).trim(),x=b.split(`
2
+ `).map(r=>r.replace(/^-\s+/,"").trim()).filter(r=>r.length>0&&(r.startsWith("- ")||r.startsWith("* ")));(x.length>0||b.length>0)&&t.push({name:E,key:k,items:x.length>0?x:b.length>0?[b]:[],expanded:!0})}}return t}function ts(i){if(!i)return null;const t=i.match(/##\s+Last\s+Updated:\s*(\d{4}-\d{2}-\d{2})/i);return t?t[1]:null}function as(i){return i.reduce((t,m)=>t+m.items.length,0)}function ns(i){switch(i){case"file":return"File (.fusion/memory/, agent/<agent-name>/memory/)";case"readonly":return"Read-Only";case"qmd":return"QMD (Quantized Memory Distillation)";default:return i}}function rs(i){switch(i){case"healthy":return"Healthy";case"warning":return"Warning";case"issues":return"Issues Found"}}function ds({projectId:i,addToast:t}){const[m,u]=a.useState("working"),[C,A]=a.useState(new Set),[E,k]=a.useState(!1),[b,x]=a.useState(null),[r,p]=a.useState({memoryEnabled:!0,memoryAutoSummarizeEnabled:!1,memoryAutoSummarizeThresholdChars:5e4,memoryAutoSummarizeSchedule:"0 3 * * *",memoryDreamsEnabled:!1,memoryDreamsSchedule:"0 4 * * *"}),[O,K]=a.useState(""),[J,L]=a.useState(!1),[S,P]=a.useState(null),{insightsContent:F,insightsLoading:ee,insightsExists:ue,saveInsights:$,memorySettings:o,settingsLoading:v,saveMemorySettings:se,savingMemorySettings:I,backendStatus:c,backendLoading:M,extractInsights:W,extracting:y,auditReport:d,auditLoading:te,refreshAudit:U,compactMemory:f,compacting:ae,installQmdAction:H,installingQmd:ne,testRetrieval:Q,memoryFiles:Y,memoryFilesLoading:re,selectedFilePath:D,selectedFileContent:z,selectedFileLoading:ye,selectedFileDirty:R,setSelectedFileContent:ge,selectFile:B,saveSelectedFile:ie,savingSelectedFile:V,reloadMemoryFiles:le,triggerDreamNow:G,dreamRunning:me}=Ve({projectId:i});a.useEffect(()=>{p(o)},[o]);const Z=a.useMemo(()=>r.memoryEnabled!==o.memoryEnabled||r.memoryAutoSummarizeEnabled!==o.memoryAutoSummarizeEnabled||r.memoryAutoSummarizeThresholdChars!==o.memoryAutoSummarizeThresholdChars||r.memoryAutoSummarizeSchedule!==o.memoryAutoSummarizeSchedule||r.memoryDreamsEnabled!==o.memoryDreamsEnabled||r.memoryDreamsSchedule!==o.memoryDreamsSchedule,[r,o]),j=a.useMemo(()=>Y.find(s=>s.path===D),[Y,D]),be=j?Xe[j.layer]:"Edits the selected memory file.",N=a.useMemo(()=>ss(F),[F]),q=a.useMemo(()=>as(N),[N]),ce=a.useMemo(()=>ts(F),[F]),oe=a.useCallback(s=>{A(h=>{const g=new Set(h);return g.has(s)?g.delete(s):g.add(s),g})},[]),xe=a.useCallback(async s=>{try{await B(s)}catch{t("Failed to load memory file","error")}},[B,t]),pe=a.useCallback(async()=>{try{await ie(),t("Memory saved","success")}catch{t("Failed to save memory","error")}},[ie,t]),fe=a.useCallback(async()=>{if(!Z)return;const s={};r.memoryEnabled!==o.memoryEnabled&&(s.memoryEnabled=r.memoryEnabled),r.memoryAutoSummarizeEnabled!==o.memoryAutoSummarizeEnabled&&(s.memoryAutoSummarizeEnabled=r.memoryAutoSummarizeEnabled),r.memoryAutoSummarizeThresholdChars!==o.memoryAutoSummarizeThresholdChars&&(s.memoryAutoSummarizeThresholdChars=r.memoryAutoSummarizeThresholdChars),r.memoryAutoSummarizeSchedule!==o.memoryAutoSummarizeSchedule&&(s.memoryAutoSummarizeSchedule=r.memoryAutoSummarizeSchedule),r.memoryDreamsEnabled!==o.memoryDreamsEnabled&&(s.memoryDreamsEnabled=r.memoryDreamsEnabled),r.memoryDreamsSchedule!==o.memoryDreamsSchedule&&(s.memoryDreamsSchedule=r.memoryDreamsSchedule);try{await se(s),t("Memory settings saved","success")}catch{t("Failed to save memory settings","error")}},[Z,r,o,se,t]),je=a.useCallback(async()=>{try{const s=await H();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")}},[H,t]),Se=a.useCallback(async()=>{L(!0),P(null);try{const s=await Q(O);P(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{L(!1)}},[O,Q,t]),X=a.useCallback(async()=>{try{await G(),t("Dream processing completed","success"),await le()}catch(s){t(s instanceof Error?s.message:"Failed to run dream processing","error")}},[G,le,t]),_=a.useCallback(async()=>{try{await f(D),t("Memory file compacted","success")}catch{t("Failed to compact memory","error")}},[f,D,t]),de=a.useCallback(async()=>{try{const s=await W();t(s.summary,"success")}catch(s){t(s instanceof Error?s.message:"Failed to extract insights","error")}},[W,t]),ve=a.useCallback(async()=>{if(b!==null)try{await $(b),k(!1),x(null),t("Insights saved","success")}catch{t("Failed to save insights","error")}},[b,$,t]),Ne=a.useCallback(()=>{x(F??""),k(!0)},[F]),Ce=a.useCallback(()=>{k(!1),x(null)},[]),n=!M&&c!==null,l=c?.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":m==="working",className:`memory-view-tab${m==="working"?" memory-view-tab--active":""}`,onClick:()=>u("working"),"data-testid":"memory-tab-working",children:"Working Memory"}),e.jsx("button",{type:"button",role:"tab","aria-selected":m==="insights",className:`memory-view-tab${m==="insights"?" memory-view-tab--active":""}`,onClick:()=>u("insights"),"data-testid":"memory-tab-insights",children:"Insights"}),e.jsx("button",{type:"button",role:"tab","aria-selected":m==="engines",className:`memory-view-tab${m==="engines"?" memory-view-tab--active":""}`,onClick:()=>u("engines"),"data-testid":"memory-tab-engines",children:"Engines"})]}),e.jsxs("div",{className:"memory-view-content",children:[m==="working"&&e.jsxs("div",{className:"memory-working-tab",children:[n&&!l&&e.jsx("div",{className:"memory-readonly-banner",children:"This memory backend is read-only. Changes cannot be saved."}),re||ye?e.jsxs("div",{className:"memory-empty-state",children:[e.jsx(w,{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:D,onChange:s=>{xe(s.target.value)},disabled:R,children:Y.map(s=>e.jsx("option",{value:s.path,title:`${s.label} — ${s.path}`,children:es(s)},s.path))}),e.jsx("small",{children:R?"Save or discard the current edits before switching files.":"Choose any project memory file to view or edit."})]}),j&&e.jsxs("div",{className:"memory-file-summary",children:[e.jsx("span",{children:Ze[j.layer]}),e.jsx("strong",{children:j.path}),e.jsxs("small",{children:[j.size.toLocaleString()," bytes · updated ",new Date(j.updatedAt).toLocaleString()]})]}),e.jsxs("div",{className:"form-group memory-editor-form-group",children:[e.jsx("label",{children:j?.label||"Memory Editor"}),e.jsx("small",{children:be}),e.jsx("div",{className:"memory-editor-container",children:e.jsx(Fe,{content:z,onChange:ge,readOnly:!l,filePath:D})})]})]}),e.jsxs("div",{className:"memory-action-bar",children:[e.jsxs("span",{className:"memory-char-count",children:[z.length," characters"]}),e.jsx("div",{className:"memory-flex-spacer"}),l&&z.length>0&&e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:_,disabled:ae||R,children:ae?e.jsxs(e.Fragment,{children:[e.jsx(w,{size:14,className:"animate-spin"}),"Compacting…"]}):"Compact Selected File"}),R&&l&&e.jsx("button",{type:"button",className:"btn btn-primary btn-sm",onClick:pe,disabled:V,children:V?e.jsxs(e.Fragment,{children:[e.jsx(w,{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:r.memoryDreamsEnabled,onChange:s=>{p(h=>({...h,memoryDreamsEnabled:s.target.checked}))},disabled:!r.memoryEnabled||v}),"Process dreams from daily memory"]}),e.jsx("small",{children:"Turns daily notes into DREAMS.md and promotes reusable lessons into MEMORY.md."})]}),r.memoryEnabled&&r.memoryDreamsEnabled&&e.jsxs(e.Fragment,{children:[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:r.memoryDreamsSchedule,onChange:s=>{p(h=>({...h,memoryDreamsSchedule:s.target.value}))},placeholder:"0 4 * * *",disabled:v}),e.jsx("small",{children:"Cron expression for dream processing."})]}),e.jsxs("div",{className:"form-group",children:[e.jsx("button",{type:"button",className:"btn btn-sm",onClick:X,disabled:me||!r.memoryDreamsEnabled,children:me?e.jsxs(e.Fragment,{children:[e.jsx(w,{size:14,className:"animate-spin"}),"Dreaming…"]}):"Dream Now"}),e.jsx("small",{children:"Manually trigger dream processing now."})]})]})]}),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:r.memoryAutoSummarizeEnabled,onChange:s=>{p(h=>({...h,memoryAutoSummarizeEnabled:s.target.checked}))},disabled:!r.memoryEnabled||v}),"Auto-Summarize Memory"]}),e.jsx("small",{children:"Automatically compact memory when it exceeds the threshold on a schedule"})]}),r.memoryEnabled&&r.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:r.memoryAutoSummarizeThresholdChars,onChange:s=>{p(h=>({...h,memoryAutoSummarizeThresholdChars:parseInt(s.target.value,10)||5e4}))},min:1e3,disabled:v}),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:r.memoryAutoSummarizeSchedule,onChange:s=>{p(h=>({...h,memoryAutoSummarizeSchedule:s.target.value}))},placeholder:"0 3 * * *",disabled:v}),e.jsx("small",{children:"Cron expression for auto-summarize schedule (default: daily at 3 AM)"})]})]})]}),!r.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."}),Z&&e.jsx("div",{className:"memory-action-bar",children:e.jsx("button",{type:"button",className:"btn btn-primary btn-sm",onClick:fe,disabled:I||v,children:I?e.jsxs(e.Fragment,{children:[e.jsx(w,{size:14,className:"animate-spin"}),"Saving…"]}):"Save Settings"})})]})]})]}),m==="insights"&&e.jsx("div",{className:"memory-insights-tab",children:ee?e.jsxs("div",{className:"memory-empty-state",children:[e.jsx(w,{size:20,className:"animate-spin"}),e.jsx("span",{children:"Loading insights…"})]}):E?e.jsxs("div",{className:"memory-insights-editor-layout",children:[e.jsx("div",{className:"memory-editor-container",children:e.jsx(Fe,{content:b??"",onChange:x,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:Ce,children:"Cancel"}),e.jsx("button",{type:"button",className:"btn btn-primary btn-sm",onClick:ve,children:"Save Insights"})]})]}):!ue||N.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:de,disabled:y,children:y?e.jsxs(e.Fragment,{children:[e.jsx(w,{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:q}),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:N.length}),e.jsx("div",{className:"memory-stat-label",children:"Categories"})]}),ce&&e.jsxs("div",{className:"memory-stat-card",children:[e.jsx("div",{className:"memory-stat-value memory-stat-value--updated",children:ce}),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:de,disabled:y,children:y?e.jsxs(e.Fragment,{children:[e.jsx(w,{size:14,className:"animate-spin"}),"Extracting…"]}):"Extract Now"}),e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:Ne,children:"Edit Raw"})]}),e.jsx("div",{className:"memory-categories-list",children:N.map(s=>{const h=!C.has(s.key);return e.jsxs("div",{className:"memory-category-section",children:[e.jsxs("div",{className:"memory-category-header",onClick:()=>oe(s.key),role:"button",tabIndex:0,onKeyDown:g=>{(g.key==="Enter"||g.key===" ")&&(g.preventDefault(),oe(s.key))},children:[e.jsx("h4",{children:s.name}),e.jsx("span",{className:"memory-category-count",children:s.items.length})]}),h&&e.jsx("div",{className:"memory-category-items",children:s.items.map((g,ze)=>e.jsx("div",{className:"memory-insight-item",children:g.replace(/^-\s+/,"").replace(/^\*\s+/,"")},ze))})]},s.key)})})]})}),m==="engines"&&e.jsx("div",{className:"memory-engines-tab",children:M||te?e.jsxs("div",{className:"memory-empty-state",children:[e.jsx(w,{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"}),c?.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."})]}):c?.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:c.qmdInstallCommand||"bun install -g @tobilu/qmd"})]}),e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:je,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:[c?.capabilities?.readable&&e.jsx("span",{className:"memory-capability-badge",children:"Readable"}),c?.capabilities?.writable&&e.jsx("span",{className:"memory-capability-badge",children:"Writable"}),c?.capabilities?.supportsAtomicWrite&&e.jsx("span",{className:"memory-capability-badge",children:"Atomic Writes"}),c?.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:O,onChange:s=>K(s.target.value),placeholder:"Search memory with qmd"}),e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:Se,disabled:J,children:J?"Testing…":"Test Retrieval"})]}),e.jsx("small",{className:"settings-muted",children:"Runs the same qmd-backed memory_search path agents use."}),S&&e.jsxs("div",{className:"memory-test-result",children:[e.jsxs("strong",{children:[S.results.length," result",S.results.length===1?"":"s"," ",'for "',S.query,'"']}),e.jsxs("small",{children:["qmd ",S.qmdAvailable?"available":"missing"," · ",S.usedFallback?"local fallback used":"qmd path used"]}),S.results.length>0?e.jsx("ul",{children:S.results.map((s,h)=>e.jsxs("li",{children:[e.jsxs("span",{children:[s.path,":",s.lineStart]}),e.jsx("p",{children:s.snippet})]},`${s.path}-${s.lineStart}-${h}`))}):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:ns(c?.currentBackend??"unknown")})}),e.jsxs("div",{className:"memory-capability-row",children:[c?.capabilities?.readable&&e.jsx("span",{className:"memory-capability-badge",children:"Readable"}),c?.capabilities?.writable&&e.jsx("span",{className:"memory-capability-badge",children:"Writable"}),c?.capabilities?.supportsAtomicWrite&&e.jsx("span",{className:"memory-capability-badge",children:"Atomic Writes"}),c?.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:rs(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:()=>U(),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{ds as MemoryView};