haansi 0.1.133 → 0.1.134

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 +515 -318
  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.133",
98
+ version: "0.1.134",
99
99
  description: "Haansi CLI - Session collector and MCP server for Claude Code & OpenAI Codex",
100
100
  bin: {
101
101
  haansi: "./dist/haansi.js"
@@ -78416,7 +78416,7 @@ var require_view = __commonJS({
78416
78416
  var dirname6 = path2.dirname;
78417
78417
  var basename4 = path2.basename;
78418
78418
  var extname = path2.extname;
78419
- var join23 = path2.join;
78419
+ var join24 = path2.join;
78420
78420
  var resolve5 = path2.resolve;
78421
78421
  module2.exports = View;
78422
78422
  function View(name, options) {
@@ -78478,12 +78478,12 @@ var require_view = __commonJS({
78478
78478
  };
78479
78479
  View.prototype.resolve = function resolve6(dir, file2) {
78480
78480
  var ext = this.ext;
78481
- var path3 = join23(dir, file2);
78481
+ var path3 = join24(dir, file2);
78482
78482
  var stat = tryStat(path3);
78483
78483
  if (stat && stat.isFile()) {
78484
78484
  return path3;
78485
78485
  }
78486
- path3 = join23(dir, basename4(file2, ext), "index" + ext);
78486
+ path3 = join24(dir, basename4(file2, ext), "index" + ext);
78487
78487
  stat = tryStat(path3);
78488
78488
  if (stat && stat.isFile()) {
78489
78489
  return path3;
@@ -82128,7 +82128,7 @@ var require_send = __commonJS({
82128
82128
  var Stream = require("stream");
82129
82129
  var util2 = require("util");
82130
82130
  var extname = path2.extname;
82131
- var join23 = path2.join;
82131
+ var join24 = path2.join;
82132
82132
  var normalize2 = path2.normalize;
82133
82133
  var resolve5 = path2.resolve;
82134
82134
  var sep3 = path2.sep;
@@ -82300,7 +82300,7 @@ var require_send = __commonJS({
82300
82300
  return res;
82301
82301
  }
82302
82302
  parts = path3.split(sep3);
82303
- path3 = normalize2(join23(root, path3));
82303
+ path3 = normalize2(join24(root, path3));
82304
82304
  } else {
82305
82305
  if (UP_PATH_REGEXP.test(path3)) {
82306
82306
  debug('malicious path "%s"', path3);
@@ -82433,7 +82433,7 @@ var require_send = __commonJS({
82433
82433
  if (err2) return self.onStatError(err2);
82434
82434
  return self.error(404);
82435
82435
  }
82436
- var p = join23(path3, self._index[i]);
82436
+ var p = join24(path3, self._index[i]);
82437
82437
  debug('stat "%s"', p);
82438
82438
  fs.stat(p, function(err3, stat) {
82439
82439
  if (err3) return next(err3);
@@ -88552,6 +88552,308 @@ var init_replay_scale = __esm({
88552
88552
  }
88553
88553
  });
88554
88554
 
88555
+ // src/commands/replay-failure-paths.ts
88556
+ function isAppFile(path2) {
88557
+ return SOURCE.test(path2) && !TEST_FILE2.test(path2) && !isTestSupport(path2) && !/(^|\/)(node_modules|dist|build|coverage|\.next)\//.test(path2);
88558
+ }
88559
+ function stackFramesOf(output) {
88560
+ const out = [];
88561
+ const seen = /* @__PURE__ */ new Set();
88562
+ for (const raw of output.split("\n")) {
88563
+ const line = relativePaths(raw);
88564
+ for (const m of line.matchAll(FRAME)) {
88565
+ const path2 = m[1].replace(/^\.\//, "");
88566
+ const n = Number(m[2]);
88567
+ if (!n || path2.split("/").includes("..") || !isAppFile(path2)) continue;
88568
+ const key = `${path2}:${n}`;
88569
+ if (seen.has(key)) continue;
88570
+ seen.add(key);
88571
+ out.push({ path: path2, line: n });
88572
+ if (out.length >= MAX_FRAMES) return out;
88573
+ }
88574
+ }
88575
+ return out;
88576
+ }
88577
+ async function resolveFrames(show, baseSha, frames) {
88578
+ const out = [];
88579
+ for (const f of frames) {
88580
+ const parts = f.path.replace(/^\/+/, "").split("/");
88581
+ const tries = f.path.startsWith("/") ? parts.slice(1, ABSOLUTE_TRIES + 1).map((_, i) => parts.slice(i + 1).join("/")) : [f.path];
88582
+ for (const p of tries) {
88583
+ if (!p || !isAppFile(p)) continue;
88584
+ if (await show(baseSha, p).catch(() => null) !== null) {
88585
+ if (!out.some((o) => o.path === p && o.line === f.line))
88586
+ out.push({ path: p, line: f.line });
88587
+ break;
88588
+ }
88589
+ }
88590
+ }
88591
+ return out;
88592
+ }
88593
+ function boundedGit(git, max2 = MAX_GIT_CALLS) {
88594
+ let calls = 0;
88595
+ return async (args) => {
88596
+ if (calls >= max2) return { code: 1, output: "" };
88597
+ calls += 1;
88598
+ try {
88599
+ return await git(args);
88600
+ } catch {
88601
+ return { code: 1, output: "" };
88602
+ }
88603
+ };
88604
+ }
88605
+ async function filesOfCommit(git, sha) {
88606
+ const out = await git(["show", "--name-only", "--format=", sha]);
88607
+ if (out.code !== 0) return [];
88608
+ return out.output.split("\n").map((l) => l.trim()).filter((l) => l && isAppFile(l)).slice(0, FILES_PER_COMMIT);
88609
+ }
88610
+ async function filesOfCommits(git, commits) {
88611
+ const out = [];
88612
+ for (const sha of commits.slice(0, MAX_COMMITS)) {
88613
+ for (const f of await filesOfCommit(git, sha))
88614
+ if (!out.includes(f)) out.push(f);
88615
+ if (out.length >= MAX_WHERE_PATHS) break;
88616
+ }
88617
+ return out.slice(0, MAX_WHERE_PATHS);
88618
+ }
88619
+ async function blamedPaths(git, baseSha, frames) {
88620
+ const commits = [];
88621
+ for (const f of frames.slice(0, MAX_FRAMES)) {
88622
+ const out = await git([
88623
+ "blame",
88624
+ "-L",
88625
+ `${f.line},${f.line}`,
88626
+ "--porcelain",
88627
+ baseSha,
88628
+ "--",
88629
+ f.path
88630
+ ]);
88631
+ if (out.code !== 0) continue;
88632
+ const sha = out.output.split(/\s/)[0] ?? "";
88633
+ if (SHA.test(sha) && !/^0+$/.test(sha) && !commits.includes(sha))
88634
+ commits.push(sha);
88635
+ }
88636
+ const files = await filesOfCommits(git, commits);
88637
+ return [.../* @__PURE__ */ new Set([...frames.map((f) => f.path), ...files])].slice(
88638
+ 0,
88639
+ MAX_WHERE_PATHS
88640
+ );
88641
+ }
88642
+ async function historyPaths(git, baseSha, files) {
88643
+ const commits = /* @__PURE__ */ new Map();
88644
+ for (const file2 of files.slice(0, MAX_HISTORY_FILES)) {
88645
+ const out = await git([
88646
+ "log",
88647
+ "-n",
88648
+ String(COMMITS_PER_FILE),
88649
+ "--format=%H %ct",
88650
+ baseSha,
88651
+ "--",
88652
+ file2
88653
+ ]);
88654
+ if (out.code !== 0) continue;
88655
+ for (const line of out.output.split("\n")) {
88656
+ const [sha, at] = line.trim().split(/\s+/);
88657
+ if (sha && SHA.test(sha) && !commits.has(sha))
88658
+ commits.set(sha, Number(at) || 0);
88659
+ }
88660
+ }
88661
+ const newest = [...commits.entries()].sort((a, b) => b[1] - a[1]).map(([sha]) => sha);
88662
+ return filesOfCommits(git, newest);
88663
+ }
88664
+ var MAX_FRAMES, COMMITS_PER_FILE, MAX_HISTORY_FILES, MAX_COMMITS, FILES_PER_COMMIT, MAX_WHERE_PATHS, MAX_GIT_CALLS, ABSOLUTE_TRIES, SOURCE, TEST_FILE2, SHA, FRAME;
88665
+ var init_replay_failure_paths = __esm({
88666
+ "src/commands/replay-failure-paths.ts"() {
88667
+ "use strict";
88668
+ init_replay_errors();
88669
+ init_replay_interface();
88670
+ MAX_FRAMES = 10;
88671
+ COMMITS_PER_FILE = 3;
88672
+ MAX_HISTORY_FILES = 16;
88673
+ MAX_COMMITS = 4;
88674
+ FILES_PER_COMMIT = 4;
88675
+ MAX_WHERE_PATHS = 6;
88676
+ MAX_GIT_CALLS = 40;
88677
+ ABSOLUTE_TRIES = 6;
88678
+ SOURCE = /\.(?:[cm]?[jt]sx?|py|go)$/;
88679
+ TEST_FILE2 = /(?:\.(?:test|spec)\.[cm]?[jt]sx?|_test\.go|(?:^|\/)test_[^/]*\.py|_test\.py)$/;
88680
+ SHA = /^[0-9a-f]{40}$/;
88681
+ FRAME = /(?:file:\/\/)?((?:\/|\.{0,2}\/)?(?:[\w.@+-]+\/)*[\w.@+-]+\.(?:[cm]?[jt]sx?|py|go)):(\d+)(?::\d+)?/g;
88682
+ }
88683
+ });
88684
+
88685
+ // src/commands/replay-spec.ts
88686
+ async function targetTestTitles(show, task) {
88687
+ const out = [];
88688
+ for (const file2 of task.testFiles) {
88689
+ const lang = adapterFor(file2);
88690
+ if (!lang) continue;
88691
+ const source = await show(task.targetSha, file2);
88692
+ if (source === null) continue;
88693
+ for (const t of lang.testTitles(source, file2)) out.push(`${file2} \u203A ${t}`);
88694
+ }
88695
+ return out;
88696
+ }
88697
+ function cappedTitles(titles) {
88698
+ const shown = [];
88699
+ let chars = 0;
88700
+ for (const t of titles) {
88701
+ if (shown.length >= MAX_TITLES || chars + t.length > MAX_TITLE_CHARS) break;
88702
+ shown.push(t);
88703
+ chars += t.length;
88704
+ }
88705
+ return { shown, more: titles.length - shown.length };
88706
+ }
88707
+ function typeNamesIn(declaration) {
88708
+ return [...new Set(declaration.match(/\b[A-Z][A-Za-z0-9_]*\b/g) ?? [])];
88709
+ }
88710
+ async function withSignatures(show, targetSha, entries) {
88711
+ const out = [];
88712
+ for (const e of entries) {
88713
+ const source = e.names.length ? await show(targetSha, e.path) : null;
88714
+ const lang = adapterFor(e.path);
88715
+ const signatures = {};
88716
+ for (const n of e.names) {
88717
+ const sig = source === null ? null : lang?.signatureOf(source, n) ?? null;
88718
+ if (sig) signatures[n] = sig;
88719
+ }
88720
+ const types2 = {};
88721
+ if (source !== null && lang) {
88722
+ const queue = Object.values(signatures).flatMap(typeNamesIn);
88723
+ const seen = new Set(e.names);
88724
+ while (queue.length && Object.keys(types2).length < MAX_TYPE_DECLARATIONS) {
88725
+ const name = queue.shift();
88726
+ if (seen.has(name)) continue;
88727
+ seen.add(name);
88728
+ const sig = lang.signatureOf(source, name);
88729
+ if (!sig) continue;
88730
+ types2[name] = sig;
88731
+ queue.push(...typeNamesIn(sig));
88732
+ }
88733
+ }
88734
+ out.push({
88735
+ ...e,
88736
+ ...Object.keys(signatures).length ? { signatures } : {},
88737
+ ...Object.keys(types2).length ? { types: types2 } : {}
88738
+ });
88739
+ }
88740
+ return out;
88741
+ }
88742
+ function fileOfTest(name) {
88743
+ const file2 = name.split(" \u203A ")[0]?.trim() ?? "";
88744
+ return /\.[cm]?[jt]sx?$|\.py$|_test\.go$/.test(file2) && !/\s/.test(file2) ? file2 : null;
88745
+ }
88746
+ function titleOfTest(name) {
88747
+ const parts = name.split(" \u203A ");
88748
+ return (fileOfTest(name) ? parts.slice(1) : parts).join(" \u203A ").trim();
88749
+ }
88750
+ async function hopOf(show, baseSha, from, skip) {
88751
+ const out = [];
88752
+ for (const file2 of from) {
88753
+ if (out.length >= MAX_HOP_MODULES) break;
88754
+ const lang = adapterFor(file2);
88755
+ if (!lang) continue;
88756
+ const source = await show(baseSha, file2).catch(() => null);
88757
+ if (source === null) continue;
88758
+ for (const candidates of lang.dependencies(source, file2)) {
88759
+ if (out.length >= MAX_HOP_MODULES) break;
88760
+ const at = await firstAt(show, baseSha, candidates).catch(() => null);
88761
+ if (!at || skip.has(at.path) || adapterFor(at.path)?.isTestFile(at.path) || isTestSupport(at.path) || out.includes(at.path))
88762
+ continue;
88763
+ out.push(at.path);
88764
+ }
88765
+ }
88766
+ return out;
88767
+ }
88768
+ async function failingPathsOf(show, task, git) {
88769
+ const named = [
88770
+ ...new Set(task.tests.map(fileOfTest).filter((f) => !!f))
88771
+ ];
88772
+ const files = [...new Set(named.length ? named : task.testFiles)];
88773
+ const tests = /* @__PURE__ */ new Set([...files, ...task.testFiles]);
88774
+ const direct = await hopOf(show, task.baseSha, files, tests);
88775
+ const second = await hopOf(
88776
+ show,
88777
+ task.baseSha,
88778
+ direct,
88779
+ /* @__PURE__ */ new Set([...tests, ...direct])
88780
+ );
88781
+ let where = [];
88782
+ if (git) {
88783
+ const run3 = boundedGit(git);
88784
+ const frames = await resolveFrames(
88785
+ show,
88786
+ task.baseSha,
88787
+ stackFramesOf(task.output ?? "")
88788
+ );
88789
+ where = frames.length ? await blamedPaths(run3, task.baseSha, frames) : await historyPaths(run3, task.baseSha, [...files, ...direct, ...second]);
88790
+ }
88791
+ return [.../* @__PURE__ */ new Set([...files, ...where, ...direct, ...second])].slice(
88792
+ 0,
88793
+ MAX_FAILING_PATHS
88794
+ );
88795
+ }
88796
+ function errorLineOf(output) {
88797
+ for (const line of output.split("\n")) {
88798
+ const m = /\b\w*(?:Error|Exception)\b:?\s*(.+)$/.exec(line) ?? /\b(expected .+)$/i.exec(line);
88799
+ if (!m) continue;
88800
+ const key = norm(m[1]).slice(0, 120);
88801
+ if (key.length >= 12) return key;
88802
+ }
88803
+ return null;
88804
+ }
88805
+ function baseNameOf(path2) {
88806
+ const parts = path2.split("/");
88807
+ const file2 = parts.pop() ?? path2;
88808
+ const name = /\.py$/.test(file2) ? file2.replace(/\.py$/, "").replace(/^test_(?=.)|(?<=.)_test$/, "") : file2.replace(/\.[cm]?[jt]sx?$/, "").replace(/\.(?:test|spec)$/, "");
88809
+ return (name === "index" || name === "__init__") && parts.length ? parts[parts.length - 1] : name;
88810
+ }
88811
+ async function candidateTests(show, task) {
88812
+ const code = new Set(task.codeFiles);
88813
+ const tests = new Set(task.testFiles);
88814
+ const related = [];
88815
+ const placed = [];
88816
+ for (const file2 of task.testFiles) {
88817
+ const direct = await hopOf(show, task.targetSha, [file2], tests);
88818
+ const second = await hopOf(
88819
+ show,
88820
+ task.targetSha,
88821
+ direct,
88822
+ /* @__PURE__ */ new Set([...tests, ...direct])
88823
+ );
88824
+ if (direct.length) placed.push(file2);
88825
+ if ([...direct, ...second].some((m) => code.has(m))) related.push(file2);
88826
+ }
88827
+ const files = related.length ? related : placed.length ? [] : [...task.testFiles];
88828
+ const out = [];
88829
+ for (const file2 of files) {
88830
+ const lang = adapterFor(file2);
88831
+ if (!lang) continue;
88832
+ const source = await show(task.targetSha, file2);
88833
+ if (source === null) continue;
88834
+ const before = await show(task.baseSha, file2);
88835
+ const old = new Set(before === null ? [] : lang.testTitles(before, file2));
88836
+ for (const t of new Set(lang.testTitles(source, file2)))
88837
+ out.push({ name: `${file2} \u203A ${t}`, isNew: !old.has(t) });
88838
+ }
88839
+ return out;
88840
+ }
88841
+ var MAX_TITLES, MAX_TITLE_CHARS, MAX_FAILING_PATHS, MAX_TYPE_DECLARATIONS, MAX_HOP_MODULES, norm;
88842
+ var init_replay_spec = __esm({
88843
+ "src/commands/replay-spec.ts"() {
88844
+ "use strict";
88845
+ init_replay_interface();
88846
+ init_replay_failure_paths();
88847
+ init_replay_lang();
88848
+ MAX_TITLES = 40;
88849
+ MAX_TITLE_CHARS = 4e3;
88850
+ MAX_FAILING_PATHS = 12;
88851
+ MAX_TYPE_DECLARATIONS = 40;
88852
+ MAX_HOP_MODULES = 24;
88853
+ norm = (s) => s.replace(/\s+/g, " ").trim();
88854
+ }
88855
+ });
88856
+
88555
88857
  // src/commands/replay-ci-token.ts
88556
88858
  var replay_ci_token_exports = {};
88557
88859
  __export(replay_ci_token_exports, {
@@ -88615,6 +88917,8 @@ __export(replay_calibrate_exports, {
88615
88917
  checkCommandsOf: () => checkCommandsOf,
88616
88918
  cliVersion: () => cliVersion,
88617
88919
  environmentOf: () => environmentOf,
88920
+ expectedTestsFor: () => expectedTestsFor,
88921
+ expectedTestsOf: () => expectedTestsOf,
88618
88922
  gradeCommandOf: () => gradeCommandOf,
88619
88923
  isFeatureDelivery: () => isFeatureDelivery,
88620
88924
  parseCalibrateArgs: () => parseCalibrateArgs,
@@ -88626,6 +88930,9 @@ __export(replay_calibrate_exports, {
88626
88930
  function testNamesOf(task) {
88627
88931
  return task.kind === "recovery" ? task.failing?.tests ?? [] : [];
88628
88932
  }
88933
+ function expectedTestsOf(task) {
88934
+ return task.kind === "recovery" ? [] : task.expectedTests ?? [];
88935
+ }
88629
88936
  function checkCommandsOf(task) {
88630
88937
  return task.kind === "recovery" ? task.failing?.commands ?? [] : [];
88631
88938
  }
@@ -88634,6 +88941,35 @@ function gradeCommandOf(task, testCmd, checkCommands = false) {
88634
88941
  if (!commands.length) return testCmd;
88635
88942
  return checkCommands ? commands.join(" && ") : null;
88636
88943
  }
88944
+ async function expectedTestsFor(deps, task, pick2) {
88945
+ const codeFiles = (task.targetFiles ?? []).filter(
88946
+ (f) => !isTestPath(f) && !isDocFile(f)
88947
+ );
88948
+ const candidates = await candidateTests(deps.showFile, {
88949
+ baseSha: task.baseSha,
88950
+ targetSha: task.targetSha,
88951
+ testFiles: task.testFiles,
88952
+ codeFiles
88953
+ });
88954
+ if (candidates.length === 0) return [];
88955
+ const stat = codeFiles.length ? await (deps.gitStdout ?? deps.git)(
88956
+ [
88957
+ "diff",
88958
+ "--numstat",
88959
+ "--no-renames",
88960
+ "--end-of-options",
88961
+ task.baseSha,
88962
+ task.targetSha,
88963
+ "--",
88964
+ ...codeFiles
88965
+ ],
88966
+ deps.repoDir
88967
+ ) : { code: 1, output: "" };
88968
+ const change = stat.code === 0 ? stat.output.trim().split("\n").map((l) => l.split(" ")).filter((c) => c.length >= 3).map(
88969
+ ([a, r, path2]) => a === "-" ? `- ${path2} (binary)` : `- ${path2} (+${a} \u2212${r})`
88970
+ ).join("\n") : codeFiles.map((f) => `- ${f}`).join("\n");
88971
+ return pick2 ? pick2(task, candidates, change) : candidates.map((c) => c.name);
88972
+ }
88637
88973
  function parseCalibrateArgs(argv) {
88638
88974
  const scale = newScaleArgs((0, import_node_os10.homedir)());
88639
88975
  const options = {
@@ -88758,13 +89094,16 @@ async function calibrateTask(deps, options, commands, task) {
88758
89094
  const since = (from) => `${Math.round((deps.now() - from) / 1e3)}s`;
88759
89095
  const runs = { base: [], target: [] };
88760
89096
  let baseErrors = null;
89097
+ let expected = expectedTestsOf(task);
89098
+ let dropped = false;
88761
89099
  const done = (reason) => ({
88762
89100
  taskId: task.taskId,
88763
89101
  inputsFingerprint: task.inputsFingerprint,
88764
89102
  state: STATE[reason],
88765
89103
  reason,
88766
89104
  runs,
88767
- ...baseErrors ? { baseErrors } : {}
89105
+ ...baseErrors ? { baseErrors } : {},
89106
+ ...isFeatureDelivery(task) && expected.length ? { expectedTests: expected } : {}
88768
89107
  });
88769
89108
  const grade = gradeCommandOf(
88770
89109
  task,
@@ -88833,7 +89172,10 @@ async function calibrateTask(deps, options, commands, task) {
88833
89172
  const test = await deps.shell(
88834
89173
  grade,
88835
89174
  dir,
88836
- focusEnv(task.testFiles, testNamesOf(task)),
89175
+ focusEnv(
89176
+ task.testFiles,
89177
+ testNamesOf(task).length ? testNamesOf(task) : expected
89178
+ ),
88837
89179
  options.timeoutMs
88838
89180
  );
88839
89181
  if (test.timedOut) {
@@ -88851,6 +89193,19 @@ async function calibrateTask(deps, options, commands, task) {
88851
89193
  if (side === "target" && test.code !== 0)
88852
89194
  for (const line of test.output.trim().split("\n").slice(-FAILURE_LINES))
88853
89195
  deps.log(` ${line}`);
89196
+ if (side === "target" && test.code !== 0 && expected.length && !dropped) {
89197
+ const failing = new Set(testErrorsOf(test.output, dir).failing);
89198
+ const kept = expected.filter((t) => !failing.has(t));
89199
+ if (kept.length && kept.length < expected.length) {
89200
+ deps.log(
89201
+ `\u2026 ${label} [target]: ${expected.length - kept.length} expected test(s) fail at the target: graded on the other ${kept.length}`
89202
+ );
89203
+ expected = kept;
89204
+ dropped = true;
89205
+ runs.target = [];
89206
+ i = -1;
89207
+ }
89208
+ }
88854
89209
  }
88855
89210
  } finally {
88856
89211
  deps.removeDir(dir);
@@ -88902,7 +89257,7 @@ async function runCalibration(options, deps, preloaded) {
88902
89257
  const toRun = [];
88903
89258
  for (const task of tasks) {
88904
89259
  const label = task.name ?? task.taskKey;
88905
- if (!SHA.test(task.baseSha) || !SHA.test(task.targetSha)) {
89260
+ if (!SHA2.test(task.baseSha) || !SHA2.test(task.targetSha)) {
88906
89261
  skipped += 1;
88907
89262
  deps.log(`skip ${label}: its commits are not commit ids`);
88908
89263
  continue;
@@ -88962,11 +89317,14 @@ async function runCalibration(options, deps, preloaded) {
88962
89317
  );
88963
89318
  };
88964
89319
  const ran = await runPool(toRun, options.concurrency ?? 1, async (task) => {
89320
+ const expectedTests = isFeatureDelivery(task) ? await expectedTestsFor(deps, task, deps.pickTests).catch(
89321
+ () => []
89322
+ ) : [];
88965
89323
  const result = await calibrateTask(
88966
89324
  deps,
88967
89325
  options,
88968
89326
  { setupCmd, testCmd },
88969
- task
89327
+ expectedTests.length ? { ...task, expectedTests } : task
88970
89328
  );
88971
89329
  deps.log(verdictLine(task, result));
88972
89330
  if (!options.dryRun) {
@@ -89100,6 +89458,9 @@ var init_replay_calibrate = __esm({
89100
89458
  init_replay();
89101
89459
  init_replay_container();
89102
89460
  init_replay_focus();
89461
+ init_replay_guard();
89462
+ init_replay_diff();
89463
+ init_replay_spec();
89103
89464
  init_replay_scale();
89104
89465
  CHECK_COMMANDS_SKIP = "graded by the commands its CI job ran; pass --check-commands to run them";
89105
89466
  RUNTIMES = ["node", "python3", "go", "java", "ruby", "rustc"];
@@ -89116,7 +89477,7 @@ var init_replay_calibrate = __esm({
89116
89477
  checkout_failed: "error",
89117
89478
  timed_out: "error"
89118
89479
  };
89119
- CALIBRATION_VERSION = 1;
89480
+ CALIBRATION_VERSION = 2;
89120
89481
  isFeatureDelivery = (task) => task.kind === "full" || task.kind === "milestone";
89121
89482
  USAGE = `Usage: haansi replay calibrate --test-cmd "<cmd>" [--setup-cmd "<cmd>"] [--repo-commands] [--check-commands]
89122
89483
  [--runs 2] [--force] [--limit n] [--timeout-min 30]
@@ -89487,7 +89848,7 @@ async function commitOf(git, startSha, pr) {
89487
89848
  startSha
89488
89849
  ]);
89489
89850
  const [sha, title] = r.output.trim().split("");
89490
- if (r.code === 0 && sha && SHA2.test(sha))
89851
+ if (r.code === 0 && sha && SHA3.test(sha))
89491
89852
  return { sha, title: (title ?? "").trim() };
89492
89853
  }
89493
89854
  return null;
@@ -89566,7 +89927,7 @@ function recordLine(r) {
89566
89927
  return `- ${dayOf(timeOf(r.at))} \xB7 ${kindOf(r)}${r.event ? ` \xB7 ${r.event}` : ""} \xB7 ${title}${description}`;
89567
89928
  }
89568
89929
  async function legacyHistorySection(git, startSha, history, scope = "git") {
89569
- if (!SHA2.test(startSha)) return [];
89930
+ if (!SHA3.test(startSha)) return [];
89570
89931
  const entries = [
89571
89932
  ...history.attempts.filter((a) => Number.isSafeInteger(a.pr) && a.pr > 0).map((attempt) => ({
89572
89933
  at: timeOf(attempt.endedAt),
@@ -89730,7 +90091,7 @@ function eventLine(e) {
89730
90091
  async function historySection(git, startSha, history, scope = "git", sourcePr = null) {
89731
90092
  if (!history.timeline)
89732
90093
  return legacyHistorySection(git, startSha, history, scope);
89733
- if (!SHA2.test(startSha)) return [];
90094
+ if (!SHA3.test(startSha)) return [];
89734
90095
  const events = history.timeline.filter((e) => scope === "all" || isCode(e));
89735
90096
  const entries = [
89736
90097
  ...events.map((event, i) => ({
@@ -89809,7 +90170,7 @@ async function historySection(git, startSha, history, scope = "git", sourcePr =
89809
90170
  ...body
89810
90171
  ];
89811
90172
  }
89812
- var MAX_HISTORY_CHARS, MAX_PR_DIFF_CHARS, MAX_STAT_LINES, MAX_LINE_DESCRIPTION, SHA2, oneLine, PLATFORMS, KINDS, timeOf, dayOf, MAX_TIMELINE_CHARS, MAX_EVENT_FILES, minuteOf, typeOf, isCode;
90173
+ var MAX_HISTORY_CHARS, MAX_PR_DIFF_CHARS, MAX_STAT_LINES, MAX_LINE_DESCRIPTION, SHA3, oneLine, PLATFORMS, KINDS, timeOf, dayOf, MAX_TIMELINE_CHARS, MAX_EVENT_FILES, minuteOf, typeOf, isCode;
89813
90174
  var init_replay_history = __esm({
89814
90175
  "src/commands/replay-history.ts"() {
89815
90176
  "use strict";
@@ -89818,7 +90179,7 @@ var init_replay_history = __esm({
89818
90179
  MAX_PR_DIFF_CHARS = 6e3;
89819
90180
  MAX_STAT_LINES = 40;
89820
90181
  MAX_LINE_DESCRIPTION = 200;
89821
- SHA2 = /^[0-9a-f]{40}$/i;
90182
+ SHA3 = /^[0-9a-f]{40}$/i;
89822
90183
  oneLine = (text, max2) => {
89823
90184
  const t = text.replace(/[`#>*_]/g, "").replace(/\s+/g, " ").trim();
89824
90185
  return t.length > max2 ? `${t.slice(0, max2)}\u2026` : t;
@@ -89974,7 +90335,7 @@ function errorKeyOf(output) {
89974
90335
  function commitTimeOf(run3) {
89975
90336
  const seen = /* @__PURE__ */ new Map();
89976
90337
  return (sha) => {
89977
- if (!SHA3.test(sha)) return Promise.resolve(null);
90338
+ if (!SHA4.test(sha)) return Promise.resolve(null);
89978
90339
  let at = seen.get(sha);
89979
90340
  if (!at) {
89980
90341
  at = run3(["log", "-1", "--format=%cI", "--end-of-options", sha]).then((r) => {
@@ -90012,7 +90373,7 @@ async function recurringFailures(tasks, committedAt) {
90012
90373
  }
90013
90374
  return out;
90014
90375
  }
90015
- var fileOf, MAX_RECURRING, SHA3;
90376
+ var fileOf, MAX_RECURRING, SHA4;
90016
90377
  var init_replay_recurring = __esm({
90017
90378
  "src/commands/replay-recurring.ts"() {
90018
90379
  "use strict";
@@ -90021,279 +90382,7 @@ var init_replay_recurring = __esm({
90021
90382
  return i < 0 ? test : test.slice(0, i);
90022
90383
  };
90023
90384
  MAX_RECURRING = 20;
90024
- SHA3 = /^[0-9a-f]{40}$/i;
90025
- }
90026
- });
90027
-
90028
- // src/commands/replay-failure-paths.ts
90029
- function isAppFile(path2) {
90030
- return SOURCE.test(path2) && !TEST_FILE2.test(path2) && !isTestSupport(path2) && !/(^|\/)(node_modules|dist|build|coverage|\.next)\//.test(path2);
90031
- }
90032
- function stackFramesOf(output) {
90033
- const out = [];
90034
- const seen = /* @__PURE__ */ new Set();
90035
- for (const raw of output.split("\n")) {
90036
- const line = relativePaths(raw);
90037
- for (const m of line.matchAll(FRAME)) {
90038
- const path2 = m[1].replace(/^\.\//, "");
90039
- const n = Number(m[2]);
90040
- if (!n || path2.split("/").includes("..") || !isAppFile(path2)) continue;
90041
- const key = `${path2}:${n}`;
90042
- if (seen.has(key)) continue;
90043
- seen.add(key);
90044
- out.push({ path: path2, line: n });
90045
- if (out.length >= MAX_FRAMES) return out;
90046
- }
90047
- }
90048
- return out;
90049
- }
90050
- async function resolveFrames(show, baseSha, frames) {
90051
- const out = [];
90052
- for (const f of frames) {
90053
- const parts = f.path.replace(/^\/+/, "").split("/");
90054
- const tries = f.path.startsWith("/") ? parts.slice(1, ABSOLUTE_TRIES + 1).map((_, i) => parts.slice(i + 1).join("/")) : [f.path];
90055
- for (const p of tries) {
90056
- if (!p || !isAppFile(p)) continue;
90057
- if (await show(baseSha, p).catch(() => null) !== null) {
90058
- if (!out.some((o) => o.path === p && o.line === f.line))
90059
- out.push({ path: p, line: f.line });
90060
- break;
90061
- }
90062
- }
90063
- }
90064
- return out;
90065
- }
90066
- function boundedGit(git, max2 = MAX_GIT_CALLS) {
90067
- let calls = 0;
90068
- return async (args) => {
90069
- if (calls >= max2) return { code: 1, output: "" };
90070
- calls += 1;
90071
- try {
90072
- return await git(args);
90073
- } catch {
90074
- return { code: 1, output: "" };
90075
- }
90076
- };
90077
- }
90078
- async function filesOfCommit(git, sha) {
90079
- const out = await git(["show", "--name-only", "--format=", sha]);
90080
- if (out.code !== 0) return [];
90081
- return out.output.split("\n").map((l) => l.trim()).filter((l) => l && isAppFile(l)).slice(0, FILES_PER_COMMIT);
90082
- }
90083
- async function filesOfCommits(git, commits) {
90084
- const out = [];
90085
- for (const sha of commits.slice(0, MAX_COMMITS)) {
90086
- for (const f of await filesOfCommit(git, sha))
90087
- if (!out.includes(f)) out.push(f);
90088
- if (out.length >= MAX_WHERE_PATHS) break;
90089
- }
90090
- return out.slice(0, MAX_WHERE_PATHS);
90091
- }
90092
- async function blamedPaths(git, baseSha, frames) {
90093
- const commits = [];
90094
- for (const f of frames.slice(0, MAX_FRAMES)) {
90095
- const out = await git([
90096
- "blame",
90097
- "-L",
90098
- `${f.line},${f.line}`,
90099
- "--porcelain",
90100
- baseSha,
90101
- "--",
90102
- f.path
90103
- ]);
90104
- if (out.code !== 0) continue;
90105
- const sha = out.output.split(/\s/)[0] ?? "";
90106
- if (SHA4.test(sha) && !/^0+$/.test(sha) && !commits.includes(sha))
90107
- commits.push(sha);
90108
- }
90109
- const files = await filesOfCommits(git, commits);
90110
- return [.../* @__PURE__ */ new Set([...frames.map((f) => f.path), ...files])].slice(
90111
- 0,
90112
- MAX_WHERE_PATHS
90113
- );
90114
- }
90115
- async function historyPaths(git, baseSha, files) {
90116
- const commits = /* @__PURE__ */ new Map();
90117
- for (const file2 of files.slice(0, MAX_HISTORY_FILES)) {
90118
- const out = await git([
90119
- "log",
90120
- "-n",
90121
- String(COMMITS_PER_FILE),
90122
- "--format=%H %ct",
90123
- baseSha,
90124
- "--",
90125
- file2
90126
- ]);
90127
- if (out.code !== 0) continue;
90128
- for (const line of out.output.split("\n")) {
90129
- const [sha, at] = line.trim().split(/\s+/);
90130
- if (sha && SHA4.test(sha) && !commits.has(sha))
90131
- commits.set(sha, Number(at) || 0);
90132
- }
90133
- }
90134
- const newest = [...commits.entries()].sort((a, b) => b[1] - a[1]).map(([sha]) => sha);
90135
- return filesOfCommits(git, newest);
90136
- }
90137
- var MAX_FRAMES, COMMITS_PER_FILE, MAX_HISTORY_FILES, MAX_COMMITS, FILES_PER_COMMIT, MAX_WHERE_PATHS, MAX_GIT_CALLS, ABSOLUTE_TRIES, SOURCE, TEST_FILE2, SHA4, FRAME;
90138
- var init_replay_failure_paths = __esm({
90139
- "src/commands/replay-failure-paths.ts"() {
90140
- "use strict";
90141
- init_replay_errors();
90142
- init_replay_interface();
90143
- MAX_FRAMES = 10;
90144
- COMMITS_PER_FILE = 3;
90145
- MAX_HISTORY_FILES = 16;
90146
- MAX_COMMITS = 4;
90147
- FILES_PER_COMMIT = 4;
90148
- MAX_WHERE_PATHS = 6;
90149
- MAX_GIT_CALLS = 40;
90150
- ABSOLUTE_TRIES = 6;
90151
- SOURCE = /\.(?:[cm]?[jt]sx?|py|go)$/;
90152
- TEST_FILE2 = /(?:\.(?:test|spec)\.[cm]?[jt]sx?|_test\.go|(?:^|\/)test_[^/]*\.py|_test\.py)$/;
90153
- SHA4 = /^[0-9a-f]{40}$/;
90154
- FRAME = /(?:file:\/\/)?((?:\/|\.{0,2}\/)?(?:[\w.@+-]+\/)*[\w.@+-]+\.(?:[cm]?[jt]sx?|py|go)):(\d+)(?::\d+)?/g;
90155
- }
90156
- });
90157
-
90158
- // src/commands/replay-spec.ts
90159
- async function targetTestTitles(show, task) {
90160
- const out = [];
90161
- for (const file2 of task.testFiles) {
90162
- const lang = adapterFor(file2);
90163
- if (!lang) continue;
90164
- const source = await show(task.targetSha, file2);
90165
- if (source === null) continue;
90166
- for (const t of lang.testTitles(source, file2)) out.push(`${file2} \u203A ${t}`);
90167
- }
90168
- return out;
90169
- }
90170
- function cappedTitles(titles) {
90171
- const shown = [];
90172
- let chars = 0;
90173
- for (const t of titles) {
90174
- if (shown.length >= MAX_TITLES || chars + t.length > MAX_TITLE_CHARS) break;
90175
- shown.push(t);
90176
- chars += t.length;
90177
- }
90178
- return { shown, more: titles.length - shown.length };
90179
- }
90180
- function typeNamesIn(declaration) {
90181
- return [...new Set(declaration.match(/\b[A-Z][A-Za-z0-9_]*\b/g) ?? [])];
90182
- }
90183
- async function withSignatures(show, targetSha, entries) {
90184
- const out = [];
90185
- for (const e of entries) {
90186
- const source = e.names.length ? await show(targetSha, e.path) : null;
90187
- const lang = adapterFor(e.path);
90188
- const signatures = {};
90189
- for (const n of e.names) {
90190
- const sig = source === null ? null : lang?.signatureOf(source, n) ?? null;
90191
- if (sig) signatures[n] = sig;
90192
- }
90193
- const types2 = {};
90194
- if (source !== null && lang) {
90195
- const queue = Object.values(signatures).flatMap(typeNamesIn);
90196
- const seen = new Set(e.names);
90197
- while (queue.length && Object.keys(types2).length < MAX_TYPE_DECLARATIONS) {
90198
- const name = queue.shift();
90199
- if (seen.has(name)) continue;
90200
- seen.add(name);
90201
- const sig = lang.signatureOf(source, name);
90202
- if (!sig) continue;
90203
- types2[name] = sig;
90204
- queue.push(...typeNamesIn(sig));
90205
- }
90206
- }
90207
- out.push({
90208
- ...e,
90209
- ...Object.keys(signatures).length ? { signatures } : {},
90210
- ...Object.keys(types2).length ? { types: types2 } : {}
90211
- });
90212
- }
90213
- return out;
90214
- }
90215
- function fileOfTest(name) {
90216
- const file2 = name.split(" \u203A ")[0]?.trim() ?? "";
90217
- return /\.[cm]?[jt]sx?$|\.py$|_test\.go$/.test(file2) && !/\s/.test(file2) ? file2 : null;
90218
- }
90219
- function titleOfTest(name) {
90220
- const parts = name.split(" \u203A ");
90221
- return (fileOfTest(name) ? parts.slice(1) : parts).join(" \u203A ").trim();
90222
- }
90223
- async function hopOf(show, baseSha, from, skip) {
90224
- const out = [];
90225
- for (const file2 of from) {
90226
- if (out.length >= MAX_HOP_MODULES) break;
90227
- const lang = adapterFor(file2);
90228
- if (!lang) continue;
90229
- const source = await show(baseSha, file2).catch(() => null);
90230
- if (source === null) continue;
90231
- for (const candidates of lang.dependencies(source, file2)) {
90232
- if (out.length >= MAX_HOP_MODULES) break;
90233
- const at = await firstAt(show, baseSha, candidates).catch(() => null);
90234
- if (!at || skip.has(at.path) || adapterFor(at.path)?.isTestFile(at.path) || isTestSupport(at.path) || out.includes(at.path))
90235
- continue;
90236
- out.push(at.path);
90237
- }
90238
- }
90239
- return out;
90240
- }
90241
- async function failingPathsOf(show, task, git) {
90242
- const named = [
90243
- ...new Set(task.tests.map(fileOfTest).filter((f) => !!f))
90244
- ];
90245
- const files = [...new Set(named.length ? named : task.testFiles)];
90246
- const tests = /* @__PURE__ */ new Set([...files, ...task.testFiles]);
90247
- const direct = await hopOf(show, task.baseSha, files, tests);
90248
- const second = await hopOf(
90249
- show,
90250
- task.baseSha,
90251
- direct,
90252
- /* @__PURE__ */ new Set([...tests, ...direct])
90253
- );
90254
- let where = [];
90255
- if (git) {
90256
- const run3 = boundedGit(git);
90257
- const frames = await resolveFrames(
90258
- show,
90259
- task.baseSha,
90260
- stackFramesOf(task.output ?? "")
90261
- );
90262
- where = frames.length ? await blamedPaths(run3, task.baseSha, frames) : await historyPaths(run3, task.baseSha, [...files, ...direct, ...second]);
90263
- }
90264
- return [.../* @__PURE__ */ new Set([...files, ...where, ...direct, ...second])].slice(
90265
- 0,
90266
- MAX_FAILING_PATHS
90267
- );
90268
- }
90269
- function errorLineOf(output) {
90270
- for (const line of output.split("\n")) {
90271
- const m = /\b\w*(?:Error|Exception)\b:?\s*(.+)$/.exec(line) ?? /\b(expected .+)$/i.exec(line);
90272
- if (!m) continue;
90273
- const key = norm(m[1]).slice(0, 120);
90274
- if (key.length >= 12) return key;
90275
- }
90276
- return null;
90277
- }
90278
- function baseNameOf(path2) {
90279
- const parts = path2.split("/");
90280
- const file2 = parts.pop() ?? path2;
90281
- const name = /\.py$/.test(file2) ? file2.replace(/\.py$/, "").replace(/^test_(?=.)|(?<=.)_test$/, "") : file2.replace(/\.[cm]?[jt]sx?$/, "").replace(/\.(?:test|spec)$/, "");
90282
- return (name === "index" || name === "__init__") && parts.length ? parts[parts.length - 1] : name;
90283
- }
90284
- var MAX_TITLES, MAX_TITLE_CHARS, MAX_FAILING_PATHS, MAX_TYPE_DECLARATIONS, MAX_HOP_MODULES, norm;
90285
- var init_replay_spec = __esm({
90286
- "src/commands/replay-spec.ts"() {
90287
- "use strict";
90288
- init_replay_interface();
90289
- init_replay_failure_paths();
90290
- init_replay_lang();
90291
- MAX_TITLES = 40;
90292
- MAX_TITLE_CHARS = 4e3;
90293
- MAX_FAILING_PATHS = 12;
90294
- MAX_TYPE_DECLARATIONS = 40;
90295
- MAX_HOP_MODULES = 24;
90296
- norm = (s) => s.replace(/\s+/g, " ").trim();
90385
+ SHA4 = /^[0-9a-f]{40}$/i;
90297
90386
  }
90298
90387
  });
90299
90388
 
@@ -90778,6 +90867,91 @@ var init_replay_inject = __esm({
90778
90867
  }
90779
90868
  });
90780
90869
 
90870
+ // src/commands/replay-select.ts
90871
+ function parseSelection(text, candidates) {
90872
+ const match = /\{[\s\S]*\}/.exec(text);
90873
+ if (!match) return null;
90874
+ let v;
90875
+ try {
90876
+ v = JSON.parse(match[0]);
90877
+ } catch {
90878
+ return null;
90879
+ }
90880
+ if (!Array.isArray(v.tests)) return null;
90881
+ const picked = new Set(
90882
+ v.tests.filter((t) => typeof t === "string")
90883
+ );
90884
+ const out = candidates.map((c) => c.name).filter((name) => picked.has(name)).slice(0, MAX_SELECTED_TESTS);
90885
+ return out.length ? out : null;
90886
+ }
90887
+ function candidatesText(candidates) {
90888
+ return candidates.map((c) => `- ${c.name}${c.isNew ? " (new)" : ""}`).join("\n");
90889
+ }
90890
+ async function selectExpectedTests(deps, input) {
90891
+ const all = input.candidates.map((c) => c.name);
90892
+ if (all.length === 0) return { tests: [], picked: false };
90893
+ if (!input.prompt || !input.agentCmd) return { tests: all, picked: false };
90894
+ const dir = (0, import_node_path18.join)(
90895
+ deps.workDir(),
90896
+ `${input.taskId.replace(/[^a-zA-Z0-9-]/g, "")}-select`
90897
+ );
90898
+ const verdictFile = (0, import_node_path18.join)(dir, "verdict.json");
90899
+ const promptFile = (0, import_node_path18.join)(dir, "prompt.md");
90900
+ const configFile = (0, import_node_path18.join)(dir, "mcp.json");
90901
+ const render = (changeChars, testsChars) => [
90902
+ input.prompt.system,
90903
+ "",
90904
+ renderTemplate(input.prompt.user, {
90905
+ task: input.card,
90906
+ change: clip3(input.change || "(no code files)", changeChars),
90907
+ tests: clip3(candidatesText(input.candidates), testsChars),
90908
+ verdict_file: verdictFile
90909
+ })
90910
+ ].join("\n");
90911
+ const prompt2 = fitPrompt(render, MAX_CHANGE_CHARS3, MAX_TESTS_CHARS);
90912
+ try {
90913
+ deps.writeFile(promptFile, prompt2);
90914
+ deps.writeFile(configFile, JSON.stringify({ mcpServers: {} }));
90915
+ const ran = await deps.shell(
90916
+ input.agentCmd,
90917
+ dir,
90918
+ {
90919
+ HAANSI_REPLAY_PROMPT: prompt2,
90920
+ HAANSI_REPLAY_PROMPT_FILE: promptFile,
90921
+ HAANSI_REPLAY_MCP_CONFIG: configFile,
90922
+ HAANSI_REPLAY_VERDICT_FILE: verdictFile
90923
+ },
90924
+ input.timeoutMs
90925
+ );
90926
+ const tests = parseSelection(deps.readFile(verdictFile) ?? "", input.candidates) ?? parseSelection(ran.output, input.candidates);
90927
+ if (!tests) {
90928
+ deps.log(
90929
+ `\u2026 ${input.label}: the test selection gave no answer: graded on all ${all.length} candidate test(s)`
90930
+ );
90931
+ return { tests: all, picked: false };
90932
+ }
90933
+ deps.log(
90934
+ `\u2026 ${input.label}: graded on ${tests.length} of ${all.length} candidate test(s), picked for the change`
90935
+ );
90936
+ return { tests, picked: true };
90937
+ } finally {
90938
+ deps.removeDir(dir);
90939
+ }
90940
+ }
90941
+ var import_node_path18, MAX_SELECTED_TESTS, MAX_TESTS_CHARS, MAX_CHANGE_CHARS3, clip3;
90942
+ var init_replay_select = __esm({
90943
+ "src/commands/replay-select.ts"() {
90944
+ "use strict";
90945
+ import_node_path18 = require("node:path");
90946
+ init_replay_judge();
90947
+ MAX_SELECTED_TESTS = 60;
90948
+ MAX_TESTS_CHARS = 6e4;
90949
+ MAX_CHANGE_CHARS3 = 2e4;
90950
+ clip3 = (text, max2) => text.length > max2 ? `${text.slice(0, max2)}
90951
+ \u2026 (trimmed)` : text;
90952
+ }
90953
+ });
90954
+
90781
90955
  // src/commands/replay-tasks.ts
90782
90956
  var replay_tasks_exports = {};
90783
90957
  __export(replay_tasks_exports, {
@@ -90909,7 +91083,9 @@ function cardPrompt(task, feedback, arm = "baseline", tools = [], injection = nu
90909
91083
  ...failing?.tests.length ? [BUG_FIX_DONE, ""] : [],
90910
91084
  ...commands.length ? [CHECK_FIX_DONE, "", ...fenced3(commands.join("\n")), ""] : [],
90911
91085
  // A feature's own tests, by title: what a ticket's spec would say.
90912
- ...task.kind !== "recovery" ? titlesSection(task.testTitles ?? []) : [],
91086
+ ...task.kind !== "recovery" ? titlesSection(
91087
+ task.expectedTests?.length ? task.expectedTests : task.testTitles ?? []
91088
+ ) : [],
90913
91089
  task.card.acceptance,
90914
91090
  ...task.card.area ? ["", "## Part of the code", "", task.card.area] : [],
90915
91091
  "",
@@ -91096,7 +91272,7 @@ async function runStoredReplays(options, deps) {
91096
91272
  );
91097
91273
  }
91098
91274
  const usable = mine.filter((t) => {
91099
- if (!SHA.test(t.baseSha) || !SHA.test(t.targetSha)) return false;
91275
+ if (!SHA2.test(t.baseSha) || !SHA2.test(t.targetSha)) return false;
91100
91276
  if (checkCommandsOf(t).length) {
91101
91277
  if (!options.checkCommands)
91102
91278
  deps.log(`skip ${t.name ?? t.taskKey}: ${CHECK_COMMANDS_SKIP}`);
@@ -91206,7 +91382,20 @@ async function runStoredReplays(options, deps) {
91206
91382
  contextUnknown = gate.unknown;
91207
91383
  tiers = gate.tiers;
91208
91384
  }
91209
- const { states } = await runCalibration(
91385
+ const pickTests = async (t, candidates, change) => (
91386
+ // The set's own tasks are calibrated: each is one of `gated`.
91387
+ (await selectExpectedTests(deps, {
91388
+ label: t.name ?? t.taskKey,
91389
+ taskId: t.taskId,
91390
+ agentCmd: options.judgeCmd || options.agentCmd,
91391
+ timeoutMs: options.timeoutMs,
91392
+ card: cardPrompt(t, null),
91393
+ change,
91394
+ candidates,
91395
+ prompt: set2.testSelectPrompt ?? null
91396
+ })).tests
91397
+ );
91398
+ const { states, calibrations } = await runCalibration(
91210
91399
  calibrateTaskOptions(
91211
91400
  {
91212
91401
  ...options,
@@ -91214,9 +91403,12 @@ async function runStoredReplays(options, deps) {
91214
91403
  },
91215
91404
  { setupCmd, testCmd }
91216
91405
  ),
91217
- { ...deps, report: deps.reportCalibration },
91406
+ { ...deps, report: deps.reportCalibration, pickTests },
91218
91407
  { ...set2, tasks: gated }
91219
91408
  );
91409
+ const kept = new Map(calibrations.map((c) => [c.taskId, c.expectedTests]));
91410
+ for (const t of gated)
91411
+ if (kept.has(t.taskId)) t.expectedTests = kept.get(t.taskId) ?? null;
91220
91412
  const calibrated = gated.length;
91221
91413
  gated = gated.filter((t) => states.get(t.taskId) === "valid");
91222
91414
  const notValid = mine.length - usable.length + (calibrated - gated.length);
@@ -91274,6 +91466,7 @@ async function runStoredReplays(options, deps) {
91274
91466
  targetSha: task.targetSha,
91275
91467
  testFiles: task.testFiles,
91276
91468
  testNames: testNamesOf(task),
91469
+ ...expectedTestsOf(task).length ? { expectedTests: expectedTestsOf(task) } : {},
91277
91470
  ...options.checkCommands && checkCommandsOf(task).length ? { gradeCommands: checkCommandsOf(task) } : {}
91278
91471
  };
91279
91472
  const targetText = await targetOf(task);
@@ -91594,6 +91787,7 @@ var init_replay_tasks = __esm({
91594
91787
  init_replay_inject();
91595
91788
  init_replay_interface();
91596
91789
  init_replay_spec();
91790
+ init_replay_select();
91597
91791
  init_replay_context();
91598
91792
  FEEDBACK_HEADER = "Your previous attempt did not pass the tests. Their output ends with:";
91599
91793
  REPORT_CHUNK2 = 200;
@@ -91622,7 +91816,7 @@ var replay_exports = {};
91622
91816
  __export(replay_exports, {
91623
91817
  OUTPUT_HEAD_CHARS: () => OUTPUT_HEAD_CHARS,
91624
91818
  OUTPUT_TAIL_CHARS: () => OUTPUT_TAIL_CHARS,
91625
- SHA: () => SHA,
91819
+ SHA: () => SHA2,
91626
91820
  cleanClone: () => cleanClone,
91627
91821
  dropLinks: () => dropLinks,
91628
91822
  ensureCommit: () => ensureCommit,
@@ -91805,7 +91999,7 @@ function cleanCheckout(deps, dir, task) {
91805
91999
  }
91806
92000
  async function replayArm(deps, options, task, arm, promptOf, inspect, agentEnv = {}) {
91807
92001
  const started = deps.now();
91808
- const dir = (0, import_node_path18.join)(
92002
+ const dir = (0, import_node_path19.join)(
91809
92003
  deps.workDir(),
91810
92004
  `${task.processId.replace(/[^a-zA-Z0-9_-]/g, "")}-${arm}`
91811
92005
  );
@@ -91834,7 +92028,7 @@ async function replayArm(deps, options, task, arm, promptOf, inspect, agentEnv =
91834
92028
  `\u2026 ${label}: set up in ${since(at)}${setup.cached ? " (from the setup cache)" : ""}`
91835
92029
  );
91836
92030
  }
91837
- const promptFile = (0, import_node_path18.join)(dir, ".haansi-replay", "prompt.md");
92031
+ const promptFile = (0, import_node_path19.join)(dir, ".haansi-replay", "prompt.md");
91838
92032
  let mcpConfigFile = agentEnv.HAANSI_REPLAY_MCP_CONFIG;
91839
92033
  if (!mcpConfigFile) {
91840
92034
  mcpConfigFile = `${dir}.mcp.json`;
@@ -91939,24 +92133,27 @@ async function replayArm(deps, options, task, arm, promptOf, inspect, agentEnv =
91939
92133
  );
91940
92134
  const gradeSha = task.testNames?.length ? task.baseSha : task.targetSha;
91941
92135
  const own = new Map(
91942
- [...files, ...restored].map((f) => [f, deps.readFile((0, import_node_path18.join)(dir, f))])
92136
+ [...files, ...restored].map((f) => [f, deps.readFile((0, import_node_path19.join)(dir, f))])
91943
92137
  );
91944
92138
  for (const f of restored) {
91945
92139
  const content = await deps.showFile(task.baseSha, f);
91946
- if (content === null) deps.removeFile((0, import_node_path18.join)(dir, f));
91947
- else deps.writeFile((0, import_node_path18.join)(dir, f), content);
92140
+ if (content === null) deps.removeFile((0, import_node_path19.join)(dir, f));
92141
+ else deps.writeFile((0, import_node_path19.join)(dir, f), content);
91948
92142
  }
91949
92143
  for (const f of files) {
91950
92144
  const content = await deps.showFile(gradeSha, f);
91951
- if (content === null) deps.removeFile((0, import_node_path18.join)(dir, f));
91952
- else deps.writeFile((0, import_node_path18.join)(dir, f), content);
92145
+ if (content === null) deps.removeFile((0, import_node_path19.join)(dir, f));
92146
+ else deps.writeFile((0, import_node_path19.join)(dir, f), content);
91953
92147
  }
91954
92148
  const testAt = deps.now();
91955
92149
  deps.log(`\u2026 ${label}: agent done in ${since(agentAt)}, grading`);
91956
92150
  const test = await deps.shell(
91957
92151
  gradeOf(task, options),
91958
92152
  dir,
91959
- focusEnv(files, task.testNames ?? []),
92153
+ focusEnv(
92154
+ files,
92155
+ task.testNames?.length ? task.testNames : task.expectedTests ?? []
92156
+ ),
91960
92157
  options.timeoutMs
91961
92158
  );
91962
92159
  const counted = testCountsOf(test.output);
@@ -92000,8 +92197,8 @@ async function replayArm(deps, options, task, arm, promptOf, inspect, agentEnv =
92000
92197
  }
92001
92198
  if (test.code === 0 && !guarded) {
92002
92199
  for (const [file2, content] of own) {
92003
- if (content === null) deps.removeFile((0, import_node_path18.join)(dir, file2));
92004
- else deps.writeFile((0, import_node_path18.join)(dir, file2), content);
92200
+ if (content === null) deps.removeFile((0, import_node_path19.join)(dir, file2));
92201
+ else deps.writeFile((0, import_node_path19.join)(dir, file2), content);
92005
92202
  }
92006
92203
  if (inspect) await inspect(dir);
92007
92204
  return {
@@ -92017,8 +92214,8 @@ async function replayArm(deps, options, task, arm, promptOf, inspect, agentEnv =
92017
92214
  };
92018
92215
  }
92019
92216
  for (const [file2, content] of own) {
92020
- if (content === null) deps.removeFile((0, import_node_path18.join)(dir, file2));
92021
- else deps.writeFile((0, import_node_path18.join)(dir, file2), content);
92217
+ if (content === null) deps.removeFile((0, import_node_path19.join)(dir, file2));
92218
+ else deps.writeFile((0, import_node_path19.join)(dir, file2), content);
92022
92219
  }
92023
92220
  feedback = [
92024
92221
  guarded ? [
@@ -92113,11 +92310,11 @@ function runCommand(file2, args, cwd, env, timeoutMs, stdoutOnly = false) {
92113
92310
  });
92114
92311
  }
92115
92312
  function dropLinks(work, path2) {
92116
- const rel = (0, import_node_path18.relative)(work, path2);
92117
- if (rel === "" || rel.startsWith("..") || (0, import_node_path18.isAbsolute)(rel)) return;
92313
+ const rel = (0, import_node_path19.relative)(work, path2);
92314
+ if (rel === "" || rel.startsWith("..") || (0, import_node_path19.isAbsolute)(rel)) return;
92118
92315
  let at = work;
92119
- for (const part of rel.split(import_node_path18.sep)) {
92120
- at = (0, import_node_path18.join)(at, part);
92316
+ for (const part of rel.split(import_node_path19.sep)) {
92317
+ at = (0, import_node_path19.join)(at, part);
92121
92318
  let link = false;
92122
92319
  try {
92123
92320
  link = (0, import_node_fs14.lstatSync)(at).isSymbolicLink();
@@ -92152,7 +92349,7 @@ function localDeps(work) {
92152
92349
  // dropLinks: with a container, nothing runs in it while these do.
92153
92350
  writeFile: (path2, content) => {
92154
92351
  dropLinks(work, path2);
92155
- (0, import_node_fs14.mkdirSync)((0, import_node_path18.dirname)(path2), { recursive: true });
92352
+ (0, import_node_fs14.mkdirSync)((0, import_node_path19.dirname)(path2), { recursive: true });
92156
92353
  const fd2 = (0, import_node_fs14.openSync)(
92157
92354
  path2,
92158
92355
  import_node_fs14.constants.O_WRONLY | import_node_fs14.constants.O_CREAT | import_node_fs14.constants.O_TRUNC | import_node_fs14.constants.O_NOFOLLOW
@@ -92213,7 +92410,7 @@ async function replay(argv) {
92213
92410
  async function replayStored(options, token2, apiUrl2) {
92214
92411
  const { runStoredReplays: runStoredReplays2 } = await Promise.resolve().then(() => (init_replay_tasks(), replay_tasks_exports));
92215
92412
  const { cliVersion: cliVersion2 } = await Promise.resolve().then(() => (init_replay_calibrate(), replay_calibrate_exports));
92216
- const work = (0, import_node_fs14.mkdtempSync)((0, import_node_path18.join)((0, import_node_os11.tmpdir)(), "haansi-replay-"));
92413
+ const work = (0, import_node_fs14.mkdtempSync)((0, import_node_path19.join)((0, import_node_os11.tmpdir)(), "haansi-replay-"));
92217
92414
  let stop = null;
92218
92415
  try {
92219
92416
  const contained = await withContainer(
@@ -92307,7 +92504,7 @@ Baseline: ${arm("baseline")} passed \xB7 With Haansi: ${arm("haansi")} passed${h
92307
92504
  removeWorkDir(work);
92308
92505
  }
92309
92506
  }
92310
- var import_node_child_process5, import_node_fs14, import_node_os11, import_node_path18, usesHaansi, SHA, ARMS, DEFAULT_ARMS, FEEDBACK_CHARS, FAILURE_LINES2, REPLAY_BRANCH, OUTPUT_HEAD_CHARS, OUTPUT_TAIL_CHARS, USAGE2;
92507
+ var import_node_child_process5, import_node_fs14, import_node_os11, import_node_path19, usesHaansi, SHA2, ARMS, DEFAULT_ARMS, FEEDBACK_CHARS, FAILURE_LINES2, REPLAY_BRANCH, OUTPUT_HEAD_CHARS, OUTPUT_TAIL_CHARS, USAGE2;
92311
92508
  var init_replay = __esm({
92312
92509
  "src/commands/replay.ts"() {
92313
92510
  "use strict";
@@ -92315,7 +92512,7 @@ var init_replay = __esm({
92315
92512
  import_node_child_process5 = require("node:child_process");
92316
92513
  import_node_fs14 = require("node:fs");
92317
92514
  import_node_os11 = require("node:os");
92318
- import_node_path18 = require("node:path");
92515
+ import_node_path19 = require("node:path");
92319
92516
  init_paths();
92320
92517
  init_replay_errors();
92321
92518
  init_api2();
@@ -92327,7 +92524,7 @@ var init_replay = __esm({
92327
92524
  init_replay_preflight();
92328
92525
  init_replay_scale();
92329
92526
  usesHaansi = (arm) => arm !== "baseline";
92330
- SHA = /^[0-9a-f]{7,40}$/i;
92527
+ SHA2 = /^[0-9a-f]{7,40}$/i;
92331
92528
  ARMS = ["baseline", "haansi", "history"];
92332
92529
  DEFAULT_ARMS = ["baseline", "haansi"];
92333
92530
  FEEDBACK_CHARS = 6e3;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "haansi",
3
- "version": "0.1.133",
3
+ "version": "0.1.134",
4
4
  "description": "Haansi CLI - Session collector and MCP server for Claude Code & OpenAI Codex",
5
5
  "bin": {
6
6
  "haansi": "./dist/haansi.js"