hop-claude 1.0.0

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.
Files changed (65) hide show
  1. package/CHANGELOG.md +316 -0
  2. package/README.md +574 -0
  3. package/SECURITY.md +280 -0
  4. package/bin/cli.js +6 -0
  5. package/dist/cli.d.ts +6 -0
  6. package/dist/cli.d.ts.map +1 -0
  7. package/dist/cli.js +147 -0
  8. package/dist/cli.js.map +1 -0
  9. package/dist/config/config-manager.d.ts +88 -0
  10. package/dist/config/config-manager.d.ts.map +1 -0
  11. package/dist/config/config-manager.js +334 -0
  12. package/dist/config/config-manager.js.map +1 -0
  13. package/dist/config/encryption-v2.d.ts +51 -0
  14. package/dist/config/encryption-v2.d.ts.map +1 -0
  15. package/dist/config/encryption-v2.js +93 -0
  16. package/dist/config/encryption-v2.js.map +1 -0
  17. package/dist/config/encryption.d.ts +36 -0
  18. package/dist/config/encryption.d.ts.map +1 -0
  19. package/dist/config/encryption.js +72 -0
  20. package/dist/config/encryption.js.map +1 -0
  21. package/dist/config/keychain.d.ts +56 -0
  22. package/dist/config/keychain.d.ts.map +1 -0
  23. package/dist/config/keychain.js +112 -0
  24. package/dist/config/keychain.js.map +1 -0
  25. package/dist/config/storage.d.ts +32 -0
  26. package/dist/config/storage.d.ts.map +1 -0
  27. package/dist/config/storage.js +87 -0
  28. package/dist/config/storage.js.map +1 -0
  29. package/dist/config/validator.d.ts +9 -0
  30. package/dist/config/validator.d.ts.map +1 -0
  31. package/dist/config/validator.js +53 -0
  32. package/dist/config/validator.js.map +1 -0
  33. package/dist/index.d.ts +2 -0
  34. package/dist/index.d.ts.map +1 -0
  35. package/dist/index.js +10 -0
  36. package/dist/index.js.map +1 -0
  37. package/dist/types/index.d.ts +38 -0
  38. package/dist/types/index.d.ts.map +1 -0
  39. package/dist/types/index.js +2 -0
  40. package/dist/types/index.js.map +1 -0
  41. package/dist/ui/display.d.ts +25 -0
  42. package/dist/ui/display.d.ts.map +1 -0
  43. package/dist/ui/display.js +39 -0
  44. package/dist/ui/display.js.map +1 -0
  45. package/dist/ui/prompts.d.ts +52 -0
  46. package/dist/ui/prompts.d.ts.map +1 -0
  47. package/dist/ui/prompts.js +339 -0
  48. package/dist/ui/prompts.js.map +1 -0
  49. package/dist/utils/backup.d.ts +14 -0
  50. package/dist/utils/backup.d.ts.map +1 -0
  51. package/dist/utils/backup.js +27 -0
  52. package/dist/utils/backup.js.map +1 -0
  53. package/dist/utils/claude-launcher.d.ts +8 -0
  54. package/dist/utils/claude-launcher.d.ts.map +1 -0
  55. package/dist/utils/claude-launcher.js +68 -0
  56. package/dist/utils/claude-launcher.js.map +1 -0
  57. package/dist/utils/migration.d.ts +18 -0
  58. package/dist/utils/migration.d.ts.map +1 -0
  59. package/dist/utils/migration.js +176 -0
  60. package/dist/utils/migration.js.map +1 -0
  61. package/dist/utils/platform.d.ts +19 -0
  62. package/dist/utils/platform.d.ts.map +1 -0
  63. package/dist/utils/platform.js +91 -0
  64. package/dist/utils/platform.js.map +1 -0
  65. package/package.json +54 -0
package/SECURITY.md ADDED
@@ -0,0 +1,280 @@
1
+ # Security Policy
2
+
3
+ ## Reporting Security Vulnerabilities
4
+
5
+ If you discover a security vulnerability in hop-claude, please report it responsibly:
6
+
7
+ - **Email:** Create an issue on GitHub with the tag `security` (or email the maintainer privately for sensitive issues)
8
+ - **Response Time:** We aim to respond within 48 hours and provide a fix within 7 days for critical vulnerabilities
9
+
10
+ **Please do not** publicly disclose the vulnerability until a fix has been released.
11
+
12
+ ---
13
+
14
+ ## Security Model
15
+
16
+ hop-claude manages sensitive API keys for Claude Code CLI. Understanding our security model helps you use the tool safely.
17
+
18
+ ### Encryption Modes
19
+
20
+ hop-claude supports three encryption modes with different security trade-offs:
21
+
22
+ #### 1. Keychain Mode (Recommended) ⭐
23
+
24
+ **Security Level:** HIGH
25
+
26
+ - API keys stored in OS-managed keychain:
27
+ - macOS: Keychain Access
28
+ - Windows: Credential Manager
29
+ - Linux: libsecret
30
+ - Keys never written to disk in plain text
31
+ - Encrypted by OS using hardware-backed secrets (when available)
32
+ - No password required for daily use
33
+
34
+ **Limitations:**
35
+ - Not portable across machines
36
+ - Requires functional OS keychain
37
+
38
+ **Best for:** Single-machine usage, maximum security
39
+
40
+ #### 2. Passphrase Mode
41
+
42
+ **Security Level:** MEDIUM to HIGH (depends on passphrase strength)
43
+
44
+ - API keys encrypted with AES-256-GCM using user-provided passphrase
45
+ - PBKDF2 key derivation with 100,000 iterations
46
+ - Fully portable across machines
47
+ - Password required for each operation
48
+
49
+ **Limitations:**
50
+ - Security depends on passphrase strength (minimum 8 characters enforced)
51
+ - Password must be remembered or stored securely
52
+ - Vulnerable to brute-force if weak password used
53
+
54
+ **Best for:** Multi-machine usage, team sharing (with secure password management)
55
+
56
+ #### 3. Legacy Mode (Deprecated)
57
+
58
+ **Security Level:** LOW
59
+
60
+ - Machine-bound encryption using hostname + username as key material
61
+ - Provides obfuscation, not true security
62
+ - Backwards compatible with v0.0.x
63
+
64
+ **Limitations:**
65
+ - Not portable across machines
66
+ - Weak against local attackers with filesystem access
67
+ - Keys can be decrypted if attacker knows hostname and username
68
+
69
+ **Status:** Deprecated. Migrate to Keychain or Passphrase mode.
70
+
71
+ ---
72
+
73
+ ## What We Protect Against
74
+
75
+ hop-claude is designed to protect against:
76
+
77
+ ✅ **Accidental Exposure**
78
+ - Prevents API keys from appearing in git commits
79
+ - Keys not visible in process listings
80
+ - Redacted in terminal output (masked as `sk-ant-***xyz`)
81
+
82
+ ✅ **Casual Filesystem Access**
83
+ - Config directory permissions: `0700` (Unix) or restricted ACL (Windows)
84
+ - Config file permissions: `0600` (Unix)
85
+ - Encrypted storage prevents casual browsing
86
+
87
+ ✅ **Command Injection Attacks**
88
+ - No shell interpretation of user input (fixed in v0.1.0)
89
+ - Safe subprocess spawning without `shell: true`
90
+
91
+ ✅ **Concurrent Write Corruption**
92
+ - File locking prevents data corruption from simultaneous access
93
+ - Safe for multiple terminal sessions
94
+
95
+ ---
96
+
97
+ ## What We Do NOT Protect Against
98
+
99
+ hop-claude is a local development tool with inherent limitations:
100
+
101
+ ❌ **Root/Admin Access Attacks**
102
+ - Local root users can access any file, including encrypted configs
103
+ - OS keychain can be accessed by users with physical machine access
104
+
105
+ ❌ **Memory Inspection**
106
+ - API keys exist in plain text in memory during use
107
+ - Process memory can be dumped by privileged users
108
+
109
+ ❌ **Physical Access**
110
+ - Unattended, unlocked machines are vulnerable
111
+ - Screen capture or keyloggers can steal passwords
112
+
113
+ ❌ **Malware**
114
+ - If your machine is compromised, all local data is at risk
115
+ - Use antivirus and keep your system updated
116
+
117
+ ❌ **Network Interception**
118
+ - hop-claude only manages local storage
119
+ - API requests from Claude Code CLI are subject to network security
120
+
121
+ ---
122
+
123
+ ## Security Best Practices
124
+
125
+ ### For Keychain Mode Users
126
+
127
+ 1. ✅ Enable full disk encryption (FileVault, BitLocker, LUKS)
128
+ 2. ✅ Use strong machine login password
129
+ 3. ✅ Lock your screen when away (auto-lock recommended)
130
+ 4. ✅ Keep OS up to date for keychain security patches
131
+
132
+ ### For Passphrase Mode Users
133
+
134
+ 1. ✅ Use strong, unique passphrase (≥12 characters, mixed case, symbols)
135
+ 2. ✅ Consider using a password manager
136
+ 3. ✅ Never commit encrypted config to public repositories
137
+ 4. ✅ Rotate API keys if passphrase is compromised
138
+
139
+ ### For All Users
140
+
141
+ 1. ✅ Run `hop-claude --encryption-info` to verify your current mode
142
+ 2. ✅ Migrate from Legacy mode: `hop-claude --migrate-encryption`
143
+ 3. ✅ Review file permissions: Config directory should be owner-only
144
+ 4. ✅ Monitor API usage on Anthropic dashboard for suspicious activity
145
+ 5. ✅ Rotate API keys periodically (every 90 days recommended)
146
+
147
+ ---
148
+
149
+ ## Known Security Issues
150
+
151
+ ### v0.0.x (Legacy)
152
+
153
+ - **CRITICAL:** Command injection vulnerability via `shell: true` ➜ Fixed in v0.1.0
154
+ - **HIGH:** Machine-bound encryption is weak ➜ Migrate to Keychain/Passphrase mode
155
+
156
+ ### v0.1.0+
157
+
158
+ - No known critical vulnerabilities
159
+ - Legacy mode still available for compatibility but deprecated
160
+
161
+ ---
162
+
163
+ ## Threat Model
164
+
165
+ ### Attacker Profiles
166
+
167
+ | Attacker Type | Can They Access Keys? | Mitigation |
168
+ |---------------|----------------------|------------|
169
+ | Remote attacker (no local access) | ❌ No | N/A - keys only stored locally |
170
+ | Casual user on shared machine | ❌ No | File permissions + encryption |
171
+ | Determined user with physical access | ⚠️ Maybe | Use keychain mode + strong login password |
172
+ | Malware on your machine | ✅ Yes | Antivirus, system updates, vigilance |
173
+ | Root/Admin with physical access | ✅ Yes | No defense - rotate keys if compromised |
174
+
175
+ ### Attack Scenarios
176
+
177
+ **Scenario 1: Laptop Theft**
178
+ - **Keychain Mode:** Safe if disk encrypted and powered off
179
+ - **Passphrase Mode:** Safe if strong passphrase used
180
+ - **Legacy Mode:** Vulnerable if attacker can boot system
181
+
182
+ **Scenario 2: Shared Development Server**
183
+ - **Keychain Mode:** Safe from other users (OS isolation)
184
+ - **Passphrase Mode:** Safe from other users (file permissions)
185
+ - **Legacy Mode:** Vulnerable to other users
186
+
187
+ **Scenario 3: Git Commit Accident**
188
+ - **All Modes:** Keys are encrypted, not plain text
189
+ - **Keychain Mode:** Config file only has placeholders
190
+ - **Passphrase/Legacy:** Encrypted keys in config, but remove from git immediately
191
+
192
+ ---
193
+
194
+ ## Migration Guide
195
+
196
+ ### From v0.0.x to v0.1.0+
197
+
198
+ ```bash
199
+ # 1. Backup your config
200
+ hop-claude -e backup-before-migration.json
201
+
202
+ # 2. Run migration
203
+ hop-claude --migrate-encryption
204
+
205
+ # 3. Choose Keychain (most secure) or Passphrase (portable)
206
+
207
+ # 4. Verify migration
208
+ hop-claude --encryption-info
209
+ ```
210
+
211
+ ### Emergency Recovery
212
+
213
+ If migration fails:
214
+
215
+ ```bash
216
+ # Restore from backup
217
+ hop-claude -i backup-before-migration.json
218
+
219
+ # Or manually restore
220
+ # macOS/Linux:
221
+ cp ~/.hop-claude-config/config.json.backup-TIMESTAMP ~/.hop-claude-config/config.json
222
+
223
+ # Windows:
224
+ copy %APPDATA%\hop-claude-config\config.json.backup-TIMESTAMP %APPDATA%\hop-claude-config\config.json
225
+ ```
226
+
227
+ ---
228
+
229
+ ## Security Changelog
230
+
231
+ ### v0.1.0 (2025-01-03)
232
+ - ✅ Fixed command injection vulnerability (CRITICAL)
233
+ - ✅ Added Keychain and Passphrase encryption modes
234
+ - ✅ Implemented file locking for concurrent access
235
+ - ✅ Improved Windows binary detection
236
+ - ✅ Enhanced error handling with type safety
237
+ - ✅ Deprecated Legacy mode
238
+
239
+ ### v0.0.x
240
+ - ⚠️ Legacy encryption only (machine-bound)
241
+ - ⚠️ Command injection vulnerability present
242
+ - ⚠️ No concurrent write protection
243
+
244
+ ---
245
+
246
+ ## Security Audits
247
+
248
+ - **Internal:** Code reviewed by gemini-3-pro-preview and openai/o3 models (2025-01-03)
249
+ - **Community:** Awaiting external security audit
250
+ - **Automated:** 31 security and functionality tests pass
251
+
252
+ ---
253
+
254
+ ## Compliance & Certifications
255
+
256
+ hop-claude is a development tool intended for:
257
+ - Local development environments
258
+ - Individual developer use
259
+ - Small team collaboration
260
+
261
+ It is **NOT** certified for:
262
+ - HIPAA, PCI-DSS, SOC 2, or other compliance frameworks
263
+ - Production secrets management
264
+ - Enterprise deployment without additional security controls
265
+
266
+ For enterprise use, consider:
267
+ - HashiCorp Vault
268
+ - AWS Secrets Manager
269
+ - Azure Key Vault
270
+ - 1Password Secrets Automation
271
+
272
+ ---
273
+
274
+ ## Contact
275
+
276
+ For security concerns:
277
+ - GitHub Issues: https://github.com/0bipinnata0/hop-claude/issues
278
+ - Email: [your-email@example.com]
279
+
280
+ Last updated: 2025-01-03
package/bin/cli.js ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env node
2
+
3
+ import('../dist/index.js').catch((err) => {
4
+ console.error('Failed to load CLI:', err);
5
+ process.exit(1);
6
+ });
package/dist/cli.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ import { Command } from 'commander';
2
+ /**
3
+ * 创建 CLI 程序
4
+ */
5
+ export declare function createCLI(): Promise<Command>;
6
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AASpC;;GAEG;AACH,wBAAsB,SAAS,qBAiH9B"}
package/dist/cli.js ADDED
@@ -0,0 +1,147 @@
1
+ import { Command } from 'commander';
2
+ import { ConfigManager } from './config/config-manager.js';
3
+ import { InteractiveUI } from './ui/prompts.js';
4
+ import { launchClaude } from './utils/claude-launcher.js';
5
+ import { displayError, displaySuccess } from './ui/display.js';
6
+ import { backupConfig, restoreConfig } from './utils/backup.js';
7
+ import { EncryptionMigration } from './utils/migration.js';
8
+ import pkg from '../package.json' with { type: 'json' };
9
+ /**
10
+ * 创建 CLI 程序
11
+ */
12
+ export async function createCLI() {
13
+ const program = new Command();
14
+ const configManager = new ConfigManager();
15
+ const ui = new InteractiveUI(configManager);
16
+ program
17
+ .name('hop-claude')
18
+ .version(pkg.version)
19
+ .description('Claude Code configuration manager and launcher')
20
+ .option('-c, --config', 'Enter configuration management mode')
21
+ .option('-l, --list', 'List all configurations')
22
+ .option('-s, --switch <profile>', 'Switch to a specific profile')
23
+ .option('-e, --export <file>', 'Export configuration to file')
24
+ .option('-i, --import <file>', 'Import configuration from file')
25
+ .option('--migrate-encryption', 'Migrate to a different encryption mode')
26
+ .option('--encryption-info', 'Show current encryption mode information')
27
+ .allowUnknownOption(true) // 允许未知选项(用于透传给 claude)
28
+ .action(async (options) => {
29
+ try {
30
+ // 加密模式迁移
31
+ if (options.migrateEncryption) {
32
+ const migration = new EncryptionMigration(configManager);
33
+ await migration.migrate();
34
+ return;
35
+ }
36
+ // 显示加密模式信息
37
+ if (options.encryptionInfo) {
38
+ const migration = new EncryptionMigration(configManager);
39
+ await migration.showEncryptionInfo();
40
+ return;
41
+ }
42
+ // 列出配置
43
+ if (options.list) {
44
+ await ui.listConfigurations();
45
+ return;
46
+ }
47
+ // 快速切换 profile
48
+ if (options.switch) {
49
+ const profile = await configManager.getProfile(options.switch);
50
+ if (!profile) {
51
+ displayError(`Profile "${options.switch}" not found`);
52
+ process.exit(1);
53
+ }
54
+ await configManager.setCurrentProfile(options.switch);
55
+ displaySuccess(`Switched to: ${options.switch}`);
56
+ // 如果有透传参数,继续启动 claude
57
+ const claudeArgs = getClaudeArgs(process.argv);
58
+ if (claudeArgs.length > 0) {
59
+ await launchClaude(profile, claudeArgs);
60
+ }
61
+ return;
62
+ }
63
+ // 导出配置
64
+ if (options.export) {
65
+ await backupConfig(configManager, options.export);
66
+ displaySuccess(`Configuration exported to: ${options.export}`);
67
+ return;
68
+ }
69
+ // 导入配置
70
+ if (options.import) {
71
+ await restoreConfig(configManager, options.import);
72
+ displaySuccess('Configuration imported successfully');
73
+ return;
74
+ }
75
+ // 强制进入配置模式
76
+ if (options.config) {
77
+ await ui.manageConfiguration();
78
+ return;
79
+ }
80
+ // 正常流程:显示当前配置 + 询问是否修改
81
+ const shouldContinue = await ui.showCurrentAndAsk();
82
+ if (!shouldContinue) {
83
+ // 用户选择退出
84
+ return;
85
+ }
86
+ // 获取当前配置并启动 claude
87
+ const currentProfile = await configManager.getCurrentProfile();
88
+ if (!currentProfile) {
89
+ displayError('No configuration selected');
90
+ process.exit(1);
91
+ }
92
+ // 获取透传参数
93
+ const claudeArgs = getClaudeArgs(process.argv);
94
+ // 启动 claude
95
+ await launchClaude(currentProfile, claudeArgs);
96
+ }
97
+ catch (error) {
98
+ const err = error instanceof Error ? error : new Error(String(error));
99
+ displayError(err.message);
100
+ // 在 DEBUG 模式下显示完整的堆栈跟踪
101
+ if (process.env.DEBUG) {
102
+ console.error('\nStack trace:');
103
+ console.error(err.stack);
104
+ }
105
+ process.exit(1);
106
+ }
107
+ });
108
+ return program;
109
+ }
110
+ /**
111
+ * 获取需要透传给 claude 的参数
112
+ * 过滤掉 cproxy 自己的参数
113
+ */
114
+ function getClaudeArgs(argv) {
115
+ const cproxyFlags = [
116
+ '-c', '--config',
117
+ '-l', '--list',
118
+ '-s', '--switch',
119
+ '-e', '--export',
120
+ '-i', '--import',
121
+ '-v', '--version',
122
+ '-h', '--help',
123
+ '--migrate-encryption',
124
+ '--encryption-info'
125
+ ];
126
+ const result = [];
127
+ let skip = false;
128
+ for (let i = 2; i < argv.length; i++) {
129
+ const arg = argv[i];
130
+ if (skip) {
131
+ skip = false;
132
+ continue;
133
+ }
134
+ // 跳过 cproxy 的选项
135
+ if (cproxyFlags.includes(arg)) {
136
+ // 如果是需要值的选项,跳过下一个参数
137
+ if (['-s', '--switch', '-e', '--export', '-i', '--import'].includes(arg)) {
138
+ skip = true;
139
+ }
140
+ continue;
141
+ }
142
+ // 其他所有参数都透传
143
+ result.push(arg);
144
+ }
145
+ return result;
146
+ }
147
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAChE,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,GAAG,MAAM,iBAAiB,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAC;AAExD;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS;IAC7B,MAAM,OAAO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pB,CAAC;IACF,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,IAAI,IAAI,GAAG,KAAK,CAAC;IAEjB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACrC,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QAEpB,IAAI,IAAI,EAAE,CAAC;YACT,IAAI,GAAG,KAAK,CAAC;YACb,SAAS;QACX,CAAC;QAED,gBAAgB;QAChB,IAAI,WAAW,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;YAC9B,oBAAoB;YACpB,IAAI,CAAC,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,UAAU,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;gBACzE,IAAI,GAAG,IAAI,CAAC;YACd,CAAC;YACD,SAAS;QACX,CAAC;QAED,YAAY;QACZ,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACnB,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,88 @@
1
+ import type { ConfigStore, ProfileConfig, DecryptedProfile, EncryptionMode } from '../types/index.js';
2
+ /**
3
+ * 配置管理核心类
4
+ * 支持三种加密模式:
5
+ * - legacy: 机器绑定加密(向后兼容)
6
+ * - keychain: OS 密钥链存储(推荐)
7
+ * - passphrase: 用户密码加密(可移植)
8
+ */
9
+ export declare class ConfigManager {
10
+ private storage;
11
+ private legacyEncryption;
12
+ private passphraseEncryption;
13
+ private keychainManager;
14
+ private sessionPassphrase?;
15
+ constructor();
16
+ /**
17
+ * 设置会话密码(用于 passphrase 模式)
18
+ */
19
+ setSessionPassphrase(passphrase: string): void;
20
+ /**
21
+ * 清除会话密码
22
+ */
23
+ clearSessionPassphrase(): void;
24
+ /**
25
+ * 获取当前加密模式
26
+ */
27
+ getEncryptionMode(): Promise<EncryptionMode>;
28
+ /**
29
+ * 初始化配置文件
30
+ */
31
+ initialize(): Promise<ConfigStore>;
32
+ /**
33
+ * 获取所有配置
34
+ */
35
+ getConfig(): Promise<ConfigStore>;
36
+ /**
37
+ * 添加或更新 profile
38
+ * @param profile 解密后的 profile
39
+ * @param passphrase 密码(仅 passphrase 模式需要)
40
+ */
41
+ saveProfile(profile: DecryptedProfile, passphrase?: string): Promise<void>;
42
+ /**
43
+ * 获取解密后的 profile
44
+ * @param domain profile 名称
45
+ * @param passphrase 密码(仅 passphrase 模式需要)
46
+ */
47
+ getProfile(domain: string, passphrase?: string): Promise<DecryptedProfile | null>;
48
+ /**
49
+ * 设置当前激活的 profile
50
+ */
51
+ setCurrentProfile(domain: string): Promise<void>;
52
+ /**
53
+ * 获取当前激活的 profile
54
+ * @param passphrase 密码(仅 passphrase 模式需要)
55
+ */
56
+ getCurrentProfile(passphrase?: string): Promise<DecryptedProfile | null>;
57
+ /**
58
+ * 列出所有 profiles(API Key 部分隐藏)
59
+ * @param passphrase 密码(仅 passphrase 模式需要)
60
+ */
61
+ listProfiles(passphrase?: string): Promise<Array<ProfileConfig & {
62
+ maskedApiKey: string;
63
+ }>>;
64
+ /**
65
+ * 删除 profile
66
+ */
67
+ deleteProfile(domain: string): Promise<void>;
68
+ /**
69
+ * 导出配置(包含加密的数据)
70
+ * 注意:keychain 模式无法导出实际密钥
71
+ */
72
+ exportConfig(): Promise<string>;
73
+ /**
74
+ * 导入配置
75
+ */
76
+ importConfig(data: string): Promise<void>;
77
+ /**
78
+ * 切换加密模式(需要提供所有必要的凭据)
79
+ * @param newMode 新的加密模式
80
+ * @param passphrase 密码(切换到 passphrase 模式时需要)
81
+ */
82
+ switchEncryptionMode(newMode: EncryptionMode, passphrase?: string): Promise<void>;
83
+ /**
84
+ * 获取配置文件路径
85
+ */
86
+ getConfigPath(): string;
87
+ }
88
+ //# sourceMappingURL=config-manager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config-manager.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