@hiveai/mcp 0.10.2 → 0.10.4

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/index.js CHANGED
@@ -131,7 +131,8 @@ import {
131
131
  loadConfig,
132
132
  loadMemoriesFromDir as loadMemoriesFromDir2,
133
133
  memoryFilePath,
134
- serializeMemory
134
+ serializeMemory,
135
+ suggestSensorFromMemory
135
136
  } from "@hiveai/core";
136
137
  import { z as z4 } from "zod";
137
138
  var MemSaveInputSchema = {
@@ -232,6 +233,8 @@ async function memSave(input, ctx) {
232
233
  symbols: input.symbols.length ? input.symbols : fm.anchor.symbols
233
234
  }
234
235
  };
236
+ const suggestedSensor = !newFrontmatter.sensor ? suggestSensorForSavedMemory(input.type, input.body, newFrontmatter.anchor.paths) : null;
237
+ if (suggestedSensor) newFrontmatter.sensor = suggestedSensor;
235
238
  await writeFile2(
236
239
  topicMatch.filePath,
237
240
  serializeMemory({ frontmatter: newFrontmatter, body: input.body }),
@@ -250,7 +253,8 @@ async function memSave(input, ctx) {
250
253
  revision_count: newFrontmatter.revision_count,
251
254
  ...mergedTw ? { warning: mergedTw } : {},
252
255
  ...bs ? { body_similar: bs } : {},
253
- ...invalidPaths.length > 0 ? { invalid_paths: invalidPaths } : {}
256
+ ...invalidPaths.length > 0 ? { invalid_paths: invalidPaths } : {},
257
+ ...suggestedSensor ? { suggested_sensor: true } : {}
254
258
  };
255
259
  }
256
260
  }
@@ -266,7 +270,8 @@ async function memSave(input, ctx) {
266
270
  symbols: input.symbols,
267
271
  commit: input.commit,
268
272
  topic: input.topic,
269
- status: haiveConfig.defaultStatus === "validated" ? "validated" : void 0
273
+ status: haiveConfig.defaultStatus === "validated" ? "validated" : void 0,
274
+ sensor: suggestSensorForSavedMemory(input.type, input.body, input.paths) ?? void 0
270
275
  });
271
276
  const file = memoryFilePath(
272
277
  ctx.paths,
@@ -307,9 +312,14 @@ async function memSave(input, ctx) {
307
312
  ...finalWarning ? { warning: finalWarning } : {},
308
313
  ...similar_found ? { similar_found } : {},
309
314
  ...bsNew ? { body_similar: bsNew } : {},
310
- ...invalidPaths.length > 0 ? { invalid_paths: invalidPaths } : {}
315
+ ...invalidPaths.length > 0 ? { invalid_paths: invalidPaths } : {},
316
+ ...frontmatter.sensor?.autogen ? { suggested_sensor: true } : {}
311
317
  };
312
318
  }
319
+ function suggestSensorForSavedMemory(type, body, paths) {
320
+ if (type !== "gotcha" && type !== "attempt") return null;
321
+ return suggestSensorFromMemory(body, paths);
322
+ }
313
323
  function criticalAnchorWarning(type, status, paths, symbols) {
314
324
  if (!["decision", "gotcha", "architecture"].includes(type)) return null;
315
325
  if (status !== "validated") return null;
@@ -1027,7 +1037,8 @@ import path5 from "path";
1027
1037
  import {
1028
1038
  buildFrontmatter as buildFrontmatter2,
1029
1039
  memoryFilePath as memoryFilePath2,
1030
- serializeMemory as serializeMemory6
1040
+ serializeMemory as serializeMemory6,
1041
+ suggestSensorFromMemory as suggestSensorFromMemory2
1031
1042
  } from "@hiveai/core";
1032
1043
  import { z as z14 } from "zod";
1033
1044
  var MemTriedInputSchema = {
@@ -1061,6 +1072,10 @@ async function memTried(input, ctx) {
1061
1072
  lines.push("", `**Instead, use:** ${input.instead}`);
1062
1073
  }
1063
1074
  const body = lines.join("\n") + "\n";
1075
+ const sensor = suggestSensorFromMemory2(body, input.paths);
1076
+ if (sensor) {
1077
+ frontmatter.sensor = sensor;
1078
+ }
1064
1079
  const file = memoryFilePath2(ctx.paths, frontmatter.scope, frontmatter.id, frontmatter.module);
1065
1080
  await mkdir3(path5.dirname(file), { recursive: true });
1066
1081
  if (existsSync14(file)) {
@@ -2443,6 +2458,7 @@ function runCommand(cmd, args, cwd) {
2443
2458
  // src/tools/anti-patterns-check.ts
2444
2459
  import { existsSync as existsSync22 } from "fs";
2445
2460
  import {
2461
+ addedLinesFromDiff,
2446
2462
  deriveConfidence as deriveConfidence6,
2447
2463
  getUsage as getUsage7,
2448
2464
  isRetiredMemory as isRetiredMemory2,
@@ -2450,6 +2466,8 @@ import {
2450
2466
  loadUsageIndex as loadUsageIndex9,
2451
2467
  literalMatchesAnyToken as literalMatchesAnyToken3,
2452
2468
  memoryMatchesAnchorPaths as memoryMatchesAnchorPaths4,
2469
+ runSensors,
2470
+ sensorTargetsFromDiff,
2453
2471
  tokenizeQuery as tokenizeQuery3
2454
2472
  } from "@hiveai/core";
2455
2473
  import { z as z24 } from "zod";
@@ -2587,6 +2605,23 @@ async function antiPatternsCheck(input, ctx) {
2587
2605
  }
2588
2606
  }
2589
2607
  }
2608
+ if (input.diff) {
2609
+ const added = addedLinesFromDiff(input.diff);
2610
+ const diffTargets = sensorTargetsFromDiff(input.diff);
2611
+ const hasFileTargets = diffTargets.some((target) => target.path.length > 0);
2612
+ const targets = diffTargets.length > 0 && hasFileTargets ? diffTargets : input.paths.length > 0 ? input.paths.map((p) => ({ path: p, content: added.trim().length > 0 ? added : input.diff })) : [{ path: "", content: added.trim().length > 0 ? added : input.diff }];
2613
+ const hits = runSensors(negative.map(({ memory }) => memory), targets);
2614
+ for (const hit of hits) {
2615
+ const found = negative.find(({ memory }) => memory.frontmatter.id === hit.memory_id);
2616
+ if (!found) continue;
2617
+ upsert(found.memory.frontmatter, found.memory.body, "sensor");
2618
+ const w = seen.get(found.memory.frontmatter.id);
2619
+ if (w) {
2620
+ w.sensor_message = hit.message;
2621
+ w.sensor_severity = hit.severity;
2622
+ }
2623
+ }
2624
+ }
2590
2625
  if (input.semantic && input.diff) {
2591
2626
  try {
2592
2627
  const mod = await import("@hiveai/embeddings");
@@ -2605,7 +2640,7 @@ async function antiPatternsCheck(input, ctx) {
2605
2640
  }
2606
2641
  const warnings = [...seen.values()].sort((a, b) => {
2607
2642
  const score = (w) => {
2608
- const reasonW = (w.reasons.includes("anchor") ? 4 : 0) + (w.reasons.includes("literal") ? 2 : 0) + (w.reasons.includes("semantic") ? 1 : 0);
2643
+ const reasonW = (w.reasons.includes("sensor") ? 8 : 0) + (w.reasons.includes("anchor") ? 4 : 0) + (w.reasons.includes("literal") ? 2 : 0) + (w.reasons.includes("semantic") ? 1 : 0);
2609
2644
  const confW = w.confidence === "authoritative" ? 3 : w.confidence === "trusted" ? 2 : w.confidence === "low" ? 1 : 0;
2610
2645
  return reasonW + confW + (w.semantic_score ?? 0);
2611
2646
  };
@@ -3148,6 +3183,24 @@ function classifyWarning(warning, paths, anchoredBlocks = false) {
3148
3183
  repair_command: repairCommand
3149
3184
  };
3150
3185
  }
3186
+ if (warning.reasons.includes("sensor")) {
3187
+ if (warning.sensor_severity === "block") {
3188
+ return {
3189
+ ...warning,
3190
+ level: "blocking",
3191
+ rationale: "deterministic hAIve sensor with block severity matched the added diff",
3192
+ affected_files: affectedFiles,
3193
+ repair_command: repairCommand
3194
+ };
3195
+ }
3196
+ return {
3197
+ ...warning,
3198
+ level: "review",
3199
+ rationale: "deterministic hAIve sensor with warn severity matched the added diff",
3200
+ affected_files: affectedFiles,
3201
+ repair_command: repairCommand
3202
+ };
3203
+ }
3151
3204
  if (isBlockingWarning(warning)) {
3152
3205
  return {
3153
3206
  ...warning,
@@ -3874,7 +3927,7 @@ When done, respond with: "Imported N memories: [list of IDs]" or "Nothing action
3874
3927
  // src/server.ts
3875
3928
  import { loadConfigSync } from "@hiveai/core";
3876
3929
  var SERVER_NAME = "haive";
3877
- var SERVER_VERSION = "0.10.2";
3930
+ var SERVER_VERSION = "0.10.4";
3878
3931
  function jsonResult(data) {
3879
3932
  return {
3880
3933
  content: [