Skip to content
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CLAUDE.md
1 change: 0 additions & 1 deletion apps/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
"@pierre/diffs": "^1.1.0-beta.16",
"effect": "catalog:",
"node-pty": "^1.1.0",
"open": "^10.1.0",
"ws": "^8.18.0"
},
"devDependencies": {
Expand Down
2 changes: 2 additions & 0 deletions apps/server/spawned2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
started
started
Copy link
Copy Markdown
Contributor

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) and apps/server/tmp-test.cmd (a batch file that appends to spawned2.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)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 8d257e2. Configure here.

14 changes: 3 additions & 11 deletions apps/server/src/codexAppServerManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ import {
resolveCodexModelForAccount,
type CodexAccountSnapshot,
} from "./provider/codexAccount";
import { buildCodexInitializeParams, killCodexChildProcess } from "./provider/codexAppServer";
import { buildCodexInitializeParams } from "./provider/codexAppServer";
import { killChildProcessTree } from "./process/killTree";

export { buildCodexInitializeParams } from "./provider/codexAppServer";
export { readCodexAccountSnapshot, resolveCodexModelForAccount } from "./provider/codexAccount";
Expand Down Expand Up @@ -306,15 +307,6 @@ function mapCodexRuntimeMode(runtimeMode: RuntimeMode): {
};
}

/**
* On Windows with `shell: true`, `child.kill()` only terminates the `cmd.exe`
* wrapper, leaving the actual command running. Use `taskkill /T` to kill the
* entire process tree instead.
*/
function killChildTree(child: ChildProcessWithoutNullStreams): void {
killCodexChildProcess(child);
}

export function normalizeCodexModelSlug(
model: string | undefined | null,
preferredId?: string,
Expand Down Expand Up @@ -908,7 +900,7 @@ export class CodexAppServerManager extends EventEmitter<CodexAppServerManagerEve
context.output.close();

if (!context.child.killed) {
killChildTree(context.child);
killChildProcessTree(context.child);
}

this.updateSession(context, {
Expand Down
14 changes: 6 additions & 8 deletions apps/server/src/git/Layers/GitCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
} from "../Services/GitCore.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;
Expand Down Expand Up @@ -520,8 +521,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),
Expand All @@ -530,12 +531,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;
Comment thread
cursor[bot] marked this conversation as resolved.
truncated = truncateOutputAtMaxBytes && limitedChunk.truncated;

const decoded = decoder.decode(chunkToDecode, { stream: !truncated });
text += decoded;
Expand Down
4 changes: 2 additions & 2 deletions apps/server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as Effect from "effect/Effect";
import * as Layer from "effect/Layer";

import { CliConfig, t3Cli } from "./main";
import { OpenLive } from "./open";
import * as DesktopLauncher from "./process/Layers/DesktopLauncher";
import { Command } from "effect/unstable/cli";
import { version } from "../package.json" with { type: "json" };
import { ServerLive } from "./wsServer";
Expand All @@ -14,7 +14,7 @@ import { FetchHttpClient } from "effect/unstable/http";
const RuntimeLayer = Layer.empty.pipe(
Layer.provideMerge(CliConfig.layer),
Layer.provideMerge(ServerLive),
Layer.provideMerge(OpenLive),
Layer.provideMerge(DesktopLauncher.layer),
Layer.provideMerge(NetService.layer),
Layer.provideMerge(NodeServices.layer),
Layer.provideMerge(FetchHttpClient.layer),
Expand Down
8 changes: 5 additions & 3 deletions apps/server/src/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { NetService } from "@t3tools/shared/Net";

import { CliConfig, recordStartupHeartbeat, t3Cli, type CliConfigShape } from "./main";
import { ServerConfig, type ServerConfigShape } from "./config";
import { Open, type OpenShape } from "./open";
import { DesktopLauncher, type DesktopLauncherShape } from "./process/Services/DesktopLauncher";
import { ProjectionSnapshotQuery } from "./orchestration/Services/ProjectionSnapshotQuery";
import { AnalyticsService } from "./telemetry/Services/AnalyticsService";
import { Server, type ServerShape } from "./wsServer";
Expand Down Expand Up @@ -50,10 +50,12 @@ const testLayer = Layer.mergeAll(
start: serverStart,
stopSignal: Effect.void,
} satisfies ServerShape),
Layer.succeed(Open, {
Layer.succeed(DesktopLauncher, {
getAvailableEditors: Effect.succeed([]),
openExternal: () => Effect.void,
openBrowser: (_target: string) => Effect.void,
openInEditor: () => Effect.void,
} satisfies OpenShape),
} satisfies DesktopLauncherShape),
ServerSettingsService.layerTest(),
AnalyticsService.layerTest,
FetchHttpClient.layer,
Expand Down
6 changes: 3 additions & 3 deletions apps/server/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
type ServerConfigShape,
} from "./config";
import { fixPath, resolveBaseDir } from "./os-jank";
import { Open } from "./open";
import { DesktopLauncher } from "./process/Services/DesktopLauncher";
import * as SqlitePersistence from "./persistence/Layers/Sqlite";
import { makeServerProviderLayer, makeServerRuntimeServicesLayer } from "./serverLayers";
import { ProjectionSnapshotQuery } from "./orchestration/Services/ProjectionSnapshotQuery";
Expand Down Expand Up @@ -336,7 +336,7 @@ export const recordStartupHeartbeat = Effect.gen(function* () {
const makeServerRuntimeProgram = (input: CliInput) =>
Effect.gen(function* () {
const { start, stopSignal } = yield* Server;
const openDeps = yield* Open;
const desktopLauncher = yield* DesktopLauncher;

const config = yield* ServerConfig;

Expand Down Expand Up @@ -366,7 +366,7 @@ const makeServerRuntimeProgram = (input: CliInput) =>

if (!config.noBrowser) {
const target = config.devUrl?.toString() ?? bindUrl;
yield* openDeps.openBrowser(target).pipe(
yield* desktopLauncher.openBrowser(target).pipe(
Effect.catch(() =>
Effect.logInfo("browser auto-open unavailable", {
hint: `Open ${target} in your browser.`,
Expand Down
Loading
Loading