claude-code-router 0.1.1__tar.gz → 0.2.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- claude_code_router-0.2.1/.github/workflows/publish.yml +136 -0
- claude_code_router-0.2.1/CHANGELOG.md +61 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/PKG-INFO +7 -3
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/README.md +6 -2
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/ccr/config.py +89 -1
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/ccr/doctor.py +5 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/ccr/evaluate/classify.py +104 -5
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/ccr/evaluate/llm.py +14 -5
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/ccr/evaluate/locate.py +55 -2
- claude_code_router-0.2.1/ccr/evaluate/predict.py +299 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/ccr/evaluate/risk.py +10 -3
- claude_code_router-0.2.1/ccr/evaluate/workspace.py +86 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/ccr/hooks/__init__.py +9 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/ccr/hooks/prompt.py +2 -1
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/ccr/install/settings.py +20 -1
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/ccr/route/__init__.py +163 -12
- claude_code_router-0.2.1/ccr/route/code.py +137 -0
- claude_code_router-0.2.1/docs/CODE_FIRST_ROUTING.md +232 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/docs/REFERENCE.md +55 -11
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/pyproject.toml +4 -1
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/conftest.py +16 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/test_budget.py +1 -1
- claude_code_router-0.2.1/tests/test_code_first.py +269 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/test_install.py +1 -1
- claude_code_router-0.2.1/tests/test_predict.py +338 -0
- claude_code_router-0.2.1/tests/test_release.py +20 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/test_route_table.py +6 -3
- claude_code_router-0.2.1/tests/test_routing_consistency.py +158 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/uv.lock +1 -1
- claude_code_router-0.1.1/.github/workflows/publish.yml +0 -33
- claude_code_router-0.1.1/CHANGELOG.md +0 -22
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/.claude/agents/Explore.md +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/.claude/agents/ccr-architect.md +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/.claude/agents/ccr-critical.md +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/.claude/agents/ccr-implement.md +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/.claude/agents/ccr-quick.md +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/.claude/agents/ccr-small.md +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/.claude/settings.json +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/.gitattributes +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/.github/ISSUE_TEMPLATE/bug_report.md +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/.github/ISSUE_TEMPLATE/feature_request.md +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/.github/pull_request_template.md +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/.github/workflows/ci.yml +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/.gitignore +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/CONTRIBUTING.md +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/LICENSE +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/ccr/__init__.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/ccr/__main__.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/ccr/cli.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/ccr/detect/__init__.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/ccr/entry.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/ccr/evaluate/__init__.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/ccr/evaluate/text.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/ccr/graph/__init__.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/ccr/graph/build.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/ccr/graph/db.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/ccr/graph/files.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/ccr/graph/git.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/ccr/graph/parse.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/ccr/graph/query.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/ccr/graph/resolve.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/ccr/headless.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/ccr/history/__init__.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/ccr/history/calibrate.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/ccr/history/dashboard.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/ccr/history/feedback.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/ccr/history/learn.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/ccr/history/prompts.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/ccr/history/redact.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/ccr/history/savings.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/ccr/history/shadow.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/ccr/history/stats.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/ccr/history/tune.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/ccr/history/why.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/ccr/hooks/bg.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/ccr/hooks/common.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/ccr/hooks/session_start.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/ccr/hooks/stop.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/ccr/hooks/tasks.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/ccr/install/__init__.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/ccr/install/agents.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/ccr/install/command.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/ccr/memory/__init__.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/ccr/memory/signals.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/ccr/memory/sources.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/ccr/report.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/ccr/route/budget.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/ccr/statusline.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/ccr/transcript.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/docs/images/dashboard.png +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/docs/images/explain.png +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/scripts/bench_graph.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/scripts/bench_hooks.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/scripts/bench_routing.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/fixtures/graph/go/go.mod +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/fixtures/graph/go/internal/store/store.go +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/fixtures/graph/go/internal/store/store_test.go +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/fixtures/graph/go/main.go +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/fixtures/graph/go/util.go +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/fixtures/graph/java/src/main/java/com/acme/app/App.java +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/fixtures/graph/java/src/main/java/com/acme/app/Helper.java +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/fixtures/graph/java/src/main/java/com/acme/util/Strings.java +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/fixtures/graph/py/.gitignore +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/fixtures/graph/py/app/__init__.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/fixtures/graph/py/app/core/__init__.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/fixtures/graph/py/app/core/engine.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/fixtures/graph/py/app/main.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/fixtures/graph/py/app/util.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/fixtures/graph/py/node_modules/dep/index.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/fixtures/graph/py/poetry.lock +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/fixtures/graph/py/tests/test_engine.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/fixtures/graph/py/tests/test_util.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/fixtures/graph/rust/Cargo.toml +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/fixtures/graph/rust/src/main.rs +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/fixtures/graph/rust/src/net/client.rs +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/fixtures/graph/rust/src/net/mod.rs +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/fixtures/graph/ts/package-lock.json +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/fixtures/graph/ts/src/app.min.js +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/fixtures/graph/ts/src/app.ts +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/fixtures/graph/ts/src/components/Button.tsx +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/fixtures/graph/ts/src/format.ts +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/fixtures/graph/ts/src/lib/index.ts +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/fixtures/graph/ts/src/lib/math.ts +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/fixtures/graph/zig/src/main.zig +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/fixtures/graph/zig/src/util.zig +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/fixtures/route/shop_py/README.md +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/fixtures/route/shop_py/app/__init__.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/fixtures/route/shop_py/app/api/__init__.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/fixtures/route/shop_py/app/api/handlers.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/fixtures/route/shop_py/app/api/pagination.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/fixtures/route/shop_py/app/auth/__init__.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/fixtures/route/shop_py/app/auth/session.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/fixtures/route/shop_py/app/auth/tokens.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/fixtures/route/shop_py/app/core/__init__.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/fixtures/route/shop_py/app/core/config.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/fixtures/route/shop_py/app/core/engine.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/fixtures/route/shop_py/app/main.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/fixtures/route/shop_py/app/payments/__init__.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/fixtures/route/shop_py/app/payments/ledger.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/fixtures/route/shop_py/app/payments/stripe_client.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/fixtures/route/shop_py/app/reports/__init__.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/fixtures/route/shop_py/app/reports/export.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/fixtures/route/shop_py/app/utils/__init__.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/fixtures/route/shop_py/app/utils/strings.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/fixtures/route/shop_py/migrations/versions/0001_init.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/fixtures/route/shop_py/migrations/versions/0002_add_email.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/fixtures/route/shop_py/pyproject.toml +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/fixtures/route/shop_py/tests/test_engine.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/fixtures/route/shop_py/tests/test_pagination.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/fixtures/route/shop_py/tests/test_strings.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/fixtures/route/svc_go/.github/workflows/ci.yml +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/fixtures/route/svc_go/cmd/server/main.go +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/fixtures/route/svc_go/deploy/terraform/main.tf +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/fixtures/route/svc_go/go.mod +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/fixtures/route/svc_go/internal/auth/jwt.go +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/fixtures/route/svc_go/internal/cache/cache.go +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/fixtures/route/svc_go/internal/http/router.go +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/fixtures/route/svc_go/internal/store/store.go +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/fixtures/route/svc_go/internal/store/store_test.go +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/fixtures/route/web_ts/package.json +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/fixtures/route/web_ts/src/App.tsx +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/fixtures/route/web_ts/src/__tests__/format.test.ts +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/fixtures/route/web_ts/src/components/Button.tsx +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/fixtures/route/web_ts/src/components/Footer.tsx +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/fixtures/route/web_ts/src/components/Navbar.tsx +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/fixtures/route/web_ts/src/hooks/useAuth.ts +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/fixtures/route/web_ts/src/index.tsx +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/fixtures/route/web_ts/src/lib/api.ts +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/fixtures/route/web_ts/src/lib/format.ts +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/fixtures/route/web_ts/src/pages/Checkout.tsx +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/fixtures/route/web_ts/src/pages/Home.tsx +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/fixtures/run/error_max_budget_usd.json +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/fixtures/run/error_max_turns.json +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/fixtures/run/success.json +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/test_calibrate.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/test_cli.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/test_config.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/test_dashboard.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/test_detect.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/test_evaluate.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/test_feedback_loops.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/test_graph.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/test_history.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/test_hooks.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/test_memory.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/test_privacy.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/test_routing_gaps.py +0 -0
- {claude_code_router-0.1.1 → claude_code_router-0.2.1}/tests/test_run.py +0 -0
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
name: Release
|
|
2
|
+
|
|
3
|
+
# A push to main that changes the version releases it: tag vX.Y.Z, create the GitHub release from
|
|
4
|
+
# CHANGELOG.md, publish to PyPI, then npm. Every step is skipped when it is already done, so a
|
|
5
|
+
# push that does not change the version does nothing, and a failed run can simply be re-run.
|
|
6
|
+
# A release created by hand still publishes (the release event), and the GitHub release created
|
|
7
|
+
# here does not trigger a second run because GITHUB_TOKEN events never start workflows.
|
|
8
|
+
|
|
9
|
+
on:
|
|
10
|
+
push:
|
|
11
|
+
branches: [main]
|
|
12
|
+
release:
|
|
13
|
+
types: [published]
|
|
14
|
+
workflow_dispatch:
|
|
15
|
+
|
|
16
|
+
concurrency:
|
|
17
|
+
group: release
|
|
18
|
+
cancel-in-progress: false
|
|
19
|
+
|
|
20
|
+
permissions:
|
|
21
|
+
contents: read
|
|
22
|
+
|
|
23
|
+
jobs:
|
|
24
|
+
check:
|
|
25
|
+
runs-on: ubuntu-latest
|
|
26
|
+
outputs:
|
|
27
|
+
version: ${{ steps.v.outputs.version }}
|
|
28
|
+
need_release: ${{ steps.v.outputs.need_release }}
|
|
29
|
+
need_pypi: ${{ steps.v.outputs.need_pypi }}
|
|
30
|
+
need_npm: ${{ steps.v.outputs.need_npm }}
|
|
31
|
+
steps:
|
|
32
|
+
- uses: actions/checkout@v4
|
|
33
|
+
- id: v
|
|
34
|
+
env:
|
|
35
|
+
EVENT: ${{ github.event_name }}
|
|
36
|
+
TAG: ${{ github.event.release.tag_name }}
|
|
37
|
+
run: |
|
|
38
|
+
set -euo pipefail
|
|
39
|
+
py=$(python3 -c "import tomllib; print(tomllib.load(open('pyproject.toml','rb'))['project']['version'])")
|
|
40
|
+
name=$(node -p "require('./npm/package.json').name")
|
|
41
|
+
npmv=$(node -p "require('./npm/package.json').version")
|
|
42
|
+
echo "pyproject=$py npm=$name@$npmv"
|
|
43
|
+
if [ "$py" != "$npmv" ]; then echo "::error::pyproject ($py) and npm/package.json ($npmv) disagree"; exit 1; fi
|
|
44
|
+
if [ "$EVENT" = "release" ] && [ "$TAG" != "v$py" ]; then
|
|
45
|
+
echo "::error::release tag $TAG does not match version v$py"; exit 1
|
|
46
|
+
fi
|
|
47
|
+
if git ls-remote --exit-code --tags origin "refs/tags/v$py" >/dev/null; then need_release=false; else need_release=true; fi
|
|
48
|
+
code=$(curl -s -o /dev/null -w '%{http_code}' "https://pypi.org/pypi/claude-code-router/$py/json")
|
|
49
|
+
if [ "$code" = 200 ]; then need_pypi=false; else need_pypi=true; fi
|
|
50
|
+
if npm view "$name@$py" version >/dev/null 2>&1; then need_npm=false; else need_npm=true; fi
|
|
51
|
+
echo "tag needed=$need_release pypi needed=$need_pypi npm needed=$need_npm"
|
|
52
|
+
{
|
|
53
|
+
echo "version=$py"
|
|
54
|
+
echo "need_release=$need_release"
|
|
55
|
+
echo "need_pypi=$need_pypi"
|
|
56
|
+
echo "need_npm=$need_npm"
|
|
57
|
+
} >> "$GITHUB_OUTPUT"
|
|
58
|
+
|
|
59
|
+
release:
|
|
60
|
+
needs: check
|
|
61
|
+
if: needs.check.outputs.need_release == 'true' && github.event_name != 'release'
|
|
62
|
+
runs-on: ubuntu-latest
|
|
63
|
+
permissions:
|
|
64
|
+
contents: write # create the tag and the GitHub release
|
|
65
|
+
steps:
|
|
66
|
+
- uses: actions/checkout@v4
|
|
67
|
+
- name: Create tag and GitHub release
|
|
68
|
+
env:
|
|
69
|
+
GH_TOKEN: ${{ github.token }}
|
|
70
|
+
VERSION: ${{ needs.check.outputs.version }}
|
|
71
|
+
run: |
|
|
72
|
+
set -euo pipefail
|
|
73
|
+
# Release notes: this version's section of CHANGELOG.md.
|
|
74
|
+
awk -v v="$VERSION" '
|
|
75
|
+
$0 ~ "^## \\[" v "\\]" { on = 1; next }
|
|
76
|
+
on && /^## \[/ { exit }
|
|
77
|
+
on { print }
|
|
78
|
+
' CHANGELOG.md > notes.md
|
|
79
|
+
[ -s notes.md ] || echo "See CHANGELOG.md." > notes.md
|
|
80
|
+
gh release create "v$VERSION" --target "$GITHUB_SHA" --title "v$VERSION" --notes-file notes.md
|
|
81
|
+
|
|
82
|
+
build:
|
|
83
|
+
needs: check
|
|
84
|
+
if: needs.check.outputs.need_pypi == 'true'
|
|
85
|
+
runs-on: ubuntu-latest
|
|
86
|
+
steps:
|
|
87
|
+
- uses: actions/checkout@v4
|
|
88
|
+
- uses: astral-sh/setup-uv@v5
|
|
89
|
+
- name: Build
|
|
90
|
+
run: uv build
|
|
91
|
+
- name: Check metadata
|
|
92
|
+
run: uvx twine check dist/*
|
|
93
|
+
- uses: actions/upload-artifact@v4
|
|
94
|
+
with:
|
|
95
|
+
name: dist
|
|
96
|
+
path: dist/
|
|
97
|
+
|
|
98
|
+
publish-pypi:
|
|
99
|
+
needs: [check, release, build]
|
|
100
|
+
# Run after the release job unless it failed; skipped is fine (tag already there).
|
|
101
|
+
if: >-
|
|
102
|
+
always() && needs.check.result == 'success' && needs.build.result == 'success' &&
|
|
103
|
+
needs.release.result != 'failure' && needs.release.result != 'cancelled'
|
|
104
|
+
runs-on: ubuntu-latest
|
|
105
|
+
environment: pypi
|
|
106
|
+
permissions:
|
|
107
|
+
id-token: write # PyPI Trusted Publishing
|
|
108
|
+
steps:
|
|
109
|
+
- uses: actions/download-artifact@v4
|
|
110
|
+
with:
|
|
111
|
+
name: dist
|
|
112
|
+
path: dist/
|
|
113
|
+
- uses: pypa/gh-action-pypi-publish@release/v1
|
|
114
|
+
|
|
115
|
+
# The npm package is a launcher that installs the PyPI release, so it goes out after PyPI.
|
|
116
|
+
publish-npm:
|
|
117
|
+
needs: [check, release, publish-pypi]
|
|
118
|
+
if: >-
|
|
119
|
+
always() && needs.check.result == 'success' && needs.check.outputs.need_npm == 'true' &&
|
|
120
|
+
needs.release.result != 'failure' && needs.release.result != 'cancelled' &&
|
|
121
|
+
(needs.publish-pypi.result == 'success' || needs.check.outputs.need_pypi == 'false')
|
|
122
|
+
runs-on: ubuntu-latest
|
|
123
|
+
environment: npm
|
|
124
|
+
permissions:
|
|
125
|
+
contents: read
|
|
126
|
+
id-token: write # npm Trusted Publishing and provenance
|
|
127
|
+
steps:
|
|
128
|
+
- uses: actions/checkout@v4
|
|
129
|
+
- uses: actions/setup-node@v4
|
|
130
|
+
with:
|
|
131
|
+
node-version: "22"
|
|
132
|
+
- name: Use an npm that supports Trusted Publishing
|
|
133
|
+
run: npm install -g npm@11
|
|
134
|
+
- name: Publish
|
|
135
|
+
working-directory: npm
|
|
136
|
+
run: npm publish --access public --provenance
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project are documented here.
|
|
4
|
+
|
|
5
|
+
## [Unreleased]
|
|
6
|
+
|
|
7
|
+
## [0.2.1] - 2026-11-24
|
|
8
|
+
|
|
9
|
+
### Changed
|
|
10
|
+
- Code-first routing and the Haiku change prediction are always on; `code_first.enabled` and
|
|
11
|
+
`predict.enabled` are gone (an old setting is ignored with a warning). Without the `claude`
|
|
12
|
+
CLI, or when Haiku is late, routing silently keeps its rule-based tier.
|
|
13
|
+
- Recent commits only strengthen a file match that already stands on its own, and are ignored
|
|
14
|
+
when they touch more than 40 files (an initial import), so a fresh repo no longer turns a
|
|
15
|
+
loose word match into a critical path.
|
|
16
|
+
- A follow-up prompt waits for Haiku at most once.
|
|
17
|
+
|
|
18
|
+
### Added
|
|
19
|
+
- The prompt hook keeps the prediction inside Claude Code's installed hook timeout, and
|
|
20
|
+
`ccr doctor` warns when that timeout is under 15 s (re-run `ccr init`).
|
|
21
|
+
- `CCR_NO_PREDICT=1` keeps test suites from calling the real CLI.
|
|
22
|
+
- Releases are automatic: a push to main that changes the version tags it, creates the GitHub
|
|
23
|
+
release from this changelog, and publishes to PyPI and then npm. Steps already done are skipped.
|
|
24
|
+
|
|
25
|
+
### Fixed
|
|
26
|
+
- The npm package name in the repo and README is now `@satya-prakash/claude-code-router`, the
|
|
27
|
+
name 0.2.0 was published under.
|
|
28
|
+
|
|
29
|
+
## [0.2.0] - 2026-11-24
|
|
30
|
+
|
|
31
|
+
### Added
|
|
32
|
+
- Code-first routing behind `code_first.enabled` (off by default): uncommitted edits and
|
|
33
|
+
recent commits help locate the files, and a score of that code can raise a real code change
|
|
34
|
+
by one tier. Trivial edits, questions, steps and small-scope wording keep their keyword tier.
|
|
35
|
+
- Haiku change prediction behind `predict.enabled` (off by default): when routing is unsure,
|
|
36
|
+
Haiku predicts the files, size and contract changes, and the tier moves by one at most. See `docs/CODE_FIRST_ROUTING.md`.
|
|
37
|
+
- npm launcher package `@satya-prakash/claude-code-router` (in `npm/`): installs `ccr` with npm and
|
|
38
|
+
runs the matching PyPI release from a private Python environment.
|
|
39
|
+
- Release workflow publishes to npm after PyPI and checks that the tag matches both versions.
|
|
40
|
+
|
|
41
|
+
### Fixed
|
|
42
|
+
- Routing inconsistencies between near-identical prompts (found with a 48-prompt probe set).
|
|
43
|
+
|
|
44
|
+
## [0.1.1] - 2026-10-17
|
|
45
|
+
|
|
46
|
+
### Added
|
|
47
|
+
- Published on PyPI as `claude-code-router` (the command is still `ccr`).
|
|
48
|
+
- CI, contributing guide, issue and PR templates, README screenshots and badges.
|
|
49
|
+
|
|
50
|
+
## [0.1.0] - 2026-10-17
|
|
51
|
+
|
|
52
|
+
### Added
|
|
53
|
+
- Rule-based routing of Claude Code tasks to six tiers (T0 to T4, plus T2H) with matching
|
|
54
|
+
`ccr-*` subagents.
|
|
55
|
+
- Task classification, tree-sitter code graph, and a risk score from dependents, complexity,
|
|
56
|
+
tests, churn, critical paths and memory notes.
|
|
57
|
+
- Learning from past outcomes, weekly budget pressure and an opt-in haiku assist.
|
|
58
|
+
- Commands: `init`, `profile`, `explain`, `run`, `stats`, `dashboard`, `export-benchmark`,
|
|
59
|
+
`calibrate`, `shadow`, `tune`, `purge`, `feedback`, `graph`, `doctor`.
|
|
60
|
+
- Claude Code hooks and a status line relay, all fail-open.
|
|
61
|
+
- MIT license.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: claude-code-router
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.1
|
|
4
4
|
Summary: Route Claude Code tasks to the cheapest sufficient model and effort
|
|
5
5
|
Project-URL: Homepage, https://github.com/ai-solution-architect-roadmap/claude-code-router
|
|
6
6
|
Project-URL: Documentation, https://github.com/ai-solution-architect-roadmap/claude-code-router/blob/main/docs/REFERENCE.md
|
|
@@ -32,6 +32,7 @@ Description-Content-Type: text/markdown
|
|
|
32
32
|
[](https://github.com/ai-solution-architect-roadmap/claude-code-router/blob/main/pyproject.toml)
|
|
33
33
|
[](https://claude.com/claude-code)
|
|
34
34
|
[](#how-it-works)
|
|
35
|
+
[](https://pepy.tech/projects/claude-code-router)
|
|
35
36
|
[](https://github.com/ai-solution-architect-roadmap/claude-code-router/commits/main)
|
|
36
37
|
|
|
37
38
|
`ccr` routes each Claude Code task to the cheapest model and effort level that should be
|
|
@@ -85,6 +86,8 @@ uv tool install claude-code-router
|
|
|
85
86
|
pipx install claude-code-router
|
|
86
87
|
# or
|
|
87
88
|
pip install claude-code-router
|
|
89
|
+
# or, with npm (installs the same Python package into ~/.ccr-npm on first run)
|
|
90
|
+
npm install -g @satya-prakash/claude-code-router
|
|
88
91
|
|
|
89
92
|
ccr --help
|
|
90
93
|
```
|
|
@@ -267,8 +270,9 @@ you add your own `critical_paths`, `critical_terms` and `hard_terms`.
|
|
|
267
270
|
|
|
268
271
|
## Privacy
|
|
269
272
|
|
|
270
|
-
|
|
271
|
-
|
|
273
|
+
Routing runs locally. When the rules are unsure, the prompt hook asks haiku through your own
|
|
274
|
+
`claude` CLI to predict the change, sending the prompt, file paths, symbol names and the diff
|
|
275
|
+
stat (no source). Local state lives in `.ccr/`.
|
|
272
276
|
|
|
273
277
|
## Documentation
|
|
274
278
|
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
[](https://github.com/ai-solution-architect-roadmap/claude-code-router/blob/main/pyproject.toml)
|
|
6
6
|
[](https://claude.com/claude-code)
|
|
7
7
|
[](#how-it-works)
|
|
8
|
+
[](https://pepy.tech/projects/claude-code-router)
|
|
8
9
|
[](https://github.com/ai-solution-architect-roadmap/claude-code-router/commits/main)
|
|
9
10
|
|
|
10
11
|
`ccr` routes each Claude Code task to the cheapest model and effort level that should be
|
|
@@ -58,6 +59,8 @@ uv tool install claude-code-router
|
|
|
58
59
|
pipx install claude-code-router
|
|
59
60
|
# or
|
|
60
61
|
pip install claude-code-router
|
|
62
|
+
# or, with npm (installs the same Python package into ~/.ccr-npm on first run)
|
|
63
|
+
npm install -g @satya-prakash/claude-code-router
|
|
61
64
|
|
|
62
65
|
ccr --help
|
|
63
66
|
```
|
|
@@ -240,8 +243,9 @@ you add your own `critical_paths`, `critical_terms` and `hard_terms`.
|
|
|
240
243
|
|
|
241
244
|
## Privacy
|
|
242
245
|
|
|
243
|
-
|
|
244
|
-
|
|
246
|
+
Routing runs locally. When the rules are unsure, the prompt hook asks haiku through your own
|
|
247
|
+
`claude` CLI to predict the change, sending the prompt, file paths, symbol names and the diff
|
|
248
|
+
stat (no source). Local state lives in `.ccr/`.
|
|
245
249
|
|
|
246
250
|
## Documentation
|
|
247
251
|
|
|
@@ -120,6 +120,30 @@ DEFAULTS: dict = {
|
|
|
120
120
|
# only when 3+ independent signals agree)
|
|
121
121
|
"ceiling_without_critical": "T3",
|
|
122
122
|
},
|
|
123
|
+
# Code-first routing (always on): find the files from the real repository state (uncommitted
|
|
124
|
+
# edits, recent commits, named paths and symbols) and score that code. The score can raise
|
|
125
|
+
# a real code change one tier above its keyword route; it never lowers a tier or moves
|
|
126
|
+
# trivial edits and questions, and steps or small-scope words still win.
|
|
127
|
+
# See docs/CODE_FIRST_ROUTING.md.
|
|
128
|
+
"code_first": {
|
|
129
|
+
"recent_commits": 5, # files from the last N commits strengthen a match
|
|
130
|
+
"min_confidence": 0.5, # location confidence needed to route from the code
|
|
131
|
+
"bands": [0.2, 0.4, 0.6], # code score edges: T1 | T2 | T2H | T3
|
|
132
|
+
"tie_margin": 0.04, # within this of an edge, the class base breaks the tie
|
|
133
|
+
},
|
|
134
|
+
# Step 2 of code-first routing (always on): when routing is unsure, ask Haiku (your claude
|
|
135
|
+
# CLI) to predict the change: files, size, interface or schema change. A small change
|
|
136
|
+
# lowers the tier by one, a large one raises it by one; never past a T4 rule or below a
|
|
137
|
+
# critical path. Cached per prompt and repository state. Without the claude CLI, or when it
|
|
138
|
+
# is late, routing silently keeps its rule-based tier. See docs/CODE_FIRST_ROUTING.md.
|
|
139
|
+
"predict": {
|
|
140
|
+
"model": "haiku",
|
|
141
|
+
"effort": "low",
|
|
142
|
+
"timeout_s": 10.0, # hard limit; a late answer leaves routing as it was.
|
|
143
|
+
# The claude CLI takes about 4-5 s per call
|
|
144
|
+
"min_confidence": 0.6, # below this the prediction is reported, not used
|
|
145
|
+
"boundary": 0.08, # code score this close to a band edge counts as unsure
|
|
146
|
+
},
|
|
123
147
|
# `ccr run` (headless `claude -p`).
|
|
124
148
|
"run": {
|
|
125
149
|
"test_command": None, # shell command that must pass for success, e.g. "pytest -q"
|
|
@@ -458,6 +482,70 @@ def _merge_routing(cfg: Config, raw: dict) -> None:
|
|
|
458
482
|
cfg.errors.append("routing: expected a mapping")
|
|
459
483
|
|
|
460
484
|
|
|
485
|
+
def _merge_code_first(cfg: Config, raw: dict) -> None:
|
|
486
|
+
sec = raw.get("code_first")
|
|
487
|
+
if sec is None:
|
|
488
|
+
return
|
|
489
|
+
if not isinstance(sec, dict):
|
|
490
|
+
cfg.errors.append("code_first: expected a mapping")
|
|
491
|
+
return
|
|
492
|
+
d = cfg.data["code_first"]
|
|
493
|
+
for k, v in sec.items():
|
|
494
|
+
if k == "enabled":
|
|
495
|
+
# always on since 0.2.1; an old opt-in setting is ignored, not an error
|
|
496
|
+
cfg.warnings.append("code_first.enabled: ignored, code-first is always on")
|
|
497
|
+
elif k == "recent_commits":
|
|
498
|
+
if _num(cfg, "code_first.recent_commits", v, 0, 100):
|
|
499
|
+
d[k] = int(v)
|
|
500
|
+
elif k in ("min_confidence", "tie_margin"):
|
|
501
|
+
if _num(cfg, f"code_first.{k}", v, 0, 1):
|
|
502
|
+
d[k] = float(v)
|
|
503
|
+
elif k == "bands":
|
|
504
|
+
ok = (isinstance(v, list) and len(v) == 3
|
|
505
|
+
and all(isinstance(x, (int, float)) and not isinstance(x, bool) and 0 < x < 1
|
|
506
|
+
for x in v)
|
|
507
|
+
and list(v) == sorted(v) and len(set(v)) == 3)
|
|
508
|
+
if ok:
|
|
509
|
+
d[k] = [float(x) for x in v]
|
|
510
|
+
else:
|
|
511
|
+
cfg.errors.append("code_first.bands: expected three rising numbers between "
|
|
512
|
+
f"0 and 1, got {v!r}")
|
|
513
|
+
else:
|
|
514
|
+
cfg.warnings.append(f"code_first.{k}: unknown field ignored")
|
|
515
|
+
|
|
516
|
+
|
|
517
|
+
def _merge_predict(cfg: Config, raw: dict) -> None:
|
|
518
|
+
sec = raw.get("predict")
|
|
519
|
+
if sec is None:
|
|
520
|
+
return
|
|
521
|
+
if not isinstance(sec, dict):
|
|
522
|
+
cfg.errors.append("predict: expected a mapping")
|
|
523
|
+
return
|
|
524
|
+
d = cfg.data["predict"]
|
|
525
|
+
for k, v in sec.items():
|
|
526
|
+
if k == "enabled":
|
|
527
|
+
# always on since 0.2.1; an old opt-in setting is ignored, not an error
|
|
528
|
+
cfg.warnings.append("predict.enabled: ignored, predict is always on")
|
|
529
|
+
elif k == "model":
|
|
530
|
+
if _valid_model(v):
|
|
531
|
+
d[k] = v
|
|
532
|
+
else:
|
|
533
|
+
cfg.errors.append(f"predict.model: unknown model {v!r}")
|
|
534
|
+
elif k == "effort":
|
|
535
|
+
if v in EFFORTS:
|
|
536
|
+
d[k] = v
|
|
537
|
+
else:
|
|
538
|
+
cfg.errors.append(f"predict.effort: must be one of {'|'.join(EFFORTS)}, "
|
|
539
|
+
f"got {v!r}")
|
|
540
|
+
elif k in ("timeout_s", "min_confidence", "boundary"):
|
|
541
|
+
# the prompt hook's Claude Code timeout is 15 s (ccr/install/settings.py)
|
|
542
|
+
lo, hi = (0.5, 13) if k == "timeout_s" else (0, 1)
|
|
543
|
+
if _num(cfg, f"predict.{k}", v, lo, hi):
|
|
544
|
+
d[k] = float(v)
|
|
545
|
+
else:
|
|
546
|
+
cfg.warnings.append(f"predict.{k}: unknown field ignored")
|
|
547
|
+
|
|
548
|
+
|
|
461
549
|
def _merge_hooks(cfg: Config, raw: dict) -> None:
|
|
462
550
|
d = cfg.data
|
|
463
551
|
hooks = raw.get("hooks")
|
|
@@ -483,7 +571,7 @@ def _merge_hooks(cfg: Config, raw: dict) -> None:
|
|
|
483
571
|
# One validator per config section, run in this order; add a section by appending here.
|
|
484
572
|
_MERGERS = (_merge_tiers, _merge_class_base, _merge_critical, _merge_hard_terms, _merge_pricing,
|
|
485
573
|
_merge_risk, _merge_budget, _merge_history, _merge_run, _merge_llm, _merge_routing,
|
|
486
|
-
_merge_hooks)
|
|
574
|
+
_merge_code_first, _merge_predict, _merge_hooks)
|
|
487
575
|
|
|
488
576
|
|
|
489
577
|
def _section(cfg: Config, raw: dict, name: str, ranges: dict[str, tuple[float, float]],
|
|
@@ -42,6 +42,11 @@ def _doctor_settings(root: Path) -> list[tuple[str, str]]:
|
|
|
42
42
|
if isinstance(hooks, dict) and hooks:
|
|
43
43
|
if "ccr" in json.dumps(hooks):
|
|
44
44
|
out.append(("OK", f"ccr hooks wired ({', '.join(hooks)})"))
|
|
45
|
+
from ccr.install.settings import installed_prompt_timeout
|
|
46
|
+
t = installed_prompt_timeout(root)
|
|
47
|
+
if t is not None and t < 15:
|
|
48
|
+
out.append(("WARN", f"prompt hook timeout is {t:.0f}s: too short for the Haiku "
|
|
49
|
+
"change prediction; re-run `ccr init` (sets 15s)"))
|
|
45
50
|
else:
|
|
46
51
|
out.append(("WARN", "hooks present but none call ccr"))
|
|
47
52
|
else:
|
|
@@ -27,6 +27,8 @@ RULES: dict[str, list[tuple[re.Pattern, float]]] = {
|
|
|
27
27
|
r"tell\s+me|show\s+me|list|walk\s+me\s+through)\b", _I), 2.0),
|
|
28
28
|
(re.compile(r"\?\s*$"), 1.5),
|
|
29
29
|
(re.compile(r"^\s*(?:help|hi|hello|hey)\s*[!?.]*\s*$", _I), 4.0),
|
|
30
|
+
# "why does X ...?" asks for an explanation; debugging words decide otherwise
|
|
31
|
+
(re.compile(r"^\s*why\b[^?]*\?", _I), 2.0),
|
|
30
32
|
(re.compile(r"\b(?:explain|describe|summari[sz]e|walk\s+me\s+through|overview\s+of|"
|
|
31
33
|
r"what\s+does|how\s+does|how\s+do(?:es)?\s+\w+\s+work|where\s+is|where\s+are|"
|
|
32
34
|
r"which\s+files?|find\s+where|look\s+up|understand|what\s+is|what\s+are|"
|
|
@@ -37,7 +39,9 @@ RULES: dict[str, list[tuple[re.Pattern, float]]] = {
|
|
|
37
39
|
r"docstrings?|readme|changelog|whitespace|indent\w*|formatting|reformat|"
|
|
38
40
|
r"lint(?:ing)?|bump|version\s+number|copy\s?text|label|colou?r|"
|
|
39
41
|
r"log\s+message|sort\s+imports|import\s+order|unused\s+imports?|"
|
|
40
|
-
r"dead\s+code|one[- ]liner|license\s+header|todo
|
|
42
|
+
r"dead\s+code|one[- ]liner|license\s+header|todo|"
|
|
43
|
+
r"unused\s+(?:[\w-]+\s+){0,2}?(?:variables?|functions?|methods?|parameters?|params?|arguments?|"
|
|
44
|
+
r"args?|constants?|fields?|helpers?|classes|class|code|locals?))\b", _I), 2.0),
|
|
41
45
|
(re.compile(r"\b(?:add|delete|remove|drop)\s+(?:a\s+|an\s+|the\s+)?(?:short\s+|trailing\s+|blank\s+)?"
|
|
42
46
|
r"(?:comments?|docstrings?|type\s+hints?|newlines?|blank\s+lines?|whitespace|"
|
|
43
47
|
r"license\s+header|commented[- ]out\s+code)\b|\bcommented[- ]out\b|"
|
|
@@ -52,7 +56,9 @@ RULES: dict[str, list[tuple[re.Pattern, float]]] = {
|
|
|
52
56
|
(re.compile(r"\btest\s+coverage\b|\btest\s+cases?\b", _I), 2.0),
|
|
53
57
|
],
|
|
54
58
|
"bugfix": [
|
|
55
|
-
(re.compile(r"\b(?:fix\w*|bugs?|broken|crash\w*|
|
|
59
|
+
(re.compile(r"\b(?:fix\w*|bugs?|broken|crash\w*|"
|
|
60
|
+
r"(?:errors?|exceptions?)(?!\s+(?:messages?|handling|handlers?|texts?|strings?|"
|
|
61
|
+
r"copy|labels?|wording|pages?|codes?|types?|classes|class))|fails?|failing|"
|
|
56
62
|
r"failure|incorrect\w*|wrong|regression|null|nil|nan|undefined|"
|
|
57
63
|
r"off[- ]by[- ]one|doesn'?t\s+work|not\s+working|traceback|panic\w*|"
|
|
58
64
|
r"segfault|returns?\s+(?:none|null|nil|wrong|empty)|double[- ]count\w*)\b",
|
|
@@ -88,7 +94,7 @@ RULES: dict[str, list[tuple[re.Pattern, float]]] = {
|
|
|
88
94
|
r"leak(?:s|ed|ing)?\s+(?:secrets?|credentials?|tokens?|keys?|pii)|"
|
|
89
95
|
r"audit|pen-?test\w*|threat\s+model)\b", _I), 3.0),
|
|
90
96
|
(re.compile(r"\b(?:session\s+fixation|fixation|csrf|clickjack\w*|brute[- ]?force|"
|
|
91
|
-
r"lock\s*down|access\s+control|authori[sz]\w*|
|
|
97
|
+
r"lock\s*down|access\s+control|authori[sz]\w*|"
|
|
92
98
|
r"tokens?\s+(?:never\s+)?expir\w*|admin\s+routes?|two[- ]factor|2fa|mfa)\b",
|
|
93
99
|
_I), 4.0),
|
|
94
100
|
(re.compile(r"\b(?:auth\w*|permissions?|secrets?|credentials?|passwords?|encrypt\w*|"
|
|
@@ -107,7 +113,8 @@ RULES: dict[str, list[tuple[re.Pattern, float]]] = {
|
|
|
107
113
|
r"hangs?|hanging|leak(?:s|ing)?|memory\s+leak|heisenbug|"
|
|
108
114
|
r"can'?t\s+reproduce|non-?deterministic\w*|keeps?\s+(?:growing|crashing|"
|
|
109
115
|
r"failing))\b", _I), 3.0),
|
|
110
|
-
|
|
116
|
+
# "why does X crash" stated as a problem, not asked as a question (see WHY_QUESTION)
|
|
117
|
+
(re.compile(r"^\s*why\b(?![^?]*\?)", _I), 2.0),
|
|
111
118
|
# symptoms with no cause named: the work is finding out what is wrong
|
|
112
119
|
(re.compile(r"\b(?:no\s+idea\s+why|(?:do\s?n'?t|not)\s+(?:know|sure)\s+why|at\s+random|"
|
|
113
120
|
r"random\s+\w+|now\s+and\s+then|at\s+times|(?:do(?:es)?n'?t|do(?:es)?\s+not)\s+add\s+up|"
|
|
@@ -128,6 +135,8 @@ RULES: dict[str, list[tuple[re.Pattern, float]]] = {
|
|
|
128
135
|
],
|
|
129
136
|
}
|
|
130
137
|
|
|
138
|
+
_SCHEMA_PLAIN = RULES["migration"][1][0] # "add a ... column to ..." without the word migration
|
|
139
|
+
|
|
131
140
|
# A leading imperative verb is the strongest single cue.
|
|
132
141
|
LEAD_VERB = [
|
|
133
142
|
(re.compile(r"^\s*(?:fix|repair|resolve|patch)\b", _I), "bugfix", 1.5),
|
|
@@ -145,6 +154,50 @@ LEAD_VERB = [
|
|
|
145
154
|
(re.compile(r"^\s*(?:plan|design|architect)\b", _I), "design", 1.5),
|
|
146
155
|
]
|
|
147
156
|
|
|
157
|
+
# Context rules: words whose meaning depends on the rest of the prompt.
|
|
158
|
+
# "why does X ...?" is a question unless it names a failure.
|
|
159
|
+
WHY_QUESTION = re.compile(r"^\s*why\b[^?]*\?", _I)
|
|
160
|
+
BUG_WORDS = re.compile(
|
|
161
|
+
r"\b(?:crash\w*|fail\w*|errors?|exceptions?|broken|bugs?|flak(?:y|iness)|intermittent\w*|"
|
|
162
|
+
r"sometimes|randomly|occasional\w*|sporadic\w*|hangs?|hanging|leak\w*|race\s+conditions?|"
|
|
163
|
+
r"deadlock\w*|wrong|incorrect\w*|null|nan|undefined|traceback|panic\w*|segfault)\b", _I)
|
|
164
|
+
# "fix the typo in the error message" is a typo fix, not a bug fix
|
|
165
|
+
TYPO = re.compile(r"\b(?:typos?|spelling|misspell\w*)\b", _I)
|
|
166
|
+
TYPO_BONUS = 2.0
|
|
167
|
+
# rate limiting is security work on auth / API surfaces, ordinary feature work elsewhere
|
|
168
|
+
RATE_LIMIT = re.compile(r"\brate[- ]?limit\w*", _I)
|
|
169
|
+
AUTH_API = re.compile(
|
|
170
|
+
r"\b(?:auth\w*|log\s?ins?|logouts?|sign[- ]?(?:in|up|on)|passwords?|credentials?|tokens?|"
|
|
171
|
+
r"sessions?|otp|2fa|mfa|api|apis|endpoints?|routes?|brute[- ]?force|abuse)\b", _I)
|
|
172
|
+
# "add a column to the dashboard table" is UI work unless database words say otherwise
|
|
173
|
+
UI_CONTEXT = re.compile(
|
|
174
|
+
r"\b(?:dashboards?|pages?|screens?|views?|ui|ux|grids?|components?|frontend|front-end|html|"
|
|
175
|
+
r"csv|spreadsheets?|excel|reports?|widgets?|modals?|forms?|display\w*|render\w*|layouts?|"
|
|
176
|
+
r"sidebars?|panels?|charts?|markdown|output)\b", _I)
|
|
177
|
+
DB_CONTEXT = re.compile(
|
|
178
|
+
r"\b(?:databases?|db|sql|postgres\w*|mysql|sqlite|schemas?|migrations?|nullable|"
|
|
179
|
+
r"not\s+null|foreign\s+keys?|primary\s+keys?|constraints?|alembic|prisma|orm|models?|"
|
|
180
|
+
r"alter|varchar|index(?:es)?|indices)\b", _I)
|
|
181
|
+
# "update/upgrade X to 1.2" is a dependency bump; frameworks, runtimes, databases and major
|
|
182
|
+
# versions ("to 5", "major") stay migrations
|
|
183
|
+
MINOR_BUMP = re.compile(
|
|
184
|
+
r"^\s*(?P<verb>update|upgrade)\s+(?:the\s+)?(?P<what>(?:[\w.@/+-]+\s+){1,3}?)"
|
|
185
|
+
r"(?:(?:dependency|package|version)\s+)?(?:from\s+v?\d[\w.]*\s+)?to\s+v?\d+(?:\.\d+)+\b", _I)
|
|
186
|
+
PLATFORM = re.compile(
|
|
187
|
+
r"\b(?:django|rails|react|angular|vue|next(?:\.?js)?|nuxt|svelte|spring|flask|fastapi|"
|
|
188
|
+
r"express|laravel|symfony|dotnet|\.net|python|node(?:\.?js)?|java|jdk|php|ruby|go|golang|"
|
|
189
|
+
r"rust|typescript|kotlin|swift|postgres\w*|mysql|mariadb|mongo\w*|redis|sqlite|"
|
|
190
|
+
r"elasticsearch|kafka|kubernetes|k8s|terraform|schema|database|db|major)\b", _I)
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
def _as_bump(core: str) -> str:
|
|
194
|
+
"""`core` with a plain "update/upgrade <dependency> to <x.y>" read as "bump ..."."""
|
|
195
|
+
m = MINOR_BUMP.search(core)
|
|
196
|
+
if not m or PLATFORM.search(core):
|
|
197
|
+
return core
|
|
198
|
+
return core[:m.start("verb")] + "bump" + core[m.end("verb"):]
|
|
199
|
+
|
|
200
|
+
|
|
148
201
|
SWEEPING = re.compile(
|
|
149
202
|
r"\b(?:everything|everywhere|the\s+whole\s+(?:thing|app|backend|frontend|stack|project)|"
|
|
150
203
|
r"rewrite\s+(?:the\s+)?(?:web\s+)?(?:app|backend|frontend|site)\b|all\s+(?:of\s+)?the\s+code|"
|
|
@@ -192,12 +245,26 @@ MIN_STEPS = 3
|
|
|
192
245
|
def count_steps(text: str) -> int:
|
|
193
246
|
"""Number of explicit steps in the prompt (0 when it is not a step-by-step list)."""
|
|
194
247
|
n = len(STEP_LINE.findall(text))
|
|
248
|
+
if n < MIN_STEPS:
|
|
249
|
+
n = max(n, _inline_steps(text))
|
|
195
250
|
if n < MIN_STEPS:
|
|
196
251
|
found = [w.lower() for w in STEP_WORDS.findall(text)]
|
|
197
252
|
n = len(found) if found and found[0].startswith("first") else 0
|
|
198
253
|
return n if n >= MIN_STEPS else 0
|
|
199
254
|
|
|
200
255
|
|
|
256
|
+
INLINE_STEP = re.compile(r"(?:^|(?<=\s))\(?(\d{1,2})[.)]\s+(?=\S)")
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
def _inline_steps(text: str) -> int:
|
|
260
|
+
"""Length of a 1. 2. 3. ... run written on one line (consecutive numbers from 1)."""
|
|
261
|
+
n = 0
|
|
262
|
+
for m in INLINE_STEP.finditer(text):
|
|
263
|
+
if int(m.group(1)) == n + 1:
|
|
264
|
+
n += 1
|
|
265
|
+
return n
|
|
266
|
+
|
|
267
|
+
|
|
201
268
|
@dataclass
|
|
202
269
|
class TaskClass:
|
|
203
270
|
kind: str
|
|
@@ -249,13 +316,16 @@ def classify(task: str, located: bool | None = None,
|
|
|
249
316
|
"""Classify a task prompt. `located`: whether code was located (feeds vagueness).
|
|
250
317
|
`hard_terms`: project words (config `hard_terms`) that count like "intermittent"."""
|
|
251
318
|
raw = task.strip()
|
|
252
|
-
core = _POLITE.sub("", raw, count=1)
|
|
319
|
+
core = _as_bump(_POLITE.sub("", raw, count=1))
|
|
253
320
|
body = T.strip_refs(core)
|
|
321
|
+
ui_table = bool(UI_CONTEXT.search(body)) and not DB_CONTEXT.search(body)
|
|
254
322
|
scores: dict[str, float] = {}
|
|
255
323
|
matched: dict[str, list[str]] = {}
|
|
256
324
|
for kind, rules in RULES.items():
|
|
257
325
|
s = 0.0
|
|
258
326
|
for rx, weight in rules:
|
|
327
|
+
if rx is _SCHEMA_PLAIN and ui_table:
|
|
328
|
+
continue
|
|
259
329
|
src = core if rx.pattern.startswith("^") or rx.pattern.startswith(r"\?") else body
|
|
260
330
|
hits = _hits(rx, src)
|
|
261
331
|
if hits:
|
|
@@ -284,6 +354,7 @@ def classify(task: str, located: bool | None = None,
|
|
|
284
354
|
# "add/write tests" is a tests task, not a feature that happens to mention tests
|
|
285
355
|
if scores.get("tests", 0) >= 3.0 and "feature" in scores:
|
|
286
356
|
scores["feature"] = max(0.0, scores["feature"] - 2.5)
|
|
357
|
+
_context_rules(core, body, hard, scores, matched)
|
|
287
358
|
# questions that also carry a strong change cue ("can you fix ...?") are change requests
|
|
288
359
|
ranked = sorted(scores.items(), key=lambda kv: (-kv[1], _PRIORITY.index(kv[0])))
|
|
289
360
|
if ranked:
|
|
@@ -310,6 +381,34 @@ def classify(task: str, located: bool | None = None,
|
|
|
310
381
|
words=len(raw.split()))
|
|
311
382
|
|
|
312
383
|
|
|
384
|
+
def _bump(scores: dict, matched: dict, kind: str, by: float, term: str) -> None:
|
|
385
|
+
scores[kind] = scores.get(kind, 0.0) + by
|
|
386
|
+
if term not in matched.setdefault(kind, []):
|
|
387
|
+
matched[kind].append(term)
|
|
388
|
+
|
|
389
|
+
|
|
390
|
+
def _context_rules(core: str, body: str, hard: list[str], scores: dict, matched: dict) -> None:
|
|
391
|
+
"""Score adjustments for words whose meaning depends on the rest of the prompt."""
|
|
392
|
+
typo = _hits(TYPO, body)
|
|
393
|
+
if typo and "trivial" in scores:
|
|
394
|
+
_bump(scores, matched, "trivial", TYPO_BONUS, typo[0])
|
|
395
|
+
rate = _hits(RATE_LIMIT, body)
|
|
396
|
+
if rate:
|
|
397
|
+
on_auth_or_api = bool(AUTH_API.search(core))
|
|
398
|
+
_bump(scores, matched, "security" if on_auth_or_api else "feature",
|
|
399
|
+
4.0 if on_auth_or_api else 1.5, rate[0])
|
|
400
|
+
if WHY_QUESTION.search(core):
|
|
401
|
+
if hard or BUG_WORDS.search(body):
|
|
402
|
+
_bump(scores, matched, "debugging", 3.5, "why")
|
|
403
|
+
scores["question"] = scores.get("question", 0.0) - 3.5
|
|
404
|
+
else:
|
|
405
|
+
# a why-question without a failure: the symptom words are not a bug report
|
|
406
|
+
scores["debugging"] = scores.get("debugging", 0.0) - 3.0
|
|
407
|
+
for kind in [k for k, v in scores.items() if v <= 0]:
|
|
408
|
+
del scores[kind]
|
|
409
|
+
matched.pop(kind, None)
|
|
410
|
+
|
|
411
|
+
|
|
313
412
|
# tie-break order: prefer the cheaper interpretation ("start low")
|
|
314
413
|
_PRIORITY = ["question", "trivial", "tests", "bugfix", "feature", "refactor", "perf",
|
|
315
414
|
"migration", "debugging", "design", "security"]
|
|
@@ -33,19 +33,28 @@ class LLMUnavailable(RuntimeError):
|
|
|
33
33
|
pass
|
|
34
34
|
|
|
35
35
|
|
|
36
|
-
def claude_command(model: str, effort: str) -> list[str]:
|
|
36
|
+
def claude_command(model: str, effort: str, lean: bool = False) -> list[str]:
|
|
37
37
|
exe = shutil.which("claude")
|
|
38
38
|
if not exe:
|
|
39
39
|
raise LLMUnavailable("`claude` CLI not found on PATH")
|
|
40
40
|
# no tools, no MCP servers, no saved session: a single cheap classification turn
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
cmd = [exe, "-p", "--model", model, "--effort", effort, "--output-format", "json",
|
|
42
|
+
"--tools", "", "--strict-mcp-config", "--no-session-persistence"]
|
|
43
|
+
if lean:
|
|
44
|
+
# start faster: with an API key, minimal mode skips hooks, plugins and memory (about
|
|
45
|
+
# 0.7 s in total); otherwise skip project settings (and their hooks) and slash
|
|
46
|
+
# commands, which saves about 0.4 s of the CLI's ~4 s start-up
|
|
47
|
+
if os.environ.get("ANTHROPIC_API_KEY"):
|
|
48
|
+
cmd.append("--bare")
|
|
49
|
+
else:
|
|
50
|
+
cmd += ["--setting-sources", "user", "--disable-slash-commands"]
|
|
51
|
+
return cmd
|
|
43
52
|
|
|
44
53
|
|
|
45
54
|
def run_claude(prompt: str, *, model: str = "haiku", effort: str = "low",
|
|
46
|
-
timeout: float = 45) -> dict:
|
|
55
|
+
timeout: float = 45, lean: bool = False) -> dict:
|
|
47
56
|
"""Run the user's claude CLI headlessly; return its JSON result object. Mock me in tests."""
|
|
48
|
-
cmd = claude_command(model, effort)
|
|
57
|
+
cmd = claude_command(model, effort, lean)
|
|
49
58
|
env = {**os.environ, "CCR_INTERNAL": "1"} # ccr hooks no-op inside this call
|
|
50
59
|
env.pop("CLAUDE_CODE_EFFORT_LEVEL", None)
|
|
51
60
|
try:
|