haansi 0.1.99 → 0.1.101

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 +116 -15
  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.99",
98
+ version: "0.1.101",
99
99
  description: "Haansi CLI - Session collector and MCP server for Claude Code & OpenAI Codex",
100
100
  bin: {
101
101
  haansi: "./dist/haansi.js"
@@ -86710,8 +86710,6 @@ function usageOf(output) {
86710
86710
  }
86711
86711
  function modelUnreachableOf(output, exitCode) {
86712
86712
  if (exitCode === 0) return null;
86713
- const used = usageOf(output);
86714
- if ((used.outputTokens ?? 0) > 0) return null;
86715
86713
  const objects = jsonLines(output);
86716
86714
  const result = [...objects].reverse().find((o) => o.type === "result");
86717
86715
  if (result && result.is_error === true) {
@@ -86719,6 +86717,8 @@ function modelUnreachableOf(output, exitCode) {
86719
86717
  if (result.terminal_reason === "api_error" || MODEL_REFUSAL.test(said))
86720
86718
  return clipReason(said || "the model's API returned an error");
86721
86719
  }
86720
+ const used = usageOf(output);
86721
+ if ((used.outputTokens ?? 0) > 0) return null;
86722
86722
  for (const o of [...objects].reverse()) {
86723
86723
  const message = typeof o.message === "string" ? o.message : typeof o.error?.message === "string" ? String(o.error.message) : "";
86724
86724
  if ((o.type === "error" || o.type === "turn.failed") && MODEL_REFUSAL.test(message))
@@ -86731,7 +86731,54 @@ function clipReason(text) {
86731
86731
  const t = text.replace(/\s+/g, " ").trim();
86732
86732
  return t.length > MAX_REASON_CHARS ? `${t.slice(0, MAX_REASON_CHARS - 1)}\u2026` : t;
86733
86733
  }
86734
- var NONE, count2, MODEL_REFUSAL, MAX_REASON_CHARS;
86734
+ function mcpServersOf(output) {
86735
+ const init2 = jsonLines(output).find(
86736
+ (o) => o.type === "system" && o.subtype === "init"
86737
+ );
86738
+ if (!init2 || !Array.isArray(init2.mcp_servers)) return null;
86739
+ return init2.mcp_servers.map((s) => s ?? {}).filter(
86740
+ (s) => typeof s.name === "string"
86741
+ ).map((s) => ({
86742
+ name: s.name,
86743
+ status: typeof s.status === "string" ? s.status : "unknown"
86744
+ }));
86745
+ }
86746
+ function haansiServersDown(output) {
86747
+ const servers = mcpServersOf(output);
86748
+ if (!servers) return null;
86749
+ return servers.filter((s) => s.name.startsWith("haansi-") && s.status !== "connected").map((s) => `${s.name}: ${s.status}`);
86750
+ }
86751
+ function agentFailureLines(output, max2, scrub) {
86752
+ const out = [];
86753
+ for (const raw of output.trim().split(/\r?\n/)) {
86754
+ const line = raw.trim();
86755
+ if (!line) continue;
86756
+ if (line.startsWith("{") && line.endsWith("}")) {
86757
+ let event = null;
86758
+ try {
86759
+ event = JSON.parse(line);
86760
+ } catch {
86761
+ event = null;
86762
+ }
86763
+ if (event && typeof event === "object") {
86764
+ if (event.type !== "result") continue;
86765
+ const said = [
86766
+ typeof event.terminal_reason === "string" ? `terminal_reason=${event.terminal_reason}` : "",
86767
+ event.is_error === true ? "is_error" : "",
86768
+ typeof event.result === "string" ? event.result : ""
86769
+ ].filter(Boolean).join(" ");
86770
+ if (said) out.push(said);
86771
+ continue;
86772
+ }
86773
+ }
86774
+ out.push(line);
86775
+ }
86776
+ return out.slice(-max2).map((l) => {
86777
+ const clean = scrub(l.replace(/\s+/g, " "));
86778
+ return clean.length > MAX_LOGGED_LINE_CHARS ? `${clean.slice(0, MAX_LOGGED_LINE_CHARS - 1)}\u2026` : clean;
86779
+ });
86780
+ }
86781
+ var NONE, count2, MODEL_REFUSAL, MAX_REASON_CHARS, MAX_LOGGED_LINE_CHARS;
86735
86782
  var init_replay_usage = __esm({
86736
86783
  "src/commands/replay-usage.ts"() {
86737
86784
  "use strict";
@@ -86745,6 +86792,7 @@ var init_replay_usage = __esm({
86745
86792
  count2 = (v) => typeof v === "number" && Number.isFinite(v) && v >= 0 ? v : null;
86746
86793
  MODEL_REFUSAL = /credit balance is too low|insufficient[_ ](?:credit|quota|balance|funds)|quota (?:exceeded|exhausted)|exceeded your (?:current )?quota|invalid (?:x-)?api[_ -]?key|authentication[_ ]error|rate[_ ]limit(?:_error| exceeded| reached)|overloaded[_ ]error|api[_ ]error/i;
86747
86794
  MAX_REASON_CHARS = 200;
86795
+ MAX_LOGGED_LINE_CHARS = 300;
86748
86796
  }
86749
86797
  });
86750
86798
 
@@ -88364,6 +88412,7 @@ function configFingerprintOf(c) {
88364
88412
  return (0, import_node_crypto6.createHash)("sha256").update(
88365
88413
  JSON.stringify({
88366
88414
  agentCmd: c.agentCmd,
88415
+ judgeCmd: c.judgeCmd ?? null,
88367
88416
  testCmd: c.testCmd,
88368
88417
  setupCmd: c.setupCmd,
88369
88418
  attempts: c.attempts,
@@ -88453,7 +88502,7 @@ async function runStoredReplays(options, deps) {
88453
88502
  );
88454
88503
  } else if (valid.length) {
88455
88504
  const gate = await gateOnContext(deps, valid, {
88456
- agentCmd: options.agentCmd,
88505
+ agentCmd: options.judgeCmd || options.agentCmd,
88457
88506
  timeoutMs: options.timeoutMs,
88458
88507
  concurrency: options.concurrency ?? 1,
88459
88508
  limit: options.limit,
@@ -88580,7 +88629,7 @@ async function runStoredReplays(options, deps) {
88580
88629
  ...await judgeUse(deps, {
88581
88630
  label,
88582
88631
  taskId: task.taskId,
88583
- agentCmd: options.agentCmd,
88632
+ agentCmd: options.judgeCmd || options.agentCmd,
88584
88633
  timeoutMs: options.timeoutMs,
88585
88634
  card: cardPrompt(task, null),
88586
88635
  calls,
@@ -88610,7 +88659,7 @@ async function runStoredReplays(options, deps) {
88610
88659
  const judged = await judgeRelevance(deps, {
88611
88660
  label,
88612
88661
  taskId: task.taskId,
88613
- agentCmd: options.agentCmd,
88662
+ agentCmd: options.judgeCmd || options.agentCmd,
88614
88663
  timeoutMs: options.timeoutMs,
88615
88664
  card: cardPrompt(task, null),
88616
88665
  targetChange: targetText,
@@ -88740,12 +88789,15 @@ var init_replay_tasks = __esm({
88740
88789
  // src/commands/replay.ts
88741
88790
  var replay_exports = {};
88742
88791
  __export(replay_exports, {
88792
+ OUTPUT_HEAD_CHARS: () => OUTPUT_HEAD_CHARS,
88793
+ OUTPUT_TAIL_CHARS: () => OUTPUT_TAIL_CHARS,
88743
88794
  SHA: () => SHA,
88744
88795
  cleanClone: () => cleanClone,
88745
88796
  dropLinks: () => dropLinks,
88746
88797
  ensureCommit: () => ensureCommit,
88747
88798
  githubRunRef: () => githubRunRef,
88748
88799
  localDeps: () => localDeps,
88800
+ outputKeeper: () => outputKeeper,
88749
88801
  parseReplayArgs: () => parseReplayArgs,
88750
88802
  replay: () => replay,
88751
88803
  replayArm: () => replayArm,
@@ -88788,6 +88840,7 @@ function parseReplayArgs(argv) {
88788
88840
  "--family is retired: replays run on the tasks selected on Impact \u2192 Replays."
88789
88841
  );
88790
88842
  } else if (a === "--agent-cmd") options.agentCmd = next();
88843
+ else if (a === "--judge-cmd") options.judgeCmd = next() || null;
88791
88844
  else if (a === "--test-cmd") options.testCmd = next();
88792
88845
  else if (a === "--setup-cmd") options.setupCmd = next() || null;
88793
88846
  else if (a === "--attempts") options.attempts = Number(next());
@@ -88971,7 +89024,11 @@ async function replayArm(deps, options, task, arm, promptOf, inspect, agentEnv =
88971
89024
  });
88972
89025
  if (agent.code !== 0) {
88973
89026
  deps.log(`\u2026 ${label}: the agent exited with code ${agent.code}`);
88974
- for (const line of agent.output.trim().split("\n").slice(-FAILURE_LINES2))
89027
+ for (const line of agentFailureLines(
89028
+ agent.output,
89029
+ FAILURE_LINES2,
89030
+ scrubSecrets
89031
+ ))
88975
89032
  deps.log(` ${line}`);
88976
89033
  }
88977
89034
  const unreachable2 = modelUnreachableOf(agent.output, agent.code);
@@ -88979,6 +89036,17 @@ async function replayArm(deps, options, task, arm, promptOf, inspect, agentEnv =
88979
89036
  throw new Error(
88980
89037
  `the agent could not reach its model (${unreachable2}); not graded, run it again`
88981
89038
  );
89039
+ if (arm === "haansi") {
89040
+ const down = haansiServersDown(agent.output);
89041
+ if (down === null)
89042
+ deps.log(
89043
+ `\u2026 ${label}: the agent did not report its MCP servers (use --output-format stream-json --verbose to check them)`
89044
+ );
89045
+ else if (down.length)
89046
+ throw new Error(
89047
+ `Haansi's servers did not load for the agent (${down.join(", ")}); not graded, run it again`
89048
+ );
89049
+ }
88982
89050
  const gradeSha = task.testNames?.length ? task.baseSha : task.targetSha;
88983
89051
  const own = new Map(files.map((f) => [f, deps.readFile((0, import_node_path16.join)(dir, f))]));
88984
89052
  for (const f of files) {
@@ -89079,6 +89147,31 @@ async function replayArm(deps, options, task, arm, promptOf, inspect, agentEnv =
89079
89147
  if (!agentEnv.HAANSI_REPLAY_MCP_CONFIG) deps.removeFile(`${dir}.mcp.json`);
89080
89148
  }
89081
89149
  }
89150
+ function outputKeeper(headChars = OUTPUT_HEAD_CHARS, tailChars = OUTPUT_TAIL_CHARS) {
89151
+ let head = "";
89152
+ let tail = "";
89153
+ let dropped = false;
89154
+ return {
89155
+ add(text) {
89156
+ if (head.length < headChars) {
89157
+ const room = headChars - head.length;
89158
+ head += text.slice(0, room);
89159
+ text = text.slice(room);
89160
+ }
89161
+ if (!text) return;
89162
+ tail += text;
89163
+ if (tail.length > tailChars) {
89164
+ tail = tail.slice(-tailChars);
89165
+ dropped = true;
89166
+ }
89167
+ },
89168
+ text() {
89169
+ return dropped ? `${head}
89170
+ \u2026 (output trimmed)
89171
+ ${tail}` : head + tail;
89172
+ }
89173
+ };
89174
+ }
89082
89175
  function runCommand(file2, args, cwd, env, timeoutMs, stdoutOnly = false) {
89083
89176
  return new Promise((resolvePromise) => {
89084
89177
  const child = (0, import_node_child_process5.spawn)(file2, args, {
@@ -89087,9 +89180,9 @@ function runCommand(file2, args, cwd, env, timeoutMs, stdoutOnly = false) {
89087
89180
  stdio: ["ignore", "pipe", "pipe"]
89088
89181
  });
89089
89182
  let output = "";
89090
- const keep = (chunk) => {
89091
- output = (output + chunk.toString()).slice(-2e5);
89092
- };
89183
+ const kept = outputKeeper();
89184
+ const keep = (chunk) => kept.add(chunk.toString());
89185
+ const finalOutput = () => stdoutOnly ? output : kept.text();
89093
89186
  if (stdoutOnly) {
89094
89187
  const chunks = [];
89095
89188
  child.stdout.on("data", (chunk) => chunks.push(chunk));
@@ -89109,13 +89202,13 @@ function runCommand(file2, args, cwd, env, timeoutMs, stdoutOnly = false) {
89109
89202
  clearTimeout(timer);
89110
89203
  resolvePromise({
89111
89204
  code: code ?? 1,
89112
- output,
89205
+ output: finalOutput(),
89113
89206
  ...timedOut ? { timedOut } : {}
89114
89207
  });
89115
89208
  });
89116
89209
  child.on("error", () => {
89117
89210
  clearTimeout(timer);
89118
- resolvePromise({ code: 1, output });
89211
+ resolvePromise({ code: 1, output: finalOutput() });
89119
89212
  });
89120
89213
  });
89121
89214
  }
@@ -89297,7 +89390,7 @@ Baseline: ${arm("baseline")} passed \xB7 With Haansi: ${arm("haansi")} passed \x
89297
89390
  (0, import_node_fs13.rmSync)(work, { recursive: true, force: true });
89298
89391
  }
89299
89392
  }
89300
- var import_node_child_process5, import_node_fs13, import_node_os11, import_node_path16, SHA, ARMS, FEEDBACK_CHARS, FAILURE_LINES2, REPLAY_BRANCH, USAGE2;
89393
+ var import_node_child_process5, import_node_fs13, import_node_os11, import_node_path16, SHA, ARMS, FEEDBACK_CHARS, FAILURE_LINES2, REPLAY_BRANCH, OUTPUT_HEAD_CHARS, OUTPUT_TAIL_CHARS, USAGE2;
89301
89394
  var init_replay = __esm({
89302
89395
  "src/commands/replay.ts"() {
89303
89396
  "use strict";
@@ -89319,9 +89412,12 @@ var init_replay = __esm({
89319
89412
  FEEDBACK_CHARS = 6e3;
89320
89413
  FAILURE_LINES2 = 8;
89321
89414
  REPLAY_BRANCH = "replay";
89415
+ OUTPUT_HEAD_CHARS = 4e4;
89416
+ OUTPUT_TAIL_CHARS = 2e5;
89322
89417
  USAGE2 = `Usage: haansi replay run --agent-cmd "<cmd>" --test-cmd "<cmd>"
89323
89418
  [--setup-cmd "<cmd>"] [--attempts 3] [--arms baseline,haansi] [--limit n]
89324
89419
  [--timeout-min 20] [--agent-name <name>] [--model <name>]
89420
+ [--judge-cmd "<cmd>"]
89325
89421
  [--run-ref <url>] [--dry-run] [--repo-commands] [--no-diffs]
89326
89422
  [--shard i/n] [--concurrency k] [--force] [--max-hours h] [--any-context]
89327
89423
  [--setup-cache <files> --setup-cache-path <paths> [--setup-cache-dir <dir>]]
@@ -89356,6 +89452,11 @@ A task with nothing relevant Haansi can return is skipped, and checked again
89356
89452
  once the organization gains new Haansi content. --any-context replays every
89357
89453
  valid task without the check (diagnostics).
89358
89454
 
89455
+ --judge-cmd runs the judges (whether the agent used what Haansi returned,
89456
+ which of it was relevant, and the context check before replaying) with their
89457
+ own command, e.g. a stronger model than a cheap agent's; --agent-cmd when not
89458
+ given.
89459
+
89359
89460
  --repo-commands uses the setup and test commands an org owner or admin saved for the
89360
89461
  repository in Haansi (Impact \u2192 Replays) for any not given here.
89361
89462
 
@@ -89368,7 +89469,7 @@ Run from a clone of the repository. Example (GitHub Actions):
89368
89469
  haansi replay run --setup-cmd 'npm ci' \\
89369
89470
  --container node:22 --container-env ANTHROPIC_API_KEY \\
89370
89471
  --container-setup 'npm install -g haansi @anthropic-ai/claude-code' \\
89371
- --agent-cmd 'claude -p "$HAANSI_REPLAY_PROMPT" --output-format json --permission-mode acceptEdits --mcp-config "$HAANSI_REPLAY_MCP_CONFIG" --allowedTools mcp__haansi-solutions,mcp__haansi-exchange,mcp__haansi-digests,mcp__haansi-onboarding,mcp__haansi-skills' \\
89472
+ --agent-cmd 'claude -p "$HAANSI_REPLAY_PROMPT" --output-format stream-json --verbose --permission-mode acceptEdits --mcp-config "$HAANSI_REPLAY_MCP_CONFIG" --allowedTools mcp__haansi-solutions,mcp__haansi-exchange,mcp__haansi-digests,mcp__haansi-onboarding,mcp__haansi-skills' \\
89372
89473
  --test-cmd 'npx vitest run $HAANSI_REPLAY_TEST_FILES -t "$HAANSI_REPLAY_TEST_PATTERN"' \\
89373
89474
  --agent-name claude-code --model claude-sonnet-5-5`;
89374
89475
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "haansi",
3
- "version": "0.1.99",
3
+ "version": "0.1.101",
4
4
  "description": "Haansi CLI - Session collector and MCP server for Claude Code & OpenAI Codex",
5
5
  "bin": {
6
6
  "haansi": "./dist/haansi.js"