@hiveai/core 0.1.0 → 0.2.0

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.d.ts CHANGED
@@ -246,4 +246,86 @@ declare function pathsOverlap(a: string, b: string): boolean;
246
246
  declare function memoryMatchesAnchorPaths(memory: LoadedMemory["memory"], inputPaths: string[]): boolean;
247
247
  declare function relPathFrom(root: string, abs: string): string;
248
248
 
249
- export { type Anchor, AnchorSchema, type AutoPromoteRule, type ConfidenceLevel, type ConfidenceThresholds, DEFAULT_AUTO_PROMOTE_RULE, DEFAULT_CONFIDENCE_THRESHOLDS, HAIVE_DIR, type HaivePaths, type LoadedMemory, MEMORIES_DIR, type Memory, type MemoryFrontmatter, MemoryFrontmatterSchema, type MemoryScope, MemoryScopeSchema, type MemoryStatus, MemoryStatusSchema, type MemoryType, MemoryTypeSchema, type MemoryUsage, PROJECT_CONTEXT_FILE, USAGE_FILE, type UsageIndex, type VerifyOptions, type VerifyResult, buildFrontmatter, bumpRead, deriveConfidence, emptyUsage, emptyUsageIndex, extractSnippet, findProjectRoot, getUsage, inferModulesFromPaths, isAutoPromoteEligible, listMarkdownFilesRecursive, literalMatchesAllTokens, loadMemoriesFromDir, loadMemory, loadUsageIndex, memoryFilePath, memoryMatchesAnchorPaths, newMemoryId, parseMemory, pathsOverlap, pickSnippetNeedle, recordRejection, relPathFrom, resolveHaivePaths, saveUsageIndex, serializeMemory, stripPrivate, tokenizeQuery, trackReads, usagePath, verifyAnchor };
249
+ /**
250
+ * Token budgeting helpers. We use the standard heuristic of ~4 chars per token,
251
+ * which is conservative for English/code/markdown. Callers that need exact
252
+ * counts should plug in a real tokenizer; this module only ever over-estimates,
253
+ * so the user's hard limits are respected.
254
+ */
255
+ declare const CHARS_PER_TOKEN = 4;
256
+ declare function estimateTokens(text: string): number;
257
+ interface TruncateOptions {
258
+ /** Maximum tokens allowed in the result (inclusive). */
259
+ maxTokens: number;
260
+ /** Marker inserted where content was dropped. */
261
+ marker?: string;
262
+ /** Where to keep characters from when truncating. Default: head. */
263
+ mode?: "head" | "tail" | "middle";
264
+ }
265
+ interface TruncateResult {
266
+ text: string;
267
+ truncated: boolean;
268
+ estimatedTokens: number;
269
+ originalTokens: number;
270
+ }
271
+ declare function truncateToTokens(input: string, options: TruncateOptions): TruncateResult;
272
+ /**
273
+ * Allocate a global token budget across N parts with relative weights, then
274
+ * truncate each part to its share. Returns parts in input order, paired with
275
+ * truncate metadata.
276
+ */
277
+ interface BudgetPart {
278
+ key: string;
279
+ text: string;
280
+ weight: number;
281
+ mode?: TruncateOptions["mode"];
282
+ }
283
+ interface BudgetSlice {
284
+ key: string;
285
+ text: string;
286
+ truncated: boolean;
287
+ estimatedTokens: number;
288
+ originalTokens: number;
289
+ allocatedTokens: number;
290
+ }
291
+ declare function allocateBudget(parts: BudgetPart[], maxTokens: number): BudgetSlice[];
292
+
293
+ declare const CODE_MAP_FILE = "code-map.json";
294
+ type CodeExportKind = "function" | "class" | "interface" | "type" | "const" | "enum" | "default";
295
+ interface CodeExport {
296
+ name: string;
297
+ kind: CodeExportKind;
298
+ description?: string;
299
+ line: number;
300
+ }
301
+ interface CodeFileEntry {
302
+ summary?: string;
303
+ exports: CodeExport[];
304
+ loc: number;
305
+ }
306
+ interface CodeMap {
307
+ version: 1;
308
+ generated_at: string;
309
+ root: string;
310
+ files: Record<string, CodeFileEntry>;
311
+ }
312
+ interface BuildCodeMapOptions {
313
+ includeExtensions?: string[];
314
+ excludeDirs?: string[];
315
+ }
316
+ declare function codeMapPath(paths: HaivePaths): string;
317
+ declare function loadCodeMap(paths: HaivePaths): Promise<CodeMap | null>;
318
+ declare function saveCodeMap(paths: HaivePaths, map: CodeMap): Promise<void>;
319
+ declare function buildCodeMap(root: string, options?: BuildCodeMapOptions): Promise<CodeMap>;
320
+ interface CodeMapQueryOptions {
321
+ file?: string;
322
+ symbol?: string;
323
+ }
324
+ declare function queryCodeMap(map: CodeMap, options: CodeMapQueryOptions): {
325
+ files: Array<{
326
+ path: string;
327
+ entry: CodeFileEntry;
328
+ }>;
329
+ };
330
+
331
+ export { type Anchor, AnchorSchema, type AutoPromoteRule, type BudgetPart, type BudgetSlice, type BuildCodeMapOptions, CHARS_PER_TOKEN, CODE_MAP_FILE, type CodeExport, type CodeExportKind, type CodeFileEntry, type CodeMap, type CodeMapQueryOptions, type ConfidenceLevel, type ConfidenceThresholds, DEFAULT_AUTO_PROMOTE_RULE, DEFAULT_CONFIDENCE_THRESHOLDS, HAIVE_DIR, type HaivePaths, type LoadedMemory, MEMORIES_DIR, type Memory, type MemoryFrontmatter, MemoryFrontmatterSchema, type MemoryScope, MemoryScopeSchema, type MemoryStatus, MemoryStatusSchema, type MemoryType, MemoryTypeSchema, type MemoryUsage, PROJECT_CONTEXT_FILE, type TruncateOptions, type TruncateResult, USAGE_FILE, type UsageIndex, type VerifyOptions, type VerifyResult, allocateBudget, buildCodeMap, buildFrontmatter, bumpRead, codeMapPath, deriveConfidence, emptyUsage, emptyUsageIndex, estimateTokens, extractSnippet, findProjectRoot, getUsage, inferModulesFromPaths, isAutoPromoteEligible, listMarkdownFilesRecursive, literalMatchesAllTokens, loadCodeMap, loadMemoriesFromDir, loadMemory, loadUsageIndex, memoryFilePath, memoryMatchesAnchorPaths, newMemoryId, parseMemory, pathsOverlap, pickSnippetNeedle, queryCodeMap, recordRejection, relPathFrom, resolveHaivePaths, saveCodeMap, saveUsageIndex, serializeMemory, stripPrivate, tokenizeQuery, trackReads, truncateToTokens, usagePath, verifyAnchor };
package/dist/index.js CHANGED
@@ -183,11 +183,30 @@ function literalMatchesAllTokens(memory, tokens) {
183
183
  const idLower = fm.id.toLowerCase();
184
184
  const tagsLower = fm.tags.map((t) => t.toLowerCase());
185
185
  const bodyLower = memory.body.toLowerCase();
186
+ const anchorPathTokens = collectAnchorPathTokens(fm.anchor.paths);
187
+ const anchorSymbolsLower = fm.anchor.symbols.map((s) => s.toLowerCase());
188
+ const moduleLower = fm.module?.toLowerCase();
189
+ const domainLower = fm.domain?.toLowerCase();
186
190
  return tokens.every((rawTok) => {
187
191
  const tok = rawTok.toLowerCase();
188
- return idLower.includes(tok) || tagsLower.some((t) => t.includes(tok)) || bodyLower.includes(tok);
192
+ return idLower.includes(tok) || tagsLower.some((t) => t.includes(tok)) || bodyLower.includes(tok) || anchorPathTokens.some((p) => p.includes(tok)) || anchorSymbolsLower.some((s) => s.includes(tok)) || moduleLower !== void 0 && moduleLower.includes(tok) || domainLower !== void 0 && domainLower.includes(tok);
189
193
  });
190
194
  }
195
+ function collectAnchorPathTokens(paths) {
196
+ const out = /* @__PURE__ */ new Set();
197
+ for (const p of paths) {
198
+ const lower = p.toLowerCase();
199
+ out.add(lower);
200
+ const base = lower.split("/").pop() ?? lower;
201
+ const noExt = base.replace(/\.[a-z0-9]+$/, "");
202
+ if (noExt) out.add(noExt);
203
+ for (const segment of lower.split("/")) {
204
+ const seg = segment.replace(/\.[a-z0-9]+$/, "");
205
+ if (seg) out.add(seg);
206
+ }
207
+ }
208
+ return [...out];
209
+ }
191
210
  function pickSnippetNeedle(query) {
192
211
  const tokens = tokenizeQuery(query);
193
212
  if (tokens.length === 0) return query.toLowerCase();
@@ -415,8 +434,282 @@ function normalize(p) {
415
434
  function relPathFrom(root, abs) {
416
435
  return path5.relative(root, abs).replace(/\\/g, "/");
417
436
  }
437
+
438
+ // src/token-budget.ts
439
+ var CHARS_PER_TOKEN = 4;
440
+ function estimateTokens(text) {
441
+ return Math.ceil(text.length / CHARS_PER_TOKEN);
442
+ }
443
+ var DEFAULT_MARKER = "\n\u2026[truncated]\u2026\n";
444
+ function truncateToTokens(input, options) {
445
+ const originalTokens = estimateTokens(input);
446
+ const max = Math.max(0, options.maxTokens);
447
+ if (originalTokens <= max) {
448
+ return { text: input, truncated: false, estimatedTokens: originalTokens, originalTokens };
449
+ }
450
+ if (max === 0) {
451
+ return { text: "", truncated: true, estimatedTokens: 0, originalTokens };
452
+ }
453
+ const marker = options.marker ?? DEFAULT_MARKER;
454
+ const mode = options.mode ?? "head";
455
+ const markerTokens = estimateTokens(marker);
456
+ const budgetChars = Math.max(0, (max - markerTokens) * CHARS_PER_TOKEN);
457
+ let result;
458
+ if (budgetChars === 0) {
459
+ result = "";
460
+ } else if (mode === "tail") {
461
+ result = marker + input.slice(input.length - budgetChars);
462
+ } else if (mode === "middle") {
463
+ const half = Math.floor(budgetChars / 2);
464
+ result = input.slice(0, half) + marker + input.slice(input.length - half);
465
+ } else {
466
+ result = input.slice(0, budgetChars) + marker;
467
+ }
468
+ return {
469
+ text: result,
470
+ truncated: true,
471
+ estimatedTokens: estimateTokens(result),
472
+ originalTokens
473
+ };
474
+ }
475
+ function allocateBudget(parts, maxTokens) {
476
+ if (parts.length === 0) return [];
477
+ const totalWeight = parts.reduce((s, p) => s + Math.max(0, p.weight), 0);
478
+ if (totalWeight === 0) {
479
+ return parts.map((p) => ({
480
+ key: p.key,
481
+ text: "",
482
+ truncated: estimateTokens(p.text) > 0,
483
+ estimatedTokens: 0,
484
+ originalTokens: estimateTokens(p.text),
485
+ allocatedTokens: 0
486
+ }));
487
+ }
488
+ const allocations = /* @__PURE__ */ new Map();
489
+ let remaining = maxTokens;
490
+ let remainingWeight = totalWeight;
491
+ const sortedByFit = [...parts].map((p) => ({
492
+ key: p.key,
493
+ tokens: estimateTokens(p.text),
494
+ share: p.weight / totalWeight * maxTokens,
495
+ part: p
496
+ })).sort((a, b) => a.tokens - b.tokens);
497
+ for (const item of sortedByFit) {
498
+ const myShare = remainingWeight > 0 ? item.part.weight / remainingWeight * remaining : 0;
499
+ const grant = Math.min(item.tokens, Math.floor(myShare));
500
+ allocations.set(item.key, grant);
501
+ remaining -= grant;
502
+ remainingWeight -= item.part.weight;
503
+ }
504
+ return parts.map((p) => {
505
+ const allocated = allocations.get(p.key) ?? 0;
506
+ const truncated = truncateToTokens(p.text, {
507
+ maxTokens: allocated,
508
+ mode: p.mode ?? "head"
509
+ });
510
+ return {
511
+ key: p.key,
512
+ text: truncated.text,
513
+ truncated: truncated.truncated,
514
+ estimatedTokens: truncated.estimatedTokens,
515
+ originalTokens: truncated.originalTokens,
516
+ allocatedTokens: allocated
517
+ };
518
+ });
519
+ }
520
+
521
+ // src/code-map.ts
522
+ import { mkdir as mkdir2, readFile as readFile4, readdir as readdir2, writeFile as writeFile2 } from "fs/promises";
523
+ import { existsSync as existsSync4 } from "fs";
524
+ import path6 from "path";
525
+ var CODE_MAP_FILE = "code-map.json";
526
+ var DEFAULT_INCLUDE = [".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs"];
527
+ var DEFAULT_EXCLUDE = [
528
+ "node_modules",
529
+ "dist",
530
+ "build",
531
+ "out",
532
+ ".git",
533
+ ".next",
534
+ ".turbo",
535
+ ".vitest-cache",
536
+ "coverage"
537
+ ];
538
+ function codeMapPath(paths) {
539
+ return path6.join(paths.haiveDir, CODE_MAP_FILE);
540
+ }
541
+ async function loadCodeMap(paths) {
542
+ const file = codeMapPath(paths);
543
+ if (!existsSync4(file)) return null;
544
+ return JSON.parse(await readFile4(file, "utf8"));
545
+ }
546
+ async function saveCodeMap(paths, map) {
547
+ const file = codeMapPath(paths);
548
+ await mkdir2(path6.dirname(file), { recursive: true });
549
+ await writeFile2(file, JSON.stringify(map, null, 2), "utf8");
550
+ }
551
+ async function buildCodeMap(root, options = {}) {
552
+ const include = new Set(options.includeExtensions ?? DEFAULT_INCLUDE);
553
+ const exclude = new Set(options.excludeDirs ?? DEFAULT_EXCLUDE);
554
+ const files = {};
555
+ for await (const abs of walkSourceFiles(root, include, exclude)) {
556
+ const rel = path6.relative(root, abs).replace(/\\/g, "/");
557
+ if (rel.startsWith(".ai/")) continue;
558
+ const content = await readFile4(abs, "utf8");
559
+ const entry = parseFile(content);
560
+ if (entry.exports.length > 0) files[rel] = entry;
561
+ }
562
+ return {
563
+ version: 1,
564
+ generated_at: (/* @__PURE__ */ new Date()).toISOString(),
565
+ root,
566
+ files
567
+ };
568
+ }
569
+ async function* walkSourceFiles(dir, include, exclude) {
570
+ let entries;
571
+ try {
572
+ entries = await readdir2(dir, { withFileTypes: true });
573
+ } catch {
574
+ return;
575
+ }
576
+ for (const entry of entries) {
577
+ if (entry.name.startsWith(".") && entry.name !== ".github") {
578
+ if (entry.isDirectory()) continue;
579
+ }
580
+ if (exclude.has(entry.name)) continue;
581
+ const full = path6.join(dir, entry.name);
582
+ if (entry.isDirectory()) {
583
+ yield* walkSourceFiles(full, include, exclude);
584
+ } else if (entry.isFile()) {
585
+ const ext = path6.extname(entry.name).toLowerCase();
586
+ if (include.has(ext)) yield full;
587
+ }
588
+ }
589
+ }
590
+ var EXPORT_RE = /^export\s+(?:default\s+)?(async\s+)?(function|class|interface|type|const|let|var|enum)\s+(\*?)\s*([A-Za-z_$][\w$]*)/gm;
591
+ var NAMED_REEXPORT_RE = /^export\s*\{([^}]+)\}/gm;
592
+ var FILE_HEADER_COMMENT_RE = /^\/\*\*([\s\S]*?)\*\//;
593
+ function parseFile(source) {
594
+ const exports = [];
595
+ const lines = source.split("\n");
596
+ const lineOffsets = computeLineOffsets(source);
597
+ let m;
598
+ EXPORT_RE.lastIndex = 0;
599
+ while (m = EXPORT_RE.exec(source)) {
600
+ const kindRaw = m[2] ?? "";
601
+ const name = m[4] ?? "";
602
+ if (!name) continue;
603
+ const kind = kindRaw === "function" ? "function" : kindRaw === "class" ? "class" : kindRaw === "interface" ? "interface" : kindRaw === "type" ? "type" : kindRaw === "enum" ? "enum" : "const";
604
+ const lineIdx = byteToLine(m.index, lineOffsets);
605
+ const description = extractJSDocAbove(lines, lineIdx);
606
+ exports.push({
607
+ name,
608
+ kind,
609
+ ...description ? { description } : {},
610
+ line: lineIdx + 1
611
+ });
612
+ }
613
+ NAMED_REEXPORT_RE.lastIndex = 0;
614
+ while (m = NAMED_REEXPORT_RE.exec(source)) {
615
+ const inside = m[1] ?? "";
616
+ const lineIdx = byteToLine(m.index, lineOffsets);
617
+ for (const part of inside.split(",")) {
618
+ const cleaned = part.trim().split(/\s+as\s+/).pop()?.trim() ?? "";
619
+ if (!cleaned || cleaned.startsWith("type ")) continue;
620
+ if (exports.some((e) => e.name === cleaned)) continue;
621
+ exports.push({ name: cleaned, kind: "const", line: lineIdx + 1 });
622
+ }
623
+ }
624
+ const summary = extractFileSummary(source);
625
+ return {
626
+ ...summary ? { summary } : {},
627
+ exports,
628
+ loc: lines.length
629
+ };
630
+ }
631
+ function computeLineOffsets(source) {
632
+ const out = [0];
633
+ for (let i = 0; i < source.length; i++) {
634
+ if (source[i] === "\n") out.push(i + 1);
635
+ }
636
+ return out;
637
+ }
638
+ function byteToLine(byte, offsets) {
639
+ let lo = 0;
640
+ let hi = offsets.length - 1;
641
+ while (lo < hi) {
642
+ const mid = lo + hi + 1 >> 1;
643
+ const off = offsets[mid] ?? 0;
644
+ if (off <= byte) lo = mid;
645
+ else hi = mid - 1;
646
+ }
647
+ return lo;
648
+ }
649
+ function extractJSDocAbove(lines, exportLine) {
650
+ let i = exportLine - 1;
651
+ while (i >= 0 && (lines[i] ?? "").trim() === "") i--;
652
+ if (i < 0) return void 0;
653
+ const line = (lines[i] ?? "").trim();
654
+ if (line.startsWith("//")) {
655
+ return line.replace(/^\/\/\s*/, "").trim() || void 0;
656
+ }
657
+ const singleLine = line.match(/^\/\*\*\s*(.*?)\s*\*\/\s*$/);
658
+ if (singleLine && singleLine[1]) {
659
+ return firstSentence(singleLine[1]);
660
+ }
661
+ if (line.endsWith("*/")) {
662
+ const collected = [];
663
+ const firstPiece = line.replace(/\*\/\s*$/, "").replace(/^\*\s?/, "").trim();
664
+ if (firstPiece) collected.unshift(firstPiece);
665
+ let j = i - 1;
666
+ while (j >= 0) {
667
+ const l = (lines[j] ?? "").trim();
668
+ if (l.startsWith("/**")) {
669
+ const inner = l.replace(/^\/\*\*/, "").trim();
670
+ if (inner) collected.unshift(inner);
671
+ break;
672
+ }
673
+ collected.unshift(l.replace(/^\*\s?/, "").trim());
674
+ j--;
675
+ }
676
+ const joined = collected.join(" ").trim();
677
+ if (!joined) return void 0;
678
+ return firstSentence(joined);
679
+ }
680
+ return void 0;
681
+ }
682
+ function firstSentence(text) {
683
+ const trimmed = text.trim();
684
+ if (!trimmed) return void 0;
685
+ return trimmed.split(/(?<=\.)\s+/)[0]?.trim();
686
+ }
687
+ function extractFileSummary(source) {
688
+ const m = source.match(FILE_HEADER_COMMENT_RE);
689
+ if (!m) return void 0;
690
+ const block = (m[1] ?? "").split("\n").map((l) => l.replace(/^\s*\*\s?/, "").trim()).filter(Boolean).join(" ");
691
+ if (!block) return void 0;
692
+ const sentence = block.split(/(?<=\.)\s+/)[0]?.trim();
693
+ return sentence;
694
+ }
695
+ function queryCodeMap(map, options) {
696
+ const files = [];
697
+ for (const [filePath, entry] of Object.entries(map.files)) {
698
+ if (options.file) {
699
+ if (!filePath.includes(options.file)) continue;
700
+ }
701
+ if (options.symbol) {
702
+ const sym = options.symbol.toLowerCase();
703
+ if (!entry.exports.some((e) => e.name.toLowerCase().includes(sym))) continue;
704
+ }
705
+ files.push({ path: filePath, entry });
706
+ }
707
+ return { files };
708
+ }
418
709
  export {
419
710
  AnchorSchema,
711
+ CHARS_PER_TOKEN,
712
+ CODE_MAP_FILE,
420
713
  DEFAULT_AUTO_PROMOTE_RULE,
421
714
  DEFAULT_CONFIDENCE_THRESHOLDS,
422
715
  HAIVE_DIR,
@@ -427,11 +720,15 @@ export {
427
720
  MemoryTypeSchema,
428
721
  PROJECT_CONTEXT_FILE,
429
722
  USAGE_FILE,
723
+ allocateBudget,
724
+ buildCodeMap,
430
725
  buildFrontmatter,
431
726
  bumpRead,
727
+ codeMapPath,
432
728
  deriveConfidence,
433
729
  emptyUsage,
434
730
  emptyUsageIndex,
731
+ estimateTokens,
435
732
  extractSnippet,
436
733
  findProjectRoot,
437
734
  getUsage,
@@ -439,6 +736,7 @@ export {
439
736
  isAutoPromoteEligible,
440
737
  listMarkdownFilesRecursive,
441
738
  literalMatchesAllTokens,
739
+ loadCodeMap,
442
740
  loadMemoriesFromDir,
443
741
  loadMemory,
444
742
  loadUsageIndex,
@@ -448,14 +746,17 @@ export {
448
746
  parseMemory,
449
747
  pathsOverlap,
450
748
  pickSnippetNeedle,
749
+ queryCodeMap,
451
750
  recordRejection,
452
751
  relPathFrom,
453
752
  resolveHaivePaths,
753
+ saveCodeMap,
454
754
  saveUsageIndex,
455
755
  serializeMemory,
456
756
  stripPrivate,
457
757
  tokenizeQuery,
458
758
  trackReads,
759
+ truncateToTokens,
459
760
  usagePath,
460
761
  verifyAnchor
461
762
  };
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/schema.ts","../src/parser.ts","../src/paths.ts","../src/loader.ts","../src/search.ts","../src/verifier.ts","../src/usage.ts","../src/confidence.ts","../src/relevance.ts"],"sourcesContent":["import { z } from \"zod\";\n\nexport const MemoryScopeSchema = z.enum([\"personal\", \"team\", \"module\"]);\n\nexport const MemoryStatusSchema = z.enum([\n \"draft\",\n \"proposed\",\n \"validated\",\n \"deprecated\",\n \"stale\",\n]);\n\nexport const MemoryTypeSchema = z.enum([\n \"convention\",\n \"decision\",\n \"gotcha\",\n \"architecture\",\n \"glossary\",\n]);\n\nexport const AnchorSchema = z.object({\n commit: z.string().optional(),\n paths: z.array(z.string()).default([]),\n symbols: z.array(z.string()).default([]),\n});\n\nconst IsoDateString = z\n .union([z.string(), z.date()])\n .transform((v) => (v instanceof Date ? v.toISOString() : v))\n .pipe(z.string().datetime());\n\nexport const MemoryFrontmatterSchema = z\n .object({\n id: z.string().min(1),\n scope: MemoryScopeSchema.default(\"personal\"),\n module: z.string().optional(),\n type: MemoryTypeSchema,\n status: MemoryStatusSchema.default(\"draft\"),\n anchor: AnchorSchema.default({ paths: [], symbols: [] }),\n tags: z.array(z.string()).default([]),\n domain: z.string().optional(),\n author: z.string().optional(),\n created_at: IsoDateString,\n expires_when: z.string().nullable().default(null),\n verified_at: z.string().nullable().default(null),\n stale_reason: z.string().nullable().default(null),\n })\n .refine(\n (data) => data.scope !== \"module\" || !!data.module,\n { message: \"module name is required when scope is 'module'\", path: [\"module\"] },\n );\n","import matter from \"gray-matter\";\nimport { MemoryFrontmatterSchema } from \"./schema.js\";\nimport type { Memory, MemoryFrontmatter } from \"./types.js\";\n\nconst PRIVATE_BLOCK_RE = /<private>[\\s\\S]*?<\\/private>/g;\n\nexport function stripPrivate(body: string): string {\n return body.replace(PRIVATE_BLOCK_RE, \"\").trimEnd();\n}\n\nexport function parseMemory(raw: string): Memory {\n const parsed = matter(raw);\n const frontmatter = MemoryFrontmatterSchema.parse(parsed.data);\n return {\n frontmatter,\n body: stripPrivate(parsed.content.trim()),\n };\n}\n\nfunction stripUndefined<T>(value: T): T {\n if (Array.isArray(value)) {\n return value.map((v) => stripUndefined(v)) as unknown as T;\n }\n if (value && typeof value === \"object\") {\n const out: Record<string, unknown> = {};\n for (const [k, v] of Object.entries(value as Record<string, unknown>)) {\n if (v === undefined) continue;\n out[k] = stripUndefined(v);\n }\n return out as T;\n }\n return value;\n}\n\nexport function serializeMemory(memory: Memory): string {\n const clean = stripUndefined(memory.frontmatter) as Record<string, unknown>;\n return matter.stringify(memory.body, clean);\n}\n\nexport function newMemoryId(type: string, slug: string, date = new Date()): string {\n const isoDate = date.toISOString().slice(0, 10);\n const safeSlug = slug\n .toLowerCase()\n .replace(/[^a-z0-9]+/g, \"-\")\n .replace(/^-|-$/g, \"\")\n .slice(0, 60);\n return `${isoDate}-${type}-${safeSlug}`;\n}\n\nexport function buildFrontmatter(input: {\n type: MemoryFrontmatter[\"type\"];\n slug: string;\n scope?: MemoryFrontmatter[\"scope\"];\n module?: string;\n tags?: string[];\n domain?: string;\n author?: string;\n paths?: string[];\n symbols?: string[];\n commit?: string;\n}): MemoryFrontmatter {\n const now = new Date();\n const id = newMemoryId(input.type, input.slug, now);\n return MemoryFrontmatterSchema.parse({\n id,\n scope: input.scope ?? \"personal\",\n module: input.module,\n type: input.type,\n status: \"draft\",\n anchor: {\n commit: input.commit,\n paths: input.paths ?? [],\n symbols: input.symbols ?? [],\n },\n tags: input.tags ?? [],\n domain: input.domain,\n author: input.author,\n created_at: now.toISOString(),\n expires_when: null,\n });\n}\n","import { existsSync } from \"node:fs\";\nimport path from \"node:path\";\n\nexport const HAIVE_DIR = \".ai\";\n\nconst ROOT_MARKERS = [\".ai\", \".git\", \"package.json\"];\n\nexport function findProjectRoot(startDir: string = process.cwd()): string {\n let current = path.resolve(startDir);\n const fsRoot = path.parse(current).root;\n while (current !== fsRoot) {\n for (const marker of ROOT_MARKERS) {\n if (existsSync(path.join(current, marker))) return current;\n }\n current = path.dirname(current);\n }\n return path.resolve(startDir);\n}\n\nexport const PROJECT_CONTEXT_FILE = \"project-context.md\";\nexport const MEMORIES_DIR = \"memories\";\n\nexport interface HaivePaths {\n root: string;\n haiveDir: string;\n projectContext: string;\n memoriesDir: string;\n personalDir: string;\n teamDir: string;\n moduleDir: string;\n modulesContextDir: string;\n}\n\nexport function resolveHaivePaths(projectRoot: string): HaivePaths {\n const haiveDir = path.join(projectRoot, HAIVE_DIR);\n const memoriesDir = path.join(haiveDir, MEMORIES_DIR);\n return {\n root: projectRoot,\n haiveDir,\n projectContext: path.join(haiveDir, PROJECT_CONTEXT_FILE),\n memoriesDir,\n personalDir: path.join(memoriesDir, \"personal\"),\n teamDir: path.join(memoriesDir, \"team\"),\n moduleDir: path.join(memoriesDir, \"module\"),\n modulesContextDir: path.join(haiveDir, \"modules\"),\n };\n}\n\nexport function memoryFilePath(\n paths: HaivePaths,\n scope: \"personal\" | \"team\" | \"module\",\n id: string,\n module?: string,\n): string {\n const base =\n scope === \"personal\"\n ? paths.personalDir\n : scope === \"team\"\n ? paths.teamDir\n : path.join(paths.moduleDir, module ?? \"_unscoped\");\n return path.join(base, `${id}.md`);\n}\n","import { readdir, readFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { parseMemory } from \"./parser.js\";\nimport type { Memory } from \"./types.js\";\n\nexport interface LoadedMemory {\n memory: Memory;\n filePath: string;\n}\n\nexport async function listMarkdownFilesRecursive(dir: string): Promise<string[]> {\n const out: string[] = [];\n let entries;\n try {\n entries = await readdir(dir, { withFileTypes: true });\n } catch {\n return out;\n }\n for (const entry of entries) {\n const full = path.join(dir, entry.name);\n if (entry.isDirectory()) {\n out.push(...(await listMarkdownFilesRecursive(full)));\n } else if (entry.isFile() && entry.name.endsWith(\".md\")) {\n out.push(full);\n }\n }\n return out;\n}\n\nexport async function loadMemory(filePath: string): Promise<LoadedMemory> {\n const raw = await readFile(filePath, \"utf8\");\n return { memory: parseMemory(raw), filePath };\n}\n\nexport async function loadMemoriesFromDir(dir: string): Promise<LoadedMemory[]> {\n const files = await listMarkdownFilesRecursive(dir);\n const out: LoadedMemory[] = [];\n for (const file of files) {\n try {\n out.push(await loadMemory(file));\n } catch {\n // Skip unparseable files in v0.1; future: surface a warning channel.\n }\n }\n return out;\n}\n","import type { Memory } from \"./types.js\";\n\nexport function tokenizeQuery(query: string): string[] {\n return query\n .toLowerCase()\n .split(/\\s+/)\n .map((t) => t.trim())\n .filter(Boolean);\n}\n\nexport function literalMatchesAllTokens(memory: Memory, tokens: string[]): boolean {\n if (tokens.length === 0) return true;\n const fm = memory.frontmatter;\n const idLower = fm.id.toLowerCase();\n const tagsLower = fm.tags.map((t) => t.toLowerCase());\n const bodyLower = memory.body.toLowerCase();\n return tokens.every((rawTok) => {\n const tok = rawTok.toLowerCase();\n return (\n idLower.includes(tok) ||\n tagsLower.some((t) => t.includes(tok)) ||\n bodyLower.includes(tok)\n );\n });\n}\n\nexport function pickSnippetNeedle(query: string): string {\n const tokens = tokenizeQuery(query);\n if (tokens.length === 0) return query.toLowerCase();\n return [...tokens].sort((a, b) => b.length - a.length)[0]!;\n}\n\nexport function extractSnippet(body: string, needle: string, radius = 40): string {\n const lower = body.toLowerCase();\n const idx = needle ? lower.indexOf(needle) : -1;\n if (idx < 0) {\n return body.slice(0, radius * 3).replace(/\\s+/g, \" \").trim();\n }\n const start = Math.max(0, idx - radius);\n const end = Math.min(body.length, idx + needle.length + radius);\n const snippet = body.slice(start, end).replace(/\\s+/g, \" \").trim();\n return (start > 0 ? \"…\" : \"\") + snippet + (end < body.length ? \"…\" : \"\");\n}\n","import { readFile } from \"node:fs/promises\";\nimport { existsSync } from \"node:fs\";\nimport path from \"node:path\";\nimport type { Memory } from \"./types.js\";\n\nexport interface VerifyResult {\n stale: boolean;\n reason: string | null;\n checkedPaths: string[];\n checkedSymbols: string[];\n}\n\nexport interface VerifyOptions {\n /** Project root used to resolve relative anchor paths. */\n projectRoot: string;\n}\n\n/**\n * Verify that a memory's anchor still matches the current code.\n * - Every anchor.paths entry must exist on disk\n * - Every anchor.symbols entry must appear at least once across the anchor.paths\n * files (or any tracked file if no paths are recorded)\n *\n * Anchorless memories (no paths and no symbols) are always considered fresh —\n * staleness only applies to memories that opted into anchoring.\n */\nexport async function verifyAnchor(\n memory: Memory,\n options: VerifyOptions,\n): Promise<VerifyResult> {\n const anchor = memory.frontmatter.anchor;\n const checkedPaths = anchor.paths;\n const checkedSymbols = anchor.symbols;\n\n if (checkedPaths.length === 0 && checkedSymbols.length === 0) {\n return { stale: false, reason: null, checkedPaths, checkedSymbols };\n }\n\n const missingPaths: string[] = [];\n const existingAbsPaths: string[] = [];\n for (const rel of checkedPaths) {\n const abs = path.isAbsolute(rel) ? rel : path.join(options.projectRoot, rel);\n if (existsSync(abs)) {\n existingAbsPaths.push(abs);\n } else {\n missingPaths.push(rel);\n }\n }\n\n if (missingPaths.length > 0) {\n return {\n stale: true,\n reason: `anchor path(s) no longer exist: ${missingPaths.join(\", \")}`,\n checkedPaths,\n checkedSymbols,\n };\n }\n\n if (checkedSymbols.length > 0) {\n if (existingAbsPaths.length === 0) {\n return {\n stale: true,\n reason: `cannot verify symbols (${checkedSymbols.join(\", \")}): no anchor paths recorded`,\n checkedPaths,\n checkedSymbols,\n };\n }\n const missingSymbols: string[] = [];\n for (const sym of checkedSymbols) {\n let found = false;\n for (const file of existingAbsPaths) {\n try {\n const contents = await readFile(file, \"utf8\");\n if (contents.includes(sym)) {\n found = true;\n break;\n }\n } catch {\n // unreadable file; treat as not finding the symbol here\n }\n }\n if (!found) missingSymbols.push(sym);\n }\n if (missingSymbols.length > 0) {\n return {\n stale: true,\n reason: `anchor symbol(s) not found in any anchor path: ${missingSymbols.join(\", \")}`,\n checkedPaths,\n checkedSymbols,\n };\n }\n }\n\n return { stale: false, reason: null, checkedPaths, checkedSymbols };\n}\n","import { mkdir, readFile, writeFile } from \"node:fs/promises\";\nimport { existsSync } from \"node:fs\";\nimport path from \"node:path\";\nimport type { HaivePaths } from \"./paths.js\";\n\nexport interface MemoryUsage {\n read_count: number;\n last_read_at: string | null;\n rejected_count: number;\n last_rejected_at: string | null;\n rejection_reason: string | null;\n}\n\nexport interface UsageIndex {\n version: 1;\n updated_at: string;\n by_id: Record<string, MemoryUsage>;\n}\n\nexport const USAGE_FILE = \"usage.json\";\n\nexport function emptyUsage(): MemoryUsage {\n return {\n read_count: 0,\n last_read_at: null,\n rejected_count: 0,\n last_rejected_at: null,\n rejection_reason: null,\n };\n}\n\nexport function emptyUsageIndex(): UsageIndex {\n return {\n version: 1,\n updated_at: new Date().toISOString(),\n by_id: {},\n };\n}\n\nexport function usagePath(paths: HaivePaths): string {\n return path.join(paths.haiveDir, \".cache\", USAGE_FILE);\n}\n\nexport async function loadUsageIndex(paths: HaivePaths): Promise<UsageIndex> {\n const file = usagePath(paths);\n if (!existsSync(file)) return emptyUsageIndex();\n const raw = await readFile(file, \"utf8\");\n try {\n const parsed = JSON.parse(raw) as UsageIndex;\n if (parsed.version !== 1) return emptyUsageIndex();\n return parsed;\n } catch {\n return emptyUsageIndex();\n }\n}\n\nexport async function saveUsageIndex(paths: HaivePaths, index: UsageIndex): Promise<void> {\n const file = usagePath(paths);\n await mkdir(path.dirname(file), { recursive: true });\n index.updated_at = new Date().toISOString();\n await writeFile(file, JSON.stringify(index, null, 2), \"utf8\");\n}\n\nexport function getUsage(index: UsageIndex, id: string): MemoryUsage {\n return index.by_id[id] ?? emptyUsage();\n}\n\nexport function bumpRead(index: UsageIndex, ids: string[]): UsageIndex {\n if (ids.length === 0) return index;\n const now = new Date().toISOString();\n for (const id of ids) {\n const current = index.by_id[id] ?? emptyUsage();\n index.by_id[id] = {\n ...current,\n read_count: current.read_count + 1,\n last_read_at: now,\n };\n }\n return index;\n}\n\nexport function recordRejection(\n index: UsageIndex,\n id: string,\n reason: string | null,\n): UsageIndex {\n const current = index.by_id[id] ?? emptyUsage();\n const now = new Date().toISOString();\n index.by_id[id] = {\n ...current,\n rejected_count: current.rejected_count + 1,\n last_rejected_at: now,\n rejection_reason: reason,\n };\n return index;\n}\n\nexport async function trackReads(\n paths: HaivePaths,\n ids: string[],\n): Promise<UsageIndex> {\n if (ids.length === 0) {\n return await loadUsageIndex(paths);\n }\n const index = await loadUsageIndex(paths);\n bumpRead(index, ids);\n await saveUsageIndex(paths, index);\n return index;\n}\n","import type { MemoryFrontmatter } from \"./types.js\";\nimport type { MemoryUsage } from \"./usage.js\";\n\nexport type ConfidenceLevel =\n | \"unverified\"\n | \"low\"\n | \"trusted\"\n | \"authoritative\"\n | \"stale\";\n\nexport interface ConfidenceThresholds {\n trustedReads: number;\n authoritativeReads: number;\n}\n\nexport const DEFAULT_CONFIDENCE_THRESHOLDS: ConfidenceThresholds = {\n trustedReads: 3,\n authoritativeReads: 10,\n};\n\nexport function deriveConfidence(\n fm: MemoryFrontmatter,\n usage: MemoryUsage,\n thresholds: ConfidenceThresholds = DEFAULT_CONFIDENCE_THRESHOLDS,\n): ConfidenceLevel {\n if (fm.status === \"stale\" || fm.status === \"deprecated\") return \"stale\";\n if (fm.status === \"validated\") {\n return usage.read_count >= thresholds.authoritativeReads\n ? \"authoritative\"\n : \"trusted\";\n }\n if (fm.status === \"proposed\") {\n return usage.read_count >= thresholds.trustedReads ? \"trusted\" : \"low\";\n }\n // draft\n return \"unverified\";\n}\n\nexport interface AutoPromoteRule {\n /** Minimum read_count to promote proposed → validated. */\n minReads: number;\n /** Maximum rejected_count tolerated (memories with more rejections never auto-promote). */\n maxRejections: number;\n}\n\nexport const DEFAULT_AUTO_PROMOTE_RULE: AutoPromoteRule = {\n minReads: 5,\n maxRejections: 0,\n};\n\nexport function isAutoPromoteEligible(\n fm: MemoryFrontmatter,\n usage: MemoryUsage,\n rule: AutoPromoteRule = DEFAULT_AUTO_PROMOTE_RULE,\n): boolean {\n if (fm.status !== \"proposed\") return false;\n if (usage.rejected_count > rule.maxRejections) return false;\n return usage.read_count >= rule.minReads;\n}\n","import path from \"node:path\";\nimport type { LoadedMemory } from \"./loader.js\";\n\nconst MODULE_PATTERNS = [\n /^packages\\/([^/]+)\\//,\n /^apps\\/([^/]+)\\//,\n /^modules\\/([^/]+)\\//,\n /^src\\/([^/]+)\\//,\n];\n\n/**\n * Best-effort inference: given a list of file paths, infer module names from\n * conventional layouts (packages/X/, apps/X/, modules/X/, src/X/).\n */\nexport function inferModulesFromPaths(filePaths: string[]): string[] {\n const out = new Set<string>();\n for (const p of filePaths) {\n const norm = normalize(p);\n for (const re of MODULE_PATTERNS) {\n const m = norm.match(re);\n if (m && m[1]) out.add(m[1]);\n }\n }\n return [...out].sort();\n}\n\n/**\n * Path overlap: returns true if `a` and `b` refer to the same path or one is a\n * parent of the other. Both inputs are treated as POSIX-style relative paths.\n */\nexport function pathsOverlap(a: string, b: string): boolean {\n const na = normalize(a);\n const nb = normalize(b);\n if (na === nb) return true;\n return na.startsWith(nb + \"/\") || nb.startsWith(na + \"/\");\n}\n\nexport function memoryMatchesAnchorPaths(\n memory: LoadedMemory[\"memory\"],\n inputPaths: string[],\n): boolean {\n const anchorPaths = memory.frontmatter.anchor.paths;\n if (anchorPaths.length === 0) return false;\n for (const ap of anchorPaths) {\n for (const ip of inputPaths) {\n if (pathsOverlap(ap, ip)) return true;\n }\n }\n return false;\n}\n\nfunction normalize(p: string): string {\n // Strip leading \"./\" and trailing \"/\", normalize separators.\n return p.replace(/\\\\/g, \"/\").replace(/^\\.\\//, \"\").replace(/\\/+$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O;AACrC,aAAW,MAAM,aAAa;AAC5B,eAAW,MAAM,YAAY;AAC3B,UAAI,aAAa,IAAI,EAAE,EAAG,QAAO;AAAA,IACnC;AAAA,EACF;AACA,SAAO;AACT;AAEA,SAAS,UAAU,GAAmB;AAEpC,SAAO,EAAE,QAAQ,OAAO,GAAG,EAAE,QAAQ,SAAS,EAAE,EAAE,QAAQ,QAAQ,EAAE;AACtE;AAEO,SAAS,YAAY,MAAc,KAAqB;AAC7D,SAAOA,MAAK,SAAS,MAAM,GAAG,EAAE,QAAQ,OAAO,GAAG;AACpD;","names":["path","path","readFile","existsSync","path","readFile","existsSync","path","path"]}
1
+ {"version":3,"sources":["../src/schema.ts","../src/parser.ts","../src/paths.ts","../src/loader.ts","../src/search.ts","../src/verifier.ts","../src/usage.ts","../src/confidence.ts","../src/relevance.ts","../src/token-budget.ts","../src/code-map.ts"],"sourcesContent":["import { z } from \"zod\";\n\nexport const MemoryScopeSchema = z.enum([\"personal\", \"team\", \"module\"]);\n\nexport const MemoryStatusSchema = z.enum([\n \"draft\",\n \"proposed\",\n \"validated\",\n \"deprecated\",\n \"stale\",\n]);\n\nexport const MemoryTypeSchema = z.enum([\n \"convention\",\n \"decision\",\n \"gotcha\",\n \"architecture\",\n \"glossary\",\n]);\n\nexport const AnchorSchema = z.object({\n commit: z.string().optional(),\n paths: z.array(z.string()).default([]),\n symbols: z.array(z.string()).default([]),\n});\n\nconst IsoDateString = z\n .union([z.string(), z.date()])\n .transform((v) => (v instanceof Date ? v.toISOString() : v))\n .pipe(z.string().datetime());\n\nexport const MemoryFrontmatterSchema = z\n .object({\n id: z.string().min(1),\n scope: MemoryScopeSchema.default(\"personal\"),\n module: z.string().optional(),\n type: MemoryTypeSchema,\n status: MemoryStatusSchema.default(\"draft\"),\n anchor: AnchorSchema.default({ paths: [], symbols: [] }),\n tags: z.array(z.string()).default([]),\n domain: z.string().optional(),\n author: z.string().optional(),\n created_at: IsoDateString,\n expires_when: z.string().nullable().default(null),\n verified_at: z.string().nullable().default(null),\n stale_reason: z.string().nullable().default(null),\n })\n .refine(\n (data) => data.scope !== \"module\" || !!data.module,\n { message: \"module name is required when scope is 'module'\", path: [\"module\"] },\n );\n","import matter from \"gray-matter\";\nimport { MemoryFrontmatterSchema } from \"./schema.js\";\nimport type { Memory, MemoryFrontmatter } from \"./types.js\";\n\nconst PRIVATE_BLOCK_RE = /<private>[\\s\\S]*?<\\/private>/g;\n\nexport function stripPrivate(body: string): string {\n return body.replace(PRIVATE_BLOCK_RE, \"\").trimEnd();\n}\n\nexport function parseMemory(raw: string): Memory {\n const parsed = matter(raw);\n const frontmatter = MemoryFrontmatterSchema.parse(parsed.data);\n return {\n frontmatter,\n body: stripPrivate(parsed.content.trim()),\n };\n}\n\nfunction stripUndefined<T>(value: T): T {\n if (Array.isArray(value)) {\n return value.map((v) => stripUndefined(v)) as unknown as T;\n }\n if (value && typeof value === \"object\") {\n const out: Record<string, unknown> = {};\n for (const [k, v] of Object.entries(value as Record<string, unknown>)) {\n if (v === undefined) continue;\n out[k] = stripUndefined(v);\n }\n return out as T;\n }\n return value;\n}\n\nexport function serializeMemory(memory: Memory): string {\n const clean = stripUndefined(memory.frontmatter) as Record<string, unknown>;\n return matter.stringify(memory.body, clean);\n}\n\nexport function newMemoryId(type: string, slug: string, date = new Date()): string {\n const isoDate = date.toISOString().slice(0, 10);\n const safeSlug = slug\n .toLowerCase()\n .replace(/[^a-z0-9]+/g, \"-\")\n .replace(/^-|-$/g, \"\")\n .slice(0, 60);\n return `${isoDate}-${type}-${safeSlug}`;\n}\n\nexport function buildFrontmatter(input: {\n type: MemoryFrontmatter[\"type\"];\n slug: string;\n scope?: MemoryFrontmatter[\"scope\"];\n module?: string;\n tags?: string[];\n domain?: string;\n author?: string;\n paths?: string[];\n symbols?: string[];\n commit?: string;\n}): MemoryFrontmatter {\n const now = new Date();\n const id = newMemoryId(input.type, input.slug, now);\n return MemoryFrontmatterSchema.parse({\n id,\n scope: input.scope ?? \"personal\",\n module: input.module,\n type: input.type,\n status: \"draft\",\n anchor: {\n commit: input.commit,\n paths: input.paths ?? [],\n symbols: input.symbols ?? [],\n },\n tags: input.tags ?? [],\n domain: input.domain,\n author: input.author,\n created_at: now.toISOString(),\n expires_when: null,\n });\n}\n","import { existsSync } from \"node:fs\";\nimport path from \"node:path\";\n\nexport const HAIVE_DIR = \".ai\";\n\nconst ROOT_MARKERS = [\".ai\", \".git\", \"package.json\"];\n\nexport function findProjectRoot(startDir: string = process.cwd()): string {\n let current = path.resolve(startDir);\n const fsRoot = path.parse(current).root;\n while (current !== fsRoot) {\n for (const marker of ROOT_MARKERS) {\n if (existsSync(path.join(current, marker))) return current;\n }\n current = path.dirname(current);\n }\n return path.resolve(startDir);\n}\n\nexport const PROJECT_CONTEXT_FILE = \"project-context.md\";\nexport const MEMORIES_DIR = \"memories\";\n\nexport interface HaivePaths {\n root: string;\n haiveDir: string;\n projectContext: string;\n memoriesDir: string;\n personalDir: string;\n teamDir: string;\n moduleDir: string;\n modulesContextDir: string;\n}\n\nexport function resolveHaivePaths(projectRoot: string): HaivePaths {\n const haiveDir = path.join(projectRoot, HAIVE_DIR);\n const memoriesDir = path.join(haiveDir, MEMORIES_DIR);\n return {\n root: projectRoot,\n haiveDir,\n projectContext: path.join(haiveDir, PROJECT_CONTEXT_FILE),\n memoriesDir,\n personalDir: path.join(memoriesDir, \"personal\"),\n teamDir: path.join(memoriesDir, \"team\"),\n moduleDir: path.join(memoriesDir, \"module\"),\n modulesContextDir: path.join(haiveDir, \"modules\"),\n };\n}\n\nexport function memoryFilePath(\n paths: HaivePaths,\n scope: \"personal\" | \"team\" | \"module\",\n id: string,\n module?: string,\n): string {\n const base =\n scope === \"personal\"\n ? paths.personalDir\n : scope === \"team\"\n ? paths.teamDir\n : path.join(paths.moduleDir, module ?? \"_unscoped\");\n return path.join(base, `${id}.md`);\n}\n","import { readdir, readFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { parseMemory } from \"./parser.js\";\nimport type { Memory } from \"./types.js\";\n\nexport interface LoadedMemory {\n memory: Memory;\n filePath: string;\n}\n\nexport async function listMarkdownFilesRecursive(dir: string): Promise<string[]> {\n const out: string[] = [];\n let entries;\n try {\n entries = await readdir(dir, { withFileTypes: true });\n } catch {\n return out;\n }\n for (const entry of entries) {\n const full = path.join(dir, entry.name);\n if (entry.isDirectory()) {\n out.push(...(await listMarkdownFilesRecursive(full)));\n } else if (entry.isFile() && entry.name.endsWith(\".md\")) {\n out.push(full);\n }\n }\n return out;\n}\n\nexport async function loadMemory(filePath: string): Promise<LoadedMemory> {\n const raw = await readFile(filePath, \"utf8\");\n return { memory: parseMemory(raw), filePath };\n}\n\nexport async function loadMemoriesFromDir(dir: string): Promise<LoadedMemory[]> {\n const files = await listMarkdownFilesRecursive(dir);\n const out: LoadedMemory[] = [];\n for (const file of files) {\n try {\n out.push(await loadMemory(file));\n } catch {\n // Skip unparseable files in v0.1; future: surface a warning channel.\n }\n }\n return out;\n}\n","import type { Memory } from \"./types.js\";\n\nexport function tokenizeQuery(query: string): string[] {\n return query\n .toLowerCase()\n .split(/\\s+/)\n .map((t) => t.trim())\n .filter(Boolean);\n}\n\nexport function literalMatchesAllTokens(memory: Memory, tokens: string[]): boolean {\n if (tokens.length === 0) return true;\n const fm = memory.frontmatter;\n const idLower = fm.id.toLowerCase();\n const tagsLower = fm.tags.map((t) => t.toLowerCase());\n const bodyLower = memory.body.toLowerCase();\n const anchorPathTokens = collectAnchorPathTokens(fm.anchor.paths);\n const anchorSymbolsLower = fm.anchor.symbols.map((s) => s.toLowerCase());\n const moduleLower = fm.module?.toLowerCase();\n const domainLower = fm.domain?.toLowerCase();\n\n return tokens.every((rawTok) => {\n const tok = rawTok.toLowerCase();\n return (\n idLower.includes(tok) ||\n tagsLower.some((t) => t.includes(tok)) ||\n bodyLower.includes(tok) ||\n anchorPathTokens.some((p) => p.includes(tok)) ||\n anchorSymbolsLower.some((s) => s.includes(tok)) ||\n (moduleLower !== undefined && moduleLower.includes(tok)) ||\n (domainLower !== undefined && domainLower.includes(tok))\n );\n });\n}\n\nfunction collectAnchorPathTokens(paths: readonly string[]): string[] {\n const out = new Set<string>();\n for (const p of paths) {\n const lower = p.toLowerCase();\n out.add(lower);\n // basename without extension\n const base = lower.split(\"/\").pop() ?? lower;\n const noExt = base.replace(/\\.[a-z0-9]+$/, \"\");\n if (noExt) out.add(noExt);\n // each path segment (helps \"verifier\" match \"src/verifier.ts\")\n for (const segment of lower.split(\"/\")) {\n const seg = segment.replace(/\\.[a-z0-9]+$/, \"\");\n if (seg) out.add(seg);\n }\n }\n return [...out];\n}\n\nexport function pickSnippetNeedle(query: string): string {\n const tokens = tokenizeQuery(query);\n if (tokens.length === 0) return query.toLowerCase();\n return [...tokens].sort((a, b) => b.length - a.length)[0]!;\n}\n\nexport function extractSnippet(body: string, needle: string, radius = 40): string {\n const lower = body.toLowerCase();\n const idx = needle ? lower.indexOf(needle) : -1;\n if (idx < 0) {\n return body.slice(0, radius * 3).replace(/\\s+/g, \" \").trim();\n }\n const start = Math.max(0, idx - radius);\n const end = Math.min(body.length, idx + needle.length + radius);\n const snippet = body.slice(start, end).replace(/\\s+/g, \" \").trim();\n return (start > 0 ? \"…\" : \"\") + snippet + (end < body.length ? \"…\" : \"\");\n}\n","import { readFile } from \"node:fs/promises\";\nimport { existsSync } from \"node:fs\";\nimport path from \"node:path\";\nimport type { Memory } from \"./types.js\";\n\nexport interface VerifyResult {\n stale: boolean;\n reason: string | null;\n checkedPaths: string[];\n checkedSymbols: string[];\n}\n\nexport interface VerifyOptions {\n /** Project root used to resolve relative anchor paths. */\n projectRoot: string;\n}\n\n/**\n * Verify that a memory's anchor still matches the current code.\n * - Every anchor.paths entry must exist on disk\n * - Every anchor.symbols entry must appear at least once across the anchor.paths\n * files (or any tracked file if no paths are recorded)\n *\n * Anchorless memories (no paths and no symbols) are always considered fresh —\n * staleness only applies to memories that opted into anchoring.\n */\nexport async function verifyAnchor(\n memory: Memory,\n options: VerifyOptions,\n): Promise<VerifyResult> {\n const anchor = memory.frontmatter.anchor;\n const checkedPaths = anchor.paths;\n const checkedSymbols = anchor.symbols;\n\n if (checkedPaths.length === 0 && checkedSymbols.length === 0) {\n return { stale: false, reason: null, checkedPaths, checkedSymbols };\n }\n\n const missingPaths: string[] = [];\n const existingAbsPaths: string[] = [];\n for (const rel of checkedPaths) {\n const abs = path.isAbsolute(rel) ? rel : path.join(options.projectRoot, rel);\n if (existsSync(abs)) {\n existingAbsPaths.push(abs);\n } else {\n missingPaths.push(rel);\n }\n }\n\n if (missingPaths.length > 0) {\n return {\n stale: true,\n reason: `anchor path(s) no longer exist: ${missingPaths.join(\", \")}`,\n checkedPaths,\n checkedSymbols,\n };\n }\n\n if (checkedSymbols.length > 0) {\n if (existingAbsPaths.length === 0) {\n return {\n stale: true,\n reason: `cannot verify symbols (${checkedSymbols.join(\", \")}): no anchor paths recorded`,\n checkedPaths,\n checkedSymbols,\n };\n }\n const missingSymbols: string[] = [];\n for (const sym of checkedSymbols) {\n let found = false;\n for (const file of existingAbsPaths) {\n try {\n const contents = await readFile(file, \"utf8\");\n if (contents.includes(sym)) {\n found = true;\n break;\n }\n } catch {\n // unreadable file; treat as not finding the symbol here\n }\n }\n if (!found) missingSymbols.push(sym);\n }\n if (missingSymbols.length > 0) {\n return {\n stale: true,\n reason: `anchor symbol(s) not found in any anchor path: ${missingSymbols.join(\", \")}`,\n checkedPaths,\n checkedSymbols,\n };\n }\n }\n\n return { stale: false, reason: null, checkedPaths, checkedSymbols };\n}\n","import { mkdir, readFile, writeFile } from \"node:fs/promises\";\nimport { existsSync } from \"node:fs\";\nimport path from \"node:path\";\nimport type { HaivePaths } from \"./paths.js\";\n\nexport interface MemoryUsage {\n read_count: number;\n last_read_at: string | null;\n rejected_count: number;\n last_rejected_at: string | null;\n rejection_reason: string | null;\n}\n\nexport interface UsageIndex {\n version: 1;\n updated_at: string;\n by_id: Record<string, MemoryUsage>;\n}\n\nexport const USAGE_FILE = \"usage.json\";\n\nexport function emptyUsage(): MemoryUsage {\n return {\n read_count: 0,\n last_read_at: null,\n rejected_count: 0,\n last_rejected_at: null,\n rejection_reason: null,\n };\n}\n\nexport function emptyUsageIndex(): UsageIndex {\n return {\n version: 1,\n updated_at: new Date().toISOString(),\n by_id: {},\n };\n}\n\nexport function usagePath(paths: HaivePaths): string {\n return path.join(paths.haiveDir, \".cache\", USAGE_FILE);\n}\n\nexport async function loadUsageIndex(paths: HaivePaths): Promise<UsageIndex> {\n const file = usagePath(paths);\n if (!existsSync(file)) return emptyUsageIndex();\n const raw = await readFile(file, \"utf8\");\n try {\n const parsed = JSON.parse(raw) as UsageIndex;\n if (parsed.version !== 1) return emptyUsageIndex();\n return parsed;\n } catch {\n return emptyUsageIndex();\n }\n}\n\nexport async function saveUsageIndex(paths: HaivePaths, index: UsageIndex): Promise<void> {\n const file = usagePath(paths);\n await mkdir(path.dirname(file), { recursive: true });\n index.updated_at = new Date().toISOString();\n await writeFile(file, JSON.stringify(index, null, 2), \"utf8\");\n}\n\nexport function getUsage(index: UsageIndex, id: string): MemoryUsage {\n return index.by_id[id] ?? emptyUsage();\n}\n\nexport function bumpRead(index: UsageIndex, ids: string[]): UsageIndex {\n if (ids.length === 0) return index;\n const now = new Date().toISOString();\n for (const id of ids) {\n const current = index.by_id[id] ?? emptyUsage();\n index.by_id[id] = {\n ...current,\n read_count: current.read_count + 1,\n last_read_at: now,\n };\n }\n return index;\n}\n\nexport function recordRejection(\n index: UsageIndex,\n id: string,\n reason: string | null,\n): UsageIndex {\n const current = index.by_id[id] ?? emptyUsage();\n const now = new Date().toISOString();\n index.by_id[id] = {\n ...current,\n rejected_count: current.rejected_count + 1,\n last_rejected_at: now,\n rejection_reason: reason,\n };\n return index;\n}\n\nexport async function trackReads(\n paths: HaivePaths,\n ids: string[],\n): Promise<UsageIndex> {\n if (ids.length === 0) {\n return await loadUsageIndex(paths);\n }\n const index = await loadUsageIndex(paths);\n bumpRead(index, ids);\n await saveUsageIndex(paths, index);\n return index;\n}\n","import type { MemoryFrontmatter } from \"./types.js\";\nimport type { MemoryUsage } from \"./usage.js\";\n\nexport type ConfidenceLevel =\n | \"unverified\"\n | \"low\"\n | \"trusted\"\n | \"authoritative\"\n | \"stale\";\n\nexport interface ConfidenceThresholds {\n trustedReads: number;\n authoritativeReads: number;\n}\n\nexport const DEFAULT_CONFIDENCE_THRESHOLDS: ConfidenceThresholds = {\n trustedReads: 3,\n authoritativeReads: 10,\n};\n\nexport function deriveConfidence(\n fm: MemoryFrontmatter,\n usage: MemoryUsage,\n thresholds: ConfidenceThresholds = DEFAULT_CONFIDENCE_THRESHOLDS,\n): ConfidenceLevel {\n if (fm.status === \"stale\" || fm.status === \"deprecated\") return \"stale\";\n if (fm.status === \"validated\") {\n return usage.read_count >= thresholds.authoritativeReads\n ? \"authoritative\"\n : \"trusted\";\n }\n if (fm.status === \"proposed\") {\n return usage.read_count >= thresholds.trustedReads ? \"trusted\" : \"low\";\n }\n // draft\n return \"unverified\";\n}\n\nexport interface AutoPromoteRule {\n /** Minimum read_count to promote proposed → validated. */\n minReads: number;\n /** Maximum rejected_count tolerated (memories with more rejections never auto-promote). */\n maxRejections: number;\n}\n\nexport const DEFAULT_AUTO_PROMOTE_RULE: AutoPromoteRule = {\n minReads: 5,\n maxRejections: 0,\n};\n\nexport function isAutoPromoteEligible(\n fm: MemoryFrontmatter,\n usage: MemoryUsage,\n rule: AutoPromoteRule = DEFAULT_AUTO_PROMOTE_RULE,\n): boolean {\n if (fm.status !== \"proposed\") return false;\n if (usage.rejected_count > rule.maxRejections) return false;\n return usage.read_count >= rule.minReads;\n}\n","import path from \"node:path\";\nimport type { LoadedMemory } from \"./loader.js\";\n\nconst MODULE_PATTERNS = [\n /^packages\\/([^/]+)\\//,\n /^apps\\/([^/]+)\\//,\n /^modules\\/([^/]+)\\//,\n /^src\\/([^/]+)\\//,\n];\n\n/**\n * Best-effort inference: given a list of file paths, infer module names from\n * conventional layouts (packages/X/, apps/X/, modules/X/, src/X/).\n */\nexport function inferModulesFromPaths(filePaths: string[]): string[] {\n const out = new Set<string>();\n for (const p of filePaths) {\n const norm = normalize(p);\n for (const re of MODULE_PATTERNS) {\n const m = norm.match(re);\n if (m && m[1]) out.add(m[1]);\n }\n }\n return [...out].sort();\n}\n\n/**\n * Path overlap: returns true if `a` and `b` refer to the same path or one is a\n * parent of the other. Both inputs are treated as POSIX-style relative paths.\n */\nexport function pathsOverlap(a: string, b: string): boolean {\n const na = normalize(a);\n const nb = normalize(b);\n if (na === nb) return true;\n return na.startsWith(nb + \"/\") || nb.startsWith(na + \"/\");\n}\n\nexport function memoryMatchesAnchorPaths(\n memory: LoadedMemory[\"memory\"],\n inputPaths: string[],\n): boolean {\n const anchorPaths = memory.frontmatter.anchor.paths;\n if (anchorPaths.length === 0) return false;\n for (const ap of anchorPaths) {\n for (const ip of inputPaths) {\n if (pathsOverlap(ap, ip)) return true;\n }\n }\n return false;\n}\n\nfunction normalize(p: string): string {\n // Strip leading \"./\" and trailing \"/\", normalize separators.\n return p.replace(/\\\\/g, \"/\").replace(/^\\.\\//, \"\").replace(/\\/+$/, \"\");\n}\n\nexport function relPathFrom(root: string, abs: string): string {\n return path.relative(root, abs).replace(/\\\\/g, \"/\");\n}\n","/**\n * Token budgeting helpers. We use the standard heuristic of ~4 chars per token,\n * which is conservative for English/code/markdown. Callers that need exact\n * counts should plug in a real tokenizer; this module only ever over-estimates,\n * so the user's hard limits are respected.\n */\n\nexport const CHARS_PER_TOKEN = 4;\n\nexport function estimateTokens(text: string): number {\n return Math.ceil(text.length / CHARS_PER_TOKEN);\n}\n\nexport interface TruncateOptions {\n /** Maximum tokens allowed in the result (inclusive). */\n maxTokens: number;\n /** Marker inserted where content was dropped. */\n marker?: string;\n /** Where to keep characters from when truncating. Default: head. */\n mode?: \"head\" | \"tail\" | \"middle\";\n}\n\nexport interface TruncateResult {\n text: string;\n truncated: boolean;\n estimatedTokens: number;\n originalTokens: number;\n}\n\nconst DEFAULT_MARKER = \"\\n…[truncated]…\\n\";\n\nexport function truncateToTokens(\n input: string,\n options: TruncateOptions,\n): TruncateResult {\n const originalTokens = estimateTokens(input);\n const max = Math.max(0, options.maxTokens);\n if (originalTokens <= max) {\n return { text: input, truncated: false, estimatedTokens: originalTokens, originalTokens };\n }\n\n if (max === 0) {\n return { text: \"\", truncated: true, estimatedTokens: 0, originalTokens };\n }\n\n const marker = options.marker ?? DEFAULT_MARKER;\n const mode = options.mode ?? \"head\";\n const markerTokens = estimateTokens(marker);\n const budgetChars = Math.max(0, (max - markerTokens) * CHARS_PER_TOKEN);\n\n let result: string;\n if (budgetChars === 0) {\n result = \"\";\n } else if (mode === \"tail\") {\n result = marker + input.slice(input.length - budgetChars);\n } else if (mode === \"middle\") {\n const half = Math.floor(budgetChars / 2);\n result = input.slice(0, half) + marker + input.slice(input.length - half);\n } else {\n result = input.slice(0, budgetChars) + marker;\n }\n\n return {\n text: result,\n truncated: true,\n estimatedTokens: estimateTokens(result),\n originalTokens,\n };\n}\n\n/**\n * Allocate a global token budget across N parts with relative weights, then\n * truncate each part to its share. Returns parts in input order, paired with\n * truncate metadata.\n */\nexport interface BudgetPart {\n key: string;\n text: string;\n weight: number;\n mode?: TruncateOptions[\"mode\"];\n}\n\nexport interface BudgetSlice {\n key: string;\n text: string;\n truncated: boolean;\n estimatedTokens: number;\n originalTokens: number;\n allocatedTokens: number;\n}\n\nexport function allocateBudget(\n parts: BudgetPart[],\n maxTokens: number,\n): BudgetSlice[] {\n if (parts.length === 0) return [];\n const totalWeight = parts.reduce((s, p) => s + Math.max(0, p.weight), 0);\n if (totalWeight === 0) {\n return parts.map((p) => ({\n key: p.key,\n text: \"\",\n truncated: estimateTokens(p.text) > 0,\n estimatedTokens: 0,\n originalTokens: estimateTokens(p.text),\n allocatedTokens: 0,\n }));\n }\n\n // First pass: allocate by weight, but if a part's content fits in less than\n // its share, redistribute the surplus to others proportionally.\n const allocations = new Map<string, number>();\n let remaining = maxTokens;\n let remainingWeight = totalWeight;\n\n // Sort parts by share fit ascending so small ones consume their share first.\n const sortedByFit = [...parts]\n .map((p) => ({\n key: p.key,\n tokens: estimateTokens(p.text),\n share: (p.weight / totalWeight) * maxTokens,\n part: p,\n }))\n .sort((a, b) => a.tokens - b.tokens);\n\n for (const item of sortedByFit) {\n const myShare = remainingWeight > 0\n ? (item.part.weight / remainingWeight) * remaining\n : 0;\n const grant = Math.min(item.tokens, Math.floor(myShare));\n allocations.set(item.key, grant);\n remaining -= grant;\n remainingWeight -= item.part.weight;\n }\n\n return parts.map((p) => {\n const allocated = allocations.get(p.key) ?? 0;\n const truncated = truncateToTokens(p.text, {\n maxTokens: allocated,\n mode: p.mode ?? \"head\",\n });\n return {\n key: p.key,\n text: truncated.text,\n truncated: truncated.truncated,\n estimatedTokens: truncated.estimatedTokens,\n originalTokens: truncated.originalTokens,\n allocatedTokens: allocated,\n };\n });\n}\n","import { mkdir, readFile, readdir, writeFile } from \"node:fs/promises\";\nimport { existsSync } from \"node:fs\";\nimport path from \"node:path\";\nimport type { HaivePaths } from \"./paths.js\";\n\nexport const CODE_MAP_FILE = \"code-map.json\";\n\nexport type CodeExportKind =\n | \"function\"\n | \"class\"\n | \"interface\"\n | \"type\"\n | \"const\"\n | \"enum\"\n | \"default\";\n\nexport interface CodeExport {\n name: string;\n kind: CodeExportKind;\n description?: string;\n line: number;\n}\n\nexport interface CodeFileEntry {\n summary?: string;\n exports: CodeExport[];\n loc: number;\n}\n\nexport interface CodeMap {\n version: 1;\n generated_at: string;\n root: string;\n files: Record<string, CodeFileEntry>;\n}\n\nexport interface BuildCodeMapOptions {\n includeExtensions?: string[];\n excludeDirs?: string[];\n}\n\nconst DEFAULT_INCLUDE = [\".ts\", \".tsx\", \".js\", \".jsx\", \".mjs\", \".cjs\"];\nconst DEFAULT_EXCLUDE = [\n \"node_modules\",\n \"dist\",\n \"build\",\n \"out\",\n \".git\",\n \".next\",\n \".turbo\",\n \".vitest-cache\",\n \"coverage\",\n];\n\nexport function codeMapPath(paths: HaivePaths): string {\n return path.join(paths.haiveDir, CODE_MAP_FILE);\n}\n\nexport async function loadCodeMap(paths: HaivePaths): Promise<CodeMap | null> {\n const file = codeMapPath(paths);\n if (!existsSync(file)) return null;\n return JSON.parse(await readFile(file, \"utf8\")) as CodeMap;\n}\n\nexport async function saveCodeMap(paths: HaivePaths, map: CodeMap): Promise<void> {\n const file = codeMapPath(paths);\n await mkdir(path.dirname(file), { recursive: true });\n await writeFile(file, JSON.stringify(map, null, 2), \"utf8\");\n}\n\nexport async function buildCodeMap(\n root: string,\n options: BuildCodeMapOptions = {},\n): Promise<CodeMap> {\n const include = new Set(options.includeExtensions ?? DEFAULT_INCLUDE);\n const exclude = new Set(options.excludeDirs ?? DEFAULT_EXCLUDE);\n const files: Record<string, CodeFileEntry> = {};\n\n for await (const abs of walkSourceFiles(root, include, exclude)) {\n const rel = path.relative(root, abs).replace(/\\\\/g, \"/\");\n if (rel.startsWith(\".ai/\")) continue;\n const content = await readFile(abs, \"utf8\");\n const entry = parseFile(content);\n if (entry.exports.length > 0) files[rel] = entry;\n }\n\n return {\n version: 1,\n generated_at: new Date().toISOString(),\n root,\n files,\n };\n}\n\nasync function* walkSourceFiles(\n dir: string,\n include: Set<string>,\n exclude: Set<string>,\n): AsyncGenerator<string> {\n let entries;\n try {\n entries = await readdir(dir, { withFileTypes: true });\n } catch {\n return;\n }\n for (const entry of entries) {\n if (entry.name.startsWith(\".\") && entry.name !== \".github\") {\n // Skip hidden dirs except .github (workflows can be useful)\n if (entry.isDirectory()) continue;\n }\n if (exclude.has(entry.name)) continue;\n const full = path.join(dir, entry.name);\n if (entry.isDirectory()) {\n yield* walkSourceFiles(full, include, exclude);\n } else if (entry.isFile()) {\n const ext = path.extname(entry.name).toLowerCase();\n if (include.has(ext)) yield full;\n }\n }\n}\n\nconst EXPORT_RE =\n /^export\\s+(?:default\\s+)?(async\\s+)?(function|class|interface|type|const|let|var|enum)\\s+(\\*?)\\s*([A-Za-z_$][\\w$]*)/gm;\n\nconst NAMED_REEXPORT_RE = /^export\\s*\\{([^}]+)\\}/gm;\n\nconst FILE_HEADER_COMMENT_RE = /^\\/\\*\\*([\\s\\S]*?)\\*\\//;\n\nfunction parseFile(source: string): CodeFileEntry {\n const exports: CodeExport[] = [];\n const lines = source.split(\"\\n\");\n const lineOffsets = computeLineOffsets(source);\n\n let m: RegExpExecArray | null;\n EXPORT_RE.lastIndex = 0;\n while ((m = EXPORT_RE.exec(source))) {\n const kindRaw = m[2] ?? \"\";\n const name = m[4] ?? \"\";\n if (!name) continue;\n const kind: CodeExportKind =\n kindRaw === \"function\" ? \"function\" :\n kindRaw === \"class\" ? \"class\" :\n kindRaw === \"interface\" ? \"interface\" :\n kindRaw === \"type\" ? \"type\" :\n kindRaw === \"enum\" ? \"enum\" : \"const\";\n const lineIdx = byteToLine(m.index, lineOffsets);\n const description = extractJSDocAbove(lines, lineIdx);\n exports.push({\n name,\n kind,\n ...(description ? { description } : {}),\n line: lineIdx + 1,\n });\n }\n\n NAMED_REEXPORT_RE.lastIndex = 0;\n while ((m = NAMED_REEXPORT_RE.exec(source))) {\n const inside = m[1] ?? \"\";\n const lineIdx = byteToLine(m.index, lineOffsets);\n for (const part of inside.split(\",\")) {\n const cleaned = part.trim().split(/\\s+as\\s+/).pop()?.trim() ?? \"\";\n if (!cleaned || cleaned.startsWith(\"type \")) continue;\n if (exports.some((e) => e.name === cleaned)) continue;\n exports.push({ name: cleaned, kind: \"const\", line: lineIdx + 1 });\n }\n }\n\n const summary = extractFileSummary(source);\n return {\n ...(summary ? { summary } : {}),\n exports,\n loc: lines.length,\n };\n}\n\nfunction computeLineOffsets(source: string): number[] {\n const out: number[] = [0];\n for (let i = 0; i < source.length; i++) {\n if (source[i] === \"\\n\") out.push(i + 1);\n }\n return out;\n}\n\nfunction byteToLine(byte: number, offsets: number[]): number {\n let lo = 0;\n let hi = offsets.length - 1;\n while (lo < hi) {\n const mid = (lo + hi + 1) >> 1;\n const off = offsets[mid] ?? 0;\n if (off <= byte) lo = mid;\n else hi = mid - 1;\n }\n return lo;\n}\n\nfunction extractJSDocAbove(lines: string[], exportLine: number): string | undefined {\n let i = exportLine - 1;\n // Skip blank lines between JSDoc and export\n while (i >= 0 && (lines[i] ?? \"\").trim() === \"\") i--;\n if (i < 0) return undefined;\n const line = (lines[i] ?? \"\").trim();\n\n if (line.startsWith(\"//\")) {\n return line.replace(/^\\/\\/\\s*/, \"\").trim() || undefined;\n }\n\n // Single-line JSDoc: /** Adds two numbers. */\n const singleLine = line.match(/^\\/\\*\\*\\s*(.*?)\\s*\\*\\/\\s*$/);\n if (singleLine && singleLine[1]) {\n return firstSentence(singleLine[1]);\n }\n\n if (line.endsWith(\"*/\")) {\n // Walk up until /**\n const collected: string[] = [];\n // First piece: content of the line before */\n const firstPiece = line.replace(/\\*\\/\\s*$/, \"\").replace(/^\\*\\s?/, \"\").trim();\n if (firstPiece) collected.unshift(firstPiece);\n let j = i - 1;\n while (j >= 0) {\n const l = (lines[j] ?? \"\").trim();\n if (l.startsWith(\"/**\")) {\n const inner = l.replace(/^\\/\\*\\*/, \"\").trim();\n if (inner) collected.unshift(inner);\n break;\n }\n collected.unshift(l.replace(/^\\*\\s?/, \"\").trim());\n j--;\n }\n const joined = collected.join(\" \").trim();\n if (!joined) return undefined;\n return firstSentence(joined);\n }\n return undefined;\n}\n\nfunction firstSentence(text: string): string | undefined {\n const trimmed = text.trim();\n if (!trimmed) return undefined;\n return trimmed.split(/(?<=\\.)\\s+/)[0]?.trim();\n}\n\nfunction extractFileSummary(source: string): string | undefined {\n const m = source.match(FILE_HEADER_COMMENT_RE);\n if (!m) return undefined;\n const block = (m[1] ?? \"\")\n .split(\"\\n\")\n .map((l) => l.replace(/^\\s*\\*\\s?/, \"\").trim())\n .filter(Boolean)\n .join(\" \");\n if (!block) return undefined;\n const sentence = block.split(/(?<=\\.)\\s+/)[0]?.trim();\n return sentence;\n}\n\nexport interface CodeMapQueryOptions {\n file?: string;\n symbol?: string;\n}\n\nexport function queryCodeMap(map: CodeMap, options: CodeMapQueryOptions): {\n files: Array<{ path: string; entry: CodeFileEntry }>;\n} {\n const files: Array<{ path: string; entry: CodeFileEntry }> = [];\n for (const [filePath, entry] of Object.entries(map.files)) {\n if (options.file) {\n if (!filePath.includes(options.file)) continue;\n }\n if (options.symbol) {\n const sym = options.symbol.toLowerCase();\n if (!entry.exports.some((e) => e.name.toLowerCase().includes(sym))) continue;\n }\n files.push({ path: filePath, entry });\n }\n return { files };\n}\n"],"mappings":";AAAA,SAAS,SAAS;AAEX,IAAM,oBAAoB,EAAE,KAAK,CAAC,YAAY,QAAQ,QAAQ,CAAC;AAE/D,IAAM,qBAAqB,EAAE,KAAK;AAAA,EACvC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAEM,IAAM,mBAAmB,EAAE,KAAK;AAAA,EACrC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAEM,IAAM,eAAe,EAAE,OAAO;AAAA,EACnC,QAAQ,EAAE,OAAO,EAAE,SAAS;AAAA,EAC5B,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,QAAQ,CAAC,CAAC;AAAA,EACrC,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,QAAQ,CAAC,CAAC;AACzC,CAAC;AAED,IAAM,gBAAgB,EACnB,MAAM,CAAC,EAAE,OAAO,GAAG,EAAE,KAAK,CAAC,CAAC,EAC5B,UAAU,CAAC,MAAO,aAAa,OAAO,EAAE,YAAY,IAAI,CAAE,EAC1D,KAAK,EAAE,OAAO,EAAE,SAAS,CAAC;AAEtB,IAAM,0BAA0B,EACpC,OAAO;AAAA,EACN,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC;AAAA,EACpB,OAAO,kBAAkB,QAAQ,UAAU;AAAA,EAC3C,QAAQ,EAAE,OAAO,EAAE,SAAS;AAAA,EAC5B,MAAM;AAAA,EACN,QAAQ,mBAAmB,QAAQ,OAAO;AAAA,EAC1C,Q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EAC7B;AACA,SAAO;AACT;AAEA,SAAS,cAAc,MAAkC;AACvD,QAAM,UAAU,KAAK,KAAK;AAC1B,MAAI,CAAC,QAAS,QAAO;AACrB,SAAO,QAAQ,MAAM,YAAY,EAAE,CAAC,GAAG,KAAK;AAC9C;AAEA,SAAS,mBAAmB,QAAoC;AAC9D,QAAM,IAAI,OAAO,MAAM,sBAAsB;AAC7C,MAAI,CAAC,EAAG,QAAO;AACf,QAAM,SAAS,EAAE,CAAC,KAAK,IACpB,MAAM,IAAI,EACV,IAAI,CAAC,MAAM,EAAE,QAAQ,aAAa,EAAE,EAAE,KAAK,CAAC,EAC5C,OAAO,OAAO,EACd,KAAK,GAAG;AACX,MAAI,CAAC,MAAO,QAAO;AACnB,QAAM,WAAW,MAAM,MAAM,YAAY,EAAE,CAAC,GAAG,KAAK;AACpD,SAAO;AACT;AAOO,SAAS,aAAa,KAAc,SAEzC;AACA,QAAM,QAAuD,CAAC;AAC9D,aAAW,CAAC,UAAU,KAAK,KAAK,OAAO,QAAQ,IAAI,KAAK,GAAG;AACzD,QAAI,QAAQ,MAAM;AAChB,UAAI,CAAC,SAAS,SAAS,QAAQ,IAAI,EAAG;AAAA,IACxC;AACA,QAAI,QAAQ,QAAQ;AAClB,YAAM,MAAM,QAAQ,OAAO,YAAY;AACvC,UAAI,CAAC,MAAM,QAAQ,KAAK,CAAC,MAAM,EAAE,KAAK,YAAY,EAAE,SAAS,GAAG,CAAC,EAAG;AAAA,IACtE;AACA,UAAM,KAAK,EAAE,MAAM,UAAU,MAAM,CAAC;AAAA,EACtC;AACA,SAAO,EAAE,MAAM;AACjB;","names":["path","path","readFile","existsSync","path","readFile","existsSync","path","path","mkdir","readFile","readdir","writeFile","existsSync","path"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hiveai/core",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "hAIve core — memory types, schema, parser, validator",
5
5
  "license": "MIT",
6
6
  "repository": {