haansi 0.1.95 → 0.1.97

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 +280 -64
  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.95",
98
+ version: "0.1.97",
99
99
  description: "Haansi CLI - Session collector and MCP server for Claude Code & OpenAI Codex",
100
100
  bin: {
101
101
  haansi: "./dist/haansi.js"
@@ -48267,8 +48267,8 @@ var require_resolve = __commonJS({
48267
48267
  }
48268
48268
  return count4;
48269
48269
  }
48270
- function getFullPath(resolver, id = "", normalize) {
48271
- if (normalize !== false)
48270
+ function getFullPath(resolver, id = "", normalize2) {
48271
+ if (normalize2 !== false)
48272
48272
  id = normalizeId(id);
48273
48273
  const p = resolver.parse(id);
48274
48274
  return _getFullPath(resolver, p);
@@ -49608,7 +49608,7 @@ var require_fast_uri = __commonJS({
49608
49608
  "use strict";
49609
49609
  var { normalizeIPv6, removeDotSegments, recomposeAuthority, normalizeComponentEncoding, isIPv4, nonSimpleDomain } = require_utils5();
49610
49610
  var { SCHEMES, getSchemeHandler } = require_schemes();
49611
- function normalize(uri, options) {
49611
+ function normalize2(uri, options) {
49612
49612
  if (typeof uri === "string") {
49613
49613
  uri = /** @type {T} */
49614
49614
  serialize(parse4(uri, options), options);
@@ -49844,7 +49844,7 @@ var require_fast_uri = __commonJS({
49844
49844
  }
49845
49845
  var fastUri = {
49846
49846
  SCHEMES,
49847
- normalize,
49847
+ normalize: normalize2,
49848
49848
  resolve: resolve5,
49849
49849
  resolveComponent,
49850
49850
  equal,
@@ -54887,8 +54887,8 @@ var require_resolve2 = __commonJS({
54887
54887
  }
54888
54888
  return count4;
54889
54889
  }
54890
- function getFullPath(resolver, id = "", normalize) {
54891
- if (normalize !== false)
54890
+ function getFullPath(resolver, id = "", normalize2) {
54891
+ if (normalize2 !== false)
54892
54892
  id = normalizeId(id);
54893
54893
  const p = resolver.parse(id);
54894
54894
  return _getFullPath(resolver, p);
@@ -74755,7 +74755,7 @@ var require_type_is = __commonJS({
74755
74755
  module2.exports = typeofrequest;
74756
74756
  module2.exports.is = typeis;
74757
74757
  module2.exports.hasBody = hasbody;
74758
- module2.exports.normalize = normalize;
74758
+ module2.exports.normalize = normalize2;
74759
74759
  module2.exports.match = mimeMatch;
74760
74760
  function typeis(value, types_) {
74761
74761
  var i;
@@ -74775,7 +74775,7 @@ var require_type_is = __commonJS({
74775
74775
  }
74776
74776
  var type;
74777
74777
  for (i = 0; i < types2.length; i++) {
74778
- if (mimeMatch(normalize(type = types2[i]), val)) {
74778
+ if (mimeMatch(normalize2(type = types2[i]), val)) {
74779
74779
  return type[0] === "+" || type.indexOf("*") !== -1 ? val : type;
74780
74780
  }
74781
74781
  }
@@ -74790,7 +74790,7 @@ var require_type_is = __commonJS({
74790
74790
  var value = req.headers["content-type"];
74791
74791
  return typeis(value, types2);
74792
74792
  }
74793
- function normalize(type) {
74793
+ function normalize2(type) {
74794
74794
  if (typeof type !== "string") {
74795
74795
  return false;
74796
74796
  }
@@ -78070,10 +78070,10 @@ var require_view = __commonJS({
78070
78070
  var debug = require_src()("express:view");
78071
78071
  var path2 = require("node:path");
78072
78072
  var fs = require("node:fs");
78073
- var dirname5 = path2.dirname;
78073
+ var dirname6 = path2.dirname;
78074
78074
  var basename4 = path2.basename;
78075
78075
  var extname = path2.extname;
78076
- var join21 = path2.join;
78076
+ var join22 = path2.join;
78077
78077
  var resolve5 = path2.resolve;
78078
78078
  module2.exports = View;
78079
78079
  function View(name, options) {
@@ -78109,7 +78109,7 @@ var require_view = __commonJS({
78109
78109
  for (var i = 0; i < roots.length && !path3; i++) {
78110
78110
  var root = roots[i];
78111
78111
  var loc = resolve5(root, name);
78112
- var dir = dirname5(loc);
78112
+ var dir = dirname6(loc);
78113
78113
  var file2 = basename4(loc);
78114
78114
  path3 = this.resolve(dir, file2);
78115
78115
  }
@@ -78135,12 +78135,12 @@ var require_view = __commonJS({
78135
78135
  };
78136
78136
  View.prototype.resolve = function resolve6(dir, file2) {
78137
78137
  var ext = this.ext;
78138
- var path3 = join21(dir, file2);
78138
+ var path3 = join22(dir, file2);
78139
78139
  var stat = tryStat(path3);
78140
78140
  if (stat && stat.isFile()) {
78141
78141
  return path3;
78142
78142
  }
78143
- path3 = join21(dir, basename4(file2, ext), "index" + ext);
78143
+ path3 = join22(dir, basename4(file2, ext), "index" + ext);
78144
78144
  stat = tryStat(path3);
78145
78145
  if (stat && stat.isFile()) {
78146
78146
  return path3;
@@ -81785,8 +81785,8 @@ var require_send = __commonJS({
81785
81785
  var Stream = require("stream");
81786
81786
  var util2 = require("util");
81787
81787
  var extname = path2.extname;
81788
- var join21 = path2.join;
81789
- var normalize = path2.normalize;
81788
+ var join22 = path2.join;
81789
+ var normalize2 = path2.normalize;
81790
81790
  var resolve5 = path2.resolve;
81791
81791
  var sep3 = path2.sep;
81792
81792
  var BYTES_RANGE_REGEXP = /^ *bytes=/;
@@ -81949,7 +81949,7 @@ var require_send = __commonJS({
81949
81949
  var parts;
81950
81950
  if (root !== null) {
81951
81951
  if (path3) {
81952
- path3 = normalize("." + sep3 + path3);
81952
+ path3 = normalize2("." + sep3 + path3);
81953
81953
  }
81954
81954
  if (UP_PATH_REGEXP.test(path3)) {
81955
81955
  debug('malicious path "%s"', path3);
@@ -81957,14 +81957,14 @@ var require_send = __commonJS({
81957
81957
  return res;
81958
81958
  }
81959
81959
  parts = path3.split(sep3);
81960
- path3 = normalize(join21(root, path3));
81960
+ path3 = normalize2(join22(root, path3));
81961
81961
  } else {
81962
81962
  if (UP_PATH_REGEXP.test(path3)) {
81963
81963
  debug('malicious path "%s"', path3);
81964
81964
  this.error(403);
81965
81965
  return res;
81966
81966
  }
81967
- parts = normalize(path3).split(sep3);
81967
+ parts = normalize2(path3).split(sep3);
81968
81968
  path3 = resolve5(path3);
81969
81969
  }
81970
81970
  if (containsDotFile(parts)) {
@@ -82090,7 +82090,7 @@ var require_send = __commonJS({
82090
82090
  if (err2) return self.onStatError(err2);
82091
82091
  return self.error(404);
82092
82092
  }
82093
- var p = join21(path3, self._index[i]);
82093
+ var p = join22(path3, self._index[i]);
82094
82094
  debug('stat "%s"', p);
82095
82095
  fs.stat(p, function(err3, stat) {
82096
82096
  if (err3) return next(err3);
@@ -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
+ }
85881
85908
  });
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")
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
+ ] : [];
85917
+ });
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;
@@ -87081,7 +87144,7 @@ async function calibrateTask(deps, options, commands, task) {
87081
87144
  `\u2026 ${label} [${side}]: tests run ${i + 1}/${options.runs} ${test.code === 0 ? "passed" : "failed"} in ${since(testAt)}`
87082
87145
  );
87083
87146
  if (side === "base" && test.code !== 0 && !baseErrors)
87084
- baseErrors = testErrorsOf(test.output);
87147
+ baseErrors = testErrorsOf(test.output, dir);
87085
87148
  if (side === "target" && test.code !== 0)
87086
87149
  for (const line of test.output.trim().split("\n").slice(-FAILURE_LINES))
87087
87150
  deps.log(` ${line}`);
@@ -87755,6 +87818,139 @@ var init_replay_relevance = __esm({
87755
87818
  }
87756
87819
  });
87757
87820
 
87821
+ // src/commands/replay-interface.ts
87822
+ function importsOf(source) {
87823
+ const text = stripComments(source);
87824
+ const out = /* @__PURE__ */ new Map();
87825
+ const re = /\bimport\s+(?:type\s+)?([\w$]+\s*,?\s*)?(?:\{([^}]*)\}|\*\s+as\s+[\w$]+)?\s*from\s*["']([^"']+)["']/g;
87826
+ let m;
87827
+ while (m = re.exec(text)) {
87828
+ const spec2 = m[3];
87829
+ if (!spec2.startsWith(".")) continue;
87830
+ const entry2 = out.get(spec2) ?? { spec: spec2, names: [], defaultImport: false };
87831
+ const head = (m[1] ?? "").replace(/,/g, "").trim();
87832
+ if (head && head !== "type" && IDENT.test(head)) entry2.defaultImport = true;
87833
+ for (const part of (m[2] ?? "").split(",")) {
87834
+ const name = part.trim().replace(/^type\s+/, "").split(/\s+as\s+/)[0].trim();
87835
+ if (name === "default") entry2.defaultImport = true;
87836
+ else if (IDENT.test(name) && !entry2.names.includes(name))
87837
+ entry2.names.push(name);
87838
+ }
87839
+ out.set(spec2, entry2);
87840
+ }
87841
+ return [...out.values()];
87842
+ }
87843
+ function exportsName(source, name) {
87844
+ const text = stripComments(source);
87845
+ if (/\bexport\s+\*\s+from\b/.test(text)) return true;
87846
+ const n = name.replace(/\$/g, "\\$");
87847
+ if (new RegExp(
87848
+ `\\bexport\\s+(?:declare\\s+)?(?:default\\s+)?(?:async\\s+)?(?:abstract\\s+)?(?:function\\*?|const|let|var|class|interface|type|enum|namespace)\\s+${n}\\b`
87849
+ ).test(text))
87850
+ return true;
87851
+ const lists = text.matchAll(/\bexport\s+(?:type\s+)?\{([^}]*)\}/g);
87852
+ for (const list2 of lists)
87853
+ for (const part of list2[1].split(",")) {
87854
+ const exported = part.trim().split(/\s+as\s+/);
87855
+ const as = (exported[1] ?? exported[0]).replace(/^type\s+/, "").trim();
87856
+ if (as === name) return true;
87857
+ }
87858
+ return false;
87859
+ }
87860
+ function hasDefaultExport(source) {
87861
+ const text = stripComments(source);
87862
+ return /\bexport\s+default\b/.test(text) || /\bexport\s*\{[^}]*\bas\s+default\b/.test(text) || // CommonJS: what a default import of it receives.
87863
+ /\bmodule\.exports\s*=/.test(text);
87864
+ }
87865
+ function candidatesFor(fromFile, spec2) {
87866
+ const base = (0, import_node_path15.normalize)((0, import_node_path15.join)((0, import_node_path15.dirname)(fromFile), spec2)).replace(/\\/g, "/");
87867
+ if (base.startsWith("..")) return [];
87868
+ const stem2 = base.replace(/\.(?:[cm]?js|jsx)$/, "");
87869
+ const withExt = /\.[cm]?[jt]sx?$/.test(base) ? [base] : [];
87870
+ return [
87871
+ ...withExt,
87872
+ ...EXTENSIONS.map((e) => `${stem2}${e}`),
87873
+ ...EXTENSIONS.map((e) => `${stem2}/index${e}`)
87874
+ ].filter((p, i, all) => all.indexOf(p) === i);
87875
+ }
87876
+ async function firstAt(show, sha, paths) {
87877
+ for (const path2 of paths) {
87878
+ const source = await show(sha, path2);
87879
+ if (source !== null) return { path: path2, source };
87880
+ }
87881
+ return null;
87882
+ }
87883
+ async function testInterfaceOf(show, task) {
87884
+ const tests = new Set(task.testFiles);
87885
+ const byPath = /* @__PURE__ */ new Map();
87886
+ for (const file2 of task.testFiles) {
87887
+ if (!JS_TEST.test(file2)) continue;
87888
+ const source = await show(task.targetSha, file2);
87889
+ if (source === null) continue;
87890
+ for (const imp of importsOf(source)) {
87891
+ const candidates = candidatesFor(file2, imp.spec);
87892
+ const atTarget = await firstAt(show, task.targetSha, candidates);
87893
+ if (!atTarget || tests.has(atTarget.path)) continue;
87894
+ if (/(^|\/)(__tests__|__mocks__|__fixtures__|fixtures?|test-utils?)\//.test(
87895
+ atTarget.path
87896
+ ))
87897
+ continue;
87898
+ const atBase = await show(task.baseSha, atTarget.path);
87899
+ const names = imp.names.filter(
87900
+ (n) => atBase === null || !exportsName(atBase, n)
87901
+ );
87902
+ const defaultExport = imp.defaultImport && (atBase === null || !hasDefaultExport(atBase));
87903
+ if (atBase !== null && names.length === 0 && !defaultExport) continue;
87904
+ const entry2 = byPath.get(atTarget.path) ?? {
87905
+ path: atTarget.path,
87906
+ newFile: atBase === null,
87907
+ names: [],
87908
+ defaultExport: false
87909
+ };
87910
+ for (const n of names) if (!entry2.names.includes(n)) entry2.names.push(n);
87911
+ entry2.defaultExport ||= defaultExport;
87912
+ byPath.set(atTarget.path, entry2);
87913
+ }
87914
+ }
87915
+ let budget = MAX_INTERFACE_NAMES;
87916
+ return [...byPath.values()].slice(0, MAX_INTERFACE_MODULES).map((e) => {
87917
+ const names = e.names.slice(0, Math.max(0, budget));
87918
+ budget -= names.length;
87919
+ return { ...e, names };
87920
+ });
87921
+ }
87922
+ function interfaceSection(entries) {
87923
+ if (entries.length === 0) return [];
87924
+ return [
87925
+ "## What the tests use",
87926
+ "",
87927
+ "The task's tests import these from the code, and they do not exist yet. Create them at these paths with these names; how they work is up to you.",
87928
+ "",
87929
+ ...entries.map((e) => {
87930
+ const what = [
87931
+ ...e.defaultExport ? ["a default export"] : [],
87932
+ ...e.names.map((n) => `\`${n}\``)
87933
+ ];
87934
+ const where = `\`${e.path}\`${e.newFile ? " (a new file)" : ""}`;
87935
+ return `- ${where}${what.length ? `: ${what.join(", ")}` : ""}`;
87936
+ }),
87937
+ ""
87938
+ ];
87939
+ }
87940
+ var import_node_path15, MAX_INTERFACE_MODULES, MAX_INTERFACE_NAMES, JS_TEST, EXTENSIONS, IDENT, stripComments;
87941
+ var init_replay_interface = __esm({
87942
+ "src/commands/replay-interface.ts"() {
87943
+ "use strict";
87944
+ import_node_path15 = require("node:path");
87945
+ MAX_INTERFACE_MODULES = 10;
87946
+ MAX_INTERFACE_NAMES = 30;
87947
+ JS_TEST = /\.[cm]?[jt]sx?$/;
87948
+ EXTENSIONS = [".ts", ".tsx", ".js", ".jsx", ".mts", ".cts", ".mjs"];
87949
+ IDENT = /^[A-Za-z_$][\w$]*$/;
87950
+ stripComments = (source) => source.replace(/\/\*[\s\S]*?\*\//g, " ").replace(/(^|[^:])\/\/.*$/gm, "$1");
87951
+ }
87952
+ });
87953
+
87758
87954
  // src/commands/replay-tasks.ts
87759
87955
  var replay_tasks_exports = {};
87760
87956
  __export(replay_tasks_exports, {
@@ -87848,6 +88044,7 @@ function cardPrompt(task, feedback, arm = "baseline", tools = []) {
87848
88044
  task.card.acceptance,
87849
88045
  ...task.card.area ? ["", "## Part of the code", "", task.card.area] : [],
87850
88046
  "",
88047
+ ...interfaceSection(task.testInterface ?? []),
87851
88048
  ...arm === "haansi" ? tools.length ? haansiSection(tools) : [HAANSI_LINE, ""] : [],
87852
88049
  ...feedback ? [FEEDBACK_HEADER, "", "```", feedback, "```", ""] : [],
87853
88050
  CODE_ONLY_LINE,
@@ -88029,6 +88226,17 @@ async function runStoredReplays(options, deps) {
88029
88226
  };
88030
88227
  const targetText = await referenceDiffOf(deps, task).catch(() => null);
88031
88228
  const targetChanges = targetText === null ? null : parseDiff(targetText);
88229
+ if (!asTask.testNames?.length && task.baseSha && task.targetSha) {
88230
+ task.testInterface = await testInterfaceOf(deps.showFile, {
88231
+ baseSha: task.baseSha,
88232
+ targetSha: task.targetSha,
88233
+ testFiles: task.testFiles
88234
+ }).catch(() => []);
88235
+ if (task.testInterface.length)
88236
+ deps.log(
88237
+ `\u2026 ${label}: the tests use ${task.testInterface.length} module(s) the start lacks; named in the prompt`
88238
+ );
88239
+ }
88032
88240
  let targetSent = false;
88033
88241
  for (const arm of arms) {
88034
88242
  if (!options.force && alreadyMeasured(
@@ -88237,6 +88445,7 @@ var init_replay_tasks = __esm({
88237
88445
  init_replay_judge();
88238
88446
  init_replay();
88239
88447
  init_replay_scale();
88448
+ init_replay_interface();
88240
88449
  FEEDBACK_HEADER = "Your previous attempt did not pass the tests. Their output ends with:";
88241
88450
  REPORT_CHUNK2 = 200;
88242
88451
  REPORT_CHARS = 4e6;
@@ -88408,7 +88617,7 @@ function cleanCheckout(deps, dir, task) {
88408
88617
  }
88409
88618
  async function replayArm(deps, options, task, arm, promptOf, inspect, agentEnv = {}) {
88410
88619
  const started = deps.now();
88411
- const dir = (0, import_node_path15.join)(
88620
+ const dir = (0, import_node_path16.join)(
88412
88621
  deps.workDir(),
88413
88622
  `${task.processId.replace(/[^a-zA-Z0-9_-]/g, "")}-${arm}`
88414
88623
  );
@@ -88437,7 +88646,7 @@ async function replayArm(deps, options, task, arm, promptOf, inspect, agentEnv =
88437
88646
  `\u2026 ${label}: set up in ${since(at)}${setup.cached ? " (from the setup cache)" : ""}`
88438
88647
  );
88439
88648
  }
88440
- const promptFile = (0, import_node_path15.join)(dir, ".haansi-replay", "prompt.md");
88649
+ const promptFile = (0, import_node_path16.join)(dir, ".haansi-replay", "prompt.md");
88441
88650
  let mcpConfigFile = agentEnv.HAANSI_REPLAY_MCP_CONFIG;
88442
88651
  if (!mcpConfigFile) {
88443
88652
  mcpConfigFile = `${dir}.mcp.json`;
@@ -88490,11 +88699,11 @@ async function replayArm(deps, options, task, arm, promptOf, inspect, agentEnv =
88490
88699
  deps.log(` ${line}`);
88491
88700
  }
88492
88701
  const gradeSha = task.testNames?.length ? task.baseSha : task.targetSha;
88493
- const own = new Map(files.map((f) => [f, deps.readFile((0, import_node_path15.join)(dir, f))]));
88702
+ const own = new Map(files.map((f) => [f, deps.readFile((0, import_node_path16.join)(dir, f))]));
88494
88703
  for (const f of files) {
88495
88704
  const content = await deps.showFile(gradeSha, f);
88496
- if (content === null) deps.removeFile((0, import_node_path15.join)(dir, f));
88497
- else deps.writeFile((0, import_node_path15.join)(dir, f), content);
88705
+ if (content === null) deps.removeFile((0, import_node_path16.join)(dir, f));
88706
+ else deps.writeFile((0, import_node_path16.join)(dir, f), content);
88498
88707
  }
88499
88708
  const testAt = deps.now();
88500
88709
  deps.log(`\u2026 ${label}: agent done in ${since(agentAt)}, grading`);
@@ -88510,10 +88719,11 @@ async function replayArm(deps, options, task, arm, promptOf, inspect, agentEnv =
88510
88719
  `\u2026 ${label}: tests ${test.code === 0 ? "passed" : "failed"} in ${since(testAt)}${counted ? ` (${counted.passed}/${counted.total} passed)` : ""}`
88511
88720
  );
88512
88721
  if (test.code !== 0) {
88513
- const error2 = attemptErrorOf(test.output, {
88514
- attempt,
88515
- agentExit: agent.code
88516
- });
88722
+ const error2 = attemptErrorOf(
88723
+ test.output,
88724
+ { attempt, agentExit: agent.code },
88725
+ dir
88726
+ );
88517
88727
  errors.push(error2);
88518
88728
  for (const name of error2.failing) deps.log(` failing: ${name}`);
88519
88729
  for (const line of test.output.trim().split("\n").slice(-FAILURE_LINES2))
@@ -88524,9 +88734,15 @@ async function replayArm(deps, options, task, arm, promptOf, inspect, agentEnv =
88524
88734
  const after = await wholeRun();
88525
88735
  const verdict2 = guardVerdict(guardStart, after, MAX_ERROR_TESTS);
88526
88736
  if (verdict2.kind === "broke") {
88737
+ const whole = attemptErrorOf(
88738
+ after.output,
88739
+ { attempt, agentExit: agent.code },
88740
+ dir
88741
+ );
88527
88742
  guarded = {
88528
- ...attemptErrorOf(after.output, { attempt, agentExit: agent.code }),
88529
- failing: verdict2.tests
88743
+ ...whole,
88744
+ failing: verdict2.tests,
88745
+ tests: whole.tests?.filter((t) => verdict2.tests.includes(t.name))
88530
88746
  };
88531
88747
  errors.push(guarded);
88532
88748
  deps.log(
@@ -88538,8 +88754,8 @@ async function replayArm(deps, options, task, arm, promptOf, inspect, agentEnv =
88538
88754
  }
88539
88755
  if (test.code === 0 && !guarded) {
88540
88756
  for (const [file2, content] of own) {
88541
- if (content === null) deps.removeFile((0, import_node_path15.join)(dir, file2));
88542
- else deps.writeFile((0, import_node_path15.join)(dir, file2), content);
88757
+ if (content === null) deps.removeFile((0, import_node_path16.join)(dir, file2));
88758
+ else deps.writeFile((0, import_node_path16.join)(dir, file2), content);
88543
88759
  }
88544
88760
  if (inspect) await inspect(dir);
88545
88761
  return {
@@ -88555,8 +88771,8 @@ async function replayArm(deps, options, task, arm, promptOf, inspect, agentEnv =
88555
88771
  };
88556
88772
  }
88557
88773
  for (const [file2, content] of own) {
88558
- if (content === null) deps.removeFile((0, import_node_path15.join)(dir, file2));
88559
- else deps.writeFile((0, import_node_path15.join)(dir, file2), content);
88774
+ if (content === null) deps.removeFile((0, import_node_path16.join)(dir, file2));
88775
+ else deps.writeFile((0, import_node_path16.join)(dir, file2), content);
88560
88776
  }
88561
88777
  feedback = guarded ? [
88562
88778
  GUARD_FEEDBACK,
@@ -88623,11 +88839,11 @@ function runCommand(file2, args, cwd, env, timeoutMs, stdoutOnly = false) {
88623
88839
  });
88624
88840
  }
88625
88841
  function dropLinks(work, path2) {
88626
- const rel = (0, import_node_path15.relative)(work, path2);
88627
- if (rel === "" || rel.startsWith("..") || (0, import_node_path15.isAbsolute)(rel)) return;
88842
+ const rel = (0, import_node_path16.relative)(work, path2);
88843
+ if (rel === "" || rel.startsWith("..") || (0, import_node_path16.isAbsolute)(rel)) return;
88628
88844
  let at = work;
88629
- for (const part of rel.split(import_node_path15.sep)) {
88630
- at = (0, import_node_path15.join)(at, part);
88845
+ for (const part of rel.split(import_node_path16.sep)) {
88846
+ at = (0, import_node_path16.join)(at, part);
88631
88847
  let link = false;
88632
88848
  try {
88633
88849
  link = (0, import_node_fs13.lstatSync)(at).isSymbolicLink();
@@ -88662,7 +88878,7 @@ function localDeps(work) {
88662
88878
  // dropLinks: with a container, nothing runs in it while these do.
88663
88879
  writeFile: (path2, content) => {
88664
88880
  dropLinks(work, path2);
88665
- (0, import_node_fs13.mkdirSync)((0, import_node_path15.dirname)(path2), { recursive: true });
88881
+ (0, import_node_fs13.mkdirSync)((0, import_node_path16.dirname)(path2), { recursive: true });
88666
88882
  const fd2 = (0, import_node_fs13.openSync)(
88667
88883
  path2,
88668
88884
  import_node_fs13.constants.O_WRONLY | import_node_fs13.constants.O_CREAT | import_node_fs13.constants.O_TRUNC | import_node_fs13.constants.O_NOFOLLOW
@@ -88723,7 +88939,7 @@ async function replay(argv) {
88723
88939
  async function replayStored(options, token2, apiUrl2) {
88724
88940
  const { runStoredReplays: runStoredReplays2 } = await Promise.resolve().then(() => (init_replay_tasks(), replay_tasks_exports));
88725
88941
  const { cliVersion: cliVersion2 } = await Promise.resolve().then(() => (init_replay_calibrate(), replay_calibrate_exports));
88726
- const work = (0, import_node_fs13.mkdtempSync)((0, import_node_path15.join)((0, import_node_os11.tmpdir)(), "haansi-replay-"));
88942
+ const work = (0, import_node_fs13.mkdtempSync)((0, import_node_path16.join)((0, import_node_os11.tmpdir)(), "haansi-replay-"));
88727
88943
  let stop = null;
88728
88944
  try {
88729
88945
  const contained = await withContainer(
@@ -88794,14 +89010,14 @@ Baseline: ${arm("baseline")} passed \xB7 With Haansi: ${arm("haansi")} passed \x
88794
89010
  (0, import_node_fs13.rmSync)(work, { recursive: true, force: true });
88795
89011
  }
88796
89012
  }
88797
- var import_node_child_process5, import_node_fs13, import_node_os11, import_node_path15, SHA, ARMS, FEEDBACK_CHARS, FAILURE_LINES2, REPLAY_BRANCH, USAGE2;
89013
+ var import_node_child_process5, import_node_fs13, import_node_os11, import_node_path16, SHA, ARMS, FEEDBACK_CHARS, FAILURE_LINES2, REPLAY_BRANCH, USAGE2;
88798
89014
  var init_replay = __esm({
88799
89015
  "src/commands/replay.ts"() {
88800
89016
  "use strict";
88801
89017
  import_node_child_process5 = require("node:child_process");
88802
89018
  import_node_fs13 = require("node:fs");
88803
89019
  import_node_os11 = require("node:os");
88804
- import_node_path15 = require("node:path");
89020
+ import_node_path16 = require("node:path");
88805
89021
  init_paths();
88806
89022
  init_replay_errors();
88807
89023
  init_api2();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "haansi",
3
- "version": "0.1.95",
3
+ "version": "0.1.97",
4
4
  "description": "Haansi CLI - Session collector and MCP server for Claude Code & OpenAI Codex",
5
5
  "bin": {
6
6
  "haansi": "./dist/haansi.js"