haansi 0.1.94 → 0.1.96

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.
Files changed (2) hide show
  1. package/dist/haansi.js +149 -43
  2. 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.94",
98
+ version: "0.1.96",
99
99
  description: "Haansi CLI - Session collector and MCP server for Claude Code & OpenAI Codex",
100
100
  bin: {
101
101
  haansi: "./dist/haansi.js"
@@ -85855,10 +85855,10 @@ function scrubSecrets(text) {
85855
85855
  }
85856
85856
  function failingTestIn(line) {
85857
85857
  const text = line.trim();
85858
- const js = /^FAIL\s+(\S+)(?:\s+>\s+(.+))?$/.exec(text);
85858
+ const js = /^FAIL\s+(\S+)(?:\s+>\s+(.+?))?(\s+\[[^\]]*\])?$/.exec(text);
85859
85859
  if (js && JS_FILE.test(js[1])) {
85860
- const name = js[2]?.replace(/\s+\[[^\]]*\]$/, "").split(/\s+>\s+/);
85861
- return name?.length ? [js[1], ...name].join(" \u203A ") : js[1];
85860
+ if (!js[2]) return js[3] ? `${js[1]} \u203A ${SUITE_LOAD_FAILED}` : js[1];
85861
+ return [js[1], ...js[2].split(/\s+>\s+/)].join(" \u203A ");
85862
85862
  }
85863
85863
  const py = /^FAILED\s+(\S+?\.py)(?:::(\S+))?(?:\s+-\s.*)?$/.exec(text);
85864
85864
  if (py) return py[2] ? `${py[1]} \u203A ${py[2].replace(/::/g, " \u203A ")}` : py[1];
@@ -85868,32 +85868,88 @@ function failingTestIn(line) {
85868
85868
  if (goPkg && !JS_FILE.test(goPkg[1])) return goPkg[1];
85869
85869
  return null;
85870
85870
  }
85871
- function testErrorsOf(output) {
85872
- const lines = output.split(/\r?\n/).map((l) => l.replace(ANSI, "").trimEnd());
85871
+ function relativePaths(text, root) {
85872
+ let out = text;
85873
+ const base = root?.replace(/\/+$/, "");
85874
+ if (base)
85875
+ for (const r of [`/private${base}/`, `${base}/`])
85876
+ out = out.split(r).join("");
85877
+ return out.replace(TEMP_CHECKOUT, "");
85878
+ }
85879
+ function messageAt(lines, i) {
85880
+ const inline = /^FAILED\s+\S+\s+-\s+(.+)$/.exec(lines[i].trim());
85881
+ if (inline) return inline[1];
85882
+ const kept = [];
85883
+ for (let j = i + 1; j < lines.length && kept.length < MESSAGE_LINES; j++) {
85884
+ const line = lines[j];
85885
+ if (!line.trim()) continue;
85886
+ if (failingTestIn(line) || MESSAGE_END.test(line)) break;
85887
+ if (line !== kept.at(-1)) kept.push(line);
85888
+ }
85889
+ if (!kept.length) return "";
85890
+ const indent = Math.min(...kept.map((l) => /^\s*/.exec(l)[0].length));
85891
+ return kept.map((l) => l.slice(indent)).join("\n");
85892
+ }
85893
+ function testErrorsOf(output, root) {
85894
+ const lines = output.split(/\r?\n/).map((l) => relativePaths(l.replace(ANSI, "").trimEnd(), root));
85873
85895
  const failing = [];
85874
- let first = -1;
85896
+ const messages = /* @__PURE__ */ new Map();
85875
85897
  lines.forEach((line, i) => {
85876
85898
  const name = failingTestIn(line);
85877
85899
  if (!name) return;
85878
- if (first < 0) first = i;
85879
- if (!failing.includes(name) && failing.length < MAX_ERROR_TESTS)
85900
+ if (!failing.includes(name)) {
85901
+ if (failing.length >= MAX_ERROR_TESTS) return;
85880
85902
  failing.push(name);
85903
+ }
85904
+ if (!messages.has(name)) {
85905
+ const message = messageAt(lines, i);
85906
+ if (message) messages.set(name, message);
85907
+ }
85908
+ });
85909
+ const tests = failing.flatMap((name) => {
85910
+ const message = messages.get(name);
85911
+ return message ? [
85912
+ {
85913
+ name: scrubSecrets(name),
85914
+ message: cut(scrubSecrets(message), MAX_TEST_MESSAGE_CHARS)
85915
+ }
85916
+ ] : [];
85881
85917
  });
85882
- const from = first >= 0 ? first : Math.max(0, lines.length - OUTPUT_LINES);
85883
- const text = scrubSecrets(
85884
- lines.slice(from, from + OUTPUT_LINES).filter((l, i, all) => l.trim() && l !== all[i - 1]).join("\n")
85918
+ const named = failing.map(scrubSecrets);
85919
+ if (!tests.length) {
85920
+ const text = scrubSecrets(
85921
+ lines.slice(-OUTPUT_LINES).filter((l, i, all) => l.trim() && l !== all[i - 1]).join("\n")
85922
+ );
85923
+ return {
85924
+ failing: named,
85925
+ output: text.length > MAX_ERROR_OUTPUT_CHARS ? `\u2026 (trimmed)
85926
+ ${text.slice(-MAX_ERROR_OUTPUT_CHARS)}` : text
85927
+ };
85928
+ }
85929
+ const summary = scrubSecrets(
85930
+ [...new Set(lines.filter((l) => SUMMARY.test(l)).map((l) => l.trim()))].slice(-4).join("\n")
85885
85931
  );
85886
- return {
85887
- failing: failing.map(scrubSecrets),
85888
- output: text.length > MAX_ERROR_OUTPUT_CHARS ? `${text.slice(0, MAX_ERROR_OUTPUT_CHARS)}
85889
- \u2026 (trimmed)` : text
85890
- };
85932
+ const budget = MAX_ERROR_OUTPUT_CHARS - summary.length - 16;
85933
+ const sections = [];
85934
+ let used = 0;
85935
+ for (const t of tests) {
85936
+ const section = `FAIL ${t.name}
85937
+ ${t.message}`;
85938
+ if (used + section.length + 2 > budget) {
85939
+ sections.push("\u2026 (trimmed)");
85940
+ break;
85941
+ }
85942
+ sections.push(section);
85943
+ used += section.length + 2;
85944
+ }
85945
+ if (summary) sections.push(summary);
85946
+ return { failing: named, output: sections.join("\n\n"), tests };
85891
85947
  }
85892
- function attemptErrorOf(output, at) {
85948
+ function attemptErrorOf(output, at, root) {
85893
85949
  return {
85894
85950
  attempt: at.attempt,
85895
85951
  agentExit: at.agentExit,
85896
- ...testErrorsOf(output)
85952
+ ...testErrorsOf(output, root)
85897
85953
  };
85898
85954
  }
85899
85955
  function testCountsOf(output) {
@@ -85926,13 +85982,16 @@ function testCountsOf(output) {
85926
85982
  const goFail = lines.filter((l) => /^--- FAIL:/.test(l)).length;
85927
85983
  return goPass + goFail > 0 ? { passed: goPass, failed: goFail, total: goPass + goFail } : null;
85928
85984
  }
85929
- var MAX_ERROR_TESTS, MAX_ERROR_OUTPUT_CHARS, OUTPUT_LINES, ANSI, JS_FILE, SECRET_PATTERNS, count;
85985
+ var MAX_ERROR_TESTS, MAX_ERROR_OUTPUT_CHARS, MAX_TEST_MESSAGE_CHARS, SUITE_LOAD_FAILED, OUTPUT_LINES, MESSAGE_LINES, ANSI, JS_FILE, SECRET_PATTERNS, TEMP_CHECKOUT, MESSAGE_END, SUMMARY, cut, count;
85930
85986
  var init_replay_errors = __esm({
85931
85987
  "src/commands/replay-errors.ts"() {
85932
85988
  "use strict";
85933
85989
  MAX_ERROR_TESTS = 30;
85934
85990
  MAX_ERROR_OUTPUT_CHARS = 4e3;
85991
+ MAX_TEST_MESSAGE_CHARS = 600;
85992
+ SUITE_LOAD_FAILED = "(suite failed to load)";
85935
85993
  OUTPUT_LINES = 80;
85994
+ MESSAGE_LINES = 12;
85936
85995
  ANSI = /\x1b\[[0-9;?]*[A-Za-z]/g;
85937
85996
  JS_FILE = /^(\S+\.(?:test|spec)\.[cm]?[jt]sx?)$/;
85938
85997
  SECRET_PATTERNS = [
@@ -85947,6 +86006,10 @@ var init_replay_errors = __esm({
85947
86006
  /(\b[a-z][a-z0-9+.-]*:\/\/)[^\s/:@]+:[^\s/@]+@/gi,
85948
86007
  /\b((?:[A-Za-z0-9_]*(?:password|passwd|secret|token|api[_-]?key|private[_-]?key)[A-Za-z0-9_]*)\s*[:=]\s*)(["']?)[^\s"',;]{4,}\2/gi
85949
86008
  ];
86009
+ TEMP_CHECKOUT = /(?:\/[^\s'"`/]+)*\/haansi-(?:replay|calibrate)-[A-Za-z0-9]{6}\/[^\s'"`/]+\//g;
86010
+ MESSAGE_END = /^\s*(?:⎯{3,}|❯\s|at\s|\d+\s*\|\s|>\s*\d+\s*\||Test Files\s|Tests:?\s+\d|Test Suites:|Duration\s|PASS\s|✓\s|=== RUN\s|ok\s|FAIL$)/;
86011
+ SUMMARY = /^\s*(?:Test Files\s+\d|Tests:?\s+\d|Test Suites:\s+\d|=+\s.*\b(?:passed|failed|error)\b.*\sin\s[\d.]+s.*=+$|(?:FAIL|ok)\s+\S+\s+[\d.]+s$)/;
86012
+ cut = (text, max2) => text.length > max2 ? `${text.slice(0, max2 - 2)} \u2026` : text;
85950
86013
  count = (text, word) => {
85951
86014
  const m = new RegExp(`(\\d+)\\s+${word}`).exec(text);
85952
86015
  return m ? Number(m[1]) : 0;
@@ -86092,10 +86155,11 @@ async function startContainer(work, options, run3, log, user = currentUser()) {
86092
86155
  stop,
86093
86156
  git: (args, cwd) => git(args, cwd, false),
86094
86157
  gitStdout: (args, cwd) => git(args, cwd, true),
86095
- shell: (command2, cwd, env, timeoutMs) => {
86158
+ shell: async (command2, cwd, env, timeoutMs) => {
86096
86159
  const names = [.../* @__PURE__ */ new Set([...options.env, ...Object.keys(env)])];
86097
86160
  const seconds = Math.max(1, Math.ceil(timeoutMs / 1e3));
86098
- return settled(
86161
+ const started2 = Date.now();
86162
+ const out = await settled(
86099
86163
  [
86100
86164
  "exec",
86101
86165
  "--user",
@@ -86117,9 +86181,13 @@ async function startContainer(work, options, run3, log, user = currentUser()) {
86117
86181
  env,
86118
86182
  timeoutMs + KILL_SLACK_MS
86119
86183
  );
86184
+ return containerTimedOut(out, Date.now() - started2, timeoutMs) ? { ...out, timedOut: true } : out;
86120
86185
  }
86121
86186
  };
86122
86187
  }
86188
+ function containerTimedOut(out, elapsedMs, timeoutMs) {
86189
+ return out.timedOut === true || out.code === 137 && elapsedMs >= timeoutMs;
86190
+ }
86123
86191
  function currentUser() {
86124
86192
  const uid = process.getuid?.() ?? 1e3;
86125
86193
  const gid = process.getgid?.() ?? 1e3;
@@ -87065,12 +87133,18 @@ async function calibrateTask(deps, options, commands, task) {
87065
87133
  focusEnv(task.testFiles, testNamesOf(task)),
87066
87134
  options.timeoutMs
87067
87135
  );
87136
+ if (test.timedOut) {
87137
+ deps.log(
87138
+ `\u2026 ${label} [${side}]: tests run ${i + 1}/${options.runs} stopped after ${since(testAt)} (--timeout-min)`
87139
+ );
87140
+ return done("timed_out");
87141
+ }
87068
87142
  runs[side].push(test.code);
87069
87143
  deps.log(
87070
87144
  `\u2026 ${label} [${side}]: tests run ${i + 1}/${options.runs} ${test.code === 0 ? "passed" : "failed"} in ${since(testAt)}`
87071
87145
  );
87072
87146
  if (side === "base" && test.code !== 0 && !baseErrors)
87073
- baseErrors = testErrorsOf(test.output);
87147
+ baseErrors = testErrorsOf(test.output, dir);
87074
87148
  if (side === "target" && test.code !== 0)
87075
87149
  for (const line of test.output.trim().split("\n").slice(-FAILURE_LINES))
87076
87150
  deps.log(` ${line}`);
@@ -87161,6 +87235,21 @@ async function runCalibration(options, deps, preloaded) {
87161
87235
  `Calibrating ${toRun.length} task(s), ${Math.min(options.concurrency ?? 1, Math.max(toRun.length, 1))} at once (${reused} calibrated already)`
87162
87236
  );
87163
87237
  const verdictLine = (task, result) => `${result.state.padEnd(7)} ${task.name ?? task.taskKey}: ${result.reason.replace(/_/g, " ")} (base ${result.runs.base.join(",") || "-"}; target ${result.runs.target.join(",") || "-"})`;
87238
+ const send = (results) => deps.report({
87239
+ runRef: options.runRef,
87240
+ environment,
87241
+ results: results.map(
87242
+ (c) => options.noDiffs ? { ...c, baseErrors: void 0 } : c
87243
+ )
87244
+ });
87245
+ let recorded = 0;
87246
+ const unsent = [];
87247
+ const noteRefused = (n) => {
87248
+ if (n)
87249
+ deps.log(
87250
+ `Haansi did not record ${n} calibration(s): their task changed since it was listed.`
87251
+ );
87252
+ };
87164
87253
  const ran = await runPool(toRun, options.concurrency ?? 1, async (task) => {
87165
87254
  const result = await calibrateTask(
87166
87255
  deps,
@@ -87169,6 +87258,15 @@ async function runCalibration(options, deps, preloaded) {
87169
87258
  task
87170
87259
  );
87171
87260
  deps.log(verdictLine(task, result));
87261
+ if (!options.dryRun) {
87262
+ try {
87263
+ const out = await send([result]);
87264
+ recorded += out.recorded;
87265
+ noteRefused(out.refused.length);
87266
+ } catch {
87267
+ unsent.push(result);
87268
+ }
87269
+ }
87172
87270
  return result;
87173
87271
  });
87174
87272
  ran.forEach((r, i) => {
@@ -87188,18 +87286,10 @@ async function runCalibration(options, deps, preloaded) {
87188
87286
  });
87189
87287
  if (options.dryRun || calibrations.length === 0)
87190
87288
  return { calibrations, reused, skipped, recorded: null, states, reasons };
87191
- let recorded = 0;
87192
- for (let i = 0; i < calibrations.length; i += REPORT_CHUNK) {
87193
- const out = await deps.report({
87194
- runRef: options.runRef,
87195
- environment,
87196
- results: calibrations.slice(i, i + REPORT_CHUNK).map((c) => options.noDiffs ? { ...c, baseErrors: void 0 } : c)
87197
- });
87289
+ for (let i = 0; i < unsent.length; i += REPORT_CHUNK) {
87290
+ const out = await send(unsent.slice(i, i + REPORT_CHUNK));
87198
87291
  recorded += out.recorded;
87199
- if (out.refused.length)
87200
- deps.log(
87201
- `Haansi did not record ${out.refused.length} calibration(s): their task changed since it was listed.`
87202
- );
87292
+ noteRefused(out.refused.length);
87203
87293
  }
87204
87294
  return { calibrations, reused, skipped, recorded, states, reasons };
87205
87295
  }
@@ -87310,7 +87400,8 @@ var init_replay_calibrate = __esm({
87310
87400
  flaky_at_base: "flaky",
87311
87401
  flaky_at_target: "flaky",
87312
87402
  setup_failed: "error",
87313
- checkout_failed: "error"
87403
+ checkout_failed: "error",
87404
+ timed_out: "error"
87314
87405
  };
87315
87406
  CALIBRATION_VERSION = 1;
87316
87407
  isFeatureDelivery = (task) => task.kind === "full" || task.kind === "milestone";
@@ -88482,10 +88573,11 @@ async function replayArm(deps, options, task, arm, promptOf, inspect, agentEnv =
88482
88573
  `\u2026 ${label}: tests ${test.code === 0 ? "passed" : "failed"} in ${since(testAt)}${counted ? ` (${counted.passed}/${counted.total} passed)` : ""}`
88483
88574
  );
88484
88575
  if (test.code !== 0) {
88485
- const error2 = attemptErrorOf(test.output, {
88486
- attempt,
88487
- agentExit: agent.code
88488
- });
88576
+ const error2 = attemptErrorOf(
88577
+ test.output,
88578
+ { attempt, agentExit: agent.code },
88579
+ dir
88580
+ );
88489
88581
  errors.push(error2);
88490
88582
  for (const name of error2.failing) deps.log(` failing: ${name}`);
88491
88583
  for (const line of test.output.trim().split("\n").slice(-FAILURE_LINES2))
@@ -88496,9 +88588,15 @@ async function replayArm(deps, options, task, arm, promptOf, inspect, agentEnv =
88496
88588
  const after = await wholeRun();
88497
88589
  const verdict2 = guardVerdict(guardStart, after, MAX_ERROR_TESTS);
88498
88590
  if (verdict2.kind === "broke") {
88591
+ const whole = attemptErrorOf(
88592
+ after.output,
88593
+ { attempt, agentExit: agent.code },
88594
+ dir
88595
+ );
88499
88596
  guarded = {
88500
- ...attemptErrorOf(after.output, { attempt, agentExit: agent.code }),
88501
- failing: verdict2.tests
88597
+ ...whole,
88598
+ failing: verdict2.tests,
88599
+ tests: whole.tests?.filter((t) => verdict2.tests.includes(t.name))
88502
88600
  };
88503
88601
  errors.push(guarded);
88504
88602
  deps.log(
@@ -88575,10 +88673,18 @@ function runCommand(file2, args, cwd, env, timeoutMs, stdoutOnly = false) {
88575
88673
  child.stdout.on("data", keep);
88576
88674
  child.stderr.on("data", keep);
88577
88675
  }
88578
- const timer = setTimeout(() => child.kill("SIGKILL"), timeoutMs);
88676
+ let timedOut = false;
88677
+ const timer = setTimeout(() => {
88678
+ timedOut = true;
88679
+ child.kill("SIGKILL");
88680
+ }, timeoutMs);
88579
88681
  child.on("close", (code) => {
88580
88682
  clearTimeout(timer);
88581
- resolvePromise({ code: code ?? 1, output });
88683
+ resolvePromise({
88684
+ code: code ?? 1,
88685
+ output,
88686
+ ...timedOut ? { timedOut } : {}
88687
+ });
88582
88688
  });
88583
88689
  child.on("error", () => {
88584
88690
  clearTimeout(timer);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "haansi",
3
- "version": "0.1.94",
3
+ "version": "0.1.96",
4
4
  "description": "Haansi CLI - Session collector and MCP server for Claude Code & OpenAI Codex",
5
5
  "bin": {
6
6
  "haansi": "./dist/haansi.js"