fix(multi-cli): populate multiCliPlan sessions in liteTaskDataStore

Fix task click handlers not working in multi-CLI planning detail page.

Root cause: liteTaskDataStore was not being populated with multiCliPlan
sessions during initialization, so task click handlers couldn't access
session data using currentSessionDetailKey.

Changes:
- navigation.js: Add code to populate multiCliPlan sessions in liteTaskDataStore
- notifications.js: Add code to populate multiCliPlan sessions when data refreshes

Now when task detail page loads, liteTaskDataStore contains the correct key
'multi-cli-${sessionId}' matching currentSessionDetailKey, allowing task
click handlers to find session data and open detail drawer.

Verified: Task clicks now properly open detail panel for all 7 tasks.
This commit is contained in:
catlog22
2026-01-22 15:41:01 +08:00
parent f0954b3247
commit ea04663035
22 changed files with 921 additions and 83 deletions

View File

@@ -13,20 +13,16 @@
import { spawn } from 'child_process';
import { join, dirname } from 'path';
import { homedir } from 'os';
import { existsSync } from 'fs';
import { fileURLToPath } from 'url';
import { getCodexLensPython } from '../utils/codexlens-path.js';
// Get directory of this module
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
// Venv paths (reuse CodexLens venv)
const CODEXLENS_VENV = join(homedir(), '.codexlens', 'venv');
const VENV_PYTHON =
process.platform === 'win32'
? join(CODEXLENS_VENV, 'Scripts', 'python.exe')
: join(CODEXLENS_VENV, 'bin', 'python');
const VENV_PYTHON = getCodexLensPython();
// Script path
const EMBEDDER_SCRIPT = join(__dirname, '..', '..', 'scripts', 'memory_embedder.py');

View File

@@ -16,6 +16,7 @@ import type { RouteContext } from '../types.js';
import { EXEC_TIMEOUTS } from '../../../utils/exec-constants.js';
import { extractJSON } from './utils.js';
import { stopWatcherForUninstall } from './watcher-handlers.js';
import { getCodexLensDataDir } from '../../../utils/codexlens-path.js';
export async function handleCodexLensConfigRoutes(ctx: RouteContext): Promise<boolean> {
const { pathname, url, req, res, initialPath, handlePostRequest, broadcastToClients } = ctx;
@@ -777,7 +778,7 @@ export async function handleCodexLensConfigRoutes(ctx: RouteContext): Promise<bo
const { join } = await import('path');
const { readFile } = await import('fs/promises');
const envPath = join(homedir(), '.codexlens', '.env');
const envPath = join(getCodexLensDataDir(), '.env');
let content = '';
try {
content = await readFile(envPath, 'utf-8');
@@ -829,7 +830,7 @@ export async function handleCodexLensConfigRoutes(ctx: RouteContext): Promise<bo
}
// Also read settings.json for current configuration
const settingsPath = join(homedir(), '.codexlens', 'settings.json');
const settingsPath = join(getCodexLensDataDir(), 'settings.json');
let settings: Record<string, any> = {};
try {
const settingsContent = await readFile(settingsPath, 'utf-8');
@@ -943,7 +944,7 @@ export async function handleCodexLensConfigRoutes(ctx: RouteContext): Promise<bo
const { join, dirname } = await import('path');
const { writeFile, mkdir, readFile } = await import('fs/promises');
const envPath = join(homedir(), '.codexlens', '.env');
const envPath = join(getCodexLensDataDir(), '.env');
await mkdir(dirname(envPath), { recursive: true });
// Read existing env file to preserve custom variables
@@ -1072,7 +1073,7 @@ export async function handleCodexLensConfigRoutes(ctx: RouteContext): Promise<bo
await writeFile(envPath, lines.join('\n'), 'utf-8');
// Also update settings.json with mapped values
const settingsPath = join(homedir(), '.codexlens', 'settings.json');
const settingsPath = join(getCodexLensDataDir(), 'settings.json');
let settings: Record<string, any> = {};
try {
const settingsContent = await readFile(settingsPath, 'utf-8');
@@ -1145,7 +1146,7 @@ export async function handleCodexLensConfigRoutes(ctx: RouteContext): Promise<bo
const { join } = await import('path');
const { readFile } = await import('fs/promises');
const settingsPath = join(homedir(), '.codexlens', 'settings.json');
const settingsPath = join(getCodexLensDataDir(), 'settings.json');
let settings: Record<string, any> = {};
try {
const content = await readFile(settingsPath, 'utf-8');
@@ -1214,7 +1215,7 @@ export async function handleCodexLensConfigRoutes(ctx: RouteContext): Promise<bo
const { join, dirname } = await import('path');
const { writeFile, mkdir, readFile } = await import('fs/promises');
const settingsPath = join(homedir(), '.codexlens', 'settings.json');
const settingsPath = join(getCodexLensDataDir(), 'settings.json');
await mkdir(dirname(settingsPath), { recursive: true });
// Read existing settings

View File

@@ -17,6 +17,7 @@ import {
import type { RouteContext } from '../types.js';
import { extractJSON } from './utils.js';
import { getDefaultTool } from '../../../tools/claude-cli-tools.js';
import { getCodexLensDataDir } from '../../../utils/codexlens-path.js';
export async function handleCodexLensSemanticRoutes(ctx: RouteContext): Promise<boolean> {
const { pathname, url, req, res, initialPath, handlePostRequest } = ctx;
@@ -445,9 +446,8 @@ export async function handleCodexLensSemanticRoutes(ctx: RouteContext): Promise<
// Write to CodexLens .env file for persistence
const { writeFileSync, existsSync, readFileSync } = await import('fs');
const { join } = await import('path');
const { homedir } = await import('os');
const codexlensDir = join(homedir(), '.codexlens');
const codexlensDir = getCodexLensDataDir();
const envFile = join(codexlensDir, '.env');
// Read existing .env content

View File

@@ -2,13 +2,29 @@
* Graph Routes Module
* Handles graph visualization API endpoints for codex-lens data
*/
import { homedir } from 'os';
import { join, resolve, normalize } from 'path';
import { existsSync, readdirSync } from 'fs';
import Database from 'better-sqlite3';
import { validatePath as validateAllowedPath } from '../../utils/path-validator.js';
import type { RouteContext } from './types.js';
/**
* Get the index root directory from CodexLens config or default.
* Matches Python implementation priority:
* 1. CODEXLENS_INDEX_DIR environment variable
* 2. index_dir from ~/.codexlens/config.json
* 3. Default: ~/.codexlens/indexes
*/
function getIndexRoot(): string {
const envOverride = process.env.CODEXLENS_INDEX_DIR;
if (envOverride) {
return envOverride;
}
// Default: use CodexLens data directory + indexes
const { getCodexLensDataDir } = require('../../utils/codexlens-path.js');
return join(getCodexLensDataDir(), 'indexes');
}
/**
* PathMapper utility class (simplified from codex-lens Python implementation)
* Maps source paths to index database paths
@@ -17,7 +33,7 @@ class PathMapper {
private indexRoot: string;
constructor(indexRoot?: string) {
this.indexRoot = indexRoot || join(homedir(), '.codexlens', 'indexes');
this.indexRoot = indexRoot || getIndexRoot();
}
/**

View File

@@ -992,6 +992,188 @@ export async function handleIssueRoutes(ctx: RouteContext): Promise<boolean> {
return true;
}
// POST /api/issues/pull - Pull issues from GitHub
if (pathname === '/api/issues/pull' && req.method === 'POST') {
const state = url.searchParams.get('state') || 'open';
const limit = parseInt(url.searchParams.get('limit') || '100');
const labels = url.searchParams.get('labels') || '';
const downloadImages = url.searchParams.get('downloadImages') === 'true';
try {
const { execSync } = await import('child_process');
const https = await import('https');
const http = await import('http');
// Check if gh CLI is available
try {
execSync('gh --version', { stdio: 'ignore', timeout: 5000 });
} catch {
res.writeHead(500, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({ error: 'GitHub CLI (gh) is not installed or not in PATH' }));
return true;
}
// Build gh command
let ghCommand = `gh issue list --state ${state} --limit ${limit} --json number,title,body,labels,url,state`;
if (labels) ghCommand += ` --label "${labels}"`;
// Execute gh command from project root
const ghOutput = execSync(ghCommand, {
encoding: 'utf-8',
stdio: ['pipe', 'pipe', 'pipe'],
timeout: 60000,
cwd: issuesDir.replace(/[\\/]\.workflow[\\/]issues$/, '')
}).trim();
if (!ghOutput) {
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({ imported: 0, updated: 0, skipped: 0, images_downloaded: 0 }));
return true;
}
const ghIssues = JSON.parse(ghOutput);
const existingIssues = readIssuesJsonl(issuesDir);
let imported = 0;
let skipped = 0;
let updated = 0;
let imagesDownloaded = 0;
// Create images directory if needed
const imagesDir = join(issuesDir, 'images');
if (downloadImages && !existsSync(imagesDir)) {
mkdirSync(imagesDir, { recursive: true });
}
// Helper function to download image
const downloadImage = async (imageUrl: string, issueNumber: number, imageIndex: number): Promise<string | null> => {
return new Promise((resolveDownload) => {
try {
const ext = imageUrl.match(/\.(png|jpg|jpeg|gif|webp|svg)/i)?.[1] || 'png';
const filename = `GH-${issueNumber}-${imageIndex}.${ext}`;
const filePath = join(imagesDir, filename);
// Skip if already downloaded
if (existsSync(filePath)) {
resolveDownload(`.workflow/issues/images/${filename}`);
return;
}
const protocol = imageUrl.startsWith('https') ? https : http;
protocol.get(imageUrl, { timeout: 30000 }, (response: any) => {
// Handle redirect
if (response.statusCode === 301 || response.statusCode === 302) {
const redirectUrl = response.headers.location;
if (redirectUrl) {
downloadImage(redirectUrl, issueNumber, imageIndex).then(resolveDownload);
return;
}
}
if (response.statusCode !== 200) {
resolveDownload(null);
return;
}
const chunks: Buffer[] = [];
response.on('data', (chunk: Buffer) => chunks.push(chunk));
response.on('end', () => {
try {
writeFileSync(filePath, Buffer.concat(chunks));
resolveDownload(`.workflow/issues/images/${filename}`);
} catch {
resolveDownload(null);
}
});
response.on('error', () => resolveDownload(null));
}).on('error', () => resolveDownload(null));
} catch {
resolveDownload(null);
}
});
};
// Process issues
for (const ghIssue of ghIssues) {
const issueId = `GH-${ghIssue.number}`;
const existingIssue = existingIssues.find((i: any) => i.id === issueId);
let context = ghIssue.body || ghIssue.title;
// Extract and download images if enabled
if (downloadImages && ghIssue.body) {
// Find all image URLs in the body
const imgPattern = /!\[[^\]]*\]\((https?:\/\/[^)]+)\)|<img[^>]+src=["'](https?:\/\/[^"']+)["']/gi;
const imageUrls: string[] = [];
let match;
while ((match = imgPattern.exec(ghIssue.body)) !== null) {
imageUrls.push(match[1] || match[2]);
}
// Download images and build reference list
if (imageUrls.length > 0) {
const downloadedImages: string[] = [];
for (let i = 0; i < imageUrls.length; i++) {
const localPath = await downloadImage(imageUrls[i], ghIssue.number, i + 1);
if (localPath) {
downloadedImages.push(localPath);
imagesDownloaded++;
}
}
// Append image references to context
if (downloadedImages.length > 0) {
context += '\n\n---\n**Downloaded Images:**\n';
downloadedImages.forEach((path, idx) => {
context += `- Image ${idx + 1}: \`${path}\`\n`;
});
}
}
}
// Prepare issue data (truncate context to 2000 chars max)
const issueData = {
id: issueId,
title: ghIssue.title,
status: ghIssue.state === 'OPEN' ? 'registered' : 'completed',
priority: 3,
context: context.substring(0, 2000),
source: 'github',
source_url: ghIssue.url,
tags: ghIssue.labels?.map((l: any) => l.name) || [],
created_at: new Date().toISOString(),
updated_at: new Date().toISOString()
};
if (existingIssue) {
// Update if changed
const newStatus = ghIssue.state === 'OPEN' ? 'registered' : 'completed';
if (existingIssue.status !== newStatus || existingIssue.title !== ghIssue.title) {
existingIssue.title = ghIssue.title;
existingIssue.status = newStatus;
existingIssue.context = issueData.context;
existingIssue.updated_at = new Date().toISOString();
updated++;
} else {
skipped++;
}
} else {
existingIssues.push(issueData);
imported++;
}
}
// Save all issues
writeIssuesJsonl(issuesDir, existingIssues);
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({ imported, updated, skipped, images_downloaded: imagesDownloaded, total: ghIssues.length }));
} catch (err: any) {
res.writeHead(500, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({ error: err.message || 'Failed to pull issues from GitHub' }));
}
return true;
}
// GET /api/issues/:id - Get issue detail
const detailMatch = pathname.match(/^\/api\/issues\/([^/]+)$/);
if (detailMatch && req.method === 'GET') {

View File

@@ -37,6 +37,38 @@ import { TaskStorageManager, type TaskCreateRequest, type TaskUpdateRequest, typ
import { executeCliTool } from '../../tools/cli-executor.js';
import { loadClaudeCliTools } from '../../tools/claude-cli-tools.js';
/**
* Module-level cache for CLI tools configuration
* Loaded once at server startup to avoid repeated file I/O
*/
let cachedEnabledTools: string[] | null = null;
/**
* Initialize CLI tools cache at server startup
* Should be called once when the server starts
*/
export function initializeCliToolsCache(): void {
try {
const cliToolsConfig = loadClaudeCliTools(os.homedir());
const enabledTools = Object.entries(cliToolsConfig.tools || {})
.filter(([_, config]) => config.enabled === true)
.map(([name]) => name);
cachedEnabledTools = ['bash', ...enabledTools];
console.log('[Loop V2] CLI tools cache initialized:', cachedEnabledTools);
} catch (err) {
console.error('[Loop V2] Failed to initialize CLI tools cache:', err);
// Fallback to basic tools if config loading fails
cachedEnabledTools = ['bash', 'gemini', 'qwen', 'codex', 'claude'];
}
}
/**
* Clear CLI tools cache (for testing or config reload)
*/
export function clearCliToolsCache(): void {
cachedEnabledTools = null;
}
/**
* V2 Loop Create Request
*/
@@ -1314,14 +1346,19 @@ function isValidId(id: string): boolean {
}
/**
* Get enabled tools list
* Get enabled tools list from cache
* If cache is not initialized, it will load from config (fallback for lazy initialization)
*/
function getEnabledToolsList(): string[] {
const cliToolsConfig = loadClaudeCliTools(os.homedir());
const enabledTools = Object.entries(cliToolsConfig.tools || {})
.filter(([_, config]) => config.enabled === true)
.map(([name]) => name);
return ['bash', ...enabledTools];
// Return cached value if available
if (cachedEnabledTools) {
return cachedEnabledTools;
}
// Fallback: lazy initialization if cache not initialized (shouldn't happen in normal operation)
console.warn('[Loop V2] CLI tools cache not initialized, performing lazy load');
initializeCliToolsCache();
return cachedEnabledTools || ['bash', 'gemini', 'qwen', 'codex', 'claude'];
}
/**