tweakcc 4.0.13 → 4.1.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 +2 -2
- package/dist/config-CQ6NxQ7f.mjs +668 -0
- package/dist/content-BrbtXJ4a.mjs +29 -0
- package/dist/index.mjs +10 -10
- package/dist/lib/index.mjs +1 -1
- package/dist/{nativeInstallation-BHG6-igp.mjs → nativeInstallation-DkUkHW0a.mjs} +1 -1
- package/package.json +3 -4
- package/dist/config-DDE1Qxwn.mjs +0 -668
- package/dist/content-D0J68msM.mjs +0 -29
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import{$ as e,D as t,S as n,c as r,d as i,et as a,f as o,l as s,m as c,n as l,r as u,tt as d,x as f}from"./config-CQ6NxQ7f.mjs";import{Box as p,Text as m,render as h,useInput as g}from"ink";import ee,{useState as te}from"react";import*as ne from"node:os";import _ from"node:os";import*as v from"node:fs/promises";import y from"node:fs/promises";import b from"path";import{jsx as x,jsxs as S}from"react/jsx-runtime";import C from"which";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),E=(()=>{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`),process.platform===`win32`&&n(`${e}/.local/bin/claude.exe`),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 D=class extends Error{constructor(e){super(e),this.name=`InstallationDetectionError`}};const O=Buffer.from([127,69,76,70]),re=Buffer.from([254,237,250,206]),ie=Buffer.from([254,237,250,207]),ae=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(`detectFileTypeHeuristic: Detected JavaScript via shebang`),`javascript`;if(e.length>=4){let t=e.subarray(0,4);if(t.equals(O))return o(`detectFileTypeHeuristic: Detected ELF binary`),`binary`;if(t.equals(re)||t.equals(ie)||t.equals(ae)||t.equals(k)||t.equals(A))return o(`detectFileTypeHeuristic: Detected Mach-O binary`),`binary`}if(e.length>=2&&e.subarray(0,2).equals(j))return o(`detectFileTypeHeuristic: 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(`detectFileTypeHeuristic: Detected binary (${r} null bytes in first ${t} bytes)`),`binary`;let i=e.subarray(0,t).toString(`utf8`).trimStart().toLowerCase();if(i.startsWith(`@echo`)||i.startsWith(`echo `)||i.startsWith(`cmd `)||i.startsWith(`cmd.exe `)||i.startsWith(`rem `))return o(`detectFileTypeHeuristic: Ignoring command script wrapper`),null;let a=n/t;return a>.9?(o(`detectFileTypeHeuristic: Detected JavaScript via text heuristic (${Math.round(a*100)}% printable)`),`javascript`):(o(`detectFileTypeHeuristic: Unknown file type (${Math.round(a*100)}% printable)`),null)}async function N(e,t=4096){try{let n=await y.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){if(process.platform===`win32`)return e;let t=await d(e);return t?(o(`maybeResolveNixWrapper: resolved Nix wrapper ${e} -> ${t}`),t):e}async function F(e){try{let t=await y.realpath(e);o(`resolvePathToInstallationType: ${e} -> ${t}`);let n=await N(t);if(!n)return o(`resolvePathToInstallationType: Could not read file prefix`),null;o(`resolvePathToInstallationType: Using heuristic file type detection`);let r=M(n);return r===`javascript`?{kind:`npm-based`,resolvedPath:t}:r===`binary`?{kind:`native-binary`,resolvedPath:await P(t)}:(o(`resolvePathToInstallationType: Heuristic could not determine file type`),null)}catch(e){return o(`resolvePathToInstallationType: Error:`,e),null}}async function I(){o(`getClaudeFromPath: PATH = ${process.env.PATH}`),o(`getClaudeFromPath: PATHEXT = ${process.env.PATHEXT}`);try{let e=await C(`claude`);return o(`getClaudeFromPath: Found claude at ${e}`),e}catch{return o(`getClaudeFromPath: claude not found on PATH`),null}}function L(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 R(e){let t=L(await y.readFile(e,`utf8`));if(!t)throw Error(`No VERSION strings found in JS file: ${e}`);return t}async function z(t){let n=await e(t);if(!n)throw Error(`Could not extract JS from native binary: ${t}`);let r=L(n.toString(`utf8`));if(!r)throw Error(`No VERSION strings found in extracted JS from: ${t}`);return r}function B(e){let t=b.basename(e).match(/^(\d+\.\d+\.\d+)$/);return t?t[1]:null}async function V(e,t){let n=B(e);return n?(o(`extractVersion: Got version ${n} from filename`),n):t===`npm-based`?R(e):z(e)}async function H(){let e=[],t=new Set;for(let n of T){let r=b.join(n,`cli.js`);if(!t.has(r))try{if(await c(r)){o(`collectCandidates: Found cli.js at ${r}`);let n=await R(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 E)if(!t.has(n))try{if(await c(n)){let r=await P(n);o(`collectCandidates: Found native binary at ${n}${r===n?``:` (resolved -> ${r})`}`);let i=await V(r,`native-binary`);e.push({path:r,kind:`native-binary`,version:i}),t.add(n)}}catch(e){o(`collectCandidates: Error checking ${n}:`,e)}return[...e].sort((e,t)=>i(e.version,t.version))}function U(e){return e.map(e=>` • ${e.path} (${e.kind}, v${e.version})`).join(`
|
|
3
|
+
`)}function W(e){return` 2. Set ccInstallationPath in your config file (${u}):
|
|
4
|
+
|
|
5
|
+
{
|
|
6
|
+
"ccInstallationPath": "${e}"
|
|
7
|
+
}`}function G(e){return` 1. Set the TWEAKCC_CC_INSTALLATION_PATH environment variable:
|
|
8
|
+
|
|
9
|
+
export TWEAKCC_CC_INSTALLATION_PATH="${e}"`}function K(e){let t=e[0]?.path||`/path/to/claude`;return`Multiple Claude Code installations found.
|
|
10
|
+
|
|
11
|
+
Found installations:
|
|
12
|
+
${U(e)}
|
|
13
|
+
|
|
14
|
+
To specify which installation to use, either:
|
|
15
|
+
|
|
16
|
+
${G(t)}
|
|
17
|
+
|
|
18
|
+
${W(t)}`}function q(){return`Could not find Claude Code installation.
|
|
19
|
+
|
|
20
|
+
To fix this, either:
|
|
21
|
+
|
|
22
|
+
${G(`/path/to/claude`)}
|
|
23
|
+
|
|
24
|
+
${W(`/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 J(e,t,n,r){return t===`npm-based`?{cliPath:e,version:n,source:r}:{nativeInstallationPath:e,version:n,source:r}}async function Y(e,t){let r=process.env.TWEAKCC_CC_INSTALLATION_PATH?.trim();if(r&&r.length>0){if(o(`Checking TWEAKCC_CC_INSTALLATION_PATH: ${r}`),!await c(r))throw new D(`TWEAKCC_CC_INSTALLATION_PATH is set to '${r}' but file does not exist.`);let e=await F(r);if(!e)throw new D(`Unable to detect installation type from TWEAKCC_CC_INSTALLATION_PATH value '${r}'.\nExpected a Claude Code cli.js file or native binary.`);let t=await V(e.resolvedPath,e.kind);return n()&&e.kind===`npm-based`&&o(`SHA256 hash: ${await f(e.resolvedPath)}`),o(`Using Claude Code from TWEAKCC_CC_INSTALLATION_PATH: ${e.resolvedPath} (${e.kind}, v${t})`),J(e.resolvedPath,e.kind,t,`env-var`)}if(e.ccInstallationPath){let t=e.ccInstallationPath;if(o(`Checking ccInstallationPath: ${t}`),!await c(t))throw new D(`ccInstallationPath is set to '${t}' but file does not exist.`);let r=await F(t);if(!r)throw new D(`Unable to detect installation type from configured ccInstallationPath '${t}'.\nExpected a Claude Code cli.js file or native binary.`);let i=await V(r.resolvedPath,r.kind);return n()&&r.kind===`npm-based`&&o(`SHA256 hash: ${await f(r.resolvedPath)}`),o(`Using Claude Code from ccInstallationPath: ${r.resolvedPath} (${r.kind}, v${i})`),J(r.resolvedPath,r.kind,i,`config`)}let i=await I();if(i){o(`Checking claude on PATH: ${i}`);let e=await F(i);if(!e)o(`Found 'claude' on PATH at '${i}', but it isn't a Claude Code cli.js or native binary (likely a CMD/BAT shim from a Node version manager such as Volta or nvm-windows). Falling back to hardcoded search paths.`);else{let t=await V(e.resolvedPath,e.kind);return n()&&e.kind===`npm-based`&&o(`SHA256 hash: ${await f(e.resolvedPath)}`),o(`Using Claude Code from PATH: ${e.resolvedPath} (${e.kind}, v${t})`),J(e.resolvedPath,e.kind,t,`path`)}}o(`Collecting candidates from hardcoded search paths...`);let a=await H();if(a.length===0){if(t.interactive)return null;throw new D(q())}if(a.length===1){let e=a[0];return o(`Using single candidate: ${e.path} (${e.kind}, v${e.version})`),J(e.path,e.kind,e.version,`search-paths`)}if(!t.interactive)throw new D(K(a));return{version:``,source:`search-paths`,_pendingCandidates:a}}function X(e){return e._pendingCandidates||null}async function oe(e){return o(`Saving selected installation to config: ${e.path}`),await s(t=>{t.ccInstallationPath=e.path}),J(e.path,e.kind,e.version,`config`)}function se(){return q()}function Z({candidates:e,onSelect:t,onCancel:n}){let[r,i]=te(0);return g((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])}),S(p,{flexDirection:`column`,children:[x(m,{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:`}),x(m,{children:` `}),e.map((e,t)=>S(p,{children:[S(m,{bold:t===r,color:t===r?`cyan`:void 0,children:[t===r?`❯ `:` `,e.path]}),S(m,{dimColor:!0,children:[` `,`(`,e.kind,`, v`,e.version,`)`]})]},e.path)),x(m,{children:` `}),S(m,{children:[`Your choice will be saved to`,` `,x(m,{color:`blue`,children:`ccInstallationPath`}),` in`,` `,S(m,{color:`blue`,children:[l.replace(ne.homedir(),`~`),`/config.json`]}),`.`]}),x(m,{children:` `}),x(m,{dimColor:!0,children:`Use ↑↓ arrows to navigate, Enter to select, Esc to quit`})]})}function Q(e){return{path:e.path,version:e.version,kind:e.kind===`npm-based`?`npm`:`native`}}function ce(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 le(){return(await H()).map(Q)}async function ue(e={}){if(e.path){let t=await F(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 V(t.resolvedPath,t.kind);return{path:t.resolvedPath,version:n,kind:t.kind===`npm-based`?`npm`:`native`}}let t=await Y(await r(),{interactive:!0});if(!t)throw Error(`Could not find Claude Code installation. Install Claude Code or specify the path explicitly.`);let n=X(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(Q));if(!t)throw Error(`No installation selected.`);return t}return ce(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(Q(t))},o=()=>{i(),e(null)};try{r=h(ee.createElement(Z,{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 de(t){if(t.kind===`native`){let n=await e(t.path);if(!n)throw Error(`Failed to extract JavaScript from native installation: ${t.path}`);return n.toString(`utf8`)}else return v.readFile(t.path,{encoding:`utf8`})}async function fe(e,n){if(e.kind===`native`){let t=Buffer.from(n,`utf8`);await a(e.path,t,e.path)}else await t(e.path,n,`patch`)}export{ue as a,Y as c,oe as d,$ as i,se as l,fe as n,Z as o,le as r,D as s,de as t,X as u};
|