mirror of
https://github.com/siteboon/claudecodeui.git
synced 2026-05-16 01:12:46 +00:00
refactor: rename session parser functions; move sessionData to a shared type
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import os from 'os';
|
||||
import path from 'path';
|
||||
import { sessionsDb } from '@/shared/database/repositories/sessions.db.js';
|
||||
import { buildLookupMap, extractFirstValidJsonlData, findFilesRecursivelyCreatedAfterLastScan, SessionData } from '@/modules/sessions/sessions.utils.js';
|
||||
import { buildLookupMap, extractFirstValidJsonlData, findFilesRecursivelyCreatedAfterLastScan } from '@/modules/providers/shared/session-parser.utils.js';
|
||||
import { SessionData } from '@/shared/types/session.js';
|
||||
|
||||
export async function processClaudeSessionFile(file: string, nameMap?: Map<string, string>): Promise<SessionData | null> {
|
||||
if (!nameMap) {
|
||||
@@ -17,7 +18,7 @@ export async function processClaudeSessionFile(file: string, nameMap?: Map<strin
|
||||
}));
|
||||
}
|
||||
|
||||
export async function getClaudeSessions() {
|
||||
export async function processClaudeSessions() {
|
||||
const base = path.join(os.homedir(), '.claude');
|
||||
// Pre-load names from history index
|
||||
const nameMap = await buildLookupMap(path.join(base, 'history.jsonl'), 'sessionId', 'display');
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import os from 'os';
|
||||
import path from 'path';
|
||||
import { sessionsDb } from '@/shared/database/repositories/sessions.db.js';
|
||||
import { buildLookupMap, extractFirstValidJsonlData, findFilesRecursivelyCreatedAfterLastScan, SessionData } from '@/modules/sessions/sessions.utils.js';
|
||||
import { buildLookupMap, extractFirstValidJsonlData, findFilesRecursivelyCreatedAfterLastScan } from '@/modules/providers/shared/session-parser.utils.js';
|
||||
import { SessionData } from '@/shared/types/session.js';
|
||||
|
||||
export async function processCodexSessionFile(file: string, nameMap?: Map<string, string>): Promise<SessionData | null> {
|
||||
if (!nameMap) {
|
||||
@@ -17,7 +18,7 @@ export async function processCodexSessionFile(file: string, nameMap?: Map<string
|
||||
}));
|
||||
}
|
||||
|
||||
export async function getCodexSessions() {
|
||||
export async function processCodexSessions() {
|
||||
const base = path.join(os.homedir(), '.codex');
|
||||
// Use the thread_name attribute as requested
|
||||
const nameMap = await buildLookupMap(path.join(base, 'session_index.jsonl'), 'id', 'thread_name');
|
||||
|
||||
@@ -5,7 +5,8 @@ import fsp from 'node:fs/promises';
|
||||
import readline from 'readline';
|
||||
import crypto from 'node:crypto';
|
||||
import { sessionsDb } from '@/shared/database/repositories/sessions.db.js';
|
||||
import { extractFirstValidJsonlData, findFilesRecursivelyCreatedAfterLastScan, SessionData } from '@/modules/sessions/sessions.utils.js';
|
||||
import { extractFirstValidJsonlData, findFilesRecursivelyCreatedAfterLastScan } from '@/modules/providers/shared/session-parser.utils.js';
|
||||
import { SessionData } from '@/shared/types/session.js';
|
||||
|
||||
function md5(input: string): string {
|
||||
return crypto.createHash('md5').update(input).digest('hex');
|
||||
@@ -56,7 +57,7 @@ export async function processCursorSessionFile(file: string): Promise<SessionDat
|
||||
});
|
||||
}
|
||||
|
||||
export async function getCursorSessions() {
|
||||
export async function processCursorSessions() {
|
||||
try {
|
||||
const cursorBase = path.join(os.homedir(), '.cursor');
|
||||
const projectsDir = path.join(cursorBase, 'projects');
|
||||
|
||||
@@ -2,7 +2,8 @@ import os from 'os';
|
||||
import path from 'path';
|
||||
import fsp from 'node:fs/promises';
|
||||
import { sessionsDb } from '@/shared/database/repositories/sessions.db.js';
|
||||
import { findFilesRecursivelyCreatedAfterLastScan, SessionData } from '@/modules/sessions/sessions.utils.js';
|
||||
import { findFilesRecursivelyCreatedAfterLastScan } from '@/modules/providers/shared/session-parser.utils.js';
|
||||
import { SessionData } from '@/shared/types/session.js';
|
||||
|
||||
export async function processGeminiSessionFile(file: string): Promise<SessionData | null> {
|
||||
try {
|
||||
@@ -23,7 +24,7 @@ export async function processGeminiSessionFile(file: string): Promise<SessionDat
|
||||
return null;
|
||||
}
|
||||
|
||||
export async function getGeminiSessions() {
|
||||
export async function processGeminiSessions() {
|
||||
const geminiPath = path.join(os.homedir(), '.gemini', 'sessions');
|
||||
const files = await findFilesRecursivelyCreatedAfterLastScan(geminiPath, '.json');
|
||||
|
||||
|
||||
@@ -3,16 +3,7 @@ import fsp from 'node:fs/promises';
|
||||
import readline from 'readline';
|
||||
import path from 'path';
|
||||
import { scanStateDb } from '@/shared/database/repositories/scan-state.db.js';
|
||||
|
||||
// ============================================================================
|
||||
// SHARED TYPES & UTILITIES
|
||||
// ============================================================================
|
||||
|
||||
export type SessionData = {
|
||||
sessionId: string;
|
||||
workspacePath: string;
|
||||
sessionName?: string;
|
||||
}
|
||||
import { SessionData } from '@/shared/types/session.js';
|
||||
|
||||
/**
|
||||
* Reads a JSONL file and builds a Map of Key -> Value.
|
||||
@@ -39,7 +30,7 @@ export async function buildLookupMap(filePath: string, keyField: string, valueFi
|
||||
/**
|
||||
* Recursively walks a directory tree and returns a flat array of all files
|
||||
* matching a specific extension (e.g., '.jsonl' or '.json').
|
||||
* It will only find the files created after the last scan date.
|
||||
* It will only find the files created after
|
||||
*/
|
||||
export async function findFilesRecursivelyCreatedAfterLastScan(
|
||||
dirPath: string,
|
||||
@@ -61,6 +52,7 @@ export async function findFilesRecursivelyCreatedAfterLastScan(
|
||||
const stats = await fsp.stat(fullPath);
|
||||
if (stats.birthtime > lastScanDate) {
|
||||
fileList.push(fullPath);
|
||||
console.log("=====> full path is: ", fullPath)
|
||||
}
|
||||
} else {
|
||||
fileList.push(fullPath);
|
||||
@@ -1,10 +1,10 @@
|
||||
import { scanStateDb } from '@/shared/database/repositories/scan-state.db.js';
|
||||
import { getClaudeSessions } from '@/modules/providers/claude/claude.session-parser.js';
|
||||
import { getCodexSessions } from '@/modules/providers/codex/codex.session-parser.js';
|
||||
import { getGeminiSessions } from '@/modules/providers/gemini/gemini.session-parser.js';
|
||||
import { getCursorSessions } from '@/modules/providers/cursor/cursor.session-parser.js';
|
||||
import { processClaudeSessions } from '@/modules/providers/claude/claude.session-parser.js';
|
||||
import { processCodexSessions } from '@/modules/providers/codex/codex.session-parser.js';
|
||||
import { processGeminiSessions } from '@/modules/providers/gemini/gemini.session-parser.js';
|
||||
import { processCursorSessions } from '@/modules/providers/cursor/cursor.session-parser.js';
|
||||
|
||||
export async function getSessions() {
|
||||
export async function processSessions() {
|
||||
|
||||
// 1. Start the timer with a unique label
|
||||
console.time("🚀 Workspace sync total time");
|
||||
@@ -13,10 +13,10 @@ export async function getSessions() {
|
||||
try {
|
||||
// Wrapping in Promise.all allows these to process concurrently, speeding up the boot time
|
||||
await Promise.allSettled([
|
||||
getClaudeSessions(),
|
||||
getCodexSessions(),
|
||||
getGeminiSessions(),
|
||||
getCursorSessions()
|
||||
processClaudeSessions(),
|
||||
processCodexSessions(),
|
||||
processGeminiSessions(),
|
||||
processCursorSessions()
|
||||
]);
|
||||
|
||||
scanStateDb.updateLastScannedAt();
|
||||
|
||||
@@ -3,7 +3,7 @@ import path from "path";
|
||||
import os from "os";
|
||||
import { promises as fsPromises } from "fs";
|
||||
import { logger } from "@/shared/utils/logger.js";
|
||||
import { getSessions } from "@/modules/sessions/sessions.service.js";
|
||||
import { processSessions } from "@/modules/sessions/sessions.service.js";
|
||||
import { processClaudeSessionFile } from "@/modules/providers/claude/claude.session-parser.js";
|
||||
import { processCodexSessionFile } from "@/modules/providers/codex/codex.session-parser.js";
|
||||
import { processGeminiSessionFile } from "@/modules/providers/gemini/gemini.session-parser.js";
|
||||
@@ -117,7 +117,7 @@ const onUpdate = async (
|
||||
export async function initializeWatcher() {
|
||||
logger.info("Setting up project watchers for providers...");
|
||||
|
||||
await getSessions();
|
||||
await processSessions();
|
||||
|
||||
for (const { provider, rootPath } of PROVIDER_WATCH_PATHS) {
|
||||
try {
|
||||
|
||||
@@ -2,4 +2,4 @@ export type SessionData = {
|
||||
sessionId: string;
|
||||
workspacePath: string;
|
||||
sessionName?: string;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user