Skip to content

feat(pager): emit OSC 1717 diff line metadata for LazyGit staging - #1341

Open
moh682 wants to merge 2 commits into
modem-dev:mainfrom
moh682:feat/osc-1717-static-pager
Open

moh682 wants to merge 2 commits into
modem-dev:mainfrom
moh682:feat/osc-1717-static-pager

Conversation

@moh682

@moh682 moh682 commented Nov 18, 2026

Copy link
Copy Markdown

Closes #1340 (draft until the proposal there is agreed).

Problem

LazyGit 0.66 stages hunks and lines straight from its diff panel. It keeps a diff renderer's output while staging only when the renderer tags rows with OSC 1717 diff line metadata; otherwise it swaps in plain git diff. So with hunk pager as LazyGit's renderer, pressing Enter on a file dropped Hunk's rendering.

Approach

  • core/process/diffLineMetadata.ts negotiates the version from OSC1717 (a V1[,V2,…] set) and formats the handshake and per-row records. Nothing is emitted without a shared version, so output elsewhere is byte-for-byte unchanged.
  • app/startup.ts: a negotiating host always gets the static pager, and the handshake is written even for non-diff or empty stdin. LazyGit probes support by running the pager on empty stdin with stdout captured, which previously took the plain-text path.
  • ui/staticDiffPager.ts tags rows using the existing row model: f on the file header, h with the hunk's first new-file line, c/a/d on content rows. Deletions take their new-file position from Pierre's hunk blocks per §5.3, so consecutive deletions share a new line. Split rows carry one record per column; blank halves, collapsed gaps and expansion rows stay untagged. The handshake also precedes the raw-patch fallback.
  • Docs: a LazyGit section in the Git pager page.

Non-goals: the interactive UI and other headless commands are untouched. Paths with control characters get no record rather than a broken escape sequence.

It lives in core because it is the static pager's output contract with the host, not an opt-in workflow.

Verification

macOS (arm64) only; Linux and Windows not tested.

  • bun run typecheck, bun run lint, bun run deps:check, bun run format:check: pass.
  • New tests: core/process/diffLineMetadata.test.ts, plus cases in ui/staticDiffPager.test.ts (unified, split, deleted file at new line 0, handshake on fallback, no output without negotiation) and app/startup.test.ts (negotiated patch, empty-stdin probe, no shared version). 68/68 pass across those files.
  • bun run test: 5897 pass, 11 fail. The failures are in extensions/installedPackageResolution, extensions/hostRuntimeModules, core/watch/observer.fs, app/documents/filesystemSource.observe, session/broker/brokerLauncher and ui/AppHost.reload. Running those files on unmodified main on the same machine gives 75 pass / 12 fail with the same tests failing.
  • Not run: bun run test:integration and bun run test:tty-smoke. Static pager output is not a PTY or interactive surface; happy to run them if you want them for this change.
  • Manual end-to-end with LazyGit 0.66.3 pointed at this branch: the staged/unstaged panels keep Hunk's rendering after Enter, and space on the first change stages exactly that block (-two -three +TWO) while +six stays unstaged.

Decoded output for a two-deletions-one-addition change:

«1»«1;f;;;a.txt»a.txt modified +2 -2
«1;h;1;;a.txt»▌@@ -1,5 +1,5 @@
«1;c;1;;a.txt»▌1 1    one
«1;d;2;2;a.txt»▌2   -  two
«1;d;2;3;a.txt»▌3   -  three
«1;a;2;;a.txt»▌  2 +  TWO

Limitations

  • With --no-hunk-headers there is no hunk header row, so no h record is emitted.
  • Combined (diff --cc) diffs get records from the same row model; I did not verify LazyGit's staging behaviour on them.

🤖 Generated with Claude Code

Omar Salah Hariri and others added 2 commits November 18, 2026 14:16
LazyGit 0.66 stages from its diff panel and keeps a renderer's output only
when each row carries OSC 1717 metadata; otherwise it falls back to plain
git diff. When the host sets OSC1717 to a version set including V1, the
pager always renders statically, writes the handshake first (also for the
empty-stdin probe), and tags file headers, hunk headers, and content rows,
one record per split column. Without the variable, output is unchanged.

Refs modem-dev#1340

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@moh682
moh682 marked this pull request as ready for review November 19, 2026 12:29
@greptile-apps

greptile-apps Bot commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

This PR does not match any of the 1 configured review trigger rule.

This branch has not been deployed

No deployments
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.

Emit OSC 1717 diff line metadata in the static pager for LazyGit staging

1 participant