Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
fix(agents): expand small diffs by default (#8995)
Wolf Mermelsteinc9d0d2063dca
diff --git a/apps/web/AGENTS.md b/apps/web/AGENTS.mdindex 251110efc1..a14b4f1286 100644--- a/apps/web/AGENTS.md+++ b/apps/web/AGENTS.md@@ -168,6 +168,10 @@ The shared plain-text Lexical codec is `packages/lexical-core/canvas-text.ts`.## Development Patterns+Shared diff and Changes views expand files with at most 40 additions + deletions+by default; keep saved per-capture choices and explicit toggles authoritative.+Use `/app/debug/diff-view-ui` to exercise the 40/41-line boundary.+Keep persistent list hotkeys free of mounted-view closures, and clearvirtualizer accessors when their view unmounts.Keep editor newline handling local; result-opening handlers must yielddiff --git a/apps/web/src/components/diff-view/DiffView.tsx b/apps/web/src/components/diff-view/DiffView.tsxindex 9789be18dd..c293d77027 100644--- a/apps/web/src/components/diff-view/DiffView.tsx+++ b/apps/web/src/components/diff-view/DiffView.tsx@@ -100,9 +100,7 @@ function Root(ready: () => parsed()?.patch === patch(),diffStyle: () => props.diffStyle,themeType: createThemeType(),- collapse:- props.collapse ??- createDiffCollapse(() => props.files.map((file) => file.path)),+ collapse: props.collapse ?? createDiffCollapse(() => props.files),active: () => props.active,};return (diff --git a/apps/web/src/components/diff-view/README.md b/apps/web/src/components/diff-view/README.mdindex ae654dec1b..bce23671bb 100644--- a/apps/web/src/components/diff-view/README.md+++ b/apps/web/src/components/diff-view/README.md@@ -47,6 +47,8 @@ The host composes the rest:- Toolbar parts, `DiffView.CollapseAll` and `DiffView.StyleToggle`, anywhereinside `Root`.- Collapse state that persists, by passing `collapse`; the default lives in memory.+ Files with at most 40 additions + deletions start expanded; larger files start+ collapsed. Individual toggles and Collapse all / Expand all override defaults.- `DiffCounts` for compact numeric totals, or `DiffStats` for those same totalsbeside five green/red squares showing the addition/deletion proportion. A staticdiagonal hatch and inset edge give the squares texture without changing their size.diff --git a/apps/web/src/components/diff-view/collapse.test.ts b/apps/web/src/components/diff-view/collapse.test.tsnew file mode 100644index 0000000000..9094df8d47--- /dev/null+++ b/apps/web/src/components/diff-view/collapse.test.ts@@ -0,0 +1,42 @@+import { createRoot, createSignal } from 'solid-js';+import { describe, expect, it } from 'vitest';+import { createDiffCollapse } from './collapse';++const FILES = [+ { path: 'empty.ts', additions: 0, deletions: 0 },+ { path: 'boundary.ts', additions: 20, deletions: 20 },+ { path: 'large.ts', additions: 20, deletions: 21 },+];++describe('createDiffCollapse', () => {+ it('applies size defaults to arriving files and preserves explicit toggles', () => {+ createRoot((dispose) => {+ const [files, setFiles] = createSignal<typeof FILES>([]);+ const collapse = createDiffCollapse(files);+ setFiles(FILES);+ expect(collapse.isCollapsed('empty.ts')).toBe(false);+ expect(collapse.isCollapsed('boundary.ts')).toBe(false);+ expect(collapse.isCollapsed('large.ts')).toBe(true);+ collapse.toggle('boundary.ts');+ collapse.toggle('large.ts');+ setFiles(FILES.map((file) => ({ ...file, additions: 100 })));+ expect(collapse.isCollapsed('empty.ts')).toBe(true);+ expect(collapse.isCollapsed('boundary.ts')).toBe(true);+ expect(collapse.isCollapsed('large.ts')).toBe(false);+ dispose();+ });+ });++ it('collapses and expands every file regardless of its default', () => {+ createRoot((dispose) => {+ const collapse = createDiffCollapse(() => FILES);+ expect(collapse.anyExpanded()).toBe(true);+ collapse.toggleAll();+ expect(collapse.anyExpanded()).toBe(false);+ collapse.toggleAll();+ expect(collapse.isCollapsed('large.ts')).toBe(false);+ expect(collapse.isCollapsed('boundary.ts')).toBe(false);+ dispose();+ });+ });+});diff --git a/apps/web/src/components/diff-view/collapse.ts b/apps/web/src/components/diff-view/collapse.tsindex 5318a4ba8f..0ac9e12381 100644--- a/apps/web/src/components/diff-view/collapse.ts+++ b/apps/web/src/components/diff-view/collapse.ts@@ -1,4 +1,6 @@-import { type Accessor, createSignal } from 'solid-js';+import { type Accessor, createMemo, createSignal } from 'solid-js';+import { defaultCollapsedPaths } from './model/collapse';+import type { DiffFile } from './model/diff-file';/** Which files show their diff. A host that persists it supplies its own. */export type DiffCollapse = {@@ -11,23 +13,25 @@ export type DiffCollapse = {/** Collapse state kept in memory for as long as the view is mounted. */export function createDiffCollapse(- paths: Accessor<readonly string[]>+ files: Accessor<readonly Pick<DiffFile, 'path' | 'additions' | 'deletions'>[]>): DiffCollapse {- const [collapsed, setCollapsed] = createSignal<ReadonlySet<string>>(- new Set()+ const defaults = createMemo(() => new Set(defaultCollapsedPaths(files())));+ const [overrides, setOverrides] = createSignal<ReadonlyMap<string, boolean>>(+ new Map());- const anyExpanded = () => paths().some((path) => !collapsed().has(path));+ const isCollapsed = (path: string) =>+ overrides().get(path) ?? defaults().has(path);+ const anyExpanded = () => files().some((file) => !isCollapsed(file.path));return {- isCollapsed: (path) => collapsed().has(path),- toggle: (path) =>- setCollapsed((previous) => {- const next = new Set(previous);- if (next.has(path)) next.delete(path);- else next.add(path);- return next;- }),- toggleAll: () =>- setCollapsed(anyExpanded() ? new Set(paths()) : new Set<string>()),+ isCollapsed,+ toggle: (path) => {+ const collapsed = !isCollapsed(path);+ setOverrides((previous) => new Map(previous).set(path, collapsed));+ },+ toggleAll: () => {+ const collapsed = anyExpanded();+ setOverrides(new Map(files().map((file) => [file.path, collapsed])));+ },anyExpanded,};}diff --git a/apps/web/src/components/diff-view/debug/DiffViewGallery.tsx b/apps/web/src/components/diff-view/debug/DiffViewGallery.tsxindex a14807af96..6afc1c2ae7 100644--- a/apps/web/src/components/diff-view/debug/DiffViewGallery.tsx+++ b/apps/web/src/components/diff-view/debug/DiffViewGallery.tsx@@ -13,7 +13,13 @@ import { DiffView } from '../DiffView';import type { DiffFile, DiffStyle } from '../model/diff-file';import { StatusLetter } from '../StatusLetter';import { CommentsDemo } from './CommentsDemo';-import { generatedChanges, SAMPLE_FILES, SAMPLE_PATCH } from './fixtures';+import {+ COLLAPSE_FILES,+ COLLAPSE_PATCH,+ generatedChanges,+ SAMPLE_FILES,+ SAMPLE_PATCH,+} from './fixtures';function Item(props: { label: string; children: JSX.Element }) {return (@@ -157,6 +163,9 @@ export default function DiffViewGallery() {return (<div class="size-full overflow-auto"><div class="mx-auto flex max-w-5xl flex-col gap-8 px-6 py-8">+ <Item label="Expansion defaults: 40 and 41 changed lines">+ <ComposedDemo files={COLLAPSE_FILES} patch={COLLAPSE_PATCH} />+ </Item><Item label="Composed: file tree, toolbar, and stack"><ComposedDemo files={SAMPLE_FILES} patch={SAMPLE_PATCH} /></Item>diff --git a/apps/web/src/components/diff-view/debug/fixtures.ts b/apps/web/src/components/diff-view/debug/fixtures.tsindex 44df233991..fc23cdacca 100644--- a/apps/web/src/components/diff-view/debug/fixtures.ts+++ b/apps/web/src/components/diff-view/debug/fixtures.ts@@ -222,3 +222,28 @@ export function generatedChanges(fileCount: number): {}return { files, patch: `${parts.join('\n')}\n` };}++/** Files at and just above the default expansion limit. */+export const COLLAPSE_FILES: DiffFile[] = [40, 41].map((additions) => ({+ path: `example/added-${additions}.ts`,+ kind: 'added',+ additions,+ deletions: 0,+ binary: false,+ patchOmitted: false,+}));++export const COLLAPSE_PATCH = COLLAPSE_FILES.map((file) =>+ [+ `diff --git a/${file.path} b/${file.path}`,+ 'new file mode 100644',+ '--- /dev/null',+ `+++ b/${file.path}`,+ `@@ -0,0 +1,${file.additions} @@`,+ ...Array.from(+ { length: file.additions },+ (_, index) => `+export const value${index + 1} = ${index + 1};`+ ),+ '',+ ].join('\n')+).join('');diff --git a/apps/web/src/components/diff-view/model/collapse.ts b/apps/web/src/components/diff-view/model/collapse.tsnew file mode 100644index 0000000000..4deec6302a--- /dev/null+++ b/apps/web/src/components/diff-view/model/collapse.ts@@ -0,0 +1,14 @@+import type { DiffFile } from './diff-file';++/** Files with at most this many additions + deletions open expanded. */+export const DEFAULT_EXPANDED_LINE_LIMIT = 40;++export function defaultCollapsedPaths(+ files: readonly Pick<DiffFile, 'path' | 'additions' | 'deletions'>[]+): string[] {+ return files+ .filter(+ (file) => file.additions + file.deletions > DEFAULT_EXPANDED_LINE_LIMIT+ )+ .map((file) => file.path);+}diff --git a/apps/web/src/features/changes/README.md b/apps/web/src/features/changes/README.mdindex bceaffd9bc..e006ea6d83 100644--- a/apps/web/src/features/changes/README.md+++ b/apps/web/src/features/changes/README.md@@ -109,6 +109,10 @@ in that split's search params (`s0.changes.pane`, `s0.changes.style`), so thesplit router drops them when the split closes or navigates away; anywhere else,such as a preview, they are local signals.+New captures expand files with at most 40 additions + deletions and collapse larger+files, on desktop and mobile. Saved collapse choices for the same capture take+precedence; selecting a file opens it.+## Lifecycle boundaries- `createChangesModel` owns source enablement and retains displayed patch text fordiff --git a/apps/web/src/features/changes/primitives/create-review-state.test.ts b/apps/web/src/features/changes/primitives/create-review-state.test.tsindex 9b1d512543..0f3e2391cd 100644--- a/apps/web/src/features/changes/primitives/create-review-state.test.ts+++ b/apps/web/src/features/changes/primitives/create-review-state.test.ts@@ -55,6 +55,46 @@ function setup() {}describe('createReviewState', () => {+ it('defaults by total changed lines and keeps choices until the next capture', () => {+ createRoot((dispose) => {+ const storage = memoryStorage();+ const capture = changeset('cs1', ['small.ts', 'boundary.ts', 'large.ts']);+ capture.files[1]!.additions = 20;+ capture.files[1]!.deletions = 20;+ capture.files[2]!.additions = 20;+ capture.files[2]!.deletions = 21;+ const [current, setCurrent] = createSignal<Changeset | undefined>();+ const review = createReviewState({+ scopeKey: () => 's1',+ changeset: current,+ storage,+ });+ setCurrent(capture);+ expect(review.isCollapsed('small.ts')).toBe(false);+ expect(review.isCollapsed('boundary.ts')).toBe(false);+ expect(review.isCollapsed('large.ts')).toBe(true);+ review.toggleCollapsed('small.ts');+ review.activate('large.ts');+ expect(review.isCollapsed('small.ts')).toBe(true);+ expect(review.isCollapsed('large.ts')).toBe(false);+ const restored = createReviewState({+ scopeKey: () => 's1',+ changeset: current,+ storage,+ });+ expect(restored.isCollapsed('small.ts')).toBe(true);+ expect(restored.isCollapsed('large.ts')).toBe(false);+ review.toggleAllCollapsed();+ expect(review.anyExpanded()).toBe(false);+ review.toggleAllCollapsed();+ expect(review.isCollapsed('large.ts')).toBe(false);+ setCurrent({ ...capture, id: 'cs2' });+ expect(review.isCollapsed('small.ts')).toBe(false);+ expect(review.isCollapsed('large.ts')).toBe(true);+ dispose();+ });+ });+it('collapses and reopens an individual file', () => {createRoot((dispose) => {const { review } = setup();diff --git a/apps/web/src/features/changes/primitives/create-review-state.ts b/apps/web/src/features/changes/primitives/create-review-state.tsindex 5db1ddde14..0e30ceedc8 100644--- a/apps/web/src/features/changes/primitives/create-review-state.ts+++ b/apps/web/src/features/changes/primitives/create-review-state.ts@@ -2,11 +2,12 @@* The reviewer's state for a changeset: collapsed diffs, the file the tree* last pointed at, and the notes queued for the agent.*- * Collapsed diffs belong to one capture: a new changeset expands them.+ * Collapsed diffs belong to one capture: a new changeset restores size-based defaults.* Notes outlive captures, since they are the reviewer's words,* and are only cleared by sending or deleting them.*/+import { defaultCollapsedPaths } from '@app/components/diff-view/model/collapse';import { type Accessor, createMemo, createSignal } from 'solid-js';import type { Changeset } from '../core/changeset';import {@@ -133,12 +134,14 @@ export function createReviewState(options: {() => options.changeset()?.files.map((file) => file.path) ?? []);- // Collapsed files from an older capture read as empty; the next write- // re-keys the stored state to the current capture.+ // A fresh capture uses size-based defaults; saved choices for the same+ // capture take precedence. The next write re-keys the stored state.const collapsed = createMemo(() => {const current = stored();return new Set(- current.changesetId === changesetId() ? current.collapsed : []+ current.changesetId === changesetId()+ ? current.collapsed+ : defaultCollapsedPaths(options.changeset()?.files ?? []));});const writeCollapsed = (update: (paths: string[]) => string[]) =>diff --git a/docs/agent-guide/ai-chat.md b/docs/agent-guide/ai-chat.mdindex 629df9be80..54ac427f40 100644--- a/docs/agent-guide/ai-chat.md+++ b/docs/agent-guide/ai-chat.md@@ -1676,8 +1676,10 @@ and line and marks them "sent to agent". Sending a typed composer messagewhile notes are queued includes those notes in the same prompt and marks themsent — a second Enter does not post them again. Clicking a note's path opensthat file in the Changes pane. Notes never go to GitHub. Collapsed files and-unsent notes persist per session in localStorage; a new capture expands all-files.+unsent notes persist per session in localStorage. A fresh capture expands files+with at most 40 changed lines (additions + deletions) and collapses larger files,+on desktop and phones. File toggles and **Collapse all / Expand all** override+these defaults; selecting a file in the tree expands it.The Changes pane header and sidebar totals display the linked PR's `additions`and `deletions` returned by the GitHub API, without summing transcript edits.