-
Notifications
You must be signed in to change notification settings - Fork 0
feat(cli): show cached local repository state in status #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
a876ced
a261a46
e4cca8a
94c863c
83860cd
8b0253b
a622fd5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,154 @@ | ||
| # Cached Repository State Implementation Plan | ||
|
|
||
| > **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking. | ||
|
|
||
| **Goal:** Make `no-mistakes status` always render cached, local-only repository branch evidence without adding a pipeline or network operation. | ||
|
|
||
| **Architecture:** `internal/cli/status.go` already obtains `branchsync.State` through `InspectCached`. Add one small presenter for that state and render it unconditionally after repository discovery. Include the rendered cached summary in the existing status telemetry fingerprint so sampled status events correspond to visible state. | ||
|
|
||
| **Tech Stack:** Go, Cobra, existing `branchsync.Service`, existing CLI test helpers. | ||
|
|
||
| --- | ||
|
|
||
| ## File structure | ||
|
|
||
| - Modify: `internal/cli/status.go` - render cached evidence and fingerprint it. | ||
| - Create: `internal/cli/status_test.go` - table tests for the pure cached-state presenter and fingerprint coverage. | ||
|
|
||
| ### Task 1: Write the failing presenter test | ||
|
|
||
| **Files:** | ||
|
|
||
| - Create: `internal/cli/status_test.go` | ||
|
|
||
| - [ ] **Step 1: Define clean, dirty, and unavailable cases** | ||
|
|
||
| ```go | ||
| func TestCachedBranchSummary(t *testing.T) { | ||
| tests := []struct { name string; state branchsync.State; want string }{ | ||
| {"clean branch", branchsync.State{State: branchsync.StateSynchronized, Local: branchsync.LocalState{Branch: "feature/state", Head: "0123456789abcdef", Clean: true}}, "cached: feature/state 01234567 (clean; already synchronized with the pipeline-pushed head)"}, | ||
| {"dirty branch", branchsync.State{State: branchsync.StateDirty, Local: branchsync.LocalState{Branch: "feature/state", Head: "fedcba9876543210", Reason: "uncommitted changes"}}, "cached: feature/state fedcba98 (dirty: uncommitted changes; dirty)"}, | ||
| {"unavailable", branchsync.State{State: branchsync.StateAmbiguousContext}, "cached: unavailable (ambiguous context)"}, | ||
| } | ||
| for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { | ||
| if got := cachedBranchSummary(tt.state); got != tt.want { t.Fatalf("cachedBranchSummary() = %q, want %q", got, tt.want) } | ||
| }) } | ||
| } | ||
| ``` | ||
|
|
||
| - [ ] **Step 2: Verify red** | ||
|
|
||
| Run: `go test ./internal/cli -run '^TestCachedBranchSummary$'` | ||
|
|
||
| Expected: compile failure because `cachedBranchSummary` does not exist. | ||
|
|
||
| ### Task 2: Add the local-only presenter and render it | ||
|
|
||
| **Files:** | ||
|
|
||
| - Modify: `internal/cli/status.go` | ||
| - Test: `internal/cli/status_test.go` | ||
|
|
||
| - [ ] **Step 1: Implement the presenter** | ||
|
|
||
| ```go | ||
| func cachedBranchSummary(state branchsync.State) string { | ||
| summary := humanSyncSummary(state) | ||
| if state.Local.Branch == "" || state.Local.Head == "" { return "cached: unavailable (" + summary + ")" } | ||
| head := state.Local.Head[:minLen(len(state.Local.Head), 8)] | ||
| cleanliness := "clean" | ||
| if !state.Local.Clean { cleanliness = "dirty"; if state.Local.Reason != "" { cleanliness += ": " + state.Local.Reason } } | ||
| return fmt.Sprintf("cached: %s %s (%s; %s)", state.Local.Branch, head, cleanliness, summary) | ||
| } | ||
| ``` | ||
|
|
||
| - [ ] **Step 2: Replace the conditional cached-state rendering** | ||
|
|
||
| ```go | ||
| syncState := (&branchsync.Service{DB: d, Repo: repo, WorkDir: "."}).InspectCached(cmd.Context()) | ||
| cachedSummary := cachedBranchSummary(syncState) | ||
| fmt.Fprintf(w, "\n %s %s\n", sDim.Render("local state:"), cachedSummary) | ||
| ``` | ||
|
|
||
| - [ ] **Step 3: Verify green** | ||
|
|
||
| Run: `go test ./internal/cli -run '^TestCachedBranchSummary$'` | ||
|
|
||
| Expected: PASS. | ||
|
|
||
| ### Task 3: Keep telemetry aligned with rendered evidence | ||
|
|
||
| **Files:** | ||
|
|
||
| - Modify: `internal/cli/status.go` | ||
| - Modify: `internal/cli/status_test.go` | ||
|
|
||
| - [ ] **Step 1: Add a failing fingerprint regression test** | ||
|
|
||
| ```go | ||
| func TestStatusFingerprintIncludesCachedSummary(t *testing.T) { | ||
| run := &db.Run{ID: "run-1", Branch: "feature/test", Status: "running", HeadSHA: "head-one"} | ||
| before := statusFingerprint("repo", "running", run, "cached: main 01234567 (clean; synchronized)") | ||
| after := statusFingerprint("repo", "running", run, "cached: main 89abcdef (dirty; dirty)") | ||
| if before == after { t.Fatal("changing displayed cached evidence must change the status fingerprint") } | ||
| } | ||
| ``` | ||
|
|
||
| - [ ] **Step 2: Verify red** | ||
|
|
||
| Run: `go test ./internal/cli -run '^TestStatusFingerprintIncludesCachedSummary$'` | ||
|
|
||
| Expected: compile failure until `statusFingerprint` accepts the cached summary. | ||
|
|
||
| - [ ] **Step 3: Update signature and call site** | ||
|
|
||
| ```go | ||
| fingerprint := statusFingerprint(repo.ID, daemonState, activeRun, cachedSummary) | ||
| ``` | ||
|
|
||
| Build the fingerprint from repository id, daemon state, cached summary, and | ||
| the existing active-run fields. Update the existing active-run-head test with | ||
| the fourth argument. | ||
|
|
||
| - [ ] **Step 4: Verify focused tests** | ||
|
|
||
| Run: `go test ./internal/cli -run 'Test(CachedBranchSummary|StatusFingerprint)'` | ||
|
|
||
| Expected: PASS. | ||
|
|
||
| ### Task 4: Validate and prepare review | ||
|
|
||
| **Files:** | ||
|
|
||
| - Modify: `internal/cli/status.go` | ||
| - Create: `internal/cli/status_test.go` | ||
|
|
||
| - [ ] **Step 1: Add command-level status coverage** | ||
|
|
||
| Use `setupTestRepo`, `executeCmd("init")`, and `executeCmd("status")` to | ||
| assert the clean and a newly dirty worktree both retain `repo`, `daemon`, and | ||
| `no active run` output and always include `local state: cached:`. The clean | ||
| case must include `(clean;`; the dirty case must include `(dirty:`. | ||
|
|
||
| Run: `go test ./internal/cli -run '^TestStatusAlwaysRendersCachedLocalState$' -count=1` | ||
|
|
||
| Expected: PASS. | ||
|
|
||
| - [ ] **Step 2: Format and run full gates** | ||
|
|
||
| Run: `gofmt -w internal/cli/status.go internal/cli/status_test.go && make lint && go test -race ./... && go build -o ./bin/no-mistakes ./cmd/no-mistakes` | ||
|
|
||
| Expected: each command exits 0. | ||
|
|
||
| - [ ] **Step 3: Inspect the review diff** | ||
|
|
||
| Run: `git diff --check && git diff -- internal/cli/status.go internal/cli/status_test.go` | ||
|
|
||
| Expected: no whitespace errors and no source file outside the planned scope. | ||
|
|
||
| - [ ] **Step 4: Commit after fresh evidence** | ||
|
|
||
| ```bash | ||
| git add internal/cli/status.go internal/cli/status_test.go | ||
| git commit -m "feat(status): show cached repository state" | ||
| ``` |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| # Cached Repository State Design | ||
|
|
||
| ## Intent | ||
|
|
||
| Rebuild the legitimate portion of the old fork's diagnostics intent on current | ||
| `upstream/main`: make `no-mistakes status` always show the already-available | ||
| local branch evidence that an agent needs before starting work. | ||
|
|
||
| ## Scope | ||
|
|
||
| `status` will call the existing `branchsync.Service.InspectCached` once and | ||
| render a clearly labelled cached summary containing the local branch, a short | ||
| HEAD, clean/dirty state, any local reason, and the existing human branch-sync | ||
| summary. Its telemetry fingerprint will include that rendered evidence so a | ||
| meaningful displayed state change is observable by the sampled read surface. | ||
|
|
||
| ## Safety contract | ||
|
|
||
| `InspectCached` is the data source because it explicitly does not fetch, | ||
| contact a remote, alter refs, alter the index, alter the worktree, create a | ||
| pipeline run, or mutate the database. The output must say `cached`; it must | ||
| not claim current remote freshness. | ||
|
|
||
| ## Non-goals | ||
|
|
||
| - No new pipeline step, daemon behaviour, schema, gate, worktree inventory, | ||
| remote inspection, or direct process execution. | ||
| - No recovery or synchronization action from `status`. | ||
| - No recovery of the fork's unregistered pipeline experiment or tracked binary. | ||
|
|
||
| ## Acceptance criteria | ||
|
|
||
| 1. A registered repository's `status` output always includes cached local | ||
| branch evidence, including an explicit unavailable form when Git evidence is | ||
| absent. | ||
| 2. A clean and a dirty local state render distinguishable, actionable text. | ||
| 3. A change to rendered cached state changes the status telemetry fingerprint. | ||
| 4. Existing status behaviour for repo identity, daemon, and active-run display | ||
| remains intact. | ||
| 5. `gofmt -w .`, `make lint`, `go test -race ./...`, and | ||
| `go build -o ./bin/no-mistakes ./cmd/no-mistakes` succeed before review. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -61,10 +61,10 @@ func newStatusCmd() *cobra.Command { | |
| if err != nil { | ||
| return "", "", fmt.Errorf("check active run: %w", err) | ||
| } | ||
| fingerprint := statusFingerprint(repo.ID, daemonState, activeRun) | ||
| if syncState := (&branchsync.Service{DB: d, Repo: repo, WorkDir: "."}).InspectCached(cmd.Context()); relevantCachedSyncState(syncState) { | ||
| fmt.Fprintf(w, "\n %s %s\n", sDim.Render("local branch:"), humanSyncSummary(syncState)) | ||
| } | ||
| syncState := (&branchsync.Service{DB: d, Repo: repo, WorkDir: "."}).InspectCached(cmd.Context()) | ||
| cachedSummary := cachedBranchSummary(syncState) | ||
| fingerprint := statusFingerprint(repo.ID, daemonState, activeRun, cachedSummary) | ||
| fmt.Fprintf(w, "\n %s %s\n", sDim.Render("local state:"), cachedSummary) | ||
| if activeRun != nil { | ||
| fmt.Fprintln(w) | ||
| fmt.Fprintf(w, " %s\n", sCyan.Render("Active run")) | ||
|
|
@@ -85,11 +85,30 @@ func newStatusCmd() *cobra.Command { | |
| } | ||
| } | ||
|
|
||
| func statusFingerprint(repoID, daemonState string, activeRun *db.Run) string { | ||
| func statusFingerprint(repoID, daemonState string, activeRun *db.Run, cachedSummary string) string { | ||
| base := repoID + "|" + daemonState + "|" + cachedSummary | ||
| if activeRun == nil { | ||
| return repoID + "|" + daemonState + "|idle" | ||
| return base + "|idle" | ||
| } | ||
| return fmt.Sprintf("%s|%s:%s:%s:%s", base, activeRun.ID, activeRun.Branch, activeRun.Status, activeRun.HeadSHA) | ||
| } | ||
|
|
||
| func cachedBranchSummary(state branchsync.State) string { | ||
| summary := humanSyncSummary(state) | ||
| if state.Local.Branch == "" || state.Local.Head == "" { | ||
| return "cached: unavailable (" + summary + ")" | ||
| } | ||
| return fmt.Sprintf("%s|%s|%s:%s:%s:%s", repoID, daemonState, activeRun.ID, activeRun.Branch, activeRun.Status, activeRun.HeadSHA) | ||
|
|
||
| head := state.Local.Head[:minLen(len(state.Local.Head), 8)] | ||
| cleanliness := "clean" | ||
| if !state.Local.Clean { | ||
| cleanliness = "dirty" | ||
| if state.Local.Reason != "" { | ||
| cleanliness += ": " + state.Local.Reason | ||
| } | ||
| } | ||
|
|
||
| return fmt.Sprintf("cached: %s %s (%s; %s)", state.Local.Branch, head, cleanliness, summary) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SUGGESTION: For a dirty worktree the cached summary renders as Reply with |
||
| } | ||
|
|
||
| func minLen(a, b int) int { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| package cli | ||
|
|
||
| import ( | ||
| "os" | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/kunchenguid/no-mistakes/internal/branchsync" | ||
| "github.com/kunchenguid/no-mistakes/internal/db" | ||
| ) | ||
|
|
||
| func TestStatusAlwaysRendersCachedLocalState(t *testing.T) { | ||
| setupTestRepo(t) | ||
| if _, err := executeCmd("init"); err != nil { | ||
| t.Fatalf("init: %v", err) | ||
| } | ||
|
|
||
| clean, err := executeCmd("status") | ||
| if err != nil { | ||
| t.Fatalf("clean status: %v", err) | ||
| } | ||
| for _, want := range []string{"repo:", "daemon:", "local state: cached:", "(clean;", "no active run"} { | ||
| if !strings.Contains(clean, want) { | ||
| t.Fatalf("clean status missing %q:\n%s", want, clean) | ||
| } | ||
| } | ||
|
|
||
| if err := os.WriteFile("uncommitted.txt", []byte("dirty\n"), 0o644); err != nil { | ||
| t.Fatalf("make worktree dirty: %v", err) | ||
| } | ||
|
|
||
| dirty, err := executeCmd("status") | ||
| if err != nil { | ||
| t.Fatalf("dirty status: %v", err) | ||
| } | ||
| for _, want := range []string{"repo:", "daemon:", "local state: cached:", "(dirty:", "no active run"} { | ||
| if !strings.Contains(dirty, want) { | ||
| t.Fatalf("dirty status missing %q:\n%s", want, dirty) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| func TestCachedBranchSummary(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| state branchsync.State | ||
| want string | ||
| }{ | ||
| { | ||
| name: "clean branch", | ||
| state: branchsync.State{ | ||
| State: branchsync.StateSynchronized, | ||
| Local: branchsync.LocalState{Branch: "feature/state", Head: "0123456789abcdef", Clean: true}, | ||
| }, | ||
| want: "cached: feature/state 01234567 (clean; already synchronized with the pipeline-pushed head)", | ||
| }, | ||
| { | ||
| name: "dirty branch", | ||
| state: branchsync.State{ | ||
| State: branchsync.StateDirty, | ||
| Local: branchsync.LocalState{Branch: "feature/state", Head: "fedcba9876543210", Reason: "uncommitted changes"}, | ||
| }, | ||
| want: "cached: feature/state fedcba98 (dirty: uncommitted changes; dirty)", | ||
| }, | ||
| { | ||
| name: "unavailable", | ||
| state: branchsync.State{State: branchsync.StateAmbiguousContext}, | ||
| want: "cached: unavailable (ambiguous context)", | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| if got := cachedBranchSummary(tt.state); got != tt.want { | ||
| t.Fatalf("cachedBranchSummary() = %q, want %q", got, tt.want) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestStatusFingerprintIncludesCachedSummary(t *testing.T) { | ||
| run := &db.Run{ID: "run-1", Branch: "feature/test", Status: "running", HeadSHA: "head-one"} | ||
| before := statusFingerprint("repo", "running", run, "cached: main 01234567 (clean; synchronized)") | ||
| after := statusFingerprint("repo", "running", run, "cached: main 89abcdef (dirty; dirty)") | ||
| if before == after { | ||
| t.Fatal("changing displayed cached evidence must change the status fingerprint") | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SUGGESTION: The status telemetry fingerprint now embeds the fully-rendered human summary from
humanSyncSummary, which is shared display copy also used byno-mistakes syncandaxi. A future wording edit to that shared function changes this fingerprint and re-triggers the read-surface telemetry gate fleet-wide (the fingerprint is persisted intelemetry-gate.jsonand gates emission on change). Consider deriving the fingerprint from structured fields (state.State,Local.Clean, branch, short head) so it reflects state without coupling to display wording.Reply with
@kilocode-bot fix itto have Kilo Code address this issue.