Logo FSBarV1_Archived

MapCacheFile Module

 Persistent, file-based cache for static per-map analysis primitives.

 Distinct from  — that module is a
 thread-safe in-memory session cache for engine-callback round-trips.
 This module serialises  plus the
 chokepoint list to a deterministic JSON file on disk so a fresh clone
 of the repository can load a precomputed analysis in under 25 ms
 instead of spending ~250 ms re-parsing the .sd7 at every trainer start.

 Feature: specs/026-permanent-map-cache/
 Clarifications:
   - Staleness detection: manual integer codeVersion, exact match.
   - Mismatch policy: hard abort via LoadError (no fallback).
   - CI enforcement: out of scope; runtime abort is the backstop.

Types

Type Description

LoadError

Structured failure mode returned by . Every constructor carries the file path (when known) plus the context needed to render an actionable diagnostic.

LoadedMap

Successful read result. Contains the fully materialised MapGrid (with LosMap/RadarMap initialised to zero arrays of the correct shape — dynamic layers are refreshed per frame by the caller) and the chokepoint list in findChokepoints output order.

SupportedMap

Declarative per-map inputs that determine what gets analysed and how. One instance per supported map; the full list is exposed via .

Functions and values

Function or value Description

cachePathFor repoRoot supported

Full Usage: cachePathFor repoRoot supported

Parameters:
Returns: string

Canonical committed-cache path for a supported map. Built as {repoRoot}/bots/trainer/map-cache/{sanitised-name}.json. Both the trainer warmup and the refresh script consult this function so the sanitisation rule lives in exactly one place.

repoRoot : string
supported : SupportedMap
Returns: string

codeVersion

Full Usage: codeVersion

Returns: int
 The current code version for map-analysis cache compatibility.

 BUMP THIS INTEGER (by +1) in the same PR whenever you change any of:
   - Chokepoints.fs / BasePlan.fs / WallIn.fs — analysis semantics
   - MapGrid.fs / SmfParser.fs / MapQuery.fs — primitive extraction
   - MapCacheFile.fs — the codec itself (write/read/blob format)

 After bumping, run bots/trainer/map-cache/refresh-all.sh and commit
 the regenerated cache files in the same PR.
Returns: int

formatLoadError error

Full Usage: formatLoadError error

Parameters:
Returns: string

Format a LoadError as a multi-line human-readable error message. Always includes: the offending file path, the mismatch kind, expected vs. found values (where applicable), and the refresh command the contributor should run next.

error : LoadError
Returns: string

read supported path

Full Usage: read supported path

Parameters:
Returns: Result<LoadedMap, LoadError>

Validation pipeline and load path. Returns a structured Error for all expected failure modes — callers map those into hard-abort exceptions per FR-006 using formatLoadError for the message text. Does not throw except for truly exceptional IO failures.

supported : SupportedMap
path : string
Returns: Result<LoadedMap, LoadError>

schemaVersion

Full Usage: schemaVersion

Returns: int

The on-disk file format version. Bumped only when the serialisation layout itself changes (fields added/removed, nesting restructured, blob encoding altered). Compared exactly on load.

Returns: int

supportedMaps

Full Usage: supportedMaps

Returns: SupportedMap list

The canonical list of supported maps for which a committed cache file is required. Adding a map to the permanent cache is exactly one new element in this list plus the committed cache file produced by the refresh script.

Returns: SupportedMap list

tryFindSupportedMap mapName

Full Usage: tryFindSupportedMap mapName

Parameters:
    mapName : string

Returns: SupportedMap option

Look up a supported map by its canonical name. Returns None for any map outside the supported set, preserving the unsupported-map fallback path for non-permanent-cache consumers (FR-010).

mapName : string
Returns: SupportedMap option

write supported grid chokepoints path

Full Usage: write supported grid chokepoints path

Parameters:

Deterministic write path. Two invocations with identical inputs MUST produce byte-identical output files (SC-004). Throws on IO failure; does not catch. Does not validate that the caller's (grid, chokepoints) values are consistent with the SupportedMap declaration — the caller is expected to produce them from the same SupportedMap it passes here.

supported : SupportedMap
grid : MapGrid
chokepoints : Chokepoint list
path : string

Type something to start searching.