Skip to content

feat: add M5 git workflow backend#72

Merged
gnanam1990 merged 5 commits into
mainfrom
feat/m5-autocommit-self-verify
Jun 5, 2026
Merged

feat: add M5 git workflow backend#72
gnanam1990 merged 5 commits into
mainfrom
feat/m5-autocommit-self-verify

Conversation

@gnanam1990

@gnanam1990 gnanam1990 commented Jun 5, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Add a Go-native internal/zerogit backend for local git change inspection, redacted diff summaries, generated commit messages, dry-run commit previews, and real git add -A / commit execution.
  • Extend verification reports with structured failure summaries and a bounded self-verification loop contract for retry-aware automation.
  • Expose the backend through zero changes inspect, zero changes commit, and zero verify --attempts with JSON/text output and CLI regression coverage.

Validation

  • go test ./internal/zerogit ./internal/verify ./internal/cli
  • go test ./...
  • go test -count=1 ./internal/zerogit ./internal/verify ./internal/cli
  • go test -count=1 -p 1 ./...
  • go build ./cmd/zero
  • bun run typecheck
  • bun test ./tests --timeout 15000 - 291 pass / 0 fail
  • bun run build
  • bun run smoke:build
  • bun run smoke:go
  • /tmp/zero-m5 changes inspect --json --diff-bytes 600
  • /tmp/zero-m5 changes commit --dry-run --message "Update M5 git backend"
  • /tmp/zero-m5 verify --attempts 2 --only go.test --timeout-ms 600000 --json
  • git diff --check origin/main..HEAD

Reviewers: @Vasanthdev2004 @anandh8x

Summary by CodeRabbit

  • New Features

    • Added change commands to inspect repo status/preview diffs and to commit changes (supports --message, --dry-run, --diff-bytes, --cwd); commit message generation/validation and commit-result reporting included
    • Verify command supports bounded retries via --attempts and emits loop reports (JSON or formatted)
    • Output summarization, redaction and diff truncation applied to verify and change outputs
  • Tests

    • Expanded tests covering verify retries, output summarization/truncation/redaction, change inspect/commit, dry-run semantics, and repo-preview behaviors

@github-actions

github-actions Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Zero automated PR review

Verdict: No blockers found

Blockers

  • None found.

Validation

  • [pass] Diff hygiene: git diff --check
  • [pass] Typecheck: bun run typecheck
  • [pass] Tests: bun run test
  • [pass] Build: bun run build
  • [pass] Smoke build: bun run smoke:build

Scope

Head: c04c58688815
Changed files (7): internal/cli/app.go, internal/cli/workflow_test.go, internal/cli/workflows.go, internal/verify/verify.go, internal/verify/verify_test.go, internal/zerogit/zerogit.go, internal/zerogit/zerogit_test.go

This deterministic review checks validation status and basic diff hygiene. A human reviewer still owns product judgment and design quality.

@coderabbitai

coderabbitai Bot commented Jun 5, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 3975db76-61dc-4f74-a467-17fd8a15fe79

📥 Commits

Reviewing files that changed from the base of the PR and between 319d0d4 and c04c586.

📒 Files selected for processing (2)
  • internal/zerogit/zerogit.go
  • internal/zerogit/zerogit_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • internal/zerogit/zerogit_test.go

Walkthrough

This PR adds a zerogit module to inspect/commit git changes, extends verify with output summarization and a bounded RunLoop, and wires both into the CLI: zero changes (inspect/status/commit) and verify --attempts with JSON and human-readable outputs.

Changes

Changes inspection and verify loops

Layer / File(s) Summary
Git inspection and commit
internal/zerogit/zerogit.go
New module providing Inspect() and Commit() to query git working-tree state and optionally create commits. Adds injectable git runners, staged-diff snapshotting with isolated index, redaction-aware truncation, commit-message generation/validation, and dry-run support.
zerogit tests and helpers
internal/zerogit/zerogit_test.go
Unit and integration tests, a fakeRunner test double, and helpers to initialize temporary git repos; tests cover diff redaction, truncation, inspect-preview behavior with unborn HEAD, and commit dry-run semantics.
Verify output summary and retry loops
internal/verify/verify.go
Extends Result with OutputSummary to capture failure context, adds OutputSummary/Attempt/LoopReport types, implements summarizeOutput for failure-context extraction, and adds RunLoop() with LoopOptions (MaxAttempts, OnFailure).
Verify tests
internal/verify/verify_test.go
Tests for parsing structured failure summaries, plain runner errors, truncation edge-cases, and RunLoop retry behavior including OnFailure invocation and attempt accounting.
CLI dependency injection and command routing
internal/cli/app.go
Extends appDeps with runVerifyLoop, inspectChanges, and commitChanges; wires defaults to verify.RunLoop, zerogit.Inspect, and zerogit.Commit; adds changes command and updates help text.
Changes and verify CLI commands
internal/cli/workflows.go, internal/cli/workflow_test.go
Adds runChanges handler for inspect/status/commit with --message, --dry-run, --diff-bytes, support for --json/--cwd; updates runVerifyCommand to use --attempts with loop output; expands parsing, redaction, and formatting helpers; adds workflow tests for verify-loop JSON and changes inspect/commit behaviors.

Sequence Diagram(s)

sequenceDiagram
  participant CLI as User CLI
  participant ZeroGit as zerogit.Inspect/Commit
  participant Verify as verify.RunLoop/Run
  participant Git as Git Runner

  alt changes inspect
    CLI->>ZeroGit: Inspect(ctx, InspectOptions)
    ZeroGit->>Git: git rev-parse, git status, git diff (GIT_INDEX_FILE)
    Git->>ZeroGit: stdout/stderr
    ZeroGit->>CLI: ChangeSummary (files, diff, truncated)
  else changes commit
    CLI->>ZeroGit: Commit(ctx, CommitOptions)
    ZeroGit->>ZeroGit: Inspect() -> ChangeSummary
    ZeroGit->>Git: git add -A
    ZeroGit->>Git: git commit -m [message]
    ZeroGit->>Git: git rev-parse --short HEAD
    Git->>ZeroGit: stdout
    ZeroGit->>CLI: CommitResult (committed, commitHash, before)
  else verify --attempts N
    CLI->>Verify: RunLoop(ctx, plan, MaxAttempts=N)
    loop Each attempt
      Verify->>Verify: Run(ctx, plan)
      Verify->>Verify: Append Attempt to LoopReport
      alt Pass
        Verify->>CLI: LoopReport OK
      else Fail & OnFailure
        Verify->>Verify: Invoke OnFailure -> decide retry/stop
      end
    end
  end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • Gitlawb/zero#70: Extends the verify module foundation introduced in that PR with OutputSummary extraction and RunLoop retry capability.

Suggested reviewers

  • anandh8x
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: add M5 git workflow backend' is concise and clearly describes the main addition—a new git workflow backend feature with M5-specific functionality that spans zerogit, verify, and CLI layers.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/m5-autocommit-self-verify

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/verify/verify.go`:
- Around line 274-276: The code sets truncated = true when len(lines) >= 8,
marking summaries truncated even if exactly eight lines were captured; change
the logic so Truncated is set only when content beyond the capture limit exists
(e.g., check for len(lines) > 8 or verify there is at least one additional
relevant line before setting truncated). Locate the block that checks len(lines)
>= 8 in verify.go and modify it to detect an actual overflow (peek the next line
index or use the total count) and only set truncated = true when there is more
content to drop.
- Around line 255-286: summarizeOutput currently returns nil when no lines match
isFailureLine, dropping plain execution errors; update summarizeOutput to fall
back to populating OutputSummary with the first non-empty trimmed line from the
provided values when no failure-context lines were captured (preserving existing
trimming, redaction behavior if present), still respecting the max-8-lines cap
and setting Truncated appropriately; keep the main loop and only create the
fallback OutputSummary (with Lines containing that one line) before returning
nil so that OutputSummary is never nil for simple command errors.

In `@internal/zerogit/zerogit.go`:
- Around line 297-306: The current branch that handles a redaction marker when
budget <= 0 can return strings longer than maxBytes (e.g. returning
redaction.RedactedSecret + suffix). Update that branch in the function using
variables suffix, marker, budget, head so the returned string never exceeds
maxBytes: if len(suffix) >= maxBytes return suffix[:maxBytes]; otherwise compute
allowed = maxBytes - len(suffix), take the first allowed bytes/characters of
redaction.RedactedSecret (or the marker) and append suffix, and return that;
this ensures all returns respect the MaxDiffBytes budget.
- Around line 88-92: Inspect() currently builds ChangeSummary.DiffStat/Diff by
calling gitRawOutput with "diff --stat HEAD --" and "diff HEAD --", which fails
for unborn HEAD and omits untracked files; change the logic to create a
temporary index that stages untracked files (use a temporary GIT_INDEX_FILE and
run "git add -A" into that index) and run "git diff --cached --stat --" and "git
diff --cached --" against that staged snapshot instead of HEAD, and add a
fallback that uses the empty-tree diff (no-HEAD) when HEAD is absent (detect via
"git rev-parse --verify HEAD" or error from git and then use the empty tree SHA)
so ChangeSummary.DiffStat/Diff reflect what "git add -A" + commit would produce;
update tests to cover unborn HEAD and untracked-only changes to assert preview
matches the commit outcome.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: ba49d743-caf6-4365-8ea8-8855ec67d64a

📥 Commits

Reviewing files that changed from the base of the PR and between a58e6c4 and 4485eb8.

📒 Files selected for processing (7)
  • internal/cli/app.go
  • internal/cli/workflow_test.go
  • internal/cli/workflows.go
  • internal/verify/verify.go
  • internal/verify/verify_test.go
  • internal/zerogit/zerogit.go
  • internal/zerogit/zerogit_test.go

Comment thread internal/verify/verify.go
Comment thread internal/verify/verify.go Outdated
Comment thread internal/zerogit/zerogit.go Outdated
Comment thread internal/zerogit/zerogit.go Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/zerogit/zerogit_test.go`:
- Around line 265-273: The test helper runGitCommand should use a context tied
to the test deadline so a stuck git process can be cancelled: replace
exec.Command(...) with exec.CommandContext(ctx, "git", args...) where ctx is
derived from t.Deadline() (e.g., context.WithDeadline or context.WithTimeout
using time.Until(t.Deadline())), ensure you import the context package (and time
if using time.Until), and propagate that ctx when creating the command; keep the
existing error handling and return value in runGitCommand.

In `@internal/zerogit/zerogit.go`:
- Line 282: The defer currently calls os.RemoveAll(tempDir) without handling its
returned error; make the ignored return explicit so errcheck is satisfied by
changing the defer to explicitly discard the error (e.g., use the blank
identifier) or handle/log it; update the defer that references tempDir in
zerogit.go (the defer os.RemoveAll(tempDir) call) so the intent to ignore the
error is explicit.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 4b738f4c-283f-44f8-aaf0-13e44ec2db99

📥 Commits

Reviewing files that changed from the base of the PR and between 4485eb8 and 319d0d4.

📒 Files selected for processing (4)
  • internal/verify/verify.go
  • internal/verify/verify_test.go
  • internal/zerogit/zerogit.go
  • internal/zerogit/zerogit_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • internal/verify/verify.go

Comment thread internal/zerogit/zerogit_test.go
Comment thread internal/zerogit/zerogit.go Outdated
@Vasanthdev2004

Copy link
Copy Markdown
Collaborator

Looks Good

I reviewed latest head c04c58688815b2d1bd188230bd15d34e5a938237 for the M5 git workflow backend. The PR branch is based on an older main (a58e6c4... while current origin/main is 43c2560...), so I validated both the PR branch and a latest-main test merge. The merge applied cleanly and the targeted/full validation still passed there.

Blockers

  • None.

Non-Blocking

  • The branch is stale relative to current main, but a detached origin/main + PR-head test merge completed cleanly. A normal update/rebase before merge would make the final diff easier to read, but I do not see a code-review blocker from the stale base.

Looks Good

  • internal/zerogit keeps inspect previews non-mutating by using an alternate GIT_INDEX_FILE for the staged snapshot diff, while the real commit path intentionally stages with git add -A only outside dry-run mode.
  • Change summaries redact status paths/diff/diffstat, truncate bounded diff output, and keep ordinary diagnostic fields useful.
  • zero changes inspect and zero changes commit route JSON/text output through the CLI redaction layer before formatting.
  • zero verify --attempts exposes a bounded loop report while preserving the single-attempt behavior for the default path.
  • Runtime probes passed for:
    • ./zero.exe changes inspect --cwd <temp-git-repo> --json --diff-bytes 600
    • ./zero.exe changes inspect --cwd <temp-git-repo> --diff-bytes 600
    • ./zero.exe changes commit --cwd <temp-git-repo> --dry-run --message "Update secret probe" --json
    • ./zero.exe changes commit --cwd <temp-git-repo> --dry-run --message "Update secret probe"
    • a real ./zero.exe changes commit --cwd <temp-git-repo> --message "Add secret probe" --json, verifying HEAD advanced and the worktree was clean afterward
    • ./zero.exe verify --attempts 2 --only go.test --timeout-ms 600000 --json
  • Redaction probes used assembled OpenAI-shaped dummy values and verified the exact raw value was absent from inspect and commit dry-run JSON/text output.

PR-branch validation passed:

  • go test -count=1 ./internal/zerogit ./internal/verify ./internal/cli
  • go test -count=1 -p 1 ./...
  • go build ./cmd/zero
  • bun install --frozen-lockfile
  • bun run typecheck
  • bun test ./tests --timeout 15000 — 291 pass / 0 fail
  • bun run build
  • bun run smoke:build
  • bun run smoke:go
  • ./zero.exe --help
  • ./zero.exe changes --help
  • ./zero.exe verify --help
  • git diff --check $(git merge-base HEAD origin/main)..HEAD

Latest-main test-merge validation passed:

  • git merge --no-commit --no-ff origin/pr/72 from current origin/main
  • go test -count=1 ./internal/zerogit ./internal/verify ./internal/cli
  • go test -count=1 -p 1 ./...
  • go build ./cmd/zero
  • bun install --frozen-lockfile
  • bun run typecheck
  • bun test ./tests --timeout 15000 — 217 pass / 0 fail
  • bun run build
  • bun run smoke:build
  • bun run smoke:go
  • ./zero.exe changes --help
  • ./zero.exe verify --help
  • git diff --check --cached

GitHub checks are green: Smoke ubuntu, Smoke macOS, Smoke Windows, Performance Smoke, Zero Review, and CodeRabbit.

@Vasanthdev2004 Vasanthdev2004 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks Good

I reviewed latest head c04c58688815b2d1bd188230bd15d34e5a938237 for the M5 git workflow backend. The PR branch is based on an older main (a58e6c4... while current origin/main is 43c2560...), so I validated both the PR branch and a latest-main test merge. The merge applied cleanly and the targeted/full validation still passed there.

Blockers

  • None.

Non-Blocking

  • The branch is stale relative to current main, but a detached origin/main + PR-head test merge completed cleanly. A normal update/rebase before merge would make the final diff easier to read, but I do not see a code-review blocker from the stale base.

Looks Good

  • internal/zerogit keeps inspect previews non-mutating by using an alternate GIT_INDEX_FILE for the staged snapshot diff, while the real commit path intentionally stages with git add -A only outside dry-run mode.
  • Change summaries redact status paths/diff/diffstat, truncate bounded diff output, and keep ordinary diagnostic fields useful.
  • zero changes inspect and zero changes commit route JSON/text output through the CLI redaction layer before formatting.
  • zero verify --attempts exposes a bounded loop report while preserving the single-attempt behavior for the default path.
  • Runtime probes passed for:
    • ./zero.exe changes inspect --cwd <temp-git-repo> --json --diff-bytes 600
    • ./zero.exe changes inspect --cwd <temp-git-repo> --diff-bytes 600
    • ./zero.exe changes commit --cwd <temp-git-repo> --dry-run --message "Update secret probe" --json
    • ./zero.exe changes commit --cwd <temp-git-repo> --dry-run --message "Update secret probe"
    • a real ./zero.exe changes commit --cwd <temp-git-repo> --message "Add secret probe" --json, verifying HEAD advanced and the worktree was clean afterward
    • ./zero.exe verify --attempts 2 --only go.test --timeout-ms 600000 --json
  • Redaction probes used assembled OpenAI-shaped dummy values and verified the exact raw value was absent from inspect and commit dry-run JSON/text output.

PR-branch validation passed:

  • go test -count=1 ./internal/zerogit ./internal/verify ./internal/cli
  • go test -count=1 -p 1 ./...
  • go build ./cmd/zero
  • bun install --frozen-lockfile
  • bun run typecheck
  • bun test ./tests --timeout 15000 — 291 pass / 0 fail
  • bun run build
  • bun run smoke:build
  • bun run smoke:go
  • ./zero.exe --help
  • ./zero.exe changes --help
  • ./zero.exe verify --help
  • git diff --check $(git merge-base HEAD origin/main)..HEAD

Latest-main test-merge validation passed:

  • git merge --no-commit --no-ff origin/pr/72 from current origin/main
  • go test -count=1 ./internal/zerogit ./internal/verify ./internal/cli
  • go test -count=1 -p 1 ./...
  • go build ./cmd/zero
  • bun install --frozen-lockfile
  • bun run typecheck
  • bun test ./tests --timeout 15000 — 217 pass / 0 fail
  • bun run build
  • bun run smoke:build
  • bun run smoke:go
  • ./zero.exe changes --help
  • ./zero.exe verify --help
  • git diff --check --cached

GitHub checks are green: Smoke ubuntu, Smoke macOS, Smoke Windows, Performance Smoke, Zero Review, and CodeRabbit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants