Skip to content

Commit a4c51c2

Browse files
Merge remote-tracking branch 'origin/main' into l76-19533
2 parents 4e3ea1f + 4af6618 commit a4c51c2

131 files changed

Lines changed: 5018 additions & 520 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/desktop/src/backend/DesktopBackendPool.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ export const layer = Layer.effect(
180180
electronDialog
181181
.showErrorBox(
182182
"This T3 home is unavailable",
183-
"Another T3 Code server, such as the background service, is using this data directory. Stop that server and reopen T3 Code, or set a separate T3CODE_HOME and pair with the running server.",
183+
"Another T3 Code server, such as the background service, is using this data directory, or an older background service is set up for it. Stop that server or try `t3 update`. If the older launcher cannot update, run `t3 service uninstall` and optionally reinstall with `t3 service install` from a current CLI. Use `npx t3@latest` if `t3` is missing or outdated, and pass `--base-dir` with the service's T3 home to each command. Then reopen T3 Code. You can also set a separate T3CODE_HOME and pair with the running server.",
184184
)
185185
.pipe(Effect.andThen(electronApp.quit)),
186186
});

‎apps/desktop/src/ipc/DesktopIpcHandlers.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,11 @@ export const installDesktopIpcHandlers = Effect.fn("desktop.ipc.installHandlers"
166166
yield* ipc.handle(installCliCommand);
167167
yield* ipc.handle(uninstallCliCommand);
168168
for (const previewMethod of PreviewIpc.methods) {
169-
yield* ipc.handle(previewMethod);
169+
// Explicit types preserve the error/service union of these heterogeneous preview methods.
170+
yield* ipc.handle<
171+
Effect.Error<ReturnType<(typeof PreviewIpc.methods)[number]["handler"]>>,
172+
Effect.Services<ReturnType<(typeof PreviewIpc.methods)[number]["handler"]>>
173+
>(previewMethod);
170174
}
171175
yield* ipc.handle(PreviewIpc.listBrowserImportSources);
172176
yield* ipc.handle(PreviewIpc.importBrowserCookies);

‎apps/desktop/src/ipc/methods/preview.test.ts‎

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
DEFAULT_BROWSER_PROFILE_ID,
44
INCOGNITO_BROWSER_PROFILE_ID,
55
PreviewAutomationStatus,
6+
PreviewCaptureFailure,
67
} from "@t3tools/contracts";
78
import * as Cause from "effect/Cause";
89
import * as Effect from "effect/Effect";
@@ -14,6 +15,8 @@ import { beforeEach, describe, expect, it, vi } from "vite-plus/test";
1415
import * as PreviewManager from "../../preview/Manager.ts";
1516
import * as BrowserImport from "../../preview/BrowserImport/BrowserImport.ts";
1617
import * as PreviewIpc from "./preview.ts";
18+
import * as DesktopIpc from "../DesktopIpc.ts";
19+
import * as DesktopClientSettings from "../../settings/DesktopClientSettings.ts";
1720

1821
const { fromPartition } = vi.hoisted(() => ({
1922
fromPartition: vi.fn(() => {
@@ -33,7 +36,102 @@ vi.mock("electron", () => ({
3336
},
3437
}));
3538

39+
const decodeCaptureFailure = Schema.decodeUnknownEffect(PreviewCaptureFailure);
40+
3641
describe("preview IPC methods", () => {
42+
const invokeCapture = (
43+
method: typeof PreviewIpc.startRecording | typeof PreviewIpc.captureScreenshot,
44+
manager: Partial<PreviewManager.PreviewManager["Service"]>,
45+
) =>
46+
Effect.scoped(
47+
Effect.gen(function* () {
48+
let listener: DesktopIpc.DesktopIpcHandleListener | undefined;
49+
const ipc = DesktopIpc.make({
50+
removeHandler: vi.fn(),
51+
handle: (_channel, registered) => {
52+
listener = registered;
53+
},
54+
removeAllListeners: vi.fn(),
55+
on: vi.fn(),
56+
});
57+
yield* ipc.handle(method);
58+
return yield* Effect.promise(async () =>
59+
structuredClone(await listener!({ sender: { id: 7 } }, { tabId: "capture-tab" })),
60+
);
61+
}).pipe(
62+
Effect.provideService(
63+
PreviewManager.PreviewManager,
64+
manager as PreviewManager.PreviewManager["Service"],
65+
),
66+
Effect.provideService(DesktopClientSettings.DesktopClientSettings, {
67+
get: Effect.succeedNone,
68+
set: () => Effect.void,
69+
}),
70+
),
71+
);
72+
73+
effectIt.effect.each([
74+
{
75+
cause: new Error("Current display surface not available for capture"),
76+
reason: "capture-unavailable",
77+
guidance: ["target tab", "unlocked", "display is on", "window is restored"],
78+
},
79+
{
80+
cause: new Cause.TimeoutError(),
81+
reason: "capture-timeout",
82+
guidance: ["timed out during capture-page"],
83+
},
84+
{
85+
cause: new Error("Current display surface not available for capture: private page data"),
86+
reason: "capture-failed",
87+
guidance: ["Preview capture failed during capture-page"],
88+
},
89+
])(
90+
"transports a safe $reason screenshot diagnostic through registered IPC",
91+
({ cause, reason, guidance }) =>
92+
Effect.gen(function* () {
93+
const result = yield* invokeCapture(PreviewIpc.captureScreenshot, {
94+
captureScreenshot: (tabId) =>
95+
Effect.fail(
96+
new PreviewManager.PreviewOperationError({
97+
operation: "captureScreenshot.capturePage",
98+
tabId,
99+
artifactPath: "/private/capture.png",
100+
cause,
101+
}),
102+
),
103+
});
104+
expect(result).toEqual({
105+
_tag: "PreviewCaptureFailure",
106+
reason,
107+
stage: "capture-page",
108+
});
109+
const failure = yield* decodeCaptureFailure(result);
110+
for (const phrase of guidance) expect(failure.message).toContain(phrase);
111+
}),
112+
);
113+
114+
effectIt.effect("preserves recording arm failures without erasing successful void results", () =>
115+
Effect.gen(function* () {
116+
const result = yield* invokeCapture(PreviewIpc.startRecording, {
117+
startRecording: (tabId) =>
118+
Effect.fail(new PreviewManager.PreviewTabNotFoundError({ tabId })),
119+
});
120+
expect(result).toEqual({
121+
_tag: "PreviewCaptureFailure",
122+
reason: "renderer-unavailable",
123+
stage: "recording-start",
124+
});
125+
const failure = yield* decodeCaptureFailure(result);
126+
expect(failure.message).toContain("Reopen the preview tab");
127+
expect(
128+
yield* invokeCapture(PreviewIpc.startRecording, {
129+
startRecording: () => Effect.void,
130+
}),
131+
).toBeUndefined();
132+
}),
133+
);
134+
37135
beforeEach(() => {
38136
fromPartition.mockClear();
39137
});

‎apps/desktop/src/ipc/methods/preview.ts‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
DesktopPreviewTabInputSchema,
2020
DesktopPreviewWebviewConfigSchema,
2121
PreviewAnnotationSubmissionResultSchema,
22+
PreviewCaptureFailure,
2223
DEFAULT_BROWSER_PROFILE_ID,
2324
INCOGNITO_BROWSER_PROFILE_ID,
2425
PreviewForwardedShortcut,
@@ -32,6 +33,7 @@ import * as NodeURL from "node:url";
3233
import * as ElectronWindow from "../../electron/ElectronWindow.ts";
3334
import * as BrowserImport from "../../preview/BrowserImport/BrowserImport.ts";
3435
import * as PreviewManager from "../../preview/Manager.ts";
36+
import { normalizeCaptureFailure } from "../../preview/captureErrors.ts";
3537
import * as DesktopClientSettings from "../../settings/DesktopClientSettings.ts";
3638
import { PREVIEW_WEBVIEW_PREFERENCES } from "../../preview/WebviewPreferences.ts";
3739
import * as IpcChannels from "../channels.ts";
@@ -207,7 +209,8 @@ export const cancelPickElement = tabMethod(
207209
export const startRecording = DesktopIpc.makeIpcMethod({
208210
channel: IpcChannels.PREVIEW_RECORDING_START_CHANNEL,
209211
payload: DesktopPreviewTabInputSchema,
210-
result: Schema.Void,
212+
// Void encodes any value as undefined, so the tagged failure must be tried first.
213+
result: Schema.Union([PreviewCaptureFailure, Schema.Void]),
211214
handler: Effect.fn("desktop.ipc.preview.startRecording")(function* ({ tabId }) {
212215
const manager = yield* PreviewManager.PreviewManager;
213216
const store = yield* DesktopClientSettings.DesktopClientSettings;
@@ -216,7 +219,11 @@ export const startRecording = DesktopIpc.makeIpcMethod({
216219
showKeyPresses: value.browserRecordingShowKeyPresses,
217220
showMousePresses: value.browserRecordingShowMousePresses,
218221
}));
219-
yield* manager.startRecording(tabId, Option.getOrUndefined(options));
222+
return yield* manager
223+
.startRecording(tabId, Option.getOrUndefined(options))
224+
.pipe(
225+
Effect.catch((error) => Effect.succeed(normalizeCaptureFailure(error, "recording-start"))),
226+
);
220227
}),
221228
});
222229
export const stopRecording = tabMethod(
@@ -390,10 +397,12 @@ export const setAnnotationSendEnabled = DesktopIpc.makeIpcMethod({
390397
export const captureScreenshot = DesktopIpc.makeIpcMethod({
391398
channel: IpcChannels.PREVIEW_CAPTURE_SCREENSHOT_CHANNEL,
392399
payload: DesktopPreviewTabInputSchema,
393-
result: DesktopPreviewScreenshotArtifactSchema,
400+
result: Schema.Union([DesktopPreviewScreenshotArtifactSchema, PreviewCaptureFailure]),
394401
handler: Effect.fn("desktop.ipc.preview.captureScreenshot")(function* ({ tabId }) {
395402
const manager = yield* PreviewManager.PreviewManager;
396-
return yield* manager.captureScreenshot(tabId);
403+
return yield* manager
404+
.captureScreenshot(tabId)
405+
.pipe(Effect.catch((error) => Effect.succeed(normalizeCaptureFailure(error, "screenshot"))));
397406
}),
398407
});
399408

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { PreviewCaptureFailure } from "@t3tools/contracts";
2+
import * as Cause from "effect/Cause";
3+
import type { PreviewManagerError } from "./Manager.ts";
4+
5+
/** Classify before Electron replaces a rejected IPC Error with its message. */
6+
export function normalizeCaptureFailure(
7+
error: PreviewManagerError,
8+
stage: PreviewCaptureFailure["stage"],
9+
): PreviewCaptureFailure {
10+
let reason: PreviewCaptureFailure["reason"] = "capture-failed";
11+
switch (error._tag) {
12+
case "PreviewTabNotFoundError":
13+
case "PreviewWebContentsNotFoundError":
14+
case "PreviewMainWindowClosedError":
15+
reason = "renderer-unavailable";
16+
break;
17+
case "PreviewWebviewNotInitializedError":
18+
case "PreviewRecordingCaptureUnavailableError":
19+
reason = "capture-unavailable";
20+
break;
21+
case "PreviewRecordingArmConflictError":
22+
reason = "recording-conflict";
23+
break;
24+
case "PreviewOperationError":
25+
if (error.operation === "captureScreenshot.capturePage") {
26+
stage = "capture-page";
27+
if (
28+
error.cause instanceof Error &&
29+
error.cause.message === "Current display surface not available for capture"
30+
) {
31+
reason = "capture-unavailable";
32+
}
33+
}
34+
if (Cause.isTimeoutError(error.cause)) reason = "capture-timeout";
35+
break;
36+
}
37+
return new PreviewCaptureFailure({ reason, stage });
38+
}

‎apps/desktop/src/wsl/DesktopWslBackend.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ export const layer = Layer.effect(
136136
Ref.set(
137137
preflightErrorRef,
138138
Option.some(
139-
"Another T3 Code server is using this distro's T3 home. Stop it, or pair with it instead.",
139+
"Another T3 Code server is using this distro's T3 home, or an older background service is set up for it. Stop that server or pair with it, or try `t3 update` in the distro. If the older launcher cannot update, run `t3 service uninstall` and optionally reinstall with `t3 service install` from a current CLI in the distro. Use `npx t3@latest` if `t3` is missing or outdated, and pass `--base-dir` with the service's T3 home to each command.",
140140
),
141141
),
142142
),

‎apps/mobile/src/features/threads/threadListV2.test.ts‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { presentThreadShell } from "@t3tools/client-runtime/state/models";
22
import * as DateTime from "effect/DateTime";
3+
import * as Schema from "effect/Schema";
34
import { planPinnedMove } from "@t3tools/client-runtime/state/thread-sort";
45
import {
56
createPendingThreadOrder,
@@ -17,6 +18,7 @@ import {
1718
CommandId,
1819
EnvironmentId,
1920
MessageId,
21+
OrchestrationV2ThreadShell,
2022
ProjectId,
2123
ProviderInstanceId,
2224
RunId,
@@ -43,6 +45,7 @@ import {
4345
} from "./threadListV2";
4446

4547
const environmentId = EnvironmentId.make("environment-1");
48+
const decodeThreadShell = Schema.decodeUnknownSync(OrchestrationV2ThreadShell);
4649

4750
function makeThread(
4851
input: Partial<EnvironmentThreadShell> & Pick<EnvironmentThreadShell, "id" | "title">,
@@ -111,6 +114,30 @@ describe("resolveThreadListV2SnoozeMenuSelection", () => {
111114
});
112115

113116
describe("resolveThreadListV2Status", () => {
117+
it("presents decoded thread waits as Waiting while preserving requests and older servers", () => {
118+
const raw = makeRawThreadShell({
119+
status: "running",
120+
activeRunId: RunId.make("run-wait"),
121+
latestRunId: RunId.make("run-wait"),
122+
});
123+
const present = (shell: unknown) => presentThreadShell(environmentId, decodeThreadShell(shell));
124+
125+
expect(resolveThreadListV2Status(present(raw))).toBe("working");
126+
const blocked = present({ ...raw, blockedOnThreadWait: true });
127+
expect(
128+
resolveThreadListV2Status({
129+
...blocked,
130+
hasPendingApprovals: true,
131+
hasPendingUserInput: true,
132+
}),
133+
).toBe("approval");
134+
expect(resolveThreadListV2Status({ ...blocked, hasPendingUserInput: true })).toBe("input");
135+
expect(resolveThreadListV2Status(blocked)).toBe("waiting");
136+
expect(resolveThreadListV2Status(present({ ...raw, blockedOnThreadWait: false }))).toBe(
137+
"working",
138+
);
139+
});
140+
114141
it("distinguishes usage limits from ordinary failures and clears the label after recovery", () => {
115142
const thread = makeThread({
116143
id: ThreadId.make("limited"),

‎apps/mobile/src/features/threads/threadListV2.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,11 @@ export function threadHasUnseenCompletion(
154154
export function resolveThreadListV2Status(
155155
thread: Pick<
156156
EnvironmentThreadShell,
157-
"hasPendingApprovals" | "hasPendingUserInput" | "pendingSubagentRequest" | "runtime"
157+
| "hasPendingApprovals"
158+
| "hasPendingUserInput"
159+
| "pendingSubagentRequest"
160+
| "runtime"
161+
| "blockedOnThreadWait"
158162
>,
159163
): ThreadListV2Status {
160164
if (thread.hasPendingApprovals || thread.pendingSubagentRequest === "approval") {
@@ -163,6 +167,9 @@ export function resolveThreadListV2Status(
163167
if (thread.hasPendingUserInput || thread.pendingSubagentRequest === "user_input") {
164168
return "input";
165169
}
170+
if (thread.runtime?.status === "running" && thread.blockedOnThreadWait === true) {
171+
return "waiting";
172+
}
166173
if (
167174
thread.runtime !== null &&
168175
["preparing", "queued", "starting", "running", "waiting"].includes(thread.runtime.status)

0 commit comments

Comments
 (0)