Repository navigation
feat(cli): squirrel self disk, so the data directory stops being invisible - #256
Merged
Merged
Conversation
added 2 commits
September 8, 2026 06:32
…sible #1912 Re-auditing a project writes a whole new crawl and retires nothing, so `project.db` grows by about one audit every time: 95 MB after one audit of a 1,000-page site, 189 MB after two, 215 MB after three. `rule_results` and its two indexes are 69.6% of that and `pages` another 28.2%, because a crawl stores around 204 check rows per page. Nothing told anyone. There was no way to find out that `~/.squirrel` had reached tens of gigabytes, let alone which project was responsible. On the machine this was written on it is 3.8 GB, with one project holding seven audits of the same site. `squirrel self disk` lists projects largest first with their audit count, then the totals, keeping the content store separate because it is shared rather than owned by any one project. `--json` for scripting, `--limit` to trim the list. It reports and nothing more: no deletion, no vacuum, no retention policy. Those need the retention window decided first, since old crawls are reachable through `report --list`, `--diff` and `--regression-since`, and that is tracked on the issue. The roots are a parameter rather than read from the environment. `getSquirrelPaths` goes through `os.homedir()`, which does not follow `$HOME`, so a test that moved `HOME` measured the developer's real data directory instead of its fixture and took 34 seconds to do it. Signed-off-by: Nik Cubrilovic <[email protected]>
…1912 Review follow-up. Four findings, all real: - `self disk` was running the usual startup maintenance, which compresses and deletes logs. The command reports the size of the logs directory, so it could change the number it was about to print, and an update could land mid- measurement. Excluded alongside the other commands that must not have the ground move under them; its siblings are unaffected. - The shared link cache was invisible. `~/.squirrel/link-cache.db` is real user data, sits outside every counted directory, and was in no line of the report. - A shared database pointed INSIDE a counted directory was counted twice, once on its own line and once in that directory. `SQUIRREL_CONTENT_STORE_PATH` puts it anywhere, and the benchmark harnesses put it under a project, so this was reachable. It now counts once, against the directory that holds it, which also stops a project being blamed for bytes it does not own. - The directory walk stopped at four levels while claiming to measure the whole project, so a deeper tree was silently understated. The limit existed to guard against symlink loops, which cannot happen here: `readdirSync` with `withFileTypes` reports link entries by lstat, so a symlink to a directory answers false to `isDirectory()` and is never recursed into. Raised to a real backstop and the reason written down. Also corrected the docs claim. Opening a WAL database read-only is a read, not "no writes of any kind": SQLite may create a `-shm` for it. Measured, the sidecars are already there from the audit that wrote the file and the read-only open creates nothing new, but the honest wording is that this does not modify your data. Signed-off-by: Nik Cubrilovic <[email protected]>
nc9
force-pushed
the
feat/self-disk-usage
branch
from
September 7, 2026 20:32
57966f3 to
f0e10cf
Compare
nc9
pushed a commit
that referenced
this pull request
Sep 7, 2026
… holding #1912 A project keeps every audit it has ever run: 95 MB after one audit of a 1,000-page site, 189 MB after two, 215 MB after three. #256 made that visible; this makes it fixable, explicitly and only when asked. `--prune --keep N` retires the audits beyond the newest N — their rule results, sitemaps, page features and frontier, plus the page rows a newer audit already supersedes — then rebuilds the file so the space returns to the filesystem. Measured on two audits of a 60-page site, keeping one: 11.5 MB to 5.7 MB, and the next audit reported all 60 pages unchanged with 0 fetched. What it keeps is the part worth getting right, and an adversarial review moved two of these from "kept by luck" to "kept on purpose": - the newest page record per url, so an incremental re-crawl still gets its ETag instead of refetching the site. The predicate is `getCachedPage`'s own ordering inverted, so what goes is exactly what that read can never return. - links, images and their appearances. `getLinksByPage` and `getImagesByPage` have no crawl_id filter and `reuseCachedPage` copies their result into the next crawl, so retiring them would leave a reused page with no links in the NEXT audit's report. - `resource_sizes`, since a retired crawl's rows may still be the freshest sub-resource record anyone has, and `published_reports`, and the `crawls` row. Guards, each with a test: a crawl that is not finished is refused inside `retireCrawls` rather than only in the caller, so a prune racing a live audit cannot delete its frontier; `--keep` is matched whole-string, because `parseInt("1e3")` is 1 and `--keep 1e3 --yes` would otherwise have kept one audit and deleted the rest; the plan is printed and confirmed first; `--dry-run` stops after printing; and an audit never prunes anything. VACUUM alone made the file BIGGER, 189 MB to 239 MB: in WAL mode the rewrite lands in the write-ahead log, so the main file shrinks while the `-wal` beside it grows by more than was saved. `PRAGMA wal_checkpoint(TRUNCATE)` after the vacuum, and running `close()` rather than merely constructing its Effect, is what makes the saving real. Draft until one thing is decided: a retired crawl still says `completed`, so `reconstructReport` will build a confident empty report from it. Making an audit unrenderable needs retirement state the report path can see, which is a schema change on a user's project.db. Options are on the issue. Signed-off-by: Nik Cubrilovic <[email protected]>
nc9
added a commit
that referenced
this pull request
Sep 8, 2026
…scan skill, bump to 1.3 (#265) Adds the disk usage and reclaim commands from #256 and #259 to the agent skill so agents know where ~/.squirrel growth comes from and how to reclaim it, and that --keep is the user's call. Skill version 1.2 -> 1.3. Signed-off-by: Nik Cubrilovic <[email protected]> Co-authored-by: Nik Cubrilovic <[email protected]>
nc9
pushed a commit
that referenced
this pull request
Sep 8, 2026
… holding #1912 A project keeps every audit it has ever run: 95 MB after one audit of a 1,000-page site, 189 MB after two, 215 MB after three. #256 made that visible; this makes it fixable, explicitly and only when asked. `--prune --keep N` retires the audits beyond the newest N — their rule results, sitemaps, page features and frontier, plus the page rows a newer audit already supersedes — then rebuilds the file so the space returns to the filesystem. Measured on two audits of a 60-page site, keeping one: 11.5 MB to 5.7 MB, and the next audit reported all 60 pages unchanged with 0 fetched. What it keeps is the part worth getting right, and an adversarial review moved two of these from "kept by luck" to "kept on purpose": - the newest page record per url, so an incremental re-crawl still gets its ETag instead of refetching the site. The predicate is `getCachedPage`'s own ordering inverted, so what goes is exactly what that read can never return. - links, images and their appearances. `getLinksByPage` and `getImagesByPage` have no crawl_id filter and `reuseCachedPage` copies their result into the next crawl, so retiring them would leave a reused page with no links in the NEXT audit's report. - `resource_sizes`, since a retired crawl's rows may still be the freshest sub-resource record anyone has, and `published_reports`, and the `crawls` row. Guards, each with a test: a crawl that is not finished is refused inside `retireCrawls` rather than only in the caller, so a prune racing a live audit cannot delete its frontier; `--keep` is matched whole-string, because `parseInt("1e3")` is 1 and `--keep 1e3 --yes` would otherwise have kept one audit and deleted the rest; the plan is printed and confirmed first; `--dry-run` stops after printing; and an audit never prunes anything. VACUUM alone made the file BIGGER, 189 MB to 239 MB: in WAL mode the rewrite lands in the write-ahead log, so the main file shrinks while the `-wal` beside it grows by more than was saved. `PRAGMA wal_checkpoint(TRUNCATE)` after the vacuum, and running `close()` rather than merely constructing its Effect, is what makes the saving real. Draft until one thing is decided: a retired crawl still says `completed`, so `reconstructReport` will build a confident empty report from it. Making an audit unrenderable needs retirement state the report path can see, which is a schema change on a user's project.db. Options are on the issue. Signed-off-by: Nik Cubrilovic <[email protected]>
nc9
pushed a commit
that referenced
this pull request
Sep 8, 2026
… holding #1912 A project keeps every audit it has ever run: 95 MB after one audit of a 1,000-page site, 189 MB after two, 215 MB after three. #256 made that visible; this makes it fixable, explicitly and only when asked. `--prune --keep N` retires the audits beyond the newest N — their rule results, sitemaps, page features and frontier, plus the page rows a newer audit already supersedes — then rebuilds the file so the space returns to the filesystem. Measured on two audits of a 60-page site, keeping one: 11.5 MB to 5.7 MB, and the next audit reported all 60 pages unchanged with 0 fetched. What it keeps is the part worth getting right, and an adversarial review moved two of these from "kept by luck" to "kept on purpose": - the newest page record per url, so an incremental re-crawl still gets its ETag instead of refetching the site. The predicate is `getCachedPage`'s own ordering inverted, so what goes is exactly what that read can never return. - links, images and their appearances. `getLinksByPage` and `getImagesByPage` have no crawl_id filter and `reuseCachedPage` copies their result into the next crawl, so retiring them would leave a reused page with no links in the NEXT audit's report. - `resource_sizes`, since a retired crawl's rows may still be the freshest sub-resource record anyone has, and `published_reports`, and the `crawls` row. Guards, each with a test: a crawl that is not finished is refused inside `retireCrawls` rather than only in the caller, so a prune racing a live audit cannot delete its frontier; `--keep` is matched whole-string, because `parseInt("1e3")` is 1 and `--keep 1e3 --yes` would otherwise have kept one audit and deleted the rest; the plan is printed and confirmed first; `--dry-run` stops after printing; and an audit never prunes anything. VACUUM alone made the file BIGGER, 189 MB to 239 MB: in WAL mode the rewrite lands in the write-ahead log, so the main file shrinks while the `-wal` beside it grows by more than was saved. `PRAGMA wal_checkpoint(TRUNCATE)` after the vacuum, and running `close()` rather than merely constructing its Effect, is what makes the saving real. Draft until one thing is decided: a retired crawl still says `completed`, so `reconstructReport` will build a confident empty report from it. Making an audit unrenderable needs retirement state the report path can see, which is a schema change on a user's project.db. Options are on the issue. Signed-off-by: Nik Cubrilovic <[email protected]>
nc9
added a commit
that referenced
this pull request
Sep 8, 2026
… holding (#259) * feat(cli): squirrel self disk --prune, to reclaim what old audits are holding #1912 A project keeps every audit it has ever run: 95 MB after one audit of a 1,000-page site, 189 MB after two, 215 MB after three. #256 made that visible; this makes it fixable, explicitly and only when asked. `--prune --keep N` retires the audits beyond the newest N — their rule results, sitemaps, page features and frontier, plus the page rows a newer audit already supersedes — then rebuilds the file so the space returns to the filesystem. Measured on two audits of a 60-page site, keeping one: 11.5 MB to 5.7 MB, and the next audit reported all 60 pages unchanged with 0 fetched. What it keeps is the part worth getting right, and an adversarial review moved two of these from "kept by luck" to "kept on purpose": - the newest page record per url, so an incremental re-crawl still gets its ETag instead of refetching the site. The predicate is `getCachedPage`'s own ordering inverted, so what goes is exactly what that read can never return. - links, images and their appearances. `getLinksByPage` and `getImagesByPage` have no crawl_id filter and `reuseCachedPage` copies their result into the next crawl, so retiring them would leave a reused page with no links in the NEXT audit's report. - `resource_sizes`, since a retired crawl's rows may still be the freshest sub-resource record anyone has, and `published_reports`, and the `crawls` row. Guards, each with a test: a crawl that is not finished is refused inside `retireCrawls` rather than only in the caller, so a prune racing a live audit cannot delete its frontier; `--keep` is matched whole-string, because `parseInt("1e3")` is 1 and `--keep 1e3 --yes` would otherwise have kept one audit and deleted the rest; the plan is printed and confirmed first; `--dry-run` stops after printing; and an audit never prunes anything. VACUUM alone made the file BIGGER, 189 MB to 239 MB: in WAL mode the rewrite lands in the write-ahead log, so the main file shrinks while the `-wal` beside it grows by more than was saved. `PRAGMA wal_checkpoint(TRUNCATE)` after the vacuum, and running `close()` rather than merely constructing its Effect, is what makes the saving real. Draft until one thing is decided: a retired crawl still says `completed`, so `reconstructReport` will build a confident empty report from it. Making an audit unrenderable needs retirement state the report path can see, which is a schema change on a user's project.db. Options are on the issue. Signed-off-by: Nik Cubrilovic <[email protected]> * feat(cli): a reclaimed audit says so instead of rendering an empty report #1912 Nik's decision on the issue: option 1, a nullable `retired_at` on `crawls`. Without it, `--prune` left the crawl row saying `completed` while its rule results were gone, so `reconstructReport` read zero checks and assembled a confident report with no findings from the pages that survive. That reads as a clean audit. It is a wrong answer where the old behaviour was merely a large file, which is why #259 stayed a draft until this landed. Migration 25 adds the column, and it goes on a reconcile list at the same time. That guard is not belt-and-braces: `pages`, `sitemaps`, `robots_txt`, `links` and `sitemap_url_statuses` have each been broken by a DB stamped at or past a version whose migration a differently-numbered build had skipped, and here the casualty would be every `listCrawls` SELECT — `report`, `report --list` and the prune itself, not just the new field. Tested by seeding a database already stamped at the current version and asserting the column appears on open. `retireCrawls` stamps it inside the same transaction as the deletes, so a crash cannot produce the one state worse than either end: data gone, audit still renderable. Refusal is structural rather than a check per call site. The three CLI gates that tested `isReportReadyStatus(crawl.status)` now test `isReportRenderable(crawl)`, which covers `report <id>`, `--diff` and `--regression-since` together and cannot be missed by a fourth. `reconstructReport` refuses independently, underneath all of them. Both say the same sentence, from one definition: Audit data was reclaimed on 2026-09-08: 06148d76-... `report --list` still shows the audit, marked `retired`, with the date its data went — keeping the crawl row is what makes the history visible instead of silently shrinking. Verified end to end: pruned a real project, then `report <id>`, `--diff` and `--regression-since` each refused with that line while the audit that was kept rendered normally. Retention is still manual and `--keep` still required; the automatic window is undecided and stays that way. Signed-off-by: Nik Cubrilovic <[email protected]> * fix(cli): close two paths that still used a reclaimed audit #1912 Review of the commit above found two, both real, both the case it was written to prevent reaching: - **`analyze` re-scored reclaimed data and called it a success.** Retirement leaves the status `completed`, and `analyze` has its own status-only gate, so `analyze <id>` re-ran the rules over whatever pages survived the prune and reported "Analysis complete" for a crawl most of whose data is gone. Its automatic selector picked retired crawls too. Both now test the stamp. - **A prune committing mid-read escaped the refusal.** `reconstructReport` checked the stamp once, outside any read transaction, so another process could retire between that check and the page and rule-result reads — and the function would return a confident empty report assembled from pre-retirement metadata. It re-reads the stamp after every read now, before returning. Two tests were weaker than they looked, and both are fixed rather than argued with. The migration test's `listCrawls` assertion passed WITHOUT the repair, because reads are `SELECT *` mapped by key: a missing column yields undefined rather than throwing. It now asserts through the prune's UPDATE, which is the part that fails loudly. And the "same transaction" test asserted only the successful end state, which holds whether or not the two are separable; it now rolls the transaction back and asserts neither the stamp nor the deletes survived. The comment on the reconcile list said a missing column makes every listCrawls SELECT throw. It does not, and the truth is worse: every retired audit silently reads as not retired and renders the empty report the column exists to prevent. Corrected in place. Signed-off-by: Nik Cubrilovic <[email protected]> --------- Signed-off-by: Nik Cubrilovic <[email protected]> Co-authored-by: Nik Cubrilovic <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The observability half of squirrelscan/repo#1912. Reports; deletes nothing.
Why
Re-auditing a project writes a whole new crawl and retires nothing, so
project.dbgrows by about one audit every time. Measured on a 1,000-page site: 95 MB after one audit, 189 MB after two, 215 MB after three, with row counts exactly doubled across crawls.Where it goes, for two audits of that site:
rule_resultspagesidx_rule_results_pageidx_rule_results_crawlA crawl stores around 204 check rows per page, so
rule_resultswith its indexes is 69.6% of the file.None of this was discoverable. There was no way to learn that
~/.squirrelhad reached tens of gigabytes, or which project was responsible. On the machine this was written on it is 3.8 GB, and the largest single project is seven audits of the same site.What this adds
Projects largest first, since the reason to run this is to find what to act on. The content store is reported separately because it is shared by every project rather than owned by one.
--jsonfor scripting,--limitto trim the list.What this deliberately does not add
No deletion, no
VACUUM, no retention policy. Old crawls are reachable throughreport --list,report --diffandreport --regression-since <audit-id>, so every byte worth reclaiming is history someone can currently ask for. How many audits to keep is a product decision, it is question 1 in the issue body, and it is tracked there rather than settled here.VACUUMis also the only thing that returns space to the filesystem and it rewrites the whole file, so it has to be user-triggered rather than part of an audit.Robustness
The states someone is in when they go looking for what is eating their disk are exactly the awkward ones, so each is covered by a test: a missing data directory reports zeroes rather than failing; a project whose database is corrupt or from an older schema still contributes its size and says why the counts are missing, instead of vanishing from the table; a project directory with no database is still listed; an unreadable entry mid-walk is skipped rather than failing the report. The directory walk is depth-limited so a symlink loop cannot hang the command.
One note for reviewers
The roots are a parameter with a real default rather than read from the environment.
getSquirrelPathsgoes throughos.homedir(), which does not follow$HOME, so the first version of the test movedHOME, measured the developer's actual~/.squirrel, and took 34 seconds to pass one assertion. With injected roots the suite runs in 78 ms.Shell completions updated for bash, zsh and fish; docs page added under
cli/self.