@hiveai/cli 0.2.10 → 0.2.11

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
@@ -13,7 +13,8 @@ import {
13
13
  loadMemoriesFromDir,
14
14
  memoryMatchesAnchorPaths,
15
15
  resolveHaivePaths,
16
- tokenizeQuery
16
+ tokenizeQuery,
17
+ trackReads
17
18
  } from "@hiveai/core";
18
19
 
19
20
  // src/utils/ui.ts
@@ -117,6 +118,11 @@ function registerBriefing(program2) {
117
118
  console.log();
118
119
  }
119
120
  console.log(ui.dim(`${top.length} memor${top.length === 1 ? "y" : "ies"} surfaced`));
121
+ const ids = top.map(({ memory: mem }) => mem.frontmatter.id);
122
+ if (ids.length > 0) {
123
+ await trackReads(paths, ids).catch(() => {
124
+ });
125
+ }
120
126
  });
121
127
  }
122
128
  function parseCsv(value) {
@@ -796,6 +802,12 @@ TODO \u2014 write the memory body.
796
802
  if (inferredTags.length > 0) {
797
803
  ui.info(`auto-tagged: ${inferredTags.join(", ")} (use --no-auto-tag to disable)`);
798
804
  }
805
+ if (anchorPaths.length === 0) {
806
+ ui.warn(
807
+ `This memory has no anchor paths \u2014 staleness cannot be detected automatically.
808
+ Add file anchors: haive memory update ${frontmatter.id} --paths <file1,file2>`
809
+ );
810
+ }
799
811
  if (frontmatter.scope === "personal") {
800
812
  console.log(
801
813
  ui.dim(
@@ -1264,12 +1276,17 @@ function registerMemoryForFiles(memory2) {
1264
1276
  seen.add(loaded.memory.frontmatter.id);
1265
1277
  }
1266
1278
  }
1279
+ const pathSegments = extractPathSegments(files);
1267
1280
  for (const loaded of all) {
1268
1281
  if (seen.has(loaded.memory.frontmatter.id)) continue;
1269
- const mod = loaded.memory.frontmatter.module;
1270
- if (mod && inferred.includes(mod)) {
1282
+ const fm = loaded.memory.frontmatter;
1283
+ const moduleHit = fm.module && inferred.includes(fm.module) || fm.tags.some((t) => {
1284
+ const tl = t.toLowerCase();
1285
+ return pathSegments.has(tl) || pathSegments.has(tl.replace(/[-_]/g, ""));
1286
+ });
1287
+ if (moduleHit) {
1271
1288
  byModule.push(loaded);
1272
- seen.add(loaded.memory.frontmatter.id);
1289
+ seen.add(fm.id);
1273
1290
  }
1274
1291
  }
1275
1292
  for (const loaded of all) {
@@ -1290,6 +1307,52 @@ function registerMemoryForFiles(memory2) {
1290
1307
  );
1291
1308
  });
1292
1309
  }
1310
+ function extractPathSegments(files) {
1311
+ const GENERIC = /* @__PURE__ */ new Set([
1312
+ "src",
1313
+ "main",
1314
+ "java",
1315
+ "kotlin",
1316
+ "python",
1317
+ "go",
1318
+ "lib",
1319
+ "libs",
1320
+ "com",
1321
+ "org",
1322
+ "net",
1323
+ "io",
1324
+ "app",
1325
+ "apps",
1326
+ "pkg",
1327
+ "internal",
1328
+ "test",
1329
+ "tests",
1330
+ "spec",
1331
+ "specs",
1332
+ "impl",
1333
+ "domain",
1334
+ "shared",
1335
+ "resources",
1336
+ "static",
1337
+ "assets",
1338
+ "config",
1339
+ "configs"
1340
+ ]);
1341
+ const out = /* @__PURE__ */ new Set();
1342
+ for (const file of files) {
1343
+ const parts = file.replace(/\\/g, "/").split("/");
1344
+ for (const part of parts) {
1345
+ const seg = part.toLowerCase().replace(/\.[^.]+$/, "");
1346
+ if (seg.length >= 3 && !GENERIC.has(seg) && /^[a-z]/.test(seg)) {
1347
+ out.add(seg);
1348
+ for (const sub of seg.split(/[-_]/).filter((s) => s.length >= 3)) {
1349
+ out.add(sub);
1350
+ }
1351
+ }
1352
+ }
1353
+ }
1354
+ return out;
1355
+ }
1293
1356
  function printGroup(root, label, loaded, usage) {
1294
1357
  if (loaded.length === 0) return;
1295
1358
  console.log(ui.bold(`
@@ -1469,7 +1532,8 @@ import {
1469
1532
  literalMatchesAnyToken,
1470
1533
  pickSnippetNeedle,
1471
1534
  resolveHaivePaths as resolveHaivePaths17,
1472
- tokenizeQuery as tokenizeQuery2
1535
+ tokenizeQuery as tokenizeQuery2,
1536
+ trackReads as trackReads2
1473
1537
  } from "@hiveai/core";
1474
1538
  function registerMemoryQuery(memory2) {
1475
1539
  memory2.command("query <text>").description("Search memories by id, tag, or substring (AND, OR fallback)").option("-d, --dir <dir>", "project root").option("--limit <n>", "max results", "20").option("--scope <scope>", "personal | team | module").option("--status <csv>", "filter by status (draft,proposed,validated,stale,rejected)").option("--show-rejected", "include rejected memories (hidden by default)").action(async (text, opts) => {
@@ -1523,6 +1587,11 @@ function registerMemoryQuery(memory2) {
1523
1587
  ui.dim(`
1524
1588
  ${top.length} of ${matches.length} match${matches.length === 1 ? "" : "es"}`)
1525
1589
  );
1590
+ const ids = top.map(({ memory: mem }) => mem.frontmatter.id);
1591
+ if (ids.length > 0) {
1592
+ await trackReads2(paths, ids).catch(() => {
1593
+ });
1594
+ }
1526
1595
  });
1527
1596
  }
1528
1597
 
@@ -1885,7 +1954,7 @@ function registerMemoryImport(memory2) {
1885
1954
 
1886
1955
  // src/index.ts
1887
1956
  var program = new Command27();
1888
- program.name("haive").description("hAIve \u2014 team-first persistent memory layer for AI coding agents").version("0.2.10");
1957
+ program.name("haive").description("hAIve \u2014 team-first persistent memory layer for AI coding agents").version("0.2.11");
1889
1958
  registerInit(program);
1890
1959
  registerMcp(program);
1891
1960
  registerBriefing(program);
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/commands/briefing.ts","../src/utils/ui.ts","../src/commands/tui.ts","../src/commands/embeddings.ts","../src/commands/index-code.ts","../src/commands/init.ts","../src/commands/install-hooks.ts","../src/commands/mcp.ts","../src/commands/sync.ts","../src/commands/memory-add.ts","../src/commands/memory-list.ts","../src/utils/fs.ts","../src/commands/memory-promote.ts","../src/commands/memory-approve.ts","../src/commands/memory-update.ts","../src/commands/memory-auto-promote.ts","../src/commands/memory-edit.ts","../src/commands/memory-for-files.ts","../src/commands/memory-hot.ts","../src/commands/memory-tried.ts","../src/commands/memory-pending.ts","../src/commands/memory-query.ts","../src/commands/memory-reject.ts","../src/commands/memory-rm.ts","../src/commands/memory-show.ts","../src/commands/memory-stats.ts","../src/commands/memory-verify.ts","../src/commands/memory-import.ts"],"sourcesContent":["import { Command } from \"commander\";\nimport { registerBriefing } from \"./commands/briefing.js\";\nimport { registerTui } from \"./commands/tui.js\";\nimport { registerEmbeddings } from \"./commands/embeddings.js\";\nimport { registerIndexCode } from \"./commands/index-code.js\";\nimport { registerInit } from \"./commands/init.js\";\nimport { registerInstallHooks } from \"./commands/install-hooks.js\";\nimport { registerMcp } from \"./commands/mcp.js\";\nimport { registerSync } from \"./commands/sync.js\";\nimport { registerMemoryAdd } from \"./commands/memory-add.js\";\nimport { registerMemoryList } from \"./commands/memory-list.js\";\nimport { registerMemoryPromote } from \"./commands/memory-promote.js\";\nimport { registerMemoryApprove } from \"./commands/memory-approve.js\";\nimport { registerMemoryUpdate } from \"./commands/memory-update.js\";\nimport { registerMemoryAutoPromote } from \"./commands/memory-auto-promote.js\";\nimport { registerMemoryEdit } from \"./commands/memory-edit.js\";\nimport { registerMemoryForFiles } from \"./commands/memory-for-files.js\";\nimport { registerMemoryHot } from \"./commands/memory-hot.js\";\nimport { registerMemoryTried } from \"./commands/memory-tried.js\";\nimport { registerMemoryPending } from \"./commands/memory-pending.js\";\nimport { registerMemoryQuery } from \"./commands/memory-query.js\";\nimport { registerMemoryReject } from \"./commands/memory-reject.js\";\nimport { registerMemoryRm } from \"./commands/memory-rm.js\";\nimport { registerMemoryShow } from \"./commands/memory-show.js\";\nimport { registerMemoryStats } from \"./commands/memory-stats.js\";\nimport { registerMemoryVerify } from \"./commands/memory-verify.js\";\nimport { registerMemoryImport } from \"./commands/memory-import.js\";\n\nconst program = new Command();\n\ndeclare const __HAIVE_VERSION__: string;\n\nprogram\n .name(\"haive\")\n .description(\"hAIve — team-first persistent memory layer for AI coding agents\")\n .version(__HAIVE_VERSION__);\n\nregisterInit(program);\nregisterMcp(program);\nregisterBriefing(program);\nregisterTui(program);\nregisterEmbeddings(program);\nregisterSync(program);\nregisterInstallHooks(program);\nregisterIndexCode(program);\n\nconst memory = program.command(\"memory\").description(\"Manage memory entries\");\nregisterMemoryAdd(memory);\nregisterMemoryList(memory);\nregisterMemoryQuery(memory);\nregisterMemoryPromote(memory);\nregisterMemoryVerify(memory);\nregisterMemoryStats(memory);\nregisterMemoryReject(memory);\nregisterMemoryAutoPromote(memory);\nregisterMemoryForFiles(memory);\nregisterMemoryShow(memory);\nregisterMemoryEdit(memory);\nregisterMemoryRm(memory);\nregisterMemoryPending(memory);\nregisterMemoryApprove(memory);\nregisterMemoryUpdate(memory);\nregisterMemoryHot(memory);\nregisterMemoryTried(memory);\nregisterMemoryImport(memory);\n\nprogram.parseAsync(process.argv).catch((err: unknown) => {\n if (isZodError(err)) {\n for (const issue of err.issues) {\n const field = issue.path.length > 0 ? `${String(issue.path.join(\".\"))}: ` : \"\";\n console.error(`\\x1b[31m✗\\x1b[0m ${field}${issue.message}`);\n }\n } else {\n console.error(err instanceof Error ? err.message : err);\n }\n process.exit(1);\n});\n\nfunction isZodError(\n err: unknown,\n): err is { issues: Array<{ path: unknown[]; message: string }> } {\n return (\n err !== null &&\n typeof err === \"object\" &&\n \"issues\" in err &&\n Array.isArray((err as Record<string, unknown>).issues)\n );\n}\n","import { existsSync } from \"node:fs\";\nimport { readFile } from \"node:fs/promises\";\nimport { Command } from \"commander\";\nimport {\n findProjectRoot,\n literalMatchesAllTokens,\n loadMemoriesFromDir,\n memoryMatchesAnchorPaths,\n resolveHaivePaths,\n tokenizeQuery,\n} from \"@hiveai/core\";\nimport { ui } from \"../utils/ui.js\";\n\ninterface BriefingOptions {\n task?: string;\n files?: string;\n maxMemories?: string;\n scope?: string;\n includeDraft?: boolean;\n includeStale?: boolean;\n dir?: string;\n}\n\nexport function registerBriefing(program: Command): void {\n program\n .command(\"briefing\")\n .description(\n \"Print project context + relevant memories in one shot — ideal for agent onboarding\",\n )\n .option(\"--task <text>\", \"what you are about to do — filters memories by relevance\")\n .option(\"--files <csv>\", \"comma-separated file paths being worked on (anchors memories)\")\n .option(\"--max-memories <n>\", \"cap on memories surfaced\", \"10\")\n .option(\n \"--scope <scope>\",\n \"personal | team | module | all (default: team)\",\n \"team\",\n )\n .option(\"--include-draft\", \"include draft memories (excluded by default)\")\n .option(\"--include-stale\", \"include stale memories (excluded by default — may be outdated)\")\n .option(\"-d, --dir <dir>\", \"project root\")\n .action(async (opts: BriefingOptions) => {\n const root = findProjectRoot(opts.dir);\n const paths = resolveHaivePaths(root);\n\n // Project context\n if (existsSync(paths.projectContext)) {\n const ctx = await readFile(paths.projectContext, \"utf8\");\n console.log(`${ui.bold(\"=== Project Context ===\")}\\n`);\n console.log(ctx.trim());\n console.log();\n } else {\n ui.warn(\n \"No project-context.md found. Run `haive init` and the `bootstrap_project` MCP prompt to set it up.\",\n );\n }\n\n if (!existsSync(paths.memoriesDir)) return;\n\n const all = await loadMemoriesFromDir(paths.memoriesDir);\n const filePaths = parseCsv(opts.files);\n const tokens = opts.task ? tokenizeQuery(opts.task) : null;\n const maxMemories = Math.max(1, Number(opts.maxMemories ?? 10));\n const scopeFilter = opts.scope ?? \"team\";\n\n // Filter: exclude noise, drafts, and stale by default\n const candidates = all.filter(({ memory: mem }) => {\n const fm = mem.frontmatter;\n if (fm.status === \"rejected\" || fm.status === \"deprecated\") return false;\n if (!opts.includeDraft && fm.status === \"draft\") return false;\n if (!opts.includeStale && fm.status === \"stale\") return false;\n if (scopeFilter !== \"all\" && fm.scope !== scopeFilter) return false;\n return true;\n });\n\n // Score by relevance\n const scored = candidates.map(({ memory: mem, filePath }) => {\n const fm = mem.frontmatter;\n let score = 0;\n if (fm.status === \"validated\") score += 3;\n else if (fm.status === \"proposed\") score += 1;\n if (filePaths.length > 0 && memoryMatchesAnchorPaths(mem, filePaths)) score += 4;\n if (tokens && literalMatchesAllTokens(mem, tokens)) score += 3;\n return { memory: mem, filePath, score };\n });\n\n scored.sort((a, b) => b.score - a.score);\n const top = scored.slice(0, maxMemories);\n\n if (top.length === 0) {\n ui.info(\"No relevant memories found.\");\n const draftCount = all.filter(\n (m) =>\n m.memory.frontmatter.status === \"draft\" &&\n (scopeFilter === \"all\" || m.memory.frontmatter.scope === scopeFilter),\n ).length;\n if (draftCount > 0) {\n ui.info(`(${draftCount} draft memories excluded — use --include-draft to show)`);\n }\n return;\n }\n\n console.log(`${ui.bold(\"=== Relevant Memories ===\")}\\n`);\n for (const { memory: mem } of top) {\n const fm = mem.frontmatter;\n const badge = ui.statusBadge(fm.status);\n const draftMarker = fm.status === \"draft\" ? ui.yellow(\" [DRAFT]\") : \"\";\n const unverifiedMarker = fm.status === \"proposed\" ? ui.yellow(\" [UNVERIFIED]\") : \"\";\n console.log(\n `${ui.bold(fm.id)} ${ui.dim(fm.scope + \"/\" + fm.type)} ${badge}${draftMarker}${unverifiedMarker}`,\n );\n console.log(mem.body.trim());\n console.log();\n }\n console.log(ui.dim(`${top.length} memor${top.length === 1 ? \"y\" : \"ies\"} surfaced`));\n });\n}\n\nfunction parseCsv(value: string | undefined): string[] {\n if (!value) return [];\n return value.split(\",\").map((s) => s.trim()).filter(Boolean);\n}\n","import pc from \"picocolors\";\n\nexport const ui = {\n info: (msg: string) => console.log(pc.cyan(\"ℹ\"), msg),\n success: (msg: string) => console.log(pc.green(\"✓\"), msg),\n warn: (msg: string) => console.log(pc.yellow(\"⚠\"), msg),\n error: (msg: string) => console.error(pc.red(\"✗\"), msg),\n dim: (msg: string) => pc.dim(msg),\n bold: (msg: string) => pc.bold(msg),\n green: (msg: string) => pc.green(msg),\n yellow: (msg: string) => pc.yellow(msg),\n red: (msg: string) => pc.red(msg),\n statusBadge: (status: string): string => {\n switch (status) {\n case \"validated\": return pc.green(status);\n case \"proposed\": return pc.yellow(status);\n case \"stale\": return pc.yellow(status);\n case \"rejected\": return pc.red(status);\n case \"deprecated\": return pc.dim(status);\n default: return pc.dim(status); // draft\n }\n },\n};\n","import { Command } from \"commander\";\nimport { findProjectRoot } from \"@hiveai/core\";\n\nexport function registerTui(program: Command): void {\n program\n .command(\"tui\")\n .description(\"Interactive TUI dashboard — browse, filter, and manage memories in the terminal\")\n .option(\"-d, --dir <dir>\", \"project root\")\n .action(async (opts: { dir?: string }) => {\n if (!process.stdout.isTTY) {\n console.error(\"haive tui requires an interactive terminal (TTY).\");\n process.exitCode = 1;\n return;\n }\n const root = findProjectRoot(opts.dir);\n const { render } = await import(\"ink\");\n const { createElement } = await import(\"react\");\n const { Dashboard } = await import(\"../tui/Dashboard.js\");\n const { waitUntilExit } = render(createElement(Dashboard, { root }));\n await waitUntilExit();\n });\n}\n","import { existsSync } from \"node:fs\";\nimport path from \"node:path\";\nimport { Command } from \"commander\";\nimport { findProjectRoot, resolveHaivePaths } from \"@hiveai/core\";\nimport { ui } from \"../utils/ui.js\";\n\ninterface EmbeddingsOptions {\n dir?: string;\n}\n\ninterface EmbeddingsQueryOptions extends EmbeddingsOptions {\n limit?: string;\n minScore?: string;\n}\n\nexport function registerEmbeddings(program: Command): void {\n const embeddings = program\n .command(\"embeddings\")\n .description(\"Manage local embeddings index for semantic search\");\n\n embeddings\n .command(\"index\")\n .description(\"Generate or refresh the embeddings index for all memories\")\n .option(\"-d, --dir <dir>\", \"project root\")\n .action(async (opts: EmbeddingsOptions) => {\n const root = findProjectRoot(opts.dir);\n const paths = resolveHaivePaths(root);\n if (!existsSync(paths.memoriesDir)) {\n ui.error(`No .ai/memories at ${root}. Run \\`haive init\\` first.`);\n process.exitCode = 1;\n return;\n }\n const { Embedder, rebuildIndex } = await loadEmbeddings();\n ui.info(\"Loading embedding model (first run downloads ~110MB)…\");\n const embedder = await Embedder.create();\n ui.info(`Model ready: ${embedder.model} (dim=${embedder.dimension}). Indexing memories…`);\n const { report } = await rebuildIndex(paths, embedder);\n ui.success(\n `Indexed ${report.total} memories — added=${report.added} updated=${report.updated} unchanged=${report.unchanged} removed=${report.removed}`,\n );\n });\n\n embeddings\n .command(\"query <text>\")\n .description(\"Run a semantic search against the local embeddings index\")\n .option(\"-d, --dir <dir>\", \"project root\")\n .option(\"--limit <n>\", \"max results\", \"10\")\n .option(\"--min-score <n>\", \"minimum cosine similarity (0-1)\", \"0\")\n .action(async (text: string, opts: EmbeddingsQueryOptions) => {\n const root = findProjectRoot(opts.dir);\n const paths = resolveHaivePaths(root);\n const { semanticSearch } = await loadEmbeddings();\n const result = await semanticSearch(paths, text, {\n limit: Number(opts.limit ?? 10),\n minScore: Number(opts.minScore ?? 0),\n });\n if (!result) {\n ui.error(\"No embeddings index found. Run `haive embeddings index` first.\");\n process.exitCode = 1;\n return;\n }\n if (result.hits.length === 0) {\n ui.info(\"No semantic matches above the threshold.\");\n return;\n }\n for (const hit of result.hits) {\n const score = hit.score.toFixed(3);\n console.log(`${ui.bold(score)} ${hit.id}`);\n console.log(` ${ui.dim(path.relative(root, hit.file_path))}`);\n }\n });\n\n embeddings\n .command(\"status\")\n .description(\"Show the embeddings index status\")\n .option(\"-d, --dir <dir>\", \"project root\")\n .action(async (opts: EmbeddingsOptions) => {\n const root = findProjectRoot(opts.dir);\n const paths = resolveHaivePaths(root);\n const { indexStat } = await loadEmbeddings();\n const stat = await indexStat(paths);\n if (!stat.exists) {\n ui.warn(\"No embeddings index. Run `haive embeddings index` to create one.\");\n return;\n }\n console.log(`${ui.bold(\"entries:\")} ${stat.count}`);\n console.log(`${ui.bold(\"model:\")} ${stat.model}`);\n console.log(`${ui.bold(\"updated_at:\")} ${stat.updatedAt}`);\n console.log(`${ui.bold(\"size:\")} ${(stat.sizeBytes / 1024).toFixed(1)} KB`);\n });\n}\n\nasync function loadEmbeddings() {\n try {\n return await import(\"@hiveai/embeddings\");\n } catch {\n ui.error(\n \"Could not load @hiveai/embeddings. Run: npm install -g @hiveai/embeddings (or `pnpm build` in the monorepo)\",\n );\n process.exit(1);\n }\n}\n","import path from \"node:path\";\nimport { Command } from \"commander\";\nimport {\n buildCodeMap,\n codeMapPath,\n findProjectRoot,\n resolveHaivePaths,\n saveCodeMap,\n} from \"@hiveai/core\";\nimport { ui } from \"../utils/ui.js\";\n\ninterface IndexCodeOptions {\n dir?: string;\n exclude?: string;\n}\n\nexport function registerIndexCode(program: Command): void {\n const idx = program.command(\"index\").description(\"Build local indexes that help AIs read less code\");\n idx.action(() => idx.help());\n idx\n .command(\"code\")\n .description(\"Scan source files and write .ai/code-map.json (file → exports + 1-line description)\")\n .option(\"-d, --dir <dir>\", \"project root\")\n .option(\n \"--exclude <csv>\",\n \"extra directory names to skip (comma-separated)\",\n \"\",\n )\n .action(async (opts: IndexCodeOptions) => {\n const root = findProjectRoot(opts.dir);\n const paths = resolveHaivePaths(root);\n const extraExcludes = (opts.exclude ?? \"\")\n .split(\",\")\n .map((s) => s.trim())\n .filter(Boolean);\n\n ui.info(`Indexing source files in ${root}…`);\n const map = await buildCodeMap(root, {\n excludeDirs: [\n \"node_modules\",\n \"dist\",\n \"build\",\n \"out\",\n \".git\",\n \".next\",\n \".turbo\",\n \".vitest-cache\",\n \"coverage\",\n ...extraExcludes,\n ],\n });\n\n await saveCodeMap(paths, map);\n const fileCount = Object.keys(map.files).length;\n const exportCount = Object.values(map.files).reduce((s, f) => s + f.exports.length, 0);\n ui.success(\n `Indexed ${fileCount} file(s) with ${exportCount} export(s) → ${path.relative(root, codeMapPath(paths))}`,\n );\n });\n}\n","import { mkdir, writeFile } from \"node:fs/promises\";\nimport { existsSync } from \"node:fs\";\nimport path from \"node:path\";\nimport { Command } from \"commander\";\nimport { findProjectRoot, resolveHaivePaths } from \"@hiveai/core\";\nimport { ui } from \"../utils/ui.js\";\n\nconst PROJECT_CONTEXT_TEMPLATE = `# Project context\n\n> Generated by \\`haive init\\`. Edit this file (or let your AI agent fill it via the upcoming MCP \\`bootstrap_project\\` tool).\n\n## Architecture\nTODO — high-level overview of the codebase.\n\n## Key modules\nTODO — list main modules and their purpose.\n\n## Conventions\nTODO — coding conventions, naming, patterns the team follows.\n\n## Glossary\nTODO — domain terms and what they mean here.\n\n## Gotchas\nTODO — known traps, surprising behavior, things newcomers stub their toes on.\n`;\n\nconst BRIDGE_BODY = `<!-- hAIve bridge file — do not edit by hand. -->\n<!-- This file points your AI tool at the shared hAIve project context. -->\n\nSee \\`.ai/project-context.md\\` for the full project context.\nMemories live under \\`.ai/memories/\\` (personal/team/module).\n\n## hAIve — mandatory rules for AI agents\n- **Before** marking a task as done (\"Done\", \"Finished\", \"C'est fait\"), call the MCP prompt \\`post_task\\`.\n- **Immediately** when an approach fails (wrong API, wrong pattern, wrong assumption), call \\`mem_tried\\` — do not wait until the end of the session.\n- When starting a new task, call \\`get_briefing\\` with the task description to load relevant memories and avoid repeating past mistakes.\n`;\n\nconst CI_WORKFLOW = `name: haive-sync\n\non:\n push:\n branches: [main, master]\n pull_request:\n paths:\n - '.ai/**'\n\njobs:\n sync:\n runs-on: ubuntu-latest\n steps:\n - uses: actions/checkout@v4\n with:\n fetch-depth: 0\n\n - uses: actions/setup-node@v4\n with:\n node-version: '20'\n\n - name: Install hAIve CLI\n run: npm install -g @haive/cli\n\n - name: Sync memories (verify anchors + auto-promote)\n run: haive sync --quiet\n\n - name: Commit updated memories (if any)\n run: |\n git config user.name \"github-actions[bot]\"\n git config user.email \"github-actions[bot]@users.noreply.github.com\"\n git add .ai/\n git diff --cached --quiet || git commit -m \"chore: haive sync [skip ci]\"\n git push\n`;\n\nexport function registerInit(program: Command): void {\n program\n .command(\"init\")\n .description(\"Initialize a hAIve project (.ai/ structure + bridge files)\")\n .option(\"-d, --dir <dir>\", \"project root\", process.cwd())\n .option(\"--no-bridges\", \"do not generate CLAUDE.md / .cursorrules / copilot-instructions.md\")\n .option(\"--with-ci\", \"write a GitHub Actions workflow (.github/workflows/haive-sync.yml)\")\n .action(async (opts: { dir: string; bridges: boolean; withCi?: boolean }) => {\n const root = path.resolve(opts.dir);\n const paths = resolveHaivePaths(root);\n\n if (existsSync(paths.haiveDir)) {\n ui.warn(`.ai/ already exists at ${paths.haiveDir} — leaving existing files in place.`);\n }\n\n await mkdir(paths.personalDir, { recursive: true });\n await mkdir(paths.teamDir, { recursive: true });\n await mkdir(paths.moduleDir, { recursive: true });\n await mkdir(paths.modulesContextDir, { recursive: true });\n\n if (!existsSync(paths.projectContext)) {\n await writeFile(paths.projectContext, PROJECT_CONTEXT_TEMPLATE, \"utf8\");\n ui.success(`Created ${path.relative(root, paths.projectContext)}`);\n }\n\n if (opts.bridges) {\n await writeBridge(root, \"CLAUDE.md\");\n await writeBridge(root, \".cursorrules\");\n await writeBridge(root, path.join(\".github\", \"copilot-instructions.md\"));\n }\n\n if (opts.withCi) {\n const ciPath = path.join(root, \".github\", \"workflows\", \"haive-sync.yml\");\n if (existsSync(ciPath)) {\n ui.info(\"CI workflow already exists — skipped\");\n } else {\n await mkdir(path.dirname(ciPath), { recursive: true });\n await writeFile(ciPath, CI_WORKFLOW, \"utf8\");\n ui.success(`Created ${path.relative(root, ciPath)}`);\n }\n }\n\n ui.success(`hAIve initialized at ${root}`);\n ui.info(\"Next: \" + ui.bold(\"haive memory add --type convention --slug <name>\"));\n });\n}\n\nasync function writeBridge(root: string, relPath: string): Promise<void> {\n const target = path.join(root, relPath);\n if (existsSync(target)) {\n ui.info(`Bridge ${relPath} already exists — skipped`);\n return;\n }\n await mkdir(path.dirname(target), { recursive: true });\n await writeFile(target, BRIDGE_BODY, \"utf8\");\n ui.success(`Created bridge ${relPath}`);\n}\n\n","import { mkdir, writeFile, chmod, readFile } from \"node:fs/promises\";\nimport { existsSync } from \"node:fs\";\nimport path from \"node:path\";\nimport { Command } from \"commander\";\nimport { findProjectRoot } from \"@hiveai/core\";\nimport { ui } from \"../utils/ui.js\";\n\ninterface InstallHooksOptions {\n dir?: string;\n force?: boolean;\n}\n\nconst HOOK_MARKER = \"# hAIve auto-generated\";\n\nconst HOOK_BODY = `#!/bin/sh\n${HOOK_MARKER} — keep this block to allow upgrades. Hand-edit anything outside it.\n\n# After a merge or pull, refresh memory anchors and auto-promote eligible\n# memories so that everyone on this branch sees consistent confidence levels.\nif command -v haive >/dev/null 2>&1; then\n haive sync --quiet --since ORIG_HEAD || true\nelif [ -x ./node_modules/.bin/haive ]; then\n ./node_modules/.bin/haive sync --quiet --since ORIG_HEAD || true\nfi\n`;\n\nconst HOOKS = [\"post-merge\", \"post-rewrite\"] as const;\n\nexport function registerInstallHooks(program: Command): void {\n program\n .command(\"install-hooks\")\n .description(\"Install git hooks that run `haive sync` after pull/merge\")\n .option(\"-d, --dir <dir>\", \"project root\")\n .option(\"--force\", \"overwrite existing hooks\")\n .action(async (opts: InstallHooksOptions) => {\n const root = findProjectRoot(opts.dir);\n const gitDir = path.join(root, \".git\");\n if (!existsSync(gitDir)) {\n ui.error(`No .git directory at ${root}.`);\n process.exitCode = 1;\n return;\n }\n const hooksDir = path.join(gitDir, \"hooks\");\n await mkdir(hooksDir, { recursive: true });\n\n let installed = 0;\n let skipped = 0;\n for (const name of HOOKS) {\n const file = path.join(hooksDir, name);\n if (existsSync(file) && !opts.force) {\n const existing = await readFile(file, \"utf8\");\n if (!existing.includes(HOOK_MARKER)) {\n ui.warn(`${name} already exists and was not written by hAIve. Re-run with --force to overwrite.`);\n skipped++;\n continue;\n }\n }\n await writeFile(file, HOOK_BODY, \"utf8\");\n await chmod(file, 0o755);\n installed++;\n }\n ui.success(`Installed ${installed} hook(s) in .git/hooks/${skipped ? `, skipped ${skipped}` : \"\"}`);\n ui.info(\"Test with: git pull (or any merge), then check .ai/memories for status updates.\");\n });\n}\n","import { spawn } from \"node:child_process\";\nimport { existsSync } from \"node:fs\";\nimport { createRequire } from \"node:module\";\nimport path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { Command } from \"commander\";\nimport { findProjectRoot } from \"@hiveai/core\";\nimport { ui } from \"../utils/ui.js\";\n\nconst require = createRequire(import.meta.url);\n\ninterface McpOptions {\n dir?: string;\n}\n\nexport function registerMcp(program: Command): void {\n program\n .command(\"mcp\")\n .description(\"Start the hAIve MCP server (stdio transport)\")\n .option(\"-d, --dir <dir>\", \"project root (defaults to nearest .ai/ or .git/)\")\n .action((opts: McpOptions) => {\n const root = findProjectRoot(opts.dir);\n const bin = locateMcpBin();\n if (!bin) {\n ui.error(\n \"@hiveai/mcp binary not found. Install @hiveai/mcp or run `pnpm build` in the monorepo.\",\n );\n process.exit(1);\n }\n const child = spawn(\"node\", [bin, \"--root\", root], {\n stdio: [\"inherit\", \"inherit\", \"inherit\"],\n env: process.env,\n });\n child.on(\"exit\", (code) => process.exit(code ?? 0));\n });\n}\n\nfunction locateMcpBin(): string | null {\n // 1. Resolve the @hiveai/mcp package and use its bin entry.\n try {\n const pkgPath = require.resolve(\"@hiveai/mcp/package.json\");\n const pkgDir = path.dirname(pkgPath);\n const candidate = path.join(pkgDir, \"dist\", \"index.js\");\n if (existsSync(candidate)) return candidate;\n } catch {\n // not installed — fall through\n }\n\n // 2. Fallback: look for sibling package in monorepo dev mode.\n const here = path.dirname(fileURLToPath(import.meta.url));\n const sibling = path.resolve(here, \"..\", \"..\", \"..\", \"mcp\", \"dist\", \"index.js\");\n if (existsSync(sibling)) return sibling;\n\n return null;\n}\n","import { spawnSync } from \"node:child_process\";\nimport { readFile, writeFile } from \"node:fs/promises\";\nimport { existsSync } from \"node:fs\";\nimport path from \"node:path\";\nimport { Command } from \"commander\";\nimport {\n DEFAULT_AUTO_PROMOTE_RULE,\n findProjectRoot,\n getUsage,\n isAutoPromoteEligible,\n isDecaying,\n loadMemoriesFromDir,\n loadUsageIndex,\n resolveHaivePaths,\n serializeMemory,\n verifyAnchor,\n} from \"@hiveai/core\";\nimport { ui } from \"../utils/ui.js\";\n\nconst BRIDGE_START = \"<!-- haive:memories-start -->\";\nconst BRIDGE_END = \"<!-- haive:memories-end -->\";\n\ninterface SyncOptions {\n dir?: string;\n quiet?: boolean;\n since?: string;\n verify?: boolean;\n promote?: boolean;\n injectBridge?: boolean;\n bridgeFile?: string;\n bridgeMaxMemories?: string;\n embed?: boolean;\n}\n\nexport function registerSync(program: Command): void {\n program\n .command(\"sync\")\n .description(\"Refresh memory state after a pull/merge: verify anchors, auto-promote, report changes\")\n .option(\"-d, --dir <dir>\", \"project root\")\n .option(\"--quiet\", \"minimal output (suitable for git hooks)\")\n .option(\n \"--since <ref>\",\n \"git ref/commit to compare against; report memories added/modified/removed since\",\n )\n .option(\"--no-verify\", \"skip the anchor verification step\")\n .option(\"--no-promote\", \"skip the auto-promotion step\")\n .option(\n \"--inject-bridge\",\n \"inject top validated memories into CLAUDE.md (or --bridge-file) between <!-- haive:memories-start/end --> markers\",\n )\n .option(\"--bridge-file <path>\", \"bridge file to inject into (default: CLAUDE.md)\")\n .option(\"--bridge-max-memories <n>\", \"max memories to inject into bridge file\", \"5\")\n .option(\"--embed\", \"rebuild embeddings index after sync (requires @haive/embeddings)\")\n .action(async (opts: SyncOptions) => {\n const root = findProjectRoot(opts.dir);\n const paths = resolveHaivePaths(root);\n if (!existsSync(paths.memoriesDir)) {\n if (!opts.quiet) ui.warn(`No .ai/memories at ${root}. Run \\`haive init\\` first.`);\n process.exitCode = 1;\n return;\n }\n\n const log = (msg: string): void => {\n if (!opts.quiet) console.log(msg);\n };\n\n let staleMarked = 0;\n let revalidated = 0;\n let promoted = 0;\n\n if (opts.verify !== false) {\n const memories = await loadMemoriesFromDir(paths.memoriesDir);\n for (const { memory, filePath } of memories) {\n const isAnchored =\n memory.frontmatter.anchor.paths.length > 0 ||\n memory.frontmatter.anchor.symbols.length > 0;\n if (!isAnchored) continue;\n\n const result = await verifyAnchor(memory, { projectRoot: root });\n const verifiedAt = new Date().toISOString();\n\n if (result.stale) {\n if (memory.frontmatter.status !== \"stale\") {\n await writeFile(\n filePath,\n serializeMemory({\n frontmatter: {\n ...memory.frontmatter,\n status: \"stale\",\n verified_at: verifiedAt,\n stale_reason: result.reason,\n },\n body: memory.body,\n }),\n \"utf8\",\n );\n staleMarked++;\n }\n } else if (memory.frontmatter.status === \"stale\") {\n await writeFile(\n filePath,\n serializeMemory({\n frontmatter: {\n ...memory.frontmatter,\n status: \"validated\",\n verified_at: verifiedAt,\n stale_reason: null,\n },\n body: memory.body,\n }),\n \"utf8\",\n );\n revalidated++;\n }\n }\n }\n\n if (opts.promote !== false) {\n const memories = await loadMemoriesFromDir(paths.memoriesDir);\n const usage = await loadUsageIndex(paths);\n for (const { memory, filePath } of memories) {\n if (\n isAutoPromoteEligible(\n memory.frontmatter,\n getUsage(usage, memory.frontmatter.id),\n DEFAULT_AUTO_PROMOTE_RULE,\n )\n ) {\n await writeFile(\n filePath,\n serializeMemory({\n frontmatter: { ...memory.frontmatter, status: \"validated\" },\n body: memory.body,\n }),\n \"utf8\",\n );\n promoted++;\n }\n }\n }\n\n const sinceReport = opts.since ? collectSinceChanges(root, opts.since) : null;\n\n const draftMemories = (await loadMemoriesFromDir(paths.memoriesDir)).filter(\n (m) => m.memory.frontmatter.status === \"draft\",\n );\n const draftCount = draftMemories.length;\n\n log(\n `${ui.dim(\"sync:\")} ${staleMarked} stale · ${revalidated} revalidated · ${promoted} promoted${sinceReport ? ` · ${sinceReport.added.length}+/${sinceReport.modified.length}~/${sinceReport.removed.length}- since ${opts.since}` : \"\"}`,\n );\n if (!opts.quiet && draftCount > 0) {\n log(\n ui.dim(\n `ℹ ${draftCount} memor${draftCount === 1 ? \"y\" : \"ies\"} in draft — run \\`haive memory approve <id>\\` to activate or \\`haive memory list --status draft\\` to review`,\n ),\n );\n }\n\n if (opts.injectBridge) {\n const bridgeFile = opts.bridgeFile\n ? path.resolve(opts.bridgeFile)\n : path.join(root, \"CLAUDE.md\");\n const maxInject = Math.max(1, Number(opts.bridgeMaxMemories ?? 5));\n await injectBridge(bridgeFile, paths.memoriesDir, maxInject, root, opts.quiet);\n }\n\n if (sinceReport && !opts.quiet) {\n if (sinceReport.added.length > 0) {\n log(ui.bold(\"\\nNew memories:\"));\n for (const f of sinceReport.added) log(` + ${f}`);\n }\n if (sinceReport.modified.length > 0) {\n log(ui.bold(\"\\nModified:\"));\n for (const f of sinceReport.modified) log(` ~ ${f}`);\n }\n if (sinceReport.removed.length > 0) {\n log(ui.bold(\"\\nRemoved:\"));\n for (const f of sinceReport.removed) log(` - ${f}`);\n }\n }\n\n // Decay report: memories not read in >90 days\n if (!opts.quiet) {\n const allForDecay = await loadMemoriesFromDir(paths.memoriesDir);\n const usageForDecay = await loadUsageIndex(paths);\n const decaying = allForDecay.filter(({ memory }) => {\n const fm = memory.frontmatter;\n if (fm.status === \"rejected\" || fm.status === \"deprecated\" || fm.status === \"stale\") return false;\n const u = getUsage(usageForDecay, fm.id);\n return isDecaying(u, fm.created_at);\n });\n if (decaying.length > 0) {\n log(ui.yellow(`\\n⚠ ${decaying.length} memor${decaying.length === 1 ? \"y\" : \"ies\"} not read in >90 days (consider reviewing or deprecating):`));\n for (const { memory } of decaying) {\n log(ui.dim(` ${memory.frontmatter.id}`));\n }\n }\n }\n\n // --embed: rebuild embeddings index after sync\n if (opts.embed) {\n try {\n const emb = await import(\"@hiveai/embeddings\");\n log(ui.dim(\"embed: rebuilding index…\"));\n const report = await emb.rebuildIndex(paths);\n log(ui.dim(`embed: index rebuilt (${report.added} added, ${report.updated} updated, ${report.removed} removed)`));\n } catch {\n ui.warn(\"--embed: @hiveai/embeddings not available or index build failed. Run `haive embeddings index` manually.\");\n }\n }\n });\n}\n\nasync function injectBridge(\n bridgeFile: string,\n memoriesDir: string,\n maxMemories: number,\n root: string,\n quiet?: boolean,\n): Promise<void> {\n if (!existsSync(memoriesDir)) return;\n\n const all = await loadMemoriesFromDir(memoriesDir);\n const top = all\n .filter(({ memory }) => {\n const s = memory.frontmatter.status;\n return s === \"validated\" || s === \"proposed\";\n })\n .sort((a, b) => {\n const score = (m: typeof a) => {\n const s = m.memory.frontmatter.status;\n return (s === \"validated\" ? 2 : 1);\n };\n return score(b) - score(a);\n })\n .slice(0, maxMemories);\n\n const block = top\n .map((m) => {\n const fm = m.memory.frontmatter;\n const unverified = fm.status === \"proposed\" ? \" [UNVERIFIED]\" : \"\";\n return `### ${fm.id} (${fm.scope}/${fm.type})${unverified}\\n${m.memory.body.trim()}`;\n })\n .join(\"\\n\\n---\\n\\n\");\n\n const injected =\n `${BRIDGE_START}\\n` +\n `<!-- AUTO-GENERATED by haive sync --inject-bridge — do not edit between these markers -->\\n\\n` +\n block +\n `\\n\\n${BRIDGE_END}`;\n\n const fileExists = existsSync(bridgeFile);\n let existing = fileExists ? await readFile(bridgeFile, \"utf8\") : \"\";\n // Normalize line endings to avoid \\r\\n accumulation\n existing = existing.replace(/\\r\\n/g, \"\\n\");\n\n const startIdx = existing.indexOf(BRIDGE_START);\n const endIdx = existing.indexOf(BRIDGE_END);\n\n // Detect partial markers — safer to abort than silently corrupt the file\n if (startIdx !== -1 && endIdx === -1) {\n ui.warn(`${path.relative(root, bridgeFile)}: found ${BRIDGE_START} without ${BRIDGE_END}. Fix the file manually before running --inject-bridge.`);\n return;\n }\n if (startIdx === -1 && endIdx !== -1) {\n ui.warn(`${path.relative(root, bridgeFile)}: found ${BRIDGE_END} without ${BRIDGE_START}. Fix the file manually before running --inject-bridge.`);\n return;\n }\n\n let updated: string;\n if (startIdx !== -1 && endIdx !== -1 && endIdx > startIdx) {\n updated = existing.slice(0, startIdx) + injected + existing.slice(endIdx + BRIDGE_END.length);\n } else {\n if (!fileExists && !quiet) {\n ui.info(`Creating ${path.relative(root, bridgeFile)} with haive memory block.`);\n }\n updated = existing + (existing.endsWith(\"\\n\") ? \"\" : \"\\n\") + \"\\n\" + injected + \"\\n\";\n }\n\n await writeFile(bridgeFile, updated, \"utf8\");\n if (!quiet) {\n console.log(\n ui.dim(`bridge: injected ${top.length} memor${top.length === 1 ? \"y\" : \"ies\"} into ${path.relative(root, bridgeFile)}`),\n );\n }\n}\n\ninterface SinceReport {\n added: string[];\n modified: string[];\n removed: string[];\n}\n\nfunction collectSinceChanges(root: string, ref: string): SinceReport | null {\n const result = spawnSync(\n \"git\",\n [\"-C\", root, \"diff\", \"--name-status\", \"--diff-filter=AMD\", `${ref}...HEAD`, \"--\", \".ai/memories\"],\n { encoding: \"utf8\" },\n );\n if (result.status !== 0) return null;\n\n const report: SinceReport = { added: [], modified: [], removed: [] };\n for (const line of result.stdout.split(\"\\n\")) {\n const [status, ...rest] = line.split(\"\\t\");\n const file = rest.join(\"\\t\").trim();\n if (!file) continue;\n if (status === \"A\") report.added.push(file);\n else if (status === \"M\") report.modified.push(file);\n else if (status === \"D\") report.removed.push(file);\n }\n return report;\n}\n","import { mkdir, readFile, writeFile } from \"node:fs/promises\";\nimport { existsSync } from \"node:fs\";\nimport path from \"node:path\";\nimport { Command } from \"commander\";\nimport {\n buildFrontmatter,\n findProjectRoot,\n inferModulesFromPaths,\n loadMemoriesFromDir,\n memoryFilePath,\n resolveHaivePaths,\n serializeMemory,\n type MemoryScope,\n type MemoryType,\n} from \"@hiveai/core\";\nimport { ui } from \"../utils/ui.js\";\n\ninterface AddOptions {\n type: MemoryType;\n slug: string;\n title?: string;\n scope?: MemoryScope;\n module?: string;\n tags?: string;\n domain?: string;\n author?: string;\n paths?: string;\n symbols?: string;\n commit?: string;\n body?: string;\n bodyFile?: string;\n dir?: string;\n}\n\nexport function registerMemoryAdd(memory: Command): void {\n memory\n .command(\"add\")\n .description(\"Add a new memory (defaults to personal scope)\")\n .requiredOption(\"--type <type>\", \"convention | decision | gotcha | architecture | glossary | attempt\")\n .requiredOption(\"--slug <slug>\", \"short identifier used in the file name\")\n .option(\"--title <text>\", \"memory title — becomes the first heading of the body\")\n .option(\"--scope <scope>\", \"personal | team | module\", \"personal\")\n .option(\"--module <name>\", \"module name (required when scope=module)\")\n .option(\"--tags <csv>\", \"comma-separated tags\")\n .option(\"--domain <domain>\", \"domain (e.g. transactions)\")\n .option(\"--author <author>\", \"author email or handle\")\n .option(\"--paths <csv>\", \"anchor paths, comma-separated\")\n .option(\"--symbols <csv>\", \"anchor symbols, comma-separated\")\n .option(\"--commit <sha>\", \"anchor commit SHA\")\n .option(\"--body <text>\", \"memory body content (Markdown) — overrides --title default body\")\n .option(\"--body-file <path>\", \"read memory body from a Markdown file — alternative to --body for long content\")\n .option(\"--no-auto-tag\", \"disable automatic tag suggestions inferred from anchor paths\")\n .option(\"-d, --dir <dir>\", \"project root\")\n .action(async (opts: AddOptions & { autoTag?: boolean }) => {\n const root = findProjectRoot(opts.dir);\n const paths = resolveHaivePaths(root);\n if (!existsSync(paths.haiveDir)) {\n ui.error(`No .ai/ found at ${root}. Run \\`haive init\\` first.`);\n process.exitCode = 1;\n return;\n }\n\n const userTags = parseCsv(opts.tags);\n const anchorPaths = parseCsv(opts.paths);\n const autoTagsEnabled = opts.autoTag !== false;\n const inferredTags = autoTagsEnabled ? inferModulesFromPaths(anchorPaths) : [];\n const mergedTags = Array.from(new Set([...userTags, ...inferredTags]));\n\n const frontmatter = buildFrontmatter({\n type: opts.type,\n slug: opts.slug,\n scope: opts.scope,\n module: opts.module,\n tags: mergedTags,\n domain: opts.domain,\n author: opts.author,\n paths: anchorPaths,\n symbols: parseCsv(opts.symbols),\n commit: opts.commit,\n });\n\n const title = opts.title ?? opts.slug;\n let body: string;\n if (opts.bodyFile !== undefined) {\n if (!existsSync(opts.bodyFile)) {\n ui.error(`--body-file not found: ${opts.bodyFile}`);\n process.exitCode = 1;\n return;\n }\n const fileContent = await readFile(opts.bodyFile, \"utf8\");\n body = opts.title ? `# ${opts.title}\\n\\n${fileContent.trim()}\\n` : fileContent;\n } else if (opts.body !== undefined) {\n body = opts.title ? `# ${opts.title}\\n\\n${opts.body}` : opts.body;\n } else {\n body = `# ${title}\\n\\nTODO — write the memory body.\\n`;\n }\n\n const file = memoryFilePath(paths, frontmatter.scope, frontmatter.id, frontmatter.module);\n await mkdir(path.dirname(file), { recursive: true });\n\n if (existsSync(file)) {\n ui.error(`Memory already exists at ${file}`);\n process.exitCode = 1;\n return;\n }\n\n // Dedup check: warn if a similar slug already exists\n if (existsSync(paths.memoriesDir)) {\n const existing = await loadMemoriesFromDir(paths.memoriesDir);\n const slugTokens = opts.slug.toLowerCase().split(/[-_\\s]+/).filter(Boolean);\n const similar = existing.filter(({ memory }) => {\n const id = memory.frontmatter.id.toLowerCase();\n return (\n slugTokens.length >= 2 &&\n slugTokens.filter((t) => id.includes(t)).length >= Math.ceil(slugTokens.length * 0.6)\n );\n });\n if (similar.length > 0) {\n ui.warn(`Possible duplicate — similar memories exist: ${similar.map((m) => m.memory.frontmatter.id).join(\", \")}`);\n ui.warn(\"Consider updating one of these with \\`haive memory update\\` instead.\");\n }\n }\n\n await writeFile(file, serializeMemory({ frontmatter, body }), \"utf8\");\n ui.success(`Created ${path.relative(root, file)}`);\n ui.info(`id=${frontmatter.id} scope=${frontmatter.scope} status=${frontmatter.status}`);\n if (inferredTags.length > 0) {\n ui.info(`auto-tagged: ${inferredTags.join(\", \")} (use --no-auto-tag to disable)`);\n }\n\n // Workflow hint\n if (frontmatter.scope === \"personal\") {\n console.log(\n ui.dim(\n `→ next: haive memory approve ${frontmatter.id} (activate)` +\n ` | haive memory promote ${frontmatter.id} (share with team)`,\n ),\n );\n } else {\n console.log(\n ui.dim(`→ next: haive memory approve ${frontmatter.id} (mark as validated)`),\n );\n }\n });\n}\n\nfunction parseCsv(value: string | undefined): string[] {\n if (!value) return [];\n return value\n .split(\",\")\n .map((s) => s.trim())\n .filter(Boolean);\n}\n","import { existsSync } from \"node:fs\";\nimport path from \"node:path\";\nimport { Command } from \"commander\";\nimport { findProjectRoot, resolveHaivePaths, type MemoryScope, type MemoryType } from \"@hiveai/core\";\nimport { loadMemoriesFromDir, type LoadedMemory } from \"../utils/fs.js\";\nimport { ui } from \"../utils/ui.js\";\n\ninterface ListOptions {\n scope?: MemoryScope;\n type?: MemoryType;\n tag?: string;\n module?: string;\n status?: string;\n showRejected?: boolean;\n dir?: string;\n}\n\nexport function registerMemoryList(memory: Command): void {\n memory\n .command(\"list\")\n .description(\"List memories with optional filters\")\n .option(\"--scope <scope>\", \"personal | team | module\")\n .option(\"--type <type>\", \"filter by type\")\n .option(\"--tag <tag>\", \"filter by tag\")\n .option(\"--module <name>\", \"filter by module name\")\n .option(\"--status <csv>\", \"filter by status (draft,proposed,validated,stale,rejected,deprecated)\")\n .option(\"--show-rejected\", \"include rejected memories (hidden by default)\")\n .option(\"-d, --dir <dir>\", \"project root\")\n .action(async (opts: ListOptions) => {\n const root = findProjectRoot(opts.dir);\n const paths = resolveHaivePaths(root);\n if (!existsSync(paths.memoriesDir)) {\n ui.error(`No memories directory at ${paths.memoriesDir}. Run \\`haive init\\` first.`);\n process.exitCode = 1;\n return;\n }\n\n const all = await loadMemoriesFromDir(paths.memoriesDir);\n const statusFilter = opts.status ? opts.status.split(\",\").map((s) => s.trim()) : null;\n const filtered = all.filter((m) => {\n if (!matchesFilters(m, opts)) return false;\n const status = m.memory.frontmatter.status;\n if (!opts.showRejected && !statusFilter && status === \"rejected\") return false;\n if (statusFilter && !statusFilter.includes(status)) return false;\n return true;\n });\n\n // Count hidden rejected (not covered by an explicit status filter)\n const hiddenRejectedCount =\n !opts.showRejected && !statusFilter\n ? all.filter(\n (m) => matchesFilters(m, opts) && m.memory.frontmatter.status === \"rejected\",\n ).length\n : 0;\n\n if (filtered.length === 0) {\n ui.info(\"No memories match the filters.\");\n if (hiddenRejectedCount > 0) {\n ui.info(`(${hiddenRejectedCount} rejected hidden — use --show-rejected to include)`);\n }\n return;\n }\n\n for (const { memory: mem, filePath } of filtered) {\n const fm = mem.frontmatter;\n const tagStr = fm.tags.length ? ui.dim(` [${fm.tags.join(\", \")}]`) : \"\";\n const moduleStr = fm.module ? ui.dim(` (${fm.module})`) : \"\";\n const statusBadge = ui.statusBadge(fm.status);\n console.log(\n `${ui.bold(fm.id)} ${ui.dim(fm.scope)}/${ui.dim(fm.type)} ${statusBadge}${moduleStr}${tagStr}`,\n );\n console.log(` ${ui.dim(path.relative(root, filePath))}`);\n }\n console.log(ui.dim(`\\n${filtered.length} memor${filtered.length === 1 ? \"y\" : \"ies\"}`));\n\n // Always show rejected hint when memories are hidden\n if (hiddenRejectedCount > 0) {\n console.log(\n ui.dim(`(${hiddenRejectedCount} rejected hidden — use --show-rejected to include)`),\n );\n }\n\n // Draft hint: scope-aware\n const draftItems = filtered.filter((m) => m.memory.frontmatter.status === \"draft\");\n if (draftItems.length > 0) {\n const hasPersonalDrafts = draftItems.some(\n (m) => m.memory.frontmatter.scope === \"personal\",\n );\n const hasTeamDrafts = draftItems.some(\n (m) => m.memory.frontmatter.scope !== \"personal\",\n );\n let hint = `ℹ ${draftItems.length} in draft — use \\`haive memory approve <id>\\` to activate`;\n if (hasPersonalDrafts && !hasTeamDrafts) {\n hint += \" or `haive memory promote <id>` to share with team\";\n }\n console.log(ui.dim(hint));\n }\n });\n}\n\nfunction matchesFilters(loaded: LoadedMemory, opts: ListOptions): boolean {\n const fm = loaded.memory.frontmatter;\n if (opts.scope && fm.scope !== opts.scope) return false;\n if (opts.type && fm.type !== opts.type) return false;\n if (opts.tag && !fm.tags.includes(opts.tag)) return false;\n if (opts.module && fm.module !== opts.module) return false;\n return true;\n}\n","export {\n loadMemoriesFromDir,\n loadMemory,\n listMarkdownFilesRecursive,\n type LoadedMemory,\n} from \"@hiveai/core\";\n","import { mkdir, unlink, writeFile } from \"node:fs/promises\";\nimport { existsSync } from \"node:fs\";\nimport path from \"node:path\";\nimport { Command } from \"commander\";\nimport {\n findProjectRoot,\n memoryFilePath,\n resolveHaivePaths,\n serializeMemory,\n} from \"@hiveai/core\";\nimport { loadMemoriesFromDir } from \"../utils/fs.js\";\nimport { ui } from \"../utils/ui.js\";\n\ninterface PromoteOptions {\n dir?: string;\n}\n\nexport function registerMemoryPromote(memory: Command): void {\n memory\n .command(\"promote <id>\")\n .description(\"Promote a personal memory to team scope (status -> proposed)\")\n .option(\"-d, --dir <dir>\", \"project root\")\n .action(async (id: string, opts: PromoteOptions) => {\n const root = findProjectRoot(opts.dir);\n const paths = resolveHaivePaths(root);\n if (!existsSync(paths.memoriesDir)) {\n ui.error(`No memories directory at ${paths.memoriesDir}. Run \\`haive init\\` first.`);\n process.exitCode = 1;\n return;\n }\n\n // Check team/module scope first to give a helpful error\n const teamAndModule = await loadMemoriesFromDir(paths.memoriesDir);\n const alreadyShared = teamAndModule.find(\n (m) =>\n m.memory.frontmatter.id === id &&\n (m.memory.frontmatter.scope === \"team\" || m.memory.frontmatter.scope === \"module\"),\n );\n if (alreadyShared) {\n const fm = alreadyShared.memory.frontmatter;\n ui.warn(\n `\"${id}\" is already in ${fm.scope} scope (status=${fm.status}).`,\n );\n if (fm.status !== \"validated\") {\n ui.info(`→ run \\`haive memory approve ${id}\\` to validate it`);\n }\n return;\n }\n\n const all = await loadMemoriesFromDir(paths.personalDir);\n const found = all.find((m) => m.memory.frontmatter.id === id);\n if (!found) {\n ui.error(`No personal memory with id \"${id}\". (Promotion only applies to personal scope.)`);\n process.exitCode = 1;\n return;\n }\n\n const updated = {\n frontmatter: {\n ...found.memory.frontmatter,\n scope: \"team\" as const,\n status: \"proposed\" as const,\n },\n body: found.memory.body,\n };\n\n const newPath = memoryFilePath(paths, \"team\", updated.frontmatter.id);\n await mkdir(path.dirname(newPath), { recursive: true });\n await writeFile(newPath, serializeMemory(updated), \"utf8\");\n await unlink(found.filePath);\n\n ui.success(`Promoted ${id} to team scope (status=proposed)`);\n ui.info(`Now at ${path.relative(root, newPath)}`);\n console.log(ui.dim(`→ next: haive memory approve ${id} (validate for team use)`));\n });\n}\n","import { existsSync } from \"node:fs\";\nimport { writeFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { Command } from \"commander\";\nimport {\n findProjectRoot,\n resolveHaivePaths,\n serializeMemory,\n} from \"@hiveai/core\";\nimport { loadMemoriesFromDir } from \"../utils/fs.js\";\nimport { ui } from \"../utils/ui.js\";\n\ninterface ApproveOptions {\n all?: boolean;\n pending?: boolean;\n dir?: string;\n}\n\nexport function registerMemoryApprove(memory: Command): void {\n memory\n .command(\"approve [id]\")\n .description(\"Mark a memory as 'validated'. Use --all to bulk-approve all proposed/draft memories.\")\n .option(\"--all\", \"approve all proposed and draft memories at once\")\n .option(\"--pending\", \"approve all memories with status 'proposed'\")\n .option(\"-d, --dir <dir>\", \"project root\")\n .action(async (id: string | undefined, opts: ApproveOptions) => {\n const root = findProjectRoot(opts.dir);\n const paths = resolveHaivePaths(root);\n if (!existsSync(paths.memoriesDir)) {\n ui.error(`No .ai/memories at ${root}.`);\n process.exitCode = 1;\n return;\n }\n\n const all = await loadMemoriesFromDir(paths.memoriesDir);\n\n // Bulk mode\n if (opts.all || opts.pending) {\n const candidates = all.filter((m) => {\n const s = m.memory.frontmatter.status;\n if (opts.all) return s === \"proposed\" || s === \"draft\";\n return s === \"proposed\";\n });\n if (candidates.length === 0) {\n ui.info(opts.all ? \"No draft or proposed memories to approve.\" : \"No proposed memories to approve.\");\n return;\n }\n let count = 0;\n for (const found of candidates) {\n const next = {\n frontmatter: { ...found.memory.frontmatter, status: \"validated\" as const },\n body: found.memory.body,\n };\n await writeFile(found.filePath, serializeMemory(next), \"utf8\");\n count++;\n }\n ui.success(`Approved ${count} memor${count === 1 ? \"y\" : \"ies\"} (status=validated)`);\n return;\n }\n\n // Single mode\n if (!id) {\n ui.error(\"Provide a memory id or use --all / --pending for bulk approval.\");\n process.exitCode = 1;\n return;\n }\n\n const found = all.find((m) => m.memory.frontmatter.id === id);\n if (!found) {\n ui.error(`No memory with id \"${id}\".`);\n process.exitCode = 1;\n return;\n }\n\n const current = found.memory.frontmatter.status;\n if (current === \"validated\") {\n ui.info(`${id} is already validated.`);\n return;\n }\n if (current !== \"proposed\" && current !== \"draft\") {\n ui.warn(`Memory has status \"${current}\"; approve still sets it to validated.`);\n }\n\n const next = {\n frontmatter: { ...found.memory.frontmatter, status: \"validated\" as const },\n body: found.memory.body,\n };\n await writeFile(found.filePath, serializeMemory(next), \"utf8\");\n ui.success(`Approved ${id} (status=validated)`);\n ui.info(path.relative(root, found.filePath));\n });\n}\n","import { writeFile } from \"node:fs/promises\";\nimport { existsSync } from \"node:fs\";\nimport path from \"node:path\";\nimport { Command } from \"commander\";\nimport {\n findProjectRoot,\n resolveHaivePaths,\n serializeMemory,\n} from \"@hiveai/core\";\nimport { loadMemoriesFromDir } from \"../utils/fs.js\";\nimport { ui } from \"../utils/ui.js\";\n\ninterface UpdateOptions {\n title?: string;\n body?: string;\n tags?: string;\n paths?: string;\n symbols?: string;\n commit?: string;\n domain?: string;\n author?: string;\n dir?: string;\n}\n\nexport function registerMemoryUpdate(memory: Command): void {\n memory\n .command(\"update <id>\")\n .description(\"Update body, tags, or anchor of an existing memory (preserves id and usage history)\")\n .option(\"--title <text>\", \"new title — replaces the first heading of the body\")\n .option(\"--body <text>\", \"new Markdown body — replaces the existing body\")\n .option(\"--tags <csv>\", \"new tags, comma-separated — fully replaces existing tags\")\n .option(\"--paths <csv>\", \"new anchor paths, comma-separated\")\n .option(\"--symbols <csv>\", \"new anchor symbols, comma-separated\")\n .option(\"--commit <sha>\", \"new anchor commit SHA\")\n .option(\"--domain <domain>\", \"new domain label\")\n .option(\"--author <author>\", \"new author handle or email\")\n .option(\"-d, --dir <dir>\", \"project root\")\n .action(async (id: string, opts: UpdateOptions) => {\n const root = findProjectRoot(opts.dir);\n const paths = resolveHaivePaths(root);\n if (!existsSync(paths.memoriesDir)) {\n ui.error(`No .ai/memories at ${root}. Run \\`haive init\\` first.`);\n process.exitCode = 1;\n return;\n }\n\n const memories = await loadMemoriesFromDir(paths.memoriesDir);\n const loaded = memories.find((m) => m.memory.frontmatter.id === id);\n if (!loaded) {\n ui.error(`No memory with id \"${id}\".`);\n process.exitCode = 1;\n return;\n }\n\n const updated: string[] = [];\n const { frontmatter, body } = loaded.memory;\n\n const newAnchor = { ...frontmatter.anchor };\n if (opts.paths !== undefined) {\n newAnchor.paths = parseCsv(opts.paths);\n updated.push(\"anchor.paths\");\n }\n if (opts.symbols !== undefined) {\n newAnchor.symbols = parseCsv(opts.symbols);\n updated.push(\"anchor.symbols\");\n }\n if (opts.commit !== undefined) {\n newAnchor.commit = opts.commit;\n updated.push(\"anchor.commit\");\n }\n\n const newFrontmatter = {\n ...frontmatter,\n anchor: newAnchor,\n ...(opts.tags !== undefined ? { tags: parseCsv(opts.tags) } : {}),\n ...(opts.domain !== undefined ? { domain: opts.domain } : {}),\n ...(opts.author !== undefined ? { author: opts.author } : {}),\n };\n if (opts.tags !== undefined) updated.push(\"tags\");\n if (opts.domain !== undefined) updated.push(\"domain\");\n if (opts.author !== undefined) updated.push(\"author\");\n\n let newBody = opts.body !== undefined ? opts.body : body;\n if (opts.title !== undefined) {\n newBody = replaceFirstHeading(newBody, opts.title);\n updated.push(\"title\");\n }\n if (opts.body !== undefined) updated.push(\"body\");\n\n if (updated.length === 0) {\n ui.warn(\"Nothing to update — provide at least one option.\");\n return;\n }\n\n await writeFile(\n loaded.filePath,\n serializeMemory({ frontmatter: newFrontmatter, body: newBody }),\n \"utf8\",\n );\n\n ui.success(`Updated ${path.relative(root, loaded.filePath)}`);\n ui.info(`fields: ${updated.join(\", \")}`);\n });\n}\n\nfunction replaceFirstHeading(body: string, title: string): string {\n const headingRe = /^#\\s+.+$/m;\n const replacement = `# ${title}`;\n if (headingRe.test(body)) {\n return body.replace(headingRe, replacement);\n }\n return `${replacement}\\n\\n${body}`;\n}\n\nfunction parseCsv(value: string): string[] {\n return value.split(\",\").map((s) => s.trim()).filter(Boolean);\n}\n","import { writeFile } from \"node:fs/promises\";\nimport { existsSync } from \"node:fs\";\nimport path from \"node:path\";\nimport { Command } from \"commander\";\nimport {\n DEFAULT_AUTO_PROMOTE_RULE,\n findProjectRoot,\n getUsage,\n isAutoPromoteEligible,\n loadUsageIndex,\n resolveHaivePaths,\n serializeMemory,\n} from \"@hiveai/core\";\nimport { loadMemoriesFromDir } from \"../utils/fs.js\";\nimport { ui } from \"../utils/ui.js\";\n\ninterface AutoPromoteOptions {\n minReads?: string;\n maxRejections?: string;\n apply?: boolean;\n dir?: string;\n}\n\nexport function registerMemoryAutoPromote(memory: Command): void {\n memory\n .command(\"auto-promote\")\n .description(\"Promote eligible 'proposed' memories to 'validated' based on usage\")\n .option(\"--min-reads <n>\", \"minimum read_count to qualify\", String(DEFAULT_AUTO_PROMOTE_RULE.minReads))\n .option(\n \"--max-rejections <n>\",\n \"memories with more rejections than this are skipped\",\n String(DEFAULT_AUTO_PROMOTE_RULE.maxRejections),\n )\n .option(\"--apply\", \"actually write status=validated to disk (default: dry-run)\")\n .option(\"-d, --dir <dir>\", \"project root\")\n .action(async (opts: AutoPromoteOptions) => {\n const root = findProjectRoot(opts.dir);\n const paths = resolveHaivePaths(root);\n if (!existsSync(paths.memoriesDir)) {\n ui.error(`No .ai/memories at ${root}.`);\n process.exitCode = 1;\n return;\n }\n\n const rule = {\n minReads: Number(opts.minReads ?? DEFAULT_AUTO_PROMOTE_RULE.minReads),\n maxRejections: Number(opts.maxRejections ?? DEFAULT_AUTO_PROMOTE_RULE.maxRejections),\n };\n\n const memories = await loadMemoriesFromDir(paths.memoriesDir);\n const usage = await loadUsageIndex(paths);\n const eligible = memories.filter(({ memory }) =>\n isAutoPromoteEligible(memory.frontmatter, getUsage(usage, memory.frontmatter.id), rule),\n );\n\n if (eligible.length === 0) {\n ui.info(\n `No memories eligible (minReads=${rule.minReads}, maxRejections=${rule.maxRejections}).`,\n );\n return;\n }\n\n let written = 0;\n for (const { memory: mem, filePath } of eligible) {\n const u = getUsage(usage, mem.frontmatter.id);\n console.log(\n `${ui.bold(opts.apply ? \"PROMOTE\" : \"would promote\")} ${mem.frontmatter.id} ${ui.dim(`reads=${u.read_count} rejections=${u.rejected_count}`)}`,\n );\n console.log(` ${ui.dim(path.relative(root, filePath))}`);\n if (opts.apply) {\n const next = {\n frontmatter: { ...mem.frontmatter, status: \"validated\" as const },\n body: mem.body,\n };\n await writeFile(filePath, serializeMemory(next), \"utf8\");\n written++;\n }\n }\n\n const summary = `${eligible.length} eligible`;\n ui.info(opts.apply ? `${summary} · ${written} promoted` : `${summary} · dry-run (use --apply)`);\n });\n}\n","import { spawn } from \"node:child_process\";\nimport { existsSync } from \"node:fs\";\nimport { readFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { Command } from \"commander\";\nimport {\n findProjectRoot,\n parseMemory,\n resolveHaivePaths,\n} from \"@hiveai/core\";\nimport { loadMemoriesFromDir } from \"../utils/fs.js\";\nimport { ui } from \"../utils/ui.js\";\n\ninterface EditOptions {\n editor?: string;\n dir?: string;\n}\n\nexport function registerMemoryEdit(memory: Command): void {\n memory\n .command(\"edit <id>\")\n .description(\"Open a memory in $EDITOR and re-validate when you save\")\n .option(\"-e, --editor <cmd>\", \"editor command (defaults to $EDITOR or 'vi')\")\n .option(\"-d, --dir <dir>\", \"project root\")\n .action(async (id: string, opts: EditOptions) => {\n const root = findProjectRoot(opts.dir);\n const paths = resolveHaivePaths(root);\n if (!existsSync(paths.memoriesDir)) {\n ui.error(`No .ai/memories at ${root}.`);\n process.exitCode = 1;\n return;\n }\n\n const all = await loadMemoriesFromDir(paths.memoriesDir);\n const found = all.find((m) => m.memory.frontmatter.id === id);\n if (!found) {\n ui.error(`No memory with id \"${id}\".`);\n process.exitCode = 1;\n return;\n }\n\n const editor = opts.editor ?? process.env.EDITOR ?? process.env.VISUAL ?? \"vi\";\n ui.info(`Opening ${path.relative(root, found.filePath)} with ${editor}…`);\n const code = await runEditor(editor, found.filePath);\n if (code !== 0) {\n ui.warn(`Editor exited with status ${code}.`);\n }\n\n try {\n const fresh = await readFile(found.filePath, \"utf8\");\n parseMemory(fresh);\n ui.success(\"Memory still parses cleanly.\");\n } catch (err) {\n ui.error(\n `Memory no longer parses: ${err instanceof Error ? err.message : String(err)}`,\n );\n ui.warn(\"File left as-is on disk; fix it and re-run a parse-aware command to confirm.\");\n process.exitCode = 1;\n }\n });\n}\n\nfunction runEditor(editor: string, file: string): Promise<number> {\n return new Promise((resolve) => {\n const child = spawn(editor, [file], { stdio: \"inherit\" });\n child.on(\"exit\", (code) => resolve(code ?? 0));\n child.on(\"error\", () => resolve(127));\n });\n}\n","import { existsSync } from \"node:fs\";\nimport path from \"node:path\";\nimport { Command } from \"commander\";\nimport {\n deriveConfidence,\n findProjectRoot,\n getUsage,\n inferModulesFromPaths,\n loadUsageIndex,\n memoryMatchesAnchorPaths,\n resolveHaivePaths,\n} from \"@hiveai/core\";\nimport { loadMemoriesFromDir } from \"../utils/fs.js\";\nimport { ui } from \"../utils/ui.js\";\n\ninterface ForFilesOptions {\n dir?: string;\n}\n\nexport function registerMemoryForFiles(memory: Command): void {\n memory\n .command(\"for-files <files...>\")\n .description(\"Show memories relevant to the given files (anchor overlap, module, domain)\")\n .option(\"-d, --dir <dir>\", \"project root\")\n .action(async (files: string[], opts: ForFilesOptions) => {\n const root = findProjectRoot(opts.dir);\n const paths = resolveHaivePaths(root);\n if (!existsSync(paths.memoriesDir)) {\n ui.error(`No .ai/memories at ${root}.`);\n process.exitCode = 1;\n return;\n }\n\n const all = await loadMemoriesFromDir(paths.memoriesDir);\n const usage = await loadUsageIndex(paths);\n const inferred = inferModulesFromPaths(files);\n\n const byAnchor: typeof all = [];\n const byModule: typeof all = [];\n const byDomain: typeof all = [];\n const seen = new Set<string>();\n\n for (const loaded of all) {\n if (memoryMatchesAnchorPaths(loaded.memory, files)) {\n byAnchor.push(loaded);\n seen.add(loaded.memory.frontmatter.id);\n }\n }\n for (const loaded of all) {\n if (seen.has(loaded.memory.frontmatter.id)) continue;\n const mod = loaded.memory.frontmatter.module;\n if (mod && inferred.includes(mod)) {\n byModule.push(loaded);\n seen.add(loaded.memory.frontmatter.id);\n }\n }\n for (const loaded of all) {\n if (seen.has(loaded.memory.frontmatter.id)) continue;\n const domain = loaded.memory.frontmatter.domain;\n if (domain && inferred.includes(domain)) {\n byDomain.push(loaded);\n seen.add(loaded.memory.frontmatter.id);\n }\n }\n\n console.log(ui.dim(`inferred modules: ${inferred.length ? inferred.join(\", \") : \"(none)\"}`));\n printGroup(root, \"anchor overlap\", byAnchor, usage);\n printGroup(root, \"module match\", byModule, usage);\n printGroup(root, \"domain match\", byDomain, usage);\n\n const total = byAnchor.length + byModule.length + byDomain.length;\n ui.info(\n `${total} relevant memor${total === 1 ? \"y\" : \"ies\"} (${byAnchor.length} anchor · ${byModule.length} module · ${byDomain.length} domain)`,\n );\n });\n}\n\nfunction printGroup(\n root: string,\n label: string,\n loaded: Array<Awaited<ReturnType<typeof loadMemoriesFromDir>>[number]>,\n usage: Awaited<ReturnType<typeof loadUsageIndex>>,\n): void {\n if (loaded.length === 0) return;\n console.log(ui.bold(`\\n— ${label} —`));\n for (const { memory: mem, filePath } of loaded) {\n const fm = mem.frontmatter;\n const u = getUsage(usage, fm.id);\n const conf = deriveConfidence(fm, u);\n console.log(`${ui.bold(fm.id)} ${ui.dim(`${fm.scope}/${fm.type}`)} ${ui.bold(conf)}`);\n console.log(` ${ui.dim(path.relative(root, filePath))}`);\n }\n}\n","import { existsSync } from \"node:fs\";\nimport path from \"node:path\";\nimport { Command } from \"commander\";\nimport {\n findProjectRoot,\n getUsage,\n loadUsageIndex,\n resolveHaivePaths,\n} from \"@hiveai/core\";\nimport { loadMemoriesFromDir } from \"../utils/fs.js\";\nimport { ui } from \"../utils/ui.js\";\n\ninterface HotOptions {\n threshold?: string;\n status?: \"draft\" | \"proposed\";\n dir?: string;\n}\n\nexport function registerMemoryHot(memory: Command): void {\n memory\n .command(\"hot\")\n .description(\"List memories actively used but not yet validated (good promotion candidates)\")\n .option(\"--threshold <n>\", \"minimum read_count to qualify\", \"3\")\n .option(\"--status <status>\", \"limit to one status (default: draft + proposed)\")\n .option(\"-d, --dir <dir>\", \"project root\")\n .action(async (opts: HotOptions) => {\n const root = findProjectRoot(opts.dir);\n const paths = resolveHaivePaths(root);\n if (!existsSync(paths.memoriesDir)) {\n ui.error(`No .ai/memories at ${root}.`);\n process.exitCode = 1;\n return;\n }\n const threshold = Math.max(1, Number(opts.threshold ?? 3));\n\n const all = await loadMemoriesFromDir(paths.memoriesDir);\n const usage = await loadUsageIndex(paths);\n const candidates = all\n .filter(({ memory: mem }) => {\n const fm = mem.frontmatter;\n if (opts.status && fm.status !== opts.status) return false;\n if (opts.status === undefined && fm.status !== \"draft\" && fm.status !== \"proposed\") {\n return false;\n }\n return getUsage(usage, fm.id).read_count >= threshold;\n })\n .sort(\n (a, b) =>\n getUsage(usage, b.memory.frontmatter.id).read_count -\n getUsage(usage, a.memory.frontmatter.id).read_count,\n );\n\n if (candidates.length === 0) {\n ui.info(`No hot memories (threshold=${threshold}).`);\n return;\n }\n\n for (const { memory: mem, filePath } of candidates) {\n const fm = mem.frontmatter;\n const u = getUsage(usage, fm.id);\n console.log(\n `${ui.bold(fm.id)} ${ui.dim(`${fm.scope}/${fm.type}`)} ${ui.bold(fm.status)} ${ui.dim(`reads=${u.read_count} rejections=${u.rejected_count}`)}`,\n );\n console.log(` ${ui.dim(path.relative(root, filePath))}`);\n }\n ui.info(\n `${candidates.length} hot — promote drafts with \\`haive memory promote <id>\\`, then \\`haive memory auto-promote --apply\\`.`,\n );\n });\n}\n","import { mkdir, writeFile } from \"node:fs/promises\";\nimport { existsSync } from \"node:fs\";\nimport path from \"node:path\";\nimport { Command } from \"commander\";\nimport {\n buildFrontmatter,\n findProjectRoot,\n memoryFilePath,\n resolveHaivePaths,\n serializeMemory,\n type MemoryScope,\n} from \"@hiveai/core\";\nimport { ui } from \"../utils/ui.js\";\n\ninterface TriedOptions {\n what: string;\n whyFailed: string;\n instead?: string;\n scope?: MemoryScope;\n module?: string;\n tags?: string;\n paths?: string;\n author?: string;\n dir?: string;\n}\n\nexport function registerMemoryTried(memory: Command): void {\n memory\n .command(\"tried\")\n .description(\n \"Record a failed approach — negative knowledge to prevent repeated AI mistakes\",\n )\n .requiredOption(\"--what <text>\", \"what approach was tried\")\n .requiredOption(\"--why-failed <text>\", \"why it failed or should NOT be used\")\n .option(\"--instead <text>\", \"recommended alternative\")\n .option(\"--scope <scope>\", \"personal | team | module\", \"personal\")\n .option(\"--module <name>\", \"module name (required when scope=module)\")\n .option(\"--tags <csv>\", \"comma-separated tags\")\n .option(\"--paths <csv>\", \"anchor paths, comma-separated\")\n .option(\"--author <author>\", \"author email or handle\")\n .option(\"-d, --dir <dir>\", \"project root\")\n .action(async (opts: TriedOptions) => {\n const root = findProjectRoot(opts.dir);\n const paths = resolveHaivePaths(root);\n if (!existsSync(paths.haiveDir)) {\n ui.error(`No .ai/ found at ${root}. Run \\`haive init\\` first.`);\n process.exitCode = 1;\n return;\n }\n\n const slug = opts.what\n .toLowerCase()\n .replace(/[^a-z0-9\\s]/g, \"\")\n .trim()\n .split(/\\s+/)\n .slice(0, 5)\n .join(\"-\");\n\n const baseFm = buildFrontmatter({\n type: \"attempt\",\n slug,\n scope: opts.scope,\n module: opts.module,\n tags: parseCsv(opts.tags),\n paths: parseCsv(opts.paths),\n author: opts.author,\n });\n // attempt memories are immediately validated — no review cycle needed\n const frontmatter = { ...baseFm, status: \"validated\" as const };\n\n const lines: string[] = [`# ${opts.what}`, \"\"];\n lines.push(`**Why it failed / do NOT use:** ${opts.whyFailed}`);\n if (opts.instead) {\n lines.push(\"\", `**Instead, use:** ${opts.instead}`);\n }\n const body = lines.join(\"\\n\") + \"\\n\";\n\n const file = memoryFilePath(paths, frontmatter.scope, frontmatter.id, frontmatter.module);\n await mkdir(path.dirname(file), { recursive: true });\n\n if (existsSync(file)) {\n ui.error(`Memory already exists at ${file}`);\n process.exitCode = 1;\n return;\n }\n\n await writeFile(file, serializeMemory({ frontmatter, body }), \"utf8\");\n ui.success(`Recorded: ${path.relative(root, file)}`);\n ui.info(`id=${frontmatter.id} type=attempt status=validated (auto-approved)`);\n });\n}\n\nfunction parseCsv(value: string | undefined): string[] {\n if (!value) return [];\n return value.split(\",\").map((s) => s.trim()).filter(Boolean);\n}\n","import { existsSync } from \"node:fs\";\nimport path from \"node:path\";\nimport { Command } from \"commander\";\nimport {\n findProjectRoot,\n getUsage,\n loadUsageIndex,\n resolveHaivePaths,\n} from \"@hiveai/core\";\nimport { loadMemoriesFromDir } from \"../utils/fs.js\";\nimport { ui } from \"../utils/ui.js\";\n\ninterface PendingOptions {\n scope?: \"personal\" | \"team\" | \"module\";\n dir?: string;\n}\n\nexport function registerMemoryPending(memory: Command): void {\n memory\n .command(\"pending\")\n .description(\"List 'proposed' memories awaiting review (sorted by reads desc)\")\n .option(\"--scope <scope>\", \"filter by scope (personal | team | module)\")\n .option(\"-d, --dir <dir>\", \"project root\")\n .action(async (opts: PendingOptions) => {\n const root = findProjectRoot(opts.dir);\n const paths = resolveHaivePaths(root);\n if (!existsSync(paths.memoriesDir)) {\n ui.error(`No .ai/memories at ${root}.`);\n process.exitCode = 1;\n return;\n }\n\n const all = await loadMemoriesFromDir(paths.memoriesDir);\n const usage = await loadUsageIndex(paths);\n const proposed = all.filter(({ memory: mem }) => {\n if (mem.frontmatter.status !== \"proposed\") return false;\n if (opts.scope && mem.frontmatter.scope !== opts.scope) return false;\n return true;\n });\n\n if (proposed.length === 0) {\n ui.info(\"No memories awaiting review.\");\n return;\n }\n\n proposed.sort(\n (a, b) =>\n getUsage(usage, b.memory.frontmatter.id).read_count -\n getUsage(usage, a.memory.frontmatter.id).read_count,\n );\n\n const now = Date.now();\n for (const { memory: mem, filePath } of proposed) {\n const fm = mem.frontmatter;\n const u = getUsage(usage, fm.id);\n const ageDays = Math.floor((now - new Date(fm.created_at).getTime()) / 86_400_000);\n const ageStr = ageDays === 0 ? \"today\" : `${ageDays}d`;\n console.log(\n `${ui.bold(fm.id)} ${ui.dim(`${fm.scope}/${fm.type}`)} ${ui.dim(`age=${ageStr} reads=${u.read_count} rejections=${u.rejected_count}`)}`,\n );\n console.log(` ${ui.dim(path.relative(root, filePath))}`);\n }\n ui.info(`${proposed.length} pending`);\n });\n}\n","import { existsSync } from \"node:fs\";\nimport path from \"node:path\";\nimport { Command } from \"commander\";\nimport {\n extractSnippet,\n findProjectRoot,\n literalMatchesAllTokens,\n literalMatchesAnyToken,\n pickSnippetNeedle,\n resolveHaivePaths,\n tokenizeQuery,\n type MemoryScope,\n} from \"@hiveai/core\";\nimport { loadMemoriesFromDir } from \"../utils/fs.js\";\nimport { ui } from \"../utils/ui.js\";\n\ninterface QueryOptions {\n dir?: string;\n limit?: string;\n scope?: MemoryScope;\n status?: string;\n showRejected?: boolean;\n}\n\nexport function registerMemoryQuery(memory: Command): void {\n memory\n .command(\"query <text>\")\n .description(\"Search memories by id, tag, or substring (AND, OR fallback)\")\n .option(\"-d, --dir <dir>\", \"project root\")\n .option(\"--limit <n>\", \"max results\", \"20\")\n .option(\"--scope <scope>\", \"personal | team | module\")\n .option(\"--status <csv>\", \"filter by status (draft,proposed,validated,stale,rejected)\")\n .option(\"--show-rejected\", \"include rejected memories (hidden by default)\")\n .action(async (text: string, opts: QueryOptions) => {\n const root = findProjectRoot(opts.dir);\n const paths = resolveHaivePaths(root);\n if (!existsSync(paths.memoriesDir)) {\n ui.error(`No memories directory at ${paths.memoriesDir}. Run \\`haive init\\` first.`);\n process.exitCode = 1;\n return;\n }\n\n const tokens = tokenizeQuery(text);\n if (tokens.length === 0) {\n ui.warn(\"Empty query — use \\`haive memory list\\` to list all memories.\");\n return;\n }\n const statusFilter = opts.status ? opts.status.split(\",\").map((s) => s.trim()) : null;\n const all = await loadMemoriesFromDir(paths.memoriesDir);\n\n const passesFilters = (mem: (typeof all)[number][\"memory\"]) => {\n const fm = mem.frontmatter;\n if (opts.scope && fm.scope !== opts.scope) return false;\n if (!opts.showRejected && !statusFilter && fm.status === \"rejected\") return false;\n if (statusFilter && !statusFilter.includes(fm.status)) return false;\n return true;\n };\n\n const eligible = all.filter(({ memory: mem }) => passesFilters(mem));\n let matches = eligible.filter(({ memory: mem }) => literalMatchesAllTokens(mem, tokens));\n let fallback = false;\n if (matches.length === 0 && tokens.length > 1) {\n matches = eligible.filter(({ memory: mem }) => literalMatchesAnyToken(mem, tokens));\n fallback = true;\n }\n\n const limit = Math.max(1, Number(opts.limit ?? 20));\n const top = matches.slice(0, limit);\n\n if (top.length === 0) {\n ui.info(`No matches for \"${text}\".`);\n return;\n }\n if (fallback) {\n ui.info(`No exact match — showing partial results (OR fallback):`);\n }\n\n const snippetNeedle = pickSnippetNeedle(text);\n for (const { memory: mem, filePath } of top) {\n const fm = mem.frontmatter;\n const statusBadge = ui.statusBadge(fm.status);\n console.log(`${ui.bold(fm.id)} ${ui.dim(fm.scope)} ${statusBadge}`);\n console.log(` ${ui.dim(path.relative(root, filePath))}`);\n const snippet = extractSnippet(mem.body, snippetNeedle);\n if (snippet) console.log(` ${snippet}`);\n }\n console.log(\n ui.dim(`\\n${top.length} of ${matches.length} match${matches.length === 1 ? \"\" : \"es\"}`),\n );\n });\n}\n","import { writeFile } from \"node:fs/promises\";\nimport { existsSync } from \"node:fs\";\nimport { Command } from \"commander\";\nimport {\n findProjectRoot,\n loadUsageIndex,\n recordRejection,\n resolveHaivePaths,\n saveUsageIndex,\n serializeMemory,\n} from \"@hiveai/core\";\nimport { loadMemoriesFromDir } from \"../utils/fs.js\";\nimport { ui } from \"../utils/ui.js\";\n\ninterface RejectOptions {\n reason?: string;\n dir?: string;\n}\n\nexport function registerMemoryReject(memory: Command): void {\n memory\n .command(\"reject <id>\")\n .description(\"Record a rejection (blocks auto-promotion and lowers confidence)\")\n .option(\"-r, --reason <reason>\", \"why this memory is being rejected\")\n .option(\"-d, --dir <dir>\", \"project root\")\n .action(async (id: string, opts: RejectOptions) => {\n const root = findProjectRoot(opts.dir);\n const paths = resolveHaivePaths(root);\n if (!existsSync(paths.memoriesDir)) {\n ui.error(`No .ai/memories at ${root}.`);\n process.exitCode = 1;\n return;\n }\n\n const memories = await loadMemoriesFromDir(paths.memoriesDir);\n const loaded = memories.find((m) => m.memory.frontmatter.id === id);\n if (!loaded) {\n ui.error(`No memory with id \"${id}\".`);\n process.exitCode = 1;\n return;\n }\n\n await writeFile(\n loaded.filePath,\n serializeMemory({\n frontmatter: {\n ...loaded.memory.frontmatter,\n status: \"rejected\",\n stale_reason: opts.reason ?? loaded.memory.frontmatter.stale_reason ?? null,\n },\n body: loaded.memory.body,\n }),\n \"utf8\",\n );\n\n const idx = await loadUsageIndex(paths);\n recordRejection(idx, id, opts.reason ?? null);\n await saveUsageIndex(paths, idx);\n const u = idx.by_id[id]!;\n ui.success(\n `Rejected ${id} (status=rejected, ${u.rejected_count} rejection${u.rejected_count === 1 ? \"\" : \"s\"})`,\n );\n if (opts.reason) ui.info(`reason: ${opts.reason}`);\n });\n}\n","import { existsSync } from \"node:fs\";\nimport { unlink } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { createInterface } from \"node:readline/promises\";\nimport { Command } from \"commander\";\nimport {\n findProjectRoot,\n loadUsageIndex,\n resolveHaivePaths,\n saveUsageIndex,\n} from \"@hiveai/core\";\nimport { loadMemoriesFromDir } from \"../utils/fs.js\";\nimport { ui } from \"../utils/ui.js\";\n\ninterface RmOptions {\n yes?: boolean;\n keepUsage?: boolean;\n dir?: string;\n}\n\nexport function registerMemoryRm(memory: Command): void {\n memory\n .command(\"rm <id>\")\n .description(\"Delete a memory file (and its usage entry by default)\")\n .option(\"-y, --yes\", \"skip the confirmation prompt\")\n .option(\"--keep-usage\", \"do not remove the usage.json entry\")\n .option(\"-d, --dir <dir>\", \"project root\")\n .action(async (id: string, opts: RmOptions) => {\n const root = findProjectRoot(opts.dir);\n const paths = resolveHaivePaths(root);\n if (!existsSync(paths.memoriesDir)) {\n ui.error(`No .ai/memories at ${root}.`);\n process.exitCode = 1;\n return;\n }\n\n const all = await loadMemoriesFromDir(paths.memoriesDir);\n const found = all.find((m) => m.memory.frontmatter.id === id);\n if (!found) {\n ui.error(`No memory with id \"${id}\".`);\n process.exitCode = 1;\n return;\n }\n\n const rel = path.relative(root, found.filePath);\n if (!opts.yes) {\n const rl = createInterface({ input: process.stdin, output: process.stdout });\n const answer = (await rl.question(`Delete ${rel}? [y/N] `)).trim().toLowerCase();\n rl.close();\n if (answer !== \"y\" && answer !== \"yes\") {\n ui.info(\"Aborted.\");\n return;\n }\n }\n\n await unlink(found.filePath);\n ui.success(`Deleted ${rel}`);\n\n if (!opts.keepUsage) {\n const idx = await loadUsageIndex(paths);\n if (idx.by_id[id]) {\n delete idx.by_id[id];\n await saveUsageIndex(paths, idx);\n ui.info(\"Removed usage entry\");\n }\n }\n });\n}\n","import { existsSync } from \"node:fs\";\nimport { readFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { Command } from \"commander\";\nimport {\n deriveConfidence,\n findProjectRoot,\n getUsage,\n loadUsageIndex,\n resolveHaivePaths,\n} from \"@hiveai/core\";\nimport { loadMemoriesFromDir } from \"../utils/fs.js\";\nimport { ui } from \"../utils/ui.js\";\n\ninterface ShowOptions {\n raw?: boolean;\n dir?: string;\n}\n\nexport function registerMemoryShow(memory: Command): void {\n memory\n .command(\"show <id>\")\n .description(\"Print a memory's frontmatter, body, and confidence/usage\")\n .option(\"--raw\", \"print the raw file contents instead of a summary\")\n .option(\"-d, --dir <dir>\", \"project root\")\n .action(async (id: string, opts: ShowOptions) => {\n const root = findProjectRoot(opts.dir);\n const paths = resolveHaivePaths(root);\n if (!existsSync(paths.memoriesDir)) {\n ui.error(`No .ai/memories at ${root}.`);\n process.exitCode = 1;\n return;\n }\n\n const all = await loadMemoriesFromDir(paths.memoriesDir);\n const found = all.find((m) => m.memory.frontmatter.id === id);\n if (!found) {\n ui.error(`No memory with id \"${id}\".`);\n process.exitCode = 1;\n return;\n }\n\n if (opts.raw) {\n console.log(await readFile(found.filePath, \"utf8\"));\n return;\n }\n\n const fm = found.memory.frontmatter;\n const usage = await loadUsageIndex(paths);\n const u = getUsage(usage, fm.id);\n const conf = deriveConfidence(fm, u);\n\n console.log(ui.bold(fm.id));\n console.log(`${ui.dim(\"scope:\")} ${fm.scope}${fm.module ? ` / ${fm.module}` : \"\"}`);\n console.log(`${ui.dim(\"type:\")} ${fm.type}`);\n console.log(`${ui.dim(\"status:\")} ${fm.status} ${ui.dim(\"→ confidence:\")} ${ui.bold(conf)}`);\n console.log(`${ui.dim(\"tags:\")} ${fm.tags.length ? fm.tags.join(\", \") : \"(none)\"}`);\n console.log(`${ui.dim(\"created:\")} ${fm.created_at}`);\n if (fm.verified_at) console.log(`${ui.dim(\"verified:\")} ${fm.verified_at}`);\n if (fm.stale_reason) console.log(`${ui.dim(\"stale:\")} ${fm.stale_reason}`);\n console.log(`${ui.dim(\"reads:\")} ${u.read_count} ${ui.dim(\"rejections:\")} ${u.rejected_count}`);\n console.log(`${ui.dim(\"file:\")} ${path.relative(root, found.filePath)}`);\n if (fm.anchor.paths.length || fm.anchor.symbols.length) {\n console.log(ui.dim(\"anchor:\"));\n if (fm.anchor.commit) console.log(` ${ui.dim(\"commit:\")} ${fm.anchor.commit}`);\n if (fm.anchor.paths.length)\n console.log(` ${ui.dim(\"paths:\")} ${fm.anchor.paths.join(\", \")}`);\n if (fm.anchor.symbols.length)\n console.log(` ${ui.dim(\"symbols:\")} ${fm.anchor.symbols.join(\", \")}`);\n }\n console.log();\n console.log(found.memory.body);\n });\n}\n","import { existsSync } from \"node:fs\";\nimport path from \"node:path\";\nimport { Command } from \"commander\";\nimport {\n deriveConfidence,\n findProjectRoot,\n getUsage,\n loadUsageIndex,\n resolveHaivePaths,\n} from \"@hiveai/core\";\nimport { loadMemoriesFromDir } from \"../utils/fs.js\";\nimport { ui } from \"../utils/ui.js\";\n\ninterface StatsOptions {\n id?: string;\n dir?: string;\n}\n\nexport function registerMemoryStats(memory: Command): void {\n memory\n .command(\"stats\")\n .description(\"Show usage stats and confidence levels per memory\")\n .option(\"--id <id>\", \"show stats for a single memory id\")\n .option(\"-d, --dir <dir>\", \"project root\")\n .action(async (opts: StatsOptions) => {\n const root = findProjectRoot(opts.dir);\n const paths = resolveHaivePaths(root);\n if (!existsSync(paths.memoriesDir)) {\n ui.error(`No .ai/memories at ${root}. Run \\`haive init\\` first.`);\n process.exitCode = 1;\n return;\n }\n\n const all = await loadMemoriesFromDir(paths.memoriesDir);\n const usage = await loadUsageIndex(paths);\n const target = opts.id\n ? all.filter((m) => m.memory.frontmatter.id === opts.id)\n : all;\n\n if (target.length === 0) {\n ui.info(opts.id ? `No memory with id \"${opts.id}\".` : \"No memories.\");\n return;\n }\n\n // Sort by read_count desc to surface the popular ones.\n target.sort(\n (a, b) =>\n getUsage(usage, b.memory.frontmatter.id).read_count -\n getUsage(usage, a.memory.frontmatter.id).read_count,\n );\n\n for (const { memory: mem, filePath } of target) {\n const fm = mem.frontmatter;\n const u = getUsage(usage, fm.id);\n const conf = deriveConfidence(fm, u);\n console.log(\n `${ui.bold(fm.id)} ${ui.dim(`${fm.scope}/${fm.type}`)} ${ui.bold(conf)}`,\n );\n console.log(\n ` ${ui.dim(\"status:\")} ${fm.status} ${ui.dim(\"reads:\")} ${u.read_count} ${ui.dim(\"rejections:\")} ${u.rejected_count}`,\n );\n console.log(` ${ui.dim(path.relative(root, filePath))}`);\n }\n });\n}\n","import { writeFile } from \"node:fs/promises\";\nimport { existsSync } from \"node:fs\";\nimport path from \"node:path\";\nimport { Command } from \"commander\";\nimport {\n findProjectRoot,\n resolveHaivePaths,\n serializeMemory,\n verifyAnchor,\n} from \"@hiveai/core\";\nimport { loadMemoriesFromDir } from \"../utils/fs.js\";\nimport { ui } from \"../utils/ui.js\";\n\ninterface VerifyOptions {\n id?: string;\n all?: boolean;\n update?: boolean;\n dir?: string;\n}\n\nexport function registerMemoryVerify(memory: Command): void {\n memory\n .command(\"verify\")\n .description(\"Check memory anchors against current code, optionally marking stale ones\")\n .option(\"--id <id>\", \"verify a single memory by id\")\n .option(\"--all\", \"verify every memory (default if --id is omitted)\")\n .option(\"--update\", \"write status=stale (or status=validated for re-freshed) back to disk\")\n .option(\"-d, --dir <dir>\", \"project root\")\n .action(async (opts: VerifyOptions) => {\n const root = findProjectRoot(opts.dir);\n const paths = resolveHaivePaths(root);\n if (!existsSync(paths.memoriesDir)) {\n ui.error(`No .ai/memories at ${root}. Run \\`haive init\\` first.`);\n process.exitCode = 1;\n return;\n }\n\n const all = await loadMemoriesFromDir(paths.memoriesDir);\n const targets = opts.id\n ? all.filter((m) => m.memory.frontmatter.id === opts.id)\n : all;\n\n if (opts.id && targets.length === 0) {\n ui.error(`No memory with id \"${opts.id}\".`);\n process.exitCode = 1;\n return;\n }\n\n let staleCount = 0;\n let freshCount = 0;\n const anchorlessIds: string[] = [];\n let updated = 0;\n\n for (const { memory: mem, filePath } of targets) {\n const result = await verifyAnchor(mem, { projectRoot: root });\n const isAnchored =\n mem.frontmatter.anchor.paths.length > 0 ||\n mem.frontmatter.anchor.symbols.length > 0;\n\n if (!isAnchored) {\n anchorlessIds.push(mem.frontmatter.id);\n continue;\n }\n\n const rel = path.relative(root, filePath);\n if (result.stale) {\n staleCount++;\n console.log(`${ui.bold(\"STALE\")} ${mem.frontmatter.id}`);\n console.log(` ${ui.dim(rel)}`);\n console.log(` ${result.reason}`);\n if (result.possibleRenames.length > 0) {\n console.log(` ${ui.yellow(\"Possible renames:\")} ${result.possibleRenames.join(\", \")}`);\n }\n } else {\n freshCount++;\n console.log(`${ui.dim(\"fresh\")} ${mem.frontmatter.id}`);\n }\n\n if (opts.update) {\n const next = applyVerification(mem, result);\n await writeFile(filePath, serializeMemory(next), \"utf8\");\n updated++;\n }\n }\n\n const summary = [\n `${freshCount} fresh`,\n `${staleCount} stale`,\n `${anchorlessIds.length} anchorless (skipped)`,\n ];\n if (opts.update) summary.push(`${updated} updated on disk`);\n ui.info(summary.join(\" · \"));\n if (anchorlessIds.length > 0) {\n console.log(\n ui.dim(\n `Anchorless memories (no paths/symbols — staleness cannot be detected):\\n` +\n anchorlessIds.map((id) => ` ${id}`).join(\"\\n\") +\n `\\nTip: use \\`haive memory update <id> --paths <files>\\` to add anchors.`,\n ),\n );\n }\n });\n}\n\nfunction applyVerification(\n mem: Parameters<typeof serializeMemory>[0],\n result: { stale: boolean; reason: string | null },\n): Parameters<typeof serializeMemory>[0] {\n const verifiedAt = new Date().toISOString();\n if (result.stale) {\n return {\n frontmatter: {\n ...mem.frontmatter,\n status: \"stale\",\n verified_at: verifiedAt,\n stale_reason: result.reason,\n },\n body: mem.body,\n };\n }\n // Reset stale_reason when re-validating; keep validated/proposed status as is,\n // promote draft→validated when verification passes.\n const nextStatus =\n mem.frontmatter.status === \"stale\" || mem.frontmatter.status === \"draft\"\n ? \"validated\"\n : mem.frontmatter.status;\n return {\n frontmatter: {\n ...mem.frontmatter,\n status: nextStatus,\n verified_at: verifiedAt,\n stale_reason: null,\n },\n body: mem.body,\n };\n}\n","import { readFile } from \"node:fs/promises\";\nimport { existsSync } from \"node:fs\";\nimport { Command } from \"commander\";\nimport {\n findProjectRoot,\n resolveHaivePaths,\n} from \"@hiveai/core\";\nimport { ui } from \"../utils/ui.js\";\n\ninterface ImportOptions {\n from: string;\n scope?: \"personal\" | \"team\";\n dir?: string;\n}\n\nexport function registerMemoryImport(memory: Command): void {\n memory\n .command(\"import\")\n .description(\n \"Parse a Markdown file and suggest memories via the import_docs MCP prompt (prints a ready-to-use prompt invocation)\",\n )\n .requiredOption(\"--from <file>\", \"Markdown/text file to import from\")\n .option(\"--scope <scope>\", \"personal | team (default: team)\", \"team\")\n .option(\"-d, --dir <dir>\", \"project root\")\n .action(async (opts: ImportOptions) => {\n const root = findProjectRoot(opts.dir);\n const paths = resolveHaivePaths(root);\n\n if (!existsSync(paths.haiveDir)) {\n ui.error(`No .ai/ found at ${root}. Run \\`haive init\\` first.`);\n process.exitCode = 1;\n return;\n }\n\n if (!existsSync(opts.from)) {\n ui.error(`File not found: ${opts.from}`);\n process.exitCode = 1;\n return;\n }\n\n const content = await readFile(opts.from, \"utf8\");\n const scope = opts.scope ?? \"team\";\n\n ui.info(`Preparing import from: ${opts.from} (scope=${scope})`);\n ui.info(`Content length: ${content.length} chars`);\n console.log();\n console.log(ui.bold(\"To import via MCP, invoke the `import_docs` prompt with:\"));\n console.log();\n console.log(\n ui.dim(\n JSON.stringify(\n {\n content: content.slice(0, 200) + (content.length > 200 ? \"…\" : \"\"),\n source: opts.from,\n scope,\n },\n null,\n 2,\n ),\n ),\n );\n console.log();\n ui.info(\n \"Or use your AI client to call: import_docs({ content: <file contents>, source: \\\"\" +\n opts.from +\n \"\\\", scope: \\\"\" +\n scope +\n \"\\\" })\",\n );\n });\n}\n"],"mappings":";;;AAAA,SAAS,WAAAA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CAAC;AAChB,CAAC;AAED,SAAS,WACP,KACgE;AAChE,SACE,QAAQ,QACR,OAAO,QAAQ,YACf,YAAY,OACZ,MAAM,QAAS,IAAgC,MAAM;AAEzD;","names":["Command","program","findProjectRoot","program","existsSync","findProjectRoot","resolveHaivePaths","program","findProjectRoot","resolveHaivePaths","existsSync","path","findProjectRoot","resolveHaivePaths","program","findProjectRoot","resolveHaivePaths","path","existsSync","path","resolveHaivePaths","program","path","resolveHaivePaths","existsSync","mkdir","writeFile","readFile","existsSync","path","findProjectRoot","program","findProjectRoot","path","existsSync","mkdir","readFile","writeFile","existsSync","path","findProjectRoot","require","program","findProjectRoot","path","existsSync","readFile","writeFile","existsSync","path","findProjectRoot","loadMemoriesFromDir","resolveHaivePaths","program","findProjectRoot","resolveHaivePaths","existsSync","loadMemoriesFromDir","memory","writeFile","path","readFile","mkdir","readFile","writeFile","existsSync","path","findProjectRoot","loadMemoriesFromDir","resolveHaivePaths","serializeMemory","memory","findProjectRoot","resolveHaivePaths","existsSync","parseCsv","readFile","mkdir","path","loadMemoriesFromDir","writeFile","serializeMemory","existsSync","path","findProjectRoot","resolveHaivePaths","loadMemoriesFromDir","memory","findProjectRoot","resolveHaivePaths","existsSync","loadMemoriesFromDir","path","mkdir","writeFile","existsSync","path","findProjectRoot","memoryFilePath","resolveHaivePaths","serializeMemory","memory","findProjectRoot","resolveHaivePaths","existsSync","loadMemoriesFromDir","memoryFilePath","mkdir","path","writeFile","serializeMemory","existsSync","writeFile","path","findProjectRoot","resolveHaivePaths","serializeMemory","memory","findProjectRoot","resolveHaivePaths","existsSync","loadMemoriesFromDir","found","next","writeFile","serializeMemory","path","writeFile","existsSync","path","findProjectRoot","resolveHaivePaths","serializeMemory","memory","findProjectRoot","resolveHaivePaths","existsSync","loadMemoriesFromDir","parseCsv","writeFile","serializeMemory","path","writeFile","existsSync","path","DEFAULT_AUTO_PROMOTE_RULE","findProjectRoot","getUsage","isAutoPromoteEligible","loadUsageIndex","resolveHaivePaths","serializeMemory","memory","DEFAULT_AUTO_PROMOTE_RULE","findProjectRoot","resolveHaivePaths","existsSync","loadMemoriesFromDir","loadUsageIndex","isAutoPromoteEligible","getUsage","path","writeFile","serializeMemory","spawn","existsSync","readFile","path","findProjectRoot","resolveHaivePaths","memory","findProjectRoot","resolveHaivePaths","existsSync","loadMemoriesFromDir","path","readFile","spawn","existsSync","path","findProjectRoot","getUsage","inferModulesFromPaths","loadUsageIndex","memoryMatchesAnchorPaths","resolveHaivePaths","memory","findProjectRoot","resolveHaivePaths","existsSync","loadMemoriesFromDir","loadUsageIndex","inferModulesFromPaths","memoryMatchesAnchorPaths","getUsage","path","existsSync","path","findProjectRoot","getUsage","loadUsageIndex","resolveHaivePaths","memory","findProjectRoot","resolveHaivePaths","existsSync","loadMemoriesFromDir","loadUsageIndex","getUsage","path","mkdir","writeFile","existsSync","path","buildFrontmatter","findProjectRoot","memoryFilePath","resolveHaivePaths","serializeMemory","memory","findProjectRoot","resolveHaivePaths","existsSync","buildFrontmatter","parseCsv","memoryFilePath","mkdir","path","writeFile","serializeMemory","existsSync","path","findProjectRoot","getUsage","loadUsageIndex","resolveHaivePaths","memory","findProjectRoot","resolveHaivePaths","existsSync","loadMemoriesFromDir","loadUsageIndex","getUsage","path","existsSync","path","findProjectRoot","literalMatchesAllTokens","resolveHaivePaths","tokenizeQuery","memory","findProjectRoot","resolveHaivePaths","existsSync","tokenizeQuery","loadMemoriesFromDir","literalMatchesAllTokens","path","writeFile","existsSync","findProjectRoot","loadUsageIndex","resolveHaivePaths","serializeMemory","memory","findProjectRoot","resolveHaivePaths","existsSync","loadMemoriesFromDir","writeFile","serializeMemory","loadUsageIndex","existsSync","unlink","path","findProjectRoot","loadUsageIndex","resolveHaivePaths","saveUsageIndex","memory","findProjectRoot","resolveHaivePaths","existsSync","loadMemoriesFromDir","path","unlink","loadUsageIndex","saveUsageIndex","existsSync","readFile","path","deriveConfidence","findProjectRoot","getUsage","loadUsageIndex","resolveHaivePaths","memory","findProjectRoot","resolveHaivePaths","existsSync","loadMemoriesFromDir","readFile","loadUsageIndex","getUsage","deriveConfidence","path","existsSync","path","deriveConfidence","findProjectRoot","getUsage","loadUsageIndex","resolveHaivePaths","memory","findProjectRoot","resolveHaivePaths","existsSync","loadMemoriesFromDir","loadUsageIndex","getUsage","deriveConfidence","path","writeFile","existsSync","path","findProjectRoot","resolveHaivePaths","serializeMemory","verifyAnchor","memory","findProjectRoot","resolveHaivePaths","existsSync","loadMemoriesFromDir","verifyAnchor","path","writeFile","serializeMemory","readFile","existsSync","findProjectRoot","resolveHaivePaths","memory","findProjectRoot","resolveHaivePaths","existsSync","readFile","Command"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/commands/briefing.ts","../src/utils/ui.ts","../src/commands/tui.ts","../src/commands/embeddings.ts","../src/commands/index-code.ts","../src/commands/init.ts","../src/commands/install-hooks.ts","../src/commands/mcp.ts","../src/commands/sync.ts","../src/commands/memory-add.ts","../src/commands/memory-list.ts","../src/utils/fs.ts","../src/commands/memory-promote.ts","../src/commands/memory-approve.ts","../src/commands/memory-update.ts","../src/commands/memory-auto-promote.ts","../src/commands/memory-edit.ts","../src/commands/memory-for-files.ts","../src/commands/memory-hot.ts","../src/commands/memory-tried.ts","../src/commands/memory-pending.ts","../src/commands/memory-query.ts","../src/commands/memory-reject.ts","../src/commands/memory-rm.ts","../src/commands/memory-show.ts","../src/commands/memory-stats.ts","../src/commands/memory-verify.ts","../src/commands/memory-import.ts"],"sourcesContent":["import { Command } from \"commander\";\nimport { registerBriefing } from \"./commands/briefing.js\";\nimport { registerTui } from \"./commands/tui.js\";\nimport { registerEmbeddings } from \"./commands/embeddings.js\";\nimport { registerIndexCode } from \"./commands/index-code.js\";\nimport { registerInit } from \"./commands/init.js\";\nimport { registerInstallHooks } from \"./commands/install-hooks.js\";\nimport { registerMcp } from \"./commands/mcp.js\";\nimport { registerSync } from \"./commands/sync.js\";\nimport { registerMemoryAdd } from \"./commands/memory-add.js\";\nimport { registerMemoryList } from \"./commands/memory-list.js\";\nimport { registerMemoryPromote } from \"./commands/memory-promote.js\";\nimport { registerMemoryApprove } from \"./commands/memory-approve.js\";\nimport { registerMemoryUpdate } from \"./commands/memory-update.js\";\nimport { registerMemoryAutoPromote } from \"./commands/memory-auto-promote.js\";\nimport { registerMemoryEdit } from \"./commands/memory-edit.js\";\nimport { registerMemoryForFiles } from \"./commands/memory-for-files.js\";\nimport { registerMemoryHot } from \"./commands/memory-hot.js\";\nimport { registerMemoryTried } from \"./commands/memory-tried.js\";\nimport { registerMemoryPending } from \"./commands/memory-pending.js\";\nimport { registerMemoryQuery } from \"./commands/memory-query.js\";\nimport { registerMemoryReject } from \"./commands/memory-reject.js\";\nimport { registerMemoryRm } from \"./commands/memory-rm.js\";\nimport { registerMemoryShow } from \"./commands/memory-show.js\";\nimport { registerMemoryStats } from \"./commands/memory-stats.js\";\nimport { registerMemoryVerify } from \"./commands/memory-verify.js\";\nimport { registerMemoryImport } from \"./commands/memory-import.js\";\n\nconst program = new Command();\n\ndeclare const __HAIVE_VERSION__: string;\n\nprogram\n .name(\"haive\")\n .description(\"hAIve — team-first persistent memory layer for AI coding agents\")\n .version(__HAIVE_VERSION__);\n\nregisterInit(program);\nregisterMcp(program);\nregisterBriefing(program);\nregisterTui(program);\nregisterEmbeddings(program);\nregisterSync(program);\nregisterInstallHooks(program);\nregisterIndexCode(program);\n\nconst memory = program.command(\"memory\").description(\"Manage memory entries\");\nregisterMemoryAdd(memory);\nregisterMemoryList(memory);\nregisterMemoryQuery(memory);\nregisterMemoryPromote(memory);\nregisterMemoryVerify(memory);\nregisterMemoryStats(memory);\nregisterMemoryReject(memory);\nregisterMemoryAutoPromote(memory);\nregisterMemoryForFiles(memory);\nregisterMemoryShow(memory);\nregisterMemoryEdit(memory);\nregisterMemoryRm(memory);\nregisterMemoryPending(memory);\nregisterMemoryApprove(memory);\nregisterMemoryUpdate(memory);\nregisterMemoryHot(memory);\nregisterMemoryTried(memory);\nregisterMemoryImport(memory);\n\nprogram.parseAsync(process.argv).catch((err: unknown) => {\n if (isZodError(err)) {\n for (const issue of err.issues) {\n const field = issue.path.length > 0 ? `${String(issue.path.join(\".\"))}: ` : \"\";\n console.error(`\\x1b[31m✗\\x1b[0m ${field}${issue.message}`);\n }\n } else {\n console.error(err instanceof Error ? err.message : err);\n }\n process.exit(1);\n});\n\nfunction isZodError(\n err: unknown,\n): err is { issues: Array<{ path: unknown[]; message: string }> } {\n return (\n err !== null &&\n typeof err === \"object\" &&\n \"issues\" in err &&\n Array.isArray((err as Record<string, unknown>).issues)\n );\n}\n","import { existsSync } from \"node:fs\";\nimport { readFile } from \"node:fs/promises\";\nimport { Command } from \"commander\";\nimport {\n findProjectRoot,\n literalMatchesAllTokens,\n loadMemoriesFromDir,\n memoryMatchesAnchorPaths,\n resolveHaivePaths,\n tokenizeQuery,\n trackReads,\n} from \"@hiveai/core\";\nimport { ui } from \"../utils/ui.js\";\n\ninterface BriefingOptions {\n task?: string;\n files?: string;\n maxMemories?: string;\n scope?: string;\n includeDraft?: boolean;\n includeStale?: boolean;\n dir?: string;\n}\n\nexport function registerBriefing(program: Command): void {\n program\n .command(\"briefing\")\n .description(\n \"Print project context + relevant memories in one shot — ideal for agent onboarding\",\n )\n .option(\"--task <text>\", \"what you are about to do — filters memories by relevance\")\n .option(\"--files <csv>\", \"comma-separated file paths being worked on (anchors memories)\")\n .option(\"--max-memories <n>\", \"cap on memories surfaced\", \"10\")\n .option(\n \"--scope <scope>\",\n \"personal | team | module | all (default: team)\",\n \"team\",\n )\n .option(\"--include-draft\", \"include draft memories (excluded by default)\")\n .option(\"--include-stale\", \"include stale memories (excluded by default — may be outdated)\")\n .option(\"-d, --dir <dir>\", \"project root\")\n .action(async (opts: BriefingOptions) => {\n const root = findProjectRoot(opts.dir);\n const paths = resolveHaivePaths(root);\n\n // Project context\n if (existsSync(paths.projectContext)) {\n const ctx = await readFile(paths.projectContext, \"utf8\");\n console.log(`${ui.bold(\"=== Project Context ===\")}\\n`);\n console.log(ctx.trim());\n console.log();\n } else {\n ui.warn(\n \"No project-context.md found. Run `haive init` and the `bootstrap_project` MCP prompt to set it up.\",\n );\n }\n\n if (!existsSync(paths.memoriesDir)) return;\n\n const all = await loadMemoriesFromDir(paths.memoriesDir);\n const filePaths = parseCsv(opts.files);\n const tokens = opts.task ? tokenizeQuery(opts.task) : null;\n const maxMemories = Math.max(1, Number(opts.maxMemories ?? 10));\n const scopeFilter = opts.scope ?? \"team\";\n\n // Filter: exclude noise, drafts, and stale by default\n const candidates = all.filter(({ memory: mem }) => {\n const fm = mem.frontmatter;\n if (fm.status === \"rejected\" || fm.status === \"deprecated\") return false;\n if (!opts.includeDraft && fm.status === \"draft\") return false;\n if (!opts.includeStale && fm.status === \"stale\") return false;\n if (scopeFilter !== \"all\" && fm.scope !== scopeFilter) return false;\n return true;\n });\n\n // Score by relevance\n const scored = candidates.map(({ memory: mem, filePath }) => {\n const fm = mem.frontmatter;\n let score = 0;\n if (fm.status === \"validated\") score += 3;\n else if (fm.status === \"proposed\") score += 1;\n if (filePaths.length > 0 && memoryMatchesAnchorPaths(mem, filePaths)) score += 4;\n if (tokens && literalMatchesAllTokens(mem, tokens)) score += 3;\n return { memory: mem, filePath, score };\n });\n\n scored.sort((a, b) => b.score - a.score);\n const top = scored.slice(0, maxMemories);\n\n if (top.length === 0) {\n ui.info(\"No relevant memories found.\");\n const draftCount = all.filter(\n (m) =>\n m.memory.frontmatter.status === \"draft\" &&\n (scopeFilter === \"all\" || m.memory.frontmatter.scope === scopeFilter),\n ).length;\n if (draftCount > 0) {\n ui.info(`(${draftCount} draft memories excluded — use --include-draft to show)`);\n }\n return;\n }\n\n console.log(`${ui.bold(\"=== Relevant Memories ===\")}\\n`);\n for (const { memory: mem } of top) {\n const fm = mem.frontmatter;\n const badge = ui.statusBadge(fm.status);\n const draftMarker = fm.status === \"draft\" ? ui.yellow(\" [DRAFT]\") : \"\";\n const unverifiedMarker = fm.status === \"proposed\" ? ui.yellow(\" [UNVERIFIED]\") : \"\";\n console.log(\n `${ui.bold(fm.id)} ${ui.dim(fm.scope + \"/\" + fm.type)} ${badge}${draftMarker}${unverifiedMarker}`,\n );\n console.log(mem.body.trim());\n console.log();\n }\n console.log(ui.dim(`${top.length} memor${top.length === 1 ? \"y\" : \"ies\"} surfaced`));\n\n // Track reads so usage stats, decay, and hot-memory detection work via CLI too\n const ids = top.map(({ memory: mem }) => mem.frontmatter.id);\n if (ids.length > 0) {\n await trackReads(paths, ids).catch(() => { /* non-fatal */ });\n }\n });\n}\n\nfunction parseCsv(value: string | undefined): string[] {\n if (!value) return [];\n return value.split(\",\").map((s) => s.trim()).filter(Boolean);\n}\n","import pc from \"picocolors\";\n\nexport const ui = {\n info: (msg: string) => console.log(pc.cyan(\"ℹ\"), msg),\n success: (msg: string) => console.log(pc.green(\"✓\"), msg),\n warn: (msg: string) => console.log(pc.yellow(\"⚠\"), msg),\n error: (msg: string) => console.error(pc.red(\"✗\"), msg),\n dim: (msg: string) => pc.dim(msg),\n bold: (msg: string) => pc.bold(msg),\n green: (msg: string) => pc.green(msg),\n yellow: (msg: string) => pc.yellow(msg),\n red: (msg: string) => pc.red(msg),\n statusBadge: (status: string): string => {\n switch (status) {\n case \"validated\": return pc.green(status);\n case \"proposed\": return pc.yellow(status);\n case \"stale\": return pc.yellow(status);\n case \"rejected\": return pc.red(status);\n case \"deprecated\": return pc.dim(status);\n default: return pc.dim(status); // draft\n }\n },\n};\n","import { Command } from \"commander\";\nimport { findProjectRoot } from \"@hiveai/core\";\n\nexport function registerTui(program: Command): void {\n program\n .command(\"tui\")\n .description(\"Interactive TUI dashboard — browse, filter, and manage memories in the terminal\")\n .option(\"-d, --dir <dir>\", \"project root\")\n .action(async (opts: { dir?: string }) => {\n if (!process.stdout.isTTY) {\n console.error(\"haive tui requires an interactive terminal (TTY).\");\n process.exitCode = 1;\n return;\n }\n const root = findProjectRoot(opts.dir);\n const { render } = await import(\"ink\");\n const { createElement } = await import(\"react\");\n const { Dashboard } = await import(\"../tui/Dashboard.js\");\n const { waitUntilExit } = render(createElement(Dashboard, { root }));\n await waitUntilExit();\n });\n}\n","import { existsSync } from \"node:fs\";\nimport path from \"node:path\";\nimport { Command } from \"commander\";\nimport { findProjectRoot, resolveHaivePaths } from \"@hiveai/core\";\nimport { ui } from \"../utils/ui.js\";\n\ninterface EmbeddingsOptions {\n dir?: string;\n}\n\ninterface EmbeddingsQueryOptions extends EmbeddingsOptions {\n limit?: string;\n minScore?: string;\n}\n\nexport function registerEmbeddings(program: Command): void {\n const embeddings = program\n .command(\"embeddings\")\n .description(\"Manage local embeddings index for semantic search\");\n\n embeddings\n .command(\"index\")\n .description(\"Generate or refresh the embeddings index for all memories\")\n .option(\"-d, --dir <dir>\", \"project root\")\n .action(async (opts: EmbeddingsOptions) => {\n const root = findProjectRoot(opts.dir);\n const paths = resolveHaivePaths(root);\n if (!existsSync(paths.memoriesDir)) {\n ui.error(`No .ai/memories at ${root}. Run \\`haive init\\` first.`);\n process.exitCode = 1;\n return;\n }\n const { Embedder, rebuildIndex } = await loadEmbeddings();\n ui.info(\"Loading embedding model (first run downloads ~110MB)…\");\n const embedder = await Embedder.create();\n ui.info(`Model ready: ${embedder.model} (dim=${embedder.dimension}). Indexing memories…`);\n const { report } = await rebuildIndex(paths, embedder);\n ui.success(\n `Indexed ${report.total} memories — added=${report.added} updated=${report.updated} unchanged=${report.unchanged} removed=${report.removed}`,\n );\n });\n\n embeddings\n .command(\"query <text>\")\n .description(\"Run a semantic search against the local embeddings index\")\n .option(\"-d, --dir <dir>\", \"project root\")\n .option(\"--limit <n>\", \"max results\", \"10\")\n .option(\"--min-score <n>\", \"minimum cosine similarity (0-1)\", \"0\")\n .action(async (text: string, opts: EmbeddingsQueryOptions) => {\n const root = findProjectRoot(opts.dir);\n const paths = resolveHaivePaths(root);\n const { semanticSearch } = await loadEmbeddings();\n const result = await semanticSearch(paths, text, {\n limit: Number(opts.limit ?? 10),\n minScore: Number(opts.minScore ?? 0),\n });\n if (!result) {\n ui.error(\"No embeddings index found. Run `haive embeddings index` first.\");\n process.exitCode = 1;\n return;\n }\n if (result.hits.length === 0) {\n ui.info(\"No semantic matches above the threshold.\");\n return;\n }\n for (const hit of result.hits) {\n const score = hit.score.toFixed(3);\n console.log(`${ui.bold(score)} ${hit.id}`);\n console.log(` ${ui.dim(path.relative(root, hit.file_path))}`);\n }\n });\n\n embeddings\n .command(\"status\")\n .description(\"Show the embeddings index status\")\n .option(\"-d, --dir <dir>\", \"project root\")\n .action(async (opts: EmbeddingsOptions) => {\n const root = findProjectRoot(opts.dir);\n const paths = resolveHaivePaths(root);\n const { indexStat } = await loadEmbeddings();\n const stat = await indexStat(paths);\n if (!stat.exists) {\n ui.warn(\"No embeddings index. Run `haive embeddings index` to create one.\");\n return;\n }\n console.log(`${ui.bold(\"entries:\")} ${stat.count}`);\n console.log(`${ui.bold(\"model:\")} ${stat.model}`);\n console.log(`${ui.bold(\"updated_at:\")} ${stat.updatedAt}`);\n console.log(`${ui.bold(\"size:\")} ${(stat.sizeBytes / 1024).toFixed(1)} KB`);\n });\n}\n\nasync function loadEmbeddings() {\n try {\n return await import(\"@hiveai/embeddings\");\n } catch {\n ui.error(\n \"Could not load @hiveai/embeddings. Run: npm install -g @hiveai/embeddings (or `pnpm build` in the monorepo)\",\n );\n process.exit(1);\n }\n}\n","import path from \"node:path\";\nimport { Command } from \"commander\";\nimport {\n buildCodeMap,\n codeMapPath,\n findProjectRoot,\n resolveHaivePaths,\n saveCodeMap,\n} from \"@hiveai/core\";\nimport { ui } from \"../utils/ui.js\";\n\ninterface IndexCodeOptions {\n dir?: string;\n exclude?: string;\n}\n\nexport function registerIndexCode(program: Command): void {\n const idx = program.command(\"index\").description(\"Build local indexes that help AIs read less code\");\n idx.action(() => idx.help());\n idx\n .command(\"code\")\n .description(\"Scan source files and write .ai/code-map.json (file → exports + 1-line description)\")\n .option(\"-d, --dir <dir>\", \"project root\")\n .option(\n \"--exclude <csv>\",\n \"extra directory names to skip (comma-separated)\",\n \"\",\n )\n .action(async (opts: IndexCodeOptions) => {\n const root = findProjectRoot(opts.dir);\n const paths = resolveHaivePaths(root);\n const extraExcludes = (opts.exclude ?? \"\")\n .split(\",\")\n .map((s) => s.trim())\n .filter(Boolean);\n\n ui.info(`Indexing source files in ${root}…`);\n const map = await buildCodeMap(root, {\n excludeDirs: [\n \"node_modules\",\n \"dist\",\n \"build\",\n \"out\",\n \".git\",\n \".next\",\n \".turbo\",\n \".vitest-cache\",\n \"coverage\",\n ...extraExcludes,\n ],\n });\n\n await saveCodeMap(paths, map);\n const fileCount = Object.keys(map.files).length;\n const exportCount = Object.values(map.files).reduce((s, f) => s + f.exports.length, 0);\n ui.success(\n `Indexed ${fileCount} file(s) with ${exportCount} export(s) → ${path.relative(root, codeMapPath(paths))}`,\n );\n });\n}\n","import { mkdir, writeFile } from \"node:fs/promises\";\nimport { existsSync } from \"node:fs\";\nimport path from \"node:path\";\nimport { Command } from \"commander\";\nimport { findProjectRoot, resolveHaivePaths } from \"@hiveai/core\";\nimport { ui } from \"../utils/ui.js\";\n\nconst PROJECT_CONTEXT_TEMPLATE = `# Project context\n\n> Generated by \\`haive init\\`. Edit this file (or let your AI agent fill it via the upcoming MCP \\`bootstrap_project\\` tool).\n\n## Architecture\nTODO — high-level overview of the codebase.\n\n## Key modules\nTODO — list main modules and their purpose.\n\n## Conventions\nTODO — coding conventions, naming, patterns the team follows.\n\n## Glossary\nTODO — domain terms and what they mean here.\n\n## Gotchas\nTODO — known traps, surprising behavior, things newcomers stub their toes on.\n`;\n\nconst BRIDGE_BODY = `<!-- hAIve bridge file — do not edit by hand. -->\n<!-- This file points your AI tool at the shared hAIve project context. -->\n\nSee \\`.ai/project-context.md\\` for the full project context.\nMemories live under \\`.ai/memories/\\` (personal/team/module).\n\n## hAIve — mandatory rules for AI agents\n- **Before** marking a task as done (\"Done\", \"Finished\", \"C'est fait\"), call the MCP prompt \\`post_task\\`.\n- **Immediately** when an approach fails (wrong API, wrong pattern, wrong assumption), call \\`mem_tried\\` — do not wait until the end of the session.\n- When starting a new task, call \\`get_briefing\\` with the task description to load relevant memories and avoid repeating past mistakes.\n`;\n\nconst CI_WORKFLOW = `name: haive-sync\n\non:\n push:\n branches: [main, master]\n pull_request:\n paths:\n - '.ai/**'\n\njobs:\n sync:\n runs-on: ubuntu-latest\n steps:\n - uses: actions/checkout@v4\n with:\n fetch-depth: 0\n\n - uses: actions/setup-node@v4\n with:\n node-version: '20'\n\n - name: Install hAIve CLI\n run: npm install -g @haive/cli\n\n - name: Sync memories (verify anchors + auto-promote)\n run: haive sync --quiet\n\n - name: Commit updated memories (if any)\n run: |\n git config user.name \"github-actions[bot]\"\n git config user.email \"github-actions[bot]@users.noreply.github.com\"\n git add .ai/\n git diff --cached --quiet || git commit -m \"chore: haive sync [skip ci]\"\n git push\n`;\n\nexport function registerInit(program: Command): void {\n program\n .command(\"init\")\n .description(\"Initialize a hAIve project (.ai/ structure + bridge files)\")\n .option(\"-d, --dir <dir>\", \"project root\", process.cwd())\n .option(\"--no-bridges\", \"do not generate CLAUDE.md / .cursorrules / copilot-instructions.md\")\n .option(\"--with-ci\", \"write a GitHub Actions workflow (.github/workflows/haive-sync.yml)\")\n .action(async (opts: { dir: string; bridges: boolean; withCi?: boolean }) => {\n const root = path.resolve(opts.dir);\n const paths = resolveHaivePaths(root);\n\n if (existsSync(paths.haiveDir)) {\n ui.warn(`.ai/ already exists at ${paths.haiveDir} — leaving existing files in place.`);\n }\n\n await mkdir(paths.personalDir, { recursive: true });\n await mkdir(paths.teamDir, { recursive: true });\n await mkdir(paths.moduleDir, { recursive: true });\n await mkdir(paths.modulesContextDir, { recursive: true });\n\n if (!existsSync(paths.projectContext)) {\n await writeFile(paths.projectContext, PROJECT_CONTEXT_TEMPLATE, \"utf8\");\n ui.success(`Created ${path.relative(root, paths.projectContext)}`);\n }\n\n if (opts.bridges) {\n await writeBridge(root, \"CLAUDE.md\");\n await writeBridge(root, \".cursorrules\");\n await writeBridge(root, path.join(\".github\", \"copilot-instructions.md\"));\n }\n\n if (opts.withCi) {\n const ciPath = path.join(root, \".github\", \"workflows\", \"haive-sync.yml\");\n if (existsSync(ciPath)) {\n ui.info(\"CI workflow already exists — skipped\");\n } else {\n await mkdir(path.dirname(ciPath), { recursive: true });\n await writeFile(ciPath, CI_WORKFLOW, \"utf8\");\n ui.success(`Created ${path.relative(root, ciPath)}`);\n }\n }\n\n ui.success(`hAIve initialized at ${root}`);\n ui.info(\"Next: \" + ui.bold(\"haive memory add --type convention --slug <name>\"));\n });\n}\n\nasync function writeBridge(root: string, relPath: string): Promise<void> {\n const target = path.join(root, relPath);\n if (existsSync(target)) {\n ui.info(`Bridge ${relPath} already exists — skipped`);\n return;\n }\n await mkdir(path.dirname(target), { recursive: true });\n await writeFile(target, BRIDGE_BODY, \"utf8\");\n ui.success(`Created bridge ${relPath}`);\n}\n\n","import { mkdir, writeFile, chmod, readFile } from \"node:fs/promises\";\nimport { existsSync } from \"node:fs\";\nimport path from \"node:path\";\nimport { Command } from \"commander\";\nimport { findProjectRoot } from \"@hiveai/core\";\nimport { ui } from \"../utils/ui.js\";\n\ninterface InstallHooksOptions {\n dir?: string;\n force?: boolean;\n}\n\nconst HOOK_MARKER = \"# hAIve auto-generated\";\n\nconst HOOK_BODY = `#!/bin/sh\n${HOOK_MARKER} — keep this block to allow upgrades. Hand-edit anything outside it.\n\n# After a merge or pull, refresh memory anchors and auto-promote eligible\n# memories so that everyone on this branch sees consistent confidence levels.\nif command -v haive >/dev/null 2>&1; then\n haive sync --quiet --since ORIG_HEAD || true\nelif [ -x ./node_modules/.bin/haive ]; then\n ./node_modules/.bin/haive sync --quiet --since ORIG_HEAD || true\nfi\n`;\n\nconst HOOKS = [\"post-merge\", \"post-rewrite\"] as const;\n\nexport function registerInstallHooks(program: Command): void {\n program\n .command(\"install-hooks\")\n .description(\"Install git hooks that run `haive sync` after pull/merge\")\n .option(\"-d, --dir <dir>\", \"project root\")\n .option(\"--force\", \"overwrite existing hooks\")\n .action(async (opts: InstallHooksOptions) => {\n const root = findProjectRoot(opts.dir);\n const gitDir = path.join(root, \".git\");\n if (!existsSync(gitDir)) {\n ui.error(`No .git directory at ${root}.`);\n process.exitCode = 1;\n return;\n }\n const hooksDir = path.join(gitDir, \"hooks\");\n await mkdir(hooksDir, { recursive: true });\n\n let installed = 0;\n let skipped = 0;\n for (const name of HOOKS) {\n const file = path.join(hooksDir, name);\n if (existsSync(file) && !opts.force) {\n const existing = await readFile(file, \"utf8\");\n if (!existing.includes(HOOK_MARKER)) {\n ui.warn(`${name} already exists and was not written by hAIve. Re-run with --force to overwrite.`);\n skipped++;\n continue;\n }\n }\n await writeFile(file, HOOK_BODY, \"utf8\");\n await chmod(file, 0o755);\n installed++;\n }\n ui.success(`Installed ${installed} hook(s) in .git/hooks/${skipped ? `, skipped ${skipped}` : \"\"}`);\n ui.info(\"Test with: git pull (or any merge), then check .ai/memories for status updates.\");\n });\n}\n","import { spawn } from \"node:child_process\";\nimport { existsSync } from \"node:fs\";\nimport { createRequire } from \"node:module\";\nimport path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { Command } from \"commander\";\nimport { findProjectRoot } from \"@hiveai/core\";\nimport { ui } from \"../utils/ui.js\";\n\nconst require = createRequire(import.meta.url);\n\ninterface McpOptions {\n dir?: string;\n}\n\nexport function registerMcp(program: Command): void {\n program\n .command(\"mcp\")\n .description(\"Start the hAIve MCP server (stdio transport)\")\n .option(\"-d, --dir <dir>\", \"project root (defaults to nearest .ai/ or .git/)\")\n .action((opts: McpOptions) => {\n const root = findProjectRoot(opts.dir);\n const bin = locateMcpBin();\n if (!bin) {\n ui.error(\n \"@hiveai/mcp binary not found. Install @hiveai/mcp or run `pnpm build` in the monorepo.\",\n );\n process.exit(1);\n }\n const child = spawn(\"node\", [bin, \"--root\", root], {\n stdio: [\"inherit\", \"inherit\", \"inherit\"],\n env: process.env,\n });\n child.on(\"exit\", (code) => process.exit(code ?? 0));\n });\n}\n\nfunction locateMcpBin(): string | null {\n // 1. Resolve the @hiveai/mcp package and use its bin entry.\n try {\n const pkgPath = require.resolve(\"@hiveai/mcp/package.json\");\n const pkgDir = path.dirname(pkgPath);\n const candidate = path.join(pkgDir, \"dist\", \"index.js\");\n if (existsSync(candidate)) return candidate;\n } catch {\n // not installed — fall through\n }\n\n // 2. Fallback: look for sibling package in monorepo dev mode.\n const here = path.dirname(fileURLToPath(import.meta.url));\n const sibling = path.resolve(here, \"..\", \"..\", \"..\", \"mcp\", \"dist\", \"index.js\");\n if (existsSync(sibling)) return sibling;\n\n return null;\n}\n","import { spawnSync } from \"node:child_process\";\nimport { readFile, writeFile } from \"node:fs/promises\";\nimport { existsSync } from \"node:fs\";\nimport path from \"node:path\";\nimport { Command } from \"commander\";\nimport {\n DEFAULT_AUTO_PROMOTE_RULE,\n findProjectRoot,\n getUsage,\n isAutoPromoteEligible,\n isDecaying,\n loadMemoriesFromDir,\n loadUsageIndex,\n resolveHaivePaths,\n serializeMemory,\n verifyAnchor,\n} from \"@hiveai/core\";\nimport { ui } from \"../utils/ui.js\";\n\nconst BRIDGE_START = \"<!-- haive:memories-start -->\";\nconst BRIDGE_END = \"<!-- haive:memories-end -->\";\n\ninterface SyncOptions {\n dir?: string;\n quiet?: boolean;\n since?: string;\n verify?: boolean;\n promote?: boolean;\n injectBridge?: boolean;\n bridgeFile?: string;\n bridgeMaxMemories?: string;\n embed?: boolean;\n}\n\nexport function registerSync(program: Command): void {\n program\n .command(\"sync\")\n .description(\"Refresh memory state after a pull/merge: verify anchors, auto-promote, report changes\")\n .option(\"-d, --dir <dir>\", \"project root\")\n .option(\"--quiet\", \"minimal output (suitable for git hooks)\")\n .option(\n \"--since <ref>\",\n \"git ref/commit to compare against; report memories added/modified/removed since\",\n )\n .option(\"--no-verify\", \"skip the anchor verification step\")\n .option(\"--no-promote\", \"skip the auto-promotion step\")\n .option(\n \"--inject-bridge\",\n \"inject top validated memories into CLAUDE.md (or --bridge-file) between <!-- haive:memories-start/end --> markers\",\n )\n .option(\"--bridge-file <path>\", \"bridge file to inject into (default: CLAUDE.md)\")\n .option(\"--bridge-max-memories <n>\", \"max memories to inject into bridge file\", \"5\")\n .option(\"--embed\", \"rebuild embeddings index after sync (requires @haive/embeddings)\")\n .action(async (opts: SyncOptions) => {\n const root = findProjectRoot(opts.dir);\n const paths = resolveHaivePaths(root);\n if (!existsSync(paths.memoriesDir)) {\n if (!opts.quiet) ui.warn(`No .ai/memories at ${root}. Run \\`haive init\\` first.`);\n process.exitCode = 1;\n return;\n }\n\n const log = (msg: string): void => {\n if (!opts.quiet) console.log(msg);\n };\n\n let staleMarked = 0;\n let revalidated = 0;\n let promoted = 0;\n\n if (opts.verify !== false) {\n const memories = await loadMemoriesFromDir(paths.memoriesDir);\n for (const { memory, filePath } of memories) {\n const isAnchored =\n memory.frontmatter.anchor.paths.length > 0 ||\n memory.frontmatter.anchor.symbols.length > 0;\n if (!isAnchored) continue;\n\n const result = await verifyAnchor(memory, { projectRoot: root });\n const verifiedAt = new Date().toISOString();\n\n if (result.stale) {\n if (memory.frontmatter.status !== \"stale\") {\n await writeFile(\n filePath,\n serializeMemory({\n frontmatter: {\n ...memory.frontmatter,\n status: \"stale\",\n verified_at: verifiedAt,\n stale_reason: result.reason,\n },\n body: memory.body,\n }),\n \"utf8\",\n );\n staleMarked++;\n }\n } else if (memory.frontmatter.status === \"stale\") {\n await writeFile(\n filePath,\n serializeMemory({\n frontmatter: {\n ...memory.frontmatter,\n status: \"validated\",\n verified_at: verifiedAt,\n stale_reason: null,\n },\n body: memory.body,\n }),\n \"utf8\",\n );\n revalidated++;\n }\n }\n }\n\n if (opts.promote !== false) {\n const memories = await loadMemoriesFromDir(paths.memoriesDir);\n const usage = await loadUsageIndex(paths);\n for (const { memory, filePath } of memories) {\n if (\n isAutoPromoteEligible(\n memory.frontmatter,\n getUsage(usage, memory.frontmatter.id),\n DEFAULT_AUTO_PROMOTE_RULE,\n )\n ) {\n await writeFile(\n filePath,\n serializeMemory({\n frontmatter: { ...memory.frontmatter, status: \"validated\" },\n body: memory.body,\n }),\n \"utf8\",\n );\n promoted++;\n }\n }\n }\n\n const sinceReport = opts.since ? collectSinceChanges(root, opts.since) : null;\n\n const draftMemories = (await loadMemoriesFromDir(paths.memoriesDir)).filter(\n (m) => m.memory.frontmatter.status === \"draft\",\n );\n const draftCount = draftMemories.length;\n\n log(\n `${ui.dim(\"sync:\")} ${staleMarked} stale · ${revalidated} revalidated · ${promoted} promoted${sinceReport ? ` · ${sinceReport.added.length}+/${sinceReport.modified.length}~/${sinceReport.removed.length}- since ${opts.since}` : \"\"}`,\n );\n if (!opts.quiet && draftCount > 0) {\n log(\n ui.dim(\n `ℹ ${draftCount} memor${draftCount === 1 ? \"y\" : \"ies\"} in draft — run \\`haive memory approve <id>\\` to activate or \\`haive memory list --status draft\\` to review`,\n ),\n );\n }\n\n if (opts.injectBridge) {\n const bridgeFile = opts.bridgeFile\n ? path.resolve(opts.bridgeFile)\n : path.join(root, \"CLAUDE.md\");\n const maxInject = Math.max(1, Number(opts.bridgeMaxMemories ?? 5));\n await injectBridge(bridgeFile, paths.memoriesDir, maxInject, root, opts.quiet);\n }\n\n if (sinceReport && !opts.quiet) {\n if (sinceReport.added.length > 0) {\n log(ui.bold(\"\\nNew memories:\"));\n for (const f of sinceReport.added) log(` + ${f}`);\n }\n if (sinceReport.modified.length > 0) {\n log(ui.bold(\"\\nModified:\"));\n for (const f of sinceReport.modified) log(` ~ ${f}`);\n }\n if (sinceReport.removed.length > 0) {\n log(ui.bold(\"\\nRemoved:\"));\n for (const f of sinceReport.removed) log(` - ${f}`);\n }\n }\n\n // Decay report: memories not read in >90 days\n if (!opts.quiet) {\n const allForDecay = await loadMemoriesFromDir(paths.memoriesDir);\n const usageForDecay = await loadUsageIndex(paths);\n const decaying = allForDecay.filter(({ memory }) => {\n const fm = memory.frontmatter;\n if (fm.status === \"rejected\" || fm.status === \"deprecated\" || fm.status === \"stale\") return false;\n const u = getUsage(usageForDecay, fm.id);\n return isDecaying(u, fm.created_at);\n });\n if (decaying.length > 0) {\n log(ui.yellow(`\\n⚠ ${decaying.length} memor${decaying.length === 1 ? \"y\" : \"ies\"} not read in >90 days (consider reviewing or deprecating):`));\n for (const { memory } of decaying) {\n log(ui.dim(` ${memory.frontmatter.id}`));\n }\n }\n }\n\n // --embed: rebuild embeddings index after sync\n if (opts.embed) {\n try {\n const emb = await import(\"@hiveai/embeddings\");\n log(ui.dim(\"embed: rebuilding index…\"));\n const report = await emb.rebuildIndex(paths);\n log(ui.dim(`embed: index rebuilt (${report.added} added, ${report.updated} updated, ${report.removed} removed)`));\n } catch {\n ui.warn(\"--embed: @hiveai/embeddings not available or index build failed. Run `haive embeddings index` manually.\");\n }\n }\n });\n}\n\nasync function injectBridge(\n bridgeFile: string,\n memoriesDir: string,\n maxMemories: number,\n root: string,\n quiet?: boolean,\n): Promise<void> {\n if (!existsSync(memoriesDir)) return;\n\n const all = await loadMemoriesFromDir(memoriesDir);\n const top = all\n .filter(({ memory }) => {\n const s = memory.frontmatter.status;\n return s === \"validated\" || s === \"proposed\";\n })\n .sort((a, b) => {\n const score = (m: typeof a) => {\n const s = m.memory.frontmatter.status;\n return (s === \"validated\" ? 2 : 1);\n };\n return score(b) - score(a);\n })\n .slice(0, maxMemories);\n\n const block = top\n .map((m) => {\n const fm = m.memory.frontmatter;\n const unverified = fm.status === \"proposed\" ? \" [UNVERIFIED]\" : \"\";\n return `### ${fm.id} (${fm.scope}/${fm.type})${unverified}\\n${m.memory.body.trim()}`;\n })\n .join(\"\\n\\n---\\n\\n\");\n\n const injected =\n `${BRIDGE_START}\\n` +\n `<!-- AUTO-GENERATED by haive sync --inject-bridge — do not edit between these markers -->\\n\\n` +\n block +\n `\\n\\n${BRIDGE_END}`;\n\n const fileExists = existsSync(bridgeFile);\n let existing = fileExists ? await readFile(bridgeFile, \"utf8\") : \"\";\n // Normalize line endings to avoid \\r\\n accumulation\n existing = existing.replace(/\\r\\n/g, \"\\n\");\n\n const startIdx = existing.indexOf(BRIDGE_START);\n const endIdx = existing.indexOf(BRIDGE_END);\n\n // Detect partial markers — safer to abort than silently corrupt the file\n if (startIdx !== -1 && endIdx === -1) {\n ui.warn(`${path.relative(root, bridgeFile)}: found ${BRIDGE_START} without ${BRIDGE_END}. Fix the file manually before running --inject-bridge.`);\n return;\n }\n if (startIdx === -1 && endIdx !== -1) {\n ui.warn(`${path.relative(root, bridgeFile)}: found ${BRIDGE_END} without ${BRIDGE_START}. Fix the file manually before running --inject-bridge.`);\n return;\n }\n\n let updated: string;\n if (startIdx !== -1 && endIdx !== -1 && endIdx > startIdx) {\n updated = existing.slice(0, startIdx) + injected + existing.slice(endIdx + BRIDGE_END.length);\n } else {\n if (!fileExists && !quiet) {\n ui.info(`Creating ${path.relative(root, bridgeFile)} with haive memory block.`);\n }\n updated = existing + (existing.endsWith(\"\\n\") ? \"\" : \"\\n\") + \"\\n\" + injected + \"\\n\";\n }\n\n await writeFile(bridgeFile, updated, \"utf8\");\n if (!quiet) {\n console.log(\n ui.dim(`bridge: injected ${top.length} memor${top.length === 1 ? \"y\" : \"ies\"} into ${path.relative(root, bridgeFile)}`),\n );\n }\n}\n\ninterface SinceReport {\n added: string[];\n modified: string[];\n removed: string[];\n}\n\nfunction collectSinceChanges(root: string, ref: string): SinceReport | null {\n const result = spawnSync(\n \"git\",\n [\"-C\", root, \"diff\", \"--name-status\", \"--diff-filter=AMD\", `${ref}...HEAD`, \"--\", \".ai/memories\"],\n { encoding: \"utf8\" },\n );\n if (result.status !== 0) return null;\n\n const report: SinceReport = { added: [], modified: [], removed: [] };\n for (const line of result.stdout.split(\"\\n\")) {\n const [status, ...rest] = line.split(\"\\t\");\n const file = rest.join(\"\\t\").trim();\n if (!file) continue;\n if (status === \"A\") report.added.push(file);\n else if (status === \"M\") report.modified.push(file);\n else if (status === \"D\") report.removed.push(file);\n }\n return report;\n}\n","import { mkdir, readFile, writeFile } from \"node:fs/promises\";\nimport { existsSync } from \"node:fs\";\nimport path from \"node:path\";\nimport { Command } from \"commander\";\nimport {\n buildFrontmatter,\n findProjectRoot,\n inferModulesFromPaths,\n loadMemoriesFromDir,\n memoryFilePath,\n resolveHaivePaths,\n serializeMemory,\n type MemoryScope,\n type MemoryType,\n} from \"@hiveai/core\";\nimport { ui } from \"../utils/ui.js\";\n\ninterface AddOptions {\n type: MemoryType;\n slug: string;\n title?: string;\n scope?: MemoryScope;\n module?: string;\n tags?: string;\n domain?: string;\n author?: string;\n paths?: string;\n symbols?: string;\n commit?: string;\n body?: string;\n bodyFile?: string;\n dir?: string;\n}\n\nexport function registerMemoryAdd(memory: Command): void {\n memory\n .command(\"add\")\n .description(\"Add a new memory (defaults to personal scope)\")\n .requiredOption(\"--type <type>\", \"convention | decision | gotcha | architecture | glossary | attempt\")\n .requiredOption(\"--slug <slug>\", \"short identifier used in the file name\")\n .option(\"--title <text>\", \"memory title — becomes the first heading of the body\")\n .option(\"--scope <scope>\", \"personal | team | module\", \"personal\")\n .option(\"--module <name>\", \"module name (required when scope=module)\")\n .option(\"--tags <csv>\", \"comma-separated tags\")\n .option(\"--domain <domain>\", \"domain (e.g. transactions)\")\n .option(\"--author <author>\", \"author email or handle\")\n .option(\"--paths <csv>\", \"anchor paths, comma-separated\")\n .option(\"--symbols <csv>\", \"anchor symbols, comma-separated\")\n .option(\"--commit <sha>\", \"anchor commit SHA\")\n .option(\"--body <text>\", \"memory body content (Markdown) — overrides --title default body\")\n .option(\"--body-file <path>\", \"read memory body from a Markdown file — alternative to --body for long content\")\n .option(\"--no-auto-tag\", \"disable automatic tag suggestions inferred from anchor paths\")\n .option(\"-d, --dir <dir>\", \"project root\")\n .action(async (opts: AddOptions & { autoTag?: boolean }) => {\n const root = findProjectRoot(opts.dir);\n const paths = resolveHaivePaths(root);\n if (!existsSync(paths.haiveDir)) {\n ui.error(`No .ai/ found at ${root}. Run \\`haive init\\` first.`);\n process.exitCode = 1;\n return;\n }\n\n const userTags = parseCsv(opts.tags);\n const anchorPaths = parseCsv(opts.paths);\n const autoTagsEnabled = opts.autoTag !== false;\n const inferredTags = autoTagsEnabled ? inferModulesFromPaths(anchorPaths) : [];\n const mergedTags = Array.from(new Set([...userTags, ...inferredTags]));\n\n const frontmatter = buildFrontmatter({\n type: opts.type,\n slug: opts.slug,\n scope: opts.scope,\n module: opts.module,\n tags: mergedTags,\n domain: opts.domain,\n author: opts.author,\n paths: anchorPaths,\n symbols: parseCsv(opts.symbols),\n commit: opts.commit,\n });\n\n const title = opts.title ?? opts.slug;\n let body: string;\n if (opts.bodyFile !== undefined) {\n if (!existsSync(opts.bodyFile)) {\n ui.error(`--body-file not found: ${opts.bodyFile}`);\n process.exitCode = 1;\n return;\n }\n const fileContent = await readFile(opts.bodyFile, \"utf8\");\n body = opts.title ? `# ${opts.title}\\n\\n${fileContent.trim()}\\n` : fileContent;\n } else if (opts.body !== undefined) {\n body = opts.title ? `# ${opts.title}\\n\\n${opts.body}` : opts.body;\n } else {\n body = `# ${title}\\n\\nTODO — write the memory body.\\n`;\n }\n\n const file = memoryFilePath(paths, frontmatter.scope, frontmatter.id, frontmatter.module);\n await mkdir(path.dirname(file), { recursive: true });\n\n if (existsSync(file)) {\n ui.error(`Memory already exists at ${file}`);\n process.exitCode = 1;\n return;\n }\n\n // Dedup check: warn if a similar slug already exists\n if (existsSync(paths.memoriesDir)) {\n const existing = await loadMemoriesFromDir(paths.memoriesDir);\n const slugTokens = opts.slug.toLowerCase().split(/[-_\\s]+/).filter(Boolean);\n const similar = existing.filter(({ memory }) => {\n const id = memory.frontmatter.id.toLowerCase();\n return (\n slugTokens.length >= 2 &&\n slugTokens.filter((t) => id.includes(t)).length >= Math.ceil(slugTokens.length * 0.6)\n );\n });\n if (similar.length > 0) {\n ui.warn(`Possible duplicate — similar memories exist: ${similar.map((m) => m.memory.frontmatter.id).join(\", \")}`);\n ui.warn(\"Consider updating one of these with \\`haive memory update\\` instead.\");\n }\n }\n\n await writeFile(file, serializeMemory({ frontmatter, body }), \"utf8\");\n ui.success(`Created ${path.relative(root, file)}`);\n ui.info(`id=${frontmatter.id} scope=${frontmatter.scope} status=${frontmatter.status}`);\n if (inferredTags.length > 0) {\n ui.info(`auto-tagged: ${inferredTags.join(\", \")} (use --no-auto-tag to disable)`);\n }\n\n // Anchorless warning: without paths the memory cannot be verified for staleness\n if (anchorPaths.length === 0) {\n ui.warn(\n `This memory has no anchor paths — staleness cannot be detected automatically.` +\n `\\n Add file anchors: haive memory update ${frontmatter.id} --paths <file1,file2>`,\n );\n }\n\n // Workflow hint\n if (frontmatter.scope === \"personal\") {\n console.log(\n ui.dim(\n `→ next: haive memory approve ${frontmatter.id} (activate)` +\n ` | haive memory promote ${frontmatter.id} (share with team)`,\n ),\n );\n } else {\n console.log(\n ui.dim(`→ next: haive memory approve ${frontmatter.id} (mark as validated)`),\n );\n }\n });\n}\n\nfunction parseCsv(value: string | undefined): string[] {\n if (!value) return [];\n return value\n .split(\",\")\n .map((s) => s.trim())\n .filter(Boolean);\n}\n","import { existsSync } from \"node:fs\";\nimport path from \"node:path\";\nimport { Command } from \"commander\";\nimport { findProjectRoot, resolveHaivePaths, type MemoryScope, type MemoryType } from \"@hiveai/core\";\nimport { loadMemoriesFromDir, type LoadedMemory } from \"../utils/fs.js\";\nimport { ui } from \"../utils/ui.js\";\n\ninterface ListOptions {\n scope?: MemoryScope;\n type?: MemoryType;\n tag?: string;\n module?: string;\n status?: string;\n showRejected?: boolean;\n dir?: string;\n}\n\nexport function registerMemoryList(memory: Command): void {\n memory\n .command(\"list\")\n .description(\"List memories with optional filters\")\n .option(\"--scope <scope>\", \"personal | team | module\")\n .option(\"--type <type>\", \"filter by type\")\n .option(\"--tag <tag>\", \"filter by tag\")\n .option(\"--module <name>\", \"filter by module name\")\n .option(\"--status <csv>\", \"filter by status (draft,proposed,validated,stale,rejected,deprecated)\")\n .option(\"--show-rejected\", \"include rejected memories (hidden by default)\")\n .option(\"-d, --dir <dir>\", \"project root\")\n .action(async (opts: ListOptions) => {\n const root = findProjectRoot(opts.dir);\n const paths = resolveHaivePaths(root);\n if (!existsSync(paths.memoriesDir)) {\n ui.error(`No memories directory at ${paths.memoriesDir}. Run \\`haive init\\` first.`);\n process.exitCode = 1;\n return;\n }\n\n const all = await loadMemoriesFromDir(paths.memoriesDir);\n const statusFilter = opts.status ? opts.status.split(\",\").map((s) => s.trim()) : null;\n const filtered = all.filter((m) => {\n if (!matchesFilters(m, opts)) return false;\n const status = m.memory.frontmatter.status;\n if (!opts.showRejected && !statusFilter && status === \"rejected\") return false;\n if (statusFilter && !statusFilter.includes(status)) return false;\n return true;\n });\n\n // Count hidden rejected (not covered by an explicit status filter)\n const hiddenRejectedCount =\n !opts.showRejected && !statusFilter\n ? all.filter(\n (m) => matchesFilters(m, opts) && m.memory.frontmatter.status === \"rejected\",\n ).length\n : 0;\n\n if (filtered.length === 0) {\n ui.info(\"No memories match the filters.\");\n if (hiddenRejectedCount > 0) {\n ui.info(`(${hiddenRejectedCount} rejected hidden — use --show-rejected to include)`);\n }\n return;\n }\n\n for (const { memory: mem, filePath } of filtered) {\n const fm = mem.frontmatter;\n const tagStr = fm.tags.length ? ui.dim(` [${fm.tags.join(\", \")}]`) : \"\";\n const moduleStr = fm.module ? ui.dim(` (${fm.module})`) : \"\";\n const statusBadge = ui.statusBadge(fm.status);\n console.log(\n `${ui.bold(fm.id)} ${ui.dim(fm.scope)}/${ui.dim(fm.type)} ${statusBadge}${moduleStr}${tagStr}`,\n );\n console.log(` ${ui.dim(path.relative(root, filePath))}`);\n }\n console.log(ui.dim(`\\n${filtered.length} memor${filtered.length === 1 ? \"y\" : \"ies\"}`));\n\n // Always show rejected hint when memories are hidden\n if (hiddenRejectedCount > 0) {\n console.log(\n ui.dim(`(${hiddenRejectedCount} rejected hidden — use --show-rejected to include)`),\n );\n }\n\n // Draft hint: scope-aware\n const draftItems = filtered.filter((m) => m.memory.frontmatter.status === \"draft\");\n if (draftItems.length > 0) {\n const hasPersonalDrafts = draftItems.some(\n (m) => m.memory.frontmatter.scope === \"personal\",\n );\n const hasTeamDrafts = draftItems.some(\n (m) => m.memory.frontmatter.scope !== \"personal\",\n );\n let hint = `ℹ ${draftItems.length} in draft — use \\`haive memory approve <id>\\` to activate`;\n if (hasPersonalDrafts && !hasTeamDrafts) {\n hint += \" or `haive memory promote <id>` to share with team\";\n }\n console.log(ui.dim(hint));\n }\n });\n}\n\nfunction matchesFilters(loaded: LoadedMemory, opts: ListOptions): boolean {\n const fm = loaded.memory.frontmatter;\n if (opts.scope && fm.scope !== opts.scope) return false;\n if (opts.type && fm.type !== opts.type) return false;\n if (opts.tag && !fm.tags.includes(opts.tag)) return false;\n if (opts.module && fm.module !== opts.module) return false;\n return true;\n}\n","export {\n loadMemoriesFromDir,\n loadMemory,\n listMarkdownFilesRecursive,\n type LoadedMemory,\n} from \"@hiveai/core\";\n","import { mkdir, unlink, writeFile } from \"node:fs/promises\";\nimport { existsSync } from \"node:fs\";\nimport path from \"node:path\";\nimport { Command } from \"commander\";\nimport {\n findProjectRoot,\n memoryFilePath,\n resolveHaivePaths,\n serializeMemory,\n} from \"@hiveai/core\";\nimport { loadMemoriesFromDir } from \"../utils/fs.js\";\nimport { ui } from \"../utils/ui.js\";\n\ninterface PromoteOptions {\n dir?: string;\n}\n\nexport function registerMemoryPromote(memory: Command): void {\n memory\n .command(\"promote <id>\")\n .description(\"Promote a personal memory to team scope (status -> proposed)\")\n .option(\"-d, --dir <dir>\", \"project root\")\n .action(async (id: string, opts: PromoteOptions) => {\n const root = findProjectRoot(opts.dir);\n const paths = resolveHaivePaths(root);\n if (!existsSync(paths.memoriesDir)) {\n ui.error(`No memories directory at ${paths.memoriesDir}. Run \\`haive init\\` first.`);\n process.exitCode = 1;\n return;\n }\n\n // Check team/module scope first to give a helpful error\n const teamAndModule = await loadMemoriesFromDir(paths.memoriesDir);\n const alreadyShared = teamAndModule.find(\n (m) =>\n m.memory.frontmatter.id === id &&\n (m.memory.frontmatter.scope === \"team\" || m.memory.frontmatter.scope === \"module\"),\n );\n if (alreadyShared) {\n const fm = alreadyShared.memory.frontmatter;\n ui.warn(\n `\"${id}\" is already in ${fm.scope} scope (status=${fm.status}).`,\n );\n if (fm.status !== \"validated\") {\n ui.info(`→ run \\`haive memory approve ${id}\\` to validate it`);\n }\n return;\n }\n\n const all = await loadMemoriesFromDir(paths.personalDir);\n const found = all.find((m) => m.memory.frontmatter.id === id);\n if (!found) {\n ui.error(`No personal memory with id \"${id}\". (Promotion only applies to personal scope.)`);\n process.exitCode = 1;\n return;\n }\n\n const updated = {\n frontmatter: {\n ...found.memory.frontmatter,\n scope: \"team\" as const,\n status: \"proposed\" as const,\n },\n body: found.memory.body,\n };\n\n const newPath = memoryFilePath(paths, \"team\", updated.frontmatter.id);\n await mkdir(path.dirname(newPath), { recursive: true });\n await writeFile(newPath, serializeMemory(updated), \"utf8\");\n await unlink(found.filePath);\n\n ui.success(`Promoted ${id} to team scope (status=proposed)`);\n ui.info(`Now at ${path.relative(root, newPath)}`);\n console.log(ui.dim(`→ next: haive memory approve ${id} (validate for team use)`));\n });\n}\n","import { existsSync } from \"node:fs\";\nimport { writeFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { Command } from \"commander\";\nimport {\n findProjectRoot,\n resolveHaivePaths,\n serializeMemory,\n} from \"@hiveai/core\";\nimport { loadMemoriesFromDir } from \"../utils/fs.js\";\nimport { ui } from \"../utils/ui.js\";\n\ninterface ApproveOptions {\n all?: boolean;\n pending?: boolean;\n dir?: string;\n}\n\nexport function registerMemoryApprove(memory: Command): void {\n memory\n .command(\"approve [id]\")\n .description(\"Mark a memory as 'validated'. Use --all to bulk-approve all proposed/draft memories.\")\n .option(\"--all\", \"approve all proposed and draft memories at once\")\n .option(\"--pending\", \"approve all memories with status 'proposed'\")\n .option(\"-d, --dir <dir>\", \"project root\")\n .action(async (id: string | undefined, opts: ApproveOptions) => {\n const root = findProjectRoot(opts.dir);\n const paths = resolveHaivePaths(root);\n if (!existsSync(paths.memoriesDir)) {\n ui.error(`No .ai/memories at ${root}.`);\n process.exitCode = 1;\n return;\n }\n\n const all = await loadMemoriesFromDir(paths.memoriesDir);\n\n // Bulk mode\n if (opts.all || opts.pending) {\n const candidates = all.filter((m) => {\n const s = m.memory.frontmatter.status;\n if (opts.all) return s === \"proposed\" || s === \"draft\";\n return s === \"proposed\";\n });\n if (candidates.length === 0) {\n ui.info(opts.all ? \"No draft or proposed memories to approve.\" : \"No proposed memories to approve.\");\n return;\n }\n let count = 0;\n for (const found of candidates) {\n const next = {\n frontmatter: { ...found.memory.frontmatter, status: \"validated\" as const },\n body: found.memory.body,\n };\n await writeFile(found.filePath, serializeMemory(next), \"utf8\");\n count++;\n }\n ui.success(`Approved ${count} memor${count === 1 ? \"y\" : \"ies\"} (status=validated)`);\n return;\n }\n\n // Single mode\n if (!id) {\n ui.error(\"Provide a memory id or use --all / --pending for bulk approval.\");\n process.exitCode = 1;\n return;\n }\n\n const found = all.find((m) => m.memory.frontmatter.id === id);\n if (!found) {\n ui.error(`No memory with id \"${id}\".`);\n process.exitCode = 1;\n return;\n }\n\n const current = found.memory.frontmatter.status;\n if (current === \"validated\") {\n ui.info(`${id} is already validated.`);\n return;\n }\n if (current !== \"proposed\" && current !== \"draft\") {\n ui.warn(`Memory has status \"${current}\"; approve still sets it to validated.`);\n }\n\n const next = {\n frontmatter: { ...found.memory.frontmatter, status: \"validated\" as const },\n body: found.memory.body,\n };\n await writeFile(found.filePath, serializeMemory(next), \"utf8\");\n ui.success(`Approved ${id} (status=validated)`);\n ui.info(path.relative(root, found.filePath));\n });\n}\n","import { writeFile } from \"node:fs/promises\";\nimport { existsSync } from \"node:fs\";\nimport path from \"node:path\";\nimport { Command } from \"commander\";\nimport {\n findProjectRoot,\n resolveHaivePaths,\n serializeMemory,\n} from \"@hiveai/core\";\nimport { loadMemoriesFromDir } from \"../utils/fs.js\";\nimport { ui } from \"../utils/ui.js\";\n\ninterface UpdateOptions {\n title?: string;\n body?: string;\n tags?: string;\n paths?: string;\n symbols?: string;\n commit?: string;\n domain?: string;\n author?: string;\n dir?: string;\n}\n\nexport function registerMemoryUpdate(memory: Command): void {\n memory\n .command(\"update <id>\")\n .description(\"Update body, tags, or anchor of an existing memory (preserves id and usage history)\")\n .option(\"--title <text>\", \"new title — replaces the first heading of the body\")\n .option(\"--body <text>\", \"new Markdown body — replaces the existing body\")\n .option(\"--tags <csv>\", \"new tags, comma-separated — fully replaces existing tags\")\n .option(\"--paths <csv>\", \"new anchor paths, comma-separated\")\n .option(\"--symbols <csv>\", \"new anchor symbols, comma-separated\")\n .option(\"--commit <sha>\", \"new anchor commit SHA\")\n .option(\"--domain <domain>\", \"new domain label\")\n .option(\"--author <author>\", \"new author handle or email\")\n .option(\"-d, --dir <dir>\", \"project root\")\n .action(async (id: string, opts: UpdateOptions) => {\n const root = findProjectRoot(opts.dir);\n const paths = resolveHaivePaths(root);\n if (!existsSync(paths.memoriesDir)) {\n ui.error(`No .ai/memories at ${root}. Run \\`haive init\\` first.`);\n process.exitCode = 1;\n return;\n }\n\n const memories = await loadMemoriesFromDir(paths.memoriesDir);\n const loaded = memories.find((m) => m.memory.frontmatter.id === id);\n if (!loaded) {\n ui.error(`No memory with id \"${id}\".`);\n process.exitCode = 1;\n return;\n }\n\n const updated: string[] = [];\n const { frontmatter, body } = loaded.memory;\n\n const newAnchor = { ...frontmatter.anchor };\n if (opts.paths !== undefined) {\n newAnchor.paths = parseCsv(opts.paths);\n updated.push(\"anchor.paths\");\n }\n if (opts.symbols !== undefined) {\n newAnchor.symbols = parseCsv(opts.symbols);\n updated.push(\"anchor.symbols\");\n }\n if (opts.commit !== undefined) {\n newAnchor.commit = opts.commit;\n updated.push(\"anchor.commit\");\n }\n\n const newFrontmatter = {\n ...frontmatter,\n anchor: newAnchor,\n ...(opts.tags !== undefined ? { tags: parseCsv(opts.tags) } : {}),\n ...(opts.domain !== undefined ? { domain: opts.domain } : {}),\n ...(opts.author !== undefined ? { author: opts.author } : {}),\n };\n if (opts.tags !== undefined) updated.push(\"tags\");\n if (opts.domain !== undefined) updated.push(\"domain\");\n if (opts.author !== undefined) updated.push(\"author\");\n\n let newBody = opts.body !== undefined ? opts.body : body;\n if (opts.title !== undefined) {\n newBody = replaceFirstHeading(newBody, opts.title);\n updated.push(\"title\");\n }\n if (opts.body !== undefined) updated.push(\"body\");\n\n if (updated.length === 0) {\n ui.warn(\"Nothing to update — provide at least one option.\");\n return;\n }\n\n await writeFile(\n loaded.filePath,\n serializeMemory({ frontmatter: newFrontmatter, body: newBody }),\n \"utf8\",\n );\n\n ui.success(`Updated ${path.relative(root, loaded.filePath)}`);\n ui.info(`fields: ${updated.join(\", \")}`);\n });\n}\n\nfunction replaceFirstHeading(body: string, title: string): string {\n const headingRe = /^#\\s+.+$/m;\n const replacement = `# ${title}`;\n if (headingRe.test(body)) {\n return body.replace(headingRe, replacement);\n }\n return `${replacement}\\n\\n${body}`;\n}\n\nfunction parseCsv(value: string): string[] {\n return value.split(\",\").map((s) => s.trim()).filter(Boolean);\n}\n","import { writeFile } from \"node:fs/promises\";\nimport { existsSync } from \"node:fs\";\nimport path from \"node:path\";\nimport { Command } from \"commander\";\nimport {\n DEFAULT_AUTO_PROMOTE_RULE,\n findProjectRoot,\n getUsage,\n isAutoPromoteEligible,\n loadUsageIndex,\n resolveHaivePaths,\n serializeMemory,\n} from \"@hiveai/core\";\nimport { loadMemoriesFromDir } from \"../utils/fs.js\";\nimport { ui } from \"../utils/ui.js\";\n\ninterface AutoPromoteOptions {\n minReads?: string;\n maxRejections?: string;\n apply?: boolean;\n dir?: string;\n}\n\nexport function registerMemoryAutoPromote(memory: Command): void {\n memory\n .command(\"auto-promote\")\n .description(\"Promote eligible 'proposed' memories to 'validated' based on usage\")\n .option(\"--min-reads <n>\", \"minimum read_count to qualify\", String(DEFAULT_AUTO_PROMOTE_RULE.minReads))\n .option(\n \"--max-rejections <n>\",\n \"memories with more rejections than this are skipped\",\n String(DEFAULT_AUTO_PROMOTE_RULE.maxRejections),\n )\n .option(\"--apply\", \"actually write status=validated to disk (default: dry-run)\")\n .option(\"-d, --dir <dir>\", \"project root\")\n .action(async (opts: AutoPromoteOptions) => {\n const root = findProjectRoot(opts.dir);\n const paths = resolveHaivePaths(root);\n if (!existsSync(paths.memoriesDir)) {\n ui.error(`No .ai/memories at ${root}.`);\n process.exitCode = 1;\n return;\n }\n\n const rule = {\n minReads: Number(opts.minReads ?? DEFAULT_AUTO_PROMOTE_RULE.minReads),\n maxRejections: Number(opts.maxRejections ?? DEFAULT_AUTO_PROMOTE_RULE.maxRejections),\n };\n\n const memories = await loadMemoriesFromDir(paths.memoriesDir);\n const usage = await loadUsageIndex(paths);\n const eligible = memories.filter(({ memory }) =>\n isAutoPromoteEligible(memory.frontmatter, getUsage(usage, memory.frontmatter.id), rule),\n );\n\n if (eligible.length === 0) {\n ui.info(\n `No memories eligible (minReads=${rule.minReads}, maxRejections=${rule.maxRejections}).`,\n );\n return;\n }\n\n let written = 0;\n for (const { memory: mem, filePath } of eligible) {\n const u = getUsage(usage, mem.frontmatter.id);\n console.log(\n `${ui.bold(opts.apply ? \"PROMOTE\" : \"would promote\")} ${mem.frontmatter.id} ${ui.dim(`reads=${u.read_count} rejections=${u.rejected_count}`)}`,\n );\n console.log(` ${ui.dim(path.relative(root, filePath))}`);\n if (opts.apply) {\n const next = {\n frontmatter: { ...mem.frontmatter, status: \"validated\" as const },\n body: mem.body,\n };\n await writeFile(filePath, serializeMemory(next), \"utf8\");\n written++;\n }\n }\n\n const summary = `${eligible.length} eligible`;\n ui.info(opts.apply ? `${summary} · ${written} promoted` : `${summary} · dry-run (use --apply)`);\n });\n}\n","import { spawn } from \"node:child_process\";\nimport { existsSync } from \"node:fs\";\nimport { readFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { Command } from \"commander\";\nimport {\n findProjectRoot,\n parseMemory,\n resolveHaivePaths,\n} from \"@hiveai/core\";\nimport { loadMemoriesFromDir } from \"../utils/fs.js\";\nimport { ui } from \"../utils/ui.js\";\n\ninterface EditOptions {\n editor?: string;\n dir?: string;\n}\n\nexport function registerMemoryEdit(memory: Command): void {\n memory\n .command(\"edit <id>\")\n .description(\"Open a memory in $EDITOR and re-validate when you save\")\n .option(\"-e, --editor <cmd>\", \"editor command (defaults to $EDITOR or 'vi')\")\n .option(\"-d, --dir <dir>\", \"project root\")\n .action(async (id: string, opts: EditOptions) => {\n const root = findProjectRoot(opts.dir);\n const paths = resolveHaivePaths(root);\n if (!existsSync(paths.memoriesDir)) {\n ui.error(`No .ai/memories at ${root}.`);\n process.exitCode = 1;\n return;\n }\n\n const all = await loadMemoriesFromDir(paths.memoriesDir);\n const found = all.find((m) => m.memory.frontmatter.id === id);\n if (!found) {\n ui.error(`No memory with id \"${id}\".`);\n process.exitCode = 1;\n return;\n }\n\n const editor = opts.editor ?? process.env.EDITOR ?? process.env.VISUAL ?? \"vi\";\n ui.info(`Opening ${path.relative(root, found.filePath)} with ${editor}…`);\n const code = await runEditor(editor, found.filePath);\n if (code !== 0) {\n ui.warn(`Editor exited with status ${code}.`);\n }\n\n try {\n const fresh = await readFile(found.filePath, \"utf8\");\n parseMemory(fresh);\n ui.success(\"Memory still parses cleanly.\");\n } catch (err) {\n ui.error(\n `Memory no longer parses: ${err instanceof Error ? err.message : String(err)}`,\n );\n ui.warn(\"File left as-is on disk; fix it and re-run a parse-aware command to confirm.\");\n process.exitCode = 1;\n }\n });\n}\n\nfunction runEditor(editor: string, file: string): Promise<number> {\n return new Promise((resolve) => {\n const child = spawn(editor, [file], { stdio: \"inherit\" });\n child.on(\"exit\", (code) => resolve(code ?? 0));\n child.on(\"error\", () => resolve(127));\n });\n}\n","import { existsSync } from \"node:fs\";\nimport path from \"node:path\";\nimport { Command } from \"commander\";\nimport {\n deriveConfidence,\n findProjectRoot,\n getUsage,\n inferModulesFromPaths,\n loadUsageIndex,\n memoryMatchesAnchorPaths,\n resolveHaivePaths,\n} from \"@hiveai/core\";\nimport { loadMemoriesFromDir } from \"../utils/fs.js\";\nimport { ui } from \"../utils/ui.js\";\n\ninterface ForFilesOptions {\n dir?: string;\n}\n\nexport function registerMemoryForFiles(memory: Command): void {\n memory\n .command(\"for-files <files...>\")\n .description(\"Show memories relevant to the given files (anchor overlap, module, domain)\")\n .option(\"-d, --dir <dir>\", \"project root\")\n .action(async (files: string[], opts: ForFilesOptions) => {\n const root = findProjectRoot(opts.dir);\n const paths = resolveHaivePaths(root);\n if (!existsSync(paths.memoriesDir)) {\n ui.error(`No .ai/memories at ${root}.`);\n process.exitCode = 1;\n return;\n }\n\n const all = await loadMemoriesFromDir(paths.memoriesDir);\n const usage = await loadUsageIndex(paths);\n const inferred = inferModulesFromPaths(files);\n\n const byAnchor: typeof all = [];\n const byModule: typeof all = [];\n const byDomain: typeof all = [];\n const seen = new Set<string>();\n\n for (const loaded of all) {\n if (memoryMatchesAnchorPaths(loaded.memory, files)) {\n byAnchor.push(loaded);\n seen.add(loaded.memory.frontmatter.id);\n }\n }\n const pathSegments = extractPathSegments(files);\n\n for (const loaded of all) {\n if (seen.has(loaded.memory.frontmatter.id)) continue;\n const fm = loaded.memory.frontmatter;\n const moduleHit =\n (fm.module && inferred.includes(fm.module)) ||\n fm.tags.some((t) => {\n const tl = t.toLowerCase();\n return pathSegments.has(tl) || pathSegments.has(tl.replace(/[-_]/g, \"\"));\n });\n if (moduleHit) {\n byModule.push(loaded);\n seen.add(fm.id);\n }\n }\n for (const loaded of all) {\n if (seen.has(loaded.memory.frontmatter.id)) continue;\n const domain = loaded.memory.frontmatter.domain;\n if (domain && inferred.includes(domain)) {\n byDomain.push(loaded);\n seen.add(loaded.memory.frontmatter.id);\n }\n }\n\n console.log(ui.dim(`inferred modules: ${inferred.length ? inferred.join(\", \") : \"(none)\"}`));\n printGroup(root, \"anchor overlap\", byAnchor, usage);\n printGroup(root, \"module match\", byModule, usage);\n printGroup(root, \"domain match\", byDomain, usage);\n\n const total = byAnchor.length + byModule.length + byDomain.length;\n ui.info(\n `${total} relevant memor${total === 1 ? \"y\" : \"ies\"} (${byAnchor.length} anchor · ${byModule.length} module · ${byDomain.length} domain)`,\n );\n });\n}\n\nfunction extractPathSegments(files: string[]): Set<string> {\n const GENERIC = new Set([\n \"src\", \"main\", \"java\", \"kotlin\", \"python\", \"go\", \"lib\", \"libs\",\n \"com\", \"org\", \"net\", \"io\", \"app\", \"apps\", \"pkg\", \"internal\",\n \"test\", \"tests\", \"spec\", \"specs\", \"impl\", \"domain\", \"shared\",\n \"resources\", \"static\", \"assets\", \"config\", \"configs\",\n ]);\n const out = new Set<string>();\n for (const file of files) {\n const parts = file.replace(/\\\\/g, \"/\").split(\"/\");\n for (const part of parts) {\n const seg = part.toLowerCase().replace(/\\.[^.]+$/, \"\");\n if (seg.length >= 3 && !GENERIC.has(seg) && /^[a-z]/.test(seg)) {\n out.add(seg);\n for (const sub of seg.split(/[-_]/).filter((s) => s.length >= 3)) {\n out.add(sub);\n }\n }\n }\n }\n return out;\n}\n\nfunction printGroup(\n root: string,\n label: string,\n loaded: Array<Awaited<ReturnType<typeof loadMemoriesFromDir>>[number]>,\n usage: Awaited<ReturnType<typeof loadUsageIndex>>,\n): void {\n if (loaded.length === 0) return;\n console.log(ui.bold(`\\n— ${label} —`));\n for (const { memory: mem, filePath } of loaded) {\n const fm = mem.frontmatter;\n const u = getUsage(usage, fm.id);\n const conf = deriveConfidence(fm, u);\n console.log(`${ui.bold(fm.id)} ${ui.dim(`${fm.scope}/${fm.type}`)} ${ui.bold(conf)}`);\n console.log(` ${ui.dim(path.relative(root, filePath))}`);\n }\n}\n","import { existsSync } from \"node:fs\";\nimport path from \"node:path\";\nimport { Command } from \"commander\";\nimport {\n findProjectRoot,\n getUsage,\n loadUsageIndex,\n resolveHaivePaths,\n} from \"@hiveai/core\";\nimport { loadMemoriesFromDir } from \"../utils/fs.js\";\nimport { ui } from \"../utils/ui.js\";\n\ninterface HotOptions {\n threshold?: string;\n status?: \"draft\" | \"proposed\";\n dir?: string;\n}\n\nexport function registerMemoryHot(memory: Command): void {\n memory\n .command(\"hot\")\n .description(\"List memories actively used but not yet validated (good promotion candidates)\")\n .option(\"--threshold <n>\", \"minimum read_count to qualify\", \"3\")\n .option(\"--status <status>\", \"limit to one status (default: draft + proposed)\")\n .option(\"-d, --dir <dir>\", \"project root\")\n .action(async (opts: HotOptions) => {\n const root = findProjectRoot(opts.dir);\n const paths = resolveHaivePaths(root);\n if (!existsSync(paths.memoriesDir)) {\n ui.error(`No .ai/memories at ${root}.`);\n process.exitCode = 1;\n return;\n }\n const threshold = Math.max(1, Number(opts.threshold ?? 3));\n\n const all = await loadMemoriesFromDir(paths.memoriesDir);\n const usage = await loadUsageIndex(paths);\n const candidates = all\n .filter(({ memory: mem }) => {\n const fm = mem.frontmatter;\n if (opts.status && fm.status !== opts.status) return false;\n if (opts.status === undefined && fm.status !== \"draft\" && fm.status !== \"proposed\") {\n return false;\n }\n return getUsage(usage, fm.id).read_count >= threshold;\n })\n .sort(\n (a, b) =>\n getUsage(usage, b.memory.frontmatter.id).read_count -\n getUsage(usage, a.memory.frontmatter.id).read_count,\n );\n\n if (candidates.length === 0) {\n ui.info(`No hot memories (threshold=${threshold}).`);\n return;\n }\n\n for (const { memory: mem, filePath } of candidates) {\n const fm = mem.frontmatter;\n const u = getUsage(usage, fm.id);\n console.log(\n `${ui.bold(fm.id)} ${ui.dim(`${fm.scope}/${fm.type}`)} ${ui.bold(fm.status)} ${ui.dim(`reads=${u.read_count} rejections=${u.rejected_count}`)}`,\n );\n console.log(` ${ui.dim(path.relative(root, filePath))}`);\n }\n ui.info(\n `${candidates.length} hot — promote drafts with \\`haive memory promote <id>\\`, then \\`haive memory auto-promote --apply\\`.`,\n );\n });\n}\n","import { mkdir, writeFile } from \"node:fs/promises\";\nimport { existsSync } from \"node:fs\";\nimport path from \"node:path\";\nimport { Command } from \"commander\";\nimport {\n buildFrontmatter,\n findProjectRoot,\n memoryFilePath,\n resolveHaivePaths,\n serializeMemory,\n type MemoryScope,\n} from \"@hiveai/core\";\nimport { ui } from \"../utils/ui.js\";\n\ninterface TriedOptions {\n what: string;\n whyFailed: string;\n instead?: string;\n scope?: MemoryScope;\n module?: string;\n tags?: string;\n paths?: string;\n author?: string;\n dir?: string;\n}\n\nexport function registerMemoryTried(memory: Command): void {\n memory\n .command(\"tried\")\n .description(\n \"Record a failed approach — negative knowledge to prevent repeated AI mistakes\",\n )\n .requiredOption(\"--what <text>\", \"what approach was tried\")\n .requiredOption(\"--why-failed <text>\", \"why it failed or should NOT be used\")\n .option(\"--instead <text>\", \"recommended alternative\")\n .option(\"--scope <scope>\", \"personal | team | module\", \"personal\")\n .option(\"--module <name>\", \"module name (required when scope=module)\")\n .option(\"--tags <csv>\", \"comma-separated tags\")\n .option(\"--paths <csv>\", \"anchor paths, comma-separated\")\n .option(\"--author <author>\", \"author email or handle\")\n .option(\"-d, --dir <dir>\", \"project root\")\n .action(async (opts: TriedOptions) => {\n const root = findProjectRoot(opts.dir);\n const paths = resolveHaivePaths(root);\n if (!existsSync(paths.haiveDir)) {\n ui.error(`No .ai/ found at ${root}. Run \\`haive init\\` first.`);\n process.exitCode = 1;\n return;\n }\n\n const slug = opts.what\n .toLowerCase()\n .replace(/[^a-z0-9\\s]/g, \"\")\n .trim()\n .split(/\\s+/)\n .slice(0, 5)\n .join(\"-\");\n\n const baseFm = buildFrontmatter({\n type: \"attempt\",\n slug,\n scope: opts.scope,\n module: opts.module,\n tags: parseCsv(opts.tags),\n paths: parseCsv(opts.paths),\n author: opts.author,\n });\n // attempt memories are immediately validated — no review cycle needed\n const frontmatter = { ...baseFm, status: \"validated\" as const };\n\n const lines: string[] = [`# ${opts.what}`, \"\"];\n lines.push(`**Why it failed / do NOT use:** ${opts.whyFailed}`);\n if (opts.instead) {\n lines.push(\"\", `**Instead, use:** ${opts.instead}`);\n }\n const body = lines.join(\"\\n\") + \"\\n\";\n\n const file = memoryFilePath(paths, frontmatter.scope, frontmatter.id, frontmatter.module);\n await mkdir(path.dirname(file), { recursive: true });\n\n if (existsSync(file)) {\n ui.error(`Memory already exists at ${file}`);\n process.exitCode = 1;\n return;\n }\n\n await writeFile(file, serializeMemory({ frontmatter, body }), \"utf8\");\n ui.success(`Recorded: ${path.relative(root, file)}`);\n ui.info(`id=${frontmatter.id} type=attempt status=validated (auto-approved)`);\n });\n}\n\nfunction parseCsv(value: string | undefined): string[] {\n if (!value) return [];\n return value.split(\",\").map((s) => s.trim()).filter(Boolean);\n}\n","import { existsSync } from \"node:fs\";\nimport path from \"node:path\";\nimport { Command } from \"commander\";\nimport {\n findProjectRoot,\n getUsage,\n loadUsageIndex,\n resolveHaivePaths,\n} from \"@hiveai/core\";\nimport { loadMemoriesFromDir } from \"../utils/fs.js\";\nimport { ui } from \"../utils/ui.js\";\n\ninterface PendingOptions {\n scope?: \"personal\" | \"team\" | \"module\";\n dir?: string;\n}\n\nexport function registerMemoryPending(memory: Command): void {\n memory\n .command(\"pending\")\n .description(\"List 'proposed' memories awaiting review (sorted by reads desc)\")\n .option(\"--scope <scope>\", \"filter by scope (personal | team | module)\")\n .option(\"-d, --dir <dir>\", \"project root\")\n .action(async (opts: PendingOptions) => {\n const root = findProjectRoot(opts.dir);\n const paths = resolveHaivePaths(root);\n if (!existsSync(paths.memoriesDir)) {\n ui.error(`No .ai/memories at ${root}.`);\n process.exitCode = 1;\n return;\n }\n\n const all = await loadMemoriesFromDir(paths.memoriesDir);\n const usage = await loadUsageIndex(paths);\n const proposed = all.filter(({ memory: mem }) => {\n if (mem.frontmatter.status !== \"proposed\") return false;\n if (opts.scope && mem.frontmatter.scope !== opts.scope) return false;\n return true;\n });\n\n if (proposed.length === 0) {\n ui.info(\"No memories awaiting review.\");\n return;\n }\n\n proposed.sort(\n (a, b) =>\n getUsage(usage, b.memory.frontmatter.id).read_count -\n getUsage(usage, a.memory.frontmatter.id).read_count,\n );\n\n const now = Date.now();\n for (const { memory: mem, filePath } of proposed) {\n const fm = mem.frontmatter;\n const u = getUsage(usage, fm.id);\n const ageDays = Math.floor((now - new Date(fm.created_at).getTime()) / 86_400_000);\n const ageStr = ageDays === 0 ? \"today\" : `${ageDays}d`;\n console.log(\n `${ui.bold(fm.id)} ${ui.dim(`${fm.scope}/${fm.type}`)} ${ui.dim(`age=${ageStr} reads=${u.read_count} rejections=${u.rejected_count}`)}`,\n );\n console.log(` ${ui.dim(path.relative(root, filePath))}`);\n }\n ui.info(`${proposed.length} pending`);\n });\n}\n","import { existsSync } from \"node:fs\";\nimport path from \"node:path\";\nimport { Command } from \"commander\";\nimport {\n extractSnippet,\n findProjectRoot,\n literalMatchesAllTokens,\n literalMatchesAnyToken,\n pickSnippetNeedle,\n resolveHaivePaths,\n tokenizeQuery,\n trackReads,\n type MemoryScope,\n} from \"@hiveai/core\";\nimport { loadMemoriesFromDir } from \"../utils/fs.js\";\nimport { ui } from \"../utils/ui.js\";\n\ninterface QueryOptions {\n dir?: string;\n limit?: string;\n scope?: MemoryScope;\n status?: string;\n showRejected?: boolean;\n}\n\nexport function registerMemoryQuery(memory: Command): void {\n memory\n .command(\"query <text>\")\n .description(\"Search memories by id, tag, or substring (AND, OR fallback)\")\n .option(\"-d, --dir <dir>\", \"project root\")\n .option(\"--limit <n>\", \"max results\", \"20\")\n .option(\"--scope <scope>\", \"personal | team | module\")\n .option(\"--status <csv>\", \"filter by status (draft,proposed,validated,stale,rejected)\")\n .option(\"--show-rejected\", \"include rejected memories (hidden by default)\")\n .action(async (text: string, opts: QueryOptions) => {\n const root = findProjectRoot(opts.dir);\n const paths = resolveHaivePaths(root);\n if (!existsSync(paths.memoriesDir)) {\n ui.error(`No memories directory at ${paths.memoriesDir}. Run \\`haive init\\` first.`);\n process.exitCode = 1;\n return;\n }\n\n const tokens = tokenizeQuery(text);\n if (tokens.length === 0) {\n ui.warn(\"Empty query — use \\`haive memory list\\` to list all memories.\");\n return;\n }\n const statusFilter = opts.status ? opts.status.split(\",\").map((s) => s.trim()) : null;\n const all = await loadMemoriesFromDir(paths.memoriesDir);\n\n const passesFilters = (mem: (typeof all)[number][\"memory\"]) => {\n const fm = mem.frontmatter;\n if (opts.scope && fm.scope !== opts.scope) return false;\n if (!opts.showRejected && !statusFilter && fm.status === \"rejected\") return false;\n if (statusFilter && !statusFilter.includes(fm.status)) return false;\n return true;\n };\n\n const eligible = all.filter(({ memory: mem }) => passesFilters(mem));\n let matches = eligible.filter(({ memory: mem }) => literalMatchesAllTokens(mem, tokens));\n let fallback = false;\n if (matches.length === 0 && tokens.length > 1) {\n matches = eligible.filter(({ memory: mem }) => literalMatchesAnyToken(mem, tokens));\n fallback = true;\n }\n\n const limit = Math.max(1, Number(opts.limit ?? 20));\n const top = matches.slice(0, limit);\n\n if (top.length === 0) {\n ui.info(`No matches for \"${text}\".`);\n return;\n }\n if (fallback) {\n ui.info(`No exact match — showing partial results (OR fallback):`);\n }\n\n const snippetNeedle = pickSnippetNeedle(text);\n for (const { memory: mem, filePath } of top) {\n const fm = mem.frontmatter;\n const statusBadge = ui.statusBadge(fm.status);\n console.log(`${ui.bold(fm.id)} ${ui.dim(fm.scope)} ${statusBadge}`);\n console.log(` ${ui.dim(path.relative(root, filePath))}`);\n const snippet = extractSnippet(mem.body, snippetNeedle);\n if (snippet) console.log(` ${snippet}`);\n }\n console.log(\n ui.dim(`\\n${top.length} of ${matches.length} match${matches.length === 1 ? \"\" : \"es\"}`),\n );\n\n // Track reads for usage stats / decay / hot detection\n const ids = top.map(({ memory: mem }) => mem.frontmatter.id);\n if (ids.length > 0) {\n await trackReads(paths, ids).catch(() => { /* non-fatal */ });\n }\n });\n}\n","import { writeFile } from \"node:fs/promises\";\nimport { existsSync } from \"node:fs\";\nimport { Command } from \"commander\";\nimport {\n findProjectRoot,\n loadUsageIndex,\n recordRejection,\n resolveHaivePaths,\n saveUsageIndex,\n serializeMemory,\n} from \"@hiveai/core\";\nimport { loadMemoriesFromDir } from \"../utils/fs.js\";\nimport { ui } from \"../utils/ui.js\";\n\ninterface RejectOptions {\n reason?: string;\n dir?: string;\n}\n\nexport function registerMemoryReject(memory: Command): void {\n memory\n .command(\"reject <id>\")\n .description(\"Record a rejection (blocks auto-promotion and lowers confidence)\")\n .option(\"-r, --reason <reason>\", \"why this memory is being rejected\")\n .option(\"-d, --dir <dir>\", \"project root\")\n .action(async (id: string, opts: RejectOptions) => {\n const root = findProjectRoot(opts.dir);\n const paths = resolveHaivePaths(root);\n if (!existsSync(paths.memoriesDir)) {\n ui.error(`No .ai/memories at ${root}.`);\n process.exitCode = 1;\n return;\n }\n\n const memories = await loadMemoriesFromDir(paths.memoriesDir);\n const loaded = memories.find((m) => m.memory.frontmatter.id === id);\n if (!loaded) {\n ui.error(`No memory with id \"${id}\".`);\n process.exitCode = 1;\n return;\n }\n\n await writeFile(\n loaded.filePath,\n serializeMemory({\n frontmatter: {\n ...loaded.memory.frontmatter,\n status: \"rejected\",\n stale_reason: opts.reason ?? loaded.memory.frontmatter.stale_reason ?? null,\n },\n body: loaded.memory.body,\n }),\n \"utf8\",\n );\n\n const idx = await loadUsageIndex(paths);\n recordRejection(idx, id, opts.reason ?? null);\n await saveUsageIndex(paths, idx);\n const u = idx.by_id[id]!;\n ui.success(\n `Rejected ${id} (status=rejected, ${u.rejected_count} rejection${u.rejected_count === 1 ? \"\" : \"s\"})`,\n );\n if (opts.reason) ui.info(`reason: ${opts.reason}`);\n });\n}\n","import { existsSync } from \"node:fs\";\nimport { unlink } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { createInterface } from \"node:readline/promises\";\nimport { Command } from \"commander\";\nimport {\n findProjectRoot,\n loadUsageIndex,\n resolveHaivePaths,\n saveUsageIndex,\n} from \"@hiveai/core\";\nimport { loadMemoriesFromDir } from \"../utils/fs.js\";\nimport { ui } from \"../utils/ui.js\";\n\ninterface RmOptions {\n yes?: boolean;\n keepUsage?: boolean;\n dir?: string;\n}\n\nexport function registerMemoryRm(memory: Command): void {\n memory\n .command(\"rm <id>\")\n .description(\"Delete a memory file (and its usage entry by default)\")\n .option(\"-y, --yes\", \"skip the confirmation prompt\")\n .option(\"--keep-usage\", \"do not remove the usage.json entry\")\n .option(\"-d, --dir <dir>\", \"project root\")\n .action(async (id: string, opts: RmOptions) => {\n const root = findProjectRoot(opts.dir);\n const paths = resolveHaivePaths(root);\n if (!existsSync(paths.memoriesDir)) {\n ui.error(`No .ai/memories at ${root}.`);\n process.exitCode = 1;\n return;\n }\n\n const all = await loadMemoriesFromDir(paths.memoriesDir);\n const found = all.find((m) => m.memory.frontmatter.id === id);\n if (!found) {\n ui.error(`No memory with id \"${id}\".`);\n process.exitCode = 1;\n return;\n }\n\n const rel = path.relative(root, found.filePath);\n if (!opts.yes) {\n const rl = createInterface({ input: process.stdin, output: process.stdout });\n const answer = (await rl.question(`Delete ${rel}? [y/N] `)).trim().toLowerCase();\n rl.close();\n if (answer !== \"y\" && answer !== \"yes\") {\n ui.info(\"Aborted.\");\n return;\n }\n }\n\n await unlink(found.filePath);\n ui.success(`Deleted ${rel}`);\n\n if (!opts.keepUsage) {\n const idx = await loadUsageIndex(paths);\n if (idx.by_id[id]) {\n delete idx.by_id[id];\n await saveUsageIndex(paths, idx);\n ui.info(\"Removed usage entry\");\n }\n }\n });\n}\n","import { existsSync } from \"node:fs\";\nimport { readFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { Command } from \"commander\";\nimport {\n deriveConfidence,\n findProjectRoot,\n getUsage,\n loadUsageIndex,\n resolveHaivePaths,\n} from \"@hiveai/core\";\nimport { loadMemoriesFromDir } from \"../utils/fs.js\";\nimport { ui } from \"../utils/ui.js\";\n\ninterface ShowOptions {\n raw?: boolean;\n dir?: string;\n}\n\nexport function registerMemoryShow(memory: Command): void {\n memory\n .command(\"show <id>\")\n .description(\"Print a memory's frontmatter, body, and confidence/usage\")\n .option(\"--raw\", \"print the raw file contents instead of a summary\")\n .option(\"-d, --dir <dir>\", \"project root\")\n .action(async (id: string, opts: ShowOptions) => {\n const root = findProjectRoot(opts.dir);\n const paths = resolveHaivePaths(root);\n if (!existsSync(paths.memoriesDir)) {\n ui.error(`No .ai/memories at ${root}.`);\n process.exitCode = 1;\n return;\n }\n\n const all = await loadMemoriesFromDir(paths.memoriesDir);\n const found = all.find((m) => m.memory.frontmatter.id === id);\n if (!found) {\n ui.error(`No memory with id \"${id}\".`);\n process.exitCode = 1;\n return;\n }\n\n if (opts.raw) {\n console.log(await readFile(found.filePath, \"utf8\"));\n return;\n }\n\n const fm = found.memory.frontmatter;\n const usage = await loadUsageIndex(paths);\n const u = getUsage(usage, fm.id);\n const conf = deriveConfidence(fm, u);\n\n console.log(ui.bold(fm.id));\n console.log(`${ui.dim(\"scope:\")} ${fm.scope}${fm.module ? ` / ${fm.module}` : \"\"}`);\n console.log(`${ui.dim(\"type:\")} ${fm.type}`);\n console.log(`${ui.dim(\"status:\")} ${fm.status} ${ui.dim(\"→ confidence:\")} ${ui.bold(conf)}`);\n console.log(`${ui.dim(\"tags:\")} ${fm.tags.length ? fm.tags.join(\", \") : \"(none)\"}`);\n console.log(`${ui.dim(\"created:\")} ${fm.created_at}`);\n if (fm.verified_at) console.log(`${ui.dim(\"verified:\")} ${fm.verified_at}`);\n if (fm.stale_reason) console.log(`${ui.dim(\"stale:\")} ${fm.stale_reason}`);\n console.log(`${ui.dim(\"reads:\")} ${u.read_count} ${ui.dim(\"rejections:\")} ${u.rejected_count}`);\n console.log(`${ui.dim(\"file:\")} ${path.relative(root, found.filePath)}`);\n if (fm.anchor.paths.length || fm.anchor.symbols.length) {\n console.log(ui.dim(\"anchor:\"));\n if (fm.anchor.commit) console.log(` ${ui.dim(\"commit:\")} ${fm.anchor.commit}`);\n if (fm.anchor.paths.length)\n console.log(` ${ui.dim(\"paths:\")} ${fm.anchor.paths.join(\", \")}`);\n if (fm.anchor.symbols.length)\n console.log(` ${ui.dim(\"symbols:\")} ${fm.anchor.symbols.join(\", \")}`);\n }\n console.log();\n console.log(found.memory.body);\n });\n}\n","import { existsSync } from \"node:fs\";\nimport path from \"node:path\";\nimport { Command } from \"commander\";\nimport {\n deriveConfidence,\n findProjectRoot,\n getUsage,\n loadUsageIndex,\n resolveHaivePaths,\n} from \"@hiveai/core\";\nimport { loadMemoriesFromDir } from \"../utils/fs.js\";\nimport { ui } from \"../utils/ui.js\";\n\ninterface StatsOptions {\n id?: string;\n dir?: string;\n}\n\nexport function registerMemoryStats(memory: Command): void {\n memory\n .command(\"stats\")\n .description(\"Show usage stats and confidence levels per memory\")\n .option(\"--id <id>\", \"show stats for a single memory id\")\n .option(\"-d, --dir <dir>\", \"project root\")\n .action(async (opts: StatsOptions) => {\n const root = findProjectRoot(opts.dir);\n const paths = resolveHaivePaths(root);\n if (!existsSync(paths.memoriesDir)) {\n ui.error(`No .ai/memories at ${root}. Run \\`haive init\\` first.`);\n process.exitCode = 1;\n return;\n }\n\n const all = await loadMemoriesFromDir(paths.memoriesDir);\n const usage = await loadUsageIndex(paths);\n const target = opts.id\n ? all.filter((m) => m.memory.frontmatter.id === opts.id)\n : all;\n\n if (target.length === 0) {\n ui.info(opts.id ? `No memory with id \"${opts.id}\".` : \"No memories.\");\n return;\n }\n\n // Sort by read_count desc to surface the popular ones.\n target.sort(\n (a, b) =>\n getUsage(usage, b.memory.frontmatter.id).read_count -\n getUsage(usage, a.memory.frontmatter.id).read_count,\n );\n\n for (const { memory: mem, filePath } of target) {\n const fm = mem.frontmatter;\n const u = getUsage(usage, fm.id);\n const conf = deriveConfidence(fm, u);\n console.log(\n `${ui.bold(fm.id)} ${ui.dim(`${fm.scope}/${fm.type}`)} ${ui.bold(conf)}`,\n );\n console.log(\n ` ${ui.dim(\"status:\")} ${fm.status} ${ui.dim(\"reads:\")} ${u.read_count} ${ui.dim(\"rejections:\")} ${u.rejected_count}`,\n );\n console.log(` ${ui.dim(path.relative(root, filePath))}`);\n }\n });\n}\n","import { writeFile } from \"node:fs/promises\";\nimport { existsSync } from \"node:fs\";\nimport path from \"node:path\";\nimport { Command } from \"commander\";\nimport {\n findProjectRoot,\n resolveHaivePaths,\n serializeMemory,\n verifyAnchor,\n} from \"@hiveai/core\";\nimport { loadMemoriesFromDir } from \"../utils/fs.js\";\nimport { ui } from \"../utils/ui.js\";\n\ninterface VerifyOptions {\n id?: string;\n all?: boolean;\n update?: boolean;\n dir?: string;\n}\n\nexport function registerMemoryVerify(memory: Command): void {\n memory\n .command(\"verify\")\n .description(\"Check memory anchors against current code, optionally marking stale ones\")\n .option(\"--id <id>\", \"verify a single memory by id\")\n .option(\"--all\", \"verify every memory (default if --id is omitted)\")\n .option(\"--update\", \"write status=stale (or status=validated for re-freshed) back to disk\")\n .option(\"-d, --dir <dir>\", \"project root\")\n .action(async (opts: VerifyOptions) => {\n const root = findProjectRoot(opts.dir);\n const paths = resolveHaivePaths(root);\n if (!existsSync(paths.memoriesDir)) {\n ui.error(`No .ai/memories at ${root}. Run \\`haive init\\` first.`);\n process.exitCode = 1;\n return;\n }\n\n const all = await loadMemoriesFromDir(paths.memoriesDir);\n const targets = opts.id\n ? all.filter((m) => m.memory.frontmatter.id === opts.id)\n : all;\n\n if (opts.id && targets.length === 0) {\n ui.error(`No memory with id \"${opts.id}\".`);\n process.exitCode = 1;\n return;\n }\n\n let staleCount = 0;\n let freshCount = 0;\n const anchorlessIds: string[] = [];\n let updated = 0;\n\n for (const { memory: mem, filePath } of targets) {\n const result = await verifyAnchor(mem, { projectRoot: root });\n const isAnchored =\n mem.frontmatter.anchor.paths.length > 0 ||\n mem.frontmatter.anchor.symbols.length > 0;\n\n if (!isAnchored) {\n anchorlessIds.push(mem.frontmatter.id);\n continue;\n }\n\n const rel = path.relative(root, filePath);\n if (result.stale) {\n staleCount++;\n console.log(`${ui.bold(\"STALE\")} ${mem.frontmatter.id}`);\n console.log(` ${ui.dim(rel)}`);\n console.log(` ${result.reason}`);\n if (result.possibleRenames.length > 0) {\n console.log(` ${ui.yellow(\"Possible renames:\")} ${result.possibleRenames.join(\", \")}`);\n }\n } else {\n freshCount++;\n console.log(`${ui.dim(\"fresh\")} ${mem.frontmatter.id}`);\n }\n\n if (opts.update) {\n const next = applyVerification(mem, result);\n await writeFile(filePath, serializeMemory(next), \"utf8\");\n updated++;\n }\n }\n\n const summary = [\n `${freshCount} fresh`,\n `${staleCount} stale`,\n `${anchorlessIds.length} anchorless (skipped)`,\n ];\n if (opts.update) summary.push(`${updated} updated on disk`);\n ui.info(summary.join(\" · \"));\n if (anchorlessIds.length > 0) {\n console.log(\n ui.dim(\n `Anchorless memories (no paths/symbols — staleness cannot be detected):\\n` +\n anchorlessIds.map((id) => ` ${id}`).join(\"\\n\") +\n `\\nTip: use \\`haive memory update <id> --paths <files>\\` to add anchors.`,\n ),\n );\n }\n });\n}\n\nfunction applyVerification(\n mem: Parameters<typeof serializeMemory>[0],\n result: { stale: boolean; reason: string | null },\n): Parameters<typeof serializeMemory>[0] {\n const verifiedAt = new Date().toISOString();\n if (result.stale) {\n return {\n frontmatter: {\n ...mem.frontmatter,\n status: \"stale\",\n verified_at: verifiedAt,\n stale_reason: result.reason,\n },\n body: mem.body,\n };\n }\n // Reset stale_reason when re-validating; keep validated/proposed status as is,\n // promote draft→validated when verification passes.\n const nextStatus =\n mem.frontmatter.status === \"stale\" || mem.frontmatter.status === \"draft\"\n ? \"validated\"\n : mem.frontmatter.status;\n return {\n frontmatter: {\n ...mem.frontmatter,\n status: nextStatus,\n verified_at: verifiedAt,\n stale_reason: null,\n },\n body: mem.body,\n };\n}\n","import { readFile } from \"node:fs/promises\";\nimport { existsSync } from \"node:fs\";\nimport { Command } from \"commander\";\nimport {\n findProjectRoot,\n resolveHaivePaths,\n} from \"@hiveai/core\";\nimport { ui } from \"../utils/ui.js\";\n\ninterface ImportOptions {\n from: string;\n scope?: \"personal\" | \"team\";\n dir?: string;\n}\n\nexport function registerMemoryImport(memory: Command): void {\n memory\n .command(\"import\")\n .description(\n \"Parse a Markdown file and suggest memories via the import_docs MCP prompt (prints a ready-to-use prompt invocation)\",\n )\n .requiredOption(\"--from <file>\", \"Markdown/text file to import from\")\n .option(\"--scope <scope>\", \"personal | team (default: team)\", \"team\")\n .option(\"-d, --dir <dir>\", \"project root\")\n .action(async (opts: ImportOptions) => {\n const root = findProjectRoot(opts.dir);\n const paths = resolveHaivePaths(root);\n\n if (!existsSync(paths.haiveDir)) {\n ui.error(`No .ai/ found at ${root}. Run \\`haive init\\` first.`);\n process.exitCode = 1;\n return;\n }\n\n if (!existsSync(opts.from)) {\n ui.error(`File not found: ${opts.from}`);\n process.exitCode = 1;\n return;\n }\n\n const content = await readFile(opts.from, \"utf8\");\n const scope = opts.scope ?? \"team\";\n\n ui.info(`Preparing import from: ${opts.from} (scope=${scope})`);\n ui.info(`Content length: ${content.length} chars`);\n console.log();\n console.log(ui.bold(\"To import via MCP, invoke the `import_docs` prompt with:\"));\n console.log();\n console.log(\n ui.dim(\n JSON.stringify(\n {\n content: content.slice(0, 200) + (content.length > 200 ? \"…\" : \"\"),\n source: opts.from,\n scope,\n },\n null,\n 2,\n ),\n ),\n );\n console.log();\n ui.info(\n \"Or use your AI client to call: import_docs({ content: <file contents>, source: \\\"\" +\n opts.from +\n \"\\\", scope: \\\"\" +\n scope +\n \"\\\" })\",\n );\n });\n}\n"],"mappings":";;;AAAA,SAAS,WAAAA,iBAAe;;;ACAxB,SAAS,kBAAkB;AAC3B,SAAS,gBAAgB;AACzB,OAAwB;AACxB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;;;ACXP,OAAO,QAAQ;AAER,IAAM,KAAK;AAAA,EAChB,MAAM,CAAC,QAAgB,QAAQ,IAAI,GAAG,KAAK,QAAG,GAAG,GAAG;AAAA,EACpD,SAAS,CAAC,QAAgB,QAAQ,IAAI,GAAG,MAAM,QAAG,GAAG,GAAG;AAAA,EACxD,MAAM,CAAC,QAAgB,QAAQ,IAAI,GAAG,OAAO,QAAG,GAAG,GAAG;AAAA,EACtD,OAAO,CAAC,QAAgB,QAAQ,MAAM,GAAG,IAAI,QAAG,GAAG,GAAG;AAAA,EACtD,KAAK,CAAC,QAAgB,GAAG,IAAI,GAAG;AAAA,EAChC,MAAM,CAAC,QAAgB,GAAG,KAAK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AAO,EACZ,YAAY,sEAAiE,EAC7E,QAAQ,QAAiB;AAE5B,aAAa,OAAO;AACpB,YAAY,OAAO;AACnB,iBAAiB,OAAO;AACxB,YAAY,OAAO;AACnB,mBAAmB,OAAO;AAC1B,aAAa,OAAO;AACpB,qBAAqB,OAAO;AAC5B,kBAAkB,OAAO;AAEzB,IAAM,SAAS,QAAQ,QAAQ,QAAQ,EAAE,YAAY,uBAAuB;AAC5E,kBAAkB,MAAM;AACxB,mBAAmB,MAAM;AACzB,oBAAoB,MAAM;AAC1B,sBAAsB,MAAM;AAC5B,qBAAqB,MAAM;AAC3B,oBAAoB,MAAM;AAC1B,qBAAqB,MAAM;AAC3B,0BAA0B,MAAM;AAChC,uBAAuB,MAAM;AAC7B,mBAAmB,MAAM;AACzB,mBAAmB,MAAM;AACzB,iBAAiB,MAAM;AACvB,sBAAsB,MAAM;AAC5B,sBAAsB,MAAM;AAC5B,qBAAqB,MAAM;AAC3B,kBAAkB,MAAM;AACxB,oBAAoB,MAAM;AAC1B,qBAAqB,MAAM;AAE3B,QAAQ,WAAW,QAAQ,IAAI,EAAE,MAAM,CAAC,QAAiB;AACvD,MAAI,WAAW,GAAG,GAAG;AACnB,eAAW,SAAS,IAAI,QAAQ;AAC9B,YAAM,QAAQ,MAAM,KAAK,SAAS,IAAI,GAAG,OAAO,MAAM,KAAK,KAAK,GAAG,CAAC,CAAC,OAAO;AAC5E,cAAQ,MAAM,yBAAoB,KAAK,GAAG,MAAM,OAAO,EAAE;AAAA,IAC3D;AAAA,EACF,OAAO;AACL,YAAQ,MAAM,eAAe,QAAQ,IAAI,UAAU,GAAG;AAAA,EACxD;AACA,UAAQ,KAAK,CAAC;AAChB,CAAC;AAED,SAAS,WACP,KACgE;AAChE,SACE,QAAQ,QACR,OAAO,QAAQ,YACf,YAAY,OACZ,MAAM,QAAS,IAAgC,MAAM;AAEzD;","names":["Command","program","findProjectRoot","program","existsSync","findProjectRoot","resolveHaivePaths","program","findProjectRoot","resolveHaivePaths","existsSync","path","findProjectRoot","resolveHaivePaths","program","findProjectRoot","resolveHaivePaths","path","existsSync","path","resolveHaivePaths","program","path","resolveHaivePaths","existsSync","mkdir","writeFile","readFile","existsSync","path","findProjectRoot","program","findProjectRoot","path","existsSync","mkdir","readFile","writeFile","existsSync","path","findProjectRoot","require","program","findProjectRoot","path","existsSync","readFile","writeFile","existsSync","path","findProjectRoot","loadMemoriesFromDir","resolveHaivePaths","program","findProjectRoot","resolveHaivePaths","existsSync","loadMemoriesFromDir","memory","writeFile","path","readFile","mkdir","readFile","writeFile","existsSync","path","findProjectRoot","loadMemoriesFromDir","resolveHaivePaths","serializeMemory","memory","findProjectRoot","resolveHaivePaths","existsSync","parseCsv","readFile","mkdir","path","loadMemoriesFromDir","writeFile","serializeMemory","existsSync","path","findProjectRoot","resolveHaivePaths","loadMemoriesFromDir","memory","findProjectRoot","resolveHaivePaths","existsSync","loadMemoriesFromDir","path","mkdir","writeFile","existsSync","path","findProjectRoot","memoryFilePath","resolveHaivePaths","serializeMemory","memory","findProjectRoot","resolveHaivePaths","existsSync","loadMemoriesFromDir","memoryFilePath","mkdir","path","writeFile","serializeMemory","existsSync","writeFile","path","findProjectRoot","resolveHaivePaths","serializeMemory","memory","findProjectRoot","resolveHaivePaths","existsSync","loadMemoriesFromDir","found","next","writeFile","serializeMemory","path","writeFile","existsSync","path","findProjectRoot","resolveHaivePaths","serializeMemory","memory","findProjectRoot","resolveHaivePaths","existsSync","loadMemoriesFromDir","parseCsv","writeFile","serializeMemory","path","writeFile","existsSync","path","DEFAULT_AUTO_PROMOTE_RULE","findProjectRoot","getUsage","isAutoPromoteEligible","loadUsageIndex","resolveHaivePaths","serializeMemory","memory","DEFAULT_AUTO_PROMOTE_RULE","findProjectRoot","resolveHaivePaths","existsSync","loadMemoriesFromDir","loadUsageIndex","isAutoPromoteEligible","getUsage","path","writeFile","serializeMemory","spawn","existsSync","readFile","path","findProjectRoot","resolveHaivePaths","memory","findProjectRoot","resolveHaivePaths","existsSync","loadMemoriesFromDir","path","readFile","spawn","existsSync","path","findProjectRoot","getUsage","inferModulesFromPaths","loadUsageIndex","memoryMatchesAnchorPaths","resolveHaivePaths","memory","findProjectRoot","resolveHaivePaths","existsSync","loadMemoriesFromDir","loadUsageIndex","inferModulesFromPaths","memoryMatchesAnchorPaths","getUsage","path","existsSync","path","findProjectRoot","getUsage","loadUsageIndex","resolveHaivePaths","memory","findProjectRoot","resolveHaivePaths","existsSync","loadMemoriesFromDir","loadUsageIndex","getUsage","path","mkdir","writeFile","existsSync","path","buildFrontmatter","findProjectRoot","memoryFilePath","resolveHaivePaths","serializeMemory","memory","findProjectRoot","resolveHaivePaths","existsSync","buildFrontmatter","parseCsv","memoryFilePath","mkdir","path","writeFile","serializeMemory","existsSync","path","findProjectRoot","getUsage","loadUsageIndex","resolveHaivePaths","memory","findProjectRoot","resolveHaivePaths","existsSync","loadMemoriesFromDir","loadUsageIndex","getUsage","path","existsSync","path","findProjectRoot","literalMatchesAllTokens","resolveHaivePaths","tokenizeQuery","trackReads","memory","findProjectRoot","resolveHaivePaths","existsSync","tokenizeQuery","loadMemoriesFromDir","literalMatchesAllTokens","path","trackReads","writeFile","existsSync","findProjectRoot","loadUsageIndex","resolveHaivePaths","serializeMemory","memory","findProjectRoot","resolveHaivePaths","existsSync","loadMemoriesFromDir","writeFile","serializeMemory","loadUsageIndex","existsSync","unlink","path","findProjectRoot","loadUsageIndex","resolveHaivePaths","saveUsageIndex","memory","findProjectRoot","resolveHaivePaths","existsSync","loadMemoriesFromDir","path","unlink","loadUsageIndex","saveUsageIndex","existsSync","readFile","path","deriveConfidence","findProjectRoot","getUsage","loadUsageIndex","resolveHaivePaths","memory","findProjectRoot","resolveHaivePaths","existsSync","loadMemoriesFromDir","readFile","loadUsageIndex","getUsage","deriveConfidence","path","existsSync","path","deriveConfidence","findProjectRoot","getUsage","loadUsageIndex","resolveHaivePaths","memory","findProjectRoot","resolveHaivePaths","existsSync","loadMemoriesFromDir","loadUsageIndex","getUsage","deriveConfidence","path","writeFile","existsSync","path","findProjectRoot","resolveHaivePaths","serializeMemory","verifyAnchor","memory","findProjectRoot","resolveHaivePaths","existsSync","loadMemoriesFromDir","verifyAnchor","path","writeFile","serializeMemory","readFile","existsSync","findProjectRoot","resolveHaivePaths","memory","findProjectRoot","resolveHaivePaths","existsSync","readFile","Command"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hiveai/cli",
3
- "version": "0.2.10",
3
+ "version": "0.2.11",
4
4
  "description": "hAIve CLI — manage shared AI memories from the terminal",
5
5
  "license": "MIT",
6
6
  "repository": {