Skip to content

28 eval-informed mental models and critical-thinking skills for Claude Code, GitHub Copilot, Codex, Cursor, and other Agent Skills-compatible tools

feat: support tool-enabled isolation and cache token metrics in eval harness

Travis Boudreauxdad5d28c732d
diff --git a/evals/lib/droid.js b/evals/lib/droid.js
index 5fd321f..4efaf00 100644
--- a/evals/lib/droid.js
+++ b/evals/lib/droid.js
@@ -92,16 +92,26 @@ function isolationMetadata(opts = {}) {
return {
enabled,
effective_cwd: effectiveCwd(opts),
- disabled_tools: enabled ? ISOLATION_DISABLED_TOOLS.slice() : [],
+ disabled_tools: enabled
+ ? (opts.restrictTools ? [] : (opts.disabledTools || ISOLATION_DISABLED_TOOLS).slice())
+ : [],
+ restricted_tools: enabled && opts.restrictTools ? opts.restrictTools.slice() : [],
env_allowlist: enabled ? ISOLATION_ENV_ALLOWLIST.slice() : null,
system_prompt_appended: enabled,
+ allow_tool_use: enabled && opts.allowToolUse === true,
};
}
function buildArgs(model, effort, promptFile, opts = {}) {
const args = ['exec', '-m', model, '-r', effort, '-f', promptFile, '--output-format', 'json'];
if (isolationEnabled(opts)) {
- args.push('--disabled-tools', ISOLATION_DISABLED_TOOLS.join(' '), '--append-system-prompt', ISOLATION_PROMPT);
+ const isolation = isolationMetadata(opts);
+ if (isolation.restricted_tools.length) {
+ args.push('--restrict-tools', isolation.restricted_tools.join(' '));
+ } else {
+ args.push('--disabled-tools', isolation.disabled_tools.join(' '));
+ }
+ args.push('--append-system-prompt', opts.appendSystemPrompt || ISOLATION_PROMPT);
}
return args;
}
@@ -237,6 +247,27 @@ function extractJson(text) {
function detectToolLeakage(_text, parsed, isolation) {
if (!isolation || !isolation.enabled || !parsed || typeof parsed !== 'object') return false;
+ if (isolation.allow_tool_use) {
+ if (!isolation.restricted_tools || !isolation.restricted_tools.length) return false;
+ const allowed = new Set(isolation.restricted_tools);
+ const names = [];
+ const collect = (event) => {
+ if (!event || typeof event !== 'object') return;
+ const name = event.name || event.tool_name || (event.tool && event.tool.name);
+ if (name) names.push(String(name));
+ };
+ collect(parsed.tool_use);
+ collect(parsed.function_call);
+ if (Array.isArray(parsed.tool_calls)) parsed.tool_calls.forEach(collect);
+ if (Array.isArray(parsed.tool_events)) parsed.tool_events.forEach(collect);
+ if (Array.isArray(parsed.content)) parsed.content.forEach(collect);
+ if (Array.isArray(parsed.events)) parsed.events.forEach((event) => {
+ collect(event);
+ collect(event && event.tool_use);
+ collect(event && event.tool_call);
+ });
+ return names.some((name) => !allowed.has(name));
+ }
// Structured CLI/tool event fields only. Do NOT regex the model answer text —
// ordinary answers may legitimately mention tools/functions without invoking them.
if (parsed.tool_use || parsed.tool_calls || parsed.function_call || parsed.tool_events) return true;
diff --git a/evals/lib/objective.js b/evals/lib/objective.js
index 5e5849b..01abf25 100644
--- a/evals/lib/objective.js
+++ b/evals/lib/objective.js
@@ -430,6 +430,8 @@ function sumUsage(a, b) {
input_tokens: x.input_tokens + y.input_tokens,
output_tokens: x.output_tokens + y.output_tokens,
cached_tokens: x.cached_tokens + y.cached_tokens,
+ cache_creation_tokens: x.cache_creation_tokens + y.cache_creation_tokens,
+ total_tokens: x.total_tokens + y.total_tokens,
calls: x.calls + y.calls,
latency_ms: x.latency_ms + y.latency_ms,
estimated_cost_usd: x.estimated_cost_usd + y.estimated_cost_usd,
@@ -443,6 +445,8 @@ function normalizeSolveUsage(result, countDefaultCall = false) {
input_tokens: raw.input_tokens || 0,
output_tokens: raw.output_tokens || 0,
cached_tokens: raw.cached_tokens || raw.cache_read_tokens || raw.cache_read_input_tokens || 0,
+ cache_creation_tokens: raw.cache_creation_tokens || raw.cache_creation_input_tokens || 0,
+ total_tokens: raw.total_tokens,
calls: raw.calls != null
? raw.calls
: (value.attempts != null ? value.attempts : (countDefaultCall ? 1 : 0)),
@@ -638,11 +642,13 @@ async function runObjectiveItems(spec) {
{
tokenBudget: arm.tokenBudget,
tokenCounter: scorerOptions.tokenCounter || defaultTokenCounter,
- tail: item.answer_instruction
- ? `\n\n${item.answer_instruction}`
- : (item.decision_instruction
- ? `\n\n${item.decision_instruction}\nEnd your response with exactly: ANSWER: <Yes or No>`
- : undefined),
+ tail: scorerName === 'file_localization'
+ ? '\n\nYour final line must be exactly `ANSWER: path/to/file.ext` with no Markdown, bullets, or trailing text. Do not use Markdown on the ANSWER line.'
+ : (item.answer_instruction
+ ? `\n\n${item.answer_instruction}`
+ : (item.decision_instruction
+ ? `\n\n${item.decision_instruction}\nEnd your response with exactly: ANSWER: <Yes or No>`
+ : undefined)),
},
);
} catch (err) {
@@ -707,6 +713,7 @@ async function runObjectiveItems(spec) {
solveResult = {
ok: false,
text: null,
+ usage: { calls: 0 },
failure: failureRecord({
type: 'transport',
message: err && err.message ? err.message : String(err),
@@ -776,6 +783,7 @@ async function runObjectiveItems(spec) {
value: null,
prompt_sha256: promptHash,
response_sha256: solveResult && solveResult.text != null ? sha256(solveResult.text) : null,
+ archive_uri: solveResult && solveResult.archive_uri || null,
usage: rowUsage,
failure,
attempts: solveResult && solveResult.attempts != null ? solveResult.attempts : null,
@@ -838,6 +846,7 @@ async function runObjectiveItems(spec) {
value: score.value,
prompt_sha256: promptHash,
response_sha256: responseHash,
+ archive_uri: solveResult.archive_uri || null,
usage: rowUsage,
failure,
attempts: solveResult.attempts != null ? solveResult.attempts : null,
@@ -861,6 +870,7 @@ async function runObjectiveItems(spec) {
value: score.value,
prompt_sha256: promptHash,
response_sha256: responseHash,
+ archive_uri: solveResult.archive_uri || null,
usage: rowUsage,
failure: null,
attempts: solveResult.attempts != null ? solveResult.attempts : null,
diff --git a/evals/lib/result.js b/evals/lib/result.js
index 6a4b388..3e04583 100644
--- a/evals/lib/result.js
+++ b/evals/lib/result.js
@@ -80,10 +80,18 @@ function failureRecord({ type, message, itemId = null, armId = null, trial = nul
}
function defaultUsage(usage = {}) {
+ const inputTokens = Number(usage.input_tokens || 0);
+ const outputTokens = Number(usage.output_tokens || 0);
+ const cachedTokens = Number(usage.cached_tokens || 0);
+ const cacheCreationTokens = Number(usage.cache_creation_tokens || 0);
return {
- input_tokens: Number(usage.input_tokens || 0),
- output_tokens: Number(usage.output_tokens || 0),
- cached_tokens: Number(usage.cached_tokens || 0),
+ input_tokens: inputTokens,
+ output_tokens: outputTokens,
+ cached_tokens: cachedTokens,
+ cache_creation_tokens: cacheCreationTokens,
+ total_tokens: usage.total_tokens != null
+ ? Number(usage.total_tokens)
+ : inputTokens + outputTokens + cachedTokens + cacheCreationTokens,
calls: Number(usage.calls || 0),
latency_ms: Number(usage.latency_ms || 0),
estimated_cost_usd: Number(usage.estimated_cost_usd || 0),
diff --git a/evals/tests/droid.test.js b/evals/tests/droid.test.js
index 31edba2..4b6f061 100644
--- a/evals/tests/droid.test.js
+++ b/evals/tests/droid.test.js
@@ -181,6 +181,63 @@ test('tool leakage under isolation is typed tool_leakage', async () => {
assert.equal(r.failure.type, 'tool_leakage');
});
+test('tool-enabled isolation permits read tools with custom restrictions', async () => {
+ let captured = null;
+ const r = await executeDroid({
+ model: 'fixture-model',
+ prompt: 'inspect the checkout',
+ isolate: true,
+ allowToolUse: true,
+ cwd: '/tmp/checkout',
+ restrictTools: ['Read', 'LS', 'Grep', 'Glob'],
+ appendSystemPrompt: 'Use only read-only repository tools.',
+ runner: makeRunner(async (ctx) => {
+ captured = ctx;
+ return {
+ status: 0,
+ stdout: droidStdout('ANSWER: src/owner.js', {
+ extra: { tool_use: { name: 'Grep', input: { pattern: 'owner' } } },
+ }),
+ stderr: '',
+ error: null,
+ timedOut: false,
+ durationMs: 8,
+ };
+ }),
+ });
+ assert.equal(r.ok, true);
+ assert.equal(r.failure, null);
+ assert.equal(r.isolation.allow_tool_use, true);
+ assert.equal(r.isolation.effective_cwd, '/tmp/checkout');
+ const restrictedAt = captured.args.indexOf('--restrict-tools');
+ assert.equal(captured.args[restrictedAt + 1], 'Read LS Grep Glob');
+ assert.equal(captured.args.includes('--disabled-tools'), false);
+ const promptAt = captured.args.indexOf('--append-system-prompt');
+ assert.equal(captured.args[promptAt + 1], 'Use only read-only repository tools.');
+});
+
+test('tool-enabled isolation rejects tool events outside explicit restrictions', async () => {
+ const r = await executeDroid({
+ model: 'fixture-model',
+ prompt: 'inspect',
+ isolate: true,
+ allowToolUse: true,
+ restrictTools: ['Read', 'LS', 'Grep', 'Glob'],
+ runner: makeRunner(async () => ({
+ status: 0,
+ stdout: droidStdout('unexpected execution', {
+ extra: { tool_use: { name: 'Execute', input: { command: 'pwd' } } },
+ }),
+ stderr: '',
+ error: null,
+ timedOut: false,
+ durationMs: 2,
+ })),
+ });
+ assert.equal(r.ok, false);
+ assert.equal(r.failure.type, 'tool_leakage');
+});
+
test('answer text mentioning tools is not tool_leakage', async () => {
const r = await executeDroid({
model: 'fixture-model',
diff --git a/evals/tests/objective.test.js b/evals/tests/objective.test.js
index 2c14fa4..8b705d7 100644
--- a/evals/tests/objective.test.js
+++ b/evals/tests/objective.test.js
@@ -294,6 +294,25 @@ test('runObjectiveItems retains every attempted arm/item/trial including failure
assert.equal(envelope.usage.calls, 0);
});
+test('a solve callback that throws before transport records zero model calls', async () => {
+ const envelope = await runObjectiveItems({
+ studyId: 'pre-call-failure',
+ studyVersion: '1',
+ preregistrationSha256: 'p'.repeat(64),
+ dataset: { source: 'fixture', version: '1', split: 'heldout', sha256: 'd'.repeat(64) },
+ arms: [{ id: 'none' }],
+ solver: { model: 'fixture-model' },
+ scorer: 'boolean',
+ items: [{ id: 'i1', prompt: 'Question?', label: true }],
+ solve: async () => {
+ throw new Error('budget stopped before call');
+ },
+ });
+ assert.equal(envelope.health.attempted, 1);
+ assert.equal(envelope.usage.calls, 0);
+ assert.equal(envelope.items[0].usage.calls, 0);
+});
+
test('none control prompt used for none arm; skill arm injects body', async () => {
const seen = [];
const envelope = await runObjectiveItems({
@@ -324,6 +343,34 @@ test('none control prompt used for none arm; skill arm injects body', async () =
assert.match(skillP, /UNIQUE_SKILL_BODY_XYZ/);
});
+test('file-localization decision instruction is not followed by a Boolean answer tail', async () => {
+ let seenPrompt = null;
+ const instruction = 'End with exactly: ANSWER: <path/to/file.ext>';
+ const envelope = await runObjectiveItems({
+ studyId: 'file-tail',
+ studyVersion: '1',
+ preregistrationSha256: 'p'.repeat(64),
+ dataset: { source: 'fixture', version: '1', split: 'heldout', sha256: 'd'.repeat(64) },
+ arms: [{ id: 'none' }],
+ solver: { model: 'fixture-model' },
+ scorer: 'file_localization',
+ items: [{
+ id: 'one',
+ prompt: `Which source file owns this behavior?\n${instruction}`,
+ gold_files: ['src/owner.js'],
+ }],
+ solve: async ({ prompt }) => {
+ seenPrompt = prompt;
+ return { ok: true, text: 'ANSWER: src/owner.js', usage: { calls: 1 } };
+ },
+ });
+
+ assert.equal(envelope.items[0].correct, true);
+ assert.match(seenPrompt, /ANSWER: <path\/to\/file\.ext>/);
+ assert.doesNotMatch(seenPrompt, /ANSWER: <Yes or No>/);
+ assert.match(seenPrompt, /Do not use Markdown/);
+});
+
// --- routing balanced accuracy nulls ---
test('balanced accuracy treats null predictions as incorrect on both classes', () => {
@@ -455,12 +502,15 @@ test('live solve usage counts attempts latency cache and estimated cost', async
solve: async () => ({
ok: true,
text: 'ANSWER: Yes',
+ archive_uri: 'file:///tmp/response.txt',
attempts: 1,
durationMs: 25,
usage: {
input_tokens: 7,
output_tokens: 3,
cache_read_tokens: 2,
+ cache_creation_tokens: 5,
+ total_tokens: 17,
est_cost_usd: 0.004,
},
}),
@@ -469,10 +519,13 @@ test('live solve usage counts attempts latency cache and estimated cost', async
input_tokens: 7,
output_tokens: 3,
cached_tokens: 2,
+ cache_creation_tokens: 5,
+ total_tokens: 17,
calls: 1,
latency_ms: 25,
estimated_cost_usd: 0.004,
});
+ assert.equal(envelope.items[0].archive_uri, 'file:///tmp/response.txt');
});
// --- arm order randomization ---