@aliou/pi-processes 0.2.2 → 0.3.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.
@@ -37,11 +37,13 @@ export function setupProcessEndHook(pi: ExtensionAPI, manager: ProcessManager) {
37
37
 
38
38
  const info: ProcessInfo = event.info;
39
39
 
40
- // Check notification preferences
41
- const shouldNotify =
42
- (info.status === "killed" && info.notifyOnKill) ||
43
- (info.status === "exited" && info.success && info.notifyOnSuccess) ||
44
- (info.status === "exited" && !info.success && info.notifyOnFailure);
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
- // Only send message to agent if notification preferences allow
69
- if (shouldNotify) {
70
- const details: ProcessUpdateDetails = {
71
- processId: info.id,
72
- processName: info.name,
73
- command: info.command,
74
- status: info.status as "exited" | "killed",
75
- exitCode: info.exitCode,
76
- success: info.success ?? false,
77
- runtime,
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
- pi.sendMessage(
81
- {
82
- customType: MESSAGE_TYPE_PROCESS_UPDATE,
83
- content: message,
84
- display: true,
85
- details,
86
- },
87
- { triggerTurn: false },
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
- notifyOnSuccess: options?.notifyOnSuccess ?? false,
152
- notifyOnFailure: options?.notifyOnFailure ?? true,
153
- notifyOnKill: options?.notifyOnKill ?? false,
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
- notifyOnSuccess: false,
310
- notifyOnFailure: true,
311
- notifyOnKill: false,
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.notifyOnKill = false;
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
- notifyOnSuccess: managed.notifyOnSuccess,
472
- notifyOnFailure: managed.notifyOnFailure,
473
- notifyOnKill: managed.notifyOnKill,
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.2.2",
3
+ "version": "0.3.1",
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.0",
36
- "@mariozechner/pi-coding-agent": "0.50.0",
37
- "@mariozechner/pi-tui": "0.50.0"
35
+ "@mariozechner/pi-ai": "0.51.0",
36
+ "@mariozechner/pi-coding-agent": "0.51.0",
37
+ "@mariozechner/pi-tui": "0.51.0"
38
38
  }
39
39
  }
@@ -13,9 +13,9 @@ interface ActionParams {
13
13
  command?: string;
14
14
  name?: string;
15
15
  id?: string;
16
- notifyOnSuccess?: boolean;
17
- notifyOnFailure?: boolean;
18
- notifyOnKill?: boolean;
16
+ alertOnSuccess?: boolean;
17
+ alertOnFailure?: boolean;
18
+ alertOnKill?: boolean;
19
19
  }
20
20
 
21
21
  export async function executeAction(
@@ -5,9 +5,9 @@ import type { ProcessManager } from "../../manager";
5
5
  interface StartParams {
6
6
  name?: string;
7
7
  command?: string;
8
- notifyOnSuccess?: boolean;
9
- notifyOnFailure?: boolean;
10
- notifyOnKill?: boolean;
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
- notifyOnSuccess: params.notifyOnSuccess,
41
- notifyOnFailure: params.notifyOnFailure,
42
- notifyOnKill: params.notifyOnKill,
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
- notifyOnSuccess: Type.Optional(
38
+ alertOnSuccess: Type.Optional(
39
39
  Type.Boolean({
40
40
  description:
41
- "Notify when process completes successfully (default: false). Use for builds/tests where you need confirmation.",
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
- notifyOnFailure: Type.Optional(
44
+ alertOnFailure: Type.Optional(
45
45
  Type.Boolean({
46
46
  description:
47
- "Notify when process fails/crashes (default: true). Use to be alerted of unexpected failures.",
47
+ "Get a turn to react when process fails/crashes (default: true). Use to be alerted of unexpected failures.",
48
48
  }),
49
49
  ),
50
- notifyOnKill: Type.Optional(
50
+ alertOnKill: Type.Optional(
51
51
  Type.Boolean({
52
52
  description:
53
- "Notify when process is killed by external signal (default: false). Note: killing via tool never notifies.",
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
- - notifyOnSuccess (default: false): Get notified when process completes successfully
67
- - notifyOnFailure (default: true): Get notified when process crashes/fails
68
- - notifyOnKill (default: false): Get notified if killed by external signal (killing via tool never notifies)
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,11 +74,11 @@ 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 notifications in UI. Notification preferences only control whether YOU (the agent) are informed.`,
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
 
81
- async execute(_toolCallId, params, _onUpdate, ctx) {
81
+ async execute(_toolCallId, params, _signal, _onUpdate, ctx) {
82
82
  return executeAction(params, manager, ctx);
83
83
  },
84
84