engine7 7.1.2 → 7.1.3

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.
Files changed (2) hide show
  1. package/dist/cli.mjs +57 -5
  2. package/package.json +1 -1
package/dist/cli.mjs CHANGED
@@ -39,6 +39,7 @@ Engine 7 \u2014 Self-hosted AI agent engine
39
39
  \u7528\u6CD5:
40
40
  engine7 init --state-dir <path> [\u9009\u9879] \u521D\u59CB\u5316 agent \u5DE5\u4F5C\u76EE\u5F55
41
41
  engine7 start [--config <path>] \u542F\u52A8 Engine
42
+ engine7 restart [--config <path>] \u91CD\u542F Engine\uFF08\u6740\u65E7\u8FDB\u7A0B+\u542F\u52A8\uFF09
42
43
  engine7 service install|uninstall|status \u5F00\u673A\u81EA\u542F\u52A8\u7BA1\u7406
43
44
 
44
45
  init \u9009\u9879:
@@ -515,14 +516,16 @@ engine7 start \u2014 \u542F\u52A8 Engine
515
516
  console.log(` config: ${configPath2}`);
516
517
  console.log(` engine: ${enginePath}`);
517
518
  const configName = path.basename(configPath2);
519
+ const myPid = process.pid;
518
520
  try {
519
521
  if (process.platform === "win32") {
520
- execSync(`powershell -Command "Get-WmiObject Win32_Process | Where-Object { $_.Name -eq 'node.exe' -and $_.CommandLine -like '*${configName}*' -and $_.CommandLine -like '*dist*' } | ForEach-Object { Write-Host '[start] Killing PID' $_.ProcessId; Stop-Process -Id $_.ProcessId -Force }"`, { stdio: "inherit" });
522
+ execSync(`powershell -Command "Get-WmiObject Win32_Process | Where-Object { $_.Name -eq 'node.exe' -and $_.CommandLine -like '*${configName}*' -and $_.CommandLine -like '*dist*' -and $_.ProcessId -ne ${myPid} } | ForEach-Object { Write-Host '[start] Killing PID' $_.ProcessId; Stop-Process -Id $_.ProcessId -Force }"`, { stdio: "inherit" });
521
523
  } else {
522
- const pids = execSync(`pgrep -f "${configName}.*dist/main.mjs" 2>/dev/null || true`, { encoding: "utf-8" }).trim();
523
- if (pids) {
524
- console.log(`[start] Killing existing engine (PID: ${pids})...`);
525
- execSync(`echo "${pids}" | xargs kill -9 2>/dev/null || true`);
524
+ const pids = execSync(`pgrep -f "dist/main.mjs.*${configName}" 2>/dev/null || true`, { encoding: "utf-8" }).trim();
525
+ const otherPids = pids.split("\n").filter((p) => p && p.trim() !== String(myPid)).join("\n").trim();
526
+ if (otherPids) {
527
+ console.log(`[start] Killing existing engine (PID: ${otherPids})...`);
528
+ execSync(`echo "${otherPids}" | xargs kill -9 2>/dev/null || true`);
526
529
  await new Promise((r) => setTimeout(r, 2e3));
527
530
  }
528
531
  }
@@ -536,6 +539,55 @@ engine7 start \u2014 \u542F\u52A8 Engine
536
539
  child.on("exit", (code) => process.exit(code ?? 1));
537
540
  return;
538
541
  }
542
+ if (subcommand === "restart") {
543
+ const { execSync } = await import("node:child_process");
544
+ const myPid = process.pid;
545
+ console.log("\u{1F504} engine7 restart");
546
+ try {
547
+ if (process.platform === "win32") {
548
+ execSync(`powershell -Command "Get-WmiObject Win32_Process | Where-Object { $_.Name -eq 'node.exe' -and $_.CommandLine -like '*dist/main.mjs*' -and $_.ProcessId -ne ${myPid} } | ForEach-Object { Write-Host '[restart] Killing PID' $_.ProcessId; Stop-Process -Id $_.ProcessId -Force }"`, { stdio: "inherit" });
549
+ } else {
550
+ const pids = execSync(`pgrep -f "dist/main.mjs" 2>/dev/null || true`, { encoding: "utf-8" }).trim();
551
+ const otherPids = pids.split("\n").filter((p) => p && p.trim() !== String(myPid)).join("\n").trim();
552
+ if (otherPids) {
553
+ console.log(`[restart] Killing existing engine (PID: ${otherPids})...`);
554
+ execSync(`echo "${otherPids}" | xargs kill -9 2>/dev/null || true`);
555
+ await new Promise((r) => setTimeout(r, 2e3));
556
+ }
557
+ }
558
+ } catch {
559
+ }
560
+ let configPath2 = "";
561
+ for (let i = 1; i < args.length; i++) {
562
+ if (args[i] === "--config" && args[i + 1]) configPath2 = args[++i];
563
+ }
564
+ if (!configPath2) {
565
+ const defaultCfg = path.join("configs", "main7.json");
566
+ const homeCfg = path.join(process.env.HOME || process.env.USERPROFILE || ".", ".engine7", "configs", "main7.json");
567
+ if (fs.existsSync(defaultCfg)) configPath2 = defaultCfg;
568
+ else if (fs.existsSync(homeCfg)) configPath2 = homeCfg;
569
+ else {
570
+ const ptr = readHomePointer();
571
+ if (ptr?.stateDir) {
572
+ const ptrCfg = path.join(ptr.stateDir, "configs", "main7.json");
573
+ if (fs.existsSync(ptrCfg)) configPath2 = ptrCfg;
574
+ }
575
+ }
576
+ }
577
+ if (!configPath2) {
578
+ console.error("\u274C \u627E\u4E0D\u5230 config");
579
+ process.exit(1);
580
+ }
581
+ const cliPath = path.resolve(process.argv[1]);
582
+ const enginePath = path.join(path.dirname(cliPath), "main.mjs");
583
+ console.log(` config: ${configPath2}`);
584
+ console.log(` engine: ${enginePath}`);
585
+ console.log("");
586
+ const { spawn } = await import("node:child_process");
587
+ const child = spawn(process.execPath, [enginePath, "--engine-config", configPath2], { stdio: "inherit", shell: false });
588
+ child.on("exit", (code) => process.exit(code ?? 1));
589
+ return;
590
+ }
539
591
  if (subcommand === "service") {
540
592
  const action = args[1];
541
593
  if (!action || action === "--help" || action === "-h") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "engine7",
3
- "version": "7.1.2",
3
+ "version": "7.1.3",
4
4
  "type": "module",
5
5
  "description": "Engine 7 — Self-hosted AI agent engine",
6
6
  "main": "dist/main.mjs",