import type { CaptureIntent } from "./types"; export interface CaptureIntentDecision { intent: CaptureIntent; confidence: number; durability: "temporary" | "task" | "project" | "long_term"; global_cues: string[]; project_cues: string[]; applicability: string[]; reasons: string[]; } function normalize(text: string): string { return text .replace(/em[ -]?dashes?/gi, "em dash") .replace(/en[ -]?dashes?/gi, "en dash") .replace(/\s+/g, " ") .trim(); } function applicability(text: string): string[] { const lower = text.toLowerCase(); const values: string[] = []; if (/\b(writ|documentation|document|article|blog|linkedin|portfolio|application|profile|punctuation|heading|quotation|em dash|en dash|humanizer|promotional language)\b/.test(lower)) values.push("writing"); if (/\b(documentation|document|readme|changelog|wiki)\b/.test(lower)) values.push("documentation"); if (/\b(publish|release|package|tag|registry)\b/.test(lower)) values.push("release"); if (/\b(test|typecheck|lint|clippy|rustfmt|cargo check)\b/.test(lower)) values.push("testing"); if (/\b(implement|code|edit|repository|repo|codebase)\b/.test(lower)) values.push("implementation"); return [...new Set(values)]; } function decision( intent: CaptureIntent, confidence: number, durability: CaptureIntentDecision["durability"], text: string, reasons: string[], ): CaptureIntentDecision { const lower = text.toLowerCase(); const globalCues = [ /\bmy preference\b/, /\bi prefer\b/, /\bi do not like\b/, /\bfor (?:all )?my writing\b/, /\bwhen writing for me\b/, /\bacross projects\b/, /\bpublic (?:writing|documentation)\b/, ].filter((pattern) => pattern.test(lower)).map((pattern) => pattern.source); const projectCues = [ /\bthis (?:project|repository|repo|codebase)\b/, /\bin this (?:project|repository|repo|codebase)\b/, ].filter((pattern) => pattern.test(lower)).map((pattern) => pattern.source); return { intent, confidence, durability, global_cues: globalCues, project_cues: projectCues, applicability: applicability(text), reasons }; } export function classifyCaptureIntent(rawText: string): CaptureIntentDecision { const text = normalize(rawText); const lower = text.toLowerCase(); if (!text || text.length < 8) return decision("not_memory", 0, "temporary", text, ["too_short"]); if (/^(?:task:|your goal is|you are a delegated|you are a subagent|