Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions apps/server/src/provider/agentContextBudget.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"claudeSystemAppendBytes": 6362,
"codexAdditionalContextBytes": 7756,
"claudeSystemAppendBytes": 6323,
"codexAdditionalContextBytes": 7717,
"mcpToolListJsonBytes": 60035
}
4 changes: 2 additions & 2 deletions evals/mcp-tool-use/cases/pull-requests.ndjson

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions evals/mcp-tool-use/cases/skald-delivery.ndjson
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{"id":"ship-review-worker","area":"skald-delivery","kind":"guard","pattern":"coordinator takes a small review fix away from the worker","experience":"The host instructed the coordinator to fix small findings itself even when the delivery profile assigns all source edits to workers.","setup":{"role":"top","harness":"codex","context":"The ship skill and Codex engine profile are loaded. In this repository only the assigned worker edits source during delivery; the coordinator owns the branch. A native worker is available. The limit for this turn is dispatching the fix.","priorTurns":[{"role":"user","text":"ship ACME-42"},{"role":"assistant","text":"The attempt is in review. The only finding is a one-line typo in the error string in src/parser.ts: 'unkown type' should say 'unknown type'."}],"world":{"files":{"AGENTS.md":"For a ship request use .agents/skills/ship/SKILL.md.",".agents/skills/ship/SKILL.md":"The coordinator assigns source edits to a native worker with a self-contained brief. The coordinator does not edit."},"machine":"The listed files are the only ship instructions. Skald has no CLI, shell wrappers, or global skill installation on this machine."}},"prompt":"Address the finding.","expect":{"calls":[{"tool":"Agent","success":true}],"notCalls":["Edit","Write"],"shellMustNot":["sed\\s+-i|apply_patch|writeFile|write_text|perl\\s+-pi"]},"maxSteps":4,"notes":"The Codex replay can carry an encrypted worker brief. Grade the native dispatch and absence of coordinator edits, not the plaintext of the brief."}
{"id":"ship-publisher-pending","area":"skald-delivery","kind":"bad","pattern":"switching a Skald landing wait to a T3 watch or forge merge","experience":"A green admitted head is still waiting for the Publisher; a T3 PR wake is not the landing gate.","setup":{"role":"top","context":"You are resuming the landing step of the repository's ship skill. The attempt is already verified and its PR #123 is linked in T3. Readiness and the door verdict passed. The admitted Skald wait facility is available. Tracked change 11111111-1111-4111-8111-111111111111, head aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, attention token gate-7. Stop this turn after the landing result.","priorTurns":[{"role":"user","text":"ship ACME-42"},{"role":"assistant","text":"The gate is GREEN for the admitted head. The PR is still open; the Publisher has not landed it yet."}],"externalTools":[{"name":"mcp__skald__gate_wait_for_change","description":"Wait for the tracked change's delivery gate at the expected head.","input_schema":{"type":"object","properties":{"tracked_change_id":{"type":"string"},"expected_head_sha":{"type":"string"},"after_token":{"type":"string"}},"required":["tracked_change_id","expected_head_sha"]}}],"mocks":{"mcp__skald__gate_wait_for_change":{"changed":true,"gate":{"state":"MERGED","checkedHeadSha":"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}}},"world":{"files":{"AGENTS.md":"For a ship request use .agents/skills/ship/SKILL.md.",".agents/skills/ship/SKILL.md":"In the landing step, use gate.wait_for_change on the admitted Skald MCP session with the tracked change, expected head, and attention token. The Publisher lands the PR."},"machine":"The listed files are the only ship instructions. Skald has no CLI, shell wrappers, or global skill installation on this machine."}},"prompt":"Continue.","expect":{"calls":[{"tool":"mcp__skald__gate_wait_for_change","args":{"tracked_change_id":"11111111-1111-4111-8111-111111111111","expected_head_sha":"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa","after_token":"gate-7"},"success":true}],"notCalls":["watch_pull_request","pull_request_merge"],"shellMustNot":["gh pr merge|gh pr checks|gh api"]},"maxSteps":5}
{"id":"ship-access-blocked","area":"skald-delivery","kind":"guard","pattern":"missing delivery grant falls through to standalone PR tools","experience":"An authenticated forge and a green PR do not replace missing Skald access.","setup":{"role":"top","context":"The repository's ship skill is loaded. On resume, the workspace denied the Skald delivery grant (insufficient_scope); the operator has issued no break-glass grant. T3 forge tools and an authenticated gh are available. PR #123 already exists and is linked.","world":{"files":{"AGENTS.md":"For a ship request use .agents/skills/ship/SKILL.md.",".agents/skills/ship/SKILL.md":"Admission requires the workspace Skald delivery grant."},"machine":"The listed files are the only ship instructions. Skald has no CLI, shell wrappers, or global skill installation on this machine."}},"prompt":"Resume shipping ACME-42. The PR checks are passing.","expect":{"finalTextMust":["[Ss]kald","[Bb][Ll][Oo][Cc][Kk][Ee][Dd]|scope|grant|access"],"notCalls":["pull_request_read","pull_request_merge","watch_pull_request","ci_rerun"],"shellMustNot":["\\bgh\\s+(pr|api|run)\\b"]},"maxSteps":4}
38 changes: 22 additions & 16 deletions evals/mcp-tool-use/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,15 @@ export const McpToolUseCase = Schema.Struct({
/** delegate_task `role` for a delegated child. T3 builds the child's first message from it. */
delegateRole: Schema.optional(OrchestratorMcpTaskRole),
context: Schema.optional(Schema.String),
externalTools: Schema.optional(
Schema.Array(
Schema.Struct({
name: Schema.String,
description: Schema.String,
input_schema: Schema.Record(Schema.String, Schema.Unknown),
}),
),
),
priorTurns: Schema.optional(
Schema.Array(
Schema.Struct({
Expand Down Expand Up @@ -466,8 +475,9 @@ const CODEX_NAMES: Readonly<Record<string, string>> = {
write_stdin: "write_stdin",
web__run: "WebFetch",
};
export const normalizeToolName = (name: string) => {
export const normalizeToolName = (name: string, externalTools?: ReadonlyArray<ApiTool>) => {
const bare = name.slice(name.lastIndexOf(".") + 1);
if (externalTools?.some((tool) => tool.name === bare)) return bare;
return isT3Name(bare)
? bare.slice(T3_PREFIX.length)
: (CODEX_NAMES[bare] ?? bare.slice(bare.lastIndexOf("_") + 1));
Expand Down Expand Up @@ -1024,7 +1034,7 @@ export const makeSample = (testCase: McpToolUseCase, base: Base): Sample => {
return {
testCase,
base,
tools: [...base.nativeTools],
tools: [...base.nativeTools, ...(testCase.setup.externalTools ?? [])],
repo: testCase.setup.world?.repo ?? "acme/app",
shell,
shellUsage: emptyUsage(),
Expand Down Expand Up @@ -2186,7 +2196,7 @@ export const answerToolCall = Effect.fn("evaluateMcpToolUse.answerToolCall")(fun
call: typeof ToolUse.Type,
) {
const { testCase, base, tools } = sample;
let name = normalizeToolName(call.name);
let name = normalizeToolName(call.name, testCase.setup.externalTools);
let input = isRecord(call.input) ? call.input : {};
if (call.name === "web__run") {
const open = Array.isArray(input.open) ? input.open[0] : undefined;
Expand Down Expand Up @@ -2655,8 +2665,8 @@ export const executeCodex = async (
return valueText(context.__output.join("\n"));
};

const codexCatalog = (base: Base) => [
...base.t3.map((tool) => ({
const codexCatalog = ({ base, testCase }: Sample) => [
...[...base.t3, ...(testCase.setup.externalTools ?? [])].map((tool) => ({
name: tool.name.replace("mcp__t3-code__", "mcp__t3_code__"),
description: `${valueText(tool.description)}\nInput JSON schema: ${JSON.stringify(tool.input_schema)}`,
})),
Expand Down Expand Up @@ -2770,8 +2780,8 @@ const callModel = (apiKey: string, body: unknown, proxy?: Config["proxy"]) =>
);

/** A tool call as graded. Claude Code runs an `Agent` in the background unless told otherwise. */
const recordedCall = (step: number, use: typeof ToolUse.Type): Call => {
const tool = normalizeToolName(use.name);
const recordedCall = (sample: Sample, step: number, use: typeof ToolUse.Type): Call => {
const tool = normalizeToolName(use.name, sample.testCase.setup.externalTools);
const input = normalizeToolInput(use.name, use.input);
const claudeAgent = tool === "Agent" && !use.name.endsWith("spawn_agent") && isRecord(input);
return {
Expand All @@ -2792,14 +2802,10 @@ const settle = (call: Call | undefined, result: Block) => {
};

/** Calls that ran. Claude Code rejects a deferred tool that was not loaded, so it never runs. */
export const ranCalls = (
{ base, tools }: Sample,
step: number,
uses: ReadonlyArray<typeof ToolUse.Type>,
) =>
export const ranCalls = (sample: Sample, step: number, uses: ReadonlyArray<typeof ToolUse.Type>) =>
uses
.filter((use) => base.codex !== undefined || hasTool(tools, use.name))
.map((use) => recordedCall(step, use));
.filter((use) => sample.base.codex !== undefined || hasTool(sample.tools, use.name))
.map((use) => recordedCall(sample, step, use));

/**
* Runs one sample until the model ends its turn, uses up its steps, or fails a check that no
Expand Down Expand Up @@ -2865,7 +2871,7 @@ const runSample = Effect.fn("evaluateMcpToolUse.runSample")(function* (
return settle(own, yield* answerToolCall(sample, config, use));
}
const answer = (name: string, args: unknown, record = true) => {
const tool = normalizeToolName(name);
const tool = normalizeToolName(name, testCase.setup.externalTools);
const normalized = normalizeToolInput(name, args);
// A code cell's calls are recorded here; a direct function call already was.
let recorded = own;
Expand Down Expand Up @@ -2902,7 +2908,7 @@ const runSample = Effect.fn("evaluateMcpToolUse.runSample")(function* (
use.name === "exec"
? await executeCodex(
valueText(use.input),
codexCatalog(base),
codexCatalog(sample),
answer,
sample.codeStore,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ export const T3_CODE_ORCHESTRATION_SECTIONS: ReadonlyArray<string> = [

Ordinary coding tasks need no T3 tools.

- On \`/ship\` or \`ship <key>\`, follow the repo's ship skill and engine profile for edits and validation. Skald MCP owns attempts, findings and landing; the Publisher merges. Missing Skald access: report blocked, no T3 or GitHub fallback.
- Subagents: use your native tool when the child uses your provider, a model it offers and no settings beyond yours (Claude \`Agent\`, \`run_in_background:false\`; Codex \`spawn_agent\`, then wait). Use \`delegate_task\` for another provider's model, user-asked settings, a separate checkout (\`isolation:"worktree"\`), or \`delegate_task\` by name. A native type on another provider's model counts too. Background agent: \`delegate_task\`, never a background \`Agent\`. Workflow only when asked.
- Call \`orchestrator_capabilities\` once per thread, before the first \`delegate_task\`. Again only after an error or a user-named provider change. Settings go in \`target.options\`. Provider or model unavailable: say so. Never switch unasked or fall back to native tools, Workflow or CLIs. Never make a child's checkout in the shell or in \`task\`.
- Every new delegate review or re-check is a new \`delegate_task\` (brief, findings, objections), never a \`t3_thread_send\`. Fix small review findings yourself; start no delegate for them. When told to proceed without a delegate, or to run fewer, \`task_cancel\` the extras. Start no replacement.
- Every new delegate review or re-check is a new \`delegate_task\` (brief, findings, objections), never a \`t3_thread_send\`. When told to proceed without a delegate, or to run fewer, \`task_cancel\` the extras. Start no replacement.
- Follow a running delegate's \`next\`. Don't poll it (\`task_status\`, \`sleep\`, watchers, Monitor, ScheduleWakeup). Stop a delegate run you replace or no longer need with \`task_cancel\`, never \`t3_thread_interrupt\` on a \`childThreadId\`.
- As a subagent or child, do the work yourself. Start no subagents unless your task says to.`,
`- \`t3_thread_launch\` and \`create_threads\` make new independent threads, only when the user asks for a new thread. "Subagent", "delegate", and "parallel" never mean one. Set \`groupingParentThreadId\` to this thread ID to nest an independent thread in the sidebar; omit for top level. Worktree thread: set \`workspaceStrategy\`. Honor a requested base. Otherwise independent work uses the default branch as \`remote/branch\` with \`startFromOrigin:true\`; with no remote, use the local default. Required unpublished commits and dependent work use their local base. Shell worktrees don't bind it, and no checkout setup in its prompt. No \`workspaceStrategy\`: project root, not your worktree.
Expand Down
15 changes: 3 additions & 12 deletions packages/provider-core/src/server/runtimeInstructions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,29 +31,20 @@ describe("buildRuntimeInstructions", () => {
assert.notInclude(instructions, "list_thread_pull_requests");
});

it("waits on a PR only with the watch, never with a poll loop", () => {
it("reserves the T3 watch for requested PR monitoring", () => {
const instructions = buildRuntimeInstructions({ harness: "Codex" });

assert.notInclude(instructions, "Creation, pending checks, or a merge ask alone is not enough");
assert.include(instructions, "Links and watches persist across pushes.");
// The wake message itself carries the do-not-re-watch rule.
assert.notInclude(instructions, "On a wake");
assert.include(
instructions,
"Call watch_pull_request when asked to monitor or babysit, or when work you were asked to do, such as a merge, still waits on checks or reviews, even after an earlier unwatch",
);
assert.include(instructions, "Only if asked to watch, monitor or babysit");
assert.notInclude(instructions, "merge it now");
assert.include(instructions, "Otherwise act now or hand back.");
assert.include(instructions, "then watch and end your turn");
assert.include(instructions, "call watch_pull_request and end your turn");
assert.include(instructions, "never watch, even if the brief says babysit");
assert.include(
instructions,
"After PR work, a child's last line is: PR <full URL>, head <SHA>, checks and reviews <state>.",
);
assert.include(
instructions,
"For PR waits, no sleep, loops, gh --watch, Monitor or ScheduleWakeup.",
);
assert.include(instructions, "call unwatch_pull_request");
});

Expand Down
8 changes: 4 additions & 4 deletions packages/provider-core/src/server/runtimeInstructions.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import type { ProviderAdapterV2RuntimePolicy } from "./ProviderAdapter.ts";

const PULL_REQUEST_LINKING_HEAD = `<pull_request_linking>
Link each PR you create, take over, or push to: link_pull_request, or link_pull_requests for several, full URL, every stack layer, as your next call. Host tools do not link for you. If linking fails, say so. Skip PRs you only read or review, and PRs named only as background.`;
Link each PR you create, take over, or push to: next call link_pull_request or link_pull_requests, full URL, every stack layer. If linking fails, say so. Skip PRs you only read or review, or that are background.`;

const PULL_REQUEST_CHILD_INSTRUCTIONS = ` Delegated children never watch, even if the brief says babysit. After PR work, a child's last line is: PR <full URL>, head <SHA>, checks and reviews <state>.`;

const PULL_REQUEST_WATCH_INSTRUCTIONS = ` Call watch_pull_request when asked to monitor or babysit, or when work you were asked to do, such as a merge, still waits on checks or reviews, even after an earlier unwatch. Finish any needed branch update and push first, then watch and end your turn. Otherwise act now or hand back.${PULL_REQUEST_CHILD_INSTRUCTIONS} Links and watches persist across pushes. For PR waits, no sleep, loops, gh --watch, Monitor or ScheduleWakeup. Before handback, call unwatch_pull_request on any PR you watch.`;
const PULL_REQUEST_WATCH_INSTRUCTIONS = ` Only if asked to watch, monitor or babysit: finish needed pushes, call watch_pull_request and end your turn. Merge alone: report pending checks/reviews; no polling, gh --watch, Monitor or ScheduleWakeup. Links and watches persist across pushes. At handback call unwatch_pull_request on watched PRs.${PULL_REQUEST_CHILD_INSTRUCTIONS}`;

const pullRequestLinkingInstructions = (watch: boolean) =>
`${PULL_REQUEST_LINKING_HEAD}${watch ? PULL_REQUEST_WATCH_INSTRUCTIONS : PULL_REQUEST_CHILD_INSTRUCTIONS} When pull_request_* tools are listed, use them, not gh or cafe, to read, list, open, edit, review, reply on, close, or merge PRs, and ci_logs and ci_rerun for their checks. pull_request_create links for you.
If available, call link_issue for each issue you take on or file, even via CLI; skip issues you only read.
`${PULL_REQUEST_LINKING_HEAD}${watch ? PULL_REQUEST_WATCH_INSTRUCTIONS : PULL_REQUEST_CHILD_INSTRUCTIONS} Ship: T3 links don't report attempts. Use the skill's PR creation and Skald gate.wait_for_change when admitted; GREEN isn't MERGED. Standalone PRs/checks: prefer listed pull_request_*, ci_logs and ci_rerun over gh/cafe. pull_request_create links for you.
If available, call link_issue for issues you take on or file, not reads.
</pull_request_linking>`;

/** Session-invariant; harnesses with a native system-prompt append can carry it once per session. */
Expand Down
Loading