@ouro.bot/cli 0.1.0-alpha.730 → 0.1.0-alpha.731

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.
@@ -36,6 +36,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.MAIL_SEARCH_TEXT_PROJECTION_VERSION = void 0;
37
37
  exports.buildMailSearchCacheDocument = buildMailSearchCacheDocument;
38
38
  exports.upsertMailSearchCacheDocument = upsertMailSearchCacheDocument;
39
+ exports.inspectMailSearchCacheFiles = inspectMailSearchCacheFiles;
40
+ exports.reloadMailSearchCache = reloadMailSearchCache;
41
+ exports.removeMailSearchCacheDocument = removeMailSearchCacheDocument;
42
+ exports.removeMailSearchCacheFile = removeMailSearchCacheFile;
39
43
  exports.syncMailSearchCacheMetadata = syncMailSearchCacheMetadata;
40
44
  exports.searchMailSearchCache = searchMailSearchCache;
41
45
  exports.snapshotMailSearchCacheForFilters = snapshotMailSearchCacheForFilters;
@@ -96,6 +100,17 @@ function readJsonDocument(filePath) {
96
100
  return null;
97
101
  }
98
102
  }
103
+ function writeJsonAtomically(filePath, value) {
104
+ const tempPath = `${filePath}.${process.pid}.${Date.now()}.tmp`;
105
+ try {
106
+ fs.writeFileSync(tempPath, `${JSON.stringify(value)}\n`, "utf-8");
107
+ fs.renameSync(tempPath, filePath);
108
+ }
109
+ finally {
110
+ if (fs.existsSync(tempPath))
111
+ fs.unlinkSync(tempPath);
112
+ }
113
+ }
99
114
  function cacheState(agentId, options) {
100
115
  const key = `${agentId}:${cacheDir(agentId, options)}`;
101
116
  let state = cacheStates.get(key);
@@ -123,8 +138,10 @@ function loadCache(agentId, options) {
123
138
  }
124
139
  return state.docs;
125
140
  }
126
- function buildMailSearchCacheDocument(message, privateEnvelope) {
141
+ function buildMailSearchCacheDocument(message, privateEnvelope, provenance = {}) {
127
142
  const readableText = (0, core_1.privateMailEnvelopeReadableText)(privateEnvelope);
143
+ const decryptionKeyId = provenance.decryptionKeyId
144
+ ?? (message.bodyForm === "encrypted" ? message.privateEnvelope?.keyId : undefined);
128
145
  return {
129
146
  schemaVersion: 1,
130
147
  messageId: message.id,
@@ -142,13 +159,14 @@ function buildMailSearchCacheDocument(message, privateEnvelope) {
142
159
  searchText: normalizeSearchText(privateEnvelope),
143
160
  textProjectionVersion: exports.MAIL_SEARCH_TEXT_PROJECTION_VERSION,
144
161
  attachmentCount: privateEnvelope.attachments.length,
162
+ ...(decryptionKeyId ? { decryptionKeyId } : {}),
145
163
  };
146
164
  }
147
- function upsertMailSearchCacheDocument(message, privateEnvelope, options) {
148
- const document = buildMailSearchCacheDocument(message, privateEnvelope);
165
+ function upsertMailSearchCacheDocument(message, privateEnvelope, options, provenance) {
166
+ const document = buildMailSearchCacheDocument(message, privateEnvelope, provenance);
149
167
  const dir = cacheDir(message.agentId, options);
150
168
  fs.mkdirSync(dir, { recursive: true });
151
- fs.writeFileSync(cachePath(message.agentId, message.id, options), `${JSON.stringify(document)}\n`, "utf-8");
169
+ writeJsonAtomically(cachePath(message.agentId, message.id, options), document);
152
170
  const state = cacheState(message.agentId, options);
153
171
  if (state.loaded)
154
172
  state.docs.set(document.messageId, document);
@@ -165,6 +183,58 @@ function upsertMailSearchCacheDocument(message, privateEnvelope, options) {
165
183
  });
166
184
  return document;
167
185
  }
186
+ function inspectMailSearchCacheFiles(agentId, options) {
187
+ const dir = cacheDir(agentId, options);
188
+ if (!fs.existsSync(dir))
189
+ return [];
190
+ return fs.readdirSync(dir, { withFileTypes: true })
191
+ .filter((entry) => entry.isFile() && entry.name.endsWith(".json"))
192
+ .map((entry) => {
193
+ const filePath = path.join(dir, entry.name);
194
+ return { fileName: entry.name, filePath, document: readJsonDocument(filePath) };
195
+ })
196
+ .sort((left, right) => left.fileName.localeCompare(right.fileName));
197
+ }
198
+ function reloadMailSearchCache(agentId, options) {
199
+ const state = cacheState(agentId, options);
200
+ state.loaded = false;
201
+ state.docs.clear();
202
+ }
203
+ function removeMailSearchCacheDocument(agentId, messageId, options) {
204
+ const filePath = cachePath(agentId, messageId, options);
205
+ let removed = false;
206
+ try {
207
+ if (fs.lstatSync(filePath).isFile()) {
208
+ fs.unlinkSync(filePath);
209
+ removed = true;
210
+ }
211
+ }
212
+ catch (error) {
213
+ if (!(typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT"))
214
+ throw error;
215
+ }
216
+ const state = cacheState(agentId, options);
217
+ if (state.loaded)
218
+ state.docs.delete(messageId);
219
+ return removed;
220
+ }
221
+ function removeMailSearchCacheFile(agentId, fileName, options) {
222
+ if (path.basename(fileName) !== fileName || !fileName.endsWith(".json"))
223
+ return false;
224
+ const filePath = path.join(cacheDir(agentId, options), fileName);
225
+ try {
226
+ if (!fs.lstatSync(filePath).isFile())
227
+ return false;
228
+ fs.unlinkSync(filePath);
229
+ reloadMailSearchCache(agentId, options);
230
+ return true;
231
+ }
232
+ catch (error) {
233
+ if (!(typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT"))
234
+ throw error;
235
+ return false;
236
+ }
237
+ }
168
238
  function syncMailSearchCacheMetadata(message, options) {
169
239
  const existing = readJsonDocument(cachePath(message.agentId, message.id, options));
170
240
  if (!existing)
@@ -177,7 +247,7 @@ function syncMailSearchCacheMetadata(message, options) {
177
247
  ...(message.ownerEmail ? { ownerEmail: message.ownerEmail } : {}),
178
248
  ...(message.source ? { source: message.source } : {}),
179
249
  };
180
- fs.writeFileSync(cachePath(message.agentId, message.id, options), `${JSON.stringify(updated)}\n`, "utf-8");
250
+ writeJsonAtomically(cachePath(message.agentId, message.id, options), updated);
181
251
  const state = cacheState(message.agentId, options);
182
252
  if (state.loaded)
183
253
  state.docs.set(updated.messageId, updated);
@@ -312,7 +382,7 @@ function writeMailSearchCoverageRecord(record, options) {
312
382
  ...(record.newestReceivedAt ? { newestReceivedAt: record.newestReceivedAt } : {}),
313
383
  };
314
384
  fs.mkdirSync(coverageDir(document.agentId, options), { recursive: true });
315
- fs.writeFileSync(coveragePath(document, options), `${JSON.stringify(document)}\n`, "utf-8");
385
+ writeJsonAtomically(coveragePath(document, options), document);
316
386
  (0, runtime_1.emitNervesEvent)({
317
387
  component: "senses",
318
388
  event: "senses.mail_search_coverage_written",