Repository navigation
Description
Problem
Everyone who audits many sites (agencies, researchers, CI over a portfolio) ends up writing their own runner around squirrel audit <url>. Each runner reinvents the same things, and several of the hard parts are not safe to do from outside the CLI: parallelism against the shared local stores (see the concurrent-audit lock issue), resuming after a crash or reboot, recording per-URL failures (unreachable, off-site seed redirect, timeout) next to the reports instead of in scrollback, and deciding retention for the shared content store and keep_audits when hundreds of audits run (the 1 GB default cap and keep_audits = 3 are tuned for one site, not a corpus).
Proposal
A documented batch mode, for example squirrel audit --urls-file urls.txt --out-dir reports/ [--concurrency N]:
- reads one URL per line (comments and blanks ignored);
- runs up to N audits at once with a safe default;
- writes one report per URL into the directory with a stable file name;
- appends one record per URL to a results file (JSONL: url, status, exit reason, score, duration, error text);
- resumes: a re-run skips URLs that already have a completed record and retries failed ones on request (
--retry-failed); - prints a one-line notice when retention or the content-store cap retires or evicts data during the run, and the docs include a "batch and corpus use" recipe for
[storage] keep_auditsandcontent_store_max_bytes(envSQUIRREL_CONTENT_STORE_MAX_BYTES).
Acceptance Criteria
-
squirrel audit --urls-file <file>audits every listed URL and writes one report each plus a JSONL results file with a per-URL status and error. - Killing the process and re-running with the same arguments does not redo completed URLs.
- A URL that fails (unreachable, refused, timeout) is recorded with its reason and does not stop the batch; the exit code says whether any URL failed.
-
--concurrency Nis respected and 10 concurrent audits complete without storage lock errors. -
docs/cli/audit.mdxdocuments the flag, the results file schema and a batch retention recipe;completion.tslists the new flags. - Prerequisite: Concurrent squirrel audit processes fail with 'SQLite database is busy (locked)' #1226 (concurrent audits and the shared stores) is fixed first; batch mode is not enabled above
--concurrency 1before it. - Each URL runs as a child
squirrel auditprocess and the manifest record (v,url,key,status,reason,exitCode,attempt, timings,report,score,pages,finalUrl,error,notes) uses the audit status vocabulary (completed,partial,blocked,unreachable,redirected,failed) plustimeout,crashed,rejected,skipped-budget; a child that dies without a record is recorded ascrashed. - Batch exit code:
0all completed or partial,1the batch could not run,2only--fail-ontripped,6at least one URL failed (new, documented in the exit-code table). - The urls-file is treated as untrusted: only http and https, no userinfo, size and length caps, non-public hosts rejected unless
--allow-private-hosts, report file names derived from a hash of the URL. - Two URLs of the same project never run at once; a lock file stops two batches on one out-dir; SIGTERM is forwarded to children and the next run resumes.
- Signed-in batches are ephemeral by default, estimate their worst-case credits up front, require
--yesand honour--max-credits. -
--urls-filerejects-o,--resume,--project-nameand--summarywith a clear message.
Activity
nc9 commentedon Oct 30, 2026
Spec: batch mode (
squirrel audit --urls-file)Status: proposal for review, no code yet. The acceptance criteria in the issue stand; the spec adds the pieces they do not name (exit codes, the status vocabulary, the child protocol, security of the input file, credits) and a few corrections. Where it differs from the issue, the issue body is updated below.
1. Surface
--urls-filereplaces the positional URL (giving both is an error). One URL per line; blank lines and#comments ignored;-reads stdin. Optional per-line overrides are out of scope (a corpus with different settings per site is several batches).--out-diris required.-o/--outputis rejected with--urls-file(one file per URL),-f/--formatapplies to every report (defaultjson, because the consumer is a machine).--max-pages,-C,--max-duration,--offline,--passive,--fail-on,--rule-include,--header, config). Flags that make no sense per batch are rejected:--resume(it means "resume an interrupted crawl", batch resume is automatic and described below),--project-name,--summary.squirrel auditstays the surface: the command-scoping rule puts project-scoped commands at top level and a batch is many audits. A separatesquirrel batchwas considered and rejected: it would duplicate the whole audit flag set.--concurrency N(defaultmin(4, max(1, floor(cores / 2))), max 16),--retry-failed,--restart(ignore and replace the results file),--url-timeout <seconds>(hard wall-clock kill per URL, defaultmax-duration * 1.5 + 60when--max-durationis set, else none),--max-urls N(default 100000),--allow-private-hosts,--max-credits N(signed-in runs, section 9),--keep-data(section 8).2. Architecture: an orchestrator that runs
squirrel auditchildrenRun each URL as a child process of the same binary (
process.execPathwith the audit arguments), not as an in-process pool.Why not in-process: the audit command is written as a process. It sets
process.exitCode, installs signal handlers, writes progress to the terminal, holds process-global singletons (the content store and link cache handles, the logger, the retained-store lease) and assumes one run's memory (a 30 to 100 page audit is hundreds of MB; a memory-hungry or wedged audit would take the batch down). A child gets crash isolation, a real exit code per URL, a kill switch for a wedged crawl, and the exact behaviour a user sees runningsquirrel auditby hand. The cost is one process start per URL (tens of milliseconds, negligible next to a crawl) and SQLite contention between children, which is the next section.Child protocol. The orchestrator passes a hidden
--batch-record <file>to each child. On exit the child writes one JSON record there (status, reason code, score, pages, duration, retention notes, final URL, report path). The orchestrator reads it, adds the child's exit code and signal, and appends to the manifest. A child that dies before writing (OOM kill, SIGKILL, crash) has no record: the orchestrator recordscrashedwith the signal. No stdout/stderr scraping: the retention and eviction notices from the issue ("one-line notice when retention or the content-store cap retires data") travel in the record'snotesand the orchestrator prints them once per occurrence.3. Hard prerequisite: #1226
The children share
~/.squirrel/content-store.dband the link cache. #1226 (concurrent audits fail withSQLite database is busy) is open and is the same defect the batch would hit on its first run at--concurrency 4. Batch mode must not ship before #1226's criteria hold (busy timeout first,BEGIN IMMEDIATEfor contending writes, an error naming the file and the wait). The batch's own test is that issue's repro at 10 and the criterion "10 concurrent audits complete without storage lock errors". Until then the default--concurrencywould have to be 1, which defeats the feature, so the order is #1226, then batch.Two URLs of the same registrable project (same project name, so the same
project.db) must not run at once: the crawl lease (#946) exists per project, but two children contending for it just wastes a run. The scheduler keeps a set of active project names and defers a URL whose project is busy (it is picked up when the other finishes). Different hosts of one site audited as separate URLs are not special-cased beyond that.4. The manifest (
results.jsonl) and statuses<out-dir>/results.jsonl, append-only, one JSON object per line, written only by the orchestrator (one writer,O_APPEND, onewriteper record so lines never interleave). Record:{ "v": 1, "url": "https://example.com/", "key": "example.com-3fa9c1", "status": "completed", "reason": null, "exitCode": 0, "attempt": 1, "startedAt": "2026-10-30T10:00:00.000Z", "finishedAt": "2026-10-30T10:01:12.000Z", "durationMs": 72000, "report": "example.com-3fa9c1.json", "score": 87, "pages": 30, "finalUrl": null, "error": null, "notes": [] }statusis the existing audit vocabulary plus three batch-only values:completed,partial(includingmax_duration, feat(cli): audit --max-duration stops at a wall-clock budget and writes a partial report #1271 #1324),blocked(CLI: fail the audit on WAF/bot challenge and block pages (all major perimeter providers), report blocked pages instead of auditing them #1253, exit 3),unreachable(fix(cli): offline level snapshot reports what ran; unreachable start URL writes a report, exit 5 #1275 #1269 #1297, exit 5),redirected(feat(cli): audit where a start URL redirects, with consent for another site (#1281) #1282, exit 4;finalUrland the chain are carried so the operator can re-queue the destination),failed(exit 1: invalid URL, crawl failed, no page fetched), plustimeout(killed by--url-timeout),crashed(no record, killed by a signal) andrejected(refused before running, withreason: bad scheme, private host, over length, duplicate) andskipped-budget(not started because--max-creditswould be passed).reasonis the audit's reason code (dns,tls,connection,http_4xx,max_duration, ...) from the shared failure vocabulary, so the manifest and a report agree.runningrecord is written when a URL starts (status: "running"). A later record for the samekeysupersedes it; arunningrecord with no successor at resume time means the process died and is treated ascrashed.erroris a short single-line message, clamped, with control characters stripped. URLs in records are the untrusted input, JSON-escaped; consumers must treat them as data.keyis the stable file stem:<host>-<first 6 hex of sha256(normalised url)>. Report files are<key>.<ext>: never derived from path or query, so no traversal or collisions, and a re-run of the same URL overwrites its own file atomically (write to.<key>.tmp, rename).Exit codes of the child are the single-audit codes (0 success including partial, 1 error, 2
--fail-ontripped, 3 blocked, 4 redirected, 5 unreachable), so the table indocs/cli/audit.mdxstays the one source.5. Resume, retry, restart
results.jsonl, takes the last record perkey, and skips keys whose status is terminal-success (completed,partial). Killing the process and re-running with the same arguments therefore does not redo completed URLs (criterion 2). A truncated last line (killed mid-write) is ignored.failed,blocked,unreachable,redirected,timeout,crashed) are skipped by default and re-run with--retry-failed, which also bumpsattempt.rejectedkeys are never retried (the input is wrong);skipped-budgetkeys run on the next invocation. A changed--max-pagesor level does not invalidate completed records (it is the operator's call:--restart).--restartrenames the old file toresults.<timestamp>.jsonland starts over.<out-dir>/.batch.lock(pid, host, start time; stale when the pid is gone on this host) stops two orchestrators on one out-dir. This is the batch counterpart of the crawl lease.6. Failures do not stop the batch; exit codes of the batch
A failing URL is recorded and the batch continues. Batch exit code:
0completedorpartialand no--fail-ongate tripped12--fail-ongate tripped (child exit 2)6failed,blocked,unreachable,redirected,timeout,crashed,rejectedorskipped-budget(takes precedence over 2)6is new and needs adding to the exit-code table and to docs;--retry-failedre-runs exactly what produced it. A final summary on stderr (counts per status, report and manifest paths) is printed in every case; with-f jsonnothing goes to stdout.7. Concurrency, memory and politeness
--concurrencychildren with the per-project deferral from section 3. The default (at most 4, at most half the cores) is conservative on a laptop: a surface audit is a few hundred MB and spends CPU on rules. Docs give a sizing table and the memory rule of thumb.--concurrencyis per machine. Politeness per target is unchanged because each audit already rate-limits to its own host; two different sites share nothing. A list that contains many URLs on one host (different paths) is the case to warn about: the scheduler serialises by project name, so they run one after another.concurrency * 600 MBexceeds it.SIGINT/SIGTERMto the orchestrator forwards SIGTERM to children, waits their grace period (the audit's own shutdown writes a partial report), records them ascrashed-with-signalonly if they do not exit, and exits 130. Records written so far make the next run a resume.8. Retention and the shared stores (the "corpus recipe")
The defaults (content store 1 GB LRU,
keep_audits = 3per project) are tuned for one site. For a batch:[storage]from the config, plus theSQUIRREL_CONTENT_STORE_MAX_BYTESenvironment variable. The docs carry the recipe the issue asks for:keep_audits = 1(or0for report-only corpora: nothing to resume or diff from),content_store_max_bytessized to the corpus when later analysis needs stored HTML, and that the content store is the only copy of fetched HTML (it is evicted, and scripts are never stored unless--store-scripts).--keep-datadocuments the opposite: by default a batch run setskeep_auditsto 1 for its children unless the config sets it, so hundreds of one-off sites do not leave hundreds of three-audit projects in~/.squirrel. This is a default for batch only and is printed in the preamble.--isolated-homeruns the children withHOME=<out-dir>/.homeso a corpus does not mix with the user's real projects and can be deleted with the out-dir. Off by default because users wantsquirrel report <domain>to work afterwards.9. Cloud, credits and publishing
A signed-in
squirrel auditregisters a website per domain, auto-publishes and spends credits. For a 500-URL batch that is 500 dashboard sites and a bill. So batch defaults differ and are stated up front:--ephemeralbehaviour of #3649: cloud features, no dashboard website, no schedule, no publish) unless--publishis given.N x (50 + 2 x max_pages)credits, with the page cap and link-check reserve) from the same estimate the single audit prints, compares it to the balance, and refuses to continue without--yes.--max-credits Ncaps total spend: the scheduler stops starting new children once the running estimate plus in-flight caps would pass it, and records the rest asskipped-budget(not retried by default). Per-audit[cloud] max_credits_per_auditstill applies to each child.--offlinebatches are fully local and need none of this.10. Security of the urls-file
The file is untrusted (shared lists, scraped data, a corpus from a third party).
http:andhttps:URLs.file:,javascript:,data:,ftp:and the rest arerejectedwith a reason. Userinfo (user:pass@host) is rejected (a credential in a list is a leak waiting to be logged).--max-urls(default 100000): a larger file is an error before any request is made. Control characters and invalid UTF-8 are rejected per line. Leading and trailing whitespace is trimmed; a missing scheme getshttps://the way the single audit does it..local,.internal) arerejectedunless--allow-private-hosts, using the same classifier the audit's cloud preflight uses (nonPublicHostLabel). The single audit allows localhost on purpose; a batch fed from a list should not scan an internal network by default. Every child also keeps the audit's own egress guard per hop, so a public name that redirects to a private address is still refused (Start URL redirects (bit.ly etc.): resolve the chain and audit the destination, with consent for cross-domain (--follow-redirect / prompt); today it scores the shortener #1281).redirected(exit 4) unless the batch is given--follow-redirect, and the manifest records the final URL.11. Documentation, completions, skill
docs/cli/audit.mdx(flags, the record schema, exit code 6, the batch retention recipe, sizing),docs/guides/batch and corpus recipe,completion.tsfor the new flags,--help. The agent skill needs a short section (agents do run batches): a private issue labelledskillsis filed with the first PR. Asquirrel auditJSON report gains no field; the record carries what a batch needs.12. Test plan
runningsuccessor logic.--retry-failedbumpsattempt,--restartrotates the file, lock file stale detection.--fail-on(2), and the batch exit code precedence.--concurrency.--yes,--max-creditsstops scheduling (stub API).13. Phases and PR split
results.jsonl, resume/restart/lock, concurrency, exit codes including6, docs, completions, tests. Local audits only; signed-in runs refuse with a message until PR B.--yes,--max-credits, ephemeral default), retention defaults and notices, sizing warning.squirrel audit --urls-file --status(summarise a manifest: counts, failures, slowest) and--isolated-home. Optional.The batch exit code
6and theredirected/unreachablestatuses depend on #1282 (merged), #1297 and #1324 (open): the orchestrator only reads child exit codes and the record, so it can land before them and the vocabulary grows as they merge.Acceptance criteria (additions)
The issue body keeps its five criteria and gains the following.
nc9 commentedon Oct 30, 2026
Review of the spec above against the current code and the open work, with the decisions it leaves to the maintainer. Recommendation: build it as written, in the three-PR split.
What is settled by the spec: child
squirrel auditprocesses under one orchestrator (the audit command owns process globals, signals and the content store handle, so an in-process pool is the wrong cut),results.jsonlwith one writer andrunningrecords for crash detection, hashed report keys, resume by default with--retry-failedand--restart, batch exit code6, per-project deferral for the one-project-one-db constraint, urls-file treated as untrusted.Interplay worth stating in the docs:
--max-durationis per URL, not per batch, so a 500-URL batch with--max-duration 60can run for hours;--url-timeoutdefaults tomax-duration * 1.5 + 60as the hard kill.--ephemeralis the batch default for signed-in runs, so no dashboard sites are created unless--publishis passed.Decisions needed before PR A:
BEGIN IMMEDIATE) before any--concurrencyabove 1, or ship PR A with the default pinned to 1 and raise it when Concurrent squirrel audit processes fail with 'SQLite database is busy (locked)' #1226 lands. Recommendation: wait, since concurrency is the point of the feature.min(4, floor(cores / 2)), cap 16. Recommendation: keep, with the memory warning atconcurrency * 600 MB.keep_audits = 1for children unless the config sets it, versus leaving the single-site default of 3. Recommendation: 1, printed in the preamble, with--keep-datato opt out.--yesrequired,--max-creditscap, in PR B and refusing signed-in runs in PR A. Recommendation: as written.--allow-private-hosts, even though a singlesquirrel auditallows localhost. Recommendation: reject by default for a list input.--isolated-homeand--status(PR C) are wanted at all, or dropped from the first release.nik
feat(cli): batch urls file: strict special-use host classifier, maske…
fix(cli): batch urls file echo masks userinfo whatever the slashes (p…
fix(utils,cli): strict host classifier: embedded IPv4 only adds a ref…
feat(cli): batch audit groundwork: urls-file reader and results manif…
feat(cli): batch urls file: strict special-use host classifier, maske…
fix(cli): batch urls file echo masks userinfo whatever the slashes (p…
fix(utils,cli): strict host classifier: embedded IPv4 only adds a ref…
refactor(cli,utils): the batch urls file reads isNonPublicHostnameFor…
feat(cli): squirrel audit --urls-file batch mode with concurrency, re…
45 remaining items
fix(cli): read batch lock file by path to clear CodeQL file race alert …
fix(cli): read batch lock through one descriptor #1231
fix(cli): take over a stale batch lock atomically #1231
fix(cli): resume a URL the batch interrupted, and kill children on a …
fix(cli): refuse a signed-in batch unless --offline is true #1231
fix(cli): pass children the resolved --offline, not the raw flags #1231
feat(cli): squirrel audit --urls-file batch mode with concurrency, re…
fix(cli): keep the missing-URL screen and remove file races in batch …
fix(cli): read batch lock file by path to clear CodeQL file race alert …
fix(cli): read batch lock through one descriptor #1231
fix(cli): take over a stale batch lock atomically #1231
fix(cli): resume a URL the batch interrupted, and kill children on a …
fix(cli): refuse a signed-in batch unless --offline is true #1231
fix(cli): pass children the resolved --offline, not the raw flags #1231