Skip to main content

Module scan_cache

Module scan_cache 

Source
Expand description

A3: LLM admission scan result cache.

Persists scan results to ~/.skilllite/scan-cache.json. Key = content_hash (SHA256 of skill_md + script_samples). Same hash within TTL avoids redundant LLM calls.

§Concurrency safety

put_cached uses a write-to-temp-then-rename strategy so that concurrent processes never see a partially-written (corrupt) JSON file. On POSIX, rename(2) is atomic: the destination path atomically switches from the old content to the new content. If two processes write at the same time the last rename wins (last-writer-wins), which is acceptable for a cache — the losing entry will simply be recomputed on the next miss.

Functions§

content_hash
Compute SHA256 hash of content for cache key.
get_cached
Look up cached LLM admission result. Returns (risk, reason) if found and not expired.
put_cached
Store LLM admission result in cache.