Skip to content

feat(cli): audit levels (--level quick|surface|full) and the audit levels docs page - #598

Merged
nc9 merged 11 commits into
mainfrom
feat/audit-levels-cli-docs
Oct 10, 2026
Merged

nc9 merged 11 commits into
mainfrom
feat/audit-levels-cli-docs

Conversation

@nc9

@nc9 nc9 commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Audit levels for the CLI and the docs: --level quick|surface|full, built on the shared definition in packages/core-contracts/src/audit-levels.ts, which is on main since #602. Rebased onto main at 2f93601; this PR no longer changes core-contracts.

Draft for review. Nothing here should merge before the maintainer has read the behaviour changes below.

What changes

  • One definition. audit, crawl, the local MCP tools, [crawler] coverage, the completions and the help text all read the levels from core-contracts. No other level list or per-level page count is left in the CLI. The config schema, the crawler's mode type and the engine's run input derive from AUDIT_LEVELS (@squirrelscan/config now depends on core-contracts).
  • --level, with --coverage/-C kept as the older name. fast still means quick. An unknown value exits 1 with unknown audit level 'turbo'. Valid: quick, surface, full (fast is accepted as quick). --level and -C naming different levels is refused.
  • Level settings are defaults. Pages, render strategy, external link checks and probing come from the level; the existing flags and config values override them. Any change makes the run custom.
  • Banner: Level surface · max 100 pages, Level custom (surface + max_pages 200), Level custom (surface + render off) · max 100 pages. It replaces the Coverage line.
  • Billing is unchanged at every level. No audit is free in credits: a signed-in quick audit registers the run and is billed 50 + 2 per audited page (up to 100), and renders the pages that need JavaScript in the cloud browser (hybrid auto), as on main. Quick only skips the cloud checks. Signed out there is nothing to bill: quick stays local, no account needed. (An earlier commit on this branch made signed-in quick free; fix(cli): bill a signed-in quick audit like every other level takes that out.)
  • squirrel crawl -C fast bug fixed. The crawl resolves its level through the shared parser; a non-numeric --max-pages is refused too.
  • Reports: auditLevel (level, basedOn, changes, settings) on the report, JSON meta.auditLevel, LLM <audit-level>, an Audit level: line in text, Markdown and HTML. No field renamed; coverageMode still stamped. A JSON report loaded back keeps it, through a parser that only returns valid words.
  • core-contracts: nothing in this PR. What it reads (AUDIT_LEVEL_PRESETS, crawlStrategyCoverageMode, AUDIT_SETTING_COPY, parseResolvedAuditSettings, CoverageMode as AuditLevel, AuditReport.auditLevel) landed with feat(core-contracts): audit levels definition (quick, surface, full) #602; the branch's own contracts commit was dropped in the rebase, since feat(core-contracts): audit levels definition (quick, surface, full) #602 contains all of it.
  • Docs: new Audit levels page (docs/guides/audit-levels.mdx) (Guides, Concepts, after Crawling), plus every page that described coverage modes. CHANGELOG entry under [Unreleased].

Behaviour changes to review

Against current main (2f93601):

  1. Link checks and probing follow the level, not sign-in. Quick: no external link checks, passive probing. Surface and full: external link checks and active probing, signed in or not. Before: external links at every level, probing active only when signed in. So a signed-out --level surface now sends active probes, and every quick run skips external links.
    Maintainer sign-off: the maintainer (Nik) approved active probing for signed-out surface and full audits on 2026-10-10, reviewing this exact item ("Probing now follows the level, not sign-in") in the behaviour walkthrough before approving the merge. audit-level-wiring.test.ts pins it: signed out and online, --level quick probes passive and --level surface and --level full probe active.
  2. Config caveats. max_pages = 100 and [external_links] enabled = true still read as unset, because squirrel init writes both into every config. There is no flag for external links either, so quick cannot check them at all: pick surface. [crawler] coverage now accepts fast and any letter case (before: a config validation error); other unknown values still fail.
  3. Local MCP. audit_website takes level (coverage still works; both naming different levels is an error). It now applies the project config the way squirrel audit does: [crawler] max_pages, [security] probe, [external_links] enabled = false, and [cloud] render as the fetch mode. At surface and full it probes actively (before: always passive). quick_check no longer checks external links. At quick the tools stay local, as on main.
    Known gap (as on main): signed in, audit_website adds the cloud checks at surface and full but never registers a billed cloud audit, so it is not billed the way squirrel audit is (a configured [cloud] render does cost 2 credits per rendered page). Its description, docs/cli/mcp.mdx, docs/developers/mcp.mdx and the CHANGELOG now say so and point at the hosted run_audit. Local MCP audit_website runs cloud checks without billing a signed-in audit #628 bills it like the CLI, in a follow-up PR after this one.
  4. squirrel crawl. --level added; an unknown level stops before the crawl (before: -C fast crawled with no page limit), and so does a non-numeric --max-pages.
  5. Copy. The banner says Level instead of Coverage; locked-check and page-limit messages point at --level instead of -C; the quick-level locked message no longer says "coverage". No copy says quick is free: the docs say a signed-in quick audit costs 50 + 2 per page, --help lists quick as "no cloud checks" (main says "fast/local/free"), the MCP descriptions drop "free" and "no credits", and cloud-audits.mdx and quickstart.mdx lose main's old "fast, free scan" lines.

Not changed: registration, the affordability preflight, the once-only cost notice and cloud rendering at quick are all as on main.

Evidence

On the rebased head:

  • Typecheck (tsgo, per package): core-contracts, config, crawler, report, audit-engine, apps/cli: clean.
  • Tests, explicit files only. New: apps/cli/tests/cli/audit-level.test.ts (renamed from coverage.test.ts, resolution and banner text), tests/commands/audit-level-wiring.test.ts (real citty argv), tests/commands/audit-quick-billing-wiring.test.ts (signed-in quick registers, quotes 50 + 2 per page, renders a client-rendered page in the cloud browser and keeps a server-rendered one on HTTP; --offline and --http controls; a signed-out quick run reads no balance, registers nothing and renders nothing; the signed-in cases fail 5 of 6 against the earlier free-quick code, and the same file with -C quick passes 6 of 6 on origin/main, so main already billed signed-in quick and only its copy said free), tests/commands/crawl-level.test.ts (fast, quick, surface, full, invalid), tests/mcp/audit-level-options.test.ts, packages/report/tests/audit-level-line.test.ts. Updated: config probe.test.ts, CLI config, completion, audit-probe-wiring, report, tips, page-limit-hint, locked-rules-footer, report locked-rules-*. Also run: core-contracts audit-levels, the other CLI, report and engine tests that read coverage or the level (quick-skips-cloud, coverage-mode, smart-audits, cloud-spend, render-decision, render-spend, MCP report-tools, publish-meta and others), and main's new decode-failures, json-stdout, console-warning-totals, toml-syntax-error. All pass.
  • Root bun run format:check and bun run lint, scripts/test-suites.ts --check, notices:check: pass.
  • Secret scan (detect-secrets-hook --baseline .secrets.baseline over tracked files): passes; the baseline only moves one line number.
  • make validate in docs: Pages: 426 Orphans: 1 ✓ All checks passed.
  • resolve-publish-decision, audit-run-lifecycle-wiring, audit-local-store-wiring and audit-non-public-host-wiring are back to main's versions, which register at quick, and pass.
  • Local fixture run before the rebase (packages/synthetic-site, 600 pages, --offline):
squirrel audit … --level quick      Level     quick · max 25 pages             Probing   passive · no requests beyond the crawl   ✓ Audited 25 pages
squirrel audit … --level surface    Level     surface · max 100 pages          Probing   active · budget 30s                      ✓ Audited 100 pages
squirrel audit … --level full       Level     full · max 500 pages             Probing   active · budget 30s                      ✓ Audited 500 pages
squirrel audit … -C fast            Level     quick · max 25 pages
squirrel audit … --level surface --max-pages 200     Level     custom (surface + max_pages 200)                ✓ Audited 200 pages
squirrel audit … --level surface --http --probe passive   Level     custom (surface + render off, probe passive) · max 100 pages
squirrel audit … --level turbo      Error: unknown audit level 'turbo'. Valid: quick, surface, full (fast is accepted as quick).   (exit 1)
squirrel crawl … -C fast --refresh  Level: quick · max 25 pages   ✓ Crawled 25 pages
  (before: "Coverage: fast (max NaN pages)", then the crawl fails on a NaN frontier priority)

After the rebase, --level turbo and --level surface -C quick still exit 1 with their messages, and audit --help lists the levels.

  • audit-schedule-notice-wiring.test.ts and audit-non-public-host-wiring.test.ts pass with HOME=$(mktemp -d). Without it they time out here, on main as well: the publish path opens every project database under the real ~/.squirrel/projects (17,248 on this machine).

Agent skill

Yes, the squirrelscan agent skill needs a change: it says quick is the default (signed in it is surface), uses -C, and should mention --level and custom levels, and say that quick skips the cloud checks but is billed like any level signed in (50 + 2 per page).

nc9 added a commit that referenced this pull request Oct 9, 2026
…602)

Adds @squirrelscan/core-contracts/audit-levels: the three levels plus custom, their preset settings, AUDIT_LEVEL_COPY and AUDIT_SETTING_COPY, resolve/clamp helpers, plan and balance limits (whole pages, NaN fails closed), the cloud's old four depths as legacy aliases, crawlStrategyCoverageMode and parseResolvedAuditSettings. AuditReport gains an optional auditLevel snapshot; CoverageMode is now the AuditLevel type (same three words). Additive: the CLI --level flag, docs and changelog stay in #598.

Signed-off-by: Nik Cubrilovic <[email protected]>
@nc9

nc9 commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

The core-contracts half of this PR landed on its own in #602 (0f960e9) so the cloud dashboard could build on it. Rebase this branch onto main: its packages/core-contracts changes are already there, except the AuditReport.coverageMode doc comment, which #602 left as it was (the new wording describes stamping that lands here). One fix arrived with #602: effectiveAuditSettings rounds plan and balance limits down and treats a NaN limit as one page.

@nc9
nc9 force-pushed the feat/audit-levels-cli-docs branch 2 times, most recently from a8ab59e to 562401a Compare October 9, 2026 22:05
nc9 added 8 commits October 10, 2026 10:16
The level is now one definition (core-contracts audit-levels) read by the
audit and crawl commands, the local MCP tools, the config schema and the
shell completions.

- `--level quick|surface|full`; `--coverage`/`-C` and `[crawler] coverage`
  still work, `fast` still means quick, anything else exits with the list
  of levels. `--level` and `-C` naming different levels is refused.
- A level fills in every setting (pages, crawl strategy, cloud checks,
  render, external links, probing) as the default; the existing flags and
  config values override single settings. Any change makes the run custom,
  and the banner says so: `Level  custom (surface + max_pages 200)`.
- Quick spends no credits when signed in: a run without cloud checks does
  not register (no audit base, no page settlement) and does not use the
  cloud browser unless asked to render.
- Quick no longer checks external links or probes by default; surface and
  full probe actively whoever is signed in. Defaults `squirrel init` writes
  (max_pages = 100, external links on) still read as unset.
- `squirrel crawl -C fast` no longer crawls unbounded: the level and a
  non-numeric --max-pages are validated through the shared helper.
- Reports carry `auditLevel` (level, basedOn, changes, settings): JSON
  meta, an `<audit-level>` LLM element, a markdown/text/html line.
  Existing fields keep their names.
- core-contracts: crawlStrategyCoverageMode and AUDIT_SETTING_COPY;
  CoverageMode and the crawler's mode type derive from AuditLevel.
- config now depends on core-contracts (workspace).

Signed-off-by: Nik Cubrilovic <[email protected]>
…nto it

New page guides/audit-levels (Concepts, after Crawling): the three levels
with every setting, defaults, custom levels in the CLI, dashboard and
reports, plan and credit limits, which level to pick, probing and
rendering, and the older names. cli/audit, cli/crawl, crawl, quickstart,
local and cloud audit guides, crawler/security/cloud/external-links/output
config, scheduled audits, MCP and reports pages now say level, --level and
the level defaults, and link to it. Fixes: quick is free when signed in,
surface sampling is a priority penalty, quick falls back to links without
a sitemap, scheduled runs use the site's level, quick_check is not a
single-page pass.

Signed-off-by: Nik Cubrilovic <[email protected]>
…el on reload

A quick audit does not register, so the affordability preflight never ran
for it, and an explicit --render on a quick run had no spend bound. It is
now held to the balance and max_credits_per_audit on the worst case of
every page rendering (2 credits each), and falls back to HTTP when not one
render fits.

A JSON report loaded back with squirrel report keeps meta.auditLevel, read
through the new core-contracts parseResolvedAuditSettings so a forged file
only yields valid level and setting words.

Signed-off-by: Nik Cubrilovic <[email protected]>
No audit is free in credits. A signed-in quick audit registers the run
(50-credit base plus 2 per audited page) and renders the pages that need
JavaScript in the cloud browser, as before audit levels. The quick level
only skips the cloud checks.

Drops the no-register path, the render-only page budget and the
suppressed spend notice, restores the register wiring tests that run at
quick, and replaces the free-quick test with one that pins registration,
hybrid cloud rendering and the 50 + 2 per page quote. Docs, CHANGELOG,
help and MCP copy no longer say quick is free.

Signed-off-by: Nik Cubrilovic <[email protected]>
nc9 added 2 commits October 10, 2026 10:20
Pins the other half of the billing rule: signed out there is nothing to bill, so quick reads no balance, registers nothing and renders nothing. The docs say local, no account needed, for signed-out quick, and up to 100 credits signed in.

Signed-off-by: Nik Cubrilovic <[email protected]>
Signed in, audit_website adds the cloud checks at surface and full without registering a billed cloud audit. Its description, the MCP docs and the CHANGELOG now say so and point at the hosted run_audit for a billed audit; #628 tracks billing it like squirrel audit. Refs #628

Signed-off-by: Nik Cubrilovic <[email protected]>
@nc9
nc9 marked this pull request as ready for review October 10, 2026 00:42
@claude

claude Bot commented Oct 10, 2026

Copy link
Copy Markdown

Reviewed the CLI wiring (audit-level.ts, commands/audit.ts, probe.ts). I did not read every docs page, the report renderers, or the MCP changes in detail, and I did not run the tests. The structure is good: one level definition, level flags parsed rather than cast, and conflicting --level/-C values refused.

  • (medium) apps/cli/src/cli/commands/audit.ts (probe resolution): behaviour change [Security Alert] New postinstall script added in [email protected] #1 means a signed-out --level surface or --level full now sends active probes at whatever URL the user gives, with no account involved. Before, active probing needed a signed-in user. Please confirm that is intended for anonymous users, given that no ownership check applies locally. The PR description flags it for the maintainer. I would want an explicit sign-off before merge, plus a test that pins signed-out surface to active.
  • (low) apps/cli/src/cli/commands/audit.ts (max-pages resolution): config.crawler.max_pages === 100 is still hard-coded here, while audit-level.ts exports CONFIG_MAX_PAGES_DEFAULT and configLevelOverrides. requestedMaxPages should use the constant so the two sentinels can't drift apart. crawl.ts and the MCP tool should be checked for the same thing.
  • (low) apps/cli/src/cli/commands/audit.ts (render strategy): when levelRender is off or http, renderStrategy becomes undefined and the controller falls back to its own default. Please check that a level whose render setting is not auto or all cannot silently end up rendering. A small wiring test would settle it.
  • (low) packages/config/src/probe.ts:108: the new ProbeLevelSource union line is over the usual line width. Run the formatter.
  • (nit) packages/config/src/probe.ts: the reworded header comment runs past the wrap width on its second line.
  • (nit) readLevelFlag / flagText: the doc comment says a repeated flag reads as comma-joined text, which no level matches. That works, but Array.isArray with an explicit 'repeated flag' error would be clearer than relying on String() behaviour.

No critical or high-severity issues found in the parts I read. Test coverage looks thorough, with new tests for the level parser, wiring, billing, crawl, MCP, completions and report output.

…er-off and anonymous probing tests

- audit, crawl and the MCP tools read the `[crawler] max_pages` sentinel
  through configMaxPagesChoice instead of a literal 100.
- A repeated --level or -C is refused with its own error.
- Tests pin that a signed-out, online audit probes actively at surface
  and full and passively at quick, and that a signed-in audit with
  rendering off (--http, --render-mode off, [cloud] render = "off")
  never sends a page to the cloud browser at any level.
- Rewrap the probe.ts header comment.

Signed-off-by: Nik Cubrilovic <[email protected]>
@nc9

nc9 commented Oct 10, 2026

Copy link
Copy Markdown
Contributor Author

Review triage for 900bee4. All fixes are in 367727b.

  • (medium) signed-out active probing. Intended. The maintainer signed it off; the PR body now records this under behaviour change 1. New test audit-level-wiring.test.ts › "signed out and online, probing follows the level": anonymous and online, --level quick probes passive, --level surface and --level full probe active.
  • (low) max_pages === 100 literal. Fixed. configMaxPagesChoice() in audit-level.ts is now the one place the sentinel is read: audit goes through configLevelOverrides, crawl calls it directly, and the MCP tool already used configLevelOverrides. Unit test added.
  • (low) render off falling back to the controller default. Checked, and now pinned by a test. With rendering off, explicitRenderMode is "off", so resolveCloudRendering gets http: true and configRendering: "http". That returns http, and the controller builds no cloud fetcher whatever renderStrategy is. New tests in audit-quick-billing-wiring.test.ts › "a signed-in audit with rendering off never renders" cover --level surface --http, --level full --render-mode off, --level quick --render-mode off and [cloud] render = "off" at surface. Each one registers and sends no page to the cloud browser, and a control at surface does render. A mutation that keeps the browser on for off fails all four. Pages the cloud checks submit for their JavaScript-content comparison at surface and full are a cloud check, not page rendering, so they are told apart and not counted.
  • (low / nit) probe.ts formatting. The header comment is rewrapped. I left line 108 (87 columns) as it is: packages/* have no formatter config or format script (CLAUDE.md: do not run oxfmt on them), and the package's own convention is about 100 columns. Default oxfmt leaves the file unchanged. apps/cli's 80-column config would reformat the whole file.
  • (nit) repeated flag. Fixed. readLevelFlag refuses an array with its own error, --coverage was given more than once (full, full). Pass one level., so a repeat no longer relies on String() turning it into text that matches no level. Tests and CHANGELOG updated.

Gates on 367727b: tsgo (apps/cli, config), the touched test files, root format:check and lint, test-suites --check, detect-secrets, and make validate. All pass.

@claude

claude Bot commented Oct 10, 2026

Copy link
Copy Markdown

Reviewed the CLI wiring (audit-level.ts, audit.ts, controllers/audit.ts) and the config/probe changes. I did not read the docs diffs or the tests line by line, and I did not run the test suite.

  • (medium) packages/config/src/probe.ts, audit.ts: probing now follows the level. A signed-in --level quick run therefore defaults to passive probing, where on main the signed-in default was active whatever the coverage. That seems intended, but please state it in the CHANGELOG as a behaviour change, since the PR is marked as waiting for the maintainer to read those. Also check that a signed-in user with [security] probe unset and -C quick gets the result you expect.
  • (low) configLevelOverrides / configMaxPagesChoice: max_pages = 100 in the config is treated as unset (the schema default), so an explicit 100 at full or quick is silently replaced by the level's page budget. This is documented in the code. Consider a one-line note in the docs too, because it is a surprising trap for anyone who sets 100 on purpose.
  • (low) packages/config/src/schema.ts: the z.preprocess on coverage makes the field's input type unknown. Check that squirrel.toml JSON-schema generation, if any, still lists the enum values.
  • (nit) packages/config/src/probe.ts: the ProbeLevelSource union line is probably over the formatter's width. Run prettier or biome on it.
  • (nit) controllers/audit.ts: the new report.auditLevel assignment sits between the comment block about rulesCache and report.rulesCache, which separates the comment from the code it describes. Move it above that block.

The rest looks good. The single level definition, the NaN-cap guard and the clear errors for --level / -C conflicts are well done, and there is solid test coverage for the new parsing and wiring.

@nc9
nc9 merged commit 2cbf648 into main Oct 10, 2026
15 checks passed
@nc9
nc9 deleted the feat/audit-levels-cli-docs branch October 10, 2026 02:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant