fix(operations): per-project git sync + completion receipts in brief (S2, S3)
Brief.Git was a single GitSync read from ORCHESTRA_DATA (never a git checkout), and completions were counted but discarded their report_ref/ receipt. Brief.Git is now keyed by project ID and built from each project's real repo; GitSync gained Ahead/Behind vs upstream; Brief now carries Receipts pulled from each TaskCompleted payload. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01W1rkJ2hBMybnJctPbcy4tT
This commit is contained in:
@@ -13,19 +13,37 @@ import (
|
||||
)
|
||||
|
||||
type Brief struct {
|
||||
From time.Time `json:"from"`
|
||||
To time.Time `json:"to"`
|
||||
Completed int `json:"completed"`
|
||||
Failed int `json:"failed"`
|
||||
Blocked int `json:"blocked"`
|
||||
NeedsAttention []domain.Event `json:"needs_attention"`
|
||||
Quota map[string]float64 `json:"quota_consumed"`
|
||||
Git GitSync `json:"git_sync"`
|
||||
From time.Time `json:"from"`
|
||||
To time.Time `json:"to"`
|
||||
Completed int `json:"completed"`
|
||||
Failed int `json:"failed"`
|
||||
Blocked int `json:"blocked"`
|
||||
NeedsAttention []domain.Event `json:"needs_attention"`
|
||||
Quota map[string]float64 `json:"quota_consumed"`
|
||||
Receipts []CompletionReceipt `json:"receipts"`
|
||||
// Git is keyed by project ID (spec §7.4: "what pushed, what's on which
|
||||
// branch, what workpc still needs to pull" is a per-project question,
|
||||
// not a single global answer read off the event-log directory).
|
||||
Git map[string]GitSync `json:"git_sync"`
|
||||
}
|
||||
type GitSync struct {
|
||||
Branch string `json:"branch"`
|
||||
Head string `json:"head"`
|
||||
Status string `json:"status"`
|
||||
// Ahead/Behind are counts vs the branch's upstream, when one is
|
||||
// configured — "what pushed" and "what workpc still needs to pull"
|
||||
// (§7.4). Zero when there is no upstream (e.g. detached HEAD).
|
||||
Ahead int `json:"ahead,omitempty"`
|
||||
Behind int `json:"behind,omitempty"`
|
||||
}
|
||||
|
||||
// CompletionReceipt names the proof a completion carries (§7.4: "what
|
||||
// pushed... and the receipts for every completion"), pulled out of
|
||||
// TaskCompleted's payload rather than just counted.
|
||||
type CompletionReceipt struct {
|
||||
TaskID string `json:"task_id"`
|
||||
ReportRef string `json:"report_ref"`
|
||||
Receipt map[string]any `json:"receipt"`
|
||||
}
|
||||
|
||||
type StandupItem struct {
|
||||
@@ -70,7 +88,7 @@ func StandupItems(tasks []domain.Task) []StandupItem {
|
||||
}
|
||||
|
||||
// BuildBrief folds only events in [from,to]. It is deliberately read-only.
|
||||
func BuildBrief(events []domain.Event, from, to time.Time, git GitSync) Brief {
|
||||
func BuildBrief(events []domain.Event, from, to time.Time, git map[string]GitSync) Brief {
|
||||
b := Brief{From: from, To: to, Quota: map[string]float64{}, Git: git}
|
||||
for _, e := range events {
|
||||
if e.At.Before(from) || e.At.After(to) {
|
||||
@@ -81,6 +99,9 @@ func BuildBrief(events []domain.Event, from, to time.Time, git GitSync) Brief {
|
||||
switch e.Type {
|
||||
case "TaskCompleted":
|
||||
b.Completed++
|
||||
receipt, _ := p["receipt"].(map[string]any)
|
||||
reportRef, _ := p["report_ref"].(string)
|
||||
b.Receipts = append(b.Receipts, CompletionReceipt{TaskID: e.TaskID, ReportRef: reportRef, Receipt: receipt})
|
||||
case "TaskFailed":
|
||||
b.Failed++
|
||||
b.NeedsAttention = append(b.NeedsAttention, e)
|
||||
@@ -178,5 +199,11 @@ func GitState(dir string) GitSync {
|
||||
if g.Head == "" {
|
||||
g.Status = fmt.Sprintf("git unavailable (%s)", dir)
|
||||
}
|
||||
if counts := run("rev-list", "--left-right", "--count", "@{u}...HEAD"); counts != "" {
|
||||
var behind, ahead int
|
||||
if n, _ := fmt.Sscanf(counts, "%d\t%d", &behind, &ahead); n == 2 {
|
||||
g.Behind, g.Ahead = behind, ahead
|
||||
}
|
||||
}
|
||||
return g
|
||||
}
|
||||
|
||||
@@ -12,11 +12,18 @@ import (
|
||||
func TestBuildBrief(t *testing.T) {
|
||||
now := time.Now()
|
||||
p, _ := json.Marshal(map[string]any{"harness_id": "cc", "consumed": 12})
|
||||
es := []domain.Event{{Type: "TaskCompleted", At: now}, {Type: "TaskFailed", At: now}, {Type: "ApprovalRequested", At: now}, {Type: "QuotaReported", At: now, Payload: p}}
|
||||
b := BuildBrief(es, now.Add(-time.Minute), now.Add(time.Minute), GitSync{Status: "clean"})
|
||||
completed, _ := json.Marshal(map[string]any{"report_ref": "sha256:abc", "receipt": map[string]any{"numerator": 42.0}})
|
||||
es := []domain.Event{{TaskID: "t1", Type: "TaskCompleted", At: now, Payload: completed}, {Type: "TaskFailed", At: now}, {Type: "ApprovalRequested", At: now}, {Type: "QuotaReported", At: now, Payload: p}}
|
||||
b := BuildBrief(es, now.Add(-time.Minute), now.Add(time.Minute), map[string]GitSync{"proj": {Status: "clean"}})
|
||||
if b.Completed != 1 || b.Failed != 1 || len(b.NeedsAttention) != 2 || b.Quota["cc"] != 12 {
|
||||
t.Fatalf("unexpected brief: %+v", b)
|
||||
}
|
||||
if len(b.Receipts) != 1 || b.Receipts[0].TaskID != "t1" || b.Receipts[0].ReportRef != "sha256:abc" || b.Receipts[0].Receipt["numerator"] != 42.0 {
|
||||
t.Fatalf("unexpected receipts: %+v", b.Receipts)
|
||||
}
|
||||
if b.Git["proj"].Status != "clean" {
|
||||
t.Fatalf("unexpected git: %+v", b.Git)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAggregateQuotaSumsRotationsAndWindows(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user