@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
ts 73 lines 2.24 KB
Raw
1 import type { ProviderDriverKind } from "@t3tools/contracts";
2 export const TRANSFER_HISTORY_TURN_COUNT = 10;
3 export const TRANSFER_HISTORY_TOOLS_PER_TURN = 5;
4 export const TRANSFER_MEASURED_TOOLS = 20;
5 export const TRANSFER_HISTORY_MCP_RESULT_BYTES = 900_000;
6 export const TRANSFER_MEASURED_MCP_RESULT_BYTES = 1_100_000;
7
8 const 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
28 function 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
38 function 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 export function diagnosticOutput(input: {
49 readonly provider: ProviderDriverKind;
50 readonly turnIndex: number;
51 readonly toolIndex: number;
52 readonly targetBytes: number;
53 }): string {
54 const chunks: string[] = [];
55 const providerSeed = input.provider === "codex" ? 0x43_4f_44_45 : 0x43_4c_41_55;
56 let length = 0;
57 let lineIndex = 0;
58
59 while (length < input.targetBytes) {
60 const modulePath = sourceModules[(input.toolIndex + lineIndex) % sourceModules.length];
61 const seed =
62 providerSeed + input.turnIndex * 100_003 + input.toolIndex * 10_007 + lineIndex * 101;
63 const line =
64 `${String(lineIndex + 1).padStart(6, "0")} ${modulePath} ` +
65 `operation=project-transfer-${input.turnIndex + 1}-${input.toolIndex + 1} ` +
66 `cursor=${mix(seed)} digest=${digest(seed)} status=completed\n`;
67 chunks.push(line);
68 length += line.length;
69 lineIndex += 1;
70 }
71
72 return chunks.join("").slice(0, input.targetBytes);
73 }