maple.state.store

State management for the MAPLE daemon.

This module provides persistent state tracking using SQLite for the MAPLE daemon. It manages policies, environments, containers, and evaluation runs with a robust database-backed storage system.

Key features: - SQLite-based persistent storage with WAL mode for concurrency - Policy and environment registry tracking - Container lifecycle management (both policies and environments) - Evaluation run history and statistics - Automatic database initialization and schema management - Context manager for safe database operations

The database schema includes: - policies: Downloaded/pulled policy models - envs: Downloaded environment images - containers: Currently running containers (policies and envs) - runs: Evaluation run history with metrics and outcomes

All database operations use proper transaction handling and support concurrent access through SQLite’s WAL (Write-Ahead Logging) mode.

Functions

add_container(container_id, type, name, ...)

Register a running container.

add_env(name, image)

Add or update a pulled environment.

add_policy(name, image, version, path[, repo])

Add or update a pulled policy.

add_run(run_id, policy_id, env_id, task[, ...])

Start tracking a run.

clear_containers()

Clear all container records.

finish_run(run_id, steps, total_reward, ...)

Record run completion.

get_container(container_id)

Get a container by ID.

get_container_by_name(name)

Get a container by name.

get_env(name)

Get a pulled environment.

get_policy(name, version)

Get a pulled policy.

get_run(run_id)

Get a run by ID.

get_run_stats([policy_id, task])

Get aggregate statistics for runs.

init_db()

Initialize database schema.

list_containers([type, status])

List containers with optional filters.

list_envs()

List all pulled environments.

list_policies()

List all pulled policies.

list_runs([policy_id, task, limit])

List runs with optional filters.

load_state()

Legacy function for backwards compatibility.

remove_container(container_id)

Remove a container from tracking.

remove_env(name)

Remove a pulled environment.

remove_policy(name, version)

Remove a pulled policy.

update_container_status(container_id, status)

Update container status.