import{n as e}from"./rolldown-runtime-BG2f4sTM.js";import{Dvt as t,Ic as n,Lc as r,Mvt as i,Tft as a,c9 as o,ddt as s,jq as c,l9 as l,mV as u,pV as d,udt as f,wft as p}from"./app-initial-BHB6SClA.js";function m({pendingWorktree:e,isConversationStarting:t,isConversationStartFailed:n}){let r=e.worktreeGitRoot!=null&&e.worktreeWorkspaceRoot!=null,i=[{id:`${e.id}:${e.attempt}:worktree`,kind:`worktree`,status:h(e.phase,r),outputText:e.worktreeOutputText}],a=g(e,r);return a!=null&&i.push({id:`${e.id}:${e.attempt}:setup`,kind:`setup`,status:a,outputText:e.setupOutputText}),(t||n)&&i.push({id:`${e.id}:${e.attempt}:conversation`,kind:`conversation`,status:n?`failed`:`running`,outputText:``}),i}function h(e,t){switch(e){case`queued`:case`creating`:return`running`;case`setting-up`:case`worktree-ready`:return`completed`;case`failed`:return t?`completed`:`failed`}}function g(e,t){switch(e.phase){case`queued`:case`creating`:return null;case`setting-up`:return`running`;case`worktree-ready`:return e.localEnvironmentConfigPath==null?null:e.errorMessage==null?`completed`:`skipped`;case`failed`:return t?`failed`:null}}var _=e((()=>{}));function v(e){let t=(0,y.c)(7),{pendingWorktree:r,isConversationStarting:i,isConversationStartFailed:a,children:o}=e,s;t[0]!==a||t[1]!==i||t[2]!==r?(s=m({pendingWorktree:r,isConversationStarting:i,isConversationStartFailed:a}),t[0]=a,t[1]=i,t[2]=r,t[3]=s):s=t[3];let c;return t[4]!==o||t[5]!==s?(c=(0,b.jsx)(n,{activities:s,children:o}),t[4]=o,t[5]=s,t[6]=c):c=t[6],c}var y,b,x=e((()=>{y=i(),r(),_(),b=t()}));async function S({createPendingWorktree:e,intl:t,pendingWorktree:n,serviceTier:r}){let i=w(n,t),a=await C(n,i,r),o=t.formatMessage({id:`worktreeInitV2.autoFix.label`,defaultMessage:`Fix worktree setup`,description:`Pending worktree label for a repair thread created after local environment setup fails`});return d(e,{hostId:n.hostId,label:o,initialThreadTitle:o,sourceWorkspaceRoot:n.sourceWorkspaceRoot,startingState:n.startingState,localEnvironmentConfigPath:null,launchMode:`start-conversation`,prompt:i,startConversationParamsInput:a,sourceConversationId:null,sourceCollaborationMode:null})}async function C(e,t,n){let r=[{type:`text`,text:t,text_elements:[]}];if(e.launchMode===`start-conversation`)return{...e.startConversationParamsInput,input:r,commentAttachments:[],workspaceRoots:[e.sourceWorkspaceRoot],cwd:e.sourceWorkspaceRoot,fileAttachments:[],addedFiles:[],threadSource:`system`,serviceTier:n};let{config:i}=await s(`read-config-for-host`,{hostId:e.hostId,includeLayers:!1,cwd:e.sourceWorkspaceRoot,priority:`critical`});return{input:r,commentAttachments:[],workspaceRoots:[e.sourceWorkspaceRoot],cwd:e.sourceWorkspaceRoot,fileAttachments:[],addedFiles:[],agentMode:p(`agent-mode-by-host-id`,{})[e.hostId]??`auto`,shouldSendPermissionOverrides:!0,model:null,serviceTier:n,reasoningEffort:null,collaborationMode:e.launchMode===`fork-conversation`?e.sourceCollaborationMode:null,config:o(i),threadSource:`system`,workspaceKind:`project`}}function w(e,t){return t.formatMessage({id:`worktreeInitV2.autoFix.prompt`,defaultMessage:"Fix this project's local environment setup.{paragraphBreak}The original worktree setup failed before its thread could start. Do not continue the original user request. Start a one-off repair task in this new worktree without running the broken setup automatically. Paths in the failure output refer to the original source or failed worktree, so edit the corresponding files in this current repair worktree. Inspect the selected local environment config and related setup files, reproduce the failure manually if useful, make the smallest source-controlled fix, verify the setup succeeds, and leave the proposed fix here for user review before they retry the original task. If the fix should not be made automatically, explain exactly what the user should change.{paragraphBreak}Selected local environment config: {configPath}{lineBreak}Original setup error: {errorMessage}{paragraphBreak}Original setup output:{lineBreak}```text{lineBreak}{outputText}{lineBreak}```",description:`Prompt sent to a repair thread created after local environment setup fails`},{configPath:e.localEnvironmentConfigPath??``,errorMessage:e.errorMessage??``,lineBreak:`
`,outputText:e.setupOutputText,paragraphBreak:`

`})}var T=e((()=>{f(),l(),c(),a(),u()}));export{x as i,T as n,v as r,S as t};
//# sourceMappingURL=worktree-setup-auto-fix-FBjTPkPf.js.map