Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

CodexDeveloperInstructions.ts

63 lines2.7 KB

1import type { V2TurnStartParams__AdditionalContextEntry } from "effect-codex-app-server/schema";
2import { buildRuntimeInstructions } from "@t3tools/provider-core/server/runtimeInstructions";
3​
4import {
5 T3_CODE_BROWSER_TOOL_INSTRUCTIONS,
6 T3_CODE_ORCHESTRATION_SECTIONS,
7} from "@t3tools/provider-core/server/orchestrationInstructions";
8​
9/** Codex silently truncates additionalContext values over 1,000 tokens, counted as UTF-8 bytes / 4. */
10export const CODEX_ADDITIONAL_CONTEXT_VALUE_MAX_BYTES = 4_000;
11​
12const T3_CODE_DEVICE_TOOL_INSTRUCTIONS = `## T3 Code devices
13​
14For iOS Simulators and Android Emulators here, call \`device_list\`, then \`device_open\`. Drive the device with the exact \`agent-device\` launcher and flags it returns, on every command. Prefer \`agent-device snapshot -i\` refs over coordinates. Use \`device_screenshot\` to see the screen. Use \`xcrun simctl\` or \`adb\` only for builds, logs, and ports. If a platform is unavailable, say so.`;
15​
16export interface T3CodeToolAvailability {
17 readonly browser: boolean;
18 readonly device: boolean;
20​
21const normalizeAvailability = (
22 availability: boolean | T3CodeToolAvailability,
23): T3CodeToolAvailability =>
24 typeof availability === "boolean" ? { browser: availability, device: false } : availability;
25​
26/** Instructions for unavailable tools would steer the model away from its remaining automation. */
27const toolInstructions = (availability: boolean | T3CodeToolAvailability): string => {
28 const tools = normalizeAvailability(availability);
29 return [
30 tools.browser ? T3_CODE_BROWSER_TOOL_INSTRUCTIONS : "",
31 tools.device ? T3_CODE_DEVICE_TOOL_INSTRUCTIONS : "",
32 ]
33 .filter(Boolean)
34 .join("\n\n");
35};
36​
37export interface CodexRuntimeInfo {
38 readonly model: string;
39 readonly modelName?: string | undefined;
40 readonly reasoningEffort?: string | undefined;
42​
43/** Keep this outside collaboration mode; model-catalog mode text overrides client developer_instructions. */
44export function buildCodexAdditionalContext(
45 runtime: CodexRuntimeInfo,
46 toolsAvailable: boolean | T3CodeToolAvailability = true,
47): Record<string, V2TurnStartParams__AdditionalContextEntry> {
48 const tools = toolInstructions(toolsAvailable);
49 // Split values to fit per-entry caps; number keys because Codex emits them in key order.
50 return {
51 ...Object.fromEntries(
52 T3_CODE_ORCHESTRATION_SECTIONS.map((section, index) => [
53 `t3_code_orchestration_${String(index + 1).padStart(2, "0")}`,
54 { kind: "application" as const, value: section },
55 ]),
56 ),
57 t3_code_runtime: {
58 kind: "application",
59 value: buildRuntimeInstructions({ harness: "Codex", ...runtime }),
60 },
61 ...(tools ? { t3_code_tools: { kind: "application", value: tools } } : {}),
62 };