@ricsam/r5d-worker 0.0.136 → 0.0.138
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 +4 -94
- package/dist/cjs/package.json +1 -1
- package/dist/mjs/main.mjs +46 -7537
- package/dist/mjs/package.json +1 -1
- package/dist/mjs/personal/action-scheduler.mjs +31 -0
- package/dist/mjs/personal/client.mjs +215 -0
- package/dist/mjs/personal/runtime.mjs +328 -0
- package/dist/mjs/personal/tcp.mjs +217 -0
- package/dist/mjs/runtime/adapter.mjs +42 -0
- package/dist/mjs/runtime/client.mjs +95 -0
- package/dist/mjs/runtime/daemon.mjs +131 -0
- package/dist/mjs/runtime/executor.mjs +436 -0
- package/dist/mjs/runtime/index.mjs +15 -0
- package/dist/mjs/runtime/protocol.mjs +139 -0
- package/dist/mjs/runtime/pty-host.mjs +156 -0
- package/dist/mjs/runtime/pty.mjs +127 -0
- package/dist/mjs/runtime/releases/artifacts.mjs +201 -0
- package/dist/mjs/runtime/releases/grants.mjs +93 -0
- package/dist/mjs/runtime/releases/main.mjs +101 -0
- package/dist/mjs/runtime/releases/manager.mjs +541 -0
- package/dist/mjs/runtime/releases/process.mjs +88 -0
- package/dist/mjs/runtime/releases/retirement.mjs +18 -0
- package/dist/mjs/runtime/releases/rpc-client.mjs +184 -0
- package/dist/mjs/runtime/releases/rpc-main.mjs +213 -0
- package/dist/mjs/runtime/releases/rpc-protocol.mjs +103 -0
- package/dist/mjs/runtime/storage.mjs +156 -0
- package/dist/mjs/runtime/workspace/artifacts.mjs +121 -0
- package/dist/mjs/runtime/workspace/authority.mjs +1355 -0
- package/dist/mjs/runtime/workspace/contracts.mjs +60 -0
- package/dist/mjs/runtime/workspace/file-write.mjs +23 -0
- package/dist/mjs/runtime/workspace/files.mjs +308 -0
- package/dist/mjs/runtime/workspace/http-body.mjs +45 -0
- package/dist/mjs/runtime/workspace/storage-client.mjs +59 -0
- package/dist/mjs/runtime/workspace/storage-wire.mjs +53 -0
- package/dist/types/main.d.ts +0 -1167
- package/dist/types/personal/action-scheduler.d.ts +23 -0
- package/dist/types/personal/client.d.ts +14 -0
- package/dist/types/personal/runtime.d.ts +121 -0
- package/dist/types/personal/tcp.d.ts +14 -0
- package/dist/types/runtime/client.d.ts +17 -0
- package/dist/types/runtime/daemon.d.ts +8 -0
- package/dist/types/runtime/executor.d.ts +35 -0
- package/dist/types/runtime/index.d.ts +5 -0
- package/dist/types/runtime/protocol.d.ts +544 -0
- package/dist/types/runtime/pty.d.ts +30 -0
- package/dist/types/runtime/releases/artifacts.d.ts +51 -0
- package/dist/types/runtime/releases/grants.d.ts +16 -0
- package/dist/types/runtime/releases/manager.d.ts +145 -0
- package/dist/types/runtime/releases/process.d.ts +14 -0
- package/dist/types/runtime/releases/retirement.d.ts +15 -0
- package/dist/types/runtime/releases/rpc-client.d.ts +52 -0
- package/dist/types/runtime/releases/rpc-main.d.ts +10 -0
- package/dist/types/runtime/releases/rpc-protocol.d.ts +1139 -0
- package/dist/types/runtime/storage.d.ts +21 -0
- package/dist/types/runtime/test-harness.d.ts +53 -0
- package/dist/types/runtime/workspace/artifacts.d.ts +30 -0
- package/dist/types/runtime/workspace/authority.d.ts +338 -0
- package/dist/types/runtime/workspace/contracts.d.ts +86 -0
- package/dist/types/runtime/workspace/file-write.d.ts +14 -0
- package/dist/types/runtime/workspace/files.d.ts +21 -0
- package/dist/types/runtime/workspace/http-body.d.ts +9 -0
- package/dist/types/runtime/workspace/storage-client.d.ts +23 -0
- package/dist/types/runtime/workspace/storage-wire.d.ts +138 -0
- package/package.json +8 -6
- package/dist/cjs/atomic-rename.cjs +0 -303
- package/dist/cjs/browser-upload.cjs +0 -73
- package/dist/cjs/cli-update.cjs +0 -108
- package/dist/cjs/command-launcher.cjs +0 -423
- package/dist/cjs/control-command-policy.cjs +0 -177
- package/dist/cjs/git-blob-hash.cjs +0 -41
- package/dist/cjs/git-identity.cjs +0 -39
- package/dist/cjs/git-process-environment.cjs +0 -133
- package/dist/cjs/inline-output.cjs +0 -62
- package/dist/cjs/main.cjs +0 -7511
- package/dist/cjs/managed-paths.cjs +0 -215
- package/dist/cjs/plan-lint.cjs +0 -165
- package/dist/cjs/plan-parser.cjs +0 -127
- package/dist/cjs/plan-paths.cjs +0 -53
- package/dist/cjs/port-forward-client.cjs +0 -206
- package/dist/cjs/process-tree.cjs +0 -117
- package/dist/cjs/project-checkout-garbage.cjs +0 -219
- package/dist/cjs/project-mirror-fetch-policy.cjs +0 -82
- package/dist/cjs/project-mirror-refs-token.cjs +0 -85
- package/dist/cjs/project-workspace-state.cjs +0 -972
- package/dist/cjs/project-worktrees.cjs +0 -1713
- package/dist/cjs/pty-output-coalescer.cjs +0 -87
- package/dist/cjs/recovery-journal-protocol.cjs +0 -56
- package/dist/cjs/recovery-journal-runtime.cjs +0 -133
- package/dist/cjs/recovery-journal-thread.cjs +0 -9
- package/dist/cjs/recovery-journal.cjs +0 -742
- package/dist/cjs/recovery-output-window.cjs +0 -77
- package/dist/cjs/recovery-protocol.cjs +0 -31
- package/dist/cjs/recovery-store.cjs +0 -252
- package/dist/cjs/registry-auth.cjs +0 -310
- package/dist/cjs/repository-transition-policy.cjs +0 -49
- package/dist/cjs/runtime-version.cjs +0 -88
- package/dist/cjs/session-file-mutations.cjs +0 -61
- package/dist/cjs/supervisor.cjs +0 -147
- package/dist/cjs/three-way-merge.cjs +0 -346
- package/dist/cjs/working-tree-mirror.cjs +0 -1872
- package/dist/cjs/workspace-automatic-sync-policy.cjs +0 -79
- package/dist/cjs/workspace-branch-incarnation-policy.cjs +0 -37
- package/dist/cjs/workspace-command-sync-policy.cjs +0 -112
- package/dist/cjs/workspace-command-targets.cjs +0 -63
- package/dist/cjs/workspace-filesystem-executor-thread.cjs +0 -36
- package/dist/cjs/workspace-filesystem-executor.cjs +0 -327
- package/dist/cjs/workspace-filesystem-job-types.cjs +0 -144
- package/dist/cjs/workspace-filesystem-jobs.cjs +0 -59
- package/dist/cjs/workspace-git-sync.cjs +0 -3450
- package/dist/cjs/workspace-hydration-ledger.cjs +0 -66
- package/dist/cjs/workspace-hydration-merge.cjs +0 -433
- package/dist/cjs/workspace-hydration-recovery-state.cjs +0 -53
- package/dist/cjs/workspace-incident-state.cjs +0 -37
- package/dist/cjs/workspace-merge-projection.cjs +0 -467
- package/dist/cjs/workspace-mount-boundary.cjs +0 -71
- package/dist/cjs/workspace-mount-hold-fence.cjs +0 -120
- package/dist/cjs/workspace-mutation-gate.cjs +0 -127
- package/dist/cjs/workspace-path-move.cjs +0 -195
- package/dist/cjs/workspace-preserve-only-policy.cjs +0 -36
- package/dist/cjs/workspace-project-config-policy.cjs +0 -53
- package/dist/cjs/workspace-projection-ledger.cjs +0 -81
- package/dist/cjs/workspace-publication-evidence.cjs +0 -46
- package/dist/cjs/workspace-sync-coalescer.cjs +0 -58
- package/dist/mjs/atomic-rename.mjs +0 -261
- package/dist/mjs/browser-upload.mjs +0 -42
- package/dist/mjs/command-launcher.mjs +0 -393
- package/dist/mjs/control-command-policy.mjs +0 -146
- package/dist/mjs/git-blob-hash.mjs +0 -16
- package/dist/mjs/git-identity.mjs +0 -15
- package/dist/mjs/git-process-environment.mjs +0 -105
- package/dist/mjs/inline-output.mjs +0 -37
- package/dist/mjs/managed-paths.mjs +0 -174
- package/dist/mjs/plan-lint.mjs +0 -129
- package/dist/mjs/plan-parser.mjs +0 -94
- package/dist/mjs/plan-paths.mjs +0 -25
- package/dist/mjs/port-forward-client.mjs +0 -172
- package/dist/mjs/project-checkout-garbage.mjs +0 -178
- package/dist/mjs/project-mirror-fetch-policy.mjs +0 -56
- package/dist/mjs/project-mirror-refs-token.mjs +0 -53
- package/dist/mjs/project-workspace-state.mjs +0 -937
- package/dist/mjs/project-worktrees.mjs +0 -1657
- package/dist/mjs/pty-output-coalescer.mjs +0 -61
- package/dist/mjs/recovery-journal-protocol.mjs +0 -30
- package/dist/mjs/recovery-journal-runtime.mjs +0 -112
- package/dist/mjs/recovery-journal-thread.mjs +0 -8
- package/dist/mjs/recovery-journal.mjs +0 -694
- package/dist/mjs/recovery-output-window.mjs +0 -53
- package/dist/mjs/recovery-protocol.mjs +0 -6
- package/dist/mjs/recovery-store.mjs +0 -217
- package/dist/mjs/registry-auth.mjs +0 -269
- package/dist/mjs/repository-transition-policy.mjs +0 -22
- package/dist/mjs/runtime-version.mjs +0 -54
- package/dist/mjs/session-file-mutations.mjs +0 -37
- package/dist/mjs/supervisor.mjs +0 -114
- package/dist/mjs/three-way-merge.mjs +0 -318
- package/dist/mjs/working-tree-mirror.mjs +0 -1817
- package/dist/mjs/workspace-automatic-sync-policy.mjs +0 -48
- package/dist/mjs/workspace-branch-incarnation-policy.mjs +0 -13
- package/dist/mjs/workspace-command-sync-policy.mjs +0 -84
- package/dist/mjs/workspace-command-targets.mjs +0 -37
- package/dist/mjs/workspace-filesystem-executor-thread.mjs +0 -38
- package/dist/mjs/workspace-filesystem-executor.mjs +0 -287
- package/dist/mjs/workspace-filesystem-job-types.mjs +0 -116
- package/dist/mjs/workspace-filesystem-jobs.mjs +0 -55
- package/dist/mjs/workspace-git-sync.mjs +0 -3407
- package/dist/mjs/workspace-hydration-ledger.mjs +0 -42
- package/dist/mjs/workspace-hydration-merge.mjs +0 -399
- package/dist/mjs/workspace-hydration-recovery-state.mjs +0 -29
- package/dist/mjs/workspace-incident-state.mjs +0 -12
- package/dist/mjs/workspace-merge-projection.mjs +0 -433
- package/dist/mjs/workspace-mount-boundary.mjs +0 -37
- package/dist/mjs/workspace-mount-hold-fence.mjs +0 -95
- package/dist/mjs/workspace-mutation-gate.mjs +0 -103
- package/dist/mjs/workspace-path-move.mjs +0 -160
- package/dist/mjs/workspace-preserve-only-policy.mjs +0 -11
- package/dist/mjs/workspace-project-config-policy.mjs +0 -27
- package/dist/mjs/workspace-projection-ledger.mjs +0 -57
- package/dist/mjs/workspace-publication-evidence.mjs +0 -21
- package/dist/mjs/workspace-sync-coalescer.mjs +0 -34
- package/dist/types/atomic-rename.d.ts +0 -78
- package/dist/types/browser-upload.d.ts +0 -7
- package/dist/types/command-launcher.d.ts +0 -104
- package/dist/types/control-command-policy.d.ts +0 -53
- package/dist/types/git-blob-hash.d.ts +0 -10
- package/dist/types/git-identity.d.ts +0 -9
- package/dist/types/git-process-environment.d.ts +0 -9
- package/dist/types/inline-output.d.ts +0 -3
- package/dist/types/managed-paths.d.ts +0 -19
- package/dist/types/plan-lint.d.ts +0 -16
- package/dist/types/plan-parser.d.ts +0 -38
- package/dist/types/plan-paths.d.ts +0 -36
- package/dist/types/port-forward-client.d.ts +0 -8
- package/dist/types/project-checkout-garbage.d.ts +0 -86
- package/dist/types/project-mirror-fetch-policy.d.ts +0 -84
- package/dist/types/project-mirror-refs-token.d.ts +0 -53
- package/dist/types/project-workspace-state.d.ts +0 -188
- package/dist/types/project-worktrees.d.ts +0 -397
- package/dist/types/pty-output-coalescer.d.ts +0 -20
- package/dist/types/recovery-journal-protocol.d.ts +0 -35
- package/dist/types/recovery-journal-runtime.d.ts +0 -12
- package/dist/types/recovery-journal-thread.d.ts +0 -1
- package/dist/types/recovery-journal.d.ts +0 -248
- package/dist/types/recovery-output-window.d.ts +0 -19
- package/dist/types/recovery-protocol.d.ts +0 -59
- package/dist/types/recovery-store.d.ts +0 -52
- package/dist/types/registry-auth.d.ts +0 -47
- package/dist/types/repository-transition-policy.d.ts +0 -26
- package/dist/types/runtime-version.d.ts +0 -1
- package/dist/types/session-file-mutations.d.ts +0 -22
- package/dist/types/supervisor-daemonized-fixture.d.ts +0 -1
- package/dist/types/supervisor-launcher-cleanup-fixture.d.ts +0 -1
- package/dist/types/supervisor-signal-fixture.d.ts +0 -1
- package/dist/types/supervisor.d.ts +0 -23
- package/dist/types/three-way-merge.d.ts +0 -77
- package/dist/types/working-tree-mirror.d.ts +0 -424
- package/dist/types/workspace-automatic-sync-policy.d.ts +0 -57
- package/dist/types/workspace-branch-incarnation-policy.d.ts +0 -14
- package/dist/types/workspace-command-sync-policy.d.ts +0 -57
- package/dist/types/workspace-command-targets.d.ts +0 -37
- package/dist/types/workspace-filesystem-executor-thread.d.ts +0 -1
- package/dist/types/workspace-filesystem-executor.d.ts +0 -123
- package/dist/types/workspace-filesystem-job-types.d.ts +0 -288
- package/dist/types/workspace-filesystem-jobs.d.ts +0 -7
- package/dist/types/workspace-git-sync.d.ts +0 -495
- package/dist/types/workspace-hydration-ledger.d.ts +0 -43
- package/dist/types/workspace-hydration-merge.d.ts +0 -95
- package/dist/types/workspace-hydration-recovery-state.d.ts +0 -10
- package/dist/types/workspace-incident-state.d.ts +0 -19
- package/dist/types/workspace-merge-projection.d.ts +0 -60
- package/dist/types/workspace-mount-boundary.d.ts +0 -10
- package/dist/types/workspace-mount-hold-fence.d.ts +0 -42
- package/dist/types/workspace-mutation-gate.d.ts +0 -42
- package/dist/types/workspace-path-move.d.ts +0 -21
- package/dist/types/workspace-preserve-only-policy.d.ts +0 -15
- package/dist/types/workspace-project-config-policy.d.ts +0 -48
- package/dist/types/workspace-projection-ledger.d.ts +0 -59
- package/dist/types/workspace-publication-evidence.d.ts +0 -17
- package/dist/types/workspace-sync-coalescer.d.ts +0 -28
- /package/dist/types/{credential-authority-lock-fixture.d.ts → runtime/adapter.d.ts} +0 -0
- /package/dist/types/{recovery-journal-stall-fixture.d.ts → runtime/releases/main.d.ts} +0 -0
|
@@ -1,423 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var command_launcher_exports = {};
|
|
20
|
-
__export(command_launcher_exports, {
|
|
21
|
-
CommandLaunchCancelledError: () => CommandLaunchCancelledError,
|
|
22
|
-
CommandLauncherUnavailableError: () => CommandLauncherUnavailableError,
|
|
23
|
-
WorkerCommandLauncher: () => WorkerCommandLauncher,
|
|
24
|
-
commandLaunchLane: () => commandLaunchLane,
|
|
25
|
-
commandLauncherEnvironment: () => commandLauncherEnvironment,
|
|
26
|
-
createWorkerCommandLauncher: () => createWorkerCommandLauncher,
|
|
27
|
-
parseCommandLauncher: () => parseCommandLauncher
|
|
28
|
-
});
|
|
29
|
-
module.exports = __toCommonJS(command_launcher_exports);
|
|
30
|
-
var import_node_child_process = require("node:child_process");
|
|
31
|
-
function commandLaunchLane(request) {
|
|
32
|
-
if (request.commandClass === "control") {
|
|
33
|
-
if (request.kind !== "exec_start") throw new Error("Control commands must be exec_start launches");
|
|
34
|
-
return "control";
|
|
35
|
-
}
|
|
36
|
-
return request.kind === "exec" && request.workspaceEffect === "none" ? "utility" : "general";
|
|
37
|
-
}
|
|
38
|
-
class CommandLauncherUnavailableError extends Error {
|
|
39
|
-
constructor(message, cause) {
|
|
40
|
-
super(message, { cause });
|
|
41
|
-
this.name = "CommandLauncherUnavailableError";
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
class CommandLaunchCancelledError extends Error {
|
|
45
|
-
constructor() {
|
|
46
|
-
super("Command cancelled before it started");
|
|
47
|
-
this.name = "CommandLaunchCancelledError";
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
function parseCommandLauncher(configuration) {
|
|
51
|
-
if (configuration === void 0) return void 0;
|
|
52
|
-
let argv;
|
|
53
|
-
try {
|
|
54
|
-
argv = JSON.parse(configuration);
|
|
55
|
-
} catch {
|
|
56
|
-
throw new Error("R5D_WORKER_COMMAND_LAUNCHER must be a JSON argv array");
|
|
57
|
-
}
|
|
58
|
-
if (!Array.isArray(argv) || argv.length === 0 || argv.some((part) => typeof part !== "string" || part.includes("\0")) || !argv[0])
|
|
59
|
-
throw new Error("R5D_WORKER_COMMAND_LAUNCHER must be a nonempty JSON argv array without NUL characters");
|
|
60
|
-
return argv;
|
|
61
|
-
}
|
|
62
|
-
function commandLauncherEnvironment(source = process.env) {
|
|
63
|
-
const result = {};
|
|
64
|
-
for (const [key, value] of Object.entries(source)) {
|
|
65
|
-
if (/^(PATH|HOME|USER|LOGNAME|TMP|TMPDIR|TEMP|SHELL|SYSTEMROOT|COMSPEC|PATHEXT|LANG|LC_[A-Z_]+)$/i.test(key)) result[key] = value;
|
|
66
|
-
}
|
|
67
|
-
return result;
|
|
68
|
-
}
|
|
69
|
-
class WorkerCommandLauncher {
|
|
70
|
-
constructor(options = {}) {
|
|
71
|
-
this.options = options;
|
|
72
|
-
this.mode = options.argv ? "external" : "direct";
|
|
73
|
-
if (!options.argv) {
|
|
74
|
-
this.exited = Promise.resolve();
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
this.child = (0, import_node_child_process.spawn)(options.argv[0], options.argv.slice(1), {
|
|
78
|
-
env: options.env ?? commandLauncherEnvironment(),
|
|
79
|
-
stdio: ["pipe", "pipe", "pipe"]
|
|
80
|
-
});
|
|
81
|
-
this.exited = new Promise((resolve) => {
|
|
82
|
-
this.child.once("close", (code, signal) => {
|
|
83
|
-
if (!this.closing) this.fail(new Error(`Configured command launcher exited (${signal ?? code ?? "unknown"})`));
|
|
84
|
-
resolve();
|
|
85
|
-
});
|
|
86
|
-
});
|
|
87
|
-
this.child.once("error", (error) => this.fail(error));
|
|
88
|
-
this.child.stdin.on("error", (error) => {
|
|
89
|
-
if (!this.closing) this.fail(error);
|
|
90
|
-
});
|
|
91
|
-
let buffered = "";
|
|
92
|
-
this.child.stdout.setEncoding("utf8");
|
|
93
|
-
this.child.stdout.on("data", (data) => {
|
|
94
|
-
buffered += data;
|
|
95
|
-
if (Buffer.byteLength(buffered) > 1024 * 1024) {
|
|
96
|
-
this.fail(new Error("Command launcher response exceeded the protocol limit"));
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
while (buffered.includes("\n")) {
|
|
100
|
-
const newline = buffered.indexOf("\n");
|
|
101
|
-
const line = buffered.slice(0, newline);
|
|
102
|
-
buffered = buffered.slice(newline + 1);
|
|
103
|
-
try {
|
|
104
|
-
this.receive(JSON.parse(line));
|
|
105
|
-
} catch (error) {
|
|
106
|
-
this.fail(error instanceof Error ? error : new Error(String(error)));
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
this.child.stderr.setEncoding("utf8");
|
|
112
|
-
this.child.stderr.on("data", (data) => options.onStderr?.(data));
|
|
113
|
-
}
|
|
114
|
-
options;
|
|
115
|
-
mode;
|
|
116
|
-
child;
|
|
117
|
-
pending = /* @__PURE__ */ new Map();
|
|
118
|
-
launches = /* @__PURE__ */ new Map();
|
|
119
|
-
exited;
|
|
120
|
-
failure;
|
|
121
|
-
closing = false;
|
|
122
|
-
initialized = false;
|
|
123
|
-
closePromise;
|
|
124
|
-
sequence = 0;
|
|
125
|
-
capacity;
|
|
126
|
-
async initialize() {
|
|
127
|
-
this.assertHealthy();
|
|
128
|
-
if (this.initialized) return;
|
|
129
|
-
if (this.child) {
|
|
130
|
-
try {
|
|
131
|
-
const result = await this.rpc("initialize");
|
|
132
|
-
this.capacity = parseCapacity(result.capacity);
|
|
133
|
-
} catch (error) {
|
|
134
|
-
this.fail(error instanceof Error ? error : new Error(String(error)));
|
|
135
|
-
await this.close();
|
|
136
|
-
throw error;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
this.initialized = true;
|
|
140
|
-
}
|
|
141
|
-
get activeIds() {
|
|
142
|
-
return [...this.launches.keys()];
|
|
143
|
-
}
|
|
144
|
-
/** The lane totals the launcher declared at initialization; undefined for a direct worker or an older launcher. */
|
|
145
|
-
get declaredCapacity() {
|
|
146
|
-
return this.capacity;
|
|
147
|
-
}
|
|
148
|
-
get supportsControlLane() {
|
|
149
|
-
return this.initialized && (this.mode === "direct" || (this.capacity?.controlSlots ?? 0) > 0);
|
|
150
|
-
}
|
|
151
|
-
/** Current admissions per lane, for the worker's capacity report. */
|
|
152
|
-
capacityReport() {
|
|
153
|
-
const bounded = this.child !== void 0;
|
|
154
|
-
const lanes = {
|
|
155
|
-
general: { slots: bounded ? this.capacity?.generalSlots ?? null : null, active: [], queued: [] },
|
|
156
|
-
utility: { slots: bounded ? this.capacity?.utilitySlots ?? null : null, active: [], queued: [] },
|
|
157
|
-
control: { slots: bounded ? this.capacity?.controlSlots ?? null : null, active: [], queued: [] }
|
|
158
|
-
};
|
|
159
|
-
for (const record of this.launches.values()) {
|
|
160
|
-
if (record.released) continue;
|
|
161
|
-
const entry = {
|
|
162
|
-
id: record.request.id,
|
|
163
|
-
...record.request.sessionId ? { sessionId: record.request.sessionId } : {},
|
|
164
|
-
since: record.since
|
|
165
|
-
};
|
|
166
|
-
(record.phase === "active" ? lanes[record.lane].active : lanes[record.lane].queued).push(entry);
|
|
167
|
-
}
|
|
168
|
-
return { bounded, controlRuntimeMs: bounded ? this.capacity?.controlRuntimeMs ?? null : null, lanes };
|
|
169
|
-
}
|
|
170
|
-
notifyCapacityChange() {
|
|
171
|
-
try {
|
|
172
|
-
this.options.onCapacityChange?.();
|
|
173
|
-
} catch {
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
async acquire(request) {
|
|
177
|
-
this.assertHealthy();
|
|
178
|
-
if (!this.initialized) throw new Error("Command launcher is not initialized");
|
|
179
|
-
request.assertAdmission();
|
|
180
|
-
if (this.launches.has(request.id)) throw new Error(`Duplicate command launch identity: ${request.id}`);
|
|
181
|
-
const lane = commandLaunchLane(request);
|
|
182
|
-
if (lane === "control" && !this.supportsControlLane)
|
|
183
|
-
throw new Error("Update the worker command launcher before running control commands");
|
|
184
|
-
let rejectAdmission;
|
|
185
|
-
const cancellation = new Promise((_resolve, reject) => {
|
|
186
|
-
rejectAdmission = reject;
|
|
187
|
-
});
|
|
188
|
-
void cancellation.catch(() => {
|
|
189
|
-
});
|
|
190
|
-
const record = {
|
|
191
|
-
request,
|
|
192
|
-
lane,
|
|
193
|
-
phase: this.child ? "queued" : "active",
|
|
194
|
-
since: (/* @__PURE__ */ new Date()).toISOString(),
|
|
195
|
-
revoked: false,
|
|
196
|
-
released: false,
|
|
197
|
-
rejectAdmission
|
|
198
|
-
};
|
|
199
|
-
this.launches.set(request.id, record);
|
|
200
|
-
this.notifyCapacityChange();
|
|
201
|
-
let prefix = [];
|
|
202
|
-
let admissionTimer;
|
|
203
|
-
try {
|
|
204
|
-
if (this.child) {
|
|
205
|
-
const { assertAdmission: _assertAdmission, ...fields } = request;
|
|
206
|
-
const acquisition = this.rpc("acquire", fields, this.options.acquisitionTimeoutMs ?? 9e4).then(async (result) => {
|
|
207
|
-
if (record.revoked) {
|
|
208
|
-
await this.releaseRecord(record);
|
|
209
|
-
throw new CommandLaunchCancelledError();
|
|
210
|
-
}
|
|
211
|
-
if (!Array.isArray(result.argvPrefix) || result.argvPrefix.some((part) => typeof part !== "string" || part.includes("\0")))
|
|
212
|
-
throw this.fail(new Error("Command launcher acquire returned an invalid argvPrefix"));
|
|
213
|
-
return result.argvPrefix;
|
|
214
|
-
});
|
|
215
|
-
admissionTimer = setInterval(() => {
|
|
216
|
-
try {
|
|
217
|
-
request.assertAdmission();
|
|
218
|
-
} catch (error) {
|
|
219
|
-
record.revoked = true;
|
|
220
|
-
record.rejectAdmission(error);
|
|
221
|
-
void this.cancel(request.id).catch(() => {
|
|
222
|
-
});
|
|
223
|
-
}
|
|
224
|
-
}, 100);
|
|
225
|
-
prefix = await Promise.race([acquisition, cancellation]);
|
|
226
|
-
record.phase = "active";
|
|
227
|
-
record.since = (/* @__PURE__ */ new Date()).toISOString();
|
|
228
|
-
this.notifyCapacityChange();
|
|
229
|
-
}
|
|
230
|
-
request.assertAdmission();
|
|
231
|
-
this.assertHealthy();
|
|
232
|
-
if (record.revoked) throw new CommandLaunchCancelledError();
|
|
233
|
-
} catch (error) {
|
|
234
|
-
if (!this.failure && !this.closing) await this.releaseRecord(record);
|
|
235
|
-
throw error;
|
|
236
|
-
} finally {
|
|
237
|
-
if (admissionTimer) clearInterval(admissionTimer);
|
|
238
|
-
}
|
|
239
|
-
return {
|
|
240
|
-
wrap: (argv) => {
|
|
241
|
-
this.assertHealthy();
|
|
242
|
-
request.assertAdmission();
|
|
243
|
-
if (record.revoked) throw new CommandLaunchCancelledError();
|
|
244
|
-
if (record.released) throw new Error("Command launch lease is already released");
|
|
245
|
-
if (!argv.length) throw new Error("Command argv must not be empty");
|
|
246
|
-
return [...prefix, ...argv];
|
|
247
|
-
},
|
|
248
|
-
cancel: async () => {
|
|
249
|
-
await this.cancel(request.id);
|
|
250
|
-
},
|
|
251
|
-
diagnose: async () => {
|
|
252
|
-
this.assertHealthy();
|
|
253
|
-
if (!this.child) return void 0;
|
|
254
|
-
try {
|
|
255
|
-
const result = await this.rpc("diagnose", { id: request.id });
|
|
256
|
-
if (result.message !== void 0 && typeof result.message !== "string")
|
|
257
|
-
throw new Error("Command launcher returned an invalid diagnostic");
|
|
258
|
-
return result.message;
|
|
259
|
-
} catch (error) {
|
|
260
|
-
throw this.fail(error instanceof Error ? error : new Error(String(error)));
|
|
261
|
-
}
|
|
262
|
-
},
|
|
263
|
-
release: () => this.releaseRecord(record)
|
|
264
|
-
};
|
|
265
|
-
}
|
|
266
|
-
/** Revoke a launch. Returns whether this launcher still held it (queued or acquired, not yet released). */
|
|
267
|
-
async cancel(id) {
|
|
268
|
-
const record = this.launches.get(id);
|
|
269
|
-
if (!record || record.released) return false;
|
|
270
|
-
record.revoked = true;
|
|
271
|
-
record.rejectAdmission(new CommandLaunchCancelledError());
|
|
272
|
-
if (this.child) {
|
|
273
|
-
try {
|
|
274
|
-
await this.rpc("cancel", { id });
|
|
275
|
-
} catch (error) {
|
|
276
|
-
throw this.fail(error instanceof Error ? error : new Error(String(error)));
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
return true;
|
|
280
|
-
}
|
|
281
|
-
async cancelSession(sessionId) {
|
|
282
|
-
await this.cancelMatching((_id, ownerSessionId) => ownerSessionId === sessionId);
|
|
283
|
-
}
|
|
284
|
-
async cancelMatching(matches) {
|
|
285
|
-
const results = await Promise.allSettled(
|
|
286
|
-
[...this.launches].filter(([id, record]) => matches(id, record.request.sessionId)).map(([id]) => this.cancel(id))
|
|
287
|
-
);
|
|
288
|
-
const errors = results.flatMap((result) => result.status === "rejected" ? [result.reason] : []);
|
|
289
|
-
if (errors.length) throw new AggregateError(errors, "Command launcher cancellation was incomplete");
|
|
290
|
-
}
|
|
291
|
-
close() {
|
|
292
|
-
return this.closePromise ??= (async () => {
|
|
293
|
-
this.closing = true;
|
|
294
|
-
for (const record of this.launches.values()) {
|
|
295
|
-
record.revoked = true;
|
|
296
|
-
record.rejectAdmission(new CommandLaunchCancelledError());
|
|
297
|
-
}
|
|
298
|
-
this.rejectPending(new CommandLauncherUnavailableError("Command launcher is shutting down"));
|
|
299
|
-
this.child?.stdin.end();
|
|
300
|
-
const exited = await this.waitForExit(6e3);
|
|
301
|
-
if (!exited) {
|
|
302
|
-
this.child?.kill("SIGKILL");
|
|
303
|
-
await this.waitForExit(1e3);
|
|
304
|
-
}
|
|
305
|
-
})();
|
|
306
|
-
}
|
|
307
|
-
async waitForExit(timeoutMs) {
|
|
308
|
-
let timer;
|
|
309
|
-
try {
|
|
310
|
-
return await Promise.race([
|
|
311
|
-
this.exited.then(() => true),
|
|
312
|
-
new Promise((resolve) => {
|
|
313
|
-
timer = setTimeout(() => resolve(false), timeoutMs);
|
|
314
|
-
})
|
|
315
|
-
]);
|
|
316
|
-
} finally {
|
|
317
|
-
if (timer) clearTimeout(timer);
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
releaseRecord(record) {
|
|
321
|
-
return record.release ??= (async () => {
|
|
322
|
-
record.revoked = true;
|
|
323
|
-
if (this.child) {
|
|
324
|
-
try {
|
|
325
|
-
await this.rpc("release", { id: record.request.id });
|
|
326
|
-
} catch (error) {
|
|
327
|
-
throw this.fail(error instanceof Error ? error : new Error(String(error)));
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
record.released = true;
|
|
331
|
-
this.launches.delete(record.request.id);
|
|
332
|
-
this.notifyCapacityChange();
|
|
333
|
-
})();
|
|
334
|
-
}
|
|
335
|
-
assertHealthy() {
|
|
336
|
-
if (this.failure) throw this.failure;
|
|
337
|
-
if (this.closing) throw new CommandLauncherUnavailableError("Command launcher is shutting down");
|
|
338
|
-
}
|
|
339
|
-
rpc(method, fields = {}, timeoutMs = this.options.requestTimeoutMs ?? 1e4) {
|
|
340
|
-
try {
|
|
341
|
-
this.assertHealthy();
|
|
342
|
-
} catch (error) {
|
|
343
|
-
return Promise.reject(error);
|
|
344
|
-
}
|
|
345
|
-
const requestId = String(++this.sequence);
|
|
346
|
-
return new Promise((resolve, reject) => {
|
|
347
|
-
const timer = setTimeout(() => this.fail(new Error(`Command launcher ${method} request timed out`)), timeoutMs);
|
|
348
|
-
this.pending.set(requestId, { resolve, reject, timer });
|
|
349
|
-
this.child.stdin.write(`${JSON.stringify({ requestId, method, ...fields })}
|
|
350
|
-
`, (error) => {
|
|
351
|
-
if (error) this.fail(error);
|
|
352
|
-
});
|
|
353
|
-
});
|
|
354
|
-
}
|
|
355
|
-
receive(value) {
|
|
356
|
-
if (!value || typeof value !== "object") throw new Error("Invalid command launcher response");
|
|
357
|
-
const response = value;
|
|
358
|
-
if (typeof response.requestId !== "string") throw new Error("Command launcher response is missing requestId");
|
|
359
|
-
const request = this.pending.get(response.requestId);
|
|
360
|
-
if (!request) throw new Error("Command launcher returned an unknown requestId");
|
|
361
|
-
this.pending.delete(response.requestId);
|
|
362
|
-
clearTimeout(request.timer);
|
|
363
|
-
if (typeof response.error === "string") {
|
|
364
|
-
request.reject(new Error(response.error));
|
|
365
|
-
return;
|
|
366
|
-
}
|
|
367
|
-
if (!response.result || typeof response.result !== "object" || Array.isArray(response.result)) {
|
|
368
|
-
const error = new Error("Command launcher response is missing result");
|
|
369
|
-
request.reject(error);
|
|
370
|
-
throw error;
|
|
371
|
-
}
|
|
372
|
-
request.resolve(response.result);
|
|
373
|
-
}
|
|
374
|
-
rejectPending(error) {
|
|
375
|
-
for (const request of this.pending.values()) {
|
|
376
|
-
clearTimeout(request.timer);
|
|
377
|
-
request.reject(error);
|
|
378
|
-
}
|
|
379
|
-
this.pending.clear();
|
|
380
|
-
}
|
|
381
|
-
fail(error) {
|
|
382
|
-
if (this.failure || this.closing) return this.failure ?? error;
|
|
383
|
-
this.failure = new CommandLauncherUnavailableError(`Command launcher unavailable: ${error.message}`, error);
|
|
384
|
-
for (const record of this.launches.values()) {
|
|
385
|
-
record.revoked = true;
|
|
386
|
-
record.rejectAdmission(this.failure);
|
|
387
|
-
}
|
|
388
|
-
this.rejectPending(this.failure);
|
|
389
|
-
this.child?.kill("SIGTERM");
|
|
390
|
-
this.options.onFailure?.(this.failure, this.activeIds);
|
|
391
|
-
return this.failure;
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
function parseCapacity(value) {
|
|
395
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) return void 0;
|
|
396
|
-
const candidate = value;
|
|
397
|
-
const numbers = ["generalSlots", "utilitySlots", "controlSlots", "controlRuntimeMs", "queueTimeoutMs"];
|
|
398
|
-
if (!numbers.every((key) => typeof candidate[key] === "number" && Number.isSafeInteger(candidate[key]) && candidate[key] >= 0)) {
|
|
399
|
-
throw new Error("Command launcher initialize returned an invalid capacity");
|
|
400
|
-
}
|
|
401
|
-
return {
|
|
402
|
-
generalSlots: candidate.generalSlots,
|
|
403
|
-
utilitySlots: candidate.utilitySlots,
|
|
404
|
-
controlSlots: candidate.controlSlots,
|
|
405
|
-
controlRuntimeMs: candidate.controlRuntimeMs,
|
|
406
|
-
queueTimeoutMs: candidate.queueTimeoutMs
|
|
407
|
-
};
|
|
408
|
-
}
|
|
409
|
-
async function createWorkerCommandLauncher(options = {}) {
|
|
410
|
-
const launcher = new WorkerCommandLauncher({ ...options, argv: parseCommandLauncher(options.configuration) });
|
|
411
|
-
await launcher.initialize();
|
|
412
|
-
return launcher;
|
|
413
|
-
}
|
|
414
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
415
|
-
0 && (module.exports = {
|
|
416
|
-
CommandLaunchCancelledError,
|
|
417
|
-
CommandLauncherUnavailableError,
|
|
418
|
-
WorkerCommandLauncher,
|
|
419
|
-
commandLaunchLane,
|
|
420
|
-
commandLauncherEnvironment,
|
|
421
|
-
createWorkerCommandLauncher,
|
|
422
|
-
parseCommandLauncher
|
|
423
|
-
});
|
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var control_command_policy_exports = {};
|
|
20
|
-
__export(control_command_policy_exports, {
|
|
21
|
-
CONTROL_COMMAND_MAX_ARGV: () => CONTROL_COMMAND_MAX_ARGV,
|
|
22
|
-
CONTROL_COMMAND_MAX_LENGTH: () => CONTROL_COMMAND_MAX_LENGTH,
|
|
23
|
-
CONTROL_COMMAND_PROGRAM: () => CONTROL_COMMAND_PROGRAM,
|
|
24
|
-
CONTROL_COMMAND_RUNTIME_MS: () => CONTROL_COMMAND_RUNTIME_MS,
|
|
25
|
-
assertControlCommandArgv: () => assertControlCommandArgv,
|
|
26
|
-
classifyControlCommand: () => classifyControlCommand,
|
|
27
|
-
controlCommandEnvironment: () => controlCommandEnvironment,
|
|
28
|
-
resolveControlCommandExecutable: () => resolveControlCommandExecutable
|
|
29
|
-
});
|
|
30
|
-
module.exports = __toCommonJS(control_command_policy_exports);
|
|
31
|
-
const CONTROL_COMMAND_PROGRAM = "r5dctl";
|
|
32
|
-
const CONTROL_COMMAND_RUNTIME_MS = 12e4;
|
|
33
|
-
const CONTROL_COMMAND_MAX_ARGV = 64;
|
|
34
|
-
const CONTROL_COMMAND_MAX_LENGTH = 4096;
|
|
35
|
-
const CONTROL_GLOBAL_FLAGS_WITH_VALUE = /* @__PURE__ */ new Set(["-p", "--project", "-s", "--session", "-b", "--branch"]);
|
|
36
|
-
const CONTROL_GLOBAL_FLAGS = /* @__PURE__ */ new Set(["--json", "-h", "--help", "-v", "--version"]);
|
|
37
|
-
const REFUSED_ANYWHERE = /* @__PURE__ */ new Set(["-f", "--follow", "--watch", "--base-url", "--config", "--token", "--api-key"]);
|
|
38
|
-
const CONTROL_VERBS = {
|
|
39
|
-
session: /* @__PURE__ */ new Set(["status", "stop", "prompt", "claim", "claims", "process-log"]),
|
|
40
|
-
sessions: /* @__PURE__ */ new Set(["recent"]),
|
|
41
|
-
describe: /* @__PURE__ */ new Set(["project", "branch", "session", "branch-operation", "branch-deletion"]),
|
|
42
|
-
get: /* @__PURE__ */ new Set(["projects", "branches", "sessions", "envs", "env"]),
|
|
43
|
-
conversation: /* @__PURE__ */ new Set(["overview", "inspect-node", "inspect-work"]),
|
|
44
|
-
ps: /* @__PURE__ */ new Set(["list", "history", "inspect", "stop"]),
|
|
45
|
-
workspace: /* @__PURE__ */ new Set(["status"]),
|
|
46
|
-
auth: /* @__PURE__ */ new Set(["status"]),
|
|
47
|
-
create: /* @__PURE__ */ new Set(["session"]),
|
|
48
|
-
update: /* @__PURE__ */ new Set(["session"]),
|
|
49
|
-
delete: /* @__PURE__ */ new Set(["session"]),
|
|
50
|
-
"answer-questions": null,
|
|
51
|
-
"answer-env-request": null
|
|
52
|
-
};
|
|
53
|
-
const CODE_LOADING_ENV_PATTERN = /^(NODE_OPTIONS|NODE_PATH|NODE_REPL_EXTERNAL_MODULE|BUN_OPTIONS|BUN_CONFIG_[A-Z_]+|LD_PRELOAD|LD_LIBRARY_PATH|LD_AUDIT|DYLD_[A-Z_]+|PATH|PATHEXT|PYTHONPATH|PERL5OPT|RUBYOPT|SHELL|ENV|BASH_ENV)$/i;
|
|
54
|
-
const BARE_WORD = /^[A-Za-z0-9_@%+=:,./-]+$/;
|
|
55
|
-
const DOUBLE_QUOTED_FORBIDDEN = /[$`\\!]/;
|
|
56
|
-
function tokenizePlainInvocation(command) {
|
|
57
|
-
if (command.length > CONTROL_COMMAND_MAX_LENGTH) return { reason: "command is longer than the control lane allows" };
|
|
58
|
-
if (/[\r\n]/.test(command)) return { reason: "multi-line commands are shell scripts" };
|
|
59
|
-
const argv = [];
|
|
60
|
-
let index = 0;
|
|
61
|
-
while (index < command.length) {
|
|
62
|
-
const char = command[index];
|
|
63
|
-
if (char === " " || char === " ") {
|
|
64
|
-
index += 1;
|
|
65
|
-
continue;
|
|
66
|
-
}
|
|
67
|
-
let word = "";
|
|
68
|
-
let quotedParts = 0;
|
|
69
|
-
let bareParts = 0;
|
|
70
|
-
while (index < command.length && command[index] !== " " && command[index] !== " ") {
|
|
71
|
-
const current = command[index];
|
|
72
|
-
if (current === "'") {
|
|
73
|
-
const end = command.indexOf("'", index + 1);
|
|
74
|
-
if (end < 0) return { reason: "unterminated single quote" };
|
|
75
|
-
word += command.slice(index + 1, end);
|
|
76
|
-
quotedParts += 1;
|
|
77
|
-
index = end + 1;
|
|
78
|
-
continue;
|
|
79
|
-
}
|
|
80
|
-
if (current === '"') {
|
|
81
|
-
const end = command.indexOf('"', index + 1);
|
|
82
|
-
if (end < 0) return { reason: "unterminated double quote" };
|
|
83
|
-
const inner = command.slice(index + 1, end);
|
|
84
|
-
if (DOUBLE_QUOTED_FORBIDDEN.test(inner)) return { reason: "double-quoted text would be expanded by the shell" };
|
|
85
|
-
word += inner;
|
|
86
|
-
quotedParts += 1;
|
|
87
|
-
index = end + 1;
|
|
88
|
-
continue;
|
|
89
|
-
}
|
|
90
|
-
let bare = "";
|
|
91
|
-
while (index < command.length && !/[\s'"]/.test(command[index])) {
|
|
92
|
-
bare += command[index];
|
|
93
|
-
index += 1;
|
|
94
|
-
}
|
|
95
|
-
if (!BARE_WORD.test(bare)) return { reason: `shell syntax in "${bare}" is not part of a plain invocation` };
|
|
96
|
-
word += bare;
|
|
97
|
-
bareParts += 1;
|
|
98
|
-
}
|
|
99
|
-
if (quotedParts + bareParts > 1) return { reason: "adjacent quoted and bare text is shell concatenation" };
|
|
100
|
-
argv.push(word);
|
|
101
|
-
if (argv.length > CONTROL_COMMAND_MAX_ARGV) return { reason: "too many arguments for a control command" };
|
|
102
|
-
}
|
|
103
|
-
if (argv.length === 0) return { reason: "empty command" };
|
|
104
|
-
return { argv };
|
|
105
|
-
}
|
|
106
|
-
function assertControlCommandArgv(argv) {
|
|
107
|
-
if (argv.length === 0 || argv.length > CONTROL_COMMAND_MAX_ARGV) throw new Error("Control commands are a single r5dctl invocation");
|
|
108
|
-
if (argv[0] !== CONTROL_COMMAND_PROGRAM) throw new Error(`Control commands must start with ${CONTROL_COMMAND_PROGRAM}`);
|
|
109
|
-
if (argv.reduce((length, argument) => length + (typeof argument === "string" ? argument.length : 0) + 1, 0) > CONTROL_COMMAND_MAX_LENGTH)
|
|
110
|
-
throw new Error("Control command arguments exceed the length limit");
|
|
111
|
-
for (const argument of argv) {
|
|
112
|
-
if (typeof argument !== "string" || argument.includes("\0") || /[\r\n]/.test(argument)) throw new Error("Control command arguments must be plain text");
|
|
113
|
-
if (REFUSED_ANYWHERE.has(argument.split("=", 1)[0])) throw new Error(`Control command option is not allowed (${argument.split("=", 1)[0]})`);
|
|
114
|
-
if (argument === "--") throw new Error("Control commands cannot use `--`");
|
|
115
|
-
}
|
|
116
|
-
let position = 1;
|
|
117
|
-
while (position < argv.length) {
|
|
118
|
-
const argument = argv[position];
|
|
119
|
-
if (CONTROL_GLOBAL_FLAGS.has(argument)) {
|
|
120
|
-
position += 1;
|
|
121
|
-
continue;
|
|
122
|
-
}
|
|
123
|
-
if (CONTROL_GLOBAL_FLAGS_WITH_VALUE.has(argument)) {
|
|
124
|
-
if (position + 1 >= argv.length) throw new Error(`Missing value for ${argument}`);
|
|
125
|
-
position += 2;
|
|
126
|
-
continue;
|
|
127
|
-
}
|
|
128
|
-
if (argument.startsWith("-")) throw new Error(`Global flag ${argument} is not allowed in a control command`);
|
|
129
|
-
break;
|
|
130
|
-
}
|
|
131
|
-
const verb = argv[position];
|
|
132
|
-
if (verb === void 0) throw new Error("Control commands need a coordination verb (for example `r5dctl ps list`)");
|
|
133
|
-
const allowed = Object.hasOwn(CONTROL_VERBS, verb) ? CONTROL_VERBS[verb] : void 0;
|
|
134
|
-
if (allowed === void 0) throw new Error(`r5dctl ${verb} is not a coordination command`);
|
|
135
|
-
if (allowed === null) return;
|
|
136
|
-
const subject = argv[position + 1];
|
|
137
|
-
if (subject === void 0 || !allowed.has(subject)) {
|
|
138
|
-
throw new Error(`r5dctl ${verb}${subject ? ` ${subject}` : ""} is not a coordination command`);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
function resolveControlCommandExecutable(trustedPath, which, program = CONTROL_COMMAND_PROGRAM) {
|
|
142
|
-
const resolved = trustedPath ? which(program, { PATH: trustedPath }) : null;
|
|
143
|
-
if (!resolved) throw new Error(`${program} is not installed on the worker's trusted PATH; control commands are unavailable until it is`);
|
|
144
|
-
return resolved;
|
|
145
|
-
}
|
|
146
|
-
function controlCommandEnvironment(environment, trustedPath) {
|
|
147
|
-
const result = {};
|
|
148
|
-
for (const [key, value] of Object.entries(environment)) {
|
|
149
|
-
if (value === void 0 || CODE_LOADING_ENV_PATTERN.test(key)) continue;
|
|
150
|
-
result[key] = value;
|
|
151
|
-
}
|
|
152
|
-
if (trustedPath !== void 0) result.PATH = trustedPath;
|
|
153
|
-
return result;
|
|
154
|
-
}
|
|
155
|
-
function classifyControlCommand(command) {
|
|
156
|
-
const tokenized = tokenizePlainInvocation(command.trim());
|
|
157
|
-
if ("reason" in tokenized) return { control: false, reason: tokenized.reason };
|
|
158
|
-
const { argv } = tokenized;
|
|
159
|
-
if (argv[0] !== CONTROL_COMMAND_PROGRAM) return { control: false, reason: "not an r5dctl invocation" };
|
|
160
|
-
try {
|
|
161
|
-
assertControlCommandArgv(argv);
|
|
162
|
-
} catch (error) {
|
|
163
|
-
return { control: false, reason: error instanceof Error ? error.message : String(error) };
|
|
164
|
-
}
|
|
165
|
-
return { control: true, argv };
|
|
166
|
-
}
|
|
167
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
168
|
-
0 && (module.exports = {
|
|
169
|
-
CONTROL_COMMAND_MAX_ARGV,
|
|
170
|
-
CONTROL_COMMAND_MAX_LENGTH,
|
|
171
|
-
CONTROL_COMMAND_PROGRAM,
|
|
172
|
-
CONTROL_COMMAND_RUNTIME_MS,
|
|
173
|
-
assertControlCommandArgv,
|
|
174
|
-
classifyControlCommand,
|
|
175
|
-
controlCommandEnvironment,
|
|
176
|
-
resolveControlCommandExecutable
|
|
177
|
-
});
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var git_blob_hash_exports = {};
|
|
20
|
-
__export(git_blob_hash_exports, {
|
|
21
|
-
gitBlobHash: () => gitBlobHash,
|
|
22
|
-
gitObjectHashAlgorithmFor: () => gitObjectHashAlgorithmFor
|
|
23
|
-
});
|
|
24
|
-
module.exports = __toCommonJS(git_blob_hash_exports);
|
|
25
|
-
var import_node_crypto = require("node:crypto");
|
|
26
|
-
function gitObjectHashAlgorithmFor(objectId) {
|
|
27
|
-
if (/^[0-9a-f]{40}$/u.test(objectId)) return "sha1";
|
|
28
|
-
if (/^[0-9a-f]{64}$/u.test(objectId)) return "sha256";
|
|
29
|
-
return null;
|
|
30
|
-
}
|
|
31
|
-
function gitBlobHash(content, algorithm) {
|
|
32
|
-
const hash = (0, import_node_crypto.createHash)(algorithm);
|
|
33
|
-
hash.update(`blob ${content.length}\0`);
|
|
34
|
-
hash.update(content);
|
|
35
|
-
return hash.digest("hex");
|
|
36
|
-
}
|
|
37
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
38
|
-
0 && (module.exports = {
|
|
39
|
-
gitBlobHash,
|
|
40
|
-
gitObjectHashAlgorithmFor
|
|
41
|
-
});
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var git_identity_exports = {};
|
|
20
|
-
__export(git_identity_exports, {
|
|
21
|
-
configureVisibleGitIdentity: () => configureVisibleGitIdentity
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(git_identity_exports);
|
|
24
|
-
function configureVisibleGitIdentity(branchPath, identity, runGit) {
|
|
25
|
-
if (!identity) {
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
const name = identity.name.trim();
|
|
29
|
-
const email = identity.email.trim();
|
|
30
|
-
if (!name || !email) {
|
|
31
|
-
throw new Error("Git identity must include name and email");
|
|
32
|
-
}
|
|
33
|
-
runGit(["config", "user.name", name], { cwd: branchPath });
|
|
34
|
-
runGit(["config", "user.email", email], { cwd: branchPath });
|
|
35
|
-
}
|
|
36
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
37
|
-
0 && (module.exports = {
|
|
38
|
-
configureVisibleGitIdentity
|
|
39
|
-
});
|