ccem 2.68.0 → 2.72.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ccem",
3
- "version": "2.68.0",
3
+ "version": "2.72.2",
4
4
  "type": "module",
5
5
  "description": "Claude Code Environment Manager",
6
6
  "repository": {
@@ -15,6 +15,40 @@ const legacyConfigPath = process.platform === 'darwin'
15
15
  ? path.join(home, 'Library', 'Preferences', 'claude-code-env-manager-nodejs', 'config.json')
16
16
  : path.join(home, '.config', 'claude-code-env-manager-nodejs', 'config.json');
17
17
 
18
+ const OFFICIAL_ENV_NAME = 'official';
19
+ const TRUSTED_OFFICIAL_BASE_URLS = new Set([
20
+ 'https://api.anthropic.com',
21
+ 'https://api.anthropic.com/',
22
+ ]);
23
+ const DEFAULT_OFFICIAL_ENV = {
24
+ ANTHROPIC_BASE_URL: 'https://api.anthropic.com',
25
+ ANTHROPIC_DEFAULT_HAIKU_MODEL: 'claude-3-5-haiku-20241022',
26
+ ANTHROPIC_MODEL: 'opus',
27
+ };
28
+
29
+ function prepareMigratedConfig(content) {
30
+ const parsed = JSON.parse(content);
31
+ if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
32
+ throw new Error('legacy config must be an object');
33
+ }
34
+ if (!parsed.registries || typeof parsed.registries !== 'object' || Array.isArray(parsed.registries)) {
35
+ parsed.registries = {};
36
+ }
37
+ if (!Object.prototype.hasOwnProperty.call(parsed.registries, OFFICIAL_ENV_NAME)) {
38
+ parsed.registries[OFFICIAL_ENV_NAME] = { ...DEFAULT_OFFICIAL_ENV };
39
+ }
40
+ const official = parsed.registries[OFFICIAL_ENV_NAME];
41
+ if (
42
+ !official
43
+ || typeof official !== 'object'
44
+ || Array.isArray(official)
45
+ || !TRUSTED_OFFICIAL_BASE_URLS.has(official.ANTHROPIC_BASE_URL)
46
+ ) {
47
+ throw new Error('protected official environment has an untrusted endpoint');
48
+ }
49
+ return `${JSON.stringify(parsed, null, 2)}\n`;
50
+ }
51
+
18
52
  function migrate() {
19
53
  // 如果新配置已存在,跳过迁移
20
54
  if (fs.existsSync(newConfigPath)) {
@@ -29,11 +63,13 @@ function migrate() {
29
63
  try {
30
64
  // 确保新目录存在
31
65
  if (!fs.existsSync(newConfigDir)) {
32
- fs.mkdirSync(newConfigDir, { recursive: true });
66
+ fs.mkdirSync(newConfigDir, { recursive: true, mode: 0o700 });
33
67
  }
68
+ if (process.platform !== 'win32') fs.chmodSync(newConfigDir, 0o700);
34
69
 
35
- // 复制配置文件
36
- fs.copyFileSync(legacyConfigPath, newConfigPath);
70
+ // Validate the protected environment before creating the destination.
71
+ const migrated = prepareMigratedConfig(fs.readFileSync(legacyConfigPath, 'utf-8'));
72
+ fs.writeFileSync(newConfigPath, migrated, { flag: 'wx', mode: 0o600 });
37
73
  console.log('CCEM: 配置已迁移到 ~/.ccem/');
38
74
  } catch (err) {
39
75
  // 静默失败,不阻塞安装