Skip to content

Local code review in the session file-changes panel (code_review) - #197

Draft
serxa wants to merge 2 commits into
mainfrom
serxa/code-review-panel
Draft

Local code review in the session file-changes panel (code_review)#197
serxa wants to merge 2 commits into
mainfrom
serxa/code-review-panel

Conversation

@serxa

@serxa serxa commented Jul 24, 2026

Copy link
Copy Markdown
Member

Local code review inside the session's file-changes panel (code_review)

Review code before it's committed or pushed, from inside a session's file-changes panel (Chat → the Files button). A session can attach one or more git worktrees; their diffs (vs a base ref) and line-anchored comment threads show in the panel. Off by default; enabled per-install via config.

Why

Reviewing an agent's in-progress changes meant reading raw git diff in a terminal — no way to point at a specific line and discuss it inside Nerve. This adds a two-way, line-anchored review loop for local (uncommitted) code, organized around "this session ↔ these worktree(s)".

What it does

  • Attach a worktree to a session (many per session, including worktrees outside the workspace), then browse its working-tree diff vs a base ref + a full-file view.
  • Comment on lines, then Submit review once: comments are staged as drafts and the whole review — an optional overall summary + every inline comment — is delivered to the target session as one turn (not one turn per comment). The agent's reply posts back onto each thread. The agent can also originate threads to point the human at a line.
  • Data model: reviews (worktree + base_ref + target_session_id) → threads (file + line + side) → comments (staged pending until submitted).

Config (off by default)

code_review:
  enabled: true
  repos:
    - ~/nerve
    - ~/project

Only files inside a configured repo root (or one of its git worktrees) are served, path-traversal guarded. Every route requires the existing web-UI auth.

Changes

  • config: CodeReviewConfig (enabled + repo roots + max file size)
  • db: migrations v045 (reviews / threads / comments) + v046 (comment pending flag); ReviewStore (session filter, pending staging, batched submit)
  • gateway: gitreview.py (worktree enumeration, working-tree diffs, file-at-ref, path guard) reusing compute_file_diff; routes/reviews.py/api/review/* reads, /api/reviews/* CRUD, and POST /api/reviews/{id}/submit (one batched turn to the session)
  • web: the Chat file-changes panel gains a Worktrees section — attach picker, per-worktree git changed-files, a line-anchored diff renderer with inline threads, a "draft" badge on staged comments, and a "Submit review (N)" bar with an optional summary
  • tests: test_reviews.py — store (session filter, pending/submit), git helpers (incl. traversal guard), routes (staging does not inject; submit delivers one turn)

Backend changes are additive (new tables/columns/routes/config); migrations create/alter only the code-review tables.

@serxa serxa changed the title Add a local code-review panel (code_review feature) Local code review in the session file-changes panel (code_review) Jul 25, 2026
Browser panel for reviewing on-disk git worktrees with line-anchored,
two-way review comments before anything is committed or pushed. Adds the
code_review config section, ReviewStore + migration, the gitreview
gateway and /api/review routes, and the web review panel folded into the
session file-changes view.

Rebased onto current main: the code_review migration is numbered v045
(main took v040-v044), and CodeReviewConfig.from_dict routes through
@_coerced like every other config section so string env values coerce
to their declared types.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@serxa
serxa force-pushed the serxa/code-review-panel branch from 5639691 to ec9bcdc Compare August 10, 2026 20:53
@serxa

serxa commented Aug 10, 2026

Copy link
Copy Markdown
Member Author

Rebased onto current main — summary of changes

This branch was force-pushed: 5639691ec9bcdc. History is rewritten, so re-sync any local checkout before continuing:

git fetch origin
git checkout serxa/code-review-panel
git reset --hard origin/serxa/code-review-panel

Goal of the rebase: keep #197 code-review-only and current with main. What changed:

1. Telegram change extracted → now in #304

This branch had previously also dropped the per-row ⭐/☆ star toggle from the Telegram /sessions keyboard. That change is removed from #197 and now lives in #304 (the Telegram /sessions PR). #197 is now 14 files, code-review only — no nerve/channels/telegram.py, no session-view code. Please keep Telegram/session changes out of this PR.

2. Migration renumbered v040v045

main now occupies v040_updated_at_from_messagesv044_task_events, so the code-review migration collided at v040. It's renamed to nerve/db/migrations/v045_code_reviews.py — content unchanged and still idempotent (CREATE TABLE/INDEX IF NOT EXISTS), so it applies cleanly whether or not the tables already exist. If anything referenced the migration by number, it's v045 now.

3. CodeReviewConfig.from_dict now routes through @_coerced

main introduced the nerve.coerce framework plus tests/test_config_env.py::TestScalarCoercion, which asserts every declared config field coerces string values to its declared type. CodeReviewConfig was casting by hand (bool(d.get(...)), [str(r) for r in ...]), which bypassed coercion — enabled: "false" became True, and a bare repos string was char-split. Fixed by decorating from_dict with @_coerced and passing raw values through, matching every other config section.

4. Conflict resolutions vs main

  • nerve/gateway/routes/__init__.py — include both the reviews router and main's workflow_runs / review_loops / config routers.
  • nerve/db/base.py — import and mix in both ReviewStore and main's ReviewLoopStore.
  • web/src/pages/ChatPage.tsx — kept the always-visible "Files & code review" button (opens the panel even with 0 changed files) plus main's responsive ContextBar wrapper (hidden md:flex).

State

Head ec9bcdc · base main · MERGEABLE · kept draft. pytest tests/test_reviews.py tests/test_config_env.py → 61 passed.

Human line comments are now staged as drafts (pending) instead of each injecting
its own turn into the target session. A "Submit review" action delivers the whole
review — an optional overall summary + all pending comments — as a single turn,
GitHub-style.

- db: v046 adds code_review_comments.pending; ReviewStore.add_comment(pending),
  list_pending_comments, mark_review_submitted
- routes: human comments stored pending (no per-comment inject);
  POST /api/reviews/{id}/submit builds one batched message + one engine.run
- web: pending "draft" badge on staged comments; "Submit review (N)" bar with an
  optional summary box, in the worktree + file views
- tests: staging (no inject), batched submit (one turn), agent reply unaffected

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@serxa

serxa commented Aug 10, 2026

Copy link
Copy Markdown
Member Author

Added batched review submission (commit 660192d): human line comments are now staged as drafts; a "Submit review" action delivers the whole review — optional summary + all pending comments — to the target session as one turn instead of one turn per comment.

  • db: v046 code_review_comments.pending; POST /api/reviews/{id}/submit
  • web: "draft" badge on staged comments + "Submit review (N)" bar (with summary) in the worktree/file views
  • tests: staging does not inject; submit delivers exactly one turn

Full suite 3204 passed (1 pre-existing unrelated xmemory failure); npm run build clean. Not yet on the live daemon — needs a redeploy of the integration branch.

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.

1 participant