Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
187 changes: 179 additions & 8 deletions .agents/upstream-review.md

Large diffs are not rendered by default.

11 changes: 8 additions & 3 deletions apps/desktop/src/ipc/methods/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
DesktopPreviewRegisterWebviewInputSchema,
DesktopPreviewScreenshotArtifactSchema,
DesktopPreviewSetColorSchemeInputSchema,
DesktopPreviewCreateTabInputSchema,
DesktopPreviewTabInputSchema,
DesktopPreviewWebviewConfigSchema,
PreviewAnnotationSubmissionResultSchema,
Expand Down Expand Up @@ -48,11 +49,15 @@ export const installPreviewEventForwarding = Effect.fn(

export const createTab = DesktopIpc.makeIpcMethod({
channel: IpcChannels.PREVIEW_CREATE_TAB_CHANNEL,
payload: DesktopPreviewTabInputSchema,
payload: DesktopPreviewCreateTabInputSchema,
result: Schema.Void,
handler: Effect.fn("desktop.ipc.preview.createTab")(function* ({ tabId }) {
handler: Effect.fn("desktop.ipc.preview.createTab")(function* ({
tabId,
zoomFactor,
colorScheme,
}) {
const manager = yield* PreviewManager.PreviewManager;
yield* manager.createTab(tabId);
yield* manager.createTab(tabId, { zoomFactor, colorScheme });
}),
});

Expand Down
7 changes: 6 additions & 1 deletion apps/desktop/src/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,12 @@ contextBridge.exposeInMainWorld("desktopBridge", {
};
},
preview: {
createTab: (tabId) => ipcRenderer.invoke(IpcChannels.PREVIEW_CREATE_TAB_CHANNEL, { tabId }),
createTab: (tabId, defaults) =>
ipcRenderer.invoke(IpcChannels.PREVIEW_CREATE_TAB_CHANNEL, {
tabId,
zoomFactor: defaults?.zoomFactor,
colorScheme: defaults?.colorScheme,
}),
closeTab: (tabId) => ipcRenderer.invoke(IpcChannels.PREVIEW_CLOSE_TAB_CHANNEL, { tabId }),
registerWebview: (tabId, webContentsId) =>
ipcRenderer.invoke(IpcChannels.PREVIEW_REGISTER_WEBVIEW_CHANNEL, { tabId, webContentsId }),
Expand Down
33 changes: 28 additions & 5 deletions apps/desktop/src/preview/Manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import type {
DesktopPreviewRecordingArtifact,
DesktopPreviewRecordingFrame,
DesktopPreviewScreenshotArtifact,
DesktopPreviewTabDefaults,
PreviewAutomationClickInput,
PreviewAutomationActionEvent,
PreviewAutomationConsoleEntry,
Expand Down Expand Up @@ -334,6 +335,21 @@ const findZoomStep = (current: number): number => {
return Math.abs(ZOOM_LEVELS[index]! - current) < ZOOM_EPSILON ? index : index - 1;
};

/**
* Clamp a client-supplied zoom factor onto the discrete ladder. The setting is
* chosen from the same ladder, but it arrives over IPC from a schema that only
* guarantees a positive number, so an out-of-band value snaps to the nearest
* step rather than leaving the guest at a zoom the zoom controls can't reach.
*/
const normalizeZoomFactor = (value: number | undefined): number => {
if (value === undefined || !Number.isFinite(value)) return DEFAULT_ZOOM_FACTOR;
let closest = ZOOM_LEVELS[0]!;
for (const level of ZOOM_LEVELS) {
if (Math.abs(level - value) < Math.abs(closest - value)) closest = level;
}
return closest;
};

const nextZoomLevel = (current: number, direction: "in" | "out"): number => {
const step = findZoomStep(current);
if (direction === "in") {
Expand Down Expand Up @@ -1614,6 +1630,7 @@ const makeNativeOperations = Effect.fn("PreviewManager.makeOperations")(function

const createTabUnlocked = Effect.fn("PreviewManager.createTabUnlocked")(function* (
tabId: string,
defaults?: DesktopPreviewTabDefaults,
) {
const updatedAt = yield* currentIso;
const result = yield* SynchronizedRef.modify(
Expand All @@ -1632,9 +1649,9 @@ const makeNativeOperations = Effect.fn("PreviewManager.makeOperations")(function
navStatus: { kind: "Idle" },
canGoBack: false,
canGoForward: false,
zoomFactor: DEFAULT_ZOOM_FACTOR,
zoomFactor: normalizeZoomFactor(defaults?.zoomFactor),
pictureInPicture: false,
colorScheme: "system",
colorScheme: defaults?.colorScheme ?? "system",
controller: "none",
updatedAt,
};
Expand All @@ -1653,8 +1670,11 @@ const makeNativeOperations = Effect.fn("PreviewManager.makeOperations")(function
return result.state;
});

const createTab = Effect.fn("PreviewManager.createTab")(function* (tabId: string) {
return yield* withTabLifecycleLock(tabId, createTabUnlocked(tabId));
const createTab = Effect.fn("PreviewManager.createTab")(function* (
tabId: string,
defaults?: DesktopPreviewTabDefaults,
) {
return yield* withTabLifecycleLock(tabId, createTabUnlocked(tabId, defaults));
});

const closeTabUnlocked = Effect.fn("PreviewManager.closeTabUnlocked")(function* (tabId: string) {
Expand Down Expand Up @@ -3802,7 +3822,10 @@ export class PreviewManager extends Context.Service<
readonly setMainWindow: (window: BrowserWindow) => Effect.Effect<void, PreviewManagerError>;
readonly getBrowserSession: (scope?: string) => Effect.Effect<Session, PreviewManagerError>;
readonly isBrowserPartition: (partition: string) => boolean;
readonly createTab: (tabId: string) => Effect.Effect<PreviewTabState, PreviewManagerError>;
readonly createTab: (
tabId: string,
defaults?: DesktopPreviewTabDefaults,
) => Effect.Effect<PreviewTabState, PreviewManagerError>;
readonly closeTab: (tabId: string) => Effect.Effect<void, PreviewManagerError>;
readonly registerWebview: (
tabId: string,
Expand Down
4 changes: 4 additions & 0 deletions apps/desktop/src/settings/DesktopClientSettings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import * as DesktopEnvironment from "../app/DesktopEnvironment.ts";
import * as DesktopClientSettings from "./DesktopClientSettings.ts";

const clientSettings: ClientSettings = {
browserDefaultViewport: { _tag: "preset", width: 1024, height: 600, presetId: "nest-hub" },
browserDefaultZoomFactor: 1.25,
browserDefaultAppearance: "dark",
browserAutoShowFloatingPreview: false,
confirmQuit: true,
confirmThreadArchive: true,
confirmThreadDelete: false,
Expand Down
33 changes: 21 additions & 12 deletions apps/mobile/src/features/threads/PendingUserInputCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -257,14 +257,16 @@ export function PendingUserInputCard(props: PendingUserInputCardProps) {
<Text className="font-sans text-base leading-snug text-neutral-950 dark:text-neutral-50">
{question.question}
</Text>
<View className="flex-row flex-wrap gap-2.5">
<View className="gap-2">
{question.options.map((option) => {
const selected = isPendingUserInputOptionSelected(draft, option.label);
const description =
option.description !== option.label ? option.description : undefined;
return (
<Pressable
key={option.label}
className={cn(
"rounded-full border px-3 py-2.5 ",
"min-h-12 w-full rounded-2xl border px-3.5 py-3",
selected
? "border-blue-300/50 bg-blue-50 dark:border-blue-400/28 dark:bg-blue-400/14"
: "border-neutral-200 bg-white dark:border-white/6 dark:bg-neutral-950/70",
Expand All @@ -277,16 +279,23 @@ export function PendingUserInputCard(props: PendingUserInputCardProps) {
)
}
>
<Text
className={cn(
"font-t3-bold text-sm",
selected
? "text-sky-700 dark:text-sky-300"
: "text-neutral-600 dark:text-neutral-300",
)}
>
{option.label}
</Text>
<View className="min-w-0 flex-1 gap-0.5">
<Text
className={cn(
"font-t3-bold text-sm",
selected
? "text-sky-700 dark:text-sky-300"
: "text-neutral-700 dark:text-neutral-200",
)}
>
{option.label}
</Text>
{description ? (
<Text className="font-sans text-sm leading-5 text-neutral-500 dark:text-neutral-400">
{description}
</Text>
) : null}
</View>
</Pressable>
);
})}
Expand Down
6 changes: 4 additions & 2 deletions apps/mobile/src/features/threads/thread-list-v2-items.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,11 @@ export const ThreadListV2SnoozedShelfHeader = memo(function ThreadListV2SnoozedS
</Text>
<View className="h-px flex-1 bg-blue-500/20 dark:bg-blue-400/15" />
<SymbolView
name={props.expanded ? "chevron.up" : "chevron.down"}
name="chevron.down"
size={10}
tintColor={colorScheme === "dark" ? SNOOZE_ACCENT_DARK : SNOOZE_ACCENT_LIGHT}
type="monochrome"
style={{ transform: [{ rotate: props.expanded ? "180deg" : "0deg" }] }}
/>
</Pressable>
);
Expand Down Expand Up @@ -171,10 +172,11 @@ export const ThreadListV2SettledShelfHeader = memo(function ThreadListV2SettledS
</Text>
<View className="h-px flex-1 bg-border" />
<SymbolView
name={props.expanded ? "chevron.up" : "chevron.down"}
name="chevron.down"
size={10}
tintColor={mutedColor}
type="monochrome"
style={{ transform: [{ rotate: props.expanded ? "180deg" : "0deg" }] }}
/>
</Pressable>
);
Expand Down
1 change: 1 addition & 0 deletions apps/server/src/auth/RpcAuthorization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export const RPC_REQUIRED_SCOPES = {
[WS_METHODS.pullRequestsListStats]: AuthOrchestrationReadScope,
[WS_METHODS.pullRequestsDetail]: AuthOrchestrationReadScope,
[WS_METHODS.pullRequestsActivity]: AuthOrchestrationReadScope,
[WS_METHODS.pullRequestsThreadComments]: AuthOrchestrationReadScope,
[WS_METHODS.pullRequestsDiffFileContents]: AuthOrchestrationReadScope,
[WS_METHODS.pullRequestsRunAction]: AuthOrchestrationOperateScope,
[WS_METHODS.pullRequestsUpdate]: AuthOrchestrationOperateScope,
Expand Down
10 changes: 4 additions & 6 deletions apps/server/src/mcp/toolkits/preview/handlers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ import { describe, expect, it } from "vite-plus/test";
import { normalizePreviewOpenInput } from "./handlers.ts";

describe("normalizePreviewOpenInput", () => {
it("opens the inline preview and reuses the current tab by default", () => {
expect(normalizePreviewOpenInput({})).toEqual({
open: true,
reuseExistingTab: true,
show: true,
});
it("leaves an unstated visibility for the client preference to decide", () => {
// Filling `open` in here would outrank `browserAutoShowFloatingPreview`,
// which is desktop-local and cannot be read from the server.
expect(normalizePreviewOpenInput({})).toEqual({ reuseExistingTab: true });
});

it("preserves an explicit background-only opt-out", () => {
Expand Down
13 changes: 10 additions & 3 deletions apps/server/src/mcp/toolkits/preview/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,21 @@ import * as McpInvocationContext from "../../McpInvocationContext.ts";
import * as PreviewAutomationBroker from "../../PreviewAutomationBroker.ts";
import { PreviewSnapshotToolkit, PreviewStandardToolkit, PreviewToolkit } from "./tools.ts";

/**
* Collapses the `show` alias onto `open` and defaults tab reuse.
*
* Deliberately leaves an unstated `open` unstated. Whether a preview the agent
* said nothing about surfaces is the user's `browserAutoShowFloatingPreview`
* preference, which is desktop-local and unreadable from here — filling in
* `true` would silently override it for every `preview_open`.
*/
export function normalizePreviewOpenInput(
input: PreviewAutomationOpenInput,
): PreviewAutomationOpenInput {
const open = input.open ?? input.show ?? true;
const open = input.open ?? input.show;
return {
...input,
open,
show: open,
...(open === undefined ? {} : { open, show: open }),
reuseExistingTab: input.reuseExistingTab ?? true,
};
}
Expand Down
26 changes: 26 additions & 0 deletions apps/server/src/orchestration/ThreadBackgroundLiveness.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,32 @@ import { describe, expect, it } from "vite-plus/test";
import * as ThreadBackgroundLiveness from "./ThreadBackgroundLiveness.ts";

describe("ThreadBackgroundLiveness", () => {
it("does not let status-free progress restart an idle task", () => {
const liveness = ThreadBackgroundLiveness.make();
liveness.recordTaskLiveness({
threadId: "thread",
taskId: "task",
taskType: undefined,
status: undefined,
kind: "started",
});
liveness.recordTaskLiveness({
threadId: "thread",
taskId: "task",
taskType: undefined,
status: "idle",
kind: "updated",
});
liveness.recordTaskLiveness({
threadId: "thread",
taskId: "task",
taskType: undefined,
status: undefined,
kind: "progress",
});
expect(liveness.getThreadBackgroundLiveness("thread")).toBeNull();
});

it("agents present as working; monitors as monitoring; agents win", () => {
const liveness = ThreadBackgroundLiveness.make();
const threadId = "t-live-1";
Expand Down
13 changes: 13 additions & 0 deletions apps/server/src/orchestration/ThreadBackgroundLiveness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,19 @@ export function make(): ThreadBackgroundLivenessService["Service"] {
return;
}

// Status-free progress is a description tick, not a restart. A delayed
// progress event after idle must not put the task back in the live set
// (#7128).
if (input.kind === "progress" && input.status === undefined) {
const existing = stateByThreadId.get(input.threadId);
const stillLive =
existing !== undefined &&
(existing.agents.has(input.taskId) || existing.monitors.has(input.taskId));
if (!stillLive) {
return;
}
}

drop(input.threadId, input.taskId);
const state = stateFor(input.threadId);
const bucket =
Expand Down
14 changes: 11 additions & 3 deletions apps/server/src/preview/Manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
FILL_PREVIEW_VIEWPORT,
PreviewSessionLookupError,
type PreviewSessionSnapshot,
type PreviewViewportSetting,
} from "@t3tools/contracts";
import {
isPreviewUrlNormalizationError,
Expand Down Expand Up @@ -121,28 +122,30 @@ const buildLoadingSnapshot = (input: {
readonly tabId: string;
readonly url: string;
readonly title: string;
readonly viewport: PreviewViewportSetting;
readonly updatedAt: string;
}): PreviewSessionSnapshot => ({
threadId: input.threadId,
tabId: input.tabId,
navStatus: { _tag: "Loading", url: input.url, title: input.title },
canGoBack: false,
canGoForward: false,
viewport: FILL_PREVIEW_VIEWPORT,
viewport: input.viewport,
updatedAt: input.updatedAt,
});

const buildIdleSnapshot = (input: {
readonly threadId: string;
readonly tabId: string;
readonly viewport: PreviewViewportSetting;
readonly updatedAt: string;
}): PreviewSessionSnapshot => ({
threadId: input.threadId,
tabId: input.tabId,
navStatus: { _tag: "Idle" },
canGoBack: false,
canGoForward: false,
viewport: FILL_PREVIEW_VIEWPORT,
viewport: input.viewport,
updatedAt: input.updatedAt,
});

Expand Down Expand Up @@ -215,15 +218,20 @@ export const make = Effect.gen(function* PreviewManagerMake() {
function* (input) {
const tabId = newPreviewTabId();
const updatedAt = yield* currentIsoTimestamp;
// Clients with a configured default send the viewport up front so the
// session is born at the right size; older clients omit it and keep the
// historical fill-panel behaviour.
const viewport = input.viewport ?? FILL_PREVIEW_VIEWPORT;
const snapshot = input.url
? buildLoadingSnapshot({
threadId: input.threadId,
tabId,
url: yield* normalizeUrl(input.url),
title: "",
viewport,
updatedAt,
})
: buildIdleSnapshot({ threadId: input.threadId, tabId, updatedAt });
: buildIdleSnapshot({ threadId: input.threadId, tabId, viewport, updatedAt });
yield* SynchronizedRef.modifyEffect(stateRef, (state) =>
Effect.gen(function* () {
const revision = state.revision + 1;
Expand Down
Loading
Loading