Skip to content

Commit 4c20ae9

Browse files
authored
Merge branch 'main' into fix/claude-meter-8594
2 parents de5fe65 + 8ddd9f7 commit 4c20ae9

869 files changed

Lines changed: 80487 additions & 12354 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/deploy-relay.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ jobs:
6363
AXIOM_TOKEN: ${{ secrets.AXIOM_TOKEN }}
6464
CLERK_SECRET_KEY: ${{ secrets.CLERK_SECRET_KEY }}
6565
APNS_PRIVATE_KEY: ${{ secrets.APNS_PRIVATE_KEY }}
66+
FCM_SERVICE_ACCOUNT: ${{ secrets.FCM_SERVICE_ACCOUNT }}
6667

6768
- name: Publish relay deploy commit status
6869
uses: actions/github-script@v8

‎.gitignore‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ dist-electron/
3030
.electron-runtime/
3131
.showcase/
3232
apps/mobile/.showcase/
33+
apps/mobile/.generated/
34+
/.generated/
3335
artifacts/app-store/screenshots/
3436
.github/pr-assets/
3537
native/**/target/
@@ -38,3 +40,6 @@ node_modules/
3840
*.log
3941
.env*
4042
!.env.example
43+
44+
# pnpm content-addressable store; never belongs in the repo.
45+
.pnpm-store/

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

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as Cause from "effect/Cause";
2+
import * as Duration from "effect/Duration";
23
import * as Effect from "effect/Effect";
34
import * as Option from "effect/Option";
45
import * as Ref from "effect/Ref";
@@ -142,6 +143,20 @@ const handleFatalStartupError = Effect.fn("desktop.startup.handleFatalStartupErr
142143
const fatalStartupCause = <E>(stage: string, cause: Cause.Cause<E>) =>
143144
handleFatalStartupError(stage, Cause.pretty(cause)).pipe(Effect.andThen(Effect.failCause(cause)));
144145

146+
export const stopAllPoolInstances = Effect.fn("desktop.app.stopAllPoolInstances")(
147+
function* (): Effect.fn.Return<void, never, DesktopBackendPool.DesktopBackendPool> {
148+
// Stop every backend in the pool with a timeout to guarantee the quit
149+
// path makes progress even if a backend hangs during teardown.
150+
const pool = yield* DesktopBackendPool.DesktopBackendPool;
151+
const instances = yield* pool.list;
152+
yield* Effect.forEach(
153+
instances,
154+
(instance) => instance.stop({ timeout: Duration.seconds(5) }),
155+
{ concurrency: "unbounded" },
156+
);
157+
},
158+
);
159+
145160
const bootstrap = Effect.gen(function* () {
146161
const pool = yield* DesktopBackendPool.DesktopBackendPool;
147162
const primaryBackend = yield* pool.primary;
@@ -313,18 +328,12 @@ const scopedProgram = Effect.scoped(
313328
const shutdown = yield* DesktopShutdown.DesktopShutdown;
314329

315330
yield* Effect.addFinalizer(() =>
316-
Effect.gen(function* () {
317-
const pool = yield* DesktopBackendPool.DesktopBackendPool;
318-
// Stop every backend in the pool, not just the primary. The
319-
// electronApp.quit() path can race ahead of the layer-scope
320-
// cascade, so leaving the WSL instance for its parent scope
321-
// finalizer means it gets hard-killed by the OS instead of
322-
// receiving SIGTERM + grace. Stops run concurrently.
323-
const instances = yield* pool.list;
324-
yield* Effect.forEach(instances, (instance) => instance.stop(), {
325-
concurrency: "unbounded",
326-
});
327-
}).pipe(Effect.ensuring(shutdown.markComplete)),
331+
// Stop every backend in the pool, not just the primary. The
332+
// electronApp.quit() path can race ahead of the layer-scope
333+
// cascade, so leaving the WSL instance for its parent scope
334+
// finalizer means it gets hard-killed by the OS instead of
335+
// receiving SIGTERM + grace.
336+
stopAllPoolInstances().pipe(Effect.ensuring(shutdown.markComplete)),
328337
);
329338

330339
yield* startup;

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

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import { HttpClient, HttpClientRequest, HttpClientResponse } from "effect/unstab
2323
import { ChildProcess, ChildProcessSpawner } from "effect/unstable/process";
2424

2525
import * as DesktopBackendManager from "./DesktopBackendManager.ts";
26+
import * as DesktopApp from "../app/DesktopApp.ts";
27+
import * as DesktopBackendPool from "./DesktopBackendPool.ts";
2628
import * as DesktopObservability from "../app/DesktopObservability.ts";
2729
import * as DesktopTelemetryPublisher from "../telemetry/DesktopTelemetryPublisher.ts";
2830
import * as DesktopWslEnvironment from "../wsl/DesktopWslEnvironment.ts";
@@ -1503,4 +1505,76 @@ describe("DesktopBackendManager", () => {
15031505
}).pipe(Effect.provide(TestClock.layer())),
15041506
),
15051507
);
1508+
1509+
it.effect("stopAllPoolInstances bounds the quit finalizer when backends hang", () =>
1510+
Effect.scoped(
1511+
Effect.gen(function* () {
1512+
// Each backend's process-scope finalizer reports when it starts and
1513+
// when it finishes, keyed by instance name, so the test can prove
1514+
// both backends reached each milestone instead of inferring it from
1515+
// a shared flag or a clock advance.
1516+
const teardownStarted = yield* Queue.unbounded<string>();
1517+
const teardownFinished = yield* Queue.unbounded<string>();
1518+
const allowTeardown = yield* Deferred.make<void>();
1519+
1520+
const makeInstance = (name: string) =>
1521+
makeTestInstance({
1522+
spawnerLayer: Layer.succeed(
1523+
ChildProcessSpawner.ChildProcessSpawner,
1524+
ChildProcessSpawner.make(() =>
1525+
Effect.gen(function* () {
1526+
const scope = yield* Scope.Scope;
1527+
yield* Scope.addFinalizer(
1528+
scope,
1529+
Queue.offer(teardownStarted, name).pipe(
1530+
Effect.andThen(Deferred.await(allowTeardown)),
1531+
Effect.andThen(Queue.offer(teardownFinished, name)),
1532+
Effect.asVoid,
1533+
),
1534+
);
1535+
return makeProcess({ exitCode: Effect.never });
1536+
}),
1537+
),
1538+
),
1539+
httpClientLayer: httpClientLayer(() => Effect.never),
1540+
});
1541+
1542+
const instance1 = yield* makeInstance("instance1");
1543+
const instance2 = yield* makeInstance("instance2");
1544+
1545+
yield* instance1.start;
1546+
yield* instance2.start;
1547+
1548+
const mockPool = Layer.succeed(DesktopBackendPool.DesktopBackendPool, {
1549+
list: Effect.succeed([instance1, instance2]),
1550+
get: () => Effect.succeed(Option.none()),
1551+
primary: Effect.die(new Error("primary not implemented")),
1552+
register: () => Effect.die(new Error("register not implemented")),
1553+
unregister: () => Effect.die(new Error("unregister not implemented")),
1554+
});
1555+
1556+
// Mirror the quit path: register stopAllPoolInstances as a scope
1557+
// finalizer and let the scope close run it, rather than calling it
1558+
// as an ordinary interruptible effect.
1559+
const quitFiber = yield* Effect.scoped(
1560+
Effect.addFinalizer(() => DesktopApp.stopAllPoolInstances()),
1561+
).pipe(Effect.provide(mockPool), Effect.forkChild);
1562+
1563+
const started = yield* Queue.takeN(teardownStarted, 2);
1564+
assert.deepEqual(started.toSorted(), ["instance1", "instance2"]);
1565+
1566+
// Both backends are now hung in teardown. Advancing past the 5s
1567+
// budget must let the quit finalizer return without them.
1568+
yield* TestClock.adjust(Duration.seconds(5));
1569+
yield* Fiber.join(quitFiber);
1570+
assert.equal(yield* Queue.size(teardownFinished), 0);
1571+
1572+
// The timed-out closes keep running in the background and finish
1573+
// once the backends unblock.
1574+
yield* Deferred.succeed(allowTeardown, undefined);
1575+
const finished = yield* Queue.takeN(teardownFinished, 2);
1576+
assert.deepEqual(finished.toSorted(), ["instance1", "instance2"]);
1577+
}).pipe(Effect.provide(TestClock.layer())),
1578+
),
1579+
);
15061580
});

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ describe("ElectronProtocol", () => {
226226
"https:",
227227
]);
228228
assert.deepEqual(directives["media-src"], ["'self'", "t3code:", "blob:", "http:", "https:"]);
229+
assert.deepEqual(directives["frame-src"], ["'self'", "blob:", "http:", "https:"]);
229230
assert.deepEqual(directives["font-src"], ["'self'", "t3code:", "data:"]);
230231
});
231232
});

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ export function makeDesktopContentSecurityPolicy(input: DesktopProtocolRegistrat
9191
"style-src 'self' 'unsafe-inline'",
9292
`font-src 'self' ${input.scheme}: data:`,
9393
"worker-src 'self' blob:",
94-
"frame-src 'self' https://challenges.cloudflare.com",
94+
// Document viewers use local Blob URLs and signed assets from runtime environments.
95+
// HTML viewers retain their own sandbox; the renderer's script policy stays unchanged.
96+
"frame-src 'self' blob: http: https:",
9597
"form-action 'self'",
9698
].join("; ");
9799
}

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

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,39 @@ describe("ElectronShell", () => {
8888
}).pipe(Effect.provide(ElectronShell.layer)),
8989
);
9090

91+
it.effect("opens Zed's ssh deep link", () =>
92+
Effect.gen(function* () {
93+
openExternalMock.mockResolvedValue(undefined);
94+
95+
const electronShell = yield* ElectronShell.ElectronShell;
96+
const results = yield* Effect.all([
97+
electronShell.openExternal("zed://ssh/example.com/home/user/project"),
98+
electronShell.openExternal("zed://ssh/example.com/"),
99+
]);
100+
101+
assert.deepEqual(results, [true, true]);
102+
assert.deepEqual(openExternalMock.mock.calls, [
103+
["zed://ssh/example.com/home/user/project"],
104+
["zed://ssh/example.com/"],
105+
]);
106+
}).pipe(Effect.provide(ElectronShell.layer)),
107+
);
108+
109+
it.effect("does not open editor URLs that mix up link shapes", () =>
110+
Effect.gen(function* () {
111+
openExternalMock.mockResolvedValue(undefined);
112+
113+
const electronShell = yield* ElectronShell.ElectronShell;
114+
const results = yield* Effect.all([
115+
electronShell.openExternal("zed://extension/attacker"),
116+
electronShell.openExternal("vscode://ssh/example.com/home/user/project"),
117+
]);
118+
119+
assert.deepEqual(results, [false, false]);
120+
assert.equal(openExternalMock.mock.calls.length, 0);
121+
}).pipe(Effect.provide(ElectronShell.layer)),
122+
);
123+
91124
it.effect("does not open remote editor URLs with userinfo", () =>
92125
Effect.gen(function* () {
93126
openExternalMock.mockResolvedValue(undefined);
@@ -100,9 +133,10 @@ describe("ElectronShell", () => {
100133
electronShell.openExternal(
101134
"vscode://:secret@vscode-remote/ssh-remote+example.com/home/user/project",
102135
),
136+
electronShell.openExternal("zed://ssh/[email protected]/home/user/project"),
103137
]);
104138

105-
assert.deepEqual(results, [false, false]);
139+
assert.deepEqual(results, [false, false, false]);
106140
assert.equal(openExternalMock.mock.calls.length, 0);
107141
}).pipe(Effect.provide(ElectronShell.layer)),
108142
);

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

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { MAC_PERMISSION_SETTINGS_URLS } from "../permissions/MacPermission.ts";
12
import {
23
REMOTE_CAPABLE_EDITOR_IDS,
34
remoteSchemeForEditor,
@@ -10,22 +11,9 @@ import * as Option from "effect/Option";
1011

1112
import * as Electron from "electron";
1213

13-
/**
14-
* Deep links to individual System Settings panes. These are app-fixed, not
15-
* renderer-supplied, so they skip `parseSafeExternalUrl` — which exists to keep
16-
* arbitrary link schemes from reaching the OS handler — and open through their
17-
* own path below. The pane rather than the URL crosses the IPC boundary, so a
18-
* renderer can only ask for one of these known destinations.
19-
*
20-
* Full Disk Access uses the post-Ventura `PrivacySecurity.extension` anchor.
21-
*/
22-
const SYSTEM_SETTINGS_URLS: Record<SystemSettingsPane, string> = {
23-
"full-disk-access":
24-
"x-apple.systempreferences:com.apple.settings.PrivacySecurity.extension?Privacy_AllFiles",
25-
};
26-
27-
// Remote open-in-editor deep links (`vscode://vscode-remote/ssh-remote+…`)
28-
// must reach the OS handler; every other non-web scheme stays blocked.
14+
// Remote open-in-editor deep links (`vscode://vscode-remote/ssh-remote+…`,
15+
// `zed://ssh/<host>/<path>`) must reach the OS handler; every other non-web
16+
// scheme stays blocked.
2917
const SAFE_WEB_PROTOCOLS = new Set(["http:", "https:"]);
3018
const REMOTE_EDITOR_PROTOCOLS = new Set(
3119
REMOTE_CAPABLE_EDITOR_IDS.flatMap((id) => {
@@ -34,13 +22,18 @@ const REMOTE_EDITOR_PROTOCOLS = new Set(
3422
}),
3523
);
3624

25+
// Zed's host sits in the first path segment, so it needs its own userinfo ban.
26+
const ZED_SSH_PATHNAME = /^\/[^/@:]+\/.*$/;
27+
3728
const isRemoteEditorUrl = (url: URL) =>
3829
REMOTE_EDITOR_PROTOCOLS.has(url.protocol) &&
3930
url.username.length === 0 &&
4031
url.password.length === 0 &&
41-
url.host === "vscode-remote" &&
42-
url.pathname.startsWith("/ssh-remote+") &&
43-
url.pathname.length > "/ssh-remote+".length;
32+
(url.protocol === "zed:"
33+
? url.host === "ssh" && ZED_SSH_PATHNAME.test(url.pathname)
34+
: url.host === "vscode-remote" &&
35+
url.pathname.startsWith("/ssh-remote+") &&
36+
url.pathname.length > "/ssh-remote+".length);
4437

4538
export function parseSafeExternalUrl(rawUrl: unknown): Option.Option<string> {
4639
if (typeof rawUrl !== "string") {
@@ -82,7 +75,7 @@ export const make = ElectronShell.of({
8275
}),
8376
openSystemSettings: (pane) =>
8477
Effect.promise(() =>
85-
Electron.shell.openExternal(SYSTEM_SETTINGS_URLS[pane]).then(
78+
Electron.shell.openExternal(MAC_PERMISSION_SETTINGS_URLS[pane]).then(
8679
() => true,
8780
() => false,
8881
),

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import {
3939
getWindowFullscreenState,
4040
openExternal,
4141
openSystemSettings,
42+
checkSystemPermission,
4243
probeRemoteEditors,
4344
pickFolder,
4445
pickProjectFavicon,
@@ -122,6 +123,7 @@ export const installDesktopIpcHandlers = Effect.fn("desktop.ipc.installHandlers"
122123
yield* ipc.handle(showContextMenu);
123124
yield* ipc.handle(openExternal);
124125
yield* ipc.handle(openSystemSettings);
126+
yield* ipc.handle(checkSystemPermission);
125127
yield* ipc.handle(probeRemoteEditors);
126128
yield* ipc.handle(getUpdateState);
127129
yield* ipc.handle(setUpdateChannel);

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,7 @@ export const PREVIEW_RECORDING_SAVE_CHANNEL = "desktop:preview-recording-save";
105105
export const PREVIEW_RECORDING_FRAME_CHANNEL = "desktop:preview-recording-frame";
106106
export const PREVIEW_STATE_CHANGE_CHANNEL = "desktop:preview-state-change";
107107
export const PREVIEW_POINTER_EVENT_CHANNEL = "desktop:preview-pointer-event";
108+
109+
export const MAC_PERMISSION_HELPER_CHANNEL = "desktop:mac-permission-helper";
110+
111+
export const CHECK_SYSTEM_PERMISSION_CHANNEL = "desktop:check-system-permission";

0 commit comments

Comments
 (0)