Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8580032a5f | ||
|
|
ebe8afb1df | ||
|
|
bf76535fe4 | ||
|
|
5c66110e26 | ||
|
|
da3c2030f7 | ||
|
|
0506508e9b | ||
|
|
b859a575d1 | ||
|
|
e63403fe92 | ||
|
|
c0e161af06 | ||
|
|
d0b9f8d40d | ||
|
|
d8b12ae801 | ||
|
|
31caa5652b | ||
|
|
e350c0a07b | ||
|
|
38e0bb07bb | ||
|
|
765e1b5fc0 | ||
|
|
03e20c875c | ||
|
|
2318e00270 | ||
|
|
4cfec8c128 | ||
|
|
1bd2fa25e2 |
No files matched your search
@@ -31,6 +31,12 @@ const TestLayer = ElectronMenu.layer.pipe(
|
||||
Layer.provide(Layer.succeed(HostProcessPlatform, "linux")),
|
||||
);
|
||||
|
||||
const makeWindow = (zoomFactor = 1): Electron.BrowserWindow =>
|
||||
({
|
||||
id: 7,
|
||||
webContents: { getZoomFactor: () => zoomFactor },
|
||||
}) as unknown as Electron.BrowserWindow;
|
||||
|
||||
describe("ElectronMenu", () => {
|
||||
beforeEach(() => {
|
||||
buildFromTemplateMock.mockReset();
|
||||
@@ -70,7 +76,7 @@ describe("ElectronMenu", () => {
|
||||
|
||||
const electronMenu = yield* ElectronMenu.ElectronMenu;
|
||||
const selectedItemId = yield* electronMenu.showContextMenu({
|
||||
window: {} as Electron.BrowserWindow,
|
||||
window: makeWindow(),
|
||||
items: [{ id: "copy", label: "Copy" }],
|
||||
position: Option.none(),
|
||||
});
|
||||
@@ -81,20 +87,24 @@ describe("ElectronMenu", () => {
|
||||
|
||||
it.effect("resolves with none when the menu closes without a click", () =>
|
||||
Effect.gen(function* () {
|
||||
let popupOptions: Electron.PopupOptions | undefined;
|
||||
buildFromTemplateMock.mockImplementation(() => ({
|
||||
popup: (options: Electron.PopupOptions) => {
|
||||
popupOptions = options;
|
||||
options.callback?.();
|
||||
},
|
||||
}));
|
||||
|
||||
const electronMenu = yield* ElectronMenu.ElectronMenu;
|
||||
const selectedItemId = yield* electronMenu.showContextMenu({
|
||||
window: {} as Electron.BrowserWindow,
|
||||
window: makeWindow(2),
|
||||
items: [{ id: "copy", label: "Copy" }],
|
||||
position: Option.some({ x: 10.8, y: 20.2 }),
|
||||
});
|
||||
|
||||
assert.isTrue(Option.isNone(selectedItemId));
|
||||
assert.equal(popupOptions?.x, 21);
|
||||
assert.equal(popupOptions?.y, 40);
|
||||
assert.deepEqual(buildFromTemplateMock.mock.calls[0]?.[0][0], {
|
||||
label: "Copy",
|
||||
enabled: true,
|
||||
|
||||
@@ -94,13 +94,20 @@ function normalizeContextMenuItems(source: readonly ContextMenuItem[]): ContextM
|
||||
return normalizedItems;
|
||||
}
|
||||
|
||||
// Renderer positions arrive in CSS pixels; popup() expects window points, so
|
||||
// page zoom must be factored in or menus drift proportionally to their
|
||||
// distance from the window origin.
|
||||
const normalizePosition = (
|
||||
position: Option.Option<ElectronMenuPosition>,
|
||||
zoomFactor: number,
|
||||
): Option.Option<ElectronMenuPosition> =>
|
||||
Option.filter(
|
||||
position,
|
||||
({ x, y }) => Number.isFinite(x) && Number.isFinite(y) && x >= 0 && y >= 0,
|
||||
).pipe(Option.map(({ x, y }) => ({ x: Math.floor(x), y: Math.floor(y) })));
|
||||
({ x, y }) =>
|
||||
Number.isFinite(x) && Number.isFinite(y) && x >= 0 && y >= 0 && Number.isFinite(zoomFactor),
|
||||
).pipe(
|
||||
Option.map(({ x, y }) => ({ x: Math.floor(x * zoomFactor), y: Math.floor(y * zoomFactor) })),
|
||||
);
|
||||
|
||||
export const make = Effect.gen(function* () {
|
||||
const platform = yield* HostProcessPlatform;
|
||||
@@ -214,7 +221,10 @@ export const make = Effect.gen(function* () {
|
||||
|
||||
try {
|
||||
const menu = Electron.Menu.buildFromTemplate(buildTemplate(normalizedItems, complete));
|
||||
const popupPosition = normalizePosition(input.position);
|
||||
const popupPosition = normalizePosition(
|
||||
input.position,
|
||||
input.window.webContents.getZoomFactor(),
|
||||
);
|
||||
const popupOptions = Option.match(popupPosition, {
|
||||
onNone: (): Electron.PopupOptions => ({
|
||||
window: input.window,
|
||||
|
||||
@@ -16,6 +16,7 @@ import {
|
||||
formatNodePtyProbeFailureReason,
|
||||
formatWslShellTransportFailureReason,
|
||||
parseNodePath,
|
||||
parseNodeVersion,
|
||||
parseResolvedPath,
|
||||
parseToolchainReport,
|
||||
probeWslDistros,
|
||||
@@ -173,6 +174,29 @@ describe("parseNodePath", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("parseNodeVersion", () => {
|
||||
it("extracts the node version from a nodeVersion: line", () => {
|
||||
expect(parseNodeVersion("nodeVersion:24.10.0")).toBe("24.10.0");
|
||||
});
|
||||
|
||||
it("returns null when the version value is empty", () => {
|
||||
expect(parseNodeVersion("nodeVersion:")).toBeNull();
|
||||
});
|
||||
|
||||
it("returns null when there is no nodeVersion line at all", () => {
|
||||
expect(parseNodeVersion("nodePath:/usr/bin/node\nresolvedPath:/usr/bin")).toBeNull();
|
||||
});
|
||||
|
||||
it("ignores surrounding noise and trims whitespace", () => {
|
||||
const stdout = [
|
||||
"some preamble noise",
|
||||
" nodeVersion:22.16.0 ",
|
||||
"nodePath:/usr/bin/node",
|
||||
].join("\n");
|
||||
expect(parseNodeVersion(stdout)).toBe("22.16.0");
|
||||
});
|
||||
});
|
||||
|
||||
describe("parseResolvedPath", () => {
|
||||
it("preserves spaces and apostrophes in the resolved login-shell PATH", () => {
|
||||
const resolvedPath = "/home/test user/bin:/opt/test's tools/bin:/usr/bin:/bin";
|
||||
|
||||
@@ -32,7 +32,11 @@ export interface EnsureWslNodePtyOptions {
|
||||
}
|
||||
|
||||
export type EnsureWslNodePtyResult =
|
||||
| { readonly ok: true; readonly nodePath: string; readonly resolvedPath: string }
|
||||
| {
|
||||
readonly ok: true;
|
||||
readonly nodePath: string;
|
||||
readonly resolvedPath: string;
|
||||
}
|
||||
| {
|
||||
readonly ok: false;
|
||||
readonly reason: string;
|
||||
@@ -222,6 +226,7 @@ export const formatNodePtyProbeFailureReason = (exitCode: number): string | null
|
||||
const NODE_PTY_PROBE_SCRIPT = (
|
||||
linuxServerDir: string,
|
||||
) => `printf 'nodePath:%s\\n' "$(command -v node 2>/dev/null)"
|
||||
printf 'nodeVersion:%s\\n' "$(node -p 'process.versions.node' 2>/dev/null)"
|
||||
printf 'resolvedPath:%s\\n' "$PATH"
|
||||
cd ${shellQuote(linuxServerDir)} && node <<'NODE' >/dev/null 2>&1
|
||||
// The server bundle externalizes its deps to node_modules, and the WSL Node
|
||||
@@ -318,6 +323,16 @@ export const parseNodePath = (stdout: string): string | null => {
|
||||
return path ?? null;
|
||||
};
|
||||
|
||||
export const parseNodeVersion = (stdout: string): string | null => {
|
||||
const version = stdout
|
||||
.split("\n")
|
||||
.map((line) => line.trim())
|
||||
.filter((line) => line.startsWith("nodeVersion:"))
|
||||
.map((line) => line.slice("nodeVersion:".length).trim())
|
||||
.find((value) => value.length > 0);
|
||||
return version ?? null;
|
||||
};
|
||||
|
||||
// Captures the login-shell PATH after the shared resolver has loaded version
|
||||
// managers. Preserve the value byte-for-byte apart from a Windows-style CR so
|
||||
// paths containing spaces or apostrophes can be forwarded as one env argv.
|
||||
@@ -404,7 +419,11 @@ const ensureNodePtyImpl = (
|
||||
|
||||
const transportFailureReason = formatWslShellTransportFailureReason(probe.transportFailure);
|
||||
if (transportFailureReason !== null) {
|
||||
return { ok: false, reason: transportFailureReason, fatal: false } as const;
|
||||
return {
|
||||
ok: false,
|
||||
reason: transportFailureReason,
|
||||
fatal: false,
|
||||
} as const;
|
||||
}
|
||||
|
||||
// No node at all, even after the shared resolver repaired PATH. Surface
|
||||
@@ -457,12 +476,31 @@ const ensureNodePtyImpl = (
|
||||
} as const;
|
||||
}
|
||||
|
||||
if (probe.exitCode === 0) return { ok: true, nodePath, resolvedPath } as const;
|
||||
if (probe.exitCode === 0) {
|
||||
const rawVersion = parseNodeVersion(probe.stdout);
|
||||
if (
|
||||
rawVersion !== null &&
|
||||
options.nodeEngineRange &&
|
||||
!satisfiesSemverRange(rawVersion, options.nodeEngineRange.trim())
|
||||
) {
|
||||
const range = options.nodeEngineRange.trim();
|
||||
return {
|
||||
ok: false,
|
||||
reason: `WSL Node.js ${rawVersion} does not satisfy the server's required engine range (${range}). Install a compatible version, and restart the desktop app.`,
|
||||
fatal: true,
|
||||
} as const;
|
||||
}
|
||||
return { ok: true, nodePath, resolvedPath } as const;
|
||||
}
|
||||
|
||||
if (options.allowBuild !== true) {
|
||||
const packagedProbeFailure = formatNodePtyProbeFailureReason(probe.exitCode);
|
||||
if (packagedProbeFailure !== null) {
|
||||
return { ok: false, reason: packagedProbeFailure, fatal: true } as const;
|
||||
return {
|
||||
ok: false,
|
||||
reason: packagedProbeFailure,
|
||||
fatal: true,
|
||||
} as const;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none">
|
||||
<path fill="#F5F5F5" d="M9.26905 15.284L17.2479 9.36086C17.6391 9.07047 18.1981 9.18374 18.3845 9.63478C19.3655 12.0135 18.9272 14.8721 16.9755 16.8349C15.0238 18.7976 12.3082 19.228 9.8261 18.2477L7.1146 19.5102C11.0037 22.1834 15.7263 21.5223 18.6774 18.5525C21.0182 16.1985 21.7432 12.9897 21.0653 10.0961L21.0714 10.1023C20.0884 5.85143 21.3131 4.15233 23.8218 0.677913C23.8812 0.595532 23.9406 0.513151 24 0.428711L20.6987 3.74866V3.73836L9.267 15.2861" />
|
||||
<path fill="#F5F5F5" d="M7.62249 16.7237C4.83113 14.0422 5.3124 9.89222 7.69417 7.49905C9.45541 5.72786 12.341 5.00497 14.86 6.06768L17.5653 4.81138C17.0779 4.45714 16.4533 4.07613 15.7365 3.80839C12.4966 2.46764 8.6178 3.13492 5.98413 5.78141C3.45081 8.32904 2.65415 12.2463 4.02219 15.5889C5.04412 18.0871 3.36889 19.8541 1.68137 21.6377C1.08337 22.2699 0.483318 22.9022 0 23.5716L7.62045 16.7257" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 948 B |
@@ -33,6 +33,9 @@ const mobileEndorsementRows = [
|
||||
<span class="hero-float-mark hf-cursor" title="Cursor">
|
||||
<img src="/harnesses/cursor_light.svg" alt="" />
|
||||
</span>
|
||||
<span class="hero-float-mark hf-grok" title="Grok">
|
||||
<img src="/harnesses/grok-dark.svg" alt="" />
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="container hero-inner">
|
||||
@@ -41,7 +44,7 @@ const mobileEndorsementRows = [
|
||||
</h1>
|
||||
|
||||
<p class="hero-sub">
|
||||
Orchestrate Claude Code, Codex, OpenCode and Cursor from one surface.
|
||||
Orchestrate Claude Code, Codex, OpenCode, Cursor, and Grok from one surface.
|
||||
Bring your own subscription. Fork the whole thing.
|
||||
</p>
|
||||
|
||||
@@ -173,7 +176,7 @@ const mobileEndorsementRows = [
|
||||
<h2>Bring your own sub</h2>
|
||||
<p>
|
||||
T3 Code doesn't resell tokens. Plug in Claude Code, Codex, OpenCode,
|
||||
or Cursor with the credentials you already have — we orchestrate
|
||||
Cursor, or Grok with the credentials you already have — we orchestrate
|
||||
them, you keep your plan.
|
||||
</p>
|
||||
</div>
|
||||
@@ -207,6 +210,13 @@ const mobileEndorsementRows = [
|
||||
<div class="harness-tag">cursor-agent</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="harness">
|
||||
<div class="harness-mark"><img src="/harnesses/grok-dark.svg" alt="" /></div>
|
||||
<div class="harness-meta">
|
||||
<div class="harness-name">Grok CLI</div>
|
||||
<div class="harness-tag">grok login</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="harness-footer">
|
||||
@@ -615,8 +625,9 @@ const mobileEndorsementRows = [
|
||||
|
||||
.hero-float-mark.hf-claude { background: radial-gradient(circle at 30% 25%, rgba(217, 119, 87, 0.22), rgba(20, 20, 24, 0.92) 65%); top: 8%; left: 7%; animation-delay: 0s; transform: rotate(-8deg); }
|
||||
.hero-float-mark.hf-codex { background: radial-gradient(circle at 30% 25%, rgba(255, 255, 255, 0.08), rgba(20, 20, 24, 0.92) 65%); top: 6%; right: 7%; animation-delay: -2.5s; transform: rotate(6deg); }
|
||||
.hero-float-mark.hf-opencode { background: radial-gradient(circle at 30% 25%, rgba(255, 255, 255, 0.06), rgba(20, 20, 24, 0.92) 65%); top: 32%; left: 5%; animation-delay: -5s; transform: rotate(4deg); }
|
||||
.hero-float-mark.hf-opencode { background: radial-gradient(circle at 30% 25%, rgba(255, 255, 255, 0.06), rgba(20, 20, 24, 0.92) 65%); top: 30%; left: 5%; animation-delay: -5s; transform: rotate(4deg); }
|
||||
.hero-float-mark.hf-cursor { background: radial-gradient(circle at 30% 25%, rgba(255, 255, 255, 0.08), rgba(20, 20, 24, 0.92) 65%); top: 30%; right: 5%; animation-delay: -7s; transform: rotate(-5deg); }
|
||||
.hero-float-mark.hf-grok { background: radial-gradient(circle at 30% 25%, rgba(255, 255, 255, 0.08), rgba(20, 20, 24, 0.92) 65%); top: 52%; left: 6%; animation-delay: -1.2s; transform: rotate(3deg); }
|
||||
|
||||
@media (max-width: 1180px) {
|
||||
.hero-float-mark { width: 76px; height: 76px; border-radius: 20px; }
|
||||
@@ -625,6 +636,7 @@ const mobileEndorsementRows = [
|
||||
.hero-float-mark.hf-codex { top: 2%; right: 3%; }
|
||||
.hero-float-mark.hf-opencode { top: 26%; left: 2%; }
|
||||
.hero-float-mark.hf-cursor { top: 24%; right: 2%; }
|
||||
.hero-float-mark.hf-grok { top: 48%; left: 2%; transform: rotate(3deg); }
|
||||
}
|
||||
|
||||
@media (max-width: 820px) {
|
||||
@@ -659,17 +671,18 @@ const mobileEndorsementRows = [
|
||||
height: 44px;
|
||||
}
|
||||
|
||||
/* Two above the title, two flanking the call-to-action area. */
|
||||
/* Three stacked on the left, two on the right — keeps the center CTA clear. */
|
||||
.hero-float-mark.hf-claude {
|
||||
top: 44px;
|
||||
left: 10px;
|
||||
transform: rotate(-10deg);
|
||||
}
|
||||
|
||||
.hero-float-mark.hf-codex {
|
||||
top: 44px;
|
||||
right: 10px;
|
||||
transform: rotate(8deg);
|
||||
.hero-float-mark.hf-grok {
|
||||
top: 240px;
|
||||
left: 4px;
|
||||
right: auto;
|
||||
transform: rotate(-4deg);
|
||||
}
|
||||
|
||||
.hero-float-mark.hf-opencode {
|
||||
@@ -679,6 +692,12 @@ const mobileEndorsementRows = [
|
||||
transform: rotate(-6deg);
|
||||
}
|
||||
|
||||
.hero-float-mark.hf-codex {
|
||||
top: 44px;
|
||||
right: 10px;
|
||||
transform: rotate(8deg);
|
||||
}
|
||||
|
||||
.hero-float-mark.hf-cursor {
|
||||
top: 474px;
|
||||
right: 4px;
|
||||
@@ -688,6 +707,14 @@ const mobileEndorsementRows = [
|
||||
}
|
||||
|
||||
@media (max-width: 340px) {
|
||||
.hero-float-mark.hf-grok {
|
||||
top: 220px;
|
||||
left: 0;
|
||||
width: 52px;
|
||||
height: 52px;
|
||||
border-radius: 14px;
|
||||
}
|
||||
|
||||
.hero-float-mark.hf-opencode,
|
||||
.hero-float-mark.hf-cursor {
|
||||
top: 580px;
|
||||
@@ -704,6 +731,7 @@ const mobileEndorsementRows = [
|
||||
right: 0;
|
||||
}
|
||||
|
||||
.hero-float-mark.hf-grok img,
|
||||
.hero-float-mark.hf-opencode img,
|
||||
.hero-float-mark.hf-cursor img {
|
||||
width: 30px;
|
||||
@@ -750,7 +778,7 @@ const mobileEndorsementRows = [
|
||||
|
||||
.harness-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(4, 1fr);
|
||||
grid-template-columns: repeat(5, 1fr);
|
||||
gap: 0;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--radius);
|
||||
@@ -1205,6 +1233,10 @@ const mobileEndorsementRows = [
|
||||
.harness-grid { grid-template-columns: 1fr 1fr; }
|
||||
.harness { border-right: 0; border-bottom: 1px solid var(--border); }
|
||||
.harness:nth-child(odd) { border-right: 1px solid var(--border); }
|
||||
.harness:nth-child(5):last-child {
|
||||
grid-column: 1 / -1;
|
||||
border-right: 0;
|
||||
}
|
||||
.git-inner { grid-template-columns: 1fr; gap: 40px; }
|
||||
.open-grid { grid-template-columns: 1fr; }
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import { DynamicColorIOS, Platform, Pressable, ScrollView, StyleSheet } from "re
|
||||
import { useResolveClassNames } from "uniwind";
|
||||
|
||||
import { AppText as Text } from "./components/AppText";
|
||||
import { renderCompactBrandTitle } from "./components/CompactBrandTitle";
|
||||
import { ArchivedThreadsRouteScreen } from "./features/archive/ArchivedThreadsRouteScreen";
|
||||
import { useAgentNotificationNavigation } from "./features/agent-awareness/notificationNavigation";
|
||||
import { ClerkSettingsSheetDetentProvider } from "./features/cloud/ClerkSettingsSheetDetent";
|
||||
@@ -377,7 +378,8 @@ export const RootStack = createNativeStackNavigator({
|
||||
...GLASS_HEADER_OPTIONS,
|
||||
contentStyle: { backgroundColor: "transparent" },
|
||||
headerBackVisible: false,
|
||||
title: "Threads",
|
||||
headerTitle: renderCompactBrandTitle,
|
||||
title: "T3 Code",
|
||||
},
|
||||
}),
|
||||
Thread: createNativeStackScreen({
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
import { View } from "react-native";
|
||||
|
||||
import { AppText as Text } from "./AppText";
|
||||
import { T3Wordmark } from "./T3Wordmark";
|
||||
import { useThemeColor } from "../lib/useThemeColor";
|
||||
|
||||
/**
|
||||
* Compact brand lockup sized for native navigation bars.
|
||||
*/
|
||||
export function CompactBrandTitle() {
|
||||
const iconColor = useThemeColor("--color-icon");
|
||||
const mutedColor = useThemeColor("--color-foreground-muted");
|
||||
const subtleColor = useThemeColor("--color-subtle");
|
||||
|
||||
return (
|
||||
<View
|
||||
aria-level={1}
|
||||
accessibilityLabel="T3 Code"
|
||||
accessible
|
||||
role="heading"
|
||||
style={{ alignItems: "center", flexDirection: "row", gap: 6 }}
|
||||
>
|
||||
<T3Wordmark color={iconColor} height={11} />
|
||||
<Text
|
||||
style={{
|
||||
color: mutedColor,
|
||||
fontFamily: "DMSans-Medium",
|
||||
fontSize: 14,
|
||||
letterSpacing: -0.35,
|
||||
}}
|
||||
>
|
||||
Code
|
||||
</Text>
|
||||
<View
|
||||
style={{
|
||||
backgroundColor: subtleColor,
|
||||
borderRadius: 999,
|
||||
paddingHorizontal: 6,
|
||||
paddingVertical: 2,
|
||||
}}
|
||||
>
|
||||
<Text
|
||||
style={{
|
||||
color: mutedColor,
|
||||
fontFamily: "DMSans-Bold",
|
||||
fontSize: 9,
|
||||
letterSpacing: 0.9,
|
||||
textTransform: "uppercase",
|
||||
}}
|
||||
>
|
||||
Alpha
|
||||
</Text>
|
||||
</View>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
export function renderCompactBrandTitle() {
|
||||
return <CompactBrandTitle />;
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import { useNavigation } from "@react-navigation/native";
|
||||
import { useMemo, useState } from "react";
|
||||
|
||||
import { NativeHeaderToolbar, NativeStackScreenOptions } from "../../native/StackHeader";
|
||||
import { renderCompactBrandTitle } from "../../components/CompactBrandTitle";
|
||||
import { useProjects, useThreadShells } from "../../state/entities";
|
||||
import { usePendingNewTasks } from "../../state/use-pending-new-tasks";
|
||||
import { useWorkspaceState } from "../../state/workspace";
|
||||
@@ -86,7 +87,9 @@ export function HomeRouteScreen() {
|
||||
>
|
||||
<>
|
||||
{/* Restore the compact title in case the split branch blanked it. */}
|
||||
<NativeStackScreenOptions options={{ title: "Threads", headerTitle: "Threads" }} />
|
||||
<NativeStackScreenOptions
|
||||
options={{ title: "T3 Code", headerTitle: renderCompactBrandTitle }}
|
||||
/>
|
||||
<HomeHeader
|
||||
environments={environments}
|
||||
searchQuery={searchQuery}
|
||||
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
import type { ReactNode } from "react";
|
||||
import { Platform, useColorScheme } from "react-native";
|
||||
|
||||
import { renderCompactBrandTitle } from "../../components/CompactBrandTitle";
|
||||
import { nativeHeaderScrollEdgeEffects } from "../../native/StackHeader";
|
||||
|
||||
const SCROLL_EDGE_EFFECTS = nativeHeaderScrollEdgeEffects(Platform.OS, Platform.Version);
|
||||
@@ -34,10 +35,11 @@ const SIDEBAR_SCREEN_OPTIONS: SidebarScreenOptions = {
|
||||
headerShadowVisible: false,
|
||||
headerShown: true,
|
||||
headerStyle: { backgroundColor: "transparent" },
|
||||
headerTitle: renderCompactBrandTitle,
|
||||
headerTitleStyle: { fontSize: 18, fontWeight: "800" },
|
||||
headerTransparent: true,
|
||||
scrollEdgeEffects: SCROLL_EDGE_EFFECTS,
|
||||
title: "Threads",
|
||||
title: "T3 Code",
|
||||
unstable_navigationItemStyle: "editor",
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
import { describe, expect, it } from "vite-plus/test";
|
||||
import {
|
||||
CommandId,
|
||||
type ClientOrchestrationCommand,
|
||||
MessageId,
|
||||
ProjectId,
|
||||
ProviderInstanceId,
|
||||
ThreadId,
|
||||
} from "@t3tools/contracts";
|
||||
|
||||
import { canonicalizeClientCommandTimestamps } from "./Normalizer.ts";
|
||||
|
||||
const clientCreatedAt = "2031-01-01T00:00:00.000Z";
|
||||
const serverReceivedAt = "2026-07-18T00:00:00.000Z";
|
||||
|
||||
describe("canonicalizeClientCommandTimestamps", () => {
|
||||
it("replaces a client command timestamp with the server receipt timestamp", () => {
|
||||
const command: ClientOrchestrationCommand = {
|
||||
type: "project.create",
|
||||
commandId: CommandId.make("command-1"),
|
||||
projectId: ProjectId.make("project-1"),
|
||||
title: "Clock-safe project",
|
||||
workspaceRoot: "/tmp/clock-safe-project",
|
||||
createdAt: clientCreatedAt,
|
||||
};
|
||||
|
||||
expect(canonicalizeClientCommandTimestamps(command, serverReceivedAt)).toEqual({
|
||||
...command,
|
||||
createdAt: serverReceivedAt,
|
||||
});
|
||||
});
|
||||
|
||||
it("replaces both timestamps when the first turn bootstraps a thread", () => {
|
||||
const command: ClientOrchestrationCommand = {
|
||||
type: "thread.turn.start",
|
||||
commandId: CommandId.make("command-2"),
|
||||
threadId: ThreadId.make("thread-1"),
|
||||
message: {
|
||||
messageId: MessageId.make("message-1"),
|
||||
role: "user",
|
||||
text: "Start a thread",
|
||||
attachments: [],
|
||||
},
|
||||
runtimeMode: "full-access",
|
||||
interactionMode: "default",
|
||||
bootstrap: {
|
||||
createThread: {
|
||||
projectId: ProjectId.make("project-1"),
|
||||
title: "Clock-safe thread",
|
||||
modelSelection: {
|
||||
instanceId: ProviderInstanceId.make("codex"),
|
||||
model: "gpt-5.4",
|
||||
},
|
||||
runtimeMode: "full-access",
|
||||
interactionMode: "default",
|
||||
branch: null,
|
||||
worktreePath: null,
|
||||
createdAt: clientCreatedAt,
|
||||
},
|
||||
},
|
||||
createdAt: clientCreatedAt,
|
||||
};
|
||||
|
||||
const result = canonicalizeClientCommandTimestamps(command, serverReceivedAt);
|
||||
|
||||
expect(result.type).toBe("thread.turn.start");
|
||||
if (result.type !== "thread.turn.start") {
|
||||
throw new Error("Expected a thread.turn.start command");
|
||||
}
|
||||
expect(result.createdAt).toBe(serverReceivedAt);
|
||||
expect(result.bootstrap?.createThread?.createdAt).toBe(serverReceivedAt);
|
||||
});
|
||||
});
|
||||
@@ -1,8 +1,10 @@
|
||||
import * as DateTime from "effect/DateTime";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as FileSystem from "effect/FileSystem";
|
||||
import * as Path from "effect/Path";
|
||||
import {
|
||||
type ClientOrchestrationCommand,
|
||||
type IsoDateTime,
|
||||
type OrchestrationCommand,
|
||||
OrchestrationDispatchCommandError,
|
||||
PROVIDER_SEND_TURN_MAX_IMAGE_BYTES,
|
||||
@@ -13,8 +15,38 @@ import { ServerConfig } from "../config.ts";
|
||||
import { parseBase64DataUrl } from "../imageMime.ts";
|
||||
import * as WorkspacePaths from "../workspace/WorkspacePaths.ts";
|
||||
|
||||
export const canonicalizeClientCommandTimestamps = (
|
||||
command: ClientOrchestrationCommand,
|
||||
receivedAt: IsoDateTime,
|
||||
): ClientOrchestrationCommand => {
|
||||
const canonicalCommand =
|
||||
"createdAt" in command
|
||||
? {
|
||||
...command,
|
||||
createdAt: receivedAt,
|
||||
}
|
||||
: command;
|
||||
|
||||
if (canonicalCommand.type !== "thread.turn.start" || !canonicalCommand.bootstrap?.createThread) {
|
||||
return canonicalCommand;
|
||||
}
|
||||
|
||||
return {
|
||||
...canonicalCommand,
|
||||
bootstrap: {
|
||||
...canonicalCommand.bootstrap,
|
||||
createThread: {
|
||||
...canonicalCommand.bootstrap.createThread,
|
||||
createdAt: receivedAt,
|
||||
},
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
export const normalizeDispatchCommand = (command: ClientOrchestrationCommand) =>
|
||||
Effect.gen(function* () {
|
||||
const receivedAt = DateTime.formatIso(yield* DateTime.now);
|
||||
const canonicalCommand = canonicalizeClientCommandTimestamps(command, receivedAt);
|
||||
const fileSystem = yield* FileSystem.FileSystem;
|
||||
const path = yield* Path.Path;
|
||||
const serverConfig = yield* ServerConfig;
|
||||
@@ -47,30 +79,33 @@ export const normalizeDispatchCommand = (command: ClientOrchestrationCommand) =>
|
||||
),
|
||||
);
|
||||
|
||||
if (command.type === "project.create") {
|
||||
if (canonicalCommand.type === "project.create") {
|
||||
return {
|
||||
...command,
|
||||
...canonicalCommand,
|
||||
workspaceRoot: yield* normalizeProjectWorkspaceRootForCreate(
|
||||
command.workspaceRoot,
|
||||
command.createWorkspaceRootIfMissing,
|
||||
canonicalCommand.workspaceRoot,
|
||||
canonicalCommand.createWorkspaceRootIfMissing,
|
||||
),
|
||||
createWorkspaceRootIfMissing: command.createWorkspaceRootIfMissing === true,
|
||||
createWorkspaceRootIfMissing: canonicalCommand.createWorkspaceRootIfMissing === true,
|
||||
} satisfies OrchestrationCommand;
|
||||
}
|
||||
|
||||
if (command.type === "project.meta.update" && command.workspaceRoot !== undefined) {
|
||||
if (
|
||||
canonicalCommand.type === "project.meta.update" &&
|
||||
canonicalCommand.workspaceRoot !== undefined
|
||||
) {
|
||||
return {
|
||||
...command,
|
||||
workspaceRoot: yield* normalizeProjectWorkspaceRoot(command.workspaceRoot),
|
||||
...canonicalCommand,
|
||||
workspaceRoot: yield* normalizeProjectWorkspaceRoot(canonicalCommand.workspaceRoot),
|
||||
} satisfies OrchestrationCommand;
|
||||
}
|
||||
|
||||
if (command.type !== "thread.turn.start") {
|
||||
return command as OrchestrationCommand;
|
||||
if (canonicalCommand.type !== "thread.turn.start") {
|
||||
return canonicalCommand as OrchestrationCommand;
|
||||
}
|
||||
|
||||
const normalizedAttachments = yield* Effect.forEach(
|
||||
command.message.attachments,
|
||||
canonicalCommand.message.attachments,
|
||||
(attachment) =>
|
||||
Effect.gen(function* () {
|
||||
const parsed = parseBase64DataUrl(attachment.dataUrl);
|
||||
@@ -87,7 +122,7 @@ export const normalizeDispatchCommand = (command: ClientOrchestrationCommand) =>
|
||||
});
|
||||
}
|
||||
|
||||
const attachmentId = createAttachmentId(command.threadId);
|
||||
const attachmentId = createAttachmentId(canonicalCommand.threadId);
|
||||
if (!attachmentId) {
|
||||
return yield* new OrchestrationDispatchCommandError({
|
||||
message: "Failed to create a safe attachment id.",
|
||||
@@ -135,9 +170,9 @@ export const normalizeDispatchCommand = (command: ClientOrchestrationCommand) =>
|
||||
);
|
||||
|
||||
return {
|
||||
...command,
|
||||
...canonicalCommand,
|
||||
message: {
|
||||
...command.message,
|
||||
...canonicalCommand.message,
|
||||
attachments: normalizedAttachments,
|
||||
},
|
||||
} satisfies OrchestrationCommand;
|
||||
|
||||
@@ -248,6 +248,38 @@ it.layer(OpenCodeAdapterTestLayer)("OpenCodeAdapterLive", (it) => {
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("fails sendTurn for missing sessions through the typed error channel", () =>
|
||||
Effect.gen(function* () {
|
||||
const adapter = yield* OpenCodeAdapter;
|
||||
const result = yield* adapter
|
||||
.sendTurn({
|
||||
threadId: asThreadId("thread-opencode-missing-send"),
|
||||
input: "hello",
|
||||
attachments: [],
|
||||
})
|
||||
.pipe(Effect.result);
|
||||
|
||||
NodeAssert.equal(result._tag, "Failure");
|
||||
NodeAssert.equal(result.failure._tag, "ProviderAdapterSessionNotFoundError");
|
||||
NodeAssert.equal(result.failure.provider, "opencode");
|
||||
NodeAssert.equal(result.failure.threadId, "thread-opencode-missing-send");
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("fails stopSession for missing sessions through the typed error channel", () =>
|
||||
Effect.gen(function* () {
|
||||
const adapter = yield* OpenCodeAdapter;
|
||||
const result = yield* adapter
|
||||
.stopSession(asThreadId("thread-opencode-missing-stop"))
|
||||
.pipe(Effect.result);
|
||||
|
||||
NodeAssert.equal(result._tag, "Failure");
|
||||
NodeAssert.equal(result.failure._tag, "ProviderAdapterSessionNotFoundError");
|
||||
NodeAssert.equal(result.failure.provider, "opencode");
|
||||
NodeAssert.equal(result.failure.threadId, "thread-opencode-missing-stop");
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("stops a configured-server session without trying to own server lifecycle", () =>
|
||||
Effect.gen(function* () {
|
||||
const adapter = yield* OpenCodeAdapter;
|
||||
|
||||
@@ -228,28 +228,25 @@ function appendTurnItem(
|
||||
resolveTurnSnapshot(context, turnId).items.push(item);
|
||||
}
|
||||
|
||||
function ensureSessionContext(
|
||||
const ensureSessionContext = Effect.fn("ensureSessionContext")(function* (
|
||||
sessions: ReadonlyMap<ThreadId, OpenCodeSessionContext>,
|
||||
threadId: ThreadId,
|
||||
): OpenCodeSessionContext {
|
||||
) {
|
||||
const session = sessions.get(threadId);
|
||||
if (!session) {
|
||||
throw new ProviderAdapterSessionNotFoundError({
|
||||
return yield* new ProviderAdapterSessionNotFoundError({
|
||||
provider: PROVIDER,
|
||||
threadId,
|
||||
});
|
||||
}
|
||||
// `ensureSessionContext` is a sync gate used from both sync helpers and
|
||||
// Effect bodies. `Ref.getUnsafe` is an atomic read of the backing cell —
|
||||
// no fiber suspension required, which keeps this callable everywhere.
|
||||
if (Ref.getUnsafe(session.stopped)) {
|
||||
throw new ProviderAdapterSessionClosedError({
|
||||
if (yield* Ref.get(session.stopped)) {
|
||||
return yield* new ProviderAdapterSessionClosedError({
|
||||
provider: PROVIDER,
|
||||
threadId,
|
||||
});
|
||||
}
|
||||
return session;
|
||||
}
|
||||
});
|
||||
|
||||
function normalizeQuestionRequest(request: QuestionRequest): ReadonlyArray<UserInputQuestion> {
|
||||
return request.questions.map((question, index) => ({
|
||||
@@ -1167,7 +1164,7 @@ export function makeOpenCodeAdapter(
|
||||
);
|
||||
|
||||
const sendTurn: OpenCodeAdapterShape["sendTurn"] = Effect.fn("sendTurn")(function* (input) {
|
||||
const context = ensureSessionContext(sessions, input.threadId);
|
||||
const context = yield* ensureSessionContext(sessions, input.threadId);
|
||||
// A sendTurn while a turn is active is a steer: OpenCode queues the
|
||||
// prompt into the busy session and the work continues as one turn, so
|
||||
// the active turn id is reused instead of opening a new turn.
|
||||
@@ -1291,7 +1288,7 @@ export function makeOpenCodeAdapter(
|
||||
|
||||
const interruptTurn: OpenCodeAdapterShape["interruptTurn"] = Effect.fn("interruptTurn")(
|
||||
function* (threadId, turnId) {
|
||||
const context = ensureSessionContext(sessions, threadId);
|
||||
const context = yield* ensureSessionContext(sessions, threadId);
|
||||
yield* runOpenCodeSdk("session.abort", () =>
|
||||
context.client.session.abort({ sessionID: context.openCodeSessionId }),
|
||||
).pipe(Effect.mapError(toRequestError));
|
||||
@@ -1313,7 +1310,7 @@ export function makeOpenCodeAdapter(
|
||||
const respondToRequest: OpenCodeAdapterShape["respondToRequest"] = Effect.fn(
|
||||
"respondToRequest",
|
||||
)(function* (threadId, requestId, decision) {
|
||||
const context = ensureSessionContext(sessions, threadId);
|
||||
const context = yield* ensureSessionContext(sessions, threadId);
|
||||
if (!context.pendingPermissions.has(requestId)) {
|
||||
return yield* new ProviderAdapterRequestError({
|
||||
provider: PROVIDER,
|
||||
@@ -1333,7 +1330,7 @@ export function makeOpenCodeAdapter(
|
||||
const respondToUserInput: OpenCodeAdapterShape["respondToUserInput"] = Effect.fn(
|
||||
"respondToUserInput",
|
||||
)(function* (threadId, requestId, answers) {
|
||||
const context = ensureSessionContext(sessions, threadId);
|
||||
const context = yield* ensureSessionContext(sessions, threadId);
|
||||
const request = context.pendingQuestions.get(requestId);
|
||||
if (!request) {
|
||||
return yield* new ProviderAdapterRequestError({
|
||||
@@ -1355,7 +1352,7 @@ export function makeOpenCodeAdapter(
|
||||
function* (threadId) {
|
||||
const context = sessions.get(threadId);
|
||||
if (!context) {
|
||||
throw new ProviderAdapterSessionNotFoundError({
|
||||
return yield* new ProviderAdapterSessionNotFoundError({
|
||||
provider: PROVIDER,
|
||||
threadId,
|
||||
});
|
||||
@@ -1385,7 +1382,7 @@ export function makeOpenCodeAdapter(
|
||||
|
||||
const readThread: OpenCodeAdapterShape["readThread"] = Effect.fn("readThread")(
|
||||
function* (threadId) {
|
||||
const context = ensureSessionContext(sessions, threadId);
|
||||
const context = yield* ensureSessionContext(sessions, threadId);
|
||||
const messages = yield* runOpenCodeSdk("session.messages", () =>
|
||||
context.client.session.messages({
|
||||
sessionID: context.openCodeSessionId,
|
||||
@@ -1411,7 +1408,7 @@ export function makeOpenCodeAdapter(
|
||||
|
||||
const rollbackThread: OpenCodeAdapterShape["rollbackThread"] = Effect.fn("rollbackThread")(
|
||||
function* (threadId, numTurns) {
|
||||
const context = ensureSessionContext(sessions, threadId);
|
||||
const context = yield* ensureSessionContext(sessions, threadId);
|
||||
const messages = yield* runOpenCodeSdk("session.messages", () =>
|
||||
context.client.session.messages({
|
||||
sessionID: context.openCodeSessionId,
|
||||
|
||||
|
Before Width: | Height: | Size: 74 KiB After Width: | Height: | Size: 111 KiB |
|
Before Width: | Height: | Size: 1003 B After Width: | Height: | Size: 2.1 KiB |
|
Before Width: | Height: | Size: 3.0 KiB After Width: | Height: | Size: 5.5 KiB |
|
Before Width: | Height: | Size: 204 KiB After Width: | Height: | Size: 277 KiB |
@@ -1,4 +1,11 @@
|
||||
import { EnvironmentId, ProjectId, ProviderInstanceId, ThreadId, TurnId } from "@t3tools/contracts";
|
||||
import {
|
||||
EnvironmentId,
|
||||
MessageId,
|
||||
ProjectId,
|
||||
ProviderInstanceId,
|
||||
ThreadId,
|
||||
TurnId,
|
||||
} from "@t3tools/contracts";
|
||||
import { describe, expect, it } from "vite-plus/test";
|
||||
|
||||
import type { Thread } from "../types";
|
||||
@@ -359,6 +366,7 @@ describe("hasServerAcknowledgedLocalDispatch", () => {
|
||||
localDispatch,
|
||||
phase: "ready",
|
||||
latestTurn: completedTurn,
|
||||
latestUserMessageId: localDispatch.latestUserMessageId,
|
||||
session: readySession,
|
||||
hasPendingApproval: false,
|
||||
hasPendingUserInput: false,
|
||||
@@ -384,6 +392,7 @@ describe("hasServerAcknowledgedLocalDispatch", () => {
|
||||
localDispatch,
|
||||
phase: "ready",
|
||||
latestTurn: newerTurn,
|
||||
latestUserMessageId: localDispatch.latestUserMessageId,
|
||||
session: { ...readySession, updatedAt: newerTurn.completedAt },
|
||||
hasPendingApproval: false,
|
||||
hasPendingUserInput: false,
|
||||
@@ -410,6 +419,7 @@ describe("hasServerAcknowledgedLocalDispatch", () => {
|
||||
localDispatch,
|
||||
phase: "running",
|
||||
latestTurn: runningTurn,
|
||||
latestUserMessageId: localDispatch.latestUserMessageId,
|
||||
session: {
|
||||
...readySession,
|
||||
status: "running",
|
||||
@@ -425,6 +435,7 @@ describe("hasServerAcknowledgedLocalDispatch", () => {
|
||||
localDispatch,
|
||||
phase: "running",
|
||||
latestTurn: runningTurn,
|
||||
latestUserMessageId: localDispatch.latestUserMessageId,
|
||||
session: {
|
||||
...readySession,
|
||||
status: "running",
|
||||
@@ -437,12 +448,56 @@ describe("hasServerAcknowledgedLocalDispatch", () => {
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it("acknowledges a steering message projected onto the current running turn", () => {
|
||||
const runningTurn = {
|
||||
...completedTurn,
|
||||
state: "running" as const,
|
||||
completedAt: null,
|
||||
};
|
||||
const runningSession = {
|
||||
...readySession,
|
||||
status: "running" as const,
|
||||
activeTurnId: runningTurn.turnId,
|
||||
};
|
||||
const localDispatch = createLocalDispatchSnapshot(
|
||||
makeThread({
|
||||
latestTurn: runningTurn,
|
||||
session: runningSession,
|
||||
messages: [
|
||||
{
|
||||
id: MessageId.make("message-before-steer"),
|
||||
role: "user",
|
||||
text: "Initial prompt",
|
||||
turnId: runningTurn.turnId,
|
||||
createdAt: runningTurn.requestedAt,
|
||||
updatedAt: runningTurn.requestedAt,
|
||||
streaming: false,
|
||||
},
|
||||
],
|
||||
}),
|
||||
);
|
||||
|
||||
expect(
|
||||
hasServerAcknowledgedLocalDispatch({
|
||||
localDispatch,
|
||||
phase: "running",
|
||||
latestTurn: runningTurn,
|
||||
latestUserMessageId: MessageId.make("message-steer"),
|
||||
session: runningSession,
|
||||
hasPendingApproval: false,
|
||||
hasPendingUserInput: false,
|
||||
threadError: null,
|
||||
}),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it("acknowledges pending user interaction and errors immediately", () => {
|
||||
const localDispatch = createLocalDispatchSnapshot(makeThread());
|
||||
const common = {
|
||||
localDispatch,
|
||||
phase: "ready" as const,
|
||||
latestTurn: null,
|
||||
latestUserMessageId: localDispatch.latestUserMessageId,
|
||||
session: null,
|
||||
hasPendingApproval: false,
|
||||
hasPendingUserInput: false,
|
||||
|
||||
@@ -387,6 +387,7 @@ export async function waitForStartedServerThread(
|
||||
export interface LocalDispatchSnapshot {
|
||||
startedAt: string;
|
||||
preparingWorktree: boolean;
|
||||
latestUserMessageId: ChatMessage["id"] | null;
|
||||
latestTurnTurnId: TurnId | null;
|
||||
latestTurnRequestedAt: string | null;
|
||||
latestTurnStartedAt: string | null;
|
||||
@@ -401,9 +402,11 @@ export function createLocalDispatchSnapshot(
|
||||
): LocalDispatchSnapshot {
|
||||
const latestTurn = activeThread?.latestTurn ?? null;
|
||||
const session = activeThread?.session ?? null;
|
||||
const latestUserMessage = activeThread?.messages.findLast((message) => message.role === "user");
|
||||
return {
|
||||
startedAt: new Date().toISOString(),
|
||||
preparingWorktree: Boolean(options?.preparingWorktree),
|
||||
latestUserMessageId: latestUserMessage?.id ?? null,
|
||||
latestTurnTurnId: latestTurn?.turnId ?? null,
|
||||
latestTurnRequestedAt: latestTurn?.requestedAt ?? null,
|
||||
latestTurnStartedAt: latestTurn?.startedAt ?? null,
|
||||
@@ -417,6 +420,7 @@ export function hasServerAcknowledgedLocalDispatch(input: {
|
||||
localDispatch: LocalDispatchSnapshot | null;
|
||||
phase: SessionPhase;
|
||||
latestTurn: Thread["latestTurn"] | null;
|
||||
latestUserMessageId: ChatMessage["id"] | null;
|
||||
session: Thread["session"] | null;
|
||||
hasPendingApproval: boolean;
|
||||
hasPendingUserInput: boolean;
|
||||
@@ -431,6 +435,8 @@ export function hasServerAcknowledgedLocalDispatch(input: {
|
||||
|
||||
const latestTurn = input.latestTurn ?? null;
|
||||
const session = input.session ?? null;
|
||||
const latestUserMessageChanged =
|
||||
input.localDispatch.latestUserMessageId !== input.latestUserMessageId;
|
||||
const latestTurnChanged =
|
||||
input.localDispatch.latestTurnTurnId !== (latestTurn?.turnId ?? null) ||
|
||||
input.localDispatch.latestTurnRequestedAt !== (latestTurn?.requestedAt ?? null) ||
|
||||
@@ -438,6 +444,13 @@ export function hasServerAcknowledgedLocalDispatch(input: {
|
||||
input.localDispatch.latestTurnCompletedAt !== (latestTurn?.completedAt ?? null);
|
||||
|
||||
if (input.phase === "running") {
|
||||
// Steering adds a user message to the current running turn without
|
||||
// necessarily changing any of the turn timestamps. Treat that projected
|
||||
// message as the server acknowledgment so the composer does not remain
|
||||
// stuck in its local "Sending" state until the turn settles.
|
||||
if (latestUserMessageChanged) {
|
||||
return true;
|
||||
}
|
||||
if (!latestTurnChanged) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -452,6 +452,8 @@ function useLocalDispatchState(input: {
|
||||
threadError: string | null | undefined;
|
||||
}) {
|
||||
const [localDispatch, setLocalDispatch] = useState<LocalDispatchSnapshot | null>(null);
|
||||
const latestUserMessageId =
|
||||
input.activeThread?.messages.findLast((message) => message.role === "user")?.id ?? null;
|
||||
|
||||
const resetLocalDispatch = useCallback(() => {
|
||||
setLocalDispatch(null);
|
||||
@@ -463,6 +465,7 @@ function useLocalDispatchState(input: {
|
||||
localDispatch,
|
||||
phase: input.phase,
|
||||
latestTurn: input.activeLatestTurn,
|
||||
latestUserMessageId,
|
||||
session: input.activeThread?.session ?? null,
|
||||
hasPendingApproval: input.activePendingApproval !== null,
|
||||
hasPendingUserInput: input.activePendingUserInput !== null,
|
||||
@@ -475,6 +478,7 @@ function useLocalDispatchState(input: {
|
||||
input.activeThread?.session,
|
||||
input.phase,
|
||||
input.threadError,
|
||||
latestUserMessageId,
|
||||
localDispatch,
|
||||
],
|
||||
);
|
||||
@@ -1063,6 +1067,14 @@ const PersistentThreadTerminalPanel = memo(function PersistentThreadTerminalPane
|
||||
);
|
||||
});
|
||||
|
||||
// Errors surface through two maps (draft-keyed and thread-keyed) whose entries
|
||||
// can race around promotion, so each write carries its time to let the latest
|
||||
// one win when they collide.
|
||||
type LocalThreadErrorEntry = {
|
||||
readonly message: string | null;
|
||||
readonly at: number;
|
||||
};
|
||||
|
||||
function ChatViewContent(props: ChatViewProps) {
|
||||
const {
|
||||
environmentId,
|
||||
@@ -1120,10 +1132,10 @@ function ChatViewContent(props: ChatViewProps) {
|
||||
);
|
||||
const composerDraftTarget: ScopedThreadRef | DraftId =
|
||||
routeKind === "server" ? routeThreadRef : props.draftId;
|
||||
const serverThread = useThread(routeKind === "server" ? routeThreadRef : null);
|
||||
const serverThread = useThread(routeThreadRef);
|
||||
const markThreadVisited = useUiStateStore((store) => store.markThreadVisited);
|
||||
const activeThreadLastVisitedAt = useUiStateStore((store) =>
|
||||
routeKind === "server" ? store.threadLastVisitedAtById[routeThreadKey] : undefined,
|
||||
const activeThreadLastVisitedAt = useUiStateStore(
|
||||
(store) => store.threadLastVisitedAtById[routeThreadKey],
|
||||
);
|
||||
const settings = useEnvironmentSettings(environmentId);
|
||||
const setStickyComposerModelSelection = useComposerDraftStore(
|
||||
@@ -1188,10 +1200,10 @@ function ChatViewContent(props: ChatViewProps) {
|
||||
const optimisticUserMessagesRef = useRef(optimisticUserMessages);
|
||||
optimisticUserMessagesRef.current = optimisticUserMessages;
|
||||
const [localDraftErrorsByDraftId, setLocalDraftErrorsByDraftId] = useState<
|
||||
Record<string, string | null>
|
||||
Record<string, LocalThreadErrorEntry>
|
||||
>({});
|
||||
const [localServerErrorsByThreadKey, setLocalServerErrorsByThreadKey] = useState<
|
||||
Record<string, string | null>
|
||||
Record<string, LocalThreadErrorEntry>
|
||||
>({});
|
||||
const [isConnecting, _setIsConnecting] = useState(false);
|
||||
const [isRevertingCheckpoint, setIsRevertingCheckpoint] = useState(false);
|
||||
@@ -1303,11 +1315,45 @@ function ChatViewContent(props: ChatViewProps) {
|
||||
? scopeProjectRef(draftThread.environmentId, draftThread.projectId)
|
||||
: null;
|
||||
const fallbackDraftProject = useProject(fallbackDraftProjectRef);
|
||||
const localDraftError =
|
||||
routeKind === "server" && serverThread
|
||||
? null
|
||||
: ((draftId ? localDraftErrorsByDraftId[draftId] : null) ?? null);
|
||||
const localServerError = localServerErrorsByThreadKey[routeThreadKey] ?? null;
|
||||
const localDraftError = serverThread
|
||||
? null
|
||||
: ((draftId ? localDraftErrorsByDraftId[draftId]?.message : null) ?? null);
|
||||
const localServerError = localServerErrorsByThreadKey[routeThreadKey]?.message ?? null;
|
||||
// Draft errors are keyed by draftId while server errors are keyed by thread
|
||||
// key, so a pending draft entry must migrate when the server thread loads or
|
||||
// a failed send would silently disappear on promotion. When both keys hold
|
||||
// an entry, the most recent write wins.
|
||||
useEffect(() => {
|
||||
if (!serverThread || !draftId) {
|
||||
return;
|
||||
}
|
||||
const pendingDraftEntry = localDraftErrorsByDraftId[draftId];
|
||||
if (pendingDraftEntry === undefined) {
|
||||
return;
|
||||
}
|
||||
setLocalDraftErrorsByDraftId((existing) => {
|
||||
if (existing[draftId] === undefined) {
|
||||
return existing;
|
||||
}
|
||||
const next = { ...existing };
|
||||
delete next[draftId];
|
||||
return next;
|
||||
});
|
||||
setLocalServerErrorsByThreadKey((existing) => {
|
||||
const currentEntry = existing[routeThreadKey];
|
||||
if (
|
||||
currentEntry !== undefined &&
|
||||
(currentEntry.at > pendingDraftEntry.at ||
|
||||
currentEntry.message === pendingDraftEntry.message)
|
||||
) {
|
||||
return existing;
|
||||
}
|
||||
return {
|
||||
...existing,
|
||||
[routeThreadKey]: pendingDraftEntry,
|
||||
};
|
||||
});
|
||||
}, [draftId, localDraftErrorsByDraftId, routeThreadKey, serverThread]);
|
||||
const localDraftThread = useMemo(
|
||||
() =>
|
||||
draftThread
|
||||
@@ -1322,7 +1368,10 @@ function ChatViewContent(props: ChatViewProps) {
|
||||
: undefined,
|
||||
[draftThread, fallbackDraftProject?.defaultModelSelection, threadId],
|
||||
);
|
||||
const isServerThread = routeKind === "server" && serverThread !== null;
|
||||
// Promotion is data-driven: the draft route keeps rendering while the
|
||||
// server thread (same pre-allocated ref) starts, so live state must not
|
||||
// depend on which route is mounted.
|
||||
const isServerThread = serverThread !== null;
|
||||
const activeThread = isServerThread ? serverThread : localDraftThread;
|
||||
const threadError = isServerThread
|
||||
? (localServerError ?? serverThread?.session?.lastError ?? null)
|
||||
@@ -2207,12 +2256,13 @@ function ChatViewContent(props: ChatViewProps) {
|
||||
worktreePath: activeThread?.worktreePath ?? null,
|
||||
})
|
||||
: null;
|
||||
const gitStatusCwd = activeThread?.worktreePath ?? gitCwd;
|
||||
const gitStatusQuery = useEnvironmentQuery(
|
||||
gitCwd === null
|
||||
gitStatusCwd === null
|
||||
? null
|
||||
: vcsEnvironment.status({
|
||||
environmentId,
|
||||
input: { cwd: gitCwd },
|
||||
input: { cwd: gitStatusCwd },
|
||||
}),
|
||||
);
|
||||
const keybindings = useAtomValue(primaryServerKeybindingsAtom);
|
||||
@@ -2246,6 +2296,9 @@ function ChatViewContent(props: ChatViewProps) {
|
||||
terminalUiLaunchContext?.threadId === activeThreadId ? terminalUiLaunchContext : null;
|
||||
// Default true while loading to avoid toolbar flicker.
|
||||
const isGitRepo = gitStatusQuery.data?.isRepo ?? true;
|
||||
const initialDiffPanelGitScope =
|
||||
gitStatusQuery.data?.hasWorkingTreeChanges === true ? "unstaged" : "branch";
|
||||
const diffPanelGitStatusResolutionKey = gitStatusQuery.data ? "resolved" : "pending";
|
||||
const terminalShortcutLabelOptions = useMemo(
|
||||
() => ({
|
||||
context: {
|
||||
@@ -2321,6 +2374,7 @@ function ChatViewContent(props: ChatViewProps) {
|
||||
(targetThreadId: ThreadId | null, error: string | null) => {
|
||||
if (!targetThreadId) return;
|
||||
const nextError = sanitizeThreadErrorMessage(error);
|
||||
const nextEntry: LocalThreadErrorEntry = { message: nextError, at: Date.now() };
|
||||
if (
|
||||
serverThread &&
|
||||
targetThreadId === routeThreadRef.threadId &&
|
||||
@@ -2328,24 +2382,24 @@ function ChatViewContent(props: ChatViewProps) {
|
||||
serverThread.id === targetThreadId
|
||||
) {
|
||||
setLocalServerErrorsByThreadKey((existing) => {
|
||||
if ((existing[routeThreadKey] ?? null) === nextError) {
|
||||
if ((existing[routeThreadKey]?.message ?? null) === nextError) {
|
||||
return existing;
|
||||
}
|
||||
return {
|
||||
...existing,
|
||||
[routeThreadKey]: nextError,
|
||||
[routeThreadKey]: nextEntry,
|
||||
};
|
||||
});
|
||||
return;
|
||||
}
|
||||
const localDraftErrorKey = draftId ?? targetThreadId;
|
||||
setLocalDraftErrorsByDraftId((existing) => {
|
||||
if ((existing[localDraftErrorKey] ?? null) === nextError) {
|
||||
if ((existing[localDraftErrorKey]?.message ?? null) === nextError) {
|
||||
return existing;
|
||||
}
|
||||
return {
|
||||
...existing,
|
||||
[localDraftErrorKey]: nextError,
|
||||
[localDraftErrorKey]: nextEntry,
|
||||
};
|
||||
});
|
||||
},
|
||||
@@ -2866,9 +2920,19 @@ function ChatViewContent(props: ChatViewProps) {
|
||||
}, [activeThreadRef, openPreview]);
|
||||
const addDiffSurface = useCallback(() => {
|
||||
if (!activeThreadRef || !isServerThread || !isGitRepo) return;
|
||||
if (planSidebarOpen) {
|
||||
dismissPlanSidebarForCurrentTurn();
|
||||
}
|
||||
useRightPanelStore.getState().open(activeThreadRef, "diff");
|
||||
onDiffPanelOpen?.();
|
||||
}, [activeThreadRef, isGitRepo, isServerThread, onDiffPanelOpen]);
|
||||
}, [
|
||||
activeThreadRef,
|
||||
dismissPlanSidebarForCurrentTurn,
|
||||
isGitRepo,
|
||||
isServerThread,
|
||||
onDiffPanelOpen,
|
||||
planSidebarOpen,
|
||||
]);
|
||||
const addFilesSurface = useCallback(() => {
|
||||
if (!activeThreadRef || !activeProject) return;
|
||||
useRightPanelStore.getState().open(activeThreadRef, "files");
|
||||
@@ -5090,7 +5154,12 @@ function ChatViewContent(props: ChatViewProps) {
|
||||
/>
|
||||
) : activeRightPanelSurface?.kind === "diff" ? (
|
||||
<Suspense fallback={null}>
|
||||
<DiffPanel mode="embedded" composerDraftTarget={composerDraftTarget} />
|
||||
<DiffPanel
|
||||
key={`${activeThreadKey}:${diffPanelGitStatusResolutionKey}`}
|
||||
mode="embedded"
|
||||
composerDraftTarget={composerDraftTarget}
|
||||
initialGitScope={initialDiffPanelGitScope}
|
||||
/>
|
||||
</Suspense>
|
||||
) : activeRightPanelSurface?.kind === "plan" ? (
|
||||
<PlanSidebar
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
import { afterEach, describe, expect, it, vi } from "vite-plus/test";
|
||||
import {
|
||||
$createParagraphNode,
|
||||
$createTextNode,
|
||||
$getRoot,
|
||||
$getSelection,
|
||||
$isRangeSelection,
|
||||
COMMAND_PRIORITY_EDITOR,
|
||||
createEditor,
|
||||
PASTE_COMMAND,
|
||||
} from "lexical";
|
||||
|
||||
import { registerComposerInlineTokenPaste } from "./composerInlineTokenPaste";
|
||||
|
||||
class TestClipboardEvent extends Event {
|
||||
readonly clipboardData: DataTransfer;
|
||||
|
||||
constructor(text: string) {
|
||||
super("paste", { cancelable: true });
|
||||
this.clipboardData = {
|
||||
files: [],
|
||||
getData: (type: string) => (type === "text/plain" ? text : ""),
|
||||
} as unknown as DataTransfer;
|
||||
}
|
||||
}
|
||||
|
||||
describe("registerComposerInlineTokenPaste", () => {
|
||||
afterEach(() => {
|
||||
vi.unstubAllGlobals();
|
||||
});
|
||||
|
||||
it("handles a copied mention without also running the plain-text paste fallback", () => {
|
||||
vi.stubGlobal("ClipboardEvent", TestClipboardEvent);
|
||||
const editor = createEditor();
|
||||
const mention = "[improve-deploy-error-logging.md](.changeset/improve-deploy-error-logging.md)";
|
||||
const plainTextFallback = vi.fn(() => {
|
||||
const selection = $getSelection();
|
||||
if (!$isRangeSelection(selection)) return false;
|
||||
selection.insertText(mention);
|
||||
return true;
|
||||
});
|
||||
|
||||
editor.update(
|
||||
() => {
|
||||
const paragraph = $createParagraphNode();
|
||||
$getRoot().append(paragraph);
|
||||
paragraph.selectEnd();
|
||||
},
|
||||
{ discrete: true },
|
||||
);
|
||||
registerComposerInlineTokenPaste(editor, {
|
||||
createMentionNode: (path) => $createTextNode(`<mention:${path}>`),
|
||||
getExpandedAbsoluteOffsetForPoint: () => 0,
|
||||
});
|
||||
editor.registerCommand(PASTE_COMMAND, plainTextFallback, COMMAND_PRIORITY_EDITOR);
|
||||
|
||||
const event = new TestClipboardEvent(mention);
|
||||
let handled = false;
|
||||
editor.update(
|
||||
() => {
|
||||
handled = editor.dispatchCommand(PASTE_COMMAND, event as ClipboardEvent);
|
||||
},
|
||||
{ discrete: true },
|
||||
);
|
||||
|
||||
expect(handled).toBe(true);
|
||||
expect(plainTextFallback).not.toHaveBeenCalled();
|
||||
expect(event.defaultPrevented).toBe(true);
|
||||
expect(editor.getEditorState().read(() => $getRoot().getTextContent())).toBe(
|
||||
"<mention:.changeset/improve-deploy-error-logging.md> ",
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -9,6 +9,7 @@ import { type ServerProviderSkill } from "@t3tools/contracts";
|
||||
import { serializeComposerFileLink } from "@t3tools/shared/composerTrigger";
|
||||
import {
|
||||
$applyNodeReplacement,
|
||||
$createRangeSelectionFromDom,
|
||||
$createRangeSelection,
|
||||
$getSelection,
|
||||
$setSelection,
|
||||
@@ -23,6 +24,7 @@ import {
|
||||
KEY_ARROW_LEFT_COMMAND,
|
||||
KEY_ARROW_RIGHT_COMMAND,
|
||||
KEY_ARROW_UP_COMMAND,
|
||||
KEY_DOWN_COMMAND,
|
||||
KEY_ENTER_COMMAND,
|
||||
KEY_TAB_COMMAND,
|
||||
COMMAND_PRIORITY_HIGH,
|
||||
@@ -63,7 +65,7 @@ import {
|
||||
INLINE_TERMINAL_CONTEXT_PLACEHOLDER,
|
||||
type TerminalContextDraft,
|
||||
} from "~/lib/terminalContext";
|
||||
import { cn } from "~/lib/utils";
|
||||
import { cn, isMacPlatform } from "~/lib/utils";
|
||||
import { basenameOfPath } from "~/pierre-icons";
|
||||
import {
|
||||
COMPOSER_INLINE_CHIP_ICON_CLASS_NAME,
|
||||
@@ -75,6 +77,7 @@ import { FILE_TAG_CHIP_CLASS_NAME, FileTagChipContent } from "./chat/FileTagChip
|
||||
import { ComposerPendingTerminalContextChip } from "./chat/ComposerPendingTerminalContexts";
|
||||
import { formatProviderSkillDisplayName } from "~/providerSkillPresentation";
|
||||
import { Tooltip, TooltipPopup, TooltipTrigger } from "./ui/tooltip";
|
||||
import { registerComposerInlineTokenPaste } from "./composerInlineTokenPaste";
|
||||
|
||||
const COMPOSER_EDITOR_HMR_KEY = `composer-editor-${Math.random().toString(36).slice(2)}`;
|
||||
const SURROUND_SYMBOLS: [string, string][] = [
|
||||
@@ -1022,6 +1025,53 @@ function ComposerInlineTokenArrowPlugin() {
|
||||
return null;
|
||||
}
|
||||
|
||||
function ComposerHomeEndKeyPlugin() {
|
||||
const [editor] = useLexicalComposerContext();
|
||||
|
||||
useEffect(() => {
|
||||
return editor.registerCommand(
|
||||
KEY_DOWN_COMMAND,
|
||||
(event) => {
|
||||
if (!isMacPlatform(navigator.platform)) {
|
||||
return false;
|
||||
}
|
||||
if (event.key !== "Home" && event.key !== "End") {
|
||||
return false;
|
||||
}
|
||||
if (event.altKey || event.metaKey || event.ctrlKey || event.isComposing) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const rootElement = editor.getRootElement();
|
||||
const selection = window.getSelection();
|
||||
const anchorNode = selection?.anchorNode;
|
||||
if (!rootElement || !selection || !anchorNode || !rootElement.contains(anchorNode)) {
|
||||
return false;
|
||||
}
|
||||
if (selection.rangeCount === 0 || typeof selection.modify !== "function") {
|
||||
return false;
|
||||
}
|
||||
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
|
||||
selection.modify(
|
||||
event.shiftKey ? "extend" : "move",
|
||||
event.key === "Home" ? "backward" : "forward",
|
||||
"lineboundary",
|
||||
);
|
||||
editor.update(() => {
|
||||
$setSelection($createRangeSelectionFromDom(selection, editor));
|
||||
});
|
||||
return true;
|
||||
},
|
||||
COMMAND_PRIORITY_HIGH,
|
||||
);
|
||||
}, [editor]);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
function ComposerInlineTokenSelectionNormalizePlugin() {
|
||||
const [editor] = useLexicalComposerContext();
|
||||
|
||||
@@ -1117,6 +1167,21 @@ function ComposerInlineTokenBackspacePlugin() {
|
||||
return null;
|
||||
}
|
||||
|
||||
function ComposerInlineTokenPastePlugin() {
|
||||
const [editor] = useLexicalComposerContext();
|
||||
|
||||
useEffect(
|
||||
() =>
|
||||
registerComposerInlineTokenPaste(editor, {
|
||||
createMentionNode: $createComposerMentionNode,
|
||||
getExpandedAbsoluteOffsetForPoint,
|
||||
}),
|
||||
[editor],
|
||||
);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
function ComposerSurroundSelectionPlugin(props: {
|
||||
terminalContexts: ReadonlyArray<TerminalContextDraft>;
|
||||
skills: ReadonlyArray<ServerProviderSkill>;
|
||||
@@ -1631,9 +1696,11 @@ function ComposerPromptEditorInner({
|
||||
<OnChangePlugin onChange={handleEditorChange} />
|
||||
<ComposerCommandKeyPlugin {...(onCommandKeyDown ? { onCommandKeyDown } : {})} />
|
||||
<ComposerSurroundSelectionPlugin terminalContexts={terminalContexts} skills={skills} />
|
||||
<ComposerHomeEndKeyPlugin />
|
||||
<ComposerInlineTokenArrowPlugin />
|
||||
<ComposerInlineTokenSelectionNormalizePlugin />
|
||||
<ComposerInlineTokenBackspacePlugin />
|
||||
<ComposerInlineTokenPastePlugin />
|
||||
<HistoryPlugin />
|
||||
</div>
|
||||
</ComposerTerminalContextActionsContext>
|
||||
|
||||
@@ -178,13 +178,19 @@ const DIFF_PANEL_UNSAFE_CSS = `
|
||||
interface DiffPanelProps {
|
||||
mode?: DiffPanelMode;
|
||||
composerDraftTarget: ScopedThreadRef | DraftId;
|
||||
initialGitScope: "branch" | "unstaged";
|
||||
}
|
||||
|
||||
export { DiffWorkerPoolProvider } from "./DiffWorkerPoolProvider";
|
||||
|
||||
export default function DiffPanel({ mode = "inline", composerDraftTarget }: DiffPanelProps) {
|
||||
export default function DiffPanel({
|
||||
mode = "inline",
|
||||
composerDraftTarget,
|
||||
initialGitScope: initialGitScopeProp,
|
||||
}: DiffPanelProps) {
|
||||
const { resolvedTheme } = useTheme();
|
||||
const settings = useClientSettings();
|
||||
const [initialGitScope] = useState(initialGitScopeProp);
|
||||
const [diffRenderMode, setDiffRenderMode] = useState<DiffRenderMode>("stacked");
|
||||
const [wordWrap, setWordWrap] = useState(settings.wordWrap);
|
||||
const [diffIgnoreWhitespace, setDiffIgnoreWhitespace] = useState(settings.diffIgnoreWhitespace);
|
||||
@@ -199,9 +205,6 @@ export default function DiffPanel({ mode = "inline", composerDraftTarget }: Diff
|
||||
strict: false,
|
||||
select: (params) => resolveThreadRouteRef(params),
|
||||
});
|
||||
const diffSelection = useDiffPanelStore((state) =>
|
||||
selectThreadDiffPanelSelection(state.byThreadKey, routeThreadRef),
|
||||
);
|
||||
const activeThreadId = routeThreadRef?.threadId ?? null;
|
||||
const activeThread = useThread(routeThreadRef);
|
||||
const activeProjectId = activeThread?.projectId ?? null;
|
||||
@@ -229,6 +232,13 @@ export default function DiffPanel({ mode = "inline", composerDraftTarget }: Diff
|
||||
})
|
||||
: null,
|
||||
);
|
||||
const diffSelection = useDiffPanelStore((state) =>
|
||||
selectThreadDiffPanelSelection(
|
||||
state.byThreadKey,
|
||||
routeThreadRef,
|
||||
initialGitScope === "unstaged",
|
||||
),
|
||||
);
|
||||
const isGitRepo = gitStatusQuery.data?.isRepo ?? true;
|
||||
const { turnDiffSummaries, inferredCheckpointTurnCountByTurnId } =
|
||||
useTurnDiffSummaries(activeThread);
|
||||
|
||||
@@ -15,6 +15,7 @@ import {
|
||||
resolveSidebarNewThreadSeedContext,
|
||||
resolveSidebarNewThreadEnvMode,
|
||||
resolveSidebarStageBadgeLabel,
|
||||
resolveSidebarThreadRowTransientProps,
|
||||
resolveThreadRowClassName,
|
||||
resolveThreadStatusPill,
|
||||
shouldClearThreadSelectionOnMouseDown,
|
||||
@@ -38,6 +39,51 @@ import {
|
||||
|
||||
const localEnvironmentId = EnvironmentId.make("environment-local");
|
||||
|
||||
describe("resolveSidebarThreadRowTransientProps", () => {
|
||||
it("only publishes rename state to the row being edited", () => {
|
||||
expect(
|
||||
resolveSidebarThreadRowTransientProps({
|
||||
threadKey: "thread-1",
|
||||
renamingThreadKey: "thread-1",
|
||||
renamingTitle: "Edited title",
|
||||
confirmingArchiveThreadKey: null,
|
||||
}),
|
||||
).toEqual({
|
||||
isRenaming: true,
|
||||
renamingTitle: "Edited title",
|
||||
isConfirmingArchive: false,
|
||||
});
|
||||
|
||||
expect(
|
||||
resolveSidebarThreadRowTransientProps({
|
||||
threadKey: "thread-2",
|
||||
renamingThreadKey: "thread-1",
|
||||
renamingTitle: "Edited title",
|
||||
confirmingArchiveThreadKey: null,
|
||||
}),
|
||||
).toEqual({
|
||||
isRenaming: false,
|
||||
renamingTitle: "",
|
||||
isConfirmingArchive: false,
|
||||
});
|
||||
});
|
||||
|
||||
it("only publishes archive confirmation state to its target row", () => {
|
||||
expect(
|
||||
resolveSidebarThreadRowTransientProps({
|
||||
threadKey: "thread-2",
|
||||
renamingThreadKey: null,
|
||||
renamingTitle: "",
|
||||
confirmingArchiveThreadKey: "thread-2",
|
||||
}),
|
||||
).toEqual({
|
||||
isRenaming: false,
|
||||
renamingTitle: "",
|
||||
isConfirmingArchive: true,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("resolveSidebarStageBadgeLabel", () => {
|
||||
it("returns Nightly for nightly primary server versions", () => {
|
||||
expect(
|
||||
|
||||
@@ -17,6 +17,25 @@ export const THREAD_JUMP_HINT_SHOW_DELAY_MS = 100;
|
||||
// nearby thread usually reuses an already-hot subscription.
|
||||
export const SIDEBAR_THREAD_PREWARM_LIMIT = 10;
|
||||
export type SidebarNewThreadEnvMode = "local" | "worktree";
|
||||
|
||||
export function resolveSidebarThreadRowTransientProps(input: {
|
||||
threadKey: string;
|
||||
renamingThreadKey: string | null;
|
||||
renamingTitle: string;
|
||||
confirmingArchiveThreadKey: string | null;
|
||||
}): {
|
||||
isRenaming: boolean;
|
||||
renamingTitle: string;
|
||||
isConfirmingArchive: boolean;
|
||||
} {
|
||||
const isRenaming = input.renamingThreadKey === input.threadKey;
|
||||
return {
|
||||
isRenaming,
|
||||
renamingTitle: isRenaming ? input.renamingTitle : "",
|
||||
isConfirmingArchive: input.confirmingArchiveThreadKey === input.threadKey,
|
||||
};
|
||||
}
|
||||
|
||||
type SidebarProject = {
|
||||
id: string;
|
||||
title: string;
|
||||
|
||||
@@ -192,6 +192,7 @@ import {
|
||||
resolveSidebarNewThreadSeedContext,
|
||||
resolveSidebarNewThreadEnvMode,
|
||||
resolveSidebarStageBadgeLabel,
|
||||
resolveSidebarThreadRowTransientProps,
|
||||
resolveThreadRowClassName,
|
||||
resolveThreadStatusPill,
|
||||
orderItemsByPreferredIds,
|
||||
@@ -324,13 +325,13 @@ interface SidebarThreadRowProps {
|
||||
isActive: boolean;
|
||||
jumpLabel: string | null;
|
||||
appSettingsConfirmThreadArchive: boolean;
|
||||
renamingThreadKey: string | null;
|
||||
isRenaming: boolean;
|
||||
renamingTitle: string;
|
||||
setRenamingTitle: (title: string) => void;
|
||||
startThreadRename: (threadKey: string, title: string) => void;
|
||||
renamingInputRef: React.RefObject<HTMLInputElement | null>;
|
||||
renamingCommittedRef: React.RefObject<boolean>;
|
||||
confirmingArchiveThreadKey: string | null;
|
||||
isConfirmingArchive: boolean;
|
||||
setConfirmingArchiveThreadKey: React.Dispatch<React.SetStateAction<string | null>>;
|
||||
confirmArchiveButtonRefs: React.RefObject<Map<string, HTMLButtonElement>>;
|
||||
handleThreadClick: (
|
||||
@@ -361,13 +362,13 @@ export const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThr
|
||||
isActive,
|
||||
jumpLabel,
|
||||
appSettingsConfirmThreadArchive,
|
||||
renamingThreadKey,
|
||||
isRenaming,
|
||||
renamingTitle,
|
||||
setRenamingTitle,
|
||||
startThreadRename,
|
||||
renamingInputRef,
|
||||
renamingCommittedRef,
|
||||
confirmingArchiveThreadKey,
|
||||
isConfirmingArchive,
|
||||
setConfirmingArchiveThreadKey,
|
||||
confirmArchiveButtonRefs,
|
||||
handleThreadClick,
|
||||
@@ -468,8 +469,8 @@ export const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThr
|
||||
const pr = resolveThreadPr(thread.branch, gitStatus.data);
|
||||
const prStatus = prStatusIndicator(pr, gitStatus.data?.sourceControlProvider);
|
||||
const terminalStatus = terminalStatusFromRunningIds(runningTerminalIds);
|
||||
const isConfirmingArchive = confirmingArchiveThreadKey === threadKey && !isThreadRunning;
|
||||
const threadMetaClassName = isConfirmingArchive
|
||||
const showArchiveConfirmation = isConfirmingArchive && !isThreadRunning;
|
||||
const threadMetaClassName = showArchiveConfirmation
|
||||
? "pointer-events-none opacity-0"
|
||||
: !isThreadRunning
|
||||
? "pointer-events-none transition-opacity duration-150 max-sm:pr-6 group-hover/menu-sub-item:opacity-0 group-focus-within/menu-sub-item:opacity-0"
|
||||
@@ -502,7 +503,7 @@ export const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThr
|
||||
(event: React.MouseEvent) => {
|
||||
// Already renaming this row: a double-click on the row chrome (outside the
|
||||
// input) must not restart and discard the in-progress edit.
|
||||
if (renamingThreadKey === threadKey) return;
|
||||
if (isRenaming) return;
|
||||
// On mobile the first tap navigates and closes the sidebar sheet, so the
|
||||
// inline rename can't be shown. Renaming there stays on the context menu.
|
||||
if (isMobile) return;
|
||||
@@ -514,7 +515,7 @@ export const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThr
|
||||
event.preventDefault();
|
||||
startThreadRename(threadKey, thread.title);
|
||||
},
|
||||
[isMobile, renamingThreadKey, startThreadRename, threadKey, thread.title],
|
||||
[isMobile, isRenaming, startThreadRename, threadKey, thread.title],
|
||||
);
|
||||
const handleRowKeyDown = useCallback(
|
||||
(event: React.KeyboardEvent) => {
|
||||
@@ -709,7 +710,7 @@ export const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThr
|
||||
</Tooltip>
|
||||
)}
|
||||
{threadStatus && <ThreadStatusLabel status={threadStatus} />}
|
||||
{renamingThreadKey === threadKey ? (
|
||||
{isRenaming ? (
|
||||
<input
|
||||
ref={handleRenameInputRef}
|
||||
className="min-w-0 flex-1 truncate text-base sm:text-xs bg-transparent outline-none border border-ring rounded px-0.5"
|
||||
@@ -783,7 +784,7 @@ export const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThr
|
||||
isRemoteThread ? "max-sm:min-w-24" : "max-sm:min-w-20"
|
||||
}`}
|
||||
>
|
||||
{isConfirmingArchive ? (
|
||||
{showArchiveConfirmation ? (
|
||||
<button
|
||||
ref={handleConfirmArchiveRef}
|
||||
type="button"
|
||||
@@ -995,6 +996,12 @@ const SidebarProjectThreadList = memo(function SidebarProjectThreadList(
|
||||
{shouldShowThreadPanel &&
|
||||
renderedThreads.map((thread) => {
|
||||
const threadKey = scopedThreadKey(scopeThreadRef(thread.environmentId, thread.id));
|
||||
const transientProps = resolveSidebarThreadRowTransientProps({
|
||||
threadKey,
|
||||
renamingThreadKey,
|
||||
renamingTitle,
|
||||
confirmingArchiveThreadKey,
|
||||
});
|
||||
return (
|
||||
<SidebarThreadRow
|
||||
key={threadKey}
|
||||
@@ -1004,13 +1011,13 @@ const SidebarProjectThreadList = memo(function SidebarProjectThreadList(
|
||||
isActive={activeRouteThreadKey === threadKey}
|
||||
jumpLabel={threadJumpLabelByKey.get(threadKey) ?? null}
|
||||
appSettingsConfirmThreadArchive={appSettingsConfirmThreadArchive}
|
||||
renamingThreadKey={renamingThreadKey}
|
||||
renamingTitle={renamingTitle}
|
||||
isRenaming={transientProps.isRenaming}
|
||||
renamingTitle={transientProps.renamingTitle}
|
||||
setRenamingTitle={setRenamingTitle}
|
||||
startThreadRename={startThreadRename}
|
||||
renamingInputRef={renamingInputRef}
|
||||
renamingCommittedRef={renamingCommittedRef}
|
||||
confirmingArchiveThreadKey={confirmingArchiveThreadKey}
|
||||
isConfirmingArchive={transientProps.isConfirmingArchive}
|
||||
setConfirmingArchiveThreadKey={setConfirmingArchiveThreadKey}
|
||||
confirmArchiveButtonRefs={confirmArchiveButtonRefs}
|
||||
handleThreadClick={handleThreadClick}
|
||||
|
||||
@@ -95,6 +95,7 @@ import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
|
||||
import { toastManager } from "../ui/toast";
|
||||
import {
|
||||
BotIcon,
|
||||
CheckIcon,
|
||||
CircleAlertIcon,
|
||||
ListTodoIcon,
|
||||
PencilRulerIcon,
|
||||
@@ -273,16 +274,25 @@ const ComposerFooterModeControls = memo(function ComposerFooterModeControls(prop
|
||||
{runtimeModeOptions.map((mode) => {
|
||||
const option = runtimeModeConfig[mode];
|
||||
const OptionIcon = option.icon;
|
||||
const isSelected = props.runtimeMode === mode;
|
||||
return (
|
||||
<SelectItem key={mode} value={mode} className="min-w-64 py-2">
|
||||
<div className="grid min-w-0 gap-0.5">
|
||||
<span className="inline-flex items-center gap-1.5 font-medium text-foreground">
|
||||
<OptionIcon className="size-3.5 shrink-0 text-muted-foreground" />
|
||||
{option.label}
|
||||
</span>
|
||||
<span className="text-muted-foreground text-xs leading-4">
|
||||
{option.description}
|
||||
</span>
|
||||
<SelectItem key={mode} value={mode} hideIndicator className="min-w-64 py-2">
|
||||
<div className="flex min-w-0 items-center gap-3">
|
||||
<div className="grid min-w-0 flex-1 gap-0.5">
|
||||
<span className="inline-flex items-center gap-1.5 font-medium text-foreground">
|
||||
<OptionIcon className="size-3.5 shrink-0 text-muted-foreground" />
|
||||
{option.label}
|
||||
</span>
|
||||
<span className="text-muted-foreground text-xs leading-4">
|
||||
{option.description}
|
||||
</span>
|
||||
</div>
|
||||
<CheckIcon
|
||||
className={cn(
|
||||
"size-4 text-blue-400",
|
||||
isSelected ? "opacity-100" : "opacity-0",
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
</SelectItem>
|
||||
);
|
||||
@@ -390,7 +400,7 @@ const ComposerFooterPrimaryActions = memo(function ComposerFooterPrimaryActions(
|
||||
export interface ChatComposerHandle {
|
||||
focusAtEnd: () => void;
|
||||
focusAt: (cursor: number) => void;
|
||||
insertTextAtEnd: (text: string) => boolean;
|
||||
insertTextAtEnd: (text: string, options?: { ensureLeadingBoundary?: boolean }) => boolean;
|
||||
openModelPicker: () => void;
|
||||
toggleModelPicker: () => void;
|
||||
isModelPickerOpen: () => boolean;
|
||||
@@ -1931,7 +1941,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
|
||||
focusAt: (cursor: number) => {
|
||||
composerEditorRef.current?.focusAt(cursor);
|
||||
},
|
||||
insertTextAtEnd: (text: string) => {
|
||||
insertTextAtEnd: (text: string, options?: { ensureLeadingBoundary?: boolean }) => {
|
||||
if (
|
||||
text.length === 0 ||
|
||||
isConnecting ||
|
||||
@@ -1942,8 +1952,14 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
const rangeEnd = promptRef.current.length;
|
||||
return applyPromptReplacement(rangeEnd, rangeEnd, text);
|
||||
const prompt = promptRef.current;
|
||||
const needsLeadingSpace =
|
||||
(options?.ensureLeadingBoundary ?? false) && prompt.length > 0 && !/\s$/.test(prompt);
|
||||
return applyPromptReplacement(
|
||||
prompt.length,
|
||||
prompt.length,
|
||||
needsLeadingSpace ? ` ${text}` : text,
|
||||
);
|
||||
},
|
||||
openModelPicker: () => {
|
||||
setIsComposerModelPickerOpen(true);
|
||||
|
||||
@@ -31,111 +31,138 @@ import {
|
||||
RustRoverIcon,
|
||||
WebStormIcon,
|
||||
} from "../JetBrainsIcons";
|
||||
import { isMacPlatform, isWindowsPlatform } from "~/lib/utils";
|
||||
import { cn, isMacPlatform, isWindowsPlatform } from "~/lib/utils";
|
||||
import { shellEnvironment } from "~/state/shell";
|
||||
import { useAtomCommand } from "~/state/use-atom-command";
|
||||
|
||||
type OpenInOption = {
|
||||
label: string;
|
||||
Icon: Icon;
|
||||
value: EditorId;
|
||||
kind: "brand" | "generic";
|
||||
};
|
||||
|
||||
const resolveOptions = (platform: string, availableEditors: ReadonlyArray<EditorId>) => {
|
||||
const baseOptions: ReadonlyArray<{ label: string; Icon: Icon; value: EditorId }> = [
|
||||
const baseOptions: ReadonlyArray<OpenInOption> = [
|
||||
{
|
||||
label: "Cursor",
|
||||
Icon: CursorIcon,
|
||||
value: "cursor",
|
||||
kind: "brand",
|
||||
},
|
||||
{
|
||||
label: "Trae",
|
||||
Icon: TraeIcon,
|
||||
value: "trae",
|
||||
kind: "brand",
|
||||
},
|
||||
{
|
||||
label: "Kiro",
|
||||
Icon: KiroIcon,
|
||||
value: "kiro",
|
||||
kind: "brand",
|
||||
},
|
||||
{
|
||||
label: "VS Code",
|
||||
Icon: VisualStudioCode,
|
||||
value: "vscode",
|
||||
kind: "brand",
|
||||
},
|
||||
{
|
||||
label: "VS Code Insiders",
|
||||
Icon: VisualStudioCodeInsiders,
|
||||
value: "vscode-insiders",
|
||||
kind: "brand",
|
||||
},
|
||||
{
|
||||
label: "VSCodium",
|
||||
Icon: VSCodium,
|
||||
value: "vscodium",
|
||||
kind: "brand",
|
||||
},
|
||||
{
|
||||
label: "Zed",
|
||||
Icon: Zed,
|
||||
value: "zed",
|
||||
kind: "brand",
|
||||
},
|
||||
{
|
||||
label: "Antigravity",
|
||||
Icon: AntigravityIcon,
|
||||
value: "antigravity",
|
||||
kind: "brand",
|
||||
},
|
||||
{
|
||||
label: "IntelliJ IDEA",
|
||||
Icon: IntelliJIdeaIcon,
|
||||
value: "idea",
|
||||
kind: "brand",
|
||||
},
|
||||
{
|
||||
label: "Aqua",
|
||||
Icon: AquaIcon,
|
||||
value: "aqua",
|
||||
kind: "brand",
|
||||
},
|
||||
{
|
||||
label: "CLion",
|
||||
Icon: CLionIcon,
|
||||
value: "clion",
|
||||
kind: "brand",
|
||||
},
|
||||
{
|
||||
label: "DataGrip",
|
||||
Icon: DataGripIcon,
|
||||
value: "datagrip",
|
||||
kind: "brand",
|
||||
},
|
||||
{
|
||||
label: "DataSpell",
|
||||
Icon: DataSpellIcon,
|
||||
value: "dataspell",
|
||||
kind: "brand",
|
||||
},
|
||||
{
|
||||
label: "GoLand",
|
||||
Icon: GoLandIcon,
|
||||
value: "goland",
|
||||
kind: "brand",
|
||||
},
|
||||
{
|
||||
label: "PhpStorm",
|
||||
Icon: PhpStormIcon,
|
||||
value: "phpstorm",
|
||||
kind: "brand",
|
||||
},
|
||||
{
|
||||
label: "PyCharm",
|
||||
Icon: PyCharmIcon,
|
||||
value: "pycharm",
|
||||
kind: "brand",
|
||||
},
|
||||
{
|
||||
label: "Rider",
|
||||
Icon: RiderIcon,
|
||||
value: "rider",
|
||||
kind: "brand",
|
||||
},
|
||||
{
|
||||
label: "RubyMine",
|
||||
Icon: RubyMineIcon,
|
||||
value: "rubymine",
|
||||
kind: "brand",
|
||||
},
|
||||
{
|
||||
label: "RustRover",
|
||||
Icon: RustRoverIcon,
|
||||
value: "rustrover",
|
||||
kind: "brand",
|
||||
},
|
||||
{
|
||||
label: "WebStorm",
|
||||
Icon: WebStormIcon,
|
||||
value: "webstorm",
|
||||
kind: "brand",
|
||||
},
|
||||
{
|
||||
label: isMacPlatform(platform)
|
||||
@@ -145,12 +172,17 @@ const resolveOptions = (platform: string, availableEditors: ReadonlyArray<Editor
|
||||
: "Files",
|
||||
Icon: FolderClosedIcon,
|
||||
value: "file-manager",
|
||||
kind: "generic",
|
||||
},
|
||||
];
|
||||
const availableEditorSet = new Set(availableEditors);
|
||||
return baseOptions.filter((option) => availableEditorSet.has(option.value));
|
||||
};
|
||||
|
||||
function getOpenInIconClass(kind: OpenInOption["kind"]) {
|
||||
return cn(kind === "brand" ? "text-foreground opacity-100" : "text-muted-foreground");
|
||||
}
|
||||
|
||||
export const OpenInPicker = memo(function OpenInPicker({
|
||||
environmentId,
|
||||
keybindings,
|
||||
@@ -233,7 +265,12 @@ export const OpenInPicker = memo(function OpenInPicker({
|
||||
disabled={!preferredEditor || !openInCwd}
|
||||
onClick={() => openInEditor(preferredEditor)}
|
||||
>
|
||||
{primaryOption?.Icon && <primaryOption.Icon aria-hidden="true" className="size-3.5" />}
|
||||
{primaryOption?.Icon && (
|
||||
<primaryOption.Icon
|
||||
aria-hidden="true"
|
||||
className={cn("size-3.5", getOpenInIconClass(primaryOption.kind))}
|
||||
/>
|
||||
)}
|
||||
<span
|
||||
className={
|
||||
compact
|
||||
@@ -259,9 +296,9 @@ export const OpenInPicker = memo(function OpenInPicker({
|
||||
</MenuTrigger>
|
||||
<MenuPopup align="end">
|
||||
{options.length === 0 && <MenuItem disabled>No installed editors found</MenuItem>}
|
||||
{options.map(({ label, Icon, value }) => (
|
||||
{options.map(({ label, Icon, value, kind }) => (
|
||||
<MenuItem key={value} onClick={() => openInEditor(value)}>
|
||||
<Icon aria-hidden="true" className="text-muted-foreground" />
|
||||
<Icon aria-hidden="true" className={getOpenInIconClass(kind)} />
|
||||
{label}
|
||||
{value === preferredEditor && openFavoriteEditorShortcutLabel && (
|
||||
<MenuShortcut>{openFavoriteEditorShortcutLabel}</MenuShortcut>
|
||||
|
||||
@@ -16,7 +16,7 @@ import {
|
||||
} from "@t3tools/shared/model";
|
||||
import { memo, useCallback, useState } from "react";
|
||||
import type { VariantProps } from "class-variance-authority";
|
||||
import { ChevronDownIcon } from "lucide-react";
|
||||
import { CheckIcon, ChevronDownIcon } from "lucide-react";
|
||||
import { Button, buttonVariants } from "../ui/button";
|
||||
import {
|
||||
Menu,
|
||||
@@ -30,6 +30,7 @@ import {
|
||||
import { useComposerDraftStore, DraftId } from "../../composerDraftStore";
|
||||
import { getProviderModelCapabilities } from "../../providerModels";
|
||||
import { cn } from "~/lib/utils";
|
||||
import { Badge } from "../ui/badge";
|
||||
|
||||
type ProviderOptions = ReadonlyArray<ProviderOptionSelection>;
|
||||
|
||||
@@ -46,6 +47,17 @@ type TraitsPersistence =
|
||||
|
||||
const ULTRATHINK_PROMPT_PREFIX = "Ultrathink:\n";
|
||||
|
||||
function DefaultBadge() {
|
||||
return (
|
||||
<Badge
|
||||
variant="outline"
|
||||
className="inline-flex h-4 w-fit min-w-0 items-center justify-center gap-0 border-border/70 bg-muted/60 px-1.5 py-0 font-semibold text-[10px] text-muted-foreground leading-none sm:h-4"
|
||||
>
|
||||
Default
|
||||
</Badge>
|
||||
);
|
||||
}
|
||||
|
||||
function replaceDescriptorCurrentValue(
|
||||
descriptors: ReadonlyArray<ProviderOptionDescriptor>,
|
||||
descriptorId: string,
|
||||
@@ -285,62 +297,90 @@ export const TraitsMenuContent = memo(function TraitsMenuContentImpl({
|
||||
|
||||
return (
|
||||
<>
|
||||
{selectDescriptors.map((descriptor, index) => (
|
||||
<div key={descriptor.id}>
|
||||
{index > 0 ? <MenuDivider /> : null}
|
||||
<MenuGroup>
|
||||
<div className="px-2 pt-1.5 pb-1 font-medium text-muted-foreground text-xs">
|
||||
{descriptor.label}
|
||||
</div>
|
||||
{ultrathinkInBodyText && descriptor.id === primarySelectDescriptor?.id ? (
|
||||
<div className="px-2 pb-1.5 text-muted-foreground/80 text-xs">
|
||||
Your prompt contains "ultrathink" in the text. Remove it to change this
|
||||
option.
|
||||
{selectDescriptors.map((descriptor, index) => {
|
||||
const selectedValue =
|
||||
ultrathinkPromptControlled && descriptor.id === primarySelectDescriptor?.id
|
||||
? "ultrathink"
|
||||
: (getDescriptorStringValue(descriptor) ?? "");
|
||||
|
||||
return (
|
||||
<div key={descriptor.id}>
|
||||
{index > 0 ? <MenuDivider /> : null}
|
||||
<MenuGroup>
|
||||
<div className="px-2 pt-1.5 pb-1 font-medium text-muted-foreground text-xs">
|
||||
{descriptor.label}
|
||||
</div>
|
||||
) : null}
|
||||
<MenuRadioGroup
|
||||
value={
|
||||
ultrathinkPromptControlled && descriptor.id === primarySelectDescriptor?.id
|
||||
? "ultrathink"
|
||||
: (getDescriptorStringValue(descriptor) ?? "")
|
||||
}
|
||||
onValueChange={(value) => handleSelectChange(descriptor, value)}
|
||||
>
|
||||
{descriptor.options.map((option) => (
|
||||
<MenuRadioItem
|
||||
key={option.id}
|
||||
value={option.id}
|
||||
disabled={ultrathinkInBodyText && descriptor.id === primarySelectDescriptor?.id}
|
||||
>
|
||||
{option.label}
|
||||
{option.isDefault ? " (default)" : ""}
|
||||
</MenuRadioItem>
|
||||
))}
|
||||
</MenuRadioGroup>
|
||||
</MenuGroup>
|
||||
</div>
|
||||
))}
|
||||
{booleanDescriptors.map((descriptor, index) => (
|
||||
<div key={descriptor.id}>
|
||||
{index > 0 || selectDescriptors.length > 0 ? <MenuDivider /> : null}
|
||||
<MenuGroup>
|
||||
<div className="px-2 py-1.5 font-medium text-muted-foreground text-xs">
|
||||
{descriptor.label}
|
||||
</div>
|
||||
<MenuRadioGroup
|
||||
value={descriptor.currentValue === true ? "on" : "off"}
|
||||
onValueChange={(value) => {
|
||||
updateDescriptors(
|
||||
replaceDescriptorCurrentValue(descriptors, descriptor.id, value === "on"),
|
||||
);
|
||||
}}
|
||||
>
|
||||
<MenuRadioItem value="on">On</MenuRadioItem>
|
||||
<MenuRadioItem value="off">Off</MenuRadioItem>
|
||||
</MenuRadioGroup>
|
||||
</MenuGroup>
|
||||
</div>
|
||||
))}
|
||||
{ultrathinkInBodyText && descriptor.id === primarySelectDescriptor?.id ? (
|
||||
<div className="px-2 pb-1.5 text-muted-foreground/80 text-xs">
|
||||
Your prompt contains "ultrathink" in the text. Remove it to change this
|
||||
option.
|
||||
</div>
|
||||
) : null}
|
||||
<MenuRadioGroup
|
||||
value={selectedValue}
|
||||
onValueChange={(value) => handleSelectChange(descriptor, value)}
|
||||
>
|
||||
{descriptor.options.map((option) => (
|
||||
<MenuRadioItem
|
||||
key={option.id}
|
||||
value={option.id}
|
||||
hideIndicator
|
||||
disabled={ultrathinkInBodyText && descriptor.id === primarySelectDescriptor?.id}
|
||||
>
|
||||
<span className="flex w-full min-w-0 items-center justify-between gap-3">
|
||||
<span className="min-w-0 truncate">
|
||||
{option.label}
|
||||
{option.isDefault ? (
|
||||
<>
|
||||
{" "}
|
||||
<DefaultBadge />
|
||||
</>
|
||||
) : null}
|
||||
</span>
|
||||
{option.id === selectedValue ? (
|
||||
<CheckIcon className="size-3.5 shrink-0 text-blue-400" />
|
||||
) : null}
|
||||
</span>
|
||||
</MenuRadioItem>
|
||||
))}
|
||||
</MenuRadioGroup>
|
||||
</MenuGroup>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
{booleanDescriptors.map((descriptor, index) => {
|
||||
const selectedValue = descriptor.currentValue === true ? "on" : "off";
|
||||
|
||||
return (
|
||||
<div key={descriptor.id}>
|
||||
{index > 0 || selectDescriptors.length > 0 ? <MenuDivider /> : null}
|
||||
<MenuGroup>
|
||||
<div className="px-2 py-1.5 font-medium text-muted-foreground text-xs">
|
||||
{descriptor.label}
|
||||
</div>
|
||||
<MenuRadioGroup
|
||||
value={selectedValue}
|
||||
onValueChange={(value) => {
|
||||
updateDescriptors(
|
||||
replaceDescriptorCurrentValue(descriptors, descriptor.id, value === "on"),
|
||||
);
|
||||
}}
|
||||
>
|
||||
{(["on", "off"] as const).map((value) => (
|
||||
<MenuRadioItem key={value} value={value} hideIndicator>
|
||||
<span className="flex w-full min-w-0 items-center justify-between gap-3">
|
||||
<span>{value === "on" ? "On" : "Off"}</span>
|
||||
{value === selectedValue ? (
|
||||
<CheckIcon className="size-3.5 shrink-0 text-blue-400" />
|
||||
) : null}
|
||||
</span>
|
||||
</MenuRadioItem>
|
||||
))}
|
||||
</MenuRadioGroup>
|
||||
</MenuGroup>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</>
|
||||
);
|
||||
});
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
import { collectComposerInlineTokens } from "@t3tools/shared/composerInlineTokens";
|
||||
import {
|
||||
$createLineBreakNode,
|
||||
$createTextNode,
|
||||
$getRoot,
|
||||
$getSelection,
|
||||
$isRangeSelection,
|
||||
COMMAND_PRIORITY_HIGH,
|
||||
PASTE_COMMAND,
|
||||
type LexicalEditor,
|
||||
type LexicalNode,
|
||||
} from "lexical";
|
||||
|
||||
interface ComposerInlineTokenPasteOptions {
|
||||
createMentionNode: (path: string) => LexicalNode;
|
||||
getExpandedAbsoluteOffsetForPoint: (node: LexicalNode, pointOffset: number) => number;
|
||||
}
|
||||
|
||||
export function registerComposerInlineTokenPaste(
|
||||
editor: LexicalEditor,
|
||||
options: ComposerInlineTokenPasteOptions,
|
||||
): () => void {
|
||||
return editor.registerCommand(
|
||||
PASTE_COMMAND,
|
||||
(event) => {
|
||||
if (!(event instanceof ClipboardEvent) || event.clipboardData === null) {
|
||||
return false;
|
||||
}
|
||||
if (event.clipboardData.files.length > 0) {
|
||||
return false;
|
||||
}
|
||||
const text = event.clipboardData.getData("text/plain");
|
||||
if (text.length === 0) {
|
||||
return false;
|
||||
}
|
||||
// Token grammar requires trailing whitespace; a virtual newline lets a
|
||||
// mention at the very end of the pasted text still parse.
|
||||
const mentions = collectComposerInlineTokens(`${text}\n`).filter(
|
||||
(token) => token.type === "mention" && token.end <= text.length,
|
||||
);
|
||||
if (mentions.length === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Lexical command listeners already run inside an editor update. Starting
|
||||
// a nested update here queues the mention insertion until after this
|
||||
// listener returns, which lets the plain-text paste handler run as well.
|
||||
const selection = $getSelection();
|
||||
if (!$isRangeSelection(selection)) {
|
||||
return false;
|
||||
}
|
||||
const nodes: LexicalNode[] = [];
|
||||
const appendText = (value: string) => {
|
||||
const lines = value.split("\n");
|
||||
for (let index = 0; index < lines.length; index += 1) {
|
||||
const line = lines[index] ?? "";
|
||||
if (line.length > 0) {
|
||||
nodes.push($createTextNode(line));
|
||||
}
|
||||
if (index < lines.length - 1) {
|
||||
nodes.push($createLineBreakNode());
|
||||
}
|
||||
}
|
||||
};
|
||||
const firstMention = mentions[0];
|
||||
if (firstMention && firstMention.start === 0) {
|
||||
const startPoint = selection.isBackward() ? selection.focus : selection.anchor;
|
||||
const insertionOffset = options.getExpandedAbsoluteOffsetForPoint(
|
||||
startPoint.getNode(),
|
||||
startPoint.offset,
|
||||
);
|
||||
const precedingChar = $getRoot()
|
||||
.getTextContent()
|
||||
.slice(insertionOffset - 1, insertionOffset);
|
||||
if (precedingChar.length > 0 && !/\s/.test(precedingChar)) {
|
||||
nodes.push($createTextNode(" "));
|
||||
}
|
||||
}
|
||||
let cursor = 0;
|
||||
for (const mention of mentions) {
|
||||
if (mention.start < cursor) {
|
||||
continue;
|
||||
}
|
||||
if (mention.start > cursor) {
|
||||
appendText(text.slice(cursor, mention.start));
|
||||
}
|
||||
nodes.push(options.createMentionNode(mention.value));
|
||||
cursor = mention.end;
|
||||
}
|
||||
if (cursor < text.length) {
|
||||
appendText(text.slice(cursor));
|
||||
} else {
|
||||
// Keep the serialized prompt valid: mention tokens need trailing
|
||||
// whitespace, so a paste ending in a mention gets the same
|
||||
// trailing space the autocomplete inserts.
|
||||
nodes.push($createTextNode(" "));
|
||||
}
|
||||
selection.insertNodes(nodes);
|
||||
event.preventDefault();
|
||||
return true;
|
||||
},
|
||||
COMMAND_PRIORITY_HIGH,
|
||||
);
|
||||
}
|
||||
@@ -1,10 +1,19 @@
|
||||
import type {
|
||||
ContextMenuItem as TreeContextMenuItem,
|
||||
ContextMenuOpenContext as TreeContextMenuOpenContext,
|
||||
} from "@pierre/trees";
|
||||
import type { EnvironmentId, ProjectEntry } from "@t3tools/contracts";
|
||||
import { FileTree, useFileTree } from "@pierre/trees/react";
|
||||
import { serializeComposerFileLink } from "@t3tools/shared/composerTrigger";
|
||||
import { RefreshCw, Search } from "lucide-react";
|
||||
import { useEffect, useMemo, useRef } from "react";
|
||||
|
||||
import { toastManager } from "~/components/ui/toast";
|
||||
import { useComposerHandleContext } from "~/composerHandleContext";
|
||||
import { writeTextToClipboard } from "~/hooks/useCopyToClipboard";
|
||||
import { useTheme } from "~/hooks/useTheme";
|
||||
import { cn } from "~/lib/utils";
|
||||
import { readLocalApi } from "~/localApi";
|
||||
import { T3_PIERRE_ICONS } from "~/pierre-icons";
|
||||
|
||||
import { useProjectEntriesQuery } from "./projectFilesQueryState";
|
||||
@@ -39,6 +48,7 @@ export default function FileBrowserPanel({
|
||||
onOpenFile,
|
||||
}: FileBrowserPanelProps) {
|
||||
const { resolvedTheme } = useTheme();
|
||||
const composerRef = useComposerHandleContext();
|
||||
const entriesQuery = useProjectEntriesQuery(environmentId, cwd);
|
||||
const entries = entriesQuery.data?.entries ?? [];
|
||||
const entryKinds = useMemo(
|
||||
@@ -49,7 +59,93 @@ export default function FileBrowserPanel({
|
||||
const treePaths = useMemo(() => entries.map(treePath), [entries]);
|
||||
const previousTreePathsRef = useRef<readonly string[]>([]);
|
||||
|
||||
// The tree renders rows in shadow DOM and its anchor rect is unreliable, so
|
||||
// capture the right-click position ourselves; contextmenu is a composed
|
||||
// event, so a capture-phase listener sees it with viewport coordinates.
|
||||
const contextMenuPointerRef = useRef<{ x: number; y: number; at: number } | null>(null);
|
||||
useEffect(() => {
|
||||
const capturePointer = (event: MouseEvent) => {
|
||||
contextMenuPointerRef.current = { x: event.clientX, y: event.clientY, at: event.timeStamp };
|
||||
};
|
||||
document.addEventListener("contextmenu", capturePointer, true);
|
||||
return () => document.removeEventListener("contextmenu", capturePointer, true);
|
||||
}, []);
|
||||
|
||||
const showEntryContextMenu = async (
|
||||
item: TreeContextMenuItem,
|
||||
context: TreeContextMenuOpenContext,
|
||||
) => {
|
||||
const api = readLocalApi();
|
||||
if (!api) {
|
||||
context.close();
|
||||
return;
|
||||
}
|
||||
const relativePath = item.path.replace(/\/$/, "");
|
||||
const mention = serializeComposerFileLink(relativePath);
|
||||
const pointer = contextMenuPointerRef.current;
|
||||
const pointerIsFresh = pointer !== null && performance.now() - pointer.at < 1000;
|
||||
const anchorRect = context.anchorElement.getBoundingClientRect();
|
||||
const position = pointerIsFresh
|
||||
? { x: pointer.x, y: pointer.y }
|
||||
: { x: anchorRect.left, y: anchorRect.bottom };
|
||||
try {
|
||||
const clicked = await api.contextMenu.show(
|
||||
[
|
||||
{ id: "copy-mention", label: "Copy mention" },
|
||||
{ id: "add-to-chat", label: "Add to chat" },
|
||||
],
|
||||
position,
|
||||
);
|
||||
if (clicked === "copy-mention") {
|
||||
try {
|
||||
await writeTextToClipboard(mention);
|
||||
toastManager.add({ type: "success", title: "Mention copied", description: relativePath });
|
||||
} catch (error) {
|
||||
toastManager.add({
|
||||
type: "error",
|
||||
title: "Failed to copy mention",
|
||||
description: error instanceof Error ? error.message : "An error occurred.",
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (clicked === "add-to-chat") {
|
||||
const composer = composerRef?.current;
|
||||
if (!composer) {
|
||||
toastManager.add({
|
||||
type: "error",
|
||||
title: "Unable to add to chat",
|
||||
description: "Open a chat for this project and try again.",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const inserted = composer.insertTextAtEnd(`${mention} `, { ensureLeadingBoundary: true });
|
||||
if (!inserted) {
|
||||
toastManager.add({
|
||||
type: "error",
|
||||
title: "Unable to add to chat",
|
||||
description: "The chat isn't ready to accept input right now.",
|
||||
});
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
context.close();
|
||||
}
|
||||
};
|
||||
const showEntryContextMenuRef = useRef(showEntryContextMenu);
|
||||
useEffect(() => {
|
||||
showEntryContextMenuRef.current = showEntryContextMenu;
|
||||
});
|
||||
|
||||
const { model } = useFileTree({
|
||||
composition: {
|
||||
contextMenu: {
|
||||
triggerMode: "right-click",
|
||||
onOpen: (item, context) => {
|
||||
void showEntryContextMenuRef.current(item, context);
|
||||
},
|
||||
},
|
||||
},
|
||||
density: "compact",
|
||||
fileTreeSearchMode: "hide-non-matches",
|
||||
flattenEmptyDirectories: true,
|
||||
|
||||
@@ -1461,22 +1461,34 @@ function SavedBackendListRow({
|
||||
</TooltipPopup>
|
||||
</Tooltip>
|
||||
) : (
|
||||
<Button
|
||||
size="xs"
|
||||
variant="outline"
|
||||
disabled={isConnecting || removingEnvironmentId === environmentId}
|
||||
onClick={() =>
|
||||
void (isConnected ? onRemove(environmentId) : onConnect(environmentId))
|
||||
}
|
||||
>
|
||||
{isConnected
|
||||
? removingEnvironmentId === environmentId
|
||||
? "Disconnecting…"
|
||||
: "Disconnect"
|
||||
: isConnecting
|
||||
? "Connecting…"
|
||||
: "Connect"}
|
||||
</Button>
|
||||
<>
|
||||
{!isConnected ? (
|
||||
<Button
|
||||
size="xs"
|
||||
variant="outline"
|
||||
disabled={removingEnvironmentId === environmentId}
|
||||
onClick={() => void onRemove(environmentId)}
|
||||
>
|
||||
{removingEnvironmentId === environmentId ? "Removing…" : "Remove"}
|
||||
</Button>
|
||||
) : null}
|
||||
<Button
|
||||
size="xs"
|
||||
variant="outline"
|
||||
disabled={isConnecting || removingEnvironmentId === environmentId}
|
||||
onClick={() =>
|
||||
void (isConnected ? onRemove(environmentId) : onConnect(environmentId))
|
||||
}
|
||||
>
|
||||
{isConnected
|
||||
? removingEnvironmentId === environmentId
|
||||
? "Disconnecting…"
|
||||
: "Disconnect"
|
||||
: isConnecting
|
||||
? "Connecting…"
|
||||
: "Connect"}
|
||||
</Button>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -147,32 +147,42 @@ function MenuRadioGroup(props: MenuPrimitive.RadioGroup.Props) {
|
||||
return <MenuPrimitive.RadioGroup data-slot="menu-radio-group" {...props} />;
|
||||
}
|
||||
|
||||
function MenuRadioItem({ className, children, ...props }: MenuPrimitive.RadioItem.Props) {
|
||||
function MenuRadioItem({
|
||||
className,
|
||||
children,
|
||||
hideIndicator = false,
|
||||
...props
|
||||
}: MenuPrimitive.RadioItem.Props & {
|
||||
hideIndicator?: boolean;
|
||||
}) {
|
||||
return (
|
||||
<MenuPrimitive.RadioItem
|
||||
className={cn(
|
||||
"grid min-h-8 in-data-[side=none]:min-w-[calc(var(--anchor-width)+1.25rem)] cursor-default grid-cols-[1rem_1fr] items-center gap-2 rounded-sm py-1 ps-2 pe-4 text-base text-foreground outline-none data-disabled:pointer-events-none data-highlighted:bg-accent data-highlighted:text-accent-foreground data-disabled:opacity-64 sm:min-h-7 sm:text-sm [&_svg:not([class*='size-'])]:size-4.5 sm:[&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:shrink-0",
|
||||
"grid min-h-8 in-data-[side=none]:min-w-[calc(var(--anchor-width)+1.25rem)] cursor-default items-center gap-2 rounded-sm py-1 text-base text-foreground outline-none data-disabled:pointer-events-none data-highlighted:bg-accent data-highlighted:text-accent-foreground data-disabled:opacity-64 sm:min-h-7 sm:text-sm [&_svg:not([class*='size-'])]:size-4.5 sm:[&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:shrink-0",
|
||||
hideIndicator ? "grid-cols-[1fr] ps-3 pe-3" : "grid-cols-[1rem_1fr] ps-2 pe-4",
|
||||
className,
|
||||
)}
|
||||
data-slot="menu-radio-item"
|
||||
{...props}
|
||||
>
|
||||
<MenuPrimitive.RadioItemIndicator className="col-start-1">
|
||||
<svg
|
||||
fill="none"
|
||||
height="24"
|
||||
stroke="currentColor"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
strokeWidth="2"
|
||||
viewBox="0 0 24 24"
|
||||
width="24"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
>
|
||||
<path d="M5.252 12.7 10.2 18.63 18.748 5.37" />
|
||||
</svg>
|
||||
</MenuPrimitive.RadioItemIndicator>
|
||||
<span className="col-start-2">{children}</span>
|
||||
{hideIndicator ? null : (
|
||||
<MenuPrimitive.RadioItemIndicator className="col-start-1">
|
||||
<svg
|
||||
fill="none"
|
||||
height="24"
|
||||
stroke="currentColor"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
strokeWidth="2"
|
||||
viewBox="0 0 24 24"
|
||||
width="24"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
>
|
||||
<path d="M5.252 12.7 10.2 18.63 18.748 5.37" />
|
||||
</svg>
|
||||
</MenuPrimitive.RadioItemIndicator>
|
||||
)}
|
||||
<span className={hideIndicator ? "col-start-1" : "col-start-2"}>{children}</span>
|
||||
</MenuPrimitive.RadioItem>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -9,12 +9,26 @@ const THREAD_REF = scopeThreadRef(EnvironmentId.make("environment-1"), ThreadId.
|
||||
describe("diffPanelStore", () => {
|
||||
beforeEach(() => useDiffPanelStore.setState({ byThreadKey: {}, branchBaseRefByThreadKey: {} }));
|
||||
|
||||
it("defaults each thread to branch changes with automatic base selection", () => {
|
||||
it("defaults each thread to branch changes when the working tree is clean", () => {
|
||||
expect(
|
||||
selectThreadDiffPanelSelection(useDiffPanelStore.getState().byThreadKey, THREAD_REF),
|
||||
).toEqual({ kind: "branch", baseRef: null });
|
||||
});
|
||||
|
||||
it("defaults each thread to working changes when the working tree is dirty", () => {
|
||||
expect(
|
||||
selectThreadDiffPanelSelection(useDiffPanelStore.getState().byThreadKey, THREAD_REF, true),
|
||||
).toEqual({ kind: "unstaged" });
|
||||
});
|
||||
|
||||
it("preserves an explicit scope selection when the working tree state changes", () => {
|
||||
useDiffPanelStore.getState().selectGitScope(THREAD_REF, "branch");
|
||||
|
||||
expect(
|
||||
selectThreadDiffPanelSelection(useDiffPanelStore.getState().byThreadKey, THREAD_REF, true),
|
||||
).toEqual({ kind: "branch", baseRef: null });
|
||||
});
|
||||
|
||||
it("clears incompatible selection fields when changing scopes", () => {
|
||||
const store = useDiffPanelStore.getState();
|
||||
store.selectTurn(THREAD_REF, TurnId.make("turn-1"), "src/app.ts");
|
||||
|
||||
@@ -11,6 +11,7 @@ export type DiffPanelSelection =
|
||||
| { kind: "turn"; turnId: TurnId; filePath: string | null; revealRequestId: number };
|
||||
|
||||
const DEFAULT_SELECTION: DiffPanelSelection = { kind: "branch", baseRef: null };
|
||||
const DEFAULT_WORKING_TREE_SELECTION: DiffPanelSelection = { kind: "unstaged" };
|
||||
|
||||
interface DiffPanelStoreState {
|
||||
byThreadKey: Record<string, DiffPanelSelection>;
|
||||
@@ -133,7 +134,11 @@ export const useDiffPanelStore = create<DiffPanelStoreState>()(
|
||||
export function selectThreadDiffPanelSelection(
|
||||
byThreadKey: Record<string, DiffPanelSelection>,
|
||||
ref: ScopedThreadRef | null | undefined,
|
||||
hasWorkingTreeChanges = false,
|
||||
): DiffPanelSelection {
|
||||
if (!ref) return DEFAULT_SELECTION;
|
||||
return byThreadKey[scopedThreadKey(ref)] ?? DEFAULT_SELECTION;
|
||||
return (
|
||||
byThreadKey[scopedThreadKey(ref)] ??
|
||||
(hasWorkingTreeChanges ? DEFAULT_WORKING_TREE_SELECTION : DEFAULT_SELECTION)
|
||||
);
|
||||
}
|
||||
@@ -117,6 +117,21 @@ describe("rightPanelStore", () => {
|
||||
).toHaveLength(2);
|
||||
});
|
||||
|
||||
it("reopening an inactive singleton activates its existing surface", () => {
|
||||
useRightPanelStore.getState().open(refA, "diff");
|
||||
useRightPanelStore.getState().open(refA, "plan");
|
||||
useRightPanelStore.getState().open(refA, "diff");
|
||||
|
||||
expect(selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA)).toEqual({
|
||||
isOpen: true,
|
||||
activeSurfaceId: "diff",
|
||||
surfaces: [
|
||||
{ id: "diff", kind: "diff" },
|
||||
{ id: "plan", kind: "plan" },
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
it("keeps files as a singleton surface", () => {
|
||||
useRightPanelStore.getState().open(refA, "files");
|
||||
useRightPanelStore.getState().open(refA, "files");
|
||||
|
||||
@@ -8,7 +8,7 @@ The three Icon Composer projects are the source of truth for full application ic
|
||||
|
||||
Each project uses `text.svg` for the T3 mark and `background.svg` when the background is a vector layer. Additional layers use semantic names that describe their role and placement.
|
||||
|
||||
Run `vp run icons:export` from the repository root to regenerate the tracked iOS, Linux, Windows, and web assets. Run `vp run icons:check` to verify that those generated assets match their sources without changing files.
|
||||
Run `vp run icons:export` from the repository root to regenerate the tracked iOS, Linux, Windows, and web assets. The development web exports are also copied to `apps/web/public` for the browser favicon and splash screen. Run `vp run icons:check` to verify that the generated assets and public copies match their sources without changing files.
|
||||
|
||||
Exporting requires Icon Composer 2 or newer on macOS. The script selects the newest compatible exporter from Xcode or a standalone Icon Composer installation and pins design generation 26. Set `ICON_COMPOSER_TOOL` to the full path of `Icon Composer.app/Contents/Executables/ictool` to override automatic discovery.
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
ProjectId,
|
||||
ProviderInstanceId,
|
||||
ThreadId,
|
||||
TurnId,
|
||||
type OrchestrationThread,
|
||||
type OrchestrationThreadDetailSnapshot,
|
||||
type OrchestrationThreadStreamItem,
|
||||
@@ -74,6 +75,26 @@ const BASE_THREAD: OrchestrationThread = {
|
||||
checkpoints: [],
|
||||
session: null,
|
||||
};
|
||||
const ACTIVE_THREAD: OrchestrationThread = {
|
||||
...BASE_THREAD,
|
||||
latestTurn: {
|
||||
turnId: TurnId.make("turn-1"),
|
||||
state: "running",
|
||||
requestedAt: "2026-04-01T00:01:00.000Z",
|
||||
startedAt: "2026-04-01T00:01:00.000Z",
|
||||
completedAt: null,
|
||||
assistantMessageId: null,
|
||||
},
|
||||
session: {
|
||||
threadId: THREAD_ID,
|
||||
status: "running",
|
||||
providerName: "codex",
|
||||
runtimeMode: "full-access",
|
||||
activeTurnId: TurnId.make("turn-1"),
|
||||
lastError: null,
|
||||
updatedAt: "2026-04-01T00:01:00.000Z",
|
||||
},
|
||||
};
|
||||
|
||||
type TestThreadInput = OrchestrationThreadStreamItem | Error;
|
||||
|
||||
@@ -308,6 +329,31 @@ describe("EnvironmentThreads", () => {
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("does not persist active thread snapshots during streaming or teardown", () =>
|
||||
Effect.gen(function* () {
|
||||
const savedThreads = yield* Effect.scoped(
|
||||
Effect.gen(function* () {
|
||||
const harness = yield* makeHarness({ cached: ACTIVE_THREAD });
|
||||
yield* awaitThreadState(
|
||||
harness.observed,
|
||||
(value) =>
|
||||
value.status === "live" &&
|
||||
Option.isSome(value.data) &&
|
||||
value.data.value.session?.status === "running",
|
||||
);
|
||||
|
||||
yield* TestClock.adjust("500 millis");
|
||||
yield* Effect.yieldNow;
|
||||
|
||||
expect(yield* Ref.get(harness.savedThreads)).toEqual([]);
|
||||
return harness.savedThreads;
|
||||
}),
|
||||
);
|
||||
|
||||
expect(yield* Ref.get(savedThreads)).toEqual([]);
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("seeds the thread from the HTTP snapshot and resumes live events", () =>
|
||||
Effect.gen(function* () {
|
||||
const httpThread: OrchestrationThread = { ...BASE_THREAD, title: "HTTP title" };
|
||||
|
||||
@@ -41,6 +41,11 @@ function formatThreadError(cause: Cause.Cause<unknown>): string {
|
||||
: "Could not synchronize the thread.";
|
||||
}
|
||||
|
||||
function shouldPersistThread(thread: OrchestrationThread): boolean {
|
||||
const status = thread.session?.status;
|
||||
return status !== "starting" && status !== "running";
|
||||
}
|
||||
|
||||
export const makeEnvironmentThreadState = Effect.fn("EnvironmentThreadState.make")(function* (
|
||||
threadId: ThreadIdType,
|
||||
) {
|
||||
@@ -128,10 +133,13 @@ export const makeEnvironmentThreadState = Effect.fn("EnvironmentThreadState.make
|
||||
status: "live",
|
||||
error: Option.none(),
|
||||
});
|
||||
// Persist the thread together with the sequence it reflects so the next warm
|
||||
// cache can resume from exactly here.
|
||||
const snapshotSequence = yield* SubscriptionRef.get(lastSequence);
|
||||
yield* Queue.offer(persistence, { snapshotSequence, thread });
|
||||
// Active threads can update many times per second and retain large tool
|
||||
// payloads. The server remains the source of truth while a turn is active;
|
||||
// persist once it settles so cache encoding stays off the streaming path.
|
||||
if (shouldPersistThread(thread)) {
|
||||
const snapshotSequence = yield* SubscriptionRef.get(lastSequence);
|
||||
yield* Queue.offer(persistence, { snapshotSequence, thread });
|
||||
}
|
||||
});
|
||||
|
||||
const setDeleted = Effect.fn("EnvironmentThreadState.setDeleted")(function* () {
|
||||
@@ -246,7 +254,8 @@ export const makeEnvironmentThreadState = Effect.fn("EnvironmentThreadState.make
|
||||
Effect.flatMap(([current, snapshotSequence]) =>
|
||||
Option.match(current.data, {
|
||||
onNone: () => Effect.void,
|
||||
onSome: (thread) => persist({ snapshotSequence, thread }),
|
||||
onSome: (thread) =>
|
||||
shouldPersistThread(thread) ? persist({ snapshotSequence, thread }) : Effect.void,
|
||||
}),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -30,6 +30,7 @@ import {
|
||||
resolveDesktopBuildIconAssets,
|
||||
resolveDesktopProductName,
|
||||
resolveDesktopUpdateChannel,
|
||||
resolveDesktopWebAssetBrand,
|
||||
resolveGitHubPublishConfig,
|
||||
resolveMockUpdateServerPort,
|
||||
resolveMockUpdateServerUrl,
|
||||
@@ -102,6 +103,11 @@ it.layer(NodeServices.layer)("build-desktop-artifact", (it) => {
|
||||
});
|
||||
});
|
||||
|
||||
it("switches the bundled splash and favicon branding for nightly versions", () => {
|
||||
assert.equal(resolveDesktopWebAssetBrand("0.0.17"), "production");
|
||||
assert.equal(resolveDesktopWebAssetBrand("0.0.17-nightly.20260413.42"), "nightly");
|
||||
});
|
||||
|
||||
it.effect("resolves GitHub desktop publish config from Effect config", () =>
|
||||
Effect.gen(function* () {
|
||||
const latestConfig = yield* resolveGitHubPublishConfig("latest").pipe(
|
||||
|
||||
@@ -10,7 +10,12 @@ import rootPackageJson from "../package.json" with { type: "json" };
|
||||
import desktopPackageJson from "../apps/desktop/package.json" with { type: "json" };
|
||||
import serverPackageJson from "../apps/server/package.json" with { type: "json" };
|
||||
|
||||
import { BRAND_ASSET_PATHS } from "./lib/brand-assets.ts";
|
||||
import { applyWebBrandAssets } from "./apply-web-brand-assets.ts";
|
||||
import {
|
||||
BRAND_ASSET_PATHS,
|
||||
resolveWebAssetBrandForChannel,
|
||||
type WebAssetBrand,
|
||||
} from "./lib/brand-assets.ts";
|
||||
import { getDefaultBuildArch } from "./lib/build-target-arch.ts";
|
||||
import { loadRepoEnv } from "./lib/public-config.ts";
|
||||
import { resolveCatalogDependencies } from "./lib/resolve-catalog.ts";
|
||||
@@ -1324,6 +1329,10 @@ export function resolveDesktopUpdateChannel(version: string): "latest" | "nightl
|
||||
return /-nightly\.\d{8}\.\d+$/.test(version) ? "nightly" : "latest";
|
||||
}
|
||||
|
||||
export function resolveDesktopWebAssetBrand(version: string): WebAssetBrand {
|
||||
return resolveWebAssetBrandForChannel(resolveDesktopUpdateChannel(version));
|
||||
}
|
||||
|
||||
export function resolveDesktopBuildIconAssets(version: string): DesktopBuildIconAssets {
|
||||
if (resolveDesktopUpdateChannel(version) === "nightly") {
|
||||
return {
|
||||
@@ -1665,6 +1674,9 @@ const buildDesktopArtifact = Effect.fn("buildDesktopArtifact")(function* (
|
||||
});
|
||||
}
|
||||
|
||||
const webAssetBrand = resolveDesktopWebAssetBrand(appVersion);
|
||||
yield* applyWebBrandAssets(webAssetBrand, "apps/server/dist/client");
|
||||
yield* Effect.log(`[desktop-artifact] Applied ${webAssetBrand} web client branding.`);
|
||||
yield* validateBundledClientAssets(path.dirname(bundledClientEntry));
|
||||
|
||||
yield* fs.makeDirectory(path.join(stageAppDir, "apps/desktop"), { recursive: true });
|
||||
|
||||
@@ -13,7 +13,7 @@ import * as Stream from "effect/Stream";
|
||||
import { Command, Flag } from "effect/unstable/cli";
|
||||
import { ChildProcess, ChildProcessSpawner } from "effect/unstable/process";
|
||||
|
||||
import { BRAND_ASSET_PATHS } from "./lib/brand-assets.ts";
|
||||
import { BRAND_ASSET_PATHS, DEVELOPMENT_PUBLIC_ICON_OVERRIDES } from "./lib/brand-assets.ts";
|
||||
import { encodePngIco, readPngDimensions, WINDOWS_ICON_SIZES } from "./lib/icon-export.ts";
|
||||
|
||||
const DESIGN_GENERATION = 26;
|
||||
@@ -751,6 +751,16 @@ export const exportBrandIcons = Effect.fn("exportBrandIcons")(function* (checkOn
|
||||
}
|
||||
}
|
||||
|
||||
for (const override of DEVELOPMENT_PUBLIC_ICON_OVERRIDES) {
|
||||
const sourceContents = generated.get(override.sourceRelativePath);
|
||||
if (sourceContents === undefined) {
|
||||
return yield* Effect.die(
|
||||
new Error(`Generated development web icon is missing: ${override.sourceRelativePath}`),
|
||||
);
|
||||
}
|
||||
generated.set(override.targetRelativePath, sourceContents);
|
||||
}
|
||||
|
||||
if (checkOnly) {
|
||||
const stale = yield* Effect.filter(
|
||||
[...generated.entries()],
|
||||
|
||||
@@ -3,6 +3,7 @@ import { describe, expect, it } from "vite-plus/test";
|
||||
import {
|
||||
BRAND_ASSET_PATHS,
|
||||
DEVELOPMENT_ICON_OVERRIDES,
|
||||
DEVELOPMENT_PUBLIC_ICON_OVERRIDES,
|
||||
PUBLISH_ICON_OVERRIDES,
|
||||
resolveWebAssetBrandForChannel,
|
||||
resolveWebIconOverrides,
|
||||
@@ -37,6 +38,27 @@ describe("brand-assets", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("maps development web assets to the public splash and favicon files", () => {
|
||||
expect(DEVELOPMENT_PUBLIC_ICON_OVERRIDES).toEqual([
|
||||
{
|
||||
sourceRelativePath: BRAND_ASSET_PATHS.developmentWebFaviconIco,
|
||||
targetRelativePath: "apps/web/public/favicon.ico",
|
||||
},
|
||||
{
|
||||
sourceRelativePath: BRAND_ASSET_PATHS.developmentWebFavicon16Png,
|
||||
targetRelativePath: "apps/web/public/favicon-16x16.png",
|
||||
},
|
||||
{
|
||||
sourceRelativePath: BRAND_ASSET_PATHS.developmentWebFavicon32Png,
|
||||
targetRelativePath: "apps/web/public/favicon-32x32.png",
|
||||
},
|
||||
{
|
||||
sourceRelativePath: BRAND_ASSET_PATHS.developmentWebAppleTouchIconPng,
|
||||
targetRelativePath: "apps/web/public/apple-touch-icon.png",
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it("can target hosted web dist directly", () => {
|
||||
expect(resolveWebIconOverrides("production", "apps/web/dist")).toContainEqual({
|
||||
sourceRelativePath: BRAND_ASSET_PATHS.productionWebAppleTouchIconPng,
|
||||
|
||||
@@ -101,4 +101,9 @@ export function resolveWebIconOverrides(
|
||||
|
||||
export const DEVELOPMENT_ICON_OVERRIDES = resolveWebIconOverrides("development", "dist/client");
|
||||
|
||||
export const DEVELOPMENT_PUBLIC_ICON_OVERRIDES = resolveWebIconOverrides(
|
||||
"development",
|
||||
"apps/web/public",
|
||||
);
|
||||
|
||||
export const PUBLISH_ICON_OVERRIDES = resolveWebIconOverrides("production", "dist/client");
|
||||