showrunner-agent-staging 0.5.138-staging.2221 → 0.5.138-staging.2222
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.
|
@@ -78,11 +78,11 @@ export function claudeBackgroundWorkEnvironment(environment) {
|
|
|
78
78
|
CLAUDE_CODE_EMIT_SESSION_STATE_EVENTS: "1",
|
|
79
79
|
};
|
|
80
80
|
}
|
|
81
|
-
export const claudeBackgroundWorkGuidance = "For a command that may take more than a minute, such as a build, a full test run
|
|
82
|
-
"run it with run_in_background and end your turn with a short note on what is running;
|
|
83
|
-
"your live card, not in the chat. You are woken when it finishes, so post the result then
|
|
84
|
-
"or polling.
|
|
85
|
-
"
|
|
81
|
+
export const claudeBackgroundWorkGuidance = "For a command that may take more than a minute, such as a build, a full test run, a screen recording, a " +
|
|
82
|
+
"render or a server, run it with run_in_background and end your turn with a short note on what is running; " +
|
|
83
|
+
"the note shows on your live card, not in the chat. You are woken when it finishes, so post the result then " +
|
|
84
|
+
"instead of sleeping or polling. Work you detach with nohup, setsid, disown or a trailing & isn't tracked: it " +
|
|
85
|
+
"doesn't keep your card up, can't be stopped from it, and nothing wakes you when it ends. " +
|
|
86
86
|
"Stop a server or job you started by stopping its background task, never with pkill -f or killall: " +
|
|
87
87
|
"a name or pattern also stops the owner's own programs that match it. " +
|
|
88
88
|
"For anything to do later or on a repeat, such as checking again in 20 minutes or every morning, " +
|
|
@@ -27,9 +27,20 @@ export declare function processesStartedBetween(before: readonly EnvironmentProc
|
|
|
27
27
|
* Each exact pid/start-time identity gets SIGTERM, then SIGKILL after `graceMilliseconds`.
|
|
28
28
|
* Returns the commands it stopped.
|
|
29
29
|
*/
|
|
30
|
-
export declare function stopCodexThreadProcesses(owned: readonly OwnedProcess[], options?: Partial<ProcessTable>
|
|
30
|
+
export declare function stopCodexThreadProcesses(owned: readonly OwnedProcess[], options?: Partial<ProcessTable> & {
|
|
31
|
+
clock?: {
|
|
32
|
+
now: () => number;
|
|
33
|
+
sleep: (milliseconds: number) => Promise<void>;
|
|
34
|
+
};
|
|
35
|
+
}): Promise<{
|
|
31
36
|
stopped: string[];
|
|
32
37
|
remaining: OwnedProcess[];
|
|
33
38
|
}>;
|
|
34
39
|
/** This user's processes with their environments: `ps -E` on macOS, /proc on Linux. */
|
|
35
40
|
export declare function listProcessEnvironments(): Promise<EnvironmentProcess[]>;
|
|
41
|
+
/**
|
|
42
|
+
* Joins `ps -E` output with a `ps` listing of the same processes without environments, by pid and
|
|
43
|
+
* start time. The two listings are taken separately, so a process only the first one saw is kept, named
|
|
44
|
+
* by its pid.
|
|
45
|
+
*/
|
|
46
|
+
export declare function parseMacProcessListings(withEnvironment: string, withoutEnvironment: string): EnvironmentProcess[];
|
|
@@ -23,6 +23,7 @@ export function processesStartedBetween(before, after) {
|
|
|
23
23
|
* Returns the commands it stopped.
|
|
24
24
|
*/
|
|
25
25
|
export async function stopCodexThreadProcesses(owned, options = {}) {
|
|
26
|
+
const clock = options.clock ?? { now: () => Date.now(), sleep: (milliseconds) => new Promise(resolve => setTimeout(resolve, milliseconds)) };
|
|
26
27
|
const kill = options.kill ?? ((pid, signal) => { process.kill(pid, signal); });
|
|
27
28
|
const identities = new Set(owned.map(candidate => `${candidate.pid}:${candidate.startTime}`));
|
|
28
29
|
const started = (await (options.list ?? listProcessEnvironments)())
|
|
@@ -41,15 +42,22 @@ export async function stopCodexThreadProcesses(owned, options = {}) {
|
|
|
41
42
|
signal(target, "SIGTERM");
|
|
42
43
|
const graceMilliseconds = options.graceMilliseconds ?? 2_000;
|
|
43
44
|
if (graceMilliseconds > 0)
|
|
44
|
-
await
|
|
45
|
+
await clock.sleep(graceMilliseconds);
|
|
45
46
|
const remaining = (await (options.list ?? listProcessEnvironments)())
|
|
46
47
|
.filter(candidate => identities.has(`${candidate.pid}:${candidate.startTime}`));
|
|
47
48
|
for (const target of remaining)
|
|
48
49
|
signal(target, "SIGKILL");
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
// A killed process can still be listed until its parent reaps it, so survivors are counted once that
|
|
51
|
+
// has had the grace period to happen.
|
|
52
|
+
const deadline = clock.now() + graceMilliseconds;
|
|
53
|
+
for (;;) {
|
|
54
|
+
const surviving = (await (options.list ?? listProcessEnvironments)())
|
|
55
|
+
.filter(candidate => identities.has(`${candidate.pid}:${candidate.startTime}`))
|
|
56
|
+
.map(({ pid, startTime, command }) => ({ pid, startTime, command }));
|
|
57
|
+
if (surviving.length === 0 || clock.now() >= deadline)
|
|
58
|
+
return { stopped: started.map(target => target.command), remaining: surviving };
|
|
59
|
+
await clock.sleep(50);
|
|
60
|
+
}
|
|
53
61
|
}
|
|
54
62
|
/** This user's processes with their environments: `ps -E` on macOS, /proc on Linux. */
|
|
55
63
|
export async function listProcessEnvironments() {
|
|
@@ -57,13 +65,31 @@ export async function listProcessEnvironments() {
|
|
|
57
65
|
return listLinuxProcessEnvironments();
|
|
58
66
|
if (process.platform !== "darwin" || process.getuid === undefined)
|
|
59
67
|
return [];
|
|
60
|
-
const
|
|
61
|
-
|
|
68
|
+
const user = String(process.getuid());
|
|
69
|
+
// `ps -E` prints the environment after the command line, on the same line, so the command line
|
|
70
|
+
// itself comes from a listing without it: a command's name never carries a secret from its environment.
|
|
71
|
+
const [withEnvironment, withoutEnvironment] = await Promise.all([
|
|
72
|
+
run("ps", ["-E", "-ww", "-U", user, "-o", "pid=,pgid=,lstart=,command="]),
|
|
73
|
+
run("ps", ["-ww", "-U", user, "-o", "pid=,lstart=,command="]),
|
|
74
|
+
]);
|
|
75
|
+
return parseMacProcessListings(withEnvironment, withoutEnvironment);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Joins `ps -E` output with a `ps` listing of the same processes without environments, by pid and
|
|
79
|
+
* start time. The two listings are taken separately, so a process only the first one saw is kept, named
|
|
80
|
+
* by its pid.
|
|
81
|
+
*/
|
|
82
|
+
export function parseMacProcessListings(withEnvironment, withoutEnvironment) {
|
|
83
|
+
const commands = new Map(withoutEnvironment.split("\n").flatMap((line) => {
|
|
84
|
+
const match = /^\s*(\d+)\s+(.{24})\s+(.*)$/u.exec(line);
|
|
85
|
+
return match === null ? [] : [[`${match[1]}:${match[2]}`, match[3] ?? ""]];
|
|
86
|
+
}));
|
|
87
|
+
return withEnvironment.split("\n").flatMap((line) => {
|
|
62
88
|
const match = /^\s*(\d+)\s+(\d+)\s+(.{24})\s+(.*)$/u.exec(line);
|
|
63
89
|
if (match === null)
|
|
64
90
|
return [];
|
|
65
|
-
|
|
66
|
-
return [{ pid: Number(match[1]), pgid: Number(match[2]), startTime: match[3] ?? "", command:
|
|
91
|
+
const command = commands.get(`${match[1]}:${match[3]}`) ?? `process ${match[1]}`;
|
|
92
|
+
return [{ pid: Number(match[1]), pgid: Number(match[2]), startTime: match[3] ?? "", command: command.slice(0, 200), environment: match[4] ?? "" }];
|
|
67
93
|
});
|
|
68
94
|
}
|
|
69
95
|
async function listLinuxProcessEnvironments() {
|