Skip to content

feat: manifest-based cache with intent-based API#23

Merged
liamcervante merged 3 commits intomainfrom
dev-130/manifest-cache
Mar 13, 2026
Merged

feat: manifest-based cache with intent-based API#23
liamcervante merged 3 commits intomainfrom
dev-130/manifest-cache

Conversation

@liamcervante
Copy link
Collaborator

@liamcervante liamcervante commented Mar 12, 2026

Summary

  • Replaces per-file cache scanning with a manifest-based design (manifest.json) using a map for O(1) lookups by path hash
  • Introduces three intent-based cache functions:
    • ForPath(path): exact path lookup with TTL and freshness checks (used by inspect <path>)
    • Latest(allowStale): returns the most recent entry within TTL (used by inspect with no args, and by scan/price for diffing)
    • ReadFile(path): reads a raw JSON file, bypassing the cache entirely (used by inspect --file)
  • Removes session tracking entirely (INFRACOST_SESSION_ID, TERM_SESSION_ID, session maps, session pruning) — terminal session IDs were unreliable across different terminal emulators and agent environments
  • The price command's temporary directory case is handled by Latest(true) which simply returns the most recent cached entry regardless of path

Test plan

  • All cache tests passing (ForPath, Latest, ReadFile, manifest load/save)
  • Tests cover TTL expiry, staleness detection, deleted source directories, heavy dir skipping
  • Callers (inspect.go, scan.go, price.go) updated and build passes
  • Technical docs updated

Introduce a manifest (manifest.json) that indexes all cache entries,
replacing the old approach of scanning individual JSON files on disk.

Key changes:
- Session ID no longer auto-detected from parent process ID (unreliable
  with AI agents that spawn new shells per command)
- Three-tier session model: explicit INFRACOST_SESSION_ID (skips TTL),
  TERM_SESSION_ID fallback (respects TTL), and path+TTL only
- Manifest uses two maps: Entries (path hash → metadata) for O(1) path
  lookups, and Sessions (session ID → cache key) for O(1) session lookups
- Read/ReadLatest return *format.Output directly instead of *Entry wrapper
- Stale session mappings (>24h) pruned on save to prevent unbounded growth
- Manifest singleton moved from package-level var to Config struct
@liamcervante liamcervante requested a review from a team March 12, 2026 17:22
Replace Read/ReadLatest/Previous with three intent-based functions:
- ForPath(path): exact path lookup with TTL and freshness checks
- Latest(allowStale): most recent entry within TTL, no session logic
- ReadFile(path): raw JSON file, bypasses cache

Remove session tracking entirely (SessionID, TermSessionID, Sessions
map, session pruning). Terminal session IDs were unreliable across
different terminal emulators and agent environments. The Latest function
now handles the price command's temp directory case by simply returning
the most recent cached entry.
@liamcervante liamcervante changed the title feat: manifest-based cache with tiered session lookups feat: manifest-based cache with intent-based API Mar 13, 2026
Copy link
Member

@owenrumney owenrumney left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approval stands - one clarifying question

@liamcervante liamcervante merged commit c9b7f9c into main Mar 13, 2026
5 checks passed
@liamcervante liamcervante deleted the dev-130/manifest-cache branch March 13, 2026 15:01
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.

2 participants