feat: Implement association tree for LSP-based code relationship discovery

- Add `association_tree` module with components for building and processing call association trees using LSP call hierarchy capabilities.
- Introduce `AssociationTreeBuilder` for constructing call trees from seed locations with depth-first expansion.
- Create data structures: `TreeNode`, `CallTree`, and `UniqueNode` for representing nodes and relationships in the call tree.
- Implement `ResultDeduplicator` to extract unique nodes from call trees and assign relevance scores based on depth, frequency, and kind.
- Add unit tests for `AssociationTreeBuilder` and `ResultDeduplicator` to ensure functionality and correctness.
This commit is contained in:
catlog22
2026-01-20 22:09:04 +08:00
parent b85d9b9eb1
commit 261c98549d
21 changed files with 2826 additions and 94 deletions

View File

@@ -72,6 +72,44 @@ export function getActiveExecutions(): ActiveExecution[] {
return Array.from(activeExecutions.values());
}
/**
* Update active execution state from hook events
* Called by hooks-routes when CLI events are received from terminal execution
*/
export function updateActiveExecution(event: {
type: 'started' | 'output' | 'completed';
executionId: string;
tool?: string;
mode?: string;
prompt?: string;
output?: string;
success?: boolean;
}): void {
const { type, executionId, tool, mode, prompt, output, success } = event;
if (type === 'started') {
// Create new active execution
activeExecutions.set(executionId, {
id: executionId,
tool: tool || 'unknown',
mode: mode || 'analysis',
prompt: (prompt || '').substring(0, 500),
startTime: Date.now(),
output: '',
status: 'running'
});
} else if (type === 'output') {
// Append output to existing execution
const activeExec = activeExecutions.get(executionId);
if (activeExec && output) {
activeExec.output += output;
}
} else if (type === 'completed') {
// Remove from active executions
activeExecutions.delete(executionId);
}
}
/**
* Handle CLI routes
* @returns true if route was handled, false otherwise

View File

@@ -266,6 +266,37 @@ export async function handleHooksRoutes(ctx: HooksRouteContext): Promise<boolean
}
}
// Update active executions state for CLI streaming events (terminal execution)
if (type === 'CLI_EXECUTION_STARTED' || type === 'CLI_OUTPUT' || type === 'CLI_EXECUTION_COMPLETED') {
try {
const { updateActiveExecution } = await import('./cli-routes.js');
if (type === 'CLI_EXECUTION_STARTED') {
updateActiveExecution({
type: 'started',
executionId: String(extraData.executionId || ''),
tool: String(extraData.tool || 'unknown'),
mode: String(extraData.mode || 'analysis'),
prompt: String(extraData.prompt_preview || '')
});
} else if (type === 'CLI_OUTPUT') {
updateActiveExecution({
type: 'output',
executionId: String(extraData.executionId || ''),
output: String(extraData.data || '')
});
} else if (type === 'CLI_EXECUTION_COMPLETED') {
updateActiveExecution({
type: 'completed',
executionId: String(extraData.executionId || ''),
success: Boolean(extraData.success)
});
}
} catch (err) {
console.error('[Hooks] Failed to update active execution:', err);
}
}
// Broadcast to all connected WebSocket clients
const notification = {
type: typeof type === 'string' && type.trim().length > 0 ? type : 'session_updated',

View File

@@ -170,7 +170,13 @@ function getIssueDetail(issuesDir: string, issueId: string) {
const issues = readIssuesJsonl(issuesDir);
let issue = issues.find(i => i.id === issueId);
// Fallback: Reconstruct issue from solution file if issue not in issues.jsonl
// Fix: Check history if not found in active issues
if (!issue) {
const historyIssues = readIssueHistoryJsonl(issuesDir);
issue = historyIssues.find(i => i.id === issueId);
}
// Fallback: Reconstruct issue from solution file if issue not in issues.jsonl or history
if (!issue) {
const solutionPath = join(issuesDir, 'solutions', `${issueId}.jsonl`);
if (existsSync(solutionPath)) {
@@ -948,7 +954,8 @@ export async function handleIssueRoutes(ctx: RouteContext): Promise<boolean> {
// GET /api/issues/history - List completed issues from history
if (pathname === '/api/issues/history' && req.method === 'GET') {
const history = readIssueHistoryJsonl(issuesDir);
// Fix: Use enrichIssues to add solution/task counts to historical issues
const history = enrichIssues(readIssueHistoryJsonl(issuesDir), issuesDir);
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({
issues: history,