1const PULL_REQUEST_LINKING_INSTRUCTIONS = `<pull_request_linking>
2When the t3-code MCP server exposes link_pull_request, you must use it to register every pull request you create or work on for this thread. Call link_pull_request with the full PR URL immediately after creating a PR or starting work on an existing PR. For a stack, call it for every layer, not just the current branch or the top PR. This applies when creating or updating PRs through gh, gh stack, another CLI, or the host API: those operations do not register the PRs with this thread. Linking an already-linked PR is safe. Before finishing PR work, call list_thread_pull_requests and link any PR from your work that is missing. Do not link unrelated PRs mentioned only as background. If a linking call fails, report that failure instead of claiming the PR is linked. When asked to monitor, watch, or babysit a PR and watch_pull_request is available, call it and end your turn: T3 Code wakes you when checks finish, someone else comments, or the branch conflicts, so do not poll or run your own watcher. When you hand the work back to the user, call unwatch_pull_request first so the thread returns to their inbox.
3</pull_request_linking>`;
4
5/**
6 * Shared runtime context; omit model and effort when the harness manages them dynamically.
7 * `modelName` is the display name users see in the model picker; `model` is the slug.
8 */
9export function buildRuntimeInstructions(runtime: {
10 readonly harness: string;
11 readonly model?: string | undefined;
12 readonly modelName?: string | undefined;
13 readonly reasoningEffort?: string | undefined;
14}): string {
15 const harness = toSingleLine(runtime.harness);
16 const model = toSingleLine(runtime.model ?? "");
17 const modelName = toSingleLine(runtime.modelName ?? "");
18 const effort = toSingleLine(runtime.reasoningEffort ?? "");
19 const modelLabel =
20 modelName && modelName !== model ? `${modelName} (model slug: ${model})` : model;
21 const modelInfo = model && model !== "auto" && model !== "default" ? `, as ${modelLabel}` : "";
22 const effortInfo = effort ? ` with ${effort} reasoning effort` : "";
23 return `<runtime_info>In case you're asked: you are running in T3 Code through the ${harness} harness${modelInfo}${effortInfo}. No need to mention this otherwise. You can embed images and videos in your response using Markdown with absolute file paths.</runtime_info>\n\n${PULL_REQUEST_LINKING_INSTRUCTIONS}`;
24}
25
26function toSingleLine(value: string): string {
27 return value.replaceAll(/\s+/g, " ").trim();
28}