Skip to content

Commit 0ee6a94

Browse files
committed
Apply current lint conventions to rebased compaction changes
1 parent 42b70f3 commit 0ee6a94

55 files changed

Lines changed: 1471 additions & 456 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

evals/compaction/fixtures.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,28 @@ export const REQUIRED_EVIDENCE: readonly Evidence[] = [
2020
{ id: "constraint", source: "operator:initial", value: "no-schema-change" },
2121
{ id: "decision", source: "operator:correction", value: "west-not-east" },
2222
{ id: "failure", source: "command:diagnose", value: "unsupported-format-7" },
23-
{ id: "decisive", source: "file:diagnostic.log:middle", value: "route-cobalt" },
23+
{
24+
id: "decisive",
25+
source: "file:diagnostic.log:middle",
26+
value: "route-cobalt",
27+
},
2428
];
2529

2630
export function evidenceText(facts: readonly Evidence[]): string {
27-
return facts.map((fact) => `[[evidence:${fact.id}|${fact.source}|${fact.value}]]`).join("\n");
31+
return facts
32+
.map((fact) => `[[evidence:${fact.id}|${fact.source}|${fact.value}]]`)
33+
.join("\n");
2834
}
2935

3036
export const INITIAL =
31-
"Audit the deployment. Preserve this constraint: " + evidenceText(REQUIRED_EVIDENCE.slice(0, 1));
37+
"Audit the deployment. Preserve this constraint: " +
38+
evidenceText(REQUIRED_EVIDENCE.slice(0, 1));
3239
export const CORRECTION =
33-
"Correction: target west instead of east. " + evidenceText(REQUIRED_EVIDENCE.slice(1, 2));
40+
"Correction: target west instead of east. " +
41+
evidenceText(REQUIRED_EVIDENCE.slice(1, 2));
3442
export const FAILED_OUTPUT =
35-
"Diagnostic preamble.\n".repeat(250) + evidenceText(REQUIRED_EVIDENCE.slice(2, 3));
43+
"Diagnostic preamble.\n".repeat(250) +
44+
evidenceText(REQUIRED_EVIDENCE.slice(2, 3));
3645
export const OVERSIZED_OUTPUT =
3746
"Unrelated diagnostic row.\n".repeat(1500) +
3847
evidenceText(REQUIRED_EVIDENCE.slice(3)) +

evals/compaction/metrics.test.ts

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,25 @@ const baseline = {
3030

3131
describe("compaction baseline grading", () => {
3232
test("requires evidence actually visible to the scripted responder", () => {
33-
expect(recoverEvidence("[[evidence:region|operator:correction|west]]")).toEqual([fact]);
33+
expect(
34+
recoverEvidence("[[evidence:region|operator:correction|west]]"),
35+
).toEqual([fact]);
3436
expect(recoverEvidence("The region was mentioned earlier.")).toEqual([]);
3537
expect(
36-
grade({ ...baseline, recovered: recoverEvidence("evidence removed") }).factualRecovery,
38+
grade({ ...baseline, recovered: recoverEvidence("evidence removed") })
39+
.factualRecovery,
3740
).toBe(false);
3841
});
3942

4043
test("rejects wrong values, sources, and altered artifacts independently", () => {
4144
expect(grade(baseline).passed).toBe(true);
42-
expect(grade({ ...baseline, recovered: [{ ...fact, value: "east" }] }).passed).toBe(false);
43-
expect(grade({ ...baseline, recovered: [{ ...fact, source: "invented" }] }).passed).toBe(false);
45+
expect(
46+
grade({ ...baseline, recovered: [{ ...fact, value: "east" }] }).passed,
47+
).toBe(false);
48+
expect(
49+
grade({ ...baseline, recovered: [{ ...fact, source: "invented" }] })
50+
.passed,
51+
).toBe(false);
4452
const altered = grade({ ...baseline, artifact: "east\n" });
4553
expect(altered.completion).toBe(false);
4654
expect(altered.factualRecovery).toBe(true);
@@ -50,9 +58,13 @@ describe("compaction baseline grading", () => {
5058
expect(grade({ ...baseline, folds: [] }).qualifying).toBe(false);
5159
for (const fold of folds) {
5260
expect(qualifyingFold({ ...fold, persisted: false })).toBe(false);
53-
expect(qualifyingFold({ ...fold, afterHash: fold.beforeHash })).toBe(false);
61+
expect(qualifyingFold({ ...fold, afterHash: fold.beforeHash })).toBe(
62+
false,
63+
);
5464
expect(qualifyingFold({ ...fold, continuedAtCall: null })).toBe(false);
55-
expect(qualifyingFold({ ...fold, afterTurns: fold.beforeTurns })).toBe(false);
65+
expect(qualifyingFold({ ...fold, afterTurns: fold.beforeTurns })).toBe(
66+
false,
67+
);
5668
}
5769
expect(grade({ ...baseline, recovered: [] }).requiredFacts).toBe(1);
5870
});
@@ -89,16 +101,23 @@ describe("compaction baseline grading", () => {
89101
});
90102

91103
test("missing usage is unavailable, not zero or an unlabelled estimate", () => {
92-
expect(Measurement({ status: "unavailable", reason: "offline" }) instanceof type.errors).toBe(
93-
false,
94-
);
95104
expect(
96-
Measurement({ status: "reported", value: -1, unit: "tokens" }) instanceof type.errors,
97-
).toBe(true);
98-
expect(Measurement({ value: 0, unit: "tokens" }) instanceof type.errors).toBe(true);
105+
Measurement({ status: "unavailable", reason: "offline" }) instanceof
106+
type.errors,
107+
).toBe(false);
99108
expect(
100-
Measurement({ status: "synthetic", value: 200000, unit: "trigger tokens" }) instanceof
109+
Measurement({ status: "reported", value: -1, unit: "tokens" }) instanceof
101110
type.errors,
111+
).toBe(true);
112+
expect(
113+
Measurement({ value: 0, unit: "tokens" }) instanceof type.errors,
114+
).toBe(true);
115+
expect(
116+
Measurement({
117+
status: "synthetic",
118+
value: 200000,
119+
unit: "trigger tokens",
120+
}) instanceof type.errors,
102121
).toBe(false);
103122
});
104123
});

evals/compaction/metrics.ts

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
import { type } from "arktype";
22

3-
export const Evidence = type({ id: "string", source: "string", value: "string" });
3+
export const Evidence = type({
4+
id: "string",
5+
source: "string",
6+
value: "string",
7+
});
48
export type Evidence = typeof Evidence.infer;
59

610
export const Measurement = type.or(
711
{ status: "'unavailable'", reason: "string" },
8-
{ status: "'reported' | 'estimated' | 'synthetic'", value: "number >= 0", unit: "string" },
12+
{
13+
status: "'reported' | 'estimated' | 'synthetic'",
14+
value: "number >= 0",
15+
unit: "string",
16+
},
917
);
1018
export type Measurement = typeof Measurement.infer;
1119

@@ -54,8 +62,10 @@ export function repeatedWork(trace: readonly Work[]) {
5462
}
5563
if (seen.has(key)) {
5664
if (work.name === "read_file") repeatedReads++;
57-
if (["grep", "search_files", "web_search"].includes(work.name)) repeatedSearches++;
58-
if (["write_file", "edit_file", "apply_patch"].includes(work.name)) duplicatedEdits++;
65+
if (["grep", "search_files", "web_search"].includes(work.name))
66+
repeatedSearches++;
67+
if (["write_file", "edit_file", "apply_patch"].includes(work.name))
68+
duplicatedEdits++;
5969
}
6070
if (failures.has(key)) repeatedFailedAttempts++;
6171
seen.add(key);
@@ -81,15 +91,20 @@ export function grade(args: {
8191
const recoveredFacts = args.expected.filter((fact) =>
8292
args.recovered.some(
8393
(answer) =>
84-
answer.id === fact.id && answer.source === fact.source && answer.value === fact.value,
94+
answer.id === fact.id &&
95+
answer.source === fact.source &&
96+
answer.value === fact.value,
8597
),
8698
).length;
8799
const work = repeatedWork(args.trace);
88100
const persistedFolds = args.folds.filter(qualifyingFold).length;
89101
const completion = args.artifact === args.expectedArtifact;
90102
const factualRecovery = recoveredFacts === args.expected.length;
91103
const repeatedActions =
92-
work.repeatedReads + work.repeatedSearches + work.repeatedFailedAttempts + work.duplicatedEdits;
104+
work.repeatedReads +
105+
work.repeatedSearches +
106+
work.repeatedFailedAttempts +
107+
work.duplicatedEdits;
93108
return {
94109
completion,
95110
factualRecovery,
@@ -98,14 +113,20 @@ export function grade(args: {
98113
persistedFolds,
99114
qualifying: persistedFolds >= 3,
100115
...work,
101-
passed: completion && factualRecovery && persistedFolds >= 3 && repeatedActions === 0,
116+
passed:
117+
completion &&
118+
factualRecovery &&
119+
persistedFolds >= 3 &&
120+
repeatedActions === 0,
102121
};
103122
}
104123

105124
/** The responder receives only inference-visible text, never grader expectations. */
106125
export function recoverEvidence(context: string): Evidence[] {
107126
const facts = new Map<string, Evidence>();
108-
for (const match of context.matchAll(/\[\[evidence:([^|\]\n]+)\|([^|\]\n]+)\|([^\]\n]+)\]\]/g)) {
127+
for (const match of context.matchAll(
128+
/\[\[evidence:([^|\]\n]+)\|([^|\]\n]+)\|([^\]\n]+)\]\]/g,
129+
)) {
109130
const [, id, source, value] = match;
110131
if (id !== undefined && source !== undefined && value !== undefined) {
111132
facts.set(id, { id, source, value });

src/agent/archive-tool-result.test.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ import { stringTool } from "@intx/agent";
66

77
import { withAuthorizedArchiveResult } from "./archive-tool-result.js";
88
import { createPermissionGate } from "../permission/gate.js";
9-
import { createCompactionArchive, type CompactionArchive } from "../session/compaction-archive.js";
9+
import {
10+
createCompactionArchive,
11+
type CompactionArchive,
12+
} from "../session/compaction-archive.js";
1013

1114
function memoryArchive(sessionId: string): CompactionArchive {
1215
const dir = mkdtempSync(join(tmpdir(), "archive-tool-result-"));
@@ -42,18 +45,26 @@ describe("withAuthorizedArchiveResult", () => {
4245
expect(tool.kind).toBe("full");
4346
if (tool.kind !== "full") return;
4447
const result = await tool.handler(
45-
{ id: "call-mt", name: "manage_tasks", arguments: { action: "create", tasks: [] } },
48+
{
49+
id: "call-mt",
50+
name: "manage_tasks",
51+
arguments: { action: "create", tasks: [] },
52+
},
4653
new AbortController().signal,
4754
);
4855
expect(result.content).toBe("listed 1 task");
4956
const occs = await archive.listOccurrences();
50-
const hits = occs.filter((occ) => occ.kind === "tool_result" && occ.callId === "call-mt");
57+
const hits = occs.filter(
58+
(occ) => occ.kind === "tool_result" && occ.callId === "call-mt",
59+
);
5160
expect(hits).toHaveLength(1);
5261
const recorded = hits[0];
5362
expect(recorded?.provenance).toBe("agent:post-policy");
5463
expect(recorded).toBeDefined();
5564
if (recorded === undefined) return;
56-
expect(await archive.readAuthorizedPayload(recorded.occurrenceId)).toContain("listed 1 task");
65+
expect(
66+
await archive.readAuthorizedPayload(recorded.occurrenceId),
67+
).toContain("listed 1 task");
5768
});
5869

5970
test("does not record when the archive getter is omitted", async () => {
@@ -111,8 +122,12 @@ describe("createAgentToolset authorized result capture", () => {
111122
);
112123
expect(posix.isError).toBeFalsy();
113124
const occs = await archive.listOccurrences();
114-
const mt = occs.filter((occ) => occ.kind === "tool_result" && occ.callId === "call-mt");
115-
const rf = occs.filter((occ) => occ.kind === "tool_result" && occ.callId === "call-rf");
125+
const mt = occs.filter(
126+
(occ) => occ.kind === "tool_result" && occ.callId === "call-mt",
127+
);
128+
const rf = occs.filter(
129+
(occ) => occ.kind === "tool_result" && occ.callId === "call-rf",
130+
);
116131
expect(mt).toHaveLength(1);
117132
expect(mt[0]?.provenance).toBe("agent:post-policy");
118133
expect(rf).toHaveLength(1);

src/agent/posix-tool-plugins.test.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,10 @@ describe("buildCorePosixToolPlugins", () => {
393393
permissionGate: gate,
394394
getEvidenceArchive: () => undefined,
395395
});
396-
const shellGuardIndex = findMiddlewareIndex(plugins, "[command timed out after");
396+
const shellGuardIndex = findMiddlewareIndex(
397+
plugins,
398+
"[command timed out after",
399+
);
397400
const archiveIndex = findMiddlewareIndex(
398401
plugins,
399402
"evidence archive is not available in this session",
@@ -436,7 +439,9 @@ describe("buildCorePosixToolPlugins", () => {
436439
new AbortController().signal,
437440
);
438441
expect(result.isError).toBe(true);
439-
expect(String(result.content)).toContain("evidence archive is not available");
442+
expect(String(result.content)).toContain(
443+
"evidence archive is not available",
444+
);
440445
} finally {
441446
await rm(cwd, { recursive: true, force: true });
442447
}

src/agent/posix-tool-plugins.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,9 @@ export function buildCorePosixToolPlugins(
9595
// regardless.
9696
const allowOutside = (): boolean => permissionGate.getSkipPermissions();
9797
const truncationOptions =
98-
getBlobWriter !== undefined || getContextDir !== undefined || getEvidenceArchive !== undefined
98+
getBlobWriter !== undefined ||
99+
getContextDir !== undefined ||
100+
getEvidenceArchive !== undefined
99101
? {
100102
...(getBlobWriter !== undefined ? { getBlobWriter } : {}),
101103
...(getContextDir !== undefined ? { getContextDir } : {}),

src/agent/prompts.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,8 @@ export function buildPromptDisciplineBlock(
225225
}
226226

227227
const TOOL_SUMMARIES: Record<string, string> = {
228-
read_file: "read a file or tool-output:///{callId} (prefer over cat/head/tail in the shell)",
228+
read_file:
229+
"read a file or tool-output:///{callId} (prefer over cat/head/tail in the shell)",
229230
write_file: "create or overwrite a file (never shell redirects or heredocs)",
230231
edit_file:
231232
"make a surgical edit (exact old_string match, or start_line/end_line line-range mode; never include read_file's NNNNNN\\t line prefix; substring failures include nearby file text; prefer over sed/awk in the shell)",
@@ -278,7 +279,9 @@ export function buildAvailableTools(
278279
opts.advertiseArchive === true
279280
? { ...TOOL_SUMMARIES, ...ARCHIVE_TOOL_SUMMARIES }
280281
: TOOL_SUMMARIES;
281-
const lines = tools.map((tool) => `- ${tool}: ${summaries[tool] ?? "available"}`);
282+
const lines = tools.map(
283+
(tool) => `- ${tool}: ${summaries[tool] ?? "available"}`,
284+
);
282285
return ["Tools:", ...lines].join("\n");
283286
}
284287

@@ -373,9 +376,12 @@ export function buildChatSystemPrompt(
373376
): string {
374377
const sections = [
375378
baseSection(baseOverride, sessionMode),
376-
buildAvailableTools(coreToolNamesForSessionMode(sessionMode, toolAvailability), {
377-
advertiseArchive: true,
378-
}),
379+
buildAvailableTools(
380+
coreToolNamesForSessionMode(sessionMode, toolAvailability),
381+
{
382+
advertiseArchive: true,
383+
},
384+
),
379385
];
380386
if (skills.length > 0) sections.push(buildSkillsSection(skills));
381387
sections.push(contextSection(env));

src/agent/tools.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,9 @@ export async function createAgentToolset(
434434
}),
435435
});
436436

437-
const posixToolNames = new Set(posixTools.definitions.map((definition) => definition.name));
437+
const posixToolNames = new Set(
438+
posixTools.definitions.map((definition) => definition.name),
439+
);
438440

439441
// Codex apply_patch proxy forwards ops through posixTools.run so permission
440442
// plugins (gate, path policy, etc.) still apply — same call shape as
@@ -545,7 +547,8 @@ export async function createAgentToolset(
545547
let definition = advertiseEditFileLineRange(
546548
advertiseShellGuardTimeout(tool.definition, shellTimeout?.defaultMs),
547549
);
548-
if (getEvidenceArchive !== undefined) definition = advertiseArchiveSurface(definition);
550+
if (getEvidenceArchive !== undefined)
551+
definition = advertiseArchiveSurface(definition);
549552
return { ...tool, definition };
550553
}),
551554
createListDirTool(cwd, {

0 commit comments

Comments
 (0)