Skip to content
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
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ jobs:
- name: Install dependencies
run: pnpm install --frozen-lockfile --ignore-scripts

- name: Generate Codex protocol types
run: pnpm run codex-protocol:gen

- name: Typecheck
run: pnpm run typecheck

Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"type": "module",
"main": "dist/main/main.cjs",
"scripts": {
"postinstall": "electron-rebuild --only better-sqlite3 && node scripts/ensure-native-deps.mjs",
"postinstall": "electron-rebuild --only better-sqlite3 && node scripts/ensure-native-deps.mjs && pnpm run codex-protocol:gen",
"setup:native": "electron-rebuild --only better-sqlite3 && node scripts/ensure-native-deps.mjs",
"dev": "concurrently -k -n renderer,electron,app -c cyan,magenta,yellow \"pnpm run dev:renderer\" \"pnpm run dev:electron\" \"pnpm run dev:app\"",
"devtools": "node scripts/dev-react-devtools.mjs",
Expand Down Expand Up @@ -49,6 +49,7 @@
"prepare:mobile:ssh": "pnpm run build:electron && pnpm run prepare:package-assets && node scripts/build-mobile-ssh-runtime.mjs",
"sentry:sourcemaps": "node scripts/sentry-sourcemaps.mjs",
"clean:sourcemaps": "node scripts/clean-sourcemaps.mjs",
"codex-protocol:gen": "pnpm --filter @poracode/codex-protocol run generate",
"dist": "node scripts/build-desktop-artifact.mjs",
"dist:win": "node scripts/build-desktop-artifact.mjs --platform win --target nsis --arch x64",
"dist:win:all": "node scripts/build-desktop-artifact.mjs --platform win",
Expand Down Expand Up @@ -97,6 +98,7 @@
"@opencode-ai/sdk": "^1.18.3",
"@poracode/activity-bridge": "file:native/activity-bridge",
"@poracode/agents-usage": "workspace:*",
"@poracode/codex-protocol": "workspace:*",
"@poracode/ssh-bridge": "file:native/ssh-bridge",
"@sentry/electron": "^7.15.0",
"@sentry/node": "10.63.0",
Expand Down
1 change: 1 addition & 0 deletions packages/codex-protocol/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
generated/
13 changes: 13 additions & 0 deletions packages/codex-protocol/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# @poracode/codex-protocol

TypeScript definitions generated during `pnpm install` from `@openai/codex`, pinned to `0.144.5`.

The generated sources live in `generated/` and are intentionally gitignored. Regenerate them manually from the repository root with:

```sh
pnpm codex-protocol:gen
```

If TypeScript reports that `./generated/index` cannot be found, run `pnpm install` or the generation command above.

Bump the exact `@openai/codex` devDependency in `package.json` to update the generated protocol version.
9 changes: 9 additions & 0 deletions packages/codex-protocol/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export type {
ApplyPatchApprovalParams,
ApplyPatchApprovalResponse,
ExecCommandApprovalParams,
ExecCommandApprovalResponse,
InitializeParams,
InitializeResponse,
} from "./generated/index";
export * from "./generated/v2/index";
22 changes: 22 additions & 0 deletions packages/codex-protocol/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "@poracode/codex-protocol",
"version": "0.1.0",
"private": true,
"description": "Install-time-generated TypeScript definitions for the Codex app-server protocol.",
"type": "module",
"sideEffects": false,
"main": "./index.ts",
"types": "./index.ts",
"exports": {
".": {
"types": "./index.ts",
"default": "./index.ts"
}
},
"scripts": {
"generate": "node ./scripts/generate.mjs"
},
"devDependencies": {
"@openai/codex": "0.144.5"
}
}
48 changes: 48 additions & 0 deletions packages/codex-protocol/scripts/generate.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { existsSync, rmSync } from "node:fs";
import { delimiter, dirname, resolve } from "node:path";
import { fileURLToPath } from "node:url";
import { spawnSync } from "node:child_process";

const packageDir = resolve(dirname(fileURLToPath(import.meta.url)), "..");
const workspaceDir = resolve(packageDir, "../..");
const executableName = process.platform === "win32" ? "codex.CMD" : "codex";
const binDirectories = [
resolve(packageDir, "node_modules/.bin"),
resolve(workspaceDir, "node_modules/.bin"),
];
const codexBinDirectory = binDirectories.find((directory) =>
existsSync(resolve(directory, executableName)),
);
const pnpmCli = process.env.npm_execpath;

if (!codexBinDirectory || !pnpmCli) {
console.error(
"Cannot generate Codex protocol types: the pinned @openai/codex binary or pnpm CLI is missing. Run `pnpm install` from the repository root, then try again.",
);
process.exit(1);
}

rmSync(resolve(packageDir, "generated"), { recursive: true, force: true });

const result = spawnSync(
process.execPath,
[pnpmCli, "exec", "codex", "app-server", "generate-ts", "--experimental", "--out", "./generated"],
{
cwd: packageDir,
env: {
...process.env,
PATH: `${codexBinDirectory}${delimiter}${process.env.PATH ?? ""}`,
},
stdio: "inherit",
},
);

if (result.error) {
console.error(`Cannot generate Codex protocol types: ${result.error.message}`);
process.exit(1);
}

if (result.status !== 0) {
console.error(`Codex protocol generation failed with exit code ${result.status ?? "unknown"}.`);
process.exit(result.status ?? 1);
}
77 changes: 77 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions pnpm-workspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ packages:
- "."
- "website"
- "packages/agents-usage"
- "packages/codex-protocol"

# Share the virtual store across worktrees/checkouts via symlinks instead of
# hardlinking every package into each node_modules/.pnpm (see pnpm.io/git-worktrees).
Expand Down Expand Up @@ -199,6 +200,8 @@ minimumReleaseAgeExclude:
- "yuku-ast@0.1.7"
- "yuku-codegen@0.5.44"
- "yuku-parser@0.5.44"
# The platform aliases are prerelease versions of this same package name.
- "@openai/codex"

# Supply-chain guard: refuse to install any package version published less
# than this many minutes ago. 7 days catches the typical window in which
Expand Down
10 changes: 9 additions & 1 deletion src/main/remote/RemoteAccessServer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3444,7 +3444,15 @@ describe("RemoteAccessServer", () => {
const checkpointCalls = [
{
procedure: "rollbackThreadConversation",
payload: { threadId: "thread-1", numTurns: 1 },
payload: {
threadId: "thread-1",
numTurns: 1,
config: {
model: "gpt-5.6-terra",
approvalPolicy: "on-request",
sandboxMode: "workspace-write",
},
},
},
{
procedure: "listFileCheckpoints",
Expand Down
13 changes: 12 additions & 1 deletion src/renderer/components/thread/ChatPane/ChatPane.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1581,7 +1581,16 @@ describe("ChatPane", () => {
});

it("shows checkpoint buttons on later user messages and reverts to before that prompt", async () => {
const thread = { ...makeThread(), status: "idle" as const };
const thread = {
...makeThread(),
status: "idle" as const,
config: {
model: "gpt-5.6-terra",
effort: "high",
approvalPolicy: "on-request",
sandboxMode: "workspace-write",
},
};
const rollbackThreadConversation = vi.fn<() => Promise<void>>().mockResolvedValue(undefined);
Object.assign(window, {
poracode: {
Expand Down Expand Up @@ -1616,6 +1625,7 @@ describe("ChatPane", () => {
expect(rollbackThreadConversation).toHaveBeenCalledWith({
threadId: thread.id,
numTurns: 1,
config: thread.config,
}),
);
await waitFor(() => expect(screen.queryByText("Follow-up prompt")).not.toBeInTheDocument());
Expand Down Expand Up @@ -1663,6 +1673,7 @@ describe("ChatPane", () => {
expect(rollbackThreadConversation).toHaveBeenCalledWith({
threadId: thread.id,
numTurns: 1,
config: thread.config,
}),
);
});
Expand Down
1 change: 1 addition & 0 deletions src/renderer/components/thread/ChatPane/ChatPane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ export function ChatPane(props: ChatPaneProps) {
<MessageList
key={threadId}
threadId={threadId}
threadConfig={thread.config}
entries={timelineEntries}
isTurnActive={isLive}
setScrollContainer={setScrollContainer}
Expand Down
23 changes: 19 additions & 4 deletions src/renderer/components/thread/ChatPane/parts/MessageList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ import {
import { LegendList, type LegendListRef } from "@legendapp/list/react";
import { Surface } from "@heroui/react";
import { Trans } from "@lingui/react/macro";
import type { MessageItemPayload, ProjectLocation, ToolCallPayload } from "@/shared/contracts";
import type {
MessageItemPayload,
ProjectLocation,
ThreadConfig,
ToolCallPayload,
} from "@/shared/contracts";
import { readBridge } from "@/renderer/bridge";
import { formatElapsed } from "@/renderer/utils/formatTime";
import { useAppStore } from "@/renderer/state/appStore";
Expand Down Expand Up @@ -47,7 +52,11 @@ import {
} from "./timelineMeasurementCache";

export interface CheckpointRevertActions {
rollbackThreadConversation(input: { threadId: string; numTurns: number }): Promise<void>;
rollbackThreadConversation(input: {
threadId: string;
numTurns: number;
config?: ThreadConfig;
}): Promise<void>;
restoreFileCheckpoint(input: {
threadId: string;
checkpointItemId: string;
Expand All @@ -57,6 +66,7 @@ export interface CheckpointRevertActions {

interface MessageListProps {
threadId: string;
threadConfig?: ThreadConfig;
entries: readonly ChatTimelineEntry[];
isTurnActive?: boolean;
setScrollContainer?: (element: HTMLDivElement | null) => void;
Expand Down Expand Up @@ -108,6 +118,7 @@ const SKIP_REVERT_CONFIRM_PREF_KEY = "poracode-chat-checkpoint-revert-skip-confi
// while moving the DOM, so the virtualizer must re-render to re-measure.
export function MessageList({
threadId,
threadConfig,
entries,
isTurnActive = false,
setScrollContainer,
Expand Down Expand Up @@ -285,7 +296,11 @@ export function MessageList({
const revert = checkpointActions ?? readBridge();
if (rollbackTurns > 0) {
try {
await revert.rollbackThreadConversation({ threadId, numTurns: rollbackTurns });
await revert.rollbackThreadConversation({
threadId,
numTurns: rollbackTurns,
...(threadConfig ? { config: threadConfig } : {}),
});
} catch (error) {
console.warn(
"[checkpoint] provider rollback failed; continuing with local revert",
Expand All @@ -304,7 +319,7 @@ export function MessageList({
await readBridge().dbTruncateThreadRuntimeAfter({ threadId, itemId });
parentActions?.onContentHeightChange();
},
[checkpointActions, parentActions, projectLocation, threadId],
[checkpointActions, parentActions, projectLocation, threadConfig, threadId],
);

const requestRevert = useCallback(
Expand Down
Loading