From de58e9ede50d2ed91899b2d53e4b030e9d2e7bca Mon Sep 17 00:00:00 2001 From: Eyal Toledano Date: Sun, 25 May 2025 17:33:00 -0400 Subject: [PATCH] feat(fuzzy): improves fuzzy search to introspect into subtasks as well. might still need improvement. --- scripts/modules/task-manager/research.js | 40 +++++++++++++++++++++++- scripts/modules/utils/fuzzyTaskSearch.js | 6 +++- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/scripts/modules/task-manager/research.js b/scripts/modules/task-manager/research.js index 42e783e5..e8ca9315 100644 --- a/scripts/modules/task-manager/research.js +++ b/scripts/modules/task-manager/research.js @@ -100,7 +100,9 @@ async function performResearch( const tasksData = await readJSON(tasksPath); if (tasksData && tasksData.tasks && tasksData.tasks.length > 0) { - const fuzzySearch = new FuzzyTaskSearch(tasksData.tasks, 'research'); + // Flatten tasks to include subtasks for fuzzy search + const flattenedTasks = flattenTasksWithSubtasks(tasksData.tasks); + const fuzzySearch = new FuzzyTaskSearch(flattenedTasks, 'research'); const searchResults = fuzzySearch.findRelevantTasks(query, { maxResults: 8, includeRecent: true, @@ -561,4 +563,40 @@ function displayResearchResults(result, query, detailLevel, tokenBreakdown) { console.log(chalk.green('✅ Research completed')); } +/** + * Flatten tasks array to include subtasks as individual searchable items + * @param {Array} tasks - Array of task objects + * @returns {Array} Flattened array including both tasks and subtasks + */ +function flattenTasksWithSubtasks(tasks) { + const flattened = []; + + for (const task of tasks) { + // Add the main task + flattened.push({ + ...task, + searchableId: task.id.toString(), // For consistent ID handling + isSubtask: false + }); + + // Add subtasks if they exist + if (task.subtasks && task.subtasks.length > 0) { + for (const subtask of task.subtasks) { + flattened.push({ + ...subtask, + searchableId: `${task.id}.${subtask.id}`, // Format: "15.2" + isSubtask: true, + parentId: task.id, + parentTitle: task.title, + // Enhance subtask context with parent information + title: `${subtask.title} (subtask of: ${task.title})`, + description: `${subtask.description} [Parent: ${task.description}]` + }); + } + } + } + + return flattened; +} + export { performResearch }; diff --git a/scripts/modules/utils/fuzzyTaskSearch.js b/scripts/modules/utils/fuzzyTaskSearch.js index a533d35e..c8fcac2f 100644 --- a/scripts/modules/utils/fuzzyTaskSearch.js +++ b/scripts/modules/utils/fuzzyTaskSearch.js @@ -276,7 +276,11 @@ export class FuzzyTaskSearch { * @returns {Array} Array of task ID strings */ getTaskIds(searchResults) { - return searchResults.results.map((task) => task.id.toString()); + return searchResults.results.map((task) => { + // Use searchableId if available (for flattened tasks with subtasks) + // Otherwise fall back to regular id + return task.searchableId || task.id.toString(); + }); } /**