1import type { ProviderDriverKind } from "@t3tools/contracts";
2export const TRANSFER_HISTORY_TURN_COUNT = 10;
3export const TRANSFER_HISTORY_TOOLS_PER_TURN = 5;
4export const TRANSFER_MEASURED_TOOLS = 20;
5export const TRANSFER_HISTORY_MCP_RESULT_BYTES = 900_000;
6export const TRANSFER_MEASURED_MCP_RESULT_BYTES = 1_100_000;
7
8const sourceModules = [
9 "connection/session.ts",
10 "connection/supervisor.ts",
11 "rpc/client.ts",
12 "rpc/protocol.ts",
13 "state/threads.ts",
14 "state/threadReducer.ts",
15 "state/threadSnapshotHttp.ts",
16 "orchestration/http.ts",
17 "orchestration/Normalizer.ts",
18 "orchestration/ActivityPayloadProjection.ts",
19 "provider/ProviderService.ts",
20 "provider/ProviderRuntimeIngestion.ts",
21 "persistence/ProjectionSnapshotQuery.ts",
22 "persistence/OrchestrationEventStore.ts",
23 "checkpointing/CheckpointStore.ts",
24 "checkpointing/CheckpointDiffQuery.ts",
25 "server.ts",
26] as const;
27
28function mix(value: number): number {
29 let mixed = value | 0;
30 mixed ^= mixed >>> 16;
31 mixed = Math.imul(mixed, 0x7feb352d);
32 mixed ^= mixed >>> 15;
33 mixed = Math.imul(mixed, 0x846ca68b);
34 mixed ^= mixed >>> 16;
35 return mixed >>> 0;
36}
37
38function digest(seed: number): string {
39 return [0, 1, 2, 3]
40 .map((offset) =>
41 mix(seed + offset * 0x9e3779b9)
42 .toString(16)
43 .padStart(8, "0"),
44 )
45 .join("");
46}
47
48/** Produces safe, deterministic output with enough entropy to exercise gzip. */
49export function diagnosticOutput(input: {
50 readonly provider: ProviderDriverKind;
51 readonly turnIndex: number;
52 readonly toolIndex: number;
53 readonly targetBytes: number;
54}): string {
55 const chunks: string[] = [];
56 const providerSeed = input.provider === "codex" ? 0x43_4f_44_45 : 0x43_4c_41_55;
57 let length = 0;
58 let lineIndex = 0;
59
60 while (length < input.targetBytes) {
61 const modulePath = sourceModules[(input.toolIndex + lineIndex) % sourceModules.length];
62 const seed =
63 providerSeed + input.turnIndex * 100_003 + input.toolIndex * 10_007 + lineIndex * 101;
64 const line =
65 `${String(lineIndex + 1).padStart(6, "0")} ${modulePath} ` +
66 `operation=project-transfer-${input.turnIndex + 1}-${input.toolIndex + 1} ` +
67 `cursor=${mix(seed)} digest=${digest(seed)} status=completed\n`;
68 chunks.push(line);
69 length += line.length;
70 lineIndex += 1;
71 }
72
73 return chunks.join("").slice(0, input.targetBytes);
74}