@vm0/runner 3.16.7 → 3.17.0
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/index.js +41 -19
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1888,12 +1888,39 @@ function encode(type, seq, payload = Buffer.alloc(0)) {
|
|
|
1888
1888
|
header.writeUInt32BE(body.length, 0);
|
|
1889
1889
|
return Buffer.concat([header, body]);
|
|
1890
1890
|
}
|
|
1891
|
-
function encodeExecPayload(command, timeoutMs) {
|
|
1891
|
+
function encodeExecPayload(command, timeoutMs, env) {
|
|
1892
1892
|
const cmdBuf = Buffer.from(command, "utf-8");
|
|
1893
|
-
const
|
|
1893
|
+
const envEntries = env ? Object.entries(env) : [];
|
|
1894
|
+
let envSize = 0;
|
|
1895
|
+
const encodedEntries = [];
|
|
1896
|
+
if (envEntries.length > 0) {
|
|
1897
|
+
envSize = 4;
|
|
1898
|
+
for (const [key, val] of envEntries) {
|
|
1899
|
+
const keyBuf = Buffer.from(key, "utf-8");
|
|
1900
|
+
const valBuf = Buffer.from(val, "utf-8");
|
|
1901
|
+
envSize += 4 + keyBuf.length + 4 + valBuf.length;
|
|
1902
|
+
encodedEntries.push([keyBuf, valBuf]);
|
|
1903
|
+
}
|
|
1904
|
+
}
|
|
1905
|
+
const payload = Buffer.alloc(8 + cmdBuf.length + envSize);
|
|
1894
1906
|
payload.writeUInt32BE(timeoutMs, 0);
|
|
1895
1907
|
payload.writeUInt32BE(cmdBuf.length, 4);
|
|
1896
1908
|
cmdBuf.copy(payload, 8);
|
|
1909
|
+
if (encodedEntries.length > 0) {
|
|
1910
|
+
let offset = 8 + cmdBuf.length;
|
|
1911
|
+
payload.writeUInt32BE(encodedEntries.length, offset);
|
|
1912
|
+
offset += 4;
|
|
1913
|
+
for (const [keyBuf, valBuf] of encodedEntries) {
|
|
1914
|
+
payload.writeUInt32BE(keyBuf.length, offset);
|
|
1915
|
+
offset += 4;
|
|
1916
|
+
keyBuf.copy(payload, offset);
|
|
1917
|
+
offset += keyBuf.length;
|
|
1918
|
+
payload.writeUInt32BE(valBuf.length, offset);
|
|
1919
|
+
offset += 4;
|
|
1920
|
+
valBuf.copy(payload, offset);
|
|
1921
|
+
offset += valBuf.length;
|
|
1922
|
+
}
|
|
1923
|
+
}
|
|
1897
1924
|
return payload;
|
|
1898
1925
|
}
|
|
1899
1926
|
function encodeWriteFilePayload(path10, content, sudo) {
|
|
@@ -2091,10 +2118,10 @@ var VsockClient = class {
|
|
|
2091
2118
|
/**
|
|
2092
2119
|
* Execute a command on the remote VM
|
|
2093
2120
|
*/
|
|
2094
|
-
async exec(command, timeoutMs) {
|
|
2121
|
+
async exec(command, timeoutMs, env) {
|
|
2095
2122
|
const actualTimeout = timeoutMs ?? DEFAULT_EXEC_TIMEOUT_MS;
|
|
2096
2123
|
try {
|
|
2097
|
-
const payload = encodeExecPayload(command, actualTimeout);
|
|
2124
|
+
const payload = encodeExecPayload(command, actualTimeout, env);
|
|
2098
2125
|
const response = await this.request(
|
|
2099
2126
|
MSG_EXEC,
|
|
2100
2127
|
payload,
|
|
@@ -2325,8 +2352,8 @@ var VsockClient = class {
|
|
|
2325
2352
|
* Returns immediately with the PID. Use waitForExit() to wait for completion.
|
|
2326
2353
|
* When the process exits, the agent sends an unsolicited notification.
|
|
2327
2354
|
*/
|
|
2328
|
-
async spawnAndWatch(command, timeoutMs = 0) {
|
|
2329
|
-
const payload = encodeExecPayload(command, timeoutMs);
|
|
2355
|
+
async spawnAndWatch(command, timeoutMs = 0, env) {
|
|
2356
|
+
const payload = encodeExecPayload(command, timeoutMs, env);
|
|
2330
2357
|
const response = await this.request(
|
|
2331
2358
|
MSG_SPAWN_WATCH,
|
|
2332
2359
|
payload,
|
|
@@ -2448,7 +2475,7 @@ var GUEST_BINARY_PATHS = {
|
|
|
2448
2475
|
/** Storage download - parallel downloads with streaming extraction */
|
|
2449
2476
|
guestDownload: "/usr/local/bin/guest-download"
|
|
2450
2477
|
};
|
|
2451
|
-
var
|
|
2478
|
+
var RUN_AGENT_PATH = "/usr/local/bin/vm0-agent/run-agent.mjs";
|
|
2452
2479
|
|
|
2453
2480
|
// src/lib/proxy/vm-registry.ts
|
|
2454
2481
|
import fs6 from "fs";
|
|
@@ -2896,7 +2923,6 @@ async function restoreSessionHistory(guest, resumeSession, workingDir, cliAgentT
|
|
|
2896
2923
|
}
|
|
2897
2924
|
|
|
2898
2925
|
// src/lib/executor/env.ts
|
|
2899
|
-
var ENV_JSON_PATH = "/tmp/vm0-env.json";
|
|
2900
2926
|
function buildEnvironmentVariables(context, apiUrl) {
|
|
2901
2927
|
const envVars = {
|
|
2902
2928
|
VM0_API_URL: apiUrl,
|
|
@@ -3074,9 +3100,7 @@ async function executeJob(context, config, options = {}) {
|
|
|
3074
3100
|
logger9.log(
|
|
3075
3101
|
`VM ${vmId} started, guest IP: ${guestIp}, veth NS IP: ${vethNsIp}`
|
|
3076
3102
|
);
|
|
3077
|
-
const
|
|
3078
|
-
buildEnvironmentVariables(context, config.server.url)
|
|
3079
|
-
);
|
|
3103
|
+
const envVars = buildEnvironmentVariables(context, config.server.url);
|
|
3080
3104
|
const firewallConfig = context.experimentalFirewall;
|
|
3081
3105
|
if (firewallConfig?.enabled) {
|
|
3082
3106
|
const mitmEnabled = firewallConfig.experimental_mitm ?? false;
|
|
@@ -3114,10 +3138,6 @@ async function executeJob(context, config, options = {}) {
|
|
|
3114
3138
|
)
|
|
3115
3139
|
);
|
|
3116
3140
|
}
|
|
3117
|
-
logger9.log(
|
|
3118
|
-
`Writing env JSON (${envJson.length} bytes) to ${ENV_JSON_PATH}`
|
|
3119
|
-
);
|
|
3120
|
-
await guest.writeFile(ENV_JSON_PATH, envJson);
|
|
3121
3141
|
const systemLogFile = `/tmp/vm0-main-${context.runId}.log`;
|
|
3122
3142
|
const startTime = Date.now();
|
|
3123
3143
|
const maxWaitMs = 2 * 60 * 60 * 1e3;
|
|
@@ -3126,10 +3146,12 @@ async function executeJob(context, config, options = {}) {
|
|
|
3126
3146
|
logger9.log(`Running command directly (benchmark mode)...`);
|
|
3127
3147
|
command = `${context.prompt} > ${systemLogFile} 2>&1`;
|
|
3128
3148
|
} else {
|
|
3129
|
-
logger9.log(
|
|
3130
|
-
|
|
3149
|
+
logger9.log(
|
|
3150
|
+
`Running agent via vsock with ${Object.keys(envVars).length} env vars...`
|
|
3151
|
+
);
|
|
3152
|
+
command = `node ${RUN_AGENT_PATH} > ${systemLogFile} 2>&1`;
|
|
3131
3153
|
}
|
|
3132
|
-
const { pid } = await guest.spawnAndWatch(command, maxWaitMs);
|
|
3154
|
+
const { pid } = await guest.spawnAndWatch(command, maxWaitMs, envVars);
|
|
3133
3155
|
logger9.log(`Process started with pid=${pid}`);
|
|
3134
3156
|
let exitCode = 1;
|
|
3135
3157
|
let exitEvent;
|
|
@@ -4646,7 +4668,7 @@ var snapshotCommand = new Command5("snapshot").description("Generate a Firecrack
|
|
|
4646
4668
|
);
|
|
4647
4669
|
|
|
4648
4670
|
// src/index.ts
|
|
4649
|
-
var version = true ? "3.
|
|
4671
|
+
var version = true ? "3.17.0" : "0.1.0";
|
|
4650
4672
|
program.name("vm0-runner").version(version).description("Self-hosted runner for VM0 agents");
|
|
4651
4673
|
program.addCommand(startCommand);
|
|
4652
4674
|
program.addCommand(doctorCommand);
|