@wipcomputer/memory-crystal 0.7.14 → 0.7.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/CHANGELOG.md CHANGED
@@ -13,6 +13,91 @@
13
13
 
14
14
 
15
15
 
16
+
17
+ ## 0.7.15 (2026-03-13)
18
+
19
+ # Dev Update: Orphan Cleanup, DELETE Trigger, Doctor Fix
20
+
21
+ **Date:** 2026-03-13
22
+ **Author:** CC-Mini
23
+ **Session:** memory-db-fix
24
+
25
+ ---
26
+
27
+ ## What Happened
28
+
29
+ Parker ran the Memory Crystal install prompt and `crystal doctor` reported "Embeddings: FAILING ... no provider configured in env." Investigation revealed two separate issues:
30
+
31
+ ### Issue 1: Doctor False Positive
32
+
33
+ `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.
34
+
35
+ **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`.
36
+
37
+ ### Issue 2: Orphaned Vectors and FTS Entries
38
+
39
+ 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.
40
+
41
+ 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.
42
+
43
+ **Impact:**
44
+ - 141,651 orphaned vectors (~875 MB)
45
+ - 141,652 orphaned FTS entries
46
+ - ~7% of search queries hit phantom results (silently filtered out)
47
+ - Database: 1.96 GB (should have been ~1 GB)
48
+
49
+ **Fix (three parts):**
50
+
51
+ 1. **DELETE trigger** added to `initChunksTables()` in `core.ts`:
52
+ ```sql
53
+ CREATE TRIGGER IF NOT EXISTS chunks_cleanup AFTER DELETE ON chunks
54
+ BEGIN
55
+ DELETE FROM chunks_vec WHERE chunk_id = OLD.id;
56
+ INSERT INTO chunks_fts(chunks_fts, rowid, text) VALUES('delete', OLD.id, OLD.text);
57
+ END;
58
+ ```
59
+
60
+ 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.
61
+
62
+ 3. **`crystal cleanup` CLI command** added to `cli.ts`. Handles the full workflow: backup, pause cron, clean orphans, VACUUM, resume cron. Supports `--dry-run`.
63
+
64
+ **Cleanup results:**
65
+ - 141,651 orphaned vectors removed
66
+ - FTS rebuilt from 73,813 chunks in 5.7s
67
+ - Database: 1.96 GB -> 1.45 GB (525 MB saved)
68
+ - Verification: chunks = FTS entries = 73,813. Match: YES
69
+ - Zero orphans remaining
70
+
71
+ ### Side Discovery: Plaintext SA Token
72
+
73
+ 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).
74
+
75
+ ### Product Rule Established
76
+
77
+ 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.
78
+
79
+ ## Files Changed
80
+
81
+ | File | Change |
82
+ |------|--------|
83
+ | `src/core.ts` | Added `chunks_cleanup` DELETE trigger, `cleanOrphans()` method |
84
+ | `src/cli.ts` | Added `crystal cleanup` command, updated imports and USAGE |
85
+ | `src/doctor.ts` | Added `checkOpEmbeddings()` for 1Password detection |
86
+ | `ai/product/bugs/2026-03-13--orphaned-vectors-and-fts-after-bulk-delete.md` | Bug report |
87
+
88
+ ## Related (wip-secrets-ios-private)
89
+
90
+ | File | What |
91
+ |------|------|
92
+ | `ai/product/product-ideas/lesa-app-remote-biometrics.md` | Lesa app: remote biometrics for agent computers |
93
+ | `ai/product/bugs/2026-03-13--plaintext-sa-token-on-disk.md` | Plaintext SA token bug report |
94
+
95
+ ## Status
96
+
97
+ - Code deployed and running (cleanup already executed)
98
+ - Not yet committed / PR'd / released
99
+ - Needs: branch, commit, PR, merge, `wip-release patch`
100
+
16
101
  ## 0.7.14 (2026-03-13)
17
102
 
18
103
  # Dev Update: Orphan Cleanup, DELETE Trigger, Doctor Fix
package/dist/installer.js CHANGED
@@ -46,6 +46,15 @@ function getRepoRoot() {
46
46
  }
47
47
  return dirname(thisDir);
48
48
  }
49
+ function semverCompare(a, b) {
50
+ const pa = a.split(".").map(Number);
51
+ const pb = b.split(".").map(Number);
52
+ for (let i = 0; i < 3; i++) {
53
+ if ((pa[i] || 0) > (pb[i] || 0)) return 1;
54
+ if ((pa[i] || 0) < (pb[i] || 0)) return -1;
55
+ }
56
+ return 0;
57
+ }
49
58
  function getLatestNpmVersion() {
50
59
  const names = ["@wipcomputer/memory-crystal", "memory-crystal"];
51
60
  for (const name of names) {
@@ -65,7 +74,7 @@ function detectInstallState() {
65
74
  const repoRoot = getRepoRoot();
66
75
  let repoVersion = readVersion(join(repoRoot, "package.json")) || "0.0.0";
67
76
  const npmVersion = getLatestNpmVersion();
68
- if (npmVersion && npmVersion > repoVersion) repoVersion = npmVersion;
77
+ if (npmVersion && semverCompare(npmVersion, repoVersion) > 0) repoVersion = npmVersion;
69
78
  const ccHookDeployed = existsSync(join(ldmExtDir, "dist", "cc-hook.js"));
70
79
  let ccHookConfigured = false;
71
80
  try {
@@ -420,7 +429,7 @@ async function runInstallOrUpdate(options) {
420
429
  }
421
430
  if (isUpdate && state.installedVersion) {
422
431
  const npmV = getLatestNpmVersion();
423
- if (npmV && npmV > state.installedVersion) {
432
+ if (npmV && semverCompare(npmV, state.installedVersion) > 0) {
424
433
  steps.push(`Upgrading v${state.installedVersion} -> v${npmV} via npm...`);
425
434
  try {
426
435
  execSync("npm install -g @wipcomputer/memory-crystal 2>&1", { encoding: "utf-8", timeout: 6e4, stdio: "pipe" });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wipcomputer/memory-crystal",
3
- "version": "0.7.14",
3
+ "version": "0.7.15",
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",