@vibeapi/cli 0.0.88 → 0.0.89

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.
@@ -1,3 +1,6 @@
1
+ type RegRunner = (args: string[]) => string;
2
+ /** 测试注入假的 reg.exe 与广播(非 Windows 没有注册表);传 null 恢复默认。 */
3
+ export declare function setUserEnvRunnersForTests(runner: RegRunner | null, onBroadcast?: () => void): void;
1
4
  export interface PersistentEnvResult {
2
5
  /** rc 文件里加了加载行(新开终端才生效);Windows 为空。 */
3
6
  rcFiles: string[];
@@ -11,3 +14,4 @@ export declare function writePersistentEnv(id: string, envFile: string, vars: Re
11
14
  export declare function removePersistentEnv(id: string, envFile: string, names: readonly string[]): void;
12
15
  /** 读回 env 文件里的变量;文件不存在或没有内容时为空对象。 */
13
16
  export declare function readPersistentEnvFile(envFile: string): Record<string, string>;
17
+ export {};
@@ -1 +1 @@
1
- import{chmodSync as n,existsSync as t,readFileSync as e,realpathSync as o,unlinkSync as r}from"fs";import{join as i}from"path";import{logger as s}from"../utils/logger.js";import{getShellRcFilePath as c,runPowerShell as f}from"./env-cleanup.js";import{atomicWriteFile as l,backupBeforeWrite as u}from"./tools/backup.js";import{toolHome as p}from"./tools/types.js";const a=n=>`# vibecli:${n}`;function m(){const n=p(),e=new Set,o=c();o&&e.add(o);for(const o of[".zshrc",".bashrc"]){const r=i(n,o);t(r)&&e.add(r)}return[...e]}function $(n,t,e){const o=`"${function(n){const t=p();return n.startsWith(t+"/")?`$HOME/${n.slice(t.length+1)}`:n}(t)}"`;return n.endsWith(".fish")?`test -f ${o}; and source ${o} ${a(e)}`:`[ -f ${o} ] && . ${o} ${a(e)}`}function v(n,e){const r=t(n)?o(n):n;u(r),l(r,e)}function E(n,t){return n.split("\n").filter(n=>!n.trimEnd().endsWith(a(t))).join("\n")}function d(n,t){if(/['\r\n]/.test(t))throw new Error(`${n} contains a quote or newline and cannot be written to a shell env file`)}export function writePersistentEnv(o,r,i){for(const[n,t]of Object.entries(i))d(n,t);const s=Object.entries(i).map(([n,t])=>`export ${n}='${t}'`).join("\n");u(r),l(r,`# Written by vibecli. Loaded from your shell profile.\n${s}\n`,384),n(r,384);for(const[n,t]of Object.entries(i))process.env[n]=t;if("win32"===process.platform){const n=Object.entries(i).map(([n,t])=>`[Environment]::SetEnvironmentVariable('${n}','${t}','User')`).join(";");return f(n),{rcFiles:[]}}const c=[];for(const n of m()){const i=t(n)?e(n,"utf-8"):"",s=$(n,r,o);if(i.split("\n").some(n=>n.trimEnd()===s)){c.push(n);continue}const f=E(i,o).replace(/\n*$/,"");v(n,`${f?f+"\n\n":""}${s}\n`),c.push(n)}return{rcFiles:c}}export function removePersistentEnv(n,o,i){const c=readPersistentEnvFile(o);if(t(o)&&(u(o),r(o)),"win32"===process.platform){const n=i.filter(n=>void 0!==c[n]).map(n=>`if([Environment]::GetEnvironmentVariable('${n}','User') -eq '${c[n]}'){[Environment]::SetEnvironmentVariable('${n}',$null,'User')}`).join(";");if(n)try{f(n)}catch(n){s.logError("persistentEnv.remove",n)}return}for(const o of m()){if(!t(o))continue;const r=e(o,"utf-8"),i=E(r,n);i!==r&&v(o,i)}}export function readPersistentEnvFile(n){const o={};if(!t(n))return o;for(const t of e(n,"utf-8").split("\n")){const n=t.match(/^export ([A-Z_][A-Z0-9_]*)='([^']*)'$/);n&&(o[n[1]]=n[2])}return o}
1
+ import{execFileSync as t,spawn as n}from"child_process";import{chmodSync as e,existsSync as o,readFileSync as r,realpathSync as s,unlinkSync as i}from"fs";import{join as c}from"path";import{logger as f}from"../utils/logger.js";import{getShellRcFilePath as u}from"./env-cleanup.js";import{atomicWriteFile as l,backupBeforeWrite as p}from"./tools/backup.js";import{toolHome as a}from"./tools/types.js";const d=t=>`# vibecli:${t}`;function m(){const t=a(),n=new Set,e=u();e&&n.add(e);for(const e of[".zshrc",".bashrc"]){const r=c(t,e);o(r)&&n.add(r)}return[...n]}function v(t,n,e){const o=`"${function(t){const n=a();return t.startsWith(n+"/")?`$HOME/${t.slice(n.length+1)}`:t}(n)}"`;return t.endsWith(".fish")?`test -f ${o}; and source ${o} ${d(e)}`:`[ -f ${o} ] && . ${o} ${d(e)}`}function E(t,n){const e=o(t)?s(t):t;p(e),l(e,n)}function $(t,n){return t.split("\n").filter(t=>!t.trimEnd().endsWith(d(n))).join("\n")}function h(t,n){if(/['\r\n]/.test(n))throw new Error(`${t} contains a quote or newline and cannot be written to a shell env file`)}const w="HKCU\\Environment",b=n=>t("reg.exe",n,{encoding:"utf-8",windowsHide:!0,timeout:15e3,stdio:["ignore","pipe","pipe"]});let g=b,j=()=>{const t=n("powershell.exe",["-NoProfile","-NonInteractive","-Command","[Environment]::SetEnvironmentVariable('VIBECLI_ENV_REFRESH',$null,'User')"],{detached:!0,stdio:"ignore",windowsHide:!0});t.on("error",t=>f.logError("persistentEnv.broadcast",t)),t.unref()};export function setUserEnvRunnersForTests(t,n){g=t??b,n&&(j=n)}function x(t){let n;try{n=g(["query",w,"/v",t])}catch{return}const e=n.match(new RegExp(String.raw`^\s*${t}\s+REG_(?:EXPAND_)?SZ\s+(.*?)\r?$`,"m"));return e?e[1]:void 0}export function writePersistentEnv(t,n,s){for(const[t,n]of Object.entries(s))h(t,n);const i=Object.entries(s).map(([t,n])=>`export ${t}='${n}'`).join("\n");p(n),l(n,`# Written by vibecli. Loaded from your shell profile.\n${i}\n`,384),e(n,384);for(const[t,n]of Object.entries(s))process.env[t]=n;if("win32"===process.platform){for(const[t,n]of Object.entries(s))g(["add",w,"/v",t,"/t","REG_SZ","/d",n,"/f"]);return j(),{rcFiles:[]}}const c=[];for(const e of m()){const s=o(e)?r(e,"utf-8"):"",i=v(e,n,t);if(s.split("\n").some(t=>t.trimEnd()===i)){c.push(e);continue}const f=$(s,t).replace(/\n*$/,"");E(e,`${f?f+"\n\n":""}${i}\n`),c.push(e)}return{rcFiles:c}}export function removePersistentEnv(t,n,e){const s=readPersistentEnvFile(n);if(o(n)&&(p(n),i(n)),"win32"===process.platform){let t=!1;for(const n of e)if(void 0!==s[n]&&x(n)===s[n])try{g(["delete",w,"/v",n,"/f"]),t=!0}catch(t){f.logError("persistentEnv.remove",t)}return void(t&&j())}for(const n of m()){if(!o(n))continue;const e=r(n,"utf-8"),s=$(e,t);s!==e&&E(n,s)}}export function readPersistentEnvFile(t){const n={};if(!o(t))return n;for(const e of r(t,"utf-8").split("\n")){const t=e.match(/^export ([A-Z_][A-Z0-9_]*)='([^']*)'$/);t&&(n[t[1]]=t[2])}return n}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vibeapi/cli",
3
- "version": "0.0.88",
3
+ "version": "0.0.89",
4
4
  "description": "CLI tool for managing AI coding assistants (Claude Code, Codex, OpenClaw, Hermes, AtomCode, Grok Build) with one unified config",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",