feat: add ModeClassifier hook — deterministic mode routing#840
Open
rikitikitavi2012-debug wants to merge 1 commit intodanielmiessler:mainfrom
Open
feat: add ModeClassifier hook — deterministic mode routing#840rikitikitavi2012-debug wants to merge 1 commit intodanielmiessler:mainfrom
rikitikitavi2012-debug wants to merge 1 commit intodanielmiessler:mainfrom
Conversation
Fixes mode classification regression where ALGORITHM mode activates only ~9% of the time due to CLAUDE.md template attraction bias. The hook runs as first UserPromptSubmit hook and classifies prompts using deterministic regex patterns (< 20ms, zero API calls): - Greetings, ratings, thanks, acks (EN + RU) → MINIMAL mode - Everything else → ALGORITHM mode (enforced) Includes 39 regex patterns covering: - English greetings, thanks, acks - Russian/Cyrillic equivalents (comprehensive) - Numeric rating patterns (9/10, 8.5, 7/10 норм, etc.) - Short positive feedback The Algorithm's Complexity Gate in OBSERVE phase handles intelligent downshifting to NATIVE for simple tasks. Targets Releases/v4.0.1/ (current upstream release). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Author
|
Friendly ping — this PR adds a ModeClassifier hook that handles deterministic mode routing (MINIMAL/NATIVE/ALGORITHM) via regex before LLM evaluation, saving tokens on simple inputs like greetings and ratings. Happy to address any feedback or adjust the approach. Let me know if there's anything blocking review. |
Author
|
Friendly ping — this PR adds a ModeClassifier hook that routes requests to the correct mode (Algorithm/Native/Minimal) via fast regex before LLM processing, reducing unnecessary LLM calls. Mergeable, no conflicts. Happy to adjust if needed. |
Author
|
Friendly ping — this PR has been open for a few days without review. Happy to address any feedback or make changes if needed. Let me know if there's anything blocking the merge. |
DevenDucommun
added a commit
to DevenDucommun/Personal_AI_Infrastructure
that referenced
this pull request
Mar 6, 2026
Algorithm v3.8.0: merge v3.6.0 cognitive scaffolding (self-interrogation, constraint extraction, confidence tags, priority classification, coverage map, QG2-QG7 gates) into v3.7.0. Split ISC methodology, capability selection, and examples into dedicated files. Standard PRD skip. Session- safe context recovery. Voice curls fire-and-forget. Hooks: consolidate 4 terminal hooks → TerminalState.hook.ts. Add ModeClassifier (deterministic mode pre-classification, PR danielmiessler#840) and PostCompactRecovery (context re-injection after compaction, PR danielmiessler#799). Portability: replace hardcoded join(homedir(),'.claude') with paiPath() across 22 TS files (PR danielmiessler#873). Docs: slim SKILLSYSTEM.md and THEHOOKSYSTEM.md to ~80 lines each; move full content to PAI/dev/. Move MEMORYSYSTEM migration history to MEMORY-CHANGELOG.md. Add TELOS/DIGEST.md template to loadAtStartup. Clean CLAUDE.md MINIMAL format. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ModeClassifier.hook.ts— a deterministic UserPromptSubmit hook that classifies every prompt into ALGORITHM or MINIMAL mode using regex patterns (< 20ms, zero API calls)settings.json(before RatingCapture)Problem
The current mode classification relies on the LLM reading CLAUDE.md instructions and choosing the correct mode. In practice, the LLM latches onto the NATIVE format template (which appears first and is simpler) and uses it ~91% of the time, even for complex tasks that should trigger ALGORITHM mode.
Solution
Remove the LLM from mode classification entirely. A deterministic regex hook runs before the AI sees the prompt:
Design Decisions
^...$). "ok" matches but "ok, do X" doesn'tTest plan
🤖 Generated with Claude Code