@yoooclaw/cli 0.8.0-beta.1 → 0.8.1

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.
@@ -0,0 +1,75 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+
4
+ // Restore the owner recorded by preinstall. Switching Hermes -> CLI is never
5
+ // inferred from an update: it requires YOOOCLAW_ACTIVATE_OWNER=cli.
6
+
7
+ const { spawnSync } = require("node:child_process");
8
+ const fs = require("node:fs");
9
+ const os = require("node:os");
10
+ const path = require("node:path");
11
+
12
+ const root = process.env.YOOOCLAW_HOME || path.join(os.homedir(), ".yoooclaw");
13
+ const statePath = path.join(root, ".cli-install-handoff.json");
14
+ let state = { activationRequested: false, runningProfiles: [] };
15
+ try {
16
+ state = JSON.parse(fs.readFileSync(statePath, "utf8"));
17
+ } catch {
18
+ // A first install or an npm client that skipped preinstall has no owner to restore.
19
+ }
20
+ const activationRequested =
21
+ process.env.YOOOCLAW_ACTIVATE_OWNER === "cli" || state.activationRequested === true;
22
+ const runningProfiles = Array.isArray(state.runningProfiles) ? state.runningProfiles : [];
23
+
24
+ if (!activationRequested && runningProfiles.length === 0) {
25
+ try {
26
+ fs.unlinkSync(statePath);
27
+ } catch {}
28
+ process.stderr.write("@yoooclaw/cli: installed; current Relay owner preserved\n");
29
+ process.exit(0);
30
+ }
31
+
32
+ function resolveBinary() {
33
+ const pkg = `@yoooclaw/cli-${process.platform}-${process.arch}`;
34
+ const binName = process.platform === "win32" ? "yc.exe" : "yc";
35
+ try {
36
+ return require.resolve(`${pkg}/bin/${binName}`);
37
+ } catch {
38
+ return null;
39
+ }
40
+ }
41
+
42
+ const bin = resolveBinary();
43
+ if (!bin) {
44
+ process.stderr.write(
45
+ "@yoooclaw/cli: native binary is unavailable; cannot restore Relay owner\n",
46
+ );
47
+ process.exit(1);
48
+ }
49
+
50
+ function run(args) {
51
+ const result = spawnSync(bin, args, {
52
+ stdio: "inherit",
53
+ env: process.env,
54
+ windowsHide: true,
55
+ });
56
+ if (result.error || result.status !== 0) {
57
+ process.exit(typeof result.status === "number" ? result.status : 1);
58
+ }
59
+ }
60
+
61
+ if (activationRequested) {
62
+ const args = ["owner", "activate", "cli", "--format", "json"];
63
+ if (process.env.HERMES_PROFILE) {
64
+ args.push("--hermes-profile", process.env.HERMES_PROFILE);
65
+ }
66
+ run(args);
67
+ } else {
68
+ for (const profile of runningProfiles) {
69
+ run(["--profile", profile, "daemon", "start", "--format", "json"]);
70
+ }
71
+ }
72
+
73
+ try {
74
+ fs.unlinkSync(statePath);
75
+ } catch {}
@@ -0,0 +1,70 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+
4
+ // Record and drain only standalone daemons that are actually running before
5
+ // npm replaces the native package. Hermes-owned installs have no standalone
6
+ // daemon, so a normal npm update leaves Hermes and its Gateway untouched.
7
+
8
+ const { spawnSync } = require("node:child_process");
9
+ const fs = require("node:fs");
10
+ const os = require("node:os");
11
+ const path = require("node:path");
12
+
13
+ const root = process.env.YOOOCLAW_HOME || path.join(os.homedir(), ".yoooclaw");
14
+ const profilesRoot = path.join(root, "profiles");
15
+ const statePath = path.join(root, ".cli-install-handoff.json");
16
+ const activationRequested = process.env.YOOOCLAW_ACTIVATE_OWNER === "cli";
17
+ let profiles = [];
18
+ try {
19
+ profiles = fs
20
+ .readdirSync(profilesRoot, { withFileTypes: true })
21
+ .filter((entry) => entry.isDirectory())
22
+ .map((entry) => entry.name);
23
+ } catch {
24
+ profiles = ["default"];
25
+ }
26
+
27
+ function oldCLIFor(profile) {
28
+ try {
29
+ const lock = JSON.parse(
30
+ fs.readFileSync(path.join(profilesRoot, profile, "daemon.lock"), "utf8"),
31
+ );
32
+ if (lock.executable && fs.existsSync(lock.executable)) {
33
+ return lock.executable;
34
+ }
35
+ } catch {
36
+ // Missing/stale lock is normal when Hermes owns the runtime.
37
+ }
38
+ return process.platform === "win32" ? "yoooclaw.cmd" : "yoooclaw";
39
+ }
40
+
41
+ const runningProfiles = [];
42
+ for (const profile of profiles) {
43
+ const oldCLI = oldCLIFor(profile);
44
+ const status = spawnSync(
45
+ oldCLI,
46
+ ["--profile", profile, "daemon", "status", "--format", "json"],
47
+ { stdio: "ignore", env: process.env, windowsHide: true },
48
+ );
49
+ if (status.status !== 0) continue;
50
+
51
+ const stopped = spawnSync(
52
+ oldCLI,
53
+ ["--profile", profile, "daemon", "stop", "--format", "json"],
54
+ { stdio: "inherit", env: process.env, windowsHide: true },
55
+ );
56
+ if (stopped.error || stopped.status !== 0) {
57
+ process.stderr.write(
58
+ `@yoooclaw/cli: failed to stop old daemon for profile ${profile}\n`,
59
+ );
60
+ process.exit(1);
61
+ }
62
+ runningProfiles.push(profile);
63
+ }
64
+
65
+ fs.mkdirSync(root, { recursive: true, mode: 0o700 });
66
+ fs.writeFileSync(
67
+ statePath,
68
+ JSON.stringify({ activationRequested, runningProfiles, preparedAt: new Date().toISOString() }),
69
+ { mode: 0o600 },
70
+ );
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@yoooclaw/cli",
3
3
  "description": "yoooclaw 独立 CLI(Go 实现,按平台分发原生二进制)",
4
- "version": "0.8.0-beta.1",
4
+ "version": "0.8.1",
5
5
  "license": "MIT",
6
6
  "author": "developer@yoooclaw.com",
7
7
  "repository": {
@@ -17,14 +17,20 @@
17
17
  },
18
18
  "files": [
19
19
  "bin/yc.js",
20
+ "bin/prepare-owner.js",
21
+ "bin/activate-owner.js",
20
22
  "README.md"
21
23
  ],
24
+ "scripts": {
25
+ "preinstall": "node bin/prepare-owner.js",
26
+ "postinstall": "node bin/activate-owner.js"
27
+ },
22
28
  "optionalDependencies": {
23
- "@yoooclaw/cli-darwin-arm64": "0.8.0-beta.1",
24
- "@yoooclaw/cli-darwin-x64": "0.8.0-beta.1",
25
- "@yoooclaw/cli-linux-arm64": "0.8.0-beta.1",
26
- "@yoooclaw/cli-linux-x64": "0.8.0-beta.1",
27
- "@yoooclaw/cli-win32-x64": "0.8.0-beta.1"
29
+ "@yoooclaw/cli-darwin-arm64": "0.8.1",
30
+ "@yoooclaw/cli-darwin-x64": "0.8.1",
31
+ "@yoooclaw/cli-linux-arm64": "0.8.1",
32
+ "@yoooclaw/cli-linux-x64": "0.8.1",
33
+ "@yoooclaw/cli-win32-x64": "0.8.1"
28
34
  },
29
35
  "engines": {
30
36
  "node": ">=18"