coding-tool-x 3.8.0 → 3.8.1

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.
@@ -0,0 +1,78 @@
1
+ 'use strict';
2
+
3
+ const { DatabaseSync } = require('node:sqlite');
4
+ const fs = require('fs');
5
+ const path = require('path');
6
+
7
+ /** @type {Map<string, DatabaseSync>} */
8
+ const _connections = new Map();
9
+
10
+ /**
11
+ * Canonicalize a file path for use as a connection key.
12
+ * @param {string} filePath
13
+ * @returns {string}
14
+ */
15
+ function _canonicalize(filePath) {
16
+ return path.resolve(filePath);
17
+ }
18
+
19
+ /**
20
+ * Open or return an existing DatabaseSync connection for `filePath`.
21
+ *
22
+ * @param {string} filePath - path to the SQLite database file
23
+ * @param {{ readOnly?: boolean, timeout?: number }} [options]
24
+ * @returns {DatabaseSync}
25
+ */
26
+ function openDatabase(filePath, options = {}) {
27
+ const key = _canonicalize(filePath);
28
+ if (_connections.has(key)) {
29
+ return _connections.get(key);
30
+ }
31
+
32
+ if (!options.readOnly) {
33
+ fs.mkdirSync(path.dirname(key), { recursive: true });
34
+ }
35
+
36
+ const db = new DatabaseSync(key, {
37
+ readOnly: options.readOnly === true,
38
+ timeout: options.timeout != null ? options.timeout : 5000
39
+ });
40
+
41
+ if (!options.readOnly) {
42
+ db.exec('PRAGMA foreign_keys = ON');
43
+ }
44
+
45
+ _connections.set(key, db);
46
+ return db;
47
+ }
48
+
49
+ /**
50
+ * Close and remove the cached connection for `filePath`. Idempotent.
51
+ *
52
+ * @param {string} filePath
53
+ */
54
+ function closeDatabase(filePath) {
55
+ const key = _canonicalize(filePath);
56
+ const db = _connections.get(key);
57
+ if (!db) {
58
+ return;
59
+ }
60
+ db.close();
61
+ _connections.delete(key);
62
+ }
63
+
64
+ /**
65
+ * Close and remove every cached connection. Idempotent.
66
+ */
67
+ function closeAllDatabases() {
68
+ for (const db of _connections.values()) {
69
+ try {
70
+ db.close();
71
+ } catch (_err) {
72
+ // swallow — best-effort teardown
73
+ }
74
+ }
75
+ _connections.clear();
76
+ }
77
+
78
+ module.exports = { openDatabase, closeDatabase, closeAllDatabases };
@@ -781,7 +781,7 @@ async function getAllAvailableProjects() {
781
781
 
782
782
  try {
783
783
  if (isCodexInstalled()) {
784
- const codexProjects = codexSessionsService.getProjects();
784
+ const codexProjects = await codexSessionsService.getProjects();
785
785
  const list = Array.isArray(codexProjects) ? codexProjects : [];
786
786
  list.forEach(project => addProject('codex', project));
787
787
  }
@@ -791,7 +791,7 @@ async function getAllAvailableProjects() {
791
791
 
792
792
  try {
793
793
  if (isGeminiInstalled()) {
794
- const geminiProjects = geminiSessionsService.getProjects();
794
+ const geminiProjects = await geminiSessionsService.getProjects();
795
795
  const list = Array.isArray(geminiProjects) ? geminiProjects : [];
796
796
  list.forEach(project => addProject('gemini', project));
797
797
  }
@@ -810,7 +810,7 @@ async function getAllAvailableProjects() {
810
810
  }
811
811
 
812
812
  try {
813
- const ompProjects = ompSessionsService.getProjects();
813
+ const ompProjects = await ompSessionsService.getProjects();
814
814
  const list = Array.isArray(ompProjects) ? ompProjects : [];
815
815
  if (list.length > 0 || ompSessionsService.isOmpInstalled()) {
816
816
  list.forEach(project => addProject('omp', project));