@wipcomputer/memory-crystal 0.7.10 → 0.7.12

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
@@ -9,6 +9,176 @@
9
9
 
10
10
 
11
11
 
12
+
13
+
14
+ ## 0.7.12 (2026-03-13)
15
+
16
+ # Dev Update: Orphan Cleanup, DELETE Trigger, Doctor Fix
17
+
18
+ **Date:** 2026-03-13
19
+ **Author:** CC-Mini
20
+ **Session:** memory-db-fix
21
+
22
+ ---
23
+
24
+ ## What Happened
25
+
26
+ Parker ran the Memory Crystal install prompt and `crystal doctor` reported "Embeddings: FAILING ... no provider configured in env." Investigation revealed two separate issues:
27
+
28
+ ### Issue 1: Doctor False Positive
29
+
30
+ `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.
31
+
32
+ **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`.
33
+
34
+ ### Issue 2: Orphaned Vectors and FTS Entries
35
+
36
+ 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.
37
+
38
+ 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.
39
+
40
+ **Impact:**
41
+ - 141,651 orphaned vectors (~875 MB)
42
+ - 141,652 orphaned FTS entries
43
+ - ~7% of search queries hit phantom results (silently filtered out)
44
+ - Database: 1.96 GB (should have been ~1 GB)
45
+
46
+ **Fix (three parts):**
47
+
48
+ 1. **DELETE trigger** added to `initChunksTables()` in `core.ts`:
49
+ ```sql
50
+ CREATE TRIGGER IF NOT EXISTS chunks_cleanup AFTER DELETE ON chunks
51
+ BEGIN
52
+ DELETE FROM chunks_vec WHERE chunk_id = OLD.id;
53
+ INSERT INTO chunks_fts(chunks_fts, rowid, text) VALUES('delete', OLD.id, OLD.text);
54
+ END;
55
+ ```
56
+
57
+ 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.
58
+
59
+ 3. **`crystal cleanup` CLI command** added to `cli.ts`. Handles the full workflow: backup, pause cron, clean orphans, VACUUM, resume cron. Supports `--dry-run`.
60
+
61
+ **Cleanup results:**
62
+ - 141,651 orphaned vectors removed
63
+ - FTS rebuilt from 73,813 chunks in 5.7s
64
+ - Database: 1.96 GB -> 1.45 GB (525 MB saved)
65
+ - Verification: chunks = FTS entries = 73,813. Match: YES
66
+ - Zero orphans remaining
67
+
68
+ ### Side Discovery: Plaintext SA Token
69
+
70
+ 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).
71
+
72
+ ### Product Rule Established
73
+
74
+ 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.
75
+
76
+ ## Files Changed
77
+
78
+ | File | Change |
79
+ |------|--------|
80
+ | `src/core.ts` | Added `chunks_cleanup` DELETE trigger, `cleanOrphans()` method |
81
+ | `src/cli.ts` | Added `crystal cleanup` command, updated imports and USAGE |
82
+ | `src/doctor.ts` | Added `checkOpEmbeddings()` for 1Password detection |
83
+ | `ai/product/bugs/2026-03-13--orphaned-vectors-and-fts-after-bulk-delete.md` | Bug report |
84
+
85
+ ## Related (wip-secrets-ios-private)
86
+
87
+ | File | What |
88
+ |------|------|
89
+ | `ai/product/product-ideas/lesa-app-remote-biometrics.md` | Lesa app: remote biometrics for agent computers |
90
+ | `ai/product/bugs/2026-03-13--plaintext-sa-token-on-disk.md` | Plaintext SA token bug report |
91
+
92
+ ## Status
93
+
94
+ - Code deployed and running (cleanup already executed)
95
+ - Not yet committed / PR'd / released
96
+ - Needs: branch, commit, PR, merge, `wip-release patch`
97
+
98
+ ## 0.7.11 (2026-03-13)
99
+
100
+ # Dev Update: Orphan Cleanup, DELETE Trigger, Doctor Fix
101
+
102
+ **Date:** 2026-03-13
103
+ **Author:** CC-Mini
104
+ **Session:** memory-db-fix
105
+
106
+ ---
107
+
108
+ ## What Happened
109
+
110
+ Parker ran the Memory Crystal install prompt and `crystal doctor` reported "Embeddings: FAILING ... no provider configured in env." Investigation revealed two separate issues:
111
+
112
+ ### Issue 1: Doctor False Positive
113
+
114
+ `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.
115
+
116
+ **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`.
117
+
118
+ ### Issue 2: Orphaned Vectors and FTS Entries
119
+
120
+ 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.
121
+
122
+ 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.
123
+
124
+ **Impact:**
125
+ - 141,651 orphaned vectors (~875 MB)
126
+ - 141,652 orphaned FTS entries
127
+ - ~7% of search queries hit phantom results (silently filtered out)
128
+ - Database: 1.96 GB (should have been ~1 GB)
129
+
130
+ **Fix (three parts):**
131
+
132
+ 1. **DELETE trigger** added to `initChunksTables()` in `core.ts`:
133
+ ```sql
134
+ CREATE TRIGGER IF NOT EXISTS chunks_cleanup AFTER DELETE ON chunks
135
+ BEGIN
136
+ DELETE FROM chunks_vec WHERE chunk_id = OLD.id;
137
+ INSERT INTO chunks_fts(chunks_fts, rowid, text) VALUES('delete', OLD.id, OLD.text);
138
+ END;
139
+ ```
140
+
141
+ 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.
142
+
143
+ 3. **`crystal cleanup` CLI command** added to `cli.ts`. Handles the full workflow: backup, pause cron, clean orphans, VACUUM, resume cron. Supports `--dry-run`.
144
+
145
+ **Cleanup results:**
146
+ - 141,651 orphaned vectors removed
147
+ - FTS rebuilt from 73,813 chunks in 5.7s
148
+ - Database: 1.96 GB -> 1.45 GB (525 MB saved)
149
+ - Verification: chunks = FTS entries = 73,813. Match: YES
150
+ - Zero orphans remaining
151
+
152
+ ### Side Discovery: Plaintext SA Token
153
+
154
+ 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).
155
+
156
+ ### Product Rule Established
157
+
158
+ 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.
159
+
160
+ ## Files Changed
161
+
162
+ | File | Change |
163
+ |------|--------|
164
+ | `src/core.ts` | Added `chunks_cleanup` DELETE trigger, `cleanOrphans()` method |
165
+ | `src/cli.ts` | Added `crystal cleanup` command, updated imports and USAGE |
166
+ | `src/doctor.ts` | Added `checkOpEmbeddings()` for 1Password detection |
167
+ | `ai/product/bugs/2026-03-13--orphaned-vectors-and-fts-after-bulk-delete.md` | Bug report |
168
+
169
+ ## Related (wip-secrets-ios-private)
170
+
171
+ | File | What |
172
+ |------|------|
173
+ | `ai/product/product-ideas/lesa-app-remote-biometrics.md` | Lesa app: remote biometrics for agent computers |
174
+ | `ai/product/bugs/2026-03-13--plaintext-sa-token-on-disk.md` | Plaintext SA token bug report |
175
+
176
+ ## Status
177
+
178
+ - Code deployed and running (cleanup already executed)
179
+ - Not yet committed / PR'd / released
180
+ - Needs: branch, commit, PR, merge, `wip-release patch`
181
+
12
182
  ## 0.7.10 (2026-03-13)
13
183
 
14
184
  # Dev Update: Orphan Cleanup, DELETE Trigger, Doctor Fix
package/dist/installer.js CHANGED
@@ -38,7 +38,7 @@ function getRepoRoot() {
38
38
  if (existsSync(pkgPath)) {
39
39
  try {
40
40
  const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
41
- if (pkg.name === "memory-crystal") return dir;
41
+ if (pkg.name === "@wipcomputer/memory-crystal") return dir;
42
42
  } catch {
43
43
  }
44
44
  }
@@ -46,13 +46,26 @@ function getRepoRoot() {
46
46
  }
47
47
  return dirname(thisDir);
48
48
  }
49
+ function getLatestNpmVersion() {
50
+ const names = ["@wipcomputer/memory-crystal", "memory-crystal"];
51
+ for (const name of names) {
52
+ try {
53
+ const v = execSync(`npm view ${name} version 2>/dev/null`, { encoding: "utf-8", timeout: 1e4 }).trim();
54
+ if (v) return v;
55
+ } catch {
56
+ }
57
+ }
58
+ return null;
59
+ }
49
60
  function detectInstallState() {
50
61
  const ldmExtDir = join(LDM_ROOT, "extensions", "memory-crystal");
51
62
  const ocExtDir = join(OC_ROOT, "extensions", "memory-crystal");
52
63
  const paths = ldmPaths();
53
64
  const installedVersion = readVersion(join(ldmExtDir, "package.json"));
54
65
  const repoRoot = getRepoRoot();
55
- const repoVersion = readVersion(join(repoRoot, "package.json")) || "0.0.0";
66
+ let repoVersion = readVersion(join(repoRoot, "package.json")) || "0.0.0";
67
+ const npmVersion = getLatestNpmVersion();
68
+ if (npmVersion && npmVersion > repoVersion) repoVersion = npmVersion;
56
69
  const ccHookDeployed = existsSync(join(ldmExtDir, "dist", "cc-hook.js"));
57
70
  let ccHookConfigured = false;
58
71
  try {
@@ -355,6 +368,18 @@ function ldmCliAvailable() {
355
368
  return false;
356
369
  }
357
370
  }
371
+ function bootstrapLdmOs(steps) {
372
+ try {
373
+ steps.push("Installing LDM OS infrastructure...");
374
+ execSync("npm install -g @wipcomputer/wip-ldm-os", { stdio: "pipe", timeout: 12e4 });
375
+ execSync("ldm --version", { stdio: "pipe", timeout: 5e3 });
376
+ steps.push("LDM OS installed.");
377
+ return true;
378
+ } catch {
379
+ steps.push("LDM OS install skipped (npm offline or permissions issue). Using standalone.");
380
+ return false;
381
+ }
382
+ }
358
383
  function runLdmInstall(repoDir) {
359
384
  const steps = [];
360
385
  try {
@@ -393,7 +418,25 @@ async function runInstallOrUpdate(options) {
393
418
  steps: [`Already at v${state.repoVersion}. Nothing to do.`]
394
419
  };
395
420
  }
396
- const hasLdmCli = ldmCliAvailable();
421
+ if (isUpdate && state.installedVersion) {
422
+ const npmV = getLatestNpmVersion();
423
+ if (npmV && npmV > state.installedVersion) {
424
+ steps.push(`Upgrading v${state.installedVersion} -> v${npmV} via npm...`);
425
+ try {
426
+ execSync("npm install -g @wipcomputer/memory-crystal 2>&1", { encoding: "utf-8", timeout: 6e4, stdio: "pipe" });
427
+ steps.push(`Installed @wipcomputer/memory-crystal@${npmV}`);
428
+ steps.push("Restarting init with updated code...");
429
+ execSync("crystal init", { stdio: "inherit", timeout: 12e4 });
430
+ return { action: "updated", version: npmV, deployedTo: ["global", "ldm", "openclaw"], steps };
431
+ } catch (err) {
432
+ steps.push(`npm upgrade failed: ${err.message}. Continuing with local code.`);
433
+ }
434
+ }
435
+ }
436
+ let hasLdmCli = ldmCliAvailable();
437
+ if (!hasLdmCli) {
438
+ hasLdmCli = bootstrapLdmOs(steps);
439
+ }
397
440
  let ldmDelegated = false;
398
441
  if (hasLdmCli) {
399
442
  steps.push("LDM OS detected. Using ldm install for deployment...");
@@ -590,7 +633,7 @@ async function runInstallOrUpdate(options) {
590
633
  }
591
634
  if (hasLdmCli) {
592
635
  steps.push('Tip: Run "ldm install" to see more components you can add.');
593
- } else {
636
+ } else if (!ldmDelegated) {
594
637
  steps.push("Tip: Install LDM OS for more components: npm install -g @wipcomputer/wip-ldm-os");
595
638
  }
596
639
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wipcomputer/memory-crystal",
3
- "version": "0.7.10",
3
+ "version": "0.7.12",
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",
@@ -55,7 +55,7 @@ npm link
55
55
  - One command, done
56
56
 
57
57
  ```bash
58
- npm install -g memory-crystal
58
+ npm install -g @wipcomputer/memory-crystal
59
59
  ```
60
60
 
61
61
  If npm is not available, check if the user has Node.js installed (`node --version`). They need Node.js 20+. If not installed, tell them to install it from https://nodejs.org first.
@@ -280,7 +280,7 @@ If the user already has a Crystal Core on another machine:
280
280
 
281
281
  ### Step 1: Install the package
282
282
 
283
- Same as above (developer fork or `npm install -g memory-crystal`).
283
+ Same as above (developer fork or `npm install -g @wipcomputer/memory-crystal`).
284
284
 
285
285
  ### Step 2: Initialize as a Node
286
286