import{n as e}from"./chunk-DR8-3Aex.js";import{Rn as t,b as n,t as r,x as i}from"./src-Di342QoJ.js";import{t as a}from"./jsx-runtime-D-D469L8.js";import{Bm as o,By as s,Fm as c,Hm as l,Im as u,KO as d,Lm as f,Mm as p,Nm as m,Pm as h,Um as g,Wm as _,ZO as v,aS as y,cd as b,od as x,sd as S,zm as C}from"./loadAgentsDir-C_wFhytF.js";import{n as w,t as T}from"./PermissionDialog-_WQPRYHQ.js";function E({currentGoal:e,newObjective:t,onConfirm:r,onCancel:a}){function o(e){e===`yes`?r():a()}let s=e.tokenBudget===null?`${e.tokensUsed}`:`${e.tokensUsed} / ${e.tokenBudget}`;return(0,D.jsx)(T,{color:`warning`,title:`Replace active goal?`,children:(0,D.jsxs)(i,{flexDirection:`column`,marginTop:1,paddingX:1,children:[(0,D.jsx)(n,{children:`A goal is already in progress. Replacing it will reset all progress and counters.`}),(0,D.jsxs)(i,{marginTop:1,flexDirection:`column`,children:[(0,D.jsx)(n,{dimColor:!0,children:`Current goal:`}),(0,D.jsxs)(n,{children:[(0,D.jsx)(n,{dimColor:!0,children:`· Objective: `}),e.objective]}),(0,D.jsxs)(n,{children:[(0,D.jsx)(n,{dimColor:!0,children:`· Status: `}),u(e.status)]}),(0,D.jsxs)(n,{children:[(0,D.jsx)(n,{dimColor:!0,children:`· Time: `}),c(e)]}),(0,D.jsxs)(n,{children:[(0,D.jsx)(n,{dimColor:!0,children:`· Tokens: `}),s]})]}),(0,D.jsxs)(i,{marginTop:1,flexDirection:`column`,children:[(0,D.jsx)(n,{dimColor:!0,children:`New objective:`}),(0,D.jsx)(n,{children:t})]}),(0,D.jsx)(i,{marginTop:1,children:(0,D.jsx)(y,{options:[{label:`Yes, replace the goal`,value:`yes`},{label:`No, keep the current goal`,value:`no`}],onChange:o,onCancel:a})})]})})}var D,O=e((()=>{t(),r(),s(),w(),o(),D=a()}));function k(e){let t=e.split(`
`)[0]??e;return t.length<=I?t:t.slice(0,I)+`…`}function A(){v(e=>e.origin===`goal-continuation`||e.origin===`goal-budget-limit`)}function j(){let e=f();if(!e)return"No active goal. Set one with `/goal <objective>`.";let t=e.tokenBudget===null?`${e.tokensUsed}`:`${e.tokensUsed} / ${e.tokenBudget}`,n=[`Goal: ${e.objective}`,`Status: ${u(e.status)}`,`Time: ${c(e)}`,`Tokens: ${t}`,`Continuation turns: ${e.turnsExecuted}`];return e.status===`max_turns`&&n.push("Hint: Max continuation turns reached (150). Run `/goal continue` to reset and continue."),n.join(`
`)}function M(e){return _(e),C(),S(),`Goal set.`}async function N(e,t,n){let r=n.trim();if(!r||r.toLowerCase()===`status`)return e(j(),{display:`system`}),null;let i=r.toLowerCase();if(i===`clear`){let t=p();return t&&(b(),A()),e(t?`Goal cleared.`:`No active goal to clear.`,{display:`system`}),null}if(i===`pause`){let t=l();return t&&(S(),A()),e(t?`Goal paused.`:`No active goal to pause.`,{display:`system`}),null}if(i===`resume`){if(f()?.status===`max_turns`)return e("Goal reached max continuation turns (150). Run `/goal continue` to reset turn counter and continue.",{display:`system`}),null;let t=g();return t&&S(),e(t?`Goal resumed.`:`No paused goal to resume.`,{display:`system`,shouldQuery:!!t}),null}if(i===`continue`){let t=h();return t&&S(),e(t?`Goal continuation counter reset (0/150). Continuing...`:`Current goal is not in max-turns state.`,{display:`system`,shouldQuery:!!t}),null}if(i===`complete`){let t=m();return t&&(S(),A()),e(t?`Goal marked complete.`:`No active goal to complete.`,{display:`system`}),null}if(r.length>F)return e(`Goal objective is too long (${r.length} chars; limit ${F}). Save the detailed instructions to a file and reference it from a shorter objective.`,{display:`system`}),null;let a=f();return a&&a.status!==`complete`?(0,P.jsx)(E,{currentGoal:a,newObjective:r,onConfirm:()=>{A(),e(M(r),{display:`system`,shouldQuery:!0,displayArgs:k(r),metaMessages:[`<goal-objective-updated>\n${r}\n</goal-objective-updated>`]})},onCancel:()=>{e(`Kept the current goal. New objective discarded.`,{display:`system`})}}):(e(M(r),{display:`system`,shouldQuery:!0,displayArgs:k(r),metaMessages:[`<goal-objective-updated>\n${r}\n</goal-objective-updated>`]}),null)}var P,F,I;e((()=>{t(),o(),x(),d(),O(),P=a(),F=4e3,I=80}))();export{N as call};