@giladbarnea/pi-simple-team 1.0.22 → 1.0.23
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 +12 -6
- package/index.ts +30 -2
- package/package.json +1 -1
- package/team-ui.ts +342 -0
package/README.md
CHANGED
|
@@ -41,6 +41,14 @@ Not scheduling a meeting.
|
|
|
41
41
|
Tell your main agent:
|
|
42
42
|
> Spawn a team.
|
|
43
43
|
|
|
44
|
+
### Watch a live team with `/team`.
|
|
45
|
+
|
|
46
|
+
`/team` is for you, not another agent tool. It gives you a live view of the room without turning the main agent into a status relay.
|
|
47
|
+
|
|
48
|
+
The command opens a read-only overlay with recent statuses, messages, and a separate event log. With no teams, it shows an empty state. With one team, it opens that team directly. With several teams, it starts with a selector.
|
|
49
|
+
|
|
50
|
+
The fixed layout keeps the latest content in view as work arrives, without scrolling or jumping around. It is an overview of the room, not a teammate drill-down or transcript.
|
|
51
|
+
|
|
44
52
|
### Throw a team at something hard.
|
|
45
53
|
|
|
46
54
|
The team takes the shape of the mission.
|
|
@@ -229,12 +237,10 @@ Kept minimal:
|
|
|
229
237
|
**User involvement track:**
|
|
230
238
|
|
|
231
239
|
- [x] Herdr panes for teammates.
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
- [ ]
|
|
236
|
-
- [ ] 👋 Joining and steering teams.
|
|
237
|
-
- [ ] 🪄 Spawning teams directly.
|
|
240
|
+
- [x] `/team`: live, read-only team dashboard.
|
|
241
|
+
- [ ] Teammate drill-down and transcripts.
|
|
242
|
+
- [ ] Joining and steering teams from slash commands.
|
|
243
|
+
- [ ] Spawning teams directly from slash commands.
|
|
238
244
|
|
|
239
245
|
**Functional:**
|
|
240
246
|
|
package/index.ts
CHANGED
|
@@ -26,6 +26,7 @@ import {
|
|
|
26
26
|
} from "./team-registry.ts";
|
|
27
27
|
import { appendTeamLog, filterTeamLog, normalizeChildEvent, nowText, pageTeamLog, preview, renderTeamLogPage, type TeamLogEntry } from "./teamlog.ts";
|
|
28
28
|
import { renderTeamMessage, renderTeamToolCall, renderTeamToolResult, type TeamMessageDetails } from "./render.ts";
|
|
29
|
+
import { openTeamOverview, type TeamSnapshot } from "./team-ui.ts";
|
|
29
30
|
import { StringEnum } from "@earendil-works/pi-ai";
|
|
30
31
|
import { Type } from "typebox";
|
|
31
32
|
|
|
@@ -387,7 +388,7 @@ function enqueueDelivery(team: TeamState, from: string, recipient: TeammateState
|
|
|
387
388
|
direction: from === "main" ? "main->teammate" : "teammate->teammate",
|
|
388
389
|
kind: "send",
|
|
389
390
|
summary: preview(message),
|
|
390
|
-
details: { from, to: recipient.name, interrupt },
|
|
391
|
+
details: { from, to: recipient.name, interrupt, message },
|
|
391
392
|
});
|
|
392
393
|
|
|
393
394
|
recipient.deliveryQueue = recipient.deliveryQueue
|
|
@@ -477,6 +478,19 @@ function allStatuses(owner: symbol): Record<string, Record<string, TeamStatus>>
|
|
|
477
478
|
return Object.fromEntries([...teams.values()].filter((team) => team.owner === owner).map((team) => [team.name, formatStatus(team)]));
|
|
478
479
|
}
|
|
479
480
|
|
|
481
|
+
function ownedTeamSnapshots(owner: symbol): TeamSnapshot[] {
|
|
482
|
+
return [...teams.values()]
|
|
483
|
+
.filter((team) => team.owner === owner)
|
|
484
|
+
.map((team) => ({
|
|
485
|
+
name: team.name,
|
|
486
|
+
created: team.created,
|
|
487
|
+
showOnHerdrPanes: team.showOnHerdrPanes,
|
|
488
|
+
roster: [...team.members.keys()],
|
|
489
|
+
statuses: formatStatus(team),
|
|
490
|
+
log: [...team.log],
|
|
491
|
+
}));
|
|
492
|
+
}
|
|
493
|
+
|
|
480
494
|
function updateStatus(team: TeamState, participant: string, word?: string, phrase?: string): void {
|
|
481
495
|
if (word === undefined && phrase === undefined) return;
|
|
482
496
|
const previous = team.statuses.get(participant) ?? status("active", "Working");
|
|
@@ -945,7 +959,14 @@ async function handleCallbackRequest(request: http.IncomingMessage, response: ht
|
|
|
945
959
|
if (tool === "teammain") {
|
|
946
960
|
const rawMessage = String(args.message ?? "");
|
|
947
961
|
const details: TeamMessageDetails = { team: team.name, from, sentAt: nowText(), message: rawMessage };
|
|
948
|
-
appendTeamLog(team, {
|
|
962
|
+
appendTeamLog(team, {
|
|
963
|
+
team: team.name,
|
|
964
|
+
teammate: from,
|
|
965
|
+
direction: "teammate->main",
|
|
966
|
+
kind: "main_message",
|
|
967
|
+
summary: preview(rawMessage),
|
|
968
|
+
details: { from, to: "main", message: rawMessage },
|
|
969
|
+
});
|
|
949
970
|
team.ownerPi.sendMessage(
|
|
950
971
|
{ customType: teamMessageType, content: `[${team.name}/${from}] ${rawMessage}`, display: true, details },
|
|
951
972
|
{ deliverAs: "steer", triggerTurn: true },
|
|
@@ -1044,6 +1065,13 @@ export default function (pi: ExtensionAPI) {
|
|
|
1044
1065
|
const sessionTeammateRoster: string[] = [];
|
|
1045
1066
|
pi.registerMessageRenderer(teamMessageType, (message, _options, theme) => renderTeamMessage(message, theme, getMarkdownTheme(), sessionTeammateRoster));
|
|
1046
1067
|
|
|
1068
|
+
pi.registerCommand("team", {
|
|
1069
|
+
description: "Open a read-only team overview",
|
|
1070
|
+
handler: async (_args, context) => {
|
|
1071
|
+
await openTeamOverview(context, () => ownedTeamSnapshots(owner));
|
|
1072
|
+
},
|
|
1073
|
+
});
|
|
1074
|
+
|
|
1047
1075
|
pi.on("session_shutdown", async () => {
|
|
1048
1076
|
for (const team of [...teams.values()]) {
|
|
1049
1077
|
if (team.owner === owner) await shutdownTeam(team);
|
package/package.json
CHANGED
package/team-ui.ts
ADDED
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
import type { ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { Key, matchesKey, SelectList, sliceByColumn, truncateToWidth, visibleWidth, type Component, type SelectItem, type TUI } from "@earendil-works/pi-tui";
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
actorHueToken,
|
|
6
|
+
statusWordToken,
|
|
7
|
+
teamLineText,
|
|
8
|
+
teamLogLines,
|
|
9
|
+
teamMessageLines,
|
|
10
|
+
type TeamMessageDetails,
|
|
11
|
+
type TeamStatusView,
|
|
12
|
+
type ThemeLike,
|
|
13
|
+
} from "./render.ts";
|
|
14
|
+
import type { TeamLogEntry, TeamLogKind } from "./teamlog.ts";
|
|
15
|
+
|
|
16
|
+
export interface TeamSnapshot {
|
|
17
|
+
name: string;
|
|
18
|
+
created: string;
|
|
19
|
+
showOnHerdrPanes: boolean;
|
|
20
|
+
roster: string[];
|
|
21
|
+
statuses: Record<string, TeamStatusView>;
|
|
22
|
+
log: TeamLogEntry[];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export type TeamSnapshotSource = () => readonly TeamSnapshot[];
|
|
26
|
+
|
|
27
|
+
const RECENT_STATUS_LIMIT = 5;
|
|
28
|
+
const RECENT_LOG_ENTRY_LIMIT = 20;
|
|
29
|
+
const LIVE_REFRESH_INTERVAL_MILLISECONDS = 500;
|
|
30
|
+
const MESSAGE_LOG_KINDS = new Set<TeamLogKind>(["send", "deliver", "ack", "main_message"]);
|
|
31
|
+
|
|
32
|
+
const overlayOptions = {
|
|
33
|
+
overlay: true,
|
|
34
|
+
overlayOptions: { anchor: "center", width: "90%", maxHeight: "90%" },
|
|
35
|
+
} as const;
|
|
36
|
+
|
|
37
|
+
function teamMessage(entry: TeamLogEntry): TeamMessageDetails | undefined {
|
|
38
|
+
if (entry.kind !== "send" && entry.kind !== "main_message") return undefined;
|
|
39
|
+
const details = entry.details as { from: string; to: string; message: string };
|
|
40
|
+
return {
|
|
41
|
+
team: entry.team,
|
|
42
|
+
from: entry.kind === "main_message" ? entry.teammate! : details.from,
|
|
43
|
+
to: entry.kind === "main_message" ? "main" : details.to,
|
|
44
|
+
sentAt: entry.timestamp,
|
|
45
|
+
message: details.message,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** middleTruncateToWidth("abcdefghij", 7) === "abc…hij" */
|
|
50
|
+
function middleTruncateToWidth(text: string, width: number, pad = false): string {
|
|
51
|
+
const targetWidth = Math.max(0, width);
|
|
52
|
+
const textWidth = visibleWidth(text);
|
|
53
|
+
if (textWidth <= targetWidth) return pad ? `${text}${" ".repeat(targetWidth - textWidth)}` : text;
|
|
54
|
+
if (targetWidth === 0) return "";
|
|
55
|
+
|
|
56
|
+
const ellipsis = "…";
|
|
57
|
+
const ellipsisWidth = visibleWidth(ellipsis);
|
|
58
|
+
if (ellipsisWidth >= targetWidth) return truncateToWidth(ellipsis, targetWidth, "", pad);
|
|
59
|
+
|
|
60
|
+
const retainedWidth = targetWidth - ellipsisWidth;
|
|
61
|
+
const leftWidth = Math.ceil(retainedWidth / 2);
|
|
62
|
+
const rightWidth = Math.floor(retainedWidth / 2);
|
|
63
|
+
const left = sliceByColumn(text, 0, leftWidth, true);
|
|
64
|
+
const right = sliceByColumn(text, textWidth - rightWidth, rightWidth, true);
|
|
65
|
+
const reset = text.includes("\x1b") ? "\x1b[0m" : "";
|
|
66
|
+
const result = `${left}${reset}${ellipsis}${reset}${right}`;
|
|
67
|
+
return pad ? `${result}${" ".repeat(Math.max(0, targetWidth - visibleWidth(result)))}` : result;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Keeps the most recently updated status first. */
|
|
71
|
+
function recentStatuses(statuses: Record<string, TeamStatusView>, limit: number): Array<[string, TeamStatusView]> {
|
|
72
|
+
return Object.entries(statuses)
|
|
73
|
+
.sort(([, left], [, right]) => Date.parse(right.updated) - Date.parse(left.updated))
|
|
74
|
+
.slice(0, limit);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function padVisible(text: string, width: number): string {
|
|
78
|
+
return `${text}${" ".repeat(Math.max(0, width - visibleWidth(text)))}`;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function statusRows(theme: ThemeLike, statuses: Array<[string, TeamStatusView]>, roster: string[], width: number): string[] {
|
|
82
|
+
const contentWidth = Math.max(0, width - 1);
|
|
83
|
+
const nameWidth = Math.max(0, ...statuses.map(([name]) => visibleWidth(name)));
|
|
84
|
+
const wordWidth = Math.max(0, ...statuses.map(([, status]) => visibleWidth(status.word)));
|
|
85
|
+
const timestampWidth = Math.max(0, ...statuses.map(([, status]) => visibleWidth(status.updated)));
|
|
86
|
+
const phraseWidth = Math.max(0, contentWidth - nameWidth - wordWidth - timestampWidth - 6);
|
|
87
|
+
|
|
88
|
+
return statuses.map(([name, status]) => {
|
|
89
|
+
const styledName = theme.fg(actorHueToken(name, roster), name);
|
|
90
|
+
const styledWord = theme.fg(statusWordToken(status.word), status.word);
|
|
91
|
+
const timestamp = theme.fg("dim", status.updated);
|
|
92
|
+
const phrase = middleTruncateToWidth(status.phrase, phraseWidth, true);
|
|
93
|
+
return `${padVisible(styledName, nameWidth)} ${padVisible(styledWord, wordWidth)} ${phrase} ${timestamp}`;
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function limitMessageRows(lines: string[], height: number): string[] {
|
|
98
|
+
if (lines.length <= height) return lines;
|
|
99
|
+
if (height <= 0) return [];
|
|
100
|
+
if (height === 1) return [lines[0]!];
|
|
101
|
+
if (height === 2) return [lines[0]!, `… ${lines.length - 1} message lines omitted …`];
|
|
102
|
+
|
|
103
|
+
const body = lines.slice(1);
|
|
104
|
+
const retainedBodyRows = height - 2;
|
|
105
|
+
const leadingRows = Math.ceil(retainedBodyRows / 2);
|
|
106
|
+
const trailingRows = Math.floor(retainedBodyRows / 2);
|
|
107
|
+
return [
|
|
108
|
+
lines[0]!,
|
|
109
|
+
...body.slice(0, leadingRows),
|
|
110
|
+
`… ${body.length - retainedBodyRows} message lines omitted …`,
|
|
111
|
+
...(trailingRows > 0 ? body.slice(-trailingRows) : []),
|
|
112
|
+
];
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
interface MessageLineSelection {
|
|
116
|
+
lines: string[];
|
|
117
|
+
messageCount: number;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** selectNewestMessageLines([["old"], ["new"]], 1).lines[0] === "new" */
|
|
121
|
+
function selectNewestMessageLines(groups: string[][], height: number): MessageLineSelection {
|
|
122
|
+
const selectedGroups: string[][] = [];
|
|
123
|
+
let remainingHeight = height;
|
|
124
|
+
|
|
125
|
+
for (let index = groups.length - 1; index >= 0; index--) {
|
|
126
|
+
const group = groups[index]!;
|
|
127
|
+
const separatorHeight = selectedGroups.length > 0 ? 1 : 0;
|
|
128
|
+
if (group.length + separatorHeight <= remainingHeight) {
|
|
129
|
+
selectedGroups.unshift(group);
|
|
130
|
+
remainingHeight -= group.length + separatorHeight;
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
if (selectedGroups.length === 0) selectedGroups.push(limitMessageRows(group, height));
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return {
|
|
138
|
+
lines: selectedGroups.flatMap((group, index) => [...(index > 0 ? [""] : []), ...group]),
|
|
139
|
+
messageCount: selectedGroups.length,
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
class TeamOverviewOverlay implements Component {
|
|
144
|
+
private readonly selector?: SelectList;
|
|
145
|
+
private selectedTeamName?: string;
|
|
146
|
+
private refreshTimer?: ReturnType<typeof setInterval>;
|
|
147
|
+
private closed = false;
|
|
148
|
+
|
|
149
|
+
constructor(
|
|
150
|
+
private readonly tui: TUI,
|
|
151
|
+
private readonly theme: ThemeLike,
|
|
152
|
+
private readonly teamSource: TeamSnapshotSource,
|
|
153
|
+
private readonly done: () => void,
|
|
154
|
+
) {
|
|
155
|
+
const teams = teamSource();
|
|
156
|
+
this.selectedTeamName = teams.length === 1 ? teams[0]!.name : undefined;
|
|
157
|
+
if (teams.length > 1) {
|
|
158
|
+
const items: SelectItem[] = teams.map((team) => ({
|
|
159
|
+
value: team.name,
|
|
160
|
+
label: team.name,
|
|
161
|
+
description: `${team.roster.length} teammate${team.roster.length === 1 ? "" : "s"}`,
|
|
162
|
+
}));
|
|
163
|
+
this.selector = new SelectList(items, this.selectorHeight(teams.length), {
|
|
164
|
+
selectedPrefix: (text) => theme.fg("accent", text),
|
|
165
|
+
selectedText: (text) => theme.fg("accent", text),
|
|
166
|
+
description: (text) => theme.fg("muted", text),
|
|
167
|
+
scrollInfo: (text) => theme.fg("dim", text),
|
|
168
|
+
noMatch: (text) => theme.fg("warning", text),
|
|
169
|
+
});
|
|
170
|
+
this.selector.onSelect = (item) => {
|
|
171
|
+
this.selectedTeamName = item.value;
|
|
172
|
+
this.tui.requestRender();
|
|
173
|
+
};
|
|
174
|
+
this.selector.onCancel = this.close;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
this.refreshTimer = setInterval(() => this.tui.requestRender(), LIVE_REFRESH_INTERVAL_MILLISECONDS);
|
|
178
|
+
this.refreshTimer.unref?.();
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
handleInput(data: string): void {
|
|
182
|
+
if (!this.selectedTeamName && this.selector) {
|
|
183
|
+
this.selector.handleInput(data);
|
|
184
|
+
this.tui.requestRender();
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
if (matchesKey(data, Key.escape) || matchesKey(data, Key.ctrl("c"))) this.close();
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
render(width: number): string[] {
|
|
191
|
+
const height = Math.max(4, Math.floor(this.tui.terminal.rows * 0.9));
|
|
192
|
+
const teams = this.teamSource();
|
|
193
|
+
if (this.selectedTeamName) {
|
|
194
|
+
const team = teams.find((candidate) => candidate.name === this.selectedTeamName)!;
|
|
195
|
+
return this.dashboard(team, width, height);
|
|
196
|
+
}
|
|
197
|
+
const innerHeight = height - 2;
|
|
198
|
+
return this.frame(this.content(Math.max(1, width - 4), teams).slice(0, innerHeight), width, height);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
invalidate(): void {
|
|
202
|
+
this.selector?.invalidate();
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
dispose(): void {
|
|
206
|
+
if (!this.refreshTimer) return;
|
|
207
|
+
clearInterval(this.refreshTimer);
|
|
208
|
+
this.refreshTimer = undefined;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
private readonly close = (): void => {
|
|
212
|
+
if (this.closed) return;
|
|
213
|
+
this.closed = true;
|
|
214
|
+
this.dispose();
|
|
215
|
+
this.done();
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
private selectorHeight(teamCount: number): number {
|
|
219
|
+
return Math.max(1, Math.min(teamCount, Math.floor(this.tui.terminal.rows * 0.9) - 8));
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
private content(width: number, teams: readonly TeamSnapshot[]): string[] {
|
|
223
|
+
if (teams.length === 0) {
|
|
224
|
+
return [
|
|
225
|
+
this.theme.fg("accent", this.theme.bold("Teams")),
|
|
226
|
+
"",
|
|
227
|
+
"No teams exist.",
|
|
228
|
+
"",
|
|
229
|
+
this.theme.fg("dim", "Esc close"),
|
|
230
|
+
];
|
|
231
|
+
}
|
|
232
|
+
return [
|
|
233
|
+
this.theme.fg("accent", this.theme.bold("Select a team")),
|
|
234
|
+
"",
|
|
235
|
+
...this.selector!.render(width),
|
|
236
|
+
"",
|
|
237
|
+
this.theme.fg("dim", "↑↓ select · Enter open · Esc close"),
|
|
238
|
+
];
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
private dashboard(team: TeamSnapshot, width: number, height: number): string[] {
|
|
242
|
+
const contentWidth = Math.max(1, width - 2);
|
|
243
|
+
const contentHeight = Math.max(1, height - 2);
|
|
244
|
+
const headerHeight = Math.min(3, Math.max(1, contentHeight - 3));
|
|
245
|
+
const desiredStatusHeight = Math.min(Object.keys(team.statuses).length, RECENT_STATUS_LIMIT) + 2;
|
|
246
|
+
const statusHeight = Math.max(1, Math.min(desiredStatusHeight, contentHeight - headerHeight - 2));
|
|
247
|
+
const feedHeight = contentHeight - headerHeight - statusHeight;
|
|
248
|
+
const messageHeight = Math.max(1, Math.min(feedHeight - 1, Math.round(feedHeight * 0.55)));
|
|
249
|
+
const logHeight = feedHeight - messageHeight;
|
|
250
|
+
|
|
251
|
+
const transport = team.showOnHerdrPanes ? "Herdr" : "RPC";
|
|
252
|
+
const metadata = [
|
|
253
|
+
`Created ${team.created}`,
|
|
254
|
+
`${team.roster.length} teammate${team.roster.length === 1 ? "" : "s"}`,
|
|
255
|
+
transport,
|
|
256
|
+
`${team.log.length} retained event${team.log.length === 1 ? "" : "s"}`,
|
|
257
|
+
"Esc close",
|
|
258
|
+
].join(" · ");
|
|
259
|
+
|
|
260
|
+
const statusContentHeight = Math.max(0, statusHeight - 2);
|
|
261
|
+
const statuses = recentStatuses(team.statuses, Math.min(RECENT_STATUS_LIMIT, statusContentHeight));
|
|
262
|
+
const statusLines = statusRows(this.theme, statuses, team.roster, Math.max(0, contentWidth - 2));
|
|
263
|
+
|
|
264
|
+
const allMessages = team.log.flatMap((entry) => {
|
|
265
|
+
const message = teamMessage(entry);
|
|
266
|
+
return message ? [message] : [];
|
|
267
|
+
});
|
|
268
|
+
const messageGroups = allMessages.map((message) => teamMessageLines(this.theme, message, team.roster).map(teamLineText));
|
|
269
|
+
const selectedMessages = selectNewestMessageLines(messageGroups, Math.max(0, messageHeight - 2));
|
|
270
|
+
const messageLines = selectedMessages.lines.length > 0 ? selectedMessages.lines : [this.theme.fg("muted", "No recent messages.")];
|
|
271
|
+
|
|
272
|
+
const allLogEntries = team.log.filter((entry) => !MESSAGE_LOG_KINDS.has(entry.kind));
|
|
273
|
+
const recentLogEntries = allLogEntries.slice(-RECENT_LOG_ENTRY_LIMIT);
|
|
274
|
+
const renderedLogLines = teamLogLines(this.theme, {
|
|
275
|
+
team: team.name,
|
|
276
|
+
roster: team.roster,
|
|
277
|
+
entries: recentLogEntries,
|
|
278
|
+
totalMatched: allLogEntries.length,
|
|
279
|
+
returned: recentLogEntries.length,
|
|
280
|
+
}).slice(1);
|
|
281
|
+
const logContentHeight = Math.max(0, logHeight - 2);
|
|
282
|
+
const logLines = renderedLogLines.slice(-logContentHeight);
|
|
283
|
+
|
|
284
|
+
const content = [
|
|
285
|
+
...this.region(this.theme.fg("accent", this.theme.bold(`Team: ${team.name}`)), [this.theme.fg("muted", metadata)], contentWidth, headerHeight),
|
|
286
|
+
...this.region(`Team Status ${team.name} · latest ${statuses.length} of ${Object.keys(team.statuses).length}`, statusLines, contentWidth, statusHeight),
|
|
287
|
+
...this.region(`Messages · latest ${selectedMessages.messageCount} of ${allMessages.length}`, messageLines, contentWidth, messageHeight),
|
|
288
|
+
...this.region(`Team Log ${team.name} · latest ${logLines.length} rows · ${allLogEntries.length} events`, logLines, contentWidth, logHeight),
|
|
289
|
+
];
|
|
290
|
+
return this.frame(content, width, height);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
private region(title: string, content: string[], width: number, height: number): string[] {
|
|
294
|
+
const frameWidth = Math.max(1, width);
|
|
295
|
+
const border = (text: string): string => this.theme.fg("border", text);
|
|
296
|
+
if (frameWidth < 3) {
|
|
297
|
+
const top = border(frameWidth === 1 ? "╭" : "╭╮");
|
|
298
|
+
if (height === 1) return [top];
|
|
299
|
+
const row = border("│".repeat(frameWidth));
|
|
300
|
+
return [top, ...Array.from({ length: Math.max(0, height - 2) }, () => row), border(frameWidth === 1 ? "╰" : "╰╯")];
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
const innerWidth = frameWidth - 2;
|
|
304
|
+
const labelWidth = Math.max(0, innerWidth - 3);
|
|
305
|
+
const label = middleTruncateToWidth(title, labelWidth);
|
|
306
|
+
const topFill = "─".repeat(Math.max(0, innerWidth - 3 - visibleWidth(label)));
|
|
307
|
+
const top = innerWidth < 3 ? border(`╭${"─".repeat(innerWidth)}╮`) : `${border("╭─ ")}${label}${border(` ${topFill}╮`)}`;
|
|
308
|
+
if (height === 1) return [top];
|
|
309
|
+
|
|
310
|
+
const visibleContent = content.slice(0, Math.max(0, height - 2));
|
|
311
|
+
while (visibleContent.length < height - 2) visibleContent.push("");
|
|
312
|
+
const row = (text: string): string => `${border("│")}${middleTruncateToWidth(` ${text}`, innerWidth, true)}${border("│")}`;
|
|
313
|
+
return [top, ...visibleContent.map(row), border(`╰${"─".repeat(innerWidth)}╯`)];
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
private frame(content: string[], width: number, height: number): string[] {
|
|
317
|
+
const frameWidth = Math.max(1, width);
|
|
318
|
+
const innerHeight = height - 2;
|
|
319
|
+
const border = (text: string): string => this.theme.fg("border", text);
|
|
320
|
+
if (frameWidth < 3) {
|
|
321
|
+
const row = border("│".repeat(frameWidth));
|
|
322
|
+
return [border(frameWidth === 1 ? "╭" : "╭╮"), ...Array.from({ length: innerHeight }, () => row), border(frameWidth === 1 ? "╰" : "╰╯")];
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
const innerWidth = frameWidth - 2;
|
|
326
|
+
const visibleContent = content.slice(0, innerHeight);
|
|
327
|
+
while (visibleContent.length < innerHeight) visibleContent.push("");
|
|
328
|
+
const row = (text: string): string => `${border("│")}${middleTruncateToWidth(text, innerWidth, true)}${border("│")}`;
|
|
329
|
+
return [border(`╭${"─".repeat(innerWidth)}╮`), ...visibleContent.map(row), border(`╰${"─".repeat(innerWidth)}╯`)];
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
export async function openTeamOverview(context: ExtensionCommandContext, teamSource: TeamSnapshotSource): Promise<void> {
|
|
334
|
+
if (context.mode !== "tui") {
|
|
335
|
+
context.ui.notify("/team is available only in interactive mode.", "warning");
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
await context.ui.custom<void>(
|
|
339
|
+
(tui, theme, _keybindings, done) => new TeamOverviewOverlay(tui, theme, teamSource, done),
|
|
340
|
+
overlayOptions,
|
|
341
|
+
);
|
|
342
|
+
}
|