engine7 7.1.17 → 7.1.19

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/cli.mjs CHANGED
@@ -38,6 +38,7 @@ function sanitizeContent(content, dirs) {
38
38
  if (original) {
39
39
  result = result.split(original).join(placeholder);
40
40
  result = result.split(original.replace(/\//g, "\\")).join(placeholder);
41
+ result = result.split(original.replace(/\//g, "\\\\")).join(placeholder);
41
42
  }
42
43
  }
43
44
  return result;
@@ -114,11 +115,19 @@ function collectAllFiles(dir) {
114
115
  }
115
116
  return files;
116
117
  }
117
- function readMainSessionId(platformMapPath) {
118
+ function readMainEngineUuid(agentsDir) {
118
119
  try {
119
- if (!fs.existsSync(platformMapPath)) return null;
120
- const map = JSON.parse(fs.readFileSync(platformMapPath, "utf-8"));
121
- return map["scope:main"] || null;
120
+ const platformMapPath = path.join(agentsDir, "main", "sessions", "platform-map.json");
121
+ const indexMapPath = path.join(agentsDir, "main", "sessions", "session-index.json");
122
+ if (!fs.existsSync(platformMapPath) || !fs.existsSync(indexMapPath)) return null;
123
+ const platformMap = JSON.parse(fs.readFileSync(platformMapPath, "utf-8"));
124
+ const mainPlatformId = platformMap["scope:main"] || platformMap["main"];
125
+ if (!mainPlatformId) return null;
126
+ const indexMap = JSON.parse(fs.readFileSync(indexMapPath, "utf-8"));
127
+ const entry = indexMap[mainPlatformId];
128
+ if (!entry || !entry.file) return null;
129
+ const basename3 = path.basename(entry.file).replace(/\.jsonl$/, "");
130
+ return basename3;
122
131
  } catch {
123
132
  return null;
124
133
  }
@@ -163,9 +172,9 @@ function collectRecentSessions(agentsDir, _days = 7) {
163
172
  }
164
173
  }
165
174
  scanSessionsDir(agentsDir);
166
- const mainSessionId = readMainSessionId(path.join(agentsDir, "main", "sessions", "platform-map.json"));
175
+ const mainEngineUuid = readMainEngineUuid(agentsDir);
167
176
  for (const [sessionKey, group] of sessionGroups) {
168
- if (!mainSessionId || !sessionKey.includes(mainSessionId)) continue;
177
+ if (!mainEngineUuid || !sessionKey.startsWith(mainEngineUuid)) continue;
169
178
  if (group.jsonl) files.push(group.jsonl);
170
179
  group.archived.sort((a, b) => b.mtime - a.mtime);
171
180
  if (group.archived.length > 0) files.push(group.archived[0].file);
@@ -232,8 +241,13 @@ async function doExport(opts) {
232
241
  const relPath = path.relative(stateDir, srcFile);
233
242
  const destFile = path.join(stagingDir, relPath);
234
243
  fs.mkdirSync(path.dirname(destFile), { recursive: true });
235
- const content = fs.readFileSync(srcFile, "utf-8");
236
- fs.writeFileSync(destFile, sanitizeContent(content, dirs));
244
+ let content = fs.readFileSync(srcFile, "utf-8");
245
+ content = sanitizeContent(content, dirs);
246
+ const baseName = path.basename(srcFile);
247
+ if (baseName === "session-index.json" || baseName === "platform-map.json") {
248
+ content = content.split("\\\\").join("/");
249
+ }
250
+ fs.writeFileSync(destFile, content);
237
251
  fileCount++;
238
252
  totalSize += fs.statSync(srcFile).size;
239
253
  }