@ricsam/r5d-worker 0.0.4 → 0.0.5

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/README.md CHANGED
@@ -1,25 +1,25 @@
1
1
  # r5d-worker
2
2
 
3
- `r5d-worker` connects a local or remote machine to a r5d.dev project so the agent can run host commands through the virtual `worker` shell command.
3
+ `r5d-worker` connects a local or remote machine to r5d.dev so the agent can run host commands through the live worker.
4
4
 
5
5
  ```sh
6
- r5d-worker start <project-id> --label macos
6
+ r5d-worker start --label macos
7
+ r5d-worker --version
7
8
  ```
8
9
 
9
10
  The worker uses the existing `r5dctl` config file and accepts `R5D_WORKER_TOKEN` or `R5D_API_KEY`. Project checkouts are managed under:
10
11
 
11
12
  ```text
12
- ~/.r5d/projects/<project-id>/<branch-name>
13
+ ~/.r5d/projects/<repo-slug>/<branch-name>
13
14
  ```
14
15
 
15
- `main` is cloned from the platform's HTTPS git remote. Other branches are created as git worktrees from the main clone.
16
+ Visible branch checkouts use GitHub `origin` remotes. r5d internal sync git metadata lives separately under `~/.r5d/sync`.
16
17
 
17
- Worker labels are mandatory and unique per project. Choose labels that describe host capabilities, such as `macos`, `linux`, `ios`, or `ec2-build`.
18
+ Worker labels are mandatory and unique per user. Choose labels that describe host capabilities, such as `macos`, `linux`, `ios`, or `ec2-build`.
18
19
 
19
20
  The agent runs commands through the virtual shell command:
20
21
 
21
22
  ```sh
22
- worker exec macos git pull --ff-only build-it-now main
23
23
  worker exec macos docker compose up -d
24
24
  worker exec macos bun test
25
25
  ```
package/dist/cjs/main.cjs CHANGED
@@ -29,6 +29,7 @@ var import_node_crypto = require("node:crypto");
29
29
  var import_node_os2 = require("node:os");
30
30
  var import_node_child_process = require("node:child_process");
31
31
  const DEFAULT_BASE_URL = "https://r5d.dev";
32
+ const WORKER_PACKAGE_NAME = "@ricsam/r5d-worker";
32
33
  const LABEL_RE = /^[A-Za-z0-9][A-Za-z0-9_.-]{0,62}$/;
33
34
  const BRANCH_RE = /^[A-Za-z0-9][A-Za-z0-9-]*[A-Za-z0-9]$|^[A-Za-z0-9]$/;
34
35
  const DEFAULT_READ_LIMIT = 2e3;
@@ -50,6 +51,7 @@ function defaultSyncRoot() {
50
51
  function printHelp() {
51
52
  process.stdout.write(`Usage:
52
53
  r5d-worker start --label <label> [--base-url <url>] [--token <token>] [--api-key <key>]
54
+ r5d-worker --version
53
55
 
54
56
  Options:
55
57
  --label <label> Required unique worker label for this user, e.g. macos or ec2-build
@@ -59,9 +61,53 @@ Options:
59
61
  --config <path> Config path (default ~/.config/r5d/r5dctl/config.json)
60
62
  --project-root <dir> Override projects checkout root (default ~/.r5d/projects)
61
63
  --sync-root <dir> Override r5d internal sync git root (default ~/.r5d/sync)
64
+ -v, --version Show r5d-worker version
62
65
  -h, --help Show this help
63
66
  `);
64
67
  }
68
+ function readVersionFile(filePath) {
69
+ try {
70
+ const version = import_node_fs.default.readFileSync(filePath, "utf8").trim();
71
+ return version || null;
72
+ } catch {
73
+ return null;
74
+ }
75
+ }
76
+ function readInstalledPackageVersion(packageJsonPath) {
77
+ try {
78
+ const parsed = JSON.parse(import_node_fs.default.readFileSync(packageJsonPath, "utf8"));
79
+ if (parsed.name === WORKER_PACKAGE_NAME && typeof parsed.version === "string" && parsed.version.trim()) {
80
+ return parsed.version.trim();
81
+ }
82
+ } catch {
83
+ return null;
84
+ }
85
+ return null;
86
+ }
87
+ function getWorkerVersion() {
88
+ const entrypoint = process.argv[1] ? import_node_path.default.resolve(process.argv[1]) : null;
89
+ let current = entrypoint ? import_node_path.default.dirname(entrypoint) : process.cwd();
90
+ for (let index = 0; index < 12; index += 1) {
91
+ const packageVersion = readInstalledPackageVersion(import_node_path.default.join(current, "package.json"));
92
+ if (packageVersion) {
93
+ return packageVersion;
94
+ }
95
+ const sourceVersion = readVersionFile(import_node_path.default.join(current, "VERSION.txt"));
96
+ if (sourceVersion && import_node_path.default.basename(current) === "binctl-packages") {
97
+ return sourceVersion;
98
+ }
99
+ const parent = import_node_path.default.dirname(current);
100
+ if (parent === current) {
101
+ break;
102
+ }
103
+ current = parent;
104
+ }
105
+ return "unknown";
106
+ }
107
+ function printVersion() {
108
+ process.stdout.write(`r5d-worker ${getWorkerVersion()}
109
+ `);
110
+ }
65
111
  function requireValue(value, message) {
66
112
  if (!value) {
67
113
  throw new Error(message);
@@ -71,7 +117,8 @@ function requireValue(value, message) {
71
117
  function parseArgs(argv) {
72
118
  const options = {
73
119
  configPath: defaultConfigPath(),
74
- help: false
120
+ help: false,
121
+ version: false
75
122
  };
76
123
  const rest = [];
77
124
  for (let index = 0; index < argv.length; index += 1) {
@@ -83,6 +130,10 @@ function parseArgs(argv) {
83
130
  options.help = true;
84
131
  continue;
85
132
  }
133
+ if (arg === "-v" || arg === "--version") {
134
+ options.version = true;
135
+ continue;
136
+ }
86
137
  const readOption = (name) => {
87
138
  if (arg === name) {
88
139
  index += 1;
@@ -128,6 +179,9 @@ function parseArgs(argv) {
128
179
  }
129
180
  rest.push(arg);
130
181
  }
182
+ if (options.version) {
183
+ return { command: "version", options };
184
+ }
131
185
  if (options.help || rest.length === 0) {
132
186
  return { command: "help", options };
133
187
  }
@@ -1325,7 +1379,7 @@ async function startWorker(options) {
1325
1379
  platform: process.platform,
1326
1380
  arch: process.arch,
1327
1381
  pid: process.pid,
1328
- version: "0.1.0",
1382
+ version: getWorkerVersion(),
1329
1383
  projectRoot: projectsRoot
1330
1384
  }
1331
1385
  };
@@ -1477,6 +1531,10 @@ async function main() {
1477
1531
  printHelp();
1478
1532
  return;
1479
1533
  }
1534
+ if (parsed.command === "version") {
1535
+ printVersion();
1536
+ return;
1537
+ }
1480
1538
  await startWorker(parsed.options);
1481
1539
  }
1482
1540
  main().catch((error) => {
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@ricsam/r5d-worker",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "type": "commonjs"
5
5
  }
package/dist/mjs/main.mjs CHANGED
@@ -6,6 +6,7 @@ import { createHash } from "node:crypto";
6
6
  import { hostname } from "node:os";
7
7
  import { spawn as spawnChildProcess } from "node:child_process";
8
8
  const DEFAULT_BASE_URL = "https://r5d.dev";
9
+ const WORKER_PACKAGE_NAME = "@ricsam/r5d-worker";
9
10
  const LABEL_RE = /^[A-Za-z0-9][A-Za-z0-9_.-]{0,62}$/;
10
11
  const BRANCH_RE = /^[A-Za-z0-9][A-Za-z0-9-]*[A-Za-z0-9]$|^[A-Za-z0-9]$/;
11
12
  const DEFAULT_READ_LIMIT = 2e3;
@@ -27,6 +28,7 @@ function defaultSyncRoot() {
27
28
  function printHelp() {
28
29
  process.stdout.write(`Usage:
29
30
  r5d-worker start --label <label> [--base-url <url>] [--token <token>] [--api-key <key>]
31
+ r5d-worker --version
30
32
 
31
33
  Options:
32
34
  --label <label> Required unique worker label for this user, e.g. macos or ec2-build
@@ -36,9 +38,53 @@ Options:
36
38
  --config <path> Config path (default ~/.config/r5d/r5dctl/config.json)
37
39
  --project-root <dir> Override projects checkout root (default ~/.r5d/projects)
38
40
  --sync-root <dir> Override r5d internal sync git root (default ~/.r5d/sync)
41
+ -v, --version Show r5d-worker version
39
42
  -h, --help Show this help
40
43
  `);
41
44
  }
45
+ function readVersionFile(filePath) {
46
+ try {
47
+ const version = fs.readFileSync(filePath, "utf8").trim();
48
+ return version || null;
49
+ } catch {
50
+ return null;
51
+ }
52
+ }
53
+ function readInstalledPackageVersion(packageJsonPath) {
54
+ try {
55
+ const parsed = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
56
+ if (parsed.name === WORKER_PACKAGE_NAME && typeof parsed.version === "string" && parsed.version.trim()) {
57
+ return parsed.version.trim();
58
+ }
59
+ } catch {
60
+ return null;
61
+ }
62
+ return null;
63
+ }
64
+ function getWorkerVersion() {
65
+ const entrypoint = process.argv[1] ? path.resolve(process.argv[1]) : null;
66
+ let current = entrypoint ? path.dirname(entrypoint) : process.cwd();
67
+ for (let index = 0; index < 12; index += 1) {
68
+ const packageVersion = readInstalledPackageVersion(path.join(current, "package.json"));
69
+ if (packageVersion) {
70
+ return packageVersion;
71
+ }
72
+ const sourceVersion = readVersionFile(path.join(current, "VERSION.txt"));
73
+ if (sourceVersion && path.basename(current) === "binctl-packages") {
74
+ return sourceVersion;
75
+ }
76
+ const parent = path.dirname(current);
77
+ if (parent === current) {
78
+ break;
79
+ }
80
+ current = parent;
81
+ }
82
+ return "unknown";
83
+ }
84
+ function printVersion() {
85
+ process.stdout.write(`r5d-worker ${getWorkerVersion()}
86
+ `);
87
+ }
42
88
  function requireValue(value, message) {
43
89
  if (!value) {
44
90
  throw new Error(message);
@@ -48,7 +94,8 @@ function requireValue(value, message) {
48
94
  function parseArgs(argv) {
49
95
  const options = {
50
96
  configPath: defaultConfigPath(),
51
- help: false
97
+ help: false,
98
+ version: false
52
99
  };
53
100
  const rest = [];
54
101
  for (let index = 0; index < argv.length; index += 1) {
@@ -60,6 +107,10 @@ function parseArgs(argv) {
60
107
  options.help = true;
61
108
  continue;
62
109
  }
110
+ if (arg === "-v" || arg === "--version") {
111
+ options.version = true;
112
+ continue;
113
+ }
63
114
  const readOption = (name) => {
64
115
  if (arg === name) {
65
116
  index += 1;
@@ -105,6 +156,9 @@ function parseArgs(argv) {
105
156
  }
106
157
  rest.push(arg);
107
158
  }
159
+ if (options.version) {
160
+ return { command: "version", options };
161
+ }
108
162
  if (options.help || rest.length === 0) {
109
163
  return { command: "help", options };
110
164
  }
@@ -1302,7 +1356,7 @@ async function startWorker(options) {
1302
1356
  platform: process.platform,
1303
1357
  arch: process.arch,
1304
1358
  pid: process.pid,
1305
- version: "0.1.0",
1359
+ version: getWorkerVersion(),
1306
1360
  projectRoot: projectsRoot
1307
1361
  }
1308
1362
  };
@@ -1454,6 +1508,10 @@ async function main() {
1454
1508
  printHelp();
1455
1509
  return;
1456
1510
  }
1511
+ if (parsed.command === "version") {
1512
+ printVersion();
1513
+ return;
1514
+ }
1457
1515
  await startWorker(parsed.options);
1458
1516
  }
1459
1517
  main().catch((error) => {
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@ricsam/r5d-worker",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "type": "module"
5
5
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ricsam/r5d-worker",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "type": "module",
5
5
  "main": "./dist/cjs/main.cjs",
6
6
  "module": "./dist/mjs/main.mjs",