@stackone/cli 1.43.1 → 1.43.2

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/dist/cli.cjs CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- const e=require(`./agentConfig-KBkYYmMr.cjs`),t=require(`./cliCore-mMrBxsVZ.cjs`);require(`./setupMigration-rqPZ8MV6.cjs`),require(`./agentApiKey-BDp7EFMI.cjs`);let n=require(`dotenv`);process.env.DOTENV_CONFIG_QUIET=`true`,(0,n.config)(),new t.t().run();
2
+ const e=require(`./agentConfig-KBkYYmMr.cjs`),t=require(`./cliCore-_XY0Dk5a.cjs`);require(`./setupMigration-rqPZ8MV6.cjs`),require(`./agentApiKey-BDp7EFMI.cjs`);let n=require(`dotenv`);process.env.DOTENV_CONFIG_QUIET=`true`,(0,n.config)(),new t.t().run();
package/dist/cli.mjs CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- import{t as e}from"./cliCore-CeD5mOhR.mjs";import"./agentConfig-BWQWMYKQ.mjs";import"./setupMigration-C1ShGzOu.mjs";import"./agentApiKey-CWXxJgCO.mjs";import{config as t}from"dotenv";process.env.DOTENV_CONFIG_QUIET=`true`,t(),new e().run();export{};
2
+ import{t as e}from"./cliCore-Dkwrx11F.mjs";import"./agentConfig-BWQWMYKQ.mjs";import"./setupMigration-C1ShGzOu.mjs";import"./agentApiKey-CWXxJgCO.mjs";import{config as t}from"dotenv";process.env.DOTENV_CONFIG_QUIET=`true`,t(),new e().run();export{};
@@ -138,8 +138,8 @@ Error: `+(e instanceof Error?e.message:String(e)))),process.exit(1)}c?.stop(),y.
138
138
  `))}async executeOrchestratedBuild(e){let{provider:t,category:n,verbose:r}=e,i=n?` (${n})`:``;y.log(T.bold(`\nOrchestrated build: ${t}${i}\n`));let a=null,o=new Map;try{for await(let t of Ut(e))switch(t.type){case`phase_start`:{let e=Sn[t.phase]||`${t.phase}...`,n=t.model?T.dim(` (${dt(t.model)})`):``;a?.stop(),a=J(T.cyan(`[${t.phase}]${n} ${e}`)).start(),o.set(t.phase,Date.now());break}case`phase_complete`:{let e=o.get(t.phase),n=e===void 0?0:Math.round((Date.now()-e)/1e3);a?.succeed(T.green(`[${t.phase}] Done (${n}s)`)),a=null;break}case`phase_error`:a?.fail(T.red(`[${t.phase}] ${t.error}`)),a=null;break;case`agent_message`:wn(t,a,r);break}}catch(e){a?.fail(),y.error(T.red(`
139
139
  Error: `+(e instanceof Error?e.message:String(e)))),process.exit(1)}a?.stop(),y.log(T.green(`
140
140
  ✓ Build complete
141
- `))}};const wn=(e,t,n)=>{let r=e.message;switch(r.type){case`text`:n&&process.stdout.write(r.content??``);break;case`tool_call`:{let n=r.toolName??`unknown tool`;t&&(t.text=T.cyan(`[${e.phase}] Tool: ${n}`));break}case`tool_error`:y.error(T.red(`\n[${e.phase}] Tool error (${r.toolName}): ${r.error??`Unknown error`}`));break;case`error`:y.error(T.red(`\n[${e.phase}] ${r.error??`Unknown error`}`));break;default:break}};function Tn(e,t){switch(e.type){case`text`:t(null),process.stdout.write(e.content??``);break;case`tool_call`:{let n=e.toolName??`unknown tool`;t(J(T.cyan(`Tool: ${n}`)).start());break}case`tool_result`:t(null);break;case`tool_progress`:{let n=e.progress?.operation||e.toolName||`Working...`;t(J(T.cyan(`Tool: ${n}`)).start());break}case`tool_error`:t(null),y.error(T.red(`\nTool error (${e.toolName}): ${e.error??`Unknown error`}`));break;case`error`:t(null),y.error(T.red(`\n${e.error??`Unknown error`}`));break;case`done`:t(null);break;default:process.env.VERBOSE&&console.warn(`[AgentRun] Unknown message type:`,e.type);break}}const En=e=>{let t=e.trim();return t===`~`?I():t.startsWith(`~/`)?R(I(),t.slice(2)):t},Dn=(e,t,n)=>e?`global`:t?`local`:n?null:`global`,On=(e,t)=>e?.trim()||(t?null:process.cwd()),kn=e=>e.existingConfig?`overwrite`:An(e),An=e=>e.mode===`local`&&e.alreadyAuthed?`work`:`auth`,jn=(e,t)=>{switch(e){case`mode`:return t.mode===`local`?t.hasGit?`repo-confirm`:`path-input`:kn(t);case`repo-confirm`:return t.repoAccepted?kn(t):`path-input`;case`path-input`:return kn(t);case`overwrite`:return An(t);case`auth`:return`work`;default:return`done`}},Mn=(e,t)=>Te(`git`,[`-C`,e,...t],{encoding:`utf-8`,stdio:[`ignore`,`pipe`,`ignore`]}).trim(),Nn=e=>{try{let t=Mn(e,[`rev-parse`,`--show-toplevel`]);if(!t)return null;let n;try{n=Mn(e,[`remote`,`get-url`,`origin`])||void 0}catch{}return{root:t,remoteUrl:n}}catch{return null}},Pn=`connector-guide.md`,Fn=`<!-- BEGIN stackone-connector-guide -->`,In=`<!-- END stackone-connector-guide -->`,Ln=/^[a-z0-9][a-z0-9_-]*$/,Rn=e=>e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),zn=e=>`<!-- Generated by \`stackone agent sync\` from @stackone/agent-harness@${e}. Edit upstream, not here. -->`,Bn=e=>{if(e.includes(`..`)||!Ln.test(e))throw Error(`Refusing unsafe path segment: ${JSON.stringify(e)}`)},Vn=e=>{let t=e.split(`/`);if(t.length===0)throw Error(`Refusing empty path: ${JSON.stringify(e)}`);for(let e of t)Bn(e)},Hn=(e,...t)=>{let n=_e(e),r=_e(n,...t);if(r!==n&&!r.startsWith(n+ve))throw Error(`Refusing path outside ${n}: ${r}`);return r},Un=(e,...t)=>de(Hn(e,...t),`utf-8`),Wn=(e,...t)=>de(Hn(e,...t)),Gn=()=>{let e=w(import.meta.url).resolve(`@stackone/agent-harness`),t=ge(e);for(let e=0;e<6;e++){if(N(R(t,`package.json`))&&N(R(t,`plugin`)))return t;let e=ge(t);if(e===t)break;t=e}return ge(ge(e))},Kn=()=>R(Gn(),`plugin`),qn=e=>{try{let t=e?_e(e,`..`):Gn();return JSON.parse(Un(t,`package.json`)).version??`unknown`}catch{return`unknown`}},Jn=e=>{let t=e.charCodeAt(0)===65279?e.slice(1):e,n=t.match(/^---\n[\s\S]*?\n---\n?/);return n&&(t=t.slice(n[0].length)),t=t.replace(/^\s*<!--[\s\S]*?-->\s*/,``),t.trim()},Yn=(e,t,n)=>{let r=[Fn,zn(n),``,t,``,In].join(`
142
- `);if(e.includes(Fn)&&e.includes(In)){let t=RegExp(`${Rn(Fn)}[\\s\\S]*?${Rn(In)}`);return e.replace(t,r)}let i=e.replace(/\s*$/,``);return i.length>0?`${i}\n\n${r}\n`:`${r}\n`},Xn=e=>{let t=[];for(let n of P(e,{withFileTypes:!0}))if(n.isDirectory()){let r=Xn(Hn(e,n.name));t.push(...r.map(e=>R(n.name,e)))}else t.push(n.name);return t},Zn=(e,t)=>{if(!N(t))return!1;let n=Xn(e).sort(),r=Xn(t).sort();return n.length!==r.length||n.some((e,t)=>e!==r[t])?!1:n.every(n=>Wn(e,n).equals(Wn(t,n)))},Qn=(e,t)=>{fe(t,{recursive:!0,force:!0}),ue(ge(t),{recursive:!0}),le(e,t,{recursive:!0})},$n=(e,t=``)=>{if(!N(e))return[];let n=[];for(let r of P(e,{withFileTypes:!0})){if(!r.isDirectory()||!Ln.test(r.name))continue;let i=t?`${t}/${r.name}`:r.name;if(N(Hn(e,r.name,`SKILL.md`))){n.push(i);continue}n.push(...$n(Hn(e,r.name),i))}return n.sort()},er=()=>({changed:[],unchanged:[],missing:[]}),tr=(e,t,n,r)=>{let i=er();for(let a of e){Vn(a);let e=Hn(t,a);if(!N(e)||!pe(e).isDirectory()){i.missing.push(a);continue}let o=Hn(n,a);if(Zn(e,o)){i.unchanged.push(a);continue}i.changed.push(a),r||Qn(e,o)}return i},nr=(e,t,n,r)=>{if(!N(Hn(e,Pn)))return`missing-source`;let i=Jn(Un(e,Pn)),a=Hn(t,`CLAUDE.md`),o=N(a)?Un(t,`CLAUDE.md`):``,s=Yn(o,i,n);return s===o?`unchanged`:(r||me(a,s),`changed`)},rr=e=>{let t=_e(e.pluginDir??Kn()),n=_e(e.cwd),r=e.version??qn(t),i=e.check??!1,a=Hn(n,`.claude`),o=Hn(t,`skills`),s=tr($n(o),o,Hn(a,`skills`),i),c=nr(t,n,r,i),l=s.changed.length>0||c===`changed`,u=c!==`missing-source`||s.changed.length+s.unchanged.length>0;if(!i&&u){ue(a,{recursive:!0});let e={harnessVersion:r,skills:s.changed.concat(s.unchanged).sort(),guide:c!==`missing-source`};me(Hn(a,`.stackone-connector-env.json`),`${JSON.stringify(e,null,2)}\n`)}return{skills:s,guide:c,hasChanges:l}},ir=e=>{try{let t=e??Kn();return pe(t).isDirectory()?e?JSON.parse(Un(_e(t,`..`),`package.json`)).name===`@stackone/agent-harness`:!0:!1}catch{return!1}},ar=({message:e,choices:t,initialIndex:n=0,onSelect:r,onCancel:i})=>{let[a,o]=G(()=>t.length?Math.min(Math.max(n,0),t.length-1):0);return V((e,n)=>{if(t.length===0){n.escape&&i?.();return}n.upArrow?o(e=>(e-1+t.length)%t.length):n.downArrow?o(e=>(e+1)%t.length):n.return?r(t[a].value):n.escape&&i?.()}),t.length===0?null:H.createElement(z,{flexDirection:`column`,paddingY:1},H.createElement(z,{borderStyle:`round`,borderColor:`cyan`,flexDirection:`column`,paddingX:2,paddingY:1},H.createElement(B,{bold:!0},e),H.createElement(z,{flexDirection:`column`,marginTop:1},t.map((e,t)=>H.createElement(B,{key:e.value,color:t===a?`#00af66`:`white`},t===a?`❯ `:` `,e.label)))),H.createElement(z,{marginTop:1},H.createElement(B,{dimColor:!0},`↑↓ to navigate • Enter to select`)))},or=({message:e,initialValue:t=``,validate:n,onSubmit:r,onCancel:i})=>{let[a,o]=G(t),[s,c]=G(null);return V((e,t)=>{if(t.return){let e=n?n(a):!0;e===!0?r(a):c(e);return}if(t.escape){i?.();return}if(t.backspace||t.delete){o(e=>e.slice(0,-1)),c(null);return}e&&!t.ctrl&&!t.meta&&!t.tab&&!t.upArrow&&!t.downArrow&&(o(t=>t+e),c(null))}),H.createElement(z,{flexDirection:`column`,paddingY:1},H.createElement(B,{bold:!0},e),H.createElement(z,{marginTop:1},H.createElement(B,null,`> `),H.createElement(B,null,a),H.createElement(B,{inverse:!0},` `)),s&&H.createElement(z,{marginTop:1},H.createElement(B,{color:`red`},s)),H.createElement(z,{marginTop:1},H.createElement(B,{dimColor:!0},`Enter to submit • Esc to cancel`)))},sr=e=>N(`${e}/CLAUDE.md`)||N(`${e}/.mcp.json`),cr=e=>{try{return pe(e).isDirectory()}catch{return!1}},lr=({initialMode:e,pathFlag:t,startDir:n,onExit:r})=>{let[i,o]=G(`mode`),[c,u]=G(null),[f,p]=G(!1),[h,g]=G([]),[v,y]=G(``),[b,x]=G(e),[C,te]=G(``),[w,T]=G(``),[E,ne]=G(!1),[D,re]=G(null),ie=W(0),ae=xe(e=>{ie.current+=1;let t=ie.current;g(n=>[...n,{...e,id:t}])},[]),O=xe(e=>{u(e)},[]),oe=xe(async e=>{let t=_e(En(e));if(!cr(t)){O({status:`error`,message:N(t)?`Target path is not a directory: ${t}`:`Target path does not exist: ${t}`});return}te(t);let n=sr(t),r=d(await ee());ne(r),o(jn(`path-input`,{mode:`local`,hasGit:!1,repoAccepted:!1,existingConfig:n,alreadyAuthed:r}))},[O]),se=xe(e=>{if(x(e),e===`local`){let e=t?.trim();if(e){oe(e);return}let r=Nn(n);r&&(T(`Install the connector setup into this repo? ${r.remoteUrl?`${r.remoteUrl} (${r.root})`:r.root}`),te(r.root)),o(jn(`mode`,{mode:`local`,hasGit:!!r,repoAccepted:!1,existingConfig:!1,alreadyAuthed:!1}));return}o(jn(`mode`,{mode:`global`,hasGit:!1,repoAccepted:!1,existingConfig:sr(n),alreadyAuthed:!1}))},[t,n,oe]);U(()=>{e&&se(e)},[]);let k=xe(e=>{e?oe(C):o(`path-input`)},[oe,C]),A=xe(e=>{if(!e){O({status:`cancelled`});return}o(jn(`overwrite`,{mode:b??`global`,hasGit:!1,repoAccepted:!1,existingConfig:!0,alreadyAuthed:E}))},[b,E,O]);return U(()=>{if(i!==`auth`)return;let e=!1;return y(`Starting browser authentication…`),vn(t=>{e||y(t)}).then(t=>{e||(re(t),ae({icon:`✓`,text:t.email?`Authenticated as ${t.email}`:`Authenticated`,color:Q.success}),o(`work`))}).catch(t=>{e||O({status:`error`,message:t instanceof Error?t.message:`Authentication failed`})}),()=>{e=!0}},[i,ae,O]),U(()=>{if(i!==`work`)return;let e=!1;return(async()=>{try{let t=D??await ee();if(!t)throw Error(`Not authenticated — no API key found`);let r=await S(b===`local`?C:n,t.apiKey);if(r.migrated&&ae({icon:`✓`,text:`Migrated ${r.actions.length} item(s) from a previous setup`,color:Q.success}),b===`local`){y(`Creating .mcp.json…`),l(m(C),s(),t.apiKey),ae({icon:`✓`,text:`Created .mcp.json`,color:Q.success}),y(`Syncing connector-building skills + guide…`);let e=rr({cwd:C});ae({icon:`✓`,text:`Connector environment ready (${e.skills.changed.length+e.skills.unchanged.length} skills in .claude/, ${e.guide===`missing-source`?`guide unavailable in this version`:`guide in CLAUDE.md`})`,color:Q.success})}else y(`Installing global MCP configuration…`),l(a(),_(),t.apiKey),ae({icon:`✓`,text:`Installed to Claude (global)`,color:Q.success});if(e)return;y(``),O({status:`done`})}catch(t){if(e)return;O({status:`error`,message:t instanceof Error?t.message:`Setup failed`})}})(),()=>{e=!0}},[i,D,b,C,n,ae,O]),U(()=>{if(!c)return;let e=setTimeout(()=>r(c),60);return()=>clearTimeout(e)},[c,r]),H.createElement(z,{flexDirection:`column`,padding:1},f?H.createElement(Ct,{wordmark:!0}):H.createElement(Tt,{ready:!0,onComplete:()=>p(!0)}),h.length>0&&H.createElement(z,{flexDirection:`column`,marginTop:1},h.map(e=>H.createElement(B,{key:e.id,color:e.color},e.icon?`${e.icon} `:``,e.text))),H.createElement(z,{marginTop:1},(()=>{if(c)return c.status===`error`?H.createElement(B,{color:Q.error},`✗ `,c.message??`Setup failed`):c.status===`cancelled`?H.createElement(B,{color:Q.dim},`Setup cancelled.`):H.createElement(z,{flexDirection:`column`},H.createElement(B,{color:Q.success},`✓ Setup complete!`),H.createElement(z,{marginTop:1,flexDirection:`column`},H.createElement(B,{color:Q.dim},`Verify with `,H.createElement(B,{color:Q.primary},`claude mcp list`)),H.createElement(B,{color:Q.dim},`Tip: run`,` `,H.createElement(B,{color:Q.primary},`claude --dangerously-skip-permissions`),` `,`to skip permission prompts`),b===`local`&&H.createElement(B,{color:Q.dim},`Refresh skills anytime with`,` `,H.createElement(B,{color:Q.primary},`stackone agent sync`))));switch(i){case`mode`:return e?null:H.createElement(ar,{message:`How do you want to set up the StackOne agent?`,initialIndex:0,choices:[{label:`Local — this project: auth + .mcp.json + connector skills (.claude/) + guide (CLAUDE.md)`,value:`local`},{label:`Global — any repo: auth + global MCP only (no connector skills/guide)`,value:`global`}],onSelect:e=>se(e),onCancel:()=>O({status:`cancelled`})});case`repo-confirm`:return H.createElement(ar,{message:w,initialIndex:0,choices:[{label:`Yes`,value:`yes`},{label:`No, let me choose a path`,value:`no`}],onSelect:e=>k(e===`yes`),onCancel:()=>O({status:`cancelled`})});case`path-input`:return H.createElement(or,{message:`Path to install the connector setup into:`,initialValue:n,validate:e=>{let t=En(e)||n;return N(t)?cr(t)?!0:`Path is not a directory: ${t}`:`Path does not exist: ${t}`},onSubmit:e=>void oe(e.trim()||n),onCancel:()=>O({status:`cancelled`})});case`overwrite`:{let e=b===`local`;return H.createElement(ar,{message:e?`Existing setup found in ${C}. Overwrite it?`:`Local setup detected in ${n} (it won't be modified). Set up the agent globally anyway?`,initialIndex:e?1:0,choices:[{label:e?`Yes, overwrite`:`Yes, set up globally`,value:`yes`},{label:`No, cancel`,value:`no`}],onSelect:e=>A(e===`yes`),onCancel:()=>O({status:`cancelled`})})}case`auth`:case`work`:return H.createElement(B,null,H.createElement(B,{color:Q.primary},H.createElement(De,{type:`dots`})),` `,v);default:return null}})()))},ur=e=>new Promise(t=>{let{unmount:n}=ye(e(e=>{n(),t(e)}))}),dr=()=>ur(e=>H.createElement(ar,{message:`How do you want to set up the StackOne agent?`,initialIndex:0,choices:[{label:`Local — this project: auth + .mcp.json + connector skills (.claude/) + guide (CLAUDE.md)`,value:`local`},{label:`Global — any repo: auth + global MCP only (no connector skills/guide)`,value:`global`}],onSelect:t=>e(t)})),fr=(e,t=!0)=>ur(n=>H.createElement(ar,{message:e,initialIndex:t?0:1,choices:[{label:`Yes`,value:`yes`},{label:`No`,value:`no`}],onSelect:e=>n(e===`yes`),onCancel:()=>n(!1)})),pr=async e=>{let t=Nn(e);return t&&await fr(`Install the connector setup into this repo? ${t.remoteUrl?`${t.remoteUrl} (${t.root})`:t.root}`,!0)?t.root:ur(n=>H.createElement(or,{message:t?`Path to install into:`:`Current directory is not a git repo. Path to install into:`,initialValue:e,validate:t=>{let n=En(t)||e;return N(n)?!0:`Path does not exist: ${n}`},onSubmit:t=>n(En(t)||e)}))},mr=e=>new Promise(t=>{let{unmount:n}=ye(H.createElement(lr,{initialMode:e.initialMode,pathFlag:e.pathFlag,startDir:e.startDir??process.cwd(),onExit:e=>{n(),t(e)}}))});var hr=class{async execute(e){y.log(T.blue.bold(`🤖 StackOne Agent Setup - Local Project
141
+ `))}};const wn=(e,t,n)=>{let r=e.message;switch(r.type){case`text`:n&&process.stdout.write(r.content??``);break;case`tool_call`:{let n=r.toolName??`unknown tool`;t&&(t.text=T.cyan(`[${e.phase}] Tool: ${n}`));break}case`tool_error`:y.error(T.red(`\n[${e.phase}] Tool error (${r.toolName}): ${r.error??`Unknown error`}`));break;case`error`:y.error(T.red(`\n[${e.phase}] ${r.error??`Unknown error`}`));break;default:break}};function Tn(e,t){switch(e.type){case`text`:t(null),process.stdout.write(e.content??``);break;case`tool_call`:{let n=e.toolName??`unknown tool`;t(J(T.cyan(`Tool: ${n}`)).start());break}case`tool_result`:t(null);break;case`tool_progress`:{let n=e.progress?.operation||e.toolName||`Working...`;t(J(T.cyan(`Tool: ${n}`)).start());break}case`tool_error`:t(null),y.error(T.red(`\nTool error (${e.toolName}): ${e.error??`Unknown error`}`));break;case`error`:t(null),y.error(T.red(`\n${e.error??`Unknown error`}`));break;case`done`:t(null);break;default:process.env.VERBOSE&&console.warn(`[AgentRun] Unknown message type:`,e.type);break}}const En=e=>{let t=e.trim();return t===`~`?I():t.startsWith(`~/`)?R(I(),t.slice(2)):t},Dn=(e,t,n)=>e?`global`:t?`local`:n?null:`global`,On=(e,t)=>e?.trim()||(t?null:process.cwd()),kn=e=>e.existingConfig?`overwrite`:An(e),An=e=>e.mode===`local`&&e.alreadyAuthed?`work`:`auth`,jn=(e,t)=>{switch(e){case`mode`:return t.mode===`local`?t.hasGit?`repo-confirm`:`path-input`:kn(t);case`repo-confirm`:return t.repoAccepted?kn(t):`path-input`;case`path-input`:return kn(t);case`overwrite`:return An(t);case`auth`:return`work`;default:return`done`}},Mn=(e,t)=>Te(`git`,[`-C`,e,...t],{encoding:`utf-8`,stdio:[`ignore`,`pipe`,`ignore`]}).trim(),Nn=e=>{try{let t=Mn(e,[`rev-parse`,`--show-toplevel`]);if(!t)return null;let n;try{n=Mn(e,[`remote`,`get-url`,`origin`])||void 0}catch{}return{root:t,remoteUrl:n}}catch{return null}},Pn=`connector-guide.md`,Fn=`<!-- BEGIN stackone-connector-guide -->`,In=`<!-- END stackone-connector-guide -->`,Ln=/^[a-z0-9][a-z0-9_-]*$/,Rn=e=>e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),zn=e=>`<!-- Generated by \`stackone agent sync\` from @stackone/agent-harness@${e}. Edit upstream, not here. -->`,Bn=e=>{if(e.includes(`..`)||!Ln.test(e))throw Error(`Refusing unsafe path segment: ${JSON.stringify(e)}`)},Vn=(e,...t)=>{let n=_e(e),r=_e(n,...t);if(r!==n&&!r.startsWith(n+ve))throw Error(`Refusing path outside ${n}: ${r}`);return r},Hn=(e,...t)=>de(Vn(e,...t),`utf-8`),Un=(e,...t)=>de(Vn(e,...t)),Wn=()=>{let e=w(import.meta.url).resolve(`@stackone/agent-harness`),t=ge(e);for(let e=0;e<6;e++){if(N(R(t,`package.json`))&&N(R(t,`plugin`)))return t;let e=ge(t);if(e===t)break;t=e}return ge(ge(e))},Gn=()=>R(Wn(),`plugin`),Kn=e=>{try{let t=e?_e(e,`..`):Wn();return JSON.parse(Hn(t,`package.json`)).version??`unknown`}catch{return`unknown`}},qn=e=>{let t=e.charCodeAt(0)===65279?e.slice(1):e,n=t.match(/^---\n[\s\S]*?\n---\n?/);return n&&(t=t.slice(n[0].length)),t=t.replace(/^\s*<!--[\s\S]*?-->\s*/,``),t.trim()},Jn=(e,t,n)=>{let r=[Fn,zn(n),``,t,``,In].join(`
142
+ `);if(e.includes(Fn)&&e.includes(In)){let t=RegExp(`${Rn(Fn)}[\\s\\S]*?${Rn(In)}`);return e.replace(t,r)}let i=e.replace(/\s*$/,``);return i.length>0?`${i}\n\n${r}\n`:`${r}\n`},Yn=e=>{let t=[];for(let n of P(e,{withFileTypes:!0}))if(n.isDirectory()){let r=Yn(Vn(e,n.name));t.push(...r.map(e=>R(n.name,e)))}else t.push(n.name);return t},Xn=(e,t)=>{if(!N(t))return!1;let n=Yn(e).sort(),r=Yn(t).sort();return n.length!==r.length||n.some((e,t)=>e!==r[t])?!1:n.every(n=>Un(e,n).equals(Un(t,n)))},Zn=(e,t)=>{fe(t,{recursive:!0,force:!0}),ue(ge(t),{recursive:!0}),le(e,t,{recursive:!0})},Qn=e=>P(e,{withFileTypes:!0}).some(t=>{if(!t.isDirectory())return!1;let n=Vn(e,t.name);return N(Vn(n,`SKILL.md`))||Qn(n)}),$n=e=>{if(!N(e))return[];let t=[],n=[];for(let r of P(e,{withFileTypes:!0})){if(!r.isDirectory()||!Ln.test(r.name))continue;let i=Vn(e,r.name);N(Vn(i,`SKILL.md`))?t.push(r.name):Qn(i)&&n.push(r.name)}return n.length>0&&console.warn(`Skipped ${n.length} grouped skill director${n.length===1?`y`:`ies`} (${n.join(`, `)}): skills must be one level down (skills/<name>/SKILL.md) to be synced. Install this plugin as a Claude Code plugin instead of syncing it.`),t.sort()},er=()=>({changed:[],unchanged:[],missing:[]}),tr=(e,t,n,r)=>{let i=er();for(let a of e){Bn(a);let e=Vn(t,a);if(!N(e)||!pe(e).isDirectory()){i.missing.push(a);continue}let o=Vn(n,a);if(Xn(e,o)){i.unchanged.push(a);continue}i.changed.push(a),r||Zn(e,o)}return i},nr=(e,t,n,r)=>{if(!N(Vn(e,Pn)))return`missing-source`;let i=qn(Hn(e,Pn)),a=Vn(t,`CLAUDE.md`),o=N(a)?Hn(t,`CLAUDE.md`):``,s=Jn(o,i,n);return s===o?`unchanged`:(r||me(a,s),`changed`)},rr=e=>{let t=_e(e.pluginDir??Gn()),n=_e(e.cwd),r=e.version??Kn(t),i=e.check??!1,a=Vn(n,`.claude`),o=Vn(t,`skills`),s=tr($n(o),o,Vn(a,`skills`),i),c=nr(t,n,r,i),l=s.changed.length>0||c===`changed`,u=c!==`missing-source`||s.changed.length+s.unchanged.length>0;if(!i&&u){ue(a,{recursive:!0});let e={harnessVersion:r,skills:s.changed.concat(s.unchanged).sort(),guide:c!==`missing-source`};me(Vn(a,`.stackone-connector-env.json`),`${JSON.stringify(e,null,2)}\n`)}return{skills:s,guide:c,hasChanges:l}},ir=e=>{try{let t=e??Gn();return pe(t).isDirectory()?e?JSON.parse(Hn(_e(t,`..`),`package.json`)).name===`@stackone/agent-harness`:!0:!1}catch{return!1}},ar=({message:e,choices:t,initialIndex:n=0,onSelect:r,onCancel:i})=>{let[a,o]=G(()=>t.length?Math.min(Math.max(n,0),t.length-1):0);return V((e,n)=>{if(t.length===0){n.escape&&i?.();return}n.upArrow?o(e=>(e-1+t.length)%t.length):n.downArrow?o(e=>(e+1)%t.length):n.return?r(t[a].value):n.escape&&i?.()}),t.length===0?null:H.createElement(z,{flexDirection:`column`,paddingY:1},H.createElement(z,{borderStyle:`round`,borderColor:`cyan`,flexDirection:`column`,paddingX:2,paddingY:1},H.createElement(B,{bold:!0},e),H.createElement(z,{flexDirection:`column`,marginTop:1},t.map((e,t)=>H.createElement(B,{key:e.value,color:t===a?`#00af66`:`white`},t===a?`❯ `:` `,e.label)))),H.createElement(z,{marginTop:1},H.createElement(B,{dimColor:!0},`↑↓ to navigate • Enter to select`)))},or=({message:e,initialValue:t=``,validate:n,onSubmit:r,onCancel:i})=>{let[a,o]=G(t),[s,c]=G(null);return V((e,t)=>{if(t.return){let e=n?n(a):!0;e===!0?r(a):c(e);return}if(t.escape){i?.();return}if(t.backspace||t.delete){o(e=>e.slice(0,-1)),c(null);return}e&&!t.ctrl&&!t.meta&&!t.tab&&!t.upArrow&&!t.downArrow&&(o(t=>t+e),c(null))}),H.createElement(z,{flexDirection:`column`,paddingY:1},H.createElement(B,{bold:!0},e),H.createElement(z,{marginTop:1},H.createElement(B,null,`> `),H.createElement(B,null,a),H.createElement(B,{inverse:!0},` `)),s&&H.createElement(z,{marginTop:1},H.createElement(B,{color:`red`},s)),H.createElement(z,{marginTop:1},H.createElement(B,{dimColor:!0},`Enter to submit • Esc to cancel`)))},sr=e=>N(`${e}/CLAUDE.md`)||N(`${e}/.mcp.json`),cr=e=>{try{return pe(e).isDirectory()}catch{return!1}},lr=({initialMode:e,pathFlag:t,startDir:n,onExit:r})=>{let[i,o]=G(`mode`),[c,u]=G(null),[f,p]=G(!1),[h,g]=G([]),[v,y]=G(``),[b,x]=G(e),[C,te]=G(``),[w,T]=G(``),[E,ne]=G(!1),[D,re]=G(null),ie=W(0),ae=xe(e=>{ie.current+=1;let t=ie.current;g(n=>[...n,{...e,id:t}])},[]),O=xe(e=>{u(e)},[]),oe=xe(async e=>{let t=_e(En(e));if(!cr(t)){O({status:`error`,message:N(t)?`Target path is not a directory: ${t}`:`Target path does not exist: ${t}`});return}te(t);let n=sr(t),r=d(await ee());ne(r),o(jn(`path-input`,{mode:`local`,hasGit:!1,repoAccepted:!1,existingConfig:n,alreadyAuthed:r}))},[O]),se=xe(e=>{if(x(e),e===`local`){let e=t?.trim();if(e){oe(e);return}let r=Nn(n);r&&(T(`Install the connector setup into this repo? ${r.remoteUrl?`${r.remoteUrl} (${r.root})`:r.root}`),te(r.root)),o(jn(`mode`,{mode:`local`,hasGit:!!r,repoAccepted:!1,existingConfig:!1,alreadyAuthed:!1}));return}o(jn(`mode`,{mode:`global`,hasGit:!1,repoAccepted:!1,existingConfig:sr(n),alreadyAuthed:!1}))},[t,n,oe]);U(()=>{e&&se(e)},[]);let k=xe(e=>{e?oe(C):o(`path-input`)},[oe,C]),A=xe(e=>{if(!e){O({status:`cancelled`});return}o(jn(`overwrite`,{mode:b??`global`,hasGit:!1,repoAccepted:!1,existingConfig:!0,alreadyAuthed:E}))},[b,E,O]);return U(()=>{if(i!==`auth`)return;let e=!1;return y(`Starting browser authentication…`),vn(t=>{e||y(t)}).then(t=>{e||(re(t),ae({icon:`✓`,text:t.email?`Authenticated as ${t.email}`:`Authenticated`,color:Q.success}),o(`work`))}).catch(t=>{e||O({status:`error`,message:t instanceof Error?t.message:`Authentication failed`})}),()=>{e=!0}},[i,ae,O]),U(()=>{if(i!==`work`)return;let e=!1;return(async()=>{try{let t=D??await ee();if(!t)throw Error(`Not authenticated — no API key found`);let r=await S(b===`local`?C:n,t.apiKey);if(r.migrated&&ae({icon:`✓`,text:`Migrated ${r.actions.length} item(s) from a previous setup`,color:Q.success}),b===`local`){y(`Creating .mcp.json…`),l(m(C),s(),t.apiKey),ae({icon:`✓`,text:`Created .mcp.json`,color:Q.success}),y(`Syncing connector-building skills + guide…`);let e=rr({cwd:C});ae({icon:`✓`,text:`Connector environment ready (${e.skills.changed.length+e.skills.unchanged.length} skills in .claude/, ${e.guide===`missing-source`?`guide unavailable in this version`:`guide in CLAUDE.md`})`,color:Q.success})}else y(`Installing global MCP configuration…`),l(a(),_(),t.apiKey),ae({icon:`✓`,text:`Installed to Claude (global)`,color:Q.success});if(e)return;y(``),O({status:`done`})}catch(t){if(e)return;O({status:`error`,message:t instanceof Error?t.message:`Setup failed`})}})(),()=>{e=!0}},[i,D,b,C,n,ae,O]),U(()=>{if(!c)return;let e=setTimeout(()=>r(c),60);return()=>clearTimeout(e)},[c,r]),H.createElement(z,{flexDirection:`column`,padding:1},f?H.createElement(Ct,{wordmark:!0}):H.createElement(Tt,{ready:!0,onComplete:()=>p(!0)}),h.length>0&&H.createElement(z,{flexDirection:`column`,marginTop:1},h.map(e=>H.createElement(B,{key:e.id,color:e.color},e.icon?`${e.icon} `:``,e.text))),H.createElement(z,{marginTop:1},(()=>{if(c)return c.status===`error`?H.createElement(B,{color:Q.error},`✗ `,c.message??`Setup failed`):c.status===`cancelled`?H.createElement(B,{color:Q.dim},`Setup cancelled.`):H.createElement(z,{flexDirection:`column`},H.createElement(B,{color:Q.success},`✓ Setup complete!`),H.createElement(z,{marginTop:1,flexDirection:`column`},H.createElement(B,{color:Q.dim},`Verify with `,H.createElement(B,{color:Q.primary},`claude mcp list`)),H.createElement(B,{color:Q.dim},`Tip: run`,` `,H.createElement(B,{color:Q.primary},`claude --dangerously-skip-permissions`),` `,`to skip permission prompts`),b===`local`&&H.createElement(B,{color:Q.dim},`Refresh skills anytime with`,` `,H.createElement(B,{color:Q.primary},`stackone agent sync`))));switch(i){case`mode`:return e?null:H.createElement(ar,{message:`How do you want to set up the StackOne agent?`,initialIndex:0,choices:[{label:`Local — this project: auth + .mcp.json + connector skills (.claude/) + guide (CLAUDE.md)`,value:`local`},{label:`Global — any repo: auth + global MCP only (no connector skills/guide)`,value:`global`}],onSelect:e=>se(e),onCancel:()=>O({status:`cancelled`})});case`repo-confirm`:return H.createElement(ar,{message:w,initialIndex:0,choices:[{label:`Yes`,value:`yes`},{label:`No, let me choose a path`,value:`no`}],onSelect:e=>k(e===`yes`),onCancel:()=>O({status:`cancelled`})});case`path-input`:return H.createElement(or,{message:`Path to install the connector setup into:`,initialValue:n,validate:e=>{let t=En(e)||n;return N(t)?cr(t)?!0:`Path is not a directory: ${t}`:`Path does not exist: ${t}`},onSubmit:e=>void oe(e.trim()||n),onCancel:()=>O({status:`cancelled`})});case`overwrite`:{let e=b===`local`;return H.createElement(ar,{message:e?`Existing setup found in ${C}. Overwrite it?`:`Local setup detected in ${n} (it won't be modified). Set up the agent globally anyway?`,initialIndex:e?1:0,choices:[{label:e?`Yes, overwrite`:`Yes, set up globally`,value:`yes`},{label:`No, cancel`,value:`no`}],onSelect:e=>A(e===`yes`),onCancel:()=>O({status:`cancelled`})})}case`auth`:case`work`:return H.createElement(B,null,H.createElement(B,{color:Q.primary},H.createElement(De,{type:`dots`})),` `,v);default:return null}})()))},ur=e=>new Promise(t=>{let{unmount:n}=ye(e(e=>{n(),t(e)}))}),dr=()=>ur(e=>H.createElement(ar,{message:`How do you want to set up the StackOne agent?`,initialIndex:0,choices:[{label:`Local — this project: auth + .mcp.json + connector skills (.claude/) + guide (CLAUDE.md)`,value:`local`},{label:`Global — any repo: auth + global MCP only (no connector skills/guide)`,value:`global`}],onSelect:t=>e(t)})),fr=(e,t=!0)=>ur(n=>H.createElement(ar,{message:e,initialIndex:t?0:1,choices:[{label:`Yes`,value:`yes`},{label:`No`,value:`no`}],onSelect:e=>n(e===`yes`),onCancel:()=>n(!1)})),pr=async e=>{let t=Nn(e);return t&&await fr(`Install the connector setup into this repo? ${t.remoteUrl?`${t.remoteUrl} (${t.root})`:t.root}`,!0)?t.root:ur(n=>H.createElement(or,{message:t?`Path to install into:`:`Current directory is not a git repo. Path to install into:`,initialValue:e,validate:t=>{let n=En(t)||e;return N(n)?!0:`Path does not exist: ${n}`},onSubmit:t=>n(En(t)||e)}))},mr=e=>new Promise(t=>{let{unmount:n}=ye(H.createElement(lr,{initialMode:e.initialMode,pathFlag:e.pathFlag,startDir:e.startDir??process.cwd(),onExit:e=>{n(),t(e)}}))});var hr=class{async execute(e){y.log(T.blue.bold(`🤖 StackOne Agent Setup - Local Project
143
143
  `));try{let t=_e(En(e?.targetPath??process.cwd()));await Le(t).then(()=>!0).catch(()=>!1)||(y.error(`Target path does not exist: ${t}`),process.exit(1)),e?.targetPath&&y.log(T.dim(`Installing into ${t}\n`));let n=await Le(`${t}/CLAUDE.md`).then(()=>!0).catch(()=>!1),r=await Le(`${t}/.mcp.json`).then(()=>!0).catch(()=>!1);if(n||r){y.warn(`Existing local setup detected:`),n&&y.log(T.dim(` • CLAUDE.md found`)),r&&y.log(T.dim(` • .mcp.json found`)),y.log(``);let t=on(!!e?.legacy,e?.credentials),i=!!process.stdin.isTTY;t||!i?y.log(T.dim(t?`Non-interactive credentials detected; proceeding without confirmation.
144
144
  `:`No interactive terminal detected; proceeding without overwrite confirmation.
145
145
  `)):(await fr(`Overwrite existing local configuration?`,!1)||(y.log(T.dim(`
@@ -150,7 +150,7 @@ Setup cancelled.`)),process.exit(0)),y.log(``))}let i=await ee();(!i||!d(i))&&(y
150
150
  Verify:`),T.cyan(`claude mcp list`)),y.log(``)}catch(e){a.fail(`Failed to create .mcp.json`),e instanceof Error&&y.error(e.message)}let o=J(`Syncing connector-building skills + guide...`).start();try{let e=rr({cwd:t}),n=e.skills.changed.length+e.skills.unchanged.length,r=e.guide===`missing-source`?`unavailable in this version`:`in CLAUDE.md`;o.succeed(`Connector-building environment ready (${n} skills in .claude/, guide ${r})`),y.log(T.dim(` Refresh anytime with`),T.cyan(`stackone agent sync`))}catch(e){o.fail(`Failed to sync connector-building environment`),e instanceof Error&&y.error(e.message)}process.exit(0)}catch(e){e instanceof Error?y.error(e.message):y.error(`Unknown error occurred`),process.exit(1)}}},gr=class{async execute(e){let t=k(),n=e?.mode;if(y.log(T.bold(`
151
151
  Available skills
152
152
  `)),t.length===0){y.log(T.dim(` No bundled skills found.
153
- `));return}for(let e of t)y.log(` • ${e}`);if(n){let e=j(n);if(e.length>0){y.log(T.bold(`\nRecommended for mode "${n}":\n`));for(let n of e){let e=t.includes(n);y.log(` • ${n}${e?``:T.dim(` (not found)`)}`)}}}y.log(``)}};const _r=(e,t,n)=>{let r=n?`stale`:`synced`;t.changed.length>0&&y.log(T.cyan(` • ${e} ${r}: ${t.changed.join(`, `)}`)),t.missing.length>0&&y.log(T.dim(` • ${e} not in this harness version: ${t.missing.join(`, `)}`))},vr=(e,t)=>{e===`missing-source`?y.log(T.dim(` • connector-guide.md not in this harness version — skipped CLAUDE.md`)):e===`changed`&&y.log(T.cyan(` • CLAUDE.md guide block ${t?`stale`:`updated`}`))};var yr=class{async execute(e){let t=!!e?.check,n=e?.pluginDir;ir(n)||(y.error(n?`--plugin-dir is not a valid @stackone/agent-harness plugin dir: ${n}`:`Could not locate the bundled @stackone/agent-harness plugin. Reinstall the CLI and try again.`),process.exit(1));let r=qn(n);y.log(T.blue.bold(`🧩 ${t?`Checking`:`Syncing`} connector-building environment`)+T.dim(` (agent-harness@${r}${n?` [--plugin-dir]`:``})\n`));try{let e=rr({cwd:process.cwd(),check:t,pluginDir:n});_r(`skills`,e.skills,t),vr(e.guide,t),t&&(e.hasChanges&&(y.log(``),y.error("Connector-building environment is out of date. Run `stackone agent sync` to update."),process.exit(1)),y.success(`Connector-building environment is up to date.`),process.exit(0)),e.hasChanges?(y.success(`Connector-building environment synced into .claude/ and CLAUDE.md.`),y.log(T.dim(`
153
+ `));return}for(let e of t)y.log(` • ${e}`);if(n){let e=j(n);if(e.length>0){y.log(T.bold(`\nRecommended for mode "${n}":\n`));for(let n of e){let e=t.includes(n);y.log(` • ${n}${e?``:T.dim(` (not found)`)}`)}}}y.log(``)}};const _r=(e,t,n)=>{let r=n?`stale`:`synced`;t.changed.length>0&&y.log(T.cyan(` • ${e} ${r}: ${t.changed.join(`, `)}`)),t.missing.length>0&&y.log(T.dim(` • ${e} not in this harness version: ${t.missing.join(`, `)}`))},vr=(e,t)=>{e===`missing-source`?y.log(T.dim(` • connector-guide.md not in this harness version — skipped CLAUDE.md`)):e===`changed`&&y.log(T.cyan(` • CLAUDE.md guide block ${t?`stale`:`updated`}`))};var yr=class{async execute(e){let t=!!e?.check,n=e?.pluginDir;ir(n)||(y.error(n?`--plugin-dir is not a valid @stackone/agent-harness plugin dir: ${n}`:`Could not locate the bundled @stackone/agent-harness plugin. Reinstall the CLI and try again.`),process.exit(1));let r=Kn(n);y.log(T.blue.bold(`🧩 ${t?`Checking`:`Syncing`} connector-building environment`)+T.dim(` (agent-harness@${r}${n?` [--plugin-dir]`:``})\n`));try{let e=rr({cwd:process.cwd(),check:t,pluginDir:n});_r(`skills`,e.skills,t),vr(e.guide,t),t&&(e.hasChanges&&(y.log(``),y.error("Connector-building environment is out of date. Run `stackone agent sync` to update."),process.exit(1)),y.success(`Connector-building environment is up to date.`),process.exit(0)),e.hasChanges?(y.success(`Connector-building environment synced into .claude/ and CLAUDE.md.`),y.log(T.dim(`
154
154
  💡 Skills and the connector guide are managed by the CLI — `),T.dim("re-run `stackone agent sync` after a CLI update."))):y.success(`Already up to date — nothing to sync.`),process.exit(0)}catch(e){y.error(e instanceof Error?e.message:`Unknown error during sync`),process.exit(1)}}};const br={profiles:{}},xr=()=>{let t=i.readConfigFile(e);if(!t)return br;try{return JSON.parse(t)}catch{return br}},Sr=e=>xr().profiles[e],Cr=e=>!!xr().profiles[e],wr=(t,n)=>{let r=xr();r.profiles[t]=n,i.writeConfigFile(e,JSON.stringify(r,null,2))},Tr=()=>{let e=xr();return Object.keys(e.profiles)},Er=`https://api.stackone.com`;var Dr=class{async execute({profile:e,connector:r,apiUrl:i,apiKey:a}={}){if(!e&&!a&&(y.error(`Profile or API key is required`),y.log(`Please provide a profile using the ${t(`--profile`)} option or an API key using the ${t(`--api-key`)} option.`),y.log(`To create a profile, run ${t(`stackone init`)}.`),process.exit(1)),e&&a&&(y.error(`Please provide either a profile or an API key, not both`),process.exit(1)),e&&i&&y.warn(`Specifying ${t(`--api-url`)} with a profile won't have any effect. Using API url from profile.`),e&&!Cr(e)){y.error(`Configuration profile ${t(e)} not found`),y.log(`Run ${t(`stackone init`)} to create a new configuration profile.\n`);let n=Tr();n.length>0&&(y.info(`Available configuration profiles:`),n.forEach(e=>{y.log(` - ${T.blue(e)}`)})),process.exit(1)}let o=e?Sr(e):{apiUrl:i??Er,apiKey:a};o?.apiKey||(y.error(`API key is missing`),y.log(`Please provide a valid API key in the profile or via the ${t(`--api-key`)} option.`),process.exit(1)),r||(y.error(`Connector identifier is required in the format provider_key@version.`),process.exit(1));let s=r.split(`@`);(s.length!==2||!s[0]||!s[1])&&(y.error(`Invalid connector format ${n(r)}. Expected format: ${t(`provider_key@version`)}`),process.exit(1));let c=o.apiUrl??Er,l=await this.dropConnector(r,c,o.apiKey);process.exit(l?0:1)}async dropConnector(e,n,i){let a=J(`🗑️ Dropping connector ${t(e)}...`).start();try{let r=Buffer.from(i).toString(`base64`),o=await fetch(`${n}/registry/connectors/${e}`,{method:`DELETE`,headers:{Authorization:`Basic ${r}`}});return a.stop(),o.status===204?(y.success(`Successfully dropped connector ${t(e)} from the registry`),!0):o.status===404?(y.error(`Connector ${t(e)} not found in the registry`),!1):o.status===401||o.status===403?(y.error(`You do not have permission to drop this connector`),!1):o.status===409?(y.error(`Connector ${t(e)} has associated configs and cannot be dropped`),y.log(`Please delete all associated integration configurations before dropping the connector.`),!1):(o.ok||await b(o,`Failed to drop connector ${t(e)} from the registry`),!1)}catch(i){return a.stop(),y.error(`Failed to drop connector ${t(e)} from registry: ${i.message}`),y.log(`Please ensure that the API at ${r(n)} is reachable and the API key is valid`),!1}}};const Or=`stackone`;async function kr(e,n){n.length===0&&(y.error(`Multiple versions of connector ${t(e)} were found but no owner information was returned`),process.exit(1));let r=n.map(e=>({value:e,label:e===Or?`StackOne`:`Custom`,hint:e===Or?`Official StackOne connector`:`Custom connector version created by your organization`}));y.warn(`Multiple versions of connector ${t(e)} were found. Please select which version to use.`);let i=await Ye({message:`Which version would you like to use?`,options:r});return Ke(i)&&(y.error(`Operation cancelled.`),process.exit(1)),i}const Ar=`https://api.stackone.com`;var jr=class{async execute({profile:e,connector:r,accountId:i,format:a,outputFile:s,apiUrl:c,apiKey:l,owner:u}={}){if(!e&&!l&&(y.error(`Profile or API key is required`),y.log(`Please provide a profile using the ${t(`--profile`)} option or an API key using the ${t(`--api-key`)} option.`),y.log(`To create a profile, run ${t(`stackone init`)}.`),process.exit(1)),e&&l&&(y.error(`Please provide either a profile or an API key, not both`),process.exit(1)),e&&c&&y.warn(`Specifying ${t(`--api-url`)} with a profile won't have any effect. Using API url from profile.`),e&&!Cr(e)){y.error(`Configuration profile ${t(e)} not found`),y.log(`Run ${t(`stackone init`)} to create a new configuration profile.\n`);let n=Tr();n.length>0&&(y.info(`Available configuration profiles:`),n.forEach(e=>{y.log(` - ${T.blue(e)}`)})),process.exit(1)}let d=e?Sr(e):{apiUrl:c??Ar,apiKey:l};d?.apiKey||(y.error(`API key is missing`),y.log(`Please provide a valid API key in the profile or via the ${t(`--api-key`)} option.`),process.exit(1)),Y(r)&&Y(i)&&(y.error(`Either ${t(`--connector`)} or ${t(`--account-id`)} must be provided`),process.exit(1)),X(r)&&X(i)&&(y.error(`Please provide either ${t(`--connector`)} or ${t(`--account-id`)}, not both.`),process.exit(1)),X(a)&&a!==`yaml`&&a!==`json`&&(y.error(`Format must be either ${t(`yaml`)} or ${t(`json`)}.`),process.exit(1));let f=d.apiUrl??Ar,p;if(X(r)){this.#t(r)||(y.error(`Invalid connector format ${n(r)}. Expected format: ${t(`provider_key@version`)} or ${t(`provider_key`)}`),process.exit(1));let e=this.#n(r);p=await this.#r(e,f,d.apiKey,a,u)}else X(i)?p=await this.#i(i,f,d.apiKey,a):(y.error(`Either ${t(`--connector`)} or ${t(`--account-id`)} must be provided`),process.exit(1));if(X(s))try{K.writeFileSync(s,p,`utf-8`),y.success(`Connector written to file: ${t(s)}`)}catch(e){y.error(`Failed to write connector to file ${t(s)}: ${e.message}`),process.exit(1)}else if(y.log(`\n${T.blue.inverse(` CONNECTOR CONTENT `)}\n`),!a||a===`yaml`)y.log(this.#e(p));else if(a===`json`)try{o(JSON.parse(p))}catch{y.log(p)}else y.log(p);process.exit(0)}#e(e){return e.split(`
155
155
  `).map(e=>{if(e.trim().startsWith(`#`))return T.gray(e);if(e.includes(`:`)){let t=e.indexOf(`:`),n=e.substring(0,t+1),r=e.substring(t+1),i=r,a=r.trim();return a===`true`||a===`false`?i=r.replace(a,T.cyan(a)):a===`null`||a===`~`?i=r.replace(a,T.gray(a)):/^-?\d+(\.\d+)?$/.test(a)?i=r.replace(a,T.green(a)):(a.startsWith(`"`)&&a.endsWith(`"`)||a.startsWith(`'`)&&a.endsWith(`'`)||a&&!a.startsWith(`-`))&&(i=r.replace(a,T.yellow(a))),T.red(n)+i}return e.trim().startsWith(`-`)?e.replace(`-`,T.gray(`-`)):e}).join(`
156
156
  `)}#t=e=>!e.includes(`/`)&&!e.includes(`\\`)&&!e.endsWith(`.yaml`)&&!e.endsWith(`.yml`)?e.includes(`@`)?e.split(`@`).length===2:!0:!1;#n=e=>e.includes(`@`)?e:`${e}@latest`;async#r(e,n,i,a,o){let s=J(`Getting connector ${t(e)} from registry...`).start();try{let r=Buffer.from(i).toString(`base64`),c=a?`?format=${a}`:``,l=o?`${c?`&`:`?`}owner=${encodeURIComponent(o)}`:``,u=await fetch(`${n}/registry/connectors/${e}${c}${l}`,{method:`GET`,headers:{Authorization:`Basic ${r}`}});if(s.stop(),u.status===409){o&&(await b(u,`Failed to get connector ${t(e)} from the registry`),process.exit(1));let i=await kr(e,(await u.json()).availableOwners??[]),a=`${n}/registry/connectors/${e}${c}${c?`&`:`?`}owner=${encodeURIComponent(i)}`;s.text=`Getting connector ${t(e)} from registry...`,s.start();let l=await fetch(a,{method:`GET`,headers:{Authorization:`Basic ${r}`}});return s.stop(),l.ok||(await b(l,`Failed to get connector ${t(e)} from the registry`),process.exit(1)),await l.text()}return u.ok||(await b(u,`Failed to get connector ${t(e)} from the registry`),process.exit(1)),await u.text()}catch(i){s.stop(),y.error(`Failed to get connector ${t(e)} from the registry: ${i.message}`),y.log(`Please ensure that the API at ${r(n)} is reachable and the API key is valid`),process.exit(1)}}async#i(e,n,i,a){let o=J(`Getting connector from account ${t(e)}...`).start();try{let r=Buffer.from(i).toString(`base64`),s=a?`?format=${a}`:``,c=await fetch(`${n}/accounts/${e}/connector${s}`,{method:`GET`,headers:{Authorization:`Basic ${r}`}});return o.stop(),c.ok||(await b(c,`Failed to get connector from account ${t(e)}`),process.exit(1)),await c.text()}catch(i){o.stop(),y.error(`Failed to get connector from account ${t(e)}: ${i.message}`),y.log(`Please ensure that the API at ${r(n)} is reachable and the API key is valid`),process.exit(1)}}};const Mr=`http://localhost:4000`;var Nr=class{async execute({environment:e}={}){let n=e?.toLowerCase()??`production`;try{Ge(`${T.inverse(` Initialize profile `)}`);let e=await Xe({message:`Profile label`,validate:e=>{if(!e||e.trim().length===0)return`The profile label is required`;if(e.includes(` `))return`The profile label cannot contain spaces`}});if(Ke(e))return Ue(`Configuration profile initialization cancelled`),process.exit(0);if(Cr(e)){let n=await We({message:`Configuration profile with name ${t(e)} already exists. Do you want to overwrite it?`});if(Ke(n)||!n)return Ue(`Configuration profile initialization cancelled`),process.exit(0)}let r;if(n===`production`)r=`https://api.stackone.com`;else if(n===`staging`)r=`https://api.stackone-dev.com`;else{let e=await Xe({message:`API URL`,placeholder:Mr,initialValue:Mr,validate:e=>{if(!e||e.trim().length===0)return`API URL is required`;try{new URL(e)}catch{return`Please enter a valid URL`}}});if(Ke(e))return Ue(`Configuration profile initialization cancelled`),process.exit(0);r=e}let i=await Je({message:`API Key`,validate:e=>{if(!e||e.trim().length===0)return`API Key is required`}});if(Ke(i))return Ue(`Configuration profile initialization cancelled`),process.exit(0);wr(e,{label:e,environment:n,apiUrl:r,apiKey:i}),qe(`${T.green(`✔`)} Configuration profile ${t(e)} initialized successfully!`),process.exit(0)}catch(e){e?.isTtyError?y.error(`Prompt couldn't be rendered in the current environment`):y.error(`Failed to initialize configuration profile: ${e}`),process.exit(1)}}};const $={pending:`○`,acceptRemote:`●`,acceptLocal:`◐`,acceptBoth:`◑`,current:`◉`,arrow:`→`,check:`✓`,cross:`✗`,warning:`⚠`};var Pr=class{constructor(e,t,n,r){this.conflicts=[],this.currentIndex=0,this.totalConflicts=0,this.currentCleanup=null,this.connectorId=t,this.localVersion=n,this.remoteVersion=r,this.conflicts=e.map(e=>({conflict:e,choice:e.type===`unchanged`?`remote`:`pending`})),this.totalConflicts=e.filter(e=>e.type===`conflict`).length}resetForReResolution(){this.currentIndex=0}async resolve(){return this.totalConflicts===0?{cancelled:!1,states:this.conflicts}:(this.moveToNextConflict(),new Promise(e=>{let t=nt({input:process.stdin,output:process.stdout});process.stdin.isTTY&&process.stdin.setRawMode(!0),process.stdin.resume(),this.render();let n=n=>{let r=n.toString();if(r===``){this.cleanup(t),this.renderCancelled(),e({cancelled:!0,states:this.conflicts});return}if(r===`\x1B`&&n.length===1){this.cleanup(t),this.renderCancelled(),e({cancelled:!0,states:this.conflicts});return}if(r.startsWith(`\x1B[`)){switch(r.slice(2)){case`D`:this.moveToPrevConflict(),this.render();break;case`C`:this.moveToNextConflict(),this.render();break}return}switch(r){case`r`:case`R`:this.setCurrentChoice(`remote`),this.advanceAfterChoice(t);break;case`l`:case`L`:this.setCurrentChoice(`local`),this.advanceAfterChoice(t);break;case`b`:case`B`:this.setCurrentChoice(`both`),this.advanceAfterChoice(t);break;case`\r`:case`
@@ -138,8 +138,8 @@ Error: `+(t instanceof Error?t.message:String(t)))),process.exit(1)}f?.stop(),e.
138
138
  `))}async executeOrchestratedBuild(t){let{provider:n,category:r,verbose:a}=t,o=r?` (${r})`:``;e.w.log(i.default.bold(`\nOrchestrated build: ${n}${o}\n`));let s=null,c=new Map;try{for await(let e of Ce(t))switch(e.type){case`phase_start`:{let t=Xe[e.phase]||`${e.phase}...`,n=e.model?i.default.dim(` (${N(e.model)})`):``;s?.stop(),s=(0,v.default)(i.default.cyan(`[${e.phase}]${n} ${t}`)).start(),c.set(e.phase,Date.now());break}case`phase_complete`:{let t=c.get(e.phase),n=t===void 0?0:Math.round((Date.now()-t)/1e3);s?.succeed(i.default.green(`[${e.phase}] Done (${n}s)`)),s=null;break}case`phase_error`:s?.fail(i.default.red(`[${e.phase}] ${e.error}`)),s=null;break;case`agent_message`:Qe(e,s,a);break}}catch(t){s?.fail(),e.w.error(i.default.red(`
139
139
  Error: `+(t instanceof Error?t.message:String(t)))),process.exit(1)}s?.stop(),e.w.log(i.default.green(`
140
140
  ✓ Build complete
141
- `))}};const Qe=(t,n,r)=>{let a=t.message;switch(a.type){case`text`:r&&process.stdout.write(a.content??``);break;case`tool_call`:{let e=a.toolName??`unknown tool`;n&&(n.text=i.default.cyan(`[${t.phase}] Tool: ${e}`));break}case`tool_error`:e.w.error(i.default.red(`\n[${t.phase}] Tool error (${a.toolName}): ${a.error??`Unknown error`}`));break;case`error`:e.w.error(i.default.red(`\n[${t.phase}] ${a.error??`Unknown error`}`));break;default:break}};function $e(t,n){switch(t.type){case`text`:n(null),process.stdout.write(t.content??``);break;case`tool_call`:{let e=t.toolName??`unknown tool`;n((0,v.default)(i.default.cyan(`Tool: ${e}`)).start());break}case`tool_result`:n(null);break;case`tool_progress`:{let e=t.progress?.operation||t.toolName||`Working...`;n((0,v.default)(i.default.cyan(`Tool: ${e}`)).start());break}case`tool_error`:n(null),e.w.error(i.default.red(`\nTool error (${t.toolName}): ${t.error??`Unknown error`}`));break;case`error`:n(null),e.w.error(i.default.red(`\n${t.error??`Unknown error`}`));break;case`done`:n(null);break;default:process.env.VERBOSE&&console.warn(`[AgentRun] Unknown message type:`,t.type);break}}const et=e=>{let t=e.trim();return t===`~`?(0,c.homedir)():t.startsWith(`~/`)?(0,l.join)((0,c.homedir)(),t.slice(2)):t},tt=(e,t,n)=>e?`global`:t?`local`:n?null:`global`,nt=(e,t)=>e?.trim()||(t?null:process.cwd()),rt=e=>e.existingConfig?`overwrite`:it(e),it=e=>e.mode===`local`&&e.alreadyAuthed?`work`:`auth`,at=(e,t)=>{switch(e){case`mode`:return t.mode===`local`?t.hasGit?`repo-confirm`:`path-input`:rt(t);case`repo-confirm`:return t.repoAccepted?rt(t):`path-input`;case`path-input`:return rt(t);case`overwrite`:return it(t);case`auth`:return`work`;default:return`done`}},ot=(e,t)=>(0,f.execFileSync)(`git`,[`-C`,e,...t],{encoding:`utf-8`,stdio:[`ignore`,`pipe`,`ignore`]}).trim(),st=e=>{try{let t=ot(e,[`rev-parse`,`--show-toplevel`]);if(!t)return null;let n;try{n=ot(e,[`remote`,`get-url`,`origin`])||void 0}catch{}return{root:t,remoteUrl:n}}catch{return null}},ct=`connector-guide.md`,lt=`<!-- BEGIN stackone-connector-guide -->`,ut=`<!-- END stackone-connector-guide -->`,dt=`.stackone-connector-env.json`,ft=/^[a-z0-9][a-z0-9_-]*$/,pt=e=>e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),mt=e=>`<!-- Generated by \`stackone agent sync\` from @stackone/agent-harness@${e}. Edit upstream, not here. -->`,ht=e=>{if(e.includes(`..`)||!ft.test(e))throw Error(`Refusing unsafe path segment: ${JSON.stringify(e)}`)},gt=e=>{let t=e.split(`/`);if(t.length===0)throw Error(`Refusing empty path: ${JSON.stringify(e)}`);for(let e of t)ht(e)},Q=(e,...t)=>{let n=(0,l.resolve)(e),r=(0,l.resolve)(n,...t);if(r!==n&&!r.startsWith(n+l.sep))throw Error(`Refusing path outside ${n}: ${r}`);return r},_t=(e,...t)=>(0,s.readFileSync)(Q(e,...t),`utf-8`),vt=(e,...t)=>(0,s.readFileSync)(Q(e,...t)),yt=`@stackone/agent-harness`,bt=()=>{let e=(0,g.createRequire)(require(`url`).pathToFileURL(__filename).href).resolve(`@stackone/agent-harness`),t=(0,l.dirname)(e);for(let e=0;e<6;e++){if((0,s.existsSync)((0,l.join)(t,`package.json`))&&(0,s.existsSync)((0,l.join)(t,`plugin`)))return t;let e=(0,l.dirname)(t);if(e===t)break;t=e}return(0,l.dirname)((0,l.dirname)(e))},xt=()=>(0,l.join)(bt(),`plugin`),St=e=>{try{let t=e?(0,l.resolve)(e,`..`):bt();return JSON.parse(_t(t,`package.json`)).version??`unknown`}catch{return`unknown`}},Ct=e=>{let t=e.charCodeAt(0)===65279?e.slice(1):e,n=t.match(/^---\n[\s\S]*?\n---\n?/);return n&&(t=t.slice(n[0].length)),t=t.replace(/^\s*<!--[\s\S]*?-->\s*/,``),t.trim()},wt=(e,t,n)=>{let r=[lt,mt(n),``,t,``,ut].join(`
142
- `);if(e.includes(lt)&&e.includes(ut)){let t=RegExp(`${pt(lt)}[\\s\\S]*?${pt(ut)}`);return e.replace(t,r)}let i=e.replace(/\s*$/,``);return i.length>0?`${i}\n\n${r}\n`:`${r}\n`},Tt=e=>{let t=[];for(let n of(0,s.readdirSync)(e,{withFileTypes:!0}))if(n.isDirectory()){let r=Tt(Q(e,n.name));t.push(...r.map(e=>(0,l.join)(n.name,e)))}else t.push(n.name);return t},Et=(e,t)=>{if(!(0,s.existsSync)(t))return!1;let n=Tt(e).sort(),r=Tt(t).sort();return n.length!==r.length||n.some((e,t)=>e!==r[t])?!1:n.every(n=>vt(e,n).equals(vt(t,n)))},Dt=(e,t)=>{(0,s.rmSync)(t,{recursive:!0,force:!0}),(0,s.mkdirSync)((0,l.dirname)(t),{recursive:!0}),(0,s.cpSync)(e,t,{recursive:!0})},Ot=(e,t=``)=>{if(!(0,s.existsSync)(e))return[];let n=[];for(let r of(0,s.readdirSync)(e,{withFileTypes:!0})){if(!r.isDirectory()||!ft.test(r.name))continue;let i=t?`${t}/${r.name}`:r.name;if((0,s.existsSync)(Q(e,r.name,`SKILL.md`))){n.push(i);continue}n.push(...Ot(Q(e,r.name),i))}return n.sort()},kt=()=>({changed:[],unchanged:[],missing:[]}),At=(e,t,n,r)=>{let i=kt();for(let a of e){gt(a);let e=Q(t,a);if(!(0,s.existsSync)(e)||!(0,s.statSync)(e).isDirectory()){i.missing.push(a);continue}let o=Q(n,a);if(Et(e,o)){i.unchanged.push(a);continue}i.changed.push(a),r||Dt(e,o)}return i},jt=(e,t,n,r)=>{if(!(0,s.existsSync)(Q(e,ct)))return`missing-source`;let i=Ct(_t(e,ct)),a=Q(t,`CLAUDE.md`),o=(0,s.existsSync)(a)?_t(t,`CLAUDE.md`):``,c=wt(o,i,n);return c===o?`unchanged`:(r||(0,s.writeFileSync)(a,c),`changed`)},Mt=e=>{let t=(0,l.resolve)(e.pluginDir??xt()),n=(0,l.resolve)(e.cwd),r=e.version??St(t),i=e.check??!1,a=Q(n,`.claude`),o=Q(t,`skills`),c=At(Ot(o),o,Q(a,`skills`),i),u=jt(t,n,r,i),d=c.changed.length>0||u===`changed`,f=u!==`missing-source`||c.changed.length+c.unchanged.length>0;if(!i&&f){(0,s.mkdirSync)(a,{recursive:!0});let e={harnessVersion:r,skills:c.changed.concat(c.unchanged).sort(),guide:u!==`missing-source`};(0,s.writeFileSync)(Q(a,`.stackone-connector-env.json`),`${JSON.stringify(e,null,2)}\n`)}return{skills:c,guide:u,hasChanges:d}},Nt=e=>{try{let t=e??xt();return(0,s.statSync)(t).isDirectory()?e?JSON.parse(_t((0,l.resolve)(t,`..`),`package.json`)).name===`@stackone/agent-harness`:!0:!1}catch{return!1}},Pt=`#00af66`,Ft=({message:e,choices:t,initialIndex:n=0,onSelect:r,onCancel:i})=>{let[a,o]=(0,d.useState)(()=>t.length?Math.min(Math.max(n,0),t.length-1):0);return(0,u.useInput)((e,n)=>{if(t.length===0){n.escape&&i?.();return}n.upArrow?o(e=>(e-1+t.length)%t.length):n.downArrow?o(e=>(e+1)%t.length):n.return?r(t[a].value):n.escape&&i?.()}),t.length===0?null:d.default.createElement(u.Box,{flexDirection:`column`,paddingY:1},d.default.createElement(u.Box,{borderStyle:`round`,borderColor:`cyan`,flexDirection:`column`,paddingX:2,paddingY:1},d.default.createElement(u.Text,{bold:!0},e),d.default.createElement(u.Box,{flexDirection:`column`,marginTop:1},t.map((e,t)=>d.default.createElement(u.Text,{key:e.value,color:t===a?`#00af66`:`white`},t===a?`❯ `:` `,e.label)))),d.default.createElement(u.Box,{marginTop:1},d.default.createElement(u.Text,{dimColor:!0},`↑↓ to navigate • Enter to select`)))},It=({message:e,initialValue:t=``,validate:n,onSubmit:r,onCancel:i})=>{let[a,o]=(0,d.useState)(t),[s,c]=(0,d.useState)(null);return(0,u.useInput)((e,t)=>{if(t.return){let e=n?n(a):!0;e===!0?r(a):c(e);return}if(t.escape){i?.();return}if(t.backspace||t.delete){o(e=>e.slice(0,-1)),c(null);return}e&&!t.ctrl&&!t.meta&&!t.tab&&!t.upArrow&&!t.downArrow&&(o(t=>t+e),c(null))}),d.default.createElement(u.Box,{flexDirection:`column`,paddingY:1},d.default.createElement(u.Text,{bold:!0},e),d.default.createElement(u.Box,{marginTop:1},d.default.createElement(u.Text,null,`> `),d.default.createElement(u.Text,null,a),d.default.createElement(u.Text,{inverse:!0},` `)),s&&d.default.createElement(u.Box,{marginTop:1},d.default.createElement(u.Text,{color:`red`},s)),d.default.createElement(u.Box,{marginTop:1},d.default.createElement(u.Text,{dimColor:!0},`Enter to submit • Esc to cancel`)))},Lt=e=>(0,s.existsSync)(`${e}/CLAUDE.md`)||(0,s.existsSync)(`${e}/.mcp.json`),Rt=e=>{try{return(0,s.statSync)(e).isDirectory()}catch{return!1}},zt=({initialMode:t,pathFlag:r,startDir:i,onExit:a})=>{let[o,c]=(0,d.useState)(`mode`),[f,m]=(0,d.useState)(null),[h,g]=(0,d.useState)(!1),[_,v]=(0,d.useState)([]),[y,b]=(0,d.useState)(``),[x,S]=(0,d.useState)(t),[C,w]=(0,d.useState)(``),[T,E]=(0,d.useState)(``),[ee,te]=(0,d.useState)(!1),[D,O]=(0,d.useState)(null),k=(0,d.useRef)(0),A=(0,d.useCallback)(e=>{k.current+=1;let t=k.current;v(n=>[...n,{...e,id:t}])},[]),M=(0,d.useCallback)(e=>{m(e)},[]),N=(0,d.useCallback)(async t=>{let n=(0,l.resolve)(et(t));if(!Rt(n)){M({status:`error`,message:(0,s.existsSync)(n)?`Target path is not a directory: ${n}`:`Target path does not exist: ${n}`});return}w(n);let r=Lt(n),i=e.l(await e.u());te(i),c(at(`path-input`,{mode:`local`,hasGit:!1,repoAccepted:!1,existingConfig:r,alreadyAuthed:i}))},[M]),P=(0,d.useCallback)(e=>{if(S(e),e===`local`){let e=r?.trim();if(e){N(e);return}let t=st(i);t&&(E(`Install the connector setup into this repo? ${t.remoteUrl?`${t.remoteUrl} (${t.root})`:t.root}`),w(t.root)),c(at(`mode`,{mode:`local`,hasGit:!!t,repoAccepted:!1,existingConfig:!1,alreadyAuthed:!1}));return}c(at(`mode`,{mode:`global`,hasGit:!1,repoAccepted:!1,existingConfig:Lt(i),alreadyAuthed:!1}))},[r,i,N]);(0,d.useEffect)(()=>{t&&P(t)},[]);let ne=(0,d.useCallback)(e=>{e?N(C):c(`path-input`)},[N,C]),re=(0,d.useCallback)(e=>{if(!e){M({status:`cancelled`});return}c(at(`overwrite`,{mode:x??`global`,hasGit:!1,repoAccepted:!1,existingConfig:!0,alreadyAuthed:ee}))},[x,ee,M]);return(0,d.useEffect)(()=>{if(o!==`auth`)return;let e=!1;return b(`Starting browser authentication…`),Ke(t=>{e||b(t)}).then(t=>{e||(O(t),A({icon:`✓`,text:t.email?`Authenticated as ${t.email}`:`Authenticated`,color:j.success}),c(`work`))}).catch(t=>{e||M({status:`error`,message:t instanceof Error?t.message:`Authentication failed`})}),()=>{e=!0}},[o,A,M]),(0,d.useEffect)(()=>{if(o!==`work`)return;let t=!1;return(async()=>{try{let r=D??await e.u();if(!r)throw Error(`Not authenticated — no API key found`);let a=await n.r(x===`local`?C:i,r.apiKey);if(a.migrated&&A({icon:`✓`,text:`Migrated ${a.actions.length} item(s) from a previous setup`,color:j.success}),x===`local`){b(`Creating .mcp.json…`),e.h(e.o(C),e.c(),r.apiKey),A({icon:`✓`,text:`Created .mcp.json`,color:j.success}),b(`Syncing connector-building skills + guide…`);let t=Mt({cwd:C});A({icon:`✓`,text:`Connector environment ready (${t.skills.changed.length+t.skills.unchanged.length} skills in .claude/, ${t.guide===`missing-source`?`guide unavailable in this version`:`guide in CLAUDE.md`})`,color:j.success})}else b(`Installing global MCP configuration…`),e.h(e.a(),e.s(),r.apiKey),A({icon:`✓`,text:`Installed to Claude (global)`,color:j.success});if(t)return;b(``),M({status:`done`})}catch(e){if(t)return;M({status:`error`,message:e instanceof Error?e.message:`Setup failed`})}})(),()=>{t=!0}},[o,D,x,C,i,A,M]),(0,d.useEffect)(()=>{if(!f)return;let e=setTimeout(()=>a(f),60);return()=>clearTimeout(e)},[f,a]),d.default.createElement(u.Box,{flexDirection:`column`,padding:1},h?d.default.createElement(le,{wordmark:!0}):d.default.createElement(de,{ready:!0,onComplete:()=>g(!0)}),_.length>0&&d.default.createElement(u.Box,{flexDirection:`column`,marginTop:1},_.map(e=>d.default.createElement(u.Text,{key:e.id,color:e.color},e.icon?`${e.icon} `:``,e.text))),d.default.createElement(u.Box,{marginTop:1},(()=>{if(f)return f.status===`error`?d.default.createElement(u.Text,{color:j.error},`✗ `,f.message??`Setup failed`):f.status===`cancelled`?d.default.createElement(u.Text,{color:j.dim},`Setup cancelled.`):d.default.createElement(u.Box,{flexDirection:`column`},d.default.createElement(u.Text,{color:j.success},`✓ Setup complete!`),d.default.createElement(u.Box,{marginTop:1,flexDirection:`column`},d.default.createElement(u.Text,{color:j.dim},`Verify with `,d.default.createElement(u.Text,{color:j.primary},`claude mcp list`)),d.default.createElement(u.Text,{color:j.dim},`Tip: run`,` `,d.default.createElement(u.Text,{color:j.primary},`claude --dangerously-skip-permissions`),` `,`to skip permission prompts`),x===`local`&&d.default.createElement(u.Text,{color:j.dim},`Refresh skills anytime with`,` `,d.default.createElement(u.Text,{color:j.primary},`stackone agent sync`))));switch(o){case`mode`:return t?null:d.default.createElement(Ft,{message:`How do you want to set up the StackOne agent?`,initialIndex:0,choices:[{label:`Local — this project: auth + .mcp.json + connector skills (.claude/) + guide (CLAUDE.md)`,value:`local`},{label:`Global — any repo: auth + global MCP only (no connector skills/guide)`,value:`global`}],onSelect:e=>P(e),onCancel:()=>M({status:`cancelled`})});case`repo-confirm`:return d.default.createElement(Ft,{message:T,initialIndex:0,choices:[{label:`Yes`,value:`yes`},{label:`No, let me choose a path`,value:`no`}],onSelect:e=>ne(e===`yes`),onCancel:()=>M({status:`cancelled`})});case`path-input`:return d.default.createElement(It,{message:`Path to install the connector setup into:`,initialValue:i,validate:e=>{let t=et(e)||i;return(0,s.existsSync)(t)?Rt(t)?!0:`Path is not a directory: ${t}`:`Path does not exist: ${t}`},onSubmit:e=>void N(e.trim()||i),onCancel:()=>M({status:`cancelled`})});case`overwrite`:{let e=x===`local`;return d.default.createElement(Ft,{message:e?`Existing setup found in ${C}. Overwrite it?`:`Local setup detected in ${i} (it won't be modified). Set up the agent globally anyway?`,initialIndex:e?1:0,choices:[{label:e?`Yes, overwrite`:`Yes, set up globally`,value:`yes`},{label:`No, cancel`,value:`no`}],onSelect:e=>re(e===`yes`),onCancel:()=>M({status:`cancelled`})})}case`auth`:case`work`:return d.default.createElement(u.Text,null,d.default.createElement(u.Text,{color:j.primary},d.default.createElement(p.default,{type:`dots`})),` `,y);default:return null}})()))},Bt=e=>new Promise(t=>{let{unmount:n}=(0,u.render)(e(e=>{n(),t(e)}))}),Vt=()=>Bt(e=>d.default.createElement(Ft,{message:`How do you want to set up the StackOne agent?`,initialIndex:0,choices:[{label:`Local — this project: auth + .mcp.json + connector skills (.claude/) + guide (CLAUDE.md)`,value:`local`},{label:`Global — any repo: auth + global MCP only (no connector skills/guide)`,value:`global`}],onSelect:t=>e(t)})),Ht=(e,t=!0)=>Bt(n=>d.default.createElement(Ft,{message:e,initialIndex:t?0:1,choices:[{label:`Yes`,value:`yes`},{label:`No`,value:`no`}],onSelect:e=>n(e===`yes`),onCancel:()=>n(!1)})),Ut=async e=>{let t=st(e);return t&&await Ht(`Install the connector setup into this repo? ${t.remoteUrl?`${t.remoteUrl} (${t.root})`:t.root}`,!0)?t.root:Bt(n=>d.default.createElement(It,{message:t?`Path to install into:`:`Current directory is not a git repo. Path to install into:`,initialValue:e,validate:t=>{let n=et(t)||e;return(0,s.existsSync)(n)?!0:`Path does not exist: ${n}`},onSubmit:t=>n(et(t)||e)}))},Wt=e=>new Promise(t=>{let{unmount:n}=(0,u.render)(d.default.createElement(zt,{initialMode:e.initialMode,pathFlag:e.pathFlag,startDir:e.startDir??process.cwd(),onExit:e=>{n(),t(e)}}))});var Gt=class{async execute(t){e.w.log(i.default.blue.bold(`🤖 StackOne Agent Setup - Local Project
141
+ `))}};const Qe=(t,n,r)=>{let a=t.message;switch(a.type){case`text`:r&&process.stdout.write(a.content??``);break;case`tool_call`:{let e=a.toolName??`unknown tool`;n&&(n.text=i.default.cyan(`[${t.phase}] Tool: ${e}`));break}case`tool_error`:e.w.error(i.default.red(`\n[${t.phase}] Tool error (${a.toolName}): ${a.error??`Unknown error`}`));break;case`error`:e.w.error(i.default.red(`\n[${t.phase}] ${a.error??`Unknown error`}`));break;default:break}};function $e(t,n){switch(t.type){case`text`:n(null),process.stdout.write(t.content??``);break;case`tool_call`:{let e=t.toolName??`unknown tool`;n((0,v.default)(i.default.cyan(`Tool: ${e}`)).start());break}case`tool_result`:n(null);break;case`tool_progress`:{let e=t.progress?.operation||t.toolName||`Working...`;n((0,v.default)(i.default.cyan(`Tool: ${e}`)).start());break}case`tool_error`:n(null),e.w.error(i.default.red(`\nTool error (${t.toolName}): ${t.error??`Unknown error`}`));break;case`error`:n(null),e.w.error(i.default.red(`\n${t.error??`Unknown error`}`));break;case`done`:n(null);break;default:process.env.VERBOSE&&console.warn(`[AgentRun] Unknown message type:`,t.type);break}}const et=e=>{let t=e.trim();return t===`~`?(0,c.homedir)():t.startsWith(`~/`)?(0,l.join)((0,c.homedir)(),t.slice(2)):t},tt=(e,t,n)=>e?`global`:t?`local`:n?null:`global`,nt=(e,t)=>e?.trim()||(t?null:process.cwd()),rt=e=>e.existingConfig?`overwrite`:it(e),it=e=>e.mode===`local`&&e.alreadyAuthed?`work`:`auth`,at=(e,t)=>{switch(e){case`mode`:return t.mode===`local`?t.hasGit?`repo-confirm`:`path-input`:rt(t);case`repo-confirm`:return t.repoAccepted?rt(t):`path-input`;case`path-input`:return rt(t);case`overwrite`:return it(t);case`auth`:return`work`;default:return`done`}},ot=(e,t)=>(0,f.execFileSync)(`git`,[`-C`,e,...t],{encoding:`utf-8`,stdio:[`ignore`,`pipe`,`ignore`]}).trim(),st=e=>{try{let t=ot(e,[`rev-parse`,`--show-toplevel`]);if(!t)return null;let n;try{n=ot(e,[`remote`,`get-url`,`origin`])||void 0}catch{}return{root:t,remoteUrl:n}}catch{return null}},ct=`connector-guide.md`,lt=`<!-- BEGIN stackone-connector-guide -->`,ut=`<!-- END stackone-connector-guide -->`,dt=`.stackone-connector-env.json`,ft=/^[a-z0-9][a-z0-9_-]*$/,pt=e=>e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),mt=e=>`<!-- Generated by \`stackone agent sync\` from @stackone/agent-harness@${e}. Edit upstream, not here. -->`,ht=e=>{if(e.includes(`..`)||!ft.test(e))throw Error(`Refusing unsafe path segment: ${JSON.stringify(e)}`)},Q=(e,...t)=>{let n=(0,l.resolve)(e),r=(0,l.resolve)(n,...t);if(r!==n&&!r.startsWith(n+l.sep))throw Error(`Refusing path outside ${n}: ${r}`);return r},gt=(e,...t)=>(0,s.readFileSync)(Q(e,...t),`utf-8`),_t=(e,...t)=>(0,s.readFileSync)(Q(e,...t)),vt=`@stackone/agent-harness`,yt=()=>{let e=(0,g.createRequire)(require(`url`).pathToFileURL(__filename).href).resolve(`@stackone/agent-harness`),t=(0,l.dirname)(e);for(let e=0;e<6;e++){if((0,s.existsSync)((0,l.join)(t,`package.json`))&&(0,s.existsSync)((0,l.join)(t,`plugin`)))return t;let e=(0,l.dirname)(t);if(e===t)break;t=e}return(0,l.dirname)((0,l.dirname)(e))},bt=()=>(0,l.join)(yt(),`plugin`),xt=e=>{try{let t=e?(0,l.resolve)(e,`..`):yt();return JSON.parse(gt(t,`package.json`)).version??`unknown`}catch{return`unknown`}},St=e=>{let t=e.charCodeAt(0)===65279?e.slice(1):e,n=t.match(/^---\n[\s\S]*?\n---\n?/);return n&&(t=t.slice(n[0].length)),t=t.replace(/^\s*<!--[\s\S]*?-->\s*/,``),t.trim()},Ct=(e,t,n)=>{let r=[lt,mt(n),``,t,``,ut].join(`
142
+ `);if(e.includes(lt)&&e.includes(ut)){let t=RegExp(`${pt(lt)}[\\s\\S]*?${pt(ut)}`);return e.replace(t,r)}let i=e.replace(/\s*$/,``);return i.length>0?`${i}\n\n${r}\n`:`${r}\n`},wt=e=>{let t=[];for(let n of(0,s.readdirSync)(e,{withFileTypes:!0}))if(n.isDirectory()){let r=wt(Q(e,n.name));t.push(...r.map(e=>(0,l.join)(n.name,e)))}else t.push(n.name);return t},Tt=(e,t)=>{if(!(0,s.existsSync)(t))return!1;let n=wt(e).sort(),r=wt(t).sort();return n.length!==r.length||n.some((e,t)=>e!==r[t])?!1:n.every(n=>_t(e,n).equals(_t(t,n)))},Et=(e,t)=>{(0,s.rmSync)(t,{recursive:!0,force:!0}),(0,s.mkdirSync)((0,l.dirname)(t),{recursive:!0}),(0,s.cpSync)(e,t,{recursive:!0})},Dt=e=>(0,s.readdirSync)(e,{withFileTypes:!0}).some(t=>{if(!t.isDirectory())return!1;let n=Q(e,t.name);return(0,s.existsSync)(Q(n,`SKILL.md`))||Dt(n)}),Ot=e=>{if(!(0,s.existsSync)(e))return[];let t=[],n=[];for(let r of(0,s.readdirSync)(e,{withFileTypes:!0})){if(!r.isDirectory()||!ft.test(r.name))continue;let i=Q(e,r.name);(0,s.existsSync)(Q(i,`SKILL.md`))?t.push(r.name):Dt(i)&&n.push(r.name)}return n.length>0&&console.warn(`Skipped ${n.length} grouped skill director${n.length===1?`y`:`ies`} (${n.join(`, `)}): skills must be one level down (skills/<name>/SKILL.md) to be synced. Install this plugin as a Claude Code plugin instead of syncing it.`),t.sort()},kt=()=>({changed:[],unchanged:[],missing:[]}),At=(e,t,n,r)=>{let i=kt();for(let a of e){ht(a);let e=Q(t,a);if(!(0,s.existsSync)(e)||!(0,s.statSync)(e).isDirectory()){i.missing.push(a);continue}let o=Q(n,a);if(Tt(e,o)){i.unchanged.push(a);continue}i.changed.push(a),r||Et(e,o)}return i},jt=(e,t,n,r)=>{if(!(0,s.existsSync)(Q(e,ct)))return`missing-source`;let i=St(gt(e,ct)),a=Q(t,`CLAUDE.md`),o=(0,s.existsSync)(a)?gt(t,`CLAUDE.md`):``,c=Ct(o,i,n);return c===o?`unchanged`:(r||(0,s.writeFileSync)(a,c),`changed`)},Mt=e=>{let t=(0,l.resolve)(e.pluginDir??bt()),n=(0,l.resolve)(e.cwd),r=e.version??xt(t),i=e.check??!1,a=Q(n,`.claude`),o=Q(t,`skills`),c=At(Ot(o),o,Q(a,`skills`),i),u=jt(t,n,r,i),d=c.changed.length>0||u===`changed`,f=u!==`missing-source`||c.changed.length+c.unchanged.length>0;if(!i&&f){(0,s.mkdirSync)(a,{recursive:!0});let e={harnessVersion:r,skills:c.changed.concat(c.unchanged).sort(),guide:u!==`missing-source`};(0,s.writeFileSync)(Q(a,`.stackone-connector-env.json`),`${JSON.stringify(e,null,2)}\n`)}return{skills:c,guide:u,hasChanges:d}},Nt=e=>{try{let t=e??bt();return(0,s.statSync)(t).isDirectory()?e?JSON.parse(gt((0,l.resolve)(t,`..`),`package.json`)).name===`@stackone/agent-harness`:!0:!1}catch{return!1}},Pt=`#00af66`,Ft=({message:e,choices:t,initialIndex:n=0,onSelect:r,onCancel:i})=>{let[a,o]=(0,d.useState)(()=>t.length?Math.min(Math.max(n,0),t.length-1):0);return(0,u.useInput)((e,n)=>{if(t.length===0){n.escape&&i?.();return}n.upArrow?o(e=>(e-1+t.length)%t.length):n.downArrow?o(e=>(e+1)%t.length):n.return?r(t[a].value):n.escape&&i?.()}),t.length===0?null:d.default.createElement(u.Box,{flexDirection:`column`,paddingY:1},d.default.createElement(u.Box,{borderStyle:`round`,borderColor:`cyan`,flexDirection:`column`,paddingX:2,paddingY:1},d.default.createElement(u.Text,{bold:!0},e),d.default.createElement(u.Box,{flexDirection:`column`,marginTop:1},t.map((e,t)=>d.default.createElement(u.Text,{key:e.value,color:t===a?`#00af66`:`white`},t===a?`❯ `:` `,e.label)))),d.default.createElement(u.Box,{marginTop:1},d.default.createElement(u.Text,{dimColor:!0},`↑↓ to navigate • Enter to select`)))},It=({message:e,initialValue:t=``,validate:n,onSubmit:r,onCancel:i})=>{let[a,o]=(0,d.useState)(t),[s,c]=(0,d.useState)(null);return(0,u.useInput)((e,t)=>{if(t.return){let e=n?n(a):!0;e===!0?r(a):c(e);return}if(t.escape){i?.();return}if(t.backspace||t.delete){o(e=>e.slice(0,-1)),c(null);return}e&&!t.ctrl&&!t.meta&&!t.tab&&!t.upArrow&&!t.downArrow&&(o(t=>t+e),c(null))}),d.default.createElement(u.Box,{flexDirection:`column`,paddingY:1},d.default.createElement(u.Text,{bold:!0},e),d.default.createElement(u.Box,{marginTop:1},d.default.createElement(u.Text,null,`> `),d.default.createElement(u.Text,null,a),d.default.createElement(u.Text,{inverse:!0},` `)),s&&d.default.createElement(u.Box,{marginTop:1},d.default.createElement(u.Text,{color:`red`},s)),d.default.createElement(u.Box,{marginTop:1},d.default.createElement(u.Text,{dimColor:!0},`Enter to submit • Esc to cancel`)))},Lt=e=>(0,s.existsSync)(`${e}/CLAUDE.md`)||(0,s.existsSync)(`${e}/.mcp.json`),Rt=e=>{try{return(0,s.statSync)(e).isDirectory()}catch{return!1}},zt=({initialMode:t,pathFlag:r,startDir:i,onExit:a})=>{let[o,c]=(0,d.useState)(`mode`),[f,m]=(0,d.useState)(null),[h,g]=(0,d.useState)(!1),[_,v]=(0,d.useState)([]),[y,b]=(0,d.useState)(``),[x,S]=(0,d.useState)(t),[C,w]=(0,d.useState)(``),[T,E]=(0,d.useState)(``),[ee,te]=(0,d.useState)(!1),[D,O]=(0,d.useState)(null),k=(0,d.useRef)(0),A=(0,d.useCallback)(e=>{k.current+=1;let t=k.current;v(n=>[...n,{...e,id:t}])},[]),M=(0,d.useCallback)(e=>{m(e)},[]),N=(0,d.useCallback)(async t=>{let n=(0,l.resolve)(et(t));if(!Rt(n)){M({status:`error`,message:(0,s.existsSync)(n)?`Target path is not a directory: ${n}`:`Target path does not exist: ${n}`});return}w(n);let r=Lt(n),i=e.l(await e.u());te(i),c(at(`path-input`,{mode:`local`,hasGit:!1,repoAccepted:!1,existingConfig:r,alreadyAuthed:i}))},[M]),P=(0,d.useCallback)(e=>{if(S(e),e===`local`){let e=r?.trim();if(e){N(e);return}let t=st(i);t&&(E(`Install the connector setup into this repo? ${t.remoteUrl?`${t.remoteUrl} (${t.root})`:t.root}`),w(t.root)),c(at(`mode`,{mode:`local`,hasGit:!!t,repoAccepted:!1,existingConfig:!1,alreadyAuthed:!1}));return}c(at(`mode`,{mode:`global`,hasGit:!1,repoAccepted:!1,existingConfig:Lt(i),alreadyAuthed:!1}))},[r,i,N]);(0,d.useEffect)(()=>{t&&P(t)},[]);let ne=(0,d.useCallback)(e=>{e?N(C):c(`path-input`)},[N,C]),re=(0,d.useCallback)(e=>{if(!e){M({status:`cancelled`});return}c(at(`overwrite`,{mode:x??`global`,hasGit:!1,repoAccepted:!1,existingConfig:!0,alreadyAuthed:ee}))},[x,ee,M]);return(0,d.useEffect)(()=>{if(o!==`auth`)return;let e=!1;return b(`Starting browser authentication…`),Ke(t=>{e||b(t)}).then(t=>{e||(O(t),A({icon:`✓`,text:t.email?`Authenticated as ${t.email}`:`Authenticated`,color:j.success}),c(`work`))}).catch(t=>{e||M({status:`error`,message:t instanceof Error?t.message:`Authentication failed`})}),()=>{e=!0}},[o,A,M]),(0,d.useEffect)(()=>{if(o!==`work`)return;let t=!1;return(async()=>{try{let r=D??await e.u();if(!r)throw Error(`Not authenticated — no API key found`);let a=await n.r(x===`local`?C:i,r.apiKey);if(a.migrated&&A({icon:`✓`,text:`Migrated ${a.actions.length} item(s) from a previous setup`,color:j.success}),x===`local`){b(`Creating .mcp.json…`),e.h(e.o(C),e.c(),r.apiKey),A({icon:`✓`,text:`Created .mcp.json`,color:j.success}),b(`Syncing connector-building skills + guide…`);let t=Mt({cwd:C});A({icon:`✓`,text:`Connector environment ready (${t.skills.changed.length+t.skills.unchanged.length} skills in .claude/, ${t.guide===`missing-source`?`guide unavailable in this version`:`guide in CLAUDE.md`})`,color:j.success})}else b(`Installing global MCP configuration…`),e.h(e.a(),e.s(),r.apiKey),A({icon:`✓`,text:`Installed to Claude (global)`,color:j.success});if(t)return;b(``),M({status:`done`})}catch(e){if(t)return;M({status:`error`,message:e instanceof Error?e.message:`Setup failed`})}})(),()=>{t=!0}},[o,D,x,C,i,A,M]),(0,d.useEffect)(()=>{if(!f)return;let e=setTimeout(()=>a(f),60);return()=>clearTimeout(e)},[f,a]),d.default.createElement(u.Box,{flexDirection:`column`,padding:1},h?d.default.createElement(le,{wordmark:!0}):d.default.createElement(de,{ready:!0,onComplete:()=>g(!0)}),_.length>0&&d.default.createElement(u.Box,{flexDirection:`column`,marginTop:1},_.map(e=>d.default.createElement(u.Text,{key:e.id,color:e.color},e.icon?`${e.icon} `:``,e.text))),d.default.createElement(u.Box,{marginTop:1},(()=>{if(f)return f.status===`error`?d.default.createElement(u.Text,{color:j.error},`✗ `,f.message??`Setup failed`):f.status===`cancelled`?d.default.createElement(u.Text,{color:j.dim},`Setup cancelled.`):d.default.createElement(u.Box,{flexDirection:`column`},d.default.createElement(u.Text,{color:j.success},`✓ Setup complete!`),d.default.createElement(u.Box,{marginTop:1,flexDirection:`column`},d.default.createElement(u.Text,{color:j.dim},`Verify with `,d.default.createElement(u.Text,{color:j.primary},`claude mcp list`)),d.default.createElement(u.Text,{color:j.dim},`Tip: run`,` `,d.default.createElement(u.Text,{color:j.primary},`claude --dangerously-skip-permissions`),` `,`to skip permission prompts`),x===`local`&&d.default.createElement(u.Text,{color:j.dim},`Refresh skills anytime with`,` `,d.default.createElement(u.Text,{color:j.primary},`stackone agent sync`))));switch(o){case`mode`:return t?null:d.default.createElement(Ft,{message:`How do you want to set up the StackOne agent?`,initialIndex:0,choices:[{label:`Local — this project: auth + .mcp.json + connector skills (.claude/) + guide (CLAUDE.md)`,value:`local`},{label:`Global — any repo: auth + global MCP only (no connector skills/guide)`,value:`global`}],onSelect:e=>P(e),onCancel:()=>M({status:`cancelled`})});case`repo-confirm`:return d.default.createElement(Ft,{message:T,initialIndex:0,choices:[{label:`Yes`,value:`yes`},{label:`No, let me choose a path`,value:`no`}],onSelect:e=>ne(e===`yes`),onCancel:()=>M({status:`cancelled`})});case`path-input`:return d.default.createElement(It,{message:`Path to install the connector setup into:`,initialValue:i,validate:e=>{let t=et(e)||i;return(0,s.existsSync)(t)?Rt(t)?!0:`Path is not a directory: ${t}`:`Path does not exist: ${t}`},onSubmit:e=>void N(e.trim()||i),onCancel:()=>M({status:`cancelled`})});case`overwrite`:{let e=x===`local`;return d.default.createElement(Ft,{message:e?`Existing setup found in ${C}. Overwrite it?`:`Local setup detected in ${i} (it won't be modified). Set up the agent globally anyway?`,initialIndex:e?1:0,choices:[{label:e?`Yes, overwrite`:`Yes, set up globally`,value:`yes`},{label:`No, cancel`,value:`no`}],onSelect:e=>re(e===`yes`),onCancel:()=>M({status:`cancelled`})})}case`auth`:case`work`:return d.default.createElement(u.Text,null,d.default.createElement(u.Text,{color:j.primary},d.default.createElement(p.default,{type:`dots`})),` `,y);default:return null}})()))},Bt=e=>new Promise(t=>{let{unmount:n}=(0,u.render)(e(e=>{n(),t(e)}))}),Vt=()=>Bt(e=>d.default.createElement(Ft,{message:`How do you want to set up the StackOne agent?`,initialIndex:0,choices:[{label:`Local — this project: auth + .mcp.json + connector skills (.claude/) + guide (CLAUDE.md)`,value:`local`},{label:`Global — any repo: auth + global MCP only (no connector skills/guide)`,value:`global`}],onSelect:t=>e(t)})),Ht=(e,t=!0)=>Bt(n=>d.default.createElement(Ft,{message:e,initialIndex:t?0:1,choices:[{label:`Yes`,value:`yes`},{label:`No`,value:`no`}],onSelect:e=>n(e===`yes`),onCancel:()=>n(!1)})),Ut=async e=>{let t=st(e);return t&&await Ht(`Install the connector setup into this repo? ${t.remoteUrl?`${t.remoteUrl} (${t.root})`:t.root}`,!0)?t.root:Bt(n=>d.default.createElement(It,{message:t?`Path to install into:`:`Current directory is not a git repo. Path to install into:`,initialValue:e,validate:t=>{let n=et(t)||e;return(0,s.existsSync)(n)?!0:`Path does not exist: ${n}`},onSubmit:t=>n(et(t)||e)}))},Wt=e=>new Promise(t=>{let{unmount:n}=(0,u.render)(d.default.createElement(zt,{initialMode:e.initialMode,pathFlag:e.pathFlag,startDir:e.startDir??process.cwd(),onExit:e=>{n(),t(e)}}))});var Gt=class{async execute(t){e.w.log(i.default.blue.bold(`🤖 StackOne Agent Setup - Local Project
143
143
  `));try{let r=(0,l.resolve)(et(t?.targetPath??process.cwd()));await(0,y.access)(r).then(()=>!0).catch(()=>!1)||(e.w.error(`Target path does not exist: ${r}`),process.exit(1)),t?.targetPath&&e.w.log(i.default.dim(`Installing into ${r}\n`));let a=await(0,y.access)(`${r}/CLAUDE.md`).then(()=>!0).catch(()=>!1),o=await(0,y.access)(`${r}/.mcp.json`).then(()=>!0).catch(()=>!1);if(a||o){e.w.warn(`Existing local setup detected:`),a&&e.w.log(i.default.dim(` • CLAUDE.md found`)),o&&e.w.log(i.default.dim(` • .mcp.json found`)),e.w.log(``);let n=Y(!!t?.legacy,t?.credentials),r=!!process.stdin.isTTY;n||!r?e.w.log(i.default.dim(n?`Non-interactive credentials detected; proceeding without confirmation.
144
144
  `:`No interactive terminal detected; proceeding without overwrite confirmation.
145
145
  `)):(await Ht(`Overwrite existing local configuration?`,!1)||(e.w.log(i.default.dim(`
@@ -150,7 +150,7 @@ Setup cancelled.`)),process.exit(0)),e.w.log(``))}let s=await e.u();(!s||!e.l(s)
150
150
  Verify:`),i.default.cyan(`claude mcp list`)),e.w.log(``)}catch(t){c.fail(`Failed to create .mcp.json`),t instanceof Error&&e.w.error(t.message)}let u=(0,v.default)(`Syncing connector-building skills + guide...`).start();try{let t=Mt({cwd:r}),n=t.skills.changed.length+t.skills.unchanged.length,a=t.guide===`missing-source`?`unavailable in this version`:`in CLAUDE.md`;u.succeed(`Connector-building environment ready (${n} skills in .claude/, guide ${a})`),e.w.log(i.default.dim(` Refresh anytime with`),i.default.cyan(`stackone agent sync`))}catch(t){u.fail(`Failed to sync connector-building environment`),t instanceof Error&&e.w.error(t.message)}process.exit(0)}catch(t){t instanceof Error?e.w.error(t.message):e.w.error(`Unknown error occurred`),process.exit(1)}}},Kt=class{async execute(t){let n=(0,o.getAvailableSkillNames)(),r=t?.mode;if(e.w.log(i.default.bold(`
151
151
  Available skills
152
152
  `)),n.length===0){e.w.log(i.default.dim(` No bundled skills found.
153
- `));return}for(let t of n)e.w.log(` • ${t}`);if(r){let t=(0,o.getSkillsForMode)(r);if(t.length>0){e.w.log(i.default.bold(`\nRecommended for mode "${r}":\n`));for(let r of t){let t=n.includes(r);e.w.log(` • ${r}${t?``:i.default.dim(` (not found)`)}`)}}}e.w.log(``)}};const qt=(t,n,r)=>{let a=r?`stale`:`synced`;n.changed.length>0&&e.w.log(i.default.cyan(` • ${t} ${a}: ${n.changed.join(`, `)}`)),n.missing.length>0&&e.w.log(i.default.dim(` • ${t} not in this harness version: ${n.missing.join(`, `)}`))},Jt=(t,n)=>{t===`missing-source`?e.w.log(i.default.dim(` • connector-guide.md not in this harness version — skipped CLAUDE.md`)):t===`changed`&&e.w.log(i.default.cyan(` • CLAUDE.md guide block ${n?`stale`:`updated`}`))};var Yt=class{async execute(t){let n=!!t?.check,r=t?.pluginDir;Nt(r)||(e.w.error(r?`--plugin-dir is not a valid @stackone/agent-harness plugin dir: ${r}`:`Could not locate the bundled @stackone/agent-harness plugin. Reinstall the CLI and try again.`),process.exit(1));let a=St(r);e.w.log(i.default.blue.bold(`🧩 ${n?`Checking`:`Syncing`} connector-building environment`)+i.default.dim(` (agent-harness@${a}${r?` [--plugin-dir]`:``})\n`));try{let t=Mt({cwd:process.cwd(),check:n,pluginDir:r});qt(`skills`,t.skills,n),Jt(t.guide,n),n&&(t.hasChanges&&(e.w.log(``),e.w.error("Connector-building environment is out of date. Run `stackone agent sync` to update."),process.exit(1)),e.w.success(`Connector-building environment is up to date.`),process.exit(0)),t.hasChanges?(e.w.success(`Connector-building environment synced into .claude/ and CLAUDE.md.`),e.w.log(i.default.dim(`
153
+ `));return}for(let t of n)e.w.log(` • ${t}`);if(r){let t=(0,o.getSkillsForMode)(r);if(t.length>0){e.w.log(i.default.bold(`\nRecommended for mode "${r}":\n`));for(let r of t){let t=n.includes(r);e.w.log(` • ${r}${t?``:i.default.dim(` (not found)`)}`)}}}e.w.log(``)}};const qt=(t,n,r)=>{let a=r?`stale`:`synced`;n.changed.length>0&&e.w.log(i.default.cyan(` • ${t} ${a}: ${n.changed.join(`, `)}`)),n.missing.length>0&&e.w.log(i.default.dim(` • ${t} not in this harness version: ${n.missing.join(`, `)}`))},Jt=(t,n)=>{t===`missing-source`?e.w.log(i.default.dim(` • connector-guide.md not in this harness version — skipped CLAUDE.md`)):t===`changed`&&e.w.log(i.default.cyan(` • CLAUDE.md guide block ${n?`stale`:`updated`}`))};var Yt=class{async execute(t){let n=!!t?.check,r=t?.pluginDir;Nt(r)||(e.w.error(r?`--plugin-dir is not a valid @stackone/agent-harness plugin dir: ${r}`:`Could not locate the bundled @stackone/agent-harness plugin. Reinstall the CLI and try again.`),process.exit(1));let a=xt(r);e.w.log(i.default.blue.bold(`🧩 ${n?`Checking`:`Syncing`} connector-building environment`)+i.default.dim(` (agent-harness@${a}${r?` [--plugin-dir]`:``})\n`));try{let t=Mt({cwd:process.cwd(),check:n,pluginDir:r});qt(`skills`,t.skills,n),Jt(t.guide,n),n&&(t.hasChanges&&(e.w.log(``),e.w.error("Connector-building environment is out of date. Run `stackone agent sync` to update."),process.exit(1)),e.w.success(`Connector-building environment is up to date.`),process.exit(0)),t.hasChanges?(e.w.success(`Connector-building environment synced into .claude/ and CLAUDE.md.`),e.w.log(i.default.dim(`
154
154
  💡 Skills and the connector guide are managed by the CLI — `),i.default.dim("re-run `stackone agent sync` after a CLI update."))):e.w.success(`Already up to date — nothing to sync.`),process.exit(0)}catch(t){e.w.error(t instanceof Error?t.message:`Unknown error during sync`),process.exit(1)}}};const Xt={profiles:{}},Zt=()=>{let n=e._.readConfigFile(t.n);if(!n)return Xt;try{return JSON.parse(n)}catch{return Xt}},Qt=e=>Zt().profiles[e],$t=e=>!!Zt().profiles[e],en=(n,r)=>{let i=Zt();i.profiles[n]=r,e._.writeConfigFile(t.n,JSON.stringify(i,null,2))},tn=()=>{let e=Zt();return Object.keys(e.profiles)},nn=`https://api.stackone.com`;var rn=class{async execute({profile:t,connector:n,apiUrl:r,apiKey:a}={}){if(!t&&!a&&(e.w.error(`Profile or API key is required`),e.w.log(`Please provide a profile using the ${e.C(`--profile`)} option or an API key using the ${e.C(`--api-key`)} option.`),e.w.log(`To create a profile, run ${e.C(`stackone init`)}.`),process.exit(1)),t&&a&&(e.w.error(`Please provide either a profile or an API key, not both`),process.exit(1)),t&&r&&e.w.warn(`Specifying ${e.C(`--api-url`)} with a profile won't have any effect. Using API url from profile.`),t&&!$t(t)){e.w.error(`Configuration profile ${e.C(t)} not found`),e.w.log(`Run ${e.C(`stackone init`)} to create a new configuration profile.\n`);let n=tn();n.length>0&&(e.w.info(`Available configuration profiles:`),n.forEach(t=>{e.w.log(` - ${i.default.blue(t)}`)})),process.exit(1)}let o=t?Qt(t):{apiUrl:r??nn,apiKey:a};o?.apiKey||(e.w.error(`API key is missing`),e.w.log(`Please provide a valid API key in the profile or via the ${e.C(`--api-key`)} option.`),process.exit(1)),n||(e.w.error(`Connector identifier is required in the format provider_key@version.`),process.exit(1));let s=n.split(`@`);(s.length!==2||!s[0]||!s[1])&&(e.w.error(`Invalid connector format ${e.S(n)}. Expected format: ${e.C(`provider_key@version`)}`),process.exit(1));let c=o.apiUrl??nn,l=await this.dropConnector(n,c,o.apiKey);process.exit(l?0:1)}async dropConnector(t,n,r){let i=(0,v.default)(`🗑️ Dropping connector ${e.C(t)}...`).start();try{let a=Buffer.from(r).toString(`base64`),o=await fetch(`${n}/registry/connectors/${t}`,{method:`DELETE`,headers:{Authorization:`Basic ${a}`}});return i.stop(),o.status===204?(e.w.success(`Successfully dropped connector ${e.C(t)} from the registry`),!0):o.status===404?(e.w.error(`Connector ${e.C(t)} not found in the registry`),!1):o.status===401||o.status===403?(e.w.error(`You do not have permission to drop this connector`),!1):o.status===409?(e.w.error(`Connector ${e.C(t)} has associated configs and cannot be dropped`),e.w.log(`Please delete all associated integration configurations before dropping the connector.`),!1):(o.ok||await e.x(o,`Failed to drop connector ${e.C(t)} from the registry`),!1)}catch(r){return i.stop(),e.w.error(`Failed to drop connector ${e.C(t)} from registry: ${r.message}`),e.w.log(`Please ensure that the API at ${e.T(n)} is reachable and the API key is valid`),!1}}};const an=`stackone`;async function on(t,n){n.length===0&&(e.w.error(`Multiple versions of connector ${e.C(t)} were found but no owner information was returned`),process.exit(1));let r=n.map(e=>({value:e,label:e===an?`StackOne`:`Custom`,hint:e===an?`Official StackOne connector`:`Custom connector version created by your organization`}));e.w.warn(`Multiple versions of connector ${e.C(t)} were found. Please select which version to use.`);let i=await(0,w.select)({message:`Which version would you like to use?`,options:r});return(0,w.isCancel)(i)&&(e.w.error(`Operation cancelled.`),process.exit(1)),i}const sn=`https://api.stackone.com`;var cn=class{async execute({profile:t,connector:n,accountId:r,format:a,outputFile:o,apiUrl:s,apiKey:c,owner:l}={}){if(!t&&!c&&(e.w.error(`Profile or API key is required`),e.w.log(`Please provide a profile using the ${e.C(`--profile`)} option or an API key using the ${e.C(`--api-key`)} option.`),e.w.log(`To create a profile, run ${e.C(`stackone init`)}.`),process.exit(1)),t&&c&&(e.w.error(`Please provide either a profile or an API key, not both`),process.exit(1)),t&&s&&e.w.warn(`Specifying ${e.C(`--api-url`)} with a profile won't have any effect. Using API url from profile.`),t&&!$t(t)){e.w.error(`Configuration profile ${e.C(t)} not found`),e.w.log(`Run ${e.C(`stackone init`)} to create a new configuration profile.\n`);let n=tn();n.length>0&&(e.w.info(`Available configuration profiles:`),n.forEach(t=>{e.w.log(` - ${i.default.blue(t)}`)})),process.exit(1)}let u=t?Qt(t):{apiUrl:s??sn,apiKey:c};u?.apiKey||(e.w.error(`API key is missing`),e.w.log(`Please provide a valid API key in the profile or via the ${e.C(`--api-key`)} option.`),process.exit(1)),(0,C.isMissing)(n)&&(0,C.isMissing)(r)&&(e.w.error(`Either ${e.C(`--connector`)} or ${e.C(`--account-id`)} must be provided`),process.exit(1)),(0,C.notMissing)(n)&&(0,C.notMissing)(r)&&(e.w.error(`Please provide either ${e.C(`--connector`)} or ${e.C(`--account-id`)}, not both.`),process.exit(1)),(0,C.notMissing)(a)&&a!==`yaml`&&a!==`json`&&(e.w.error(`Format must be either ${e.C(`yaml`)} or ${e.C(`json`)}.`),process.exit(1));let d=u.apiUrl??sn,f;if((0,C.notMissing)(n)){this.#t(n)||(e.w.error(`Invalid connector format ${e.S(n)}. Expected format: ${e.C(`provider_key@version`)} or ${e.C(`provider_key`)}`),process.exit(1));let t=this.#n(n);f=await this.#r(t,d,u.apiKey,a,l)}else (0,C.notMissing)(r)?f=await this.#i(r,d,u.apiKey,a):(e.w.error(`Either ${e.C(`--connector`)} or ${e.C(`--account-id`)} must be provided`),process.exit(1));if((0,C.notMissing)(o))try{m.default.writeFileSync(o,f,`utf-8`),e.w.success(`Connector written to file: ${e.C(o)}`)}catch(t){e.w.error(`Failed to write connector to file ${e.C(o)}: ${t.message}`),process.exit(1)}else if(e.w.log(`\n${i.default.blue.inverse(` CONNECTOR CONTENT `)}\n`),!a||a===`yaml`)e.w.log(this.#e(f));else if(a===`json`)try{e.b(JSON.parse(f))}catch{e.w.log(f)}else e.w.log(f);process.exit(0)}#e(e){return e.split(`
155
155
  `).map(e=>{if(e.trim().startsWith(`#`))return i.default.gray(e);if(e.includes(`:`)){let t=e.indexOf(`:`),n=e.substring(0,t+1),r=e.substring(t+1),a=r,o=r.trim();return o===`true`||o===`false`?a=r.replace(o,i.default.cyan(o)):o===`null`||o===`~`?a=r.replace(o,i.default.gray(o)):/^-?\d+(\.\d+)?$/.test(o)?a=r.replace(o,i.default.green(o)):(o.startsWith(`"`)&&o.endsWith(`"`)||o.startsWith(`'`)&&o.endsWith(`'`)||o&&!o.startsWith(`-`))&&(a=r.replace(o,i.default.yellow(o))),i.default.red(n)+a}return e.trim().startsWith(`-`)?e.replace(`-`,i.default.gray(`-`)):e}).join(`
156
156
  `)}#t=e=>!e.includes(`/`)&&!e.includes(`\\`)&&!e.endsWith(`.yaml`)&&!e.endsWith(`.yml`)?e.includes(`@`)?e.split(`@`).length===2:!0:!1;#n=e=>e.includes(`@`)?e:`${e}@latest`;async#r(t,n,r,i,a){let o=(0,v.default)(`Getting connector ${e.C(t)} from registry...`).start();try{let s=Buffer.from(r).toString(`base64`),c=i?`?format=${i}`:``,l=a?`${c?`&`:`?`}owner=${encodeURIComponent(a)}`:``,u=await fetch(`${n}/registry/connectors/${t}${c}${l}`,{method:`GET`,headers:{Authorization:`Basic ${s}`}});if(o.stop(),u.status===409){a&&(await e.x(u,`Failed to get connector ${e.C(t)} from the registry`),process.exit(1));let r=await on(t,(await u.json()).availableOwners??[]),i=`${n}/registry/connectors/${t}${c}${c?`&`:`?`}owner=${encodeURIComponent(r)}`;o.text=`Getting connector ${e.C(t)} from registry...`,o.start();let l=await fetch(i,{method:`GET`,headers:{Authorization:`Basic ${s}`}});return o.stop(),l.ok||(await e.x(l,`Failed to get connector ${e.C(t)} from the registry`),process.exit(1)),await l.text()}return u.ok||(await e.x(u,`Failed to get connector ${e.C(t)} from the registry`),process.exit(1)),await u.text()}catch(r){o.stop(),e.w.error(`Failed to get connector ${e.C(t)} from the registry: ${r.message}`),e.w.log(`Please ensure that the API at ${e.T(n)} is reachable and the API key is valid`),process.exit(1)}}async#i(t,n,r,i){let a=(0,v.default)(`Getting connector from account ${e.C(t)}...`).start();try{let o=Buffer.from(r).toString(`base64`),s=i?`?format=${i}`:``,c=await fetch(`${n}/accounts/${t}/connector${s}`,{method:`GET`,headers:{Authorization:`Basic ${o}`}});return a.stop(),c.ok||(await e.x(c,`Failed to get connector from account ${e.C(t)}`),process.exit(1)),await c.text()}catch(r){a.stop(),e.w.error(`Failed to get connector from account ${e.C(t)}: ${r.message}`),e.w.log(`Please ensure that the API at ${e.T(n)} is reachable and the API key is valid`),process.exit(1)}}};const ln=`https://api.stackone.com`,un=`https://api.stackone-dev.com`,dn=`http://localhost:4000`;var fn=class{async execute({environment:t}={}){let n=t?.toLowerCase()??`production`;try{(0,w.intro)(`${i.default.inverse(` Initialize profile `)}`);let t=await(0,w.text)({message:`Profile label`,validate:e=>{if(!e||e.trim().length===0)return`The profile label is required`;if(e.includes(` `))return`The profile label cannot contain spaces`}});if((0,w.isCancel)(t))return(0,w.cancel)(`Configuration profile initialization cancelled`),process.exit(0);if($t(t)){let n=await(0,w.confirm)({message:`Configuration profile with name ${e.C(t)} already exists. Do you want to overwrite it?`});if((0,w.isCancel)(n)||!n)return(0,w.cancel)(`Configuration profile initialization cancelled`),process.exit(0)}let r;if(n===`production`)r=`https://api.stackone.com`;else if(n===`staging`)r=`https://api.stackone-dev.com`;else{let e=await(0,w.text)({message:`API URL`,placeholder:dn,initialValue:dn,validate:e=>{if(!e||e.trim().length===0)return`API URL is required`;try{new URL(e)}catch{return`Please enter a valid URL`}}});if((0,w.isCancel)(e))return(0,w.cancel)(`Configuration profile initialization cancelled`),process.exit(0);r=e}let a=await(0,w.password)({message:`API Key`,validate:e=>{if(!e||e.trim().length===0)return`API Key is required`}});if((0,w.isCancel)(a))return(0,w.cancel)(`Configuration profile initialization cancelled`),process.exit(0);en(t,{label:t,environment:n,apiUrl:r,apiKey:a}),(0,w.outro)(`${i.default.green(`✔`)} Configuration profile ${e.C(t)} initialized successfully!`),process.exit(0)}catch(t){t?.isTtyError?e.w.error(`Prompt couldn't be rendered in the current environment`):e.w.error(`Failed to initialize configuration profile: ${t}`),process.exit(1)}}};const pn=20,$={pending:`○`,acceptRemote:`●`,acceptLocal:`◐`,acceptBoth:`◑`,current:`◉`,arrow:`→`,check:`✓`,cross:`✗`,warning:`⚠`};var mn=class{constructor(e,t,n,r){this.conflicts=[],this.currentIndex=0,this.totalConflicts=0,this.currentCleanup=null,this.connectorId=t,this.localVersion=n,this.remoteVersion=r,this.conflicts=e.map(e=>({conflict:e,choice:e.type===`unchanged`?`remote`:`pending`})),this.totalConflicts=e.filter(e=>e.type===`conflict`).length}resetForReResolution(){this.currentIndex=0}async resolve(){return this.totalConflicts===0?{cancelled:!1,states:this.conflicts}:(this.moveToNextConflict(),new Promise(e=>{let t=(0,ee.createInterface)({input:process.stdin,output:process.stdout});process.stdin.isTTY&&process.stdin.setRawMode(!0),process.stdin.resume(),this.render();let n=n=>{let r=n.toString();if(r===``){this.cleanup(t),this.renderCancelled(),e({cancelled:!0,states:this.conflicts});return}if(r===`\x1B`&&n.length===1){this.cleanup(t),this.renderCancelled(),e({cancelled:!0,states:this.conflicts});return}if(r.startsWith(`\x1B[`)){switch(r.slice(2)){case`D`:this.moveToPrevConflict(),this.render();break;case`C`:this.moveToNextConflict(),this.render();break}return}switch(r){case`r`:case`R`:this.setCurrentChoice(`remote`),this.advanceAfterChoice(t);break;case`l`:case`L`:this.setCurrentChoice(`local`),this.advanceAfterChoice(t);break;case`b`:case`B`:this.setCurrentChoice(`both`),this.advanceAfterChoice(t);break;case`\r`:case`
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- require(`./agentConfig-KBkYYmMr.cjs`);const e=require(`./cliCore-mMrBxsVZ.cjs`);require(`./setupMigration-rqPZ8MV6.cjs`),require(`./agentApiKey-BDp7EFMI.cjs`),exports.CLI=e.t;
1
+ require(`./agentConfig-KBkYYmMr.cjs`);const e=require(`./cliCore-_XY0Dk5a.cjs`);require(`./setupMigration-rqPZ8MV6.cjs`),require(`./agentApiKey-BDp7EFMI.cjs`),exports.CLI=e.t;
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{t as e}from"./cliCore-CeD5mOhR.mjs";import"./agentConfig-BWQWMYKQ.mjs";import"./setupMigration-C1ShGzOu.mjs";import"./agentApiKey-CWXxJgCO.mjs";export{e as CLI};
1
+ import{t as e}from"./cliCore-Dkwrx11F.mjs";import"./agentConfig-BWQWMYKQ.mjs";import"./setupMigration-C1ShGzOu.mjs";import"./agentApiKey-CWXxJgCO.mjs";export{e as CLI};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stackone/cli",
3
- "version": "1.43.1",
3
+ "version": "1.43.2",
4
4
  "description": "StackOne Connect CLI tool",
5
5
  "type": "module",
6
6
  "main": "dist/index.mjs",
@@ -37,10 +37,10 @@
37
37
  "@stackone/agent-config": "1.4.0",
38
38
  "@stackone/agent-harness": "0.16.0",
39
39
  "@stackone/connect-sdk": "2.102.0",
40
- "@stackone/core": "3.16.0",
40
+ "@stackone/core": "3.20.0",
41
41
  "@stackone/defender": "0.7.2",
42
42
  "@stackone/expressions": "0.37.0",
43
- "@stackone/transport": "2.28.2",
43
+ "@stackone/transport": "2.30.0",
44
44
  "@stackone/utils": "1.2.0",
45
45
  "chalk": "5.6.2",
46
46
  "chokidar": "5.0.0",