import { createStore } from "solid-js/store"
import { parseDiffFromFile } from "@pierre/diffs"
import { CurrentSessionProviders } from "../storybook/current-session-story"
import { editThenTestDocument, reviewDiffs } from "../storybook/current-session-fixtures"
import { File } from "./file"
import { Button } from "@opencode/ui/button"
import { SessionReview, type SessionReviewComment, type SessionReviewFocus } from "./session-review"
type ReviewArgs = { split: boolean; empty: boolean; disableLineNumbers: boolean; overflow: "wrap" | "scroll" }
function ReviewStory(props: ReviewArgs) {
return (
diff.file)}
split={props.split}
overflow={props.overflow}
disableLineNumbers={props.disableLineNumbers}
/>
)
}
export default {
title: "OpenCode/Review/Changed files",
id: "components-session-review",
component: SessionReview,
parameters: {
layout: "fullscreen",
docs: {
description: {
component:
"The production inline review surface with current Session diffs. Expand files, switch the view, and inspect the same content in both color schemes.",
},
},
},
}
export const Unified = {
args: { split: false, empty: false, disableLineNumbers: false, overflow: "wrap" },
argTypes: { overflow: { options: ["wrap", "scroll"] } },
render: (args: ReviewArgs) => ,
}
export const Split = {
...Unified,
args: { ...Unified.args, split: true },
}
export const UnifiedDark = {
...Unified,
globals: { theme: "dark" },
}
const commentFile = "src/review.ts"
const mentionPaths = [commentFile, "src/review.test.ts", "src/server.ts", "README.md"]
const commentDiffs = [
{
file: commentFile,
additions: 1,
deletions: 1,
status: "modified" as const,
patch:
"diff --git a/src/review.ts b/src/review.ts\n--- a/src/review.ts\n+++ b/src/review.ts\n@@ -1,3 +1,3 @@\n export const first = 1\n-export const value = 'before'\n+export const value = 'after'\n export const last = 3\n",
},
]
function InteractiveCommentsStory() {
const [state, setState] = createStore<{ comments: SessionReviewComment[]; next: number }>({ comments: [], next: 1 })
return (
{
setState("comments", (comments) => [...comments, { id: `comment-${state.next}`, ...comment }])
setState("next", (next) => next + 1)
}}
onLineCommentUpdate={(update) =>
setState("comments", (comment) => comment.id === update.id, "comment", update.comment)
}
onLineCommentDelete={(target) =>
setState("comments", (comments) => comments.filter((comment) => comment.id !== target.id))
}
lineCommentActions={{
moreLabel: "More options",
editLabel: "Edit",
deleteLabel: "Delete",
saveLabel: "Save",
}}
lineCommentMention={{ items: (query) => mentionPaths.filter((path) => path.includes(query)) }}
/>
)
}
export const InteractiveComments = { render: () => }
// A parent asks the review to reveal a saved comment, as a composer chip does. "Focus missing comment" names a
// comment that never renders, so the request settles by timing out.
function FocusedCommentStory() {
const [state, setState] = createStore<{ focus: SessionReviewFocus | null }>({ focus: null })
const comments: SessionReviewComment[] = [
{
id: "comment-1",
file: commentFile,
selection: { start: 2, end: 2, side: "additions" },
comment: "Saved comment",
},
]
return (
Focus request:
setState("focus", focus)}
onLineComment={() => undefined}
/>
)
}
export const FocusedComment = { render: () => }
const gitDiffs = [
{
// OpenCode 93e1f383dd79683af4fc5ad139cea0516603c838, unchanged git-show output.
file: "packages/session-ui/src/components/file.tsx",
additions: 1,
deletions: 1,
patch: `diff --git a/packages/session-ui/src/components/file.tsx b/packages/session-ui/src/components/file.tsx
index 704971b014..4876731cbd 100644
--- a/packages/session-ui/src/components/file.tsx
+++ b/packages/session-ui/src/components/file.tsx
@@ -702,7 +702,7 @@ function ViewerShell(props: {
data-mode={props.mode}
dir="ltr"
style={styleVariables}
- class="relative outline-none"
+ class="relative select-text outline-none"
classList={{
...props.classList,
[props.class ?? ""]: !!props.class,
`,
},
{
// OpenCode 497a24c17d, unchanged git-show output.
file: "packages/core/src/session/runner/retry.ts",
additions: 1,
deletions: 1,
patch: `diff --git a/packages/core/src/session/runner/retry.ts b/packages/core/src/session/runner/retry.ts
index 10f6680097..ef26792ffe 100644
--- a/packages/core/src/session/runner/retry.ts
+++ b/packages/core/src/session/runner/retry.ts
@@ -15,7 +15,7 @@ export interface Input {
}
\x20
export function isRetryable(error: AIError) {
- const override = "http" in error.reason ? error.reason.http?.response?.headers["x-should-retry"] : undefined
+ const override = error.reason.http?.headers["x-should-retry"]
if (override === "true") return true
if (override === "false") return false
switch (error.reason._tag) {
`,
},
]
export const InlineChanges = {
args: { split: false },
render: (args: { split: boolean }) => (
diff.file)}
split={args.split}
/>
),
}
export const LargeFile = {
args: { split: false, source: "files" },
argTypes: { source: { control: "select", options: ["files", "metadata"] } },
render: (args: { split: boolean; source: string }) => {
// Cross the viewer's 500,000-character limit without long changed lines or 1,000 total lines.
const padding = `// ${"unchanged ".repeat(70)}\n`.repeat(800)
const before = { name: "large.ts", contents: `export const value = 'before'\n${padding}` }
const after = { name: "large.ts", contents: `export const value = 'after'\n${padding}` }
return (
)
},
}