Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 125 additions & 4 deletions cli/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ categories = ["command-line-utilities", "development-tools"]
anyhow = "1"
chrono = "0.4"
clap = { version = "4", features = ["derive"] }
turso = "0.6.0"
turso = { version = "0.6.0", features = ["sync"] }
clap_complete = "4"
dirs = "6"
hmac = "0.13"
Expand Down
24 changes: 24 additions & 0 deletions cli/src/cli_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ pub const VERSION_CLAP_ABOUT: &str = "Print deterministic runtime version metada
pub const VERSION_TOP_LEVEL_PURPOSE: &str = "Print deterministic runtime version metadata";
pub const VERSION_SHOW_IN_TOP_LEVEL_HELP: bool = true;

pub const SYNC_CLAP_ABOUT: &str = "Push or pull changes to/from Turso Cloud";
pub const SYNC_TOP_LEVEL_PURPOSE: &str = "Sync local database with Turso Cloud (push/pull)";
pub const SYNC_SHOW_IN_TOP_LEVEL_HELP: bool = true;

pub const COMPLETION_CLAP_ABOUT: &str = "Generate deterministic shell completion scripts";
pub const COMPLETION_TOP_LEVEL_PURPOSE: &str = "Generate deterministic shell completion scripts";
pub const COMPLETION_SHOW_IN_TOP_LEVEL_HELP: bool = true;
Expand Down Expand Up @@ -75,6 +79,11 @@ pub const TOP_LEVEL_COMMANDS: &[TopLevelCommandMetadata] = &[
purpose: COMPLETION_TOP_LEVEL_PURPOSE,
show_in_top_level_help: COMPLETION_SHOW_IN_TOP_LEVEL_HELP,
},
TopLevelCommandMetadata {
name: crate::services::sync::NAME,
purpose: SYNC_TOP_LEVEL_PURPOSE,
show_in_top_level_help: SYNC_SHOW_IN_TOP_LEVEL_HELP,
},
];

#[derive(Parser, Debug)]
Expand Down Expand Up @@ -190,6 +199,12 @@ pub enum Commands {
#[arg(long, value_enum)]
shell: CompletionShell,
},

#[command(about = SYNC_CLAP_ABOUT, hide = !SYNC_SHOW_IN_TOP_LEVEL_HELP)]
Sync {
#[command(subcommand)]
subcommand: SyncSubcommand,
},
}

#[derive(Subcommand, Debug, Clone, PartialEq, Eq)]
Expand Down Expand Up @@ -276,6 +291,15 @@ pub enum HooksSubcommand {
DiffTrace,
}

#[derive(Subcommand, Debug, Clone, PartialEq, Eq)]
pub enum SyncSubcommand {
#[command(about = "Push local changes to Turso Cloud")]
Push,

#[command(about = "Pull remote changes from Turso Cloud")]
Pull,
}

#[derive(ValueEnum, Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum OutputFormat {
#[default]
Expand Down
9 changes: 8 additions & 1 deletion cli/src/services/agent_trace_db/lifecycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,15 @@ impl ServiceLifecycle for AgentTraceDbLifecycle {
}

fn setup(&self, _ctx: &AppContext) -> Result<SetupOutcome> {
AgentTraceDb::new()
let db = AgentTraceDb::new()
.context("Agent trace DB lifecycle setup failed while initializing agent trace DB")?;

if db.is_sync_mode() {
if let Err(e) = db.pull() {
tracing::warn!("Agent trace DB initial sync pull failed (setup continues): {e}");
}
}

Ok(SetupOutcome::default())
}
}
Expand Down
4 changes: 4 additions & 0 deletions cli/src/services/agent_trace_db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ impl DbSpec for AgentTraceDbSpec {
fn migrations() -> &'static [(&'static str, &'static str)] {
AGENT_TRACE_MIGRATIONS
}

fn sync_enabled() -> bool {
true
}
}

/// Agent trace Turso database adapter.
Expand Down
1 change: 1 addition & 0 deletions cli/src/services/command_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ pub fn build_default_registry() -> CommandRegistry {
"completion",
crate::services::completion::command::make_completion_command,
);
registry.register("sync", crate::services::sync::command::make_sync_command);
registry
}

Expand Down
9 changes: 9 additions & 0 deletions cli/src/services/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ pub(crate) const ENV_LOG_FORMAT: &str = "SCE_LOG_FORMAT";
pub(crate) const ENV_LOG_FILE: &str = "SCE_LOG_FILE";
pub(crate) const ENV_LOG_FILE_MODE: &str = "SCE_LOG_FILE_MODE";
pub(crate) const ENV_ATTRIBUTION_HOOKS_ENABLED: &str = "SCE_ATTRIBUTION_HOOKS_ENABLED";

// Sync (Turso Cloud) env var keys.
// When SCE_SYNC_URL and SCE_SYNC_TOKEN are both set, TursoDb<M> opens in sync
// (remote-backed) mode. When either is absent, local-only mode is used.
#[allow(dead_code)]
pub(crate) const SYNC_URL_ENV_KEY: &str = "SCE_SYNC_URL";
#[allow(dead_code)]
pub(crate) const SYNC_TOKEN_ENV_KEY: &str = "SCE_SYNC_TOKEN";

const WORKOS_CLIENT_ID_ENV: &str = "WORKOS_CLIENT_ID";
const WORKOS_CLIENT_ID_BAKED_DEFAULT: &str = "client_sce_default";
const WORKOS_CLIENT_ID_KEY: AuthConfigKeySpec = AuthConfigKeySpec {
Expand Down
Loading