1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
//! Object model definitions for Git blobs, trees, commits, tags, and
//! AI workflow objects.
//!
//! This module is the storage-layer contract for `git-internal`.
//! Git-native objects (`Blob`, `Tree`, `Commit`, `Tag`) model repository
//! content, while the AI objects model immutable workflow history that
//! Libra orchestrates on top.
//!
//! # How Libra should use this module
//!
//! Libra should treat every AI object here as an immutable record:
//!
//! - construct the object in memory,
//! - populate optional fields before persistence,
//! - persist it once,
//! - derive current state later from object history plus Libra
//! projections.
//!
//! Libra should not store scheduler state, selected heads, active UI
//! focus, or query caches in these objects. Those belong to Libra's own
//! runtime and index layer.
//!
//! AI workflow objects are split into three layers:
//!
//! - **Snapshot objects** in `git-internal` answer "what was the stored
//! fact at this revision?"
//! - **Event objects** in `git-internal` answer "what happened later?"
//! - **Libra projections** answer "what is the system's current view?"
//!
//! # Relationship Design Standard
//!
//! Relationship fields follow a simple storage rule:
//!
//! - Store the canonical ownership edge on the child object when the
//! relationship is a historical fact.
//! - Low-frequency, strongly aggregated relationships that benefit
//! from fast parent-to-children traversal may additionally keep a
//! reverse convenience link.
//! - High-frequency, high-cardinality, event-stream relationships
//! should remain single-directional to avoid turning parent objects
//! into rewrite hotspots.
//!
//! # Three-Layer Design
//!
//! ```text
//! +------------------------------------------------------------------+
//! | Libra projection / runtime |
//! |------------------------------------------------------------------|
//! | thread heads / selected_plan_id / active_run / scheduler state |
//! | live context window / UI focus / query indexes |
//! +--------------------------------+---------------------------------+
//! |
//! v
//! +------------------------------------------------------------------+
//! | git-internal event objects |
//! |------------------------------------------------------------------|
//! | IntentEvent / TaskEvent / RunEvent / PlanStepEvent / RunUsage |
//! | ToolInvocation / Evidence / Decision / ContextFrame |
//! +--------------------------------+---------------------------------+
//! |
//! v
//! +------------------------------------------------------------------+
//! | git-internal snapshot objects |
//! |------------------------------------------------------------------|
//! | Intent / Plan / Task / Run / PatchSet / ContextSnapshot |
//! | Provenance |
//! +------------------------------------------------------------------+
//! ```
//!
//! # Main Object Relationships
//!
//! ```text
//! Snapshot layer
//! ==============
//!
//! Intent --parents----------------------------> Intent
//! Intent --analysis_context_frames-----------> ContextFrame
//! Plan --intent-----------------------------> Intent
//! Plan --context_frames---------------------> ContextFrame
//! Plan --parents----------------------------> Plan
//! Task --intent?----------------------------> Intent
//! Task --parent?----------------------------> Task
//! Task --origin_step_id?-------------------> PlanStep.step_id
//! Run --task-------------------------------> Task
//! Run --plan?------------------------------> Plan
//! Run --snapshot?--------------------------> ContextSnapshot
//! PatchSet --run----------------------------> Run
//! Provenance --run_id-------------------------> Run
//!
//! Event layer
//! ===========
//!
//! IntentEvent --intent_id-------------------> Intent
//! IntentEvent --next_intent_id?-------------> Intent
//! ContextFrame --intent_id?------------------> Intent
//! TaskEvent --task_id---------------------> Task
//! RunEvent --run_id----------------------> Run
//! RunUsage --run_id----------------------> Run
//! PlanStepEvent --plan_id + step_id + run_id-> Plan / Run / PlanStep
//! ToolInvocation--run_id----------------------> Run
//! Evidence --run_id / patchset_id?-------> Run / PatchSet
//! Decision --run_id / chosen_patchset_id?> Run / PatchSet
//! ContextFrame --run_id? / plan_id? / step_id?> Run / Plan / PlanStep
//! ```
//!
//! # Libra read / write pattern
//!
//! A typical Libra call flow looks like this:
//!
//! 1. write snapshot objects when a new immutable revision is defined
//! (`Intent`, `Plan`, `Task`, `Run`, `PatchSet`, `ContextSnapshot`,
//! `Provenance`);
//! 2. append event objects as execution progresses
//! (`IntentEvent`, `TaskEvent`, `RunEvent`, `PlanStepEvent`,
//! `RunUsage`, `ToolInvocation`, `Evidence`, `Decision`,
//! `ContextFrame`);
//! 3. rebuild current state in Libra from those immutable objects plus
//! its own `Thread`, `Scheduler`, `UI`, and `Query Index`
//! projections.
//!
//! ## Object Relationship Summary
//!
//! | From | Field | To | Cardinality |
//! |------|-------|----|-------------|
//! | Intent | `parents` | Intent | 0..N |
//! | Intent | `analysis_context_frames` | ContextFrame | 0..N |
//! | Plan | `intent` | Intent | 1 canonical |
//! | Plan | `parents` | Plan | 0..N |
//! | Plan | `context_frames` | ContextFrame | 0..N |
//! | Task | `parent` | Task | 0..1 |
//! | Task | `intent` | Intent | 0..1 |
//! | Task | `origin_step_id` | PlanStep.step_id | 0..1 |
//! | Task | `dependencies` | Task | 0..N |
//! | Run | `task` | Task | 1 |
//! | Run | `plan` | Plan | 0..1 |
//! | Run | `snapshot` | ContextSnapshot | 0..1 |
//! | PatchSet | `run` | Run | 1 |
//! | Provenance | `run_id` | Run | 1 |
//! | IntentEvent | `intent_id` | Intent | 1 |
//! | IntentEvent | `next_intent_id` | Intent | 0..1 recommended follow-up |
//! | ContextFrame | `intent_id` | Intent | 0..1 |
//! | TaskEvent | `task_id` | Task | 1 |
//! | RunEvent | `run_id` | Run | 1 |
//! | RunUsage | `run_id` | Run | 1 |
//! | PlanStepEvent | `plan_id` | Plan | 1 |
//! | PlanStepEvent | `step_id` | PlanStep.step_id | 1 |
//! | PlanStepEvent | `run_id` | Run | 1 |
//! | ToolInvocation | `run_id` | Run | 1 |
//! | Evidence | `run_id` | Run | 1 |
//! | Evidence | `patchset_id` | PatchSet | 0..1 |
//! | Decision | `run_id` | Run | 1 |
//! | Decision | `chosen_patchset_id` | PatchSet | 0..1 |
//! | ContextFrame | `run_id` | Run | 0..1 |
//! | ContextFrame | `plan_id` | Plan | 0..1 |
//! | ContextFrame | `step_id` | PlanStep.step_id | 0..1 |
//!
use ;
use crate::;
/// **The Object Trait**
/// Defines the common interface for all Git object types, including blobs, trees, commits, and tags.