@xdarkicex/openclaw-memory-libravdb 1.4.46 → 1.4.48

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
@@ -34419,824 +34419,324 @@ function isRecord(value) {
34419
34419
  import fs2 from "node:fs";
34420
34420
  import fsp2 from "node:fs/promises";
34421
34421
  import path2 from "node:path";
34422
- var DEFAULT_DEBOUNCE_MS2 = 150;
34423
- var DEFAULT_TOKENIZER_ID = "markdown-ingest:v1";
34424
- var MARKDOWN_INGEST_VERSION = 3;
34425
- var HASH_BACKEND = "wasm-fnv1a64";
34426
- function createMarkdownIngestionHandle(cfg, getRpc, logger = console, fsApi = createRealFsApi2()) {
34427
- const adapters = [];
34428
- const genericRoots = normalizeMarkdownRoots(cfg.markdownIngestionRoots);
34429
- if (isMarkdownIngestionEnabled(cfg, genericRoots)) {
34430
- adapters.push(
34431
- new DirectoryMarkdownSourceAdapter(
34432
- "generic",
34433
- {
34434
- roots: genericRoots,
34435
- include: cfg.markdownIngestionInclude,
34436
- exclude: cfg.markdownIngestionExclude,
34437
- debounceMs: cfg.markdownIngestionDebounceMs ?? DEFAULT_DEBOUNCE_MS2
34438
- },
34439
- getRpc,
34440
- logger,
34441
- fsApi
34442
- )
34443
- );
34422
+
34423
+ // node_modules/.pnpm/@bufbuild+protobuf@1.7.2/node_modules/@bufbuild/protobuf/dist/proxy/index.js
34424
+ var proxy_exports = {};
34425
+ __reExport(proxy_exports, __toESM(require_cjs(), 1));
34426
+
34427
+ // node_modules/.pnpm/@xdarkicex+libravdb-contracts@0.0.6/node_modules/@xdarkicex/libravdb-contracts/gen/js/libravdb/ipc/v1/rpc_pb.js
34428
+ var IngestMode;
34429
+ (function(IngestMode2) {
34430
+ IngestMode2[IngestMode2["REPLACE"] = 0] = "REPLACE";
34431
+ IngestMode2[IngestMode2["APPEND"] = 1] = "APPEND";
34432
+ })(IngestMode || (IngestMode = {}));
34433
+ proxy_exports.proto3.util.setEnumType(IngestMode, "libravdb.ipc.v1.IngestMode", [
34434
+ { no: 0, name: "INGEST_MODE_REPLACE" },
34435
+ { no: 1, name: "INGEST_MODE_APPEND" }
34436
+ ]);
34437
+ var RpcRequest = class _RpcRequest extends proxy_exports.Message {
34438
+ /**
34439
+ * @generated from field: uint64 id = 1;
34440
+ */
34441
+ id = proxy_exports.protoInt64.zero;
34442
+ /**
34443
+ * @generated from field: string method = 2;
34444
+ */
34445
+ method = "";
34446
+ /**
34447
+ * @generated from field: bytes params = 3;
34448
+ */
34449
+ params = new Uint8Array(0);
34450
+ constructor(data) {
34451
+ super();
34452
+ proxy_exports.proto3.util.initPartial(data, this);
34444
34453
  }
34445
- const obsidianRoots = normalizeMarkdownRoots(cfg.markdownIngestionObsidianRoots);
34446
- if (cfg.markdownIngestionObsidianEnabled !== false && obsidianRoots.length > 0) {
34447
- adapters.push(
34448
- new DirectoryMarkdownSourceAdapter(
34449
- "obsidian",
34450
- {
34451
- roots: obsidianRoots,
34452
- include: cfg.markdownIngestionObsidianInclude,
34453
- exclude: cfg.markdownIngestionObsidianExclude,
34454
- debounceMs: cfg.markdownIngestionObsidianDebounceMs ?? cfg.markdownIngestionDebounceMs ?? DEFAULT_DEBOUNCE_MS2
34455
- },
34456
- getRpc,
34457
- logger,
34458
- fsApi
34459
- )
34460
- );
34454
+ static runtime = proxy_exports.proto3;
34455
+ static typeName = "libravdb.ipc.v1.RpcRequest";
34456
+ static fields = proxy_exports.proto3.util.newFieldList(() => [
34457
+ {
34458
+ no: 1,
34459
+ name: "id",
34460
+ kind: "scalar",
34461
+ T: 4
34462
+ /* ScalarType.UINT64 */
34463
+ },
34464
+ {
34465
+ no: 2,
34466
+ name: "method",
34467
+ kind: "scalar",
34468
+ T: 9
34469
+ /* ScalarType.STRING */
34470
+ },
34471
+ {
34472
+ no: 3,
34473
+ name: "params",
34474
+ kind: "scalar",
34475
+ T: 12
34476
+ /* ScalarType.BYTES */
34477
+ }
34478
+ ]);
34479
+ static fromBinary(bytes, options) {
34480
+ return new _RpcRequest().fromBinary(bytes, options);
34461
34481
  }
34462
- if (adapters.length === 0) {
34463
- return {
34464
- async start() {
34465
- },
34466
- async refresh() {
34467
- },
34468
- async stop() {
34469
- }
34470
- };
34482
+ static fromJson(jsonValue, options) {
34483
+ return new _RpcRequest().fromJson(jsonValue, options);
34471
34484
  }
34472
- const adapter = new CompositeMarkdownSourceAdapter(adapters);
34473
- return {
34474
- start: () => adapter.start(),
34475
- refresh: () => adapter.refresh(),
34476
- stop: () => adapter.stop()
34477
- };
34478
- }
34479
- var CompositeMarkdownSourceAdapter = class {
34480
- constructor(adapters) {
34481
- this.adapters = adapters;
34485
+ static fromJsonString(jsonString, options) {
34486
+ return new _RpcRequest().fromJsonString(jsonString, options);
34482
34487
  }
34483
- adapters;
34484
- kind = "composite";
34485
- async start() {
34486
- for (const adapter of this.adapters) {
34487
- await adapter.start();
34488
- }
34488
+ static equals(a, b) {
34489
+ return proxy_exports.proto3.util.equals(_RpcRequest, a, b);
34489
34490
  }
34490
- async refresh() {
34491
- for (const adapter of this.adapters) {
34492
- await adapter.refresh();
34493
- }
34491
+ };
34492
+ var RpcResponse = class _RpcResponse extends proxy_exports.Message {
34493
+ /**
34494
+ * @generated from field: uint64 id = 1;
34495
+ */
34496
+ id = proxy_exports.protoInt64.zero;
34497
+ /**
34498
+ * @generated from field: bytes result = 2;
34499
+ */
34500
+ result = new Uint8Array(0);
34501
+ /**
34502
+ * @generated from field: libravdb.ipc.v1.RpcError error = 3;
34503
+ */
34504
+ error;
34505
+ constructor(data) {
34506
+ super();
34507
+ proxy_exports.proto3.util.initPartial(data, this);
34494
34508
  }
34495
- async stop() {
34496
- for (const adapter of this.adapters) {
34497
- await adapter.stop();
34498
- }
34509
+ static runtime = proxy_exports.proto3;
34510
+ static typeName = "libravdb.ipc.v1.RpcResponse";
34511
+ static fields = proxy_exports.proto3.util.newFieldList(() => [
34512
+ {
34513
+ no: 1,
34514
+ name: "id",
34515
+ kind: "scalar",
34516
+ T: 4
34517
+ /* ScalarType.UINT64 */
34518
+ },
34519
+ {
34520
+ no: 2,
34521
+ name: "result",
34522
+ kind: "scalar",
34523
+ T: 12
34524
+ /* ScalarType.BYTES */
34525
+ },
34526
+ { no: 3, name: "error", kind: "message", T: RpcError }
34527
+ ]);
34528
+ static fromBinary(bytes, options) {
34529
+ return new _RpcResponse().fromBinary(bytes, options);
34530
+ }
34531
+ static fromJson(jsonValue, options) {
34532
+ return new _RpcResponse().fromJson(jsonValue, options);
34533
+ }
34534
+ static fromJsonString(jsonString, options) {
34535
+ return new _RpcResponse().fromJsonString(jsonString, options);
34536
+ }
34537
+ static equals(a, b) {
34538
+ return proxy_exports.proto3.util.equals(_RpcResponse, a, b);
34499
34539
  }
34500
34540
  };
34501
- var DirectoryMarkdownSourceAdapter = class {
34502
- kind;
34503
- roots;
34504
- includePatterns;
34505
- excludePatterns;
34506
- debounceMs;
34507
- fsApi;
34508
- getRpc;
34509
- logger;
34510
- states = /* @__PURE__ */ new Map();
34511
- fileStates = /* @__PURE__ */ new Map();
34512
- activeScans = /* @__PURE__ */ new Set();
34513
- tokenizerId;
34514
- coreDoc;
34515
- started = false;
34516
- stopping = false;
34517
- constructor(kind, config, getRpc, logger, fsApi) {
34518
- this.kind = kind;
34519
- this.roots = config.roots;
34520
- this.includePatterns = config.include?.length ? config.include : [];
34521
- this.excludePatterns = config.exclude?.length ? config.exclude : [];
34522
- this.debounceMs = config.debounceMs ?? DEFAULT_DEBOUNCE_MS2;
34523
- this.fsApi = fsApi;
34524
- this.getRpc = getRpc;
34525
- this.logger = logger;
34526
- this.tokenizerId = DEFAULT_TOKENIZER_ID;
34527
- this.coreDoc = true;
34541
+ var RpcError = class _RpcError extends proxy_exports.Message {
34542
+ /**
34543
+ * @generated from field: string message = 1;
34544
+ */
34545
+ message = "";
34546
+ /**
34547
+ * @generated from field: int32 code = 2;
34548
+ */
34549
+ code = 0;
34550
+ constructor(data) {
34551
+ super();
34552
+ proxy_exports.proto3.util.initPartial(data, this);
34528
34553
  }
34529
- async start() {
34530
- if (this.started) {
34531
- return;
34554
+ static runtime = proxy_exports.proto3;
34555
+ static typeName = "libravdb.ipc.v1.RpcError";
34556
+ static fields = proxy_exports.proto3.util.newFieldList(() => [
34557
+ {
34558
+ no: 1,
34559
+ name: "message",
34560
+ kind: "scalar",
34561
+ T: 9
34562
+ /* ScalarType.STRING */
34563
+ },
34564
+ {
34565
+ no: 2,
34566
+ name: "code",
34567
+ kind: "scalar",
34568
+ T: 5
34569
+ /* ScalarType.INT32 */
34532
34570
  }
34533
- this.started = true;
34534
- this.stopping = false;
34535
- await this.refresh();
34571
+ ]);
34572
+ static fromBinary(bytes, options) {
34573
+ return new _RpcError().fromBinary(bytes, options);
34536
34574
  }
34537
- async refresh() {
34538
- if (!this.started || this.stopping) {
34539
- return;
34540
- }
34541
- for (const root of this.roots) {
34542
- await this.scanRoot(root);
34543
- }
34575
+ static fromJson(jsonValue, options) {
34576
+ return new _RpcError().fromJson(jsonValue, options);
34544
34577
  }
34545
- async stop() {
34546
- this.stopping = true;
34547
- for (const state of this.states.values()) {
34548
- if (state.scanState.timer) {
34549
- clearTimeout(state.scanState.timer);
34550
- state.scanState.timer = null;
34551
- }
34552
- for (const watcher of state.directoryWatchers.values()) {
34553
- watcher.close();
34554
- }
34555
- state.directoryWatchers.clear();
34556
- }
34557
- if (this.activeScans.size > 0) {
34558
- await Promise.allSettled([...this.activeScans]);
34559
- }
34560
- this.states.clear();
34561
- this.fileStates.clear();
34562
- this.started = false;
34578
+ static fromJsonString(jsonString, options) {
34579
+ return new _RpcError().fromJsonString(jsonString, options);
34563
34580
  }
34564
- getRootState(root) {
34565
- const resolved = path2.resolve(root);
34566
- const existing = this.states.get(resolved);
34567
- if (existing) {
34568
- return existing;
34569
- }
34570
- const created = {
34571
- root: resolved,
34572
- scanState: {
34573
- scanning: false,
34574
- dirty: false,
34575
- timer: null
34576
- },
34577
- knownFiles: /* @__PURE__ */ new Set(),
34578
- directoryWatchers: /* @__PURE__ */ new Map()
34579
- };
34580
- this.states.set(resolved, created);
34581
- return created;
34581
+ static equals(a, b) {
34582
+ return proxy_exports.proto3.util.equals(_RpcError, a, b);
34582
34583
  }
34583
- async scanRoot(root) {
34584
- if (!this.started || this.stopping) {
34585
- return;
34586
- }
34587
- const rootState = this.getRootState(root);
34588
- if (rootState.scanState.scanning) {
34589
- rootState.scanState.dirty = true;
34590
- return;
34591
- }
34592
- rootState.scanState.scanning = true;
34593
- const scan = (async () => {
34594
- try {
34595
- const currentFiles = /* @__PURE__ */ new Set();
34596
- await this.walkDirectory(rootState, rootState.root, currentFiles);
34597
- if (!this.stopping) {
34598
- await this.pruneDeletedFiles(rootState, currentFiles);
34599
- rootState.knownFiles = currentFiles;
34600
- }
34601
- } finally {
34602
- rootState.scanState.scanning = false;
34603
- if (rootState.scanState.dirty) {
34604
- rootState.scanState.dirty = false;
34605
- if (!this.stopping) {
34606
- this.scheduleRootScan(rootState);
34607
- }
34608
- }
34609
- }
34610
- })();
34611
- this.activeScans.add(scan);
34612
- try {
34613
- await scan;
34614
- } finally {
34615
- this.activeScans.delete(scan);
34616
- }
34584
+ };
34585
+ var StringList = class _StringList extends proxy_exports.Message {
34586
+ /**
34587
+ * @generated from field: repeated string values = 1;
34588
+ */
34589
+ values = [];
34590
+ constructor(data) {
34591
+ super();
34592
+ proxy_exports.proto3.util.initPartial(data, this);
34617
34593
  }
34618
- scheduleRootScan(rootState) {
34619
- if (!this.started || this.stopping) {
34620
- return;
34621
- }
34622
- if (rootState.scanState.scanning) {
34623
- rootState.scanState.dirty = true;
34624
- return;
34625
- }
34626
- if (rootState.scanState.timer) {
34627
- return;
34628
- }
34629
- rootState.scanState.timer = setTimeout(() => {
34630
- rootState.scanState.timer = null;
34631
- void this.scanRoot(rootState.root).catch((error) => {
34632
- this.logger.warn?.(`[markdown-ingest] root scan failed for ${rootState.root}: ${formatError(error)}`);
34633
- });
34634
- }, this.debounceMs);
34594
+ static runtime = proxy_exports.proto3;
34595
+ static typeName = "libravdb.ipc.v1.StringList";
34596
+ static fields = proxy_exports.proto3.util.newFieldList(() => [
34597
+ { no: 1, name: "values", kind: "scalar", T: 9, repeated: true }
34598
+ ]);
34599
+ static fromBinary(bytes, options) {
34600
+ return new _StringList().fromBinary(bytes, options);
34635
34601
  }
34636
- async walkDirectory(rootState, dir, currentFiles) {
34637
- await this.ensureDirectoryWatcher(rootState, dir);
34638
- let entries;
34639
- try {
34640
- entries = await this.fsApi.readdir(dir);
34641
- } catch (error) {
34642
- const message = formatError(error);
34643
- if (!message.includes("ENOENT")) {
34644
- this.logger.warn?.(`[markdown-ingest] readdir failed for ${dir}: ${message}`);
34645
- }
34646
- return;
34647
- }
34648
- for (const entry of entries) {
34649
- if (this.stopping) {
34650
- return;
34651
- }
34652
- const child = path2.join(dir, entry.name);
34653
- if (entry.isDirectory()) {
34654
- await this.walkDirectory(rootState, child, currentFiles);
34655
- continue;
34656
- }
34657
- if (!entry.isFile() || !isMarkdownFile(entry.name)) {
34658
- continue;
34659
- }
34660
- if (!this.shouldIncludeFile(rootState.root, child)) {
34661
- continue;
34662
- }
34663
- currentFiles.add(child);
34664
- try {
34665
- await this.syncMarkdownFile(rootState, child);
34666
- } catch (error) {
34667
- if (!this.stopping) {
34668
- this.logger.warn?.(`[markdown-ingest] sync failed for ${child}: ${formatError(error)}`);
34669
- }
34670
- }
34671
- }
34602
+ static fromJson(jsonValue, options) {
34603
+ return new _StringList().fromJson(jsonValue, options);
34672
34604
  }
34673
- async ensureDirectoryWatcher(rootState, dir) {
34674
- if (rootState.directoryWatchers.has(dir)) {
34675
- return;
34676
- }
34677
- try {
34678
- const watcher = this.fsApi.watch(dir, () => {
34679
- if (!this.stopping) {
34680
- this.scheduleRootScan(rootState);
34681
- }
34682
- });
34683
- watcher.on("error", (error) => {
34684
- this.logger.warn?.(`[markdown-ingest] watch error for ${dir}: ${formatError(error)}`);
34685
- });
34686
- rootState.directoryWatchers.set(dir, watcher);
34687
- } catch (error) {
34688
- this.logger.warn?.(`[markdown-ingest] watch unavailable for ${dir}: ${formatError(error)}`);
34689
- }
34605
+ static fromJsonString(jsonString, options) {
34606
+ return new _StringList().fromJsonString(jsonString, options);
34690
34607
  }
34691
- shouldIncludeFile(root, filePath) {
34692
- if (isOpenClawMemoryFile(filePath)) {
34693
- return true;
34694
- }
34695
- const relative = toPosixPath(path2.relative(root, filePath));
34696
- if (this.excludePatterns.length > 0) {
34697
- for (const pattern of this.excludePatterns) {
34698
- if (matchesGlob(relative, pattern)) {
34699
- return false;
34700
- }
34701
- }
34702
- }
34703
- if (this.includePatterns.length > 0) {
34704
- for (const pattern of this.includePatterns) {
34705
- if (matchesGlob(relative, pattern)) {
34706
- return true;
34707
- }
34708
- }
34709
- return false;
34710
- }
34711
- return true;
34608
+ static equals(a, b) {
34609
+ return proxy_exports.proto3.util.equals(_StringList, a, b);
34712
34610
  }
34713
- async pruneDeletedFiles(rootState, currentFiles) {
34714
- const removed = [];
34715
- for (const previous of rootState.knownFiles) {
34716
- if (!currentFiles.has(previous)) {
34717
- removed.push(previous);
34718
- }
34719
- }
34720
- if (removed.length === 0) {
34721
- return;
34722
- }
34723
- for (const filePath of removed) {
34724
- await this.deleteSourceDocument(filePath);
34725
- this.fileStates.delete(filePath);
34726
- }
34611
+ };
34612
+ var SearchResult = class _SearchResult extends proxy_exports.Message {
34613
+ /**
34614
+ * @generated from field: string id = 1;
34615
+ */
34616
+ id = "";
34617
+ /**
34618
+ * @generated from field: double score = 2;
34619
+ */
34620
+ score = 0;
34621
+ /**
34622
+ * @generated from field: string text = 3;
34623
+ */
34624
+ text = "";
34625
+ /**
34626
+ * @generated from field: google.protobuf.Struct metadata = 4;
34627
+ */
34628
+ metadata;
34629
+ /**
34630
+ * @generated from field: uint64 version = 5;
34631
+ */
34632
+ version = proxy_exports.protoInt64.zero;
34633
+ constructor(data) {
34634
+ super();
34635
+ proxy_exports.proto3.util.initPartial(data, this);
34727
34636
  }
34728
- async syncMarkdownFile(rootState, filePath) {
34729
- const sourceDoc = filePath;
34730
- const relativePath = toPosixPath(path2.relative(rootState.root, filePath));
34731
- const stat = await this.safeStat(filePath);
34732
- if (!stat) {
34733
- await this.deleteSourceDocument(sourceDoc);
34734
- this.fileStates.delete(sourceDoc);
34735
- return;
34637
+ static runtime = proxy_exports.proto3;
34638
+ static typeName = "libravdb.ipc.v1.SearchResult";
34639
+ static fields = proxy_exports.proto3.util.newFieldList(() => [
34640
+ {
34641
+ no: 1,
34642
+ name: "id",
34643
+ kind: "scalar",
34644
+ T: 9
34645
+ /* ScalarType.STRING */
34646
+ },
34647
+ {
34648
+ no: 2,
34649
+ name: "score",
34650
+ kind: "scalar",
34651
+ T: 1
34652
+ /* ScalarType.DOUBLE */
34653
+ },
34654
+ {
34655
+ no: 3,
34656
+ name: "text",
34657
+ kind: "scalar",
34658
+ T: 9
34659
+ /* ScalarType.STRING */
34660
+ },
34661
+ { no: 4, name: "metadata", kind: "message", T: proxy_exports.Struct },
34662
+ {
34663
+ no: 5,
34664
+ name: "version",
34665
+ kind: "scalar",
34666
+ T: 4
34667
+ /* ScalarType.UINT64 */
34736
34668
  }
34737
- const cached = this.fileStates.get(sourceDoc);
34738
- if (cached && cached.size === stat.size && cached.mtimeMs === stat.mtimeMs) {
34739
- return;
34740
- }
34741
- const bytes = await this.safeReadFile(filePath);
34742
- if (!bytes) {
34743
- await this.deleteSourceDocument(sourceDoc);
34744
- this.fileStates.delete(sourceDoc);
34745
- return;
34746
- }
34747
- const fileHash = hashBytes(bytes);
34748
- if (cached && cached.fileHash === fileHash) {
34749
- this.fileStates.set(sourceDoc, {
34750
- root: rootState.root,
34751
- sourceDoc,
34752
- relativePath,
34753
- fileHash,
34754
- size: stat.size,
34755
- mtimeMs: stat.mtimeMs
34756
- });
34757
- return;
34758
- }
34759
- const text = textDecoder2.decode(bytes);
34760
- if (this.kind === "obsidian" && this.includePatterns.length === 0 && !looksLikeObsidianNote(filePath, text)) {
34761
- await this.deleteSourceDocument(sourceDoc);
34762
- this.fileStates.delete(sourceDoc);
34763
- return;
34764
- }
34765
- await this.ingestMarkdownDocument(sourceDoc, text, rootState.root, relativePath, fileHash, stat.size, stat.mtimeMs);
34766
- this.fileStates.set(sourceDoc, {
34767
- root: rootState.root,
34768
- sourceDoc,
34769
- relativePath,
34770
- fileHash,
34771
- size: stat.size,
34772
- mtimeMs: stat.mtimeMs
34773
- });
34774
- }
34775
- async ingestMarkdownDocument(sourceDoc, text, sourceRoot, sourcePath, fileHash, sourceSize, sourceMtimeMs) {
34776
- const rpc = await this.getRpc();
34777
- const params = {
34778
- sourceDoc,
34779
- text,
34780
- tokenizerId: this.tokenizerId,
34781
- coreDoc: this.coreDoc,
34782
- sourceMeta: {
34783
- sourceRoot,
34784
- sourcePath,
34785
- sourceKind: this.kind,
34786
- fileHash,
34787
- sourceSize,
34788
- sourceMtimeMs: Math.trunc(sourceMtimeMs),
34789
- ingestVersion: MARKDOWN_INGEST_VERSION,
34790
- hashBackend: HASH_BACKEND
34791
- }
34792
- };
34793
- await rpc.call("ingest_markdown_document", params);
34669
+ ]);
34670
+ static fromBinary(bytes, options) {
34671
+ return new _SearchResult().fromBinary(bytes, options);
34794
34672
  }
34795
- async deleteSourceDocument(sourceDoc) {
34796
- const rpc = await this.getRpc();
34797
- const params = { sourceDoc };
34798
- await rpc.call("delete_authored_document", params);
34673
+ static fromJson(jsonValue, options) {
34674
+ return new _SearchResult().fromJson(jsonValue, options);
34799
34675
  }
34800
- async safeStat(filePath) {
34801
- try {
34802
- return await this.fsApi.stat(filePath);
34803
- } catch {
34804
- return null;
34805
- }
34676
+ static fromJsonString(jsonString, options) {
34677
+ return new _SearchResult().fromJsonString(jsonString, options);
34806
34678
  }
34807
- async safeReadFile(filePath) {
34808
- try {
34809
- return await this.fsApi.readFile(filePath);
34810
- } catch {
34811
- return null;
34812
- }
34679
+ static equals(a, b) {
34680
+ return proxy_exports.proto3.util.equals(_SearchResult, a, b);
34813
34681
  }
34814
34682
  };
34815
- function toPosixPath(value) {
34816
- return value.split(path2.sep).join("/");
34817
- }
34818
- var textDecoder2 = new TextDecoder();
34819
- function normalizeMarkdownRoots(roots) {
34820
- if (!roots?.length) {
34821
- return [];
34822
- }
34823
- const resolved = /* @__PURE__ */ new Set();
34824
- for (const root of roots) {
34825
- const trimmed = root.trim();
34826
- if (!trimmed) {
34827
- continue;
34828
- }
34829
- resolved.add(path2.resolve(trimmed));
34830
- }
34831
- return [...resolved];
34832
- }
34833
- function isMarkdownIngestionEnabled(cfg, roots) {
34834
- if (cfg.markdownIngestionEnabled === false) {
34835
- return false;
34836
- }
34837
- return roots.length > 0;
34838
- }
34839
- function createRealFsApi2() {
34840
- return {
34841
- readdir: async (dir) => fsp2.readdir(dir, { withFileTypes: true }),
34842
- readFile: async (file) => fsp2.readFile(file),
34843
- stat: async (file) => {
34844
- const stat = await fsp2.stat(file);
34845
- return { size: stat.size, mtimeMs: stat.mtimeMs };
34846
- },
34847
- watch: (dir, onChange) => fs2.watch(dir, onChange)
34848
- };
34849
- }
34850
- function isMarkdownFile(fileName) {
34851
- const lower = fileName.toLowerCase();
34852
- return lower.endsWith(".md") || lower.endsWith(".markdown");
34853
- }
34854
- function matchesGlob(value, pattern) {
34855
- const escaped = pattern.split("*").map((part) => part.replace(/[.+?^${}()|[\]\\]/g, "\\$&")).join(".*");
34856
- return new RegExp(`^${escaped}$`).test(value);
34857
- }
34858
- function looksLikeObsidianNote(filePath, text) {
34859
- if (!text.startsWith("---\n")) {
34860
- return hasInlineObsidianTag(text);
34861
- }
34862
- const frontmatterEnd = findFrontmatterEnd(text, 4);
34863
- if (frontmatterEnd < 0) {
34864
- return hasInlineObsidianTag(text);
34865
- }
34866
- const frontmatter = text.slice(4, frontmatterEnd);
34867
- const lines = frontmatter.split("\n");
34868
- for (const line of lines) {
34869
- const trimmed = line.trimStart();
34870
- if (trimmed.startsWith("tags:") || trimmed.startsWith("tag:") || trimmed.startsWith("openclaw:") || trimmed.startsWith("memory:")) {
34871
- return true;
34872
- }
34873
- }
34874
- return hasInlineObsidianTag(text.slice(frontmatterEnd + 4));
34875
- }
34876
- function findFrontmatterEnd(text, offset) {
34877
- for (let i = offset; i < text.length - 3; i++) {
34878
- if (text.charCodeAt(i) !== 45 || text.charCodeAt(i + 1) !== 45 || text.charCodeAt(i + 2) !== 45) {
34879
- continue;
34880
- }
34881
- const next = text.charCodeAt(i + 3);
34882
- if (next === 10) {
34883
- return i;
34884
- }
34885
- if (next === 13 && text.charCodeAt(i + 4) === 10) {
34886
- return i;
34887
- }
34888
- }
34889
- return -1;
34890
- }
34891
- function hasInlineObsidianTag(text) {
34892
- let inFence = false;
34893
- const lines = text.split("\n");
34894
- for (const line of lines) {
34895
- const trimmed = line.trimStart();
34896
- if (trimmed.startsWith("```") || trimmed.startsWith("~~~")) {
34897
- inFence = !inFence;
34898
- continue;
34899
- }
34900
- if (inFence) {
34901
- continue;
34902
- }
34903
- if (trimmed.startsWith("#")) {
34904
- continue;
34905
- }
34906
- if (/(^|[^A-Za-z0-9_])#([A-Za-z][A-Za-z0-9/_-]*)\b/.test(line)) {
34907
- return true;
34908
- }
34909
- }
34910
- return false;
34911
- }
34912
- function isOpenClawMemoryFile(filePath) {
34913
- return path2.basename(filePath).toLowerCase() === "memory.md";
34914
- }
34915
-
34916
- // src/memory-provider.ts
34917
- var MEMORY_PROMPT_HEADER = [
34918
- "## Memory",
34919
- "LibraVDB persistent memory is configured. Recalled memories may appear",
34920
- "in context via the context-engine assembler when available and relevant.",
34921
- ""
34922
- ];
34923
- function buildMemoryPromptSection(_getRpc, _cfg) {
34924
- return function memoryPromptSection({
34925
- availableTools: _availableTools,
34926
- citationsMode: _citationsMode
34927
- }) {
34928
- return [...MEMORY_PROMPT_HEADER];
34929
- };
34930
- }
34931
-
34932
- // node_modules/.pnpm/@bufbuild+protobuf@1.7.2/node_modules/@bufbuild/protobuf/dist/proxy/index.js
34933
- var proxy_exports = {};
34934
- __reExport(proxy_exports, __toESM(require_cjs(), 1));
34935
-
34936
- // node_modules/.pnpm/@xdarkicex+libravdb-contracts@0.0.1/node_modules/@xdarkicex/libravdb-contracts/gen/js/libravdb/ipc/v1/rpc_pb.js
34937
- var RpcRequest = class _RpcRequest extends proxy_exports.Message {
34683
+ var MarkdownSourceMeta = class _MarkdownSourceMeta extends proxy_exports.Message {
34938
34684
  /**
34939
- * @generated from field: uint64 id = 1;
34685
+ * @generated from field: string source_root = 1;
34940
34686
  */
34941
- id = proxy_exports.protoInt64.zero;
34687
+ sourceRoot = "";
34942
34688
  /**
34943
- * @generated from field: string method = 2;
34689
+ * @generated from field: string source_path = 2;
34944
34690
  */
34945
- method = "";
34691
+ sourcePath = "";
34946
34692
  /**
34947
- * @generated from field: bytes params = 3;
34693
+ * @generated from field: string source_kind = 3;
34948
34694
  */
34949
- params = new Uint8Array(0);
34695
+ sourceKind = "";
34696
+ /**
34697
+ * @generated from field: string file_hash = 4;
34698
+ */
34699
+ fileHash = "";
34700
+ /**
34701
+ * @generated from field: int64 source_size = 5;
34702
+ */
34703
+ sourceSize = proxy_exports.protoInt64.zero;
34704
+ /**
34705
+ * @generated from field: int64 source_mtime_ms = 6;
34706
+ */
34707
+ sourceMtimeMs = proxy_exports.protoInt64.zero;
34708
+ /**
34709
+ * @generated from field: int32 ingest_version = 7;
34710
+ */
34711
+ ingestVersion = 0;
34712
+ /**
34713
+ * @generated from field: string hash_backend = 8;
34714
+ */
34715
+ hashBackend = "";
34950
34716
  constructor(data) {
34951
34717
  super();
34952
34718
  proxy_exports.proto3.util.initPartial(data, this);
34953
34719
  }
34954
34720
  static runtime = proxy_exports.proto3;
34955
- static typeName = "libravdb.ipc.v1.RpcRequest";
34721
+ static typeName = "libravdb.ipc.v1.MarkdownSourceMeta";
34956
34722
  static fields = proxy_exports.proto3.util.newFieldList(() => [
34957
34723
  {
34958
34724
  no: 1,
34959
- name: "id",
34725
+ name: "source_root",
34960
34726
  kind: "scalar",
34961
- T: 4
34962
- /* ScalarType.UINT64 */
34727
+ T: 9
34728
+ /* ScalarType.STRING */
34963
34729
  },
34964
34730
  {
34965
34731
  no: 2,
34966
- name: "method",
34732
+ name: "source_path",
34967
34733
  kind: "scalar",
34968
34734
  T: 9
34969
34735
  /* ScalarType.STRING */
34970
34736
  },
34971
34737
  {
34972
34738
  no: 3,
34973
- name: "params",
34974
- kind: "scalar",
34975
- T: 12
34976
- /* ScalarType.BYTES */
34977
- }
34978
- ]);
34979
- static fromBinary(bytes, options) {
34980
- return new _RpcRequest().fromBinary(bytes, options);
34981
- }
34982
- static fromJson(jsonValue, options) {
34983
- return new _RpcRequest().fromJson(jsonValue, options);
34984
- }
34985
- static fromJsonString(jsonString, options) {
34986
- return new _RpcRequest().fromJsonString(jsonString, options);
34987
- }
34988
- static equals(a, b) {
34989
- return proxy_exports.proto3.util.equals(_RpcRequest, a, b);
34990
- }
34991
- };
34992
- var RpcResponse = class _RpcResponse extends proxy_exports.Message {
34993
- /**
34994
- * @generated from field: uint64 id = 1;
34995
- */
34996
- id = proxy_exports.protoInt64.zero;
34997
- /**
34998
- * @generated from field: bytes result = 2;
34999
- */
35000
- result = new Uint8Array(0);
35001
- /**
35002
- * @generated from field: libravdb.ipc.v1.RpcError error = 3;
35003
- */
35004
- error;
35005
- constructor(data) {
35006
- super();
35007
- proxy_exports.proto3.util.initPartial(data, this);
35008
- }
35009
- static runtime = proxy_exports.proto3;
35010
- static typeName = "libravdb.ipc.v1.RpcResponse";
35011
- static fields = proxy_exports.proto3.util.newFieldList(() => [
35012
- {
35013
- no: 1,
35014
- name: "id",
35015
- kind: "scalar",
35016
- T: 4
35017
- /* ScalarType.UINT64 */
35018
- },
35019
- {
35020
- no: 2,
35021
- name: "result",
35022
- kind: "scalar",
35023
- T: 12
35024
- /* ScalarType.BYTES */
35025
- },
35026
- { no: 3, name: "error", kind: "message", T: RpcError }
35027
- ]);
35028
- static fromBinary(bytes, options) {
35029
- return new _RpcResponse().fromBinary(bytes, options);
35030
- }
35031
- static fromJson(jsonValue, options) {
35032
- return new _RpcResponse().fromJson(jsonValue, options);
35033
- }
35034
- static fromJsonString(jsonString, options) {
35035
- return new _RpcResponse().fromJsonString(jsonString, options);
35036
- }
35037
- static equals(a, b) {
35038
- return proxy_exports.proto3.util.equals(_RpcResponse, a, b);
35039
- }
35040
- };
35041
- var RpcError = class _RpcError extends proxy_exports.Message {
35042
- /**
35043
- * @generated from field: string message = 1;
35044
- */
35045
- message = "";
35046
- /**
35047
- * @generated from field: int32 code = 2;
35048
- */
35049
- code = 0;
35050
- constructor(data) {
35051
- super();
35052
- proxy_exports.proto3.util.initPartial(data, this);
35053
- }
35054
- static runtime = proxy_exports.proto3;
35055
- static typeName = "libravdb.ipc.v1.RpcError";
35056
- static fields = proxy_exports.proto3.util.newFieldList(() => [
35057
- {
35058
- no: 1,
35059
- name: "message",
35060
- kind: "scalar",
35061
- T: 9
35062
- /* ScalarType.STRING */
35063
- },
35064
- {
35065
- no: 2,
35066
- name: "code",
35067
- kind: "scalar",
35068
- T: 5
35069
- /* ScalarType.INT32 */
35070
- }
35071
- ]);
35072
- static fromBinary(bytes, options) {
35073
- return new _RpcError().fromBinary(bytes, options);
35074
- }
35075
- static fromJson(jsonValue, options) {
35076
- return new _RpcError().fromJson(jsonValue, options);
35077
- }
35078
- static fromJsonString(jsonString, options) {
35079
- return new _RpcError().fromJsonString(jsonString, options);
35080
- }
35081
- static equals(a, b) {
35082
- return proxy_exports.proto3.util.equals(_RpcError, a, b);
35083
- }
35084
- };
35085
- var StringList = class _StringList extends proxy_exports.Message {
35086
- /**
35087
- * @generated from field: repeated string values = 1;
35088
- */
35089
- values = [];
35090
- constructor(data) {
35091
- super();
35092
- proxy_exports.proto3.util.initPartial(data, this);
35093
- }
35094
- static runtime = proxy_exports.proto3;
35095
- static typeName = "libravdb.ipc.v1.StringList";
35096
- static fields = proxy_exports.proto3.util.newFieldList(() => [
35097
- { no: 1, name: "values", kind: "scalar", T: 9, repeated: true }
35098
- ]);
35099
- static fromBinary(bytes, options) {
35100
- return new _StringList().fromBinary(bytes, options);
35101
- }
35102
- static fromJson(jsonValue, options) {
35103
- return new _StringList().fromJson(jsonValue, options);
35104
- }
35105
- static fromJsonString(jsonString, options) {
35106
- return new _StringList().fromJsonString(jsonString, options);
35107
- }
35108
- static equals(a, b) {
35109
- return proxy_exports.proto3.util.equals(_StringList, a, b);
35110
- }
35111
- };
35112
- var SearchResult = class _SearchResult extends proxy_exports.Message {
35113
- /**
35114
- * @generated from field: string id = 1;
35115
- */
35116
- id = "";
35117
- /**
35118
- * @generated from field: double score = 2;
35119
- */
35120
- score = 0;
35121
- /**
35122
- * @generated from field: string text = 3;
35123
- */
35124
- text = "";
35125
- /**
35126
- * @generated from field: google.protobuf.Struct metadata = 4;
35127
- */
35128
- metadata;
35129
- /**
35130
- * @generated from field: uint64 version = 5;
35131
- */
35132
- version = proxy_exports.protoInt64.zero;
35133
- constructor(data) {
35134
- super();
35135
- proxy_exports.proto3.util.initPartial(data, this);
35136
- }
35137
- static runtime = proxy_exports.proto3;
35138
- static typeName = "libravdb.ipc.v1.SearchResult";
35139
- static fields = proxy_exports.proto3.util.newFieldList(() => [
35140
- {
35141
- no: 1,
35142
- name: "id",
35143
- kind: "scalar",
35144
- T: 9
35145
- /* ScalarType.STRING */
35146
- },
35147
- {
35148
- no: 2,
35149
- name: "score",
35150
- kind: "scalar",
35151
- T: 1
35152
- /* ScalarType.DOUBLE */
35153
- },
35154
- {
35155
- no: 3,
35156
- name: "text",
35157
- kind: "scalar",
35158
- T: 9
35159
- /* ScalarType.STRING */
35160
- },
35161
- { no: 4, name: "metadata", kind: "message", T: proxy_exports.Struct },
35162
- {
35163
- no: 5,
35164
- name: "version",
35165
- kind: "scalar",
35166
- T: 4
35167
- /* ScalarType.UINT64 */
35168
- }
35169
- ]);
35170
- static fromBinary(bytes, options) {
35171
- return new _SearchResult().fromBinary(bytes, options);
35172
- }
35173
- static fromJson(jsonValue, options) {
35174
- return new _SearchResult().fromJson(jsonValue, options);
35175
- }
35176
- static fromJsonString(jsonString, options) {
35177
- return new _SearchResult().fromJsonString(jsonString, options);
35178
- }
35179
- static equals(a, b) {
35180
- return proxy_exports.proto3.util.equals(_SearchResult, a, b);
35181
- }
35182
- };
35183
- var MarkdownSourceMeta = class _MarkdownSourceMeta extends proxy_exports.Message {
35184
- /**
35185
- * @generated from field: string source_root = 1;
35186
- */
35187
- sourceRoot = "";
35188
- /**
35189
- * @generated from field: string source_path = 2;
35190
- */
35191
- sourcePath = "";
35192
- /**
35193
- * @generated from field: string source_kind = 3;
35194
- */
35195
- sourceKind = "";
35196
- /**
35197
- * @generated from field: string file_hash = 4;
35198
- */
35199
- fileHash = "";
35200
- /**
35201
- * @generated from field: int64 source_size = 5;
35202
- */
35203
- sourceSize = proxy_exports.protoInt64.zero;
35204
- /**
35205
- * @generated from field: int64 source_mtime_ms = 6;
35206
- */
35207
- sourceMtimeMs = proxy_exports.protoInt64.zero;
35208
- /**
35209
- * @generated from field: int32 ingest_version = 7;
35210
- */
35211
- ingestVersion = 0;
35212
- /**
35213
- * @generated from field: string hash_backend = 8;
35214
- */
35215
- hashBackend = "";
35216
- constructor(data) {
35217
- super();
35218
- proxy_exports.proto3.util.initPartial(data, this);
35219
- }
35220
- static runtime = proxy_exports.proto3;
35221
- static typeName = "libravdb.ipc.v1.MarkdownSourceMeta";
35222
- static fields = proxy_exports.proto3.util.newFieldList(() => [
35223
- {
35224
- no: 1,
35225
- name: "source_root",
35226
- kind: "scalar",
35227
- T: 9
35228
- /* ScalarType.STRING */
35229
- },
35230
- {
35231
- no: 2,
35232
- name: "source_path",
35233
- kind: "scalar",
35234
- T: 9
35235
- /* ScalarType.STRING */
35236
- },
35237
- {
35238
- no: 3,
35239
- name: "source_kind",
34739
+ name: "source_kind",
35240
34740
  kind: "scalar",
35241
34741
  T: 9
35242
34742
  /* ScalarType.STRING */
@@ -36512,6 +36012,12 @@ var IngestMarkdownDocumentRequest = class _IngestMarkdownDocumentRequest extends
36512
36012
  * @generated from field: libravdb.ipc.v1.MarkdownSourceMeta source_meta = 5;
36513
36013
  */
36514
36014
  sourceMeta;
36015
+ /**
36016
+ * default INGEST_MODE_REPLACE if absent
36017
+ *
36018
+ * @generated from field: libravdb.ipc.v1.IngestMode mode = 6;
36019
+ */
36020
+ mode = IngestMode.REPLACE;
36515
36021
  constructor(data) {
36516
36022
  super();
36517
36023
  proxy_exports.proto3.util.initPartial(data, this);
@@ -36547,7 +36053,8 @@ var IngestMarkdownDocumentRequest = class _IngestMarkdownDocumentRequest extends
36547
36053
  T: 8
36548
36054
  /* ScalarType.BOOL */
36549
36055
  },
36550
- { no: 5, name: "source_meta", kind: "message", T: MarkdownSourceMeta }
36056
+ { no: 5, name: "source_meta", kind: "message", T: MarkdownSourceMeta },
36057
+ { no: 6, name: "mode", kind: "enum", T: proxy_exports.proto3.getEnumType(IngestMode) }
36551
36058
  ]);
36552
36059
  static fromBinary(bytes, options) {
36553
36060
  return new _IngestMarkdownDocumentRequest().fromBinary(bytes, options);
@@ -38592,132 +38099,781 @@ var RankCandidatesRequest = class _RankCandidatesRequest extends proxy_exports.M
38592
38099
  static equals(a, b) {
38593
38100
  return proxy_exports.proto3.util.equals(_RankCandidatesRequest, a, b);
38594
38101
  }
38595
- };
38596
- var RankCandidatesResponse = class _RankCandidatesResponse extends proxy_exports.Message {
38597
- /**
38598
- * @generated from field: repeated libravdb.ipc.v1.RankCandidate ranked = 1;
38599
- */
38600
- ranked = [];
38601
- constructor(data) {
38602
- super();
38603
- proxy_exports.proto3.util.initPartial(data, this);
38102
+ };
38103
+ var RankCandidatesResponse = class _RankCandidatesResponse extends proxy_exports.Message {
38104
+ /**
38105
+ * @generated from field: repeated libravdb.ipc.v1.RankCandidate ranked = 1;
38106
+ */
38107
+ ranked = [];
38108
+ constructor(data) {
38109
+ super();
38110
+ proxy_exports.proto3.util.initPartial(data, this);
38111
+ }
38112
+ static runtime = proxy_exports.proto3;
38113
+ static typeName = "libravdb.ipc.v1.RankCandidatesResponse";
38114
+ static fields = proxy_exports.proto3.util.newFieldList(() => [
38115
+ { no: 1, name: "ranked", kind: "message", T: RankCandidate, repeated: true }
38116
+ ]);
38117
+ static fromBinary(bytes, options) {
38118
+ return new _RankCandidatesResponse().fromBinary(bytes, options);
38119
+ }
38120
+ static fromJson(jsonValue, options) {
38121
+ return new _RankCandidatesResponse().fromJson(jsonValue, options);
38122
+ }
38123
+ static fromJsonString(jsonString, options) {
38124
+ return new _RankCandidatesResponse().fromJsonString(jsonString, options);
38125
+ }
38126
+ static equals(a, b) {
38127
+ return proxy_exports.proto3.util.equals(_RankCandidatesResponse, a, b);
38128
+ }
38129
+ };
38130
+ var RebuildIndexRequest = class _RebuildIndexRequest extends proxy_exports.Message {
38131
+ /**
38132
+ * @generated from field: string namespace = 1;
38133
+ */
38134
+ namespace = "";
38135
+ /**
38136
+ * @generated from field: repeated string collections = 2;
38137
+ */
38138
+ collections = [];
38139
+ constructor(data) {
38140
+ super();
38141
+ proxy_exports.proto3.util.initPartial(data, this);
38142
+ }
38143
+ static runtime = proxy_exports.proto3;
38144
+ static typeName = "libravdb.ipc.v1.RebuildIndexRequest";
38145
+ static fields = proxy_exports.proto3.util.newFieldList(() => [
38146
+ {
38147
+ no: 1,
38148
+ name: "namespace",
38149
+ kind: "scalar",
38150
+ T: 9
38151
+ /* ScalarType.STRING */
38152
+ },
38153
+ { no: 2, name: "collections", kind: "scalar", T: 9, repeated: true }
38154
+ ]);
38155
+ static fromBinary(bytes, options) {
38156
+ return new _RebuildIndexRequest().fromBinary(bytes, options);
38157
+ }
38158
+ static fromJson(jsonValue, options) {
38159
+ return new _RebuildIndexRequest().fromJson(jsonValue, options);
38160
+ }
38161
+ static fromJsonString(jsonString, options) {
38162
+ return new _RebuildIndexRequest().fromJsonString(jsonString, options);
38163
+ }
38164
+ static equals(a, b) {
38165
+ return proxy_exports.proto3.util.equals(_RebuildIndexRequest, a, b);
38166
+ }
38167
+ };
38168
+ var RebuildIndexResponse = class _RebuildIndexResponse extends proxy_exports.Message {
38169
+ /**
38170
+ * @generated from field: int32 collections_processed = 1;
38171
+ */
38172
+ collectionsProcessed = 0;
38173
+ /**
38174
+ * @generated from field: int32 records_reindexed = 2;
38175
+ */
38176
+ recordsReindexed = 0;
38177
+ /**
38178
+ * @generated from field: int32 collections_recreated = 3;
38179
+ */
38180
+ collectionsRecreated = 0;
38181
+ /**
38182
+ * @generated from field: repeated string errors = 4;
38183
+ */
38184
+ errors = [];
38185
+ constructor(data) {
38186
+ super();
38187
+ proxy_exports.proto3.util.initPartial(data, this);
38188
+ }
38189
+ static runtime = proxy_exports.proto3;
38190
+ static typeName = "libravdb.ipc.v1.RebuildIndexResponse";
38191
+ static fields = proxy_exports.proto3.util.newFieldList(() => [
38192
+ {
38193
+ no: 1,
38194
+ name: "collections_processed",
38195
+ kind: "scalar",
38196
+ T: 5
38197
+ /* ScalarType.INT32 */
38198
+ },
38199
+ {
38200
+ no: 2,
38201
+ name: "records_reindexed",
38202
+ kind: "scalar",
38203
+ T: 5
38204
+ /* ScalarType.INT32 */
38205
+ },
38206
+ {
38207
+ no: 3,
38208
+ name: "collections_recreated",
38209
+ kind: "scalar",
38210
+ T: 5
38211
+ /* ScalarType.INT32 */
38212
+ },
38213
+ { no: 4, name: "errors", kind: "scalar", T: 9, repeated: true }
38214
+ ]);
38215
+ static fromBinary(bytes, options) {
38216
+ return new _RebuildIndexResponse().fromBinary(bytes, options);
38217
+ }
38218
+ static fromJson(jsonValue, options) {
38219
+ return new _RebuildIndexResponse().fromJson(jsonValue, options);
38220
+ }
38221
+ static fromJsonString(jsonString, options) {
38222
+ return new _RebuildIndexResponse().fromJsonString(jsonString, options);
38223
+ }
38224
+ static equals(a, b) {
38225
+ return proxy_exports.proto3.util.equals(_RebuildIndexResponse, a, b);
38226
+ }
38227
+ };
38228
+
38229
+ // src/ingest-queue.ts
38230
+ var DEFAULT_OPTIONS = {
38231
+ chunkTokens: 8192,
38232
+ retryBaseDelayMs: 500,
38233
+ maxRetries: 4
38234
+ };
38235
+ var IngestQueue = class {
38236
+ queue = [];
38237
+ rpcCall;
38238
+ logger;
38239
+ options;
38240
+ running = false;
38241
+ constructor(rpcCall, logger, options = {}) {
38242
+ this.rpcCall = rpcCall;
38243
+ this.logger = logger;
38244
+ this.options = { ...DEFAULT_OPTIONS, ...options };
38245
+ }
38246
+ async enqueueIngest(sourceDoc, text, baseParams) {
38247
+ if (this.options.chunkTokens === Infinity) {
38248
+ return this.ingestWithRetry({
38249
+ ...baseParams,
38250
+ sourceDoc,
38251
+ text,
38252
+ mode: IngestMode.REPLACE
38253
+ });
38254
+ }
38255
+ const chunks = splitIntoChunks(text, this.options.chunkTokens);
38256
+ if (chunks.length === 1) {
38257
+ return this.ingestWithRetry({
38258
+ ...baseParams,
38259
+ sourceDoc,
38260
+ text: chunks[0].text,
38261
+ mode: IngestMode.REPLACE
38262
+ });
38263
+ }
38264
+ for (let i = 0; i < chunks.length; i++) {
38265
+ const isFirst = i === 0;
38266
+ const chunkParams = {
38267
+ ...baseParams,
38268
+ sourceDoc,
38269
+ text: chunks[i].text,
38270
+ mode: isFirst ? IngestMode.REPLACE : IngestMode.APPEND
38271
+ };
38272
+ await this.ingestWithRetry(chunkParams);
38273
+ }
38274
+ }
38275
+ async ingestWithRetry(params) {
38276
+ await withRetry(
38277
+ () => this.rpcCall("ingest_markdown_document", params),
38278
+ this.options.maxRetries,
38279
+ this.options.retryBaseDelayMs,
38280
+ this.logger,
38281
+ `ingest_markdown_document(${params.sourceDoc})`
38282
+ );
38283
+ }
38284
+ async enqueueDelete(sourceDoc) {
38285
+ await withRetry(
38286
+ () => this.rpcCall("delete_authored_document", { sourceDoc }),
38287
+ this.options.maxRetries,
38288
+ this.options.retryBaseDelayMs,
38289
+ this.logger,
38290
+ `delete_authored_document(${sourceDoc})`
38291
+ );
38292
+ }
38293
+ };
38294
+ function splitIntoChunks(text, maxTokens) {
38295
+ const maxChars = maxTokens * 4;
38296
+ if (text.length <= maxChars) {
38297
+ return [{ text, ordinal: 0 }];
38298
+ }
38299
+ const chunks = [];
38300
+ let offset = 0;
38301
+ let ordinal = 0;
38302
+ while (offset < text.length) {
38303
+ let end = Math.min(offset + maxChars, text.length);
38304
+ const probeLimit = Math.min(256, end - offset);
38305
+ let hardCut = end;
38306
+ for (let i = 0; i < probeLimit; i++) {
38307
+ const pos = end - i;
38308
+ const ch = text.charAt(pos);
38309
+ if (ch === "\n" && text.charAt(pos + 1) === "\n") {
38310
+ hardCut = pos + 2;
38311
+ break;
38312
+ }
38313
+ }
38314
+ if (hardCut === end) {
38315
+ for (let i = 0; i < probeLimit; i++) {
38316
+ const pos = end - i;
38317
+ if (text.charAt(pos) === "\n") {
38318
+ hardCut = pos + 1;
38319
+ break;
38320
+ }
38321
+ }
38322
+ }
38323
+ if (hardCut === end) {
38324
+ for (let i = 0; i < probeLimit; i++) {
38325
+ const pos = end - i;
38326
+ if (text.charAt(pos) === " ") {
38327
+ hardCut = pos;
38328
+ break;
38329
+ }
38330
+ }
38331
+ }
38332
+ chunks.push({ text: text.slice(offset, hardCut), ordinal });
38333
+ ordinal++;
38334
+ offset = hardCut;
38335
+ }
38336
+ return chunks;
38337
+ }
38338
+ async function withRetry(fn, maxRetries, baseDelayMs, logger, label) {
38339
+ let lastError;
38340
+ for (let attempt = 0; attempt <= maxRetries; attempt++) {
38341
+ try {
38342
+ return await fn();
38343
+ } catch (err) {
38344
+ lastError = err;
38345
+ if (attempt < maxRetries) {
38346
+ const cap = baseDelayMs * Math.pow(2, attempt);
38347
+ const delay = Math.random() * cap;
38348
+ logger.warn?.(`[ingest-queue] ${label} failed (attempt ${attempt + 1}/${maxRetries + 1}), retrying in ${Math.round(delay)}ms: ${err}`);
38349
+ await sleep(delay);
38350
+ }
38351
+ }
38352
+ }
38353
+ throw lastError instanceof Error ? lastError : new Error(String(lastError));
38354
+ }
38355
+ function sleep(ms) {
38356
+ return new Promise((resolve) => setTimeout(resolve, ms));
38357
+ }
38358
+
38359
+ // src/markdown-ingest.ts
38360
+ var DEFAULT_DEBOUNCE_MS2 = 150;
38361
+ var DEFAULT_TOKENIZER_ID = "markdown-ingest:v1";
38362
+ var MARKDOWN_INGEST_VERSION = 3;
38363
+ var HASH_BACKEND = "wasm-fnv1a64";
38364
+ function createMarkdownIngestionHandle(cfg, getRpc, logger = console, fsApi = createRealFsApi2()) {
38365
+ const adapters = [];
38366
+ const genericRoots = normalizeMarkdownRoots(cfg.markdownIngestionRoots);
38367
+ if (isMarkdownIngestionEnabled(cfg, genericRoots)) {
38368
+ adapters.push(
38369
+ new DirectoryMarkdownSourceAdapter(
38370
+ "generic",
38371
+ {
38372
+ roots: genericRoots,
38373
+ include: cfg.markdownIngestionInclude,
38374
+ exclude: cfg.markdownIngestionExclude,
38375
+ debounceMs: cfg.markdownIngestionDebounceMs ?? DEFAULT_DEBOUNCE_MS2
38376
+ },
38377
+ getRpc,
38378
+ logger,
38379
+ fsApi
38380
+ )
38381
+ );
38382
+ }
38383
+ const obsidianRoots = normalizeMarkdownRoots(cfg.markdownIngestionObsidianRoots);
38384
+ if (cfg.markdownIngestionObsidianEnabled !== false && obsidianRoots.length > 0) {
38385
+ adapters.push(
38386
+ new DirectoryMarkdownSourceAdapter(
38387
+ "obsidian",
38388
+ {
38389
+ roots: obsidianRoots,
38390
+ include: cfg.markdownIngestionObsidianInclude,
38391
+ exclude: cfg.markdownIngestionObsidianExclude,
38392
+ debounceMs: cfg.markdownIngestionObsidianDebounceMs ?? cfg.markdownIngestionDebounceMs ?? DEFAULT_DEBOUNCE_MS2
38393
+ },
38394
+ getRpc,
38395
+ logger,
38396
+ fsApi
38397
+ )
38398
+ );
38399
+ }
38400
+ if (adapters.length === 0) {
38401
+ return {
38402
+ async start() {
38403
+ },
38404
+ async refresh() {
38405
+ },
38406
+ async stop() {
38407
+ }
38408
+ };
38409
+ }
38410
+ const adapter = new CompositeMarkdownSourceAdapter(adapters);
38411
+ return {
38412
+ start: () => adapter.start(),
38413
+ refresh: () => adapter.refresh(),
38414
+ stop: () => adapter.stop()
38415
+ };
38416
+ }
38417
+ var CompositeMarkdownSourceAdapter = class {
38418
+ constructor(adapters) {
38419
+ this.adapters = adapters;
38420
+ }
38421
+ adapters;
38422
+ kind = "composite";
38423
+ async start() {
38424
+ for (const adapter of this.adapters) {
38425
+ await adapter.start();
38426
+ }
38427
+ }
38428
+ async refresh() {
38429
+ for (const adapter of this.adapters) {
38430
+ await adapter.refresh();
38431
+ }
38432
+ }
38433
+ async stop() {
38434
+ for (const adapter of this.adapters) {
38435
+ await adapter.stop();
38436
+ }
38437
+ }
38438
+ };
38439
+ var DirectoryMarkdownSourceAdapter = class {
38440
+ kind;
38441
+ roots;
38442
+ includePatterns;
38443
+ excludePatterns;
38444
+ debounceMs;
38445
+ fsApi;
38446
+ getRpc;
38447
+ logger;
38448
+ states = /* @__PURE__ */ new Map();
38449
+ fileStates = /* @__PURE__ */ new Map();
38450
+ activeScans = /* @__PURE__ */ new Set();
38451
+ tokenizerId;
38452
+ coreDoc;
38453
+ started = false;
38454
+ ingestQueue = null;
38455
+ stopping = false;
38456
+ constructor(kind, config, getRpc, logger, fsApi) {
38457
+ this.kind = kind;
38458
+ this.roots = config.roots;
38459
+ this.includePatterns = config.include?.length ? config.include : [];
38460
+ this.excludePatterns = config.exclude?.length ? config.exclude : [];
38461
+ this.debounceMs = config.debounceMs ?? DEFAULT_DEBOUNCE_MS2;
38462
+ this.fsApi = fsApi;
38463
+ this.getRpc = getRpc;
38464
+ this.logger = logger;
38465
+ this.tokenizerId = DEFAULT_TOKENIZER_ID;
38466
+ this.coreDoc = true;
38467
+ }
38468
+ async start() {
38469
+ if (this.started) {
38470
+ return;
38471
+ }
38472
+ this.started = true;
38473
+ this.stopping = false;
38474
+ await this.refresh();
38475
+ }
38476
+ async refresh() {
38477
+ if (!this.started || this.stopping) {
38478
+ return;
38479
+ }
38480
+ for (const root of this.roots) {
38481
+ await this.scanRoot(root);
38482
+ }
38483
+ }
38484
+ async stop() {
38485
+ this.stopping = true;
38486
+ for (const state of this.states.values()) {
38487
+ if (state.scanState.timer) {
38488
+ clearTimeout(state.scanState.timer);
38489
+ state.scanState.timer = null;
38490
+ }
38491
+ for (const watcher of state.directoryWatchers.values()) {
38492
+ watcher.close();
38493
+ }
38494
+ state.directoryWatchers.clear();
38495
+ }
38496
+ if (this.activeScans.size > 0) {
38497
+ await Promise.allSettled([...this.activeScans]);
38498
+ }
38499
+ this.states.clear();
38500
+ this.fileStates.clear();
38501
+ this.started = false;
38502
+ }
38503
+ getRootState(root) {
38504
+ const resolved = path2.resolve(root);
38505
+ const existing = this.states.get(resolved);
38506
+ if (existing) {
38507
+ return existing;
38508
+ }
38509
+ const created = {
38510
+ root: resolved,
38511
+ scanState: {
38512
+ scanning: false,
38513
+ dirty: false,
38514
+ timer: null
38515
+ },
38516
+ knownFiles: /* @__PURE__ */ new Set(),
38517
+ directoryWatchers: /* @__PURE__ */ new Map()
38518
+ };
38519
+ this.states.set(resolved, created);
38520
+ return created;
38521
+ }
38522
+ async scanRoot(root) {
38523
+ if (!this.started || this.stopping) {
38524
+ return;
38525
+ }
38526
+ const rootState = this.getRootState(root);
38527
+ if (rootState.scanState.scanning) {
38528
+ rootState.scanState.dirty = true;
38529
+ return;
38530
+ }
38531
+ rootState.scanState.scanning = true;
38532
+ const scan = (async () => {
38533
+ try {
38534
+ const currentFiles = /* @__PURE__ */ new Set();
38535
+ await this.walkDirectory(rootState, rootState.root, currentFiles);
38536
+ if (!this.stopping) {
38537
+ await this.pruneDeletedFiles(rootState, currentFiles);
38538
+ rootState.knownFiles = currentFiles;
38539
+ }
38540
+ } finally {
38541
+ rootState.scanState.scanning = false;
38542
+ if (rootState.scanState.dirty) {
38543
+ rootState.scanState.dirty = false;
38544
+ if (!this.stopping) {
38545
+ this.scheduleRootScan(rootState);
38546
+ }
38547
+ }
38548
+ }
38549
+ })();
38550
+ this.activeScans.add(scan);
38551
+ try {
38552
+ await scan;
38553
+ } finally {
38554
+ this.activeScans.delete(scan);
38555
+ }
38556
+ }
38557
+ scheduleRootScan(rootState) {
38558
+ if (!this.started || this.stopping) {
38559
+ return;
38560
+ }
38561
+ if (rootState.scanState.scanning) {
38562
+ rootState.scanState.dirty = true;
38563
+ return;
38564
+ }
38565
+ if (rootState.scanState.timer) {
38566
+ return;
38567
+ }
38568
+ rootState.scanState.timer = setTimeout(() => {
38569
+ rootState.scanState.timer = null;
38570
+ void this.scanRoot(rootState.root).catch((error) => {
38571
+ this.logger.warn?.(`[markdown-ingest] root scan failed for ${rootState.root}: ${formatError(error)}`);
38572
+ });
38573
+ }, this.debounceMs);
38574
+ }
38575
+ async walkDirectory(rootState, dir, currentFiles) {
38576
+ await this.ensureDirectoryWatcher(rootState, dir);
38577
+ let entries;
38578
+ try {
38579
+ entries = await this.fsApi.readdir(dir);
38580
+ } catch (error) {
38581
+ const message = formatError(error);
38582
+ if (!message.includes("ENOENT")) {
38583
+ this.logger.warn?.(`[markdown-ingest] readdir failed for ${dir}: ${message}`);
38584
+ }
38585
+ return;
38586
+ }
38587
+ for (const entry of entries) {
38588
+ if (this.stopping) {
38589
+ return;
38590
+ }
38591
+ const child = path2.join(dir, entry.name);
38592
+ if (entry.isDirectory()) {
38593
+ await this.walkDirectory(rootState, child, currentFiles);
38594
+ continue;
38595
+ }
38596
+ if (!entry.isFile() || !isMarkdownFile(entry.name)) {
38597
+ continue;
38598
+ }
38599
+ if (!this.shouldIncludeFile(rootState.root, child)) {
38600
+ continue;
38601
+ }
38602
+ currentFiles.add(child);
38603
+ try {
38604
+ await this.syncMarkdownFile(rootState, child);
38605
+ } catch (error) {
38606
+ if (!this.stopping) {
38607
+ this.logger.warn?.(`[markdown-ingest] sync failed for ${child}: ${formatError(error)}`);
38608
+ }
38609
+ }
38610
+ }
38611
+ }
38612
+ async ensureDirectoryWatcher(rootState, dir) {
38613
+ if (rootState.directoryWatchers.has(dir)) {
38614
+ return;
38615
+ }
38616
+ try {
38617
+ const watcher = this.fsApi.watch(dir, () => {
38618
+ if (!this.stopping) {
38619
+ this.scheduleRootScan(rootState);
38620
+ }
38621
+ });
38622
+ watcher.on("error", (error) => {
38623
+ this.logger.warn?.(`[markdown-ingest] watch error for ${dir}: ${formatError(error)}`);
38624
+ });
38625
+ rootState.directoryWatchers.set(dir, watcher);
38626
+ } catch (error) {
38627
+ this.logger.warn?.(`[markdown-ingest] watch unavailable for ${dir}: ${formatError(error)}`);
38628
+ }
38629
+ }
38630
+ shouldIncludeFile(root, filePath) {
38631
+ if (isOpenClawMemoryFile(filePath)) {
38632
+ return true;
38633
+ }
38634
+ const relative = toPosixPath(path2.relative(root, filePath));
38635
+ if (this.excludePatterns.length > 0) {
38636
+ for (const pattern of this.excludePatterns) {
38637
+ if (matchesGlob(relative, pattern)) {
38638
+ return false;
38639
+ }
38640
+ }
38641
+ }
38642
+ if (this.includePatterns.length > 0) {
38643
+ for (const pattern of this.includePatterns) {
38644
+ if (matchesGlob(relative, pattern)) {
38645
+ return true;
38646
+ }
38647
+ }
38648
+ return false;
38649
+ }
38650
+ return true;
38651
+ }
38652
+ async pruneDeletedFiles(rootState, currentFiles) {
38653
+ const removed = [];
38654
+ for (const previous of rootState.knownFiles) {
38655
+ if (!currentFiles.has(previous)) {
38656
+ removed.push(previous);
38657
+ }
38658
+ }
38659
+ if (removed.length === 0) {
38660
+ return;
38661
+ }
38662
+ for (const filePath of removed) {
38663
+ await this.deleteSourceDocument(filePath);
38664
+ this.fileStates.delete(filePath);
38665
+ }
38666
+ }
38667
+ async syncMarkdownFile(rootState, filePath) {
38668
+ const sourceDoc = filePath;
38669
+ const relativePath = toPosixPath(path2.relative(rootState.root, filePath));
38670
+ const stat = await this.safeStat(filePath);
38671
+ if (!stat) {
38672
+ await this.deleteSourceDocument(sourceDoc);
38673
+ this.fileStates.delete(sourceDoc);
38674
+ return;
38675
+ }
38676
+ const cached = this.fileStates.get(sourceDoc);
38677
+ if (cached && cached.size === stat.size && cached.mtimeMs === stat.mtimeMs) {
38678
+ return;
38679
+ }
38680
+ const bytes = await this.safeReadFile(filePath);
38681
+ if (!bytes) {
38682
+ await this.deleteSourceDocument(sourceDoc);
38683
+ this.fileStates.delete(sourceDoc);
38684
+ return;
38685
+ }
38686
+ const fileHash = hashBytes(bytes);
38687
+ if (cached && cached.fileHash === fileHash) {
38688
+ this.fileStates.set(sourceDoc, {
38689
+ root: rootState.root,
38690
+ sourceDoc,
38691
+ relativePath,
38692
+ fileHash,
38693
+ size: stat.size,
38694
+ mtimeMs: stat.mtimeMs
38695
+ });
38696
+ return;
38697
+ }
38698
+ const text = textDecoder2.decode(bytes);
38699
+ if (this.kind === "obsidian" && this.includePatterns.length === 0 && !looksLikeObsidianNote(filePath, text)) {
38700
+ await this.deleteSourceDocument(sourceDoc);
38701
+ this.fileStates.delete(sourceDoc);
38702
+ return;
38703
+ }
38704
+ await this.ingestMarkdownDocument(sourceDoc, text, rootState.root, relativePath, fileHash, stat.size, stat.mtimeMs);
38705
+ this.fileStates.set(sourceDoc, {
38706
+ root: rootState.root,
38707
+ sourceDoc,
38708
+ relativePath,
38709
+ fileHash,
38710
+ size: stat.size,
38711
+ mtimeMs: stat.mtimeMs
38712
+ });
38713
+ }
38714
+ async ingestMarkdownDocument(sourceDoc, text, sourceRoot, sourcePath, fileHash, sourceSize, sourceMtimeMs) {
38715
+ const queue = await this.getIngestQueue();
38716
+ await queue.enqueueIngest(
38717
+ sourceDoc,
38718
+ text,
38719
+ {
38720
+ tokenizerId: this.tokenizerId,
38721
+ coreDoc: this.coreDoc,
38722
+ sourceMeta: {
38723
+ sourceRoot,
38724
+ sourcePath,
38725
+ sourceKind: this.kind,
38726
+ fileHash,
38727
+ sourceSize,
38728
+ sourceMtimeMs: Math.trunc(sourceMtimeMs),
38729
+ ingestVersion: MARKDOWN_INGEST_VERSION,
38730
+ hashBackend: HASH_BACKEND
38731
+ }
38732
+ }
38733
+ );
38604
38734
  }
38605
- static runtime = proxy_exports.proto3;
38606
- static typeName = "libravdb.ipc.v1.RankCandidatesResponse";
38607
- static fields = proxy_exports.proto3.util.newFieldList(() => [
38608
- { no: 1, name: "ranked", kind: "message", T: RankCandidate, repeated: true }
38609
- ]);
38610
- static fromBinary(bytes, options) {
38611
- return new _RankCandidatesResponse().fromBinary(bytes, options);
38735
+ async deleteSourceDocument(sourceDoc) {
38736
+ const queue = await this.getIngestQueue();
38737
+ await queue.enqueueDelete(sourceDoc);
38612
38738
  }
38613
- static fromJson(jsonValue, options) {
38614
- return new _RankCandidatesResponse().fromJson(jsonValue, options);
38739
+ async getIngestQueue() {
38740
+ if (!this.ingestQueue) {
38741
+ const rpc = await this.getRpc();
38742
+ this.ingestQueue = new IngestQueue(rpc.call.bind(rpc), this.logger);
38743
+ }
38744
+ return this.ingestQueue;
38615
38745
  }
38616
- static fromJsonString(jsonString, options) {
38617
- return new _RankCandidatesResponse().fromJsonString(jsonString, options);
38746
+ async safeStat(filePath) {
38747
+ try {
38748
+ return await this.fsApi.stat(filePath);
38749
+ } catch {
38750
+ return null;
38751
+ }
38618
38752
  }
38619
- static equals(a, b) {
38620
- return proxy_exports.proto3.util.equals(_RankCandidatesResponse, a, b);
38753
+ async safeReadFile(filePath) {
38754
+ try {
38755
+ return await this.fsApi.readFile(filePath);
38756
+ } catch {
38757
+ return null;
38758
+ }
38621
38759
  }
38622
38760
  };
38623
- var RebuildIndexRequest = class _RebuildIndexRequest extends proxy_exports.Message {
38624
- /**
38625
- * @generated from field: string namespace = 1;
38626
- */
38627
- namespace = "";
38628
- /**
38629
- * @generated from field: repeated string collections = 2;
38630
- */
38631
- collections = [];
38632
- constructor(data) {
38633
- super();
38634
- proxy_exports.proto3.util.initPartial(data, this);
38635
- }
38636
- static runtime = proxy_exports.proto3;
38637
- static typeName = "libravdb.ipc.v1.RebuildIndexRequest";
38638
- static fields = proxy_exports.proto3.util.newFieldList(() => [
38639
- {
38640
- no: 1,
38641
- name: "namespace",
38642
- kind: "scalar",
38643
- T: 9
38644
- /* ScalarType.STRING */
38645
- },
38646
- { no: 2, name: "collections", kind: "scalar", T: 9, repeated: true }
38647
- ]);
38648
- static fromBinary(bytes, options) {
38649
- return new _RebuildIndexRequest().fromBinary(bytes, options);
38650
- }
38651
- static fromJson(jsonValue, options) {
38652
- return new _RebuildIndexRequest().fromJson(jsonValue, options);
38653
- }
38654
- static fromJsonString(jsonString, options) {
38655
- return new _RebuildIndexRequest().fromJsonString(jsonString, options);
38761
+ function toPosixPath(value) {
38762
+ return value.split(path2.sep).join("/");
38763
+ }
38764
+ var textDecoder2 = new TextDecoder();
38765
+ function normalizeMarkdownRoots(roots) {
38766
+ if (!roots?.length) {
38767
+ return [];
38656
38768
  }
38657
- static equals(a, b) {
38658
- return proxy_exports.proto3.util.equals(_RebuildIndexRequest, a, b);
38769
+ const resolved = /* @__PURE__ */ new Set();
38770
+ for (const root of roots) {
38771
+ const trimmed = root.trim();
38772
+ if (!trimmed) {
38773
+ continue;
38774
+ }
38775
+ resolved.add(path2.resolve(trimmed));
38659
38776
  }
38660
- };
38661
- var RebuildIndexResponse = class _RebuildIndexResponse extends proxy_exports.Message {
38662
- /**
38663
- * @generated from field: int32 collections_processed = 1;
38664
- */
38665
- collectionsProcessed = 0;
38666
- /**
38667
- * @generated from field: int32 records_reindexed = 2;
38668
- */
38669
- recordsReindexed = 0;
38670
- /**
38671
- * @generated from field: int32 collections_recreated = 3;
38672
- */
38673
- collectionsRecreated = 0;
38674
- /**
38675
- * @generated from field: repeated string errors = 4;
38676
- */
38677
- errors = [];
38678
- constructor(data) {
38679
- super();
38680
- proxy_exports.proto3.util.initPartial(data, this);
38777
+ return [...resolved];
38778
+ }
38779
+ function isMarkdownIngestionEnabled(cfg, roots) {
38780
+ if (cfg.markdownIngestionEnabled === false) {
38781
+ return false;
38681
38782
  }
38682
- static runtime = proxy_exports.proto3;
38683
- static typeName = "libravdb.ipc.v1.RebuildIndexResponse";
38684
- static fields = proxy_exports.proto3.util.newFieldList(() => [
38685
- {
38686
- no: 1,
38687
- name: "collections_processed",
38688
- kind: "scalar",
38689
- T: 5
38690
- /* ScalarType.INT32 */
38691
- },
38692
- {
38693
- no: 2,
38694
- name: "records_reindexed",
38695
- kind: "scalar",
38696
- T: 5
38697
- /* ScalarType.INT32 */
38698
- },
38699
- {
38700
- no: 3,
38701
- name: "collections_recreated",
38702
- kind: "scalar",
38703
- T: 5
38704
- /* ScalarType.INT32 */
38783
+ return roots.length > 0;
38784
+ }
38785
+ function createRealFsApi2() {
38786
+ return {
38787
+ readdir: async (dir) => fsp2.readdir(dir, { withFileTypes: true }),
38788
+ readFile: async (file) => fsp2.readFile(file),
38789
+ stat: async (file) => {
38790
+ const stat = await fsp2.stat(file);
38791
+ return { size: stat.size, mtimeMs: stat.mtimeMs };
38705
38792
  },
38706
- { no: 4, name: "errors", kind: "scalar", T: 9, repeated: true }
38707
- ]);
38708
- static fromBinary(bytes, options) {
38709
- return new _RebuildIndexResponse().fromBinary(bytes, options);
38793
+ watch: (dir, onChange) => fs2.watch(dir, onChange)
38794
+ };
38795
+ }
38796
+ function isMarkdownFile(fileName) {
38797
+ const lower = fileName.toLowerCase();
38798
+ return lower.endsWith(".md") || lower.endsWith(".markdown");
38799
+ }
38800
+ function matchesGlob(value, pattern) {
38801
+ const escaped = pattern.split("*").map((part) => part.replace(/[.+?^${}()|[\]\\]/g, "\\$&")).join(".*");
38802
+ return new RegExp(`^${escaped}$`).test(value);
38803
+ }
38804
+ function looksLikeObsidianNote(filePath, text) {
38805
+ if (!text.startsWith("---\n")) {
38806
+ return hasInlineObsidianTag(text);
38710
38807
  }
38711
- static fromJson(jsonValue, options) {
38712
- return new _RebuildIndexResponse().fromJson(jsonValue, options);
38808
+ const frontmatterEnd = findFrontmatterEnd(text, 4);
38809
+ if (frontmatterEnd < 0) {
38810
+ return hasInlineObsidianTag(text);
38713
38811
  }
38714
- static fromJsonString(jsonString, options) {
38715
- return new _RebuildIndexResponse().fromJsonString(jsonString, options);
38812
+ const frontmatter = text.slice(4, frontmatterEnd);
38813
+ const lines = frontmatter.split("\n");
38814
+ for (const line of lines) {
38815
+ const trimmed = line.trimStart();
38816
+ if (trimmed.startsWith("tags:") || trimmed.startsWith("tag:") || trimmed.startsWith("openclaw:") || trimmed.startsWith("memory:")) {
38817
+ return true;
38818
+ }
38716
38819
  }
38717
- static equals(a, b) {
38718
- return proxy_exports.proto3.util.equals(_RebuildIndexResponse, a, b);
38820
+ return hasInlineObsidianTag(text.slice(frontmatterEnd + 4));
38821
+ }
38822
+ function findFrontmatterEnd(text, offset) {
38823
+ for (let i = offset; i < text.length - 3; i++) {
38824
+ if (text.charCodeAt(i) !== 45 || text.charCodeAt(i + 1) !== 45 || text.charCodeAt(i + 2) !== 45) {
38825
+ continue;
38826
+ }
38827
+ const next = text.charCodeAt(i + 3);
38828
+ if (next === 10) {
38829
+ return i;
38830
+ }
38831
+ if (next === 13 && text.charCodeAt(i + 4) === 10) {
38832
+ return i;
38833
+ }
38719
38834
  }
38720
- };
38835
+ return -1;
38836
+ }
38837
+ function hasInlineObsidianTag(text) {
38838
+ let inFence = false;
38839
+ const lines = text.split("\n");
38840
+ for (const line of lines) {
38841
+ const trimmed = line.trimStart();
38842
+ if (trimmed.startsWith("```") || trimmed.startsWith("~~~")) {
38843
+ inFence = !inFence;
38844
+ continue;
38845
+ }
38846
+ if (inFence) {
38847
+ continue;
38848
+ }
38849
+ if (trimmed.startsWith("#")) {
38850
+ continue;
38851
+ }
38852
+ if (/(^|[^A-Za-z0-9_])#([A-Za-z][A-Za-z0-9/_-]*)\b/.test(line)) {
38853
+ return true;
38854
+ }
38855
+ }
38856
+ return false;
38857
+ }
38858
+ function isOpenClawMemoryFile(filePath) {
38859
+ return path2.basename(filePath).toLowerCase() === "memory.md";
38860
+ }
38861
+
38862
+ // src/memory-provider.ts
38863
+ var MEMORY_PROMPT_HEADER = [
38864
+ "## Memory",
38865
+ "LibraVDB persistent memory is configured. Recalled memories may appear",
38866
+ "in context via the context-engine assembler when available and relevant.",
38867
+ ""
38868
+ ];
38869
+ function buildMemoryPromptSection(_getRpc, _cfg) {
38870
+ return function memoryPromptSection({
38871
+ availableTools: _availableTools,
38872
+ citationsMode: _citationsMode
38873
+ }) {
38874
+ return [...MEMORY_PROMPT_HEADER];
38875
+ };
38876
+ }
38721
38877
 
38722
38878
  // src/rpc-protobuf-codecs.ts
38723
38879
  function encodeMessage(schema, init) {
@@ -39308,7 +39464,7 @@ var SidecarSupervisor = class {
39308
39464
  this.logger.info?.(
39309
39465
  `[libravdb] Daemon not ready, retrying connection (attempt ${attempt + 1}/${STARTUP_CONNECT_MAX_RETRIES})...`
39310
39466
  );
39311
- await sleep(delayMs);
39467
+ await sleep2(delayMs);
39312
39468
  }
39313
39469
  }
39314
39470
  }
@@ -39490,7 +39646,7 @@ function isConfiguredEndpoint(value) {
39490
39646
  const port = Number(address.slice(separator + 1));
39491
39647
  return host.length > 0 && Number.isInteger(port) && port > 0 && port <= 65535;
39492
39648
  }
39493
- function sleep(delayMs) {
39649
+ function sleep2(delayMs) {
39494
39650
  return new Promise((resolve) => setTimeout(resolve, delayMs));
39495
39651
  }
39496
39652