engine7 7.1.18 → 7.1.20

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
@@ -115,11 +115,19 @@ function collectAllFiles(dir) {
115
115
  }
116
116
  return files;
117
117
  }
118
- function readMainSessionId(platformMapPath) {
118
+ function readMainEngineUuid(agentsDir) {
119
119
  try {
120
- if (!fs.existsSync(platformMapPath)) return null;
121
- const map = JSON.parse(fs.readFileSync(platformMapPath, "utf-8"));
122
- 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;
123
131
  } catch {
124
132
  return null;
125
133
  }
@@ -164,9 +172,9 @@ function collectRecentSessions(agentsDir, _days = 7) {
164
172
  }
165
173
  }
166
174
  scanSessionsDir(agentsDir);
167
- const mainSessionId = readMainSessionId(path.join(agentsDir, "main", "sessions", "platform-map.json"));
175
+ const mainEngineUuid = readMainEngineUuid(agentsDir);
168
176
  for (const [sessionKey, group] of sessionGroups) {
169
- if (!mainSessionId || !sessionKey.includes(mainSessionId)) continue;
177
+ if (!mainEngineUuid || !sessionKey.startsWith(mainEngineUuid)) continue;
170
178
  if (group.jsonl) files.push(group.jsonl);
171
179
  group.archived.sort((a, b) => b.mtime - a.mtime);
172
180
  if (group.archived.length > 0) files.push(group.archived[0].file);
@@ -233,8 +241,13 @@ async function doExport(opts) {
233
241
  const relPath = path.relative(stateDir, srcFile);
234
242
  const destFile = path.join(stagingDir, relPath);
235
243
  fs.mkdirSync(path.dirname(destFile), { recursive: true });
236
- const content = fs.readFileSync(srcFile, "utf-8");
237
- 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);
238
251
  fileCount++;
239
252
  totalSize += fs.statSync(srcFile).size;
240
253
  }
@@ -321,19 +334,25 @@ async function doImport(opts) {
321
334
  console.log(` \u6587\u4EF6\u6570: ${manifest.fileCount}`);
322
335
  const wsStaging = path.join(stagingDir, "workspace");
323
336
  let restoredCount = 0;
337
+ let skipCount = 0;
324
338
  if (fs.existsSync(wsStaging)) {
325
339
  const allFiles = collectAllFiles(wsStaging);
326
340
  for (const srcFile of allFiles) {
327
341
  const relPath = path.relative(wsStaging, srcFile);
328
342
  const destFile = path.join(workspace, relPath);
329
343
  fs.mkdirSync(path.dirname(destFile), { recursive: true });
330
- if (isTextFile(srcFile)) {
331
- const content = fs.readFileSync(srcFile, "utf-8");
332
- fs.writeFileSync(destFile, restoreContent(content, dirs));
333
- } else {
334
- fs.copyFileSync(srcFile, destFile);
344
+ try {
345
+ if (isTextFile(srcFile)) {
346
+ const content = fs.readFileSync(srcFile, "utf-8");
347
+ fs.writeFileSync(destFile, restoreContent(content, dirs));
348
+ } else {
349
+ fs.copyFileSync(srcFile, destFile);
350
+ }
351
+ restoredCount++;
352
+ } catch (e) {
353
+ skipCount++;
354
+ console.log(` \u26A0\uFE0F \u8DF3\u8FC7: ${path.relative(wsStaging, srcFile)} (${e.code || e.message})`);
335
355
  }
336
- restoredCount++;
337
356
  }
338
357
  }
339
358
  const agentsStaging = path.join(stagingDir, "agents");
@@ -364,7 +383,7 @@ async function doImport(opts) {
364
383
  restoredCount++;
365
384
  }
366
385
  }
367
- console.log(`\u2705 \u6062\u590D\u5B8C\u6210: ${restoredCount} \u6587\u4EF6 \u2192 ${stateDir}`);
386
+ console.log(`\u2705 \u6062\u590D\u5B8C\u6210: ${restoredCount} \u6587\u4EF6 \u2192 ${stateDir}${skipCount ? ` (\u8DF3\u8FC7 ${skipCount})` : ""}`);
368
387
  const platformConfigName = process.platform === "darwin" ? "xiaoke-mac.json" : "xiaoke-win.json";
369
388
  const restoredConfigPath = path.join(stateDir, "configs", platformConfigName);
370
389
  const configToUse = fs.existsSync(restoredConfigPath) ? restoredConfigPath : path.join(stateDir, "configs", "xiaoke.json");
@@ -530,7 +549,8 @@ var init_cli_travel = __esm({
530
549
  "test-agent",
531
550
  "nul",
532
551
  "*.bak*",
533
- "*.bak-*"
552
+ "*.bak-*",
553
+ "~$*"
534
554
  ]);
535
555
  TEXT_EXTENSIONS = /* @__PURE__ */ new Set([
536
556
  ".md",