Skip to content

Commit 8953e43

Browse files
committed
Merge upstream/main into fix/background-agent-capture
2 parents 7aaff44 + 29980a3 commit 8953e43

515 files changed

Lines changed: 10063 additions & 3435 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/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"@t3tools/tailscale": "workspace:*",
2525
"dbus-next": "0.10.2",
2626
"effect": "catalog:",
27-
"electron": "44.4.2",
27+
"electron": "44.4.5",
2828
"electron-store": "^8.2.0",
2929
"electron-updater": "^6.8.9",
3030
"ffi-rs": "1.3.2",

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

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as NodeServices from "@effect/platform-node/NodeServices";
2-
import { expect, it } from "@effect/vitest";
2+
import { afterEach, beforeEach, expect, it } from "@effect/vitest";
33
import * as Effect from "effect/Effect";
44
import * as FileSystem from "effect/FileSystem";
55
import * as Option from "effect/Option";
@@ -85,6 +85,15 @@ const fakePowerShell = (initial: string) => {
8585
return { registry, spawner };
8686
};
8787

88+
// The machine's own PATH may already hold a t3; each test sets the PATH it means.
89+
const machinePath = process.env.PATH;
90+
beforeEach(() => {
91+
process.env.PATH = "";
92+
});
93+
afterEach(() => {
94+
process.env.PATH = machinePath;
95+
});
96+
8897
it.layer(NodeServices.layer)("DesktopCliCommand", (it) => {
8998
it.effect("links the launcher onto PATH and removes only that link", () =>
9099
Effect.gen(function* () {
@@ -165,24 +174,31 @@ it.layer(NodeServices.layer)("DesktopCliCommand", (it) => {
165174
}).pipe(Effect.scoped),
166175
);
167176

168-
it.effect("reports when another t3 earlier on PATH would run instead", () =>
177+
it.effect("refuses to install behind another t3 that runs first", () =>
169178
Effect.gen(function* () {
170179
const fs = yield* FileSystem.FileSystem;
171180
const path = yield* Path.Path;
172181
const home = yield* fs.makeTempDirectoryScoped();
173182
const shadow = path.join(home, "shadow");
174183
yield* fs.makeDirectory(shadow);
175184
yield* fs.writeFileString(path.join(shadow, "t3"), "#!/bin/sh\n", { mode: 0o755 });
176-
const previous = process.env.PATH;
177185
process.env.PATH = [shadow, path.join(home, ".local", "bin")].join(":");
178-
yield* Effect.addFinalizer(() => Effect.sync(() => (process.env.PATH = previous)));
179186

180187
const command = yield* commandIn({ home });
188+
const theirs = path.join(shadow, "t3");
189+
expect((yield* command.state).shadowedBy).toBe(theirs);
190+
// A link behind it would never run, so nothing is created.
191+
const error = yield* Effect.flip(command.install);
192+
expect(error.message).toContain(theirs);
193+
expect(yield* fs.exists(path.join(home, ".local", "bin", "t3"))).toBe(false);
194+
195+
yield* fs.remove(theirs);
181196
const installed = yield* command.install;
182-
expect(installed.installedPath).toBe(path.join(home, ".local", "bin", "t3"));
183-
expect(installed.onPath).toBe(false);
184-
yield* fs.remove(path.join(shadow, "t3"));
185-
expect((yield* command.state).onPath).toBe(true);
197+
expect(installed).toMatchObject({
198+
onPath: true,
199+
installedPath: path.join(home, ".local", "bin", "t3"),
200+
});
201+
expect(installed.shadowedBy).toBeUndefined();
186202
}).pipe(Effect.scoped),
187203
);
188204

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

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,14 @@ export const make = Effect.gen(function* () {
146146
return Option.none<string>();
147147
});
148148

149+
/** The `t3` a new shell runs when it is not this app's, on Unix. */
150+
const foreignFirstOnPath = Effect.gen(function* () {
151+
if (windows) return Option.none<string>();
152+
const first = yield* firstOnPath;
153+
if (Option.isNone(first) || (yield* isOurLink(first.value))) return Option.none<string>();
154+
return first;
155+
});
156+
149157
/** Where this app's command is installed now, if anywhere. */
150158
const installedAt = Effect.gen(function* () {
151159
if (windows) {
@@ -167,12 +175,16 @@ export const make = Effect.gen(function* () {
167175
return { supported: false, installedPath: null, onPath: false } as const;
168176
}
169177
const installed = yield* installedAt;
170-
if (Option.isNone(installed)) return { supported: true, installedPath: null, onPath: false };
178+
const shadowedBy = yield* foreignFirstOnPath;
179+
const shadow = Option.isSome(shadowedBy) ? { shadowedBy: shadowedBy.value } : {};
180+
if (Option.isNone(installed)) {
181+
return { supported: true, installedPath: null, onPath: false, ...shadow };
182+
}
171183
// On Windows only terminals opened after the change see it. On Unix the
172184
// first `t3` on PATH must be ours; a `t3` earlier on PATH would shadow it.
173185
const first = yield* firstOnPath;
174186
const onPath = windows || (Option.isSome(first) && (yield* isOurLink(first.value)));
175-
return { supported: true, installedPath: installed.value, onPath };
187+
return { supported: true, installedPath: installed.value, onPath, ...shadow };
176188
}).pipe(Effect.orElseSucceed(() => ({ supported: false, installedPath: null, onPath: false })));
177189

178190
/** Writes the launcher if the app has not yet, e.g. when no local backend runs. */
@@ -209,6 +221,13 @@ export const make = Effect.gen(function* () {
209221
.remove(existing.value)
210222
.pipe(Effect.mapError(() => fail(`Could not replace ${existing.value}.`)));
211223
}
224+
// A link behind another `t3` never runs, so installing one would only hide the problem.
225+
const shadowedBy = yield* foreignFirstOnPath;
226+
if (Option.isSome(shadowedBy)) {
227+
return yield* fail(
228+
`Another t3 at ${shadowedBy.value} runs first in a new terminal. Remove it, or run the launcher directly at ${launcher}.`,
229+
);
230+
}
212231
const onPath = pathEntries(process.env.PATH, ":");
213232
const candidates = unixCandidates(environment.homeDirectory, environment.platform);
214233
// Prefer a folder already on PATH that the user can write to without admin rights.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ function layerDesktopWindow(
9696
dispatchMenuAction: () => Effect.void,
9797
dispatchSnapShotEvent: () => Effect.void,
9898
zoomMain: () => Effect.void,
99+
runMainContentsCommand: () => Effect.void,
99100
syncAppearance: Effect.void,
100101
});
101102
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ function layerPool(labelRef: Ref.Ref<string>): Layer.Layer<DesktopBackendPool.De
100100
dispatchMenuAction: () => Effect.die("unexpected menu action"),
101101
dispatchSnapShotEvent: () => Effect.void,
102102
zoomMain: () => Effect.die("unexpected zoom"),
103+
runMainContentsCommand: () => Effect.die("unexpected main contents command"),
103104
syncAppearance: Effect.void,
104105
} satisfies DesktopWindow.DesktopWindow["Service"]),
105106
),

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,10 @@ export class ElectronDialog extends Context.Service<
9595
readonly pickFiles: (
9696
input: ElectronDialogPickFilesInput,
9797
) => Effect.Effect<readonly string[], ElectronDialogPickFilesError>;
98+
/** Pass `owner` to attach the box to that window so it cannot fall behind it. */
9899
readonly showMessageBox: (
99100
options: Electron.MessageBoxOptions,
101+
owner?: Electron.BrowserWindow,
100102
) => Effect.Effect<Electron.MessageBoxReturnValue, ElectronDialogShowMessageBoxError>;
101103
readonly showErrorBox: (title: string, content: string) => Effect.Effect<void>;
102104
}
@@ -164,9 +166,12 @@ export const make = ElectronDialog.of({
164166
});
165167
return result.canceled ? [] : result.filePaths;
166168
}),
167-
showMessageBox: (options) =>
169+
showMessageBox: (options, owner) =>
168170
Effect.tryPromise({
169-
try: () => Electron.dialog.showMessageBox(options),
171+
try: () =>
172+
owner === undefined
173+
? Electron.dialog.showMessageBox(options)
174+
: Electron.dialog.showMessageBox(owner, options),
170175
catch: (cause) =>
171176
new ElectronDialogShowMessageBoxError({
172177
type: options.type ?? null,

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,20 @@ describe("ElectronShell", () => {
106106
}).pipe(Effect.provide(ElectronShell.layer)),
107107
);
108108

109+
it.effect("opens the JetBrains Toolbox ssh deep link", () =>
110+
Effect.gen(function* () {
111+
openExternalMock.mockResolvedValue(undefined);
112+
113+
const url =
114+
"jetbrains://gateway/ssh/environment?h=example.com&launchIde=true&ideHint=IU&projectHint=%2Fhome%2Fuser%2Fproject";
115+
const electronShell = yield* ElectronShell.ElectronShell;
116+
const result = yield* electronShell.openExternal(url);
117+
118+
assert.equal(result, true);
119+
assert.deepEqual(openExternalMock.mock.calls, [[url]]);
120+
}).pipe(Effect.provide(ElectronShell.layer)),
121+
);
122+
109123
it.effect("does not open editor URLs that mix up link shapes", () =>
110124
Effect.gen(function* () {
111125
openExternalMock.mockResolvedValue(undefined);
@@ -114,9 +128,12 @@ describe("ElectronShell", () => {
114128
const results = yield* Effect.all([
115129
electronShell.openExternal("zed://extension/attacker"),
116130
electronShell.openExternal("vscode://ssh/example.com/home/user/project"),
131+
electronShell.openExternal("jetbrains://idea/navigate/reference?project=x&path=y"),
132+
electronShell.openExternal("jetbrains://gateway/ssh/environment?launchIde=true"),
133+
electronShell.openExternal("jetbrains://gateway/com.example.provider/connect?h=x"),
117134
]);
118135

119-
assert.deepEqual(results, [false, false]);
136+
assert.deepEqual(results, [false, false, false, false, false]);
120137
assert.equal(openExternalMock.mock.calls.length, 0);
121138
}).pipe(Effect.provide(ElectronShell.layer)),
122139
);
@@ -134,9 +151,10 @@ describe("ElectronShell", () => {
134151
"vscode://:secret@vscode-remote/ssh-remote+example.com/home/user/project",
135152
),
136153
electronShell.openExternal("zed://ssh/[email protected]/home/user/project"),
154+
electronShell.openExternal("jetbrains://user@gateway/ssh/environment?h=example.com"),
137155
]);
138156

139-
assert.deepEqual(results, [false, false, false]);
157+
assert.deepEqual(results, [false, false, false, false]);
140158
assert.equal(openExternalMock.mock.calls.length, 0);
141159
}).pipe(Effect.provide(ElectronShell.layer)),
142160
);

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import * as Option from "effect/Option";
1212
import * as Electron from "electron";
1313

1414
// 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.
15+
// `zed://ssh/<host>/<path>`, `jetbrains://gateway/ssh/environment?h=…`) must
16+
// reach the OS handler; every other non-web scheme stays blocked.
1717
const SAFE_WEB_PROTOCOLS = new Set(["http:", "https:"]);
1818
const REMOTE_EDITOR_PROTOCOLS = new Set(
1919
REMOTE_CAPABLE_EDITOR_IDS.flatMap((id) => {
@@ -31,9 +31,13 @@ const isRemoteEditorUrl = (url: URL) =>
3131
url.password.length === 0 &&
3232
(url.protocol === "zed:"
3333
? 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);
34+
: url.protocol === "jetbrains:"
35+
? url.host === "gateway" &&
36+
url.pathname === "/ssh/environment" &&
37+
(url.searchParams.get("h") ?? "").length > 0
38+
: url.host === "vscode-remote" &&
39+
url.pathname.startsWith("/ssh-remote+") &&
40+
url.pathname.length > "/ssh-remote+".length);
3741

3842
export function parseSafeExternalUrl(rawUrl: unknown): Option.Option<string> {
3943
if (typeof rawUrl !== "string") {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ export const PREVIEW_STATE_CHANGE_CHANNEL = "desktop:preview-state-change";
111111
export const PREVIEW_POINTER_EVENT_CHANNEL = "desktop:preview-pointer-event";
112112
export const PREVIEW_CAPTURE_REQUEST_CHANNEL = "desktop:preview-capture-request";
113113
export const PREVIEW_CAPTURE_READY_CHANNEL = "desktop:preview-capture-ready";
114+
export const PREVIEW_OPEN_LINK_CHANNEL = "desktop:preview-open-link";
114115

115116
export const MAC_PERMISSION_HELPER_CHANNEL = "desktop:mac-permission-helper";
116117

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ export const installPreviewEventForwarding = Effect.fn(
6363
yield* manager.subscribePointerEvents((event) =>
6464
electronWindow.sendAll(IpcChannels.PREVIEW_POINTER_EVENT_CHANNEL, event),
6565
);
66+
yield* manager.subscribeOpenLinks((event) =>
67+
electronWindow.sendAll(IpcChannels.PREVIEW_OPEN_LINK_CHANNEL, event),
68+
);
6669
});
6770

6871
export const acknowledgeCapture = DesktopIpc.makeIpcMethod({

0 commit comments

Comments
 (0)