quotarouter 0.3.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.
- quotarouter-0.3.1/.env.example +33 -0
- quotarouter-0.3.1/.gitignore +15 -0
- quotarouter-0.3.1/CHANGELOG.md +109 -0
- quotarouter-0.3.1/CONTRIBUTING.md +140 -0
- quotarouter-0.3.1/LICENSE +21 -0
- quotarouter-0.3.1/PKG-INFO +482 -0
- quotarouter-0.3.1/README.md +447 -0
- quotarouter-0.3.1/SECURITY.md +38 -0
- quotarouter-0.3.1/docs/chains.example.toml +30 -0
- quotarouter-0.3.1/docs/chains.md +134 -0
- quotarouter-0.3.1/docs/development.md +71 -0
- quotarouter-0.3.1/docs/reviews/2026-11-22-model-review.md +120 -0
- quotarouter-0.3.1/docs/testing.md +283 -0
- quotarouter-0.3.1/docs/vendor-probes.md +108 -0
- quotarouter-0.3.1/examples/library.py +60 -0
- quotarouter-0.3.1/hermes_plugin/__init__.py +58 -0
- quotarouter-0.3.1/hermes_plugin/plugin.yaml +8 -0
- quotarouter-0.3.1/openspec/changes/archive/.gitkeep +0 -0
- quotarouter-0.3.1/openspec/changes/archive/2026-11-22-e2e-verification/design.md +83 -0
- quotarouter-0.3.1/openspec/changes/archive/2026-11-22-e2e-verification/proposal.md +42 -0
- quotarouter-0.3.1/openspec/changes/archive/2026-11-22-e2e-verification/specs/end-to-end-verification/spec.md +68 -0
- quotarouter-0.3.1/openspec/changes/archive/2026-11-22-e2e-verification/tasks.md +37 -0
- quotarouter-0.3.1/openspec/changes/archive/2026-11-22-ops-surface/design.md +53 -0
- quotarouter-0.3.1/openspec/changes/archive/2026-11-22-ops-surface/proposal.md +45 -0
- quotarouter-0.3.1/openspec/changes/archive/2026-11-22-ops-surface/specs/ops-surface/spec.md +66 -0
- quotarouter-0.3.1/openspec/changes/archive/2026-11-22-ops-surface/tasks.md +47 -0
- quotarouter-0.3.1/openspec/changes/archive/2026-11-22-provider-agnostic-core/design.md +62 -0
- quotarouter-0.3.1/openspec/changes/archive/2026-11-22-provider-agnostic-core/proposal.md +45 -0
- quotarouter-0.3.1/openspec/changes/archive/2026-11-22-provider-agnostic-core/specs/provider-agnostic-core/spec.md +56 -0
- quotarouter-0.3.1/openspec/changes/archive/2026-11-22-provider-agnostic-core/tasks.md +46 -0
- quotarouter-0.3.1/openspec/changes/archive/2026-11-23-custom-chain-override/.openspec.yaml +2 -0
- quotarouter-0.3.1/openspec/changes/archive/2026-11-23-custom-chain-override/design.md +336 -0
- quotarouter-0.3.1/openspec/changes/archive/2026-11-23-custom-chain-override/proposal.md +99 -0
- quotarouter-0.3.1/openspec/changes/archive/2026-11-23-custom-chain-override/specs/call-budget/spec.md +98 -0
- quotarouter-0.3.1/openspec/changes/archive/2026-11-23-custom-chain-override/specs/chain-selection/spec.md +158 -0
- quotarouter-0.3.1/openspec/changes/archive/2026-11-23-custom-chain-override/tasks.md +188 -0
- quotarouter-0.3.1/openspec/config.yaml +24 -0
- quotarouter-0.3.1/openspec/specs/.gitkeep +0 -0
- quotarouter-0.3.1/openspec/specs/call-budget/spec.md +97 -0
- quotarouter-0.3.1/openspec/specs/chain-selection/spec.md +157 -0
- quotarouter-0.3.1/openspec/specs/end-to-end-verification/spec.md +78 -0
- quotarouter-0.3.1/openspec/specs/ops-surface/spec.md +71 -0
- quotarouter-0.3.1/openspec/specs/provider-agnostic-core/spec.md +65 -0
- quotarouter-0.3.1/pyproject.toml +55 -0
- quotarouter-0.3.1/quotarouter/__init__.py +27 -0
- quotarouter-0.3.1/quotarouter/__main__.py +10 -0
- quotarouter-0.3.1/quotarouter/alerts.py +208 -0
- quotarouter-0.3.1/quotarouter/chains.py +276 -0
- quotarouter-0.3.1/quotarouter/cli.py +588 -0
- quotarouter-0.3.1/quotarouter/config.py +176 -0
- quotarouter-0.3.1/quotarouter/env_source.py +113 -0
- quotarouter-0.3.1/quotarouter/errors.py +123 -0
- quotarouter-0.3.1/quotarouter/http_client.py +75 -0
- quotarouter-0.3.1/quotarouter/integrations/__init__.py +14 -0
- quotarouter-0.3.1/quotarouter/integrations/hermes.py +130 -0
- quotarouter-0.3.1/quotarouter/integrations/mcp.py +347 -0
- quotarouter-0.3.1/quotarouter/ledger.py +442 -0
- quotarouter-0.3.1/quotarouter/py.typed +0 -0
- quotarouter-0.3.1/quotarouter/retention.py +176 -0
- quotarouter-0.3.1/quotarouter/routing.py +902 -0
- quotarouter-0.3.1/quotarouter/stages/__init__.py +33 -0
- quotarouter-0.3.1/quotarouter/stages/base.py +132 -0
- quotarouter-0.3.1/quotarouter/stages/deepseek.py +106 -0
- quotarouter-0.3.1/quotarouter/stages/exa.py +87 -0
- quotarouter-0.3.1/quotarouter/stages/firecrawl.py +125 -0
- quotarouter-0.3.1/quotarouter/stages/jina.py +139 -0
- quotarouter-0.3.1/quotarouter/stages/keenable.py +78 -0
- quotarouter-0.3.1/quotarouter/stages/keyless.py +181 -0
- quotarouter-0.3.1/quotarouter/stages/tavily.py +95 -0
- quotarouter-0.3.1/quotarouter/types.py +102 -0
- quotarouter-0.3.1/scripts/model_review.py +330 -0
- quotarouter-0.3.1/scripts/preflight.sh +105 -0
- quotarouter-0.3.1/tests/conftest.py +85 -0
- quotarouter-0.3.1/tests/e2e/harness.py +425 -0
- quotarouter-0.3.1/tests/e2e/test_hermes_e2e.py +81 -0
- quotarouter-0.3.1/tests/fixtures/429-retry-after.json +3 -0
- quotarouter-0.3.1/tests/fixtures/deepseek-balance-empty.json +11 -0
- quotarouter-0.3.1/tests/fixtures/deepseek-search-402.json +8 -0
- quotarouter-0.3.1/tests/fixtures/exa-402.json +6 -0
- quotarouter-0.3.1/tests/fixtures/exa-search-ok.json +21 -0
- quotarouter-0.3.1/tests/fixtures/firecrawl-scrape-403.json +11 -0
- quotarouter-0.3.1/tests/fixtures/firecrawl-scrape-ok.json +11 -0
- quotarouter-0.3.1/tests/fixtures/firecrawl-search-ok.json +13 -0
- quotarouter-0.3.1/tests/fixtures/firecrawl-usage.json +9 -0
- quotarouter-0.3.1/tests/fixtures/jina-js-wall.txt +6 -0
- quotarouter-0.3.1/tests/fixtures/jina-ok.txt +10 -0
- quotarouter-0.3.1/tests/fixtures/keenable-search-ok.json +13 -0
- quotarouter-0.3.1/tests/fixtures/tavily-search-ok.json +12 -0
- quotarouter-0.3.1/tests/test_accounting.py +152 -0
- quotarouter-0.3.1/tests/test_adversarial.py +228 -0
- quotarouter-0.3.1/tests/test_alerts_and_keyless.py +123 -0
- quotarouter-0.3.1/tests/test_call_budget.py +185 -0
- quotarouter-0.3.1/tests/test_chain_config.py +123 -0
- quotarouter-0.3.1/tests/test_chain_file.py +217 -0
- quotarouter-0.3.1/tests/test_chain_resolution.py +267 -0
- quotarouter-0.3.1/tests/test_chain_walk.py +267 -0
- quotarouter-0.3.1/tests/test_cli.py +210 -0
- quotarouter-0.3.1/tests/test_cli_chains.py +179 -0
- quotarouter-0.3.1/tests/test_cli_ops.py +202 -0
- quotarouter-0.3.1/tests/test_degenerate_paths.py +424 -0
- quotarouter-0.3.1/tests/test_docs_examples.py +143 -0
- quotarouter-0.3.1/tests/test_edge_cases.py +551 -0
- quotarouter-0.3.1/tests/test_env_source.py +85 -0
- quotarouter-0.3.1/tests/test_errors.py +49 -0
- quotarouter-0.3.1/tests/test_funding.py +27 -0
- quotarouter-0.3.1/tests/test_hermes_provider.py +144 -0
- quotarouter-0.3.1/tests/test_integrations.py +162 -0
- quotarouter-0.3.1/tests/test_jina_reader.py +129 -0
- quotarouter-0.3.1/tests/test_ledger.py +79 -0
- quotarouter-0.3.1/tests/test_live.py +78 -0
- quotarouter-0.3.1/tests/test_mcp_integration.py +118 -0
- quotarouter-0.3.1/tests/test_mcp_protocol.py +301 -0
- quotarouter-0.3.1/tests/test_mcp_stdio.py +66 -0
- quotarouter-0.3.1/tests/test_ops.py +389 -0
- quotarouter-0.3.1/tests/test_packaging.py +358 -0
- quotarouter-0.3.1/tests/test_provider_and_cli.py +166 -0
- quotarouter-0.3.1/tests/test_resilience.py +137 -0
- quotarouter-0.3.1/tests/test_review_harness.py +96 -0
- quotarouter-0.3.1/tests/test_routing.py +427 -0
- quotarouter-0.3.1/tests/test_self_healing.py +197 -0
- quotarouter-0.3.1/tests/test_stage_base.py +111 -0
- quotarouter-0.3.1/tests/test_stages.py +425 -0
- quotarouter-0.3.1/tests/test_state_machine.py +114 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Vendor keys. Copy to ~/.config/quotarouter/.env (or ./.env next to your project, or point
|
|
2
|
+
# QUOTAROUTER_ENV_FILE at any file with this shape) and fill in what you have.
|
|
3
|
+
#
|
|
4
|
+
# Every vendor is optional: a stage without a key is skipped, never dialed. With no keys at all
|
|
5
|
+
# the router still answers through the anonymous tier (see "Last resort" in the README).
|
|
6
|
+
#
|
|
7
|
+
# Never commit the filled-in copy. Nothing here is read unless the matching stage is enabled.
|
|
8
|
+
|
|
9
|
+
# Search (free tier), also used as an extract fallback
|
|
10
|
+
EXA_API_KEY=
|
|
11
|
+
|
|
12
|
+
# Search and extract (free monthly credits; the only vendor that reports an exact balance)
|
|
13
|
+
FIRECRAWL_API_KEY=
|
|
14
|
+
|
|
15
|
+
# Search and extract (paid balance; the stage parks itself while the balance is empty and
|
|
16
|
+
# returns on its own after a top-up)
|
|
17
|
+
DEEPSEEK_API_KEY=
|
|
18
|
+
|
|
19
|
+
# Search (optional; free plan is 1000 credits a month)
|
|
20
|
+
TAVILY_API_KEY=
|
|
21
|
+
|
|
22
|
+
# Search (optional; first in the default chain once a key is present)
|
|
23
|
+
KEENABLE_API_KEY=
|
|
24
|
+
|
|
25
|
+
# The Reader works without a key; a key only raises the rate limit
|
|
26
|
+
JINA_API_KEY=
|
|
27
|
+
|
|
28
|
+
# --- router knobs, all optional -----------------------------------------------------------
|
|
29
|
+
# QUOTAROUTER_SEARCH_ORDER=exa,firecrawl,deepseek
|
|
30
|
+
# QUOTAROUTER_EXTRACT_ORDER=jina,firecrawl,exa
|
|
31
|
+
# QUOTAROUTER_STATE_DIR=~/.local/state/quotarouter
|
|
32
|
+
# QUOTAROUTER_ALLOW_KEYLESS=1
|
|
33
|
+
# QUOTAROUTER_QUOTA_RETRY=900
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project are documented here. The format follows
|
|
4
|
+
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and the project adheres to
|
|
5
|
+
[Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
|
+
|
|
7
|
+
## [Unreleased]
|
|
8
|
+
|
|
9
|
+
Nothing yet.
|
|
10
|
+
|
|
11
|
+
## [0.3.1] — 2026-11-23
|
|
12
|
+
|
|
13
|
+
### Fixed
|
|
14
|
+
|
|
15
|
+
- A ledger entry whose counters are not numbers is dropped by name and reported, instead of being
|
|
16
|
+
loaded as-is. Before this, a file edited by hand (or truncated by a full disk) could hand the
|
|
17
|
+
router a list where it expected a float and fail inside `charge()` — halfway through a call, where
|
|
18
|
+
it looks like a vendor outage. The other entries are kept, as with any malformed record.
|
|
19
|
+
- `jina` had a branch after `_raise_for_status` that could never run; the page-level error now
|
|
20
|
+
comes from the classifier itself.
|
|
21
|
+
|
|
22
|
+
### Changed
|
|
23
|
+
|
|
24
|
+
- Line coverage is 100%, up from 94%: the offline suite now exercises every branch of the CLI,
|
|
25
|
+
the integrations, the ledger's corruption paths, the retention edges and each vendor's
|
|
26
|
+
non-JSON and empty-answer handling. `pytest -q` runs 498 tests.
|
|
27
|
+
|
|
28
|
+
## [0.3.0] — 2026-11-23
|
|
29
|
+
|
|
30
|
+
### Added
|
|
31
|
+
|
|
32
|
+
- **A call can name its own chain**, down to a single vendor: `run_search(..., stages=["exa"])`,
|
|
33
|
+
`chain="free"`, `fallback=True`, `ignore_pause=True`; the same optional arguments on the MCP
|
|
34
|
+
tools (`stages`, `chain`, `fallback`, `force`, `budget`, `max_cost_usd`). Without them a call
|
|
35
|
+
walks the configured order exactly as before.
|
|
36
|
+
- **Named chains in a file**: `~/.config/quotarouter/chains.toml` (`QUOTAROUTER_CHAINS_FILE`),
|
|
37
|
+
a chain being a pair of stage lists plus a description, a budget and a strictness flag. A
|
|
38
|
+
malformed entry is reported and dropped; the rest still loads. `QUOTAROUTER_CHAINS` remains as a
|
|
39
|
+
one-line shorthand and replaces the file when set. Guide: `docs/chains.md`.
|
|
40
|
+
- **A per-call budget**: `budget="free"` refuses to spend money (no balance-funded stage, no
|
|
41
|
+
overrun of a spent free grant), and `max_cost_usd` refuses a call whose estimate exceeds the
|
|
42
|
+
ceiling before any vendor is dialed. A stage declares how it is funded (`free` / `balance`), so
|
|
43
|
+
"free" is a fact rather than an inference.
|
|
44
|
+
- `quotarouter chains`, `quotarouter call`, and `route --chain/--stages/--budget/--max-cost` —
|
|
45
|
+
all of them resolve without dialing a vendor.
|
|
46
|
+
- The audit line records `chain_mode`, `requested`, `budget` and, for a batch served by more than
|
|
47
|
+
one vendor, `delivered: {stage: pages}`. All fields are additive; older readers ignore them.
|
|
48
|
+
|
|
49
|
+
### Changed
|
|
50
|
+
|
|
51
|
+
- `quota_status` over MCP now reports `vendors`, `chains` and `allow_chain_override`, and each
|
|
52
|
+
vendor's `funding`. The vendor map moved under `vendors`.
|
|
53
|
+
- The plugin manifest version is checked against `quotarouter.__version__` by a test, and its
|
|
54
|
+
description no longer repeats the default order.
|
|
55
|
+
|
|
56
|
+
### Added (earlier)
|
|
57
|
+
|
|
58
|
+
- `quotarouter recheck` — probe the vendors now and release machine pauses immediately,
|
|
59
|
+
instead of waiting for the next search.
|
|
60
|
+
- `QUOTAROUTER_QUOTA_RETRY` / `QUOTAROUTER_QUOTA_RETRY_MAX` — how long a vendor parked for an
|
|
61
|
+
unfunded account waits before it is retried (default 900 s, doubling, capped at 6 h).
|
|
62
|
+
|
|
63
|
+
### Changed
|
|
64
|
+
|
|
65
|
+
- A vendor parked because its account cannot pay is now a machine pause with a deadline, not an
|
|
66
|
+
infinite one: it returns by itself as soon as a balance probe reports room. Only
|
|
67
|
+
`disable` (an operator stop) is permanent. Records written before this distinction are read
|
|
68
|
+
by their reason.
|
|
69
|
+
- An empty page from any stage is a failure, not a result: `selftest` no longer counts a
|
|
70
|
+
whitespace-only page as delivered.
|
|
71
|
+
|
|
72
|
+
### Fixed
|
|
73
|
+
|
|
74
|
+
- Transport failures (timeouts, connection resets, TLS errors) were never translated into the
|
|
75
|
+
package's own error type, so every stage's failure handling was dead code for real network
|
|
76
|
+
problems: a vendor that had gone dark looked like one bad page and was dialed again on the
|
|
77
|
+
next call.
|
|
78
|
+
- The keyless tier negotiated MCP without accepting `text/event-stream` (every call answered
|
|
79
|
+
`406`) and passed `{"url": …}` where `{"urls": [...]}` is required, so the last-resort stage
|
|
80
|
+
had never worked and reported an error message as page content.
|
|
81
|
+
- `ledger.iso()` raised `OverflowError` on an operator stop (`inf` deadline), which aborted
|
|
82
|
+
`status` and every probe report.
|
|
83
|
+
- A corrupt ledger entry no longer discards the readable ones; a ledger whose JSON parses but
|
|
84
|
+
has no vendor map is reported and rebuilt instead of silently zeroing all counters.
|
|
85
|
+
- Tavily extract returned only the successful URLs and lost the caller's order; a failed URL is
|
|
86
|
+
now a page error in its original position.
|
|
87
|
+
|
|
88
|
+
## [0.2.0] — 2026-11-22
|
|
89
|
+
|
|
90
|
+
First version meant to be used outside the author's machine.
|
|
91
|
+
|
|
92
|
+
### Added
|
|
93
|
+
|
|
94
|
+
- Provider-agnostic core: `Router.run_search()` / `Router.run_extract()`, persistent quota
|
|
95
|
+
ledger, pause kinds with backoff, and an audit trail (`routes.jsonl`).
|
|
96
|
+
- Stages: `exa`, `firecrawl`, `deepseek`, `tavily`, `keenable`, `jina` (Reader, works without a
|
|
97
|
+
key), and an anonymous MCP-based tier as the last resort.
|
|
98
|
+
- Integrations: a Hermes web-search provider and an MCP stdio server (`web_search`,
|
|
99
|
+
`web_extract`, `quota_status`, `quota_probe`) that works with any MCP client.
|
|
100
|
+
- CLI: `status`, `probe`, `route`, `selftest`, `serve-mcp`, `prune`, `daemon`, `schedule`,
|
|
101
|
+
`disable`, `enable`, `reset`, `alert-test`.
|
|
102
|
+
- Bounded per-URL parallelism for extract, log rotation, alert transports (webhook, Telegram,
|
|
103
|
+
command) with a cooldown, and a page-level error policy that does not park a healthy stage for
|
|
104
|
+
a blocked website.
|
|
105
|
+
|
|
106
|
+
[Unreleased]: https://github.com/sorochinssky/quotarouter/compare/v0.3.1...HEAD
|
|
107
|
+
[0.3.1]: https://github.com/sorochinssky/quotarouter/releases/tag/v0.3.1
|
|
108
|
+
[0.3.0]: https://github.com/sorochinssky/quotarouter/releases/tag/v0.3.0
|
|
109
|
+
[0.2.0]: https://github.com/sorochinssky/quotarouter/releases/tag/v0.2.0
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
# Contributing
|
|
2
|
+
|
|
3
|
+
Bug reports and pull requests are welcome. This is a small package with an unusually strict
|
|
4
|
+
gate, so here is the short version of what "done" means.
|
|
5
|
+
|
|
6
|
+
## Before you open an issue
|
|
7
|
+
|
|
8
|
+
Run these and paste the output — most reports are answerable from them:
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
python -c "import quotarouter, sys; print(quotarouter.__version__, sys.version)"
|
|
12
|
+
quotarouter status --json # what the ledger believes about each vendor
|
|
13
|
+
quotarouter route # who would serve the next search and extract, and why not
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
For a failed call, the line in `<state dir>/routes.jsonl` carries the reason per stage
|
|
17
|
+
(`exa: quota (402) -> firecrawl=ok`). Replace anything that looks like a key before posting.
|
|
18
|
+
|
|
19
|
+
## Setting up
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
python3 -m venv .venv && . .venv/bin/activate
|
|
23
|
+
pip install -e ".[dev]"
|
|
24
|
+
cp .env.example .env # fill in the keys you actually have; never commit it
|
|
25
|
+
python -m pytest -q # offline, no network, no keys needed
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Python 3.11, 3.12 and 3.13 are supported and tested; 3.14 works too.
|
|
29
|
+
|
|
30
|
+
## The gate
|
|
31
|
+
|
|
32
|
+
`scripts/preflight.sh` runs everything, and a green run is what a mergeable change means here.
|
|
33
|
+
There is no CI by choice: the gate is local. The steps, in order, are described in
|
|
34
|
+
[docs/development.md](docs/development.md). The short version:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
python -m pytest -q # offline suite
|
|
38
|
+
python -m pytest -m "live and not e2e" -q # real vendors, needs keys, spends a fraction of a cent
|
|
39
|
+
python -m pytest -m e2e -q # end-to-end inside a real Hermes install
|
|
40
|
+
hermes plugins validate hermes_plugin # manifest and registration, if you touched the shim
|
|
41
|
+
python -m mypy --ignore-missing-imports quotarouter # the package ships py.typed
|
|
42
|
+
python -m build && twine check dist/* # packaging
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Skip the live and e2e levels only when the keys or a Hermes install are genuinely unavailable,
|
|
46
|
+
and say so in the pull request.
|
|
47
|
+
|
|
48
|
+
## The chain is data
|
|
49
|
+
|
|
50
|
+
There are exactly two chains, and they are separate lists because the cheap vendor for a query is
|
|
51
|
+
not the cheap vendor for a page:
|
|
52
|
+
|
|
53
|
+
```
|
|
54
|
+
search : keenable -> exa -> tavily -> firecrawl -> deepseek
|
|
55
|
+
extract: jina -> keenable -> firecrawl -> tavily -> exa -> deepseek
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Both come from the environment and are read once per process:
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
QUOTAROUTER_SEARCH_ORDER=exa,firecrawl,deepseek
|
|
62
|
+
QUOTAROUTER_EXTRACT_ORDER=jina,firecrawl,exa
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
What to know before changing one:
|
|
66
|
+
|
|
67
|
+
- **One name is a valid chain.** `QUOTAROUTER_SEARCH_ORDER=exa` means "exa or nothing": no
|
|
68
|
+
failover, and the error says so. Useful for a single free account and for measuring one vendor.
|
|
69
|
+
- **A stage that cannot do the capability is skipped**, with the reason `does not support extract`.
|
|
70
|
+
The extract chain may name a search-only vendor; it just never serves.
|
|
71
|
+
- **A misspelled name is reported at startup** (`... is not a stage this build has; the chain is
|
|
72
|
+
shorter than it looks`) and then skipped at call time. It is a warning, not an error: a chain
|
|
73
|
+
that names a vendor from a newer release must still run on an older one.
|
|
74
|
+
- **`keyless` is not in the chains.** The anonymous tier is a fallback that serves when nothing in
|
|
75
|
+
the chain could, and it is switched by `QUOTAROUTER_ALLOW_KEYLESS` / `KEYLESS_LAST_RESORT`
|
|
76
|
+
rather than by position.
|
|
77
|
+
- **The order is per process; a call may still name its own chain.** `run_search(query, limit,
|
|
78
|
+
stages=[...])`, `chain="name"`, `fallback=True`, `budget="free"`, `max_cost_usd=...`,
|
|
79
|
+
`ignore_pause=True` — and the same optional arguments on the MCP tools. Without them the call
|
|
80
|
+
walks the configured order, byte for byte as before.
|
|
81
|
+
- **A named chain lives in a file, not in one variable.** `~/.config/quotarouter/chains.toml`
|
|
82
|
+
(`QUOTAROUTER_CHAINS_FILE`), because a chain is a pair of lists plus a description and a budget.
|
|
83
|
+
`QUOTAROUTER_CHAINS` remains as a one-line shorthand and replaces the file when set. Format and
|
|
84
|
+
examples: `docs/chains.md`; the shipped example is `docs/chains.example.toml`, and a test loads it.
|
|
85
|
+
- **A custom chain is strict.** No silent continuation into the default order, no anonymous tier
|
|
86
|
+
behind it. `fallback=True` or `strict = false` asks for the tail explicitly.
|
|
87
|
+
- **A chain's budget cannot be loosened by a caller.** The stricter of (chain, call) applies: a name
|
|
88
|
+
that says `free` is a promise, not a default.
|
|
89
|
+
- **A dollar ceiling cannot price vendor credits.** A credit-metered stage under `max_cost_usd` is
|
|
90
|
+
held to its free grant instead. Do not add an exchange rate: the router has no tariff and must not
|
|
91
|
+
invent one.
|
|
92
|
+
- **Order is not priority by quality, only by spend.** Put the free allowance you have most of
|
|
93
|
+
first, and the paid balance last.
|
|
94
|
+
|
|
95
|
+
`quotarouter route` prints the decision — usable stages in order, then every skip with its reason
|
|
96
|
+
— so a chain question is answerable without a live call. `quotarouter route --chain <name>`,
|
|
97
|
+
`--stages a,b` and `--budget free` resolve the chain a call would use; `quotarouter chains` prints
|
|
98
|
+
what the file produced and what it dropped.
|
|
99
|
+
|
|
100
|
+
## Rules enforced by tests, not by review
|
|
101
|
+
|
|
102
|
+
- **Every behaviour change lands with a test that fails without it.** A bug fix starts with the
|
|
103
|
+
reproducing test.
|
|
104
|
+
- **English only** in tracked files: code, comments, docs, commit messages, log lines. A test
|
|
105
|
+
walks the repository for Cyrillic.
|
|
106
|
+
- **The core stays host-agnostic**: `quotarouter/` must not import `agent`, `hermes_cli`, `tools`
|
|
107
|
+
or `hermes_plugins`. Host coupling belongs in `quotarouter/integrations/`.
|
|
108
|
+
- **No secrets** in code, docs, fixtures or fixtures' filenames. Vendors are configured through
|
|
109
|
+
environment variables; a test fixture carries a balance, never a key.
|
|
110
|
+
- **A test may not cost money.** Anything that spends vendor credits is marked `live` and is
|
|
111
|
+
excluded from the default run.
|
|
112
|
+
|
|
113
|
+
## Pull requests
|
|
114
|
+
|
|
115
|
+
- One logical change per pull request, one commit per step of it.
|
|
116
|
+
- Describe the failure you saw, not the diff you wrote; the diff is right there.
|
|
117
|
+
- New behaviour comes with a test; a fixed bug comes with the test that reproduces it.
|
|
118
|
+
- If the change touches the plugin shim, the provider contract or the MCP surface, run the live
|
|
119
|
+
and e2e levels too (see the gate above) — the offline suite cannot see a registry change.
|
|
120
|
+
- A documentation change that alters an example has to keep the example executable: the gate runs
|
|
121
|
+
`examples/library.py` against the installed wheel.
|
|
122
|
+
|
|
123
|
+
## Style
|
|
124
|
+
|
|
125
|
+
Match the file you are editing: short functions, comments that explain *why* (the interesting
|
|
126
|
+
ones in this package record a bug that was paid for), error messages that name the vendor and
|
|
127
|
+
the reason, and docstrings that state the contract rather than the mechanics.
|
|
128
|
+
|
|
129
|
+
Commit messages: English, imperative subject line, body explaining the why. One logical change
|
|
130
|
+
per commit.
|
|
131
|
+
|
|
132
|
+
## Vendors
|
|
133
|
+
|
|
134
|
+
Adding a stage means adding a file in `quotarouter/stages/`, registering it in
|
|
135
|
+
`quotarouter/stages/__init__.py`, and covering four things with tests on `httpx.MockTransport`:
|
|
136
|
+
a normal answer, an empty answer (not a success), a quota refusal, and a page-level refusal that
|
|
137
|
+
must not park the stage. `quotarouter/stages/base.py` documents the contract; `docs/vendor-probes.md`
|
|
138
|
+
records which vendors have actually been exercised against their live API and which are only
|
|
139
|
+
covered by hand-written fixtures. Do not move a row from the second column to the first without
|
|
140
|
+
a probe output to point at.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Andrey Sorochinsky
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|