@hiveai/mcp 0.2.7 → 0.2.8
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 +170 -12
- package/dist/index.js.map +1 -1
- package/dist/server.js +170 -12
- package/dist/server.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -397,6 +397,7 @@ async function memVerify(input, ctx) {
|
|
|
397
397
|
file_path: filePath,
|
|
398
398
|
stale: result.stale,
|
|
399
399
|
reason: result.reason,
|
|
400
|
+
...result.possibleRenames.length > 0 ? { possible_renames: result.possibleRenames } : {},
|
|
400
401
|
status_after: statusAfter
|
|
401
402
|
});
|
|
402
403
|
}
|
|
@@ -859,6 +860,7 @@ import {
|
|
|
859
860
|
estimateTokens,
|
|
860
861
|
getUsage as getUsage5,
|
|
861
862
|
inferModulesFromPaths as inferModulesFromPaths2,
|
|
863
|
+
isDecaying,
|
|
862
864
|
literalMatchesAllTokens as literalMatchesAllTokens2,
|
|
863
865
|
loadMemoriesFromDir as loadMemoriesFromDir12,
|
|
864
866
|
loadUsageIndex as loadUsageIndex7,
|
|
@@ -883,12 +885,17 @@ var GetBriefingInputSchema = {
|
|
|
883
885
|
"Use semantic ranking when a task is provided (requires `haive embeddings index`)."
|
|
884
886
|
),
|
|
885
887
|
include_stale: z15.boolean().default(false).describe("Include stale memories (excluded by default \u2014 they may be outdated)"),
|
|
886
|
-
track: z15.boolean().default(true).describe("Increment read_count on returned memories")
|
|
888
|
+
track: z15.boolean().default(true).describe("Increment read_count on returned memories"),
|
|
889
|
+
format: z15.enum(["full", "compact"]).default("full").describe(
|
|
890
|
+
"Output format: 'full' returns complete memory bodies; 'compact' returns id + 1-line summary only (call mem_get for details)."
|
|
891
|
+
)
|
|
887
892
|
};
|
|
888
893
|
async function getBriefing(input, ctx) {
|
|
889
894
|
const inferred = inferModulesFromPaths2(input.files);
|
|
890
895
|
const memories = [];
|
|
891
896
|
let searchMode = "literal";
|
|
897
|
+
let usage = { version: 1, updated_at: "", by_id: {} };
|
|
898
|
+
let byId = /* @__PURE__ */ new Map();
|
|
892
899
|
if (existsSync15(ctx.paths.memoriesDir)) {
|
|
893
900
|
const allLoaded = await loadMemoriesFromDir12(ctx.paths.memoriesDir);
|
|
894
901
|
const allMemories = allLoaded.filter(({ memory }) => {
|
|
@@ -897,7 +904,7 @@ async function getBriefing(input, ctx) {
|
|
|
897
904
|
if (!input.include_stale && s === "stale") return false;
|
|
898
905
|
return true;
|
|
899
906
|
});
|
|
900
|
-
|
|
907
|
+
usage = await loadUsageIndex7(ctx.paths);
|
|
901
908
|
const semanticHits = input.task && input.semantic ? await trySemanticHits(ctx, input.task, allMemories.length * 2) : null;
|
|
902
909
|
if (input.task && input.semantic) {
|
|
903
910
|
searchMode = semanticHits ? "semantic" : "literal_fallback";
|
|
@@ -954,7 +961,6 @@ async function getBriefing(input, ctx) {
|
|
|
954
961
|
}
|
|
955
962
|
}
|
|
956
963
|
if (semanticHits) {
|
|
957
|
-
const byId = new Map(allMemories.map((m) => [m.memory.frontmatter.id, m]));
|
|
958
964
|
for (const hit of semanticHits) {
|
|
959
965
|
const loaded = byId.get(hit.id);
|
|
960
966
|
if (loaded) addOrUpdate(loaded, "semantic", hit.score, "semantic");
|
|
@@ -969,6 +975,17 @@ async function getBriefing(input, ctx) {
|
|
|
969
975
|
const sb = reasonScore(b) + confidenceScore(b) + (b.semantic_score ?? 0);
|
|
970
976
|
return sb - sa;
|
|
971
977
|
});
|
|
978
|
+
byId = new Map(allMemories.map((m) => [m.memory.frontmatter.id, m]));
|
|
979
|
+
for (const mem of ranked.slice(0, input.max_memories)) {
|
|
980
|
+
if (seen.size >= input.max_memories * 2) break;
|
|
981
|
+
const loaded = byId.get(mem.id);
|
|
982
|
+
if (!loaded) continue;
|
|
983
|
+
for (const relId of loaded.memory.frontmatter.related_ids ?? []) {
|
|
984
|
+
if (seen.has(relId)) continue;
|
|
985
|
+
const related = byId.get(relId);
|
|
986
|
+
if (related) addOrUpdate(related, "anchor", void 0, "partial");
|
|
987
|
+
}
|
|
988
|
+
}
|
|
972
989
|
memories.push(...ranked.slice(0, input.max_memories));
|
|
973
990
|
if (input.track && memories.length > 0) {
|
|
974
991
|
await trackReads3(ctx.paths, memories.map((m) => m.id));
|
|
@@ -1009,7 +1026,6 @@ ${m.content}`).join("\n\n---\n\n"),
|
|
|
1009
1026
|
trimmedModules.push({ name: m.name, content: sub.text, truncated: sub.truncated });
|
|
1010
1027
|
}
|
|
1011
1028
|
}
|
|
1012
|
-
const trimmedMemoriesText = memoriesSlice.text;
|
|
1013
1029
|
const trimmedMemories = [];
|
|
1014
1030
|
if (!memoriesSlice.truncated) {
|
|
1015
1031
|
trimmedMemories.push(...memories);
|
|
@@ -1029,13 +1045,22 @@ ${m.content}`).join("\n\n---\n\n"),
|
|
|
1029
1045
|
}
|
|
1030
1046
|
}
|
|
1031
1047
|
const totalTokens = projectSlice.estimatedTokens + modulesSlice.estimatedTokens + memoriesSlice.estimatedTokens;
|
|
1048
|
+
const decayWarnings = [];
|
|
1049
|
+
for (const m of trimmedMemories) {
|
|
1050
|
+
const u = getUsage5(usage, m.id);
|
|
1051
|
+
const loaded = byId.get(m.id);
|
|
1052
|
+
const createdAt = loaded?.memory.frontmatter.created_at ?? (/* @__PURE__ */ new Date()).toISOString();
|
|
1053
|
+
if (isDecaying(u, createdAt)) decayWarnings.push(m.id);
|
|
1054
|
+
}
|
|
1055
|
+
const outputMemories = input.format === "compact" ? trimmedMemories.map((m) => ({ ...m, body: compactSummary(m.body) })) : trimmedMemories;
|
|
1032
1056
|
return {
|
|
1033
1057
|
...input.task ? { task: input.task } : {},
|
|
1034
1058
|
search_mode: searchMode,
|
|
1035
1059
|
inferred_modules: inferred,
|
|
1036
1060
|
project_context: projectContext ? { content: projectSlice.text, truncated: projectSlice.truncated } : null,
|
|
1037
1061
|
module_contexts: trimmedModules,
|
|
1038
|
-
memories:
|
|
1062
|
+
memories: outputMemories,
|
|
1063
|
+
decay_warnings: decayWarnings,
|
|
1039
1064
|
estimated_tokens: totalTokens,
|
|
1040
1065
|
budget: {
|
|
1041
1066
|
max_tokens: input.max_tokens,
|
|
@@ -1047,6 +1072,13 @@ ${m.content}`).join("\n\n---\n\n"),
|
|
|
1047
1072
|
}
|
|
1048
1073
|
};
|
|
1049
1074
|
}
|
|
1075
|
+
function compactSummary(body) {
|
|
1076
|
+
for (const line of body.split("\n")) {
|
|
1077
|
+
const trimmed = line.replace(/^#+\s*/, "").trim();
|
|
1078
|
+
if (trimmed.length > 0) return trimmed.slice(0, 120);
|
|
1079
|
+
}
|
|
1080
|
+
return body.slice(0, 120);
|
|
1081
|
+
}
|
|
1050
1082
|
async function trySemanticHits(ctx, task, limit) {
|
|
1051
1083
|
let mod;
|
|
1052
1084
|
try {
|
|
@@ -1106,13 +1138,58 @@ async function codeMapTool(input, ctx) {
|
|
|
1106
1138
|
};
|
|
1107
1139
|
}
|
|
1108
1140
|
|
|
1109
|
-
// src/
|
|
1141
|
+
// src/tools/mem-diff.ts
|
|
1142
|
+
import { existsSync as existsSync16 } from "fs";
|
|
1143
|
+
import { loadMemoriesFromDir as loadMemoriesFromDir13 } from "@hiveai/core";
|
|
1110
1144
|
import { z as z17 } from "zod";
|
|
1145
|
+
var MemDiffInputSchema = {
|
|
1146
|
+
id_a: z17.string().min(1).describe("First memory id"),
|
|
1147
|
+
id_b: z17.string().min(1).describe("Second memory id")
|
|
1148
|
+
};
|
|
1149
|
+
async function memDiff(input, ctx) {
|
|
1150
|
+
if (!existsSync16(ctx.paths.memoriesDir)) {
|
|
1151
|
+
throw new Error(`No .ai/memories at ${ctx.paths.root}.`);
|
|
1152
|
+
}
|
|
1153
|
+
const all = await loadMemoriesFromDir13(ctx.paths.memoriesDir);
|
|
1154
|
+
const foundA = all.find((m) => m.memory.frontmatter.id === input.id_a);
|
|
1155
|
+
const foundB = all.find((m) => m.memory.frontmatter.id === input.id_b);
|
|
1156
|
+
if (!foundA) throw new Error(`No memory with id "${input.id_a}".`);
|
|
1157
|
+
if (!foundB) throw new Error(`No memory with id "${input.id_b}".`);
|
|
1158
|
+
const fmA = foundA.memory.frontmatter;
|
|
1159
|
+
const fmB = foundB.memory.frontmatter;
|
|
1160
|
+
const frontmatterDiff = {};
|
|
1161
|
+
const allKeys = /* @__PURE__ */ new Set([...Object.keys(fmA), ...Object.keys(fmB)]);
|
|
1162
|
+
for (const key of allKeys) {
|
|
1163
|
+
const va = fmA[key];
|
|
1164
|
+
const vb = fmB[key];
|
|
1165
|
+
if (JSON.stringify(va) !== JSON.stringify(vb)) {
|
|
1166
|
+
frontmatterDiff[key] = { a: va, b: vb };
|
|
1167
|
+
}
|
|
1168
|
+
}
|
|
1169
|
+
const linesA = new Set(foundA.memory.body.split("\n").map((l) => l.trim()).filter(Boolean));
|
|
1170
|
+
const linesB = new Set(foundB.memory.body.split("\n").map((l) => l.trim()).filter(Boolean));
|
|
1171
|
+
const onlyA = [...linesA].filter((l) => !linesB.has(l));
|
|
1172
|
+
const onlyB = [...linesB].filter((l) => !linesA.has(l));
|
|
1173
|
+
const common = [...linesA].filter((l) => linesB.has(l)).length;
|
|
1174
|
+
return {
|
|
1175
|
+
id_a: input.id_a,
|
|
1176
|
+
id_b: input.id_b,
|
|
1177
|
+
frontmatter_diff: frontmatterDiff,
|
|
1178
|
+
body_diff: {
|
|
1179
|
+
lines_only_in_a: onlyA,
|
|
1180
|
+
lines_only_in_b: onlyB,
|
|
1181
|
+
common_lines: common
|
|
1182
|
+
}
|
|
1183
|
+
};
|
|
1184
|
+
}
|
|
1185
|
+
|
|
1186
|
+
// src/prompts/bootstrap-project.ts
|
|
1187
|
+
import { z as z18 } from "zod";
|
|
1111
1188
|
var BootstrapProjectArgsSchema = {
|
|
1112
|
-
module:
|
|
1189
|
+
module: z18.string().optional().describe(
|
|
1113
1190
|
"Optional module name to scope the analysis to (writes to .ai/modules/<module>/context.md)"
|
|
1114
1191
|
),
|
|
1115
|
-
focus:
|
|
1192
|
+
focus: z18.string().optional().describe("Optional area to emphasize (e.g. 'data layer', 'API surface')")
|
|
1116
1193
|
};
|
|
1117
1194
|
var ROOT_TEMPLATE = `# Project context
|
|
1118
1195
|
|
|
@@ -1194,10 +1271,10 @@ ${template}\`\`\`
|
|
|
1194
1271
|
}
|
|
1195
1272
|
|
|
1196
1273
|
// src/prompts/post-task.ts
|
|
1197
|
-
import { z as
|
|
1274
|
+
import { z as z19 } from "zod";
|
|
1198
1275
|
var PostTaskArgsSchema = {
|
|
1199
|
-
task_summary:
|
|
1200
|
-
files_touched:
|
|
1276
|
+
task_summary: z19.string().optional().describe("One sentence describing what you just did"),
|
|
1277
|
+
files_touched: z19.array(z19.string()).optional().describe("Files you created or modified during the task")
|
|
1201
1278
|
};
|
|
1202
1279
|
function postTaskPrompt(args, ctx) {
|
|
1203
1280
|
const taskLine = args.task_summary ? `
|
|
@@ -1253,9 +1330,78 @@ When done, respond with a brief summary: "Saved N memories: [list of IDs]" or "N
|
|
|
1253
1330
|
};
|
|
1254
1331
|
}
|
|
1255
1332
|
|
|
1333
|
+
// src/prompts/import-docs.ts
|
|
1334
|
+
import { z as z20 } from "zod";
|
|
1335
|
+
var ImportDocsArgsSchema = {
|
|
1336
|
+
content: z20.string().describe("The documentation content to analyze and import as memories (Markdown, README, ADR, etc.)"),
|
|
1337
|
+
source: z20.string().optional().describe("Origin of the content (file path, URL, or document title) \u2014 used to anchor memories"),
|
|
1338
|
+
scope: z20.enum(["personal", "team"]).default("team").describe("Scope to assign to created memories"),
|
|
1339
|
+
dry_run: z20.boolean().default(false).describe("If true, describe what would be saved without actually calling mem_save")
|
|
1340
|
+
};
|
|
1341
|
+
function importDocsPrompt(args, ctx) {
|
|
1342
|
+
const sourceLine = args.source ? `
|
|
1343
|
+
Source: **${args.source}**` : "";
|
|
1344
|
+
const dryRunNote = args.dry_run ? "\n> **DRY RUN** \u2014 describe what you would save but do not call any tools." : "";
|
|
1345
|
+
const text = `You are given documentation to analyze and import into the hAIve memory system.
|
|
1346
|
+
${sourceLine}
|
|
1347
|
+
Scope: **${args.scope}**
|
|
1348
|
+
Project root: \`${ctx.paths.root}\`
|
|
1349
|
+
${dryRunNote}
|
|
1350
|
+
|
|
1351
|
+
## Your task
|
|
1352
|
+
|
|
1353
|
+
Read the documentation below and extract actionable memories. For each distinct piece of knowledge:
|
|
1354
|
+
|
|
1355
|
+
1. **Identify the memory type** \u2014 which category fits best?
|
|
1356
|
+
- \`convention\` \u2014 how things are done here (naming, patterns, workflow)
|
|
1357
|
+
- \`decision\` \u2014 a choice that was made and why (tradeoffs, constraints)
|
|
1358
|
+
- \`gotcha\` \u2014 non-obvious behavior, traps, things that surprise newcomers
|
|
1359
|
+
- \`architecture\` \u2014 structural overview of a system or module
|
|
1360
|
+
- \`glossary\` \u2014 domain terms and their meaning in this project
|
|
1361
|
+
|
|
1362
|
+
2. **Determine the anchor** \u2014 which files or symbols does this knowledge apply to? List them in \`paths\`.
|
|
1363
|
+
|
|
1364
|
+
3. **Write a focused body** \u2014 one memory = one insight. Do not combine multiple unrelated facts.
|
|
1365
|
+
- Start with the key fact or rule
|
|
1366
|
+
- Add context: why it matters, when it applies
|
|
1367
|
+
- Add examples if helpful
|
|
1368
|
+
|
|
1369
|
+
4. **Call \`mem_save\`** for each memory (unless dry_run).
|
|
1370
|
+
- Set \`scope="${args.scope}"\`
|
|
1371
|
+
- Set \`slug\` to a short kebab-case identifier
|
|
1372
|
+
- Set \`paths\` to the relevant file paths (extracted from the doc if present)
|
|
1373
|
+
|
|
1374
|
+
## Rules
|
|
1375
|
+
|
|
1376
|
+
- Skip generic documentation that applies to any project (e.g., "install with npm install").
|
|
1377
|
+
- Prioritize gotchas, non-obvious decisions, and domain-specific conventions.
|
|
1378
|
+
- If the same knowledge is repeated in different sections, save it once.
|
|
1379
|
+
- Maximum 10 memories per import \u2014 select the most actionable ones.
|
|
1380
|
+
|
|
1381
|
+
## Documentation to import
|
|
1382
|
+
|
|
1383
|
+
---
|
|
1384
|
+
|
|
1385
|
+
${args.content}
|
|
1386
|
+
|
|
1387
|
+
---
|
|
1388
|
+
|
|
1389
|
+
When done, respond with: "Imported N memories: [list of IDs]" or "Nothing actionable found."
|
|
1390
|
+
`;
|
|
1391
|
+
return {
|
|
1392
|
+
description: "Import documentation as hAIve memories",
|
|
1393
|
+
messages: [
|
|
1394
|
+
{
|
|
1395
|
+
role: "user",
|
|
1396
|
+
content: { type: "text", text }
|
|
1397
|
+
}
|
|
1398
|
+
]
|
|
1399
|
+
};
|
|
1400
|
+
}
|
|
1401
|
+
|
|
1256
1402
|
// src/server.ts
|
|
1257
1403
|
var SERVER_NAME = "haive";
|
|
1258
|
-
var SERVER_VERSION = "0.2.
|
|
1404
|
+
var SERVER_VERSION = "0.2.8";
|
|
1259
1405
|
function jsonResult(data) {
|
|
1260
1406
|
return {
|
|
1261
1407
|
content: [
|
|
@@ -1368,6 +1514,12 @@ function createHaiveServer(options = {}) {
|
|
|
1368
1514
|
MemTriedInputSchema,
|
|
1369
1515
|
async (input) => jsonResult(await memTried(input, context))
|
|
1370
1516
|
);
|
|
1517
|
+
server.tool(
|
|
1518
|
+
"mem_diff",
|
|
1519
|
+
"Compare two memories side-by-side: shows frontmatter fields that differ and lines unique to each body. Useful before merging or deduplicating memories.",
|
|
1520
|
+
MemDiffInputSchema,
|
|
1521
|
+
async (input) => jsonResult(await memDiff(input, context))
|
|
1522
|
+
);
|
|
1371
1523
|
server.prompt(
|
|
1372
1524
|
"bootstrap_project",
|
|
1373
1525
|
"Instructions for the AI client to analyze the project and save the context.",
|
|
@@ -1380,6 +1532,12 @@ function createHaiveServer(options = {}) {
|
|
|
1380
1532
|
PostTaskArgsSchema,
|
|
1381
1533
|
(args) => postTaskPrompt(args, context)
|
|
1382
1534
|
);
|
|
1535
|
+
server.prompt(
|
|
1536
|
+
"import_docs",
|
|
1537
|
+
"Analyze documentation (README, ADR, wiki page, etc.) and save the actionable knowledge as hAIve memories. Pass the content and an optional source/scope.",
|
|
1538
|
+
ImportDocsArgsSchema,
|
|
1539
|
+
(args) => importDocsPrompt(args, context)
|
|
1540
|
+
);
|
|
1383
1541
|
return { server, context };
|
|
1384
1542
|
}
|
|
1385
1543
|
|