@aliou/pi-processes 0.8.0 → 0.9.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/package.json +6 -6
- package/src/hooks/process-end.ts +3 -1
- package/src/hooks/process-watch.ts +3 -1
- package/src/hooks/utils.ts +23 -0
- package/src/hooks/widget/setup.ts +20 -13
- package/src/tools/index.ts +7 -11
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aliou/pi-processes",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"private": false,
|
|
@@ -36,18 +36,18 @@
|
|
|
36
36
|
"@aliou/pi-utils-settings": "^0.10.0",
|
|
37
37
|
"@aliou/pi-utils-ui": "^0.1.0",
|
|
38
38
|
"@aliou/sh": "^0.1.0",
|
|
39
|
-
"
|
|
39
|
+
"typebox": "^1.0.0"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
|
-
"@mariozechner/pi-coding-agent": "0.
|
|
43
|
-
"@mariozechner/pi-tui": "0.
|
|
42
|
+
"@mariozechner/pi-coding-agent": "0.72.1",
|
|
43
|
+
"@mariozechner/pi-tui": "0.72.1"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@aliou/biome-plugins": "^0.3.2",
|
|
47
47
|
"@biomejs/biome": "^2.3.13",
|
|
48
48
|
"@changesets/cli": "^2.27.11",
|
|
49
|
-
"@mariozechner/pi-ai": "0.
|
|
50
|
-
"@mariozechner/pi-coding-agent": "0.
|
|
49
|
+
"@mariozechner/pi-ai": "0.72.1",
|
|
50
|
+
"@mariozechner/pi-coding-agent": "0.72.1",
|
|
51
51
|
"@types/node": "^25.0.10",
|
|
52
52
|
"husky": "^9.1.7",
|
|
53
53
|
"typescript": "^5.9.3",
|
package/src/hooks/process-end.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
|
|
|
2
2
|
import { MESSAGE_TYPE_PROCESS_UPDATE, type ProcessInfo } from "../constants";
|
|
3
3
|
import type { ProcessManager } from "../manager";
|
|
4
4
|
import { formatRuntime } from "../utils";
|
|
5
|
+
import { safeSendMessage } from "./utils";
|
|
5
6
|
|
|
6
7
|
interface ProcessUpdateDetails {
|
|
7
8
|
kind: "lifecycle";
|
|
@@ -54,7 +55,8 @@ export function setupProcessEndHook(pi: ExtensionAPI, manager: ProcessManager) {
|
|
|
54
55
|
runtime,
|
|
55
56
|
};
|
|
56
57
|
|
|
57
|
-
|
|
58
|
+
safeSendMessage(
|
|
59
|
+
pi,
|
|
58
60
|
{
|
|
59
61
|
customType: MESSAGE_TYPE_PROCESS_UPDATE,
|
|
60
62
|
content: message,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
|
|
2
2
|
import { MESSAGE_TYPE_PROCESS_UPDATE } from "../constants";
|
|
3
3
|
import type { ProcessManager } from "../manager";
|
|
4
|
+
import { safeSendMessage } from "./utils";
|
|
4
5
|
|
|
5
6
|
interface ProcessWatchUpdateDetails {
|
|
6
7
|
kind: "watch_matched";
|
|
@@ -70,7 +71,8 @@ export function setupProcessWatchHook(
|
|
|
70
71
|
}
|
|
71
72
|
}
|
|
72
73
|
|
|
73
|
-
|
|
74
|
+
safeSendMessage(
|
|
75
|
+
pi,
|
|
74
76
|
{
|
|
75
77
|
customType: MESSAGE_TYPE_PROCESS_UPDATE,
|
|
76
78
|
content: message,
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Send a message via pi, swallowing stale-context errors.
|
|
5
|
+
*
|
|
6
|
+
* After /new, /resume, or /fork, the pi proxy is invalidated and all
|
|
7
|
+
* method calls throw. This wrapper catches that specific error so the
|
|
8
|
+
* extension doesn't crash — the event is simply lost for the old session.
|
|
9
|
+
*/
|
|
10
|
+
export function safeSendMessage(
|
|
11
|
+
pi: ExtensionAPI,
|
|
12
|
+
message: Parameters<ExtensionAPI["sendMessage"]>[0],
|
|
13
|
+
options?: Parameters<ExtensionAPI["sendMessage"]>[1],
|
|
14
|
+
): void {
|
|
15
|
+
try {
|
|
16
|
+
pi.sendMessage(message, options);
|
|
17
|
+
} catch (err: unknown) {
|
|
18
|
+
if (err instanceof Error && err.message.includes("stale")) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
throw err;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -19,7 +19,7 @@ export function setupProcessWidget(
|
|
|
19
19
|
manager: ProcessManager,
|
|
20
20
|
config: ResolvedProcessesConfig,
|
|
21
21
|
) {
|
|
22
|
-
let
|
|
22
|
+
let activeCtx: ExtensionContext | null = null;
|
|
23
23
|
let logDockComponent: LogDockComponent | null = null;
|
|
24
24
|
let logDockComponentTui: { requestRender(): void } | null = null;
|
|
25
25
|
|
|
@@ -30,30 +30,26 @@ export function setupProcessWidget(
|
|
|
30
30
|
};
|
|
31
31
|
|
|
32
32
|
function updateWidget() {
|
|
33
|
-
if (!
|
|
33
|
+
if (!activeCtx?.hasUI) return;
|
|
34
34
|
|
|
35
35
|
if (!configLoader.getConfig().widget.showStatusWidget) {
|
|
36
|
-
|
|
36
|
+
activeCtx.ui.setWidget(STATUS_WIDGET_ID, undefined);
|
|
37
37
|
} else {
|
|
38
38
|
const processes = manager.list();
|
|
39
39
|
const maxWidth = process.stdout.columns || 120;
|
|
40
|
-
const lines = renderStatusWidget(
|
|
41
|
-
processes,
|
|
42
|
-
latestContext.ui.theme,
|
|
43
|
-
maxWidth,
|
|
44
|
-
);
|
|
40
|
+
const lines = renderStatusWidget(processes, activeCtx.ui.theme, maxWidth);
|
|
45
41
|
|
|
46
42
|
if (lines.length === 0) {
|
|
47
|
-
|
|
43
|
+
activeCtx.ui.setWidget(STATUS_WIDGET_ID, undefined);
|
|
48
44
|
} else {
|
|
49
|
-
|
|
45
|
+
activeCtx.ui.setWidget(STATUS_WIDGET_ID, lines, {
|
|
50
46
|
placement: "belowEditor",
|
|
51
47
|
});
|
|
52
48
|
}
|
|
53
49
|
}
|
|
54
50
|
|
|
55
51
|
if (dockState.visibility === "hidden") {
|
|
56
|
-
|
|
52
|
+
activeCtx.ui.setWidget(LOG_DOCK_WIDGET_ID, undefined);
|
|
57
53
|
if (logDockComponent) {
|
|
58
54
|
logDockComponent.dispose();
|
|
59
55
|
logDockComponent = null;
|
|
@@ -72,7 +68,7 @@ export function setupProcessWidget(
|
|
|
72
68
|
dockHeight: height,
|
|
73
69
|
});
|
|
74
70
|
} else {
|
|
75
|
-
const ctx =
|
|
71
|
+
const ctx = activeCtx;
|
|
76
72
|
ctx.ui.setWidget(
|
|
77
73
|
LOG_DOCK_WIDGET_ID,
|
|
78
74
|
(tui: { requestRender(): void }, theme: typeof ctx.ui.theme) => {
|
|
@@ -152,9 +148,20 @@ export function setupProcessWidget(
|
|
|
152
148
|
logDockComponent = null;
|
|
153
149
|
logDockComponentTui = null;
|
|
154
150
|
}
|
|
155
|
-
|
|
151
|
+
activeCtx = ctx;
|
|
156
152
|
updateWidget();
|
|
157
153
|
});
|
|
158
154
|
|
|
155
|
+
pi.on("session_shutdown", async (_event, ctx) => {
|
|
156
|
+
activeCtx = null;
|
|
157
|
+
if (logDockComponent) {
|
|
158
|
+
logDockComponent.dispose();
|
|
159
|
+
logDockComponent = null;
|
|
160
|
+
logDockComponentTui = null;
|
|
161
|
+
}
|
|
162
|
+
ctx.ui.setWidget(STATUS_WIDGET_ID, undefined);
|
|
163
|
+
ctx.ui.setWidget(LOG_DOCK_WIDGET_ID, undefined);
|
|
164
|
+
});
|
|
165
|
+
|
|
159
166
|
return { update: updateWidget, dockActions };
|
|
160
167
|
}
|
package/src/tools/index.ts
CHANGED
|
@@ -7,7 +7,7 @@ import type {
|
|
|
7
7
|
ToolRenderResultOptions,
|
|
8
8
|
} from "@mariozechner/pi-coding-agent";
|
|
9
9
|
import { Text } from "@mariozechner/pi-tui";
|
|
10
|
-
import { type Static, Type } from "
|
|
10
|
+
import { type Static, Type } from "typebox";
|
|
11
11
|
import type { ProcessesDetails } from "../constants";
|
|
12
12
|
import type { ProcessManager } from "../manager";
|
|
13
13
|
import { executeAction, renderActionCall, renderActionResult } from "./actions";
|
|
@@ -75,16 +75,12 @@ const ProcessesParams = Type.Object({
|
|
|
75
75
|
"Get a turn to react when process is killed by external signal (default: false). Note: killing via tool never triggers a turn.",
|
|
76
76
|
}),
|
|
77
77
|
),
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}),
|
|
85
|
-
),
|
|
86
|
-
}
|
|
87
|
-
: {}),
|
|
78
|
+
preview: Type.Optional(
|
|
79
|
+
StringEnum(["start", "list", "output", "logs", "error"] as const, {
|
|
80
|
+
description:
|
|
81
|
+
"For action=debug_preview only: which rendered result variant to preview (default: start)",
|
|
82
|
+
}),
|
|
83
|
+
),
|
|
88
84
|
logWatches: Type.Optional(
|
|
89
85
|
Type.Array(
|
|
90
86
|
Type.Object(
|