Commit 7912321
feat: add NADIRCLAW_CLASSIFIER_STRIP_PATTERNS env var for classifier input cleaning (#77)
* feat: add NADIRCLAW_CLASSIFIER_STRIP_PATTERNS env var for classifier input cleaning
Agent frameworks (OpenClaw, Claude Code, NanoBot, Hermes, etc.) often wrap
the human's actual prompt in a structured envelope - metadata blocks, memory
context, system notes - that does not reflect the complexity of the request.
The classifier sees JSON schemas, memory dumps, and tool definitions,
inflating the score even for trivial requests like "hello".
Changes:
- settings.py: new CLASSIFIER_STRIP_PATTERNS property (env var, default empty = off)
- server.py: _strip_classifier_input() function + call sites in _smart_route_full,
/v1/classify, and /v1/classify/batch
- Invalid regex logs a warning and is silently ignored (no crash)
- Zero overhead when unset: regex is None, function is a no-op
* Guard over-broad strip patterns + add tests (review #77)
Addresses the one pre-merge blocker from review: an over-broad
NADIRCLAW_CLASSIFIER_STRIP_PATTERNS could consume the entire prompt,
leaving the classifier an empty string and silently routing everything
to the cheapest tier. _strip_classifier_input now returns the original
text when stripping empties it.
Adds tests/test_classifier_strip.py covering the contract: unset =>
identity, pattern strips envelope (incl. DOTALL across newlines), invalid
regex => no-op + warning, and the over-broad => fall-back-to-original
guard.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: BunpGhost <bunpghost@users.noreply.github.com>
Co-authored-by: Nadir <amirdor@gmail.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>1 parent a7f46e8 commit 7912321
3 files changed
Lines changed: 147 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
27 | 69 | | |
28 | 70 | | |
29 | 71 | | |
| |||
533 | 575 | | |
534 | 576 | | |
535 | 577 | | |
| 578 | + | |
| 579 | + | |
536 | 580 | | |
537 | 581 | | |
538 | 582 | | |
| |||
547 | 591 | | |
548 | 592 | | |
549 | 593 | | |
| 594 | + | |
550 | 595 | | |
551 | | - | |
| 596 | + | |
552 | 597 | | |
553 | 598 | | |
554 | 599 | | |
| |||
571 | 616 | | |
572 | 617 | | |
573 | 618 | | |
574 | | - | |
| 619 | + | |
| 620 | + | |
575 | 621 | | |
576 | 622 | | |
577 | 623 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
553 | 553 | | |
554 | 554 | | |
555 | 555 | | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
556 | 576 | | |
557 | 577 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
0 commit comments