haansi 0.1.105 → 0.1.107
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.
- package/dist/haansi.js +137 -66
- 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
|
+
version: "0.1.107",
|
|
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_-]+/;
|
|
@@ -60171,7 +60178,7 @@ var init_stdio2 = __esm({
|
|
|
60171
60178
|
function searchSolutionsTool(contextSchema2) {
|
|
60172
60179
|
return {
|
|
60173
60180
|
name: "search_solutions",
|
|
60174
|
-
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. 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.",
|
|
60181
|
+
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.",
|
|
60175
60182
|
inputSchema: {
|
|
60176
60183
|
type: "object",
|
|
60177
60184
|
properties: {
|
|
@@ -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
|
|
86741
|
-
|
|
86742
|
-
|
|
86743
|
-
const
|
|
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
|
-
...
|
|
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
|
-
|
|
86765
|
-
2,
|
|
86766
|
-
|
|
86767
|
-
|
|
86768
|
-
|
|
86769
|
-
|
|
86770
|
-
|
|
86771
|
-
|
|
86772
|
-
|
|
86773
|
-
|
|
86774
|
-
|
|
86775
|
-
|
|
86776
|
-
...ask.
|
|
86777
|
-
|
|
86778
|
-
|
|
86779
|
-
|
|
86780
|
-
|
|
86781
|
-
|
|
86782
|
-
|
|
86783
|
-
|
|
86784
|
-
|
|
86785
|
-
|
|
86786
|
-
|
|
86787
|
-
|
|
86788
|
-
|
|
86789
|
-
|
|
86790
|
-
|
|
86791
|
-
|
|
86792
|
-
|
|
86793
|
-
|
|
86794
|
-
|
|
86795
|
-
|
|
86796
|
-
|
|
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
|
|
|
@@ -89299,6 +89359,7 @@ function visibleAsk(task) {
|
|
|
89299
89359
|
task.card.acceptance,
|
|
89300
89360
|
task.card.area ?? ""
|
|
89301
89361
|
].join("\n");
|
|
89362
|
+
const anchored = (q) => q.trim() ? `${head} ${q}` : "";
|
|
89302
89363
|
let paths;
|
|
89303
89364
|
let queries;
|
|
89304
89365
|
let hints;
|
|
@@ -89312,10 +89373,12 @@ function visibleAsk(task) {
|
|
|
89312
89373
|
].slice(0, MAX_FAILING_PATHS);
|
|
89313
89374
|
const files = [...new Set(paths.map(baseNameOf))];
|
|
89314
89375
|
const errorLine = errorLineOf(failing.output);
|
|
89376
|
+
const titles = failing.tests.slice(0, FAILING_QUERIES).map(titleOfTest);
|
|
89315
89377
|
queries = [
|
|
89316
|
-
|
|
89317
|
-
errorLine ?? "",
|
|
89318
|
-
|
|
89378
|
+
anchored(titles[0] ?? ""),
|
|
89379
|
+
anchored(errorLine ?? ""),
|
|
89380
|
+
...titles.slice(1).map(anchored),
|
|
89381
|
+
anchored(files.slice(0, 6).join(" "))
|
|
89319
89382
|
];
|
|
89320
89383
|
hints = {
|
|
89321
89384
|
failingTests: failing.tests,
|
|
@@ -89330,8 +89393,8 @@ function visibleAsk(task) {
|
|
|
89330
89393
|
const names = iface.flatMap((e) => e.names);
|
|
89331
89394
|
queries = [
|
|
89332
89395
|
head,
|
|
89333
|
-
...(task.kind !== "recovery" ? task.testTitles ?? [] : []).slice(0, TITLE_QUERIES).map(titleOfTest),
|
|
89334
|
-
names.join(" ")
|
|
89396
|
+
...(task.kind !== "recovery" ? task.testTitles ?? [] : []).slice(0, TITLE_QUERIES).map((t) => anchored(titleOfTest(t))),
|
|
89397
|
+
anchored(names.join(" "))
|
|
89335
89398
|
];
|
|
89336
89399
|
hints = { files: paths, names: [...new Set(names)] };
|
|
89337
89400
|
}
|
|
@@ -89494,8 +89557,8 @@ var init_replay_context = __esm({
|
|
|
89494
89557
|
init_replay_diff();
|
|
89495
89558
|
init_replay_scale();
|
|
89496
89559
|
init_replay_spec();
|
|
89497
|
-
CONTEXT_CHECK_VERSION =
|
|
89498
|
-
QUERY_CHARS2 =
|
|
89560
|
+
CONTEXT_CHECK_VERSION = 5;
|
|
89561
|
+
QUERY_CHARS2 = 300;
|
|
89499
89562
|
ERROR_CHARS = 1e3;
|
|
89500
89563
|
MAX_PATHS = 20;
|
|
89501
89564
|
HEAD_CHARS = 120;
|
|
@@ -89574,9 +89637,17 @@ function haansiSection(tools, hint = null) {
|
|
|
89574
89637
|
return [
|
|
89575
89638
|
"## Your organization's knowledge (Haansi)",
|
|
89576
89639
|
"",
|
|
89577
|
-
"These MCP servers hold what your organization learned before this task began
|
|
89640
|
+
"These MCP servers hold what your organization learned before this task began. They are read-only here.",
|
|
89641
|
+
"",
|
|
89642
|
+
"Start here, before you read or change any code, and search again when you get stuck:",
|
|
89643
|
+
"",
|
|
89644
|
+
"- 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.",
|
|
89645
|
+
"- Team procedures: match_playbook with the task, and search_skills; get_skill loads one.",
|
|
89646
|
+
"- Earlier attempts at the same code: get_prior_attempts with the files you expect to change.",
|
|
89647
|
+
"- Incidents like this one: search_prior_incidents.",
|
|
89648
|
+
"- Recent work, conventions and shared answers: search_digests, search_guides and search_exchange.",
|
|
89578
89649
|
"",
|
|
89579
|
-
"
|
|
89650
|
+
"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
89651
|
"",
|
|
89581
89652
|
...hint ? [HAANSI_HINTS[hint], ""] : [],
|
|
89582
89653
|
...tools.flatMap((s) => [
|
|
@@ -90858,7 +90929,7 @@ Run from a clone of the repository. Example (GitHub Actions):
|
|
|
90858
90929
|
haansi replay run --setup-cmd 'npm ci' \\
|
|
90859
90930
|
--container node:22 --container-env ANTHROPIC_API_KEY \\
|
|
90860
90931
|
--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' \\
|
|
90932
|
+
--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
90933
|
--test-cmd 'npx vitest run $HAANSI_REPLAY_TEST_FILES -t "$HAANSI_REPLAY_TEST_PATTERN"' \\
|
|
90863
90934
|
--agent-name claude-code --model claude-sonnet-5-5`;
|
|
90864
90935
|
}
|