ml_switcheroo.cli.handlers.snapshots

Snapshot and Sync Command Handlers.

This module manages the “Spoke” side of the Knowledge Base (Snapshots & Overlays). It handles: 1. Syncing: Linking Abstract Standards (Hub) to installed framework implementations. 2. Snapshotting: Capturing API surfaces for Ghost Mode support.

Update: Automatically extracts test_config from adapters and persists it into the snapshot templates. This ensures gen-tests has the necessary metadata.

Functions

handle_snapshot(→ int)

Handles the 'snapshot' command.

handle_sync(→ int)

Handles the 'sync' command.

Module Contents

ml_switcheroo.cli.handlers.snapshots.handle_snapshot(out_dir: pathlib.Path | None) int

Handles the ‘snapshot’ command.

Scans installed frameworks and dumps their API signatures to JSON files. These snapshots allow the engine to operate in “Ghost Mode” (e.g., in WebAssembly) without requiring the heavy frameworks to be installed.

Parameters:

out_dir – Optional custom output directory. Defaults to package/snapshots.

Returns:

Exit code.

Return type:

int

ml_switcheroo.cli.handlers.snapshots.handle_sync(framework: str) int

Handles the ‘sync’ command.

Links the Abstract Standards (Hub) to the concrete implementation in a specific framework. This process involves: 1. Reading the Specs from semantics/. 2. Introspecting the installed framework to find matching APIs. 3. Merging Static Definitions from the Adapter (for Ghost support). 4. Applying Adapter-specific manual wiring (plugins, templates). 5. Persisting Test Configuration templates. 6. Writing the results to the Snapshot Overlay (snapshots/{fw}_mappings.json).

Parameters:

framework – The framework key to sync (e.g. ‘torch’, ‘jax’).

Returns:

Exit code.

Return type:

int