haansi 0.1.107 → 0.1.109

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 +181 -101
  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.107",
98
+ version: "0.1.109",
99
99
  description: "Haansi CLI - Session collector and MCP server for Claude Code & OpenAI Codex",
100
100
  bin: {
101
101
  haansi: "./dist/haansi.js"
@@ -78230,7 +78230,7 @@ var require_view = __commonJS({
78230
78230
  var dirname6 = path2.dirname;
78231
78231
  var basename4 = path2.basename;
78232
78232
  var extname = path2.extname;
78233
- var join22 = path2.join;
78233
+ var join23 = path2.join;
78234
78234
  var resolve5 = path2.resolve;
78235
78235
  module2.exports = View;
78236
78236
  function View(name, options) {
@@ -78292,12 +78292,12 @@ var require_view = __commonJS({
78292
78292
  };
78293
78293
  View.prototype.resolve = function resolve6(dir, file2) {
78294
78294
  var ext = this.ext;
78295
- var path3 = join22(dir, file2);
78295
+ var path3 = join23(dir, file2);
78296
78296
  var stat = tryStat(path3);
78297
78297
  if (stat && stat.isFile()) {
78298
78298
  return path3;
78299
78299
  }
78300
- path3 = join22(dir, basename4(file2, ext), "index" + ext);
78300
+ path3 = join23(dir, basename4(file2, ext), "index" + ext);
78301
78301
  stat = tryStat(path3);
78302
78302
  if (stat && stat.isFile()) {
78303
78303
  return path3;
@@ -81942,7 +81942,7 @@ var require_send = __commonJS({
81942
81942
  var Stream = require("stream");
81943
81943
  var util2 = require("util");
81944
81944
  var extname = path2.extname;
81945
- var join22 = path2.join;
81945
+ var join23 = path2.join;
81946
81946
  var normalize2 = path2.normalize;
81947
81947
  var resolve5 = path2.resolve;
81948
81948
  var sep3 = path2.sep;
@@ -82114,7 +82114,7 @@ var require_send = __commonJS({
82114
82114
  return res;
82115
82115
  }
82116
82116
  parts = path3.split(sep3);
82117
- path3 = normalize2(join22(root, path3));
82117
+ path3 = normalize2(join23(root, path3));
82118
82118
  } else {
82119
82119
  if (UP_PATH_REGEXP.test(path3)) {
82120
82120
  debug('malicious path "%s"', path3);
@@ -82247,7 +82247,7 @@ var require_send = __commonJS({
82247
82247
  if (err2) return self.onStatError(err2);
82248
82248
  return self.error(404);
82249
82249
  }
82250
- var p = join22(path3, self._index[i]);
82250
+ var p = join23(path3, self._index[i]);
82251
82251
  debug('stat "%s"', p);
82252
82252
  fs.stat(p, function(err3, stat) {
82253
82253
  if (err3) return next(err3);
@@ -86008,6 +86008,37 @@ var init_skills = __esm({
86008
86008
  }
86009
86009
  });
86010
86010
 
86011
+ // src/commands/replay-workdir.ts
86012
+ function makeWritable(dir) {
86013
+ const stat = (0, import_node_fs11.lstatSync)(dir);
86014
+ if (!stat.isDirectory()) return;
86015
+ (0, import_node_fs11.chmodSync)(dir, stat.mode | 448);
86016
+ for (const entry2 of (0, import_node_fs11.readdirSync)(dir)) makeWritable((0, import_node_path10.join)(dir, entry2));
86017
+ }
86018
+ function removeWorkDir(dir, log = (line) => console.error(line)) {
86019
+ try {
86020
+ (0, import_node_fs11.rmSync)(dir, { recursive: true, force: true });
86021
+ return;
86022
+ } catch {
86023
+ }
86024
+ try {
86025
+ makeWritable(dir);
86026
+ (0, import_node_fs11.rmSync)(dir, { recursive: true, force: true });
86027
+ } catch (err2) {
86028
+ log(
86029
+ `Could not remove the work directory ${dir}: ${err2 instanceof Error ? err2.message : String(err2)}`
86030
+ );
86031
+ }
86032
+ }
86033
+ var import_node_fs11, import_node_path10;
86034
+ var init_replay_workdir = __esm({
86035
+ "src/commands/replay-workdir.ts"() {
86036
+ "use strict";
86037
+ import_node_fs11 = require("node:fs");
86038
+ import_node_path10 = require("node:path");
86039
+ }
86040
+ });
86041
+
86011
86042
  // src/commands/replay-errors.ts
86012
86043
  function scrubSecrets(text) {
86013
86044
  let out = text;
@@ -86273,13 +86304,13 @@ function containerRefusal(env, options) {
86273
86304
  return 'This job can ask GitHub for an identity token ("permissions: id-token: write"), so the agent and the tests it edits could too. Run them in a container: add --container node:22 (and --container-setup to install your agent).';
86274
86305
  }
86275
86306
  function inside(work, cwd) {
86276
- const rel = (0, import_node_path10.relative)(work, cwd);
86277
- return rel === "" || !rel.startsWith("..") && !(0, import_node_path10.isAbsolute)(rel) ? cwd : work;
86307
+ const rel = (0, import_node_path11.relative)(work, cwd);
86308
+ return rel === "" || !rel.startsWith("..") && !(0, import_node_path11.isAbsolute)(rel) ? cwd : work;
86278
86309
  }
86279
86310
  async function startContainer(work, options, run3, log, user = currentUser()) {
86280
86311
  const name = `haansi-replay-${(0, import_node_crypto3.randomBytes)(6).toString("hex")}`;
86281
- const home = (0, import_node_path10.join)(work, ".home");
86282
- (0, import_node_fs11.mkdirSync)(home, { recursive: true });
86312
+ const home = (0, import_node_path11.join)(work, ".home");
86313
+ (0, import_node_fs12.mkdirSync)(home, { recursive: true });
86283
86314
  log(`\u2026 starting container ${options.image}`);
86284
86315
  const started = await run3(
86285
86316
  "docker",
@@ -86446,13 +86477,13 @@ async function withContainer(deps, work, options, run3) {
86446
86477
  function hostGit(work, repoDir, args, cwd) {
86447
86478
  return inside(work, cwd) !== cwd || args.includes(repoDir);
86448
86479
  }
86449
- var import_node_crypto3, import_node_fs11, import_node_path10, NO_CONTAINER, ENV_NAME, IMAGE, SETUP_TIMEOUT_MS, KILL_SLACK_MS, PIDS_LIMIT, SETTLE_SCRIPT, GIT_TIMEOUT_MS;
86480
+ var import_node_crypto3, import_node_fs12, import_node_path11, NO_CONTAINER, ENV_NAME, IMAGE, SETUP_TIMEOUT_MS, KILL_SLACK_MS, PIDS_LIMIT, SETTLE_SCRIPT, GIT_TIMEOUT_MS;
86450
86481
  var init_replay_container = __esm({
86451
86482
  "src/commands/replay-container.ts"() {
86452
86483
  "use strict";
86453
86484
  import_node_crypto3 = require("node:crypto");
86454
- import_node_fs11 = require("node:fs");
86455
- import_node_path10 = require("node:path");
86485
+ import_node_fs12 = require("node:fs");
86486
+ import_node_path11 = require("node:path");
86456
86487
  NO_CONTAINER = {
86457
86488
  image: null,
86458
86489
  setupCmd: null,
@@ -86999,6 +87030,34 @@ function agentFailureLines(output, max2, scrub) {
86999
87030
  return clean.length > MAX_LOGGED_LINE_CHARS ? `${clean.slice(0, MAX_LOGGED_LINE_CHARS - 1)}\u2026` : clean;
87000
87031
  });
87001
87032
  }
87033
+ function toolUsesOf(output) {
87034
+ const counts = /* @__PURE__ */ new Map();
87035
+ let structured = false;
87036
+ for (const line of output.split("\n")) {
87037
+ const trimmed = line.trim();
87038
+ if (!trimmed.startsWith("{")) continue;
87039
+ let event;
87040
+ try {
87041
+ event = JSON.parse(trimmed);
87042
+ } catch {
87043
+ continue;
87044
+ }
87045
+ if (event.type !== "assistant") continue;
87046
+ structured = true;
87047
+ const content = Array.isArray(event.message?.content) ? event.message.content : [];
87048
+ for (const block of content) {
87049
+ if (block?.type === "tool_use" && typeof block.name === "string")
87050
+ counts.set(block.name, (counts.get(block.name) ?? 0) + 1);
87051
+ }
87052
+ }
87053
+ if (!structured) return null;
87054
+ return [...counts.entries()].sort(
87055
+ (a, b) => b[1] - a[1] || a[0].localeCompare(b[0])
87056
+ );
87057
+ }
87058
+ function toolUsesLine(uses) {
87059
+ return uses.length ? uses.map(([name, n]) => `${name}\xD7${n}`).join(", ") : "none";
87060
+ }
87002
87061
  var NONE, count2, MODEL_REFUSAL, MAX_REASON_CHARS, MAX_LOGGED_LINE_CHARS;
87003
87062
  var init_replay_usage = __esm({
87004
87063
  "src/commands/replay-usage.ts"() {
@@ -87092,20 +87151,20 @@ async function setUpClone(deps, dir, setupCmd, timeoutMs, cache, platform2 = pro
87092
87151
  `${setupCmd}\0${cache.paths.join(",")}`,
87093
87152
  cache.keyFiles.filter(safeCachePath).map((path2) => ({
87094
87153
  path: path2,
87095
- content: deps.readFile((0, import_node_path11.join)(dir, path2))
87154
+ content: deps.readFile((0, import_node_path12.join)(dir, path2))
87096
87155
  }))
87097
87156
  ) : null;
87098
- const kept = key && cache ? (0, import_node_path11.join)(cache.dir, key) : null;
87157
+ const kept = key && cache ? (0, import_node_path12.join)(cache.dir, key) : null;
87099
87158
  const q = shellPath;
87100
87159
  const run3 = (command2) => deps.shell(command2, dir, {}, timeoutMs);
87101
87160
  if (kept && cache) {
87102
- const manifest = deps.readFile((0, import_node_path11.join)(kept, MANIFEST));
87161
+ const manifest = deps.readFile((0, import_node_path12.join)(kept, MANIFEST));
87103
87162
  const paths = manifest === null ? null : foundPaths(manifest);
87104
- if (paths && (await run3(`test -f ${q((0, import_node_path11.join)(kept, ".complete"))}`)).code === 0) {
87163
+ if (paths && (await run3(`test -f ${q((0, import_node_path12.join)(kept, ".complete"))}`)).code === 0) {
87105
87164
  let restored = true;
87106
87165
  for (const p of paths) {
87107
87166
  const copied = await run3(
87108
- `rm -rf ${q((0, import_node_path11.join)(dir, p))} && mkdir -p ${q((0, import_node_path11.join)(dir, p, ".."))} && ${copyCommand(platform2, (0, import_node_path11.join)(kept, p), (0, import_node_path11.join)(dir, p), true)}`
87167
+ `rm -rf ${q((0, import_node_path12.join)(dir, p))} && mkdir -p ${q((0, import_node_path12.join)(dir, p, ".."))} && ${copyCommand(platform2, (0, import_node_path12.join)(kept, p), (0, import_node_path12.join)(dir, p), true)}`
87109
87168
  );
87110
87169
  if (copied.code !== 0) {
87111
87170
  restored = false;
@@ -87131,10 +87190,10 @@ async function setUpClone(deps, dir, setupCmd, timeoutMs, cache, platform2 = pro
87131
87190
  let ok = (await run3(`mkdir -p ${q(tmp)}`)).code === 0;
87132
87191
  for (const p of [...new Set(paths)].sort()) {
87133
87192
  if (!ok) break;
87134
- ok = (await run3(`mkdir -p ${q((0, import_node_path11.join)(tmp, p, ".."))}`)).code === 0 && (await run3(copyCommand(platform2, (0, import_node_path11.join)(dir, p), (0, import_node_path11.join)(tmp, p), false))).code === 0;
87193
+ ok = (await run3(`mkdir -p ${q((0, import_node_path12.join)(tmp, p, ".."))}`)).code === 0 && (await run3(copyCommand(platform2, (0, import_node_path12.join)(dir, p), (0, import_node_path12.join)(tmp, p), false))).code === 0;
87135
87194
  }
87136
87195
  await run3(
87137
- ok ? `printf '%s\\n' ${[...new Set(paths)].sort().map(q).join(" ")} > ${q((0, import_node_path11.join)(tmp, MANIFEST))} && touch ${q((0, import_node_path11.join)(tmp, ".complete"))} && rm -rf ${q(kept)} && mv ${q(tmp)} ${q(kept)}` : `rm -rf ${q(tmp)}`
87196
+ ok ? `printf '%s\\n' ${[...new Set(paths)].sort().map(q).join(" ")} > ${q((0, import_node_path12.join)(tmp, MANIFEST))} && touch ${q((0, import_node_path12.join)(tmp, ".complete"))} && rm -rf ${q(kept)} && mv ${q(tmp)} ${q(kept)}` : `rm -rf ${q(tmp)}`
87138
87197
  );
87139
87198
  }
87140
87199
  return { ...setup, cached: false };
@@ -87145,7 +87204,7 @@ function newScaleArgs(home) {
87145
87204
  concurrency: 1,
87146
87205
  cacheFiles: [],
87147
87206
  cachePaths: [],
87148
- cacheDir: (0, import_node_path11.join)(home, ".cache", "haansi-replay")
87207
+ cacheDir: (0, import_node_path12.join)(home, ".cache", "haansi-replay")
87149
87208
  };
87150
87209
  }
87151
87210
  function takeScaleArg(a, next, state, errors) {
@@ -87189,12 +87248,12 @@ function finishScaleArgs(state, containerImage, errors) {
87189
87248
  }
87190
87249
  return { shard: state.shard, concurrency: state.concurrency, setupCache };
87191
87250
  }
87192
- var import_node_crypto4, import_node_path11, shellPath, MANIFEST, commaList;
87251
+ var import_node_crypto4, import_node_path12, shellPath, MANIFEST, commaList;
87193
87252
  var init_replay_scale = __esm({
87194
87253
  "src/commands/replay-scale.ts"() {
87195
87254
  "use strict";
87196
87255
  import_node_crypto4 = require("node:crypto");
87197
- import_node_path11 = require("node:path");
87256
+ import_node_path12 = require("node:path");
87198
87257
  shellPath = (s) => `'${s.replace(/'/g, `'\\''`)}'`;
87199
87258
  MANIFEST = ".paths";
87200
87259
  commaList = (v) => v.split(",").map((s) => s.trim()).filter(Boolean);
@@ -87404,7 +87463,7 @@ async function calibrateTask(deps, options, commands, task) {
87404
87463
  });
87405
87464
  const sides = isFeatureDelivery(task) ? ["target"] : ["base", "target"];
87406
87465
  for (const side of sides) {
87407
- const dir = (0, import_node_path12.join)(
87466
+ const dir = (0, import_node_path13.join)(
87408
87467
  deps.workDir(),
87409
87468
  `${task.taskId.replace(/[^a-zA-Z0-9-]/g, "")}-${side}`
87410
87469
  );
@@ -87447,8 +87506,8 @@ async function calibrateTask(deps, options, commands, task) {
87447
87506
  if (side === "base" && testNamesOf(task).length === 0) {
87448
87507
  for (const f of task.testFiles) {
87449
87508
  const content = await deps.showFile(task.targetSha, f);
87450
- if (content === null) deps.removeFile((0, import_node_path12.join)(dir, f));
87451
- else deps.writeFile((0, import_node_path12.join)(dir, f), content);
87509
+ if (content === null) deps.removeFile((0, import_node_path13.join)(dir, f));
87510
+ else deps.writeFile((0, import_node_path13.join)(dir, f), content);
87452
87511
  }
87453
87512
  }
87454
87513
  for (let i = 0; i < options.runs; i++) {
@@ -87648,7 +87707,7 @@ async function calibrate(argv) {
87648
87707
  process.exitCode = 1;
87649
87708
  return;
87650
87709
  }
87651
- const work = (0, import_node_fs12.mkdtempSync)((0, import_node_path12.join)((0, import_node_os10.tmpdir)(), "haansi-calibrate-"));
87710
+ const work = (0, import_node_fs13.mkdtempSync)((0, import_node_path13.join)((0, import_node_os10.tmpdir)(), "haansi-calibrate-"));
87652
87711
  let stop = null;
87653
87712
  try {
87654
87713
  const contained = await withContainer(
@@ -87690,7 +87749,7 @@ Valid: ${count4("valid")} \xB7 Invalid: ${count4("invalid")} \xB7 Flaky: ${count
87690
87749
  process.exitCode = 1;
87691
87750
  } finally {
87692
87751
  await stop?.();
87693
- (0, import_node_fs12.rmSync)(work, { recursive: true, force: true });
87752
+ removeWorkDir(work);
87694
87753
  }
87695
87754
  }
87696
87755
  function cliVersion() {
@@ -87700,14 +87759,15 @@ function cliVersion() {
87700
87759
  return null;
87701
87760
  }
87702
87761
  }
87703
- var import_node_crypto5, import_node_fs12, import_node_os10, import_node_path12, RUNTIMES, REPORT_CHUNK, FAILURE_LINES, STATE, CALIBRATION_VERSION, isFeatureDelivery, USAGE;
87762
+ var import_node_crypto5, import_node_fs13, import_node_os10, import_node_path13, RUNTIMES, REPORT_CHUNK, FAILURE_LINES, STATE, CALIBRATION_VERSION, isFeatureDelivery, USAGE;
87704
87763
  var init_replay_calibrate = __esm({
87705
87764
  "src/commands/replay-calibrate.ts"() {
87706
87765
  "use strict";
87766
+ init_replay_workdir();
87707
87767
  import_node_crypto5 = require("node:crypto");
87708
- import_node_fs12 = require("node:fs");
87768
+ import_node_fs13 = require("node:fs");
87709
87769
  import_node_os10 = require("node:os");
87710
- import_node_path12 = require("node:path");
87770
+ import_node_path13 = require("node:path");
87711
87771
  init_paths();
87712
87772
  init_api2();
87713
87773
  init_replay_errors();
@@ -87875,6 +87935,19 @@ var init_replay_diff = __esm({
87875
87935
  });
87876
87936
 
87877
87937
  // src/commands/replay-judge.ts
87938
+ function fitPrompt(render, changeChars, itemsChars, maxBytes = MAX_PROMPT_BYTES) {
87939
+ const FLOOR = 4e3;
87940
+ let change = changeChars;
87941
+ let items = itemsChars;
87942
+ let prompt2 = render(change, items);
87943
+ while (Buffer.byteLength(prompt2, "utf8") > maxBytes) {
87944
+ if (items > FLOOR) items = Math.max(FLOOR, Math.floor(items * 0.8));
87945
+ else if (change > FLOOR) change = Math.max(FLOOR, Math.floor(change * 0.8));
87946
+ else break;
87947
+ prompt2 = render(change, items);
87948
+ }
87949
+ return prompt2;
87950
+ }
87878
87951
  function renderTemplate(template, vars) {
87879
87952
  return template.replace(
87880
87953
  /\{\{(\w+)\}\}/g,
@@ -87934,21 +88007,25 @@ async function judgeUse(deps, input) {
87934
88007
  judgeTag: null
87935
88008
  };
87936
88009
  const tag = input.prompt.edited ? `${input.prompt.tag}+edited` : input.prompt.tag;
87937
- const dir = (0, import_node_path13.join)(deps.workDir(), `${input.taskId}-judge`);
87938
- const verdictFile = (0, import_node_path13.join)(dir, "verdict.json");
87939
- const promptFile = (0, import_node_path13.join)(dir, "prompt.md");
87940
- const configFile = (0, import_node_path13.join)(dir, "mcp.json");
88010
+ const dir = (0, import_node_path14.join)(deps.workDir(), `${input.taskId}-judge`);
88011
+ const verdictFile = (0, import_node_path14.join)(dir, "verdict.json");
88012
+ const promptFile = (0, import_node_path14.join)(dir, "prompt.md");
88013
+ const configFile = (0, import_node_path14.join)(dir, "mcp.json");
87941
88014
  const returned = input.calls.map((c) => c.returnedText ?? "").filter(Boolean).join("\n\n");
87942
- const prompt2 = [
87943
- input.prompt.system,
87944
- "",
87945
- renderTemplate(input.prompt.user, {
87946
- task: input.card,
87947
- returned: clip(returned || "(only ids came back)", MAX_RETURNED_CHARS),
87948
- change: input.change || "(no change)",
87949
- verdict_file: verdictFile
87950
- })
87951
- ].join("\n");
88015
+ const prompt2 = fitPrompt(
88016
+ (changeChars, returnedChars) => [
88017
+ input.prompt.system,
88018
+ "",
88019
+ renderTemplate(input.prompt.user, {
88020
+ task: input.card,
88021
+ returned: clip(returned || "(only ids came back)", returnedChars),
88022
+ change: clip(input.change || "(no change)", changeChars),
88023
+ verdict_file: verdictFile
88024
+ })
88025
+ ].join("\n"),
88026
+ MAX_CHANGE_CHARS,
88027
+ MAX_RETURNED_CHARS
88028
+ );
87952
88029
  try {
87953
88030
  deps.writeFile(promptFile, prompt2);
87954
88031
  deps.writeFile(configFile, JSON.stringify({ mcpServers: {} }));
@@ -87979,14 +88056,15 @@ async function judgeUse(deps, input) {
87979
88056
  deps.removeDir(dir);
87980
88057
  }
87981
88058
  }
87982
- var import_node_path13, MAX_CHANGE_CHARS, MAX_RETURNED_CHARS, MAX_REASON, VERDICTS, clip;
88059
+ var import_node_path14, MAX_CHANGE_CHARS, MAX_RETURNED_CHARS, MAX_PROMPT_BYTES, MAX_REASON, VERDICTS, clip;
87983
88060
  var init_replay_judge = __esm({
87984
88061
  "src/commands/replay-judge.ts"() {
87985
88062
  "use strict";
87986
- import_node_path13 = require("node:path");
88063
+ import_node_path14 = require("node:path");
87987
88064
  init_replay_diff();
87988
88065
  MAX_CHANGE_CHARS = 6e4;
87989
88066
  MAX_RETURNED_CHARS = 6e4;
88067
+ MAX_PROMPT_BYTES = 12e4;
87990
88068
  MAX_REASON = 300;
87991
88069
  VERDICTS = ["used", "partly", "not_used"];
87992
88070
  clip = (text, max2) => text.length > max2 ? `${text.slice(0, max2)}
@@ -88082,23 +88160,21 @@ async function judgeRelevance(deps, input) {
88082
88160
  judgeTag: null
88083
88161
  };
88084
88162
  const tag = input.prompt.edited ? `${input.prompt.tag}+edited` : input.prompt.tag;
88085
- const dir = (0, import_node_path14.join)(deps.workDir(), `${input.taskId}-relevance`);
88086
- const verdictFile = (0, import_node_path14.join)(dir, "verdict.json");
88087
- const promptFile = (0, import_node_path14.join)(dir, "prompt.md");
88088
- const configFile = (0, import_node_path14.join)(dir, "mcp.json");
88089
- const prompt2 = [
88163
+ const dir = (0, import_node_path15.join)(deps.workDir(), `${input.taskId}-relevance`);
88164
+ const verdictFile = (0, import_node_path15.join)(dir, "verdict.json");
88165
+ const promptFile = (0, import_node_path15.join)(dir, "prompt.md");
88166
+ const configFile = (0, import_node_path15.join)(dir, "mcp.json");
88167
+ const render = (changeChars, itemsChars) => [
88090
88168
  input.prompt.system,
88091
88169
  "",
88092
88170
  renderTemplate(input.prompt.user, {
88093
88171
  task: input.card,
88094
- target_change: clip2(
88095
- input.targetChange || "(no change)",
88096
- MAX_CHANGE_CHARS2
88097
- ),
88098
- items: clip2(itemsText(all) || "(only ids came back)", MAX_ITEMS_CHARS),
88172
+ target_change: clip2(input.targetChange || "(no change)", changeChars),
88173
+ items: clip2(itemsText(all) || "(only ids came back)", itemsChars),
88099
88174
  verdict_file: verdictFile
88100
88175
  })
88101
88176
  ].join("\n");
88177
+ const prompt2 = fitPrompt(render, MAX_CHANGE_CHARS2, MAX_ITEMS_CHARS);
88102
88178
  try {
88103
88179
  deps.writeFile(promptFile, prompt2);
88104
88180
  deps.writeFile(configFile, JSON.stringify({ mcpServers: {} }));
@@ -88138,11 +88214,12 @@ async function judgeRelevance(deps, input) {
88138
88214
  deps.removeDir(dir);
88139
88215
  }
88140
88216
  }
88141
- var import_node_path14, MAX_CHANGE_CHARS2, MAX_ITEMS_CHARS, QUERY_CHARS, TERMS, clip2, COMMON, said;
88217
+ var import_node_path15, MAX_CHANGE_CHARS2, MAX_ITEMS_CHARS, QUERY_CHARS, TERMS, clip2, COMMON, said;
88142
88218
  var init_replay_relevance = __esm({
88143
88219
  "src/commands/replay-relevance.ts"() {
88144
88220
  "use strict";
88145
- import_node_path14 = require("node:path");
88221
+ import_node_path15 = require("node:path");
88222
+ init_replay_judge();
88146
88223
  init_replay_judge();
88147
88224
  MAX_CHANGE_CHARS2 = 6e4;
88148
88225
  MAX_ITEMS_CHARS = 8e4;
@@ -88242,7 +88319,7 @@ function hasDefaultExport(source) {
88242
88319
  /\bmodule\.exports\s*=/.test(text);
88243
88320
  }
88244
88321
  function candidatesFor(fromFile, spec2) {
88245
- const base = (0, import_node_path15.normalize)((0, import_node_path15.join)((0, import_node_path15.dirname)(fromFile), spec2)).replace(/\\/g, "/");
88322
+ const base = (0, import_node_path16.normalize)((0, import_node_path16.join)((0, import_node_path16.dirname)(fromFile), spec2)).replace(/\\/g, "/");
88246
88323
  if (base.startsWith("..")) return [];
88247
88324
  const stem2 = base.replace(/\.(?:[cm]?js|jsx)$/, "");
88248
88325
  const withExt = /\.[cm]?[jt]sx?$/.test(base) ? [base] : [];
@@ -88482,11 +88559,11 @@ function packageSpecsOf(source) {
88482
88559
  if (!out.includes(m[1])) out.push(m[1]);
88483
88560
  return out;
88484
88561
  }
88485
- var import_node_path15, MAX_SIGNATURE_LINES, MAX_SIGNATURE_CHARS, JS_SOURCE, JS_TEST_FILE, EXTENSIONS, IDENT, stripComments, CALL, jsAdapter;
88562
+ var import_node_path16, MAX_SIGNATURE_LINES, MAX_SIGNATURE_CHARS, JS_SOURCE, JS_TEST_FILE, EXTENSIONS, IDENT, stripComments, CALL, jsAdapter;
88486
88563
  var init_replay_lang_js = __esm({
88487
88564
  "src/commands/replay-lang-js.ts"() {
88488
88565
  "use strict";
88489
- import_node_path15 = require("node:path");
88566
+ import_node_path16 = require("node:path");
88490
88567
  MAX_SIGNATURE_LINES = 15;
88491
88568
  MAX_SIGNATURE_CHARS = 600;
88492
88569
  JS_SOURCE = /\.[cm]?[jt]sx?$/;
@@ -88610,14 +88687,14 @@ function pythonModuleCandidates(fromPath, spec2) {
88610
88687
  const parts = rest ? rest.split(".") : [];
88611
88688
  if (!parts.every((p) => IDENT2.test(p))) return [];
88612
88689
  const at = (dir2) => {
88613
- const base = import_node_path16.posix.join(dir2, ...parts);
88614
- return parts.length ? [`${base}.py`, import_node_path16.posix.join(base, "__init__.py")] : [import_node_path16.posix.join(base, "__init__.py")];
88690
+ const base = import_node_path17.posix.join(dir2, ...parts);
88691
+ return parts.length ? [`${base}.py`, import_node_path17.posix.join(base, "__init__.py")] : [import_node_path17.posix.join(base, "__init__.py")];
88615
88692
  };
88616
- let dir = import_node_path16.posix.dirname(fromPath);
88693
+ let dir = import_node_path17.posix.dirname(fromPath);
88617
88694
  if (level) {
88618
88695
  for (let k = 1; k < level; k++) {
88619
88696
  if (dir === "." || dir === "/") return [];
88620
- dir = import_node_path16.posix.dirname(dir);
88697
+ dir = import_node_path17.posix.dirname(dir);
88621
88698
  }
88622
88699
  return at(dir);
88623
88700
  }
@@ -88626,7 +88703,7 @@ function pythonModuleCandidates(fromPath, spec2) {
88626
88703
  for (; ; ) {
88627
88704
  out.push(...at(dir));
88628
88705
  if (dir === "." || dir === "/" || dir === "") break;
88629
- dir = import_node_path16.posix.dirname(dir);
88706
+ dir = import_node_path17.posix.dirname(dir);
88630
88707
  }
88631
88708
  return out;
88632
88709
  }
@@ -88851,11 +88928,11 @@ function pythonDependencies(source, fromPath) {
88851
88928
  out.push(...pythonMocks(source, fromPath));
88852
88929
  return out.filter((c) => c.length > 0);
88853
88930
  }
88854
- var import_node_path16, PY, IDENT2, EXTERNAL, indentOf, pythonAdapter;
88931
+ var import_node_path17, PY, IDENT2, EXTERNAL, indentOf, pythonAdapter;
88855
88932
  var init_replay_lang_python = __esm({
88856
88933
  "src/commands/replay-lang-python.ts"() {
88857
88934
  "use strict";
88858
- import_node_path16 = require("node:path");
88935
+ import_node_path17 = require("node:path");
88859
88936
  init_replay_lang_js();
88860
88937
  PY = /\.py$/;
88861
88938
  IDENT2 = /^[A-Za-z_]\w*$/;
@@ -90387,7 +90464,7 @@ function cleanCheckout(deps, dir, task) {
90387
90464
  }
90388
90465
  async function replayArm(deps, options, task, arm, promptOf, inspect, agentEnv = {}) {
90389
90466
  const started = deps.now();
90390
- const dir = (0, import_node_path17.join)(
90467
+ const dir = (0, import_node_path18.join)(
90391
90468
  deps.workDir(),
90392
90469
  `${task.processId.replace(/[^a-zA-Z0-9_-]/g, "")}-${arm}`
90393
90470
  );
@@ -90416,7 +90493,7 @@ async function replayArm(deps, options, task, arm, promptOf, inspect, agentEnv =
90416
90493
  `\u2026 ${label}: set up in ${since(at)}${setup.cached ? " (from the setup cache)" : ""}`
90417
90494
  );
90418
90495
  }
90419
- const promptFile = (0, import_node_path17.join)(dir, ".haansi-replay", "prompt.md");
90496
+ const promptFile = (0, import_node_path18.join)(dir, ".haansi-replay", "prompt.md");
90420
90497
  let mcpConfigFile = agentEnv.HAANSI_REPLAY_MCP_CONFIG;
90421
90498
  if (!mcpConfigFile) {
90422
90499
  mcpConfigFile = `${dir}.mcp.json`;
@@ -90488,12 +90565,14 @@ async function replayArm(deps, options, task, arm, promptOf, inspect, agentEnv =
90488
90565
  `Haansi's servers did not load for the agent (${down.join(", ")}); not graded, run it again`
90489
90566
  );
90490
90567
  }
90568
+ const uses = toolUsesOf(agent.output);
90569
+ if (uses) deps.log(`\u2026 ${label}: tools used: ${toolUsesLine(uses)}`);
90491
90570
  const gradeSha = task.testNames?.length ? task.baseSha : task.targetSha;
90492
- const own = new Map(files.map((f) => [f, deps.readFile((0, import_node_path17.join)(dir, f))]));
90571
+ const own = new Map(files.map((f) => [f, deps.readFile((0, import_node_path18.join)(dir, f))]));
90493
90572
  for (const f of files) {
90494
90573
  const content = await deps.showFile(gradeSha, f);
90495
- if (content === null) deps.removeFile((0, import_node_path17.join)(dir, f));
90496
- else deps.writeFile((0, import_node_path17.join)(dir, f), content);
90574
+ if (content === null) deps.removeFile((0, import_node_path18.join)(dir, f));
90575
+ else deps.writeFile((0, import_node_path18.join)(dir, f), content);
90497
90576
  }
90498
90577
  const testAt = deps.now();
90499
90578
  deps.log(`\u2026 ${label}: agent done in ${since(agentAt)}, grading`);
@@ -90544,8 +90623,8 @@ async function replayArm(deps, options, task, arm, promptOf, inspect, agentEnv =
90544
90623
  }
90545
90624
  if (test.code === 0 && !guarded) {
90546
90625
  for (const [file2, content] of own) {
90547
- if (content === null) deps.removeFile((0, import_node_path17.join)(dir, file2));
90548
- else deps.writeFile((0, import_node_path17.join)(dir, file2), content);
90626
+ if (content === null) deps.removeFile((0, import_node_path18.join)(dir, file2));
90627
+ else deps.writeFile((0, import_node_path18.join)(dir, file2), content);
90549
90628
  }
90550
90629
  if (inspect) await inspect(dir);
90551
90630
  return {
@@ -90561,8 +90640,8 @@ async function replayArm(deps, options, task, arm, promptOf, inspect, agentEnv =
90561
90640
  };
90562
90641
  }
90563
90642
  for (const [file2, content] of own) {
90564
- if (content === null) deps.removeFile((0, import_node_path17.join)(dir, file2));
90565
- else deps.writeFile((0, import_node_path17.join)(dir, file2), content);
90643
+ if (content === null) deps.removeFile((0, import_node_path18.join)(dir, file2));
90644
+ else deps.writeFile((0, import_node_path18.join)(dir, file2), content);
90566
90645
  }
90567
90646
  feedback = guarded ? [
90568
90647
  GUARD_FEEDBACK,
@@ -90654,19 +90733,19 @@ function runCommand(file2, args, cwd, env, timeoutMs, stdoutOnly = false) {
90654
90733
  });
90655
90734
  }
90656
90735
  function dropLinks(work, path2) {
90657
- const rel = (0, import_node_path17.relative)(work, path2);
90658
- if (rel === "" || rel.startsWith("..") || (0, import_node_path17.isAbsolute)(rel)) return;
90736
+ const rel = (0, import_node_path18.relative)(work, path2);
90737
+ if (rel === "" || rel.startsWith("..") || (0, import_node_path18.isAbsolute)(rel)) return;
90659
90738
  let at = work;
90660
- for (const part of rel.split(import_node_path17.sep)) {
90661
- at = (0, import_node_path17.join)(at, part);
90739
+ for (const part of rel.split(import_node_path18.sep)) {
90740
+ at = (0, import_node_path18.join)(at, part);
90662
90741
  let link = false;
90663
90742
  try {
90664
- link = (0, import_node_fs13.lstatSync)(at).isSymbolicLink();
90743
+ link = (0, import_node_fs14.lstatSync)(at).isSymbolicLink();
90665
90744
  } catch {
90666
90745
  return;
90667
90746
  }
90668
90747
  if (link) {
90669
- (0, import_node_fs13.rmSync)(at, { force: true });
90748
+ (0, import_node_fs14.rmSync)(at, { force: true });
90670
90749
  return;
90671
90750
  }
90672
90751
  }
@@ -90693,29 +90772,29 @@ function localDeps(work) {
90693
90772
  // dropLinks: with a container, nothing runs in it while these do.
90694
90773
  writeFile: (path2, content) => {
90695
90774
  dropLinks(work, path2);
90696
- (0, import_node_fs13.mkdirSync)((0, import_node_path17.dirname)(path2), { recursive: true });
90697
- const fd2 = (0, import_node_fs13.openSync)(
90775
+ (0, import_node_fs14.mkdirSync)((0, import_node_path18.dirname)(path2), { recursive: true });
90776
+ const fd2 = (0, import_node_fs14.openSync)(
90698
90777
  path2,
90699
- import_node_fs13.constants.O_WRONLY | import_node_fs13.constants.O_CREAT | import_node_fs13.constants.O_TRUNC | import_node_fs13.constants.O_NOFOLLOW
90778
+ import_node_fs14.constants.O_WRONLY | import_node_fs14.constants.O_CREAT | import_node_fs14.constants.O_TRUNC | import_node_fs14.constants.O_NOFOLLOW
90700
90779
  );
90701
90780
  try {
90702
- (0, import_node_fs13.writeFileSync)(fd2, content);
90781
+ (0, import_node_fs14.writeFileSync)(fd2, content);
90703
90782
  } finally {
90704
- (0, import_node_fs13.closeSync)(fd2);
90783
+ (0, import_node_fs14.closeSync)(fd2);
90705
90784
  }
90706
90785
  },
90707
90786
  readFile: (path2) => {
90708
90787
  dropLinks(work, path2);
90709
- if (!(0, import_node_fs13.existsSync)(path2)) return null;
90710
- const fd2 = (0, import_node_fs13.openSync)(path2, import_node_fs13.constants.O_RDONLY | import_node_fs13.constants.O_NOFOLLOW);
90788
+ if (!(0, import_node_fs14.existsSync)(path2)) return null;
90789
+ const fd2 = (0, import_node_fs14.openSync)(path2, import_node_fs14.constants.O_RDONLY | import_node_fs14.constants.O_NOFOLLOW);
90711
90790
  try {
90712
- return (0, import_node_fs13.readFileSync)(fd2, "utf-8");
90791
+ return (0, import_node_fs14.readFileSync)(fd2, "utf-8");
90713
90792
  } finally {
90714
- (0, import_node_fs13.closeSync)(fd2);
90793
+ (0, import_node_fs14.closeSync)(fd2);
90715
90794
  }
90716
90795
  },
90717
- removeFile: (path2) => (0, import_node_fs13.rmSync)(path2, { force: true }),
90718
- removeDir: (path2) => (0, import_node_fs13.rmSync)(path2, { recursive: true, force: true }),
90796
+ removeFile: (path2) => (0, import_node_fs14.rmSync)(path2, { force: true }),
90797
+ removeDir: (path2) => (0, import_node_fs14.rmSync)(path2, { recursive: true, force: true }),
90719
90798
  now: () => Date.now(),
90720
90799
  log: (line) => console.log(line)
90721
90800
  };
@@ -90754,7 +90833,7 @@ async function replay(argv) {
90754
90833
  async function replayStored(options, token2, apiUrl2) {
90755
90834
  const { runStoredReplays: runStoredReplays2 } = await Promise.resolve().then(() => (init_replay_tasks(), replay_tasks_exports));
90756
90835
  const { cliVersion: cliVersion2 } = await Promise.resolve().then(() => (init_replay_calibrate(), replay_calibrate_exports));
90757
- const work = (0, import_node_fs13.mkdtempSync)((0, import_node_path17.join)((0, import_node_os11.tmpdir)(), "haansi-replay-"));
90836
+ const work = (0, import_node_fs14.mkdtempSync)((0, import_node_path18.join)((0, import_node_os11.tmpdir)(), "haansi-replay-"));
90758
90837
  let stop = null;
90759
90838
  try {
90760
90839
  const contained = await withContainer(
@@ -90835,17 +90914,18 @@ Baseline: ${arm("baseline")} passed \xB7 With Haansi: ${arm("haansi")} passed \x
90835
90914
  process.exitCode = 1;
90836
90915
  } finally {
90837
90916
  await stop?.();
90838
- (0, import_node_fs13.rmSync)(work, { recursive: true, force: true });
90917
+ removeWorkDir(work);
90839
90918
  }
90840
90919
  }
90841
- var import_node_child_process5, import_node_fs13, import_node_os11, import_node_path17, SHA, ARMS, FEEDBACK_CHARS, FAILURE_LINES2, REPLAY_BRANCH, OUTPUT_HEAD_CHARS, OUTPUT_TAIL_CHARS, USAGE2;
90920
+ var import_node_child_process5, import_node_fs14, import_node_os11, import_node_path18, SHA, ARMS, FEEDBACK_CHARS, FAILURE_LINES2, REPLAY_BRANCH, OUTPUT_HEAD_CHARS, OUTPUT_TAIL_CHARS, USAGE2;
90842
90921
  var init_replay = __esm({
90843
90922
  "src/commands/replay.ts"() {
90844
90923
  "use strict";
90924
+ init_replay_workdir();
90845
90925
  import_node_child_process5 = require("node:child_process");
90846
- import_node_fs13 = require("node:fs");
90926
+ import_node_fs14 = require("node:fs");
90847
90927
  import_node_os11 = require("node:os");
90848
- import_node_path17 = require("node:path");
90928
+ import_node_path18 = require("node:path");
90849
90929
  init_paths();
90850
90930
  init_replay_errors();
90851
90931
  init_api2();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "haansi",
3
- "version": "0.1.107",
3
+ "version": "0.1.109",
4
4
  "description": "Haansi CLI - Session collector and MCP server for Claude Code & OpenAI Codex",
5
5
  "bin": {
6
6
  "haansi": "./dist/haansi.js"