Skip to content

Commit 45dff94

Browse files
authored
refactor(agent): generalize native goal naming
Generated-By: PostHog Code Task-Id: f8939190-58a1-493b-904c-457c7859b3d6
1 parent 9d3747e commit 45dff94

8 files changed

Lines changed: 37 additions & 37 deletions

File tree

packages/agent/src/acp-extensions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export const POSTHOG_NOTIFICATIONS = {
9191
CODEX_GOAL: "_posthog/codex_goal",
9292
} as const;
9393

94-
export type CodexGoalState = {
94+
export type NativeGoalState = {
9595
objective: string;
9696
status:
9797
| "active"

packages/agent/src/adapters/codex-app-server/codex-app-server-agent.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ describe("CodexAppServerAgent", () => {
454454

455455
await agent.newSession({
456456
cwd: "/repo",
457-
_meta: { codexGoal: restoredGoal },
457+
_meta: { nativeGoal: restoredGoal },
458458
} as unknown as NewSessionRequest);
459459

460460
expect(stub.requests).toContainEqual({

packages/agent/src/adapters/codex-app-server/codex-app-server-agent.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import type {
2121
} from "@agentclientprotocol/sdk";
2222
import { mcpToolKey, posthogToolMeta } from "@posthog/shared";
2323
import {
24-
type CodexGoalState,
24+
type NativeGoalState,
2525
POSTHOG_NOTIFICATIONS,
2626
} from "../../acp-extensions";
2727
import { DEFAULT_CODEX_MODEL } from "../../gateway-models";
@@ -90,7 +90,7 @@ type AppServerSessionMeta = {
9090
channelMode?: boolean;
9191
spokenNarration?: boolean;
9292
baseBranch?: string;
93-
codexGoal?: CodexGoalState;
93+
nativeGoal?: NativeGoalState;
9494
};
9595

9696
/** The subset of codex's `Thread` the adapter reads: id + persisted `turns` for history replay. */
@@ -101,7 +101,7 @@ type AppServerThread = {
101101

102102
type ThreadGoal = {
103103
objective: string;
104-
status: CodexGoalState["status"];
104+
status: NativeGoalState["status"];
105105
};
106106

107107
type GoalCommand =
@@ -482,8 +482,8 @@ export class CodexAppServerAgent extends BaseAcpAgent {
482482
}
483483
this.threadId = threadId;
484484
this.sessionId = threadId;
485-
if (method === APP_SERVER_METHODS.THREAD_START && params.meta?.codexGoal) {
486-
await this.restoreGoal(params.meta.codexGoal);
485+
if (method === APP_SERVER_METHODS.THREAD_START && params.meta?.nativeGoal) {
486+
await this.restoreGoal(params.meta.nativeGoal);
487487
}
488488
await this.loadModelConfig();
489489
this.emitConfigOptions();
@@ -785,7 +785,7 @@ export class CodexAppServerAgent extends BaseAcpAgent {
785785
this.broadcastAgentText(`${prefix}: ${result.goal.objective}`);
786786
}
787787

788-
private async restoreGoal(goal: CodexGoalState): Promise<void> {
788+
private async restoreGoal(goal: NativeGoalState): Promise<void> {
789789
if (!this.threadId) return;
790790
const result = await this.rpc.request<{ goal: ThreadGoal }>(
791791
APP_SERVER_METHODS.THREAD_GOAL_SET,
@@ -798,7 +798,7 @@ export class CodexAppServerAgent extends BaseAcpAgent {
798798
await this.emitGoalState(result.goal);
799799
}
800800

801-
private async emitGoalState(goal: CodexGoalState | null): Promise<void> {
801+
private async emitGoalState(goal: NativeGoalState | null): Promise<void> {
802802
await this.client
803803
.extNotification(POSTHOG_NOTIFICATIONS.CODEX_GOAL, { goal })
804804
.catch((error) =>

packages/agent/src/resume.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717

1818
import type { ContentBlock } from "@agentclientprotocol/sdk";
19-
import type { CodexGoalState } from "./acp-extensions";
19+
import type { NativeGoalState } from "./acp-extensions";
2020
import { selectRecentTurns } from "./adapters/claude/session/jsonl-hydration";
2121
import type { PostHogAPIClient } from "./posthog-api";
2222
import { ResumeSaga } from "./sagas/resume-saga";
@@ -30,7 +30,7 @@ export interface ResumeState {
3030
lastDevice?: DeviceInfo;
3131
logEntryCount: number;
3232
sessionId: string | null;
33-
codexGoal?: CodexGoalState | null;
33+
nativeGoal?: NativeGoalState | null;
3434
}
3535

3636
export interface ConversationTurn {
@@ -97,7 +97,7 @@ export async function resumeFromLog(
9797
lastDevice: result.data.lastDevice,
9898
logEntryCount: result.data.logEntryCount,
9999
sessionId: result.data.sessionId,
100-
codexGoal: result.data.codexGoal,
100+
nativeGoal: result.data.nativeGoal,
101101
};
102102
}
103103

packages/agent/src/sagas/resume-saga.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ describe("ResumeSaga", () => {
663663

664664
expect(result.success).toBe(true);
665665
if (!result.success) return;
666-
expect(result.data.codexGoal).toEqual(expected);
666+
expect(result.data.nativeGoal).toEqual(expected);
667667
});
668668
});
669669

packages/agent/src/sagas/resume-saga.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { ContentBlock } from "@agentclientprotocol/sdk";
22
import { Saga } from "@posthog/shared";
3-
import { type CodexGoalState, POSTHOG_NOTIFICATIONS } from "../acp-extensions";
3+
import { type NativeGoalState, POSTHOG_NOTIFICATIONS } from "../acp-extensions";
44
import type { PostHogAPIClient } from "../posthog-api";
55
import type {
66
DeviceInfo,
@@ -37,7 +37,7 @@ export interface ResumeOutput {
3737
lastDevice?: DeviceInfo;
3838
logEntryCount: number;
3939
sessionId: string | null;
40-
codexGoal?: CodexGoalState | null;
40+
nativeGoal?: NativeGoalState | null;
4141
}
4242

4343
export class ResumeSaga extends Saga<ResumeInput, ResumeOutput> {
@@ -92,8 +92,8 @@ export class ResumeSaga extends Saga<ResumeInput, ResumeOutput> {
9292
const sessionId = await this.readOnlyStep("find_session_id", () =>
9393
Promise.resolve(this.findSessionId(entries)),
9494
);
95-
const codexGoal = await this.readOnlyStep("find_codex_goal", () =>
96-
Promise.resolve(this.findCodexGoal(entries)),
95+
const nativeGoal = await this.readOnlyStep("find_native_goal", () =>
96+
Promise.resolve(this.findNativeGoal(entries)),
9797
);
9898

9999
this.log.info("Resume state rebuilt", {
@@ -110,7 +110,7 @@ export class ResumeSaga extends Saga<ResumeInput, ResumeOutput> {
110110
lastDevice,
111111
logEntryCount: entries.length,
112112
sessionId,
113-
codexGoal,
113+
nativeGoal,
114114
};
115115
}
116116

@@ -121,14 +121,14 @@ export class ResumeSaga extends Saga<ResumeInput, ResumeOutput> {
121121
interrupted: false,
122122
logEntryCount: 0,
123123
sessionId: null,
124-
codexGoal: undefined,
124+
nativeGoal: undefined,
125125
};
126126
}
127127

128-
private findCodexGoal(
128+
private findNativeGoal(
129129
entries: StoredNotification[],
130-
): CodexGoalState | null | undefined {
131-
const statuses = new Set<CodexGoalState["status"]>([
130+
): NativeGoalState | null | undefined {
131+
const statuses = new Set<NativeGoalState["status"]>([
132132
"active",
133133
"paused",
134134
"blocked",
@@ -151,11 +151,11 @@ export class ResumeSaga extends Saga<ResumeInput, ResumeOutput> {
151151
if (
152152
typeof value.objective === "string" &&
153153
typeof value.status === "string" &&
154-
statuses.has(value.status as CodexGoalState["status"])
154+
statuses.has(value.status as NativeGoalState["status"])
155155
) {
156156
return {
157157
objective: value.objective,
158-
status: value.status as CodexGoalState["status"],
158+
status: value.status as NativeGoalState["status"],
159159
};
160160
}
161161
return undefined;

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,9 @@ interface TestableServer {
243243
runtimeAdapter: Adapter,
244244
): { claudeCode: { options: Record<string, unknown> } } | undefined;
245245
resumeState: ResumeState | null;
246-
getCodexGoalForFreshSession(
246+
getNativeGoalForFreshSession(
247247
runtimeAdapter: Adapter,
248-
): ResumeState["codexGoal"];
248+
): ResumeState["nativeGoal"];
249249
}
250250

251251
interface NativeResumeTestServer {
@@ -2389,11 +2389,11 @@ describe("AgentServer HTTP Mode", () => {
23892389
interrupted: false,
23902390
logEntryCount: 1,
23912391
sessionId: "prior-session",
2392-
codexGoal: goal,
2392+
nativeGoal: goal,
23932393
};
23942394

2395-
expect(s.getCodexGoalForFreshSession("codex")).toEqual(goal);
2396-
expect(s.getCodexGoalForFreshSession("claude")).toBeUndefined();
2395+
expect(s.getNativeGoalForFreshSession("codex")).toEqual(goal);
2396+
expect(s.getNativeGoalForFreshSession("claude")).toBeUndefined();
23972397
});
23982398

23992399
it.each([

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -802,11 +802,11 @@ export class AgentServer {
802802
return { sessionId: priorSessionId, warm };
803803
}
804804

805-
private getCodexGoalForFreshSession(
805+
private getNativeGoalForFreshSession(
806806
runtimeAdapter: Adapter,
807-
): ResumeState["codexGoal"] {
807+
): ResumeState["nativeGoal"] {
808808
if (runtimeAdapter !== "codex") return undefined;
809-
return this.resumeState?.codexGoal;
809+
return this.resumeState?.nativeGoal;
810810
}
811811

812812
async stop(): Promise<void> {
@@ -1438,7 +1438,7 @@ export class AgentServer {
14381438
initialPermissionMode,
14391439
);
14401440
let effectiveSessionMeta: typeof sessionMeta & {
1441-
codexGoal?: NonNullable<ResumeState["codexGoal"]>;
1441+
nativeGoal?: NonNullable<ResumeState["nativeGoal"]>;
14421442
} = sessionMeta;
14431443

14441444
let acpSessionId: string | null = null;
@@ -1467,10 +1467,10 @@ export class AgentServer {
14671467
}
14681468
}
14691469
if (!acpSessionId) {
1470-
const restoredCodexGoal =
1471-
this.getCodexGoalForFreshSession(runtimeAdapter);
1472-
effectiveSessionMeta = restoredCodexGoal
1473-
? { ...sessionMeta, codexGoal: restoredCodexGoal }
1470+
const restoredNativeGoal =
1471+
this.getNativeGoalForFreshSession(runtimeAdapter);
1472+
effectiveSessionMeta = restoredNativeGoal
1473+
? { ...sessionMeta, nativeGoal: restoredNativeGoal }
14741474
: sessionMeta;
14751475
const sessionResponse = await clientConnection.newSession({
14761476
cwd: sessionCwd,

0 commit comments

Comments
 (0)