t3-code-android-nightly/apps/server/scripts/codexReplayRecordingRecords.ts
Julius Marminge de34391427
feat(orchestrator): introduce new orchestrator (#2829)
Co-authored-by: maria-rcks <maria@kuuro.net>
Co-authored-by: Bilal Bakr <62337003+Bil0000@users.noreply.github.com>
Co-authored-by: shivam <91240327+shivamhwp@users.noreply.github.com>
Co-authored-by: Vitalii Yehorov <vitalyiegorov@gmail.com>
Co-authored-by: Jake Leventhal <jakeleventhal@me.com>
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-authored-by: Alex Southwell <saphid@gmail.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Nicholas Wasmiller <derped@mineperial.com>
Co-authored-by: PB <poilmb@gmail.com>
Co-authored-by: Exotic <118054752+extoci@users.noreply.github.com>
Co-authored-by: Yash Singh <saiansh2525@gmail.com>
Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: Theo Browne <me@t3.gg>
Co-authored-by: Gabriel De Andrade <30420087+gabrielelpidio@users.noreply.github.com>
Co-authored-by: Dara Adedeji <76637177+SunkenInTime@users.noreply.github.com>
Co-authored-by: scratchyone <scratchywon@gmail.com>
Co-authored-by: Dominic Roy <dominic@sdko.org>
Co-authored-by: chukfinley <chuk@chuk.dev>
Co-authored-by: Primož Ajdišek <bigpod@bigpod.si>
Co-authored-by: benthecarman <benthecarman@live.com>
Co-authored-by: NaveDanan <nave0712@gmail.com>
Co-authored-by: aaditagrawal <103925638+aaditagrawal@users.noreply.github.com>
Co-authored-by: Aditya Garud <153842990+yashranaway@users.noreply.github.com>
Co-authored-by: Nick Anisimov <n.anisimov.23@gmail.com>
Co-authored-by: MacKinley Smith <smithmackinley@gmail.com>
Co-authored-by: Yordis Prieto <yordis.prieto@gmail.com>
Co-authored-by: t3-code[bot] <269035359+t3-code[bot]@users.noreply.github.com>
Co-authored-by: AKolenda <akole779@mtroyal.ca>
Co-authored-by: Guillermo Casanova <75276669+Gigioxx@users.noreply.github.com>
Co-authored-by: Otavio Salvador <otavio@ossystems.com.br>
Co-authored-by: Shirish Pothi <183252392+shirishpothi@users.noreply.github.com>
Co-authored-by: Ishaan Kothari <ishaanko.mail@gmail.com>
Co-authored-by: Bob Fowler <bob@rjf.ca>
Co-authored-by: Anton Bezdenezhnykh <gamer392@yandex.ru>
Co-authored-by: ValeraZSD <48602572+ValeraZSD@users.noreply.github.com>
Co-authored-by: Ephraim <ephraim39hr14m@gmail.com>
Co-authored-by: Ryan Ilano <ryanilano@users.noreply.github.com>
Co-authored-by: Alex <me@pixp.cc>
Co-authored-by: maco <gosarmarcel7@gmail.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Tristan Knight <admin@snappeh.com>
Co-authored-by: PR Batch Tester <agent@local.test>
Co-authored-by: oliver <97427849+flamboh@users.noreply.github.com>
Co-authored-by: kamkm <99585688+Kamkmgamer@users.noreply.github.com>
Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
2026-10-02 12:22:22 -07:00

83 lines
3 KiB
TypeScript

const REPLAY_WORKSPACE_PLACEHOLDER = "<workspace>";
const REPLAY_HOME = "/home/replay-user";
const REPLAY_CHECKOUT = "/home/replay-user/t3code";
const REPLAY_HOSTNAME = "replay-host";
/** Account- and install-scoped values Codex reports; the adapter reads none of them. */
const REPLAY_VALUES_BY_KEY: Readonly<Record<string, string>> = {
installationId: "00000000-0000-4000-8000-000000000000",
planType: "unknown",
};
interface CodexReplayRecordingMachine {
readonly home: string;
readonly hostname: string;
/** Root of the checkout the recorder runs from; it names the local worktree layout. */
readonly checkout: string;
}
function withWorkspacePlaceholder(value: unknown, workspace: string): unknown {
if (value === workspace) {
return REPLAY_WORKSPACE_PLACEHOLDER;
}
if (Array.isArray(value)) {
return value.map((entry) => withWorkspacePlaceholder(entry, workspace));
}
if (typeof value !== "object" || value === null) {
return value;
}
return Object.fromEntries(
Object.entries(value).map(([key, entry]) => [key, withWorkspacePlaceholder(entry, workspace)]),
);
}
function withoutMachineIdentity(
value: unknown,
machine: CodexReplayRecordingMachine,
key?: string,
): unknown {
if (typeof value === "string") {
const replacement = key === undefined ? undefined : REPLAY_VALUES_BY_KEY[key];
if (replacement !== undefined) return replacement;
return value === machine.hostname
? REPLAY_HOSTNAME
: value.replaceAll(machine.checkout, REPLAY_CHECKOUT).replaceAll(machine.home, REPLAY_HOME);
}
if (Array.isArray(value)) {
return value.map((entry) => withoutMachineIdentity(entry, machine));
}
if (typeof value !== "object" || value === null) {
return value;
}
return Object.fromEntries(
Object.entries(value).map(([entryKey, entry]) => [
entryKey,
withoutMachineIdentity(entry, machine, entryKey),
]),
);
}
/**
* Codex supports multiple provider threads in one app-server session, so native
* fork recording keeps the request ids emitted by that single client. Outbound
* frames name the recording cwd `<workspace>`, which replay swaps for its own
* checkpoint workspace. With `machine`, every frame also swaps the checkout
* path, home directory, hostname, installation id and plan type for neutral
* values so fixtures carry no local identity; the adapter reads none of them.
*/
export function codexReplayRecordingOutputRecords(
records: ReadonlyArray<Record<string, unknown>>,
options: {
readonly workspace: string;
readonly machine?: CodexReplayRecordingMachine;
},
): ReadonlyArray<Record<string, unknown>> {
return records.map((record) => {
const named =
record.type === "expect_outbound"
? { ...record, frame: withWorkspacePlaceholder(record.frame, options.workspace) }
: record;
return options.machine === undefined || !("frame" in named)
? named
: { ...named, frame: withoutMachineIdentity(named.frame, options.machine) };
});
}