haansi 0.1.114 → 0.1.116

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 +77 -23
  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.114",
98
+ version: "0.1.116",
99
99
  description: "Haansi CLI - Session collector and MCP server for Claude Code & OpenAI Codex",
100
100
  bin: {
101
101
  haansi: "./dist/haansi.js"
@@ -60289,7 +60289,7 @@ var init_stdio2 = __esm({
60289
60289
  function searchSolutionsTool(contextSchema2) {
60290
60290
  return {
60291
60291
  name: "search_solutions",
60292
- description: "Search previously solved similar questions from your organization's knowledge base. Finds how bugs were fixed, what patterns were used, and past resolutions to similar problems. Results are ranked by a composite of relevance, quality, recency, and verification status. Describe the problem in a sentence in query: a test name, an identifier or a list of file names alone rarely matches; pass those in the structured inputs instead. For a failing test, pass its name in failing_tests and the error line in error. Pass the files you expect to change, or that the failure runs through, in files.",
60292
+ description: "Search previously solved similar questions from your organization's knowledge base. Finds how bugs were fixed, what patterns were used, and past resolutions to similar problems. Results are ranked by a composite of relevance, quality, recency, and verification status. Most are related problems rather than yours: take an idea, step or check only where it fits your change, check it still applies to the code as it is, and say which you used. Describe the problem in a sentence in query: a test name, an identifier or a list of file names alone rarely matches; pass those in the structured inputs instead. For a failing test, pass its name in failing_tests and the error line in error. Pass the files you changed (or will change), or that the failure runs through, in files.",
60293
60293
  inputSchema: {
60294
60294
  type: "object",
60295
60295
  properties: {
@@ -60309,7 +60309,7 @@ function searchSolutionsTool(contextSchema2) {
60309
60309
  description: "Optional. The error line, e.g. the assertion or exception message"
60310
60310
  },
60311
60311
  files: stringList(
60312
- "Optional. File paths you expect to change, or that the failure runs through"
60312
+ "Optional. File paths you changed (or will change), or that the failure runs through"
60313
60313
  ),
60314
60314
  names: stringList(
60315
60315
  "Optional. Identifiers involved: functions, classes, routes, config keys"
@@ -89648,11 +89648,39 @@ function storedScoreOf(task) {
89648
89648
  nearby: task.context?.nearby ?? 0
89649
89649
  };
89650
89650
  }
89651
- function rankFound(tasks, scoreOf) {
89652
- return tasks.map((task) => ({ task, score: scoreOf(task) })).sort(
89653
- (a, b) => b.score.onPoint - a.score.onPoint || b.score.nearby - a.score.nearby || a.task.place - b.task.place
89651
+ function gateTierOf(state, score) {
89652
+ if (state === "found") return "found";
89653
+ if ((state === "missed" || state === "none") && score.nearby > 0)
89654
+ return "nearby";
89655
+ return null;
89656
+ }
89657
+ function rankFound(tasks, scoreOf, tierOf = () => "found") {
89658
+ return tasks.map((task) => ({ task, score: scoreOf(task), tier: tierOf(task) })).sort(
89659
+ (a, b) => Number(a.tier === "nearby") - Number(b.tier === "nearby") || b.score.onPoint - a.score.onPoint || b.score.nearby - a.score.nearby || a.task.place - b.task.place
89654
89660
  ).map((r) => r.task);
89655
89661
  }
89662
+ function agreeOn(a, b, reached) {
89663
+ if (!a.relevantIds) return b;
89664
+ if (!b.relevantIds) return a;
89665
+ const second = new Set(b.relevantIds);
89666
+ const onPoint = a.relevantIds.filter((id) => second.has(id));
89667
+ const agreed = new Set(onPoint);
89668
+ const nearby = [
89669
+ .../* @__PURE__ */ new Set([
89670
+ ...a.nearbyIds ?? [],
89671
+ ...b.nearbyIds ?? [],
89672
+ ...a.relevantIds,
89673
+ ...b.relevantIds
89674
+ ])
89675
+ ].filter((id) => !agreed.has(id));
89676
+ return {
89677
+ relevantIds: onPoint,
89678
+ recallIds: onPoint.filter((id) => !reached.has(id)),
89679
+ nearbyIds: nearby,
89680
+ knowledge: knowledgeOf(onPoint, reached),
89681
+ judgeTag: a.judgeTag
89682
+ };
89683
+ }
89656
89684
  function stateOf(knowledge) {
89657
89685
  if (knowledge === "returned") return "found";
89658
89686
  return knowledge;
@@ -89760,17 +89788,20 @@ async function checkContext(deps, input) {
89760
89788
  filesOfDiff(input.targetText)
89761
89789
  )
89762
89790
  );
89763
- const judged = await judgeRelevance(deps, {
89791
+ const targetChange = input.targetText;
89792
+ const judgeOnce = (n) => judgeRelevance(deps, {
89764
89793
  label,
89765
- taskId: `${task.taskId}-context`,
89794
+ taskId: `${task.taskId}-context-${n}`,
89766
89795
  agentCmd: input.agentCmd,
89767
89796
  timeoutMs: input.timeoutMs,
89768
89797
  card: input.card,
89769
- targetChange: input.targetText,
89798
+ targetChange,
89770
89799
  reached,
89771
89800
  recall,
89772
89801
  prompt: input.prompt
89773
89802
  });
89803
+ const reachedIds = new Set(reached.flatMap((c) => c.returnedIds));
89804
+ const judged = agreeOn(await judgeOnce(1), await judgeOnce(2), reachedIds);
89774
89805
  const state = stateOf(judged.knowledge);
89775
89806
  if (!state || !judged.relevantIds) return null;
89776
89807
  const visible = new Set(reached.flatMap((c) => c.returnedIds));
@@ -89844,29 +89875,41 @@ async function gateOnContext(deps, tasks, options) {
89844
89875
  `The context checks could not be reported (${err2 instanceof Error ? err2.message : String(err2)}); the next run checks them again.`
89845
89876
  );
89846
89877
  }
89847
- const found = [];
89878
+ const scoreOf = (t) => scores.get(t.taskId) ?? { onPoint: 0, nearby: 0 };
89879
+ const tiers = /* @__PURE__ */ new Map();
89848
89880
  let noContext = 0;
89849
89881
  let unknown2 = 0;
89850
89882
  for (const t of tasks) {
89851
89883
  const label = t.name ?? t.taskKey;
89852
89884
  const s = states.get(t.taskId);
89853
- if (s === "found") found.push(t);
89854
- else if (s === "missed" || s === "none") {
89885
+ const tier = gateTierOf(s, scoreOf(t));
89886
+ if (tier) {
89887
+ tiers.set(t.taskId, tier);
89888
+ if (tier === "nearby")
89889
+ deps.log(
89890
+ `nearby ${label}: no on-point context, ${scoreOf(t).nearby} nearby item(s): replayed, read apart`
89891
+ );
89892
+ } else if (s === "missed" || s === "none") {
89855
89893
  noContext += 1;
89856
- deps.log(`skip ${label}: no on-point context Haansi can return (${s})`);
89894
+ deps.log(
89895
+ `skip ${label}: no on-point or nearby context Haansi can return (${s})`
89896
+ );
89857
89897
  } else unknown2 += 1;
89858
89898
  }
89859
89899
  const replay2 = rankFound(
89860
- found,
89861
- (t) => scores.get(t.taskId) ?? { onPoint: 0, nearby: 0 }
89900
+ tasks.filter((t) => tiers.has(t.taskId)),
89901
+ scoreOf,
89902
+ (t) => tiers.get(t.taskId)
89862
89903
  );
89863
- return { replay: replay2, noContext, unknown: unknown2 };
89904
+ const nearby = replay2.filter((t) => tiers.get(t.taskId) === "nearby").length;
89905
+ return { replay: replay2, nearby, noContext, unknown: unknown2 };
89864
89906
  }
89865
89907
  function fromChecks(tasks, limit, shard) {
89908
+ const tierOf = (t) => gateTierOf(t.context?.state, storedScoreOf(t));
89866
89909
  const ready = tasks.filter(
89867
- (t) => !needsCheck(t) && t.context?.state === "found" && t.calibration?.state === "valid" && t.calibration.inputsFingerprint === t.inputsFingerprint
89910
+ (t) => !needsCheck(t) && tierOf(t) !== null && t.calibration?.state === "valid" && t.calibration.inputsFingerprint === t.inputsFingerprint
89868
89911
  );
89869
- const ranked = rankFound(ready, storedScoreOf);
89912
+ const ranked = rankFound(ready, storedScoreOf, (t) => tierOf(t));
89870
89913
  const top = limit ? ranked.slice(0, limit) : ranked;
89871
89914
  const mine = shard && shard.count > 1 ? top.filter((_, i) => i % shard.count === shard.index - 1) : top;
89872
89915
  return { found: ready.length, top, mine };
@@ -89879,7 +89922,7 @@ var init_replay_context = __esm({
89879
89922
  init_replay_diff();
89880
89923
  init_replay_scale();
89881
89924
  init_replay_spec();
89882
- CONTEXT_CHECK_VERSION = 5;
89925
+ CONTEXT_CHECK_VERSION = 6;
89883
89926
  QUERY_CHARS2 = 300;
89884
89927
  ERROR_CHARS = 1e3;
89885
89928
  MAX_PATHS = 20;
@@ -89970,7 +90013,7 @@ function haansiSection(tools, hint = null) {
89970
90013
  "- Incidents like this one: search_prior_incidents.",
89971
90014
  "- Recent work, conventions and shared answers: search_digests, search_guides and search_exchange.",
89972
90015
  "",
89973
- "A test name, an identifier or a list of file names alone rarely finds anything; ask with what is wrong, and pass those in the structured inputs. Read what applies and say which items you used.",
90016
+ "A test name, an identifier or a list of file names alone rarely finds anything; ask with what is wrong, and pass those in the structured inputs. Most of what comes back is a related problem rather than this one: take an idea, step or check only where it fits your change, check it still applies to the code as it is, and say which items you used.",
89974
90017
  "",
89975
90018
  ...hint ? [HAANSI_HINTS[hint], ""] : [],
89976
90019
  ...tools.flatMap((s) => [
@@ -90239,6 +90282,7 @@ async function runStoredReplays(options, deps) {
90239
90282
  );
90240
90283
  };
90241
90284
  let noContext = 0;
90285
+ let nearby = 0;
90242
90286
  let contextUnknown = 0;
90243
90287
  let gated = valid;
90244
90288
  if (options.anyContext) {
@@ -90258,12 +90302,13 @@ async function runStoredReplays(options, deps) {
90258
90302
  prompt: promptForRelevance
90259
90303
  });
90260
90304
  gated = gate.replay;
90305
+ nearby = gate.nearby;
90261
90306
  noContext = gate.noContext;
90262
90307
  contextUnknown = gate.unknown;
90263
90308
  }
90264
90309
  if (options.checkOnly) {
90265
90310
  deps.log(
90266
- `Checked: ${gated.length} found \xB7 ${noContext} with no on-point context \xB7 ${contextUnknown} unknown \xB7 ${notValid} not valid.`
90311
+ `Checked: ${gated.length - nearby} found \xB7 ${nearby} nearby \xB7 ${noContext} with no on-point or nearby context \xB7 ${contextUnknown} unknown \xB7 ${notValid} not valid.`
90267
90312
  );
90268
90313
  return {
90269
90314
  results: [],
@@ -90271,6 +90316,7 @@ async function runStoredReplays(options, deps) {
90271
90316
  noContext,
90272
90317
  contextUnknown,
90273
90318
  found: gated.length,
90319
+ nearby,
90274
90320
  recorded: null
90275
90321
  };
90276
90322
  }
@@ -91128,7 +91174,15 @@ async function replayStored(options, token2, apiUrl2) {
91128
91174
  runCommand
91129
91175
  );
91130
91176
  stop = contained.stop;
91131
- const { results, notValid, noContext, contextUnknown, found, recorded } = await runStoredReplays2(options, {
91177
+ const {
91178
+ results,
91179
+ notValid,
91180
+ noContext,
91181
+ contextUnknown,
91182
+ found,
91183
+ nearby,
91184
+ recorded
91185
+ } = await runStoredReplays2(options, {
91132
91186
  ...contained.deps,
91133
91187
  getReplaySet: (repository) => apiGet3(
91134
91188
  `/memory/replays/tasks?repository=${encodeURIComponent(repository)}`,
@@ -91179,7 +91233,7 @@ async function replayStored(options, token2, apiUrl2) {
91179
91233
  if (options.checkOnly) {
91180
91234
  console.log(
91181
91235
  `
91182
- Context checked: ${found ?? 0} task(s) found \xB7 ${noContext ?? 0} with no on-point context${contextUnknown ? ` \xB7 ${contextUnknown} could not be checked` : ""} \xB7 ${notValid} not valid to replay`
91236
+ Context checked: ${(found ?? 0) - (nearby ?? 0)} task(s) found \xB7 ${nearby ?? 0} with nearby context only \xB7 ${noContext ?? 0} with no on-point or nearby context${contextUnknown ? ` \xB7 ${contextUnknown} could not be checked` : ""} \xB7 ${notValid} not valid to replay`
91183
91237
  );
91184
91238
  return;
91185
91239
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "haansi",
3
- "version": "0.1.114",
3
+ "version": "0.1.116",
4
4
  "description": "Haansi CLI - Session collector and MCP server for Claude Code & OpenAI Codex",
5
5
  "bin": {
6
6
  "haansi": "./dist/haansi.js"