@vibeapi/api-helper 0.0.30 → 0.0.32
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 +5 -17
- package/dist/commands/setup.d.ts +1 -1
- package/dist/lib/config.d.ts +7 -6
- package/dist/lib/config.js +1 -1
- package/dist/lib/secret-store.d.ts +9 -32
- package/dist/lib/secret-store.js +1 -1
- package/dist/lib/tools/backup.d.ts +3 -4
- package/dist/lib/tools/backup.js +1 -1
- package/dist/lib/tools/codex.js +1 -1
- package/dist/lib/tools/types.d.ts +3 -4
- package/dist/locales/en_US.json +1 -5
- package/dist/locales/zh_CN.json +0 -4
- package/package.json +2 -2
- package/dist/__tests__/api-validator.test.d.ts +0 -1
- package/dist/__tests__/api-validator.test.js +0 -1
- package/dist/__tests__/api-validator.test.js.map +0 -1
- package/dist/__tests__/claude-code-manager.test.d.ts +0 -1
- package/dist/__tests__/claude-code-manager.test.js +0 -1
- package/dist/__tests__/claude-code-manager.test.js.map +0 -1
- package/dist/__tests__/command.test.d.ts +0 -1
- package/dist/__tests__/command.test.js +0 -1
- package/dist/__tests__/command.test.js.map +0 -1
- package/dist/__tests__/commands.test.d.ts +0 -1
- package/dist/__tests__/commands.test.js +0 -1
- package/dist/__tests__/commands.test.js.map +0 -1
- package/dist/__tests__/config-profiles.test.d.ts +0 -1
- package/dist/__tests__/config-profiles.test.js +0 -1
- package/dist/__tests__/config-profiles.test.js.map +0 -1
- package/dist/__tests__/config.test.d.ts +0 -1
- package/dist/__tests__/config.test.js +0 -1
- package/dist/__tests__/config.test.js.map +0 -1
- package/dist/__tests__/env-cleanup.test.d.ts +0 -1
- package/dist/__tests__/env-cleanup.test.js +0 -1
- package/dist/__tests__/env-cleanup.test.js.map +0 -1
- package/dist/__tests__/extra-commands.test.d.ts +0 -1
- package/dist/__tests__/extra-commands.test.js +0 -1
- package/dist/__tests__/extra-commands.test.js.map +0 -1
- package/dist/__tests__/i18n.test.d.ts +0 -1
- package/dist/__tests__/i18n.test.js +0 -1
- package/dist/__tests__/i18n.test.js.map +0 -1
- package/dist/__tests__/logger.test.d.ts +0 -1
- package/dist/__tests__/logger.test.js +0 -1
- package/dist/__tests__/logger.test.js.map +0 -1
- package/dist/__tests__/model-registry.test.d.ts +0 -1
- package/dist/__tests__/model-registry.test.js +0 -1
- package/dist/__tests__/model-registry.test.js.map +0 -1
- package/dist/__tests__/opencode-manager.test.d.ts +0 -1
- package/dist/__tests__/opencode-manager.test.js +0 -1
- package/dist/__tests__/opencode-manager.test.js.map +0 -1
- package/dist/__tests__/runtime-options.test.d.ts +0 -1
- package/dist/__tests__/runtime-options.test.js +0 -1
- package/dist/__tests__/runtime-options.test.js.map +0 -1
- package/dist/__tests__/secret-store.test.d.ts +0 -1
- package/dist/__tests__/secret-store.test.js +0 -1
- package/dist/__tests__/secret-store.test.js.map +0 -1
- package/dist/__tests__/settings-template.test.d.ts +0 -1
- package/dist/__tests__/settings-template.test.js +0 -1
- package/dist/__tests__/settings-template.test.js.map +0 -1
- package/dist/__tests__/setup-command.test.d.ts +0 -1
- package/dist/__tests__/setup-command.test.js +0 -1
- package/dist/__tests__/setup-command.test.js.map +0 -1
- package/dist/__tests__/string-width.test.d.ts +0 -1
- package/dist/__tests__/string-width.test.js +0 -1
- package/dist/__tests__/string-width.test.js.map +0 -1
- package/dist/__tests__/tool-adapters.test.d.ts +0 -1
- package/dist/__tests__/tool-adapters.test.js +0 -1
- package/dist/__tests__/tool-adapters.test.js.map +0 -1
- package/dist/__tests__/tool-manager.test.d.ts +0 -1
- package/dist/__tests__/tool-manager.test.js +0 -1
- package/dist/__tests__/tool-manager.test.js.map +0 -1
- package/dist/__tests__/wizard.test.d.ts +0 -1
- package/dist/__tests__/wizard.test.js +0 -1
- package/dist/__tests__/wizard.test.js.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/commands/auth.js.map +0 -1
- package/dist/commands/bench.js.map +0 -1
- package/dist/commands/completion.js.map +0 -1
- package/dist/commands/config.js.map +0 -1
- package/dist/commands/doctor.js.map +0 -1
- package/dist/commands/index.js.map +0 -1
- package/dist/commands/lang.js.map +0 -1
- package/dist/commands/logs.js.map +0 -1
- package/dist/commands/setup.js.map +0 -1
- package/dist/commands/status.js.map +0 -1
- package/dist/commands/update.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/lib/api-validator.js.map +0 -1
- package/dist/lib/brand.js.map +0 -1
- package/dist/lib/claude-code-manager.js.map +0 -1
- package/dist/lib/command.js.map +0 -1
- package/dist/lib/config.js.map +0 -1
- package/dist/lib/confirm.js.map +0 -1
- package/dist/lib/env-cleanup.js.map +0 -1
- package/dist/lib/i18n.js.map +0 -1
- package/dist/lib/model-registry.js.map +0 -1
- package/dist/lib/opencode-manager.js.map +0 -1
- package/dist/lib/runtime-options.js.map +0 -1
- package/dist/lib/secret-store.js.map +0 -1
- package/dist/lib/settings-template.js.map +0 -1
- package/dist/lib/tool-manager.js.map +0 -1
- package/dist/lib/tools/atomcode.js.map +0 -1
- package/dist/lib/tools/backup.js.map +0 -1
- package/dist/lib/tools/claude-code.js.map +0 -1
- package/dist/lib/tools/codex.js.map +0 -1
- package/dist/lib/tools/hermes.js.map +0 -1
- package/dist/lib/tools/openclaw.js.map +0 -1
- package/dist/lib/tools/opencode.js.map +0 -1
- package/dist/lib/tools/registry.js.map +0 -1
- package/dist/lib/tools/types.js.map +0 -1
- package/dist/lib/wizard.js.map +0 -1
- package/dist/utils/logger.js.map +0 -1
- package/dist/utils/string-width.js.map +0 -1
package/README.md
CHANGED
|
@@ -16,14 +16,6 @@ npm install -g @vibeapi/cli # 或全局安装后用 vibecli
|
|
|
16
16
|
|
|
17
17
|
> `@vibeapi/cli` 与 `@vibeapi/api-helper` 是同一产物的双包名(同版本等价),装哪个都一样。
|
|
18
18
|
|
|
19
|
-
**npmjs.com 连不上时走 CNB 镜像**(同步发布):
|
|
20
|
-
|
|
21
|
-
```bash
|
|
22
|
-
npm config set registry https://registry.npmmirror.com
|
|
23
|
-
npm config set @vibeapi:registry https://npm.cnb.cool/vibeapi/npm/-/packages/
|
|
24
|
-
npm install -g @vibeapi/api-helper
|
|
25
|
-
```
|
|
26
|
-
|
|
27
19
|
## 快速开始
|
|
28
20
|
|
|
29
21
|
```bash
|
|
@@ -35,7 +27,7 @@ vibecli status # 查看当前配置
|
|
|
35
27
|
|
|
36
28
|
```bash
|
|
37
29
|
vibecli setup --key sk-xxx # 校验后按 Key 能力自动配置(能访问 Claude 模型配 Claude Code、能访问 GPT 模型配 Codex)
|
|
38
|
-
vibecli setup --claudekey sk-a --codexkey sk-b # 双令牌各配各的(如 Claude 分组 + GPT
|
|
30
|
+
vibecli setup --claudekey sk-a --codexkey sk-b # 双令牌各配各的(如 Claude 分组 + GPT 分组),存为工具专属 Key
|
|
39
31
|
```
|
|
40
32
|
|
|
41
33
|
非交互(CI):
|
|
@@ -51,7 +43,7 @@ vibecli config claude-code --non-interactive
|
|
|
51
43
|
- **按工具选模型**:使用默认 / 实时从 API 拉取 / 内置预设 / 手动输入;每个工具可用不同模型。
|
|
52
44
|
- Claude Code 默认用 Claude 组合(sonnet 为 1M 变体 `claude-sonnet-5[1m]`,opus 为 1M 变体 `claude-opus-4-8[1m]`);Codex 默认 `gpt-5.6-sol`,其余工具默认 `gpt-5.5`。
|
|
53
45
|
- **改前自动备份 + 一键还原**:覆盖配置前先快照(每文件留 10 份),`vibecli config <tool> restore` 随时回退;还原本身也可再撤销。
|
|
54
|
-
- **多 Profile +
|
|
46
|
+
- **多 Profile + 可迁移凭据**:work/personal 各自独立;API Key 存在权限为 `0600` 的 `~/.vibecli/config.yaml`,与 Claude/Codex 本身的明文凭据方式一致,换机不会被主机绑定加密阻断。
|
|
55
47
|
- **CI 友好**:所有命令支持 `--json` / `--non-interactive` / `--yes` / `--dry-run` / `--no-color`。
|
|
56
48
|
|
|
57
49
|
## 常用命令
|
|
@@ -64,14 +56,10 @@ vibecli config profile use work # 切换 profile
|
|
|
64
56
|
vibecli doctor # 健康巡检
|
|
65
57
|
```
|
|
66
58
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
## 链接
|
|
59
|
+
## 支持
|
|
70
60
|
|
|
71
|
-
|
|
72
|
-
- [CHANGELOG](./CHANGELOG.md) · [发布流程 PUBLISH.md](./PUBLISH.md)
|
|
73
|
-
- 主页 <https://www.vibeapi.cn/> · 反馈 <https://www.vibeapi.cn/support>
|
|
61
|
+
主页 <https://www.vibeapi.cn/> · 反馈 <https://www.vibeapi.cn/support>
|
|
74
62
|
|
|
75
63
|
## License
|
|
76
64
|
|
|
77
|
-
UNLICENSED — 仅供 VibeAPI
|
|
65
|
+
UNLICENSED — 仅供 VibeAPI 用户使用,详见随包附带的 LICENSE。
|
package/dist/commands/setup.d.ts
CHANGED
package/dist/lib/config.d.ts
CHANGED
|
@@ -11,6 +11,8 @@ export interface VibecliModels {
|
|
|
11
11
|
}
|
|
12
12
|
export interface VibecliProfile {
|
|
13
13
|
api_key?: string;
|
|
14
|
+
/** Per-tool credentials used by setup --claudekey/--codexkey. */
|
|
15
|
+
tool_api_keys?: Record<string, string>;
|
|
14
16
|
base_url?: string;
|
|
15
17
|
models?: VibecliModels;
|
|
16
18
|
/** Per-tool model overrides, merged over `models` when configuring that tool. */
|
|
@@ -27,6 +29,7 @@ export interface ConfigBackupInfo {
|
|
|
27
29
|
}
|
|
28
30
|
export interface VibecliConfig {
|
|
29
31
|
lang: string;
|
|
32
|
+
credential_store?: 'plaintext';
|
|
30
33
|
active_profile?: string;
|
|
31
34
|
profiles?: Record<string, VibecliProfile>;
|
|
32
35
|
presets?: Record<string, VibecliPreset>;
|
|
@@ -53,6 +56,7 @@ export declare class ConfigManager {
|
|
|
53
56
|
private createDefaultConfig;
|
|
54
57
|
private normalizeModels;
|
|
55
58
|
private normalizeToolModels;
|
|
59
|
+
private normalizeStringRecord;
|
|
56
60
|
private normalizeProfile;
|
|
57
61
|
private normalizeProfiles;
|
|
58
62
|
private normalizePresets;
|
|
@@ -60,22 +64,19 @@ export declare class ConfigManager {
|
|
|
60
64
|
private syncLegacyFields;
|
|
61
65
|
private sanitizeBackupLabel;
|
|
62
66
|
private getBackupDir;
|
|
63
|
-
private
|
|
67
|
+
private getLegacySecretsPath;
|
|
64
68
|
private getSecretsBackupPath;
|
|
65
|
-
private snapshotSecrets;
|
|
66
|
-
private restoreSecretsSnapshot;
|
|
67
69
|
static getInstance(): ConfigManager;
|
|
68
70
|
private ensureConfigDir;
|
|
69
71
|
private loadConfig;
|
|
70
|
-
private hasInlineSecrets;
|
|
71
72
|
private needsMigration;
|
|
72
73
|
private migrateOldConfig;
|
|
73
74
|
private atomicWrite;
|
|
74
75
|
private backupConfig;
|
|
75
76
|
private rotateBackups;
|
|
76
77
|
saveConfig(config?: VibecliConfig): void;
|
|
77
|
-
private
|
|
78
|
-
private
|
|
78
|
+
private prepareForPersistence;
|
|
79
|
+
private mergeLegacySecrets;
|
|
79
80
|
getConfig(): VibecliConfig;
|
|
80
81
|
updateConfig(updates: Partial<VibecliConfig>): void;
|
|
81
82
|
isFirstRun(): boolean;
|
package/dist/lib/config.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{existsSync as e,mkdirSync as t,readFileSync as i,writeFileSync as o,renameSync as r,unlinkSync as s,readdirSync as n,rmdirSync as a,statSync as c,copyFileSync as l}from"fs";import{join as f,dirname as g}from"path";import{homedir as h}from"os";import*as p from"js-yaml";import{logger as m}from"../utils/logger.js";import{getDefaultModels as u}from"./model-registry.js";import{secretStore as d}from"./secret-store.js";import{i18n as y}from"./i18n.js";export const DEFAULT_BASE_URL="https://www.vibeapi.cn";export const DEFAULT_MODELS=u();export const DEFAULT_PROFILE_NAME="default";export class ConfigManager{static instance;configDir;configPath;config;runtimeBaseUrl;constructor(){this.configDir=this.resolveConfigDir(),this.migrateLegacyConfigDir(),this.configPath=f(this.configDir,"config.yaml"),this.config=this.loadConfig()}migrateLegacyConfigDir(){try{const t=f(g(this.configDir),".chelper");if(t===this.configDir||!e(t))return;if(["config.yaml","secrets.enc"].some(t=>e(f(this.configDir,t))))return;if(e(this.configDir)){for(const i of n(t)){const o=f(this.configDir,i);e(o)||r(f(t,i),o)}0===n(t).length&&a(t)}else r(t,this.configDir);m.info(`Migrated config dir: ${t} -> ${this.configDir}`)}catch(e){m.warn("Failed to migrate legacy .chelper config dir:",e)}}resolveConfigDir(){const e=process.env.VIBECLI_CONFIG_DIR;if(e&&e.trim())return e.trim();const t=process.env.VIBECLI_TEST_HOME;return t&&t.trim()?f(t.trim(),".vibecli"):f(h(),".vibecli")}createDefaultConfig(){return this.syncLegacyFields({lang:"en_US",active_profile:"default",profiles:{[DEFAULT_PROFILE_NAME]:{}},presets:{}})}normalizeModels(e){const t={haiku:e?.haiku?.trim()||DEFAULT_MODELS.haiku,sonnet:e?.sonnet?.trim()||DEFAULT_MODELS.sonnet,opus:e?.opus?.trim()||DEFAULT_MODELS.opus,reasoning:e?.reasoning?.trim()||DEFAULT_MODELS.reasoning};if(e&&"object"==typeof e)for(const[i,o]of Object.entries(e))i in t||"string"==typeof o&&o.trim()&&(t[i]=o.trim());return t}normalizeToolModels(e){if(!e||"object"!=typeof e)return{};const t=Object.entries(e).flatMap(([e,t])=>{if(!e||"string"!=typeof e||!t||"object"!=typeof t)return[];const i={};for(const[e,o]of Object.entries(t))"string"==typeof o&&o.trim()&&(i[e]=o.trim());return Object.keys(i).length>0?[[e,i]]:[]});return Object.fromEntries(t)}normalizeProfile(e){if(!e)return{};const t=this.normalizeToolModels(e.tool_models);return{..."string"==typeof e.api_key&&e.api_key?{api_key:e.api_key}:{},..."string"==typeof e.base_url&&e.base_url?{base_url:e.base_url}:{},...e.models?{models:this.normalizeModels(e.models)}:{},...Object.keys(t).length>0?{tool_models:t}:{}}}normalizeProfiles(e){if(!e||"object"!=typeof e)return{};const t=Object.entries(e).flatMap(([e,t])=>e&&"string"==typeof e&&t&&"object"==typeof t?[[e,this.normalizeProfile(t)]]:[]);return Object.fromEntries(t)}normalizePresets(e){if(!e||"object"!=typeof e)return{};const t=Object.entries(e).flatMap(([e,t])=>{if(!e||"string"!=typeof e||!t||"object"!=typeof t)return[];const i=t;return i.models?[[e,{models:this.normalizeModels(i.models),updated_at:i.updated_at||new Date(0).toISOString()}]]:[]});return Object.fromEntries(t)}getResolvedActiveProfile(e){const t=e.active_profile||"default";return e.profiles?.[t]||{}}syncLegacyFields(e){const t=this.normalizeProfiles(e.profiles),i=e.active_profile?.trim()||Object.keys(t)[0]||"default",o=t[i]?t:{...t,[i]:{}},r=this.getResolvedActiveProfile({...e,profiles:o,active_profile:i});return{...e,lang:e.lang||"en_US",active_profile:i,profiles:o,presets:this.normalizePresets(e.presets),api_key:r.api_key,base_url:r.base_url,models:r.models?this.normalizeModels(r.models):DEFAULT_MODELS}}sanitizeBackupLabel(e){return(e||"").trim().replace(/[^a-zA-Z0-9._-]+/g,"-").replace(/^-+|-+$/g,"").slice(0,40)}getBackupDir(){return f(this.configDir,"backups")}getSecretsPath(){return f(this.configDir,"secrets.enc")}getSecretsBackupPath(e){return e.replace(/\.yaml$/,".secrets.enc")}snapshotSecrets(t){const i=this.getSecretsPath();if(e(i))try{l(i,this.getSecretsBackupPath(t))}catch(e){m.logError("ConfigManager.snapshotSecrets",e)}}restoreSecretsSnapshot(t){const i=this.getSecretsBackupPath(t);if(e(i))try{l(i,this.getSecretsPath())}catch(e){m.logError("ConfigManager.restoreSecretsSnapshot",e)}}static getInstance(){return ConfigManager.instance||(ConfigManager.instance=new ConfigManager),ConfigManager.instance}ensureConfigDir(){e(this.configDir)||t(this.configDir,{recursive:!0})}loadConfig(){try{if(e(this.configPath)){const e=i(this.configPath,"utf-8"),t=p.load(e),o=this.migrateOldConfig(t||{lang:"en_US"}),r=this.hydrateSecretsFromStore(o);return(this.needsMigration(t)||this.hasInlineSecrets(t))&&(this.backupConfig(),this.atomicWrite(this.configPath,p.dump(this.extractSecretsForPersistence(r)))),r}}catch(e){m.warn("Failed to load config, using defaults:",e),m.logError("ConfigManager.loadConfig",e)}return this.createDefaultConfig()}hasInlineSecrets(e){if(!e||"object"!=typeof e)return!1;const t=e;if("string"==typeof t.api_key&&t.api_key)return!0;if(t.profiles&&"object"==typeof t.profiles)for(const e of Object.values(t.profiles))if(e&&"object"==typeof e&&"string"==typeof e.api_key&&e.api_key)return!0;return!1}needsMigration(e){return!(!e||"object"!=typeof e)&&("plan"in e||!("profiles"in e)||!("active_profile"in e)||!("presets"in e))}migrateOldConfig(e){if(!e||"object"!=typeof e)return this.createDefaultConfig();const t=e,{plan:i,...o}=t,r=this.normalizeProfiles(o.profiles),s=this.normalizeProfile({api_key:"string"==typeof o.api_key?o.api_key:void 0,base_url:"string"==typeof o.base_url?o.base_url:void 0,models:o.models}),n=Object.keys(r).length>0?r:{[DEFAULT_PROFILE_NAME]:s},a="string"==typeof o.active_profile&&o.active_profile.trim()?o.active_profile.trim():Object.keys(n)[0]||"default";return this.syncLegacyFields({lang:"string"==typeof o.lang&&o.lang?o.lang:"en_US",active_profile:a,profiles:n,presets:this.normalizePresets(o.presets)})}atomicWrite(t,i){const n=`${t}.tmp`;try{o(n,i,"utf-8"),r(n,t)}catch(t){if(e(n))try{s(n)}catch{}throw t}}backupConfig(){if(!e(this.configPath))return;const r=this.getBackupDir();e(r)||t(r,{recursive:!0});const s=(new Date).toISOString().replace(/[:.]/g,"-"),n=f(r,`config-${s}.yaml`);try{const e=i(this.configPath,"utf-8");o(n,e,"utf-8"),this.snapshotSecrets(n),this.rotateBackups(r,10,30)}catch(e){m.logError("ConfigManager.backupConfig",e)}}rotateBackups(t,i,o){try{const r=Date.now()-24*o*60*60*1e3,a=n(t).filter(e=>e.startsWith("config-")&&e.endsWith(".yaml")).map(e=>({name:e,path:f(t,e),mtime:c(f(t,e)).mtime})).sort((e,t)=>t.mtime.getTime()-e.mtime.getTime()),l=new Set;a.slice(i).forEach(e=>l.add(e.path)),a.forEach(e=>{e.mtime.getTime()<r&&l.add(e.path)});for(const t of l){let i=!1;try{s(t),i=!0}catch(e){m.logError("ConfigManager.rotateBackups",e)}if(i){const i=this.getSecretsBackupPath(t);if(e(i))try{s(i)}catch(e){m.logError("ConfigManager.rotateBackups.secrets",e)}}}}catch(e){m.logError("ConfigManager.rotateBackups",e)}}saveConfig(e){try{this.ensureConfigDir(),this.backupConfig();const t=this.syncLegacyFields(this.migrateOldConfig(e||this.config)),i=this.extractSecretsForPersistence(t),o=p.dump(i);this.atomicWrite(this.configPath,o),this.config=t}catch(e){throw m.error("Failed to save config:",e),m.logError("ConfigManager.saveConfig",e),e}}extractSecretsForPersistence(e){const t={...e.profiles||{}},i=[];for(const[e,o]of Object.entries(t))o?.api_key&&(d.setApiKey(e,o.api_key),i.push(e));for(const e of i){const{api_key:i,...o}=t[e];t[e]=o}const o={...e,profiles:t};return delete o.api_key,o}hydrateSecretsFromStore(e){const t={...e.profiles||{}};for(const[e,i]of Object.entries(t)){if(i?.api_key)continue;const o=d.getApiKey(e);o&&(t[e]={...i,api_key:o})}return{...e,profiles:t}}getConfig(){return this.syncLegacyFields({...this.config})}updateConfig(e){this.saveConfig({...this.config,...e})}isFirstRun(){return!e(this.configPath)}getLang(){return this.config.lang||"en_US"}setLang(e){this.updateConfig({lang:e})}getActiveProfileName(){return this.config.active_profile||"default"}listProfiles(){return Object.keys(this.config.profiles||{}).sort()}getProfile(e=this.getActiveProfileName()){const t=this.config.profiles?.[e]||{};return{...t.api_key?{api_key:t.api_key}:{},...t.base_url?{base_url:t.base_url}:{},models:t.models?this.normalizeModels(t.models):DEFAULT_MODELS,...t.tool_models&&Object.keys(t.tool_models).length>0?{tool_models:this.normalizeToolModels(t.tool_models)}:{}}}createProfile(e,t=this.getActiveProfileName()){const i=this.getProfile(t),o={...this.config.profiles||{},[e]:{...i.api_key?{api_key:i.api_key}:{},...i.base_url?{base_url:i.base_url}:{},models:this.normalizeModels(i.models)}};this.saveConfig({...this.config,profiles:o})}setActiveProfile(e){if(!this.config.profiles?.[e])throw new Error(`Profile not found: ${e}`);this.saveConfig({...this.config,active_profile:e})}updateProfile(e,t){const i=this.config.profiles?.[e]||{},o=t.models?this.normalizeModels({...i.models,...t.models}):i.models?this.normalizeModels(i.models):void 0,r={...i,...void 0!==t.api_key?{api_key:t.api_key}:{},...void 0!==t.base_url?{base_url:t.base_url}:{},...o?{models:o}:{}},s={...this.config.profiles||{},[e]:r};this.saveConfig({...this.config,profiles:s})}deleteProfile(e){const t={...this.config.profiles||{}};if(!t[e])return;const i=Object.keys(t).filter(t=>t!==e);if(0===i.length)throw new Error("At least one profile must remain");delete t[e];const o=this.getActiveProfileName()===e?i[0]:this.getActiveProfileName();this.saveConfig({...this.config,profiles:t,active_profile:o})}getApiKey(){return this.config.profiles?.[this.getActiveProfileName()]?.api_key}setApiKey(e){this.updateProfile(this.getActiveProfileName(),{api_key:e})}revokeApiKey(){const e=this.config.profiles?.[this.getActiveProfileName()]||{},{api_key:t,...i}=e,o={...this.config.profiles||{},[this.getActiveProfileName()]:i};try{d.deleteApiKey(this.getActiveProfileName()),d.deleteToolApiKeys(this.getActiveProfileName())}catch(e){m.logError("ConfigManager.revokeApiKey",e);try{d.deleteAll()}catch(e){m.logError("ConfigManager.revokeApiKey.deleteAll",e)}}this.saveConfig({...this.config,profiles:o})}getApiKeyFingerprint(){try{return d.fingerprint(this.getActiveProfileName())}catch{return""}}getApiKeyForTool(e){try{const t=d.getToolApiKey(this.getActiveProfileName(),e);if(t)return t}catch{}return this.getApiKey()||void 0}setToolApiKey(e,t){d.setToolApiKey(this.getActiveProfileName(),e,t)}clearToolApiKey(e){d.deleteToolApiKey(this.getActiveProfileName(),e)}listToolApiKeys(){try{return d.listToolsWithKeys(this.getActiveProfileName())}catch{return[]}}getToolApiKeyFingerprint(e){try{return d.toolFingerprint(this.getActiveProfileName(),e)}catch{return""}}getModels(){const e=this.config.profiles?.[this.getActiveProfileName()]?.models;return e?this.normalizeModels(e):DEFAULT_MODELS}setModels(e){this.updateProfile(this.getActiveProfileName(),{models:this.normalizeModels(e)})}updateModels(e){this.setModels(this.normalizeModels({...this.getModels(),...e}))}getModelsForTool(e){const t=this.getModels(),i=this.config.profiles?.[this.getActiveProfileName()]?.tool_models?.[e];return i?this.normalizeModels({...t,...i}):t}setToolModel(e,t){const i=this.getActiveProfileName(),o=this.config.profiles?.[i]||{},r={...o.tool_models||{}};t&&0!==Object.keys(t).length?r[e]=t:delete r[e];const s={...o};Object.keys(r).length>0?s.tool_models=r:delete s.tool_models;const n={...this.config.profiles||{},[i]:s};this.saveConfig({...this.config,profiles:n})}getCustomPresets(){return{...this.config.presets||{}}}saveCustomPreset(e,t){const i={...this.config.presets||{},[e]:{models:this.normalizeModels(t),updated_at:(new Date).toISOString()}};this.saveConfig({...this.config,presets:i})}deleteCustomPreset(e){const t={...this.config.presets||{}};t[e]&&(delete t[e],this.saveConfig({...this.config,presets:t}))}listBackups(){const t=this.getBackupDir();return e(t)?n(t).filter(e=>e.startsWith("config-")&&e.endsWith(".yaml")).map(e=>{const i=f(t,e);return{name:e,path:i,mtimeMs:c(i).mtimeMs}}).sort((e,t)=>t.mtimeMs-e.mtimeMs):[]}createBackup(r){this.ensureConfigDir();const s=this.getBackupDir();e(s)||t(s,{recursive:!0});const n=(new Date).toISOString().replace(/[:.]/g,"-"),a=this.sanitizeBackupLabel(r),c=f(s,a?`config-${n}-${a}.yaml`:`config-${n}.yaml`),l=e(this.configPath)?i(this.configPath,"utf-8"):p.dump(this.getConfig());return o(c,l,"utf-8"),this.snapshotSecrets(c),this.rotateBackups(s,10,30),c}restoreBackup(t){if(!t||"."===t||".."===t||/[/\\]|\.\./.test(t))throw new Error(`Invalid backup name: ${t}`);const o=this.getBackupDir(),r=f(o,t);if(!e(r))throw new Error(`Backup not found: ${t}`);const s=i(r,"utf-8"),n=p.load(s),a=this.getSecretsBackupPath(r),c=e(a),l=this.hasInlineSecrets(n);if(!c&&!l)throw new Error(y.t("config.backup_companion_missing",{path:a}));c&&this.restoreSecretsSnapshot(r);const g=this.migrateOldConfig(n||this.createDefaultConfig()),h=c?this.hydrateSecretsFromStore(g):g;this.saveConfig(h)}getBaseUrl(){return this.runtimeBaseUrl||this.config.profiles?.[this.getActiveProfileName()]?.base_url||DEFAULT_BASE_URL}setBaseUrl(e,t=!1){this.runtimeBaseUrl=e,t&&this.updateProfile(this.getActiveProfileName(),{base_url:e})}resetBaseUrl(){this.runtimeBaseUrl=void 0;const e=this.config.profiles?.[this.getActiveProfileName()]||{},{base_url:t,...i}=e,o={...this.config.profiles||{},[this.getActiveProfileName()]:i};this.saveConfig({...this.config,profiles:o})}}export const configManager=ConfigManager.getInstance();
|
|
1
|
+
import{existsSync as e,mkdirSync as t,readFileSync as i,writeFileSync as o,renameSync as s,unlinkSync as r,readdirSync as n,rmdirSync as a,statSync as c,chmodSync as l}from"fs";import{join as f,dirname as g}from"path";import{homedir as h}from"os";import{createHash as p}from"crypto";import*as m from"js-yaml";import{logger as u}from"../utils/logger.js";import{getDefaultModels as d}from"./model-registry.js";import{readLegacySecretsFile as y}from"./secret-store.js";export const DEFAULT_BASE_URL="https://www.vibeapi.cn";export const DEFAULT_MODELS=d();export const DEFAULT_PROFILE_NAME="default";const _="plaintext";export class ConfigManager{static instance;configDir;configPath;config;runtimeBaseUrl;constructor(){this.configDir=this.resolveConfigDir(),this.migrateLegacyConfigDir(),this.configPath=f(this.configDir,"config.yaml"),this.config=this.loadConfig()}migrateLegacyConfigDir(){try{const t=f(g(this.configDir),".chelper");if(t===this.configDir||!e(t))return;if(["config.yaml","secrets.enc"].some(t=>e(f(this.configDir,t))))return;if(e(this.configDir)){for(const i of n(t)){const o=f(this.configDir,i);e(o)||s(f(t,i),o)}0===n(t).length&&a(t)}else s(t,this.configDir);u.info(`Migrated config dir: ${t} -> ${this.configDir}`)}catch(e){u.warn("Failed to migrate legacy .chelper config dir:",e)}}resolveConfigDir(){const e=process.env.VIBECLI_CONFIG_DIR;if(e&&e.trim())return e.trim();const t=process.env.VIBECLI_TEST_HOME;return t&&t.trim()?f(t.trim(),".vibecli"):f(h(),".vibecli")}createDefaultConfig(){return this.syncLegacyFields({lang:"en_US",active_profile:"default",profiles:{[DEFAULT_PROFILE_NAME]:{}},presets:{}})}normalizeModels(e){const t={haiku:e?.haiku?.trim()||DEFAULT_MODELS.haiku,sonnet:e?.sonnet?.trim()||DEFAULT_MODELS.sonnet,opus:e?.opus?.trim()||DEFAULT_MODELS.opus,reasoning:e?.reasoning?.trim()||DEFAULT_MODELS.reasoning};if(e&&"object"==typeof e)for(const[i,o]of Object.entries(e))i in t||"string"==typeof o&&o.trim()&&(t[i]=o.trim());return t}normalizeToolModels(e){if(!e||"object"!=typeof e)return{};const t=Object.entries(e).flatMap(([e,t])=>{if(!e||"string"!=typeof e||!t||"object"!=typeof t)return[];const i={};for(const[e,o]of Object.entries(t))"string"==typeof o&&o.trim()&&(i[e]=o.trim());return Object.keys(i).length>0?[[e,i]]:[]});return Object.fromEntries(t)}normalizeStringRecord(e){return!e||"object"!=typeof e||Array.isArray(e)?{}:Object.fromEntries(Object.entries(e).filter(e=>"string"==typeof e[1]&&Boolean(e[1].trim())).map(([e,t])=>[e,t.trim()]))}normalizeProfile(e){if(!e)return{};const t=this.normalizeToolModels(e.tool_models),i=this.normalizeStringRecord(e.tool_api_keys);return{..."string"==typeof e.api_key&&e.api_key?{api_key:e.api_key}:{},...Object.keys(i).length>0?{tool_api_keys:i}:{},..."string"==typeof e.base_url&&e.base_url?{base_url:e.base_url}:{},...e.models?{models:this.normalizeModels(e.models)}:{},...Object.keys(t).length>0?{tool_models:t}:{}}}normalizeProfiles(e){if(!e||"object"!=typeof e)return{};const t=Object.entries(e).flatMap(([e,t])=>e&&"string"==typeof e&&t&&"object"==typeof t?[[e,this.normalizeProfile(t)]]:[]);return Object.fromEntries(t)}normalizePresets(e){if(!e||"object"!=typeof e)return{};const t=Object.entries(e).flatMap(([e,t])=>{if(!e||"string"!=typeof e||!t||"object"!=typeof t)return[];const i=t;return i.models?[[e,{models:this.normalizeModels(i.models),updated_at:i.updated_at||new Date(0).toISOString()}]]:[]});return Object.fromEntries(t)}getResolvedActiveProfile(e){const t=e.active_profile||"default";return e.profiles?.[t]||{}}syncLegacyFields(e){const t=this.normalizeProfiles(e.profiles),i=e.active_profile?.trim()||Object.keys(t)[0]||"default",o=t[i]?t:{...t,[i]:{}},s=this.getResolvedActiveProfile({...e,profiles:o,active_profile:i});return{...e,lang:e.lang||"en_US",active_profile:i,profiles:o,presets:this.normalizePresets(e.presets),api_key:s.api_key,base_url:s.base_url,models:s.models?this.normalizeModels(s.models):DEFAULT_MODELS}}sanitizeBackupLabel(e){return(e||"").trim().replace(/[^a-zA-Z0-9._-]+/g,"-").replace(/^-+|-+$/g,"").slice(0,40)}getBackupDir(){return f(this.configDir,"backups")}getLegacySecretsPath(){return f(this.configDir,"secrets.enc")}getSecretsBackupPath(e){return e.replace(/\.yaml$/,".secrets.enc")}static getInstance(){return ConfigManager.instance||(ConfigManager.instance=new ConfigManager),ConfigManager.instance}ensureConfigDir(){e(this.configDir)||t(this.configDir,{recursive:!0})}loadConfig(){try{if(e(this.configPath)){const t=i(this.configPath,"utf-8"),o=m.load(t);let s=this.migrateOldConfig(o||{lang:"en_US"}),n=!1;const a=this.getLegacySecretsPath();if(e(a)&&o?.credential_store!==_)try{s=this.mergeLegacySecrets(s,y(a)),n=!0}catch(e){u.warn("Legacy secrets.enc is unreadable on this host; it was kept for recovery and will not block new credentials."),u.logError("ConfigManager.migrateLegacySecrets",e)}if((this.needsMigration(o)||n)&&(this.backupConfig(),this.atomicWrite(this.configPath,m.dump(this.prepareForPersistence(s))),n))try{r(a)}catch(e){u.logError("ConfigManager.removeLegacySecrets",e)}try{l(this.configPath,384)}catch{}return s}const t=this.getLegacySecretsPath();if(e(t))try{const e=this.mergeLegacySecrets(this.createDefaultConfig(),y(t));this.ensureConfigDir(),this.atomicWrite(this.configPath,m.dump(this.prepareForPersistence(e)));try{r(t)}catch(e){u.logError("ConfigManager.removeLegacySecrets",e)}return e}catch(e){u.warn("Legacy secrets.enc is unreadable on this host; it was kept for recovery and will not block new credentials."),u.logError("ConfigManager.migrateLegacySecretsWithoutConfig",e)}}catch(e){u.warn("Failed to load config, using defaults:",e),u.logError("ConfigManager.loadConfig",e)}return this.createDefaultConfig()}needsMigration(e){return!(!e||"object"!=typeof e)&&("plan"in e||!("profiles"in e)||!("active_profile"in e)||!("presets"in e))}migrateOldConfig(e){if(!e||"object"!=typeof e)return this.createDefaultConfig();const t=e,{plan:i,...o}=t,s=this.normalizeProfiles(o.profiles),r=this.normalizeProfile({api_key:"string"==typeof o.api_key?o.api_key:void 0,base_url:"string"==typeof o.base_url?o.base_url:void 0,models:o.models}),n=Object.keys(s).length>0?s:{[DEFAULT_PROFILE_NAME]:r},a="string"==typeof o.active_profile&&o.active_profile.trim()?o.active_profile.trim():Object.keys(n)[0]||"default";return this.syncLegacyFields({lang:"string"==typeof o.lang&&o.lang?o.lang:"en_US",...o.credential_store===_?{credential_store:_}:{},active_profile:a,profiles:n,presets:this.normalizePresets(o.presets)})}atomicWrite(t,i){const n=`${t}.tmp`;try{o(n,i,{encoding:"utf-8",mode:384}),s(n,t);try{l(t,384)}catch{}}catch(t){if(e(n))try{r(n)}catch{}throw t}}backupConfig(){if(!e(this.configPath))return;const s=this.getBackupDir();e(s)||t(s,{recursive:!0});const r=(new Date).toISOString().replace(/[:.]/g,"-"),n=f(s,`config-${r}.yaml`);try{const e=i(this.configPath,"utf-8");o(n,e,{encoding:"utf-8",mode:384}),this.rotateBackups(s,10,30)}catch(e){u.logError("ConfigManager.backupConfig",e)}}rotateBackups(t,i,o){try{const s=Date.now()-24*o*60*60*1e3,a=n(t).filter(e=>e.startsWith("config-")&&e.endsWith(".yaml")).map(e=>({name:e,path:f(t,e),mtime:c(f(t,e)).mtime})).sort((e,t)=>t.mtime.getTime()-e.mtime.getTime()),l=new Set;a.slice(i).forEach(e=>l.add(e.path)),a.forEach(e=>{e.mtime.getTime()<s&&l.add(e.path)});for(const t of l){let i=!1;try{r(t),i=!0}catch(e){u.logError("ConfigManager.rotateBackups",e)}if(i){const i=this.getSecretsBackupPath(t);if(e(i))try{r(i)}catch(e){u.logError("ConfigManager.rotateBackups.secrets",e)}}}}catch(e){u.logError("ConfigManager.rotateBackups",e)}}saveConfig(e){try{this.ensureConfigDir(),this.backupConfig();const t=this.syncLegacyFields(this.migrateOldConfig(e||this.config)),i=this.prepareForPersistence(t),o=m.dump(i);this.atomicWrite(this.configPath,o),this.config=t}catch(e){throw u.error("Failed to save config:",e),u.logError("ConfigManager.saveConfig",e),e}}prepareForPersistence(e){const t={...e,credential_store:_};return delete t.api_key,delete t.base_url,delete t.models,t}mergeLegacySecrets(e,t){const i={...e.profiles||{}},o=new Set([...Object.keys(t.api_keys||{}),...Object.keys(t.tool_api_keys||{})]);for(const e of o){const o=i[e]||{},s=o.api_key||t.api_keys?.[e],r={...t.tool_api_keys?.[e]||{},...o.tool_api_keys||{}};i[e]={...o,...s?{api_key:s}:{},...Object.keys(r).length>0?{tool_api_keys:r}:{}}}return this.syncLegacyFields({...e,profiles:i})}getConfig(){return this.syncLegacyFields({...this.config})}updateConfig(e){this.saveConfig({...this.config,...e})}isFirstRun(){return!e(this.configPath)}getLang(){return this.config.lang||"en_US"}setLang(e){this.updateConfig({lang:e})}getActiveProfileName(){return this.config.active_profile||"default"}listProfiles(){return Object.keys(this.config.profiles||{}).sort()}getProfile(e=this.getActiveProfileName()){const t=this.config.profiles?.[e]||{};return{...t.api_key?{api_key:t.api_key}:{},...t.tool_api_keys&&Object.keys(t.tool_api_keys).length>0?{tool_api_keys:this.normalizeStringRecord(t.tool_api_keys)}:{},...t.base_url?{base_url:t.base_url}:{},models:t.models?this.normalizeModels(t.models):DEFAULT_MODELS,...t.tool_models&&Object.keys(t.tool_models).length>0?{tool_models:this.normalizeToolModels(t.tool_models)}:{}}}createProfile(e,t=this.getActiveProfileName()){const i=this.getProfile(t),o={...this.config.profiles||{},[e]:{...i.api_key?{api_key:i.api_key}:{},...i.base_url?{base_url:i.base_url}:{},models:this.normalizeModels(i.models)}};this.saveConfig({...this.config,profiles:o})}setActiveProfile(e){if(!this.config.profiles?.[e])throw new Error(`Profile not found: ${e}`);this.saveConfig({...this.config,active_profile:e})}updateProfile(e,t){const i=this.config.profiles?.[e]||{},o=t.models?this.normalizeModels({...i.models,...t.models}):i.models?this.normalizeModels(i.models):void 0,s={...i,...void 0!==t.api_key?{api_key:t.api_key}:{},...void 0!==t.base_url?{base_url:t.base_url}:{},...o?{models:o}:{}},r={...this.config.profiles||{},[e]:s};this.saveConfig({...this.config,profiles:r})}deleteProfile(e){const t={...this.config.profiles||{}};if(!t[e])return;const i=Object.keys(t).filter(t=>t!==e);if(0===i.length)throw new Error("At least one profile must remain");delete t[e];const o=this.getActiveProfileName()===e?i[0]:this.getActiveProfileName();this.saveConfig({...this.config,profiles:t,active_profile:o})}getApiKey(){return this.config.profiles?.[this.getActiveProfileName()]?.api_key}setApiKey(e){this.updateProfile(this.getActiveProfileName(),{api_key:e})}revokeApiKey(){const e=this.config.profiles?.[this.getActiveProfileName()]||{},{api_key:t,tool_api_keys:i,...o}=e,s={...this.config.profiles||{},[this.getActiveProfileName()]:o};this.saveConfig({...this.config,profiles:s})}getApiKeyFingerprint(){const e=this.getApiKey();return e?p("sha256").update(e).digest("hex").slice(0,12):""}getApiKeyForTool(e){const t=this.config.profiles?.[this.getActiveProfileName()];return t?.tool_api_keys?.[e]||t?.api_key||void 0}setToolApiKey(e,t){const i=this.getActiveProfileName(),o=this.config.profiles?.[i]||{},s={...this.config.profiles||{},[i]:{...o,tool_api_keys:{...o.tool_api_keys||{},[e]:t}}};this.saveConfig({...this.config,profiles:s})}clearToolApiKey(e){const t=this.getActiveProfileName(),i=this.config.profiles?.[t]||{},{[e]:o,...s}=i.tool_api_keys||{},r={...i};Object.keys(s).length>0?r.tool_api_keys=s:delete r.tool_api_keys,this.saveConfig({...this.config,profiles:{...this.config.profiles||{},[t]:r}})}listToolApiKeys(){return Object.keys(this.config.profiles?.[this.getActiveProfileName()]?.tool_api_keys||{}).sort()}getToolApiKeyFingerprint(e){const t=this.config.profiles?.[this.getActiveProfileName()]?.tool_api_keys?.[e];return t?p("sha256").update(t).digest("hex").slice(0,12):""}getModels(){const e=this.config.profiles?.[this.getActiveProfileName()]?.models;return e?this.normalizeModels(e):DEFAULT_MODELS}setModels(e){this.updateProfile(this.getActiveProfileName(),{models:this.normalizeModels(e)})}updateModels(e){this.setModels(this.normalizeModels({...this.getModels(),...e}))}getModelsForTool(e){const t=this.getModels(),i=this.config.profiles?.[this.getActiveProfileName()]?.tool_models?.[e];return i?this.normalizeModels({...t,...i}):t}setToolModel(e,t){const i=this.getActiveProfileName(),o=this.config.profiles?.[i]||{},s={...o.tool_models||{}};t&&0!==Object.keys(t).length?s[e]=t:delete s[e];const r={...o};Object.keys(s).length>0?r.tool_models=s:delete r.tool_models;const n={...this.config.profiles||{},[i]:r};this.saveConfig({...this.config,profiles:n})}getCustomPresets(){return{...this.config.presets||{}}}saveCustomPreset(e,t){const i={...this.config.presets||{},[e]:{models:this.normalizeModels(t),updated_at:(new Date).toISOString()}};this.saveConfig({...this.config,presets:i})}deleteCustomPreset(e){const t={...this.config.presets||{}};t[e]&&(delete t[e],this.saveConfig({...this.config,presets:t}))}listBackups(){const t=this.getBackupDir();return e(t)?n(t).filter(e=>e.startsWith("config-")&&e.endsWith(".yaml")).map(e=>{const i=f(t,e);return{name:e,path:i,mtimeMs:c(i).mtimeMs}}).sort((e,t)=>t.mtimeMs-e.mtimeMs):[]}createBackup(s){this.ensureConfigDir();const r=this.getBackupDir();e(r)||t(r,{recursive:!0});const n=(new Date).toISOString().replace(/[:.]/g,"-"),a=this.sanitizeBackupLabel(s),c=f(r,a?`config-${n}-${a}.yaml`:`config-${n}.yaml`),l=e(this.configPath)?i(this.configPath,"utf-8"):m.dump(this.prepareForPersistence(this.getConfig()));return o(c,l,{encoding:"utf-8",mode:384}),this.rotateBackups(r,10,30),c}restoreBackup(t){if(!t||"."===t||".."===t||/[/\\]|\.\./.test(t))throw new Error(`Invalid backup name: ${t}`);const o=this.getBackupDir(),s=f(o,t);if(!e(s))throw new Error(`Backup not found: ${t}`);const r=i(s,"utf-8"),n=m.load(r),a=this.getSecretsBackupPath(s);let c=this.migrateOldConfig(n||this.createDefaultConfig());if(n?.credential_store!==_&&e(a))try{c=this.mergeLegacySecrets(c,y(a))}catch(e){throw new Error(`Legacy backup credentials could not be decrypted: ${a}`,{cause:e})}this.saveConfig(c)}getBaseUrl(){return this.runtimeBaseUrl||this.config.profiles?.[this.getActiveProfileName()]?.base_url||DEFAULT_BASE_URL}setBaseUrl(e,t=!1){this.runtimeBaseUrl=e,t&&this.updateProfile(this.getActiveProfileName(),{base_url:e})}resetBaseUrl(){this.runtimeBaseUrl=void 0;const e=this.config.profiles?.[this.getActiveProfileName()]||{},{base_url:t,...i}=e,o={...this.config.profiles||{},[this.getActiveProfileName()]:i};this.saveConfig({...this.config,profiles:o})}}export const configManager=ConfigManager.getInstance();
|
|
@@ -2,36 +2,13 @@ export declare class SecretStoreDecryptError extends Error {
|
|
|
2
2
|
readonly cause?: unknown | undefined;
|
|
3
3
|
constructor(message: string, cause?: unknown | undefined);
|
|
4
4
|
}
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
private lastDecryptError;
|
|
10
|
-
private constructor();
|
|
11
|
-
static getInstance(): SecretStore;
|
|
12
|
-
private ensureDir;
|
|
13
|
-
private writeAtomic;
|
|
14
|
-
private readEnvelope;
|
|
15
|
-
private decrypt;
|
|
16
|
-
private encrypt;
|
|
17
|
-
private loadRecord;
|
|
18
|
-
private safeLoadRecord;
|
|
19
|
-
private persistRecord;
|
|
20
|
-
isAvailable(): boolean;
|
|
21
|
-
getLastDecryptError(): SecretStoreDecryptError | null;
|
|
22
|
-
fingerprint(profile: string): string;
|
|
23
|
-
getApiKey(profile: string): string | undefined;
|
|
24
|
-
setApiKey(profile: string, apiKey: string): void;
|
|
25
|
-
deleteApiKey(profile: string): void;
|
|
26
|
-
listProfilesWithKeys(): string[];
|
|
27
|
-
/** 读取某工具的专属 Key(没有则 undefined,调用方回退 profile 默认 Key)。 */
|
|
28
|
-
getToolApiKey(profile: string, tool: string): string | undefined;
|
|
29
|
-
setToolApiKey(profile: string, tool: string, apiKey: string): void;
|
|
30
|
-
deleteToolApiKey(profile: string, tool: string): void;
|
|
31
|
-
/** 撤销 profile 时连同其全部工具专属 Key 一起清掉。 */
|
|
32
|
-
deleteToolApiKeys(profile: string): void;
|
|
33
|
-
listToolsWithKeys(profile: string): string[];
|
|
34
|
-
toolFingerprint(profile: string, tool: string): string;
|
|
35
|
-
deleteAll(): void;
|
|
5
|
+
/** Read-only shape used to migrate credential files written by vibecli <= 0.0.30. */
|
|
6
|
+
export interface LegacySecretRecord {
|
|
7
|
+
api_keys?: Record<string, string>;
|
|
8
|
+
tool_api_keys?: Record<string, Record<string, string>>;
|
|
36
9
|
}
|
|
37
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Decrypt a legacy secrets.enc file for one-time migration. New credentials are
|
|
12
|
+
* never written through this module; config.yaml is the sole vibecli store.
|
|
13
|
+
*/
|
|
14
|
+
export declare function readLegacySecretsFile(path: string): LegacySecretRecord;
|
package/dist/lib/secret-store.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{existsSync as e,
|
|
1
|
+
import{existsSync as e,readFileSync as t}from"fs";import{hostname as r,userInfo as o}from"os";import{createDecipheriv as s,scryptSync as c}from"crypto";export class SecretStoreDecryptError extends Error{cause;constructor(e,t){super(e),this.cause=t,this.name="SecretStoreDecryptError"}}function n(e){return!e||"object"!=typeof e||Array.isArray(e)?{}:Object.fromEntries(Object.entries(e).filter(e=>"string"==typeof e[1]&&Boolean(e[1].trim())).map(([e,t])=>[e,t.trim()]))}export function readLegacySecretsFile(i){if(!e(i))return{};let a;try{const e=JSON.parse(t(i,"utf-8"));if(!function(e){if(!e||"object"!=typeof e)return!1;const t=e;return(2===t.version||1===t.version)&&"string"==typeof t.iv&&"string"==typeof t.salt&&"string"==typeof t.auth_tag&&"string"==typeof t.cipher_text}(e))throw new Error("invalid secret envelope");a=e}catch(e){throw new SecretStoreDecryptError(`Failed to read legacy secret envelope: ${i}`,e)}try{const e=Buffer.from(a.salt,"base64"),t=Buffer.from(a.iv,"base64"),i=Buffer.from(a.auth_tag,"base64"),f=Buffer.from(a.cipher_text,"base64"),p=1===a.version?16384:32768,y=s("aes-256-gcm",function(e,t){const s=`${o().username}:${r()}:vibecli-secret-store`;return c(s,e,32,{N:t,maxmem:67108864})}(e,p),t);y.setAuthTag(i);const u=Buffer.concat([y.update(f),y.final()]);return function(e){if(!e||"object"!=typeof e||Array.isArray(e))return{};const t=e,r=n(t.api_keys),o=t.tool_api_keys&&"object"==typeof t.tool_api_keys?t.tool_api_keys:{},s=Object.fromEntries(Object.entries(o).map(([e,t])=>[e,n(t)]).filter(([,e])=>Object.keys(e).length>0));return{...Object.keys(r).length>0?{api_keys:r}:{},...Object.keys(s).length>0?{tool_api_keys:s}:{}}}(JSON.parse(u.toString("utf-8")))}catch(e){throw new SecretStoreDecryptError(`Failed to decrypt legacy secret envelope: ${i} (host or user identity may have changed)`,e)}}
|
|
@@ -28,10 +28,9 @@ export interface BackupEntry {
|
|
|
28
28
|
seq: number;
|
|
29
29
|
}
|
|
30
30
|
/**
|
|
31
|
-
* List a file's snapshots, newest first.
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
* Empty if the dir/file has none.
|
|
31
|
+
* List a file's snapshots, newest first. The filename timestamp is authoritative:
|
|
32
|
+
* copy/restore operations can make filesystem mtime tie or move backwards. The
|
|
33
|
+
* numeric collision suffix orders snapshots created within the same millisecond.
|
|
35
34
|
*/
|
|
36
35
|
export declare function listBackups(filePath: string): BackupEntry[];
|
|
37
36
|
export interface RestoreResult {
|
package/dist/lib/tools/backup.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{existsSync as t,copyFileSync as r,readdirSync as
|
|
1
|
+
import{existsSync as t,copyFileSync as r,readdirSync as e,statSync as o,unlinkSync as s,writeFileSync as c,renameSync as n,mkdirSync as a}from"fs";import{dirname as i,basename as u,join as m}from"path";import{logger as p}from"../../utils/logger.js";export function atomicWriteFile(r,e){const o=i(r);t(o)||a(o,{recursive:!0});const u=`${r}.tmp-${process.pid}-${Date.now()}`;try{c(u,e,"utf-8"),n(u,r)}catch(r){try{t(u)&&s(u)}catch{}throw r}}export const MAX_TOOL_BACKUPS=10;const f=".bak-";function h(r){const e=`${r}${f}${(new Date).toISOString().replace(/[:.]/g,"-")}`;let o=e,s=1;for(;t(o);)o=`${e}-${s++}`;return o}export function backupBeforeWrite(e,o=10){try{if(!t(e))return;r(e,h(e)),d(e,o)}catch(t){p.logError("backupBeforeWrite",t)}}function l(t){const r=t.match(/Z-(\d+)$/);return r?Number(r[1]):0}function b(t){const r=t.match(/(\d{4})-(\d{2})-(\d{2})T(\d{2})-(\d{2})-(\d{2})-(\d{3})Z(?:-\d+)?$/);if(!r)return 0;const[,e,o,s,c,n,a,i]=r;return Date.UTC(Number(e),Number(o)-1,Number(s),Number(c),Number(n),Number(a),Number(i))}export function listBackups(t){const r=i(t),s=u(t)+f;try{return e(r).filter(t=>t.startsWith(s)).map(t=>{const e=m(r,t);return{path:e,name:t,mtimeMs:o(e).mtimeMs,seq:l(t),timestampMs:b(t)}}).sort((t,r)=>r.timestampMs-t.timestampMs||r.seq-t.seq||r.mtimeMs-t.mtimeMs)}catch{return[]}}export function restoreBackup(e,o){const s=o?listBackups(e).find(t=>t.path===o||t.name===o)?.path:listBackups(e)[0]?.path;if(!s||!t(s))return{restored:!1,reason:"no_backup"};let c;if(t(e)){const t=h(e);try{r(e,t),c=u(t)}catch(t){p.logError("restoreBackup.snapshot",t)}}return r(s,e),d(e,10),{restored:!0,from:u(s),snapshot:c}}function d(t,r){for(const e of listBackups(t).slice(Math.max(0,r)))try{s(e.path)}catch(t){p.logError("backupBeforeWrite.rotate",t)}}
|
package/dist/lib/tools/codex.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{existsSync as r,readFileSync as e}from"fs";import{join as t}from"path";import*as o from"@iarna/toml";import{logger as n}from"../../utils/logger.js";import{backupBeforeWrite as i,atomicWriteFile as s}from"./backup.js";import{pickModel as a,toolHome as c,withV1 as l}from"./types.js";import{getToolDefaultModel as d}from"../model-registry.js";const m=()=>t(c(),".codex"),
|
|
1
|
+
import{existsSync as r,readFileSync as e}from"fs";import{join as t}from"path";import*as o from"@iarna/toml";import{logger as n}from"../../utils/logger.js";import{backupBeforeWrite as i,atomicWriteFile as s}from"./backup.js";import{pickModel as a,toolHome as c,withV1 as l}from"./types.js";import{getToolDefaultModel as d}from"../model-registry.js";const m=()=>t(c(),".codex"),u=()=>t(m(),"config.toml"),f=()=>t(m(),"auth.json"),p="OPENAI_API_KEY",g="custom";function y(r){return!!r&&"object"==typeof r&&!Array.isArray(r)}function _(r,e){return y(r[e])||(r[e]={}),r[e]}function h(){if(!r(u()))return{};const t=e(u(),"utf-8");if(!t.trim())return{};try{const r=o.parse(t);if(!y(r))throw new Error("config.toml root must be a TOML table");return r}catch(r){throw new Error(`Existing ~/.codex/config.toml cannot be parsed, back it up and fix it first: ${r instanceof Error?r.message:String(r)}`)}}function x(){if(!r(f()))return{};try{const r=JSON.parse(e(f(),"utf-8"));return y(r)?r:{}}catch{return{}}}export const codexAdapter={name:"codex",displayName:"Codex",command:"codex",installCommand:"npm install -g @openai/codex",configPath:u(),loadPrivateConfig(r){const e=d("codex"),t=a(r.models,e),n=function(r){return/(?:^|\/)claude(?:-|$)/i.test(r)}(t)?e:t,c=l(r.baseUrl),m=h();m.model=n,m.model_provider=g,m.model_reasoning_effort="xhigh";const v=_(m,"model_providers"),b=y(v[g])?{...v[g]}:{};delete b.env_key,v[g]={...b,name:"custom",wire_api:"responses",requires_openai_auth:!0,base_url:c};const C=_(m,"profiles"),j=y(C[n])?{...C[n]}:{};C[n]={...j,model_provider:g,model:n},_(_(m,"tui"),"model_availability_nux")[n]=4;const E=_(m,"features");E.goals=!0,E.js_repl=!1,i(u()),s(u(),o.stringify(m)),function(r){const e=r.trim();if(!e)return;const t={...x(),auth_mode:"apikey",[p]:e};i(f()),s(f(),JSON.stringify(t,null,2)+"\n")}(r.apiKey)},unloadPrivateConfig(){if(!r(u()))return;let e;try{e=h()}catch(r){return void n.logError("codexAdapter.unloadPrivateConfig",r)}const t=e.model_providers;y(t)&&(delete t[g],0===Object.keys(t).length&&delete e.model_providers),e.model_provider===g&&delete e.model_provider,i(u()),s(u(),o.stringify(e))},detectCurrentConfig(){const r=x()[p];return{apiKey:"string"==typeof r&&r.trim()?r.trim():null}},getConfig(){try{return h()}catch(r){return n.logError("codexAdapter.getConfig",r),null}},backupPaths:()=>[u(),f()]};
|
|
@@ -60,10 +60,9 @@ export interface ToolAdapter {
|
|
|
60
60
|
*/
|
|
61
61
|
export declare function primaryModel(models: VibecliModels): string;
|
|
62
62
|
/**
|
|
63
|
-
* Pick the model for a
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
* default model name is meaningless to these OpenAI-compatible tools.
|
|
63
|
+
* Pick the model for a single-model tool. Any customized primary is preserved;
|
|
64
|
+
* otherwise the adapter-specific default is used. Protocol compatibility is an
|
|
65
|
+
* adapter concern (Codex, for example, rejects Claude model ids itself).
|
|
67
66
|
*/
|
|
68
67
|
export declare function pickModel(models: VibecliModels, fallback: string): string;
|
|
69
68
|
/**
|
package/dist/locales/en_US.json
CHANGED
|
@@ -240,8 +240,7 @@
|
|
|
240
240
|
"backup_created": "Backup created: {{path}}",
|
|
241
241
|
"backup_restored": "Backup restored: {{name}}",
|
|
242
242
|
"backup_restore_missing_name": "Specify a backup name to restore",
|
|
243
|
-
"
|
|
244
|
-
"profile_delete_confirm": "Delete profile {{name}}? This removes its api_key from the keystore.",
|
|
243
|
+
"profile_delete_confirm": "Delete profile {{name}}? This removes its stored API keys.",
|
|
245
244
|
"profile_delete_dry_run": "Would delete profile {{name}}",
|
|
246
245
|
"profile_delete_aborted": "Profile deletion cancelled",
|
|
247
246
|
"backup_restore_confirm": "Restore backup {{name}}? Current config and api_key will be overwritten.",
|
|
@@ -300,9 +299,6 @@
|
|
|
300
299
|
"non_interactive_required_token": "An API token is required in non-interactive mode",
|
|
301
300
|
"non_interactive_aborted": "Aborted - missing required input"
|
|
302
301
|
},
|
|
303
|
-
"secret_store": {
|
|
304
|
-
"host_changed": "Stored API key cannot be decrypted on this host. The keystore was likely created under a different user/machine. Re-authenticate via 'vibecli auth' to refresh."
|
|
305
|
-
},
|
|
306
302
|
"setup": {
|
|
307
303
|
"usage": "Usage: vibecli setup --key sk-xxx or vibecli setup --claudekey sk-a --codexkey sk-b",
|
|
308
304
|
"validating": "Validating API key for {{label}}...",
|
package/dist/locales/zh_CN.json
CHANGED
|
@@ -240,7 +240,6 @@
|
|
|
240
240
|
"backup_created": "备份已创建: {{path}}",
|
|
241
241
|
"backup_restored": "备份已恢复: {{name}}",
|
|
242
242
|
"backup_restore_missing_name": "请指定要恢复的备份名称",
|
|
243
|
-
"backup_companion_missing": "备份缺少加密密钥伴随文件 ({{path}}),已中止恢复以避免 api_key 错乱",
|
|
244
243
|
"profile_delete_confirm": "确定删除 Profile {{name}}?将同时清除其密钥",
|
|
245
244
|
"profile_delete_dry_run": "将删除 Profile {{name}}",
|
|
246
245
|
"profile_delete_aborted": "已取消删除 Profile",
|
|
@@ -300,9 +299,6 @@
|
|
|
300
299
|
"non_interactive_required_token": "非交互模式下必须提供 API Token",
|
|
301
300
|
"non_interactive_aborted": "已中止 - 缺少必要输入"
|
|
302
301
|
},
|
|
303
|
-
"secret_store": {
|
|
304
|
-
"host_changed": "本机无法解密已保存的 API Key。密钥库可能创建于其它机器或用户。请通过 'vibecli auth' 重新认证以刷新。"
|
|
305
|
-
},
|
|
306
302
|
"setup": {
|
|
307
303
|
"usage": "用法: vibecli setup --key sk-xxx 或 vibecli setup --claudekey sk-a --codexkey sk-b",
|
|
308
304
|
"validating": "正在验证 {{label}} 的 API Key...",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vibeapi/api-helper",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.32",
|
|
4
4
|
"description": "CLI tool for managing AI coding assistants (Claude Code, Codex, OpenClaw, Hermes, AtomCode) with one unified config",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -77,7 +77,7 @@
|
|
|
77
77
|
"vitest": "^3.2.1"
|
|
78
78
|
},
|
|
79
79
|
"scripts": {
|
|
80
|
-
"build": "tsc && node scripts/copy-assets.mjs",
|
|
80
|
+
"build": "pnpm run clean && tsc -p tsconfig.build.json && node scripts/copy-assets.mjs && node scripts/check-package.mjs",
|
|
81
81
|
"build:prod": "pnpm run build && node scripts/obfuscate.mjs",
|
|
82
82
|
"dev": "tsx watch src/cli.ts",
|
|
83
83
|
"start": "node dist/cli.js",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{describe as e,it as o,expect as t,vi as r,afterEach as s}from"vitest";import{validateApiKey as a,fetchModels as n}from"../lib/api-validator.js";e("API Validator",()=>{const l=globalThis.fetch;s(()=>{globalThis.fetch=l,r.restoreAllMocks()}),o("should return valid for successful response",async()=>{globalThis.fetch=r.fn().mockResolvedValue({ok:!0,status:200,json:()=>Promise.resolve({object:"list",data:[]})});const e=await a("valid-key",{retries:0});t(e.valid).toBe(!0)}),o("should return invalid for 401 response",async()=>{globalThis.fetch=r.fn().mockResolvedValue({ok:!1,status:401,statusText:"Unauthorized"});const e=await a("invalid-key",{retries:0});t(e.valid).toBe(!1),t(e.error).toBe("invalid_api_key")}),o("should return network error for fetch failure",async()=>{globalThis.fetch=r.fn().mockRejectedValue(new Error("fetch failed"));const e=await a("any-key",{retries:0});t(e.valid).toBe(!1),t(e.error).toBe("network_error")}),o("should return network error for timeout",async()=>{const e=new Error("The operation was aborted");e.name="AbortError",globalThis.fetch=r.fn().mockRejectedValue(e);const o=await a("any-key",{retries:0});t(o.valid).toBe(!1),t(o.error).toBe("network_error"),t(o.message).toBe("Request timeout")}),o("should handle non-200 non-401 responses",async()=>{globalThis.fetch=r.fn().mockResolvedValue({ok:!1,status:500,statusText:"Internal Server Error"});const e=await a("any-key",{retries:0});t(e.valid).toBe(!1),t(e.error).toBe("unknown_error")}),o("should retry on network error and eventually succeed",async()=>{const e=r.fn().mockRejectedValueOnce(new Error("connect ETIMEDOUT")).mockRejectedValueOnce(new Error("connect ECONNRESET")).mockResolvedValueOnce({ok:!0,status:200,json:()=>Promise.resolve({object:"list"})}),o=await a("k",{retries:2,backoffMs:0,fetchFn:e,sleepFn:()=>Promise.resolve()});t(o.valid).toBe(!0),t(e).toHaveBeenCalledTimes(3)}),o("should NOT retry on invalid_api_key",async()=>{const e=r.fn().mockResolvedValue({ok:!1,status:401,statusText:"Unauthorized"}),o=await a("k",{retries:5,backoffMs:0,fetchFn:e,sleepFn:()=>Promise.resolve()});t(o.error).toBe("invalid_api_key"),t(e).toHaveBeenCalledTimes(1)}),e("fetchModels",()=>{o("returns the model ids from /v1/models",async()=>{const e=r.fn().mockResolvedValue({ok:!0,status:200,json:()=>Promise.resolve({object:"list",data:[{id:"gpt-5.5"},{id:"glm-5.2"},{id:""},{notId:1}]})}),o=await n("k",{fetchFn:e});t(o.ok).toBe(!0),t(o.models).toEqual(["gpt-5.5","glm-5.2"])}),o("returns ok=false on non-2xx",async()=>{const e=r.fn().mockResolvedValue({ok:!1,status:401}),o=await n("bad",{fetchFn:e});t(o.ok).toBe(!1),t(o.models).toEqual([])}),o("returns ok=false on network error",async()=>{const e=r.fn().mockRejectedValue(new Error("boom")),o=await n("k",{fetchFn:e});t(o.ok).toBe(!1)})})});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"api-validator.test.js","sourceRoot":"","sources":["../../src/__tests__/api-validator.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EA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AAC,IAAI,CAAC,CAAC;YAC1B,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC;QACvD,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,6BAA6B,EAAE,KAAK,IAAI,EAAE;YACzC,MAAM,SAAS,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC;YACxE,MAAM,GAAG,GAAG,MAAM,WAAW,CAAC,KAAK,EAAE,EAAE,OAAO,EAAE,SAAoC,EAAE,CAAC,CAAC;YACxF,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAC3B,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QACnC,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,mCAAmC,EAAE,KAAK,IAAI,EAAE;YAC/C,MAAM,SAAS,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;YAC/D,MAAM,GAAG,GAAG,MAAM,WAAW,CAAC,GAAG,EAAE,EAAE,OAAO,EAAE,SAAoC,EAAE,CAAC,CAAC;YACtF,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC/B,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{describe as e,it as t,expect as n,beforeEach as o,afterEach as s,vi as i}from"vitest";import{mkdirSync as a,rmSync as r,existsSync as O,readFileSync as g}from"fs";import{join as l}from"path";import{tmpdir as d}from"os";const v=l(d(),`vibecli-cc-${Date.now()}-${Math.random().toString(36).slice(2)}`);i.mock("os",async()=>({...await i.importActual("os"),homedir:()=>v})),e("ClaudeCodeManager",()=>{let e;o(async()=>{a(v,{recursive:!0}),({claudeCodeManager:e}=await import("../lib/claude-code-manager.js"))}),s(()=>{try{r(v,{recursive:!0,force:!0})}catch{}}),t("returns empty settings when file is missing",()=>{const t=e.getSettings();n(t).toEqual({})}),t("persists and reads settings via atomic write",()=>{e.saveSettings({env:{ANTHROPIC_AUTH_TOKEN:"tk",FOO:"bar"}});const t=l(v,".claude","settings.json");n(O(t)).toBe(!0);const o=JSON.parse(g(t,"utf-8"));n(o.env.ANTHROPIC_AUTH_TOKEN).toBe("tk");const s=e.getSettings();n(s.env?.ANTHROPIC_AUTH_TOKEN).toBe("tk")}),t("returns empty MCP config when file is missing",()=>{n(e.getMCPConfig()).toEqual({})}),t("marks onboarding completed and stores api credentials",()=>{e.loadPrivateConfig("sk-test",{haiku:"h",sonnet:"s",opus:"o",reasoning:"r"});const t=e.getSettings();n(t.env?.ANTHROPIC_AUTH_TOKEN).toBe("sk-test"),n(t.env?.ANTHROPIC_DEFAULT_HAIKU_MODEL).toBe("h"),n(t.env?.ANTHROPIC_DEFAULT_SONNET_MODEL).toBe("s"),n(t.env?.ANTHROPIC_DEFAULT_OPUS_MODEL).toBe("o"),n(t.env?.ANTHROPIC_MODEL).toBe("o");const o=e.getMCPConfig();n(o.hasCompletedOnboarding).toBe(!0)}),t("always writes the model env vars, even for default models",async()=>{const{DEFAULT_MODELS:t}=await import("../lib/config.js");e.loadPrivateConfig("sk-test",{...t});const o=e.getSettings();n(o.env?.ANTHROPIC_AUTH_TOKEN).toBe("sk-test"),n(o.env?.ANTHROPIC_BASE_URL).toBeDefined(),n(o.env?.ANTHROPIC_DEFAULT_HAIKU_MODEL).toBe(t.haiku),n(o.env?.ANTHROPIC_DEFAULT_SONNET_MODEL).toBe(t.sonnet),n(o.env?.ANTHROPIC_DEFAULT_OPUS_MODEL).toBe(t.opus),n(o.env?.ANTHROPIC_MODEL).toBe(t.opus),n(t.sonnet).toBe("claude-sonnet-5[1m]"),n(t.opus).toContain("[1m]")}),t("refreshes model env vars on reload (no stale values)",async()=>{const{DEFAULT_MODELS:t}=await import("../lib/config.js");e.loadPrivateConfig("sk-test",{...t,opus:"glm-5",sonnet:"glm-5",haiku:"glm-5"}),n(e.getSettings().env?.ANTHROPIC_MODEL).toBe("glm-5"),e.loadPrivateConfig("sk-test",{...t}),n(e.getSettings().env?.ANTHROPIC_MODEL).toBe(t.opus),n(e.getSettings().env?.ANTHROPIC_DEFAULT_SONNET_MODEL).toBe(t.sonnet)}),t("applies the top-level model from settings-template.json",()=>{e.loadPrivateConfig("sk-test",{haiku:"h",sonnet:"s",opus:"o",reasoning:"r"}),n(e.getSettings().model).toBe("opus[1m]")}),t("removes private env vars on unload but preserves user vars",()=>{e.saveSettings({env:{ANTHROPIC_AUTH_TOKEN:"tk",ANTHROPIC_BASE_URL:"https://x",CUSTOM_FLAG:"keep-me"}}),e.unloadPrivateConfig();const t=e.getSettings();n(t.env?.ANTHROPIC_AUTH_TOKEN).toBeUndefined(),n(t.env?.ANTHROPIC_BASE_URL).toBeUndefined(),n(t.env?.CUSTOM_FLAG).toBe("keep-me")}),t("drops env field entirely when no vars remain after unload",()=>{e.saveSettings({env:{ANTHROPIC_AUTH_TOKEN:"tk"}}),e.unloadPrivateConfig();const t=e.getSettings();n(t.env).toBeUndefined()}),t("detectCurrentConfig returns null when no token configured",()=>{const t=e.detectCurrentConfig();n(t.apiKey).toBeNull()}),t("detectCurrentConfig returns the configured token",()=>{e.saveSettings({env:{ANTHROPIC_AUTH_TOKEN:"sk-detect"}}),n(e.detectCurrentConfig().apiKey).toBe("sk-detect")}),t("experimental feature: set / get / remove are idempotent",()=>{e.setExperimentalFeature("FOO_FLAG","1"),n(e.getExperimentalFeature("FOO_FLAG")).toBe("1"),e.setExperimentalFeature("FOO_FLAG","1"),n(e.getExperimentalFeature("FOO_FLAG")).toBe("1"),e.removeExperimentalFeature("FOO_FLAG"),n(e.getExperimentalFeature("FOO_FLAG")).toBeUndefined(),n(()=>e.removeExperimentalFeature("FOO_FLAG")).not.toThrow()}),t("saveMCPConfig persists onto disk",()=>{e.saveMCPConfig({hasCompletedOnboarding:!0});const t=l(v,".claude.json");n(O(t)).toBe(!0);const o=JSON.parse(g(t,"utf-8"));n(o.hasCompletedOnboarding).toBe(!0)})});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"claude-code-manager.test.js","sourceRoot":"","sources":["../../src/__tests__/claude-code-manager.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACzE,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AACjE,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AAE5B,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM,EAAE,EAAE,cAAc,IAAI,CAAC,GAAG,EAAE,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;AAElG,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,IAAI,EAAE;IACrB,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,YAAY,CAAsB,IAAI,CAAC,CAAC;IAChE,OAAO;QACH,GAAG,MAAM;QACT,OAAO,EAAE,GAAG,EAAE,CAAC,OAAO;KACzB,CAAC;AACN,CAAC,CAAC,CAAC;AAEH,QAAQ,CAAC,mBAAmB,EAAE,GAAG,EAAE;IAC/B,IAAI,iBAAmF,CAAC;IAExF,UAAU,CAAC,KAAK,IAAI,EAAE;QAClB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AAsB,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAEvE,oBAAoB;QACpB,iBAAiB,CAAC,sBAAsB,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC;QAC1D,MAAM,CAAC,iBAAiB,CAAC,sBAAsB,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAEvE,iBAAiB,CAAC,yBAAyB,CAAC,UAAU,CAAC,CAAC;QACxD,MAAM,CAAC,iBAAiB,CAAC,sBAAsB,CAAC,UAAU,CAAC,CAAC,CAAC,aAAa,EAAE,CAAC;QAE7E,+BAA+B;QAC/B,MAAM,CAAC,GAAG,EAAE,CAAC,iBAAiB,CAAC,yBAAyB,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;IACxF,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,kCAAkC,EAAE,GAAG,EAAE;QACxC,iBAAiB,CAAC,aAAa,CAAC,EAAE,sBAAsB,EAAE,IAAI,EAAE,CAAC,CAAC;QAClE,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC;QAC9C,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACvC,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;QAC1D,MAAM,CAAC,MAAM,CAAC,sBAAsB,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACrD,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{describe as e,it as o,expect as t,beforeEach as n,afterEach as a,vi as s}from"vitest";import{mkdirSync as i,rmSync as c}from"fs";import{join as r}from"path";import{tmpdir as m}from"os";const p=r(m(),`vibecli-cmd-${Date.now()}-${Math.random().toString(36).slice(2)}`);e("Command class",()=>{let e;n(()=>{i(p,{recursive:!0}),e=process.env.VIBECLI_TEST_HOME,process.env.VIBECLI_TEST_HOME=p}),a(()=>{void 0!==e?process.env.VIBECLI_TEST_HOME=e:delete process.env.VIBECLI_TEST_HOME;try{c(p,{recursive:!0,force:!0})}catch{}}),o("constructs and exposes commander program",async()=>{const{Command:e}=await import("../lib/command.js"),o=(new e).getProgram();t(o).toBeDefined(),t(o.name()).toBe("vibecli")}),o("registers expected subcommands",async()=>{const{Command:e}=await import("../lib/command.js"),o=(new e).getProgram().commands.map(e=>e.name());t(o).toContain("init"),t(o).toContain("lang"),t(o).toContain("auth"),t(o).toContain("doctor"),t(o).toContain("status"),t(o).toContain("enter")}),o("exposes --base global option",async()=>{const{Command:e}=await import("../lib/command.js"),o=(new e).getProgram().options.map(e=>e.long);t(o).toContain("--base")}),o("exposes a version derived from package.json",async()=>{const{Command:e}=await import("../lib/command.js"),o=(new e).getProgram();t(typeof o.version).toBe("function")})}),e("config tool via commander honors global --non-interactive",()=>{let e;n(()=>{i(p,{recursive:!0}),e=process.env.VIBECLI_TEST_HOME,process.env.VIBECLI_TEST_HOME=p}),a(async()=>{const{resetRuntimeOptions:o}=await import("../lib/runtime-options.js");o(),void 0!==e?process.env.VIBECLI_TEST_HOME=e:delete process.env.VIBECLI_TEST_HOME;try{c(p,{recursive:!0,force:!0})}catch{}}),o("config <tool> --non-interactive resolves without opening the interactive menu",async()=>{const{Command:e}=await import("../lib/command.js"),o=new e,n=[],a=s.spyOn(console,"log").mockImplementation((...e)=>{n.push(e.join(" "))});try{await o.execute(["config","atomcode","--non-interactive"])}finally{a.mockRestore()}t(n.join("\n")).toMatch(/AtomCode|API/i)})}),e("command --base preflight",()=>{let e;n(()=>{i(p,{recursive:!0}),e=process.env.VIBECLI_TEST_HOME,process.env.VIBECLI_TEST_HOME=p}),a(()=>{void 0!==e?process.env.VIBECLI_TEST_HOME=e:delete process.env.VIBECLI_TEST_HOME;try{c(p,{recursive:!0,force:!0})}catch{}}),o("execute() applies --base before parse",async()=>{const{configManager:e}=await import("../lib/config.js"),{Command:o}=await import("../lib/command.js"),n=new o,a=s.spyOn(e,"setBaseUrl");try{await n.execute(["--base","https://example.com","--help"])}catch{}t(a).toHaveBeenCalledWith("https://example.com")}),o("execute() also accepts --base=URL form",async()=>{const{configManager:e}=await import("../lib/config.js"),{Command:o}=await import("../lib/command.js"),n=new o,a=s.spyOn(e,"setBaseUrl");try{await n.execute(["--base=https://eq.example.com","--help"])}catch{}t(a).toHaveBeenCalledWith("https://eq.example.com")})});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"command.test.js","sourceRoot":"","sources":["../../src/__tests__/command.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACzE,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AAE5B,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM,EAAE,EAAE,eAAe,IAAI,CAAC,GAAG,EAAE,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;AAEnG,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;IAC3B,IAAI,gBAAoC,CAAC;IAEzC,UAAU,CAAC,GAAG,EAAE;QACZ,SAAS,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QACxC,gBAAgB,GAAG,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC;QACjD,OAAO,CAAC,GAAG,C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ect as t,beforeEach as e,afterEach as n,vi as s}from"vitest";import{mkdirSync as i,rmSync as m}from"fs";import{join as r}from"path";import{tmpdir as c}from"os";const d=r(c(),`vibecli-handlers-${Date.now()}-${Math.random().toString(36).slice(2)}`);a("command handlers",()=>{let r,c;e(()=>{i(d,{recursive:!0}),r=process.env.VIBECLI_TEST_HOME,process.env.VIBECLI_TEST_HOME=d,c=s.spyOn(console,"log").mockImplementation(()=>{})}),n(()=>{void 0!==r?process.env.VIBECLI_TEST_HOME=r:delete process.env.VIBECLI_TEST_HOME;try{m(d,{recursive:!0,force:!0})}catch{}s.restoreAllMocks()}),a("langCommand",()=>{o("show prints current language without throwing",async()=>{const{langCommand:a}=await import("../commands/lang.js");await a(["show"]),t(c).toHaveBeenCalled()}),o("set updates language for a supported locale",async()=>{const{langCommand:a}=await import("../commands/lang.js"),{configManager:o}=await import("../lib/config.js");await a(["set","en_US"]),t(o.getLang()).toBe("en_US")}),o("set rejects an unsupported locale",async()=>{const{langCommand:a}=await import("../commands/lang.js");await t(a(["set","xx_YY"])).resolves.toBeUndefined(),t(c).toHaveBeenCalled()})}),a("statusCommand",()=>{o("prints something without throwing",async()=>{const{statusCommand:a}=await import("../commands/status.js");await a(),t(c).toHaveBeenCalled()})}),a("authCommand",()=>{o("reload exits early when no api key is configured",async()=>{const{authCommand:a}=await import("../commands/auth.js");await a(["reload","claude"]),t(c).toHaveBeenCalled()}),o("reload rejects unsupported tools",async()=>{const{authCommand:a}=await import("../commands/auth.js");await a(["reload","unsupported-tool"]),t(c).toHaveBeenCalled()}),o("directAuth path attempts validation",async()=>{const a=await import("../lib/api-validator.js"),o=s.spyOn(a,"validateApiKey").mockResolvedValue({valid:!1,error:"invalid_api_key"}),{authCommand:e}=await import("../commands/auth.js");await e(["some-token"]),t(o).toHaveBeenCalled()})}),a("doctorCommand",()=>{o("runs without throwing when no api key",async()=>{const{doctorCommand:a}=await import("../commands/doctor.js");await a(),t(c).toHaveBeenCalled()})}),a("configCommand",()=>{o("exists and is invokable",async()=>{const a=await import("../commands/config.js");t(typeof a.configCommand).toBe("function")})})});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"commands.test.js","sourceRoot":"","sources":["../../src/__tests__/commands.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACzE,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AAE5B,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM,EAAE,EAAE,oBAAoB,IAAI,CAAC,GAAG,EAAE,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;AAExG,QAAQ,CAAC,kBAAkB,EAAE,GAAG,EAAE;IAC9B,IAAI,gBAAoC,CAAC;IACzC,IAAI,MAAmC,CAAC;IAExC,UAAU,CAAC,GAAG,EAAE;QACZ,SAAS,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QACxC,gBAAgB,GAAG,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC;QACjD,OAAO,CAAC,GAAG,CAAC,iBAAiB,GAAG,OAAO,CAAC;QACxC,MAAM,GAAG,EAAE,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,kBAAkB,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;IAC1E,CAAC,CAAC,CAAC;IAEH,SAAS,CAAC,GAAG,EAAE;QACX,IAAI,gBAAgB,KAAK,SAAS,EAAE,CAAC;YACjC,OAAO,CAAC,GAAG,CAAC,iBAAiB,GAAG,gBAAgB,CAAC;QACr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AK,EAAE,KAAK;gBACZ,KAAK,EAAE,iBAAiB;aAC3B,CAAC,CAAC;YACH,MAAM,EAAE,WAAW,EAAE,GAAG,MAAM,MAAM,CAAC,qBAAqB,CAAC,CAAC;YAC5D,MAAM,WAAW,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC;YAClC,MAAM,CAAC,GAAG,CAAC,CAAC,gBAAgB,EAAE,CAAC;QACnC,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;QAC3B,EAAE,CAAC,uCAAuC,EAAE,KAAK,IAAI,EAAE;YACnD,MAAM,EAAE,aAAa,EAAE,GAAG,MAAM,MAAM,CAAC,uBAAuB,CAAC,CAAC;YAChE,mEAAmE;YACnE,2CAA2C;YAC3C,MAAM,aAAa,EAAE,CAAC;YACtB,MAAM,CAAC,MAAM,CAAC,CAAC,gBAAgB,EAAE,CAAC;QACtC,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;QAC3B,EAAE,CAAC,yBAAyB,EAAE,KAAK,IAAI,EAAE;YACrC,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,uBAAuB,CAAC,CAAC;YAClD,MAAM,CAAC,OAAO,GAAG,CAAC,aAAa,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QACtD,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{describe as e,it as a,expect as t,beforeEach as o,afterEach as n,vi as i}from"vitest";import{mkdirSync as r,rmSync as s,existsSync as c,readFileSync as g}from"fs";import{join as l}from"path";import{tmpdir as f}from"os";import*as p from"js-yaml";e("ConfigManager profiles & presets & backups",()=>{let e,m,M;o(async()=>{e=l(f(),`vibecli-profile-${Date.now()}-${Math.random().toString(36).slice(2)}`),r(e,{recursive:!0}),m=process.env.VIBECLI_TEST_HOME,process.env.VIBECLI_TEST_HOME=e,i.resetModules(),M=await import("../lib/config.js")}),n(()=>{void 0!==m?process.env.VIBECLI_TEST_HOME=m:delete process.env.VIBECLI_TEST_HOME;try{s(e,{recursive:!0,force:!0})}catch{}}),a("starts with a default profile",()=>{const e=M.configManager.listProfiles();t(e).toContain(M.DEFAULT_PROFILE_NAME),t(M.configManager.getActiveProfileName()).toBe(M.DEFAULT_PROFILE_NAME)}),a("persists API key on the active profile only",()=>{M.configManager.setApiKey("key-default"),M.configManager.createProfile("alt"),M.configManager.setActiveProfile("alt"),M.configManager.setApiKey("key-alt"),M.configManager.setActiveProfile(M.DEFAULT_PROFILE_NAME),t(M.configManager.getApiKey()).toBe("key-default"),M.configManager.setActiveProfile("alt"),t(M.configManager.getApiKey()).toBe("key-alt")}),a("refuses to delete the only remaining profile",()=>{t(()=>M.configManager.deleteProfile(M.DEFAULT_PROFILE_NAME)).toThrow()}),a("deletes a profile and re-elects an active one",()=>{M.configManager.createProfile("alt"),M.configManager.setActiveProfile("alt"),M.configManager.deleteProfile("alt"),t(M.configManager.listProfiles()).not.toContain("alt"),t(M.configManager.getActiveProfileName()).toBe(M.DEFAULT_PROFILE_NAME)}),a("saves and applies custom presets",()=>{const e={haiku:"h-x",sonnet:"s-x",opus:"o-x",reasoning:"r-x"};M.configManager.saveCustomPreset("mine",e);const a=M.configManager.getCustomPresets();t(a.mine.models).toEqual(e),t(typeof a.mine.updated_at).toBe("string"),M.configManager.setModels(M.DEFAULT_MODELS),M.configManager.setModels(a.mine.models),t(M.configManager.getModels()).toEqual(e),M.configManager.deleteCustomPreset("mine"),t(M.configManager.getCustomPresets()).not.toHaveProperty("mine")}),a("creates manual backups and lists them",()=>{M.configManager.setApiKey("key-1");const e=M.configManager.createBackup("snapshot one");t(c(e)).toBe(!0);const a=M.configManager.listBackups();t(a.length).toBeGreaterThan(0),t(a[0].name).toBe(e.split(/[/\\]/).pop())}),a("restores a previous backup",async()=>{M.configManager.setApiKey("key-old");const e=M.configManager.createBackup();M.configManager.setApiKey("key-new"),i.resetModules();const a=await import("../lib/config.js");a.configManager.restoreBackup(e.split(/[/\\]/).pop()),t(a.configManager.getApiKey()).toBe("key-old")}),a("rejects backup names containing path-traversal segments",()=>{t(()=>M.configManager.restoreBackup("..")).toThrow(/Invalid backup name/),t(()=>M.configManager.restoreBackup("../etc/passwd")).toThrow(/Invalid backup name/),t(()=>M.configManager.restoreBackup("a/b.yaml")).toThrow(/Invalid backup name/),t(()=>M.configManager.restoreBackup("a\\b.yaml")).toThrow(/Invalid backup name/)}),a("migrates legacy plan field on disk",async()=>{const a=l(e,".vibecli");r(a,{recursive:!0}),(await import("fs")).writeFileSync(l(a,"config.yaml"),p.dump({lang:"zh_CN",api_key:"legacy-key",plan:"legacy-plan"}),"utf-8"),i.resetModules();const o=await import("../lib/config.js");t(o.configManager.getApiKey()).toBe("legacy-key");const n=p.load(g(l(a,"config.yaml"),"utf-8"));t(n).not.toHaveProperty("plan"),t(n).toHaveProperty("profiles")}),a("revokeApiKey clears both yaml profile and the encrypted secrets entry",async()=>{M.configManager.setApiKey("sk-revoke-test"),t(M.configManager.getApiKey()).toBe("sk-revoke-test");const a=await import("../lib/secret-store.js");t(a.secretStore.getApiKey(M.DEFAULT_PROFILE_NAME)).toBe("sk-revoke-test"),M.configManager.revokeApiKey(),t(M.configManager.getApiKey()).toBeUndefined();const o=p.load(g(l(e,".vibecli","config.yaml"),"utf-8"));t(o.profiles?.[M.DEFAULT_PROFILE_NAME]?.api_key).toBeUndefined(),t(a.secretStore.getApiKey(M.DEFAULT_PROFILE_NAME)).toBeUndefined(),t(a.secretStore.listProfilesWithKeys()).not.toContain(M.DEFAULT_PROFILE_NAME)}),a("--base=URL form is recognized as a transient runtime override (not persisted)",async()=>{M.configManager.setApiKey("sk-anchor");const{Command:a}=await import("../lib/command.js"),o=new a;try{await o.execute(["--base=https://transient.example.com","--help"])}catch{}t(M.configManager.getBaseUrl()).toBe("https://transient.example.com");const n=p.load(g(l(e,".vibecli","config.yaml"),"utf-8")),i=M.configManager.getActiveProfileName();t(n.profiles?.[i]?.base_url).not.toBe("https://transient.example.com")})});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"config-profiles.test.js","sourceRoot":"","sources":["../../src/__tests__/config-profiles.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACzE,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AACjE,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AAC5B,OAAO,KAAK,IAAI,MAAM,SAAS,CAAC;AAQhC,QAAQ,CAAC,4CAA4C,EAAE,GAAG,EAAE;IACxD,IAAI,OAAe,CAAC;IACpB,IAAI,gBAAoC,CAAC;IACzC,IAAI,GAAwB,CAAC;IAE7B,UAAU,CAAC,KAAK,IAAI,EAAE;QAClB,OAAO,GAAG,IAAI,CAAC,MAAM,EAAE,EAAE,mBAAmB,IAAI,CAAC,GAAG,EAAE,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QACjG,SAAS,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QACxC,gBAAgB,GAAG,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC;QACjD,OAAO,CAAC,GAAG,CAAC,iBAAiB,GAAG,OAAO,CAAC;QACxC,EAAE,CAAC,YAAY,EAAE,CAAC;QAClB,GAAG,GAAG,MAAM,MAAM,CAAC,kBAAkB,CAAC,CAAC;IAC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AC,+BAA+B,CAAC,CAAC;QAE7E,0EAA0E;QAC1E,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,OAAO,EAAE,UAAU,EAAE,aAAa,CAAC,EAAE,OAAO,CAAC,CAAyD,CAAC;QAClJ,MAAM,aAAa,GAAG,GAAG,CAAC,aAAa,CAAC,oBAAoB,EAAE,CAAC;QAC/D,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,aAAa,CAAC,EAAE,QAAQ,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,+BAA+B,CAAC,CAAC;IACjG,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{describe as e,it as o,expect as c,beforeEach as t,afterEach as i,vi as n}from"vitest";import{mkdirSync as s,rmSync as r,existsSync as a,readFileSync as l,writeFileSync as g}from"fs";import{join as p}from"path";import{tmpdir as v}from"os";import*as u from"js-yaml";e("legacy ~/.chelper migration",()=>{let e,l;t(()=>{e=p(v(),`vibecli-mig-${Date.now()}-${Math.random().toString(36).slice(2)}`),s(e,{recursive:!0}),l=process.env.VIBECLI_TEST_HOME,process.env.VIBECLI_TEST_HOME=e}),i(()=>{void 0!==l?process.env.VIBECLI_TEST_HOME=l:delete process.env.VIBECLI_TEST_HOME;try{r(e,{recursive:!0,force:!0})}catch{}}),o("renames ~/.chelper to ~/.vibecli on startup (whole-directory move)",async()=>{const o=p(e,".chelper");s(o,{recursive:!0}),g(p(o,"config.yaml"),u.dump({lang:"zh_CN"}),"utf-8"),g(p(o,"secrets.enc"),"opaque-envelope","utf-8"),n.resetModules();const{configManager:t}=await import("../lib/config.js");c(a(p(e,".vibecli","config.yaml"))).toBe(!0),c(a(p(e,".vibecli","secrets.enc"))).toBe(!0),c(a(o)).toBe(!1),c(t.getLang()).toBe("zh_CN")}),o("migrates into a pre-created empty ~/.vibecli (e.g. logger made the dir first)",async()=>{s(p(e,".vibecli","logs"),{recursive:!0});const o=p(e,".chelper");s(o,{recursive:!0}),g(p(o,"config.yaml"),u.dump({lang:"zh_CN"}),"utf-8"),g(p(o,"secrets.enc"),"opaque-envelope","utf-8"),n.resetModules();const{configManager:t}=await import("../lib/config.js");c(a(p(e,".vibecli","config.yaml"))).toBe(!0),c(a(p(e,".vibecli","secrets.enc"))).toBe(!0),c(a(o)).toBe(!1),c(t.getLang()).toBe("zh_CN")}),o("leaves an existing ~/.vibecli untouched even when ~/.chelper also exists",async()=>{s(p(e,".vibecli"),{recursive:!0}),g(p(e,".vibecli","config.yaml"),u.dump({lang:"en_US"}),"utf-8"),s(p(e,".chelper"),{recursive:!0}),g(p(e,".chelper","config.yaml"),u.dump({lang:"zh_CN"}),"utf-8"),n.resetModules();const{configManager:o}=await import("../lib/config.js");c(o.getLang()).toBe("en_US"),c(a(p(e,".chelper"))).toBe(!0)})}),e("ConfigManager",()=>{let e,n;t(()=>{e=p(v(),`vibecli-test-${Date.now()}-${Math.random().toString(36).slice(2)}`),s(e,{recursive:!0}),n=process.env.VIBECLI_TEST_HOME,process.env.VIBECLI_TEST_HOME=e}),i(()=>{void 0!==n?process.env.VIBECLI_TEST_HOME=n:delete process.env.VIBECLI_TEST_HOME;try{r(e,{recursive:!0,force:!0})}catch{}}),o("should detect first run when no config exists",async()=>{const o=p(e,".vibecli","config.yaml");c(a(o)).toBe(!1)}),o("should save and load config correctly",async()=>{const o=p(e,".vibecli");s(o,{recursive:!0});const t=p(o,"config.yaml"),i=u.dump({lang:"zh_CN",api_key:"test-key-123"});g(t,i,"utf-8");const n=u.load(l(t,"utf-8"));c(n.lang).toBe("zh_CN"),c(n.api_key).toBe("test-key-123")}),o("should handle missing config gracefully",()=>{const o=p(e,".vibecli","config.yaml");c(a(o)).toBe(!1)}),o("should migrate old config with plan field",()=>{const o=p(e,".vibecli");s(o,{recursive:!0});const t=p(o,"config.yaml");g(t,u.dump({lang:"en_US",plan:"some-plan",api_key:"key123"}),"utf-8");const i=u.load(l(t,"utf-8"));c(i.plan).toBe("some-plan"),c(i.lang).toBe("en_US")}),o("should create backup directory on save",()=>{const o=p(e,".vibecli");s(o,{recursive:!0});const t=p(o,"backups");c(a(t)).toBe(!1)})});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"config.test.js","sourceRoot":"","sources":["../../src/__tests__/config.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACzE,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;AAChF,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AAC5B,OAAO,KAAK,IAAI,MAAM,SAAS,CAAC;AAEhC,QAAQ,CAAC,6BAA6B,EAAE,GAAG,EAAE;IACzC,IAAI,OAAe,CAAC;IACpB,IAAI,gBAAoC,CAAC;IAEzC,UAAU,CAAC,GAAG,EAAE;QACZ,OAAO,GAAG,IAAI,CAAC,MAAM,EAAE,EAAE,eAAe,IAAI,CAAC,GAAG,EAAE,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QAC7F,SAAS,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QACxC,gBAAgB,GAAG,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC;QACjD,OAAO,CAAC,GAAG,CAAC,iBAAiB,GAAG,OAAO,CAAC;IAC5C,CAAC,CAAC,CAAC;IAEH,SAAS,CAAC,GAAG,EAAE;QACX,IAAI,gBAAgB,KAAK,SAAS,EAAE,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tC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACtC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,wCAAwC,EAAE,GAAG,EAAE;QAC9C,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;QAC5C,SAAS,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QAC1C,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;QAC7C,MAAM,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC9C,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{describe as e,it as s,expect as o,beforeEach as t,afterEach as n}from"vitest";import{mkdirSync as r,rmSync as a,readFileSync as l,writeFileSync as i,existsSync as p}from"fs";import{join as c}from"path";import{tmpdir as A}from"os";import{cleanupAnthropicEnvVars as _,cleanupShellRcEnvVars as I,getShellRcFilePath as E}from"../lib/env-cleanup.js";const P=["ANTHROPIC_API_KEY","ANTHROPIC_BASE_URL","SHELL","VIBECLI_TEST_HOME"];e("env-cleanup",()=>{let h,v;t(()=>{h=c(A(),`vibecli-env-${Date.now()}-${Math.random().toString(36).slice(2)}`),r(h,{recursive:!0}),v=Object.fromEntries(P.map(e=>[e,process.env[e]])),process.env.VIBECLI_TEST_HOME=h,process.env.SHELL="/bin/bash",delete process.env.ANTHROPIC_API_KEY,delete process.env.ANTHROPIC_BASE_URL}),n(()=>{for(const e of P)void 0!==v[e]?process.env[e]=v[e]:delete process.env[e];try{a(h,{recursive:!0,force:!0})}catch{}}),e("getShellRcFilePath",()=>{s.skipIf("win32"===process.platform)("maps common shells to their rc files",()=>{process.env.SHELL="/bin/bash",o(E()).toBe(c(h,".bashrc")),process.env.SHELL="/usr/bin/zsh",o(E()).toBe(c(h,".zshrc")),process.env.SHELL="/usr/bin/fish",o(E()).toBe(c(h,".config","fish","config.fish")),process.env.SHELL="/bin/dash",o(E()).toBe(c(h,".profile"))})}),e("cleanupAnthropicEnvVars",()=>{s("returns empty and touches nothing when the vars are absent",()=>{const e=c(h,".bashrc");i(e,"export ANTHROPIC_API_KEY=sk-stale\n","utf-8"),o(_()).toEqual([]),o(l(e,"utf-8")).toContain("ANTHROPIC_API_KEY")}),s("clears both vars from process.env and reports them",()=>{process.env.ANTHROPIC_API_KEY="sk-leak",process.env.ANTHROPIC_BASE_URL="https://leak.example.com";const e=_();o(e.sort()).toEqual(["ANTHROPIC_API_KEY","ANTHROPIC_BASE_URL"]),o(process.env.ANTHROPIC_API_KEY).toBeUndefined(),o(process.env.ANTHROPIC_BASE_URL).toBeUndefined()}),s("reports only the var that was actually set",()=>{process.env.ANTHROPIC_BASE_URL="https://leak.example.com",o(_()).toEqual(["ANTHROPIC_BASE_URL"]),o(process.env.ANTHROPIC_BASE_URL).toBeUndefined()}),s.skipIf("win32"===process.platform)("strips export lines from the shell rc file but keeps other content",()=>{const e=c(h,".bashrc");i(e,['alias ll="ls -la"',"# Claude Code environment variables","export ANTHROPIC_BASE_URL=https://old.example.com","export ANTHROPIC_API_KEY=sk-old",'export PATH="$PATH:/opt/bin"',""].join("\n"),"utf-8"),process.env.ANTHROPIC_API_KEY="sk-leak",_();const s=l(e,"utf-8");o(s).not.toContain("ANTHROPIC_BASE_URL"),o(s).not.toContain("ANTHROPIC_API_KEY"),o(s).not.toContain("Claude Code environment variables"),o(s).toContain('alias ll="ls -la"'),o(s).toContain('export PATH="$PATH:/opt/bin"')}),s("survives a missing rc file",()=>{process.env.ANTHROPIC_API_KEY="sk-leak",o(p(c(h,".bashrc"))).toBe(!1),o(_()).toEqual(["ANTHROPIC_API_KEY"]),o(process.env.ANTHROPIC_API_KEY).toBeUndefined()})}),e("cleanupShellRcEnvVars",()=>{s.skipIf("win32"===process.platform)("returns false when nothing changes",()=>{i(c(h,".bashrc"),'alias ll="ls -la"\n',"utf-8"),o(I()).toBe(!1)}),s.skipIf("win32"===process.platform)("returns true when export lines were removed",()=>{i(c(h,".bashrc"),"export ANTHROPIC_API_KEY=sk-old\n","utf-8"),o(I()).toBe(!0)})})});
|