haansi 0.1.98 → 0.1.99

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 +291 -25
  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.98",
98
+ version: "0.1.99",
99
99
  description: "Haansi CLI - Session collector and MCP server for Claude Code & OpenAI Codex",
100
100
  bin: {
101
101
  haansi: "./dist/haansi.js"
@@ -19550,6 +19550,22 @@ var init_exclusions = __esm({
19550
19550
  target_diff_sha: [
19551
19551
  "not-personal",
19552
19552
  "The target commit SHA its stored diff was read at."
19553
+ ],
19554
+ context_state: [
19555
+ "operational",
19556
+ "Closed CHECK vocabulary (found, missed, none)."
19557
+ ],
19558
+ context_relevant_ids: [
19559
+ "join-key",
19560
+ "Ids of Haansi items (solution:\u2026, skill:\u2026) the relevance judge found bear on the task."
19561
+ ],
19562
+ context_judge_tag: [
19563
+ "operational",
19564
+ "The prompt version that judged relevance (replay-relevance-judge-vN)."
19565
+ ],
19566
+ context_inputs_fingerprint: [
19567
+ "derived",
19568
+ "A SHA-256 of the task's inputs; not reversible."
19553
19569
  ]
19554
19570
  }),
19555
19571
  ...exchangeExclusions(INTEL, "problem_family_members", {
@@ -86430,9 +86446,9 @@ function readTools(result) {
86430
86446
  }));
86431
86447
  }
86432
86448
  function firstSentence(text) {
86433
- const flat2 = text.replace(/\s+/g, " ").trim();
86434
- const end = flat2.search(/[.!?](\s|$)/);
86435
- const sentence = end >= 0 ? flat2.slice(0, end + 1) : flat2;
86449
+ const flat3 = text.replace(/\s+/g, " ").trim();
86450
+ const end = flat3.search(/[.!?](\s|$)/);
86451
+ const sentence = end >= 0 ? flat3.slice(0, end + 1) : flat3;
86436
86452
  return sentence.length > 240 ? `${sentence.slice(0, 237)}\u2026` : sentence;
86437
86453
  }
86438
86454
  async function httpTools(fetchImpl, url2, headers) {
@@ -86610,18 +86626,34 @@ async function searchHaansi(session, ask, fetchImpl = fetch) {
86610
86626
  },
86611
86627
  sid
86612
86628
  ).then((r) => r.text().then(rpcResult))
86629
+ ] : [],
86630
+ ...ask.paths?.length ? [
86631
+ rpc(
86632
+ 4,
86633
+ "tools/call",
86634
+ {
86635
+ name: "get_prior_attempts",
86636
+ arguments: {
86637
+ paths: ask.paths,
86638
+ ...ask.queries[0] ? { query: ask.queries[0] } : {},
86639
+ limit: PRIOR_ATTEMPTS_LIMIT
86640
+ }
86641
+ },
86642
+ sid
86643
+ ).then((r) => r.text().then(rpcResult))
86613
86644
  ] : []
86614
86645
  ]);
86615
86646
  })() : Promise.resolve();
86616
86647
  await Promise.allSettled([...solutions, skills2]);
86617
86648
  }
86618
- var SOLUTIONS_PER_QUERY;
86649
+ var SOLUTIONS_PER_QUERY, PRIOR_ATTEMPTS_LIMIT;
86619
86650
  var init_replay_fallback = __esm({
86620
86651
  "src/commands/replay-fallback.ts"() {
86621
86652
  "use strict";
86622
86653
  init_setup_mcp();
86623
86654
  init_replay_preflight();
86624
86655
  SOLUTIONS_PER_QUERY = 5;
86656
+ PRIOR_ATTEMPTS_LIMIT = 3;
86625
86657
  }
86626
86658
  });
86627
86659
 
@@ -87976,6 +88008,187 @@ var init_replay_interface = __esm({
87976
88008
  }
87977
88009
  });
87978
88010
 
88011
+ // src/commands/replay-context.ts
88012
+ function stateOf(knowledge) {
88013
+ if (knowledge === "returned") return "found";
88014
+ return knowledge;
88015
+ }
88016
+ function needsCheck(task) {
88017
+ const c = task.context;
88018
+ return !c || c.state === null || c.stale;
88019
+ }
88020
+ function pathsIn(text) {
88021
+ const found = text.match(/(?<![\w./-])(?:[\w.-]+\/)+[\w.-]*[\w-](?:\.[a-z0-9]+)?/gi) ?? [];
88022
+ return [
88023
+ ...new Set(
88024
+ found.map((p) => p.replace(/^\.\//, "").replace(/[.,:;]+$/, "")).filter(
88025
+ (p) => p.includes("/") && !p.startsWith("/") && !/^https?:/i.test(p) && !p.split("/").some((part) => part === ".." || part === "")
88026
+ )
88027
+ )
88028
+ ];
88029
+ }
88030
+ function visibleAsk(task) {
88031
+ const failing = task.kind === "recovery" ? task.failing : null;
88032
+ const problem = flat2(task.card.problem);
88033
+ const cardText = [
88034
+ task.card.problem,
88035
+ task.card.acceptance,
88036
+ task.card.area ?? ""
88037
+ ].join("\n");
88038
+ const iface = task.testInterface ?? [];
88039
+ const paths = [
88040
+ .../* @__PURE__ */ new Set([...iface.map((e) => e.path), ...pathsIn(cardText)])
88041
+ ].slice(0, MAX_PATHS);
88042
+ const names = iface.flatMap((e) => e.names);
88043
+ const queries = [
88044
+ problem,
88045
+ flat2(`${task.card.area ?? ""} ${flat2(task.card.acceptance)}`),
88046
+ failing?.tests.length ? flat2(failing.tests.join(" ")) : "",
88047
+ names.length ? names.join(" ") : ""
88048
+ ].map((q) => q.slice(0, QUERY_CHARS2).trim()).filter((q, i, all) => q !== "" && all.indexOf(q) === i);
88049
+ const error2 = failing ? [
88050
+ ...failing.tests,
88051
+ ...failing.output ? [failing.output.slice(0, ERROR_CHARS)] : []
88052
+ ].join("\n").trim() || null : null;
88053
+ return {
88054
+ task: [task.card.problem, task.card.acceptance].join("\n\n").slice(0, 1e3),
88055
+ error: error2,
88056
+ queries,
88057
+ ...paths.length ? { paths } : {}
88058
+ };
88059
+ }
88060
+ async function checkContext(deps, input) {
88061
+ const { task, label } = input;
88062
+ if (!deps.searchHaansi) return null;
88063
+ if (input.targetText === null) {
88064
+ deps.log(
88065
+ `\u2026 ${label}: context not checked: the target's change could not be read`
88066
+ );
88067
+ return null;
88068
+ }
88069
+ const search = async (ask) => {
88070
+ const session = {
88071
+ ...await deps.openSession(task.taskId),
88072
+ apiUrl: deps.apiUrl,
88073
+ token: deps.token
88074
+ };
88075
+ await deps.searchHaansi(session, ask).catch(() => void 0);
88076
+ return (await deps.getCalls(session.sessionId)).calls;
88077
+ };
88078
+ const reached = await search(visibleAsk(task));
88079
+ const recall = await search(
88080
+ recallAsk(
88081
+ task.card.problem,
88082
+ input.targetText,
88083
+ filesOfDiff(input.targetText)
88084
+ )
88085
+ );
88086
+ const judged = await judgeRelevance(deps, {
88087
+ label,
88088
+ taskId: `${task.taskId}-context`,
88089
+ agentCmd: input.agentCmd,
88090
+ timeoutMs: input.timeoutMs,
88091
+ card: input.card,
88092
+ targetChange: input.targetText,
88093
+ reached,
88094
+ recall,
88095
+ prompt: input.prompt
88096
+ });
88097
+ const state = stateOf(judged.knowledge);
88098
+ if (!state || !judged.relevantIds) return null;
88099
+ return {
88100
+ taskId: task.taskId,
88101
+ inputsFingerprint: task.inputsFingerprint,
88102
+ state,
88103
+ relevantIds: judged.relevantIds,
88104
+ judgeTag: judged.judgeTag
88105
+ };
88106
+ }
88107
+ async function gateOnContext(deps, tasks, options) {
88108
+ const states = /* @__PURE__ */ new Map();
88109
+ const checks = [];
88110
+ for (const t of tasks)
88111
+ if (!needsCheck(t)) states.set(t.taskId, t.context.state);
88112
+ const found = () => [...states.values()].filter((s) => s === "found").length;
88113
+ const toCheck = tasks.filter((t) => needsCheck(t));
88114
+ await runPool(toCheck, options.concurrency, async (task) => {
88115
+ if (options.limit && found() >= options.limit) return;
88116
+ const label = task.name ?? task.taskKey;
88117
+ try {
88118
+ await options.prepare?.(task);
88119
+ const check3 = await checkContext(deps, {
88120
+ task,
88121
+ label,
88122
+ card: options.cardOf(task),
88123
+ targetText: await options.targetOf(task),
88124
+ agentCmd: options.agentCmd,
88125
+ timeoutMs: options.timeoutMs,
88126
+ prompt: await options.prompt()
88127
+ });
88128
+ states.set(task.taskId, check3?.state ?? null);
88129
+ if (!check3) {
88130
+ deps.log(
88131
+ `context unknown ${label}: the relevance judge gave no verdict`
88132
+ );
88133
+ return;
88134
+ }
88135
+ checks.push(check3);
88136
+ const n = check3.relevantIds.length;
88137
+ deps.log(
88138
+ `context ${check3.state.padEnd(6)} ${label}${n ? ` (${n} relevant item${n === 1 ? "" : "s"})` : ""}`
88139
+ );
88140
+ } catch (err2) {
88141
+ states.set(task.taskId, null);
88142
+ deps.log(
88143
+ `context unknown ${label}: ${err2 instanceof Error ? err2.message : String(err2)}`
88144
+ );
88145
+ }
88146
+ });
88147
+ if (!options.dryRun && checks.length && deps.reportContext)
88148
+ for (let i = 0; i < checks.length; i += CONTEXT_REPORT_CHUNK)
88149
+ try {
88150
+ const out = await deps.reportContext({
88151
+ results: checks.slice(i, i + CONTEXT_REPORT_CHUNK)
88152
+ });
88153
+ if (out.refused.length)
88154
+ deps.log(
88155
+ `Haansi did not record ${out.refused.length} context check(s): their task's inputs changed during the run.`
88156
+ );
88157
+ } catch (err2) {
88158
+ deps.log(
88159
+ `The context checks could not be reported (${err2 instanceof Error ? err2.message : String(err2)}); the next run checks them again.`
88160
+ );
88161
+ }
88162
+ const replay2 = [];
88163
+ let noContext = 0;
88164
+ let unknown2 = 0;
88165
+ for (const t of tasks) {
88166
+ const label = t.name ?? t.taskKey;
88167
+ if (!states.has(t.taskId)) continue;
88168
+ const s = states.get(t.taskId);
88169
+ if (s === "found") replay2.push(t);
88170
+ else if (s === "missed" || s === "none") {
88171
+ noContext += 1;
88172
+ deps.log(`skip ${label}: no relevant context Haansi can return (${s})`);
88173
+ } else unknown2 += 1;
88174
+ }
88175
+ return { replay: replay2, noContext, unknown: unknown2 };
88176
+ }
88177
+ var QUERY_CHARS2, ERROR_CHARS, MAX_PATHS, CONTEXT_REPORT_CHUNK, flat2;
88178
+ var init_replay_context = __esm({
88179
+ "src/commands/replay-context.ts"() {
88180
+ "use strict";
88181
+ init_replay_relevance();
88182
+ init_replay_diff();
88183
+ init_replay_scale();
88184
+ QUERY_CHARS2 = 200;
88185
+ ERROR_CHARS = 1e3;
88186
+ MAX_PATHS = 20;
88187
+ CONTEXT_REPORT_CHUNK = 100;
88188
+ flat2 = (text) => text.replace(/\s+/g, " ").trim();
88189
+ }
88190
+ });
88191
+
87979
88192
  // src/commands/replay-tasks.ts
87980
88193
  var replay_tasks_exports = {};
87981
88194
  __export(replay_tasks_exports, {
@@ -88023,8 +88236,8 @@ function fenced(text) {
88023
88236
  return [fence, text, fence];
88024
88237
  }
88025
88238
  function listItem(name) {
88026
- const flat2 = name.replace(/[\u0000-\u001f\u007f]+/g, " ").trim();
88027
- return `- \`${flat2.replace(/`/g, "'")}\``;
88239
+ const flat3 = name.replace(/[\u0000-\u001f\u007f]+/g, " ").trim();
88240
+ return `- \`${flat3.replace(/`/g, "'")}\``;
88028
88241
  }
88029
88242
  function haansiSection(tools) {
88030
88243
  return [
@@ -88201,7 +88414,6 @@ async function runStoredReplays(options, deps) {
88201
88414
  );
88202
88415
  const notValid = mine.length - valid.length;
88203
88416
  const arms = options.arms;
88204
- const chosen = options.limit ? valid.slice(0, options.limit) : valid;
88205
88417
  let judgePrompt;
88206
88418
  const promptForJudge = async () => {
88207
88419
  if (judgePrompt === void 0)
@@ -88214,6 +88426,48 @@ async function runStoredReplays(options, deps) {
88214
88426
  relevancePrompt = deps.getRelevancePrompt ? await deps.getRelevancePrompt().catch(() => null) : null;
88215
88427
  return relevancePrompt;
88216
88428
  };
88429
+ const targets = /* @__PURE__ */ new Map();
88430
+ const targetOf = (task) => {
88431
+ let t = targets.get(task.taskId);
88432
+ if (!t) {
88433
+ t = referenceDiffOf(deps, task).catch(() => null);
88434
+ targets.set(task.taskId, t);
88435
+ }
88436
+ return t;
88437
+ };
88438
+ const interfaceOf = async (task) => {
88439
+ if (task.testInterface !== void 0) return;
88440
+ task.testInterface = !testNamesOf(task).length && task.baseSha && task.targetSha ? await testInterfaceOf(deps.showFile, {
88441
+ baseSha: task.baseSha,
88442
+ targetSha: task.targetSha,
88443
+ testFiles: task.testFiles
88444
+ }).catch(() => []) : [];
88445
+ };
88446
+ let noContext = 0;
88447
+ let contextUnknown = 0;
88448
+ let gated = valid;
88449
+ if (options.anyContext) {
88450
+ if (valid.length)
88451
+ deps.log(
88452
+ "--any-context: replaying valid tasks without the context check."
88453
+ );
88454
+ } else if (valid.length) {
88455
+ const gate = await gateOnContext(deps, valid, {
88456
+ agentCmd: options.agentCmd,
88457
+ timeoutMs: options.timeoutMs,
88458
+ concurrency: options.concurrency ?? 1,
88459
+ limit: options.limit,
88460
+ dryRun: options.dryRun,
88461
+ cardOf: (task) => cardPrompt(task, null),
88462
+ targetOf,
88463
+ prepare: interfaceOf,
88464
+ prompt: promptForRelevance
88465
+ });
88466
+ gated = gate.replay;
88467
+ noContext = gate.noContext;
88468
+ contextUnknown = gate.unknown;
88469
+ }
88470
+ const chosen = options.limit ? gated.slice(0, options.limit) : gated;
88217
88471
  const results = [];
88218
88472
  let recorded = 0;
88219
88473
  let pending = [];
@@ -88249,19 +88503,13 @@ async function runStoredReplays(options, deps) {
88249
88503
  testFiles: task.testFiles,
88250
88504
  testNames: testNamesOf(task)
88251
88505
  };
88252
- const targetText = await referenceDiffOf(deps, task).catch(() => null);
88506
+ const targetText = await targetOf(task);
88253
88507
  const targetChanges = targetText === null ? null : parseDiff(targetText);
88254
- if (!asTask.testNames?.length && task.baseSha && task.targetSha) {
88255
- task.testInterface = await testInterfaceOf(deps.showFile, {
88256
- baseSha: task.baseSha,
88257
- targetSha: task.targetSha,
88258
- testFiles: task.testFiles
88259
- }).catch(() => []);
88260
- if (task.testInterface.length)
88261
- deps.log(
88262
- `\u2026 ${label}: the tests use ${task.testInterface.length} module(s) the start lacks; named in the prompt`
88263
- );
88264
- }
88508
+ await interfaceOf(task);
88509
+ if (task.testInterface?.length)
88510
+ deps.log(
88511
+ `\u2026 ${label}: the tests use ${task.testInterface.length} module(s) the start lacks; named in the prompt`
88512
+ );
88265
88513
  let targetSent = false;
88266
88514
  for (const arm of arms) {
88267
88515
  if (!options.force && alreadyMeasured(
@@ -88439,10 +88687,11 @@ async function runStoredReplays(options, deps) {
88439
88687
  }
88440
88688
  };
88441
88689
  await runPool(chosen, options.concurrency ?? 1, replayOne);
88690
+ const counts = { notValid, noContext, contextUnknown };
88442
88691
  if (options.dryRun || results.length === 0)
88443
- return { results, notValid, recorded: null };
88692
+ return { results, ...counts, recorded: null };
88444
88693
  if (pending.length) await report(pending);
88445
- return { results, notValid, recorded };
88694
+ return { results, ...counts, recorded };
88446
88695
  }
88447
88696
  function haansiUseOf(calls) {
88448
88697
  return {
@@ -88471,6 +88720,7 @@ var init_replay_tasks = __esm({
88471
88720
  init_replay();
88472
88721
  init_replay_scale();
88473
88722
  init_replay_interface();
88723
+ init_replay_context();
88474
88724
  FEEDBACK_HEADER = "Your previous attempt did not pass the tests. Their output ends with:";
88475
88725
  REPORT_CHUNK2 = 200;
88476
88726
  REPORT_CHARS = 4e6;
@@ -88551,6 +88801,7 @@ function parseReplayArgs(argv) {
88551
88801
  else if (a === "--repo-commands") options.repoCommands = true;
88552
88802
  else if (takeScaleArg(a, next, scale, errors)) continue;
88553
88803
  else if (a === "--force") options.force = true;
88804
+ else if (a === "--any-context") options.anyContext = true;
88554
88805
  else if (a === "--max-hours") options.maxHours = Number(next());
88555
88806
  else if (takeContainerArg(a, next, options.container, errors)) continue;
88556
88807
  else if (a === "--arms")
@@ -88979,7 +89230,7 @@ async function replayStored(options, token2, apiUrl2) {
88979
89230
  runCommand
88980
89231
  );
88981
89232
  stop = contained.stop;
88982
- const { results, notValid, recorded } = await runStoredReplays2(options, {
89233
+ const { results, notValid, noContext, contextUnknown, recorded } = await runStoredReplays2(options, {
88983
89234
  ...contained.deps,
88984
89235
  getReplaySet: (repository) => apiGet3(
88985
89236
  `/memory/replays/tasks?repository=${encodeURIComponent(repository)}`,
@@ -88998,6 +89249,12 @@ async function replayStored(options, token2, apiUrl2) {
88998
89249
  token2,
88999
89250
  apiUrl2
89000
89251
  ),
89252
+ reportContext: async (body) => await apiPost2(
89253
+ "/memory/replays/tasks/context",
89254
+ body,
89255
+ token2,
89256
+ apiUrl2
89257
+ ),
89001
89258
  env: process.env,
89002
89259
  cliVersion: cliVersion2(),
89003
89260
  preflight: (session) => preflightHaansi(session),
@@ -89027,7 +89284,7 @@ async function replayStored(options, token2, apiUrl2) {
89027
89284
  };
89028
89285
  console.log(
89029
89286
  `
89030
- Baseline: ${arm("baseline")} passed \xB7 With Haansi: ${arm("haansi")} passed \xB7 ${notValid} task(s) not valid to replay`
89287
+ Baseline: ${arm("baseline")} passed \xB7 With Haansi: ${arm("haansi")} passed \xB7 ${notValid} task(s) not valid to replay \xB7 ${noContext ?? 0} skipped with no relevant context${contextUnknown ? ` \xB7 ${contextUnknown} whose context could not be checked` : ""}`
89031
89288
  );
89032
89289
  console.log(
89033
89290
  recorded === null ? options.dryRun ? "Dry run: nothing reported." : "Nothing to report." : `Reported ${recorded} result(s) to Haansi.`
@@ -89066,7 +89323,7 @@ var init_replay = __esm({
89066
89323
  [--setup-cmd "<cmd>"] [--attempts 3] [--arms baseline,haansi] [--limit n]
89067
89324
  [--timeout-min 20] [--agent-name <name>] [--model <name>]
89068
89325
  [--run-ref <url>] [--dry-run] [--repo-commands] [--no-diffs]
89069
- [--shard i/n] [--concurrency k] [--force] [--max-hours h]
89326
+ [--shard i/n] [--concurrency k] [--force] [--max-hours h] [--any-context]
89070
89327
  [--setup-cache <files> --setup-cache-path <paths> [--setup-cache-dir <dir>]]
89071
89328
  [--container <image> [--container-setup "<cmd>"] [--container-env NAME]...]
89072
89329
 
@@ -89090,6 +89347,15 @@ package-lock.json --setup-cache-path '**/node_modules' keeps the setup's output
89090
89347
  (every workspace's node_modules) per lockfile (in ~/.cache/haansi-replay, or --setup-cache-dir) and restores
89091
89348
  it instead of running the setup again; not with --container.
89092
89349
 
89350
+ Only tasks Haansi holds relevant context for are replayed. Before any agent
89351
+ runs, each valid task is checked: Haansi is searched with only what the agent
89352
+ sees at the task's start (its card, a bug fix's failing tests, what its tests
89353
+ import, the paths the card names), and the relevance judge (your agent
89354
+ command, once per task checked) says whether anything relevant came back.
89355
+ A task with nothing relevant Haansi can return is skipped, and checked again
89356
+ once the organization gains new Haansi content. --any-context replays every
89357
+ valid task without the check (diagnostics).
89358
+
89093
89359
  --repo-commands uses the setup and test commands an org owner or admin saved for the
89094
89360
  repository in Haansi (Impact \u2192 Replays) for any not given here.
89095
89361
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "haansi",
3
- "version": "0.1.98",
3
+ "version": "0.1.99",
4
4
  "description": "Haansi CLI - Session collector and MCP server for Claude Code & OpenAI Codex",
5
5
  "bin": {
6
6
  "haansi": "./dist/haansi.js"