haansi 0.1.135 → 0.1.137

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 +91 -36
  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.135",
98
+ version: "0.1.137",
99
99
  description: "Haansi CLI - Session collector and MCP server for Claude Code & OpenAI Codex",
100
100
  bin: {
101
101
  haansi: "./dist/haansi.js"
@@ -2417,6 +2417,14 @@ var init_scaling_metrics = __esm({
2417
2417
  treatMissingData: "breaching",
2418
2418
  missingDataRationale: "The reconciler is the only publisher and runs on a schedule independent of every worker. Its silence means the reconciler itself is broken, and the backlog it was watching is unobserved rather than empty. Scaling out against an unknown backlog wastes money; scaling in loses the queue. Breaching keeps capacity up until a human looks."
2419
2419
  }),
2420
+ MINING_PENDING_DECISIONS: spec({
2421
+ name: "haansi/mining/pending_decisions",
2422
+ unit: "Count",
2423
+ description: "Context decisions queued for the LLM (mining_pending_decisions, state 'pending'), platform-resident orgs.",
2424
+ dimensions: ["environment"],
2425
+ treatMissingData: "breaching",
2426
+ missingDataRationale: "Read only by the adaptive controller as a guard on scaling canonical ingestion: faster ingestion just grows this queue. Absent means the queue is unobserved, and the controller holds ingestion capacity rather than guessing in either direction."
2427
+ }),
2420
2428
  MINING_REPLAYS_IN_PROGRESS: spec({
2421
2429
  name: "haansi/mining/replays_in_progress",
2422
2430
  unit: "Count",
@@ -88810,27 +88818,14 @@ function baseNameOf(path2) {
88810
88818
  const name = /\.py$/.test(file2) ? file2.replace(/\.py$/, "").replace(/^test_(?=.)|(?<=.)_test$/, "") : file2.replace(/\.[cm]?[jt]sx?$/, "").replace(/\.(?:test|spec)$/, "");
88811
88819
  return (name === "index" || name === "__init__") && parts.length ? parts[parts.length - 1] : name;
88812
88820
  }
88821
+ function isUnitTestFile(path2) {
88822
+ const lang = adapterFor(path2);
88823
+ return !!lang && lang.isTestFile(path2) && !NOT_UNIT.test(path2);
88824
+ }
88813
88825
  async function candidateTests(show, task) {
88814
- const code = new Set(task.codeFiles);
88815
- const tests = new Set(task.testFiles);
88816
- const related = [];
88817
- const placed = [];
88818
- for (const file2 of task.testFiles) {
88819
- const direct = await hopOf(show, task.targetSha, [file2], tests);
88820
- const second = await hopOf(
88821
- show,
88822
- task.targetSha,
88823
- direct,
88824
- /* @__PURE__ */ new Set([...tests, ...direct])
88825
- );
88826
- if (direct.length) placed.push(file2);
88827
- if ([...direct, ...second].some((m) => code.has(m))) related.push(file2);
88828
- }
88829
- const files = related.length ? related : placed.length ? [] : [...task.testFiles];
88830
88826
  const out = [];
88831
- for (const file2 of files) {
88827
+ for (const file2 of task.testFiles.filter(isUnitTestFile)) {
88832
88828
  const lang = adapterFor(file2);
88833
- if (!lang) continue;
88834
88829
  const source = await show(task.targetSha, file2);
88835
88830
  if (source === null) continue;
88836
88831
  const before = await show(task.baseSha, file2);
@@ -88840,7 +88835,7 @@ async function candidateTests(show, task) {
88840
88835
  }
88841
88836
  return out;
88842
88837
  }
88843
- var MAX_TITLES, MAX_TITLE_CHARS, MAX_FAILING_PATHS, MAX_TYPE_DECLARATIONS, MAX_HOP_MODULES, norm;
88838
+ var MAX_TITLES, MAX_TITLE_CHARS, MAX_FAILING_PATHS, MAX_TYPE_DECLARATIONS, MAX_HOP_MODULES, norm, NOT_UNIT;
88844
88839
  var init_replay_spec = __esm({
88845
88840
  "src/commands/replay-spec.ts"() {
88846
88841
  "use strict";
@@ -88853,6 +88848,7 @@ var init_replay_spec = __esm({
88853
88848
  MAX_TYPE_DECLARATIONS = 40;
88854
88849
  MAX_HOP_MODULES = 24;
88855
88850
  norm = (s) => s.replace(/\s+/g, " ").trim();
88851
+ NOT_UNIT = /(^|\/)(tests\/integration|integration|e2e|playwright|cypress)\/|\.(integration|e2e)\.(test|spec)\.[a-z]+$|\.snap$|\.snapshot\.txt$/i;
88856
88852
  }
88857
88853
  });
88858
88854
 
@@ -89017,6 +89013,7 @@ function answerOf(text) {
89017
89013
  function parseSelection(text, candidates) {
89018
89014
  const v = answerOf(text);
89019
89015
  if (!v || !Array.isArray(v.tests)) return null;
89016
+ if (v.tests.length === 0) return [];
89020
89017
  const picked = new Set(
89021
89018
  v.tests.filter((t) => typeof t === "string").map(key)
89022
89019
  );
@@ -89074,8 +89071,9 @@ async function selectExpectedTests(deps, input) {
89074
89071
  );
89075
89072
  return { tests: all, picked: false };
89076
89073
  }
89074
+ const added = input.candidates.filter((c) => c.isNew).length;
89077
89075
  deps.log(
89078
- `\u2026 ${input.label}: graded on ${tests.length} of ${offered.length} candidate test(s), picked for the change`
89076
+ `\u2026 ${input.label}: graded on the ${added} test(s) the change added and ${tests.filter((t) => !input.candidates.find((c) => c.name === t)?.isNew).length} more picked, of ${offered.length} candidate test(s)`
89079
89077
  );
89080
89078
  return { tests, picked: true };
89081
89079
  } finally {
@@ -89192,8 +89190,7 @@ async function expectedTestsFor(deps, task, pick2) {
89192
89190
  const candidates = await candidateTests(deps.showFile, {
89193
89191
  baseSha: task.baseSha,
89194
89192
  targetSha: task.targetSha,
89195
- testFiles: task.testFiles,
89196
- codeFiles
89193
+ testFiles: task.testFiles
89197
89194
  });
89198
89195
  if (candidates.length === 0) return [];
89199
89196
  const stat = codeFiles.length ? await (deps.gitStdout ?? deps.git)(
@@ -89212,7 +89209,10 @@ async function expectedTestsFor(deps, task, pick2) {
89212
89209
  const change = stat.code === 0 ? stat.output.trim().split("\n").map((l) => l.split(" ")).filter((c) => c.length >= 3).map(
89213
89210
  ([a, r, path2]) => a === "-" ? `- ${path2} (binary)` : `- ${path2} (+${a} \u2212${r})`
89214
89211
  ).join("\n") : codeFiles.map((f) => `- ${f}`).join("\n");
89215
- const tests = pick2 ? await pick2(task, candidates, change) : candidates.map((c) => c.name);
89212
+ const picked = new Set(
89213
+ pick2 ? await pick2(task, candidates, change) : candidates.map((c) => c.name)
89214
+ );
89215
+ const tests = candidates.filter((c) => c.isNew || picked.has(c.name)).map((c) => c.name);
89216
89216
  return tests.length <= MAX_EXPECTED_TESTS ? tests : [];
89217
89217
  }
89218
89218
  function parseCalibrateArgs(argv) {
@@ -90493,6 +90493,9 @@ var init_replay_recurring = __esm({
90493
90493
  });
90494
90494
 
90495
90495
  // src/commands/replay-context.ts
90496
+ function meetsMinimum(score, min) {
90497
+ return score.onPoint >= (min?.onPoint ?? 0) && score.nearby >= (min?.nearby ?? 0);
90498
+ }
90496
90499
  function storedScoreOf(task) {
90497
90500
  return {
90498
90501
  onPoint: task.context?.onPoint ?? 0,
@@ -90741,11 +90744,17 @@ async function gateOnContext(deps, tasks, options) {
90741
90744
  let noContext = 0;
90742
90745
  let nearby = 0;
90743
90746
  let unknown2 = 0;
90747
+ let below = 0;
90744
90748
  for (const t of tasks) {
90745
90749
  const label = t.name ?? t.taskKey;
90746
90750
  const s = states.get(t.taskId);
90747
90751
  const tier = gateTierOf(s, recurringOf(t).length) ?? (s === "none" && options.history?.(t) ? "history" : null);
90748
- if (tier) {
90752
+ if (tier && !meetsMinimum(scoreOf(t), options.minimum)) {
90753
+ below += 1;
90754
+ deps.log(
90755
+ `skip ${label}: ${scoreOf(t).onPoint} on point and ${scoreOf(t).nearby} nearby in Haansi's search, under the run's minimum (${options.minimum?.onPoint ?? 0} on point, ${options.minimum?.nearby ?? 0} nearby)`
90756
+ );
90757
+ } else if (tier) {
90749
90758
  tiers.set(t.taskId, tier);
90750
90759
  if (tier === "missed")
90751
90760
  deps.log(
@@ -90780,6 +90789,7 @@ async function gateOnContext(deps, tasks, options) {
90780
90789
  return {
90781
90790
  replay: replay2,
90782
90791
  nearby,
90792
+ belowMinimum: below,
90783
90793
  missed: count4("missed"),
90784
90794
  recurring: count4("recurring"),
90785
90795
  history: count4("history"),
@@ -90788,10 +90798,10 @@ async function gateOnContext(deps, tasks, options) {
90788
90798
  tiers
90789
90799
  };
90790
90800
  }
90791
- function fromChecks(tasks, limit, shard, history) {
90801
+ function fromChecks(tasks, limit, shard, history, minimum) {
90792
90802
  const tierOf = (t) => gateTierOf(t.context?.state, t.context?.recurringIds?.length ?? 0) ?? (t.context?.state === "none" && history?.(t) ? "history" : null);
90793
90803
  const ready = tasks.filter(
90794
- (t) => !needsCheck(t) && tierOf(t) !== null && t.calibration?.state === "valid" && t.calibration.inputsFingerprint === t.inputsFingerprint
90804
+ (t) => !needsCheck(t) && tierOf(t) !== null && meetsMinimum(storedScoreOf(t), minimum) && t.calibration?.state === "valid" && t.calibration.inputsFingerprint === t.inputsFingerprint
90795
90805
  );
90796
90806
  const ranked = rankFound(ready, storedScoreOf, (t) => tierOf(t));
90797
90807
  const top = limit ? ranked.slice(0, limit) : ranked;
@@ -91261,6 +91271,10 @@ async function runStoredReplays(options, deps) {
91261
91271
  set2 = { ...set2, tasks: fresh };
91262
91272
  if (fresh.length === 0) return { results: [], notValid: 0, recorded: null };
91263
91273
  }
91274
+ const minimum = {
91275
+ onPoint: options.minOnPoint ?? 0,
91276
+ nearby: options.minNearby ?? 0
91277
+ };
91264
91278
  const historyTier = options.arms.includes("history") ? (t) => hasHistory(
91265
91279
  t,
91266
91280
  historyScope === "all" && set2.historyActivity === true ? "all" : "git"
@@ -91272,7 +91286,8 @@ async function runStoredReplays(options, deps) {
91272
91286
  set2.tasks,
91273
91287
  options.limit,
91274
91288
  options.shard ?? null,
91275
- historyTier
91289
+ historyTier,
91290
+ minimum
91276
91291
  );
91277
91292
  mine = picked.mine;
91278
91293
  tiers = picked.tiers;
@@ -91393,7 +91408,8 @@ async function runStoredReplays(options, deps) {
91393
91408
  targetOf,
91394
91409
  prepare: interfaceOf,
91395
91410
  prompt: promptForRelevance,
91396
- history: historyTier
91411
+ history: historyTier,
91412
+ minimum
91397
91413
  });
91398
91414
  gated = gate.replay;
91399
91415
  nearby = gate.nearby;
@@ -91523,7 +91539,14 @@ async function runStoredReplays(options, deps) {
91523
91539
  );
91524
91540
  return;
91525
91541
  }
91526
- for (const arm of arms) {
91542
+ const repeats = options.repeats ?? DEFAULT_REPEATS;
91543
+ const runs = Array.from(
91544
+ { length: repeats },
91545
+ (_, i) => arms.map((arm) => ({ arm, run: i + 1 }))
91546
+ ).flat();
91547
+ for (const { arm, run: run3 } of runs) {
91548
+ if (repeats > 1 && arm === arms[0])
91549
+ deps.log(`\u2026 ${label}: run ${run3}/${repeats}`);
91527
91550
  if (arm === "history" && history.length === 0) {
91528
91551
  deps.log(
91529
91552
  `skip history ${label}: nothing of its workstream before it began`
@@ -91702,7 +91725,9 @@ async function runStoredReplays(options, deps) {
91702
91725
  const sendTarget = !options.noDiffs && !targetSent && targetText !== null;
91703
91726
  const byFiles = isFeatureDelivery(task);
91704
91727
  const passed = r.passed && (!byFiles || (overlap.fileRecall ?? 0) >= FEATURE_MIN_FILE_RECALL);
91705
- if (r.passed && !passed)
91728
+ const tooSmall = r.passed && !passed;
91729
+ const tooSmallText = `Tests passed, but the change was too small: it covers ${pct(overlap.fileRecall)} of the target's files (a feature needs ${pct(FEATURE_MIN_FILE_RECALL)}).`;
91730
+ if (tooSmall)
91706
91731
  deps.log(
91707
91732
  `\u2026 ${label} [${arm}]: tests pass, but the change covers ${pct(overlap.fileRecall)} of the target's files (a feature needs ${pct(FEATURE_MIN_FILE_RECALL)})`
91708
91733
  );
@@ -91722,7 +91747,17 @@ async function runStoredReplays(options, deps) {
91722
91747
  haansi,
91723
91748
  sessionId: session?.sessionId ?? null,
91724
91749
  configFingerprint,
91725
- errors: options.noDiffs ? null : r.errors ?? [],
91750
+ errors: options.noDiffs ? null : [
91751
+ ...r.errors ?? [],
91752
+ ...tooSmall ? [
91753
+ {
91754
+ attempt: r.attempts,
91755
+ agentExit: 0,
91756
+ failing: [],
91757
+ output: tooSmallText
91758
+ }
91759
+ ] : []
91760
+ ],
91726
91761
  testCounts: r.testCounts ?? [],
91727
91762
  usage: r.usage ?? [],
91728
91763
  specGaps: task.specGaps ? task.specGaps.length : null
@@ -91835,6 +91870,8 @@ var init_replay_tasks = __esm({
91835
91870
  // src/commands/replay.ts
91836
91871
  var replay_exports = {};
91837
91872
  __export(replay_exports, {
91873
+ DEFAULT_REPEATS: () => DEFAULT_REPEATS,
91874
+ MAX_REPEATS: () => MAX_REPEATS,
91838
91875
  OUTPUT_HEAD_CHARS: () => OUTPUT_HEAD_CHARS,
91839
91876
  OUTPUT_TAIL_CHARS: () => OUTPUT_TAIL_CHARS,
91840
91877
  SHA: () => SHA2,
@@ -91881,7 +91918,8 @@ function parseReplayArgs(argv) {
91881
91918
  concurrency: 1,
91882
91919
  setupCache: null,
91883
91920
  force: false,
91884
- maxHours: null
91921
+ maxHours: null,
91922
+ repeats: DEFAULT_REPEATS
91885
91923
  };
91886
91924
  let sub;
91887
91925
  const errors = [];
@@ -91899,6 +91937,9 @@ function parseReplayArgs(argv) {
91899
91937
  else if (a === "--test-cmd") options.testCmd = next();
91900
91938
  else if (a === "--setup-cmd") options.setupCmd = next() || null;
91901
91939
  else if (a === "--attempts") options.attempts = Number(next());
91940
+ else if (a === "--repeats") options.repeats = Number(next());
91941
+ else if (a === "--min-on-point") options.minOnPoint = Number(next());
91942
+ else if (a === "--min-nearby") options.minNearby = Number(next());
91902
91943
  else if (a === "--limit") options.limit = Number(next());
91903
91944
  else if (a === "--timeout-min") options.timeoutMs = Number(next()) * 6e4;
91904
91945
  else if (a === "--agent-name") options.agentName = next();
@@ -91933,6 +91974,14 @@ function parseReplayArgs(argv) {
91933
91974
  );
91934
91975
  if (!Number.isInteger(options.attempts) || options.attempts < 1 || options.attempts > 20)
91935
91976
  errors.push("--attempts must be 1 to 20.");
91977
+ if (!Number.isInteger(options.repeats) || options.repeats < 1 || options.repeats > MAX_REPEATS)
91978
+ errors.push(`--repeats must be 1 to ${MAX_REPEATS}.`);
91979
+ for (const [flag, v] of [
91980
+ ["--min-on-point", options.minOnPoint],
91981
+ ["--min-nearby", options.minNearby]
91982
+ ])
91983
+ if (v !== void 0 && (!Number.isInteger(v) || v < 0))
91984
+ errors.push(`${flag} must be a whole number, 0 or more.`);
91936
91985
  if (options.limit !== null && (!Number.isInteger(options.limit) || options.limit < 1))
91937
91986
  errors.push("--limit must be a positive whole number.");
91938
91987
  if (!Number.isFinite(options.timeoutMs) || options.timeoutMs <= 0)
@@ -92525,7 +92574,7 @@ Baseline: ${arm("baseline")} passed \xB7 With Haansi: ${arm("haansi")} passed${h
92525
92574
  removeWorkDir(work);
92526
92575
  }
92527
92576
  }
92528
- 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;
92577
+ var import_node_child_process5, import_node_fs14, import_node_os11, import_node_path19, DEFAULT_REPEATS, MAX_REPEATS, usesHaansi, SHA2, ARMS, DEFAULT_ARMS, FEEDBACK_CHARS, FAILURE_LINES2, REPLAY_BRANCH, OUTPUT_HEAD_CHARS, OUTPUT_TAIL_CHARS, USAGE2;
92529
92578
  var init_replay = __esm({
92530
92579
  "src/commands/replay.ts"() {
92531
92580
  "use strict";
@@ -92544,6 +92593,8 @@ var init_replay = __esm({
92544
92593
  init_replay_usage();
92545
92594
  init_replay_preflight();
92546
92595
  init_replay_scale();
92596
+ DEFAULT_REPEATS = 2;
92597
+ MAX_REPEATS = 5;
92547
92598
  usesHaansi = (arm) => arm !== "baseline";
92548
92599
  SHA2 = /^[0-9a-f]{7,40}$/i;
92549
92600
  ARMS = ["baseline", "haansi", "history"];
@@ -92554,7 +92605,8 @@ var init_replay = __esm({
92554
92605
  OUTPUT_HEAD_CHARS = 4e4;
92555
92606
  OUTPUT_TAIL_CHARS = 2e5;
92556
92607
  USAGE2 = `Usage: haansi replay run --agent-cmd "<cmd>" --test-cmd "<cmd>"
92557
- [--setup-cmd "<cmd>"] [--attempts 2] [--arms baseline,haansi,history] [--history git|all] [--limit n]
92608
+ [--setup-cmd "<cmd>"] [--attempts 2] [--repeats 2] [--arms baseline,haansi,history] [--history git|all] [--limit n]
92609
+ [--min-on-point n] [--min-nearby n]
92558
92610
  [--timeout-min 20] [--agent-name <name>] [--model <name>]
92559
92611
  [--judge-cmd "<cmd>"]
92560
92612
  [--run-ref <url>] [--dry-run] [--repo-commands] [--check-commands] [--no-diffs]
@@ -92578,7 +92630,10 @@ test output on this machine and reports only how far they match.
92578
92630
  At scale: --shard i/n takes this job's share of the tasks (a CI matrix of n
92579
92631
  jobs); --concurrency k replays k tasks at once here; an arm already measured
92580
92632
  on the same card with the same agent and model is skipped (--force runs it
92581
- again); --new-only leaves out every task replayed before on all its arms with
92633
+ again); --repeats n runs each arm n times per task (default 2), interleaved
92634
+ (each arm once, then each again), each run its own result; --min-on-point
92635
+ and --min-nearby replay only tasks whose context check returned at least
92636
+ that many on-point and nearby items; --new-only leaves out every task replayed before on all its arms with
92582
92637
  the same agent and model, in any version, before --limit picks; --max-hours stops starting arms after h hours. --setup-cache
92583
92638
  package-lock.json --setup-cache-path '**/node_modules' keeps the setup's output
92584
92639
  (every workspace's node_modules) per lockfile (in ~/.cache/haansi-replay, or --setup-cache-dir) and restores
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "haansi",
3
- "version": "0.1.135",
3
+ "version": "0.1.137",
4
4
  "description": "Haansi CLI - Session collector and MCP server for Claude Code & OpenAI Codex",
5
5
  "bin": {
6
6
  "haansi": "./dist/haansi.js"