Skip to content

Commit f0995f9

Browse files
committed
Merge remote-tracking branch 'origin/main' into deps/effect-tsgo
# Conflicts: # apps/desktop/src/preview/Manager.ts # apps/server/src/assets/AttachmentUpload.ts # apps/server/src/assets/NativeAppIconResolver.ts # apps/server/src/cli/app.ts # apps/server/src/device/SshDeviceHost.ts # apps/server/src/mcp/McpHttpServer.ts # apps/server/src/preview/Manager.ts # apps/server/src/project/ProjectSetupScriptRunner.ts # apps/server/src/provider/ProviderCredentialStore.ts # apps/server/src/provider/openCodeUsageLimits.ts # apps/server/src/pullRequest/GitHubPullRequestCli.ts # apps/server/src/vcs/GitVcsDriver.ts # apps/server/src/ws.ts
2 parents ee0371e + 4ae976d commit f0995f9

40 files changed

Lines changed: 679 additions & 1295 deletions

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as NodeVM from "node:vm";
2+
import * as NodeCrypto from "@effect/platform-node/NodeCrypto";
23
import { it as effectIt } from "@effect/vitest";
34
import { DESKTOP_PREVIEW_RECORDING_CAPTURE_TRIGGER } from "@t3tools/contracts";
45
import type {
@@ -279,6 +280,7 @@ const layer = PreviewManager.layer.pipe(
279280
Layer.provideMerge(layerEnvironment),
280281
Layer.provideMerge(layerFileSystem),
281282
Layer.provideMerge(Path.layer),
283+
Layer.provideMerge(NodeCrypto.layer),
282284
Layer.provideMerge(Layer.succeed(HostProcessPlatform, "darwin")),
283285
);
284286
const encodePreviewManagerError = Schema.encodeSync(PreviewManager.PreviewManagerError);

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
* elements live in the renderer; we only attach listeners and forward state
66
* here). Single layer-scoped browser session partition.
77
*/
8-
// @effect-diagnostics-next-line nodeBuiltinImport:off -- uses Node's synchronous randomUUID; Effect's Crypto.randomUUIDv4 is an Effect.
9-
import * as NodeCrypto from "node:crypto";
108
import {
119
DesktopPreviewRecordingInputSchema,
1210
DESKTOP_PREVIEW_RECORDING_CAPTURE_TRIGGER,
@@ -50,6 +48,7 @@ import {
5048
import * as Cause from "effect/Cause";
5149
import * as Clock from "effect/Clock";
5250
import * as Context from "effect/Context";
51+
import * as Crypto from "effect/Crypto";
5352
import * as DateTime from "effect/DateTime";
5453
import * as Deferred from "effect/Deferred";
5554
import * as Effect from "effect/Effect";
@@ -644,6 +643,7 @@ const makeNativeOperations = Effect.fn("PreviewManager.makeOperations")(function
644643
const rendererHistory = yield* DesktopRendererHistory.DesktopRendererHistory;
645644
const hostPlatform = yield* HostProcessPlatform;
646645
const path = yield* Path.Path;
646+
const crypto = yield* Crypto.Crypto;
647647
const parentScope = yield* Scope.Scope;
648648
const context = yield* Effect.context<never>();
649649
const runFork = Effect.runForkWith(context);
@@ -1658,9 +1658,9 @@ const makeNativeOperations = Effect.fn("PreviewManager.makeOperations")(function
16581658
returnByValue: boolean,
16591659
awaitPromise = true,
16601660
): Effect.Effect<A, PreviewManagerError> =>
1661-
Effect.suspend(() => {
1662-
const objectGroup = `t3-evaluation-${NodeCrypto.randomUUID()}`;
1663-
return send("Runtime.evaluate", {
1661+
Effect.gen(function* () {
1662+
const objectGroup = `t3-evaluation-${yield* crypto.randomUUIDv4.pipe(Effect.orDie)}`;
1663+
return yield* send("Runtime.evaluate", {
16641664
expression,
16651665
awaitPromise,
16661666
returnByValue,
@@ -4187,10 +4187,11 @@ const makeNativeOperations = Effect.fn("PreviewManager.makeOperations")(function
41874187
const context = { operation: "automationPress.awaitNativeKey", tabId, webContentsId: wc.id };
41884188
const evaluate = (frame: Electron.WebFrameMain, expression: string) =>
41894189
attemptPromise(context, () => frame.executeJavaScript(expression));
4190+
const receiptId = yield* crypto.randomUUIDv4.pipe(Effect.orDie);
41904191
const { frames, receiptKey } = yield* Effect.acquireRelease(
41914192
attempt(context, () => ({
41924193
frames: wc.mainFrame.framesInSubtree,
4193-
receiptKey: JSON.stringify(`__t3NativeKey_${NodeCrypto.randomUUID()}`),
4194+
receiptKey: JSON.stringify(`__t3NativeKey_${receiptId}`),
41944195
})),
41954196
({ frames, receiptKey }) =>
41964197
Effect.forEach(
@@ -4446,10 +4447,8 @@ const makeNativeOperations = Effect.fn("PreviewManager.makeOperations")(function
44464447
keySequence,
44474448
clipboardData,
44484449
);
4449-
const selectionKey = yield* encodeJson(
4450-
context,
4451-
`__t3EditingSelection_${NodeCrypto.randomUUID()}`,
4452-
);
4450+
const selectionId = yield* crypto.randomUUIDv4.pipe(Effect.orDie);
4451+
const selectionKey = yield* encodeJson(context, `__t3EditingSelection_${selectionId}`);
44534452
// Editing requires an active document. Preserve the target
44544453
// and selection across focus handlers without focusing the desktop.
44554454
yield* Effect.acquireUseRelease(

‎apps/server/scripts/measure-pr-preview.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ const layerMeasuredProcess = Layer.effect(
5050
const layerServices = GitHubPullRequestCli.layer.pipe(
5151
Layer.provide(GitHubCli.layer),
5252
Layer.provideMerge(layerMeasuredProcess),
53+
Layer.provide(NodeServices.layer),
5354
);
5455

5556
const decodeJson = Schema.decodeSync(Schema.fromJsonString(Schema.Unknown));

‎apps/server/src/assets/AttachmentUpload.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
// @effect-diagnostics-next-line nodeBuiltinImport:off -- uses Node's synchronous randomUUID; Effect's Crypto.randomUUIDv4 is an Effect.
2-
import * as NodeCrypto from "node:crypto";
3-
41
import {
52
ATTACHMENT_UPLOAD_URL_TTL_MS,
63
type AttachmentCreateUploadUrlInput,
74
AttachmentUploadSigningKeyError,
85
} from "@t3tools/contracts";
96
import * as Clock from "effect/Clock";
7+
import * as Crypto from "effect/Crypto";
108
import * as Effect from "effect/Effect";
119
import * as FileSystem from "effect/FileSystem";
1210
import * as Option from "effect/Option";
@@ -171,9 +169,11 @@ export const storeAttachmentUpload = Effect.fn("AttachmentUpload.store")(functio
171169
attachmentsDir: config.attachmentsDir,
172170
relativePath,
173171
});
172+
const crypto = yield* Crypto.Crypto;
173+
const partId = yield* crypto.randomUUIDv4.pipe(Effect.orDie);
174174
const partPath = resolveAttachmentRelativePath({
175175
attachmentsDir: config.attachmentsDir,
176-
relativePath: `${relativePath}.${NodeCrypto.randomUUID()}.part`,
176+
relativePath: `${relativePath}.${partId}.part`,
177177
});
178178
if (!finalPath || !partPath) {
179179
return { ok: false, status: 500, detail: "Failed to resolve attachment path." };

‎apps/server/src/assets/NativeAppIconResolver.ts‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
// @effect-diagnostics-next-line nodeBuiltinImport:off -- uses Node's synchronous createHash and randomUUID; Effect's Crypto has digest and randomUUIDv4 as Effects.
2-
import * as NodeCrypto from "node:crypto";
31
import type { ToolActivityNativeAppReference } from "@t3tools/contracts";
42
import * as Cache from "effect/Cache";
53
import * as Cause from "effect/Cause";
4+
import * as Crypto from "effect/Crypto";
65
import * as Effect from "effect/Effect";
76
import * as Clock from "effect/Clock";
87
import * as Context from "effect/Context";
@@ -14,6 +13,7 @@ import * as Option from "effect/Option";
1413
import * as Path from "effect/Path";
1514
import * as PlatformError from "effect/PlatformError";
1615
import * as Semaphore from "effect/Semaphore";
16+
import * as Hex from "effect/encoding/Hex";
1717
import { ChildProcess, ChildProcessSpawner } from "effect/process";
1818
import { HostProcessPlatform } from "@t3tools/shared/hostProcess";
1919

@@ -176,17 +176,21 @@ const resolveNativeAppIconUncached = Effect.fn("NativeAppIconResolver.resolveUnc
176176
const appVersion =
177177
(yield* plistValue(infoPlistPath, "CFBundleVersion")) ||
178178
(yield* plistValue(infoPlistPath, "CFBundleShortVersionString"));
179-
const cacheKey = NodeCrypto.createHash("sha256")
180-
.update(`${canonicalAppPath}\0${appVersion}\0${sourceIconPath}`)
181-
.digest("hex");
179+
const crypto = yield* Crypto.Crypto;
180+
const cacheKey = yield* crypto
181+
.digest(
182+
"SHA-256",
183+
new TextEncoder().encode(`${canonicalAppPath}\0${appVersion}\0${sourceIconPath}`),
184+
)
185+
.pipe(Effect.map(Hex.encode), Effect.orDie);
182186
const cacheDirectory = path.join(config.providerStatusCacheDir, "native-app-icons");
183187
const cachePath = path.join(cacheDirectory, `${cacheKey}.png`);
184188
if (yield* existingFile(cachePath)) return cachePath;
185189

186190
yield* fileSystem.makeDirectory(cacheDirectory, { recursive: true });
187191
const temporaryPath = path.join(
188192
cacheDirectory,
189-
`.${cacheKey}-${process.pid}-${(yield* Clock.currentTimeMillis).toString(36)}-${NodeCrypto.randomUUID()}.png`,
193+
`.${cacheKey}-${process.pid}-${(yield* Clock.currentTimeMillis).toString(36)}-${yield* crypto.randomUUIDv4.pipe(Effect.orDie)}.png`,
190194
);
191195
yield* commandOutput("/usr/bin/sips", [
192196
"-z",

‎apps/server/src/cli/app.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
// @effect-diagnostics globalTimers:off -- The Node socket client owns its response deadline and clears it on every completion path.
2-
// @effect-diagnostics-next-line nodeBuiltinImport:off -- uses Node's synchronous randomUUID; Effect's Crypto.randomUUIDv4 is an Effect.
3-
import * as NodeCrypto from "node:crypto";
42
import * as NodeNet from "node:net";
53
import * as NodeOS from "node:os";
64

@@ -19,6 +17,7 @@ import {
1917
} from "@t3tools/shared/hostProcess";
2018
import * as Config from "effect/Config";
2119
import * as Console from "effect/Console";
20+
import * as Crypto from "effect/Crypto";
2221
import * as Effect from "effect/Effect";
2322
import * as Option from "effect/Option";
2423
import * as Path from "effect/Path";
@@ -213,9 +212,11 @@ const runAppCommand = Effect.fn("cli.app")(function* (flags: {
213212
userId,
214213
joinPath: path.join,
215214
}).address;
215+
const crypto = yield* Crypto.Crypto;
216+
const requestId = yield* crypto.randomUUIDv4.pipe(Effect.orDie);
216217
const request: DesktopAppActivationRequest = {
217218
version: DESKTOP_APP_ACTIVATION_PROTOCOL_VERSION,
218-
requestId: NodeCrypto.randomUUID(),
219+
requestId,
219220
type: "open-workspace",
220221
workspaceRoot,
221222
platform: hostPlatform,

‎apps/server/src/device/SshDeviceHost.ts‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// @effect-diagnostics-next-line nodeBuiltinImport:off -- uses Node's synchronous createHash; Effect's Crypto.digest is an Effect.
2-
import * as NodeCrypto from "node:crypto";
31
import {
42
type DeviceHostSummary,
53
DevicePlatformAvailability,
@@ -10,6 +8,7 @@ import {
108
import { runSshCommand, baseSshArgs, resolveSshCommand } from "@t3tools/ssh/command";
119
import * as NetService from "@t3tools/shared/Net";
1210
import { waitForHttpReady } from "@t3tools/shared/httpReadiness";
11+
import * as Crypto from "effect/Crypto";
1312
import * as Exit from "effect/Exit";
1413
import * as Effect from "effect/Effect";
1514
import * as FileSystem from "effect/FileSystem";
@@ -18,6 +17,7 @@ import * as Scope from "effect/Scope";
1817
import * as Semaphore from "effect/Semaphore";
1918
import * as Schema from "effect/Schema";
2019
import * as Stream from "effect/Stream";
20+
import * as Hex from "effect/encoding/Hex";
2121
import * as HttpClient from "effect/http/HttpClient";
2222
import * as ChildProcess from "effect/process/ChildProcess";
2323
import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
@@ -80,10 +80,11 @@ const ownerFor = Effect.fn("SshDeviceHost.ownerFor")(function* (hostId: string)
8080
const environmentId = yield* fs
8181
.readFileString(server.environmentIdPath)
8282
.pipe(Effect.orElseSucceed(() => server.stateDir));
83-
return NodeCrypto.createHash("sha256")
84-
.update(`${environmentId}\0${server.stateDir}\0${hostId}`)
85-
.digest("hex")
86-
.slice(0, 24);
83+
const crypto = yield* Crypto.Crypto;
84+
const owner = yield* crypto
85+
.digest("SHA-256", new TextEncoder().encode(`${environmentId}\0${server.stateDir}\0${hostId}`))
86+
.pipe(Effect.map(Hex.encode), Effect.orDie);
87+
return owner.slice(0, 24);
8788
});
8889

8990
export const probe = Effect.fn("SshDeviceHost.probe")(function* (
@@ -126,6 +127,7 @@ export const make = Effect.fn("SshDeviceHost.make")(function* (
126127
const net = yield* NetService.NetService;
127128
const http = yield* HttpClient.HttpClient;
128129
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
130+
const crypto = yield* Crypto.Crypto;
129131
const parentScope = yield* Scope.Scope;
130132
const ssh = yield* resolveSshCommand;
131133
const owner = yield* ownerFor(config.id);
@@ -136,6 +138,7 @@ export const make = Effect.fn("SshDeviceHost.make")(function* (
136138
| FileSystem.FileSystem
137139
| Path.Path
138140
| ChildProcessSpawner.ChildProcessSpawner
141+
| Crypto.Crypto
139142
| ServerConfig.ServerConfig
140143
>,
141144
) =>
@@ -144,6 +147,7 @@ export const make = Effect.fn("SshDeviceHost.make")(function* (
144147
Effect.provideService(Path.Path, path),
145148
Effect.provideService(ServerConfig.ServerConfig, server),
146149
Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),
150+
Effect.provideService(Crypto.Crypto, crypto),
147151
);
148152
const lock = yield* Semaphore.make(1);
149153
let stopped = false;

‎apps/server/src/mcp/McpHttpServer.ts‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
// @effect-diagnostics-next-line nodeBuiltinImport:off -- uses Node's synchronous randomUUID; Effect's Crypto.randomUUIDv4 is an Effect.
2-
import * as NodeCrypto from "node:crypto";
31
import * as Cause from "effect/Cause";
42
import * as Clock from "effect/Clock";
53
import * as Context from "effect/Context";
4+
import * as Crypto from "effect/Crypto";
65
import * as Effect from "effect/Effect";
76
import * as FileSystem from "effect/FileSystem";
87
import * as Layer from "effect/Layer";
@@ -335,8 +334,10 @@ const saveScreenshot = Effect.fn("McpHttpServer.saveScreenshot")(function* (
335334
const fileSystem = yield* FileSystem.FileSystem;
336335
const path = yield* Path.Path;
337336
const millis = yield* Clock.currentTimeMillis;
337+
const crypto = yield* Crypto.Crypto;
338338
// Two saves in the same millisecond must not overwrite each other.
339-
const fileName = `browser-screenshot-${screenshotSiteSlug(pageUrl)}-${millis.toString(36)}-${NodeCrypto.randomUUID().slice(0, 8)}.png`;
339+
const unique = (yield* crypto.randomUUIDv4.pipe(Effect.orDie)).slice(0, 8);
340+
const fileName = `browser-screenshot-${screenshotSiteSlug(pageUrl)}-${millis.toString(36)}-${unique}.png`;
340341
const screenshotPath = path.join(config.browserArtifactsDir, fileName);
341342
yield* fileSystem.makeDirectory(config.browserArtifactsDir, { recursive: true }).pipe(
342343
Effect.andThen(fileSystem.writeFile(screenshotPath, data)),
@@ -388,7 +389,7 @@ const registerPreviewSnapshot = Effect.fn("McpHttpServer.registerPreviewSnapshot
388389
const broker = yield* PreviewAutomationBroker.PreviewAutomationBroker;
389390
// The MCP tool runner only supplies the client, so hand the save path its services here.
390391
const saveServices = yield* Effect.context<
391-
ServerConfig.ServerConfig | FileSystem.FileSystem | Path.Path
392+
ServerConfig.ServerConfig | FileSystem.FileSystem | Path.Path | Crypto.Crypto
392393
>();
393394
const built = yield* PreviewSnapshotToolkit;
394395
const tool = PreviewSnapshotTool;

‎apps/server/src/mcp/toolkits/previewControls/handlers.test.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import * as NodeCrypto from "@effect/platform-node/NodeCrypto";
12
import { expect, it } from "@effect/vitest";
23
import {
34
DEFAULT_SERVER_SETTINGS,
@@ -45,7 +46,7 @@ it.effect.each([
4546
capabilities: new Set(effective.enableAgentBrowserAccess ? ["preview"] : []),
4647
issuedAt: 0,
4748
};
48-
const manager = yield* Preview.make;
49+
const manager = yield* Preview.make.pipe(Effect.provide(NodeCrypto.layer));
4950
const tab = yield* manager.open({ threadId, url: "http://localhost:3000" });
5051
const layerDependencies = Layer.mergeAll(
5152
Layer.succeed(Preview.PreviewManager, manager),

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
import * as NodeCrypto from "@effect/platform-node/NodeCrypto";
12
import { it } from "@effect/vitest";
23
import { type PreviewEvent, ThreadId } from "@t3tools/contracts";
34
import { PreviewUrlNormalizationError } from "@t3tools/shared/preview";
4-
import { Effect, PubSub } from "effect";
5+
import * as Effect from "effect/Effect";
6+
import * as Layer from "effect/Layer";
7+
import * as PubSub from "effect/PubSub";
58
import { expect } from "vite-plus/test";
69

710
import * as PreviewManager from "./Manager.ts";
@@ -35,7 +38,7 @@ const collectEvents = Effect.gen(function* () {
3538
return collector;
3639
}).pipe(Effect.withSpan("preview.test.collectEvents"));
3740

38-
it.layer(PreviewManager.layer)("PreviewManager", (it) => {
41+
it.layer(PreviewManager.layer.pipe(Layer.provide(NodeCrypto.layer)))("PreviewManager", (it) => {
3942
it.effect("opens a session and emits opened with normalized URL", () =>
4043
Effect.gen(function* () {
4144
const threadId = freshThreadId();

0 commit comments

Comments
 (0)