Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
26be7dd
Merge commit 'fed1a7d' into gui/diff-discussions
lunemec Nov 20, 2026
73b5426
Add independent diff discussions and reply navigation
lunemec Nov 20, 2026
7e10817
Harden discussion navigation and background question sessions
lunemec Nov 20, 2026
e9a5bab
Use discussion navigation from command search
lunemec Nov 20, 2026
b184cfe
Continue diff questions in saved threads
lunemec Nov 20, 2026
9e33d03
Merge upstream main into diff discussions
lunemec Nov 24, 2026
fbfdf05
Collapse completed discussions in margin-gui
lunemec Nov 24, 2026
df8e164
Keep resolved discussion controls reachable
lunemec Nov 24, 2026
e0259ef
Follow the recap cursor after opening a disclosure
lunemec Nov 24, 2026
66e9333
Open a PR-first repository picker from the sidebar
lunemec Nov 24, 2026
164a07d
Clarify Margin GUI reading controls
lunemec Nov 24, 2026
f6acd6a
Keep the sidebar visible when opening a repository
lunemec Nov 24, 2026
b3689b7
Keep PR review walkthroughs switchable in margin-gui
lunemec Nov 24, 2026
4c994f0
Default margin-gui to Standard editing
lunemec Nov 24, 2026
3637771
Separate review grouping and display in margin-gui
lunemec Nov 24, 2026
241d638
Dim files and steps without matching notes
lunemec Nov 24, 2026
8fa8785
Align review toolbar control heights
lunemec Nov 24, 2026
3f3835d
Reuse prepared walkthroughs when switching review modes
lunemec Nov 24, 2026
e4cc1b9
Match the Notes dropdown to toolbar buttons
lunemec Nov 24, 2026
ecff5b0
Fix picker refresh and filtered note navigation
lunemec Nov 24, 2026
9653418
Add segmented review controls and adaptive toolbar overflow
lunemec Nov 24, 2026
42f9697
Fix note acknowledgement and focus in filtered reviews
lunemec Nov 24, 2026
2104424
Remove the diff-side selector from Margin GUI
lunemec Nov 24, 2026
6907aac
Keep uncommitted branch changes reviewable in Margin GUI
lunemec Nov 25, 2026
346c289
Merge upstream main into Margin PR 5
lunemec Nov 25, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# margin

**Yet another code review tool.** Yes. The one that makes sure you actually read the change, shows
which tests run each line, and lets you break a line in place, with vim keys, to see whether any of
them notice. See [the project page](https://antas.cz/margin/).
which tests run each line, and lets you edit a line in place to see whether any of them notice.
The GUI defaults to standard editing and offers Vim keybindings in Settings.
See [the project page](https://antas.cz/margin/).

margin reviews git changes with a coding agent beside you. The agent reads the change first, lays
out a route through it in reading order and writes a note on every change: what it does, why it is
Expand Down
42 changes: 29 additions & 13 deletions cmd/margin-gui/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/redrick/margin/internal/cli"
"github.com/redrick/margin/internal/config"
"github.com/redrick/margin/internal/control"
"github.com/redrick/margin/internal/review"
)

// scrollback is how much agent output is kept to replay when the review is shown again.
Expand All @@ -46,6 +47,7 @@ func (a *Agents) SetSubmit(submit bool) {

type session struct {
cmd *exec.Cmd
command string
pty *os.File
lease *os.File
exited chan struct{}
Expand Down Expand Up @@ -73,10 +75,11 @@ func (a *Agents) Start(reviewPath, repo string, created bool, cols, rows int) (s
return s.replay(), nil
}
return "", startLeasedAgent(reviewPath, func(lease *os.File) error {
if _, err := loadAgentReview(reviewPath, repo); err != nil {
rv, err := loadAgentReview(reviewPath, repo)
if err != nil {
return err
}
return a.launchNew(lease, reviewPath, repo, config.Load().Agent, created, false, cols, rows)
return a.launchNew(lease, rv, repo, config.Load().Agent, created, false, cols, rows)
})
}

Expand All @@ -86,8 +89,13 @@ func (s *session) replay() string {
return base64.StdEncoding.EncodeToString(s.buf)
}

func (a *Agents) launchNew(lease *os.File, path, repo, command string, created, continued bool, cols, rows int) error {
saved := savedAgent{Command: command, Repo: resumeIdentity(repo), Run: rand.Text(), Auto: true}
func (a *Agents) launchNew(lease *os.File, rv *review.Review, repo, command string, created, continued bool, cols, rows int) error {
path := rv.Path
preparation, err := beginWalkPreparation(rv)
if err != nil {
return err
}
saved := savedAgent{Command: command, Repo: resumeIdentity(repo), Run: rand.Text(), Auto: true, PreparingWalk: !continued && preparation != ""}
var registration *control.Server
var endpoint string
provider := agentPreset(command)
Expand All @@ -98,7 +106,7 @@ func (a *Agents) launchNew(lease *os.File, path, repo, command string, created,
log.Printf("registering the Codex conversation: %v", err)
}
}
argv := (config.Config{Agent: command}).AgentArgv(kickoff(path, created, continued, endpoint))
argv := (config.Config{Agent: command}).AgentArgv(kickoff(path, created, continued, endpoint, preparation))
if provider == "claude" {
saved.ID = newClaudeID()
argv = append([]string{argv[0], "--session-id", saved.ID}, argv[1:]...)
Expand Down Expand Up @@ -128,7 +136,7 @@ func (a *Agents) launch(lease *os.File, path, repo string, argv []string, saved
return err
}
s := &session{
cmd: cmd, pty: f, lease: lease, run: saved.Run, resuming: resuming,
cmd: cmd, command: saved.Command, pty: f, lease: lease, run: saved.Run, resuming: resuming,
exited: make(chan struct{}), registration: registration,
}
if err := updateReviewResume(path, func(record *reviewResume) bool {
Expand Down Expand Up @@ -352,7 +360,7 @@ func (a *Agents) pump(reviewPath string, s *session) {
}
}

func kickoff(reviewPath string, created, continued bool, endpoint string) string {
func kickoff(reviewPath string, created, continued bool, endpoint, preparation string) string {
command := "margin"
if endpoint != "" {
// A reused Codex app server can supply its own PATH to shell commands.
Expand All @@ -364,16 +372,24 @@ func kickoff(reviewPath string, created, continued bool, endpoint string) string
if endpoint != "" {
brief += " --gui-agent " + quoteAgentArg(endpoint)
}
var prompt string
if continued {
return "Continue the saved Margin review at " + reviewPath + ". Run `" + brief + " --continue` for the saved context. " +
prompt = "Continue the saved Margin review at " + reviewPath + ". Run `" + brief + " --continue` for the saved context. " +
"Wait for the reader's next instruction before reviewing again, running tests or editing files."
} else {
if created || preparation != "" {
brief += " --new"
}
prompt = "Code review with margin. The person reads the review in the margin desktop app beside you. Review file: " + reviewPath + "\n" +
"Start the review: run `" + brief + "` and follow its instructions."
}
if created {
brief += " --new"
if preparation != "" {
prompt += "\nThe reader can review by file while you prepare the functional walkthrough. " +
"After step 0, save the complete grouping and run `" + command + " walkthrough-ready --review " + quoteAgentArg(reviewPath) +
" --preparation " + quoteAgentArg(preparation) + "` before writing notes or measuring coverage. " +
"If it reports a problem with the grouping, fix it and run the command again. Keep any existing reader feedback."
}
return "Code review with margin. The person reads the review in the margin desktop app beside you, " +
"which reloads whenever the review file changes. Review file: " + reviewPath + "\n" +
"Start the review: run `" + brief + "` and follow its instructions."
return prompt
}

func quoteAgentArg(arg string) string {
Expand Down
23 changes: 13 additions & 10 deletions cmd/margin-gui/agent_resume.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ import (
)

type AgentResumeStatus struct {
Name string `json:"name,omitempty"`
Saved bool `json:"saved"`
Exact bool `json:"exact"`
Auto bool `json:"auto"`
CanLink bool `json:"canLink"`
Failed bool `json:"failed"`
WalkAttempted bool `json:"walkAttempted,omitempty"`
WalkPreparing bool `json:"walkPreparing,omitempty"`
Name string `json:"name,omitempty"`
Saved bool `json:"saved"`
Exact bool `json:"exact"`
Auto bool `json:"auto"`
CanLink bool `json:"canLink"`
Failed bool `json:"failed"`
}

var uuidPattern = regexp.MustCompile(`^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$`)
Expand Down Expand Up @@ -92,16 +94,17 @@ func newClaudeID() string {
}

func (a *Agents) ResumeStatus(path, repo string) AgentResumeStatus {
saved := readReviewResume(path).Agent
record := readReviewResume(path)
saved := record.Agent
if saved == nil || saved.Repo != resumeIdentity(repo) || strings.TrimSpace(saved.Command) == "" {
return AgentResumeStatus{CanLink: agentPreset(config.Load().Agent) != ""}
return AgentResumeStatus{CanLink: agentPreset(config.Load().Agent) != "", WalkAttempted: record.WalkPreparation != ""}
}
name := filepath.Base(strings.Fields(saved.Command)[0])
provider := agentPreset(saved.Command)
exact := validSessionID(provider, saved.ID)
return AgentResumeStatus{
Name: name, Saved: true, Exact: exact, Auto: saved.Auto && exact && !saved.Failed,
CanLink: provider != "", Failed: saved.Failed,
CanLink: provider != "", Failed: saved.Failed, WalkAttempted: record.WalkPreparation != "", WalkPreparing: saved.PreparingWalk,
}
}

Expand Down Expand Up @@ -178,7 +181,7 @@ func (a *Agents) restore(path, repo string, automatic, continued bool, cols, row
return errors.New("no saved agent for this review")
}
if continued {
return a.launchNew(lease, path, repo, saved.Command, false, true, cols, rows)
return a.launchNew(lease, rv, repo, saved.Command, false, true, cols, rows)
}
args, err := nativeResumeArgs(*saved)
if err != nil {
Expand Down
32 changes: 26 additions & 6 deletions cmd/margin-gui/assets/answers.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,29 @@ import { api, state, esc, el, toast, errText, md, openModal, closeModal } from "

let panel = null;

export async function openAnswers(focus = "") {
export async function openAnswers(focus, navigation, onRead) {
const review = state.opened;
let v;
try {
v = await api("Reviews.Answers");
} catch (e) {
return toast(errText(e), true);
toast(errText(e), true);
return false;
}
panel = { v, focus, editing: false, replying: "" };
if (review !== state.opened || (focus && !v.sections[focus])) return false;
panel = { v, focus, onRead, editing: false, replying: "" };
const body = el(`<div class="answers"></div>`);
const m = openModal("Answers to your comments", body, "wide");
if (navigation) m.querySelector(".modal-head").insertBefore(navigation, m.querySelector(".modal-head > button"));
m.onkey = answersKey;
render();
if (focus) onRead(focus, v.sections[focus]);
return true;
}

export function hasAnswerDraft() {
const textarea = document.querySelector(".answers textarea");
return textarea && (panel.editing ? textarea.value !== panel.v.text : !!textarea.value.trim());
}

function render() {
Expand Down Expand Up @@ -67,7 +78,10 @@ function render() {
let at = 0;
for (const [id, start] of order) {
if (start > at) doc.append(el(`<div>${md(v.text.slice(at, start))}</div>`));
const sec = el(`<section class="ans-sec" data-id="${esc(id)}">${md(v.sections[id])}</section>`);
const sec = el(`<section class="ans-sec" tabindex="0" data-id="${esc(id)}">${md(v.sections[id])}</section>`);
const read = () => panel.onRead(id, v.sections[id]);
sec.addEventListener("click", read);
sec.addEventListener("focus", read);
const comment = state.view?.reader?.comments.find((c) => c.id === id);
const bar = el(`<div class="ans-bar">${comment ? `<span class="badge">${comment.resolved ? "resolved" : "open"}</span>` : ""}<span class="spacer"></span></div>`);
const reply = el(`<button class="small">Reply</button>`);
Expand All @@ -87,7 +101,10 @@ function render() {
const target = panel.focus && box.querySelector(`.ans-sec[data-id="${CSS.escape(panel.focus)}"]`);
if (target) {
target.classList.add("focus");
requestAnimationFrame(() => target.scrollIntoView({ block: "start" }));
requestAnimationFrame(() => {
target.focus({ preventScroll: true });
target.scrollIntoView({ block: "start" });
});
panel.focus = "";
}
}
Expand Down Expand Up @@ -157,8 +174,11 @@ function answersKey(e) {
// is editing or replying.
Events.On("review:changed", async () => {
if (!panel || !document.querySelector(".modal .answers") || panel.editing || panel.replying) return;
const opened = state.opened, current = panel;
try {
panel.v = await api("Reviews.Answers");
const v = await api("Reviews.Answers");
if (state.opened !== opened || panel !== current || panel.editing || panel.replying) return;
panel.v = v;
render();
} catch {}
});
Expand Down
27 changes: 19 additions & 8 deletions cmd/margin-gui/assets/app.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Events } from "/wails/runtime.js";
import { api, $, state, hooks, toast, errText, tail, openModal, closeModal, applyTheme, setThemeMode, followsSystem } from "./core.js";
import { openReview, openReviewFile, reviewKey, renderReview, sendComments, sendFixes } from "./review.js";
import { loadWorkspace, loadRecent, renderSide, addFolder, selectWorktree, homeKey, backToReview, syncSideButtons, openSwitcher, switcherOpen, openSettings, navState } from "./nav.js";
import { openReview, openReviewFile, reviewKey, renderReview, renderWalkthrough, sendComments, sendFixes } from "./review.js";
import { loadWorkspace, loadRecent, renderSide, addFolder, selectWorktree, refreshWorktree, homeKey, backToReview, syncSideButtons, openSwitcher, switcherOpen, openSettings, navState } from "./nav.js";

// Agent terminal

Expand Down Expand Up @@ -75,7 +75,9 @@ async function refreshAgent(opened) {
]);
if (state.opened !== opened || request !== agentStatusRequest) return null;
opened.agent = saved ?? {};
opened.walkAgentLive = live;
setAgentLive(live);
renderWalkthrough();
$("#agent-btn").disabled = !!(opened.launching || opened.linking);
return live;
}
Expand Down Expand Up @@ -122,6 +124,9 @@ async function startAgent(opened, action, automatic = false) {
if (opened.launching) return;
const button = $("#agent-btn");
opened.launching = true;
opened.launchingWalkthrough = action === "Start" || action === "Resume" && opened.agent?.walkPreparing;
opened.walkFailure = false;
renderWalkthrough();
button.disabled = true;
// A launch changes the process status while the terminal may still receive earlier events.
++agentStatusRequest;
Expand All @@ -138,12 +143,17 @@ async function startAgent(opened, action, automatic = false) {
if (await refreshAgent(opened) && !automatic) term.focus();
} catch (e) {
if (state.opened === opened) {
opened.walkFailure = true;
await refreshAgent(opened).catch(() => {});
toast(errText(e), true);
}
} finally {
opened.launching = false;
if (state.opened === opened) button.disabled = false;
opened.launchingWalkthrough = false;
if (state.opened === opened) {
button.disabled = false;
renderWalkthrough();
}
}
}

Expand Down Expand Up @@ -227,6 +237,7 @@ function togglePicker() {

function showReviewer(loading = false) {
if (loading) {
$("#walkthrough").classList.add("hidden");
$("#agent-btn").disabled = true;
$("#agent-link").classList.add("hidden");
}
Expand Down Expand Up @@ -254,7 +265,6 @@ async function crumbBack() {
if (!o) return;
const w = state.worktree;
if (w && (w.path === o.repo || w.repo?.worktrees?.some((x) => x.path === o.repo))) {
$("#workspace").classList.remove("focus");
return selectWorktree(w, w.repo);
}
const nav = navState();
Expand Down Expand Up @@ -295,7 +305,7 @@ async function pickReviewFile() {

document.addEventListener("keydown", (e) => {
if (switcherOpen()) return;
if (document.activeElement?.closest?.(".cm-editor")) return;
const inEditor = document.activeElement?.closest?.(".cm-editor");
const inTerm = document.activeElement?.closest?.("#terminal");
const inInput = ["INPUT", "TEXTAREA", "SELECT"].includes(document.activeElement?.tagName) && !inTerm;
if (inTerm) {
Expand All @@ -305,15 +315,16 @@ document.addEventListener("keydown", (e) => {
}
return;
}
if ((e.ctrlKey || e.metaKey) && (e.key === "k" || e.key === "p")) {
if (!inEditor && (e.ctrlKey || e.metaKey) && (e.key === "k" || e.key === "p")) {
e.preventDefault();
return openSwitcher();
}
if ((e.ctrlKey || e.metaKey) && e.key === ",") {
e.preventDefault();
return openSettings();
}
if (inInput) return;
if (inEditor || inInput) return;
if ((e.key === "Enter" || e.key === " ") && e.target.closest?.("button, summary")) return;
if (!e.ctrlKey && !e.metaKey && !e.altKey) {
if (e.key === "\\") {
e.preventDefault();
Expand Down Expand Up @@ -344,7 +355,7 @@ $("#show-side").onclick = togglePicker;
$("#toggle-picker").onclick = togglePicker;
$("#crumb").onclick = crumbBack;
$("#back-review").onclick = backToReview;
$("#wt-refresh").onclick = () => state.worktree && selectWorktree(state.worktree, state.worktree.repo);
$("#wt-refresh").onclick = refreshWorktree;
$("#agent-btn").onclick = toggleAgent;
$("#agent-link").onclick = linkAgent;
$("#send-btn").onclick = sendComments;
Expand Down
4 changes: 1 addition & 3 deletions cmd/margin-gui/assets/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@ export const state = {
step: 0,
nudged: false,
more: false,
filter: 0,
showGhosts: true,
filter: "All notes",
split: false,
showNotes: true,
unfold: false,
expand: {},
whole: {},
Expand Down
Loading
Loading