Compare commits

..
Author SHA1 Message Date
Cursor AgentandJulius Marminge b89ba0651b Format image preview dialog callback
Co-authored-by: Julius Marminge <[email protected]>
2026-05-20 16:12:09 +00:00
Cursor AgentandJulius Marminge 406d486e06 Refresh React Scan after recording
Co-authored-by: Julius Marminge <[email protected]>
2026-05-20 16:11:38 +00:00
Cursor AgentandJulius Marminge 100a978bc5 Derive image preview index during render
Co-authored-by: Julius Marminge <[email protected]>
2026-05-20 16:10:45 +00:00
Cursor AgentandJulius Marminge 926042276d Add React Scan image preview recordings
Co-authored-by: Julius Marminge <[email protected]>
2026-05-20 16:09:58 +00:00
Cursor AgentandJulius Marminge 5a5afe7f8f Avoid effect-sync renders in image preview dialog
Co-authored-by: Julius Marminge <[email protected]>
2026-05-20 16:08:52 +00:00
9 changed files with 121 additions and 180 deletions

No files matched your search

@@ -1,4 +1,4 @@
import { assert, describe, expect, it } from "@effect/vitest";
import { describe, expect, it } from "@effect/vitest";
import * as DateTime from "effect/DateTime";
import * as Effect from "effect/Effect";
import * as Layer from "effect/Layer";
@@ -66,56 +66,6 @@ describe("ProcessDiagnostics", () => {
}),
);
it.effect("parses Windows process JSON through schemas", () =>
Effect.sync(() => {
const rows = ProcessDiagnostics.parseWindowsProcessRows(`
[
{
"ProcessId": 4242,
"ParentProcessId": 100,
"CommandLine": "node server.js",
"WorkingSetSize": 4096.7,
"PercentProcessorTime": 2.5,
"Status": "Running"
},
{
"ProcessId": 0,
"ParentProcessId": 100,
"Name": "invalid.exe"
},
{
"ProcessId": 4243,
"ParentProcessId": 4242,
"Name": "child.exe"
}
]
`);
assert.deepEqual(rows, [
{
pid: 4242,
ppid: 100,
pgid: null,
status: "Running",
cpuPercent: 2.5,
rssBytes: 4097,
elapsed: "",
command: "node server.js",
},
{
pid: 4243,
ppid: 4242,
pgid: null,
status: "Live",
cpuPercent: 0,
rssBytes: 0,
elapsed: "",
command: "child.exe",
},
]);
}),
);
it.effect("aggregates only descendants of the server process", () =>
Effect.sync(() => {
const diagnostics = ProcessDiagnostics.aggregateProcessDiagnostics({
@@ -26,23 +26,9 @@ export interface ProcessRow {
readonly command: string;
}
const PROCESS_QUERY_TIMEOUT_MS = 1_000;
const POSIX_PROCESS_QUERY_COMMAND = "pid=,ppid=,pgid=,stat=,pcpu=,rss=,etime=,command=";
const PROCESS_QUERY_MAX_OUTPUT_BYTES = 2 * 1024 * 1024;
const PROCESS_QUERY_TIMEOUT = Duration.seconds(1);
const WindowsProcessRecord = Schema.Struct({
ProcessId: Schema.Number,
ParentProcessId: Schema.Number,
CommandLine: Schema.optional(Schema.String),
Name: Schema.optional(Schema.String),
WorkingSetSize: Schema.optional(Schema.Number),
PercentProcessorTime: Schema.optional(Schema.Number),
Status: Schema.optional(Schema.String),
});
type WindowsProcessRecord = typeof WindowsProcessRecord.Type;
const WindowsProcessJson = Schema.fromJsonString(Schema.Unknown);
const decodeWindowsProcessRecord = Schema.decodeUnknownOption(WindowsProcessRecord);
const decodeWindowsProcessJson = Schema.decodeUnknownOption(WindowsProcessJson);
export interface ProcessDiagnosticsShape {
readonly read: Effect.Effect<ServerProcessDiagnosticsResult>;
@@ -88,9 +74,6 @@ function parseNumber(value: string): number | null {
return Number.isFinite(parsed) ? parsed : null;
}
const nonEmptyWindowsString = (value: string | undefined): Option.Option<string> =>
Option.fromUndefinedOr(value).pipe(Option.filter((text) => text.trim().length > 0));
export function parsePosixProcessRows(output: string): ReadonlyArray<ProcessRow> {
const rows: ProcessRow[] = [];
const rowPattern =
@@ -156,61 +139,51 @@ export function parsePosixProcessRows(output: string): ReadonlyArray<ProcessRow>
return rows;
}
function normalizeWindowsProcessRow(record: WindowsProcessRecord): Option.Option<ProcessRow> {
const pid = Number.isInteger(record.ProcessId) ? Option.some(record.ProcessId) : Option.none();
const ppid = Number.isInteger(record.ParentProcessId)
? Option.some(record.ParentProcessId)
: Option.none();
const commandLine = nonEmptyWindowsString(record.CommandLine).pipe(
Option.orElse(() => nonEmptyWindowsString(record.Name)),
);
function normalizeWindowsProcessRow(value: unknown): ProcessRow | null {
if (typeof value !== "object" || value === null) return null;
const record = value as Record<string, unknown>;
const pid = typeof record.ProcessId === "number" ? record.ProcessId : null;
const ppid = typeof record.ParentProcessId === "number" ? record.ParentProcessId : null;
const commandLine =
typeof record.CommandLine === "string" && record.CommandLine.trim().length > 0
? record.CommandLine
: typeof record.Name === "string"
? record.Name
: null;
const workingSet =
record.WorkingSetSize !== undefined && Number.isFinite(record.WorkingSetSize)
typeof record.WorkingSetSize === "number" && Number.isFinite(record.WorkingSetSize)
? Math.max(0, Math.round(record.WorkingSetSize))
: 0;
const cpuPercent =
record.PercentProcessorTime !== undefined && Number.isFinite(record.PercentProcessorTime)
typeof record.PercentProcessorTime === "number" && Number.isFinite(record.PercentProcessorTime)
? Math.max(0, record.PercentProcessorTime)
: 0;
if (
Option.isNone(pid) ||
pid.value <= 0 ||
Option.isNone(ppid) ||
ppid.value < 0 ||
Option.isNone(commandLine)
) {
return Option.none<ProcessRow>();
}
return Option.some({
pid: pid.value,
ppid: ppid.value,
if (!pid || pid <= 0 || ppid === null || ppid < 0 || !commandLine) return null;
return {
pid,
ppid,
pgid: null,
status: record.Status !== undefined && record.Status.length > 0 ? record.Status : "Live",
status: typeof record.Status === "string" && record.Status.length > 0 ? record.Status : "Live",
cpuPercent,
rssBytes: workingSet,
elapsed: "",
command: commandLine.value,
});
command: commandLine,
};
}
export function parseWindowsProcessRows(output: string): ReadonlyArray<ProcessRow> {
function parseWindowsProcessRows(output: string): ReadonlyArray<ProcessRow> {
if (output.trim().length === 0) return [];
const parsed = decodeWindowsProcessJson(output);
if (Option.isNone(parsed)) return [];
const records = Array.isArray(parsed.value) ? parsed.value : [parsed.value];
return records.flatMap((record) => {
const decoded = decodeWindowsProcessRecord(record);
return Option.match(decoded, {
onNone: () => [],
onSome: (windowsRecord) =>
Option.match(normalizeWindowsProcessRow(windowsRecord), {
onNone: () => [],
onSome: (row) => [row],
}),
try {
const parsed = JSON.parse(output) as unknown;
const records = Array.isArray(parsed) ? parsed : [parsed];
return records.flatMap((record) => {
const row = normalizeWindowsProcessRow(record);
return row ? [row] : [];
});
});
} catch {
return [];
}
}
export function buildDescendantEntries(
@@ -336,7 +309,7 @@ const runProcess = Effect.fn("runProcess")(
(effect, input) =>
effect.pipe(
Effect.scoped,
Effect.timeoutOption(PROCESS_QUERY_TIMEOUT),
Effect.timeoutOption(Duration.millis(PROCESS_QUERY_TIMEOUT_MS)),
Effect.flatMap((result) =>
Option.match(result, {
onNone: () => Effect.fail(toProcessDiagnosticsError(`${input.errorMessage} timed out.`)),
@@ -67,24 +67,4 @@ describe("VcsProjectConfig", () => {
}),
);
});
it.layer(TestLayer)("falls back to auto when config is invalid JSON", (it) => {
it.effect("returns auto", () =>
Effect.gen(function* () {
const fileSystem = yield* FileSystem.FileSystem;
const path = yield* Path.Path;
const root = yield* fileSystem.makeTempDirectoryScoped({
prefix: "t3-vcs-config-test-",
});
const configDir = path.join(root, ".t3code");
yield* fileSystem.makeDirectory(configDir, { recursive: true });
yield* fileSystem.writeFileString(path.join(configDir, "vcs.json"), "{ nope");
const config = yield* VcsProjectConfig.VcsProjectConfig;
const kind = yield* config.resolveKind({ cwd: root });
assert.equal(kind, "auto");
}),
);
});
});
+28 -18
View File
@@ -2,7 +2,6 @@ import * as Context from "effect/Context";
import * as Effect from "effect/Effect";
import * as FileSystem from "effect/FileSystem";
import * as Layer from "effect/Layer";
import * as Option from "effect/Option";
import * as Path from "effect/Path";
import * as Schema from "effect/Schema";
@@ -16,10 +15,16 @@ const ProjectVcsConfig = Schema.Struct({
),
vcsKind: Schema.optional(VcsDriverKind),
});
const ProjectVcsConfigJson = Schema.fromJsonString(ProjectVcsConfig);
const decodeProjectVcsConfigJson = Schema.decodeUnknownOption(ProjectVcsConfigJson);
const isProjectVcsConfig = Schema.is(ProjectVcsConfig);
type ProjectVcsConfigFile = typeof ProjectVcsConfig.Type;
interface ProjectVcsConfigFile {
readonly vcs?:
| {
readonly kind?: VcsDriverKindType | undefined;
}
| undefined;
readonly vcsKind?: VcsDriverKindType | undefined;
}
export interface VcsProjectConfigResolveInput {
readonly cwd: string;
@@ -40,8 +45,13 @@ function configuredKind(config: ProjectVcsConfigFile): VcsDriverKindType | "auto
return config.vcs?.kind ?? config.vcsKind ?? "auto";
}
function parseConfig(raw: string): Option.Option<ProjectVcsConfigFile> {
return decodeProjectVcsConfigJson(raw);
function parseConfig(raw: string): ProjectVcsConfigFile | null {
try {
const parsed = JSON.parse(raw) as unknown;
return isProjectVcsConfig(parsed) ? parsed : null;
} catch {
return null;
}
}
export const make = Effect.fn("makeVcsProjectConfig")(function* () {
@@ -53,12 +63,12 @@ export const make = Effect.fn("makeVcsProjectConfig")(function* () {
while (true) {
const candidate = path.join(current, ".t3code", "vcs.json");
if (yield* fileSystem.exists(candidate).pipe(Effect.orElseSucceed(() => false))) {
return Option.some(candidate);
return candidate;
}
const parent = path.dirname(current);
if (parent === current) {
return Option.none<string>();
return null;
}
current = parent;
}
@@ -68,27 +78,26 @@ export const make = Effect.fn("makeVcsProjectConfig")(function* () {
configPath: string,
) {
const raw = yield* fileSystem.readFileString(configPath).pipe(
Effect.map(Option.some),
Effect.catch((error) =>
Effect.logWarning("failed to read VCS project config", {
configPath,
error,
}).pipe(Effect.as(Option.none<string>())),
}).pipe(Effect.as(null)),
),
);
if (Option.isNone(raw)) {
if (raw === null) {
return "auto" as const;
}
const parsed = parseConfig(raw.value);
if (Option.isNone(parsed)) {
const parsed = parseConfig(raw);
if (parsed === null) {
yield* Effect.logWarning("invalid VCS project config", {
configPath,
});
return "auto" as const;
}
return configuredKind(parsed.value);
return configuredKind(parsed);
});
const resolveKind: VcsProjectConfigShape["resolveKind"] = Effect.fn(
@@ -99,10 +108,11 @@ export const make = Effect.fn("makeVcsProjectConfig")(function* () {
}
const configPath = yield* findConfigPath(input.cwd);
return yield* Option.match(configPath, {
onNone: () => Effect.succeed("auto" as const),
onSome: readConfiguredKind,
});
if (configPath === null) {
return "auto";
}
return yield* readConfiguredKind(configPath);
});
return VcsProjectConfig.of({
+9 -2
View File
@@ -147,7 +147,10 @@ import { ExpandedImageDialog } from "./chat/ExpandedImageDialog";
import { PullRequestThreadDialog } from "./PullRequestThreadDialog";
import { MessagesTimeline } from "./chat/MessagesTimeline";
import { ChatHeader } from "./chat/ChatHeader";
import { type ExpandedImagePreview } from "./chat/ExpandedImagePreview";
import {
getExpandedImagePreviewIdentityKey,
type ExpandedImagePreview,
} from "./chat/ExpandedImagePreview";
import { NoActiveThreadState } from "./NoActiveThreadState";
import { resolveEffectiveEnvMode, resolveEnvironmentOptionLabel } from "./BranchToolbar.logic";
import { ProviderStatusBanner } from "./chat/ProviderStatusBanner";
@@ -3773,7 +3776,11 @@ export default function ChatView(props: ChatViewProps) {
) : null}
{expandedImage && (
<ExpandedImageDialog preview={expandedImage} onClose={closeExpandedImage} />
<ExpandedImageDialog
key={getExpandedImagePreviewIdentityKey(expandedImage)}
preview={expandedImage}
onClose={closeExpandedImage}
/>
)}
</div>
);
@@ -1,4 +1,4 @@
import { memo, useCallback, useEffect, useState } from "react";
import { memo, useCallback, useEffect, useEffectEvent, useState } from "react";
import { ChevronLeftIcon, ChevronRightIcon, XIcon } from "lucide-react";
import { Button } from "../ui/button";
import type { ExpandedImagePreview } from "./ExpandedImagePreview";
@@ -8,52 +8,65 @@ interface ExpandedImageDialogProps {
onClose: () => void;
}
export const ExpandedImageDialog = memo(function ExpandedImageDialog({
preview: initialPreview,
onClose,
}: ExpandedImageDialogProps) {
const [preview, setPreview] = useState(initialPreview);
// Sync when the parent hands us a new preview reference.
useEffect(() => {
setPreview(initialPreview);
}, [initialPreview]);
const navigateImage = useCallback((direction: -1 | 1) => {
setPreview((existing) => {
if (existing.images.length <= 1) return existing;
const nextIndex =
(existing.index + direction + existing.images.length) % existing.images.length;
if (nextIndex === existing.index) return existing;
return { ...existing, index: nextIndex };
});
}, []);
function useExpandedImageDialogKeyboardShortcuts(input: {
readonly imageCount: number;
readonly onClose: () => void;
readonly onNavigate: (direction: -1 | 1) => void;
}) {
const close = useEffectEvent(input.onClose);
const navigate = useEffectEvent(input.onNavigate);
useEffect(() => {
const onKeyDown = (event: globalThis.KeyboardEvent) => {
if (event.key === "Escape") {
event.preventDefault();
event.stopPropagation();
onClose();
close();
return;
}
if (preview.images.length <= 1) return;
if (input.imageCount <= 1) return;
if (event.key === "ArrowLeft") {
event.preventDefault();
event.stopPropagation();
navigateImage(-1);
navigate(-1);
return;
}
if (event.key !== "ArrowRight") return;
event.preventDefault();
event.stopPropagation();
navigateImage(1);
navigate(1);
};
window.addEventListener("keydown", onKeyDown);
return () => window.removeEventListener("keydown", onKeyDown);
}, [navigateImage, onClose, preview.images.length]);
}, [close, input.imageCount, navigate]);
}
const item = preview.images[preview.index];
export const ExpandedImageDialog = memo(function ExpandedImageDialog({
preview,
onClose,
}: ExpandedImageDialogProps) {
const [navigationOffset, setNavigationOffset] = useState(0);
const imageCount = preview.images.length;
const activeIndex =
imageCount > 0 ? (preview.index + navigationOffset + imageCount) % imageCount : preview.index;
const navigateImage = useCallback(
(direction: -1 | 1) => {
setNavigationOffset((offset) => {
if (imageCount <= 1) return offset;
return offset + direction;
});
},
[imageCount],
);
useExpandedImageDialogKeyboardShortcuts({
imageCount,
onClose,
onNavigate: navigateImage,
});
const item = preview.images[activeIndex];
if (!item) return null;
return (
@@ -69,7 +82,7 @@ export const ExpandedImageDialog = memo(function ExpandedImageDialog({
aria-label="Close image preview"
onClick={onClose}
/>
{preview.images.length > 1 && (
{imageCount > 1 && (
<Button
type="button"
size="icon"
@@ -100,10 +113,10 @@ export const ExpandedImageDialog = memo(function ExpandedImageDialog({
/>
<p className="mt-2 max-w-[92vw] truncate text-center text-xs text-muted-foreground/80">
{item.name}
{preview.images.length > 1 ? ` (${preview.index + 1}/${preview.images.length})` : ""}
{imageCount > 1 ? ` (${activeIndex + 1}/${imageCount})` : ""}
</p>
</div>
{preview.images.length > 1 && (
{imageCount > 1 && (
<Button
type="button"
size="icon"
@@ -8,6 +8,14 @@ export interface ExpandedImagePreview {
index: number;
}
export function getExpandedImagePreviewIdentityKey(preview: ExpandedImagePreview): string {
const selectedImage = preview.images[preview.index];
const selectedImageKey = selectedImage
? `${selectedImage.name.length}:${selectedImage.name}:${selectedImage.src.length}:${selectedImage.src}`
: "missing";
return `${preview.images.length}:${preview.index}:${selectedImageKey}`;
}
export function buildExpandedImagePreview(
images: ReadonlyArray<{ id: string; name: string; previewUrl?: string }>,
selectedImageId: string,
Binary file not shown.
Binary file not shown.