v3/@claude-flow/guidance/docs/adrs/ADR-G003-intent-weighted-classification.md
Accepted
2026-02-01
The shard retriever (ADR-G002) must classify the current task's intent to boost relevant shards. For example, a "fix the XSS vulnerability" task should boost security shards, while "add the user profile page" should boost feature and architecture shards.
Intent classification must satisfy three constraints:
The system supports 11 intent categories defined in src/types.ts as the TaskIntent union type: bug-fix, feature, refactor, security, performance, testing, docs, deployment, architecture, debug, and general.
Use weighted regular expression patterns per intent category, with highest-total-score-wins as the classification strategy.
The INTENT_PATTERNS map in src/retriever.ts defines, for each TaskIntent, an array of { pattern: RegExp; weight: number } entries. Example:
'security': [
{ pattern: /\b(security|auth|permission|access control|encrypt|secret|token)\b/i, weight: 0.9 },
{ pattern: /\b(cve|vulnerability|injection|xss|csrf|sanitize)\b/i, weight: 1.0 },
],
Classification algorithm in ShardRetriever.classifyIntent():
general), iterate its patternsgeneralThe general intent has a single catch-all pattern /./ with weight 0.1, ensuring it never wins over a real match but provides a fallback.
Patterns use word boundary anchors (\b) and case-insensitive flags (/i). Alternation groups handle variants: tests? matches both "test" and "tests", mocks? matches "mock" and "mocks".
RetrievalRequest.intent allows callers to override the detected intent. This is useful when the calling context has stronger signal (e.g., the user explicitly tagged the task or the hook system classified it).
general. Mitigation: the intent override in RetrievalRequest allows external classifiers to supply the intent.Send the task description to a cheap model (e.g., Haiku) with a classification prompt. Rejected because it adds 200-500ms latency, requires an API key, is non-deterministic across runs, and costs money per classification.
Pre-compute TF-IDF vectors for each intent and compare. Rejected because TF-IDF requires a corpus, adds a vocabulary dependency, and is slower than regex for this small pattern set. The benefit of TF-IDF (handling novel terms) is marginal when the intent categories are well-defined.
Embed the task description and compare to intent centroid embeddings. Rejected because it requires an embedding model (adding a dependency), is slower than regex (~5ms vs. <0.1ms), and the 11-class problem is simple enough for pattern matching.
Match keywords without weights, count matches. Rejected because it treats ambiguous keywords (like "fix") equally with specific ones (like "cve"), leading to frequent misclassification when descriptions contain generic action verbs.
v3/@claude-flow/guidance/src/retriever.ts -- INTENT_PATTERNS map, ShardRetriever.classifyIntent()v3/@claude-flow/guidance/src/types.ts -- TaskIntent union type