@0xkahi/pi-qol 1.1.0 → 1.1.2
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 +4 -4
- package/src/extensions/workmux/index.ts +41 -14
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@0xkahi/pi-qol",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "quality of life pi extensions",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
|
@@ -45,9 +45,9 @@
|
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@biomejs/biome": "^2.4.15",
|
|
47
47
|
"@changesets/cli": "^2.31.0",
|
|
48
|
-
"@earendil-works/pi-ai": "^0.
|
|
49
|
-
"@earendil-works/pi-coding-agent": "^0.
|
|
50
|
-
"@earendil-works/pi-tui": "^0.
|
|
48
|
+
"@earendil-works/pi-ai": "^0.87.0",
|
|
49
|
+
"@earendil-works/pi-coding-agent": "^0.87.0",
|
|
50
|
+
"@earendil-works/pi-tui": "^0.87.0",
|
|
51
51
|
"@types/bun": "latest",
|
|
52
52
|
"@types/node": "^24.0.0",
|
|
53
53
|
"bun-types": "latest",
|
|
@@ -1,29 +1,56 @@
|
|
|
1
|
-
import type { ExtensionAPI } from '@earendil-works/pi-coding-agent';
|
|
1
|
+
import type { ExtensionAPI, ExtensionContext } from '@earendil-works/pi-coding-agent';
|
|
2
2
|
import type { ConfigLoader } from '../../config-loader';
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
type AssistantState = { stopReason?: string; errorMessage?: string };
|
|
5
|
+
|
|
6
|
+
export function registerWorkmux(pi: ExtensionAPI, deps: { config: ConfigLoader }) {
|
|
7
|
+
let sessionActive = false;
|
|
8
|
+
let writes = Promise.resolve();
|
|
9
|
+
|
|
5
10
|
function setStatus(status: string) {
|
|
6
|
-
|
|
11
|
+
writes = writes.then(async () => {
|
|
12
|
+
await pi.exec('workmux', ['set-window-status', status]).catch(() => {});
|
|
13
|
+
});
|
|
14
|
+
return writes;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function latestAssistantWasAborted(ctx: ExtensionContext) {
|
|
18
|
+
const branch = ctx.sessionManager.getBranch() as Array<{
|
|
19
|
+
type?: string;
|
|
20
|
+
message?: AssistantState & { role?: string };
|
|
21
|
+
}>;
|
|
22
|
+
for (let index = branch.length - 1; index >= 0; index--) {
|
|
23
|
+
const entry = branch[index];
|
|
24
|
+
if (entry?.type !== 'message' || entry.message?.role !== 'assistant') continue;
|
|
25
|
+
return (
|
|
26
|
+
entry.message.stopReason === 'aborted' ||
|
|
27
|
+
(entry.message.stopReason === 'error' && /\boperation was aborted\b/i.test(entry.message.errorMessage ?? ''))
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
return false;
|
|
7
31
|
}
|
|
8
32
|
|
|
9
33
|
pi.on('session_start', async () => {
|
|
10
|
-
|
|
34
|
+
sessionActive = false;
|
|
35
|
+
await writes;
|
|
36
|
+
if (!deps.config.isEnabled('workmux')) return;
|
|
37
|
+
await pi.exec('workmux', ['register-agent']).catch(() => {});
|
|
38
|
+
sessionActive = true;
|
|
11
39
|
});
|
|
12
40
|
|
|
13
41
|
pi.on('agent_start', async () => {
|
|
14
|
-
|
|
42
|
+
if (!sessionActive) return;
|
|
43
|
+
await setStatus('working');
|
|
15
44
|
});
|
|
16
45
|
|
|
17
|
-
pi.on('
|
|
18
|
-
|
|
46
|
+
pi.on('agent_settled', async (_event, ctx) => {
|
|
47
|
+
if (!sessionActive) return;
|
|
48
|
+
if (latestAssistantWasAborted(ctx)) return;
|
|
49
|
+
await setStatus('done');
|
|
19
50
|
});
|
|
20
|
-
}
|
|
21
51
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
if (registered || !deps.config.isEnabled('workmux')) return;
|
|
26
|
-
activateWorkmux(pi);
|
|
27
|
-
registered = true;
|
|
52
|
+
pi.on('session_shutdown', async () => {
|
|
53
|
+
sessionActive = false;
|
|
54
|
+
await writes;
|
|
28
55
|
});
|
|
29
56
|
}
|