@monoes/monograph 1.5.0 → 1.5.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@monoes/monograph",
3
- "version": "1.5.0",
3
+ "version": "1.5.1",
4
4
  "type": "module",
5
5
  "description": "Native TypeScript code intelligence engine for monomind",
6
6
  "main": "dist/src/index.js",
@@ -24,10 +24,14 @@ const STOPWORDS = new Set([
24
24
  */
25
25
  export function extractSearchTerms(query: string): string[] {
26
26
  const words = query.split(/[\s,;:!?()\[\]{}'"]+/).filter(Boolean);
27
- // If query is a single token or all tokens are code-like, it's already an identifier query
27
+ // If query is a single token, it's already a bare identifier query — nothing to extract.
28
+ // (We used to also bail out for short, stopword-free multi-token queries under the
29
+ // assumption they were "already an identifier query", but that misfires for queries
30
+ // like "ExtensionBridge keepalive reconnect" — three distinct identifier-ish tokens
31
+ // that FTS5 MATCH ANDs together and fails to find as a single row. Since this function
32
+ // only runs as a fallback after the raw MATCH already returned zero rows, there's no
33
+ // extra cost to always extracting terms for multi-token queries.)
28
34
  if (words.length <= 1) return [];
29
- const hasStopword = words.some(w => STOPWORDS.has(w.toLowerCase()));
30
- if (!hasStopword && words.length <= 3) return [];
31
35
 
32
36
  const terms = new Set<string>();
33
37
  for (const word of words) {
@@ -13,6 +13,8 @@ export interface WatchAsyncOptions extends WatcherOptions {
13
13
  force?: boolean;
14
14
  codeOnly?: boolean;
15
15
  llmMaxSections?: number;
16
+ /** Auto-stop after this many ms of no file changes. Default 30min. 0 = never. */
17
+ idleTimeoutMs?: number;
16
18
  }
17
19
 
18
20
  /** Convenience: start a watcher and trigger buildAsync on every change. Returns stop() fn. */
@@ -23,11 +25,25 @@ export async function watchAsync(
23
25
  const { buildAsync } = await import('../pipeline/orchestrator.js');
24
26
  const watcher = new MonographWatcher(repoPath, { debounceMs: opts.debounceMs ?? 3000 });
25
27
 
28
+ // Idle timeout: auto-stop after prolonged inactivity to reclaim resources.
29
+ const idleMs = opts.idleTimeoutMs ?? 30 * 60_000; // default 30min
30
+ let idleTimer: ReturnType<typeof setTimeout> | null = null;
31
+ const resetIdle = (): void => {
32
+ if (idleMs <= 0) return;
33
+ if (idleTimer) clearTimeout(idleTimer);
34
+ idleTimer = setTimeout(() => {
35
+ opts.onProgress?.({ phase: 'watch', message: `No changes for ${Math.round(idleMs / 60_000)}min — auto-stopping watcher.` });
36
+ watcher.stop().catch(() => {});
37
+ }, idleMs);
38
+ (idleTimer as { unref?: () => void }).unref?.();
39
+ };
40
+
26
41
  // monolean: full rebuild per change-batch, serialized — true incremental rebuild
27
42
  // (re-parse only changed files) requires restructuring the phase pipeline.
28
43
  let building = false;
29
44
  let rerun = false;
30
45
  watcher.on('monograph:updated', async (files: string[]) => {
46
+ resetIdle();
31
47
  if (building) { rerun = true; return; } // coalesce saves that land mid-build
32
48
  building = true;
33
49
  try {
@@ -52,7 +68,13 @@ export async function watchAsync(
52
68
  });
53
69
 
54
70
  await watcher.start();
55
- return { stop: () => watcher.stop() };
71
+ resetIdle(); // start the idle clock
72
+ return {
73
+ stop: async () => {
74
+ if (idleTimer) clearTimeout(idleTimer);
75
+ await watcher.stop();
76
+ },
77
+ };
56
78
  }
57
79
 
58
80
  export class MonographWatcher extends EventEmitter {