haansi 0.1.98 → 0.1.100
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/haansi.js +357 -28
- package/package.json +1 -1
package/dist/haansi.js
CHANGED
|
@@ -95,7 +95,7 @@ var require_package = __commonJS({
|
|
|
95
95
|
"package.json"(exports2, module2) {
|
|
96
96
|
module2.exports = {
|
|
97
97
|
name: "haansi",
|
|
98
|
-
version: "0.1.
|
|
98
|
+
version: "0.1.100",
|
|
99
99
|
description: "Haansi CLI - Session collector and MCP server for Claude Code & OpenAI Codex",
|
|
100
100
|
bin: {
|
|
101
101
|
haansi: "./dist/haansi.js"
|
|
@@ -19550,6 +19550,22 @@ var init_exclusions = __esm({
|
|
|
19550
19550
|
target_diff_sha: [
|
|
19551
19551
|
"not-personal",
|
|
19552
19552
|
"The target commit SHA its stored diff was read at."
|
|
19553
|
+
],
|
|
19554
|
+
context_state: [
|
|
19555
|
+
"operational",
|
|
19556
|
+
"Closed CHECK vocabulary (found, missed, none)."
|
|
19557
|
+
],
|
|
19558
|
+
context_relevant_ids: [
|
|
19559
|
+
"join-key",
|
|
19560
|
+
"Ids of Haansi items (solution:\u2026, skill:\u2026) the relevance judge found bear on the task."
|
|
19561
|
+
],
|
|
19562
|
+
context_judge_tag: [
|
|
19563
|
+
"operational",
|
|
19564
|
+
"The prompt version that judged relevance (replay-relevance-judge-vN)."
|
|
19565
|
+
],
|
|
19566
|
+
context_inputs_fingerprint: [
|
|
19567
|
+
"derived",
|
|
19568
|
+
"A SHA-256 of the task's inputs; not reversible."
|
|
19553
19569
|
]
|
|
19554
19570
|
}),
|
|
19555
19571
|
...exchangeExclusions(INTEL, "problem_family_members", {
|
|
@@ -86430,9 +86446,9 @@ function readTools(result) {
|
|
|
86430
86446
|
}));
|
|
86431
86447
|
}
|
|
86432
86448
|
function firstSentence(text) {
|
|
86433
|
-
const
|
|
86434
|
-
const end =
|
|
86435
|
-
const sentence = end >= 0 ?
|
|
86449
|
+
const flat3 = text.replace(/\s+/g, " ").trim();
|
|
86450
|
+
const end = flat3.search(/[.!?](\s|$)/);
|
|
86451
|
+
const sentence = end >= 0 ? flat3.slice(0, end + 1) : flat3;
|
|
86436
86452
|
return sentence.length > 240 ? `${sentence.slice(0, 237)}\u2026` : sentence;
|
|
86437
86453
|
}
|
|
86438
86454
|
async function httpTools(fetchImpl, url2, headers) {
|
|
@@ -86610,18 +86626,34 @@ async function searchHaansi(session, ask, fetchImpl = fetch) {
|
|
|
86610
86626
|
},
|
|
86611
86627
|
sid
|
|
86612
86628
|
).then((r) => r.text().then(rpcResult))
|
|
86629
|
+
] : [],
|
|
86630
|
+
...ask.paths?.length ? [
|
|
86631
|
+
rpc(
|
|
86632
|
+
4,
|
|
86633
|
+
"tools/call",
|
|
86634
|
+
{
|
|
86635
|
+
name: "get_prior_attempts",
|
|
86636
|
+
arguments: {
|
|
86637
|
+
paths: ask.paths,
|
|
86638
|
+
...ask.queries[0] ? { query: ask.queries[0] } : {},
|
|
86639
|
+
limit: PRIOR_ATTEMPTS_LIMIT
|
|
86640
|
+
}
|
|
86641
|
+
},
|
|
86642
|
+
sid
|
|
86643
|
+
).then((r) => r.text().then(rpcResult))
|
|
86613
86644
|
] : []
|
|
86614
86645
|
]);
|
|
86615
86646
|
})() : Promise.resolve();
|
|
86616
86647
|
await Promise.allSettled([...solutions, skills2]);
|
|
86617
86648
|
}
|
|
86618
|
-
var SOLUTIONS_PER_QUERY;
|
|
86649
|
+
var SOLUTIONS_PER_QUERY, PRIOR_ATTEMPTS_LIMIT;
|
|
86619
86650
|
var init_replay_fallback = __esm({
|
|
86620
86651
|
"src/commands/replay-fallback.ts"() {
|
|
86621
86652
|
"use strict";
|
|
86622
86653
|
init_setup_mcp();
|
|
86623
86654
|
init_replay_preflight();
|
|
86624
86655
|
SOLUTIONS_PER_QUERY = 5;
|
|
86656
|
+
PRIOR_ATTEMPTS_LIMIT = 3;
|
|
86625
86657
|
}
|
|
86626
86658
|
});
|
|
86627
86659
|
|
|
@@ -86699,7 +86731,54 @@ function clipReason(text) {
|
|
|
86699
86731
|
const t = text.replace(/\s+/g, " ").trim();
|
|
86700
86732
|
return t.length > MAX_REASON_CHARS ? `${t.slice(0, MAX_REASON_CHARS - 1)}\u2026` : t;
|
|
86701
86733
|
}
|
|
86702
|
-
|
|
86734
|
+
function mcpServersOf(output) {
|
|
86735
|
+
const init2 = jsonLines(output).find(
|
|
86736
|
+
(o) => o.type === "system" && o.subtype === "init"
|
|
86737
|
+
);
|
|
86738
|
+
if (!init2 || !Array.isArray(init2.mcp_servers)) return null;
|
|
86739
|
+
return init2.mcp_servers.map((s) => s ?? {}).filter(
|
|
86740
|
+
(s) => typeof s.name === "string"
|
|
86741
|
+
).map((s) => ({
|
|
86742
|
+
name: s.name,
|
|
86743
|
+
status: typeof s.status === "string" ? s.status : "unknown"
|
|
86744
|
+
}));
|
|
86745
|
+
}
|
|
86746
|
+
function haansiServersDown(output) {
|
|
86747
|
+
const servers = mcpServersOf(output);
|
|
86748
|
+
if (!servers) return null;
|
|
86749
|
+
return servers.filter((s) => s.name.startsWith("haansi-") && s.status !== "connected").map((s) => `${s.name}: ${s.status}`);
|
|
86750
|
+
}
|
|
86751
|
+
function agentFailureLines(output, max2, scrub) {
|
|
86752
|
+
const out = [];
|
|
86753
|
+
for (const raw of output.trim().split(/\r?\n/)) {
|
|
86754
|
+
const line = raw.trim();
|
|
86755
|
+
if (!line) continue;
|
|
86756
|
+
if (line.startsWith("{") && line.endsWith("}")) {
|
|
86757
|
+
let event = null;
|
|
86758
|
+
try {
|
|
86759
|
+
event = JSON.parse(line);
|
|
86760
|
+
} catch {
|
|
86761
|
+
event = null;
|
|
86762
|
+
}
|
|
86763
|
+
if (event && typeof event === "object") {
|
|
86764
|
+
if (event.type !== "result") continue;
|
|
86765
|
+
const said = [
|
|
86766
|
+
typeof event.terminal_reason === "string" ? `terminal_reason=${event.terminal_reason}` : "",
|
|
86767
|
+
event.is_error === true ? "is_error" : "",
|
|
86768
|
+
typeof event.result === "string" ? event.result : ""
|
|
86769
|
+
].filter(Boolean).join(" ");
|
|
86770
|
+
if (said) out.push(said);
|
|
86771
|
+
continue;
|
|
86772
|
+
}
|
|
86773
|
+
}
|
|
86774
|
+
out.push(line);
|
|
86775
|
+
}
|
|
86776
|
+
return out.slice(-max2).map((l) => {
|
|
86777
|
+
const clean = scrub(l.replace(/\s+/g, " "));
|
|
86778
|
+
return clean.length > MAX_LOGGED_LINE_CHARS ? `${clean.slice(0, MAX_LOGGED_LINE_CHARS - 1)}\u2026` : clean;
|
|
86779
|
+
});
|
|
86780
|
+
}
|
|
86781
|
+
var NONE, count2, MODEL_REFUSAL, MAX_REASON_CHARS, MAX_LOGGED_LINE_CHARS;
|
|
86703
86782
|
var init_replay_usage = __esm({
|
|
86704
86783
|
"src/commands/replay-usage.ts"() {
|
|
86705
86784
|
"use strict";
|
|
@@ -86713,6 +86792,7 @@ var init_replay_usage = __esm({
|
|
|
86713
86792
|
count2 = (v) => typeof v === "number" && Number.isFinite(v) && v >= 0 ? v : null;
|
|
86714
86793
|
MODEL_REFUSAL = /credit balance is too low|insufficient[_ ](?:credit|quota|balance|funds)|quota (?:exceeded|exhausted)|exceeded your (?:current )?quota|invalid (?:x-)?api[_ -]?key|authentication[_ ]error|rate[_ ]limit(?:_error| exceeded| reached)|overloaded[_ ]error|api[_ ]error/i;
|
|
86715
86794
|
MAX_REASON_CHARS = 200;
|
|
86795
|
+
MAX_LOGGED_LINE_CHARS = 300;
|
|
86716
86796
|
}
|
|
86717
86797
|
});
|
|
86718
86798
|
|
|
@@ -87976,6 +88056,187 @@ var init_replay_interface = __esm({
|
|
|
87976
88056
|
}
|
|
87977
88057
|
});
|
|
87978
88058
|
|
|
88059
|
+
// src/commands/replay-context.ts
|
|
88060
|
+
function stateOf(knowledge) {
|
|
88061
|
+
if (knowledge === "returned") return "found";
|
|
88062
|
+
return knowledge;
|
|
88063
|
+
}
|
|
88064
|
+
function needsCheck(task) {
|
|
88065
|
+
const c = task.context;
|
|
88066
|
+
return !c || c.state === null || c.stale;
|
|
88067
|
+
}
|
|
88068
|
+
function pathsIn(text) {
|
|
88069
|
+
const found = text.match(/(?<![\w./-])(?:[\w.-]+\/)+[\w.-]*[\w-](?:\.[a-z0-9]+)?/gi) ?? [];
|
|
88070
|
+
return [
|
|
88071
|
+
...new Set(
|
|
88072
|
+
found.map((p) => p.replace(/^\.\//, "").replace(/[.,:;]+$/, "")).filter(
|
|
88073
|
+
(p) => p.includes("/") && !p.startsWith("/") && !/^https?:/i.test(p) && !p.split("/").some((part) => part === ".." || part === "")
|
|
88074
|
+
)
|
|
88075
|
+
)
|
|
88076
|
+
];
|
|
88077
|
+
}
|
|
88078
|
+
function visibleAsk(task) {
|
|
88079
|
+
const failing = task.kind === "recovery" ? task.failing : null;
|
|
88080
|
+
const problem = flat2(task.card.problem);
|
|
88081
|
+
const cardText = [
|
|
88082
|
+
task.card.problem,
|
|
88083
|
+
task.card.acceptance,
|
|
88084
|
+
task.card.area ?? ""
|
|
88085
|
+
].join("\n");
|
|
88086
|
+
const iface = task.testInterface ?? [];
|
|
88087
|
+
const paths = [
|
|
88088
|
+
.../* @__PURE__ */ new Set([...iface.map((e) => e.path), ...pathsIn(cardText)])
|
|
88089
|
+
].slice(0, MAX_PATHS);
|
|
88090
|
+
const names = iface.flatMap((e) => e.names);
|
|
88091
|
+
const queries = [
|
|
88092
|
+
problem,
|
|
88093
|
+
flat2(`${task.card.area ?? ""} ${flat2(task.card.acceptance)}`),
|
|
88094
|
+
failing?.tests.length ? flat2(failing.tests.join(" ")) : "",
|
|
88095
|
+
names.length ? names.join(" ") : ""
|
|
88096
|
+
].map((q) => q.slice(0, QUERY_CHARS2).trim()).filter((q, i, all) => q !== "" && all.indexOf(q) === i);
|
|
88097
|
+
const error2 = failing ? [
|
|
88098
|
+
...failing.tests,
|
|
88099
|
+
...failing.output ? [failing.output.slice(0, ERROR_CHARS)] : []
|
|
88100
|
+
].join("\n").trim() || null : null;
|
|
88101
|
+
return {
|
|
88102
|
+
task: [task.card.problem, task.card.acceptance].join("\n\n").slice(0, 1e3),
|
|
88103
|
+
error: error2,
|
|
88104
|
+
queries,
|
|
88105
|
+
...paths.length ? { paths } : {}
|
|
88106
|
+
};
|
|
88107
|
+
}
|
|
88108
|
+
async function checkContext(deps, input) {
|
|
88109
|
+
const { task, label } = input;
|
|
88110
|
+
if (!deps.searchHaansi) return null;
|
|
88111
|
+
if (input.targetText === null) {
|
|
88112
|
+
deps.log(
|
|
88113
|
+
`\u2026 ${label}: context not checked: the target's change could not be read`
|
|
88114
|
+
);
|
|
88115
|
+
return null;
|
|
88116
|
+
}
|
|
88117
|
+
const search = async (ask) => {
|
|
88118
|
+
const session = {
|
|
88119
|
+
...await deps.openSession(task.taskId),
|
|
88120
|
+
apiUrl: deps.apiUrl,
|
|
88121
|
+
token: deps.token
|
|
88122
|
+
};
|
|
88123
|
+
await deps.searchHaansi(session, ask).catch(() => void 0);
|
|
88124
|
+
return (await deps.getCalls(session.sessionId)).calls;
|
|
88125
|
+
};
|
|
88126
|
+
const reached = await search(visibleAsk(task));
|
|
88127
|
+
const recall = await search(
|
|
88128
|
+
recallAsk(
|
|
88129
|
+
task.card.problem,
|
|
88130
|
+
input.targetText,
|
|
88131
|
+
filesOfDiff(input.targetText)
|
|
88132
|
+
)
|
|
88133
|
+
);
|
|
88134
|
+
const judged = await judgeRelevance(deps, {
|
|
88135
|
+
label,
|
|
88136
|
+
taskId: `${task.taskId}-context`,
|
|
88137
|
+
agentCmd: input.agentCmd,
|
|
88138
|
+
timeoutMs: input.timeoutMs,
|
|
88139
|
+
card: input.card,
|
|
88140
|
+
targetChange: input.targetText,
|
|
88141
|
+
reached,
|
|
88142
|
+
recall,
|
|
88143
|
+
prompt: input.prompt
|
|
88144
|
+
});
|
|
88145
|
+
const state = stateOf(judged.knowledge);
|
|
88146
|
+
if (!state || !judged.relevantIds) return null;
|
|
88147
|
+
return {
|
|
88148
|
+
taskId: task.taskId,
|
|
88149
|
+
inputsFingerprint: task.inputsFingerprint,
|
|
88150
|
+
state,
|
|
88151
|
+
relevantIds: judged.relevantIds,
|
|
88152
|
+
judgeTag: judged.judgeTag
|
|
88153
|
+
};
|
|
88154
|
+
}
|
|
88155
|
+
async function gateOnContext(deps, tasks, options) {
|
|
88156
|
+
const states = /* @__PURE__ */ new Map();
|
|
88157
|
+
const checks = [];
|
|
88158
|
+
for (const t of tasks)
|
|
88159
|
+
if (!needsCheck(t)) states.set(t.taskId, t.context.state);
|
|
88160
|
+
const found = () => [...states.values()].filter((s) => s === "found").length;
|
|
88161
|
+
const toCheck = tasks.filter((t) => needsCheck(t));
|
|
88162
|
+
await runPool(toCheck, options.concurrency, async (task) => {
|
|
88163
|
+
if (options.limit && found() >= options.limit) return;
|
|
88164
|
+
const label = task.name ?? task.taskKey;
|
|
88165
|
+
try {
|
|
88166
|
+
await options.prepare?.(task);
|
|
88167
|
+
const check3 = await checkContext(deps, {
|
|
88168
|
+
task,
|
|
88169
|
+
label,
|
|
88170
|
+
card: options.cardOf(task),
|
|
88171
|
+
targetText: await options.targetOf(task),
|
|
88172
|
+
agentCmd: options.agentCmd,
|
|
88173
|
+
timeoutMs: options.timeoutMs,
|
|
88174
|
+
prompt: await options.prompt()
|
|
88175
|
+
});
|
|
88176
|
+
states.set(task.taskId, check3?.state ?? null);
|
|
88177
|
+
if (!check3) {
|
|
88178
|
+
deps.log(
|
|
88179
|
+
`context unknown ${label}: the relevance judge gave no verdict`
|
|
88180
|
+
);
|
|
88181
|
+
return;
|
|
88182
|
+
}
|
|
88183
|
+
checks.push(check3);
|
|
88184
|
+
const n = check3.relevantIds.length;
|
|
88185
|
+
deps.log(
|
|
88186
|
+
`context ${check3.state.padEnd(6)} ${label}${n ? ` (${n} relevant item${n === 1 ? "" : "s"})` : ""}`
|
|
88187
|
+
);
|
|
88188
|
+
} catch (err2) {
|
|
88189
|
+
states.set(task.taskId, null);
|
|
88190
|
+
deps.log(
|
|
88191
|
+
`context unknown ${label}: ${err2 instanceof Error ? err2.message : String(err2)}`
|
|
88192
|
+
);
|
|
88193
|
+
}
|
|
88194
|
+
});
|
|
88195
|
+
if (!options.dryRun && checks.length && deps.reportContext)
|
|
88196
|
+
for (let i = 0; i < checks.length; i += CONTEXT_REPORT_CHUNK)
|
|
88197
|
+
try {
|
|
88198
|
+
const out = await deps.reportContext({
|
|
88199
|
+
results: checks.slice(i, i + CONTEXT_REPORT_CHUNK)
|
|
88200
|
+
});
|
|
88201
|
+
if (out.refused.length)
|
|
88202
|
+
deps.log(
|
|
88203
|
+
`Haansi did not record ${out.refused.length} context check(s): their task's inputs changed during the run.`
|
|
88204
|
+
);
|
|
88205
|
+
} catch (err2) {
|
|
88206
|
+
deps.log(
|
|
88207
|
+
`The context checks could not be reported (${err2 instanceof Error ? err2.message : String(err2)}); the next run checks them again.`
|
|
88208
|
+
);
|
|
88209
|
+
}
|
|
88210
|
+
const replay2 = [];
|
|
88211
|
+
let noContext = 0;
|
|
88212
|
+
let unknown2 = 0;
|
|
88213
|
+
for (const t of tasks) {
|
|
88214
|
+
const label = t.name ?? t.taskKey;
|
|
88215
|
+
if (!states.has(t.taskId)) continue;
|
|
88216
|
+
const s = states.get(t.taskId);
|
|
88217
|
+
if (s === "found") replay2.push(t);
|
|
88218
|
+
else if (s === "missed" || s === "none") {
|
|
88219
|
+
noContext += 1;
|
|
88220
|
+
deps.log(`skip ${label}: no relevant context Haansi can return (${s})`);
|
|
88221
|
+
} else unknown2 += 1;
|
|
88222
|
+
}
|
|
88223
|
+
return { replay: replay2, noContext, unknown: unknown2 };
|
|
88224
|
+
}
|
|
88225
|
+
var QUERY_CHARS2, ERROR_CHARS, MAX_PATHS, CONTEXT_REPORT_CHUNK, flat2;
|
|
88226
|
+
var init_replay_context = __esm({
|
|
88227
|
+
"src/commands/replay-context.ts"() {
|
|
88228
|
+
"use strict";
|
|
88229
|
+
init_replay_relevance();
|
|
88230
|
+
init_replay_diff();
|
|
88231
|
+
init_replay_scale();
|
|
88232
|
+
QUERY_CHARS2 = 200;
|
|
88233
|
+
ERROR_CHARS = 1e3;
|
|
88234
|
+
MAX_PATHS = 20;
|
|
88235
|
+
CONTEXT_REPORT_CHUNK = 100;
|
|
88236
|
+
flat2 = (text) => text.replace(/\s+/g, " ").trim();
|
|
88237
|
+
}
|
|
88238
|
+
});
|
|
88239
|
+
|
|
87979
88240
|
// src/commands/replay-tasks.ts
|
|
87980
88241
|
var replay_tasks_exports = {};
|
|
87981
88242
|
__export(replay_tasks_exports, {
|
|
@@ -88023,8 +88284,8 @@ function fenced(text) {
|
|
|
88023
88284
|
return [fence, text, fence];
|
|
88024
88285
|
}
|
|
88025
88286
|
function listItem(name) {
|
|
88026
|
-
const
|
|
88027
|
-
return `- \`${
|
|
88287
|
+
const flat3 = name.replace(/[\u0000-\u001f\u007f]+/g, " ").trim();
|
|
88288
|
+
return `- \`${flat3.replace(/`/g, "'")}\``;
|
|
88028
88289
|
}
|
|
88029
88290
|
function haansiSection(tools) {
|
|
88030
88291
|
return [
|
|
@@ -88201,7 +88462,6 @@ async function runStoredReplays(options, deps) {
|
|
|
88201
88462
|
);
|
|
88202
88463
|
const notValid = mine.length - valid.length;
|
|
88203
88464
|
const arms = options.arms;
|
|
88204
|
-
const chosen = options.limit ? valid.slice(0, options.limit) : valid;
|
|
88205
88465
|
let judgePrompt;
|
|
88206
88466
|
const promptForJudge = async () => {
|
|
88207
88467
|
if (judgePrompt === void 0)
|
|
@@ -88214,6 +88474,48 @@ async function runStoredReplays(options, deps) {
|
|
|
88214
88474
|
relevancePrompt = deps.getRelevancePrompt ? await deps.getRelevancePrompt().catch(() => null) : null;
|
|
88215
88475
|
return relevancePrompt;
|
|
88216
88476
|
};
|
|
88477
|
+
const targets = /* @__PURE__ */ new Map();
|
|
88478
|
+
const targetOf = (task) => {
|
|
88479
|
+
let t = targets.get(task.taskId);
|
|
88480
|
+
if (!t) {
|
|
88481
|
+
t = referenceDiffOf(deps, task).catch(() => null);
|
|
88482
|
+
targets.set(task.taskId, t);
|
|
88483
|
+
}
|
|
88484
|
+
return t;
|
|
88485
|
+
};
|
|
88486
|
+
const interfaceOf = async (task) => {
|
|
88487
|
+
if (task.testInterface !== void 0) return;
|
|
88488
|
+
task.testInterface = !testNamesOf(task).length && task.baseSha && task.targetSha ? await testInterfaceOf(deps.showFile, {
|
|
88489
|
+
baseSha: task.baseSha,
|
|
88490
|
+
targetSha: task.targetSha,
|
|
88491
|
+
testFiles: task.testFiles
|
|
88492
|
+
}).catch(() => []) : [];
|
|
88493
|
+
};
|
|
88494
|
+
let noContext = 0;
|
|
88495
|
+
let contextUnknown = 0;
|
|
88496
|
+
let gated = valid;
|
|
88497
|
+
if (options.anyContext) {
|
|
88498
|
+
if (valid.length)
|
|
88499
|
+
deps.log(
|
|
88500
|
+
"--any-context: replaying valid tasks without the context check."
|
|
88501
|
+
);
|
|
88502
|
+
} else if (valid.length) {
|
|
88503
|
+
const gate = await gateOnContext(deps, valid, {
|
|
88504
|
+
agentCmd: options.agentCmd,
|
|
88505
|
+
timeoutMs: options.timeoutMs,
|
|
88506
|
+
concurrency: options.concurrency ?? 1,
|
|
88507
|
+
limit: options.limit,
|
|
88508
|
+
dryRun: options.dryRun,
|
|
88509
|
+
cardOf: (task) => cardPrompt(task, null),
|
|
88510
|
+
targetOf,
|
|
88511
|
+
prepare: interfaceOf,
|
|
88512
|
+
prompt: promptForRelevance
|
|
88513
|
+
});
|
|
88514
|
+
gated = gate.replay;
|
|
88515
|
+
noContext = gate.noContext;
|
|
88516
|
+
contextUnknown = gate.unknown;
|
|
88517
|
+
}
|
|
88518
|
+
const chosen = options.limit ? gated.slice(0, options.limit) : gated;
|
|
88217
88519
|
const results = [];
|
|
88218
88520
|
let recorded = 0;
|
|
88219
88521
|
let pending = [];
|
|
@@ -88249,19 +88551,13 @@ async function runStoredReplays(options, deps) {
|
|
|
88249
88551
|
testFiles: task.testFiles,
|
|
88250
88552
|
testNames: testNamesOf(task)
|
|
88251
88553
|
};
|
|
88252
|
-
const targetText = await
|
|
88554
|
+
const targetText = await targetOf(task);
|
|
88253
88555
|
const targetChanges = targetText === null ? null : parseDiff(targetText);
|
|
88254
|
-
|
|
88255
|
-
|
|
88256
|
-
|
|
88257
|
-
|
|
88258
|
-
|
|
88259
|
-
}).catch(() => []);
|
|
88260
|
-
if (task.testInterface.length)
|
|
88261
|
-
deps.log(
|
|
88262
|
-
`\u2026 ${label}: the tests use ${task.testInterface.length} module(s) the start lacks; named in the prompt`
|
|
88263
|
-
);
|
|
88264
|
-
}
|
|
88556
|
+
await interfaceOf(task);
|
|
88557
|
+
if (task.testInterface?.length)
|
|
88558
|
+
deps.log(
|
|
88559
|
+
`\u2026 ${label}: the tests use ${task.testInterface.length} module(s) the start lacks; named in the prompt`
|
|
88560
|
+
);
|
|
88265
88561
|
let targetSent = false;
|
|
88266
88562
|
for (const arm of arms) {
|
|
88267
88563
|
if (!options.force && alreadyMeasured(
|
|
@@ -88439,10 +88735,11 @@ async function runStoredReplays(options, deps) {
|
|
|
88439
88735
|
}
|
|
88440
88736
|
};
|
|
88441
88737
|
await runPool(chosen, options.concurrency ?? 1, replayOne);
|
|
88738
|
+
const counts = { notValid, noContext, contextUnknown };
|
|
88442
88739
|
if (options.dryRun || results.length === 0)
|
|
88443
|
-
return { results,
|
|
88740
|
+
return { results, ...counts, recorded: null };
|
|
88444
88741
|
if (pending.length) await report(pending);
|
|
88445
|
-
return { results,
|
|
88742
|
+
return { results, ...counts, recorded };
|
|
88446
88743
|
}
|
|
88447
88744
|
function haansiUseOf(calls) {
|
|
88448
88745
|
return {
|
|
@@ -88471,6 +88768,7 @@ var init_replay_tasks = __esm({
|
|
|
88471
88768
|
init_replay();
|
|
88472
88769
|
init_replay_scale();
|
|
88473
88770
|
init_replay_interface();
|
|
88771
|
+
init_replay_context();
|
|
88474
88772
|
FEEDBACK_HEADER = "Your previous attempt did not pass the tests. Their output ends with:";
|
|
88475
88773
|
REPORT_CHUNK2 = 200;
|
|
88476
88774
|
REPORT_CHARS = 4e6;
|
|
@@ -88551,6 +88849,7 @@ function parseReplayArgs(argv) {
|
|
|
88551
88849
|
else if (a === "--repo-commands") options.repoCommands = true;
|
|
88552
88850
|
else if (takeScaleArg(a, next, scale, errors)) continue;
|
|
88553
88851
|
else if (a === "--force") options.force = true;
|
|
88852
|
+
else if (a === "--any-context") options.anyContext = true;
|
|
88554
88853
|
else if (a === "--max-hours") options.maxHours = Number(next());
|
|
88555
88854
|
else if (takeContainerArg(a, next, options.container, errors)) continue;
|
|
88556
88855
|
else if (a === "--arms")
|
|
@@ -88720,7 +89019,11 @@ async function replayArm(deps, options, task, arm, promptOf, inspect, agentEnv =
|
|
|
88720
89019
|
});
|
|
88721
89020
|
if (agent.code !== 0) {
|
|
88722
89021
|
deps.log(`\u2026 ${label}: the agent exited with code ${agent.code}`);
|
|
88723
|
-
for (const line of
|
|
89022
|
+
for (const line of agentFailureLines(
|
|
89023
|
+
agent.output,
|
|
89024
|
+
FAILURE_LINES2,
|
|
89025
|
+
scrubSecrets
|
|
89026
|
+
))
|
|
88724
89027
|
deps.log(` ${line}`);
|
|
88725
89028
|
}
|
|
88726
89029
|
const unreachable2 = modelUnreachableOf(agent.output, agent.code);
|
|
@@ -88728,6 +89031,17 @@ async function replayArm(deps, options, task, arm, promptOf, inspect, agentEnv =
|
|
|
88728
89031
|
throw new Error(
|
|
88729
89032
|
`the agent could not reach its model (${unreachable2}); not graded, run it again`
|
|
88730
89033
|
);
|
|
89034
|
+
if (arm === "haansi") {
|
|
89035
|
+
const down = haansiServersDown(agent.output);
|
|
89036
|
+
if (down === null)
|
|
89037
|
+
deps.log(
|
|
89038
|
+
`\u2026 ${label}: the agent did not report its MCP servers (use --output-format stream-json --verbose to check them)`
|
|
89039
|
+
);
|
|
89040
|
+
else if (down.length)
|
|
89041
|
+
throw new Error(
|
|
89042
|
+
`Haansi's servers did not load for the agent (${down.join(", ")}); not graded, run it again`
|
|
89043
|
+
);
|
|
89044
|
+
}
|
|
88731
89045
|
const gradeSha = task.testNames?.length ? task.baseSha : task.targetSha;
|
|
88732
89046
|
const own = new Map(files.map((f) => [f, deps.readFile((0, import_node_path16.join)(dir, f))]));
|
|
88733
89047
|
for (const f of files) {
|
|
@@ -88979,7 +89293,7 @@ async function replayStored(options, token2, apiUrl2) {
|
|
|
88979
89293
|
runCommand
|
|
88980
89294
|
);
|
|
88981
89295
|
stop = contained.stop;
|
|
88982
|
-
const { results, notValid, recorded } = await runStoredReplays2(options, {
|
|
89296
|
+
const { results, notValid, noContext, contextUnknown, recorded } = await runStoredReplays2(options, {
|
|
88983
89297
|
...contained.deps,
|
|
88984
89298
|
getReplaySet: (repository) => apiGet3(
|
|
88985
89299
|
`/memory/replays/tasks?repository=${encodeURIComponent(repository)}`,
|
|
@@ -88998,6 +89312,12 @@ async function replayStored(options, token2, apiUrl2) {
|
|
|
88998
89312
|
token2,
|
|
88999
89313
|
apiUrl2
|
|
89000
89314
|
),
|
|
89315
|
+
reportContext: async (body) => await apiPost2(
|
|
89316
|
+
"/memory/replays/tasks/context",
|
|
89317
|
+
body,
|
|
89318
|
+
token2,
|
|
89319
|
+
apiUrl2
|
|
89320
|
+
),
|
|
89001
89321
|
env: process.env,
|
|
89002
89322
|
cliVersion: cliVersion2(),
|
|
89003
89323
|
preflight: (session) => preflightHaansi(session),
|
|
@@ -89027,7 +89347,7 @@ async function replayStored(options, token2, apiUrl2) {
|
|
|
89027
89347
|
};
|
|
89028
89348
|
console.log(
|
|
89029
89349
|
`
|
|
89030
|
-
Baseline: ${arm("baseline")} passed \xB7 With Haansi: ${arm("haansi")} passed \xB7 ${notValid} task(s) not valid to replay`
|
|
89350
|
+
Baseline: ${arm("baseline")} passed \xB7 With Haansi: ${arm("haansi")} passed \xB7 ${notValid} task(s) not valid to replay \xB7 ${noContext ?? 0} skipped with no relevant context${contextUnknown ? ` \xB7 ${contextUnknown} whose context could not be checked` : ""}`
|
|
89031
89351
|
);
|
|
89032
89352
|
console.log(
|
|
89033
89353
|
recorded === null ? options.dryRun ? "Dry run: nothing reported." : "Nothing to report." : `Reported ${recorded} result(s) to Haansi.`
|
|
@@ -89066,7 +89386,7 @@ var init_replay = __esm({
|
|
|
89066
89386
|
[--setup-cmd "<cmd>"] [--attempts 3] [--arms baseline,haansi] [--limit n]
|
|
89067
89387
|
[--timeout-min 20] [--agent-name <name>] [--model <name>]
|
|
89068
89388
|
[--run-ref <url>] [--dry-run] [--repo-commands] [--no-diffs]
|
|
89069
|
-
[--shard i/n] [--concurrency k] [--force] [--max-hours h]
|
|
89389
|
+
[--shard i/n] [--concurrency k] [--force] [--max-hours h] [--any-context]
|
|
89070
89390
|
[--setup-cache <files> --setup-cache-path <paths> [--setup-cache-dir <dir>]]
|
|
89071
89391
|
[--container <image> [--container-setup "<cmd>"] [--container-env NAME]...]
|
|
89072
89392
|
|
|
@@ -89090,6 +89410,15 @@ package-lock.json --setup-cache-path '**/node_modules' keeps the setup's output
|
|
|
89090
89410
|
(every workspace's node_modules) per lockfile (in ~/.cache/haansi-replay, or --setup-cache-dir) and restores
|
|
89091
89411
|
it instead of running the setup again; not with --container.
|
|
89092
89412
|
|
|
89413
|
+
Only tasks Haansi holds relevant context for are replayed. Before any agent
|
|
89414
|
+
runs, each valid task is checked: Haansi is searched with only what the agent
|
|
89415
|
+
sees at the task's start (its card, a bug fix's failing tests, what its tests
|
|
89416
|
+
import, the paths the card names), and the relevance judge (your agent
|
|
89417
|
+
command, once per task checked) says whether anything relevant came back.
|
|
89418
|
+
A task with nothing relevant Haansi can return is skipped, and checked again
|
|
89419
|
+
once the organization gains new Haansi content. --any-context replays every
|
|
89420
|
+
valid task without the check (diagnostics).
|
|
89421
|
+
|
|
89093
89422
|
--repo-commands uses the setup and test commands an org owner or admin saved for the
|
|
89094
89423
|
repository in Haansi (Impact \u2192 Replays) for any not given here.
|
|
89095
89424
|
|
|
@@ -89102,7 +89431,7 @@ Run from a clone of the repository. Example (GitHub Actions):
|
|
|
89102
89431
|
haansi replay run --setup-cmd 'npm ci' \\
|
|
89103
89432
|
--container node:22 --container-env ANTHROPIC_API_KEY \\
|
|
89104
89433
|
--container-setup 'npm install -g haansi @anthropic-ai/claude-code' \\
|
|
89105
|
-
--agent-cmd 'claude -p "$HAANSI_REPLAY_PROMPT" --output-format json --permission-mode acceptEdits --mcp-config "$HAANSI_REPLAY_MCP_CONFIG" --allowedTools mcp__haansi-solutions,mcp__haansi-exchange,mcp__haansi-digests,mcp__haansi-onboarding,mcp__haansi-skills' \\
|
|
89434
|
+
--agent-cmd 'claude -p "$HAANSI_REPLAY_PROMPT" --output-format stream-json --verbose --permission-mode acceptEdits --mcp-config "$HAANSI_REPLAY_MCP_CONFIG" --allowedTools mcp__haansi-solutions,mcp__haansi-exchange,mcp__haansi-digests,mcp__haansi-onboarding,mcp__haansi-skills' \\
|
|
89106
89435
|
--test-cmd 'npx vitest run $HAANSI_REPLAY_TEST_FILES -t "$HAANSI_REPLAY_TEST_PATTERN"' \\
|
|
89107
89436
|
--agent-name claude-code --model claude-sonnet-5-5`;
|
|
89108
89437
|
}
|