Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
25 changes: 25 additions & 0 deletions apps/desktop/e2e/review.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { test, expect, type ElectronApplication, type Page } from "@playwright/test";
import { execFileSync } from "node:child_process";
import fs from "node:fs";
import path from "node:path";
import { launch, seedHome, tid, items } from "./support";
Expand Down Expand Up @@ -67,6 +68,30 @@ test("changed files can be selected with the keyboard", async () => {
await expect(file).toHaveAttribute("aria-pressed", "true");
});

test("an untracked link to a directory and a nested repository open without a diff error", async () => {
fs.mkdirSync(path.join(repo, "target"));
fs.writeFileSync(path.join(repo, "target", "inside.txt"), "inside\n");
fs.symlinkSync("target", path.join(repo, "dir-link"));
const nested = path.join(repo, "vendor", "lib");
fs.mkdirSync(nested, { recursive: true });
execFileSync("git", ["init", "-q"], { cwd: nested });
fs.writeFileSync(path.join(nested, "f.txt"), "x\n");
execFileSync("git", ["add", "."], { cwd: nested });
execFileSync("git", ["-c", "commit.gpgsign=false", "-c", "user.name=test", "-c", "[email protected]", "commit", "-qm", "x"], { cwd: nested });
await tid(page, "changes-refresh").click();

await page.getByRole("button", { name: "View diff for dir-link", exact: true }).click();
await expect(tid(page, "diff").locator('[data-line="add"]')).toHaveText(["1target"]);
await expect(tid(page, "changes-diff")).toContainText("+1");
await expect(tid(page, "changes-diff-error")).toHaveCount(0);

const row = page.locator('[data-testid="changes-file"][data-path="vendor/lib/"]');
await expect(tid(row, "changes-file-path")).toHaveText("lib");
await page.getByRole("button", { name: "View diff for vendor/lib/", exact: true }).click();
await expect(tid(page, "changes-diff")).toContainText("No textual diff.");
await expect(tid(page, "changes-diff-error")).toHaveCount(0);
});

test("Enter during IME composition keeps the unsent message", async () => {
const input = tid(page, "composer-input");
await input.fill("日本語");
Expand Down
27 changes: 23 additions & 4 deletions apps/desktop/src/main/engine/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ export async function status(cwd: string): Promise<ChangesSnapshot> {
if (f.code === "??") {
const abs = path.join(cwd, f.path);
try {
f.additions = countLines(fs.readFileSync(abs, "utf8"));
// A link's content is its target, one line, whatever it points at.
f.additions = fs.lstatSync(abs).isSymbolicLink() ? 1 : countLines(fs.readFileSync(abs, "utf8"));
} catch {
/* binary or unreadable */
}
Expand Down Expand Up @@ -151,6 +152,26 @@ function diffOutput(result: { stdout: string; stderr: string; code: number }, no
return result.stdout;
}

/**
* An untracked path as a pure addition. git cannot compare /dev/null with a directory, and it sees
* one through a symlink to a directory or at a nested repository, which status lists as `dir/`.
* A nested repository has no text to show. The link gets the diff git prints for any other link.
*/
async function untrackedDiff(root: string, repoRel: string, context: string[]): Promise<string> {
const abs = path.join(root, repoRel);
let directory = false;
try {
directory = fs.statSync(abs).isDirectory();
} catch { /* A dangling or looping link is one git can show. */ }
if (!directory) return diffOutput(await git(root, ["--literal-pathspecs", "diff", ...context, "--no-index", "--", "/dev/null", repoRel]), true);
if (!fs.lstatSync(abs).isSymbolicLink()) return "";
const lines = fs.readlinkSync(abs).split("\n");
return [
`diff --git a/${repoRel} b/${repoRel}`, "new file mode 120000", "--- /dev/null", `+++ b/${repoRel}${repoRel.includes(" ") ? "\t" : ""}`,
`@@ -0,0 +1${lines.length > 1 ? `,${lines.length}` : ""} @@`, ...lines.map((line) => `+${line}`), "\\ No newline at end of file", "",
].join("\n");
}

/** Unified diff for one path; untracked files are rendered as pure additions. */
export async function diff(cwd: string, rel: string, original?: string, fullContext = false): Promise<string> {
const context = fullContext ? ["--unified=100000"] : [];
Expand All @@ -171,9 +192,7 @@ export async function diff(cwd: string, rel: string, original?: string, fullCont
}
}

if (code === "??") {
return diffOutput(await git(root, ["--literal-pathspecs", "diff", ...context, "--no-index", "--", "/dev/null", repoRel]), true);
}
if (code === "??") return untrackedDiff(root, repoRel, context);

const committed = await hasCommits(root);
const target = committed ? "HEAD" : "--cached";
Expand Down
8 changes: 6 additions & 2 deletions apps/desktop/src/renderer/components/ChangesPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import { ErrorNotice } from "./ui/ErrorNotice";
interface Props { visible: boolean; thread: Thread; changes: ChangesSnapshot | null; onRefresh: () => void; onRevert: (path: string) => void }
const compactCount = new Intl.NumberFormat("en", { notation: "compact", maximumFractionDigits: 1 });

/** Git lists a nested repository as `dir/`; its row goes by that directory's name, in its parent's group. */
const rowPath = (file: string) => file.replace(/\/$/, "");

/** Review occupies a workspace tab; the diff and its file tree scroll independently. */
export function ChangesPanel({ visible, thread, changes, onRefresh, onRevert }: Props) {
const [selection, setSelection] = useState<string | null>(null);
Expand Down Expand Up @@ -46,7 +49,8 @@ export function ChangesPanel({ visible, thread, changes, onRefresh, onRevert }:
const paths = (changes?.files ?? []).filter((f) => f.path.toLowerCase().includes(filter.toLowerCase())).sort((a, b) => Number(a.code === "??") - Number(b.code === "??") || a.path.localeCompare(b.path));
const groups = new Map<string, typeof paths>();
for (const f of paths) {
const folder = f.path.includes("/") ? f.path.slice(0, f.path.lastIndexOf("/")) : "";
const name = rowPath(f.path);
const folder = name.includes("/") ? name.slice(0, name.lastIndexOf("/")) : "";
groups.set(folder, [...(groups.get(folder) ?? []), f]);
}
return <section className="review-panel" data-testid="changes-panel" aria-label="Review changes">
Expand Down Expand Up @@ -85,7 +89,7 @@ export function ChangesPanel({ visible, thread, changes, onRefresh, onRevert }:
{[...groups].map(([folder, files]) => <FileGroup key={folder} folder={folder}>
{files.map((f) => <div key={f.path} className={`review-file${file === f.path ? " selected" : ""}`} data-testid="changes-file" data-path={f.path} aria-current={file === f.path ? "true" : undefined}>
<button className="review-file-select" aria-label={`View diff for ${f.path}`} aria-pressed={file === f.path} onClick={() => setSelection(f.path)}>
<FileIcon path={f.path} /><span data-testid="changes-file-path" title={f.path}>{f.path.split("/").at(-1)}</span><span className={`review-status ${f.code === "??" ? "add" : "modified"}`}>{f.code === "??" ? "U" : f.code.includes("D") ? "D" : "▪"}</span>
<FileIcon path={f.path} /><span data-testid="changes-file-path" title={f.path}>{rowPath(f.path).split("/").at(-1)}</span><span className={`review-status ${f.code === "??" ? "add" : "modified"}`}>{f.code === "??" ? "U" : f.code.includes("D") ? "D" : "▪"}</span>
</button>
<button className="review-revert" data-testid="changes-revert" aria-label={`Discard changes to ${f.path}`} title="Discard changes to this file" onClick={() => onRevert(f.path)}>↶</button>
</div>)}
Expand Down
70 changes: 70 additions & 0 deletions apps/desktop/test/git.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,76 @@ test("status/diff/revert over tracked, untracked and deleted files", async () =>
await assert.rejects(gitx.revert(repo, "../outside"), /outside the workspace/);
});

test("an untracked symlink to a directory diffs as a new link, the way git shows any other link", async () => {
const repo = gitRepo();
fs.mkdirSync(path.join(repo, "target"));
fs.writeFileSync(path.join(repo, "target", "inside.txt"), "one\ntwo\nthree\n");
fs.symlinkSync("target", path.join(repo, "to dir"));
const shown = await gitx.diff(repo, "to dir");
assert.equal(shown, "diff --git a/to dir b/to dir\nnew file mode 120000\n--- /dev/null\n+++ b/to dir\t\n@@ -0,0 +1 @@\n+target\n\\ No newline at end of file\n");
assert.equal(await gitx.diff(repo, "to dir", undefined, true), shown, "the expanded view has no other lines to add");
assert.doesNotMatch(shown, /inside\.txt|one/, "the link is shown, not what it points at");

// With the target gone git can diff the same link itself, which keeps the two from drifting apart.
fs.rmSync(path.join(repo, "target"), { recursive: true });
assert.equal(shown, (await gitx.diff(repo, "to dir")).replace(/^index .*\n/m, ""));
});

test("the other untracked links keep git's own diff, and the list counts every link as one line", async () => {
const repo = gitRepo();
fs.writeFileSync(path.join(repo, "real.txt"), "one\ntwo\nthree\n");
execFileSync("git", ["add", "real.txt"], { cwd: repo });
fs.mkdirSync(path.join(repo, "target"));
fs.writeFileSync(path.join(repo, "target", ".keep"), "");
execFileSync("git", ["add", "target"], { cwd: repo });
execFileSync("git", ["-c", "commit.gpgsign=false", "-c", "user.name=test", "-c", "[email protected]", "commit", "-qm", "files"], { cwd: repo });
fs.symlinkSync("real.txt", path.join(repo, "to-file"));
fs.symlinkSync("target", path.join(repo, "to-dir"));
fs.symlinkSync("nowhere", path.join(repo, "dangling"));
fs.symlinkSync("loop", path.join(repo, "loop"));
for (const [name, target] of [["to-file", "real.txt"], ["dangling", "nowhere"], ["loop", "loop"], ["to-dir", "target"]] as const) {
const shown = await gitx.diff(repo, name);
assert.match(shown, /^new file mode 120000$/m, name);
assert.ok(shown.endsWith(`@@ -0,0 +1 @@\n+${target}\n\\ No newline at end of file\n`), `${name}: ${shown}`);
}
assert.deepEqual((await gitx.status(repo)).files.map((f) => [f.path, f.additions]), [["dangling", 1], ["loop", 1], ["to-dir", 1], ["to-file", 1]]);
});

test("an untracked symlink to a directory diffs from a project inside the repository", async () => {
const repo = gitRepo();
fs.mkdirSync(path.join(repo, "app", "target"), { recursive: true });
fs.symlinkSync("target", path.join(repo, "app", "link"));
const project = path.join(repo, "app");
assert.deepEqual((await gitx.status(project)).files.map((f) => f.path), ["link"]);
const shown = await gitx.diff(project, "link");
assert.match(shown, /^\+\+\+ b\/app\/link$/m);
assert.match(shown, /^\+target$/m);
});

test("an untracked nested repository has no diff to show and does not fail", async () => {
const repo = gitRepo();
const nested = path.join(repo, "vendor", "lib");
fs.mkdirSync(nested, { recursive: true });
await gitx.git(nested, ["init", "-q", "-b", "main"]);
fs.writeFileSync(path.join(nested, "f.txt"), "x\n");
await gitx.git(nested, ["add", "f.txt"]);
await gitx.git(nested, ["-c", "commit.gpgsign=false", "-c", "user.name=test", "-c", "[email protected]", "commit", "-qm", "x"]);
assert.deepEqual((await gitx.status(repo)).files.map((f) => [f.path, f.code]), [["vendor/lib/", "??"]]);
assert.equal(await gitx.diff(repo, "vendor/lib/"), "");
await gitx.revert(repo, "vendor/lib/");
assert.equal(fs.readFileSync(path.join(nested, "f.txt"), "utf8"), "x\n", "discarding must never delete another repository");
});

test("discarding an untracked symlink to a directory removes the link and keeps what it points at", async () => {
const repo = gitRepo();
const outside = tmpdir("modex-link-target-");
fs.writeFileSync(path.join(outside, "precious.txt"), "keep\n");
fs.symlinkSync(outside, path.join(repo, "link"));
await gitx.revert(repo, "link");
assert.equal(fs.lstatSync(path.join(repo, "link"), { throwIfNoEntry: false }), undefined);
assert.equal(fs.readFileSync(path.join(outside, "precious.txt"), "utf8"), "keep\n");
});

test("discarding files before the first commit clears intent-to-add and staged edits", async () => {
const repo = tmpdir("modex-unborn-repo-");
await gitx.git(repo, ["init", "-q", "-b", "main"]);
Expand Down
2 changes: 2 additions & 0 deletions docs/status.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ Also unreleased, since that summary: #467 (`8a28df3`) adds the Claude account po

Automatic credit conservation adds account-bound CLI quota admission, configurable 20% allowance / 10 provider-credit-unit thresholds, economical suitable routes and explicit standard speed during conservation. Every automatic model/account replacement rechecks quota, supported effort and the task capability floor; enabled Claude rotation can skip exhausted fresh-thread accounts before coding. Conservation also avoids a separate paid title-generation turn. Local qualification passes build/typechecks, 216 focused cases, 2,530 full unit cases (36 explicit skips), 518 desktop UI cases (11 explicit skips) and seven site UI cases; protected hosted CI and merge-queue acceptance are separate delivery gates. Exact price savings, live coding/billing and installed-release acceptance remain unqualified. [Delivery audit](reviews/2026-11-12-credit-conservation-delivery.md), [behavior](auto-routing.md#automatic-credit-conservation).

Also unreleased: the Changes panel opens an untracked symlink to a directory as a new link, and a nested repository as "No textual diff.", instead of failing with `Could not access '<path>/null'`.

## v0.4.1 publication and remaining acceptance

- **v0.4.1 published (2026-10-31).** Signed tag `v0.4.1` names protected merge `6a97d23`. Release run `41163487821` passed signed packaged E2E (479 desktop passed, 4 skipped; 7 site passed), three native updater scenarios, Windows/Linux checks and artifact attachment. All five downloaded installers match the release manifest; macOS signature, Gatekeeper and stapler checks passed. The initial download-failure job stopped before updater execution because its fixture manifest was missing; one retry passed on the unchanged candidate. Original failures and acceptance limits remain in the [publication review](reviews/2026-10-30-v0.4.1-release-review.md#published--2026-10-31-utc).
Expand Down
Loading