@giladbarnea/pi-simple-team 1.0.9 → 1.0.11
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 +3 -2
- package/render.ts +29 -10
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@giladbarnea/pi-simple-team",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.11",
|
|
4
4
|
"description": "A flat, live team of Pi agents.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package",
|
|
@@ -41,6 +41,7 @@
|
|
|
41
41
|
"pi": {
|
|
42
42
|
"extensions": [
|
|
43
43
|
"./index.ts"
|
|
44
|
-
]
|
|
44
|
+
],
|
|
45
|
+
"image": "https://raw.githubusercontent.com/giladbarnea/pi-simple-team/main/screenshots/pi-simple-team-banner.png"
|
|
45
46
|
}
|
|
46
47
|
}
|
package/render.ts
CHANGED
|
@@ -46,14 +46,28 @@ interface TeamLogRenderView {
|
|
|
46
46
|
filters?: Record<string, unknown>;
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
/** A rendered line
|
|
50
|
-
export type TeamLine = string | { prefix: string; text: string };
|
|
49
|
+
/** A rendered line with optional wrapping or right-aligned layout metadata. */
|
|
50
|
+
export type TeamLine = string | { prefix: string; text: string } | { left: string; right: string };
|
|
51
|
+
|
|
52
|
+
function isRightAlignedTeamLine(line: TeamLine): line is { left: string; right: string } {
|
|
53
|
+
return typeof line !== "string" && "right" in line;
|
|
54
|
+
}
|
|
51
55
|
|
|
52
56
|
export function teamLineText(line: TeamLine): string {
|
|
53
|
-
|
|
57
|
+
if (typeof line === "string") return line;
|
|
58
|
+
if (isRightAlignedTeamLine(line)) return `${line.left}${line.right}`.trimEnd();
|
|
59
|
+
return `${line.prefix}${line.text}`.trimEnd();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** rightAlignedLine("left", "right", 12) === "left right" */
|
|
63
|
+
function rightAlignedLine(left: string, right: string, width: number): string {
|
|
64
|
+
const rightText = truncateToWidth(right, width, glyphs().ellipsis);
|
|
65
|
+
const leftWidth = Math.max(0, width - visibleLength(rightText));
|
|
66
|
+
return `${truncateToWidth(left, leftWidth, glyphs().ellipsis, true)}${rightText}`;
|
|
54
67
|
}
|
|
55
68
|
|
|
56
69
|
function wrapTeamLine(line: TeamLine, width: number): string[] {
|
|
70
|
+
if (isRightAlignedTeamLine(line)) return [rightAlignedLine(line.left, line.right, width)];
|
|
57
71
|
if (typeof line === "string") {
|
|
58
72
|
const wrapped = wrapTextWithAnsi(line, width);
|
|
59
73
|
return wrapped.length > 0 ? wrapped : [""];
|
|
@@ -68,6 +82,10 @@ function clipToWidth(line: string, width: number): string {
|
|
|
68
82
|
return truncateToWidth(line, Math.max(1, width), glyphs().ellipsis);
|
|
69
83
|
}
|
|
70
84
|
|
|
85
|
+
function clipTeamLine(line: TeamLine, width: number): string {
|
|
86
|
+
return isRightAlignedTeamLine(line) ? rightAlignedLine(line.left, line.right, width) : clipToWidth(teamLineText(line), width);
|
|
87
|
+
}
|
|
88
|
+
|
|
71
89
|
/** Clips each logical line to the render width (collapsed) or wraps it (expanded). */
|
|
72
90
|
export class TeamLines {
|
|
73
91
|
private cachedWidth?: number;
|
|
@@ -88,7 +106,7 @@ export class TeamLines {
|
|
|
88
106
|
const targetWidth = Math.max(1, stableRenderWidth(width));
|
|
89
107
|
this.cachedLines =
|
|
90
108
|
this.mode === "clip"
|
|
91
|
-
? this.lines.map((line) =>
|
|
109
|
+
? this.lines.map((line) => clipTeamLine(line, targetWidth))
|
|
92
110
|
: this.lines.flatMap((line) => wrapTeamLine(line, targetWidth));
|
|
93
111
|
this.cachedWidth = width;
|
|
94
112
|
return this.cachedLines;
|
|
@@ -151,19 +169,20 @@ export function statusWordToken(word: string): string {
|
|
|
151
169
|
return STATUS_WORD_TOKENS[word.trim().toLowerCase()] ?? "accent";
|
|
152
170
|
}
|
|
153
171
|
|
|
154
|
-
function memberRows(theme: ThemeLike, statuses: Record<string, TeamStatusView>, roster: string[], indent = ""):
|
|
172
|
+
function memberRows(theme: ThemeLike, statuses: Record<string, TeamStatusView>, roster: string[], indent = ""): TeamLine[] {
|
|
155
173
|
const names = Object.keys(statuses);
|
|
156
174
|
const nameWidth = Math.max(...names.map((name) => name.length));
|
|
157
175
|
const wordWidth = Math.max(...names.map((name) => statuses[name]!.word.length));
|
|
158
176
|
return names.map((name, index) => {
|
|
159
177
|
const entry = statuses[name]!;
|
|
160
178
|
const branch = index === names.length - 1 ? "└" : "├";
|
|
161
|
-
const
|
|
162
|
-
|
|
179
|
+
const left = `${indent}${treeConnector(theme, branch)}${theme.fg(actorHueToken(name, roster), padVisible(name, nameWidth))} ${theme.fg(statusWordToken(entry.word), padVisible(entry.word, wordWidth))} ${entry.phrase}`;
|
|
180
|
+
const right = theme.fg("dim", entry.updated);
|
|
181
|
+
return { left, right };
|
|
163
182
|
});
|
|
164
183
|
}
|
|
165
184
|
|
|
166
|
-
export function teamStatusLines(theme: ThemeLike, team: string, statuses: Record<string, TeamStatusView>, roster: string[] = []):
|
|
185
|
+
export function teamStatusLines(theme: ThemeLike, team: string, statuses: Record<string, TeamStatusView>, roster: string[] = []): TeamLine[] {
|
|
167
186
|
const members = Object.values(statuses);
|
|
168
187
|
const workingCount = members.filter((member) => statusWordToken(member.word) === "success").length;
|
|
169
188
|
const stats = [theme.fg("muted", plural(members.length, "member"))];
|
|
@@ -171,9 +190,9 @@ export function teamStatusLines(theme: ThemeLike, team: string, statuses: Record
|
|
|
171
190
|
return [headerLine(theme, "Team Status", theme.fg("accent", team), stats), ...memberRows(theme, statuses, roster)];
|
|
172
191
|
}
|
|
173
192
|
|
|
174
|
-
export function allTeamsStatusLines(theme: ThemeLike, teams: Record<string, Record<string, TeamStatusView>>, roster: string[] = []):
|
|
193
|
+
export function allTeamsStatusLines(theme: ThemeLike, teams: Record<string, Record<string, TeamStatusView>>, roster: string[] = []): TeamLine[] {
|
|
175
194
|
const teamNames = Object.keys(teams);
|
|
176
|
-
const lines = [headerLine(theme, "Team Status", theme.fg("muted", plural(teamNames.length, "team")))];
|
|
195
|
+
const lines: TeamLine[] = [headerLine(theme, "Team Status", theme.fg("muted", plural(teamNames.length, "team")))];
|
|
177
196
|
teamNames.forEach((teamName, index) => {
|
|
178
197
|
const branch = index === teamNames.length - 1 ? "└" : "├";
|
|
179
198
|
lines.push(`${treeConnector(theme, branch)}${theme.fg("accent", teamName)}`);
|