pi-straw-boss 0.75.1 → 0.75.2
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/server/{chunk-SDNV6G3O.mjs → chunk-PQZBUOCK.mjs} +61 -20
- package/dist/server/cli.mjs +2 -2
- package/dist/server/main.mjs +197 -170
- package/package.json +1 -1
- package/src/balance.d.mts +1 -1
- package/src/balance.mjs +5 -3
- package/src/exe.d.mts +2 -1
- package/src/exe.mjs +72 -9
- package/src/herdr.ts +7 -4
- package/src/hygiene.ts +3 -3
- package/src/lan/ca.ts +2 -2
- package/src/lan/firewall.ts +2 -2
- package/src/lanface.ts +2 -2
- package/src/link/allow.ts +1 -1
- package/src/pairing.ts +1 -1
- package/src/procs/killguard.ts +1 -1
- package/src/procs/table.ts +1 -1
- package/src/remote.ts +1 -1
- package/src/server/carops.ts +1 -1
- package/src/server/guihost.ts +5 -2
- package/src/server/lineage.ts +1 -1
- package/src/server/traincmds.ts +1 -1
- package/src/spawn.ts +13 -6
- package/src/startof.ts +1 -1
- package/src/trainguard.ts +1 -1
- package/src/trust/ask.ts +8 -1
- package/src/trust/intent.ts +42 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/exe.mjs
|
|
2
|
-
import { execFile, execFileSync } from "node:child_process";
|
|
2
|
+
import { execFile, execFileSync, spawn } from "node:child_process";
|
|
3
3
|
import { accessSync, constants, statSync } from "node:fs";
|
|
4
4
|
import { posix, win32 } from "node:path";
|
|
5
5
|
var ExeNotFound = class extends Error {
|
|
@@ -47,8 +47,48 @@ function resolveExe(name, deps = {}) {
|
|
|
47
47
|
return found;
|
|
48
48
|
}
|
|
49
49
|
var forgetExe = (name) => void (name === void 0 ? cache.clear() : cache.delete(name));
|
|
50
|
+
var GRACE_MS = 2e3;
|
|
51
|
+
var signalGroup = (pid, signal) => {
|
|
52
|
+
try {
|
|
53
|
+
return process.kill(-pid, signal);
|
|
54
|
+
} catch {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
function execFileByDeadline(file, args, options, done) {
|
|
59
|
+
const alone = process.platform === "win32" || options.group === false, limit = options.maxBuffer ?? 1024 * 1024, cmd = [file, ...args].join(" ");
|
|
60
|
+
const child = spawn(file, args, { cwd: options.cwd, env: options.env, windowsHide: options.windowsHide, detached: !alone });
|
|
61
|
+
let stdout = "", stderr = "", settled = false;
|
|
62
|
+
let ended;
|
|
63
|
+
const settle = (error) => {
|
|
64
|
+
if (settled) return;
|
|
65
|
+
settled = true;
|
|
66
|
+
clearTimeout(timer);
|
|
67
|
+
for (const stream of [child.stdin, child.stdout, child.stderr]) stream?.destroy();
|
|
68
|
+
done(error, stdout, stderr);
|
|
69
|
+
};
|
|
70
|
+
const failure = (what, marks) => Object.assign(new Error(`${what}: ${cmd}${stderr ? `
|
|
71
|
+
${stderr}` : ""}`), { cmd, ...marks });
|
|
72
|
+
const byStatus = ({ code, signal }) => settle(code === 0 ? null : failure("Command failed", { code, killed: false, signal }));
|
|
73
|
+
const cutOff = (what, code) => {
|
|
74
|
+
if (settled) return;
|
|
75
|
+
settle(failure(what, { code, killed: true, signal: "SIGTERM" }));
|
|
76
|
+
if (ended) return;
|
|
77
|
+
const send = (signal) => alone || child.pid === void 0 ? child.kill(signal) : signalGroup(child.pid, signal);
|
|
78
|
+
send("SIGTERM");
|
|
79
|
+
const hard = setTimeout(() => (send("SIGKILL"), child.unref()), options.grace ?? GRACE_MS);
|
|
80
|
+
child.once("exit", () => (alone || child.pid === void 0 || !signalGroup(child.pid, 0)) && clearTimeout(hard));
|
|
81
|
+
};
|
|
82
|
+
const timer = setTimeout(() => ended ? byStatus(ended) : cutOff(`Command timed out after ${options.deadline} ms`, null), options.deadline);
|
|
83
|
+
child.stdout?.setEncoding("utf8").on("data", (chunk) => (stdout += chunk).length > limit && cutOff("stdout maxBuffer length exceeded", "ERR_CHILD_PROCESS_STDIO_MAXBUFFER"));
|
|
84
|
+
child.stderr?.setEncoding("utf8").on("data", (chunk) => (stderr += chunk).length > limit && cutOff("stderr maxBuffer length exceeded", "ERR_CHILD_PROCESS_STDIO_MAXBUFFER"));
|
|
85
|
+
child.on("error", settle);
|
|
86
|
+
child.once("exit", (code, signal) => ended = { code, signal });
|
|
87
|
+
child.once("close", (code, signal) => byStatus({ code, signal }));
|
|
88
|
+
return child;
|
|
89
|
+
}
|
|
50
90
|
function execFileExe(name, args, options, done) {
|
|
51
|
-
const env = options.env ?? process.env;
|
|
91
|
+
const env = options.env ?? process.env, { deadline } = options;
|
|
52
92
|
const start = (again) => {
|
|
53
93
|
let file;
|
|
54
94
|
try {
|
|
@@ -63,9 +103,8 @@ function execFileExe(name, args, options, done) {
|
|
|
63
103
|
);
|
|
64
104
|
return void 0;
|
|
65
105
|
}
|
|
66
|
-
|
|
67
|
-
if (error &&
|
|
68
|
-
error.code === "ENOENT" && again) {
|
|
106
|
+
const finish = (error, stdout, stderr) => {
|
|
107
|
+
if (error && error.code === "ENOENT" && again) {
|
|
69
108
|
forgetExe(name);
|
|
70
109
|
let next;
|
|
71
110
|
try {
|
|
@@ -81,7 +120,8 @@ function execFileExe(name, args, options, done) {
|
|
|
81
120
|
if (next !== file) return void start(false);
|
|
82
121
|
}
|
|
83
122
|
done(error, String(stdout), String(stderr));
|
|
84
|
-
}
|
|
123
|
+
};
|
|
124
|
+
return deadline === void 0 ? execFile(file, args, options, finish) : execFileByDeadline(file, args, { ...options, deadline }, finish);
|
|
85
125
|
};
|
|
86
126
|
return start(true);
|
|
87
127
|
}
|
|
@@ -132,7 +172,7 @@ var TTL_MS = 10 * 6e4;
|
|
|
132
172
|
var START_MS = 3e4;
|
|
133
173
|
var START_ATTEMPTS = 20;
|
|
134
174
|
var herdrRun = (args, timeoutMs = 5e3) => new Promise((resolve4, reject) => {
|
|
135
|
-
execFileExe(process.env.HERDR_BIN_PATH || "herdr", args, {
|
|
175
|
+
execFileExe(process.env.HERDR_BIN_PATH || "herdr", args, { deadline: timeoutMs }, (error, stdout, stderr) => {
|
|
136
176
|
if (error) reject(Object.assign(new Error(`herdr ${args.join(" ")} failed: ${stderr.trim() || error.message}`), { stderr: stderr.trim(), code: error.code, killed: error.killed === true, signal: error.signal ?? void 0 }));
|
|
137
177
|
else resolve4(stdout);
|
|
138
178
|
});
|
|
@@ -179,14 +219,16 @@ async function panes(run4, workspace) {
|
|
|
179
219
|
return (await result(run4, ["pane", "list", ...workspace ? ["--workspace", workspace] : []])).panes;
|
|
180
220
|
}
|
|
181
221
|
var herdrCall = (socketPath = herdrSocket()) => (method, params, timeoutMs = 5e3) => new Promise((resolve4, reject) => {
|
|
182
|
-
const socket = createConnection(localEndpoint(socketPath))
|
|
222
|
+
const socket = createConnection(localEndpoint(socketPath)), text4 = new StringDecoder("utf8");
|
|
183
223
|
let reply = "";
|
|
184
|
-
const fail = (code, message) => (socket.destroy(), reject(new HerdrError(code, `herdr ${method} failed: ${code} ${message}`.trim())));
|
|
224
|
+
const fail = (code, message) => (clearTimeout(timer), socket.destroy(), reject(new HerdrError(code, `herdr ${method} failed: ${code} ${message}`.trim())));
|
|
225
|
+
const timer = setTimeout(() => fail("timeout", `no answer within ${timeoutMs} ms`), timeoutMs);
|
|
185
226
|
socket.on("connect", () => socket.write(`${JSON.stringify({ id: `straw-boss-${Date.now()}`, method, params })}
|
|
186
227
|
`));
|
|
187
228
|
socket.on("data", (chunk) => {
|
|
188
229
|
reply += text4.write(chunk);
|
|
189
230
|
if (!reply.includes("\n")) return;
|
|
231
|
+
clearTimeout(timer);
|
|
190
232
|
socket.destroy();
|
|
191
233
|
try {
|
|
192
234
|
const { result: result2, error } = JSON.parse(reply.split("\n")[0]);
|
|
@@ -196,7 +238,6 @@ var herdrCall = (socketPath = herdrSocket()) => (method, params, timeoutMs = 5e3
|
|
|
196
238
|
fail("bad_frame", reply.slice(0, 200));
|
|
197
239
|
}
|
|
198
240
|
});
|
|
199
|
-
socket.on("timeout", () => fail("timeout", `no answer within ${timeoutMs} ms`));
|
|
200
241
|
socket.on("error", (error) => fail("socket_error", error.message));
|
|
201
242
|
socket.on("close", () => fail("closed", "the connection closed before an answer"));
|
|
202
243
|
});
|
|
@@ -623,7 +664,7 @@ var spawnQuietly = (file, args, { timeout, ...options }, done) => {
|
|
|
623
664
|
return child;
|
|
624
665
|
};
|
|
625
666
|
var laterBy = (ms) => new Promise((done) => setTimeout(done, ms).unref());
|
|
626
|
-
function createStartOf({ platform = process.platform, ps = (pid) => String(execFileSyncExe("ps", ["-o", "lstart=", "-p", String(pid)], { encoding: "utf8", timeout: 2e3, stdio: ["ignore", "pipe", "ignore"], env: { ...process.env, LC_ALL: "C", TZ: "UTC" } })), launch: launch2 = spawnQuietly, now = Date.now, wait = laterBy } = {}) {
|
|
667
|
+
function createStartOf({ platform = process.platform, ps = (pid) => String(execFileSyncExe("ps", ["-o", "lstart=", "-p", String(pid)], { encoding: "utf8", timeout: 2e3, killSignal: "SIGKILL", stdio: ["ignore", "pipe", "ignore"], env: { ...process.env, LC_ALL: "C", TZ: "UTC" } })), launch: launch2 = spawnQuietly, now = Date.now, wait = laterBy } = {}) {
|
|
627
668
|
const known = /* @__PURE__ */ new Map(), asking = /* @__PURE__ */ new Map();
|
|
628
669
|
const valid = (pid) => Number.isSafeInteger(pid) && pid > 0;
|
|
629
670
|
const failedFor = (pid, fails) => pid === process.pid ? MAX_FAIL_MS : Math.min(FIRST_FAIL_MS * 2 ** (fails - 1), MAX_FAIL_MS);
|
|
@@ -1343,7 +1384,7 @@ var OPEN_LINE = "o open one in this computer's browser";
|
|
|
1343
1384
|
var CODE_MS2 = 10 * 6e4;
|
|
1344
1385
|
var MAX_CODES2 = 16;
|
|
1345
1386
|
var FORWARDED = ["x-forwarded-for", "x-forwarded-host", "x-forwarded-proto", "forwarded", "via", "tailscale-headers-info", "tailscale-user-login", "tailscale-user-name", "tailscale-funnel-request"];
|
|
1346
|
-
var tailscale = (args) => new Promise((done, fail) => execFileExe("tailscale", args, {
|
|
1387
|
+
var tailscale = (args) => new Promise((done, fail) => execFileExe("tailscale", args, { deadline: 15e3 }, (error, out, err) => error ? fail(new Error(error.code === "ENOENT" ? "Tailscale is not installed (no tailscale command on PATH)" : `tailscale ${args.join(" ")} failed: ${err.trim() || error.message}`)) : done(out)));
|
|
1347
1388
|
function parse(text4, what) {
|
|
1348
1389
|
try {
|
|
1349
1390
|
return JSON.parse(text4.trim() || "{}") ?? {};
|
|
@@ -2692,7 +2733,7 @@ async function helloOf(endpoint, secret, ms = 2e3) {
|
|
|
2692
2733
|
}
|
|
2693
2734
|
|
|
2694
2735
|
// src/server/client.ts
|
|
2695
|
-
import { spawn } from "node:child_process";
|
|
2736
|
+
import { spawn as spawn2 } from "node:child_process";
|
|
2696
2737
|
import { randomBytes as randomBytes8 } from "node:crypto";
|
|
2697
2738
|
import { existsSync as existsSync5 } from "node:fs";
|
|
2698
2739
|
import { createConnection as createConnection3 } from "node:net";
|
|
@@ -2988,7 +3029,7 @@ var ServerError = class extends Error {
|
|
|
2988
3029
|
var SPAWN_OPTIONS = { detached: true, stdio: "ignore", windowsHide: true };
|
|
2989
3030
|
var spawnDetached = (spec) => {
|
|
2990
3031
|
guardSpawn(spec);
|
|
2991
|
-
const child =
|
|
3032
|
+
const child = spawn2(spec.command, spec.args, { ...spec.options, env: spec.env, cwd: spec.cwd });
|
|
2992
3033
|
child.unref();
|
|
2993
3034
|
noteStarted(child.pid);
|
|
2994
3035
|
child.once("exit", () => forgetStarted(child.pid));
|
|
@@ -5793,7 +5834,7 @@ function enterMarker(dir, name, started, now, deps) {
|
|
|
5793
5834
|
}
|
|
5794
5835
|
|
|
5795
5836
|
// src/server/traingate.ts
|
|
5796
|
-
import { spawn as
|
|
5837
|
+
import { spawn as spawn3 } from "node:child_process";
|
|
5797
5838
|
import { createHash as createHash7, randomBytes as randomBytes11, randomUUID as randomUUID2 } from "node:crypto";
|
|
5798
5839
|
import { chmodSync as chmodSync7, closeSync as closeSync4, constants as constants4, fstatSync as fstatSync4, lstatSync as lstatSync6, mkdirSync as mkdirSync10, openSync as openSync4, readFileSync as readFileSync16, readSync as readSync3, renameSync as renameSync11, unlinkSync as unlinkSync4, writeFileSync as writeFileSync13 } from "node:fs";
|
|
5799
5840
|
import { availableParallelism, homedir as homedir3, loadavg } from "node:os";
|
|
@@ -5834,7 +5875,7 @@ function parsePs(text4) {
|
|
|
5834
5875
|
return table;
|
|
5835
5876
|
}
|
|
5836
5877
|
var run3 = (file, args) => new Promise((resolve4, reject) => {
|
|
5837
|
-
execFileExe(file, args, { encoding: "utf8", maxBuffer: 1 << 26,
|
|
5878
|
+
execFileExe(file, args, { encoding: "utf8", maxBuffer: 1 << 26, deadline: 15e3, env: { ...process.env, LC_ALL: "C", TZ: "UTC" } }, (error, stdout) => error && !stdout ? reject(error) : resolve4(stdout));
|
|
5838
5879
|
});
|
|
5839
5880
|
function exeName(link) {
|
|
5840
5881
|
const name = basename4(link.endsWith(" (deleted)") ? link.slice(0, -" (deleted)".length) : link);
|
|
@@ -5925,7 +5966,7 @@ var KILLS_DIR = "kills";
|
|
|
5925
5966
|
var cwdOfSync = (pid) => {
|
|
5926
5967
|
try {
|
|
5927
5968
|
if (process.platform === "linux") return readlinkSync3(`/proc/${pid}/cwd`).replace(/ \(deleted\)$/, "");
|
|
5928
|
-
return parseLsofCwd(String(execFileSyncExe("lsof", ["-a", "-d", "cwd", "-Fpfn", "-p", String(pid)], { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"], timeout: 5e3 }))).get(pid)?.path;
|
|
5969
|
+
return parseLsofCwd(String(execFileSyncExe("lsof", ["-a", "-d", "cwd", "-Fpfn", "-p", String(pid)], { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"], timeout: 5e3, killSignal: "SIGKILL" }))).get(pid)?.path;
|
|
5929
5970
|
} catch {
|
|
5930
5971
|
return void 0;
|
|
5931
5972
|
}
|
|
@@ -6033,7 +6074,7 @@ var reap = (refs, over = {}) => killSequence(refs, { read: () => readTable(void
|
|
|
6033
6074
|
|
|
6034
6075
|
// src/server/traingate.ts
|
|
6035
6076
|
var BEAT_MS = 3e4;
|
|
6036
|
-
var
|
|
6077
|
+
var GRACE_MS2 = 4e3;
|
|
6037
6078
|
var KILL_WAIT_MS = 500;
|
|
6038
6079
|
var TRY_GRACE_MS = 1e4;
|
|
6039
6080
|
var GATE_MAX_BOARDS = 4096;
|
|
@@ -6180,7 +6221,7 @@ var killGroup = (pid, signal) => signal === 0 ? process.kill(pid, 0) : sendSigna
|
|
|
6180
6221
|
var realSleep = (ms) => new Promise((done) => setTimeout(done, ms));
|
|
6181
6222
|
var lastLine = (text4) => text4.split(/\r?\n/).map((l) => l.trim()).filter(Boolean).at(-1) ?? "";
|
|
6182
6223
|
async function runGate(specFile, deps) {
|
|
6183
|
-
const d = { ...deps, beatMs: deps.beatMs ?? BEAT_MS, graceMs: deps.graceMs ??
|
|
6224
|
+
const d = { ...deps, beatMs: deps.beatMs ?? BEAT_MS, graceMs: deps.graceMs ?? GRACE_MS2, kill: deps.kill ?? killGroup };
|
|
6184
6225
|
const groupAlive = (pid) => {
|
|
6185
6226
|
try {
|
|
6186
6227
|
d.kill(-pid, 0);
|
|
@@ -6299,7 +6340,7 @@ async function runGate(specFile, deps) {
|
|
|
6299
6340
|
}
|
|
6300
6341
|
async function runChild(command, stdout, stderr, beat, deadline) {
|
|
6301
6342
|
const file = "/bin/sh";
|
|
6302
|
-
const child =
|
|
6343
|
+
const child = spawn3(file, ["-c", command], { cwd, detached: true, stdio: ["ignore", stdout, stderr], env: d.env });
|
|
6303
6344
|
const exited = new Promise((done) => {
|
|
6304
6345
|
child.once("exit", (code2, signal) => done({ code: code2, signal }));
|
|
6305
6346
|
child.once("error", (error) => done({ code: null, signal: null, error }));
|
package/dist/server/cli.mjs
CHANGED
|
@@ -86,7 +86,7 @@ import {
|
|
|
86
86
|
writeBoard,
|
|
87
87
|
writeJson,
|
|
88
88
|
writerAlive
|
|
89
|
-
} from "./chunk-
|
|
89
|
+
} from "./chunk-PQZBUOCK.mjs";
|
|
90
90
|
|
|
91
91
|
// src/server/cli.ts
|
|
92
92
|
import { existsSync as existsSync2, realpathSync as realpathSync2 } from "node:fs";
|
|
@@ -294,7 +294,7 @@ function check(flags, io) {
|
|
|
294
294
|
const exists = io.exists ?? ((path) => existsSync(resolve3(cwd, path)));
|
|
295
295
|
const isAncestor = io.isAncestor ?? ((older, newer2) => {
|
|
296
296
|
try {
|
|
297
|
-
execFileSyncExe("git", ["merge-base", "--is-ancestor", older, newer2], { cwd, stdio: "ignore", timeout: 15e3 });
|
|
297
|
+
execFileSyncExe("git", ["merge-base", "--is-ancestor", older, newer2], { cwd, stdio: "ignore", timeout: 15e3, killSignal: "SIGKILL" });
|
|
298
298
|
return true;
|
|
299
299
|
} catch {
|
|
300
300
|
return false;
|