@souhaithub/shes 0.1.0 → 0.1.1

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.
Files changed (2) hide show
  1. package/dist/shes.mjs +78 -10
  2. package/package.json +1 -1
package/dist/shes.mjs CHANGED
@@ -21358,6 +21358,22 @@ var init_paths = __esm({
21358
21358
 
21359
21359
  // ../core/dist/exec.js
21360
21360
  import { spawn } from "node:child_process";
21361
+ function hookProcessExit() {
21362
+ if (hooked)
21363
+ return;
21364
+ hooked = true;
21365
+ process.on("exit", () => signalGroups("SIGKILL"));
21366
+ for (const sig2 of ["SIGINT", "SIGTERM", "SIGHUP"]) {
21367
+ const onSignal = () => {
21368
+ signalGroups(sig2);
21369
+ if (process.listenerCount(sig2) === 1) {
21370
+ process.removeListener(sig2, onSignal);
21371
+ process.kill(process.pid, sig2);
21372
+ }
21373
+ };
21374
+ process.on(sig2, onSignal);
21375
+ }
21376
+ }
21361
21377
  function runCommand(spec) {
21362
21378
  const timeoutMs = spec.timeoutMs ?? 10 * 60 * 1e3;
21363
21379
  const max = spec.maxOutputBytes ?? 2 * 1024 * 1024;
@@ -21376,12 +21392,28 @@ function runCommand(spec) {
21376
21392
  cwd: spec.cwd,
21377
21393
  env,
21378
21394
  shell: false,
21379
- stdio: ["ignore", "pipe", "pipe"]
21395
+ stdio: ["ignore", "pipe", "pipe"],
21396
+ detached: GROUPS
21380
21397
  });
21381
21398
  } catch (e) {
21382
21399
  reject(new ShesError("EXTERNAL_COMMAND_FAILED", `Failed to start ${spec.command}`, { cause: e }));
21383
21400
  return;
21384
21401
  }
21402
+ const proc = child;
21403
+ const pid = proc.pid;
21404
+ if (GROUPS && pid) {
21405
+ hookProcessExit();
21406
+ liveGroups.add(pid);
21407
+ }
21408
+ const kill = (sig2) => {
21409
+ try {
21410
+ if (GROUPS && pid)
21411
+ process.kill(-pid, sig2);
21412
+ else
21413
+ proc.kill(sig2);
21414
+ } catch {
21415
+ }
21416
+ };
21385
21417
  let stdout = "";
21386
21418
  let stderr = "";
21387
21419
  let truncated = false;
@@ -21402,17 +21434,29 @@ function runCommand(spec) {
21402
21434
  child.stderr.on("data", (c2) => stderr = append(stderr, c2));
21403
21435
  const timer = setTimeout(() => {
21404
21436
  timedOut = true;
21405
- child.kill("SIGTERM");
21406
- setTimeout(() => child.kill("SIGKILL"), 5e3).unref();
21437
+ kill("SIGTERM");
21438
+ setTimeout(() => kill("SIGKILL"), 5e3).unref();
21407
21439
  }, timeoutMs);
21440
+ child.on("exit", () => {
21441
+ if (!timedOut)
21442
+ return;
21443
+ setTimeout(() => {
21444
+ proc.stdout.destroy();
21445
+ proc.stderr.destroy();
21446
+ }, 2e3).unref();
21447
+ });
21408
21448
  child.on("error", (e) => {
21409
21449
  clearTimeout(timer);
21450
+ if (pid)
21451
+ liveGroups.delete(pid);
21410
21452
  reject(new ShesError("EXTERNAL_COMMAND_FAILED", `Failed to run ${spec.command}: ${e.message}`, {
21411
21453
  cause: e
21412
21454
  }));
21413
21455
  });
21414
21456
  child.on("close", (code, signal) => {
21415
21457
  clearTimeout(timer);
21458
+ if (pid)
21459
+ liveGroups.delete(pid);
21416
21460
  resolve({
21417
21461
  command: spec.command,
21418
21462
  args: spec.args,
@@ -21445,12 +21489,23 @@ async function which(binary) {
21445
21489
  }
21446
21490
  return void 0;
21447
21491
  }
21448
- var STRIPPED_ENV;
21492
+ var STRIPPED_ENV, GROUPS, liveGroups, hooked, signalGroups;
21449
21493
  var init_exec = __esm({
21450
21494
  "../core/dist/exec.js"() {
21451
21495
  "use strict";
21452
21496
  init_dist();
21453
21497
  STRIPPED_ENV = /^(SHES_(API_TOKEN|RUNNER_SECRET|SIGNING_KEY)|GOOGLE_APPLICATION_CREDENTIALS)$/;
21498
+ GROUPS = process.platform !== "win32";
21499
+ liveGroups = /* @__PURE__ */ new Set();
21500
+ hooked = false;
21501
+ signalGroups = (sig2) => {
21502
+ for (const pid of liveGroups) {
21503
+ try {
21504
+ process.kill(-pid, sig2);
21505
+ } catch {
21506
+ }
21507
+ }
21508
+ };
21454
21509
  }
21455
21510
  });
21456
21511
 
@@ -24393,8 +24448,8 @@ var init_capabilities = __esm({
24393
24448
  cap("core.file-ops", "Planned file operations with diffs, backups and managed blocks", "tested", [], ["packages/core/src/core.test.ts"]);
24394
24449
  cap("core.exec", "Shell-free command runner with timeout and output caps", "tested", [], ["packages/core/src/core.test.ts"]);
24395
24450
  cap("core.path-scope", "Project path scoping incl. symlink escape protection", "tested", [], ["packages/core/src/core.test.ts"]);
24396
- cap("cli", "shes CLI (bundled, installable from tarball)", "verified", [
24397
- "Prepared for npm as @souhaithub/shes (proprietary license, third-party notices bundled) but not yet published; install from a tarball until then.",
24451
+ cap("cli", "shes CLI (bundled; installable from npm or a tarball)", "verified", [
24452
+ "Published on npm as @souhaithub/shes (proprietary license, third-party notices bundled). Releases are staged on npm and need a maintainer's approval.",
24398
24453
  "`shes update` checks the npm registry's latest version; it does not install updates."
24399
24454
  ], ["packages/cli/src/cli.test.ts", "packages/cli/src/update.test.ts", E2E]);
24400
24455
  cap("mcp.server", "SHES MCP server (stdio, 10 initial tools, capabilities resource)", "verified", [], ["packages/mcp-server/src/server.test.ts", E2E]);
@@ -24467,7 +24522,7 @@ var init_capabilities = __esm({
24467
24522
  RUN7
24468
24523
  ]);
24469
24524
  cap("runner.local", "Local runner (`shes runner pair|allow|policy|start|status|stop|revoke`): outbound-only, local project allowlist and job policy, OS sandbox (macOS) with write, credential-read and network restrictions, minimal environment, timeouts, output caps, cancellation, crash recovery, report upload", "verified", [
24470
- "OS sandbox verified on macOS (sandbox-exec). The Linux bubblewrap sandbox is implemented but not tested; without a sandbox, jobs other than diagnostics are refused unless the owner selects best-effort.",
24525
+ "OS sandbox verified on macOS (sandbox-exec) and on Linux with bubblewrap (CI on Ubuntu 24.04 with AppArmor's user-namespace restriction, and Debian as an unprivileged user): writes outside the project, credential reads and network are blocked, and cancelled jobs are killed. Without a sandbox, jobs other than diagnostics are refused unless the owner selects best-effort.",
24471
24526
  "Network restriction allows localhost so test servers work.",
24472
24527
  "Memory/CPU limits are not enforced on local runners (timeouts and output caps are)."
24473
24528
  ], ["services/local-runner/src/runner.test.ts", "tests/e2e/runner-e2e.sh", RUN7]);
@@ -61415,7 +61470,7 @@ init_dist();
61415
61470
  import { existsSync, realpathSync } from "node:fs";
61416
61471
  import path2 from "node:path";
61417
61472
  import { fileURLToPath } from "node:url";
61418
- var VERSION = "0.1.0";
61473
+ var VERSION = "0.1.1";
61419
61474
  function projectRoot(flag) {
61420
61475
  if (flag) {
61421
61476
  if (!existsSync(flag))
@@ -65910,8 +65965,11 @@ function wrapCommand(command, args, s) {
65910
65965
  "/dev",
65911
65966
  "--proc",
65912
65967
  "/proc",
65913
- "--die-with-parent",
65914
- "--new-session"
65968
+ "--die-with-parent"
65969
+ // No --new-session: the runner already starts bwrap detached (its own session, no controlling terminal), and
65970
+ // the job must stay in that process group so cancellation and timeouts can kill it. With --new-session the
65971
+ // job left the group; where --die-with-parent does not take effect (Ubuntu 24.04 with AppArmor's
65972
+ // unprivileged-userns restriction) a cancelled job kept running after bwrap was killed.
65915
65973
  ];
65916
65974
  for (const w of s.writable)
65917
65975
  b.push("--bind", w, w);
@@ -66165,7 +66223,9 @@ function run(command, args, o) {
66165
66223
  let truncated = false;
66166
66224
  let timedOut = false;
66167
66225
  let cancelled = false;
66226
+ let killed = false;
66168
66227
  const kill = () => {
66228
+ killed = true;
66169
66229
  try {
66170
66230
  process.kill(-child.pid, "SIGTERM");
66171
66231
  } catch {
@@ -66202,6 +66262,14 @@ function run(command, args, o) {
66202
66262
  kill();
66203
66263
  };
66204
66264
  o.signal.addEventListener("abort", onAbort, { once: true });
66265
+ child.on("exit", () => {
66266
+ if (!killed)
66267
+ return;
66268
+ setTimeout(() => {
66269
+ child.stdout.destroy();
66270
+ child.stderr.destroy();
66271
+ }, 2e3).unref();
66272
+ });
66205
66273
  child.on("close", (code, sig2) => {
66206
66274
  clearTimeout(timer);
66207
66275
  o.signal.removeEventListener("abort", onAbort);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@souhaithub/shes",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "SHES — Souhait Hub Engineering System CLI and MCP server",
5
5
  "license": "UNLICENSED",
6
6
  "keywords": [