engine7 7.1.9 → 7.1.11
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 +50 -25
- package/package.json +1 -1
package/dist/cli.mjs
CHANGED
|
@@ -153,8 +153,17 @@ async function doExport(opts) {
|
|
|
153
153
|
const dirs = { workspace, stateDir, engineHome };
|
|
154
154
|
const wsFiles = collectFiles(workspace, WORKSPACE_INCLUDE, WORKSPACE_OPTIONAL);
|
|
155
155
|
const sessionFiles = collectRecentSessions(path.join(stateDir, "agents"), 7);
|
|
156
|
+
const configsDir = path.join(stateDir, "configs");
|
|
157
|
+
const configFiles = [];
|
|
158
|
+
if (fs.existsSync(configsDir)) {
|
|
159
|
+
for (const f of collectAllFiles(configsDir)) {
|
|
160
|
+
if (shouldExclude(path.basename(f))) continue;
|
|
161
|
+
configFiles.push(f);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
156
164
|
console.log(` workspace \u6587\u4EF6: ${wsFiles.length}`);
|
|
157
165
|
console.log(` session jsonl: ${sessionFiles.length} (\u6700\u8FD17\u5929)`);
|
|
166
|
+
console.log(` configs: ${configFiles.length}`);
|
|
158
167
|
if (dryRun2) {
|
|
159
168
|
console.log(`
|
|
160
169
|
[DRY RUN] \u4F1A\u6253\u5305\u4EE5\u4E0B\u6587\u4EF6:`);
|
|
@@ -193,6 +202,19 @@ async function doExport(opts) {
|
|
|
193
202
|
fileCount++;
|
|
194
203
|
totalSize += fs.statSync(srcFile).size;
|
|
195
204
|
}
|
|
205
|
+
for (const srcFile of configFiles) {
|
|
206
|
+
const relPath = path.relative(stateDir, srcFile);
|
|
207
|
+
const destFile = path.join(stagingDir, relPath);
|
|
208
|
+
fs.mkdirSync(path.dirname(destFile), { recursive: true });
|
|
209
|
+
if (isTextFile(srcFile)) {
|
|
210
|
+
const content = fs.readFileSync(srcFile, "utf-8");
|
|
211
|
+
fs.writeFileSync(destFile, sanitizeContent(content, dirs));
|
|
212
|
+
} else {
|
|
213
|
+
fs.copyFileSync(srcFile, destFile);
|
|
214
|
+
}
|
|
215
|
+
fileCount++;
|
|
216
|
+
totalSize += fs.statSync(srcFile).size;
|
|
217
|
+
}
|
|
196
218
|
const manifest = {
|
|
197
219
|
agentName,
|
|
198
220
|
version,
|
|
@@ -208,16 +230,11 @@ async function doExport(opts) {
|
|
|
208
230
|
note
|
|
209
231
|
};
|
|
210
232
|
fs.writeFileSync(path.join(stagingDir, "manifest.json"), JSON.stringify(manifest, null, 2));
|
|
211
|
-
const archiveFile = path.join(tmpDir, `${agentName}-${version}.
|
|
233
|
+
const archiveFile = path.join(tmpDir, `${agentName}-${version}.tar.gz`);
|
|
212
234
|
console.log(`
|
|
213
235
|
\u{1F5DC}\uFE0F \u6253\u5305\u4E2D...`);
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
const childName = path.basename(stagingDir);
|
|
217
|
-
execSync(`powershell -Command "Compress-Archive -Path '${stagingParent}/${childName}' -DestinationPath '${archiveFile}' -Force"`, { stdio: "pipe" });
|
|
218
|
-
} else {
|
|
219
|
-
execSync(`cd "${tmpDir}" && zip -r -q "${archiveFile}" ${agentName}`, { stdio: "pipe" });
|
|
220
|
-
}
|
|
236
|
+
const tarExe = process.platform === "win32" ? "C:\\Windows\\System32\\tar.exe" : "tar";
|
|
237
|
+
execSync(`"${tarExe}" -czf "${archiveFile}" -C "${tmpDir}" ${agentName}`, { stdio: "pipe" });
|
|
221
238
|
const archiveSize = fs.statSync(archiveFile).size;
|
|
222
239
|
console.log(`\u2705 \u6253\u5305\u5B8C\u6210: ${archiveFile} (${(archiveSize / 1024 / 1024).toFixed(1)} MB, ${fileCount} \u6587\u4EF6)`);
|
|
223
240
|
const cfg = loadTravelConfig();
|
|
@@ -251,19 +268,8 @@ async function doImport(opts) {
|
|
|
251
268
|
return;
|
|
252
269
|
}
|
|
253
270
|
console.log(`\u{1F4C2} \u89E3\u5305\u4E2D...`);
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
execSync(`tar -xzf "${archiveFile}" -C "${tmpDir}"`, { stdio: "pipe" });
|
|
257
|
-
} else {
|
|
258
|
-
execSync(`tar -xzf "${archiveFile}" -C "${tmpDir}"`, { stdio: "pipe" });
|
|
259
|
-
}
|
|
260
|
-
} else {
|
|
261
|
-
if (process.platform === "win32") {
|
|
262
|
-
execSync(`powershell -Command "Expand-Archive -Path '${archiveFile}' -DestinationPath '${tmpDir}' -Force"`, { stdio: "pipe" });
|
|
263
|
-
} else {
|
|
264
|
-
execSync(`unzip -q -o "${archiveFile}" -d "${tmpDir}"`, { stdio: "pipe" });
|
|
265
|
-
}
|
|
266
|
-
}
|
|
271
|
+
const tarExe = process.platform === "win32" ? "C:\\Windows\\System32\\tar.exe" : "tar";
|
|
272
|
+
execSync(`"${tarExe}" -xzf "${archiveFile}" -C "${tmpDir}"`, { stdio: "pipe" });
|
|
267
273
|
const stagingDir = path.join(tmpDir, agentName);
|
|
268
274
|
const manifestPath = path.join(stagingDir, "manifest.json");
|
|
269
275
|
if (!fs.existsSync(manifestPath)) {
|
|
@@ -305,9 +311,28 @@ async function doImport(opts) {
|
|
|
305
311
|
restoredCount++;
|
|
306
312
|
}
|
|
307
313
|
}
|
|
314
|
+
const configsStaging = path.join(stagingDir, "configs");
|
|
315
|
+
if (fs.existsSync(configsStaging)) {
|
|
316
|
+
const cfgFiles = collectAllFiles(configsStaging);
|
|
317
|
+
for (const srcFile of cfgFiles) {
|
|
318
|
+
const relPath = path.relative(stagingDir, srcFile);
|
|
319
|
+
const destFile = path.join(stateDir, relPath);
|
|
320
|
+
fs.mkdirSync(path.dirname(destFile), { recursive: true });
|
|
321
|
+
if (isTextFile(srcFile)) {
|
|
322
|
+
const content = fs.readFileSync(srcFile, "utf-8");
|
|
323
|
+
fs.writeFileSync(destFile, restoreContent(content, dirs));
|
|
324
|
+
} else {
|
|
325
|
+
fs.copyFileSync(srcFile, destFile);
|
|
326
|
+
}
|
|
327
|
+
restoredCount++;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
308
330
|
console.log(`\u2705 \u6062\u590D\u5B8C\u6210: ${restoredCount} \u6587\u4EF6 \u2192 ${stateDir}`);
|
|
331
|
+
const platformConfigName = process.platform === "darwin" ? "xiaoke-mac.json" : "xiaoke-win.json";
|
|
332
|
+
const restoredConfigPath = path.join(stateDir, "configs", platformConfigName);
|
|
333
|
+
const configToUse = fs.existsSync(restoredConfigPath) ? restoredConfigPath : path.join(stateDir, "configs", "xiaoke.json");
|
|
309
334
|
console.log(`
|
|
310
|
-
\u{1F4A1} \u4E0B\u4E00\u6B65: engine7 start --config
|
|
335
|
+
\u{1F4A1} \u4E0B\u4E00\u6B65: engine7 start --config "${configToUse}"`);
|
|
311
336
|
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
312
337
|
}
|
|
313
338
|
async function uploadToGitHub(cfg, archiveFile, agentName, version, manifest) {
|
|
@@ -345,7 +370,7 @@ async function uploadToGitHub(cfg, archiveFile, agentName, version, manifest) {
|
|
|
345
370
|
headers: {
|
|
346
371
|
"Authorization": `Bearer ${cfg.githubToken}`,
|
|
347
372
|
"Accept": "application/vnd.github+json",
|
|
348
|
-
"Content-Type": "application/
|
|
373
|
+
"Content-Type": "application/gzip",
|
|
349
374
|
"Content-Length": String(fileBuffer.length)
|
|
350
375
|
},
|
|
351
376
|
body: fileBuffer
|
|
@@ -380,9 +405,9 @@ async function downloadFromGitHub(cfg, agentName, version, destDir) {
|
|
|
380
405
|
throw new Error(`\u83B7\u53D6 release \u5931\u8D25: ${res.status}`);
|
|
381
406
|
}
|
|
382
407
|
const release = await res.json();
|
|
383
|
-
const asset = release.assets?.find((a) => a.name.endsWith(".
|
|
408
|
+
const asset = release.assets?.find((a) => a.name.endsWith(".tar.gz") || a.name.endsWith(".zip"));
|
|
384
409
|
if (!asset) {
|
|
385
|
-
throw new Error(`release ${tag} \u6CA1\u6709
|
|
410
|
+
throw new Error(`release ${tag} \u6CA1\u6709 tar.gz/zip asset`);
|
|
386
411
|
}
|
|
387
412
|
const downloadRes = await fetch(asset.url, {
|
|
388
413
|
headers: {
|