haansi 0.1.105 → 0.1.106

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 +127 -59
  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.105",
98
+ version: "0.1.106",
99
99
  description: "Haansi CLI - Session collector and MCP server for Claude Code & OpenAI Codex",
100
100
  bin: {
101
101
  haansi: "./dist/haansi.js"
@@ -547,10 +547,10 @@ __export(setup_mcp_exports, {
547
547
  });
548
548
  function parseTarget(arg) {
549
549
  if (!arg || arg === "all") return "all";
550
- if (arg === "solutions" || arg === "exchange" || arg === "digests" || arg === "onboarding" || arg === "skills")
550
+ if (arg === "solutions" || arg === "exchange" || arg === "digests" || arg === "onboarding" || arg === "skills" || arg === "incidents")
551
551
  return arg;
552
552
  throw new Error(
553
- `Unknown target: ${arg}. Use one of: solutions, exchange, digests, onboarding, skills, all (default).`
553
+ `Unknown target: ${arg}. Use one of: solutions, exchange, digests, onboarding, skills, incidents, all (default).`
554
554
  );
555
555
  }
556
556
  function httpServerUrl(path2) {
@@ -792,6 +792,13 @@ var init_setup_mcp = __esm({
792
792
  target: "skills",
793
793
  name: "haansi-skills",
794
794
  path: "/api/v1/memory/skills/mcp"
795
+ },
796
+ // Past incidents: what happened, how it was resolved, and what resembles
797
+ // the problem at hand (served as of a replay's start in a replay).
798
+ {
799
+ target: "incidents",
800
+ name: "haansi-incidents",
801
+ path: "/api/v1/memory/processes/incidents/mcp"
795
802
  }
796
803
  ];
797
804
  HSK_BEARER = /Bearer hsk_[A-Za-z0-9_-]+/;
@@ -60235,6 +60242,38 @@ var init_search_solutions_tool = __esm({
60235
60242
  }
60236
60243
  });
60237
60244
 
60245
+ // ../service-capture/agent-sessions/get-solution-tool.ts
60246
+ function getSolutionTool(contextSchema2) {
60247
+ return {
60248
+ name: "get_solution",
60249
+ description: "Read one solution from your organization's knowledge base in full: the problem, the solution, every step with why it was needed, and the files it changed. Pass the id a search_solutions result names (solution:<id>). Search first; open the results that look like your problem.",
60250
+ inputSchema: {
60251
+ type: "object",
60252
+ properties: {
60253
+ id: {
60254
+ type: "string",
60255
+ description: "The solution's id, as a search result names it"
60256
+ },
60257
+ _context: contextSchema2
60258
+ },
60259
+ required: ["id"]
60260
+ }
60261
+ };
60262
+ }
60263
+ function getSolutionPath(id) {
60264
+ const match = typeof id === "string" ? ID.exec(id.trim()) : null;
60265
+ return match ? `/memory/solutions/${match[1].toLowerCase()}` : null;
60266
+ }
60267
+ var ID, NOT_A_SOLUTION_ID, NO_SUCH_SOLUTION;
60268
+ var init_get_solution_tool = __esm({
60269
+ "../service-capture/agent-sessions/get-solution-tool.ts"() {
60270
+ "use strict";
60271
+ ID = /^(?:solution:)?([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})$/i;
60272
+ NOT_A_SOLUTION_ID = "Pass the id a search_solutions result names, e.g. solution:1b2c3d4e-\u2026.";
60273
+ NO_SUCH_SOLUTION = "No such solution: it may have been removed, or it is not one you can read.";
60274
+ }
60275
+ });
60276
+
60238
60277
  // ../../node_modules/depd/index.js
60239
60278
  var require_depd = __commonJS({
60240
60279
  "../../node_modules/depd/index.js"(exports2, module2) {
@@ -84401,6 +84440,7 @@ var init_mcp_server2 = __esm({
84401
84440
  init_stdio2();
84402
84441
  init_entrypoint();
84403
84442
  init_search_solutions_tool();
84443
+ init_get_solution_tool();
84404
84444
  init_types4();
84405
84445
  (0, import_dotenv3.config)({ path: (0, import_path5.resolve)(__dirname, "../../../.env") });
84406
84446
  DEFAULT_API_URL3 = SERVICE_URL_DEFAULTS.haansiApiBaseUrl;
@@ -84438,6 +84478,7 @@ var init_mcp_server2 = __esm({
84438
84478
  server.setRequestHandler(ListToolsRequestSchema, async () => ({
84439
84479
  tools: [
84440
84480
  searchSolutionsTool(contextSchema),
84481
+ getSolutionTool(contextSchema),
84441
84482
  {
84442
84483
  name: "list_recent_solutions",
84443
84484
  description: "List the most recently added distilled paths from the knowledge base.",
@@ -84577,6 +84618,34 @@ var init_mcp_server2 = __esm({
84577
84618
  ]
84578
84619
  };
84579
84620
  }
84621
+ case "get_solution": {
84622
+ const { id, _context } = args;
84623
+ const path2 = getSolutionPath(id);
84624
+ if (!path2) {
84625
+ return {
84626
+ content: [{ type: "text", text: NOT_A_SOLUTION_ID }],
84627
+ isError: true
84628
+ };
84629
+ }
84630
+ const extraHeaders = {};
84631
+ if (_context?.userId) {
84632
+ extraHeaders["X-Session-User-Id"] = String(_context.userId);
84633
+ }
84634
+ if (_context?.orgId) {
84635
+ extraHeaders["X-Session-Org-Id"] = String(_context.orgId);
84636
+ }
84637
+ try {
84638
+ const data = await apiGet2(path2, { extraHeaders });
84639
+ return {
84640
+ content: [{ type: "text", text: data.text ?? NO_SUCH_SOLUTION }]
84641
+ };
84642
+ } catch (err2) {
84643
+ if (err2 instanceof ApiError && err2.status === 404) {
84644
+ return { content: [{ type: "text", text: NO_SUCH_SOLUTION }] };
84645
+ }
84646
+ throw err2;
84647
+ }
84648
+ }
84580
84649
  case "list_recent_solutions": {
84581
84650
  const { limit = 10, _context } = args;
84582
84651
  const n = Math.min(Math.max(1, limit), 50);
@@ -86737,18 +86806,16 @@ async function searchHaansi(session, ask, fetchImpl = fetch) {
86737
86806
  { method: "GET", headers }
86738
86807
  )
86739
86808
  );
86740
- const skillsPath = HTTP_SERVERS.find((s) => s.name === "haansi-skills")?.path;
86741
- const skills2 = skillsPath ? (async () => {
86742
- const url2 = `${base}${skillsPath}`;
86743
- const mcpHeaders = {
86744
- ...headers,
86745
- "Content-Type": "application/json",
86746
- Accept: "application/json, text/event-stream"
86747
- };
86809
+ const mcp = async (server2, calls) => {
86810
+ const path2 = HTTP_SERVERS.find((s) => s.name === server2)?.path;
86811
+ if (!path2 || calls.length === 0) return;
86812
+ const url2 = `${base}${path2}`;
86748
86813
  const rpc = (id, method, params, sid2) => fetchImpl(url2, {
86749
86814
  method: "POST",
86750
86815
  headers: {
86751
- ...mcpHeaders,
86816
+ ...headers,
86817
+ "Content-Type": "application/json",
86818
+ Accept: "application/json, text/event-stream",
86752
86819
  ...sid2 ? { "Mcp-Session-Id": sid2 } : {}
86753
86820
  },
86754
86821
  body: JSON.stringify({ jsonrpc: "2.0", id, method, params })
@@ -86760,50 +86827,42 @@ async function searchHaansi(session, ask, fetchImpl = fetch) {
86760
86827
  });
86761
86828
  if (!init2.ok) return;
86762
86829
  const sid = init2.headers?.get("mcp-session-id") ?? void 0;
86763
- await Promise.allSettled([
86764
- rpc(
86765
- 2,
86766
- "tools/call",
86767
- {
86768
- name: "match_playbook",
86769
- arguments: {
86770
- task: ask.task,
86771
- ...ask.error ? { error: ask.error } : {}
86772
- }
86773
- },
86774
- sid
86775
- ).then((r) => r.text()),
86776
- ...ask.queries[0] ? [
86777
- rpc(
86778
- 3,
86779
- "tools/call",
86780
- {
86781
- name: "search_skills",
86782
- arguments: { query: ask.queries[0], limit: 5 }
86783
- },
86784
- sid
86785
- ).then((r) => r.text().then(rpcResult))
86786
- ] : [],
86787
- ...ask.paths?.length ? [
86788
- rpc(
86789
- 4,
86790
- "tools/call",
86791
- {
86792
- name: "get_prior_attempts",
86793
- arguments: {
86794
- paths: ask.paths,
86795
- ...ask.queries[0] ? { query: ask.queries[0] } : {},
86796
- limit: PRIOR_ATTEMPTS_LIMIT
86797
- }
86798
- },
86799
- sid
86800
- ).then((r) => r.text().then(rpcResult))
86801
- ] : []
86802
- ]);
86803
- })() : Promise.resolve();
86804
- await Promise.allSettled([...solutions, skills2]);
86830
+ await Promise.allSettled(
86831
+ calls.map(
86832
+ (call, i) => rpc(i + 2, "tools/call", call, sid).then(
86833
+ (r) => r.text().then(rpcResult)
86834
+ )
86835
+ )
86836
+ );
86837
+ };
86838
+ const first = ask.queries[0];
86839
+ const searchWith = (name) => first ? [{ name, arguments: { query: first, limit: OTHER_SOURCE_LIMIT } }] : [];
86840
+ const skills2 = mcp("haansi-skills", [
86841
+ {
86842
+ name: "match_playbook",
86843
+ arguments: { task: ask.task, ...ask.error ? { error: ask.error } : {} }
86844
+ },
86845
+ ...first ? [{ name: "search_skills", arguments: { query: first, limit: 5 } }] : [],
86846
+ ...ask.paths?.length ? [
86847
+ {
86848
+ name: "get_prior_attempts",
86849
+ arguments: {
86850
+ paths: ask.paths,
86851
+ ...first ? { query: first } : {},
86852
+ limit: PRIOR_ATTEMPTS_LIMIT
86853
+ }
86854
+ }
86855
+ ] : []
86856
+ ]);
86857
+ const others = [
86858
+ mcp("haansi-exchange", searchWith("search_exchange")),
86859
+ mcp("haansi-digests", searchWith("search_digests")),
86860
+ mcp("haansi-onboarding", searchWith("search_guides")),
86861
+ mcp("haansi-incidents", searchWith("search_prior_incidents"))
86862
+ ];
86863
+ await Promise.allSettled([...solutions, skills2, ...others]);
86805
86864
  }
86806
- var SOLUTIONS_PER_QUERY, MAX_HINT_ITEMS2, MAX_HINT_ITEM_CHARS2, MAX_HINT_ERROR_CHARS2, clipList2, PRIOR_ATTEMPTS_LIMIT;
86865
+ var SOLUTIONS_PER_QUERY, MAX_HINT_ITEMS2, MAX_HINT_ITEM_CHARS2, MAX_HINT_ERROR_CHARS2, clipList2, PRIOR_ATTEMPTS_LIMIT, OTHER_SOURCE_LIMIT;
86807
86866
  var init_replay_fallback = __esm({
86808
86867
  "src/commands/replay-fallback.ts"() {
86809
86868
  "use strict";
@@ -86815,6 +86874,7 @@ var init_replay_fallback = __esm({
86815
86874
  MAX_HINT_ERROR_CHARS2 = 1e3;
86816
86875
  clipList2 = (items) => (items ?? []).map((v) => v.trim().slice(0, MAX_HINT_ITEM_CHARS2)).filter(Boolean).slice(0, MAX_HINT_ITEMS2);
86817
86876
  PRIOR_ATTEMPTS_LIMIT = 3;
86877
+ OTHER_SOURCE_LIMIT = 5;
86818
86878
  }
86819
86879
  });
86820
86880
 
@@ -89494,7 +89554,7 @@ var init_replay_context = __esm({
89494
89554
  init_replay_diff();
89495
89555
  init_replay_scale();
89496
89556
  init_replay_spec();
89497
- CONTEXT_CHECK_VERSION = 3;
89557
+ CONTEXT_CHECK_VERSION = 4;
89498
89558
  QUERY_CHARS2 = 200;
89499
89559
  ERROR_CHARS = 1e3;
89500
89560
  MAX_PATHS = 20;
@@ -89574,9 +89634,17 @@ function haansiSection(tools, hint = null) {
89574
89634
  return [
89575
89635
  "## Your organization's knowledge (Haansi)",
89576
89636
  "",
89577
- "These MCP servers hold what your organization learned before this task began: solutions to past problems, team skills and playbooks, earlier attempts at the same code, digests, onboarding guides and Exchange posts. They are read-only here.",
89637
+ "These MCP servers hold what your organization learned before this task began. They are read-only here.",
89638
+ "",
89639
+ "Start here, before you read or change any code, and search again when you get stuck:",
89640
+ "",
89641
+ "- 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.",
89642
+ "- Team procedures: match_playbook with the task, and search_skills; get_skill loads one.",
89643
+ "- Earlier attempts at the same code: get_prior_attempts with the files you expect to change.",
89644
+ "- Incidents like this one: search_prior_incidents.",
89645
+ "- Recent work, conventions and shared answers: search_digests, search_guides and search_exchange.",
89578
89646
  "",
89579
- "Start here, before you read or change any code: search them for this problem (search_solutions with the problem and its error, match_playbook and search_skills for a team playbook, get_prior_attempts with the files you expect to change), and read what applies. Search again when you get stuck.",
89647
+ "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.",
89580
89648
  "",
89581
89649
  ...hint ? [HAANSI_HINTS[hint], ""] : [],
89582
89650
  ...tools.flatMap((s) => [
@@ -90858,7 +90926,7 @@ Run from a clone of the repository. Example (GitHub Actions):
90858
90926
  haansi replay run --setup-cmd 'npm ci' \\
90859
90927
  --container node:22 --container-env ANTHROPIC_API_KEY \\
90860
90928
  --container-setup 'npm install -g haansi @anthropic-ai/claude-code' \\
90861
- --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' \\
90929
+ --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' \\
90862
90930
  --test-cmd 'npx vitest run $HAANSI_REPLAY_TEST_FILES -t "$HAANSI_REPLAY_TEST_PATTERN"' \\
90863
90931
  --agent-name claude-code --model claude-sonnet-5-5`;
90864
90932
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "haansi",
3
- "version": "0.1.105",
3
+ "version": "0.1.106",
4
4
  "description": "Haansi CLI - Session collector and MCP server for Claude Code & OpenAI Codex",
5
5
  "bin": {
6
6
  "haansi": "./dist/haansi.js"