Skip to content

feat(cli): add cache list/clear command#232

Merged
YusukeHirao merged 5 commits into
devfrom
worktree-clear-cache
Jul 24, 2026
Merged

feat(cli): add cache list/clear command#232
YusukeHirao merged 5 commits into
devfrom
worktree-clear-cache

Conversation

@YusukeHirao

Copy link
Copy Markdown
Member

Summary

  • Add nitpicker cache list [--json] and nitpicker cache clear [archive] to list/clear the on-disk tar-extraction cache (and the sibling analyze table cache) that viewer/MCP/query CLI populate under getArchiveCacheRoot(). Previously the only way to clear this was a manual rm -rf.
  • cache clear with no archive wipes the whole cache root; with a .nitpicker path it removes only that archive's tar-cache entry (content-addressed lookup — a stale entry from a since-changed archive won't be found this way, cache list + cache clear with no argument is the fallback). No confirmation prompt, matching the existing "manual rm -rf is safe" design for the tar cache.
  • Refactors @nitpicker/core's hardcoded analyze table cache path into getTableCacheRoot(), defined as a child of crawler's getArchiveCacheRoot(). Default behaviour is unchanged; NITPICKER_TAR_CACHE_DIR now also redirects the table cache, matching the tar cache it already redirects.
  • New crawler functions (listArchiveCacheEntries, clearArchiveCacheRoot, clearArchiveCacheEntry) are pure — they take cacheRoot/cacheDir as a parameter rather than resolving the real OS temp cache themselves, so their unit tests exercise a throwaway directory and never touch a real developer machine's cache.
  • Adds an e2e test that spawns the built CLI to prove the real wiring end-to-end (crawl → cache populated → cache list reports it → cache clear removes it), since the command-level unit test mocks @nitpicker/crawler entirely.

Test plan

  • yarn build (worktree, NX_WORKSPACE_ROOT_PATH set)
  • yarn lint
  • yarn test — 494 files / 3484 tests passed
  • yarn vitest run --config vitest.e2e.config.ts packages/test-server/src/__tests__/e2e/cache-cli.e2e.ts — 3 tests passed
  • Manual review of git diff origin/dev...HEAD for stray domains / sample-value convention

🤖 Generated with Claude Code

Adds listArchiveCacheEntries, clearArchiveCacheRoot, and clearArchiveCacheEntry
(each a pure function taking cacheRoot/cacheDir as a parameter, never
resolving the real OS temp cache themselves) plus the shared ArchiveCacheEntry
type and a pathExists helper. Also exports getArchiveCacheRoot,
computeArchiveCacheKey, and resolveArchiveCacheDir, which were previously
internal-only, so the upcoming CLI cache command can use them.
…cheRoot

Replaces the hardcoded os.tmpdir()/nitpicker/cache/table path with
getTableCacheRoot(), defined as a child of crawler's getArchiveCacheRoot().
Default behaviour is unchanged; NITPICKER_TAR_CACHE_DIR now also redirects
the analyze table cache, matching the tar-extraction cache it already
redirects.
Adds a `cache` sub-command with two operations: `list` (human-readable text
by default, `--json` for machine output) and `clear` (wipes the entire cache
root, or just one archive's tar-cache entry when a `.nitpicker` path is
given). No confirmation prompt, matching the existing "manual rm -rf is safe"
design for the tar cache. Adds formatBytes and formatCacheList as separate
testable formatting helpers.
cache.spec.ts mocks @nitpicker/crawler entirely to unit-test the command's
own branching, proving nothing about whether the real
getArchiveCacheRoot/listArchiveCacheEntries/clearArchiveCache* functions
agree with what Archive.openCached actually writes to disk. Spawns the built
CLI binary (same pattern as viewer-read-model-build.e2e.ts) with
NITPICKER_TAR_CACHE_DIR pinned to a throwaway directory, so the suite never
touches a real developer machine's cache. Registers the new file in the
e2e shard manifest.
@YusukeHirao
YusukeHirao merged commit 4a19135 into dev Jul 24, 2026
10 checks passed
@YusukeHirao
YusukeHirao deleted the worktree-clear-cache branch July 24, 2026 12:54
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