wicked-brain 0.4.14 → 0.4.15

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": "wicked-brain",
3
- "version": "0.4.14",
3
+ "version": "0.4.15",
4
4
  "type": "module",
5
5
  "description": "Digital brain as skills for AI coding CLIs — no vector DB, no embeddings, no infrastructure",
6
6
  "keywords": [
@@ -36,26 +36,33 @@ export class FileWatcher {
36
36
  }
37
37
 
38
38
  start() {
39
+ const brainDirs = ["chunks", "wiki", "memory"];
40
+
39
41
  // Build initial hash map
40
- this.#scanAndHash("chunks");
41
- this.#scanAndHash("wiki");
42
- this.#scanAndHash("memory");
42
+ for (const dir of brainDirs) this.#scanAndHash(dir);
43
43
 
44
44
  // Watch directories
45
- for (const dir of ["chunks", "wiki", "memory"]) {
46
- const absDir = join(this.#brainPath, dir);
47
- if (!existsSync(absDir)) continue;
45
+ const unwatched = [];
46
+ for (const dir of brainDirs) {
47
+ if (!this.#tryWatch(dir)) unwatched.push(dir);
48
+ }
48
49
 
49
- try {
50
- const watcher = watch(absDir, { recursive: true }, (eventType, filename) => {
51
- if (!filename || !filename.endsWith(".md")) return;
52
- const relPath = normalizePath(`${dir}/${filename}`);
53
- this.#debounce(relPath, () => this.#handleChange(relPath));
54
- });
55
- this.#watchers.push(watcher);
56
- } catch {
57
- // recursive watch not supported on this platform (Linux) — fall back to polling
58
- }
50
+ // Retry directories that were missing at startup (check every 3s, stop after 30s)
51
+ if (unwatched.length > 0) {
52
+ const pending = new Set(unwatched);
53
+ let elapsed = 0;
54
+ const retryInterval = setInterval(() => {
55
+ elapsed += 3000;
56
+ for (const dir of pending) {
57
+ if (this.#tryWatch(dir)) {
58
+ this.#scanAndHash(dir);
59
+ pending.delete(dir);
60
+ }
61
+ }
62
+ if (pending.size === 0 || elapsed >= 30000) clearInterval(retryInterval);
63
+ }, 3000);
64
+ // Don't keep the process alive just for retries
65
+ retryInterval.unref();
59
66
  }
60
67
 
61
68
  // Watch registered project directories
@@ -84,6 +91,24 @@ export class FileWatcher {
84
91
  }
85
92
  }
86
93
 
94
+ /** Try to set up fs.watch for a brain subdirectory. Returns true on success. */
95
+ #tryWatch(dir) {
96
+ const absDir = join(this.#brainPath, dir);
97
+ if (!existsSync(absDir)) return false;
98
+ try {
99
+ const watcher = watch(absDir, { recursive: true }, (eventType, filename) => {
100
+ if (!filename || !filename.endsWith(".md")) return;
101
+ const relPath = normalizePath(`${dir}/${filename}`);
102
+ this.#debounce(relPath, () => this.#handleChange(relPath));
103
+ });
104
+ this.#watchers.push(watcher);
105
+ return true;
106
+ } catch {
107
+ // recursive watch not supported (Linux) — polling fallback handles it
108
+ return false;
109
+ }
110
+ }
111
+
87
112
  stop() {
88
113
  for (const w of this.#watchers) w.close();
89
114
  this.#watchers = [];
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wicked-brain-server",
3
- "version": "0.4.14",
3
+ "version": "0.4.15",
4
4
  "type": "module",
5
5
  "description": "SQLite FTS5 search server for wicked-brain digital knowledge bases",
6
6
  "keywords": [
@@ -189,17 +189,18 @@ Use your native Write tool to create these directories (write a `.gitkeep` place
189
189
  - `{brain_path}/chunks/inferred`
190
190
  - `{brain_path}/wiki/concepts`
191
191
  - `{brain_path}/wiki/topics`
192
+ - `{brain_path}/memory`
192
193
  - `{brain_path}/_meta`
193
194
 
194
195
  Shell equivalents if needed:
195
196
  ```bash
196
197
  # macOS/Linux
197
198
  mkdir -p {brain_path}/raw {brain_path}/chunks/extracted {brain_path}/chunks/inferred \
198
- {brain_path}/wiki/concepts {brain_path}/wiki/topics {brain_path}/_meta
199
+ {brain_path}/wiki/concepts {brain_path}/wiki/topics {brain_path}/memory {brain_path}/_meta
199
200
  ```
200
201
  ```powershell
201
202
  # Windows PowerShell
202
- New-Item -ItemType Directory -Force -Path "{brain_path}\raw","{brain_path}\chunks\extracted","{brain_path}\chunks\inferred","{brain_path}\wiki\concepts","{brain_path}\wiki\topics","{brain_path}\_meta"
203
+ New-Item -ItemType Directory -Force -Path "{brain_path}\raw","{brain_path}\chunks\extracted","{brain_path}\chunks\inferred","{brain_path}\wiki\concepts","{brain_path}\wiki\topics","{brain_path}\memory","{brain_path}\_meta"
203
204
  ```
204
205
 
205
206
  ### Step 4: Write brain.json
@@ -17,7 +17,7 @@ Store and recall experiential learnings in the brain's memory system.
17
17
  - Uses `curl` for server API calls (available on Windows 10+, macOS, Linux)
18
18
  - File writes use agent-native tools (Write/Edit), not shell commands
19
19
  - Path separator: always use forward slashes in `contains:` and `path` fields
20
- - Brain path default: `~/.wicked-brain` (macOS/Linux), `%USERPROFILE%\.wicked-brain` (Windows)
20
+ - Brain path default: `~/.wicked-brain/projects/{project-name}` (macOS/Linux), `%USERPROFILE%\.wicked-brain\projects\{project-name}` (Windows)
21
21
 
22
22
  ## Config
23
23