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
24 changes: 24 additions & 0 deletions cli/src/services/agent_trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,20 @@ use super::patch::{
};

pub const AGENT_TRACE_VERSION: &str = "0.1.0";
pub const SCE_METADATA_VERSION: &str = env!("CARGO_PKG_VERSION");

fn default_agent_trace_version() -> String {
AGENT_TRACE_VERSION.to_owned()
}

fn default_agent_trace_metadata() -> AgentTraceMetadata {
AgentTraceMetadata {
sce: AgentTraceSceMetadata {
version: SCE_METADATA_VERSION.to_owned(),
},
}
}

fn generate_agent_trace_id(commit_time: DateTime<FixedOffset>) -> Result<String> {
let seconds = u64::try_from(commit_time.timestamp()).with_context(|| {
format!(
Expand Down Expand Up @@ -78,6 +87,17 @@ pub struct AgentTraceTool {
#[serde(skip_serializing_if = "Option::is_none")]
pub version: Option<String>,
}
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[serde(rename_all = "snake_case")]
pub struct AgentTraceMetadata {
pub sce: AgentTraceSceMetadata,
}

#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[serde(rename_all = "snake_case")]
pub struct AgentTraceSceMetadata {
pub version: String,
}

fn parse_commit_timestamp(commit_timestamp: &str) -> Result<DateTime<FixedOffset>> {
DateTime::parse_from_rfc3339(commit_timestamp).with_context(|| {
Expand Down Expand Up @@ -243,6 +263,9 @@ pub struct AgentTrace {
/// Optional tool metadata sourced from caller-provided metadata input.
#[serde(skip_serializing_if = "Option::is_none")]
pub tool: Option<AgentTraceTool>,
/// Implementation-specific metadata for SCE-generated traces.
#[serde(default = "default_agent_trace_metadata")]
pub metadata: AgentTraceMetadata,
/// File-level trace entries, one per file present in `post_commit_patch`.
pub files: Vec<TraceFile>,
}
Expand Down Expand Up @@ -442,6 +465,7 @@ pub fn build_agent_trace(
revision: metadata.commit_revision.to_owned(),
}),
tool,
metadata: default_agent_trace_metadata(),
files,
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
"type": "git",
"revision": "a0b1c2d3e4f5a6b7c8d9e0f11223344556677889"
},
"metadata": {
"sce": {
"version": "0.2.0"
}
},
"files": [
{
"path": "hunks/fib.ts",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,10 @@
"type": "git",
"revision": "a0b1c2d3e4f5a6b7c8d9e0f11223344556677889"
},
"metadata": {
"sce": {
"version": "0.2.0"
}
},
"files": []
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
"type": "git",
"revision": "a0b1c2d3e4f5a6b7c8d9e0f11223344556677889"
},
"metadata": {
"sce": {
"version": "0.2.0"
}
},
"files": [
{
"path": "hunks/hello.ts",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
"type": "git",
"revision": "a0b1c2d3e4f5a6b7c8d9e0f11223344556677889"
},
"metadata": {
"sce": {
"version": "0.2.0"
}
},
"files": [
{
"path": ".version",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
"type": "git",
"revision": "a0b1c2d3e4f5a6b7c8d9e0f11223344556677889"
},
"metadata": {
"sce": {
"version": "0.2.0"
}
},
"files": [
{
"path": "poem.md",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
"type": "git",
"revision": "a0b1c2d3e4f5a6b7c8d9e0f11223344556677889"
},
"metadata": {
"sce": {
"version": "0.2.0"
}
},
"files": [
{
"path": "poem.md",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
"type": "git",
"revision": "a0b1c2d3e4f5a6b7c8d9e0f11223344556677889"
},
"metadata": {
"sce": {
"version": "0.2.0"
}
},
"files": [
{
"path": "animals.txt",
Expand Down
7 changes: 7 additions & 0 deletions cli/src/services/agent_trace/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ fn assert_builds_expected_agent_trace(scenario: AgentTraceScenario) {
);
let actual_json = serde_json::to_value(&actual).expect("agent trace should serialize");
validate_agent_trace_value(&actual_json).expect("actual json should validate against schema");
let metadata_version = actual_json["metadata"]["sce"]["version"]
.as_str()
.expect("metadata.sce.version should serialize as a string");
assert!(
!metadata_version.is_empty(),
"metadata.sce.version should not be empty"
);
assert_eq!(actual_json["vcs"], golden["vcs"]);
assert_eq!(actual_json["files"], golden["files"]);
}
Expand Down
4 changes: 2 additions & 2 deletions context/context-map.md

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

1 change: 1 addition & 0 deletions context/glossary.md

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

2 changes: 1 addition & 1 deletion context/overview.md

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

Loading