@trama-dev/runtime 0.2.2 → 0.3.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/dist/tools.js CHANGED
@@ -2,8 +2,8 @@ import { spawn } from "child_process";
2
2
  import { readFileSync, writeFileSync, mkdirSync } from "fs";
3
3
  import { resolve, dirname } from "path";
4
4
  import { guardPath } from "./path-guard.js";
5
- import { signalGroup, superviseChild } from "./child-process.js";
6
- import { untilSettled } from "./lifetime.js";
5
+ import { signalGroup, stopGroups, superviseChild } from "./child-process.js";
6
+ import { stopWithThisProcess } from "./lifetime.js";
7
7
  const MAX_FETCH_BODY = 10 * 1024 * 1024; // 10 MB
8
8
  const DEFAULT_SHELL_TIMEOUT = 30_000;
9
9
  const GROUP_SWEEP_MS = 250;
@@ -21,9 +21,11 @@ export function createTools(projectDir, signal) {
21
21
  groups.get(pgid)?.forget();
22
22
  groups.delete(pgid);
23
23
  };
24
- // Shell commands must not see the bridge's address or the init file (which
25
- // holds its secret). A top-level runner has neither in its environment, but
26
- // a runner inside a program — a session's creator — inherits both.
24
+ // Shell commands run here do not get the bridge's address or the init file
25
+ // (which holds its secret). A top-level runner has neither in its
26
+ // environment, but a runner inside a program — a session's creator —
27
+ // inherits both. (This covers tools.shell only: what the agent backend runs
28
+ // on its own takes its environment from this process.)
27
29
  const { TRAMA_PORT: _port, TRAMA_INIT: _init, ...shellEnv } = process.env;
28
30
  const stopSweeping = () => {
29
31
  if (sweeper)
@@ -47,7 +49,7 @@ export function createTools(projectDir, signal) {
47
49
  const markShellExited = (pgid) => {
48
50
  const group = groups.get(pgid);
49
51
  if (!group)
50
- return; // already killed by killActiveShells
52
+ return; // already stopped by stopActiveShells
51
53
  group.shellExited = true;
52
54
  if (!sweeper) {
53
55
  sweeper = setInterval(sweep, GROUP_SWEEP_MS);
@@ -55,11 +57,11 @@ export function createTools(projectDir, signal) {
55
57
  }
56
58
  };
57
59
  return {
58
- killActiveShells() {
59
- for (const pgid of [...groups.keys()]) {
60
- signalGroup(pgid, "SIGKILL");
60
+ async stopActiveShells() {
61
+ const pgids = [...groups.keys()];
62
+ await stopGroups(pgids);
63
+ for (const pgid of pgids)
61
64
  untrack(pgid);
62
- }
63
65
  stopSweeping();
64
66
  },
65
67
  async read(path) {
@@ -88,7 +90,7 @@ export function createTools(projectDir, signal) {
88
90
  });
89
91
  const pgid = child.pid;
90
92
  if (pgid) {
91
- groups.set(pgid, { shellExited: false, forget: untilSettled(() => signalGroup(pgid, "SIGKILL")) });
93
+ groups.set(pgid, { shellExited: false, forget: stopWithThisProcess(pgid) });
92
94
  }
93
95
  try {
94
96
  const exit = await superviseChild(child, { timeout: options.timeout ?? DEFAULT_SHELL_TIMEOUT });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trama-dev/runtime",
3
- "version": "0.2.2",
3
+ "version": "0.3.0",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {