@wipcomputer/memory-crystal 0.7.17 → 0.7.18

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/CHANGELOG.md CHANGED
@@ -16,6 +16,91 @@
16
16
 
17
17
 
18
18
 
19
+
20
+ ## 0.7.18 (2026-03-13)
21
+
22
+ # Dev Update: Orphan Cleanup, DELETE Trigger, Doctor Fix
23
+
24
+ **Date:** 2026-03-13
25
+ **Author:** CC-Mini
26
+ **Session:** memory-db-fix
27
+
28
+ ---
29
+
30
+ ## What Happened
31
+
32
+ Parker ran the Memory Crystal install prompt and `crystal doctor` reported "Embeddings: FAILING ... no provider configured in env." Investigation revealed two separate issues:
33
+
34
+ ### Issue 1: Doctor False Positive
35
+
36
+ `checkEmbeddingProvider()` in `doctor.ts` only checked `process.env.OPENAI_API_KEY`. But the cron job and hooks resolve the key from 1Password via the SA token at `~/.openclaw/secrets/op-sa-token`. The doctor didn't know about this path.
37
+
38
+ **Fix:** Added `checkOpEmbeddings()` helper to `doctor.ts` that checks for the SA token file, then does a live `op read` to verify it works. Doctor now reports `ok: openai (via 1Password)` instead of `fail`.
39
+
40
+ ### Issue 2: Orphaned Vectors and FTS Entries
41
+
42
+ On 2026-03-11, 141,652 bulk file-scan chunks were correctly deleted from the `chunks` table. Parker said: "Why are we indexing documents?" These were raw file scans (Python venv packages, TypeScript source, vendor code) with no conversational context.
43
+
44
+ The deletion used raw SQL (`DELETE FROM chunks WHERE agent_id = 'system'`). But Memory Crystal had no DELETE trigger. The corresponding entries in `chunks_vec` (sqlite-vec) and `chunks_fts` (FTS5) were left orphaned.
45
+
46
+ **Impact:**
47
+ - 141,651 orphaned vectors (~875 MB)
48
+ - 141,652 orphaned FTS entries
49
+ - ~7% of search queries hit phantom results (silently filtered out)
50
+ - Database: 1.96 GB (should have been ~1 GB)
51
+
52
+ **Fix (three parts):**
53
+
54
+ 1. **DELETE trigger** added to `initChunksTables()` in `core.ts`:
55
+ ```sql
56
+ CREATE TRIGGER IF NOT EXISTS chunks_cleanup AFTER DELETE ON chunks
57
+ BEGIN
58
+ DELETE FROM chunks_vec WHERE chunk_id = OLD.id;
59
+ INSERT INTO chunks_fts(chunks_fts, rowid, text) VALUES('delete', OLD.id, OLD.text);
60
+ END;
61
+ ```
62
+
63
+ 2. **`cleanOrphans()` method** added to Crystal class in `core.ts`. Counts orphaned vec/FTS entries, deletes vec orphans in batches of 1000, rebuilds FTS5 from scratch.
64
+
65
+ 3. **`crystal cleanup` CLI command** added to `cli.ts`. Handles the full workflow: backup, pause cron, clean orphans, VACUUM, resume cron. Supports `--dry-run`.
66
+
67
+ **Cleanup results:**
68
+ - 141,651 orphaned vectors removed
69
+ - FTS rebuilt from 73,813 chunks in 5.7s
70
+ - Database: 1.96 GB -> 1.45 GB (525 MB saved)
71
+ - Verification: chunks = FTS entries = 73,813. Match: YES
72
+ - Zero orphans remaining
73
+
74
+ ### Side Discovery: Plaintext SA Token
75
+
76
+ During investigation, discovered that `~/.openclaw/secrets/op-sa-token` is a plaintext 1Password SA token readable by any process running as `lesa`. This is the bootstrap credential that unlocks all secrets. Bug report filed. Long-term fix: Lesa iOS app with remote biometrics (product doc written).
77
+
78
+ ### Product Rule Established
79
+
80
+ Memory Crystal indexes conversations only. File content that appears in conversation turns (agent reads a file, discusses it) is captured as part of the conversation. Raw directory scanning without conversational context is not what Memory Crystal is for.
81
+
82
+ ## Files Changed
83
+
84
+ | File | Change |
85
+ |------|--------|
86
+ | `src/core.ts` | Added `chunks_cleanup` DELETE trigger, `cleanOrphans()` method |
87
+ | `src/cli.ts` | Added `crystal cleanup` command, updated imports and USAGE |
88
+ | `src/doctor.ts` | Added `checkOpEmbeddings()` for 1Password detection |
89
+ | `ai/product/bugs/2026-03-13--orphaned-vectors-and-fts-after-bulk-delete.md` | Bug report |
90
+
91
+ ## Related (wip-secrets-ios-private)
92
+
93
+ | File | What |
94
+ |------|------|
95
+ | `ai/product/product-ideas/lesa-app-remote-biometrics.md` | Lesa app: remote biometrics for agent computers |
96
+ | `ai/product/bugs/2026-03-13--plaintext-sa-token-on-disk.md` | Plaintext SA token bug report |
97
+
98
+ ## Status
99
+
100
+ - Code deployed and running (cleanup already executed)
101
+ - Not yet committed / PR'd / released
102
+ - Needs: branch, commit, PR, merge, `wip-release patch`
103
+
19
104
  ## 0.7.17 (2026-03-13)
20
105
 
21
106
  # Dev Update: Orphan Cleanup, DELETE Trigger, Doctor Fix
package/dist/bridge.js CHANGED
@@ -4,7 +4,7 @@ import {
4
4
  isBridgeRegistered,
5
5
  registerBridgeDesktop,
6
6
  registerBridgeMcp
7
- } from "./chunk-MPLTNMRG.js";
7
+ } from "./chunk-AEWLSYPH.js";
8
8
  export {
9
9
  isBridgeDesktopRegistered,
10
10
  isBridgeInstalled,
@@ -0,0 +1,72 @@
1
+ // src/bridge.ts
2
+ import { existsSync, readFileSync, writeFileSync } from "fs";
3
+ import { execSync } from "child_process";
4
+ import { join } from "path";
5
+ var HOME = process.env.HOME || "";
6
+ function _checkLocalBridge() {
7
+ if (existsSync(join(HOME, ".openclaw", "extensions", "lesa-bridge", "dist", "index.js"))) return true;
8
+ if (existsSync(join(HOME, ".ldm", "extensions", "lesa-bridge", "dist", "index.js"))) return true;
9
+ return false;
10
+ }
11
+ function isBridgeInstalled() {
12
+ try {
13
+ execSync("which lesa 2>/dev/null", { encoding: "utf-8" });
14
+ return true;
15
+ } catch {
16
+ return _checkLocalBridge();
17
+ }
18
+ }
19
+ function isBridgeRegistered() {
20
+ const mcpPath = join(HOME, ".claude", ".mcp.json");
21
+ try {
22
+ if (existsSync(mcpPath)) {
23
+ const config = JSON.parse(readFileSync(mcpPath, "utf-8"));
24
+ if (config.mcpServers && config.mcpServers["lesa-bridge"]) return true;
25
+ }
26
+ } catch {
27
+ }
28
+ try {
29
+ const r = execSync("claude mcp get lesa-bridge 2>&1", { encoding: "utf-8", timeout: 5e3 });
30
+ if (!r.includes("not found") && !r.includes("error")) return true;
31
+ } catch {
32
+ }
33
+ return false;
34
+ }
35
+ function isBridgeDesktopRegistered() {
36
+ const desktopConfig = join(HOME, "Library", "Application Support", "Claude", "claude_desktop_config.json");
37
+ try {
38
+ if (existsSync(desktopConfig)) {
39
+ const config = JSON.parse(readFileSync(desktopConfig, "utf-8"));
40
+ if (config.mcpServers && config.mcpServers["lesa-bridge"]) return true;
41
+ }
42
+ } catch {
43
+ }
44
+ return false;
45
+ }
46
+ function registerBridgeMcp() {
47
+ execSync("claude mcp add --scope user lesa-bridge -- lesa", {
48
+ encoding: "utf-8",
49
+ stdio: "pipe"
50
+ });
51
+ }
52
+ function registerBridgeDesktop() {
53
+ const desktopConfig = join(HOME, "Library", "Application Support", "Claude", "claude_desktop_config.json");
54
+ if (!existsSync(desktopConfig)) return false;
55
+ try {
56
+ const config = JSON.parse(readFileSync(desktopConfig, "utf-8"));
57
+ if (!config.mcpServers) config.mcpServers = {};
58
+ config.mcpServers["lesa-bridge"] = { command: "lesa" };
59
+ writeFileSync(desktopConfig, JSON.stringify(config, null, 2) + "\n");
60
+ return true;
61
+ } catch {
62
+ return false;
63
+ }
64
+ }
65
+
66
+ export {
67
+ isBridgeInstalled,
68
+ isBridgeRegistered,
69
+ isBridgeDesktopRegistered,
70
+ registerBridgeMcp,
71
+ registerBridgeDesktop
72
+ };
package/dist/doctor.js CHANGED
@@ -4,7 +4,7 @@ import {
4
4
  import {
5
5
  isBridgeInstalled,
6
6
  isBridgeRegistered
7
- } from "./chunk-MPLTNMRG.js";
7
+ } from "./chunk-AEWLSYPH.js";
8
8
  import {
9
9
  ldmPaths,
10
10
  resolveStatePath
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wipcomputer/memory-crystal",
3
- "version": "0.7.17",
3
+ "version": "0.7.18",
4
4
  "description": "Sovereign memory system — local-first with ephemeral encrypted relay. Your memory, your machine, your rules.",
5
5
  "type": "module",
6
6
  "main": "dist/core.js",