Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/app/e2e/regression/review-line-comment.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ async function openReview(page: Page) {

await page.goto(`/${base64Encode(directory)}/session/${sessionID}`)
await expectSessionTitle(page, title)
const diffResponse = page.waitForResponse((response) => new URL(response.url()).pathname === "/vcs/diff")
const diffResponse = page.waitForResponse((response) => new URL(response.url()).pathname === "/api/vcs/diff")
await page.getByRole("tab", { name: "Changes" }).click()
expect(await (await diffResponse).json()).toHaveLength(1)
expect((await (await diffResponse).json()).data).toHaveLength(1)

const review = page.locator('[data-component="session-review"]')
await expectAppVisible(review)
Expand Down
14 changes: 8 additions & 6 deletions packages/app/e2e/regression/review-state-persistence.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,18 +92,20 @@ async function setup(page: Page) {
route.fulfill({
status: 200,
contentType: "application/json",
body: JSON.stringify({ branch: "feature", default_branch: "dev" }),
body: JSON.stringify({ location: { directory }, data: { branch: "feature", defaultBranch: "dev" } }),
}),
)
await page.route("**/vcs/diff**", (route) =>
route.fulfill({
status: 200,
contentType: "application/json",
body: JSON.stringify(
new URL(route.request().url()).searchParams.get("mode") === "branch"
? [diff("src/alpha.ts"), diff("src/beta.ts")]
: [diff("src/alpha.ts"), diff("src/gamma.ts")],
),
body: JSON.stringify({
location: { directory },
data:
new URL(route.request().url()).searchParams.get("mode") === "branch"
? [diff("src/alpha.ts"), diff("src/beta.ts")]
: [diff("src/alpha.ts"), diff("src/gamma.ts")],
}),
}),
)
await page.addInitScript(
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/pages/session/file-tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ export function SessionFileView(props: SessionFileViewProps) {
const source = props.diff
if (!source) return
const loaded = loadedDiff()
return normalize(loaded?.source === source && loaded.version === props.diffVersion ? loaded.value : source)
return normalize(loaded && loaded.source === source && loaded.version === props.diffVersion ? loaded.value : source)
})

return (
Expand Down
3 changes: 2 additions & 1 deletion packages/app/src/pages/session/review-tab.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { createEffect, onCleanup, type JSX } from "solid-js"
import { makeEventListener } from "@solid-primitives/event-listener"
import type { SnapshotFileDiff, VcsFileDiff } from "@opencode-ai/sdk/v2"
import type { FileDiffInfo } from "@opencode-ai/client/promise"
import { SessionReview } from "@opencode-ai/session-ui/session-review"
import type {
SessionReviewCommentActions,
Expand All @@ -14,7 +15,7 @@ import type { LineComment } from "@/context/comments"

export type DiffStyle = "unified" | "split"

type ReviewDiff = SnapshotFileDiff | VcsFileDiff
type ReviewDiff = FileDiffInfo | SnapshotFileDiff | VcsFileDiff

export interface SessionReviewTabProps {
title?: JSX.Element
Expand Down
8 changes: 5 additions & 3 deletions packages/app/src/pages/session/session-side-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { IconButtonV2 } from "@opencode-ai/ui/v2/icon-button-v2"
import { KeybindV2 } from "@opencode-ai/ui/v2/keybind-v2"
import { TooltipV2 } from "@opencode-ai/ui/v2/tooltip-v2"
import type { SnapshotFileDiff, VcsFileDiff } from "@opencode-ai/sdk/v2"
import type { FileDiffInfo } from "@opencode-ai/client/promise"
import { ConstrainDragYAxis, getDraggableId } from "@/utils/solid-dnd"
import { useDialog } from "@opencode-ai/ui/context/dialog"

Expand Down Expand Up @@ -56,15 +57,16 @@ import { setSessionHandoff } from "@/pages/session/handoff"
import { useSessionLayout } from "@/pages/session/session-layout"
import { SessionFileBrowserTab, type SessionFileBrowserState } from "@/pages/session/v2/session-file-browser-tab"

type RenderDiff = (SnapshotFileDiff & { file: string }) | VcsFileDiff
type ReviewDiff = FileDiffInfo | SnapshotFileDiff | VcsFileDiff
type RenderDiff = FileDiffInfo | (SnapshotFileDiff & { file: string }) | VcsFileDiff

function renderDiff(value: SnapshotFileDiff | VcsFileDiff): value is RenderDiff {
function renderDiff(value: ReviewDiff): value is RenderDiff {
return typeof value.file === "string"
}

export function SessionSidePanel(props: {
canReview: () => boolean
diffs: () => (SnapshotFileDiff | VcsFileDiff)[]
diffs: () => ReviewDiff[]
diffsReady: () => boolean
empty: () => string
hasReview: () => boolean
Expand Down
5 changes: 3 additions & 2 deletions packages/app/src/pages/session/v2/review-diff-kinds.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import type { SnapshotFileDiff, VcsFileDiff } from "@opencode-ai/sdk/v2"
import type { FileDiffInfo } from "@opencode-ai/client/promise"
import type { Kind } from "@/components/file-tree-v2"
import { normalizeFileTreeV2Path } from "@/components/file-tree-v2-model"

export type RenderDiff = (SnapshotFileDiff & { file: string }) | VcsFileDiff
export type RenderDiff = FileDiffInfo | (SnapshotFileDiff & { file: string }) | VcsFileDiff

export function normalizePath(p: string) {
return normalizeFileTreeV2Path(p)
}

export function filterRenderableDiff(value: SnapshotFileDiff | VcsFileDiff): value is RenderDiff {
export function filterRenderableDiff(value: FileDiffInfo | SnapshotFileDiff | VcsFileDiff): value is RenderDiff {
return typeof value.file === "string"
}

Expand Down
3 changes: 2 additions & 1 deletion packages/app/src/pages/session/v2/review-panel-v2.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { createMemo, createResource, createSignal, Show, type JSX } from "solid-js"
import type { SnapshotFileDiff, VcsFileDiff } from "@opencode-ai/sdk/v2"
import type { FileDiffInfo } from "@opencode-ai/client/promise"
import {
SESSION_REVIEW_V2_SIDEBAR_WIDTH_MAX,
SESSION_REVIEW_V2_SIDEBAR_WIDTH_MIN,
Expand Down Expand Up @@ -30,7 +31,7 @@ import {
import type { ReviewPanelV2State } from "@/pages/session/v2/review-panel-v2-state"
import { applyFileListKeyDown, SessionFileListV2 } from "@/pages/session/v2/session-file-list-v2"

type ReviewDiff = SnapshotFileDiff | VcsFileDiff
type ReviewDiff = FileDiffInfo | SnapshotFileDiff | VcsFileDiff

export type ReviewPanelV2Props = {
title?: JSX.Element
Expand Down
3 changes: 2 additions & 1 deletion packages/app/src/utils/diffs.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { describe, expect, test } from "bun:test"
import type { SnapshotFileDiff } from "@opencode-ai/sdk/v2"
import type { FileDiffInfo } from "@opencode-ai/client/promise"
import type { Message } from "@opencode-ai/sdk/v2/client"
import { diffs, message } from "./diffs"

Expand All @@ -9,7 +10,7 @@ const item = {
additions: 1,
deletions: 1,
status: "modified",
} satisfies SnapshotFileDiff
} satisfies FileDiffInfo & SnapshotFileDiff

describe("diffs", () => {
test("keeps valid arrays", () => {
Expand Down
3 changes: 2 additions & 1 deletion packages/app/src/utils/diffs.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type { SnapshotFileDiff, VcsFileDiff } from "@opencode-ai/sdk/v2"
import type { FileDiffInfo } from "@opencode-ai/client/promise"
import type { Message } from "@opencode-ai/sdk/v2/client"

type Diff = SnapshotFileDiff | VcsFileDiff
type Diff = FileDiffInfo | SnapshotFileDiff | VcsFileDiff

function diff(value: unknown): value is Diff {
if (!value || typeof value !== "object" || Array.isArray(value)) return false
Expand Down
3 changes: 2 additions & 1 deletion packages/session-ui/src/components/session-diff.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { parseDiffFromFile, parsePatchFiles, type FileDiffMetadata } from "@pierre/diffs"
import { parsePatch } from "diff"
import type { SnapshotFileDiff, VcsFileDiff } from "@opencode-ai/sdk/v2"
import type { FileDiffInfo } from "@opencode-ai/client/promise"

type LegacyDiff = {
file: string
Expand All @@ -13,7 +14,7 @@ type LegacyDiff = {
}

type SnapshotDiff = SnapshotFileDiff & { file: string }
type ReviewDiff = SnapshotDiff | VcsFileDiff | LegacyDiff
type ReviewDiff = SnapshotDiff | FileDiffInfo | VcsFileDiff | LegacyDiff
export type DiffSource = Pick<LegacyDiff, "file" | "patch" | "before" | "after">

export type ViewDiff = {
Expand Down
5 changes: 3 additions & 2 deletions packages/session-ui/src/components/session-review.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { checksum } from "@opencode-ai/core/util/encode"
import { createEffect, createMemo, For, Match, onCleanup, Show, Switch, untrack, type JSX } from "solid-js"
import { createStore } from "solid-js/store"
import { type FileContent, type SnapshotFileDiff, type VcsFileDiff } from "@opencode-ai/sdk/v2"
import type { FileDiffInfo } from "@opencode-ai/client/promise"
import { PreloadMultiFileDiffResult } from "@pierre/diffs/ssr"
import { type SelectedLineRange } from "@pierre/diffs"
import { Dynamic } from "solid-js/web"
Expand Down Expand Up @@ -62,10 +63,10 @@ export type SessionReviewCommentActions = {

export type SessionReviewFocus = { file: string; id: string }

type RawReviewDiff = (SnapshotFileDiff | VcsFileDiff) & {
type RawReviewDiff = (SnapshotFileDiff | FileDiffInfo | VcsFileDiff) & {
preloaded?: PreloadMultiFileDiffResult<any>
}
type ReviewDiff = ((SnapshotFileDiff & { file: string }) | VcsFileDiff) & {
type ReviewDiff = ((SnapshotFileDiff & { file: string }) | FileDiffInfo | VcsFileDiff) & {
preloaded?: PreloadMultiFileDiffResult<any>
}
type Item = ViewDiff & { preloaded?: PreloadMultiFileDiffResult<any> }
Expand Down
3 changes: 2 additions & 1 deletion packages/session-ui/src/components/session-turn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
Message as MessageType,
Part as PartType,
} from "@opencode-ai/sdk/v2/client"
import type { FileDiffInfo } from "@opencode-ai/client/promise"
import type { SessionStatus } from "@opencode-ai/sdk/v2"
import { useData } from "../context"
import { useFileComponent } from "@opencode-ai/ui/context/file"
Expand Down Expand Up @@ -90,7 +91,7 @@ function list<T>(value: T[] | undefined | null, fallback: T[]) {
return fallback
}

type SummaryDiff = SnapshotFileDiff & { file: string }
type SummaryDiff = (SnapshotFileDiff & { file: string }) | FileDiffInfo

function summaryDiff(value: SnapshotFileDiff): value is SummaryDiff {
return typeof value.file === "string"
Expand Down
3 changes: 2 additions & 1 deletion packages/session-ui/src/context/data.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Message, Session, Part, SnapshotFileDiff, SessionStatus, Provider } from "@opencode-ai/sdk/v2"
import type { FileDiffInfo } from "@opencode-ai/client/promise"
import { createSimpleContext } from "@opencode-ai/ui/context"
import { PreloadMultiFileDiffResult } from "@pierre/diffs/ssr"

Expand All @@ -21,7 +22,7 @@ type Data = {
[sessionID: string]: SessionStatus
}
session_diff: {
[sessionID: string]: SnapshotFileDiff[]
[sessionID: string]: (SnapshotFileDiff | FileDiffInfo)[]
}
session_diff_preload?: {
[sessionID: string]: PreloadMultiFileDiffResult<any>[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { useI18n } from "@opencode-ai/ui/context/i18n"
import { mediaKindFromPath } from "../../pierre/media"
import { cloneSelectedLineRange, previewSelectedLines } from "../../pierre/selection-bridge"
import type { FileContent, SnapshotFileDiff, VcsFileDiff } from "@opencode-ai/sdk/v2"
import type { FileDiffInfo } from "@opencode-ai/client/promise"
import { createEffect, createMemo, onCleanup, Show, untrack } from "solid-js"
import { createStore } from "solid-js/store"
import { Dynamic } from "solid-js/web"
Expand All @@ -27,7 +28,7 @@ import { LineCommentV2OverflowIcon } from "@opencode-ai/ui/v2/line-comment-v2"
import { MenuV2 } from "@opencode-ai/ui/v2/menu-v2"
import "./session-review-v2.css"

type ReviewDiff = (SnapshotFileDiff & { file: string }) | VcsFileDiff
type ReviewDiff = (SnapshotFileDiff & { file: string }) | FileDiffInfo | VcsFileDiff

export type SessionReviewFilePreviewV2Props = {
file: string
Expand Down
Loading