Skip to content

Commit a09b3f4

Browse files
only21milclaude
andcommitted
fix(server): Codex file-change approvals list the files they change
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 7447436 commit a09b3f4

1 file changed

Lines changed: 60 additions & 2 deletions

File tree

‎apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts‎

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,16 @@ const CODEX_PROVIDER = ProviderDriverKind.make("codex");
149149
export const CODEX_DRIVER_KIND = CODEX_PROVIDER;
150150
export const CODEX_DEFAULT_INSTANCE_ID = defaultInstanceIdForDriver(CODEX_DRIVER_KIND);
151151

152+
// Change kind by path. Legacy apply-patch payloads fit as they are.
153+
type CodexFileChangeKinds = Readonly<
154+
Record<string, CodexSchema.V2ItemStartedNotification__PatchChangeKind>
155+
>;
156+
152157
/** Describe approval scope even when Codex omits or blanks the optional reason. */
153158
export function codexFileChangeApprovalPrompt(input: {
154159
readonly reason?: string | null;
155160
readonly grantRoot?: string | null;
156-
readonly fileChanges?: CodexSchema.ServerRequest__ApplyPatchApprovalParams["fileChanges"];
161+
readonly fileChanges?: CodexFileChangeKinds;
157162
}): string | undefined {
158163
const reason = input.reason?.trim();
159164
if (reason) return reason;
@@ -1878,6 +1883,11 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
18781883
const offeredContinuationItemsByTurn = yield* Ref.make(new Map<string, Set<string>>());
18791884
const finalAnswerItemIdsByTurn = yield* Ref.make(new Map<string, Set<string>>());
18801885
const completedFinalAnswerTextsByTurn = yield* Ref.make(new Map<string, Set<string>>());
1886+
// File change kinds from item/started, by turn and item, so the item's
1887+
// approval request can list its paths. Diffs are not kept.
1888+
const fileChangeKindsByTurn = yield* Ref.make(
1889+
new Map<string, Map<string, CodexFileChangeKinds>>(),
1890+
);
18811891
// Native completion and the interrupt timeout share one finalization
18821892
// path. Serialize the race so only one can publish terminal events.
18831893
const turnTerminalizationPermit = yield* Semaphore.make(1);
@@ -4651,6 +4661,20 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
46514661
);
46524662
}
46534663

4664+
if (payload.item.type === "fileChange") {
4665+
const kinds = Object.fromEntries(
4666+
payload.item.changes.map((change) => [change.path, change.kind]),
4667+
);
4668+
yield* Ref.update(fileChangeKindsByTurn, (current) => {
4669+
const updated = new Map(current);
4670+
const items = new Map(updated.get(payload.turnId) ?? []);
4671+
items.set(payload.item.id, kinds);
4672+
updated.set(payload.turnId, items);
4673+
return updated;
4674+
});
4675+
return;
4676+
}
4677+
46544678
if (payload.item.type === "agentMessage") {
46554679
if (payload.item.phase !== "commentary") {
46564680
yield* Ref.update(finalAnswerItemIdsByTurn, (current) => {
@@ -4755,6 +4779,23 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
47554779
yield* updateSubagentStates({ item: payload.item });
47564780
return;
47574781
}
4782+
if (payload.item.type === "fileChange") {
4783+
yield* Ref.update(fileChangeKindsByTurn, (current) => {
4784+
const items = current.get(payload.turnId);
4785+
if (items === undefined || !items.has(payload.item.id)) {
4786+
return current;
4787+
}
4788+
const remaining = new Map(items);
4789+
remaining.delete(payload.item.id);
4790+
const updated = new Map(current);
4791+
if (remaining.size === 0) {
4792+
updated.delete(payload.turnId);
4793+
} else {
4794+
updated.set(payload.turnId, remaining);
4795+
}
4796+
return updated;
4797+
});
4798+
}
47584799
const resolved = yield* resolveItemEventContext(payload.turnId);
47594800
if (resolved === undefined) {
47604801
return;
@@ -5122,12 +5163,21 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
51225163
);
51235164
}
51245165

5166+
// Codex sends item/started before this request, so the item's paths
5167+
// are cached. Without them the prompt falls back as before.
5168+
const fileChanges = (yield* Ref.get(fileChangeKindsByTurn))
5169+
.get(payload.turnId)
5170+
?.get(payload.itemId);
51255171
const artifacts = yield* buildApprovalRequestArtifacts({
51265172
context,
51275173
nativeItemId: payload.itemId,
51285174
nativeRequestId: payload.itemId,
51295175
requestKind: "file-change",
5130-
prompt: codexFileChangeApprovalPrompt(payload) ?? null,
5176+
prompt:
5177+
codexFileChangeApprovalPrompt({
5178+
...payload,
5179+
...(fileChanges === undefined ? {} : { fileChanges }),
5180+
}) ?? null,
51315181
});
51325182
const decision = yield* Deferred.make<ProviderApprovalDecision, never>();
51335183
yield* Ref.update(pendingRuntimeRequests, (current) => {
@@ -5928,6 +5978,14 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
59285978
updated.delete(input.nativeTurnId);
59295979
return updated;
59305980
});
5981+
yield* Ref.update(fileChangeKindsByTurn, (current) => {
5982+
if (!current.has(input.nativeTurnId)) {
5983+
return current;
5984+
}
5985+
const updated = new Map(current);
5986+
updated.delete(input.nativeTurnId);
5987+
return updated;
5988+
});
59315989
if (input.context.nativeStartReady !== undefined) {
59325990
yield* Deferred.succeed(input.context.nativeStartReady, undefined);
59335991
}

0 commit comments

Comments
 (0)