haansi 0.1.18 → 0.1.19

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 +84 -37
  2. package/package.json +1 -1
package/dist/haansi.js CHANGED
@@ -39,7 +39,7 @@ var require_package = __commonJS({
39
39
  "package.json"(exports2, module2) {
40
40
  module2.exports = {
41
41
  name: "haansi",
42
- version: "0.1.18",
42
+ version: "0.1.19",
43
43
  description: "Haansi CLI - Session collector and MCP server for Claude Code",
44
44
  bin: {
45
45
  haansi: "./dist/haansi.js"
@@ -57218,7 +57218,26 @@ function resolveHaansiBin() {
57218
57218
  }
57219
57219
  return "haansi";
57220
57220
  }
57221
- async function setupMcp() {
57221
+ function resolveToken3() {
57222
+ if (process.env.HAANSI_TOKEN) return process.env.HAANSI_TOKEN;
57223
+ if ((0, import_node_fs3.existsSync)(CREDENTIALS_FILE5)) {
57224
+ try {
57225
+ const creds = JSON.parse((0, import_node_fs3.readFileSync)(CREDENTIALS_FILE5, "utf-8"));
57226
+ if (typeof creds.token === "string" && creds.token) return creds.token;
57227
+ } catch {
57228
+ }
57229
+ }
57230
+ return null;
57231
+ }
57232
+ function parseTarget(arg) {
57233
+ if (!arg || arg === "all") return "all";
57234
+ if (arg === "solutions" || arg === "exchange") return arg;
57235
+ throw new Error(
57236
+ `Unknown target: ${arg}. Use one of: solutions, exchange, all (default).`
57237
+ );
57238
+ }
57239
+ async function setupMcp(targetArg) {
57240
+ const target = parseTarget(targetArg);
57222
57241
  let config6 = {};
57223
57242
  if ((0, import_node_fs3.existsSync)(CLAUDE_JSON)) {
57224
57243
  try {
@@ -57229,22 +57248,44 @@ async function setupMcp() {
57229
57248
  );
57230
57249
  }
57231
57250
  }
57232
- if (!config6.mcpServers) {
57233
- config6.mcpServers = {};
57251
+ if (!config6.mcpServers) config6.mcpServers = {};
57252
+ const installed = [];
57253
+ const warnings = [];
57254
+ if (target === "all" || target === "solutions") {
57255
+ const haansiBin = resolveHaansiBin();
57256
+ config6.mcpServers["haansi-solutions"] = {
57257
+ command: haansiBin,
57258
+ args: ["mcp-server"]
57259
+ };
57260
+ installed.push(`haansi-solutions (stdio \u2192 ${haansiBin} mcp-server)`);
57261
+ }
57262
+ if (target === "all" || target === "exchange") {
57263
+ const token = resolveToken3();
57264
+ if (!token) {
57265
+ const msg = "haansi-exchange not registered: no token found. Run `haansi auth login` first, or set HAANSI_TOKEN.";
57266
+ if (target === "exchange") {
57267
+ console.error(msg);
57268
+ process.exit(1);
57269
+ }
57270
+ warnings.push(msg);
57271
+ } else {
57272
+ const apiUrl = process.env.HAANSI_API_URL ?? DEFAULT_API_URL5;
57273
+ const exchangeUrl = `${apiUrl.replace(/\/+$/, "")}/api/v1/mcp/exchange`;
57274
+ config6.mcpServers["haansi-exchange"] = {
57275
+ type: "http",
57276
+ url: exchangeUrl,
57277
+ headers: { Authorization: `Bearer ${token}` }
57278
+ };
57279
+ installed.push(`haansi-exchange (http \u2192 ${exchangeUrl})`);
57280
+ }
57234
57281
  }
57235
- const haansiBin = resolveHaansiBin();
57236
- config6.mcpServers["haansi-solutions"] = {
57237
- command: haansiBin,
57238
- args: ["mcp-server"]
57239
- };
57240
57282
  (0, import_node_fs3.writeFileSync)(CLAUDE_JSON, JSON.stringify(config6, null, 2) + "\n", "utf-8");
57241
- console.log(`MCP server configured in ${CLAUDE_JSON}`);
57242
- console.log(` command: ${haansiBin} mcp-server`);
57243
- console.log(
57244
- "\nRestart Claude Code to activate the haansi-solutions MCP server."
57245
- );
57283
+ console.log(`MCP servers configured in ${CLAUDE_JSON}`);
57284
+ for (const entry of installed) console.log(` \u2022 ${entry}`);
57285
+ for (const w of warnings) console.log(` ! ${w}`);
57286
+ console.log("\nRestart Claude Code to activate the changes.");
57246
57287
  }
57247
- var import_node_fs3, import_node_path3, import_node_os3, import_node_child_process2, CLAUDE_JSON;
57288
+ var import_node_fs3, import_node_path3, import_node_os3, import_node_child_process2, CLAUDE_JSON, CREDENTIALS_FILE5, DEFAULT_API_URL5;
57248
57289
  var init_setup_mcp = __esm({
57249
57290
  "src/commands/setup-mcp.ts"() {
57250
57291
  "use strict";
@@ -57253,6 +57294,8 @@ var init_setup_mcp = __esm({
57253
57294
  import_node_os3 = require("node:os");
57254
57295
  import_node_child_process2 = require("node:child_process");
57255
57296
  CLAUDE_JSON = (0, import_node_path3.join)((0, import_node_os3.homedir)(), ".claude.json");
57297
+ CREDENTIALS_FILE5 = (0, import_node_path3.join)((0, import_node_os3.homedir)(), ".haansi", "credentials.json");
57298
+ DEFAULT_API_URL5 = "https://api.haansi.co";
57256
57299
  }
57257
57300
  });
57258
57301
 
@@ -57355,11 +57398,11 @@ var config_exports = {};
57355
57398
  __export(config_exports, {
57356
57399
  config: () => config5
57357
57400
  });
57358
- function resolveToken3() {
57401
+ function resolveToken4() {
57359
57402
  if (process.env.HAANSI_TOKEN) return process.env.HAANSI_TOKEN;
57360
- if ((0, import_node_fs5.existsSync)(CREDENTIALS_FILE5)) {
57403
+ if ((0, import_node_fs5.existsSync)(CREDENTIALS_FILE6)) {
57361
57404
  try {
57362
- const creds = JSON.parse((0, import_node_fs5.readFileSync)(CREDENTIALS_FILE5, "utf-8"));
57405
+ const creds = JSON.parse((0, import_node_fs5.readFileSync)(CREDENTIALS_FILE6, "utf-8"));
57363
57406
  if (creds.token) return creds.token;
57364
57407
  } catch (err) {
57365
57408
  console.error("Failed to read credentials file:", err);
@@ -57368,7 +57411,7 @@ function resolveToken3() {
57368
57411
  return null;
57369
57412
  }
57370
57413
  async function config5(args) {
57371
- const token = resolveToken3();
57414
+ const token = resolveToken4();
57372
57415
  if (!token) {
57373
57416
  console.error(
57374
57417
  "Error: No token found. Run `haansi init` or set HAANSI_TOKEN."
@@ -57376,7 +57419,7 @@ async function config5(args) {
57376
57419
  process.exit(1);
57377
57420
  return;
57378
57421
  }
57379
- const apiUrl = process.env.HAANSI_API_URL ?? DEFAULT_API_URL5;
57422
+ const apiUrl = process.env.HAANSI_API_URL ?? DEFAULT_API_URL6;
57380
57423
  const subcommand = args[0];
57381
57424
  if (subcommand === "get") {
57382
57425
  const key = args[1];
@@ -57451,15 +57494,15 @@ Supported keys:
57451
57494
  if (subcommand !== void 0) process.exit(1);
57452
57495
  }
57453
57496
  }
57454
- var import_node_fs5, import_node_path5, import_node_os5, DEFAULT_API_URL5, CREDENTIALS_FILE5, VALID_SESSION_MODES;
57497
+ var import_node_fs5, import_node_path5, import_node_os5, DEFAULT_API_URL6, CREDENTIALS_FILE6, VALID_SESSION_MODES;
57455
57498
  var init_config = __esm({
57456
57499
  "src/commands/config.ts"() {
57457
57500
  "use strict";
57458
57501
  import_node_fs5 = require("node:fs");
57459
57502
  import_node_path5 = require("node:path");
57460
57503
  import_node_os5 = require("node:os");
57461
- DEFAULT_API_URL5 = "https://api.haansi.co";
57462
- CREDENTIALS_FILE5 = (0, import_node_path5.join)((0, import_node_os5.homedir)(), ".haansi", "credentials.json");
57504
+ DEFAULT_API_URL6 = "https://api.haansi.co";
57505
+ CREDENTIALS_FILE6 = (0, import_node_path5.join)((0, import_node_os5.homedir)(), ".haansi", "credentials.json");
57463
57506
  VALID_SESSION_MODES = ["private", "org"];
57464
57507
  }
57465
57508
  });
@@ -57471,11 +57514,11 @@ __export(list_exports, {
57471
57514
  saveKnowledge: () => saveKnowledge,
57472
57515
  searchKnowledge: () => searchKnowledge
57473
57516
  });
57474
- function resolveToken4() {
57517
+ function resolveToken5() {
57475
57518
  if (process.env.HAANSI_TOKEN) return process.env.HAANSI_TOKEN;
57476
- if ((0, import_node_fs6.existsSync)(CREDENTIALS_FILE6)) {
57519
+ if ((0, import_node_fs6.existsSync)(CREDENTIALS_FILE7)) {
57477
57520
  try {
57478
- const creds = JSON.parse((0, import_node_fs6.readFileSync)(CREDENTIALS_FILE6, "utf-8"));
57521
+ const creds = JSON.parse((0, import_node_fs6.readFileSync)(CREDENTIALS_FILE7, "utf-8"));
57479
57522
  if (creds.token) return creds.token;
57480
57523
  } catch (err) {
57481
57524
  console.error("Failed to read credentials file:", err);
@@ -57509,8 +57552,8 @@ async function apiPost2(path, body, token, apiUrl) {
57509
57552
  return response.json();
57510
57553
  }
57511
57554
  async function list(options) {
57512
- const apiUrl = process.env.HAANSI_API_URL ?? DEFAULT_API_URL6;
57513
- const token = resolveToken4();
57555
+ const apiUrl = process.env.HAANSI_API_URL ?? DEFAULT_API_URL7;
57556
+ const token = resolveToken5();
57514
57557
  let data;
57515
57558
  if (options.search) {
57516
57559
  data = await apiGet3(
@@ -57535,8 +57578,8 @@ async function list(options) {
57535
57578
  ${data.results.length} result(s)`);
57536
57579
  }
57537
57580
  async function searchKnowledge(options) {
57538
- const apiUrl = process.env.HAANSI_API_URL ?? DEFAULT_API_URL6;
57539
- const token = resolveToken4();
57581
+ const apiUrl = process.env.HAANSI_API_URL ?? DEFAULT_API_URL7;
57582
+ const token = resolveToken5();
57540
57583
  let url2 = `/sessions/knowledge/search?q=${encodeURIComponent(options.query)}&limit=${options.limit}`;
57541
57584
  if (options.artifactType) {
57542
57585
  url2 += `&artifact_type=${encodeURIComponent(options.artifactType)}`;
@@ -57552,8 +57595,8 @@ async function searchKnowledge(options) {
57552
57595
  ${data.results.length} result(s)`);
57553
57596
  }
57554
57597
  async function saveKnowledge(options) {
57555
- const apiUrl = process.env.HAANSI_API_URL ?? DEFAULT_API_URL6;
57556
- const token = resolveToken4();
57598
+ const apiUrl = process.env.HAANSI_API_URL ?? DEFAULT_API_URL7;
57599
+ const token = resolveToken5();
57557
57600
  const body = {
57558
57601
  problem_description: options.problem,
57559
57602
  solution_summary: options.solution,
@@ -57568,15 +57611,15 @@ async function saveKnowledge(options) {
57568
57611
  console.log(` Solution: ${data.solution_summary}`);
57569
57612
  console.log("\nThis is now searchable via `haansi search-solutions`.");
57570
57613
  }
57571
- var import_node_fs6, import_node_path6, import_node_os6, DEFAULT_API_URL6, CREDENTIALS_FILE6;
57614
+ var import_node_fs6, import_node_path6, import_node_os6, DEFAULT_API_URL7, CREDENTIALS_FILE7;
57572
57615
  var init_list = __esm({
57573
57616
  "src/commands/list.ts"() {
57574
57617
  "use strict";
57575
57618
  import_node_fs6 = require("node:fs");
57576
57619
  import_node_path6 = require("node:path");
57577
57620
  import_node_os6 = require("node:os");
57578
- DEFAULT_API_URL6 = "https://api.haansi.co";
57579
- CREDENTIALS_FILE6 = (0, import_node_path6.join)((0, import_node_os6.homedir)(), ".haansi", "credentials.json");
57621
+ DEFAULT_API_URL7 = "https://api.haansi.co";
57622
+ CREDENTIALS_FILE7 = (0, import_node_path6.join)((0, import_node_os6.homedir)(), ".haansi", "credentials.json");
57580
57623
  }
57581
57624
  });
57582
57625
 
@@ -57638,7 +57681,8 @@ Collector done: ${uploaded} uploaded, ${skipped} unchanged, ${errors} errors`
57638
57681
  }
57639
57682
  case "setup-mcp": {
57640
57683
  const { setupMcp: setupMcp2 } = await Promise.resolve().then(() => (init_setup_mcp(), setup_mcp_exports));
57641
- await setupMcp2();
57684
+ const targetArg = process.argv[3];
57685
+ await setupMcp2(targetArg);
57642
57686
  break;
57643
57687
  }
57644
57688
  case "setup-daemon": {
@@ -57742,7 +57786,10 @@ Commands:
57742
57786
 
57743
57787
  daemon Run the collector on a schedule (every 30 min)
57744
57788
  mcp-server Start the Haansi MCP server (used by Claude Code)
57745
- setup-mcp Add haansi-solutions MCP entry to ~/.claude.json
57789
+ setup-mcp [target] Register MCP servers in ~/.claude.json
57790
+ target: solutions | exchange | all (default: all)
57791
+ - solutions: stdio, per-org search/save tools
57792
+ - exchange: http, cross-org marketplace (read-only)
57746
57793
  setup-daemon Install launchd service to auto-start daemon on login (macOS)
57747
57794
  help Show this help message
57748
57795
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "haansi",
3
- "version": "0.1.18",
3
+ "version": "0.1.19",
4
4
  "description": "Haansi CLI - Session collector and MCP server for Claude Code",
5
5
  "bin": {
6
6
  "haansi": "./dist/haansi.js"