haansi 0.1.111 → 0.1.113

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 +156 -18
  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.111",
98
+ version: "0.1.113",
99
99
  description: "Haansi CLI - Session collector and MCP server for Claude Code & OpenAI Codex",
100
100
  bin: {
101
101
  haansi: "./dist/haansi.js"
@@ -19657,6 +19657,48 @@ var init_exclusions = __esm({
19657
19657
  ],
19658
19658
  cadence: ["operational", "Closed CHECK vocabulary (weekly, monthly)."]
19659
19659
  }),
19660
+ ...exchangeExclusions(INTEL, "repo_convention_skills", {
19661
+ repository: [
19662
+ "join-key",
19663
+ "owner/repo, as in repo_conventions; unique with the org."
19664
+ ]
19665
+ }),
19666
+ ...exchangeExclusions(INTEL, "repo_convention_proposal_runs", {
19667
+ repository: [
19668
+ "join-key",
19669
+ "owner/repo a run was asked for, as in repo_conventions; NULL for the daily run."
19670
+ ],
19671
+ trigger: ["operational", "Closed CHECK vocabulary (schedule, request)."],
19672
+ skipped_reason: [
19673
+ "operational",
19674
+ "Closed CHECK vocabulary (no_model, no_github)."
19675
+ ]
19676
+ }),
19677
+ ...exchangeExclusions(INTEL, "repo_convention_proposal_inputs", {
19678
+ repository: [
19679
+ "join-key",
19680
+ "owner/repo, as in repo_conventions; the primary key with the org."
19681
+ ],
19682
+ input_key: [
19683
+ "not-personal",
19684
+ "sha256 hex of an input's name (file path, or CI check and target); no plaintext."
19685
+ ],
19686
+ fingerprint: [
19687
+ "not-personal",
19688
+ "sha256 hex of what was sent to the model, or the commit SHA last read; no plaintext."
19689
+ ]
19690
+ }),
19691
+ ...exchangeExclusions(INTEL, "repo_convention_checks", {
19692
+ repository: [
19693
+ "join-key",
19694
+ "owner/repo the check covered, as in repo_conventions; matched by equality."
19695
+ ],
19696
+ trigger: ["operational", "Closed CHECK vocabulary (schedule, request)."],
19697
+ skipped_reason: [
19698
+ "operational",
19699
+ "Closed CHECK vocabulary (no_model, no_github)."
19700
+ ]
19701
+ }),
19660
19702
  ...exchangeExclusions(INTEL, "attempt_rule_configs", {
19661
19703
  config: [
19662
19704
  "operational",
@@ -26924,6 +26966,31 @@ var init_table_registry = __esm({
26924
26966
  entry("intelligence", INTELLIGENCE_DB, "repo_convention_settings", "direct", {
26925
26967
  scopingColumn: "organization_id"
26926
26968
  }),
26969
+ // The skill each repository's conventions were built into
26970
+ // (repo-conventions/003).
26971
+ entry("intelligence", INTELLIGENCE_DB, "repo_convention_skills", "direct", {
26972
+ scopingColumn: "organization_id"
26973
+ }),
26974
+ // The proposer's runs and what it last sent per input (repo-conventions/004).
26975
+ entry(
26976
+ "intelligence",
26977
+ INTELLIGENCE_DB,
26978
+ "repo_convention_proposal_runs",
26979
+ "direct",
26980
+ { scopingColumn: "organization_id" }
26981
+ ),
26982
+ entry(
26983
+ "intelligence",
26984
+ INTELLIGENCE_DB,
26985
+ "repo_convention_proposal_inputs",
26986
+ "direct",
26987
+ { scopingColumn: "organization_id" }
26988
+ ),
26989
+ // Freshness checks of a repository's approved conventions
26990
+ // (repo-conventions/005).
26991
+ entry("intelligence", INTELLIGENCE_DB, "repo_convention_checks", "direct", {
26992
+ scopingColumn: "organization_id"
26993
+ }),
26927
26994
  // "Mine more tasks" requests the outcome ledger polls (outcome-ledger/058).
26928
26995
  entry("intelligence", INTELLIGENCE_DB, "replay_mining_requests", "direct", {
26929
26996
  scopingColumn: "organization_id"
@@ -85827,9 +85894,13 @@ __export(skills_exports, {
85827
85894
  sha256: () => sha256,
85828
85895
  skills: () => skills,
85829
85896
  syncInto: () => syncInto,
85897
+ syncableCards: () => syncableCards,
85830
85898
  targetDirs: () => targetDirs,
85831
85899
  unchangedLocally: () => unchangedLocally
85832
85900
  });
85901
+ function syncableCards(cards) {
85902
+ return cards.filter((c) => c.needsUpdate !== true);
85903
+ }
85833
85904
  function parseSkillsArgs(argv) {
85834
85905
  const options = { project: false };
85835
85906
  let sub;
@@ -86020,7 +86091,7 @@ async function skills(argv) {
86020
86091
  token2,
86021
86092
  apiUrl2
86022
86093
  );
86023
- const cards = list2.data ?? [];
86094
+ const cards = syncableCards(list2.data ?? []);
86024
86095
  const { agents } = resolveAgentSelection(options.agent);
86025
86096
  for (const dir of targetDirs(options, agents)) {
86026
86097
  const report = await syncInto(
@@ -86711,6 +86782,9 @@ function unreachable(checks) {
86711
86782
  const down = checks.filter((c) => !c.ok);
86712
86783
  return down.length ? down.map((c) => `${c.name} (${c.reason ?? "no answer"})`).join(", ") : null;
86713
86784
  }
86785
+ function agentLoadsMachineServers(agentCmd) {
86786
+ return /(^|[\s/"'])claude(\s|$)/.test(agentCmd) && !/--strict-mcp-config(?![\w-])/.test(agentCmd);
86787
+ }
86714
86788
  function agentCannotCallHaansi(agentCmd) {
86715
86789
  if (!/(^|[\s/"'])claude(\s|$)/.test(agentCmd)) return null;
86716
86790
  if (/--dangerously-skip-permissions|bypassPermissions/.test(agentCmd))
@@ -87060,6 +87134,11 @@ function haansiServersDown(output) {
87060
87134
  if (!servers) return null;
87061
87135
  return servers.filter((s) => s.name.startsWith("haansi-") && s.status !== "connected").map((s) => `${s.name}: ${s.status}`);
87062
87136
  }
87137
+ function haansiServersLoaded(output) {
87138
+ const servers = mcpServersOf(output);
87139
+ if (!servers) return null;
87140
+ return servers.filter((s) => s.name.startsWith("haansi-") && s.status === "connected").map((s) => s.name);
87141
+ }
87063
87142
  function agentFailureLines(output, max2, scrub) {
87064
87143
  const out = [];
87065
87144
  for (const raw of output.trim().split(/\r?\n/)) {
@@ -88017,6 +88096,11 @@ function renderTemplate(template, vars) {
88017
88096
  function judgeChange(diff) {
88018
88097
  return clip(diff, MAX_CHANGE_CHARS);
88019
88098
  }
88099
+ function baselineText(baseline) {
88100
+ if (baseline === null || baseline === void 0)
88101
+ return "(not run alongside this one: judge from the material and the change alone)";
88102
+ return baseline || "(it changed nothing)";
88103
+ }
88020
88104
  function parseJudgement(text, returnedIds) {
88021
88105
  const match = /\{[\s\S]*\}/.exec(text);
88022
88106
  if (!match) return null;
@@ -88080,6 +88164,8 @@ async function judgeUse(deps, input) {
88080
88164
  task: input.card,
88081
88165
  returned: clip(returned || "(only ids came back)", returnedChars),
88082
88166
  change: clip(input.change || "(no change)", changeChars),
88167
+ // Shares the change's budget: they are read side by side.
88168
+ baseline: clip(baselineText(input.baseline), changeChars),
88083
88169
  verdict_file: verdictFile
88084
88170
  })
88085
88171
  ].join("\n"),
@@ -88514,7 +88600,7 @@ function typeEnd(text, i, stops, bodyBrace) {
88514
88600
  return text.length;
88515
88601
  }
88516
88602
  function capSignature(text) {
88517
- const lines = text.trim().split("\n").map((l) => l.replace(/\s+$/, ""));
88603
+ const lines = text.trim().split("\n").map((l) => l.replace(/\s+$/, "")).filter((l) => l !== "");
88518
88604
  let out = lines.slice(0, MAX_SIGNATURE_LINES).join("\n");
88519
88605
  let cut2 = lines.length > MAX_SIGNATURE_LINES;
88520
88606
  if (out.length > MAX_SIGNATURE_CHARS) {
@@ -88559,7 +88645,7 @@ function signatureOf(source, name) {
88559
88645
  }
88560
88646
  return capSignature(text.slice(start, end));
88561
88647
  }
88562
- const type = new RegExp(`${lead}(type\\s+${n})\\b`).exec(text);
88648
+ const type = new RegExp(`${lead}(type\\s+${n})\\b(?=\\s*[=<])`).exec(text);
88563
88649
  if (type) {
88564
88650
  const start = type.index + type[0].length - type[2].length - type[1].length;
88565
88651
  const end = typeEnd(text, type.index + type[0].length, ";", false);
@@ -89182,16 +89268,25 @@ function interfaceSection(entries) {
89182
89268
  ];
89183
89269
  const where = `\`${e.path}\`${e.newFile ? " (a new file)" : ""}`;
89184
89270
  const declared = e.names.filter((n) => e.signatures?.[n]);
89271
+ const types2 = Object.entries(e.types ?? {});
89272
+ const fence = adapterFor(e.path)?.fence ?? "ts";
89185
89273
  return [
89186
89274
  `- ${where}${what.length ? `: ${what.join(", ")}` : ""}`,
89187
89275
  // As the target declares each: its shape, never its body.
89188
89276
  ...declared.flatMap((n) => [
89189
89277
  "",
89190
- ...fenced(e.signatures[n], adapterFor(e.path)?.fence ?? "ts").map(
89191
- (l) => ` ${l}`
89192
- )
89278
+ ...fenced(e.signatures[n], fence).map((l) => ` ${l}`)
89193
89279
  ]),
89194
- ...declared.length ? [""] : []
89280
+ ...declared.length ? [""] : [],
89281
+ // The shapes those declarations name, as the module declares them.
89282
+ ...types2.length ? [
89283
+ " The types these use, declared in the same module:",
89284
+ ...types2.flatMap(([, sig]) => [
89285
+ "",
89286
+ ...fenced(sig, fence).map((l) => ` ${l}`)
89287
+ ]),
89288
+ ""
89289
+ ] : []
89195
89290
  ];
89196
89291
  }),
89197
89292
  ""
@@ -89359,16 +89454,38 @@ function cappedTitles(titles) {
89359
89454
  }
89360
89455
  return { shown, more: titles.length - shown.length };
89361
89456
  }
89457
+ function typeNamesIn(declaration) {
89458
+ return [...new Set(declaration.match(/\b[A-Z][A-Za-z0-9_]*\b/g) ?? [])];
89459
+ }
89362
89460
  async function withSignatures(show, targetSha, entries) {
89363
89461
  const out = [];
89364
89462
  for (const e of entries) {
89365
89463
  const source = e.names.length ? await show(targetSha, e.path) : null;
89464
+ const lang = adapterFor(e.path);
89366
89465
  const signatures = {};
89367
89466
  for (const n of e.names) {
89368
- const sig = source === null ? null : adapterFor(e.path)?.signatureOf(source, n) ?? null;
89467
+ const sig = source === null ? null : lang?.signatureOf(source, n) ?? null;
89369
89468
  if (sig) signatures[n] = sig;
89370
89469
  }
89371
- out.push(Object.keys(signatures).length ? { ...e, signatures } : e);
89470
+ const types2 = {};
89471
+ if (source !== null && lang) {
89472
+ const queue = Object.values(signatures).flatMap(typeNamesIn);
89473
+ const seen = new Set(e.names);
89474
+ while (queue.length && Object.keys(types2).length < MAX_TYPE_DECLARATIONS) {
89475
+ const name = queue.shift();
89476
+ if (seen.has(name)) continue;
89477
+ seen.add(name);
89478
+ const sig = lang.signatureOf(source, name);
89479
+ if (!sig) continue;
89480
+ types2[name] = sig;
89481
+ queue.push(...typeNamesIn(sig));
89482
+ }
89483
+ }
89484
+ out.push({
89485
+ ...e,
89486
+ ...Object.keys(signatures).length ? { signatures } : {},
89487
+ ...Object.keys(types2).length ? { types: types2 } : {}
89488
+ });
89372
89489
  }
89373
89490
  return out;
89374
89491
  }
@@ -89441,7 +89558,7 @@ function baseNameOf(path2) {
89441
89558
  const name = /\.py$/.test(file2) ? file2.replace(/\.py$/, "").replace(/^test_(?=.)|(?<=.)_test$/, "") : file2.replace(/\.[cm]?[jt]sx?$/, "").replace(/\.(?:test|spec)$/, "");
89442
89559
  return (name === "index" || name === "__init__") && parts.length ? parts[parts.length - 1] : name;
89443
89560
  }
89444
- var MAX_TITLES, MAX_TITLE_CHARS, MAX_FAILING_PATHS, MAX_HOP_MODULES, norm;
89561
+ var MAX_TITLES, MAX_TITLE_CHARS, MAX_FAILING_PATHS, MAX_TYPE_DECLARATIONS, MAX_HOP_MODULES, norm;
89445
89562
  var init_replay_spec = __esm({
89446
89563
  "src/commands/replay-spec.ts"() {
89447
89564
  "use strict";
@@ -89451,6 +89568,7 @@ var init_replay_spec = __esm({
89451
89568
  MAX_TITLES = 40;
89452
89569
  MAX_TITLE_CHARS = 4e3;
89453
89570
  MAX_FAILING_PATHS = 12;
89571
+ MAX_TYPE_DECLARATIONS = 8;
89454
89572
  MAX_HOP_MODULES = 24;
89455
89573
  norm = (s) => s.replace(/\s+/g, " ").trim();
89456
89574
  }
@@ -89776,12 +89894,12 @@ function haansiSection(tools, hint = null) {
89776
89894
  "",
89777
89895
  "These MCP servers hold what your organization learned before this task began. They are read-only here.",
89778
89896
  "",
89779
- "Start here, before you read or change any code, and search again when you get stuck:",
89897
+ "Work on the task first, as you would without them: read the code and make your change. Then, before you finish, check your work against them, and change it where they show something wrong, missing or already tried. Search again whenever you get stuck:",
89780
89898
  "",
89781
- "- Repository conventions: before you start coding, get_conventions with the files you expect to change: the repository's approved conventions (rules this codebase follows) that apply to them.",
89899
+ "- Repository conventions: get_conventions with the files you changed: the repository's approved conventions (rules this codebase follows) that apply to them.",
89782
89900
  "- Past fixes: search_solutions with a sentence about the problem (its error line in error, failing tests in failing_tests, the files you expect to change in files, identifiers in names), then get_solution to read the matching results in full.",
89783
89901
  "- Team procedures: match_playbook with the task, and search_skills; get_skill loads one.",
89784
- "- Earlier attempts at the same code: get_prior_attempts with the files you expect to change.",
89902
+ "- Earlier attempts at the same code: get_prior_attempts with the files you changed.",
89785
89903
  "- Incidents like this one: search_prior_incidents.",
89786
89904
  "- Recent work, conventions and shared answers: search_digests, search_guides and search_exchange.",
89787
89905
  "",
@@ -89938,6 +90056,14 @@ async function runStoredReplays(options, deps) {
89938
90056
  throw new Error(
89939
90057
  `No test command: pass --test-cmd, or set one for ${repository} in Haansi.`
89940
90058
  );
90059
+ for (const [flag, cmd] of [
90060
+ ["--agent-cmd", options.agentCmd],
90061
+ ["--judge-cmd", options.judgeCmd ?? ""]
90062
+ ])
90063
+ if (cmd && agentLoadsMachineServers(cmd))
90064
+ deps.log(
90065
+ `${flag} runs Claude Code without --strict-mcp-config: it also loads the MCP servers set up on this machine. Add --strict-mcp-config so each arm and judge gets only its own servers.`
90066
+ );
89941
90067
  if (set2.tasks.length === 0) {
89942
90068
  deps.log(
89943
90069
  `No replay tasks for ${repository} yet: they need a card (replay task cards on for the organization).`
@@ -89980,7 +90106,9 @@ async function runStoredReplays(options, deps) {
89980
90106
  (t) => states.get(t.taskId) === "valid" && t.testFiles.length > 0 && t.testFiles.every(safeTestFile) && SHA.test(t.baseSha) && SHA.test(t.targetSha)
89981
90107
  );
89982
90108
  const notValid = mine.length - valid.length;
89983
- const arms = options.arms;
90109
+ const arms = [...options.arms].sort(
90110
+ (a, b) => Number(a !== "baseline") - Number(b !== "baseline")
90111
+ );
89984
90112
  let judgePrompt;
89985
90113
  const promptForJudge = async () => {
89986
90114
  if (judgePrompt === void 0)
@@ -90110,6 +90238,7 @@ async function runStoredReplays(options, deps) {
90110
90238
  `\u2026 ${label}: the tests use ${task.testInterface.length} module(s) the start lacks; named in the prompt`
90111
90239
  );
90112
90240
  let targetSent = false;
90241
+ let baselineChange = null;
90113
90242
  for (const arm of arms) {
90114
90243
  if (!options.force && alreadyMeasured(
90115
90244
  task.measured,
@@ -90172,6 +90301,7 @@ async function runStoredReplays(options, deps) {
90172
90301
  changed = await changedFiles(deps, dir, task.baseSha);
90173
90302
  agentDiff = await agentDiffOf(deps, dir, task.baseSha);
90174
90303
  if (arm === "haansi") change = judgeChange(agentDiff);
90304
+ else baselineChange = judgeChange(agentDiff);
90175
90305
  },
90176
90306
  {
90177
90307
  HAANSI_REPLAY_MCP_CONFIG: configPath,
@@ -90195,6 +90325,7 @@ async function runStoredReplays(options, deps) {
90195
90325
  card: cardPrompt(task, null),
90196
90326
  calls,
90197
90327
  change,
90328
+ baseline: baselineChange,
90198
90329
  prompt: await promptForJudge()
90199
90330
  })
90200
90331
  };
@@ -90379,7 +90510,7 @@ function parseReplayArgs(argv) {
90379
90510
  testCmd: "",
90380
90511
  setupCmd: null,
90381
90512
  repoCommands: false,
90382
- attempts: 3,
90513
+ attempts: 2,
90383
90514
  arms: [...ARMS],
90384
90515
  limit: null,
90385
90516
  // 20 minutes an attempt: the longest replays (90 min) were stuck.
@@ -90626,6 +90757,13 @@ async function replayArm(deps, options, task, arm, promptOf, inspect, agentEnv =
90626
90757
  `Haansi's servers did not load for the agent (${down.join(", ")}); not graded, run it again`
90627
90758
  );
90628
90759
  }
90760
+ if (arm === "baseline") {
90761
+ const loaded = haansiServersLoaded(agent.output) ?? [];
90762
+ if (loaded.length)
90763
+ throw new Error(
90764
+ `the baseline's agent loaded Haansi's servers (${loaded.join(", ")}): it did not run without Haansi; not graded. Add --strict-mcp-config to a Claude Code command.`
90765
+ );
90766
+ }
90629
90767
  const uses = toolUsesOf(agent.output);
90630
90768
  if (uses) deps.log(`\u2026 ${label}: tools used: ${toolUsesLine(uses)}`);
90631
90769
  const gradeSha = task.testNames?.length ? task.baseSha : task.targetSha;
@@ -91004,7 +91142,7 @@ var init_replay = __esm({
91004
91142
  OUTPUT_HEAD_CHARS = 4e4;
91005
91143
  OUTPUT_TAIL_CHARS = 2e5;
91006
91144
  USAGE2 = `Usage: haansi replay run --agent-cmd "<cmd>" --test-cmd "<cmd>"
91007
- [--setup-cmd "<cmd>"] [--attempts 3] [--arms baseline,haansi] [--limit n]
91145
+ [--setup-cmd "<cmd>"] [--attempts 2] [--arms baseline,haansi] [--limit n]
91008
91146
  [--timeout-min 20] [--agent-name <name>] [--model <name>]
91009
91147
  [--judge-cmd "<cmd>"]
91010
91148
  [--run-ref <url>] [--dry-run] [--repo-commands] [--no-diffs]
@@ -91070,7 +91208,7 @@ Run from a clone of the repository. Example (GitHub Actions):
91070
91208
  haansi replay run --setup-cmd 'npm ci' \\
91071
91209
  --container node:22 --container-env ANTHROPIC_API_KEY \\
91072
91210
  --container-setup 'npm install -g haansi @anthropic-ai/claude-code' \\
91073
- --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,mcp__haansi-incidents' \\
91211
+ --agent-cmd 'claude -p "$HAANSI_REPLAY_PROMPT" --output-format stream-json --verbose --permission-mode acceptEdits --mcp-config "$HAANSI_REPLAY_MCP_CONFIG" --strict-mcp-config --allowedTools mcp__haansi-solutions,mcp__haansi-exchange,mcp__haansi-digests,mcp__haansi-onboarding,mcp__haansi-skills,mcp__haansi-incidents' \\
91074
91212
  --test-cmd 'npx vitest run $HAANSI_REPLAY_TEST_FILES -t "$HAANSI_REPLAY_TEST_PATTERN"' \\
91075
91213
  --agent-name claude-code --model claude-sonnet-5-5`;
91076
91214
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "haansi",
3
- "version": "0.1.111",
3
+ "version": "0.1.113",
4
4
  "description": "Haansi CLI - Session collector and MCP server for Claude Code & OpenAI Codex",
5
5
  "bin": {
6
6
  "haansi": "./dist/haansi.js"