Skip to content

Commit a80dbed

Browse files
committed
chore: merge main into composer reset fix
2 parents 36aae63 + 15707a8 commit a80dbed

71 files changed

Lines changed: 1721 additions & 293 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.

‎.agents/skills/test-t3-app/SKILL.md‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ description: Test T3 Code's web and desktop UI through its built-in Browser pane
55

66
# Test T3 web and desktop
77

8-
Use T3's built-in Browser panel for verification. If its tools are absent or
9-
the panel reports unavailable, explain the blocker and stop verification.
10-
Do not install or switch to another automation system. For native mobile
11-
testing, use [test-t3-mobile](../test-t3-mobile/SKILL.md).
8+
Use T3's built-in Browser panel for verification. Follow the recovery steps
9+
below before declaring it unavailable. Do not install or switch to another
10+
automation system. For native mobile testing, use
11+
[test-t3-mobile](../test-t3-mobile/SKILL.md).
1212

1313
## Start the app
1414

@@ -36,8 +36,13 @@ model, such as Haiku for Claude or Luna for Codex.
3636

3737
## Use the Browser panel
3838

39-
Call `preview_status`, then `preview_open` if the Browser panel is
40-
closed. Navigate to the complete startup pairing URL once with
39+
Call `preview_status`. If no tab can be automated, call `preview_open`, including
40+
when status reports `available: false` or `tabId: null`. Status can report
41+
unavailable simply because no tab exists yet; opening a tab needs no user action.
42+
Stop verification and explain the blocker only if the tools are absent or
43+
`preview_open` reports unavailable or fails.
44+
45+
Navigate to the complete startup pairing URL once with
4146
`preview_navigate`, then use `preview_snapshot` and T3's interaction tools.
4247
If the token was consumed or expired, run `node apps/server/src/bin.ts pair`
4348
for a fresh one. Keep using the same tab.

‎apps/desktop/src/app/DesktopStartupRecovery.test.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,19 @@ describe("resolveStartupRecoveryOffer", () => {
7474
).toEqual({ _tag: "Reinstall", version: "0.1.2" });
7575
});
7676

77+
it("blames the managed policy unless a newer version can read it", () => {
78+
expect(
79+
resolveStartupRecoveryOffer(
80+
updateState({ status: "available", availableVersion: "0.1.4" }),
81+
"0.1.2",
82+
true,
83+
),
84+
).toEqual({ _tag: "Update", version: "0.1.4" });
85+
expect(
86+
resolveStartupRecoveryOffer(updateState({ status: "up-to-date" }), "0.1.2", true),
87+
).toEqual({ _tag: "ManagedPolicy" });
88+
});
89+
7790
it("falls back to the releases page when this version never started", () => {
7891
expect(resolveStartupRecoveryOffer(updateState({ status: "disabled" }), "0.1.3")).toEqual({
7992
_tag: "Releases",
@@ -168,6 +181,7 @@ it.effect.each([
168181
yield* SubscriptionRef.set(state.primaryBackendStartup, {
169182
_tag: "Failing",
170183
reason: "Server failed before readiness",
184+
managedPolicy: false,
171185
output: "Failure details",
172186
});
173187
yield* Deferred.await(checked);

‎apps/desktop/src/app/DesktopStartupRecovery.ts‎

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ export type StartupRecoveryOffer =
3232
| { readonly _tag: "Update"; readonly version: string }
3333
| { readonly _tag: "Downloading"; readonly version: string; readonly percent: number | null }
3434
| { readonly _tag: "Reinstall"; readonly version: string }
35-
| { readonly _tag: "Releases" };
35+
| { readonly _tag: "Releases" }
36+
| { readonly _tag: "ManagedPolicy" };
3637

3738
const STARTUP_RECOVERY_ACTIONS = ["update", "reinstall", "releases", "copy", "quit"] as const;
3839
type StartupRecoveryAction = (typeof STARTUP_RECOVERY_ACTIONS)[number];
@@ -41,6 +42,7 @@ type StartupRecoveryAction = (typeof STARTUP_RECOVERY_ACTIONS)[number];
4142
export function resolveStartupRecoveryOffer(
4243
update: DesktopUpdateState,
4344
lastStartedVersion: string | null,
45+
managedPolicy = false,
4446
): StartupRecoveryOffer {
4547
if (update.status === "downloading" && update.availableVersion !== null) {
4648
return {
@@ -55,6 +57,8 @@ export function resolveStartupRecoveryOffer(
5557
if (updateVersion !== null && updateVersion !== update.notAppliedVersion) {
5658
return { _tag: "Update", version: updateVersion };
5759
}
60+
// A newer release can know a key this one refuses; an older one or the releases page cannot help.
61+
if (managedPolicy) return { _tag: "ManagedPolicy" };
5862
if (update.enabled && (update.status === "idle" || update.status === "checking")) {
5963
return { _tag: "Checking" };
6064
}
@@ -98,6 +102,11 @@ function describeOffer(offer: StartupRecoveryOffer): { text: string; action: str
98102
text: "Get a different version from the releases page.",
99103
action: actionLink("releases", "Open releases", true),
100104
};
105+
case "ManagedPolicy":
106+
return {
107+
text: "Your organization's managed policy stopped T3 Code from starting. Send the details below to your IT administrator.",
108+
action: "",
109+
};
101110
}
102111
}
103112

@@ -171,8 +180,14 @@ export const listen: Effect.Effect<
171180
const { latest, changes: updateChanges } = yield* updates.subscribe;
172181
const updateStateRef = yield* Ref.make(latest);
173182

174-
const offer = Ref.get(updateStateRef).pipe(
175-
Effect.map((state) => resolveStartupRecoveryOffer(state, lastStartedVersion)),
183+
const offer = Effect.all([Ref.get(updateStateRef), Ref.get(failureRef)]).pipe(
184+
Effect.map(([state, failure]) =>
185+
resolveStartupRecoveryOffer(
186+
state,
187+
lastStartedVersion,
188+
Option.exists(failure, ({ managedPolicy }) => managedPolicy),
189+
),
190+
),
176191
);
177192

178193
const render = Effect.gen(function* () {
@@ -332,7 +347,8 @@ export const listen: Effect.Effect<
332347
}
333348
if (startup._tag !== "Failing") return;
334349
if (Option.isSome(yield* Ref.get(failureRef))) return;
335-
yield* Ref.set(failureRef, Option.some({ reason: startup.reason, output: startup.output }));
350+
const { _tag, ...failure } = startup;
351+
yield* Ref.set(failureRef, Option.some(failure));
336352
// The backend manager already logs each failure's reason.
337353
yield* logWarning("primary backend failing to start");
338354
yield* show();

‎apps/desktop/src/backend/DesktopBackendManager.test.ts‎

Lines changed: 54 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
SERVER_EXIT_CODE_MANAGED_POLICY,
23
SERVER_EXIT_CODE_STATE_DIR_OWNED,
34
DesktopBackendBootstrap,
45
type DesktopBackendBootstrap as DesktopBackendBootstrapValue,
@@ -623,56 +624,63 @@ describe("DesktopBackendManager", () => {
623624
),
624625
);
625626

626-
it.effect("reports a crash loop with the server output on the third restart", () =>
627-
Effect.scoped(
628-
Effect.gen(function* () {
629-
const message = "Error: Cannot find module 'zod/v4' in /Users/René";
630-
let exitCount = 0;
631-
const firstExit = yield* Deferred.make<void>();
632-
const reports = yield* Queue.unbounded<{
633-
readonly exitCount: number;
634-
readonly failure: DesktopBackendManager.BackendStartupFailure;
635-
}>();
636-
const instance = yield* makeTestInstance({
637-
spawnerLayer: Layer.succeed(
638-
ChildProcessSpawner.ChildProcessSpawner,
639-
ChildProcessSpawner.make(() =>
640-
Effect.succeed(
641-
makeProcess({
642-
// "é" split across chunks must not decode as U+FFFD, and the 4,000-char cut
643-
// lands inside the emoji's surrogate pair.
644-
stderr: Stream.make(
645-
new TextEncoder().encode(
646-
`😀${"x".repeat(3_999 - message.length)}${message.slice(0, -1)}`,
627+
// A policy refusal is reported on the first exit, since retrying cannot fix it.
628+
it.effect.each([
629+
{ code: 1, exits: 3, managedPolicy: false },
630+
{ code: SERVER_EXIT_CODE_MANAGED_POLICY, exits: 1, managedPolicy: true },
631+
])(
632+
"reports exit $code with the server output after $exits exits",
633+
({ code, exits, managedPolicy }) =>
634+
Effect.scoped(
635+
Effect.gen(function* () {
636+
const message = "Error: Cannot find module 'zod/v4' in /Users/René";
637+
let exitCount = 0;
638+
const firstExit = yield* Deferred.make<void>();
639+
const reports = yield* Queue.unbounded<{
640+
readonly exitCount: number;
641+
readonly failure: DesktopBackendManager.BackendStartupFailure;
642+
}>();
643+
const instance = yield* makeTestInstance({
644+
spawnerLayer: Layer.succeed(
645+
ChildProcessSpawner.ChildProcessSpawner,
646+
ChildProcessSpawner.make(() =>
647+
Effect.succeed(
648+
makeProcess({
649+
// "é" split across chunks must not decode as U+FFFD, and the 4,000-char cut
650+
// lands inside the emoji's surrogate pair.
651+
stderr: Stream.make(
652+
new TextEncoder().encode(
653+
`😀${"x".repeat(3_999 - message.length)}${message.slice(0, -1)}`,
654+
),
655+
new Uint8Array([0xc3]),
656+
new Uint8Array([0xa9]),
647657
),
648-
new Uint8Array([0xc3]),
649-
new Uint8Array([0xa9]),
650-
),
651-
exitCode: Effect.succeed(ChildProcessSpawner.ExitCode(1)),
652-
}),
658+
exitCode: Effect.succeed(ChildProcessSpawner.ExitCode(code)),
659+
}),
660+
),
653661
),
654662
),
655-
),
656-
httpClientLayer: layerHttpClient(() => Effect.never),
657-
backendOutputLog: {
658-
persistFailure: () => {
659-
exitCount += 1;
660-
return Deferred.succeed(firstExit, undefined).pipe(Effect.asVoid);
663+
httpClientLayer: layerHttpClient(() => Effect.never),
664+
backendOutputLog: {
665+
persistFailure: () => {
666+
exitCount += 1;
667+
return Deferred.succeed(firstExit, undefined).pipe(Effect.asVoid);
668+
},
661669
},
662-
},
663-
onStartupFailure: (failure) =>
664-
Queue.offer(reports, { exitCount, failure }).pipe(Effect.asVoid),
665-
});
666-
yield* instance.start;
667-
yield* Deferred.await(firstExit);
668-
yield* TestClock.adjust(Duration.minutes(1));
669-
const { exitCount: exitsWhenReported, failure } = yield* Queue.take(reports);
670-
assert.equal(exitsWhenReported, 3);
671-
assert.equal(failure.reason, "The server could not start (code=1).");
672-
assert.isTrue(failure.output.endsWith(message));
673-
assert.isTrue(failure.output.isWellFormed());
674-
}).pipe(Effect.provide(TestClock.layer())),
675-
),
670+
onStartupFailure: (failure) =>
671+
Queue.offer(reports, { exitCount, failure }).pipe(Effect.asVoid),
672+
});
673+
yield* instance.start;
674+
yield* Deferred.await(firstExit);
675+
yield* TestClock.adjust(Duration.minutes(1));
676+
const { exitCount: exitsWhenReported, failure } = yield* Queue.take(reports);
677+
assert.equal(exitsWhenReported, exits);
678+
assert.equal(failure.reason, `The server could not start (code=${code}).`);
679+
assert.equal(failure.managedPolicy, managedPolicy);
680+
assert.isTrue(failure.output.endsWith(message));
681+
assert.isTrue(failure.output.isWellFormed());
682+
}).pipe(Effect.provide(TestClock.layer())),
683+
),
676684
);
677685

678686
it.effect("waits out a slow startup and reports one that never becomes ready", () =>

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { HttpClient } from "effect/http";
1717
import { ChildProcess, ChildProcessSpawner } from "effect/process";
1818

1919
import {
20+
SERVER_EXIT_CODE_MANAGED_POLICY,
2021
SERVER_EXIT_CODE_STATE_DIR_OWNED,
2122
DesktopBackendBootstrap,
2223
type DesktopBackendBootstrap as DesktopBackendBootstrapValue,
@@ -223,6 +224,8 @@ export const PRIMARY_INSTANCE_ID: BackendInstanceId = BackendInstanceId(
223224

224225
export interface BackendStartupFailure {
225226
readonly reason: string;
227+
/** The server refused to start under this machine's managed policy. */
228+
readonly managedPolicy: boolean;
226229
/** Tail of the last run's stdout and stderr. */
227230
readonly output: string;
228231
}
@@ -635,9 +638,11 @@ export const makeBackendInstance = Effect.fn("makeBackendInstance")(function* (
635638
// One streaming decoder per stream keeps UTF-8 characters split across chunks intact.
636639
const makeOutputDecoders = () => ({ stdout: new TextDecoder(), stderr: new TextDecoder() });
637640
let outputDecoders = makeOutputDecoders();
638-
const reportStartupFailure = (reason: string) =>
641+
const reportStartupFailure = (reason: string, managedPolicy = false) =>
639642
Ref.get(outputTail).pipe(
640-
Effect.flatMap((output) => spec.onStartupFailure?.({ reason, output }) ?? Effect.void),
643+
Effect.flatMap(
644+
(output) => spec.onStartupFailure?.({ reason, managedPolicy, output }) ?? Effect.void,
645+
),
641646
);
642647

643648
const { logWarning: logInstanceWarning, logError: logInstanceError } =
@@ -880,7 +885,7 @@ export const makeBackendInstance = Effect.fn("makeBackendInstance")(function* (
880885
yield* (spec.onStateDirOwned?.() ?? Effect.void).pipe(Effect.ignore);
881886
return;
882887
}
883-
yield* scheduleRestart(reason);
888+
yield* scheduleRestart(reason, exitCode);
884889
}
885890
}),
886891
);
@@ -980,6 +985,7 @@ export const makeBackendInstance = Effect.fn("makeBackendInstance")(function* (
980985

981986
const scheduleRestart = Effect.fn("desktop.backendInstance.scheduleRestart")(function* (
982987
reason: string,
988+
exitCode?: number,
983989
) {
984990
const scheduled = yield* SubscriptionRef.modify(state, (latest) => {
985991
if (!latest.desiredRunning || Option.isSome(latest.restartFiber)) {
@@ -1003,8 +1009,10 @@ export const makeBackendInstance = Effect.fn("makeBackendInstance")(function* (
10031009
reason,
10041010
delayMs: Duration.toMillis(delay),
10051011
});
1006-
if (attempt >= STARTUP_FAILURE_RESTART_ATTEMPTS) {
1007-
yield* reportStartupFailure(`The server could not start (${reason}).`);
1012+
// Retrying cannot fix a policy refusal, so say so at once; retries still pick up a fix.
1013+
const managedPolicy = exitCode === SERVER_EXIT_CODE_MANAGED_POLICY;
1014+
if (managedPolicy || attempt >= STARTUP_FAILURE_RESTART_ATTEMPTS) {
1015+
yield* reportStartupFailure(`The server could not start (${reason}).`, managedPolicy);
10081016
}
10091017
const restartFiber = yield* Effect.forkIn(
10101018
Effect.sleep(delay).pipe(

‎apps/desktop/src/preview/Manager.test.ts‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,33 @@ describe("PreviewManager", () => {
615615
),
616616
);
617617

618+
effectIt.effect.each([
619+
["darwin", true, false, true],
620+
["darwin", false, true, false],
621+
["linux", false, true, true],
622+
["win32", true, false, false],
623+
] as const)(
624+
"reloads the preview only on the platform refresh chord: %s meta=%s ctrl=%s",
625+
([platform, meta, control, expected]) =>
626+
withManager(
627+
(manager) =>
628+
Effect.gen(function* () {
629+
const preview = makeFaviconWebContents();
630+
fromId.mockReturnValue(preview.webContents);
631+
yield* manager.createTab("tab_refresh");
632+
yield* manager.registerWebview("tab_refresh", 42);
633+
const preventDefault = vi.fn();
634+
preview.listeners.get("before-input-event")!(
635+
{ preventDefault } as never,
636+
{ type: "keyDown", key: "r", meta, control, shift: false, alt: false } as never,
637+
);
638+
expect(preventDefault).toHaveBeenCalledTimes(expected ? 1 : 0);
639+
expect(preview.reload).toHaveBeenCalledTimes(expected ? 1 : 0);
640+
}),
641+
platform,
642+
),
643+
);
644+
618645
effectIt.effect("keeps editing and forwarded shortcuts in whichever tab holds focus", () =>
619646
withManager((manager) =>
620647
Effect.gen(function* () {

‎apps/desktop/src/preview/Manager.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -464,10 +464,10 @@ export const previewWindowOpenAction = (details: {
464464
: "navigate";
465465
};
466466

467-
const isPreviewRefreshShortcut = (input: Electron.Input): boolean =>
467+
const isPreviewRefreshShortcut = (input: Electron.Input, platform: NodeJS.Platform): boolean =>
468468
input.type === "keyDown" &&
469469
input.key.toLowerCase() === "r" &&
470-
(input.meta || input.control) &&
470+
(platform === "darwin" ? input.meta && !input.control : input.control && !input.meta) &&
471471
!input.shift &&
472472
!input.alt;
473473

@@ -1488,7 +1488,7 @@ const makeNativeOperations = Effect.fn("PreviewManager.makeOperations")(function
14881488
}
14891489
return;
14901490
}
1491-
if (isPreviewRefreshShortcut(input)) {
1491+
if (isPreviewRefreshShortcut(input, hostPlatform)) {
14921492
event.preventDefault();
14931493
runFork(
14941494
attempt({ operation: "shortcut.refresh", tabId, webContentsId: wc.id }, () =>

0 commit comments

Comments
 (0)