Skip to main content

agentmux_srv/migrations/
m0009_transcript_backfill.rs

1// Copyright 2026, AgentMux Corp.
2// SPDX-License-Identifier: Apache-2.0
3
4use crate::backend::storage::filestore::FileStore;
5use crate::registry;
6use super::{Migration, MigrationContext, MigrationError, MigrationScope};
7
8pub struct M0009TranscriptBackfill;
9
10impl Migration for M0009TranscriptBackfill {
11    fn id(&self) -> &'static str { "0009_transcript_backfill" }
12    fn scope(&self) -> MigrationScope { MigrationScope::Global }
13    fn description(&self) -> &'static str { "Backfill agent conversation transcripts into global shared store" }
14
15    fn up(&self, ctx: &MigrationContext) -> Result<(), MigrationError> {
16        let transcripts_dir = ctx.home.join("shared").join("agents").join("transcripts");
17        std::fs::create_dir_all(&transcripts_dir)
18            .map_err(|e| MigrationError(format!("transcript_backfill: create transcripts dir: {}", e)))?;
19
20        let global = FileStore::open(&transcripts_dir.join("filestore.db"))
21            .map_err(|e| MigrationError(format!("transcript_backfill: open global filestore: {}", e)))?;
22
23        // Collect definition IDs to seed transcripts for.
24        let def_ids: Vec<String> = {
25            let def_dir = ctx.home.join("shared").join("agents").join("definitions");
26            if def_dir.exists() {
27                registry::DefinitionStore::open(def_dir)
28                    .ok()
29                    .and_then(|ds| ds.list_active().ok())
30                    .map(|recs| recs.into_iter().map(|r| r.data.id).collect())
31                    .unwrap_or_default()
32            } else {
33                Vec::new()
34            }
35        };
36
37        crate::backend::transcript_backfill::backfill_transcripts_once(
38            &ctx.home,
39            &transcripts_dir,
40            &def_ids,
41            &global,
42        );
43        Ok(())
44    }
45}