Skip to content
Merged
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
44 changes: 22 additions & 22 deletions .claude/settings.json

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

3 changes: 3 additions & 0 deletions .sce/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
"pi"
]
},
"agent_trace": {
"auto_sync": true
},
"log_dir": "context/tmp",
"log_level": "error",
"policies": {
Expand Down
9 changes: 9 additions & 0 deletions cli/src/services/config/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ pub(super) fn format_show_output(runtime: &RuntimeConfig, report_format: ReportF
&runtime.agent_trace_repository_remote.value,
runtime.agent_trace_repository_remote.source,
),
format_resolved_value_text(
"agent_trace.auto_sync",
&runtime.agent_trace_auto_sync.value.to_string(),
runtime.agent_trace_auto_sync.source,
),
format_bash_policies_text(&runtime.bash_policies),
format_database_retry_text(&runtime.database_retry),
format_validation_warnings_text(&warnings),
Expand Down Expand Up @@ -89,6 +94,10 @@ pub(super) fn format_show_output(runtime: &RuntimeConfig, report_format: ReportF
runtime.agent_trace_repository_remote.value.as_str(),
runtime.agent_trace_repository_remote.source,
),
"auto_sync": format_resolved_value_json(
runtime.agent_trace_auto_sync.value,
runtime.agent_trace_auto_sync.source,
),
},
"policies": {
"bash": format_bash_policies_json(&runtime.bash_policies),
Expand Down
67 changes: 67 additions & 0 deletions cli/src/services/config/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ pub(super) struct RuntimeConfig {
pub(super) control_plane_base_url: ResolvedOptionalValue<String>,
pub(super) agent_trace_repository_id: ResolvedOptionalValue<String>,
pub(super) agent_trace_repository_remote: ResolvedValue<String>,
pub(super) agent_trace_auto_sync: ResolvedValue<bool>,
pub(super) bash_policies: ResolvedOptionalValue<BashPolicyConfig>,
pub(super) database_retry: ResolvedOptionalValue<DatabaseRetryConfig>,
pub(super) validation_errors: Vec<String>,
Expand Down Expand Up @@ -268,6 +269,7 @@ where

Ok(ResolvedHookRuntimeConfig {
attribution_hooks_enabled: runtime.attribution_hooks_enabled.value,
agent_trace_auto_sync: runtime.agent_trace_auto_sync.value,
})
}

Expand Down Expand Up @@ -318,6 +320,7 @@ where
control_plane_base_url: None,
agent_trace_repository_id: None,
agent_trace_repository_remote: None,
agent_trace_auto_sync: None,
bash_policy_presets: None,
bash_policy_custom: None,
database_retry: None,
Expand Down Expand Up @@ -364,6 +367,9 @@ where
if let Some(agent_trace_repository_remote) = layer.agent_trace_repository_remote {
file_config.agent_trace_repository_remote = Some(agent_trace_repository_remote);
}
if let Some(agent_trace_auto_sync) = layer.agent_trace_auto_sync {
file_config.agent_trace_auto_sync = Some(agent_trace_auto_sync);
}
if let Some(bash_policy_presets) = layer.bash_policy_presets {
file_config.bash_policy_presets = Some(bash_policy_presets);
}
Expand Down Expand Up @@ -522,6 +528,17 @@ where
};
}

let resolved_agent_trace_auto_sync = match file_config.agent_trace_auto_sync {
Some(value) => ResolvedValue {
value: value.value,
source: ValueSource::ConfigFile(value.source),
},
None => ResolvedValue {
value: true,
source: ValueSource::Default,
},
};

let resolved_bash_policies = resolve_bash_policy_config(
file_config.bash_policy_presets.as_ref(),
file_config.bash_policy_custom.as_ref(),
Expand All @@ -543,6 +560,7 @@ where
control_plane_base_url: resolved_control_plane_base_url,
agent_trace_repository_id: resolved_agent_trace_repository_id,
agent_trace_repository_remote: resolved_agent_trace_repository_remote,
agent_trace_auto_sync: resolved_agent_trace_auto_sync,
bash_policies: resolved_bash_policies,
database_retry: resolved_database_retry,
validation_errors,
Expand Down Expand Up @@ -765,6 +783,7 @@ mod tests {

Ok(ResolvedHookRuntimeConfig {
attribution_hooks_enabled: runtime.attribution_hooks_enabled.value,
agent_trace_auto_sync: runtime.agent_trace_auto_sync.value,
})
}

Expand Down Expand Up @@ -805,6 +824,54 @@ mod tests {
assert_eq!(runtime.agent_trace_repository_id.source, None);
}

#[test]
fn agent_trace_auto_sync_defaults_to_true() {
let runtime = resolve_runtime_with_config(None).unwrap();

assert!(runtime.agent_trace_auto_sync.value);
assert_eq!(runtime.agent_trace_auto_sync.source, ValueSource::Default);
}

#[test]
fn agent_trace_auto_sync_resolves_from_config_file() {
let runtime =
resolve_runtime_with_config(Some(r#"{"agent_trace":{"auto_sync":true}}"#)).unwrap();

assert!(runtime.agent_trace_auto_sync.value);
assert_eq!(
runtime.agent_trace_auto_sync.source,
ValueSource::ConfigFile(ConfigPathSource::Flag)
);
}

#[test]
fn agent_trace_auto_sync_uses_local_config_over_global_config() {
let runtime = resolve_runtime_config_with(
&empty_request(),
Path::new("/tmp/repo"),
|_| None,
|path| {
if path == Path::new("/tmp/global-sce-config.json") {
Ok(r#"{"agent_trace":{"auto_sync":false}}"#.to_string())
} else {
Ok(r#"{"agent_trace":{"auto_sync":true}}"#.to_string())
}
},
|path| {
path == Path::new("/tmp/global-sce-config.json")
|| path == Path::new("/tmp/repo/.sce/config.json")
},
|| Ok(PathBuf::from("/tmp/global-sce-config.json")),
)
.unwrap();

assert!(runtime.agent_trace_auto_sync.value);
assert_eq!(
runtime.agent_trace_auto_sync.source,
ValueSource::ConfigFile(ConfigPathSource::DefaultDiscoveredLocal)
);
}

#[test]
fn agent_trace_repository_remote_defaults_to_origin() {
let runtime = resolve_runtime_with_config(None).unwrap();
Expand Down
46 changes: 41 additions & 5 deletions cli/src/services/config/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ pub(crate) struct ParsedFileConfigDocument {
pub(crate) struct ParsedAgentTraceConfigDocument {
pub(crate) repository_id: Option<String>,
pub(crate) repository_remote: Option<String>,
pub(crate) auto_sync: Option<bool>,
}

#[derive(Clone, Debug, Deserialize, Eq, PartialEq)]
Expand Down Expand Up @@ -165,6 +166,7 @@ pub(crate) struct FileConfig {
pub(crate) control_plane_base_url: Option<FileConfigValue<String>>,
pub(crate) agent_trace_repository_id: Option<FileConfigValue<String>>,
pub(crate) agent_trace_repository_remote: Option<FileConfigValue<String>>,
pub(crate) agent_trace_auto_sync: Option<FileConfigValue<bool>>,
pub(crate) bash_policy_presets: Option<FileConfigValue<Vec<String>>>,
pub(crate) bash_policy_custom: Option<FileConfigValue<Vec<CustomBashPolicyEntry>>>,
pub(crate) database_retry: Option<FileConfigValue<DatabaseRetryConfig>>,
Expand Down Expand Up @@ -313,7 +315,7 @@ pub(crate) fn parse_file_config(
let control_plane_base_url = typed
.control_plane_base_url
.map(|value| FileConfigValue { value, source });
let (agent_trace_repository_id, agent_trace_repository_remote) =
let (agent_trace_repository_id, agent_trace_repository_remote, agent_trace_auto_sync) =
map_agent_trace_config(typed.agent_trace.as_ref(), object, path, source)?;
let (attribution_hooks_enabled, bash_policy_presets, bash_policy_custom, database_retry) =
map_policies_config(typed.policies.as_ref(), object, path, source)?;
Expand All @@ -330,6 +332,7 @@ pub(crate) fn parse_file_config(
control_plane_base_url,
agent_trace_repository_id,
agent_trace_repository_remote,
agent_trace_auto_sync,
bash_policy_presets,
bash_policy_custom,
database_retry,
Expand Down Expand Up @@ -610,6 +613,7 @@ pub(crate) fn map_database_retry_config(
pub(crate) type ParsedAgentTraceConfig = (
Option<FileConfigValue<String>>,
Option<FileConfigValue<String>>,
Option<FileConfigValue<bool>>,
);

fn map_agent_trace_config(
Expand All @@ -619,7 +623,7 @@ fn map_agent_trace_config(
source: ConfigPathSource,
) -> Result<ParsedAgentTraceConfig> {
let Some(agent_trace_value) = object.get("agent_trace") else {
return Ok((None, None));
return Ok((None, None, None));
};

let agent_trace_object = agent_trace_value.as_object().with_context(|| {
Expand All @@ -633,8 +637,8 @@ fn map_agent_trace_config(
agent_trace_object,
path,
Some("agent_trace"),
&["repository_id", "repository_remote"],
"repository_id, repository_remote",
&["repository_id", "repository_remote", "auto_sync"],
"repository_id, repository_remote, auto_sync",
)?;

let repository_id = typed
Expand All @@ -643,8 +647,11 @@ fn map_agent_trace_config(
let repository_remote = typed
.and_then(|config| config.repository_remote.clone())
.map(|value| FileConfigValue { value, source });
let auto_sync = typed
.and_then(|config| config.auto_sync)
.map(|value| FileConfigValue { value, source });

Ok((repository_id, repository_remote))
Ok((repository_id, repository_remote, auto_sync))
}

fn map_integrations_config(
Expand Down Expand Up @@ -745,6 +752,13 @@ mod agent_trace_config_tests {
.map(|value| value.value.as_str()),
Some("upstream")
);
assert_eq!(
config
.agent_trace_auto_sync
.as_ref()
.map(|value| value.value),
None
);
}

#[test]
Expand Down Expand Up @@ -790,4 +804,26 @@ mod agent_trace_config_tests {

assert!(error.contains("failed schema validation"), "{error}");
}

#[test]
fn parses_agent_trace_auto_sync() {
let config = parse(r#"{"agent_trace":{"auto_sync":true}}"#).unwrap();

assert_eq!(
config
.agent_trace_auto_sync
.as_ref()
.map(|value| value.value),
Some(true)
);
}

#[test]
fn rejects_non_boolean_agent_trace_auto_sync() {
let error = parse(r#"{"agent_trace":{"auto_sync":"true"}}"#)
.unwrap_err()
.to_string();

assert!(error.contains("failed schema validation"), "{error}");
}
}
1 change: 1 addition & 0 deletions cli/src/services/config/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ pub(crate) struct ResolvedObservabilityRuntimeConfig {
#[derive(Clone, Debug, Eq, PartialEq)]
pub(crate) struct ResolvedHookRuntimeConfig {
pub(crate) attribution_hooks_enabled: bool,
pub(crate) agent_trace_auto_sync: bool,
}

#[derive(Clone, Debug, Eq, PartialEq)]
Expand Down
Loading
Loading