this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat(tools): add parse_brain_dump tool

Extracts tasks and ideas from free-form text using heuristics:
- Recognizes task prefixes (-, *, TODO, numbers)
- Identifies action verbs indicating tasks
- Returns structured items array for agent processing

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

alice e9637ca8 9d4904a2

+154
+154
src/tools/capture.ts
··· 1 + /** 2 + * Capture tools for parsing and extracting structured data from brain dumps 3 + * 4 + * Implements the parse_brain_dump tool that extracts tasks and ideas 5 + * from free-form text input. 6 + */ 7 + 8 + import { registerTool, type ToolDefinition } from './dispatcher'; 9 + import { db, schema } from '../db'; 10 + 11 + /** 12 + * Arguments for parse_brain_dump tool 13 + */ 14 + export interface ParseBrainDumpArgs { 15 + /** Raw brain dump text from user */ 16 + text: string; 17 + } 18 + 19 + /** 20 + * Result from parse_brain_dump tool 21 + */ 22 + export interface ParseBrainDumpResult { 23 + /** Extracted tasks with their IDs */ 24 + tasks: { 25 + id: string; 26 + content: string; 27 + priority: number; 28 + }[]; 29 + /** Extracted ideas with their IDs */ 30 + ideas: { 31 + id: string; 32 + content: string; 33 + }[]; 34 + } 35 + 36 + /** 37 + * Parse brain dump text to extract tasks and ideas 38 + * 39 + * Uses simple heuristics for M2: 40 + * - Lines starting with "- ", "* ", "TODO", numbers, or action verbs are tasks 41 + * - Other lines are ideas 42 + * - Strips common prefixes and cleans up text 43 + */ 44 + function parseBrainDump(text: string): { tasks: string[]; ideas: string[] } { 45 + const lines = text 46 + .split('\n') 47 + .map((line) => line.trim()) 48 + .filter((line) => line.length > 0); 49 + 50 + const tasks: string[] = []; 51 + const ideas: string[] = []; 52 + 53 + // Common task prefixes to strip 54 + const taskPrefixes = [/^-\s+/, /^\*\s+/, /^\d+[).]\s+/, /^TODO:?\s*/i, /^TASK:?\s*/i]; 55 + 56 + // Action verbs that indicate tasks 57 + const actionVerbs = 58 + /^(add|create|implement|fix|update|write|build|test|review|refactor|delete|remove|setup|configure|install|deploy|investigate|research|learn|study|call|email|message|buy|order|schedule|plan|organize|clean|finish|complete|start|begin)\b/i; 59 + 60 + for (const line of lines) { 61 + let content = line; 62 + let isTask = false; 63 + 64 + // Check for task prefixes 65 + for (const prefix of taskPrefixes) { 66 + if (prefix.test(content)) { 67 + content = content.replace(prefix, ''); 68 + isTask = true; 69 + break; 70 + } 71 + } 72 + 73 + // If no prefix matched, check for action verbs 74 + if (!isTask && actionVerbs.test(content)) { 75 + isTask = true; 76 + } 77 + 78 + // Clean up content 79 + content = content.trim(); 80 + 81 + if (content.length > 0) { 82 + if (isTask) { 83 + tasks.push(content); 84 + } else { 85 + ideas.push(content); 86 + } 87 + } 88 + } 89 + 90 + return { tasks, ideas }; 91 + } 92 + 93 + /** 94 + * parse_brain_dump tool handler 95 + * 96 + * Extracts structured tasks and ideas from raw text and saves them to the database. 97 + */ 98 + export const parseBrainDumpTool: ToolDefinition<ParseBrainDumpArgs, ParseBrainDumpResult> = registerTool({ 99 + name: 'parse_brain_dump', 100 + description: 'Extract tasks and ideas from a free-form brain dump text. Saves extracted items to database.', 101 + parameters: { 102 + type: 'object', 103 + properties: { 104 + text: { 105 + type: 'string', 106 + description: 'Raw brain dump text from user', 107 + }, 108 + }, 109 + required: ['text'], 110 + }, 111 + handler: async (args, context) => { 112 + const { text } = args; 113 + const { userId } = context; 114 + 115 + // Parse the brain dump 116 + const { tasks: taskTexts, ideas: ideaTexts } = parseBrainDump(text); 117 + 118 + // Save tasks to database 119 + const tasks: ParseBrainDumpResult['tasks'] = []; 120 + for (const content of taskTexts) { 121 + const id = crypto.randomUUID(); 122 + await db.insert(schema.items).values({ 123 + id, 124 + userId, 125 + type: 'task', 126 + content, 127 + status: 'open', 128 + priority: 2, // Default medium priority 129 + parentId: null, 130 + }); 131 + tasks.push({ id, content, priority: 2 }); 132 + } 133 + 134 + // Save ideas to database 135 + const ideas: ParseBrainDumpResult['ideas'] = []; 136 + for (const content of ideaTexts) { 137 + const id = crypto.randomUUID(); 138 + await db.insert(schema.items).values({ 139 + id, 140 + userId, 141 + type: 'brain_dump', 142 + content, 143 + status: 'open', 144 + priority: 2, 145 + parentId: null, 146 + }); 147 + ideas.push({ id, content }); 148 + } 149 + 150 + console.log(`Parsed brain dump: ${String(tasks.length)} tasks, ${String(ideas.length)} ideas`); 151 + 152 + return { tasks, ideas }; 153 + }, 154 + });