@piotr-oles/pi-subagents 1.0.3 → 1.0.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/package.json +1 -1
- package/src/tools/components/inline-container.ts +3 -2
- package/src/tools/components/subagent-tool-call-component.ts +4 -5
- package/src/tools/components/subagent-tool-result-component.ts +2 -1
- package/src/tools/components/truncate-tool-line.ts +28 -0
- package/src/tools/subagent-tool.ts +5 -4
package/package.json
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Component } from "@earendil-works/pi-tui";
|
|
2
|
-
import { Container,
|
|
2
|
+
import { Container, visibleWidth } from "@earendil-works/pi-tui";
|
|
3
|
+
import { truncateToolLine } from "./truncate-tool-line.js";
|
|
3
4
|
|
|
4
5
|
export class InlineContainer implements Component {
|
|
5
6
|
private readonly container: Container;
|
|
@@ -46,7 +47,7 @@ export class InlineContainer implements Component {
|
|
|
46
47
|
|
|
47
48
|
const text = parts.join(this.gap);
|
|
48
49
|
|
|
49
|
-
return [
|
|
50
|
+
return [truncateToolLine(text, width, "", true)];
|
|
50
51
|
}
|
|
51
52
|
|
|
52
53
|
invalidate() {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Theme } from "@earendil-works/pi-coding-agent";
|
|
2
|
-
import { type Component, Text
|
|
2
|
+
import { type Component, Text } from "@earendil-works/pi-tui";
|
|
3
3
|
import type { SubagentToolParamsType } from "../types.js";
|
|
4
|
+
import { truncateToolLine } from "./truncate-tool-line.js";
|
|
4
5
|
|
|
5
6
|
export class SubagentToolCallComponent implements Component {
|
|
6
7
|
constructor(
|
|
@@ -23,10 +24,8 @@ export class SubagentToolCallComponent implements Component {
|
|
|
23
24
|
const id = params.id ? theme.fg("syntaxNumber", `#${params.id}`) : undefined;
|
|
24
25
|
const name = params.name ? theme.fg("accent", params.name) : undefined;
|
|
25
26
|
const description = params.description ? theme.fg("dim", params.description) : undefined;
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
width,
|
|
29
|
-
);
|
|
27
|
+
const title = [toolTitle, id, name, description].filter(Boolean).join(" ");
|
|
28
|
+
const header = truncateToolLine(title, width);
|
|
30
29
|
|
|
31
30
|
if (expanded && params.prompt) {
|
|
32
31
|
const prompt = new Text(theme.fg("dim", params.prompt.trim()), 0, 1);
|
|
@@ -6,6 +6,7 @@ import type { RunningAgentSessionEntry } from "../../domain/instance/running-sub
|
|
|
6
6
|
import type { SubagentSessionEntry } from "../../domain/types.js";
|
|
7
7
|
import { formatDuration, formatFilePath, formatUsage, getFirstLine } from "../../format.js";
|
|
8
8
|
import { InlineContainer } from "./inline-container.js";
|
|
9
|
+
import { truncateToolLine } from "./truncate-tool-line.js";
|
|
9
10
|
|
|
10
11
|
export class SubagentToolResultComponent implements Component {
|
|
11
12
|
private readonly summary: SubagentSummaryComponent;
|
|
@@ -189,7 +190,7 @@ class SubagentSummaryTextComponent implements Component {
|
|
|
189
190
|
}
|
|
190
191
|
|
|
191
192
|
render(width: number): string[] {
|
|
192
|
-
return [
|
|
193
|
+
return [truncateToolLine(this.text(), width, "", true)];
|
|
193
194
|
}
|
|
194
195
|
|
|
195
196
|
invalidate() {}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { sliceByColumn, truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
|
|
2
|
+
|
|
3
|
+
const FULL_RESET = "\x1b[0m";
|
|
4
|
+
const TEXT_RESET = "\x1b[23m\x1b[39m";
|
|
5
|
+
|
|
6
|
+
export function truncateToolLine(
|
|
7
|
+
text: string,
|
|
8
|
+
width: number,
|
|
9
|
+
ellipsis = "...",
|
|
10
|
+
pad = false,
|
|
11
|
+
): string {
|
|
12
|
+
if (width <= 0) {
|
|
13
|
+
return "";
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const textWidth = visibleWidth(text);
|
|
17
|
+
if (textWidth <= width) {
|
|
18
|
+
return pad ? text + " ".repeat(width - textWidth) : text;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const suffix = sliceByColumn(ellipsis, 0, width, true);
|
|
22
|
+
const prefixWidth = width - visibleWidth(suffix);
|
|
23
|
+
// Remove Pi's final reset so the dots inherit the text color and the card keeps its background.
|
|
24
|
+
const prefix =
|
|
25
|
+
prefixWidth > 0 ? truncateToWidth(text, prefixWidth, "").slice(0, -FULL_RESET.length) : "";
|
|
26
|
+
const line = prefix + suffix + TEXT_RESET;
|
|
27
|
+
return pad ? line + " ".repeat(width - visibleWidth(line)) : line;
|
|
28
|
+
}
|
|
@@ -33,14 +33,14 @@ export function createSubagentTool(deps: SubagentToolDeps) {
|
|
|
33
33
|
executionMode: "parallel",
|
|
34
34
|
execute: async (toolCallId, params, signal, onUpdate, ctx) => {
|
|
35
35
|
const availableTools = pi.getActiveTools();
|
|
36
|
-
const
|
|
36
|
+
const id = typeof params.id === "string" && params.id !== "" ? params.id : undefined;
|
|
37
37
|
const onUpdateThrottled = onUpdate ? throttle(onUpdate, 500) : undefined;
|
|
38
38
|
|
|
39
39
|
let promise: Promise<DoneSubagent>;
|
|
40
40
|
|
|
41
|
-
if (
|
|
41
|
+
if (id) {
|
|
42
42
|
promise = instanceManager.followUp({
|
|
43
|
-
id
|
|
43
|
+
id,
|
|
44
44
|
prompt: params.prompt,
|
|
45
45
|
description: params.description,
|
|
46
46
|
signal,
|
|
@@ -49,6 +49,7 @@ export function createSubagentTool(deps: SubagentToolDeps) {
|
|
|
49
49
|
},
|
|
50
50
|
});
|
|
51
51
|
} else {
|
|
52
|
+
const generatedId = instanceManager.id(toolCallId);
|
|
52
53
|
const template = templatesManager.getTemplate(params.name);
|
|
53
54
|
if (!template) {
|
|
54
55
|
const availableSubagents = templatesManager
|
|
@@ -60,7 +61,7 @@ export function createSubagentTool(deps: SubagentToolDeps) {
|
|
|
60
61
|
);
|
|
61
62
|
}
|
|
62
63
|
promise = instanceManager.spawn({
|
|
63
|
-
id:
|
|
64
|
+
id: generatedId,
|
|
64
65
|
ctx,
|
|
65
66
|
template,
|
|
66
67
|
prompt: params.prompt,
|