Skip to content

Commit a92e9ea

Browse files
Antigravity Agentclaude
andcommitted
feat(mu): MU Error Protocol v2 + Learning DB + Sync Checker (#79, #74, #71)
- #79: MU Error Protocol v2 — Severity (P0-P3), ResolutionStatus, root_cause, aggregate reports (tri mu report), 11/11 tests - #74: MU Learning DB — 12 auto-fix rules, tri mu learn/fix, 7/7 tests - #71: Spec ↔ Code Sync Checker — tri sync-check, drift detection, 6/6 tests Closes #79, Closes #74, Closes #71 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent d1843a2 commit a92e9ea

8 files changed

Lines changed: 1475 additions & 18 deletions

File tree

specs/tri/mu_error_protocol.tri

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
# ═══════════════════════════════════════════════════════════════════════════════
2-
# VIBEE Specification — MU Error Protocol
2+
# VIBEE Specification — MU Error Protocol v2
33
# ═══════════════════════════════════════════════════════════════════════════════
44
# φ² + 1/φ² = 3 = TRINITY
55
# Issue #73: Structured failure logging for Agent MU
6+
# Issue #79: v2 — severity, resolution tracking, aggregate reports
67
# ═══════════════════════════════════════════════════════════════════════════════
78

89
name: mu_error_protocol
9-
version: "1.0.0"
10+
version: "2.0.0"
1011
language: zig
1112
module: mu_error_protocol
1213

1314
description: |
14-
MU Error Protocol — structured JSON logging of every pipeline failure.
15+
MU Error Protocol v2 — structured JSON logging of every pipeline failure.
1516
Each error → .trinity/mu/errors/{timestamp}.json.
16-
Queryable by category, with stats summaries.
17+
v2 adds: Severity (P0-P3), ResolutionStatus, root_cause, aggregate reports.
18+
Queryable by category/severity, with stats and matrix reports.
1719

1820
# ═══════════════════════════════════════════════════════════════════════════════
1921
# TYPE SYSTEM
@@ -45,10 +47,36 @@ types:
4547
fix_attempted: Bool
4648
fix_result: String
4749

50+
Severity:
51+
variants:
52+
- p0
53+
- p1
54+
- p2
55+
- p3
56+
57+
ResolutionStatus:
58+
variants:
59+
- open
60+
- fixed
61+
- wontfix
62+
- spec_quality
63+
64+
MuError:
65+
fields:
66+
# ... (v1 fields above)
67+
# v2 fields:
68+
severity: Severity
69+
root_cause: String
70+
resolution_status: ResolutionStatus
71+
fix_commit: String
72+
generator_component: String
73+
4874
ErrorStats:
4975
fields:
5076
total_errors: Int
5177
category_counts: List(Int)
78+
severity_counts: List(Int)
79+
resolution_counts: List(Int)
5280
has_last_error: Bool
5381
error_rate: Float
5482

@@ -121,13 +149,26 @@ behaviors:
121149
- Print results table
122150

123151
run_mu_stats_command:
124-
description: "CLI: tri mu stats"
152+
description: "CLI: tri mu stats — category + severity + resolution breakdowns"
125153
inputs: []
126154
output: Void
127155
steps:
128156
- Call get_stats
129157
- Print category breakdown table
130-
- Print V-formula with error rate
158+
- Print severity breakdown (P0-P3)
159+
- Print resolution breakdown (open/fixed/wontfix/spec_quality)
160+
- Print V-formula with resolution rate
161+
162+
run_mu_report_command:
163+
description: "CLI: tri mu report — aggregate category × severity matrix"
164+
inputs: []
165+
output: Void
166+
steps:
167+
- Call get_stats
168+
- Print category × severity cross-tabulation matrix
169+
- Print resolution summary
170+
- Print P0/P1 action items
171+
- Print V-formula with fix rate
131172

132173
# ═══════════════════════════════════════════════════════════════════════════════
133174
# CONSTRAINTS

specs/tri/mu_learning_db.tri

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
# ═══════════════════════════════════════════════════════════════════════════════
2+
# VIBEE Specification — MU Learning DB
3+
# ═══════════════════════════════════════════════════════════════════════════════
4+
# φ² + 1/φ² = 3 = TRINITY
5+
# Issue #74: Accumulate error patterns → auto-fix rules
6+
# ═══════════════════════════════════════════════════════════════════════════════
7+
8+
name: mu_learning_db
9+
version: "1.0.0"
10+
language: zig
11+
module: mu_learning_db
12+
13+
description: |
14+
MU Learning DB — scans .trinity/mu/errors/*.json, extracts recurring patterns,
15+
builds auto-fix rules. `tri mu learn` extracts patterns, `tri mu fix <spec>`
16+
applies known fixes to generated output.
17+
18+
# ═══════════════════════════════════════════════════════════════════════════════
19+
# TYPE SYSTEM
20+
# ═══════════════════════════════════════════════════════════════════════════════
21+
22+
types:
23+
AutoFixRule:
24+
fields:
25+
id: String
26+
pattern: String
27+
replacement: String
28+
category: String
29+
description: String
30+
apply_count: Int
31+
success_count: Int
32+
33+
LearnResult:
34+
fields:
35+
rules_total: Int
36+
new_rules: Int
37+
updated_rules: Int
38+
errors_scanned: Int
39+
40+
FixResult:
41+
fields:
42+
spec: String
43+
rules_applied: Int
44+
fixes_made: Int
45+
compile_before: Bool
46+
compile_after: Bool
47+
48+
# ═══════════════════════════════════════════════════════════════════════════════
49+
# BEHAVIORS
50+
# ═══════════════════════════════════════════════════════════════════════════════
51+
52+
behaviors:
53+
get_builtin_rules:
54+
description: "Return hardcoded auto-fix rules from known patterns"
55+
inputs: []
56+
output: List(AutoFixRule)
57+
steps:
58+
- Return rules for Int64→i64, List→[]const, Float32→f64, etc.
59+
- Return rules for YAML comment stripping
60+
- Return rules for missing import detection
61+
62+
learn_from_errors:
63+
description: "Scan .trinity/mu/errors/*.json, extract new patterns"
64+
inputs: []
65+
output: LearnResult
66+
steps:
67+
- Read all JSON files in .trinity/mu/errors/
68+
- Group by error_category
69+
- Count frequency of each error_message prefix
70+
- Merge with existing rules in .trinity/mu/learning_db.json
71+
- Save updated DB
72+
73+
apply_fixes:
74+
description: "Apply known fixes to a spec's generated output"
75+
inputs:
76+
- spec_path: String
77+
output: FixResult
78+
steps:
79+
- Load learning DB
80+
- Run vibee gen on spec
81+
- Read generated .zig file
82+
- Apply matching auto-fix rules
83+
- Write fixed file
84+
- Run zig ast-check
85+
- Report result
86+
87+
run_mu_learn_command:
88+
description: "CLI: tri mu learn"
89+
inputs: []
90+
output: Void
91+
steps:
92+
- Call learn_from_errors
93+
- Print summary of new/updated rules
94+
95+
run_mu_fix_command:
96+
description: "CLI: tri mu fix <spec>"
97+
inputs:
98+
- spec_path: String
99+
output: Void
100+
steps:
101+
- Call apply_fixes
102+
- Print before/after compile status
103+
104+
# ═══════════════════════════════════════════════════════════════════════════════
105+
# CONSTRAINTS
106+
# ═══════════════════════════════════════════════════════════════════════════════
107+
108+
constraints:
109+
- Learning DB at .trinity/mu/learning_db.json
110+
- At least 10 built-in auto-fix rules
111+
- Rules are additive — never remove a working rule
112+
- Fix attempts are logged with success/fail
113+
- Never modify .tri specs — only fix generated output
114+
115+
# ═══════════════════════════════════════════════════════════════════════════════
116+
# TESTS
117+
# ═══════════════════════════════════════════════════════════════════════════════
118+
119+
tests:
120+
- name: "builtin rules count"
121+
expected: {min_rules: 10}
122+
123+
- name: "Int64 → i64 fix"
124+
input: {code: "const x: Int64 = 0;"}
125+
expected: {fixed: "const x: i64 = 0;"}
126+
127+
- name: "List(T) → []const T fix"
128+
input: {code: "items: List(u8)"}
129+
expected: {fixed: "items: []const u8"}

specs/tri/sync_checker.tri

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# ═══════════════════════════════════════════════════════════════════════════════
2+
# VIBEE Specification — Spec ↔ Code Sync Checker
3+
# ═══════════════════════════════════════════════════════════════════════════════
4+
# φ² + 1/φ² = 3 = TRINITY
5+
# Issue #71: Detect drift between .tri specs and .zig code
6+
# ═══════════════════════════════════════════════════════════════════════════════
7+
8+
name: sync_checker
9+
version: "1.0.0"
10+
language: zig
11+
module: sync_checker
12+
13+
description: |
14+
Spec ↔ Code Sync Checker — compares .tri spec definitions against .zig code.
15+
Reports types missing in code, functions missing in code, code not in spec.
16+
Exit 0 if synced, exit 1 with drift report.
17+
18+
types:
19+
SyncResult:
20+
fields:
21+
spec_path: String
22+
code_path: String
23+
spec_types: List(String)
24+
code_types: List(String)
25+
spec_behaviors: List(String)
26+
code_functions: List(String)
27+
missing_in_code: List(String)
28+
missing_in_spec: List(String)
29+
matched: List(String)
30+
is_synced: Bool
31+
32+
behaviors:
33+
parse_spec:
34+
description: "Parse .tri spec → extract type names + behavior names"
35+
inputs:
36+
- spec_path: String
37+
output: SyncResult
38+
steps:
39+
- Read .tri YAML file
40+
- Extract type names from types: section
41+
- Extract behavior names from behaviors: section
42+
- Return lists
43+
44+
parse_code:
45+
description: "Parse .zig source → extract pub types + pub fns"
46+
inputs:
47+
- code_path: String
48+
output: SyncResult
49+
steps:
50+
- Read .zig file line by line
51+
- Extract pub const X = struct/enum/union
52+
- Extract pub fn X names
53+
- Return lists
54+
55+
compare:
56+
description: "Compare spec vs code, find drift"
57+
inputs:
58+
- spec: SyncResult
59+
- code: SyncResult
60+
output: SyncResult
61+
steps:
62+
- Find items in spec but not in code (missing_in_code)
63+
- Find items in code but not in spec (missing_in_spec)
64+
- Find matched items
65+
- Set is_synced = (missing_in_code.len == 0)
66+
67+
run_sync_check:
68+
description: "CLI: tri sync-check <spec.tri>"
69+
inputs:
70+
- spec_path: String
71+
output: Void
72+
steps:
73+
- Parse spec
74+
- Find corresponding .zig file
75+
- Parse code
76+
- Compare
77+
- Print drift report
78+
- Exit 0 or 1
79+
80+
constraints:
81+
- Spec types map to pub const/struct/enum in code
82+
- Spec behaviors map to pub fn in code (snake_case)
83+
- Missing in code = drift (spec promises something code doesn't deliver)
84+
- Extra in code = acceptable (code can have helpers)
85+
- Exit code reflects sync status
86+
87+
tests:
88+
- name: "synced spec and code"
89+
expected: {is_synced: true, missing_in_code: []}
90+
91+
- name: "missing type in code"
92+
expected: {is_synced: false, missing_in_code: ["MissingType"]}

src/tri/main.zig

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,16 @@ pub fn main() !void {
520520
} else if (std.mem.eql(u8, subcmd, "verify")) {
521521
const mu_verify = @import("mu_verify_failures.zig");
522522
try mu_verify.runMuVerifyCommand(allocator);
523+
} else if (std.mem.eql(u8, subcmd, "report")) {
524+
const mu_proto = @import("mu_error_protocol.zig");
525+
try mu_proto.runMuReportCommand(allocator);
526+
} else if (std.mem.eql(u8, subcmd, "learn")) {
527+
const mu_learn = @import("mu_learning_db.zig");
528+
try mu_learn.runMuLearnCommand(allocator);
529+
} else if (std.mem.eql(u8, subcmd, "fix")) {
530+
const mu_learn = @import("mu_learning_db.zig");
531+
const fix_args = if (cmd_args.len > 1) cmd_args[1..] else &[_][]const u8{};
532+
try mu_learn.runMuFixCommand(allocator, fix_args);
523533
} else {
524534
std.debug.print(
525535
\\🧠 MU — Memory Unit
@@ -529,6 +539,9 @@ pub fn main() !void {
529539
\\ errors Query logged errors (--category, --limit)
530540
\\ stats Error statistics by category
531541
\\ verify Run MU against known failures (MU-5)
542+
\\ report Aggregate report — category × severity matrix (v2)
543+
\\ learn Scan error logs → build auto-fix pattern DB
544+
\\ fix Apply auto-fix rules: tri mu fix <file> | --all
532545
\\ help Show this help
533546
\\
534547
, .{});
@@ -597,6 +610,12 @@ pub fn main() !void {
597610
const spec_enricher = @import("tri_spec_enricher.zig");
598611
try spec_enricher.runEnrichCommand(allocator, cmd_args);
599612
},
613+
// Spec ↔ Code Sync Checker (Issue #71)
614+
.sync_check => {
615+
const sc = @import("sync_checker.zig");
616+
const exit_code = try sc.runSyncCheckCommand(allocator, cmd_args);
617+
if (exit_code != 0) std.process.exit(exit_code);
618+
},
600619
// GitHub Integration (Protocol v2)
601620
.github => try github_commands.runGithubCommand(allocator, cmd_args, false),
602621
// .monitor => { // TODO: Add monitor to Command enum in tri_utils.zig
@@ -1084,6 +1103,13 @@ fn dispatchCommand(
10841103
std.debug.print("Enrich error: {}\n", .{err});
10851104
};
10861105
},
1106+
// Spec ↔ Code Sync Checker (Issue #71)
1107+
.sync_check => {
1108+
const sc = @import("sync_checker.zig");
1109+
_ = sc.runSyncCheckCommand(allocator, cmd_args) catch |err| {
1110+
std.debug.print("Sync check error: {}\n", .{err});
1111+
};
1112+
},
10871113
// GitHub Integration (Protocol v2)
10881114
.github => github_commands.runGithubCommand(allocator, cmd_args, state.dry_run) catch |err| {
10891115
std.debug.print("GitHub error: {}\n", .{err});

0 commit comments

Comments
 (0)