@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/agent-backend.d.ts +18 -0
- package/dist/agent-backend.js +9 -0
- package/dist/agent.d.ts +12 -2
- package/dist/agent.js +23 -6
- package/dist/bridge-client.d.ts +17 -0
- package/dist/bridge-client.js +52 -0
- package/dist/child-process.d.ts +40 -7
- package/dist/child-process.js +180 -25
- package/dist/client.js +2 -39
- package/dist/index.js +12 -11
- package/dist/ipc-server.d.ts +2 -0
- package/dist/ipc-server.js +21 -3
- package/dist/lifetime.d.ts +8 -4
- package/dist/lifetime.js +32 -17
- package/dist/pi-adapter.d.ts +6 -13
- package/dist/pi-adapter.js +9 -32
- package/dist/runner-types.d.ts +9 -7
- package/dist/runner.d.ts +10 -3
- package/dist/runner.js +112 -52
- package/dist/tools.d.ts +2 -2
- package/dist/tools.js +13 -11
- package/package.json +1 -1
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 {
|
|
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
|
|
25
|
-
// holds its secret). A top-level runner has neither in its
|
|
26
|
-
// a runner inside a program — a session's creator —
|
|
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
|
|
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
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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:
|
|
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 });
|