Skip to content
This repository was archived by the owner on May 4, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all 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: 2 additions & 0 deletions apps/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
"test": "vitest run"
},
"dependencies": {
"@github/copilot": "1.0.2",
"@github/copilot-sdk": "0.1.31-unstable.0",
"@effect/platform-node": "catalog:",
"@effect/sql-sqlite-bun": "catalog:",
"@pierre/diffs": "^1.1.0-beta.16",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,12 @@ describe("CheckpointDiffQueryLive", () => {
readonly toCheckpointRef: CheckpointRef;
readonly cwd: string;
}> = [];
const workspaceRoot = process.cwd();

const snapshot = makeSnapshot({
projectId,
threadId,
workspaceRoot: "/tmp/workspace",
workspaceRoot,
worktreePath: null,
checkpointTurnCount: 1,
checkpointRef: toCheckpointRef,
Expand Down Expand Up @@ -141,7 +142,7 @@ describe("CheckpointDiffQueryLive", () => {
expect(hasCheckpointRefCalls).toEqual([expectedFromRef, toCheckpointRef]);
expect(diffCheckpointsCalls).toEqual([
{
cwd: "/tmp/workspace",
cwd: workspaceRoot,
fromCheckpointRef: expectedFromRef,
toCheckpointRef,
},
Expand Down
6 changes: 3 additions & 3 deletions apps/server/src/checkpointing/Layers/CheckpointDiffQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Effect, Layer, Schema } from "effect";

import { ProjectionSnapshotQuery } from "../../orchestration/Services/ProjectionSnapshotQuery.ts";
import { CheckpointInvariantError, CheckpointUnavailableError } from "../Errors.ts";
import { checkpointRefForThreadTurn, resolveThreadWorkspaceCwd } from "../Utils.ts";
import { checkpointRefForThreadTurn, resolveExistingThreadWorkspaceCwd } from "../Utils.ts";
import { CheckpointStore } from "../Services/CheckpointStore.ts";
import {
CheckpointDiffQuery,
Expand Down Expand Up @@ -62,14 +62,14 @@ const make = Effect.gen(function* () {
});
}

const workspaceCwd = resolveThreadWorkspaceCwd({
const workspaceCwd = resolveExistingThreadWorkspaceCwd({
thread,
projects: snapshot.projects,
});
if (!workspaceCwd) {
return yield* new CheckpointInvariantError({
operation,
detail: `Workspace path missing for thread '${input.threadId}' when computing turn diff.`,
detail: `Workspace path is missing or unavailable for thread '${input.threadId}' when computing turn diff.`,
});
}

Expand Down
20 changes: 20 additions & 0 deletions apps/server/src/checkpointing/Utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { existsSync } from "node:fs";

import { Encoding } from "effect";
import { CheckpointRef, ProjectId, type ThreadId } from "@t3tools/contracts";

Expand Down Expand Up @@ -26,3 +28,21 @@ export function resolveThreadWorkspaceCwd(input: {

return input.projects.find((project) => project.id === input.thread.projectId)?.workspaceRoot;
}

export function resolveExistingThreadWorkspaceCwd(input: {
readonly thread: {
readonly projectId: ProjectId;
readonly worktreePath: string | null;
};
readonly projects: ReadonlyArray<{
readonly id: ProjectId;
readonly workspaceRoot: string;
}>;
}): string | undefined {
const resolvedCwd = resolveThreadWorkspaceCwd(input);
if (!resolvedCwd) {
return undefined;
}

return existsSync(resolvedCwd) ? resolvedCwd : undefined;
}
33 changes: 30 additions & 3 deletions apps/server/src/git/Layers/CodexTextGeneration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,21 @@ const makeCodexTextGeneration = Effect.gen(function* () {
cwd,
prompt,
outputSchemaJson,
binaryPath = "codex",
homePath,
model = CODEX_MODEL,
reasoningEffort = CODEX_REASONING_EFFORT,
imagePaths = [],
cleanupPaths = [],
}: {
operation: "generateCommitMessage" | "generatePrContent" | "generateBranchName";
cwd: string;
prompt: string;
outputSchemaJson: S;
binaryPath?: string;
homePath?: string;
model?: string;
reasoningEffort?: string;
imagePaths?: ReadonlyArray<string>;
cleanupPaths?: ReadonlyArray<string>;
}): Effect.Effect<S["Type"], TextGenerationError, S["DecodingServices"]> =>
Expand All @@ -205,16 +213,16 @@ const makeCodexTextGeneration = Effect.gen(function* () {

const runCodexCommand = Effect.gen(function* () {
const command = ChildProcess.make(
"codex",
binaryPath,
[
"exec",
"--ephemeral",
"-s",
"read-only",
"--model",
CODEX_MODEL,
model,
"--config",
`model_reasoning_effort="${CODEX_REASONING_EFFORT}"`,
`model_reasoning_effort="${reasoningEffort}"`,
"--output-schema",
schemaPath,
"--output-last-message",
Expand All @@ -224,6 +232,7 @@ const makeCodexTextGeneration = Effect.gen(function* () {
],
{
cwd,
...(homePath ? { env: { ...process.env, HOME: homePath } } : {}),
shell: process.platform === "win32",
stdin: {
stream: Stream.make(new TextEncoder().encode(prompt)),
Expand Down Expand Up @@ -314,6 +323,11 @@ const makeCodexTextGeneration = Effect.gen(function* () {

const generateCommitMessage: TextGenerationShape["generateCommitMessage"] = (input) => {
const wantsBranch = input.includeBranch === true;
const binaryPath = input.providerOptions?.codex?.binaryPath ?? "codex";
const homePath = input.providerOptions?.codex?.homePath;
const model = input.model ?? CODEX_MODEL;
const reasoningEffort =
input.modelOptions?.codex?.reasoningEffort ?? CODEX_REASONING_EFFORT;

const prompt = [
"You write concise git commit messages.",
Expand Down Expand Up @@ -353,6 +367,10 @@ const makeCodexTextGeneration = Effect.gen(function* () {
cwd: input.cwd,
prompt,
outputSchemaJson,
binaryPath,
model,
reasoningEffort,
...(homePath ? { homePath } : {}),
}).pipe(
Effect.map(
(generated) =>
Expand All @@ -368,6 +386,11 @@ const makeCodexTextGeneration = Effect.gen(function* () {
};

const generatePrContent: TextGenerationShape["generatePrContent"] = (input) => {
const binaryPath = input.providerOptions?.codex?.binaryPath ?? "codex";
const homePath = input.providerOptions?.codex?.homePath;
const model = input.model ?? CODEX_MODEL;
const reasoningEffort =
input.modelOptions?.codex?.reasoningEffort ?? CODEX_REASONING_EFFORT;
const prompt = [
"You write GitHub pull request content.",
"Return a JSON object with keys: title, body.",
Expand All @@ -394,6 +417,10 @@ const makeCodexTextGeneration = Effect.gen(function* () {
operation: "generatePrContent",
cwd: input.cwd,
prompt,
binaryPath,
model,
reasoningEffort,
...(homePath ? { homePath } : {}),
outputSchemaJson: Schema.Struct({
title: Schema.String,
body: Schema.String,
Expand Down
Loading
Loading