Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

refactor(changes): shared changes and diff view ui/utils (#7488)

dev-rb41b66e23079d
diff --git a/apps/web/src/components/app/split-layout/componentRegistry.tsx b/apps/web/src/components/app/split-layout/componentRegistry.tsx
index 8051b4eac4..07966642d3 100644
--- a/apps/web/src/components/app/split-layout/componentRegistry.tsx
+++ b/apps/web/src/components/app/split-layout/componentRegistry.tsx
@@ -478,7 +478,7 @@ if (LOCAL_ONLY) {
registerComponent(
'agent-changes-ui',
- lazy(() => import('@app/features/agent-changes/debug/Gallery'))
+ lazy(() => import('@app/features/changes/debug/Gallery'))
);
registerComponent(
diff --git a/apps/web/src/components/diff-view/DiffView.tsx b/apps/web/src/components/diff-view/DiffView.tsx
index a5e4251a8c..e31af4e6f0 100644
--- a/apps/web/src/components/diff-view/DiffView.tsx
+++ b/apps/web/src/components/diff-view/DiffView.tsx
@@ -23,12 +23,12 @@ import {
type JSX,
on,
onCleanup,
- onMount,
type ParentProps,
Show,
useContext,
} from 'solid-js';
import { createDiffCollapse, type DiffCollapse } from './collapse';
+import { createDiffReveal } from './create-diff-reveal';
import { DiffCounts } from './DiffCounts';
import { type DiffFile, type DiffStyle, splitPath } from './model/diff-file';
import type { LineAnnotation, LineRange } from './model/lines';
@@ -158,18 +158,15 @@ function DiffNote(props: { children: JSX.Element }) {
function Stack(props: DiffListProps) {
const view = useDiffView();
const activePath = createMemo(view.active);
- const cards = new Map<string, HTMLElement>();
const [flashing, setFlashing] = createSignal<string>();
- const queue = createRenderQueue();
- const [visible, setVisible] = createSignal<ReadonlySet<string>>(new Set());
let scroller!: HTMLDivElement;
- let observer: IntersectionObserver | undefined;
+ const diffReveal = createDiffReveal(() => scroller);
let anchoredPath: string | undefined;
let pendingSelection = activePath();
let scrollingToAnchor = false;
let resizePending = false;
const alignAnchor = () => {
- const card = anchoredPath ? cards.get(anchoredPath) : undefined;
+ const card = anchoredPath ? diffReveal.card(anchoredPath) : undefined;
if (!card?.isConnected) return;
const margin =
Number.parseFloat(getComputedStyle(card).scrollMarginTop) || 0;
@@ -208,7 +205,7 @@ function Stack(props: DiffListProps) {
createResizeObserver(
() => {
view.entries();
- return [...cards.values()];
+ return diffReveal.cards();
},
() => {
if (scrollingToAnchor) {
@@ -220,32 +217,6 @@ function Stack(props: DiffListProps) {
);
}
- const reveal = (path: string) => {
- queue.enqueue(path, () => {
- setVisible((paths) => new Set([...paths, path]));
- });
- };
- onMount(() => {
- // Older webviews still get queued rendering, without viewport gating.
- if (typeof IntersectionObserver === 'undefined') {
- for (const path of cards.keys()) reveal(path);
- return;
- }
- observer = new IntersectionObserver(
- (entries) => {
- for (const entry of entries) {
- if (!entry.isIntersecting) continue;
- const path = (entry.target as HTMLElement).dataset.path;
- if (path) reveal(path);
- observer?.unobserve(entry.target);
- }
- },
- { root: scroller, rootMargin: '400px 0px' }
- );
- for (const card of cards.values()) observer.observe(card);
- });
- onCleanup(() => observer?.disconnect());
-
// Jumping to a file is a DOM concern: scroll the card in and flash it.
createEffect(
on(
@@ -260,8 +231,8 @@ function Stack(props: DiffListProps) {
// Entry refreshes must not reselect an unchanged path after the user
// takes over scrolling. A pending selection still waits for its card.
if (!path || pendingSelection !== path) return;
- reveal(path);
- const card = cards.get(path);
+ diffReveal.reveal(path);
+ const card = diffReveal.card(path);
if (!card) return;
pendingSelection = undefined;
anchoredPath = path;
@@ -309,17 +280,9 @@ function Stack(props: DiffListProps) {
return (
<FileContext.Provider value={entry}>
<Card
- ref={(element: HTMLDivElement) => {
- const filePath = path();
- cards.set(filePath, element);
- if (observer) observer.observe(element);
- else if (typeof IntersectionObserver === 'undefined')
- reveal(filePath);
- onCleanup(() => {
- cards.delete(filePath);
- observer?.unobserve(element);
- });
- }}
+ ref={(element: HTMLDivElement) =>
+ diffReveal.register(path(), element)
+ }
class={cn(
'shrink-0 scroll-mt-3 overflow-clip transition',
flashing() === path() &&
@@ -337,7 +300,7 @@ function Stack(props: DiffListProps) {
</header>
<Show when={!collapsed()}>
<Show
- when={visible().has(path())}
+ when={diffReveal.visible(path())}
fallback={
<div
class="flex h-40 items-center justify-center text-xs text-ink-placeholder"
diff --git a/apps/web/src/components/diff-view/README.md b/apps/web/src/components/diff-view/README.md
index 77ae02353e..1562e5a975 100644
--- a/apps/web/src/components/diff-view/README.md
+++ b/apps/web/src/components/diff-view/README.md
@@ -18,6 +18,12 @@ release the anchor so manual scrolling and review-note editing remain unrestrict
Refreshing files or patch text does not reselect an unchanged active file after
that release; an initial pending selection still waits for its file card.
+`Root` keeps patch parsing separate from the stack's body-reveal queue.
+`create-diff-reveal.ts` owns viewport observation and file-card registration;
+scroll anchoring stays in `Stack` and also reacts to later highlighting.
+Both queues are scoped to their respective Solid owners. A host that animates
+an exit retains those owners until the visual exit completes.
+
Each file is an outlined `@ui` `Card` with a 40px sticky header: a ghost
disclosure button, the status letter and `text-xs` path (directory in
`text-ink-subtle`), and `text-xs` counts. Both default and custom headers use
diff --git a/apps/web/src/components/diff-view/create-diff-reveal.ts b/apps/web/src/components/diff-view/create-diff-reveal.ts
new file mode 100644
index 0000000000..c454442b24
--- /dev/null
+++ b/apps/web/src/components/diff-view/create-diff-reveal.ts
@@ -0,0 +1,54 @@
+import { createRenderQueue } from '@app/lib/utils/create-render-queue';
+import { createSignal, onCleanup, onMount } from 'solid-js';
+
+/** Queues each file body when its card approaches the stack viewport. */
+export function createDiffReveal(scroller: () => HTMLElement) {
+ const queue = createRenderQueue();
+ // Keep revealed paths in memory when their bodies collapse or leave the viewport.
+ const [visible, setVisible] = createSignal<ReadonlySet<string>>(new Set());
+ const cards = new Map<string, HTMLElement>();
+ let observer: IntersectionObserver | undefined;
+
+ const reveal = (path: string) => {
+ queue.enqueue(path, () => {
+ setVisible((paths) => new Set([...paths, path]));
+ });
+ };
+
+ onMount(() => {
+ // Older webviews still get queued rendering, without viewport gating.
+ if (typeof IntersectionObserver === 'undefined') {
+ for (const path of cards.keys()) reveal(path);
+ return;
+ }
+ observer = new IntersectionObserver(
+ (entries) => {
+ for (const entry of entries) {
+ if (!entry.isIntersecting) continue;
+ const path = (entry.target as HTMLElement).dataset.path;
+ if (path) reveal(path);
+ observer?.unobserve(entry.target);
+ }
+ },
+ { root: scroller(), rootMargin: '400px 0px' }
+ );
+ for (const card of cards.values()) observer.observe(card);
+ });
+ onCleanup(() => observer?.disconnect());
+
+ return {
+ visible: (path: string) => visible().has(path),
+ reveal,
+ card: (path: string) => cards.get(path),
+ cards: () => [...cards.values()],
+ register(path: string, element: HTMLElement) {
+ cards.set(path, element);
+ if (observer) observer.observe(element);
+ else if (typeof IntersectionObserver === 'undefined') reveal(path);
+ onCleanup(() => {
+ cards.delete(path);
+ observer?.unobserve(element);
+ });
+ },
+ };
+}
diff --git a/apps/web/src/components/ui/components/CollapseTransition.tsx b/apps/web/src/components/ui/components/CollapseTransition.tsx
index 4fbb6ee33f..e32afd389b 100644
--- a/apps/web/src/components/ui/components/CollapseTransition.tsx
+++ b/apps/web/src/components/ui/components/CollapseTransition.tsx
@@ -1,3 +1,4 @@
+import { createAnimationGroup } from '@app/lib/utils/create-animation-group';
import { createResizeObserver } from '@solid-primitives/resize-observer';
import {
children,
@@ -70,22 +71,21 @@ export function CollapseTransition(props: CollapseTransitionProps) {
element.getBoundingClientRect()[axis()];
let measuredSize: number | undefined;
let disposed = false;
- let running:
- | { target: HTMLElement; content: HTMLElement; finish: () => void }
- | undefined;
+ const motion = createAnimationGroup();
+ let running: { target: HTMLElement; content: HTMLElement } | undefined;
createResizeObserver(container, (_rect, element) => {
if (!running) measuredSize = sizeOf(element);
});
onMount(() => {
- props.captureController?.({ finish: () => running?.finish() });
+ props.captureController?.({ finish: motion.finish });
const element = container();
props.onPresenceChange?.(props.open);
if (element) measuredSize = sizeOf(element);
});
onCleanup(() => {
disposed = true;
- running?.finish();
+ motion.finish();
});
function animate(element: Element, opening: boolean, done: () => void) {
@@ -109,7 +109,7 @@ export function CollapseTransition(props: CollapseTransitionProps) {
const companions = untrack(() =>
props.companions?.({ opening, from, interrupted: running !== undefined })
);
- running?.finish();
+ motion.finish();
const to = opening ? (props.expandedSize ?? sizeOf(target)) : collapsedSize;
const style = getComputedStyle(target);
const {
@@ -147,42 +147,40 @@ export function CollapseTransition(props: CollapseTransitionProps) {
easing: 'ease-out',
fill: 'both',
};
- const size = target.animate(
+ running = { target, content: element };
+ motion.start(
[
{
- ...sizing,
- [axis()]: `${from}px`,
- [paddingStart]: opening ? '0' : startPadding,
- [paddingEnd]: opening ? '0' : endPadding,
+ target,
+ keyframes: [
+ {
+ ...sizing,
+ [axis()]: `${from}px`,
+ [paddingStart]: opening ? '0' : startPadding,
+ [paddingEnd]: opening ? '0' : endPadding,
+ },
+ {
+ ...sizing,
+ [axis()]: `${to}px`,
+ [paddingStart]: opening ? startPadding : '0',
+ [paddingEnd]: opening ? endPadding : '0',
+ },
+ ],
},
{
- ...sizing,
- [axis()]: `${to}px`,
- [paddingStart]: opening ? startPadding : '0',
- [paddingEnd]: opening ? endPadding : '0',
+ target: element,
+ keyframes: [{ opacity: fromOpacity }, { opacity: opening ? 1 : 0 }],
},
+ ...(companions ?? []),
],
- options
+ options,
+ () => {
+ running = undefined;
+ measuredSize = to;
+ props.onPresenceChange?.(opening || props.open);
+ done();
+ }
);
- const opacity = element.animate(
- [{ opacity: fromOpacity }, { opacity: opening ? 1 : 0 }],
- options
- );
- const companionAnimations = companions?.map(({ target, keyframes }) =>
- target.animate(keyframes, options)
- );
- const finish = () => {
- if (running?.finish !== finish) return;
- running = undefined;
- measuredSize = to;
- props.onPresenceChange?.(opening || props.open);
- done();
- size.cancel();
- opacity.cancel();
- companionAnimations?.forEach((animation) => animation.cancel());
- };
- running = { target, content: element, finish };
- size.onfinish = finish;
}
return (
diff --git a/apps/web/src/features/agent-changes/views/AgentChangesSplit.tsx b/apps/web/src/features/agent-changes/views/AgentChangesSplit.tsx
deleted file mode 100644
index 4a2443b9be..0000000000
--- a/apps/web/src/features/agent-changes/views/AgentChangesSplit.tsx
+++ /dev/null
@@ -1,308 +0,0 @@
-/**
- * The session and its Changes pane side by side, on a draggable divider.
- * Closing the pane hands the width back to the session; spotlighting it
- * takes the session's width away.
- */
-
-import { FloatRegion } from '@components/app/mobile/float-regions/FloatRegion';
-import { FloatRegions } from '@components/app/mobile/float-regions/float-region-state';
-import { Resize } from '@core/component/Resize';
-import type { ResizeZoneCtx } from '@core/component/Resize/types';
-import { isTouchDevice } from '@core/mobile/isTouchDevice';
-import { createMediaQuery } from '@solid-primitives/media';
-import {
- type Accessor,
- createEffect,
- createMemo,
- createSignal,
- on,
- onCleanup,
- type ParentProps,
- Show,
-} from 'solid-js';
-import { useAgentChanges } from '../context/agent-changes-controller';
-import { createChangesNarrow } from '../primitives/create-changes-narrow';
-import { ChangesPane } from './ChangesPane';
-
-const SESSION_MIN_PX = 320;
-const CHANGES_MIN_PX = 400;
-
-/** Keep the resize panel registered until its content finishes sliding out. */
-function createChangesPresence(visible: Accessor<boolean>) {
- const reducedMotion = createMediaQuery('(prefers-reduced-motion: reduce)');
- const [present, setPresent] = createSignal(visible());
- const [transitioning, setTransitioning] = createSignal(false);
- let element: HTMLDivElement | undefined;
- let animation: Animation | undefined;
- let siblings: Animation[] = [];
- const cancelSiblings = () => {
- for (const sibling of siblings) sibling.cancel();
- siblings = [];
- };
- const animateSplit = (
- element: HTMLElement,
- visible: boolean,
- options: KeyframeAnimationOptions
- ) => {
- const continuing = siblings.length > 0;
- const panel = element.parentElement;
- if (!panel?.matches('[data-resize-panel]')) {
- cancelSiblings();
- return;
- }
- const root = panel.parentElement;
- const sessionContent = root?.querySelector<HTMLElement>(
- ':scope > [data-resize-panel] > [data-agent-changes-session]'
- );
- const session =
- sessionContent?.hidden ||
- sessionContent?.hasAttribute('data-slide-underlay')
- ? undefined
- : sessionContent?.parentElement;
- const gutter = root?.querySelector<HTMLElement>(
- ':scope > [role="separator"]'
- );
- const sessionWidth = session
- ? continuing || !visible
- ? getComputedStyle(session).width
- : '100%'
- : undefined;
- const gutterTransform = gutter
- ? continuing || !visible
- ? getComputedStyle(gutter).transform
- : `translateX(${panel.style.width})`
- : undefined;
- cancelSiblings();
- // Match the session and divider to the pane's slide in both directions.
- // The solver holds the resting widths under these temporary animations.
- if (session) {
- siblings.push(
- session.animate(
- [
- { width: sessionWidth },
- { width: visible ? session.style.width : '100%' },
- ],
- options
- )
- );
- }
- if (gutter) {
- gutter.inert = !visible;
- siblings.push(
- gutter.animate(
- [
- { transform: gutterTransform },
- {
- transform: visible
- ? 'translateX(0)'
- : `translateX(${panel.style.width})`,
- },
- ],
- options
- )
- );
- }
- };
- let revision = 0;
-
- // Synchronize the imperative animation with visibility. The retained owner
- // keeps Resize.Panel's registration and the conversation draft intact on exit.
- createEffect(
- on(visible, (visible) => {
- const current = ++revision;
- setTransitioning(
- !reducedMotion() && typeof HTMLElement.prototype.animate === 'function'
- );
- if (visible) setPresent(true);
- if (!visible && (reducedMotion() || !element?.animate)) {
- animation?.cancel();
- animation = undefined;
- cancelSiblings();
- setPresent(false);
- setTransitioning(false);
- return;
- }
- queueMicrotask(() => {
- if (current !== revision || !element) return;
- // Snapshot values before cancellation: computed styles are live objects.
- const previousTransform = animation
- ? getComputedStyle(element).transform
- : undefined;
- animation?.cancel();
- animation = undefined;
- element.inert = !visible;
- if (reducedMotion() || !element.animate) {
- cancelSiblings();
- setPresent(visible);
- setTransitioning(false);
- return;
- }
- const options: KeyframeAnimationOptions = {
- duration: 220,
- easing: 'ease-in-out',
- fill: 'forwards',
- };
- animateSplit(element, visible, options);
- animation = element.animate(
- [
- {
- transform:
- previousTransform ??
- (visible ? 'translateX(100%)' : 'translateX(0)'),
- },
- { transform: visible ? 'translateX(0)' : 'translateX(100%)' },
- ],
- options
- );
- animation.onfinish = () => {
- if (current !== revision) return;
- const finished = animation;
- animation = undefined;
- setPresent(visible);
- // Hold the final frame through unmount, then release WAAPI styles.
- finished?.cancel();
- cancelSiblings();
- setTransitioning(false);
- };
- });
- })
- );
- onCleanup(() => {
- revision += 1;
- animation?.cancel();
- cancelSiblings();
- });
-
- return {
- finish: () => {
- revision += 1;
- const finished = animation;
- animation = undefined;
- setPresent(visible());
- finished?.cancel();
- cancelSiblings();
- setTransitioning(false);
- },
- present,
- transitioning,
- ref: (node: HTMLDivElement) => {
- element = node;
- },
- };
-}
-
-export function AgentChangesSplit(props: ParentProps) {
- const { available, layout } = useAgentChanges();
- const [root, setRoot] = createSignal<HTMLDivElement>();
- const narrow = createChangesNarrow(root);
- let zone: ResizeZoneCtx | undefined;
- // A host that can never have changes keeps the session alone on screen,
- // whatever a stale URL asks for.
- // Split/full changes keep the same visibility and must not replay the slide.
- const changesVisible = createMemo(
- () => available() && layout.changesVisible()
- );
- const presence = createChangesPresence(changesVisible);
- const sessionVisible = createMemo<boolean>((previous) => {
- if (!available()) return true;
- // A narrow host opens as a takeover without changing the saved wide layout.
- if (changesVisible() && narrow()) return false;
- // A spotlight request during a slide waits for the slide to settle, so its
- // endpoint does not move underneath the running translation.
- if (presence.transitioning()) return previous ?? layout.sessionVisible();
- if (changesVisible()) return layout.sessionVisible();
- // Closing from full width must not shrink the pane before it slides out.
- return presence.present() ? (previous ?? true) : true;
- });
- // Reveal the retained host behind a full-width slide without changing the
- // Changes panel's solved geometry until the slide finishes, including reversals.
- const slideUnderlay = () =>
- presence.present() &&
- !sessionVisible() &&
- (!changesVisible() || presence.transitioning());
- const sessionShown = () => sessionVisible() || slideUnderlay();
-
- return (
- <div
- ref={setRoot}
- data-agent-changes-host
- class="size-full min-h-0 min-w-0 overflow-hidden"
- >
- <Show
- when={isTouchDevice()}
- fallback={
- <Resize.Zone
- direction="horizontal"
- gutter={1}
- class="overflow-hidden"
- resizable
- captureResizeCtx={(ctx) => {
- zone = ctx;
- createEffect(on(ctx.size, presence.finish, { defer: true }));
- }}
- >
- {/* Hiding retains resize intent and the host's editor/composer owner. */}
- <Resize.Panel
- id="agent-session"
- minSize={SESSION_MIN_PX}
- index={0}
- persistent
- hidden={() => !sessionVisible()}
- >
- <div
- data-agent-changes-session
- data-slide-underlay={slideUnderlay() ? '' : undefined}
- hidden={!sessionShown()}
- inert={!sessionVisible() && changesVisible()}
- style={{
- width: slideUnderlay() ? `${zone?.size() ?? 0}px` : undefined,
- }}
- class="flex h-full min-w-0 flex-col overflow-hidden"
- >
- {props.children}
- </div>
- </Resize.Panel>
- <Show when={presence.present()}>
- <Resize.Panel
- id="agent-changes"
- minSize={CHANGES_MIN_PX}
- index={1}
- target={layout.changesShare()}
- onSizeChangeEnd={(size) => {
- const total = zone?.size() ?? 0;
- if (total > 0) layout.setChangesShare((size / total) * 100);
- }}
- >
- <div ref={presence.ref} class="h-full min-w-0 overflow-hidden">
- <ChangesPane fullWidth={narrow()} />
- </div>
- </Resize.Panel>
- </Show>
- </Resize.Zone>
- }
- >
- <div class="relative flex size-full min-w-0 flex-col overflow-hidden">
- <div
- class="flex size-full min-w-0 flex-col"
- classList={{ hidden: changesVisible() }}
- inert={changesVisible()}
- >
- {props.children}
- </div>
- <Show when={presence.present()}>
- <div
- ref={presence.ref}
- class="absolute inset-0 min-w-0 pt-(--mobile-content-inset-top)"
- style={{ 'padding-bottom': `${FloatRegions.hostHeight()}px` }}
- >
- <FloatRegion region="accessory" priority={1}>
- <span />
- </FloatRegion>
- <ChangesPane fullWidth />
- </div>
- </Show>
- </div>
- </Show>
- </div>
- );
-}
diff --git a/apps/web/src/features/agents-view/components/AgentSessionPane.tsx b/apps/web/src/features/agents-view/components/AgentSessionPane.tsx
index e8e5fe8f32..699c910e34 100644
--- a/apps/web/src/features/agents-view/components/AgentSessionPane.tsx
+++ b/apps/web/src/features/agents-view/components/AgentSessionPane.tsx
@@ -1,10 +1,3 @@
-import {
- AgentChangesProvider,
- AgentChangesSplit,
- ChangesHandoff,
- ChangesToggle,
- ReviewNotesDock,
-} from '@app/features/agent-changes/agent-changes';
import { AgentSessionProvider } from '@app/features/block-agent/agent-session-provider';
import { AgentComposer } from '@app/features/block-agent/component/AgentComposer';
import { AgentPreviewBanner } from '@app/features/block-agent/component/AgentPreviewBanner';
@@ -23,6 +16,13 @@ import {
pendingSession,
} from '@app/features/block-agent/context/pending-session';
import { createAgentRouteTarget } from '@app/features/block-agent/primitives/create-agent-route-target';
+import { AgentChangesProvider } from '@app/features/changes/agent-session-changes';
+import {
+ ChangesHandoff,
+ ChangesSplit,
+ ChangesToggle,
+ ReviewNotesDock,
+} from '@app/features/changes/changes';
import { useBlockEntityCommands } from '@app/features/next-soup/actions';
import { SidePanel } from '@components/app/side-panel';
import { SplitFileMenu } from '@components/app/split-layout/components/SplitFileMenu';
@@ -319,12 +319,12 @@ export function AgentSessionPane(props: {
return (
<AgentSessionProvider blockId={props.id} onSessionId={props.onSessionId}>
<AgentChangesProvider>
- <AgentChangesSplit>
+ <ChangesSplit>
<SessionContent
onDeleted={props.onDeleted}
notificationSource={props.notificationSource}
/>
- </AgentChangesSplit>
+ </ChangesSplit>
</AgentChangesProvider>
</AgentSessionProvider>
);
diff --git a/apps/web/src/features/block-agent/component/AgentComposer.test.tsx b/apps/web/src/features/block-agent/component/AgentComposer.test.tsx
index cf71f08842..39adcc71e5 100644
--- a/apps/web/src/features/block-agent/component/AgentComposer.test.tsx
+++ b/apps/web/src/features/block-agent/component/AgentComposer.test.tsx
@@ -24,8 +24,8 @@ const mocks = vi.hoisted(() => ({
queued: undefined as QueuedPromptsProps | undefined,
}));
-vi.mock('@app/features/agent-changes/context/agent-changes-controller', () => ({
- useOptionalAgentChanges: () => ({ consumeSendableNotes: mocks.consumeNotes }),
+vi.mock('@app/features/changes/context/changes-controller', () => ({
+ useOptionalChanges: () => ({ consumeSendableNotes: mocks.consumeNotes }),
}));
vi.mock('@channel/Input', () => ({
createInputAttachmentTracker: () => ({
diff --git a/apps/web/src/features/block-agent/component/AgentComposer.tsx b/apps/web/src/features/block-agent/component/AgentComposer.tsx
index 543ad56d0e..cfa7260865 100644
--- a/apps/web/src/features/block-agent/component/AgentComposer.tsx
+++ b/apps/web/src/features/block-agent/component/AgentComposer.tsx
@@ -7,7 +7,7 @@ import { Button } from '@ui';
* combined model-and-effort change waits for runtime confirmation.
*/
-import { useOptionalAgentChanges } from '@app/features/agent-changes/context/agent-changes-controller';
+import { useOptionalChanges } from '@app/features/changes/context/changes-controller';
import {
createInputAttachmentTracker,
type InputAttachmentData,
@@ -70,7 +70,7 @@ export function AgentComposer(props: {
registerQuoteInsert,
initialInput,
} = useAgentSession();
- const changes = useOptionalAgentChanges();
+ const changes = useOptionalChanges();
const readOnly = () => session()?.canEdit === false;
// The fold speculates the action the moment it is issued, so success is
diff --git a/apps/web/src/features/block-agent/component/AgentSplitHeader.tsx b/apps/web/src/features/block-agent/component/AgentSplitHeader.tsx
index a6ec2e7dc9..5392fb5efe 100644
--- a/apps/web/src/features/block-agent/component/AgentSplitHeader.tsx
+++ b/apps/web/src/features/block-agent/component/AgentSplitHeader.tsx
@@ -1,4 +1,4 @@
-import { ChangesToggle } from '@app/features/agent-changes/agent-changes';
+import { ChangesToggle } from '@app/features/changes/changes';
import { useBlockEntityCommands } from '@app/features/next-soup/actions/use-block-entity-commands';
import {
type BlockTool,
diff --git a/apps/web/src/features/block-agent/component/Block.tsx b/apps/web/src/features/block-agent/component/Block.tsx
index 5d812f2117..811300ef4e 100644
--- a/apps/web/src/features/block-agent/component/Block.tsx
+++ b/apps/web/src/features/block-agent/component/Block.tsx
@@ -1,9 +1,9 @@
+import { AgentChangesProvider } from '@app/features/changes/agent-session-changes';
import {
- AgentChangesProvider,
- AgentChangesSplit,
ChangesHandoff,
+ ChangesSplit,
ReviewNotesDock,
-} from '@app/features/agent-changes/agent-changes';
+} from '@app/features/changes/changes';
import { useGlobalNotificationSource } from '@components/app/GlobalAppState';
import { FloatRegionOrInline } from '@components/app/mobile/float-regions/FloatRegion';
import { SidePanel } from '@components/app/side-panel';
@@ -158,7 +158,7 @@ function AgentBlockContent(props: {
<AgentPreviewBanner />
{/* The Changes pane opens beside the transcript; closed, the
transcript keeps the whole width. */}
- <AgentChangesSplit>
+ <ChangesSplit>
<Transcript searchTarget={searchTarget()} />
{/* Full-frame mobile: composer + queue float in the bottom
accessory region above the dock; desktop stays inline. */}
@@ -190,7 +190,7 @@ function AgentBlockContent(props: {
</div>
</div>
</AgentComposerRegion>
- </AgentChangesSplit>
+ </ChangesSplit>
</SidePanel.Layout>
</div>
</StaticMarkdownContext>
diff --git a/apps/web/src/features/block-agent/component/session-read-hosts.test.tsx b/apps/web/src/features/block-agent/component/session-read-hosts.test.tsx
index ccdcfc4adf..256b62aa1f 100644
--- a/apps/web/src/features/block-agent/component/session-read-hosts.test.tsx
+++ b/apps/web/src/features/block-agent/component/session-read-hosts.test.tsx
@@ -112,9 +112,11 @@ vi.mock('@core/component/TopBar/shareModal', () => ({
vi.mock('@components/app/mobile/float-regions/FloatRegion', () => ({
FloatRegionOrInline: (props: { children: JSX.Element }) => props.children,
}));
-vi.mock('@app/features/agent-changes/agent-changes', () => ({
+vi.mock('@app/features/changes/agent-session-changes', () => ({
AgentChangesProvider: (props: { children: JSX.Element }) => props.children,
- AgentChangesSplit: (props: { children: JSX.Element }) => props.children,
+}));
+vi.mock('@app/features/changes/changes', () => ({
+ ChangesSplit: (props: { children: JSX.Element }) => props.children,
ChangesHandoff: () => null,
ChangesToggle: () => null,
ReviewNotesDock: () => null,
diff --git a/apps/web/src/features/block-agent/component/sidepanel/AgentSidePanelSections.tsx b/apps/web/src/features/block-agent/component/sidepanel/AgentSidePanelSections.tsx
index 9683ad5da0..f0602dc100 100644
--- a/apps/web/src/features/block-agent/component/sidepanel/AgentSidePanelSections.tsx
+++ b/apps/web/src/features/block-agent/component/sidepanel/AgentSidePanelSections.tsx
@@ -10,7 +10,7 @@
*/
import { DiffCounts } from '@app/components/diff-view';
-import { useOptionalAgentChanges } from '@app/features/agent-changes/context/agent-changes-controller';
+import { useOptionalChanges } from '@app/features/changes/context/changes-controller';
import { SidePanel } from '@components/app/side-panel';
import { EntityMetadata } from '@components/app/side-panel/EntityMetadata';
import { ModelIcon } from '@core/component/AI/component/ProviderIcon';
@@ -35,7 +35,7 @@ export function AgentSidePanelSections() {
const { sessionId, session, bot, metadata, messages } = useAgentSession();
const plan = createMemo(() => latestPlan(messages()));
- const changes = useOptionalAgentChanges();
+ const changes = useOptionalChanges();
const files = () => changes?.model.files() ?? [];
const activity = createMemo(() => activityCounts(messages()));
const totals = () => changes?.changeCounts();
diff --git a/apps/web/src/features/block-pr/component/PrChanges.tsx b/apps/web/src/features/block-pr/component/PrChanges.tsx
index bbb39c1d79..cf869e8778 100644
--- a/apps/web/src/features/block-pr/component/PrChanges.tsx
+++ b/apps/web/src/features/block-pr/component/PrChanges.tsx
@@ -2,17 +2,13 @@
* The Changes pane on a pull request page: a read-only viewer over the pull
* request's changes at its current base and head. Review state is kept under
* `pr:<foreign-entity-id>`, apart from any agent session on the same pull
- * request. Hosts place `AgentChangesSplit` and `ChangesToggle` inside.
+ * request. Hosts place `ChangesSplit` and `ChangesToggle` inside.
*/
-import { copyText } from '@app/features/agent-changes/agent-changes';
-import type { ChangesHost } from '@app/features/agent-changes/context/agent-changes-context';
-import { AgentChangesControllerProvider } from '@app/features/agent-changes/context/agent-changes-controller';
-import { createPaneViewState } from '@app/features/agent-changes/pane-view-state';
-import { createAgentChanges } from '@app/features/agent-changes/primitives/create-agent-changes';
-import { toast } from '@core/component/Toast/Toast';
-import { openExternalUrl } from '@core/util/url';
-import { createSignal, type ParentProps } from 'solid-js';
+import { createBrowserChangesActions } from '@app/features/changes/browser-host';
+import { ChangesProvider } from '@app/features/changes/changes';
+import type { ChangesHost } from '@app/features/changes/context/changes-context';
+import type { ParentProps } from 'solid-js';
import { createPrChangesSource } from '../data/pr-changes';
export function PrChangesProvider(
@@ -31,23 +27,11 @@ export function PrChangesProvider(
pullRequestTitle: () => props.pullRequestTitle,
// Missing GitHub totals never fall back to captured estimates.
pullRequestChangeCounts: () => props.pullRequestChangeCounts,
- openExternal: openExternalUrl,
- copyText,
- notify: (message, tone) => {
- if (tone === 'success') toast.success(message);
- else toast.failure(message);
- },
+ ...createBrowserChangesActions(),
};
- const view = createPaneViewState();
- const [dismissed, setDismissed] = createSignal<string>();
- const controller = createAgentChanges({
- context: { source, host },
- view,
- dismissed: [dismissed, (id) => setDismissed(id)],
- });
return (
- <AgentChangesControllerProvider value={controller}>
+ <ChangesProvider context={{ source, host }}>
{props.children}
- </AgentChangesControllerProvider>
+ </ChangesProvider>
);
}
diff --git a/apps/web/src/features/block-pr/data/pr-changes.test.ts b/apps/web/src/features/block-pr/data/pr-changes.test.ts
index 0605237259..2fc5421dac 100644
--- a/apps/web/src/features/block-pr/data/pr-changes.test.ts
+++ b/apps/web/src/features/block-pr/data/pr-changes.test.ts
@@ -1,4 +1,4 @@
-import { changesState } from '@app/features/agent-changes/core/changeset';
+import { changesState } from '@app/features/changes/core/changeset';
import { describe, expect, it } from 'vitest';
import { decodePrChanges } from './pr-changes';
diff --git a/apps/web/src/features/block-pr/data/pr-changes.ts b/apps/web/src/features/block-pr/data/pr-changes.ts
index 3b29529d30..c521200089 100644
--- a/apps/web/src/features/block-pr/data/pr-changes.ts
+++ b/apps/web/src/features/block-pr/data/pr-changes.ts
@@ -7,12 +7,12 @@
import type {
ChangesSource,
PatchRead,
-} from '@app/features/agent-changes/context/agent-changes-context';
-import type { SessionChanges } from '@app/features/agent-changes/core/changeset';
+} from '@app/features/changes/context/changes-context';
+import type { ChangesSummary } from '@app/features/changes/core/changeset';
import {
decodeChangeset,
queryStatus,
-} from '@app/features/agent-changes/queries/session-changes';
+} from '@app/features/changes/queries/changes-adapter';
import {
useGithubPullRequestChangesPatchQuery,
useGithubPullRequestChangesQuery,
@@ -23,7 +23,7 @@ import type { Accessor } from 'solid-js';
export function decodePrChanges(
dto: GithubPullRequestChangesResponse,
now = new Date().toISOString()
-): SessionChanges {
+): ChangesSummary {
if (dto.changeset) {
return { changeset: decodeChangeset(dto.changeset), capturing: false };
}
diff --git a/apps/web/src/features/block-pr/views/PrDetail.test.ts b/apps/web/src/features/block-pr/views/PrDetail.test.ts
index dcd4e8bae0..e2656dbf3f 100644
--- a/apps/web/src/features/block-pr/views/PrDetail.test.ts
+++ b/apps/web/src/features/block-pr/views/PrDetail.test.ts
@@ -44,8 +44,8 @@ vi.mock('../data/queries', () => ({
usePrForeignEntityQuery: () => ({ isPending: true }),
prForeignEntityQueryKey: (id: string) => ['pr-foreign-entity', id],
}));
-vi.mock('@app/features/agent-changes/agent-changes', () => ({
- AgentChangesSplit: () => null,
+vi.mock('@app/features/changes/changes', () => ({
+ ChangesSplit: () => null,
ChangesToggle: () => null,
}));
vi.mock('../component/PrChanges', () => ({ PrChangesProvider: () => null }));
diff --git a/apps/web/src/features/block-pr/views/PrDetail.tsx b/apps/web/src/features/block-pr/views/PrDetail.tsx
index 0cfaedc199..723d4d3485 100644
--- a/apps/web/src/features/block-pr/views/PrDetail.tsx
+++ b/apps/web/src/features/block-pr/views/PrDetail.tsx
@@ -1,9 +1,6 @@
import { ViewShell } from '@app/components/view-shell';
-import {
- AgentChangesSplit,
- ChangesToggle,
-} from '@app/features/agent-changes/agent-changes';
-import { useOptionalAgentChanges } from '@app/features/agent-changes/context/agent-changes-controller';
+import { ChangesSplit, ChangesToggle } from '@app/features/changes/changes';
+import { useOptionalChanges } from '@app/features/changes/context/changes-controller';
import { useGlobalNotificationSource } from '@components/app/GlobalAppState';
import { SidePanel } from '@components/app/side-panel';
import { SplitPanel } from '@components/app/split-panel';
@@ -221,7 +218,7 @@ export function StandalonePrDetail(props: { foreignEntityId: string }) {
pullRequestTitle={detail.data()?.pullRequest.name ?? undefined}
pullRequestChangeCounts={detail.changeCounts()}
>
- <AgentChangesSplit>
+ <ChangesSplit>
<div class="flex size-full min-h-0 min-w-0 flex-col overflow-hidden @container">
<ViewShell.TopBar class="touch:flex">
<SplitPanel.CloseButton class="hidden shrink-0 touch:flex" />
@@ -241,7 +238,7 @@ export function StandalonePrDetail(props: { foreignEntityId: string }) {
onRetry={() => void detail.query.refetch()}
/>
</div>
- </AgentChangesSplit>
+ </ChangesSplit>
</PrChangesProvider>
</SidePanel.Root>
);
@@ -262,7 +259,7 @@ function PrMetadata(props: {
prRef: PrRef;
pullRequest?: GithubPullRequestWithDetails;
}) {
- const changes = useOptionalAgentChanges();
+ const changes = useOptionalChanges();
return (
<div class="mb-6 flex flex-row flex-wrap items-center gap-2 text-sm empty:hidden">
<Show when={props.pullRequest?.status}>
diff --git a/apps/web/src/features/agent-changes/README.md b/apps/web/src/features/changes/README.md
similarity index 66%
rename from apps/web/src/features/agent-changes/README.md
rename to apps/web/src/features/changes/README.md
index b0a442e60f..bceaffd9bc 100644
--- a/apps/web/src/features/agent-changes/README.md
+++ b/apps/web/src/features/changes/README.md
@@ -1,19 +1,31 @@
-# Pull request diff viewer
+# Shared Changes viewer
-`agent-changes.tsx` wires the viewer into agent sessions. The controller and views
-can also be mounted by a PR external entity without an `AgentSessionProvider`.
+`changes.tsx` is the shared entry for PRs, agent sessions, and previews. A host
+supplies a `ChangesSource` and `ChangesHost`; `ChangesProvider` owns controller,
+view-state, and dismissal setup. Shared UI never reads agent-session context.
-A host supplies `ChangesSource` and `ChangesHost` from
-`context/agent-changes-context.ts`, creates a controller with `createAgentChanges`,
-and mounts `AgentChangesControllerProvider` around `ChangesPane` or
-`AgentChangesSplit`. Give each host a stable `scopeKey` (for example,
-`pr:<foreign-entity-id>`) to isolate its locally persisted collapse state and notes.
-The optional `agent` capability enables inline note creation and sending; omit it
-for a read-only PR viewer. The optional `canHaveChanges` accessor hides every
-control and the pane while false; the session host reports it from the harness and
-the linked pull request, so a chat-only (in-memory) session or a coding session
-without a pull request yet shows no GitHub chrome. Clipboard, external navigation,
-and notifications are host callbacks.
+```tsx
+<ChangesProvider context={{ source, host }}>
+ <ChangesSplit>
+ <header><ChangesToggle /></header>
+ <HostContent />
+ </ChangesSplit>
+</ChangesProvider>
+```
+
+`AgentChangesProvider` in `agent-session-changes.tsx` supplies the harness source,
+linked PR metadata, and prompt-based note sending. `block-pr/component/PrChanges.tsx`
+supplies the storage-service PR source and existing PR metadata without an agent
+capability, so the same viewer stays read-only. Neither adapter duplicates the
+shared controller setup or owns the other adapter's queries. `browser-host.ts`
+provides clipboard, external navigation, and notifications explicitly at these
+production boundaries; the generic provider has no implicit browser actions.
+
+Give each host a stable `scopeKey` (for example, `pr:<foreign-entity-id>`) to isolate
+persisted layout, collapse state, and notes. The optional `agent` capability enables
+inline note creation and sending. The optional `canHaveChanges` accessor hides all
+controls and the pane while false. The session adapter also gates its source, so
+chat-only sessions and coding sessions without a linked PR make no changes requests.
`views/ChangesPane.tsx` composes the generic `FileTree`
(`@ui/components/FileTree`) and `DiffView` (`src/components/diff-view`) from the
@@ -40,7 +52,7 @@ in the floating diff controls; a hidden or drawer tree puts its count there too.
Another host composes the same components its own way.
Native PR and Agents workspace hosts put their title row and content together
-inside `AgentChangesSplit`, so changes occupy the full height beside that row.
+inside `ChangesSplit`, so changes occupy the full height beside that row.
Host title, sharing, and sidebar actions remain available on the left. The Changes
button stays visible in split view: ghost while closed, accent text on a tinted
background while open, without the shared foreground pressed overlay; clicking
@@ -96,3 +108,26 @@ Where the host's route lists `changesSearch.namespace` in its `search`, they liv
in that split's search params (`s0.changes.pane`, `s0.changes.style`), so the
split router drops them when the split closes or navigates away; anywhere else,
such as a preview, they are local signals.
+
+## Lifecycle boundaries
+
+- `createChangesModel` owns source enablement and retains displayed patch text for
+ the same changeset during exit. Diff rendering never fetches a patch.
+- Generic `DiffView.Root` owns queued patch parsing and its unchanged-text cache.
+ `create-diff-reveal.ts` owns the stack's separate reveal queue, card registration,
+ and viewport observation. Selection anchoring stays in `DiffView.Stack`, because
+ later syntax highlighting also changes card heights. Each queue follows its
+ Solid owner and disposes only when that owner unmounts.
+- `create-split-presence.ts` separates visibility intent from retained pane presence
+ and motion. `ChangesSplit` owns Resize registration and retained host content.
+- `create-tree-layout.ts` owns tree presence and Resize-dependent companion frames.
+ The view keeps the tree's owner and moves its DOM between wide and drawer docks.
+- `create-animation-group.ts` shares cancellation, stale completion guards, and
+ synchronous finish/release mechanics. It does not own mount policy or geometry.
+ Pane translation and tree width collapse keep separate timing and presence policy.
+- Drawer `Dialog.Content` releases on close immediately; only an inert visual frame
+ survives exit. Do not retain the dialog just to retain the tree or its animation.
+
+The `changes` route namespace, existing `agent-changes:*` storage prefixes, and
+query-cache namespace remain unchanged after the feature rename. The debug gallery
+also keeps its existing `agent-changes-ui` route ID.
diff --git a/apps/web/src/features/agent-changes/agent-changes.test.tsx b/apps/web/src/features/changes/agent-session-changes.test.tsx
similarity index 92%
rename from apps/web/src/features/agent-changes/agent-changes.test.tsx
rename to apps/web/src/features/changes/agent-session-changes.test.tsx
index 587f1a3749..eb170549ee 100644
--- a/apps/web/src/features/agent-changes/agent-changes.test.tsx
+++ b/apps/web/src/features/changes/agent-session-changes.test.tsx
@@ -2,16 +2,10 @@ import type { AgentSessionResponse } from '@service-agent-harness/generated/sche
import { render, screen } from '@solidjs/testing-library';
import { createSignal } from 'solid-js';
import { beforeEach, describe, expect, it, vi } from 'vitest';
-import {
- AgentChangesProvider,
- ChangesHandoff,
- ChangesToggle,
-} from './agent-changes';
-import { useAgentChanges } from './context/agent-changes-controller';
-import {
- createMockAgentChangesContext,
- mockChangeset,
-} from './tests/mock-context';
+import { AgentChangesProvider } from './agent-session-changes';
+import { ChangesHandoff, ChangesToggle } from './changes';
+import { useChanges } from './context/changes-controller';
+import { createMockChangesContext, mockChangeset } from './tests/mock-context';
const [session, setSession] = createSignal<AgentSessionResponse>();
const [stats, setStats] = createSignal<{
@@ -34,7 +28,7 @@ vi.mock('../block-agent/context/AgentSessionContext', () => ({
vi.mock('./queries/session-changes', () => ({
createSessionChangesSource: (sessionId: () => string | undefined) => {
- const context = createMockAgentChangesContext({
+ const context = createMockChangesContext({
summary: { capturing: false, changeset: mockChangeset() },
});
return {
@@ -64,7 +58,7 @@ function sessionWith(fields: {
}
function ChangesHostMetadata() {
- const { context, changeCounts } = useAgentChanges();
+ const { context, changeCounts } = useChanges();
return (
<>
<span aria-label="PR title">{context.host.pullRequestTitle?.()}</span>
diff --git a/apps/web/src/features/agent-changes/agent-changes.tsx b/apps/web/src/features/changes/agent-session-changes.tsx
similarity index 55%
rename from apps/web/src/features/agent-changes/agent-changes.tsx
rename to apps/web/src/features/changes/agent-session-changes.tsx
index 454395aff9..2c9f74f8bb 100644
--- a/apps/web/src/features/agent-changes/agent-changes.tsx
+++ b/apps/web/src/features/changes/agent-session-changes.tsx
@@ -1,41 +1,20 @@
/**
- * Production entry point for the Changes pane.
+ * Agent-session adapter for the shared Changes feature.
*
- * Builds the controller from the real adapters: the agent-harness changes
- * queries, and the surrounding agent-session block for posting prompts and
- * reading the linked pull request. Hosts mount `AgentChangesProvider`
- * inside `AgentSessionProvider`, then place the split, the toggle, the
- * hand-off card, and the notes chip where they belong.
+ * Only this entry reads AgentSessionContext, gates harness queries, and enables
+ * prompt-based note sending. Shared UI and controller setup live in changes.tsx.
*/
import { isCoderHarness } from '@app/features/agents-view/core/agent-kind';
import { toast } from '@core/component/Toast/Toast';
-import { openExternalUrl } from '@core/util/url';
-import { createSignal, type ParentProps } from 'solid-js';
+import type { ParentProps } from 'solid-js';
import { useAgentSession } from '../block-agent/context/AgentSessionContext';
-import type { ChangesHost } from './context/agent-changes-context';
-import { AgentChangesControllerProvider } from './context/agent-changes-controller';
-import { createPaneViewState } from './pane-view-state';
-import { createAgentChanges } from './primitives/create-agent-changes';
+import { createBrowserChangesActions } from './browser-host';
+import { ChangesProvider } from './changes';
+import type { ChangesHost } from './context/changes-context';
import { createPullRequestStatsSource } from './queries/pull-request-stats';
import { createSessionChangesSource } from './queries/session-changes';
-export { AgentChangesSplit } from './views/AgentChangesSplit';
-export {
- ChangesHandoff,
- ChangesToggle,
- ReviewNotesDock,
-} from './views/SessionChangesControls';
-
-export async function copyText(text: string): Promise<boolean> {
- try {
- await navigator.clipboard.writeText(text);
- return true;
- } catch {
- return false;
- }
-}
-
export function AgentChangesProvider(props: ParentProps) {
const session = useAgentSession();
const pullRequestUrl = () => session.session()?.pullRequestUrl ?? undefined;
@@ -75,23 +54,11 @@ export function AgentChangesProvider(props: ParentProps) {
},
canHaveChanges,
pullRequestUrl,
- openExternal: openExternalUrl,
- copyText,
- notify: (message, tone) => {
- if (tone === 'success') toast.success(message);
- else toast.failure(message);
- },
+ ...createBrowserChangesActions(),
};
- const view = createPaneViewState();
- const [dismissed, setDismissed] = createSignal<string>();
- const controller = createAgentChanges({
- context: { source, host },
- view,
- dismissed: [dismissed, (id) => setDismissed(id)],
- });
return (
- <AgentChangesControllerProvider value={controller}>
+ <ChangesProvider context={{ source, host }}>
{props.children}
- </AgentChangesControllerProvider>
+ </ChangesProvider>
);
}
diff --git a/apps/web/src/features/changes/browser-host.ts b/apps/web/src/features/changes/browser-host.ts
new file mode 100644
index 0000000000..1c72bef111
--- /dev/null
+++ b/apps/web/src/features/changes/browser-host.ts
@@ -0,0 +1,25 @@
+import { toast } from '@core/component/Toast/Toast';
+import { openExternalUrl } from '@core/util/url';
+import type { ChangesHost } from './context/changes-context';
+
+/** Browser actions shared by production hosts, never implicit controller defaults. */
+export function createBrowserChangesActions(): Pick<
+ ChangesHost,
+ 'copyText' | 'openExternal' | 'notify'
+> {
+ return {
+ openExternal: openExternalUrl,
+ copyText: async (text) => {
+ try {
+ await navigator.clipboard.writeText(text);
+ return true;
+ } catch {
+ return false;
+ }
+ },
+ notify: (message, tone) => {
+ if (tone === 'success') toast.success(message);
+ else toast.failure(message);
+ },
+ };
+}
diff --git a/apps/web/src/features/agent-changes/changes-search.ts b/apps/web/src/features/changes/changes-search.ts
similarity index 100%
rename from apps/web/src/features/agent-changes/changes-search.ts
rename to apps/web/src/features/changes/changes-search.ts
diff --git a/apps/web/src/features/changes/changes.tsx b/apps/web/src/features/changes/changes.tsx
new file mode 100644
index 0000000000..8b25ea3b11
--- /dev/null
+++ b/apps/web/src/features/changes/changes.tsx
@@ -0,0 +1,37 @@
+/** Shared composition for PR, agent-session, and preview Changes hosts. */
+import { createSignal, type ParentProps } from 'solid-js';
+import type { ChangesContext, PaneViewState } from './context/changes-context';
+import { ChangesControllerProvider } from './context/changes-controller';
+import { createPaneViewState } from './pane-view-state';
+import { createChanges } from './primitives/create-changes';
+
+export type { ChangesHost, ChangesSource } from './context/changes-context';
+export { useChanges, useOptionalChanges } from './context/changes-controller';
+export {
+ ChangesHandoff,
+ ChangesToggle,
+ ReviewNotesDock,
+} from './views/ChangesControls';
+export { ChangesPane } from './views/ChangesPane';
+export { ChangesSplit } from './views/ChangesSplit';
+
+export function ChangesProvider(
+ props: ParentProps<{
+ context: ChangesContext;
+ view?: PaneViewState;
+ storage?: Pick<Storage, 'getItem' | 'setItem' | 'removeItem'>;
+ }>
+) {
+ const [dismissed, setDismissed] = createSignal<string>();
+ const controller = createChanges({
+ context: props.context,
+ view: props.view ?? createPaneViewState(),
+ storage: props.storage,
+ dismissed: [dismissed, (id) => setDismissed(id)],
+ });
+ return (
+ <ChangesControllerProvider value={controller}>
+ {props.children}
+ </ChangesControllerProvider>
+ );
+}
diff --git a/apps/web/src/features/agent-changes/components/ChangesHeader.tsx b/apps/web/src/features/changes/components/ChangesHeader.tsx
similarity index 100%
rename from apps/web/src/features/agent-changes/components/ChangesHeader.tsx
rename to apps/web/src/features/changes/components/ChangesHeader.tsx
diff --git a/apps/web/src/features/agent-changes/components/ChangesNotice.tsx b/apps/web/src/features/changes/components/ChangesNotice.tsx
similarity index 100%
rename from apps/web/src/features/agent-changes/components/ChangesNotice.tsx
rename to apps/web/src/features/changes/components/ChangesNotice.tsx
diff --git a/apps/web/src/features/agent-changes/components/ChangesReadyCard.tsx b/apps/web/src/features/changes/components/ChangesReadyCard.tsx
similarity index 100%
rename from apps/web/src/features/agent-changes/components/ChangesReadyCard.tsx
rename to apps/web/src/features/changes/components/ChangesReadyCard.tsx
diff --git a/apps/web/src/features/agent-changes/components/ChangesToggleButton.tsx b/apps/web/src/features/changes/components/ChangesToggleButton.tsx
similarity index 100%
rename from apps/web/src/features/agent-changes/components/ChangesToggleButton.tsx
rename to apps/web/src/features/changes/components/ChangesToggleButton.tsx
diff --git a/apps/web/src/features/agent-changes/components/CopyFilePathButton.tsx b/apps/web/src/features/changes/components/CopyFilePathButton.tsx
similarity index 100%
rename from apps/web/src/features/agent-changes/components/CopyFilePathButton.tsx
rename to apps/web/src/features/changes/components/CopyFilePathButton.tsx
diff --git a/apps/web/src/features/agent-changes/components/NoteAnnotation.tsx b/apps/web/src/features/changes/components/NoteAnnotation.tsx
similarity index 100%
rename from apps/web/src/features/agent-changes/components/NoteAnnotation.tsx
rename to apps/web/src/features/changes/components/NoteAnnotation.tsx
diff --git a/apps/web/src/features/agent-changes/components/ReviewNotesChip.test.tsx b/apps/web/src/features/changes/components/ReviewNotesChip.test.tsx
similarity index 100%
rename from apps/web/src/features/agent-changes/components/ReviewNotesChip.test.tsx
rename to apps/web/src/features/changes/components/ReviewNotesChip.test.tsx
diff --git a/apps/web/src/features/agent-changes/components/ReviewNotesChip.tsx b/apps/web/src/features/changes/components/ReviewNotesChip.tsx
similarity index 100%
rename from apps/web/src/features/agent-changes/components/ReviewNotesChip.tsx
rename to apps/web/src/features/changes/components/ReviewNotesChip.tsx
diff --git a/apps/web/src/features/agent-changes/context/agent-changes-context.ts b/apps/web/src/features/changes/context/changes-context.ts
similarity index 87%
rename from apps/web/src/features/agent-changes/context/agent-changes-context.ts
rename to apps/web/src/features/changes/context/changes-context.ts
index cf0db758f9..2493ec2f68 100644
--- a/apps/web/src/features/agent-changes/context/agent-changes-context.ts
+++ b/apps/web/src/features/changes/context/changes-context.ts
@@ -2,14 +2,13 @@
* The capabilities the Changes pane needs from its host, and the contract
* its views consume.
*
- * Production wiring (`../agent-changes.tsx`) builds these from the real
- * queries and the agent-session block; tests hand in fakes. Nothing under
- * `queries/`, `primitives/`, `components/`, or `views/` imports app
- * singletons directly.
+ * Host adapters supply source reads and explicit actions. changes.tsx builds
+ * the shared controller; tests supply fakes. The contract has no production
+ * service dependencies or implicit host fallback.
*/
import type { Accessor } from 'solid-js';
-import type { SessionChanges } from '../core/changeset';
+import type { ChangesSummary } from '../core/changeset';
import type { DiffStyle, PaneLayout } from '../core/layout';
export type QueryStatus = 'idle' | 'pending' | 'error' | 'success';
@@ -24,7 +23,7 @@ export type PatchRead = {
/** How the pane reads and refreshes a pull request snapshot. */
export type ChangesSource = {
/** The latest summary; undefined until the first read lands. */
- summary: Accessor<SessionChanges | undefined>;
+ summary: Accessor<ChangesSummary | undefined>;
summaryStatus: Accessor<QueryStatus>;
/**
* Read the patch behind a changeset. Runs only while `enabled` is true, so
@@ -78,7 +77,7 @@ export type PaneViewState = {
setDiffStyle: (style: DiffStyle) => void;
};
-export type AgentChangesContext = {
+export type ChangesContext = {
source: ChangesSource;
host: ChangesHost;
};
diff --git a/apps/web/src/features/agent-changes/context/agent-changes-controller.tsx b/apps/web/src/features/changes/context/changes-controller.tsx
similarity index 51%
rename from apps/web/src/features/agent-changes/context/agent-changes-controller.tsx
rename to apps/web/src/features/changes/context/changes-controller.tsx
index b0eba0c005..313562609b 100644
--- a/apps/web/src/features/agent-changes/context/agent-changes-controller.tsx
+++ b/apps/web/src/features/changes/context/changes-controller.tsx
@@ -5,21 +5,21 @@
*/
import { createContext, useContext } from 'solid-js';
-import type { AgentChangesController } from '../primitives/create-agent-changes';
+import type { ChangesController } from '../primitives/create-changes';
-const Context = createContext<AgentChangesController>();
+const Context = createContext<ChangesController>();
-export const AgentChangesControllerProvider = Context.Provider;
+export const ChangesControllerProvider = Context.Provider;
-export function useAgentChanges(): AgentChangesController {
+export function useChanges(): ChangesController {
const controller = useContext(Context);
if (!controller) {
- throw new Error('AgentChangesControllerProvider is required');
+ throw new Error('ChangesControllerProvider is required');
}
return controller;
}
/** The controller when a host mounted one; undefined outside the pane. */
-export function useOptionalAgentChanges(): AgentChangesController | undefined {
+export function useOptionalChanges(): ChangesController | undefined {
return useContext(Context);
}
diff --git a/apps/web/src/features/agent-changes/core/changeset.test.ts b/apps/web/src/features/changes/core/changeset.test.ts
similarity index 100%
rename from apps/web/src/features/agent-changes/core/changeset.test.ts
rename to apps/web/src/features/changes/core/changeset.test.ts
diff --git a/apps/web/src/features/agent-changes/core/changeset.ts b/apps/web/src/features/changes/core/changeset.ts
similarity index 95%
rename from apps/web/src/features/agent-changes/core/changeset.ts
rename to apps/web/src/features/changes/core/changeset.ts
index c81f4af301..cfd0fd32a0 100644
--- a/apps/web/src/features/agent-changes/core/changeset.ts
+++ b/apps/web/src/features/changes/core/changeset.ts
@@ -1,5 +1,5 @@
/**
- * The vocabulary of a session's captured changes.
+ * The vocabulary of a captured changes snapshot.
*
* Pure types and functions: what a changed file is, how a capture went, and
* the small derivations the pane shows (ranges, totals). A `ChangedFile`
@@ -30,7 +30,7 @@ export type GitRef = {
sha?: string;
};
-/** One capture of a session's changes. */
+/** One captured snapshot between a base and head. */
export type Changeset = {
/** Changes with every capture, so it doubles as a cache key for the patch. */
id: string;
@@ -60,8 +60,8 @@ export type CaptureAttempt = {
error?: string;
};
-/** Everything the summary endpoint says about a session's changes. */
-export type SessionChanges = {
+/** The source's snapshot and latest capture attempt, when available. */
+export type ChangesSummary = {
changeset?: Changeset;
attempt?: CaptureAttempt;
/** A capture is running right now. */
@@ -112,7 +112,7 @@ export type ChangesState =
| { kind: 'none' };
export function changesState(
- summary: SessionChanges | undefined,
+ summary: ChangesSummary | undefined,
summaryStatus: 'idle' | 'pending' | 'error' | 'success' = summary
? 'success'
: 'pending'
diff --git a/apps/web/src/features/agent-changes/core/layout.test.ts b/apps/web/src/features/changes/core/layout.test.ts
similarity index 89%
rename from apps/web/src/features/agent-changes/core/layout.test.ts
rename to apps/web/src/features/changes/core/layout.test.ts
index a1204c0d3b..b79d6df991 100644
--- a/apps/web/src/features/agent-changes/core/layout.test.ts
+++ b/apps/web/src/features/changes/core/layout.test.ts
@@ -4,7 +4,7 @@ import {
DEFAULT_CHANGES_SHARE,
ensureChangesVisible,
isChangesVisible,
- isSessionVisible,
+ isHostVisible,
toggleChanges,
toggleSpotlight,
} from './layout';
@@ -30,8 +30,8 @@ describe('layout moves', () => {
it('knows which panes are on screen', () => {
expect(isChangesVisible('closed')).toBe(false);
- expect(isSessionVisible('full')).toBe(false);
- expect(isChangesVisible('split') && isSessionVisible('split')).toBe(true);
+ expect(isHostVisible('full')).toBe(false);
+ expect(isChangesVisible('split') && isHostVisible('split')).toBe(true);
});
});
diff --git a/apps/web/src/features/agent-changes/core/layout.ts b/apps/web/src/features/changes/core/layout.ts
similarity index 96%
rename from apps/web/src/features/agent-changes/core/layout.ts
rename to apps/web/src/features/changes/core/layout.ts
index 1e5c9b6f4e..95324f20c8 100644
--- a/apps/web/src/features/agent-changes/core/layout.ts
+++ b/apps/web/src/features/changes/core/layout.ts
@@ -24,7 +24,7 @@ export function isChangesVisible(layout: PaneLayout): boolean {
return layout !== 'closed';
}
-export function isSessionVisible(layout: PaneLayout): boolean {
+export function isHostVisible(layout: PaneLayout): boolean {
return layout !== 'full';
}
diff --git a/apps/web/src/features/agent-changes/core/pull-request.ts b/apps/web/src/features/changes/core/pull-request.ts
similarity index 100%
rename from apps/web/src/features/agent-changes/core/pull-request.ts
rename to apps/web/src/features/changes/core/pull-request.ts
diff --git a/apps/web/src/features/agent-changes/core/review-notes.test.ts b/apps/web/src/features/changes/core/review-notes.test.ts
similarity index 100%
rename from apps/web/src/features/agent-changes/core/review-notes.test.ts
rename to apps/web/src/features/changes/core/review-notes.test.ts
diff --git a/apps/web/src/features/agent-changes/core/review-notes.ts b/apps/web/src/features/changes/core/review-notes.ts
similarity index 100%
rename from apps/web/src/features/agent-changes/core/review-notes.ts
rename to apps/web/src/features/changes/core/review-notes.ts
diff --git a/apps/web/src/features/agent-changes/debug/Gallery.tsx b/apps/web/src/features/changes/debug/Gallery.tsx
similarity index 90%
rename from apps/web/src/features/agent-changes/debug/Gallery.tsx
rename to apps/web/src/features/changes/debug/Gallery.tsx
index f13ee896d8..431064043f 100644
--- a/apps/web/src/features/agent-changes/debug/Gallery.tsx
+++ b/apps/web/src/features/changes/debug/Gallery.tsx
@@ -9,16 +9,16 @@ import { SAMPLE_PATCH } from '@app/components/diff-view/debug/fixtures';
import { QueuedPrompts } from '@app/features/block-agent/ui';
import { Button } from '@ui';
import { createSignal, For, Show } from 'solid-js';
-import { AgentChangesControllerProvider } from '../context/agent-changes-controller';
+import { ChangesControllerProvider } from '../context/changes-controller';
import { createPaneViewState } from '../pane-view-state';
-import { createAgentChanges } from '../primitives/create-agent-changes';
-import { createMockAgentChangesContext } from '../tests/mock-context';
-import { AgentChangesSplit } from '../views/AgentChangesSplit';
+import { createChanges } from '../primitives/create-changes';
+import { createMockChangesContext } from '../tests/mock-context';
import {
ChangesHandoff,
ChangesToggle,
ReviewNotesDock,
-} from '../views/SessionChangesControls';
+} from '../views/ChangesControls';
+import { ChangesSplit } from '../views/ChangesSplit';
import { gallerySummary } from './gallery-fixture';
const GALLERY_QUEUE = Array.from({ length: 12 }, (_, index) => ({
@@ -37,15 +37,15 @@ const GALLERY_QUEUE = Array.from({ length: 12 }, (_, index) => ({
: `Queued follow-up #${index + 1}: tighten the unread rail query.`,
}));
-export default function AgentChangesGallery() {
- const context = createMockAgentChangesContext({
+export default function ChangesGallery() {
+ const context = createMockChangesContext({
summary: gallerySummary(),
patch: SAMPLE_PATCH,
sessionId: 'gallery-session',
});
const view = createPaneViewState();
const [dismissed, setDismissed] = createSignal<string>();
- const controller = createAgentChanges({
+ const controller = createChanges({
context,
view,
dismissed: [dismissed, setDismissed],
@@ -81,9 +81,9 @@ export default function AgentChangesGallery() {
};
return (
- <AgentChangesControllerProvider value={controller}>
+ <ChangesControllerProvider value={controller}>
<div class="flex h-full min-h-0 flex-col bg-panel">
- <AgentChangesSplit>
+ <ChangesSplit>
<header class="flex h-12 shrink-0 items-center gap-2 border-b border-edge px-4">
<h2 class="min-w-0 flex-1 truncate text-sm font-semibold text-ink">
Stale unread dots on archived sessions
@@ -168,8 +168,8 @@ export default function AgentChangesGallery() {
Message the agent, @mention anything
</div>
</div>
- </AgentChangesSplit>
+ </ChangesSplit>
</div>
- </AgentChangesControllerProvider>
+ </ChangesControllerProvider>
);
}
diff --git a/apps/web/src/features/agent-changes/debug/gallery-fixture.ts b/apps/web/src/features/changes/debug/gallery-fixture.ts
similarity index 87%
rename from apps/web/src/features/agent-changes/debug/gallery-fixture.ts
rename to apps/web/src/features/changes/debug/gallery-fixture.ts
index a20e51c492..968309c3cb 100644
--- a/apps/web/src/features/agent-changes/debug/gallery-fixture.ts
+++ b/apps/web/src/features/changes/debug/gallery-fixture.ts
@@ -2,9 +2,9 @@ import {
SAMPLE_FILES,
SAMPLE_PATCH,
} from '@app/components/diff-view/debug/fixtures';
-import type { SessionChanges } from '../core/changeset';
+import type { ChangesSummary } from '../core/changeset';
-export function gallerySummary(): SessionChanges {
+export function gallerySummary(): ChangesSummary {
return {
capturing: false,
attempt: {
diff --git a/apps/web/src/features/agent-changes/pane-view-state.ts b/apps/web/src/features/changes/pane-view-state.ts
similarity index 94%
rename from apps/web/src/features/agent-changes/pane-view-state.ts
rename to apps/web/src/features/changes/pane-view-state.ts
index 853490f53d..ea8a132e4f 100644
--- a/apps/web/src/features/agent-changes/pane-view-state.ts
+++ b/apps/web/src/features/changes/pane-view-state.ts
@@ -4,7 +4,7 @@ import {
} from '@app/lib/split-router';
import { createSignal } from 'solid-js';
import { changesSearch } from './changes-search';
-import type { PaneViewState } from './context/agent-changes-context';
+import type { PaneViewState } from './context/changes-context';
import type { DiffStyle, PaneLayout } from './core/layout';
/** View state that lives only as long as the host, starting closed. */
diff --git a/apps/web/src/features/agent-changes/primitives/create-changes-model.test.ts b/apps/web/src/features/changes/primitives/create-changes-model.test.ts
similarity index 96%
rename from apps/web/src/features/agent-changes/primitives/create-changes-model.test.ts
rename to apps/web/src/features/changes/primitives/create-changes-model.test.ts
index 612711d8c1..7e75b34007 100644
--- a/apps/web/src/features/agent-changes/primitives/create-changes-model.test.ts
+++ b/apps/web/src/features/changes/primitives/create-changes-model.test.ts
@@ -4,8 +4,8 @@ import type {
ChangesSource,
PatchRead,
QueryStatus,
-} from '../context/agent-changes-context';
-import type { SessionChanges } from '../core/changeset';
+} from '../context/changes-context';
+import type { ChangesSummary } from '../core/changeset';
import { createChangesModel } from './create-changes-model';
const PATCH = `diff --git a/a.ts b/a.ts
@@ -19,7 +19,7 @@ const PATCH = `diff --git a/a.ts b/a.ts
function summaryWith(
files: string[],
patchBytes = PATCH.length
-): SessionChanges {
+): ChangesSummary {
return {
capturing: false,
changeset: {
@@ -44,7 +44,7 @@ function summaryWith(
}
function setup() {
- const [summary, setSummary] = createSignal<SessionChanges>();
+ const [summary, setSummary] = createSignal<ChangesSummary>();
const [patchText, setPatchText] = createSignal<string>();
const [patchStatus, setPatchStatus] = createSignal<QueryStatus>('idle');
const [visible, setVisible] = createSignal(false);
diff --git a/apps/web/src/features/agent-changes/primitives/create-changes-model.ts b/apps/web/src/features/changes/primitives/create-changes-model.ts
similarity index 97%
rename from apps/web/src/features/agent-changes/primitives/create-changes-model.ts
rename to apps/web/src/features/changes/primitives/create-changes-model.ts
index f93c60dfdb..32e8217108 100644
--- a/apps/web/src/features/agent-changes/primitives/create-changes-model.ts
+++ b/apps/web/src/features/changes/primitives/create-changes-model.ts
@@ -5,10 +5,7 @@
*/
import { type Accessor, createMemo, createSignal } from 'solid-js';
-import type {
- ChangesSource,
- QueryStatus,
-} from '../context/agent-changes-context';
+import type { ChangesSource, QueryStatus } from '../context/changes-context';
import {
type ChangedFile,
type Changeset,
diff --git a/apps/web/src/features/agent-changes/primitives/create-changes-narrow.ts b/apps/web/src/features/changes/primitives/create-changes-narrow.ts
similarity index 100%
rename from apps/web/src/features/agent-changes/primitives/create-changes-narrow.ts
rename to apps/web/src/features/changes/primitives/create-changes-narrow.ts
diff --git a/apps/web/src/features/agent-changes/primitives/create-agent-changes.ts b/apps/web/src/features/changes/primitives/create-changes.ts
similarity index 90%
rename from apps/web/src/features/agent-changes/primitives/create-agent-changes.ts
rename to apps/web/src/features/changes/primitives/create-changes.ts
index 228e0ac4b9..604b093531 100644
--- a/apps/web/src/features/agent-changes/primitives/create-agent-changes.ts
+++ b/apps/web/src/features/changes/primitives/create-changes.ts
@@ -4,10 +4,7 @@
*/
import type { Accessor } from 'solid-js';
-import type {
- AgentChangesContext,
- PaneViewState,
-} from '../context/agent-changes-context';
+import type { ChangesContext, PaneViewState } from '../context/changes-context';
import type { DiffStyle } from '../core/layout';
import { formatNotesForAgent, sendableNotes } from '../core/review-notes';
import { type ChangesModel, createChangesModel } from './create-changes-model';
@@ -22,8 +19,8 @@ import {
export type { DiffStyle } from '../core/layout';
-export type AgentChangesController = {
- context: AgentChangesContext;
+export type ChangesController = {
+ context: ChangesContext;
/** False when the host can never have changes; every control renders nothing. */
available: Accessor<boolean>;
layout: PaneLayoutController;
@@ -47,20 +44,20 @@ export type AgentChangesController = {
copyPath: (path: string) => Promise<boolean>;
};
-export function createAgentChanges(options: {
- context: AgentChangesContext;
+export function createChanges(options: {
+ context: ChangesContext;
storage?: Pick<Storage, 'getItem' | 'setItem' | 'removeItem'>;
/** The pane's layout and diff style, from `createPaneViewState`. */
view: PaneViewState;
- /** Per-session "dismissed for changeset id" memory. */
+ /** Per-host "dismissed for changeset id" memory. */
dismissed: [
get: Accessor<string | undefined>,
set: (changesetId: string | undefined) => void,
];
-}): AgentChangesController {
+}): ChangesController {
const { source, host } = options.context;
const layout = createPaneLayout({
- sessionId: host.scopeKey,
+ scopeKey: host.scopeKey,
storage: options.storage,
layout: [options.view.layout, options.view.setLayout],
});
@@ -69,7 +66,7 @@ export function createAgentChanges(options: {
changesVisible: layout.changesVisible,
});
const review = createReviewState({
- sessionId: host.scopeKey,
+ scopeKey: host.scopeKey,
changeset: model.changeset,
storage: options.storage,
});
diff --git a/apps/web/src/features/agent-changes/primitives/create-pane-layout.ts b/apps/web/src/features/changes/primitives/create-pane-layout.ts
similarity index 89%
rename from apps/web/src/features/agent-changes/primitives/create-pane-layout.ts
rename to apps/web/src/features/changes/primitives/create-pane-layout.ts
index af8e84d1c0..7d8b982021 100644
--- a/apps/web/src/features/agent-changes/primitives/create-pane-layout.ts
+++ b/apps/web/src/features/changes/primitives/create-pane-layout.ts
@@ -9,12 +9,12 @@ import {
DEFAULT_CHANGES_SHARE,
ensureChangesVisible,
isChangesVisible,
- isSessionVisible,
+ isHostVisible,
type PaneLayout,
toggleChanges,
toggleSpotlight,
} from '../core/layout';
-import { createPersistedSessionState } from './create-persisted-session-state';
+import { createPersistedScopeState } from './create-persisted-scope-state';
export const DEFAULT_TREE_WIDTH = 256;
export const MIN_TREE_WIDTH = 144;
@@ -28,7 +28,7 @@ function clampTreeWidth(width: number): number {
export type PaneLayoutController = {
layout: Accessor<PaneLayout>;
changesVisible: Accessor<boolean>;
- sessionVisible: Accessor<boolean>;
+ hostVisible: Accessor<boolean>;
/** Percent of the width the changes pane takes in the split. */
changesShare: Accessor<number>;
setChangesShare: (share: number) => void;
@@ -67,13 +67,14 @@ function parseLayout(raw: unknown): StoredLayout | undefined {
}
export function createPaneLayout(options: {
- sessionId: Accessor<string | undefined>;
+ scopeKey: Accessor<string | undefined>;
layout: [get: Accessor<PaneLayout>, set: (layout: PaneLayout) => void];
storage?: Pick<Storage, 'getItem' | 'setItem' | 'removeItem'>;
}): PaneLayoutController {
const [layout, setLayout] = options.layout;
- const [stored, setStored] = createPersistedSessionState<StoredLayout>({
- sessionId: options.sessionId,
+ const [stored, setStored] = createPersistedScopeState<StoredLayout>({
+ scopeKey: options.scopeKey,
+ // Keep existing stored preferences across the shared-feature rename.
namespace: 'agent-changes:layout',
initial: () => ({
share: DEFAULT_CHANGES_SHARE,
@@ -89,7 +90,7 @@ export function createPaneLayout(options: {
return {
layout,
changesVisible: () => isChangesVisible(layout()),
- sessionVisible: () => isSessionVisible(layout()),
+ hostVisible: () => isHostVisible(layout()),
changesShare: () => stored().share,
setChangesShare: (share) =>
setStored((previous) => ({
diff --git a/apps/web/src/features/agent-changes/primitives/create-persisted-session-state.test.ts b/apps/web/src/features/changes/primitives/create-persisted-scope-state.test.ts
similarity index 76%
rename from apps/web/src/features/agent-changes/primitives/create-persisted-session-state.test.ts
rename to apps/web/src/features/changes/primitives/create-persisted-scope-state.test.ts
index 66b3de6c81..1c67f1436e 100644
--- a/apps/web/src/features/agent-changes/primitives/create-persisted-session-state.test.ts
+++ b/apps/web/src/features/changes/primitives/create-persisted-scope-state.test.ts
@@ -1,6 +1,6 @@
import { createRoot, createSignal } from 'solid-js';
import { describe, expect, it } from 'vitest';
-import { createPersistedSessionState } from './create-persisted-session-state';
+import { createPersistedScopeState } from './create-persisted-scope-state';
function memoryStorage() {
const map = new Map<string, string>();
@@ -12,13 +12,13 @@ function memoryStorage() {
};
}
-describe('createPersistedSessionState', () => {
+describe('createPersistedScopeState', () => {
it('writes under the session key and reloads per session', () => {
createRoot((dispose) => {
const storage = memoryStorage();
- const [sessionId, setSessionId] = createSignal<string | undefined>('s1');
- const [count, setCount] = createPersistedSessionState<number>({
- sessionId,
+ const [scopeKey, setSessionId] = createSignal<string | undefined>('s1');
+ const [count, setCount] = createPersistedScopeState<number>({
+ scopeKey,
namespace: 'test',
initial: () => 0,
parse: (raw) => (typeof raw === 'number' ? raw : undefined),
@@ -44,9 +44,9 @@ describe('createPersistedSessionState', () => {
createRoot((dispose) => {
const storage = memoryStorage();
storage.map.set('test:s1', '{not json');
- const [sessionId] = createSignal<string | undefined>('s1');
- const [value, setValue] = createPersistedSessionState<number>({
- sessionId,
+ const [scopeKey] = createSignal<string | undefined>('s1');
+ const [value, setValue] = createPersistedScopeState<number>({
+ scopeKey,
namespace: 'test',
initial: () => 1,
parse: (raw) => (typeof raw === 'number' ? raw : undefined),
@@ -55,8 +55,8 @@ describe('createPersistedSessionState', () => {
expect(value()).toBe(1);
const [none] = createSignal<string | undefined>(undefined);
- const [memory, setMemory] = createPersistedSessionState<number>({
- sessionId: none,
+ const [memory, setMemory] = createPersistedScopeState<number>({
+ scopeKey: none,
namespace: 'test',
initial: () => 1,
parse: (raw) => (typeof raw === 'number' ? raw : undefined),
diff --git a/apps/web/src/features/agent-changes/primitives/create-persisted-session-state.ts b/apps/web/src/features/changes/primitives/create-persisted-scope-state.ts
similarity index 54%
rename from apps/web/src/features/agent-changes/primitives/create-persisted-session-state.ts
rename to apps/web/src/features/changes/primitives/create-persisted-scope-state.ts
index b87ac12d9c..f2cd3340b2 100644
--- a/apps/web/src/features/agent-changes/primitives/create-persisted-session-state.ts
+++ b/apps/web/src/features/changes/primitives/create-persisted-scope-state.ts
@@ -1,18 +1,18 @@
/**
- * A signal scoped to one session and mirrored into `localStorage`, so a
+ * A signal scoped to one host and mirrored into `localStorage`, so a
* reload keeps the reviewer's place: which diffs they collapsed, the
* notes they have not sent yet, how the panes were laid out.
*
- * The value re-loads whenever the session id changes; a missing id keeps
+ * The value re-loads whenever the scope key changes; a missing key keeps
* the state in memory only.
*/
import { type Accessor, createMemo, createSignal } from 'solid-js';
-export type PersistedSessionStateOptions<T> = {
- /** The session the state belongs to; undefined while it is unknown. */
- sessionId: Accessor<string | undefined>;
- /** Storage key prefix; the session id is appended. */
+export type PersistedScopeStateOptions<T> = {
+ /** The host scope the state belongs to; undefined while it is unknown. */
+ scopeKey: Accessor<string | undefined>;
+ /** Storage key prefix; the scope key is appended. */
namespace: string;
initial: () => T;
/** Turn a stored JSON value back into state, or reject it with undefined. */
@@ -31,16 +31,16 @@ function defaultStorage():
}
}
-export function createPersistedSessionState<T>(
- options: PersistedSessionStateOptions<T>
+export function createPersistedScopeState<T>(
+ options: PersistedScopeStateOptions<T>
): [get: Accessor<T>, set: (next: T | ((previous: T) => T)) => void] {
const storage = options.storage ?? defaultStorage();
- const keyFor = (sessionId: string) => `${options.namespace}:${sessionId}`;
+ const keyFor = (scopeKey: string) => `${options.namespace}:${scopeKey}`;
- const load = (sessionId: string | undefined): T => {
- if (!sessionId || !storage) return options.initial();
+ const load = (scopeKey: string | undefined): T => {
+ if (!scopeKey || !storage) return options.initial();
try {
- const raw = storage.getItem(keyFor(sessionId));
+ const raw = storage.getItem(keyFor(scopeKey));
if (raw == null) return options.initial();
return options.parse(JSON.parse(raw)) ?? options.initial();
} catch {
@@ -48,30 +48,30 @@ export function createPersistedSessionState<T>(
}
};
- const save = (sessionId: string | undefined, value: T) => {
- if (!sessionId || !storage) return;
+ const save = (scopeKey: string | undefined, value: T) => {
+ if (!scopeKey || !storage) return;
try {
- storage.setItem(keyFor(sessionId), JSON.stringify(value));
+ storage.setItem(keyFor(scopeKey), JSON.stringify(value));
} catch {
// Storage full or unavailable: the in-memory state still works.
}
};
- // One signal per session id: switching sessions swaps to a freshly loaded
- // signal instead of writing one session's state under another's key.
+ // One signal per scope: switching hosts loads a fresh signal instead of
+ // writing one host's state under another's key.
const scoped = createMemo(() => {
- const sessionId = options.sessionId();
- const [value, setValue] = createSignal<T>(load(sessionId));
- return { sessionId, value, setValue };
+ const scopeKey = options.scopeKey();
+ const [value, setValue] = createSignal<T>(load(scopeKey));
+ return { scopeKey, value, setValue };
});
const get: Accessor<T> = () => scoped().value();
const set = (next: T | ((previous: T) => T)) => {
- const { sessionId, value, setValue } = scoped();
+ const { scopeKey, value, setValue } = scoped();
const resolved =
typeof next === 'function' ? (next as (previous: T) => T)(value()) : next;
setValue(() => resolved);
- save(sessionId, resolved);
+ save(scopeKey, resolved);
};
return [get, set];
}
diff --git a/apps/web/src/features/agent-changes/primitives/create-review-state.test.ts b/apps/web/src/features/changes/primitives/create-review-state.test.ts
similarity index 99%
rename from apps/web/src/features/agent-changes/primitives/create-review-state.test.ts
rename to apps/web/src/features/changes/primitives/create-review-state.test.ts
index 23a02bd09a..d59150d173 100644
--- a/apps/web/src/features/agent-changes/primitives/create-review-state.test.ts
+++ b/apps/web/src/features/changes/primitives/create-review-state.test.ts
@@ -38,7 +38,7 @@ function setup() {
changeset('cs1', ['a.ts', 'b.ts'])
);
const review = createReviewState({
- sessionId: () => 's1',
+ scopeKey: () => 's1',
changeset: current,
storage: memoryStorage(),
now: () => 'T',
diff --git a/apps/web/src/features/agent-changes/primitives/create-review-state.ts b/apps/web/src/features/changes/primitives/create-review-state.ts
similarity index 95%
rename from apps/web/src/features/agent-changes/primitives/create-review-state.ts
rename to apps/web/src/features/changes/primitives/create-review-state.ts
index e1874f7708..5db1ddde14 100644
--- a/apps/web/src/features/agent-changes/primitives/create-review-state.ts
+++ b/apps/web/src/features/changes/primitives/create-review-state.ts
@@ -16,7 +16,7 @@ import {
queuedNotes,
type ReviewNote,
} from '../core/review-notes';
-import { createPersistedSessionState } from './create-persisted-session-state';
+import { createPersistedScopeState } from './create-persisted-scope-state';
export type ReviewController = {
collapsed: Accessor<ReadonlySet<string>>;
@@ -99,7 +99,7 @@ function toggleIn(list: readonly string[], path: string): string[] {
}
export function createReviewState(options: {
- sessionId: Accessor<string | undefined>;
+ scopeKey: Accessor<string | undefined>;
changeset: Accessor<Changeset | undefined>;
storage?: Pick<Storage, 'getItem' | 'setItem' | 'removeItem'>;
now?: () => string;
@@ -113,8 +113,9 @@ export function createReviewState(options: {
? crypto.randomUUID()
: `${Date.now()}-${Math.random().toString(36).slice(2)}`);
- const [stored, setStored] = createPersistedSessionState<StoredReview>({
- sessionId: options.sessionId,
+ const [stored, setStored] = createPersistedScopeState<StoredReview>({
+ scopeKey: options.scopeKey,
+ // Keep existing notes and collapse state across the shared-feature rename.
namespace: 'agent-changes:review',
initial: () => ({
changesetId: undefined,
diff --git a/apps/web/src/features/changes/primitives/create-split-presence.ts b/apps/web/src/features/changes/primitives/create-split-presence.ts
new file mode 100644
index 0000000000..658925fe8a
--- /dev/null
+++ b/apps/web/src/features/changes/primitives/create-split-presence.ts
@@ -0,0 +1,149 @@
+import {
+ type AnimationTarget,
+ createAnimationGroup,
+} from '@app/lib/utils/create-animation-group';
+import { createMediaQuery } from '@solid-primitives/media';
+import {
+ type Accessor,
+ createEffect,
+ createSignal,
+ on,
+ onCleanup,
+} from 'solid-js';
+
+/** Geometry belongs to Resize; these frames temporarily accompany the slide. */
+function splitFrames(
+ element: HTMLElement,
+ hostContent: HTMLElement | undefined,
+ opening: boolean,
+ interrupted: boolean
+): AnimationTarget[] {
+ const panel = element.parentElement;
+ if (!panel?.matches('[data-resize-panel]')) return [];
+ const host =
+ hostContent?.hidden || hostContent?.hasAttribute('data-slide-underlay')
+ ? undefined
+ : hostContent?.parentElement;
+ const gutter = panel.parentElement?.querySelector<HTMLElement>(
+ ':scope > [role="separator"]'
+ );
+ const frames: AnimationTarget[] = [];
+ if (host) {
+ frames.push({
+ target: host,
+ keyframes: [
+ {
+ width:
+ interrupted || !opening ? getComputedStyle(host).width : '100%',
+ },
+ { width: opening ? host.style.width : '100%' },
+ ],
+ });
+ }
+ if (gutter) {
+ gutter.inert = !opening;
+ frames.push({
+ target: gutter,
+ keyframes: [
+ {
+ transform:
+ interrupted || !opening
+ ? getComputedStyle(gutter).transform
+ : `translateX(${panel.style.width})`,
+ },
+ {
+ transform: opening
+ ? 'translateX(0)'
+ : `translateX(${panel.style.width})`,
+ },
+ ],
+ });
+ }
+ return frames;
+}
+
+/** Retain the pane's owner and Resize registration until its slide finishes. */
+export function createSplitPresence(
+ visible: Accessor<boolean>,
+ hostContent: Accessor<HTMLElement | undefined>
+) {
+ const reducedMotion = createMediaQuery('(prefers-reduced-motion: reduce)');
+ const [present, setPresent] = createSignal(visible());
+ const [transitioning, setTransitioning] = createSignal(false);
+ const motion = createAnimationGroup();
+ let element: HTMLDivElement | undefined;
+ let revision = 0;
+
+ const finish = () => {
+ revision += 1;
+ // Settle to current intent, not an interrupted animation's old endpoint.
+ setPresent(visible());
+ motion.cancel();
+ setTransitioning(false);
+ };
+ createEffect(
+ on(visible, (opening) => {
+ const current = ++revision;
+ setTransitioning(
+ !reducedMotion() && typeof HTMLElement.prototype.animate === 'function'
+ );
+ if (opening) setPresent(true);
+ if (!opening && (reducedMotion() || !element?.animate)) {
+ finish();
+ return;
+ }
+ queueMicrotask(() => {
+ if (current !== revision || !element) return;
+ // Read live styles before releasing the interrupted group's frames.
+ const interrupted = motion.running();
+ const transform = interrupted
+ ? getComputedStyle(element).transform
+ : opening
+ ? 'translateX(100%)'
+ : 'translateX(0)';
+ element.inert = !opening;
+ if (reducedMotion() || !element.animate) {
+ finish();
+ return;
+ }
+ const companions = splitFrames(
+ element,
+ hostContent(),
+ opening,
+ interrupted
+ );
+ motion.start(
+ [
+ {
+ target: element,
+ keyframes: [
+ { transform },
+ { transform: opening ? 'translateX(0)' : 'translateX(100%)' },
+ ],
+ },
+ ...companions,
+ ],
+ { duration: 220, easing: 'ease-in-out', fill: 'forwards' },
+ () => {
+ if (current === revision) setPresent(opening);
+ },
+ () => {
+ if (current === revision) setTransitioning(false);
+ }
+ );
+ });
+ })
+ );
+ onCleanup(() => {
+ revision += 1;
+ motion.cancel();
+ });
+ return {
+ present,
+ transitioning,
+ finish,
+ ref: (node: HTMLDivElement) => {
+ element = node;
+ },
+ };
+}
diff --git a/apps/web/src/features/changes/primitives/create-tree-layout.ts b/apps/web/src/features/changes/primitives/create-tree-layout.ts
new file mode 100644
index 0000000000..9dc5f0ff97
--- /dev/null
+++ b/apps/web/src/features/changes/primitives/create-tree-layout.ts
@@ -0,0 +1,112 @@
+import type { AnimationTarget } from '@app/lib/utils/create-animation-group';
+import type { ResizeZoneCtx } from '@core/component/Resize/types';
+import {
+ type Accessor,
+ createEffect,
+ createMemo,
+ createSignal,
+ on,
+} from 'solid-js';
+import { DEFAULT_TREE_WIDTH, MIN_TREE_WIDTH } from './create-pane-layout';
+
+type TreeTransition = { opening: boolean; from: number; interrupted: boolean };
+type TreeResizeZone = Pick<ResizeZoneCtx, 'size' | 'sizeOf'>;
+
+/** Pixel geometry and presence for the tree's Resize panel, not its DOM owner. */
+export function createTreeLayout(options: {
+ visible: Accessor<boolean>;
+ width: Accessor<number>;
+ dock: Accessor<HTMLElement | undefined>;
+ diff: Accessor<HTMLElement | undefined>;
+}) {
+ const [present, setPresent] = createSignal(options.visible());
+ let zone: TreeResizeZone | undefined;
+ let finishMotion: (() => void) | undefined;
+ let expandedSize = options.width;
+ const panel = () =>
+ options.dock()?.closest<HTMLElement>('[data-resize-panel]');
+ const finish = () => finishMotion?.();
+
+ const companions = ({ opening, from, interrupted }: TreeTransition) => {
+ const treePanel = panel();
+ const diffPanel = options.diff()?.parentElement;
+ const root = treePanel?.parentElement;
+ if (!treePanel || !diffPanel || !root) return [];
+ const width = zone?.size() ?? root.clientWidth;
+ const fromOffset = from > 0 ? from + 1 : 0;
+ const toOffset = opening ? expandedSize() + 1 : 0;
+ const current = getComputedStyle(diffPanel);
+ const frames: AnimationTarget[] = [
+ {
+ target: diffPanel,
+ keyframes: [
+ interrupted
+ ? { left: current.left, width: current.width }
+ : { left: `${fromOffset}px`, width: `${width - fromOffset}px` },
+ { left: `${toOffset}px`, width: `${width - toOffset}px` },
+ ],
+ },
+ ];
+ const gutter = root.querySelector<HTMLElement>(
+ ':scope > [role="separator"]'
+ );
+ if (gutter) {
+ gutter.inert = !opening;
+ gutter.setAttribute('aria-hidden', String(!opening));
+ const inset = Number.parseFloat(gutter.style.left) - expandedSize();
+ frames.push({
+ target: gutter,
+ keyframes: [
+ {
+ left:
+ interrupted && gutter.getAnimations?.().length
+ ? getComputedStyle(gutter).left
+ : `${from + inset}px`,
+ },
+ { left: `${(opening ? expandedSize() : 0) + inset}px` },
+ ],
+ });
+ }
+ return frames;
+ };
+
+ return {
+ present,
+ setPresent,
+ panel,
+ expandedSize: () => expandedSize(),
+ drawerWidth: () => {
+ const available = zone?.size() ?? DEFAULT_TREE_WIDTH;
+ return Math.min(
+ DEFAULT_TREE_WIDTH,
+ Math.max(Math.min(MIN_TREE_WIDTH, available), available - 32)
+ );
+ },
+ companions,
+ finish,
+ captureController: (controller: { finish: () => void }) => {
+ finishMotion = controller.finish;
+ },
+ captureZone: (ctx: TreeResizeZone) => {
+ if (zone === ctx) return;
+ zone = ctx;
+ const size = ctx.sizeOf('changes-file-tree');
+ expandedSize = createMemo<number>((previous) => {
+ const solved = size();
+ return options.visible() && solved > 0
+ ? solved
+ : (previous ?? options.width());
+ });
+ // Resize invalidates animation endpoints; settle before using new geometry.
+ createEffect(on(ctx.size, finish, { defer: true }));
+ },
+ settle: (event: PointerEvent | KeyboardEvent) => {
+ if (
+ event.target instanceof Element &&
+ event.target.closest('[role="separator"]')
+ ) {
+ finish();
+ }
+ },
+ };
+}
diff --git a/apps/web/src/features/changes/queries/changes-adapter.ts b/apps/web/src/features/changes/queries/changes-adapter.ts
new file mode 100644
index 0000000000..48058fb43a
--- /dev/null
+++ b/apps/web/src/features/changes/queries/changes-adapter.ts
@@ -0,0 +1,51 @@
+/** Shared wire decoding and query status, without session query dependencies. */
+import type {
+ ChangedFileDto,
+ ChangesetDto,
+ GitRefDto,
+} from '@service-agent-harness/generated/schemas';
+import type { QueryStatus } from '../context/changes-context';
+import type { ChangedFile, Changeset, GitRef } from '../core/changeset';
+
+function decodeRef(ref: GitRefDto): GitRef {
+ return { name: ref.name ?? undefined, sha: ref.sha ?? undefined };
+}
+
+function decodeFile(file: ChangedFileDto): ChangedFile {
+ return {
+ path: file.path,
+ previousPath: file.previousPath ?? undefined,
+ kind: file.kind,
+ additions: file.additions,
+ deletions: file.deletions,
+ binary: file.binary,
+ patchOmitted: file.patchOmitted,
+ };
+}
+
+export function decodeChangeset(dto: ChangesetDto): Changeset {
+ return {
+ id: dto.id,
+ repository: dto.repository ?? undefined,
+ base: decodeRef(dto.base),
+ head: decodeRef(dto.head),
+ files: dto.files.map(decodeFile),
+ additions: dto.additions,
+ deletions: dto.deletions,
+ patchBytes: dto.patchBytes,
+ truncated: dto.truncated,
+ capturedAt: dto.capturedAt,
+ };
+}
+
+export function queryStatus(query: {
+ isPending: boolean;
+ isError: boolean;
+ isSuccess: boolean;
+ fetchStatus: string;
+}): QueryStatus {
+ if (query.isSuccess) return 'success';
+ if (query.isError) return 'error';
+ if (query.isPending && query.fetchStatus === 'idle') return 'idle';
+ return 'pending';
+}
diff --git a/apps/web/src/features/agent-changes/queries/keys.ts b/apps/web/src/features/changes/queries/keys.ts
similarity index 72%
rename from apps/web/src/features/agent-changes/queries/keys.ts
rename to apps/web/src/features/changes/queries/keys.ts
index 7bd4b5796a..b3fd0eda41 100644
--- a/apps/web/src/features/agent-changes/queries/keys.ts
+++ b/apps/web/src/features/changes/queries/keys.ts
@@ -1,6 +1,6 @@
import { createQueryKeys } from '@lukemorales/query-key-factory';
-export const agentChangesKeys = createQueryKeys('agent-changes', {
+export const changesKeys = createQueryKeys('agent-changes', {
pullRequestStats: (githubKey: string, captureId: string) => ({
queryKey: [githubKey, captureId],
}),
diff --git a/apps/web/src/features/agent-changes/queries/pull-request-stats.test.ts b/apps/web/src/features/changes/queries/pull-request-stats.test.ts
similarity index 100%
rename from apps/web/src/features/agent-changes/queries/pull-request-stats.test.ts
rename to apps/web/src/features/changes/queries/pull-request-stats.test.ts
diff --git a/apps/web/src/features/agent-changes/queries/pull-request-stats.ts b/apps/web/src/features/changes/queries/pull-request-stats.ts
similarity index 93%
rename from apps/web/src/features/agent-changes/queries/pull-request-stats.ts
rename to apps/web/src/features/changes/queries/pull-request-stats.ts
index 7a60d95b93..54434b603f 100644
--- a/apps/web/src/features/agent-changes/queries/pull-request-stats.ts
+++ b/apps/web/src/features/changes/queries/pull-request-stats.ts
@@ -8,7 +8,7 @@ import {
prHtmlUrl,
toGithubKey,
} from '../../block-pr/util/prKey';
-import { agentChangesKeys } from './keys';
+import { changesKeys } from './keys';
export function pullRequestStatsQueryOptions(
url: string | undefined,
@@ -17,8 +17,7 @@ export function pullRequestStatsQueryOptions(
const reference = url ? parseGithubPrUrl(url) : null;
const githubKey = reference ? toGithubKey(reference) : '';
return {
- queryKey: agentChangesKeys.pullRequestStats(githubKey, captureId ?? '')
- .queryKey,
+ queryKey: changesKeys.pullRequestStats(githubKey, captureId ?? '').queryKey,
enabled: reference !== null,
queryFn: async () => {
if (!reference) return null;
diff --git a/apps/web/src/features/agent-changes/queries/session-changes.test.ts b/apps/web/src/features/changes/queries/session-changes.test.ts
similarity index 100%
rename from apps/web/src/features/agent-changes/queries/session-changes.test.ts
rename to apps/web/src/features/changes/queries/session-changes.test.ts
diff --git a/apps/web/src/features/agent-changes/queries/session-changes.ts b/apps/web/src/features/changes/queries/session-changes.ts
similarity index 60%
rename from apps/web/src/features/agent-changes/queries/session-changes.ts
rename to apps/web/src/features/changes/queries/session-changes.ts
index 19e08474ba..acc3059fd5 100644
--- a/apps/web/src/features/agent-changes/queries/session-changes.ts
+++ b/apps/web/src/features/changes/queries/session-changes.ts
@@ -12,57 +12,11 @@ import {
import type {
AgentSessionChangesResponse,
CaptureAttemptDto,
- ChangedFileDto,
- ChangesetDto,
- GitRefDto,
} from '@service-agent-harness/generated/schemas';
import type { Accessor } from 'solid-js';
-import type {
- ChangesSource,
- PatchRead,
- QueryStatus,
-} from '../context/agent-changes-context';
-import type {
- CaptureAttempt,
- ChangedFile,
- Changeset,
- GitRef,
- SessionChanges,
-} from '../core/changeset';
-
-function decodeRef(ref: GitRefDto): GitRef {
- return {
- name: ref.name ?? undefined,
- sha: ref.sha ?? undefined,
- };
-}
-
-function decodeFile(file: ChangedFileDto): ChangedFile {
- return {
- path: file.path,
- previousPath: file.previousPath ?? undefined,
- kind: file.kind,
- additions: file.additions,
- deletions: file.deletions,
- binary: file.binary,
- patchOmitted: file.patchOmitted,
- };
-}
-
-export function decodeChangeset(dto: ChangesetDto): Changeset {
- return {
- id: dto.id,
- repository: dto.repository ?? undefined,
- base: decodeRef(dto.base),
- head: decodeRef(dto.head),
- files: dto.files.map(decodeFile),
- additions: dto.additions,
- deletions: dto.deletions,
- patchBytes: dto.patchBytes,
- truncated: dto.truncated,
- capturedAt: dto.capturedAt,
- };
-}
+import type { ChangesSource, PatchRead } from '../context/changes-context';
+import type { CaptureAttempt, ChangesSummary } from '../core/changeset';
+import { decodeChangeset, queryStatus } from './changes-adapter';
function decodeAttempt(dto: CaptureAttemptDto): CaptureAttempt {
return {
@@ -75,7 +29,7 @@ function decodeAttempt(dto: CaptureAttemptDto): CaptureAttempt {
export function decodeSessionChanges(
dto: AgentSessionChangesResponse
-): SessionChanges {
+): ChangesSummary {
return {
changeset: dto.changeset ? decodeChangeset(dto.changeset) : undefined,
attempt: dto.attempt ? decodeAttempt(dto.attempt) : undefined,
@@ -83,18 +37,6 @@ export function decodeSessionChanges(
};
}
-export function queryStatus(query: {
- isPending: boolean;
- isError: boolean;
- isSuccess: boolean;
- fetchStatus: string;
-}): QueryStatus {
- if (query.isSuccess) return 'success';
- if (query.isError) return 'error';
- if (query.isPending && query.fetchStatus === 'idle') return 'idle';
- return 'pending';
-}
-
/** The production source: TanStack queries against the agent-harness service. */
export function createSessionChangesSource(
sessionId: Accessor<string | undefined>
diff --git a/apps/web/src/features/agent-changes/tests/memory-storage.ts b/apps/web/src/features/changes/tests/memory-storage.ts
similarity index 100%
rename from apps/web/src/features/agent-changes/tests/memory-storage.ts
rename to apps/web/src/features/changes/tests/memory-storage.ts
diff --git a/apps/web/src/features/agent-changes/tests/mock-context.ts b/apps/web/src/features/changes/tests/mock-context.ts
similarity index 88%
rename from apps/web/src/features/agent-changes/tests/mock-context.ts
rename to apps/web/src/features/changes/tests/mock-context.ts
index 62fab19dfd..ce1866af41 100644
--- a/apps/web/src/features/agent-changes/tests/mock-context.ts
+++ b/apps/web/src/features/changes/tests/mock-context.ts
@@ -5,14 +5,14 @@
import { createSignal } from 'solid-js';
import type {
- AgentChangesContext,
ChangesAgent,
+ ChangesContext,
ChangesHost,
ChangesSource,
PatchRead,
QueryStatus,
-} from '../context/agent-changes-context';
-import type { Changeset, SessionChanges } from '../core/changeset';
+} from '../context/changes-context';
+import type { Changeset, ChangesSummary } from '../core/changeset';
export const MOCK_PATCH = `diff --git a/apps/web/src/a.ts b/apps/web/src/a.ts
index 1111111..2222222 100644
@@ -66,9 +66,9 @@ export function mockChangeset(overrides: Partial<Changeset> = {}): Changeset {
};
}
-export type MockAgentChangesContext = AgentChangesContext & {
+export type MockChangesContext = ChangesContext & {
host: ChangesHost & { agent: ChangesAgent };
- setSummary: (summary: SessionChanges | undefined) => void;
+ setSummary: (summary: ChangesSummary | undefined) => void;
setPatch: (patch: string | undefined) => void;
setPullRequestUrl: (url: string | undefined) => void;
sent: string[];
@@ -77,15 +77,15 @@ export type MockAgentChangesContext = AgentChangesContext & {
refreshes: () => number;
};
-export function createMockAgentChangesContext(
+export function createMockChangesContext(
options: {
- summary?: SessionChanges;
+ summary?: ChangesSummary;
patch?: string;
canSend?: boolean;
sessionId?: string;
} = {}
-): MockAgentChangesContext {
- const [summary, setSummary] = createSignal<SessionChanges | undefined>(
+): MockChangesContext {
+ const [summary, setSummary] = createSignal<ChangesSummary | undefined>(
options.summary
);
const [patch, setPatch] = createSignal<string | undefined>(options.patch);
diff --git a/apps/web/src/features/agent-changes/views/SessionChangesControls.tsx b/apps/web/src/features/changes/views/ChangesControls.tsx
similarity index 80%
rename from apps/web/src/features/agent-changes/views/SessionChangesControls.tsx
rename to apps/web/src/features/changes/views/ChangesControls.tsx
index fe681d549b..3e18cbb157 100644
--- a/apps/web/src/features/agent-changes/views/SessionChangesControls.tsx
+++ b/apps/web/src/features/changes/views/ChangesControls.tsx
@@ -1,19 +1,17 @@
/**
- * The pieces the session pane itself shows: the header opener, the
- * "changes ready" hand-off card, and the queued-notes chip by the composer.
- * Each renders nothing until a host has mounted the controller, and nothing
- * at all while the host reports it can never have changes (a chat-only
- * harness has no repository to diff).
+ * Host-composed opener, changes-ready card, and optional agent notes dock.
+ * Each renders nothing without a controller or when the host cannot have changes.
+ * Agent-only actions require the explicit note-sending capability.
*/
import { createSignal, Show } from 'solid-js';
import { ChangesReadyCard } from '../components/ChangesReadyCard';
import { ChangesToggleButton } from '../components/ChangesToggleButton';
import { ReviewNotesChip } from '../components/ReviewNotesChip';
-import { useOptionalAgentChanges } from '../context/agent-changes-controller';
+import { useOptionalChanges } from '../context/changes-controller';
export function ChangesToggle() {
- const controller = useOptionalAgentChanges();
+ const controller = useOptionalChanges();
if (!controller) return null;
const { available, layout } = controller;
return (
@@ -28,7 +26,7 @@ export function ChangesToggle() {
/** Shown while the pane is closed and a changeset with files is waiting. */
export function ChangesHandoff() {
- const controller = useOptionalAgentChanges();
+ const controller = useOptionalChanges();
if (!controller) return null;
const { available, layout, model, review, context } = controller;
const visible = () =>
@@ -59,7 +57,7 @@ export function ChangesHandoff() {
}
export function ReviewNotesDock() {
- const controller = useOptionalAgentChanges();
+ const controller = useOptionalChanges();
const [expanded, setExpanded] = createSignal(false);
if (!controller) return null;
const { available, review, context, layout } = controller;
diff --git a/apps/web/src/features/agent-changes/views/ChangesPane.tsx b/apps/web/src/features/changes/views/ChangesPane.tsx
similarity index 80%
rename from apps/web/src/features/agent-changes/views/ChangesPane.tsx
rename to apps/web/src/features/changes/views/ChangesPane.tsx
index 979d2f6ffd..084e593e84 100644
--- a/apps/web/src/features/agent-changes/views/ChangesPane.tsx
+++ b/apps/web/src/features/changes/views/ChangesPane.tsx
@@ -11,7 +11,6 @@ import {
StatusLetter,
} from '@app/components/diff-view';
import { Resize } from '@core/component/Resize';
-import type { ResizeZoneCtx } from '@core/component/Resize/types';
import { isTouchDevice } from '@core/mobile/isTouchDevice';
import * as Dialog from '@kobalte/core/dialog';
import ArrowsClockwiseIcon from '@phosphor/arrows-clockwise.svg';
@@ -20,15 +19,11 @@ import FileIcon from '@phosphor/file.svg';
import SidebarIcon from '@phosphor/sidebar-simple.svg';
import WarningCircleIcon from '@phosphor/warning-circle.svg';
import { Button, cn, Panel } from '@ui';
-import {
- CollapseTransition,
- type CollapseTransitionProps,
-} from '@ui/components/CollapseTransition';
+import { CollapseTransition } from '@ui/components/CollapseTransition';
import { FileTree } from '@ui/components/FileTree';
import {
type Accessor,
createEffect,
- createMemo,
createSignal,
Match,
on,
@@ -40,7 +35,7 @@ import { ChangesHeader } from '../components/ChangesHeader';
import { CaptureBanner, ChangesNotice } from '../components/ChangesNotice';
import { CopyFilePathButton } from '../components/CopyFilePathButton';
import { NoteAnnotation } from '../components/NoteAnnotation';
-import { useAgentChanges } from '../context/agent-changes-controller';
+import { useChanges } from '../context/changes-controller';
import {
type ChangesState,
describeFileCount,
@@ -48,10 +43,10 @@ import {
} from '../core/changeset';
import { createChangesNarrow } from '../primitives/create-changes-narrow';
import {
- DEFAULT_TREE_WIDTH,
MAX_TREE_WIDTH,
MIN_TREE_WIDTH,
} from '../primitives/create-pane-layout';
+import { createTreeLayout } from '../primitives/create-tree-layout';
import { ChangesTreeDrawer } from './ChangesTreeDrawer';
/** The state narrowed to one kind, for `<Match>` to hand its fields down. */
@@ -63,7 +58,7 @@ function stateOf<K extends ChangesState['kind']>(state: ChangesState, kind: K) {
/** Strips over the body: a failed refresh, and a capture over the changeset on screen. */
function CaptureBanners() {
- const { model } = useAgentChanges();
+ const { model } = useChanges();
const showsChangeset = () => model.changeset() !== undefined;
return (
<>
@@ -100,7 +95,7 @@ function ChangesTreeToggle(props: {
open?: boolean;
onToggle?: () => void;
}) {
- const { layout } = useAgentChanges();
+ const { layout } = useChanges();
const open = () => (props.narrow ? props.open : layout.treeOpen());
const label = () => (open() ? 'Hide file tree' : 'Show file tree');
return props.narrow && !props.onToggle ? (
@@ -125,7 +120,7 @@ function ChangesTreeToggle(props: {
/** Borderless diff controls above the stack, scoped to the diff column's width. */
function ChangesControls(props: { narrow: boolean; drawerOpen: boolean }) {
- const { model, layout, diffStyle, setDiffStyle } = useAgentChanges();
+ const { model, layout, diffStyle, setDiffStyle } = useChanges();
const refreshing = () =>
model.refreshing() || model.state().kind === 'capturing';
const treeVisible = () => !props.narrow && layout.treeOpen();
@@ -174,7 +169,7 @@ function ChangesControls(props: { narrow: boolean; drawerOpen: boolean }) {
/** Count on the left, with the tree visibility toggle on the right. */
function ChangesTreeHeader(props: { narrow: boolean; onClose: () => void }) {
- const { model, layout } = useAgentChanges();
+ const { model, layout } = useChanges();
return (
<div
class="flex min-w-0 shrink-0 items-center justify-between gap-1 px-3 pt-2 pb-1"
@@ -221,7 +216,7 @@ function ChangesBodyContent(props: {
drawerOpen: Accessor<boolean>;
closeDrawer: () => void;
}) {
- const { model, review, layout, copyPath, context } = useAgentChanges();
+ const { model, review, layout, copyPath, context } = useChanges();
const notes = createDiffComments({
items: review.notes,
rangeOf: (note) => note,
@@ -239,76 +234,16 @@ function ChangesBodyContent(props: {
),
});
const treeVisible = () => !props.narrow() && layout.treeOpen();
- const [treePresent, setTreePresent] = createSignal(treeVisible());
const [wideDock, setWideDock] = createSignal<HTMLDivElement>();
const [drawerDock, setDrawerDock] = createSignal<HTMLDivElement>();
let treeBody!: HTMLDivElement;
let diffBody: HTMLDivElement | undefined;
- let zone: ResizeZoneCtx | undefined;
- let finishTreeMotion: (() => void) | undefined;
- let expandedTreeSize: Accessor<number> = layout.treeWidth;
- const drawerWidth = () => {
- const available = zone?.size() ?? DEFAULT_TREE_WIDTH;
- return Math.min(
- DEFAULT_TREE_WIDTH,
- Math.max(Math.min(MIN_TREE_WIDTH, available), available - 32)
- );
- };
- const treePanel = () =>
- wideDock()?.closest<HTMLElement>('[data-resize-panel]');
- const companions: NonNullable<CollapseTransitionProps['companions']> = ({
- opening,
- from,
- interrupted,
- }) => {
- const panel = treePanel();
- const diffPanel = diffBody?.parentElement;
- const root = panel?.parentElement;
- if (!panel || !diffPanel || !root) return [];
- const width = zone?.size() ?? root.clientWidth;
- const fromOffset = from > 0 ? from + 1 : 0;
- const toOffset = opening ? expandedTreeSize() + 1 : 0;
- const current = getComputedStyle(diffPanel);
- const animations: { target: HTMLElement; keyframes: Keyframe[] }[] = [
- {
- target: diffPanel,
- keyframes: [
- interrupted
- ? { left: current.left, width: current.width }
- : { left: `${fromOffset}px`, width: `${width - fromOffset}px` },
- { left: `${toOffset}px`, width: `${width - toOffset}px` },
- ],
- },
- ];
- const gutter = root.querySelector<HTMLElement>('[role="separator"]');
- if (gutter) {
- gutter.inert = !opening;
- gutter.setAttribute('aria-hidden', String(!opening));
- const inset = Number.parseFloat(gutter.style.left) - expandedTreeSize();
- animations.push({
- target: gutter,
- keyframes: [
- {
- left:
- interrupted && gutter.getAnimations?.().length
- ? getComputedStyle(gutter).left
- : `${from + inset}px`,
- },
- { left: `${(opening ? expandedTreeSize() : 0) + inset}px` },
- ],
- });
- }
- return animations;
- };
- const finishTreeAnimation = () => finishTreeMotion?.();
- const settleTreeAnimation = (event: PointerEvent | KeyboardEvent) => {
- if (
- !(event.target instanceof Element) ||
- !event.target.closest('[role="separator"]')
- )
- return;
- finishTreeAnimation();
- };
+ const treeLayout = createTreeLayout({
+ visible: treeVisible,
+ width: layout.treeWidth,
+ dock: wideDock,
+ diff: () => diffBody,
+ });
// Construct once under Dialog.Root so directory state survives docking and hiding.
const tree = (
<div
@@ -357,7 +292,7 @@ function ChangesBodyContent(props: {
on(
props.narrow,
() => {
- finishTreeAnimation();
+ treeLayout.finish();
if (!props.narrow()) props.closeDrawer();
},
{ defer: true }
@@ -379,15 +314,15 @@ function ChangesBodyContent(props: {
<div
class="min-h-0 flex-1"
ref={(element) => {
- element.addEventListener('pointerdown', settleTreeAnimation, true);
- element.addEventListener('keydown', settleTreeAnimation, true);
+ element.addEventListener('pointerdown', treeLayout.settle, true);
+ element.addEventListener('keydown', treeLayout.settle, true);
onCleanup(() => {
element.removeEventListener(
'pointerdown',
- settleTreeAnimation,
+ treeLayout.settle,
true
);
- element.removeEventListener('keydown', settleTreeAnimation, true);
+ element.removeEventListener('keydown', treeLayout.settle, true);
});
}}
>
@@ -395,19 +330,7 @@ function ChangesBodyContent(props: {
direction="horizontal"
gutter={1}
class="overflow-hidden"
- captureResizeCtx={(ctx) => {
- if (zone === ctx) return;
- zone = ctx;
- const size = ctx.sizeOf('changes-file-tree');
- expandedTreeSize = createMemo<number>((previous) => {
- const solved = size();
- return treeVisible() && solved > 0
- ? solved
- : (previous ?? layout.treeWidth());
- });
- // Outer split and viewport changes invalidate pixel animation endpoints.
- createEffect(on(ctx.size, finishTreeAnimation, { defer: true }));
- }}
+ captureResizeCtx={treeLayout.captureZone}
>
<Resize.Panel
id="changes-file-tree"
@@ -418,7 +341,7 @@ function ChangesBodyContent(props: {
redistributionPreferredSize={layout.treeWidth()}
onSizeChangeEnd={layout.setTreeWidth}
hidden={() =>
- props.narrow() || (!treeVisible() && !treePresent())
+ props.narrow() || (!treeVisible() && !treeLayout.present())
}
persistent
>
@@ -426,13 +349,11 @@ function ChangesBodyContent(props: {
<CollapseTransition
open={treeVisible()}
axis="width"
- container={() => treePanel() ?? undefined}
- expandedSize={expandedTreeSize()}
- companions={companions}
- onPresenceChange={setTreePresent}
- captureController={(controller) => {
- finishTreeMotion = controller.finish;
- }}
+ container={() => treeLayout.panel() ?? undefined}
+ expandedSize={treeLayout.expandedSize()}
+ companions={treeLayout.companions}
+ onPresenceChange={treeLayout.setPresent}
+ captureController={treeLayout.captureController}
>
<div ref={setWideDock} class="size-full" />
</CollapseTransition>
@@ -495,7 +416,7 @@ function ChangesBodyContent(props: {
<Show when={props.narrow()}>
<ChangesTreeDrawer
open={props.drawerOpen()}
- width={drawerWidth()}
+ width={treeLayout.drawerWidth()}
onClose={props.closeDrawer}
dock={setDrawerDock}
/>
@@ -508,7 +429,7 @@ function ChangesBodyContent(props: {
/** Every state without files to show, each explained in the body. */
function ChangesNotices() {
- const { model } = useAgentChanges();
+ const { model } = useChanges();
const state = model.state;
const showsChangeset = () => model.changeset() !== undefined;
const range = () => {
@@ -589,7 +510,7 @@ function ChangesNotices() {
export function ChangesPane(props: { fullWidth?: boolean }) {
const { layout, model, review, diffStyle, context, changeCounts } =
- useAgentChanges();
+ useChanges();
const collapse: DiffCollapse = {
isCollapsed: review.isCollapsed,
toggle: review.toggleCollapsed,
diff --git a/apps/web/src/features/changes/views/ChangesSplit.tsx b/apps/web/src/features/changes/views/ChangesSplit.tsx
new file mode 100644
index 0000000000..0104536bdd
--- /dev/null
+++ b/apps/web/src/features/changes/views/ChangesSplit.tsx
@@ -0,0 +1,140 @@
+/** Shared responsive split that retains host and diff owners through motion. */
+
+import { FloatRegion } from '@components/app/mobile/float-regions/FloatRegion';
+import { FloatRegions } from '@components/app/mobile/float-regions/float-region-state';
+import { Resize } from '@core/component/Resize';
+import type { ResizeZoneCtx } from '@core/component/Resize/types';
+import { isTouchDevice } from '@core/mobile/isTouchDevice';
+import {
+ createEffect,
+ createMemo,
+ createSignal,
+ on,
+ type ParentProps,
+ Show,
+} from 'solid-js';
+import { useChanges } from '../context/changes-controller';
+import { createChangesNarrow } from '../primitives/create-changes-narrow';
+import { createSplitPresence } from '../primitives/create-split-presence';
+import { ChangesPane } from './ChangesPane';
+
+const HOST_MIN_PX = 320;
+const CHANGES_MIN_PX = 400;
+
+export function ChangesSplit(props: ParentProps) {
+ const { available, layout } = useChanges();
+ const [root, setRoot] = createSignal<HTMLDivElement>();
+ const narrow = createChangesNarrow(root);
+ let zone: ResizeZoneCtx | undefined;
+ let hostContent: HTMLDivElement | undefined;
+ // A host that can never have changes keeps the session alone on screen,
+ // whatever a stale URL asks for.
+ // Split/full changes keep the same visibility and must not replay the slide.
+ const changesVisible = createMemo(
+ () => available() && layout.changesVisible()
+ );
+ const presence = createSplitPresence(changesVisible, () => hostContent);
+ const hostVisible = createMemo<boolean>((previous) => {
+ if (!available()) return true;
+ // A narrow host opens as a takeover without changing the saved wide layout.
+ if (changesVisible() && narrow()) return false;
+ // A spotlight request during a slide waits for the slide to settle, so its
+ // endpoint does not move underneath the running translation.
+ if (presence.transitioning()) return previous ?? layout.hostVisible();
+ if (changesVisible()) return layout.hostVisible();
+ // Closing from full width must not shrink the pane before it slides out.
+ return presence.present() ? (previous ?? true) : true;
+ });
+ // Reveal the retained host behind a full-width slide without changing the
+ // Changes panel's solved geometry until the slide finishes, including reversals.
+ const slideUnderlay = () =>
+ presence.present() &&
+ !hostVisible() &&
+ (!changesVisible() || presence.transitioning());
+ const hostShown = () => hostVisible() || slideUnderlay();
+
+ return (
+ <div
+ ref={setRoot}
+ data-changes-host
+ class="size-full min-h-0 min-w-0 overflow-hidden"
+ >
+ <Show
+ when={isTouchDevice()}
+ fallback={
+ <Resize.Zone
+ direction="horizontal"
+ gutter={1}
+ class="overflow-hidden"
+ resizable
+ captureResizeCtx={(ctx) => {
+ zone = ctx;
+ createEffect(on(ctx.size, presence.finish, { defer: true }));
+ }}
+ >
+ {/* Hiding retains resize intent and the host's editor/composer owner. */}
+ <Resize.Panel
+ id="changes-content"
+ minSize={HOST_MIN_PX}
+ index={0}
+ persistent
+ hidden={() => !hostVisible()}
+ >
+ <div
+ ref={hostContent}
+ data-changes-content
+ data-slide-underlay={slideUnderlay() ? '' : undefined}
+ hidden={!hostShown()}
+ inert={!hostVisible() && changesVisible()}
+ style={{
+ width: slideUnderlay() ? `${zone?.size() ?? 0}px` : undefined,
+ }}
+ class="flex h-full min-w-0 flex-col overflow-hidden"
+ >
+ {props.children}
+ </div>
+ </Resize.Panel>
+ <Show when={presence.present()}>
+ <Resize.Panel
+ id="changes-pane"
+ minSize={CHANGES_MIN_PX}
+ index={1}
+ target={layout.changesShare()}
+ onSizeChangeEnd={(size) => {
+ const total = zone?.size() ?? 0;
+ if (total > 0) layout.setChangesShare((size / total) * 100);
+ }}
+ >
+ <div ref={presence.ref} class="h-full min-w-0 overflow-hidden">
+ <ChangesPane fullWidth={narrow()} />
+ </div>
+ </Resize.Panel>
+ </Show>
+ </Resize.Zone>
+ }
+ >
+ <div class="relative flex size-full min-w-0 flex-col overflow-hidden">
+ <div
+ class="flex size-full min-w-0 flex-col"
+ classList={{ hidden: changesVisible() }}
+ inert={changesVisible()}
+ >
+ {props.children}
+ </div>
+ <Show when={presence.present()}>
+ <div
+ ref={presence.ref}
+ class="absolute inset-0 min-w-0 pt-(--mobile-content-inset-top)"
+ style={{ 'padding-bottom': `${FloatRegions.hostHeight()}px` }}
+ >
+ <FloatRegion region="accessory" priority={1}>
+ <span />
+ </FloatRegion>
+ <ChangesPane fullWidth />
+ </div>
+ </Show>
+ </div>
+ </Show>
+ </div>
+ );
+}
diff --git a/apps/web/src/features/agent-changes/views/ChangesTreeDrawer.tsx b/apps/web/src/features/changes/views/ChangesTreeDrawer.tsx
similarity index 100%
rename from apps/web/src/features/agent-changes/views/ChangesTreeDrawer.tsx
rename to apps/web/src/features/changes/views/ChangesTreeDrawer.tsx
diff --git a/apps/web/src/features/reviews-view/components/ReviewsPrDetail.tsx b/apps/web/src/features/reviews-view/components/ReviewsPrDetail.tsx
index f940f0c03f..87dd7f5109 100644
--- a/apps/web/src/features/reviews-view/components/ReviewsPrDetail.tsx
+++ b/apps/web/src/features/reviews-view/components/ReviewsPrDetail.tsx
@@ -1,5 +1,5 @@
import { ViewBreadcrumbs, ViewShell } from '@app/components/view-shell';
-import { AgentChangesSplit } from '@app/features/agent-changes/agent-changes';
+import { ChangesSplit } from '@app/features/changes/changes';
import { useAnalytics } from '@app/lib/analytics/analytics-context';
import { useRouteParams } from '@app/lib/split-router';
import { reviewsPrRoute } from '@app/routes/routes';
@@ -93,7 +93,7 @@ export function ReviewsPrDetail(props: { foreignEntityId: string }) {
name={name()}
status={detail.data()?.pullRequest.status ?? undefined}
/>
- <AgentChangesSplit>
+ <ChangesSplit>
<div class="flex size-full min-h-0 min-w-0 flex-col overflow-hidden @container">
<ViewShell.TopBar class="touch:flex">
<SplitPanel.CloseButton class="hidden shrink-0 touch:flex" />
@@ -108,7 +108,7 @@ export function ReviewsPrDetail(props: { foreignEntityId: string }) {
onRetry={() => void detail.query.refetch()}
/>
</div>
- </AgentChangesSplit>
+ </ChangesSplit>
</PrChangesProvider>
</SidePanel.Root>
);
diff --git a/apps/web/src/lib/utils/create-animation-group.ts b/apps/web/src/lib/utils/create-animation-group.ts
new file mode 100644
index 0000000000..df27eb9b23
--- /dev/null
+++ b/apps/web/src/lib/utils/create-animation-group.ts
@@ -0,0 +1,73 @@
+export type AnimationTarget = {
+ target: HTMLElement;
+ keyframes: Keyframe[];
+};
+
+type AnimationGroup = {
+ animations: Animation[];
+ complete: () => void;
+ afterRelease?: () => void;
+};
+
+/**
+ * One interruptible WAAPI group. Callers capture keyframes before starting a
+ * replacement and own presence, geometry, and disposal policy.
+ */
+export function createAnimationGroup() {
+ let current: AnimationGroup | undefined;
+
+ const release = (group: AnimationGroup) => {
+ for (const animation of group.animations) {
+ animation.onfinish = null;
+ animation.cancel();
+ }
+ };
+ const cancel = () => {
+ const group = current;
+ current = undefined;
+ if (group) release(group);
+ };
+ const finish = () => {
+ const group = current;
+ if (!group) return;
+ current = undefined;
+ try {
+ // Apply presence changes while the final animation frame still holds.
+ group.complete();
+ } finally {
+ release(group);
+ group.afterRelease?.();
+ }
+ };
+
+ return {
+ running: () => current !== undefined,
+ cancel,
+ finish,
+ start(
+ targets: readonly AnimationTarget[],
+ options: KeyframeAnimationOptions,
+ complete: () => void,
+ afterRelease?: () => void
+ ) {
+ cancel();
+ const group: AnimationGroup = {
+ animations: targets.map(({ target, keyframes }) =>
+ target.animate(keyframes, options)
+ ),
+ complete,
+ afterRelease,
+ };
+ const primary = group.animations[0];
+ if (!primary) {
+ complete();
+ afterRelease?.();
+ return;
+ }
+ current = group;
+ primary.onfinish = () => {
+ if (current === group) finish();
+ };
+ },
+ };
+}
diff --git a/apps/web/src/routes/routes.ts b/apps/web/src/routes/routes.ts
index b81892e07d..4f57afb439 100644
--- a/apps/web/src/routes/routes.ts
+++ b/apps/web/src/routes/routes.ts
@@ -1,4 +1,3 @@
-import { changesSearch } from '@app/features/agent-changes/changes-search';
import { agentsRouteSegments } from '@app/features/agents-view/core/route';
import { agentDetailSearch } from '@app/features/block-agent/agent-route';
import { SPREADSHEET_COMMENT_PARAMS } from '@app/features/block-spreadsheet/core/spreadsheet-comments';
@@ -9,6 +8,7 @@ import {
calendarPeriodPath,
} from '@app/features/calendar-view/calendar-url';
import { CALENDAR_VIEW_ID } from '@app/features/calendar-view/types';
+import { changesSearch } from '@app/features/changes/changes-search';
import { driveDetailTrailSchema } from '@app/features/drive-view/primitives/drive-detail-trail';
import {
DRIVE_DOCUMENT_TYPES,
diff --git a/docs/AGENT_GUIDE/ai-chat.md b/docs/AGENT_GUIDE/ai-chat.md
index d9382a3bb2..e7ee2aa86f 100644
--- a/docs/AGENT_GUIDE/ai-chat.md
+++ b/docs/AGENT_GUIDE/ai-chat.md
@@ -986,6 +986,8 @@ resizing them. File selection, Escape, the backdrop, or **Hide file tree** dismi
the drawer and restores focus to its opener. Drawer visibility never changes the
saved wide-tree preference or width. Phones keep unified diffs and omit layout
controls, with **Back to conversation** closing Changes.
+Closing the drawer releases its dialog handlers immediately; the exiting tree
+frame stays inert, so the animation does not intercept Escape or steal focus.
Returning from full width restores the previous split ratio without replaying
the opening slide or losing the conversation draft, diff state, or scroll position.
Drag the divider beside the file tree to resize it, or focus that divider and use
@@ -1019,10 +1021,10 @@ that 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.
-The session header's **Changes** pill and sidebar totals display the linked
-PR's `additions` and `deletions` returned by the GitHub API, without summing
-transcript edits. The sidebar lists files from the captured PR diff. Counts
-refresh when a capture changes and every 30 seconds while the session is open.
+The Changes pane header and sidebar totals display the linked PR's `additions`
+and `deletions` returned by the GitHub API, without summing transcript edits.
+The header toggle itself has no totals. The sidebar lists files from the captured PR diff.
+Counts refresh when a capture changes and every 30 seconds while the session is open.
Zero-valued counts and unavailable GitHub statistics are hidden; a missing PR
or failed GitHub request never falls back to estimated transcript totals.
diff --git a/docs/AGENT_GUIDE/surfaces.md b/docs/AGENT_GUIDE/surfaces.md
index 6e2fc650c9..32ffd7ebce 100644
--- a/docs/AGENT_GUIDE/surfaces.md
+++ b/docs/AGENT_GUIDE/surfaces.md
@@ -1472,6 +1472,8 @@ Narrow file trees start closed. **Show file tree** opens an animated drawer over
diffs without resizing them, including on phones. File selection, Escape, the
backdrop, or **Hide file tree** closes the drawer and restores focus to its opener.
The drawer does not change the saved wide-tree visibility or preferred width.
+Closing releases the drawer's dialog handlers immediately while its inert visual
+frame finishes exiting, so rapid reopening does not restore focus to a stale opener.
The file tree has its own draggable, keyboard-resizable divider and remembers its
width locally. Tree visibility uses the sidebar's shared width transition while
retaining directory state and diff owners. Reduced motion skips this transition.
diff --git a/rules/ast-grep/ts-feature-components-presentational.yml b/rules/ast-grep/ts-feature-components-presentational.yml
index 26602b5063..7d540f08f5 100644
--- a/rules/ast-grep/ts-feature-components-presentational.yml
+++ b/rules/ast-grep/ts-feature-components-presentational.yml
@@ -31,7 +31,7 @@ files:
- apps/web/src/features/email-message/components/**
- apps/web/src/features/email-thread/components/**
- apps/web/src/features/email-compose/components/**
- - apps/web/src/features/agent-changes/components/**
+ - apps/web/src/features/changes/components/**
- apps/web/src/features/block-write/components/**
rule:
any:
diff --git a/rules/ast-grep/ts-feature-core-pure.yml b/rules/ast-grep/ts-feature-core-pure.yml
index 5a2a435f4b..e7c3942ffb 100644
--- a/rules/ast-grep/ts-feature-core-pure.yml
+++ b/rules/ast-grep/ts-feature-core-pure.yml
@@ -32,7 +32,7 @@ files:
- apps/web/src/features/email-message/core/**
- apps/web/src/features/email-thread/core/**
- apps/web/src/features/email-compose/core/**
- - apps/web/src/features/agent-changes/core/**
+ - apps/web/src/features/changes/core/**
- apps/web/src/features/block-write/core/**
rule:
kind: string
diff --git a/rules/ast-grep/ts-feature-data-no-ui.yml b/rules/ast-grep/ts-feature-data-no-ui.yml
index e835241355..c886b182f4 100644
--- a/rules/ast-grep/ts-feature-data-no-ui.yml
+++ b/rules/ast-grep/ts-feature-data-no-ui.yml
@@ -48,8 +48,8 @@ files:
- apps/web/src/features/email-thread/primitives/**
- apps/web/src/features/email-compose/queries/**
- apps/web/src/features/email-compose/primitives/**
- - apps/web/src/features/agent-changes/queries/**
- - apps/web/src/features/agent-changes/primitives/**
+ - apps/web/src/features/changes/queries/**
+ - apps/web/src/features/changes/primitives/**
- apps/web/src/features/block-write/queries/**
- apps/web/src/features/block-write/primitives/**
rule:
diff --git a/rules/ast-grep/ts-feature-layers-use-context.yml b/rules/ast-grep/ts-feature-layers-use-context.yml
index 0709bb8c97..2f088b534e 100644
--- a/rules/ast-grep/ts-feature-layers-use-context.yml
+++ b/rules/ast-grep/ts-feature-layers-use-context.yml
@@ -88,10 +88,10 @@ files:
- apps/web/src/features/email-compose/queries/**
- apps/web/src/features/email-compose/primitives/**
- apps/web/src/features/email-compose/views/**
- - apps/web/src/features/agent-changes/components/**
- - apps/web/src/features/agent-changes/queries/**
- - apps/web/src/features/agent-changes/primitives/**
- - apps/web/src/features/agent-changes/views/**
+ - apps/web/src/features/changes/components/**
+ - apps/web/src/features/changes/queries/**
+ - apps/web/src/features/changes/primitives/**
+ - apps/web/src/features/changes/views/**
- apps/web/src/features/block-write/queries/**
- apps/web/src/features/block-write/primitives/**
- apps/web/src/features/block-write/components/**
diff --git a/rules/ast-grep/tsx-feature-components-presentational.yml b/rules/ast-grep/tsx-feature-components-presentational.yml
index 0940f2092f..ce9649d8b1 100644
--- a/rules/ast-grep/tsx-feature-components-presentational.yml
+++ b/rules/ast-grep/tsx-feature-components-presentational.yml
@@ -31,7 +31,7 @@ files:
- apps/web/src/features/email-message/components/**
- apps/web/src/features/email-thread/components/**
- apps/web/src/features/email-compose/components/**
- - apps/web/src/features/agent-changes/components/**
+ - apps/web/src/features/changes/components/**
- apps/web/src/features/block-write/components/**
rule:
any:
diff --git a/rules/ast-grep/tsx-feature-core-pure.yml b/rules/ast-grep/tsx-feature-core-pure.yml
index 2e1ff30aaa..cf7f532778 100644
--- a/rules/ast-grep/tsx-feature-core-pure.yml
+++ b/rules/ast-grep/tsx-feature-core-pure.yml
@@ -32,7 +32,7 @@ files:
- apps/web/src/features/email-message/core/**
- apps/web/src/features/email-thread/core/**
- apps/web/src/features/email-compose/core/**
- - apps/web/src/features/agent-changes/core/**
+ - apps/web/src/features/changes/core/**
- apps/web/src/features/block-write/core/**
rule:
kind: string
diff --git a/rules/ast-grep/tsx-feature-data-no-ui.yml b/rules/ast-grep/tsx-feature-data-no-ui.yml
index d32a2c0d77..4e2ca2dd7f 100644
--- a/rules/ast-grep/tsx-feature-data-no-ui.yml
+++ b/rules/ast-grep/tsx-feature-data-no-ui.yml
@@ -48,8 +48,8 @@ files:
- apps/web/src/features/email-thread/primitives/**
- apps/web/src/features/email-compose/queries/**
- apps/web/src/features/email-compose/primitives/**
- - apps/web/src/features/agent-changes/queries/**
- - apps/web/src/features/agent-changes/primitives/**
+ - apps/web/src/features/changes/queries/**
+ - apps/web/src/features/changes/primitives/**
- apps/web/src/features/block-write/queries/**
- apps/web/src/features/block-write/primitives/**
rule:
diff --git a/rules/ast-grep/tsx-feature-layers-use-context.yml b/rules/ast-grep/tsx-feature-layers-use-context.yml
index f7faa293a2..8e4deb5695 100644
--- a/rules/ast-grep/tsx-feature-layers-use-context.yml
+++ b/rules/ast-grep/tsx-feature-layers-use-context.yml
@@ -88,10 +88,10 @@ files:
- apps/web/src/features/email-compose/queries/**
- apps/web/src/features/email-compose/primitives/**
- apps/web/src/features/email-compose/views/**
- - apps/web/src/features/agent-changes/components/**
- - apps/web/src/features/agent-changes/queries/**
- - apps/web/src/features/agent-changes/primitives/**
- - apps/web/src/features/agent-changes/views/**
+ - apps/web/src/features/changes/components/**
+ - apps/web/src/features/changes/queries/**
+ - apps/web/src/features/changes/primitives/**
+ - apps/web/src/features/changes/views/**
- apps/web/src/features/block-write/queries/**
- apps/web/src/features/block-write/primitives/**
- apps/web/src/features/block-write/components/**