vicTop-cw/fist-mbt/src/store does not have a README file

    Store

    pub trait Store {
    fn create_task(Self,
    Task
    ) -> Result[Unit, String]
    fn get_task(Self, String) ->
    Task
    ?
    fn update_task(Self,
    Task
    ) -> Result[Unit, String]
    fn list_tasks(Self) -> Array[
    Task
    ]
    fn delete_task(Self, String) -> Result[Unit, String]
    fn clear(Self) -> Unit
    }

    仓库统一接口

    ExecutionRecord

    pub struct ExecutionRecord {
    id : String
    task_id : String
    executor : String
    model : String
    tokens_in : Int
    tokens_out : Int
    cost : Double
    duration_ms : Int
    rate_limited : Bool
    failure_reason : String
    created_at : String
    }

    执行记录结构体

    MemoryStore

    pub struct MemoryStore {
    tasks : Map[String,
    Task
    ]
    specs : Map[String, SpecRecord]
    default_ns : String
    }

    内存实现:进程内 Map,简单可靠,配合单机 MCP server 足够。

    MemoryStore::clear

    fn MemoryStore::clear(self : MemoryStore) -> Unit

    提升声明:允许通过具体类型直接调用 trait 方法(避免 deprecated 隐式提升)。

    MemoryStore::create_task

    fn MemoryStore::create_task(self : MemoryStore, task :
    Task
    ) -> Result[Unit, String]

    提升声明:允许通过具体类型直接调用 trait 方法(避免 deprecated 隐式提升)。

    MemoryStore::delete_task

    fn MemoryStore::delete_task(self : MemoryStore, id : String) -> Result[Unit, String]

    提升声明:允许通过具体类型直接调用 trait 方法(避免 deprecated 隐式提升)。

    MemoryStore::get_spec

    fn MemoryStore::get_spec(self : MemoryStore, id : String) -> SpecRecord?

    按 id 读取单条语料记录。

    MemoryStore::get_task

    fn MemoryStore::get_task(self : MemoryStore, id : String) ->
    Task
    ?

    提升声明:允许通过具体类型直接调用 trait 方法(避免 deprecated 隐式提升)。

    MemoryStore::list_specs_by_task

    fn MemoryStore::list_specs_by_task(self : MemoryStore, task_id : String) -> Array[SpecRecord]

    列出某任务的全部语料 / 复验记录。

    MemoryStore::list_tasks

    提升声明:允许通过具体类型直接调用 trait 方法(避免 deprecated 隐式提升)。

    MemoryStore::list_tasks_in

    fn MemoryStore::list_tasks_in(self : MemoryStore, ns_filter : String) -> Array[
    Task
    ]

    列出指定命名空间的任务

    MemoryStore::new

    MemoryStore::update_spec_status

    fn MemoryStore::update_spec_status(self : MemoryStore, id : String, status : String, content : String, updated_at : String) -> Result[Unit, String]

    更新语料状态(可同时更新内容与时间戳)。

    MemoryStore::update_task

    fn MemoryStore::update_task(self : MemoryStore, task :
    Task
    ) -> Result[Unit, String]

    提升声明:允许通过具体类型直接调用 trait 方法(避免 deprecated 隐式提升)。

    MemoryStore::upsert_spec

    fn MemoryStore::upsert_spec(self : MemoryStore, rec : SpecRecord) -> Result[Unit, String]

    写入 / 覆盖一条语料记录(主键 id)。

    MultiStore

    pub struct MultiStore {
    stores : Map[String, SqliteStore]
    data_dir : String
    }

    FIST-Mbt store: 命名空间多库持久化管理器。 按 ns 路由到独立 SQLite 文件 {data_dir}/{ns}.db,惰性打开(首次访问才建库)。 每个 ns 拥有独立的物理库文件,实现多租户/多项目隔离;路径完全由参数传入, 不做任何绝对路径硬编码。

    可变性模式与 AuditLog 一致:通过 self.stores.set / self.stores.remove 原地修改, 无需在调用方重新赋值。这样可被模块级不可变绑定持有,供 MCP 工具闭包安全调用。

    MultiStore::close

    fn MultiStore::close(self : MultiStore, ns : String) -> Unit

    关闭并移除某个命名空间(不删除物理文件,可重新 open 恢复)。

    MultiStore::close_all

    fn MultiStore::close_all(self : MultiStore) -> Unit

    关闭全部命名空间。

    MultiStore::get

    fn MultiStore::get(self : MultiStore, ns : String) -> SqliteStore?

    获取某 ns 的存储;惰性打开:尚未打开时按当前 data_dir 首次创建/打开。 打开失败返回 None。

    MultiStore::new

    fn MultiStore::new(data_dir? : String) -> MultiStore

    构造:仅记录根目录,不打开任何库(惰性)。

    MultiStore::ns_list

    fn MultiStore::ns_list(self : MultiStore) -> Array[String]

    列出已打开的命名空间(Map 遍历顺序,不保证稳定)。

    MultiStore::ns_stats

    fn MultiStore::ns_stats(self : MultiStore) -> Json

    每个已打开 ns 的任务数统计(直接用该 ns 库的 tasks 表 COUNT)。 返回 Json 数组,元素形如 {"ns": "...", "total": N}。

    MultiStore::open

    fn MultiStore::open(self : MultiStore, ns~ : String, data_dir~ : String) -> Bool

    打开(或复用已打开的)某个命名空间对应的库文件 {data_dir}/{ns}.db。 失败返回 false,成功返回 true。

    SpecRecord

    pub struct SpecRecord {
    id : String
    task_id : String
    spec_type : String
    content : String
    status : String
    created_at : String
    updated_at : String
    } derive(Eq,
    Debug
    )

    语料 / 复验记录(跨后端统一结构)。

    SpecRecord::new

    fn SpecRecord::new(id~ : String, task_id~ : String, spec_type? : String, content? : String, status? : String, created_at? : String, updated_at? : String) -> SpecRecord

    便捷构造(仅 id / task_id 必填,其余带默认值)。

    SpecRecord::to_json

    fn SpecRecord::to_json(self : SpecRecord) -> Json

    记录转 JSON(供 MCP 工具输出,content 不展开以免撑爆响应)。

    SqliteStore

    pub struct SqliteStore {
    db :
    Database
    ?
    }

    SQLite 后端:持有打开的 Database(Option 以承载 open 失败场景)。

    SqliteStore::archive_task

    fn SqliteStore::archive_task(self : SqliteStore, t :
    Task
    , archived_at~ : String) -> Result[Unit, String]

    将已归档任务写入 archive 表快照。

    SqliteStore::clear

    fn SqliteStore::clear(self : SqliteStore) -> Unit

    提升声明:允许通过具体类型直接调用 trait 方法。

    SqliteStore::create_task

    fn SqliteStore::create_task(self : SqliteStore, task :
    Task
    ) -> Result[Unit, String]

    提升声明:允许通过具体类型直接调用 trait 方法。

    SqliteStore::delete_heartbeat

    fn SqliteStore::delete_heartbeat(self : SqliteStore, task_id : String) -> Result[Unit, String]

    删除心跳记录。

    SqliteStore::delete_task

    fn SqliteStore::delete_task(self : SqliteStore, id : String) -> Result[Unit, String]

    提升声明:允许通过具体类型直接调用 trait 方法。

    SqliteStore::ensure_specs_table

    fn SqliteStore::ensure_specs_table(self : SqliteStore) -> Bool

    确保 specs 表存在(幂等;旧库自动补齐)。

    SqliteStore::get_spec

    fn SqliteStore::get_spec(self : SqliteStore, id : String) -> SpecRecord?

    按 id 读取单条语料记录。

    SqliteStore::get_task

    fn SqliteStore::get_task(self : SqliteStore, id : String) ->
    Task
    ?

    提升声明:允许通过具体类型直接调用 trait 方法。

    SqliteStore::list_all_heartbeats

    fn SqliteStore::list_all_heartbeats(self : SqliteStore) -> Array[(String, String, String, String)]

    列出全部心跳记录(供启动时加载)。

    SqliteStore::list_archived

    fn SqliteStore::list_archived(self : SqliteStore) -> Array[(String, String)]

    列出全部归档快照(id -> 原 task_json)。

    SqliteStore::list_specs_by_task

    fn SqliteStore::list_specs_by_task(self : SqliteStore, task_id : String) -> Array[SpecRecord]

    列出某任务的全部语料 / 复验记录(按 created_at、id 升序)。

    SqliteStore::list_tasks

    提升声明:允许通过具体类型直接调用 trait 方法。

    SqliteStore::list_tasks_in

    fn SqliteStore::list_tasks_in(self : SqliteStore, ns_filter : String) -> Array[
    Task
    ]

    列出指定命名空间的任务

    SqliteStore::new

    fn SqliteStore::new() -> SqliteStore?

    以默认路径(fist-mbt.db,随运行目录)打开的便捷构造。

    SqliteStore::open

    fn SqliteStore::open(db_path : String) -> SqliteStore?

    打开数据库并初始化五表 schema。失败返回 None(调用方决定是否 abort / 回退内存)。

    SqliteStore::read_heartbeat

    fn SqliteStore::read_heartbeat(self : SqliteStore, task_id : String) -> (String, String, String)

    读取指定任务的心跳记录。

    SqliteStore::record_execution

    fn SqliteStore::record_execution(self : SqliteStore, task_id~ : String, executor~ : String, model~ : String, tokens_in~ : Int, tokens_out~ : Int, cost~ : Double, duration_ms~ : Int, rate_limited~ : Bool, failure_reason~ : String, created_at~ : String) -> Result[Unit, String]

    写入执行记录(供 execute 工具调用)。

    SqliteStore::update_spec_status

    fn SqliteStore::update_spec_status(self : SqliteStore, id : String, status : String, content : String, updated_at : String) -> Result[Unit, String]

    更新语料状态(可同时更新内容与时间戳)。

    SqliteStore::update_task

    fn SqliteStore::update_task(self : SqliteStore, task :
    Task
    ) -> Result[Unit, String]

    提升声明:允许通过具体类型直接调用 trait 方法。

    SqliteStore::upsert_spec

    fn SqliteStore::upsert_spec(self : SqliteStore, rec : SpecRecord) -> Result[Unit, String]

    写入 / 覆盖一条语料记录(UPSERT,主键 id)。

    SqliteStore::write_heartbeat

    fn SqliteStore::write_heartbeat(self : SqliteStore, agent_id~ : String, task_id~ : String, last_seen~ : String, status~ : String) -> Result[Unit, String]

    写入心跳记录(UPSERT:存在则更新 last_seen / status,不存在则插入)。

    StoreBackend

    pub enum StoreBackend {
    Mem(MemoryStore)
    Sql(SqliteStore)
    }

    后端路由:内存版(默认,测试/演示)或 SQLite 持久化(运行时内建数据库)。 FistEngine 持此类型,业务层不感知具体后端。

    StoreBackend::clear

    fn StoreBackend::clear(self : StoreBackend) -> Unit

    StoreBackend::cost_stats

    fn StoreBackend::cost_stats(self : StoreBackend) -> Json

    成本聚合统计:SQLite 后端从 executions 表聚合,内存后端返回零值。

    StoreBackend::create_task

    fn StoreBackend::create_task(self : StoreBackend, task :
    Task
    ) -> Result[Unit, String]

    StoreBackend::delete_heartbeat

    fn StoreBackend::delete_heartbeat(self : StoreBackend, task_id : String) -> Result[Unit, String]

    删除心跳记录。

    StoreBackend::delete_task

    fn StoreBackend::delete_task(self : StoreBackend, id : String) -> Result[Unit, String]

    StoreBackend::get_spec

    fn StoreBackend::get_spec(self : StoreBackend, id : String) -> SpecRecord?

    按 id 读取单条语料记录。

    StoreBackend::get_task

    StoreBackend::list_all_heartbeats

    fn StoreBackend::list_all_heartbeats(self : StoreBackend) -> Array[(String, String, String, String)]

    列出全部心跳记录(供启动时加载)。

    StoreBackend::list_specs_by_task

    fn StoreBackend::list_specs_by_task(self : StoreBackend, task_id : String) -> Array[SpecRecord]

    列出某任务的全部语料 / 复验记录。

    StoreBackend::list_tasks

    StoreBackend::list_tasks_in

    fn StoreBackend::list_tasks_in(self : StoreBackend, ns : String) -> Array[
    Task
    ]

    列出指定命名空间的任务(跨后端)

    StoreBackend::memory

    fn StoreBackend::memory() -> StoreBackend

    后端工厂(跨包构造 StoreBackend 需经 pub 函数)

    StoreBackend::read_heartbeat

    fn StoreBackend::read_heartbeat(self : StoreBackend, task_id : String) -> (String, String, String)

    读取心跳记录(返回 (agent_id, last_seen, status),无记录返回 ("", "", ""))。

    StoreBackend::record_execution

    fn StoreBackend::record_execution(self : StoreBackend, task_id~ : String, executor~ : String, model~ : String, tokens_in~ : Int, tokens_out~ : Int, cost~ : Double, duration_ms~ : Int, rate_limited~ : Bool, failure_reason~ : String, created_at~ : String) -> Result[Unit, String]

    执行元数据记录(可选参数,供 execute 工具写入 executions 表)。 MemoryStore 为 no-op,SqliteStore 写入 executions 表。

    StoreBackend::set_namespace

    fn StoreBackend::set_namespace(self : StoreBackend, ns : String) -> Unit

    设置默认命名空间

    StoreBackend::sqlite

    StoreBackend::update_spec_status

    fn StoreBackend::update_spec_status(self : StoreBackend, id : String, status : String, content : String, updated_at : String) -> Result[Unit, String]

    更新语料状态。

    StoreBackend::update_task

    fn StoreBackend::update_task(self : StoreBackend, task :
    Task
    ) -> Result[Unit, String]

    StoreBackend::upsert_spec

    fn StoreBackend::upsert_spec(self : StoreBackend, rec : SpecRecord) -> Result[Unit, String]

    写入 / 覆盖一条语料记录(内存与 SQLite 后端均真实落库)。

    StoreBackend::write_heartbeat

    fn StoreBackend::write_heartbeat(self : StoreBackend, agent_id~ : String, task_id~ : String, last_seen~ : String, status~ : String) -> Result[Unit, String]

    写入心跳记录(SQLite 落库,内存后端为 no-op)。

    aggregate_stats

    fn aggregate_stats(db :
    Database
    ) -> Json

    聚合统计:总成本 / 总 token / 执行次数 / 按执行器分组

    executions_table_sql

    fn executions_table_sql() -> String

    executions 表 CREATE TABLE SQL(使用 \n 避免跨行字面量)

    init_executions_table

    fn init_executions_table(db :
    Database
    ) -> Bool

    初始化 executions 表

    insert_execution

    fn insert_execution(db :
    Database
    , rec : ExecutionRecord) -> Result[Unit, String]

    写入执行记录

    list_all_executions

    fn list_all_executions(db :
    Database
    ) -> Array[ExecutionRecord]

    列出全部执行记录(按 created_at DESC)

    specs_table_sql

    fn specs_table_sql() -> String

    specs 表 CREATE TABLE SQL(幂等,兼容旧库)。