@memrosetta/cli 0.4.7 → 0.5.0
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-2MO65JLK.js +139 -0
- package/dist/chunk-5PH2RDAS.js +750 -0
- package/dist/chunk-IKIJVRHU.js +16 -0
- package/dist/chunk-PMQKXYS6.js +752 -0
- package/dist/chunk-SYPVELIW.js +64 -0
- package/dist/chunk-TSA67QME.js +56 -0
- package/dist/chunk-UKGD7QXV.js +81 -0
- package/dist/chunk-UOT33X3Q.js +750 -0
- package/dist/chunk-VR3TRSC7.js +148 -0
- package/dist/clear-HNVVALWL.js +39 -0
- package/dist/compress-VZJHSVJK.js +33 -0
- package/dist/count-WRCFIWWS.js +24 -0
- package/dist/enforce-PHO4L7C2.js +381 -0
- package/dist/feedback-JXSKOFRS.js +51 -0
- package/dist/feedback-O6NKG46O.js +51 -0
- package/dist/hooks/enforce-claude-code.js +119 -0
- package/dist/hooks/on-prompt.js +9 -5
- package/dist/hooks/on-stop.js +8 -4
- package/dist/index.js +22 -16
- package/dist/ingest-JWLBIFEI.js +97 -0
- package/dist/init-ARU2CIOH.js +205 -0
- package/dist/init-C2MCDVWL.js +205 -0
- package/dist/init-LIWL7Y3H.js +205 -0
- package/dist/init-VUJX3RRW.js +205 -0
- package/dist/invalidate-QPOV2E5U.js +40 -0
- package/dist/invalidate-VUHHNZUX.js +40 -0
- package/dist/maintain-UUZ76QET.js +37 -0
- package/dist/relate-MIOQYWTI.js +57 -0
- package/dist/relate-TEZ3GIIY.js +57 -0
- package/dist/reset-HQFOMYVP.js +129 -0
- package/dist/reset-OVU4A575.js +129 -0
- package/dist/reset-T6DPQCWI.js +129 -0
- package/dist/reset-WMDSMCAR.js +129 -0
- package/dist/search-IXV43G2C.js +48 -0
- package/dist/status-BLHKHB34.js +184 -0
- package/dist/status-CNGR7YDV.js +184 -0
- package/dist/status-IHYARQXU.js +184 -0
- package/dist/store-DTN3PTFQ.js +101 -0
- package/dist/store-V7I5RJ6Y.js +101 -0
- package/dist/sync-EHYMBZHE.js +542 -0
- package/dist/sync-UJBD7575.js +542 -0
- package/dist/working-memory-CH524PJA.js +53 -0
- package/package.json +6 -5
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getConfig
|
|
3
|
+
} from "./chunk-SEPYQK3J.js";
|
|
4
|
+
|
|
5
|
+
// src/sync/cli-sync.ts
|
|
6
|
+
import { createHash, randomUUID } from "crypto";
|
|
7
|
+
import { userInfo } from "os";
|
|
8
|
+
function deterministicOpId(kind, key) {
|
|
9
|
+
const hash = createHash("sha256").update(`${kind}:${key}`).digest("hex");
|
|
10
|
+
return `op-${hash.slice(0, 16)}`;
|
|
11
|
+
}
|
|
12
|
+
var DISABLED = {
|
|
13
|
+
enabled: false,
|
|
14
|
+
userId: "",
|
|
15
|
+
deviceId: "",
|
|
16
|
+
enqueue() {
|
|
17
|
+
},
|
|
18
|
+
close() {
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
async function openCliSyncContext(dbPath) {
|
|
22
|
+
const config = getConfig();
|
|
23
|
+
if (!config.syncEnabled || !config.syncServerUrl || !config.syncApiKey || !config.syncDeviceId) {
|
|
24
|
+
return DISABLED;
|
|
25
|
+
}
|
|
26
|
+
const userId = config.syncUserId ?? userInfo().username;
|
|
27
|
+
const deviceId = config.syncDeviceId;
|
|
28
|
+
try {
|
|
29
|
+
const { default: Database } = await import("better-sqlite3");
|
|
30
|
+
const { SyncClient, ensureSyncSchema } = await import("@memrosetta/sync-client");
|
|
31
|
+
const db = new Database(dbPath);
|
|
32
|
+
ensureSyncSchema(db);
|
|
33
|
+
const client = new SyncClient(db, {
|
|
34
|
+
serverUrl: config.syncServerUrl,
|
|
35
|
+
apiKey: config.syncApiKey,
|
|
36
|
+
deviceId,
|
|
37
|
+
userId
|
|
38
|
+
});
|
|
39
|
+
const outbox = client.getOutbox();
|
|
40
|
+
return {
|
|
41
|
+
enabled: true,
|
|
42
|
+
userId,
|
|
43
|
+
deviceId,
|
|
44
|
+
enqueue(op) {
|
|
45
|
+
try {
|
|
46
|
+
outbox.addOp(op);
|
|
47
|
+
} catch (err) {
|
|
48
|
+
process.stderr.write(
|
|
49
|
+
`[sync] enqueue failed: ${err instanceof Error ? err.message : String(err)}
|
|
50
|
+
`
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
close() {
|
|
55
|
+
try {
|
|
56
|
+
db.close();
|
|
57
|
+
} catch {
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
} catch (err) {
|
|
62
|
+
process.stderr.write(
|
|
63
|
+
`[sync] disabled for this command: ${err instanceof Error ? err.message : String(err)}
|
|
64
|
+
`
|
|
65
|
+
);
|
|
66
|
+
return DISABLED;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
function buildMemoryCreatedOp(ctx, memory) {
|
|
70
|
+
return {
|
|
71
|
+
opId: randomUUID(),
|
|
72
|
+
opType: "memory_created",
|
|
73
|
+
deviceId: ctx.deviceId,
|
|
74
|
+
userId: ctx.userId,
|
|
75
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
76
|
+
payload: {
|
|
77
|
+
memoryId: memory.memoryId,
|
|
78
|
+
userId: memory.userId,
|
|
79
|
+
namespace: memory.namespace,
|
|
80
|
+
memoryType: memory.memoryType,
|
|
81
|
+
content: memory.content,
|
|
82
|
+
rawText: memory.rawText,
|
|
83
|
+
documentDate: memory.documentDate,
|
|
84
|
+
sourceId: memory.sourceId,
|
|
85
|
+
confidence: memory.confidence,
|
|
86
|
+
salience: memory.salience,
|
|
87
|
+
keywords: memory.keywords,
|
|
88
|
+
eventDateStart: memory.eventDateStart,
|
|
89
|
+
eventDateEnd: memory.eventDateEnd,
|
|
90
|
+
invalidatedAt: memory.invalidatedAt,
|
|
91
|
+
learnedAt: memory.learnedAt
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
function buildRelationCreatedOp(ctx, relation) {
|
|
96
|
+
return {
|
|
97
|
+
opId: randomUUID(),
|
|
98
|
+
opType: "relation_created",
|
|
99
|
+
deviceId: ctx.deviceId,
|
|
100
|
+
userId: ctx.userId,
|
|
101
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
102
|
+
payload: {
|
|
103
|
+
srcMemoryId: relation.srcMemoryId,
|
|
104
|
+
dstMemoryId: relation.dstMemoryId,
|
|
105
|
+
relationType: relation.relationType,
|
|
106
|
+
reason: relation.reason,
|
|
107
|
+
createdAt: relation.createdAt
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
function buildMemoryInvalidatedOp(ctx, memoryId, invalidatedAt, reason) {
|
|
112
|
+
return {
|
|
113
|
+
opId: randomUUID(),
|
|
114
|
+
opType: "memory_invalidated",
|
|
115
|
+
deviceId: ctx.deviceId,
|
|
116
|
+
userId: ctx.userId,
|
|
117
|
+
createdAt: invalidatedAt,
|
|
118
|
+
payload: { memoryId, invalidatedAt, reason }
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
function buildFeedbackGivenOp(ctx, memoryId, helpful, recordedAt) {
|
|
122
|
+
return {
|
|
123
|
+
opId: randomUUID(),
|
|
124
|
+
opType: "feedback_given",
|
|
125
|
+
deviceId: ctx.deviceId,
|
|
126
|
+
userId: ctx.userId,
|
|
127
|
+
createdAt: recordedAt,
|
|
128
|
+
payload: { memoryId, helpful, recordedAt }
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export {
|
|
133
|
+
deterministicOpId,
|
|
134
|
+
openCliSyncContext,
|
|
135
|
+
buildMemoryCreatedOp,
|
|
136
|
+
buildRelationCreatedOp,
|
|
137
|
+
buildMemoryInvalidatedOp,
|
|
138
|
+
buildFeedbackGivenOp
|
|
139
|
+
};
|