coding-tool-x 3.3.7 → 3.3.8

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 (48) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/dist/web/assets/{Analytics-IW6eAy9u.js → Analytics-DLpoDZ2M.js} +1 -1
  3. package/dist/web/assets/{ConfigTemplates-BPtkTMSc.js → ConfigTemplates-D_hRb55W.js} +1 -1
  4. package/dist/web/assets/Home-BMoFdAwy.css +1 -0
  5. package/dist/web/assets/Home-DNwp-0J-.js +1 -0
  6. package/dist/web/assets/{PluginManager-BGx9MSDV.js → PluginManager-JXsyym1s.js} +1 -1
  7. package/dist/web/assets/{ProjectList-BCn-mrCx.js → ProjectList-DZWSeb-q.js} +1 -1
  8. package/dist/web/assets/{SessionList-CzLfebJQ.js → SessionList-Cs624DR3.js} +1 -1
  9. package/dist/web/assets/{SkillManager-CXz2vBQx.js → SkillManager-bEliz7qz.js} +1 -1
  10. package/dist/web/assets/{WorkspaceManager-CHtgMfKc.js → WorkspaceManager-J3RecFGn.js} +1 -1
  11. package/dist/web/assets/{icons-B29onFfZ.js → icons-Cuc23WS7.js} +1 -1
  12. package/dist/web/assets/index-BXeSvAwU.js +2 -0
  13. package/dist/web/assets/index-DWAC3Tdv.css +1 -0
  14. package/dist/web/index.html +3 -3
  15. package/package.json +3 -2
  16. package/src/commands/toggle-proxy.js +100 -5
  17. package/src/config/paths.js +102 -19
  18. package/src/server/api/channels.js +9 -0
  19. package/src/server/api/codex-channels.js +9 -0
  20. package/src/server/api/codex-proxy.js +22 -11
  21. package/src/server/api/gemini-proxy.js +22 -11
  22. package/src/server/api/oauth-credentials.js +163 -0
  23. package/src/server/api/opencode-proxy.js +22 -10
  24. package/src/server/api/plugins.js +3 -1
  25. package/src/server/api/proxy.js +39 -44
  26. package/src/server/api/skills.js +91 -13
  27. package/src/server/codex-proxy-server.js +1 -11
  28. package/src/server/index.js +1 -0
  29. package/src/server/services/channels.js +18 -22
  30. package/src/server/services/codex-channels.js +124 -175
  31. package/src/server/services/codex-config.js +2 -5
  32. package/src/server/services/codex-settings-manager.js +12 -348
  33. package/src/server/services/config-export-service.js +23 -2
  34. package/src/server/services/gemini-channels.js +11 -9
  35. package/src/server/services/mcp-service.js +33 -16
  36. package/src/server/services/native-keychain.js +243 -0
  37. package/src/server/services/native-oauth-adapters.js +890 -0
  38. package/src/server/services/oauth-credentials-service.js +786 -0
  39. package/src/server/services/oauth-utils.js +49 -0
  40. package/src/server/services/opencode-channels.js +13 -9
  41. package/src/server/services/opencode-settings-manager.js +169 -16
  42. package/src/server/services/plugins-service.js +22 -1
  43. package/src/server/services/settings-manager.js +13 -0
  44. package/src/server/services/skill-service.js +712 -332
  45. package/dist/web/assets/Home-BsSioaaB.css +0 -1
  46. package/dist/web/assets/Home-obifg_9E.js +0 -1
  47. package/dist/web/assets/index-C7LPdVsN.js +0 -2
  48. package/dist/web/assets/index-eEmjZKWP.css +0 -1
@@ -4,6 +4,7 @@ const { startProxyServer, stopProxyServer, getProxyStatus } = require('../proxy-
4
4
  const {
5
5
  setProxyConfig,
6
6
  restoreSettings,
7
+ deleteBackup,
7
8
  isProxyConfig,
8
9
  getCurrentProxyPort,
9
10
  settingsExists,
@@ -11,6 +12,7 @@ const {
11
12
  readSettings
12
13
  } = require('../services/settings-manager');
13
14
  const { getAllChannels } = require('../services/channels');
15
+ const { clearNativeOAuth } = require('../services/native-oauth-adapters');
14
16
  const { clearAllLogs } = require('../websocket-server');
15
17
  const { PATHS, NATIVE_PATHS, ensureStorageDirMigrated } = require('../../config/paths');
16
18
  const fs = require('fs');
@@ -37,6 +39,24 @@ function selectLatestEnabledChannel(channels) {
37
39
  }, enabledChannels[0]);
38
40
  }
39
41
 
42
+ function resolveActiveChannel(channels, activeChannelId = null) {
43
+ if (!Array.isArray(channels) || channels.length === 0) {
44
+ return null;
45
+ }
46
+
47
+ if (activeChannelId) {
48
+ const matched = channels.find(channel => channel.id === activeChannelId);
49
+ if (matched) {
50
+ return matched;
51
+ }
52
+ }
53
+
54
+ return selectLatestEnabledChannel(channels)
55
+ || channels.find(channel => channel.enabled !== false)
56
+ || channels[0]
57
+ || null;
58
+ }
59
+
40
60
  // 保存激活渠道ID
41
61
  function saveActiveChannelId(channelId) {
42
62
  ensureStorageDirMigrated();
@@ -70,11 +90,14 @@ function findActiveChannelFromSettings() {
70
90
  try {
71
91
  const settings = readSettings();
72
92
  const baseUrl = settings?.env?.ANTHROPIC_BASE_URL || '';
93
+ const { readNativeOAuth } = require('../services/native-oauth-adapters');
94
+ const nativeOAuth = readNativeOAuth('claude');
73
95
 
74
96
  // 兼容多种 API Key 格式(与 channels.js 保持一致)
75
- let apiKey = settings?.env?.ANTHROPIC_API_KEY || // 标准格式
76
- settings?.env?.ANTHROPIC_AUTH_TOKEN || // 88code等平台格式
77
- '';
97
+ let apiKey = settings?.env?.ANTHROPIC_API_KEY || '';
98
+ if (!apiKey && !nativeOAuth) {
99
+ apiKey = settings?.env?.ANTHROPIC_AUTH_TOKEN || '';
100
+ }
78
101
 
79
102
  // 如果 apiKey 仍为空,尝试从 apiKeyHelper 提取
80
103
  if (!apiKey && settings?.apiKeyHelper) {
@@ -195,6 +218,7 @@ router.post('/start', async (req, res) => {
195
218
  }
196
219
 
197
220
  // 5. 设置代理配置(备份并修改 settings.json)
221
+ clearNativeOAuth('claude');
198
222
  setProxyConfig(proxyResult.port);
199
223
 
200
224
  const updatedStatus = getProxyStatus();
@@ -221,57 +245,28 @@ router.post('/start', async (req, res) => {
221
245
  router.post('/stop', async (req, res) => {
222
246
  try {
223
247
  const channelsBeforeStop = getAllChannels();
224
- const latestEnabledChannel = selectLatestEnabledChannel(channelsBeforeStop);
248
+ const activeChannelId = loadActiveChannelId();
249
+ let restoredChannel = resolveActiveChannel(channelsBeforeStop, activeChannelId);
225
250
 
226
251
  // 1. 停止代理服务器
227
252
  const proxyResult = await stopProxyServer();
228
- const activeChannelId = loadActiveChannelId();
229
-
230
- // 2. 恢复配置(优先从备份,否则选择权重最高的启用渠道)
231
- let restoredChannel = null;
253
+ const hadBackup = hasBackup();
232
254
 
233
- // 优先尝试从备份恢复
234
- if (hasBackup()) {
255
+ // 2. 恢复配置(优先恢复当前活动渠道,避免覆盖动态切换期间的设置变更)
256
+ if (restoredChannel) {
257
+ if (hadBackup) {
258
+ deleteBackup();
259
+ console.log('✅ Discarded backup snapshot');
260
+ }
261
+ } else if (hadBackup) {
235
262
  restoreSettings();
236
263
  console.log('✅ Restored settings from backup');
237
-
238
- // 尝试找到匹配的渠道
239
264
  const channels = getAllChannels();
240
265
  const currentSettings = require('../services/channels').getCurrentSettings();
241
266
  if (currentSettings) {
242
267
  restoredChannel = channels.find(ch =>
243
268
  ch.baseUrl === currentSettings.baseUrl && ch.apiKey === currentSettings.apiKey
244
- );
245
- }
246
- // Fallback: keep latest enabled channel when leaving dynamic switching mode
247
- if (!restoredChannel && latestEnabledChannel) {
248
- restoredChannel = channels.find(ch => ch.id === latestEnabledChannel.id) || latestEnabledChannel;
249
- }
250
- // Fallback: use previously active channel id
251
- if (!restoredChannel && activeChannelId) {
252
- restoredChannel = channels.find(ch => ch.id === activeChannelId);
253
- }
254
- // Fallback: use first enabled channel
255
- if (!restoredChannel) {
256
- restoredChannel = channels.find(ch => ch.enabled !== false) || channels[0];
257
- }
258
- } else {
259
- // 没有备份,选择权重最高的启用渠道
260
- const { getBestChannelForRestore, updateClaudeSettings } = require('../services/channels');
261
- const channels = getAllChannels();
262
- restoredChannel = latestEnabledChannel
263
- ? channels.find(ch => ch.id === latestEnabledChannel.id)
264
- : null;
265
- if (!restoredChannel && activeChannelId) {
266
- restoredChannel = channels.find(ch => ch.id === activeChannelId);
267
- }
268
- if (!restoredChannel) {
269
- restoredChannel = getBestChannelForRestore();
270
- }
271
-
272
- if (restoredChannel) {
273
- updateClaudeSettings(restoredChannel.baseUrl, restoredChannel.apiKey);
274
- console.log(`✅ Restored settings to best channel: ${restoredChannel.name}`);
269
+ ) || null;
275
270
  }
276
271
  }
277
272
 
@@ -283,7 +278,7 @@ router.post('/stop', async (req, res) => {
283
278
  }
284
279
 
285
280
  // 3. 删除备份文件和active-channel.json
286
- if (hasBackup()) {
281
+ if (hadBackup && !restoredChannel) {
287
282
  const backupPath = NATIVE_PATHS.claude.settingsBackup;
288
283
  if (fs.existsSync(backupPath)) {
289
284
  fs.unlinkSync(backupPath);
@@ -25,6 +25,22 @@ function getSkillService(req) {
25
25
  return { platform, service: skillServices.get(platform) };
26
26
  }
27
27
 
28
+ function extractRepoPayload(source = {}) {
29
+ const repo = source.repo && typeof source.repo === 'object' ? source.repo : source;
30
+ return {
31
+ id: repo.id || source.repoId || '',
32
+ provider: repo.provider || source.provider || '',
33
+ host: repo.host || source.host || '',
34
+ owner: repo.owner || source.owner || '',
35
+ name: repo.name || source.name || '',
36
+ branch: repo.branch || source.branch || 'main',
37
+ directory: repo.directory || source.directory || '',
38
+ projectPath: repo.projectPath || source.projectPath || '',
39
+ localPath: repo.localPath || source.localPath || '',
40
+ repoUrl: repo.repoUrl || source.repoUrl || ''
41
+ };
42
+ }
43
+
28
44
  /**
29
45
  * 获取技能列表
30
46
  * GET /api/skills
@@ -66,7 +82,9 @@ router.get('/detail/*', async (req, res) => {
66
82
  });
67
83
  }
68
84
 
69
- const result = await service.getSkillDetail(directory);
85
+ const repoHint = extractRepoPayload(req.query || {});
86
+ const hasRepoHint = Object.values(repoHint).some(Boolean);
87
+ const result = await service.getSkillDetail(directory, hasRepoHint ? repoHint : null, req.query.fullDirectory || '');
70
88
  res.json({
71
89
  success: true,
72
90
  platform,
@@ -106,7 +124,7 @@ router.get('/installed', (req, res) => {
106
124
  /**
107
125
  * 安装技能
108
126
  * POST /api/skills/install
109
- * Body: { directory, fullDirectory, repo: { owner, name, branch } }
127
+ * Body: { directory, fullDirectory, repo }
110
128
  * - directory: 本地安装目录(相对路径)
111
129
  * - fullDirectory: 仓库中的完整路径(当指定了仓库子目录时使用)
112
130
  */
@@ -122,7 +140,7 @@ router.post('/install', async (req, res) => {
122
140
  });
123
141
  }
124
142
 
125
- if (!repo || !repo.owner || !repo.name) {
143
+ if (!repo) {
126
144
  return res.status(400).json({
127
145
  success: false,
128
146
  message: 'Missing repo info'
@@ -131,11 +149,7 @@ router.post('/install', async (req, res) => {
131
149
 
132
150
  const result = await service.installSkill(
133
151
  directory,
134
- {
135
- owner: repo.owner,
136
- name: repo.name,
137
- branch: repo.branch || 'main'
138
- },
152
+ extractRepoPayload({ repo }),
139
153
  fullDirectory || null // 传递 fullDirectory 用于从仓库子目录下载
140
154
  );
141
155
 
@@ -153,6 +167,28 @@ router.post('/install', async (req, res) => {
153
167
  }
154
168
  });
155
169
 
170
+ /**
171
+ * 安装本地 cc-tool 托管的技能
172
+ * POST /api/skills/install-local
173
+ * Body: { directory }
174
+ */
175
+ router.post('/install-local', (req, res) => {
176
+ try {
177
+ const { platform, service } = getSkillService(req);
178
+ const { directory } = req.body;
179
+
180
+ if (!directory) {
181
+ return res.status(400).json({ success: false, message: 'Missing directory' });
182
+ }
183
+
184
+ const result = service.installLocalSkill(directory);
185
+ res.json({ success: true, platform, ...result });
186
+ } catch (err) {
187
+ console.error('[Skills API] Install local skill error:', err);
188
+ res.status(500).json({ success: false, message: err.message });
189
+ }
190
+ });
191
+
156
192
  /**
157
193
  * 创建自定义技能
158
194
  * POST /api/skills/create
@@ -264,22 +300,23 @@ router.get('/repos', (req, res) => {
264
300
  /**
265
301
  * 添加仓库
266
302
  * POST /api/skills/repos
267
- * Body: { owner, name, branch, directory, enabled }
303
+ * Body: { provider, owner, name, host, projectPath, localPath, branch, directory, enabled }
268
304
  * - directory: 可选,指定扫描的子目录路径
269
305
  */
270
306
  router.post('/repos', (req, res) => {
271
307
  try {
272
308
  const { platform, service } = getSkillService(req);
273
- const { owner, name, branch = 'main', directory = '', enabled = true } = req.body;
309
+ const repo = extractRepoPayload(req.body);
310
+ repo.enabled = req.body.enabled !== false;
274
311
 
275
- if (!owner || !name) {
312
+ if (!repo.localPath && !repo.projectPath && (!repo.owner || !repo.name)) {
276
313
  return res.status(400).json({
277
314
  success: false,
278
- message: 'Missing owner or name'
315
+ message: 'Missing repo info'
279
316
  });
280
317
  }
281
318
 
282
- const repos = service.addRepo({ owner, name, branch, directory, enabled });
319
+ const repos = service.addRepo(repo);
283
320
 
284
321
  res.json({
285
322
  success: true,
@@ -295,6 +332,47 @@ router.post('/repos', (req, res) => {
295
332
  }
296
333
  });
297
334
 
335
+ router.delete('/repos', (req, res) => {
336
+ try {
337
+ const { platform, service } = getSkillService(req);
338
+ const { id = '', owner = '', name = '', directory = '' } = req.query;
339
+ const repos = service.removeRepo(owner, name, directory, id);
340
+
341
+ res.json({
342
+ success: true,
343
+ platform,
344
+ repos
345
+ });
346
+ } catch (err) {
347
+ console.error('[Skills API] Remove repo error:', err);
348
+ res.status(500).json({
349
+ success: false,
350
+ message: err.message
351
+ });
352
+ }
353
+ });
354
+
355
+ router.put('/repos/toggle', (req, res) => {
356
+ try {
357
+ const { platform, service } = getSkillService(req);
358
+ const { id = '', owner = '', name = '', enabled, directory = '' } = req.body;
359
+
360
+ const repos = service.toggleRepo(owner, name, directory, enabled, id);
361
+
362
+ res.json({
363
+ success: true,
364
+ platform,
365
+ repos
366
+ });
367
+ } catch (err) {
368
+ console.error('[Skills API] Toggle repo error:', err);
369
+ res.status(500).json({
370
+ success: false,
371
+ message: err.message
372
+ });
373
+ }
374
+ });
375
+
298
376
  /**
299
377
  * 删除仓库
300
378
  * DELETE /api/skills/repos/:owner/:name
@@ -11,7 +11,7 @@ const { resolveModelPricing } = require('./utils/pricing');
11
11
  const { recordRequest: recordCodexRequest } = require('./services/codex-statistics-service');
12
12
  const { saveProxyStartTime, clearProxyStartTime, getProxyStartTime, getProxyRuntime } = require('./services/proxy-runtime');
13
13
  const { createDecodedStream } = require('./services/response-decoder');
14
- const { getEnabledChannels, writeCodexConfigForMultiChannel, getEffectiveApiKey } = require('./services/codex-channels');
14
+ const { getEffectiveApiKey } = require('./services/codex-channels');
15
15
  const { persistProxyRequestSnapshot } = require('./services/request-logger');
16
16
 
17
17
  let proxyServer = null;
@@ -585,16 +585,6 @@ async function startCodexProxyServer(options = {}) {
585
585
  // 保存代理启动时间(如果是切换渠道,保留原有启动时间)
586
586
  saveProxyStartTime('codex', preserveStartTime);
587
587
 
588
- // 启动代理时同步配置到 Codex 的 config.toml
589
- try {
590
- const enabledChannels = getEnabledChannels();
591
- if (enabledChannels.length > 0) {
592
- writeCodexConfigForMultiChannel(enabledChannels);
593
- }
594
- } catch (err) {
595
- // ignore sync error
596
- }
597
-
598
588
  resolve({ success: true, port });
599
589
  });
600
590
 
@@ -217,6 +217,7 @@ async function startServer(port, host = '127.0.0.1', options = {}) {
217
217
 
218
218
  // 配置导出/导入 API
219
219
  app.use('/api/config-export', require('./api/config-export'));
220
+ app.use('/api/oauth-credentials', require('./api/oauth-credentials'));
220
221
 
221
222
  // 配置同步 API
222
223
  app.use('/api/config-sync', require('./api/config-sync'));
@@ -1,6 +1,7 @@
1
1
  const fs = require('fs');
2
2
  const { isProxyConfig } = require('./settings-manager');
3
3
  const { PATHS, NATIVE_PATHS } = require('../../config/paths');
4
+ const { clearNativeOAuth } = require('./native-oauth-adapters');
4
5
 
5
6
  function getChannelsFilePath() {
6
7
  const dir = PATHS.base;
@@ -165,11 +166,13 @@ function getCurrentSettings() {
165
166
  return null;
166
167
  }
167
168
  const settings = JSON.parse(fs.readFileSync(settingsPath, 'utf8'));
169
+ const nativeOAuth = require('./native-oauth-adapters').readNativeOAuth('claude');
168
170
 
169
171
  let baseUrl = settings.env?.ANTHROPIC_BASE_URL || '';
170
- let apiKey = settings.env?.ANTHROPIC_API_KEY ||
171
- settings.env?.ANTHROPIC_AUTH_TOKEN ||
172
- '';
172
+ let apiKey = settings.env?.ANTHROPIC_API_KEY || '';
173
+ if (!apiKey && !nativeOAuth) {
174
+ apiKey = settings.env?.ANTHROPIC_AUTH_TOKEN || '';
175
+ }
173
176
 
174
177
  if (!apiKey && settings.apiKeyHelper) {
175
178
  apiKey = extractApiKeyFromHelper(settings.apiKeyHelper);
@@ -288,14 +291,6 @@ function updateChannel(id, updates) {
288
291
  console.log(`[Single-channel mode] Enabled "${nextChannel.name}", disabled all others`);
289
292
  }
290
293
 
291
- // Prevent disabling last enabled channel when proxy is OFF
292
- if (!isProxyRunning && !nextChannel.enabled && oldChannel.enabled) {
293
- const enabledCount = data.channels.filter(ch => ch.enabled).length;
294
- if (enabledCount === 0) {
295
- throw new Error('无法禁用最后一个启用的渠道。请先启用其他渠道或启动动态切换。');
296
- }
297
- }
298
-
299
294
  saveChannels(data);
300
295
 
301
296
  // Sync settings.json only when proxy is OFF.
@@ -341,6 +336,7 @@ function applyChannelToSettings(id) {
341
336
  }
342
337
 
343
338
  function updateClaudeSettingsWithModelConfig(channel) {
339
+ clearNativeOAuth('claude');
344
340
  const settingsPath = getClaudeSettingsPath();
345
341
 
346
342
  let settings = {};
@@ -354,17 +350,10 @@ function updateClaudeSettingsWithModelConfig(channel) {
354
350
 
355
351
  const { baseUrl, apiKey, modelConfig, presetId, proxyUrl } = channel;
356
352
 
357
- const useAuthToken = settings.env.ANTHROPIC_AUTH_TOKEN !== undefined;
358
- const useApiKey = settings.env.ANTHROPIC_API_KEY !== undefined;
359
-
360
353
  settings.env.ANTHROPIC_BASE_URL = baseUrl;
361
-
362
- if (useAuthToken || (!useAuthToken && !useApiKey)) {
363
- settings.env.ANTHROPIC_AUTH_TOKEN = apiKey;
364
- delete settings.env.ANTHROPIC_API_KEY;
365
- } else {
366
- settings.env.ANTHROPIC_API_KEY = apiKey;
367
- }
354
+ settings.env.ANTHROPIC_API_KEY = apiKey;
355
+ delete settings.env.ANTHROPIC_AUTH_TOKEN;
356
+ delete settings.env.CLAUDE_CODE_OAUTH_TOKEN;
368
357
 
369
358
  if (presetId && presetId !== 'official' && modelConfig) {
370
359
  if (modelConfig.model) {
@@ -433,6 +422,12 @@ function getEffectiveApiKey(channel) {
433
422
  return channel.apiKey || null;
434
423
  }
435
424
 
425
+ function disableAllChannels() {
426
+ const data = loadChannels();
427
+ data.channels.forEach(ch => { ch.enabled = false; });
428
+ saveChannels(data);
429
+ }
430
+
436
431
  module.exports = {
437
432
  getAllChannels,
438
433
  getCurrentChannel,
@@ -444,5 +439,6 @@ module.exports = {
444
439
  getBestChannelForRestore,
445
440
  updateClaudeSettings,
446
441
  updateClaudeSettingsWithModelConfig,
447
- getEffectiveApiKey
442
+ getEffectiveApiKey,
443
+ disableAllChannels
448
444
  };