@mmmbuto/nexuscli 0.6.1 → 0.6.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.
|
@@ -147,6 +147,15 @@ class SessionManager {
|
|
|
147
147
|
return crypto.createHash('md5').update(workspacePath).digest('hex').substring(0, 8);
|
|
148
148
|
}
|
|
149
149
|
|
|
150
|
+
/**
|
|
151
|
+
* Normalize workspace path (remove trailing slashes)
|
|
152
|
+
* Prevents duplicate entries like /path and /path/
|
|
153
|
+
*/
|
|
154
|
+
_normalizePath(workspacePath) {
|
|
155
|
+
if (!workspacePath) return '';
|
|
156
|
+
return workspacePath.replace(/\/+$/, '');
|
|
157
|
+
}
|
|
158
|
+
|
|
150
159
|
/**
|
|
151
160
|
* Get or create session for conversation + engine
|
|
152
161
|
*
|
|
@@ -164,16 +173,17 @@ class SessionManager {
|
|
|
164
173
|
*/
|
|
165
174
|
async getOrCreateSession(conversationId, engine, workspacePath) {
|
|
166
175
|
const normalizedEngine = this._normalizeEngine(engine);
|
|
176
|
+
const normalizedPath = this._normalizePath(workspacePath);
|
|
167
177
|
const cacheKey = this._getCacheKey(conversationId, normalizedEngine);
|
|
168
178
|
|
|
169
|
-
console.log(`[SessionManager] getOrCreateSession(${conversationId}, ${normalizedEngine}, ${
|
|
179
|
+
console.log(`[SessionManager] getOrCreateSession(${conversationId}, ${normalizedEngine}, ${normalizedPath})`);
|
|
170
180
|
|
|
171
181
|
// 1. Check RAM cache first (fastest path)
|
|
172
182
|
if (this.sessionMap.has(cacheKey)) {
|
|
173
183
|
const cachedId = this.sessionMap.get(cacheKey);
|
|
174
184
|
|
|
175
185
|
// Verify it still exists on filesystem
|
|
176
|
-
if (this.sessionFileExists(cachedId, normalizedEngine,
|
|
186
|
+
if (this.sessionFileExists(cachedId, normalizedEngine, normalizedPath)) {
|
|
177
187
|
this.lastAccess.set(cacheKey, Date.now());
|
|
178
188
|
console.log(`[SessionManager] Cache hit: ${cachedId}`);
|
|
179
189
|
return { sessionId: cachedId, isNew: false };
|
|
@@ -195,7 +205,7 @@ class SessionManager {
|
|
|
195
205
|
|
|
196
206
|
if (row) {
|
|
197
207
|
// 3. Verify session file exists on filesystem
|
|
198
|
-
if (this.sessionFileExists(row.id, normalizedEngine, row.workspace_path ||
|
|
208
|
+
if (this.sessionFileExists(row.id, normalizedEngine, row.workspace_path || normalizedPath)) {
|
|
199
209
|
// Valid session - update cache and return
|
|
200
210
|
this.sessionMap.set(cacheKey, row.id);
|
|
201
211
|
this.lastAccess.set(cacheKey, Date.now());
|
|
@@ -223,7 +233,7 @@ class SessionManager {
|
|
|
223
233
|
VALUES (?, ?, ?, ?, ?, ?, ?)
|
|
224
234
|
`);
|
|
225
235
|
const title = 'New Chat'; // Will be updated after first response
|
|
226
|
-
insertStmt.run(sessionId,
|
|
236
|
+
insertStmt.run(sessionId, normalizedPath, normalizedEngine, conversationId, title, now, now);
|
|
227
237
|
saveDb();
|
|
228
238
|
console.log(`[SessionManager] Saved to DB: ${sessionId}`);
|
|
229
239
|
} catch (dbErr) {
|