@wipcomputer/memory-crystal 0.7.34-alpha.1 → 0.7.34-alpha.3

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/LICENSE CHANGED
@@ -49,4 +49,4 @@ You should have received a copy of the GNU Affero General Public License
49
49
  along with this program. If not, see <https://www.gnu.org/licenses/>.
50
50
 
51
51
 
52
- AGPLv3 for personal use is free. Commercial licenses available.
52
+ AGPLv3 for personal use is free. Commercial licenses available.
package/dist/bridge.js CHANGED
@@ -1,10 +1,67 @@
1
- import {
2
- isBridgeDesktopRegistered,
3
- isBridgeInstalled,
4
- isBridgeRegistered,
5
- registerBridgeDesktop,
6
- registerBridgeMcp
7
- } from "./chunk-AEWLSYPH.js";
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
+ }
8
65
  export {
9
66
  isBridgeDesktopRegistered,
10
67
  isBridgeInstalled,
package/dist/bulk-copy.js CHANGED
@@ -1,20 +1,71 @@
1
- import {
2
- ldmPaths
3
- } from "./chunk-DFQ72B7M.js";
1
+ // src/bulk-copy.ts
2
+ import { existsSync as existsSync2, mkdirSync as mkdirSync2, copyFileSync as copyFileSync2, statSync, readdirSync as readdirSync2 } from "fs";
3
+ import { join as join2, basename } from "path";
4
+
5
+ // src/ldm.ts
6
+ import { existsSync, mkdirSync, readFileSync, writeFileSync, copyFileSync, chmodSync, readdirSync } from "fs";
7
+ import { join, dirname } from "path";
8
+ import { execSync } from "child_process";
9
+ import { fileURLToPath } from "url";
10
+ var HOME = process.env.HOME || "";
11
+ var LDM_ROOT = join(HOME, ".ldm");
12
+ function loadAgentConfig(id) {
13
+ const cfgPath = join(LDM_ROOT, "agents", id, "config.json");
14
+ try {
15
+ if (existsSync(cfgPath)) return JSON.parse(readFileSync(cfgPath, "utf-8"));
16
+ } catch {
17
+ }
18
+ return null;
19
+ }
20
+ function getAgentId(harnessHint) {
21
+ if (process.env.CRYSTAL_AGENT_ID) return process.env.CRYSTAL_AGENT_ID;
22
+ const agentsDir = join(LDM_ROOT, "agents");
23
+ if (existsSync(agentsDir)) {
24
+ try {
25
+ for (const d of readdirSync(agentsDir)) {
26
+ const cfg = loadAgentConfig(d);
27
+ if (!cfg || !cfg.agentId) continue;
28
+ if (!harnessHint) return cfg.agentId;
29
+ if (harnessHint === "claude-code" && cfg.harness === "claude-code-cli") return cfg.agentId;
30
+ if (harnessHint === "openclaw" && cfg.harness === "openclaw") return cfg.agentId;
31
+ }
32
+ } catch {
33
+ }
34
+ }
35
+ return harnessHint === "openclaw" ? "oc-lesa-mini" : "cc-mini";
36
+ }
37
+ function ldmPaths(agentId) {
38
+ const id = agentId || getAgentId();
39
+ const agentRoot = join(LDM_ROOT, "agents", id);
40
+ return {
41
+ root: LDM_ROOT,
42
+ bin: join(LDM_ROOT, "bin"),
43
+ secrets: join(LDM_ROOT, "secrets"),
44
+ state: join(LDM_ROOT, "state"),
45
+ config: join(LDM_ROOT, "config.json"),
46
+ crystalDb: join(LDM_ROOT, "memory", "crystal.db"),
47
+ crystalLance: join(LDM_ROOT, "memory", "lance"),
48
+ agentRoot,
49
+ transcripts: join(agentRoot, "memory", "transcripts"),
50
+ sessions: join(agentRoot, "memory", "sessions"),
51
+ daily: join(agentRoot, "memory", "daily"),
52
+ journals: join(agentRoot, "memory", "journals"),
53
+ workspace: join(agentRoot, "memory", "workspace")
54
+ };
55
+ }
56
+ var LEGACY_OC_DIR = join(HOME, ".openclaw");
4
57
 
5
58
  // src/bulk-copy.ts
6
- import { existsSync, mkdirSync, copyFileSync, statSync, readdirSync } from "fs";
7
- import { join, basename } from "path";
8
59
  function bulkCopyToLdm(sessionPaths, agentId, options) {
9
60
  const start = Date.now();
10
61
  const paths = ldmPaths(agentId);
11
62
  let filesCopied = 0;
12
63
  let filesSkipped = 0;
13
64
  let bytesWritten = 0;
14
- mkdirSync(paths.transcripts, { recursive: true });
65
+ mkdirSync2(paths.transcripts, { recursive: true });
15
66
  for (const srcPath of sessionPaths) {
16
- const destPath = join(paths.transcripts, basename(srcPath));
17
- if (existsSync(destPath)) {
67
+ const destPath = join2(paths.transcripts, basename(srcPath));
68
+ if (existsSync2(destPath)) {
18
69
  try {
19
70
  const srcSize = statSync(srcPath).size;
20
71
  const destSize = statSync(destPath).size;
@@ -26,14 +77,14 @@ function bulkCopyToLdm(sessionPaths, agentId, options) {
26
77
  }
27
78
  }
28
79
  try {
29
- copyFileSync(srcPath, destPath);
80
+ copyFileSync2(srcPath, destPath);
30
81
  bytesWritten += statSync(destPath).size;
31
82
  filesCopied++;
32
83
  } catch {
33
84
  }
34
85
  }
35
86
  if (options?.workspace && options.workspaceSrc) {
36
- mkdirSync(paths.workspace, { recursive: true });
87
+ mkdirSync2(paths.workspace, { recursive: true });
37
88
  const wsResult = copyWorkspaceRecursive(options.workspaceSrc, paths.workspace);
38
89
  filesCopied += wsResult.copied;
39
90
  filesSkipped += wsResult.skipped;
@@ -51,20 +102,20 @@ function copyWorkspaceRecursive(srcDir, destDir) {
51
102
  let skipped = 0;
52
103
  let bytes = 0;
53
104
  try {
54
- for (const entry of readdirSync(srcDir)) {
105
+ for (const entry of readdirSync2(srcDir)) {
55
106
  if (entry.startsWith(".")) continue;
56
- const srcPath = join(srcDir, entry);
57
- const destPath = join(destDir, entry);
107
+ const srcPath = join2(srcDir, entry);
108
+ const destPath = join2(destDir, entry);
58
109
  try {
59
110
  const stat = statSync(srcPath);
60
111
  if (stat.isDirectory()) {
61
- mkdirSync(destPath, { recursive: true });
112
+ mkdirSync2(destPath, { recursive: true });
62
113
  const sub = copyWorkspaceRecursive(srcPath, destPath);
63
114
  copied += sub.copied;
64
115
  skipped += sub.skipped;
65
116
  bytes += sub.bytes;
66
117
  } else if (entry.endsWith(".md")) {
67
- if (existsSync(destPath)) {
118
+ if (existsSync2(destPath)) {
68
119
  try {
69
120
  if (stat.size === statSync(destPath).size) {
70
121
  skipped++;
@@ -73,7 +124,7 @@ function copyWorkspaceRecursive(srcDir, destDir) {
73
124
  } catch {
74
125
  }
75
126
  }
76
- copyFileSync(srcPath, destPath);
127
+ copyFileSync2(srcPath, destPath);
77
128
  bytes += stat.size;
78
129
  copied++;
79
130
  }