@aliou/pi-processes 0.1.1 → 0.2.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.
- package/README.md +31 -0
- package/commands/index.ts +3 -465
- package/hooks/cleanup.ts +3 -1
- package/hooks/process-end.ts +9 -21
- package/hooks/widget.ts +33 -62
- package/index.ts +8 -0
- package/manager.ts +254 -181
- package/package.json +9 -5
- package/tools/actions/clear.ts +20 -0
- package/tools/actions/index.ts +49 -0
- package/tools/actions/kill.ts +76 -0
- package/tools/actions/list.ts +37 -0
- package/tools/actions/logs.ts +59 -0
- package/tools/actions/output.ts +73 -0
- package/tools/actions/start.ts +55 -0
- package/tools/index.ts +29 -312
- package/constants.ts +0 -2
package/hooks/widget.ts
CHANGED
|
@@ -2,44 +2,35 @@ import type {
|
|
|
2
2
|
ExtensionAPI,
|
|
3
3
|
ExtensionContext,
|
|
4
4
|
} from "@mariozechner/pi-coding-agent";
|
|
5
|
-
import type { ProcessInfo
|
|
5
|
+
import type { ProcessInfo } from "../constants";
|
|
6
|
+
import type { ProcessManager } from "../manager";
|
|
6
7
|
|
|
7
8
|
const WIDGET_ID = "processes-status";
|
|
8
9
|
|
|
9
|
-
function formatRuntime(startTime: number, endTime: number | null): string {
|
|
10
|
-
const end = endTime ?? Date.now();
|
|
11
|
-
const ms = end - startTime;
|
|
12
|
-
const seconds = Math.floor(ms / 1000);
|
|
13
|
-
const minutes = Math.floor(seconds / 60);
|
|
14
|
-
const hours = Math.floor(minutes / 60);
|
|
15
|
-
|
|
16
|
-
if (hours > 0) {
|
|
17
|
-
return `${hours}h${minutes % 60}m`;
|
|
18
|
-
}
|
|
19
|
-
if (minutes > 0) {
|
|
20
|
-
return `${minutes}m${seconds % 60}s`;
|
|
21
|
-
}
|
|
22
|
-
return `${seconds}s`;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
10
|
function formatProcessStatus(
|
|
26
11
|
proc: ProcessInfo,
|
|
27
12
|
theme: ExtensionContext["ui"]["theme"],
|
|
28
13
|
): string {
|
|
29
|
-
const runtime = formatRuntime(proc.startTime, proc.endTime);
|
|
30
14
|
const name =
|
|
31
15
|
proc.name.length > 20 ? `${proc.name.slice(0, 17)}...` : proc.name;
|
|
32
16
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
17
|
+
switch (proc.status) {
|
|
18
|
+
case "running":
|
|
19
|
+
return `${theme.fg("accent", name)} ${theme.fg("dim", "running")}`;
|
|
20
|
+
case "terminating":
|
|
21
|
+
return `${theme.fg("warning", name)} ${theme.fg("dim", "terminating")}`;
|
|
22
|
+
case "terminate_timeout":
|
|
23
|
+
return `${theme.fg("error", name)} ${theme.fg("error", "terminate_timeout")}`;
|
|
24
|
+
case "killed":
|
|
25
|
+
return `${theme.fg("warning", name)} ${theme.fg("dim", "killed")}`;
|
|
26
|
+
case "exited":
|
|
27
|
+
if (proc.success) {
|
|
28
|
+
return `${theme.fg("dim", name)} ${theme.fg("success", "done")}`;
|
|
29
|
+
}
|
|
30
|
+
return `${theme.fg("error", name)} ${theme.fg("error", `exit(${proc.exitCode ?? "?"})`)}`;
|
|
31
|
+
default:
|
|
32
|
+
return `${theme.fg("dim", name)} ${theme.fg("dim", proc.status)}`;
|
|
41
33
|
}
|
|
42
|
-
return `${theme.fg("error", name)} ${theme.fg("error", `exit(${proc.exitCode ?? "?"})`)}`;
|
|
43
34
|
}
|
|
44
35
|
|
|
45
36
|
function renderWidget(
|
|
@@ -50,17 +41,25 @@ function renderWidget(
|
|
|
50
41
|
return [];
|
|
51
42
|
}
|
|
52
43
|
|
|
53
|
-
const
|
|
54
|
-
|
|
44
|
+
const aliveish = processes.filter(
|
|
45
|
+
(p) =>
|
|
46
|
+
p.status === "running" ||
|
|
47
|
+
p.status === "terminating" ||
|
|
48
|
+
p.status === "terminate_timeout",
|
|
49
|
+
);
|
|
50
|
+
const finished = processes.filter(
|
|
51
|
+
(p) =>
|
|
52
|
+
p.status !== "running" &&
|
|
53
|
+
p.status !== "terminating" &&
|
|
54
|
+
p.status !== "terminate_timeout",
|
|
55
|
+
);
|
|
55
56
|
|
|
56
57
|
const parts: string[] = [];
|
|
57
58
|
|
|
58
|
-
|
|
59
|
-
for (const proc of running) {
|
|
59
|
+
for (const proc of aliveish) {
|
|
60
60
|
parts.push(formatProcessStatus(proc, theme));
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
// Show finished processes (most recent first, limit to 3)
|
|
64
63
|
const recentFinished = finished
|
|
65
64
|
.sort((a, b) => (b.endTime ?? 0) - (a.endTime ?? 0))
|
|
66
65
|
.slice(0, 3);
|
|
@@ -69,7 +68,6 @@ function renderWidget(
|
|
|
69
68
|
parts.push(formatProcessStatus(proc, theme));
|
|
70
69
|
}
|
|
71
70
|
|
|
72
|
-
// If there are more finished processes, show count
|
|
73
71
|
const hiddenCount = finished.length - recentFinished.length;
|
|
74
72
|
if (hiddenCount > 0) {
|
|
75
73
|
parts.push(theme.fg("dim", `+${hiddenCount} more`));
|
|
@@ -81,7 +79,6 @@ function renderWidget(
|
|
|
81
79
|
|
|
82
80
|
export function setupProcessWidget(pi: ExtensionAPI, manager: ProcessManager) {
|
|
83
81
|
let latestContext: ExtensionContext | null = null;
|
|
84
|
-
let refreshInterval: ReturnType<typeof setInterval> | null = null;
|
|
85
82
|
|
|
86
83
|
function updateWidget() {
|
|
87
84
|
if (!latestContext?.hasUI) return;
|
|
@@ -98,28 +95,9 @@ export function setupProcessWidget(pi: ExtensionAPI, manager: ProcessManager) {
|
|
|
98
95
|
}
|
|
99
96
|
}
|
|
100
97
|
|
|
101
|
-
function startRefresh() {
|
|
102
|
-
if (refreshInterval) return;
|
|
103
|
-
refreshInterval = setInterval(() => {
|
|
104
|
-
const hasRunning = manager.list().some((p) => p.status === "running");
|
|
105
|
-
if (hasRunning) {
|
|
106
|
-
updateWidget();
|
|
107
|
-
}
|
|
108
|
-
}, 1000);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
function stopRefresh() {
|
|
112
|
-
if (refreshInterval) {
|
|
113
|
-
clearInterval(refreshInterval);
|
|
114
|
-
refreshInterval = null;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
// Capture context and update widget
|
|
119
98
|
pi.on("session_start", async (_event, ctx) => {
|
|
120
99
|
latestContext = ctx;
|
|
121
100
|
updateWidget();
|
|
122
|
-
startRefresh();
|
|
123
101
|
});
|
|
124
102
|
|
|
125
103
|
pi.on("session_switch", async (_event, ctx) => {
|
|
@@ -127,16 +105,9 @@ export function setupProcessWidget(pi: ExtensionAPI, manager: ProcessManager) {
|
|
|
127
105
|
updateWidget();
|
|
128
106
|
});
|
|
129
107
|
|
|
130
|
-
|
|
131
|
-
stopRefresh();
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
// Chain into process end callback
|
|
135
|
-
const originalOnProcessEnd = manager.onProcessEnd;
|
|
136
|
-
manager.onProcessEnd = (info) => {
|
|
137
|
-
originalOnProcessEnd?.call(manager, info);
|
|
108
|
+
manager.onEvent(() => {
|
|
138
109
|
updateWidget();
|
|
139
|
-
};
|
|
110
|
+
});
|
|
140
111
|
|
|
141
112
|
return {
|
|
142
113
|
update: updateWidget,
|
package/index.ts
CHANGED
|
@@ -5,6 +5,14 @@ import { ProcessManager } from "./manager";
|
|
|
5
5
|
import { setupProcessesTools } from "./tools";
|
|
6
6
|
|
|
7
7
|
export default function (pi: ExtensionAPI) {
|
|
8
|
+
if (process.platform === "win32") {
|
|
9
|
+
pi.on("session_start", async (_event, ctx) => {
|
|
10
|
+
if (!ctx.hasUI) return;
|
|
11
|
+
ctx.ui.notify("processes extension not available on Windows", "warning");
|
|
12
|
+
});
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
|
|
8
16
|
const manager = new ProcessManager();
|
|
9
17
|
|
|
10
18
|
setupProcessesHooks(pi, manager);
|