oira666_pi-subagent 0.7.3 → 0.7.5
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 +6 -2
- package/extension/async-jobs.ts +29 -0
- package/extension/completion.ts +4 -0
- package/extension/interrupt.ts +4 -2
- package/extension/state.ts +1 -0
- package/package.json +11 -10
- package/resume.ts +2 -2
package/README.md
CHANGED
|
@@ -4,7 +4,9 @@ Delegate tasks to agents running in separate Pi processes. Each worker has its o
|
|
|
4
4
|
|
|
5
5
|
Launches return immediately. Completion and worker messages arrive as steering that wakes an idle lead.
|
|
6
6
|
|
|
7
|
-
Requires Pi
|
|
7
|
+
Requires Pi 1.4.0 or newer, using the `@earendil-works` SDK packages. Only the latest npm Pi release is tested.
|
|
8
|
+
|
|
9
|
+
Tested against Pi 1.4.0
|
|
8
10
|
|
|
9
11
|
## Install
|
|
10
12
|
|
|
@@ -171,7 +173,9 @@ npm ci
|
|
|
171
173
|
npm run check
|
|
172
174
|
```
|
|
173
175
|
|
|
174
|
-
|
|
176
|
+
`npm test` first installs the four declared Pi SDK packages at `@latest` with `--save-dev --ignore-scripts`, then typechecks before running tests. `npm run check` uses that same path and also checks formatting and file size. Network access is required, and a newer Pi release can update `package.json` and `package-lock.json`. Keep those changes together.
|
|
177
|
+
|
|
178
|
+
Tests use the real SDK packages installed as development dependencies. SDK/loader integration tests exercise extension loading and argument validation. Terminal rendering tests use test themes, including ANSI styling, width limits and theme invalidation. They do not verify every installed theme or a live interactive terminal. Prompt guidance tests check generated text, not model behavior. No host loader or permissive type shims are needed. Run tests outside a delegated worker environment, or unset inherited `PI_SUBAGENT_*` storage and budget variables first.
|
|
175
179
|
|
|
176
180
|
Source organization:
|
|
177
181
|
|
package/extension/async-jobs.ts
CHANGED
|
@@ -34,6 +34,7 @@ function recordCount(state: ExtensionState, count: number): void {
|
|
|
34
34
|
|
|
35
35
|
/** Pending delivery is work too: a queued message has not started its continuation yet. */
|
|
36
36
|
function emitBackgroundCount(state: ExtensionState): void {
|
|
37
|
+
state.onBackgroundChanged?.();
|
|
37
38
|
if (state.currentDepth > 0) {
|
|
38
39
|
const running = state.backgroundJobs.size + pendingCount(state);
|
|
39
40
|
if (state.latestSessionCtx?.mode === "rpc") {
|
|
@@ -67,6 +68,33 @@ export function releaseCompletionDelivery(state: ExtensionState, token: string,
|
|
|
67
68
|
|
|
68
69
|
/** Register once from registerSessionEvents. Starting an unrelated run must not drain this counter. */
|
|
69
70
|
export function registerAsyncDeliveryEvents(state: ExtensionState): void {
|
|
71
|
+
state.pi.on("agent_before_settle", async (event, ctx) => {
|
|
72
|
+
if (ctx.mode !== "print" && ctx.mode !== "json") return;
|
|
73
|
+
if (event.outcome === "aborted" || event.context.pendingMessages.length > 0) return;
|
|
74
|
+
const generation = state.lifecycleGeneration;
|
|
75
|
+
const signal = ctx.signal;
|
|
76
|
+
while (
|
|
77
|
+
state.sessionActive &&
|
|
78
|
+
generation === state.lifecycleGeneration &&
|
|
79
|
+
!signal?.aborted &&
|
|
80
|
+
(state.backgroundJobs.size > 0 || pendingCount(state) > 0)
|
|
81
|
+
) {
|
|
82
|
+
// Keep Pi's run open until delivery queues a continuation, not until the whole batch finishes.
|
|
83
|
+
let wake: (() => void) | undefined;
|
|
84
|
+
try {
|
|
85
|
+
const queued = await new Promise<boolean>((resolve) => {
|
|
86
|
+
state.onBackgroundChanged = (messageQueued = false) => resolve(messageQueued);
|
|
87
|
+
wake = () => resolve(false);
|
|
88
|
+
signal?.addEventListener("abort", wake, { once: true });
|
|
89
|
+
});
|
|
90
|
+
if (queued) return;
|
|
91
|
+
} finally {
|
|
92
|
+
state.onBackgroundChanged = undefined;
|
|
93
|
+
if (wake) signal?.removeEventListener("abort", wake);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
// Pi drains messages queued by sendMessage before settling, without an extra synthetic prompt.
|
|
97
|
+
});
|
|
70
98
|
state.pi.on("context", (event) => {
|
|
71
99
|
const messages = event.messages.filter(
|
|
72
100
|
(message) =>
|
|
@@ -119,6 +147,7 @@ export function notifyLead(
|
|
|
119
147
|
triggerTurn: true,
|
|
120
148
|
},
|
|
121
149
|
);
|
|
150
|
+
state.onBackgroundChanged?.(true);
|
|
122
151
|
}
|
|
123
152
|
|
|
124
153
|
export function startBackground(
|
package/extension/completion.ts
CHANGED
|
@@ -47,6 +47,7 @@ export function publishCompletion(
|
|
|
47
47
|
let delivered = false;
|
|
48
48
|
const deliver = (interrupted = false) => {
|
|
49
49
|
if (state.pendingCompletionDeliveries.get(deliveryId) !== generation || (delivered && !interrupted)) return;
|
|
50
|
+
let messageQueued = false;
|
|
50
51
|
try {
|
|
51
52
|
const silent = interrupted || interruptEpoch !== (state.interruptEpoch ?? 0) || explicitlyStopped(state, result);
|
|
52
53
|
state.pi.sendMessage(
|
|
@@ -59,6 +60,7 @@ export function publishCompletion(
|
|
|
59
60
|
silent ? { triggerTurn: false } : { deliverAs: "steer", triggerTurn: true },
|
|
60
61
|
);
|
|
61
62
|
delivered = true;
|
|
63
|
+
messageQueued = !silent;
|
|
62
64
|
// Interrupted deliveries are durable accounting only, with no continuation to await.
|
|
63
65
|
if (silent) releaseCompletionDelivery(state, deliveryId, generation);
|
|
64
66
|
// Normal sendMessage returns before queued messages are consumed.
|
|
@@ -66,6 +68,8 @@ export function publishCompletion(
|
|
|
66
68
|
} catch (error) {
|
|
67
69
|
releaseCompletionDelivery(state, deliveryId, generation);
|
|
68
70
|
console.error("[pi-subagent] Completion delivery failed:", error);
|
|
71
|
+
} finally {
|
|
72
|
+
state.onBackgroundChanged?.(messageQueued);
|
|
69
73
|
}
|
|
70
74
|
};
|
|
71
75
|
(state.pendingCompletionInterrupts ??= new Map()).set(deliveryId, () => deliver(true));
|
package/extension/interrupt.ts
CHANGED
|
@@ -96,8 +96,9 @@ export function registerSubagentInterrupt(state: ExtensionState): void {
|
|
|
96
96
|
state.pi.on("input", (event) => {
|
|
97
97
|
const pending = state.pendingAutomaticResume;
|
|
98
98
|
if (
|
|
99
|
+
pending &&
|
|
99
100
|
event.source === "extension" &&
|
|
100
|
-
event.text === pending
|
|
101
|
+
event.text === pending.prompt &&
|
|
101
102
|
pending.interruptEpoch !== (state.interruptEpoch ?? 0)
|
|
102
103
|
) {
|
|
103
104
|
state.pendingAutomaticResume = undefined;
|
|
@@ -106,7 +107,8 @@ export function registerSubagentInterrupt(state: ExtensionState): void {
|
|
|
106
107
|
});
|
|
107
108
|
state.pi.on("before_agent_start", (event) => {
|
|
108
109
|
const pending = state.pendingAutomaticResume;
|
|
109
|
-
startingResumeEpoch =
|
|
110
|
+
startingResumeEpoch =
|
|
111
|
+
event.messageType === "user" && pending && event.prompt === pending.prompt ? pending.interruptEpoch : undefined;
|
|
110
112
|
if (startingResumeEpoch !== undefined) state.pendingAutomaticResume = undefined;
|
|
111
113
|
});
|
|
112
114
|
state.pi.on("agent_start", (_event, ctx) => {
|
package/extension/state.ts
CHANGED
|
@@ -17,6 +17,7 @@ import type { BackgroundJob } from "./async-jobs.js";
|
|
|
17
17
|
|
|
18
18
|
export interface ExtensionState extends DelegationDepthConfig {
|
|
19
19
|
backgroundJobs: Map<string, BackgroundJob>;
|
|
20
|
+
onBackgroundChanged?: (messageQueued?: boolean) => void;
|
|
20
21
|
/** Delivery token -> session generation, retained until the completion is consumed. */
|
|
21
22
|
pendingCompletionDeliveries: Map<string, number>;
|
|
22
23
|
pendingCompletionInterrupts: Map<string, () => void>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "oira666_pi-subagent",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.5",
|
|
4
4
|
"description": "Subagent extension for Pi coding agent. Delegate tasks to specialized agents.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.ts",
|
|
@@ -55,29 +55,30 @@
|
|
|
55
55
|
},
|
|
56
56
|
"license": "MIT",
|
|
57
57
|
"scripts": {
|
|
58
|
+
"pretest": "npm install --save-dev --ignore-scripts @earendil-works/pi-agent-core@latest @earendil-works/pi-ai@latest @earendil-works/pi-coding-agent@latest @earendil-works/pi-tui@latest && npm run typecheck",
|
|
58
59
|
"test": "node --import tsx/esm --test test/*.test.ts",
|
|
59
60
|
"typecheck": "tsc --noEmit",
|
|
60
61
|
"format": "prettier --write \"*.ts\" \"{extension,runner,storage,types,ui,test}/**/*.ts\" \"scripts/*.mjs\" package.json tsconfig.json .prettierrc.json",
|
|
61
62
|
"format:check": "prettier --check \"*.ts\" \"{extension,runner,storage,types,ui,test}/**/*.ts\" \"scripts/*.mjs\" package.json tsconfig.json .prettierrc.json",
|
|
62
63
|
"check:size": "node scripts/check-size.mjs",
|
|
63
|
-
"check": "npm
|
|
64
|
+
"check": "npm test && npm run format:check && npm run check:size"
|
|
64
65
|
},
|
|
65
66
|
"devDependencies": {
|
|
67
|
+
"@earendil-works/pi-agent-core": "^1.4.0",
|
|
68
|
+
"@earendil-works/pi-ai": "^1.4.0",
|
|
69
|
+
"@earendil-works/pi-coding-agent": "^1.4.0",
|
|
70
|
+
"@earendil-works/pi-tui": "^1.4.0",
|
|
66
71
|
"@sinclair/typebox": ">=0.34.0",
|
|
67
|
-
"@earendil-works/pi-agent-core": "^0.87.1",
|
|
68
|
-
"@earendil-works/pi-ai": "^0.87.1",
|
|
69
|
-
"@earendil-works/pi-coding-agent": "^0.87.1",
|
|
70
|
-
"@earendil-works/pi-tui": "^0.87.1",
|
|
71
72
|
"@types/node": "^25.2.3",
|
|
72
73
|
"prettier": "^3.9.6",
|
|
73
74
|
"tsx": "^4.23.13",
|
|
74
75
|
"typescript": "^5.9.3"
|
|
75
76
|
},
|
|
76
77
|
"peerDependencies": {
|
|
77
|
-
"@earendil-works/pi-agent-core": "
|
|
78
|
-
"@earendil-works/pi-ai": "
|
|
79
|
-
"@earendil-works/pi-coding-agent": "
|
|
80
|
-
"@earendil-works/pi-tui": "
|
|
78
|
+
"@earendil-works/pi-agent-core": ">=1.4.0",
|
|
79
|
+
"@earendil-works/pi-ai": ">=1.4.0",
|
|
80
|
+
"@earendil-works/pi-coding-agent": ">=1.4.0",
|
|
81
|
+
"@earendil-works/pi-tui": ">=1.4.0",
|
|
81
82
|
"@sinclair/typebox": "*"
|
|
82
83
|
},
|
|
83
84
|
"peerDependenciesMeta": {
|
package/resume.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as path from "node:path";
|
|
2
2
|
import { DEFAULT_AGENT } from "./agents.js";
|
|
3
3
|
import { excludeStoppedWorkers } from "./storage/stopped-workers.js";
|
|
4
|
-
import type
|
|
4
|
+
import { getAgentDir, type ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
5
5
|
import { parseBoolean, RESUME_PROVIDER } from "./shared.js";
|
|
6
6
|
import { isBudgetAmount } from "./budget.js";
|
|
7
7
|
import { isRecord, sanitizePathComponent } from "./storage/values.js";
|
|
@@ -55,7 +55,7 @@ export function getDefaultSubagentSessionRoot(ctx: ExtensionContext): string {
|
|
|
55
55
|
return path.join(mainSessionDir, "subagents");
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
|
|
58
|
+
return path.join(getAgentDir(), "sessions", "subagents");
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
export function buildSubagentSessionDir(
|