@ricsam/r5d-worker 0.0.8 → 0.0.10
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 +1 -1
- package/dist/cjs/main.cjs +51 -13
- package/dist/cjs/package.json +1 -1
- package/dist/mjs/main.mjs +40 -14
- package/dist/mjs/package.json +1 -1
- package/dist/types/main.d.ts +12 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@ The worker uses the existing `r5dctl` config file and accepts `R5D_WORKER_TOKEN`
|
|
|
13
13
|
~/.r5d/projects/<namespace-repo>/<branch-name>
|
|
14
14
|
```
|
|
15
15
|
|
|
16
|
-
Visible branch checkouts
|
|
16
|
+
Visible branch checkouts are the user/agent workbench. The worker may clone the connected GitHub `origin` during first setup, but ongoing pull/push/fetch/reset behavior is manual Git work. r5d internal sync git metadata lives separately under `~/.r5d/sync`.
|
|
17
17
|
|
|
18
18
|
Worker labels are mandatory and unique per user. Choose labels that describe host capabilities, such as `macos`, `linux`, `ios`, or `ec2-build`.
|
|
19
19
|
|
package/dist/cjs/main.cjs
CHANGED
|
@@ -6,6 +6,10 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
6
6
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
7
|
var __getProtoOf = Object.getPrototypeOf;
|
|
8
8
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
9
13
|
var __copyProps = (to, from, except, desc) => {
|
|
10
14
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
15
|
for (let key of __getOwnPropNames(from))
|
|
@@ -22,6 +26,12 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
22
26
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
23
27
|
mod
|
|
24
28
|
));
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
+
var main_exports = {};
|
|
31
|
+
__export(main_exports, {
|
|
32
|
+
ensureVisibleGitCheckout: () => ensureVisibleGitCheckout
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(main_exports);
|
|
25
35
|
var import_node_fs = __toESM(require("node:fs"), 1);
|
|
26
36
|
var import_node_os = __toESM(require("node:os"), 1);
|
|
27
37
|
var import_node_path = __toESM(require("node:path"), 1);
|
|
@@ -29,6 +39,7 @@ var import_node_crypto = require("node:crypto");
|
|
|
29
39
|
var import_node_os2 = require("node:os");
|
|
30
40
|
var import_node_child_process = require("node:child_process");
|
|
31
41
|
var import_git_identity = require("./git-identity.cjs");
|
|
42
|
+
const import_meta = {};
|
|
32
43
|
const DEFAULT_BASE_URL = "https://r5d.dev";
|
|
33
44
|
const WORKER_PACKAGE_NAME = "@ricsam/r5d-worker";
|
|
34
45
|
const LABEL_RE = /^[A-Za-z0-9][A-Za-z0-9_.-]{0,62}$/;
|
|
@@ -596,19 +607,23 @@ function ensureVisibleGitCheckout(input) {
|
|
|
596
607
|
validateBranchName(input.branchName);
|
|
597
608
|
import_node_fs.default.mkdirSync(input.projectRoot, { recursive: true });
|
|
598
609
|
const branchPath = import_node_path.default.join(input.projectRoot, input.branchName);
|
|
599
|
-
|
|
610
|
+
const createdCheckout = !hasNormalVisibleGitDir(branchPath);
|
|
611
|
+
if (createdCheckout) {
|
|
600
612
|
import_node_fs.default.rmSync(branchPath, { recursive: true, force: true });
|
|
601
613
|
import_node_fs.default.mkdirSync(import_node_path.default.dirname(branchPath), { recursive: true });
|
|
602
614
|
if (!tryGit(["clone", "--origin", "origin", input.githubRemoteUrl, branchPath], { auth: input.githubAuth })) {
|
|
603
615
|
import_node_fs.default.mkdirSync(branchPath, { recursive: true });
|
|
604
616
|
runGit(["init"], { cwd: branchPath });
|
|
605
617
|
}
|
|
618
|
+
ensureOriginRemote(branchPath, input.githubRemoteUrl);
|
|
619
|
+
configureVisibleGitHubAuth(branchPath, input.githubRemoteUrl, input.githubAuthHeader);
|
|
620
|
+
(0, import_git_identity.configureVisibleGitIdentity)(branchPath, visibleGitIdentity, runGit);
|
|
621
|
+
tryGit(["fetch", "origin", "--prune"], { cwd: branchPath, auth: input.githubAuth });
|
|
622
|
+
checkoutVisibleBranch({ branchPath, branchName: input.branchName, defaultBranch: input.defaultBranch });
|
|
623
|
+
return branchPath;
|
|
606
624
|
}
|
|
607
|
-
ensureOriginRemote(branchPath, input.githubRemoteUrl);
|
|
608
625
|
configureVisibleGitHubAuth(branchPath, input.githubRemoteUrl, input.githubAuthHeader);
|
|
609
626
|
(0, import_git_identity.configureVisibleGitIdentity)(branchPath, visibleGitIdentity, runGit);
|
|
610
|
-
tryGit(["fetch", "origin", "--prune"], { cwd: branchPath, auth: input.githubAuth });
|
|
611
|
-
checkoutVisibleBranch({ branchPath, branchName: input.branchName, defaultBranch: input.defaultBranch });
|
|
612
627
|
return branchPath;
|
|
613
628
|
}
|
|
614
629
|
function configureInternalRepo(context, remoteUrl) {
|
|
@@ -714,6 +729,15 @@ async function streamCommandOutput(stream, onData) {
|
|
|
714
729
|
function ensureOperationBranch(input) {
|
|
715
730
|
return ensureBranchWorkspace(input);
|
|
716
731
|
}
|
|
732
|
+
function internalGitProcessEnv(workspace, env) {
|
|
733
|
+
if (env?.R5D_USE_INTERNAL_GIT !== "1") {
|
|
734
|
+
return {};
|
|
735
|
+
}
|
|
736
|
+
return {
|
|
737
|
+
GIT_DIR: workspace.internalGit.gitDir,
|
|
738
|
+
GIT_WORK_TREE: workspace.branchPath
|
|
739
|
+
};
|
|
740
|
+
}
|
|
717
741
|
function formatLineNumberedContent(content, offset, limit) {
|
|
718
742
|
const allLines = content.split("\n");
|
|
719
743
|
const totalLines = allLines.length;
|
|
@@ -1190,7 +1214,7 @@ async function executeCommand(input) {
|
|
|
1190
1214
|
const startedAt = Date.now();
|
|
1191
1215
|
let timeout;
|
|
1192
1216
|
try {
|
|
1193
|
-
const
|
|
1217
|
+
const workspace = ensureBranchWorkspace({
|
|
1194
1218
|
projectId: input.projectId,
|
|
1195
1219
|
baseUrl: input.baseUrl,
|
|
1196
1220
|
token: input.token,
|
|
@@ -1199,7 +1223,7 @@ async function executeCommand(input) {
|
|
|
1199
1223
|
branchName: input.message.branchName,
|
|
1200
1224
|
manifest: input.manifest
|
|
1201
1225
|
});
|
|
1202
|
-
const cwd = resolveCommandCwd(
|
|
1226
|
+
const cwd = resolveCommandCwd(workspace.branchPath, input.message.cwd);
|
|
1203
1227
|
const subprocess = Bun.spawn(input.message.argv, {
|
|
1204
1228
|
cwd,
|
|
1205
1229
|
stdout: "pipe",
|
|
@@ -1207,7 +1231,8 @@ async function executeCommand(input) {
|
|
|
1207
1231
|
env: {
|
|
1208
1232
|
...process.env,
|
|
1209
1233
|
...containerRegistryEnv(),
|
|
1210
|
-
...input.message.env ?? {}
|
|
1234
|
+
...input.message.env ?? {},
|
|
1235
|
+
...internalGitProcessEnv(workspace, input.message.env)
|
|
1211
1236
|
}
|
|
1212
1237
|
});
|
|
1213
1238
|
activeProcesses.set(input.message.runId, { process: subprocess, command: input.message.argv });
|
|
@@ -1261,7 +1286,7 @@ async function executeStreamingCommand(input) {
|
|
|
1261
1286
|
});
|
|
1262
1287
|
return;
|
|
1263
1288
|
}
|
|
1264
|
-
const
|
|
1289
|
+
const workspace = ensureBranchWorkspace({
|
|
1265
1290
|
projectId: input.projectId,
|
|
1266
1291
|
baseUrl: input.baseUrl,
|
|
1267
1292
|
token: input.token,
|
|
@@ -1270,7 +1295,7 @@ async function executeStreamingCommand(input) {
|
|
|
1270
1295
|
branchName: input.message.branchName,
|
|
1271
1296
|
manifest: input.manifest
|
|
1272
1297
|
});
|
|
1273
|
-
const cwd = resolveCommandCwd(
|
|
1298
|
+
const cwd = resolveCommandCwd(workspace.branchPath, input.message.cwd);
|
|
1274
1299
|
const subprocess = Bun.spawn(input.message.argv, {
|
|
1275
1300
|
cwd,
|
|
1276
1301
|
stdout: "pipe",
|
|
@@ -1278,7 +1303,8 @@ async function executeStreamingCommand(input) {
|
|
|
1278
1303
|
env: {
|
|
1279
1304
|
...process.env,
|
|
1280
1305
|
...containerRegistryEnv(),
|
|
1281
|
-
...input.message.env ?? {}
|
|
1306
|
+
...input.message.env ?? {},
|
|
1307
|
+
...internalGitProcessEnv(workspace, input.message.env)
|
|
1282
1308
|
}
|
|
1283
1309
|
});
|
|
1284
1310
|
activeProcesses.set(input.message.runId, { process: subprocess, command: input.message.argv });
|
|
@@ -1884,8 +1910,20 @@ async function main() {
|
|
|
1884
1910
|
}
|
|
1885
1911
|
await startWorker(parsed.options);
|
|
1886
1912
|
}
|
|
1887
|
-
|
|
1888
|
-
|
|
1913
|
+
function isCliEntrypoint() {
|
|
1914
|
+
if (import_meta.main) {
|
|
1915
|
+
return true;
|
|
1916
|
+
}
|
|
1917
|
+
return typeof require === "function" && typeof module !== "undefined" && require.main === module;
|
|
1918
|
+
}
|
|
1919
|
+
if (isCliEntrypoint()) {
|
|
1920
|
+
main().catch((error) => {
|
|
1921
|
+
process.stderr.write(`[r5d-worker] ${error instanceof Error ? error.message : String(error)}
|
|
1889
1922
|
`);
|
|
1890
|
-
|
|
1923
|
+
process.exit(1);
|
|
1924
|
+
});
|
|
1925
|
+
}
|
|
1926
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1927
|
+
0 && (module.exports = {
|
|
1928
|
+
ensureVisibleGitCheckout
|
|
1891
1929
|
});
|
package/dist/cjs/package.json
CHANGED
package/dist/mjs/main.mjs
CHANGED
|
@@ -573,19 +573,23 @@ function ensureVisibleGitCheckout(input) {
|
|
|
573
573
|
validateBranchName(input.branchName);
|
|
574
574
|
fs.mkdirSync(input.projectRoot, { recursive: true });
|
|
575
575
|
const branchPath = path.join(input.projectRoot, input.branchName);
|
|
576
|
-
|
|
576
|
+
const createdCheckout = !hasNormalVisibleGitDir(branchPath);
|
|
577
|
+
if (createdCheckout) {
|
|
577
578
|
fs.rmSync(branchPath, { recursive: true, force: true });
|
|
578
579
|
fs.mkdirSync(path.dirname(branchPath), { recursive: true });
|
|
579
580
|
if (!tryGit(["clone", "--origin", "origin", input.githubRemoteUrl, branchPath], { auth: input.githubAuth })) {
|
|
580
581
|
fs.mkdirSync(branchPath, { recursive: true });
|
|
581
582
|
runGit(["init"], { cwd: branchPath });
|
|
582
583
|
}
|
|
584
|
+
ensureOriginRemote(branchPath, input.githubRemoteUrl);
|
|
585
|
+
configureVisibleGitHubAuth(branchPath, input.githubRemoteUrl, input.githubAuthHeader);
|
|
586
|
+
configureVisibleGitIdentity(branchPath, visibleGitIdentity, runGit);
|
|
587
|
+
tryGit(["fetch", "origin", "--prune"], { cwd: branchPath, auth: input.githubAuth });
|
|
588
|
+
checkoutVisibleBranch({ branchPath, branchName: input.branchName, defaultBranch: input.defaultBranch });
|
|
589
|
+
return branchPath;
|
|
583
590
|
}
|
|
584
|
-
ensureOriginRemote(branchPath, input.githubRemoteUrl);
|
|
585
591
|
configureVisibleGitHubAuth(branchPath, input.githubRemoteUrl, input.githubAuthHeader);
|
|
586
592
|
configureVisibleGitIdentity(branchPath, visibleGitIdentity, runGit);
|
|
587
|
-
tryGit(["fetch", "origin", "--prune"], { cwd: branchPath, auth: input.githubAuth });
|
|
588
|
-
checkoutVisibleBranch({ branchPath, branchName: input.branchName, defaultBranch: input.defaultBranch });
|
|
589
593
|
return branchPath;
|
|
590
594
|
}
|
|
591
595
|
function configureInternalRepo(context, remoteUrl) {
|
|
@@ -691,6 +695,15 @@ async function streamCommandOutput(stream, onData) {
|
|
|
691
695
|
function ensureOperationBranch(input) {
|
|
692
696
|
return ensureBranchWorkspace(input);
|
|
693
697
|
}
|
|
698
|
+
function internalGitProcessEnv(workspace, env) {
|
|
699
|
+
if (env?.R5D_USE_INTERNAL_GIT !== "1") {
|
|
700
|
+
return {};
|
|
701
|
+
}
|
|
702
|
+
return {
|
|
703
|
+
GIT_DIR: workspace.internalGit.gitDir,
|
|
704
|
+
GIT_WORK_TREE: workspace.branchPath
|
|
705
|
+
};
|
|
706
|
+
}
|
|
694
707
|
function formatLineNumberedContent(content, offset, limit) {
|
|
695
708
|
const allLines = content.split("\n");
|
|
696
709
|
const totalLines = allLines.length;
|
|
@@ -1167,7 +1180,7 @@ async function executeCommand(input) {
|
|
|
1167
1180
|
const startedAt = Date.now();
|
|
1168
1181
|
let timeout;
|
|
1169
1182
|
try {
|
|
1170
|
-
const
|
|
1183
|
+
const workspace = ensureBranchWorkspace({
|
|
1171
1184
|
projectId: input.projectId,
|
|
1172
1185
|
baseUrl: input.baseUrl,
|
|
1173
1186
|
token: input.token,
|
|
@@ -1176,7 +1189,7 @@ async function executeCommand(input) {
|
|
|
1176
1189
|
branchName: input.message.branchName,
|
|
1177
1190
|
manifest: input.manifest
|
|
1178
1191
|
});
|
|
1179
|
-
const cwd = resolveCommandCwd(
|
|
1192
|
+
const cwd = resolveCommandCwd(workspace.branchPath, input.message.cwd);
|
|
1180
1193
|
const subprocess = Bun.spawn(input.message.argv, {
|
|
1181
1194
|
cwd,
|
|
1182
1195
|
stdout: "pipe",
|
|
@@ -1184,7 +1197,8 @@ async function executeCommand(input) {
|
|
|
1184
1197
|
env: {
|
|
1185
1198
|
...process.env,
|
|
1186
1199
|
...containerRegistryEnv(),
|
|
1187
|
-
...input.message.env ?? {}
|
|
1200
|
+
...input.message.env ?? {},
|
|
1201
|
+
...internalGitProcessEnv(workspace, input.message.env)
|
|
1188
1202
|
}
|
|
1189
1203
|
});
|
|
1190
1204
|
activeProcesses.set(input.message.runId, { process: subprocess, command: input.message.argv });
|
|
@@ -1238,7 +1252,7 @@ async function executeStreamingCommand(input) {
|
|
|
1238
1252
|
});
|
|
1239
1253
|
return;
|
|
1240
1254
|
}
|
|
1241
|
-
const
|
|
1255
|
+
const workspace = ensureBranchWorkspace({
|
|
1242
1256
|
projectId: input.projectId,
|
|
1243
1257
|
baseUrl: input.baseUrl,
|
|
1244
1258
|
token: input.token,
|
|
@@ -1247,7 +1261,7 @@ async function executeStreamingCommand(input) {
|
|
|
1247
1261
|
branchName: input.message.branchName,
|
|
1248
1262
|
manifest: input.manifest
|
|
1249
1263
|
});
|
|
1250
|
-
const cwd = resolveCommandCwd(
|
|
1264
|
+
const cwd = resolveCommandCwd(workspace.branchPath, input.message.cwd);
|
|
1251
1265
|
const subprocess = Bun.spawn(input.message.argv, {
|
|
1252
1266
|
cwd,
|
|
1253
1267
|
stdout: "pipe",
|
|
@@ -1255,7 +1269,8 @@ async function executeStreamingCommand(input) {
|
|
|
1255
1269
|
env: {
|
|
1256
1270
|
...process.env,
|
|
1257
1271
|
...containerRegistryEnv(),
|
|
1258
|
-
...input.message.env ?? {}
|
|
1272
|
+
...input.message.env ?? {},
|
|
1273
|
+
...internalGitProcessEnv(workspace, input.message.env)
|
|
1259
1274
|
}
|
|
1260
1275
|
});
|
|
1261
1276
|
activeProcesses.set(input.message.runId, { process: subprocess, command: input.message.argv });
|
|
@@ -1861,8 +1876,19 @@ async function main() {
|
|
|
1861
1876
|
}
|
|
1862
1877
|
await startWorker(parsed.options);
|
|
1863
1878
|
}
|
|
1864
|
-
|
|
1865
|
-
|
|
1879
|
+
function isCliEntrypoint() {
|
|
1880
|
+
if (import.meta.main) {
|
|
1881
|
+
return true;
|
|
1882
|
+
}
|
|
1883
|
+
return typeof require === "function" && typeof module !== "undefined" && require.main === module;
|
|
1884
|
+
}
|
|
1885
|
+
if (isCliEntrypoint()) {
|
|
1886
|
+
main().catch((error) => {
|
|
1887
|
+
process.stderr.write(`[r5d-worker] ${error instanceof Error ? error.message : String(error)}
|
|
1866
1888
|
`);
|
|
1867
|
-
|
|
1868
|
-
});
|
|
1889
|
+
process.exit(1);
|
|
1890
|
+
});
|
|
1891
|
+
}
|
|
1892
|
+
export {
|
|
1893
|
+
ensureVisibleGitCheckout
|
|
1894
|
+
};
|
package/dist/mjs/package.json
CHANGED
package/dist/types/main.d.ts
CHANGED
|
@@ -1,2 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
|
+
type GitAuth = {
|
|
3
|
+
extraHeaderUrl: string;
|
|
4
|
+
header: string;
|
|
5
|
+
};
|
|
6
|
+
export declare function ensureVisibleGitCheckout(input: {
|
|
7
|
+
projectRoot: string;
|
|
8
|
+
branchName: string;
|
|
9
|
+
githubRemoteUrl: string;
|
|
10
|
+
githubAuth?: GitAuth;
|
|
11
|
+
githubAuthHeader?: string | null;
|
|
12
|
+
defaultBranch: string;
|
|
13
|
+
}): string;
|
|
2
14
|
export {};
|