@wipcomputer/memory-crystal 0.7.32 → 0.7.34-alpha.1
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/SKILL.md +1 -1
- package/cloud/wrangler.toml +30 -0
- package/dist/bridge.d.ts +7 -0
- package/dist/bridge.js +14 -0
- package/dist/bulk-copy.d.ts +17 -0
- package/dist/bulk-copy.js +90 -0
- package/dist/cc-hook.d.ts +8 -0
- package/dist/cc-hook.js +368 -0
- package/dist/cc-poller.d.ts +1 -0
- package/dist/cc-poller.js +550 -0
- package/dist/chunk-25LXQJ4Z.js +110 -0
- package/dist/chunk-2DRXIRQW.js +97 -0
- package/dist/chunk-2GBYLMEF.js +1385 -0
- package/dist/chunk-2ZNH5F6E.js +1281 -0
- package/dist/chunk-3G3SFYYI.js +288 -0
- package/dist/chunk-3RG5ZIWI.js +10 -0
- package/dist/chunk-3S6TI23B.js +97 -0
- package/dist/chunk-3VFIJYS4.js +818 -0
- package/dist/chunk-437F27T6.js +97 -0
- package/dist/chunk-52QE3YI3.js +1169 -0
- package/dist/chunk-57RP3DIN.js +1205 -0
- package/dist/chunk-5HSZ4W2P.js +62 -0
- package/dist/chunk-5I7GMRDN.js +146 -0
- package/dist/chunk-645IPXW3.js +290 -0
- package/dist/chunk-7A7ELD4C.js +1205 -0
- package/dist/chunk-7FYY4GZM.js +1205 -0
- package/dist/chunk-7IUE7ODU.js +254 -0
- package/dist/chunk-7RMLKZIS.js +108 -0
- package/dist/chunk-AA3OPP4Z.js +432 -0
- package/dist/chunk-AEWLSYPH.js +72 -0
- package/dist/chunk-ASSZDR6I.js +108 -0
- package/dist/chunk-AYRJVWUC.js +1205 -0
- package/dist/chunk-CCYI5O3D.js +148 -0
- package/dist/chunk-CGIDSAJB.js +288 -0
- package/dist/chunk-D3I3ZSE2.js +411 -0
- package/dist/chunk-D3MACYZ4.js +108 -0
- package/dist/chunk-DACSKLY6.js +219 -0
- package/dist/chunk-DFQ72B7M.js +248 -0
- package/dist/chunk-DW5B4BL7.js +108 -0
- package/dist/chunk-EKSACBTJ.js +1070 -0
- package/dist/chunk-EXEZZADG.js +248 -0
- package/dist/chunk-F3Y7EL7K.js +83 -0
- package/dist/chunk-FBQWSDPC.js +1328 -0
- package/dist/chunk-FHRZNOMW.js +1205 -0
- package/dist/chunk-IM7N24MT.js +129 -0
- package/dist/chunk-IPNYIXFK.js +1178 -0
- package/dist/chunk-J7MRSZIO.js +167 -0
- package/dist/chunk-JITKI2OI.js +106 -0
- package/dist/chunk-JWZXYVET.js +1068 -0
- package/dist/chunk-KCQUXVYT.js +108 -0
- package/dist/chunk-KOQ43OX6.js +1281 -0
- package/dist/chunk-KYVWO6ZM.js +1069 -0
- package/dist/chunk-L3VHARQH.js +413 -0
- package/dist/chunk-LBWDS6BE.js +288 -0
- package/dist/chunk-LOVAHSQV.js +411 -0
- package/dist/chunk-LQOYCAGG.js +446 -0
- package/dist/chunk-LWAIPJ2W.js +146 -0
- package/dist/chunk-M5DHKW7M.js +127 -0
- package/dist/chunk-MBKCIJHM.js +1328 -0
- package/dist/chunk-MK42FMEG.js +147 -0
- package/dist/chunk-MOBMYHKL.js +1205 -0
- package/dist/chunk-MPLTNMRG.js +67 -0
- package/dist/chunk-NIJCVN3O.js +147 -0
- package/dist/chunk-NX647OM3.js +310 -0
- package/dist/chunk-NZCFSZQ7.js +1205 -0
- package/dist/chunk-O2UITJGH.js +465 -0
- package/dist/chunk-OCRA44AZ.js +108 -0
- package/dist/chunk-P3KJR66H.js +117 -0
- package/dist/chunk-PEK6JH65.js +432 -0
- package/dist/chunk-PJ6FFKEX.js +77 -0
- package/dist/chunk-PLUBBZYR.js +800 -0
- package/dist/chunk-PNKVD2UK.js +26 -0
- package/dist/chunk-PSQZURHO.js +229 -0
- package/dist/chunk-SGL6ISBJ.js +1061 -0
- package/dist/chunk-SJABZZT5.js +97 -0
- package/dist/chunk-TD3P3K32.js +1199 -0
- package/dist/chunk-TMDZJJKV.js +288 -0
- package/dist/chunk-UNHVZB5G.js +411 -0
- package/dist/chunk-VAFTWSTE.js +1061 -0
- package/dist/chunk-VNFXFQBB.js +217 -0
- package/dist/chunk-X3GVFKSJ.js +1205 -0
- package/dist/chunk-XZ3S56RQ.js +1061 -0
- package/dist/chunk-Y72C7F6O.js +148 -0
- package/dist/chunk-YLICP577.js +1205 -0
- package/dist/chunk-YX6AXLVK.js +159 -0
- package/dist/chunk-ZCQYHTNU.js +146 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +1160 -0
- package/dist/cloud-crystal.js +6 -0
- package/dist/core.d.ts +252 -0
- package/dist/core.js +12 -0
- package/dist/crypto.d.ts +20 -0
- package/dist/crypto.js +27 -0
- package/dist/crystal-capture.sh +29 -0
- package/dist/crystal-serve.d.ts +4 -0
- package/dist/crystal-serve.js +252 -0
- package/dist/dev-update-SZ2Z4WCQ.js +6 -0
- package/dist/discover.d.ts +30 -0
- package/dist/discover.js +177 -0
- package/dist/doctor.d.ts +9 -0
- package/dist/doctor.js +342 -0
- package/dist/dream-weaver.d.ts +8 -0
- package/dist/dream-weaver.js +56 -0
- package/dist/file-sync.d.ts +48 -0
- package/dist/file-sync.js +18 -0
- package/dist/installer.d.ts +61 -0
- package/dist/installer.js +772 -0
- package/dist/ldm-backup.sh +116 -0
- package/dist/ldm.d.ts +50 -0
- package/dist/ldm.js +32 -0
- package/dist/llm-XXLYPIOF.js +16 -0
- package/dist/mcp-server.d.ts +1 -0
- package/dist/mcp-server.js +277 -0
- package/dist/migrate.d.ts +1 -0
- package/dist/migrate.js +89 -0
- package/dist/mirror-sync.d.ts +1 -0
- package/dist/mirror-sync.js +159 -0
- package/dist/mlx-setup-XKU67WCT.js +289 -0
- package/dist/oc-backfill.d.ts +19 -0
- package/dist/oc-backfill.js +74 -0
- package/dist/openclaw.d.ts +5 -0
- package/dist/openclaw.js +434 -0
- package/dist/pair.d.ts +4 -0
- package/dist/pair.js +75 -0
- package/dist/poller.d.ts +1 -0
- package/dist/poller.js +634 -0
- package/dist/role.d.ts +24 -0
- package/dist/role.js +13 -0
- package/dist/search-pipeline-4K4OJSSS.js +255 -0
- package/dist/search-pipeline-4PRS6LI7.js +280 -0
- package/dist/search-pipeline-7UJMXPLO.js +280 -0
- package/dist/search-pipeline-CBV25NX7.js +99 -0
- package/dist/search-pipeline-DQTRLGBH.js +74 -0
- package/dist/search-pipeline-HNG37REH.js +282 -0
- package/dist/search-pipeline-IZFPLBUB.js +280 -0
- package/dist/search-pipeline-MID6F26Q.js +73 -0
- package/dist/search-pipeline-N52JZFNN.js +282 -0
- package/dist/search-pipeline-OPB2PRQQ.js +280 -0
- package/dist/search-pipeline-VXTE5HAD.js +262 -0
- package/dist/search-pipeline-XHFKADRG.js +73 -0
- package/dist/staging.d.ts +29 -0
- package/dist/staging.js +21 -0
- package/dist/summarize.d.ts +19 -0
- package/dist/summarize.js +10 -0
- package/dist/worker-demo.js +186 -0
- package/dist/worker-mcp.js +404 -0
- package/dist/worker.js +137 -0
- package/package.json +15 -1
- package/.env.example +0 -20
- package/.publish-skill.json +0 -1
- package/CHANGELOG.md +0 -1372
- package/README-ENTERPRISE.md +0 -226
- package/RELAY.md +0 -199
- package/wrangler-demo.toml +0 -8
- package/wrangler-mcp.toml +0 -24
package/dist/openclaw.js
ADDED
|
@@ -0,0 +1,434 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Crystal,
|
|
3
|
+
resolveConfig
|
|
4
|
+
} from "./chunk-2GBYLMEF.js";
|
|
5
|
+
import {
|
|
6
|
+
ensureLdm,
|
|
7
|
+
resolveStatePath,
|
|
8
|
+
stateWritePath
|
|
9
|
+
} from "./chunk-DFQ72B7M.js";
|
|
10
|
+
|
|
11
|
+
// src/dev-update.ts
|
|
12
|
+
import { execSync } from "child_process";
|
|
13
|
+
import { existsSync, mkdirSync, writeFileSync, readFileSync } from "fs";
|
|
14
|
+
import { join, basename } from "path";
|
|
15
|
+
var HOME = process.env.HOME || "";
|
|
16
|
+
function resolveWorkspace() {
|
|
17
|
+
const configPath = join(HOME, ".ldm", "config.json");
|
|
18
|
+
if (existsSync(configPath)) {
|
|
19
|
+
try {
|
|
20
|
+
const config = JSON.parse(readFileSync(configPath, "utf-8"));
|
|
21
|
+
if (config.workspace) return config.workspace;
|
|
22
|
+
} catch {
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return join(HOME, "wipcomputerinc");
|
|
26
|
+
}
|
|
27
|
+
var TEAM_DIR = join(resolveWorkspace(), "team");
|
|
28
|
+
var CC_REPOS = join(TEAM_DIR, "cc-mini", "repos");
|
|
29
|
+
var LESA_REPOS = join(TEAM_DIR, "L\u0113sa", "repos");
|
|
30
|
+
var DEV_UPDATES_DIR = join(CC_REPOS, "wip-dev-updates");
|
|
31
|
+
var LAST_RUN_PATH = resolveStatePath("dev-update-last-run.json");
|
|
32
|
+
function loadLastRun() {
|
|
33
|
+
try {
|
|
34
|
+
if (existsSync(LAST_RUN_PATH)) {
|
|
35
|
+
return JSON.parse(readFileSync(LAST_RUN_PATH, "utf-8"));
|
|
36
|
+
}
|
|
37
|
+
} catch {
|
|
38
|
+
}
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
function saveLastRun(run) {
|
|
42
|
+
const writePath = stateWritePath("dev-update-last-run.json");
|
|
43
|
+
writeFileSync(writePath, JSON.stringify(run, null, 2));
|
|
44
|
+
}
|
|
45
|
+
function git(repoPath, cmd) {
|
|
46
|
+
try {
|
|
47
|
+
return execSync(`git -C "${repoPath}" ${cmd}`, {
|
|
48
|
+
encoding: "utf-8",
|
|
49
|
+
timeout: 1e4,
|
|
50
|
+
stdio: ["pipe", "pipe", "pipe"]
|
|
51
|
+
}).trim();
|
|
52
|
+
} catch {
|
|
53
|
+
return "";
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function scanRepo(repoPath, since) {
|
|
57
|
+
if (!existsSync(join(repoPath, ".git"))) return null;
|
|
58
|
+
const name = basename(repoPath);
|
|
59
|
+
if (name === "_third-party-repos" || name === "wip-dev-updates") return null;
|
|
60
|
+
const recentCommits = git(repoPath, `log --oneline --since="${since}"`);
|
|
61
|
+
const uncommitted = git(repoPath, "status --porcelain");
|
|
62
|
+
if (!recentCommits && !uncommitted) return null;
|
|
63
|
+
const lines = [];
|
|
64
|
+
lines.push(`# ${name}`);
|
|
65
|
+
lines.push("");
|
|
66
|
+
if (recentCommits) {
|
|
67
|
+
lines.push("## Recent Commits");
|
|
68
|
+
lines.push("");
|
|
69
|
+
lines.push("```");
|
|
70
|
+
lines.push(...recentCommits.split("\n").slice(0, 10));
|
|
71
|
+
lines.push("```");
|
|
72
|
+
lines.push("");
|
|
73
|
+
}
|
|
74
|
+
if (uncommitted) {
|
|
75
|
+
lines.push("## Uncommitted Changes");
|
|
76
|
+
lines.push("");
|
|
77
|
+
lines.push("```");
|
|
78
|
+
lines.push(...uncommitted.split("\n").slice(0, 20));
|
|
79
|
+
lines.push("```");
|
|
80
|
+
lines.push("");
|
|
81
|
+
}
|
|
82
|
+
if (recentCommits) {
|
|
83
|
+
const diffStat = git(repoPath, `diff --stat "HEAD@{${since}}" HEAD`);
|
|
84
|
+
if (diffStat) {
|
|
85
|
+
lines.push("## Files Changed");
|
|
86
|
+
lines.push("");
|
|
87
|
+
lines.push("```");
|
|
88
|
+
lines.push(...diffStat.split("\n").slice(-15));
|
|
89
|
+
lines.push("```");
|
|
90
|
+
lines.push("");
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
const branch = git(repoPath, "branch --show-current") || "unknown";
|
|
94
|
+
lines.push(`**Branch:** ${branch}`);
|
|
95
|
+
lines.push("");
|
|
96
|
+
return lines.join("\n");
|
|
97
|
+
}
|
|
98
|
+
function runDevUpdate(author) {
|
|
99
|
+
const lastRun = loadLastRun();
|
|
100
|
+
if (lastRun) {
|
|
101
|
+
const elapsed = Date.now() - new Date(lastRun.timestamp).getTime();
|
|
102
|
+
if (elapsed < 60 * 60 * 1e3) {
|
|
103
|
+
return { reposUpdated: 0, files: [] };
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
let since = "6 hours ago";
|
|
107
|
+
if (lastRun?.timestamp) {
|
|
108
|
+
const lastDate = new Date(lastRun.timestamp);
|
|
109
|
+
const hoursAgo = Math.ceil((Date.now() - lastDate.getTime()) / (1e3 * 60 * 60));
|
|
110
|
+
since = `${Math.max(hoursAgo, 1)} hours ago`;
|
|
111
|
+
}
|
|
112
|
+
const now = /* @__PURE__ */ new Date();
|
|
113
|
+
const ts = [
|
|
114
|
+
String(now.getMonth() + 1).padStart(2, "0"),
|
|
115
|
+
String(now.getDate()).padStart(2, "0"),
|
|
116
|
+
String(now.getFullYear())
|
|
117
|
+
].join("-") + "--" + [
|
|
118
|
+
String(now.getHours()).padStart(2, "0"),
|
|
119
|
+
String(now.getMinutes()).padStart(2, "0"),
|
|
120
|
+
String(now.getSeconds()).padStart(2, "0")
|
|
121
|
+
].join("-");
|
|
122
|
+
const files = [];
|
|
123
|
+
const repoDirs = [CC_REPOS, LESA_REPOS];
|
|
124
|
+
for (const parentDir of repoDirs) {
|
|
125
|
+
if (!existsSync(parentDir)) continue;
|
|
126
|
+
let entries;
|
|
127
|
+
try {
|
|
128
|
+
entries = execSync(`ls "${parentDir}"`, { encoding: "utf-8" }).trim().split("\n");
|
|
129
|
+
} catch {
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
for (const entry of entries) {
|
|
133
|
+
const repoPath = join(parentDir, entry);
|
|
134
|
+
const content = scanRepo(repoPath, since);
|
|
135
|
+
if (!content) continue;
|
|
136
|
+
const repoName = basename(repoPath);
|
|
137
|
+
const outDir = join(repoPath, "ai");
|
|
138
|
+
const outFile = join(outDir, `${now.toISOString().slice(0, 10)}--${now.toISOString().slice(11, 19).replace(/:/g, "-")}--${author}--dev-update-${repoName}.md`);
|
|
139
|
+
mkdirSync(outDir, { recursive: true });
|
|
140
|
+
const header = `*Auto-generated dev update by ${author} at ${now.toISOString().slice(0, 16).replace("T", " ")}*
|
|
141
|
+
|
|
142
|
+
`;
|
|
143
|
+
writeFileSync(outFile, content.replace(/^# .+\n/, `$&
|
|
144
|
+
${header}`));
|
|
145
|
+
files.push(`${repoName}/ai/${basename(outFile)}`);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
if (false) {
|
|
149
|
+
try {
|
|
150
|
+
execSync(
|
|
151
|
+
`cd "${DEV_UPDATES_DIR}" && git add -A && git commit -m "${author} auto-dev-update ${ts}: ${files.length} repo(s)" --no-verify && git push --quiet`,
|
|
152
|
+
{ encoding: "utf-8", timeout: 3e4, stdio: "pipe" }
|
|
153
|
+
);
|
|
154
|
+
} catch {
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
saveLastRun({
|
|
158
|
+
timestamp: now.toISOString(),
|
|
159
|
+
author,
|
|
160
|
+
reposUpdated: files.length
|
|
161
|
+
});
|
|
162
|
+
return { reposUpdated: files.length, files };
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// src/openclaw.ts
|
|
166
|
+
import {
|
|
167
|
+
existsSync as existsSync2,
|
|
168
|
+
readFileSync as readFileSync2,
|
|
169
|
+
readdirSync,
|
|
170
|
+
copyFileSync,
|
|
171
|
+
statSync,
|
|
172
|
+
mkdirSync as mkdirSync2
|
|
173
|
+
} from "fs";
|
|
174
|
+
import { join as join2 } from "path";
|
|
175
|
+
var PRIVATE_MODE_PATH = resolveStatePath("memory-capture-state.json");
|
|
176
|
+
function isPrivateMode() {
|
|
177
|
+
try {
|
|
178
|
+
if (existsSync2(PRIVATE_MODE_PATH)) {
|
|
179
|
+
const state = JSON.parse(readFileSync2(PRIVATE_MODE_PATH, "utf-8"));
|
|
180
|
+
return state.enabled === false;
|
|
181
|
+
}
|
|
182
|
+
} catch {
|
|
183
|
+
}
|
|
184
|
+
return false;
|
|
185
|
+
}
|
|
186
|
+
var OC_AGENT_ID = "oc-lesa-mini";
|
|
187
|
+
function syncRawDataToLdm(logger) {
|
|
188
|
+
try {
|
|
189
|
+
const paths = ensureLdm(OC_AGENT_ID);
|
|
190
|
+
const HOME2 = process.env.HOME || "";
|
|
191
|
+
const ocDir = join2(HOME2, ".openclaw");
|
|
192
|
+
const sessionsDir = join2(ocDir, "agents", "main", "sessions");
|
|
193
|
+
if (existsSync2(sessionsDir)) {
|
|
194
|
+
let copied = 0;
|
|
195
|
+
for (const file of readdirSync(sessionsDir)) {
|
|
196
|
+
if (!file.endsWith(".jsonl")) continue;
|
|
197
|
+
const src = join2(sessionsDir, file);
|
|
198
|
+
const dest = join2(paths.transcripts, file);
|
|
199
|
+
if (idempotentCopy(src, dest)) copied++;
|
|
200
|
+
}
|
|
201
|
+
if (copied > 0) logger.info(`memory-crystal: synced ${copied} session files to LDM`);
|
|
202
|
+
}
|
|
203
|
+
const workspaceDir = join2(ocDir, "workspace");
|
|
204
|
+
if (existsSync2(workspaceDir)) {
|
|
205
|
+
syncDirRecursive(workspaceDir, paths.workspace, ".md");
|
|
206
|
+
}
|
|
207
|
+
const dailyDir = join2(ocDir, "workspace", "memory");
|
|
208
|
+
if (existsSync2(dailyDir)) {
|
|
209
|
+
for (const file of readdirSync(dailyDir)) {
|
|
210
|
+
if (!file.endsWith(".md")) continue;
|
|
211
|
+
if (/^\d{4}-\d{2}-\d{2}\.md$/.test(file)) {
|
|
212
|
+
const src = join2(dailyDir, file);
|
|
213
|
+
const dest = join2(paths.daily, file);
|
|
214
|
+
idempotentCopy(src, dest);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
} catch (err) {
|
|
219
|
+
logger.warn(`memory-crystal: raw data sync failed (non-fatal): ${err.message}`);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
function idempotentCopy(src, dest) {
|
|
223
|
+
try {
|
|
224
|
+
if (existsSync2(dest)) {
|
|
225
|
+
const srcStat = statSync(src);
|
|
226
|
+
const destStat = statSync(dest);
|
|
227
|
+
if (srcStat.size === destStat.size && srcStat.mtimeMs <= destStat.mtimeMs) return false;
|
|
228
|
+
}
|
|
229
|
+
const destDir = join2(dest, "..");
|
|
230
|
+
if (!existsSync2(destDir)) mkdirSync2(destDir, { recursive: true });
|
|
231
|
+
copyFileSync(src, dest);
|
|
232
|
+
return true;
|
|
233
|
+
} catch {
|
|
234
|
+
return false;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
function syncDirRecursive(srcDir, destDir, ext) {
|
|
238
|
+
if (!existsSync2(destDir)) mkdirSync2(destDir, { recursive: true });
|
|
239
|
+
for (const entry of readdirSync(srcDir, { withFileTypes: true })) {
|
|
240
|
+
const srcPath = join2(srcDir, entry.name);
|
|
241
|
+
const destPath = join2(destDir, entry.name);
|
|
242
|
+
if (entry.isDirectory()) {
|
|
243
|
+
syncDirRecursive(srcPath, destPath, ext);
|
|
244
|
+
} else if (entry.name.endsWith(ext)) {
|
|
245
|
+
idempotentCopy(srcPath, destPath);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
var openclaw_default = {
|
|
250
|
+
register(api) {
|
|
251
|
+
const crystal = new Crystal(resolveConfig());
|
|
252
|
+
let initialized = false;
|
|
253
|
+
async function ensureInit() {
|
|
254
|
+
if (!initialized) {
|
|
255
|
+
await crystal.init();
|
|
256
|
+
initialized = true;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
api.on("agent_end", async (event, ctx) => {
|
|
260
|
+
if (isPrivateMode()) return;
|
|
261
|
+
await ensureInit();
|
|
262
|
+
const messages = event.messages;
|
|
263
|
+
if (!messages || messages.length === 0) return;
|
|
264
|
+
const agentId = ctx.agentId || OC_AGENT_ID;
|
|
265
|
+
const sessionKey = ctx.sessionKey || "unknown";
|
|
266
|
+
const state = crystal.getCaptureState(agentId, sessionKey);
|
|
267
|
+
const storedCount = state.lastMessageCount;
|
|
268
|
+
let startIndex = storedCount;
|
|
269
|
+
if (messages.length < storedCount) {
|
|
270
|
+
api.logger.info(`memory-crystal: compaction detected (${storedCount} \u2192 ${messages.length} messages), resetting capture position`);
|
|
271
|
+
startIndex = 0;
|
|
272
|
+
}
|
|
273
|
+
if (messages.length <= startIndex) return;
|
|
274
|
+
const newTurns = [];
|
|
275
|
+
for (let i = startIndex; i < messages.length; i++) {
|
|
276
|
+
const msg = messages[i];
|
|
277
|
+
if (!msg.content) continue;
|
|
278
|
+
const role = msg.role;
|
|
279
|
+
if (role !== "user" && role !== "assistant") continue;
|
|
280
|
+
let text = "";
|
|
281
|
+
if (typeof msg.content === "string") {
|
|
282
|
+
text = msg.content;
|
|
283
|
+
} else if (Array.isArray(msg.content)) {
|
|
284
|
+
text = msg.content.filter((b) => b.type === "text").map((b) => b.text).join("\n");
|
|
285
|
+
}
|
|
286
|
+
if (!text || text.length < 50) continue;
|
|
287
|
+
const maxSingleChunkChars = 2e3 * 4;
|
|
288
|
+
if (text.length <= maxSingleChunkChars) {
|
|
289
|
+
newTurns.push({
|
|
290
|
+
text,
|
|
291
|
+
role,
|
|
292
|
+
source_type: "conversation",
|
|
293
|
+
source_id: sessionKey,
|
|
294
|
+
agent_id: agentId,
|
|
295
|
+
token_count: Math.ceil(text.length / 4),
|
|
296
|
+
created_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
297
|
+
});
|
|
298
|
+
} else {
|
|
299
|
+
const chunks = crystal.chunkText(text);
|
|
300
|
+
for (const chunkText of chunks) {
|
|
301
|
+
newTurns.push({
|
|
302
|
+
text: chunkText,
|
|
303
|
+
role,
|
|
304
|
+
source_type: "conversation",
|
|
305
|
+
source_id: sessionKey,
|
|
306
|
+
agent_id: agentId,
|
|
307
|
+
token_count: Math.ceil(chunkText.length / 4),
|
|
308
|
+
created_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
const totalTokens = newTurns.reduce((sum, c) => sum + c.token_count, 0);
|
|
314
|
+
if (totalTokens < 500) return;
|
|
315
|
+
try {
|
|
316
|
+
const count = await crystal.ingest(newTurns);
|
|
317
|
+
crystal.setCaptureState(agentId, sessionKey, messages.length, state.captureCount + 1);
|
|
318
|
+
api.logger.info(`memory-crystal: ingested ${count} chunks from ${sessionKey} (cycle ${state.captureCount + 1})`);
|
|
319
|
+
} catch (err) {
|
|
320
|
+
api.logger.error(`memory-crystal: ingest error: ${err.message}`);
|
|
321
|
+
}
|
|
322
|
+
syncRawDataToLdm(api.logger);
|
|
323
|
+
});
|
|
324
|
+
function toolResult(text, isError = false) {
|
|
325
|
+
return {
|
|
326
|
+
content: [{ type: "text", text }],
|
|
327
|
+
...isError ? { isError: true } : {}
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
api.registerTool(
|
|
331
|
+
{
|
|
332
|
+
name: "crystal_search",
|
|
333
|
+
label: "Search Memory Crystal",
|
|
334
|
+
description: "Search memory crystal \u2014 semantic search across all conversations and stored memories.",
|
|
335
|
+
parameters: {
|
|
336
|
+
type: "object",
|
|
337
|
+
properties: {
|
|
338
|
+
query: { type: "string", description: "What to search for" },
|
|
339
|
+
limit: { type: "number", description: "Max results (default: 5)" },
|
|
340
|
+
agent_id: { type: "string", description: "Filter by agent" }
|
|
341
|
+
},
|
|
342
|
+
required: ["query"]
|
|
343
|
+
},
|
|
344
|
+
async execute(_id, params) {
|
|
345
|
+
try {
|
|
346
|
+
await ensureInit();
|
|
347
|
+
const results = await crystal.search(
|
|
348
|
+
params.query,
|
|
349
|
+
params.limit || 5,
|
|
350
|
+
params.agent_id ? { agent_id: params.agent_id } : void 0
|
|
351
|
+
);
|
|
352
|
+
if (results.length === 0) return toolResult("No results found.");
|
|
353
|
+
const formatted = results.map((r, i) => {
|
|
354
|
+
const score = (r.score * 100).toFixed(1);
|
|
355
|
+
const date = r.created_at?.slice(0, 10) || "unknown";
|
|
356
|
+
return `[${i + 1}] (${score}%, ${r.agent_id}, ${date}, ${r.role})
|
|
357
|
+
${r.text}`;
|
|
358
|
+
}).join("\n\n---\n\n");
|
|
359
|
+
return toolResult(formatted);
|
|
360
|
+
} catch (err) {
|
|
361
|
+
return toolResult(`crystal_search error: ${err.message}`, true);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
},
|
|
365
|
+
{ optional: true }
|
|
366
|
+
);
|
|
367
|
+
api.registerTool(
|
|
368
|
+
{
|
|
369
|
+
name: "crystal_remember",
|
|
370
|
+
label: "Remember in Crystal",
|
|
371
|
+
description: "Store a fact, preference, or observation in memory crystal.",
|
|
372
|
+
parameters: {
|
|
373
|
+
type: "object",
|
|
374
|
+
properties: {
|
|
375
|
+
text: { type: "string", description: "The fact to remember" },
|
|
376
|
+
category: { type: "string", enum: ["fact", "preference", "event", "opinion", "skill", "user", "feedback", "project", "reference"] }
|
|
377
|
+
},
|
|
378
|
+
required: ["text"]
|
|
379
|
+
},
|
|
380
|
+
async execute(_id, params) {
|
|
381
|
+
if (isPrivateMode()) {
|
|
382
|
+
return toolResult("Private mode is on. No memories are being stored. Use /private-mode off to resume.");
|
|
383
|
+
}
|
|
384
|
+
try {
|
|
385
|
+
await ensureInit();
|
|
386
|
+
const id = await crystal.remember(params.text, params.category || "fact");
|
|
387
|
+
return toolResult(`Remembered (id: ${id}): ${params.text}`);
|
|
388
|
+
} catch (err) {
|
|
389
|
+
return toolResult(`crystal_remember error: ${err.message}`, true);
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
},
|
|
393
|
+
{ optional: true }
|
|
394
|
+
);
|
|
395
|
+
api.registerTool(
|
|
396
|
+
{
|
|
397
|
+
name: "crystal_forget",
|
|
398
|
+
label: "Forget Memory",
|
|
399
|
+
description: "Deprecate a memory by ID.",
|
|
400
|
+
parameters: {
|
|
401
|
+
type: "object",
|
|
402
|
+
properties: {
|
|
403
|
+
id: { type: "number", description: "Memory ID to deprecate" }
|
|
404
|
+
},
|
|
405
|
+
required: ["id"]
|
|
406
|
+
},
|
|
407
|
+
async execute(_id, params) {
|
|
408
|
+
try {
|
|
409
|
+
await ensureInit();
|
|
410
|
+
const ok = crystal.forget(params.id);
|
|
411
|
+
return toolResult(ok ? `Forgot memory ${params.id}` : `Memory ${params.id} not found`);
|
|
412
|
+
} catch (err) {
|
|
413
|
+
return toolResult(`crystal_forget error: ${err.message}`, true);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
},
|
|
417
|
+
{ optional: true }
|
|
418
|
+
);
|
|
419
|
+
api.on("before_compaction", (_event, _ctx) => {
|
|
420
|
+
try {
|
|
421
|
+
const result = runDevUpdate("lesa");
|
|
422
|
+
if (result.reposUpdated > 0) {
|
|
423
|
+
api.logger.info(`memory-crystal: auto-dev-update wrote ${result.reposUpdated} updates before compaction`);
|
|
424
|
+
}
|
|
425
|
+
} catch (err) {
|
|
426
|
+
api.logger.warn(`memory-crystal: auto-dev-update failed: ${err.message}`);
|
|
427
|
+
}
|
|
428
|
+
});
|
|
429
|
+
api.logger.info("memory-crystal plugin registered");
|
|
430
|
+
}
|
|
431
|
+
};
|
|
432
|
+
export {
|
|
433
|
+
openclaw_default as default
|
|
434
|
+
};
|
package/dist/pair.d.ts
ADDED
package/dist/pair.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import {
|
|
2
|
+
RELAY_KEY_PATH,
|
|
3
|
+
decodePairingString,
|
|
4
|
+
encodePairingString,
|
|
5
|
+
generateRelayKey,
|
|
6
|
+
loadRelayKey
|
|
7
|
+
} from "./chunk-D3MACYZ4.js";
|
|
8
|
+
import "./chunk-DFQ72B7M.js";
|
|
9
|
+
|
|
10
|
+
// src/pair.ts
|
|
11
|
+
import { existsSync, writeFileSync, mkdirSync, chmodSync } from "fs";
|
|
12
|
+
import { dirname } from "path";
|
|
13
|
+
import qrcode from "qrcode-terminal";
|
|
14
|
+
function generateQR(text) {
|
|
15
|
+
return new Promise((resolve) => {
|
|
16
|
+
qrcode.generate(text, { small: true }, (code) => {
|
|
17
|
+
resolve(code);
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
function saveKey(key) {
|
|
22
|
+
const dir = dirname(RELAY_KEY_PATH);
|
|
23
|
+
if (!existsSync(dir)) {
|
|
24
|
+
mkdirSync(dir, { recursive: true });
|
|
25
|
+
}
|
|
26
|
+
writeFileSync(RELAY_KEY_PATH, key.toString("base64") + "\n", { mode: 384 });
|
|
27
|
+
try {
|
|
28
|
+
chmodSync(RELAY_KEY_PATH, 384);
|
|
29
|
+
} catch {
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
async function pairShow() {
|
|
33
|
+
let key;
|
|
34
|
+
try {
|
|
35
|
+
key = loadRelayKey();
|
|
36
|
+
console.log("Relay key found.\n");
|
|
37
|
+
} catch {
|
|
38
|
+
console.log("No relay key found. Generating one...");
|
|
39
|
+
key = generateRelayKey();
|
|
40
|
+
saveKey(key);
|
|
41
|
+
console.log(`Key saved to ${RELAY_KEY_PATH}
|
|
42
|
+
`);
|
|
43
|
+
}
|
|
44
|
+
const pairingString = encodePairingString(key);
|
|
45
|
+
console.log("Scan this QR code from your other device:\n");
|
|
46
|
+
const qr = await generateQR(pairingString);
|
|
47
|
+
console.log(qr);
|
|
48
|
+
console.log("Or copy this pairing code:\n");
|
|
49
|
+
console.log(` ${pairingString}
|
|
50
|
+
`);
|
|
51
|
+
console.log("On the other device, run:");
|
|
52
|
+
console.log(` crystal pair --code ${pairingString}
|
|
53
|
+
`);
|
|
54
|
+
}
|
|
55
|
+
function pairReceive(code) {
|
|
56
|
+
const key = decodePairingString(code);
|
|
57
|
+
if (existsSync(RELAY_KEY_PATH)) {
|
|
58
|
+
try {
|
|
59
|
+
const existing = loadRelayKey();
|
|
60
|
+
if (existing.equals(key)) {
|
|
61
|
+
console.log("This device already has the same key. Nothing to do.");
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
console.log("Replacing existing relay key with new key from pairing code.");
|
|
65
|
+
} catch {
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
saveKey(key);
|
|
69
|
+
console.log(`Key received and saved to ${RELAY_KEY_PATH}`);
|
|
70
|
+
console.log("Relay encryption is now active on this device.");
|
|
71
|
+
}
|
|
72
|
+
export {
|
|
73
|
+
pairReceive,
|
|
74
|
+
pairShow
|
|
75
|
+
};
|
package/dist/poller.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|