mirror of
https://github.com/siteboon/claudecodeui.git
synced 2026-05-16 17:16:19 +00:00
Compare commits
1 Commits
feature/se
...
fix/regex-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5ad2876cd2 |
@@ -157,11 +157,7 @@ export default tseslint.config(
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: "backend-shared-utils", // shared backend runtime helpers that modules may import directly
|
type: "backend-shared-utils", // shared backend runtime helpers that modules may import directly
|
||||||
pattern: [
|
pattern: ["server/shared/utils.{js,ts}", "server/shared/claude-cli-path.ts"], // classify the shared utils file so modules can depend on it explicitly
|
||||||
"server/shared/utils.{js,ts}",
|
|
||||||
"server/shared/frontmatter.ts",
|
|
||||||
"server/shared/claude-cli-path.ts",
|
|
||||||
], // classify shared utility files so modules can depend on them explicitly
|
|
||||||
mode: "file",
|
mode: "file",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -150,6 +150,7 @@ async function spawnCursor(command, options = {}, ws) {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const response = JSON.parse(line);
|
const response = JSON.parse(line);
|
||||||
|
console.log('Parsed JSON response:', response);
|
||||||
|
|
||||||
// Handle different message types
|
// Handle different message types
|
||||||
switch (response.type) {
|
switch (response.type) {
|
||||||
@@ -158,6 +159,7 @@ async function spawnCursor(command, options = {}, ws) {
|
|||||||
// Capture session ID
|
// Capture session ID
|
||||||
if (response.session_id && !capturedSessionId) {
|
if (response.session_id && !capturedSessionId) {
|
||||||
capturedSessionId = response.session_id;
|
capturedSessionId = response.session_id;
|
||||||
|
console.log('Captured session ID:', capturedSessionId);
|
||||||
|
|
||||||
// Update process key with captured session ID
|
// Update process key with captured session ID
|
||||||
if (processKey !== capturedSessionId) {
|
if (processKey !== capturedSessionId) {
|
||||||
@@ -195,6 +197,7 @@ async function spawnCursor(command, options = {}, ws) {
|
|||||||
|
|
||||||
case 'result': {
|
case 'result': {
|
||||||
// Session complete — send stream end + lifecycle complete with result payload
|
// Session complete — send stream end + lifecycle complete with result payload
|
||||||
|
console.log('Cursor session result:', response);
|
||||||
const resultText = typeof response.result === 'string' ? response.result : '';
|
const resultText = typeof response.result === 'string' ? response.result : '';
|
||||||
ws.send(createNormalizedMessage({
|
ws.send(createNormalizedMessage({
|
||||||
kind: 'complete',
|
kind: 'complete',
|
||||||
@@ -210,6 +213,8 @@ async function spawnCursor(command, options = {}, ws) {
|
|||||||
// Unknown message types — ignore.
|
// Unknown message types — ignore.
|
||||||
}
|
}
|
||||||
} catch (parseError) {
|
} catch (parseError) {
|
||||||
|
console.log('Non-JSON response:', line);
|
||||||
|
|
||||||
if (shouldSuppressForTrustRetry(line)) {
|
if (shouldSuppressForTrustRetry(line)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -223,6 +228,7 @@ async function spawnCursor(command, options = {}, ws) {
|
|||||||
// Handle stdout (streaming JSON responses)
|
// Handle stdout (streaming JSON responses)
|
||||||
cursorProcess.stdout.on('data', (data) => {
|
cursorProcess.stdout.on('data', (data) => {
|
||||||
const rawOutput = data.toString();
|
const rawOutput = data.toString();
|
||||||
|
console.log('Cursor CLI stdout:', rawOutput);
|
||||||
|
|
||||||
// Stream chunks can split JSON objects across packets; keep trailing partial line.
|
// Stream chunks can split JSON objects across packets; keep trailing partial line.
|
||||||
stdoutLineBuffer += rawOutput;
|
stdoutLineBuffer += rawOutput;
|
||||||
@@ -248,6 +254,8 @@ async function spawnCursor(command, options = {}, ws) {
|
|||||||
|
|
||||||
// Handle process completion
|
// Handle process completion
|
||||||
cursorProcess.on('close', async (code) => {
|
cursorProcess.on('close', async (code) => {
|
||||||
|
console.log(`Cursor CLI process exited with code ${code}`);
|
||||||
|
|
||||||
const finalSessionId = capturedSessionId || sessionId || processKey;
|
const finalSessionId = capturedSessionId || sessionId || processKey;
|
||||||
activeCursorProcesses.delete(finalSessionId);
|
activeCursorProcesses.delete(finalSessionId);
|
||||||
|
|
||||||
|
|||||||
@@ -1,123 +1,19 @@
|
|||||||
import { spawn } from 'child_process';
|
import { spawn } from 'child_process';
|
||||||
import { promises as fs } from 'fs';
|
|
||||||
import os from 'os';
|
|
||||||
import path from 'path';
|
|
||||||
|
|
||||||
import crossSpawn from 'cross-spawn';
|
import crossSpawn from 'cross-spawn';
|
||||||
|
|
||||||
|
// Use cross-spawn on Windows for correct .cmd resolution (same pattern as cursor-cli.js)
|
||||||
|
const spawnFunction = process.platform === 'win32' ? crossSpawn : spawn;
|
||||||
|
import { promises as fs } from 'fs';
|
||||||
|
import path from 'path';
|
||||||
|
import os from 'os';
|
||||||
import sessionManager from './sessionManager.js';
|
import sessionManager from './sessionManager.js';
|
||||||
import GeminiResponseHandler from './gemini-response-handler.js';
|
import GeminiResponseHandler from './gemini-response-handler.js';
|
||||||
import { notifyRunFailed, notifyRunStopped } from './services/notification-orchestrator.js';
|
import { notifyRunFailed, notifyRunStopped } from './services/notification-orchestrator.js';
|
||||||
import { providerAuthService } from './modules/providers/services/provider-auth.service.js';
|
import { providerAuthService } from './modules/providers/services/provider-auth.service.js';
|
||||||
import { createNormalizedMessage } from './shared/utils.js';
|
import { createNormalizedMessage } from './shared/utils.js';
|
||||||
|
|
||||||
// Use cross-spawn on Windows for correct .cmd resolution (same pattern as cursor-cli.js)
|
|
||||||
const spawnFunction = process.platform === 'win32' ? crossSpawn : spawn;
|
|
||||||
|
|
||||||
let activeGeminiProcesses = new Map(); // Track active processes by session ID
|
let activeGeminiProcesses = new Map(); // Track active processes by session ID
|
||||||
|
|
||||||
function mapGeminiExitCodeToMessage(exitCode) {
|
|
||||||
switch (exitCode) {
|
|
||||||
case 42:
|
|
||||||
return 'Gemini rejected the request input (exit code 42).';
|
|
||||||
case 44:
|
|
||||||
return 'Gemini sandbox error (exit code 44). Check local sandbox/container settings.';
|
|
||||||
case 52:
|
|
||||||
return 'Gemini configuration error (exit code 52). Check your Gemini settings files for invalid JSON/config.';
|
|
||||||
case 53:
|
|
||||||
return 'Gemini conversation turn limit reached (exit code 53). Start a new Gemini session.';
|
|
||||||
default:
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const GEMINI_AUTH_ENV_KEYS = [
|
|
||||||
'GEMINI_API_KEY',
|
|
||||||
'GOOGLE_API_KEY',
|
|
||||||
'GOOGLE_CLOUD_PROJECT',
|
|
||||||
'GOOGLE_CLOUD_PROJECT_ID',
|
|
||||||
'GOOGLE_CLOUD_LOCATION',
|
|
||||||
'GOOGLE_APPLICATION_CREDENTIALS'
|
|
||||||
];
|
|
||||||
|
|
||||||
function parseEnvFileContent(content) {
|
|
||||||
const parsed = {};
|
|
||||||
|
|
||||||
for (const rawLine of content.split(/\r?\n/)) {
|
|
||||||
const line = rawLine.trim();
|
|
||||||
if (!line || line.startsWith('#')) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const exportPrefix = 'export ';
|
|
||||||
const normalizedLine = line.startsWith(exportPrefix) ? line.slice(exportPrefix.length).trim() : line;
|
|
||||||
const separatorIndex = normalizedLine.indexOf('=');
|
|
||||||
|
|
||||||
if (separatorIndex <= 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const key = normalizedLine.slice(0, separatorIndex).trim();
|
|
||||||
if (!key) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
let value = normalizedLine.slice(separatorIndex + 1).trim();
|
|
||||||
const hasDoubleQuotes = value.startsWith('"') && value.endsWith('"');
|
|
||||||
const hasSingleQuotes = value.startsWith('\'') && value.endsWith('\'');
|
|
||||||
|
|
||||||
if (hasDoubleQuotes || hasSingleQuotes) {
|
|
||||||
value = value.slice(1, -1);
|
|
||||||
} else {
|
|
||||||
// Support inline comments in unquoted values: KEY=value # comment
|
|
||||||
value = value.replace(/\s+#.*$/, '').trim();
|
|
||||||
}
|
|
||||||
|
|
||||||
parsed[key] = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
return parsed;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function loadGeminiUserLevelEnv() {
|
|
||||||
const geminiCliHome = (process.env.GEMINI_CLI_HOME || '').trim() || os.homedir();
|
|
||||||
const envCandidates = [
|
|
||||||
path.join(geminiCliHome, '.gemini', '.env'),
|
|
||||||
path.join(geminiCliHome, '.env')
|
|
||||||
];
|
|
||||||
|
|
||||||
for (const envPath of envCandidates) {
|
|
||||||
try {
|
|
||||||
await fs.access(envPath);
|
|
||||||
const content = await fs.readFile(envPath, 'utf8');
|
|
||||||
return parseEnvFileContent(content);
|
|
||||||
} catch {
|
|
||||||
// Keep scanning for the next candidate.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
async function buildGeminiProcessEnv() {
|
|
||||||
const processEnv = { ...process.env };
|
|
||||||
if (processEnv.GEMINI_API_KEY || processEnv.GOOGLE_API_KEY || processEnv.GOOGLE_APPLICATION_CREDENTIALS) {
|
|
||||||
return processEnv;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Gemini CLI docs recommend ~/.gemini/.env for persistent headless auth settings.
|
|
||||||
// When the server process was launched without shell profile variables, we still
|
|
||||||
// want the spawned CLI process to inherit those user-level credentials.
|
|
||||||
const userEnv = await loadGeminiUserLevelEnv();
|
|
||||||
for (const key of GEMINI_AUTH_ENV_KEYS) {
|
|
||||||
if (!processEnv[key] && userEnv[key]) {
|
|
||||||
processEnv[key] = userEnv[key];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return processEnv;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function spawnGemini(command, options = {}, ws) {
|
async function spawnGemini(command, options = {}, ws) {
|
||||||
const { sessionId, projectPath, cwd, toolsSettings, permissionMode, images, sessionSummary } = options;
|
const { sessionId, projectPath, cwd, toolsSettings, permissionMode, images, sessionSummary } = options;
|
||||||
let capturedSessionId = sessionId; // Track session ID throughout the process
|
let capturedSessionId = sessionId; // Track session ID throughout the process
|
||||||
@@ -204,11 +100,6 @@ async function spawnGemini(command, options = {}, ws) {
|
|||||||
args.push('--debug');
|
args.push('--debug');
|
||||||
}
|
}
|
||||||
|
|
||||||
// This integration runs Gemini in headless mode and cannot answer trust prompts.
|
|
||||||
// Skip folder-trust interactivity so authenticated runs don't fail with
|
|
||||||
// FatalUntrustedWorkspaceError in previously unseen directories.
|
|
||||||
args.push('--skip-trust');
|
|
||||||
|
|
||||||
// Add MCP config flag only if MCP servers are configured
|
// Add MCP config flag only if MCP servers are configured
|
||||||
try {
|
try {
|
||||||
const geminiConfigPath = path.join(os.homedir(), '.gemini.json');
|
const geminiConfigPath = path.join(os.homedir(), '.gemini.json');
|
||||||
@@ -263,6 +154,9 @@ async function spawnGemini(command, options = {}, ws) {
|
|||||||
|
|
||||||
// Try to find gemini in PATH first, then fall back to environment variable
|
// Try to find gemini in PATH first, then fall back to environment variable
|
||||||
const geminiPath = process.env.GEMINI_PATH || 'gemini';
|
const geminiPath = process.env.GEMINI_PATH || 'gemini';
|
||||||
|
console.log('Spawning Gemini CLI:', geminiPath, args.join(' '));
|
||||||
|
console.log('Working directory:', workingDir);
|
||||||
|
|
||||||
let spawnCmd = geminiPath;
|
let spawnCmd = geminiPath;
|
||||||
let spawnArgs = args;
|
let spawnArgs = args;
|
||||||
|
|
||||||
@@ -274,13 +168,11 @@ async function spawnGemini(command, options = {}, ws) {
|
|||||||
spawnArgs = ['-c', 'exec "$0" "$@"', geminiPath, ...args];
|
spawnArgs = ['-c', 'exec "$0" "$@"', geminiPath, ...args];
|
||||||
}
|
}
|
||||||
|
|
||||||
const spawnEnv = await buildGeminiProcessEnv();
|
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const geminiProcess = spawnFunction(spawnCmd, spawnArgs, {
|
const geminiProcess = spawnFunction(spawnCmd, spawnArgs, {
|
||||||
cwd: workingDir,
|
cwd: workingDir,
|
||||||
stdio: ['pipe', 'pipe', 'pipe'],
|
stdio: ['pipe', 'pipe', 'pipe'],
|
||||||
env: spawnEnv
|
env: { ...process.env } // Inherit all environment variables
|
||||||
});
|
});
|
||||||
let terminalNotificationSent = false;
|
let terminalNotificationSent = false;
|
||||||
let terminalFailureReason = null;
|
let terminalFailureReason = null;
|
||||||
@@ -384,43 +276,12 @@ async function spawnGemini(command, options = {}, ws) {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
onInit: (event) => {
|
onInit: (event) => {
|
||||||
const discoveredSessionId = event?.session_id;
|
if (capturedSessionId) {
|
||||||
if (!discoveredSessionId) {
|
const sess = sessionManager.getSession(capturedSessionId);
|
||||||
return;
|
if (sess && !sess.cliSessionId) {
|
||||||
}
|
sess.cliSessionId = event.session_id;
|
||||||
|
sessionManager.saveSession(capturedSessionId);
|
||||||
// New Gemini sessions announce their canonical ID asynchronously via the
|
|
||||||
// initial `init` stream event. Avoid synthetic IDs and only register
|
|
||||||
// the session once that real ID is known (same model used by Claude/Codex).
|
|
||||||
if (!capturedSessionId) {
|
|
||||||
capturedSessionId = discoveredSessionId;
|
|
||||||
|
|
||||||
sessionManager.createSession(capturedSessionId, cwd || process.cwd());
|
|
||||||
if (command) {
|
|
||||||
sessionManager.addMessage(capturedSessionId, 'user', command);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (processKey !== capturedSessionId) {
|
|
||||||
activeGeminiProcesses.delete(processKey);
|
|
||||||
activeGeminiProcesses.set(capturedSessionId, geminiProcess);
|
|
||||||
}
|
|
||||||
|
|
||||||
geminiProcess.sessionId = capturedSessionId;
|
|
||||||
|
|
||||||
if (ws.setSessionId && typeof ws.setSessionId === 'function') {
|
|
||||||
ws.setSessionId(capturedSessionId);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!sessionId && !sessionCreatedSent) {
|
|
||||||
sessionCreatedSent = true;
|
|
||||||
ws.send(createNormalizedMessage({ kind: 'session_created', newSessionId: capturedSessionId, sessionId: capturedSessionId, provider: 'gemini' }));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const sess = sessionManager.getSession(capturedSessionId);
|
|
||||||
if (sess && !sess.cliSessionId) {
|
|
||||||
sess.cliSessionId = discoveredSessionId;
|
|
||||||
sessionManager.saveSession(capturedSessionId);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -431,6 +292,30 @@ async function spawnGemini(command, options = {}, ws) {
|
|||||||
const rawOutput = data.toString();
|
const rawOutput = data.toString();
|
||||||
startTimeout(); // Re-arm the timeout
|
startTimeout(); // Re-arm the timeout
|
||||||
|
|
||||||
|
// For new sessions, create a session ID FIRST
|
||||||
|
if (!sessionId && !sessionCreatedSent && !capturedSessionId) {
|
||||||
|
capturedSessionId = `gemini_${Date.now()}`;
|
||||||
|
sessionCreatedSent = true;
|
||||||
|
|
||||||
|
// Create session in session manager
|
||||||
|
sessionManager.createSession(capturedSessionId, cwd || process.cwd());
|
||||||
|
|
||||||
|
// Save the user message now that we have a session ID
|
||||||
|
if (command) {
|
||||||
|
sessionManager.addMessage(capturedSessionId, 'user', command);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update process key with captured session ID
|
||||||
|
if (processKey !== capturedSessionId) {
|
||||||
|
activeGeminiProcesses.delete(processKey);
|
||||||
|
activeGeminiProcesses.set(capturedSessionId, geminiProcess);
|
||||||
|
}
|
||||||
|
|
||||||
|
ws.setSessionId && typeof ws.setSessionId === 'function' && ws.setSessionId(capturedSessionId);
|
||||||
|
|
||||||
|
ws.send(createNormalizedMessage({ kind: 'session_created', newSessionId: capturedSessionId, sessionId: capturedSessionId, provider: 'gemini' }));
|
||||||
|
}
|
||||||
|
|
||||||
if (responseHandler) {
|
if (responseHandler) {
|
||||||
responseHandler.processData(rawOutput);
|
responseHandler.processData(rawOutput);
|
||||||
} else if (rawOutput) {
|
} else if (rawOutput) {
|
||||||
@@ -496,38 +381,12 @@ async function spawnGemini(command, options = {}, ws) {
|
|||||||
notifyTerminalState({ code });
|
notifyTerminalState({ code });
|
||||||
resolve();
|
resolve();
|
||||||
} else {
|
} else {
|
||||||
const socketSessionId = typeof ws.getSessionId === 'function' ? ws.getSessionId() : finalSessionId;
|
// code 127 = shell "command not found" — check installation
|
||||||
|
|
||||||
// code 127 = shell "command not found" - check installation
|
|
||||||
if (code === 127) {
|
if (code === 127) {
|
||||||
const installed = await providerAuthService.isProviderInstalled('gemini');
|
const installed = await providerAuthService.isProviderInstalled('gemini');
|
||||||
if (!installed) {
|
if (!installed) {
|
||||||
terminalFailureReason = 'Gemini CLI is not installed. Please install it first: https://github.com/google-gemini/gemini-cli';
|
const socketSessionId = typeof ws.getSessionId === 'function' ? ws.getSessionId() : finalSessionId;
|
||||||
ws.send(createNormalizedMessage({ kind: 'error', content: terminalFailureReason, sessionId: socketSessionId, provider: 'gemini' }));
|
ws.send(createNormalizedMessage({ kind: 'error', content: 'Gemini CLI is not installed. Please install it first: https://github.com/google-gemini/gemini-cli', sessionId: socketSessionId, provider: 'gemini' }));
|
||||||
}
|
|
||||||
} else if (code === 41) {
|
|
||||||
// Gemini CLI documents exit code 41 as FatalAuthenticationError.
|
|
||||||
// Surface an actionable auth error instead of a generic exit-code message.
|
|
||||||
let authErrorSuffix = '';
|
|
||||||
try {
|
|
||||||
const authStatus = await providerAuthService.getProviderAuthStatus('gemini');
|
|
||||||
if (!authStatus?.authenticated && authStatus?.error) {
|
|
||||||
authErrorSuffix = ` Details: ${authStatus.error}`;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
// Keep base remediation text when auth status lookup fails.
|
|
||||||
}
|
|
||||||
|
|
||||||
terminalFailureReason =
|
|
||||||
'Gemini authentication failed (exit code 41). '
|
|
||||||
+ 'Run `gemini` in a terminal to choose an auth method, or configure a valid `GEMINI_API_KEY`.'
|
|
||||||
+ authErrorSuffix;
|
|
||||||
ws.send(createNormalizedMessage({ kind: 'error', content: terminalFailureReason, sessionId: socketSessionId, provider: 'gemini' }));
|
|
||||||
} else {
|
|
||||||
const mappedError = mapGeminiExitCodeToMessage(code);
|
|
||||||
if (mappedError) {
|
|
||||||
terminalFailureReason = mappedError;
|
|
||||||
ws.send(createNormalizedMessage({ kind: 'error', content: terminalFailureReason, sessionId: socketSessionId, provider: 'gemini' }));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -535,14 +394,7 @@ async function spawnGemini(command, options = {}, ws) {
|
|||||||
code,
|
code,
|
||||||
error: code === null ? 'Gemini CLI process was terminated or timed out' : null
|
error: code === null ? 'Gemini CLI process was terminated or timed out' : null
|
||||||
});
|
});
|
||||||
reject(
|
reject(new Error(code === null ? 'Gemini CLI process was terminated or timed out' : `Gemini CLI exited with code ${code}`));
|
||||||
new Error(
|
|
||||||
terminalFailureReason
|
|
||||||
|| (code === null
|
|
||||||
? 'Gemini CLI process was terminated or timed out'
|
|
||||||
: `Gemini CLI exited with code ${code}`)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -257,10 +257,8 @@ const rebuildSessionsTableWithProjectSchema = (db: Database): void => {
|
|||||||
|
|
||||||
if (!shouldRebuild) {
|
if (!shouldRebuild) {
|
||||||
addColumnToTableIfNotExists(db, 'sessions', columnNames, 'jsonl_path', 'TEXT');
|
addColumnToTableIfNotExists(db, 'sessions', columnNames, 'jsonl_path', 'TEXT');
|
||||||
addColumnToTableIfNotExists(db, 'sessions', columnNames, 'isArchived', 'BOOLEAN DEFAULT 0');
|
|
||||||
addColumnToTableIfNotExists(db, 'sessions', columnNames, 'created_at', 'DATETIME');
|
addColumnToTableIfNotExists(db, 'sessions', columnNames, 'created_at', 'DATETIME');
|
||||||
addColumnToTableIfNotExists(db, 'sessions', columnNames, 'updated_at', 'DATETIME');
|
addColumnToTableIfNotExists(db, 'sessions', columnNames, 'updated_at', 'DATETIME');
|
||||||
db.exec('UPDATE sessions SET isArchived = COALESCE(isArchived, 0)');
|
|
||||||
db.exec('UPDATE sessions SET created_at = COALESCE(created_at, CURRENT_TIMESTAMP)');
|
db.exec('UPDATE sessions SET created_at = COALESCE(created_at, CURRENT_TIMESTAMP)');
|
||||||
db.exec('UPDATE sessions SET updated_at = COALESCE(updated_at, CURRENT_TIMESTAMP)');
|
db.exec('UPDATE sessions SET updated_at = COALESCE(updated_at, CURRENT_TIMESTAMP)');
|
||||||
return;
|
return;
|
||||||
@@ -286,10 +284,6 @@ const rebuildSessionsTableWithProjectSchema = (db: Database): void => {
|
|||||||
? 'jsonl_path'
|
? 'jsonl_path'
|
||||||
: 'NULL';
|
: 'NULL';
|
||||||
|
|
||||||
const isArchivedExpression = columnNames.includes('isArchived')
|
|
||||||
? 'COALESCE(isArchived, 0)'
|
|
||||||
: '0';
|
|
||||||
|
|
||||||
const createdAtExpression = columnNames.includes('created_at')
|
const createdAtExpression = columnNames.includes('created_at')
|
||||||
? 'COALESCE(created_at, CURRENT_TIMESTAMP)'
|
? 'COALESCE(created_at, CURRENT_TIMESTAMP)'
|
||||||
: 'CURRENT_TIMESTAMP';
|
: 'CURRENT_TIMESTAMP';
|
||||||
@@ -309,7 +303,6 @@ const rebuildSessionsTableWithProjectSchema = (db: Database): void => {
|
|||||||
custom_name TEXT,
|
custom_name TEXT,
|
||||||
project_path TEXT,
|
project_path TEXT,
|
||||||
jsonl_path TEXT,
|
jsonl_path TEXT,
|
||||||
isArchived BOOLEAN DEFAULT 0,
|
|
||||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||||
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||||
PRIMARY KEY (session_id),
|
PRIMARY KEY (session_id),
|
||||||
@@ -326,7 +319,6 @@ const rebuildSessionsTableWithProjectSchema = (db: Database): void => {
|
|||||||
${customNameExpression} AS custom_name,
|
${customNameExpression} AS custom_name,
|
||||||
${projectPathExpression} AS project_path,
|
${projectPathExpression} AS project_path,
|
||||||
${jsonlPathExpression} AS jsonl_path,
|
${jsonlPathExpression} AS jsonl_path,
|
||||||
${isArchivedExpression} AS isArchived,
|
|
||||||
${createdAtExpression} AS created_at,
|
${createdAtExpression} AS created_at,
|
||||||
${updatedAtExpression} AS updated_at,
|
${updatedAtExpression} AS updated_at,
|
||||||
rowid AS source_rowid
|
rowid AS source_rowid
|
||||||
@@ -340,7 +332,6 @@ const rebuildSessionsTableWithProjectSchema = (db: Database): void => {
|
|||||||
custom_name,
|
custom_name,
|
||||||
project_path,
|
project_path,
|
||||||
jsonl_path,
|
jsonl_path,
|
||||||
isArchived,
|
|
||||||
created_at,
|
created_at,
|
||||||
updated_at,
|
updated_at,
|
||||||
ROW_NUMBER() OVER (
|
ROW_NUMBER() OVER (
|
||||||
@@ -355,7 +346,6 @@ const rebuildSessionsTableWithProjectSchema = (db: Database): void => {
|
|||||||
custom_name,
|
custom_name,
|
||||||
project_path,
|
project_path,
|
||||||
jsonl_path,
|
jsonl_path,
|
||||||
isArchived,
|
|
||||||
created_at,
|
created_at,
|
||||||
updated_at
|
updated_at
|
||||||
)
|
)
|
||||||
@@ -365,7 +355,6 @@ const rebuildSessionsTableWithProjectSchema = (db: Database): void => {
|
|||||||
custom_name,
|
custom_name,
|
||||||
project_path,
|
project_path,
|
||||||
jsonl_path,
|
jsonl_path,
|
||||||
isArchived,
|
|
||||||
created_at,
|
created_at,
|
||||||
updated_at
|
updated_at
|
||||||
FROM ranked_rows
|
FROM ranked_rows
|
||||||
@@ -432,7 +421,6 @@ export const runMigrations = (db: Database) => {
|
|||||||
|
|
||||||
db.exec('CREATE INDEX IF NOT EXISTS idx_session_ids_lookup ON sessions(session_id)');
|
db.exec('CREATE INDEX IF NOT EXISTS idx_session_ids_lookup ON sessions(session_id)');
|
||||||
db.exec('CREATE INDEX IF NOT EXISTS idx_sessions_project_path ON sessions(project_path)');
|
db.exec('CREATE INDEX IF NOT EXISTS idx_sessions_project_path ON sessions(project_path)');
|
||||||
db.exec('CREATE INDEX IF NOT EXISTS idx_sessions_is_archived ON sessions(isArchived)');
|
|
||||||
db.exec('CREATE INDEX IF NOT EXISTS idx_projects_is_starred ON projects(isStarred)');
|
db.exec('CREATE INDEX IF NOT EXISTS idx_projects_is_starred ON projects(isStarred)');
|
||||||
db.exec('CREATE INDEX IF NOT EXISTS idx_projects_is_archived ON projects(isArchived)');
|
db.exec('CREATE INDEX IF NOT EXISTS idx_projects_is_archived ON projects(isArchived)');
|
||||||
|
|
||||||
|
|||||||
@@ -95,19 +95,6 @@ export const projectsDb = {
|
|||||||
`).all() as ProjectRepositoryRow[];
|
`).all() as ProjectRepositoryRow[];
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
|
||||||
* Archived rows are queried separately so archive-focused UIs can present
|
|
||||||
* hidden workspaces without reintroducing them into the active sidebar list.
|
|
||||||
*/
|
|
||||||
getArchivedProjectPaths(): ProjectRepositoryRow[] {
|
|
||||||
const db = getConnection();
|
|
||||||
return db.prepare(`
|
|
||||||
SELECT project_id, project_path, custom_project_name, isStarred, isArchived
|
|
||||||
FROM projects
|
|
||||||
WHERE isArchived = 1
|
|
||||||
`).all() as ProjectRepositoryRow[];
|
|
||||||
},
|
|
||||||
|
|
||||||
getCustomProjectName(projectPath: string): string | null {
|
getCustomProjectName(projectPath: string): string | null {
|
||||||
const db = getConnection();
|
const db = getConnection();
|
||||||
const normalizedProjectPath = normalizeProjectPath(projectPath);
|
const normalizedProjectPath = normalizeProjectPath(projectPath);
|
||||||
|
|||||||
@@ -1,72 +0,0 @@
|
|||||||
import assert from 'node:assert/strict';
|
|
||||||
import { mkdtemp, rm } from 'node:fs/promises';
|
|
||||||
import { tmpdir } from 'node:os';
|
|
||||||
import path from 'node:path';
|
|
||||||
import test from 'node:test';
|
|
||||||
|
|
||||||
import { closeConnection } from '@/modules/database/connection.js';
|
|
||||||
import { initializeDatabase } from '@/modules/database/init-db.js';
|
|
||||||
import { sessionsDb } from '@/modules/database/repositories/sessions.db.js';
|
|
||||||
|
|
||||||
async function withIsolatedDatabase(runTest: () => void | Promise<void>): Promise<void> {
|
|
||||||
const previousDatabasePath = process.env.DATABASE_PATH;
|
|
||||||
const tempDirectory = await mkdtemp(path.join(tmpdir(), 'sessions-db-'));
|
|
||||||
const databasePath = path.join(tempDirectory, 'auth.db');
|
|
||||||
|
|
||||||
closeConnection();
|
|
||||||
process.env.DATABASE_PATH = databasePath;
|
|
||||||
await initializeDatabase();
|
|
||||||
|
|
||||||
try {
|
|
||||||
await runTest();
|
|
||||||
} finally {
|
|
||||||
closeConnection();
|
|
||||||
if (previousDatabasePath === undefined) {
|
|
||||||
delete process.env.DATABASE_PATH;
|
|
||||||
} else {
|
|
||||||
process.env.DATABASE_PATH = previousDatabasePath;
|
|
||||||
}
|
|
||||||
await rm(tempDirectory, { recursive: true, force: true });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
test('session archive queries hide archived rows from active project views', async () => {
|
|
||||||
await withIsolatedDatabase(() => {
|
|
||||||
sessionsDb.createSession('session-active', 'claude', '/workspace/demo-project', 'Active Session');
|
|
||||||
sessionsDb.createSession('session-archived', 'claude', '/workspace/demo-project', 'Archived Session');
|
|
||||||
sessionsDb.updateSessionIsArchived('session-archived', true);
|
|
||||||
|
|
||||||
const activeSessions = sessionsDb.getAllSessions();
|
|
||||||
const archivedSessions = sessionsDb.getArchivedSessions();
|
|
||||||
const activeProjectSessions = sessionsDb.getSessionsByProjectPath('/workspace/demo-project');
|
|
||||||
const allProjectSessions = sessionsDb.getSessionsByProjectPathIncludingArchived('/workspace/demo-project');
|
|
||||||
|
|
||||||
assert.deepEqual(activeSessions.map((session) => session.session_id), ['session-active']);
|
|
||||||
assert.deepEqual(archivedSessions.map((session) => session.session_id), ['session-archived']);
|
|
||||||
assert.deepEqual(activeProjectSessions.map((session) => session.session_id), ['session-active']);
|
|
||||||
assert.deepEqual(
|
|
||||||
allProjectSessions.map((session) => session.session_id).sort(),
|
|
||||||
['session-active', 'session-archived'],
|
|
||||||
);
|
|
||||||
assert.equal(sessionsDb.countSessionsByProjectPath('/workspace/demo-project'), 1);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
test('createSession reactivates archived rows when the session becomes active again', async () => {
|
|
||||||
await withIsolatedDatabase(() => {
|
|
||||||
sessionsDb.createSession('session-reused', 'claude', '/workspace/demo-project', 'First Name');
|
|
||||||
sessionsDb.updateSessionIsArchived('session-reused', true);
|
|
||||||
|
|
||||||
sessionsDb.createSession('session-reused', 'claude', '/workspace/demo-project', 'Updated Name');
|
|
||||||
|
|
||||||
const activeSessions = sessionsDb.getAllSessions();
|
|
||||||
const archivedSessions = sessionsDb.getArchivedSessions();
|
|
||||||
const restoredSession = sessionsDb.getSessionById('session-reused');
|
|
||||||
|
|
||||||
assert.equal(activeSessions.length, 1);
|
|
||||||
assert.equal(activeSessions[0]?.session_id, 'session-reused');
|
|
||||||
assert.equal(activeSessions[0]?.custom_name, 'Updated Name');
|
|
||||||
assert.equal(archivedSessions.length, 0);
|
|
||||||
assert.equal(restoredSession?.isArchived, 0);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -8,14 +8,13 @@ type SessionRow = {
|
|||||||
project_path: string | null;
|
project_path: string | null;
|
||||||
jsonl_path: string | null;
|
jsonl_path: string | null;
|
||||||
custom_name: string | null;
|
custom_name: string | null;
|
||||||
isArchived: number;
|
|
||||||
created_at: string;
|
created_at: string;
|
||||||
updated_at: string;
|
updated_at: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
type SessionMetadataLookupRow = Pick<
|
type SessionMetadataLookupRow = Pick<
|
||||||
SessionRow,
|
SessionRow,
|
||||||
'session_id' | 'provider' | 'project_path' | 'jsonl_path' | 'custom_name' | 'isArchived' | 'created_at' | 'updated_at'
|
'session_id' | 'provider' | 'project_path' | 'jsonl_path' | 'custom_name' | 'created_at' | 'updated_at'
|
||||||
>;
|
>;
|
||||||
|
|
||||||
function normalizeTimestamp(value?: string): string | null {
|
function normalizeTimestamp(value?: string): string | null {
|
||||||
@@ -54,14 +53,13 @@ export const sessionsDb = {
|
|||||||
projectsDb.createProjectPath(normalizedProjectPath);
|
projectsDb.createProjectPath(normalizedProjectPath);
|
||||||
|
|
||||||
db.prepare(
|
db.prepare(
|
||||||
`INSERT INTO sessions (session_id, provider, custom_name, project_path, jsonl_path, isArchived, created_at, updated_at)
|
`INSERT INTO sessions (session_id, provider, custom_name, project_path, jsonl_path, created_at, updated_at)
|
||||||
VALUES (?, ?, ?, ?, ?, 0, COALESCE(?, CURRENT_TIMESTAMP), COALESCE(?, CURRENT_TIMESTAMP))
|
VALUES (?, ?, ?, ?, ?, COALESCE(?, CURRENT_TIMESTAMP), COALESCE(?, CURRENT_TIMESTAMP))
|
||||||
ON CONFLICT(session_id) DO UPDATE SET
|
ON CONFLICT(session_id) DO UPDATE SET
|
||||||
provider = excluded.provider,
|
provider = excluded.provider,
|
||||||
updated_at = excluded.updated_at,
|
updated_at = excluded.updated_at,
|
||||||
project_path = excluded.project_path,
|
project_path = excluded.project_path,
|
||||||
jsonl_path = excluded.jsonl_path,
|
jsonl_path = excluded.jsonl_path,
|
||||||
isArchived = 0,
|
|
||||||
custom_name = COALESCE(excluded.custom_name, sessions.custom_name)`
|
custom_name = COALESCE(excluded.custom_name, sessions.custom_name)`
|
||||||
).run(
|
).run(
|
||||||
sessionId,
|
sessionId,
|
||||||
@@ -89,7 +87,7 @@ export const sessionsDb = {
|
|||||||
const db = getConnection();
|
const db = getConnection();
|
||||||
const row = db
|
const row = db
|
||||||
.prepare(
|
.prepare(
|
||||||
`SELECT session_id, provider, project_path, jsonl_path, custom_name, isArchived, created_at, updated_at
|
`SELECT session_id, provider, project_path, jsonl_path, custom_name, created_at, updated_at
|
||||||
FROM sessions
|
FROM sessions
|
||||||
WHERE session_id = ?
|
WHERE session_id = ?
|
||||||
ORDER BY updated_at DESC
|
ORDER BY updated_at DESC
|
||||||
@@ -104,25 +102,8 @@ export const sessionsDb = {
|
|||||||
const db = getConnection();
|
const db = getConnection();
|
||||||
return db
|
return db
|
||||||
.prepare(
|
.prepare(
|
||||||
`SELECT session_id, provider, project_path, jsonl_path, custom_name, isArchived, created_at, updated_at
|
`SELECT session_id, provider, project_path, jsonl_path, custom_name, created_at, updated_at
|
||||||
FROM sessions
|
FROM sessions`
|
||||||
WHERE isArchived = 0`
|
|
||||||
)
|
|
||||||
.all() as SessionRow[];
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Archived rows are intentionally queried separately so the caller can render
|
|
||||||
* them in a dedicated view without reintroducing them into active session lists.
|
|
||||||
*/
|
|
||||||
getArchivedSessions(): SessionRow[] {
|
|
||||||
const db = getConnection();
|
|
||||||
return db
|
|
||||||
.prepare(
|
|
||||||
`SELECT session_id, provider, project_path, jsonl_path, custom_name, isArchived, created_at, updated_at
|
|
||||||
FROM sessions
|
|
||||||
WHERE isArchived = 1
|
|
||||||
ORDER BY datetime(COALESCE(updated_at, created_at)) DESC, session_id DESC`
|
|
||||||
)
|
)
|
||||||
.all() as SessionRow[];
|
.all() as SessionRow[];
|
||||||
},
|
},
|
||||||
@@ -132,24 +113,7 @@ export const sessionsDb = {
|
|||||||
const normalizedProjectPath = normalizeProjectPath(projectPath);
|
const normalizedProjectPath = normalizeProjectPath(projectPath);
|
||||||
return db
|
return db
|
||||||
.prepare(
|
.prepare(
|
||||||
`SELECT session_id, provider, project_path, jsonl_path, custom_name, isArchived, created_at, updated_at
|
`SELECT session_id, provider, project_path, jsonl_path, custom_name, created_at, updated_at
|
||||||
FROM sessions
|
|
||||||
WHERE project_path = ?
|
|
||||||
AND isArchived = 0`
|
|
||||||
)
|
|
||||||
.all(normalizedProjectPath) as SessionRow[];
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Permanent project deletion must see every session row for the path,
|
|
||||||
* including archived ones, so their transcript files can be cleaned up.
|
|
||||||
*/
|
|
||||||
getSessionsByProjectPathIncludingArchived(projectPath: string): SessionRow[] {
|
|
||||||
const db = getConnection();
|
|
||||||
const normalizedProjectPath = normalizeProjectPath(projectPath);
|
|
||||||
return db
|
|
||||||
.prepare(
|
|
||||||
`SELECT session_id, provider, project_path, jsonl_path, custom_name, isArchived, created_at, updated_at
|
|
||||||
FROM sessions
|
FROM sessions
|
||||||
WHERE project_path = ?`
|
WHERE project_path = ?`
|
||||||
)
|
)
|
||||||
@@ -161,10 +125,9 @@ export const sessionsDb = {
|
|||||||
const normalizedProjectPath = normalizeProjectPath(projectPath);
|
const normalizedProjectPath = normalizeProjectPath(projectPath);
|
||||||
return db
|
return db
|
||||||
.prepare(
|
.prepare(
|
||||||
`SELECT session_id, provider, project_path, jsonl_path, custom_name, isArchived, created_at, updated_at
|
`SELECT session_id, provider, project_path, jsonl_path, custom_name, created_at, updated_at
|
||||||
FROM sessions
|
FROM sessions
|
||||||
WHERE project_path = ?
|
WHERE project_path = ?
|
||||||
AND isArchived = 0
|
|
||||||
ORDER BY datetime(COALESCE(updated_at, created_at)) DESC, session_id DESC
|
ORDER BY datetime(COALESCE(updated_at, created_at)) DESC, session_id DESC
|
||||||
LIMIT ? OFFSET ?`
|
LIMIT ? OFFSET ?`
|
||||||
)
|
)
|
||||||
@@ -178,8 +141,7 @@ export const sessionsDb = {
|
|||||||
.prepare(
|
.prepare(
|
||||||
`SELECT COUNT(*) AS count
|
`SELECT COUNT(*) AS count
|
||||||
FROM sessions
|
FROM sessions
|
||||||
WHERE project_path = ?
|
WHERE project_path = ?`
|
||||||
AND isArchived = 0`
|
|
||||||
)
|
)
|
||||||
.get(normalizedProjectPath) as { count: number } | undefined;
|
.get(normalizedProjectPath) as { count: number } | undefined;
|
||||||
|
|
||||||
@@ -205,19 +167,6 @@ export const sessionsDb = {
|
|||||||
return row?.custom_name ?? null;
|
return row?.custom_name ?? null;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
|
||||||
* Soft-delete and restore both use the same flag update so callers keep the
|
|
||||||
* row, metadata, and file path intact while toggling visibility.
|
|
||||||
*/
|
|
||||||
updateSessionIsArchived(sessionId: string, isArchived: boolean): void {
|
|
||||||
const db = getConnection();
|
|
||||||
db.prepare(
|
|
||||||
`UPDATE sessions
|
|
||||||
SET isArchived = ?
|
|
||||||
WHERE session_id = ?`
|
|
||||||
).run(isArchived ? 1 : 0, sessionId);
|
|
||||||
},
|
|
||||||
|
|
||||||
deleteSessionById(sessionId: string): boolean {
|
deleteSessionById(sessionId: string): boolean {
|
||||||
const db = getConnection();
|
const db = getConnection();
|
||||||
return db.prepare('DELETE FROM sessions WHERE session_id = ?').run(sessionId).changes > 0;
|
return db.prepare('DELETE FROM sessions WHERE session_id = ?').run(sessionId).changes > 0;
|
||||||
|
|||||||
@@ -86,7 +86,6 @@ CREATE TABLE IF NOT EXISTS sessions (
|
|||||||
custom_name TEXT,
|
custom_name TEXT,
|
||||||
project_path TEXT,
|
project_path TEXT,
|
||||||
jsonl_path TEXT,
|
jsonl_path TEXT,
|
||||||
isArchived BOOLEAN DEFAULT 0,
|
|
||||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||||
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||||
PRIMARY KEY (session_id),
|
PRIMARY KEY (session_id),
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ import express from 'express';
|
|||||||
import { createProject, updateProjectDisplayName } from '@/modules/projects/services/project-management.service.js';
|
import { createProject, updateProjectDisplayName } from '@/modules/projects/services/project-management.service.js';
|
||||||
import { startCloneProject } from '@/modules/projects/services/project-clone.service.js';
|
import { startCloneProject } from '@/modules/projects/services/project-clone.service.js';
|
||||||
import { getProjectTaskMaster } from '@/modules/projects/services/projects-has-taskmaster.service.js';
|
import { getProjectTaskMaster } from '@/modules/projects/services/projects-has-taskmaster.service.js';
|
||||||
import { AppError, asyncHandler, createApiSuccessResponse } from '@/shared/utils.js';
|
import { AppError, asyncHandler } from '@/shared/utils.js';
|
||||||
import { getArchivedProjectsWithSessions, getProjectSessionsPage, getProjectsWithSessions } from '@/modules/projects/services/projects-with-sessions-fetch.service.js';
|
import { getProjectSessionsPage, getProjectsWithSessions } from '@/modules/projects/services/projects-with-sessions-fetch.service.js';
|
||||||
import { deleteOrArchiveProject, restoreArchivedProject } from '@/modules/projects/services/project-delete.service.js';
|
import { deleteOrArchiveProject } from '@/modules/projects/services/project-delete.service.js';
|
||||||
import { applyLegacyStarredProjectIds, toggleProjectStar } from '@/modules/projects/services/project-star.service.js';
|
import { applyLegacyStarredProjectIds, toggleProjectStar } from '@/modules/projects/services/project-star.service.js';
|
||||||
|
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
@@ -73,14 +73,6 @@ router.get(
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
router.get(
|
|
||||||
'/archived',
|
|
||||||
asyncHandler(async (_req, res) => {
|
|
||||||
const projects = await getArchivedProjectsWithSessions();
|
|
||||||
res.json(createApiSuccessResponse({ projects }));
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
router.get(
|
router.get(
|
||||||
'/:projectId/sessions',
|
'/:projectId/sessions',
|
||||||
asyncHandler(async (req, res) => {
|
asyncHandler(async (req, res) => {
|
||||||
@@ -238,15 +230,6 @@ router.post(
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
router.post(
|
|
||||||
'/:projectId/restore',
|
|
||||||
asyncHandler(async (req, res) => {
|
|
||||||
const projectId = typeof req.params.projectId === 'string' ? req.params.projectId : '';
|
|
||||||
restoreArchivedProject(projectId);
|
|
||||||
res.json(createApiSuccessResponse({ projectId, isArchived: false }));
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* - `force` not set / false: archive project in DB only (`isArchived` = 1; hidden from active list).
|
* - `force` not set / false: archive project in DB only (`isArchived` = 1; hidden from active list).
|
||||||
* - `force=true`: remove DB row, delete session rows for that path, remove all `*.jsonl` under the Claude project dir.
|
* - `force=true`: remove DB row, delete session rows for that path, remove all `*.jsonl` under the Claude project dir.
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ async function unlinkJsonlIfExists(filePath: string): Promise<void> {
|
|||||||
* Loads all session rows for the project path and removes each distinct `jsonl_path` file on disk.
|
* Loads all session rows for the project path and removes each distinct `jsonl_path` file on disk.
|
||||||
*/
|
*/
|
||||||
export async function deleteSessionJsonlFilesForProjectPath(projectPath: string): Promise<void> {
|
export async function deleteSessionJsonlFilesForProjectPath(projectPath: string): Promise<void> {
|
||||||
const sessions = sessionsDb.getSessionsByProjectPathIncludingArchived(projectPath);
|
const sessions = sessionsDb.getSessionsByProjectPath(projectPath);
|
||||||
const paths = uniqueJsonlPathsFromSessions(sessions);
|
const paths = uniqueJsonlPathsFromSessions(sessions);
|
||||||
|
|
||||||
for (const filePath of paths) {
|
for (const filePath of paths) {
|
||||||
@@ -73,18 +73,3 @@ export async function deleteOrArchiveProject(projectId: string, force: boolean):
|
|||||||
sessionsDb.deleteSessionsByProjectPath(row.project_path);
|
sessionsDb.deleteSessionsByProjectPath(row.project_path);
|
||||||
projectsDb.deleteProjectById(projectId);
|
projectsDb.deleteProjectById(projectId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Restores one archived project row back into the active project list.
|
|
||||||
*/
|
|
||||||
export function restoreArchivedProject(projectId: string): void {
|
|
||||||
const row = projectsDb.getProjectById(projectId);
|
|
||||||
if (!row) {
|
|
||||||
throw new AppError(`Unknown projectId: ${projectId}`, {
|
|
||||||
code: 'PROJECT_NOT_FOUND',
|
|
||||||
statusCode: 404,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
projectsDb.updateProjectIsArchivedById(projectId, false);
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -40,10 +40,6 @@ export type ProjectListItem = {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export type ArchivedProjectListItem = ProjectListItem & {
|
|
||||||
isArchived: true;
|
|
||||||
};
|
|
||||||
|
|
||||||
type ProgressUpdate = {
|
type ProgressUpdate = {
|
||||||
phase: 'loading' | 'complete';
|
phase: 'loading' | 'complete';
|
||||||
current: number;
|
current: number;
|
||||||
@@ -154,16 +150,6 @@ function bucketSessionRowsByProvider(rows: SessionRepositoryRow[]): SessionsByPr
|
|||||||
return byProvider;
|
return byProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
function readProjectSessionsIncludingArchived(projectPath: string): ProjectSessionsPageResult {
|
|
||||||
const rows = sessionsDb.getSessionsByProjectPathIncludingArchived(projectPath) as SessionRepositoryRow[];
|
|
||||||
|
|
||||||
return {
|
|
||||||
sessionsByProvider: bucketSessionRowsByProvider(rows),
|
|
||||||
total: rows.length,
|
|
||||||
hasMore: false,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads one paginated project session slice from the DB and groups rows by provider.
|
* Reads one paginated project session slice from the DB and groups rows by provider.
|
||||||
*/
|
*/
|
||||||
@@ -269,56 +255,6 @@ export async function getProjectsWithSessions(
|
|||||||
return projects;
|
return projects;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Reads archived projects from DB and includes every session row for each
|
|
||||||
* project path, because an archived workspace should surface all preserved
|
|
||||||
* conversation history in the archive view regardless of each session's flag.
|
|
||||||
*/
|
|
||||||
export async function getArchivedProjectsWithSessions(
|
|
||||||
options: Pick<GetProjectsWithSessionsOptions, 'skipSynchronization'> = {},
|
|
||||||
): Promise<ArchivedProjectListItem[]> {
|
|
||||||
if (!options.skipSynchronization) {
|
|
||||||
await sessionSynchronizerService.synchronizeSessions();
|
|
||||||
}
|
|
||||||
|
|
||||||
const projectRows = projectsDb.getArchivedProjectPaths() as Array<{
|
|
||||||
project_id: string;
|
|
||||||
project_path: string;
|
|
||||||
custom_project_name?: string | null;
|
|
||||||
isStarred?: number;
|
|
||||||
}>;
|
|
||||||
|
|
||||||
const archivedProjects: ArchivedProjectListItem[] = [];
|
|
||||||
|
|
||||||
for (const row of projectRows) {
|
|
||||||
const displayName =
|
|
||||||
row.custom_project_name && row.custom_project_name.trim().length > 0
|
|
||||||
? row.custom_project_name
|
|
||||||
: await generateDisplayName(path.basename(row.project_path) || row.project_path, row.project_path);
|
|
||||||
|
|
||||||
const sessionsPage = readProjectSessionsIncludingArchived(row.project_path);
|
|
||||||
|
|
||||||
archivedProjects.push({
|
|
||||||
projectId: row.project_id,
|
|
||||||
path: row.project_path,
|
|
||||||
displayName,
|
|
||||||
fullPath: row.project_path,
|
|
||||||
isStarred: Boolean(row.isStarred),
|
|
||||||
isArchived: true,
|
|
||||||
sessions: sessionsPage.sessionsByProvider.claude,
|
|
||||||
cursorSessions: sessionsPage.sessionsByProvider.cursor,
|
|
||||||
codexSessions: sessionsPage.sessionsByProvider.codex,
|
|
||||||
geminiSessions: sessionsPage.sessionsByProvider.gemini,
|
|
||||||
sessionMeta: {
|
|
||||||
hasMore: sessionsPage.hasMore,
|
|
||||||
total: sessionsPage.total,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return archivedProjects;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads one paginated session slice for a specific project id.
|
* Loads one paginated session slice for a specific project id.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,346 +0,0 @@
|
|||||||
# Providers Module Guide
|
|
||||||
|
|
||||||
This file documents the current provider contract in `server/modules/providers`.
|
|
||||||
Keep it current whenever provider wiring, skill discovery, or session sync
|
|
||||||
behavior changes. The goal is that a human or AI agent can add a new provider
|
|
||||||
without guessing which files need to move.
|
|
||||||
|
|
||||||
## Current Provider Shape
|
|
||||||
|
|
||||||
Every provider wrapper exposes five facets:
|
|
||||||
|
|
||||||
- `auth`
|
|
||||||
- `mcp`
|
|
||||||
- `skills`
|
|
||||||
- `sessions`
|
|
||||||
- `sessionSynchronizer`
|
|
||||||
|
|
||||||
These correspond to the shared interfaces in `server/shared/interfaces.ts`:
|
|
||||||
|
|
||||||
- `IProviderAuth`
|
|
||||||
- `IProviderMcp`
|
|
||||||
- `IProviderSkills`
|
|
||||||
- `IProviderSessions`
|
|
||||||
- `IProviderSessionSynchronizer`
|
|
||||||
|
|
||||||
The services that consume them are:
|
|
||||||
|
|
||||||
- `providerAuthService`
|
|
||||||
- `providerMcpService`
|
|
||||||
- `providerSkillsService`
|
|
||||||
- `sessionsService`
|
|
||||||
- `sessionSynchronizerService`
|
|
||||||
|
|
||||||
Current provider ids in this repo are:
|
|
||||||
|
|
||||||
- `claude`
|
|
||||||
- `codex`
|
|
||||||
- `cursor`
|
|
||||||
- `gemini`
|
|
||||||
|
|
||||||
Those ids are mirrored in backend unions and frontend provider constants. If
|
|
||||||
adding a new provider, update every place that hardcodes this list.
|
|
||||||
|
|
||||||
## Current File Layout
|
|
||||||
|
|
||||||
Each provider lives under its own folder in `server/modules/providers/list/`:
|
|
||||||
|
|
||||||
```text
|
|
||||||
server/modules/providers/list/<provider>/
|
|
||||||
<provider>.provider.ts
|
|
||||||
<provider>-auth.provider.ts
|
|
||||||
<provider>-mcp.provider.ts
|
|
||||||
<provider>-skills.provider.ts
|
|
||||||
<provider>-sessions.provider.ts
|
|
||||||
<provider>-session-synchronizer.provider.ts
|
|
||||||
```
|
|
||||||
|
|
||||||
The existing provider folders are `claude`, `codex`, `cursor`, and `gemini`.
|
|
||||||
|
|
||||||
## What Each Facet Does
|
|
||||||
|
|
||||||
| Facet | Responsibility | Base / Service |
|
|
||||||
| --- | --- | --- |
|
|
||||||
| `auth` | Report install/auth state for the provider runtime | `IProviderAuth` -> `providerAuthService` |
|
|
||||||
| `mcp` | Read, list, write, and remove provider-native MCP config | `McpProvider` -> `providerMcpService` |
|
|
||||||
| `skills` | Discover provider-native skill markdown files | `SkillsProvider` -> `providerSkillsService` |
|
|
||||||
| `sessions` | Normalize live events and fetch session history | `IProviderSessions` -> `sessionsService` |
|
|
||||||
| `sessionSynchronizer` | Scan transcript artifacts and upsert session metadata | `IProviderSessionSynchronizer` -> `sessionSynchronizerService` |
|
|
||||||
|
|
||||||
`sessions` and `sessionSynchronizer` are separate concerns:
|
|
||||||
|
|
||||||
- `sessions` handles runtime event normalization and history fetches.
|
|
||||||
- `sessionSynchronizer` handles file-backed session indexing into `sessionsDb`.
|
|
||||||
|
|
||||||
## How To Add A Provider
|
|
||||||
|
|
||||||
1. Add the provider id everywhere it is part of the contract.
|
|
||||||
|
|
||||||
- Update `server/shared/types.ts` `LLMProvider`.
|
|
||||||
- Update `src/types/app.ts` `LLMProvider` if the frontend should know about it.
|
|
||||||
- Update `server/modules/providers/provider.routes.ts`.
|
|
||||||
- Update `server/routes/agent.js` if the provider is launchable from the agent runtime.
|
|
||||||
- Update `server/index.js` if the provider needs runtime boot or shutdown wiring.
|
|
||||||
- Update `shared/modelConstants.js` if the provider appears in UI provider pickers.
|
|
||||||
- Update `src/components/chat/hooks/useChatProviderState.ts` and
|
|
||||||
`src/components/chat/view/subcomponents/ProviderSelectionEmptyState.tsx` if
|
|
||||||
the provider should be selectable in chat.
|
|
||||||
- Update `src/components/provider-auth/view/ProviderLoginModal.tsx` if the
|
|
||||||
provider has a login/setup flow.
|
|
||||||
|
|
||||||
2. Create the wrapper class.
|
|
||||||
|
|
||||||
- Add `server/modules/providers/list/<provider>/<provider>.provider.ts`.
|
|
||||||
- Extend `AbstractProvider`.
|
|
||||||
- Expose readonly `auth`, `mcp`, `skills`, `sessions`, and `sessionSynchronizer`.
|
|
||||||
- Call `super('<provider>')`.
|
|
||||||
|
|
||||||
3. Implement auth.
|
|
||||||
|
|
||||||
- Return a full `ProviderAuthStatus`.
|
|
||||||
- Treat normal `not installed` / `not authenticated` states as data, not exceptions.
|
|
||||||
- Keep provider-specific credential discovery inside the auth provider.
|
|
||||||
- If the provider has no auth step, return a stable unauthenticated or not-installed status instead of omitting the facet.
|
|
||||||
|
|
||||||
4. Implement MCP.
|
|
||||||
|
|
||||||
- Extend `McpProvider`.
|
|
||||||
- Pass the supported scopes and transports to `super(...)`.
|
|
||||||
- Implement the four required methods:
|
|
||||||
- `readScopedServers(...)`
|
|
||||||
- `writeScopedServers(...)`
|
|
||||||
- `buildServerConfig(...)`
|
|
||||||
- `normalizeServerConfig(...)`
|
|
||||||
- Use the shared validation and normalization behavior from `McpProvider`.
|
|
||||||
- Keep the provider-specific config format local to the provider implementation.
|
|
||||||
|
|
||||||
Current MCP formats in this repo are:
|
|
||||||
|
|
||||||
| Provider | User / Project Storage | Supported Scopes | Supported Transports |
|
|
||||||
| --- | --- | --- | --- |
|
|
||||||
| Claude | `.mcp.json` in user / local / project locations | `user`, `local`, `project` | `stdio`, `http`, `sse` |
|
|
||||||
| Codex | `.codex/config.toml` | `user`, `project` | `stdio`, `http` |
|
|
||||||
| Cursor | `.cursor/mcp.json` | `user`, `project` | `stdio`, `http` |
|
|
||||||
| Gemini | `.gemini/settings.json` | `user`, `project` | `stdio`, `http` |
|
|
||||||
|
|
||||||
5. Implement skills.
|
|
||||||
|
|
||||||
- Extend `SkillsProvider`.
|
|
||||||
- Implement `getSkillSources(workspacePath)`.
|
|
||||||
- Return the actual discovery roots for the provider.
|
|
||||||
- Skills are discovered from `SKILL.md` files.
|
|
||||||
- `readProviderSkillMarkdownDefinition(...)` reads front matter `name` and `description`.
|
|
||||||
- If `name` is missing, the parent directory name is used as a fallback.
|
|
||||||
- Use `recursive: true` only when the provider stores skills in nested trees.
|
|
||||||
- Keep the emitted `command` string aligned with the provider's real skill syntax.
|
|
||||||
|
|
||||||
Current skill discovery roots are:
|
|
||||||
|
|
||||||
| Provider | User Roots | Project / Repo Roots | Prefix | Notes |
|
|
||||||
| --- | --- | --- | --- | --- |
|
|
||||||
| Claude | `~/.claude/skills` | `<workspace>/.claude/skills` | `/` | Also discovers Claude plugin skills from enabled plugin installs. Command skills live under `commands/`; markdown skills live under `skills/` and are scanned recursively. |
|
|
||||||
| Codex | `~/.agents/skills`, `~/.codex/skills/.system`, `/etc/codex/skills` | `<workspace>/.agents/skills`, `path.dirname(workspacePath)/.agents/skills`, topmost git root `.agents/skills` | `$` | Overlapping roots are deduplicated before scanning. |
|
|
||||||
| Cursor | `~/.cursor/skills` | `<workspace>/.cursor/skills`, `<workspace>/.agents/skills` | `/` | Uses slash-style commands. |
|
|
||||||
| Gemini | `~/.gemini/skills`, `~/.agents/skills` | `<workspace>/.gemini/skills`, `<workspace>/.agents/skills` | `/` | Uses slash-style commands. |
|
|
||||||
|
|
||||||
Command forms currently used by the providers are:
|
|
||||||
|
|
||||||
- Claude user/project skills: `/skill-name`
|
|
||||||
- Claude plugin skills: `/plugin-name:skill-name`
|
|
||||||
- Codex skills: `$skill-name`
|
|
||||||
- Cursor skills: `/skill-name`
|
|
||||||
- Gemini skills: `/skill-name`
|
|
||||||
|
|
||||||
6. Implement sessions.
|
|
||||||
|
|
||||||
- Implement `normalizeMessage(raw, sessionId)` and `fetchHistory(sessionId, options)`.
|
|
||||||
- Use `createNormalizedMessage(...)` and `generateMessageId(...)` for emitted messages.
|
|
||||||
- Keep normalized message ids unique. If one raw event produces multiple text
|
|
||||||
parts, append a discriminator so ids do not collide.
|
|
||||||
- Keep pagination consistent:
|
|
||||||
- `limit: null` means unbounded/full history.
|
|
||||||
- `limit: 0` means an empty page.
|
|
||||||
- always return `total`, `hasMore`, `offset`, and `limit` when paginating.
|
|
||||||
- Sanitize any filesystem-derived ids before using them in file or database paths.
|
|
||||||
- Do not assume a provider's history format matches another provider's format.
|
|
||||||
|
|
||||||
7. Implement session synchronization.
|
|
||||||
|
|
||||||
- Implement `synchronize(since?: Date)` to scan provider artifacts and upsert
|
|
||||||
sessions into `sessionsDb`.
|
|
||||||
- Implement `synchronizeFile(filePath)` for single-file watcher updates.
|
|
||||||
- Use the existing helpers when they fit:
|
|
||||||
- `buildLookupMap(...)`
|
|
||||||
- `extractFirstValidJsonlData(...)`
|
|
||||||
- `findFilesRecursivelyCreatedAfter(...)`
|
|
||||||
- `normalizeSessionName(...)`
|
|
||||||
- `readFileTimestamps(...)`
|
|
||||||
- Make the sync resilient to partial, malformed, or missing provider files.
|
|
||||||
- The orchestration service runs all provider synchronizers and only advances
|
|
||||||
`scan_state.last_scanned_at` when every provider succeeds.
|
|
||||||
|
|
||||||
Current session sync roots are:
|
|
||||||
|
|
||||||
| Provider | Scan Roots | Metadata Helpers / Notes |
|
|
||||||
| --- | --- | --- |
|
|
||||||
| Claude | `~/.claude/projects/**/*.jsonl` | Uses `~/.claude/history.jsonl` for name lookup and the trailing `ai-title`, `last-prompt`, or `custom-title` entries for title recovery. |
|
|
||||||
| Codex | `~/.codex/sessions/**/*.jsonl` | Uses `~/.codex/session_index.jsonl` for title lookup and the last `task_complete` message for a fallback title. |
|
|
||||||
| Cursor | `~/.cursor/projects/**/*.jsonl` | Uses sibling `worker.log` to recover `workspacePath`, then derives the session title from the first user prompt. |
|
|
||||||
| Gemini | `~/.gemini/tmp/**/*.jsonl` | Current full scans only index temp JSONL chat artifacts. Single-file sync also accepts legacy `.json` files. |
|
|
||||||
|
|
||||||
8. Register the provider.
|
|
||||||
|
|
||||||
- Add the new provider class to `server/modules/providers/provider.registry.ts`.
|
|
||||||
- Update `server/modules/providers/provider.routes.ts` provider parsing.
|
|
||||||
- If the provider introduces a new service or lifecycle hook, export it from the module entrypoint that consumes providers.
|
|
||||||
|
|
||||||
9. Wire runtime and UI surfaces outside the providers module when needed.
|
|
||||||
|
|
||||||
If the provider can run live chat sessions, update the runtime entrypoints too:
|
|
||||||
|
|
||||||
- `server/routes/agent.js`
|
|
||||||
- `server/index.js`
|
|
||||||
|
|
||||||
If the provider is visible in the UI, update:
|
|
||||||
|
|
||||||
- `shared/modelConstants.js`
|
|
||||||
- `src/components/chat/hooks/useChatProviderState.ts`
|
|
||||||
- `src/components/chat/view/subcomponents/ProviderSelectionEmptyState.tsx`
|
|
||||||
- `src/components/provider-auth/view/ProviderLoginModal.tsx`
|
|
||||||
|
|
||||||
## Minimal Wrapper Template
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import { AbstractProvider } from '@/modules/providers/shared/base/abstract.provider.js';
|
|
||||||
import { <Provider>ProviderAuth } from './<provider>-auth.provider.js';
|
|
||||||
import { <Provider>McpProvider } from './<provider>-mcp.provider.js';
|
|
||||||
import { <Provider>SkillsProvider } from './<provider>-skills.provider.js';
|
|
||||||
import { <Provider>SessionsProvider } from './<provider>-sessions.provider.js';
|
|
||||||
import { <Provider>SessionSynchronizer } from './<provider>-session-synchronizer.provider.js';
|
|
||||||
import type {
|
|
||||||
IProviderAuth,
|
|
||||||
IProviderMcp,
|
|
||||||
IProviderSessionSynchronizer,
|
|
||||||
IProviderSessions,
|
|
||||||
IProviderSkills,
|
|
||||||
} from '@/shared/interfaces.js';
|
|
||||||
|
|
||||||
export class <Provider>Provider extends AbstractProvider {
|
|
||||||
readonly auth: IProviderAuth = new <Provider>ProviderAuth();
|
|
||||||
readonly mcp: IProviderMcp = new <Provider>McpProvider();
|
|
||||||
readonly skills: IProviderSkills = new <Provider>SkillsProvider();
|
|
||||||
readonly sessions: IProviderSessions = new <Provider>SessionsProvider();
|
|
||||||
readonly sessionSynchronizer: IProviderSessionSynchronizer =
|
|
||||||
new <Provider>SessionSynchronizer();
|
|
||||||
|
|
||||||
constructor() {
|
|
||||||
super('<provider>');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## Minimal Skills Template
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import path from 'node:path';
|
|
||||||
|
|
||||||
import { SkillsProvider } from '@/modules/providers/shared/skills/skills.provider.js';
|
|
||||||
import type { ProviderSkillSource } from '@/shared/types.js';
|
|
||||||
|
|
||||||
export class <Provider>SkillsProvider extends SkillsProvider {
|
|
||||||
constructor() {
|
|
||||||
super('<provider>');
|
|
||||||
}
|
|
||||||
|
|
||||||
protected async getSkillSources(workspacePath: string): Promise<ProviderSkillSource[]> {
|
|
||||||
return [
|
|
||||||
{
|
|
||||||
scope: 'project',
|
|
||||||
rootDir: path.join(workspacePath, '.<provider>', 'skills'),
|
|
||||||
commandPrefix: '/',
|
|
||||||
},
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## Minimal Session Sync Template
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import type { IProviderSessionSynchronizer } from '@/shared/interfaces.js';
|
|
||||||
|
|
||||||
export class <Provider>SessionSynchronizer implements IProviderSessionSynchronizer {
|
|
||||||
async synchronize(since?: Date): Promise<number> {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
async synchronizeFile(filePath: string): Promise<string | null> {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## AI Prompt Template
|
|
||||||
|
|
||||||
Use this prompt when asking an AI agent to add a provider:
|
|
||||||
|
|
||||||
```text
|
|
||||||
Add a new provider "<provider>" using the current provider module architecture.
|
|
||||||
|
|
||||||
Requirements:
|
|
||||||
1) Create:
|
|
||||||
- server/modules/providers/list/<provider>/<provider>.provider.ts
|
|
||||||
- server/modules/providers/list/<provider>/<provider>-auth.provider.ts
|
|
||||||
- server/modules/providers/list/<provider>/<provider>-mcp.provider.ts
|
|
||||||
- server/modules/providers/list/<provider>/<provider>-skills.provider.ts
|
|
||||||
- server/modules/providers/list/<provider>/<provider>-sessions.provider.ts
|
|
||||||
- server/modules/providers/list/<provider>/<provider>-session-synchronizer.provider.ts
|
|
||||||
2) Register in:
|
|
||||||
- server/modules/providers/provider.registry.ts
|
|
||||||
- server/modules/providers/provider.routes.ts
|
|
||||||
- server/shared/types.ts LLMProvider
|
|
||||||
- src/types/app.ts LLMProvider
|
|
||||||
3) Mirror the nearest existing provider implementation for file naming, style,
|
|
||||||
and error handling.
|
|
||||||
4) Implement skills support with SkillsProvider and the current skill roots.
|
|
||||||
5) Implement session synchronization if the provider stores transcript files.
|
|
||||||
6) Ensure sessions use unique ids, safe path handling, and correct pagination.
|
|
||||||
7) Keep `sessions` and `sessionSynchronizer` separate.
|
|
||||||
8) Run:
|
|
||||||
- npx eslint <touched files>
|
|
||||||
- npx tsc --noEmit -p server/tsconfig.json
|
|
||||||
```
|
|
||||||
|
|
||||||
## Validation
|
|
||||||
|
|
||||||
After adding or changing a provider, run the relevant checks:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
npx eslint server/modules/providers/**/*.ts server/shared/types.ts server/shared/interfaces.ts
|
|
||||||
npx tsc --noEmit -p server/tsconfig.json
|
|
||||||
```
|
|
||||||
|
|
||||||
Useful tests in this repo:
|
|
||||||
|
|
||||||
- `server/modules/providers/tests/mcp.test.ts`
|
|
||||||
- `server/modules/providers/tests/skills.test.ts`
|
|
||||||
|
|
||||||
If you touch sessions or session synchronization, add or update focused tests
|
|
||||||
alongside the implementation.
|
|
||||||
|
|
||||||
## Common Mistakes
|
|
||||||
|
|
||||||
- Adding provider files but forgetting `provider.registry.ts` or
|
|
||||||
`provider.routes.ts`.
|
|
||||||
- Updating backend provider ids but not `src/types/app.ts` or the frontend
|
|
||||||
provider constants.
|
|
||||||
- Omitting `skills` or `sessionSynchronizer` from the wrapper.
|
|
||||||
- Returning duplicate normalized message ids for split content.
|
|
||||||
- Treating `limit === 0` as unbounded history.
|
|
||||||
- Building file paths from raw session ids without validation.
|
|
||||||
- Hardcoding a skill root without checking the provider's actual discovery rules.
|
|
||||||
- Forgetting that Claude plugin skills are discovered differently from normal
|
|
||||||
user/project skill folders.
|
|
||||||
- Assuming one provider's MCP config file format works for the others.
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
export { sessionSynchronizerService } from './services/session-synchronizer.service.js';
|
export { sessionSynchronizerService } from './services/session-synchronizer.service.js';
|
||||||
export { providerSkillsService } from './services/skills.service.js';
|
|
||||||
|
|
||||||
export { initializeSessionsWatcher } from './services/sessions-watcher.service.js';
|
export { initializeSessionsWatcher } from './services/sessions-watcher.service.js';
|
||||||
export { closeSessionsWatcher } from './services/sessions-watcher.service.js';
|
export { closeSessionsWatcher } from './services/sessions-watcher.service.js';
|
||||||
@@ -157,14 +157,9 @@ export class ClaudeSessionSynchronizer implements IProviderSessionSynchronizer {
|
|||||||
const eventSessionId = typeof data.sessionId === 'string' ? data.sessionId : undefined;
|
const eventSessionId = typeof data.sessionId === 'string' ? data.sessionId : undefined;
|
||||||
const aiTitle = typeof data.aiTitle === 'string' ? data.aiTitle : undefined;
|
const aiTitle = typeof data.aiTitle === 'string' ? data.aiTitle : undefined;
|
||||||
const lastPrompt = typeof data.lastPrompt === 'string' ? data.lastPrompt : undefined;
|
const lastPrompt = typeof data.lastPrompt === 'string' ? data.lastPrompt : undefined;
|
||||||
const claudeRenamedTitle = typeof data.customTitle === 'string' ? data.customTitle : undefined;
|
|
||||||
|
|
||||||
if (
|
if ((eventType === 'ai-title' && eventSessionId === sessionId && aiTitle?.trim()) || (eventType === 'last-prompt' && eventSessionId === sessionId && lastPrompt?.trim())) {
|
||||||
(eventType === 'ai-title' && eventSessionId === sessionId && aiTitle?.trim()) ||
|
return aiTitle || lastPrompt;
|
||||||
(eventType === 'last-prompt' && eventSessionId === sessionId && lastPrompt?.trim()) ||
|
|
||||||
(eventType === "custom-title" && eventSessionId === sessionId && claudeRenamedTitle?.trim())
|
|
||||||
) {
|
|
||||||
return aiTitle || lastPrompt || claudeRenamedTitle;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
|
|||||||
@@ -200,18 +200,17 @@ async function getSessionMessages(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Claude writes a mix of truly internal transcript rows and "UI-hidden" local
|
* Claude writes internal command and system reminder entries into history.
|
||||||
* command artifacts into the same JSONL stream.
|
* Those are useful for the CLI but should not appear in the user-facing chat.
|
||||||
*
|
|
||||||
* Important distinction:
|
|
||||||
* - system reminders / caveats / interruption banners should stay hidden
|
|
||||||
* - local command payloads (`<command-name>...`) and stdout wrappers
|
|
||||||
* (`<local-command-stdout>...`) should be remapped into normal chat messages
|
|
||||||
* instead of being discarded as internal content
|
|
||||||
*/
|
*/
|
||||||
const INTERNAL_CONTENT_PREFIXES = [
|
const INTERNAL_CONTENT_PREFIXES = [
|
||||||
|
'<command-name>',
|
||||||
|
'<command-message>',
|
||||||
|
'<command-args>',
|
||||||
|
'<local-command-stdout>',
|
||||||
'<system-reminder>',
|
'<system-reminder>',
|
||||||
'Caveat:',
|
'Caveat:',
|
||||||
|
'This session is being continued from a previous',
|
||||||
'[Request interrupted',
|
'[Request interrupted',
|
||||||
] as const;
|
] as const;
|
||||||
|
|
||||||
@@ -219,73 +218,6 @@ function isInternalContent(content: string): boolean {
|
|||||||
return INTERNAL_CONTENT_PREFIXES.some((prefix) => content.startsWith(prefix));
|
return INTERNAL_CONTENT_PREFIXES.some((prefix) => content.startsWith(prefix));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Claude wraps local slash-command metadata in lightweight XML-like tags inside
|
|
||||||
* a plain string payload. We intentionally parse only the small tag surface we
|
|
||||||
* care about instead of introducing a generic XML parser for untrusted history.
|
|
||||||
*/
|
|
||||||
function extractTaggedContent(content: string, tagName: string): string | null {
|
|
||||||
const escapedTagName = tagName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
||||||
const match = new RegExp(`<${escapedTagName}>([\\s\\S]*?)<\\/${escapedTagName}>`).exec(content);
|
|
||||||
return match ? match[1] : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
type ClaudeLocalCommandPayload = {
|
|
||||||
commandName: string;
|
|
||||||
commandMessage: string;
|
|
||||||
commandArgs: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts Claude's hidden local command wrapper into structured metadata.
|
|
||||||
*
|
|
||||||
* The three tags often coexist in one string payload. Returning `null` lets the
|
|
||||||
* normal text path continue untouched for unrelated messages.
|
|
||||||
*/
|
|
||||||
function parseLocalCommandPayload(content: string): ClaudeLocalCommandPayload | null {
|
|
||||||
const commandName = extractTaggedContent(content, 'command-name');
|
|
||||||
const commandMessage = extractTaggedContent(content, 'command-message');
|
|
||||||
const commandArgs = extractTaggedContent(content, 'command-args');
|
|
||||||
|
|
||||||
if (commandName === null && commandMessage === null && commandArgs === null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
commandName: commandName ?? '',
|
|
||||||
commandMessage: commandMessage ?? '',
|
|
||||||
commandArgs: commandArgs ?? '',
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Produces the short user-visible command string that should appear in chat.
|
|
||||||
*
|
|
||||||
* We prefer the slash-prefixed command name because that most closely matches
|
|
||||||
* what the user actually typed, and only fall back to the message body when the
|
|
||||||
* command name is unavailable in older transcript variants.
|
|
||||||
*/
|
|
||||||
function buildLocalCommandDisplayText(payload: ClaudeLocalCommandPayload): string {
|
|
||||||
const commandName = payload.commandName.trim();
|
|
||||||
const commandMessage = payload.commandMessage.trim();
|
|
||||||
const commandArgs = payload.commandArgs.trim();
|
|
||||||
const baseCommand = commandName || commandMessage;
|
|
||||||
|
|
||||||
if (!baseCommand) {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
return commandArgs ? `${baseCommand} ${commandArgs}` : baseCommand;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Claude local-command stdout may contain ANSI styling codes because it was
|
|
||||||
* captured from the terminal. The web chat should receive readable plain text.
|
|
||||||
*/
|
|
||||||
function stripAnsiFormatting(text: string): string {
|
|
||||||
return text.replace(/\u001B\[[0-9;?]*[ -/]*[@-~]/g, '');
|
|
||||||
}
|
|
||||||
|
|
||||||
export class ClaudeSessionsProvider implements IProviderSessions {
|
export class ClaudeSessionsProvider implements IProviderSessions {
|
||||||
/**
|
/**
|
||||||
* Normalizes one Claude JSONL entry or live SDK stream event into the shared
|
* Normalizes one Claude JSONL entry or live SDK stream event into the shared
|
||||||
@@ -308,7 +240,7 @@ export class ClaudeSessionsProvider implements IProviderSessions {
|
|||||||
const ts = raw.timestamp || new Date().toISOString();
|
const ts = raw.timestamp || new Date().toISOString();
|
||||||
const baseId = raw.uuid || generateMessageId('claude');
|
const baseId = raw.uuid || generateMessageId('claude');
|
||||||
|
|
||||||
if (raw.message?.role === 'user' && raw.message?.content && raw.isMeta !== true) {
|
if (raw.message?.role === 'user' && raw.message?.content) {
|
||||||
if (Array.isArray(raw.message.content)) {
|
if (Array.isArray(raw.message.content)) {
|
||||||
for (let partIndex = 0; partIndex < raw.message.content.length; partIndex++) {
|
for (let partIndex = 0; partIndex < raw.message.content.length; partIndex++) {
|
||||||
const part = raw.message.content[partIndex];
|
const part = raw.message.content[partIndex];
|
||||||
@@ -361,80 +293,6 @@ export class ClaudeSessionsProvider implements IProviderSessions {
|
|||||||
}
|
}
|
||||||
} else if (typeof raw.message.content === 'string') {
|
} else if (typeof raw.message.content === 'string') {
|
||||||
const text = raw.message.content;
|
const text = raw.message.content;
|
||||||
|
|
||||||
/**
|
|
||||||
* Claude stores compact summaries as synthetic "user" rows so the CLI
|
|
||||||
* can resume the next session turn with the summary in-context.
|
|
||||||
*
|
|
||||||
* For the web UI this is much more useful as assistant-authored summary
|
|
||||||
* text; otherwise it is both filtered by the generic internal-prefix
|
|
||||||
* check and visually mislabeled as a user message.
|
|
||||||
*/
|
|
||||||
if (raw.isCompactSummary === true && text.trim()) {
|
|
||||||
messages.push(createNormalizedMessage({
|
|
||||||
id: baseId,
|
|
||||||
sessionId,
|
|
||||||
timestamp: ts,
|
|
||||||
provider: PROVIDER,
|
|
||||||
kind: 'text',
|
|
||||||
role: 'assistant',
|
|
||||||
content: text,
|
|
||||||
isCompactSummary: true,
|
|
||||||
}));
|
|
||||||
return messages;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Local slash commands are serialized as tagged text even though they
|
|
||||||
* are semantically a user action. Expose the parsed fields to the
|
|
||||||
* frontend and emit a plain user-visible command string so the command
|
|
||||||
* no longer disappears from history.
|
|
||||||
*/
|
|
||||||
const localCommandPayload = parseLocalCommandPayload(text);
|
|
||||||
if (localCommandPayload) {
|
|
||||||
const displayText = buildLocalCommandDisplayText(localCommandPayload);
|
|
||||||
if (displayText) {
|
|
||||||
messages.push(createNormalizedMessage({
|
|
||||||
id: baseId,
|
|
||||||
sessionId,
|
|
||||||
timestamp: ts,
|
|
||||||
provider: PROVIDER,
|
|
||||||
kind: 'text',
|
|
||||||
role: 'user',
|
|
||||||
content: displayText,
|
|
||||||
commandName: localCommandPayload.commandName,
|
|
||||||
commandMessage: localCommandPayload.commandMessage,
|
|
||||||
commandArgs: localCommandPayload.commandArgs,
|
|
||||||
isLocalCommand: true,
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
return messages;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Local command stdout is also written as a "user" row in Claude's
|
|
||||||
* transcript, but it is terminal output produced in response to the
|
|
||||||
* command. Re-label it as assistant text so the chat transcript matches
|
|
||||||
* the actual conversational flow seen by the user.
|
|
||||||
*/
|
|
||||||
const localCommandStdout = extractTaggedContent(text, 'local-command-stdout');
|
|
||||||
if (localCommandStdout !== null) {
|
|
||||||
const stdoutText = stripAnsiFormatting(localCommandStdout).trim();
|
|
||||||
if (stdoutText) {
|
|
||||||
messages.push(createNormalizedMessage({
|
|
||||||
id: baseId,
|
|
||||||
sessionId,
|
|
||||||
timestamp: ts,
|
|
||||||
provider: PROVIDER,
|
|
||||||
kind: 'text',
|
|
||||||
role: 'assistant',
|
|
||||||
content: stdoutText,
|
|
||||||
isLocalCommandStdout: true,
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
return messages;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (text && !isInternalContent(text)) {
|
if (text && !isInternalContent(text)) {
|
||||||
messages.push(createNormalizedMessage({
|
messages.push(createNormalizedMessage({
|
||||||
id: baseId,
|
id: baseId,
|
||||||
@@ -556,9 +414,7 @@ export class ClaudeSessionsProvider implements IProviderSessions {
|
|||||||
|
|
||||||
let result: ClaudeHistoryResult;
|
let result: ClaudeHistoryResult;
|
||||||
try {
|
try {
|
||||||
// Load full history first so `total` reflects frontend-normalized messages,
|
result = await getSessionMessages(sessionId, limit, offset);
|
||||||
// not raw JSONL records.
|
|
||||||
result = await getSessionMessages(sessionId, null, 0);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const message = error instanceof Error ? error.message : String(error);
|
const message = error instanceof Error ? error.message : String(error);
|
||||||
console.warn(`[ClaudeProvider] Failed to load session ${sessionId}:`, message);
|
console.warn(`[ClaudeProvider] Failed to load session ${sessionId}:`, message);
|
||||||
@@ -566,6 +422,8 @@ export class ClaudeSessionsProvider implements IProviderSessions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const rawMessages = Array.isArray(result) ? result : (result.messages || []);
|
const rawMessages = Array.isArray(result) ? result : (result.messages || []);
|
||||||
|
const total = Array.isArray(result) ? rawMessages.length : (result.total || 0);
|
||||||
|
const hasMore = Array.isArray(result) ? false : Boolean(result.hasMore);
|
||||||
|
|
||||||
const toolResultMap = new Map<string, ClaudeToolResult>();
|
const toolResultMap = new Map<string, ClaudeToolResult>();
|
||||||
for (const raw of rawMessages) {
|
for (const raw of rawMessages) {
|
||||||
@@ -606,31 +464,12 @@ export class ClaudeSessionsProvider implements IProviderSessions {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const totalNormalized = normalized.length;
|
|
||||||
let total = 0;
|
|
||||||
for (const msg of normalized) {
|
|
||||||
if (msg.kind !== 'tool_result') {
|
|
||||||
total += 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const normalizedOffset = Math.max(0, offset);
|
|
||||||
const normalizedLimit = limit === null ? null : Math.max(0, limit);
|
|
||||||
const messages = normalizedLimit === null
|
|
||||||
? normalized
|
|
||||||
: normalized.slice(
|
|
||||||
Math.max(0, totalNormalized - normalizedOffset - normalizedLimit),
|
|
||||||
Math.max(0, totalNormalized - normalizedOffset),
|
|
||||||
);
|
|
||||||
const hasMore = normalizedLimit === null
|
|
||||||
? false
|
|
||||||
: Math.max(0, totalNormalized - normalizedOffset - normalizedLimit) > 0;
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
messages,
|
messages: normalized,
|
||||||
total,
|
total,
|
||||||
hasMore,
|
hasMore,
|
||||||
offset: normalizedOffset,
|
offset,
|
||||||
limit: normalizedLimit,
|
limit,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,257 +0,0 @@
|
|||||||
import { readFile, readdir, stat } from 'node:fs/promises';
|
|
||||||
import os from 'node:os';
|
|
||||||
import path from 'node:path';
|
|
||||||
|
|
||||||
import { SkillsProvider } from '@/modules/providers/shared/skills/skills.provider.js';
|
|
||||||
import { parseFrontMatter } from '@/shared/frontmatter.js';
|
|
||||||
import type {
|
|
||||||
ProviderSkill,
|
|
||||||
ProviderSkillListOptions,
|
|
||||||
ProviderSkillSource,
|
|
||||||
} from '@/shared/types.js';
|
|
||||||
import {
|
|
||||||
findProviderSkillMarkdownFiles,
|
|
||||||
readJsonConfig,
|
|
||||||
readObjectRecord,
|
|
||||||
readOptionalString,
|
|
||||||
readProviderSkillMarkdownDefinition,
|
|
||||||
} from '@/shared/utils.js';
|
|
||||||
|
|
||||||
const getClaudeHomePath = (): string => path.join(os.homedir(), '.claude');
|
|
||||||
|
|
||||||
const getClaudePluginName = (pluginId: string): string | null => {
|
|
||||||
const normalizedPluginId = pluginId.trim();
|
|
||||||
if (!normalizedPluginId || normalizedPluginId === '@') {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
const [pluginName] = normalizedPluginId.split('@');
|
|
||||||
return readOptionalString(pluginName) ?? null;
|
|
||||||
};
|
|
||||||
|
|
||||||
const stripMarkdownExtension = (filename: string): string =>
|
|
||||||
filename.replace(/\.md$/i, '');
|
|
||||||
|
|
||||||
const pathExistsAsDirectory = async (directoryPath: string): Promise<boolean> => {
|
|
||||||
try {
|
|
||||||
const directoryStats = await stat(directoryPath);
|
|
||||||
return directoryStats.isDirectory();
|
|
||||||
} catch {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const listChildDirectories = async (directoryPath: string): Promise<string[]> => {
|
|
||||||
try {
|
|
||||||
const entries = await readdir(directoryPath, { withFileTypes: true });
|
|
||||||
return entries
|
|
||||||
.filter((entry) => entry.isDirectory())
|
|
||||||
.map((entry) => path.join(directoryPath, entry.name))
|
|
||||||
.sort((left, right) => left.localeCompare(right));
|
|
||||||
} catch {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const readClaudePluginName = async (
|
|
||||||
installPath: string,
|
|
||||||
pluginId: string,
|
|
||||||
): Promise<string | null> => {
|
|
||||||
try {
|
|
||||||
const pluginConfig = await readJsonConfig(
|
|
||||||
path.join(installPath, '.claude-plugin', 'plugin.json'),
|
|
||||||
);
|
|
||||||
|
|
||||||
// Older or partial plugin installs may not have plugin.json yet. Falling
|
|
||||||
// back keeps discovery useful without inventing a separate namespace.
|
|
||||||
return readOptionalString(pluginConfig.name) ?? getClaudePluginName(pluginId);
|
|
||||||
} catch {
|
|
||||||
return getClaudePluginName(pluginId);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export class ClaudeSkillsProvider extends SkillsProvider {
|
|
||||||
constructor() {
|
|
||||||
super('claude');
|
|
||||||
}
|
|
||||||
|
|
||||||
async listSkills(options?: ProviderSkillListOptions): Promise<ProviderSkill[]> {
|
|
||||||
return [
|
|
||||||
...(await super.listSkills(options)),
|
|
||||||
...(await this.listPluginSkills(getClaudeHomePath())),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
protected async getSkillSources(workspacePath: string): Promise<ProviderSkillSource[]> {
|
|
||||||
const claudeHomePath = getClaudeHomePath();
|
|
||||||
|
|
||||||
return [
|
|
||||||
{
|
|
||||||
scope: 'user',
|
|
||||||
rootDir: path.join(claudeHomePath, 'skills'),
|
|
||||||
commandPrefix: '/',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
scope: 'project',
|
|
||||||
rootDir: path.join(workspacePath, '.claude', 'skills'),
|
|
||||||
commandPrefix: '/',
|
|
||||||
},
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
private async listPluginSkills(claudeHomePath: string): Promise<ProviderSkill[]> {
|
|
||||||
const settings = await readJsonConfig(path.join(claudeHomePath, 'settings.json'));
|
|
||||||
const enabledPlugins = readObjectRecord(settings.enabledPlugins);
|
|
||||||
if (!enabledPlugins) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
const installedConfig = await readJsonConfig(
|
|
||||||
path.join(claudeHomePath, 'plugins', 'installed_plugins.json'),
|
|
||||||
);
|
|
||||||
const installedPlugins = readObjectRecord(installedConfig.plugins);
|
|
||||||
if (!installedPlugins) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
const skills: ProviderSkill[] = [];
|
|
||||||
const visitedPluginFolders = new Set<string>();
|
|
||||||
const pluginEntries = Object.entries(enabledPlugins)
|
|
||||||
.sort(([left], [right]) => left.localeCompare(right));
|
|
||||||
for (const [pluginId, enabled] of pluginEntries) {
|
|
||||||
if (enabled !== true) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const installs = installedPlugins[pluginId];
|
|
||||||
if (!Array.isArray(installs)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const install of installs) {
|
|
||||||
const installRecord = readObjectRecord(install);
|
|
||||||
const installPath = readOptionalString(installRecord?.installPath);
|
|
||||||
if (!installPath) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Claude's installed path points at one version folder; the usable
|
|
||||||
// plugin payloads live in the direct child folders beside it.
|
|
||||||
const pluginFolders = await listChildDirectories(path.dirname(installPath));
|
|
||||||
for (const pluginFolder of pluginFolders) {
|
|
||||||
const pluginFolderKey = `${pluginId}:${path.resolve(pluginFolder)}`;
|
|
||||||
if (visitedPluginFolders.has(pluginFolderKey)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
visitedPluginFolders.add(pluginFolderKey);
|
|
||||||
|
|
||||||
const pluginName = await readClaudePluginName(pluginFolder, pluginId);
|
|
||||||
if (!pluginName) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const commandsPath = path.join(pluginFolder, 'commands');
|
|
||||||
if (await pathExistsAsDirectory(commandsPath)) {
|
|
||||||
skills.push(
|
|
||||||
...(await this.listPluginCommandSkills(commandsPath, pluginId, pluginName)),
|
|
||||||
);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const skillsPath = path.join(pluginFolder, 'skills');
|
|
||||||
if (!(await pathExistsAsDirectory(skillsPath))) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
skills.push(
|
|
||||||
...(await this.listPluginSkillMarkdowns(pluginFolder, pluginId, pluginName)),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return skills;
|
|
||||||
}
|
|
||||||
|
|
||||||
private async listPluginCommandSkills(
|
|
||||||
commandsPath: string,
|
|
||||||
pluginId: string,
|
|
||||||
pluginName: string,
|
|
||||||
): Promise<ProviderSkill[]> {
|
|
||||||
const skills: ProviderSkill[] = [];
|
|
||||||
|
|
||||||
try {
|
|
||||||
const entries = await readdir(commandsPath, { withFileTypes: true });
|
|
||||||
const commandFiles = entries
|
|
||||||
.filter((entry) => entry.isFile() && entry.name.toLowerCase().endsWith('.md'))
|
|
||||||
.sort((left, right) => left.name.localeCompare(right.name));
|
|
||||||
|
|
||||||
for (const commandFile of commandFiles) {
|
|
||||||
const sourcePath = path.join(commandsPath, commandFile.name);
|
|
||||||
try {
|
|
||||||
const definition = await this.readPluginCommandDefinition(sourcePath);
|
|
||||||
skills.push({
|
|
||||||
provider: this.provider,
|
|
||||||
name: definition.name,
|
|
||||||
description: definition.description,
|
|
||||||
command: `/${pluginName}:${definition.name}`,
|
|
||||||
scope: 'plugin',
|
|
||||||
sourcePath,
|
|
||||||
pluginName,
|
|
||||||
pluginId,
|
|
||||||
});
|
|
||||||
} catch {
|
|
||||||
// Malformed command markdown should not block sibling plugin commands.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
// Missing or unreadable command folders are treated as empty plugin command sets.
|
|
||||||
}
|
|
||||||
|
|
||||||
return skills;
|
|
||||||
}
|
|
||||||
|
|
||||||
private async readPluginCommandDefinition(
|
|
||||||
commandPath: string,
|
|
||||||
): Promise<{ name: string; description: string }> {
|
|
||||||
const content = await readFile(commandPath, 'utf8');
|
|
||||||
const parsed = parseFrontMatter(content);
|
|
||||||
const data = readObjectRecord(parsed.data) ?? {};
|
|
||||||
|
|
||||||
return {
|
|
||||||
name: stripMarkdownExtension(path.basename(commandPath)),
|
|
||||||
description: readOptionalString(data.description) ?? '',
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
private async listPluginSkillMarkdowns(
|
|
||||||
installPath: string,
|
|
||||||
pluginId: string,
|
|
||||||
pluginName: string,
|
|
||||||
): Promise<ProviderSkill[]> {
|
|
||||||
const skillFiles = await findProviderSkillMarkdownFiles(path.join(installPath, 'skills'), {
|
|
||||||
recursive: true,
|
|
||||||
});
|
|
||||||
const skills: ProviderSkill[] = [];
|
|
||||||
|
|
||||||
for (const skillPath of skillFiles) {
|
|
||||||
try {
|
|
||||||
const definition = await readProviderSkillMarkdownDefinition(skillPath);
|
|
||||||
skills.push({
|
|
||||||
provider: this.provider,
|
|
||||||
name: definition.name,
|
|
||||||
description: definition.description,
|
|
||||||
command: `/${pluginName}:${definition.name}`,
|
|
||||||
scope: 'plugin',
|
|
||||||
sourcePath: skillPath,
|
|
||||||
pluginName,
|
|
||||||
pluginId,
|
|
||||||
});
|
|
||||||
} catch {
|
|
||||||
// A bad plugin skill file should not block other installed plugin skills.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return skills;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -3,18 +3,11 @@ import { ClaudeProviderAuth } from '@/modules/providers/list/claude/claude-auth.
|
|||||||
import { ClaudeMcpProvider } from '@/modules/providers/list/claude/claude-mcp.provider.js';
|
import { ClaudeMcpProvider } from '@/modules/providers/list/claude/claude-mcp.provider.js';
|
||||||
import { ClaudeSessionSynchronizer } from '@/modules/providers/list/claude/claude-session-synchronizer.provider.js';
|
import { ClaudeSessionSynchronizer } from '@/modules/providers/list/claude/claude-session-synchronizer.provider.js';
|
||||||
import { ClaudeSessionsProvider } from '@/modules/providers/list/claude/claude-sessions.provider.js';
|
import { ClaudeSessionsProvider } from '@/modules/providers/list/claude/claude-sessions.provider.js';
|
||||||
import { ClaudeSkillsProvider } from '@/modules/providers/list/claude/claude-skills.provider.js';
|
import type { IProviderAuth, IProviderSessionSynchronizer, IProviderSessions } from '@/shared/interfaces.js';
|
||||||
import type {
|
|
||||||
IProviderAuth,
|
|
||||||
IProviderSessionSynchronizer,
|
|
||||||
IProviderSkills,
|
|
||||||
IProviderSessions,
|
|
||||||
} from '@/shared/interfaces.js';
|
|
||||||
|
|
||||||
export class ClaudeProvider extends AbstractProvider {
|
export class ClaudeProvider extends AbstractProvider {
|
||||||
readonly mcp = new ClaudeMcpProvider();
|
readonly mcp = new ClaudeMcpProvider();
|
||||||
readonly auth: IProviderAuth = new ClaudeProviderAuth();
|
readonly auth: IProviderAuth = new ClaudeProviderAuth();
|
||||||
readonly skills: IProviderSkills = new ClaudeSkillsProvider();
|
|
||||||
readonly sessions: IProviderSessions = new ClaudeSessionsProvider();
|
readonly sessions: IProviderSessions = new ClaudeSessionsProvider();
|
||||||
readonly sessionSynchronizer: IProviderSessionSynchronizer = new ClaudeSessionSynchronizer();
|
readonly sessionSynchronizer: IProviderSessionSynchronizer = new ClaudeSessionSynchronizer();
|
||||||
|
|
||||||
|
|||||||
@@ -520,9 +520,7 @@ export class CodexSessionsProvider implements IProviderSessions {
|
|||||||
|
|
||||||
let result: CodexHistoryResult;
|
let result: CodexHistoryResult;
|
||||||
try {
|
try {
|
||||||
// Load full history first so `total` reflects frontend-normalized messages,
|
result = await getCodexSessionMessages(sessionId, limit, offset);
|
||||||
// not raw JSONL records.
|
|
||||||
result = await getCodexSessionMessages(sessionId, null, 0);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const message = error instanceof Error ? error.message : String(error);
|
const message = error instanceof Error ? error.message : String(error);
|
||||||
console.warn(`[CodexProvider] Failed to load session ${sessionId}:`, message);
|
console.warn(`[CodexProvider] Failed to load session ${sessionId}:`, message);
|
||||||
@@ -530,6 +528,8 @@ export class CodexSessionsProvider implements IProviderSessions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const rawMessages = Array.isArray(result) ? result : (result.messages || []);
|
const rawMessages = Array.isArray(result) ? result : (result.messages || []);
|
||||||
|
const total = Array.isArray(result) ? rawMessages.length : (result.total || 0);
|
||||||
|
const hasMore = Array.isArray(result) ? false : Boolean(result.hasMore);
|
||||||
const tokenUsage = Array.isArray(result) ? undefined : result.tokenUsage;
|
const tokenUsage = Array.isArray(result) ? undefined : result.tokenUsage;
|
||||||
|
|
||||||
const normalized: NormalizedMessage[] = [];
|
const normalized: NormalizedMessage[] = [];
|
||||||
@@ -552,31 +552,12 @@ export class CodexSessionsProvider implements IProviderSessions {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const totalNormalized = normalized.length;
|
|
||||||
let total = 0;
|
|
||||||
for (const msg of normalized) {
|
|
||||||
if (msg.kind !== 'tool_result') {
|
|
||||||
total += 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const normalizedOffset = Math.max(0, offset);
|
|
||||||
const normalizedLimit = limit === null ? null : Math.max(0, limit);
|
|
||||||
const messages = normalizedLimit === null
|
|
||||||
? normalized
|
|
||||||
: normalized.slice(
|
|
||||||
Math.max(0, totalNormalized - normalizedOffset - normalizedLimit),
|
|
||||||
Math.max(0, totalNormalized - normalizedOffset),
|
|
||||||
);
|
|
||||||
const hasMore = normalizedLimit === null
|
|
||||||
? false
|
|
||||||
: Math.max(0, totalNormalized - normalizedOffset - normalizedLimit) > 0;
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
messages,
|
messages: normalized,
|
||||||
total,
|
total,
|
||||||
hasMore,
|
hasMore,
|
||||||
offset: normalizedOffset,
|
offset,
|
||||||
limit: normalizedLimit,
|
limit,
|
||||||
tokenUsage,
|
tokenUsage,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,100 +0,0 @@
|
|||||||
import fs from 'node:fs/promises';
|
|
||||||
import os from 'node:os';
|
|
||||||
import path from 'node:path';
|
|
||||||
|
|
||||||
import { SkillsProvider } from '@/modules/providers/shared/skills/skills.provider.js';
|
|
||||||
import type { ProviderSkillSource } from '@/shared/types.js';
|
|
||||||
|
|
||||||
const hasGitMarker = async (dirPath: string): Promise<boolean> => {
|
|
||||||
try {
|
|
||||||
const gitMarkerStats = await fs.stat(path.join(dirPath, '.git'));
|
|
||||||
return gitMarkerStats.isDirectory() || gitMarkerStats.isFile();
|
|
||||||
} catch {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const findTopmostGitRoot = async (startPath: string): Promise<string | null> => {
|
|
||||||
let currentPath = path.resolve(startPath);
|
|
||||||
let topmostGitRoot: string | null = null;
|
|
||||||
|
|
||||||
while (true) {
|
|
||||||
if (await hasGitMarker(currentPath)) {
|
|
||||||
topmostGitRoot = currentPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
const parentPath = path.dirname(currentPath);
|
|
||||||
if (parentPath === currentPath) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
currentPath = parentPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
return topmostGitRoot;
|
|
||||||
};
|
|
||||||
|
|
||||||
const addUniqueSource = (
|
|
||||||
sources: ProviderSkillSource[],
|
|
||||||
seenRootDirs: Set<string>,
|
|
||||||
source: ProviderSkillSource,
|
|
||||||
): void => {
|
|
||||||
const normalizedRootDir = path.resolve(source.rootDir);
|
|
||||||
if (seenRootDirs.has(normalizedRootDir)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
seenRootDirs.add(normalizedRootDir);
|
|
||||||
sources.push({ ...source, rootDir: normalizedRootDir });
|
|
||||||
};
|
|
||||||
|
|
||||||
export class CodexSkillsProvider extends SkillsProvider {
|
|
||||||
constructor() {
|
|
||||||
super('codex');
|
|
||||||
}
|
|
||||||
|
|
||||||
protected async getSkillSources(workspacePath: string): Promise<ProviderSkillSource[]> {
|
|
||||||
const sources: ProviderSkillSource[] = [];
|
|
||||||
const seenRootDirs = new Set<string>();
|
|
||||||
const repoRoot = await findTopmostGitRoot(workspacePath);
|
|
||||||
|
|
||||||
addUniqueSource(sources, seenRootDirs, {
|
|
||||||
scope: 'repo',
|
|
||||||
rootDir: path.join(workspacePath, '.agents', 'skills'),
|
|
||||||
commandPrefix: '$',
|
|
||||||
});
|
|
||||||
|
|
||||||
if (repoRoot) {
|
|
||||||
// Codex checks repository skills at the launch folder, one folder above it,
|
|
||||||
// and the topmost git root; these can collapse to the same directory.
|
|
||||||
addUniqueSource(sources, seenRootDirs, {
|
|
||||||
scope: 'repo',
|
|
||||||
rootDir: path.join(path.dirname(workspacePath), '.agents', 'skills'),
|
|
||||||
commandPrefix: '$',
|
|
||||||
});
|
|
||||||
addUniqueSource(sources, seenRootDirs, {
|
|
||||||
scope: 'repo',
|
|
||||||
rootDir: path.join(repoRoot, '.agents', 'skills'),
|
|
||||||
commandPrefix: '$',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
addUniqueSource(sources, seenRootDirs, {
|
|
||||||
scope: 'user',
|
|
||||||
rootDir: path.join(os.homedir(), '.agents', 'skills'),
|
|
||||||
commandPrefix: '$',
|
|
||||||
});
|
|
||||||
addUniqueSource(sources, seenRootDirs, {
|
|
||||||
scope: 'admin',
|
|
||||||
rootDir: path.join('/etc', 'codex', 'skills'),
|
|
||||||
commandPrefix: '$',
|
|
||||||
});
|
|
||||||
addUniqueSource(sources, seenRootDirs, {
|
|
||||||
scope: 'system',
|
|
||||||
rootDir: path.join(os.homedir(), '.codex', 'skills', '.system'),
|
|
||||||
commandPrefix: '$',
|
|
||||||
});
|
|
||||||
|
|
||||||
return sources;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -3,18 +3,11 @@ import { CodexProviderAuth } from '@/modules/providers/list/codex/codex-auth.pro
|
|||||||
import { CodexMcpProvider } from '@/modules/providers/list/codex/codex-mcp.provider.js';
|
import { CodexMcpProvider } from '@/modules/providers/list/codex/codex-mcp.provider.js';
|
||||||
import { CodexSessionSynchronizer } from '@/modules/providers/list/codex/codex-session-synchronizer.provider.js';
|
import { CodexSessionSynchronizer } from '@/modules/providers/list/codex/codex-session-synchronizer.provider.js';
|
||||||
import { CodexSessionsProvider } from '@/modules/providers/list/codex/codex-sessions.provider.js';
|
import { CodexSessionsProvider } from '@/modules/providers/list/codex/codex-sessions.provider.js';
|
||||||
import { CodexSkillsProvider } from '@/modules/providers/list/codex/codex-skills.provider.js';
|
import type { IProviderAuth, IProviderSessionSynchronizer, IProviderSessions } from '@/shared/interfaces.js';
|
||||||
import type {
|
|
||||||
IProviderAuth,
|
|
||||||
IProviderSessionSynchronizer,
|
|
||||||
IProviderSkills,
|
|
||||||
IProviderSessions,
|
|
||||||
} from '@/shared/interfaces.js';
|
|
||||||
|
|
||||||
export class CodexProvider extends AbstractProvider {
|
export class CodexProvider extends AbstractProvider {
|
||||||
readonly mcp = new CodexMcpProvider();
|
readonly mcp = new CodexMcpProvider();
|
||||||
readonly auth: IProviderAuth = new CodexProviderAuth();
|
readonly auth: IProviderAuth = new CodexProviderAuth();
|
||||||
readonly skills: IProviderSkills = new CodexSkillsProvider();
|
|
||||||
readonly sessions: IProviderSessions = new CodexSessionsProvider();
|
readonly sessions: IProviderSessions = new CodexSessionsProvider();
|
||||||
readonly sessionSynchronizer: IProviderSessionSynchronizer = new CodexSessionSynchronizer();
|
readonly sessionSynchronizer: IProviderSessionSynchronizer = new CodexSessionSynchronizer();
|
||||||
|
|
||||||
|
|||||||
@@ -45,28 +45,44 @@ export class CursorSessionSynchronizer implements IProviderSessionSynchronizer {
|
|||||||
*/
|
*/
|
||||||
async synchronize(since?: Date): Promise<number> {
|
async synchronize(since?: Date): Promise<number> {
|
||||||
const projectsDir = path.join(this.cursorHome, 'projects');
|
const projectsDir = path.join(this.cursorHome, 'projects');
|
||||||
|
const projectEntries = await listDirectoryEntriesSafe(projectsDir);
|
||||||
|
const seenProjectPaths = new Set<string>();
|
||||||
|
|
||||||
let processed = 0;
|
let processed = 0;
|
||||||
|
for (const entry of projectEntries) {
|
||||||
const files = await findFilesRecursivelyCreatedAfter(projectsDir, '.jsonl', since ?? null);
|
if (!entry.isDirectory()) {
|
||||||
|
|
||||||
for (const filePath of files) {
|
|
||||||
const parsed = await this.processSessionFile(filePath);
|
|
||||||
if (!parsed) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const timestamps = await readFileTimestamps(filePath);
|
const workerLogPath = path.join(projectsDir, entry.name, 'worker.log');
|
||||||
sessionsDb.createSession(
|
const projectPath = await this.extractProjectPathFromWorkerLog(workerLogPath);
|
||||||
parsed.sessionId,
|
if (!projectPath || seenProjectPaths.has(projectPath)) {
|
||||||
this.provider,
|
continue;
|
||||||
parsed.projectPath,
|
}
|
||||||
parsed.sessionName,
|
|
||||||
timestamps.createdAt,
|
seenProjectPaths.add(projectPath);
|
||||||
timestamps.updatedAt,
|
const projectHash = this.md5(projectPath);
|
||||||
filePath
|
const chatsDir = path.join(this.cursorHome, 'chats', projectHash);
|
||||||
);
|
const files = await findFilesRecursivelyCreatedAfter(chatsDir, '.jsonl', since ?? null);
|
||||||
processed += 1;
|
|
||||||
|
for (const filePath of files) {
|
||||||
|
const parsed = await this.processSessionFile(filePath);
|
||||||
|
if (!parsed) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const timestamps = await readFileTimestamps(filePath);
|
||||||
|
sessionsDb.createSession(
|
||||||
|
parsed.sessionId,
|
||||||
|
this.provider,
|
||||||
|
parsed.projectPath,
|
||||||
|
parsed.sessionName,
|
||||||
|
timestamps.createdAt,
|
||||||
|
timestamps.updatedAt,
|
||||||
|
filePath
|
||||||
|
);
|
||||||
|
processed += 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return processed;
|
return processed;
|
||||||
@@ -97,6 +113,13 @@ export class CursorSessionSynchronizer implements IProviderSessionSynchronizer {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Produces the same project hash Cursor uses in chat directory names.
|
||||||
|
*/
|
||||||
|
private md5(input: string): string {
|
||||||
|
return crypto.createHash('md5').update(input).digest('hex');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extracts project path from Cursor worker.log.
|
* Extracts project path from Cursor worker.log.
|
||||||
*/
|
*/
|
||||||
@@ -126,7 +149,7 @@ export class CursorSessionSynchronizer implements IProviderSessionSynchronizer {
|
|||||||
*/
|
*/
|
||||||
private async processSessionFile(filePath: string): Promise<ParsedSession | null> {
|
private async processSessionFile(filePath: string): Promise<ParsedSession | null> {
|
||||||
const sessionId = path.basename(filePath, '.jsonl');
|
const sessionId = path.basename(filePath, '.jsonl');
|
||||||
const grandparentDir = path.dirname(path.dirname(path.dirname(filePath)));
|
const grandparentDir = path.dirname(path.dirname(filePath));
|
||||||
const workerLogPath = path.join(grandparentDir, 'worker.log');
|
const workerLogPath = path.join(grandparentDir, 'worker.log');
|
||||||
const projectPath = await this.extractProjectPathFromWorkerLog(workerLogPath);
|
const projectPath = await this.extractProjectPathFromWorkerLog(workerLogPath);
|
||||||
|
|
||||||
|
|||||||
@@ -25,167 +25,6 @@ type CursorMessageBlob = {
|
|||||||
content: AnyRecord;
|
content: AnyRecord;
|
||||||
};
|
};
|
||||||
|
|
||||||
function isInternalCursorText(value: unknown): boolean {
|
|
||||||
if (typeof value !== 'string') {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const normalized = value.trim();
|
|
||||||
return normalized.startsWith('<user_info>') || normalized.startsWith('<system_reminder>');
|
|
||||||
}
|
|
||||||
|
|
||||||
function isInternalCursorPart(part: unknown): boolean {
|
|
||||||
if (!part || typeof part !== 'object') {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const record = part as AnyRecord;
|
|
||||||
const type = typeof record.type === 'string' ? record.type : '';
|
|
||||||
if (type === 'user_info' || type === 'system_reminder') {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return isInternalCursorText(record.text);
|
|
||||||
}
|
|
||||||
|
|
||||||
function unwrapUserQueryText(value: string, role: 'user' | 'assistant'): string {
|
|
||||||
if (role !== 'user') {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
const normalized = value.trimStart();
|
|
||||||
const openTag = '<user_query>';
|
|
||||||
const closeTag = '</user_query>';
|
|
||||||
if (!normalized.startsWith(openTag)) {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
const afterOpen = normalized.slice(openTag.length);
|
|
||||||
const closeIndex = afterOpen.lastIndexOf(closeTag);
|
|
||||||
const inner = closeIndex >= 0 ? afterOpen.slice(0, closeIndex) : afterOpen;
|
|
||||||
return inner.trim();
|
|
||||||
}
|
|
||||||
|
|
||||||
function normalizeToolId(value: unknown): string | null {
|
|
||||||
if (typeof value !== 'string') {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
const normalized = value.trim();
|
|
||||||
return normalized ? normalized : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
function extractCursorToolResultContent(item: AnyRecord): string {
|
|
||||||
if (typeof item.result === 'string' && item.result.trim()) {
|
|
||||||
return item.result;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof item.output === 'string' && item.output.trim()) {
|
|
||||||
return item.output;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Array.isArray(item.experimental_content)) {
|
|
||||||
const experimentalText = item.experimental_content
|
|
||||||
.map((part: unknown) => {
|
|
||||||
if (typeof part === 'string') {
|
|
||||||
return part;
|
|
||||||
}
|
|
||||||
if (part && typeof part === 'object') {
|
|
||||||
const record = part as AnyRecord;
|
|
||||||
if (typeof record.text === 'string') {
|
|
||||||
return record.text;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return '';
|
|
||||||
})
|
|
||||||
.filter(Boolean)
|
|
||||||
.join('\n');
|
|
||||||
|
|
||||||
if (experimentalText.trim()) {
|
|
||||||
return experimentalText;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return typeof item.result === 'string' ? item.result : '';
|
|
||||||
}
|
|
||||||
|
|
||||||
function parseCursorToolInput(rawInput: unknown): unknown {
|
|
||||||
if (typeof rawInput !== 'string') {
|
|
||||||
return rawInput;
|
|
||||||
}
|
|
||||||
|
|
||||||
const trimmed = rawInput.trim();
|
|
||||||
if (!trimmed) {
|
|
||||||
return rawInput;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
return JSON.parse(trimmed);
|
|
||||||
} catch {
|
|
||||||
return rawInput;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function normalizeCursorToolInput(toolName: string, rawInput: unknown): unknown {
|
|
||||||
const parsed = parseCursorToolInput(rawInput);
|
|
||||||
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
|
||||||
return parsed;
|
|
||||||
}
|
|
||||||
|
|
||||||
const input = parsed as AnyRecord;
|
|
||||||
const normalized: AnyRecord = { ...input };
|
|
||||||
|
|
||||||
const filePath = input.file_path
|
|
||||||
?? input.filePath
|
|
||||||
?? input.path
|
|
||||||
?? input.file
|
|
||||||
?? input.filename;
|
|
||||||
if (typeof filePath === 'string' && filePath.trim()) {
|
|
||||||
normalized.file_path = filePath;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (toolName === 'Write') {
|
|
||||||
const content = input.content
|
|
||||||
?? input.text
|
|
||||||
?? input.value
|
|
||||||
?? input.contents
|
|
||||||
?? input.fileContent
|
|
||||||
?? input.new_string
|
|
||||||
?? input.newString;
|
|
||||||
if (typeof content === 'string') {
|
|
||||||
normalized.content = content;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (toolName === 'Edit') {
|
|
||||||
const oldString = input.old_string
|
|
||||||
?? input.oldString
|
|
||||||
?? input.old
|
|
||||||
?? '';
|
|
||||||
const newString = input.new_string
|
|
||||||
?? input.newString
|
|
||||||
?? input.new
|
|
||||||
?? input.content
|
|
||||||
?? '';
|
|
||||||
|
|
||||||
if (typeof oldString === 'string') {
|
|
||||||
normalized.old_string = oldString;
|
|
||||||
}
|
|
||||||
if (typeof newString === 'string') {
|
|
||||||
normalized.new_string = newString;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (toolName === 'ApplyPatch') {
|
|
||||||
const patch = input.patch ?? input.diff ?? input.content;
|
|
||||||
if (typeof patch === 'string' && !normalized.patch) {
|
|
||||||
normalized.patch = patch;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return normalized;
|
|
||||||
}
|
|
||||||
|
|
||||||
function sanitizeCursorSessionId(sessionId: string): string {
|
function sanitizeCursorSessionId(sessionId: string): string {
|
||||||
const normalized = sessionId.trim();
|
const normalized = sessionId.trim();
|
||||||
if (!normalized) {
|
if (!normalized) {
|
||||||
@@ -386,14 +225,13 @@ export class CursorSessionsProvider implements IProviderSessions {
|
|||||||
try {
|
try {
|
||||||
const blobs = await this.loadCursorBlobs(sessionId, projectPath);
|
const blobs = await this.loadCursorBlobs(sessionId, projectPath);
|
||||||
const allNormalized = this.normalizeCursorBlobs(blobs, sessionId);
|
const allNormalized = this.normalizeCursorBlobs(blobs, sessionId);
|
||||||
const renderableMessages = allNormalized.filter((msg) => msg.kind !== 'tool_result');
|
const total = allNormalized.length;
|
||||||
const total = renderableMessages.length;
|
|
||||||
|
|
||||||
if (limit !== null) {
|
if (limit !== null) {
|
||||||
const start = offset;
|
const start = offset;
|
||||||
const page = limit === 0
|
const page = limit === 0
|
||||||
? []
|
? []
|
||||||
: renderableMessages.slice(start, start + limit);
|
: allNormalized.slice(start, start + limit);
|
||||||
const hasMore = limit === 0
|
const hasMore = limit === 0
|
||||||
? start < total
|
? start < total
|
||||||
: start + limit < total;
|
: start + limit < total;
|
||||||
@@ -407,7 +245,7 @@ export class CursorSessionsProvider implements IProviderSessions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
messages: renderableMessages,
|
messages: allNormalized,
|
||||||
total,
|
total,
|
||||||
hasMore: false,
|
hasMore: false,
|
||||||
offset: 0,
|
offset: 0,
|
||||||
@@ -445,24 +283,11 @@ export class CursorSessionsProvider implements IProviderSessions {
|
|||||||
let text = '';
|
let text = '';
|
||||||
if (Array.isArray(content.message.content)) {
|
if (Array.isArray(content.message.content)) {
|
||||||
text = content.message.content
|
text = content.message.content
|
||||||
.map((part: string | AnyRecord) => {
|
.map((part: string | AnyRecord) => typeof part === 'string' ? part : part?.text || '')
|
||||||
if (typeof part === 'string') {
|
|
||||||
if (isInternalCursorText(part)) {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
return unwrapUserQueryText(part, role);
|
|
||||||
}
|
|
||||||
if (isInternalCursorPart(part)) {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
return unwrapUserQueryText(part?.text || '', role);
|
|
||||||
})
|
|
||||||
.filter(Boolean)
|
.filter(Boolean)
|
||||||
.join('\n');
|
.join('\n');
|
||||||
} else if (typeof content.message.content === 'string') {
|
} else if (typeof content.message.content === 'string') {
|
||||||
if (!isInternalCursorText(content.message.content)) {
|
text = content.message.content;
|
||||||
text = unwrapUserQueryText(content.message.content, role);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (text?.trim()) {
|
if (text?.trim()) {
|
||||||
messages.push(createNormalizedMessage({
|
messages.push(createNormalizedMessage({
|
||||||
@@ -491,14 +316,7 @@ export class CursorSessionsProvider implements IProviderSessions {
|
|||||||
if (item?.type !== 'tool-result') {
|
if (item?.type !== 'tool-result') {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const cursorOptions = content.providerOptions?.cursor as AnyRecord | undefined;
|
const toolCallId = item.toolCallId || content.id;
|
||||||
const highLevelToolCallResult = cursorOptions?.highLevelToolCallResult;
|
|
||||||
const toolCallId = normalizeToolId(item.toolCallId)
|
|
||||||
|| normalizeToolId(item.tool_call_id)
|
|
||||||
|| normalizeToolId(highLevelToolCallResult?.toolCallId)
|
|
||||||
|| normalizeToolId(highLevelToolCallResult?.tool_call_id)
|
|
||||||
|| normalizeToolId(content.id)
|
|
||||||
|| '';
|
|
||||||
messages.push(createNormalizedMessage({
|
messages.push(createNormalizedMessage({
|
||||||
id: `${baseId}_tr`,
|
id: `${baseId}_tr`,
|
||||||
sessionId,
|
sessionId,
|
||||||
@@ -506,9 +324,8 @@ export class CursorSessionsProvider implements IProviderSessions {
|
|||||||
provider: PROVIDER,
|
provider: PROVIDER,
|
||||||
kind: 'tool_result',
|
kind: 'tool_result',
|
||||||
toolId: toolCallId,
|
toolId: toolCallId,
|
||||||
content: extractCursorToolResultContent(item),
|
content: item.result || '',
|
||||||
isError: Boolean(item.isError || item.is_error),
|
isError: false,
|
||||||
toolUseResult: highLevelToolCallResult,
|
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
@@ -519,15 +336,8 @@ export class CursorSessionsProvider implements IProviderSessions {
|
|||||||
if (Array.isArray(content.content)) {
|
if (Array.isArray(content.content)) {
|
||||||
for (let partIdx = 0; partIdx < content.content.length; partIdx++) {
|
for (let partIdx = 0; partIdx < content.content.length; partIdx++) {
|
||||||
const part = content.content[partIdx];
|
const part = content.content[partIdx];
|
||||||
if (isInternalCursorPart(part)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (part?.type === 'text' && part?.text) {
|
if (part?.type === 'text' && part?.text) {
|
||||||
const normalizedPartText = unwrapUserQueryText(part.text, role);
|
|
||||||
if (!normalizedPartText) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
messages.push(createNormalizedMessage({
|
messages.push(createNormalizedMessage({
|
||||||
id: `${baseId}_${partIdx}`,
|
id: `${baseId}_${partIdx}`,
|
||||||
sessionId,
|
sessionId,
|
||||||
@@ -535,7 +345,7 @@ export class CursorSessionsProvider implements IProviderSessions {
|
|||||||
provider: PROVIDER,
|
provider: PROVIDER,
|
||||||
kind: 'text',
|
kind: 'text',
|
||||||
role,
|
role,
|
||||||
content: normalizedPartText,
|
content: part.text,
|
||||||
sequence: blob.sequence,
|
sequence: blob.sequence,
|
||||||
rowid: blob.rowid,
|
rowid: blob.rowid,
|
||||||
}));
|
}));
|
||||||
@@ -551,11 +361,7 @@ export class CursorSessionsProvider implements IProviderSessions {
|
|||||||
} else if (part?.type === 'tool-call' || part?.type === 'tool_use') {
|
} else if (part?.type === 'tool-call' || part?.type === 'tool_use') {
|
||||||
const rawToolName = part.toolName || part.name || 'Unknown Tool';
|
const rawToolName = part.toolName || part.name || 'Unknown Tool';
|
||||||
const toolName = rawToolName === 'ApplyPatch' ? 'Edit' : rawToolName;
|
const toolName = rawToolName === 'ApplyPatch' ? 'Edit' : rawToolName;
|
||||||
const toolId = normalizeToolId(part.toolCallId)
|
const toolId = part.toolCallId || part.id || `tool_${i}_${partIdx}`;
|
||||||
|| normalizeToolId(part.tool_call_id)
|
|
||||||
|| normalizeToolId(part.id)
|
|
||||||
|| `tool_${i}_${partIdx}`;
|
|
||||||
const normalizedToolInput = normalizeCursorToolInput(rawToolName, part.args ?? part.input);
|
|
||||||
const message = createNormalizedMessage({
|
const message = createNormalizedMessage({
|
||||||
id: `${baseId}_${partIdx}`,
|
id: `${baseId}_${partIdx}`,
|
||||||
sessionId,
|
sessionId,
|
||||||
@@ -563,22 +369,14 @@ export class CursorSessionsProvider implements IProviderSessions {
|
|||||||
provider: PROVIDER,
|
provider: PROVIDER,
|
||||||
kind: 'tool_use',
|
kind: 'tool_use',
|
||||||
toolName,
|
toolName,
|
||||||
toolInput: normalizedToolInput,
|
toolInput: part.args || part.input,
|
||||||
toolId,
|
toolId,
|
||||||
});
|
});
|
||||||
messages.push(message);
|
messages.push(message);
|
||||||
toolUseMap.set(toolId, message);
|
toolUseMap.set(toolId, message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (
|
} else if (typeof content.content === 'string' && content.content.trim()) {
|
||||||
typeof content.content === 'string'
|
|
||||||
&& content.content.trim()
|
|
||||||
&& !isInternalCursorText(content.content)
|
|
||||||
) {
|
|
||||||
const normalizedText = unwrapUserQueryText(content.content, role);
|
|
||||||
if (!normalizedText) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
messages.push(createNormalizedMessage({
|
messages.push(createNormalizedMessage({
|
||||||
id: baseId,
|
id: baseId,
|
||||||
sessionId,
|
sessionId,
|
||||||
@@ -586,7 +384,7 @@ export class CursorSessionsProvider implements IProviderSessions {
|
|||||||
provider: PROVIDER,
|
provider: PROVIDER,
|
||||||
kind: 'text',
|
kind: 'text',
|
||||||
role,
|
role,
|
||||||
content: normalizedText,
|
content: content.content,
|
||||||
sequence: blob.sequence,
|
sequence: blob.sequence,
|
||||||
rowid: blob.rowid,
|
rowid: blob.rowid,
|
||||||
}));
|
}));
|
||||||
@@ -603,7 +401,6 @@ export class CursorSessionsProvider implements IProviderSessions {
|
|||||||
toolUse.toolResult = {
|
toolUse.toolResult = {
|
||||||
content: msg.content,
|
content: msg.content,
|
||||||
isError: msg.isError,
|
isError: msg.isError,
|
||||||
toolUseResult: msg.toolUseResult,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,31 +0,0 @@
|
|||||||
import os from 'node:os';
|
|
||||||
import path from 'node:path';
|
|
||||||
|
|
||||||
import { SkillsProvider } from '@/modules/providers/shared/skills/skills.provider.js';
|
|
||||||
import type { ProviderSkillSource } from '@/shared/types.js';
|
|
||||||
|
|
||||||
export class CursorSkillsProvider extends SkillsProvider {
|
|
||||||
constructor() {
|
|
||||||
super('cursor');
|
|
||||||
}
|
|
||||||
|
|
||||||
protected async getSkillSources(workspacePath: string): Promise<ProviderSkillSource[]> {
|
|
||||||
return [
|
|
||||||
{
|
|
||||||
scope: 'project',
|
|
||||||
rootDir: path.join(workspacePath, '.agents', 'skills'),
|
|
||||||
commandPrefix: '/',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
scope: 'project',
|
|
||||||
rootDir: path.join(workspacePath, '.cursor', 'skills'),
|
|
||||||
commandPrefix: '/',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
scope: 'user',
|
|
||||||
rootDir: path.join(os.homedir(), '.cursor', 'skills'),
|
|
||||||
commandPrefix: '/',
|
|
||||||
},
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -3,18 +3,11 @@ import { CursorProviderAuth } from '@/modules/providers/list/cursor/cursor-auth.
|
|||||||
import { CursorMcpProvider } from '@/modules/providers/list/cursor/cursor-mcp.provider.js';
|
import { CursorMcpProvider } from '@/modules/providers/list/cursor/cursor-mcp.provider.js';
|
||||||
import { CursorSessionSynchronizer } from '@/modules/providers/list/cursor/cursor-session-synchronizer.provider.js';
|
import { CursorSessionSynchronizer } from '@/modules/providers/list/cursor/cursor-session-synchronizer.provider.js';
|
||||||
import { CursorSessionsProvider } from '@/modules/providers/list/cursor/cursor-sessions.provider.js';
|
import { CursorSessionsProvider } from '@/modules/providers/list/cursor/cursor-sessions.provider.js';
|
||||||
import { CursorSkillsProvider } from '@/modules/providers/list/cursor/cursor-skills.provider.js';
|
import type { IProviderAuth, IProviderSessionSynchronizer, IProviderSessions } from '@/shared/interfaces.js';
|
||||||
import type {
|
|
||||||
IProviderAuth,
|
|
||||||
IProviderSessionSynchronizer,
|
|
||||||
IProviderSkills,
|
|
||||||
IProviderSessions,
|
|
||||||
} from '@/shared/interfaces.js';
|
|
||||||
|
|
||||||
export class CursorProvider extends AbstractProvider {
|
export class CursorProvider extends AbstractProvider {
|
||||||
readonly mcp = new CursorMcpProvider();
|
readonly mcp = new CursorMcpProvider();
|
||||||
readonly auth: IProviderAuth = new CursorProviderAuth();
|
readonly auth: IProviderAuth = new CursorProviderAuth();
|
||||||
readonly skills: IProviderSkills = new CursorSkillsProvider();
|
|
||||||
readonly sessions: IProviderSessions = new CursorSessionsProvider();
|
readonly sessions: IProviderSessions = new CursorSessionsProvider();
|
||||||
readonly sessionSynchronizer: IProviderSessionSynchronizer = new CursorSessionSynchronizer();
|
readonly sessionSynchronizer: IProviderSessionSynchronizer = new CursorSessionSynchronizer();
|
||||||
|
|
||||||
|
|||||||
@@ -15,24 +15,7 @@ type GeminiCredentialsStatus = {
|
|||||||
error?: string;
|
error?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
type GeminiAuthType =
|
|
||||||
| 'oauth-personal'
|
|
||||||
| 'gemini-api-key'
|
|
||||||
| 'vertex-ai'
|
|
||||||
| 'compute-default-credentials'
|
|
||||||
| 'gateway'
|
|
||||||
| 'cloud-shell'
|
|
||||||
| null;
|
|
||||||
|
|
||||||
export class GeminiProviderAuth implements IProviderAuth {
|
export class GeminiProviderAuth implements IProviderAuth {
|
||||||
/**
|
|
||||||
* Gemini CLI can override its home root via GEMINI_CLI_HOME.
|
|
||||||
* Use the same resolution so status checks match runtime behavior.
|
|
||||||
*/
|
|
||||||
private getGeminiCliHome(): string {
|
|
||||||
return process.env.GEMINI_CLI_HOME?.trim() || os.homedir();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether the Gemini CLI is available on this host.
|
* Checks whether the Gemini CLI is available on this host.
|
||||||
*/
|
*/
|
||||||
@@ -75,88 +58,6 @@ export class GeminiProviderAuth implements IProviderAuth {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Parses dotenv-style key/value pairs.
|
|
||||||
*/
|
|
||||||
private parseEnvFile(content: string): Record<string, string> {
|
|
||||||
const parsed: Record<string, string> = {};
|
|
||||||
|
|
||||||
for (const rawLine of content.split(/\r?\n/)) {
|
|
||||||
const line = rawLine.trim();
|
|
||||||
if (!line || line.startsWith('#')) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const normalizedLine = line.startsWith('export ')
|
|
||||||
? line.slice('export '.length).trim()
|
|
||||||
: line;
|
|
||||||
const separatorIndex = normalizedLine.indexOf('=');
|
|
||||||
if (separatorIndex <= 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const key = normalizedLine.slice(0, separatorIndex).trim();
|
|
||||||
if (!key) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
let value = normalizedLine.slice(separatorIndex + 1).trim();
|
|
||||||
const quoted = (value.startsWith('"') && value.endsWith('"')) || (value.startsWith('\'') && value.endsWith('\''));
|
|
||||||
if (quoted) {
|
|
||||||
value = value.slice(1, -1);
|
|
||||||
} else {
|
|
||||||
value = value.replace(/\s+#.*$/, '').trim();
|
|
||||||
}
|
|
||||||
|
|
||||||
parsed[key] = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
return parsed;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Loads user-level auth env in Gemini's "first file found" order.
|
|
||||||
*/
|
|
||||||
private async loadUserLevelAuthEnv(): Promise<Record<string, string>> {
|
|
||||||
const geminiCliHome = this.getGeminiCliHome();
|
|
||||||
const envCandidates = [
|
|
||||||
path.join(geminiCliHome, '.gemini', '.env'),
|
|
||||||
path.join(geminiCliHome, '.env'),
|
|
||||||
];
|
|
||||||
|
|
||||||
for (const envPath of envCandidates) {
|
|
||||||
try {
|
|
||||||
const content = await readFile(envPath, 'utf8');
|
|
||||||
return this.parseEnvFile(content);
|
|
||||||
} catch {
|
|
||||||
// Continue to the next fallback.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reads Gemini's selected auth type from settings.json when available.
|
|
||||||
*/
|
|
||||||
private async readSelectedAuthType(): Promise<GeminiAuthType> {
|
|
||||||
try {
|
|
||||||
const settingsPath = path.join(this.getGeminiCliHome(), '.gemini', 'settings.json');
|
|
||||||
const content = await readFile(settingsPath, 'utf8');
|
|
||||||
const settings = readObjectRecord(JSON.parse(content));
|
|
||||||
const security = readObjectRecord(settings?.security);
|
|
||||||
const auth = readObjectRecord(security?.auth);
|
|
||||||
const selectedType = readOptionalString(auth?.selectedType);
|
|
||||||
if (!selectedType) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return selectedType as GeminiAuthType;
|
|
||||||
} catch {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks Gemini credentials from API key env vars or local OAuth credential files.
|
* Checks Gemini credentials from API key env vars or local OAuth credential files.
|
||||||
*/
|
*/
|
||||||
@@ -165,46 +66,8 @@ export class GeminiProviderAuth implements IProviderAuth {
|
|||||||
return { authenticated: true, email: 'API Key Auth', method: 'api_key' };
|
return { authenticated: true, email: 'API Key Auth', method: 'api_key' };
|
||||||
}
|
}
|
||||||
|
|
||||||
const userEnv = await this.loadUserLevelAuthEnv();
|
|
||||||
if (readOptionalString(userEnv.GEMINI_API_KEY)) {
|
|
||||||
return { authenticated: true, email: 'API Key Auth', method: 'api_key' };
|
|
||||||
}
|
|
||||||
|
|
||||||
const selectedType = await this.readSelectedAuthType();
|
|
||||||
if (selectedType === 'vertex-ai') {
|
|
||||||
const hasGoogleApiKey = Boolean(
|
|
||||||
process.env.GOOGLE_API_KEY?.trim()
|
|
||||||
|| readOptionalString(userEnv.GOOGLE_API_KEY)
|
|
||||||
);
|
|
||||||
const hasProject = Boolean(
|
|
||||||
process.env.GOOGLE_CLOUD_PROJECT?.trim()
|
|
||||||
|| process.env.GOOGLE_CLOUD_PROJECT_ID?.trim()
|
|
||||||
|| readOptionalString(userEnv.GOOGLE_CLOUD_PROJECT)
|
|
||||||
|| readOptionalString(userEnv.GOOGLE_CLOUD_PROJECT_ID)
|
|
||||||
);
|
|
||||||
const hasLocation = Boolean(
|
|
||||||
process.env.GOOGLE_CLOUD_LOCATION?.trim()
|
|
||||||
|| readOptionalString(userEnv.GOOGLE_CLOUD_LOCATION)
|
|
||||||
);
|
|
||||||
const hasServiceAccount = Boolean(
|
|
||||||
process.env.GOOGLE_APPLICATION_CREDENTIALS?.trim()
|
|
||||||
|| readOptionalString(userEnv.GOOGLE_APPLICATION_CREDENTIALS)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (hasGoogleApiKey || hasServiceAccount || (hasProject && hasLocation)) {
|
|
||||||
return { authenticated: true, email: 'Vertex AI Auth', method: 'vertex_ai' };
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
authenticated: false,
|
|
||||||
email: null,
|
|
||||||
method: 'vertex_ai',
|
|
||||||
error: 'Gemini is set to Vertex AI, but required env vars are missing',
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const credsPath = path.join(this.getGeminiCliHome(), '.gemini', 'oauth_creds.json');
|
const credsPath = path.join(os.homedir(), '.gemini', 'oauth_creds.json');
|
||||||
const content = await readFile(credsPath, 'utf8');
|
const content = await readFile(credsPath, 'utf8');
|
||||||
const creds = readObjectRecord(JSON.parse(content)) ?? {};
|
const creds = readObjectRecord(JSON.parse(content)) ?? {};
|
||||||
const accessToken = readOptionalString(creds.access_token);
|
const accessToken = readOptionalString(creds.access_token);
|
||||||
@@ -243,25 +106,6 @@ export class GeminiProviderAuth implements IProviderAuth {
|
|||||||
method: 'credentials_file',
|
method: 'credentials_file',
|
||||||
};
|
};
|
||||||
} catch {
|
} catch {
|
||||||
if (selectedType === 'gemini-api-key') {
|
|
||||||
return {
|
|
||||||
authenticated: false,
|
|
||||||
email: null,
|
|
||||||
method: 'api_key',
|
|
||||||
error: 'Gemini is set to "Use Gemini API key", but GEMINI_API_KEY is unavailable',
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (selectedType === 'oauth-personal') {
|
|
||||||
return {
|
|
||||||
authenticated: false,
|
|
||||||
email: null,
|
|
||||||
method: 'credentials_file',
|
|
||||||
error: 'Gemini is set to Google sign-in, but no cached OAuth credentials were found',
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// If no explicit auth type was selected, surface the generic "not configured" error.
|
|
||||||
return {
|
return {
|
||||||
authenticated: false,
|
authenticated: false,
|
||||||
email: null,
|
email: null,
|
||||||
@@ -296,7 +140,7 @@ export class GeminiProviderAuth implements IProviderAuth {
|
|||||||
*/
|
*/
|
||||||
private async getActiveAccountEmail(): Promise<string | null> {
|
private async getActiveAccountEmail(): Promise<string | null> {
|
||||||
try {
|
try {
|
||||||
const accPath = path.join(this.getGeminiCliHome(), '.gemini', 'google_accounts.json');
|
const accPath = path.join(os.homedir(), '.gemini', 'google_accounts.json');
|
||||||
const accContent = await readFile(accPath, 'utf8');
|
const accContent = await readFile(accPath, 'utf8');
|
||||||
const accounts = readObjectRecord(JSON.parse(accContent));
|
const accounts = readObjectRecord(JSON.parse(accContent));
|
||||||
return readOptionalString(accounts?.active) ?? null;
|
return readOptionalString(accounts?.active) ?? null;
|
||||||
|
|||||||
@@ -39,37 +39,33 @@ export class GeminiSessionSynchronizer implements IProviderSessionSynchronizer {
|
|||||||
async synchronize(since?: Date): Promise<number> {
|
async synchronize(since?: Date): Promise<number> {
|
||||||
const projectHashLookup = this.buildProjectHashLookup();
|
const projectHashLookup = this.buildProjectHashLookup();
|
||||||
|
|
||||||
// const legacySessionFiles = await findFilesRecursivelyCreatedAfter(
|
const legacySessionFiles = await findFilesRecursivelyCreatedAfter(
|
||||||
// path.join(this.geminiHome, 'sessions'),
|
path.join(this.geminiHome, 'sessions'),
|
||||||
// '.json',
|
'.json',
|
||||||
// since ?? null
|
since ?? null
|
||||||
// );
|
);
|
||||||
// Gemini creates overlapping artifacts across `sessions/` and `tmp/`.
|
const legacyTempFiles = await findFilesRecursivelyCreatedAfter(
|
||||||
// We currently index only `tmp/*/chats/*.jsonl` because those files are the
|
path.join(this.geminiHome, 'tmp'),
|
||||||
// live transcript source and avoid duplicate session rows from mirrored files.
|
'.json',
|
||||||
// const legacyTempFiles = await findFilesRecursivelyCreatedAfter(
|
since ?? null
|
||||||
// path.join(this.geminiHome, 'tmp'),
|
);
|
||||||
// '.json',
|
const jsonlSessionFiles = await findFilesRecursivelyCreatedAfter(
|
||||||
// since ?? null
|
path.join(this.geminiHome, 'sessions'),
|
||||||
// );
|
'.jsonl',
|
||||||
// const jsonlSessionFiles = await findFilesRecursivelyCreatedAfter(
|
since ?? null
|
||||||
// path.join(this.geminiHome, 'sessions'),
|
);
|
||||||
// '.jsonl',
|
|
||||||
// since ?? null
|
|
||||||
// );
|
|
||||||
const jsonlTempFiles = await findFilesRecursivelyCreatedAfter(
|
const jsonlTempFiles = await findFilesRecursivelyCreatedAfter(
|
||||||
path.join(this.geminiHome, 'tmp'),
|
path.join(this.geminiHome, 'tmp'),
|
||||||
'.jsonl',
|
'.jsonl',
|
||||||
since ?? null
|
since ?? null
|
||||||
);
|
);
|
||||||
|
|
||||||
// Current strategy: index only temp chat JSONL artifacts.
|
// Process legacy JSON first, then JSONL. If both exist for a session id,
|
||||||
|
// the JSONL artifact becomes the canonical jsonl_path via upsert.
|
||||||
const files = [
|
const files = [
|
||||||
// ...legacySessionFiles,
|
...legacySessionFiles,
|
||||||
// Intentionally disabled to avoid duplicate indexing from mirrored
|
...legacyTempFiles,
|
||||||
// `sessions/*.json` and `sessions/*.jsonl` artifacts.
|
...jsonlSessionFiles,
|
||||||
// ...legacyTempFiles,
|
|
||||||
// ...jsonlSessionFiles,
|
|
||||||
...jsonlTempFiles,
|
...jsonlTempFiles,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
@@ -528,16 +528,10 @@ export class GeminiSessionsProvider implements IProviderSessions {
|
|||||||
const messages = pageLimit === null
|
const messages = pageLimit === null
|
||||||
? normalized.slice(start)
|
? normalized.slice(start)
|
||||||
: normalized.slice(start, start + pageLimit);
|
: normalized.slice(start, start + pageLimit);
|
||||||
let total = 0;
|
|
||||||
for (const msg of normalized) {
|
|
||||||
if (msg.kind !== 'tool_result') {
|
|
||||||
total += 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
messages,
|
messages,
|
||||||
total,
|
total: normalized.length,
|
||||||
hasMore: pageLimit === null ? false : start + pageLimit < normalized.length,
|
hasMore: pageLimit === null ? false : start + pageLimit < normalized.length,
|
||||||
offset: start,
|
offset: start,
|
||||||
limit: pageLimit,
|
limit: pageLimit,
|
||||||
|
|||||||
@@ -1,36 +0,0 @@
|
|||||||
import os from 'node:os';
|
|
||||||
import path from 'node:path';
|
|
||||||
|
|
||||||
import { SkillsProvider } from '@/modules/providers/shared/skills/skills.provider.js';
|
|
||||||
import type { ProviderSkillSource } from '@/shared/types.js';
|
|
||||||
|
|
||||||
export class GeminiSkillsProvider extends SkillsProvider {
|
|
||||||
constructor() {
|
|
||||||
super('gemini');
|
|
||||||
}
|
|
||||||
|
|
||||||
protected async getSkillSources(workspacePath: string): Promise<ProviderSkillSource[]> {
|
|
||||||
return [
|
|
||||||
{
|
|
||||||
scope: 'user',
|
|
||||||
rootDir: path.join(os.homedir(), '.gemini', 'skills'),
|
|
||||||
commandPrefix: '/',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
scope: 'user',
|
|
||||||
rootDir: path.join(os.homedir(), '.agents', 'skills'),
|
|
||||||
commandPrefix: '/',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
scope: 'project',
|
|
||||||
rootDir: path.join(workspacePath, '.gemini', 'skills'),
|
|
||||||
commandPrefix: '/',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
scope: 'project',
|
|
||||||
rootDir: path.join(workspacePath, '.agents', 'skills'),
|
|
||||||
commandPrefix: '/',
|
|
||||||
},
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -3,18 +3,11 @@ import { GeminiProviderAuth } from '@/modules/providers/list/gemini/gemini-auth.
|
|||||||
import { GeminiMcpProvider } from '@/modules/providers/list/gemini/gemini-mcp.provider.js';
|
import { GeminiMcpProvider } from '@/modules/providers/list/gemini/gemini-mcp.provider.js';
|
||||||
import { GeminiSessionSynchronizer } from '@/modules/providers/list/gemini/gemini-session-synchronizer.provider.js';
|
import { GeminiSessionSynchronizer } from '@/modules/providers/list/gemini/gemini-session-synchronizer.provider.js';
|
||||||
import { GeminiSessionsProvider } from '@/modules/providers/list/gemini/gemini-sessions.provider.js';
|
import { GeminiSessionsProvider } from '@/modules/providers/list/gemini/gemini-sessions.provider.js';
|
||||||
import { GeminiSkillsProvider } from '@/modules/providers/list/gemini/gemini-skills.provider.js';
|
import type { IProviderAuth, IProviderSessionSynchronizer, IProviderSessions } from '@/shared/interfaces.js';
|
||||||
import type {
|
|
||||||
IProviderAuth,
|
|
||||||
IProviderSessionSynchronizer,
|
|
||||||
IProviderSkills,
|
|
||||||
IProviderSessions,
|
|
||||||
} from '@/shared/interfaces.js';
|
|
||||||
|
|
||||||
export class GeminiProvider extends AbstractProvider {
|
export class GeminiProvider extends AbstractProvider {
|
||||||
readonly mcp = new GeminiMcpProvider();
|
readonly mcp = new GeminiMcpProvider();
|
||||||
readonly auth: IProviderAuth = new GeminiProviderAuth();
|
readonly auth: IProviderAuth = new GeminiProviderAuth();
|
||||||
readonly skills: IProviderSkills = new GeminiSkillsProvider();
|
|
||||||
readonly sessions: IProviderSessions = new GeminiSessionsProvider();
|
readonly sessions: IProviderSessions = new GeminiSessionsProvider();
|
||||||
readonly sessionSynchronizer: IProviderSessionSynchronizer = new GeminiSessionSynchronizer();
|
readonly sessionSynchronizer: IProviderSessionSynchronizer = new GeminiSessionSynchronizer();
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import express, { type Request, type Response } from 'express';
|
|||||||
|
|
||||||
import { providerAuthService } from '@/modules/providers/services/provider-auth.service.js';
|
import { providerAuthService } from '@/modules/providers/services/provider-auth.service.js';
|
||||||
import { providerMcpService } from '@/modules/providers/services/mcp.service.js';
|
import { providerMcpService } from '@/modules/providers/services/mcp.service.js';
|
||||||
import { providerSkillsService } from '@/modules/providers/services/skills.service.js';
|
|
||||||
import { sessionConversationsSearchService } from '@/modules/providers/services/session-conversations-search.service.js';
|
import { sessionConversationsSearchService } from '@/modules/providers/services/session-conversations-search.service.js';
|
||||||
import { sessionsService } from '@/modules/providers/services/sessions.service.js';
|
import { sessionsService } from '@/modules/providers/services/sessions.service.js';
|
||||||
import type { LLMProvider, McpScope, McpTransport, UpsertProviderMcpServerInput } from '@/shared/types.js';
|
import type { LLMProvider, McpScope, McpTransport, UpsertProviderMcpServerInput } from '@/shared/types.js';
|
||||||
@@ -248,17 +247,6 @@ router.get(
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
// ----------------- Skills routes -----------------
|
|
||||||
router.get(
|
|
||||||
'/:provider/skills',
|
|
||||||
asyncHandler(async (req: Request, res: Response) => {
|
|
||||||
const provider = parseProvider(req.params.provider);
|
|
||||||
const workspacePath = readOptionalQueryString(req.query.workspacePath);
|
|
||||||
const skills = await providerSkillsService.listProviderSkills(provider, { workspacePath });
|
|
||||||
res.json(createApiSuccessResponse({ provider, skills }));
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
// ----------------- MCP routes -----------------
|
// ----------------- MCP routes -----------------
|
||||||
router.get(
|
router.get(
|
||||||
'/:provider/mcp/servers',
|
'/:provider/mcp/servers',
|
||||||
@@ -323,33 +311,12 @@ router.post(
|
|||||||
);
|
);
|
||||||
|
|
||||||
// ----------------- Session routes -----------------
|
// ----------------- Session routes -----------------
|
||||||
router.get(
|
|
||||||
'/sessions/archived',
|
|
||||||
asyncHandler(async (_req: Request, res: Response) => {
|
|
||||||
const sessions = sessionsService.listArchivedSessions();
|
|
||||||
res.json(createApiSuccessResponse({ sessions }));
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
router.delete(
|
router.delete(
|
||||||
'/sessions/:sessionId',
|
'/sessions/:sessionId',
|
||||||
asyncHandler(async (req: Request, res: Response) => {
|
asyncHandler(async (req: Request, res: Response) => {
|
||||||
const sessionId = parseSessionId(req.params.sessionId);
|
const sessionId = parseSessionId(req.params.sessionId);
|
||||||
const force = parseOptionalBooleanQuery(req.query.force, 'force') ?? false;
|
const deletedFromDisk = parseOptionalBooleanQuery(req.query.deletedFromDisk, 'deletedFromDisk') ?? false;
|
||||||
const deletedFromDisk = parseOptionalBooleanQuery(req.query.deletedFromDisk, 'deletedFromDisk') ?? force;
|
const result = await sessionsService.deleteSessionById(sessionId, deletedFromDisk);
|
||||||
const result = await sessionsService.deleteOrArchiveSessionById(sessionId, {
|
|
||||||
force,
|
|
||||||
deletedFromDisk,
|
|
||||||
});
|
|
||||||
res.json(createApiSuccessResponse(result));
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
router.post(
|
|
||||||
'/sessions/:sessionId/restore',
|
|
||||||
asyncHandler(async (req: Request, res: Response) => {
|
|
||||||
const sessionId = parseSessionId(req.params.sessionId);
|
|
||||||
const result = sessionsService.restoreSessionById(sessionId);
|
|
||||||
res.json(createApiSuccessResponse(result));
|
res.json(createApiSuccessResponse(result));
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -89,8 +89,13 @@ const RIPGREP_CHUNK_CONCURRENCY = 6;
|
|||||||
const UNKNOWN_PROJECT_KEY = '__unknown_project__';
|
const UNKNOWN_PROJECT_KEY = '__unknown_project__';
|
||||||
|
|
||||||
const INTERNAL_CONTENT_PREFIXES = [
|
const INTERNAL_CONTENT_PREFIXES = [
|
||||||
|
'<command-name>',
|
||||||
|
'<command-message>',
|
||||||
|
'<command-args>',
|
||||||
|
'<local-command-stdout>',
|
||||||
'<system-reminder>',
|
'<system-reminder>',
|
||||||
'Caveat:',
|
'Caveat:',
|
||||||
|
'This session is being continued from a previous',
|
||||||
'Invalid API key',
|
'Invalid API key',
|
||||||
'[Request interrupted',
|
'[Request interrupted',
|
||||||
] as const;
|
] as const;
|
||||||
@@ -297,135 +302,6 @@ function extractClaudeText(content: unknown): string {
|
|||||||
.join(' ');
|
.join(' ');
|
||||||
}
|
}
|
||||||
|
|
||||||
function extractTaggedContent(content: string, tagName: string): string | null {
|
|
||||||
const escapedTagName = tagName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
||||||
const match = new RegExp(`<${escapedTagName}>([\\s\\S]*?)<\\/${escapedTagName}>`).exec(content);
|
|
||||||
return match ? match[1] : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
type ClaudeLocalCommandPayload = {
|
|
||||||
commandName: string;
|
|
||||||
commandMessage: string;
|
|
||||||
commandArgs: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
function parseClaudeLocalCommandPayload(content: string): ClaudeLocalCommandPayload | null {
|
|
||||||
const commandName = extractTaggedContent(content, 'command-name');
|
|
||||||
const commandMessage = extractTaggedContent(content, 'command-message');
|
|
||||||
const commandArgs = extractTaggedContent(content, 'command-args');
|
|
||||||
|
|
||||||
if (commandName === null && commandMessage === null && commandArgs === null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
commandName: commandName ?? '',
|
|
||||||
commandMessage: commandMessage ?? '',
|
|
||||||
commandArgs: commandArgs ?? '',
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function buildClaudeLocalCommandDisplayText(payload: ClaudeLocalCommandPayload): string {
|
|
||||||
const commandName = payload.commandName.trim();
|
|
||||||
const commandMessage = payload.commandMessage.trim();
|
|
||||||
const commandArgs = payload.commandArgs.trim();
|
|
||||||
const baseCommand = commandName || commandMessage;
|
|
||||||
|
|
||||||
if (!baseCommand) {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
return commandArgs ? `${baseCommand} ${commandArgs}` : baseCommand;
|
|
||||||
}
|
|
||||||
|
|
||||||
function stripAnsiFormatting(text: string): string {
|
|
||||||
return text.replace(/\u001B\[[0-9;?]*[ -/]*[@-~]/g, '');
|
|
||||||
}
|
|
||||||
|
|
||||||
type ClaudeSearchableMessage = {
|
|
||||||
text: string;
|
|
||||||
role: 'user' | 'assistant';
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Claude mixes visible chat, compact summaries, and local command wrappers into
|
|
||||||
* the same transcript stream. Search should operate on the user-visible meaning
|
|
||||||
* of those rows rather than the raw wrapper syntax.
|
|
||||||
*/
|
|
||||||
function extractClaudeSearchableMessage(entry: AnyRecord): ClaudeSearchableMessage | null {
|
|
||||||
if (!entry.message?.content || entry.isApiErrorMessage) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
const rawRole = entry.message.role;
|
|
||||||
if (rawRole !== 'user' && rawRole !== 'assistant') {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof entry.message.content === 'string') {
|
|
||||||
const content = String(entry.message.content);
|
|
||||||
|
|
||||||
if (entry.isCompactSummary === true && content.trim()) {
|
|
||||||
return {
|
|
||||||
text: content,
|
|
||||||
role: 'assistant',
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const localCommand = parseClaudeLocalCommandPayload(content);
|
|
||||||
if (localCommand) {
|
|
||||||
const displayText = buildClaudeLocalCommandDisplayText(localCommand);
|
|
||||||
return displayText
|
|
||||||
? {
|
|
||||||
text: displayText,
|
|
||||||
role: 'user',
|
|
||||||
}
|
|
||||||
: null;
|
|
||||||
}
|
|
||||||
|
|
||||||
const localCommandStdout = extractTaggedContent(content, 'local-command-stdout');
|
|
||||||
if (localCommandStdout !== null) {
|
|
||||||
const stdoutText = stripAnsiFormatting(localCommandStdout).trim();
|
|
||||||
return stdoutText
|
|
||||||
? {
|
|
||||||
text: stdoutText,
|
|
||||||
role: 'assistant',
|
|
||||||
}
|
|
||||||
: null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!content || isInternalContent(content)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
text: content,
|
|
||||||
role: rawRole,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const text = extractClaudeText(entry.message.content);
|
|
||||||
if (!text) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (entry.isCompactSummary === true) {
|
|
||||||
return {
|
|
||||||
text,
|
|
||||||
role: 'assistant',
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isInternalContent(text)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
text,
|
|
||||||
role: rawRole,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function extractCodexText(content: unknown): string {
|
function extractCodexText(content: unknown): string {
|
||||||
if (typeof content === 'string') {
|
if (typeof content === 'string') {
|
||||||
return content;
|
return content;
|
||||||
@@ -472,7 +348,6 @@ function extractGeminiText(content: unknown): string {
|
|||||||
|
|
||||||
function normalizeSearchableSessions(rows: SessionRepositoryRow[]): SearchableSessionRow[] {
|
function normalizeSearchableSessions(rows: SessionRepositoryRow[]): SearchableSessionRow[] {
|
||||||
const normalizedRows: SearchableSessionRow[] = [];
|
const normalizedRows: SearchableSessionRow[] = [];
|
||||||
const projectArchiveStateByPath = new Map<string, boolean>();
|
|
||||||
|
|
||||||
for (const row of rows) {
|
for (const row of rows) {
|
||||||
const provider = row.provider as SearchableProvider;
|
const provider = row.provider as SearchableProvider;
|
||||||
@@ -490,27 +365,6 @@ function normalizeSearchableSessions(rows: SessionRepositoryRow[]): SearchableSe
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Active session rows can still belong to an archived project because
|
|
||||||
* project archiving intentionally preserves the underlying session data.
|
|
||||||
* Global conversation search should follow the visible workspace model,
|
|
||||||
* which means excluding any session whose owning project is archived.
|
|
||||||
*
|
|
||||||
* Cache the archive lookup per normalized project path so one search pass
|
|
||||||
* does not re-query the same project row for every session in that folder.
|
|
||||||
*/
|
|
||||||
const normalizedProjectPath = typeof row.project_path === 'string' ? row.project_path.trim() : '';
|
|
||||||
if (normalizedProjectPath) {
|
|
||||||
if (!projectArchiveStateByPath.has(normalizedProjectPath)) {
|
|
||||||
const projectRow = projectsDb.getProjectPath(normalizedProjectPath);
|
|
||||||
projectArchiveStateByPath.set(normalizedProjectPath, Boolean(projectRow?.isArchived));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (projectArchiveStateByPath.get(normalizedProjectPath) === true) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
normalizedRows.push({
|
normalizedRows.push({
|
||||||
...row,
|
...row,
|
||||||
provider,
|
provider,
|
||||||
@@ -879,21 +733,18 @@ async function parseClaudeSessionMatches(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const searchableMessage = extractClaudeSearchableMessage(entry);
|
if (!entry.message?.content || entry.isApiErrorMessage) {
|
||||||
if (!searchableMessage) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const { text, role } = searchableMessage;
|
const role = entry.message.role;
|
||||||
|
if (role !== 'user' && role !== 'assistant') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
const text = extractClaudeText(entry.message.content);
|
||||||
* Claude compact summaries are the most faithful session-summary source
|
if (!text || isInternalContent(text)) {
|
||||||
* after a `/compact` because they describe the post-compaction state that
|
continue;
|
||||||
* the resumed session actually continues from. Prefer them over generic
|
|
||||||
* fallback user text when present.
|
|
||||||
*/
|
|
||||||
if (entry.isCompactSummary === true) {
|
|
||||||
state.resolvedSummary = text;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (role === 'user') {
|
if (role === 'user') {
|
||||||
|
|||||||
@@ -18,18 +18,16 @@ const PROVIDER_WATCH_PATHS: Array<{ provider: LLMProvider; rootPath: string }> =
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
provider: 'cursor',
|
provider: 'cursor',
|
||||||
rootPath: path.join(os.homedir(), '.cursor', 'projects'),
|
rootPath: path.join(os.homedir(), '.cursor', 'chats'),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
provider: 'codex',
|
provider: 'codex',
|
||||||
rootPath: path.join(os.homedir(), '.codex', 'sessions'),
|
rootPath: path.join(os.homedir(), '.codex', 'sessions'),
|
||||||
},
|
},
|
||||||
// {
|
{
|
||||||
// provider: 'gemini',
|
provider: 'gemini',
|
||||||
// rootPath: path.join(os.homedir(), '.gemini', 'sessions'),
|
rootPath: path.join(os.homedir(), '.gemini', 'sessions'),
|
||||||
// },
|
},
|
||||||
// Keep `sessions/` watcher disabled: Gemini also mirrors artifacts there,
|
|
||||||
// which causes duplicate synchronization events.
|
|
||||||
{
|
{
|
||||||
provider: 'gemini',
|
provider: 'gemini',
|
||||||
rootPath: path.join(os.homedir(), '.gemini', 'tmp'),
|
rootPath: path.join(os.homedir(), '.gemini', 'tmp'),
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import fsp from 'node:fs/promises';
|
import fsp from 'node:fs/promises';
|
||||||
import path from 'node:path';
|
|
||||||
|
|
||||||
import { projectsDb, sessionsDb } from '@/modules/database/index.js';
|
import { sessionsDb } from '@/modules/database/index.js';
|
||||||
import { providerRegistry } from '@/modules/providers/provider.registry.js';
|
import { providerRegistry } from '@/modules/providers/provider.registry.js';
|
||||||
import type {
|
import type {
|
||||||
FetchHistoryOptions,
|
FetchHistoryOptions,
|
||||||
@@ -11,19 +10,6 @@ import type {
|
|||||||
} from '@/shared/types.js';
|
} from '@/shared/types.js';
|
||||||
import { AppError } from '@/shared/utils.js';
|
import { AppError } from '@/shared/utils.js';
|
||||||
|
|
||||||
type ArchivedSessionListItem = {
|
|
||||||
sessionId: string;
|
|
||||||
provider: LLMProvider;
|
|
||||||
projectId: string | null;
|
|
||||||
projectPath: string | null;
|
|
||||||
projectDisplayName: string;
|
|
||||||
sessionTitle: string;
|
|
||||||
createdAt: string | null;
|
|
||||||
updatedAt: string | null;
|
|
||||||
lastActivity: string | null;
|
|
||||||
isProjectArchived: boolean;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes one file if it exists.
|
* Removes one file if it exists.
|
||||||
*/
|
*/
|
||||||
@@ -40,28 +26,6 @@ async function removeFileIfExists(filePath: string): Promise<boolean> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Archive rows need a stable project label even when the owning project is not
|
|
||||||
* part of the active sidebar payload. This lightweight resolver keeps the
|
|
||||||
* archive API self-contained while still matching the project's stored display
|
|
||||||
* name when one exists.
|
|
||||||
*/
|
|
||||||
function resolveProjectDisplayName(
|
|
||||||
projectPath: string | null,
|
|
||||||
customProjectName: string | null | undefined,
|
|
||||||
): string {
|
|
||||||
const trimmedCustomName = typeof customProjectName === 'string' ? customProjectName.trim() : '';
|
|
||||||
if (trimmedCustomName.length > 0) {
|
|
||||||
return trimmedCustomName;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!projectPath) {
|
|
||||||
return 'Unknown Project';
|
|
||||||
}
|
|
||||||
|
|
||||||
return path.basename(projectPath) || projectPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Application service for provider-backed session message operations.
|
* Application service for provider-backed session message operations.
|
||||||
*
|
*
|
||||||
@@ -115,53 +79,15 @@ export const sessionsService = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns archived sessions with enough project metadata for the sidebar to
|
* Deletes one persisted session row by id.
|
||||||
* group, filter, open, and restore them without a per-row follow-up query.
|
|
||||||
*/
|
|
||||||
listArchivedSessions(): ArchivedSessionListItem[] {
|
|
||||||
const archivedSessions = sessionsDb.getArchivedSessions();
|
|
||||||
const projectCache = new Map<string, ReturnType<typeof projectsDb.getProjectPath>>();
|
|
||||||
|
|
||||||
return archivedSessions.map((session) => {
|
|
||||||
const projectPath = session.project_path?.trim() ? session.project_path : null;
|
|
||||||
let project = null;
|
|
||||||
|
|
||||||
if (projectPath) {
|
|
||||||
if (!projectCache.has(projectPath)) {
|
|
||||||
projectCache.set(projectPath, projectsDb.getProjectPath(projectPath));
|
|
||||||
}
|
|
||||||
project = projectCache.get(projectPath) ?? null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
sessionId: session.session_id,
|
|
||||||
provider: session.provider as LLMProvider,
|
|
||||||
projectId: project?.project_id ?? null,
|
|
||||||
projectPath,
|
|
||||||
projectDisplayName: resolveProjectDisplayName(projectPath, project?.custom_project_name),
|
|
||||||
sessionTitle: session.custom_name?.trim() || session.session_id,
|
|
||||||
createdAt: session.created_at ?? null,
|
|
||||||
updatedAt: session.updated_at ?? null,
|
|
||||||
lastActivity: session.updated_at ?? session.created_at ?? null,
|
|
||||||
isProjectArchived: Boolean(project?.isArchived),
|
|
||||||
};
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Archives or permanently deletes one persisted session row by id.
|
|
||||||
*
|
*
|
||||||
* Soft-delete mirrors the project behavior by toggling `isArchived` so the
|
* When `deletedFromDisk` is true and a session `jsonl_path` exists, the path
|
||||||
* row disappears from active lists but remains restorable. Force-delete
|
* is deleted from disk before the DB row is removed.
|
||||||
* optionally removes the transcript file before deleting the database row.
|
|
||||||
*/
|
*/
|
||||||
async deleteOrArchiveSessionById(
|
async deleteSessionById(
|
||||||
sessionId: string,
|
sessionId: string,
|
||||||
options: {
|
deletedFromDisk = false,
|
||||||
force?: boolean;
|
): Promise<{ sessionId: string; deletedFromDisk: boolean }> {
|
||||||
deletedFromDisk?: boolean;
|
|
||||||
} = {},
|
|
||||||
): Promise<{ sessionId: string; action: 'archived' | 'deleted'; deletedFromDisk: boolean }> {
|
|
||||||
const session = sessionsDb.getSessionById(sessionId);
|
const session = sessionsDb.getSessionById(sessionId);
|
||||||
if (!session) {
|
if (!session) {
|
||||||
throw new AppError(`Session "${sessionId}" was not found.`, {
|
throw new AppError(`Session "${sessionId}" was not found.`, {
|
||||||
@@ -170,17 +96,8 @@ export const sessionsService = {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!options.force) {
|
|
||||||
sessionsDb.updateSessionIsArchived(sessionId, true);
|
|
||||||
return {
|
|
||||||
sessionId,
|
|
||||||
action: 'archived',
|
|
||||||
deletedFromDisk: false,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
let removedFromDisk = false;
|
let removedFromDisk = false;
|
||||||
if (options.deletedFromDisk && session.jsonl_path) {
|
if (deletedFromDisk && session.jsonl_path) {
|
||||||
removedFromDisk = await removeFileIfExists(session.jsonl_path);
|
removedFromDisk = await removeFileIfExists(session.jsonl_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -192,27 +109,7 @@ export const sessionsService = {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return { sessionId, deletedFromDisk: removedFromDisk };
|
||||||
sessionId,
|
|
||||||
action: 'deleted',
|
|
||||||
deletedFromDisk: removedFromDisk,
|
|
||||||
};
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Restores one archived session back into the active sidebar lists.
|
|
||||||
*/
|
|
||||||
restoreSessionById(sessionId: string): { sessionId: string; isArchived: false } {
|
|
||||||
const session = sessionsDb.getSessionById(sessionId);
|
|
||||||
if (!session) {
|
|
||||||
throw new AppError(`Session "${sessionId}" was not found.`, {
|
|
||||||
code: 'SESSION_NOT_FOUND',
|
|
||||||
statusCode: 404,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
sessionsDb.updateSessionIsArchived(sessionId, false);
|
|
||||||
return { sessionId, isArchived: false };
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,15 +0,0 @@
|
|||||||
import { providerRegistry } from '@/modules/providers/provider.registry.js';
|
|
||||||
import type { ProviderSkill, ProviderSkillListOptions } from '@/shared/types.js';
|
|
||||||
|
|
||||||
export const providerSkillsService = {
|
|
||||||
/**
|
|
||||||
* Lists normalized skills visible to one provider.
|
|
||||||
*/
|
|
||||||
async listProviderSkills(
|
|
||||||
providerName: string,
|
|
||||||
options?: ProviderSkillListOptions,
|
|
||||||
): Promise<ProviderSkill[]> {
|
|
||||||
const provider = providerRegistry.resolveProvider(providerName);
|
|
||||||
return provider.skills.listSkills(options);
|
|
||||||
},
|
|
||||||
};
|
|
||||||
@@ -3,7 +3,6 @@ import type {
|
|||||||
IProviderAuth,
|
IProviderAuth,
|
||||||
IProviderMcp,
|
IProviderMcp,
|
||||||
IProviderSessionSynchronizer,
|
IProviderSessionSynchronizer,
|
||||||
IProviderSkills,
|
|
||||||
IProviderSessions,
|
IProviderSessions,
|
||||||
} from '@/shared/interfaces.js';
|
} from '@/shared/interfaces.js';
|
||||||
import type { LLMProvider } from '@/shared/types.js';
|
import type { LLMProvider } from '@/shared/types.js';
|
||||||
@@ -19,7 +18,6 @@ export abstract class AbstractProvider implements IProvider {
|
|||||||
readonly id: LLMProvider;
|
readonly id: LLMProvider;
|
||||||
abstract readonly mcp: IProviderMcp;
|
abstract readonly mcp: IProviderMcp;
|
||||||
abstract readonly auth: IProviderAuth;
|
abstract readonly auth: IProviderAuth;
|
||||||
abstract readonly skills: IProviderSkills;
|
|
||||||
abstract readonly sessions: IProviderSessions;
|
abstract readonly sessions: IProviderSessions;
|
||||||
abstract readonly sessionSynchronizer: IProviderSessionSynchronizer;
|
abstract readonly sessionSynchronizer: IProviderSessionSynchronizer;
|
||||||
|
|
||||||
|
|||||||
@@ -1,64 +0,0 @@
|
|||||||
import path from 'node:path';
|
|
||||||
|
|
||||||
import type { IProviderSkills } from '@/shared/interfaces.js';
|
|
||||||
import type {
|
|
||||||
LLMProvider,
|
|
||||||
ProviderSkill,
|
|
||||||
ProviderSkillListOptions,
|
|
||||||
ProviderSkillSource,
|
|
||||||
} from '@/shared/types.js';
|
|
||||||
import {
|
|
||||||
findProviderSkillMarkdownFiles,
|
|
||||||
readProviderSkillMarkdownDefinition,
|
|
||||||
} from '@/shared/utils.js';
|
|
||||||
|
|
||||||
const resolveWorkspacePath = (workspacePath?: string): string =>
|
|
||||||
path.resolve(workspacePath ?? process.cwd());
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Shared skills provider for provider-specific skill source discovery.
|
|
||||||
*/
|
|
||||||
export abstract class SkillsProvider implements IProviderSkills {
|
|
||||||
protected readonly provider: LLMProvider;
|
|
||||||
|
|
||||||
protected constructor(provider: LLMProvider) {
|
|
||||||
this.provider = provider;
|
|
||||||
}
|
|
||||||
|
|
||||||
async listSkills(options?: ProviderSkillListOptions): Promise<ProviderSkill[]> {
|
|
||||||
const workspacePath = resolveWorkspacePath(options?.workspacePath);
|
|
||||||
const sources = await this.getSkillSources(workspacePath);
|
|
||||||
const skills: ProviderSkill[] = [];
|
|
||||||
|
|
||||||
for (const source of sources) {
|
|
||||||
const skillFiles = await findProviderSkillMarkdownFiles(source.rootDir, {
|
|
||||||
recursive: source.recursive,
|
|
||||||
});
|
|
||||||
for (const skillPath of skillFiles) {
|
|
||||||
try {
|
|
||||||
const definition = await readProviderSkillMarkdownDefinition(skillPath);
|
|
||||||
const command = source.commandForSkill
|
|
||||||
? source.commandForSkill(definition.name)
|
|
||||||
: `${source.commandPrefix ?? '/'}${definition.name}`;
|
|
||||||
|
|
||||||
skills.push({
|
|
||||||
provider: this.provider,
|
|
||||||
name: definition.name,
|
|
||||||
description: definition.description,
|
|
||||||
command,
|
|
||||||
scope: source.scope,
|
|
||||||
sourcePath: skillPath,
|
|
||||||
pluginName: source.pluginName,
|
|
||||||
pluginId: source.pluginId,
|
|
||||||
});
|
|
||||||
} catch {
|
|
||||||
// A malformed or unreadable skill markdown file should not hide other valid skills.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return skills;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract getSkillSources(workspacePath: string): Promise<ProviderSkillSource[]>;
|
|
||||||
}
|
|
||||||
@@ -1,446 +0,0 @@
|
|||||||
import assert from 'node:assert/strict';
|
|
||||||
import fs from 'node:fs/promises';
|
|
||||||
import os from 'node:os';
|
|
||||||
import path from 'node:path';
|
|
||||||
import test from 'node:test';
|
|
||||||
|
|
||||||
import { providerSkillsService } from '@/modules/providers/services/skills.service.js';
|
|
||||||
|
|
||||||
const patchHomeDir = (nextHomeDir: string) => {
|
|
||||||
const original = os.homedir;
|
|
||||||
(os as any).homedir = () => nextHomeDir;
|
|
||||||
return () => {
|
|
||||||
(os as any).homedir = original;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
const writeSkill = async (
|
|
||||||
skillsRoot: string,
|
|
||||||
directoryName: string,
|
|
||||||
name: string,
|
|
||||||
description: string,
|
|
||||||
): Promise<string> => {
|
|
||||||
const skillDir = path.join(skillsRoot, directoryName);
|
|
||||||
await fs.mkdir(skillDir, { recursive: true });
|
|
||||||
const skillPath = path.join(skillDir, 'SKILL.md');
|
|
||||||
await fs.writeFile(
|
|
||||||
skillPath,
|
|
||||||
`---\nname: ${name}\ndescription: ${description}\n---\n\n`,
|
|
||||||
'utf8',
|
|
||||||
);
|
|
||||||
return skillPath;
|
|
||||||
};
|
|
||||||
|
|
||||||
const writeClaudePluginManifest = async (
|
|
||||||
installPath: string,
|
|
||||||
name: string,
|
|
||||||
): Promise<void> => {
|
|
||||||
const pluginConfigDir = path.join(installPath, '.claude-plugin');
|
|
||||||
await fs.mkdir(pluginConfigDir, { recursive: true });
|
|
||||||
await fs.writeFile(
|
|
||||||
path.join(pluginConfigDir, 'plugin.json'),
|
|
||||||
JSON.stringify(
|
|
||||||
{
|
|
||||||
name,
|
|
||||||
version: '0.1.0',
|
|
||||||
description: `${name} test plugin`,
|
|
||||||
},
|
|
||||||
null,
|
|
||||||
2,
|
|
||||||
),
|
|
||||||
'utf8',
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
const writeClaudePluginCommand = async (
|
|
||||||
commandsRoot: string,
|
|
||||||
commandName: string,
|
|
||||||
description: string,
|
|
||||||
): Promise<string> => {
|
|
||||||
await fs.mkdir(commandsRoot, { recursive: true });
|
|
||||||
const commandPath = path.join(commandsRoot, `${commandName}.md`);
|
|
||||||
await fs.writeFile(
|
|
||||||
commandPath,
|
|
||||||
`---\ndescription: ${description}\nargument-hint: 'test args'\n---\n\nCommand body.\n`,
|
|
||||||
'utf8',
|
|
||||||
);
|
|
||||||
return commandPath;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This test covers Claude user/project skill folders plus plugin discovery from
|
|
||||||
* installed plugin command files and fallback plugin skill files.
|
|
||||||
*/
|
|
||||||
test('providerSkillsService lists claude user, project, and enabled plugin skills', { concurrency: false }, async () => {
|
|
||||||
const tempRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'llm-skills-claude-'));
|
|
||||||
const workspacePath = path.join(tempRoot, 'workspace');
|
|
||||||
const commandPluginInstallPath = path.join(
|
|
||||||
tempRoot,
|
|
||||||
'.claude',
|
|
||||||
'plugins',
|
|
||||||
'cache',
|
|
||||||
'notion-plugin',
|
|
||||||
'notion',
|
|
||||||
'abc123',
|
|
||||||
);
|
|
||||||
const skillPluginInstallPath = path.join(
|
|
||||||
tempRoot,
|
|
||||||
'.claude',
|
|
||||||
'plugins',
|
|
||||||
'cache',
|
|
||||||
'anthropic-agent-skills',
|
|
||||||
'example-skills',
|
|
||||||
'def456',
|
|
||||||
);
|
|
||||||
const disabledPluginInstallPath = path.join(
|
|
||||||
tempRoot,
|
|
||||||
'.claude',
|
|
||||||
'plugins',
|
|
||||||
'cache',
|
|
||||||
'disabled-marketplace',
|
|
||||||
'disabled-skills',
|
|
||||||
'ghi789',
|
|
||||||
);
|
|
||||||
const emptyIdPluginInstallPath = path.join(
|
|
||||||
tempRoot,
|
|
||||||
'.claude',
|
|
||||||
'plugins',
|
|
||||||
'cache',
|
|
||||||
'invalid-empty-plugin',
|
|
||||||
'empty',
|
|
||||||
'000',
|
|
||||||
);
|
|
||||||
const atIdPluginInstallPath = path.join(
|
|
||||||
tempRoot,
|
|
||||||
'.claude',
|
|
||||||
'plugins',
|
|
||||||
'cache',
|
|
||||||
'invalid-at-plugin',
|
|
||||||
'at',
|
|
||||||
'000',
|
|
||||||
);
|
|
||||||
const siblingSkillPluginPath = path.join(path.dirname(skillPluginInstallPath), 'legacy777');
|
|
||||||
await fs.mkdir(workspacePath, { recursive: true });
|
|
||||||
|
|
||||||
const restoreHomeDir = patchHomeDir(tempRoot);
|
|
||||||
try {
|
|
||||||
await writeSkill(
|
|
||||||
path.join(tempRoot, '.claude', 'skills'),
|
|
||||||
'claude-user-dir',
|
|
||||||
'claude-user',
|
|
||||||
'Claude user skill',
|
|
||||||
);
|
|
||||||
await writeSkill(
|
|
||||||
path.join(workspacePath, '.claude', 'skills'),
|
|
||||||
'claude-project-dir',
|
|
||||||
'claude-project',
|
|
||||||
'Claude project skill',
|
|
||||||
);
|
|
||||||
await writeClaudePluginManifest(commandPluginInstallPath, 'Notion');
|
|
||||||
await writeClaudePluginCommand(
|
|
||||||
path.join(commandPluginInstallPath, 'commands'),
|
|
||||||
'insert-row',
|
|
||||||
'Insert a Notion database row',
|
|
||||||
);
|
|
||||||
await writeSkill(
|
|
||||||
path.join(commandPluginInstallPath, 'skills'),
|
|
||||||
'ignored-command-plugin-skill-dir',
|
|
||||||
'ignored-command-plugin-skill',
|
|
||||||
'Command plugin fallback skill should be ignored',
|
|
||||||
);
|
|
||||||
await writeClaudePluginManifest(skillPluginInstallPath, 'ExampleSkills');
|
|
||||||
await writeSkill(
|
|
||||||
path.join(skillPluginInstallPath, 'skills'),
|
|
||||||
'claude-plugin-dir',
|
|
||||||
'claude-plugin',
|
|
||||||
'Claude plugin skill',
|
|
||||||
);
|
|
||||||
await writeSkill(
|
|
||||||
path.join(skillPluginInstallPath, 'skills'),
|
|
||||||
'claude-plugin-second-dir',
|
|
||||||
'claude-plugin-second',
|
|
||||||
'Second Claude plugin skill',
|
|
||||||
);
|
|
||||||
await writeSkill(
|
|
||||||
path.join(skillPluginInstallPath, 'skills', 'nested', 'collection'),
|
|
||||||
'claude-plugin-nested-dir',
|
|
||||||
'claude-plugin-nested',
|
|
||||||
'Nested Claude plugin skill',
|
|
||||||
);
|
|
||||||
await writeSkill(
|
|
||||||
path.join(siblingSkillPluginPath, 'skills'),
|
|
||||||
'claude-plugin-sibling-dir',
|
|
||||||
'claude-plugin-sibling',
|
|
||||||
'Sibling Claude plugin skill',
|
|
||||||
);
|
|
||||||
await writeClaudePluginManifest(disabledPluginInstallPath, 'DisabledSkills');
|
|
||||||
await writeClaudePluginCommand(
|
|
||||||
path.join(disabledPluginInstallPath, 'commands'),
|
|
||||||
'disabled-command',
|
|
||||||
'Disabled plugin command',
|
|
||||||
);
|
|
||||||
await writeClaudePluginCommand(
|
|
||||||
path.join(emptyIdPluginInstallPath, 'commands'),
|
|
||||||
'invalid-empty-command',
|
|
||||||
'Invalid empty id command',
|
|
||||||
);
|
|
||||||
await writeClaudePluginCommand(
|
|
||||||
path.join(atIdPluginInstallPath, 'commands'),
|
|
||||||
'invalid-at-command',
|
|
||||||
'Invalid at id command',
|
|
||||||
);
|
|
||||||
await writeSkill(
|
|
||||||
path.join(
|
|
||||||
disabledPluginInstallPath,
|
|
||||||
'skills',
|
|
||||||
),
|
|
||||||
'disabled-plugin-dir',
|
|
||||||
'disabled-plugin',
|
|
||||||
'Disabled plugin skill',
|
|
||||||
);
|
|
||||||
|
|
||||||
await fs.writeFile(
|
|
||||||
path.join(tempRoot, '.claude', 'settings.json'),
|
|
||||||
JSON.stringify(
|
|
||||||
{
|
|
||||||
enabledPlugins: {
|
|
||||||
'': true,
|
|
||||||
'@': true,
|
|
||||||
'notion@notion-marketplace': true,
|
|
||||||
'example-skills@anthropic-agent-skills': true,
|
|
||||||
'disabled-skills@disabled-marketplace': false,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
null,
|
|
||||||
2,
|
|
||||||
),
|
|
||||||
'utf8',
|
|
||||||
);
|
|
||||||
await fs.writeFile(
|
|
||||||
path.join(tempRoot, '.claude', 'plugins', 'installed_plugins.json'),
|
|
||||||
JSON.stringify(
|
|
||||||
{
|
|
||||||
version: 2,
|
|
||||||
plugins: {
|
|
||||||
'': [
|
|
||||||
{
|
|
||||||
scope: 'user',
|
|
||||||
installPath: emptyIdPluginInstallPath,
|
|
||||||
version: '000',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
'@': [
|
|
||||||
{
|
|
||||||
scope: 'user',
|
|
||||||
installPath: atIdPluginInstallPath,
|
|
||||||
version: '000',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
'notion@notion-marketplace': [
|
|
||||||
{
|
|
||||||
scope: 'user',
|
|
||||||
installPath: commandPluginInstallPath,
|
|
||||||
version: 'abc123',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
'example-skills@anthropic-agent-skills': [
|
|
||||||
{
|
|
||||||
scope: 'user',
|
|
||||||
installPath: skillPluginInstallPath,
|
|
||||||
version: 'def456',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
'disabled-skills@disabled-marketplace': [
|
|
||||||
{
|
|
||||||
scope: 'user',
|
|
||||||
installPath: disabledPluginInstallPath,
|
|
||||||
version: 'ghi789',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
null,
|
|
||||||
2,
|
|
||||||
),
|
|
||||||
'utf8',
|
|
||||||
);
|
|
||||||
|
|
||||||
const skills = await providerSkillsService.listProviderSkills('claude', { workspacePath });
|
|
||||||
const byName = new Map(skills.map((skill) => [skill.name, skill]));
|
|
||||||
|
|
||||||
assert.equal(byName.get('claude-user')?.scope, 'user');
|
|
||||||
assert.equal(byName.get('claude-user')?.command, '/claude-user');
|
|
||||||
assert.equal(byName.get('claude-project')?.scope, 'project');
|
|
||||||
assert.equal(byName.get('claude-project')?.command, '/claude-project');
|
|
||||||
|
|
||||||
const pluginCommand = byName.get('insert-row');
|
|
||||||
assert.equal(pluginCommand?.scope, 'plugin');
|
|
||||||
assert.equal(pluginCommand?.pluginName, 'Notion');
|
|
||||||
assert.equal(pluginCommand?.pluginId, 'notion@notion-marketplace');
|
|
||||||
assert.equal(pluginCommand?.command, '/Notion:insert-row');
|
|
||||||
assert.equal(pluginCommand?.description, 'Insert a Notion database row');
|
|
||||||
assert.match(pluginCommand?.sourcePath ?? '', /commands[\\/]insert-row\.md$/);
|
|
||||||
assert.equal(byName.has('ignored-command-plugin-skill'), false);
|
|
||||||
|
|
||||||
const pluginSkill = byName.get('claude-plugin');
|
|
||||||
assert.equal(pluginSkill?.scope, 'plugin');
|
|
||||||
assert.equal(pluginSkill?.pluginName, 'ExampleSkills');
|
|
||||||
assert.equal(pluginSkill?.pluginId, 'example-skills@anthropic-agent-skills');
|
|
||||||
assert.equal(pluginSkill?.command, '/ExampleSkills:claude-plugin');
|
|
||||||
assert.equal(pluginSkill?.description, 'Claude plugin skill');
|
|
||||||
assert.match(
|
|
||||||
pluginSkill?.sourcePath ?? '',
|
|
||||||
/cache[\\/]anthropic-agent-skills[\\/]example-skills[\\/]def456[\\/]skills[\\/]/,
|
|
||||||
);
|
|
||||||
|
|
||||||
const secondPluginSkill = byName.get('claude-plugin-second');
|
|
||||||
assert.equal(secondPluginSkill?.scope, 'plugin');
|
|
||||||
assert.equal(secondPluginSkill?.command, '/ExampleSkills:claude-plugin-second');
|
|
||||||
|
|
||||||
const nestedPluginSkill = byName.get('claude-plugin-nested');
|
|
||||||
assert.equal(nestedPluginSkill?.scope, 'plugin');
|
|
||||||
assert.equal(nestedPluginSkill?.command, '/ExampleSkills:claude-plugin-nested');
|
|
||||||
assert.equal(nestedPluginSkill?.description, 'Nested Claude plugin skill');
|
|
||||||
|
|
||||||
const siblingPluginSkill = byName.get('claude-plugin-sibling');
|
|
||||||
assert.equal(siblingPluginSkill?.scope, 'plugin');
|
|
||||||
assert.equal(siblingPluginSkill?.pluginName, 'example-skills');
|
|
||||||
assert.equal(siblingPluginSkill?.command, '/example-skills:claude-plugin-sibling');
|
|
||||||
assert.equal(siblingPluginSkill?.description, 'Sibling Claude plugin skill');
|
|
||||||
assert.equal(byName.has('disabled-command'), false);
|
|
||||||
assert.equal(byName.has('disabled-plugin'), false);
|
|
||||||
assert.equal(byName.has('invalid-empty-command'), false);
|
|
||||||
assert.equal(byName.has('invalid-at-command'), false);
|
|
||||||
assert.equal(skills.some((skill) => skill.command.startsWith('/:')), false);
|
|
||||||
} finally {
|
|
||||||
restoreHomeDir();
|
|
||||||
await fs.rm(tempRoot, { recursive: true, force: true });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This test covers Codex repository/user/system skill folders and verifies that
|
|
||||||
* repository lookup includes cwd, parent, and git root skill locations.
|
|
||||||
*/
|
|
||||||
test('providerSkillsService lists codex repository, user, and system skills', { concurrency: false }, async () => {
|
|
||||||
const tempRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'llm-skills-codex-'));
|
|
||||||
const repoRoot = path.join(tempRoot, 'repo');
|
|
||||||
const workspacePath = path.join(repoRoot, 'packages', 'app');
|
|
||||||
await fs.mkdir(path.join(repoRoot, '.git'), { recursive: true });
|
|
||||||
await fs.mkdir(workspacePath, { recursive: true });
|
|
||||||
|
|
||||||
const restoreHomeDir = patchHomeDir(tempRoot);
|
|
||||||
try {
|
|
||||||
await writeSkill(
|
|
||||||
path.join(workspacePath, '.agents', 'skills'),
|
|
||||||
'codex-cwd-dir',
|
|
||||||
'codex-cwd',
|
|
||||||
'Codex cwd skill',
|
|
||||||
);
|
|
||||||
await writeSkill(
|
|
||||||
path.join(repoRoot, 'packages', '.agents', 'skills'),
|
|
||||||
'codex-parent-dir',
|
|
||||||
'codex-parent',
|
|
||||||
'Codex parent skill',
|
|
||||||
);
|
|
||||||
await writeSkill(
|
|
||||||
path.join(repoRoot, '.agents', 'skills'),
|
|
||||||
'codex-root-dir',
|
|
||||||
'codex-root',
|
|
||||||
'Codex root skill',
|
|
||||||
);
|
|
||||||
await writeSkill(
|
|
||||||
path.join(tempRoot, '.agents', 'skills'),
|
|
||||||
'codex-user-dir',
|
|
||||||
'codex-user',
|
|
||||||
'Codex user skill',
|
|
||||||
);
|
|
||||||
await writeSkill(
|
|
||||||
path.join(tempRoot, '.codex', 'skills', '.system'),
|
|
||||||
'codex-system-dir',
|
|
||||||
'codex-system',
|
|
||||||
'Codex system skill',
|
|
||||||
);
|
|
||||||
|
|
||||||
const skills = await providerSkillsService.listProviderSkills('codex', { workspacePath });
|
|
||||||
const byName = new Map(skills.map((skill) => [skill.name, skill]));
|
|
||||||
|
|
||||||
assert.equal(byName.get('codex-cwd')?.scope, 'repo');
|
|
||||||
assert.equal(byName.get('codex-parent')?.scope, 'repo');
|
|
||||||
assert.equal(byName.get('codex-root')?.scope, 'repo');
|
|
||||||
assert.equal(byName.get('codex-user')?.scope, 'user');
|
|
||||||
assert.equal(byName.get('codex-system')?.scope, 'system');
|
|
||||||
assert.equal(byName.get('codex-root')?.command, '$codex-root');
|
|
||||||
} finally {
|
|
||||||
restoreHomeDir();
|
|
||||||
await fs.rm(tempRoot, { recursive: true, force: true });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This test covers Gemini and Cursor skill directory rules, including shared
|
|
||||||
* `.agents/skills` project support.
|
|
||||||
*/
|
|
||||||
test('providerSkillsService lists gemini and cursor skills from their configured directories', { concurrency: false }, async () => {
|
|
||||||
const tempRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'llm-skills-gc-'));
|
|
||||||
const workspacePath = path.join(tempRoot, 'workspace');
|
|
||||||
await fs.mkdir(workspacePath, { recursive: true });
|
|
||||||
|
|
||||||
const restoreHomeDir = patchHomeDir(tempRoot);
|
|
||||||
try {
|
|
||||||
await writeSkill(
|
|
||||||
path.join(tempRoot, '.gemini', 'skills'),
|
|
||||||
'gemini-user-dir',
|
|
||||||
'gemini-user',
|
|
||||||
'Gemini user skill',
|
|
||||||
);
|
|
||||||
await writeSkill(
|
|
||||||
path.join(tempRoot, '.agents', 'skills'),
|
|
||||||
'agents-user-dir',
|
|
||||||
'agents-user',
|
|
||||||
'Agents user skill',
|
|
||||||
);
|
|
||||||
await writeSkill(
|
|
||||||
path.join(workspacePath, '.gemini', 'skills'),
|
|
||||||
'gemini-project-dir',
|
|
||||||
'gemini-project',
|
|
||||||
'Gemini project skill',
|
|
||||||
);
|
|
||||||
await writeSkill(
|
|
||||||
path.join(workspacePath, '.agents', 'skills'),
|
|
||||||
'agents-project-dir',
|
|
||||||
'agents-project',
|
|
||||||
'Agents project skill',
|
|
||||||
);
|
|
||||||
await writeSkill(
|
|
||||||
path.join(workspacePath, '.cursor', 'skills'),
|
|
||||||
'cursor-project-dir',
|
|
||||||
'cursor-project',
|
|
||||||
'Cursor project skill',
|
|
||||||
);
|
|
||||||
await writeSkill(
|
|
||||||
path.join(tempRoot, '.cursor', 'skills'),
|
|
||||||
'cursor-user-dir',
|
|
||||||
'cursor-user',
|
|
||||||
'Cursor user skill',
|
|
||||||
);
|
|
||||||
|
|
||||||
const geminiSkills = await providerSkillsService.listProviderSkills('gemini', { workspacePath });
|
|
||||||
const geminiByName = new Map(geminiSkills.map((skill) => [skill.name, skill]));
|
|
||||||
assert.equal(geminiByName.get('gemini-user')?.scope, 'user');
|
|
||||||
assert.equal(geminiByName.get('agents-user')?.scope, 'user');
|
|
||||||
assert.equal(geminiByName.get('gemini-project')?.scope, 'project');
|
|
||||||
assert.equal(geminiByName.get('agents-project')?.scope, 'project');
|
|
||||||
assert.equal(geminiByName.get('gemini-project')?.command, '/gemini-project');
|
|
||||||
|
|
||||||
const cursorSkills = await providerSkillsService.listProviderSkills('cursor', { workspacePath });
|
|
||||||
const cursorByName = new Map(cursorSkills.map((skill) => [skill.name, skill]));
|
|
||||||
assert.equal(cursorByName.get('agents-project')?.scope, 'project');
|
|
||||||
assert.equal(cursorByName.get('cursor-project')?.scope, 'project');
|
|
||||||
assert.equal(cursorByName.get('cursor-user')?.scope, 'user');
|
|
||||||
assert.equal(cursorByName.get('cursor-user')?.command, '/cursor-user');
|
|
||||||
} finally {
|
|
||||||
restoreHomeDir();
|
|
||||||
await fs.rm(tempRoot, { recursive: true, force: true });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
@@ -143,7 +143,7 @@ function transformCodexEvent(event) {
|
|||||||
case 'thread.started':
|
case 'thread.started':
|
||||||
return {
|
return {
|
||||||
type: 'thread_started',
|
type: 'thread_started',
|
||||||
threadId: event.thread_id || event.id
|
threadId: event.id
|
||||||
};
|
};
|
||||||
|
|
||||||
case 'error':
|
case 'error':
|
||||||
@@ -207,8 +207,7 @@ export async function queryCodex(command, options = {}, ws) {
|
|||||||
|
|
||||||
let codex;
|
let codex;
|
||||||
let thread;
|
let thread;
|
||||||
let capturedSessionId = sessionId;
|
let currentSessionId = sessionId;
|
||||||
let sessionCreatedSent = false;
|
|
||||||
let terminalFailure = null;
|
let terminalFailure = null;
|
||||||
const abortController = new AbortController();
|
const abortController = new AbortController();
|
||||||
|
|
||||||
@@ -232,23 +231,20 @@ export async function queryCodex(command, options = {}, ws) {
|
|||||||
thread = codex.startThread(threadOptions);
|
thread = codex.startThread(threadOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
const registerSession = (id) => {
|
// Get the thread ID
|
||||||
if (!id) {
|
currentSessionId = thread.id || sessionId || `codex-${Date.now()}`;
|
||||||
return;
|
|
||||||
}
|
|
||||||
activeCodexSessions.set(id, {
|
|
||||||
thread,
|
|
||||||
codex,
|
|
||||||
status: 'running',
|
|
||||||
abortController,
|
|
||||||
startedAt: new Date().toISOString()
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
// Existing sessions can be tracked immediately; new sessions are tracked after thread.started.
|
// Track the session
|
||||||
if (capturedSessionId) {
|
activeCodexSessions.set(currentSessionId, {
|
||||||
registerSession(capturedSessionId);
|
thread,
|
||||||
}
|
codex,
|
||||||
|
status: 'running',
|
||||||
|
abortController,
|
||||||
|
startedAt: new Date().toISOString()
|
||||||
|
});
|
||||||
|
|
||||||
|
// Send session created event
|
||||||
|
sendMessage(ws, createNormalizedMessage({ kind: 'session_created', newSessionId: currentSessionId, sessionId: currentSessionId, provider: 'codex' }));
|
||||||
|
|
||||||
// Execute with streaming
|
// Execute with streaming
|
||||||
const streamedTurn = await thread.runStreamed(command, {
|
const streamedTurn = await thread.runStreamed(command, {
|
||||||
@@ -256,34 +252,11 @@ export async function queryCodex(command, options = {}, ws) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
for await (const event of streamedTurn.events) {
|
for await (const event of streamedTurn.events) {
|
||||||
// Capture thread/session id lazily from the stream (Codex emits this asynchronously).
|
|
||||||
if (event.type === 'thread.started') {
|
|
||||||
const discoveredSessionId = event.thread_id || event.id || null;
|
|
||||||
if (discoveredSessionId && !capturedSessionId) {
|
|
||||||
capturedSessionId = discoveredSessionId;
|
|
||||||
registerSession(capturedSessionId);
|
|
||||||
|
|
||||||
if (ws.setSessionId && typeof ws.setSessionId === 'function') {
|
|
||||||
ws.setSessionId(capturedSessionId);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!sessionId && !sessionCreatedSent) {
|
|
||||||
sessionCreatedSent = true;
|
|
||||||
sendMessage(ws, createNormalizedMessage({ kind: 'session_created', newSessionId: capturedSessionId, sessionId: capturedSessionId, provider: 'codex' }));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if session was aborted
|
// Check if session was aborted
|
||||||
if (abortController.signal.aborted) {
|
const session = activeCodexSessions.get(currentSessionId);
|
||||||
|
if (!session || session.status === 'aborted') {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (capturedSessionId) {
|
|
||||||
const session = activeCodexSessions.get(capturedSessionId);
|
|
||||||
if (session?.status === 'aborted') {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event.type === 'item.started' || event.type === 'item.updated') {
|
if (event.type === 'item.started' || event.type === 'item.updated') {
|
||||||
continue;
|
continue;
|
||||||
@@ -292,7 +265,7 @@ export async function queryCodex(command, options = {}, ws) {
|
|||||||
const transformed = transformCodexEvent(event);
|
const transformed = transformCodexEvent(event);
|
||||||
|
|
||||||
// Normalize the transformed event into NormalizedMessage(s) via adapter
|
// Normalize the transformed event into NormalizedMessage(s) via adapter
|
||||||
const normalizedMsgs = sessionsService.normalizeMessage('codex', transformed, capturedSessionId || sessionId || null);
|
const normalizedMsgs = sessionsService.normalizeMessage('codex', transformed, currentSessionId);
|
||||||
for (const msg of normalizedMsgs) {
|
for (const msg of normalizedMsgs) {
|
||||||
sendMessage(ws, msg);
|
sendMessage(ws, msg);
|
||||||
}
|
}
|
||||||
@@ -302,7 +275,7 @@ export async function queryCodex(command, options = {}, ws) {
|
|||||||
notifyRunFailed({
|
notifyRunFailed({
|
||||||
userId: ws?.userId || null,
|
userId: ws?.userId || null,
|
||||||
provider: 'codex',
|
provider: 'codex',
|
||||||
sessionId: capturedSessionId || sessionId || null,
|
sessionId: currentSessionId,
|
||||||
sessionName: sessionSummary,
|
sessionName: sessionSummary,
|
||||||
error: terminalFailure
|
error: terminalFailure
|
||||||
});
|
});
|
||||||
@@ -311,29 +284,24 @@ export async function queryCodex(command, options = {}, ws) {
|
|||||||
// Extract and send token usage if available (normalized to match Claude format)
|
// Extract and send token usage if available (normalized to match Claude format)
|
||||||
if (event.type === 'turn.completed' && event.usage) {
|
if (event.type === 'turn.completed' && event.usage) {
|
||||||
const totalTokens = (event.usage.input_tokens || 0) + (event.usage.output_tokens || 0);
|
const totalTokens = (event.usage.input_tokens || 0) + (event.usage.output_tokens || 0);
|
||||||
sendMessage(ws, createNormalizedMessage({ kind: 'status', text: 'token_budget', tokenBudget: { used: totalTokens, total: 200000 }, sessionId: capturedSessionId || sessionId || null, provider: 'codex' }));
|
sendMessage(ws, createNormalizedMessage({ kind: 'status', text: 'token_budget', tokenBudget: { used: totalTokens, total: 200000 }, sessionId: currentSessionId, provider: 'codex' }));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send completion event
|
// Send completion event
|
||||||
if (!terminalFailure) {
|
if (!terminalFailure) {
|
||||||
sendMessage(ws, createNormalizedMessage({
|
sendMessage(ws, createNormalizedMessage({ kind: 'complete', actualSessionId: thread.id, sessionId: currentSessionId, provider: 'codex' }));
|
||||||
kind: 'complete',
|
|
||||||
actualSessionId: capturedSessionId || thread.id || sessionId || null,
|
|
||||||
sessionId: capturedSessionId || sessionId || null,
|
|
||||||
provider: 'codex'
|
|
||||||
}));
|
|
||||||
notifyRunStopped({
|
notifyRunStopped({
|
||||||
userId: ws?.userId || null,
|
userId: ws?.userId || null,
|
||||||
provider: 'codex',
|
provider: 'codex',
|
||||||
sessionId: capturedSessionId || sessionId || null,
|
sessionId: currentSessionId,
|
||||||
sessionName: sessionSummary,
|
sessionName: sessionSummary,
|
||||||
stopReason: 'completed'
|
stopReason: 'completed'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const session = capturedSessionId ? activeCodexSessions.get(capturedSessionId) : null;
|
const session = currentSessionId ? activeCodexSessions.get(currentSessionId) : null;
|
||||||
const wasAborted =
|
const wasAborted =
|
||||||
session?.status === 'aborted' ||
|
session?.status === 'aborted' ||
|
||||||
error?.name === 'AbortError' ||
|
error?.name === 'AbortError' ||
|
||||||
@@ -348,12 +316,12 @@ export async function queryCodex(command, options = {}, ws) {
|
|||||||
? 'Codex CLI is not configured. Please set up authentication first.'
|
? 'Codex CLI is not configured. Please set up authentication first.'
|
||||||
: error.message;
|
: error.message;
|
||||||
|
|
||||||
sendMessage(ws, createNormalizedMessage({ kind: 'error', content: errorContent, sessionId: capturedSessionId || sessionId || null, provider: 'codex' }));
|
sendMessage(ws, createNormalizedMessage({ kind: 'error', content: errorContent, sessionId: currentSessionId, provider: 'codex' }));
|
||||||
if (!terminalFailure) {
|
if (!terminalFailure) {
|
||||||
notifyRunFailed({
|
notifyRunFailed({
|
||||||
userId: ws?.userId || null,
|
userId: ws?.userId || null,
|
||||||
provider: 'codex',
|
provider: 'codex',
|
||||||
sessionId: capturedSessionId || sessionId || null,
|
sessionId: currentSessionId,
|
||||||
sessionName: sessionSummary,
|
sessionName: sessionSummary,
|
||||||
error
|
error
|
||||||
});
|
});
|
||||||
@@ -362,8 +330,8 @@ export async function queryCodex(command, options = {}, ws) {
|
|||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
// Update session status
|
// Update session status
|
||||||
if (capturedSessionId) {
|
if (currentSessionId) {
|
||||||
const session = activeCodexSessions.get(capturedSessionId);
|
const session = activeCodexSessions.get(currentSessionId);
|
||||||
if (session) {
|
if (session) {
|
||||||
session.status = session.status === 'aborted' ? 'aborted' : 'completed';
|
session.status = session.status === 'aborted' ? 'aborted' : 'completed';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,9 @@
|
|||||||
import { promises as fs } from 'fs';
|
|
||||||
import os from 'os';
|
|
||||||
import path from 'path';
|
|
||||||
|
|
||||||
import express from 'express';
|
import express from 'express';
|
||||||
|
import { promises as fs } from 'fs';
|
||||||
|
import path from 'path';
|
||||||
|
import os from 'os';
|
||||||
import { CLAUDE_MODELS, CURSOR_MODELS, CODEX_MODELS } from '../../shared/modelConstants.js';
|
import { CLAUDE_MODELS, CURSOR_MODELS, CODEX_MODELS } from '../../shared/modelConstants.js';
|
||||||
import { parseFrontMatter } from '../shared/frontmatter.js';
|
import { parseFrontmatter } from '../utils/frontmatter.js';
|
||||||
import { findAppRoot, getModuleDir } from '../utils/runtime-paths.js';
|
import { findAppRoot, getModuleDir } from '../utils/runtime-paths.js';
|
||||||
|
|
||||||
const __dirname = getModuleDir(import.meta.url);
|
const __dirname = getModuleDir(import.meta.url);
|
||||||
@@ -42,7 +40,7 @@ async function scanCommandsDirectory(dir, baseDir, namespace) {
|
|||||||
// Parse markdown file for metadata
|
// Parse markdown file for metadata
|
||||||
try {
|
try {
|
||||||
const content = await fs.readFile(fullPath, 'utf8');
|
const content = await fs.readFile(fullPath, 'utf8');
|
||||||
const { data: frontmatter, content: commandContent } = parseFrontMatter(content);
|
const { data: frontmatter, content: commandContent } = parseFrontmatter(content);
|
||||||
|
|
||||||
// Calculate relative path from baseDir for command name
|
// Calculate relative path from baseDir for command name
|
||||||
const relativePath = path.relative(baseDir, fullPath);
|
const relativePath = path.relative(baseDir, fullPath);
|
||||||
@@ -515,7 +513,7 @@ router.post('/execute', async (req, res) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
const content = await fs.readFile(commandPath, 'utf8');
|
const content = await fs.readFile(commandPath, 'utf8');
|
||||||
const { data: metadata, content: commandContent } = parseFrontMatter(content);
|
const { data: metadata, content: commandContent } = parseFrontmatter(content);
|
||||||
// Basic argument replacement (will be enhanced in command parser utility)
|
// Basic argument replacement (will be enhanced in command parser utility)
|
||||||
let processedContent = commandContent;
|
let processedContent = commandContent;
|
||||||
|
|
||||||
|
|||||||
@@ -4,8 +4,6 @@ import type {
|
|||||||
LLMProvider,
|
LLMProvider,
|
||||||
McpScope,
|
McpScope,
|
||||||
NormalizedMessage,
|
NormalizedMessage,
|
||||||
ProviderSkill,
|
|
||||||
ProviderSkillListOptions,
|
|
||||||
ProviderAuthStatus,
|
ProviderAuthStatus,
|
||||||
ProviderMcpServer,
|
ProviderMcpServer,
|
||||||
UpsertProviderMcpServerInput,
|
UpsertProviderMcpServerInput,
|
||||||
@@ -22,7 +20,6 @@ export interface IProvider {
|
|||||||
readonly id: LLMProvider;
|
readonly id: LLMProvider;
|
||||||
readonly mcp: IProviderMcp;
|
readonly mcp: IProviderMcp;
|
||||||
readonly auth: IProviderAuth;
|
readonly auth: IProviderAuth;
|
||||||
readonly skills: IProviderSkills;
|
|
||||||
readonly sessions: IProviderSessions;
|
readonly sessions: IProviderSessions;
|
||||||
readonly sessionSynchronizer: IProviderSessionSynchronizer;
|
readonly sessionSynchronizer: IProviderSessionSynchronizer;
|
||||||
}
|
}
|
||||||
@@ -42,22 +39,6 @@ export interface IProviderAuth {
|
|||||||
getStatus(): Promise<ProviderAuthStatus>;
|
getStatus(): Promise<ProviderAuthStatus>;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------
|
|
||||||
//----------------- PROVIDER SKILLS INTERFACE ------------
|
|
||||||
/**
|
|
||||||
* Skills contract for one provider.
|
|
||||||
*
|
|
||||||
* Implementations discover provider-native skill markdown locations and return
|
|
||||||
* normalized skill records with the exact command syntax expected by that
|
|
||||||
* provider. Each skill is read from a `SKILL.md` file under its skill directory.
|
|
||||||
*/
|
|
||||||
export interface IProviderSkills {
|
|
||||||
/**
|
|
||||||
* Lists all skills visible to this provider for the optional workspace.
|
|
||||||
*/
|
|
||||||
listSkills(options?: ProviderSkillListOptions): Promise<ProviderSkill[]>;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---------------------------
|
// ---------------------------
|
||||||
//----------------- PROVIDER MCP INTERFACE ------------
|
//----------------- PROVIDER MCP INTERFACE ------------
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -102,21 +102,6 @@ export type NormalizedMessage = {
|
|||||||
kind: MessageKind;
|
kind: MessageKind;
|
||||||
role?: 'user' | 'assistant';
|
role?: 'user' | 'assistant';
|
||||||
content?: string;
|
content?: string;
|
||||||
/**
|
|
||||||
* Optional display-oriented metadata used by providers that need to expose
|
|
||||||
* richer transcript artifacts without introducing a brand-new message kind.
|
|
||||||
*
|
|
||||||
* Current Claude usage:
|
|
||||||
* - local slash commands expose parsed command fields
|
|
||||||
* - compact summaries are flagged so the UI can treat them differently later
|
|
||||||
*/
|
|
||||||
displayText?: string;
|
|
||||||
commandName?: string;
|
|
||||||
commandMessage?: string;
|
|
||||||
commandArgs?: string;
|
|
||||||
isLocalCommand?: boolean;
|
|
||||||
isLocalCommandStdout?: boolean;
|
|
||||||
isCompactSummary?: boolean;
|
|
||||||
images?: unknown;
|
images?: unknown;
|
||||||
toolName?: string;
|
toolName?: string;
|
||||||
toolInput?: unknown;
|
toolInput?: unknown;
|
||||||
@@ -171,69 +156,6 @@ export type FetchHistoryResult = {
|
|||||||
tokenUsage?: unknown;
|
tokenUsage?: unknown;
|
||||||
};
|
};
|
||||||
|
|
||||||
// ---------------------------
|
|
||||||
//----------------- PROVIDER SKILL TYPES ------------
|
|
||||||
/**
|
|
||||||
* Scope where a provider skill definition was discovered.
|
|
||||||
*
|
|
||||||
* Provider skill adapters should use this to describe the origin of each
|
|
||||||
* skill markdown file without leaking provider-specific folder names into route
|
|
||||||
* contracts. `repo` is used for Codex repository lookup locations, while
|
|
||||||
* `project` is used for providers that treat workspace-local skills as project
|
|
||||||
* scoped.
|
|
||||||
*/
|
|
||||||
export type ProviderSkillScope = 'user' | 'project' | 'plugin' | 'repo' | 'admin' | 'system';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Shared input accepted by provider skill listing operations.
|
|
||||||
*
|
|
||||||
* Routes pass `workspacePath` when a caller wants project/repository skills for
|
|
||||||
* a specific folder. Providers should fall back to the backend process cwd when
|
|
||||||
* this option is omitted.
|
|
||||||
*/
|
|
||||||
export type ProviderSkillListOptions = {
|
|
||||||
workspacePath?: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Normalized skill record returned by provider skill adapters.
|
|
||||||
*
|
|
||||||
* The `command` value is the exact invocation text the selected provider expects
|
|
||||||
* for this skill. Claude plugin skills use a namespaced command such as
|
|
||||||
* `/plugin-name:skill-name`, while Codex skills use the `$skill-name` form.
|
|
||||||
* `sourcePath` points to the skill markdown file that produced the record so
|
|
||||||
* callers can distinguish duplicate skill names across scopes.
|
|
||||||
*/
|
|
||||||
export type ProviderSkill = {
|
|
||||||
provider: LLMProvider;
|
|
||||||
name: string;
|
|
||||||
description: string;
|
|
||||||
command: string;
|
|
||||||
scope: ProviderSkillScope;
|
|
||||||
sourcePath: string;
|
|
||||||
pluginName?: string;
|
|
||||||
pluginId?: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Internal source descriptor consumed by shared provider skill discovery logic.
|
|
||||||
*
|
|
||||||
* Concrete provider adapters build these records from their native lookup rules.
|
|
||||||
* The shared skills provider then scans `rootDir` for child skill markdown files
|
|
||||||
* and uses `commandForSkill` or `commandPrefix` to produce the provider-specific
|
|
||||||
* invocation command. Set `recursive` only when a provider stores skills under
|
|
||||||
* arbitrary nested folders below the source root.
|
|
||||||
*/
|
|
||||||
export type ProviderSkillSource = {
|
|
||||||
scope: ProviderSkillScope;
|
|
||||||
rootDir: string;
|
|
||||||
recursive?: boolean;
|
|
||||||
commandPrefix?: '/' | '$';
|
|
||||||
commandForSkill?: (skillName: string) => string;
|
|
||||||
pluginName?: string;
|
|
||||||
pluginId?: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
// ---------------------------
|
// ---------------------------
|
||||||
//----------------- SHARED ERROR TYPES ------------
|
//----------------- SHARED ERROR TYPES ------------
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ import readline from 'node:readline';
|
|||||||
|
|
||||||
import type { NextFunction, Request, RequestHandler, Response } from 'express';
|
import type { NextFunction, Request, RequestHandler, Response } from 'express';
|
||||||
|
|
||||||
import { parseFrontMatter } from '@/shared/frontmatter.js';
|
|
||||||
import type {
|
import type {
|
||||||
AnyRecord,
|
AnyRecord,
|
||||||
ApiSuccessShape,
|
ApiSuccessShape,
|
||||||
@@ -504,99 +503,6 @@ export const writeJsonConfig = async (filePath: string, data: Record<string, unk
|
|||||||
await writeFile(filePath, `${JSON.stringify(data, null, 2)}\n`, 'utf8');
|
await writeFile(filePath, `${JSON.stringify(data, null, 2)}\n`, 'utf8');
|
||||||
};
|
};
|
||||||
|
|
||||||
// ---------------------------
|
|
||||||
//----------------- PROVIDER SKILL FILE UTILITIES ------------
|
|
||||||
/**
|
|
||||||
* Finds direct child skill markdown files under a provider skill root.
|
|
||||||
*
|
|
||||||
* Skill systems usually store one skill per child directory, so direct mode
|
|
||||||
* scans only `<root>/<skill-name>/SKILL.md`. Recursive mode is reserved for
|
|
||||||
* provider sources that can nest skills arbitrarily, and it returns every
|
|
||||||
* descendant `SKILL.md`. Missing or unreadable roots return an empty list
|
|
||||||
* because users may not have every provider installed or configured.
|
|
||||||
*/
|
|
||||||
export async function findProviderSkillMarkdownFiles(
|
|
||||||
rootDir: string,
|
|
||||||
options: { recursive?: boolean } = {},
|
|
||||||
): Promise<string[]> {
|
|
||||||
const skillFiles: string[] = [];
|
|
||||||
|
|
||||||
const collectRecursive = async (dirPath: string): Promise<void> => {
|
|
||||||
let entries;
|
|
||||||
try {
|
|
||||||
entries = await readdir(dirPath, { withFileTypes: true });
|
|
||||||
} catch {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const skillPath = path.join(dirPath, 'SKILL.md');
|
|
||||||
const skillStats = await stat(skillPath);
|
|
||||||
if (skillStats.isFile()) {
|
|
||||||
skillFiles.push(skillPath);
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
// Directories without SKILL.md are expected while walking plugin trees.
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const entry of entries) {
|
|
||||||
if (entry.isDirectory()) {
|
|
||||||
await collectRecursive(path.join(dirPath, entry.name));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if (options.recursive) {
|
|
||||||
await collectRecursive(rootDir);
|
|
||||||
return skillFiles.sort((left, right) => left.localeCompare(right));
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const entries = await readdir(rootDir, { withFileTypes: true });
|
|
||||||
|
|
||||||
for (const entry of entries) {
|
|
||||||
if (!entry.isDirectory()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const skillPath = path.join(rootDir, entry.name, 'SKILL.md');
|
|
||||||
try {
|
|
||||||
const skillStats = await stat(skillPath);
|
|
||||||
if (skillStats.isFile()) {
|
|
||||||
skillFiles.push(skillPath);
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
// A partial skill directory should not block discovery of sibling skills.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return skillFiles.sort((left, right) => left.localeCompare(right));
|
|
||||||
} catch {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reads the `name` and `description` fields from a provider skill markdown file.
|
|
||||||
*
|
|
||||||
* The metadata is expected in markdown front matter. If a skill omits `name`, the
|
|
||||||
* parent directory name is used as a stable fallback so providers can still
|
|
||||||
* expose the skill. Missing descriptions are normalized to an empty string.
|
|
||||||
*/
|
|
||||||
export async function readProviderSkillMarkdownDefinition(
|
|
||||||
skillPath: string,
|
|
||||||
): Promise<{ name: string; description: string }> {
|
|
||||||
const content = await readFile(skillPath, 'utf8');
|
|
||||||
const parsed = parseFrontMatter(content);
|
|
||||||
const data = readObjectRecord(parsed.data) ?? {};
|
|
||||||
const fallbackName = path.basename(path.dirname(skillPath));
|
|
||||||
|
|
||||||
return {
|
|
||||||
name: readOptionalString(data.name) ?? fallbackName,
|
|
||||||
description: readOptionalString(data.description) ?? '',
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---------------------------
|
// ---------------------------
|
||||||
//----------------- SESSION SYNCHRONIZER TITLE HELPERS ------------
|
//----------------- SESSION SYNCHRONIZER TITLE HELPERS ------------
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,11 +1,9 @@
|
|||||||
import { execFile } from 'child_process';
|
|
||||||
import { promises as fs } from 'fs';
|
import { promises as fs } from 'fs';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
import { execFile } from 'child_process';
|
||||||
import { promisify } from 'util';
|
import { promisify } from 'util';
|
||||||
|
|
||||||
import { parse as parseShellCommand } from 'shell-quote';
|
import { parse as parseShellCommand } from 'shell-quote';
|
||||||
|
import { parseFrontmatter } from './frontmatter.js';
|
||||||
import { parseFrontMatter } from '../shared/frontmatter.js';
|
|
||||||
|
|
||||||
const execFileAsync = promisify(execFile);
|
const execFileAsync = promisify(execFile);
|
||||||
|
|
||||||
@@ -34,7 +32,7 @@ const BASH_COMMAND_ALLOWLIST = [
|
|||||||
*/
|
*/
|
||||||
export function parseCommand(content) {
|
export function parseCommand(content) {
|
||||||
try {
|
try {
|
||||||
const parsed = parseFrontMatter(content);
|
const parsed = parseFrontmatter(content);
|
||||||
return {
|
return {
|
||||||
data: parsed.data || {},
|
data: parsed.data || {},
|
||||||
content: parsed.content || '',
|
content: parsed.content || '',
|
||||||
|
|||||||
@@ -9,10 +9,10 @@ const frontmatterOptions = {
|
|||||||
engines: {
|
engines: {
|
||||||
js: disabledFrontmatterEngine,
|
js: disabledFrontmatterEngine,
|
||||||
javascript: disabledFrontmatterEngine,
|
javascript: disabledFrontmatterEngine,
|
||||||
json: disabledFrontmatterEngine,
|
json: disabledFrontmatterEngine
|
||||||
},
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export function parseFrontMatter(content: string) {
|
export function parseFrontmatter(content) {
|
||||||
return matter(content, frontmatterOptions);
|
return matter(content, frontmatterOptions);
|
||||||
}
|
}
|
||||||
@@ -84,7 +84,6 @@ export const GEMINI_MODELS = {
|
|||||||
{ value: "gemini-2.5-flash", label: "Gemini 2.5 Flash" },
|
{ value: "gemini-2.5-flash", label: "Gemini 2.5 Flash" },
|
||||||
{ value: "gemini-2.5-pro", label: "Gemini 2.5 Pro" },
|
{ value: "gemini-2.5-pro", label: "Gemini 2.5 Pro" },
|
||||||
{ value: "gemini-2.0-flash-lite", label: "Gemini 2.0 Flash Lite" },
|
{ value: "gemini-2.0-flash-lite", label: "Gemini 2.0 Flash Lite" },
|
||||||
{ value: "gemini-2.5-flash-lite", label: "Gemini 2.5 Flash Lite" },
|
|
||||||
{ value: "gemini-2.0-flash", label: "Gemini 2.0 Flash" },
|
{ value: "gemini-2.0-flash", label: "Gemini 2.0 Flash" },
|
||||||
{ value: "gemini-2.0-pro-exp", label: "Gemini 2.0 Pro Experimental" },
|
{ value: "gemini-2.0-pro-exp", label: "Gemini 2.0 Pro Experimental" },
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ function AppContentInner() {
|
|||||||
markSessionAsInactive,
|
markSessionAsInactive,
|
||||||
markSessionAsProcessing,
|
markSessionAsProcessing,
|
||||||
markSessionAsNotProcessing,
|
markSessionAsNotProcessing,
|
||||||
|
replaceTemporarySession,
|
||||||
} = useSessionProtection();
|
} = useSessionProtection();
|
||||||
|
|
||||||
const {
|
const {
|
||||||
@@ -190,6 +191,7 @@ function AppContentInner() {
|
|||||||
onSessionProcessing={markSessionAsProcessing}
|
onSessionProcessing={markSessionAsProcessing}
|
||||||
onSessionNotProcessing={markSessionAsNotProcessing}
|
onSessionNotProcessing={markSessionAsNotProcessing}
|
||||||
processingSessions={processingSessions}
|
processingSessions={processingSessions}
|
||||||
|
onReplaceTemporarySession={replaceTemporarySession}
|
||||||
onNavigateToSession={(targetSessionId: string, options) =>
|
onNavigateToSession={(targetSessionId: string, options) =>
|
||||||
navigate(`/session/${targetSessionId}`, { replace: Boolean(options?.replace) })
|
navigate(`/session/${targetSessionId}`, { replace: Boolean(options?.replace) })
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import type {
|
|||||||
TouchEvent,
|
TouchEvent,
|
||||||
} from 'react';
|
} from 'react';
|
||||||
import { useDropzone } from 'react-dropzone';
|
import { useDropzone } from 'react-dropzone';
|
||||||
|
|
||||||
import { authenticatedFetch } from '../../../utils/api';
|
import { authenticatedFetch } from '../../../utils/api';
|
||||||
import { thinkingModes } from '../constants/thinkingModes';
|
import { thinkingModes } from '../constants/thinkingModes';
|
||||||
import { grantClaudeToolPermission } from '../utils/chatPermissions';
|
import { grantClaudeToolPermission } from '../utils/chatPermissions';
|
||||||
@@ -22,7 +21,6 @@ import type {
|
|||||||
} from '../types/types';
|
} from '../types/types';
|
||||||
import type { Project, ProjectSession, LLMProvider } from '../../../types/app';
|
import type { Project, ProjectSession, LLMProvider } from '../../../types/app';
|
||||||
import { escapeRegExp } from '../utils/chatFormatting';
|
import { escapeRegExp } from '../utils/chatFormatting';
|
||||||
|
|
||||||
import { useFileMentions } from './useFileMentions';
|
import { useFileMentions } from './useFileMentions';
|
||||||
import { type SlashCommand, useSlashCommands } from './useSlashCommands';
|
import { type SlashCommand, useSlashCommands } from './useSlashCommands';
|
||||||
|
|
||||||
@@ -82,6 +80,9 @@ const createFakeSubmitEvent = () => {
|
|||||||
return { preventDefault: () => undefined } as unknown as FormEvent<HTMLFormElement>;
|
return { preventDefault: () => undefined } as unknown as FormEvent<HTMLFormElement>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const isTemporarySessionId = (sessionId: string | null | undefined) =>
|
||||||
|
Boolean(sessionId && sessionId.startsWith('new-session-'));
|
||||||
|
|
||||||
const getNotificationSessionSummary = (
|
const getNotificationSessionSummary = (
|
||||||
selectedSession: ProjectSession | null,
|
selectedSession: ProjectSession | null,
|
||||||
fallbackInput: string,
|
fallbackInput: string,
|
||||||
@@ -152,7 +153,6 @@ export function useChatComposerState({
|
|||||||
((event: FormEvent<HTMLFormElement> | MouseEvent | TouchEvent | KeyboardEvent<HTMLTextAreaElement>) => Promise<void>) | null
|
((event: FormEvent<HTMLFormElement> | MouseEvent | TouchEvent | KeyboardEvent<HTMLTextAreaElement>) => Promise<void>) | null
|
||||||
>(null);
|
>(null);
|
||||||
const inputValueRef = useRef(input);
|
const inputValueRef = useRef(input);
|
||||||
const selectedProjectId = selectedProject?.projectId;
|
|
||||||
|
|
||||||
const handleBuiltInCommand = useCallback(
|
const handleBuiltInCommand = useCallback(
|
||||||
(result: CommandExecutionResult) => {
|
(result: CommandExecutionResult) => {
|
||||||
@@ -362,7 +362,6 @@ export function useChatComposerState({
|
|||||||
handleCommandMenuKeyDown,
|
handleCommandMenuKeyDown,
|
||||||
} = useSlashCommands({
|
} = useSlashCommands({
|
||||||
selectedProject,
|
selectedProject,
|
||||||
provider,
|
|
||||||
input,
|
input,
|
||||||
setInput,
|
setInput,
|
||||||
textareaRef,
|
textareaRef,
|
||||||
@@ -472,14 +471,14 @@ export function useChatComposerState({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Intercept slash commands only when "/" is the first input character.
|
// Intercept slash commands: if input starts with /commandName, execute as command with args
|
||||||
const commandInput = currentInput.trimEnd();
|
const trimmedInput = currentInput.trim();
|
||||||
if (commandInput.startsWith('/')) {
|
if (trimmedInput.startsWith('/')) {
|
||||||
const firstSpace = commandInput.indexOf(' ');
|
const firstSpace = trimmedInput.indexOf(' ');
|
||||||
const commandName = firstSpace > 0 ? commandInput.slice(0, firstSpace) : commandInput;
|
const commandName = firstSpace > 0 ? trimmedInput.slice(0, firstSpace) : trimmedInput;
|
||||||
const matchedCommand = slashCommands.find((cmd: SlashCommand) => cmd.name === commandName);
|
const matchedCommand = slashCommands.find((cmd: SlashCommand) => cmd.name === commandName);
|
||||||
if (matchedCommand && matchedCommand.type !== 'skill') {
|
if (matchedCommand) {
|
||||||
executeCommand(matchedCommand, commandInput);
|
executeCommand(matchedCommand, trimmedInput);
|
||||||
setInput('');
|
setInput('');
|
||||||
inputValueRef.current = '';
|
inputValueRef.current = '';
|
||||||
setAttachedImages([]);
|
setAttachedImages([]);
|
||||||
@@ -534,6 +533,7 @@ export function useChatComposerState({
|
|||||||
|
|
||||||
const effectiveSessionId =
|
const effectiveSessionId =
|
||||||
currentSessionId || selectedSession?.id || sessionStorage.getItem('cursorSessionId');
|
currentSessionId || selectedSession?.id || sessionStorage.getItem('cursorSessionId');
|
||||||
|
const sessionToActivate = effectiveSessionId || `new-session-${Date.now()}`;
|
||||||
|
|
||||||
const userMessage: ChatMessage = {
|
const userMessage: ChatMessage = {
|
||||||
type: 'user',
|
type: 'user',
|
||||||
@@ -559,12 +559,10 @@ export function useChatComposerState({
|
|||||||
// Reset stale pending IDs from previous interrupted runs before creating a new one.
|
// Reset stale pending IDs from previous interrupted runs before creating a new one.
|
||||||
sessionStorage.removeItem('pendingSessionId');
|
sessionStorage.removeItem('pendingSessionId');
|
||||||
}
|
}
|
||||||
// For new sessions we intentionally keep this as `null` until the backend
|
|
||||||
// emits `session_created` with the canonical provider session id.
|
|
||||||
pendingViewSessionRef.current = { sessionId: null, startedAt: Date.now() };
|
pendingViewSessionRef.current = { sessionId: null, startedAt: Date.now() };
|
||||||
}
|
}
|
||||||
if (effectiveSessionId) {
|
onSessionActive?.(sessionToActivate);
|
||||||
onSessionActive?.(effectiveSessionId);
|
if (effectiveSessionId && !isTemporarySessionId(effectiveSessionId)) {
|
||||||
onSessionProcessing?.(effectiveSessionId);
|
onSessionProcessing?.(effectiveSessionId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -715,27 +713,27 @@ export function useChatComposerState({
|
|||||||
}, [input]);
|
}, [input]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!selectedProjectId) {
|
if (!selectedProject) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const savedInput = safeLocalStorage.getItem(`draft_input_${selectedProjectId}`) || '';
|
const savedInput = safeLocalStorage.getItem(`draft_input_${selectedProject.projectId}`) || '';
|
||||||
setInput((previous) => {
|
setInput((previous) => {
|
||||||
const next = previous === savedInput ? previous : savedInput;
|
const next = previous === savedInput ? previous : savedInput;
|
||||||
inputValueRef.current = next;
|
inputValueRef.current = next;
|
||||||
return next;
|
return next;
|
||||||
});
|
});
|
||||||
}, [selectedProjectId]);
|
}, [selectedProject?.projectId]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!selectedProjectId) {
|
if (!selectedProject) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (input !== '') {
|
if (input !== '') {
|
||||||
safeLocalStorage.setItem(`draft_input_${selectedProjectId}`, input);
|
safeLocalStorage.setItem(`draft_input_${selectedProject.projectId}`, input);
|
||||||
} else {
|
} else {
|
||||||
safeLocalStorage.removeItem(`draft_input_${selectedProjectId}`);
|
safeLocalStorage.removeItem(`draft_input_${selectedProject.projectId}`);
|
||||||
}
|
}
|
||||||
}, [input, selectedProjectId]);
|
}, [input, selectedProject]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!textareaRef.current) {
|
if (!textareaRef.current) {
|
||||||
@@ -870,7 +868,7 @@ export function useChatComposerState({
|
|||||||
];
|
];
|
||||||
|
|
||||||
const targetSessionId =
|
const targetSessionId =
|
||||||
candidateSessionIds.find((sessionId) => Boolean(sessionId)) || null;
|
candidateSessionIds.find((sessionId) => Boolean(sessionId) && !isTemporarySessionId(sessionId)) || null;
|
||||||
|
|
||||||
if (!targetSessionId) {
|
if (!targetSessionId) {
|
||||||
console.warn('Abort requested but no concrete session ID is available yet.');
|
console.warn('Abort requested but no concrete session ID is available yet.');
|
||||||
|
|||||||
@@ -11,9 +11,8 @@ import { decodeHtmlEntities, unescapeWithMathProtection, formatUsageLimitText }
|
|||||||
* Convert NormalizedMessage[] from the session store into ChatMessage[]
|
* Convert NormalizedMessage[] from the session store into ChatMessage[]
|
||||||
* that the existing UI components expect.
|
* that the existing UI components expect.
|
||||||
*
|
*
|
||||||
* Truly internal/system content is already filtered server-side. Some Claude
|
* Internal/system content (e.g. <system-reminder>, <command-name>) is already
|
||||||
* transcript artifacts such as local slash commands and compact summaries are
|
* filtered server-side by the Claude provider module.
|
||||||
* intentionally preserved and annotated so they can render like normal chat.
|
|
||||||
*/
|
*/
|
||||||
export function normalizedToChatMessages(messages: NormalizedMessage[]): ChatMessage[] {
|
export function normalizedToChatMessages(messages: NormalizedMessage[]): ChatMessage[] {
|
||||||
const converted: ChatMessage[] = [];
|
const converted: ChatMessage[] = [];
|
||||||
@@ -27,16 +26,6 @@ export function normalizedToChatMessages(messages: NormalizedMessage[]): ChatMes
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (const msg of messages) {
|
for (const msg of messages) {
|
||||||
const sharedMetadata = {
|
|
||||||
displayText: msg.displayText,
|
|
||||||
commandName: msg.commandName,
|
|
||||||
commandMessage: msg.commandMessage,
|
|
||||||
commandArgs: msg.commandArgs,
|
|
||||||
isLocalCommand: msg.isLocalCommand,
|
|
||||||
isLocalCommandStdout: msg.isLocalCommandStdout,
|
|
||||||
isCompactSummary: msg.isCompactSummary,
|
|
||||||
};
|
|
||||||
|
|
||||||
switch (msg.kind) {
|
switch (msg.kind) {
|
||||||
case 'text': {
|
case 'text': {
|
||||||
const content = msg.content || '';
|
const content = msg.content || '';
|
||||||
@@ -53,14 +42,12 @@ export function normalizedToChatMessages(messages: NormalizedMessage[]): ChatMes
|
|||||||
timestamp: msg.timestamp,
|
timestamp: msg.timestamp,
|
||||||
isTaskNotification: true,
|
isTaskNotification: true,
|
||||||
taskStatus: taskNotifMatch[1]?.trim() || 'completed',
|
taskStatus: taskNotifMatch[1]?.trim() || 'completed',
|
||||||
...sharedMetadata,
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
converted.push({
|
converted.push({
|
||||||
type: 'user',
|
type: 'user',
|
||||||
content: unescapeWithMathProtection(decodeHtmlEntities(content)),
|
content: unescapeWithMathProtection(decodeHtmlEntities(content)),
|
||||||
timestamp: msg.timestamp,
|
timestamp: msg.timestamp,
|
||||||
...sharedMetadata,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -71,7 +58,6 @@ export function normalizedToChatMessages(messages: NormalizedMessage[]): ChatMes
|
|||||||
type: 'assistant',
|
type: 'assistant',
|
||||||
content: text,
|
content: text,
|
||||||
timestamp: msg.timestamp,
|
timestamp: msg.timestamp,
|
||||||
...sharedMetadata,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -120,7 +106,6 @@ export function normalizedToChatMessages(messages: NormalizedMessage[]): ChatMes
|
|||||||
isComplete: Boolean(toolResult),
|
isComplete: Boolean(toolResult),
|
||||||
}
|
}
|
||||||
: undefined,
|
: undefined,
|
||||||
...sharedMetadata,
|
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -132,7 +117,6 @@ export function normalizedToChatMessages(messages: NormalizedMessage[]): ChatMes
|
|||||||
content: unescapeWithMathProtection(msg.content),
|
content: unescapeWithMathProtection(msg.content),
|
||||||
timestamp: msg.timestamp,
|
timestamp: msg.timestamp,
|
||||||
isThinking: true,
|
isThinking: true,
|
||||||
...sharedMetadata,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -142,7 +126,6 @@ export function normalizedToChatMessages(messages: NormalizedMessage[]): ChatMes
|
|||||||
type: 'error',
|
type: 'error',
|
||||||
content: msg.content || 'Unknown error',
|
content: msg.content || 'Unknown error',
|
||||||
timestamp: msg.timestamp,
|
timestamp: msg.timestamp,
|
||||||
...sharedMetadata,
|
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -152,7 +135,6 @@ export function normalizedToChatMessages(messages: NormalizedMessage[]): ChatMes
|
|||||||
content: msg.content || '',
|
content: msg.content || '',
|
||||||
timestamp: msg.timestamp,
|
timestamp: msg.timestamp,
|
||||||
isInteractivePrompt: true,
|
isInteractivePrompt: true,
|
||||||
...sharedMetadata,
|
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -163,7 +145,6 @@ export function normalizedToChatMessages(messages: NormalizedMessage[]): ChatMes
|
|||||||
timestamp: msg.timestamp,
|
timestamp: msg.timestamp,
|
||||||
isTaskNotification: true,
|
isTaskNotification: true,
|
||||||
taskStatus: msg.status || 'completed',
|
taskStatus: msg.status || 'completed',
|
||||||
...sharedMetadata,
|
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -174,7 +155,6 @@ export function normalizedToChatMessages(messages: NormalizedMessage[]): ChatMes
|
|||||||
content: msg.content,
|
content: msg.content,
|
||||||
timestamp: msg.timestamp,
|
timestamp: msg.timestamp,
|
||||||
isStreaming: true,
|
isStreaming: true,
|
||||||
...sharedMetadata,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import type { Dispatch, MutableRefObject, SetStateAction } from 'react';
|
|||||||
|
|
||||||
import { usePaletteOps } from '../../../contexts/PaletteOpsContext';
|
import { usePaletteOps } from '../../../contexts/PaletteOpsContext';
|
||||||
import type { PendingPermissionRequest, SessionNavigationOptions } from '../types/types';
|
import type { PendingPermissionRequest, SessionNavigationOptions } from '../types/types';
|
||||||
import type { ProjectSession, LLMProvider } from '../../../types/app';
|
import type { Project, ProjectSession, LLMProvider } from '../../../types/app';
|
||||||
import type { SessionStore, NormalizedMessage } from '../../../stores/useSessionStore';
|
import type { SessionStore, NormalizedMessage } from '../../../stores/useSessionStore';
|
||||||
|
|
||||||
type PendingViewSession = {
|
type PendingViewSession = {
|
||||||
@@ -51,6 +51,7 @@ type LatestChatMessage = {
|
|||||||
interface UseChatRealtimeHandlersArgs {
|
interface UseChatRealtimeHandlersArgs {
|
||||||
latestMessage: LatestChatMessage | null;
|
latestMessage: LatestChatMessage | null;
|
||||||
provider: LLMProvider;
|
provider: LLMProvider;
|
||||||
|
selectedProject: Project | null;
|
||||||
selectedSession: ProjectSession | null;
|
selectedSession: ProjectSession | null;
|
||||||
currentSessionId: string | null;
|
currentSessionId: string | null;
|
||||||
setCurrentSessionId: (sessionId: string | null) => void;
|
setCurrentSessionId: (sessionId: string | null) => void;
|
||||||
@@ -60,11 +61,13 @@ interface UseChatRealtimeHandlersArgs {
|
|||||||
setTokenBudget: (budget: Record<string, unknown> | null) => void;
|
setTokenBudget: (budget: Record<string, unknown> | null) => void;
|
||||||
setPendingPermissionRequests: Dispatch<SetStateAction<PendingPermissionRequest[]>>;
|
setPendingPermissionRequests: Dispatch<SetStateAction<PendingPermissionRequest[]>>;
|
||||||
pendingViewSessionRef: MutableRefObject<PendingViewSession | null>;
|
pendingViewSessionRef: MutableRefObject<PendingViewSession | null>;
|
||||||
|
streamBufferRef: MutableRefObject<string>;
|
||||||
streamTimerRef: MutableRefObject<number | null>;
|
streamTimerRef: MutableRefObject<number | null>;
|
||||||
accumulatedStreamRef: MutableRefObject<string>;
|
accumulatedStreamRef: MutableRefObject<string>;
|
||||||
onSessionInactive?: (sessionId?: string | null) => void;
|
onSessionInactive?: (sessionId?: string | null) => void;
|
||||||
onSessionProcessing?: (sessionId?: string | null) => void;
|
onSessionProcessing?: (sessionId?: string | null) => void;
|
||||||
onSessionNotProcessing?: (sessionId?: string | null) => void;
|
onSessionNotProcessing?: (sessionId?: string | null) => void;
|
||||||
|
onReplaceTemporarySession?: (sessionId?: string | null) => void;
|
||||||
onNavigateToSession?: (sessionId: string, options?: SessionNavigationOptions) => void;
|
onNavigateToSession?: (sessionId: string, options?: SessionNavigationOptions) => void;
|
||||||
onWebSocketReconnect?: () => void;
|
onWebSocketReconnect?: () => void;
|
||||||
sessionStore: SessionStore;
|
sessionStore: SessionStore;
|
||||||
@@ -77,6 +80,7 @@ interface UseChatRealtimeHandlersArgs {
|
|||||||
export function useChatRealtimeHandlers({
|
export function useChatRealtimeHandlers({
|
||||||
latestMessage,
|
latestMessage,
|
||||||
provider,
|
provider,
|
||||||
|
selectedProject,
|
||||||
selectedSession,
|
selectedSession,
|
||||||
currentSessionId,
|
currentSessionId,
|
||||||
setCurrentSessionId,
|
setCurrentSessionId,
|
||||||
@@ -86,11 +90,13 @@ export function useChatRealtimeHandlers({
|
|||||||
setTokenBudget,
|
setTokenBudget,
|
||||||
setPendingPermissionRequests,
|
setPendingPermissionRequests,
|
||||||
pendingViewSessionRef,
|
pendingViewSessionRef,
|
||||||
|
streamBufferRef,
|
||||||
streamTimerRef,
|
streamTimerRef,
|
||||||
accumulatedStreamRef,
|
accumulatedStreamRef,
|
||||||
onSessionInactive,
|
onSessionInactive,
|
||||||
onSessionProcessing,
|
onSessionProcessing,
|
||||||
onSessionNotProcessing,
|
onSessionNotProcessing,
|
||||||
|
onReplaceTemporarySession,
|
||||||
onNavigateToSession,
|
onNavigateToSession,
|
||||||
onWebSocketReconnect,
|
onWebSocketReconnect,
|
||||||
sessionStore,
|
sessionStore,
|
||||||
@@ -181,6 +187,7 @@ export function useChatRealtimeHandlers({
|
|||||||
if (msg.kind === 'stream_delta') {
|
if (msg.kind === 'stream_delta') {
|
||||||
const text = msg.content || '';
|
const text = msg.content || '';
|
||||||
if (!text) return;
|
if (!text) return;
|
||||||
|
streamBufferRef.current += text;
|
||||||
accumulatedStreamRef.current += text;
|
accumulatedStreamRef.current += text;
|
||||||
if (!streamTimerRef.current) {
|
if (!streamTimerRef.current) {
|
||||||
streamTimerRef.current = window.setTimeout(() => {
|
streamTimerRef.current = window.setTimeout(() => {
|
||||||
@@ -209,18 +216,12 @@ export function useChatRealtimeHandlers({
|
|||||||
sessionStore.finalizeStreaming(sid);
|
sessionStore.finalizeStreaming(sid);
|
||||||
}
|
}
|
||||||
accumulatedStreamRef.current = '';
|
accumulatedStreamRef.current = '';
|
||||||
|
streamBufferRef.current = '';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- All other messages: route to store ---
|
// --- All other messages: route to store ---
|
||||||
const shouldPersist =
|
if (sid) {
|
||||||
msg.kind !== 'session_created'
|
|
||||||
&& msg.kind !== 'complete'
|
|
||||||
&& msg.kind !== 'status'
|
|
||||||
&& msg.kind !== 'permission_request'
|
|
||||||
&& msg.kind !== 'permission_cancelled';
|
|
||||||
|
|
||||||
if (sid && shouldPersist) {
|
|
||||||
sessionStore.appendRealtime(sid, msg as NormalizedMessage);
|
sessionStore.appendRealtime(sid, msg as NormalizedMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -230,16 +231,13 @@ export function useChatRealtimeHandlers({
|
|||||||
const newSessionId = msg.newSessionId;
|
const newSessionId = msg.newSessionId;
|
||||||
if (!newSessionId) break;
|
if (!newSessionId) break;
|
||||||
|
|
||||||
// We no longer synthesize client-side placeholder IDs. Until the provider
|
if (!currentSessionId || currentSessionId.startsWith('new-session-')) {
|
||||||
// announces `session_created`, the active id is expected to be null.
|
|
||||||
if (!currentSessionId) {
|
|
||||||
console.log('Session created with ID:', newSessionId);
|
|
||||||
console.log('Existing session ID:', currentSessionId);
|
|
||||||
sessionStorage.setItem('pendingSessionId', newSessionId);
|
sessionStorage.setItem('pendingSessionId', newSessionId);
|
||||||
if (pendingViewSessionRef.current && !pendingViewSessionRef.current.sessionId) {
|
if (pendingViewSessionRef.current && !pendingViewSessionRef.current.sessionId) {
|
||||||
pendingViewSessionRef.current.sessionId = newSessionId;
|
pendingViewSessionRef.current.sessionId = newSessionId;
|
||||||
}
|
}
|
||||||
setCurrentSessionId(newSessionId);
|
setCurrentSessionId(newSessionId);
|
||||||
|
onReplaceTemporarySession?.(newSessionId);
|
||||||
setPendingPermissionRequests((prev) =>
|
setPendingPermissionRequests((prev) =>
|
||||||
prev.map((r) => (r.sessionId ? r : { ...r, sessionId: newSessionId })),
|
prev.map((r) => (r.sessionId ? r : { ...r, sessionId: newSessionId })),
|
||||||
);
|
);
|
||||||
@@ -259,6 +257,7 @@ export function useChatRealtimeHandlers({
|
|||||||
sessionStore.finalizeStreaming(sid);
|
sessionStore.finalizeStreaming(sid);
|
||||||
}
|
}
|
||||||
accumulatedStreamRef.current = '';
|
accumulatedStreamRef.current = '';
|
||||||
|
streamBufferRef.current = '';
|
||||||
|
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
setCanAbortSession(false);
|
setCanAbortSession(false);
|
||||||
@@ -387,6 +386,7 @@ export function useChatRealtimeHandlers({
|
|||||||
}, [
|
}, [
|
||||||
latestMessage,
|
latestMessage,
|
||||||
provider,
|
provider,
|
||||||
|
selectedProject,
|
||||||
selectedSession,
|
selectedSession,
|
||||||
currentSessionId,
|
currentSessionId,
|
||||||
setCurrentSessionId,
|
setCurrentSessionId,
|
||||||
@@ -396,11 +396,13 @@ export function useChatRealtimeHandlers({
|
|||||||
setTokenBudget,
|
setTokenBudget,
|
||||||
setPendingPermissionRequests,
|
setPendingPermissionRequests,
|
||||||
pendingViewSessionRef,
|
pendingViewSessionRef,
|
||||||
|
streamBufferRef,
|
||||||
streamTimerRef,
|
streamTimerRef,
|
||||||
accumulatedStreamRef,
|
accumulatedStreamRef,
|
||||||
onSessionInactive,
|
onSessionInactive,
|
||||||
onSessionProcessing,
|
onSessionProcessing,
|
||||||
onSessionNotProcessing,
|
onSessionNotProcessing,
|
||||||
|
onReplaceTemporarySession,
|
||||||
onNavigateToSession,
|
onNavigateToSession,
|
||||||
onWebSocketReconnect,
|
onWebSocketReconnect,
|
||||||
sessionStore,
|
sessionStore,
|
||||||
|
|||||||
@@ -182,7 +182,6 @@ export function useChatSessionState({
|
|||||||
messagesOffsetRef.current = 0;
|
messagesOffsetRef.current = 0;
|
||||||
setHasMoreMessages(false);
|
setHasMoreMessages(false);
|
||||||
setTotalMessages(0);
|
setTotalMessages(0);
|
||||||
|
|
||||||
setTokenBudget(null);
|
setTokenBudget(null);
|
||||||
setVisibleMessageCount(INITIAL_VISIBLE_MESSAGES);
|
setVisibleMessageCount(INITIAL_VISIBLE_MESSAGES);
|
||||||
setAllMessagesLoaded(false);
|
setAllMessagesLoaded(false);
|
||||||
@@ -319,6 +318,7 @@ export function useChatSessionState({
|
|||||||
if (!hasMoreMessages || !selectedSession || !selectedProject) return false;
|
if (!hasMoreMessages || !selectedSession || !selectedProject) return false;
|
||||||
|
|
||||||
const sessionProvider = selectedSession.__provider || 'claude';
|
const sessionProvider = selectedSession.__provider || 'claude';
|
||||||
|
if (sessionProvider === 'cursor') return false;
|
||||||
|
|
||||||
isLoadingMoreRef.current = true;
|
isLoadingMoreRef.current = true;
|
||||||
const previousScrollHeight = container.scrollHeight;
|
const previousScrollHeight = container.scrollHeight;
|
||||||
@@ -551,6 +551,7 @@ export function useChatSessionState({
|
|||||||
const scrollToTarget = async () => {
|
const scrollToTarget = async () => {
|
||||||
if (!allMessagesLoadedRef.current && selectedSession && selectedProject) {
|
if (!allMessagesLoadedRef.current && selectedSession && selectedProject) {
|
||||||
const sessionProvider = selectedSession.__provider || 'claude';
|
const sessionProvider = selectedSession.__provider || 'claude';
|
||||||
|
if (sessionProvider !== 'cursor') {
|
||||||
try {
|
try {
|
||||||
// Load all messages into the store for search navigation
|
// Load all messages into the store for search navigation
|
||||||
const slot = await sessionStore.fetchFromServer(selectedSession.id, {
|
const slot = await sessionStore.fetchFromServer(selectedSession.id, {
|
||||||
@@ -572,6 +573,7 @@ export function useChatSessionState({
|
|||||||
} catch {
|
} catch {
|
||||||
// Fall through and scroll in current messages
|
// Fall through and scroll in current messages
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
setVisibleMessageCount(Infinity);
|
setVisibleMessageCount(Infinity);
|
||||||
|
|
||||||
@@ -626,7 +628,7 @@ export function useChatSessionState({
|
|||||||
|
|
||||||
// Token usage fetch for Claude
|
// Token usage fetch for Claude
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!selectedProject || !selectedSession?.id) {
|
if (!selectedProject || !selectedSession?.id || selectedSession.id.startsWith('new-session-')) {
|
||||||
setTokenBudget(null);
|
setTokenBudget(null);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -719,6 +721,15 @@ export function useChatSessionState({
|
|||||||
if (!selectedSession || !selectedProject) return;
|
if (!selectedSession || !selectedProject) return;
|
||||||
if (isLoadingAllMessages) return;
|
if (isLoadingAllMessages) return;
|
||||||
const sessionProvider = selectedSession.__provider || 'claude';
|
const sessionProvider = selectedSession.__provider || 'claude';
|
||||||
|
if (sessionProvider === 'cursor') {
|
||||||
|
setVisibleMessageCount(Infinity);
|
||||||
|
setAllMessagesLoaded(true);
|
||||||
|
allMessagesLoadedRef.current = true;
|
||||||
|
setLoadAllJustFinished(true);
|
||||||
|
if (loadAllFinishedTimerRef.current) clearTimeout(loadAllFinishedTimerRef.current);
|
||||||
|
loadAllFinishedTimerRef.current = setTimeout(() => { setLoadAllJustFinished(false); setShowLoadAllOverlay(false); }, 1000);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const requestSessionId = selectedSession.id;
|
const requestSessionId = selectedSession.id;
|
||||||
allMessagesLoadedRef.current = true;
|
allMessagesLoadedRef.current = true;
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
||||||
import type { Dispatch, KeyboardEvent, RefObject, SetStateAction } from 'react';
|
import type { Dispatch, KeyboardEvent, RefObject, SetStateAction } from 'react';
|
||||||
|
import Fuse from 'fuse.js';
|
||||||
import { authenticatedFetch } from '../../../utils/api';
|
import { authenticatedFetch } from '../../../utils/api';
|
||||||
import { safeLocalStorage } from '../utils/chatStorage';
|
import { safeLocalStorage } from '../utils/chatStorage';
|
||||||
import type { LLMProvider, Project } from '../../../types/app';
|
import type { Project } from '../../../types/app';
|
||||||
|
|
||||||
const COMMAND_QUERY_DEBOUNCE_MS = 150;
|
const COMMAND_QUERY_DEBOUNCE_MS = 150;
|
||||||
|
|
||||||
@@ -12,37 +12,19 @@ export interface SlashCommand {
|
|||||||
description?: string;
|
description?: string;
|
||||||
namespace?: string;
|
namespace?: string;
|
||||||
path?: string;
|
path?: string;
|
||||||
type?: 'built-in' | 'custom' | 'skill' | string;
|
type?: string;
|
||||||
metadata?: Record<string, unknown>;
|
metadata?: Record<string, unknown>;
|
||||||
[key: string]: unknown;
|
[key: string]: unknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface UseSlashCommandsOptions {
|
interface UseSlashCommandsOptions {
|
||||||
selectedProject: Project | null;
|
selectedProject: Project | null;
|
||||||
provider: LLMProvider;
|
|
||||||
input: string;
|
input: string;
|
||||||
setInput: Dispatch<SetStateAction<string>>;
|
setInput: Dispatch<SetStateAction<string>>;
|
||||||
textareaRef: RefObject<HTMLTextAreaElement>;
|
textareaRef: RefObject<HTMLTextAreaElement>;
|
||||||
onExecuteCommand: (command: SlashCommand, rawInput?: string) => void | Promise<void>;
|
onExecuteCommand: (command: SlashCommand, rawInput?: string) => void | Promise<void>;
|
||||||
}
|
}
|
||||||
|
|
||||||
type ProviderSkill = {
|
|
||||||
name: string;
|
|
||||||
description?: string;
|
|
||||||
command: string;
|
|
||||||
scope: string;
|
|
||||||
sourcePath?: string;
|
|
||||||
pluginName?: string;
|
|
||||||
pluginId?: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
type ProviderSkillsResponse = {
|
|
||||||
success?: boolean;
|
|
||||||
data?: {
|
|
||||||
skills?: ProviderSkill[];
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
const getCommandHistoryKey = (projectName: string) => `command_history_${projectName}`;
|
const getCommandHistoryKey = (projectName: string) => `command_history_${projectName}`;
|
||||||
|
|
||||||
const readCommandHistory = (projectName: string): Record<string, number> => {
|
const readCommandHistory = (projectName: string): Record<string, number> => {
|
||||||
@@ -66,78 +48,8 @@ const saveCommandHistory = (projectName: string, history: Record<string, number>
|
|||||||
const isPromiseLike = (value: unknown): value is Promise<unknown> =>
|
const isPromiseLike = (value: unknown): value is Promise<unknown> =>
|
||||||
Boolean(value) && typeof (value as Promise<unknown>).then === 'function';
|
Boolean(value) && typeof (value as Promise<unknown>).then === 'function';
|
||||||
|
|
||||||
const isSkillCommand = (command: SlashCommand) =>
|
|
||||||
command.type === 'skill' || command.metadata?.type === 'skill';
|
|
||||||
|
|
||||||
const dedupeProviderSkills = (skills: ProviderSkill[]): ProviderSkill[] => {
|
|
||||||
const seenCommands = new Set<string>();
|
|
||||||
|
|
||||||
return skills.filter((skill) => {
|
|
||||||
// Multiple physical Claude plugin folders can expose the same invocation.
|
|
||||||
// The slash menu should show each executable command only once.
|
|
||||||
const key = skill.command;
|
|
||||||
if (seenCommands.has(key)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
seenCommands.add(key);
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const mapSkillToSlashCommand = (skill: ProviderSkill): SlashCommand => ({
|
|
||||||
name: skill.command,
|
|
||||||
description: skill.description,
|
|
||||||
namespace: 'skill',
|
|
||||||
path: skill.sourcePath,
|
|
||||||
type: 'skill',
|
|
||||||
metadata: {
|
|
||||||
type: skill.scope,
|
|
||||||
scope: skill.scope,
|
|
||||||
sourcePath: skill.sourcePath,
|
|
||||||
pluginName: skill.pluginName,
|
|
||||||
pluginId: skill.pluginId,
|
|
||||||
skillName: skill.name,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const filterSlashCommands = (
|
|
||||||
commands: SlashCommand[],
|
|
||||||
query: string,
|
|
||||||
): SlashCommand[] => {
|
|
||||||
const normalizedQuery = query.trim().toLowerCase();
|
|
||||||
if (!normalizedQuery) {
|
|
||||||
return commands;
|
|
||||||
}
|
|
||||||
|
|
||||||
const commandPrefix = normalizedQuery.startsWith('/')
|
|
||||||
? normalizedQuery
|
|
||||||
: `/${normalizedQuery}`;
|
|
||||||
const namePrefixMatches = commands.filter((command) =>
|
|
||||||
command.name.toLowerCase().startsWith(commandPrefix),
|
|
||||||
);
|
|
||||||
|
|
||||||
// Namespaced commands should behave like path completion. Once a provider
|
|
||||||
// namespace is typed, only exact command-prefix matches should stay visible.
|
|
||||||
if (normalizedQuery.includes(':') || namePrefixMatches.length > 0) {
|
|
||||||
return namePrefixMatches;
|
|
||||||
}
|
|
||||||
|
|
||||||
const nameSubstringMatches = commands.filter((command) =>
|
|
||||||
command.name.toLowerCase().includes(normalizedQuery),
|
|
||||||
);
|
|
||||||
if (nameSubstringMatches.length > 0) {
|
|
||||||
return nameSubstringMatches;
|
|
||||||
}
|
|
||||||
|
|
||||||
return commands.filter((command) =>
|
|
||||||
command.description?.toLowerCase().includes(normalizedQuery),
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export function useSlashCommands({
|
export function useSlashCommands({
|
||||||
selectedProject,
|
selectedProject,
|
||||||
provider,
|
|
||||||
input,
|
input,
|
||||||
setInput,
|
setInput,
|
||||||
textareaRef,
|
textareaRef,
|
||||||
@@ -168,8 +80,6 @@ export function useSlashCommands({
|
|||||||
}, [clearCommandQueryTimer]);
|
}, [clearCommandQueryTimer]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let cancelled = false;
|
|
||||||
|
|
||||||
const fetchCommands = async () => {
|
const fetchCommands = async () => {
|
||||||
if (!selectedProject) {
|
if (!selectedProject) {
|
||||||
setSlashCommands([]);
|
setSlashCommands([]);
|
||||||
@@ -178,14 +88,13 @@ export function useSlashCommands({
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const workspacePath = selectedProject.fullPath || selectedProject.path || '';
|
|
||||||
const response = await authenticatedFetch('/api/commands/list', {
|
const response = await authenticatedFetch('/api/commands/list', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
projectPath: workspacePath || selectedProject.path,
|
projectPath: selectedProject.path,
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -194,25 +103,11 @@ export function useSlashCommands({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
const skillsParams = new URLSearchParams();
|
|
||||||
if (workspacePath) {
|
|
||||||
skillsParams.set('workspacePath', workspacePath);
|
|
||||||
}
|
|
||||||
|
|
||||||
const skillsResponse = await authenticatedFetch(
|
|
||||||
`/api/providers/${encodeURIComponent(provider)}/skills${skillsParams.toString() ? `?${skillsParams.toString()}` : ''}`,
|
|
||||||
);
|
|
||||||
const skillsData = skillsResponse.ok
|
|
||||||
? ((await skillsResponse.json()) as ProviderSkillsResponse)
|
|
||||||
: null;
|
|
||||||
const skillCommands = dedupeProviderSkills(skillsData?.data?.skills || [])
|
|
||||||
.map(mapSkillToSlashCommand);
|
|
||||||
const allCommands: SlashCommand[] = [
|
const allCommands: SlashCommand[] = [
|
||||||
...((data.builtIn || []) as SlashCommand[]).map((command) => ({
|
...((data.builtIn || []) as SlashCommand[]).map((command) => ({
|
||||||
...command,
|
...command,
|
||||||
type: 'built-in',
|
type: 'built-in',
|
||||||
})),
|
})),
|
||||||
...skillCommands,
|
|
||||||
...((data.custom || []) as SlashCommand[]).map((command) => ({
|
...((data.custom || []) as SlashCommand[]).map((command) => ({
|
||||||
...command,
|
...command,
|
||||||
type: 'custom',
|
type: 'custom',
|
||||||
@@ -226,22 +121,15 @@ export function useSlashCommands({
|
|||||||
return commandBUsage - commandAUsage;
|
return commandBUsage - commandAUsage;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!cancelled) {
|
setSlashCommands(sortedCommands);
|
||||||
setSlashCommands(sortedCommands);
|
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error fetching slash commands:', error);
|
console.error('Error fetching slash commands:', error);
|
||||||
if (!cancelled) {
|
setSlashCommands([]);
|
||||||
setSlashCommands([]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
fetchCommands();
|
fetchCommands();
|
||||||
return () => {
|
}, [selectedProject]);
|
||||||
cancelled = true;
|
|
||||||
};
|
|
||||||
}, [selectedProject, provider]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!showCommandMenu) {
|
if (!showCommandMenu) {
|
||||||
@@ -249,9 +137,36 @@ export function useSlashCommands({
|
|||||||
}
|
}
|
||||||
}, [showCommandMenu]);
|
}, [showCommandMenu]);
|
||||||
|
|
||||||
|
const fuse = useMemo(() => {
|
||||||
|
if (!slashCommands.length) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Fuse(slashCommands, {
|
||||||
|
keys: [
|
||||||
|
{ name: 'name', weight: 2 },
|
||||||
|
{ name: 'description', weight: 1 },
|
||||||
|
],
|
||||||
|
threshold: 0.4,
|
||||||
|
includeScore: true,
|
||||||
|
minMatchCharLength: 1,
|
||||||
|
});
|
||||||
|
}, [slashCommands]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setFilteredCommands(filterSlashCommands(slashCommands, commandQuery));
|
if (!commandQuery) {
|
||||||
}, [commandQuery, slashCommands]);
|
setFilteredCommands(slashCommands);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!fuse) {
|
||||||
|
setFilteredCommands([]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const results = fuse.search(commandQuery);
|
||||||
|
setFilteredCommands(results.map((result) => result.item));
|
||||||
|
}, [commandQuery, slashCommands, fuse]);
|
||||||
|
|
||||||
const frequentCommands = useMemo(() => {
|
const frequentCommands = useMemo(() => {
|
||||||
if (!selectedProject || slashCommands.length === 0) {
|
if (!selectedProject || slashCommands.length === 0) {
|
||||||
@@ -283,63 +198,25 @@ export function useSlashCommands({
|
|||||||
[selectedProject],
|
[selectedProject],
|
||||||
);
|
);
|
||||||
|
|
||||||
const insertCommandIntoInput = useCallback(
|
const selectCommandFromKeyboard = useCallback(
|
||||||
(command: SlashCommand) => {
|
(command: SlashCommand) => {
|
||||||
const currentTextarea = textareaRef.current;
|
const textBeforeSlash = input.slice(0, slashPosition);
|
||||||
const insertionStart = slashPosition >= 0
|
const textAfterSlash = input.slice(slashPosition);
|
||||||
? slashPosition
|
const spaceIndex = textAfterSlash.indexOf(' ');
|
||||||
: currentTextarea?.selectionStart ?? input.length;
|
const textAfterQuery = spaceIndex !== -1 ? textAfterSlash.slice(spaceIndex) : '';
|
||||||
const textBeforeCommand = input.slice(0, insertionStart);
|
const newInput = `${textBeforeSlash}${command.name} ${textAfterQuery}`;
|
||||||
const textAfterCommandStart = input.slice(insertionStart);
|
|
||||||
const spaceIndex = textAfterCommandStart.indexOf(' ');
|
|
||||||
const textAfterCommand = slashPosition >= 0 && spaceIndex !== -1
|
|
||||||
? textAfterCommandStart.slice(spaceIndex).trimStart()
|
|
||||||
: input.slice(currentTextarea?.selectionEnd ?? insertionStart);
|
|
||||||
const separator = textBeforeCommand && !/\s$/.test(textBeforeCommand) ? ' ' : '';
|
|
||||||
const newInput = `${textBeforeCommand}${separator}${command.name}${textAfterCommand ? ` ${textAfterCommand}` : ' '}`;
|
|
||||||
|
|
||||||
setInput(newInput);
|
setInput(newInput);
|
||||||
resetCommandMenuState();
|
resetCommandMenuState();
|
||||||
|
|
||||||
window.requestAnimationFrame(() => {
|
|
||||||
currentTextarea?.focus();
|
|
||||||
const nextCursorPosition = `${textBeforeCommand}${separator}${command.name} `.length;
|
|
||||||
currentTextarea?.setSelectionRange(nextCursorPosition, nextCursorPosition);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
[input, resetCommandMenuState, setInput, slashPosition, textareaRef],
|
|
||||||
);
|
|
||||||
|
|
||||||
const executeNonSkillCommand = useCallback(
|
|
||||||
(command: SlashCommand) => {
|
|
||||||
const executionResult = onExecuteCommand(command);
|
const executionResult = onExecuteCommand(command);
|
||||||
if (isPromiseLike(executionResult)) {
|
if (isPromiseLike(executionResult)) {
|
||||||
executionResult.then(
|
executionResult.catch(() => {
|
||||||
() => {
|
// Keep behavior silent; execution errors are handled by caller.
|
||||||
resetCommandMenuState();
|
});
|
||||||
},
|
|
||||||
() => {
|
|
||||||
resetCommandMenuState();
|
|
||||||
// Keep behavior silent; execution errors are handled by caller.
|
|
||||||
},
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
resetCommandMenuState();
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[onExecuteCommand, resetCommandMenuState],
|
[input, slashPosition, setInput, resetCommandMenuState, onExecuteCommand],
|
||||||
);
|
|
||||||
|
|
||||||
const selectCommandFromKeyboard = useCallback(
|
|
||||||
(command: SlashCommand) => {
|
|
||||||
if (isSkillCommand(command)) {
|
|
||||||
insertCommandIntoInput(command);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
executeNonSkillCommand(command);
|
|
||||||
},
|
|
||||||
[executeNonSkillCommand, insertCommandIntoInput],
|
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleCommandSelect = useCallback(
|
const handleCommandSelect = useCallback(
|
||||||
@@ -354,14 +231,20 @@ export function useSlashCommands({
|
|||||||
}
|
}
|
||||||
|
|
||||||
trackCommandUsage(command);
|
trackCommandUsage(command);
|
||||||
if (isSkillCommand(command)) {
|
const executionResult = onExecuteCommand(command);
|
||||||
insertCommandIntoInput(command);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
executeNonSkillCommand(command);
|
if (isPromiseLike(executionResult)) {
|
||||||
|
executionResult.then(() => {
|
||||||
|
resetCommandMenuState();
|
||||||
|
});
|
||||||
|
executionResult.catch(() => {
|
||||||
|
// Keep behavior silent; execution errors are handled by caller.
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
resetCommandMenuState();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
[selectedProject, trackCommandUsage, insertCommandIntoInput, executeNonSkillCommand],
|
[selectedProject, trackCommandUsage, onExecuteCommand, resetCommandMenuState],
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleToggleCommandMenu = useCallback(() => {
|
const handleToggleCommandMenu = useCallback(() => {
|
||||||
@@ -393,7 +276,7 @@ export function useSlashCommands({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const slashPattern = /^\/(\S*)$/;
|
const slashPattern = /(^|\s)\/(\S*)$/;
|
||||||
const match = textBeforeCursor.match(slashPattern);
|
const match = textBeforeCursor.match(slashPattern);
|
||||||
|
|
||||||
if (!match) {
|
if (!match) {
|
||||||
@@ -401,8 +284,8 @@ export function useSlashCommands({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const slashPos = 0;
|
const slashPos = (match.index || 0) + match[1].length;
|
||||||
const query = match[1];
|
const query = match[2];
|
||||||
|
|
||||||
setSlashPosition(slashPos);
|
setSlashPosition(slashPos);
|
||||||
setShowCommandMenu(true);
|
setShowCommandMenu(true);
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ export interface SubagentChildTool {
|
|||||||
export interface ChatMessage {
|
export interface ChatMessage {
|
||||||
type: string;
|
type: string;
|
||||||
content?: string;
|
content?: string;
|
||||||
displayText?: string;
|
|
||||||
timestamp: string | number | Date;
|
timestamp: string | number | Date;
|
||||||
images?: ChatImage[];
|
images?: ChatImage[];
|
||||||
reasoning?: string;
|
reasoning?: string;
|
||||||
@@ -41,12 +40,6 @@ export interface ChatMessage {
|
|||||||
toolResult?: ToolResult | null;
|
toolResult?: ToolResult | null;
|
||||||
toolId?: string;
|
toolId?: string;
|
||||||
toolCallId?: string;
|
toolCallId?: string;
|
||||||
commandName?: string;
|
|
||||||
commandMessage?: string;
|
|
||||||
commandArgs?: string;
|
|
||||||
isLocalCommand?: boolean;
|
|
||||||
isLocalCommandStdout?: boolean;
|
|
||||||
isCompactSummary?: boolean;
|
|
||||||
isSubagentContainer?: boolean;
|
isSubagentContainer?: boolean;
|
||||||
subagentState?: {
|
subagentState?: {
|
||||||
childTools: SubagentChildTool[];
|
childTools: SubagentChildTool[];
|
||||||
@@ -115,6 +108,7 @@ export interface ChatInterfaceProps {
|
|||||||
onSessionProcessing?: (sessionId?: string | null) => void;
|
onSessionProcessing?: (sessionId?: string | null) => void;
|
||||||
onSessionNotProcessing?: (sessionId?: string | null) => void;
|
onSessionNotProcessing?: (sessionId?: string | null) => void;
|
||||||
processingSessions?: Set<string>;
|
processingSessions?: Set<string>;
|
||||||
|
onReplaceTemporarySession?: (sessionId?: string | null) => void;
|
||||||
onNavigateToSession?: (targetSessionId: string, options?: SessionNavigationOptions) => void;
|
onNavigateToSession?: (targetSessionId: string, options?: SessionNavigationOptions) => void;
|
||||||
onShowSettings?: () => void;
|
onShowSettings?: () => void;
|
||||||
autoExpandTools?: boolean;
|
autoExpandTools?: boolean;
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ function ChatInterface({
|
|||||||
onSessionProcessing,
|
onSessionProcessing,
|
||||||
onSessionNotProcessing,
|
onSessionNotProcessing,
|
||||||
processingSessions,
|
processingSessions,
|
||||||
|
onReplaceTemporarySession,
|
||||||
onNavigateToSession,
|
onNavigateToSession,
|
||||||
onShowSettings,
|
onShowSettings,
|
||||||
autoExpandTools,
|
autoExpandTools,
|
||||||
@@ -49,6 +50,7 @@ function ChatInterface({
|
|||||||
const { t } = useTranslation('chat');
|
const { t } = useTranslation('chat');
|
||||||
|
|
||||||
const sessionStore = useSessionStore();
|
const sessionStore = useSessionStore();
|
||||||
|
const streamBufferRef = useRef('');
|
||||||
const streamTimerRef = useRef<number | null>(null);
|
const streamTimerRef = useRef<number | null>(null);
|
||||||
const accumulatedStreamRef = useRef('');
|
const accumulatedStreamRef = useRef('');
|
||||||
const pendingViewSessionRef = useRef<PendingViewSession | null>(null);
|
const pendingViewSessionRef = useRef<PendingViewSession | null>(null);
|
||||||
@@ -58,6 +60,7 @@ function ChatInterface({
|
|||||||
clearTimeout(streamTimerRef.current);
|
clearTimeout(streamTimerRef.current);
|
||||||
streamTimerRef.current = null;
|
streamTimerRef.current = null;
|
||||||
}
|
}
|
||||||
|
streamBufferRef.current = '';
|
||||||
accumulatedStreamRef.current = '';
|
accumulatedStreamRef.current = '';
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
@@ -222,6 +225,7 @@ function ChatInterface({
|
|||||||
useChatRealtimeHandlers({
|
useChatRealtimeHandlers({
|
||||||
latestMessage,
|
latestMessage,
|
||||||
provider,
|
provider,
|
||||||
|
selectedProject,
|
||||||
selectedSession,
|
selectedSession,
|
||||||
currentSessionId,
|
currentSessionId,
|
||||||
setCurrentSessionId,
|
setCurrentSessionId,
|
||||||
@@ -231,11 +235,13 @@ function ChatInterface({
|
|||||||
setTokenBudget,
|
setTokenBudget,
|
||||||
setPendingPermissionRequests,
|
setPendingPermissionRequests,
|
||||||
pendingViewSessionRef,
|
pendingViewSessionRef,
|
||||||
|
streamBufferRef,
|
||||||
streamTimerRef,
|
streamTimerRef,
|
||||||
accumulatedStreamRef,
|
accumulatedStreamRef,
|
||||||
onSessionInactive,
|
onSessionInactive,
|
||||||
onSessionProcessing,
|
onSessionProcessing,
|
||||||
onSessionNotProcessing,
|
onSessionNotProcessing,
|
||||||
|
onReplaceTemporarySession,
|
||||||
onNavigateToSession,
|
onNavigateToSession,
|
||||||
onWebSocketReconnect: handleWebSocketReconnect,
|
onWebSocketReconnect: handleWebSocketReconnect,
|
||||||
sessionStore,
|
sessionStore,
|
||||||
|
|||||||
@@ -213,6 +213,13 @@ export default function ChatMessagesPane({
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{/* Performance warning when all messages are loaded */}
|
||||||
|
{allMessagesLoaded && (
|
||||||
|
<div className="border-b border-amber-200 bg-amber-50 py-1.5 text-center text-xs text-amber-600 dark:border-amber-800 dark:bg-amber-900/20 dark:text-amber-400">
|
||||||
|
{t('session.messages.perfWarning')}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
{/* Legacy message count indicator (for non-paginated view) */}
|
{/* Legacy message count indicator (for non-paginated view) */}
|
||||||
{!hasMoreMessages && chatMessages.length > visibleMessageCount && (
|
{!hasMoreMessages && chatMessages.length > visibleMessageCount && (
|
||||||
<div className="border-b border-gray-200 py-2 text-center text-sm text-gray-500 dark:border-gray-700 dark:text-gray-400">
|
<div className="border-b border-gray-200 py-2 text-center text-sm text-gray-500 dark:border-gray-700 dark:text-gray-400">
|
||||||
|
|||||||
@@ -1,15 +1,5 @@
|
|||||||
import { useEffect, useRef } from 'react';
|
import { useEffect, useRef } from 'react';
|
||||||
import type { CSSProperties } from 'react';
|
import type { CSSProperties } from 'react';
|
||||||
import {
|
|
||||||
CornerDownLeft,
|
|
||||||
Folder,
|
|
||||||
MessageSquare,
|
|
||||||
Sparkles,
|
|
||||||
Star,
|
|
||||||
Terminal,
|
|
||||||
User,
|
|
||||||
type LucideIcon,
|
|
||||||
} from 'lucide-react';
|
|
||||||
|
|
||||||
type CommandMenuCommand = {
|
type CommandMenuCommand = {
|
||||||
name: string;
|
name: string;
|
||||||
@@ -31,92 +21,59 @@ type CommandMenuProps = {
|
|||||||
frequentCommands?: CommandMenuCommand[];
|
frequentCommands?: CommandMenuCommand[];
|
||||||
};
|
};
|
||||||
|
|
||||||
type CommandMenuRow = {
|
|
||||||
command: CommandMenuCommand;
|
|
||||||
commandIndex: number;
|
|
||||||
renderKey: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
const menuBaseStyle: CSSProperties = {
|
const menuBaseStyle: CSSProperties = {
|
||||||
maxHeight: '360px',
|
maxHeight: '300px',
|
||||||
overflowY: 'auto',
|
overflowY: 'auto',
|
||||||
borderRadius: '8px',
|
borderRadius: '8px',
|
||||||
boxShadow: '0 24px 60px rgba(2, 6, 23, 0.38), 0 0 0 1px rgba(148, 163, 184, 0.12)',
|
boxShadow: '0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05)',
|
||||||
zIndex: 1000,
|
zIndex: 1000,
|
||||||
padding: '6px',
|
padding: '8px',
|
||||||
transition: 'opacity 150ms ease-in-out, transform 150ms ease-in-out',
|
transition: 'opacity 150ms ease-in-out, transform 150ms ease-in-out',
|
||||||
backdropFilter: 'blur(12px)',
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const namespaceLabels: Record<string, string> = {
|
const namespaceLabels: Record<string, string> = {
|
||||||
frequent: 'Frequently Used',
|
frequent: 'Frequently Used',
|
||||||
builtin: 'Built-in Commands',
|
builtin: 'Built-in Commands',
|
||||||
skill: 'Skills',
|
|
||||||
project: 'Project Commands',
|
project: 'Project Commands',
|
||||||
user: 'User Commands',
|
user: 'User Commands',
|
||||||
other: 'Other Commands',
|
other: 'Other Commands',
|
||||||
};
|
};
|
||||||
|
|
||||||
const namespaceIcons: Record<string, LucideIcon> = {
|
const namespaceIcons: Record<string, string> = {
|
||||||
frequent: Star,
|
frequent: '[*]',
|
||||||
builtin: Terminal,
|
builtin: '[B]',
|
||||||
skill: Sparkles,
|
project: '[P]',
|
||||||
project: Folder,
|
user: '[U]',
|
||||||
user: User,
|
other: '[O]',
|
||||||
other: MessageSquare,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const namespaceAccentClasses: Record<string, string> = {
|
|
||||||
frequent: 'border-amber-200 bg-amber-50 text-amber-700 dark:border-amber-400/20 dark:bg-amber-400/10 dark:text-amber-200',
|
|
||||||
builtin: 'border-sky-200 bg-sky-50 text-sky-700 dark:border-sky-400/20 dark:bg-sky-400/10 dark:text-sky-200',
|
|
||||||
skill: 'border-emerald-200 bg-emerald-50 text-emerald-700 dark:border-emerald-400/20 dark:bg-emerald-400/10 dark:text-emerald-200',
|
|
||||||
project: 'border-indigo-200 bg-indigo-50 text-indigo-700 dark:border-indigo-400/20 dark:bg-indigo-400/10 dark:text-indigo-200',
|
|
||||||
user: 'border-rose-200 bg-rose-50 text-rose-700 dark:border-rose-400/20 dark:bg-rose-400/10 dark:text-rose-200',
|
|
||||||
other: 'border-gray-200 bg-gray-50 text-gray-600 dark:border-gray-500/20 dark:bg-gray-500/10 dark:text-gray-200',
|
|
||||||
};
|
|
||||||
|
|
||||||
const MENU_EDGE_GAP = 16;
|
|
||||||
const MENU_MAX_HEIGHT = 360;
|
|
||||||
|
|
||||||
const getCommandKey = (command: CommandMenuCommand) =>
|
const getCommandKey = (command: CommandMenuCommand) =>
|
||||||
`${command.name}::${command.namespace || command.type || 'other'}::${command.path || ''}`;
|
`${command.name}::${command.namespace || command.type || 'other'}::${command.path || ''}`;
|
||||||
|
|
||||||
const getNamespace = (command: CommandMenuCommand) => command.namespace || command.type || 'other';
|
const getNamespace = (command: CommandMenuCommand) => command.namespace || command.type || 'other';
|
||||||
|
|
||||||
const getNamespaceIcon = (namespace: string) => namespaceIcons[namespace] || namespaceIcons.other;
|
|
||||||
|
|
||||||
const getNamespaceAccentClass = (namespace: string) =>
|
|
||||||
namespaceAccentClasses[namespace] || namespaceAccentClasses.other;
|
|
||||||
|
|
||||||
const getMenuPosition = (position: { top: number; left: number; bottom?: number }): CSSProperties => {
|
const getMenuPosition = (position: { top: number; left: number; bottom?: number }): CSSProperties => {
|
||||||
if (typeof window === 'undefined') {
|
if (typeof window === 'undefined') {
|
||||||
return { position: 'fixed', top: '16px', left: '16px' };
|
return { position: 'fixed', top: '16px', left: '16px' };
|
||||||
}
|
}
|
||||||
if (window.innerWidth < 640) {
|
if (window.innerWidth < 640) {
|
||||||
const anchorBottom = Math.max(MENU_EDGE_GAP, position.bottom ?? 90);
|
|
||||||
return {
|
return {
|
||||||
position: 'fixed',
|
position: 'fixed',
|
||||||
bottom: `${anchorBottom}px`,
|
bottom: `${position.bottom ?? 90}px`,
|
||||||
left: '16px',
|
left: '16px',
|
||||||
right: '16px',
|
right: '16px',
|
||||||
width: 'auto',
|
width: 'auto',
|
||||||
maxWidth: 'calc(100vw - 32px)',
|
maxWidth: 'calc(100vw - 32px)',
|
||||||
maxHeight: `min(54vh, calc(100vh - ${anchorBottom}px - ${MENU_EDGE_GAP}px))`,
|
maxHeight: 'min(50vh, 300px)',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
const anchorBottom = Math.max(MENU_EDGE_GAP, position.bottom ?? 90);
|
|
||||||
const clampedLeft = Math.max(
|
|
||||||
MENU_EDGE_GAP,
|
|
||||||
Math.min(position.left, window.innerWidth - 440 - MENU_EDGE_GAP),
|
|
||||||
);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
position: 'fixed',
|
position: 'fixed',
|
||||||
bottom: `${anchorBottom}px`,
|
top: `${Math.max(16, Math.min(position.top, window.innerHeight - 316))}px`,
|
||||||
left: `${clampedLeft}px`,
|
left: `${position.left}px`,
|
||||||
width: 'min(440px, calc(100vw - 32px))',
|
width: 'min(400px, calc(100vw - 32px))',
|
||||||
maxWidth: 'calc(100vw - 32px)',
|
maxWidth: 'calc(100vw - 32px)',
|
||||||
maxHeight: `min(${MENU_MAX_HEIGHT}px, calc(100vh - ${anchorBottom}px - ${MENU_EDGE_GAP}px))`,
|
maxHeight: '300px',
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -166,24 +123,7 @@ export default function CommandMenu({
|
|||||||
|
|
||||||
const hasFrequentCommands = frequentCommands.length > 0;
|
const hasFrequentCommands = frequentCommands.length > 0;
|
||||||
const frequentCommandKeys = new Set(frequentCommands.map(getCommandKey));
|
const frequentCommandKeys = new Set(frequentCommands.map(getCommandKey));
|
||||||
const commandIndexesByKey = new Map<string, number[]>();
|
const groupedCommands = commands.reduce<Record<string, CommandMenuCommand[]>>((groups, command) => {
|
||||||
commands.forEach((command, index) => {
|
|
||||||
const key = getCommandKey(command);
|
|
||||||
const commandIndexes = commandIndexesByKey.get(key) ?? [];
|
|
||||||
commandIndexes.push(index);
|
|
||||||
commandIndexesByKey.set(key, commandIndexes);
|
|
||||||
});
|
|
||||||
const frequentCommandOccurrences = new Map<string, number>();
|
|
||||||
const getFrequentCommandIndex = (command: CommandMenuCommand): number => {
|
|
||||||
const key = getCommandKey(command);
|
|
||||||
const occurrence = frequentCommandOccurrences.get(key) ?? 0;
|
|
||||||
frequentCommandOccurrences.set(key, occurrence + 1);
|
|
||||||
|
|
||||||
const commandIndexes = commandIndexesByKey.get(key) ?? [];
|
|
||||||
return commandIndexes[occurrence] ?? commandIndexes[0] ?? -1;
|
|
||||||
};
|
|
||||||
|
|
||||||
const groupedCommands = commands.reduce<Record<string, CommandMenuRow[]>>((groups, command, index) => {
|
|
||||||
if (hasFrequentCommands && frequentCommandKeys.has(getCommandKey(command))) {
|
if (hasFrequentCommands && frequentCommandKeys.has(getCommandKey(command))) {
|
||||||
return groups;
|
return groups;
|
||||||
}
|
}
|
||||||
@@ -191,46 +131,33 @@ export default function CommandMenu({
|
|||||||
if (!groups[namespace]) {
|
if (!groups[namespace]) {
|
||||||
groups[namespace] = [];
|
groups[namespace] = [];
|
||||||
}
|
}
|
||||||
groups[namespace].push({
|
groups[namespace].push(command);
|
||||||
command,
|
|
||||||
commandIndex: index,
|
|
||||||
renderKey: `${namespace}-${index}-${getCommandKey(command)}`,
|
|
||||||
});
|
|
||||||
return groups;
|
return groups;
|
||||||
}, {});
|
}, {});
|
||||||
if (hasFrequentCommands) {
|
if (hasFrequentCommands) {
|
||||||
groupedCommands.frequent = frequentCommands
|
groupedCommands.frequent = frequentCommands;
|
||||||
.map((command, index) => {
|
|
||||||
const commandIndex = getFrequentCommandIndex(command);
|
|
||||||
return {
|
|
||||||
command,
|
|
||||||
commandIndex,
|
|
||||||
renderKey: `frequent-${index}-${commandIndex}-${getCommandKey(command)}`,
|
|
||||||
};
|
|
||||||
})
|
|
||||||
.filter((row) => row.commandIndex >= 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const preferredOrder = hasFrequentCommands
|
const preferredOrder = hasFrequentCommands
|
||||||
? ['frequent', 'builtin', 'skill', 'project', 'user', 'other']
|
? ['frequent', 'builtin', 'project', 'user', 'other']
|
||||||
: ['builtin', 'skill', 'project', 'user', 'other'];
|
: ['builtin', 'project', 'user', 'other'];
|
||||||
const extraNamespaces = Object.keys(groupedCommands).filter((namespace) => !preferredOrder.includes(namespace));
|
const extraNamespaces = Object.keys(groupedCommands).filter((namespace) => !preferredOrder.includes(namespace));
|
||||||
const orderedNamespaces = [...preferredOrder, ...extraNamespaces].filter((namespace) => groupedCommands[namespace]);
|
const orderedNamespaces = [...preferredOrder, ...extraNamespaces].filter((namespace) => groupedCommands[namespace]);
|
||||||
|
|
||||||
|
const commandIndexByKey = new Map<string, number>();
|
||||||
|
commands.forEach((command, index) => {
|
||||||
|
const key = getCommandKey(command);
|
||||||
|
if (!commandIndexByKey.has(key)) {
|
||||||
|
commandIndexByKey.set(key, index);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
if (commands.length === 0) {
|
if (commands.length === 0) {
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
ref={menuRef}
|
ref={menuRef}
|
||||||
className="command-menu command-menu-empty border border-gray-200 bg-white/95 text-sm text-gray-500 dark:border-gray-700/80 dark:bg-gray-900/95 dark:text-gray-400"
|
className="command-menu command-menu-empty border border-gray-200 bg-white text-gray-500 dark:border-gray-700 dark:bg-gray-800 dark:text-gray-400"
|
||||||
style={{
|
style={{ ...menuPosition, ...menuBaseStyle, overflowY: 'hidden', padding: '20px', opacity: 1, transform: 'translateY(0)', textAlign: 'center' }}
|
||||||
...menuBaseStyle,
|
|
||||||
...menuPosition,
|
|
||||||
overflowY: 'hidden',
|
|
||||||
padding: '20px',
|
|
||||||
opacity: 1,
|
|
||||||
transform: 'translateY(0)',
|
|
||||||
textAlign: 'center',
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
No commands available
|
No commands available
|
||||||
</div>
|
</div>
|
||||||
@@ -242,73 +169,51 @@ export default function CommandMenu({
|
|||||||
ref={menuRef}
|
ref={menuRef}
|
||||||
role="listbox"
|
role="listbox"
|
||||||
aria-label="Available commands"
|
aria-label="Available commands"
|
||||||
className="command-menu border border-gray-200/90 bg-white/95 text-gray-900 dark:border-slate-700/80 dark:bg-slate-950/95 dark:text-slate-100"
|
className="command-menu border border-gray-200 bg-white dark:border-gray-700 dark:bg-gray-800"
|
||||||
style={{ ...menuBaseStyle, ...menuPosition, opacity: 1, transform: 'translateY(0)' }}
|
style={{ ...menuPosition, ...menuBaseStyle, opacity: 1, transform: 'translateY(0)' }}
|
||||||
>
|
>
|
||||||
{orderedNamespaces.map((namespace) => (
|
{orderedNamespaces.map((namespace) => (
|
||||||
<div key={namespace} className="command-group">
|
<div key={namespace} className="command-group">
|
||||||
{orderedNamespaces.length > 1 && (
|
{orderedNamespaces.length > 1 && (
|
||||||
<div className="flex items-center justify-between px-2 pb-1.5 pt-2 text-[10px] font-semibold uppercase tracking-wide text-gray-500 dark:text-slate-400">
|
<div className="px-3 pb-1 pt-2 text-xs font-semibold uppercase tracking-wide text-gray-500 dark:text-gray-400">
|
||||||
<span>{namespaceLabels[namespace] || namespace}</span>
|
{namespaceLabels[namespace] || namespace}
|
||||||
<span className="rounded border border-gray-200 bg-gray-50 px-1.5 py-0.5 text-[10px] text-gray-500 dark:border-slate-700 dark:bg-slate-900 dark:text-slate-400">
|
|
||||||
{(groupedCommands[namespace] || []).length}
|
|
||||||
</span>
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{(groupedCommands[namespace] || []).map(({ command, commandIndex, renderKey }) => {
|
{(groupedCommands[namespace] || []).map((command) => {
|
||||||
|
const commandKey = getCommandKey(command);
|
||||||
|
const commandIndex = commandIndexByKey.get(commandKey) ?? -1;
|
||||||
const isSelected = commandIndex === selectedIndex;
|
const isSelected = commandIndex === selectedIndex;
|
||||||
const NamespaceIcon = getNamespaceIcon(namespace);
|
|
||||||
const accentClass = getNamespaceAccentClass(namespace);
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
key={renderKey}
|
key={`${namespace}-${command.name}-${command.path || ''}`}
|
||||||
ref={isSelected ? selectedItemRef : null}
|
ref={isSelected ? selectedItemRef : null}
|
||||||
role="option"
|
role="option"
|
||||||
aria-selected={isSelected}
|
aria-selected={isSelected}
|
||||||
className={`command-item group relative mb-1 flex cursor-pointer items-start gap-2 rounded-md border px-2.5 py-2 transition-all ${
|
className={`command-item mb-0.5 flex cursor-pointer items-start rounded-md px-3 py-2.5 transition-colors ${
|
||||||
isSelected
|
isSelected ? 'bg-blue-50 dark:bg-blue-900' : 'bg-transparent'
|
||||||
? 'border-sky-200 bg-sky-50 shadow-sm dark:border-cyan-400/30 dark:bg-cyan-400/10'
|
|
||||||
: 'border-transparent bg-transparent hover:border-gray-200 hover:bg-gray-50/90 dark:hover:border-slate-700 dark:hover:bg-slate-900/80'
|
|
||||||
}`}
|
}`}
|
||||||
onMouseEnter={() => onSelect && commandIndex >= 0 && onSelect(command, commandIndex, true)}
|
onMouseEnter={() => onSelect && commandIndex >= 0 && onSelect(command, commandIndex, true)}
|
||||||
onClick={() => onSelect && commandIndex >= 0 && onSelect(command, commandIndex, false)}
|
onClick={() => onSelect && commandIndex >= 0 && onSelect(command, commandIndex, false)}
|
||||||
onMouseDown={(event) => event.preventDefault()}
|
onMouseDown={(event) => event.preventDefault()}
|
||||||
>
|
>
|
||||||
{isSelected && (
|
<div className="min-w-0 flex-1">
|
||||||
<span className="absolute bottom-1.5 left-1.5 top-1.5 w-0.5 rounded-full bg-sky-500 dark:bg-cyan-300" />
|
<div className={`flex items-center gap-2 ${command.description ? 'mb-1' : 'mb-0'}`}>
|
||||||
)}
|
<span className="shrink-0 text-xs text-gray-500 dark:text-gray-300">{namespaceIcons[namespace] || namespaceIcons.other}</span>
|
||||||
<span className={`mt-0.5 flex h-7 w-7 shrink-0 items-center justify-center rounded-md border ${accentClass}`}>
|
<span className="font-mono text-sm font-semibold text-gray-900 dark:text-gray-100">{command.name}</span>
|
||||||
<NamespaceIcon aria-hidden="true" size={14} strokeWidth={2.2} />
|
|
||||||
</span>
|
|
||||||
<div className="min-w-0 flex-1 pr-1">
|
|
||||||
<div className={`flex min-w-0 items-center gap-2 ${command.description ? 'mb-1' : 'mb-0'}`}>
|
|
||||||
<span
|
|
||||||
className="min-w-0 truncate font-mono text-[13px] font-semibold text-gray-950 dark:text-slate-50"
|
|
||||||
title={command.name}
|
|
||||||
>
|
|
||||||
{command.name}
|
|
||||||
</span>
|
|
||||||
{command.metadata?.type && (
|
{command.metadata?.type && (
|
||||||
<span className="command-metadata-badge shrink-0 rounded border border-gray-200 bg-white px-1.5 py-0.5 text-[10px] font-medium text-gray-500 shadow-sm dark:border-slate-700 dark:bg-slate-900 dark:text-slate-300">
|
<span className="command-metadata-badge rounded bg-gray-100 px-1.5 py-0.5 text-[10px] font-medium text-gray-500 dark:bg-gray-700 dark:text-gray-300">
|
||||||
{command.metadata.type}
|
{command.metadata.type}
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
{command.description && (
|
{command.description && (
|
||||||
<div
|
<div className="ml-6 truncate whitespace-nowrap text-[13px] text-gray-500 dark:text-gray-300">
|
||||||
className="truncate whitespace-nowrap text-[12px] leading-4 text-gray-500 dark:text-slate-400"
|
|
||||||
title={command.description}
|
|
||||||
>
|
|
||||||
{command.description}
|
{command.description}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
{isSelected && (
|
{isSelected && <span className="ml-2 text-xs font-semibold text-blue-500 dark:text-blue-300">{'<-'}</span>}
|
||||||
<span className="mt-1 flex h-6 w-6 shrink-0 items-center justify-center rounded border border-sky-200 bg-white text-sky-600 shadow-sm dark:border-cyan-400/30 dark:bg-slate-950 dark:text-cyan-200">
|
|
||||||
<CornerDownLeft aria-hidden="true" size={13} strokeWidth={2.2} />
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ export type MainContentProps = {
|
|||||||
onSessionProcessing: SessionLifecycleHandler;
|
onSessionProcessing: SessionLifecycleHandler;
|
||||||
onSessionNotProcessing: SessionLifecycleHandler;
|
onSessionNotProcessing: SessionLifecycleHandler;
|
||||||
processingSessions: Set<string>;
|
processingSessions: Set<string>;
|
||||||
|
onReplaceTemporarySession: SessionLifecycleHandler;
|
||||||
onNavigateToSession: (targetSessionId: string, options?: SessionNavigationOptions) => void;
|
onNavigateToSession: (targetSessionId: string, options?: SessionNavigationOptions) => void;
|
||||||
onShowSettings: () => void;
|
onShowSettings: () => void;
|
||||||
externalMessageUpdate: number;
|
externalMessageUpdate: number;
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ function MainContent({
|
|||||||
onSessionProcessing,
|
onSessionProcessing,
|
||||||
onSessionNotProcessing,
|
onSessionNotProcessing,
|
||||||
processingSessions,
|
processingSessions,
|
||||||
|
onReplaceTemporarySession,
|
||||||
onNavigateToSession,
|
onNavigateToSession,
|
||||||
onShowSettings,
|
onShowSettings,
|
||||||
externalMessageUpdate,
|
externalMessageUpdate,
|
||||||
@@ -136,6 +137,7 @@ function MainContent({
|
|||||||
onSessionProcessing={onSessionProcessing}
|
onSessionProcessing={onSessionProcessing}
|
||||||
onSessionNotProcessing={onSessionNotProcessing}
|
onSessionNotProcessing={onSessionNotProcessing}
|
||||||
processingSessions={processingSessions}
|
processingSessions={processingSessions}
|
||||||
|
onReplaceTemporarySession={onReplaceTemporarySession}
|
||||||
onNavigateToSession={onNavigateToSession}
|
onNavigateToSession={onNavigateToSession}
|
||||||
onShowSettings={onShowSettings}
|
onShowSettings={onShowSettings}
|
||||||
autoExpandTools={autoExpandTools}
|
autoExpandTools={autoExpandTools}
|
||||||
|
|||||||
@@ -5,11 +5,8 @@ import { api } from '../../../utils/api';
|
|||||||
import { usePaletteOps } from '../../../contexts/PaletteOpsContext';
|
import { usePaletteOps } from '../../../contexts/PaletteOpsContext';
|
||||||
import type { Project, ProjectSession, LLMProvider } from '../../../types/app';
|
import type { Project, ProjectSession, LLMProvider } from '../../../types/app';
|
||||||
import type {
|
import type {
|
||||||
ArchivedProjectListItem,
|
|
||||||
ArchivedSessionListItem,
|
|
||||||
DeleteProjectConfirmation,
|
DeleteProjectConfirmation,
|
||||||
ProjectSortOrder,
|
ProjectSortOrder,
|
||||||
SidebarSearchMode,
|
|
||||||
SessionDeleteConfirmation,
|
SessionDeleteConfirmation,
|
||||||
SessionWithProvider,
|
SessionWithProvider,
|
||||||
} from '../types/types';
|
} from '../types/types';
|
||||||
@@ -63,20 +60,6 @@ export type SearchProgress = {
|
|||||||
totalProjects: number;
|
totalProjects: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
type ArchivedSessionsApiPayload = {
|
|
||||||
success?: boolean;
|
|
||||||
data?: {
|
|
||||||
sessions?: ArchivedSessionListItem[];
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
type ArchivedProjectsApiPayload = {
|
|
||||||
success?: boolean;
|
|
||||||
data?: {
|
|
||||||
projects?: ArchivedProjectListItem[];
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
type UseSidebarControllerArgs = {
|
type UseSidebarControllerArgs = {
|
||||||
projects: Project[];
|
projects: Project[];
|
||||||
selectedProject: Project | null;
|
selectedProject: Project | null;
|
||||||
@@ -129,13 +112,10 @@ export function useSidebarController({
|
|||||||
const [deleteConfirmation, setDeleteConfirmation] = useState<DeleteProjectConfirmation | null>(null);
|
const [deleteConfirmation, setDeleteConfirmation] = useState<DeleteProjectConfirmation | null>(null);
|
||||||
const [sessionDeleteConfirmation, setSessionDeleteConfirmation] = useState<SessionDeleteConfirmation | null>(null);
|
const [sessionDeleteConfirmation, setSessionDeleteConfirmation] = useState<SessionDeleteConfirmation | null>(null);
|
||||||
const [showVersionModal, setShowVersionModal] = useState(false);
|
const [showVersionModal, setShowVersionModal] = useState(false);
|
||||||
const [searchMode, setSearchMode] = useState<SidebarSearchMode>('projects');
|
const [searchMode, setSearchMode] = useState<'projects' | 'conversations'>('projects');
|
||||||
const [conversationResults, setConversationResults] = useState<ConversationSearchResults | null>(null);
|
const [conversationResults, setConversationResults] = useState<ConversationSearchResults | null>(null);
|
||||||
const [isSearching, setIsSearching] = useState(false);
|
const [isSearching, setIsSearching] = useState(false);
|
||||||
const [searchProgress, setSearchProgress] = useState<SearchProgress | null>(null);
|
const [searchProgress, setSearchProgress] = useState<SearchProgress | null>(null);
|
||||||
const [archivedProjects, setArchivedProjects] = useState<ArchivedProjectListItem[]>([]);
|
|
||||||
const [archivedSessions, setArchivedSessions] = useState<ArchivedSessionListItem[]>([]);
|
|
||||||
const [isArchivedSessionsLoading, setIsArchivedSessionsLoading] = useState(false);
|
|
||||||
const [debouncedSearchQuery, setDebouncedSearchQuery] = useState('');
|
const [debouncedSearchQuery, setDebouncedSearchQuery] = useState('');
|
||||||
const [optimisticStarByProjectId, setOptimisticStarByProjectId] = useState<Map<string, boolean>>(new Map());
|
const [optimisticStarByProjectId, setOptimisticStarByProjectId] = useState<Map<string, boolean>>(new Map());
|
||||||
const [loadingMoreProjects, setLoadingMoreProjects] = useState<Set<string>>(new Set());
|
const [loadingMoreProjects, setLoadingMoreProjects] = useState<Set<string>>(new Set());
|
||||||
@@ -221,40 +201,6 @@ export function useSidebarController({
|
|||||||
onRefreshRef.current = onRefresh;
|
onRefreshRef.current = onRefresh;
|
||||||
}, [onRefresh]);
|
}, [onRefresh]);
|
||||||
|
|
||||||
const fetchArchivedSessions = useCallback(async () => {
|
|
||||||
setIsArchivedSessionsLoading(true);
|
|
||||||
|
|
||||||
try {
|
|
||||||
const [archivedProjectsResponse, archivedSessionsResponse] = await Promise.all([
|
|
||||||
api.archivedProjects(),
|
|
||||||
api.getArchivedSessions(),
|
|
||||||
]);
|
|
||||||
|
|
||||||
if (!archivedProjectsResponse.ok) {
|
|
||||||
throw new Error(`Failed to load archived projects: ${archivedProjectsResponse.status}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!archivedSessionsResponse.ok) {
|
|
||||||
throw new Error(`Failed to load archived sessions: ${archivedSessionsResponse.status}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
const archivedProjectsPayload = (await archivedProjectsResponse.json()) as ArchivedProjectsApiPayload;
|
|
||||||
const archivedSessionsPayload = (await archivedSessionsResponse.json()) as ArchivedSessionsApiPayload;
|
|
||||||
const nextProjects = Array.isArray(archivedProjectsPayload.data?.projects) ? archivedProjectsPayload.data.projects : [];
|
|
||||||
const archivedProjectIds = new Set(nextProjects.map((project) => project.projectId));
|
|
||||||
const nextStandaloneSessions = Array.isArray(archivedSessionsPayload.data?.sessions)
|
|
||||||
? archivedSessionsPayload.data.sessions.filter((session) => !session.projectId || !archivedProjectIds.has(session.projectId))
|
|
||||||
: [];
|
|
||||||
|
|
||||||
setArchivedProjects(nextProjects);
|
|
||||||
setArchivedSessions(nextStandaloneSessions);
|
|
||||||
} catch (error) {
|
|
||||||
console.error('[Sidebar] Failed to load archived sessions:', error);
|
|
||||||
} finally {
|
|
||||||
setIsArchivedSessionsLoading(false);
|
|
||||||
}
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (migrationStartedRef.current) {
|
if (migrationStartedRef.current) {
|
||||||
return;
|
return;
|
||||||
@@ -281,20 +227,6 @@ export function useSidebarController({
|
|||||||
void migrateLegacyStars();
|
void migrateLegacyStars();
|
||||||
}, [onRefresh]);
|
}, [onRefresh]);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
void fetchArchivedSessions();
|
|
||||||
}, [fetchArchivedSessions]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (searchMode !== 'archived') {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Refresh archive contents when the archived tab opens so restore actions
|
|
||||||
// and background synchronizer updates are reflected without a full reload.
|
|
||||||
void fetchArchivedSessions();
|
|
||||||
}, [fetchArchivedSessions, searchMode]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setOptimisticStarByProjectId((previous) => {
|
setOptimisticStarByProjectId((previous) => {
|
||||||
if (previous.size === 0) {
|
if (previous.size === 0) {
|
||||||
@@ -587,56 +519,6 @@ export function useSidebarController({
|
|||||||
[debouncedSearchQuery, sortedProjects],
|
[debouncedSearchQuery, sortedProjects],
|
||||||
);
|
);
|
||||||
|
|
||||||
const filteredArchivedSessions = useMemo(() => {
|
|
||||||
const normalizedSearch = debouncedSearchQuery.trim().toLowerCase();
|
|
||||||
if (!normalizedSearch) {
|
|
||||||
return archivedSessions;
|
|
||||||
}
|
|
||||||
|
|
||||||
return archivedSessions.filter((session) => {
|
|
||||||
const searchableFields = [
|
|
||||||
session.sessionTitle,
|
|
||||||
session.projectDisplayName,
|
|
||||||
session.projectPath ?? '',
|
|
||||||
session.provider,
|
|
||||||
];
|
|
||||||
|
|
||||||
return searchableFields.some((value) => value.toLowerCase().includes(normalizedSearch));
|
|
||||||
});
|
|
||||||
}, [archivedSessions, debouncedSearchQuery]);
|
|
||||||
|
|
||||||
const filteredArchivedProjects = useMemo(() => {
|
|
||||||
const normalizedSearch = debouncedSearchQuery.trim().toLowerCase();
|
|
||||||
if (!normalizedSearch) {
|
|
||||||
return archivedProjects;
|
|
||||||
}
|
|
||||||
|
|
||||||
return archivedProjects.filter((project) => {
|
|
||||||
const projectMatches = [
|
|
||||||
project.displayName,
|
|
||||||
project.fullPath || '',
|
|
||||||
].some((value) => value.toLowerCase().includes(normalizedSearch));
|
|
||||||
|
|
||||||
if (projectMatches) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return getAllSessions(project).some((session) => {
|
|
||||||
const sessionSummary =
|
|
||||||
typeof session.summary === 'string' && session.summary.trim().length > 0
|
|
||||||
? session.summary
|
|
||||||
: typeof session.name === 'string'
|
|
||||||
? session.name
|
|
||||||
: '';
|
|
||||||
|
|
||||||
return [
|
|
||||||
sessionSummary,
|
|
||||||
session.__provider,
|
|
||||||
].some((value) => value.toLowerCase().includes(normalizedSearch));
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}, [archivedProjects, debouncedSearchQuery]);
|
|
||||||
|
|
||||||
const startEditing = useCallback((project: Project) => {
|
const startEditing = useCallback((project: Project) => {
|
||||||
// `editingProject` is keyed by projectId so it stays stable across
|
// `editingProject` is keyed by projectId so it stays stable across
|
||||||
// display-name mutations that happen while the input is open.
|
// display-name mutations that happen while the input is open.
|
||||||
@@ -674,26 +556,17 @@ export function useSidebarController({
|
|||||||
// Kept with project/provider arguments for component wiring compatibility;
|
// Kept with project/provider arguments for component wiring compatibility;
|
||||||
// deletion now uses only `sessionId` via /api/providers/sessions/:sessionId.
|
// deletion now uses only `sessionId` via /api/providers/sessions/:sessionId.
|
||||||
(
|
(
|
||||||
projectId: string | null,
|
projectId: string,
|
||||||
sessionId: string,
|
sessionId: string,
|
||||||
sessionTitle: string,
|
sessionTitle: string,
|
||||||
provider: SessionDeleteConfirmation['provider'] = 'claude',
|
provider: SessionDeleteConfirmation['provider'] = 'claude',
|
||||||
options: {
|
|
||||||
isArchived?: boolean;
|
|
||||||
} = {},
|
|
||||||
) => {
|
) => {
|
||||||
setSessionDeleteConfirmation({
|
setSessionDeleteConfirmation({ projectId, sessionId, sessionTitle, provider });
|
||||||
projectId,
|
|
||||||
sessionId,
|
|
||||||
sessionTitle,
|
|
||||||
provider,
|
|
||||||
isArchived: Boolean(options.isArchived),
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
[],
|
[],
|
||||||
);
|
);
|
||||||
|
|
||||||
const confirmDeleteSession = useCallback(async (hardDelete = false) => {
|
const confirmDeleteSession = useCallback(async () => {
|
||||||
if (!sessionDeleteConfirmation) {
|
if (!sessionDeleteConfirmation) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -702,11 +575,10 @@ export function useSidebarController({
|
|||||||
setSessionDeleteConfirmation(null);
|
setSessionDeleteConfirmation(null);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await api.deleteSession(sessionId, hardDelete);
|
const response = await api.deleteSession(sessionId);
|
||||||
|
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
onSessionDelete?.(sessionId);
|
onSessionDelete?.(sessionId);
|
||||||
await fetchArchivedSessions();
|
|
||||||
} else {
|
} else {
|
||||||
const errorText = await response.text();
|
const errorText = await response.text();
|
||||||
console.error('[Sidebar] Failed to delete session:', {
|
console.error('[Sidebar] Failed to delete session:', {
|
||||||
@@ -719,7 +591,7 @@ export function useSidebarController({
|
|||||||
console.error('[Sidebar] Error deleting session:', error);
|
console.error('[Sidebar] Error deleting session:', error);
|
||||||
alert(t('messages.deleteSessionError'));
|
alert(t('messages.deleteSessionError'));
|
||||||
}
|
}
|
||||||
}, [fetchArchivedSessions, onSessionDelete, sessionDeleteConfirmation, t]);
|
}, [onSessionDelete, sessionDeleteConfirmation, t]);
|
||||||
|
|
||||||
const requestProjectDelete = useCallback(
|
const requestProjectDelete = useCallback(
|
||||||
(project: Project) => {
|
(project: Project) => {
|
||||||
@@ -775,88 +647,14 @@ export function useSidebarController({
|
|||||||
[onProjectSelect, setCurrentProject],
|
[onProjectSelect, setCurrentProject],
|
||||||
);
|
);
|
||||||
|
|
||||||
const openArchivedSession = useCallback((session: ArchivedSessionListItem) => {
|
|
||||||
const activeProject = session.projectId
|
|
||||||
? projects.find((candidate) => candidate.projectId === session.projectId)
|
|
||||||
: null;
|
|
||||||
const archivedProject = session.projectId
|
|
||||||
? archivedProjects.find((candidate) => candidate.projectId === session.projectId)
|
|
||||||
: null;
|
|
||||||
const matchingProject = activeProject ?? archivedProject ?? null;
|
|
||||||
const sessionPayload: ProjectSession = {
|
|
||||||
id: session.sessionId,
|
|
||||||
summary: session.sessionTitle,
|
|
||||||
__provider: session.provider,
|
|
||||||
__projectId: matchingProject?.projectId ?? session.projectId ?? undefined,
|
|
||||||
};
|
|
||||||
|
|
||||||
// Archived sessions still need a selected project context. Active projects
|
|
||||||
// come from the normal sidebar list, while archived-project sessions resolve
|
|
||||||
// through the archive payload loaded by this controller.
|
|
||||||
if (matchingProject) {
|
|
||||||
handleProjectSelect(matchingProject);
|
|
||||||
}
|
|
||||||
|
|
||||||
onSessionSelect(sessionPayload);
|
|
||||||
}, [archivedProjects, handleProjectSelect, onSessionSelect, projects]);
|
|
||||||
|
|
||||||
const restoreArchivedProject = useCallback(async (projectId: string) => {
|
|
||||||
try {
|
|
||||||
const response = await api.restoreProject(projectId);
|
|
||||||
if (!response.ok) {
|
|
||||||
const errorText = await response.text();
|
|
||||||
console.error('[Sidebar] Failed to restore project:', {
|
|
||||||
status: response.status,
|
|
||||||
error: errorText,
|
|
||||||
});
|
|
||||||
alert(t('messages.restoreProjectFailed', 'Failed to restore project. Please try again.'));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
await Promise.all([
|
|
||||||
Promise.resolve(onRefresh()),
|
|
||||||
fetchArchivedSessions(),
|
|
||||||
]);
|
|
||||||
} catch (error) {
|
|
||||||
console.error('[Sidebar] Error restoring project:', error);
|
|
||||||
alert(t('messages.restoreProjectError', 'Error restoring project. Please try again.'));
|
|
||||||
}
|
|
||||||
}, [fetchArchivedSessions, onRefresh, t]);
|
|
||||||
|
|
||||||
const restoreArchivedSession = useCallback(async (sessionId: string) => {
|
|
||||||
try {
|
|
||||||
const response = await api.restoreSession(sessionId);
|
|
||||||
if (!response.ok) {
|
|
||||||
const errorText = await response.text();
|
|
||||||
console.error('[Sidebar] Failed to restore session:', {
|
|
||||||
status: response.status,
|
|
||||||
error: errorText,
|
|
||||||
});
|
|
||||||
alert(t('messages.restoreSessionFailed', 'Failed to restore session. Please try again.'));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
await Promise.all([
|
|
||||||
Promise.resolve(onRefresh()),
|
|
||||||
fetchArchivedSessions(),
|
|
||||||
]);
|
|
||||||
} catch (error) {
|
|
||||||
console.error('[Sidebar] Error restoring session:', error);
|
|
||||||
alert(t('messages.restoreSessionError', 'Error restoring session. Please try again.'));
|
|
||||||
}
|
|
||||||
}, [fetchArchivedSessions, onRefresh, t]);
|
|
||||||
|
|
||||||
const refreshProjects = useCallback(async () => {
|
const refreshProjects = useCallback(async () => {
|
||||||
setIsRefreshing(true);
|
setIsRefreshing(true);
|
||||||
try {
|
try {
|
||||||
await Promise.all([
|
await onRefresh();
|
||||||
Promise.resolve(onRefresh()),
|
|
||||||
fetchArchivedSessions(),
|
|
||||||
]);
|
|
||||||
} finally {
|
} finally {
|
||||||
setIsRefreshing(false);
|
setIsRefreshing(false);
|
||||||
}
|
}
|
||||||
}, [fetchArchivedSessions, onRefresh]);
|
}, [onRefresh]);
|
||||||
|
|
||||||
const updateSessionSummary = useCallback(
|
const updateSessionSummary = useCallback(
|
||||||
// `_projectId` and `_provider` are preserved for compatibility with
|
// `_projectId` and `_provider` are preserved for compatibility with
|
||||||
@@ -914,10 +712,6 @@ export function useSidebarController({
|
|||||||
sessionDeleteConfirmation,
|
sessionDeleteConfirmation,
|
||||||
showVersionModal,
|
showVersionModal,
|
||||||
filteredProjects,
|
filteredProjects,
|
||||||
archivedProjects: filteredArchivedProjects,
|
|
||||||
archivedSessions: filteredArchivedSessions,
|
|
||||||
archivedSessionsCount: archivedProjects.length + archivedSessions.length,
|
|
||||||
isArchivedSessionsLoading,
|
|
||||||
toggleProject,
|
toggleProject,
|
||||||
handleSessionClick,
|
handleSessionClick,
|
||||||
toggleStarProject,
|
toggleStarProject,
|
||||||
@@ -932,9 +726,6 @@ export function useSidebarController({
|
|||||||
requestProjectDelete,
|
requestProjectDelete,
|
||||||
confirmDeleteProject,
|
confirmDeleteProject,
|
||||||
handleProjectSelect,
|
handleProjectSelect,
|
||||||
openArchivedSession,
|
|
||||||
restoreArchivedProject,
|
|
||||||
restoreArchivedSession,
|
|
||||||
refreshProjects,
|
refreshProjects,
|
||||||
updateSessionSummary,
|
updateSessionSummary,
|
||||||
collapseSidebar,
|
collapseSidebar,
|
||||||
|
|||||||
@@ -1,26 +1,11 @@
|
|||||||
import type { LoadingProgress, Project, ProjectSession, LLMProvider } from '../../../types/app';
|
import type { LoadingProgress, Project, ProjectSession, LLMProvider } from '../../../types/app';
|
||||||
|
|
||||||
export type ProjectSortOrder = 'name' | 'date';
|
export type ProjectSortOrder = 'name' | 'date';
|
||||||
export type SidebarSearchMode = 'projects' | 'conversations' | 'archived';
|
|
||||||
export type ArchivedProjectListItem = Project & { isArchived: true };
|
|
||||||
|
|
||||||
export type SessionWithProvider = ProjectSession & {
|
export type SessionWithProvider = ProjectSession & {
|
||||||
__provider: LLMProvider;
|
__provider: LLMProvider;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type ArchivedSessionListItem = {
|
|
||||||
sessionId: string;
|
|
||||||
provider: LLMProvider;
|
|
||||||
projectId: string | null;
|
|
||||||
projectPath: string | null;
|
|
||||||
projectDisplayName: string;
|
|
||||||
sessionTitle: string;
|
|
||||||
createdAt: string | null;
|
|
||||||
updatedAt: string | null;
|
|
||||||
lastActivity: string | null;
|
|
||||||
isProjectArchived: boolean;
|
|
||||||
};
|
|
||||||
|
|
||||||
export type DeleteProjectConfirmation = {
|
export type DeleteProjectConfirmation = {
|
||||||
project: Project;
|
project: Project;
|
||||||
sessionCount: number;
|
sessionCount: number;
|
||||||
@@ -29,11 +14,10 @@ export type DeleteProjectConfirmation = {
|
|||||||
// Delete confirmation payload used by sidebar UX. `projectId`/`provider` are
|
// Delete confirmation payload used by sidebar UX. `projectId`/`provider` are
|
||||||
// kept for wiring compatibility, while API deletion now keys only by sessionId.
|
// kept for wiring compatibility, while API deletion now keys only by sessionId.
|
||||||
export type SessionDeleteConfirmation = {
|
export type SessionDeleteConfirmation = {
|
||||||
projectId: string | null;
|
projectId: string;
|
||||||
sessionId: string;
|
sessionId: string;
|
||||||
sessionTitle: string;
|
sessionTitle: string;
|
||||||
provider: LLMProvider;
|
provider: LLMProvider;
|
||||||
isArchived: boolean;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export type SidebarProps = {
|
export type SidebarProps = {
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import type { TFunction } from 'i18next';
|
import type { TFunction } from 'i18next';
|
||||||
|
|
||||||
import type { Project } from '../../../types/app';
|
import type { Project } from '../../../types/app';
|
||||||
import type { ProjectSortOrder, SettingsProject, SessionViewModel, SessionWithProvider } from '../types/types';
|
import type { ProjectSortOrder, SettingsProject, SessionViewModel, SessionWithProvider } from '../types/types';
|
||||||
|
|
||||||
@@ -53,24 +52,44 @@ export const clearLegacyStarredProjectIds = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const getCreatedTimestamp = (session: SessionWithProvider): string => {
|
|
||||||
return String(session.createdAt || session.created_at || '');
|
|
||||||
};
|
|
||||||
|
|
||||||
const getUpdatedTimestamp = (session: SessionWithProvider): string => {
|
|
||||||
return String(session.lastActivity || '');
|
|
||||||
};
|
|
||||||
|
|
||||||
export const getSessionDate = (session: SessionWithProvider): Date => {
|
export const getSessionDate = (session: SessionWithProvider): Date => {
|
||||||
return new Date(getUpdatedTimestamp(session) || getCreatedTimestamp(session) || 0);
|
if (session.__provider === 'cursor') {
|
||||||
|
return new Date(session.createdAt || 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (session.__provider === 'codex') {
|
||||||
|
return new Date(session.createdAt || session.lastActivity || 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Date(session.lastActivity || session.createdAt || 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getSessionName = (session: SessionWithProvider, t: TFunction): string => {
|
export const getSessionName = (session: SessionWithProvider, t: TFunction): string => {
|
||||||
return session.summary || session.name || t('projects.newSession');
|
if (session.__provider === 'cursor') {
|
||||||
|
return session.summary || session.name || t('projects.untitledSession');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (session.__provider === 'codex') {
|
||||||
|
return session.summary || session.name || t('projects.codexSession');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (session.__provider === 'gemini') {
|
||||||
|
return session.summary || session.name || t('projects.newSession');
|
||||||
|
}
|
||||||
|
|
||||||
|
return session.summary || t('projects.newSession');
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getSessionTime = (session: SessionWithProvider): string => {
|
export const getSessionTime = (session: SessionWithProvider): string => {
|
||||||
return getUpdatedTimestamp(session) || getCreatedTimestamp(session);
|
if (session.__provider === 'cursor') {
|
||||||
|
return String(session.createdAt || '');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (session.__provider === 'codex') {
|
||||||
|
return String(session.createdAt || session.lastActivity || '');
|
||||||
|
}
|
||||||
|
|
||||||
|
return String(session.lastActivity || session.createdAt || '');
|
||||||
};
|
};
|
||||||
|
|
||||||
export const createSessionViewModel = (
|
export const createSessionViewModel = (
|
||||||
|
|||||||
@@ -75,10 +75,6 @@ function Sidebar({
|
|||||||
sessionDeleteConfirmation,
|
sessionDeleteConfirmation,
|
||||||
showVersionModal,
|
showVersionModal,
|
||||||
filteredProjects,
|
filteredProjects,
|
||||||
archivedProjects,
|
|
||||||
archivedSessions,
|
|
||||||
archivedSessionsCount,
|
|
||||||
isArchivedSessionsLoading,
|
|
||||||
toggleProject,
|
toggleProject,
|
||||||
handleSessionClick,
|
handleSessionClick,
|
||||||
toggleStarProject,
|
toggleStarProject,
|
||||||
@@ -94,9 +90,6 @@ function Sidebar({
|
|||||||
requestProjectDelete,
|
requestProjectDelete,
|
||||||
confirmDeleteProject,
|
confirmDeleteProject,
|
||||||
handleProjectSelect,
|
handleProjectSelect,
|
||||||
openArchivedSession,
|
|
||||||
restoreArchivedProject,
|
|
||||||
restoreArchivedSession,
|
|
||||||
refreshProjects,
|
refreshProjects,
|
||||||
updateSessionSummary,
|
updateSessionSummary,
|
||||||
collapseSidebar: handleCollapseSidebar,
|
collapseSidebar: handleCollapseSidebar,
|
||||||
@@ -191,8 +184,8 @@ function Sidebar({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<SidebarModals
|
<SidebarModals
|
||||||
projects={projects}
|
projects={projects}
|
||||||
showSettings={showSettings}
|
showSettings={showSettings}
|
||||||
settingsInitialTab={settingsInitialTab}
|
settingsInitialTab={settingsInitialTab}
|
||||||
onCloseSettings={onCloseSettings}
|
onCloseSettings={onCloseSettings}
|
||||||
@@ -224,38 +217,22 @@ function Sidebar({
|
|||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
<SidebarContent
|
<SidebarContent
|
||||||
isPWA={isPWA}
|
isPWA={isPWA}
|
||||||
isMobile={isMobile}
|
isMobile={isMobile}
|
||||||
isLoading={isLoading}
|
isLoading={isLoading}
|
||||||
projects={projects}
|
projects={projects}
|
||||||
archivedProjects={archivedProjects}
|
|
||||||
archivedSessions={archivedSessions}
|
|
||||||
archivedSessionsCount={archivedSessionsCount}
|
|
||||||
isArchivedSessionsLoading={isArchivedSessionsLoading}
|
|
||||||
searchFilter={searchFilter}
|
searchFilter={searchFilter}
|
||||||
onSearchFilterChange={setSearchFilter}
|
onSearchFilterChange={setSearchFilter}
|
||||||
onClearSearchFilter={() => setSearchFilter('')}
|
onClearSearchFilter={() => setSearchFilter('')}
|
||||||
searchMode={searchMode}
|
searchMode={searchMode}
|
||||||
onSearchModeChange={(mode) => {
|
onSearchModeChange={(mode: 'projects' | 'conversations') => {
|
||||||
setSearchMode(mode);
|
setSearchMode(mode);
|
||||||
if (mode === 'projects') clearConversationResults();
|
if (mode === 'projects') clearConversationResults();
|
||||||
}}
|
}}
|
||||||
conversationResults={conversationResults}
|
conversationResults={conversationResults}
|
||||||
isSearching={isSearching}
|
isSearching={isSearching}
|
||||||
searchProgress={searchProgress}
|
searchProgress={searchProgress}
|
||||||
onRestoreArchivedProject={restoreArchivedProject}
|
|
||||||
onArchivedSessionClick={openArchivedSession}
|
|
||||||
onRestoreArchivedSession={restoreArchivedSession}
|
|
||||||
onDeleteArchivedSession={(session) => {
|
|
||||||
showDeleteSessionConfirmation(
|
|
||||||
session.projectId,
|
|
||||||
session.sessionId,
|
|
||||||
session.sessionTitle,
|
|
||||||
session.provider,
|
|
||||||
{ isArchived: true },
|
|
||||||
);
|
|
||||||
}}
|
|
||||||
onConversationResultClick={(projectId: string | null, sessionId: string, provider: string, messageTimestamp?: string | null, messageSnippet?: string | null) => {
|
onConversationResultClick={(projectId: string | null, sessionId: string, provider: string, messageTimestamp?: string | null, messageSnippet?: string | null) => {
|
||||||
// `projectId` (DB key) is the canonical identifier post-migration.
|
// `projectId` (DB key) is the canonical identifier post-migration.
|
||||||
// The server emits null when it can't resolve a project row for
|
// The server emits null when it can't resolve a project row for
|
||||||
|
|||||||
@@ -1,16 +1,15 @@
|
|||||||
import { type ReactNode } from 'react';
|
import { type ReactNode } from 'react';
|
||||||
import { Archive, Folder, MessageSquare, RotateCcw, Search, Trash2 } from 'lucide-react';
|
import { Folder, MessageSquare, Search } from 'lucide-react';
|
||||||
import type { TFunction } from 'i18next';
|
import type { TFunction } from 'i18next';
|
||||||
import { ScrollArea } from '../../../../shared/view/ui';
|
import { ScrollArea } from '../../../../shared/view/ui';
|
||||||
import type { Project } from '../../../../types/app';
|
import type { Project } from '../../../../types/app';
|
||||||
import type { ReleaseInfo } from '../../../../types/sharedTypes';
|
import type { ReleaseInfo } from '../../../../types/sharedTypes';
|
||||||
import type { ConversationSearchResults, SearchProgress } from '../../hooks/useSidebarController';
|
import type { ConversationSearchResults, SearchProgress } from '../../hooks/useSidebarController';
|
||||||
import type { ArchivedProjectListItem, ArchivedSessionListItem, SidebarSearchMode } from '../../types/types';
|
|
||||||
import SessionProviderLogo from '../../../llm-logo-provider/SessionProviderLogo';
|
|
||||||
import SidebarFooter from './SidebarFooter';
|
import SidebarFooter from './SidebarFooter';
|
||||||
import SidebarHeader from './SidebarHeader';
|
import SidebarHeader from './SidebarHeader';
|
||||||
import SidebarProjectList, { type SidebarProjectListProps } from './SidebarProjectList';
|
import SidebarProjectList, { type SidebarProjectListProps } from './SidebarProjectList';
|
||||||
import { getAllSessions } from '../../utils/utils';
|
|
||||||
|
type SearchMode = 'projects' | 'conversations';
|
||||||
|
|
||||||
function HighlightedSnippet({ snippet, highlights }: { snippet: string; highlights: { start: number; end: number }[] }) {
|
function HighlightedSnippet({ snippet, highlights }: { snippet: string; highlights: { start: number; end: number }[] }) {
|
||||||
const parts: ReactNode[] = [];
|
const parts: ReactNode[] = [];
|
||||||
@@ -36,100 +35,19 @@ function HighlightedSnippet({ snippet, highlights }: { snippet: string; highligh
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
type ArchivedSessionGroup = {
|
|
||||||
key: string;
|
|
||||||
projectId: string | null;
|
|
||||||
projectDisplayName: string;
|
|
||||||
projectPath: string | null;
|
|
||||||
isProjectArchived: boolean;
|
|
||||||
sessions: ArchivedSessionListItem[];
|
|
||||||
latestActivity: string | null;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Groups archived sessions by project metadata so the archive view preserves
|
|
||||||
* the same mental model as the active sidebar: projects first, then sessions.
|
|
||||||
*/
|
|
||||||
function groupArchivedSessionsByProject(sessions: ArchivedSessionListItem[]): ArchivedSessionGroup[] {
|
|
||||||
const groups = new Map<string, ArchivedSessionGroup>();
|
|
||||||
|
|
||||||
for (const session of sessions) {
|
|
||||||
const key = session.projectId ?? session.projectPath ?? `session:${session.sessionId}`;
|
|
||||||
const existingGroup = groups.get(key);
|
|
||||||
|
|
||||||
if (existingGroup) {
|
|
||||||
existingGroup.sessions.push(session);
|
|
||||||
if (!existingGroup.latestActivity || (session.lastActivity && session.lastActivity > existingGroup.latestActivity)) {
|
|
||||||
existingGroup.latestActivity = session.lastActivity;
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
groups.set(key, {
|
|
||||||
key,
|
|
||||||
projectId: session.projectId,
|
|
||||||
projectDisplayName: session.projectDisplayName,
|
|
||||||
projectPath: session.projectPath,
|
|
||||||
isProjectArchived: session.isProjectArchived,
|
|
||||||
sessions: [session],
|
|
||||||
latestActivity: session.lastActivity,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return [...groups.values()].sort((groupA, groupB) => {
|
|
||||||
const a = groupA.latestActivity ?? '';
|
|
||||||
const b = groupB.latestActivity ?? '';
|
|
||||||
return b.localeCompare(a);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function formatCompactArchivedAge(dateString: string | null): string {
|
|
||||||
if (!dateString) {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
const date = new Date(dateString);
|
|
||||||
if (Number.isNaN(date.getTime())) {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
const diffInMinutes = Math.floor(Math.max(0, Date.now() - date.getTime()) / (1000 * 60));
|
|
||||||
if (diffInMinutes < 1) {
|
|
||||||
return '<1m';
|
|
||||||
}
|
|
||||||
if (diffInMinutes < 60) {
|
|
||||||
return `${diffInMinutes}m`;
|
|
||||||
}
|
|
||||||
|
|
||||||
const diffInHours = Math.floor(diffInMinutes / 60);
|
|
||||||
if (diffInHours < 24) {
|
|
||||||
return `${diffInHours}hr`;
|
|
||||||
}
|
|
||||||
|
|
||||||
return `${Math.floor(diffInHours / 24)}d`;
|
|
||||||
}
|
|
||||||
|
|
||||||
type SidebarContentProps = {
|
type SidebarContentProps = {
|
||||||
isPWA: boolean;
|
isPWA: boolean;
|
||||||
isMobile: boolean;
|
isMobile: boolean;
|
||||||
isLoading: boolean;
|
isLoading: boolean;
|
||||||
projects: Project[];
|
projects: Project[];
|
||||||
archivedProjects: ArchivedProjectListItem[];
|
|
||||||
archivedSessions: ArchivedSessionListItem[];
|
|
||||||
archivedSessionsCount: number;
|
|
||||||
isArchivedSessionsLoading: boolean;
|
|
||||||
searchFilter: string;
|
searchFilter: string;
|
||||||
onSearchFilterChange: (value: string) => void;
|
onSearchFilterChange: (value: string) => void;
|
||||||
onClearSearchFilter: () => void;
|
onClearSearchFilter: () => void;
|
||||||
searchMode: SidebarSearchMode;
|
searchMode: SearchMode;
|
||||||
onSearchModeChange: (mode: SidebarSearchMode) => void;
|
onSearchModeChange: (mode: SearchMode) => void;
|
||||||
conversationResults: ConversationSearchResults | null;
|
conversationResults: ConversationSearchResults | null;
|
||||||
isSearching: boolean;
|
isSearching: boolean;
|
||||||
searchProgress: SearchProgress | null;
|
searchProgress: SearchProgress | null;
|
||||||
onRestoreArchivedProject: (projectId: string) => void;
|
|
||||||
onArchivedSessionClick: (session: ArchivedSessionListItem) => void;
|
|
||||||
onRestoreArchivedSession: (sessionId: string) => void;
|
|
||||||
onDeleteArchivedSession: (session: ArchivedSessionListItem) => void;
|
|
||||||
// Conversation result clicks pass back the DB projectId (or null when the
|
// Conversation result clicks pass back the DB projectId (or null when the
|
||||||
// server couldn't resolve it). Consumers must handle the null case.
|
// server couldn't resolve it). Consumers must handle the null case.
|
||||||
onConversationResultClick: (projectId: string | null, sessionId: string, provider: string, messageTimestamp?: string | null, messageSnippet?: string | null) => void;
|
onConversationResultClick: (projectId: string | null, sessionId: string, provider: string, messageTimestamp?: string | null, messageSnippet?: string | null) => void;
|
||||||
@@ -152,10 +70,6 @@ export default function SidebarContent({
|
|||||||
isMobile,
|
isMobile,
|
||||||
isLoading,
|
isLoading,
|
||||||
projects,
|
projects,
|
||||||
archivedProjects,
|
|
||||||
archivedSessions,
|
|
||||||
archivedSessionsCount,
|
|
||||||
isArchivedSessionsLoading,
|
|
||||||
searchFilter,
|
searchFilter,
|
||||||
onSearchFilterChange,
|
onSearchFilterChange,
|
||||||
onClearSearchFilter,
|
onClearSearchFilter,
|
||||||
@@ -164,10 +78,6 @@ export default function SidebarContent({
|
|||||||
conversationResults,
|
conversationResults,
|
||||||
isSearching,
|
isSearching,
|
||||||
searchProgress,
|
searchProgress,
|
||||||
onRestoreArchivedProject,
|
|
||||||
onArchivedSessionClick,
|
|
||||||
onRestoreArchivedSession,
|
|
||||||
onDeleteArchivedSession,
|
|
||||||
onConversationResultClick,
|
onConversationResultClick,
|
||||||
onRefresh,
|
onRefresh,
|
||||||
isRefreshing,
|
isRefreshing,
|
||||||
@@ -184,7 +94,6 @@ export default function SidebarContent({
|
|||||||
}: SidebarContentProps) {
|
}: SidebarContentProps) {
|
||||||
const showConversationSearch = searchMode === 'conversations' && searchFilter.trim().length >= 2;
|
const showConversationSearch = searchMode === 'conversations' && searchFilter.trim().length >= 2;
|
||||||
const hasPartialResults = conversationResults && conversationResults.results.length > 0;
|
const hasPartialResults = conversationResults && conversationResults.results.length > 0;
|
||||||
const groupedArchivedSessions = groupArchivedSessionsByProject(archivedSessions);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
@@ -196,8 +105,6 @@ export default function SidebarContent({
|
|||||||
isMobile={isMobile}
|
isMobile={isMobile}
|
||||||
isLoading={isLoading}
|
isLoading={isLoading}
|
||||||
projectsCount={projects.length}
|
projectsCount={projects.length}
|
||||||
archivedSessionsCount={archivedSessionsCount}
|
|
||||||
isArchivedSessionsLoading={isArchivedSessionsLoading}
|
|
||||||
searchFilter={searchFilter}
|
searchFilter={searchFilter}
|
||||||
onSearchFilterChange={onSearchFilterChange}
|
onSearchFilterChange={onSearchFilterChange}
|
||||||
onClearSearchFilter={onClearSearchFilter}
|
onClearSearchFilter={onClearSearchFilter}
|
||||||
@@ -307,207 +214,6 @@ export default function SidebarContent({
|
|||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
) : null
|
) : null
|
||||||
) : searchMode === 'archived' ? (
|
|
||||||
isArchivedSessionsLoading ? (
|
|
||||||
<div className="px-4 py-12 text-center md:py-8">
|
|
||||||
<div className="mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-lg bg-muted md:mb-3">
|
|
||||||
<div className="h-6 w-6 animate-spin rounded-full border-2 border-muted-foreground border-t-transparent" />
|
|
||||||
</div>
|
|
||||||
<h3 className="mb-2 text-base font-medium text-foreground md:mb-1">
|
|
||||||
{t('archived.loadingTitle', 'Loading archive...')}
|
|
||||||
</h3>
|
|
||||||
<p className="text-sm text-muted-foreground">
|
|
||||||
{t('archived.loadingDescription', 'Fetching hidden workspaces and sessions you can restore later.')}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
) : archivedProjects.length === 0 && groupedArchivedSessions.length === 0 ? (
|
|
||||||
<div className="px-4 py-12 text-center md:py-8">
|
|
||||||
<div className="mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-lg bg-muted md:mb-3">
|
|
||||||
<Archive className="h-6 w-6 text-muted-foreground" />
|
|
||||||
</div>
|
|
||||||
<h3 className="mb-2 text-base font-medium text-foreground md:mb-1">
|
|
||||||
{archivedSessionsCount > 0
|
|
||||||
? t('archived.noMatchingSessions', 'No matching archived items')
|
|
||||||
: t('archived.emptyTitle', 'No archived items')}
|
|
||||||
</h3>
|
|
||||||
<p className="text-sm text-muted-foreground">
|
|
||||||
{archivedSessionsCount > 0
|
|
||||||
? t('archived.tryDifferentSearch', 'Try a different search term.')
|
|
||||||
: t('archived.emptyDescription', 'Archived workspaces and sessions will appear here when you hide them from the active list.')}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
) : (
|
|
||||||
<div className="space-y-3 px-2">
|
|
||||||
<div className="flex items-center justify-between px-1">
|
|
||||||
<p className="text-xs text-muted-foreground">
|
|
||||||
{`${archivedSessionsCount} ${t(
|
|
||||||
archivedSessionsCount === 1 ? 'archived.sessionCountOne' : 'archived.sessionCountOther',
|
|
||||||
archivedSessionsCount === 1 ? 'archived item' : 'archived items',
|
|
||||||
)}`}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
{archivedProjects.map((project) => {
|
|
||||||
const projectSessions = getAllSessions(project);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div key={project.projectId} className="overflow-hidden rounded-xl border border-border/70 bg-card/60 shadow-sm">
|
|
||||||
<div className="flex items-start justify-between gap-3 border-b border-border/60 px-3 py-2.5">
|
|
||||||
<div className="min-w-0">
|
|
||||||
<div className="flex items-center gap-2">
|
|
||||||
<Folder className="h-3.5 w-3.5 flex-shrink-0 text-muted-foreground" />
|
|
||||||
<span className="truncate text-sm font-medium text-foreground">
|
|
||||||
{project.displayName}
|
|
||||||
</span>
|
|
||||||
<span className="inline-flex items-center justify-center rounded-full bg-muted px-1 py-px text-[7px] font-medium uppercase leading-none tracking-[0.02em] text-center text-muted-foreground">
|
|
||||||
{t('archived.projectArchived', 'Project archived')}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<p className="mt-1 truncate text-xs text-muted-foreground/70" title={project.fullPath}>
|
|
||||||
{project.fullPath}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<button
|
|
||||||
className="flex h-7 w-7 flex-shrink-0 items-center justify-center rounded-lg bg-emerald-50 text-emerald-700 transition-colors hover:bg-emerald-100 dark:bg-emerald-900/20 dark:text-emerald-300 dark:hover:bg-emerald-900/30"
|
|
||||||
onClick={() => onRestoreArchivedProject(project.projectId)}
|
|
||||||
title={t('archived.restoreProject', 'Restore workspace')}
|
|
||||||
>
|
|
||||||
<RotateCcw className="h-3.5 w-3.5" />
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
{projectSessions.length > 0 && (
|
|
||||||
<div className="divide-y divide-border/50">
|
|
||||||
{projectSessions.map((session) => (
|
|
||||||
<button
|
|
||||||
key={String(session.id)}
|
|
||||||
className="flex w-full items-center gap-2 px-3 py-2.5 text-left transition-colors hover:bg-accent/40"
|
|
||||||
onClick={() => onArchivedSessionClick({
|
|
||||||
sessionId: String(session.id),
|
|
||||||
provider: session.__provider,
|
|
||||||
projectId: project.projectId,
|
|
||||||
projectPath: project.fullPath,
|
|
||||||
projectDisplayName: project.displayName,
|
|
||||||
sessionTitle:
|
|
||||||
(typeof session.summary === 'string' && session.summary.trim().length > 0
|
|
||||||
? session.summary
|
|
||||||
: typeof session.name === 'string' && session.name.trim().length > 0
|
|
||||||
? session.name
|
|
||||||
: String(session.id)),
|
|
||||||
createdAt: typeof session.created_at === 'string' ? session.created_at : null,
|
|
||||||
updatedAt: typeof session.updated_at === 'string' ? session.updated_at : null,
|
|
||||||
lastActivity:
|
|
||||||
typeof session.lastActivity === 'string'
|
|
||||||
? session.lastActivity
|
|
||||||
: typeof session.updated_at === 'string'
|
|
||||||
? session.updated_at
|
|
||||||
: typeof session.created_at === 'string'
|
|
||||||
? session.created_at
|
|
||||||
: null,
|
|
||||||
isProjectArchived: true,
|
|
||||||
})}
|
|
||||||
>
|
|
||||||
<SessionProviderLogo provider={session.__provider} className="h-3.5 w-3.5 flex-shrink-0" />
|
|
||||||
<div className="min-w-0 flex-1">
|
|
||||||
<div className="flex items-center gap-2">
|
|
||||||
<span className="truncate text-xs font-medium text-foreground">
|
|
||||||
{(typeof session.summary === 'string' && session.summary.trim().length > 0
|
|
||||||
? session.summary
|
|
||||||
: typeof session.name === 'string' && session.name.trim().length > 0
|
|
||||||
? session.name
|
|
||||||
: String(session.id))}
|
|
||||||
</span>
|
|
||||||
<span className="ml-auto flex-shrink-0 text-[11px] text-muted-foreground">
|
|
||||||
{formatCompactArchivedAge(
|
|
||||||
typeof session.lastActivity === 'string'
|
|
||||||
? session.lastActivity
|
|
||||||
: typeof session.updated_at === 'string'
|
|
||||||
? session.updated_at
|
|
||||||
: typeof session.created_at === 'string'
|
|
||||||
? session.created_at
|
|
||||||
: null,
|
|
||||||
)}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<p className="mt-0.5 text-[11px] uppercase tracking-wide text-muted-foreground/70">
|
|
||||||
{session.__provider}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</button>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
{groupedArchivedSessions.map((group) => (
|
|
||||||
<div key={group.key} className="overflow-hidden rounded-xl border border-border/70 bg-card/60 shadow-sm">
|
|
||||||
<div className="flex items-start justify-between gap-3 border-b border-border/60 px-3 py-2.5">
|
|
||||||
<div className="min-w-0">
|
|
||||||
<div className="flex items-center gap-2">
|
|
||||||
<Folder className="h-3.5 w-3.5 flex-shrink-0 text-muted-foreground" />
|
|
||||||
<span className="truncate text-sm font-medium text-foreground">
|
|
||||||
{group.projectDisplayName}
|
|
||||||
</span>
|
|
||||||
{group.isProjectArchived && (
|
|
||||||
<span className="inline-flex items-center justify-center rounded-full bg-muted px-1 py-px text-[7px] font-medium uppercase leading-none tracking-[0.02em] text-center text-muted-foreground">
|
|
||||||
{t('archived.projectArchived', 'Project archived')}
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
{group.projectPath && (
|
|
||||||
<p className="mt-1 truncate text-xs text-muted-foreground/70" title={group.projectPath}>
|
|
||||||
{group.projectPath}
|
|
||||||
</p>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
<span className="flex-shrink-0 text-[11px] text-muted-foreground">
|
|
||||||
{group.sessions.length}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<div className="divide-y divide-border/50">
|
|
||||||
{group.sessions.map((session) => (
|
|
||||||
<div key={session.sessionId} className="flex items-center gap-2 px-3 py-2.5">
|
|
||||||
<button
|
|
||||||
className="flex min-w-0 flex-1 items-center gap-2 text-left transition-colors hover:text-foreground"
|
|
||||||
onClick={() => onArchivedSessionClick(session)}
|
|
||||||
>
|
|
||||||
<SessionProviderLogo provider={session.provider} className="h-3.5 w-3.5 flex-shrink-0" />
|
|
||||||
<div className="min-w-0 flex-1">
|
|
||||||
<div className="flex items-center gap-2">
|
|
||||||
<span className="truncate text-xs font-medium text-foreground">
|
|
||||||
{session.sessionTitle}
|
|
||||||
</span>
|
|
||||||
{session.lastActivity && (
|
|
||||||
<span className="ml-auto flex-shrink-0 text-[11px] text-muted-foreground">
|
|
||||||
{formatCompactArchivedAge(session.lastActivity)}
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
<p className="mt-0.5 text-[11px] uppercase tracking-wide text-muted-foreground/70">
|
|
||||||
{session.provider}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</button>
|
|
||||||
<button
|
|
||||||
className="flex h-7 w-7 flex-shrink-0 items-center justify-center rounded-lg bg-emerald-50 text-emerald-700 transition-colors hover:bg-emerald-100 dark:bg-emerald-900/20 dark:text-emerald-300 dark:hover:bg-emerald-900/30"
|
|
||||||
onClick={() => onRestoreArchivedSession(session.sessionId)}
|
|
||||||
title={t('archived.restore', 'Restore session')}
|
|
||||||
>
|
|
||||||
<RotateCcw className="h-3.5 w-3.5" />
|
|
||||||
</button>
|
|
||||||
<button
|
|
||||||
className="flex h-7 w-7 flex-shrink-0 items-center justify-center rounded-lg bg-red-50 text-red-700 transition-colors hover:bg-red-100 dark:bg-red-900/20 dark:text-red-300 dark:hover:bg-red-900/30"
|
|
||||||
onClick={() => onDeleteArchivedSession(session)}
|
|
||||||
title={t('archived.deletePermanently', 'Delete permanently')}
|
|
||||||
>
|
|
||||||
<Trash2 className="h-3.5 w-3.5" />
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
) : (
|
) : (
|
||||||
<SidebarProjectList {...projectListProps} />
|
<SidebarProjectList {...projectListProps} />
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -1,26 +1,25 @@
|
|||||||
import { Archive, Folder, FolderPlus, MessageSquare, Plus, RefreshCw, Search, X, PanelLeftClose } from 'lucide-react';
|
import { Folder, FolderPlus, MessageSquare, Plus, RefreshCw, Search, X, PanelLeftClose } from 'lucide-react';
|
||||||
import type { TFunction } from 'i18next';
|
import type { TFunction } from 'i18next';
|
||||||
import { Button, Input, Tooltip } from '../../../../shared/view/ui';
|
import { Button, Input } from '../../../../shared/view/ui';
|
||||||
import { IS_PLATFORM } from '../../../../constants/config';
|
import { IS_PLATFORM } from '../../../../constants/config';
|
||||||
import { cn } from '../../../../lib/utils';
|
import { cn } from '../../../../lib/utils';
|
||||||
import type { SidebarSearchMode } from '../../types/types';
|
|
||||||
import GitHubStarBadge from './GitHubStarBadge';
|
import GitHubStarBadge from './GitHubStarBadge';
|
||||||
|
|
||||||
const MOD_KEY =
|
const MOD_KEY =
|
||||||
typeof navigator !== 'undefined' && /Mac|iPhone|iPad/.test(navigator.platform) ? '⌘' : 'Ctrl';
|
typeof navigator !== 'undefined' && /Mac|iPhone|iPad/.test(navigator.platform) ? '⌘' : 'Ctrl';
|
||||||
|
|
||||||
|
type SearchMode = 'projects' | 'conversations';
|
||||||
|
|
||||||
type SidebarHeaderProps = {
|
type SidebarHeaderProps = {
|
||||||
isPWA: boolean;
|
isPWA: boolean;
|
||||||
isMobile: boolean;
|
isMobile: boolean;
|
||||||
isLoading: boolean;
|
isLoading: boolean;
|
||||||
projectsCount: number;
|
projectsCount: number;
|
||||||
archivedSessionsCount: number;
|
|
||||||
isArchivedSessionsLoading: boolean;
|
|
||||||
searchFilter: string;
|
searchFilter: string;
|
||||||
onSearchFilterChange: (value: string) => void;
|
onSearchFilterChange: (value: string) => void;
|
||||||
onClearSearchFilter: () => void;
|
onClearSearchFilter: () => void;
|
||||||
searchMode: SidebarSearchMode;
|
searchMode: SearchMode;
|
||||||
onSearchModeChange: (mode: SidebarSearchMode) => void;
|
onSearchModeChange: (mode: SearchMode) => void;
|
||||||
onRefresh: () => void;
|
onRefresh: () => void;
|
||||||
isRefreshing: boolean;
|
isRefreshing: boolean;
|
||||||
onCreateProject: () => void;
|
onCreateProject: () => void;
|
||||||
@@ -33,8 +32,6 @@ export default function SidebarHeader({
|
|||||||
isMobile,
|
isMobile,
|
||||||
isLoading,
|
isLoading,
|
||||||
projectsCount,
|
projectsCount,
|
||||||
archivedSessionsCount,
|
|
||||||
isArchivedSessionsLoading,
|
|
||||||
searchFilter,
|
searchFilter,
|
||||||
onSearchFilterChange,
|
onSearchFilterChange,
|
||||||
onClearSearchFilter,
|
onClearSearchFilter,
|
||||||
@@ -46,13 +43,6 @@ export default function SidebarHeader({
|
|||||||
onCollapseSidebar,
|
onCollapseSidebar,
|
||||||
t,
|
t,
|
||||||
}: SidebarHeaderProps) {
|
}: SidebarHeaderProps) {
|
||||||
const showSearchTools = (projectsCount > 0 || archivedSessionsCount > 0 || isArchivedSessionsLoading) && !isLoading;
|
|
||||||
const searchPlaceholder = searchMode === 'conversations'
|
|
||||||
? t('search.conversationsPlaceholder')
|
|
||||||
: searchMode === 'archived'
|
|
||||||
? t('search.archivedPlaceholder', 'Search archived sessions...')
|
|
||||||
: t('projects.searchPlaceholder');
|
|
||||||
|
|
||||||
const LogoBlock = () => (
|
const LogoBlock = () => (
|
||||||
<div className="flex min-w-0 items-center gap-2.5">
|
<div className="flex min-w-0 items-center gap-2.5">
|
||||||
<div className="flex h-7 w-7 flex-shrink-0 items-center justify-center rounded-lg bg-primary/90 shadow-sm">
|
<div className="flex h-7 w-7 flex-shrink-0 items-center justify-center rounded-lg bg-primary/90 shadow-sm">
|
||||||
@@ -123,7 +113,7 @@ export default function SidebarHeader({
|
|||||||
<GitHubStarBadge />
|
<GitHubStarBadge />
|
||||||
|
|
||||||
{/* Search bar */}
|
{/* Search bar */}
|
||||||
{showSearchTools && (
|
{projectsCount > 0 && !isLoading && (
|
||||||
<div className="mt-2.5 space-y-2">
|
<div className="mt-2.5 space-y-2">
|
||||||
{/* Search mode toggle */}
|
{/* Search mode toggle */}
|
||||||
<div className="flex rounded-lg bg-muted/50 p-0.5">
|
<div className="flex rounded-lg bg-muted/50 p-0.5">
|
||||||
@@ -153,28 +143,12 @@ export default function SidebarHeader({
|
|||||||
<MessageSquare className="h-3 w-3" />
|
<MessageSquare className="h-3 w-3" />
|
||||||
{t('search.modeConversations')}
|
{t('search.modeConversations')}
|
||||||
</button>
|
</button>
|
||||||
<Tooltip content={t('search.archiveOnlyTooltip', 'Archive only')} position="top">
|
|
||||||
<button
|
|
||||||
onClick={() => onSearchModeChange('archived')}
|
|
||||||
aria-pressed={searchMode === 'archived'}
|
|
||||||
aria-label={t('search.archiveOnlyTooltip', 'Archive only')}
|
|
||||||
title={t('search.archiveOnlyTooltip', 'Archive only')}
|
|
||||||
className={cn(
|
|
||||||
"flex items-center justify-center rounded-md px-2.5 py-1.5 text-xs font-medium transition-all",
|
|
||||||
searchMode === 'archived'
|
|
||||||
? "bg-background shadow-sm text-foreground"
|
|
||||||
: "text-muted-foreground hover:text-foreground"
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
<Archive className="h-3 w-3" />
|
|
||||||
</button>
|
|
||||||
</Tooltip>
|
|
||||||
</div>
|
</div>
|
||||||
<div className="relative">
|
<div className="relative">
|
||||||
<Search className="pointer-events-none absolute left-3 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground/50" />
|
<Search className="pointer-events-none absolute left-3 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground/50" />
|
||||||
<Input
|
<Input
|
||||||
type="text"
|
type="text"
|
||||||
placeholder={searchPlaceholder}
|
placeholder={searchMode === 'conversations' ? t('search.conversationsPlaceholder') : t('projects.searchPlaceholder')}
|
||||||
value={searchFilter}
|
value={searchFilter}
|
||||||
onChange={(event) => onSearchFilterChange(event.target.value)}
|
onChange={(event) => onSearchFilterChange(event.target.value)}
|
||||||
className="nav-search-input h-9 rounded-xl border-0 pl-9 pr-14 text-sm transition-all duration-200 placeholder:text-muted-foreground/40 focus-visible:ring-0 focus-visible:ring-offset-0"
|
className="nav-search-input h-9 rounded-xl border-0 pl-9 pr-14 text-sm transition-all duration-200 placeholder:text-muted-foreground/40 focus-visible:ring-0 focus-visible:ring-offset-0"
|
||||||
@@ -241,7 +215,7 @@ export default function SidebarHeader({
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Mobile search */}
|
{/* Mobile search */}
|
||||||
{showSearchTools && (
|
{projectsCount > 0 && !isLoading && (
|
||||||
<div className="mt-2.5 space-y-2">
|
<div className="mt-2.5 space-y-2">
|
||||||
<div className="flex rounded-lg bg-muted/50 p-0.5">
|
<div className="flex rounded-lg bg-muted/50 p-0.5">
|
||||||
<button
|
<button
|
||||||
@@ -270,28 +244,12 @@ export default function SidebarHeader({
|
|||||||
<MessageSquare className="h-3 w-3" />
|
<MessageSquare className="h-3 w-3" />
|
||||||
{t('search.modeConversations')}
|
{t('search.modeConversations')}
|
||||||
</button>
|
</button>
|
||||||
<Tooltip content={t('search.archiveOnlyTooltip', 'Archive only')} position="top">
|
|
||||||
<button
|
|
||||||
onClick={() => onSearchModeChange('archived')}
|
|
||||||
aria-pressed={searchMode === 'archived'}
|
|
||||||
aria-label={t('search.archiveOnlyTooltip', 'Archive only')}
|
|
||||||
title={t('search.archiveOnlyTooltip', 'Archive only')}
|
|
||||||
className={cn(
|
|
||||||
"flex items-center justify-center rounded-md px-2.5 py-1.5 text-xs font-medium transition-all",
|
|
||||||
searchMode === 'archived'
|
|
||||||
? "bg-background shadow-sm text-foreground"
|
|
||||||
: "text-muted-foreground hover:text-foreground"
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
<Archive className="h-3 w-3" />
|
|
||||||
</button>
|
|
||||||
</Tooltip>
|
|
||||||
</div>
|
</div>
|
||||||
<div className="relative">
|
<div className="relative">
|
||||||
<Search className="pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground/50" />
|
<Search className="pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground/50" />
|
||||||
<Input
|
<Input
|
||||||
type="text"
|
type="text"
|
||||||
placeholder={searchPlaceholder}
|
placeholder={searchMode === 'conversations' ? t('search.conversationsPlaceholder') : t('projects.searchPlaceholder')}
|
||||||
value={searchFilter}
|
value={searchFilter}
|
||||||
onChange={(event) => onSearchFilterChange(event.target.value)}
|
onChange={(event) => onSearchFilterChange(event.target.value)}
|
||||||
className="nav-search-input h-10 rounded-xl border-0 pl-10 pr-9 text-sm transition-all duration-200 placeholder:text-muted-foreground/40 focus-visible:ring-0 focus-visible:ring-offset-0"
|
className="nav-search-input h-10 rounded-xl border-0 pl-10 pr-9 text-sm transition-all duration-200 placeholder:text-muted-foreground/40 focus-visible:ring-0 focus-visible:ring-offset-0"
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ type SidebarModalsProps = {
|
|||||||
onConfirmDeleteProject: (deleteData?: boolean) => void;
|
onConfirmDeleteProject: (deleteData?: boolean) => void;
|
||||||
sessionDeleteConfirmation: SessionDeleteConfirmation | null;
|
sessionDeleteConfirmation: SessionDeleteConfirmation | null;
|
||||||
onCancelDeleteSession: () => void;
|
onCancelDeleteSession: () => void;
|
||||||
onConfirmDeleteSession: (hardDelete?: boolean) => void;
|
onConfirmDeleteSession: () => void;
|
||||||
showVersionModal: boolean;
|
showVersionModal: boolean;
|
||||||
onCloseVersionModal: () => void;
|
onCloseVersionModal: () => void;
|
||||||
releaseInfo: ReleaseInfo | null;
|
releaseInfo: ReleaseInfo | null;
|
||||||
@@ -133,7 +133,7 @@ export default function SidebarModals({
|
|||||||
onClick={() => onConfirmDeleteProject(false)}
|
onClick={() => onConfirmDeleteProject(false)}
|
||||||
>
|
>
|
||||||
<EyeOff className="mr-2 h-4 w-4" />
|
<EyeOff className="mr-2 h-4 w-4" />
|
||||||
{t('deleteConfirmation.archiveProject', 'Archive project')}
|
{t('deleteConfirmation.removeFromSidebar')}
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
variant="destructive"
|
variant="destructive"
|
||||||
@@ -173,34 +173,22 @@ export default function SidebarModals({
|
|||||||
?
|
?
|
||||||
</p>
|
</p>
|
||||||
<p className="mt-3 text-xs text-muted-foreground">
|
<p className="mt-3 text-xs text-muted-foreground">
|
||||||
{sessionDeleteConfirmation.isArchived
|
{t('deleteConfirmation.cannotUndo')}
|
||||||
? t('deleteConfirmation.archivedSessionNotice', 'This session is already archived. You can keep it hidden or delete it permanently.')
|
|
||||||
: t('deleteConfirmation.archiveSessionNotice', 'Archive keeps the session out of the active list while preserving its history.')}
|
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex flex-col gap-2 border-t border-border bg-muted/30 p-4">
|
<div className="flex gap-3 border-t border-border bg-muted/30 p-4">
|
||||||
{!sessionDeleteConfirmation.isArchived && (
|
<Button variant="outline" className="flex-1" onClick={onCancelDeleteSession}>
|
||||||
<Button
|
{t('actions.cancel')}
|
||||||
variant="outline"
|
</Button>
|
||||||
className="w-full justify-start"
|
|
||||||
onClick={() => onConfirmDeleteSession(false)}
|
|
||||||
>
|
|
||||||
<EyeOff className="mr-2 h-4 w-4" />
|
|
||||||
{t('deleteConfirmation.archiveSession', 'Archive session')}
|
|
||||||
</Button>
|
|
||||||
)}
|
|
||||||
<Button
|
<Button
|
||||||
variant="destructive"
|
variant="destructive"
|
||||||
className="w-full justify-start bg-red-600 text-white hover:bg-red-700"
|
className="flex-1 bg-red-600 text-white hover:bg-red-700"
|
||||||
onClick={() => onConfirmDeleteSession(true)}
|
onClick={onConfirmDeleteSession}
|
||||||
>
|
>
|
||||||
<Trash2 className="mr-2 h-4 w-4" />
|
<Trash2 className="mr-2 h-4 w-4" />
|
||||||
{t('deleteConfirmation.deleteSessionPermanently', 'Delete permanently')}
|
{t('actions.delete')}
|
||||||
</Button>
|
|
||||||
<Button variant="ghost" className="w-full" onClick={onCancelDeleteSession}>
|
|
||||||
{t('actions.cancel')}
|
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -239,7 +239,7 @@ export default function SidebarSessionItem({
|
|||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
requestDeleteSession();
|
requestDeleteSession();
|
||||||
}}
|
}}
|
||||||
title={t('tooltips.deleteSessionOptions', 'Archive or permanently delete this session')}
|
title={t('tooltips.deleteSession')}
|
||||||
>
|
>
|
||||||
<Trash2 className="h-3 w-3 text-red-600 dark:text-red-400" />
|
<Trash2 className="h-3 w-3 text-red-600 dark:text-red-400" />
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@@ -435,7 +435,9 @@ export function useProjectsState({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const hasActiveSession = Boolean(selectedSession && activeSessions.has(selectedSession.id));
|
const hasActiveSession =
|
||||||
|
(selectedSession && activeSessions.has(selectedSession.id)) ||
|
||||||
|
(activeSessions.size > 0 && Array.from(activeSessions).some((id) => id.startsWith('new-session-')));
|
||||||
|
|
||||||
const updatedProjectsWithTaskMaster = mergeTaskMasterCache(projectsMessage.projects, projects);
|
const updatedProjectsWithTaskMaster = mergeTaskMasterCache(projectsMessage.projects, projects);
|
||||||
const updatedProjects = mergeExpandedSessionPages(projects, updatedProjectsWithTaskMaster);
|
const updatedProjects = mergeExpandedSessionPages(projects, updatedProjectsWithTaskMaster);
|
||||||
|
|||||||
@@ -44,6 +44,23 @@ export function useSessionProtection() {
|
|||||||
});
|
});
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
const replaceTemporarySession = useCallback((realSessionId?: string | null) => {
|
||||||
|
if (!realSessionId) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setActiveSessions((prev) => {
|
||||||
|
const next = new Set<string>();
|
||||||
|
for (const sessionId of prev) {
|
||||||
|
if (!sessionId.startsWith('new-session-')) {
|
||||||
|
next.add(sessionId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
next.add(realSessionId);
|
||||||
|
return next;
|
||||||
|
});
|
||||||
|
}, []);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
activeSessions,
|
activeSessions,
|
||||||
processingSessions,
|
processingSessions,
|
||||||
@@ -51,5 +68,6 @@ export function useSessionProtection() {
|
|||||||
markSessionAsInactive,
|
markSessionAsInactive,
|
||||||
markSessionAsProcessing,
|
markSessionAsProcessing,
|
||||||
markSessionAsNotProcessing,
|
markSessionAsNotProcessing,
|
||||||
|
replaceTemporarySession,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,20 +40,6 @@ export interface NormalizedMessage {
|
|||||||
// kind-specific fields (flat for simplicity)
|
// kind-specific fields (flat for simplicity)
|
||||||
role?: 'user' | 'assistant';
|
role?: 'user' | 'assistant';
|
||||||
content?: string;
|
content?: string;
|
||||||
/**
|
|
||||||
* Mirrors optional transcript metadata from the server.
|
|
||||||
*
|
|
||||||
* These fields are currently used by Claude history normalization so local
|
|
||||||
* slash commands, local stdout, and compact summaries do not disappear when
|
|
||||||
* the session store hydrates from REST history.
|
|
||||||
*/
|
|
||||||
displayText?: string;
|
|
||||||
commandName?: string;
|
|
||||||
commandMessage?: string;
|
|
||||||
commandArgs?: string;
|
|
||||||
isLocalCommand?: boolean;
|
|
||||||
isLocalCommandStdout?: boolean;
|
|
||||||
isCompactSummary?: boolean;
|
|
||||||
images?: string[];
|
images?: string[];
|
||||||
toolName?: string;
|
toolName?: string;
|
||||||
toolInput?: unknown;
|
toolInput?: unknown;
|
||||||
|
|||||||
@@ -54,7 +54,6 @@ export const api = {
|
|||||||
// After the projectName → projectId migration the path/query identifier is
|
// After the projectName → projectId migration the path/query identifier is
|
||||||
// the DB-assigned `projectId`; parameter names reflect that for clarity.
|
// the DB-assigned `projectId`; parameter names reflect that for clarity.
|
||||||
projects: () => authenticatedFetch('/api/projects'),
|
projects: () => authenticatedFetch('/api/projects'),
|
||||||
archivedProjects: () => authenticatedFetch('/api/projects/archived'),
|
|
||||||
projectSessions: (projectId, { limit = 20, offset = 0 } = {}) => {
|
projectSessions: (projectId, { limit = 20, offset = 0 } = {}) => {
|
||||||
const params = new URLSearchParams();
|
const params = new URLSearchParams();
|
||||||
params.set('limit', String(limit));
|
params.set('limit', String(limit));
|
||||||
@@ -79,28 +78,9 @@ export const api = {
|
|||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
body: JSON.stringify({ displayName }),
|
body: JSON.stringify({ displayName }),
|
||||||
}),
|
}),
|
||||||
restoreProject: (projectId) =>
|
deleteSession: (sessionId) =>
|
||||||
authenticatedFetch(`/api/projects/${encodeURIComponent(projectId)}/restore`, {
|
authenticatedFetch(`/api/providers/sessions/${sessionId}`, {
|
||||||
method: 'POST',
|
|
||||||
}),
|
|
||||||
// Session deletion now mirrors project deletion:
|
|
||||||
// - default: archive only (`isArchived = 1`)
|
|
||||||
// - hardDelete: remove the row and, by default, its persisted transcript file
|
|
||||||
deleteSession: (sessionId, hardDelete = false) => {
|
|
||||||
const params = new URLSearchParams();
|
|
||||||
if (hardDelete) {
|
|
||||||
params.set('force', 'true');
|
|
||||||
}
|
|
||||||
const qs = params.toString();
|
|
||||||
return authenticatedFetch(`/api/providers/sessions/${sessionId}${qs ? `?${qs}` : ''}`, {
|
|
||||||
method: 'DELETE',
|
method: 'DELETE',
|
||||||
});
|
|
||||||
},
|
|
||||||
getArchivedSessions: () =>
|
|
||||||
authenticatedFetch('/api/providers/sessions/archived'),
|
|
||||||
restoreSession: (sessionId) =>
|
|
||||||
authenticatedFetch(`/api/providers/sessions/${sessionId}/restore`, {
|
|
||||||
method: 'POST',
|
|
||||||
}),
|
}),
|
||||||
renameSession: (sessionId, summary) =>
|
renameSession: (sessionId, summary) =>
|
||||||
authenticatedFetch(`/api/providers/sessions/${sessionId}`, {
|
authenticatedFetch(`/api/providers/sessions/${sessionId}`, {
|
||||||
|
|||||||
Reference in New Issue
Block a user