@aliou/pi-processes 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/hooks/process-end.ts +27 -26
- package/manager.ts +10 -10
- package/package.json +4 -4
- package/tools/actions/index.ts +3 -3
- package/tools/actions/start.ts +6 -6
- package/tools/index.ts +10 -10
package/hooks/process-end.ts
CHANGED
|
@@ -37,11 +37,13 @@ export function setupProcessEndHook(pi: ExtensionAPI, manager: ProcessManager) {
|
|
|
37
37
|
|
|
38
38
|
const info: ProcessInfo = event.info;
|
|
39
39
|
|
|
40
|
-
//
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
(info.status === "
|
|
40
|
+
// Determine if the agent should get a turn to react to this process ending.
|
|
41
|
+
// When true, the agent receives the message in its context and can respond
|
|
42
|
+
// (e.g. check results, fix code, restart the process).
|
|
43
|
+
const triggerAgentTurn =
|
|
44
|
+
(info.status === "killed" && info.alertOnKill) ||
|
|
45
|
+
(info.status === "exited" && info.success && info.alertOnSuccess) ||
|
|
46
|
+
(info.status === "exited" && !info.success && info.alertOnFailure);
|
|
45
47
|
|
|
46
48
|
const runtime = formatRuntime(info.startTime, info.endTime);
|
|
47
49
|
|
|
@@ -65,27 +67,26 @@ export function setupProcessEndHook(pi: ExtensionAPI, manager: ProcessManager) {
|
|
|
65
67
|
latestContext.ui.notify(message, level);
|
|
66
68
|
}
|
|
67
69
|
|
|
68
|
-
//
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
70
|
+
// Always send the message so it appears in the conversation history.
|
|
71
|
+
// Only trigger an agent turn when the notification preferences say so.
|
|
72
|
+
const details: ProcessUpdateDetails = {
|
|
73
|
+
processId: info.id,
|
|
74
|
+
processName: info.name,
|
|
75
|
+
command: info.command,
|
|
76
|
+
status: info.status as "exited" | "killed",
|
|
77
|
+
exitCode: info.exitCode,
|
|
78
|
+
success: info.success ?? false,
|
|
79
|
+
runtime,
|
|
80
|
+
};
|
|
79
81
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}
|
|
82
|
+
pi.sendMessage(
|
|
83
|
+
{
|
|
84
|
+
customType: MESSAGE_TYPE_PROCESS_UPDATE,
|
|
85
|
+
content: message,
|
|
86
|
+
display: true,
|
|
87
|
+
details,
|
|
88
|
+
},
|
|
89
|
+
{ triggerTurn: triggerAgentTurn },
|
|
90
|
+
);
|
|
90
91
|
});
|
|
91
92
|
}
|
package/manager.ts
CHANGED
|
@@ -148,9 +148,9 @@ export class ProcessManager {
|
|
|
148
148
|
success: null,
|
|
149
149
|
stdoutFile,
|
|
150
150
|
stderrFile,
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
151
|
+
alertOnSuccess: options?.alertOnSuccess ?? false,
|
|
152
|
+
alertOnFailure: options?.alertOnFailure ?? true,
|
|
153
|
+
alertOnKill: options?.alertOnKill ?? false,
|
|
154
154
|
process: child,
|
|
155
155
|
lastSignalSent: null,
|
|
156
156
|
};
|
|
@@ -306,9 +306,9 @@ export class ProcessManager {
|
|
|
306
306
|
success: false,
|
|
307
307
|
stdoutFile: "",
|
|
308
308
|
stderrFile: "",
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
309
|
+
alertOnSuccess: false,
|
|
310
|
+
alertOnFailure: true,
|
|
311
|
+
alertOnKill: false,
|
|
312
312
|
},
|
|
313
313
|
reason: "not_found",
|
|
314
314
|
};
|
|
@@ -317,7 +317,7 @@ export class ProcessManager {
|
|
|
317
317
|
const signal = opts?.signal ?? "SIGTERM";
|
|
318
318
|
const timeoutMs = opts?.timeoutMs ?? 3000;
|
|
319
319
|
|
|
320
|
-
managed.
|
|
320
|
+
managed.alertOnKill = false;
|
|
321
321
|
|
|
322
322
|
if (!LIVE_STATUSES.has(managed.status)) {
|
|
323
323
|
return { ok: true, info: this.toProcessInfo(managed) };
|
|
@@ -468,9 +468,9 @@ export class ProcessManager {
|
|
|
468
468
|
success: managed.success,
|
|
469
469
|
stdoutFile: managed.stdoutFile,
|
|
470
470
|
stderrFile: managed.stderrFile,
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
471
|
+
alertOnSuccess: managed.alertOnSuccess,
|
|
472
|
+
alertOnFailure: managed.alertOnFailure,
|
|
473
|
+
alertOnKill: managed.alertOnKill,
|
|
474
474
|
};
|
|
475
475
|
}
|
|
476
476
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aliou/pi-processes",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"private": false,
|
|
6
6
|
"keywords": [
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
"@sinclair/typebox": "^0.34.41"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
|
-
"@mariozechner/pi-ai": "0.50.
|
|
36
|
-
"@mariozechner/pi-coding-agent": "0.50.
|
|
37
|
-
"@mariozechner/pi-tui": "0.50.
|
|
35
|
+
"@mariozechner/pi-ai": "0.50.4",
|
|
36
|
+
"@mariozechner/pi-coding-agent": "0.50.4",
|
|
37
|
+
"@mariozechner/pi-tui": "0.50.4"
|
|
38
38
|
}
|
|
39
39
|
}
|
package/tools/actions/index.ts
CHANGED
|
@@ -13,9 +13,9 @@ interface ActionParams {
|
|
|
13
13
|
command?: string;
|
|
14
14
|
name?: string;
|
|
15
15
|
id?: string;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
alertOnSuccess?: boolean;
|
|
17
|
+
alertOnFailure?: boolean;
|
|
18
|
+
alertOnKill?: boolean;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
export async function executeAction(
|
package/tools/actions/start.ts
CHANGED
|
@@ -5,9 +5,9 @@ import type { ProcessManager } from "../../manager";
|
|
|
5
5
|
interface StartParams {
|
|
6
6
|
name?: string;
|
|
7
7
|
command?: string;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
alertOnSuccess?: boolean;
|
|
9
|
+
alertOnFailure?: boolean;
|
|
10
|
+
alertOnKill?: boolean;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export function executeStart(
|
|
@@ -37,9 +37,9 @@ export function executeStart(
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
const proc = manager.start(params.name, params.command, ctx.cwd, {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
alertOnSuccess: params.alertOnSuccess,
|
|
41
|
+
alertOnFailure: params.alertOnFailure,
|
|
42
|
+
alertOnKill: params.alertOnKill,
|
|
43
43
|
});
|
|
44
44
|
|
|
45
45
|
const message = `Started "${proc.name}" (${proc.id}, PID: ${proc.pid})\nLogs: ${proc.stdoutFile}`;
|
package/tools/index.ts
CHANGED
|
@@ -35,22 +35,22 @@ const ProcessesParams = Type.Object({
|
|
|
35
35
|
"Process ID or name to match (required for output/kill/logs). Can be proc_N or friendly name.",
|
|
36
36
|
}),
|
|
37
37
|
),
|
|
38
|
-
|
|
38
|
+
alertOnSuccess: Type.Optional(
|
|
39
39
|
Type.Boolean({
|
|
40
40
|
description:
|
|
41
|
-
"
|
|
41
|
+
"Get a turn to react when process completes successfully (default: false). Use for builds/tests where you need confirmation.",
|
|
42
42
|
}),
|
|
43
43
|
),
|
|
44
|
-
|
|
44
|
+
alertOnFailure: Type.Optional(
|
|
45
45
|
Type.Boolean({
|
|
46
46
|
description:
|
|
47
|
-
"
|
|
47
|
+
"Get a turn to react when process fails/crashes (default: true). Use to be alerted of unexpected failures.",
|
|
48
48
|
}),
|
|
49
49
|
),
|
|
50
|
-
|
|
50
|
+
alertOnKill: Type.Optional(
|
|
51
51
|
Type.Boolean({
|
|
52
52
|
description:
|
|
53
|
-
"
|
|
53
|
+
"Get a turn to react when process is killed by external signal (default: false). Note: killing via tool never triggers a turn.",
|
|
54
54
|
}),
|
|
55
55
|
),
|
|
56
56
|
});
|
|
@@ -63,9 +63,9 @@ export function setupProcessesTools(pi: ExtensionAPI, manager: ProcessManager) {
|
|
|
63
63
|
label: "Processes",
|
|
64
64
|
description: `Manage background processes. Actions:
|
|
65
65
|
- start: Run command in background (requires 'name' and 'command')
|
|
66
|
-
-
|
|
67
|
-
-
|
|
68
|
-
-
|
|
66
|
+
- alertOnSuccess (default: false): Get a turn to react when process completes successfully
|
|
67
|
+
- alertOnFailure (default: true): Get a turn to react when process crashes/fails
|
|
68
|
+
- alertOnKill (default: false): Get a turn to react if killed by external signal (killing via tool never triggers a turn)
|
|
69
69
|
- list: Show all managed processes with their IDs and names
|
|
70
70
|
- output: Get recent stdout/stderr (requires 'id' - can be proc_N or name match)
|
|
71
71
|
- logs: Get log file paths to inspect with read tool (requires 'id')
|
|
@@ -74,7 +74,7 @@ export function setupProcessesTools(pi: ExtensionAPI, manager: ProcessManager) {
|
|
|
74
74
|
|
|
75
75
|
Important: You DON'T need to poll or wait for processes. Notifications arrive automatically based on your preferences. Start processes and continue with other work - you'll be informed if something requires attention.
|
|
76
76
|
|
|
77
|
-
Note: User always sees
|
|
77
|
+
Note: User always sees process updates in the UI. The notify flags control whether YOU (the agent) get a turn to react (e.g. check results, fix code, restart).`,
|
|
78
78
|
|
|
79
79
|
parameters: ProcessesParams,
|
|
80
80
|
|