Skip to content

Commit 47bff26

Browse files
Merge branch 'main' into fix/subagent-result-message-delivery
2 parents 4a5d56a + a9af48a commit 47bff26

557 files changed

Lines changed: 25578 additions & 3163 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.

‎.github/workflows/cursor-hygiene-webhook.yml‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ name: Forward to Cursor hygiene
33
on:
44
push:
55
branches: [main]
6-
pull_request:
6+
# Use trusted workflow code and repository secrets for fork PRs.
7+
# Keep this job payload-only: never check out or run PR code.
8+
pull_request_target:
79
types: [opened, reopened, ready_for_review]
810
issues:
911
types: [opened, closed, reopened]
@@ -34,7 +36,7 @@ jobs:
3436
--output /dev/null --write-out '%{http_code}' \
3537
-H "Authorization: $AUTH" \
3638
-H "Content-Type: application/json" \
37-
-H "X-GitHub-Event: ${{ github.event_name }}" \
39+
-H "X-GitHub-Event: ${{ github.event_name == 'pull_request_target' && 'pull_request' || github.event_name }}" \
3840
-H "X-GitHub-Delivery: ${{ github.run_id }}-${{ github.run_attempt }}" \
3941
--data-binary @"${{ github.event_path }}") || curl_status=$?
4042
if [ "$curl_status" -eq 0 ]; then

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,7 @@ const bootstrap = Effect.gen(function* () {
239239
}
240240

241241
if (!(yield* Ref.get(state.quitting))) {
242-
if (settings.wslOnly === true && settings.wslBackendEnabled === true) {
243-
yield* desktopWindow.showConnectingSplash;
244-
}
242+
yield* desktopWindow.showConnectingSplash;
245243
yield* primaryBackend.start;
246244
yield* logBootstrapInfo("bootstrap backend start requested");
247245
yield* appActivation.start.pipe(

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

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// @effect-diagnostics nodeBuiltinImport:off globalFetchInEffect:off - Hosted handoff test uses a real localhost listener without an OpenAI account.
22
import * as NodeHttp from "node:http";
3-
import * as NodePath from "@effect/platform-node/NodePath";
3+
import * as NodePath from "node:path";
4+
import * as PlatformNodePath from "@effect/platform-node/NodePath";
45
import { codexAuthHandoffUrl, readCodexAuthDelivery } from "@t3tools/shared/codexAuthHandoff";
56
import { EnvironmentId, ProviderInstanceId } from "@t3tools/contracts";
67
import * as HostProcess from "@t3tools/shared/HostProcess";
@@ -59,11 +60,15 @@ const layerDesktopClerk = (
5960
copyText: () => Effect.void,
6061
},
6162
listeners = new Map<string, (...args: unknown[]) => void>(),
63+
isPackaged = false,
6264
) => {
6365
const environment = DesktopEnvironment.DesktopEnvironment.of({
6466
stateDir: "/tmp/t3-state",
6567
isDevelopment,
6668
appDataDirectory: "/tmp/app-data",
69+
isPackaged,
70+
dirname: platform === "win32" ? String.raw`C:\T3 Code\dist-electron` : "/tmp/dist-electron",
71+
path: platform === "win32" ? NodePath.win32 : NodePath.posix,
6772
platform,
6873
} as unknown as DesktopEnvironment.DesktopEnvironment["Service"]);
6974

@@ -95,7 +100,7 @@ const layerDesktopClerk = (
95100
return DesktopClerk.layer.pipe(
96101
Layer.provide(
97102
Layer.mergeAll(
98-
NodePath.layerPosix,
103+
PlatformNodePath.layerPosix,
99104
Layer.succeed(DesktopEnvironment.DesktopEnvironment, environment),
100105
Layer.succeed(ElectronApp.ElectronApp, electronApp),
101106
Layer.succeed(ElectronShell.ElectronShell, shell),
@@ -112,6 +117,67 @@ describe("DesktopClerk", () => {
112117
storageMock.mockReset();
113118
});
114119

120+
it.effect.each([
121+
{ platform: "win32", isPackaged: false, isDevelopment: false, registers: true },
122+
{ platform: "win32", isPackaged: false, isDevelopment: true, registers: false },
123+
{ platform: "win32", isPackaged: true, isDevelopment: false, registers: false },
124+
{ platform: "darwin", isPackaged: false, isDevelopment: false, registers: false },
125+
{ platform: "linux", isPackaged: false, isDevelopment: false, registers: false },
126+
] as const)(
127+
"registers an entry point only for unpackaged non-development Windows ($platform, packaged=$isPackaged, development=$isDevelopment)",
128+
({ platform, isPackaged, isDevelopment, registers }) => {
129+
const events: string[] = [];
130+
storageMock.mockReturnValue(storageAdapter);
131+
createClerkBridgeMock.mockImplementation(() => {
132+
events.push("bridge");
133+
return { cleanup: vi.fn() };
134+
});
135+
const setAsDefaultProtocolClient = vi.fn(() =>
136+
Effect.sync(() => {
137+
events.push("register");
138+
return true;
139+
}),
140+
);
141+
const electronApp = {
142+
on: () => Effect.void,
143+
setAsDefaultProtocolClient,
144+
} as unknown as ElectronApp.ElectronApp["Service"];
145+
146+
return Effect.gen(function* () {
147+
const clerk = yield* DesktopClerk.DesktopClerk;
148+
yield* clerk.configure;
149+
150+
assert.deepEqual(
151+
setAsDefaultProtocolClient.mock.calls,
152+
registers
153+
? [["t3code", process.execPath, [String.raw`C:\T3 Code\dist-electron\main.cjs`]]]
154+
: [],
155+
);
156+
assert.deepEqual(events, registers ? ["bridge", "register"] : ["bridge"]);
157+
}).pipe(
158+
Effect.scoped,
159+
Effect.provide(
160+
layerDesktopClerk(
161+
isDevelopment,
162+
[],
163+
platform,
164+
undefined,
165+
undefined,
166+
undefined,
167+
isPackaged,
168+
),
169+
),
170+
Effect.provideService(ElectronApp.ElectronApp, electronApp),
171+
Effect.provideService(
172+
ElectronWindow.ElectronWindow,
173+
{} as ElectronWindow.ElectronWindow["Service"],
174+
),
175+
Effect.provideService(DesktopWebLinks.DesktopWebLinks, ignoreWebLinks),
176+
Effect.provideService(HostProcess.Arguments, ["electron"]),
177+
);
178+
},
179+
);
180+
115181
it.effect("acquires and releases the SDK bridge with the layer", () => {
116182
const cleanup = vi.fn();
117183
const events: string[] = [];

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,20 @@ export const make = Effect.gen(function* () {
151151
const context = yield* Effect.context<ElectronWindow.ElectronWindow>();
152152
const runPromise = Effect.runPromiseWith(context);
153153

154+
// Clerk's bare scheme registration omits the app entry on unpackaged Windows.
155+
// Development callbacks also need dev server environment this command cannot restore.
156+
if (
157+
!environment.isPackaged &&
158+
!environment.isDevelopment &&
159+
environment.platform === "win32"
160+
) {
161+
yield* electronApp.setAsDefaultProtocolClient(
162+
ElectronProtocol.getDesktopScheme(environment.isDevelopment),
163+
process.execPath,
164+
[environment.path.join(environment.dirname, "main.cjs")],
165+
);
166+
}
167+
154168
const startProviderAuthHandoff = (value: string | undefined) => {
155169
if (!value) return false;
156170
const request = readCodexAuthHandoff(value, environment.isDevelopment);

‎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/electron/ElectronShell.test.ts‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,12 @@ describe("ElectronShell", () => {
7878

7979
const electronShell = yield* ElectronShell.ElectronShell;
8080
const result = yield* electronShell.openExternal(
81-
"vscode://vscode-remote/ssh-remote+example.com/home/user/project",
81+
"vscode://vscode-remote/ssh-remote+user%40example.com/home/user/project",
8282
);
8383

8484
assert.equal(result, true);
8585
assert.deepEqual(openExternalMock.mock.calls, [
86-
["vscode://vscode-remote/ssh-remote+example.com/home/user/project"],
86+
["vscode://vscode-remote/ssh-remote+user%40example.com/home/user/project"],
8787
]);
8888
}).pipe(Effect.provide(ElectronShell.layer)),
8989
);
@@ -94,13 +94,13 @@ describe("ElectronShell", () => {
9494

9595
const electronShell = yield* ElectronShell.ElectronShell;
9696
const results = yield* Effect.all([
97-
electronShell.openExternal("zed://ssh/example.com/home/user/project"),
97+
electronShell.openExternal("zed://ssh/user@example.com/home/user/project"),
9898
electronShell.openExternal("zed://ssh/example.com/"),
9999
]);
100100

101101
assert.deepEqual(results, [true, true]);
102102
assert.deepEqual(openExternalMock.mock.calls, [
103-
["zed://ssh/example.com/home/user/project"],
103+
["zed://ssh/user@example.com/home/user/project"],
104104
["zed://ssh/example.com/"],
105105
]);
106106
}).pipe(Effect.provide(ElectronShell.layer)),
@@ -111,7 +111,7 @@ describe("ElectronShell", () => {
111111
openExternalMock.mockResolvedValue(undefined);
112112

113113
const url =
114-
"jetbrains://gateway/ssh/environment?h=example.com&launchIde=true&ideHint=IU&projectHint=%2Fhome%2Fuser%2Fproject";
114+
"jetbrains://gateway/ssh/environment?h=example.com&launchIde=true&ideHint=IU&projectHint=%2Fhome%2Fuser%2Fproject&u=user";
115115
const electronShell = yield* ElectronShell.ElectronShell;
116116
const result = yield* electronShell.openExternal(url);
117117

@@ -150,7 +150,7 @@ describe("ElectronShell", () => {
150150
electronShell.openExternal(
151151
"vscode://:secret@vscode-remote/ssh-remote+example.com/home/user/project",
152152
),
153-
electronShell.openExternal("zed://ssh/[email protected]/home/user/project"),
153+
electronShell.openExternal("zed://ssh/user:secret@example.com/home/user/project"),
154154
electronShell.openExternal("jetbrains://user@gateway/ssh/environment?h=example.com"),
155155
]);
156156

‎apps/desktop/src/electron/ElectronShell.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ const REMOTE_EDITOR_PROTOCOLS = new Set(
2222
}),
2323
);
2424

25-
// Zed's host sits in the first path segment, so it needs its own userinfo ban.
26-
const ZED_SSH_PATHNAME = /^\/[^/@:]+\/.*$/;
25+
// Zed embeds [user@]host in the path; reject passwords and ports there.
26+
const ZED_SSH_PATHNAME = /^\/(?:[^/@:]+@)?[^/@:]+\/.*$/;
2727

2828
const isRemoteEditorUrl = (url: URL) =>
2929
REMOTE_EDITOR_PROTOCOLS.has(url.protocol) &&

‎apps/desktop/src/electron/ElectronUpdater.test.ts‎

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { assert, describe, it } from "@effect/vitest";
22
import * as Effect from "effect/Effect";
3+
import type { VerifyUpdateCodeSignature } from "electron-updater";
34
import { beforeEach, vi } from "vite-plus/test";
45

56
const { autoUpdaterMock } = vi.hoisted(() => ({
@@ -13,6 +14,8 @@ const { autoUpdaterMock } = vi.hoisted(() => ({
1314
fullChangelog: false,
1415
checkForUpdates: vi.fn(() => Promise.resolve(null)),
1516
downloadUpdate: vi.fn(() => Promise.resolve([])),
17+
logger: { info: vi.fn(), warn: vi.fn(), error: vi.fn() },
18+
verifyUpdateCodeSignature: undefined as VerifyUpdateCodeSignature | undefined,
1619
on: vi.fn(),
1720
quitAndInstall: vi.fn(),
1821
removeListener: vi.fn(),
@@ -43,6 +46,7 @@ describe("ElectronUpdater", () => {
4346
autoUpdaterMock.quitAndInstall.mockClear();
4447
autoUpdaterMock.removeListener.mockClear();
4548
autoUpdaterMock.setFeedURL.mockClear();
49+
autoUpdaterMock.verifyUpdateCodeSignature = undefined;
4650
});
4751

4852
it.effect("scopes updater event listeners", () =>
@@ -136,4 +140,84 @@ describe("ElectronUpdater", () => {
136140
assert.deepEqual(autoUpdaterMock.quitAndInstall.mock.calls, [[true, false]]);
137141
}).pipe(Effect.provide(ElectronUpdater.layer)),
138142
);
143+
144+
describe("Windows update signature check", () => {
145+
const publisherNames = ["T3 Tools Inc"];
146+
const installerPath = "C:\\updater\\pending\\temp-T3-Code-x64.exe";
147+
// execFile marks the error killed when the verifier exceeds its 20-second timeout.
148+
const timedOut = () =>
149+
Object.assign(new Error("Command failed: powershell.exe"), { killed: true });
150+
151+
const downloadVerifyingSignature = () => {
152+
autoUpdaterMock.downloadUpdate.mockImplementationOnce(async () => {
153+
const rejection = await autoUpdaterMock.verifyUpdateCodeSignature!(
154+
publisherNames,
155+
installerPath,
156+
);
157+
// NSIS accepts only null as a successful signature check.
158+
if (rejection !== null) throw new Error(`Invalid signature: ${rejection}`);
159+
return [];
160+
});
161+
return Effect.flatMap(ElectronUpdater.ElectronUpdater, (updater) => updater.downloadUpdate);
162+
};
163+
164+
it.effect("retries a timed-out signature check with the same verifier and installer", () =>
165+
Effect.gen(function* () {
166+
const verify = vi
167+
.fn<VerifyUpdateCodeSignature>()
168+
.mockRejectedValueOnce(timedOut())
169+
.mockResolvedValueOnce(null);
170+
autoUpdaterMock.verifyUpdateCodeSignature = verify;
171+
172+
yield* downloadVerifyingSignature();
173+
174+
assert.deepEqual(verify.mock.calls, [
175+
[publisherNames, installerPath],
176+
[publisherNames, installerPath],
177+
]);
178+
}).pipe(Effect.provide(ElectronUpdater.layer)),
179+
);
180+
181+
it.effect("fails on invalid signatures, other errors and two timeouts on each download", () =>
182+
Effect.gen(function* () {
183+
const cases = [
184+
{ outcome: () => Promise.resolve("Invalid publisher"), calls: 1 },
185+
{ outcome: () => Promise.reject(new Error("Cannot execute PowerShell")), calls: 1 },
186+
{ outcome: () => Promise.reject(timedOut()), calls: 2 },
187+
];
188+
for (const { outcome, calls } of cases) {
189+
const verify = vi.fn<VerifyUpdateCodeSignature>(outcome);
190+
autoUpdaterMock.verifyUpdateCodeSignature = verify;
191+
192+
// Reusing the installed verifier must neither stack retries nor exhaust future retries.
193+
for (let download = 1; download <= 2; download++) {
194+
const error = yield* downloadVerifyingSignature().pipe(Effect.flip);
195+
assert.instanceOf(error, ElectronUpdater.ElectronUpdaterDownloadUpdateError);
196+
assert.equal(verify.mock.calls.length, calls * download);
197+
}
198+
}
199+
}).pipe(Effect.provide(ElectronUpdater.layer)),
200+
);
201+
202+
it.effect("rejects a retry when the upstream capability probe skips verification", () =>
203+
Effect.gen(function* () {
204+
const verify = vi
205+
.fn<VerifyUpdateCodeSignature>()
206+
.mockRejectedValueOnce(timedOut())
207+
.mockImplementationOnce(async () => {
208+
// Upstream resolves null even though its failed capability probe skips verification.
209+
autoUpdaterMock.logger.warn(
210+
"Cannot execute ConvertTo-Json: spawnSync powershell.exe ETIMEDOUT. Ignoring signature validation due to unsupported powershell version. Please upgrade to powershell 3 or higher.",
211+
);
212+
return null;
213+
});
214+
autoUpdaterMock.verifyUpdateCodeSignature = verify;
215+
216+
const error = yield* downloadVerifyingSignature().pipe(Effect.flip);
217+
218+
assert.instanceOf(error, ElectronUpdater.ElectronUpdaterDownloadUpdateError);
219+
assert.equal(verify.mock.calls.length, 2);
220+
}).pipe(Effect.provide(ElectronUpdater.layer)),
221+
);
222+
});
139223
});

‎apps/desktop/src/electron/ElectronUpdater.ts‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import * as Schema from "effect/Schema";
55
import * as Scope from "effect/Scope";
66

77
import { autoUpdater } from "electron-updater";
8+
import type { NsisUpdater, VerifyUpdateCodeSignature } from "electron-updater";
89

910
type AutoUpdater = typeof autoUpdater;
1011

@@ -80,6 +81,45 @@ export class ElectronUpdater extends Context.Service<
8081
}
8182
>()("@t3tools/desktop/electron/ElectronUpdater") {}
8283

84+
const signatureChecksWithRetry = new WeakSet<VerifyUpdateCodeSignature>();
85+
86+
const retrySignatureCheckAfterTimeout = () => {
87+
// Only the Windows NSIS updater exposes this hook; its PowerShell check times out after 20 s.
88+
const updater = autoUpdater as AutoUpdater &
89+
Partial<Pick<NsisUpdater, "verifyUpdateCodeSignature">>;
90+
const verify = updater.verifyUpdateCodeSignature;
91+
if (verify === undefined || signatureChecksWithRetry.has(verify)) return;
92+
93+
const verifyWithRetry: VerifyUpdateCodeSignature = async (publisherNames, path) => {
94+
try {
95+
return await verify(publisherNames, path);
96+
} catch (error) {
97+
if (!(error instanceof Error && "killed" in error && error.killed === true)) throw error;
98+
}
99+
100+
const logger = updater.logger;
101+
let skipped = false;
102+
updater.logger = {
103+
info: (message) => logger?.info(message),
104+
warn: (message) => {
105+
// A failed capability probe makes electron-updater warn and return null without checking.
106+
skipped ||= String(message).includes("Ignoring signature validation");
107+
logger?.warn(message);
108+
},
109+
error: (message) => logger?.error(message),
110+
debug: (message) => logger?.debug?.(message),
111+
};
112+
try {
113+
const result = await verify(publisherNames, path);
114+
return skipped ? "Signature validation was skipped after a timed-out check." : result;
115+
} finally {
116+
updater.logger = logger;
117+
}
118+
};
119+
signatureChecksWithRetry.add(verifyWithRetry);
120+
updater.verifyUpdateCodeSignature = verifyWithRetry;
121+
};
122+
83123
/** @public Service construction is part of the canonical Effect module API. */
84124
export const make = ElectronUpdater.of({
85125
setFeedURL: (options) =>
@@ -131,6 +171,7 @@ export const make = ElectronUpdater.of({
131171
}).pipe(Effect.asVoid);
132172
}),
133173
downloadUpdate: Effect.suspend(() => {
174+
retrySignatureCheckAfterTimeout();
134175
const channel = autoUpdater.channel;
135176
return Effect.tryPromise({
136177
try: () => autoUpdater.downloadUpdate(),

0 commit comments

Comments
 (0)