Commit e0b4ddd
feat(agent,scripting): client reuse + usage tracking (v2.51.204)
`agent.fetch` now inherits the engine's proxy-configured HTTP client
instead of using a process-wide static — scripts go through the same
proxy / TLS / headers as the rest of the agent. Per-call fetch + script
activity is tracked in lock-free atomics on the engine.
## Client reuse
* `ScriptEngine` gains a `default_client: reqwest::Client` field plus
`with_client(...)` builder method.
* New per-call methods `run_python_with_client` and
`run_javascript_with_client` accept an explicit client override.
* Chrome dispatcher (`run_embedded_script`) now reads
`engine.client.clone()` (cheap — reqwest::Client is internally Arc'd)
and routes through the `*_with_client` variant when set. Scripts
inherit the agent's proxy without any extra wiring.
* `Job` carries the client into the worker; native `agent.fetch` hooks
use that client instead of the static fallback. No more per-script
client construction.
## Usage tracking
* New `ScriptUsage` struct with atomic counters: `scripts_run`,
`scripts_timed_out`, `scripts_failed`, `fetch_calls`, `fetch_errors`,
`fetch_bytes_in`.
* No mutexes — counters are `AtomicU64` with `Ordering::Relaxed` (we
want monotonic activity totals, not synchronization).
* Engine exposes `usage_snapshot() -> ScriptUsageSnapshot` for plain-data
reads + `usage_handle() -> Arc<ScriptUsage>` for live observation.
## Tests
All 20 scripting tests still pass (parallel + --test-threads=1).
cargo fmt + clippy clean across scripting + chrome+scripting.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 6aea8e5 commit e0b4ddd
14 files changed
Lines changed: 289 additions & 75 deletions
File tree
- spider_agent_html
- spider_agent_types
- spider_agent
- src
- automation
- scripting
- spider_cli
- spider_mcp
- spider_utils
- spider_worker
- spider
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
32 | | - | |
| 31 | + | |
| 32 | + | |
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5835 | 5835 | | |
5836 | 5836 | | |
5837 | 5837 | | |
5838 | | - | |
5839 | | - | |
5840 | | - | |
| 5838 | + | |
| 5839 | + | |
| 5840 | + | |
| 5841 | + | |
| 5842 | + | |
| 5843 | + | |
| 5844 | + | |
| 5845 | + | |
| 5846 | + | |
| 5847 | + | |
| 5848 | + | |
| 5849 | + | |
| 5850 | + | |
| 5851 | + | |
| 5852 | + | |
| 5853 | + | |
5841 | 5854 | | |
5842 | 5855 | | |
5843 | 5856 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
37 | 41 | | |
38 | 42 | | |
39 | 43 | | |
| |||
101 | 105 | | |
102 | 106 | | |
103 | 107 | | |
| 108 | + | |
| 109 | + | |
104 | 110 | | |
105 | 111 | | |
106 | 112 | | |
| |||
373 | 379 | | |
374 | 380 | | |
375 | 381 | | |
376 | | - | |
377 | | - | |
378 | | - | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
379 | 387 | | |
380 | 388 | | |
381 | 389 | | |
| |||
0 commit comments