coder-config 0.44.19 → 0.44.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/constants.js CHANGED
@@ -2,7 +2,7 @@
2
2
  * Constants and tool path configurations
3
3
  */
4
4
 
5
- const VERSION = '0.44.19';
5
+ const VERSION = '0.44.21';
6
6
 
7
7
  // Tool-specific path configurations
8
8
  const TOOL_PATHS = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "coder-config",
3
- "version": "0.44.19",
3
+ "version": "0.44.21",
4
4
  "description": "Configuration manager for AI coding tools - Claude Code, Gemini CLI, Codex CLI, Antigravity. Manage MCPs, rules, permissions, memory, and workstreams.",
5
5
  "author": "regression.io",
6
6
  "main": "config-loader.js",
@@ -2979,7 +2979,7 @@ When reporting issues, include:
2979
2979
 
2980
2980
  These projects are frequently worked on together.`),f(!0)},$r=X=>{T(we=>we.filter(Te=>Te!==X))},tr=X=>{P.includes(X)||T(we=>[...we,X])},fr=async X=>{const we=B[X];if(!we&&!q[X]){Q(Te=>({...Te,[X]:!0}));try{const Te=await xe.getSubprojects(X);H($e=>({...$e,[X]:Te.subprojects||[]}))}catch(Te){console.error("Failed to load subprojects:",Te),H($e=>({...$e,[X]:[]}))}finally{Q(Te=>({...Te,[X]:!1}))}}z(Te=>({...Te,[X]:!we}))},ln=X=>{const we=X.projects.sort().join("|"),Te=[...W,we];le(Te),localStorage.setItem("dismissedWorkstreamSuggestions",JSON.stringify(Te)),fe($e=>$e.filter(Ve=>Ve.projects.sort().join("|")!==we)),Y.success("Suggestion dismissed")},fs=ne.filter(X=>{const we=X.projects.sort().join("|");return!W.includes(we)}),ms=async()=>{if(confirm("Clear activity data older than 30 days?"))try{const X=await xe.clearActivity(30);X.success&&(Y.success(`Cleared ${X.cleared} old entries`),Br())}catch(X){Y.error("Failed to clear activity: "+X.message)}},cn=async(X,we)=>{if(!X||X.length===0){Y.error("Add projects first to generate rules");return}Z(!0);try{const Te=await xe.generateWorkstreamRules(X,oe);Te.success&&Te.rules?(we(Te.rules),Y.success(oe?"Generated rules with Claude":"Generated rules from repos")):Y.error(Te.error||"Failed to generate rules")}catch(Te){Y.error("Failed to generate rules: "+Te.message)}finally{Z(!1)}},it=async()=>{L(!0);try{const X=await xe.installWorkstreamHook();X.success?(Y.success(X.message),F(we=>({...we,isInstalled:!0}))):Y.error(X.error||"Failed to install hook")}catch(X){Y.error("Failed to install hook: "+X.message)}finally{L(!1)}},Mt=async()=>{Ee(!0);try{const X=await xe.installCdHook();X.success?(Y.success("CD hook installed. Restart your shell to activate."),je(we=>({...we,installed:!0}))):Y.error(X.error||"Failed to install CD hook")}catch(X){Y.error("Failed to install CD hook: "+X.message)}finally{Ee(!1)}},Ut=async()=>{Ee(!0);try{const X=await xe.uninstallCdHook();X.success?(Y.success("CD hook uninstalled. Restart your shell to apply."),je(we=>({...we,installed:!1}))):Y.error(X.error||"Failed to uninstall CD hook")}catch(X){Y.error("Failed to uninstall CD hook: "+X.message)}finally{Ee(!1)}},cr=async()=>{const X=!ye.workstreamAutoActivate;try{await xe.setGlobalAutoActivate(X),Ne(we=>({...we,workstreamAutoActivate:X})),Y.success(`Auto-activation ${X?"enabled":"disabled"}`)}catch(we){Y.error("Failed to update setting: "+we.message)}},es=async(X,we)=>{try{(await xe.setWorkstreamAutoActivate(X.id,we)).success&&(n($e=>$e.map(Ve=>Ve.id===X.id?{...Ve,autoActivate:we==="default"?void 0:we==="on"}:Ve)),Y.success(`Auto-activate ${we} for ${X.name}`))}catch(Te){Y.error("Failed to update: "+Te.message)}},Gt=async()=>{if(!(!Ae||!Fe.trim()))try{const X=await xe.addTriggerFolder(Ae.id,Fe.trim());X.success&&(n(we=>we.map(Te=>Te.id===Ae.id?X.workstream:Te)),Y.success("Trigger folder added"),de(!1),pt(""),ze(null))}catch(X){Y.error("Failed to add trigger folder: "+X.message)}},rr=async(X,we)=>{try{const Te=await xe.removeTriggerFolder(X.id,we);Te.success&&(n($e=>$e.map(Ve=>Ve.id===X.id?Te.workstream:Ve)),Y.success("Trigger folder removed"))}catch(Te){Y.error("Failed to remove trigger folder: "+Te.message)}},ps=async()=>{try{d(!0);const X=await xe.getWorkstreams();n(X.workstreams||[])}catch{Y.error("Failed to load workstreams")}finally{d(!1)}},sr=async()=>{if(!g.trim()){Y.error("Name is required");return}M(!0);try{const X=await xe.createWorkstream(g.trim(),P,k);X.success?(n(we=>[...we,X.workstream]),Y.success(`Created workstream: ${g}`),f(!1),v(""),E(""),T([]),fe(we=>we.filter(Te=>Te.name!==g.trim()))):Y.error(X.error||"Failed to create workstream")}catch(X){Y.error("Failed to create workstream: "+X.message)}finally{M(!1)}},Tr=async X=>{if(confirm(`Delete workstream "${X.name}"?
2981
2981
 
2982
- This cannot be undone.`))try{const we=await xe.deleteWorkstream(X.id);we.success?(n(Te=>Te.filter($e=>$e.id!==X.id)),Y.success(`Deleted workstream: ${X.name}`)):Y.error(we.error||"Failed to delete workstream")}catch(we){Y.error("Failed to delete workstream: "+we.message)}},qr=async()=>{if(m){M(!0);try{const X=await xe.updateWorkstream(m.id,{name:m.name,rules:m.rules,projects:m.projects||[]});X.success?(n(we=>we.map(Te=>Te.id===m.id?X.workstream:Te)),Y.success("Workstream updated"),h(null)):Y.error(X.error||"Failed to update workstream")}catch(X){Y.error("Failed to update workstream: "+X.message)}finally{M(!1)}}},_r=X=>{Ue(X.id),be(X.rules||"")},Tn=()=>{Ue(null),be("")},Zn=async X=>{Ye(!0);try{const we=await xe.updateWorkstream(X.id,{name:X.name,rules:ue,projects:X.projects||[]});we.success?(n(Te=>Te.map($e=>$e.id===X.id?we.workstream:$e)),Y.success("Rules updated"),Ue(null),be("")):Y.error(we.error||"Failed to update rules")}catch(we){Y.error("Failed to update rules: "+we.message)}finally{Ye(!1)}},Li=X=>{b(we=>{const Te=new Set(we);return Te.has(X)?Te.delete(X):Te.add(X),Te})},Oi=async()=>{if(!j||y.size===0)return;M(!0);let X=0,we=null;for(const Te of y)try{const $e=await xe.addProjectToWorkstream(j.id,Te);$e.success&&(we=$e.workstream,X++)}catch($e){console.error("Failed to add project:",Te,$e)}we&&n(Te=>Te.map($e=>$e.id===j.id?we:$e)),X>0?Y.success(`Added ${X} project${X>1?"s":""} to ${j.name}`):Y.error("Failed to add projects"),M(!1),w(!1),_(null),b(new Set)},bo=async(X,we)=>{try{const Te=await xe.removeProjectFromWorkstream(X.id,we);Te.success?(n($e=>$e.map(Ve=>Ve.id===X.id?Te.workstream:Ve)),Y.success(`Removed project from ${X.name}`)):Y.error(Te.error||"Failed to remove project")}catch(Te){Y.error("Failed to remove project: "+Te.message)}},As=X=>X.split("/").pop()||X,Fi=X=>s.filter(we=>{var Te;return(Te=we.projects)==null?void 0:Te.includes(X)}).length,Ts=(X,we=null)=>{var Ve,wt;const Te=Fi(X),$e=we?(wt=(Ve=s.find(dr=>dr.id===we))==null?void 0:Ve.projects)==null?void 0:wt.includes(X):!1;return Te===0?null:Te===1?$e?null:"in use":"shared"};return o?r.jsx("div",{className:"flex items-center justify-center h-64",children:r.jsx(Ze,{className:"w-8 h-8 animate-spin text-indigo-600"})}):r.jsxs("div",{className:"space-y-6",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx("div",{className:"w-10 h-10 rounded-lg bg-purple-100 dark:bg-purple-900/30 flex items-center justify-center",children:r.jsx(gn,{className:"w-5 h-5 text-purple-600 dark:text-purple-400"})}),r.jsxs("div",{children:[r.jsx("h2",{className:"text-lg font-semibold text-gray-900 dark:text-white",children:"Workstreams"}),r.jsx("p",{className:"text-sm text-gray-500 dark:text-slate-400",children:"Context sets for multi-project workflows"})]})]}),r.jsxs("div",{className:"flex gap-2",children:[r.jsxs(te,{variant:"outline",onClick:ps,size:"sm",children:[r.jsx(wr,{className:"w-4 h-4 mr-2"}),"Refresh"]}),r.jsxs(te,{onClick:()=>f(!0),className:"bg-purple-600 hover:bg-purple-700",children:[r.jsx(jt,{className:"w-4 h-4 mr-2"}),"New Workstream"]})]})]}),r.jsx("div",{className:"bg-purple-50 dark:bg-purple-950/30 border border-purple-200 dark:border-purple-800 rounded-lg p-4 text-sm text-purple-700 dark:text-purple-400",children:r.jsxs("p",{children:[r.jsx("strong",{children:"Workstreams"})," let you group related repos together so Claude sees them as one cohesive project. Perfect for microservices, monorepos, or any multi-repo setup where context matters. Your custom rules and context persist across sessions, and Claude stays scoped to only the directories you specify."]})}),r.jsx("div",{className:"bg-white dark:bg-slate-950 rounded-xl border border-gray-200 dark:border-slate-800 shadow-sm overflow-hidden",children:s.length===0?r.jsxs("div",{className:"p-12 text-center",children:[r.jsx(gn,{className:"w-12 h-12 mx-auto mb-4 text-gray-300 dark:text-slate-600"}),r.jsx("h3",{className:"text-lg font-medium text-gray-900 dark:text-white mb-2",children:"No Workstreams Yet"}),r.jsx("p",{className:"text-sm text-gray-500 dark:text-slate-400 mb-4",children:"Create your first workstream to organize multi-project contexts."}),r.jsxs(te,{onClick:()=>f(!0),children:[r.jsx(jt,{className:"w-4 h-4 mr-2"}),"Create Your First Workstream"]})]}):r.jsx("div",{className:"divide-y divide-gray-100 dark:divide-slate-800",children:s.map(X=>{var we,Te,$e,Ve;return r.jsxs("div",{className:"group",children:[r.jsxs("div",{className:"p-4 flex items-center gap-4 transition-colors cursor-pointer hover:bg-gray-50 dark:hover:bg-slate-900",onClick:()=>l(u===X.id?null:X.id),children:[r.jsx("div",{className:"w-5 h-5 flex items-center justify-center text-gray-400",children:u===X.id?r.jsx(vr,{className:"w-4 h-4"}):r.jsx(Qr,{className:"w-4 h-4"})}),r.jsx("div",{className:"w-10 h-10 rounded-lg flex items-center justify-center bg-gray-100 dark:bg-slate-800",children:r.jsx(gn,{className:"w-5 h-5 text-gray-500 dark:text-slate-400"})}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("h3",{className:"font-medium truncate text-gray-900 dark:text-white",children:X.name}),((we=X.projects)==null?void 0:we.length)>0&&r.jsxs("span",{className:"text-xs bg-gray-100 dark:bg-slate-800 text-gray-600 dark:text-slate-400 px-1.5 py-0.5 rounded",children:[X.projects.length," project",X.projects.length!==1?"s":""]}),X.rules&&r.jsxs("span",{className:"text-xs bg-blue-100 dark:bg-blue-900/30 text-blue-600 dark:text-blue-400 px-1.5 py-0.5 rounded",children:[r.jsx(Pr,{className:"w-3 h-3 inline mr-0.5"}),"Rules"]})]}),r.jsx("p",{className:"text-sm text-gray-500 dark:text-slate-400 truncate",children:((Te=X.projects)==null?void 0:Te.length)>0?X.projects.map(wt=>As(wt)).join(", "):"No projects added"})]}),r.jsxs("div",{className:"flex items-center gap-2",onClick:wt=>wt.stopPropagation(),children:[r.jsx(te,{size:"sm",variant:"ghost",onClick:()=>h({...X}),className:"text-gray-500 dark:text-slate-400 hover:text-purple-600 dark:hover:text-purple-400",title:"Edit workstream",children:r.jsx(rm,{className:"w-4 h-4"})}),r.jsx(te,{size:"sm",variant:"ghost",onClick:()=>Tr(X),className:"text-gray-500 dark:text-slate-400 hover:text-red-600 dark:hover:text-red-400",title:"Delete workstream",children:r.jsx(ds,{className:"w-4 h-4"})})]})]}),u===X.id&&r.jsxs("div",{className:"px-4 pb-4 pl-16 space-y-4 bg-gray-50/50 dark:bg-slate-900/50",children:[r.jsxs("div",{children:[r.jsxs("div",{className:"flex items-center justify-between mb-2",children:[r.jsx("h4",{className:"text-sm font-medium text-gray-700 dark:text-slate-300",children:"Projects"}),r.jsxs(te,{size:"sm",variant:"outline",onClick:()=>{_(X),w(!0)},children:[r.jsx(zn,{className:"w-4 h-4 mr-1"}),"Add Project"]})]}),(($e=X.projects)==null?void 0:$e.length)>0?r.jsx("div",{className:"space-y-1",children:X.projects.map(wt=>r.jsxs("div",{className:"flex items-center justify-between py-1.5 px-3 bg-white dark:bg-slate-800 rounded border border-gray-200 dark:border-slate-700",children:[r.jsx("span",{className:"text-sm font-mono text-gray-700 dark:text-slate-300 truncate",children:wt.replace(/^\/Users\/[^/]+/,"~")}),r.jsx(te,{size:"sm",variant:"ghost",onClick:()=>bo(X,wt),className:"text-gray-400 hover:text-red-500 h-6 w-6 p-0",children:r.jsx(yb,{className:"w-4 h-4"})})]},wt))}):r.jsx("p",{className:"text-sm text-gray-500 dark:text-slate-400 italic",children:"No projects added yet. Add projects to help organize your workstream."})]}),r.jsxs("div",{children:[r.jsxs("div",{className:"flex items-center justify-between mb-2",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("h4",{className:"text-sm font-medium text-gray-700 dark:text-slate-300",children:"Trigger Folders"}),r.jsx(xr,{children:r.jsxs(Ot,{children:[r.jsx(Ft,{asChild:!0,children:r.jsx(ra,{className:"w-3.5 h-3.5 text-gray-400"})}),r.jsx(Rt,{children:r.jsx("p",{className:"max-w-xs text-xs",children:"Additional folders that activate this workstream when you cd into them. Projects are always trigger folders automatically."})})]})})]}),r.jsxs(te,{size:"sm",variant:"outline",onClick:()=>{ze(X),de(!0)},children:[r.jsx(zn,{className:"w-4 h-4 mr-1"}),"Add Folder"]})]}),((Ve=X.triggerFolders)==null?void 0:Ve.length)>0?r.jsx("div",{className:"space-y-1",children:X.triggerFolders.map(wt=>r.jsxs("div",{className:"flex items-center justify-between py-1.5 px-3 bg-white dark:bg-slate-800 rounded border border-gray-200 dark:border-slate-700",children:[r.jsx("span",{className:"text-sm font-mono text-gray-700 dark:text-slate-300 truncate",children:wt.replace(/^\/Users\/[^/]+/,"~")}),r.jsx(te,{size:"sm",variant:"ghost",onClick:()=>rr(X,wt),className:"text-gray-400 hover:text-red-500 h-6 w-6 p-0",children:r.jsx(yb,{className:"w-4 h-4"})})]},wt))}):r.jsx("p",{className:"text-sm text-gray-500 dark:text-slate-400 italic",children:"No extra trigger folders. Projects auto-trigger this workstream."})]}),r.jsxs("div",{className:"flex items-center justify-between py-2 px-3 bg-white dark:bg-slate-800 rounded border border-gray-200 dark:border-slate-700",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(no,{className:"w-4 h-4 text-amber-500"}),r.jsx("span",{className:"text-sm font-medium text-gray-700 dark:text-slate-300",children:"Auto-Activate on cd"})]}),r.jsxs(Xn,{children:[r.jsx(Jn,{asChild:!0,children:r.jsxs(te,{variant:"outline",size:"sm",children:[X.autoActivate===!0?"On":X.autoActivate===!1?"Off":"Default",r.jsx(vr,{className:"w-3 h-3 ml-1"})]})}),r.jsxs(jn,{align:"end",children:[r.jsxs(At,{onClick:()=>es(X,"on"),children:[r.jsx(Tt,{className:`w-4 h-4 mr-2 ${X.autoActivate===!0?"opacity-100":"opacity-0"}`}),"On"]}),r.jsxs(At,{onClick:()=>es(X,"off"),children:[r.jsx(Tt,{className:`w-4 h-4 mr-2 ${X.autoActivate===!1?"opacity-100":"opacity-0"}`}),"Off"]}),r.jsxs(At,{onClick:()=>es(X,"default"),children:[r.jsx(Tt,{className:`w-4 h-4 mr-2 ${X.autoActivate===void 0?"opacity-100":"opacity-0"}`}),"Default (",ye.workstreamAutoActivate?"On":"Off",")"]})]})]})]}),r.jsxs("div",{children:[r.jsxs("div",{className:"flex items-center justify-between mb-2",children:[r.jsx("h4",{className:"text-sm font-medium text-gray-700 dark:text-slate-300",children:"Rules"}),Be===X.id?r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsxs(te,{size:"sm",variant:"ghost",onClick:Tn,disabled:Qe,className:"text-gray-500 dark:text-slate-400 h-7",children:[r.jsx(Hn,{className:"w-4 h-4 mr-1"}),"Cancel"]}),r.jsxs(te,{size:"sm",onClick:()=>Zn(X),disabled:Qe,className:"bg-purple-600 hover:bg-purple-700 h-7",children:[Qe?r.jsx(Ze,{className:"w-4 h-4 animate-spin mr-1"}):r.jsx(Ps,{className:"w-4 h-4 mr-1"}),"Save"]})]}):r.jsxs(te,{size:"sm",variant:"ghost",onClick:()=>_r(X),className:"text-gray-500 dark:text-slate-400 hover:text-purple-600 dark:hover:text-purple-400 h-7",children:[r.jsx(rm,{className:"w-4 h-4 mr-1"}),"Edit"]})]}),Be===X.id?r.jsx(_t,{value:ue,onChange:wt=>be(wt.target.value),placeholder:"Context rules for this workstream. These will be injected into every Claude session when this workstream is active.",rows:8,className:"font-mono text-sm",autoFocus:!0}):X.rules?r.jsx("pre",{className:"text-sm text-gray-600 dark:text-slate-400 bg-white dark:bg-slate-800 rounded border border-gray-200 dark:border-slate-700 p-3 overflow-auto max-h-40 whitespace-pre-wrap cursor-pointer hover:border-purple-300 dark:hover:border-purple-700 transition-colors",onClick:()=>_r(X),title:"Click to edit",children:X.rules}):r.jsx("p",{className:"text-sm text-gray-500 dark:text-slate-400 italic cursor-pointer hover:text-purple-600 dark:hover:text-purple-400 transition-colors",onClick:()=>_r(X),children:"No rules defined. Click to add context rules for this workstream."})]})]})]},X.id)})})}),r.jsxs("div",{className:"space-y-3",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("h3",{className:"text-sm font-medium text-gray-700 dark:text-slate-300",children:"Hook Integration"}),r.jsx(xr,{children:r.jsxs(Ot,{children:[r.jsx(Ft,{asChild:!0,children:r.jsx("button",{className:"text-gray-400 hover:text-gray-600 dark:hover:text-slate-300",children:r.jsx(ra,{className:"w-4 h-4"})})}),r.jsx(Rt,{side:"right",className:"max-w-xs",children:r.jsxs("p",{className:"text-sm",children:[r.jsx("strong",{children:"What are hooks?"}),r.jsx("br",{}),r.jsx("br",{}),"Hooks are scripts that run automatically at specific points in Claude Code sessions. The workstream hook runs before each prompt and injects your active workstream's rules into the context.",r.jsx("br",{}),r.jsx("br",{}),r.jsx("strong",{children:"How it works:"}),r.jsx("br",{}),"1. You activate a workstream",r.jsx("br",{}),"2. Hook detects the active workstream",r.jsx("br",{}),"3. Rules are prepended to Claude's context",r.jsx("br",{}),"4. Claude understands your project context"]})})]})})]}),K.isInstalled?r.jsx("div",{className:"bg-green-50 dark:bg-green-950/30 border border-green-200 dark:border-green-800 rounded-lg p-4 text-sm text-green-700 dark:text-green-400",children:r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(ao,{className:"w-5 h-5 flex-shrink-0"}),r.jsxs("div",{children:[r.jsx("p",{className:"font-medium",children:"Hook Installed"}),r.jsx("p",{className:"text-green-600 dark:text-green-500",children:"Workstream rules will be automatically injected into every Claude session."})]})]})}):r.jsx("div",{className:"bg-amber-50 dark:bg-amber-950/30 border border-amber-200 dark:border-amber-800 rounded-lg p-4 text-sm text-amber-700 dark:text-amber-400",children:r.jsxs("div",{className:"flex gap-3",children:[r.jsx(ks,{className:"w-5 h-5 flex-shrink-0 mt-0.5"}),r.jsxs("div",{className:"flex-1",children:[r.jsx("p",{className:"font-medium mb-1",children:"Hook Not Installed"}),r.jsx("p",{className:"mb-3",children:"Install the pre-prompt hook to automatically inject workstream rules into every Claude session."}),r.jsxs(te,{onClick:it,disabled:R||K.loading,size:"sm",className:"bg-amber-600 hover:bg-amber-700 text-white",children:[R?r.jsx(Ze,{className:"w-4 h-4 animate-spin mr-2"}):r.jsx(Kn,{className:"w-4 h-4 mr-2"}),"Install Hook"]}),r.jsxs("p",{className:"text-xs mt-2 text-amber-600 dark:text-amber-500",children:["Creates ",r.jsx("code",{className:"bg-amber-100 dark:bg-amber-900/50 px-1 rounded",children:"~/.claude/hooks/pre-prompt.sh"})]})]})]})})]}),r.jsxs("div",{className:"space-y-3",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("h3",{className:"text-sm font-medium text-gray-700 dark:text-slate-300",children:"Folder Auto-Activation"}),r.jsx(xr,{children:r.jsxs(Ot,{children:[r.jsx(Ft,{asChild:!0,children:r.jsx(ra,{className:"w-4 h-4 text-gray-400"})}),r.jsxs(Rt,{className:"max-w-sm",children:[r.jsx("p",{className:"text-sm mb-2",children:r.jsx("strong",{children:"How it works:"})}),r.jsxs("ol",{className:"text-xs space-y-1 list-decimal list-inside",children:[r.jsx("li",{children:"Install the CD hook to your shell"}),r.jsxs("li",{children:["When you ",r.jsx("code",{className:"bg-slate-700 px-1 rounded",children:"cd"})," into a folder matching a workstream, it auto-activates"]}),r.jsx("li",{children:"If multiple workstreams match, you'll be prompted to choose"})]})]})]})})]}),r.jsxs("div",{className:"bg-white dark:bg-slate-950 rounded-xl border border-gray-200 dark:border-slate-800 shadow-sm p-4",children:[r.jsxs("div",{className:"flex items-center justify-between mb-4 pb-4 border-b border-gray-200 dark:border-slate-800",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(no,{className:"w-4 h-4 text-amber-500"}),r.jsx("span",{className:"text-sm font-medium text-gray-700 dark:text-slate-300",children:"Global Auto-Activate"}),r.jsx("span",{className:"text-xs text-gray-500 dark:text-slate-400",children:"(default for all workstreams)"})]}),r.jsx(te,{variant:ye.workstreamAutoActivate?"default":"outline",size:"sm",onClick:cr,children:ye.workstreamAutoActivate?"Enabled":"Disabled"})]}),lt.installed?r.jsxs("div",{className:"flex items-start gap-3 p-3 bg-green-50 dark:bg-green-900/20 rounded-lg border border-green-200 dark:border-green-800",children:[r.jsx(ao,{className:"w-5 h-5 text-green-600 dark:text-green-400 flex-shrink-0 mt-0.5"}),r.jsxs("div",{className:"flex-1",children:[r.jsx("p",{className:"font-medium text-green-800 dark:text-green-300",children:"CD Hook Installed"}),r.jsxs("p",{className:"text-xs text-green-600 dark:text-green-400 mt-1",children:["Shell: ",lt.shell," • RC file: ",r.jsx("code",{className:"bg-green-100 dark:bg-green-900/50 px-1 rounded",children:(Bi=lt.rcFile)==null?void 0:Bi.replace(/^\/Users\/[^/]+/,"~")})]}),r.jsxs(te,{variant:"outline",size:"sm",className:"mt-2",onClick:Ut,disabled:_e,children:[_e?r.jsx(Ze,{className:"w-4 h-4 animate-spin mr-2"}):null,"Uninstall"]})]})]}):r.jsxs("div",{className:"flex items-start gap-3 p-3 bg-amber-50 dark:bg-amber-900/20 rounded-lg border border-amber-200 dark:border-amber-800",children:[r.jsx(ks,{className:"w-5 h-5 text-amber-600 dark:text-amber-400 flex-shrink-0 mt-0.5"}),r.jsxs("div",{children:[r.jsx("p",{className:"font-medium text-amber-800 dark:text-amber-300 mb-1",children:"CD Hook Not Installed"}),r.jsx("p",{className:"text-xs text-amber-600 dark:text-amber-400 mb-2",children:"Install the hook to auto-activate workstreams when you cd into matching folders."}),r.jsxs(te,{variant:"default",size:"sm",onClick:Mt,disabled:_e||lt.loading,className:"bg-amber-600 hover:bg-amber-700 text-white",children:[_e?r.jsx(Ze,{className:"w-4 h-4 animate-spin mr-2"}):r.jsx(Kn,{className:"w-4 h-4 mr-2"}),"Install CD Hook"]}),r.jsxs("p",{className:"text-xs mt-2 text-amber-600 dark:text-amber-500",children:["Adds function to ",r.jsx("code",{className:"bg-amber-100 dark:bg-amber-900/50 px-1 rounded",children:"~/.zshrc"})," or ",r.jsx("code",{className:"bg-amber-100 dark:bg-amber-900/50 px-1 rounded",children:"~/.bashrc"})]})]})]})]})]}),U&&U.totalSessions>0&&r.jsxs("div",{className:"bg-white dark:bg-slate-950 rounded-xl border border-gray-200 dark:border-slate-800 shadow-sm p-4",children:[r.jsxs("div",{className:"flex items-center justify-between mb-4",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(i5,{className:"w-5 h-5 text-indigo-600 dark:text-indigo-400"}),r.jsx("h3",{className:"font-medium text-gray-900 dark:text-white",children:"Activity Insights"})]}),r.jsxs(te,{variant:"ghost",size:"sm",onClick:ms,className:"text-gray-500 dark:text-slate-400 hover:text-red-500",children:[r.jsx(ds,{className:"w-4 h-4 mr-1"}),"Clear Old"]})]}),r.jsxs("div",{className:"grid grid-cols-3 gap-4 mb-4",children:[r.jsxs("div",{className:"bg-gray-50 dark:bg-slate-900 rounded-lg p-3",children:[r.jsxs("div",{className:"flex items-center gap-2 text-gray-500 dark:text-slate-400 text-xs mb-1",children:[r.jsx(BC,{className:"w-3 h-3"}),"Sessions"]}),r.jsx("div",{className:"text-2xl font-semibold text-gray-900 dark:text-white",children:U.totalSessions})]}),r.jsxs("div",{className:"bg-gray-50 dark:bg-slate-900 rounded-lg p-3",children:[r.jsxs("div",{className:"flex items-center gap-2 text-gray-500 dark:text-slate-400 text-xs mb-1",children:[r.jsx(Pr,{className:"w-3 h-3"}),"Files Tracked"]}),r.jsx("div",{className:"text-2xl font-semibold text-gray-900 dark:text-white",children:U.totalFiles})]}),r.jsxs("div",{className:"bg-gray-50 dark:bg-slate-900 rounded-lg p-3",children:[r.jsxs("div",{className:"flex items-center gap-2 text-gray-500 dark:text-slate-400 text-xs mb-1",children:[r.jsx(gn,{className:"w-3 h-3"}),"Projects Active"]}),r.jsx("div",{className:"text-2xl font-semibold text-gray-900 dark:text-white",children:U.projectCount})]})]}),((ei=U.topProjects)==null?void 0:ei.length)>0&&r.jsxs("div",{children:[r.jsx("h4",{className:"text-sm font-medium text-gray-700 dark:text-slate-300 mb-2",children:"Most Active Projects"}),r.jsx("div",{className:"space-y-1",children:U.topProjects.slice(0,5).map((X,we)=>r.jsxs("div",{className:"flex items-center justify-between text-sm",children:[r.jsx("span",{className:"text-gray-600 dark:text-slate-400 truncate",title:X.path,children:X.path.split("/").pop()}),r.jsxs("span",{className:"text-gray-400 dark:text-slate-500 text-xs",children:[X.fileCount," files"]})]},X.path))})]})]}),fs.length>0&&r.jsxs("div",{className:"bg-gradient-to-r from-indigo-50 to-purple-50 dark:from-indigo-950/30 dark:to-purple-950/30 rounded-xl border border-indigo-200 dark:border-indigo-800 p-4",children:[r.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[r.jsx(Yt,{className:"w-5 h-5 text-indigo-600 dark:text-indigo-400"}),r.jsx("h3",{className:"font-medium text-indigo-900 dark:text-indigo-300",children:"Suggested Workstreams"}),r.jsx("span",{className:"text-xs bg-indigo-100 dark:bg-indigo-900/50 text-indigo-600 dark:text-indigo-400 px-1.5 py-0.5 rounded",children:"Based on activity patterns"})]}),r.jsx("p",{className:"text-sm text-indigo-700 dark:text-indigo-400 mb-4",children:"These projects are frequently worked on together. Create a workstream to group them?"}),r.jsx("div",{className:"space-y-3",children:fs.map(X=>r.jsxs("div",{className:"bg-white dark:bg-slate-900 rounded-lg border border-indigo-200 dark:border-indigo-800 p-3",children:[r.jsxs("div",{className:"flex items-center justify-between mb-2",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(no,{className:"w-4 h-4 text-amber-500"}),r.jsx("span",{className:"font-medium text-gray-900 dark:text-white",children:X.name}),X.coActivityScore&&r.jsxs("span",{className:"text-xs text-gray-500 dark:text-slate-400",children:[X.coActivityScore,"% co-activity"]})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(te,{size:"sm",variant:"ghost",onClick:()=>ln(X),className:"text-gray-400 hover:text-gray-600 dark:hover:text-slate-300",title:"Dismiss suggestion",children:r.jsx(Hn,{className:"w-4 h-4"})}),r.jsxs(te,{size:"sm",onClick:()=>$t(X),className:"bg-indigo-600 hover:bg-indigo-700",children:[r.jsx(jt,{className:"w-4 h-4 mr-1"}),"Create"]})]})]}),r.jsx("div",{className:"flex flex-wrap gap-1",children:X.projects.map(we=>r.jsx("span",{className:"text-xs bg-gray-100 dark:bg-slate-800 text-gray-600 dark:text-slate-400 px-2 py-0.5 rounded",children:we.split("/").pop()},we))})]},X.name))})]}),r.jsxs("div",{className:"bg-gray-50 dark:bg-slate-900 rounded-lg p-4 border border-transparent dark:border-slate-800",children:[r.jsx("h4",{className:"text-sm font-medium text-gray-900 dark:text-white mb-2",children:"CLI Commands"}),r.jsxs("div",{className:"space-y-1 text-sm text-gray-600 dark:text-slate-400 font-mono",children:[r.jsx("p",{children:"coder-config workstream # List workstreams"}),r.jsx("p",{children:'coder-config workstream use "Name" # Set workstream for this tab'}),r.jsx("p",{children:'coder-config workstream create "Name" # Create workstream'})]})]}),r.jsx(bt,{open:c,onOpenChange:X=>{X||(f(!1),v(""),E(""),T([]),O(!1),z({}))},children:r.jsxs(xt,{className:"max-w-lg max-h-[85vh] overflow-y-auto",children:[r.jsx(vt,{children:r.jsxs(yt,{className:"flex items-center gap-2",children:[r.jsx(gn,{className:"w-5 h-5 text-purple-600"}),"Create Workstream"]})}),r.jsxs("div",{className:"space-y-4 py-4",children:[r.jsxs("div",{children:[r.jsx("label",{className:"text-sm font-medium text-gray-700 dark:text-slate-300 mb-1 block",children:"Name"}),r.jsx(dt,{value:g,onChange:X=>v(X.target.value),placeholder:"e.g., User Auth, Admin Dashboard",autoFocus:!0})]}),r.jsxs("div",{children:[r.jsxs("div",{className:"flex items-center justify-between mb-2",children:[r.jsx("label",{className:"text-sm font-medium text-gray-700 dark:text-slate-300",children:"Projects"}),r.jsxs(te,{type:"button",size:"sm",variant:"outline",onClick:()=>O(!I),children:[r.jsx(zn,{className:"w-4 h-4 mr-1"}),"Add"]})]}),P.length>0?r.jsx("div",{className:"space-y-1 mb-2",children:P.map(X=>r.jsxs("div",{className:"flex items-center justify-between py-1.5 px-3 bg-gray-50 dark:bg-slate-800 rounded border border-gray-200 dark:border-slate-700",children:[r.jsx("span",{className:"text-sm font-mono text-gray-700 dark:text-slate-300 truncate",children:X.replace(/^\/Users\/[^/]+/,"~")}),r.jsx(te,{type:"button",size:"sm",variant:"ghost",onClick:()=>$r(X),className:"text-gray-400 hover:text-red-500 h-6 w-6 p-0",children:r.jsx(Hn,{className:"w-4 h-4"})})]},X))}):r.jsx("p",{className:"text-sm text-gray-500 dark:text-slate-400 italic mb-2",children:"No projects added. Add projects to help organize your workstream."}),I&&e.length>0&&r.jsx("div",{className:"border border-gray-200 dark:border-slate-700 rounded-lg p-2 max-h-64 overflow-y-auto bg-white dark:bg-slate-900",children:e.map(X=>{const we=Ts(X.path),Te=B[X.path],$e=G[X.path],Ve=q[X.path]||[],wt=P.includes(X.path);return r.jsxs("div",{className:"mb-1",children:[r.jsxs("div",{className:"flex items-center gap-1",children:[r.jsx("button",{type:"button",onClick:()=>fr(X.path),className:"p-1 hover:bg-gray-100 dark:hover:bg-slate-800 rounded",title:"Show sub-projects",children:$e?r.jsx(Ze,{className:"w-4 h-4 animate-spin text-gray-400"}):Te?r.jsx(vr,{className:"w-4 h-4 text-gray-400"}):r.jsx(Qr,{className:"w-4 h-4 text-gray-400"})}),r.jsxs("button",{type:"button",onClick:()=>tr(X.path),disabled:wt,className:`flex-1 text-left p-2 rounded transition-colors ${wt?"bg-purple-50 dark:bg-purple-950/30 opacity-50":"hover:bg-purple-50 dark:hover:bg-purple-950/30"}`,children:[r.jsxs("div",{className:"flex items-center justify-between text-sm",children:[r.jsx("span",{className:"font-medium text-gray-900 dark:text-white",children:X.name}),r.jsxs("div",{className:"flex items-center gap-1",children:[we&&r.jsx("span",{className:`text-xs px-1.5 py-0.5 rounded ${we==="shared"?"bg-amber-100 dark:bg-amber-900/50 text-amber-700 dark:text-amber-400":"bg-blue-100 dark:bg-blue-900/50 text-blue-700 dark:text-blue-400"}`,children:we}),wt&&r.jsx(Tt,{className:"w-4 h-4 text-purple-600"})]})]}),r.jsx("div",{className:"text-xs text-gray-500 dark:text-slate-400 font-mono truncate",children:X.path.replace(/^\/Users\/[^/]+/,"~")})]})]}),Te&&Ve.length>0&&r.jsx("div",{className:"ml-6 mt-1 space-y-1 border-l-2 border-gray-200 dark:border-slate-700 pl-2",children:Ve.map(dr=>{const Xt=P.includes(dr.dir),Cr=Ts(dr.dir);return r.jsxs("button",{type:"button",onClick:()=>tr(dr.dir),disabled:Xt,className:`w-full text-left p-2 rounded transition-colors ${Xt?"bg-purple-50 dark:bg-purple-950/30 opacity-50":"hover:bg-purple-50 dark:hover:bg-purple-950/30"}`,children:[r.jsxs("div",{className:"flex items-center justify-between text-sm",children:[r.jsx("span",{className:"text-gray-700 dark:text-slate-300",children:dr.name}),r.jsxs("div",{className:"flex items-center gap-1",children:[Cr&&r.jsx("span",{className:`text-xs px-1.5 py-0.5 rounded ${Cr==="shared"?"bg-amber-100 dark:bg-amber-900/50 text-amber-700 dark:text-amber-400":"bg-blue-100 dark:bg-blue-900/50 text-blue-700 dark:text-blue-400"}`,children:Cr}),Xt&&r.jsx(Tt,{className:"w-4 h-4 text-purple-600"})]})]}),r.jsx("div",{className:"text-xs text-gray-500 dark:text-slate-400 font-mono",children:dr.relativePath})]},dr.dir)})}),Te&&Ve.length===0&&!$e&&r.jsx("div",{className:"ml-6 mt-1 pl-2 text-xs text-gray-400 dark:text-slate-500 italic",children:"No sub-projects found"})]},X.id)})})]}),r.jsxs("div",{children:[r.jsxs("div",{className:"flex items-center justify-between mb-1",children:[r.jsx("label",{className:"text-sm font-medium text-gray-700 dark:text-slate-300",children:"Context (optional)"}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsxs("label",{className:"flex items-center gap-1.5 text-xs text-gray-500 dark:text-slate-400 cursor-pointer",children:[r.jsx(ho,{checked:oe,onCheckedChange:Se,className:"h-3.5 w-3.5"}),"Use Claude"]}),r.jsxs(te,{type:"button",size:"sm",variant:"ghost",onClick:()=>cn(P,E),disabled:re||P.length===0,className:"text-xs h-7 text-purple-600 hover:text-purple-700 hover:bg-purple-50 dark:hover:bg-purple-950/30",title:oe?"Use Claude Code to analyze repos":"Extract from README, package.json, etc.",children:[re?r.jsx(Ze,{className:"w-3 h-3 animate-spin mr-1"}):r.jsx(zs,{className:"w-3 h-3 mr-1"}),"Generate"]})]})]}),r.jsx(_t,{value:k,onChange:X=>E(X.target.value),placeholder:"Context rules for this workstream. These will be injected into every Claude session when this workstream is active.",rows:6}),r.jsx("p",{className:"text-xs text-gray-500 dark:text-slate-400 mt-1",children:'Example: "Focus on user authentication. Use JWT tokens. React Query for state management."'})]})]}),r.jsxs(St,{children:[r.jsx(te,{variant:"outline",onClick:()=>{f(!1),v(""),E(""),T([]),O(!1),z({})},children:"Cancel"}),r.jsxs(te,{onClick:sr,disabled:N||!g.trim(),className:"bg-purple-600 hover:bg-purple-700",children:[N?r.jsx(Ze,{className:"w-4 h-4 animate-spin mr-2"}):r.jsx(jt,{className:"w-4 h-4 mr-2"}),"Create"]})]})]})}),r.jsx(bt,{open:!!m,onOpenChange:X=>!X&&h(null),children:r.jsxs(xt,{className:"max-w-lg max-h-[85vh] overflow-y-auto",children:[r.jsx(vt,{children:r.jsxs(yt,{className:"flex items-center gap-2",children:[r.jsx(rm,{className:"w-5 h-5 text-purple-600"}),"Edit Workstream"]})}),m&&r.jsxs("div",{className:"space-y-4 py-4",children:[r.jsxs("div",{children:[r.jsx("label",{className:"text-sm font-medium text-gray-700 dark:text-slate-300 mb-1 block",children:"Name"}),r.jsx(dt,{value:m.name,onChange:X=>h(we=>({...we,name:X.target.value}))})]}),r.jsxs("div",{children:[r.jsxs("div",{className:"flex items-center justify-between mb-2",children:[r.jsx("label",{className:"text-sm font-medium text-gray-700 dark:text-slate-300",children:"Projects"}),r.jsxs(te,{type:"button",size:"sm",variant:"outline",onClick:()=>h(X=>({...X,showPicker:!X.showPicker})),children:[r.jsx(zn,{className:"w-4 h-4 mr-1"}),"Add"]})]}),((ti=m.projects)==null?void 0:ti.length)>0?r.jsx("div",{className:"space-y-1 mb-2",children:m.projects.map(X=>r.jsxs("div",{className:"flex items-center justify-between py-1.5 px-3 bg-gray-50 dark:bg-slate-800 rounded border border-gray-200 dark:border-slate-700",children:[r.jsx("span",{className:"text-sm font-mono text-gray-700 dark:text-slate-300 truncate",children:X.replace(/^\/Users\/[^/]+/,"~")}),r.jsx(te,{type:"button",size:"sm",variant:"ghost",onClick:()=>h(we=>({...we,projects:we.projects.filter(Te=>Te!==X)})),className:"text-gray-400 hover:text-red-500 h-6 w-6 p-0",children:r.jsx(Hn,{className:"w-4 h-4"})})]},X))}):r.jsx("p",{className:"text-sm text-gray-500 dark:text-slate-400 italic mb-2",children:"No projects in this workstream."}),m.showPicker&&e.length>0&&r.jsx("div",{className:"border border-gray-200 dark:border-slate-700 rounded-lg p-2 max-h-48 overflow-y-auto bg-white dark:bg-slate-900",children:e.map(X=>{var dr;const we=(dr=m.projects)==null?void 0:dr.includes(X.path),Te=Ts(X.path,m.id),$e=B[X.path],Ve=G[X.path],wt=q[X.path]||[];return r.jsxs("div",{className:"mb-1",children:[r.jsxs("div",{className:"flex items-center gap-1",children:[r.jsx("button",{type:"button",onClick:()=>fr(X.path),className:"p-1 hover:bg-gray-100 dark:hover:bg-slate-800 rounded",title:"Show sub-projects",children:Ve?r.jsx(Ze,{className:"w-4 h-4 animate-spin text-gray-400"}):$e?r.jsx(vr,{className:"w-4 h-4 text-gray-400"}):r.jsx(Qr,{className:"w-4 h-4 text-gray-400"})}),r.jsxs("button",{type:"button",onClick:()=>!we&&h(Xt=>({...Xt,projects:[...Xt.projects||[],X.path]})),disabled:we,className:`flex-1 text-left p-2 rounded transition-colors ${we?"bg-purple-50 dark:bg-purple-950/30 opacity-50":"hover:bg-purple-50 dark:hover:bg-purple-950/30"}`,children:[r.jsxs("div",{className:"flex items-center justify-between text-sm",children:[r.jsx("span",{className:"font-medium text-gray-900 dark:text-white",children:X.name}),r.jsxs("div",{className:"flex items-center gap-1",children:[Te&&r.jsx("span",{className:`text-xs px-1.5 py-0.5 rounded ${Te==="shared"?"bg-amber-100 dark:bg-amber-900/50 text-amber-700 dark:text-amber-400":"bg-blue-100 dark:bg-blue-900/50 text-blue-700 dark:text-blue-400"}`,children:Te}),we&&r.jsx(Tt,{className:"w-4 h-4 text-purple-600"})]})]}),r.jsx("div",{className:"text-xs text-gray-500 dark:text-slate-400 font-mono truncate",children:X.path.replace(/^\/Users\/[^/]+/,"~")})]})]}),$e&&wt.length>0&&r.jsx("div",{className:"ml-6 mt-1 space-y-1 border-l-2 border-gray-200 dark:border-slate-700 pl-2",children:wt.map(Xt=>{var Ks;const Cr=(Ks=m.projects)==null?void 0:Ks.includes(Xt.dir),gs=Ts(Xt.dir,m.id);return r.jsxs("button",{type:"button",onClick:()=>!Cr&&h(Rr=>({...Rr,projects:[...Rr.projects||[],Xt.dir]})),disabled:Cr,className:`w-full text-left p-2 rounded transition-colors ${Cr?"bg-purple-50 dark:bg-purple-950/30 opacity-50":"hover:bg-purple-50 dark:hover:bg-purple-950/30"}`,children:[r.jsxs("div",{className:"flex items-center justify-between text-sm",children:[r.jsx("span",{className:"text-gray-700 dark:text-slate-300",children:Xt.name}),r.jsxs("div",{className:"flex items-center gap-1",children:[gs&&r.jsx("span",{className:`text-xs px-1.5 py-0.5 rounded ${gs==="shared"?"bg-amber-100 dark:bg-amber-900/50 text-amber-700 dark:text-amber-400":"bg-blue-100 dark:bg-blue-900/50 text-blue-700 dark:text-blue-400"}`,children:gs}),Cr&&r.jsx(Tt,{className:"w-4 h-4 text-purple-600"})]})]}),r.jsx("div",{className:"text-xs text-gray-500 dark:text-slate-400 font-mono truncate",children:Xt.relativePath})]},Xt.dir)})}),$e&&wt.length===0&&!Ve&&r.jsx("div",{className:"ml-6 mt-1 pl-2 text-xs text-gray-400 dark:text-slate-500 italic",children:"No sub-projects found"})]},X.id)})})]}),r.jsxs("div",{children:[r.jsxs("div",{className:"flex items-center justify-between mb-1",children:[r.jsx("label",{className:"text-sm font-medium text-gray-700 dark:text-slate-300",children:"Rules"}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsxs("label",{className:"flex items-center gap-1.5 text-xs text-gray-500 dark:text-slate-400 cursor-pointer",children:[r.jsx(ho,{checked:oe,onCheckedChange:Se,className:"h-3.5 w-3.5"}),"Use Claude"]}),r.jsxs(te,{type:"button",size:"sm",variant:"ghost",onClick:()=>cn(m.projects,X=>h(we=>({...we,rules:X}))),disabled:re||!((ce=m.projects)!=null&&ce.length),className:"text-xs h-7 text-purple-600 hover:text-purple-700 hover:bg-purple-50 dark:hover:bg-purple-950/30",title:oe?"Use Claude Code to analyze repos":"Extract from README, package.json, etc.",children:[re?r.jsx(Ze,{className:"w-3 h-3 animate-spin mr-1"}):r.jsx(zs,{className:"w-3 h-3 mr-1"}),"Generate"]})]})]}),r.jsx(_t,{value:m.rules||"",onChange:X=>h(we=>({...we,rules:X.target.value})),placeholder:"Context rules for this workstream...",rows:8})]})]}),r.jsxs(St,{children:[r.jsx(te,{variant:"outline",onClick:()=>h(null),children:"Cancel"}),r.jsxs(te,{onClick:qr,disabled:N,className:"bg-purple-600 hover:bg-purple-700",children:[N?r.jsx(Ze,{className:"w-4 h-4 animate-spin mr-2"}):r.jsx(Ps,{className:"w-4 h-4 mr-2"}),"Save Changes"]})]})]})}),r.jsx(bt,{open:x,onOpenChange:X=>{w(X),X||(z({}),b(new Set))},children:r.jsxs(xt,{className:"max-w-lg",children:[r.jsx(vt,{children:r.jsxs(yt,{className:"flex items-center gap-2",children:[r.jsx(zn,{className:"w-5 h-5 text-purple-600"}),"Add Project to ",j==null?void 0:j.name]})}),r.jsxs("div",{className:"py-4",children:[r.jsx("p",{className:"text-sm text-gray-600 dark:text-slate-400 mb-4",children:"Select projects to add to this workstream (multi-select enabled):"}),e.length>0?r.jsx("div",{className:"space-y-1 max-h-64 overflow-y-auto border border-gray-200 dark:border-slate-700 rounded-lg p-2 bg-white dark:bg-slate-900",children:e.map(X=>{var Xt;const we=(Xt=j==null?void 0:j.projects)==null?void 0:Xt.includes(X.path),Te=y.has(X.path),$e=Ts(X.path,j==null?void 0:j.id),Ve=B[X.path],wt=G[X.path],dr=q[X.path]||[];return r.jsxs("div",{className:"mb-1",children:[r.jsxs("div",{className:"flex items-center gap-1",children:[r.jsx("button",{type:"button",onClick:()=>fr(X.path),className:"p-1 hover:bg-gray-100 dark:hover:bg-slate-800 rounded",title:"Show sub-projects",children:wt?r.jsx(Ze,{className:"w-4 h-4 animate-spin text-gray-400"}):Ve?r.jsx(vr,{className:"w-4 h-4 text-gray-400"}):r.jsx(Qr,{className:"w-4 h-4 text-gray-400"})}),r.jsxs("button",{type:"button",onClick:()=>!we&&Li(X.path),disabled:we,className:`flex-1 text-left p-2 rounded transition-colors ${we?"bg-gray-100 dark:bg-slate-800 opacity-50 cursor-not-allowed":Te?"bg-purple-100 dark:bg-purple-950/50 ring-2 ring-purple-500":"hover:bg-purple-50 dark:hover:bg-purple-950/30"}`,children:[r.jsxs("div",{className:"flex items-center justify-between text-sm",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("div",{className:`w-4 h-4 rounded border-2 flex items-center justify-center ${we?"bg-gray-300 dark:bg-slate-600 border-gray-300 dark:border-slate-600":Te?"bg-purple-600 border-purple-600":"border-gray-300 dark:border-slate-600"}`,children:(we||Te)&&r.jsx(Tt,{className:"w-3 h-3 text-white"})}),r.jsx("span",{className:"font-medium text-gray-900 dark:text-white",children:X.name})]}),r.jsxs("div",{className:"flex items-center gap-1",children:[$e&&r.jsx("span",{className:`text-xs px-1.5 py-0.5 rounded ${$e==="shared"?"bg-amber-100 dark:bg-amber-900/50 text-amber-700 dark:text-amber-400":"bg-blue-100 dark:bg-blue-900/50 text-blue-700 dark:text-blue-400"}`,children:$e}),we&&r.jsx("span",{className:"text-xs text-gray-500 dark:text-slate-400",children:"added"})]})]}),r.jsx("div",{className:"text-xs text-gray-500 dark:text-slate-400 font-mono truncate ml-6",children:X.path.replace(/^\/Users\/[^/]+/,"~")})]})]}),Ve&&dr.length>0&&r.jsx("div",{className:"ml-6 mt-1 space-y-1 border-l-2 border-gray-200 dark:border-slate-700 pl-2",children:dr.map(Cr=>{var hc;const gs=(hc=j==null?void 0:j.projects)==null?void 0:hc.includes(Cr.dir),Ks=y.has(Cr.dir),Rr=Ts(Cr.dir,j==null?void 0:j.id);return r.jsxs("button",{type:"button",onClick:()=>!gs&&Li(Cr.dir),disabled:gs,className:`w-full text-left p-2 rounded transition-colors ${gs?"bg-gray-100 dark:bg-slate-800 opacity-50 cursor-not-allowed":Ks?"bg-purple-100 dark:bg-purple-950/50 ring-2 ring-purple-500":"hover:bg-purple-50 dark:hover:bg-purple-950/30"}`,children:[r.jsxs("div",{className:"flex items-center justify-between text-sm",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("div",{className:`w-4 h-4 rounded border-2 flex items-center justify-center ${gs?"bg-gray-300 dark:bg-slate-600 border-gray-300 dark:border-slate-600":Ks?"bg-purple-600 border-purple-600":"border-gray-300 dark:border-slate-600"}`,children:(gs||Ks)&&r.jsx(Tt,{className:"w-3 h-3 text-white"})}),r.jsx("span",{className:"text-gray-700 dark:text-slate-300",children:Cr.name})]}),r.jsxs("div",{className:"flex items-center gap-1",children:[Rr&&r.jsx("span",{className:`text-xs px-1.5 py-0.5 rounded ${Rr==="shared"?"bg-amber-100 dark:bg-amber-900/50 text-amber-700 dark:text-amber-400":"bg-blue-100 dark:bg-blue-900/50 text-blue-700 dark:text-blue-400"}`,children:Rr}),gs&&r.jsx("span",{className:"text-xs text-gray-500 dark:text-slate-400",children:"added"})]})]}),r.jsx("div",{className:"text-xs text-gray-500 dark:text-slate-400 font-mono truncate ml-6",children:Cr.relativePath})]},Cr.dir)})}),Ve&&dr.length===0&&!wt&&r.jsx("div",{className:"ml-6 mt-1 pl-2 text-xs text-gray-400 dark:text-slate-500 italic",children:"No sub-projects found"})]},X.id)})}):r.jsx("p",{className:"text-sm text-gray-500 dark:text-slate-400 text-center py-4",children:"No projects registered. Add projects in the Projects view first."})]}),r.jsxs(St,{children:[r.jsx(te,{variant:"outline",onClick:()=>{w(!1),b(new Set)},children:"Cancel"}),r.jsxs(te,{onClick:Oi,disabled:y.size===0||N,className:"bg-purple-600 hover:bg-purple-700",children:[N?r.jsx(Ze,{className:"w-4 h-4 animate-spin mr-2"}):r.jsx(jt,{className:"w-4 h-4 mr-2"}),"Add Selected (",y.size,")"]})]})]})}),r.jsx(bt,{open:ie,onOpenChange:X=>{X||(de(!1),pt(""),ze(null))},children:r.jsxs(xt,{children:[r.jsx(vt,{children:r.jsx(yt,{children:"Add Trigger Folder"})}),r.jsxs("div",{className:"space-y-4 py-4",children:[r.jsxs("p",{className:"text-sm text-gray-600 dark:text-slate-400",children:["Add a folder that will trigger the workstream ",r.jsx("strong",{children:Ae==null?void 0:Ae.name})," when you cd into it."]}),r.jsxs("div",{children:[r.jsx("label",{className:"text-sm font-medium text-gray-700 dark:text-slate-300 mb-1 block",children:"Folder Path"}),r.jsx(dt,{value:Fe,onChange:X=>pt(X.target.value),placeholder:"~/path/to/folder",className:"font-mono"}),r.jsx("p",{className:"text-xs text-gray-500 dark:text-slate-400 mt-1",children:"Use absolute path or ~ for home directory"})]})]}),r.jsxs(St,{children:[r.jsx(te,{variant:"outline",onClick:()=>{de(!1),pt(""),ze(null)},children:"Cancel"}),r.jsxs(te,{onClick:Gt,disabled:!Fe.trim(),className:"bg-purple-600 hover:bg-purple-700",children:[r.jsx(zn,{className:"w-4 h-4 mr-2"}),"Add Folder"]})]})]})})]})}const e_={clarify:"bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-200",plan:"bg-purple-100 text-purple-800 dark:bg-purple-900 dark:text-purple-200",execute:"bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-200"},Yo={pending:r.jsx(Sl,{className:"w-4 h-4 text-gray-500"}),running:r.jsx(UC,{className:"w-4 h-4 text-green-500"}),paused:r.jsx(Zm,{className:"w-4 h-4 text-yellow-500"}),completed:r.jsx(ao,{className:"w-4 h-4 text-green-600"}),failed:r.jsx(sa,{className:"w-4 h-4 text-red-500"}),cancelled:r.jsx(sa,{className:"w-4 h-4 text-gray-500"})};function qH({activeProject:e=null}){var bo,As,Fi,Ts,Bi,ei,ti;const[t,s]=C.useState([]),[n,o]=C.useState(!0),[d,u]=C.useState(null),[l,c]=C.useState({}),[f,m]=C.useState([]),[h,x]=C.useState(null),[w,j]=C.useState(""),[_,y]=C.useState(!1),[b,g]=C.useState(!1),[v,k]=C.useState(!1),[E,P]=C.useState(!1),[T,N]=C.useState(null),[M,I]=C.useState(""),[O,B]=C.useState(""),[z,q]=C.useState(50),[H,G]=C.useState("DONE"),[Q,K]=C.useState(!1),[F,R]=C.useState(50),[L,U]=C.useState(!1),[$,ne]=C.useState("DONE"),[fe,pe]=C.useState([]),[J,W]=C.useState({stopHook:{},prepromptHook:{}}),[le,re]=C.useState(!1),[Z,oe]=C.useState({needsInstall:!0}),[Se,Be]=C.useState(!1),[Ue,ue]=C.useState(null),[be,Qe]=C.useState(null),[Ye,lt]=C.useState(!1),[je,ye]=C.useState(!1),[Ne,_e]=C.useState(null),[Ee,ie]=C.useState(!0),[de,Ae]=C.useState(null),[ze,Fe]=C.useState(!1);C.useEffect(()=>{Vt(),Br(),$t(),lr(),ct()},[]);const pt=C.useRef(null);C.useEffect(()=>{if(!je||!Ne){pt.current=null;return}pt.current=Ne.status;const ce=setInterval(async()=>{var X,we,Te;try{const Ve=(await xe.getLoop(Ne.id)).loop,wt=pt.current!==Ve.status,dr=["completed","paused","failed","cancelled"].includes(Ve.status);if(wt&&dr){clearInterval(ce);const Xt={name:Ve.name,task:(X=Ve.task)==null?void 0:X.original,status:Ve.status,pauseReason:Ve.pauseReason,iterations:((we=Ve.iterations)==null?void 0:we.current)||0,maxIterations:((Te=Ve.iterations)==null?void 0:Te.max)||50,phase:Ve.phase,startedAt:Ve.startedAt,completedAt:Ve.completedAt||new Date().toISOString(),duration:Ve.startedAt?Math.round((Date.now()-new Date(Ve.startedAt).getTime())/1e3):null};Ae(Xt),Ve.status==="completed"?Y.success("Loop completed successfully!"):Ve.status==="paused"?Y.info(`Loop paused: ${Ve.pauseReason||"unknown reason"}`):Ve.status==="failed"?Y.error("Loop failed"):Ve.status==="cancelled"&&Y.warning("Loop cancelled"),Vt(),Ee&&Ve.status==="completed"?setTimeout(()=>{ye(!1),_e(null),Fe(!0)},1500):Fe(!0)}pt.current=Ve.status}catch($e){console.error("Failed to poll loop status:",$e)}},3e3);return()=>clearInterval(ce)},[je,Ne,Ee]);const ct=async()=>{try{const ce=await xe.getRalphLoopPluginStatus();oe(ce)}catch(ce){console.error("Failed to load plugin status:",ce)}},lr=async()=>{try{const ce=await xe.getWorkstreams();m(ce.workstreams||[]),x(ce.activeId||null)}catch(ce){console.error("Failed to load workstreams:",ce)}};C.useEffect(()=>{_&&h&&B(h)},[_,h]);const Vt=async()=>{try{o(!0);const ce=await xe.getLoops();s(ce.loops||[]),c(ce.config||{})}catch{Y.error("Failed to load loops")}finally{o(!1)}},Br=async()=>{try{const X=(await xe.getLoopConfig()).config||{};c(X),R(X.maxIterations||50),U(X.autoApprovePlan||!1),ne(X.completionPromise||"DONE"),q(X.maxIterations||50),G(X.completionPromise||"DONE")}catch(ce){console.error("Failed to load config:",ce)}},$t=async()=>{try{const ce=await xe.getLoopHookStatus();W(ce)}catch(ce){console.error("Failed to load hook status:",ce)}},$r=async()=>{try{const ce=await xe.getLoopHistory();pe(ce.completed||[])}catch{Y.error("Failed to load history")}},tr=async()=>{if(!M.trim()){Y.error("Task description is required");return}try{K(!0);const ce=await xe.createLoop(M,{workstreamId:O||null,projectPath:(e==null?void 0:e.path)||(e==null?void 0:e.dir)||null,maxIterations:parseInt(z,10)||50,completionPromise:H||"DONE"});ce.success?(Y.success("Loop created"),y(!1),I(""),B(""),q(F),G($),Vt()):Y.error(ce.error||"Failed to create loop")}catch(ce){Y.error(ce.message)}finally{K(!1)}},fr=async ce=>{if(Z.needsInstall){ue(ce),Qe("start"),Be(!0);return}await ln(ce)},ln=async ce=>{try{const X=await xe.startLoop(ce);X.success&&X.loop?(Y.success("Loop started - launching Claude Code"),_e(X.loop),ye(!0),Vt()):Y.error(X.error||"Failed to start loop")}catch(X){Y.error(X.message)}},fs=async()=>{try{lt(!0);const ce=await xe.installRalphLoopPlugin();ce.success?(Y.success("ralph-loop plugin installed"),oe({installed:!0,scope:"user",needsInstall:!1}),Be(!1),Ue&&(be==="resume"?await Ut(Ue):await ln(Ue),ue(null),Qe(null))):Y.error(ce.error||"Failed to install plugin")}catch(ce){Y.error(ce.message)}finally{lt(!1)}},ms=()=>{Be(!1),ue(null),Qe(null)},cn=C.useCallback(async(ce,X)=>{var we,Te;if(Ne)try{const Ve=(await xe.getLoop(Ne.id)).loop;Ve.taskComplete||Ve.status==="completed"?(Y.success("Loop completed successfully!"),ye(!1),_e(null)):Ve.status==="paused"?Y.info(`Loop paused: ${Ve.pauseReason||"user requested"}`):((we=Ve.iterations)==null?void 0:we.current)>=((Te=Ve.iterations)==null?void 0:Te.max)?(Y.warning("Loop reached max iterations"),await xe.pauseLoop(Ve.id)):Y.info("Claude exited. Click Start to continue the loop."),Vt()}catch($e){console.error("Failed to check loop status:",$e)}},[Ne]),it=async ce=>{try{const X=await xe.pauseLoop(ce);X.success?(Y.success("Loop paused"),Vt()):Y.error(X.error||"Failed to pause loop")}catch(X){Y.error(X.message)}},Mt=async ce=>{if(Z.needsInstall){ue(ce),Qe("resume"),Be(!0);return}await Ut(ce)},Ut=async ce=>{try{const X=await xe.resumeLoop(ce);X.success&&X.loop?(Y.success("Loop resumed - launching Claude Code"),_e(X.loop),ye(!0),Vt()):Y.error(X.error||"Failed to resume loop")}catch(X){Y.error(X.message)}},cr=async ce=>{if(confirm("Cancel this loop?"))try{const X=await xe.cancelLoop(ce);X.success?(Y.success("Loop cancelled"),Vt()):Y.error(X.error||"Failed to cancel loop")}catch(X){Y.error(X.message)}},es=async ce=>{if(confirm("Delete this loop and all its data?"))try{const X=await xe.deleteLoop(ce);X.success?(Y.success("Loop deleted"),Vt()):Y.error(X.error||"Failed to delete loop")}catch(X){Y.error(X.message)}},Gt=async ce=>{try{const X=await xe.approveLoop(ce);X.success?(Y.success("Plan approved"),Vt()):Y.error(X.error||"Failed to approve plan")}catch(X){Y.error(X.message)}},rr=async()=>{try{K(!0);const ce=await xe.updateLoopConfig({maxIterations:parseInt(F,10),autoApprovePlan:L,completionPromise:$});ce.success?(Y.success("Configuration saved"),g(!1),Br()):Y.error(ce.error||"Failed to save configuration")}catch(ce){Y.error(ce.message)}finally{K(!1)}},ps=async()=>{try{re(!0);const ce=await xe.installLoopHooks();ce.success?(Y.success("Hooks installed successfully"),$t()):Y.error(ce.error||"Failed to install hooks")}catch(ce){Y.error(ce.message)}finally{re(!1)}},sr=async ce=>{try{const X=await xe.getLoop(ce.id);N({...X.loop,clarifications:X.clarifications,plan:X.plan}),P(!0)}catch{Y.error("Failed to load loop details")}},Tr=ce=>{navigator.clipboard.writeText(ce),Y.success("Copied to clipboard")},qr=ce=>ce?new Date(ce).toLocaleString():"-",_r=ce=>ce.iterations?Math.min(100,ce.iterations.current/ce.iterations.max*100):0,Tn=((bo=J.stopHook)==null?void 0:bo.exists)&&((As=J.prepromptHook)==null?void 0:As.exists),Zn=ce=>{if(!ce)return null;const X=f.find(we=>we.id===ce);return(X==null?void 0:X.name)||ce},Li=w?t.filter(ce=>ce.workstreamId===w):t,Oi=ce=>{var $e,Ve;const X=((($e=ce.task)==null?void 0:$e.original)||"").replace(/"/g,'\\"'),we=((Ve=ce.iterations)==null?void 0:Ve.max)||50,Te=ce.completionPromise||"DONE";return`claude --dangerously-skip-permissions "/ralph-loop ${X} --max-iterations ${we} --completion-promise '${Te}'"`};return r.jsxs("div",{className:"p-6 space-y-6 max-w-6xl mx-auto",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsxs("h1",{className:"text-2xl font-bold flex items-center gap-2",children:[r.jsx(Dl,{className:"w-6 h-6"}),"Ralph Loops"]}),r.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"Autonomous development loops using the official ralph-loop plugin"})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[f.length>0&&r.jsxs("div",{className:"flex items-center gap-1",children:[r.jsx(mg,{className:"w-4 h-4 text-muted-foreground"}),r.jsxs("select",{className:"text-sm border rounded px-2 py-1 bg-background",value:w,onChange:ce=>j(ce.target.value),children:[r.jsx("option",{value:"",children:"All workstreams"}),f.map(ce=>r.jsx("option",{value:ce.id,children:ce.name},ce.id))]})]}),r.jsx(xr,{children:r.jsxs(Ot,{children:[r.jsx(Ft,{asChild:!0,children:r.jsxs(te,{variant:"outline",size:"sm",onClick:()=>{$r(),k(!0)},children:[r.jsx(Qd,{className:"w-4 h-4 mr-1"}),"History"]})}),r.jsx(Rt,{children:"View completed loops"})]})}),r.jsx(xr,{children:r.jsxs(Ot,{children:[r.jsx(Ft,{asChild:!0,children:r.jsxs(te,{variant:"outline",size:"sm",onClick:()=>g(!0),children:[r.jsx(Vs,{className:"w-4 h-4 mr-1"}),"Config"]})}),r.jsx(Rt,{children:"Configure loop defaults"})]})}),r.jsxs(te,{onClick:()=>y(!0),children:[r.jsx(jt,{className:"w-4 h-4 mr-1"}),"New Loop"]})]})]}),!Tn&&r.jsxs("div",{className:"bg-yellow-50 dark:bg-yellow-900/20 border border-yellow-200 dark:border-yellow-800 rounded-lg p-4 flex items-center justify-between",children:[r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx(ks,{className:"w-5 h-5 text-yellow-600"}),r.jsxs("div",{children:[r.jsx("p",{className:"font-medium text-yellow-800 dark:text-yellow-200",children:"Hooks not installed"}),r.jsx("p",{className:"text-sm text-yellow-700 dark:text-yellow-300",children:"Install the Ralph Loop hooks to enable automatic loop continuation"})]})]}),r.jsxs(te,{variant:"outline",size:"sm",onClick:ps,disabled:le,children:[le?r.jsx(Ze,{className:"w-4 h-4 animate-spin mr-1"}):null,"Install Hooks"]})]}),n?r.jsx("div",{className:"flex items-center justify-center py-12",children:r.jsx(Ze,{className:"w-6 h-6 animate-spin text-muted-foreground"})}):Li.length===0?r.jsxs("div",{className:"text-center py-12 text-muted-foreground",children:[r.jsx(Dl,{className:"w-12 h-12 mx-auto mb-4 opacity-50"}),r.jsx("p",{className:"text-lg font-medium",children:w?"No loops in this workstream":"No loops yet"}),r.jsx("p",{className:"text-sm mt-1",children:"Create a loop to start autonomous development"})]}):r.jsx("div",{className:"space-y-3",children:Li.map(ce=>{var X,we,Te,$e,Ve;return r.jsxs("div",{className:"border rounded-lg bg-card overflow-hidden",children:[r.jsxs("div",{className:"p-4 cursor-pointer hover:bg-muted/50 transition-colors",onClick:()=>u(d===ce.id?null:ce.id),children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{className:"flex items-center gap-3",children:[d===ce.id?r.jsx(vr,{className:"w-4 h-4 text-muted-foreground"}):r.jsx(Qr,{className:"w-4 h-4 text-muted-foreground"}),Yo[ce.status]||Yo.pending,r.jsxs("div",{children:[r.jsx("h3",{className:"font-medium",children:ce.name}),r.jsx("p",{className:"text-sm text-muted-foreground truncate max-w-md",children:((X=ce.task)==null?void 0:X.original)||"No task"})]})]}),r.jsxs("div",{className:"flex items-center gap-3",children:[ce.workstreamId&&r.jsxs("span",{className:"text-xs px-2 py-0.5 rounded-full bg-purple-100 text-purple-800 dark:bg-purple-900 dark:text-purple-200 flex items-center gap-1",children:[r.jsx(gn,{className:"w-3 h-3"}),Zn(ce.workstreamId)]}),r.jsx("span",{className:`text-xs px-2 py-0.5 rounded-full ${e_[ce.phase]||"bg-gray-100 dark:bg-gray-800"}`,children:ce.phase}),r.jsxs("span",{className:"text-sm text-muted-foreground",children:[((we=ce.iterations)==null?void 0:we.current)||0,"/",((Te=ce.iterations)==null?void 0:Te.max)||50]}),r.jsxs("div",{className:"flex items-center gap-1",onClick:wt=>wt.stopPropagation(),children:[ce.status==="pending"&&r.jsx(xr,{children:r.jsxs(Ot,{children:[r.jsx(Ft,{asChild:!0,children:r.jsx(te,{variant:"ghost",size:"sm",onClick:()=>fr(ce.id),children:r.jsx(UC,{className:"w-4 h-4"})})}),r.jsx(Rt,{children:"Start loop"})]})}),ce.status==="running"&&r.jsx(xr,{children:r.jsxs(Ot,{children:[r.jsx(Ft,{asChild:!0,children:r.jsx(te,{variant:"ghost",size:"sm",onClick:()=>it(ce.id),children:r.jsx(Zm,{className:"w-4 h-4"})})}),r.jsx(Rt,{children:"Pause loop"})]})}),ce.status==="paused"&&r.jsx(xr,{children:r.jsxs(Ot,{children:[r.jsx(Ft,{asChild:!0,children:r.jsx(te,{variant:"ghost",size:"sm",onClick:()=>Mt(ce.id),children:r.jsx(sm,{className:"w-4 h-4"})})}),r.jsx(Rt,{children:"Resume loop"})]})}),(ce.status==="cancelled"||ce.status==="failed")&&r.jsx(xr,{children:r.jsxs(Ot,{children:[r.jsx(Ft,{asChild:!0,children:r.jsx(te,{variant:"ghost",size:"sm",onClick:()=>fr(ce.id),children:r.jsx(sm,{className:"w-4 h-4"})})}),r.jsx(Rt,{children:"Restart loop"})]})}),ce.phase==="plan"&&ce.status==="running"&&r.jsx(xr,{children:r.jsxs(Ot,{children:[r.jsx(Ft,{asChild:!0,children:r.jsx(te,{variant:"ghost",size:"sm",onClick:()=>Gt(ce.id),children:r.jsx(Tt,{className:"w-4 h-4"})})}),r.jsx(Rt,{children:"Approve plan"})]})}),r.jsx(xr,{children:r.jsxs(Ot,{children:[r.jsx(Ft,{asChild:!0,children:r.jsx(te,{variant:"ghost",size:"sm",onClick:()=>sr(ce),children:r.jsx(hg,{className:"w-4 h-4"})})}),r.jsx(Rt,{children:"View details"})]})}),(ce.status==="running"||ce.status==="paused")&&r.jsx(xr,{children:r.jsxs(Ot,{children:[r.jsx(Ft,{asChild:!0,children:r.jsx(te,{variant:"ghost",size:"sm",onClick:()=>cr(ce.id),children:r.jsx(sa,{className:"w-4 h-4"})})}),r.jsx(Rt,{children:"Cancel loop"})]})}),r.jsx(xr,{children:r.jsxs(Ot,{children:[r.jsx(Ft,{asChild:!0,children:r.jsx(te,{variant:"ghost",size:"sm",onClick:()=>es(ce.id),children:r.jsx(ds,{className:"w-4 h-4 text-red-500"})})}),r.jsx(Rt,{children:"Delete loop"})]})})]})]})]}),r.jsxs("div",{className:"mt-3",children:[r.jsxs("div",{className:"flex justify-between text-xs text-muted-foreground mb-1",children:[r.jsx("span",{children:"Iterations"}),r.jsxs("span",{children:[(($e=ce.iterations)==null?void 0:$e.current)||0," / ",((Ve=ce.iterations)==null?void 0:Ve.max)||50]})]}),r.jsx("div",{className:"h-1.5 bg-muted rounded-full overflow-hidden",children:r.jsx("div",{className:"h-full bg-blue-500 transition-all",style:{width:`${_r(ce)}%`}})})]})]}),d===ce.id&&r.jsxs("div",{className:"border-t p-4 bg-muted/30 space-y-4",children:[r.jsxs("div",{className:"grid grid-cols-2 gap-4 text-sm",children:[r.jsxs("div",{children:[r.jsx("span",{className:"text-muted-foreground",children:"ID:"}),r.jsx("span",{className:"ml-2 font-mono",children:ce.id}),r.jsx(te,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 ml-1",onClick:()=>Tr(ce.id),children:r.jsx(Ml,{className:"w-3 h-3"})})]}),r.jsxs("div",{children:[r.jsx("span",{className:"text-muted-foreground",children:"Status:"}),r.jsxs("span",{className:"ml-2",children:[ce.status,ce.pauseReason?` (${ce.pauseReason})`:""]})]}),r.jsxs("div",{children:[r.jsx("span",{className:"text-muted-foreground",children:"Created:"}),r.jsx("span",{className:"ml-2",children:qr(ce.createdAt)})]}),r.jsxs("div",{children:[r.jsx("span",{className:"text-muted-foreground",children:"Updated:"}),r.jsx("span",{className:"ml-2",children:qr(ce.updatedAt)})]}),ce.workstreamId&&r.jsxs("div",{className:"col-span-2",children:[r.jsx("span",{className:"text-muted-foreground",children:"Workstream:"}),r.jsxs("span",{className:"ml-2 inline-flex items-center gap-1",children:[r.jsx(gn,{className:"w-3 h-3 text-purple-500"}),Zn(ce.workstreamId)]})]})]}),r.jsxs("div",{className:"bg-muted p-3 rounded-md",children:[r.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[r.jsx(Lt,{className:"w-4 h-4"}),r.jsx("span",{className:"text-sm font-medium",children:"Run this loop (uses official ralph-loop plugin):"})]}),r.jsx("code",{className:"text-xs bg-background p-2 rounded block whitespace-pre-wrap",children:Oi(ce)})]})]})]},ce.id)})}),r.jsx(bt,{open:_,onOpenChange:y,children:r.jsxs(xt,{className:"sm:max-w-lg",children:[r.jsx(vt,{children:r.jsx(yt,{children:"Create New Loop"})}),r.jsxs("div",{className:"space-y-4 py-4",children:[r.jsxs("div",{children:[r.jsx("label",{className:"text-sm font-medium mb-1 block",children:"Task Description"}),r.jsx(_t,{placeholder:"Describe what you want Claude to accomplish...",value:M,onChange:ce=>I(ce.target.value),rows:4}),r.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Be specific about the goal. The loop will continue until this task is completed."})]}),r.jsxs("div",{children:[r.jsx("label",{className:"text-sm font-medium mb-1 block",children:"Project"}),r.jsx("div",{className:"text-sm p-2 bg-muted rounded-md",children:e?r.jsx("span",{className:"font-mono",children:e.name||e.path||e.dir}):r.jsx("span",{className:"text-muted-foreground",children:"No project selected - loop will run in server directory"})})]}),r.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[r.jsxs("div",{children:[r.jsx("label",{className:"text-sm font-medium mb-1 block",children:"Max Iterations"}),r.jsx(dt,{type:"number",value:z,onChange:ce=>q(ce.target.value),min:1,max:1e3}),r.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Safety limit for the loop"})]}),r.jsxs("div",{children:[r.jsx("label",{className:"text-sm font-medium mb-1 block",children:"Completion Promise"}),r.jsx(dt,{value:H,onChange:ce=>G(ce.target.value),placeholder:"DONE"}),r.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Text that signals completion"})]})]}),f.length>0&&r.jsxs("div",{children:[r.jsx("label",{className:"text-sm font-medium mb-1 block",children:"Workstream (optional)"}),r.jsxs("select",{className:"w-full border rounded-md p-2 bg-background",value:O,onChange:ce=>B(ce.target.value),children:[r.jsx("option",{value:"",children:"No workstream"}),f.map(ce=>r.jsx("option",{value:ce.id,children:ce.name},ce.id))]})]})]}),r.jsxs(St,{children:[r.jsx(te,{variant:"outline",onClick:()=>y(!1),children:"Cancel"}),r.jsxs(te,{onClick:tr,disabled:Q||!M.trim(),children:[Q?r.jsx(Ze,{className:"w-4 h-4 animate-spin mr-1"}):null,"Create Loop"]})]})]})}),r.jsx(bt,{open:b,onOpenChange:g,children:r.jsxs(xt,{className:"sm:max-w-md",children:[r.jsx(vt,{children:r.jsx(yt,{children:"Loop Configuration"})}),r.jsxs("div",{className:"space-y-4 py-4",children:[r.jsxs("div",{children:[r.jsx("label",{className:"text-sm font-medium mb-1 block",children:"Max Iterations"}),r.jsx(dt,{type:"number",value:F,onChange:ce=>R(ce.target.value),min:1,max:1e3}),r.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Loop will pause after this many iterations"})]}),r.jsxs("div",{children:[r.jsx("label",{className:"text-sm font-medium mb-1 block",children:"Default Completion Promise"}),r.jsx(dt,{value:$,onChange:ce=>ne(ce.target.value),placeholder:"DONE"}),r.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Default text that signals loop completion (used with official ralph-loop plugin)"})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("input",{type:"checkbox",id:"autoApprovePlan",checked:L,onChange:ce=>U(ce.target.checked),className:"rounded"}),r.jsx("label",{htmlFor:"autoApprovePlan",className:"text-sm",children:"Auto-approve plans (skip manual plan approval)"})]})]}),r.jsxs(St,{children:[r.jsx(te,{variant:"outline",onClick:()=>g(!1),children:"Cancel"}),r.jsxs(te,{onClick:rr,disabled:Q,children:[Q?r.jsx(Ze,{className:"w-4 h-4 animate-spin mr-1"}):null,"Save"]})]})]})}),r.jsx(bt,{open:v,onOpenChange:k,children:r.jsxs(xt,{className:"sm:max-w-2xl max-h-[80vh] overflow-y-auto",children:[r.jsx(vt,{children:r.jsx(yt,{children:"Loop History"})}),r.jsx("div",{className:"space-y-3 py-4",children:fe.length===0?r.jsx("p",{className:"text-center text-muted-foreground py-8",children:"No completed loops yet"}):fe.slice().reverse().map(ce=>r.jsxs("div",{className:"border rounded-lg p-3",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[Yo[ce.status]||Yo.completed,r.jsx("span",{className:"font-medium",children:ce.name})]}),r.jsx("span",{className:"text-xs text-muted-foreground",children:qr(ce.completedAt)})]}),r.jsx("p",{className:"text-sm text-muted-foreground mt-1 truncate",children:ce.task}),r.jsx("div",{className:"mt-2 text-xs text-muted-foreground",children:r.jsxs("span",{children:["Iterations: ",ce.totalIterations]})})]},ce.id))})]})}),r.jsx(bt,{open:E,onOpenChange:P,children:r.jsxs(xt,{className:"sm:max-w-3xl max-h-[80vh] overflow-y-auto",children:[r.jsx(vt,{children:r.jsx(yt,{children:(T==null?void 0:T.name)||"Loop Details"})}),T&&r.jsxs("div",{className:"space-y-4 py-4",children:[r.jsxs("div",{className:"grid grid-cols-3 gap-4 text-sm",children:[r.jsxs("div",{className:"border rounded p-3",children:[r.jsx("div",{className:"text-muted-foreground text-xs mb-1",children:"Phase"}),r.jsx("span",{className:`text-sm px-2 py-0.5 rounded-full ${e_[T.phase]||""}`,children:T.phase})]}),r.jsxs("div",{className:"border rounded p-3",children:[r.jsx("div",{className:"text-muted-foreground text-xs mb-1",children:"Status"}),r.jsxs("div",{className:"flex items-center gap-1",children:[Yo[T.status],r.jsx("span",{children:T.status})]})]}),r.jsxs("div",{className:"border rounded p-3",children:[r.jsx("div",{className:"text-muted-foreground text-xs mb-1",children:"Progress"}),r.jsxs("span",{children:[((Fi=T.iterations)==null?void 0:Fi.current)||0," / ",((Ts=T.iterations)==null?void 0:Ts.max)||50]})]})]}),r.jsxs("div",{children:[r.jsx("h4",{className:"text-sm font-medium mb-2",children:"Task"}),r.jsx("div",{className:"bg-muted p-3 rounded text-sm",children:(Bi=T.task)==null?void 0:Bi.original})]}),T.clarifications&&r.jsxs("div",{children:[r.jsx("h4",{className:"text-sm font-medium mb-2",children:"Clarifications"}),r.jsx("div",{className:"bg-muted p-3 rounded text-sm whitespace-pre-wrap max-h-40 overflow-y-auto",children:T.clarifications})]}),T.plan&&r.jsxs("div",{children:[r.jsx("h4",{className:"text-sm font-medium mb-2",children:"Plan"}),r.jsx("div",{className:"bg-muted p-3 rounded text-sm whitespace-pre-wrap max-h-60 overflow-y-auto font-mono",children:T.plan})]}),r.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[r.jsxs("div",{children:[r.jsx("h4",{className:"text-sm font-medium mb-2",children:"Max Iterations"}),r.jsx("div",{className:"bg-muted p-2 rounded text-sm",children:((ei=T.iterations)==null?void 0:ei.max)||50})]}),r.jsxs("div",{children:[r.jsx("h4",{className:"text-sm font-medium mb-2",children:"Completion Promise"}),r.jsxs("div",{className:"bg-muted p-2 rounded text-sm font-mono",children:["<promise>",T.completionPromise||"DONE","</promise>"]})]})]}),r.jsxs("div",{children:[r.jsx("h4",{className:"text-sm font-medium mb-2",children:"Run Command (uses official ralph-loop plugin)"}),r.jsx("code",{className:"text-xs bg-muted p-3 rounded block whitespace-pre-wrap",children:Oi(T)})]})]})]})}),r.jsx(bt,{open:Se,onOpenChange:Be,children:r.jsxs(xt,{className:"sm:max-w-md",children:[r.jsx(vt,{children:r.jsxs(yt,{className:"flex items-center gap-2",children:[r.jsx(Kn,{className:"w-5 h-5"}),"Install ralph-loop Plugin"]})}),r.jsxs("div",{className:"py-4",children:[r.jsxs("p",{className:"text-sm text-muted-foreground mb-4",children:["The ",r.jsx("code",{className:"bg-muted px-1 rounded",children:"ralph-loop"})," plugin is required to run loops. This plugin provides the ",r.jsx("code",{className:"bg-muted px-1 rounded",children:"/ralph-loop"})," command that enables autonomous iteration."]}),Z.scope==="project"&&r.jsx("div",{className:"bg-yellow-50 dark:bg-yellow-900/20 border border-yellow-200 dark:border-yellow-800 rounded p-3 mb-4",children:r.jsxs("p",{className:"text-sm text-yellow-800 dark:text-yellow-200",children:["Plugin is currently installed only for project: ",r.jsx("br",{}),r.jsx("code",{className:"text-xs",children:Z.projectPath})]})}),r.jsx("p",{className:"text-sm",children:"Install the plugin globally (user scope) to use loops from any project?"})]}),r.jsxs(St,{children:[r.jsx(te,{variant:"outline",onClick:ms,disabled:Ye,children:"Cancel"}),r.jsx(te,{onClick:fs,disabled:Ye,children:Ye?r.jsxs(r.Fragment,{children:[r.jsx(Ze,{className:"w-4 h-4 animate-spin mr-1"}),"Installing..."]}):r.jsxs(r.Fragment,{children:[r.jsx(Kn,{className:"w-4 h-4 mr-1"}),"Install Plugin"]})})]})]})}),r.jsx(bj,{open:je,onOpenChange:ce=>{ye(ce),ce||(_e(null),Vt())},title:Ne?`Loop: ${Ne.name}`:"Running Loop",description:(ti=Ne==null?void 0:Ne.task)==null?void 0:ti.original,cwd:Ne==null?void 0:Ne.projectPath,initialCommand:Ne?Oi(Ne):"",env:Ne?{CODER_LOOP_ID:Ne.id,...Ne.workstreamId&&{CODER_WORKSTREAM:Ne.workstreamId}}:{},onExit:cn,headerExtra:r.jsxs("label",{className:"flex items-center gap-2 text-sm cursor-pointer select-none",children:[r.jsx("input",{type:"checkbox",checked:Ee,onChange:ce=>ie(ce.target.checked),className:"rounded"}),"Auto-close when done"]})}),r.jsx(bt,{open:ze,onOpenChange:Fe,children:r.jsxs(xt,{className:"sm:max-w-md",children:[r.jsx(vt,{children:r.jsxs(yt,{className:"flex items-center gap-2",children:[(de==null?void 0:de.status)==="completed"&&r.jsxs(r.Fragment,{children:[r.jsx(ao,{className:"w-5 h-5 text-green-600"})," Loop Completed"]}),(de==null?void 0:de.status)==="paused"&&r.jsxs(r.Fragment,{children:[r.jsx(Zm,{className:"w-5 h-5 text-yellow-500"})," Loop Paused"]}),(de==null?void 0:de.status)==="failed"&&r.jsxs(r.Fragment,{children:[r.jsx(sa,{className:"w-5 h-5 text-red-500"})," Loop Failed"]}),(de==null?void 0:de.status)==="cancelled"&&r.jsxs(r.Fragment,{children:[r.jsx(sa,{className:"w-5 h-5 text-gray-500"})," Loop Cancelled"]})]})}),de&&r.jsxs("div",{className:"space-y-4 py-4",children:[r.jsxs("div",{children:[r.jsx("h4",{className:"text-sm font-medium mb-1",children:"Task"}),r.jsx("p",{className:"text-sm text-muted-foreground bg-muted p-2 rounded",children:de.task})]}),de.pauseReason&&r.jsxs("div",{children:[r.jsx("h4",{className:"text-sm font-medium mb-1",children:"Reason"}),r.jsx("p",{className:"text-sm text-muted-foreground bg-muted p-2 rounded",children:de.pauseReason})]}),r.jsxs("div",{className:"grid grid-cols-3 gap-3 text-sm",children:[r.jsxs("div",{className:"border rounded p-3",children:[r.jsx("div",{className:"text-muted-foreground text-xs mb-1",children:"Status"}),r.jsxs("div",{className:"font-medium flex items-center gap-1",children:[Yo[de.status],r.jsx("span",{className:"capitalize",children:de.status})]})]}),r.jsxs("div",{className:"border rounded p-3",children:[r.jsx("div",{className:"text-muted-foreground text-xs mb-1",children:"Iterations"}),r.jsxs("div",{className:"font-medium",children:[de.iterations," / ",de.maxIterations]})]}),r.jsxs("div",{className:"border rounded p-3",children:[r.jsx("div",{className:"text-muted-foreground text-xs mb-1",children:"Duration"}),r.jsx("div",{className:"font-medium",children:de.duration!=null?de.duration<60?`${de.duration}s`:de.duration<3600?`${Math.floor(de.duration/60)}m ${de.duration%60}s`:`${Math.floor(de.duration/3600)}h ${Math.floor(de.duration%3600/60)}m`:"-"})]})]}),r.jsxs("div",{className:"text-xs text-muted-foreground",children:[de.status==="completed"?"Completed":"Stopped"," at ",qr(de.completedAt)]})]}),r.jsxs(St,{children:[r.jsx(te,{variant:"outline",onClick:()=>Fe(!1),children:"Close"}),(de==null?void 0:de.status)==="paused"&&r.jsxs(te,{onClick:()=>{Fe(!1);const ce=t.find(X=>X.name===de.name);ce&&Mt(ce.id)},children:[r.jsx(sm,{className:"w-4 h-4 mr-1"}),"Resume"]}),r.jsx(te,{variant:"secondary",onClick:()=>{if(Fe(!1),de){const ce=t.find(X=>X.name===de.name);ce&&sr(ce)}},children:"View Details"})]})]})})]})}function YH(e,t=[]){let s=[];function n(d,u){const l=C.createContext(u);l.displayName=d+"Context";const c=s.length;s=[...s,u];const f=h=>{var b;const{scope:x,children:w,...j}=h,_=((b=x==null?void 0:x[e])==null?void 0:b[c])||l,y=C.useMemo(()=>j,Object.values(j));return r.jsx(_.Provider,{value:y,children:w})};f.displayName=d+"Provider";function m(h,x){var _;const w=((_=x==null?void 0:x[e])==null?void 0:_[c])||l,j=C.useContext(w);if(j)return j;if(u!==void 0)return u;throw new Error(`\`${h}\` must be used within \`${d}\``)}return[f,m]}const o=()=>{const d=s.map(u=>C.createContext(u));return function(l){const c=(l==null?void 0:l[e])||d;return C.useMemo(()=>({[`__scope${e}`]:{...l,[e]:c}}),[l,c])}};return o.scopeName=e,[n,XH(o,...t)]}function XH(...e){const t=e[0];if(e.length===1)return t;const s=()=>{const n=e.map(o=>({useScope:o(),scopeName:o.scopeName}));return function(d){const u=n.reduce((l,{useScope:c,scopeName:f})=>{const h=c(d)[`__scope${f}`];return{...l,...h}},{});return C.useMemo(()=>({[`__scope${t.scopeName}`]:u}),[u])}};return s.scopeName=t.scopeName,s}var JH=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],t2=JH.reduce((e,t)=>{const s=_u(`Primitive.${t}`),n=C.forwardRef((o,d)=>{const{asChild:u,...l}=o,c=u?s:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),r.jsx(c,{...l,ref:d})});return n.displayName=`Primitive.${t}`,{...e,[t]:n}},{}),_x="Progress",Cx=100,[QH]=YH(_x),[ZH,eW]=QH(_x),r2=C.forwardRef((e,t)=>{const{__scopeProgress:s,value:n=null,max:o,getValueLabel:d=tW,...u}=e;(o||o===0)&&!t_(o)&&console.error(rW(`${o}`,"Progress"));const l=t_(o)?o:Cx;n!==null&&!r_(n,l)&&console.error(sW(`${n}`,"Progress"));const c=r_(n,l)?n:null,f=fu(c)?d(c,l):void 0;return r.jsx(ZH,{scope:s,value:c,max:l,children:r.jsx(t2.div,{"aria-valuemax":l,"aria-valuemin":0,"aria-valuenow":fu(c)?c:void 0,"aria-valuetext":f,role:"progressbar","data-state":i2(c,l),"data-value":c??void 0,"data-max":l,...u,ref:t})})});r2.displayName=_x;var s2="ProgressIndicator",n2=C.forwardRef((e,t)=>{const{__scopeProgress:s,...n}=e,o=eW(s2,s);return r.jsx(t2.div,{"data-state":i2(o.value,o.max),"data-value":o.value??void 0,"data-max":o.max,...n,ref:t})});n2.displayName=s2;function tW(e,t){return`${Math.round(e/t*100)}%`}function i2(e,t){return e==null?"indeterminate":e===t?"complete":"loading"}function fu(e){return typeof e=="number"}function t_(e){return fu(e)&&!isNaN(e)&&e>0}function r_(e,t){return fu(e)&&!isNaN(e)&&e<=t&&e>=0}function rW(e,t){return`Invalid prop \`max\` of value \`${e}\` supplied to \`${t}\`. Only numbers greater than 0 are valid max values. Defaulting to \`${Cx}\`.`}function sW(e,t){return`Invalid prop \`value\` of value \`${e}\` supplied to \`${t}\`. The \`value\` prop must be:
2982
+ This cannot be undone.`))try{const we=await xe.deleteWorkstream(X.id);we.success?(n(Te=>Te.filter($e=>$e.id!==X.id)),Y.success(`Deleted workstream: ${X.name}`)):Y.error(we.error||"Failed to delete workstream")}catch(we){Y.error("Failed to delete workstream: "+we.message)}},qr=async()=>{if(m){M(!0);try{const X=await xe.updateWorkstream(m.id,{name:m.name,rules:m.rules,projects:m.projects||[]});X.success?(n(we=>we.map(Te=>Te.id===m.id?X.workstream:Te)),Y.success("Workstream updated"),h(null)):Y.error(X.error||"Failed to update workstream")}catch(X){Y.error("Failed to update workstream: "+X.message)}finally{M(!1)}}},_r=X=>{Ue(X.id),be(X.rules||"")},Tn=()=>{Ue(null),be("")},Zn=async X=>{Ye(!0);try{const we=await xe.updateWorkstream(X.id,{name:X.name,rules:ue,projects:X.projects||[]});we.success?(n(Te=>Te.map($e=>$e.id===X.id?we.workstream:$e)),Y.success("Rules updated"),Ue(null),be("")):Y.error(we.error||"Failed to update rules")}catch(we){Y.error("Failed to update rules: "+we.message)}finally{Ye(!1)}},Li=X=>{b(we=>{const Te=new Set(we);return Te.has(X)?Te.delete(X):Te.add(X),Te})},Oi=async()=>{if(!j||y.size===0)return;M(!0);let X=0,we=null;for(const Te of y)try{const $e=await xe.addProjectToWorkstream(j.id,Te);$e.success&&(we=$e.workstream,X++)}catch($e){console.error("Failed to add project:",Te,$e)}we&&n(Te=>Te.map($e=>$e.id===j.id?we:$e)),X>0?Y.success(`Added ${X} project${X>1?"s":""} to ${j.name}`):Y.error("Failed to add projects"),M(!1),w(!1),_(null),b(new Set)},bo=async(X,we)=>{try{const Te=await xe.removeProjectFromWorkstream(X.id,we);Te.success?(n($e=>$e.map(Ve=>Ve.id===X.id?Te.workstream:Ve)),Y.success(`Removed project from ${X.name}`)):Y.error(Te.error||"Failed to remove project")}catch(Te){Y.error("Failed to remove project: "+Te.message)}},As=X=>X.split("/").pop()||X,Fi=X=>s.filter(we=>{var Te;return(Te=we.projects)==null?void 0:Te.includes(X)}).length,Ts=(X,we=null)=>{var Ve,wt;const Te=Fi(X),$e=we?(wt=(Ve=s.find(dr=>dr.id===we))==null?void 0:Ve.projects)==null?void 0:wt.includes(X):!1;return Te===0?null:Te===1?$e?null:"in use":"shared"};return o?r.jsx("div",{className:"flex items-center justify-center h-64",children:r.jsx(Ze,{className:"w-8 h-8 animate-spin text-indigo-600"})}):r.jsxs("div",{className:"space-y-6",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx("div",{className:"w-10 h-10 rounded-lg bg-purple-100 dark:bg-purple-900/30 flex items-center justify-center",children:r.jsx(gn,{className:"w-5 h-5 text-purple-600 dark:text-purple-400"})}),r.jsxs("div",{children:[r.jsx("h2",{className:"text-lg font-semibold text-gray-900 dark:text-white",children:"Workstreams"}),r.jsx("p",{className:"text-sm text-gray-500 dark:text-slate-400",children:"Context sets for multi-project workflows"})]})]}),r.jsxs("div",{className:"flex gap-2",children:[r.jsxs(te,{variant:"outline",onClick:ps,size:"sm",children:[r.jsx(wr,{className:"w-4 h-4 mr-2"}),"Refresh"]}),r.jsxs(te,{onClick:()=>f(!0),className:"bg-purple-600 hover:bg-purple-700",children:[r.jsx(jt,{className:"w-4 h-4 mr-2"}),"New Workstream"]})]})]}),r.jsx("div",{className:"bg-purple-50 dark:bg-purple-950/30 border border-purple-200 dark:border-purple-800 rounded-lg p-4 text-sm text-purple-700 dark:text-purple-400",children:r.jsxs("p",{children:[r.jsx("strong",{children:"Workstreams"})," let you group related repos together so Claude sees them as one cohesive project. Perfect for microservices, monorepos, or any multi-repo setup where context matters. Your custom rules and context persist across sessions, and Claude stays scoped to only the directories you specify."]})}),r.jsx("div",{className:"bg-white dark:bg-slate-950 rounded-xl border border-gray-200 dark:border-slate-800 shadow-sm overflow-hidden",children:s.length===0?r.jsxs("div",{className:"p-12 text-center",children:[r.jsx(gn,{className:"w-12 h-12 mx-auto mb-4 text-gray-300 dark:text-slate-600"}),r.jsx("h3",{className:"text-lg font-medium text-gray-900 dark:text-white mb-2",children:"No Workstreams Yet"}),r.jsx("p",{className:"text-sm text-gray-500 dark:text-slate-400 mb-4",children:"Create your first workstream to organize multi-project contexts."}),r.jsxs(te,{onClick:()=>f(!0),children:[r.jsx(jt,{className:"w-4 h-4 mr-2"}),"Create Your First Workstream"]})]}):r.jsx("div",{className:"divide-y divide-gray-100 dark:divide-slate-800",children:s.map(X=>{var we,Te,$e,Ve;return r.jsxs("div",{className:"group",children:[r.jsxs("div",{className:"p-4 flex items-center gap-4 transition-colors cursor-pointer hover:bg-gray-50 dark:hover:bg-slate-900",onClick:()=>l(u===X.id?null:X.id),children:[r.jsx("div",{className:"w-5 h-5 flex items-center justify-center text-gray-400",children:u===X.id?r.jsx(vr,{className:"w-4 h-4"}):r.jsx(Qr,{className:"w-4 h-4"})}),r.jsx("div",{className:"w-10 h-10 rounded-lg flex items-center justify-center bg-gray-100 dark:bg-slate-800",children:r.jsx(gn,{className:"w-5 h-5 text-gray-500 dark:text-slate-400"})}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("h3",{className:"font-medium truncate text-gray-900 dark:text-white",children:X.name}),((we=X.projects)==null?void 0:we.length)>0&&r.jsxs("span",{className:"text-xs bg-gray-100 dark:bg-slate-800 text-gray-600 dark:text-slate-400 px-1.5 py-0.5 rounded",children:[X.projects.length," project",X.projects.length!==1?"s":""]}),X.rules&&r.jsxs("span",{className:"text-xs bg-blue-100 dark:bg-blue-900/30 text-blue-600 dark:text-blue-400 px-1.5 py-0.5 rounded",children:[r.jsx(Pr,{className:"w-3 h-3 inline mr-0.5"}),"Rules"]})]}),r.jsx("p",{className:"text-sm text-gray-500 dark:text-slate-400 truncate",children:((Te=X.projects)==null?void 0:Te.length)>0?X.projects.map(wt=>As(wt)).join(", "):"No projects added"})]}),r.jsxs("div",{className:"flex items-center gap-2",onClick:wt=>wt.stopPropagation(),children:[r.jsx(te,{size:"sm",variant:"ghost",onClick:()=>h({...X}),className:"text-gray-500 dark:text-slate-400 hover:text-purple-600 dark:hover:text-purple-400",title:"Edit workstream",children:r.jsx(rm,{className:"w-4 h-4"})}),r.jsx(te,{size:"sm",variant:"ghost",onClick:()=>Tr(X),className:"text-gray-500 dark:text-slate-400 hover:text-red-600 dark:hover:text-red-400",title:"Delete workstream",children:r.jsx(ds,{className:"w-4 h-4"})})]})]}),u===X.id&&r.jsxs("div",{className:"px-4 pb-4 pl-16 space-y-4 bg-gray-50/50 dark:bg-slate-900/50",children:[r.jsxs("div",{children:[r.jsxs("div",{className:"flex items-center justify-between mb-2",children:[r.jsx("h4",{className:"text-sm font-medium text-gray-700 dark:text-slate-300",children:"Projects"}),r.jsxs(te,{size:"sm",variant:"outline",onClick:()=>{_(X),w(!0)},children:[r.jsx(zn,{className:"w-4 h-4 mr-1"}),"Add Project"]})]}),(($e=X.projects)==null?void 0:$e.length)>0?r.jsx("div",{className:"space-y-1",children:X.projects.map(wt=>r.jsxs("div",{className:"flex items-center justify-between py-1.5 px-3 bg-white dark:bg-slate-800 rounded border border-gray-200 dark:border-slate-700",children:[r.jsx("span",{className:"text-sm font-mono text-gray-700 dark:text-slate-300 truncate",children:wt.replace(/^\/Users\/[^/]+/,"~")}),r.jsx(te,{size:"sm",variant:"ghost",onClick:()=>bo(X,wt),className:"text-gray-400 hover:text-red-500 h-6 w-6 p-0",children:r.jsx(yb,{className:"w-4 h-4"})})]},wt))}):r.jsx("p",{className:"text-sm text-gray-500 dark:text-slate-400 italic",children:"No projects added yet. Add projects to help organize your workstream."})]}),r.jsxs("div",{children:[r.jsxs("div",{className:"flex items-center justify-between mb-2",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("h4",{className:"text-sm font-medium text-gray-700 dark:text-slate-300",children:"Trigger Folders"}),r.jsx(xr,{children:r.jsxs(Ot,{children:[r.jsx(Ft,{asChild:!0,children:r.jsx(ra,{className:"w-3.5 h-3.5 text-gray-400"})}),r.jsx(Rt,{children:r.jsx("p",{className:"max-w-xs text-xs",children:"Additional folders that activate this workstream when you cd into them. Projects are always trigger folders automatically."})})]})})]}),r.jsxs(te,{size:"sm",variant:"outline",onClick:()=>{ze(X),de(!0)},children:[r.jsx(zn,{className:"w-4 h-4 mr-1"}),"Add Folder"]})]}),((Ve=X.triggerFolders)==null?void 0:Ve.length)>0?r.jsx("div",{className:"space-y-1",children:X.triggerFolders.map(wt=>r.jsxs("div",{className:"flex items-center justify-between py-1.5 px-3 bg-white dark:bg-slate-800 rounded border border-gray-200 dark:border-slate-700",children:[r.jsx("span",{className:"text-sm font-mono text-gray-700 dark:text-slate-300 truncate",children:wt.replace(/^\/Users\/[^/]+/,"~")}),r.jsx(te,{size:"sm",variant:"ghost",onClick:()=>rr(X,wt),className:"text-gray-400 hover:text-red-500 h-6 w-6 p-0",children:r.jsx(yb,{className:"w-4 h-4"})})]},wt))}):r.jsx("p",{className:"text-sm text-gray-500 dark:text-slate-400 italic",children:"No extra trigger folders. Projects auto-trigger this workstream."})]}),r.jsxs("div",{className:"flex items-center justify-between py-2 px-3 bg-white dark:bg-slate-800 rounded border border-gray-200 dark:border-slate-700",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(no,{className:"w-4 h-4 text-amber-500"}),r.jsx("span",{className:"text-sm font-medium text-gray-700 dark:text-slate-300",children:"Auto-Activate on cd"})]}),r.jsxs(Xn,{children:[r.jsx(Jn,{asChild:!0,children:r.jsxs(te,{variant:"outline",size:"sm",children:[X.autoActivate===!0?"On":X.autoActivate===!1?"Off":"Default",r.jsx(vr,{className:"w-3 h-3 ml-1"})]})}),r.jsxs(jn,{align:"end",children:[r.jsxs(At,{onClick:()=>es(X,"on"),children:[r.jsx(Tt,{className:`w-4 h-4 mr-2 ${X.autoActivate===!0?"opacity-100":"opacity-0"}`}),"On"]}),r.jsxs(At,{onClick:()=>es(X,"off"),children:[r.jsx(Tt,{className:`w-4 h-4 mr-2 ${X.autoActivate===!1?"opacity-100":"opacity-0"}`}),"Off"]}),r.jsxs(At,{onClick:()=>es(X,"default"),children:[r.jsx(Tt,{className:`w-4 h-4 mr-2 ${X.autoActivate===void 0?"opacity-100":"opacity-0"}`}),"Default (",ye.workstreamAutoActivate?"On":"Off",")"]})]})]})]}),r.jsxs("div",{children:[r.jsxs("div",{className:"flex items-center justify-between mb-2",children:[r.jsx("h4",{className:"text-sm font-medium text-gray-700 dark:text-slate-300",children:"Rules"}),Be===X.id?r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsxs(te,{size:"sm",variant:"ghost",onClick:Tn,disabled:Qe,className:"text-gray-500 dark:text-slate-400 h-7",children:[r.jsx(Hn,{className:"w-4 h-4 mr-1"}),"Cancel"]}),r.jsxs(te,{size:"sm",onClick:()=>Zn(X),disabled:Qe,className:"bg-purple-600 hover:bg-purple-700 h-7",children:[Qe?r.jsx(Ze,{className:"w-4 h-4 animate-spin mr-1"}):r.jsx(Ps,{className:"w-4 h-4 mr-1"}),"Save"]})]}):r.jsxs(te,{size:"sm",variant:"ghost",onClick:()=>_r(X),className:"text-gray-500 dark:text-slate-400 hover:text-purple-600 dark:hover:text-purple-400 h-7",children:[r.jsx(rm,{className:"w-4 h-4 mr-1"}),"Edit"]})]}),Be===X.id?r.jsx(_t,{value:ue,onChange:wt=>be(wt.target.value),placeholder:"Context rules for this workstream. These will be injected into every Claude session when this workstream is active.",rows:8,className:"font-mono text-sm",autoFocus:!0}):X.rules?r.jsx("pre",{className:"text-sm text-gray-600 dark:text-slate-400 bg-white dark:bg-slate-800 rounded border border-gray-200 dark:border-slate-700 p-3 overflow-auto max-h-40 whitespace-pre-wrap cursor-pointer hover:border-purple-300 dark:hover:border-purple-700 transition-colors",onClick:()=>_r(X),title:"Click to edit",children:X.rules}):r.jsx("p",{className:"text-sm text-gray-500 dark:text-slate-400 italic cursor-pointer hover:text-purple-600 dark:hover:text-purple-400 transition-colors",onClick:()=>_r(X),children:"No rules defined. Click to add context rules for this workstream."})]})]})]},X.id)})})}),r.jsxs("div",{className:"space-y-3",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("h3",{className:"text-sm font-medium text-gray-700 dark:text-slate-300",children:"Hook Integration"}),r.jsx(xr,{children:r.jsxs(Ot,{children:[r.jsx(Ft,{asChild:!0,children:r.jsx("button",{className:"text-gray-400 hover:text-gray-600 dark:hover:text-slate-300",children:r.jsx(ra,{className:"w-4 h-4"})})}),r.jsx(Rt,{side:"right",className:"max-w-xs",children:r.jsxs("p",{className:"text-sm",children:[r.jsx("strong",{children:"What are hooks?"}),r.jsx("br",{}),r.jsx("br",{}),"Hooks are scripts that run automatically at specific points in Claude Code sessions. The workstream hook runs before each prompt and injects your active workstream's rules into the context.",r.jsx("br",{}),r.jsx("br",{}),r.jsx("strong",{children:"How it works:"}),r.jsx("br",{}),"1. You activate a workstream",r.jsx("br",{}),"2. Hook detects the active workstream",r.jsx("br",{}),"3. Rules are prepended to Claude's context",r.jsx("br",{}),"4. Claude understands your project context"]})})]})})]}),K.isInstalled?r.jsx("div",{className:"bg-green-50 dark:bg-green-950/30 border border-green-200 dark:border-green-800 rounded-lg p-4 text-sm text-green-700 dark:text-green-400",children:r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(ao,{className:"w-5 h-5 flex-shrink-0"}),r.jsxs("div",{children:[r.jsx("p",{className:"font-medium",children:"Hook Installed"}),r.jsx("p",{className:"text-green-600 dark:text-green-500",children:"Workstream rules will be automatically injected into every Claude session."})]})]})}):r.jsx("div",{className:"bg-amber-50 dark:bg-amber-950/30 border border-amber-200 dark:border-amber-800 rounded-lg p-4 text-sm text-amber-700 dark:text-amber-400",children:r.jsxs("div",{className:"flex gap-3",children:[r.jsx(ks,{className:"w-5 h-5 flex-shrink-0 mt-0.5"}),r.jsxs("div",{className:"flex-1",children:[r.jsx("p",{className:"font-medium mb-1",children:"Hook Not Installed"}),r.jsx("p",{className:"mb-3",children:"Install the pre-prompt hook to automatically inject workstream rules into every Claude session."}),r.jsxs(te,{onClick:it,disabled:R||K.loading,size:"sm",className:"bg-amber-600 hover:bg-amber-700 text-white",children:[R?r.jsx(Ze,{className:"w-4 h-4 animate-spin mr-2"}):r.jsx(Kn,{className:"w-4 h-4 mr-2"}),"Install Hook"]}),r.jsxs("p",{className:"text-xs mt-2 text-amber-600 dark:text-amber-500",children:["Creates ",r.jsx("code",{className:"bg-amber-100 dark:bg-amber-900/50 px-1 rounded",children:"~/.claude/hooks/pre-prompt.sh"})]})]})]})})]}),r.jsxs("div",{className:"space-y-3",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("h3",{className:"text-sm font-medium text-gray-700 dark:text-slate-300",children:"Folder Auto-Activation"}),r.jsx(xr,{children:r.jsxs(Ot,{children:[r.jsx(Ft,{asChild:!0,children:r.jsx(ra,{className:"w-4 h-4 text-gray-400"})}),r.jsxs(Rt,{className:"max-w-sm",children:[r.jsx("p",{className:"text-sm mb-2",children:r.jsx("strong",{children:"How it works:"})}),r.jsxs("ol",{className:"text-xs space-y-1 list-decimal list-inside",children:[r.jsx("li",{children:"Install the CD hook to your shell"}),r.jsxs("li",{children:["When you ",r.jsx("code",{className:"bg-slate-700 px-1 rounded",children:"cd"})," into a folder matching a workstream, it auto-activates"]}),r.jsx("li",{children:"If multiple workstreams match, you'll be prompted to choose"})]})]})]})})]}),r.jsxs("div",{className:"bg-white dark:bg-slate-950 rounded-xl border border-gray-200 dark:border-slate-800 shadow-sm p-4",children:[r.jsxs("div",{className:"flex items-center justify-between mb-4 pb-4 border-b border-gray-200 dark:border-slate-800",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(no,{className:"w-4 h-4 text-amber-500"}),r.jsx("span",{className:"text-sm font-medium text-gray-700 dark:text-slate-300",children:"Global Auto-Activate"}),r.jsx("span",{className:"text-xs text-gray-500 dark:text-slate-400",children:"(default for all workstreams)"})]}),r.jsx(te,{variant:ye.workstreamAutoActivate?"default":"outline",size:"sm",onClick:cr,children:ye.workstreamAutoActivate?"Enabled":"Disabled"})]}),lt.installed?r.jsxs("div",{className:"flex items-start gap-3 p-3 bg-green-50 dark:bg-green-900/20 rounded-lg border border-green-200 dark:border-green-800",children:[r.jsx(ao,{className:"w-5 h-5 text-green-600 dark:text-green-400 flex-shrink-0 mt-0.5"}),r.jsxs("div",{className:"flex-1",children:[r.jsx("p",{className:"font-medium text-green-800 dark:text-green-300",children:"CD Hook Installed"}),r.jsxs("p",{className:"text-xs text-green-600 dark:text-green-400 mt-1",children:["Shell: ",lt.shell," • RC file: ",r.jsx("code",{className:"bg-green-100 dark:bg-green-900/50 px-1 rounded",children:(Bi=lt.rcFile)==null?void 0:Bi.replace(/^\/Users\/[^/]+/,"~")})]}),r.jsxs(te,{variant:"outline",size:"sm",className:"mt-2",onClick:Ut,disabled:_e,children:[_e?r.jsx(Ze,{className:"w-4 h-4 animate-spin mr-2"}):null,"Uninstall"]})]})]}):r.jsxs("div",{className:"flex items-start gap-3 p-3 bg-amber-50 dark:bg-amber-900/20 rounded-lg border border-amber-200 dark:border-amber-800",children:[r.jsx(ks,{className:"w-5 h-5 text-amber-600 dark:text-amber-400 flex-shrink-0 mt-0.5"}),r.jsxs("div",{children:[r.jsx("p",{className:"font-medium text-amber-800 dark:text-amber-300 mb-1",children:"CD Hook Not Installed"}),r.jsx("p",{className:"text-xs text-amber-600 dark:text-amber-400 mb-2",children:"Install the hook to auto-activate workstreams when you cd into matching folders."}),r.jsxs(te,{variant:"default",size:"sm",onClick:Mt,disabled:_e||lt.loading,className:"bg-amber-600 hover:bg-amber-700 text-white",children:[_e?r.jsx(Ze,{className:"w-4 h-4 animate-spin mr-2"}):r.jsx(Kn,{className:"w-4 h-4 mr-2"}),"Install CD Hook"]}),r.jsxs("p",{className:"text-xs mt-2 text-amber-600 dark:text-amber-500",children:["Adds function to ",r.jsx("code",{className:"bg-amber-100 dark:bg-amber-900/50 px-1 rounded",children:"~/.zshrc"})," or ",r.jsx("code",{className:"bg-amber-100 dark:bg-amber-900/50 px-1 rounded",children:"~/.bashrc"})]})]})]})]})]}),U&&U.totalSessions>0&&r.jsxs("div",{className:"bg-white dark:bg-slate-950 rounded-xl border border-gray-200 dark:border-slate-800 shadow-sm p-4",children:[r.jsxs("div",{className:"flex items-center justify-between mb-4",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(i5,{className:"w-5 h-5 text-indigo-600 dark:text-indigo-400"}),r.jsx("h3",{className:"font-medium text-gray-900 dark:text-white",children:"Activity Insights"})]}),r.jsxs(te,{variant:"ghost",size:"sm",onClick:ms,className:"text-gray-500 dark:text-slate-400 hover:text-red-500",children:[r.jsx(ds,{className:"w-4 h-4 mr-1"}),"Clear Old"]})]}),r.jsxs("div",{className:"grid grid-cols-3 gap-4 mb-4",children:[r.jsxs("div",{className:"bg-gray-50 dark:bg-slate-900 rounded-lg p-3",children:[r.jsxs("div",{className:"flex items-center gap-2 text-gray-500 dark:text-slate-400 text-xs mb-1",children:[r.jsx(BC,{className:"w-3 h-3"}),"Sessions"]}),r.jsx("div",{className:"text-2xl font-semibold text-gray-900 dark:text-white",children:U.totalSessions})]}),r.jsxs("div",{className:"bg-gray-50 dark:bg-slate-900 rounded-lg p-3",children:[r.jsxs("div",{className:"flex items-center gap-2 text-gray-500 dark:text-slate-400 text-xs mb-1",children:[r.jsx(Pr,{className:"w-3 h-3"}),"Files Tracked"]}),r.jsx("div",{className:"text-2xl font-semibold text-gray-900 dark:text-white",children:U.totalFiles})]}),r.jsxs("div",{className:"bg-gray-50 dark:bg-slate-900 rounded-lg p-3",children:[r.jsxs("div",{className:"flex items-center gap-2 text-gray-500 dark:text-slate-400 text-xs mb-1",children:[r.jsx(gn,{className:"w-3 h-3"}),"Projects Active"]}),r.jsx("div",{className:"text-2xl font-semibold text-gray-900 dark:text-white",children:U.projectCount})]})]}),((ei=U.topProjects)==null?void 0:ei.length)>0&&r.jsxs("div",{children:[r.jsx("h4",{className:"text-sm font-medium text-gray-700 dark:text-slate-300 mb-2",children:"Most Active Projects"}),r.jsx("div",{className:"space-y-1",children:U.topProjects.slice(0,5).map((X,we)=>r.jsxs("div",{className:"flex items-center justify-between text-sm",children:[r.jsx("span",{className:"text-gray-600 dark:text-slate-400 truncate",title:X.path,children:X.path.split("/").pop()}),r.jsxs("span",{className:"text-gray-400 dark:text-slate-500 text-xs",children:[X.fileCount," files"]})]},X.path))})]})]}),fs.length>0&&r.jsxs("div",{className:"bg-gradient-to-r from-indigo-50 to-purple-50 dark:from-indigo-950/30 dark:to-purple-950/30 rounded-xl border border-indigo-200 dark:border-indigo-800 p-4",children:[r.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[r.jsx(Yt,{className:"w-5 h-5 text-indigo-600 dark:text-indigo-400"}),r.jsx("h3",{className:"font-medium text-indigo-900 dark:text-indigo-300",children:"Suggested Workstreams"}),r.jsx("span",{className:"text-xs bg-indigo-100 dark:bg-indigo-900/50 text-indigo-600 dark:text-indigo-400 px-1.5 py-0.5 rounded",children:"Based on activity patterns"})]}),r.jsx("p",{className:"text-sm text-indigo-700 dark:text-indigo-400 mb-4",children:"These projects are frequently worked on together. Create a workstream to group them?"}),r.jsx("div",{className:"space-y-3",children:fs.map(X=>r.jsxs("div",{className:"bg-white dark:bg-slate-900 rounded-lg border border-indigo-200 dark:border-indigo-800 p-3",children:[r.jsxs("div",{className:"flex items-center justify-between mb-2",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(no,{className:"w-4 h-4 text-amber-500"}),r.jsx("span",{className:"font-medium text-gray-900 dark:text-white",children:X.name}),X.coActivityScore&&r.jsxs("span",{className:"text-xs text-gray-500 dark:text-slate-400",children:[X.coActivityScore,"% co-activity"]})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(te,{size:"sm",variant:"ghost",onClick:()=>ln(X),className:"text-gray-400 hover:text-gray-600 dark:hover:text-slate-300",title:"Dismiss suggestion",children:r.jsx(Hn,{className:"w-4 h-4"})}),r.jsxs(te,{size:"sm",onClick:()=>$t(X),className:"bg-indigo-600 hover:bg-indigo-700",children:[r.jsx(jt,{className:"w-4 h-4 mr-1"}),"Create"]})]})]}),r.jsx("div",{className:"flex flex-wrap gap-1",children:X.projects.map(we=>r.jsx("span",{className:"text-xs bg-gray-100 dark:bg-slate-800 text-gray-600 dark:text-slate-400 px-2 py-0.5 rounded",children:we.split("/").pop()},we))})]},X.name))})]}),r.jsxs("div",{className:"bg-gray-50 dark:bg-slate-900 rounded-lg p-4 border border-transparent dark:border-slate-800",children:[r.jsx("h4",{className:"text-sm font-medium text-gray-900 dark:text-white mb-2",children:"CLI Commands"}),r.jsxs("div",{className:"space-y-1 text-sm text-gray-600 dark:text-slate-400 font-mono",children:[r.jsx("p",{children:"coder-config workstream # List workstreams"}),r.jsx("p",{children:'coder-config workstream use "Name" # Set workstream for this tab'}),r.jsx("p",{children:'coder-config workstream create "Name" # Create workstream'})]})]}),r.jsx(bt,{open:c,onOpenChange:X=>{X||(f(!1),v(""),E(""),T([]),O(!1),z({}))},children:r.jsxs(xt,{className:"max-w-lg max-h-[85vh] overflow-y-auto",children:[r.jsx(vt,{children:r.jsxs(yt,{className:"flex items-center gap-2",children:[r.jsx(gn,{className:"w-5 h-5 text-purple-600"}),"Create Workstream"]})}),r.jsxs("div",{className:"space-y-4 py-4",children:[r.jsxs("div",{children:[r.jsx("label",{className:"text-sm font-medium text-gray-700 dark:text-slate-300 mb-1 block",children:"Name"}),r.jsx(dt,{value:g,onChange:X=>v(X.target.value),placeholder:"e.g., User Auth, Admin Dashboard",autoFocus:!0})]}),r.jsxs("div",{children:[r.jsxs("div",{className:"flex items-center justify-between mb-2",children:[r.jsx("label",{className:"text-sm font-medium text-gray-700 dark:text-slate-300",children:"Projects"}),r.jsxs(te,{type:"button",size:"sm",variant:"outline",onClick:()=>O(!I),children:[r.jsx(zn,{className:"w-4 h-4 mr-1"}),"Add"]})]}),P.length>0?r.jsx("div",{className:"space-y-1 mb-2",children:P.map(X=>r.jsxs("div",{className:"flex items-center justify-between py-1.5 px-3 bg-gray-50 dark:bg-slate-800 rounded border border-gray-200 dark:border-slate-700",children:[r.jsx("span",{className:"text-sm font-mono text-gray-700 dark:text-slate-300 truncate",children:X.replace(/^\/Users\/[^/]+/,"~")}),r.jsx(te,{type:"button",size:"sm",variant:"ghost",onClick:()=>$r(X),className:"text-gray-400 hover:text-red-500 h-6 w-6 p-0",children:r.jsx(Hn,{className:"w-4 h-4"})})]},X))}):r.jsx("p",{className:"text-sm text-gray-500 dark:text-slate-400 italic mb-2",children:"No projects added. Add projects to help organize your workstream."}),I&&e.length>0&&r.jsx("div",{className:"border border-gray-200 dark:border-slate-700 rounded-lg p-2 max-h-64 overflow-y-auto bg-white dark:bg-slate-900",children:e.map(X=>{const we=Ts(X.path),Te=B[X.path],$e=G[X.path],Ve=q[X.path]||[],wt=P.includes(X.path);return r.jsxs("div",{className:"mb-1",children:[r.jsxs("div",{className:"flex items-center gap-1",children:[r.jsx("button",{type:"button",onClick:()=>fr(X.path),className:"p-1 hover:bg-gray-100 dark:hover:bg-slate-800 rounded",title:"Show sub-projects",children:$e?r.jsx(Ze,{className:"w-4 h-4 animate-spin text-gray-400"}):Te?r.jsx(vr,{className:"w-4 h-4 text-gray-400"}):r.jsx(Qr,{className:"w-4 h-4 text-gray-400"})}),r.jsxs("button",{type:"button",onClick:()=>tr(X.path),disabled:wt,className:`flex-1 text-left p-2 rounded transition-colors ${wt?"bg-purple-50 dark:bg-purple-950/30 opacity-50":"hover:bg-purple-50 dark:hover:bg-purple-950/30"}`,children:[r.jsxs("div",{className:"flex items-center justify-between text-sm",children:[r.jsx("span",{className:"font-medium text-gray-900 dark:text-white",children:X.name}),r.jsxs("div",{className:"flex items-center gap-1",children:[we&&r.jsx("span",{className:`text-xs px-1.5 py-0.5 rounded ${we==="shared"?"bg-amber-100 dark:bg-amber-900/50 text-amber-700 dark:text-amber-400":"bg-blue-100 dark:bg-blue-900/50 text-blue-700 dark:text-blue-400"}`,children:we}),wt&&r.jsx(Tt,{className:"w-4 h-4 text-purple-600"})]})]}),r.jsx("div",{className:"text-xs text-gray-500 dark:text-slate-400 font-mono truncate",children:X.path.replace(/^\/Users\/[^/]+/,"~")})]})]}),Te&&Ve.length>0&&r.jsx("div",{className:"ml-6 mt-1 space-y-1 border-l-2 border-gray-200 dark:border-slate-700 pl-2",children:Ve.map(dr=>{const Xt=P.includes(dr.dir),Cr=Ts(dr.dir);return r.jsxs("button",{type:"button",onClick:()=>tr(dr.dir),disabled:Xt,className:`w-full text-left p-2 rounded transition-colors ${Xt?"bg-purple-50 dark:bg-purple-950/30 opacity-50":"hover:bg-purple-50 dark:hover:bg-purple-950/30"}`,children:[r.jsxs("div",{className:"flex items-center justify-between text-sm",children:[r.jsx("span",{className:"text-gray-700 dark:text-slate-300",children:dr.name}),r.jsxs("div",{className:"flex items-center gap-1",children:[Cr&&r.jsx("span",{className:`text-xs px-1.5 py-0.5 rounded ${Cr==="shared"?"bg-amber-100 dark:bg-amber-900/50 text-amber-700 dark:text-amber-400":"bg-blue-100 dark:bg-blue-900/50 text-blue-700 dark:text-blue-400"}`,children:Cr}),Xt&&r.jsx(Tt,{className:"w-4 h-4 text-purple-600"})]})]}),r.jsx("div",{className:"text-xs text-gray-500 dark:text-slate-400 font-mono",children:dr.relativePath})]},dr.dir)})}),Te&&Ve.length===0&&!$e&&r.jsx("div",{className:"ml-6 mt-1 pl-2 text-xs text-gray-400 dark:text-slate-500 italic",children:"No sub-projects found"})]},X.id)})})]}),r.jsxs("div",{children:[r.jsxs("div",{className:"flex items-center justify-between mb-1",children:[r.jsx("label",{className:"text-sm font-medium text-gray-700 dark:text-slate-300",children:"Context (optional)"}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsxs("label",{className:"flex items-center gap-1.5 text-xs text-gray-500 dark:text-slate-400 cursor-pointer",children:[r.jsx(ho,{checked:oe,onCheckedChange:Se,className:"h-3.5 w-3.5"}),"Use Claude"]}),r.jsxs(te,{type:"button",size:"sm",variant:"ghost",onClick:()=>cn(P,E),disabled:re||P.length===0,className:"text-xs h-7 text-purple-600 hover:text-purple-700 hover:bg-purple-50 dark:hover:bg-purple-950/30",title:oe?"Use Claude Code to analyze repos":"Extract from README, package.json, etc.",children:[re?r.jsx(Ze,{className:"w-3 h-3 animate-spin mr-1"}):r.jsx(zs,{className:"w-3 h-3 mr-1"}),"Generate"]})]})]}),r.jsx(_t,{value:k,onChange:X=>E(X.target.value),placeholder:"Context rules for this workstream. These will be injected into every Claude session when this workstream is active.",rows:6}),r.jsx("p",{className:"text-xs text-gray-500 dark:text-slate-400 mt-1",children:'Example: "Focus on user authentication. Use JWT tokens. React Query for state management."'})]})]}),r.jsxs(St,{children:[r.jsx(te,{variant:"outline",onClick:()=>{f(!1),v(""),E(""),T([]),O(!1),z({})},children:"Cancel"}),r.jsxs(te,{onClick:sr,disabled:N||!g.trim(),className:"bg-purple-600 hover:bg-purple-700",children:[N?r.jsx(Ze,{className:"w-4 h-4 animate-spin mr-2"}):r.jsx(jt,{className:"w-4 h-4 mr-2"}),"Create"]})]})]})}),r.jsx(bt,{open:!!m,onOpenChange:X=>!X&&h(null),children:r.jsxs(xt,{className:"max-w-lg max-h-[85vh] overflow-y-auto",children:[r.jsx(vt,{children:r.jsxs(yt,{className:"flex items-center gap-2",children:[r.jsx(rm,{className:"w-5 h-5 text-purple-600"}),"Edit Workstream"]})}),m&&r.jsxs("div",{className:"space-y-4 py-4",children:[r.jsxs("div",{children:[r.jsx("label",{className:"text-sm font-medium text-gray-700 dark:text-slate-300 mb-1 block",children:"Name"}),r.jsx(dt,{value:m.name,onChange:X=>h(we=>({...we,name:X.target.value}))})]}),r.jsxs("div",{children:[r.jsxs("div",{className:"flex items-center justify-between mb-2",children:[r.jsx("label",{className:"text-sm font-medium text-gray-700 dark:text-slate-300",children:"Projects"}),r.jsxs(te,{type:"button",size:"sm",variant:"outline",onClick:()=>h(X=>({...X,showPicker:!X.showPicker})),children:[r.jsx(zn,{className:"w-4 h-4 mr-1"}),"Add"]})]}),((ti=m.projects)==null?void 0:ti.length)>0?r.jsx("div",{className:"space-y-1 mb-2",children:m.projects.map(X=>r.jsxs("div",{className:"flex items-center justify-between py-1.5 px-3 bg-gray-50 dark:bg-slate-800 rounded border border-gray-200 dark:border-slate-700",children:[r.jsx("span",{className:"text-sm font-mono text-gray-700 dark:text-slate-300 truncate",children:X.replace(/^\/Users\/[^/]+/,"~")}),r.jsx(te,{type:"button",size:"sm",variant:"ghost",onClick:()=>h(we=>({...we,projects:we.projects.filter(Te=>Te!==X)})),className:"text-gray-400 hover:text-red-500 h-6 w-6 p-0",children:r.jsx(Hn,{className:"w-4 h-4"})})]},X))}):r.jsx("p",{className:"text-sm text-gray-500 dark:text-slate-400 italic mb-2",children:"No projects in this workstream."}),m.showPicker&&e.length>0&&r.jsx("div",{className:"border border-gray-200 dark:border-slate-700 rounded-lg p-2 max-h-48 overflow-y-auto bg-white dark:bg-slate-900",children:e.map(X=>{var dr;const we=(dr=m.projects)==null?void 0:dr.includes(X.path),Te=Ts(X.path,m.id),$e=B[X.path],Ve=G[X.path],wt=q[X.path]||[];return r.jsxs("div",{className:"mb-1",children:[r.jsxs("div",{className:"flex items-center gap-1",children:[r.jsx("button",{type:"button",onClick:()=>fr(X.path),className:"p-1 hover:bg-gray-100 dark:hover:bg-slate-800 rounded",title:"Show sub-projects",children:Ve?r.jsx(Ze,{className:"w-4 h-4 animate-spin text-gray-400"}):$e?r.jsx(vr,{className:"w-4 h-4 text-gray-400"}):r.jsx(Qr,{className:"w-4 h-4 text-gray-400"})}),r.jsxs("button",{type:"button",onClick:()=>!we&&h(Xt=>({...Xt,projects:[...Xt.projects||[],X.path]})),disabled:we,className:`flex-1 text-left p-2 rounded transition-colors ${we?"bg-purple-50 dark:bg-purple-950/30 opacity-50":"hover:bg-purple-50 dark:hover:bg-purple-950/30"}`,children:[r.jsxs("div",{className:"flex items-center justify-between text-sm",children:[r.jsx("span",{className:"font-medium text-gray-900 dark:text-white",children:X.name}),r.jsxs("div",{className:"flex items-center gap-1",children:[Te&&r.jsx("span",{className:`text-xs px-1.5 py-0.5 rounded ${Te==="shared"?"bg-amber-100 dark:bg-amber-900/50 text-amber-700 dark:text-amber-400":"bg-blue-100 dark:bg-blue-900/50 text-blue-700 dark:text-blue-400"}`,children:Te}),we&&r.jsx(Tt,{className:"w-4 h-4 text-purple-600"})]})]}),r.jsx("div",{className:"text-xs text-gray-500 dark:text-slate-400 font-mono truncate",children:X.path.replace(/^\/Users\/[^/]+/,"~")})]})]}),$e&&wt.length>0&&r.jsx("div",{className:"ml-6 mt-1 space-y-1 border-l-2 border-gray-200 dark:border-slate-700 pl-2",children:wt.map(Xt=>{var Ks;const Cr=(Ks=m.projects)==null?void 0:Ks.includes(Xt.dir),gs=Ts(Xt.dir,m.id);return r.jsxs("button",{type:"button",onClick:()=>!Cr&&h(Rr=>({...Rr,projects:[...Rr.projects||[],Xt.dir]})),disabled:Cr,className:`w-full text-left p-2 rounded transition-colors ${Cr?"bg-purple-50 dark:bg-purple-950/30 opacity-50":"hover:bg-purple-50 dark:hover:bg-purple-950/30"}`,children:[r.jsxs("div",{className:"flex items-center justify-between text-sm",children:[r.jsx("span",{className:"text-gray-700 dark:text-slate-300",children:Xt.name}),r.jsxs("div",{className:"flex items-center gap-1",children:[gs&&r.jsx("span",{className:`text-xs px-1.5 py-0.5 rounded ${gs==="shared"?"bg-amber-100 dark:bg-amber-900/50 text-amber-700 dark:text-amber-400":"bg-blue-100 dark:bg-blue-900/50 text-blue-700 dark:text-blue-400"}`,children:gs}),Cr&&r.jsx(Tt,{className:"w-4 h-4 text-purple-600"})]})]}),r.jsx("div",{className:"text-xs text-gray-500 dark:text-slate-400 font-mono truncate",children:Xt.relativePath})]},Xt.dir)})}),$e&&wt.length===0&&!Ve&&r.jsx("div",{className:"ml-6 mt-1 pl-2 text-xs text-gray-400 dark:text-slate-500 italic",children:"No sub-projects found"})]},X.id)})})]}),r.jsxs("div",{children:[r.jsxs("div",{className:"flex items-center justify-between mb-1",children:[r.jsx("label",{className:"text-sm font-medium text-gray-700 dark:text-slate-300",children:"Rules"}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsxs("label",{className:"flex items-center gap-1.5 text-xs text-gray-500 dark:text-slate-400 cursor-pointer",children:[r.jsx(ho,{checked:oe,onCheckedChange:Se,className:"h-3.5 w-3.5"}),"Use Claude"]}),r.jsxs(te,{type:"button",size:"sm",variant:"ghost",onClick:()=>cn(m.projects,X=>h(we=>({...we,rules:X}))),disabled:re||!((ce=m.projects)!=null&&ce.length),className:"text-xs h-7 text-purple-600 hover:text-purple-700 hover:bg-purple-50 dark:hover:bg-purple-950/30",title:oe?"Use Claude Code to analyze repos":"Extract from README, package.json, etc.",children:[re?r.jsx(Ze,{className:"w-3 h-3 animate-spin mr-1"}):r.jsx(zs,{className:"w-3 h-3 mr-1"}),"Generate"]})]})]}),r.jsx(_t,{value:m.rules||"",onChange:X=>h(we=>({...we,rules:X.target.value})),placeholder:"Context rules for this workstream...",rows:8})]})]}),r.jsxs(St,{children:[r.jsx(te,{variant:"outline",onClick:()=>h(null),children:"Cancel"}),r.jsxs(te,{onClick:qr,disabled:N,className:"bg-purple-600 hover:bg-purple-700",children:[N?r.jsx(Ze,{className:"w-4 h-4 animate-spin mr-2"}):r.jsx(Ps,{className:"w-4 h-4 mr-2"}),"Save Changes"]})]})]})}),r.jsx(bt,{open:x,onOpenChange:X=>{w(X),X||(z({}),b(new Set))},children:r.jsxs(xt,{className:"max-w-lg",children:[r.jsx(vt,{children:r.jsxs(yt,{className:"flex items-center gap-2",children:[r.jsx(zn,{className:"w-5 h-5 text-purple-600"}),"Add Project to ",j==null?void 0:j.name]})}),r.jsxs("div",{className:"py-4",children:[r.jsx("p",{className:"text-sm text-gray-600 dark:text-slate-400 mb-4",children:"Select projects to add to this workstream (multi-select enabled):"}),e.length>0?r.jsx("div",{className:"space-y-1 max-h-64 overflow-y-auto border border-gray-200 dark:border-slate-700 rounded-lg p-2 bg-white dark:bg-slate-900",children:e.map(X=>{var Xt;const we=(Xt=j==null?void 0:j.projects)==null?void 0:Xt.includes(X.path),Te=y.has(X.path),$e=Ts(X.path,j==null?void 0:j.id),Ve=B[X.path],wt=G[X.path],dr=q[X.path]||[];return r.jsxs("div",{className:"mb-1",children:[r.jsxs("div",{className:"flex items-center gap-1",children:[r.jsx("button",{type:"button",onClick:()=>fr(X.path),className:"p-1 hover:bg-gray-100 dark:hover:bg-slate-800 rounded",title:"Show sub-projects",children:wt?r.jsx(Ze,{className:"w-4 h-4 animate-spin text-gray-400"}):Ve?r.jsx(vr,{className:"w-4 h-4 text-gray-400"}):r.jsx(Qr,{className:"w-4 h-4 text-gray-400"})}),r.jsxs("button",{type:"button",onClick:()=>!we&&Li(X.path),disabled:we,className:`flex-1 text-left p-2 rounded transition-colors ${we?"bg-gray-100 dark:bg-slate-800 opacity-50 cursor-not-allowed":Te?"bg-purple-100 dark:bg-purple-950/50 ring-2 ring-purple-500":"hover:bg-purple-50 dark:hover:bg-purple-950/30"}`,children:[r.jsxs("div",{className:"flex items-center justify-between text-sm",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("div",{className:`w-4 h-4 rounded border-2 flex items-center justify-center ${we?"bg-gray-300 dark:bg-slate-600 border-gray-300 dark:border-slate-600":Te?"bg-purple-600 border-purple-600":"border-gray-300 dark:border-slate-600"}`,children:(we||Te)&&r.jsx(Tt,{className:"w-3 h-3 text-white"})}),r.jsx("span",{className:"font-medium text-gray-900 dark:text-white",children:X.name})]}),r.jsxs("div",{className:"flex items-center gap-1",children:[$e&&r.jsx("span",{className:`text-xs px-1.5 py-0.5 rounded ${$e==="shared"?"bg-amber-100 dark:bg-amber-900/50 text-amber-700 dark:text-amber-400":"bg-blue-100 dark:bg-blue-900/50 text-blue-700 dark:text-blue-400"}`,children:$e}),we&&r.jsx("span",{className:"text-xs text-gray-500 dark:text-slate-400",children:"added"})]})]}),r.jsx("div",{className:"text-xs text-gray-500 dark:text-slate-400 font-mono truncate ml-6",children:X.path.replace(/^\/Users\/[^/]+/,"~")})]})]}),Ve&&dr.length>0&&r.jsx("div",{className:"ml-6 mt-1 space-y-1 border-l-2 border-gray-200 dark:border-slate-700 pl-2",children:dr.map(Cr=>{var hc;const gs=(hc=j==null?void 0:j.projects)==null?void 0:hc.includes(Cr.dir),Ks=y.has(Cr.dir),Rr=Ts(Cr.dir,j==null?void 0:j.id);return r.jsxs("button",{type:"button",onClick:()=>!gs&&Li(Cr.dir),disabled:gs,className:`w-full text-left p-2 rounded transition-colors ${gs?"bg-gray-100 dark:bg-slate-800 opacity-50 cursor-not-allowed":Ks?"bg-purple-100 dark:bg-purple-950/50 ring-2 ring-purple-500":"hover:bg-purple-50 dark:hover:bg-purple-950/30"}`,children:[r.jsxs("div",{className:"flex items-center justify-between text-sm",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("div",{className:`w-4 h-4 rounded border-2 flex items-center justify-center ${gs?"bg-gray-300 dark:bg-slate-600 border-gray-300 dark:border-slate-600":Ks?"bg-purple-600 border-purple-600":"border-gray-300 dark:border-slate-600"}`,children:(gs||Ks)&&r.jsx(Tt,{className:"w-3 h-3 text-white"})}),r.jsx("span",{className:"text-gray-700 dark:text-slate-300",children:Cr.name})]}),r.jsxs("div",{className:"flex items-center gap-1",children:[Rr&&r.jsx("span",{className:`text-xs px-1.5 py-0.5 rounded ${Rr==="shared"?"bg-amber-100 dark:bg-amber-900/50 text-amber-700 dark:text-amber-400":"bg-blue-100 dark:bg-blue-900/50 text-blue-700 dark:text-blue-400"}`,children:Rr}),gs&&r.jsx("span",{className:"text-xs text-gray-500 dark:text-slate-400",children:"added"})]})]}),r.jsx("div",{className:"text-xs text-gray-500 dark:text-slate-400 font-mono truncate ml-6",children:Cr.relativePath})]},Cr.dir)})}),Ve&&dr.length===0&&!wt&&r.jsx("div",{className:"ml-6 mt-1 pl-2 text-xs text-gray-400 dark:text-slate-500 italic",children:"No sub-projects found"})]},X.id)})}):r.jsx("p",{className:"text-sm text-gray-500 dark:text-slate-400 text-center py-4",children:"No projects registered. Add projects in the Projects view first."})]}),r.jsxs(St,{children:[r.jsx(te,{variant:"outline",onClick:()=>{w(!1),b(new Set)},children:"Cancel"}),r.jsxs(te,{onClick:Oi,disabled:y.size===0||N,className:"bg-purple-600 hover:bg-purple-700",children:[N?r.jsx(Ze,{className:"w-4 h-4 animate-spin mr-2"}):r.jsx(jt,{className:"w-4 h-4 mr-2"}),"Add Selected (",y.size,")"]})]})]})}),r.jsx(bt,{open:ie,onOpenChange:X=>{X||(de(!1),pt(""),ze(null))},children:r.jsxs(xt,{children:[r.jsx(vt,{children:r.jsx(yt,{children:"Add Trigger Folder"})}),r.jsxs("div",{className:"space-y-4 py-4",children:[r.jsxs("p",{className:"text-sm text-gray-600 dark:text-slate-400",children:["Add a folder that will trigger the workstream ",r.jsx("strong",{children:Ae==null?void 0:Ae.name})," when you cd into it."]}),r.jsxs("div",{children:[r.jsx("label",{className:"text-sm font-medium text-gray-700 dark:text-slate-300 mb-1 block",children:"Folder Path"}),r.jsx(dt,{value:Fe,onChange:X=>pt(X.target.value),placeholder:"~/path/to/folder",className:"font-mono"}),r.jsx("p",{className:"text-xs text-gray-500 dark:text-slate-400 mt-1",children:"Use absolute path or ~ for home directory"})]})]}),r.jsxs(St,{children:[r.jsx(te,{variant:"outline",onClick:()=>{de(!1),pt(""),ze(null)},children:"Cancel"}),r.jsxs(te,{onClick:Gt,disabled:!Fe.trim(),className:"bg-purple-600 hover:bg-purple-700",children:[r.jsx(zn,{className:"w-4 h-4 mr-2"}),"Add Folder"]})]})]})})]})}const e_={clarify:"bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-200",plan:"bg-purple-100 text-purple-800 dark:bg-purple-900 dark:text-purple-200",execute:"bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-200"},Yo={pending:r.jsx(Sl,{className:"w-4 h-4 text-gray-500"}),running:r.jsx(UC,{className:"w-4 h-4 text-green-500"}),paused:r.jsx(Zm,{className:"w-4 h-4 text-yellow-500"}),completed:r.jsx(ao,{className:"w-4 h-4 text-green-600"}),failed:r.jsx(sa,{className:"w-4 h-4 text-red-500"}),cancelled:r.jsx(sa,{className:"w-4 h-4 text-gray-500"})};function qH({activeProject:e=null}){var bo,As,Fi,Ts,Bi,ei,ti;const[t,s]=C.useState([]),[n,o]=C.useState(!0),[d,u]=C.useState(null),[l,c]=C.useState({}),[f,m]=C.useState([]),[h,x]=C.useState(null),[w,j]=C.useState(""),[_,y]=C.useState(!1),[b,g]=C.useState(!1),[v,k]=C.useState(!1),[E,P]=C.useState(!1),[T,N]=C.useState(null),[M,I]=C.useState(""),[O,B]=C.useState(""),[z,q]=C.useState(50),[H,G]=C.useState("DONE"),[Q,K]=C.useState(!1),[F,R]=C.useState(50),[L,U]=C.useState(!1),[$,ne]=C.useState("DONE"),[fe,pe]=C.useState([]),[J,W]=C.useState({stopHook:{},prepromptHook:{}}),[le,re]=C.useState(!1),[Z,oe]=C.useState({needsInstall:!0}),[Se,Be]=C.useState(!1),[Ue,ue]=C.useState(null),[be,Qe]=C.useState(null),[Ye,lt]=C.useState(!1),[je,ye]=C.useState(!1),[Ne,_e]=C.useState(null),[Ee,ie]=C.useState(!0),[de,Ae]=C.useState(null),[ze,Fe]=C.useState(!1);C.useEffect(()=>{Vt(),Br(),$t(),lr(),ct()},[]);const pt=C.useRef(null);C.useEffect(()=>{if(!je||!Ne){pt.current=null;return}pt.current=Ne.status;const ce=setInterval(async()=>{var X,we,Te;try{const Ve=(await xe.getLoop(Ne.id)).loop,wt=pt.current!==Ve.status,dr=["completed","paused","failed","cancelled"].includes(Ve.status);if(wt&&dr){clearInterval(ce);const Xt={name:Ve.name,task:(X=Ve.task)==null?void 0:X.original,status:Ve.status,pauseReason:Ve.pauseReason,iterations:((we=Ve.iterations)==null?void 0:we.current)||0,maxIterations:((Te=Ve.iterations)==null?void 0:Te.max)||50,phase:Ve.phase,startedAt:Ve.startedAt,completedAt:Ve.completedAt||new Date().toISOString(),duration:Ve.startedAt?Math.round((Date.now()-new Date(Ve.startedAt).getTime())/1e3):null};Ae(Xt),Ve.status==="completed"?Y.success("Loop completed successfully!"):Ve.status==="paused"?Y.info(`Loop paused: ${Ve.pauseReason||"unknown reason"}`):Ve.status==="failed"?Y.error("Loop failed"):Ve.status==="cancelled"&&Y.warning("Loop cancelled"),Vt(),Ee&&Ve.status==="completed"?setTimeout(()=>{ye(!1),_e(null),Fe(!0)},1500):Fe(!0)}pt.current=Ve.status}catch($e){console.error("Failed to poll loop status:",$e)}},3e3);return()=>clearInterval(ce)},[je,Ne,Ee]);const ct=async()=>{try{const ce=await xe.getRalphLoopPluginStatus();oe(ce)}catch(ce){console.error("Failed to load plugin status:",ce)}},lr=async()=>{try{const ce=await xe.getWorkstreams();m(ce.workstreams||[]),x(ce.activeId||null)}catch(ce){console.error("Failed to load workstreams:",ce)}};C.useEffect(()=>{_&&h&&B(h)},[_,h]);const Vt=async()=>{try{o(!0);const ce=await xe.getLoops();s(ce.loops||[]),c(ce.config||{})}catch{Y.error("Failed to load loops")}finally{o(!1)}},Br=async()=>{try{const X=(await xe.getLoopConfig()).config||{};c(X),R(X.maxIterations||50),U(X.autoApprovePlan||!1),ne(X.completionPromise||"DONE"),q(X.maxIterations||50),G(X.completionPromise||"DONE")}catch(ce){console.error("Failed to load config:",ce)}},$t=async()=>{try{const ce=await xe.getLoopHookStatus();W(ce)}catch(ce){console.error("Failed to load hook status:",ce)}},$r=async()=>{try{const ce=await xe.getLoopHistory();pe(ce.completed||[])}catch{Y.error("Failed to load history")}},tr=async()=>{if(!M.trim()){Y.error("Task description is required");return}try{K(!0);const ce=await xe.createLoop(M,{workstreamId:O||null,projectPath:(e==null?void 0:e.path)||(e==null?void 0:e.dir)||null,maxIterations:parseInt(z,10)||50,completionPromise:H||"DONE"});ce.success?(Y.success("Loop created"),y(!1),I(""),B(""),q(F),G($),Vt()):Y.error(ce.error||"Failed to create loop")}catch(ce){Y.error(ce.message)}finally{K(!1)}},fr=async ce=>{if(Z.needsInstall){ue(ce),Qe("start"),Be(!0);return}await ln(ce)},ln=async ce=>{try{const X=await xe.startLoop(ce);X.success&&X.loop?(Y.success("Loop started - launching Claude Code"),_e(X.loop),ye(!0),Vt()):Y.error(X.error||"Failed to start loop")}catch(X){Y.error(X.message)}},fs=async()=>{try{lt(!0);const ce=await xe.installRalphLoopPlugin();ce.success?(Y.success("ralph-loop plugin installed"),oe({installed:!0,scope:"user",needsInstall:!1}),Be(!1),Ue&&(be==="resume"?await Ut(Ue):await ln(Ue),ue(null),Qe(null))):Y.error(ce.error||"Failed to install plugin")}catch(ce){Y.error(ce.message)}finally{lt(!1)}},ms=()=>{Be(!1),ue(null),Qe(null)},cn=C.useCallback(async(ce,X)=>{var we,Te;if(Ne)try{const Ve=(await xe.getLoop(Ne.id)).loop;Ve.taskComplete||Ve.status==="completed"?(Y.success("Loop completed successfully!"),ye(!1),_e(null)):Ve.status==="paused"?Y.info(`Loop paused: ${Ve.pauseReason||"user requested"}`):((we=Ve.iterations)==null?void 0:we.current)>=((Te=Ve.iterations)==null?void 0:Te.max)?(Y.warning("Loop reached max iterations"),await xe.pauseLoop(Ve.id)):Y.info("Claude exited. Click Start to continue the loop."),Vt()}catch($e){console.error("Failed to check loop status:",$e)}},[Ne]),it=async ce=>{try{const X=await xe.pauseLoop(ce);X.success?(Y.success("Loop paused"),Vt()):Y.error(X.error||"Failed to pause loop")}catch(X){Y.error(X.message)}},Mt=async ce=>{if(Z.needsInstall){ue(ce),Qe("resume"),Be(!0);return}await Ut(ce)},Ut=async ce=>{try{const X=await xe.resumeLoop(ce);X.success&&X.loop?(Y.success("Loop resumed - launching Claude Code"),_e(X.loop),ye(!0),Vt()):Y.error(X.error||"Failed to resume loop")}catch(X){Y.error(X.message)}},cr=async ce=>{if(confirm("Cancel this loop?"))try{const X=await xe.cancelLoop(ce);X.success?(Y.success("Loop cancelled"),Vt()):Y.error(X.error||"Failed to cancel loop")}catch(X){Y.error(X.message)}},es=async ce=>{if(confirm("Delete this loop and all its data?"))try{const X=await xe.deleteLoop(ce);X.success?(Y.success("Loop deleted"),Vt()):Y.error(X.error||"Failed to delete loop")}catch(X){Y.error(X.message)}},Gt=async ce=>{try{const X=await xe.approveLoop(ce);X.success?(Y.success("Plan approved"),Vt()):Y.error(X.error||"Failed to approve plan")}catch(X){Y.error(X.message)}},rr=async()=>{try{K(!0);const ce=await xe.updateLoopConfig({maxIterations:parseInt(F,10),autoApprovePlan:L,completionPromise:$});ce.success?(Y.success("Configuration saved"),g(!1),Br()):Y.error(ce.error||"Failed to save configuration")}catch(ce){Y.error(ce.message)}finally{K(!1)}},ps=async()=>{try{re(!0);const ce=await xe.installLoopHooks();ce.success?(Y.success("Hooks installed successfully"),$t()):Y.error(ce.error||"Failed to install hooks")}catch(ce){Y.error(ce.message)}finally{re(!1)}},sr=async ce=>{try{const X=await xe.getLoop(ce.id);N({...X.loop,clarifications:X.clarifications,plan:X.plan}),P(!0)}catch{Y.error("Failed to load loop details")}},Tr=ce=>{navigator.clipboard.writeText(ce),Y.success("Copied to clipboard")},qr=ce=>ce?new Date(ce).toLocaleString():"-",_r=ce=>ce.iterations?Math.min(100,ce.iterations.current/ce.iterations.max*100):0,Tn=((bo=J.stopHook)==null?void 0:bo.registered)&&((As=J.prepromptHook)==null?void 0:As.registered),Zn=ce=>{if(!ce)return null;const X=f.find(we=>we.id===ce);return(X==null?void 0:X.name)||ce},Li=w?t.filter(ce=>ce.workstreamId===w):t,Oi=ce=>{var $e,Ve;const X=((($e=ce.task)==null?void 0:$e.original)||"").replace(/"/g,'\\"'),we=((Ve=ce.iterations)==null?void 0:Ve.max)||50,Te=ce.completionPromise||"DONE";return`claude --dangerously-skip-permissions "/ralph-loop ${X} --max-iterations ${we} --completion-promise '${Te}'"`};return r.jsxs("div",{className:"p-6 space-y-6 max-w-6xl mx-auto",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsxs("h1",{className:"text-2xl font-bold flex items-center gap-2",children:[r.jsx(Dl,{className:"w-6 h-6"}),"Ralph Loops"]}),r.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"Autonomous development loops using the official ralph-loop plugin"})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[f.length>0&&r.jsxs("div",{className:"flex items-center gap-1",children:[r.jsx(mg,{className:"w-4 h-4 text-muted-foreground"}),r.jsxs("select",{className:"text-sm border rounded px-2 py-1 bg-background",value:w,onChange:ce=>j(ce.target.value),children:[r.jsx("option",{value:"",children:"All workstreams"}),f.map(ce=>r.jsx("option",{value:ce.id,children:ce.name},ce.id))]})]}),r.jsx(xr,{children:r.jsxs(Ot,{children:[r.jsx(Ft,{asChild:!0,children:r.jsxs(te,{variant:"outline",size:"sm",onClick:()=>{$r(),k(!0)},children:[r.jsx(Qd,{className:"w-4 h-4 mr-1"}),"History"]})}),r.jsx(Rt,{children:"View completed loops"})]})}),r.jsx(xr,{children:r.jsxs(Ot,{children:[r.jsx(Ft,{asChild:!0,children:r.jsxs(te,{variant:"outline",size:"sm",onClick:()=>g(!0),children:[r.jsx(Vs,{className:"w-4 h-4 mr-1"}),"Config"]})}),r.jsx(Rt,{children:"Configure loop defaults"})]})}),r.jsxs(te,{onClick:()=>y(!0),children:[r.jsx(jt,{className:"w-4 h-4 mr-1"}),"New Loop"]})]})]}),!Tn&&r.jsxs("div",{className:"bg-yellow-50 dark:bg-yellow-900/20 border border-yellow-200 dark:border-yellow-800 rounded-lg p-4 flex items-center justify-between",children:[r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx(ks,{className:"w-5 h-5 text-yellow-600"}),r.jsxs("div",{children:[r.jsx("p",{className:"font-medium text-yellow-800 dark:text-yellow-200",children:"Hooks not installed"}),r.jsx("p",{className:"text-sm text-yellow-700 dark:text-yellow-300",children:"Install the Ralph Loop hooks to enable automatic loop continuation"})]})]}),r.jsxs(te,{variant:"outline",size:"sm",onClick:ps,disabled:le,children:[le?r.jsx(Ze,{className:"w-4 h-4 animate-spin mr-1"}):null,"Install Hooks"]})]}),n?r.jsx("div",{className:"flex items-center justify-center py-12",children:r.jsx(Ze,{className:"w-6 h-6 animate-spin text-muted-foreground"})}):Li.length===0?r.jsxs("div",{className:"text-center py-12 text-muted-foreground",children:[r.jsx(Dl,{className:"w-12 h-12 mx-auto mb-4 opacity-50"}),r.jsx("p",{className:"text-lg font-medium",children:w?"No loops in this workstream":"No loops yet"}),r.jsx("p",{className:"text-sm mt-1",children:"Create a loop to start autonomous development"})]}):r.jsx("div",{className:"space-y-3",children:Li.map(ce=>{var X,we,Te,$e,Ve;return r.jsxs("div",{className:"border rounded-lg bg-card overflow-hidden",children:[r.jsxs("div",{className:"p-4 cursor-pointer hover:bg-muted/50 transition-colors",onClick:()=>u(d===ce.id?null:ce.id),children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{className:"flex items-center gap-3",children:[d===ce.id?r.jsx(vr,{className:"w-4 h-4 text-muted-foreground"}):r.jsx(Qr,{className:"w-4 h-4 text-muted-foreground"}),Yo[ce.status]||Yo.pending,r.jsxs("div",{children:[r.jsx("h3",{className:"font-medium",children:ce.name}),r.jsx("p",{className:"text-sm text-muted-foreground truncate max-w-md",children:((X=ce.task)==null?void 0:X.original)||"No task"})]})]}),r.jsxs("div",{className:"flex items-center gap-3",children:[ce.workstreamId&&r.jsxs("span",{className:"text-xs px-2 py-0.5 rounded-full bg-purple-100 text-purple-800 dark:bg-purple-900 dark:text-purple-200 flex items-center gap-1",children:[r.jsx(gn,{className:"w-3 h-3"}),Zn(ce.workstreamId)]}),r.jsx("span",{className:`text-xs px-2 py-0.5 rounded-full ${e_[ce.phase]||"bg-gray-100 dark:bg-gray-800"}`,children:ce.phase}),r.jsxs("span",{className:"text-sm text-muted-foreground",children:[((we=ce.iterations)==null?void 0:we.current)||0,"/",((Te=ce.iterations)==null?void 0:Te.max)||50]}),r.jsxs("div",{className:"flex items-center gap-1",onClick:wt=>wt.stopPropagation(),children:[ce.status==="pending"&&r.jsx(xr,{children:r.jsxs(Ot,{children:[r.jsx(Ft,{asChild:!0,children:r.jsx(te,{variant:"ghost",size:"sm",onClick:()=>fr(ce.id),children:r.jsx(UC,{className:"w-4 h-4"})})}),r.jsx(Rt,{children:"Start loop"})]})}),ce.status==="running"&&r.jsx(xr,{children:r.jsxs(Ot,{children:[r.jsx(Ft,{asChild:!0,children:r.jsx(te,{variant:"ghost",size:"sm",onClick:()=>it(ce.id),children:r.jsx(Zm,{className:"w-4 h-4"})})}),r.jsx(Rt,{children:"Pause loop"})]})}),ce.status==="paused"&&r.jsx(xr,{children:r.jsxs(Ot,{children:[r.jsx(Ft,{asChild:!0,children:r.jsx(te,{variant:"ghost",size:"sm",onClick:()=>Mt(ce.id),children:r.jsx(sm,{className:"w-4 h-4"})})}),r.jsx(Rt,{children:"Resume loop"})]})}),(ce.status==="cancelled"||ce.status==="failed")&&r.jsx(xr,{children:r.jsxs(Ot,{children:[r.jsx(Ft,{asChild:!0,children:r.jsx(te,{variant:"ghost",size:"sm",onClick:()=>fr(ce.id),children:r.jsx(sm,{className:"w-4 h-4"})})}),r.jsx(Rt,{children:"Restart loop"})]})}),ce.phase==="plan"&&ce.status==="running"&&r.jsx(xr,{children:r.jsxs(Ot,{children:[r.jsx(Ft,{asChild:!0,children:r.jsx(te,{variant:"ghost",size:"sm",onClick:()=>Gt(ce.id),children:r.jsx(Tt,{className:"w-4 h-4"})})}),r.jsx(Rt,{children:"Approve plan"})]})}),r.jsx(xr,{children:r.jsxs(Ot,{children:[r.jsx(Ft,{asChild:!0,children:r.jsx(te,{variant:"ghost",size:"sm",onClick:()=>sr(ce),children:r.jsx(hg,{className:"w-4 h-4"})})}),r.jsx(Rt,{children:"View details"})]})}),(ce.status==="running"||ce.status==="paused")&&r.jsx(xr,{children:r.jsxs(Ot,{children:[r.jsx(Ft,{asChild:!0,children:r.jsx(te,{variant:"ghost",size:"sm",onClick:()=>cr(ce.id),children:r.jsx(sa,{className:"w-4 h-4"})})}),r.jsx(Rt,{children:"Cancel loop"})]})}),r.jsx(xr,{children:r.jsxs(Ot,{children:[r.jsx(Ft,{asChild:!0,children:r.jsx(te,{variant:"ghost",size:"sm",onClick:()=>es(ce.id),children:r.jsx(ds,{className:"w-4 h-4 text-red-500"})})}),r.jsx(Rt,{children:"Delete loop"})]})})]})]})]}),r.jsxs("div",{className:"mt-3",children:[r.jsxs("div",{className:"flex justify-between text-xs text-muted-foreground mb-1",children:[r.jsx("span",{children:"Iterations"}),r.jsxs("span",{children:[(($e=ce.iterations)==null?void 0:$e.current)||0," / ",((Ve=ce.iterations)==null?void 0:Ve.max)||50]})]}),r.jsx("div",{className:"h-1.5 bg-muted rounded-full overflow-hidden",children:r.jsx("div",{className:"h-full bg-blue-500 transition-all",style:{width:`${_r(ce)}%`}})})]})]}),d===ce.id&&r.jsxs("div",{className:"border-t p-4 bg-muted/30 space-y-4",children:[r.jsxs("div",{className:"grid grid-cols-2 gap-4 text-sm",children:[r.jsxs("div",{children:[r.jsx("span",{className:"text-muted-foreground",children:"ID:"}),r.jsx("span",{className:"ml-2 font-mono",children:ce.id}),r.jsx(te,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 ml-1",onClick:()=>Tr(ce.id),children:r.jsx(Ml,{className:"w-3 h-3"})})]}),r.jsxs("div",{children:[r.jsx("span",{className:"text-muted-foreground",children:"Status:"}),r.jsxs("span",{className:"ml-2",children:[ce.status,ce.pauseReason?` (${ce.pauseReason})`:""]})]}),r.jsxs("div",{children:[r.jsx("span",{className:"text-muted-foreground",children:"Created:"}),r.jsx("span",{className:"ml-2",children:qr(ce.createdAt)})]}),r.jsxs("div",{children:[r.jsx("span",{className:"text-muted-foreground",children:"Updated:"}),r.jsx("span",{className:"ml-2",children:qr(ce.updatedAt)})]}),ce.workstreamId&&r.jsxs("div",{className:"col-span-2",children:[r.jsx("span",{className:"text-muted-foreground",children:"Workstream:"}),r.jsxs("span",{className:"ml-2 inline-flex items-center gap-1",children:[r.jsx(gn,{className:"w-3 h-3 text-purple-500"}),Zn(ce.workstreamId)]})]})]}),r.jsxs("div",{className:"bg-muted p-3 rounded-md",children:[r.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[r.jsx(Lt,{className:"w-4 h-4"}),r.jsx("span",{className:"text-sm font-medium",children:"Run this loop (uses official ralph-loop plugin):"})]}),r.jsx("code",{className:"text-xs bg-background p-2 rounded block whitespace-pre-wrap",children:Oi(ce)})]})]})]},ce.id)})}),r.jsx(bt,{open:_,onOpenChange:y,children:r.jsxs(xt,{className:"sm:max-w-lg",children:[r.jsx(vt,{children:r.jsx(yt,{children:"Create New Loop"})}),r.jsxs("div",{className:"space-y-4 py-4",children:[r.jsxs("div",{children:[r.jsx("label",{className:"text-sm font-medium mb-1 block",children:"Task Description"}),r.jsx(_t,{placeholder:"Describe what you want Claude to accomplish...",value:M,onChange:ce=>I(ce.target.value),rows:4}),r.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Be specific about the goal. The loop will continue until this task is completed."})]}),r.jsxs("div",{children:[r.jsx("label",{className:"text-sm font-medium mb-1 block",children:"Project"}),r.jsx("div",{className:"text-sm p-2 bg-muted rounded-md",children:e?r.jsx("span",{className:"font-mono",children:e.name||e.path||e.dir}):r.jsx("span",{className:"text-muted-foreground",children:"No project selected - loop will run in server directory"})})]}),r.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[r.jsxs("div",{children:[r.jsx("label",{className:"text-sm font-medium mb-1 block",children:"Max Iterations"}),r.jsx(dt,{type:"number",value:z,onChange:ce=>q(ce.target.value),min:1,max:1e3}),r.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Safety limit for the loop"})]}),r.jsxs("div",{children:[r.jsx("label",{className:"text-sm font-medium mb-1 block",children:"Completion Promise"}),r.jsx(dt,{value:H,onChange:ce=>G(ce.target.value),placeholder:"DONE"}),r.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Text that signals completion"})]})]}),f.length>0&&r.jsxs("div",{children:[r.jsx("label",{className:"text-sm font-medium mb-1 block",children:"Workstream (optional)"}),r.jsxs("select",{className:"w-full border rounded-md p-2 bg-background",value:O,onChange:ce=>B(ce.target.value),children:[r.jsx("option",{value:"",children:"No workstream"}),f.map(ce=>r.jsx("option",{value:ce.id,children:ce.name},ce.id))]})]})]}),r.jsxs(St,{children:[r.jsx(te,{variant:"outline",onClick:()=>y(!1),children:"Cancel"}),r.jsxs(te,{onClick:tr,disabled:Q||!M.trim(),children:[Q?r.jsx(Ze,{className:"w-4 h-4 animate-spin mr-1"}):null,"Create Loop"]})]})]})}),r.jsx(bt,{open:b,onOpenChange:g,children:r.jsxs(xt,{className:"sm:max-w-md",children:[r.jsx(vt,{children:r.jsx(yt,{children:"Loop Configuration"})}),r.jsxs("div",{className:"space-y-4 py-4",children:[r.jsxs("div",{children:[r.jsx("label",{className:"text-sm font-medium mb-1 block",children:"Max Iterations"}),r.jsx(dt,{type:"number",value:F,onChange:ce=>R(ce.target.value),min:1,max:1e3}),r.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Loop will pause after this many iterations"})]}),r.jsxs("div",{children:[r.jsx("label",{className:"text-sm font-medium mb-1 block",children:"Default Completion Promise"}),r.jsx(dt,{value:$,onChange:ce=>ne(ce.target.value),placeholder:"DONE"}),r.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Default text that signals loop completion (used with official ralph-loop plugin)"})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("input",{type:"checkbox",id:"autoApprovePlan",checked:L,onChange:ce=>U(ce.target.checked),className:"rounded"}),r.jsx("label",{htmlFor:"autoApprovePlan",className:"text-sm",children:"Auto-approve plans (skip manual plan approval)"})]})]}),r.jsxs(St,{children:[r.jsx(te,{variant:"outline",onClick:()=>g(!1),children:"Cancel"}),r.jsxs(te,{onClick:rr,disabled:Q,children:[Q?r.jsx(Ze,{className:"w-4 h-4 animate-spin mr-1"}):null,"Save"]})]})]})}),r.jsx(bt,{open:v,onOpenChange:k,children:r.jsxs(xt,{className:"sm:max-w-2xl max-h-[80vh] overflow-y-auto",children:[r.jsx(vt,{children:r.jsx(yt,{children:"Loop History"})}),r.jsx("div",{className:"space-y-3 py-4",children:fe.length===0?r.jsx("p",{className:"text-center text-muted-foreground py-8",children:"No completed loops yet"}):fe.slice().reverse().map(ce=>r.jsxs("div",{className:"border rounded-lg p-3",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[Yo[ce.status]||Yo.completed,r.jsx("span",{className:"font-medium",children:ce.name})]}),r.jsx("span",{className:"text-xs text-muted-foreground",children:qr(ce.completedAt)})]}),r.jsx("p",{className:"text-sm text-muted-foreground mt-1 truncate",children:ce.task}),r.jsx("div",{className:"mt-2 text-xs text-muted-foreground",children:r.jsxs("span",{children:["Iterations: ",ce.totalIterations]})})]},ce.id))})]})}),r.jsx(bt,{open:E,onOpenChange:P,children:r.jsxs(xt,{className:"sm:max-w-3xl max-h-[80vh] overflow-y-auto",children:[r.jsx(vt,{children:r.jsx(yt,{children:(T==null?void 0:T.name)||"Loop Details"})}),T&&r.jsxs("div",{className:"space-y-4 py-4",children:[r.jsxs("div",{className:"grid grid-cols-3 gap-4 text-sm",children:[r.jsxs("div",{className:"border rounded p-3",children:[r.jsx("div",{className:"text-muted-foreground text-xs mb-1",children:"Phase"}),r.jsx("span",{className:`text-sm px-2 py-0.5 rounded-full ${e_[T.phase]||""}`,children:T.phase})]}),r.jsxs("div",{className:"border rounded p-3",children:[r.jsx("div",{className:"text-muted-foreground text-xs mb-1",children:"Status"}),r.jsxs("div",{className:"flex items-center gap-1",children:[Yo[T.status],r.jsx("span",{children:T.status})]})]}),r.jsxs("div",{className:"border rounded p-3",children:[r.jsx("div",{className:"text-muted-foreground text-xs mb-1",children:"Progress"}),r.jsxs("span",{children:[((Fi=T.iterations)==null?void 0:Fi.current)||0," / ",((Ts=T.iterations)==null?void 0:Ts.max)||50]})]})]}),r.jsxs("div",{children:[r.jsx("h4",{className:"text-sm font-medium mb-2",children:"Task"}),r.jsx("div",{className:"bg-muted p-3 rounded text-sm",children:(Bi=T.task)==null?void 0:Bi.original})]}),T.clarifications&&r.jsxs("div",{children:[r.jsx("h4",{className:"text-sm font-medium mb-2",children:"Clarifications"}),r.jsx("div",{className:"bg-muted p-3 rounded text-sm whitespace-pre-wrap max-h-40 overflow-y-auto",children:T.clarifications})]}),T.plan&&r.jsxs("div",{children:[r.jsx("h4",{className:"text-sm font-medium mb-2",children:"Plan"}),r.jsx("div",{className:"bg-muted p-3 rounded text-sm whitespace-pre-wrap max-h-60 overflow-y-auto font-mono",children:T.plan})]}),r.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[r.jsxs("div",{children:[r.jsx("h4",{className:"text-sm font-medium mb-2",children:"Max Iterations"}),r.jsx("div",{className:"bg-muted p-2 rounded text-sm",children:((ei=T.iterations)==null?void 0:ei.max)||50})]}),r.jsxs("div",{children:[r.jsx("h4",{className:"text-sm font-medium mb-2",children:"Completion Promise"}),r.jsxs("div",{className:"bg-muted p-2 rounded text-sm font-mono",children:["<promise>",T.completionPromise||"DONE","</promise>"]})]})]}),r.jsxs("div",{children:[r.jsx("h4",{className:"text-sm font-medium mb-2",children:"Run Command (uses official ralph-loop plugin)"}),r.jsx("code",{className:"text-xs bg-muted p-3 rounded block whitespace-pre-wrap",children:Oi(T)})]})]})]})}),r.jsx(bt,{open:Se,onOpenChange:Be,children:r.jsxs(xt,{className:"sm:max-w-md",children:[r.jsx(vt,{children:r.jsxs(yt,{className:"flex items-center gap-2",children:[r.jsx(Kn,{className:"w-5 h-5"}),"Install ralph-loop Plugin"]})}),r.jsxs("div",{className:"py-4",children:[r.jsxs("p",{className:"text-sm text-muted-foreground mb-4",children:["The ",r.jsx("code",{className:"bg-muted px-1 rounded",children:"ralph-loop"})," plugin is required to run loops. This plugin provides the ",r.jsx("code",{className:"bg-muted px-1 rounded",children:"/ralph-loop"})," command that enables autonomous iteration."]}),Z.scope==="project"&&r.jsx("div",{className:"bg-yellow-50 dark:bg-yellow-900/20 border border-yellow-200 dark:border-yellow-800 rounded p-3 mb-4",children:r.jsxs("p",{className:"text-sm text-yellow-800 dark:text-yellow-200",children:["Plugin is currently installed only for project: ",r.jsx("br",{}),r.jsx("code",{className:"text-xs",children:Z.projectPath})]})}),r.jsx("p",{className:"text-sm",children:"Install the plugin globally (user scope) to use loops from any project?"})]}),r.jsxs(St,{children:[r.jsx(te,{variant:"outline",onClick:ms,disabled:Ye,children:"Cancel"}),r.jsx(te,{onClick:fs,disabled:Ye,children:Ye?r.jsxs(r.Fragment,{children:[r.jsx(Ze,{className:"w-4 h-4 animate-spin mr-1"}),"Installing..."]}):r.jsxs(r.Fragment,{children:[r.jsx(Kn,{className:"w-4 h-4 mr-1"}),"Install Plugin"]})})]})]})}),r.jsx(bj,{open:je,onOpenChange:ce=>{ye(ce),ce||(_e(null),Vt())},title:Ne?`Loop: ${Ne.name}`:"Running Loop",description:(ti=Ne==null?void 0:Ne.task)==null?void 0:ti.original,cwd:Ne==null?void 0:Ne.projectPath,initialCommand:Ne?Oi(Ne):"",env:Ne?{CODER_LOOP_ID:Ne.id,...Ne.workstreamId&&{CODER_WORKSTREAM:Ne.workstreamId}}:{},onExit:cn,headerExtra:r.jsxs("label",{className:"flex items-center gap-2 text-sm cursor-pointer select-none",children:[r.jsx("input",{type:"checkbox",checked:Ee,onChange:ce=>ie(ce.target.checked),className:"rounded"}),"Auto-close when done"]})}),r.jsx(bt,{open:ze,onOpenChange:Fe,children:r.jsxs(xt,{className:"sm:max-w-md",children:[r.jsx(vt,{children:r.jsxs(yt,{className:"flex items-center gap-2",children:[(de==null?void 0:de.status)==="completed"&&r.jsxs(r.Fragment,{children:[r.jsx(ao,{className:"w-5 h-5 text-green-600"})," Loop Completed"]}),(de==null?void 0:de.status)==="paused"&&r.jsxs(r.Fragment,{children:[r.jsx(Zm,{className:"w-5 h-5 text-yellow-500"})," Loop Paused"]}),(de==null?void 0:de.status)==="failed"&&r.jsxs(r.Fragment,{children:[r.jsx(sa,{className:"w-5 h-5 text-red-500"})," Loop Failed"]}),(de==null?void 0:de.status)==="cancelled"&&r.jsxs(r.Fragment,{children:[r.jsx(sa,{className:"w-5 h-5 text-gray-500"})," Loop Cancelled"]})]})}),de&&r.jsxs("div",{className:"space-y-4 py-4",children:[r.jsxs("div",{children:[r.jsx("h4",{className:"text-sm font-medium mb-1",children:"Task"}),r.jsx("p",{className:"text-sm text-muted-foreground bg-muted p-2 rounded",children:de.task})]}),de.pauseReason&&r.jsxs("div",{children:[r.jsx("h4",{className:"text-sm font-medium mb-1",children:"Reason"}),r.jsx("p",{className:"text-sm text-muted-foreground bg-muted p-2 rounded",children:de.pauseReason})]}),r.jsxs("div",{className:"grid grid-cols-3 gap-3 text-sm",children:[r.jsxs("div",{className:"border rounded p-3",children:[r.jsx("div",{className:"text-muted-foreground text-xs mb-1",children:"Status"}),r.jsxs("div",{className:"font-medium flex items-center gap-1",children:[Yo[de.status],r.jsx("span",{className:"capitalize",children:de.status})]})]}),r.jsxs("div",{className:"border rounded p-3",children:[r.jsx("div",{className:"text-muted-foreground text-xs mb-1",children:"Iterations"}),r.jsxs("div",{className:"font-medium",children:[de.iterations," / ",de.maxIterations]})]}),r.jsxs("div",{className:"border rounded p-3",children:[r.jsx("div",{className:"text-muted-foreground text-xs mb-1",children:"Duration"}),r.jsx("div",{className:"font-medium",children:de.duration!=null?de.duration<60?`${de.duration}s`:de.duration<3600?`${Math.floor(de.duration/60)}m ${de.duration%60}s`:`${Math.floor(de.duration/3600)}h ${Math.floor(de.duration%3600/60)}m`:"-"})]})]}),r.jsxs("div",{className:"text-xs text-muted-foreground",children:[de.status==="completed"?"Completed":"Stopped"," at ",qr(de.completedAt)]})]}),r.jsxs(St,{children:[r.jsx(te,{variant:"outline",onClick:()=>Fe(!1),children:"Close"}),(de==null?void 0:de.status)==="paused"&&r.jsxs(te,{onClick:()=>{Fe(!1);const ce=t.find(X=>X.name===de.name);ce&&Mt(ce.id)},children:[r.jsx(sm,{className:"w-4 h-4 mr-1"}),"Resume"]}),r.jsx(te,{variant:"secondary",onClick:()=>{if(Fe(!1),de){const ce=t.find(X=>X.name===de.name);ce&&sr(ce)}},children:"View Details"})]})]})})]})}function YH(e,t=[]){let s=[];function n(d,u){const l=C.createContext(u);l.displayName=d+"Context";const c=s.length;s=[...s,u];const f=h=>{var b;const{scope:x,children:w,...j}=h,_=((b=x==null?void 0:x[e])==null?void 0:b[c])||l,y=C.useMemo(()=>j,Object.values(j));return r.jsx(_.Provider,{value:y,children:w})};f.displayName=d+"Provider";function m(h,x){var _;const w=((_=x==null?void 0:x[e])==null?void 0:_[c])||l,j=C.useContext(w);if(j)return j;if(u!==void 0)return u;throw new Error(`\`${h}\` must be used within \`${d}\``)}return[f,m]}const o=()=>{const d=s.map(u=>C.createContext(u));return function(l){const c=(l==null?void 0:l[e])||d;return C.useMemo(()=>({[`__scope${e}`]:{...l,[e]:c}}),[l,c])}};return o.scopeName=e,[n,XH(o,...t)]}function XH(...e){const t=e[0];if(e.length===1)return t;const s=()=>{const n=e.map(o=>({useScope:o(),scopeName:o.scopeName}));return function(d){const u=n.reduce((l,{useScope:c,scopeName:f})=>{const h=c(d)[`__scope${f}`];return{...l,...h}},{});return C.useMemo(()=>({[`__scope${t.scopeName}`]:u}),[u])}};return s.scopeName=t.scopeName,s}var JH=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],t2=JH.reduce((e,t)=>{const s=_u(`Primitive.${t}`),n=C.forwardRef((o,d)=>{const{asChild:u,...l}=o,c=u?s:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),r.jsx(c,{...l,ref:d})});return n.displayName=`Primitive.${t}`,{...e,[t]:n}},{}),_x="Progress",Cx=100,[QH]=YH(_x),[ZH,eW]=QH(_x),r2=C.forwardRef((e,t)=>{const{__scopeProgress:s,value:n=null,max:o,getValueLabel:d=tW,...u}=e;(o||o===0)&&!t_(o)&&console.error(rW(`${o}`,"Progress"));const l=t_(o)?o:Cx;n!==null&&!r_(n,l)&&console.error(sW(`${n}`,"Progress"));const c=r_(n,l)?n:null,f=fu(c)?d(c,l):void 0;return r.jsx(ZH,{scope:s,value:c,max:l,children:r.jsx(t2.div,{"aria-valuemax":l,"aria-valuemin":0,"aria-valuenow":fu(c)?c:void 0,"aria-valuetext":f,role:"progressbar","data-state":i2(c,l),"data-value":c??void 0,"data-max":l,...u,ref:t})})});r2.displayName=_x;var s2="ProgressIndicator",n2=C.forwardRef((e,t)=>{const{__scopeProgress:s,...n}=e,o=eW(s2,s);return r.jsx(t2.div,{"data-state":i2(o.value,o.max),"data-value":o.value??void 0,"data-max":o.max,...n,ref:t})});n2.displayName=s2;function tW(e,t){return`${Math.round(e/t*100)}%`}function i2(e,t){return e==null?"indeterminate":e===t?"complete":"loading"}function fu(e){return typeof e=="number"}function t_(e){return fu(e)&&!isNaN(e)&&e>0}function r_(e,t){return fu(e)&&!isNaN(e)&&e<=t&&e>=0}function rW(e,t){return`Invalid prop \`max\` of value \`${e}\` supplied to \`${t}\`. Only numbers greater than 0 are valid max values. Defaulting to \`${Cx}\`.`}function sW(e,t){return`Invalid prop \`value\` of value \`${e}\` supplied to \`${t}\`. The \`value\` prop must be:
2983
2983
  - a positive number
2984
2984
  - less than the value passed to \`max\` (or ${Cx} if no \`max\` prop is set)
2985
2985
  - \`null\` or \`undefined\` if the progress is indeterminate.
@@ -19,7 +19,7 @@
19
19
 
20
20
  <!-- PWA Manifest -->
21
21
  <link rel="manifest" href="/manifest.json">
22
- <script type="module" crossorigin src="/assets/index-BuO1jFRz.js"></script>
22
+ <script type="module" crossorigin src="/assets/index-DKnr0y8P.js"></script>
23
23
  <link rel="stylesheet" crossorigin href="/assets/index-DAbOgCcu.css">
24
24
  </head>
25
25
  <body>
@@ -241,37 +241,55 @@ function recordIteration(manager, id, iteration) {
241
241
  }
242
242
 
243
243
  /**
244
- * Check if loop hooks are installed (official ralph-loop plugin)
244
+ * Check if loop hooks are installed and registered in Claude Code settings
245
245
  */
246
246
  function getLoopHookStatus() {
247
- // Check for official ralph-loop plugin
248
- const pluginsDir = path.join(os.homedir(), '.claude', 'plugins', 'marketplaces');
249
- const officialPluginPath = path.join(pluginsDir, 'claude-plugins-official', 'plugins', 'ralph-loop');
250
- const stopHookPath = path.join(officialPluginPath, 'hooks', 'stop-hook.sh');
251
-
252
- // Also check custom hooks dir for backwards compatibility
253
- const customHooksDir = path.join(os.homedir(), '.claude', 'hooks');
254
- const customStopHookPath = path.join(customHooksDir, 'ralph-loop-stop.sh');
255
- const customPrepromptHookPath = path.join(customHooksDir, 'ralph-loop-preprompt.sh');
247
+ const claudeSettingsPath = path.join(os.homedir(), '.claude', 'settings.json');
248
+ const claudeHooksDir = path.join(os.homedir(), '.claude', 'hooks');
249
+ const stopHookPath = path.join(claudeHooksDir, 'ralph-loop-stop.sh');
250
+ const prepromptHookPath = path.join(claudeHooksDir, 'ralph-loop-preprompt.sh');
251
+
252
+ // Check if hook files exist
253
+ const stopHookFileExists = fs.existsSync(stopHookPath);
254
+ const prepromptHookFileExists = fs.existsSync(prepromptHookPath);
255
+
256
+ // Check if hooks are registered in settings.json
257
+ let stopHookRegistered = false;
258
+ let prepromptHookRegistered = false;
259
+
260
+ if (fs.existsSync(claudeSettingsPath)) {
261
+ try {
262
+ const settings = JSON.parse(fs.readFileSync(claudeSettingsPath, 'utf8'));
263
+ const hooks = settings.hooks || {};
264
+
265
+ // Check Stop hook registration
266
+ if (hooks.Stop) {
267
+ stopHookRegistered = hooks.Stop.some(entry =>
268
+ entry.hooks?.some(h => h.command?.includes('ralph-loop-stop.sh'))
269
+ );
270
+ }
256
271
 
257
- const officialPluginExists = fs.existsSync(officialPluginPath);
258
- const officialHookExists = fs.existsSync(stopHookPath);
272
+ // Check PreToolUse hook registration
273
+ if (hooks.PreToolUse) {
274
+ prepromptHookRegistered = hooks.PreToolUse.some(entry =>
275
+ entry.hooks?.some(h => h.command?.includes('ralph-loop-preprompt.sh'))
276
+ );
277
+ }
278
+ } catch (e) {
279
+ // Ignore parse errors
280
+ }
281
+ }
259
282
 
260
283
  const status = {
261
- // Official plugin is preferred
262
- usingOfficialPlugin: officialPluginExists,
263
- officialPlugin: {
264
- path: officialPluginPath,
265
- exists: officialPluginExists
266
- },
267
284
  stopHook: {
268
- path: officialHookExists ? stopHookPath : customStopHookPath,
269
- exists: officialHookExists || fs.existsSync(customStopHookPath)
285
+ path: stopHookPath,
286
+ exists: stopHookFileExists,
287
+ registered: stopHookRegistered
270
288
  },
271
289
  prepromptHook: {
272
- // Official plugin doesn't need preprompt hook
273
- path: customPrepromptHookPath,
274
- exists: officialPluginExists || fs.existsSync(customPrepromptHookPath)
290
+ path: prepromptHookPath,
291
+ exists: prepromptHookFileExists,
292
+ registered: prepromptHookRegistered
275
293
  }
276
294
  };
277
295
 
@@ -419,32 +437,105 @@ function fixRalphLoopPluginStructure() {
419
437
  }
420
438
 
421
439
  /**
422
- * Install loop hooks (or verify official plugin is installed)
440
+ * Install loop hooks into Claude Code's settings.json
441
+ * Registers Stop hook that increments iteration count after each response
423
442
  */
424
443
  function installLoopHooks(manager) {
425
- const pluginsDir = path.join(os.homedir(), '.claude', 'plugins', 'marketplaces');
426
- const officialPluginPath = path.join(pluginsDir, 'claude-plugins-official', 'plugins', 'ralph-loop');
444
+ const claudeSettingsPath = path.join(os.homedir(), '.claude', 'settings.json');
445
+ const claudeHooksDir = path.join(os.homedir(), '.claude', 'hooks');
446
+
447
+ // Ensure hooks directory exists
448
+ if (!fs.existsSync(claudeHooksDir)) {
449
+ fs.mkdirSync(claudeHooksDir, { recursive: true });
450
+ }
451
+
452
+ // Copy the stop hook script to ~/.claude/hooks/
453
+ const stopHookSource = path.join(__dirname, '..', '..', 'hooks', 'ralph-loop-stop.sh');
454
+ const stopHookDest = path.join(claudeHooksDir, 'ralph-loop-stop.sh');
455
+
456
+ // Also copy preprompt hook
457
+ const prepromptHookSource = path.join(__dirname, '..', '..', 'hooks', 'ralph-loop-preprompt.sh');
458
+ const prepromptHookDest = path.join(claudeHooksDir, 'ralph-loop-preprompt.sh');
459
+
460
+ try {
461
+ // Copy hook scripts
462
+ if (fs.existsSync(stopHookSource)) {
463
+ fs.copyFileSync(stopHookSource, stopHookDest);
464
+ fs.chmodSync(stopHookDest, '755');
465
+ }
466
+ if (fs.existsSync(prepromptHookSource)) {
467
+ fs.copyFileSync(prepromptHookSource, prepromptHookDest);
468
+ fs.chmodSync(prepromptHookDest, '755');
469
+ }
470
+
471
+ // Load existing settings
472
+ let settings = {};
473
+ if (fs.existsSync(claudeSettingsPath)) {
474
+ settings = JSON.parse(fs.readFileSync(claudeSettingsPath, 'utf8'));
475
+ }
476
+
477
+ // Initialize hooks if needed
478
+ if (!settings.hooks) {
479
+ settings.hooks = {};
480
+ }
481
+
482
+ // Add Stop hook for iteration tracking
483
+ const stopHookEntry = {
484
+ hooks: [{
485
+ type: 'command',
486
+ command: stopHookDest
487
+ }]
488
+ };
489
+
490
+ // Check if Stop hook already exists
491
+ if (!settings.hooks.Stop) {
492
+ settings.hooks.Stop = [stopHookEntry];
493
+ } else {
494
+ // Check if our hook is already registered
495
+ const hookExists = settings.hooks.Stop.some(entry =>
496
+ entry.hooks?.some(h => h.command?.includes('ralph-loop-stop.sh'))
497
+ );
498
+ if (!hookExists) {
499
+ settings.hooks.Stop.push(stopHookEntry);
500
+ }
501
+ }
502
+
503
+ // Add PreToolUse hook for context injection (optional)
504
+ const prepromptHookEntry = {
505
+ hooks: [{
506
+ type: 'command',
507
+ command: prepromptHookDest
508
+ }]
509
+ };
510
+
511
+ if (!settings.hooks.PreToolUse) {
512
+ settings.hooks.PreToolUse = [prepromptHookEntry];
513
+ } else {
514
+ const hookExists = settings.hooks.PreToolUse.some(entry =>
515
+ entry.hooks?.some(h => h.command?.includes('ralph-loop-preprompt.sh'))
516
+ );
517
+ if (!hookExists) {
518
+ settings.hooks.PreToolUse.push(prepromptHookEntry);
519
+ }
520
+ }
521
+
522
+ // Save updated settings
523
+ fs.writeFileSync(claudeSettingsPath, JSON.stringify(settings, null, 2) + '\n');
427
524
 
428
- // Check if official plugin is already installed
429
- if (fs.existsSync(officialPluginPath)) {
430
525
  return {
431
526
  success: true,
432
- message: 'Official ralph-loop plugin is already installed',
433
- usingOfficialPlugin: true,
434
- pluginPath: officialPluginPath,
435
- note: 'Loops use the /ralph-loop command from the official claude-plugins-official marketplace'
527
+ message: 'Loop hooks installed successfully',
528
+ stopHook: stopHookDest,
529
+ prepromptHook: prepromptHookDest,
530
+ note: 'Stop hook will increment iteration count after each Claude response when CODER_LOOP_ID is set'
531
+ };
532
+ } catch (error) {
533
+ return {
534
+ success: false,
535
+ error: error.message,
536
+ suggestion: 'Try manually copying hooks to ~/.claude/hooks/ and adding to ~/.claude/settings.json'
436
537
  };
437
538
  }
438
-
439
- // Suggest installing the official plugin
440
- return {
441
- success: false,
442
- error: 'Official ralph-loop plugin not found',
443
- suggestion: 'Install the claude-plugins-official marketplace to get the ralph-loop plugin:\n' +
444
- ' 1. Add marketplace: coder-config marketplace add https://github.com/anthropics/claude-plugins-official\n' +
445
- ' 2. Or manually clone: git clone https://github.com/anthropics/claude-plugins-official ~/.claude/plugins/marketplaces/claude-plugins-official',
446
- note: 'The official plugin provides /ralph-loop command with stop-hook for autonomous loops'
447
- };
448
539
  }
449
540
 
450
541
  module.exports = {