tweakcc 3.4.0 → 4.0.1
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 +1053 -69
- package/dist/config-WXSHpuVT.mjs +669 -0
- package/dist/content-BPPXiS27.mjs +29 -0
- package/dist/index.mjs +24 -666
- package/dist/lib/index.mjs +1 -0
- package/dist/nativeInstallation-CBnbx1lo.mjs +4 -0
- package/package.json +16 -11
- package/dist/nativeInstallation-DBmBL-fs.mjs +0 -4
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import{E as e,Q as t,Z as n,b as r,c as i,d as a,f as o,l as s,n as c,p as l,r as u,x as d}from"./config-WXSHpuVT.mjs";import{Box as f,Text as p,render as m,useInput as h}from"ink";import g,{useState as ee}from"react";import*as te from"node:os";import _ from"node:os";import*as ne from"node:fs/promises";import v from"node:fs/promises";import y from"path";import{jsx as b,jsxs as x}from"react/jsx-runtime";import S from"which";import{WASMagic as C}from"wasmagic";import{globbySync as w}from"globby";const T=(()=>{let e=[],t=process.platform==`win32`?_.homedir().replace(/\\/g,`/`):_.homedir(),n=`node_modules/@anthropic-ai/claude-code`,r=(t,n=!1)=>{if(n)try{let n=w(t,{onlyFiles:!1});e.push({pattern:t,isGlob:!0,expandedPaths:n})}catch(n){n instanceof Error&&`code`in n&&(n.code===`EACCES`||n.code===`EPERM`)?o(`Permission denied accessing: ${t} (${n.code})`):o(`Error expanding glob pattern "${t}": ${n instanceof Error?n.message:String(n)}`),e.push({pattern:t,isGlob:!0,expandedPaths:[]})}else e.push({pattern:t,isGlob:!1,expandedPaths:[t]})};return r(`${_.homedir()}/.claude/local/${n}`),process.env.NPM_PREFIX&&r(`${process.env.NPM_PREFIX}/lib/${n}`),process.env.N_PREFIX&&r(`${process.env.N_PREFIX}/lib/${n}`),process.env.VOLTA_HOME&&r(`${process.env.VOLTA_HOME}/lib/${n}`),process.env.FNM_DIR&&r(`${process.env.FNM_DIR}/lib/${n}`),process.env.NVM_DIR&&r(`${process.env.NVM_DIR}/lib/${n}`),process.env.NODENV_ROOT&&r(`${process.env.NODENV_ROOT}/versions/*/lib/${n}`,!0),process.env.NVS_HOME&&r(`${process.env.NVS_HOME}/node/*/*/lib/${n}`,!0),process.env.ASDF_DATA_DIR&&r(`${process.env.ASDF_DATA_DIR}/installs/nodejs/*/lib/${n}`,!0),process.platform==`win32`?(r(`${t}/AppData/Local/Volta/tools/image/packages/@anthropic-ai/claude-code/${n}`),r(`${t}/AppData/Roaming/npm/${n}`),r(`${t}/AppData/Roaming/nvm/*/${n}`,!0),r(`${t}/AppData/Local/Yarn/config/global/${n}`),r(`${t}/AppData/Local/pnpm/global/*/${n}`,!0),r(`C:/nvm4w/nodejs/${n}`),r(`${t}/n/versions/node/*/lib/${n}`,!0),r(`${t}/AppData/Roaming/Yarn/config/global/${n}`),r(`${t}/AppData/Roaming/pnpm-global/${n}`),r(`${t}/AppData/Roaming/pnpm-global/*/${n}`,!0),r(`${t}/.bun/install/global/${n}`),r(`${t}/.bun/install/cache/@anthropic-ai/claude-code*@@@*`,!0),r(`${t}/AppData/Local/Bun/install/cache/@anthropic-ai/claude-code*@@@*`,!0),r(`${t}/AppData/Local/fnm_multishells/*/node_modules/${n}`,!0),r(`${t}/AppData/Local/mise/installs/node/*/${n}`,!0),r(`${t}/AppData/Local/mise/installs/npm-anthropic-ai-claude-code/*/${n}`,!0)):(process.platform==`darwin`&&(r(`${t}/Library/${n}`),r(`/opt/local/lib/${n}`),r(`${t}/.bun/install/cache/@anthropic-ai/claude-code*@@@*`,!0),r(`${t}/Library/Caches/bun/install/cache/@anthropic-ai/claude-code*@@@*`,!0)),r(`${t}/.local/lib/${n}`),r(`${t}/.local/share/${n}`),r(`${t}/.npm-global/lib/${n}`),r(`${t}/.npm-packages/lib/${n}`),r(`${t}/.npm/lib/${n}`),r(`${t}/npm/lib/${n}`),r(`/etc/${n}`),r(`/lib/${n}`),r(`/opt/node/lib/${n}`),r(`/usr/lib/${n}`),r(`/usr/local/lib/${n}`),r(`/usr/share/${n}`),r(`/var/lib/${n}`),r(`/opt/homebrew/lib/${n}`),r(`${t}/.linuxbrew/lib/${n}`),r(`${t}/.config/yarn/global/${n}`),r(`${t}/.yarn/global/${n}`),r(`${t}/.bun/install/global/${n}`),r(`${t}/.pnpm-global/${n}`),r(`${t}/.pnpm-global/*/${n}`,!0),r(`${t}/pnpm-global/${n}`),r(`${t}/pnpm-global/*/${n}`,!0),r(`${t}/.local/share/pnpm/global/${n}`),r(`${t}/.local/share/pnpm/global/*/${n}`,!0),r(`${t}/.bun/install/global/${n}`),r(`${t}/.bun/install/cache/@anthropic-ai/claude-code*@@@*`,!0),r(`${t}/.local/share/bun/install/cache/@anthropic-ai/claude-code*@@@*`,!0),r(`/usr/local/n/versions/node/*/lib/${n}`,!0),r(`${t}/n/versions/node/*/lib/${n}`,!0),r(`${t}/n/lib/${n}`),r(`${t}/.volta/tools/image/node/*/lib/${n}`,!0),r(`${t}/.fnm/node-versions/*/installation/lib/${n}`,!0),r(`${t}/.local/state/fnm_multishells/*/lib/${n}`,!0),r(`/usr/local/nvm/versions/node/*/lib/${n}`,!0),r(`/usr/local/share/nvm/versions/node/*/lib/${n}`,!0),r(`${t}/.nvm/versions/node/*/lib/${n}`,!0),r(`${t}/.nodenv/versions/*/lib/${n}`,!0),r(`${t}/.nvs/*/lib/${n}`,!0),r(`${t}/.asdf/installs/nodejs/*/lib/${n}`,!0),process.env.MISE_DATA_DIR&&r(`${process.env.MISE_DATA_DIR}/installs/node/*/lib/${n}`,!0),r(`${t}/.local/share/mise/installs/node/*/lib/${n}`,!0),process.env.MISE_DATA_DIR&&r(`${process.env.MISE_DATA_DIR}/installs/npm-anthropic-ai-claude-code/*/lib/${n}`,!0),r(`${t}/.local/share/mise/installs/npm-anthropic-ai-claude-code/*/lib/${n}`,!0)),process.platform==`win32`&&e.forEach(e=>{e.pattern=e.pattern.replace(/\//g,`\\`),e.expandedPaths=e.expandedPaths.map(e=>e.replace(/\//g,`\\`))}),e})().flatMap(e=>e.expandedPaths),re=(()=>{let e=process.platform===`win32`?_.homedir().replace(/\\/g,`/`):_.homedir(),t=[],n=(e,n=!1)=>{if(n)try{let n=w(e,{onlyFiles:!0});t.push({pattern:e,isGlob:!0,expandedPaths:n})}catch(n){n instanceof Error&&`code`in n&&(n.code===`EACCES`||n.code===`EPERM`)?o(`Permission denied accessing: ${e} (${n.code})`):o(`Error expanding glob pattern "${e}": ${n instanceof Error?n.message:String(n)}`),t.push({pattern:e,isGlob:!0,expandedPaths:[]})}else t.push({pattern:e,isGlob:!1,expandedPaths:[e]})};return n(`${e}/.local/bin/claude`),n(`${e}/.local/share/claude/versions/*`,!0),process.platform===`win32`&&t.forEach(e=>{e.pattern=e.pattern.replace(/\//g,`\\`),e.expandedPaths=e.expandedPaths.map(e=>e.replace(/\//g,`\\`))}),t})().flatMap(e=>e.expandedPaths);var E=class extends Error{constructor(e){super(e),this.name=`InstallationDetectionError`}};let D=null;async function ie(){return D||=C.create().catch(e=>(o(`WASMagic initialization failed (likely SIMD unsupported on this CPU):`,e),o(`Using fallback file type detection`),null)),D}const ae=Buffer.from([127,69,76,70]),oe=Buffer.from([254,237,250,206]),se=Buffer.from([254,237,250,207]),O=Buffer.from([206,250,237,254]),k=Buffer.from([207,250,237,254]),A=Buffer.from([202,254,186,190]),j=Buffer.from([77,90]);function M(e){if(e.length===0)return null;if(e[0]===35&&e[1]===33&&e.subarray(0,Math.min(256,e.length)).toString(`utf8`).split(`
|
|
2
|
+
`)[0].includes(`node`))return o(`detectFileTypeFallback: Detected JavaScript via shebang`),`javascript`;if(e.length>=4){let t=e.subarray(0,4);if(t.equals(ae))return o(`detectFileTypeFallback: Detected ELF binary`),`binary`;if(t.equals(oe)||t.equals(se)||t.equals(O)||t.equals(k)||t.equals(A))return o(`detectFileTypeFallback: Detected Mach-O binary`),`binary`}if(e.length>=2&&e.subarray(0,2).equals(j))return o(`detectFileTypeFallback: Detected PE binary`),`binary`;let t=Math.min(512,e.length),n=0,r=0;for(let i=0;i<t;i++){let t=e[i];(t>=32&&t<=126||t===9||t===10||t===13)&&n++,t===0&&r++}if(r>0)return o(`detectFileTypeFallback: Detected binary (${r} null bytes in first ${t} bytes)`),`binary`;let i=n/t;return i>.9?(o(`detectFileTypeFallback: Detected JavaScript via text heuristic (${Math.round(i*100)}% printable)`),`javascript`):(o(`detectFileTypeFallback: Unknown file type (${Math.round(i*100)}% printable)`),null)}async function N(e,t=4096){try{let n=await v.open(e,`r`);try{let e=Buffer.allocUnsafe(t),{bytesRead:r}=await n.read({buffer:e,position:0,length:t});return r<=0?null:e.subarray(0,r)}finally{await n.close()}}catch(e){return o(`Failed to read file prefix:`,e),null}}async function P(e){try{let t=await v.realpath(e);o(`resolvePathToInstallationType: ${e} -> ${t}`);let n=await N(t);if(!n)return o(`resolvePathToInstallationType: Could not read file prefix`),null;let r=await ie();if(r&&typeof r.detect==`function`){let e=r.detect(n)||null;if(e){let n=e.toLowerCase();return o(`resolvePathToInstallationType: Detected mime type: ${n}`),n.includes(`javascript`)?{kind:`npm-based`,resolvedPath:t}:n.startsWith(`text/`)?(o(`resolvePathToInstallationType: Unrecognized file type`),null):{kind:`native-binary`,resolvedPath:t}}}o(`resolvePathToInstallationType: Using fallback file type detection`);let i=M(n);return i===`javascript`?{kind:`npm-based`,resolvedPath:t}:i===`binary`?{kind:`native-binary`,resolvedPath:t}:(o(`resolvePathToInstallationType: Fallback could not determine file type`),null)}catch(e){return o(`resolvePathToInstallationType: Error:`,e),null}}async function F(){try{let e=await S(`claude`);return o(`getClaudeFromPath: Found claude at ${e}`),e}catch{return o(`getClaudeFromPath: claude not found on PATH`),null}}function I(e){let t=/\bVERSION:"(\d+\.\d+\.\d+)"/g,n=new Map,r;for(;(r=t.exec(e))!==null;){let e=r[1];n.set(e,(n.get(e)||0)+1)}if(n.size===0)return null;let i=0,a;for(let[e,t]of n.entries())o(`Found version ${e} with ${t} occurrences`),t>i&&(i=t,a=e);return a&&o(`Extracted version ${a} (${i} occurrences)`),a||null}async function L(e){let t=I(await v.readFile(e,`utf8`));if(!t)throw Error(`No VERSION strings found in JS file: ${e}`);return t}async function R(e){let t=await n(e);if(!t)throw Error(`Could not extract JS from native binary: ${e}`);let r=I(t.toString(`utf8`));if(!r)throw Error(`No VERSION strings found in extracted JS from: ${e}`);return r}function z(e){let t=y.basename(e).match(/^(\d+\.\d+\.\d+)$/);return t?t[1]:null}async function B(e,t){let n=z(e);return n?(o(`extractVersion: Got version ${n} from filename`),n):t===`npm-based`?L(e):R(e)}async function V(){let e=[],t=new Set;for(let n of T){let r=y.join(n,`cli.js`);if(!t.has(r))try{if(await l(r)){o(`collectCandidates: Found cli.js at ${r}`);let n=await L(r);e.push({path:r,kind:`npm-based`,version:n}),t.add(r)}}catch(e){o(`collectCandidates: Error checking ${r}:`,e)}}for(let n of re)if(!t.has(n))try{if(await l(n)){o(`collectCandidates: Found native binary at ${n}`);let r=await B(n,`native-binary`);e.push({path:n,kind:`native-binary`,version:r}),t.add(n)}}catch(e){o(`collectCandidates: Error checking ${n}:`,e)}return[...e].sort((e,t)=>a(e.version,t.version))}function H(e){return e.map(e=>` • ${e.path} (${e.kind}, v${e.version})`).join(`
|
|
3
|
+
`)}function U(e){return` 2. Set ccInstallationPath in your config file (${u}):
|
|
4
|
+
|
|
5
|
+
{
|
|
6
|
+
"ccInstallationPath": "${e}"
|
|
7
|
+
}`}function W(e){return` 1. Set the TWEAKCC_CC_INSTALLATION_PATH environment variable:
|
|
8
|
+
|
|
9
|
+
export TWEAKCC_CC_INSTALLATION_PATH="${e}"`}function G(e){let t=e[0]?.path||`/path/to/claude`;return`Multiple Claude Code installations found.
|
|
10
|
+
|
|
11
|
+
Found installations:
|
|
12
|
+
${H(e)}
|
|
13
|
+
|
|
14
|
+
To specify which installation to use, either:
|
|
15
|
+
|
|
16
|
+
${W(t)}
|
|
17
|
+
|
|
18
|
+
${U(t)}`}function K(){return`Could not find Claude Code installation.
|
|
19
|
+
|
|
20
|
+
To fix this, either:
|
|
21
|
+
|
|
22
|
+
${W(`/path/to/claude`)}
|
|
23
|
+
|
|
24
|
+
${U(`/path/to/claude`)}
|
|
25
|
+
|
|
26
|
+
3. Install Claude Code:
|
|
27
|
+
• npm install -g @anthropic-ai/claude-code
|
|
28
|
+
• Or download from https://claude.ai/download`}function q(e,t,n,r){return t===`npm-based`?{cliPath:e,version:n,source:r}:{nativeInstallationPath:e,version:n,source:r}}async function J(e,t){let n=process.env.TWEAKCC_CC_INSTALLATION_PATH?.trim();if(n&&n.length>0){if(o(`Checking TWEAKCC_CC_INSTALLATION_PATH: ${n}`),!await l(n))throw new E(`TWEAKCC_CC_INSTALLATION_PATH is set to '${n}' but file does not exist.`);let e=await P(n);if(!e)throw new E(`Unable to detect installation type from TWEAKCC_CC_INSTALLATION_PATH value '${n}'.\nExpected a Claude Code cli.js file or native binary.`);let t=await B(e.resolvedPath,e.kind);return d()&&e.kind===`npm-based`&&o(`SHA256 hash: ${await r(e.resolvedPath)}`),o(`Using Claude Code from TWEAKCC_CC_INSTALLATION_PATH: ${e.resolvedPath} (${e.kind}, v${t})`),q(e.resolvedPath,e.kind,t,`env-var`)}if(e.ccInstallationPath){let t=e.ccInstallationPath;if(o(`Checking ccInstallationPath: ${t}`),!await l(t))throw new E(`ccInstallationPath is set to '${t}' but file does not exist.`);let n=await P(t);if(!n)throw new E(`Unable to detect installation type from configured ccInstallationPath '${t}'.\nExpected a Claude Code cli.js file or native binary.`);let i=await B(n.resolvedPath,n.kind);return d()&&n.kind===`npm-based`&&o(`SHA256 hash: ${await r(n.resolvedPath)}`),o(`Using Claude Code from ccInstallationPath: ${n.resolvedPath} (${n.kind}, v${i})`),q(n.resolvedPath,n.kind,i,`config`)}let i=await F();if(i){o(`Checking claude on PATH: ${i}`);let e=await P(i);if(!e)o(`Unable to detect installation type from 'claude' on PATH (${i}). Falling back to hardcoded search paths.`);else{let t=await B(e.resolvedPath,e.kind);return d()&&e.kind===`npm-based`&&o(`SHA256 hash: ${await r(e.resolvedPath)}`),o(`Using Claude Code from PATH: ${e.resolvedPath} (${e.kind}, v${t})`),q(e.resolvedPath,e.kind,t,`path`)}}o(`Collecting candidates from hardcoded search paths...`);let a=await V();if(a.length===0){if(t.interactive)return null;throw new E(K())}if(a.length===1){let e=a[0];return o(`Using single candidate: ${e.path} (${e.kind}, v${e.version})`),q(e.path,e.kind,e.version,`search-paths`)}if(!t.interactive)throw new E(G(a));return{version:``,source:`search-paths`,_pendingCandidates:a}}function Y(e){return e._pendingCandidates||null}async function ce(e){return o(`Saving selected installation to config: ${e.path}`),await s(t=>{t.ccInstallationPath=e.path}),q(e.path,e.kind,e.version,`config`)}function le(){return K()}function X({candidates:e,onSelect:t,onCancel:n}){let[r,i]=ee(0);return h((a,o)=>{o.escape?n?n():process.exit(0):o.upArrow?i(t=>t>0?t-1:e.length-1):o.downArrow?i(t=>t<e.length-1?t+1:0):o.return&&t(e[r])}),x(f,{flexDirection:`column`,children:[b(p,{bold:!0,color:`yellow`,children:`No claude executable was found in PATH, but multiple Claude Code installations were found on this machine. Please select one:`}),b(p,{children:` `}),e.map((e,t)=>x(f,{children:[x(p,{bold:t===r,color:t===r?`cyan`:void 0,children:[t===r?`❯ `:` `,e.path]}),x(p,{dimColor:!0,children:[` `,`(`,e.kind,`, v`,e.version,`)`]})]},e.path)),b(p,{children:` `}),x(p,{children:[`Your choice will be saved to`,` `,b(p,{color:`blue`,children:`ccInstallationPath`}),` in`,` `,x(p,{color:`blue`,children:[c.replace(te.homedir(),`~`),`/config.json`]}),`.`]}),b(p,{children:` `}),b(p,{dimColor:!0,children:`Use ↑↓ arrows to navigate, Enter to select, Esc to quit`})]})}function Z(e){return{path:e.path,version:e.version,kind:e.kind===`npm-based`?`npm`:`native`}}function Q(e){let t=e.cliPath??e.nativeInstallationPath;if(!t)throw Error(`Installation info has neither cliPath nor nativeInstallationPath`);return{path:t,version:e.version,kind:e.cliPath?`npm`:`native`}}async function ue(){return(await V()).map(Z)}async function de(e={}){if(e.path){let t=await P(e.path);if(!t)throw Error(`Unable to detect installation type from path '${e.path}'. Expected a Claude Code cli.js file or native binary.\n`);let n=await B(t.resolvedPath,t.kind);return{path:t.resolvedPath,version:n,kind:t.kind===`npm-based`?`npm`:`native`}}let t=await J(await i(),{interactive:!0});if(!t)throw Error(`Could not find Claude Code installation. Install Claude Code or specify the path explicitly.`);let n=Y(t);if(n){if(!e.interactive){let e=n.map(e=>` • ${e.path} (${e.kind}, v${e.version})`).join(`
|
|
29
|
+
`);throw Error(`Multiple Claude Code installations found:\n${e}\n\nPass { interactive: true } to show a picker, or { path: "..." } to specify explicitly.\nAlternatively, set "ccInstallationPath" in ${u} to the path to a Claude Code installation.`)}let t=await $(n.map(Z));if(!t)throw Error(`No installation selected.`);return t}return Q(t)}async function $(e){let t=e.map(e=>({path:e.path,version:e.version,kind:e.kind===`npm`?`npm-based`:`native-binary`}));return new Promise((e,n)=>{let r,i=()=>{try{r.unmount()}catch{}process.stdin.ref()},a=t=>{i(),e(Z(t))},o=()=>{i(),e(null)};try{r=m(g.createElement(X,{candidates:t,onSelect:a,onCancel:o}),{exitOnCtrlC:!1}),r.waitUntilExit().catch(e=>{i(),n(e instanceof Error?e:Error(String(e)))})}catch(e){process.stdin.ref(),n(e instanceof Error?e:Error(String(e)))}})}async function fe(e){if(e.kind===`native`){let t=await n(e.path);if(!t)throw Error(`Failed to extract JavaScript from native installation: ${e.path}`);return t.toString(`utf8`)}else return ne.readFile(e.path,{encoding:`utf8`})}async function pe(n,r){if(n.kind===`native`){let e=Buffer.from(r,`utf8`);await t(n.path,e,n.path)}else await e(n.path,r,`patch`)}export{de as a,J as c,ce as d,$ as i,le as l,pe as n,X as o,ue as r,E as s,fe as t,Y as u};
|