engine7 7.1.150 → 7.1.151

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.
@@ -34474,11 +34474,13 @@ function secretsCandidates(stateDir2, configName) {
34474
34474
  join42(stateDir2, "configs", `.env.${configName}`),
34475
34475
  join42(stateDir2, "configs", ".env")
34476
34476
  ];
34477
- if (isDefaultStateDir(stateDir2)) return [shared, ...inState];
34477
+ const travel = join42(stateDir2, "secrets.env");
34478
+ if (isDefaultStateDir(stateDir2)) return [shared, ...inState, travel];
34478
34479
  return [
34479
34480
  join42(secretsHome(), ".engine7-secrets", `${configName}-${stateKey2(stateDir2)}.env`),
34480
34481
  shared,
34481
- ...inState
34482
+ ...inState,
34483
+ travel
34482
34484
  ];
34483
34485
  }
34484
34486
  function readSecretsEntries(stateDir2, configName) {
package/dist/cli.mjs CHANGED
@@ -19220,11 +19220,13 @@ function secretsCandidates(stateDir, configName) {
19220
19220
  join25(stateDir, "configs", `.env.${configName}`),
19221
19221
  join25(stateDir, "configs", ".env")
19222
19222
  ];
19223
- if (isDefaultStateDir(stateDir)) return [shared, ...inState];
19223
+ const travel = join25(stateDir, "secrets.env");
19224
+ if (isDefaultStateDir(stateDir)) return [shared, ...inState, travel];
19224
19225
  return [
19225
19226
  join25(secretsHome(), ".engine7-secrets", `${configName}-${stateKey2(stateDir)}.env`),
19226
19227
  shared,
19227
- ...inState
19228
+ ...inState,
19229
+ travel
19228
19230
  ];
19229
19231
  }
19230
19232
  function readSecretsEntries(stateDir, configName) {
@@ -21236,12 +21238,16 @@ var init_peer_tunnel = __esm({
21236
21238
  import { execFile as execFile2 } from "node:child_process";
21237
21239
  import { randomUUID as randomUUID17 } from "node:crypto";
21238
21240
  import { setTimeout as delay2 } from "node:timers/promises";
21241
+ function ccPeerTarget(remoteTargets, alias) {
21242
+ if (typeof alias !== "string" || !validAlias(alias)) return void 0;
21243
+ const targets = remoteTargets?.targets;
21244
+ const host = targets && typeof targets === "object" && Object.hasOwn(targets, alias) ? targets[alias] : void 0;
21245
+ return typeof host === "string" && validSshHost(host) ? { alias, host } : void 0;
21246
+ }
21239
21247
  function resolvePeer(alias) {
21240
- const targets = peerConfig()?.targets;
21241
- if (!validAlias(alias) || !targets || !Object.hasOwn(targets, alias) || !validSshHost(targets[alias])) {
21242
- throw new Error(`\u8FDC\u7A0B CC \u76EE\u6807\u672A\u914D\u7F6E\uFF1A${alias}`);
21243
- }
21244
- return { alias, host: targets[alias] };
21248
+ const target = ccPeerTarget(peerConfig(), alias);
21249
+ if (!target) throw new Error(`\u8FDC\u7A0B CC \u76EE\u6807\u672A\u914D\u7F6E\uFF1A${alias}`);
21250
+ return target;
21245
21251
  }
21246
21252
  function selectCcPeer(target, useDefault = true) {
21247
21253
  if (typeof target === "string" && target.startsWith("remote:")) return resolvePeer(target.slice(7));
@@ -42271,9 +42277,9 @@ async function sendVoiceToMulticaIssue(text4, issueId, opts) {
42271
42277
  }
42272
42278
  const content = opts.caption || `\u{1F399}\uFE0F \u8BED\u97F3\u6D88\u606F\uFF08${text4.length} \u5B57\uFF09`;
42273
42279
  try {
42274
- const { execFile: execFile10 } = await import("node:child_process");
42275
- const { promisify: promisify12 } = await import("node:util");
42276
- const execFileA = promisify12(execFile10);
42280
+ const { execFile: execFile11 } = await import("node:child_process");
42281
+ const { promisify: promisify13 } = await import("node:util");
42282
+ const execFileA = promisify13(execFile11);
42277
42283
  const { stdout } = await execFileA("multica", [
42278
42284
  "issue",
42279
42285
  "comment",
@@ -59768,6 +59774,14 @@ function sanitizeTitle(title2) {
59768
59774
  const cleaned = title2.replace(/[\\/:*?"<>|\r\n]+/g, " ").replace(/\s+/g, "_").replace(/[^\w一-鿿-]/g, "").slice(0, 48);
59769
59775
  return cleaned || "untitled";
59770
59776
  }
59777
+ function normalizeNextCheck(raw) {
59778
+ const v = String(raw ?? "").trim();
59779
+ if (!v) return null;
59780
+ const at = Date.parse(v);
59781
+ if (!Number.isFinite(at)) return null;
59782
+ const cutoff = /^\d{4}-\d{2}-\d{2}$/.test(v) ? at + 864e5 - 1 : at;
59783
+ return cutoff > Date.now() ? v : null;
59784
+ }
59771
59785
  async function writeTopicEntry(binding, entry) {
59772
59786
  if (!binding.topicsDir) throw new Error("binding \u672A\u914D\u7F6E topicsDir\uFF08memory_topic \u4E0D\u53EF\u7528\uFF09");
59773
59787
  if (!TOPIC_TYPES.includes(entry.type)) {
@@ -59781,18 +59795,21 @@ async function writeTopicEntry(binding, entry) {
59781
59795
  }
59782
59796
  const dateTag = entry.date;
59783
59797
  const base = sanitizeTitle(entry.title);
59784
- const frontmatter = [
59798
+ const lines = [
59785
59799
  "---",
59786
59800
  `name: ${base}`,
59787
59801
  `description: ${entry.description.replace(/\r?\n/g, " ").slice(0, 300)}`,
59788
59802
  `type: ${entry.type}`,
59789
59803
  `date: ${entry.date}`,
59790
59804
  "via: doubao",
59791
- `date_kind: ${entry.dateKind === "recorded" ? "recorded" : "source_declared_event"}`,
59792
- "---",
59793
- "",
59794
- ""
59795
- ].join("\n");
59805
+ `date_kind: ${entry.dateKind === "recorded" ? "recorded" : "source_declared_event"}`
59806
+ ];
59807
+ const nextCheckAt = normalizeNextCheck(entry.nextCheckAt);
59808
+ if (nextCheckAt) lines.push(`next_check_at: ${nextCheckAt}`);
59809
+ const trigger = String(entry.trigger ?? "").replace(/\r?\n/g, " ").trim().slice(0, 200);
59810
+ if (trigger) lines.push(`trigger: ${trigger}`);
59811
+ lines.push("---", "", "");
59812
+ const frontmatter = lines.join("\n");
59796
59813
  const content = frontmatter + entry.body.trim() + "\n";
59797
59814
  await fs67.mkdir(typeDir, { recursive: true });
59798
59815
  let candidate = path70.join(typeDir, `${entry.type}_${base}_${dateTag}.md`);
@@ -59993,7 +60010,7 @@ ${existing.length ? existing.join("\n") : "\uFF08\u65E0\uFF09"}
59993
60010
  ${convo}`;
59994
60011
  let reply;
59995
60012
  try {
59996
- reply = await callLlm(llm, ORGANIZE_SYSTEM, user);
60013
+ reply = await callLlm(llm, organizeSystem(today2), user);
59997
60014
  } catch (err) {
59998
60015
  return { status: "error", processed: entries2.length, written: [], detail: `LLM \u8C03\u7528\u5931\u8D25\uFF1A${err?.message ?? err}` };
59999
60016
  }
@@ -60008,7 +60025,9 @@ ${convo}`;
60008
60025
  description: String(it.description || ""),
60009
60026
  body: String(it.body || ""),
60010
60027
  date: String(it.date || today2),
60011
- dateKind: it.date ? "event" : "recorded"
60028
+ dateKind: it.date ? "event" : "recorded",
60029
+ nextCheckAt: it.next_check_at ?? null,
60030
+ trigger: it.trigger ?? null
60012
60031
  });
60013
60032
  if (r.created) written.push(r.file.split(/[\\/]/).pop() || r.file);
60014
60033
  } catch (err) {
@@ -60038,20 +60057,22 @@ function startOrganizeLoop(cfg, rawConfig, intervalMin = ORGANIZE_DEFAULT_INTERV
60038
60057
  timer.unref?.();
60039
60058
  return timer;
60040
60059
  }
60041
- var ORGANIZE_DEFAULT_INTERVAL_MIN, ORGANIZE_SYSTEM;
60060
+ var ORGANIZE_DEFAULT_INTERVAL_MIN, organizeSystem;
60042
60061
  var init_organize = __esm({
60043
60062
  "src/mem-serve/organize.ts"() {
60044
60063
  "use strict";
60045
60064
  init_topic_store();
60046
60065
  init_clock();
60047
60066
  ORGANIZE_DEFAULT_INTERVAL_MIN = 60;
60048
- ORGANIZE_SYSTEM = `\u4F60\u662F\u8BB0\u5FC6\u6574\u7406\u5668\u3002\u8F93\u5165\u662F\u8C46\u5305\u5BF9\u8BDD\u7684\u539F\u59CB\u526F\u672C\uFF08\u7528\u6237\u6D88\u606F role=user\uFF0C\u8C46\u5305 AI \u56DE\u590D role=assistant\uFF09\uFF0C\u6309\u4E24\u4E2A\u8FC7\u6EE4\u5668\u63D0\u70BC\u6210 topics \u6761\u76EE\uFF1A
60067
+ organizeSystem = (today2) => `\u4F60\u662F\u8BB0\u5FC6\u6574\u7406\u5668\u3002\u8F93\u5165\u662F\u8C46\u5305\u5BF9\u8BDD\u7684\u539F\u59CB\u526F\u672C\uFF08\u7528\u6237\u6D88\u606F role=user\uFF0C\u8C46\u5305 AI \u56DE\u590D role=assistant\uFF09\uFF0C\u6309\u4E24\u4E2A\u8FC7\u6EE4\u5668\u63D0\u70BC\u6210 topics \u6761\u76EE\uFF1A
60049
60068
 
60050
60069
  Surprising Filter\uFF08\u4E8B\u5B9E\u7C7B\u4E94\u578B user/people/project/feedback/reference\uFF09\uFF1A\u4E09\u95EE\u5168\u8FC7\u624D\u6210\u6761\u2014\u2014\u2460\u65B0\u4FE1\u606F\u5417 \u2461\u610F\u5916\u6216\u975E\u663E\u7136\u5417\uFF08\u63A8\u5F97\u51FA\u6765\u7684\u4E0D\u6210\u6761\uFF09\u2462\u5C06\u6765\u6709\u7528\u5417\u3002
60051
60070
  Milestone Filter\uFF08emotion \u578B\uFF09\uFF1A\u53EA\u6536\u300C\u7B2C\u4E00\u6B21\u300D\u6216\u300C\u8F6C\u6298\u70B9\u300D\uFF0C\u91CD\u590D\u65E5\u5E38\u4E0D\u662F\u91CC\u7A0B\u7891\u3002
60052
60071
 
60053
60072
  \u89C4\u5219\uFF1A
60054
- - \u53EA\u8F93\u51FA JSON \u6570\u7EC4\uFF0C\u65E0\u5176\u5B83\u6587\u5B57\uFF1A[{"type":"...","title":"...","description":"...","body":"...","date":"YYYY-MM-DD"}]
60073
+ - \u53EA\u8F93\u51FA JSON \u6570\u7EC4\uFF0C\u65E0\u5176\u5B83\u6587\u5B57\uFF1A[{"type":"...","title":"...","description":"...","body":"...","date":"YYYY-MM-DD","next_check_at":"YYYY-MM-DD \u6216 null","trigger":"... \u6216 null"}]
60074
+ - next_check_at / trigger\uFF1A\u8FD9\u6761\u8BDD\u9898\u300C\u8FD8\u6709\u6CA1\u6709\u540E\u7EED\u300D\u3002\u6709\u660E\u786E\u5C06\u6765\u8282\u70B9\uFF08\u5230\u671F\u3001\u7EED\u8D39\u3001\u4EA4\u4ED8\u3001\u590D\u67E5\u3001\u7B49\u56DE\u590D\u3001\u7B49\u62CD\u677F\uFF09\u5C31\u586B next_check_at=\u90A3\u4E2A\u65E5\u671F\uFF0Ctrigger \u5199\u300C\u4EC0\u4E48\u7B97\u6709\u53D8\u5316\u300D\uFF1B\u7EAF\u6863\u6848\u7C7B\uFF08\u753B\u50CF\u3001\u504F\u597D\u3001\u5DF2\u5B8C\u7ED3\u7684\u4E8B\uFF09\u4E00\u5F8B null\uFF0C\u5B81\u53EF\u6F0F\u4E0D\u53EF\u6EE5\u586B\u2014\u2014\u586B\u4E86\u5C31\u662F\u7ED9\u6211\u81EA\u5DF1\u6392\u4E86\u4E00\u4E2A\u95F9\u949F
60075
+ - next_check_at \u53EA\u5141\u8BB8\u672A\u6765\u65E5\u671F\uFF08\u4ECA\u5929 ${today2} \u4E4B\u540E\uFF09\u6216 null
60055
60076
  - type \u5FC5\u987B\u662F ${TOPIC_TYPES.join("/")} \u516D\u7C7B\u4E4B\u4E00
60056
60077
  - date \u7EDD\u5BF9\u65E5\u671F\u5E26\u5E74\u4EFD\uFF1Bpeople \u7C7B description \u5F00\u5934\u5199\u4EBA\u540D\uFF1B\u4E00\u6761\u4E00\u4E8B
60057
60078
  - \u65E5\u671F\u4EE5\u5BF9\u5E94\u539F\u6D88\u606F\u7684\u5B8C\u6574\u65F6\u95F4\u548C\u5B9E\u4F8B\u65F6\u533A\u4E3A\u57FA\u51C6\uFF0C\u4E0D\u80FD\u7528\u6574\u7406\u6267\u884C\u5F53\u5929\u4EE3\u66FF\uFF1B\u4E8B\u4EF6\u53EA\u6709\u6708\u65E5\u65F6\u6309\u5BF9\u5E94\u539F\u6D88\u606F\u5E74\u4EFD\u8865\u5168\uFF0C\u65E7 topics \u7F3A\u5E74\u7EDF\u4E00 2026\uFF1B\u6CA1\u6709\u5355\u4E00\u4E8B\u4EF6\u65E5\u671F\u65F6\u7701\u7565 date\uFF0C\u7531\u7F51\u5173\u4FDD\u5B58\u5B8C\u6574\u8BB0\u5F55\u65E5\u671F\uFF1B\u6BCF\u5E74\u751F\u65E5\u4FDD\u7559\u6708\u65E5\u3002\u7ED9\u51FA\u5DF2\u6709\u6761\u76EE\u6E05\u5355\u2014\u2014\u91CD\u590D\u7684\u4E0D\u8981\u518D\u51FA
@@ -66905,14 +66926,15 @@ RestartSec=5
66905
66926
  WantedBy=multi-user.target
66906
66927
  `;
66907
66928
  }
66908
- var CLOUD_ENGINE_INSTALL_LOCK, CLOUD_ENGINE_CHECKSUMS, checksumCommand, CLOUD_ENGINE_START_CHECK, checkIfRecorded;
66929
+ var CLOUD_ENGINE_INSTALL_LOCK, CLOUD_ENGINE_CHECKSUMS, checksumCommand, checksumFailure, CLOUD_ENGINE_START_CHECK, checkIfRecorded;
66909
66930
  var init_config_remap = __esm({
66910
66931
  "src/travel/config-remap.ts"() {
66911
66932
  "use strict";
66912
66933
  CLOUD_ENGINE_INSTALL_LOCK = "/var/lock/engine7-travel-install.lock";
66913
66934
  CLOUD_ENGINE_CHECKSUMS = "/var/lib/engine7/travel-engine.sha256";
66914
66935
  checksumCommand = `/usr/bin/sha256sum --check --strict --quiet ${CLOUD_ENGINE_CHECKSUMS}`;
66915
- CLOUD_ENGINE_START_CHECK = `ExecStartPre=+/usr/bin/flock -s ${CLOUD_ENGINE_INSTALL_LOCK} ${checksumCommand}`;
66936
+ checksumFailure = `[engine7] \u5B8C\u6574\u6027\u6821\u9A8C\u5931\u8D25\uFF1A\u5F15\u64CE\u6587\u4EF6\u88AB travel \u5B89\u88C5\u8DEF\u5F84\u4E4B\u5916\u7684\u65B9\u5F0F\u6539\u8FC7\uFF08\u4F8B\u5982\u673A\u4E0A npm i -g\uFF09\u3002\u4FEE\u590D\uFF1Aengine7 travel-install-local --refresh-manifest\uFF08\u88C5\u65B0\u7248\u672C\u7528 --version X\uFF09`;
66937
+ CLOUD_ENGINE_START_CHECK = `ExecStartPre=+/usr/bin/flock -s ${CLOUD_ENGINE_INSTALL_LOCK} /bin/sh -c '${checksumCommand} || { echo "${checksumFailure}" >&2; exit 1; }'`;
66916
66938
  checkIfRecorded = `ExecStartPre=+/usr/bin/flock -s ${CLOUD_ENGINE_INSTALL_LOCK} /bin/sh -c 'test ! -e ${CLOUD_ENGINE_CHECKSUMS} || exec ${checksumCommand}'`;
66917
66939
  }
66918
66940
  });
@@ -69442,9 +69464,9 @@ console.log(JSON.stringify({api:config.api,profile:{id:process.env.ENGINE_AGENT|
69442
69464
  }
69443
69465
  async function createMoveSteps(log = () => {
69444
69466
  }, runner, owner2 = travelOwner(), recoverLegacy = false) {
69445
- const { execFile: execFile10 } = await import("node:child_process");
69446
- const { promisify: promisify12 } = await import("node:util");
69447
- const exec4 = promisify12(execFile10);
69467
+ const { execFile: execFile11 } = await import("node:child_process");
69468
+ const { promisify: promisify13 } = await import("node:util");
69469
+ const exec4 = promisify13(execFile11);
69448
69470
  const { basename: basename24 } = await import("node:path");
69449
69471
  const run = runner ?? ((command, args, options) => exec4(command, args, { maxBuffer: 32 * 1024 * 1024, ...options }));
69450
69472
  const engineConfigPath = (configPath) => resolve49(configPath);
@@ -69539,12 +69561,16 @@ if(receipt.version!==1||receipt.files?.['install-identity.json']!==hash)process.
69539
69561
  }
69540
69562
  } else if (owner2) await run("ssh", [...sshOptions, host, remoteOwnerCheck(remoteRoot, owner2)], { timeout: 15e3 });
69541
69563
  else if (process.env.ENGINE7_TRAVEL_REQUIRE_OWNER === "1") {
69542
- const installId = JSON.parse(readFileSync94(join127(stateDirOf(configPath), "install-identity.json"), "utf8")).installId;
69543
- if (typeof installId !== "string" || !installId) throw Error("TRAVEL_WRONG_REMOTE_OWNER");
69544
- const script = `const fs=require('node:fs');const [root,id]=process.argv.slice(1);
69545
- try{if(JSON.parse(fs.readFileSync(root+'/install-identity.json','utf8')).installId!==id||
69546
- JSON.parse(fs.readFileSync(root+'/config.json','utf8')).stateDir!==root)process.exit(1)}catch{process.exit(1)}`;
69547
- await run("ssh", [...sshOptions, host, "node -e " + quoteRemote(script) + " " + quoteRemote(remoteRoot) + " " + quoteRemote(installId)], { timeout: 15e3 });
69564
+ const name = String(JSON.parse(readFileSync94(engineConfigPath(configPath), "utf8")).agents?.defaults?.name ?? "");
69565
+ const script = `const fs=require('node:fs');const [root,name]=process.argv.slice(1);
69566
+ try{fs.lstatSync(root+'/.travel/owner.json');process.exit(1)}catch(error){if(error.code!=='ENOENT')throw error}
69567
+ const config=JSON.parse(fs.readFileSync(root+'/config.json','utf8'));
69568
+ if(config.stateDir!==root||(name&&String(config?.agents?.defaults?.name??'')!==name))process.exit(1)`;
69569
+ try {
69570
+ await run("ssh", [...sshOptions, host, "node -e " + quoteRemote(script) + " " + quoteRemote(remoteRoot) + " " + quoteRemote(name)], { timeout: 15e3 });
69571
+ } catch (cause) {
69572
+ throw Error("TRAVEL_WRONG_REMOTE_OWNER \u4E91\u673A\u76EE\u5F55\u4E0D\u662F\u5979\u7684\uFF1Aconfig \u4F19\u4F34\u540D\u4E0D\u7B26\uFF0C\u6216\u5DF2\u88AB\u522B\u7684\u5EA7\u4F4D\u53F7\u8BA4\u9886\u3002", { cause });
69573
+ }
69548
69574
  }
69549
69575
  if (owner2 || recoverLegacy || process.env.ENGINE7_TRAVEL_REQUIRE_OWNER === "1") {
69550
69576
  const { stdout } = await run("ssh", [...sshOptions, host, `systemctl show -p WorkingDirectory --value ${remoteUnit(configPath)}`], { timeout: 15e3 });
@@ -69956,6 +69982,82 @@ var init_medicheck = __esm({
69956
69982
  }
69957
69983
  });
69958
69984
 
69985
+ // src/travel/local-install.ts
69986
+ var local_install_exports = {};
69987
+ __export(local_install_exports, {
69988
+ RUNTIME_ENTRIES: () => RUNTIME_ENTRIES,
69989
+ localInstall: () => localInstall,
69990
+ manifestShell: () => manifestShell,
69991
+ resolveEngineRoot: () => resolveEngineRoot,
69992
+ selectEngineUnits: () => selectEngineUnits,
69993
+ sq: () => sq
69994
+ });
69995
+ import { execFile as execFile9 } from "node:child_process";
69996
+ import { promisify as promisify11 } from "node:util";
69997
+ import { existsSync as existsSync76, realpathSync as realpathSync15 } from "node:fs";
69998
+ import { dirname as dirname47, join as join131 } from "node:path";
69999
+ function sq(s) {
70000
+ return `'${s.replace(/'/g, `'\\''`)}'`;
70001
+ }
70002
+ function manifestShell(engineRoot) {
70003
+ const files = RUNTIME_ENTRIES.map((e) => `"${engineRoot}/${e}"`).join(" ");
70004
+ return `set -e; C="${CLOUD_ENGINE_CHECKSUMS}"; mkdir -p "$(dirname "$C")"; c=$(mktemp "$C.XXXXXX"); sha256sum ${files} > "$c"; mv -f "$c" "$C"; sha256sum --check --strict --quiet "$C"`;
70005
+ }
70006
+ function selectEngineUnits(units, launcher) {
70007
+ return units.filter((u) => u.unit.startsWith("engine7-") && u.unit.endsWith(".service") && u.execStart.includes(` ${launcher} `)).map((u) => u.unit);
70008
+ }
70009
+ function resolveEngineRoot() {
70010
+ return dirname47(dirname47(realpathSync15(process.argv[1])));
70011
+ }
70012
+ async function localInstall(opts) {
70013
+ const engineRoot = opts.engineRoot ?? resolveEngineRoot();
70014
+ const launcher = opts.launcher ?? join131(engineRoot, "bin", "engine7");
70015
+ const run = opts.runner ?? realRunner;
70016
+ const verified = opts.verified ?? existsSync76(CLOUD_ENGINE_CHECKSUMS);
70017
+ const actions = [];
70018
+ let version;
70019
+ if (opts.version) {
70020
+ version = opts.version;
70021
+ await run(`flock -x ${CLOUD_ENGINE_INSTALL_LOCK} sh -c ${sq(`set -e; npm install -g engine7@${opts.version}`)}`);
70022
+ actions.push("install");
70023
+ const got = (await run("engine7 --version")).stdout.trim().split(/\s+/).pop();
70024
+ if (got !== opts.version) throw new Error(`TRAVEL_INSTALL_VERSION_MISMATCH \u88C5\u5B8C engine7 --version=${got}\uFF0C\u671F\u671B ${opts.version}\uFF1B\u6E05\u5355\u672A\u5199\u3001\u670D\u52A1\u672A\u91CD\u542F`);
70025
+ }
70026
+ if ((opts.refreshManifestOnly || opts.version) && verified) {
70027
+ await run(`flock -x ${CLOUD_ENGINE_INSTALL_LOCK} sh -c ${sq(manifestShell(engineRoot))}`);
70028
+ actions.push("manifest");
70029
+ }
70030
+ let units;
70031
+ if (opts.restart) {
70032
+ const listed = (await run(`systemctl list-unit-files 'engine7-*.service' --no-legend --no-pager`)).stdout;
70033
+ const names = listed.split("\n").map((l) => l.trim().split(/\s+/)[0]).filter((n) => n.endsWith(".service"));
70034
+ const infos = [];
70035
+ for (const unit2 of names) {
70036
+ const [workingDirectory, execStart] = (await Promise.all([
70037
+ run(`systemctl show -p WorkingDirectory --value ${unit2}`),
70038
+ run(`systemctl show -p ExecStart --value ${unit2}`)
70039
+ ])).map((r) => r.stdout.trim());
70040
+ infos.push({ unit: unit2, workingDirectory, execStart });
70041
+ }
70042
+ units = selectEngineUnits(infos, launcher);
70043
+ if (units.length) await run(`systemctl restart ${units.join(" ")}`);
70044
+ actions.push("restart");
70045
+ }
70046
+ return { ok: true, actions, ...version ? { version } : {}, ...units ? { units } : {} };
70047
+ }
70048
+ var RUNTIME_ENTRIES, realRunner;
70049
+ var init_local_install = __esm({
70050
+ "src/travel/local-install.ts"() {
70051
+ "use strict";
70052
+ init_config_remap();
70053
+ RUNTIME_ENTRIES = ["dist/main.mjs", "dist/cli.mjs", "dist/engine-startup.mjs", "dist/recall-worker.mjs", "bin/engine7", "package.json"];
70054
+ realRunner = async (cmd) => {
70055
+ const { stdout } = await promisify11(execFile9)("sh", ["-c", cmd], { maxBuffer: 16 * 1024 * 1024 });
70056
+ return { stdout };
70057
+ };
70058
+ }
70059
+ });
70060
+
69959
70061
  // src/travel/remote-setup.ts
69960
70062
  var remote_setup_exports = {};
69961
70063
  __export(remote_setup_exports, {
@@ -69963,18 +70065,18 @@ __export(remote_setup_exports, {
69963
70065
  freeCloudPort: () => freeCloudPort,
69964
70066
  setupRemote: () => setupRemote
69965
70067
  });
69966
- import { execFile as execFile9 } from "node:child_process";
69967
- import { parseEnv, promisify as promisify11 } from "node:util";
70068
+ import { execFile as execFile10 } from "node:child_process";
70069
+ import { parseEnv, promisify as promisify12 } from "node:util";
69968
70070
  import { createHash as createHash61, randomUUID as randomUUID47 } from "node:crypto";
69969
70071
  import { readFileSync as readFileSync98, writeFileSync as writeFileSync57, mkdtempSync as mkdtempSync2, mkdirSync as mkdirSync54, renameSync as renameSync28, rmSync as rmSync9 } from "node:fs";
69970
70072
  import { tmpdir as tmpdir6 } from "node:os";
69971
- import { dirname as dirname47, join as join131, resolve as resolve50 } from "node:path";
70073
+ import { dirname as dirname48, join as join132, resolve as resolve50 } from "node:path";
69972
70074
  import { fileURLToPath as fileURLToPath21 } from "node:url";
69973
70075
  function enginePackageRoot() {
69974
- const here = dirname47(fileURLToPath21(import.meta.url));
69975
- for (const dir of [join131(here, ".."), join131(here, "..", "..")]) {
70076
+ const here = dirname48(fileURLToPath21(import.meta.url));
70077
+ for (const dir of [join132(here, ".."), join132(here, "..", "..")]) {
69976
70078
  try {
69977
- const pkg = JSON.parse(readFileSync98(join131(dir, "package.json"), "utf8"));
70079
+ const pkg = JSON.parse(readFileSync98(join132(dir, "package.json"), "utf8"));
69978
70080
  if (pkg.name === "engine7") return dir;
69979
70081
  } catch {
69980
70082
  }
@@ -70013,7 +70115,7 @@ async function fetchReleaseTarball(version, staging, run, baseUrl = RELEASE_BASE
70013
70115
  }
70014
70116
  }
70015
70117
  if (!expected) return null;
70016
- const target = join131(staging, name);
70118
+ const target = join132(staging, name);
70017
70119
  try {
70018
70120
  await run("curl", ["-fsSL", "-m", "900", "--max-filesize", "268435456", "-o", target, `${baseUrl}/${name}`]);
70019
70121
  } catch {
@@ -70122,7 +70224,7 @@ async function setupRemote(options) {
70122
70224
  } else if (options.forceInstall || options.installOnly || remoteVersion !== localVersion) {
70123
70225
  log(`[setup-remote] engine7 ${remoteVersion || "\u672A\u88C5"} \u2192 ${localVersion}\uFF08tarball \u76F4\u88C5\uFF09`);
70124
70226
  const packageRoot = enginePackageRoot();
70125
- const staging = mkdtempSync2(join131(tmpdir6(), "e7-pkg-"));
70227
+ const staging = mkdtempSync2(join132(tmpdir6(), "e7-pkg-"));
70126
70228
  try {
70127
70229
  const release2 = options.forceInstall ? null : await fetchReleaseTarball(localVersion, staging, run);
70128
70230
  if (!release2 && !options.forceInstall && remoteVersion === localVersion) {
@@ -70136,7 +70238,7 @@ async function setupRemote(options) {
70136
70238
  }
70137
70239
  const remoteStage = "/tmp/engine7-travel-" + randomUUID47();
70138
70240
  await ssh(`umask 077; mkdir -p ${remoteStage}`);
70139
- await scp(join131(staging, tarball), remoteStage + "/");
70241
+ await scp(join132(staging, tarball), remoteStage + "/");
70140
70242
  const remoteTarball = remoteStage + "/" + tarball;
70141
70243
  const probe = async (command) => (await ssh(command)).stdout.trim();
70142
70244
  const mirror = /^cn-[a-z0-9-]+$/.test(await probe("curl -s -m 2 http://100.100.100.200/latest/meta-data/region-id || true")) || await probe("curl -s -m 3 -o /dev/null -w '%{http_code}' https://registry.npmjs.org/engine7/latest || true") !== "200";
@@ -70146,7 +70248,7 @@ async function setupRemote(options) {
70146
70248
  const runtimeEntries = ["dist/main.mjs", "dist/cli.mjs", "dist/engine-startup.mjs", "dist/recall-worker.mjs", "bin/engine7", "package.json"];
70147
70249
  const archiveEntries = runtimeEntries.map((entry) => "package/" + entry).join(" ");
70148
70250
  const result = await ssh(asRoot(`flock -x ${CLOUD_ENGINE_INSTALL_LOCK} sh -c ` + quoteRemote(
70149
- `test -f ${receipt} && exit 0; current=$(engine7 --version 2>/dev/null | sed -n 's/^engine7 \\([0-9][0-9.]*\\)$/\\1/p'); if [ -n "$current" ] && [ "$current" != ${localVersion} ] && [ "$(printf '%s\\n' "$current" ${localVersion} | LC_ALL=C sort -V | tail -n 1)" = "$current" ]; then printf '[setup-remote] \u4FDD\u7559\u4E91\u7AEF\u8F83\u65B0\u7684\u5F15\u64CE %s\\n' "$current"; exit 0; fi; ${install} && test "$(engine7 --version)" = ${quoteRemote("engine7 " + localVersion)} && tar -xzf ${remoteTarball} -C ${remoteStage} ${archiveEntries} && engine_bin=$(readlink -f "$(command -v engine7)") && engine_root=$(dirname "$(dirname "$engine_bin")") && for entry in ${runtimeEntries.join(" ")}; do cmp "${remoteStage}/package/$entry" "$engine_root/$entry" || exit 1; done && mkdir -p ${dirname47(CLOUD_ENGINE_CHECKSUMS)} && checksums=$(mktemp ${CLOUD_ENGINE_CHECKSUMS}.XXXXXX) && sha256sum ${runtimeEntries.map((entry) => '"$engine_root/' + entry + '"').join(" ")} > "$checksums" && mv -f "$checksums" ${CLOUD_ENGINE_CHECKSUMS} && touch ${receipt}`
70251
+ `test -f ${receipt} && exit 0; current=$(engine7 --version 2>/dev/null | sed -n 's/^engine7 \\([0-9][0-9.]*\\)$/\\1/p'); if [ -n "$current" ] && [ "$current" != ${localVersion} ] && [ "$(printf '%s\\n' "$current" ${localVersion} | LC_ALL=C sort -V | tail -n 1)" = "$current" ]; then printf '[setup-remote] \u4FDD\u7559\u4E91\u7AEF\u8F83\u65B0\u7684\u5F15\u64CE %s\\n' "$current"; exit 0; fi; ${install} && test "$(engine7 --version)" = ${quoteRemote("engine7 " + localVersion)} && tar -xzf ${remoteTarball} -C ${remoteStage} ${archiveEntries} && engine_bin=$(readlink -f "$(command -v engine7)") && engine_root=$(dirname "$(dirname "$engine_bin")") && for entry in ${runtimeEntries.join(" ")}; do cmp "${remoteStage}/package/$entry" "$engine_root/$entry" || exit 1; done && mkdir -p ${dirname48(CLOUD_ENGINE_CHECKSUMS)} && checksums=$(mktemp ${CLOUD_ENGINE_CHECKSUMS}.XXXXXX) && sha256sum ${runtimeEntries.map((entry) => '"$engine_root/' + entry + '"').join(" ")} > "$checksums" && mv -f "$checksums" ${CLOUD_ENGINE_CHECKSUMS} && touch ${receipt}`
70150
70252
  )));
70151
70253
  if (result.stdout.includes("[setup-remote] \u4FDD\u7559\u4E91\u7AEF\u8F83\u65B0\u7684\u5F15\u64CE")) log(result.stdout.trim().split("\n").at(-1));
70152
70254
  else verifiedRuntime = true;
@@ -70180,8 +70282,8 @@ async function setupRemote(options) {
70180
70282
  remapped.api = { ...remapped.api ?? {}, port: cloudPort - offset };
70181
70283
  log(`[setup-remote] \u4E91\u673A\u53E3 ${wantedPort} \u5DF2\u88AB\u522B\u7684\u4F19\u4F34\u5360\u7528\uFF0C\u6539\u4E3A ${cloudPort}\uFF08\u672C\u673A\u770B\u7684\u5730\u5740\u4E0D\u53D8\uFF0C\u7F51\u5173\u8F6C\u53D1\uFF09`);
70182
70284
  }
70183
- const localTemp = mkdtempSync2(join131(tmpdir6(), "e7-cfg-"));
70184
- const configFile = join131(localTemp, "config.json");
70285
+ const localTemp = mkdtempSync2(join132(tmpdir6(), "e7-cfg-"));
70286
+ const configFile = join132(localTemp, "config.json");
70185
70287
  writeFileSync57(configFile, JSON.stringify(remapped, null, 2));
70186
70288
  await scp(configFile, `${options.remoteRoot}/config.json`);
70187
70289
  if (secretsPath) {
@@ -70194,7 +70296,7 @@ async function setupRemote(options) {
70194
70296
  const [remoteNode = "node", remoteEngine = "engine7"] = remotePaths.split("\n").map((v) => v.trim()).filter(Boolean);
70195
70297
  const unit2 = buildSystemdUnit({ companion: String(companion), remoteRoot: options.remoteRoot, nodeBin: remoteNode, engineBin: remoteEngine, verifiedRuntime, ...loginUser === "root" ? {} : { user: loginUser } });
70196
70298
  const unitId = unitIdFor(String(companion), owner2);
70197
- const unitFile = join131(localTemp, `engine7-${unitId}.service`);
70299
+ const unitFile = join132(localTemp, `engine7-${unitId}.service`);
70198
70300
  writeFileSync57(unitFile, unit2);
70199
70301
  if (loginUser === "root") {
70200
70302
  await scp(unitFile, `/etc/systemd/system/engine7-${unitId}.service`);
@@ -70208,9 +70310,9 @@ async function setupRemote(options) {
70208
70310
  await ssh(asRoot("systemctl daemon-reload"));
70209
70311
  log(`[setup-remote] \u5B8C\u6210\uFF1A${host}:${options.remoteRoot}\uFF08engine7-${unitId}.service\uFF09`);
70210
70312
  try {
70211
- mkdirSync54(join131(stateDir, ".travel"), { recursive: true });
70313
+ mkdirSync54(join132(stateDir, ".travel"), { recursive: true });
70212
70314
  if (!owner2) {
70213
- const marker = join131(stateDir, ".travel", "remote.json");
70315
+ const marker = join132(stateDir, ".travel", "remote.json");
70214
70316
  const temporary = marker + "." + randomUUID47();
70215
70317
  try {
70216
70318
  writeFileSync57(temporary, JSON.stringify({ host, remoteRoot: root, savedAt: Date.now() }), { mode: 384, flag: "wx" });
@@ -70233,7 +70335,7 @@ var init_remote_setup = __esm({
70233
70335
  init_ssh();
70234
70336
  init_api_port();
70235
70337
  realRun = async (command, args, options) => {
70236
- const run = promisify11(execFile9);
70338
+ const run = promisify12(execFile10);
70237
70339
  try {
70238
70340
  const { stdout } = await run(command, args, { maxBuffer: 32 * 1024 * 1024, ...options });
70239
70341
  return { stdout };
@@ -72377,6 +72479,27 @@ async function main() {
72377
72479
  console.log(`[medicheck] \u5B8C\u6210\uFF1A\u7269\u5316 ${result.fixed.length}\uFF0C\u4ECD\u7F3A ${result.stillMissing.length}`);
72378
72480
  process.exit(0);
72379
72481
  }
72482
+ if (subcommand === "travel-install-local") {
72483
+ try {
72484
+ const { localInstall: localInstall2 } = await Promise.resolve().then(() => (init_local_install(), local_install_exports));
72485
+ let version = "", refreshManifestOnly = false, restart = false;
72486
+ for (let i = 1; i < args.length; i++) {
72487
+ if (args[i] === "--version" && args[i + 1]) version = args[++i];
72488
+ else if (args[i] === "--refresh-manifest") refreshManifestOnly = true;
72489
+ else if (args[i] === "--restart") restart = true;
72490
+ }
72491
+ if (!version && !refreshManifestOnly) {
72492
+ console.error("\u7528\u6CD5: engine7 travel-install-local (--version <x.y.z> | --refresh-manifest) [--restart]");
72493
+ process.exit(1);
72494
+ }
72495
+ const out = await localInstall2({ ...version ? { version } : {}, refreshManifestOnly, restart });
72496
+ console.log(`[travel-install-local] ok: ${out.actions.join(" \u2192 ")}${out.version ? ` (${out.version})` : ""}${out.units ? ` ${out.units.join(" ")}` : ""}`);
72497
+ process.exit(0);
72498
+ } catch (error) {
72499
+ console.error(error instanceof Error ? error.message : String(error));
72500
+ process.exit(1);
72501
+ }
72502
+ }
72380
72503
  if (subcommand === "travel-setup-remote") {
72381
72504
  try {
72382
72505
  const { setupRemote: setupRemote2 } = await Promise.resolve().then(() => (init_remote_setup(), remote_setup_exports));