oasis_test 0.1.115 → 0.1.117

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/index.js +127 -97
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -1933,9 +1933,9 @@ function resolveNodeRef(ref2, candidates) {
1933
1933
  const hit = candidates.find((n) => n.id === r);
1934
1934
  return hit ? { ok: true, id: hit.id } : { ok: false, reason: "not_found" };
1935
1935
  }
1936
- const sep4 = r.indexOf(":");
1937
- const type = (sep4 >= 0 ? r.slice(0, sep4) : r).trim().toLowerCase();
1938
- const title = sep4 >= 0 ? r.slice(sep4 + 1).trim().toLowerCase() : null;
1936
+ const sep5 = r.indexOf(":");
1937
+ const type = (sep5 >= 0 ? r.slice(0, sep5) : r).trim().toLowerCase();
1938
+ const title = sep5 >= 0 ? r.slice(sep5 + 1).trim().toLowerCase() : null;
1939
1939
  const matches = candidates.filter((n) => n.type.toLowerCase() === type && (title === null || (n.title ?? "").toLowerCase() === title));
1940
1940
  if (matches.length === 0) return { ok: false, reason: "not_found" };
1941
1941
  if (matches.length === 1) return { ok: true, id: matches[0].id };
@@ -5726,8 +5726,8 @@ var init_dispatcher = __esm({
5726
5726
  /** 从 produce jobKey 解析 artifactId:`produce::<artifactId>` 或 `produce::<artifactId>::<part>`。 */
5727
5727
  artifactIdFromJobKey(jobKey) {
5728
5728
  const rest = jobKey.slice(jobKey.indexOf("::") + 2);
5729
- const sep4 = rest.indexOf("::");
5730
- return sep4 >= 0 ? rest.slice(0, sep4) : rest;
5729
+ const sep5 = rest.indexOf("::");
5730
+ return sep5 >= 0 ? rest.slice(0, sep5) : rest;
5731
5731
  }
5732
5732
  /**
5733
5733
  * 某节点的派发器运行时信号(stuckDiagnosis 的非 oplog 那半;proposal 协调者阻塞诊断 D1)。
@@ -40107,7 +40107,7 @@ var require_websocket = __commonJS({
40107
40107
  var http2 = require("http");
40108
40108
  var net = require("net");
40109
40109
  var tls = require("tls");
40110
- var { randomBytes: randomBytes7, createHash: createHash18 } = require("crypto");
40110
+ var { randomBytes: randomBytes7, createHash: createHash19 } = require("crypto");
40111
40111
  var { Duplex, Readable } = require("stream");
40112
40112
  var { URL: URL2 } = require("url");
40113
40113
  var PerMessageDeflate2 = require_permessage_deflate();
@@ -40775,7 +40775,7 @@ var require_websocket = __commonJS({
40775
40775
  abortHandshake(websocket, socket, "Invalid Upgrade header");
40776
40776
  return;
40777
40777
  }
40778
- const digest = createHash18("sha1").update(key + GUID).digest("base64");
40778
+ const digest = createHash19("sha1").update(key + GUID).digest("base64");
40779
40779
  if (res.headers["sec-websocket-accept"] !== digest) {
40780
40780
  abortHandshake(websocket, socket, "Invalid Sec-WebSocket-Accept header");
40781
40781
  return;
@@ -41144,7 +41144,7 @@ var require_websocket_server = __commonJS({
41144
41144
  var EventEmitter = require("events");
41145
41145
  var http2 = require("http");
41146
41146
  var { Duplex } = require("stream");
41147
- var { createHash: createHash18 } = require("crypto");
41147
+ var { createHash: createHash19 } = require("crypto");
41148
41148
  var extension2 = require_extension();
41149
41149
  var PerMessageDeflate2 = require_permessage_deflate();
41150
41150
  var subprotocol2 = require_subprotocol();
@@ -41451,7 +41451,7 @@ var require_websocket_server = __commonJS({
41451
41451
  );
41452
41452
  }
41453
41453
  if (this._state > RUNNING) return abortHandshake(socket, 503);
41454
- const digest = createHash18("sha1").update(key + GUID).digest("base64");
41454
+ const digest = createHash19("sha1").update(key + GUID).digest("base64");
41455
41455
  const headers = [
41456
41456
  "HTTP/1.1 101 Switching Protocols",
41457
41457
  "Upgrade: websocket",
@@ -150077,9 +150077,9 @@ function agentEdgesFor(dependsOn, nodes, briefId, issues) {
150077
150077
  edges.add(briefId);
150078
150078
  continue;
150079
150079
  }
150080
- const sep4 = d.indexOf(":");
150081
- const depType = (sep4 >= 0 ? d.slice(0, sep4) : d).trim().toLowerCase();
150082
- const depTitle = sep4 >= 0 ? d.slice(sep4 + 1).trim().toLowerCase() : null;
150080
+ const sep5 = d.indexOf(":");
150081
+ const depType = (sep5 >= 0 ? d.slice(0, sep5) : d).trim().toLowerCase();
150082
+ const depTitle = sep5 >= 0 ? d.slice(sep5 + 1).trim().toLowerCase() : null;
150083
150083
  const match = nodes.find((n) => n.type === depType && (depTitle === null || (n.title ?? "").toLowerCase() === depTitle));
150084
150084
  if (match) edges.add(match.id);
150085
150085
  else issues.push({ code: "planner_invalid", severity: "warning", message: `\u8282\u70B9\u4F9D\u8D56\u300C${dep}\u300D\u627E\u4E0D\u5230\u5BF9\u5E94\u4E0A\u6E38\uFF08\u6309 type:title \u5339\u914D\uFF09\uFF0C\u5DF2\u5FFD\u7565\u8FD9\u6761\u8FB9\u3002` });
@@ -153848,17 +153848,17 @@ function stageConnectorWrapper(connector) {
153848
153848
  const cacheKey = `${commandName} ${scriptPath}`;
153849
153849
  const cached3 = stagedBinDirs.get(cacheKey);
153850
153850
  if (cached3 && (0, import_node_fs4.existsSync)((0, import_node_path4.join)(cached3, commandName))) return (0, import_node_path4.join)(cached3, commandName);
153851
- const binDir2 = (0, import_node_fs4.mkdtempSync)((0, import_node_path4.join)((0, import_node_os.tmpdir)(), `oasis-conn-${connector.config.slug}-`));
153852
- const link = (0, import_node_path4.join)(binDir2, commandName);
153851
+ const binDir = (0, import_node_fs4.mkdtempSync)((0, import_node_path4.join)((0, import_node_os.tmpdir)(), `oasis-conn-${connector.config.slug}-`));
153852
+ const link = (0, import_node_path4.join)(binDir, commandName);
153853
153853
  (0, import_node_fs4.symlinkSync)(scriptPath, link);
153854
153854
  if (!(0, import_node_fs4.existsSync)(link)) {
153855
153855
  try {
153856
- (0, import_node_fs4.rmSync)(binDir2, { recursive: true, force: true });
153856
+ (0, import_node_fs4.rmSync)(binDir, { recursive: true, force: true });
153857
153857
  } catch {
153858
153858
  }
153859
153859
  throw new Error(`connector ${connector.config.slug}: \u8F6F\u94FE\u5EFA\u5B8C\u4ECD\u4E0D\u53EF\u89E3\u6790\uFF08${link} \u2192 ${scriptPath}\uFF09`);
153860
153860
  }
153861
- stagedBinDirs.set(cacheKey, binDir2);
153861
+ stagedBinDirs.set(cacheKey, binDir);
153862
153862
  return link;
153863
153863
  }
153864
153864
  function isStagedWrapperUsable(link) {
@@ -166463,10 +166463,10 @@ function createTokenIssuer(opts = {}) {
166463
166463
  if (revoked.has(token)) return null;
166464
166464
  if (!token.startsWith(SESSION_TOKEN_PREFIX)) return null;
166465
166465
  const encoded = token.slice(SESSION_TOKEN_PREFIX.length);
166466
- const sep4 = encoded.indexOf(".");
166467
- if (sep4 <= 0) return null;
166468
- const payload = encoded.slice(0, sep4);
166469
- const actualSig = encoded.slice(sep4 + 1);
166466
+ const sep5 = encoded.indexOf(".");
166467
+ if (sep5 <= 0) return null;
166468
+ const payload = encoded.slice(0, sep5);
166469
+ const actualSig = encoded.slice(sep5 + 1);
166470
166470
  const expectedSig = sign(secret, payload);
166471
166471
  if (!signatureMatches(actualSig, expectedSig)) return null;
166472
166472
  let claims;
@@ -197452,8 +197452,8 @@ exec ${JSON.stringify(tsx)} ${JSON.stringify(main)} "$@"
197452
197452
  return wrapper;
197453
197453
  }
197454
197454
  function splitIdentityFiles3(prompt) {
197455
- const sep4 = /<!-- FILE: (.+?) -->\n?/g;
197456
- const parts = prompt.split(sep4);
197455
+ const sep5 = /<!-- FILE: (.+?) -->\n?/g;
197456
+ const parts = prompt.split(sep5);
197457
197457
  if (parts.length === 1) return { "identity/AGENTS.md": prompt };
197458
197458
  const out = {};
197459
197459
  for (let i = 1; i < parts.length; i += 2) {
@@ -206558,8 +206558,8 @@ function sanitizeDaemonPath(rawPath) {
206558
206558
  return !SESSION_SCOPED_PREFIXES.some((p2) => base.startsWith(p2));
206559
206559
  }).join(":");
206560
206560
  }
206561
- function installRuntimeAssets(srcRoot, binDir2) {
206562
- if (path29.resolve(srcRoot) === path29.resolve(binDir2)) return 0;
206561
+ function installRuntimeAssets(srcRoot, binDir) {
206562
+ if (path29.resolve(srcRoot) === path29.resolve(binDir)) return 0;
206563
206563
  let copied = 0;
206564
206564
  let entries;
206565
206565
  try {
@@ -206577,7 +206577,7 @@ function installRuntimeAssets(srcRoot, binDir2) {
206577
206577
  continue;
206578
206578
  }
206579
206579
  if (files.length === 0) continue;
206580
- const destDir = path29.join(binDir2, entry.name);
206580
+ const destDir = path29.join(binDir, entry.name);
206581
206581
  fs35.mkdirSync(destDir, { recursive: true });
206582
206582
  for (const f2 of files) {
206583
206583
  const dest = path29.join(destDir, f2);
@@ -206588,10 +206588,10 @@ function installRuntimeAssets(srcRoot, binDir2) {
206588
206588
  }
206589
206589
  return copied;
206590
206590
  }
206591
- function syncRuntimeAssets(candidateRoots, binDir2) {
206592
- fs35.mkdirSync(binDir2, { recursive: true });
206591
+ function syncRuntimeAssets(candidateRoots, binDir) {
206592
+ fs35.mkdirSync(binDir, { recursive: true });
206593
206593
  for (const root of candidateRoots) {
206594
- const copied = installRuntimeAssets(root, binDir2);
206594
+ const copied = installRuntimeAssets(root, binDir);
206595
206595
  if (copied > 0) return { from: root, copied };
206596
206596
  }
206597
206597
  return null;
@@ -206604,12 +206604,9 @@ var path30 = __toESM(require("node:path"));
206604
206604
  var DEFAULT_INSTANCE = "default";
206605
206605
  var home = () => os12.homedir();
206606
206606
  var oasisDir = () => path30.join(home(), ".oasis");
206607
- var binDir = () => path30.join(oasisDir(), "bin");
206608
- var binFile = () => path30.join(binDir(), "oasis.js");
206609
- var npmPrefix = () => path30.join(oasisDir(), "npm-global");
206610
206607
  var versionsDir = () => path30.join(oasisDir(), "versions");
206611
- var versionDir = (v2) => path30.join(versionsDir(), v2);
206612
- var currentLink = () => path30.join(oasisDir(), "current");
206608
+ var versionDir = (label) => path30.join(versionsDir(), label);
206609
+ var npmPrefix = () => path30.join(oasisDir(), "npm-global");
206613
206610
  var localBin = () => path30.join(home(), ".local", "bin", "oasis");
206614
206611
  var instancesRoot = () => path30.join(oasisDir(), "instances");
206615
206612
  function isValidInstanceName(name) {
@@ -206625,7 +206622,11 @@ function instancePaths(name) {
206625
206622
  dir,
206626
206623
  configFile: path30.join(dir, "node-config.json"),
206627
206624
  pidFile: path30.join(dir, "node.pid"),
206628
- logFile: path30.join(dir, "node.log")
206625
+ logFile: path30.join(dir, "node.log"),
206626
+ binDir: path30.join(dir, "bin"),
206627
+ binFile: path30.join(dir, "bin", "oasis.js"),
206628
+ currentLink: path30.join(dir, "current"),
206629
+ sessionsDir: path30.join(dir, "sessions")
206629
206630
  };
206630
206631
  }
206631
206632
  function listInstances() {
@@ -206644,6 +206645,16 @@ function listInstances() {
206644
206645
  }
206645
206646
  return found;
206646
206647
  }
206648
+ function referencedVersionLabels() {
206649
+ const labels = /* @__PURE__ */ new Set();
206650
+ for (const name of listInstances()) {
206651
+ try {
206652
+ labels.add(path30.basename(fs36.realpathSync(instancePaths(name).currentLink)));
206653
+ } catch {
206654
+ }
206655
+ }
206656
+ return [...labels];
206657
+ }
206647
206658
  function normalizeServerUrl(raw) {
206648
206659
  try {
206649
206660
  const u = new URL(raw);
@@ -206656,24 +206667,26 @@ function normalizeServerUrl(raw) {
206656
206667
  return raw.trim().replace(/\/+$/, "").toLowerCase();
206657
206668
  }
206658
206669
  }
206659
- function hostSlug(raw) {
206660
- let host;
206661
- try {
206662
- host = new URL(raw).hostname;
206663
- } catch {
206664
- host = raw.replace(/^[a-z]+:\/\//i, "").split("/")[0] ?? raw;
206665
- }
206666
- const slug6 = host.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
206667
- return slug6 || "node";
206668
- }
206669
206670
  var systemdUnitName = (name) => `oasis-node@${name}.service`;
206670
206671
  var launchdLabel = (name) => name === DEFAULT_INSTANCE ? "com.oasis.node" : `com.oasis.node.${name}`;
206671
206672
  var LEGACY_SYSTEMD_UNIT = "oasis-node.service";
206672
206673
  var LEGACY_LAUNCHD_LABEL = "com.oasis.node";
206673
206674
 
206674
206675
  // src/install.ts
206676
+ var import_node_crypto50 = require("node:crypto");
206675
206677
  var fs37 = __toESM(require("node:fs"));
206676
206678
  var path31 = __toESM(require("node:path"));
206679
+ function versionLabel(sourceFile, pkgVersion, npmPrefixDir) {
206680
+ if (isFromNpmPrefix(sourceFile, npmPrefixDir)) return pkgVersion;
206681
+ const digest = (0, import_node_crypto50.createHash)("sha256").update(fs37.readFileSync(sourceFile)).digest("hex").slice(0, 8);
206682
+ return `${pkgVersion}+local.${digest}`;
206683
+ }
206684
+ function isFromNpmPrefix(sourceFile, npmPrefixDir) {
206685
+ const src = realpathOrSelf(sourceFile);
206686
+ const root = realpathOrSelf(path31.join(npmPrefixDir, "lib", "node_modules"));
206687
+ return src.startsWith(root + path31.sep);
206688
+ }
206689
+ var isLocalLabel = (label) => label.includes("+local.");
206677
206690
  function installBinaryAtomic(sourceFile, targetPath) {
206678
206691
  if (realpathOrSelf(sourceFile) === realpathOrSelf(targetPath)) return;
206679
206692
  fs37.mkdirSync(path31.dirname(targetPath), { recursive: true });
@@ -206715,8 +206728,9 @@ function pointCurrentAt(linkPath, targetDir) {
206715
206728
  }
206716
206729
  }
206717
206730
  function gcVersions(versionsDirPath, opts) {
206718
- const keepRecent = opts.keepRecent ?? 2;
206719
- const minAgeMs = opts.minAgeMs ?? 24 * 60 * 60 * 1e3;
206731
+ const keep = new Set(opts.keep);
206732
+ const keepSpare = opts.keepSpare ?? 1;
206733
+ const minAgeMs = opts.minAgeMs ?? 60 * 60 * 1e3;
206720
206734
  const now = opts.now ?? Date.now();
206721
206735
  let entries;
206722
206736
  try {
@@ -206724,7 +206738,7 @@ function gcVersions(versionsDirPath, opts) {
206724
206738
  } catch {
206725
206739
  return [];
206726
206740
  }
206727
- const candidates = entries.filter((name) => name !== opts.keep && !name.includes(".tmp.")).map((name) => {
206741
+ const candidates = entries.filter((name) => !keep.has(name) && !name.includes(".tmp.")).map((name) => {
206728
206742
  const full = path31.join(versionsDirPath, name);
206729
206743
  try {
206730
206744
  const st = fs37.statSync(full);
@@ -206734,7 +206748,7 @@ function gcVersions(versionsDirPath, opts) {
206734
206748
  }
206735
206749
  }).filter((x2) => x2 !== null).sort((a, b2) => b2.mtime - a.mtime);
206736
206750
  const deleted = [];
206737
- for (const c of candidates.slice(keepRecent)) {
206751
+ for (const c of candidates.slice(keepSpare)) {
206738
206752
  if (now - c.mtime < minAgeMs) continue;
206739
206753
  try {
206740
206754
  fs37.rmSync(c.full, { recursive: true, force: true });
@@ -206756,9 +206770,7 @@ function shimScript() {
206756
206770
  }
206757
206771
 
206758
206772
  // src/index.ts
206759
- var PKG_VERSION = true ? "0.1.115" : "dev";
206760
- var BIN_DIR = binDir();
206761
- var BIN_FILE = binFile();
206773
+ var PKG_VERSION = true ? "0.1.117" : "dev";
206762
206774
  var LOCAL_BIN = localBin();
206763
206775
  var NPM_PREFIX = npmPrefix();
206764
206776
  var INSTANCE = DEFAULT_INSTANCE;
@@ -206766,19 +206778,28 @@ var INST = instancePaths(DEFAULT_INSTANCE);
206766
206778
  var CONFIG_FILE = INST.configFile;
206767
206779
  var PID_FILE = INST.pidFile;
206768
206780
  var LOG_FILE = INST.logFile;
206781
+ var BIN_DIR = INST.binDir;
206782
+ var BIN_FILE = INST.binFile;
206769
206783
  function useInstance(name) {
206770
206784
  INSTANCE = name;
206771
206785
  INST = instancePaths(name);
206772
206786
  CONFIG_FILE = INST.configFile;
206773
206787
  PID_FILE = INST.pidFile;
206774
206788
  LOG_FILE = INST.logFile;
206789
+ BIN_DIR = INST.binDir;
206790
+ BIN_FILE = INST.binFile;
206775
206791
  }
206776
206792
  var PKG_NAME = "oasis_test";
206777
206793
  var parseFlags = (argv) => {
206778
206794
  const flags = /* @__PURE__ */ new Map();
206779
206795
  for (let i = 0; i < argv.length; i++) {
206780
206796
  const a = argv[i];
206781
- if (a.startsWith("--")) flags.set(a.slice(2), argv[++i] ?? "");
206797
+ if (!a.startsWith("--")) continue;
206798
+ const next = argv[i + 1];
206799
+ if (next !== void 0 && !next.startsWith("--")) {
206800
+ flags.set(a.slice(2), next);
206801
+ i++;
206802
+ } else flags.set(a.slice(2), "");
206782
206803
  }
206783
206804
  return flags;
206784
206805
  };
@@ -206833,20 +206854,23 @@ function ensureRuntimeAssets(targetDir = BIN_DIR) {
206833
206854
  }
206834
206855
  function installSoftware() {
206835
206856
  const src = process.argv[1];
206836
- const vDir = versionDir(PKG_VERSION);
206857
+ const label = versionLabel(src, PKG_VERSION, NPM_PREFIX);
206858
+ const vDir = versionDir(label);
206837
206859
  installBinaryAtomic(src, path32.join(vDir, "oasis.js"));
206838
206860
  ensureRuntimeAssets(vDir);
206839
- pointCurrentAt(currentLink(), vDir);
206840
206861
  installBinaryAtomic(src, BIN_FILE);
206841
206862
  ensureRuntimeAssets(BIN_DIR);
206863
+ pointCurrentAt(INST.currentLink, vDir);
206842
206864
  fs38.mkdirSync(path32.dirname(LOCAL_BIN), { recursive: true });
206843
206865
  fs38.writeFileSync(LOCAL_BIN, shimScript(), { mode: 493 });
206844
- const removed = gcVersions(versionsDir(), { keep: PKG_VERSION });
206845
- if (removed.length) console.error(`[oasis] \u7248\u672C GC\uFF1A\u5220\u9664 ${removed.join(", ")}\uFF08\u4FDD\u7559 ${PKG_VERSION} + \u6700\u8FD1 2 \u7248\uFF09`);
206866
+ const keep = [.../* @__PURE__ */ new Set([label, ...referencedVersionLabels()])];
206867
+ const removed = gcVersions(versionsDir(), { keep });
206868
+ if (removed.length) console.error(`[oasis] \u7248\u672C GC\uFF1A\u5220\u9664 ${removed.join(", ")}\uFF08\u5728\u7528\uFF1A${keep.join(", ")}\uFF09`);
206869
+ return label;
206846
206870
  }
206847
206871
  function setupAutostart(name) {
206848
206872
  const inst = instancePaths(name);
206849
- const cmd = `${process.execPath} "${BIN_FILE}" --_daemon --instance ${name}`;
206873
+ const cmd = `${process.execPath} "${inst.binFile}" --_daemon --instance ${name}`;
206850
206874
  const home2 = os13.homedir();
206851
206875
  const pnpmHome = process.env["PNPM_HOME"] || path32.join(home2, ".local", "share", "pnpm");
206852
206876
  const extraBins = [
@@ -206866,9 +206890,13 @@ function setupAutostart(name) {
206866
206890
  `Description=Oasis Node Daemon (${name})`,
206867
206891
  "After=network.target",
206868
206892
  "",
206893
+ // OASIS_CLI_HOME 由 daemon 继承给它 spawn 的 agent 会话——非 default 实例的会话因此
206894
+ // 用的是**本实例**的 CLI 版本,而不是 PATH 上那个默认指向 default 的 shim。
206895
+ // (台阶 3 的 D4 后半截会把它细到「每个会话钉 spawn 那一刻的版本」,这里先钉到实例。)
206869
206896
  "[Service]",
206870
206897
  `ExecStart=${cmd}`,
206871
206898
  `Environment=PATH=${daemonPath}`,
206899
+ `Environment=OASIS_CLI_HOME=${inst.currentLink}`,
206872
206900
  `StandardOutput=append:${inst.logFile}`,
206873
206901
  `StandardError=append:${inst.logFile}`,
206874
206902
  "Restart=on-failure",
@@ -206916,9 +206944,12 @@ function setupAutostart(name) {
206916
206944
  function spawnDaemon() {
206917
206945
  fs38.mkdirSync(path32.dirname(LOG_FILE), { recursive: true });
206918
206946
  const log3 = fs38.openSync(LOG_FILE, "a");
206919
- const child = (0, import_node_child_process19.spawn)(process.execPath, [BIN_FILE, "--_daemon", "--instance", INSTANCE], {
206947
+ const child = (0, import_node_child_process19.spawn)(process.execPath, [INST.binFile, "--_daemon", "--instance", INSTANCE], {
206920
206948
  detached: true,
206921
- stdio: ["ignore", log3, log3]
206949
+ stdio: ["ignore", log3, log3],
206950
+ // 与 systemd unit 里那条 Environment 等价——detached 兜底路径不能少,否则同一实例在两条
206951
+ // 启动路径下 spawn 出的会话会用不同版本的 CLI。
206952
+ env: { ...process.env, OASIS_CLI_HOME: INST.currentLink }
206922
206953
  });
206923
206954
  child.unref();
206924
206955
  return child.pid ?? 0;
@@ -206961,9 +206992,17 @@ function stopDaemon(name) {
206961
206992
  }
206962
206993
  }
206963
206994
  }
206964
- function selfUpdate() {
206995
+ function selfUpdate(opts = {}) {
206965
206996
  const cfg = readConfig();
206966
206997
  if (!cfg?.serverUrl) throw new Error("no config \u2014 run `oasis daemon start` first");
206998
+ if (cfg.pinnedVersion && !opts.force) {
206999
+ console.error(`[oasis] \u5B9E\u4F8B ${INSTANCE} \u5DF2\u9489\u5728 ${cfg.pinnedVersion}\uFF0C\u8DF3\u8FC7\u81EA\u66F4\u65B0\uFF08\u8981\u89E3\u9664\uFF1Aoasis daemon update --instance ${INSTANCE} --force\uFF09`);
207000
+ return false;
207001
+ }
207002
+ if (cfg.pinnedVersion && opts.force) {
207003
+ saveConfig({ ...cfg, pinnedVersion: void 0 });
207004
+ console.error(`[oasis] --force\uFF1A\u5DF2\u89E3\u9664 ${INSTANCE} \u7684\u7248\u672C\u9489\u6B7B\uFF08\u539F ${cfg.pinnedVersion}\uFF09`);
207005
+ }
206967
207006
  const nameArg = cfg.name ? ` --name '${cfg.name.replace(/'/g, "'\\''")}'` : "";
206968
207007
  const oasisBin = path32.join(NPM_PREFIX, "bin", "oasis");
206969
207008
  const startCmd = `"${oasisBin}" daemon start --instance ${INSTANCE} --server-ws '${cfg.serverUrl}'${nameArg}`;
@@ -206991,37 +207030,15 @@ function selfUpdate() {
206991
207030
  const child = (0, import_node_child_process19.spawn)("sh", ["-c", inner], { detached: true, stdio: ["ignore", log3, log3] });
206992
207031
  child.unref();
206993
207032
  }
207033
+ return true;
206994
207034
  }
206995
- function resolveInstance(explicit, serverUrl, forStart) {
206996
- if (explicit) {
206997
- if (!isValidInstanceName(explicit)) {
206998
- console.error(`[oasis] \u975E\u6CD5\u5B9E\u4F8B\u540D "${explicit}"\uFF1A\u53EA\u5141\u8BB8\u5C0F\u5199\u5B57\u6BCD/\u6570\u5B57/.-_\uFF0C\u4E14\u4EE5\u5B57\u6BCD\u6570\u5B57\u5F00\u5934`);
206999
- process.exit(1);
207000
- }
207001
- return explicit;
207002
- }
207003
- const existing = listInstances();
207004
- if (existing.length === 0) return DEFAULT_INSTANCE;
207005
- if (existing.length === 1) return existing[0];
207006
- const demand = (why) => {
207007
- console.error(`[oasis] \u672C\u673A\u6709 ${existing.length} \u4E2A daemon \u5B9E\u4F8B\uFF08${existing.join(", ")}\uFF09\uFF1A${why}`);
207008
- console.error(` \u8BF7\u7528 --instance <name> \u663E\u5F0F\u6307\u5B9A\u3002`);
207035
+ function resolveInstance(explicit) {
207036
+ if (!explicit) return DEFAULT_INSTANCE;
207037
+ if (!isValidInstanceName(explicit)) {
207038
+ console.error(`[oasis] \u975E\u6CD5\u5B9E\u4F8B\u540D "${explicit}"\uFF1A\u53EA\u5141\u8BB8\u5C0F\u5199\u5B57\u6BCD/\u6570\u5B57/.-_\uFF0C\u4E14\u4EE5\u5B57\u6BCD\u6570\u5B57\u5F00\u5934`);
207009
207039
  process.exit(1);
207010
- };
207011
- if (!serverUrl) return demand("\u6CA1\u7ED9 --server-ws\uFF0C\u65E0\u4ECE\u5224\u65AD\u4F60\u8981\u54EA\u4E00\u4E2A");
207012
- const want = normalizeServerUrl(serverUrl);
207013
- const hit = existing.filter((n) => {
207014
- const c = readConfigAt(instancePaths(n).configFile);
207015
- return !!c?.serverUrl && normalizeServerUrl(c.serverUrl) === want;
207016
- });
207017
- if (hit.length === 1) return hit[0];
207018
- if (hit.length > 1) return demand(`${hit.join(", ")} \u90FD\u8FDE\u7740 ${want}`);
207019
- if (!forStart) return demand(`\u6CA1\u6709\u5B9E\u4F8B\u8FDE\u7740 ${want}`);
207020
- const slug6 = hostSlug(serverUrl);
207021
- if (existing.includes(slug6)) {
207022
- return demand(`\u81EA\u52A8\u5B9E\u4F8B\u540D "${slug6}" \u5DF2\u88AB\u5360\u7528\uFF0C\u800C\u5B83\u8FDE\u7684\u4E0D\u662F ${want}`);
207023
207040
  }
207024
- return slug6;
207041
+ return explicit;
207025
207042
  }
207026
207043
  function derivedNodeIdFor(name) {
207027
207044
  if (name === DEFAULT_INSTANCE) return resolveNodeId();
@@ -207047,7 +207064,7 @@ void (async () => {
207047
207064
  }
207048
207065
  const flags = parseFlags(dargs);
207049
207066
  if (cmd === "--_daemon") {
207050
- useInstance(resolveInstance(flags.get("instance"), void 0, false));
207067
+ useInstance(resolveInstance(flags.get("instance")));
207051
207068
  const cfg = readConfig();
207052
207069
  if (!cfg) {
207053
207070
  console.error("[oasis] no config \u2014 run `oasis daemon start` first");
@@ -207128,13 +207145,18 @@ void (async () => {
207128
207145
  }
207129
207146
  if (dsub === "start") {
207130
207147
  const serverUrlFlag = flags.get("server-ws") ?? process.env["OASIS_SERVER_WS"];
207131
- useInstance(resolveInstance(flags.get("instance"), serverUrlFlag, true));
207148
+ useInstance(resolveInstance(flags.get("instance")));
207132
207149
  const prev = readConfig();
207133
207150
  const serverUrl = serverUrlFlag ?? prev?.serverUrl;
207134
207151
  if (!serverUrl) {
207135
207152
  console.error("Usage: oasis daemon start --server-ws <wss://...> (--enroll-token <ent_...> | --token <ont_...>) [--name <name>] [--instance <name>]");
207136
207153
  process.exit(1);
207137
207154
  }
207155
+ if (!flags.get("instance") && prev?.serverUrl && normalizeServerUrl(prev.serverUrl) !== normalizeServerUrl(serverUrl)) {
207156
+ console.error(`[oasis] \u26A0 \u5B9E\u4F8B "${INSTANCE}" \u539F\u672C\u8FDE ${prev.serverUrl}\uFF0C\u672C\u6B21\u5C06\u6539\u8FDE ${serverUrl}\u2014\u2014\u8FD9\u662F**\u8FC1\u79FB**\u4E0D\u662F\u65B0\u589E\u3002`);
207157
+ console.error(`[oasis] \u60F3\u8BA9\u4E24\u4E2A\u63A7\u5236\u9762\u5E76\u5B58\uFF0C\u8BF7\u4E2D\u6B62\uFF08Ctrl-C\uFF09\u5E76\u6539\u7528\uFF1A`);
207158
+ console.error(`[oasis] oasis daemon start --instance <\u65B0\u540D\u5B57> --server-ws ${serverUrl} --enroll-token <ent_...>`);
207159
+ }
207138
207160
  const serverChanged = !!prev?.serverUrl && prev.serverUrl !== serverUrl;
207139
207161
  let nodeId = serverChanged ? void 0 : prev?.nodeId;
207140
207162
  let token = serverChanged ? flags.get("token") ?? process.env["OASIS_NODE_TOKEN"] : flags.get("token") ?? process.env["OASIS_NODE_TOKEN"] ?? prev?.token;
@@ -207161,7 +207183,11 @@ void (async () => {
207161
207183
  const name = flags.get("name") ?? prev?.name;
207162
207184
  const nameChanged = prev?.name !== void 0 && name !== prev.name;
207163
207185
  saveConfig({ serverUrl, token, nodeId, ...name ? { name } : {}, reportRuntimesOnNextStart: true });
207164
- installSoftware();
207186
+ const installedLabel = installSoftware();
207187
+ if (isLocalLabel(installedLabel)) {
207188
+ saveConfig({ ...readConfig(), pinnedVersion: installedLabel });
207189
+ console.log(` \u672C\u5730\u6784\u5EFA \u2192 \u5DF2\u9489\u7248\u672C ${installedLabel}\uFF08\u81EA\u66F4\u65B0\u5BF9\u672C\u5B9E\u4F8B\u5931\u6548\uFF1B\u89E3\u9664\uFF1Aoasis daemon update --instance ${INSTANCE} --force\uFF09`);
207190
+ }
207165
207191
  stopDaemon(INSTANCE);
207166
207192
  const tookOver = setupAutostart(INSTANCE);
207167
207193
  const suffix = `${nameChanged ? ` [name updated: ${prev.name} \u2192 ${name}]` : ""}`;
@@ -207178,13 +207204,13 @@ void (async () => {
207178
207204
  return;
207179
207205
  }
207180
207206
  if (dsub === "stop") {
207181
- useInstance(resolveInstance(flags.get("instance"), flags.get("server-ws"), false));
207207
+ useInstance(resolveInstance(flags.get("instance")));
207182
207208
  stopDaemon(INSTANCE);
207183
207209
  console.log(`\u2713 stopped (instance ${INSTANCE})`);
207184
207210
  return;
207185
207211
  }
207186
207212
  if (dsub === "restart") {
207187
- useInstance(resolveInstance(flags.get("instance"), flags.get("server-ws"), false));
207213
+ useInstance(resolveInstance(flags.get("instance")));
207188
207214
  stopDaemon(INSTANCE);
207189
207215
  if (!readConfig()) {
207190
207216
  console.error("no config \u2014 run `oasis daemon start` first");
@@ -207195,14 +207221,18 @@ void (async () => {
207195
207221
  return;
207196
207222
  }
207197
207223
  if (dsub === "update") {
207198
- useInstance(resolveInstance(flags.get("instance"), flags.get("server-ws"), false));
207224
+ useInstance(resolveInstance(flags.get("instance")));
207199
207225
  if (!readConfig()?.serverUrl) {
207200
207226
  console.error("no config \u2014 run `oasis daemon start` first");
207201
207227
  process.exit(1);
207202
207228
  }
207203
- console.log(`\u2192 \u66F4\u65B0 ${PKG_NAME} \u5230\u6700\u65B0\u7248\u672C\u5E76\u91CD\u542F\u8282\u70B9\u2026`);
207204
- selfUpdate();
207205
- console.log(`\u2713 \u66F4\u65B0\u5DF2\u89E6\u53D1\uFF08\u540E\u53F0\u62C9\u53D6 ${PKG_NAME}@latest \u5E76\u91CD\u542F\uFF09\uFF1B\u67E5\u770B\u65E5\u5FD7\uFF1Atail -f ${LOG_FILE}`);
207229
+ const forced = flags.has("force") || dargs.includes("--force");
207230
+ console.log(`\u2192 \u66F4\u65B0 ${PKG_NAME} \u5230\u6700\u65B0\u7248\u672C\u5E76\u91CD\u542F\u8282\u70B9\u2026${forced ? "\uFF08--force\uFF1A\u5FFD\u7565\u5E76\u89E3\u9664\u7248\u672C\u9489\u6B7B\uFF09" : ""}`);
207231
+ if (selfUpdate({ force: forced })) {
207232
+ console.log(`\u2713 \u66F4\u65B0\u5DF2\u89E6\u53D1\uFF08\u540E\u53F0\u62C9\u53D6 ${PKG_NAME}@latest \u5E76\u91CD\u542F\uFF09\uFF1B\u67E5\u770B\u65E5\u5FD7\uFF1Atail -f ${LOG_FILE}`);
207233
+ } else {
207234
+ console.log(`\uFF08\u672A\u89E6\u53D1\u66F4\u65B0\u2014\u2014\u672C\u5B9E\u4F8B\u5DF2\u9489\u7248\u672C\uFF09`);
207235
+ }
207206
207236
  return;
207207
207237
  }
207208
207238
  if (dsub === "status") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oasis_test",
3
- "version": "0.1.115",
3
+ "version": "0.1.117",
4
4
  "description": "Oasis node daemon + CLI — background daemon, auto-start, full server CLI",
5
5
  "bin": {
6
6
  "oasis": "./dist/index.js"
@@ -26,6 +26,6 @@
26
26
  "node": ">=20"
27
27
  },
28
28
  "oasisRelease": {
29
- "sourceHead": "dab28ef58182b7f3744481d124d14f54459588ae"
29
+ "sourceHead": "e184c6203a01203cf15f702f0bd0f744584dccd4"
30
30
  }
31
31
  }