Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 5.2k
Refactor open service onto Effect-backed process spawning#1603
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
2ade037d7257dfd358a667fa5304439e8bc935e7c60cdb35ec5472479b3394c72c34781218eff8d257e2b909b94File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| started | ||
| started | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -38,6 +38,7 @@ import { | ||
| } from "../remoteRefs.ts"; | ||
| import { ServerConfig } from "../../config.ts"; | ||
| import { decodeJsonResult } from "@t3tools/shared/schemaJson"; | ||
| import { limitChunkToByteLimit } from "../../process/outputBuffer"; | ||
| const DEFAULT_TIMEOUT_MS = 30_000; | ||
| const DEFAULT_MAX_OUTPUT_BYTES = 1_000_000; | ||
| @@ -618,8 +619,8 @@ const collectOutput = Effect.fn("collectOutput")(function* <E>( | ||
| if (truncateOutputAtMaxBytes && truncated) { | ||
| return; | ||
| } | ||
| const nextBytes = bytes + chunk.byteLength; | ||
| if (!truncateOutputAtMaxBytes && nextBytes > maxOutputBytes) { | ||
| const limitedChunk = limitChunkToByteLimit(chunk, bytes, maxOutputBytes); | ||
| if (!truncateOutputAtMaxBytes && limitedChunk.overflow) { | ||
| return yield* new GitCommandError({ | ||
| operation: input.operation, | ||
| command: quoteGitCommand(input.args), | ||
| @@ -628,12 +629,9 @@ const collectOutput = Effect.fn("collectOutput")(function* <E>( | ||
| }); | ||
| } | ||
| const chunkToDecode = | ||
| truncateOutputAtMaxBytes && nextBytes > maxOutputBytes | ||
| ? chunk.subarray(0, Math.max(0, maxOutputBytes - bytes)) | ||
| : chunk; | ||
| bytes += chunkToDecode.byteLength; | ||
| truncated = truncateOutputAtMaxBytes && nextBytes > maxOutputBytes; | ||
| const chunkToDecode = truncateOutputAtMaxBytes ? limitedChunk.chunk : chunk; | ||
| bytes = truncateOutputAtMaxBytes ? limitedChunk.nextBytes : bytes + chunk.byteLength; | ||
cursor[bot] marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| truncated = truncateOutputAtMaxBytes && limitedChunk.truncated; | ||
| const decoded = decoder.decode(chunkToDecode, { stream: !truncated }); | ||
| text += decoded; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -9,6 +9,7 @@ | ||
| import { spawn } from "node:child_process"; | ||
| import { accessSync, constants, statSync } from "node:fs"; | ||
| import { extname, join } from "node:path"; | ||
| import { pathToFileURL } from "node:url"; | ||
| import { EDITORS, OpenError, type EditorId } from "@t3tools/contracts"; | ||
| import { Context, Effect, Layer } from "effect"; | ||
| @@ -35,6 +36,11 @@ interface CommandAvailabilityOptions { | ||
| } | ||
| const TARGET_WITH_POSITION_PATTERN = /^(.*?):(\d+)(?::(\d+))?$/; | ||
| const WINDOWS_EDITOR_URI_SCHEMES: Partial<Record<EditorId, string>> = { | ||
| vscode: "vscode", | ||
| "vscode-insiders": "vscode-insiders", | ||
| vscodium: "vscodium", | ||
| }; | ||
| function parseTargetPathAndPosition(target: string): { | ||
| path: string; | ||
| @@ -53,6 +59,36 @@ function parseTargetPathAndPosition(target: string): { | ||
| }; | ||
| } | ||
| function splitTargetPathAndSuffix(target: string): { | ||
| path: string; | ||
| suffix: string; | ||
| } { | ||
| const parsedTarget = parseTargetPathAndPosition(target); | ||
| if (!parsedTarget) { | ||
| return { path: target, suffix: "" }; | ||
| } | ||
| return { | ||
| path: parsedTarget.path, | ||
| suffix: parsedTarget.column | ||
| ? `:${parsedTarget.line}:${parsedTarget.column}` | ||
| : `:${parsedTarget.line}`, | ||
| }; | ||
| } | ||
| function makeWindowsEditorProtocolTarget(editor: EditorId, target: string): string | undefined { | ||
| const scheme = WINDOWS_EDITOR_URI_SCHEMES[editor]; | ||
| if (!scheme) return undefined; | ||
| const { path, suffix } = splitTargetPathAndSuffix(target); | ||
| const fileUrl = pathToFileURL(path).href; | ||
| const fileTarget = fileUrl.startsWith("file:///") | ||
| ? fileUrl.slice("file:///".length) | ||
| : fileUrl.replace(/^file:\/\//, ""); | ||
| return `${scheme}://file/${fileTarget}${suffix}`; | ||
| } | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Duplicate | ||
| function resolveCommandEditorArgs( | ||
| editor: (typeof EDITORS)[number], | ||
| target: string, | ||
| @@ -268,6 +304,16 @@ export const resolveEditorLaunch = Effect.fn("resolveEditorLaunch")(function* ( | ||
| return yield* new OpenError({ message: `Unknown editor: ${input.editor}` }); | ||
| } | ||
| if (platform === "win32") { | ||
| const protocolTarget = makeWindowsEditorProtocolTarget(input.editor, input.cwd); | ||
| if (protocolTarget) { | ||
| return { | ||
| command: fileManagerCommandForPlatform(platform), | ||
| args: [protocolTarget], | ||
| }; | ||
| } | ||
| } | ||
| if (editorDef.commands) { | ||
| const command = | ||
| resolveAvailableCommand(editorDef.commands, { platform, env }) ?? editorDef.commands[0]; | ||
| @@ -296,7 +342,12 @@ export const launchDetached = (launch: EditorLaunch) => | ||
| child = spawn(launch.command, [...launch.args], { | ||
| detached: true, | ||
| stdio: "ignore", | ||
| shell: process.platform === "win32", | ||
| shell: | ||
| process.platform === "win32" && | ||
| launch.command.toLowerCase() !== "explorer" && | ||
| !launch.command.toLowerCase().endsWith("\\explorer.exe") && | ||
| !launch.command.toLowerCase().endsWith("/explorer.exe"), | ||
| ...(process.platform === "win32" ? { windowsHide: true } : {}), | ||
| }); | ||
| } catch (error) { | ||
| return resume( | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Debug test files accidentally committed to repository
Medium Severity
apps/server/spawned2.txt(containing "started" output) andapps/server/tmp-test.cmd(a batch file that appends tospawned2.txt) are debug/test artifacts that were accidentally included in the commit. These files are not referenced by any production or test code and appear to be leftovers from manual testing of process spawning.Additional Locations (1)
apps/server/tmp-test.cmd#L1-L3Reviewed by Cursor Bugbot for commit 8d257e2. Configure here.