Skip to content

Pierre diffs update - #24

Closed
ShpetimA wants to merge 3 commits into
masterfrom
pierre-diffs-update
Closed

ShpetimA wants to merge 3 commits into
masterfrom
pierre-diffs-update

Conversation

@ShpetimA

Copy link
Copy Markdown
Owner

No description provided.

@ShpetimA

Copy link
Copy Markdown
Owner Author

/review

@orc-review orc-review 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.

This PR is a large refactor (+3413/-934, 40 files) that migrates the Changes and Pull-Request diff panes from the single-file DiffWorkspace onto a new multi-file @pierre/diffs CodeView (via ChangesCodeViewDiffPane and PullRequestCodeViewDiffPane), replaces single-document LSP syncing with useCurrentLspDocuments (plural), adds multi-file diagnostics + a diagnostics summary banner, and introduces a git command error-log feature with a RepoActionErrorDialog. The direction is sound and the new panes are well-structured, but there are several issues that should be addressed before merge.

Highest priority: (1) patches/@pierre__diffs@1.2.4.patch is added but never wired up — there is no pnpm.patchedDependencies entry in the root package.json, and the filename version (1.2.4) does not match the pinned @pierre/diffs@1.2.7. The patch fixes VirtualizedFileDiff forceRender behavior in advanced mode; if that fix is required for the new CodeView to render correctly, it is silently missing. (2) The root package.json now declares electron: ^42.3.0 as a runtime dependency while apps/desktop pins electron: 41.0.2 in devDependencies — two divergent Electron versions in the workspace, and a runtime dep on a private root package that has no runtime.

Secondary: the new git error-log writer stores full git stdout/stderr (which can contain file contents/secrets) in a shared, world-readable tmpdir using predictable filenames with default permissions and no cleanup, and a module-level singleton that any concurrent failed git command overwrites — so the dialog can surface the wrong command's output. Test coverage is light for the volume of new logic (no tests for git error logging, buildRepoActionError, useMultiDiffDiagnostics, useParsedMultiFileDiffs, or LspDiagnosticsSummaryNotice).

General comments

  • Test coverage is thin for the amount of new logic. The only behavioral test added is LspSymbolPeek scroll positioning. There are no tests for: writeGitCommandErrorLog/getLastGitCommandErrorLogPath (electron), buildRepoActionError/firstErrorLine/stripAnsi (actions.ts), useParsedMultiFileDiffs cache/microtask behavior, useMultiDiffDiagnostics re-paint effect, LspDiagnosticsSummaryNotice pending/unavailable counting, or buildMultiDiffScrollbarMarkers/buildDiffScrollbarMarkers math. Given these drive rendering and git-failure UX, unit tests for the pure helpers (marker math, ANSI/error-line stripping, diagnostics summary counts) would be high-value and low-cost.
  • Behavior change worth flagging: PullRequestFiles.tsx/PullRequestReviewFilesScreen.tsx drop the per-file useThrottledDiffSelection/useGetBranchFileVersionsQuery (single-file) flow in favor of eagerly subscribing to branch-file-version queries for ALL files via useEnsureBranchFileVersionQueries (one RTK Query subscription per file). For PRs with many changed files this is a meaningful increase in concurrent git IPC + subscriptions; verify that scales acceptably and that unsubscriptions on target changes are timely (they look correct — keyed off targetKey).
  • useCurrentLspDocuments now syncs an LSP document for every file with available newFile contents across all multi-diff targets, not just the active file. On large diffs this opens many LSP documents simultaneously. Confirm the LSP session manager tolerates this and that it's the intended behavior (vs. syncing only the active + visible items).
  • .vite-hooks/pre-commit now runs pnpm precommit (= pnpm lint && pnpm fmt:check), and a new precommit:fix script exists — fine. Just note the pre-commit hook no longer runs typecheck/tests, matching the prior behavior, so CI is the gate for those.

Comment thread package.json
"check": "pnpm lint && pnpm typecheck && pnpm test && pnpm fmt:check"
},
"dependencies": {
"electron": "^42.3.0"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Two concerns here:

  1. electron is added as a runtime dependency of the root package, but the root package is "private": true with no main/runtime — Electron belongs in devDependencies (or only in apps/desktop).
  2. This pins ^42.3.0 while apps/desktop/package.json still pins "electron": "41.0.2". The workspace now resolves two different Electron majors, which can lead to the wrong binary being used by tooling/electron-builder. Was this intended? If the goal was just to allow onlyBuiltDependencies to take effect, it should be a devDependency matching the desktop workspace version.

Comment thread package.json
},
"packageManager": "pnpm@10.28.0"
"packageManager": "pnpm@10.28.0",
"pnpm": {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

There is a patches/@pierre__diffs@1.2.4.patch in this PR but no pnpm.patchedDependencies field anywhere (verified: no matches in the repo). pnpm will not apply patches from patches/ without this config. Additionally the patch filename targets 1.2.4 while @pierre/diffs is pinned to 1.2.7, so even with the config the version qualifier wouldn't match. The patch edits VirtualizedFileDiff to force-render in advanced mode — if that change is needed for the new CodeView rendering to behave, the fix is currently dead. Either add the patchedDependencies entry keyed to 1.2.7 (and regenerate with pnpm patch) or drop the file if it's no longer needed.

const GIT_TIMEOUT_MS = 30_000;
const GIT_WRITE_RETRY_COUNT = 3;
const GIT_WRITE_RETRY_DELAY_MS = 120;
const GIT_ERROR_LOG_DIR = path.join(os.tmpdir(), "open-warden-git-logs");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

os.tmpdir() resolves to /tmp on many Linux setups, which is world-readable. The log content includes full git stdout/stderr (repo path, command, and potentially file contents/diff text), so other local users could read it. Prefer a 0o700 directory under the user's data/cache dir (e.g. app.getPath('temp')/userData), or fs.mkdir(..., { mode: 0o700 }) and write with mode: 0o600. There's also no eviction/cleanup, so logs accumulate for the process lifetime.

}) {
try {
await fs.mkdir(GIT_ERROR_LOG_DIR, { recursive: true });
const logPath = path.join(GIT_ERROR_LOG_DIR, `git-${Date.now()}-${process.pid}.log`);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The filename git-${Date.now()}-${process.pid}.log is predictable, and fs.writeFile follows existing entries — a pre-placed symlink at that path (classic /tmp symlink attack) would let another user overwrite an arbitrary file the app user can write. Use a random suffix (crypto.randomUUID()) and write with flag: 'wx' (exclusive create) plus a restrictive mode to mitigate both guessing and symlink races.

const GIT_WRITE_RETRY_DELAY_MS = 120;
const GIT_ERROR_LOG_DIR = path.join(os.tmpdir(), "open-warden-git-logs");

let lastGitCommandErrorLog: { repoPath: string; path: string } | null = null;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

lastGitCommandErrorLog is a process-wide singleton overwritten by every failed git command (the runGit catch on line 165 calls writeGitCommandErrorLog unconditionally). If any other git operation fails between a commit failure and the getLastGitCommandErrorLogPath(repoPath) lookup in toGitErrorResult (e.g. a concurrent snapshot poll, stage, or discard — all of which also go through runGit), the RepoActionErrorDialog will display the wrong command's output. Only repoPath is filtered, not the args/command identity. Consider returning the logPath on the thrown GitCommandError (it already carries it) and reading it from the error instead of via this singleton lookup.

return { data: await commitStaged(repoPath, message) };
} catch (error) {
return { error: toErrorResult(error) };
return { error: await toGitErrorResult(error, repoPath) };

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Only commitStaged uses toGitErrorResult (with the log path); discardFile(s)/All, stageAll, unstageAll, and hunk operations still use plain toErrorResult. That may be intentional (commit is where verbose pre-commit output matters), but runRepoAction/buildRepoActionError apply to all actions, so non-commit failures will always show logPath: null and no "Open Git Log" button. Worth confirming this asymmetry is deliberate.

};

type FileVersionData = {
oldFile: DiffFile | null;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The effect closes over requests but lists only [requestKey] as a dep. It works today because requestKey is derived from requests, but when every request is already cached you still schedule a queueMicrotask(forceUpdate) on each requestKey change — that's an extra render per cache change. Consider gating the microtask on whether forceUpdate was already triggered for this key, or just unconditionally calling forceUpdate() after the loadParsedDiff settle. Not a correctness bug, just a note.

const message = error instanceof Error ? error.message : String(error);
toast.error(`Failed to ${repoActionLabel(action)}: ${message}`);
const actionError = buildRepoActionError(action, error);
dispatch(setRepoActionError(actionError));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

runRepoAction now both shows a toast and dispatches setRepoActionError (rendered as a modal RepoActionErrorDialog). For commit failures the user gets two simultaneous notifications for the same error. If the modal is the intended primary surface, consider dropping the toast (or vice versa) to avoid duplicate/noisy feedback.

@@ -0,0 +1,178 @@
import { useCallback, type PointerEvent, type RefObject } from "react";

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This duplicates the DiffScrollbarMarkers component that still lives in DiffViewer.tsx (the one used by DiffWorkspace). The two have already diverged slightly (this new one is the exported, multi-diff-aware version). Consider reusing one implementation to avoid future drift, or renaming to make the split explicit.

Comment on lines +39 to +59
hunk.hunkContent.forEach((content, contentIndex) => {
if (content.type === "context") {
splitOffset += content.lines;
unifiedOffset += content.lines;
return;
}

const splitStart = hunk.splitLineStart + splitOffset;
const unifiedStart = hunk.unifiedLineStart + unifiedOffset;
const splitRows = Math.max(content.additions, content.deletions);

if (content.deletions > 0) {
const start = diffStyle === "split" ? splitStart : unifiedStart;
const rows = diffStyle === "split" ? splitRows : content.deletions;
markers.push({
key: `${hunkIndex}-${contentIndex}-deletions`,
type: "deletion",
top: clampPercent((start / totalLines) * 100),
height: clampPercent((Math.max(1, rows) / totalLines) * 100),
});
}

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

/orc What is this


if (content.additions > 0) {
const start = diffStyle === "split" ? splitStart : unifiedStart + content.deletions;
const rows = diffStyle === "split" ? splitRows : content.additions;

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

/review

@ShpetimA

Copy link
Copy Markdown
Owner Author

/orc what is the deal with this pr

@orc-review

orc-review Bot commented Jun 18, 2026

Copy link
Copy Markdown

This is a "Pierre diffs update" PR with an empty description, but the diff is large (~40 files). It does three related things:

1. Upgrades @pierre/diffs 1.1.15 → 1.2.7 and adopts the new CodeView multi-file API

  • Adds patches/@pierre__diffs@1.2.4.patch (note: patch filename says 1.2.4 but package.json pins 1.2.7 — worth flagging) forcing re-render in advanced mode.
  • Replaces the per-file DiffWorkspace with two new multi-file panes that render all files in one virtualized CodeView:
    • apps/desktop/src/features/source-control/components/ChangesCodeViewDiffPane.tsx (Changes screen)
    • apps/desktop/src/features/pull-requests/components/PullRequestCodeViewDiffPane.tsx (PR review + preview)
  • Shared infrastructure: useMultiDiffCodeViewOptions.ts, useMultiDiffDiagnostics.ts, DiffScrollbarMarkers.tsx. Deletes the old single-file useDiffDiagnostics.ts hooks.

2. Better git error reporting

  • New desktop API getLastGitCommandErrorLogPath; runGit now writes full command/stdout/stderr to $TMPDIR/open-warden-git-logs/... and attaches logPath to GitCommandError.
  • New RepoActionErrorDialog.tsx with "Show Command Output" + "Open Git Log" buttons, driven by repoActionError in sourceControlSlice. Replaces plain toast.error in runRepoAction (apps/desktop/src/features/source-control/actions.ts:499).

3. LSP + UX polish that comes with multi-file view

  • useCurrentLspDocument → useCurrentLspDocuments (syncs diagnostics for every visible file).
  • New LspDiagnosticsSummaryNotice aggregating "N problems across M files" with copy-all.
  • Per-line diagnostic styling via data-lsp-diagnostic-line attribute.
  • LspSymbolPeek now anchors against a layer marker so it positions correctly inside the scrolled CodeView (new test covers scrolled-viewport case).
  • Comment composer split into selectedRange vs composerRange so click-drag selection doesn't pop the composer until mouse-up.

Loose ends worth questioning

  • Root package.json adds electron: ^42.3.0 as a dependency (not devDependency) plus pnpm.onlyBuiltDependencies: ["electron"] — looks like it should be a devDep.
  • The patch file is named @pierre__diffs@1.2.4.patch while package.json pins 1.2.7; pnpm applies patches by name-glob so it may still match, but the version mismatch is suspicious.

@ShpetimA

Copy link
Copy Markdown
Owner Author

/review

1 similar comment
@ShpetimA

Copy link
Copy Markdown
Owner Author

/review

@orc-review orc-review 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.

LGTM with one bug: LSP document synchronization may fail to re-sync documents after LSP server restart

Comment on lines +38 to +40
for (const [key, nextDocument] of nextDocuments) {
const currentDocument = activeDocumentsRef.current.get(key);
if (currentDocument?.text === nextDocument.text) continue;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: Skipping syncLspDocument when text hasn't unchanged prevents re-syncing after LSP server restart. If the LSP server crashes and restarts while documents are open, they won't be re-synced because their text content hasn't changed. This causes the LSP server to operate on stale or missing document state. The backend should handle deduplication, so always call syncLspDocument for active documents.

@ShpetimA ShpetimA closed this Jun 20, 2026
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