go: define model types with YAML struct tags
Swadhin Biswas committed 7 months ago
e26b07b
1 parent e50af6c
commit e26b07b
1 file changed
+101 -0
Showing 1 changed file+101-0
▼GO/cortexa/models.go
+101-0
| @@ -0,0 +1,101 @@ | ||
1 | +// Package cortexa implements contexa — Git-inspired context management | |
2 | +// for LLM agents. COMMIT, BRANCH, MERGE, and CONTEXT over versioned memory. | |
3 | +// | |
4 | +// Paper: "Git Context Controller: Manage the Context of LLM-based Agents like Git" | |
5 | +// arXiv:2508.00031 — Junde Wu et al., 2025 | |
6 | +// | |
7 | +// Author: Swadhin Biswas (@swadhinbiswas) | |
8 | + | |
9 | +package cortexa | |
10 | + | |
11 | +import ( | |
12 | + "fmt" | |
13 | + "strings" | |
14 | +) | |
15 | + | |
16 | +// OTARecord represents a single Observation–Thought–Action cycle logged to log.md. | |
17 | +type OTARecord struct { | |
18 | + Step int `yaml:"step"` | |
19 | + Timestamp string `yaml:"timestamp"` | |
20 | + Observation string `yaml:"observation"` | |
21 | + Thought string `yaml:"thought"` | |
22 | + Action string `yaml:"action"` | |
23 | +} | |
24 | + | |
25 | +// ToMarkdown renders the OTA record in the markdown format used by GCC. | |
26 | +func (r OTARecord) ToMarkdown() string { | |
27 | + return fmt.Sprintf( | |
28 | + "### Step %d — %s\n**Observation:** %s\n\n**Thought:** %s\n\n**Action:** %s\n\n---\n", | |
29 | + r.Step, r.Timestamp, r.Observation, r.Thought, r.Action, | |
30 | + ) | |
31 | +} | |
32 | + | |
33 | +// CommitRecord represents a milestone checkpoint (paper §3.2). | |
34 | +// Fields: Branch Purpose, Previous Progress Summary, This Commit's Contribution. | |
35 | +type CommitRecord struct { | |
36 | + CommitID string `yaml:"commit_id"` | |
37 | + BranchName string `yaml:"branch_name"` | |
38 | + BranchPurpose string `yaml:"branch_purpose"` | |
39 | + PreviousProgressSummary string `yaml:"previous_progress_summary"` | |
40 | + ThisCommitContribution string `yaml:"this_commit_contribution"` | |
41 | + Timestamp string `yaml:"timestamp"` | |
42 | +} | |
43 | + | |
44 | +// ToMarkdown renders the commit record in the markdown format used by GCC. | |
45 | +func (c CommitRecord) ToMarkdown() string { | |
46 | + return fmt.Sprintf( | |
47 | + "## Commit `%s`\n**Timestamp:** %s\n\n**Branch Purpose:** %s\n\n"+ | |
48 | + "**Previous Progress Summary:** %s\n\n"+ | |
49 | + "**This Commit's Contribution:** %s\n\n---\n", | |
50 | + c.CommitID, c.Timestamp, c.BranchPurpose, | |
51 | + c.PreviousProgressSummary, c.ThisCommitContribution, | |
52 | + ) | |
53 | +} | |
54 | + | |
55 | +// BranchMetadata is stored in metadata.yaml per branch (paper §3.1). | |
56 | +// Records architectural intent and motivation. | |
57 | +type BranchMetadata struct { | |
58 | + Name string `yaml:"name"` | |
59 | + Purpose string `yaml:"purpose"` | |
60 | + CreatedFrom string `yaml:"created_from"` | |
61 | + CreatedAt string `yaml:"created_at"` | |
62 | + Status string `yaml:"status"` | |
63 | + MergedInto *string `yaml:"merged_into,omitempty"` | |
64 | + MergedAt *string `yaml:"merged_at,omitempty"` | |
65 | +} | |
66 | + | |
67 | +// ContextResult is the result of the CONTEXT command (paper §3.5). | |
68 | +// K controls the commit retrieval window (paper experiments: K=1). | |
69 | +type ContextResult struct { | |
70 | + BranchName string | |
71 | + K int | |
72 | + Commits []CommitRecord | |
73 | + OTARecords []OTARecord | |
74 | + MainRoadmap string | |
75 | + Metadata *BranchMetadata | |
76 | +} | |
77 | + | |
78 | +// Summary renders a formatted markdown summary of the context. | |
79 | +func (cr ContextResult) Summary() string { | |
80 | + var b strings.Builder | |
81 | + fmt.Fprintf(&b, "# CONTEXT — branch `%s` (K=%d)\n\n", cr.BranchName, cr.K) | |
82 | + b.WriteString("## Global Roadmap\n") | |
83 | + b.WriteString(cr.MainRoadmap) | |
84 | + b.WriteString("\n\n") | |
85 | + fmt.Fprintf(&b, "## Last %d Commit(s)\n", cr.K) | |
86 | + for _, c := range cr.Commits { | |
87 | + b.WriteString(c.ToMarkdown()) | |
88 | + } | |
89 | + if len(cr.OTARecords) > 0 { | |
90 | + recent := cr.OTARecords | |
91 | + if len(recent) > 5 { | |
92 | + recent = recent[len(recent)-5:] | |
93 | + } | |
94 | + fmt.Fprintf(&b, "\n## Recent OTA Steps (showing last %d of %d)\n", | |
95 | + len(recent), len(cr.OTARecords)) | |
96 | + for _, r := range recent { | |
97 | + b.WriteString(r.ToMarkdown()) | |
98 | + } | |
99 | + } | |
100 | + return b.String() | |
101 | +} | |
0 | 102 | |