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
    call_logs : Array[Json]
    reservations : Map[String, (String, String, String)]
    executors : Map[String, (String, 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::executor_clear

    fn MemoryStore::executor_clear(self : MemoryStore) -> Bool

    内存后端:清空全部执行者能力注册(Marketplace 重置/整洁)。

    MemoryStore::executor_list

    fn MemoryStore::executor_list(self : MemoryStore) -> Array[(String, String, String)]

    内存后端:列出全部执行者 (name, abilities_json, created_at)。

    MemoryStore::executor_save

    fn MemoryStore::executor_save(self : MemoryStore, name~ : String, abilities_json~ : String, created_at~ : String) -> Result[String, String]

    内存后端:写入/覆盖一个执行者的能力注册(幂等)。

    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::recent_call_logs

    fn MemoryStore::recent_call_logs(self : MemoryStore, limit? : Int) -> Array[Json]

    读取最近 N 条调用日志(新的在前)。

    MemoryStore::rsv_get

    fn MemoryStore::rsv_get(self : MemoryStore, scope : String) -> (String, String, String)?

    内存后端:查询某作用域预订(未预订返回 None)。

    MemoryStore::rsv_list

    fn MemoryStore::rsv_list(self : MemoryStore) -> Array[(String, String, String)]

    内存后端:列出全部预订(升序,无指定顺序保证)。

    MemoryStore::rsv_release

    fn MemoryStore::rsv_release(self : MemoryStore, scope : String, agent : String) -> Bool

    内存后端:释放预订(仅持有者可释放;不存在或非持有者返回 false)。

    MemoryStore::rsv_set

    fn MemoryStore::rsv_set(self : MemoryStore, scope~ : String, agent~ : String, ttl_until~ : String, created_at~ : String) -> Result[String, String]

    内存后端:写入/覆盖某作用域预订。(返回值约定:Ok(msg),不使用)

    MemoryStore::rsv_try_set

    fn MemoryStore::rsv_try_set(self : MemoryStore, scope~ : String, agent~ : String, ttl_until~ : String, created_at~ : String) -> Result[RsvOutcome, String]

    内存后端:按裁决写预订,写后回读收口。 旧形状(先 rsv_get 判空再无条件 rsv_set)在跨进程下会双方都读到空闲、双方都写成功; 内存后端本来没有那个窗口,但两后端必须同一形状,否则单测永远绿而 SQLite 红(BUG-85/BUG-79 的旧例)。

    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)。

    MemoryStore::write_call_log

    fn MemoryStore::write_call_log(self : MemoryStore, ts~ : String, tool~ : String, caller~ : String, ns~ : String, params_json~ : String, result_json~ : String, ok~ : Bool, runtime_ms~ : Int, seq~ : Int) -> Result[Unit, String]

    写入一条调用日志(MemoryStore 进程内 array,软上限 ~500,超限丢最早一条)。

    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::data_dir_ok

    fn MultiStore::data_dir_ok(dir : String) -> Bool

    库文件根目录校验(BUG-78):只接受相对 server 进程 cwd 的相对路径。 拒空串 / .. 上跳 / 前导分隔符 / 盘符(C:)——过去这里只对 ns 走 safe_ns, data_dir 原样拼进 \{dir}/\{safe}.db 就交给 SqliteStore::open(open 会建文件), 于是"命名空间物理隔离"实际是"调用方指到哪就往哪建库"。 口径与 src/server/bugreport.mbt 的 bug_project_dir_ok 保持一致: 同族守卫不该有两套规则(project_dir 拒穿越、data_dir 放行,就是本次缺陷的形状)。

    MultiStore::get

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

    获取某 ns 的存储;惰性打开:尚未打开时按 self.data_dir 首次创建/打开, 并在打开成功后缓存进 self.stores,保证后续 get/ns_stats 复用同一句柄。 ns 非法(未过 safe_ns)或打开失败返回 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}/{safe_ns}.db。 ns 会先经 safe_ns 消毒,非法命名空间直接失败返回 false。 data_dir~ 为空时回退到 self.data_dir(与 get 保持一致,避免状态分裂); 两者取用后的最终目录仍要过 data_dir_ok(BUG-78:消毒范围覆盖实际落点,不只覆盖入参形态)。

    MultiStore::safe_ns

    fn MultiStore::safe_ns(ns : String) -> String?

    命名空间消毒:仅允许 [A-Za-z0-9_-],拒绝空串及任何含(斜杠/反斜杠/点/ 控制字符/空白)的输入,杜绝路径遍历(../../etc/x)与注入。 合法返回浅拷贝后的 ns;非法返回 None。

    RsvOutcome

    pub struct RsvOutcome {
    reserved : Bool
    action : String
    prev_agent : String
    agent : String
    ttl_until : String
    }

    预订裁决结果。agent/ttl_until 一律是库里现值(conflict 时即 held_by), 不是调用方想要的那个值——回执不许由请求反推。

    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::cb_get

    fn SqliteStore::cb_get(self : SqliteStore, ns : String, circuit : String) -> (String, Int, Int, Int, Int, Int, Int)?

    读取某熔断器记录(R104):(state, failures, window_secs, threshold, recovery_secs, opened_at, last_fail_ts)。

    SqliteStore::cb_save

    fn SqliteStore::cb_save(self : SqliteStore, ns : String, circuit : String, state : String, failures : Int, window_secs : Int, threshold : Int, recovery_secs : Int, opened_at : Int, last_fail_ts : Int, updated_at : String) -> Result[Unit, String]

    写入/覆盖熔断器记录(R104,ON CONFLICT DO UPDATE 幂等)。

    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::db_path_from_env

    fn SqliteStore::db_path_from_env(env_value : String?) -> String

    由环境值决定库路径(纯函数,便于白盒判据;空串视为未设置)。

    SqliteStore::default_db_path

    fn SqliteStore::default_db_path() -> String

    进程默认库路径回显(只读,供工具与 CLI 说明"这一轮的行到底落在哪个文件")。

    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::evolve_bump_child

    fn SqliteStore::evolve_bump_child(self : SqliteStore, id : String) -> Bool

    递增某产物的 children 计数(每次新增子代 +1)。返回是否成功。

    SqliteStore::evolve_list

    fn SqliteStore::evolve_list(self : SqliteStore) -> Array[Json]

    读取全部 DGM 产物(evolve_artifacts 表),按 created_at 升序。 返回 JSON 数组(供 MCP/展示)。

    SqliteStore::evolve_upsert

    fn SqliteStore::evolve_upsert(self : SqliteStore, id~ : String, parent_id~ : String, goal~ : String, note~ : String, code~ : String, score~ : Double, parts_json~ : String, created_at~ : String) -> Result[Unit, String]

    插入一个 DGM 产物(evolve_artifacts 表)。失败返回 Err。

    SqliteStore::executor_clear

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

    SQLite 后端:清空全部执行者能力注册(Marketplace 重置/整洁)。

    SqliteStore::executor_list

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

    SQLite 后端:列出全部执行者 (name, abilities_json, created_at)。

    SqliteStore::executor_save

    fn SqliteStore::executor_save(self : SqliteStore, name~ : String, abilities_json~ : String, created_at~ : String) -> Result[String, String]

    SQLite 后端:写入/覆盖一个执行者的能力注册。(幂等:同 name 覆盖)

    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_heartbeat_intervals

    fn SqliteStore::list_heartbeat_intervals(self : SqliteStore, task_id : String, limit? : Int) -> Array[Int]

    读取指定任务的心跳间隔历史(时间序:旧→新;最多 limit 条,默认 100)。

    SqliteStore::list_saga_actions

    fn SqliteStore::list_saga_actions(self : SqliteStore, ns : String, root_task_id : String) -> Array[(Int, String, String, String, String)]

    列出某根任务已登记的 Saga 补偿步骤(前向顺序 id ASC:登记顺序)。 返回 (id, step, task_id, compensation, status) 五元组数组。

    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
    ]

    列出指定命名空间的任务。 BUG-85:空 ns 的回退口径与内存后端对齐(list_tasks_in("") = 默认命名空间), 否则同一个入参在两个后端上一个是 default 行、一个是零行。

    SqliteStore::mark_saga_actions_done

    fn SqliteStore::mark_saga_actions_done(self : SqliteStore, ns? : String, root_task_id~ : String, ids~ : Array[Int]) -> Result[Unit, String]

    把指定 Saga 补偿步骤标记为 done(已补偿/已消费),幂等。

    SqliteStore::new

    fn SqliteStore::new() -> SqliteStore?

    以默认路径打开的便捷构造。 BUG-90:默认路径过去写死 fist-mbt.db,调用面没有任何合规出口把一整轮验证 收进独立库 —— store_open(scratch=true) 自称"库落 temp/ 临时区,不污染仓库根", 实测任务行仍落仓库根 fist-mbt.db(工具闭包用的是模块级 engine,而非 mstore 里的 ns 库)。 这里补的是运维侧出口:FIST_DB_PATH 环境变量,与 FIST_RUN_CHECK_ALLOW 同族 (扩权位只在进程环境里,调用方传参不能自我扩权)。未设置时行为逐字不变。

    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::recent_call_logs

    fn SqliteStore::recent_call_logs(self : SqliteStore, limit? : Int) -> Array[Json]

    读取最近 N 条调用日志(按自增 id DESC,新的在前;seq 仅作同进程单调定位)。

    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::rsv_get

    fn SqliteStore::rsv_get(self : SqliteStore, scope : String) -> (String, String, String)?

    SQLite 后端:查询某作用域预订。

    SqliteStore::rsv_list

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

    SQLite 后端:列出全部预订。

    SqliteStore::rsv_release

    fn SqliteStore::rsv_release(self : SqliteStore, scope : String, agent : String) -> Bool

    SQLite 后端:释放预订(仅持有者)。 BUG-79:Statement::execute -> Bool 只表示「语句没报错」——绑定层(mizchi/sqlite 的 js 与 native 两版签名都是 execute -> Bool)根本不给 changes(),删 0 行同样返回 true。 于是非持有者调 reserve_release 会被告知「已释放」而预订仍在,两个 agent 同改一份作用域, 正是这个原语要防的多 agent 撞车;内存后端校持有者,所以它的单测永远绿、抓不到。 修法:删前先按 scope 读回持有者比对,不匹配即 false(与内存后端同语义)。

    SqliteStore::rsv_set

    fn SqliteStore::rsv_set(self : SqliteStore, scope~ : String, agent~ : String, ttl_until~ : String, created_at~ : String) -> Result[String, String]

    SQLite 后端:写入/覆盖某作用域预订(ON CONFLICT DO UPDATE)。

    SqliteStore::rsv_try_set

    fn SqliteStore::rsv_try_set(self : SqliteStore, scope~ : String, agent~ : String, ttl_until~ : String, created_at~ : String) -> Result[RsvOutcome, String]

    SQLite 后端:按裁决写预订——抢不到就是 0 行,不是异常(BUG-136)。 与旧 rsv_set(无条件 ON CONFLICT DO UPDATE SET)的区别在 WHERE: 只有「本来就是我的」或「现持有者的 TTL 已过期」才覆盖,二者都由数据库判, 不由调用方写前那次读判(excluded.created_at 就是本次请求的服务端盖章时刻)。 纯 INSERT 不带 conflict 子句这条路不能用:约束冲突会撞上面那个抛异常形态, 把一次正常冲突变成 server 崩溃。结论一律取写后回读,与内存后端同构。

    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_call_log

    fn SqliteStore::write_call_log(self : SqliteStore, ts~ : String, tool~ : String, caller~ : String, ns~ : String, params_json~ : String, result_json~ : String, ok~ : Bool, runtime_ms~ : Int, seq~ : Int) -> Result[Unit, String]

    写入一条调用日志到 call_log 表。best-effort:失败返回 Err(调用方应忽略)。

    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,不存在则插入)。

    SqliteStore::write_heartbeat_interval

    fn SqliteStore::write_heartbeat_interval(self : SqliteStore, task_id~ : String, interval_sec~ : Int, ts~ : String) -> Result[Unit, String]

    追加一条心跳间隔历史(R90,Phi Accrual 判活的数据源);同一任务保留最近 1000 条。

    SqliteStore::write_saga_action

    fn SqliteStore::write_saga_action(self : SqliteStore, ns? : String, root_task_id~ : String, step~ : String, task_id? : String, compensation~ : String, created_at~ : String) -> Result[Unit, String]

    登记一条 Saga 补偿步骤(R92,durable action log):同一 (ns, root_task_id, step) 幂等覆盖——重登记会把 status 重置为 pending(重试安全),created_at 刷新。

    StoreBackend

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

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

    StoreBackend::backend_name

    fn StoreBackend::backend_name(self : StoreBackend) -> String

    后端自述(BUG-119):"sqlite" 表示心跳真的落库、跨进程可读;"memory" 表示只活在本进程。 看护面必须把它打进回执——否则内存后端会冒充"心跳已持久化"。

    StoreBackend::cb_get

    fn StoreBackend::cb_get(self : StoreBackend, ns : String, circuit : String) -> (String, Int, Int, Int, Int, Int, Int)?

    读取某熔断器记录(R104:内存后端返回 None,SQLite 实读)。

    StoreBackend::cb_save

    fn StoreBackend::cb_save(self : StoreBackend, ns : String, circuit : String, state : String, failures : Int, window_secs : Int, threshold : Int, recovery_secs : Int, opened_at : Int, last_fail_ts : Int, updated_at : String) -> Result[Unit, String]

    写入/覆盖熔断器记录(R104:内存后端为 no-op,SQLite 幂等 upsert)。

    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::executor_clear

    fn StoreBackend::executor_clear(self : StoreBackend) -> Bool

    后端统一:清空全部执行者能力注册(Marketplace 重置/整洁)。

    StoreBackend::executor_list

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

    后端统一:列出全部执行者 (name, abilities_json, created_at)。

    StoreBackend::executor_save

    fn StoreBackend::executor_save(self : StoreBackend, name~ : String, abilities_json~ : String, created_at~ : String) -> Result[String, 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_heartbeat_intervals

    fn StoreBackend::list_heartbeat_intervals(self : StoreBackend, task_id : String, limit? : Int) -> Array[Int]

    读取心跳间隔历史(R90:内存后端返回空)。

    StoreBackend::list_saga_actions

    fn StoreBackend::list_saga_actions(self : StoreBackend, ns : String, root_task_id : String) -> Array[(Int, String, String, String, String)]

    列出某根任务的 Saga 补偿步骤(R92:内存后端返回空,SQLite 前向顺序)。

    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::mark_saga_actions_done

    fn StoreBackend::mark_saga_actions_done(self : StoreBackend, ns? : String, root_task_id~ : String, ids~ : Array[Int]) -> Result[Unit, String]

    把指定 Saga 补偿步骤标记 done(R92:内存后端为 no-op,SQLite 幂等更新)。

    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::recent_call_logs

    fn StoreBackend::recent_call_logs(self : StoreBackend, limit? : Int) -> Array[Json]

    读取最近 N 条调用日志(双后端统一入口,新的在前)。

    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::rsv_get

    fn StoreBackend::rsv_get(self : StoreBackend, scope : String) -> (String, String, String)?

    后端统一:查询某作用域预订。

    StoreBackend::rsv_list

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

    后端统一:列出全部预订。

    StoreBackend::rsv_release

    fn StoreBackend::rsv_release(self : StoreBackend, scope : String, agent : String) -> Bool

    后端统一:释放预订(仅持有者)。

    StoreBackend::rsv_set

    fn StoreBackend::rsv_set(self : StoreBackend, scope~ : String, agent~ : String, ttl_until~ : String, created_at~ : String) -> Result[String, String]

    后端统一:写入/覆盖某作用域预订(拿来主义:Interlinked 文件预订)。

    StoreBackend::rsv_try_set

    fn StoreBackend::rsv_try_set(self : StoreBackend, scope~ : String, agent~ : String, ttl_until~ : String, created_at~ : String) -> Result[RsvOutcome, String]

    后端统一:按裁决写预订(BUG-136)。抢不到就抢不到,绝不覆盖别人的活体预订; 两个后端返回同一种结论(旧例 BUG-85:同名方法两种语义,单测永远绿而线上红)。

    StoreBackend::set_namespace

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

    设置默认命名空间

    StoreBackend::sqlite

    StoreBackend::sqlite_store

    fn StoreBackend::sqlite_store(self : StoreBackend) -> SqliteStore?

    提取底层 SQLite 句柄(内存后端返回 None)。 供跨包复用 SqliteStore 专有能力(如 evolve_artifacts 的 evolve_upsert / evolve_list)。

    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_call_log

    fn StoreBackend::write_call_log(self : StoreBackend, ts~ : String, tool~ : String, caller~ : String, ns~ : String, params_json~ : String, result_json~ : String, ok~ : Bool, runtime_ms~ : Int, seq~ : Int) -> Result[Unit, String]

    写入一条调用日志(双后端统一入口,best-effort:失败仅返回 Err,调用方应忽略)。

    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)。

    StoreBackend::write_heartbeat_interval

    fn StoreBackend::write_heartbeat_interval(self : StoreBackend, task_id~ : String, interval_sec~ : Int, ts~ : String) -> Result[Unit, String]

    追加心跳间隔历史(R90:SQLite 落库,内存后端为 no-op——与心跳表同模式)。

    StoreBackend::write_saga_action

    fn StoreBackend::write_saga_action(self : StoreBackend, ns? : String, root_task_id~ : String, step~ : String, task_id? : String, compensation~ : String, created_at~ : String) -> Result[Unit, String]

    登记 Saga 补偿步骤(R92:SQLite 落库 durable action log,内存后端为 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)

    rsv_action

    fn rsv_action(prev : (String, String, String)?, agent : String, now : String) -> (Bool, String)

    裁决规则单一真源:给定写前快照与本次请求,判「该不该写」+动作标签。 两个后端都从这里取标签,SQLite 侧的 ON CONFLICT ... WHERE 编码的是同一条规则 (reservations.agent = excluded.agent OR reservations.ttl_until < excluded.created_at)。 同持有者排在过期之前:自己续一条已过期的预订,报 renewed 而不是 taken_over(与旧口径逐字一致)。

    specs_table_sql

    fn specs_table_sql() -> String

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