Add tests and implement functionality for staged cascade search and LSP expansion

- Introduced a new JSON file for verbose output of the Codex Lens search results.
- Added unit tests for binary search functionality in `test_stage1_binary_search_uses_chunk_lines.py`.
- Implemented regression tests for staged cascade Stage 2 expansion depth in `test_staged_cascade_lsp_depth.py`.
- Created unit tests for staged cascade Stage 2 realtime LSP graph expansion in `test_staged_cascade_realtime_lsp.py`.
- Enhanced the ChainSearchEngine to respect configuration settings for staged LSP depth and improve search accuracy.
This commit is contained in:
catlog22
2026-02-08 21:54:42 +08:00
parent 166211dcd4
commit b9b2932f50
20 changed files with 1882 additions and 283 deletions

View File

@@ -439,6 +439,119 @@ export async function handleSystemRoutes(ctx: SystemRouteContext): Promise<boole
return true;
}
// API: Native OS folder selection dialog
if (pathname === '/api/dialog/select-folder' && req.method === 'POST') {
handlePostRequest(req, res, async (body) => {
const { initialDir } = body as { initialDir?: string };
const os = await import('os');
const { execFile } = await import('child_process');
const startDir = initialDir || os.homedir();
return new Promise<Record<string, unknown>>((resolve) => {
if (process.platform === 'win32') {
const script = `Add-Type -AssemblyName System.Windows.Forms; $d = New-Object System.Windows.Forms.FolderBrowserDialog; $d.SelectedPath = '${startDir.replace(/'/g, "''")}'; $d.ShowNewFolderButton = $true; if ($d.ShowDialog() -eq 'OK') { $d.SelectedPath }`;
execFile('powershell', ['-NoProfile', '-Command', script],
{ timeout: 120000 },
(err, stdout) => {
if (err || !stdout.trim()) {
resolve({ cancelled: true });
} else {
resolve({ path: stdout.trim() });
}
}
);
} else if (process.platform === 'darwin') {
const escapedDir = startDir.replace(/"/g, '\\"');
const script = `POSIX path of (choose folder with prompt "Select Project Folder" default location POSIX file "${escapedDir}")`;
execFile('osascript', ['-e', script],
{ timeout: 120000 },
(err, stdout) => {
if (err || !stdout.trim()) {
resolve({ cancelled: true });
} else {
resolve({ path: stdout.trim().replace(/\/$/, '') });
}
}
);
} else {
// Linux: try zenity, fallback to kdialog
execFile('zenity', ['--file-selection', '--directory', '--title=Select Project Folder', `--filename=${startDir}/`],
{ timeout: 120000 },
(err, stdout) => {
if (err || !stdout.trim()) {
execFile('kdialog', ['--getexistingdirectory', startDir, '--title', 'Select Project Folder'],
{ timeout: 120000 },
(err2, stdout2) => {
resolve(err2 || !stdout2.trim() ? { cancelled: true } : { path: stdout2.trim() });
}
);
} else {
resolve({ path: stdout.trim() });
}
}
);
}
});
});
return true;
}
// API: Native OS file selection dialog
if (pathname === '/api/dialog/select-file' && req.method === 'POST') {
handlePostRequest(req, res, async (body) => {
const { initialDir } = body as { initialDir?: string };
const os = await import('os');
const { execFile } = await import('child_process');
const startDir = initialDir || os.homedir();
return new Promise<Record<string, unknown>>((resolve) => {
if (process.platform === 'win32') {
const script = `Add-Type -AssemblyName System.Windows.Forms; $d = New-Object System.Windows.Forms.OpenFileDialog; $d.InitialDirectory = '${startDir.replace(/'/g, "''")}'; if ($d.ShowDialog() -eq 'OK') { $d.FileName }`;
execFile('powershell', ['-NoProfile', '-Command', script],
{ timeout: 120000 },
(err, stdout) => {
if (err || !stdout.trim()) {
resolve({ cancelled: true });
} else {
resolve({ path: stdout.trim() });
}
}
);
} else if (process.platform === 'darwin') {
const escapedDir = startDir.replace(/"/g, '\\"');
const script = `POSIX path of (choose file with prompt "Select File" default location POSIX file "${escapedDir}")`;
execFile('osascript', ['-e', script],
{ timeout: 120000 },
(err, stdout) => {
if (err || !stdout.trim()) {
resolve({ cancelled: true });
} else {
resolve({ path: stdout.trim() });
}
}
);
} else {
execFile('zenity', ['--file-selection', '--title=Select File', `--filename=${startDir}/`],
{ timeout: 120000 },
(err, stdout) => {
if (err || !stdout.trim()) {
execFile('kdialog', ['--getopenfilename', startDir, '--title', 'Select File'],
{ timeout: 120000 },
(err2, stdout2) => {
resolve(err2 || !stdout2.trim() ? { cancelled: true } : { path: stdout2.trim() });
}
);
} else {
resolve({ path: stdout.trim() });
}
}
);
}
});
});
return true;
}
// API: File dialog - list directory contents for file browser
if (pathname === '/api/dialog/browse' && req.method === 'POST') {
handlePostRequest(req, res, async (body) => {