@piotr-oles/pi-subagents 1.0.4 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@piotr-oles/pi-subagents",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "Pi Agent extension: spawn specialized subagents with isolated sessions",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1,5 +1,6 @@
1
1
  import type { Component } from "@earendil-works/pi-tui";
2
- import { Container, truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
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 [truncateToWidth(text, width, "", true)];
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, truncateToWidth } from "@earendil-works/pi-tui";
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 header = truncateToWidth(
27
- [toolTitle, id, name, description].filter(Boolean).join(" "),
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 [truncateToWidth(this.text(), width, "", true)];
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
+ }