@adversity/coding-tool-x 2.4.1 → 2.4.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.
@@ -611,51 +611,72 @@ function removeProjectFromWorkspace(workspaceId, projectName, removeWorktrees =
611
611
 
612
612
  /**
613
613
  * 获取所有渠道(Claude/Codex/Gemini)的项目并集
614
- * @returns {Array} 去重后的项目列表
614
+ * @returns {Promise<Array>} 去重后的项目列表
615
615
  */
616
- function getAllAvailableProjects() {
617
- const { NATIVE_PATHS } = require('../../config/paths');
616
+ async function getAllAvailableProjects() {
617
+ const { loadConfig } = require('../../config/loader');
618
618
  const sessionsService = require('./sessions');
619
+ const codexSessionsService = require('./codex-sessions');
620
+ const geminiSessionsService = require('./gemini-sessions');
621
+ const { isCodexInstalled } = require('./codex-config');
622
+ const { isGeminiInstalled } = require('./gemini-config');
619
623
 
620
624
  const allProjects = [];
621
- const seenPaths = new Set();
625
+ const seenKeys = new Set();
626
+
627
+ function addProject(channel, project) {
628
+ if (!project || !project.name) return;
629
+
630
+ const projectPath = project.fullPath || project.path || null;
631
+ const keyBase = projectPath || project.name;
632
+ const projectKey = `${channel}:${keyBase}`;
633
+ if (seenKeys.has(projectKey)) return;
634
+ seenKeys.add(projectKey);
635
+
636
+ const displayName = project.displayName || (projectPath ? path.basename(projectPath) : project.name);
637
+ const lastUsedValue = project.lastUsed || project.lastUpdated || null;
638
+ const lastUsed = typeof lastUsedValue === 'string'
639
+ ? new Date(lastUsedValue).getTime()
640
+ : (lastUsedValue || 0);
641
+
642
+ allProjects.push({
643
+ name: project.name,
644
+ displayName,
645
+ fullPath: projectPath || project.name,
646
+ channel,
647
+ sessionCount: project.sessionCount || 0,
648
+ lastUsed,
649
+ isGitRepo: projectPath ? isGitRepo(projectPath) : false
650
+ });
651
+ }
622
652
 
623
- // 定义渠道配置
624
- const channels = [
625
- { name: 'claude', projectsDir: NATIVE_PATHS.claude.projects },
626
- { name: 'codex', projectsDir: NATIVE_PATHS.codex.sessions },
627
- { name: 'gemini', projectsDir: NATIVE_PATHS.gemini.tmp }
628
- ];
653
+ try {
654
+ const config = loadConfig();
655
+ const claudeProjects = await sessionsService.getProjectsWithStats(config, { force: true });
656
+ const list = Array.isArray(claudeProjects) ? claudeProjects : [];
657
+ list.forEach(project => addProject('claude', project));
658
+ } catch (error) {
659
+ console.error('获取 claude 项目失败:', error.message);
660
+ }
629
661
 
630
- for (const channel of channels) {
631
- try {
632
- if (!fs.existsSync(channel.projectsDir)) {
633
- continue;
634
- }
662
+ try {
663
+ if (isCodexInstalled()) {
664
+ const codexProjects = codexSessionsService.getProjects();
665
+ const list = Array.isArray(codexProjects) ? codexProjects : [];
666
+ list.forEach(project => addProject('codex', project));
667
+ }
668
+ } catch (error) {
669
+ console.error('获取 codex 项目失败:', error.message);
670
+ }
635
671
 
636
- const config = { projectsDir: channel.projectsDir };
637
- const projects = sessionsService.getProjectsWithStats(config, { force: true });
638
-
639
- for (const proj of projects) {
640
- // 使用 fullPath + channel 组合去重,允许同一项目在不同渠道显示
641
- const projectPath = proj.fullPath;
642
- const projectKey = `${projectPath}:${channel.name}`;
643
- if (projectPath && !seenPaths.has(projectKey)) {
644
- seenPaths.add(projectKey);
645
- allProjects.push({
646
- name: proj.name,
647
- displayName: proj.displayName,
648
- fullPath: projectPath,
649
- channel: channel.name,
650
- sessionCount: proj.sessionCount || 0,
651
- lastUsed: proj.lastUsed,
652
- isGitRepo: isGitRepo(projectPath)
653
- });
654
- }
655
- }
656
- } catch (error) {
657
- console.error(`获取 ${channel.name} 项目失败:`, error.message);
672
+ try {
673
+ if (isGeminiInstalled()) {
674
+ const geminiProjects = geminiSessionsService.getProjects();
675
+ const list = Array.isArray(geminiProjects) ? geminiProjects : [];
676
+ list.forEach(project => addProject('gemini', project));
658
677
  }
678
+ } catch (error) {
679
+ console.error('获取 gemini 项目失败:', error.message);
659
680
  }
660
681
 
661
682
  // 按最后使用时间排序