coder-config 0.44.27 → 0.44.28

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.27';
5
+ const VERSION = '0.44.28';
6
6
 
7
7
  // Tool-specific path configurations
8
8
  const TOOL_PATHS = {
package/lib/loops.js CHANGED
@@ -392,7 +392,8 @@ function loopStart(installDir, idOrName) {
392
392
 
393
393
  // Output run instructions (using official ralph-loop plugin)
394
394
  const task = state.task.original.replace(/"/g, '\\"');
395
- const completionPromise = state.completionPromise || 'DONE';
395
+ // Escape single quotes in completion promise (replace ' with '\'' for shell)
396
+ const completionPromise = (state.completionPromise || 'DONE').replace(/'/g, "'\\''");
396
397
  console.log('\nTo run this loop with Claude Code (uses official ralph-loop plugin):');
397
398
  console.log(` claude --dangerously-skip-permissions "/ralph-loop ${task} --max-iterations ${state.iterations.max} --completion-promise '${completionPromise}'"`);
398
399
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "coder-config",
3
- "version": "0.44.27",
3
+ "version": "0.44.28",
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)},Fr=Z=>{T(je=>je.filter(Le=>Le!==Z))},dr=Z=>{P.includes(Z)||T(je=>[...je,Z])},wr=async Z=>{const je=B[Z];if(!je&&!Y[Z]){J(Le=>({...Le,[Z]:!0}));try{const Le=await pe.getSubprojects(Z);H(Ve=>({...Ve,[Z]:Le.subprojects||[]}))}catch(Le){console.error("Failed to load subprojects:",Le),H(Ve=>({...Ve,[Z]:[]}))}finally{J(Le=>({...Le,[Z]:!1}))}}z(Le=>({...Le,[Z]:!je}))},yn=Z=>{const je=Z.projects.sort().join("|"),Le=[...W,je];ce(Le),localStorage.setItem("dismissedWorkstreamSuggestions",JSON.stringify(Le)),he(Ve=>Ve.filter(jt=>jt.projects.sort().join("|")!==je)),q.success("Suggestion dismissed")},qr=se.filter(Z=>{const je=Z.projects.sort().join("|");return!W.includes(je)}),fs=async()=>{if(confirm("Clear activity data older than 30 days?"))try{const Z=await pe.clearActivity(30);Z.success&&(q.success(`Cleared ${Z.cleared} old entries`),Kr())}catch(Z){q.error("Failed to clear activity: "+Z.message)}},bn=async(Z,je)=>{if(!Z||Z.length===0){q.error("Add projects first to generate rules");return}Q(!0);try{const Le=await pe.generateWorkstreamRules(Z,ae);Le.success&&Le.rules?(je(Le.rules),q.success(ae?"Generated rules with Claude":"Generated rules from repos")):q.error(Le.error||"Failed to generate rules")}catch(Le){q.error("Failed to generate rules: "+Le.message)}finally{Q(!1)}},rt=async()=>{O(!0);try{const Z=await pe.installWorkstreamHook();Z.success?(q.success(Z.message),F(je=>({...je,isInstalled:!0}))):q.error(Z.error||"Failed to install hook")}catch(Z){q.error("Failed to install hook: "+Z.message)}finally{O(!1)}},Bt=async()=>{Ee(!0);try{const Z=await pe.installCdHook();Z.success?(q.success("CD hook installed. Restart your shell to activate."),we(je=>({...je,installed:!0}))):q.error(Z.error||"Failed to install CD hook")}catch(Z){q.error("Failed to install CD hook: "+Z.message)}finally{Ee(!1)}},Ht=async()=>{Ee(!0);try{const Z=await pe.uninstallCdHook();Z.success?(q.success("CD hook uninstalled. Restart your shell to apply."),we(je=>({...je,installed:!1}))):q.error(Z.error||"Failed to uninstall CD hook")}catch(Z){q.error("Failed to uninstall CD hook: "+Z.message)}finally{Ee(!1)}},pr=async()=>{const Z=!be.workstreamAutoActivate;try{await pe.setGlobalAutoActivate(Z),Oe(je=>({...je,workstreamAutoActivate:Z})),q.success(`Auto-activation ${Z?"enabled":"disabled"}`)}catch(je){q.error("Failed to update setting: "+je.message)}},Br=async(Z,je)=>{try{(await pe.setWorkstreamAutoActivate(Z.id,je)).success&&(n(Ve=>Ve.map(jt=>jt.id===Z.id?{...jt,autoActivate:je==="default"?void 0:je==="on"}:jt)),q.success(`Auto-activate ${je} for ${Z.name}`))}catch(Le){q.error("Failed to update: "+Le.message)}},Wt=async()=>{if(!(!Pe||!He.trim()))try{const Z=await pe.addTriggerFolder(Pe.id,He.trim());Z.success&&(n(je=>je.map(Le=>Le.id===Pe.id?Z.workstream:Le)),q.success("Trigger folder added"),xe(!1),St(""),ze(null))}catch(Z){q.error("Failed to add trigger folder: "+Z.message)}},rr=async(Z,je)=>{try{const Le=await pe.removeTriggerFolder(Z.id,je);Le.success&&(n(Ve=>Ve.map(jt=>jt.id===Z.id?Le.workstream:jt)),q.success("Trigger folder removed"))}catch(Le){q.error("Failed to remove trigger folder: "+Le.message)}},as=async()=>{try{d(!0);const Z=await pe.getWorkstreams();n(Z.workstreams||[])}catch{q.error("Failed to load workstreams")}finally{d(!1)}},Yt=async()=>{if(!g.trim()){q.error("Name is required");return}M(!0);try{const Z=await pe.createWorkstream(g.trim(),P,k);Z.success?(n(je=>[...je,Z.workstream]),q.success(`Created workstream: ${g}`),f(!1),v(""),E(""),T([]),he(je=>je.filter(Le=>Le.name!==g.trim()))):q.error(Z.error||"Failed to create workstream")}catch(Z){q.error("Failed to create workstream: "+Z.message)}finally{M(!1)}},_t=async Z=>{if(confirm(`Delete workstream "${Z.name}"?
2981
2981
 
2982
- This cannot be undone.`))try{const je=await pe.deleteWorkstream(Z.id);je.success?(n(Le=>Le.filter(Ve=>Ve.id!==Z.id)),q.success(`Deleted workstream: ${Z.name}`)):q.error(je.error||"Failed to delete workstream")}catch(je){q.error("Failed to delete workstream: "+je.message)}},Yr=async()=>{if(m){M(!0);try{const Z=await pe.updateWorkstream(m.id,{name:m.name,rules:m.rules,projects:m.projects||[]});Z.success?(n(je=>je.map(Le=>Le.id===m.id?Z.workstream:Le)),q.success("Workstream updated"),h(null)):q.error(Z.error||"Failed to update workstream")}catch(Z){q.error("Failed to update workstream: "+Z.message)}finally{M(!1)}}},gr=Z=>{Be(Z.id),ye(Z.rules||"")},Un=()=>{Be(null),ye("")},et=async Z=>{Xe(!0);try{const je=await pe.updateWorkstream(Z.id,{name:Z.name,rules:de,projects:Z.projects||[]});je.success?(n(Le=>Le.map(Ve=>Ve.id===Z.id?je.workstream:Ve)),q.success("Rules updated"),Be(null),ye("")):q.error(je.error||"Failed to update rules")}catch(je){q.error("Failed to update rules: "+je.message)}finally{Xe(!1)}},Po=Z=>{b(je=>{const Le=new Set(je);return Le.has(Z)?Le.delete(Z):Le.add(Z),Le})},Ga=async()=>{if(!j||y.size===0)return;M(!0);let Z=0,je=null;for(const Le of y)try{const Ve=await pe.addProjectToWorkstream(j.id,Le);Ve.success&&(je=Ve.workstream,Z++)}catch(Ve){console.error("Failed to add project:",Le,Ve)}je&&n(Le=>Le.map(Ve=>Ve.id===j.id?je:Ve)),Z>0?q.success(`Added ${Z} project${Z>1?"s":""} to ${j.name}`):q.error("Failed to add projects"),M(!1),w(!1),C(null),b(new Set)},wn=async(Z,je)=>{try{const Le=await pe.removeProjectFromWorkstream(Z.id,je);Le.success?(n(Ve=>Ve.map(jt=>jt.id===Z.id?Le.workstream:jt)),q.success(`Removed project from ${Z.name}`)):q.error(Le.error||"Failed to remove project")}catch(Le){q.error("Failed to remove project: "+Le.message)}},ms=Z=>Z.split("/").pop()||Z,Ao=Z=>s.filter(je=>{var Le;return(Le=je.projects)==null?void 0:Le.includes(Z)}).length,sn=(Z,je=null)=>{var jt,Nt;const Le=Ao(Z),Ve=je?(Nt=(jt=s.find(xr=>xr.id===je))==null?void 0:jt.projects)==null?void 0:Nt.includes(Z):!1;return Le===0?null:Le===1?Ve?null:"in use":"shared"};return o?r.jsx("div",{className:"flex items-center justify-center h-64",children:r.jsx(Qe,{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(Pn,{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(re,{variant:"outline",onClick:as,size:"sm",children:[r.jsx(Ar,{className:"w-4 h-4 mr-2"}),"Refresh"]}),r.jsxs(re,{onClick:()=>f(!0),className:"bg-purple-600 hover:bg-purple-700",children:[r.jsx(Tt,{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(Pn,{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(re,{onClick:()=>f(!0),children:[r.jsx(Tt,{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(Z=>{var je,Le,Ve,jt;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===Z.id?null:Z.id),children:[r.jsx("div",{className:"w-5 h-5 flex items-center justify-center text-gray-400",children:u===Z.id?r.jsx(Nr,{className:"w-4 h-4"}):r.jsx(us,{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(Pn,{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:Z.name}),((je=Z.projects)==null?void 0:je.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:[Z.projects.length," project",Z.projects.length!==1?"s":""]}),Z.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(Lr,{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:((Le=Z.projects)==null?void 0:Le.length)>0?Z.projects.map(Nt=>ms(Nt)).join(", "):"No projects added"})]}),r.jsxs("div",{className:"flex items-center gap-2",onClick:Nt=>Nt.stopPropagation(),children:[r.jsx(re,{size:"sm",variant:"ghost",onClick:()=>h({...Z}),className:"text-gray-500 dark:text-slate-400 hover:text-purple-600 dark:hover:text-purple-400",title:"Edit workstream",children:r.jsx(wm,{className:"w-4 h-4"})}),r.jsx(re,{size:"sm",variant:"ghost",onClick:()=>_t(Z),className:"text-gray-500 dark:text-slate-400 hover:text-red-600 dark:hover:text-red-400",title:"Delete workstream",children:r.jsx(Ss,{className:"w-4 h-4"})})]})]}),u===Z.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(re,{size:"sm",variant:"outline",onClick:()=>{C(Z),w(!0)},children:[r.jsx(ti,{className:"w-4 h-4 mr-1"}),"Add Project"]})]}),((Ve=Z.projects)==null?void 0:Ve.length)>0?r.jsx("div",{className:"space-y-1",children:Z.projects.map(Nt=>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:Nt.replace(/^\/Users\/[^/]+/,"~")}),r.jsx(re,{size:"sm",variant:"ghost",onClick:()=>wn(Z,Nt),className:"text-gray-400 hover:text-red-500 h-6 w-6 p-0",children:r.jsx(Nb,{className:"w-4 h-4"})})]},Nt))}):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(or,{children:r.jsxs(It,{children:[r.jsx(Lt,{asChild:!0,children:r.jsx(ya,{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(re,{size:"sm",variant:"outline",onClick:()=>{ze(Z),xe(!0)},children:[r.jsx(ti,{className:"w-4 h-4 mr-1"}),"Add Folder"]})]}),((jt=Z.triggerFolders)==null?void 0:jt.length)>0?r.jsx("div",{className:"space-y-1",children:Z.triggerFolders.map(Nt=>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:Nt.replace(/^\/Users\/[^/]+/,"~")}),r.jsx(re,{size:"sm",variant:"ghost",onClick:()=>rr(Z,Nt),className:"text-gray-400 hover:text-red-500 h-6 w-6 p-0",children:r.jsx(Nb,{className:"w-4 h-4"})})]},Nt))}):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(mo,{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(di,{children:[r.jsx(ui,{asChild:!0,children:r.jsxs(re,{variant:"outline",size:"sm",children:[Z.autoActivate===!0?"On":Z.autoActivate===!1?"Off":"Default",r.jsx(Nr,{className:"w-3 h-3 ml-1"})]})}),r.jsxs(Bn,{align:"end",children:[r.jsxs(Ft,{onClick:()=>Br(Z,"on"),children:[r.jsx(Ot,{className:`w-4 h-4 mr-2 ${Z.autoActivate===!0?"opacity-100":"opacity-0"}`}),"On"]}),r.jsxs(Ft,{onClick:()=>Br(Z,"off"),children:[r.jsx(Ot,{className:`w-4 h-4 mr-2 ${Z.autoActivate===!1?"opacity-100":"opacity-0"}`}),"Off"]}),r.jsxs(Ft,{onClick:()=>Br(Z,"default"),children:[r.jsx(Ot,{className:`w-4 h-4 mr-2 ${Z.autoActivate===void 0?"opacity-100":"opacity-0"}`}),"Default (",be.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"}),$e===Z.id?r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsxs(re,{size:"sm",variant:"ghost",onClick:Un,disabled:Ze,className:"text-gray-500 dark:text-slate-400 h-7",children:[r.jsx(ri,{className:"w-4 h-4 mr-1"}),"Cancel"]}),r.jsxs(re,{size:"sm",onClick:()=>et(Z),disabled:Ze,className:"bg-purple-600 hover:bg-purple-700 h-7",children:[Ze?r.jsx(Qe,{className:"w-4 h-4 animate-spin mr-1"}):r.jsx(zs,{className:"w-4 h-4 mr-1"}),"Save"]})]}):r.jsxs(re,{size:"sm",variant:"ghost",onClick:()=>gr(Z),className:"text-gray-500 dark:text-slate-400 hover:text-purple-600 dark:hover:text-purple-400 h-7",children:[r.jsx(wm,{className:"w-4 h-4 mr-1"}),"Edit"]})]}),$e===Z.id?r.jsx(Ct,{value:de,onChange:Nt=>ye(Nt.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}):Z.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:()=>gr(Z),title:"Click to edit",children:Z.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:()=>gr(Z),children:"No rules defined. Click to add context rules for this workstream."})]})]})]},Z.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(or,{children:r.jsxs(It,{children:[r.jsx(Lt,{asChild:!0,children:r.jsx("button",{className:"text-gray-400 hover:text-gray-600 dark:hover:text-slate-300",children:r.jsx(ya,{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(xo,{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(Os,{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(re,{onClick:rt,disabled:R||K.loading,size:"sm",className:"bg-amber-600 hover:bg-amber-700 text-white",children:[R?r.jsx(Qe,{className:"w-4 h-4 animate-spin mr-2"}):r.jsx(ai,{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(or,{children:r.jsxs(It,{children:[r.jsx(Lt,{asChild:!0,children:r.jsx(ya,{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(mo,{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(re,{variant:be.workstreamAutoActivate?"default":"outline",size:"sm",onClick:pr,children:be.workstreamAutoActivate?"Enabled":"Disabled"})]}),dt.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(xo,{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: ",dt.shell," • RC file: ",r.jsx("code",{className:"bg-green-100 dark:bg-green-900/50 px-1 rounded",children:(_r=dt.rcFile)==null?void 0:_r.replace(/^\/Users\/[^/]+/,"~")})]}),r.jsxs(re,{variant:"outline",size:"sm",className:"mt-2",onClick:Ht,disabled:Se,children:[Se?r.jsx(Qe,{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(Os,{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(re,{variant:"default",size:"sm",onClick:Bt,disabled:Se||dt.loading,className:"bg-amber-600 hover:bg-amber-700 text-white",children:[Se?r.jsx(Qe,{className:"w-4 h-4 animate-spin mr-2"}):r.jsx(ai,{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(re,{variant:"ghost",size:"sm",onClick:fs,className:"text-gray-500 dark:text-slate-400 hover:text-red-500",children:[r.jsx(Ss,{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(KC,{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(Lr,{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(Pn,{className:"w-3 h-3"}),"Projects Active"]}),r.jsx("div",{className:"text-2xl font-semibold text-gray-900 dark:text-white",children:U.projectCount})]})]}),((fi=U.topProjects)==null?void 0:fi.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((Z,je)=>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:Z.path,children:Z.path.split("/").pop()}),r.jsxs("span",{className:"text-gray-400 dark:text-slate-500 text-xs",children:[Z.fileCount," files"]})]},Z.path))})]})]}),qr.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(Kt,{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:qr.map(Z=>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(mo,{className:"w-4 h-4 text-amber-500"}),r.jsx("span",{className:"font-medium text-gray-900 dark:text-white",children:Z.name}),Z.coActivityScore&&r.jsxs("span",{className:"text-xs text-gray-500 dark:text-slate-400",children:[Z.coActivityScore,"% co-activity"]})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(re,{size:"sm",variant:"ghost",onClick:()=>yn(Z),className:"text-gray-400 hover:text-gray-600 dark:hover:text-slate-300",title:"Dismiss suggestion",children:r.jsx(ri,{className:"w-4 h-4"})}),r.jsxs(re,{size:"sm",onClick:()=>Zt(Z),className:"bg-indigo-600 hover:bg-indigo-700",children:[r.jsx(Tt,{className:"w-4 h-4 mr-1"}),"Create"]})]})]}),r.jsx("div",{className:"flex flex-wrap gap-1",children:Z.projects.map(je=>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:je.split("/").pop()},je))})]},Z.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:Z=>{Z||(f(!1),v(""),E(""),T([]),L(!1),z({}))},children:r.jsxs(gt,{className:"max-w-lg max-h-[85vh] overflow-y-auto",children:[r.jsx(xt,{children:r.jsxs(vt,{className:"flex items-center gap-2",children:[r.jsx(Pn,{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(ct,{value:g,onChange:Z=>v(Z.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(re,{type:"button",size:"sm",variant:"outline",onClick:()=>L(!I),children:[r.jsx(ti,{className:"w-4 h-4 mr-1"}),"Add"]})]}),P.length>0?r.jsx("div",{className:"space-y-1 mb-2",children:P.map(Z=>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:Z.replace(/^\/Users\/[^/]+/,"~")}),r.jsx(re,{type:"button",size:"sm",variant:"ghost",onClick:()=>Fr(Z),className:"text-gray-400 hover:text-red-500 h-6 w-6 p-0",children:r.jsx(ri,{className:"w-4 h-4"})})]},Z))}):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(Z=>{const je=sn(Z.path),Le=B[Z.path],Ve=G[Z.path],jt=Y[Z.path]||[],Nt=P.includes(Z.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:()=>wr(Z.path),className:"p-1 hover:bg-gray-100 dark:hover:bg-slate-800 rounded",title:"Show sub-projects",children:Ve?r.jsx(Qe,{className:"w-4 h-4 animate-spin text-gray-400"}):Le?r.jsx(Nr,{className:"w-4 h-4 text-gray-400"}):r.jsx(us,{className:"w-4 h-4 text-gray-400"})}),r.jsxs("button",{type:"button",onClick:()=>dr(Z.path),disabled:Nt,className:`flex-1 text-left p-2 rounded transition-colors ${Nt?"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:Z.name}),r.jsxs("div",{className:"flex items-center gap-1",children:[je&&r.jsx("span",{className:`text-xs px-1.5 py-0.5 rounded ${je==="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:je}),Nt&&r.jsx(Ot,{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:Z.path.replace(/^\/Users\/[^/]+/,"~")})]})]}),Le&&jt.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:jt.map(xr=>{const sr=P.includes(xr.dir),vr=sn(xr.dir);return r.jsxs("button",{type:"button",onClick:()=>dr(xr.dir),disabled:sr,className:`w-full text-left p-2 rounded transition-colors ${sr?"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:xr.name}),r.jsxs("div",{className:"flex items-center gap-1",children:[vr&&r.jsx("span",{className:`text-xs px-1.5 py-0.5 rounded ${vr==="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:vr}),sr&&r.jsx(Ot,{className:"w-4 h-4 text-purple-600"})]})]}),r.jsx("div",{className:"text-xs text-gray-500 dark:text-slate-400 font-mono",children:xr.relativePath})]},xr.dir)})}),Le&&jt.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"})]},Z.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(wo,{checked:ae,onCheckedChange:Ce,className:"h-3.5 w-3.5"}),"Use Claude"]}),r.jsxs(re,{type:"button",size:"sm",variant:"ghost",onClick:()=>bn(P,E),disabled:ne||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:ae?"Use Claude Code to analyze repos":"Extract from README, package.json, etc.",children:[ne?r.jsx(Qe,{className:"w-3 h-3 animate-spin mr-1"}):r.jsx(ns,{className:"w-3 h-3 mr-1"}),"Generate"]})]})]}),r.jsx(Ct,{value:k,onChange:Z=>E(Z.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(kt,{children:[r.jsx(re,{variant:"outline",onClick:()=>{f(!1),v(""),E(""),T([]),L(!1),z({})},children:"Cancel"}),r.jsxs(re,{onClick:Yt,disabled:N||!g.trim(),className:"bg-purple-600 hover:bg-purple-700",children:[N?r.jsx(Qe,{className:"w-4 h-4 animate-spin mr-2"}):r.jsx(Tt,{className:"w-4 h-4 mr-2"}),"Create"]})]})]})}),r.jsx(bt,{open:!!m,onOpenChange:Z=>!Z&&h(null),children:r.jsxs(gt,{className:"max-w-lg max-h-[85vh] overflow-y-auto",children:[r.jsx(xt,{children:r.jsxs(vt,{className:"flex items-center gap-2",children:[r.jsx(wm,{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(ct,{value:m.name,onChange:Z=>h(je=>({...je,name:Z.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(re,{type:"button",size:"sm",variant:"outline",onClick:()=>h(Z=>({...Z,showPicker:!Z.showPicker})),children:[r.jsx(ti,{className:"w-4 h-4 mr-1"}),"Add"]})]}),((mi=m.projects)==null?void 0:mi.length)>0?r.jsx("div",{className:"space-y-1 mb-2",children:m.projects.map(Z=>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:Z.replace(/^\/Users\/[^/]+/,"~")}),r.jsx(re,{type:"button",size:"sm",variant:"ghost",onClick:()=>h(je=>({...je,projects:je.projects.filter(Le=>Le!==Z)})),className:"text-gray-400 hover:text-red-500 h-6 w-6 p-0",children:r.jsx(ri,{className:"w-4 h-4"})})]},Z))}):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(Z=>{var xr;const je=(xr=m.projects)==null?void 0:xr.includes(Z.path),Le=sn(Z.path,m.id),Ve=B[Z.path],jt=G[Z.path],Nt=Y[Z.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:()=>wr(Z.path),className:"p-1 hover:bg-gray-100 dark:hover:bg-slate-800 rounded",title:"Show sub-projects",children:jt?r.jsx(Qe,{className:"w-4 h-4 animate-spin text-gray-400"}):Ve?r.jsx(Nr,{className:"w-4 h-4 text-gray-400"}):r.jsx(us,{className:"w-4 h-4 text-gray-400"})}),r.jsxs("button",{type:"button",onClick:()=>!je&&h(sr=>({...sr,projects:[...sr.projects||[],Z.path]})),disabled:je,className:`flex-1 text-left p-2 rounded transition-colors ${je?"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:Z.name}),r.jsxs("div",{className:"flex items-center gap-1",children:[Le&&r.jsx("span",{className:`text-xs px-1.5 py-0.5 rounded ${Le==="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:Le}),je&&r.jsx(Ot,{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:Z.path.replace(/^\/Users\/[^/]+/,"~")})]})]}),Ve&&Nt.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:Nt.map(sr=>{var Ns;const vr=(Ns=m.projects)==null?void 0:Ns.includes(sr.dir),Xr=sn(sr.dir,m.id);return r.jsxs("button",{type:"button",onClick:()=>!vr&&h(Cr=>({...Cr,projects:[...Cr.projects||[],sr.dir]})),disabled:vr,className:`w-full text-left p-2 rounded transition-colors ${vr?"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:sr.name}),r.jsxs("div",{className:"flex items-center gap-1",children:[Xr&&r.jsx("span",{className:`text-xs px-1.5 py-0.5 rounded ${Xr==="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:Xr}),vr&&r.jsx(Ot,{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:sr.relativePath})]},sr.dir)})}),Ve&&Nt.length===0&&!jt&&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"})]},Z.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(wo,{checked:ae,onCheckedChange:Ce,className:"h-3.5 w-3.5"}),"Use Claude"]}),r.jsxs(re,{type:"button",size:"sm",variant:"ghost",onClick:()=>bn(m.projects,Z=>h(je=>({...je,rules:Z}))),disabled:ne||!((Gi=m.projects)!=null&&Gi.length),className:"text-xs h-7 text-purple-600 hover:text-purple-700 hover:bg-purple-50 dark:hover:bg-purple-950/30",title:ae?"Use Claude Code to analyze repos":"Extract from README, package.json, etc.",children:[ne?r.jsx(Qe,{className:"w-3 h-3 animate-spin mr-1"}):r.jsx(ns,{className:"w-3 h-3 mr-1"}),"Generate"]})]})]}),r.jsx(Ct,{value:m.rules||"",onChange:Z=>h(je=>({...je,rules:Z.target.value})),placeholder:"Context rules for this workstream...",rows:8})]})]}),r.jsxs(kt,{children:[r.jsx(re,{variant:"outline",onClick:()=>h(null),children:"Cancel"}),r.jsxs(re,{onClick:Yr,disabled:N,className:"bg-purple-600 hover:bg-purple-700",children:[N?r.jsx(Qe,{className:"w-4 h-4 animate-spin mr-2"}):r.jsx(zs,{className:"w-4 h-4 mr-2"}),"Save Changes"]})]})]})}),r.jsx(bt,{open:x,onOpenChange:Z=>{w(Z),Z||(z({}),b(new Set))},children:r.jsxs(gt,{className:"max-w-lg",children:[r.jsx(xt,{children:r.jsxs(vt,{className:"flex items-center gap-2",children:[r.jsx(ti,{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(Z=>{var sr;const je=(sr=j==null?void 0:j.projects)==null?void 0:sr.includes(Z.path),Le=y.has(Z.path),Ve=sn(Z.path,j==null?void 0:j.id),jt=B[Z.path],Nt=G[Z.path],xr=Y[Z.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:()=>wr(Z.path),className:"p-1 hover:bg-gray-100 dark:hover:bg-slate-800 rounded",title:"Show sub-projects",children:Nt?r.jsx(Qe,{className:"w-4 h-4 animate-spin text-gray-400"}):jt?r.jsx(Nr,{className:"w-4 h-4 text-gray-400"}):r.jsx(us,{className:"w-4 h-4 text-gray-400"})}),r.jsxs("button",{type:"button",onClick:()=>!je&&Po(Z.path),disabled:je,className:`flex-1 text-left p-2 rounded transition-colors ${je?"bg-gray-100 dark:bg-slate-800 opacity-50 cursor-not-allowed":Le?"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 ${je?"bg-gray-300 dark:bg-slate-600 border-gray-300 dark:border-slate-600":Le?"bg-purple-600 border-purple-600":"border-gray-300 dark:border-slate-600"}`,children:(je||Le)&&r.jsx(Ot,{className:"w-3 h-3 text-white"})}),r.jsx("span",{className:"font-medium text-gray-900 dark:text-white",children:Z.name})]}),r.jsxs("div",{className:"flex items-center gap-1",children:[Ve&&r.jsx("span",{className:`text-xs px-1.5 py-0.5 rounded ${Ve==="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:Ve}),je&&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:Z.path.replace(/^\/Users\/[^/]+/,"~")})]})]}),jt&&xr.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:xr.map(vr=>{var To;const Xr=(To=j==null?void 0:j.projects)==null?void 0:To.includes(vr.dir),Ns=y.has(vr.dir),Cr=sn(vr.dir,j==null?void 0:j.id);return r.jsxs("button",{type:"button",onClick:()=>!Xr&&Po(vr.dir),disabled:Xr,className:`w-full text-left p-2 rounded transition-colors ${Xr?"bg-gray-100 dark:bg-slate-800 opacity-50 cursor-not-allowed":Ns?"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 ${Xr?"bg-gray-300 dark:bg-slate-600 border-gray-300 dark:border-slate-600":Ns?"bg-purple-600 border-purple-600":"border-gray-300 dark:border-slate-600"}`,children:(Xr||Ns)&&r.jsx(Ot,{className:"w-3 h-3 text-white"})}),r.jsx("span",{className:"text-gray-700 dark:text-slate-300",children:vr.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}),Xr&&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:vr.relativePath})]},vr.dir)})}),jt&&xr.length===0&&!Nt&&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"})]},Z.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(kt,{children:[r.jsx(re,{variant:"outline",onClick:()=>{w(!1),b(new Set)},children:"Cancel"}),r.jsxs(re,{onClick:Ga,disabled:y.size===0||N,className:"bg-purple-600 hover:bg-purple-700",children:[N?r.jsx(Qe,{className:"w-4 h-4 animate-spin mr-2"}):r.jsx(Tt,{className:"w-4 h-4 mr-2"}),"Add Selected (",y.size,")"]})]})]})}),r.jsx(bt,{open:oe,onOpenChange:Z=>{Z||(xe(!1),St(""),ze(null))},children:r.jsxs(gt,{children:[r.jsx(xt,{children:r.jsx(vt,{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:Pe==null?void 0:Pe.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(ct,{value:He,onChange:Z=>St(Z.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(kt,{children:[r.jsx(re,{variant:"outline",onClick:()=>{xe(!1),St(""),ze(null)},children:"Cancel"}),r.jsxs(re,{onClick:Wt,disabled:!He.trim(),className:"bg-purple-600 hover:bg-purple-700",children:[r.jsx(ti,{className:"w-4 h-4 mr-2"}),"Add Folder"]})]})]})})]})}const l_={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"},ha={pending:r.jsx(ql,{className:"w-4 h-4 text-gray-500"}),running:r.jsx(ZC,{className:"w-4 h-4 text-green-500"}),paused:r.jsx(xp,{className:"w-4 h-4 text-yellow-500"}),completed:r.jsx(xo,{className:"w-4 h-4 text-green-600"}),failed:r.jsx(ba,{className:"w-4 h-4 text-red-500"}),cancelled:r.jsx(ba,{className:"w-4 h-4 text-gray-500"})};function qH({activeProject:e=null}){var Lo,Za,el,tl,Oo,qi,nn,on;const[t,s]=_.useState([]),[n,o]=_.useState(!0),[d,u]=_.useState(null),[l,c]=_.useState({}),[f,m]=_.useState([]),[h,x]=_.useState(null),[w,j]=_.useState(""),[C,y]=_.useState(!1),[b,g]=_.useState(!1),[v,k]=_.useState(!1),[E,P]=_.useState(!1),[T,N]=_.useState(null),[M,I]=_.useState(!1),[L,B]=_.useState(null),[z,Y]=_.useState(""),[H,G]=_.useState(""),[J,K]=_.useState(50),[F,R]=_.useState("DONE"),[O,U]=_.useState(!1),[$,se]=_.useState(!1),[he,fe]=_.useState(!1),[X,W]=_.useState(""),[ce,ne]=_.useState(""),[Q,ae]=_.useState(!1),[Ce,$e]=_.useState(!1),[Be,de]=_.useState(null),[ye,Ze]=_.useState("create"),[Xe,dt]=_.useState(""),[we,be]=_.useState(""),[Oe,Se]=_.useState(50),[Ee,oe]=_.useState("DONE"),[xe,Pe]=_.useState(""),[ze,He]=_.useState(50),[St,ut]=_.useState(!1),[cr,os]=_.useState("DONE"),[Kr,Zt]=_.useState([]),[Fr,dr]=_.useState({stopHook:{},prepromptHook:{}}),[wr,yn]=_.useState(!1),[qr,fs]=_.useState({needsInstall:!0}),[bn,rt]=_.useState(!1),[Bt,Ht]=_.useState(null),[pr,Br]=_.useState(null),[Wt,rr]=_.useState(!1),[as,Yt]=_.useState(!1),[_t,Yr]=_.useState(null),[gr,Un]=_.useState(!0),[et,Po]=_.useState(null),[Ga,wn]=_.useState(!1);_.useEffect(()=>{_r(),fi(),mi(),sn(),Ao()},[]);const ms=_.useRef(null);_.useEffect(()=>{if(!as||!_t){ms.current=null;return}ms.current=_t.status;const te=setInterval(async()=>{var Ie,$t,zt;try{const ht=(await pe.getLoop(_t.id)).loop,Jr=ms.current!==ht.status,Hs=["completed","paused","failed","cancelled"].includes(ht.status);if(Jr&&Hs){clearInterval(te);const Vn={id:ht.id,name:ht.name,task:(Ie=ht.task)==null?void 0:Ie.original,status:ht.status,pauseReason:ht.pauseReason,iterations:(($t=ht.iterations)==null?void 0:$t.current)||0,maxIterations:((zt=ht.iterations)==null?void 0:zt.max)||50,phase:ht.phase,startedAt:ht.startedAt,completedAt:ht.completedAt||new Date().toISOString(),duration:ht.startedAt?Math.round((Date.now()-new Date(ht.startedAt).getTime())/1e3):null};Po(Vn),ht.status==="completed"?q.success("Loop completed successfully!"):ht.status==="paused"?q.info(`Loop paused: ${ht.pauseReason||"unknown reason"}`):ht.status==="failed"?q.error("Loop failed"):ht.status==="cancelled"&&q.warning("Loop cancelled"),_r(),gr&&ht.status==="completed"?setTimeout(()=>{Yt(!1),Yr(null),wn(!0)},1500):wn(!0)}ms.current=ht.status}catch($r){console.error("Failed to poll loop status:",$r)}},3e3);return()=>clearInterval(te)},[as,_t,gr]);const Ao=async()=>{try{const te=await pe.getRalphLoopPluginStatus();fs(te)}catch(te){console.error("Failed to load plugin status:",te)}},sn=async()=>{try{const te=await pe.getWorkstreams();m(te.workstreams||[]),x(te.activeId||null)}catch(te){console.error("Failed to load workstreams:",te)}};_.useEffect(()=>{C&&h&&G(h)},[C,h]);const _r=async()=>{try{o(!0);const te=await pe.getLoops();s(te.loops||[]),c(te.config||{})}catch{q.error("Failed to load loops")}finally{o(!1)}},fi=async()=>{try{const Ie=(await pe.getLoopConfig()).config||{};c(Ie),He(Ie.maxIterations||50),ut(Ie.autoApprovePlan||!1),os(Ie.completionPromise||"DONE"),K(Ie.maxIterations||50),R(Ie.completionPromise||"DONE")}catch(te){console.error("Failed to load config:",te)}},mi=async()=>{try{const te=await pe.getLoopHookStatus();dr(te)}catch(te){console.error("Failed to load hook status:",te)}},Gi=async()=>{try{const te=await pe.getLoopHistory();Zt(te.completed||[])}catch{q.error("Failed to load history")}},Z=async()=>{if(!z.trim()){q.error("Task description is required");return}await sr(z)},je=async()=>{if(!z.trim()){q.error("Enter a task description first");return}try{se(!0),ne(z),Ze("create");const te=await pe.tuneLoopPrompt(z,(e==null?void 0:e.path)||(e==null?void 0:e.dir)||null);te.success?(W(te.tunedPrompt),fe(!0)):q.error(te.error||"Failed to tune prompt")}catch(te){q.error(te.message)}finally{se(!1)}},Le=()=>{ye==="edit"?be(X):(Y(X),ae(!0)),fe(!1),q.success("Tuned prompt applied")},Ve=()=>{fe(!1)},jt=te=>{te.status==="failed"||te.status==="paused"?(de(te),$e(!0)):Ic(te.id)},Nt=async()=>{var te,Ie,$t,zt;if(Be)try{se(!0);const $r=((te=Be.task)==null?void 0:te.original)||"",ht=await pe.getLoop(Be.id),Jr=ht.loop||Be,Hs={status:Jr.status,pauseReason:Jr.pauseReason,iterations:((Ie=Jr.iterations)==null?void 0:Ie.current)||0,maxIterations:(($t=Jr.iterations)==null?void 0:$t.max)||50,phase:Jr.phase,clarifications:ht.clarifications||"",plan:ht.plan||"",iterationHistory:(((zt=Jr.iterations)==null?void 0:zt.history)||[]).slice(-5).map(rl=>`Iteration ${rl.n}: ${rl.summary||"no summary"}`).join(`
2982
+ This cannot be undone.`))try{const je=await pe.deleteWorkstream(Z.id);je.success?(n(Le=>Le.filter(Ve=>Ve.id!==Z.id)),q.success(`Deleted workstream: ${Z.name}`)):q.error(je.error||"Failed to delete workstream")}catch(je){q.error("Failed to delete workstream: "+je.message)}},Yr=async()=>{if(m){M(!0);try{const Z=await pe.updateWorkstream(m.id,{name:m.name,rules:m.rules,projects:m.projects||[]});Z.success?(n(je=>je.map(Le=>Le.id===m.id?Z.workstream:Le)),q.success("Workstream updated"),h(null)):q.error(Z.error||"Failed to update workstream")}catch(Z){q.error("Failed to update workstream: "+Z.message)}finally{M(!1)}}},gr=Z=>{Be(Z.id),ye(Z.rules||"")},Un=()=>{Be(null),ye("")},et=async Z=>{Xe(!0);try{const je=await pe.updateWorkstream(Z.id,{name:Z.name,rules:de,projects:Z.projects||[]});je.success?(n(Le=>Le.map(Ve=>Ve.id===Z.id?je.workstream:Ve)),q.success("Rules updated"),Be(null),ye("")):q.error(je.error||"Failed to update rules")}catch(je){q.error("Failed to update rules: "+je.message)}finally{Xe(!1)}},Po=Z=>{b(je=>{const Le=new Set(je);return Le.has(Z)?Le.delete(Z):Le.add(Z),Le})},Ga=async()=>{if(!j||y.size===0)return;M(!0);let Z=0,je=null;for(const Le of y)try{const Ve=await pe.addProjectToWorkstream(j.id,Le);Ve.success&&(je=Ve.workstream,Z++)}catch(Ve){console.error("Failed to add project:",Le,Ve)}je&&n(Le=>Le.map(Ve=>Ve.id===j.id?je:Ve)),Z>0?q.success(`Added ${Z} project${Z>1?"s":""} to ${j.name}`):q.error("Failed to add projects"),M(!1),w(!1),C(null),b(new Set)},wn=async(Z,je)=>{try{const Le=await pe.removeProjectFromWorkstream(Z.id,je);Le.success?(n(Ve=>Ve.map(jt=>jt.id===Z.id?Le.workstream:jt)),q.success(`Removed project from ${Z.name}`)):q.error(Le.error||"Failed to remove project")}catch(Le){q.error("Failed to remove project: "+Le.message)}},ms=Z=>Z.split("/").pop()||Z,Ao=Z=>s.filter(je=>{var Le;return(Le=je.projects)==null?void 0:Le.includes(Z)}).length,sn=(Z,je=null)=>{var jt,Nt;const Le=Ao(Z),Ve=je?(Nt=(jt=s.find(xr=>xr.id===je))==null?void 0:jt.projects)==null?void 0:Nt.includes(Z):!1;return Le===0?null:Le===1?Ve?null:"in use":"shared"};return o?r.jsx("div",{className:"flex items-center justify-center h-64",children:r.jsx(Qe,{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(Pn,{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(re,{variant:"outline",onClick:as,size:"sm",children:[r.jsx(Ar,{className:"w-4 h-4 mr-2"}),"Refresh"]}),r.jsxs(re,{onClick:()=>f(!0),className:"bg-purple-600 hover:bg-purple-700",children:[r.jsx(Tt,{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(Pn,{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(re,{onClick:()=>f(!0),children:[r.jsx(Tt,{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(Z=>{var je,Le,Ve,jt;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===Z.id?null:Z.id),children:[r.jsx("div",{className:"w-5 h-5 flex items-center justify-center text-gray-400",children:u===Z.id?r.jsx(Nr,{className:"w-4 h-4"}):r.jsx(us,{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(Pn,{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:Z.name}),((je=Z.projects)==null?void 0:je.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:[Z.projects.length," project",Z.projects.length!==1?"s":""]}),Z.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(Lr,{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:((Le=Z.projects)==null?void 0:Le.length)>0?Z.projects.map(Nt=>ms(Nt)).join(", "):"No projects added"})]}),r.jsxs("div",{className:"flex items-center gap-2",onClick:Nt=>Nt.stopPropagation(),children:[r.jsx(re,{size:"sm",variant:"ghost",onClick:()=>h({...Z}),className:"text-gray-500 dark:text-slate-400 hover:text-purple-600 dark:hover:text-purple-400",title:"Edit workstream",children:r.jsx(wm,{className:"w-4 h-4"})}),r.jsx(re,{size:"sm",variant:"ghost",onClick:()=>_t(Z),className:"text-gray-500 dark:text-slate-400 hover:text-red-600 dark:hover:text-red-400",title:"Delete workstream",children:r.jsx(Ss,{className:"w-4 h-4"})})]})]}),u===Z.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(re,{size:"sm",variant:"outline",onClick:()=>{C(Z),w(!0)},children:[r.jsx(ti,{className:"w-4 h-4 mr-1"}),"Add Project"]})]}),((Ve=Z.projects)==null?void 0:Ve.length)>0?r.jsx("div",{className:"space-y-1",children:Z.projects.map(Nt=>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:Nt.replace(/^\/Users\/[^/]+/,"~")}),r.jsx(re,{size:"sm",variant:"ghost",onClick:()=>wn(Z,Nt),className:"text-gray-400 hover:text-red-500 h-6 w-6 p-0",children:r.jsx(Nb,{className:"w-4 h-4"})})]},Nt))}):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(or,{children:r.jsxs(It,{children:[r.jsx(Lt,{asChild:!0,children:r.jsx(ya,{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(re,{size:"sm",variant:"outline",onClick:()=>{ze(Z),xe(!0)},children:[r.jsx(ti,{className:"w-4 h-4 mr-1"}),"Add Folder"]})]}),((jt=Z.triggerFolders)==null?void 0:jt.length)>0?r.jsx("div",{className:"space-y-1",children:Z.triggerFolders.map(Nt=>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:Nt.replace(/^\/Users\/[^/]+/,"~")}),r.jsx(re,{size:"sm",variant:"ghost",onClick:()=>rr(Z,Nt),className:"text-gray-400 hover:text-red-500 h-6 w-6 p-0",children:r.jsx(Nb,{className:"w-4 h-4"})})]},Nt))}):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(mo,{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(di,{children:[r.jsx(ui,{asChild:!0,children:r.jsxs(re,{variant:"outline",size:"sm",children:[Z.autoActivate===!0?"On":Z.autoActivate===!1?"Off":"Default",r.jsx(Nr,{className:"w-3 h-3 ml-1"})]})}),r.jsxs(Bn,{align:"end",children:[r.jsxs(Ft,{onClick:()=>Br(Z,"on"),children:[r.jsx(Ot,{className:`w-4 h-4 mr-2 ${Z.autoActivate===!0?"opacity-100":"opacity-0"}`}),"On"]}),r.jsxs(Ft,{onClick:()=>Br(Z,"off"),children:[r.jsx(Ot,{className:`w-4 h-4 mr-2 ${Z.autoActivate===!1?"opacity-100":"opacity-0"}`}),"Off"]}),r.jsxs(Ft,{onClick:()=>Br(Z,"default"),children:[r.jsx(Ot,{className:`w-4 h-4 mr-2 ${Z.autoActivate===void 0?"opacity-100":"opacity-0"}`}),"Default (",be.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"}),$e===Z.id?r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsxs(re,{size:"sm",variant:"ghost",onClick:Un,disabled:Ze,className:"text-gray-500 dark:text-slate-400 h-7",children:[r.jsx(ri,{className:"w-4 h-4 mr-1"}),"Cancel"]}),r.jsxs(re,{size:"sm",onClick:()=>et(Z),disabled:Ze,className:"bg-purple-600 hover:bg-purple-700 h-7",children:[Ze?r.jsx(Qe,{className:"w-4 h-4 animate-spin mr-1"}):r.jsx(zs,{className:"w-4 h-4 mr-1"}),"Save"]})]}):r.jsxs(re,{size:"sm",variant:"ghost",onClick:()=>gr(Z),className:"text-gray-500 dark:text-slate-400 hover:text-purple-600 dark:hover:text-purple-400 h-7",children:[r.jsx(wm,{className:"w-4 h-4 mr-1"}),"Edit"]})]}),$e===Z.id?r.jsx(Ct,{value:de,onChange:Nt=>ye(Nt.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}):Z.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:()=>gr(Z),title:"Click to edit",children:Z.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:()=>gr(Z),children:"No rules defined. Click to add context rules for this workstream."})]})]})]},Z.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(or,{children:r.jsxs(It,{children:[r.jsx(Lt,{asChild:!0,children:r.jsx("button",{className:"text-gray-400 hover:text-gray-600 dark:hover:text-slate-300",children:r.jsx(ya,{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(xo,{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(Os,{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(re,{onClick:rt,disabled:R||K.loading,size:"sm",className:"bg-amber-600 hover:bg-amber-700 text-white",children:[R?r.jsx(Qe,{className:"w-4 h-4 animate-spin mr-2"}):r.jsx(ai,{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(or,{children:r.jsxs(It,{children:[r.jsx(Lt,{asChild:!0,children:r.jsx(ya,{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(mo,{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(re,{variant:be.workstreamAutoActivate?"default":"outline",size:"sm",onClick:pr,children:be.workstreamAutoActivate?"Enabled":"Disabled"})]}),dt.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(xo,{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: ",dt.shell," • RC file: ",r.jsx("code",{className:"bg-green-100 dark:bg-green-900/50 px-1 rounded",children:(_r=dt.rcFile)==null?void 0:_r.replace(/^\/Users\/[^/]+/,"~")})]}),r.jsxs(re,{variant:"outline",size:"sm",className:"mt-2",onClick:Ht,disabled:Se,children:[Se?r.jsx(Qe,{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(Os,{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(re,{variant:"default",size:"sm",onClick:Bt,disabled:Se||dt.loading,className:"bg-amber-600 hover:bg-amber-700 text-white",children:[Se?r.jsx(Qe,{className:"w-4 h-4 animate-spin mr-2"}):r.jsx(ai,{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(re,{variant:"ghost",size:"sm",onClick:fs,className:"text-gray-500 dark:text-slate-400 hover:text-red-500",children:[r.jsx(Ss,{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(KC,{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(Lr,{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(Pn,{className:"w-3 h-3"}),"Projects Active"]}),r.jsx("div",{className:"text-2xl font-semibold text-gray-900 dark:text-white",children:U.projectCount})]})]}),((fi=U.topProjects)==null?void 0:fi.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((Z,je)=>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:Z.path,children:Z.path.split("/").pop()}),r.jsxs("span",{className:"text-gray-400 dark:text-slate-500 text-xs",children:[Z.fileCount," files"]})]},Z.path))})]})]}),qr.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(Kt,{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:qr.map(Z=>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(mo,{className:"w-4 h-4 text-amber-500"}),r.jsx("span",{className:"font-medium text-gray-900 dark:text-white",children:Z.name}),Z.coActivityScore&&r.jsxs("span",{className:"text-xs text-gray-500 dark:text-slate-400",children:[Z.coActivityScore,"% co-activity"]})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(re,{size:"sm",variant:"ghost",onClick:()=>yn(Z),className:"text-gray-400 hover:text-gray-600 dark:hover:text-slate-300",title:"Dismiss suggestion",children:r.jsx(ri,{className:"w-4 h-4"})}),r.jsxs(re,{size:"sm",onClick:()=>Zt(Z),className:"bg-indigo-600 hover:bg-indigo-700",children:[r.jsx(Tt,{className:"w-4 h-4 mr-1"}),"Create"]})]})]}),r.jsx("div",{className:"flex flex-wrap gap-1",children:Z.projects.map(je=>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:je.split("/").pop()},je))})]},Z.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:Z=>{Z||(f(!1),v(""),E(""),T([]),L(!1),z({}))},children:r.jsxs(gt,{className:"max-w-lg max-h-[85vh] overflow-y-auto",children:[r.jsx(xt,{children:r.jsxs(vt,{className:"flex items-center gap-2",children:[r.jsx(Pn,{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(ct,{value:g,onChange:Z=>v(Z.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(re,{type:"button",size:"sm",variant:"outline",onClick:()=>L(!I),children:[r.jsx(ti,{className:"w-4 h-4 mr-1"}),"Add"]})]}),P.length>0?r.jsx("div",{className:"space-y-1 mb-2",children:P.map(Z=>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:Z.replace(/^\/Users\/[^/]+/,"~")}),r.jsx(re,{type:"button",size:"sm",variant:"ghost",onClick:()=>Fr(Z),className:"text-gray-400 hover:text-red-500 h-6 w-6 p-0",children:r.jsx(ri,{className:"w-4 h-4"})})]},Z))}):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(Z=>{const je=sn(Z.path),Le=B[Z.path],Ve=G[Z.path],jt=Y[Z.path]||[],Nt=P.includes(Z.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:()=>wr(Z.path),className:"p-1 hover:bg-gray-100 dark:hover:bg-slate-800 rounded",title:"Show sub-projects",children:Ve?r.jsx(Qe,{className:"w-4 h-4 animate-spin text-gray-400"}):Le?r.jsx(Nr,{className:"w-4 h-4 text-gray-400"}):r.jsx(us,{className:"w-4 h-4 text-gray-400"})}),r.jsxs("button",{type:"button",onClick:()=>dr(Z.path),disabled:Nt,className:`flex-1 text-left p-2 rounded transition-colors ${Nt?"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:Z.name}),r.jsxs("div",{className:"flex items-center gap-1",children:[je&&r.jsx("span",{className:`text-xs px-1.5 py-0.5 rounded ${je==="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:je}),Nt&&r.jsx(Ot,{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:Z.path.replace(/^\/Users\/[^/]+/,"~")})]})]}),Le&&jt.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:jt.map(xr=>{const sr=P.includes(xr.dir),vr=sn(xr.dir);return r.jsxs("button",{type:"button",onClick:()=>dr(xr.dir),disabled:sr,className:`w-full text-left p-2 rounded transition-colors ${sr?"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:xr.name}),r.jsxs("div",{className:"flex items-center gap-1",children:[vr&&r.jsx("span",{className:`text-xs px-1.5 py-0.5 rounded ${vr==="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:vr}),sr&&r.jsx(Ot,{className:"w-4 h-4 text-purple-600"})]})]}),r.jsx("div",{className:"text-xs text-gray-500 dark:text-slate-400 font-mono",children:xr.relativePath})]},xr.dir)})}),Le&&jt.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"})]},Z.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(wo,{checked:ae,onCheckedChange:Ce,className:"h-3.5 w-3.5"}),"Use Claude"]}),r.jsxs(re,{type:"button",size:"sm",variant:"ghost",onClick:()=>bn(P,E),disabled:ne||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:ae?"Use Claude Code to analyze repos":"Extract from README, package.json, etc.",children:[ne?r.jsx(Qe,{className:"w-3 h-3 animate-spin mr-1"}):r.jsx(ns,{className:"w-3 h-3 mr-1"}),"Generate"]})]})]}),r.jsx(Ct,{value:k,onChange:Z=>E(Z.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(kt,{children:[r.jsx(re,{variant:"outline",onClick:()=>{f(!1),v(""),E(""),T([]),L(!1),z({})},children:"Cancel"}),r.jsxs(re,{onClick:Yt,disabled:N||!g.trim(),className:"bg-purple-600 hover:bg-purple-700",children:[N?r.jsx(Qe,{className:"w-4 h-4 animate-spin mr-2"}):r.jsx(Tt,{className:"w-4 h-4 mr-2"}),"Create"]})]})]})}),r.jsx(bt,{open:!!m,onOpenChange:Z=>!Z&&h(null),children:r.jsxs(gt,{className:"max-w-lg max-h-[85vh] overflow-y-auto",children:[r.jsx(xt,{children:r.jsxs(vt,{className:"flex items-center gap-2",children:[r.jsx(wm,{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(ct,{value:m.name,onChange:Z=>h(je=>({...je,name:Z.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(re,{type:"button",size:"sm",variant:"outline",onClick:()=>h(Z=>({...Z,showPicker:!Z.showPicker})),children:[r.jsx(ti,{className:"w-4 h-4 mr-1"}),"Add"]})]}),((mi=m.projects)==null?void 0:mi.length)>0?r.jsx("div",{className:"space-y-1 mb-2",children:m.projects.map(Z=>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:Z.replace(/^\/Users\/[^/]+/,"~")}),r.jsx(re,{type:"button",size:"sm",variant:"ghost",onClick:()=>h(je=>({...je,projects:je.projects.filter(Le=>Le!==Z)})),className:"text-gray-400 hover:text-red-500 h-6 w-6 p-0",children:r.jsx(ri,{className:"w-4 h-4"})})]},Z))}):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(Z=>{var xr;const je=(xr=m.projects)==null?void 0:xr.includes(Z.path),Le=sn(Z.path,m.id),Ve=B[Z.path],jt=G[Z.path],Nt=Y[Z.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:()=>wr(Z.path),className:"p-1 hover:bg-gray-100 dark:hover:bg-slate-800 rounded",title:"Show sub-projects",children:jt?r.jsx(Qe,{className:"w-4 h-4 animate-spin text-gray-400"}):Ve?r.jsx(Nr,{className:"w-4 h-4 text-gray-400"}):r.jsx(us,{className:"w-4 h-4 text-gray-400"})}),r.jsxs("button",{type:"button",onClick:()=>!je&&h(sr=>({...sr,projects:[...sr.projects||[],Z.path]})),disabled:je,className:`flex-1 text-left p-2 rounded transition-colors ${je?"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:Z.name}),r.jsxs("div",{className:"flex items-center gap-1",children:[Le&&r.jsx("span",{className:`text-xs px-1.5 py-0.5 rounded ${Le==="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:Le}),je&&r.jsx(Ot,{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:Z.path.replace(/^\/Users\/[^/]+/,"~")})]})]}),Ve&&Nt.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:Nt.map(sr=>{var Ns;const vr=(Ns=m.projects)==null?void 0:Ns.includes(sr.dir),Xr=sn(sr.dir,m.id);return r.jsxs("button",{type:"button",onClick:()=>!vr&&h(Cr=>({...Cr,projects:[...Cr.projects||[],sr.dir]})),disabled:vr,className:`w-full text-left p-2 rounded transition-colors ${vr?"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:sr.name}),r.jsxs("div",{className:"flex items-center gap-1",children:[Xr&&r.jsx("span",{className:`text-xs px-1.5 py-0.5 rounded ${Xr==="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:Xr}),vr&&r.jsx(Ot,{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:sr.relativePath})]},sr.dir)})}),Ve&&Nt.length===0&&!jt&&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"})]},Z.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(wo,{checked:ae,onCheckedChange:Ce,className:"h-3.5 w-3.5"}),"Use Claude"]}),r.jsxs(re,{type:"button",size:"sm",variant:"ghost",onClick:()=>bn(m.projects,Z=>h(je=>({...je,rules:Z}))),disabled:ne||!((Gi=m.projects)!=null&&Gi.length),className:"text-xs h-7 text-purple-600 hover:text-purple-700 hover:bg-purple-50 dark:hover:bg-purple-950/30",title:ae?"Use Claude Code to analyze repos":"Extract from README, package.json, etc.",children:[ne?r.jsx(Qe,{className:"w-3 h-3 animate-spin mr-1"}):r.jsx(ns,{className:"w-3 h-3 mr-1"}),"Generate"]})]})]}),r.jsx(Ct,{value:m.rules||"",onChange:Z=>h(je=>({...je,rules:Z.target.value})),placeholder:"Context rules for this workstream...",rows:8})]})]}),r.jsxs(kt,{children:[r.jsx(re,{variant:"outline",onClick:()=>h(null),children:"Cancel"}),r.jsxs(re,{onClick:Yr,disabled:N,className:"bg-purple-600 hover:bg-purple-700",children:[N?r.jsx(Qe,{className:"w-4 h-4 animate-spin mr-2"}):r.jsx(zs,{className:"w-4 h-4 mr-2"}),"Save Changes"]})]})]})}),r.jsx(bt,{open:x,onOpenChange:Z=>{w(Z),Z||(z({}),b(new Set))},children:r.jsxs(gt,{className:"max-w-lg",children:[r.jsx(xt,{children:r.jsxs(vt,{className:"flex items-center gap-2",children:[r.jsx(ti,{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(Z=>{var sr;const je=(sr=j==null?void 0:j.projects)==null?void 0:sr.includes(Z.path),Le=y.has(Z.path),Ve=sn(Z.path,j==null?void 0:j.id),jt=B[Z.path],Nt=G[Z.path],xr=Y[Z.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:()=>wr(Z.path),className:"p-1 hover:bg-gray-100 dark:hover:bg-slate-800 rounded",title:"Show sub-projects",children:Nt?r.jsx(Qe,{className:"w-4 h-4 animate-spin text-gray-400"}):jt?r.jsx(Nr,{className:"w-4 h-4 text-gray-400"}):r.jsx(us,{className:"w-4 h-4 text-gray-400"})}),r.jsxs("button",{type:"button",onClick:()=>!je&&Po(Z.path),disabled:je,className:`flex-1 text-left p-2 rounded transition-colors ${je?"bg-gray-100 dark:bg-slate-800 opacity-50 cursor-not-allowed":Le?"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 ${je?"bg-gray-300 dark:bg-slate-600 border-gray-300 dark:border-slate-600":Le?"bg-purple-600 border-purple-600":"border-gray-300 dark:border-slate-600"}`,children:(je||Le)&&r.jsx(Ot,{className:"w-3 h-3 text-white"})}),r.jsx("span",{className:"font-medium text-gray-900 dark:text-white",children:Z.name})]}),r.jsxs("div",{className:"flex items-center gap-1",children:[Ve&&r.jsx("span",{className:`text-xs px-1.5 py-0.5 rounded ${Ve==="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:Ve}),je&&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:Z.path.replace(/^\/Users\/[^/]+/,"~")})]})]}),jt&&xr.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:xr.map(vr=>{var To;const Xr=(To=j==null?void 0:j.projects)==null?void 0:To.includes(vr.dir),Ns=y.has(vr.dir),Cr=sn(vr.dir,j==null?void 0:j.id);return r.jsxs("button",{type:"button",onClick:()=>!Xr&&Po(vr.dir),disabled:Xr,className:`w-full text-left p-2 rounded transition-colors ${Xr?"bg-gray-100 dark:bg-slate-800 opacity-50 cursor-not-allowed":Ns?"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 ${Xr?"bg-gray-300 dark:bg-slate-600 border-gray-300 dark:border-slate-600":Ns?"bg-purple-600 border-purple-600":"border-gray-300 dark:border-slate-600"}`,children:(Xr||Ns)&&r.jsx(Ot,{className:"w-3 h-3 text-white"})}),r.jsx("span",{className:"text-gray-700 dark:text-slate-300",children:vr.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}),Xr&&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:vr.relativePath})]},vr.dir)})}),jt&&xr.length===0&&!Nt&&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"})]},Z.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(kt,{children:[r.jsx(re,{variant:"outline",onClick:()=>{w(!1),b(new Set)},children:"Cancel"}),r.jsxs(re,{onClick:Ga,disabled:y.size===0||N,className:"bg-purple-600 hover:bg-purple-700",children:[N?r.jsx(Qe,{className:"w-4 h-4 animate-spin mr-2"}):r.jsx(Tt,{className:"w-4 h-4 mr-2"}),"Add Selected (",y.size,")"]})]})]})}),r.jsx(bt,{open:oe,onOpenChange:Z=>{Z||(xe(!1),St(""),ze(null))},children:r.jsxs(gt,{children:[r.jsx(xt,{children:r.jsx(vt,{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:Pe==null?void 0:Pe.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(ct,{value:He,onChange:Z=>St(Z.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(kt,{children:[r.jsx(re,{variant:"outline",onClick:()=>{xe(!1),St(""),ze(null)},children:"Cancel"}),r.jsxs(re,{onClick:Wt,disabled:!He.trim(),className:"bg-purple-600 hover:bg-purple-700",children:[r.jsx(ti,{className:"w-4 h-4 mr-2"}),"Add Folder"]})]})]})})]})}const l_={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"},ha={pending:r.jsx(ql,{className:"w-4 h-4 text-gray-500"}),running:r.jsx(ZC,{className:"w-4 h-4 text-green-500"}),paused:r.jsx(xp,{className:"w-4 h-4 text-yellow-500"}),completed:r.jsx(xo,{className:"w-4 h-4 text-green-600"}),failed:r.jsx(ba,{className:"w-4 h-4 text-red-500"}),cancelled:r.jsx(ba,{className:"w-4 h-4 text-gray-500"})};function qH({activeProject:e=null}){var Lo,Za,el,tl,Oo,qi,nn,on;const[t,s]=_.useState([]),[n,o]=_.useState(!0),[d,u]=_.useState(null),[l,c]=_.useState({}),[f,m]=_.useState([]),[h,x]=_.useState(null),[w,j]=_.useState(""),[C,y]=_.useState(!1),[b,g]=_.useState(!1),[v,k]=_.useState(!1),[E,P]=_.useState(!1),[T,N]=_.useState(null),[M,I]=_.useState(!1),[L,B]=_.useState(null),[z,Y]=_.useState(""),[H,G]=_.useState(""),[J,K]=_.useState(50),[F,R]=_.useState("DONE"),[O,U]=_.useState(!1),[$,se]=_.useState(!1),[he,fe]=_.useState(!1),[X,W]=_.useState(""),[ce,ne]=_.useState(""),[Q,ae]=_.useState(!1),[Ce,$e]=_.useState(!1),[Be,de]=_.useState(null),[ye,Ze]=_.useState("create"),[Xe,dt]=_.useState(""),[we,be]=_.useState(""),[Oe,Se]=_.useState(50),[Ee,oe]=_.useState("DONE"),[xe,Pe]=_.useState(""),[ze,He]=_.useState(50),[St,ut]=_.useState(!1),[cr,os]=_.useState("DONE"),[Kr,Zt]=_.useState([]),[Fr,dr]=_.useState({stopHook:{},prepromptHook:{}}),[wr,yn]=_.useState(!1),[qr,fs]=_.useState({needsInstall:!0}),[bn,rt]=_.useState(!1),[Bt,Ht]=_.useState(null),[pr,Br]=_.useState(null),[Wt,rr]=_.useState(!1),[as,Yt]=_.useState(!1),[_t,Yr]=_.useState(null),[gr,Un]=_.useState(!0),[et,Po]=_.useState(null),[Ga,wn]=_.useState(!1);_.useEffect(()=>{_r(),fi(),mi(),sn(),Ao()},[]);const ms=_.useRef(null);_.useEffect(()=>{if(!as||!_t){ms.current=null;return}ms.current=_t.status;const te=setInterval(async()=>{var Ie,$t,zt;try{const ht=(await pe.getLoop(_t.id)).loop,Jr=ms.current!==ht.status,Hs=["completed","paused","failed","cancelled"].includes(ht.status);if(Jr&&Hs){clearInterval(te);const Vn={id:ht.id,name:ht.name,task:(Ie=ht.task)==null?void 0:Ie.original,status:ht.status,pauseReason:ht.pauseReason,iterations:(($t=ht.iterations)==null?void 0:$t.current)||0,maxIterations:((zt=ht.iterations)==null?void 0:zt.max)||50,phase:ht.phase,startedAt:ht.startedAt,completedAt:ht.completedAt||new Date().toISOString(),duration:ht.startedAt?Math.round((Date.now()-new Date(ht.startedAt).getTime())/1e3):null};Po(Vn),ht.status==="completed"?q.success("Loop completed successfully!"):ht.status==="paused"?q.info(`Loop paused: ${ht.pauseReason||"unknown reason"}`):ht.status==="failed"?q.error("Loop failed"):ht.status==="cancelled"&&q.warning("Loop cancelled"),_r(),gr&&ht.status==="completed"?setTimeout(()=>{Yt(!1),Yr(null),wn(!0)},1500):wn(!0)}ms.current=ht.status}catch($r){console.error("Failed to poll loop status:",$r)}},3e3);return()=>clearInterval(te)},[as,_t,gr]);const Ao=async()=>{try{const te=await pe.getRalphLoopPluginStatus();fs(te)}catch(te){console.error("Failed to load plugin status:",te)}},sn=async()=>{try{const te=await pe.getWorkstreams();m(te.workstreams||[]),x(te.activeId||null)}catch(te){console.error("Failed to load workstreams:",te)}};_.useEffect(()=>{C&&h&&G(h)},[C,h]);const _r=async()=>{try{o(!0);const te=await pe.getLoops();s(te.loops||[]),c(te.config||{})}catch{q.error("Failed to load loops")}finally{o(!1)}},fi=async()=>{try{const Ie=(await pe.getLoopConfig()).config||{};c(Ie),He(Ie.maxIterations||50),ut(Ie.autoApprovePlan||!1),os(Ie.completionPromise||"DONE"),K(Ie.maxIterations||50),R(Ie.completionPromise||"DONE")}catch(te){console.error("Failed to load config:",te)}},mi=async()=>{try{const te=await pe.getLoopHookStatus();dr(te)}catch(te){console.error("Failed to load hook status:",te)}},Gi=async()=>{try{const te=await pe.getLoopHistory();Zt(te.completed||[])}catch{q.error("Failed to load history")}},Z=async()=>{if(!z.trim()){q.error("Task description is required");return}await sr(z)},je=async()=>{if(!z.trim()){q.error("Enter a task description first");return}try{se(!0),ne(z),Ze("create");const te=await pe.tuneLoopPrompt(z,(e==null?void 0:e.path)||(e==null?void 0:e.dir)||null);te.success?(W(te.tunedPrompt),fe(!0)):q.error(te.error||"Failed to tune prompt")}catch(te){q.error(te.message)}finally{se(!1)}},Le=()=>{ye==="edit"?be(X):(Y(X),ae(!0)),fe(!1),q.success("Tuned prompt applied")},Ve=()=>{fe(!1)},jt=te=>{te.status==="failed"||te.status==="paused"||te.status==="cancelled"?(de(te),$e(!0)):Ic(te.id)},Nt=async()=>{var te,Ie,$t,zt;if(Be)try{se(!0);const $r=((te=Be.task)==null?void 0:te.original)||"",ht=await pe.getLoop(Be.id),Jr=ht.loop||Be,Hs={status:Jr.status,pauseReason:Jr.pauseReason,iterations:((Ie=Jr.iterations)==null?void 0:Ie.current)||0,maxIterations:(($t=Jr.iterations)==null?void 0:$t.max)||50,phase:Jr.phase,clarifications:ht.clarifications||"",plan:ht.plan||"",iterationHistory:(((zt=Jr.iterations)==null?void 0:zt.history)||[]).slice(-5).map(rl=>`Iteration ${rl.n}: ${rl.summary||"no summary"}`).join(`
2983
2983
  `)};let Vn="";Hs.clarifications&&(Vn+=`=== Clarifications ===
2984
2984
  ${Hs.clarifications}
2985
2985
 
@@ -2988,7 +2988,7 @@ ${Hs.plan}
2988
2988
 
2989
2989
  `),Hs.iterationHistory&&(Vn+=`=== Recent Iterations ===
2990
2990
  ${Hs.iterationHistory}
2991
- `),Hs.transcript=Vn;const pi=await pe.tuneLoopPrompt($r,Be.projectPath||(e==null?void 0:e.path)||(e==null?void 0:e.dir)||null,Hs);pi.success?(await pe.updateLoop(Be.id,{task:{original:pi.tunedPrompt}}),q.success("Prompt tuned and loop updated"),$e(!1),await Ka(Be.id),_r()):q.error(pi.error||"Failed to tune prompt")}catch($r){q.error($r.message)}finally{se(!1),de(null)}},xr=async()=>{Be&&($e(!1),await Ic(Be.id),de(null))},sr=async te=>{try{U(!0);const Ie=await pe.createLoop(te,{workstreamId:H||null,projectPath:(e==null?void 0:e.path)||(e==null?void 0:e.dir)||null,maxIterations:parseInt(J,10)||50,completionPromise:F||"DONE"});Ie.success?(q.success("Loop created"),y(!1),Y(""),G(""),K(ze),R(cr),ae(!1),_r()):q.error(Ie.error||"Failed to create loop")}catch(Ie){q.error(Ie.message)}finally{U(!1)}},vr=async te=>{if(qr.needsInstall){Ht(te),Br("start"),rt(!0);return}await Xr(te)},Xr=async te=>{try{const Ie=await pe.startLoop(te);Ie.success&&Ie.loop?(q.success("Loop started - launching Claude Code"),Yr(Ie.loop),Yt(!0),_r()):q.error(Ie.error||"Failed to start loop")}catch(Ie){q.error(Ie.message)}},Ns=async()=>{try{rr(!0);const te=await pe.installRalphLoopPlugin();te.success?(q.success("ralph-loop plugin installed"),fs({installed:!0,scope:"user",needsInstall:!1}),rt(!1),Bt&&(pr==="resume"?await Ka(Bt):await Xr(Bt),Ht(null),Br(null))):q.error(te.error||"Failed to install plugin")}catch(te){q.error(te.message)}finally{rr(!1)}},Cr=()=>{rt(!1),Ht(null),Br(null)},To=_.useCallback(async(te,Ie)=>{var $t,zt;if(_t)try{const ht=(await pe.getLoop(_t.id)).loop;ht.taskComplete||ht.status==="completed"?(q.success("Loop completed successfully!"),Yt(!1),Yr(null)):ht.status==="paused"?q.info(`Loop paused: ${ht.pauseReason||"user requested"}`):(($t=ht.iterations)==null?void 0:$t.current)>=((zt=ht.iterations)==null?void 0:zt.max)?(q.warning("Loop reached max iterations"),await pe.pauseLoop(ht.id)):q.info("Claude exited. Click Start to continue the loop."),_r()}catch($r){console.error("Failed to check loop status:",$r)}},[_t]),Es=async te=>{try{const Ie=await pe.pauseLoop(te);Ie.success?(q.success("Loop paused"),_r()):q.error(Ie.error||"Failed to pause loop")}catch(Ie){q.error(Ie.message)}},Ic=async te=>{if(qr.needsInstall){Ht(te),Br("resume"),rt(!0);return}await Ka(te)},Ka=async te=>{try{const Ie=await pe.resumeLoop(te);Ie.success&&Ie.loop?(q.success("Loop resumed - launching Claude Code"),Yr(Ie.loop),Yt(!0),_r()):q.error(Ie.error||"Failed to resume loop")}catch(Ie){q.error(Ie.message)}},Ch=async te=>{if(confirm("Cancel this loop?"))try{const Ie=await pe.cancelLoop(te);Ie.success?(q.success("Loop cancelled"),_r()):q.error(Ie.error||"Failed to cancel loop")}catch(Ie){q.error(Ie.message)}},Ro=async te=>{if(confirm("Delete this loop and all its data?"))try{const Ie=await pe.deleteLoop(te);Ie.success?(q.success("Loop deleted"),_r()):q.error(Ie.error||"Failed to delete loop")}catch(Ie){q.error(Ie.message)}},Mo=te=>{var Ie,$t;B(te),dt(te.name||""),be(((Ie=te.task)==null?void 0:Ie.original)||""),Se((($t=te.iterations)==null?void 0:$t.max)||50),oe(te.completionPromise||"DONE"),Pe(te.workstreamId||""),I(!0)},Ki=async()=>{if(L)try{U(!0);const te={name:Xe,task:{original:we},iterations:{max:parseInt(Oe,10)},completionPromise:Ee,workstreamId:xe||null},Ie=await pe.updateLoop(L.id,te);Ie.success?(q.success("Loop updated"),I(!1),B(null),_r()):q.error(Ie.error||"Failed to update loop")}catch(te){q.error(te.message)}finally{U(!1)}},Do=async te=>{var Ie,$t;try{U(!0);const zt=await pe.createLoop(((Ie=te.task)==null?void 0:Ie.original)||"",{name:`${te.name} (copy)`,workstreamId:te.workstreamId||null,projectPath:te.projectPath||(e==null?void 0:e.path)||(e==null?void 0:e.dir)||null,maxIterations:(($t=te.iterations)==null?void 0:$t.max)||50,completionPromise:te.completionPromise||"DONE"});zt.success?(q.success("Loop copied"),_r()):q.error(zt.error||"Failed to copy loop")}catch(zt){q.error(zt.message)}finally{U(!1)}},Sh=async te=>{try{const Ie=await pe.approveLoop(te);Ie.success?(q.success("Plan approved"),_r()):q.error(Ie.error||"Failed to approve plan")}catch(Ie){q.error(Ie.message)}},kh=async()=>{try{U(!0);const te=await pe.updateLoopConfig({maxIterations:parseInt(ze,10),autoApprovePlan:St,completionPromise:cr});te.success?(q.success("Configuration saved"),g(!1),fi()):q.error(te.error||"Failed to save configuration")}catch(te){q.error(te.message)}finally{U(!1)}},qa=async()=>{try{yn(!0);const te=await pe.installLoopHooks();te.success?(q.success("Hooks installed successfully"),mi()):q.error(te.error||"Failed to install hooks")}catch(te){q.error(te.message)}finally{yn(!1)}},Ya=async te=>{try{const Ie=await pe.getLoop(te.id);N({...Ie.loop,clarifications:Ie.clarifications,plan:Ie.plan}),P(!0)}catch{q.error("Failed to load loop details")}},Xa=te=>{navigator.clipboard.writeText(te),q.success("Copied to clipboard")},_n=te=>te?new Date(te).toLocaleString():"-",jh=te=>te.iterations?Math.min(100,te.iterations.current/te.iterations.max*100):0,Ja=((Lo=Fr.stopHook)==null?void 0:Lo.registered)&&((Za=Fr.prepromptHook)==null?void 0:Za.registered),Pt=te=>{if(!te)return null;const Ie=f.find($t=>$t.id===te);return(Ie==null?void 0:Ie.name)||te},Qa=w?t.filter(te=>te.workstreamId===w):t,Io=te=>{var $r,ht;const Ie=((($r=te.task)==null?void 0:$r.original)||"").replace(/"/g,'\\"'),$t=((ht=te.iterations)==null?void 0:ht.max)||50,zt=te.completionPromise||"DONE";return`claude --dangerously-skip-permissions "/ralph-loop ${Ie} --max-iterations ${$t} --completion-promise '${zt}'"`};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(sc,{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(Rg,{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:te=>j(te.target.value),children:[r.jsx("option",{value:"",children:"All workstreams"}),f.map(te=>r.jsx("option",{value:te.id,children:te.name},te.id))]})]}),r.jsx(or,{children:r.jsxs(It,{children:[r.jsx(Lt,{asChild:!0,children:r.jsxs(re,{variant:"outline",size:"sm",onClick:()=>{Gi(),k(!0)},children:[r.jsx(xu,{className:"w-4 h-4 mr-1"}),"History"]})}),r.jsx(Rt,{children:"View completed loops"})]})}),r.jsx(or,{children:r.jsxs(It,{children:[r.jsx(Lt,{asChild:!0,children:r.jsxs(re,{variant:"outline",size:"sm",onClick:()=>g(!0),children:[r.jsx(en,{className:"w-4 h-4 mr-1"}),"Config"]})}),r.jsx(Rt,{children:"Configure loop defaults"})]})}),r.jsxs(re,{onClick:()=>y(!0),children:[r.jsx(Tt,{className:"w-4 h-4 mr-1"}),"New Loop"]})]})]}),!Ja&&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(Os,{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(re,{variant:"outline",size:"sm",onClick:qa,disabled:wr,children:[wr?r.jsx(Qe,{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(Qe,{className:"w-6 h-6 animate-spin text-muted-foreground"})}):Qa.length===0?r.jsxs("div",{className:"text-center py-12 text-muted-foreground",children:[r.jsx(sc,{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:Qa.map(te=>{var Ie,$t,zt,$r,ht;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===te.id?null:te.id),children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{className:"flex items-center gap-3",children:[d===te.id?r.jsx(Nr,{className:"w-4 h-4 text-muted-foreground"}):r.jsx(us,{className:"w-4 h-4 text-muted-foreground"}),ha[te.status]||ha.pending,r.jsxs("div",{children:[r.jsx("h3",{className:"font-medium",children:te.name}),r.jsx("p",{className:"text-sm text-muted-foreground truncate max-w-md",children:((Ie=te.task)==null?void 0:Ie.original)||"No task"})]})]}),r.jsxs("div",{className:"flex items-center gap-3",children:[te.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(Pn,{className:"w-3 h-3"}),Pt(te.workstreamId)]}),r.jsx("span",{className:`text-xs px-2 py-0.5 rounded-full ${l_[te.phase]||"bg-gray-100 dark:bg-gray-800"}`,children:te.phase}),r.jsxs("span",{className:"text-sm text-muted-foreground",children:[(($t=te.iterations)==null?void 0:$t.current)||0,"/",((zt=te.iterations)==null?void 0:zt.max)||50]}),r.jsxs("div",{className:"flex items-center gap-1",onClick:Jr=>Jr.stopPropagation(),children:[te.status==="pending"&&r.jsx(or,{children:r.jsxs(It,{children:[r.jsx(Lt,{asChild:!0,children:r.jsx(re,{variant:"ghost",size:"sm",onClick:()=>vr(te.id),children:r.jsx(ZC,{className:"w-4 h-4"})})}),r.jsx(Rt,{children:"Start loop"})]})}),te.status==="running"&&r.jsx(or,{children:r.jsxs(It,{children:[r.jsx(Lt,{asChild:!0,children:r.jsx(re,{variant:"ghost",size:"sm",onClick:()=>Es(te.id),children:r.jsx(xp,{className:"w-4 h-4"})})}),r.jsx(Rt,{children:"Pause loop"})]})}),te.status==="paused"&&r.jsx(or,{children:r.jsxs(It,{children:[r.jsx(Lt,{asChild:!0,children:r.jsx(re,{variant:"ghost",size:"sm",onClick:()=>jt(te),children:r.jsx($d,{className:"w-4 h-4"})})}),r.jsx(Rt,{children:"Resume loop"})]})}),(te.status==="cancelled"||te.status==="failed")&&r.jsx(or,{children:r.jsxs(It,{children:[r.jsx(Lt,{asChild:!0,children:r.jsx(re,{variant:"ghost",size:"sm",onClick:()=>jt(te),children:r.jsx($d,{className:"w-4 h-4"})})}),r.jsx(Rt,{children:"Restart loop"})]})}),te.phase==="plan"&&te.status==="running"&&r.jsx(or,{children:r.jsxs(It,{children:[r.jsx(Lt,{asChild:!0,children:r.jsx(re,{variant:"ghost",size:"sm",onClick:()=>Sh(te.id),children:r.jsx(Ot,{className:"w-4 h-4"})})}),r.jsx(Rt,{children:"Approve plan"})]})}),r.jsx(or,{children:r.jsxs(It,{children:[r.jsx(Lt,{asChild:!0,children:r.jsx(re,{variant:"ghost",size:"sm",onClick:()=>Mo(te),children:r.jsx(zu,{className:"w-4 h-4"})})}),r.jsx(Rt,{children:"Edit loop"})]})}),r.jsx(or,{children:r.jsxs(It,{children:[r.jsx(Lt,{asChild:!0,children:r.jsx(re,{variant:"ghost",size:"sm",onClick:()=>Do(te),children:r.jsx(Pa,{className:"w-4 h-4"})})}),r.jsx(Rt,{children:"Duplicate loop"})]})}),r.jsx(or,{children:r.jsxs(It,{children:[r.jsx(Lt,{asChild:!0,children:r.jsx(re,{variant:"ghost",size:"sm",onClick:()=>Ya(te),children:r.jsx(Ag,{className:"w-4 h-4"})})}),r.jsx(Rt,{children:"View details"})]})}),(te.status==="running"||te.status==="paused")&&r.jsx(or,{children:r.jsxs(It,{children:[r.jsx(Lt,{asChild:!0,children:r.jsx(re,{variant:"ghost",size:"sm",onClick:()=>Ch(te.id),children:r.jsx(ba,{className:"w-4 h-4"})})}),r.jsx(Rt,{children:"Cancel loop"})]})}),r.jsx(or,{children:r.jsxs(It,{children:[r.jsx(Lt,{asChild:!0,children:r.jsx(re,{variant:"ghost",size:"sm",onClick:()=>Ro(te.id),children:r.jsx(Ss,{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:[(($r=te.iterations)==null?void 0:$r.current)||0," / ",((ht=te.iterations)==null?void 0:ht.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:`${jh(te)}%`}})})]})]}),d===te.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:te.id}),r.jsx(re,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 ml-1",onClick:()=>Xa(te.id),children:r.jsx(Pa,{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:[te.status,te.pauseReason?` (${te.pauseReason})`:""]})]}),r.jsxs("div",{children:[r.jsx("span",{className:"text-muted-foreground",children:"Created:"}),r.jsx("span",{className:"ml-2",children:_n(te.createdAt)})]}),r.jsxs("div",{children:[r.jsx("span",{className:"text-muted-foreground",children:"Updated:"}),r.jsx("span",{className:"ml-2",children:_n(te.updatedAt)})]}),te.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(Pn,{className:"w-3 h-3 text-purple-500"}),Pt(te.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(Gt,{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:Io(te)})]})]})]},te.id)})}),r.jsx(bt,{open:C,onOpenChange:y,children:r.jsxs(gt,{className:"sm:max-w-lg",children:[r.jsx(xt,{children:r.jsx(vt,{children:"Create New Loop"})}),r.jsxs("div",{className:"space-y-4 py-4",children:[r.jsxs("div",{children:[r.jsxs("div",{className:"flex items-center justify-between mb-1",children:[r.jsx("label",{className:"text-sm font-medium",children:"Task Description"}),r.jsx(or,{children:r.jsxs(It,{children:[r.jsx(Lt,{asChild:!0,children:r.jsxs(re,{variant:"outline",size:"sm",onClick:je,disabled:$||!z.trim(),className:"h-7 text-xs",children:[$?r.jsx(Qe,{className:"w-3 h-3 animate-spin mr-1"}):r.jsx(ns,{className:"w-3 h-3 mr-1"}),"Tune with AI"]})}),r.jsx(Rt,{children:r.jsx("p",{className:"max-w-xs",children:"Use Claude to optimize your prompt for Ralph Loop execution - adds clear completion signals, verification steps, and acceptance criteria."})})]})})]}),r.jsx(Ct,{placeholder:"Describe what you want Claude to accomplish...",value:z,onChange:te=>{Y(te.target.value),ae(!1)},rows:4}),r.jsxs("div",{className:"flex items-center justify-between mt-1",children:[r.jsx("p",{className:"text-xs text-muted-foreground",children:"Be specific about the goal. The loop will continue until this task is completed."}),Q&&r.jsxs("span",{className:"text-xs text-green-600 dark:text-green-400 flex items-center gap-1",children:[r.jsx(Kt,{className:"w-3 h-3"}),"AI-tuned"]})]})]}),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(ct,{type:"number",value:J,onChange:te=>K(te.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(ct,{value:F,onChange:te=>R(te.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:H,onChange:te=>G(te.target.value),children:[r.jsx("option",{value:"",children:"No workstream"}),f.map(te=>r.jsx("option",{value:te.id,children:te.name},te.id))]})]})]}),r.jsxs(kt,{children:[r.jsx(re,{variant:"outline",onClick:()=>y(!1),children:"Cancel"}),r.jsxs(re,{onClick:Z,disabled:O||!z.trim(),children:[O?r.jsx(Qe,{className:"w-4 h-4 animate-spin mr-1"}):null,"Create Loop"]})]})]})}),r.jsx(bt,{open:M,onOpenChange:I,children:r.jsxs(gt,{className:"sm:max-w-lg",children:[r.jsx(xt,{children:r.jsx(vt,{children:"Edit 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:"Name"}),r.jsx(ct,{placeholder:"Loop name",value:Xe,onChange:te=>dt(te.target.value)})]}),r.jsxs("div",{children:[r.jsxs("div",{className:"flex items-center justify-between mb-1",children:[r.jsx("label",{className:"text-sm font-medium",children:"Task Description"}),r.jsx(or,{children:r.jsxs(It,{children:[r.jsx(Lt,{asChild:!0,children:r.jsxs(re,{variant:"outline",size:"sm",onClick:async()=>{if(!we.trim()){q.error("Enter a task description first");return}try{se(!0),ne(we),Ze("edit");const te=await pe.tuneLoopPrompt(we,(L==null?void 0:L.projectPath)||(e==null?void 0:e.path)||(e==null?void 0:e.dir)||null);te.success?(W(te.tunedPrompt),fe(!0)):q.error(te.error||"Failed to tune prompt")}catch(te){q.error(te.message)}finally{se(!1)}},disabled:$||!we.trim(),className:"h-7 text-xs",children:[$?r.jsx(Qe,{className:"w-3 h-3 animate-spin mr-1"}):r.jsx(ns,{className:"w-3 h-3 mr-1"}),"Tune with AI"]})}),r.jsx(Rt,{children:r.jsx("p",{className:"max-w-xs",children:"Use Claude to optimize your prompt for Ralph Loop execution."})})]})})]}),r.jsx(Ct,{placeholder:"Describe what you want Claude to accomplish...",value:we,onChange:te=>be(te.target.value),rows:4})]}),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(ct,{type:"number",value:Oe,onChange:te=>Se(te.target.value),min:1,max:1e3})]}),r.jsxs("div",{children:[r.jsx("label",{className:"text-sm font-medium mb-1 block",children:"Completion Promise"}),r.jsx(ct,{value:Ee,onChange:te=>oe(te.target.value),placeholder:"DONE"})]})]}),f.length>0&&r.jsxs("div",{children:[r.jsx("label",{className:"text-sm font-medium mb-1 block",children:"Workstream"}),r.jsxs("select",{className:"w-full border rounded-md p-2 bg-background",value:xe,onChange:te=>Pe(te.target.value),children:[r.jsx("option",{value:"",children:"No workstream"}),f.map(te=>r.jsx("option",{value:te.id,children:te.name},te.id))]})]}),L&&r.jsxs("div",{className:"text-xs text-muted-foreground",children:[r.jsxs("span",{children:["ID: ",L.id]}),r.jsx("span",{className:"mx-2",children:"|"}),r.jsxs("span",{children:["Status: ",L.status]}),r.jsx("span",{className:"mx-2",children:"|"}),r.jsxs("span",{children:["Phase: ",L.phase]})]})]}),r.jsxs(kt,{children:[r.jsx(re,{variant:"outline",onClick:()=>I(!1),children:"Cancel"}),r.jsxs(re,{onClick:Ki,disabled:O||!we.trim(),children:[O?r.jsx(Qe,{className:"w-4 h-4 animate-spin mr-1"}):null,"Save Changes"]})]})]})}),r.jsx(bt,{open:b,onOpenChange:g,children:r.jsxs(gt,{className:"sm:max-w-md",children:[r.jsx(xt,{children:r.jsx(vt,{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(ct,{type:"number",value:ze,onChange:te=>He(te.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(ct,{value:cr,onChange:te=>os(te.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:St,onChange:te=>ut(te.target.checked),className:"rounded"}),r.jsx("label",{htmlFor:"autoApprovePlan",className:"text-sm",children:"Auto-approve plans (skip manual plan approval)"})]})]}),r.jsxs(kt,{children:[r.jsx(re,{variant:"outline",onClick:()=>g(!1),children:"Cancel"}),r.jsxs(re,{onClick:kh,disabled:O,children:[O?r.jsx(Qe,{className:"w-4 h-4 animate-spin mr-1"}):null,"Save"]})]})]})}),r.jsx(bt,{open:v,onOpenChange:k,children:r.jsxs(gt,{className:"sm:max-w-2xl max-h-[80vh] overflow-y-auto",children:[r.jsx(xt,{children:r.jsx(vt,{children:"Loop History"})}),r.jsx("div",{className:"space-y-3 py-4",children:Kr.length===0?r.jsx("p",{className:"text-center text-muted-foreground py-8",children:"No completed loops yet"}):Kr.slice().reverse().map(te=>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:[ha[te.status]||ha.completed,r.jsx("span",{className:"font-medium",children:te.name})]}),r.jsx("span",{className:"text-xs text-muted-foreground",children:_n(te.completedAt)})]}),r.jsx("p",{className:"text-sm text-muted-foreground mt-1 truncate",children:te.task}),r.jsx("div",{className:"mt-2 text-xs text-muted-foreground",children:r.jsxs("span",{children:["Iterations: ",te.totalIterations]})})]},te.id))})]})}),r.jsx(bt,{open:E,onOpenChange:P,children:r.jsxs(gt,{className:"sm:max-w-3xl max-h-[80vh] overflow-y-auto",children:[r.jsx(xt,{children:r.jsx(vt,{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 ${l_[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:[ha[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:[((el=T.iterations)==null?void 0:el.current)||0," / ",((tl=T.iterations)==null?void 0:tl.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:(Oo=T.task)==null?void 0:Oo.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:((qi=T.iterations)==null?void 0:qi.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:Io(T)})]})]})]})}),r.jsx(bt,{open:bn,onOpenChange:rt,children:r.jsxs(gt,{className:"sm:max-w-md",children:[r.jsx(xt,{children:r.jsxs(vt,{className:"flex items-center gap-2",children:[r.jsx(ai,{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."]}),qr.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:qr.projectPath})]})}),r.jsx("p",{className:"text-sm",children:"Install the plugin globally (user scope) to use loops from any project?"})]}),r.jsxs(kt,{children:[r.jsx(re,{variant:"outline",onClick:Cr,disabled:Wt,children:"Cancel"}),r.jsx(re,{onClick:Ns,disabled:Wt,children:Wt?r.jsxs(r.Fragment,{children:[r.jsx(Qe,{className:"w-4 h-4 animate-spin mr-1"}),"Installing..."]}):r.jsxs(r.Fragment,{children:[r.jsx(ai,{className:"w-4 h-4 mr-1"}),"Install Plugin"]})})]})]})}),r.jsx(Ej,{open:as,onOpenChange:te=>{Yt(te),te||(Yr(null),_r())},title:_t?`Loop: ${_t.name}`:"Running Loop",description:(nn=_t==null?void 0:_t.task)==null?void 0:nn.original,cwd:_t==null?void 0:_t.projectPath,initialCommand:_t?Io(_t):"",env:_t?{CODER_LOOP_ID:_t.id,..._t.workstreamId&&{CODER_WORKSTREAM:_t.workstreamId}}:{},onExit:To,headerExtra:r.jsxs("label",{className:"flex items-center gap-2 text-sm cursor-pointer select-none",children:[r.jsx("input",{type:"checkbox",checked:gr,onChange:te=>Un(te.target.checked),className:"rounded"}),"Auto-close when done"]})}),r.jsx(bt,{open:he,onOpenChange:fe,children:r.jsxs(gt,{className:"sm:max-w-2xl max-h-[80vh] overflow-y-auto",children:[r.jsx(xt,{children:r.jsxs(vt,{className:"flex items-center gap-2",children:[r.jsx(ns,{className:"w-5 h-5 text-purple-500"}),"AI-Tuned Prompt"]})}),r.jsxs("div",{className:"space-y-4 py-4",children:[r.jsxs("div",{children:[r.jsx("h4",{className:"text-sm font-medium mb-2 text-muted-foreground",children:"Original Prompt"}),r.jsx("div",{className:"bg-muted p-3 rounded text-sm whitespace-pre-wrap max-h-32 overflow-y-auto",children:ce})]}),r.jsxs("div",{children:[r.jsxs("h4",{className:"text-sm font-medium mb-2 flex items-center gap-2",children:[r.jsx(Kt,{className:"w-4 h-4 text-purple-500"}),"Tuned Prompt"]}),r.jsx(Ct,{value:X,onChange:te=>W(te.target.value),rows:10,className:"font-mono text-sm"}),r.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"You can edit the tuned prompt before accepting it."})]})]}),r.jsxs(kt,{children:[r.jsx(re,{variant:"outline",onClick:Ve,children:"Keep Original"}),r.jsxs(re,{onClick:Le,children:[r.jsx(Ot,{className:"w-4 h-4 mr-1"}),"Use Tuned Prompt"]})]})]})}),r.jsx(bt,{open:Ce,onOpenChange:$e,children:r.jsxs(gt,{className:"sm:max-w-md",children:[r.jsx(xt,{children:r.jsxs(vt,{className:"flex items-center gap-2",children:[r.jsx($d,{className:"w-5 h-5"}),"Resume Loop"]})}),r.jsx("div",{className:"py-4",children:Be&&r.jsxs(r.Fragment,{children:[r.jsxs("p",{className:"text-sm mb-4",children:["This loop ",Be.status==="failed"?"failed":"was paused",Be.pauseReason&&`: ${Be.pauseReason}`]}),r.jsx("p",{className:"text-sm text-muted-foreground mb-4",children:"Would you like to tune the prompt with AI before resuming? This can help add guardrails based on what went wrong."}),r.jsx("div",{className:"bg-muted p-3 rounded text-sm max-h-32 overflow-y-auto",children:(on=Be.task)==null?void 0:on.original})]})}),r.jsxs(kt,{className:"flex-col sm:flex-row gap-2",children:[r.jsx(re,{variant:"outline",onClick:()=>{$e(!1),de(null)},children:"Cancel"}),r.jsx(re,{variant:"secondary",onClick:xr,children:"Resume As-Is"}),r.jsxs(re,{onClick:Nt,disabled:$,children:[$?r.jsx(Qe,{className:"w-4 h-4 animate-spin mr-1"}):r.jsx(ns,{className:"w-4 h-4 mr-1"}),"Tune & Resume"]})]})]})}),r.jsx(bt,{open:Ga,onOpenChange:wn,children:r.jsxs(gt,{className:"sm:max-w-md",children:[r.jsx(xt,{children:r.jsxs(vt,{className:"flex items-center gap-2",children:[(et==null?void 0:et.status)==="completed"&&r.jsxs(r.Fragment,{children:[r.jsx(xo,{className:"w-5 h-5 text-green-600"})," Loop Completed"]}),(et==null?void 0:et.status)==="paused"&&r.jsxs(r.Fragment,{children:[r.jsx(xp,{className:"w-5 h-5 text-yellow-500"})," Loop Paused"]}),(et==null?void 0:et.status)==="failed"&&r.jsxs(r.Fragment,{children:[r.jsx(ba,{className:"w-5 h-5 text-red-500"})," Loop Failed"]}),(et==null?void 0:et.status)==="cancelled"&&r.jsxs(r.Fragment,{children:[r.jsx(ba,{className:"w-5 h-5 text-gray-500"})," Loop Cancelled"]})]})}),et&&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:et.task})]}),et.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:et.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:[ha[et.status],r.jsx("span",{className:"capitalize",children:et.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:[et.iterations," / ",et.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:et.duration!=null?et.duration<60?`${et.duration}s`:et.duration<3600?`${Math.floor(et.duration/60)}m ${et.duration%60}s`:`${Math.floor(et.duration/3600)}h ${Math.floor(et.duration%3600/60)}m`:"-"})]})]}),r.jsxs("div",{className:"text-xs text-muted-foreground",children:[et.status==="completed"?"Completed":"Stopped"," at ",_n(et.completedAt)]})]}),r.jsxs(kt,{children:[r.jsx(re,{variant:"outline",onClick:()=>wn(!1),children:"Close"}),((et==null?void 0:et.status)==="paused"||(et==null?void 0:et.status)==="failed"||(et==null?void 0:et.status)==="cancelled")&&r.jsxs(re,{onClick:()=>{if(wn(!1),et!=null&&et.id){const te=t.find(Ie=>Ie.id===et.id);te&&jt(te)}},children:[r.jsx($d,{className:"w-4 h-4 mr-1"}),(et==null?void 0:et.status)==="paused"?"Resume":"Restart"]}),r.jsx(re,{variant:"secondary",onClick:()=>{if(wn(!1),et!=null&&et.id){const te=t.find(Ie=>Ie.id===et.id);te&&Ya(te)}},children:"View Details"})]})]})})]})}function YH(e,t=[]){let s=[];function n(d,u){const l=_.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,C=((b=x==null?void 0:x[e])==null?void 0:b[c])||l,y=_.useMemo(()=>j,Object.values(j));return r.jsx(C.Provider,{value:y,children:w})};f.displayName=d+"Provider";function m(h,x){var C;const w=((C=x==null?void 0:x[e])==null?void 0:C[c])||l,j=_.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=>_.createContext(u));return function(l){const c=(l==null?void 0:l[e])||d;return _.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 _.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"],c2=JH.reduce((e,t)=>{const s=Hu(`Primitive.${t}`),n=_.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}},{}),Bx="Progress",$x=100,[QH]=YH(Bx),[ZH,eW]=QH(Bx),d2=_.forwardRef((e,t)=>{const{__scopeProgress:s,value:n=null,max:o,getValueLabel:d=tW,...u}=e;(o||o===0)&&!c_(o)&&console.error(rW(`${o}`,"Progress"));const l=c_(o)?o:$x;n!==null&&!d_(n,l)&&console.error(sW(`${n}`,"Progress"));const c=d_(n,l)?n:null,f=Ru(c)?d(c,l):void 0;return r.jsx(ZH,{scope:s,value:c,max:l,children:r.jsx(c2.div,{"aria-valuemax":l,"aria-valuemin":0,"aria-valuenow":Ru(c)?c:void 0,"aria-valuetext":f,role:"progressbar","data-state":f2(c,l),"data-value":c??void 0,"data-max":l,...u,ref:t})})});d2.displayName=Bx;var u2="ProgressIndicator",h2=_.forwardRef((e,t)=>{const{__scopeProgress:s,...n}=e,o=eW(u2,s);return r.jsx(c2.div,{"data-state":f2(o.value,o.max),"data-value":o.value??void 0,"data-max":o.max,...n,ref:t})});h2.displayName=u2;function tW(e,t){return`${Math.round(e/t*100)}%`}function f2(e,t){return e==null?"indeterminate":e===t?"complete":"loading"}function Ru(e){return typeof e=="number"}function c_(e){return Ru(e)&&!isNaN(e)&&e>0}function d_(e,t){return Ru(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 \`${$x}\`.`}function sW(e,t){return`Invalid prop \`value\` of value \`${e}\` supplied to \`${t}\`. The \`value\` prop must be:
2991
+ `),Hs.transcript=Vn;const pi=await pe.tuneLoopPrompt($r,Be.projectPath||(e==null?void 0:e.path)||(e==null?void 0:e.dir)||null,Hs);pi.success?(await pe.updateLoop(Be.id,{task:{original:pi.tunedPrompt}}),q.success("Prompt tuned and loop updated"),$e(!1),await Ka(Be.id),_r()):q.error(pi.error||"Failed to tune prompt")}catch($r){q.error($r.message)}finally{se(!1),de(null)}},xr=async()=>{Be&&($e(!1),await Ic(Be.id),de(null))},sr=async te=>{try{U(!0);const Ie=await pe.createLoop(te,{workstreamId:H||null,projectPath:(e==null?void 0:e.path)||(e==null?void 0:e.dir)||null,maxIterations:parseInt(J,10)||50,completionPromise:F||"DONE"});Ie.success?(q.success("Loop created"),y(!1),Y(""),G(""),K(ze),R(cr),ae(!1),_r()):q.error(Ie.error||"Failed to create loop")}catch(Ie){q.error(Ie.message)}finally{U(!1)}},vr=async te=>{if(qr.needsInstall){Ht(te),Br("start"),rt(!0);return}await Xr(te)},Xr=async te=>{try{const Ie=await pe.startLoop(te);Ie.success&&Ie.loop?(q.success("Loop started - launching Claude Code"),Yr(Ie.loop),Yt(!0),_r()):q.error(Ie.error||"Failed to start loop")}catch(Ie){q.error(Ie.message)}},Ns=async()=>{try{rr(!0);const te=await pe.installRalphLoopPlugin();te.success?(q.success("ralph-loop plugin installed"),fs({installed:!0,scope:"user",needsInstall:!1}),rt(!1),Bt&&(pr==="resume"?await Ka(Bt):await Xr(Bt),Ht(null),Br(null))):q.error(te.error||"Failed to install plugin")}catch(te){q.error(te.message)}finally{rr(!1)}},Cr=()=>{rt(!1),Ht(null),Br(null)},To=_.useCallback(async(te,Ie)=>{var $t,zt;if(_t)try{const ht=(await pe.getLoop(_t.id)).loop;ht.taskComplete||ht.status==="completed"?(q.success("Loop completed successfully!"),Yt(!1),Yr(null)):ht.status==="paused"?q.info(`Loop paused: ${ht.pauseReason||"user requested"}`):(($t=ht.iterations)==null?void 0:$t.current)>=((zt=ht.iterations)==null?void 0:zt.max)?(q.warning("Loop reached max iterations"),await pe.pauseLoop(ht.id)):q.info("Claude exited. Click Start to continue the loop."),_r()}catch($r){console.error("Failed to check loop status:",$r)}},[_t]),Es=async te=>{try{const Ie=await pe.pauseLoop(te);Ie.success?(q.success("Loop paused"),_r()):q.error(Ie.error||"Failed to pause loop")}catch(Ie){q.error(Ie.message)}},Ic=async te=>{if(qr.needsInstall){Ht(te),Br("resume"),rt(!0);return}await Ka(te)},Ka=async te=>{try{const Ie=await pe.resumeLoop(te);Ie.success&&Ie.loop?(q.success("Loop resumed - launching Claude Code"),Yr(Ie.loop),Yt(!0),_r()):q.error(Ie.error||"Failed to resume loop")}catch(Ie){q.error(Ie.message)}},Ch=async te=>{if(confirm("Cancel this loop?"))try{const Ie=await pe.cancelLoop(te);Ie.success?(q.success("Loop cancelled"),_r()):q.error(Ie.error||"Failed to cancel loop")}catch(Ie){q.error(Ie.message)}},Ro=async te=>{if(confirm("Delete this loop and all its data?"))try{const Ie=await pe.deleteLoop(te);Ie.success?(q.success("Loop deleted"),_r()):q.error(Ie.error||"Failed to delete loop")}catch(Ie){q.error(Ie.message)}},Mo=te=>{var Ie,$t;B(te),dt(te.name||""),be(((Ie=te.task)==null?void 0:Ie.original)||""),Se((($t=te.iterations)==null?void 0:$t.max)||50),oe(te.completionPromise||"DONE"),Pe(te.workstreamId||""),I(!0)},Ki=async()=>{if(L)try{U(!0);const te={name:Xe,task:{original:we},iterations:{max:parseInt(Oe,10)},completionPromise:Ee,workstreamId:xe||null},Ie=await pe.updateLoop(L.id,te);Ie.success?(q.success("Loop updated"),I(!1),B(null),_r()):q.error(Ie.error||"Failed to update loop")}catch(te){q.error(te.message)}finally{U(!1)}},Do=async te=>{var Ie,$t;try{U(!0);const zt=await pe.createLoop(((Ie=te.task)==null?void 0:Ie.original)||"",{name:`${te.name} (copy)`,workstreamId:te.workstreamId||null,projectPath:te.projectPath||(e==null?void 0:e.path)||(e==null?void 0:e.dir)||null,maxIterations:(($t=te.iterations)==null?void 0:$t.max)||50,completionPromise:te.completionPromise||"DONE"});zt.success?(q.success("Loop copied"),_r()):q.error(zt.error||"Failed to copy loop")}catch(zt){q.error(zt.message)}finally{U(!1)}},Sh=async te=>{try{const Ie=await pe.approveLoop(te);Ie.success?(q.success("Plan approved"),_r()):q.error(Ie.error||"Failed to approve plan")}catch(Ie){q.error(Ie.message)}},kh=async()=>{try{U(!0);const te=await pe.updateLoopConfig({maxIterations:parseInt(ze,10),autoApprovePlan:St,completionPromise:cr});te.success?(q.success("Configuration saved"),g(!1),fi()):q.error(te.error||"Failed to save configuration")}catch(te){q.error(te.message)}finally{U(!1)}},qa=async()=>{try{yn(!0);const te=await pe.installLoopHooks();te.success?(q.success("Hooks installed successfully"),mi()):q.error(te.error||"Failed to install hooks")}catch(te){q.error(te.message)}finally{yn(!1)}},Ya=async te=>{try{const Ie=await pe.getLoop(te.id);N({...Ie.loop,clarifications:Ie.clarifications,plan:Ie.plan}),P(!0)}catch{q.error("Failed to load loop details")}},Xa=te=>{navigator.clipboard.writeText(te),q.success("Copied to clipboard")},_n=te=>te?new Date(te).toLocaleString():"-",jh=te=>te.iterations?Math.min(100,te.iterations.current/te.iterations.max*100):0,Ja=((Lo=Fr.stopHook)==null?void 0:Lo.registered)&&((Za=Fr.prepromptHook)==null?void 0:Za.registered),Pt=te=>{if(!te)return null;const Ie=f.find($t=>$t.id===te);return(Ie==null?void 0:Ie.name)||te},Qa=w?t.filter(te=>te.workstreamId===w):t,Io=te=>{var $r,ht;const Ie=((($r=te.task)==null?void 0:$r.original)||"").replace(/"/g,'\\"'),$t=((ht=te.iterations)==null?void 0:ht.max)||50,zt=(te.completionPromise||"DONE").replace(/'/g,"'\\''");return`claude --dangerously-skip-permissions "/ralph-loop ${Ie} --max-iterations ${$t} --completion-promise '${zt}'"`};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(sc,{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(Rg,{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:te=>j(te.target.value),children:[r.jsx("option",{value:"",children:"All workstreams"}),f.map(te=>r.jsx("option",{value:te.id,children:te.name},te.id))]})]}),r.jsx(or,{children:r.jsxs(It,{children:[r.jsx(Lt,{asChild:!0,children:r.jsxs(re,{variant:"outline",size:"sm",onClick:()=>{Gi(),k(!0)},children:[r.jsx(xu,{className:"w-4 h-4 mr-1"}),"History"]})}),r.jsx(Rt,{children:"View completed loops"})]})}),r.jsx(or,{children:r.jsxs(It,{children:[r.jsx(Lt,{asChild:!0,children:r.jsxs(re,{variant:"outline",size:"sm",onClick:()=>g(!0),children:[r.jsx(en,{className:"w-4 h-4 mr-1"}),"Config"]})}),r.jsx(Rt,{children:"Configure loop defaults"})]})}),r.jsxs(re,{onClick:()=>y(!0),children:[r.jsx(Tt,{className:"w-4 h-4 mr-1"}),"New Loop"]})]})]}),!Ja&&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(Os,{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(re,{variant:"outline",size:"sm",onClick:qa,disabled:wr,children:[wr?r.jsx(Qe,{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(Qe,{className:"w-6 h-6 animate-spin text-muted-foreground"})}):Qa.length===0?r.jsxs("div",{className:"text-center py-12 text-muted-foreground",children:[r.jsx(sc,{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:Qa.map(te=>{var Ie,$t,zt,$r,ht;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===te.id?null:te.id),children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{className:"flex items-center gap-3",children:[d===te.id?r.jsx(Nr,{className:"w-4 h-4 text-muted-foreground"}):r.jsx(us,{className:"w-4 h-4 text-muted-foreground"}),ha[te.status]||ha.pending,r.jsxs("div",{children:[r.jsx("h3",{className:"font-medium",children:te.name}),r.jsx("p",{className:"text-sm text-muted-foreground truncate max-w-md",children:((Ie=te.task)==null?void 0:Ie.original)||"No task"})]})]}),r.jsxs("div",{className:"flex items-center gap-3",children:[te.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(Pn,{className:"w-3 h-3"}),Pt(te.workstreamId)]}),r.jsx("span",{className:`text-xs px-2 py-0.5 rounded-full ${l_[te.phase]||"bg-gray-100 dark:bg-gray-800"}`,children:te.phase}),r.jsxs("span",{className:"text-sm text-muted-foreground",children:[(($t=te.iterations)==null?void 0:$t.current)||0,"/",((zt=te.iterations)==null?void 0:zt.max)||50]}),r.jsxs("div",{className:"flex items-center gap-1",onClick:Jr=>Jr.stopPropagation(),children:[te.status==="pending"&&r.jsx(or,{children:r.jsxs(It,{children:[r.jsx(Lt,{asChild:!0,children:r.jsx(re,{variant:"ghost",size:"sm",onClick:()=>vr(te.id),children:r.jsx(ZC,{className:"w-4 h-4"})})}),r.jsx(Rt,{children:"Start loop"})]})}),te.status==="running"&&r.jsx(or,{children:r.jsxs(It,{children:[r.jsx(Lt,{asChild:!0,children:r.jsx(re,{variant:"ghost",size:"sm",onClick:()=>Es(te.id),children:r.jsx(xp,{className:"w-4 h-4"})})}),r.jsx(Rt,{children:"Pause loop"})]})}),te.status==="paused"&&r.jsx(or,{children:r.jsxs(It,{children:[r.jsx(Lt,{asChild:!0,children:r.jsx(re,{variant:"ghost",size:"sm",onClick:()=>jt(te),children:r.jsx($d,{className:"w-4 h-4"})})}),r.jsx(Rt,{children:"Resume loop"})]})}),(te.status==="cancelled"||te.status==="failed")&&r.jsx(or,{children:r.jsxs(It,{children:[r.jsx(Lt,{asChild:!0,children:r.jsx(re,{variant:"ghost",size:"sm",onClick:()=>jt(te),children:r.jsx($d,{className:"w-4 h-4"})})}),r.jsx(Rt,{children:"Restart loop"})]})}),te.phase==="plan"&&te.status==="running"&&r.jsx(or,{children:r.jsxs(It,{children:[r.jsx(Lt,{asChild:!0,children:r.jsx(re,{variant:"ghost",size:"sm",onClick:()=>Sh(te.id),children:r.jsx(Ot,{className:"w-4 h-4"})})}),r.jsx(Rt,{children:"Approve plan"})]})}),r.jsx(or,{children:r.jsxs(It,{children:[r.jsx(Lt,{asChild:!0,children:r.jsx(re,{variant:"ghost",size:"sm",onClick:()=>Mo(te),children:r.jsx(zu,{className:"w-4 h-4"})})}),r.jsx(Rt,{children:"Edit loop"})]})}),r.jsx(or,{children:r.jsxs(It,{children:[r.jsx(Lt,{asChild:!0,children:r.jsx(re,{variant:"ghost",size:"sm",onClick:()=>Do(te),children:r.jsx(Pa,{className:"w-4 h-4"})})}),r.jsx(Rt,{children:"Duplicate loop"})]})}),r.jsx(or,{children:r.jsxs(It,{children:[r.jsx(Lt,{asChild:!0,children:r.jsx(re,{variant:"ghost",size:"sm",onClick:()=>Ya(te),children:r.jsx(Ag,{className:"w-4 h-4"})})}),r.jsx(Rt,{children:"View details"})]})}),(te.status==="running"||te.status==="paused")&&r.jsx(or,{children:r.jsxs(It,{children:[r.jsx(Lt,{asChild:!0,children:r.jsx(re,{variant:"ghost",size:"sm",onClick:()=>Ch(te.id),children:r.jsx(ba,{className:"w-4 h-4"})})}),r.jsx(Rt,{children:"Cancel loop"})]})}),r.jsx(or,{children:r.jsxs(It,{children:[r.jsx(Lt,{asChild:!0,children:r.jsx(re,{variant:"ghost",size:"sm",onClick:()=>Ro(te.id),children:r.jsx(Ss,{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:[(($r=te.iterations)==null?void 0:$r.current)||0," / ",((ht=te.iterations)==null?void 0:ht.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:`${jh(te)}%`}})})]})]}),d===te.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:te.id}),r.jsx(re,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 ml-1",onClick:()=>Xa(te.id),children:r.jsx(Pa,{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:[te.status,te.pauseReason?` (${te.pauseReason})`:""]})]}),r.jsxs("div",{children:[r.jsx("span",{className:"text-muted-foreground",children:"Created:"}),r.jsx("span",{className:"ml-2",children:_n(te.createdAt)})]}),r.jsxs("div",{children:[r.jsx("span",{className:"text-muted-foreground",children:"Updated:"}),r.jsx("span",{className:"ml-2",children:_n(te.updatedAt)})]}),te.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(Pn,{className:"w-3 h-3 text-purple-500"}),Pt(te.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(Gt,{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:Io(te)})]})]})]},te.id)})}),r.jsx(bt,{open:C,onOpenChange:y,children:r.jsxs(gt,{className:"sm:max-w-lg",children:[r.jsx(xt,{children:r.jsx(vt,{children:"Create New Loop"})}),r.jsxs("div",{className:"space-y-4 py-4",children:[r.jsxs("div",{children:[r.jsxs("div",{className:"flex items-center justify-between mb-1",children:[r.jsx("label",{className:"text-sm font-medium",children:"Task Description"}),r.jsx(or,{children:r.jsxs(It,{children:[r.jsx(Lt,{asChild:!0,children:r.jsxs(re,{variant:"outline",size:"sm",onClick:je,disabled:$||!z.trim(),className:"h-7 text-xs",children:[$?r.jsx(Qe,{className:"w-3 h-3 animate-spin mr-1"}):r.jsx(ns,{className:"w-3 h-3 mr-1"}),"Tune with AI"]})}),r.jsx(Rt,{children:r.jsx("p",{className:"max-w-xs",children:"Use Claude to optimize your prompt for Ralph Loop execution - adds clear completion signals, verification steps, and acceptance criteria."})})]})})]}),r.jsx(Ct,{placeholder:"Describe what you want Claude to accomplish...",value:z,onChange:te=>{Y(te.target.value),ae(!1)},rows:4}),r.jsxs("div",{className:"flex items-center justify-between mt-1",children:[r.jsx("p",{className:"text-xs text-muted-foreground",children:"Be specific about the goal. The loop will continue until this task is completed."}),Q&&r.jsxs("span",{className:"text-xs text-green-600 dark:text-green-400 flex items-center gap-1",children:[r.jsx(Kt,{className:"w-3 h-3"}),"AI-tuned"]})]})]}),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(ct,{type:"number",value:J,onChange:te=>K(te.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(ct,{value:F,onChange:te=>R(te.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:H,onChange:te=>G(te.target.value),children:[r.jsx("option",{value:"",children:"No workstream"}),f.map(te=>r.jsx("option",{value:te.id,children:te.name},te.id))]})]})]}),r.jsxs(kt,{children:[r.jsx(re,{variant:"outline",onClick:()=>y(!1),children:"Cancel"}),r.jsxs(re,{onClick:Z,disabled:O||!z.trim(),children:[O?r.jsx(Qe,{className:"w-4 h-4 animate-spin mr-1"}):null,"Create Loop"]})]})]})}),r.jsx(bt,{open:M,onOpenChange:I,children:r.jsxs(gt,{className:"sm:max-w-lg",children:[r.jsx(xt,{children:r.jsx(vt,{children:"Edit 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:"Name"}),r.jsx(ct,{placeholder:"Loop name",value:Xe,onChange:te=>dt(te.target.value)})]}),r.jsxs("div",{children:[r.jsxs("div",{className:"flex items-center justify-between mb-1",children:[r.jsx("label",{className:"text-sm font-medium",children:"Task Description"}),r.jsx(or,{children:r.jsxs(It,{children:[r.jsx(Lt,{asChild:!0,children:r.jsxs(re,{variant:"outline",size:"sm",onClick:async()=>{if(!we.trim()){q.error("Enter a task description first");return}try{se(!0),ne(we),Ze("edit");const te=await pe.tuneLoopPrompt(we,(L==null?void 0:L.projectPath)||(e==null?void 0:e.path)||(e==null?void 0:e.dir)||null);te.success?(W(te.tunedPrompt),fe(!0)):q.error(te.error||"Failed to tune prompt")}catch(te){q.error(te.message)}finally{se(!1)}},disabled:$||!we.trim(),className:"h-7 text-xs",children:[$?r.jsx(Qe,{className:"w-3 h-3 animate-spin mr-1"}):r.jsx(ns,{className:"w-3 h-3 mr-1"}),"Tune with AI"]})}),r.jsx(Rt,{children:r.jsx("p",{className:"max-w-xs",children:"Use Claude to optimize your prompt for Ralph Loop execution."})})]})})]}),r.jsx(Ct,{placeholder:"Describe what you want Claude to accomplish...",value:we,onChange:te=>be(te.target.value),rows:4})]}),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(ct,{type:"number",value:Oe,onChange:te=>Se(te.target.value),min:1,max:1e3})]}),r.jsxs("div",{children:[r.jsx("label",{className:"text-sm font-medium mb-1 block",children:"Completion Promise"}),r.jsx(ct,{value:Ee,onChange:te=>oe(te.target.value),placeholder:"DONE"})]})]}),f.length>0&&r.jsxs("div",{children:[r.jsx("label",{className:"text-sm font-medium mb-1 block",children:"Workstream"}),r.jsxs("select",{className:"w-full border rounded-md p-2 bg-background",value:xe,onChange:te=>Pe(te.target.value),children:[r.jsx("option",{value:"",children:"No workstream"}),f.map(te=>r.jsx("option",{value:te.id,children:te.name},te.id))]})]}),L&&r.jsxs("div",{className:"text-xs text-muted-foreground",children:[r.jsxs("span",{children:["ID: ",L.id]}),r.jsx("span",{className:"mx-2",children:"|"}),r.jsxs("span",{children:["Status: ",L.status]}),r.jsx("span",{className:"mx-2",children:"|"}),r.jsxs("span",{children:["Phase: ",L.phase]})]})]}),r.jsxs(kt,{children:[r.jsx(re,{variant:"outline",onClick:()=>I(!1),children:"Cancel"}),r.jsxs(re,{onClick:Ki,disabled:O||!we.trim(),children:[O?r.jsx(Qe,{className:"w-4 h-4 animate-spin mr-1"}):null,"Save Changes"]})]})]})}),r.jsx(bt,{open:b,onOpenChange:g,children:r.jsxs(gt,{className:"sm:max-w-md",children:[r.jsx(xt,{children:r.jsx(vt,{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(ct,{type:"number",value:ze,onChange:te=>He(te.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(ct,{value:cr,onChange:te=>os(te.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:St,onChange:te=>ut(te.target.checked),className:"rounded"}),r.jsx("label",{htmlFor:"autoApprovePlan",className:"text-sm",children:"Auto-approve plans (skip manual plan approval)"})]})]}),r.jsxs(kt,{children:[r.jsx(re,{variant:"outline",onClick:()=>g(!1),children:"Cancel"}),r.jsxs(re,{onClick:kh,disabled:O,children:[O?r.jsx(Qe,{className:"w-4 h-4 animate-spin mr-1"}):null,"Save"]})]})]})}),r.jsx(bt,{open:v,onOpenChange:k,children:r.jsxs(gt,{className:"sm:max-w-2xl max-h-[80vh] overflow-y-auto",children:[r.jsx(xt,{children:r.jsx(vt,{children:"Loop History"})}),r.jsx("div",{className:"space-y-3 py-4",children:Kr.length===0?r.jsx("p",{className:"text-center text-muted-foreground py-8",children:"No completed loops yet"}):Kr.slice().reverse().map(te=>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:[ha[te.status]||ha.completed,r.jsx("span",{className:"font-medium",children:te.name})]}),r.jsx("span",{className:"text-xs text-muted-foreground",children:_n(te.completedAt)})]}),r.jsx("p",{className:"text-sm text-muted-foreground mt-1 truncate",children:te.task}),r.jsx("div",{className:"mt-2 text-xs text-muted-foreground",children:r.jsxs("span",{children:["Iterations: ",te.totalIterations]})})]},te.id))})]})}),r.jsx(bt,{open:E,onOpenChange:P,children:r.jsxs(gt,{className:"sm:max-w-3xl max-h-[80vh] overflow-y-auto",children:[r.jsx(xt,{children:r.jsx(vt,{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 ${l_[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:[ha[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:[((el=T.iterations)==null?void 0:el.current)||0," / ",((tl=T.iterations)==null?void 0:tl.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:(Oo=T.task)==null?void 0:Oo.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:((qi=T.iterations)==null?void 0:qi.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:Io(T)})]})]})]})}),r.jsx(bt,{open:bn,onOpenChange:rt,children:r.jsxs(gt,{className:"sm:max-w-md",children:[r.jsx(xt,{children:r.jsxs(vt,{className:"flex items-center gap-2",children:[r.jsx(ai,{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."]}),qr.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:qr.projectPath})]})}),r.jsx("p",{className:"text-sm",children:"Install the plugin globally (user scope) to use loops from any project?"})]}),r.jsxs(kt,{children:[r.jsx(re,{variant:"outline",onClick:Cr,disabled:Wt,children:"Cancel"}),r.jsx(re,{onClick:Ns,disabled:Wt,children:Wt?r.jsxs(r.Fragment,{children:[r.jsx(Qe,{className:"w-4 h-4 animate-spin mr-1"}),"Installing..."]}):r.jsxs(r.Fragment,{children:[r.jsx(ai,{className:"w-4 h-4 mr-1"}),"Install Plugin"]})})]})]})}),r.jsx(Ej,{open:as,onOpenChange:te=>{Yt(te),te||(Yr(null),_r())},title:_t?`Loop: ${_t.name}`:"Running Loop",description:(nn=_t==null?void 0:_t.task)==null?void 0:nn.original,cwd:_t==null?void 0:_t.projectPath,initialCommand:_t?Io(_t):"",env:_t?{CODER_LOOP_ID:_t.id,..._t.workstreamId&&{CODER_WORKSTREAM:_t.workstreamId}}:{},onExit:To,headerExtra:r.jsxs("label",{className:"flex items-center gap-2 text-sm cursor-pointer select-none",children:[r.jsx("input",{type:"checkbox",checked:gr,onChange:te=>Un(te.target.checked),className:"rounded"}),"Auto-close when done"]})}),r.jsx(bt,{open:he,onOpenChange:fe,children:r.jsxs(gt,{className:"sm:max-w-2xl max-h-[80vh] overflow-y-auto",children:[r.jsx(xt,{children:r.jsxs(vt,{className:"flex items-center gap-2",children:[r.jsx(ns,{className:"w-5 h-5 text-purple-500"}),"AI-Tuned Prompt"]})}),r.jsxs("div",{className:"space-y-4 py-4",children:[r.jsxs("div",{children:[r.jsx("h4",{className:"text-sm font-medium mb-2 text-muted-foreground",children:"Original Prompt"}),r.jsx("div",{className:"bg-muted p-3 rounded text-sm whitespace-pre-wrap max-h-32 overflow-y-auto",children:ce})]}),r.jsxs("div",{children:[r.jsxs("h4",{className:"text-sm font-medium mb-2 flex items-center gap-2",children:[r.jsx(Kt,{className:"w-4 h-4 text-purple-500"}),"Tuned Prompt"]}),r.jsx(Ct,{value:X,onChange:te=>W(te.target.value),rows:10,className:"font-mono text-sm"}),r.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"You can edit the tuned prompt before accepting it."})]})]}),r.jsxs(kt,{children:[r.jsx(re,{variant:"outline",onClick:Ve,children:"Keep Original"}),r.jsxs(re,{onClick:Le,children:[r.jsx(Ot,{className:"w-4 h-4 mr-1"}),"Use Tuned Prompt"]})]})]})}),r.jsx(bt,{open:Ce,onOpenChange:$e,children:r.jsxs(gt,{className:"sm:max-w-md",children:[r.jsx(xt,{children:r.jsxs(vt,{className:"flex items-center gap-2",children:[r.jsx($d,{className:"w-5 h-5"}),"Resume Loop"]})}),r.jsx("div",{className:"py-4",children:Be&&r.jsxs(r.Fragment,{children:[r.jsxs("p",{className:"text-sm mb-4",children:["This loop ",Be.status==="failed"?"failed":Be.status==="cancelled"?"was cancelled":"was paused",Be.pauseReason&&`: ${Be.pauseReason}`]}),r.jsx("p",{className:"text-sm text-muted-foreground mb-4",children:"Would you like to tune the prompt with AI before resuming? This can help add guardrails based on what went wrong."}),r.jsx("div",{className:"bg-muted p-3 rounded text-sm max-h-32 overflow-y-auto",children:(on=Be.task)==null?void 0:on.original})]})}),r.jsxs(kt,{className:"flex-col sm:flex-row gap-2",children:[r.jsx(re,{variant:"outline",onClick:()=>{$e(!1),de(null)},children:"Cancel"}),r.jsx(re,{variant:"secondary",onClick:xr,children:"Resume As-Is"}),r.jsxs(re,{onClick:Nt,disabled:$,children:[$?r.jsx(Qe,{className:"w-4 h-4 animate-spin mr-1"}):r.jsx(ns,{className:"w-4 h-4 mr-1"}),"Tune & Resume"]})]})]})}),r.jsx(bt,{open:Ga,onOpenChange:wn,children:r.jsxs(gt,{className:"sm:max-w-md",children:[r.jsx(xt,{children:r.jsxs(vt,{className:"flex items-center gap-2",children:[(et==null?void 0:et.status)==="completed"&&r.jsxs(r.Fragment,{children:[r.jsx(xo,{className:"w-5 h-5 text-green-600"})," Loop Completed"]}),(et==null?void 0:et.status)==="paused"&&r.jsxs(r.Fragment,{children:[r.jsx(xp,{className:"w-5 h-5 text-yellow-500"})," Loop Paused"]}),(et==null?void 0:et.status)==="failed"&&r.jsxs(r.Fragment,{children:[r.jsx(ba,{className:"w-5 h-5 text-red-500"})," Loop Failed"]}),(et==null?void 0:et.status)==="cancelled"&&r.jsxs(r.Fragment,{children:[r.jsx(ba,{className:"w-5 h-5 text-gray-500"})," Loop Cancelled"]})]})}),et&&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:et.task})]}),et.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:et.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:[ha[et.status],r.jsx("span",{className:"capitalize",children:et.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:[et.iterations," / ",et.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:et.duration!=null?et.duration<60?`${et.duration}s`:et.duration<3600?`${Math.floor(et.duration/60)}m ${et.duration%60}s`:`${Math.floor(et.duration/3600)}h ${Math.floor(et.duration%3600/60)}m`:"-"})]})]}),r.jsxs("div",{className:"text-xs text-muted-foreground",children:[et.status==="completed"?"Completed":"Stopped"," at ",_n(et.completedAt)]})]}),r.jsxs(kt,{children:[r.jsx(re,{variant:"outline",onClick:()=>wn(!1),children:"Close"}),((et==null?void 0:et.status)==="paused"||(et==null?void 0:et.status)==="failed"||(et==null?void 0:et.status)==="cancelled")&&r.jsxs(re,{onClick:()=>{if(wn(!1),et!=null&&et.id){const te=t.find(Ie=>Ie.id===et.id);te&&jt(te)}},children:[r.jsx($d,{className:"w-4 h-4 mr-1"}),(et==null?void 0:et.status)==="paused"?"Resume":"Restart"]}),r.jsx(re,{variant:"secondary",onClick:()=>{if(wn(!1),et!=null&&et.id){const te=t.find(Ie=>Ie.id===et.id);te&&Ya(te)}},children:"View Details"})]})]})})]})}function YH(e,t=[]){let s=[];function n(d,u){const l=_.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,C=((b=x==null?void 0:x[e])==null?void 0:b[c])||l,y=_.useMemo(()=>j,Object.values(j));return r.jsx(C.Provider,{value:y,children:w})};f.displayName=d+"Provider";function m(h,x){var C;const w=((C=x==null?void 0:x[e])==null?void 0:C[c])||l,j=_.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=>_.createContext(u));return function(l){const c=(l==null?void 0:l[e])||d;return _.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 _.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"],c2=JH.reduce((e,t)=>{const s=Hu(`Primitive.${t}`),n=_.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}},{}),Bx="Progress",$x=100,[QH]=YH(Bx),[ZH,eW]=QH(Bx),d2=_.forwardRef((e,t)=>{const{__scopeProgress:s,value:n=null,max:o,getValueLabel:d=tW,...u}=e;(o||o===0)&&!c_(o)&&console.error(rW(`${o}`,"Progress"));const l=c_(o)?o:$x;n!==null&&!d_(n,l)&&console.error(sW(`${n}`,"Progress"));const c=d_(n,l)?n:null,f=Ru(c)?d(c,l):void 0;return r.jsx(ZH,{scope:s,value:c,max:l,children:r.jsx(c2.div,{"aria-valuemax":l,"aria-valuemin":0,"aria-valuenow":Ru(c)?c:void 0,"aria-valuetext":f,role:"progressbar","data-state":f2(c,l),"data-value":c??void 0,"data-max":l,...u,ref:t})})});d2.displayName=Bx;var u2="ProgressIndicator",h2=_.forwardRef((e,t)=>{const{__scopeProgress:s,...n}=e,o=eW(u2,s);return r.jsx(c2.div,{"data-state":f2(o.value,o.max),"data-value":o.value??void 0,"data-max":o.max,...n,ref:t})});h2.displayName=u2;function tW(e,t){return`${Math.round(e/t*100)}%`}function f2(e,t){return e==null?"indeterminate":e===t?"complete":"loading"}function Ru(e){return typeof e=="number"}function c_(e){return Ru(e)&&!isNaN(e)&&e>0}function d_(e,t){return Ru(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 \`${$x}\`.`}function sW(e,t){return`Invalid prop \`value\` of value \`${e}\` supplied to \`${t}\`. The \`value\` prop must be:
2992
2992
  - a positive number
2993
2993
  - less than the value passed to \`max\` (or ${$x} if no \`max\` prop is set)
2994
2994
  - \`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-RGj0_IWM.js"></script>
22
+ <script type="module" crossorigin src="/assets/index-BgXF4ZHQ.js"></script>
23
23
  <link rel="stylesheet" crossorigin href="/assets/index-BpOj57dd.css">
24
24
  </head>
25
25
  <body>