rust: define data model structs and YAML serialization

Swadhin Biswas committed 7 months ago
a97d2bd
1 parent 076fb5f
commit a97d2bd
1 file changed
+103 -0
Showing 1 changed file+103-0
▼RUST/src/models.rs
+103-0
1
+//! Data models for GCC (arXiv:2508.00031v2).
2
+
3
+use serde::{Deserialize, Serialize};
4
+
5
+/// A single Observation–Thought–Action step logged to `log.md`.
6
+/// The paper continuously logs OTA cycles as the agent executes.
7
+#[derive(Debug, Clone, Serialize, Deserialize)]
8
+pub struct OTARecord {
9
+ pub step: usize,
10
+ pub timestamp: String,
11
+ pub observation: String,
12
+ pub thought: String,
13
+ pub action: String,
14
+}
15
+
16
+impl OTARecord {
17
+ pub fn to_markdown(&self) -> String {
18
+ format!(
19
+ "### Step {} — {}\n**Observation:** {}\n\n**Thought:** {}\n\n**Action:** {}\n\n---\n",
20
+ self.step, self.timestamp, self.observation, self.thought, self.action
21
+ )
22
+ }
23
+}
24
+
25
+/// A commit checkpoint as described in paper §3.2.
26
+/// Fields: Branch Purpose, Previous Progress Summary, This Commit's Contribution.
27
+#[derive(Debug, Clone, Serialize, Deserialize)]
28
+pub struct CommitRecord {
29
+ pub commit_id: String,
30
+ pub branch_name: String,
31
+ pub branch_purpose: String,
32
+ pub previous_progress_summary: String,
33
+ pub this_commit_contribution: String,
34
+ pub timestamp: String,
35
+}
36
+
37
+impl CommitRecord {
38
+ pub fn to_markdown(&self) -> String {
39
+ format!(
40
+ "## Commit `{}`\n**Timestamp:** {}\n\n**Branch Purpose:** {}\n\n\
41
+ **Previous Progress Summary:** {}\n\n\
42
+ **This Commit's Contribution:** {}\n\n---\n",
43
+ self.commit_id,
44
+ self.timestamp,
45
+ self.branch_purpose,
46
+ self.previous_progress_summary,
47
+ self.this_commit_contribution,
48
+ )
49
+ }
50
+}
51
+
52
+/// Branch metadata stored in `metadata.yaml` (paper §3.1).
53
+/// Records the intent and motivation of each branch.
54
+#[derive(Debug, Clone, Serialize, Deserialize)]
55
+pub struct BranchMetadata {
56
+ pub name: String,
57
+ pub purpose: String,
58
+ pub created_from: String,
59
+ pub created_at: String,
60
+ pub status: String, // "active" | "merged" | "abandoned"
61
+ pub merged_into: Option<String>,
62
+ pub merged_at: Option<String>,
63
+}
64
+
65
+/// Result of the CONTEXT command (paper §3.5).
66
+/// The paper fixes K=1 in experiments (most recent commit record revealed).
67
+#[derive(Debug, Clone)]
68
+pub struct ContextResult {
69
+ pub branch_name: String,
70
+ pub k: usize,
71
+ pub commits: Vec<CommitRecord>,
72
+ pub ota_records: Vec<OTARecord>,
73
+ pub main_roadmap: String,
74
+ pub metadata: Option<BranchMetadata>,
75
+}
76
+
77
+impl ContextResult {
78
+ pub fn summary(&self) -> String {
79
+ let mut out = format!(
80
+ "# CONTEXT — branch `{}` (K={})\n\n",
81
+ self.branch_name, self.k
82
+ );
83
+ out.push_str("## Global Roadmap\n");
84
+ out.push_str(&self.main_roadmap);
85
+ out.push_str("\n\n");
86
+ out.push_str(&format!("## Last {} Commit(s)\n", self.k));
87
+ for c in &self.commits {
88
+ out.push_str(&c.to_markdown());
89
+ }
90
+ if !self.ota_records.is_empty() {
91
+ let recent = self.ota_records.iter().rev().take(5).collect::<Vec<_>>();
92
+ out.push_str(&format!(
93
+ "\n## Recent OTA Steps (showing last {} of {})\n",
94
+ recent.len(),
95
+ self.ota_records.len()
96
+ ));
97
+ for r in recent.into_iter().rev() {
98
+ out.push_str(&r.to_markdown());
99
+ }
100
+ }
101
+ out
102
+ }
103
+}
0
104