@yahyahammad/venastine 0.3.9 → 0.3.10
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.
- package/CONFIG_ARCHITECTURE.md +109 -0
- package/README.md +13 -4
- package/bin/venastine.mjs +62 -6
- package/bin/venastine.py +3 -1
- package/cli_commands.py +10 -0
- package/config.yaml +51 -0
- package/config_schema.py +16 -0
- package/core/client.py +45 -4
- package/core/commands.py +4 -0
- package/core/provider_errors.py +40 -0
- package/core/reasoning/scholar.py +14 -5
- package/docs/SECURITY.md +6 -0
- package/mcp_client/client.py +49 -2
- package/package.json +1 -1
- package/pyproject.toml +1 -1
- package/requirements.txt +19 -0
- package/tools/builtin/_net_common.py +878 -0
- package/tools/builtin/_page_text.py +490 -0
- package/tools/builtin/_pdf_text.py +113 -0
- package/tools/builtin/arxiv.py +5 -1
- package/tools/builtin/fetch_url.py +388 -120
- package/tools/builtin/web_search.py +81 -7
- package/tools/registry.py +10 -0
- package/tui/app.py +54 -0
- package/tui/app.tcss +7 -0
- package/tui/widgets.py +48 -0
package/CONFIG_ARCHITECTURE.md
CHANGED
|
@@ -191,6 +191,8 @@ list which is a decision rather than an omission.
|
|
|
191
191
|
- [File-ops workspace (ROADMAP §6)](#file-ops-workspace-roadmap-6)
|
|
192
192
|
- [/init (ROADMAP_v2 §24)](#init-roadmap_v2-24)
|
|
193
193
|
- [MCP teardown (ROADMAP_v2 §37 F6, #64)](#mcp-teardown-roadmap_v2-37-f6-64)
|
|
194
|
+
- [Network limits (ROADMAP_v3 §53)](#network-limits-roadmap_v3-53)
|
|
195
|
+
- [Reading web pages and PDFs (ROADMAP_v3 §92)](#reading-web-pages-and-pdfs-roadmap_v3-92)
|
|
194
196
|
- [Shell / sandbox (ROADMAP §7)](#shell-sandbox-roadmap-7)
|
|
195
197
|
- [Output redaction (#167/#49, batch 20)](#output-redaction-16749-batch-20)
|
|
196
198
|
- [Compaction (ROADMAP_v2 §21)](#compaction-roadmap_v2-21)
|
|
@@ -931,6 +933,113 @@ legacy "sse" transport keeps the SDK's fixed 1 MiB: `sse_client` takes no
|
|
|
931
933
|
size. An ordinary key rather than harness authority, like
|
|
932
934
|
`max_read_chars`: it is a resource bound, not a permission.
|
|
933
935
|
|
|
936
|
+
## Network limits (ROADMAP_v3 §53)
|
|
937
|
+
|
|
938
|
+
Four keys: one window and three ceilings. Every ceiling ships at 0, and a
|
|
939
|
+
meter at 0 admits every call, counts nothing and never opens the ledger, so
|
|
940
|
+
a harness nobody has configured behaves exactly as it did before §53 and
|
|
941
|
+
writes no file for it (IO1).
|
|
942
|
+
|
|
943
|
+
### `network_window_hours`
|
|
944
|
+
|
|
945
|
+
24, the owner's choice (IO8), and one window for all three meters rather
|
|
946
|
+
than one each, also the owner's. No span of this length may exceed a
|
|
947
|
+
meter's ceiling.
|
|
948
|
+
|
|
949
|
+
The length was weighed both ways. A shorter window bounds a burst more
|
|
950
|
+
tightly and frees room sooner, but over a day it lets through 24 / window
|
|
951
|
+
times the ceiling: a "250 MB" read as per day is 1 GB a day at 6 hours,
|
|
952
|
+
which a user finds out about by running out of data. A longer window maps
|
|
953
|
+
straight onto an allowance, and its failure is loud instead -- a refusal
|
|
954
|
+
that says when room returns, after a wait that can be the whole window.
|
|
955
|
+
24 hours is the shortest period allowances are commonly sold in.
|
|
956
|
+
|
|
957
|
+
The ledger's buckets are this window over 1,440 and never narrower than a
|
|
958
|
+
minute (IO10): 60 s at 24 hours, 30 minutes at 30 days. A bucket that
|
|
959
|
+
straddles the window's old edge counts whole, so a figure errs high by at
|
|
960
|
+
most one bucket and never low.
|
|
961
|
+
|
|
962
|
+
### `network_limit_tools_mb`
|
|
963
|
+
|
|
964
|
+
The tool meter's ceiling. `fetch_url`, `arxiv_search` and the scholar
|
|
965
|
+
lookup are counted at the wire through `_net_common.stream` and
|
|
966
|
+
`_net_common.get`. `web_search` is charged an ESTIMATE, 21,000 bytes per
|
|
967
|
+
result asked for (IO15, amending IO3), because `ddgs` talks through
|
|
968
|
+
primp, which has no hook. Measured live through a counting proxy, five
|
|
969
|
+
and ten results cost 85,746 and 206,637 bytes on the wire; IO3's "the size
|
|
970
|
+
of what it returned" would have counted 1,967 and 2,445. Re-measure when
|
|
971
|
+
`ddgs` moves, since which backends it queries decides the number.
|
|
972
|
+
|
|
973
|
+
### `network_limit_provider_mb`
|
|
974
|
+
|
|
975
|
+
The provider meter's ceiling: every model call -- chat, the research
|
|
976
|
+
passes, the critic, the embedder -- through event hooks on each SDK's own
|
|
977
|
+
HTTP client, which `core/client.py` builds with hooks only while this is
|
|
978
|
+
set. The upload is the large part, because every step re-sends the thread,
|
|
979
|
+
so this meter is admitted on what a request will SEND as well as on what is
|
|
980
|
+
already used: an upload that would pass the ceiling is refused whole,
|
|
981
|
+
before it leaves.
|
|
982
|
+
|
|
983
|
+
### `network_limit_mcp_mb`
|
|
984
|
+
|
|
985
|
+
The MCP meter's ceiling, for servers reached over `http` or `sse`. A
|
|
986
|
+
`stdio` server is a child process whose sockets are its own, and is not
|
|
987
|
+
counted. Admitted in `mcp_client.call_tool`, before a call is sent; the
|
|
988
|
+
hooks on the client only count.
|
|
989
|
+
|
|
990
|
+
**What all three share.** Decimal megabytes (1 MB = 1,000,000 bytes, as a
|
|
991
|
+
carrier counts), and download and upload together, the way an allowance is
|
|
992
|
+
charged (IO9). 0 is off, so each meter is enabled separately (IO1): a
|
|
993
|
+
local Ollama or a local MCP server costs no allowance and should not be
|
|
994
|
+
charged against one bought for a tether.
|
|
995
|
+
|
|
996
|
+
**A call is checked before it starts** (IO11): refused when its meter is
|
|
997
|
+
full or, where what it will send is known, when sending it would pass the
|
|
998
|
+
ceiling. A response already in flight completes and is counted, so a meter
|
|
999
|
+
can end a window over its ceiling by one response, and no body is ever cut
|
|
1000
|
+
part-way (IO6). A tool refusal reaches the model as the meter's own
|
|
1001
|
+
sentence, a provider refusal ends the turn with it and is never retried,
|
|
1002
|
+
and the transcript gets one warning for each run of refusals.
|
|
1003
|
+
|
|
1004
|
+
**The ledger** is `~/.config/venastine/network.db`, shared by every
|
|
1005
|
+
harness process and subagent (IO10). It holds counts, never traffic, and
|
|
1006
|
+
deletes rows past the window on every write, so it stops at about 1,440
|
|
1007
|
+
rows per meter however much traffic there was. Counts reach it at most once
|
|
1008
|
+
a minute and only when something was counted (IO12); a crash loses at most
|
|
1009
|
+
that minute. A file that cannot be read or written does not turn a meter
|
|
1010
|
+
off: the process's own counts still enforce, and `/network` says the
|
|
1011
|
+
ledger is not in use.
|
|
1012
|
+
|
|
1013
|
+
Not authority keys: a ceiling decides how much may be spent, which is
|
|
1014
|
+
`ensemble_mode`'s side of the line, not what may run. What none of them can
|
|
1015
|
+
count (IO5): shell commands (containers, WSL, SSH), `stdio` MCP servers,
|
|
1016
|
+
sign-in and token-refresh traffic, and TLS and TCP overhead. `/network`
|
|
1017
|
+
lists every meter, what it has used and when room returns.
|
|
1018
|
+
|
|
1019
|
+
## Reading web pages and PDFs (ROADMAP_v3 §92)
|
|
1020
|
+
|
|
1021
|
+
### `fetch_max_html_mb`
|
|
1022
|
+
|
|
1023
|
+
2, decimal megabytes (PT3, the owner's amendment of PG6). How much of one
|
|
1024
|
+
HTML page `fetch_url` downloads. What the model reads is the page's
|
|
1025
|
+
extracted text -- its main content without the site's navigation -- held up
|
|
1026
|
+
to 200,000 characters and paged; so this bounds the download, not the
|
|
1027
|
+
memory. Measured: Wikipedia's article began at HTML character 73,396, which
|
|
1028
|
+
the old 64 KB cap never reached. A page past the limit is read that far and
|
|
1029
|
+
says the rest was never retrieved.
|
|
1030
|
+
|
|
1031
|
+
### `fetch_max_pdf_mb`
|
|
1032
|
+
|
|
1033
|
+
32, decimal megabytes (PT6, the owner's number, configurable at their
|
|
1034
|
+
request). How large a PDF `fetch_url` will download. arXiv papers run 1-5 MB
|
|
1035
|
+
and the Llama 2 report is 13.7 MB. A PDF cannot be read in part, because its
|
|
1036
|
+
index is at the end, so one past the limit is refused whole -- before any of
|
|
1037
|
+
it is read when the server states its size. It is parsed with pypdf in
|
|
1038
|
+
`tools/isolation`'s child, which `tool_compute_timeout_s` stops.
|
|
1039
|
+
|
|
1040
|
+
Neither is an authority key: each bounds how much is downloaded, not what
|
|
1041
|
+
may run. Text that is neither HTML nor a PDF keeps PG6's 64 KB.
|
|
1042
|
+
|
|
934
1043
|
## Shell / sandbox (ROADMAP §7)
|
|
935
1044
|
|
|
936
1045
|
### `shell_binary`
|
package/README.md
CHANGED
|
@@ -46,6 +46,10 @@ You can also download and inspect the scripts before running them. They
|
|
|
46
46
|
download the shared Python installer completely, then execute it. It resolves
|
|
47
47
|
`main` to a full commit ID, downloads that source archive, and installs the
|
|
48
48
|
runtime dependencies in an isolated environment. It does not install Python.
|
|
49
|
+
When `uv` is on your PATH, it installs them — copying files rather than linking
|
|
50
|
+
them out of its cache — and pip does otherwise, or if uv fails. With no Python
|
|
51
|
+
3.11+ on your PATH, the scripts also ask uv for one it already has, and never
|
|
52
|
+
download one.
|
|
49
53
|
|
|
50
54
|
The source lives under `~/.local/share/venastine/app`, with a `venastine`
|
|
51
55
|
command in `~/.local/bin` (`venastine.cmd` on Windows). When that directory is
|
|
@@ -75,7 +79,8 @@ never replaced.
|
|
|
75
79
|
|
|
76
80
|
Choose a branch, tag, or full commit ID with `VENASTINE_REF`; choose locations
|
|
77
81
|
with `VENASTINE_INSTALL_DIR` and `VENASTINE_BIN_DIR`, or a Python executable
|
|
78
|
-
with `VENASTINE_PYTHON`; `VENASTINE_NO_MODIFY_PATH=1` leaves PATH alone
|
|
82
|
+
with `VENASTINE_PYTHON`; `VENASTINE_NO_MODIFY_PATH=1` leaves PATH alone, and
|
|
83
|
+
`VENASTINE_NO_UV=1` installs with pip even when uv is on your PATH. Set
|
|
79
84
|
these before running either command. The default
|
|
80
85
|
ref is `main`; older refs without `bin/venastine.py` cannot use this installer.
|
|
81
86
|
The installer itself is downloaded from `main`, even when selecting another
|
|
@@ -106,7 +111,7 @@ venastine --tui
|
|
|
106
111
|
```
|
|
107
112
|
|
|
108
113
|
|
|
109
|
-
**npm handles the setup for you.** It delivers the harness as a folder of source — there is no bundled binary — and Python still runs it, so the only prerequisite you provide is an interpreter on PATH. Everything after that happens on first launch: the launcher finds a suitable Python, tells you which one and what it is about to install, and builds an isolated environment with the pinned dependencies once you agree. It asks every time it would install something, never installs during `npm install` itself, and refuses rather than proceeding when there is no terminal to ask in.
|
|
114
|
+
**npm handles the setup for you.** It delivers the harness as a folder of source — there is no bundled binary — and Python still runs it, so the only prerequisite you provide is an interpreter on PATH. Everything after that happens on first launch: the launcher finds a suitable Python, tells you which one and what it is about to install, and builds an isolated environment with the pinned dependencies once you agree — with uv when it is on your PATH, as the GitHub installers do. It asks every time it would install something, never installs during `npm install` itself, and refuses rather than proceeding when there is no terminal to ask in.
|
|
110
115
|
|
|
111
116
|
Two things differ from a clone, both to make a command you run from anywhere behave sensibly:
|
|
112
117
|
|
|
@@ -181,7 +186,7 @@ Every launch flag is tabulated in the [CLI flag reference](#cli-flag-reference)
|
|
|
181
186
|
|
|
182
187
|
A turn prints as it runs, one step at a time: the model's reasoning, what it said, and a line for each tool call as it starts. During a turn, Ctrl+C twice within two seconds stops it at the next safe point; the first press only says so, so a stray one costs nothing. At the prompt, Ctrl+C or Ctrl+D exits. The thread id is printed after the first response so you can resume later — and resuming **replays the conversation**, so you can see what you are picking up. Tool calls replay as one line each; their results do not, since a single research turn can carry hundreds of kilobytes of fetched pages.
|
|
183
188
|
|
|
184
|
-
A line that starts with `/` is a command, as in the TUI, and never reaches the model; an unknown one is an error rather than a chat turn. The CLI has
|
|
189
|
+
A line that starts with `/` is a command, as in the TUI, and never reaches the model; an unknown one is an error rather than a chat turn. The CLI has nineteen: `/help`, `/quit`, `/threads`, `/resume`, `/new`, `/goal`, `/agent`, `/skill`, `/grill-me`, `/effort`, `/model`, `/compact`, `/summary`, `/ref`, `/memories`, `/forget`, `/claims`, `/call` and `/network`. They mean what the TUI's do: both shells read one catalog of commands, so a name, its arguments and its description cannot differ between them. `/threads` and `/ref` print a numbered list and ask for a number, or a thread id for one the list does not show. `/call` lists this conversation's tool calls, numbered, and `/call 3` shows the third in full: the whole command and what it returned, or a background session's output, or the run a subagent made. It is the CLI's version of ctrl+clicking a tool line in the TUI. `/model` here lasts for the session, since the CLI starts from `--model` or settings.json.
|
|
185
190
|
|
|
186
191
|
---
|
|
187
192
|
|
|
@@ -515,6 +520,7 @@ Symmetric, and applied centrally to every tool in every mode rather than by tool
|
|
|
515
520
|
|
|
516
521
|
- **Arguments are refused, not rewritten.** If a tool call carries something matching a credential pattern or a URL on the blocked-domain list, the call is refused. Silently rewriting an argument would run the tool with parameters neither you nor the model chose, and then report success.
|
|
517
522
|
- **Results are redacted.** Anything key-shaped in a tool's output becomes `[REDACTED]` before it reaches the model, the transcript, the database **or the log file**. This recurses through nested structures — third-party MCP servers return arbitrary JSON, and that was once the one path nothing scanned — and it covers *every* key of a result, not a list of expected ones, because the two search tools returned theirs under a key the list did not name. The log was a fourth sink and an unlisted exception rather than an accepted one: a failing tool's traceback carries the request that produced it, which for an HTTP client is a URL with the key in its query string.
|
|
523
|
+
- **A fetched page is its text, and a PDF is read.** `fetch_url` returns a page's main content without the site's menus, banners and scripts, with links marked `[L1]`, `[L2]` and their URLs listed beside each page of text; a PDF's text comes back page by page, parsed in a separate process that a timeout stops. A long document is read 5,000 characters at a time by offset, to its end. An image or archive is refused with a reason. `fetch_max_html_mb` and `fetch_max_pdf_mb` in `config.yaml` bound the downloads (2 MB and 32 MB).
|
|
518
524
|
- **URLs are checked before every request, including redirects.** `fetch_url` follows redirects by hand and re-checks each hop, so a public URL that redirects to a blocked domain or into your private network is refused *before* the request is issued. Addresses that are not publicly routable — loopback, private ranges, link-local, and the cloud metadata endpoint at `169.254.169.254` — are refused outright. The blocklist matches subdomains. **Known limitation:** the address check resolves and then hands the URL to the HTTP client, which resolves again, so a host whose DNS changes between the two is not covered.
|
|
519
525
|
- **The scan fails closed.** Traversal is depth-bounded so a hostile structure cannot exhaust the stack, and hitting that bound redacts rather than passing the value through. A bound that emits unchecked data is just a documented bypass.
|
|
520
526
|
- **Refusal reasons never quote the secret.** Explaining that a credential leaked, by printing it, would leak it into model context, the transcript and the database.
|
|
@@ -703,6 +709,7 @@ paths are cached and 200 matches offered; narrow the query when a limit is shown
|
|
|
703
709
|
| `/compact [--strength 1-5]` | Fold older turns now instead of waiting for the trigger. Recent turns keep exactly the protection an automatic compaction gives them |
|
|
704
710
|
| `/trigger [tokens\|off]` | Override **when this chat compacts**, for this session only. An absolute prompt size (`80k`), not a margin below the window. A value below the warning margin or the keep-recent floor is refused naming it; a value below the thread's current size is accepted and says a fold is coming |
|
|
705
711
|
| `/window [tokens\|off]` | Set this model's **context window** and remember it, per `(provider, model)` and across launches. It outranks both the provider's own answer and the built-in table, and it moves everything derived from the window: the chat compaction trigger, the research-pass backstop and the summarizer's input budget. Above what the provider reports it warns rather than refusing, because raising it is the point — a gateway or a self-hosted endpoint can report its own default rather than your deployment's |
|
|
712
|
+
| `/network` | What each network meter has used against its ceiling over the rolling window, which part is an estimate, and when room returns. Every ceiling is off until you set one in `config.yaml`; see [Budgets and stop conditions](#budgets-and-stop-conditions) |
|
|
706
713
|
| `/config [key] [value]` | Browse and set the harness's own settings without leaving the session. Typing `/config ` lists all 133 of them in the same panel the slash commands use, with the values each one takes and the value in the file; completing a key then offers that key's values. A value you have already changed reads `pending restart` until you relaunch, and bare `/config` lists every one of them, old to new — so several settings can be changed in a row and applied together. Bare `/config <key>` explains one, including what outranks it — an environment variable, a `settings.json` key — and containers are listed but edited in the file. A write goes through the whole document's validation first, keeps every comment in `config.yaml`, and offers to relaunch, because values are read once at startup. The nine AUTHORITY keys ask first, naming what the key permits |
|
|
707
714
|
| `/claims [run id]` | Open the claims view — tier, grounding status, assumption flags, score breakdown per claim — during a run or afterwards (**ctrl+l**) |
|
|
708
715
|
| `/copy [last\|report\|claims\|conversation\|all] [--file <path>]` | Copy out of the session. Defaults to the last response; `conversation` is the exchange alone — your turns, the answers, the reasoning, the tool calls and the diffs; `all` is everything on screen (the harness's own lines included) plus report plus claims. Clipboard delivery cannot be confirmed, so `--file <path>` is the route that provably worked |
|
|
@@ -861,6 +868,8 @@ Other ceilings worth knowing: the six maths tools run in killable subprocesses u
|
|
|
861
868
|
|
|
862
869
|
Subagents spawned in one model response run **concurrently**, up to `SUBAGENT_MAX_PARALLEL`. Their answers come back to the model in the order it asked for them however they finish, one approval question reaches you at a time, and the sidebar draws them as a tree rather than a chain. The database runs in SQLite's WAL mode to keep their writes from contending, which means `app.db` is accompanied by `app.db-wal` and `app.db-shm` while the harness is open — both are gitignored, and excluded from `git archive`, because a WAL file holds recently written messages.
|
|
863
870
|
|
|
871
|
+
**Network limits are off by default.** For a metered connection, `config.yaml` can cap what the harness pulls and pushes over a rolling window, 24 hours unless you change it, with a separate ceiling in decimal megabytes for each of three kinds of traffic: the network tools, the model provider's API, and MCP servers reached over HTTP. A local Ollama or a local MCP server need not count against an allowance, so each is switched on by its own ceiling. A call that would pass its ceiling is refused with a reason that says when room returns; one already running is never cut off, so a meter can end up over by one response. Counts are kept in `~/.config/venastine/network.db`, shared by every harness process, written at most once a minute, and pruned as they leave the window. Shell commands, `stdio` MCP servers, sign-in traffic and TLS overhead are not counted, and `web_search`'s figure is an estimate (its client cannot be counted). `/network` shows the meters, and the sidebar shows them while any is on.
|
|
872
|
+
|
|
864
873
|
### Logging
|
|
865
874
|
|
|
866
875
|
Two sinks from startup: stderr, and a rotating file — `logs/app.log` in the working directory, 1 MB per file, three backups kept. `AGENT_LOG_LEVEL` sets verbosity (a name like `INFO` or a number like `20`; anything else prints a warning naming the value and runs at `INFO`, as an unwritable `AGENT_LOG_FILE` does) and `AGENT_LOG_FILE` moves the file, creating the parent directory if needed. The file formatter redacts secret-shaped strings on the way out — the same patterns tool outputs get — because a failing tool's traceback routinely carries the request that produced it, and for an HTTP client that is a URL with the key in it.
|
|
@@ -1006,7 +1015,7 @@ note that shell approval is governed solely by `shell_approval_mode` -- `tool_ap
|
|
|
1006
1015
|
deliberately has no `shell` key, so an old file carrying one is refused at startup
|
|
1007
1016
|
naming the key — see `tests/BREAKING_CHANGES.md` §24.
|
|
1008
1017
|
|
|
1009
|
-
Run the test suite with `pytest` —
|
|
1018
|
+
Run the test suite with `pytest` — 9169 tests, fully offline, no API keys needed. The suite's own packages are `requirements-test.txt`, separate from `requirements.txt` since batch 136: they used to be in the shipped dependency list, so installing the harness also installed a test runner. It runs in parallel by default (`pytest-xdist`, 70% of your cores): **1:26 on a 16-core machine, against 9:06 single-process.** `pytest -n0` forces the old serial run, which is what you want under a debugger or when something is parsing the output. Eight further tests are marked `integration` and excluded by default: three spawn a real stdio MCP server, one runs an external program through the host fallback shell, one builds the hosted bundle's Docker image, and three run the installers' uv path against a real uv (`pytest -m integration`).
|
|
1010
1019
|
|
|
1011
1020
|
## Documentation
|
|
1012
1021
|
|
package/bin/venastine.mjs
CHANGED
|
@@ -242,11 +242,13 @@ function ask(question) {
|
|
|
242
242
|
async function ensureRuntime(python, rt, { assumeYes }) {
|
|
243
243
|
if (isReady(rt)) return;
|
|
244
244
|
|
|
245
|
+
const uv = findUv();
|
|
245
246
|
const summary =
|
|
246
247
|
'Venastine needs a Python environment (first run).\n' +
|
|
247
248
|
` python : ${python.version} (${python.executable})\n` +
|
|
248
249
|
` venv : ${rt.dir}\n` +
|
|
249
|
-
` install : ${countRequirements()} packages from requirements.txt
|
|
250
|
+
` install : ${countRequirements()} packages from requirements.txt` +
|
|
251
|
+
`${uv ? ', with uv' : ''}\n`;
|
|
250
252
|
|
|
251
253
|
if (!assumeYes) {
|
|
252
254
|
if (!process.stdin.isTTY) {
|
|
@@ -265,10 +267,9 @@ async function ensureRuntime(python, rt, { assumeYes }) {
|
|
|
265
267
|
process.stdout.write(summary);
|
|
266
268
|
}
|
|
267
269
|
|
|
270
|
+
let installer;
|
|
268
271
|
try {
|
|
269
|
-
|
|
270
|
-
run(rt.python, ['-m', 'pip', 'install', '--disable-pip-version-check',
|
|
271
|
-
'-r', REQUIREMENTS]);
|
|
272
|
+
installer = installRequirements(python, rt, uv);
|
|
272
273
|
} catch (e) {
|
|
273
274
|
// Leave nothing half-built behind: the next run must start clean rather
|
|
274
275
|
// than inherit a venv that is missing an unknown subset of its packages.
|
|
@@ -281,12 +282,56 @@ async function ensureRuntime(python, rt, { assumeYes }) {
|
|
|
281
282
|
requirementsHash: requirementsHash(),
|
|
282
283
|
python: python.executable,
|
|
283
284
|
pythonVersion: python.version,
|
|
285
|
+
installer,
|
|
284
286
|
createdAt: new Date().toISOString(),
|
|
285
287
|
}, null, 2));
|
|
286
288
|
}
|
|
287
289
|
|
|
288
|
-
|
|
289
|
-
|
|
290
|
+
/**
|
|
291
|
+
* uv, when it is on PATH and VENASTINE_NO_UV is unset (ROADMAP_v3 §93), the
|
|
292
|
+
* same rule scripts/install.py keeps for the GitHub installers.
|
|
293
|
+
*/
|
|
294
|
+
function findUv() {
|
|
295
|
+
const off = process.env.VENASTINE_NO_UV;
|
|
296
|
+
if (off && off !== '0') return null;
|
|
297
|
+
const r = spawnSync('uv', ['--version'], { encoding: 'utf8', windowsHide: true });
|
|
298
|
+
return r.status === 0 ? 'uv' : null;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* COPY, NEVER uv's DEFAULT LINK. On Linux and Windows uv hardlinks each file
|
|
303
|
+
* out of its cache, which would make the venv's code one inode with a file
|
|
304
|
+
* under ~/.cache/uv -- writable where ~/.config/venastine is protected.
|
|
305
|
+
* Bytecode is compiled as pip compiles it, so a first launch compiles nothing.
|
|
306
|
+
*/
|
|
307
|
+
const UV_INSTALL = ['pip', 'install', '--link-mode', 'copy', '--compile-bytecode'];
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* The venv, then requirements.txt in it: by uv when there is one, by pip
|
|
311
|
+
* otherwise. `python -m venv` either way, so the venv holds pip as it always
|
|
312
|
+
* has. A uv that fails -- too old, or blind to a mirror only pip.conf names
|
|
313
|
+
* -- costs a fresh venv and a pip install, never the launch. uv runs from
|
|
314
|
+
* the venv's directory so a project's uv settings in cwd are not read.
|
|
315
|
+
*/
|
|
316
|
+
function installRequirements(python, rt, uv) {
|
|
317
|
+
run(python.executable, ['-m', 'venv', rt.dir]);
|
|
318
|
+
if (uv) {
|
|
319
|
+
try {
|
|
320
|
+
run(uv, [...UV_INSTALL, '--python', rt.python, '-r', REQUIREMENTS], { cwd: rt.dir });
|
|
321
|
+
return 'uv';
|
|
322
|
+
} catch (e) {
|
|
323
|
+
process.stdout.write(`uv could not install them (${e.message}); starting again with pip.\n`);
|
|
324
|
+
fs.rmSync(rt.dir, { recursive: true, force: true });
|
|
325
|
+
run(python.executable, ['-m', 'venv', rt.dir]);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
run(rt.python, ['-m', 'pip', 'install', '--disable-pip-version-check',
|
|
329
|
+
'-r', REQUIREMENTS]);
|
|
330
|
+
return 'pip';
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
function run(cmd, args, options = {}) {
|
|
334
|
+
const r = spawnSync(cmd, args, { stdio: 'inherit', windowsHide: true, ...options });
|
|
290
335
|
if (r.error) throw r.error;
|
|
291
336
|
if (r.status !== 0) throw new Error(`${path.basename(cmd)} ${args[0]} exited ${r.status}`);
|
|
292
337
|
}
|
|
@@ -439,6 +484,16 @@ function configStateSummary() {
|
|
|
439
484
|
}
|
|
440
485
|
}
|
|
441
486
|
|
|
487
|
+
/** A stamp from before ROADMAP_v3 §93 names no installer, and was pip's. */
|
|
488
|
+
function installedBy(rt) {
|
|
489
|
+
if (!isReady(rt)) return `${findUv() ? 'uv' : 'pip'} (on the first run)`;
|
|
490
|
+
try {
|
|
491
|
+
return JSON.parse(fs.readFileSync(rt.stamp, 'utf8')).installer || 'pip';
|
|
492
|
+
} catch {
|
|
493
|
+
return 'pip';
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
|
|
442
497
|
function doctor(python, rt) {
|
|
443
498
|
const cwd = process.cwd();
|
|
444
499
|
const env = childEnv();
|
|
@@ -450,6 +505,7 @@ function doctor(python, rt) {
|
|
|
450
505
|
` python : ${python.version} (${python.executable})`,
|
|
451
506
|
` venv : ${rt.dir}`,
|
|
452
507
|
` venv ready : ${isReady(rt) ? 'yes' : 'no (first run will build it)'}`,
|
|
508
|
+
` installed by : ${installedBy(rt)}`,
|
|
453
509
|
` cwd : ${cwd}`,
|
|
454
510
|
` providers.json: ${env.AGENT_PROVIDERS_FILE
|
|
455
511
|
|| (fs.existsSync(localProviders) ? localProviders : '(none found)')}`,
|
package/bin/venastine.py
CHANGED
|
@@ -48,7 +48,9 @@ def main(argv=None):
|
|
|
48
48
|
env = child_env(Path.cwd(), Path.home(), os.environ)
|
|
49
49
|
if argv == ["--venastine-doctor"]:
|
|
50
50
|
version = json.loads((root / "package.json").read_text(encoding="utf-8"))["version"]
|
|
51
|
-
|
|
51
|
+
# An install from before ROADMAP_v3 §93 recorded no installer, and was pip's.
|
|
52
|
+
print(f"venastine {version}\n commit: {runtime['commit']}\n package root: {root}\n python: {python}\n"
|
|
53
|
+
f" installed by: {runtime.get('installer', 'pip')}\n cwd: {Path.cwd()}")
|
|
52
54
|
for name in ("AGENT_PROVIDERS_FILE", "APP_DB_PATH", "AGENT_LOG_FILE"):
|
|
53
55
|
print(f" {name}: {env.get(name, '(local/default)')}")
|
|
54
56
|
return 0
|
package/cli_commands.py
CHANGED
|
@@ -663,6 +663,15 @@ def _cmd_memories(session: ChatSession, args: str) -> None:
|
|
|
663
663
|
print_memories()
|
|
664
664
|
|
|
665
665
|
|
|
666
|
+
def _cmd_network(session: ChatSession, args: str) -> None:
|
|
667
|
+
"""ROADMAP_v3 §53 (IO13). The TUI's /network, line for line: both
|
|
668
|
+
print `_net_common.network_report`."""
|
|
669
|
+
from tools.builtin import _net_common
|
|
670
|
+
|
|
671
|
+
for line in _net_common.network_report():
|
|
672
|
+
_out(line)
|
|
673
|
+
|
|
674
|
+
|
|
666
675
|
def _cmd_forget(session: ChatSession, args: str) -> None:
|
|
667
676
|
raw = args.strip()
|
|
668
677
|
if not raw:
|
|
@@ -823,6 +832,7 @@ def register_cli_commands() -> None:
|
|
|
823
832
|
bind("help", _cmd_help),
|
|
824
833
|
bind("memories", _cmd_memories),
|
|
825
834
|
bind("model", _cmd_model),
|
|
835
|
+
bind("network", _cmd_network),
|
|
826
836
|
bind("new", _cmd_new),
|
|
827
837
|
bind("quit", _cmd_quit),
|
|
828
838
|
bind("ref", _cmd_ref),
|
package/config.yaml
CHANGED
|
@@ -595,6 +595,57 @@ teardown_budget_s: 10.0
|
|
|
595
595
|
# What reaches the model is bounded separately, by max_read_chars.
|
|
596
596
|
mcp_max_event_bytes: 16777216
|
|
597
597
|
|
|
598
|
+
# ======================================================================
|
|
599
|
+
# Network limits
|
|
600
|
+
# ======================================================================
|
|
601
|
+
|
|
602
|
+
# A ceiling on what the harness pulls and pushes over any rolling window,
|
|
603
|
+
# for a metered connection. Every ceiling ships at 0, which means no limit,
|
|
604
|
+
# no counting and no file. Each one is in decimal megabytes (1 MB =
|
|
605
|
+
# 1,000,000 bytes, the way carriers count) and covers both directions.
|
|
606
|
+
#
|
|
607
|
+
# Three meters, enabled separately, because they are not the same kind of
|
|
608
|
+
# traffic: a local Ollama or a local MCP server costs no allowance.
|
|
609
|
+
# tools fetch_url, arxiv_search, web_search and the scholar lookup.
|
|
610
|
+
# provider every model call: chat, the research passes, the embedder.
|
|
611
|
+
# The upload is the big part, since every step re-sends the
|
|
612
|
+
# thread.
|
|
613
|
+
# mcp MCP servers reached over "http" or "sse".
|
|
614
|
+
#
|
|
615
|
+
# A call is checked before it starts. One that would pass its ceiling is
|
|
616
|
+
# refused with a reason, and one already running is never cut off, so a
|
|
617
|
+
# meter can end up over by one response. Counts are kept in
|
|
618
|
+
# ~/.config/venastine/network.db, shared by every harness process, and
|
|
619
|
+
# written at most once a minute. Entries older than the window are deleted.
|
|
620
|
+
#
|
|
621
|
+
# What these CANNOT count: shell commands (containers, WSL, SSH), "stdio"
|
|
622
|
+
# MCP servers, sign-in and token-refresh traffic, and TLS/TCP overhead.
|
|
623
|
+
# web_search's figure is an estimate, measured at about 21 kB per result
|
|
624
|
+
# asked for, because its client has no way to count. /network shows every
|
|
625
|
+
# meter, what it has used, and when room returns.
|
|
626
|
+
network_window_hours: 24
|
|
627
|
+
network_limit_tools_mb: 0
|
|
628
|
+
network_limit_provider_mb: 0
|
|
629
|
+
network_limit_mcp_mb: 0
|
|
630
|
+
|
|
631
|
+
# ======================================================================
|
|
632
|
+
# Reading web pages and PDFs
|
|
633
|
+
# ======================================================================
|
|
634
|
+
|
|
635
|
+
# How much fetch_url downloads of one HTML page or one PDF, in decimal
|
|
636
|
+
# megabytes. What the model reads is the extracted TEXT -- a page without
|
|
637
|
+
# its navigation, a PDF's words -- held up to 200,000 characters at a time
|
|
638
|
+
# and paged through; an offset past that fetches again and serves the rest.
|
|
639
|
+
#
|
|
640
|
+
# An HTML page past its limit is read as far as the limit and says the rest
|
|
641
|
+
# was never retrieved. A PDF cannot be read in part (its index is at the
|
|
642
|
+
# end), so one past its limit is refused whole, before it is downloaded
|
|
643
|
+
# when the server states its size. PDFs are parsed with pypdf in a separate
|
|
644
|
+
# process that tool_compute_timeout_s stops. Text that is neither (JSON,
|
|
645
|
+
# plain text, XML) keeps its 64 KB read limit.
|
|
646
|
+
fetch_max_html_mb: 2
|
|
647
|
+
fetch_max_pdf_mb: 32
|
|
648
|
+
|
|
598
649
|
# ======================================================================
|
|
599
650
|
# Shell and sandbox
|
|
600
651
|
# ======================================================================
|
package/config_schema.py
CHANGED
|
@@ -401,6 +401,22 @@ class HarnessConfig(_Model):
|
|
|
401
401
|
# -- MCP results -------------------------------------------------------
|
|
402
402
|
mcp_max_event_bytes: PositiveInt
|
|
403
403
|
|
|
404
|
+
# -- Network limits (ROADMAP_v3 section 53) ----------------------------
|
|
405
|
+
# One window for all three meters (IO8) and one ceiling each, in
|
|
406
|
+
# decimal megabytes, where 0 is off (IO9). Not authority keys: a
|
|
407
|
+
# ceiling decides how much may be spent, which is the line
|
|
408
|
+
# `ensemble_mode` sits on, not what may run.
|
|
409
|
+
network_window_hours: PositiveNumber
|
|
410
|
+
network_limit_tools_mb: NonNegativeNumber
|
|
411
|
+
network_limit_provider_mb: NonNegativeNumber
|
|
412
|
+
network_limit_mcp_mb: NonNegativeNumber
|
|
413
|
+
|
|
414
|
+
# -- Reading web pages and PDFs (batch 240) ----------------------------
|
|
415
|
+
# The owner's amendment of PG6: what is HELD is extracted text, so these
|
|
416
|
+
# bound the download, not the memory.
|
|
417
|
+
fetch_max_html_mb: PositiveNumber
|
|
418
|
+
fetch_max_pdf_mb: PositiveNumber
|
|
419
|
+
|
|
404
420
|
# -- Shell / sandbox ---------------------------------------------------
|
|
405
421
|
shell_binary: str
|
|
406
422
|
allow_insecure_sandbox_fallback: StrictBool
|
package/core/client.py
CHANGED
|
@@ -70,10 +70,11 @@ def api_initialization(provider_name: str):
|
|
|
70
70
|
client = _chatgpt_client()
|
|
71
71
|
elif entry.get("is_v1_compatible", False):
|
|
72
72
|
from openai import OpenAI
|
|
73
|
-
client = OpenAI(base_url=entry["API_URL"], api_key=entry["API_KEY"]
|
|
73
|
+
client = OpenAI(base_url=entry["API_URL"], api_key=entry["API_KEY"],
|
|
74
|
+
**_metered("openai"))
|
|
74
75
|
elif provider_name == "GOOGLE":
|
|
75
76
|
from google import genai
|
|
76
|
-
client = genai.Client(api_key=entry["API_KEY"])
|
|
77
|
+
client = genai.Client(api_key=entry["API_KEY"], **_metered("google"))
|
|
77
78
|
elif provider_name == "ANTHROPIC":
|
|
78
79
|
# Batch 234. Refused HERE, before a client exists, because the SDK
|
|
79
80
|
# no longer says what is wrong: 2.x sends the key as `Bearer <key>`,
|
|
@@ -85,7 +86,7 @@ def api_initialization(provider_name: str):
|
|
|
85
86
|
if not entry.get("API_KEY"):
|
|
86
87
|
raise ValueError(credentials.empty_key_refusal(provider_name))
|
|
87
88
|
from anthropic import Anthropic
|
|
88
|
-
client = Anthropic(api_key=entry["API_KEY"])
|
|
89
|
+
client = Anthropic(api_key=entry["API_KEY"], **_metered("anthropic"))
|
|
89
90
|
# Add further proprietary API formats here
|
|
90
91
|
else:
|
|
91
92
|
raise ValueError(f"Provider {provider_name} is not currently supported")
|
|
@@ -122,7 +123,47 @@ def _chatgpt_client():
|
|
|
122
123
|
from core import chatgpt_auth
|
|
123
124
|
|
|
124
125
|
return OpenAI(base_url=chatgpt_auth.RESOURCE,
|
|
125
|
-
api_key=chatgpt_auth.access_token, max_retries=0
|
|
126
|
+
api_key=chatgpt_auth.access_token, max_retries=0,
|
|
127
|
+
**_metered("openai"))
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def _metered(sdk: str) -> dict:
|
|
131
|
+
"""The extra constructor arguments that put the provider meter on a
|
|
132
|
+
client (ROADMAP_v3 §53, IO4) -- `{}` while that meter is off.
|
|
133
|
+
|
|
134
|
+
EMPTY BY DEFAULT, AND THAT IS THE POINT: with no provider ceiling every
|
|
135
|
+
SDK builds the client it always built, so nobody who has not set a
|
|
136
|
+
limit runs a different HTTP stack because this exists.
|
|
137
|
+
|
|
138
|
+
THE SDK'S OWN DEFAULT CLIENT, WITH HOOKS, where the SDK offers one.
|
|
139
|
+
`DefaultHttpxClient` carries anthropic's and openai's timeouts,
|
|
140
|
+
connection limits and redirect setting; a bare `httpx2.Client` would
|
|
141
|
+
have brought httpx2's five-second timeout to a model call. google-genai
|
|
142
|
+
has no such class: its own client is an httpx one that follows
|
|
143
|
+
redirects and takes its timeout per request, so an httpx2 client set
|
|
144
|
+
to follow redirects is the same behaviour (measured: plain, streamed
|
|
145
|
+
and embedding calls all pass through it).
|
|
146
|
+
|
|
147
|
+
The client is built once per provider -- `_client_cache` -- and the
|
|
148
|
+
ceiling is read when a request is made, so the hooks stay right for
|
|
149
|
+
the life of the client.
|
|
150
|
+
"""
|
|
151
|
+
from tools.builtin import _net_common
|
|
152
|
+
|
|
153
|
+
if not _net_common.PROVIDER.enabled():
|
|
154
|
+
return {}
|
|
155
|
+
hooks = _net_common.provider_event_hooks()
|
|
156
|
+
if sdk == "google":
|
|
157
|
+
import httpx2
|
|
158
|
+
from google.genai import types
|
|
159
|
+
|
|
160
|
+
return {"http_options": types.HttpOptions(httpx_client=httpx2.Client(
|
|
161
|
+
follow_redirects=True, event_hooks=hooks))}
|
|
162
|
+
if sdk == "anthropic":
|
|
163
|
+
from anthropic import DefaultHttpxClient
|
|
164
|
+
else:
|
|
165
|
+
from openai import DefaultHttpxClient
|
|
166
|
+
return {"http_client": DefaultHttpxClient(event_hooks=hooks)}
|
|
126
167
|
|
|
127
168
|
|
|
128
169
|
def forget_client(provider_name: str) -> None:
|
package/core/commands.py
CHANGED
|
@@ -125,6 +125,10 @@ _SPECS = (
|
|
|
125
125
|
"the CLI does not have."}),
|
|
126
126
|
CommandSpec("model", "switch provider and/or model for this session",
|
|
127
127
|
"[[PROVIDER] name]"),
|
|
128
|
+
# ROADMAP_v3 §53 (IO13). Both shells: a line terminal on a metered
|
|
129
|
+
# connection needs the figure as much as the TUI does. 47 characters
|
|
130
|
+
# with its name, inside the slash panel's 50 at 80x24.
|
|
131
|
+
CommandSpec("network", "network data used against its limits"),
|
|
128
132
|
CommandSpec("new", "start a new thread"),
|
|
129
133
|
CommandSpec("quit", "exit the harness", aliases=("exit", "bye")),
|
|
130
134
|
CommandSpec("ref", "reference another conversation's summary",
|
package/core/provider_errors.py
CHANGED
|
@@ -43,6 +43,18 @@ Everything else is NOT: a bad request, an auth failure or an unknown model
|
|
|
43
43
|
fails identically on every attempt, and a harness error -- D21's
|
|
44
44
|
RuntimeError, a ValueError from message translation -- is a bug, not
|
|
45
45
|
weather, and retrying it would only delay the traceback.
|
|
46
|
+
|
|
47
|
+
A NETWORK-LIMIT REFUSAL IS NEVER TRANSIENT, AND IT IS FOUND IN THE CHAIN
|
|
48
|
+
(ROADMAP_v3 §53, batch 239). The provider meter refuses inside the SDK's
|
|
49
|
+
own HTTP client, and the SDKs do not agree on what that looks like from
|
|
50
|
+
here: openai and google-genai raise the refusal itself, while anthropic
|
|
51
|
+
wraps it -- measured -- as `APIConnectionError("Connection error.")`, its
|
|
52
|
+
cause the refusal, after two retries of its own that the meter refuses at
|
|
53
|
+
zero bytes. Read at the top only, that is a connection failure, retried
|
|
54
|
+
twice more here with a wait, and then described as "Connection error.",
|
|
55
|
+
which says nothing true. So both questions this module answers walk
|
|
56
|
+
`__cause__` / `__context__` first: a refusal anywhere in the chain is not
|
|
57
|
+
worth another attempt, and its own sentence is the description.
|
|
46
58
|
"""
|
|
47
59
|
|
|
48
60
|
from random import random
|
|
@@ -92,6 +104,27 @@ def _names(exc: BaseException) -> set:
|
|
|
92
104
|
return {cls.__name__ for cls in type(exc).__mro__}
|
|
93
105
|
|
|
94
106
|
|
|
107
|
+
#: By NAME, for the reason above: this module imports nothing of the
|
|
108
|
+
#: harness's tools either, and the class lives in `tools/builtin/_net_common`.
|
|
109
|
+
_REFUSAL_NAME = "NetworkLimitReached"
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def network_refusal(exc: BaseException) -> Optional[BaseException]:
|
|
113
|
+
"""The network-limit refusal in `exc`'s chain, or None (§53).
|
|
114
|
+
|
|
115
|
+
Bounded, because a chain can be a cycle: an exception raised while
|
|
116
|
+
handling itself is its own `__context__`.
|
|
117
|
+
"""
|
|
118
|
+
seen: set = set()
|
|
119
|
+
current: Optional[BaseException] = exc
|
|
120
|
+
while current is not None and id(current) not in seen:
|
|
121
|
+
if _REFUSAL_NAME in _names(current):
|
|
122
|
+
return current
|
|
123
|
+
seen.add(id(current))
|
|
124
|
+
current = current.__cause__ or current.__context__
|
|
125
|
+
return None
|
|
126
|
+
|
|
127
|
+
|
|
95
128
|
def _as_status(value) -> Optional[int]:
|
|
96
129
|
if isinstance(value, str) and value.isdigit():
|
|
97
130
|
value = int(value)
|
|
@@ -141,6 +174,8 @@ def _body_verdict(body) -> Optional[bool]:
|
|
|
141
174
|
|
|
142
175
|
def is_transient(exc: BaseException) -> bool:
|
|
143
176
|
"""Would the same call plausibly succeed if simply made again?"""
|
|
177
|
+
if network_refusal(exc) is not None:
|
|
178
|
+
return False
|
|
144
179
|
names = _names(exc)
|
|
145
180
|
if names & _NEVER_TRANSIENT_NAMES:
|
|
146
181
|
return False
|
|
@@ -226,7 +261,12 @@ def describe(exc: BaseException) -> str:
|
|
|
226
261
|
and the retry warning, so the three never describe the same exception
|
|
227
262
|
three ways. Not redacted: every caller that shows or
|
|
228
263
|
stores it redacts the whole line it is part of.
|
|
264
|
+
|
|
265
|
+
A network-limit refusal is described as ITSELF wherever it sits in the
|
|
266
|
+
chain (§53): under anthropic the top of the chain is a connection error
|
|
267
|
+
whose message is "Connection error.", and the refusal is the cause.
|
|
229
268
|
"""
|
|
269
|
+
exc = network_refusal(exc) or exc
|
|
230
270
|
text = " ".join(str(exc).split())
|
|
231
271
|
if len(text) > DESCRIBE_LIMIT:
|
|
232
272
|
text = text[:DESCRIBE_LIMIT - 1].rstrip() + "…"
|
|
@@ -51,7 +51,8 @@ import re
|
|
|
51
51
|
from datetime import date, timedelta
|
|
52
52
|
|
|
53
53
|
import config
|
|
54
|
-
from tools.builtin
|
|
54
|
+
from tools.builtin import _net_common
|
|
55
|
+
from tools.builtin._net_common import NetworkLimitReached, TTLCache
|
|
55
56
|
|
|
56
57
|
logger = logging.getLogger(__name__)
|
|
57
58
|
|
|
@@ -233,9 +234,11 @@ class ScholarLookup:
|
|
|
233
234
|
INJECTABLE, and every test injects: the suite runs offline, and a
|
|
234
235
|
scoring rule tested through a real socket is a scoring rule tested
|
|
235
236
|
on somebody's connection.
|
|
236
|
-
"""
|
|
237
|
-
import httpx
|
|
238
237
|
|
|
238
|
+
`_net_common.get` is `httpx.get`, admitted and counted against the
|
|
239
|
+
tool meter (ROADMAP_v3 §53), which imports httpx lazily for the
|
|
240
|
+
reason this function used to.
|
|
241
|
+
"""
|
|
239
242
|
from safety.policy_enforcement import is_url_permitted
|
|
240
243
|
|
|
241
244
|
url = f"{config.SCHOLAR_API_URL.rstrip('/')}/{path.lstrip('/')}"
|
|
@@ -247,9 +250,9 @@ class ScholarLookup:
|
|
|
247
250
|
# git config or an environment variable is not a rate-limit
|
|
248
251
|
# optimisation, it is an unasked-for disclosure.
|
|
249
252
|
params = {**params, "mailto": config.SCHOLAR_MAILTO}
|
|
250
|
-
response =
|
|
253
|
+
response = _net_common.get(
|
|
251
254
|
url, params=params, timeout=config.SCHOLAR_TIMEOUT_S,
|
|
252
|
-
headers={"User-Agent":
|
|
255
|
+
headers={"User-Agent": _net_common.USER_AGENT},
|
|
253
256
|
follow_redirects=True)
|
|
254
257
|
response.raise_for_status()
|
|
255
258
|
return response.json()
|
|
@@ -267,6 +270,12 @@ class ScholarLookup:
|
|
|
267
270
|
for _ in range(config.SCHOLAR_MAX_RETRIES + 1):
|
|
268
271
|
try:
|
|
269
272
|
payload = self._fetch(path, params)
|
|
273
|
+
except NetworkLimitReached as exc:
|
|
274
|
+
# §53. Refused the same way on every attempt, so not
|
|
275
|
+
# retried; the lookup degrades for this run as an outage
|
|
276
|
+
# does, and the meter has already said why, once.
|
|
277
|
+
last = exc
|
|
278
|
+
break
|
|
270
279
|
except Exception as exc: # noqa: BLE001 - degraded, never fatal
|
|
271
280
|
last = exc
|
|
272
281
|
continue
|