import{n as e}from"./chunk-DR8-3Aex.js";import{n as t,t as n}from"./memoize-DNnuA2aU.js";import{$ as r,In as i,Ln as a,t as o,v as s}from"./src-Di342QoJ.js";import{Cc as c,Gc as l,Sc as u,Uc as d,dc as f,lc as p,yc as m}from"./paths-Ci1iwL5Y.js";import{D as ee,E as te,K as h,O as ne,U as re,_ as ie,h as ae}from"./debug-otxXY3j-.js";import{n as oe,t as g}from"./cwd--iizewsn.js";import{a as se,n as _}from"./env-C2A9gV_G.js";import{o as v,s as y}from"./log-DSV4Ht5l.js";import{i as b,o as x}from"./platform-mh9ypxS8.js";import{r as S,t as C}from"./execFileNoThrow-azCkYhmF.js";import{d as ce,o as w,s as le}from"./types-KeqFPzY5.js";import{r as T,t as ue}from"./completionCache-C7hDqIDL.js";import{homedir as E,platform as D}from"os";import{dirname as de,join as O}from"path";import{randomBytes as k}from"crypto";import{copyFile as A,mkdir as j,readFile as M,stat as N,writeFile as P}from"fs/promises";import{pathToFileURL as fe}from"url";function F(){let e=ae().existsSync(O(g(),`CLAUDE.md`)),t=l(g());return[{key:`workspace`,text:`Ask Claude to create a new app or clone a repository`,isComplete:!1,isCompletable:!0,isEnabled:t},{key:`claudemd`,text:`Run /init to create a CLAUDE.md file with instructions for Claude`,isComplete:e,isCompletable:!0,isEnabled:!t}]}function I(){return F().filter(({isCompletable:e,isEnabled:t})=>e&&t).every(({isComplete:e})=>e)}function L(){p().hasCompletedProjectOnboarding||I()&&u(e=>({...e,hasCompletedProjectOnboarding:!0}))}function R(){u(e=>({...e,projectOnboardingSeenCount:e.projectOnboardingSeenCount+1}))}var z,B=e((()=>{n(),m(),oe(),d(),ie(),z=t(()=>{let e=p();return e.hasCompletedProjectOnboarding||e.projectOnboardingSeenCount>=4||process.env.IS_DEMO?!1:!I()})}));function pe(e){c(t=>({...t,appleTerminalSetupInProgress:!0,appleTerminalBackupPath:e}))}function V(){c(e=>({...e,appleTerminalSetupInProgress:!1}))}function me(){let e=f();return{inProgress:e.appleTerminalSetupInProgress??!1,backupPath:e.appleTerminalBackupPath||null}}function H(){return O(E(),`Library`,`Preferences`,`com.apple.Terminal.plist`)}async function he(){let e=H(),t=`${e}.bak`;try{let{code:n}=await C(`defaults`,[`export`,`com.apple.Terminal`,e]);if(n!==0)return null;try{await N(e)}catch{return null}return await C(`defaults`,[`export`,`com.apple.Terminal`,t]),pe(t),t}catch(e){return y(e),null}}async function U(){let{inProgress:e,backupPath:t}=me();if(!e)return{status:`no_backup`};if(!t)return V(),{status:`no_backup`};try{await N(t)}catch{return V(),{status:`no_backup`}}try{let{code:e}=await C(`defaults`,[`import`,`com.apple.Terminal`,t]);return e===0?(await C(`killall`,[`cfprefsd`]),V(),{status:`restored`}):{status:`failed`,backupPath:t}}catch(e){return y(Error(`Failed to restore Terminal.app settings with: ${e}`)),V(),{status:`failed`,backupPath:t}}}var W=e((()=>{m(),S(),v()}));function ge(){let e=process.env.VSCODE_GIT_ASKPASS_MAIN??``,t=process.env.PATH??``;return e.includes(`.vscode-server`)||e.includes(`.cursor-server`)||e.includes(`.windsurf-server`)||t.includes(`.vscode-server`)||t.includes(`.cursor-server`)||t.includes(`.windsurf-server`)}function _e(){return!_.terminal||!(_.terminal in $)?null:$[_.terminal]??null}function G(e){return r()?`\x1b]8;;${fe(e).href}\x07${e}\x1b]8;;\x07`:e}function K(){return D()===`darwin`&&_.terminal===`Apple_Terminal`||_.terminal===`vscode`||_.terminal===`cursor`||_.terminal===`windsurf`||_.terminal===`alacritty`||_.terminal===`zed`}async function q(e){let t=``;switch(_.terminal){case`Apple_Terminal`:t=await xe(e);break;case`vscode`:t=await Y(`VSCode`,e);break;case`cursor`:t=await Y(`Cursor`,e);break;case`windsurf`:t=await Y(`Windsurf`,e);break;case`alacritty`:t=await Se(e);break;case`zed`:t=await Ce(e);break;case null:break}return c(e=>[`vscode`,`cursor`,`windsurf`,`alacritty`,`zed`].includes(_.terminal??``)?e.shiftEnterKeyBindingInstalled===!0?e:{...e,shiftEnterKeyBindingInstalled:!0}:_.terminal===`Apple_Terminal`?e.optionAsMetaKeyInstalled===!0?e:{...e,optionAsMetaKeyInstalled:!0}:e),L(),process.env.USER_TYPE===`ant`&&(t+=await T(e)),t}function ve(){return f().shiftEnterKeyBindingInstalled===!0}function J(){return f().hasUsedBackslashReturn===!0}function ye(){f().hasUsedBackslashReturn||c(e=>({...e,hasUsedBackslashReturn:!0}))}async function be(e,t,n){if(_.terminal&&_.terminal in $)return e(`Shift+Enter is natively supported in ${$[_.terminal]}.

No configuration needed. Just use Shift+Enter to add newlines.`),null;if(!K()){let t=_.terminal||`your current terminal`,n=b(),r=``;return n===`macos`?r=`   • macOS: Apple Terminal
`:n===`windows`&&(r=`   • Windows: Windows Terminal
`),e(`Terminal setup cannot be run from ${t}.

This command configures a convenient Shift+Enter shortcut for multi-line prompts.
${i.dim(`Note: You can already use backslash (\\\\) + return to add newlines.`)}

To set up the shortcut (optional):
1. Exit tmux/screen temporarily
2. Run /terminal-setup directly in one of these terminals:
${r}   • IDE: VSCode, Cursor, Windsurf, Zed
   • Other: Alacritty
3. Return to tmux/screen - settings will persist

${i.dim(`Note: iTerm2, WezTerm, Ghostty, Kitty, and Warp support Shift+Enter natively.`)}`),null}return e(await q(t.options.theme)),null}async function Y(e=`VSCode`,t){if(ge())return`${s(`warning`,t)(`Cannot install keybindings from a remote ${e} session.`)}${Q}${Q}${e} keybindings must be installed on your local machine, not the remote server.${Q}${Q}To install the Shift+Enter keybinding:${Q}1. Open ${e} on your local machine (not connected to remote)${Q}2. Open the Command Palette (Cmd/Ctrl+Shift+P) → "Preferences: Open Keyboard Shortcuts (JSON)"${Q}3. Add this keybinding (the file must be a JSON array):${Q}${Q}${i.dim(`[
  {
    "key": "shift+enter",
    "command": "workbench.action.terminal.sendSequence",
    "args": { "text": "\\u001b\\r" },
    "when": "terminalFocus"
  }
]`)}${Q}`;let n=e===`VSCode`?`Code`:e,r=O(E(),D()===`win32`?O(`AppData`,`Roaming`,n,`User`):D()===`darwin`?O(`Library`,`Application Support`,n,`User`):O(`.config`,n,`User`)),a=O(r,`keybindings.json`);try{await j(r,{recursive:!0});let n=`[]`,o=[],c=!1;try{n=await M(a,{encoding:`utf-8`}),c=!0,o=ce(n)??[]}catch(e){if(!h(e))throw e}if(c){let n=`${a}.${k(4).toString(`hex`)}.bak`;try{await A(a,n)}catch{return`${s(`warning`,t)(`Error backing up existing ${e} terminal keybindings. Bailing out.`)}${Q}${i.dim(`See ${G(a)}`)}${Q}${i.dim(`Backup path: ${G(n)}`)}${Q}`}}return o.find(e=>e.key===`shift+enter`&&e.command===`workbench.action.terminal.sendSequence`&&e.when===`terminalFocus`)?`${s(`warning`,t)(`Found existing ${e} terminal Shift+Enter key binding. Remove it to continue.`)}${Q}${i.dim(`See ${G(a)}`)}${Q}`:(await P(a,w(n,{key:`shift+enter`,command:`workbench.action.terminal.sendSequence`,args:{text:`\x1B\r`},when:`terminalFocus`}),{encoding:`utf-8`}),`${s(`success`,t)(`Installed ${e} terminal Shift+Enter key binding`)}${Q}${i.dim(`See ${G(a)}`)}${Q}`)}catch(t){throw y(t),Error(`Failed to install ${e} terminal Shift+Enter key binding`)}}async function X(e){let{code:t}=await C(`/usr/libexec/PlistBuddy`,[`-c`,`Add :'Window Settings':'${e}':useOptionAsMetaKey bool true`,H()]);if(t!==0){let{code:t}=await C(`/usr/libexec/PlistBuddy`,[`-c`,`Set :'Window Settings':'${e}':useOptionAsMetaKey true`,H()]);if(t!==0)return y(Error(`Failed to enable Option as Meta key for Terminal.app profile: ${e}`)),!1}return!0}async function Z(e){let{code:t}=await C(`/usr/libexec/PlistBuddy`,[`-c`,`Add :'Window Settings':'${e}':Bell bool false`,H()]);if(t!==0){let{code:t}=await C(`/usr/libexec/PlistBuddy`,[`-c`,`Set :'Window Settings':'${e}':Bell false`,H()]);if(t!==0)return y(Error(`Failed to disable audio bell for Terminal.app profile: ${e}`)),!1}return!0}async function xe(e){try{if(!await he())throw Error(`Failed to create backup of Terminal.app preferences, bailing out`);let{stdout:t,code:n}=await C(`defaults`,[`read`,`com.apple.Terminal`,`Default Window Settings`]);if(n!==0||!t.trim())throw Error(`Failed to read default Terminal.app profile`);let{stdout:r,code:a}=await C(`defaults`,[`read`,`com.apple.Terminal`,`Startup Window Settings`]);if(a!==0||!r.trim())throw Error(`Failed to read startup Terminal.app profile`);let o=!1,c=t.trim(),l=await X(c),u=await Z(c);(l||u)&&(o=!0);let d=r.trim();if(d!==c){let e=await X(d),t=await Z(d);(e||t)&&(o=!0)}if(!o)throw Error(`Failed to enable Option as Meta key or disable audio bell for any Terminal.app profile`);return await C(`killall`,[`cfprefsd`]),V(),`${s(`success`,e)(`Configured Terminal.app settings:`)}${Q}${s(`success`,e)(`- Enabled "Use Option as Meta key"`)}${Q}${s(`success`,e)(`- Switched to visual bell`)}${Q}${i.dim(`Option+Enter will now enter a newline.`)}${Q}${i.dim(`You must restart Terminal.app for changes to take effect.`,e)}${Q}`}catch(e){y(e);let t=await U(),n=`Failed to enable Option as Meta key for Terminal.app.`;throw t.status===`restored`?Error(`${n} Your settings have been restored from backup.`):t.status===`failed`?Error(`${n} Restoring from backup failed, try manually with: defaults import com.apple.Terminal ${t.backupPath}`):Error(`${n} No backup was available to restore from.`)}}async function Se(e){let t=[],n=process.env.XDG_CONFIG_HOME;if(n?t.push(O(n,`alacritty`,`alacritty.toml`)):t.push(O(E(),`.config`,`alacritty`,`alacritty.toml`)),D()===`win32`){let e=process.env.APPDATA;e&&t.push(O(e,`alacritty`,`alacritty.toml`))}let r=null,a=``,o=!1;for(let e of t)try{a=await M(e,{encoding:`utf-8`}),r=e,o=!0;break}catch(e){if(!h(e))throw e}if(r||(r=t[0]??null),!r)throw Error(`No valid config path found for Alacritty`);try{if(o){if(a.includes(`mods = "Shift"`)&&a.includes(`key = "Return"`))return`${s(`warning`,e)(`Found existing Alacritty Shift+Enter key binding. Remove it to continue.`)}${Q}${i.dim(`See ${G(r)}`)}${Q}`;let t=k(4).toString(`hex`),n=`${r}.${t}.bak`;try{await A(r,n)}catch{return`${s(`warning`,e)(`Error backing up existing Alacritty config. Bailing out.`)}${Q}${i.dim(`See ${G(r)}`)}${Q}${i.dim(`Backup path: ${G(n)}`)}${Q}`}}else await j(de(r),{recursive:!0});let t=a;return a&&!a.endsWith(`
`)&&(t+=`
`),t+=`
[[keyboard.bindings]]
key = "Return"
mods = "Shift"
chars = "\\u001B\\r"
`,await P(r,t,{encoding:`utf-8`}),`${s(`success`,e)(`Installed Alacritty Shift+Enter key binding`)}${Q}${s(`success`,e)(`You may need to restart Alacritty for changes to take effect`)}${Q}${i.dim(`See ${G(r)}`)}${Q}`}catch(e){throw y(e),Error(`Failed to install Alacritty Shift+Enter key binding`)}}async function Ce(e){let t=O(E(),`.config`,`zed`),n=O(t,`keymap.json`);try{await j(t,{recursive:!0});let r=`[]`,a=!1;try{r=await M(n,{encoding:`utf-8`}),a=!0}catch(e){if(!h(e))throw e}if(a){if(r.includes(`shift-enter`))return`${s(`warning`,e)(`Found existing Zed Shift+Enter key binding. Remove it to continue.`)}${Q}${i.dim(`See ${G(n)}`)}${Q}`;let t=`${n}.${k(4).toString(`hex`)}.bak`;try{await A(n,t)}catch{return`${s(`warning`,e)(`Error backing up existing Zed keymap. Bailing out.`)}${Q}${i.dim(`See ${G(n)}`)}${Q}${i.dim(`Backup path: ${G(t)}`)}${Q}`}}let o;try{o=ee(r),Array.isArray(o)||(o=[])}catch{o=[]}return o.push({context:`Terminal`,bindings:{"shift-enter":[`terminal::SendText`,`\x1B\r`]}}),await P(n,ne(o,null,2)+`
`,{encoding:`utf-8`}),`${s(`success`,e)(`Installed Zed Shift+Enter key binding`)}${Q}${i.dim(`See ${G(n)}`)}${Q}`}catch(e){throw y(e),Error(`Failed to install Zed Shift+Enter key binding`)}}var Q,$,we=e((()=>{a(),o(),B(),W(),ue(),m(),se(),re(),S(),le(),v(),x(),te(),Q=`
`,$={ghostty:`Ghostty`,kitty:`Kitty`,"iTerm.app":`iTerm2`,WezTerm:`WezTerm`,WarpTerminal:`Warp`}}));export{ve as a,K as c,F as d,R as f,z as h,we as i,U as l,L as m,_e as n,ye as o,B as p,J as r,q as s,be as t,W as u};