Skip to main content

agentmux_srv_core/backend/storage/
builtin_seeds.rs

1// Copyright 2026, AgentMux Corp.
2// SPDX-License-Identifier: Apache-2.0
3
4//! The record of what AgentMux has shipped into a store once (`backend::builtin_skills`): a key per seeded
5//! item that stays after the user deletes the item, so a delete is final and the seed does not bring it
6//! back at the next start. The table is created on first use, like `db_skill_reach`, with no schema bump.
7
8use rusqlite::params;
9
10use super::error::StoreError;
11use super::store::Store;
12
13const SCHEMA: &str = "CREATE TABLE IF NOT EXISTS db_builtin_seeds (
14        key       TEXT PRIMARY KEY,
15        seeded_at INTEGER NOT NULL DEFAULT 0
16    );";
17
18impl Store {
19    /// Whether the item `key` was seeded into this store before (and may since have been edited or deleted).
20    pub fn builtin_seed_done(&self, key: &str) -> Result<bool, StoreError> {
21        let conn = self.conn.lock().unwrap();
22        conn.execute_batch(SCHEMA)?;
23        let n: i64 = conn.query_row("SELECT COUNT(*) FROM db_builtin_seeds WHERE key = ?1", params![key], |r| r.get(0))?;
24        Ok(n > 0)
25    }
26
27    /// Records that `key` was seeded at `now_ms`. Marking twice keeps the first time.
28    pub fn builtin_seed_mark(&self, key: &str, now_ms: i64) -> Result<(), StoreError> {
29        let conn = self.conn.lock().unwrap();
30        conn.execute_batch(SCHEMA)?;
31        conn.execute("INSERT OR IGNORE INTO db_builtin_seeds (key, seeded_at) VALUES (?1, ?2)", params![key, now_ms])?;
32        Ok(())
33    }
34}