@piotr-oles/pi-subagents 1.0.1 → 1.0.3
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 +4 -4
- package/package.json +7 -7
- package/src/commands/components/subagent-template-details-component.ts +1 -0
- package/src/domain/instance/running-subagent.ts +11 -1
- package/src/domain/subagent-templates-manager.ts +1 -0
- package/src/test-helpers/scripted-session-builder.ts +5 -0
- package/src/test-helpers/scripted-session.ts +13 -1
- package/src/test-helpers.ts +1 -0
- package/src/tools/components/subagent-tool-result-component.ts +13 -1
- package/src/tools/subagent-tool.ts +19 -5
package/README.md
CHANGED
|
@@ -92,10 +92,10 @@ Opens an interactive menu listing all loaded agent templates with their source (
|
|
|
92
92
|
## Development
|
|
93
93
|
|
|
94
94
|
```bash
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
95
|
+
npm install
|
|
96
|
+
npm test
|
|
97
|
+
npm run typecheck
|
|
98
|
+
npm run check
|
|
99
99
|
```
|
|
100
100
|
|
|
101
101
|
To test changes manually, pass the source entry point directly to pi:
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@piotr-oles/pi-subagents",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "Pi Agent extension: spawn specialized subagents with isolated sessions",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
|
-
"url": "https://github.com/piotr-oles/pi-extensions.git",
|
|
7
|
+
"url": "git+https://github.com/piotr-oles/pi-extensions.git",
|
|
8
8
|
"directory": "packages/pi-subagents"
|
|
9
9
|
},
|
|
10
10
|
"keywords": [
|
|
@@ -30,17 +30,17 @@
|
|
|
30
30
|
"typecheck": "tsc --noEmit",
|
|
31
31
|
"check": "biome ci src/",
|
|
32
32
|
"fix": "biome check --write src/",
|
|
33
|
-
"release": "semantic-release -e semantic-release-monorepo"
|
|
33
|
+
"release": "semantic-release -e semantic-release-monorepo -e ../../.releaserc.json"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
36
|
"@earendil-works/pi-agent-core": "*",
|
|
37
37
|
"@earendil-works/pi-coding-agent": "*"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@earendil-works/pi-agent-core": "
|
|
41
|
-
"@earendil-works/pi-ai": "
|
|
42
|
-
"@earendil-works/pi-coding-agent": "
|
|
43
|
-
"@earendil-works/pi-tui": "
|
|
40
|
+
"@earendil-works/pi-agent-core": "0.80.10",
|
|
41
|
+
"@earendil-works/pi-ai": "0.80.10",
|
|
42
|
+
"@earendil-works/pi-coding-agent": "0.80.10",
|
|
43
|
+
"@earendil-works/pi-tui": "0.80.10",
|
|
44
44
|
"@marcfargas/pi-test-harness": "^0.6.1",
|
|
45
45
|
"strip-ansi": "^7.2.0",
|
|
46
46
|
"typebox": "^1.1.38",
|
|
@@ -160,7 +160,10 @@ export class RunningSubagent {
|
|
|
160
160
|
if (event.message.role === "assistant") {
|
|
161
161
|
this.state.lastMessage = event.message;
|
|
162
162
|
}
|
|
163
|
-
if (
|
|
163
|
+
if (
|
|
164
|
+
this.config.maxTurns &&
|
|
165
|
+
(event.message.role !== "assistant" || event.message.stopReason !== "error")
|
|
166
|
+
) {
|
|
164
167
|
if (
|
|
165
168
|
!this.state.steered &&
|
|
166
169
|
this.config.graceTurns > 0 &&
|
|
@@ -201,6 +204,13 @@ export class RunningSubagent {
|
|
|
201
204
|
onDone(this.done({ status: "exceeded_limit", limit: this.state.exceededLimit }));
|
|
202
205
|
} else if (this.state.aborted) {
|
|
203
206
|
onDone(this.done({ status: "aborted" }));
|
|
207
|
+
} else if (this.state.lastMessage?.stopReason === "error") {
|
|
208
|
+
onDone(
|
|
209
|
+
this.done({
|
|
210
|
+
status: "error",
|
|
211
|
+
error: this.state.lastMessage.errorMessage ?? "Unknown provider error",
|
|
212
|
+
}),
|
|
213
|
+
);
|
|
204
214
|
} else {
|
|
205
215
|
onDone(
|
|
206
216
|
this.done({
|
|
@@ -43,6 +43,11 @@ export class ScriptedSessionBuilder {
|
|
|
43
43
|
return this;
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
+
providerError(message: string): this {
|
|
47
|
+
this.completion = { kind: "provider-error", message };
|
|
48
|
+
return this;
|
|
49
|
+
}
|
|
50
|
+
|
|
46
51
|
fail(message: string): this {
|
|
47
52
|
this.completion = { kind: "error", message };
|
|
48
53
|
return this;
|
|
@@ -18,6 +18,7 @@ export type Step = TurnStep | EventStep | SideEffectStep;
|
|
|
18
18
|
|
|
19
19
|
export type Completion =
|
|
20
20
|
| { readonly kind: "complete"; readonly text: string }
|
|
21
|
+
| { readonly kind: "provider-error"; readonly message: string }
|
|
21
22
|
| { readonly kind: "error"; readonly message: string };
|
|
22
23
|
|
|
23
24
|
/**
|
|
@@ -72,7 +73,18 @@ export class ScriptedSession {
|
|
|
72
73
|
return;
|
|
73
74
|
}
|
|
74
75
|
|
|
75
|
-
if (this.completion.kind === "error") {
|
|
76
|
+
if (this.completion.kind === "provider-error") {
|
|
77
|
+
await this.handler?.({
|
|
78
|
+
type: "turn_end",
|
|
79
|
+
message: {
|
|
80
|
+
role: "assistant",
|
|
81
|
+
content: [],
|
|
82
|
+
stopReason: "error",
|
|
83
|
+
errorMessage: this.completion.message,
|
|
84
|
+
},
|
|
85
|
+
toolResults: [],
|
|
86
|
+
} as unknown as AgentSessionEvent);
|
|
87
|
+
} else if (this.completion.kind === "error") {
|
|
76
88
|
throw new Error(this.completion.message);
|
|
77
89
|
}
|
|
78
90
|
}
|
package/src/test-helpers.ts
CHANGED
|
@@ -56,6 +56,10 @@ export class SubagentToolResultComponent implements Component {
|
|
|
56
56
|
this.summary.invalidate();
|
|
57
57
|
this.details.invalidate();
|
|
58
58
|
}
|
|
59
|
+
|
|
60
|
+
dispose(): void {
|
|
61
|
+
this.summary.dispose();
|
|
62
|
+
}
|
|
59
63
|
}
|
|
60
64
|
|
|
61
65
|
class SubagentSummaryComponent implements Component {
|
|
@@ -84,6 +88,10 @@ class SubagentSummaryComponent implements Component {
|
|
|
84
88
|
invalidate() {
|
|
85
89
|
this.container.invalidate();
|
|
86
90
|
}
|
|
91
|
+
|
|
92
|
+
dispose(): void {
|
|
93
|
+
this.icon.dispose();
|
|
94
|
+
}
|
|
87
95
|
}
|
|
88
96
|
|
|
89
97
|
class SubagentDetailsComponent implements Component {
|
|
@@ -268,7 +276,7 @@ class SubagentSummaryTextComponent implements Component {
|
|
|
268
276
|
const theme = this.theme;
|
|
269
277
|
const parts: string[] = [];
|
|
270
278
|
if (done.result.status === "error") {
|
|
271
|
-
parts.push(theme.fg("error", done.result.error));
|
|
279
|
+
parts.push(theme.fg("error", getFirstLine(done.result.error)));
|
|
272
280
|
}
|
|
273
281
|
if (done.result.status === "aborted") {
|
|
274
282
|
parts.push(theme.fg("dim", "cancelled"));
|
|
@@ -311,6 +319,10 @@ class SubagentIconComponent implements Component {
|
|
|
311
319
|
|
|
312
320
|
invalidate() {}
|
|
313
321
|
|
|
322
|
+
dispose(): void {
|
|
323
|
+
this.stopAnimation();
|
|
324
|
+
}
|
|
325
|
+
|
|
314
326
|
private syncAnimation(): void {
|
|
315
327
|
if (this.entry.status === "running") {
|
|
316
328
|
this.startAnimation();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { TextContent } from "@earendil-works/pi-ai";
|
|
2
2
|
import { defineTool, type ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
3
|
-
import type
|
|
3
|
+
import { type Component, Text } from "@earendil-works/pi-tui";
|
|
4
4
|
import type { DoneSubagent } from "../domain/instance/done-subagent.js";
|
|
5
5
|
import type { SubagentInstancesManager } from "../domain/subagent-instances-manager.js";
|
|
6
6
|
import type { SubagentTemplatesManager } from "../domain/subagent-templates-manager.js";
|
|
@@ -76,11 +76,18 @@ export function createSubagentTool(deps: SubagentToolDeps) {
|
|
|
76
76
|
ctx.ui.setWorkingIndicator({ frames: [ctx.ui.theme.fg("dim", "●")] });
|
|
77
77
|
ctx.ui.setWorkingMessage("Waiting for subagents");
|
|
78
78
|
|
|
79
|
-
|
|
79
|
+
let done: DoneSubagent;
|
|
80
|
+
try {
|
|
81
|
+
done = await promise;
|
|
82
|
+
} finally {
|
|
83
|
+
if (!instanceManager.isRunning()) {
|
|
84
|
+
ctx.ui.setWorkingIndicator();
|
|
85
|
+
ctx.ui.setWorkingMessage();
|
|
86
|
+
}
|
|
87
|
+
}
|
|
80
88
|
|
|
81
|
-
if (
|
|
82
|
-
|
|
83
|
-
ctx.ui.setWorkingMessage();
|
|
89
|
+
if (done.result.status === "error") {
|
|
90
|
+
throw new Error(done.result.error);
|
|
84
91
|
}
|
|
85
92
|
|
|
86
93
|
return {
|
|
@@ -102,6 +109,13 @@ export function createSubagentTool(deps: SubagentToolDeps) {
|
|
|
102
109
|
},
|
|
103
110
|
/** Custom rendering for tool result display */
|
|
104
111
|
renderResult(result, _options, theme, context): Component {
|
|
112
|
+
if (context.isError) {
|
|
113
|
+
if (context.lastComponent instanceof SubagentToolResultComponent) {
|
|
114
|
+
context.lastComponent.dispose();
|
|
115
|
+
}
|
|
116
|
+
const error = result.content[0];
|
|
117
|
+
return new Text(error.type === "text" ? error.text : "", 0, 0);
|
|
118
|
+
}
|
|
105
119
|
if (!(context.lastComponent instanceof SubagentToolResultComponent)) {
|
|
106
120
|
return new SubagentToolResultComponent(
|
|
107
121
|
result.details,
|