@runfusion/fusion 0.41.0 → 0.42.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 (83) hide show
  1. package/dist/bin.js +44240 -41922
  2. package/dist/client/.vite/manifest.json +72 -72
  3. package/dist/client/assets/AgentDetailView-C5Lb3fd3.js +18 -0
  4. package/dist/client/assets/AgentDetailView-DiWELtb1.css +1 -0
  5. package/dist/client/assets/{AgentPermissionPolicyEditor-VDXL4XQc.js → AgentPermissionPolicyEditor-DtRcvE6M.js} +2 -2
  6. package/dist/client/assets/{AgentsView-ChXccELt.js → AgentsView-BVW-NOYD.js} +3 -3
  7. package/dist/client/assets/ChatView-Dy-oIkrK.js +6 -0
  8. package/dist/client/assets/{DevServerView-DGOahw1o.js → DevServerView-DLsFSP4s.js} +1 -1
  9. package/dist/client/assets/{DirectoryPicker-DgqHlxyh.js → DirectoryPicker-_QawX-uL.js} +1 -1
  10. package/dist/client/assets/{DocumentsView-CbbZwzbH.js → DocumentsView-DierUJsj.js} +1 -1
  11. package/dist/client/assets/{EvalsView-BL_ue7fJ.js → EvalsView-B83lYKQl.js} +1 -1
  12. package/dist/client/assets/{ExperimentalAgentOnboardingModal-8H4XAu4O.js → ExperimentalAgentOnboardingModal-CTctYTPU.js} +1 -1
  13. package/dist/client/assets/{GoalsView-CO4FVL3E.js → GoalsView-CKn8i0i0.js} +1 -1
  14. package/dist/client/assets/{InsightsView-C5vLvWVE.js → InsightsView-EpRHCD8G.js} +1 -1
  15. package/dist/client/assets/{MemoryView-BL3W3yOv.js → MemoryView-Df_ocTc5.js} +2 -2
  16. package/dist/client/assets/NodesView-DF7xJ_3z.js +14 -0
  17. package/dist/client/assets/{PiExtensionsManager-HvSiVeDN.js → PiExtensionsManager-BOooOEDx.js} +2 -2
  18. package/dist/client/assets/{PluginManager-DIjrlhnU.js → PluginManager-CHrDAzK6.js} +1 -1
  19. package/dist/client/assets/{PullRequestView-C2jQX8xZ.js → PullRequestView-CJU21OZ6.js} +2 -2
  20. package/dist/client/assets/{ReliabilityView-DbqEwoRs.js → ReliabilityView-uHkW1Qeu.js} +1 -1
  21. package/dist/client/assets/{ResearchView-C1QghmLI.js → ResearchView-oZ2-vbjL.js} +1 -1
  22. package/dist/client/assets/{SecretsView-Y2MQ-9n5.js → SecretsView-BpkqSV_E.js} +1 -1
  23. package/dist/client/assets/SessionTerminal-D9IW4cDj.js +2 -0
  24. package/dist/client/assets/{SettingsModal-DabcZZ6S.js → SettingsModal-BmB5l2bA.js} +1 -1
  25. package/dist/client/assets/SettingsModal-C8gsAazm.js +31 -0
  26. package/dist/client/assets/{SetupWizardModal-Db-Rxinm.js → SetupWizardModal-BYLEU_7o.js} +1 -1
  27. package/dist/client/assets/{SkillsView-CIEY1-DE.js → SkillsView-8GgQ8Z_Z.js} +1 -1
  28. package/dist/client/assets/{StashRecoveryView-B6iDu5tI.js → StashRecoveryView-CT1t1Uf2.js} +1 -1
  29. package/dist/client/assets/{TodoView-B8IK_BPM.js → TodoView-BUj6ITAb.js} +2 -2
  30. package/dist/client/assets/WorkflowNodeEditor-CN7GPmvV.js +8 -0
  31. package/dist/client/assets/WorkflowNodeEditor-aPj8cv81.css +1 -0
  32. package/dist/client/assets/app-B2ZxMfJT.js +13 -0
  33. package/dist/client/assets/app-BffGU_HQ.js +13 -0
  34. package/dist/client/assets/app-C8AHhs5N.js +13 -0
  35. package/dist/client/assets/app-DCot4oXA.js +13 -0
  36. package/dist/client/assets/app-Ri9Te2Dv.js +13 -0
  37. package/dist/client/assets/app-sEkTyT-w.js +13 -0
  38. package/dist/client/assets/{dashboard-view-O5j3PSGY.js → dashboard-view-C3SsjXo1.js} +1621 -1621
  39. package/dist/client/assets/{dashboard-view-Dn4CztR6.js → dashboard-view-CrYwb0oQ.js} +1 -1
  40. package/dist/client/assets/dashboard-view-Du53JbmQ.css +1 -0
  41. package/dist/client/assets/{folder-open-C9XAaduE.js → folder-open-CREXTATY.js} +1 -1
  42. package/dist/client/assets/index-2kYpdJrx.js +793 -0
  43. package/dist/client/assets/index-CJUfvGdC.css +1 -0
  44. package/dist/client/assets/{upload-BRAEugYV.js → upload-BvLUlwaH.js} +1 -1
  45. package/dist/client/assets/{users-BlflbMZ3.js → users-CjhbU-sF.js} +1 -1
  46. package/dist/client/index.html +2 -2
  47. package/dist/client/version.json +1 -1
  48. package/dist/droid-cli/package.json +1 -1
  49. package/dist/extension.js +43622 -41519
  50. package/dist/pi-claude-cli/package.json +1 -1
  51. package/dist/plugins/fusion-plugin-acp-runtime/package.json +1 -1
  52. package/dist/plugins/fusion-plugin-cli-printing-press/package.json +1 -1
  53. package/dist/plugins/fusion-plugin-compound-engineering/bundled.js +59 -8
  54. package/dist/plugins/fusion-plugin-compound-engineering/package.json +1 -1
  55. package/dist/plugins/fusion-plugin-cursor-runtime/package.json +1 -1
  56. package/dist/plugins/fusion-plugin-dependency-graph/package.json +1 -1
  57. package/dist/plugins/fusion-plugin-droid-runtime/package.json +1 -1
  58. package/dist/plugins/fusion-plugin-hermes-runtime/package.json +1 -1
  59. package/dist/plugins/fusion-plugin-openclaw-runtime/package.json +1 -1
  60. package/dist/plugins/fusion-plugin-paperclip-runtime/package.json +1 -1
  61. package/dist/plugins/fusion-plugin-reports/package.json +1 -1
  62. package/dist/plugins/fusion-plugin-roadmap/package.json +1 -1
  63. package/dist/plugins/fusion-plugin-whatsapp-chat/package.json +1 -1
  64. package/package.json +2 -1
  65. package/skill/fusion/references/extension-tools.md +3 -3
  66. package/skill/fusion/references/fusion-capabilities.md +2 -2
  67. package/dist/client/assets/AgentDetailView-CY-O6VkV.css +0 -1
  68. package/dist/client/assets/AgentDetailView-krC0B2O0.js +0 -18
  69. package/dist/client/assets/ChatView-Dz_xBKit.js +0 -6
  70. package/dist/client/assets/NodesView-DfBNNm9c.js +0 -14
  71. package/dist/client/assets/SessionTerminal-DaTXNT3A.js +0 -2
  72. package/dist/client/assets/SettingsModal-BAzm2kYd.js +0 -31
  73. package/dist/client/assets/WorkflowNodeEditor-DaPyvD_R.js +0 -8
  74. package/dist/client/assets/WorkflowNodeEditor-Po5uv_dN.css +0 -1
  75. package/dist/client/assets/app-CTRT_hQh.js +0 -13
  76. package/dist/client/assets/app-CVg6W-HU.js +0 -13
  77. package/dist/client/assets/app-CY3pQXOr.js +0 -13
  78. package/dist/client/assets/app-DNh04p5I.js +0 -13
  79. package/dist/client/assets/app-DhHgtB9j.js +0 -13
  80. package/dist/client/assets/app-NL_hPGDS.js +0 -13
  81. package/dist/client/assets/dashboard-view-BgiLoG1G.css +0 -1
  82. package/dist/client/assets/index-BHGM5W8a.css +0 -1
  83. package/dist/client/assets/index-CgfrecpF.js +0 -793
@@ -1 +1 @@
1
- import{r as l,j as e}from"./vendor-react-D37HfzIf.js";import{cT as b,bd as L,cU as O,cV as W,cW as _,X as G,b as $,C,L as Y}from"./index-CgfrecpF.js";import{D as V}from"./DirectoryPicker-DgqHlxyh.js";import{s as f}from"./projectDetection-G3XuxD2X.js";import{u as q}from"./vendor-i18n-CV0mwX_-.js";import"./vendor-reactflow-CRZcPCXF.js";import"./vendor-xterm-tcedd2Jt.js";import"./vendor-codemirror-jBKmHyH0.js";import"./folder-open-C9XAaduE.js";function oe({onProjectRegistered:m,onClose:j}){const{t:s}=q("app"),y="https://github.com/runfusion/fusion/discussions",[z,P]=l.useState(!0),[t,n]=l.useState(()=>({step:b()?"manual":"auth",manualMode:"existing",manualPath:"",manualCloneUrl:"",manualName:"",manualIsolationMode:"in-process",manualNodeId:"",isRegistering:!1,error:null})),[x,T]=l.useState(!1),[i,u]=l.useState(""),[p,g]=l.useState(()=>b()),{nodes:N,loading:M}=L(),S=N.find(a=>a.type==="local")?.id,k=l.useCallback(()=>{P(!1),j?.()},[j]),I=l.useCallback(a=>{n(o=>{const d={manualPath:a};return a&&(!o.manualName||o.manualName===f(o.manualPath))&&(d.manualName=f(a)),{...o,...d}})},[]),R=l.useCallback(async()=>{const a=t.manualPath.trim(),o=t.manualName.trim(),d=t.manualCloneUrl.trim();if(!(!a||!o)&&!(t.manualMode==="clone"&&!d)){n(c=>({...c,isRegistering:!0,error:null}));try{const c={name:o,path:a,isolationMode:t.manualIsolationMode,nodeId:t.manualNodeId||void 0,cloneUrl:t.manualMode==="clone"?d:void 0},h=await O(c);m(h),n(B=>({...B,step:"complete",isRegistering:!1}))}catch(c){n(h=>({...h,isRegistering:!1,error:c instanceof Error?c.message:"Failed to register project"}))}}},[t.manualPath,t.manualName,t.manualCloneUrl,t.manualMode,t.manualIsolationMode,t.manualNodeId,m]),v=l.useCallback(()=>{const a=i.trim();a&&(W(a),g(a),u(""),n(o=>o.step==="auth"?{...o,step:"manual"}:o))},[i]),A=l.useCallback(()=>{_(),g(void 0),u("")},[]),F=l.useCallback(()=>{n(a=>({...a,step:"manual"}))},[]);if(!z)return null;const w=t.manualMode==="existing",r=t.manualMode==="clone",U=t.manualPath.trim().length>0,D=t.manualName.trim().length>0,E=t.manualCloneUrl.trim().length>0,H=t.isRegistering||!U||!D||r&&!E;return e.jsx("div",{className:"modal-overlay open setup-wizard-overlay",role:"dialog","aria-modal":"true","aria-labelledby":"wizard-title",children:e.jsxs("div",{className:"modal setup-wizard-modal",children:[e.jsxs("div",{className:"setup-wizard-header",children:[e.jsxs("div",{className:"setup-wizard-heading",children:[e.jsxs("div",{className:"setup-wizard-brand","aria-label":"Fusion",children:[e.jsxs("svg",{className:"setup-wizard-brand-logo",width:28,height:28,viewBox:"0 0 128 128",fill:"none","aria-label":"Fusion logo",role:"img",children:[e.jsx("circle",{cx:"64",cy:"64",r:"52",stroke:"currentColor",strokeWidth:"8"}),e.jsx("path",{d:"M26 101C44 82 62 64 82 45C90 37 98 30 104 24C96 35 89 47 81 60C70 79 57 95 43 108C38 112 32 108 26 101Z",fill:"currentColor"})]}),e.jsx("span",{className:"setup-wizard-brand-name",children:"Fusion"})]}),e.jsxs("h2",{id:"wizard-title",className:"setup-wizard-title",children:[t.step==="auth"&&s("setup.setAuthToken","Set Auth Token"),t.step==="manual"&&s("setup.welcomeToFusion","Welcome to Fusion"),t.step==="complete"&&s("setup.setupComplete","Setup Complete!")]})]}),t.step!=="complete"&&e.jsx("button",{className:"modal-close",onClick:k,"aria-label":s("setup.closeWizard","Close wizard"),children:e.jsx(G,{size:20})})]}),e.jsxs("div",{className:"setup-wizard-content",children:[t.step==="auth"&&e.jsxs("div",{className:"setup-wizard-auth-step",children:[e.jsx("p",{className:"setup-wizard-auth-step-description",children:s("setup.authDescription","This dashboard requires an auth token to communicate with the Fusion daemon. Paste the token below to continue.")}),e.jsxs("div",{className:"form-group",children:[e.jsx("label",{htmlFor:"setup-auth-token",children:s("setup.authToken","Auth Token")}),e.jsx("input",{id:"setup-auth-token",type:"password",value:i,onChange:a=>u(a.target.value),placeholder:s("setup.pasteTokenPlaceholder","Paste the daemon auth token"),autoComplete:"off",spellCheck:!1,autoFocus:!0}),e.jsx("p",{className:"form-hint",children:s("setup.tokenEnvVar","The token was set via the {{env}} environment variable when starting the dashboard.",{env:"FUSION_DAEMON_TOKEN"})})]}),t.error&&e.jsx("div",{className:"wizard-error",role:"alert",children:t.error})]}),t.step==="manual"&&e.jsxs("div",{className:"setup-wizard-manual",children:[e.jsxs("div",{className:"form-group",children:[e.jsx("label",{htmlFor:"project-name",children:s("setup.projectName","Project Name")}),e.jsx("input",{id:"project-name",type:"text",value:t.manualName,onChange:a=>n(o=>({...o,manualName:a.target.value})),placeholder:s("setup.projectNamePlaceholder","my-project")}),e.jsx("p",{className:"form-hint",children:r?s("setup.projectNameHintClone","By default this follows the destination folder name unless you edit it."):s("setup.projectNameHintExisting","By default this follows the selected directory name unless you edit it.")})]}),e.jsxs("div",{className:"form-group",children:[e.jsx("label",{htmlFor:"project-path",children:r?s("setup.destinationDirectory","Destination Directory"):s("setup.projectDirectory","Project Directory")}),e.jsx(V,{value:t.manualPath,onChange:I,nodeId:t.manualNodeId||void 0,localNodeId:S,placeholder:r?s("setup.clonePathPlaceholder","/path/for/new-clone"):s("setup.projectPathPlaceholder","/path/to/your/project")}),e.jsx("p",{className:"form-hint",children:r?s("setup.clonePathHint","Select or type an absolute destination path. Fusion will clone into this directory."):s("setup.projectPathHint","Select or type the absolute path to your project")})]}),e.jsxs("div",{className:"setup-wizard-advanced",children:[e.jsxs("button",{type:"button",className:"setup-wizard-advanced-toggle","aria-expanded":x,onClick:()=>T(a=>!a),children:[e.jsx($,{size:16,className:"setup-wizard-advanced-chevron"}),e.jsx("span",{children:s("setup.advancedSettings","Advanced settings")})]}),x&&e.jsxs("div",{className:"setup-wizard-advanced-panel",children:[e.jsxs("fieldset",{className:"setup-wizard-mode-switch","aria-label":"Project setup mode",children:[e.jsx("legend",{children:s("setup.setupMode","Setup Mode")}),e.jsxs("label",{className:`setup-wizard-mode-option${w?" selected":""}`,children:[e.jsx("input",{type:"radio",name:"setup-mode",value:"existing",checked:w,onChange:()=>n(a=>({...a,manualMode:"existing",error:null}))}),e.jsx("span",{children:s("setup.useExistingDirectory","Use Existing Directory")})]}),e.jsxs("label",{className:`setup-wizard-mode-option${r?" selected":""}`,children:[e.jsx("input",{type:"radio",name:"setup-mode",value:"clone",checked:r,onChange:()=>n(a=>({...a,manualMode:"clone",error:null}))}),e.jsx("span",{children:s("setup.cloneGitRepository","Clone Git Repository")})]})]}),r&&e.jsxs("div",{className:"form-group",children:[e.jsx("label",{htmlFor:"project-clone-url",children:s("setup.repositoryUrl","Repository URL")}),e.jsx("input",{id:"project-clone-url",type:"text",value:t.manualCloneUrl,onChange:a=>n(o=>({...o,manualCloneUrl:a.target.value})),placeholder:s("setup.repositoryUrlPlaceholder","https://github.com/owner/repo.git")}),e.jsx("p",{className:"form-hint",children:s("setup.cloneGitHint","Fusion will run git clone into the destination directory, then register that cloned folder.")})]}),e.jsx("div",{className:"form-group",children:e.jsxs("div",{className:"project-node-selector",children:[e.jsx("span",{className:"project-node-selector__label",children:s("setup.runtimeNode","Runtime Node")}),e.jsxs("select",{value:t.manualNodeId,onChange:a=>n(o=>({...o,manualNodeId:a.target.value})),disabled:M||t.isRegistering,children:[e.jsx("option",{value:"",children:s("setup.localNode","Local node")}),N.map(a=>e.jsxs("option",{value:a.id,children:[a.name," (",a.type,")"]},a.id))]})]})}),e.jsxs("div",{className:"form-group",children:[e.jsx("label",{children:s("setup.isolationMode","Isolation Mode")}),e.jsxs("div",{className:"setup-wizard-isolation-options",children:[e.jsxs("label",{className:`setup-wizard-isolation-option${t.manualIsolationMode==="in-process"?" selected":""}`,children:[e.jsx("input",{type:"radio",name:"isolation-mode",value:"in-process",checked:t.manualIsolationMode==="in-process",onChange:()=>n(a=>({...a,manualIsolationMode:"in-process"}))}),e.jsxs("div",{className:"setup-wizard-isolation-option-content",children:[e.jsx("strong",{children:s("setup.inProcess","In-Process")}),e.jsx("span",{children:s("setup.inProcessDesc","Lower overhead, shared memory. Best for most projects.")}),e.jsx("span",{className:"wizard-option-recommended",children:s("setup.recommended","Recommended")})]})]}),e.jsxs("label",{className:`setup-wizard-isolation-option${t.manualIsolationMode==="child-process"?" selected":""}`,children:[e.jsx("input",{type:"radio",name:"isolation-mode",value:"child-process",checked:t.manualIsolationMode==="child-process",onChange:()=>n(a=>({...a,manualIsolationMode:"child-process"}))}),e.jsxs("div",{className:"setup-wizard-isolation-option-content",children:[e.jsx("strong",{children:s("setup.childProcess","Child-Process")}),e.jsx("span",{children:s("setup.childProcessDesc","Isolated execution with crash containment.")})]})]})]})]}),e.jsxs("div",{className:"form-group",children:[e.jsx("label",{htmlFor:"advanced-auth-token",children:s("setup.browserAuthToken","Browser Auth Token")}),e.jsxs("div",{className:"setup-wizard-auth-token",children:[e.jsx("input",{id:"advanced-auth-token",type:"password",value:i,onChange:a=>u(a.target.value),placeholder:p?s("setup.replaceTokenPlaceholder","Enter a new token to replace the stored one"):s("setup.pasteTokenForBrowserPlaceholder","Paste the auth token for this browser"),autoComplete:"off",spellCheck:!1}),e.jsxs("div",{className:"setup-wizard-auth-token-actions",children:[e.jsx("button",{type:"button",className:"btn",onClick:v,disabled:i.trim().length===0,children:p?s("setup.updateToken","Update token"):s("setup.setToken","Set token")}),p&&e.jsx("button",{type:"button",className:"btn",onClick:A,children:s("setup.resetToken","Reset token")})]})]}),e.jsx("p",{className:"form-hint",children:p?s("setup.tokenStoredHint","A token is already stored in this browser. You can update or reset it below."):s("setup.noTokenHint","No token is stored. Use the auth prompt at the top of the wizard, or set one here.")})]})]})]}),t.error&&e.jsx("div",{className:"wizard-error",role:"alert",children:t.error})]}),t.step==="complete"&&e.jsxs("div",{className:"setup-wizard-complete",children:[e.jsxs("div",{className:"setup-wizard-success-streak","aria-hidden":"true",children:[e.jsx("div",{className:"setup-wizard-success-streak-core"}),e.jsx("div",{className:"setup-wizard-success-streak-glow"})]}),e.jsx(C,{size:64,className:"success-icon"}),e.jsx("h3",{children:s("setup.allSet","All Set!")}),e.jsx("p",{children:s("setup.projectRegisteredSuccess","Your project has been registered successfully.")}),e.jsx("p",{children:s("setup.addMoreProjectsHint","You can add more projects anytime from the project overview.")})]})]}),e.jsxs("div",{className:"setup-wizard-footer",children:[e.jsx("a",{className:"btn setup-wizard-help-link",href:y,target:"_blank",rel:"noreferrer",children:s("setup.needHelp","Need help?")}),t.step==="auth"&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"btn",onClick:F,children:s("setup.skip","Skip")}),e.jsx("button",{className:"btn btn-primary",onClick:v,disabled:i.trim().length===0,children:e.jsx("span",{children:s("setup.setTokenContinue","Set Token & Continue")})})]}),t.step==="manual"&&e.jsx("button",{className:"btn btn-primary",onClick:R,disabled:H,children:t.isRegistering?e.jsxs(e.Fragment,{children:[e.jsx(Y,{size:16,className:"animate-spin"}),e.jsx("span",{children:s("setup.registering","Registering...")})]}):e.jsx("span",{children:s("setup.registerProject","Register Project")})}),t.step==="complete"&&e.jsxs("button",{className:"btn btn-primary",onClick:k,children:[e.jsx(C,{size:16}),e.jsx("span",{children:s("setup.getStarted","Get Started")})]})]})]})})}export{oe as SetupWizardModal};
1
+ import{r as l,j as e}from"./vendor-react-D37HfzIf.js";import{cW as b,bd as L,cX as O,cY as W,cZ as _,X as G,b as Y,C,L as $}from"./index-2kYpdJrx.js";import{D as X}from"./DirectoryPicker-_QawX-uL.js";import{s as f}from"./projectDetection-G3XuxD2X.js";import{u as Z}from"./vendor-i18n-CV0mwX_-.js";import"./vendor-reactflow-CRZcPCXF.js";import"./vendor-xterm-tcedd2Jt.js";import"./vendor-codemirror-jBKmHyH0.js";import"./folder-open-CREXTATY.js";function oe({onProjectRegistered:m,onClose:j}){const{t:s}=Z("app"),y="https://github.com/runfusion/fusion/discussions",[z,P]=l.useState(!0),[t,n]=l.useState(()=>({step:b()?"manual":"auth",manualMode:"existing",manualPath:"",manualCloneUrl:"",manualName:"",manualIsolationMode:"in-process",manualNodeId:"",isRegistering:!1,error:null})),[x,M]=l.useState(!1),[i,u]=l.useState(""),[p,g]=l.useState(()=>b()),{nodes:N,loading:S}=L(),T=N.find(a=>a.type==="local")?.id,k=l.useCallback(()=>{P(!1),j?.()},[j]),I=l.useCallback(a=>{n(o=>{const d={manualPath:a};return a&&(!o.manualName||o.manualName===f(o.manualPath))&&(d.manualName=f(a)),{...o,...d}})},[]),R=l.useCallback(async()=>{const a=t.manualPath.trim(),o=t.manualName.trim(),d=t.manualCloneUrl.trim();if(!(!a||!o)&&!(t.manualMode==="clone"&&!d)){n(c=>({...c,isRegistering:!0,error:null}));try{const c={name:o,path:a,isolationMode:t.manualIsolationMode,nodeId:t.manualNodeId||void 0,cloneUrl:t.manualMode==="clone"?d:void 0},h=await O(c);m(h),n(B=>({...B,step:"complete",isRegistering:!1}))}catch(c){n(h=>({...h,isRegistering:!1,error:c instanceof Error?c.message:"Failed to register project"}))}}},[t.manualPath,t.manualName,t.manualCloneUrl,t.manualMode,t.manualIsolationMode,t.manualNodeId,m]),v=l.useCallback(()=>{const a=i.trim();a&&(W(a),g(a),u(""),n(o=>o.step==="auth"?{...o,step:"manual"}:o))},[i]),A=l.useCallback(()=>{_(),g(void 0),u("")},[]),F=l.useCallback(()=>{n(a=>({...a,step:"manual"}))},[]);if(!z)return null;const w=t.manualMode==="existing",r=t.manualMode==="clone",U=t.manualPath.trim().length>0,D=t.manualName.trim().length>0,E=t.manualCloneUrl.trim().length>0,H=t.isRegistering||!U||!D||r&&!E;return e.jsx("div",{className:"modal-overlay open setup-wizard-overlay",role:"dialog","aria-modal":"true","aria-labelledby":"wizard-title",children:e.jsxs("div",{className:"modal setup-wizard-modal",children:[e.jsxs("div",{className:"setup-wizard-header",children:[e.jsxs("div",{className:"setup-wizard-heading",children:[e.jsxs("div",{className:"setup-wizard-brand","aria-label":"Fusion",children:[e.jsxs("svg",{className:"setup-wizard-brand-logo",width:28,height:28,viewBox:"0 0 128 128",fill:"none","aria-label":"Fusion logo",role:"img",children:[e.jsx("circle",{cx:"64",cy:"64",r:"52",stroke:"currentColor",strokeWidth:"8"}),e.jsx("path",{d:"M26 101C44 82 62 64 82 45C90 37 98 30 104 24C96 35 89 47 81 60C70 79 57 95 43 108C38 112 32 108 26 101Z",fill:"currentColor"})]}),e.jsx("span",{className:"setup-wizard-brand-name",children:"Fusion"})]}),e.jsxs("h2",{id:"wizard-title",className:"setup-wizard-title",children:[t.step==="auth"&&s("setup.setAuthToken","Set Auth Token"),t.step==="manual"&&s("setup.welcomeToFusion","Welcome to Fusion"),t.step==="complete"&&s("setup.setupComplete","Setup Complete!")]})]}),t.step!=="complete"&&e.jsx("button",{className:"modal-close",onClick:k,"aria-label":s("setup.closeWizard","Close wizard"),children:e.jsx(G,{size:20})})]}),e.jsxs("div",{className:"setup-wizard-content",children:[t.step==="auth"&&e.jsxs("div",{className:"setup-wizard-auth-step",children:[e.jsx("p",{className:"setup-wizard-auth-step-description",children:s("setup.authDescription","This dashboard requires an auth token to communicate with the Fusion daemon. Paste the token below to continue.")}),e.jsxs("div",{className:"form-group",children:[e.jsx("label",{htmlFor:"setup-auth-token",children:s("setup.authToken","Auth Token")}),e.jsx("input",{id:"setup-auth-token",type:"password",value:i,onChange:a=>u(a.target.value),placeholder:s("setup.pasteTokenPlaceholder","Paste the daemon auth token"),autoComplete:"off",spellCheck:!1,autoFocus:!0}),e.jsx("p",{className:"form-hint",children:s("setup.tokenEnvVar","The token was set via the {{env}} environment variable when starting the dashboard.",{env:"FUSION_DAEMON_TOKEN"})})]}),t.error&&e.jsx("div",{className:"wizard-error",role:"alert",children:t.error})]}),t.step==="manual"&&e.jsxs("div",{className:"setup-wizard-manual",children:[e.jsxs("div",{className:"form-group",children:[e.jsx("label",{htmlFor:"project-name",children:s("setup.projectName","Project Name")}),e.jsx("input",{id:"project-name",type:"text",value:t.manualName,onChange:a=>n(o=>({...o,manualName:a.target.value})),placeholder:s("setup.projectNamePlaceholder","my-project")}),e.jsx("p",{className:"form-hint",children:r?s("setup.projectNameHintClone","By default this follows the destination folder name unless you edit it."):s("setup.projectNameHintExisting","By default this follows the selected directory name unless you edit it.")})]}),e.jsxs("div",{className:"form-group",children:[e.jsx("label",{htmlFor:"project-path",children:r?s("setup.destinationDirectory","Destination Directory"):s("setup.projectDirectory","Project Directory")}),e.jsx(X,{value:t.manualPath,onChange:I,nodeId:t.manualNodeId||void 0,localNodeId:T,placeholder:r?s("setup.clonePathPlaceholder","/path/for/new-clone"):s("setup.projectPathPlaceholder","/path/to/your/project")}),e.jsx("p",{className:"form-hint",children:r?s("setup.clonePathHint","Select or type an absolute destination path. Fusion will clone into this directory."):s("setup.projectPathHint","Select or type the absolute path to your project")})]}),e.jsxs("div",{className:"setup-wizard-advanced",children:[e.jsxs("button",{type:"button",className:"setup-wizard-advanced-toggle","aria-expanded":x,onClick:()=>M(a=>!a),children:[e.jsx(Y,{size:16,className:"setup-wizard-advanced-chevron"}),e.jsx("span",{children:s("setup.advancedSettings","Advanced settings")})]}),x&&e.jsxs("div",{className:"setup-wizard-advanced-panel",children:[e.jsxs("fieldset",{className:"setup-wizard-mode-switch","aria-label":"Project setup mode",children:[e.jsx("legend",{children:s("setup.setupMode","Setup Mode")}),e.jsxs("label",{className:`setup-wizard-mode-option${w?" selected":""}`,children:[e.jsx("input",{type:"radio",name:"setup-mode",value:"existing",checked:w,onChange:()=>n(a=>({...a,manualMode:"existing",error:null}))}),e.jsx("span",{children:s("setup.useExistingDirectory","Use Existing Directory")})]}),e.jsxs("label",{className:`setup-wizard-mode-option${r?" selected":""}`,children:[e.jsx("input",{type:"radio",name:"setup-mode",value:"clone",checked:r,onChange:()=>n(a=>({...a,manualMode:"clone",error:null}))}),e.jsx("span",{children:s("setup.cloneGitRepository","Clone Git Repository")})]})]}),r&&e.jsxs("div",{className:"form-group",children:[e.jsx("label",{htmlFor:"project-clone-url",children:s("setup.repositoryUrl","Repository URL")}),e.jsx("input",{id:"project-clone-url",type:"text",value:t.manualCloneUrl,onChange:a=>n(o=>({...o,manualCloneUrl:a.target.value})),placeholder:s("setup.repositoryUrlPlaceholder","https://github.com/owner/repo.git")}),e.jsx("p",{className:"form-hint",children:s("setup.cloneGitHint","Fusion will run git clone into the destination directory, then register that cloned folder.")})]}),e.jsx("div",{className:"form-group",children:e.jsxs("div",{className:"project-node-selector",children:[e.jsx("span",{className:"project-node-selector__label",children:s("setup.runtimeNode","Runtime Node")}),e.jsxs("select",{value:t.manualNodeId,onChange:a=>n(o=>({...o,manualNodeId:a.target.value})),disabled:S||t.isRegistering,children:[e.jsx("option",{value:"",children:s("setup.localNode","Local node")}),N.map(a=>e.jsxs("option",{value:a.id,children:[a.name," (",a.type,")"]},a.id))]})]})}),e.jsxs("div",{className:"form-group",children:[e.jsx("label",{children:s("setup.isolationMode","Isolation Mode")}),e.jsxs("div",{className:"setup-wizard-isolation-options",children:[e.jsxs("label",{className:`setup-wizard-isolation-option${t.manualIsolationMode==="in-process"?" selected":""}`,children:[e.jsx("input",{type:"radio",name:"isolation-mode",value:"in-process",checked:t.manualIsolationMode==="in-process",onChange:()=>n(a=>({...a,manualIsolationMode:"in-process"}))}),e.jsxs("div",{className:"setup-wizard-isolation-option-content",children:[e.jsx("strong",{children:s("setup.inProcess","In-Process")}),e.jsx("span",{children:s("setup.inProcessDesc","Lower overhead, shared memory. Best for most projects.")}),e.jsx("span",{className:"wizard-option-recommended",children:s("setup.recommended","Recommended")})]})]}),e.jsxs("label",{className:`setup-wizard-isolation-option${t.manualIsolationMode==="child-process"?" selected":""}`,children:[e.jsx("input",{type:"radio",name:"isolation-mode",value:"child-process",checked:t.manualIsolationMode==="child-process",onChange:()=>n(a=>({...a,manualIsolationMode:"child-process"}))}),e.jsxs("div",{className:"setup-wizard-isolation-option-content",children:[e.jsx("strong",{children:s("setup.childProcess","Child-Process")}),e.jsx("span",{children:s("setup.childProcessDesc","Isolated execution with crash containment.")})]})]})]})]}),e.jsxs("div",{className:"form-group",children:[e.jsx("label",{htmlFor:"advanced-auth-token",children:s("setup.browserAuthToken","Browser Auth Token")}),e.jsxs("div",{className:"setup-wizard-auth-token",children:[e.jsx("input",{id:"advanced-auth-token",type:"password",value:i,onChange:a=>u(a.target.value),placeholder:p?s("setup.replaceTokenPlaceholder","Enter a new token to replace the stored one"):s("setup.pasteTokenForBrowserPlaceholder","Paste the auth token for this browser"),autoComplete:"off",spellCheck:!1}),e.jsxs("div",{className:"setup-wizard-auth-token-actions",children:[e.jsx("button",{type:"button",className:"btn",onClick:v,disabled:i.trim().length===0,children:p?s("setup.updateToken","Update token"):s("setup.setToken","Set token")}),p&&e.jsx("button",{type:"button",className:"btn",onClick:A,children:s("setup.resetToken","Reset token")})]})]}),e.jsx("p",{className:"form-hint",children:p?s("setup.tokenStoredHint","A token is already stored in this browser. You can update or reset it below."):s("setup.noTokenHint","No token is stored. Use the auth prompt at the top of the wizard, or set one here.")})]})]})]}),t.error&&e.jsx("div",{className:"wizard-error",role:"alert",children:t.error})]}),t.step==="complete"&&e.jsxs("div",{className:"setup-wizard-complete",children:[e.jsxs("div",{className:"setup-wizard-success-streak","aria-hidden":"true",children:[e.jsx("div",{className:"setup-wizard-success-streak-core"}),e.jsx("div",{className:"setup-wizard-success-streak-glow"})]}),e.jsx(C,{size:64,className:"success-icon"}),e.jsx("h3",{children:s("setup.allSet","All Set!")}),e.jsx("p",{children:s("setup.projectRegisteredSuccess","Your project has been registered successfully.")}),e.jsx("p",{children:s("setup.addMoreProjectsHint","You can add more projects anytime from the project overview.")})]})]}),e.jsxs("div",{className:"setup-wizard-footer",children:[e.jsx("a",{className:"btn setup-wizard-help-link",href:y,target:"_blank",rel:"noreferrer",children:s("setup.needHelp","Need help?")}),t.step==="auth"&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"btn",onClick:F,children:s("setup.skip","Skip")}),e.jsx("button",{className:"btn btn-primary",onClick:v,disabled:i.trim().length===0,children:e.jsx("span",{children:s("setup.setTokenContinue","Set Token & Continue")})})]}),t.step==="manual"&&e.jsx("button",{className:"btn btn-primary",onClick:R,disabled:H,children:t.isRegistering?e.jsxs(e.Fragment,{children:[e.jsx($,{size:16,className:"animate-spin"}),e.jsx("span",{children:s("setup.registering","Registering...")})]}):e.jsx("span",{children:s("setup.registerProject","Register Project")})}),t.step==="complete"&&e.jsxs("button",{className:"btn btn-primary",onClick:k,children:[e.jsx(C,{size:16}),e.jsx("span",{children:s("setup.getStarted","Get Started")})]})]})]})})}export{oe as SetupWizardModal};
@@ -1 +1 @@
1
- import{r as a,j as s}from"./vendor-react-D37HfzIf.js";import{bT as J,bU as O,bV as T,bW as Y,bX as Z,bS as ss,X as V,R as es,a as ls,b as is,L as U,ay as as}from"./index-CgfrecpF.js";import{u as ts}from"./vendor-i18n-CV0mwX_-.js";import"./vendor-reactflow-CRZcPCXF.js";import"./vendor-xterm-tcedd2Jt.js";import"./vendor-codemirror-jBKmHyH0.js";function us({projectId:o,addToast:r,onClose:W}){const{t:l}=ts("app"),[m,v]=a.useState([]),[C,L]=a.useState(!0),[$,D]=a.useState(!1),[F,N]=a.useState(null),[z,K]=a.useState([]),[u,X]=a.useState(""),[S,R]=a.useState(null),[k,b]=a.useState(null),[x,j]=a.useState(null),[B,P]=a.useState(!1),[A,w]=a.useState(null),d=a.useRef(null),[y,I]=a.useState(""),M=u.trim()?m.filter(e=>e.name.toLowerCase().includes(u.toLowerCase())||e.relativePath.toLowerCase().includes(u.toLowerCase())):m,g=a.useCallback(async()=>{L(!0);try{const e=await J(o);v(e)}catch(e){const t=e instanceof Error?e.message:l("skills.loadDiscoveredError","Failed to load discovered skills");r(t,"error")}finally{L(!1)}},[o,r]),h=a.useCallback(async e=>{const t=i=>{if(!i||typeof i!="object")return!1;const n=i;if(typeof n.status=="number"&&n.status>=500)return!0;if(n.details&&typeof n.details=="object"){const p=n.details;if(typeof p.code=="string"&&p.code.startsWith("upstream_"))return!0}const c=i;return typeof c.error=="string"&&typeof c.code=="string"};D(!0),N(null);try{const i=await O(e,20,o);K(i.entries)}catch(i){if(t(i))N(l("skills.catalogUnavailable","Catalog is temporarily unavailable. Please try again later."));else{const n=i instanceof Error?i.message:l("skills.loadCatalogError","Failed to load catalog");N(n)}}finally{D(!1)}},[o]);a.useEffect(()=>{g(),h("")},[g,h]);const _=a.useCallback(e=>{X(e),d.current&&clearTimeout(d.current),d.current=setTimeout(()=>{I(e),d.current=null},300)},[]);a.useEffect(()=>()=>{d.current&&(clearTimeout(d.current),d.current=null)},[]),a.useEffect(()=>{h(y)},[y,h]);const q=a.useCallback(async(e,t)=>{const i=!t;v(n=>n.map(c=>c.id===e?{...c,toggling:!0}:c));try{await T(e,i,o),v(n=>n.map(c=>c.id===e?{...c,enabled:i,toggling:!1}:c)),r(l(`skills.${i?"enabled":"disabled"}`,i?"Skill enabled":"Skill disabled"),"success")}catch(n){v(p=>p.map(E=>E.id===e?{...E,toggling:!1}:E));const c=n instanceof Error?n.message:l("skills.toggleError","Failed to toggle skill");r(l("skills.toggleFailed","Failed to toggle skill: {{message}}",{message:c}),"error")}},[o,r]),G=a.useCallback(async e=>{const t=e.repo?.trim();if(!(!t||S===e.id)){R(e.id);try{await Y(t,e.slug||e.name,o),r(l("skills.installSuccess","Installed {{name}}",{name:e.name}),"success"),await g()}catch(i){const n=i instanceof Error?i.message:l("skills.installError","Failed to install skill");r(l("skills.installFailed","Failed to install {{name}}: {{message}}",{name:e.name,message:n}),"error")}finally{R(i=>i===e.id?null:i)}}},[r,S,g,o]),f=a.useCallback(async e=>{P(!0),w(null),j(null);try{const t=await Z(e,o);j(t)}catch(t){const i=t instanceof Error?t.message:l("skills.loadContentError","Failed to load skill content");w(i)}finally{P(!1)}},[o]),Q=a.useCallback((e,t)=>{if(!(t&&t.target.closest(".skills-view-item-toggle"))){if(k===e){b(null),j(null),w(null);return}b(e),f(e)}},[k,f]),H=a.useCallback(e=>{k!==e&&b(e),f(e)},[f,k]);return s.jsxs("div",{className:"skills-view","data-testid":"skills-view",children:[s.jsxs("div",{className:"skills-view-header",children:[s.jsxs("div",{className:"skills-view-title",children:[s.jsxs("h2",{children:[s.jsx(ss,{size:20}),l("skills.title","Skills")]}),s.jsxs("span",{className:"skills-view-count","aria-label":l("skills.discoveredCount","{{count}} discovered skills",{count:m.length}),children:[m.length," ",l("skills.discovered","discovered")]})]}),s.jsxs("div",{className:"skills-view-actions",children:[s.jsx("button",{className:"btn-icon skills-view-close touch-target",onClick:W,"aria-label":l("skills.closeView","Close skills view"),children:s.jsx(V,{size:16})}),s.jsxs("button",{className:"btn btn-sm touch-target",onClick:()=>void g(),disabled:C,children:[s.jsx(es,{size:14,className:C?"spin":""}),l("common.refresh","Refresh")]})]})]}),s.jsxs("div",{className:"skills-view-content",children:[s.jsx("div",{className:"skills-view-search",children:s.jsx("input",{type:"text",className:"form-input",placeholder:l("skills.searchPlaceholder","Search skills..."),value:u,onChange:e=>_(e.target.value),"aria-label":l("skills.searchLabel","Search skills")})}),s.jsxs("section",{className:"skills-view-section","aria-labelledby":"discovered-skills-title",children:[s.jsx("h3",{id:"discovered-skills-title",className:"skills-view-section-title",children:l("skills.discoveredSection","Discovered Skills")}),C?s.jsxs("div",{className:"skills-view-loading",children:[s.jsx("span",{className:"spinner"}),l("skills.loadingDiscovered","Loading discovered skills...")]}):m.length===0?s.jsx("div",{className:"skills-view-empty",children:s.jsx("p",{children:l("skills.noDiscovered","No skills discovered in this project.")})}):M.length===0?s.jsx("div",{className:"skills-view-empty",children:s.jsx("p",{children:l("skills.noMatchingDiscovered","No discovered skills match your search.")})}):s.jsx("div",{className:"skills-view-list",children:M.map(e=>{const t=k===e.id;return s.jsxs("div",{children:[s.jsxs("div",{className:`skills-view-item${t?" skills-view-item--selected":""}`,onClick:i=>Q(e.id,i),role:"button",tabIndex:0,onKeyDown:i=>{(i.key==="Enter"||i.key===" ")&&(i.preventDefault(),Q(e.id))},"aria-expanded":t,"aria-label":l("skills.viewDetails","View details for {{name}}",{name:e.name}),children:[s.jsxs("div",{className:"skills-view-item-info",children:[s.jsxs("span",{className:"skills-view-item-name",children:[t?s.jsx(ls,{size:14}):s.jsx(is,{size:14}),e.name]}),s.jsx("span",{className:"skills-view-item-path",children:e.relativePath}),s.jsx("span",{className:"skills-view-item-source",children:e.metadata.source})]}),s.jsxs("label",{className:"skills-view-item-toggle",onClick:i=>i.stopPropagation(),children:[s.jsx("input",{type:"checkbox",checked:e.enabled,disabled:e.toggling,onChange:()=>void q(e.id,e.enabled),"aria-label":l(`skills.${e.enabled?"disable":"enable"}Skill`,e.enabled?"Disable {{name}}":"Enable {{name}}",{name:e.name})}),s.jsx("span",{className:"skills-view-toggle-slider"})]})]}),t&&s.jsxs("div",{className:"skills-view-detail","data-testid":"skill-detail",children:[s.jsxs("div",{className:"skills-view-detail-header",children:[s.jsx("span",{className:"skills-view-detail-title",children:e.name}),s.jsxs("button",{className:"btn btn-sm skills-view-detail-close",onClick:()=>{b(null),j(null),w(null)},"aria-label":l("skills.closeDetail","Close skill detail"),children:[s.jsx(V,{size:14}),l("common.close","Close")]})]}),B?s.jsxs("div",{className:"skills-view-detail-loading",children:[s.jsx(U,{size:16,className:"spin"}),l("skills.loadingContent","Loading skill content...")]}):A?s.jsxs("div",{className:"skills-view-detail-error",children:[s.jsx(as,{size:14}),s.jsx("span",{children:A}),s.jsx("button",{className:"btn btn-sm",onClick:()=>H(e.id),children:l("common.retry","Retry")})]}):x?s.jsxs(s.Fragment,{children:[s.jsx("pre",{className:"skills-view-detail-content",children:x.skillMd||l("skills.noSkillMd","(No SKILL.md found)")}),x.files.length>0&&s.jsxs("div",{className:"skills-view-detail-files",children:[s.jsxs("span",{className:"skills-view-detail-files-label",children:[l("skills.filesLabel","Files"),":"]}),x.files.map(i=>s.jsxs("span",{className:"badge badge--sm",children:[i.name,i.type==="directory"&&"/"]},i.relativePath))]})]}):null]})]},e.id)})})]}),s.jsxs("section",{className:"skills-view-section","aria-labelledby":"catalog-title",children:[s.jsx("h3",{id:"catalog-title",className:"skills-view-section-title",children:l("skills.catalogSection","Skills Catalog")}),F?s.jsxs("div",{className:"skills-view-error",children:[s.jsx("p",{children:F}),s.jsx("button",{className:"btn btn-sm",onClick:()=>void h(y),children:l("common.tryAgain","Try Again")})]}):$?s.jsxs("div",{className:"skills-view-loading",children:[s.jsx("span",{className:"spinner"}),l("skills.loadingCatalog","Loading catalog...")]}):z.length===0?s.jsx("div",{className:"skills-view-empty",children:u?s.jsx("p",{children:l("skills.noMatchingSearch","No skills match your search.")}):s.jsx("p",{children:l("skills.noCatalogAvailable","No skills available in the catalog.")})}):s.jsx("div",{className:"skills-view-grid",children:z.map(e=>{const i=!!e.repo?.trim(),n=S===e.id;return s.jsxs("div",{className:"skills-view-card",children:[s.jsxs("div",{className:"skills-view-card-header",children:[s.jsx("h4",{className:"skills-view-card-title",children:e.name}),i?s.jsxs("button",{type:"button",className:"btn btn-sm skills-view-card-install",onClick:()=>void G(e),disabled:n,"aria-label":l("skills.installSkill","Install {{name}}",{name:e.name}),children:[n?s.jsx(U,{size:14,className:"spin"}):null,n?l("skills.installing","Installing…"):l("skills.install","Install")]}):null]}),e.description&&s.jsx("p",{className:"skills-view-card-description",children:e.description}),e.tags&&e.tags.length>0&&s.jsx("div",{className:"skills-view-card-tags",children:e.tags.map(c=>s.jsx("span",{className:"badge badge--sm",children:c},c))}),e.installs!==void 0&&s.jsx("span",{className:"skills-view-card-installs",children:l("skills.installsCount","{{value}} installs",{value:e.installs.toLocaleString()})})]},e.id)})})]})]})]})}export{us as SkillsView};
1
+ import{r as a,j as s}from"./vendor-react-D37HfzIf.js";import{bU as H,bV as J,bW as O,bX as T,bY as Z,bT as ss,X as V,R as es,a as ls,b as is,L as U,ay as as}from"./index-2kYpdJrx.js";import{u as ts}from"./vendor-i18n-CV0mwX_-.js";import"./vendor-reactflow-CRZcPCXF.js";import"./vendor-xterm-tcedd2Jt.js";import"./vendor-codemirror-jBKmHyH0.js";function us({projectId:o,addToast:r,onClose:W}){const{t:l}=ts("app"),[m,v]=a.useState([]),[C,L]=a.useState(!0),[$,D]=a.useState(!1),[F,N]=a.useState(null),[z,K]=a.useState([]),[u,X]=a.useState(""),[S,R]=a.useState(null),[k,b]=a.useState(null),[x,j]=a.useState(null),[B,P]=a.useState(!1),[A,w]=a.useState(null),d=a.useRef(null),[y,I]=a.useState(""),M=u.trim()?m.filter(e=>e.name.toLowerCase().includes(u.toLowerCase())||e.relativePath.toLowerCase().includes(u.toLowerCase())):m,g=a.useCallback(async()=>{L(!0);try{const e=await H(o);v(e)}catch(e){const t=e instanceof Error?e.message:l("skills.loadDiscoveredError","Failed to load discovered skills");r(t,"error")}finally{L(!1)}},[o,r]),h=a.useCallback(async e=>{const t=i=>{if(!i||typeof i!="object")return!1;const n=i;if(typeof n.status=="number"&&n.status>=500)return!0;if(n.details&&typeof n.details=="object"){const p=n.details;if(typeof p.code=="string"&&p.code.startsWith("upstream_"))return!0}const c=i;return typeof c.error=="string"&&typeof c.code=="string"};D(!0),N(null);try{const i=await J(e,20,o);K(i.entries)}catch(i){if(t(i))N(l("skills.catalogUnavailable","Catalog is temporarily unavailable. Please try again later."));else{const n=i instanceof Error?i.message:l("skills.loadCatalogError","Failed to load catalog");N(n)}}finally{D(!1)}},[o]);a.useEffect(()=>{g(),h("")},[g,h]);const Y=a.useCallback(e=>{X(e),d.current&&clearTimeout(d.current),d.current=setTimeout(()=>{I(e),d.current=null},300)},[]);a.useEffect(()=>()=>{d.current&&(clearTimeout(d.current),d.current=null)},[]),a.useEffect(()=>{h(y)},[y,h]);const _=a.useCallback(async(e,t)=>{const i=!t;v(n=>n.map(c=>c.id===e?{...c,toggling:!0}:c));try{await O(e,i,o),v(n=>n.map(c=>c.id===e?{...c,enabled:i,toggling:!1}:c)),r(l(`skills.${i?"enabled":"disabled"}`,i?"Skill enabled":"Skill disabled"),"success")}catch(n){v(p=>p.map(E=>E.id===e?{...E,toggling:!1}:E));const c=n instanceof Error?n.message:l("skills.toggleError","Failed to toggle skill");r(l("skills.toggleFailed","Failed to toggle skill: {{message}}",{message:c}),"error")}},[o,r]),q=a.useCallback(async e=>{const t=e.repo?.trim();if(!(!t||S===e.id)){R(e.id);try{await T(t,e.slug||e.name,o),r(l("skills.installSuccess","Installed {{name}}",{name:e.name}),"success"),await g()}catch(i){const n=i instanceof Error?i.message:l("skills.installError","Failed to install skill");r(l("skills.installFailed","Failed to install {{name}}: {{message}}",{name:e.name,message:n}),"error")}finally{R(i=>i===e.id?null:i)}}},[r,S,g,o]),f=a.useCallback(async e=>{P(!0),w(null),j(null);try{const t=await Z(e,o);j(t)}catch(t){const i=t instanceof Error?t.message:l("skills.loadContentError","Failed to load skill content");w(i)}finally{P(!1)}},[o]),Q=a.useCallback((e,t)=>{if(!(t&&t.target.closest(".skills-view-item-toggle"))){if(k===e){b(null),j(null),w(null);return}b(e),f(e)}},[k,f]),G=a.useCallback(e=>{k!==e&&b(e),f(e)},[f,k]);return s.jsxs("div",{className:"skills-view","data-testid":"skills-view",children:[s.jsxs("div",{className:"skills-view-header",children:[s.jsxs("div",{className:"skills-view-title",children:[s.jsxs("h2",{children:[s.jsx(ss,{size:20}),l("skills.title","Skills")]}),s.jsxs("span",{className:"skills-view-count","aria-label":l("skills.discoveredCount","{{count}} discovered skills",{count:m.length}),children:[m.length," ",l("skills.discovered","discovered")]})]}),s.jsxs("div",{className:"skills-view-actions",children:[s.jsx("button",{className:"btn-icon skills-view-close touch-target",onClick:W,"aria-label":l("skills.closeView","Close skills view"),children:s.jsx(V,{size:16})}),s.jsxs("button",{className:"btn btn-sm touch-target",onClick:()=>void g(),disabled:C,children:[s.jsx(es,{size:14,className:C?"spin":""}),l("common.refresh","Refresh")]})]})]}),s.jsxs("div",{className:"skills-view-content",children:[s.jsx("div",{className:"skills-view-search",children:s.jsx("input",{type:"text",className:"form-input",placeholder:l("skills.searchPlaceholder","Search skills..."),value:u,onChange:e=>Y(e.target.value),"aria-label":l("skills.searchLabel","Search skills")})}),s.jsxs("section",{className:"skills-view-section","aria-labelledby":"discovered-skills-title",children:[s.jsx("h3",{id:"discovered-skills-title",className:"skills-view-section-title",children:l("skills.discoveredSection","Discovered Skills")}),C?s.jsxs("div",{className:"skills-view-loading",children:[s.jsx("span",{className:"spinner"}),l("skills.loadingDiscovered","Loading discovered skills...")]}):m.length===0?s.jsx("div",{className:"skills-view-empty",children:s.jsx("p",{children:l("skills.noDiscovered","No skills discovered in this project.")})}):M.length===0?s.jsx("div",{className:"skills-view-empty",children:s.jsx("p",{children:l("skills.noMatchingDiscovered","No discovered skills match your search.")})}):s.jsx("div",{className:"skills-view-list",children:M.map(e=>{const t=k===e.id;return s.jsxs("div",{children:[s.jsxs("div",{className:`skills-view-item${t?" skills-view-item--selected":""}`,onClick:i=>Q(e.id,i),role:"button",tabIndex:0,onKeyDown:i=>{(i.key==="Enter"||i.key===" ")&&(i.preventDefault(),Q(e.id))},"aria-expanded":t,"aria-label":l("skills.viewDetails","View details for {{name}}",{name:e.name}),children:[s.jsxs("div",{className:"skills-view-item-info",children:[s.jsxs("span",{className:"skills-view-item-name",children:[t?s.jsx(ls,{size:14}):s.jsx(is,{size:14}),e.name]}),s.jsx("span",{className:"skills-view-item-path",children:e.relativePath}),s.jsx("span",{className:"skills-view-item-source",children:e.metadata.source})]}),s.jsxs("label",{className:"skills-view-item-toggle",onClick:i=>i.stopPropagation(),children:[s.jsx("input",{type:"checkbox",checked:e.enabled,disabled:e.toggling,onChange:()=>void _(e.id,e.enabled),"aria-label":l(`skills.${e.enabled?"disable":"enable"}Skill`,e.enabled?"Disable {{name}}":"Enable {{name}}",{name:e.name})}),s.jsx("span",{className:"skills-view-toggle-slider"})]})]}),t&&s.jsxs("div",{className:"skills-view-detail","data-testid":"skill-detail",children:[s.jsxs("div",{className:"skills-view-detail-header",children:[s.jsx("span",{className:"skills-view-detail-title",children:e.name}),s.jsxs("button",{className:"btn btn-sm skills-view-detail-close",onClick:()=>{b(null),j(null),w(null)},"aria-label":l("skills.closeDetail","Close skill detail"),children:[s.jsx(V,{size:14}),l("common.close","Close")]})]}),B?s.jsxs("div",{className:"skills-view-detail-loading",children:[s.jsx(U,{size:16,className:"spin"}),l("skills.loadingContent","Loading skill content...")]}):A?s.jsxs("div",{className:"skills-view-detail-error",children:[s.jsx(as,{size:14}),s.jsx("span",{children:A}),s.jsx("button",{className:"btn btn-sm",onClick:()=>G(e.id),children:l("common.retry","Retry")})]}):x?s.jsxs(s.Fragment,{children:[s.jsx("pre",{className:"skills-view-detail-content",children:x.skillMd||l("skills.noSkillMd","(No SKILL.md found)")}),x.files.length>0&&s.jsxs("div",{className:"skills-view-detail-files",children:[s.jsxs("span",{className:"skills-view-detail-files-label",children:[l("skills.filesLabel","Files"),":"]}),x.files.map(i=>s.jsxs("span",{className:"badge badge--sm",children:[i.name,i.type==="directory"&&"/"]},i.relativePath))]})]}):null]})]},e.id)})})]}),s.jsxs("section",{className:"skills-view-section","aria-labelledby":"catalog-title",children:[s.jsx("h3",{id:"catalog-title",className:"skills-view-section-title",children:l("skills.catalogSection","Skills Catalog")}),F?s.jsxs("div",{className:"skills-view-error",children:[s.jsx("p",{children:F}),s.jsx("button",{className:"btn btn-sm",onClick:()=>void h(y),children:l("common.tryAgain","Try Again")})]}):$?s.jsxs("div",{className:"skills-view-loading",children:[s.jsx("span",{className:"spinner"}),l("skills.loadingCatalog","Loading catalog...")]}):z.length===0?s.jsx("div",{className:"skills-view-empty",children:u?s.jsx("p",{children:l("skills.noMatchingSearch","No skills match your search.")}):s.jsx("p",{children:l("skills.noCatalogAvailable","No skills available in the catalog.")})}):s.jsx("div",{className:"skills-view-grid",children:z.map(e=>{const i=!!e.repo?.trim(),n=S===e.id;return s.jsxs("div",{className:"skills-view-card",children:[s.jsxs("div",{className:"skills-view-card-header",children:[s.jsx("h4",{className:"skills-view-card-title",children:e.name}),i?s.jsxs("button",{type:"button",className:"btn btn-sm skills-view-card-install",onClick:()=>void q(e),disabled:n,"aria-label":l("skills.installSkill","Install {{name}}",{name:e.name}),children:[n?s.jsx(U,{size:14,className:"spin"}):null,n?l("skills.installing","Installing…"):l("skills.install","Install")]}):null]}),e.description&&s.jsx("p",{className:"skills-view-card-description",children:e.description}),e.tags&&e.tags.length>0&&s.jsx("div",{className:"skills-view-card-tags",children:e.tags.map(c=>s.jsx("span",{className:"badge badge--sm",children:c},c))}),e.installs!==void 0&&s.jsx("span",{className:"skills-view-card-installs",children:l("skills.installsCount","{{value}} installs",{value:e.installs.toLocaleString()})})]},e.id)})})]})]})]})}export{us as SkillsView};
@@ -1 +1 @@
1
- import{r as n,j as s}from"./vendor-react-D37HfzIf.js";import{v as g,cG as d}from"./index-CgfrecpF.js";import{u as R}from"./vendor-i18n-CV0mwX_-.js";import"./vendor-reactflow-CRZcPCXF.js";import"./vendor-xterm-tcedd2Jt.js";import"./vendor-codemirror-jBKmHyH0.js";function L(){const{t:e}=R("app"),{confirm:f}=g(),[i,v]=n.useState([]),[h,p]=n.useState(null),[u,y]=n.useState({}),[t,c]=n.useState(null),l=n.useCallback(async()=>{try{p(null);const a=await d("/stash-recovery/orphans");v(a.records??[])}catch(a){p(a instanceof Error?a.message:e("stashRecovery.failedToLoadOrphans","Failed to load orphans"))}},[e]);n.useEffect(()=>{l()},[l]);const x=n.useMemo(()=>{const a=new Map;for(const r of i){const o=r.sourceTaskId??e("stashRecovery.unknownSource","Unknown source"),m=a.get(o)??[];m.push(r),a.set(o,m)}return Array.from(a.entries())},[i,e]),j=n.useCallback(async a=>{const r=await d(`/stash-recovery/orphans/${a}/apply`,{method:"POST"});y(o=>({...o,[a]:r.ok?e("stashRecovery.applied","Applied"):r.stderr??r.reason??e("stashRecovery.applyFailed","Apply failed")}))},[e]),b=n.useCallback(async a=>{await f({title:e("stashRecovery.dropTitle","Drop orphaned stash?"),message:e("stashRecovery.dropMessage","This removes the stash entry permanently."),confirmLabel:e("stashRecovery.dropConfirm","Drop"),danger:!0})&&(await d(`/stash-recovery/orphans/${a}/drop`,{method:"POST",body:JSON.stringify({confirm:!0})}),await l())},[f,l,e]),N=n.useCallback(async a=>{c({sha:a,diff:"",truncated:!1,loading:!0,error:null});try{const r=await d(`/stash-recovery/orphans/${a}/diff`);c({sha:a,diff:r.diff??"",truncated:!!r.truncated,loading:!1,error:null})}catch(r){c({sha:a,diff:"",truncated:!1,loading:!1,error:r instanceof Error?r.message:e("stashRecovery.failedToLoadDiff","Failed to load diff")})}},[e]);return i.length===0&&!h?s.jsxs("div",{className:"card stash-recovery-view",children:[s.jsx("p",{children:e("stashRecovery.noOrphans","No orphaned merger autostashes found.")}),s.jsx("button",{className:"btn btn-sm",onClick:()=>void l(),children:e("actions.refresh","Refresh")})]}):s.jsxs("div",{className:"card stash-recovery-view",children:[s.jsxs("div",{className:"stash-recovery-header",children:[s.jsx("h2",{children:e("stashRecovery.title","Stash Recovery")}),s.jsx("span",{children:e("stashRecovery.orphanCount","{{count}} orphans",{count:i.length})}),s.jsx("button",{className:"btn btn-sm",onClick:()=>void l(),children:e("actions.refresh","Refresh")})]}),h&&s.jsx("div",{className:"form-error",children:h}),x.map(([a,r])=>s.jsxs("section",{children:[s.jsx("h3",{children:a}),r.map(o=>s.jsxs("div",{className:"stash-row",children:[s.jsxs("div",{className:"stash-field",children:[s.jsx("span",{className:"stash-field-label",children:e("stashRecovery.shaLabel","SHA")}),s.jsx("span",{children:o.sha.slice(0,7)})]}),s.jsxs("div",{className:"stash-field",children:[s.jsx("span",{className:"stash-field-label",children:e("stashRecovery.classificationLabel","Classification")}),s.jsx("span",{children:o.classification})]}),s.jsxs("div",{className:"stash-field",children:[s.jsx("span",{className:"stash-field-label",children:e("stashRecovery.changedPathsLabel","Changed paths")}),s.jsx("span",{children:e("stashRecovery.fileCount","{{count}} files",{count:o.changedPaths.length})})]}),s.jsxs("div",{className:"stash-row-actions",children:[s.jsx("button",{className:"btn btn-sm stash-action-btn",onClick:()=>void N(o.sha),children:e("stashRecovery.inspectDiff","Inspect diff")}),s.jsx("button",{className:"btn btn-sm stash-action-btn",onClick:()=>void j(o.sha),children:e("stashRecovery.apply","Apply")})]}),s.jsx("div",{className:"stash-row-actions-danger",children:s.jsx("button",{className:"btn btn-sm btn-danger stash-action-btn",onClick:()=>void b(o.sha),children:e("stashRecovery.drop","Drop")})}),u[o.sha]&&s.jsx("div",{className:"stash-status",children:u[o.sha]})]},o.sha))]},a)),t&&s.jsx("div",{className:"modal-overlay open",onClick:()=>c(null),children:s.jsxs("div",{className:"modal stash-recovery-diff-modal",role:"dialog","aria-modal":"true","aria-label":e("stashRecovery.diffDialogLabel","Diff for {{sha}}",{sha:t.sha}),onClick:a=>a.stopPropagation(),children:[s.jsxs("div",{className:"modal-header",children:[s.jsx("h3",{children:e("stashRecovery.diffHeader","Diff for {{sha}}",{sha:t.sha.slice(0,7)})}),s.jsx("button",{className:"modal-close",onClick:()=>c(null),"aria-label":e("stashRecovery.closeDiffDialog","Close diff dialog"),children:"×"})]}),t.loading&&s.jsx("p",{children:e("stashRecovery.loadingDiff","Loading diff…")}),t.error&&s.jsx("div",{className:"form-error",children:t.error}),!t.loading&&!t.error&&s.jsxs(s.Fragment,{children:[s.jsx("pre",{className:"stash-recovery-diff-pre",children:t.diff||e("stashRecovery.noDiffOutput","No diff output available.")}),t.truncated&&s.jsx("p",{className:"stash-status",children:e("stashRecovery.diffTruncated","Diff output truncated.")})]}),s.jsx("div",{className:"modal-actions",children:s.jsx("button",{className:"btn",onClick:()=>c(null),children:e("actions.close","Close")})})]})})]})}export{L as StashRecoveryView};
1
+ import{r as n,j as s}from"./vendor-react-D37HfzIf.js";import{v as g,cH as d}from"./index-2kYpdJrx.js";import{u as R}from"./vendor-i18n-CV0mwX_-.js";import"./vendor-reactflow-CRZcPCXF.js";import"./vendor-xterm-tcedd2Jt.js";import"./vendor-codemirror-jBKmHyH0.js";function L(){const{t:e}=R("app"),{confirm:f}=g(),[i,v]=n.useState([]),[h,p]=n.useState(null),[u,y]=n.useState({}),[t,c]=n.useState(null),l=n.useCallback(async()=>{try{p(null);const a=await d("/stash-recovery/orphans");v(a.records??[])}catch(a){p(a instanceof Error?a.message:e("stashRecovery.failedToLoadOrphans","Failed to load orphans"))}},[e]);n.useEffect(()=>{l()},[l]);const x=n.useMemo(()=>{const a=new Map;for(const r of i){const o=r.sourceTaskId??e("stashRecovery.unknownSource","Unknown source"),m=a.get(o)??[];m.push(r),a.set(o,m)}return Array.from(a.entries())},[i,e]),j=n.useCallback(async a=>{const r=await d(`/stash-recovery/orphans/${a}/apply`,{method:"POST"});y(o=>({...o,[a]:r.ok?e("stashRecovery.applied","Applied"):r.stderr??r.reason??e("stashRecovery.applyFailed","Apply failed")}))},[e]),b=n.useCallback(async a=>{await f({title:e("stashRecovery.dropTitle","Drop orphaned stash?"),message:e("stashRecovery.dropMessage","This removes the stash entry permanently."),confirmLabel:e("stashRecovery.dropConfirm","Drop"),danger:!0})&&(await d(`/stash-recovery/orphans/${a}/drop`,{method:"POST",body:JSON.stringify({confirm:!0})}),await l())},[f,l,e]),N=n.useCallback(async a=>{c({sha:a,diff:"",truncated:!1,loading:!0,error:null});try{const r=await d(`/stash-recovery/orphans/${a}/diff`);c({sha:a,diff:r.diff??"",truncated:!!r.truncated,loading:!1,error:null})}catch(r){c({sha:a,diff:"",truncated:!1,loading:!1,error:r instanceof Error?r.message:e("stashRecovery.failedToLoadDiff","Failed to load diff")})}},[e]);return i.length===0&&!h?s.jsxs("div",{className:"card stash-recovery-view",children:[s.jsx("p",{children:e("stashRecovery.noOrphans","No orphaned merger autostashes found.")}),s.jsx("button",{className:"btn btn-sm",onClick:()=>void l(),children:e("actions.refresh","Refresh")})]}):s.jsxs("div",{className:"card stash-recovery-view",children:[s.jsxs("div",{className:"stash-recovery-header",children:[s.jsx("h2",{children:e("stashRecovery.title","Stash Recovery")}),s.jsx("span",{children:e("stashRecovery.orphanCount","{{count}} orphans",{count:i.length})}),s.jsx("button",{className:"btn btn-sm",onClick:()=>void l(),children:e("actions.refresh","Refresh")})]}),h&&s.jsx("div",{className:"form-error",children:h}),x.map(([a,r])=>s.jsxs("section",{children:[s.jsx("h3",{children:a}),r.map(o=>s.jsxs("div",{className:"stash-row",children:[s.jsxs("div",{className:"stash-field",children:[s.jsx("span",{className:"stash-field-label",children:e("stashRecovery.shaLabel","SHA")}),s.jsx("span",{children:o.sha.slice(0,7)})]}),s.jsxs("div",{className:"stash-field",children:[s.jsx("span",{className:"stash-field-label",children:e("stashRecovery.classificationLabel","Classification")}),s.jsx("span",{children:o.classification})]}),s.jsxs("div",{className:"stash-field",children:[s.jsx("span",{className:"stash-field-label",children:e("stashRecovery.changedPathsLabel","Changed paths")}),s.jsx("span",{children:e("stashRecovery.fileCount","{{count}} files",{count:o.changedPaths.length})})]}),s.jsxs("div",{className:"stash-row-actions",children:[s.jsx("button",{className:"btn btn-sm stash-action-btn",onClick:()=>void N(o.sha),children:e("stashRecovery.inspectDiff","Inspect diff")}),s.jsx("button",{className:"btn btn-sm stash-action-btn",onClick:()=>void j(o.sha),children:e("stashRecovery.apply","Apply")})]}),s.jsx("div",{className:"stash-row-actions-danger",children:s.jsx("button",{className:"btn btn-sm btn-danger stash-action-btn",onClick:()=>void b(o.sha),children:e("stashRecovery.drop","Drop")})}),u[o.sha]&&s.jsx("div",{className:"stash-status",children:u[o.sha]})]},o.sha))]},a)),t&&s.jsx("div",{className:"modal-overlay open",onClick:()=>c(null),children:s.jsxs("div",{className:"modal stash-recovery-diff-modal",role:"dialog","aria-modal":"true","aria-label":e("stashRecovery.diffDialogLabel","Diff for {{sha}}",{sha:t.sha}),onClick:a=>a.stopPropagation(),children:[s.jsxs("div",{className:"modal-header",children:[s.jsx("h3",{children:e("stashRecovery.diffHeader","Diff for {{sha}}",{sha:t.sha.slice(0,7)})}),s.jsx("button",{className:"modal-close",onClick:()=>c(null),"aria-label":e("stashRecovery.closeDiffDialog","Close diff dialog"),children:"×"})]}),t.loading&&s.jsx("p",{children:e("stashRecovery.loadingDiff","Loading diff…")}),t.error&&s.jsx("div",{className:"form-error",children:t.error}),!t.loading&&!t.error&&s.jsxs(s.Fragment,{children:[s.jsx("pre",{className:"stash-recovery-diff-pre",children:t.diff||e("stashRecovery.noDiffOutput","No diff output available.")}),t.truncated&&s.jsx("p",{className:"stash-status",children:e("stashRecovery.diffTruncated","Diff output truncated.")})]}),s.jsx("div",{className:"modal-actions",children:s.jsx("button",{className:"btn",onClick:()=>c(null),children:e("actions.close","Close")})})]})})]})}export{L as StashRecoveryView};
@@ -1,6 +1,6 @@
1
- import{r as c,j as e}from"./vendor-react-D37HfzIf.js";import{c as Et,a7 as ut,a8 as bt,a9 as Tt,cu as Dt,cv as Ft,cw as $t,cx as Rt,cy as Mt,cz as Ot,cA as _t,cB as Ut,ac as Pt,v as Kt,j as Bt,z as q,cC as pt,L as Xt,J as zt,bI as Q,X as Z,cD as ft,b6 as ht,U as xt,aj as Wt,a as Gt,aA as Ht,B as gt}from"./index-CgfrecpF.js";import{u as Lt}from"./vendor-i18n-CV0mwX_-.js";import"./vendor-reactflow-CRZcPCXF.js";import"./vendor-xterm-tcedd2Jt.js";import"./vendor-codemirror-jBKmHyH0.js";/**
1
+ import{r as c,j as e}from"./vendor-react-D37HfzIf.js";import{c as Et,a7 as ut,a8 as bt,a9 as Tt,cv as Dt,cw as Ft,cx as $t,cy as Rt,cz as Mt,cA as Ot,cB as _t,cC as Ut,ac as Pt,v as Kt,j as Bt,z as q,cD as pt,L as Xt,J as zt,bJ as Q,X as Z,cE as ft,b6 as ht,U as xt,aj as Jt,a as Wt,aA as Gt,B as gt}from"./index-2kYpdJrx.js";import{u as Lt}from"./vendor-i18n-CV0mwX_-.js";import"./vendor-reactflow-CRZcPCXF.js";import"./vendor-xterm-tcedd2Jt.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.
5
5
  * See the LICENSE file in the root directory of this source tree.
6
- */const Jt=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M8 12h8",key:"1wcyev"}],["path",{d:"M12 8v8",key:"napkw2"}]],Vt=Et("circle-plus",Jt);function Yt(C){const{items:l,...p}=C;return p}function vt(C){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?`${C}-${crypto.randomUUID()}`:`${C}-${Date.now()}-${Math.random().toString(36).slice(2,10)}`}function qt(C={}){const{t:l}=Lt("app"),{projectId:p,addToast:v}=C,R=`${Tt.TODO_LISTS_PREFIX}${p??"global"}`,[o,I]=c.useState(()=>{const a=ut(R,{maxAgeMs:bt});return Array.isArray(a)?a:[]}),[k,w]=c.useState([]),[X,N]=c.useState(()=>o.length===0),[G,y]=c.useState(null),[T,D]=c.useState(null),[j,x]=c.useState([]),A=c.useRef(T);A.current=T,c.useEffect(()=>{let a=!1;const d=ut(R,{maxAgeMs:bt}),f=Array.isArray(d)&&d.length>0;f?(I(d),N(!1)):(I([]),N(!0));async function m(){f||N(!0),y(null);try{const r=await Ut(p);if(a)return;x(r);const s=r.map(Yt);I(s),Pt(R,s,{maxBytes:5e5});const i=A.current&&r.some(n=>n.id===A.current)?A.current:r[0]?.id??null;D(i),w(i?r.find(n=>n.id===i)?.items??[]:[])}catch(r){if(a)return;x([]),I([]),w([]),D(null),y(r instanceof Error?r.message:l("todo.failedLoadLists","Failed to load todo lists"))}finally{a||N(!1)}}return m(),()=>{a=!0}},[R,p]),c.useEffect(()=>{if(!T){w([]);return}const a=j.find(d=>d.id===T);w(a?.items??[])},[j,T]);const H=c.useCallback(async a=>{const d=o,f=j,m=new Date().toISOString(),r={id:vt("temp-list"),projectId:p??"",title:a,createdAt:m,updatedAt:m};y(null),I(s=>[...s,r]),x(s=>[...s,{...r,items:[]}]);try{const s=await Dt(a,p);I(i=>i.map(n=>n.id===r.id?s:n)),x(i=>i.map(n=>n.id===r.id?{...s,items:[]}:n)),A.current||D(s.id)}catch(s){I(d),x(f),y(s instanceof Error?s.message:l("todo.failedCreateList","Failed to create list")),v?.(l("todo.failedCreateListToast","Failed to create todo list"),"error")}},[v,j,o,p,l]),J=c.useCallback(async(a,d)=>{const f=o,m=j;y(null),I(r=>r.map(s=>s.id===a?{...s,title:d}:s)),x(r=>r.map(s=>s.id===a?{...s,title:d}:s));try{const r=await Ft(a,d,p);I(s=>s.map(i=>i.id===a?r:i)),x(s=>s.map(i=>i.id===a?{...r,items:i.items}:i))}catch(r){I(f),x(m),y(r instanceof Error?r.message:l("todo.failedRenameList","Failed to rename list")),v?.(l("todo.failedRenameListToast","Failed to rename todo list"),"error")}},[v,j,o,p,l]),O=c.useCallback(async a=>{const d=o,f=j,m=A.current,r=m===a?o.find(s=>s.id!==a)?.id??null:m;y(null),I(s=>s.filter(i=>i.id!==a)),x(s=>s.filter(i=>i.id!==a)),m===a&&D(r);try{await $t(a,p)}catch(s){I(d),x(f),D(m),y(s instanceof Error?s.message:l("todo.failedDeleteList","Failed to delete list")),v?.(l("todo.failedDeleteListToast","Failed to delete todo list"),"error")}},[v,j,o,p,l]),S=c.useCallback(async a=>{const d=A.current;if(!d)return;const f=k,m=j,r=new Date().toISOString(),s=k.reduce((n,u)=>Math.max(n,u.sortOrder),-1),i={id:vt("temp-item"),listId:d,text:a,completed:!1,completedAt:null,createdAt:r,updatedAt:r,sortOrder:s+1};y(null),w(n=>[...n,i]),x(n=>n.map(u=>u.id===d?{...u,items:[...u.items,i]}:u));try{const n=await Rt(d,a,p);w(u=>u.map(g=>g.id===i.id?n:g)),x(u=>u.map(g=>g.id===d?{...g,items:g.items.map($=>$.id===i.id?n:$)}:g))}catch(n){w(f),x(m),y(n instanceof Error?n.message:l("todo.failedCreateItem","Failed to create item")),v?.(l("todo.failedCreateItemToast","Failed to create todo item"),"error")}},[v,k,j,p,l]),M=c.useCallback(async(a,d)=>{const f=k.find(n=>n.id===a);if(!f)return;const m=k,r=j,s=d.completed??f.completed,i={...f,...d,completed:s,completedAt:s?f.completedAt??new Date().toISOString():null,updatedAt:new Date().toISOString()};y(null),w(n=>n.map(u=>u.id===a?i:u)),x(n=>n.map(u=>u.id===i.listId?{...u,items:u.items.map(g=>g.id===a?i:g)}:u));try{const n=await Mt(a,d,p);w(u=>u.map(g=>g.id===a?n:g)),x(u=>u.map(g=>g.id===n.listId?{...g,items:g.items.map($=>$.id===a?n:$)}:g))}catch(n){w(m),x(r),y(n instanceof Error?n.message:l("todo.failedUpdateItem","Failed to update item")),v?.(l("todo.failedUpdateItemToast","Failed to update todo item"),"error")}},[v,k,j,p,l]),E=c.useCallback(async a=>{const d=k.find(f=>f.id===a);d&&await M(a,{completed:!d.completed})},[k,M]),_=c.useCallback(async a=>{const d=k,f=j;y(null),w(m=>m.filter(r=>r.id!==a)),x(m=>m.map(r=>({...r,items:r.items.filter(s=>s.id!==a)})));try{await Ot(a,p)}catch(m){w(d),x(f),y(m instanceof Error?m.message:l("todo.failedDeleteItem","Failed to delete item")),v?.(l("todo.failedDeleteItemToast","Failed to delete todo item"),"error")}},[v,k,j,p,l]),F=c.useCallback(async a=>{const d=A.current;if(!d)return;const f=k,m=j,r=new Map(k.map(i=>[i.id,i])),s=a.map((i,n)=>{const u=r.get(i);return u?{...u,sortOrder:n}:null}).filter(i=>i!==null);y(null),w(s),x(i=>i.map(n=>n.id===d?{...n,items:s}:n));try{await _t(d,a,p)}catch(i){w(f),x(m),y(i instanceof Error?i.message:l("todo.failedReorderItems","Failed to reorder items")),v?.(l("todo.failedReorderItemsToast","Failed to reorder todo items"),"error")}},[v,k,j,p,l]);return{lists:o,items:k,loading:X,error:G,selectedListId:T,setSelectedListId:D,createList:H,renameList:J,deleteList:O,createItem:S,updateItem:M,toggleItem:E,deleteItem:_,reorderItems:F}}function Qt(C){return[...C].sort((l,p)=>l.sortOrder-p.sortOrder)}function ne({projectId:C,addToast:l,onPlanningMode:p,onTaskCreated:v,mobileKeyboardActive:R=!1}){const{t:o}=Lt("app"),{lists:I,items:k,loading:w,error:X,selectedListId:N,setSelectedListId:G,createList:y,renameList:T,deleteList:D,createItem:j,updateItem:x,toggleItem:A,deleteItem:H,reorderItems:J}=qt({projectId:C,addToast:(t,h)=>{if(h==="success"||h==="error"||h==="info"||h===void 0){l(t,h);return}l(t,"info")}}),[O,S]=c.useState(null),[M,E]=c.useState(""),[_,F]=c.useState(null),[a,d]=c.useState(""),[f,m]=c.useState(""),[r,s]=c.useState(!1),[i,n]=c.useState(""),[u,g]=c.useState([]),[$,tt]=c.useState(!1),[V,U]=c.useState(!1),[et,P]=c.useState(null),Y=c.useRef(null),{confirm:yt}=Kt(),st=c.useMemo(()=>I.find(t=>t.id===N)??null,[I,N]),z=c.useMemo(()=>Qt(k.filter(t=>t.listId===N)),[k,N]);function ot(){S(null),E(""),m(""),s(!1)}function W(){F(null),d(""),n("")}function jt(t){ot(),W(),G(t)}const It=c.useCallback(async()=>{tt(!0);try{const t=await Bt(void 0,C);g(t),U(!0)}catch(t){l(o("todo.failedToLoadAgents","Failed to load agents: {{error}}",{error:q(t)}),"error"),U(!1),P(null)}finally{tt(!1)}},[C,l,o]);c.useEffect(()=>{S(null),E(""),m(""),s(!1),F(null),d(""),n(""),U(!1),P(null)},[N]),c.useEffect(()=>{if(!V)return;const t=h=>{Y.current&&!Y.current.contains(h.target)&&(U(!1),P(null))};return document.addEventListener("mousedown",t),()=>{document.removeEventListener("mousedown",t)}},[V]);function kt(t){W(),S(t.id),E(t.title),s(!1)}async function at(){if(!O)return;const t=M.trim();if(!t){S(null),E("");return}await T(O,t),S(null),E("")}function nt(){S(null),E("")}function it(t){ot(),F(t.id),d(t.text)}async function dt(){if(!_)return;const t=a.trim();if(!t){F(null),d("");return}await x(_,{text:t}),F(null),d("")}function rt(){F(null),d("")}async function lt(){const t=f.trim();t&&(await y(t),m(""),s(!1))}async function ct(){if(!N)return;const t=i.trim();t&&(await j(t),n(""))}async function Ct(t){await yt({title:o("todo.deleteListTitle","Delete List"),message:o("todo.deleteListConfirm","Delete this list and all its items?"),danger:!0})&&await D(t)}async function wt(t){await H(t)}async function mt(t,h){const L=z.map(B=>B.id),b=L.findIndex(B=>B===t);if(b<0)return;const K=h==="up"?b-1:b+1;K<0||K>=L.length||([L[b],L[K]]=[L[K],L[b]],await J(L))}const Nt=c.useCallback(async t=>{try{const h={description:t.text,column:"triage",source:{sourceType:"dashboard_ui"}},L=await pt(h,C);v?.(L),l(o("todo.taskCreatedFromTodo","Created {{id}} from todo",{id:L.id}),"success")}catch(h){l(o("todo.failedToCreateTask","Failed to create task: {{error}}",{error:q(h)}),"error")}},[C,l,v,o]),At=c.useCallback(async(t,h)=>{try{const L={description:t.text,column:"triage",assignedAgentId:h,source:{sourceType:"dashboard_ui"}},b=await pt(L,C);v?.(b);const B=u.find(St=>St.id===h)?.name??h;l(o("todo.taskCreatedAndAssigned","Created {{id}} and assigned to {{agent}}",{id:b.id,agent:B}),"success"),U(!1),P(null)}catch(L){l(o("todo.failedToCreateAndAssign","Failed to create and assign task: {{error}}",{error:q(L)}),"error")}},[C,l,u,v,o]);return w?e.jsx("div",{className:"todo-view",children:e.jsxs("div",{className:"todo-loading",children:[e.jsx(Xt,{className:"todo-loading-icon","aria-hidden":"true"}),e.jsx("p",{children:o("todo.loading","Loading todos...")})]})}):e.jsx("div",{className:`todo-view${R?" todo-view--mobile-keyboard-active":""}`,"data-testid":"todo-view-root",children:e.jsxs("div",{className:"todo-view-layout",children:[e.jsxs("aside",{className:"todo-view-sidebar","aria-label":o("todo.listsLabel","Todo lists sidebar"),children:[e.jsxs("div",{className:"todo-sidebar-header",children:[e.jsx("h3",{className:"todo-sidebar-title",children:o("todo.lists","Lists")}),e.jsx("button",{type:"button",className:"btn btn-sm btn-icon todo-add-list-btn",onClick:()=>{W(),s(!0),S(null)},"aria-label":o("todo.addList","Add list"),"data-testid":"add-list-button",children:e.jsx(zt,{})})]}),r&&e.jsxs("div",{className:"todo-list-item",children:[e.jsx("input",{className:"input todo-inline-edit-input",placeholder:o("todo.newListTitle","New list title"),value:f,onChange:t=>m(t.target.value),onKeyDown:t=>{t.key==="Enter"&&lt(),t.key==="Escape"&&(m(""),s(!1))},autoFocus:!0,"data-testid":"new-list-input"}),e.jsx("button",{type:"button",className:"btn btn-sm btn-icon todo-icon-btn",onClick:()=>{lt()},"aria-label":o("todo.saveList","Save list"),children:e.jsx(Q,{})}),e.jsx("button",{type:"button",className:"btn btn-sm btn-icon todo-icon-btn",onClick:()=>{m(""),s(!1)},"aria-label":o("todo.cancelList","Cancel list"),children:e.jsx(Z,{})})]}),I.length===0&&!r?e.jsxs("div",{className:"todo-empty-state",children:[e.jsx(ft,{"aria-hidden":"true"}),e.jsx("p",{children:o("todo.noListsEmpty","No todo lists yet. Create one to get started.")}),e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>{W(),s(!0)},children:o("todo.createList","Create List")})]}):e.jsx("div",{className:"todo-list-items",role:"list","aria-label":o("todo.todoListsLabel","Todo lists"),children:I.map(t=>{const h=t.id===N,L=t.id===O;return e.jsx("div",{className:`todo-list-item${h?" todo-list-item--active":""}`,role:"listitem",children:L?e.jsxs(e.Fragment,{children:[e.jsx("input",{className:"input todo-inline-edit-input",value:M,onChange:b=>E(b.target.value),onKeyDown:b=>{b.key==="Enter"&&at(),b.key==="Escape"&&nt()},autoFocus:!0,"data-testid":`rename-list-input-${t.id}`}),e.jsx("button",{type:"button",className:"btn btn-sm btn-icon todo-icon-btn",onClick:()=>{at()},"aria-label":o("todo.saveListRename","Save list rename"),children:e.jsx(Q,{})}),e.jsx("button",{type:"button",className:"btn btn-sm btn-icon todo-icon-btn",onClick:nt,"aria-label":o("todo.cancelListRename","Cancel list rename"),children:e.jsx(Z,{})})]}):e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:"todo-list-select-btn",onClick:()=>jt(t.id),"aria-label":o("todo.selectList","Select list {{title}}",{title:t.title}),"aria-current":h?"true":void 0,"data-testid":`todo-list-${t.id}`,children:e.jsx("span",{className:"todo-list-item-name",children:t.title})}),e.jsxs("div",{className:"todo-list-item-actions",children:[e.jsx("button",{type:"button",className:"btn btn-sm btn-icon todo-icon-btn",onClick:()=>{kt(t)},"aria-label":o("todo.renameList","Rename {{title}}",{title:t.title}),"data-testid":`rename-list-button-${t.id}`,children:e.jsx(ht,{})}),e.jsx("button",{type:"button",className:"btn btn-sm btn-icon btn-danger todo-icon-btn",onClick:()=>{Ct(t.id)},"aria-label":o("todo.deleteList","Delete {{title}}",{title:t.title}),"data-testid":`delete-list-button-${t.id}`,children:e.jsx(xt,{})})]})]})},t.id)})})]}),e.jsxs("section",{className:"todo-view-main","aria-label":o("todo.itemsLabel","Todo items"),children:[X&&e.jsxs("div",{className:"todo-error-banner",role:"alert",children:[e.jsx("span",{className:"todo-error-message",children:X}),e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>window.location.reload(),children:o("actions.retry","Retry")})]}),st?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"todo-items-header",children:e.jsx("h3",{children:st.title})}),e.jsxs("div",{className:"todo-add-item-row",children:[e.jsx("input",{className:"input",placeholder:o("todo.addItemPlaceholder","Add a todo item"),value:i,onChange:t=>n(t.target.value),onKeyDown:t=>{t.key==="Enter"&&ct(),t.key==="Escape"&&n("")},"data-testid":"new-item-input"}),e.jsx("button",{type:"button",className:"btn btn-primary",onClick:()=>{ct()},children:o("actions.add","Add")})]}),z.length===0?e.jsx("div",{className:"todo-empty-state",children:e.jsx("p",{children:o("todo.noItemsEmpty","No items in this list. Add one above.")})}):e.jsx("div",{className:"todo-items-list",children:z.map((t,h)=>{const L=t.id===_;return e.jsxs("div",{className:"todo-item","data-testid":`todo-item-${t.id}`,children:[e.jsxs("div",{className:"todo-item-main-row",children:[e.jsx("input",{type:"checkbox",checked:t.completed,onChange:()=>{A(t.id)},className:"todo-item-checkbox","aria-label":`Toggle ${t.text}`,"data-testid":`toggle-item-${t.id}`}),L?e.jsx("input",{className:"input todo-inline-edit-input",value:a,onChange:b=>d(b.target.value),onKeyDown:b=>{b.key==="Enter"&&dt(),b.key==="Escape"&&rt()},autoFocus:!0,"data-testid":`edit-item-input-${t.id}`}):e.jsx("button",{type:"button",className:`todo-item-text${t.completed?" todo-item-text--completed":""}`,onClick:()=>it(t),children:t.text})]}),e.jsx("div",{className:"todo-item-actions","data-testid":`todo-item-actions-${t.id}`,children:L?e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:"btn btn-sm btn-icon todo-icon-btn",onClick:()=>{dt()},"aria-label":o("todo.saveItemEdit","Save item edit"),children:e.jsx(Q,{})}),e.jsx("button",{type:"button",className:"btn btn-sm btn-icon todo-icon-btn",onClick:rt,"aria-label":o("todo.cancelItemEdit","Cancel item edit"),children:e.jsx(Z,{})})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"todo-item-reorder-btns",children:[e.jsx("button",{type:"button",className:"btn btn-sm btn-icon todo-item-reorder-btn",onClick:()=>{mt(t.id,"up")},disabled:h===0,"aria-label":o("todo.moveItemUp","Move {{text}} up",{text:t.text}),"data-testid":`move-up-${t.id}`,children:e.jsx(Wt,{})}),e.jsx("button",{type:"button",className:"btn btn-sm btn-icon todo-item-reorder-btn",onClick:()=>{mt(t.id,"down")},disabled:h===z.length-1,"aria-label":o("todo.moveItemDown","Move {{text}} down",{text:t.text}),"data-testid":`move-down-${t.id}`,children:e.jsx(Gt,{})})]}),e.jsx("button",{type:"button",className:"btn btn-sm btn-icon todo-icon-btn",onClick:()=>{p?.(t.text)},"aria-label":o("todo.startPlanning","Start planning from {{text}}",{text:t.text}),"data-testid":`planning-from-${t.id}`,children:e.jsx(Ht,{})}),e.jsx("button",{type:"button",className:"btn btn-sm btn-icon todo-icon-btn",onClick:()=>{Nt(t)},"aria-label":o("todo.createTaskFrom","Create task from {{text}}",{text:t.text}),"data-testid":`create-task-from-${t.id}`,children:e.jsx(Vt,{})}),e.jsxs("div",{className:"todo-agent-picker-trigger",ref:et===t.id?Y:void 0,children:[e.jsx("button",{type:"button",className:"btn btn-sm btn-icon todo-icon-btn",onClick:()=>{P(t.id),It()},"aria-label":o("todo.assignAgent","Assign {{text}} to agent",{text:t.text}),"data-testid":`assign-agent-for-${t.id}`,children:e.jsx(gt,{})}),V&&et===t.id&&e.jsx("div",{className:"todo-agent-picker-dropdown",onMouseDown:b=>{b.preventDefault()},children:$?e.jsx("div",{className:"todo-agent-picker-loading",children:o("todo.loadingAgents","Loading agents...")}):u.length>0?u.map(b=>e.jsxs("button",{type:"button",className:"todo-agent-picker-item",onClick:()=>{At(t,b.id)},children:[e.jsx(gt,{}),e.jsx("span",{children:b.name}),e.jsx("span",{className:"todo-agent-picker-role",children:b.role})]},b.id)):e.jsx("div",{className:"todo-agent-picker-empty",children:o("todo.noAgentsAvailable","No agents available")})})]}),e.jsx("button",{type:"button",className:"btn btn-sm btn-icon todo-icon-btn",onClick:()=>it(t),"aria-label":o("todo.editItem","Edit {{text}}",{text:t.text}),"data-testid":`edit-item-${t.id}`,children:e.jsx(ht,{})}),e.jsx("button",{type:"button",className:"btn btn-sm btn-icon btn-danger todo-icon-btn",onClick:()=>{wt(t.id)},"aria-label":o("todo.deleteItem","Delete {{text}}",{text:t.text}),"data-testid":`delete-item-${t.id}`,children:e.jsx(xt,{})})]})})]},t.id)})})]}):e.jsxs("div",{className:"todo-empty-state",children:[e.jsx(ft,{"aria-hidden":"true"}),e.jsx("p",{children:o("todo.selectListEmpty","Select a list from the sidebar")})]})]})]})})}export{ne as TodoView};
6
+ */const Ht=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M8 12h8",key:"1wcyev"}],["path",{d:"M12 8v8",key:"napkw2"}]],Vt=Et("circle-plus",Ht);function Yt(C){const{items:l,...p}=C;return p}function vt(C){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?`${C}-${crypto.randomUUID()}`:`${C}-${Date.now()}-${Math.random().toString(36).slice(2,10)}`}function qt(C={}){const{t:l}=Lt("app"),{projectId:p,addToast:v}=C,R=`${Tt.TODO_LISTS_PREFIX}${p??"global"}`,[o,I]=c.useState(()=>{const a=ut(R,{maxAgeMs:bt});return Array.isArray(a)?a:[]}),[k,w]=c.useState([]),[X,N]=c.useState(()=>o.length===0),[W,y]=c.useState(null),[T,D]=c.useState(null),[j,x]=c.useState([]),A=c.useRef(T);A.current=T,c.useEffect(()=>{let a=!1;const d=ut(R,{maxAgeMs:bt}),f=Array.isArray(d)&&d.length>0;f?(I(d),N(!1)):(I([]),N(!0));async function m(){f||N(!0),y(null);try{const r=await Ut(p);if(a)return;x(r);const s=r.map(Yt);I(s),Pt(R,s,{maxBytes:5e5});const i=A.current&&r.some(n=>n.id===A.current)?A.current:r[0]?.id??null;D(i),w(i?r.find(n=>n.id===i)?.items??[]:[])}catch(r){if(a)return;x([]),I([]),w([]),D(null),y(r instanceof Error?r.message:l("todo.failedLoadLists","Failed to load todo lists"))}finally{a||N(!1)}}return m(),()=>{a=!0}},[R,p]),c.useEffect(()=>{if(!T){w([]);return}const a=j.find(d=>d.id===T);w(a?.items??[])},[j,T]);const G=c.useCallback(async a=>{const d=o,f=j,m=new Date().toISOString(),r={id:vt("temp-list"),projectId:p??"",title:a,createdAt:m,updatedAt:m};y(null),I(s=>[...s,r]),x(s=>[...s,{...r,items:[]}]);try{const s=await Dt(a,p);I(i=>i.map(n=>n.id===r.id?s:n)),x(i=>i.map(n=>n.id===r.id?{...s,items:[]}:n)),A.current||D(s.id)}catch(s){I(d),x(f),y(s instanceof Error?s.message:l("todo.failedCreateList","Failed to create list")),v?.(l("todo.failedCreateListToast","Failed to create todo list"),"error")}},[v,j,o,p,l]),H=c.useCallback(async(a,d)=>{const f=o,m=j;y(null),I(r=>r.map(s=>s.id===a?{...s,title:d}:s)),x(r=>r.map(s=>s.id===a?{...s,title:d}:s));try{const r=await Ft(a,d,p);I(s=>s.map(i=>i.id===a?r:i)),x(s=>s.map(i=>i.id===a?{...r,items:i.items}:i))}catch(r){I(f),x(m),y(r instanceof Error?r.message:l("todo.failedRenameList","Failed to rename list")),v?.(l("todo.failedRenameListToast","Failed to rename todo list"),"error")}},[v,j,o,p,l]),O=c.useCallback(async a=>{const d=o,f=j,m=A.current,r=m===a?o.find(s=>s.id!==a)?.id??null:m;y(null),I(s=>s.filter(i=>i.id!==a)),x(s=>s.filter(i=>i.id!==a)),m===a&&D(r);try{await $t(a,p)}catch(s){I(d),x(f),D(m),y(s instanceof Error?s.message:l("todo.failedDeleteList","Failed to delete list")),v?.(l("todo.failedDeleteListToast","Failed to delete todo list"),"error")}},[v,j,o,p,l]),S=c.useCallback(async a=>{const d=A.current;if(!d)return;const f=k,m=j,r=new Date().toISOString(),s=k.reduce((n,u)=>Math.max(n,u.sortOrder),-1),i={id:vt("temp-item"),listId:d,text:a,completed:!1,completedAt:null,createdAt:r,updatedAt:r,sortOrder:s+1};y(null),w(n=>[...n,i]),x(n=>n.map(u=>u.id===d?{...u,items:[...u.items,i]}:u));try{const n=await Rt(d,a,p);w(u=>u.map(g=>g.id===i.id?n:g)),x(u=>u.map(g=>g.id===d?{...g,items:g.items.map($=>$.id===i.id?n:$)}:g))}catch(n){w(f),x(m),y(n instanceof Error?n.message:l("todo.failedCreateItem","Failed to create item")),v?.(l("todo.failedCreateItemToast","Failed to create todo item"),"error")}},[v,k,j,p,l]),M=c.useCallback(async(a,d)=>{const f=k.find(n=>n.id===a);if(!f)return;const m=k,r=j,s=d.completed??f.completed,i={...f,...d,completed:s,completedAt:s?f.completedAt??new Date().toISOString():null,updatedAt:new Date().toISOString()};y(null),w(n=>n.map(u=>u.id===a?i:u)),x(n=>n.map(u=>u.id===i.listId?{...u,items:u.items.map(g=>g.id===a?i:g)}:u));try{const n=await Mt(a,d,p);w(u=>u.map(g=>g.id===a?n:g)),x(u=>u.map(g=>g.id===n.listId?{...g,items:g.items.map($=>$.id===a?n:$)}:g))}catch(n){w(m),x(r),y(n instanceof Error?n.message:l("todo.failedUpdateItem","Failed to update item")),v?.(l("todo.failedUpdateItemToast","Failed to update todo item"),"error")}},[v,k,j,p,l]),E=c.useCallback(async a=>{const d=k.find(f=>f.id===a);d&&await M(a,{completed:!d.completed})},[k,M]),_=c.useCallback(async a=>{const d=k,f=j;y(null),w(m=>m.filter(r=>r.id!==a)),x(m=>m.map(r=>({...r,items:r.items.filter(s=>s.id!==a)})));try{await Ot(a,p)}catch(m){w(d),x(f),y(m instanceof Error?m.message:l("todo.failedDeleteItem","Failed to delete item")),v?.(l("todo.failedDeleteItemToast","Failed to delete todo item"),"error")}},[v,k,j,p,l]),F=c.useCallback(async a=>{const d=A.current;if(!d)return;const f=k,m=j,r=new Map(k.map(i=>[i.id,i])),s=a.map((i,n)=>{const u=r.get(i);return u?{...u,sortOrder:n}:null}).filter(i=>i!==null);y(null),w(s),x(i=>i.map(n=>n.id===d?{...n,items:s}:n));try{await _t(d,a,p)}catch(i){w(f),x(m),y(i instanceof Error?i.message:l("todo.failedReorderItems","Failed to reorder items")),v?.(l("todo.failedReorderItemsToast","Failed to reorder todo items"),"error")}},[v,k,j,p,l]);return{lists:o,items:k,loading:X,error:W,selectedListId:T,setSelectedListId:D,createList:G,renameList:H,deleteList:O,createItem:S,updateItem:M,toggleItem:E,deleteItem:_,reorderItems:F}}function Qt(C){return[...C].sort((l,p)=>l.sortOrder-p.sortOrder)}function ne({projectId:C,addToast:l,onPlanningMode:p,onTaskCreated:v,mobileKeyboardActive:R=!1}){const{t:o}=Lt("app"),{lists:I,items:k,loading:w,error:X,selectedListId:N,setSelectedListId:W,createList:y,renameList:T,deleteList:D,createItem:j,updateItem:x,toggleItem:A,deleteItem:G,reorderItems:H}=qt({projectId:C,addToast:(t,h)=>{if(h==="success"||h==="error"||h==="info"||h===void 0){l(t,h);return}l(t,"info")}}),[O,S]=c.useState(null),[M,E]=c.useState(""),[_,F]=c.useState(null),[a,d]=c.useState(""),[f,m]=c.useState(""),[r,s]=c.useState(!1),[i,n]=c.useState(""),[u,g]=c.useState([]),[$,tt]=c.useState(!1),[V,U]=c.useState(!1),[et,P]=c.useState(null),Y=c.useRef(null),{confirm:yt}=Kt(),st=c.useMemo(()=>I.find(t=>t.id===N)??null,[I,N]),z=c.useMemo(()=>Qt(k.filter(t=>t.listId===N)),[k,N]);function ot(){S(null),E(""),m(""),s(!1)}function J(){F(null),d(""),n("")}function jt(t){ot(),J(),W(t)}const It=c.useCallback(async()=>{tt(!0);try{const t=await Bt(void 0,C);g(t),U(!0)}catch(t){l(o("todo.failedToLoadAgents","Failed to load agents: {{error}}",{error:q(t)}),"error"),U(!1),P(null)}finally{tt(!1)}},[C,l,o]);c.useEffect(()=>{S(null),E(""),m(""),s(!1),F(null),d(""),n(""),U(!1),P(null)},[N]),c.useEffect(()=>{if(!V)return;const t=h=>{Y.current&&!Y.current.contains(h.target)&&(U(!1),P(null))};return document.addEventListener("mousedown",t),()=>{document.removeEventListener("mousedown",t)}},[V]);function kt(t){J(),S(t.id),E(t.title),s(!1)}async function at(){if(!O)return;const t=M.trim();if(!t){S(null),E("");return}await T(O,t),S(null),E("")}function nt(){S(null),E("")}function it(t){ot(),F(t.id),d(t.text)}async function dt(){if(!_)return;const t=a.trim();if(!t){F(null),d("");return}await x(_,{text:t}),F(null),d("")}function rt(){F(null),d("")}async function lt(){const t=f.trim();t&&(await y(t),m(""),s(!1))}async function ct(){if(!N)return;const t=i.trim();t&&(await j(t),n(""))}async function Ct(t){await yt({title:o("todo.deleteListTitle","Delete List"),message:o("todo.deleteListConfirm","Delete this list and all its items?"),danger:!0})&&await D(t)}async function wt(t){await G(t)}async function mt(t,h){const L=z.map(B=>B.id),b=L.findIndex(B=>B===t);if(b<0)return;const K=h==="up"?b-1:b+1;K<0||K>=L.length||([L[b],L[K]]=[L[K],L[b]],await H(L))}const Nt=c.useCallback(async t=>{try{const h={description:t.text,column:"triage",source:{sourceType:"dashboard_ui"}},L=await pt(h,C);v?.(L),l(o("todo.taskCreatedFromTodo","Created {{id}} from todo",{id:L.id}),"success")}catch(h){l(o("todo.failedToCreateTask","Failed to create task: {{error}}",{error:q(h)}),"error")}},[C,l,v,o]),At=c.useCallback(async(t,h)=>{try{const L={description:t.text,column:"triage",assignedAgentId:h,source:{sourceType:"dashboard_ui"}},b=await pt(L,C);v?.(b);const B=u.find(St=>St.id===h)?.name??h;l(o("todo.taskCreatedAndAssigned","Created {{id}} and assigned to {{agent}}",{id:b.id,agent:B}),"success"),U(!1),P(null)}catch(L){l(o("todo.failedToCreateAndAssign","Failed to create and assign task: {{error}}",{error:q(L)}),"error")}},[C,l,u,v,o]);return w?e.jsx("div",{className:"todo-view",children:e.jsxs("div",{className:"todo-loading",children:[e.jsx(Xt,{className:"todo-loading-icon","aria-hidden":"true"}),e.jsx("p",{children:o("todo.loading","Loading todos...")})]})}):e.jsx("div",{className:`todo-view${R?" todo-view--mobile-keyboard-active":""}`,"data-testid":"todo-view-root",children:e.jsxs("div",{className:"todo-view-layout",children:[e.jsxs("aside",{className:"todo-view-sidebar","aria-label":o("todo.listsLabel","Todo lists sidebar"),children:[e.jsxs("div",{className:"todo-sidebar-header",children:[e.jsx("h3",{className:"todo-sidebar-title",children:o("todo.lists","Lists")}),e.jsx("button",{type:"button",className:"btn btn-sm btn-icon todo-add-list-btn",onClick:()=>{J(),s(!0),S(null)},"aria-label":o("todo.addList","Add list"),"data-testid":"add-list-button",children:e.jsx(zt,{})})]}),r&&e.jsxs("div",{className:"todo-list-item",children:[e.jsx("input",{className:"input todo-inline-edit-input",placeholder:o("todo.newListTitle","New list title"),value:f,onChange:t=>m(t.target.value),onKeyDown:t=>{t.key==="Enter"&&lt(),t.key==="Escape"&&(m(""),s(!1))},autoFocus:!0,"data-testid":"new-list-input"}),e.jsx("button",{type:"button",className:"btn btn-sm btn-icon todo-icon-btn",onClick:()=>{lt()},"aria-label":o("todo.saveList","Save list"),children:e.jsx(Q,{})}),e.jsx("button",{type:"button",className:"btn btn-sm btn-icon todo-icon-btn",onClick:()=>{m(""),s(!1)},"aria-label":o("todo.cancelList","Cancel list"),children:e.jsx(Z,{})})]}),I.length===0&&!r?e.jsxs("div",{className:"todo-empty-state",children:[e.jsx(ft,{"aria-hidden":"true"}),e.jsx("p",{children:o("todo.noListsEmpty","No todo lists yet. Create one to get started.")}),e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>{J(),s(!0)},children:o("todo.createList","Create List")})]}):e.jsx("div",{className:"todo-list-items",role:"list","aria-label":o("todo.todoListsLabel","Todo lists"),children:I.map(t=>{const h=t.id===N,L=t.id===O;return e.jsx("div",{className:`todo-list-item${h?" todo-list-item--active":""}`,role:"listitem",children:L?e.jsxs(e.Fragment,{children:[e.jsx("input",{className:"input todo-inline-edit-input",value:M,onChange:b=>E(b.target.value),onKeyDown:b=>{b.key==="Enter"&&at(),b.key==="Escape"&&nt()},autoFocus:!0,"data-testid":`rename-list-input-${t.id}`}),e.jsx("button",{type:"button",className:"btn btn-sm btn-icon todo-icon-btn",onClick:()=>{at()},"aria-label":o("todo.saveListRename","Save list rename"),children:e.jsx(Q,{})}),e.jsx("button",{type:"button",className:"btn btn-sm btn-icon todo-icon-btn",onClick:nt,"aria-label":o("todo.cancelListRename","Cancel list rename"),children:e.jsx(Z,{})})]}):e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:"todo-list-select-btn",onClick:()=>jt(t.id),"aria-label":o("todo.selectList","Select list {{title}}",{title:t.title}),"aria-current":h?"true":void 0,"data-testid":`todo-list-${t.id}`,children:e.jsx("span",{className:"todo-list-item-name",children:t.title})}),e.jsxs("div",{className:"todo-list-item-actions",children:[e.jsx("button",{type:"button",className:"btn btn-sm btn-icon todo-icon-btn",onClick:()=>{kt(t)},"aria-label":o("todo.renameList","Rename {{title}}",{title:t.title}),"data-testid":`rename-list-button-${t.id}`,children:e.jsx(ht,{})}),e.jsx("button",{type:"button",className:"btn btn-sm btn-icon btn-danger todo-icon-btn",onClick:()=>{Ct(t.id)},"aria-label":o("todo.deleteList","Delete {{title}}",{title:t.title}),"data-testid":`delete-list-button-${t.id}`,children:e.jsx(xt,{})})]})]})},t.id)})})]}),e.jsxs("section",{className:"todo-view-main","aria-label":o("todo.itemsLabel","Todo items"),children:[X&&e.jsxs("div",{className:"todo-error-banner",role:"alert",children:[e.jsx("span",{className:"todo-error-message",children:X}),e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>window.location.reload(),children:o("actions.retry","Retry")})]}),st?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"todo-items-header",children:e.jsx("h3",{children:st.title})}),e.jsxs("div",{className:"todo-add-item-row",children:[e.jsx("input",{className:"input",placeholder:o("todo.addItemPlaceholder","Add a todo item"),value:i,onChange:t=>n(t.target.value),onKeyDown:t=>{t.key==="Enter"&&ct(),t.key==="Escape"&&n("")},"data-testid":"new-item-input"}),e.jsx("button",{type:"button",className:"btn btn-primary",onClick:()=>{ct()},children:o("actions.add","Add")})]}),z.length===0?e.jsx("div",{className:"todo-empty-state",children:e.jsx("p",{children:o("todo.noItemsEmpty","No items in this list. Add one above.")})}):e.jsx("div",{className:"todo-items-list",children:z.map((t,h)=>{const L=t.id===_;return e.jsxs("div",{className:"todo-item","data-testid":`todo-item-${t.id}`,children:[e.jsxs("div",{className:"todo-item-main-row",children:[e.jsx("input",{type:"checkbox",checked:t.completed,onChange:()=>{A(t.id)},className:"todo-item-checkbox","aria-label":`Toggle ${t.text}`,"data-testid":`toggle-item-${t.id}`}),L?e.jsx("input",{className:"input todo-inline-edit-input",value:a,onChange:b=>d(b.target.value),onKeyDown:b=>{b.key==="Enter"&&dt(),b.key==="Escape"&&rt()},autoFocus:!0,"data-testid":`edit-item-input-${t.id}`}):e.jsx("button",{type:"button",className:`todo-item-text${t.completed?" todo-item-text--completed":""}`,onClick:()=>it(t),children:t.text})]}),e.jsx("div",{className:"todo-item-actions","data-testid":`todo-item-actions-${t.id}`,children:L?e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:"btn btn-sm btn-icon todo-icon-btn",onClick:()=>{dt()},"aria-label":o("todo.saveItemEdit","Save item edit"),children:e.jsx(Q,{})}),e.jsx("button",{type:"button",className:"btn btn-sm btn-icon todo-icon-btn",onClick:rt,"aria-label":o("todo.cancelItemEdit","Cancel item edit"),children:e.jsx(Z,{})})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"todo-item-reorder-btns",children:[e.jsx("button",{type:"button",className:"btn btn-sm btn-icon todo-item-reorder-btn",onClick:()=>{mt(t.id,"up")},disabled:h===0,"aria-label":o("todo.moveItemUp","Move {{text}} up",{text:t.text}),"data-testid":`move-up-${t.id}`,children:e.jsx(Jt,{})}),e.jsx("button",{type:"button",className:"btn btn-sm btn-icon todo-item-reorder-btn",onClick:()=>{mt(t.id,"down")},disabled:h===z.length-1,"aria-label":o("todo.moveItemDown","Move {{text}} down",{text:t.text}),"data-testid":`move-down-${t.id}`,children:e.jsx(Wt,{})})]}),e.jsx("button",{type:"button",className:"btn btn-sm btn-icon todo-icon-btn",onClick:()=>{p?.(t.text)},"aria-label":o("todo.startPlanning","Start planning from {{text}}",{text:t.text}),"data-testid":`planning-from-${t.id}`,children:e.jsx(Gt,{})}),e.jsx("button",{type:"button",className:"btn btn-sm btn-icon todo-icon-btn",onClick:()=>{Nt(t)},"aria-label":o("todo.createTaskFrom","Create task from {{text}}",{text:t.text}),"data-testid":`create-task-from-${t.id}`,children:e.jsx(Vt,{})}),e.jsxs("div",{className:"todo-agent-picker-trigger",ref:et===t.id?Y:void 0,children:[e.jsx("button",{type:"button",className:"btn btn-sm btn-icon todo-icon-btn",onClick:()=>{P(t.id),It()},"aria-label":o("todo.assignAgent","Assign {{text}} to agent",{text:t.text}),"data-testid":`assign-agent-for-${t.id}`,children:e.jsx(gt,{})}),V&&et===t.id&&e.jsx("div",{className:"todo-agent-picker-dropdown",onMouseDown:b=>{b.preventDefault()},children:$?e.jsx("div",{className:"todo-agent-picker-loading",children:o("todo.loadingAgents","Loading agents...")}):u.length>0?u.map(b=>e.jsxs("button",{type:"button",className:"todo-agent-picker-item",onClick:()=>{At(t,b.id)},children:[e.jsx(gt,{}),e.jsx("span",{children:b.name}),e.jsx("span",{className:"todo-agent-picker-role",children:b.role})]},b.id)):e.jsx("div",{className:"todo-agent-picker-empty",children:o("todo.noAgentsAvailable","No agents available")})})]}),e.jsx("button",{type:"button",className:"btn btn-sm btn-icon todo-icon-btn",onClick:()=>it(t),"aria-label":o("todo.editItem","Edit {{text}}",{text:t.text}),"data-testid":`edit-item-${t.id}`,children:e.jsx(ht,{})}),e.jsx("button",{type:"button",className:"btn btn-sm btn-icon btn-danger todo-icon-btn",onClick:()=>{wt(t.id)},"aria-label":o("todo.deleteItem","Delete {{text}}",{text:t.text}),"data-testid":`delete-item-${t.id}`,children:e.jsx(xt,{})})]})})]},t.id)})})]}):e.jsxs("div",{className:"todo-empty-state",children:[e.jsx(ft,{"aria-hidden":"true"}),e.jsx("p",{children:o("todo.selectListEmpty","Select a list from the sidebar")})]})]})]})})}export{ne as TodoView};