beads-ui 0.8.0 → 0.8.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/CHANGES.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changes
2
2
 
3
+ ## 0.8.1
4
+
5
+ - [`59715e8`](https://github.com/mantoni/beads-ui/commit/59715e8eb7834e6fb6ee8f63f2257da33831d705)
6
+ Fix DB watch loop firing every second
7
+
8
+ _Released by [Maximilian Antoni](https://github.com/mantoni) on 2025-12-30._
9
+
3
10
  ## 0.8.0
4
11
 
5
12
  - [`2cfcd2d`](https://github.com/mantoni/beads-ui/commit/2cfcd2d4d4aa670b67f7798ecf7dfebaf5d2383c)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "beads-ui",
3
- "version": "0.8.0",
3
+ "version": "0.8.1",
4
4
  "description": "Local UI for Beads — Collaborate on issues with your coding agent.",
5
5
  "keywords": [
6
6
  "agent",
package/server/watcher.js CHANGED
@@ -9,27 +9,33 @@ import { debug } from './logging.js';
9
9
  *
10
10
  * @param {string} root_dir - Project root directory (starting point for resolution).
11
11
  * @param {() => void} onChange - Called when changes are detected.
12
- * @param {{ debounce_ms?: number, explicit_db?: string }} [options]
12
+ * @param {{ debounce_ms?: number, cooldown_ms?: number, explicit_db?: string }} [options]
13
13
  * @returns {{ close: () => void, rebind: (opts?: { root_dir?: string, explicit_db?: string }) => void, path: string }}
14
14
  */
15
15
  export function watchDb(root_dir, onChange, options = {}) {
16
16
  const debounce_ms = options.debounce_ms ?? 250;
17
+ const cooldown_ms = options.cooldown_ms ?? 1000;
17
18
  const log = debug('watcher');
18
19
 
19
20
  /** @type {ReturnType<typeof setTimeout> | undefined} */
20
21
  let timer;
21
22
  /** @type {fs.FSWatcher | undefined} */
22
23
  let watcher;
24
+ let cooldown_until = 0;
23
25
  let current_path = '';
24
26
  let current_dir = '';
25
27
  let current_file = '';
26
28
 
29
+ /**
30
+ * Schedule the debounced onChange callback.
31
+ */
27
32
  const schedule = () => {
28
33
  if (timer) {
29
34
  clearTimeout(timer);
30
35
  }
31
36
  timer = setTimeout(() => {
32
37
  onChange();
38
+ cooldown_until = Date.now() + cooldown_ms;
33
39
  }, debounce_ms);
34
40
  timer.unref();
35
41
  };
@@ -62,6 +68,9 @@ export function watchDb(root_dir, onChange, options = {}) {
62
68
  return;
63
69
  }
64
70
  if (event_type === 'change' || event_type === 'rename') {
71
+ if (Date.now() < cooldown_until) {
72
+ return;
73
+ }
65
74
  log('fs %s %s', event_type, filename || '');
66
75
  schedule();
67
76
  }
@@ -102,6 +111,7 @@ export function watchDb(root_dir, onChange, options = {}) {
102
111
  if (next_path !== current_path) {
103
112
  // swap watcher
104
113
  watcher?.close();
114
+ cooldown_until = 0;
105
115
  bind(next_root, next_explicit);
106
116
  }
107
117
  }