@memrosetta/cli 0.3.2 → 0.4.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/dist/chunk-356QK7TK.js +533 -0
- package/dist/chunk-3LSITXZ4.js +69 -0
- package/dist/chunk-6IOTBMUB.js +570 -0
- package/dist/chunk-72IW6TAV.js +59 -0
- package/dist/chunk-BGXZ3MDD.js +341 -0
- package/dist/chunk-EZVP3OY7.js +52 -0
- package/dist/chunk-FCHV2JMZ.js +347 -0
- package/dist/{chunk-F7ZMZ6HN.js → chunk-HXZ7MAT6.js} +2 -1
- package/dist/chunk-IM6H35RB.js +341 -0
- package/dist/chunk-JGE6RXXH.js +48 -0
- package/dist/chunk-JPBSMZ26.js +343 -0
- package/dist/chunk-KSKRPUZZ.js +43 -0
- package/dist/chunk-L6S3TXHR.js +326 -0
- package/dist/chunk-MISLIVUL.js +70 -0
- package/dist/chunk-NU5ZJJXP.js +63 -0
- package/dist/{chunk-326TFH4F.js → chunk-OCCU5YEG.js} +11 -42
- package/dist/chunk-PW52BB6L.js +61 -0
- package/dist/chunk-RABFL4EN.js +528 -0
- package/dist/chunk-RDUU53MG.js +343 -0
- package/dist/chunk-RYPYJJ2K.js +70 -0
- package/dist/chunk-SEPYQK3J.js +60 -0
- package/dist/{chunk-CATBN3ZT.js → chunk-TQOH7ZXN.js} +6 -18
- package/dist/chunk-Y6NH6K27.js +209 -0
- package/dist/{clear-MTL4CQM3.js → clear-47OFIDME.js} +10 -5
- package/dist/clear-4RQW6SYW.js +39 -0
- package/dist/clear-5SZVGYBX.js +39 -0
- package/dist/clear-BYRCL5ZN.js +39 -0
- package/dist/clear-ETQ7XFMV.js +39 -0
- package/dist/clear-P6H55OKZ.js +39 -0
- package/dist/clear-T3TWJQKL.js +39 -0
- package/dist/{compress-Z46R4N4M.js → compress-HDNYPXZ3.js} +10 -5
- package/dist/compress-S6MS4QW7.js +33 -0
- package/dist/compress-SEFTKZMU.js +33 -0
- package/dist/compress-TVWXLW3L.js +33 -0
- package/dist/compress-VLYNZ5BQ.js +33 -0
- package/dist/compress-YNY6YNFU.js +33 -0
- package/dist/compress-ZXWRRGHT.js +33 -0
- package/dist/{count-4TZ3C524.js → count-26AGY5XL.js} +10 -5
- package/dist/count-AMSEVDWR.js +24 -0
- package/dist/count-AVG5ZIRW.js +24 -0
- package/dist/count-CJIYYJKN.js +24 -0
- package/dist/count-KFFD4ML7.js +24 -0
- package/dist/count-UUAD3GEJ.js +24 -0
- package/dist/count-Z67KBEMV.js +24 -0
- package/dist/feedback-QDOWDWHM.js +40 -0
- package/dist/feedback-XGBKFQXC.js +40 -0
- package/dist/{get-B6AL75EW.js → get-75MGS4LN.js} +4 -2
- package/dist/get-NY5H3MUA.js +30 -0
- package/dist/hooks/on-prompt.js +2 -2
- package/dist/hooks/on-stop.js +2 -2
- package/dist/index.js +35 -18
- package/dist/ingest-A3BAI2C4.js +95 -0
- package/dist/ingest-E7QDD5NY.js +95 -0
- package/dist/ingest-GSJMWDV5.js +95 -0
- package/dist/ingest-IGI7RXR4.js +95 -0
- package/dist/ingest-JPIHSH7W.js +95 -0
- package/dist/ingest-QGXA4Y6C.js +95 -0
- package/dist/ingest-TZEVA25F.js +95 -0
- package/dist/init-2PRW64KV.js +146 -0
- package/dist/init-C3CONL23.js +146 -0
- package/dist/init-DAKOWQSW.js +169 -0
- package/dist/init-FYPMJDRN.js +146 -0
- package/dist/{init-C335O4TX.js → init-GCT4XEI6.js} +2 -2
- package/dist/init-GRVRJ6RO.js +205 -0
- package/dist/init-HBEIXY3N.js +146 -0
- package/dist/init-LK4UQISR.js +205 -0
- package/dist/init-MISGIVCC.js +146 -0
- package/dist/init-MNM4TXXJ.js +146 -0
- package/dist/{init-YAGOXYWG.js → init-OQW3KXTR.js} +2 -2
- package/dist/init-SIEKAILM.js +113 -0
- package/dist/init-TM7GTHTJ.js +146 -0
- package/dist/init-VYWOSISP.js +146 -0
- package/dist/init-WCL7FZOJ.js +182 -0
- package/dist/init-ZLUDTJAP.js +182 -0
- package/dist/invalidate-BY5VNFSE.js +25 -0
- package/dist/{invalidate-C54IVIGL.js → invalidate-D2O4VWZU.js} +4 -2
- package/dist/{maintain-ZPHG47YY.js → maintain-B65WIMGJ.js} +10 -5
- package/dist/maintain-EWOU3DGT.js +37 -0
- package/dist/maintain-FELKLG7O.js +37 -0
- package/dist/maintain-SGM56XKE.js +37 -0
- package/dist/maintain-VX2VWB2L.js +37 -0
- package/dist/maintain-WRRDXEG3.js +37 -0
- package/dist/maintain-XTCSOQBU.js +37 -0
- package/dist/{relate-R6DQUJCQ.js → relate-2QMG5H2I.js} +5 -3
- package/dist/relate-C22YYJZT.js +46 -0
- package/dist/relate-L5464WV5.js +47 -0
- package/dist/relate-SGZLG7JU.js +47 -0
- package/dist/relate-V5RYMJJ5.js +47 -0
- package/dist/relate-W4BXPFJA.js +46 -0
- package/dist/reset-45EUG44R.js +95 -0
- package/dist/reset-5NDHFUC3.js +95 -0
- package/dist/reset-C7I3LA5M.js +95 -0
- package/dist/reset-CYY4KYAB.js +129 -0
- package/dist/reset-F6F2R6BR.js +95 -0
- package/dist/reset-K3K4K5CT.js +95 -0
- package/dist/reset-K4WZJ4WU.js +95 -0
- package/dist/{reset-P63V46RN.js → reset-NNQQJN6L.js} +2 -2
- package/dist/{reset-GPV46GSD.js → reset-P5FXLI4E.js} +2 -2
- package/dist/reset-SORHIEKY.js +112 -0
- package/dist/reset-SVJMWYAK.js +95 -0
- package/dist/reset-W22RJGYZ.js +112 -0
- package/dist/reset-W3QVA632.js +95 -0
- package/dist/reset-WYEU6XJQ.js +112 -0
- package/dist/{search-YEYKOEXC.js → search-2SU5WQYK.js} +9 -4
- package/dist/search-5EE3XB2R.js +48 -0
- package/dist/search-BJ2YV5IS.js +48 -0
- package/dist/search-L6P3XY47.js +48 -0
- package/dist/search-PT4POELX.js +48 -0
- package/dist/search-UA7Y55LQ.js +48 -0
- package/dist/search-ZKLRJXFT.js +48 -0
- package/dist/status-3XVXJF7M.js +170 -0
- package/dist/status-4THJLSJL.js +131 -0
- package/dist/status-4UYY7TOE.js +131 -0
- package/dist/status-7G3RMR6A.js +139 -0
- package/dist/status-7M4TJVDH.js +170 -0
- package/dist/status-7MEEKEC2.js +131 -0
- package/dist/status-BQL4VJ6Y.js +149 -0
- package/dist/status-BTEVCZ5K.js +125 -0
- package/dist/status-F3NZGGPH.js +131 -0
- package/dist/status-GQMXOMRN.js +131 -0
- package/dist/status-HJGTMHTD.js +131 -0
- package/dist/{status-AMMF6QGI.js → status-IEKR6SSH.js} +35 -6
- package/dist/status-JJGVWESB.js +139 -0
- package/dist/status-LDVRVYZH.js +131 -0
- package/dist/{status-XNQRRFWF.js → status-TATIX3R6.js} +1 -1
- package/dist/{status-PYD6U7U7.js → status-TVY32MZD.js} +10 -3
- package/dist/{store-ZMERYHI6.js → store-2USP33HQ.js} +12 -7
- package/dist/store-6D5OJ2DX.js +91 -0
- package/dist/store-I4JNJWAZ.js +91 -0
- package/dist/store-R4LXYE57.js +91 -0
- package/dist/store-UMR2NOT7.js +91 -0
- package/dist/store-XCFYGYBE.js +91 -0
- package/dist/store-ZDI5AH4M.js +91 -0
- package/dist/sync-643GTA5X.js +319 -0
- package/dist/sync-BPVMHW34.js +319 -0
- package/dist/sync-OZQLBYT2.js +317 -0
- package/dist/sync-WURX2HJZ.js +321 -0
- package/dist/update-XJLMXCDZ.js +36 -0
- package/dist/{working-memory-2RRQFX4Q.js → working-memory-2U33JHJB.js} +10 -6
- package/dist/working-memory-35TMFU3P.js +53 -0
- package/dist/working-memory-IBWGIXLW.js +53 -0
- package/dist/working-memory-RZE3GYQZ.js +53 -0
- package/dist/working-memory-UYVEJJYW.js +53 -0
- package/dist/working-memory-VP6L2QV6.js +53 -0
- package/dist/working-memory-WGB5DZ3B.js +53 -0
- package/package.json +5 -4
- package/dist/chunk-MWLPPS7U.js +0 -133
- package/dist/ingest-ZOR3XSAE.js +0 -152
- package/dist/init-7VFBCA4O.js +0 -26
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
import {
|
|
2
|
+
hasFlag,
|
|
3
|
+
optionalOption,
|
|
4
|
+
requireOption
|
|
5
|
+
} from "./chunk-NU5ZJJXP.js";
|
|
6
|
+
import {
|
|
7
|
+
output,
|
|
8
|
+
outputError
|
|
9
|
+
} from "./chunk-ET6TNQOJ.js";
|
|
10
|
+
import {
|
|
11
|
+
getConfig,
|
|
12
|
+
getDefaultDbPath,
|
|
13
|
+
writeConfig
|
|
14
|
+
} from "./chunk-SEPYQK3J.js";
|
|
15
|
+
|
|
16
|
+
// src/commands/sync.ts
|
|
17
|
+
import { randomUUID } from "crypto";
|
|
18
|
+
import { userInfo } from "os";
|
|
19
|
+
function parseSubcommand(args) {
|
|
20
|
+
const first = args[0];
|
|
21
|
+
if (!first || first.startsWith("--")) return null;
|
|
22
|
+
if (first === "enable" || first === "disable" || first === "status" || first === "now" || first === "device-id") {
|
|
23
|
+
return first;
|
|
24
|
+
}
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
async function readHiddenInput(prompt) {
|
|
28
|
+
const stdin = process.stdin;
|
|
29
|
+
const stdout = process.stdout;
|
|
30
|
+
if (!stdin.isTTY) {
|
|
31
|
+
throw new Error("Interactive input requires a TTY. Use --key-stdin to pipe the key instead.");
|
|
32
|
+
}
|
|
33
|
+
stdout.write(prompt);
|
|
34
|
+
const wasRaw = stdin.isRaw;
|
|
35
|
+
stdin.setRawMode(true);
|
|
36
|
+
stdin.resume();
|
|
37
|
+
stdin.setEncoding("utf-8");
|
|
38
|
+
return new Promise((resolve, reject) => {
|
|
39
|
+
let buffer = "";
|
|
40
|
+
const onData = (chunk) => {
|
|
41
|
+
for (const ch of chunk) {
|
|
42
|
+
const code = ch.charCodeAt(0);
|
|
43
|
+
if (code === 13 || code === 10) {
|
|
44
|
+
stdin.removeListener("data", onData);
|
|
45
|
+
stdin.setRawMode(wasRaw);
|
|
46
|
+
stdin.pause();
|
|
47
|
+
stdout.write("\n");
|
|
48
|
+
resolve(buffer);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if (code === 3) {
|
|
52
|
+
stdin.removeListener("data", onData);
|
|
53
|
+
stdin.setRawMode(wasRaw);
|
|
54
|
+
stdin.pause();
|
|
55
|
+
stdout.write("\n");
|
|
56
|
+
reject(new Error("Aborted"));
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
if (code === 127 || code === 8) {
|
|
60
|
+
buffer = buffer.slice(0, -1);
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
buffer += ch;
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
stdin.on("data", onData);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
async function readStdinKey() {
|
|
70
|
+
const chunks = [];
|
|
71
|
+
for await (const chunk of process.stdin) {
|
|
72
|
+
chunks.push(chunk);
|
|
73
|
+
}
|
|
74
|
+
return Buffer.concat(chunks).toString("utf-8").trim();
|
|
75
|
+
}
|
|
76
|
+
async function testConnection(serverUrl, apiKey) {
|
|
77
|
+
const url = `${serverUrl.replace(/\/$/, "")}/sync/health`;
|
|
78
|
+
try {
|
|
79
|
+
const res = await fetch(url, {
|
|
80
|
+
headers: { Authorization: `Bearer ${apiKey}` }
|
|
81
|
+
});
|
|
82
|
+
if (!res.ok) {
|
|
83
|
+
throw new Error(`HTTP ${res.status} ${res.statusText}`);
|
|
84
|
+
}
|
|
85
|
+
} catch (err) {
|
|
86
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
87
|
+
throw new Error(`Sync server health check failed: ${msg}`);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
async function withSyncClient(dbPath, config, fn) {
|
|
91
|
+
const Database = (await import("better-sqlite3")).default;
|
|
92
|
+
const { SyncClient, ensureSyncSchema } = await import("@memrosetta/sync-client");
|
|
93
|
+
if (!config.syncServerUrl || !config.syncApiKey || !config.syncDeviceId) {
|
|
94
|
+
throw new Error("Sync is not configured. Run: memrosetta sync enable --server <url>");
|
|
95
|
+
}
|
|
96
|
+
const db = new Database(dbPath);
|
|
97
|
+
try {
|
|
98
|
+
ensureSyncSchema(db);
|
|
99
|
+
const client = new SyncClient(db, {
|
|
100
|
+
serverUrl: config.syncServerUrl,
|
|
101
|
+
apiKey: config.syncApiKey,
|
|
102
|
+
deviceId: config.syncDeviceId,
|
|
103
|
+
userId: userInfo().username
|
|
104
|
+
});
|
|
105
|
+
return await fn(client, db);
|
|
106
|
+
} finally {
|
|
107
|
+
db.close();
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
async function runEnable(options) {
|
|
111
|
+
const { args, format } = options;
|
|
112
|
+
let serverUrl;
|
|
113
|
+
try {
|
|
114
|
+
serverUrl = requireOption(args, "--server", "server URL");
|
|
115
|
+
} catch (err) {
|
|
116
|
+
outputError(err instanceof Error ? err.message : String(err), format);
|
|
117
|
+
process.exitCode = 1;
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
let apiKey = optionalOption(args, "--key");
|
|
121
|
+
if (hasFlag(args, "--key-stdin")) {
|
|
122
|
+
apiKey = await readStdinKey();
|
|
123
|
+
}
|
|
124
|
+
if (!apiKey) {
|
|
125
|
+
try {
|
|
126
|
+
apiKey = await readHiddenInput("API key: ");
|
|
127
|
+
} catch (err) {
|
|
128
|
+
outputError(err instanceof Error ? err.message : String(err), format);
|
|
129
|
+
process.exitCode = 1;
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
if (!apiKey) {
|
|
134
|
+
outputError("API key is required", format);
|
|
135
|
+
process.exitCode = 1;
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
const skipTest = hasFlag(args, "--no-test");
|
|
139
|
+
if (!skipTest) {
|
|
140
|
+
try {
|
|
141
|
+
await testConnection(serverUrl, apiKey);
|
|
142
|
+
} catch (err) {
|
|
143
|
+
outputError(
|
|
144
|
+
`${err instanceof Error ? err.message : String(err)}
|
|
145
|
+
Use --no-test to skip the health check.`,
|
|
146
|
+
format
|
|
147
|
+
);
|
|
148
|
+
process.exitCode = 1;
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
const existing = getConfig();
|
|
153
|
+
const deviceId = existing.syncDeviceId ?? `device-${randomUUID().slice(0, 8)}`;
|
|
154
|
+
writeConfig({
|
|
155
|
+
...existing,
|
|
156
|
+
syncEnabled: true,
|
|
157
|
+
syncServerUrl: serverUrl,
|
|
158
|
+
syncApiKey: apiKey,
|
|
159
|
+
syncDeviceId: deviceId
|
|
160
|
+
});
|
|
161
|
+
if (format === "text") {
|
|
162
|
+
process.stdout.write("Sync enabled.\n");
|
|
163
|
+
process.stdout.write(` Server: ${serverUrl}
|
|
164
|
+
`);
|
|
165
|
+
process.stdout.write(` DeviceId: ${deviceId}
|
|
166
|
+
`);
|
|
167
|
+
if (skipTest) {
|
|
168
|
+
process.stdout.write(" (health check skipped)\n");
|
|
169
|
+
}
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
output({ enabled: true, serverUrl, deviceId, healthCheckSkipped: skipTest }, format);
|
|
173
|
+
}
|
|
174
|
+
function runDisable(options) {
|
|
175
|
+
const { format } = options;
|
|
176
|
+
const existing = getConfig();
|
|
177
|
+
writeConfig({
|
|
178
|
+
...existing,
|
|
179
|
+
syncEnabled: false
|
|
180
|
+
});
|
|
181
|
+
if (format === "text") {
|
|
182
|
+
process.stdout.write("Sync disabled. (server URL and API key preserved for re-enable)\n");
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
output({ enabled: false }, format);
|
|
186
|
+
}
|
|
187
|
+
async function runStatus(options) {
|
|
188
|
+
const { format, db } = options;
|
|
189
|
+
const config = getConfig();
|
|
190
|
+
const dbPath = db ?? config.dbPath ?? getDefaultDbPath();
|
|
191
|
+
if (!config.syncEnabled) {
|
|
192
|
+
if (format === "text") {
|
|
193
|
+
process.stdout.write("Sync: disabled\n");
|
|
194
|
+
if (config.syncServerUrl) {
|
|
195
|
+
process.stdout.write(` Server: ${config.syncServerUrl}
|
|
196
|
+
`);
|
|
197
|
+
}
|
|
198
|
+
if (config.syncDeviceId) {
|
|
199
|
+
process.stdout.write(` DeviceId: ${config.syncDeviceId}
|
|
200
|
+
`);
|
|
201
|
+
}
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
output(
|
|
205
|
+
{
|
|
206
|
+
enabled: false,
|
|
207
|
+
serverUrl: config.syncServerUrl ?? null,
|
|
208
|
+
deviceId: config.syncDeviceId ?? null
|
|
209
|
+
},
|
|
210
|
+
format
|
|
211
|
+
);
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
try {
|
|
215
|
+
const status = await withSyncClient(dbPath, config, async (client) => client.getStatus());
|
|
216
|
+
if (format === "text") {
|
|
217
|
+
process.stdout.write("Sync: enabled\n");
|
|
218
|
+
process.stdout.write(` Server: ${status.serverUrl}
|
|
219
|
+
`);
|
|
220
|
+
process.stdout.write(` DeviceId: ${status.deviceId}
|
|
221
|
+
`);
|
|
222
|
+
process.stdout.write(` Pending ops: ${status.pendingOps}
|
|
223
|
+
`);
|
|
224
|
+
process.stdout.write(` Current cursor: ${status.cursor}
|
|
225
|
+
`);
|
|
226
|
+
process.stdout.write(
|
|
227
|
+
` Last push: ${status.lastPush.successAt ?? "never"}` + (status.lastPush.attemptAt && status.lastPush.attemptAt !== status.lastPush.successAt ? ` (last attempt: ${status.lastPush.attemptAt})` : "") + "\n"
|
|
228
|
+
);
|
|
229
|
+
process.stdout.write(
|
|
230
|
+
` Last pull: ${status.lastPull.successAt ?? "never"}` + (status.lastPull.attemptAt && status.lastPull.attemptAt !== status.lastPull.successAt ? ` (last attempt: ${status.lastPull.attemptAt})` : "") + "\n"
|
|
231
|
+
);
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
output(status, format);
|
|
235
|
+
} catch (err) {
|
|
236
|
+
outputError(err instanceof Error ? err.message : String(err), format);
|
|
237
|
+
process.exitCode = 1;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
async function runNow(options) {
|
|
241
|
+
const { args, format, db } = options;
|
|
242
|
+
const config = getConfig();
|
|
243
|
+
const dbPath = db ?? config.dbPath ?? getDefaultDbPath();
|
|
244
|
+
if (!config.syncEnabled) {
|
|
245
|
+
outputError("Sync is disabled. Run: memrosetta sync enable --server <url>", format);
|
|
246
|
+
process.exitCode = 1;
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
const pushOnly = hasFlag(args, "--push-only");
|
|
250
|
+
const pullOnly = hasFlag(args, "--pull-only");
|
|
251
|
+
try {
|
|
252
|
+
const result = await withSyncClient(dbPath, config, async (client) => {
|
|
253
|
+
let pushed = 0;
|
|
254
|
+
let pulled = 0;
|
|
255
|
+
if (!pullOnly) {
|
|
256
|
+
const pushResult = await client.push();
|
|
257
|
+
pushed = pushResult.pushed;
|
|
258
|
+
}
|
|
259
|
+
if (!pushOnly) {
|
|
260
|
+
pulled = await client.pull();
|
|
261
|
+
}
|
|
262
|
+
return { pushed, pulled };
|
|
263
|
+
});
|
|
264
|
+
if (format === "text") {
|
|
265
|
+
process.stdout.write(`Sync complete. pushed=${result.pushed} pulled=${result.pulled}
|
|
266
|
+
`);
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
output(result, format);
|
|
270
|
+
} catch (err) {
|
|
271
|
+
outputError(err instanceof Error ? err.message : String(err), format);
|
|
272
|
+
process.exitCode = 1;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
function runDeviceId(options) {
|
|
276
|
+
const { format } = options;
|
|
277
|
+
const config = getConfig();
|
|
278
|
+
if (!config.syncDeviceId) {
|
|
279
|
+
outputError("No deviceId set. Run: memrosetta sync enable --server <url>", format);
|
|
280
|
+
process.exitCode = 1;
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
if (format === "text") {
|
|
284
|
+
process.stdout.write(`${config.syncDeviceId}
|
|
285
|
+
`);
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
output({ deviceId: config.syncDeviceId }, format);
|
|
289
|
+
}
|
|
290
|
+
async function run(options) {
|
|
291
|
+
const sub = parseSubcommand(options.args);
|
|
292
|
+
if (!sub) {
|
|
293
|
+
outputError(
|
|
294
|
+
"Usage: memrosetta sync <enable|disable|status|now|device-id>\n\n enable --server <url> [--key <key> | --key-stdin] [--no-test]\n disable\n status\n now [--push-only | --pull-only]\n device-id\n",
|
|
295
|
+
options.format
|
|
296
|
+
);
|
|
297
|
+
process.exitCode = 1;
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
const rest = { ...options, args: options.args.slice(1) };
|
|
301
|
+
switch (sub) {
|
|
302
|
+
case "enable":
|
|
303
|
+
await runEnable(rest);
|
|
304
|
+
return;
|
|
305
|
+
case "disable":
|
|
306
|
+
runDisable(rest);
|
|
307
|
+
return;
|
|
308
|
+
case "status":
|
|
309
|
+
await runStatus(rest);
|
|
310
|
+
return;
|
|
311
|
+
case "now":
|
|
312
|
+
await runNow(rest);
|
|
313
|
+
return;
|
|
314
|
+
case "device-id":
|
|
315
|
+
runDeviceId(rest);
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
export {
|
|
320
|
+
run
|
|
321
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// src/commands/update.ts
|
|
2
|
+
import { execSync } from "child_process";
|
|
3
|
+
import { createRequire } from "module";
|
|
4
|
+
async function run() {
|
|
5
|
+
const require2 = createRequire(import.meta.url);
|
|
6
|
+
const pkg = require2("../../package.json");
|
|
7
|
+
const current = pkg.version;
|
|
8
|
+
process.stdout.write(`Current version: ${current}
|
|
9
|
+
`);
|
|
10
|
+
process.stdout.write("Checking for updates...\n");
|
|
11
|
+
try {
|
|
12
|
+
const latest = execSync("npm view @memrosetta/cli version", { encoding: "utf-8" }).trim();
|
|
13
|
+
if (latest === current) {
|
|
14
|
+
process.stdout.write(`Already up to date (${current}).
|
|
15
|
+
`);
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
process.stdout.write(`New version available: ${latest}
|
|
19
|
+
`);
|
|
20
|
+
process.stdout.write("Updating...\n");
|
|
21
|
+
execSync("npm install -g @memrosetta/cli@latest --force", {
|
|
22
|
+
stdio: "inherit"
|
|
23
|
+
});
|
|
24
|
+
process.stdout.write(`
|
|
25
|
+
Updated: ${current} -> ${latest}
|
|
26
|
+
`);
|
|
27
|
+
} catch (err) {
|
|
28
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
29
|
+
process.stderr.write(`Update failed: ${message}
|
|
30
|
+
`);
|
|
31
|
+
process.exitCode = 1;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export {
|
|
35
|
+
run
|
|
36
|
+
};
|
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
import {
|
|
2
|
-
optionalOption
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
optionalOption
|
|
3
|
+
} from "./chunk-PW52BB6L.js";
|
|
4
|
+
import {
|
|
5
|
+
getDefaultUserId
|
|
6
|
+
} from "./chunk-TU5EHSDE.js";
|
|
7
|
+
import {
|
|
8
|
+
getEngine
|
|
9
|
+
} from "./chunk-2ZBEEETG.js";
|
|
5
10
|
import {
|
|
6
|
-
getEngine,
|
|
7
11
|
output
|
|
8
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-ET6TNQOJ.js";
|
|
9
13
|
|
|
10
14
|
// src/commands/working-memory.ts
|
|
11
15
|
async function run(options) {
|
|
12
16
|
const { args, format, db, noEmbeddings } = options;
|
|
13
|
-
const userId =
|
|
17
|
+
const userId = optionalOption(args, "--user") ?? getDefaultUserId();
|
|
14
18
|
const maxTokensStr = optionalOption(args, "--max-tokens");
|
|
15
19
|
const maxTokens = maxTokensStr ? parseInt(maxTokensStr, 10) : void 0;
|
|
16
20
|
if (maxTokens !== void 0 && (isNaN(maxTokens) || maxTokens <= 0)) {
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import {
|
|
2
|
+
optionalOption
|
|
3
|
+
} from "./chunk-HXZ7MAT6.js";
|
|
4
|
+
import {
|
|
5
|
+
getDefaultUserId
|
|
6
|
+
} from "./chunk-KSKRPUZZ.js";
|
|
7
|
+
import {
|
|
8
|
+
getEngine
|
|
9
|
+
} from "./chunk-EZVP3OY7.js";
|
|
10
|
+
import {
|
|
11
|
+
output
|
|
12
|
+
} from "./chunk-ET6TNQOJ.js";
|
|
13
|
+
|
|
14
|
+
// src/commands/working-memory.ts
|
|
15
|
+
async function run(options) {
|
|
16
|
+
const { args, format, db, noEmbeddings } = options;
|
|
17
|
+
const userId = optionalOption(args, "--user") ?? getDefaultUserId();
|
|
18
|
+
const maxTokensStr = optionalOption(args, "--max-tokens");
|
|
19
|
+
const maxTokens = maxTokensStr ? parseInt(maxTokensStr, 10) : void 0;
|
|
20
|
+
if (maxTokens !== void 0 && (isNaN(maxTokens) || maxTokens <= 0)) {
|
|
21
|
+
throw new Error("--max-tokens must be a positive integer");
|
|
22
|
+
}
|
|
23
|
+
const engine = await getEngine({ db, noEmbeddings });
|
|
24
|
+
const memories = await engine.workingMemory(userId, maxTokens);
|
|
25
|
+
if (format === "text") {
|
|
26
|
+
if (memories.length === 0) {
|
|
27
|
+
process.stdout.write("No working memory found.\n");
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const totalTokens = memories.reduce(
|
|
31
|
+
(sum, m) => sum + Math.ceil(m.content.length / 4),
|
|
32
|
+
0
|
|
33
|
+
);
|
|
34
|
+
for (const memory of memories) {
|
|
35
|
+
const tier = memory.tier.toUpperCase();
|
|
36
|
+
const score = memory.activationScore.toFixed(2);
|
|
37
|
+
process.stdout.write(
|
|
38
|
+
`[${tier}|${score}] ${memory.content} (${memory.memoryType})
|
|
39
|
+
`
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
process.stdout.write(
|
|
43
|
+
`
|
|
44
|
+
${memories.length} memories, ~${totalTokens} tokens
|
|
45
|
+
`
|
|
46
|
+
);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
output({ userId, maxTokens: maxTokens ?? 3e3, memories }, format);
|
|
50
|
+
}
|
|
51
|
+
export {
|
|
52
|
+
run
|
|
53
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import {
|
|
2
|
+
optionalOption
|
|
3
|
+
} from "./chunk-TGGGIJC4.js";
|
|
4
|
+
import {
|
|
5
|
+
getEngine
|
|
6
|
+
} from "./chunk-POK32V2J.js";
|
|
7
|
+
import {
|
|
8
|
+
output
|
|
9
|
+
} from "./chunk-ET6TNQOJ.js";
|
|
10
|
+
import {
|
|
11
|
+
getDefaultUserId
|
|
12
|
+
} from "./chunk-TU5EHSDE.js";
|
|
13
|
+
|
|
14
|
+
// src/commands/working-memory.ts
|
|
15
|
+
async function run(options) {
|
|
16
|
+
const { args, format, db, noEmbeddings } = options;
|
|
17
|
+
const userId = optionalOption(args, "--user") ?? getDefaultUserId();
|
|
18
|
+
const maxTokensStr = optionalOption(args, "--max-tokens");
|
|
19
|
+
const maxTokens = maxTokensStr ? parseInt(maxTokensStr, 10) : void 0;
|
|
20
|
+
if (maxTokens !== void 0 && (isNaN(maxTokens) || maxTokens <= 0)) {
|
|
21
|
+
throw new Error("--max-tokens must be a positive integer");
|
|
22
|
+
}
|
|
23
|
+
const engine = await getEngine({ db, noEmbeddings });
|
|
24
|
+
const memories = await engine.workingMemory(userId, maxTokens);
|
|
25
|
+
if (format === "text") {
|
|
26
|
+
if (memories.length === 0) {
|
|
27
|
+
process.stdout.write("No working memory found.\n");
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const totalTokens = memories.reduce(
|
|
31
|
+
(sum, m) => sum + Math.ceil(m.content.length / 4),
|
|
32
|
+
0
|
|
33
|
+
);
|
|
34
|
+
for (const memory of memories) {
|
|
35
|
+
const tier = memory.tier.toUpperCase();
|
|
36
|
+
const score = memory.activationScore.toFixed(2);
|
|
37
|
+
process.stdout.write(
|
|
38
|
+
`[${tier}|${score}] ${memory.content} (${memory.memoryType})
|
|
39
|
+
`
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
process.stdout.write(
|
|
43
|
+
`
|
|
44
|
+
${memories.length} memories, ~${totalTokens} tokens
|
|
45
|
+
`
|
|
46
|
+
);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
output({ userId, maxTokens: maxTokens ?? 3e3, memories }, format);
|
|
50
|
+
}
|
|
51
|
+
export {
|
|
52
|
+
run
|
|
53
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import {
|
|
2
|
+
optionalOption
|
|
3
|
+
} from "./chunk-HXZ7MAT6.js";
|
|
4
|
+
import {
|
|
5
|
+
getDefaultUserId
|
|
6
|
+
} from "./chunk-TU5EHSDE.js";
|
|
7
|
+
import {
|
|
8
|
+
getEngine
|
|
9
|
+
} from "./chunk-2ZBEEETG.js";
|
|
10
|
+
import {
|
|
11
|
+
output
|
|
12
|
+
} from "./chunk-ET6TNQOJ.js";
|
|
13
|
+
|
|
14
|
+
// src/commands/working-memory.ts
|
|
15
|
+
async function run(options) {
|
|
16
|
+
const { args, format, db, noEmbeddings } = options;
|
|
17
|
+
const userId = optionalOption(args, "--user") ?? getDefaultUserId();
|
|
18
|
+
const maxTokensStr = optionalOption(args, "--max-tokens");
|
|
19
|
+
const maxTokens = maxTokensStr ? parseInt(maxTokensStr, 10) : void 0;
|
|
20
|
+
if (maxTokens !== void 0 && (isNaN(maxTokens) || maxTokens <= 0)) {
|
|
21
|
+
throw new Error("--max-tokens must be a positive integer");
|
|
22
|
+
}
|
|
23
|
+
const engine = await getEngine({ db, noEmbeddings });
|
|
24
|
+
const memories = await engine.workingMemory(userId, maxTokens);
|
|
25
|
+
if (format === "text") {
|
|
26
|
+
if (memories.length === 0) {
|
|
27
|
+
process.stdout.write("No working memory found.\n");
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const totalTokens = memories.reduce(
|
|
31
|
+
(sum, m) => sum + Math.ceil(m.content.length / 4),
|
|
32
|
+
0
|
|
33
|
+
);
|
|
34
|
+
for (const memory of memories) {
|
|
35
|
+
const tier = memory.tier.toUpperCase();
|
|
36
|
+
const score = memory.activationScore.toFixed(2);
|
|
37
|
+
process.stdout.write(
|
|
38
|
+
`[${tier}|${score}] ${memory.content} (${memory.memoryType})
|
|
39
|
+
`
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
process.stdout.write(
|
|
43
|
+
`
|
|
44
|
+
${memories.length} memories, ~${totalTokens} tokens
|
|
45
|
+
`
|
|
46
|
+
);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
output({ userId, maxTokens: maxTokens ?? 3e3, memories }, format);
|
|
50
|
+
}
|
|
51
|
+
export {
|
|
52
|
+
run
|
|
53
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import {
|
|
2
|
+
optionalOption
|
|
3
|
+
} from "./chunk-NU5ZJJXP.js";
|
|
4
|
+
import {
|
|
5
|
+
getEngine
|
|
6
|
+
} from "./chunk-72IW6TAV.js";
|
|
7
|
+
import {
|
|
8
|
+
output
|
|
9
|
+
} from "./chunk-ET6TNQOJ.js";
|
|
10
|
+
import {
|
|
11
|
+
getDefaultUserId
|
|
12
|
+
} from "./chunk-SEPYQK3J.js";
|
|
13
|
+
|
|
14
|
+
// src/commands/working-memory.ts
|
|
15
|
+
async function run(options) {
|
|
16
|
+
const { args, format, db, noEmbeddings } = options;
|
|
17
|
+
const userId = optionalOption(args, "--user") ?? getDefaultUserId();
|
|
18
|
+
const maxTokensStr = optionalOption(args, "--max-tokens");
|
|
19
|
+
const maxTokens = maxTokensStr ? parseInt(maxTokensStr, 10) : void 0;
|
|
20
|
+
if (maxTokens !== void 0 && (isNaN(maxTokens) || maxTokens <= 0)) {
|
|
21
|
+
throw new Error("--max-tokens must be a positive integer");
|
|
22
|
+
}
|
|
23
|
+
const engine = await getEngine({ db, noEmbeddings });
|
|
24
|
+
const memories = await engine.workingMemory(userId, maxTokens);
|
|
25
|
+
if (format === "text") {
|
|
26
|
+
if (memories.length === 0) {
|
|
27
|
+
process.stdout.write("No working memory found.\n");
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const totalTokens = memories.reduce(
|
|
31
|
+
(sum, m) => sum + Math.ceil(m.content.length / 4),
|
|
32
|
+
0
|
|
33
|
+
);
|
|
34
|
+
for (const memory of memories) {
|
|
35
|
+
const tier = memory.tier.toUpperCase();
|
|
36
|
+
const score = memory.activationScore.toFixed(2);
|
|
37
|
+
process.stdout.write(
|
|
38
|
+
`[${tier}|${score}] ${memory.content} (${memory.memoryType})
|
|
39
|
+
`
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
process.stdout.write(
|
|
43
|
+
`
|
|
44
|
+
${memories.length} memories, ~${totalTokens} tokens
|
|
45
|
+
`
|
|
46
|
+
);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
output({ userId, maxTokens: maxTokens ?? 3e3, memories }, format);
|
|
50
|
+
}
|
|
51
|
+
export {
|
|
52
|
+
run
|
|
53
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import {
|
|
2
|
+
optionalOption
|
|
3
|
+
} from "./chunk-VZQURGWB.js";
|
|
4
|
+
import {
|
|
5
|
+
getEngine
|
|
6
|
+
} from "./chunk-72IW6TAV.js";
|
|
7
|
+
import {
|
|
8
|
+
output
|
|
9
|
+
} from "./chunk-ET6TNQOJ.js";
|
|
10
|
+
import {
|
|
11
|
+
getDefaultUserId
|
|
12
|
+
} from "./chunk-SEPYQK3J.js";
|
|
13
|
+
|
|
14
|
+
// src/commands/working-memory.ts
|
|
15
|
+
async function run(options) {
|
|
16
|
+
const { args, format, db, noEmbeddings } = options;
|
|
17
|
+
const userId = optionalOption(args, "--user") ?? getDefaultUserId();
|
|
18
|
+
const maxTokensStr = optionalOption(args, "--max-tokens");
|
|
19
|
+
const maxTokens = maxTokensStr ? parseInt(maxTokensStr, 10) : void 0;
|
|
20
|
+
if (maxTokens !== void 0 && (isNaN(maxTokens) || maxTokens <= 0)) {
|
|
21
|
+
throw new Error("--max-tokens must be a positive integer");
|
|
22
|
+
}
|
|
23
|
+
const engine = await getEngine({ db, noEmbeddings });
|
|
24
|
+
const memories = await engine.workingMemory(userId, maxTokens);
|
|
25
|
+
if (format === "text") {
|
|
26
|
+
if (memories.length === 0) {
|
|
27
|
+
process.stdout.write("No working memory found.\n");
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const totalTokens = memories.reduce(
|
|
31
|
+
(sum, m) => sum + Math.ceil(m.content.length / 4),
|
|
32
|
+
0
|
|
33
|
+
);
|
|
34
|
+
for (const memory of memories) {
|
|
35
|
+
const tier = memory.tier.toUpperCase();
|
|
36
|
+
const score = memory.activationScore.toFixed(2);
|
|
37
|
+
process.stdout.write(
|
|
38
|
+
`[${tier}|${score}] ${memory.content} (${memory.memoryType})
|
|
39
|
+
`
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
process.stdout.write(
|
|
43
|
+
`
|
|
44
|
+
${memories.length} memories, ~${totalTokens} tokens
|
|
45
|
+
`
|
|
46
|
+
);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
output({ userId, maxTokens: maxTokens ?? 3e3, memories }, format);
|
|
50
|
+
}
|
|
51
|
+
export {
|
|
52
|
+
run
|
|
53
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import {
|
|
2
|
+
optionalOption
|
|
3
|
+
} from "./chunk-HXZ7MAT6.js";
|
|
4
|
+
import {
|
|
5
|
+
getDefaultUserId
|
|
6
|
+
} from "./chunk-JGE6RXXH.js";
|
|
7
|
+
import {
|
|
8
|
+
getEngine
|
|
9
|
+
} from "./chunk-2ZBEEETG.js";
|
|
10
|
+
import {
|
|
11
|
+
output
|
|
12
|
+
} from "./chunk-ET6TNQOJ.js";
|
|
13
|
+
|
|
14
|
+
// src/commands/working-memory.ts
|
|
15
|
+
async function run(options) {
|
|
16
|
+
const { args, format, db, noEmbeddings } = options;
|
|
17
|
+
const userId = optionalOption(args, "--user") ?? getDefaultUserId();
|
|
18
|
+
const maxTokensStr = optionalOption(args, "--max-tokens");
|
|
19
|
+
const maxTokens = maxTokensStr ? parseInt(maxTokensStr, 10) : void 0;
|
|
20
|
+
if (maxTokens !== void 0 && (isNaN(maxTokens) || maxTokens <= 0)) {
|
|
21
|
+
throw new Error("--max-tokens must be a positive integer");
|
|
22
|
+
}
|
|
23
|
+
const engine = await getEngine({ db, noEmbeddings });
|
|
24
|
+
const memories = await engine.workingMemory(userId, maxTokens);
|
|
25
|
+
if (format === "text") {
|
|
26
|
+
if (memories.length === 0) {
|
|
27
|
+
process.stdout.write("No working memory found.\n");
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const totalTokens = memories.reduce(
|
|
31
|
+
(sum, m) => sum + Math.ceil(m.content.length / 4),
|
|
32
|
+
0
|
|
33
|
+
);
|
|
34
|
+
for (const memory of memories) {
|
|
35
|
+
const tier = memory.tier.toUpperCase();
|
|
36
|
+
const score = memory.activationScore.toFixed(2);
|
|
37
|
+
process.stdout.write(
|
|
38
|
+
`[${tier}|${score}] ${memory.content} (${memory.memoryType})
|
|
39
|
+
`
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
process.stdout.write(
|
|
43
|
+
`
|
|
44
|
+
${memories.length} memories, ~${totalTokens} tokens
|
|
45
|
+
`
|
|
46
|
+
);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
output({ userId, maxTokens: maxTokens ?? 3e3, memories }, format);
|
|
50
|
+
}
|
|
51
|
+
export {
|
|
52
|
+
run
|
|
53
|
+
};
|