Skip to content

Commit 2d9b0b5

Browse files
committed
refactor: extract shared Adapter type (claude|codex)
Introduces packages/shared/src/adapter.ts as the single source of truth for the "claude" | "codex" runtime-adapter union, previously duplicated (often under different local names: AgentAdapter, AdapterType, RuntimeAdapter, PreviewAdapter, CloudRuntimeAdapter) across core, ui, workspace-server, agent, api-client, and the desktop/mobile apps. All call sites now import Adapter from @posthog/shared instead of redeclaring the literal union.
1 parent e8e5ed5 commit 2d9b0b5

37 files changed

Lines changed: 109 additions & 70 deletions

apps/code/src/renderer/desktop-services.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,11 @@ import {
4949
NOTIFICATIONS_SERVICE,
5050
type NotificationTarget,
5151
} from "@posthog/platform/notifications";
52-
import { AUTORESEARCH_FLAG, type CloudRegion } from "@posthog/shared";
52+
import {
53+
type Adapter,
54+
AUTORESEARCH_FLAG,
55+
type CloudRegion,
56+
} from "@posthog/shared";
5357
import {
5458
AUTH_SIDE_EFFECTS,
5559
type IAuthSideEffects,
@@ -116,7 +120,7 @@ const reportModelResolverLog = logger.scope("report-model-resolver");
116120
container.bind<ReportModelResolver>(REPORT_MODEL_RESOLVER).toConstantValue({
117121
async resolveDefaultModel(
118122
apiHost: string,
119-
adapter: "claude" | "codex",
123+
adapter: Adapter,
120124
preferredModel?: string | null,
121125
): Promise<string | undefined> {
122126
try {

apps/mobile/src/features/tasks/api.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { Adapter } from "@posthog/shared";
12
import { fetch } from "expo/fetch";
23
import {
34
authedFetch,
@@ -421,7 +422,7 @@ export interface RunTaskInCloudOptions {
421422
pendingUserMessage?: string;
422423
mode?: "interactive" | "background";
423424
/** Adapter to use on the cloud runner. Currently only "claude" on mobile. */
424-
runtimeAdapter?: "claude" | "codex";
425+
runtimeAdapter?: Adapter;
425426
/** Gateway model ID, e.g. "claude-opus-4-8". */
426427
model?: string;
427428
/** Reasoning effort: "low" | "medium" | "high" (model-dependent). */

packages/agent/e2e/config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { existsSync } from "node:fs";
22
import { join } from "node:path";
3+
import type { Adapter } from "@posthog/shared";
34

4-
export type Adapter = "claude" | "codex";
5+
export type { Adapter };
56

67
/**
78
* Live e2e configuration, resolved entirely from the environment so no secret is

packages/agent/src/adapters/acp-connection.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { AgentSideConnection, ndJsonStream } from "@agentclientprotocol/sdk";
2+
import type { Adapter } from "@posthog/shared";
23
import type { SessionLogWriter } from "../session-log-writer";
34
import type { PostHogAPIConfig, ProcessSpawnedCallback } from "../types";
45
import { Logger } from "../utils/logger";
@@ -13,10 +14,8 @@ import { nativeCodexBinaryPath } from "./codex-app-server/binary-path";
1314
import { CodexAppServerAgent } from "./codex-app-server/codex-app-server-agent";
1415
import type { CodexOptions } from "./codex-app-server/spawn";
1516

16-
type AgentAdapter = "claude" | "codex";
17-
1817
export type AcpConnectionConfig = {
19-
adapter?: AgentAdapter;
18+
adapter?: Adapter;
2019
logWriter?: SessionLogWriter;
2120
taskRunId?: string;
2221
taskId?: string;

packages/agent/src/adapters/reasoning-effort.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1+
import type { Adapter } from "@posthog/shared";
12
import { getEffortOptions as getClaudeEffortOptions } from "./claude/session/models";
23
import { getReasoningEffortOptions as getCodexReasoningEffortOptions } from "./codex-app-server/models";
34

4-
export type RuntimeAdapter = "claude" | "codex";
5-
65
export type SupportedReasoningEffort =
76
| "low"
87
| "medium"
@@ -16,7 +15,7 @@ export interface ReasoningEffortOption {
1615
}
1716

1817
export function getReasoningEffortOptions(
19-
adapter: RuntimeAdapter,
18+
adapter: Adapter,
2019
modelId: string,
2120
): ReasoningEffortOption[] | null {
2221
const options =
@@ -28,7 +27,7 @@ export function getReasoningEffortOptions(
2827
}
2928

3029
export function isSupportedReasoningEffort(
31-
adapter: RuntimeAdapter,
30+
adapter: Adapter,
3231
modelId: string,
3332
value: string,
3433
): value is SupportedReasoningEffort {

packages/agent/src/server/agent-server.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
33
import { tmpdir } from "node:os";
44
import { join } from "node:path";
55
import type { ContentBlock } from "@agentclientprotocol/sdk";
6+
import type { Adapter } from "@posthog/shared";
67
import { zipSync } from "fflate";
78
import jwt from "jsonwebtoken";
89
import { type SetupServerApi, setupServer } from "msw/node";
@@ -228,9 +229,9 @@ interface TestableServer {
228229
inboxReportUrl?: string | null,
229230
): string | { append: string };
230231
buildCodexInstructions(systemPrompt: string | { append: string }): string;
231-
getRuntimeAdapter(): "claude" | "codex";
232+
getRuntimeAdapter(): Adapter;
232233
buildClaudeCodeSessionMeta(
233-
runtimeAdapter: "claude" | "codex",
234+
runtimeAdapter: Adapter,
234235
): { claudeCode: { options: Record<string, unknown> } } | undefined;
235236
}
236237

@@ -240,7 +241,7 @@ interface NativeResumeTestServer {
240241
payload: JwtPayload,
241242
posthogAPI: PostHogAPIClient,
242243
preTaskRun: TaskRun | null,
243-
runtimeAdapter: "claude" | "codex",
244+
runtimeAdapter: Adapter,
244245
cwd: string,
245246
permissionMode: PermissionMode,
246247
): Promise<{ sessionId: string; warm: boolean } | null>;

packages/agent/src/server/agent-server.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
import { type ServerType, serve } from "@hono/node-server";
1717
import { execGh } from "@posthog/git/gh";
1818
import { getCurrentBranch } from "@posthog/git/queries";
19+
import type { Adapter } from "@posthog/shared";
1920
import { unzipSync } from "fflate";
2021
import { Hono } from "hono";
2122
import { z } from "zod";
@@ -396,7 +397,7 @@ export class AgentServer {
396397
this.app = this.createApp();
397398
}
398399

399-
private getRuntimeAdapter(): "claude" | "codex" {
400+
private getRuntimeAdapter(): Adapter {
400401
return this.config.runtimeAdapter ?? "claude";
401402
}
402403

@@ -669,7 +670,7 @@ export class AgentServer {
669670
payload: JwtPayload,
670671
posthogAPI: PostHogAPIClient,
671672
preTaskRun: TaskRun | null,
672-
runtimeAdapter: "claude" | "codex",
673+
runtimeAdapter: Adapter,
673674
cwd: string,
674675
permissionMode: PermissionMode,
675676
): Promise<{ sessionId: string; warm: boolean } | null> {
@@ -2543,7 +2544,7 @@ export class AgentServer {
25432544
* it cannot sit behind a plugins guard.
25442545
*/
25452546
private buildClaudeCodeSessionMeta(
2546-
runtimeAdapter: "claude" | "codex",
2547+
runtimeAdapter: Adapter,
25472548
): { claudeCode: { options: Record<string, unknown> } } | undefined {
25482549
const plugins = this.config.claudeCode?.plugins;
25492550
const effort =

packages/agent/src/server/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { Adapter } from "@posthog/shared";
12
import type { AgentMode } from "../types";
23
import type { RemoteMcpServer } from "./schemas";
34

@@ -30,7 +31,7 @@ export interface AgentServerConfig {
3031
baseBranch?: string;
3132
claudeCode?: ClaudeCodeConfig;
3233
allowedDomains?: string[];
33-
runtimeAdapter?: "claude" | "codex";
34+
runtimeAdapter?: Adapter;
3435
model?: string;
3536
reasoningEffort?: "low" | "medium" | "high" | "xhigh" | "max";
3637
}

packages/agent/src/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type {
2+
Adapter,
23
GitHandoffCheckpoint,
34
HandoffLocalGitState as GitHandoffLocalGitState,
45
PostHogAPIConfig,
@@ -49,7 +50,7 @@ export interface ProcessSpawnedCallback {
4950

5051
export interface TaskExecutionOptions {
5152
repositoryPath?: string;
52-
adapter?: "claude" | "codex";
53+
adapter?: Adapter;
5354
model?: string;
5455
gatewayUrl?: string;
5556
codexBinaryPath?: string;

packages/api-client/src/posthog-client.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import "./generated.augment";
22
import { isSupportedReasoningEffort } from "@posthog/agent/adapters/reasoning-effort";
33
import type { PermissionMode } from "@posthog/agent/execution-mode";
44
import type {
5+
Adapter,
56
CloudRunSource,
67
PrAuthorshipMode,
78
SeatData,
@@ -470,10 +471,8 @@ export interface FinalizedTaskArtifactUpload {
470471
uploaded_at?: string;
471472
}
472473

473-
type CloudRuntimeAdapter = "claude" | "codex";
474-
475474
interface CloudRunOptions {
476-
adapter?: CloudRuntimeAdapter;
475+
adapter?: Adapter;
477476
model?: string;
478477
reasoningLevel?: string;
479478
sandboxEnvironmentId?: string;

0 commit comments

Comments
 (0)