inscope 0.8.7 → 0.8.8
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/README.md +2 -2
- package/dist/bin/index.mjs +35 -35
- package/dist/index.mjs +10 -10
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -133,7 +133,7 @@ Create the config, generate the chpwd hook, and add a source line to `~/.zshrc`.
|
|
|
133
133
|
Map a directory. Run it bare and it walks you through everything: pick the GitHub account from your signed-in `gh` accounts, accept your global git identity or set a per-workspace one, and toggle which MCP servers to enable. Enabling Slack adds a keychain prompt and a Yes/No for posting messages. Pass any flag to skip its prompt, or `-y` to take the defaults non-interactively (for scripts and CI).
|
|
134
134
|
|
|
135
135
|
<p align="center">
|
|
136
|
-
<img src="https://raw.githubusercontent.com/nrjdalal/inscope/main/.github/assets/add.gif" alt="inscope add: gh picker, git identity, server multiselect, and the Slack prompts" width="900" />
|
|
136
|
+
<img src="https://raw.githubusercontent.com/nrjdalal/inscope/main/.github/assets/add.gif" alt="inscope add: gh picker, git identity, server multiselect, the Slack package picker, and the Slack prompts" width="900" />
|
|
137
137
|
</p>
|
|
138
138
|
|
|
139
139
|
```
|
|
@@ -180,7 +180,7 @@ List the configured workspaces with their path, gh account, git email, and enabl
|
|
|
180
180
|
|
|
181
181
|
### `inscope diff`
|
|
182
182
|
|
|
183
|
-
Preview exactly what `apply` would write: a colored diff of the hook, git includes, and each `.mcp.json` against your config. `--adopt` pulls config-expressible on-disk settings (a Slack add-message tool, a custom server URL) back into the config, so the next apply keeps them instead of dropping them. `--exit-code` exits non-zero when anything is out of sync, so it works as a CI or pre-commit gate.
|
|
183
|
+
Preview exactly what `apply` would write: a colored diff of the hook, git includes, and each `.mcp.json` against your config. `--adopt` pulls config-expressible on-disk settings (a Slack add-message tool or package, a custom server URL) back into the config, so the next apply keeps them instead of dropping them. `--exit-code` exits non-zero when anything is out of sync, so it works as a CI or pre-commit gate.
|
|
184
184
|
|
|
185
185
|
<p align="center">
|
|
186
186
|
<img src="https://raw.githubusercontent.com/nrjdalal/inscope/main/.github/assets/diff.gif" alt="inscope diff: colored drift, then --adopt back-syncs an on-disk setting into the config" width="900" />
|
package/dist/bin/index.mjs
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import e from"node:fs";import{parseArgs as t}from"node:util";import n from"node:path";import r from"node:os";import{spawnSync as i}from"node:child_process";import a from"node:readline";const o=()=>process.env.HOME?.trim()||r.homedir(),s=()=>process.env.XDG_CONFIG_HOME?.trim()||n.join(o(),`.config`),c=e=>e===`~`?o():e.startsWith(`~/`)?n.join(o(),e.slice(2)):e,l=e=>{let t=c(e),r=o();return t===r?`~`:t.startsWith(r+n.sep)?`~/`+t.slice(r.length+1):t},u=e=>n.resolve(c(e)),d=()=>n.join(s(),`inscope`),f=()=>n.join(d(),`inscope.json`),p=()=>n.join(d(),`inscope.zsh`),m=()=>n.join(d(),`git`),h=()=>n.join(o(),`.gitconfig`),g=()=>n.join(o(),`.zshrc`),_=t=>{try{return e.readFileSync(t,`utf8`)}catch{return null}},v=e=>_(e)??``,y=(t,r)=>{let i=t;try{i=e.realpathSync(t)}catch{}let a=n.dirname(i);e.mkdirSync(a,{recursive:!0});let o;try{o=e.statSync(i).mode}catch{}let s=n.join(a,`.${n.basename(i)}.inscope-${process.pid}.tmp`);e.writeFileSync(s,r),o!==void 0&&e.chmodSync(s,o&4095);try{e.renameSync(s,i)}catch(t){try{e.rmSync(s,{force:!0})}catch{}throw t}},b=[`slack-mcp-server`,`@nrjdalal/slack-mcp-server`],x=`slack-mcp-server`,S=()=>({version:1,workspaces:[]}),C=()=>e.existsSync(f()),w=()=>{let t=f(),n=e.readFileSync(t,`utf8`),r;try{r=JSON.parse(n)}catch{throw Error(`${l(t)} is not valid JSON; fix it, then re-run.`)}let i=ae(r);if(i)throw Error(i);try{D(r)}catch(e){let n=e instanceof Error?e.message:String(e);throw Error(`${n}\nFix it in ${l(t)}, then re-run.`)}return r},T=e=>{D(e),y(f(),JSON.stringify(e,null,2)+`
|
|
3
|
-
`)},ee=/^[A-Za-z0-9._-]+$/,te=e=>e?ee.test(e)?null:`use only letters, digits, dot (.), dash (-), or underscore (_)`:`must not be empty`,ne=/[\\"`$\n]/,E=e=>ne.test(e)?'must not contain a backslash (\\), quote ("), backtick (`), $, or newline':null,re=e=>e?E(e):`must not be empty`,ie=e=>/[\n\r]/.test(e)?`must not contain a newline`:null,ae=e=>typeof e.version==`number`&&e.version>1?`config version ${e.version} is newer than this inscope supports (max 1); upgrade inscope`:null,oe=e=>e.toLowerCase().replace(/[^a-z0-9._-]+/g,`-`).replace(/^[-.]+|[-.]+$/g,``),D=e=>{if(!e||typeof e!=`object`)throw Error(`config is not an object`);let t=ae(e);if(t)throw Error(t);if(!Array.isArray(e.workspaces))throw Error(`config.workspaces must be an array`);let n=new Set;for(let t of e.workspaces){if(!t.name)throw Error(`a workspace is missing a name`);let e=te(t.name);if(e)throw Error(`workspace name "${t.name}" is invalid: ${e}`);if(!t.path)throw Error(`workspace "${t.name}" is missing a path`);let r=re(t.path);if(r)throw Error(`workspace "${t.name}" path "${t.path}" is invalid: ${r}`);if(t.gh){let e=E(t.gh);if(e)throw Error(`workspace "${t.name}" gh account "${t.gh}" is invalid: ${e}`)}if(t.git?.email){let e=ie(t.git.email);if(e)throw Error(`workspace "${t.name}" git email "${t.git.email}" is invalid: ${e}`)}if(t.git?.name){let e=ie(t.git.name);if(e)throw Error(`workspace "${t.name}" git name "${t.git.name}" is invalid: ${e}`)}let i=t.servers?.slack;if(i&&i.keychain){let e=E(i.keychain);if(e)throw Error(`workspace "${t.name}" Slack keychain "${i.keychain}" is invalid: ${e}`)}let a=i&&i.package;if(a&&!b.includes(a))throw Error(`workspace "${t.name}" Slack package "${a}" is invalid: use one of ${b.join(`, `)}`);if(n.has(t.name))throw Error(`duplicate workspace name "${t.name}"`);n.add(t.name)}},se=e=>oe(n.basename(u(e)))||`workspace`,O=(e,t)=>{let n=e.workspaces.find(e=>e.name===t);if(n)return n;let r=u(t);return e.workspaces.find(e=>u(e.path)===r)},ce=(e,t,n)=>{let r=u(t);return e.workspaces.find(e=>e.name!==n&&u(e.path)===r)},le=(e,t)=>{let n=e.workspaces.filter(e=>e.name!==t.name);return n.push({...t,path:l(t.path)}),n.sort((e,t)=>e.name.localeCompare(t.name)),{...e,workspaces:n}},ue=(e,t)=>{let n=O(e,t);return n?{cfg:{...e,workspaces:e.workspaces.filter(e=>e.name!==n.name)},removed:n}:{cfg:e}},de=(e=x)=>e===`@nrjdalal/slack-mcp-server`?`@nrjdalal/slack-mcp-server@latest`:`slack-mcp-server@1.3.0`,k={atlassian:`https://mcp.atlassian.com/v1/mcp`,canva:`https://mcp.canva.com/mcp`,clickup:`https://mcp.clickup.com/mcp`,hubspot:`https://mcp.hubspot.com`,intercom:`https://mcp.intercom.com/mcp`,linear:`https://mcp.linear.app/mcp`,monday:`https://mcp.monday.com/mcp`,notion:`https://mcp.notion.com/mcp`,plane:`https://mcp.plane.so/http/mcp`,sentry:`https://mcp.sentry.dev/mcp`,stripe:`https://mcp.stripe.com`,vercel:`https://mcp.vercel.com`,webflow:`https://mcp.webflow.com/`},A=[`github`,`atlassian`,`canva`,`clickup`,`hubspot`,`intercom`,`linear`,`monday`,`notion`,`plane`,`sentry`,`slack`,`stripe`,`vercel`,`webflow`],
|
|
4
|
-
`,
|
|
3
|
+
`)},ee=/^[A-Za-z0-9._-]+$/,te=e=>e?ee.test(e)?null:`use only letters, digits, dot (.), dash (-), or underscore (_)`:`must not be empty`,ne=/[\\"`$\n]/,E=e=>ne.test(e)?'must not contain a backslash (\\), quote ("), backtick (`), $, or newline':null,re=e=>e?E(e):`must not be empty`,ie=e=>/[\n\r]/.test(e)?`must not contain a newline`:null,ae=e=>typeof e.version==`number`&&e.version>1?`config version ${e.version} is newer than this inscope supports (max 1); upgrade inscope`:null,oe=e=>e.toLowerCase().replace(/[^a-z0-9._-]+/g,`-`).replace(/^[-.]+|[-.]+$/g,``),D=e=>{if(!e||typeof e!=`object`)throw Error(`config is not an object`);let t=ae(e);if(t)throw Error(t);if(!Array.isArray(e.workspaces))throw Error(`config.workspaces must be an array`);let n=new Set;for(let t of e.workspaces){if(!t.name)throw Error(`a workspace is missing a name`);let e=te(t.name);if(e)throw Error(`workspace name "${t.name}" is invalid: ${e}`);if(!t.path)throw Error(`workspace "${t.name}" is missing a path`);let r=re(t.path);if(r)throw Error(`workspace "${t.name}" path "${t.path}" is invalid: ${r}`);if(t.gh){let e=E(t.gh);if(e)throw Error(`workspace "${t.name}" gh account "${t.gh}" is invalid: ${e}`)}if(t.git?.email){let e=ie(t.git.email);if(e)throw Error(`workspace "${t.name}" git email "${t.git.email}" is invalid: ${e}`)}if(t.git?.name){let e=ie(t.git.name);if(e)throw Error(`workspace "${t.name}" git name "${t.git.name}" is invalid: ${e}`)}let i=t.servers?.slack;if(i&&i.keychain){let e=E(i.keychain);if(e)throw Error(`workspace "${t.name}" Slack keychain "${i.keychain}" is invalid: ${e}`)}let a=i&&i.package;if(a&&!b.includes(a))throw Error(`workspace "${t.name}" Slack package "${a}" is invalid: use one of ${b.join(`, `)}`);if(n.has(t.name))throw Error(`duplicate workspace name "${t.name}"`);n.add(t.name)}},se=e=>oe(n.basename(u(e)))||`workspace`,O=(e,t)=>{let n=e.workspaces.find(e=>e.name===t);if(n)return n;let r=u(t);return e.workspaces.find(e=>u(e.path)===r)},ce=(e,t,n)=>{let r=u(t);return e.workspaces.find(e=>e.name!==n&&u(e.path)===r)},le=(e,t)=>{let n=e.workspaces.filter(e=>e.name!==t.name);return n.push({...t,path:l(t.path)}),n.sort((e,t)=>e.name.localeCompare(t.name)),{...e,workspaces:n}},ue=(e,t)=>{let n=O(e,t);return n?{cfg:{...e,workspaces:e.workspaces.filter(e=>e.name!==n.name)},removed:n}:{cfg:e}},de=(e=x)=>e===`@nrjdalal/slack-mcp-server`?`@nrjdalal/slack-mcp-server@latest`:`slack-mcp-server@1.3.0`,fe=e=>{if(!Array.isArray(e))return null;let t=e.find(e=>typeof e==`string`&&e.includes(`slack-mcp-server`));return t?t.startsWith(`@nrjdalal/slack-mcp-server`)?`@nrjdalal/slack-mcp-server`:t.startsWith(`slack-mcp-server`)?`slack-mcp-server`:null:null},k={atlassian:`https://mcp.atlassian.com/v1/mcp`,canva:`https://mcp.canva.com/mcp`,clickup:`https://mcp.clickup.com/mcp`,hubspot:`https://mcp.hubspot.com`,intercom:`https://mcp.intercom.com/mcp`,linear:`https://mcp.linear.app/mcp`,monday:`https://mcp.monday.com/mcp`,notion:`https://mcp.notion.com/mcp`,plane:`https://mcp.plane.so/http/mcp`,sentry:`https://mcp.sentry.dev/mcp`,stripe:`https://mcp.stripe.com`,vercel:`https://mcp.vercel.com`,webflow:`https://mcp.webflow.com/`},A=[`github`,`atlassian`,`canva`,`clickup`,`hubspot`,`intercom`,`linear`,`monday`,`notion`,`plane`,`sentry`,`slack`,`stripe`,`vercel`,`webflow`],pe=e=>A.map(t=>`${t}-${e}`),j=e=>n.join(u(e.path),`.mcp.json`),me=(e,t)=>e&&typeof e==`object`&&e.url?e.url:t,he=e=>{let t=e.servers,n={};for(let r of A){let i=t[r];if(!i)continue;let a=`${r}-${e.name}`;if(r===`github`)n[a]={type:`http`,url:`https://api.githubcopilot.com/mcp/`,headers:{Authorization:"Bearer ${GITHUB_TOKEN}"}};else if(r===`slack`){let e=i,t=e.package??x,r={SLACK_MCP_XOXP_TOKEN:"${SLACK_MCP_XOXP_TOKEN}"},o=[`-y`,de(t)];t===`@nrjdalal/slack-mcp-server`?e.addMessageTool||(r.SLACK_MCP_ALLOW_WRITE=`false`):(o.push(`--transport`,`stdio`),e.addMessageTool&&(r.SLACK_MCP_ADD_MESSAGE_TOOL=`true`)),n[a]={type:`stdio`,command:`npx`,args:o,env:r}}else n[a]={type:`http`,url:me(i,k[r])}}return n},ge=t=>{if(!e.existsSync(t))return{};try{return JSON.parse(e.readFileSync(t,`utf8`))}catch{return{}}},M=t=>{if(!e.existsSync(t))return{};try{return JSON.parse(e.readFileSync(t,`utf8`))}catch{throw Error(`${t} is not valid JSON; fix or remove it, then re-run inscope (left it untouched)`)}},_e=t=>{let n=j(t);return e.existsSync(n)?ge(n):null},ve=(e,t)=>{let n=e.mcpServers&&typeof e.mcpServers==`object`?{...e.mcpServers}:{};for(let e of pe(t.name))delete n[e];return Object.assign(n,he(t)),{...e,mcpServers:n}},N=e=>JSON.stringify(e,null,2)+`
|
|
4
|
+
`,ye=e=>{for(let t of e)M(j(t))},be=e=>{let t=j(e);y(t,N(ve(M(t),e)))},xe=t=>{let n=j(t);if(!e.existsSync(n))return;let r=M(n);if(r.mcpServers&&typeof r.mcpServers==`object`)for(let e of pe(t.name))delete r.mcpServers[e];y(n,N(r))},P=(e,t,n)=>{let r=i(e,t,{encoding:`utf8`,input:n?.input});return{status:r.status??(r.error?127:1),stdout:r.stdout??``,stderr:r.stderr??``}},Se=()=>process.platform===`darwin`,F=()=>process.env.USER||``,Ce=(e,t=P)=>{let n=t(`gh`,[`auth`,`token`,`-u`,e]),r=n.stdout.trim();return n.status===0&&r?r:null},we=(e=P)=>{let t=e(`gh`,[`auth`,`status`]);return(t.stdout+t.stderr).trim()},Te=(e=P)=>{let t=[];for(let n of we(e).matchAll(/account (\S+) \(/g))t.includes(n[1])||t.push(n[1]);return t},Ee=(e,t=P)=>{let n=t(`git`,[`config`,`--global`,e]),r=n.stdout.trim();return n.status===0&&r?r:null},De=(e,t=P)=>{let n=t(`security`,[`find-generic-password`,`-a`,F(),`-s`,e,`-w`]);return n.status===0&&n.stdout.trim().length>0},Oe=(e,t,n=P)=>{let r=n(`security`,[`add-generic-password`,`-U`,`-a`,F(),`-s`,e,`-w`,t]);if(r.status!==0)throw Error(`security add-generic-password failed: ${r.stderr.trim()||`unknown error`}`)},ke=e=>`security add-generic-password -U -a "${F()||`$USER`}" -s ${e} -w 'xoxp-...'`,Ae=(e,t=P)=>{let n=t(`git`,[`config`,`--file`,e,`user.email`]);return n.status===0?n.stdout.trim():null},I=()=>!!(process.stdin.isTTY&&process.stdout.isTTY),je=(e,t=e)=>process.stdout.isTTY?`\x1b]8;;${e}\x07${t}\x1b]8;;\x07`:e,L=e=>t=>process.stdout.isTTY?`\x1b[${e}m${t}\x1b[0m`:t,R=L(`38;5;208`),Me=L(`38;2;63;185;80`),z=L(`38;2;210;153;34`),B=L(`38;2;248;81;73`),V=e=>{let t=process.stdin;t.isTTY&&typeof t.setRawMode==`function`&&t.setRawMode(e)},Ne=()=>{V(!0),process.stdin.resume();let e=()=>V(!1);return process.once(`exit`,e),()=>{process.removeListener(`exit`,e),V(!1),process.stdin.pause()}};let H=``;const Pe=e=>new Promise(t=>{process.stdout.write(e);let n=()=>{let e=H.indexOf(`
|
|
5
5
|
`);if(e<0)return!1;let n=H.slice(0,e).replace(/\r$/,``);return H=H.slice(e+1),t(n),!0};if(n())return;let r=e=>{H+=e.toString(`utf8`),H.includes(`
|
|
6
|
-
`)&&(process.stdin.off(`data`,r),process.stdin.off(`end`,i),process.stdin.pause(),n())},i=()=>{process.stdin.off(`data`,r),process.stdin.off(`end`,i);let e=H.replace(/\r$/,``);H=``,t(e)};process.stdin.on(`data`,r),process.stdin.on(`end`,i),process.stdin.resume()}),U=async(e,t=``)=>(await
|
|
7
|
-
`),n.close(),t(e.trim())})}),
|
|
8
|
-
`);let s=e=>{e||o.write(`\x1b[${t.length}A`);for(let e=0;e<t.length;e++){let n=e===i,r=`${n?`❯`:` `} ${t[e].label}`;o.write(`\x1b[2K ${n?
|
|
9
|
-
`),process.exit(130))};process.stdin.on(`keypress`,u)}),
|
|
10
|
-
`);let c=e=>{e||s.write(`\x1b[${t.length}A`);for(let e=0;e<t.length;e++){let n=e===o,i=`${n?`❯`:` `} ${r[e]?`◉`:`◯`} ${t[e].label}`;s.write(`\x1b[2K ${n?
|
|
11
|
-
`),process.exit(130))};process.stdin.on(`keypress`,d)}),K=e=>`# >>> inscope:${e} >>>`,
|
|
12
|
-
|
|
13
|
-
`).replace(/^\n+/,``))},
|
|
14
|
-
`),
|
|
6
|
+
`)&&(process.stdin.off(`data`,r),process.stdin.off(`end`,i),process.stdin.pause(),n())},i=()=>{process.stdin.off(`data`,r),process.stdin.off(`end`,i);let e=H.replace(/\r$/,``);H=``,t(e)};process.stdin.on(`data`,r),process.stdin.on(`end`,i),process.stdin.resume()}),U=async(e,t=``)=>(await Pe(`${e}${t?` [${t}]`:``}: `)).trim()||t,W=async(e,t=!1)=>{if(!I()){let n=(await Pe(`${e} [${t?`Y/n`:`y/N`}]: `)).trim().toLowerCase();return n?n===`y`||n===`yes`:t}return G(e,[{label:`Yes`,value:!0},{label:`No`,value:!1}],t?0:1)},Fe=e=>new Promise(t=>{let n=a.createInterface({input:process.stdin,output:process.stdout}),r=n.output,i=!1;n._writeToOutput=t=>{if(!i){r.write(t),t.includes(e)&&(i=!0);return}},n.question(e,e=>{r.write(`
|
|
7
|
+
`),n.close(),t(e.trim())})}),Ie=`\x1B[36m`,Le=`\x1B[0m`,G=(e,t,n=0)=>new Promise(r=>{if(!I()||t.length===0){r(t[Math.min(n,t.length-1)]?.value);return}let i=Math.max(0,Math.min(n,t.length-1)),o=process.stdout;o.write(e+`
|
|
8
|
+
`);let s=e=>{e||o.write(`\x1b[${t.length}A`);for(let e=0;e<t.length;e++){let n=e===i,r=`${n?`❯`:` `} ${t[e].label}`;o.write(`\x1b[2K ${n?Ie+r+Le:r}\n`)}};s(!0),a.emitKeypressEvents(process.stdin);let c=Ne(),l=()=>{process.stdin.off(`keypress`,u),c()},u=(e,n)=>{n.name===`up`||n.name===`k`?(i=(i-1+t.length)%t.length,s(!1)):n.name===`down`||n.name===`j`?(i=(i+1)%t.length,s(!1)):n.name===`return`||n.name===`enter`?(l(),r(t[i].value)):n.ctrl&&n.name===`c`&&(l(),o.write(`
|
|
9
|
+
`),process.exit(130))};process.stdin.on(`keypress`,u)}),Re=(e,t)=>new Promise(n=>{let r=t.map(e=>!!e.checked),i=()=>t.filter((e,t)=>r[t]).map(e=>e.value);if(!I()||t.length===0){n(i());return}let o=0,s=process.stdout;s.write(e+`
|
|
10
|
+
`);let c=e=>{e||s.write(`\x1b[${t.length}A`);for(let e=0;e<t.length;e++){let n=e===o,i=`${n?`❯`:` `} ${r[e]?`◉`:`◯`} ${t[e].label}`;s.write(`\x1b[2K ${n?Ie+i+Le:i}\n`)}};c(!0),a.emitKeypressEvents(process.stdin);let l=Ne(),u=()=>{process.stdin.off(`keypress`,d),l()},d=(e,a)=>{a.name===`up`||a.name===`k`?(o=(o-1+t.length)%t.length,c(!1)):a.name===`down`||a.name===`j`?(o=(o+1)%t.length,c(!1)):a.name===`space`||e===` `?(r[o]=!r[o],c(!1)):a.name===`return`||a.name===`enter`?(u(),n(i())):a.ctrl&&a.name===`c`&&(u(),s.write(`
|
|
11
|
+
`),process.exit(130))};process.stdin.on(`keypress`,d)}),K=e=>`# >>> inscope:${e} >>>`,ze=e=>`# <<< inscope:${e} <<<`,q=e=>e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),Be=e=>RegExp(`${q(K(e))}\\n[\\s\\S]*?\\n${q(ze(e))}\\n?`),Ve=(e,t)=>{let n=t.replace(/\n+$/,``);return`${K(e)}\n${n}\n${ze(e)}\n`},He=(e,t,n)=>{let r=v(e),i=Ve(t,n),a=Be(t),o;if(a.test(r))o=r.replace(a,i);else{let e=r.replace(/\n*$/,``);o=e.length?`${e}\n\n${i}`:i}y(e,o)},Ue=(e,t)=>{let n=v(e);n&&y(e,n.replace(Be(t),``).replace(/\n{3,}/g,`
|
|
12
|
+
|
|
13
|
+
`).replace(/^\n+/,``))},We=(e,t)=>{let n=v(e).match(RegExp(`${q(K(t))}\\n([\\s\\S]*?)\\n${q(ze(t))}`));return n?n[1]:null},J=`gitconfig`,Y=e=>!!(e.git&&(e.git.email||e.git.name)),X=e=>n.join(m(),`${e}.gitconfig`),Ge=e=>l(e).replace(/\/+$/,``)+`/`,Ke=e=>e.workspaces.filter(Y).map(e=>`[includeIf "gitdir:${Ge(e.path)}"]\n\tpath = ${l(X(e.name))}`).join(`
|
|
14
|
+
`),qe=e=>{let t=[`# Managed by inscope. Do not edit by hand.`,`[user]`];return e.git?.email&&t.push(`\temail = ${e.git.email}`),e.git?.name&&t.push(`\tname = ${e.git.name}`),t.join(`
|
|
15
15
|
`)+`
|
|
16
|
-
`},
|
|
16
|
+
`},Je=t=>{e.mkdirSync(m(),{recursive:!0});for(let e of t.workspaces)Y(e)?y(X(e.name),qe(e)):Ye(e.name);let n=Ke(t);n?He(h(),J,n):Ue(h(),J)},Ye=t=>{let n=X(t);e.existsSync(n)&&e.rmSync(n)},Xe=e=>{let t=l(e);return t===`~`?`"$HOME/"*`:t.startsWith(`~/`)?`"$HOME/${t.slice(2)}/"*`:`"${t}/"*`},Ze=e=>e.servers.slack?e.servers.slack.keychain:``,Qe=e=>{let t=[...e.workspaces].sort((e,t)=>e.name.localeCompare(t.name));return`# Managed by inscope. Do not edit by hand.
|
|
17
17
|
# Source of truth: ~/.config/inscope/inscope.json
|
|
18
18
|
# Edit there, then run \`inscope apply\` to regenerate this file.
|
|
19
19
|
#
|
|
@@ -24,7 +24,7 @@ import e from"node:fs";import{parseArgs as t}from"node:util";import n from"node:
|
|
|
24
24
|
__inscope_resolve_identity() {
|
|
25
25
|
local ws
|
|
26
26
|
case "\${PWD}/" in
|
|
27
|
-
${[...t].sort((e,t)=>l(t.path).length-l(e.path).length).map(e=>` ${
|
|
27
|
+
${[...t].sort((e,t)=>l(t.path).length-l(e.path).length).map(e=>` ${Xe(e.path)}) ws="${e.name}" ;;`).join(`
|
|
28
28
|
`)||` # no workspaces configured`}
|
|
29
29
|
*) ws="" ;;
|
|
30
30
|
esac
|
|
@@ -34,7 +34,7 @@ ${[...t].sort((e,t)=>l(t.path).length-l(e.path).length).map(e=>` ${Ye(e.path)
|
|
|
34
34
|
|
|
35
35
|
local gh_user="" slack_svc=""
|
|
36
36
|
case "$ws" in
|
|
37
|
-
${t.map(e=>{let t=[];e.gh&&t.push(`gh_user="${e.gh}"`);let n=
|
|
37
|
+
${t.map(e=>{let t=[];e.gh&&t.push(`gh_user="${e.gh}"`);let n=Ze(e);return n&&t.push(`slack_svc="${n}"`),` ${e.name}) ${t.length?t.join(`; `):`:`} ;;`}).join(`
|
|
38
38
|
`)||` # no workspaces configured`}
|
|
39
39
|
*) return ;; # outside a mapped workspace: nothing set
|
|
40
40
|
esac
|
|
@@ -60,8 +60,8 @@ autoload -Uz add-zsh-hook
|
|
|
60
60
|
add-zsh-hook chpwd __inscope_resolve_identity
|
|
61
61
|
__inscope_ws="__init__" # force the first resolve, clearing any inherited token
|
|
62
62
|
__inscope_resolve_identity
|
|
63
|
-
`}
|
|
64
|
-
No token entered; skipped keychain write.`)}else
|
|
63
|
+
`},$e=e=>{let t=o();return e===t?`$HOME`:e.startsWith(t+n.sep)?`$HOME/${e.slice(t.length+1)}`:e},et=()=>{let e=$e(p());return`[ -r "${e}" ] && source "${e}"`},tt=e=>{let t=et();if(e.includes(t))return e;let n=e.replace(/\n*$/,``),r=`# inscope: load each workspace's tokens (GitHub, Slack) from \$PWD on every cd\n${t}`;return n.length?`${n}\n\n${r}\n`:`${r}\n`},nt=()=>{let e=g(),t=v(e),n=tt(t);n!==t&&y(e,n)},rt=()=>v(g()).includes(et()),Z=e=>{ye(e.workspaces);let t=p();y(t,Qe(e)),Je(e),nt();let n=[];for(let t of e.workspaces)be(t),n.push(j(t));return{hook:t,gitconfig:e.workspaces.some(e=>e.git?.email||e.git?.name),mcp:n}},it=A,at=e=>`SLACK_MCP_XOXP_TOKEN_${e.toUpperCase().replace(/[^A-Z0-9]+/g,`_`)}`,ot=e=>A.filter(t=>!!e[t]),st=(e,t)=>{let n={};for(let r of A)if(r===`slack`){if(!t){n[r]=!1;continue}let e={keychain:t.keychain,addMessageTool:t.addMessageTool};t.package&&t.package!==x&&(e.package=t.package),n[r]=e}else n[r]=e.includes(r);return n},Q=[{label:`slack-mcp-server (korotovsky, pinned)`,value:`slack-mcp-server`},{label:`@nrjdalal/slack-mcp-server (latest)`,value:`@nrjdalal/slack-mcp-server`}],ct=e=>{let t=(e??``).trim().toLowerCase();return t?[`@nrjdalal/slack-mcp-server`,`nrjdalal`,`nrj`].includes(t)?`@nrjdalal/slack-mcp-server`:[`slack-mcp-server`,`default`,`original`,`korotovsky`].includes(t)?`slack-mcp-server`:null:x},lt=e=>e?`global: ${e}`:`no global set`,ut=e=>{let t=C()?w():S(),n=t.workspaces.find(t=>t.name===e.name),r=le(t,e);T(r),Z(r),n&&u(n.path)!==u(e.path)&&xe(n)},dt=async(e,t)=>{if(!e.servers.slack)return;let n=e.servers.slack.keychain;if(t){let e=await Fe(`Paste the Slack xoxp token for ${n}: `);e?(Oe(n,e),console.log(`\n✓ stored ${n} in the macOS keychain`)):console.error(`
|
|
64
|
+
No token entered; skipped keychain write.`)}else De(n)||console.log(`\nSlack token not in the keychain yet. Store it once with:\n${R(ke(n))}\n\nSetup guide: ${R(je(`https://github.com/korotovsky/slack-mcp-server/blob/HEAD/docs/01-authentication-setup.md#option-2-using-slack_mcp_xoxp_token-user-oauth`))}`)};var $=`inscope`,ft=`0.8.8`,pt={name:`Neeraj Dalal`,email:`admin@nrjdalal.com`,url:`https://nrjdalal.com`};const mt=`Map a directory to a GitHub account, git email, and MCP servers.
|
|
65
65
|
Runs interactively in a terminal; pass flags or -y to skip the prompts. Re-running
|
|
66
66
|
with the same label updates that workspace; each directory maps to one workspace.
|
|
67
67
|
|
|
@@ -84,27 +84,27 @@ Options:
|
|
|
84
84
|
--slack-message allow the Slack MCP server to post messages
|
|
85
85
|
--seed-slack prompt for the Slack token and store it in the keychain
|
|
86
86
|
-y, --yes accept defaults, skip all prompts (non-interactive)
|
|
87
|
-
-h, --help Display help message`,
|
|
87
|
+
-h, --help Display help message`,ht=A.map(e=>({label:e,value:e,checked:e===`github`})),gt=async n=>{let{positionals:r,values:i}=t({allowPositionals:!0,options:{help:{type:`boolean`,short:`h`},yes:{type:`boolean`,short:`y`},gh:{type:`string`},email:{type:`string`},"git-name":{type:`string`},label:{type:`string`},servers:{type:`string`},"slack-keychain":{type:`string`},"slack-package":{type:`string`},"slack-message":{type:`boolean`},"seed-slack":{type:`boolean`}},args:n});i.help&&(console.log(mt),process.exit(0));let a=I()&&!i.yes;a&&console.log();let o=r[0];if(!o)if(a)o=await U(`Workspace directory`,process.cwd());else throw Error(mt);let s=re(o);s&&(console.error(`\nInvalid workspace path "${o}": ${s}`),process.exit(1)),e.existsSync(u(o))||console.error(z(`Warning: ${l(o)} does not exist yet; it will be created.`)+`
|
|
88
88
|
`);let c=i.label||se(o);a&&!i.label&&(c=await U(`Label`,c));let d=te(c);if(d&&(console.error(`\nInvalid label "${c}": ${d}`),process.exit(1)),C()){let e=ce(w(),o,c);e&&(console.error(`\n${l(o)} is already mapped to workspace "${e.name}". Run \`${$} edit ${e.name}\` to change it, or \`${$} rm ${e.name}\` first.`),process.exit(1))}let f=i.gh;f===void 0&&a&&(f=await G(`
|
|
89
|
-
GitHub account for this workspace`,[...
|
|
90
|
-
Slack uses a user OAuth (xoxp) token.`),i[`slack-package`]||(x=await G(`Slack MCP server package`,Q,Math.max(0,Q.findIndex(e=>e.value===x)))),i[`slack-keychain`]||(_=await U(`Slack keychain service`,_)),i[`slack-message`]||(v=await W(`Allow Slack to post messages?`,!0)),i[`seed-slack`]||(y=await W(`Store the Slack token now?`,!0)));let S=f?E(f):null;if(S&&(console.error(`\nInvalid gh account "${f}": ${S}`),process.exit(1)),g){let e=E(_);e&&(console.error(`\nInvalid Slack keychain service "${_}": ${e}`),process.exit(1))}let T={name:c,path:l(o),gh:f,git:p||m?{email:p,name:m}:void 0,servers:
|
|
89
|
+
GitHub account for this workspace`,[...Te().map(e=>({label:e,value:e})),{label:`(none)`,value:``}])||void 0);let p=i.email,m=i[`git-name`];a&&(p===void 0&&(p=await U(`Git email (${lt(Ee(`user.email`))})`)||void 0),m===void 0&&(m=await U(`Git name (${lt(Ee(`user.name`))})`)||void 0));let h;if(i.servers!==void 0){h=i.servers.split(`,`).map(e=>e.trim()).filter(Boolean);let e=new Set(A),t=h.filter(t=>!e.has(t));t.length&&console.error(z(`\nIgnoring unknown server(s): ${t.join(`, `)}`))}else h=a?await Re(`MCP servers (space toggles, enter confirms)`,ht):[`github`];let g=h.includes(`slack`)||!!i[`slack-keychain`]||!!i[`slack-package`]||!!i[`seed-slack`],_=i[`slack-keychain`]||at(c),v=!!i[`slack-message`],y=!!i[`seed-slack`],b=ct(i[`slack-package`]);b===null&&(console.error(`\nInvalid --slack-package "${i[`slack-package`]}": use slack-mcp-server or @nrjdalal/slack-mcp-server`),process.exit(1));let x=b;g&&a&&(console.log(`
|
|
90
|
+
Slack uses a user OAuth (xoxp) token.`),i[`slack-package`]||(x=await G(`Slack MCP server package`,Q,Math.max(0,Q.findIndex(e=>e.value===x)))),i[`slack-keychain`]||(_=await U(`Slack keychain service`,_)),i[`slack-message`]||(v=await W(`Allow Slack to post messages?`,!0)),i[`seed-slack`]||(y=await W(`Store the Slack token now?`,!0)));let S=f?E(f):null;if(S&&(console.error(`\nInvalid gh account "${f}": ${S}`),process.exit(1)),g){let e=E(_);e&&(console.error(`\nInvalid Slack keychain service "${_}": ${e}`),process.exit(1))}let T={name:c,path:l(o),gh:f,git:p||m?{email:p,name:m}:void 0,servers:st(h,g?{keychain:_,addMessageTool:v,package:x}:null)};ut(T),console.log(`\n✓ workspace "${c}" -> ${T.path}`),console.log(`✓ regenerated the hook, git includes, and ${T.path}/.mcp.json`),await dt(T,y),console.log(`\nLaunch \`claude\` from ${T.path} (or relaunch) to pick up the new identity.`),process.exit(0)},_t=`Regenerate the chpwd hook, git includes, and every .mcp.json
|
|
91
91
|
from your config. Idempotent: run it any time the config changes.
|
|
92
92
|
|
|
93
93
|
Usage:
|
|
94
94
|
$ ${$} apply
|
|
95
95
|
|
|
96
96
|
Options:
|
|
97
|
-
-h, --help Display help message`,
|
|
97
|
+
-h, --help Display help message`,vt=e=>{let{values:n}=t({allowPositionals:!0,options:{help:{type:`boolean`,short:`h`}},args:e});n.help&&(console.log(_t),process.exit(0)),C()||(console.error(`No config found. Run \`${$} init\` first.`),process.exit(1));let r=w(),i=Z(r);console.log(`\n✓ hook ${i.hook}`),i.gitconfig&&console.log(`✓ gitconfig ~/.gitconfig (includeIf block)`);for(let e of i.mcp)console.log(`✓ mcp ${e}`);console.log(`\nApplied ${r.workspaces.length} workspace(s).`),process.exit(0)},yt=e=>{let t=v(e);if(!t)return null;try{return JSON.parse(t)}catch{return null}},bt=e=>N(ve(yt(j(e))??{},e)),xt=t=>{let n=j(t);if(!e.existsSync(n))return null;try{return JSON.parse(e.readFileSync(n,`utf8`)),null}catch{return"invalid JSON; `apply` will not touch it until you fix it"}},St=e=>{let t=[],n=p();t.push({label:`hook`,path:n,current:v(n),next:Qe(e)}),t.push({label:`gitconfig`,path:h(),current:We(h(),J)??``,next:Ke(e)});for(let n of e.workspaces){if(!Y(n))continue;let e=X(n.name);t.push({label:`gitconfig:${n.name}`,path:e,current:v(e),next:qe(n)})}for(let n of e.workspaces){let e=j(n),r=xt(n);if(r){t.push({label:`mcp:${n.name}`,path:e,current:``,next:``,error:r});continue}t.push({label:`mcp:${n.name}`,path:e,current:v(e),next:bt(n)})}return t.filter(e=>e.error!=null||e.current!==e.next)},Ct=(e,t)=>{let n=e.length?e.split(`
|
|
98
98
|
`):[],r=t.length?t.split(`
|
|
99
99
|
`):[],i=n.length,a=r.length,o=Array.from({length:i+1},()=>Array.from({length:a+1},()=>0));for(let e=i-1;e>=0;e--)for(let t=a-1;t>=0;t--)o[e][t]=n[e]===r[t]?o[e+1][t+1]+1:Math.max(o[e+1][t],o[e][t+1]);let s=[],c=0,l=0;for(;c<i&&l<a;)n[c]===r[l]?(s.push(` ${n[c]}`),c++,l++):o[c+1][l]>=o[c][l+1]?(s.push(`- ${n[c]}`),c++):(s.push(`+ ${r[l]}`),l++);for(;c<i;)s.push(`- ${n[c++]}`);for(;l<a;)s.push(`+ ${r[l++]}`);return s.join(`
|
|
100
|
-
`)},
|
|
100
|
+
`)},wt=e=>{let t=[],n=e.workspaces.map(e=>{let n=yt(j(e))?.mcpServers;if(!n||typeof n!=`object`)return e;let r=e.servers,i=e.servers.slack;i&&!i.addMessageTool&&n[`slack-${e.name}`]?.env?.SLACK_MCP_ADD_MESSAGE_TOOL===`true`&&(r={...r,slack:{...i,addMessageTool:!0}},t.push(`${e.name}: slack.addMessageTool = true`));let a=r.slack;if(a){let i=fe(n[`slack-${e.name}`]?.args),o=a.package??x;if(i&&i!==o){let n={...a};i===x?delete n.package:n.package=i,r={...r,slack:n},t.push(`${e.name}: slack.package = ${i}`)}}for(let i of A){if(i===`github`||i===`slack`)continue;let a=n[`${i}-${e.name}`]?.url;if(typeof a!=`string`)continue;let o=e.servers[i];if(!o){r={...r,[i]:a===k[i]?!0:{url:a}},t.push(`${e.name}: ${i} = ${a===k[i]?`enabled`:a}`);continue}a!==((typeof o==`object`?o.url:void 0)??k[i])&&(r={...r,[i]:{url:a}},t.push(`${e.name}: ${i}.url = ${a}`))}return r===e.servers?e:{...e,servers:r}});return{cfg:{...e,workspaces:n},changes:t}},Tt=e=>{if(!process.stdout.isTTY)return e;let t=process.stdout.columns||80;return e.split(`
|
|
101
101
|
`).map(e=>{if(!e.startsWith(`- `)&&!e.startsWith(`+ `))return e;let n=` `.repeat(Math.max(0,t-e.length));return`\x1b[${e.startsWith(`- `)?`48;2;48;27;31;38;2;248;81;73`:`48;2;18;38;30;38;2;63;185;80`}m${e}${n}\x1b[0m`}).join(`
|
|
102
|
-
`)},
|
|
102
|
+
`)},Et=`Show what \`${$} apply\` would change: a diff of each managed
|
|
103
103
|
artifact (the zsh hook, git includes, and .mcp.json files) against what your
|
|
104
104
|
config would generate. Read-only.
|
|
105
105
|
|
|
106
106
|
With --adopt, pull settings that exist in your .mcp.json but not your config
|
|
107
|
-
(a Slack add-message tool, a custom server URL) back into the config, so the
|
|
107
|
+
(a Slack add-message tool or package, a custom server URL) back into the config, so the
|
|
108
108
|
next apply keeps them instead of dropping them.
|
|
109
109
|
|
|
110
110
|
Usage:
|
|
@@ -113,9 +113,9 @@ Usage:
|
|
|
113
113
|
Options:
|
|
114
114
|
--adopt Write config-expressible on-disk settings back into the config
|
|
115
115
|
--exit-code Exit 1 if anything is out of sync (for CI / pre-commit gates)
|
|
116
|
-
-h, --help Display help message`,
|
|
116
|
+
-h, --help Display help message`,Dt=e=>{let{values:n}=t({allowPositionals:!0,options:{help:{type:`boolean`,short:`h`},adopt:{type:`boolean`},"exit-code":{type:`boolean`}},args:e});n.help&&(console.log(Et),process.exit(0)),C()||(console.error(`No config found. Run \`${$} init\` first.`),process.exit(1));let r=w();if(n.adopt){let{cfg:e,changes:t}=wt(r);t.length||(console.log(`
|
|
117
117
|
Nothing to adopt: the config already covers your .mcp.json settings.`),process.exit(0)),D(e),T(e),console.log(`
|
|
118
|
-
Adopted into config:`);for(let e of t)console.log(` ${e}`);console.log(`\nRun ${R(`${$} apply`)} to regenerate from the updated config.`),process.exit(0)}let i=
|
|
118
|
+
Adopted into config:`);for(let e of t)console.log(` ${e}`);console.log(`\nRun ${R(`${$} apply`)} to regenerate from the updated config.`),process.exit(0)}let i=St(r);i.length||(console.log("\nIn sync. `apply` would change nothing."),process.exit(0));let a=n[`exit-code`]?1:0;for(let e of i)console.log(`\n${R(`${l(e.path)} (${e.label})`)}`),e.error?console.log(B(` ${e.error}`)):console.log(Tt(Ct(e.current,e.next)));let{changes:o}=wt(r);if(o.length){console.log("\nThese .mcp.json settings aren't in your config, so `apply` would drop them:");for(let e of o)console.log(` ${e}`);console.log(`\nRun ${R(`${$} diff --adopt`)} to keep them by writing them into the config.`)}process.exit(a)},Ot=de(`@nrjdalal/slack-mcp-server`),kt=e=>{let t=[],n=e?.mcpServers;if(!n||typeof n!=`object`)return t;for(let[e,r]of Object.entries(n)){let n=Array.isArray(r?.args)?r.args:[];if(!n.includes(Ot)){if(n.some(e=>typeof e==`string`&&e.endsWith(`@latest`)))t.push(e);else if(r?.command===`npx`){let r=n.find(e=>typeof e==`string`&&!e.startsWith(`-`));r&&!r.includes(`@`)&&t.push(e)}}}return t},At=(e,t=process.cwd())=>{let r=n.resolve(t),i,a=-1;for(let t of e.workspaces){let e=u(t.path);(r===e||r.startsWith(e+n.sep))&&e.length>a&&(i=t,a=e.length)}return i},jt=(e=P)=>{let t=e(`gh`,[`api`,`user`,`--jq`,`.login`]),n=e(`git`,[`config`,`user.email`]);return{pwd:process.cwd(),gh:t.status===0&&t.stdout.trim()?t.stdout.trim():`none`,gitEmail:n.status===0?n.stdout.trim():`none`,tokenSet:!!process.env.GITHUB_TOKEN}},Mt=(t,r=P)=>{let i=[];Se()||i.push({status:`warn`,label:`platform`,detail:`inscope's secret resolution targets macOS (gh keyring + Keychain)`});let a=process.env.SHELL??``;a&&!/(^|\/)zsh$/.test(a)&&i.push({status:`warn`,label:`shell`,detail:`login shell is ${n.basename(a)}; inscope targets zsh (the hook is written to ~/.zshrc)`});let o=p(),s=_(o);s===null?i.push({status:`fail`,label:`hook`,detail:`missing ${o}; run \`inscope init\``}):s===Qe(t)?i.push({status:`ok`,label:`hook`,detail:o}):i.push({status:`warn`,label:`hook`,detail:"out of date; run `inscope apply`"}),i.push(rt()?{status:`ok`,label:`zshrc`,detail:`sources the hook`}:{status:`warn`,label:`zshrc`,detail:"does not source the hook; run `inscope init`"}),t.workspaces.some(Y)&&i.push(We(h(),J)===null?{status:`fail`,label:`gitconfig`,detail:"missing includeIf block; run `inscope apply`"}:{status:`ok`,label:`gitconfig`,detail:`includeIf block present`});for(let n of t.workspaces){let t=`[${n.name}]`;if(n.gh&&i.push(Ce(n.gh,r)?{status:`ok`,label:`${t} gh`,detail:`token for ${n.gh}`}:{status:`fail`,label:`${t} gh`,detail:`no token for ${n.gh}; run \`gh auth login\``}),n.servers.slack){let e=n.servers.slack.keychain;i.push(De(e,r)?{status:`ok`,label:`${t} slack`,detail:e}:{status:`fail`,label:`${t} slack`,detail:`${e} not in keychain; run \`${ke(e)}\``})}if(Y(n)){let a=X(n.name);if(!e.existsSync(a))i.push({status:`fail`,label:`${t} git`,detail:`missing ${a}; run \`inscope apply\``});else if(n.git?.email){let e=Ae(a,r);i.push(e===n.git.email?{status:`ok`,label:`${t} git`,detail:n.git.email}:{status:`fail`,label:`${t} git`,detail:`email is ${e??`unset`}, expected ${n.git.email}`})}}let a=xt(n);if(a)i.push({status:`fail`,label:`${t} mcp`,detail:a});else{let e=_e(n);if(e===null)i.push({status:`warn`,label:`${t} mcp`,detail:"no .mcp.json; run `inscope apply`"});else{let r=pe(n.name).filter(t=>e.mcpServers?.[t]);i.push({status:`ok`,label:`${t} mcp`,detail:`${r.length} server(s)`}),_(j(n))!==bt(n)&&i.push({status:`warn`,label:`${t} mcp`,detail:"out of date; run `inscope diff`"});let a=kt(e);a.length&&i.push({status:`warn`,label:`${t} mcp`,detail:`unpinned: ${a.join(`, `)}`})}}}return i},Nt=`Verify the setup: gh tokens resolve, keychain entries exist,
|
|
119
119
|
git emails match per path, the hook is current, and no MCP server is unpinned.
|
|
120
120
|
Exits non-zero if any check fails.
|
|
121
121
|
|
|
@@ -123,8 +123,8 @@ Usage:
|
|
|
123
123
|
$ ${$} doctor
|
|
124
124
|
|
|
125
125
|
Options:
|
|
126
|
-
-h, --help Display help message`,
|
|
127
|
-
`);console.log(`\n${a}`);let o=
|
|
126
|
+
-h, --help Display help message`,Pt={ok:`✓`,warn:`!`,fail:`✗`},Ft={ok:Me,warn:z,fail:B},It=e=>{let{values:n}=t({allowPositionals:!0,options:{help:{type:`boolean`,short:`h`}},args:e});n.help&&(console.log(Nt),process.exit(0)),C()||(console.error(`No config found. Run \`${$} init\` first.`),process.exit(1));let r=w(),i=Mt(r),a=i.map(e=>`${Ft[e.status](Pt[e.status])} ${e.label}${e.detail?` ${e.detail}`:``}`).join(`
|
|
127
|
+
`);console.log(`\n${a}`);let o=At(r);if(o){let e=jt();console.log(`\nThis shell (${o.name}):`),console.log(` pwd ${e.pwd}`),console.log(` gh ${e.gh}`),console.log(` git ${e.gitEmail}`),console.log(` token ${e.tokenSet?`set`:`unset`}`)}let s=i.filter(e=>e.status===`fail`).length;s&&(console.log(`\n${B(`${s} check(s) failed.`)}`),process.exit(1)),console.log(`\n${Me(`All checks passed.`)}`),process.exit(0)},Lt=`Edit a configured workspace interactively, then re-apply.
|
|
128
128
|
Pick a workspace (or pass its path/label), step through the prompts pre-filled
|
|
129
129
|
with its current values, and inscope regenerates everything on save.
|
|
130
130
|
|
|
@@ -132,25 +132,25 @@ Usage:
|
|
|
132
132
|
$ ${$} edit [path|label]
|
|
133
133
|
|
|
134
134
|
Options:
|
|
135
|
-
-h, --help Display help message`,
|
|
136
|
-
Slack uses a user OAuth (xoxp) token.`),b=await G(`Slack MCP server package`,Q,Math.max(0,Q.findIndex(e=>e.value===b))),v=await U(`Slack keychain service`,v),y=await W(`Allow Slack to post messages?`,y),
|
|
135
|
+
-h, --help Display help message`,Rt=async e=>{let{positionals:n,values:r}=t({allowPositionals:!0,options:{help:{type:`boolean`,short:`h`}},args:e});r.help&&(console.log(Lt),process.exit(0)),C()||(console.error(`No config found. Run \`${$} init\` first.`),process.exit(1));let i=w();i.workspaces.length||(console.error(`No workspaces yet. Add one with \`${$} add <path>\`.`),process.exit(1));let a=n[0],o=await(async()=>{if(a){let e=O(i,a);return e||(console.error(`No workspace matching "${a}".`),process.exit(1)),e}if(i.workspaces.length===1)return i.workspaces[0];if(I())return G(`Edit which workspace?`,i.workspaces.map(e=>({label:`${e.name} (${e.path})`,value:e})));console.error(`Specify a workspace, e.g. \`${$} edit <label>\`.`),process.exit(1)})();console.log(`\nEditing "${o.name}" (${o.path})\n`);let s=[...Te().map(e=>({label:e,value:e})),{label:`(none)`,value:``}],c=await G(`GitHub account`,s,Math.max(0,s.findIndex(e=>e.value===(o.gh??``))))||void 0,l=o.git?.email,u=await U(l?`Git email (enter keeps ${l}, "-" to inherit global)`:`Git email (enter to inherit global)`,l??``),d=u===`-`?void 0:u||void 0,f=o.git?.name,p=await U(f?`Git name (enter keeps ${f}, "-" to inherit global)`:`Git name (enter to inherit global)`,f??``),m=p===`-`?void 0:p||void 0,h=ot(o.servers),g=await Re(`MCP servers (space toggles, enter confirms)`,it.map(e=>({label:e,value:e,checked:h.includes(e)}))),_=g.includes(`slack`),v=o.servers.slack?o.servers.slack.keychain:at(o.name),y=o.servers.slack?!!o.servers.slack.addMessageTool:!1,b=o.servers.slack?o.servers.slack.package??x:x,S=!1;if(_&&(console.log(`
|
|
136
|
+
Slack uses a user OAuth (xoxp) token.`),b=await G(`Slack MCP server package`,Q,Math.max(0,Q.findIndex(e=>e.value===b))),v=await U(`Slack keychain service`,v),y=await W(`Allow Slack to post messages?`,y),De(v)||(S=await W(`Store the Slack token now?`,!0))),_){let e=E(v);e&&(console.error(`\nInvalid Slack keychain service "${v}": ${e}`),process.exit(1))}let T={name:o.name,path:o.path,gh:c,git:d||m?{email:d,name:m}:void 0,servers:st(g,_?{keychain:v,addMessageTool:y,package:b}:null)};ut(T),console.log(`\n✓ updated "${T.name}" -> ${T.path}`),await dt(T,S),console.log(`\nRelaunch \`claude\` from ${T.path} to pick up the changes.`),process.exit(0)},zt=`Set up inscope: create the config, generate the chpwd hook, and
|
|
137
137
|
source it from ~/.zshrc. Safe to run again; it never overwrites your config.
|
|
138
138
|
|
|
139
139
|
Usage:
|
|
140
140
|
$ ${$} init
|
|
141
141
|
|
|
142
142
|
Options:
|
|
143
|
-
-h, --help Display help message`,
|
|
143
|
+
-h, --help Display help message`,Bt=e=>{let{values:n}=t({allowPositionals:!0,options:{help:{type:`boolean`,short:`h`}},args:e});n.help&&(console.log(zt),process.exit(0));let r;C()?(r=w(),console.log(`\nUsing existing config at ${f()}`)):(r=S(),T(r),console.log(`\nCreated ${f()}`)),Z(r),console.log(`Generated the chpwd hook and added a source line to ~/.zshrc.`),console.log(`
|
|
144
144
|
Next steps:
|
|
145
145
|
1. Reload your shell: source ~/.zshrc (or open a new terminal)
|
|
146
|
-
2. Map a workspace: ${$} add ~/acme`),process.exit(0)},
|
|
146
|
+
2. Map a workspace: ${$} add ~/acme`),process.exit(0)},Vt=`List the configured workspaces. Run \`${$} doctor\` to verify
|
|
147
147
|
that their tokens and identities actually resolve.
|
|
148
148
|
|
|
149
149
|
Usage:
|
|
150
150
|
$ ${$} list
|
|
151
151
|
|
|
152
152
|
Options:
|
|
153
|
-
-h, --help Display help message`,
|
|
153
|
+
-h, --help Display help message`,Ht=e=>{let{values:n}=t({allowPositionals:!0,options:{help:{type:`boolean`,short:`h`}},args:e});n.help&&(console.log(Vt),process.exit(0)),C()||(console.error(`No config found. Run \`${$} init\` first.`),process.exit(1));let r=w();r.workspaces.length||(console.log(`No workspaces yet. Add one with \`${$} add <path> --gh <account>\`.`),process.exit(0));for(let e of r.workspaces)console.log(`\n${e.name}`),console.log(` path ${e.path}`),console.log(` gh ${e.gh??`(none)`}`),console.log(` git ${e.git?.email??`(default)`}`),console.log(` servers ${ot(e.servers).join(`, `)||`none`}`),e.servers.slack&&console.log(` slack keychain: ${e.servers.slack.keychain}`);process.exit(0)},Ut=`Remove a workspace mapping. Drops its git include and the MCP
|
|
154
154
|
servers inscope manages; leaves your keychain and gh accounts untouched. Pick a
|
|
155
155
|
workspace, or pass its path/label.
|
|
156
156
|
|
|
@@ -159,8 +159,8 @@ Usage:
|
|
|
159
159
|
|
|
160
160
|
Options:
|
|
161
161
|
-y, --yes Skip the type-the-label confirmation
|
|
162
|
-
-h, --help Display help message`,
|
|
163
|
-
${$}@${
|
|
162
|
+
-h, --help Display help message`,Wt=async e=>{let{positionals:n,values:r}=t({allowPositionals:!0,options:{help:{type:`boolean`,short:`h`},yes:{type:`boolean`,short:`y`}},args:e});r.help&&(console.log(Ut),process.exit(0)),C()||(console.error(`No config found. Run \`${$} init\` first.`),process.exit(1));let i=w();i.workspaces.length||(console.error(`No workspaces to remove.`),process.exit(1));let a=n[0],o;if(a){let e=O(i,a);e||(console.error(`No workspace matching "${a}".`),process.exit(1)),o=e}else I()?o=await G(`Remove which workspace?`,i.workspaces.map(e=>({label:`${e.name} (${e.path})`,value:e}))):(console.error(`Specify a workspace, e.g. \`${$} rm <label>\`.`),process.exit(1));if(!r.yes){console.log(`\n⚠ Removing "${o.name}" (${o.path}) unmaps it from inscope.`);let e=await U(`Type "${o.name}" to confirm`);e!==o.name&&(console.error(`Aborted: "${e}" does not match "${o.name}".`),process.exit(1))}let{cfg:s}=ue(i,o.name);xe(o),Ye(o.name),T(s),Z(s),console.log(`\n✓ removed workspace "${o.name}"`),o.servers.slack&&console.log(`\nNote: the keychain entry ${o.servers.slack.keychain} was left in place.\nDelete it with: ${R(`security delete-generic-password -s ${o.servers.slack.keychain}`)}`),process.exit(0)},Gt=`Version:
|
|
163
|
+
${$}@${ft}
|
|
164
164
|
|
|
165
165
|
Per-workspace identity for Claude Code: scope MCP servers, GitHub auth, and git
|
|
166
166
|
commit identity to the directory you are in, so concurrent sessions never clash.
|
|
@@ -183,4 +183,4 @@ Options:
|
|
|
183
183
|
-h, --help Display help
|
|
184
184
|
|
|
185
185
|
Author:
|
|
186
|
-
${
|
|
186
|
+
${pt.name} <${pt.email}> (${pt.url})`;(async()=>{try{let e=process.argv.slice(2),t=e[0],n=e.slice(1);switch(t){case`init`:return Bt(n);case`add`:return await gt(n);case`edit`:return Rt(n);case`rm`:case`remove`:return await Wt(n);case`ls`:case`list`:return Ht(n);case`diff`:return Dt(n);case`apply`:case`sync`:return vt(n);case`doctor`:return It(n)}(t===`-v`||t===`--version`)&&(console.log(`${$}@${ft}`),process.exit(0)),(!t||t===`-h`||t===`--help`)&&(console.log(Gt),process.exit(0)),console.error(`unknown command: ${e.join(` `)}\n`),console.error(Gt),process.exit(1)}catch(e){console.error(e.message),process.exit(1)}})();export{};
|
package/dist/index.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import e from"node:fs";import t from"node:path";import n from"node:os";import{spawnSync as r}from"node:child_process";const i=()=>process.env.HOME?.trim()||n.homedir(),a=()=>process.env.XDG_CONFIG_HOME?.trim()||t.join(i(),`.config`),o=e=>e===`~`?i():e.startsWith(`~/`)?t.join(i(),e.slice(2)):e,s=e=>{let n=o(e),r=i();return n===r?`~`:n.startsWith(r+t.sep)?`~/`+n.slice(r.length+1):n},c=e=>t.resolve(o(e)),l=()=>t.join(a(),`inscope`),u=()=>t.join(l(),`inscope.json`),d=()=>t.join(l(),`inscope.zsh`),f=()=>t.join(l(),`git`),p=()=>t.join(i(),`.gitconfig`),
|
|
2
|
-
`)},
|
|
1
|
+
import e from"node:fs";import t from"node:path";import n from"node:os";import{spawnSync as r}from"node:child_process";const i=()=>process.env.HOME?.trim()||n.homedir(),a=()=>process.env.XDG_CONFIG_HOME?.trim()||t.join(i(),`.config`),o=e=>e===`~`?i():e.startsWith(`~/`)?t.join(i(),e.slice(2)):e,s=e=>{let n=o(e),r=i();return n===r?`~`:n.startsWith(r+t.sep)?`~/`+n.slice(r.length+1):n},c=e=>t.resolve(o(e)),l=()=>t.join(a(),`inscope`),u=()=>t.join(l(),`inscope.json`),d=()=>t.join(l(),`inscope.zsh`),f=()=>t.join(l(),`git`),p=()=>t.join(i(),`.gitconfig`),m=()=>t.join(i(),`.zshrc`),h=t=>{try{return e.readFileSync(t,`utf8`)}catch{return null}},g=e=>h(e)??``,_=(n,r)=>{let i=n;try{i=e.realpathSync(n)}catch{}let a=t.dirname(i);e.mkdirSync(a,{recursive:!0});let o;try{o=e.statSync(i).mode}catch{}let s=t.join(a,`.${t.basename(i)}.inscope-${process.pid}.tmp`);e.writeFileSync(s,r),o!==void 0&&e.chmodSync(s,o&4095);try{e.renameSync(s,i)}catch(t){try{e.rmSync(s,{force:!0})}catch{}throw t}},v=[`slack-mcp-server`,`@nrjdalal/slack-mcp-server`],y=`slack-mcp-server`,ee=1,te=()=>({version:1,workspaces:[]}),ne=()=>e.existsSync(u()),re=()=>{let t=u(),n=e.readFileSync(t,`utf8`),r;try{r=JSON.parse(n)}catch{throw Error(`${s(t)} is not valid JSON; fix it, then re-run.`)}let i=T(r);if(i)throw Error(i);try{D(r)}catch(e){let n=e instanceof Error?e.message:String(e);throw Error(`${n}\nFix it in ${s(t)}, then re-run.`)}return r},ie=e=>{D(e),_(u(),JSON.stringify(e,null,2)+`
|
|
2
|
+
`)},b=/^[A-Za-z0-9._-]+$/,x=e=>e?b.test(e)?null:`use only letters, digits, dot (.), dash (-), or underscore (_)`:`must not be empty`,ae=/[\\"`$\n]/,S=e=>ae.test(e)?'must not contain a backslash (\\), quote ("), backtick (`), $, or newline':null,C=e=>e?S(e):`must not be empty`,w=e=>/[\n\r]/.test(e)?`must not contain a newline`:null,T=e=>typeof e.version==`number`&&e.version>1?`config version ${e.version} is newer than this inscope supports (max 1); upgrade inscope`:null,E=e=>e.toLowerCase().replace(/[^a-z0-9._-]+/g,`-`).replace(/^[-.]+|[-.]+$/g,``),D=e=>{if(!e||typeof e!=`object`)throw Error(`config is not an object`);let t=T(e);if(t)throw Error(t);if(!Array.isArray(e.workspaces))throw Error(`config.workspaces must be an array`);let n=new Set;for(let t of e.workspaces){if(!t.name)throw Error(`a workspace is missing a name`);let e=x(t.name);if(e)throw Error(`workspace name "${t.name}" is invalid: ${e}`);if(!t.path)throw Error(`workspace "${t.name}" is missing a path`);let r=C(t.path);if(r)throw Error(`workspace "${t.name}" path "${t.path}" is invalid: ${r}`);if(t.gh){let e=S(t.gh);if(e)throw Error(`workspace "${t.name}" gh account "${t.gh}" is invalid: ${e}`)}if(t.git?.email){let e=w(t.git.email);if(e)throw Error(`workspace "${t.name}" git email "${t.git.email}" is invalid: ${e}`)}if(t.git?.name){let e=w(t.git.name);if(e)throw Error(`workspace "${t.name}" git name "${t.git.name}" is invalid: ${e}`)}let i=t.servers?.slack;if(i&&i.keychain){let e=S(i.keychain);if(e)throw Error(`workspace "${t.name}" Slack keychain "${i.keychain}" is invalid: ${e}`)}let a=i&&i.package;if(a&&!v.includes(a))throw Error(`workspace "${t.name}" Slack package "${a}" is invalid: use one of ${v.join(`, `)}`);if(n.has(t.name))throw Error(`duplicate workspace name "${t.name}"`);n.add(t.name)}},oe=e=>E(t.basename(c(e)))||`workspace`,se=(e,t)=>{let n=e.workspaces.find(e=>e.name===t);if(n)return n;let r=c(t);return e.workspaces.find(e=>c(e.path)===r)},ce=(e,t,n)=>{let r=c(t);return e.workspaces.find(e=>e.name!==n&&c(e.path)===r)},le=(e,t)=>{let n=e.workspaces.filter(e=>e.name!==t.name);return n.push({...t,path:s(t.path)}),n.sort((e,t)=>e.name.localeCompare(t.name)),{...e,workspaces:n}},ue=(e,t)=>{let n=se(e,t);return n?{cfg:{...e,workspaces:e.workspaces.filter(e=>e.name!==n.name)},removed:n}:{cfg:e}},O=e=>`# >>> inscope:${e} >>>`,k=e=>`# <<< inscope:${e} <<<`,A=e=>e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),de=e=>RegExp(`${A(O(e))}\\n[\\s\\S]*?\\n${A(k(e))}\\n?`),fe=(e,t)=>{let n=t.replace(/\n+$/,``);return`${O(e)}\n${n}\n${k(e)}\n`},pe=(e,t,n)=>{let r=g(e),i=fe(t,n),a=de(t),o;if(a.test(r))o=r.replace(a,i);else{let e=r.replace(/\n*$/,``);o=e.length?`${e}\n\n${i}`:i}_(e,o)},me=(e,t)=>{let n=g(e);n&&_(e,n.replace(de(t),``).replace(/\n{3,}/g,`
|
|
3
3
|
|
|
4
|
-
`).replace(/^\n+/,``))},
|
|
5
|
-
`),
|
|
4
|
+
`).replace(/^\n+/,``))},j=(e,t)=>{let n=g(e).match(RegExp(`${A(O(t))}\\n([\\s\\S]*?)\\n${A(k(t))}`));return n?n[1]:null},M=`gitconfig`,N=e=>!!(e.git&&(e.git.email||e.git.name)),P=e=>t.join(f(),`${e}.gitconfig`),he=e=>s(e).replace(/\/+$/,``)+`/`,F=e=>e.workspaces.filter(N).map(e=>`[includeIf "gitdir:${he(e.path)}"]\n\tpath = ${s(P(e.name))}`).join(`
|
|
5
|
+
`),I=e=>{let t=[`# Managed by inscope. Do not edit by hand.`,`[user]`];return e.git?.email&&t.push(`\temail = ${e.git.email}`),e.git?.name&&t.push(`\tname = ${e.git.name}`),t.join(`
|
|
6
6
|
`)+`
|
|
7
|
-
`},
|
|
7
|
+
`},L=t=>{e.mkdirSync(f(),{recursive:!0});for(let e of t.workspaces)N(e)?_(P(e.name),I(e)):ge(e.name);let n=F(t);n?pe(p(),M,n):me(p(),M)},ge=t=>{let n=P(t);e.existsSync(n)&&e.rmSync(n)},_e=e=>{let t=s(e);return t===`~`?`"$HOME/"*`:t.startsWith(`~/`)?`"$HOME/${t.slice(2)}/"*`:`"${t}/"*`},ve=e=>e.servers.slack?e.servers.slack.keychain:``,R=e=>{let t=[...e.workspaces].sort((e,t)=>e.name.localeCompare(t.name));return`# Managed by inscope. Do not edit by hand.
|
|
8
8
|
# Source of truth: ~/.config/inscope/inscope.json
|
|
9
9
|
# Edit there, then run \`inscope apply\` to regenerate this file.
|
|
10
10
|
#
|
|
@@ -15,7 +15,7 @@ import e from"node:fs";import t from"node:path";import n from"node:os";import{sp
|
|
|
15
15
|
__inscope_resolve_identity() {
|
|
16
16
|
local ws
|
|
17
17
|
case "\${PWD}/" in
|
|
18
|
-
${[...t].sort((e,t)=>s(t.path).length-s(e.path).length).map(e=>` ${
|
|
18
|
+
${[...t].sort((e,t)=>s(t.path).length-s(e.path).length).map(e=>` ${_e(e.path)}) ws="${e.name}" ;;`).join(`
|
|
19
19
|
`)||` # no workspaces configured`}
|
|
20
20
|
*) ws="" ;;
|
|
21
21
|
esac
|
|
@@ -25,7 +25,7 @@ ${[...t].sort((e,t)=>s(t.path).length-s(e.path).length).map(e=>` ${ve(e.path)
|
|
|
25
25
|
|
|
26
26
|
local gh_user="" slack_svc=""
|
|
27
27
|
case "$ws" in
|
|
28
|
-
${t.map(e=>{let t=[];e.gh&&t.push(`gh_user="${e.gh}"`);let n=
|
|
28
|
+
${t.map(e=>{let t=[];e.gh&&t.push(`gh_user="${e.gh}"`);let n=ve(e);return n&&t.push(`slack_svc="${n}"`),` ${e.name}) ${t.length?t.join(`; `):`:`} ;;`}).join(`
|
|
29
29
|
`)||` # no workspaces configured`}
|
|
30
30
|
*) return ;; # outside a mapped workspace: nothing set
|
|
31
31
|
esac
|
|
@@ -51,8 +51,8 @@ autoload -Uz add-zsh-hook
|
|
|
51
51
|
add-zsh-hook chpwd __inscope_resolve_identity
|
|
52
52
|
__inscope_ws="__init__" # force the first resolve, clearing any inherited token
|
|
53
53
|
__inscope_resolve_identity
|
|
54
|
-
`},
|
|
55
|
-
`,
|
|
54
|
+
`},z=`1.3.0`,B=(e=y)=>e===`@nrjdalal/slack-mcp-server`?`@nrjdalal/slack-mcp-server@latest`:`slack-mcp-server@${z}`,ye=e=>{if(!Array.isArray(e))return null;let t=e.find(e=>typeof e==`string`&&e.includes(`slack-mcp-server`));return t?t.startsWith(`@nrjdalal/slack-mcp-server`)?`@nrjdalal/slack-mcp-server`:t.startsWith(`slack-mcp-server`)?`slack-mcp-server`:null:null},V={atlassian:`https://mcp.atlassian.com/v1/mcp`,canva:`https://mcp.canva.com/mcp`,clickup:`https://mcp.clickup.com/mcp`,hubspot:`https://mcp.hubspot.com`,intercom:`https://mcp.intercom.com/mcp`,linear:`https://mcp.linear.app/mcp`,monday:`https://mcp.monday.com/mcp`,notion:`https://mcp.notion.com/mcp`,plane:`https://mcp.plane.so/http/mcp`,sentry:`https://mcp.sentry.dev/mcp`,stripe:`https://mcp.stripe.com`,vercel:`https://mcp.vercel.com`,webflow:`https://mcp.webflow.com/`},H=[`github`,`atlassian`,`canva`,`clickup`,`hubspot`,`intercom`,`linear`,`monday`,`notion`,`plane`,`sentry`,`slack`,`stripe`,`vercel`,`webflow`],U=e=>H.map(t=>`${t}-${e}`),W=e=>t.join(c(e.path),`.mcp.json`),be=(e,t)=>e&&typeof e==`object`&&e.url?e.url:t,G=e=>{let t=e.servers,n={};for(let r of H){let i=t[r];if(!i)continue;let a=`${r}-${e.name}`;if(r===`github`)n[a]={type:`http`,url:`https://api.githubcopilot.com/mcp/`,headers:{Authorization:"Bearer ${GITHUB_TOKEN}"}};else if(r===`slack`){let e=i,t=e.package??y,r={SLACK_MCP_XOXP_TOKEN:"${SLACK_MCP_XOXP_TOKEN}"},o=[`-y`,B(t)];t===`@nrjdalal/slack-mcp-server`?e.addMessageTool||(r.SLACK_MCP_ALLOW_WRITE=`false`):(o.push(`--transport`,`stdio`),e.addMessageTool&&(r.SLACK_MCP_ADD_MESSAGE_TOOL=`true`)),n[a]={type:`stdio`,command:`npx`,args:o,env:r}}else n[a]={type:`http`,url:be(i,V[r])}}return n},xe=e=>({mcpServers:G(e)}),Se=t=>{if(!e.existsSync(t))return{};try{return JSON.parse(e.readFileSync(t,`utf8`))}catch{return{}}},K=t=>{if(!e.existsSync(t))return{};try{return JSON.parse(e.readFileSync(t,`utf8`))}catch{throw Error(`${t} is not valid JSON; fix or remove it, then re-run inscope (left it untouched)`)}},Ce=t=>{let n=W(t);return e.existsSync(n)?Se(n):null},we=(e,t)=>{let n=e.mcpServers&&typeof e.mcpServers==`object`?{...e.mcpServers}:{};for(let e of U(t.name))delete n[e];return Object.assign(n,G(t)),{...e,mcpServers:n}},q=e=>JSON.stringify(e,null,2)+`
|
|
55
|
+
`,Te=e=>{for(let t of e)K(W(t))},Ee=e=>{let t=W(e);_(t,q(we(K(t),e)))},De=t=>{let n=W(t);if(!e.existsSync(n))return;let r=K(n);if(r.mcpServers&&typeof r.mcpServers==`object`)for(let e of U(t.name))delete r.mcpServers[e];_(n,q(r))},Oe=e=>{let n=i();return e===n?`$HOME`:e.startsWith(n+t.sep)?`$HOME/${e.slice(n.length+1)}`:e},ke=()=>{let e=Oe(d());return`[ -r "${e}" ] && source "${e}"`},Ae=e=>{let t=ke();if(e.includes(t))return e;let n=e.replace(/\n*$/,``),r=`# inscope: load each workspace's tokens (GitHub, Slack) from \$PWD on every cd\n${t}`;return n.length?`${n}\n\n${r}\n`:`${r}\n`},je=()=>{let e=m(),t=g(e),n=Ae(t);n!==t&&_(e,n)},Me=()=>g(m()).includes(ke()),Ne=e=>{Te(e.workspaces);let t=d();_(t,R(e)),L(e),je();let n=[];for(let t of e.workspaces)Ee(t),n.push(W(t));return{hook:t,gitconfig:e.workspaces.some(e=>e.git?.email||e.git?.name),mcp:n}},Pe=e=>{let t=g(e);if(!t)return null;try{return JSON.parse(t)}catch{return null}},J=e=>q(we(Pe(W(e))??{},e)),Y=t=>{let n=W(t);if(!e.existsSync(n))return null;try{return JSON.parse(e.readFileSync(n,`utf8`)),null}catch{return"invalid JSON; `apply` will not touch it until you fix it"}},Fe=e=>{let t=[],n=d();t.push({label:`hook`,path:n,current:g(n),next:R(e)}),t.push({label:`gitconfig`,path:p(),current:j(p(),M)??``,next:F(e)});for(let n of e.workspaces){if(!N(n))continue;let e=P(n.name);t.push({label:`gitconfig:${n.name}`,path:e,current:g(e),next:I(n)})}for(let n of e.workspaces){let e=W(n),r=Y(n);if(r){t.push({label:`mcp:${n.name}`,path:e,current:``,next:``,error:r});continue}t.push({label:`mcp:${n.name}`,path:e,current:g(e),next:J(n)})}return t.filter(e=>e.error!=null||e.current!==e.next)},Ie=(e,t)=>{let n=e.length?e.split(`
|
|
56
56
|
`):[],r=t.length?t.split(`
|
|
57
57
|
`):[],i=n.length,a=r.length,o=Array.from({length:i+1},()=>Array.from({length:a+1},()=>0));for(let e=i-1;e>=0;e--)for(let t=a-1;t>=0;t--)o[e][t]=n[e]===r[t]?o[e+1][t+1]+1:Math.max(o[e+1][t],o[e][t+1]);let s=[],c=0,l=0;for(;c<i&&l<a;)n[c]===r[l]?(s.push(` ${n[c]}`),c++,l++):o[c+1][l]>=o[c][l+1]?(s.push(`- ${n[c]}`),c++):(s.push(`+ ${r[l]}`),l++);for(;c<i;)s.push(`- ${n[c++]}`);for(;l<a;)s.push(`+ ${r[l++]}`);return s.join(`
|
|
58
|
-
`)},
|
|
58
|
+
`)},Le=e=>{let t=[],n=e.workspaces.map(e=>{let n=Pe(W(e))?.mcpServers;if(!n||typeof n!=`object`)return e;let r=e.servers,i=e.servers.slack;i&&!i.addMessageTool&&n[`slack-${e.name}`]?.env?.SLACK_MCP_ADD_MESSAGE_TOOL===`true`&&(r={...r,slack:{...i,addMessageTool:!0}},t.push(`${e.name}: slack.addMessageTool = true`));let a=r.slack;if(a){let i=ye(n[`slack-${e.name}`]?.args),o=a.package??y;if(i&&i!==o){let n={...a};i===y?delete n.package:n.package=i,r={...r,slack:n},t.push(`${e.name}: slack.package = ${i}`)}}for(let i of H){if(i===`github`||i===`slack`)continue;let a=n[`${i}-${e.name}`]?.url;if(typeof a!=`string`)continue;let o=e.servers[i];if(!o){r={...r,[i]:a===V[i]?!0:{url:a}},t.push(`${e.name}: ${i} = ${a===V[i]?`enabled`:a}`);continue}a!==((typeof o==`object`?o.url:void 0)??V[i])&&(r={...r,[i]:{url:a}},t.push(`${e.name}: ${i}.url = ${a}`))}return r===e.servers?e:{...e,servers:r}});return{cfg:{...e,workspaces:n},changes:t}},X=(e,t,n)=>{let i=r(e,t,{encoding:`utf8`,input:n?.input});return{status:i.status??(i.error?127:1),stdout:i.stdout??``,stderr:i.stderr??``}},Re=()=>process.platform===`darwin`,Z=()=>process.env.USER||``,ze=(e,t=X)=>{let n=t(`gh`,[`auth`,`token`,`-u`,e]),r=n.stdout.trim();return n.status===0&&r?r:null},Be=(e=X)=>{let t=e(`gh`,[`auth`,`status`]);return(t.stdout+t.stderr).trim()},Ve=(e=X)=>{let t=[];for(let n of Be(e).matchAll(/account (\S+) \(/g))t.includes(n[1])||t.push(n[1]);return t},He=(e,t=X)=>{let n=t(`git`,[`config`,`--global`,e]),r=n.stdout.trim();return n.status===0&&r?r:null},Q=(e,t=X)=>{let n=t(`security`,[`find-generic-password`,`-a`,Z(),`-s`,e,`-w`]);return n.status===0&&n.stdout.trim().length>0},Ue=(e,t,n=X)=>{let r=n(`security`,[`add-generic-password`,`-U`,`-a`,Z(),`-s`,e,`-w`,t]);if(r.status!==0)throw Error(`security add-generic-password failed: ${r.stderr.trim()||`unknown error`}`)},We=e=>`security add-generic-password -U -a "${Z()||`$USER`}" -s ${e} -w 'xoxp-...'`,$=(e,t=X)=>{let n=t(`git`,[`config`,`--file`,e,`user.email`]);return n.status===0?n.stdout.trim():null},Ge=B(`@nrjdalal/slack-mcp-server`),Ke=e=>{let t=[],n=e?.mcpServers;if(!n||typeof n!=`object`)return t;for(let[e,r]of Object.entries(n)){let n=Array.isArray(r?.args)?r.args:[];if(!n.includes(Ge)){if(n.some(e=>typeof e==`string`&&e.endsWith(`@latest`)))t.push(e);else if(r?.command===`npx`){let r=n.find(e=>typeof e==`string`&&!e.startsWith(`-`));r&&!r.includes(`@`)&&t.push(e)}}}return t},qe=(e,n=process.cwd())=>{let r=t.resolve(n),i,a=-1;for(let n of e.workspaces){let e=c(n.path);(r===e||r.startsWith(e+t.sep))&&e.length>a&&(i=n,a=e.length)}return i},Je=(e=X)=>{let t=e(`gh`,[`api`,`user`,`--jq`,`.login`]),n=e(`git`,[`config`,`user.email`]);return{pwd:process.cwd(),gh:t.status===0&&t.stdout.trim()?t.stdout.trim():`none`,gitEmail:n.status===0?n.stdout.trim():`none`,tokenSet:!!process.env.GITHUB_TOKEN}},Ye=(n,r=X)=>{let i=[];Re()||i.push({status:`warn`,label:`platform`,detail:`inscope's secret resolution targets macOS (gh keyring + Keychain)`});let a=process.env.SHELL??``;a&&!/(^|\/)zsh$/.test(a)&&i.push({status:`warn`,label:`shell`,detail:`login shell is ${t.basename(a)}; inscope targets zsh (the hook is written to ~/.zshrc)`});let o=d(),s=h(o);s===null?i.push({status:`fail`,label:`hook`,detail:`missing ${o}; run \`inscope init\``}):s===R(n)?i.push({status:`ok`,label:`hook`,detail:o}):i.push({status:`warn`,label:`hook`,detail:"out of date; run `inscope apply`"}),i.push(Me()?{status:`ok`,label:`zshrc`,detail:`sources the hook`}:{status:`warn`,label:`zshrc`,detail:"does not source the hook; run `inscope init`"}),n.workspaces.some(N)&&i.push(j(p(),M)===null?{status:`fail`,label:`gitconfig`,detail:"missing includeIf block; run `inscope apply`"}:{status:`ok`,label:`gitconfig`,detail:`includeIf block present`});for(let t of n.workspaces){let n=`[${t.name}]`;if(t.gh&&i.push(ze(t.gh,r)?{status:`ok`,label:`${n} gh`,detail:`token for ${t.gh}`}:{status:`fail`,label:`${n} gh`,detail:`no token for ${t.gh}; run \`gh auth login\``}),t.servers.slack){let e=t.servers.slack.keychain;i.push(Q(e,r)?{status:`ok`,label:`${n} slack`,detail:e}:{status:`fail`,label:`${n} slack`,detail:`${e} not in keychain; run \`${We(e)}\``})}if(N(t)){let a=P(t.name);if(!e.existsSync(a))i.push({status:`fail`,label:`${n} git`,detail:`missing ${a}; run \`inscope apply\``});else if(t.git?.email){let e=$(a,r);i.push(e===t.git.email?{status:`ok`,label:`${n} git`,detail:t.git.email}:{status:`fail`,label:`${n} git`,detail:`email is ${e??`unset`}, expected ${t.git.email}`})}}let a=Y(t);if(a)i.push({status:`fail`,label:`${n} mcp`,detail:a});else{let e=Ce(t);if(e===null)i.push({status:`warn`,label:`${n} mcp`,detail:"no .mcp.json; run `inscope apply`"});else{let r=U(t.name).filter(t=>e.mcpServers?.[t]);i.push({status:`ok`,label:`${n} mcp`,detail:`${r.length} server(s)`}),h(W(t))!==J(t)&&i.push({status:`warn`,label:`${n} mcp`,detail:"out of date; run `inscope diff`"});let a=Ke(e);a.length&&i.push({status:`warn`,label:`${n} mcp`,detail:`unpinned: ${a.join(`, `)}`})}}}return i};export{ee as CONFIG_VERSION,y as DEFAULT_SLACK_PACKAGE,z as SLACK_MCP_VERSION,v as SLACK_PACKAGES,b as WORKSPACE_NAME_RE,Le as adoptable,Ne as applyAll,L as applyGitconfig,Ee as applyMcp,Fe as computeDrift,ne as configExists,T as configVersionError,qe as currentWorkspace,te as defaultConfig,X as defaultRunner,Ie as diffLines,je as ensureZshrcSource,se as findWorkspace,Ve as ghAccounts,Be as ghStatus,ze as ghToken,$ as gitEmailForFile,He as gitGlobal,w as gitValueError,S as hookValueError,Re as isMacOS,Q as keychainHas,Ue as keychainSet,We as keychainSetCommand,oe as labelFromPath,Je as liveSnapshot,re as loadConfig,U as managedKeys,Y as mcpError,W as mcpFilePath,J as mcpTarget,ce as pathConflict,Ce as readMcp,De as removeMcp,ue as removeWorkspace,F as renderGitInclude,R as renderHook,xe as renderMcp,I as renderPerWorkspaceGitconfig,G as renderServers,Ae as renderZshrcSource,Ye as runDoctor,ie as saveConfig,E as slugify,le as upsertWorkspace,D as validateConfig,x as workspaceNameError,C as workspacePathError,Me as zshrcSourcesHook};
|