@ricsam/r5d-worker 0.0.151 → 0.0.153

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/dist/mjs/main.mjs CHANGED
@@ -7,7 +7,7 @@ import { startManagerRpc } from "./runtime/releases/rpc-main.mjs";
7
7
  import { ManagerRpcConfig } from "./runtime/releases/rpc-protocol.mjs";
8
8
  const args = process.argv.slice(2);
9
9
  if (args.includes("--version")) {
10
- console.log(`r5d-worker ${true ? "0.0.151" : "development"}`);
10
+ console.log(`r5d-worker ${true ? "0.0.153" : "development"}`);
11
11
  } else if (!args.length || args.includes("--help")) {
12
12
  console.log(
13
13
  "Usage: r5d-worker start --label <label> [--root <dir>] [--base-url <url>] [--token <worker-token>]\n r5d-worker executor /absolute/private/config.json\n r5d-worker manager /absolute/private/config.json\n\nRun independently supervised durable runtime services. Provision configuration with r5dinfra."
@@ -15,7 +15,7 @@ if (args.includes("--version")) {
15
15
  } else if (args[0] === "start") {
16
16
  const runtime = await startPersonalWorker(
17
17
  parsePersonalWorkerOptions(args.slice(1)),
18
- true ? "0.0.151" : "development"
18
+ true ? "0.0.153" : "development"
19
19
  );
20
20
  console.log(`Worker connected: ${runtime.resourceId}`);
21
21
  let closing = false;
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@ricsam/r5d-worker",
3
- "version": "0.0.151",
3
+ "version": "0.0.153",
4
4
  "type": "module"
5
5
  }
@@ -6,6 +6,16 @@ function packageMain(moduleUrl) {
6
6
  const module = fileURLToPath(moduleUrl);
7
7
  return path.join(path.dirname(module), path.extname(module) === ".cjs" ? "main.cjs" : "main.mjs");
8
8
  }
9
+ function internalMain(moduleUrl) {
10
+ return path.join(path.dirname(fileURLToPath(moduleUrl)), "..", "internal-r5dctl.cjs");
11
+ }
12
+ async function inspectInternal(candidate) {
13
+ const entrypoint = await fs.realpath(candidate);
14
+ const stat = await fs.lstat(entrypoint);
15
+ if (!stat.isFile() || stat.nlink !== 1 || stat.mode & 2 || ![0, process.getuid?.()].includes(stat.uid))
16
+ throw new Error("Untrusted internal r5dctl entrypoint");
17
+ return entrypoint;
18
+ }
9
19
  async function inspectPackage(candidate) {
10
20
  const entrypoint = await fs.realpath(candidate);
11
21
  const entrypointStat = await fs.lstat(entrypoint);
@@ -39,13 +49,19 @@ async function resolvePersonalCliEntrypoint(explicit, workerVersion, dependencie
39
49
  source = "explicit";
40
50
  candidate = explicit;
41
51
  } else {
52
+ const bundled = dependencies.bundled ?? internalMain(import.meta.url);
42
53
  try {
43
- const resolvePackage = dependencies.resolvePackage ?? ((specifier) => import.meta.resolve(specifier));
44
- candidate = packageMain(resolvePackage(`${PACKAGE_NAME}/cli`));
45
- source = "bundled";
46
- } catch {
47
- source = "path";
48
- candidate = (dependencies.which ?? Bun.which)("r5dctl");
54
+ return { entrypoint: await inspectInternal(bundled), version: workerVersion, source: "bundled" };
55
+ } catch (error) {
56
+ if (error.code !== "ENOENT" || workerVersion !== "development") throw error;
57
+ try {
58
+ const resolvePackage = dependencies.resolvePackage ?? ((specifier) => import.meta.resolve(specifier));
59
+ candidate = packageMain(resolvePackage(`${PACKAGE_NAME}/cli`));
60
+ source = "bundled";
61
+ } catch {
62
+ source = "path";
63
+ candidate = (dependencies.which ?? Bun.which)("r5dctl");
64
+ }
49
65
  }
50
66
  }
51
67
  if (!candidate) throw new Error("Install @ricsam/r5dctl before starting this worker");
@@ -105,7 +105,7 @@ async function openPersonalWorkerRuntime(options) {
105
105
  let cliDirectory;
106
106
  if (options.cliEntrypoint) {
107
107
  const cli = await fs.realpath(options.cliEntrypoint), executable = await fs.realpath(process.execPath), stat = await fs.lstat(cli);
108
- if (!stat.isFile() || stat.mode & 18 || ![0, process.getuid?.()].includes(stat.uid))
108
+ if (!stat.isFile() || stat.nlink !== 1 || stat.mode & 2 || ![0, process.getuid?.()].includes(stat.uid))
109
109
  throw new Error("Untrusted installed r5dctl entrypoint");
110
110
  cliDirectory = path.join(root, "bin");
111
111
  privateDirectory(cliDirectory);
@@ -94,6 +94,11 @@ class WorkspaceAuthority {
94
94
  linkedWorkbench(b) {
95
95
  return Boolean(b.config.namespace && b.config.projectName);
96
96
  }
97
+ githubOrigin(b) {
98
+ if (!b.config.namespace || !b.config.projectName)
99
+ throw new WorkspaceError("invalid_config", "Project checkout is missing its GitHub repository identity");
100
+ return `https://github.com/${b.config.namespace}/${b.config.projectName}.git`;
101
+ }
97
102
  resolveHostPath(value) {
98
103
  const expanded = value === "~" ? os.homedir() : value.startsWith("~/") ? path.join(os.homedir(), value.slice(2)) : value;
99
104
  if (!path.isAbsolute(expanded) || expanded.includes("\0")) throw new WorkspaceError("unsafe_path", "Host path must be absolute or home-relative");
@@ -783,10 +788,19 @@ class WorkspaceAuthority {
783
788
  if ((await fs.readdir(b.config.cwd)).length) throw new WorkspaceError("nonempty_workbench", "Linked worktree destination must be empty");
784
789
  await git(b.repo, ["worktree", "add", "--force", b.config.cwd, b.config.branch]);
785
790
  }
786
- const remote2 = `r5d-canonical://${this.config.installationId}/${b.config.userId}/${b.config.repositoryId}`;
787
- await git(b.repo, ["config", "remote.canonical.url", remote2]);
788
- await git(b.repo, ["config", "remote.canonical.pushurl", remote2]);
791
+ const origin = this.githubOrigin(b);
792
+ await git(b.repo, ["config", "--local", "--replace-all", "remote.origin.url", origin]);
793
+ await git(b.repo, ["config", "--local", "--replace-all", "remote.origin.fetch", "+refs/heads/*:refs/remotes/origin/*"]);
794
+ const localConfig = (await readRegular(path.join(b.repo, "config"), 128 * 1024)).toString("utf8");
795
+ if (/^\[remote "canonical"\]\s*$/m.test(localConfig))
796
+ await git(b.repo, ["config", "--local", "--remove-section", "remote.canonical"]);
797
+ await git(b.repo, ["config", "--local", "--replace-all", `branch.${b.config.branch}.remote`, "origin"]);
798
+ await git(b.repo, ["config", "--local", "--replace-all", `branch.${b.config.branch}.merge`, `refs/heads/${b.config.branch}`]);
799
+ await git(b.repo, ["config", "--local", "--replace-all", "push.default", "upstream"]);
800
+ await git(b.repo, ["config", "--local", "--replace-all", "credential.helper", ""]);
801
+ await git(b.repo, ["config", "--local", "--replace-all", "credential.useHttpPath", "false"]);
789
802
  await git(b.repo, ["config", "protocol.allow", "never"]);
803
+ await git(b.repo, ["config", "protocol.https.allow", "always"]);
790
804
  return;
791
805
  }
792
806
  const destination = path.join(b.config.cwd, ".git");
@@ -1,4 +1,5 @@
1
1
  type ResolutionDependencies = {
2
+ bundled?: string;
2
3
  resolvePackage?: (specifier: string) => string;
3
4
  which?: (command: string) => string | null;
4
5
  };
@@ -33,6 +33,7 @@ export declare class WorkspaceAuthority {
33
33
  private ensureRepository;
34
34
  private assertNonOverlappingCheckout;
35
35
  private linkedWorkbench;
36
+ private githubOrigin;
36
37
  private resolveHostPath;
37
38
  static open(options: WorkspaceAuthorityOptions): Promise<WorkspaceAuthority>;
38
39
  private readonly registrations;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ricsam/r5d-worker",
3
- "version": "0.0.151",
3
+ "version": "0.0.153",
4
4
  "type": "module",
5
5
  "main": "./dist/mjs/main.mjs",
6
6
  "module": "./dist/mjs/main.mjs",
@@ -21,8 +21,7 @@
21
21
  "r5d-worker": "dist/mjs/main.mjs"
22
22
  },
23
23
  "dependencies": {
24
- "@ricsam/r5d-api": "^0.0.151",
25
- "@ricsam/r5dctl": "0.0.151",
24
+ "@ricsam/r5d-api": "^0.0.153",
26
25
  "node-pty": "1.1.0",
27
26
  "zod": "^4.1.13",
28
27
  "picomatch": "^4.0.3"