@giladbarnea/pi-simple-team 1.0.2 → 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/index.ts +20 -15
- package/package.json +1 -1
- package/render-support/glyphs.ts +2 -0
- package/render.ts +252 -67
- package/teamlog.ts +6 -1
package/index.ts
CHANGED
|
@@ -344,6 +344,19 @@ function updateStatus(team: TeamState, participant: string, word?: string, phras
|
|
|
344
344
|
team.statuses.set(participant, status(word ?? previous.word, phrase ?? previous.phrase));
|
|
345
345
|
}
|
|
346
346
|
|
|
347
|
+
/** Pure status reads are meta-actions and stay out of the log, like teamlog reads. */
|
|
348
|
+
function logStatusDeclaration(team: TeamState, participant: string, word?: string, phrase?: string): void {
|
|
349
|
+
if (word === undefined && phrase === undefined) return;
|
|
350
|
+
appendTeamLog(team, {
|
|
351
|
+
team: team.name,
|
|
352
|
+
teammate: participant,
|
|
353
|
+
direction: "runtime",
|
|
354
|
+
kind: "status",
|
|
355
|
+
summary: preview(`${word ?? ""} ${phrase ?? ""}`.trim()),
|
|
356
|
+
details: { word: word ?? "", phrase: phrase ?? "" },
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
|
|
347
360
|
function startTeammate(team: TeamState, teammateSpec: TeammateSpec, participants: string[]): TeammateState {
|
|
348
361
|
const teammateName = compactName(teammateSpec.name);
|
|
349
362
|
const thinking = teammateSpec.thinking ?? defaultThinkingLevel;
|
|
@@ -425,6 +438,7 @@ function startTeammate(team: TeamState, teammateSpec: TeammateSpec, participants
|
|
|
425
438
|
direction: "runtime",
|
|
426
439
|
kind: "spawn",
|
|
427
440
|
summary: `spawned ${teammate.name} (model=${teammate.model}, thinking=${teammate.thinking})`,
|
|
441
|
+
details: { model: teammate.model, thinking: teammate.thinking },
|
|
428
442
|
});
|
|
429
443
|
|
|
430
444
|
return teammate;
|
|
@@ -515,14 +529,10 @@ async function handleCallbackRequest(request: http.IncomingMessage, response: ht
|
|
|
515
529
|
}
|
|
516
530
|
|
|
517
531
|
if (tool === "teamstatus") {
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
direction: "runtime",
|
|
523
|
-
kind: "status",
|
|
524
|
-
summary: preview(`${String(args.word ?? "")} ${String(args.phrase ?? "")}`.trim()),
|
|
525
|
-
});
|
|
532
|
+
const word = args.word as string | undefined;
|
|
533
|
+
const phrase = args.phrase as string | undefined;
|
|
534
|
+
updateStatus(team, from, word, phrase);
|
|
535
|
+
logStatusDeclaration(team, from, word, phrase);
|
|
526
536
|
writeJson(response, 200, { team: team.name, status: formatStatus(team) });
|
|
527
537
|
return;
|
|
528
538
|
}
|
|
@@ -664,13 +674,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
664
674
|
}
|
|
665
675
|
const team = resolveTeam(owner, params.team);
|
|
666
676
|
updateStatus(team, "main", params.word, params.phrase);
|
|
667
|
-
|
|
668
|
-
team: team.name,
|
|
669
|
-
teammate: "main",
|
|
670
|
-
direction: "runtime",
|
|
671
|
-
kind: "status",
|
|
672
|
-
summary: preview(`${params.word ?? ""} ${params.phrase ?? ""}`.trim()),
|
|
673
|
-
});
|
|
677
|
+
logStatusDeclaration(team, "main", params.word, params.phrase);
|
|
674
678
|
return toolResult({ team: team.name, status: formatStatus(team) });
|
|
675
679
|
},
|
|
676
680
|
}),
|
|
@@ -709,6 +713,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
709
713
|
content: [{ type: "text" as const, text }],
|
|
710
714
|
details: {
|
|
711
715
|
team: team.name,
|
|
716
|
+
roster: [...team.members.keys()],
|
|
712
717
|
entries: page.entries,
|
|
713
718
|
totalMatched: page.totalMatched,
|
|
714
719
|
returned: page.returned,
|
package/package.json
CHANGED
package/render-support/glyphs.ts
CHANGED
|
@@ -108,6 +108,7 @@ export const GLYPHS = {
|
|
|
108
108
|
prompt: "π",
|
|
109
109
|
ellipsis: "…",
|
|
110
110
|
arrow: "→",
|
|
111
|
+
chevron: "❯",
|
|
111
112
|
codeBar: "▌",
|
|
112
113
|
},
|
|
113
114
|
ascii: {
|
|
@@ -124,6 +125,7 @@ export const GLYPHS = {
|
|
|
124
125
|
prompt: "pi",
|
|
125
126
|
ellipsis: "...",
|
|
126
127
|
arrow: "->",
|
|
128
|
+
chevron: ">",
|
|
127
129
|
codeBar: "|",
|
|
128
130
|
},
|
|
129
131
|
} as const;
|
package/render.ts
CHANGED
|
@@ -2,9 +2,9 @@ import { Markdown, type MarkdownTheme, truncateToWidth, wrapTextWithAnsi } from
|
|
|
2
2
|
|
|
3
3
|
import { padVisible, stableRenderWidth, visibleLength } from "./render-support/ansi.ts";
|
|
4
4
|
import { glyphs } from "./render-support/glyphs.ts";
|
|
5
|
-
import { stackPrefix, toolLabel, treeConnector, treeStem } from "./render-support/theme.ts";
|
|
6
|
-
import { plural, renderPendingCall, textContent } from "./render-support/text.ts";
|
|
7
|
-
import { timeOfDay, type TeamLogEntry
|
|
5
|
+
import { stackPrefix, toolLabel, treeConnector, treeGlyph, treeStem } from "./render-support/theme.ts";
|
|
6
|
+
import { commandExit, plural, renderPendingCall, textContent } from "./render-support/text.ts";
|
|
7
|
+
import { timeOfDay, type TeamLogEntry } from "./teamlog.ts";
|
|
8
8
|
|
|
9
9
|
export interface ThemeLike {
|
|
10
10
|
bold(text: string): string;
|
|
@@ -38,6 +38,7 @@ export interface TeamMessageDetails {
|
|
|
38
38
|
|
|
39
39
|
interface TeamLogRenderView {
|
|
40
40
|
team: string;
|
|
41
|
+
roster?: string[];
|
|
41
42
|
entries: TeamLogEntry[];
|
|
42
43
|
totalMatched: number;
|
|
43
44
|
returned: number;
|
|
@@ -227,38 +228,39 @@ export function teamShutdownLines(theme: ThemeLike, team: string, teammates: str
|
|
|
227
228
|
return [header, `${treeConnector(theme, "└")}${theme.fg("muted", teammates.join(glyphs().dot))}`];
|
|
228
229
|
}
|
|
229
230
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
const KIND_MARK_SPECS: Record<TeamLogKind, { mark: KindMarkName; token: string }> = {
|
|
233
|
-
spawn: { mark: "diamond", token: "accent" },
|
|
234
|
-
send: { mark: "arrow", token: "accent" },
|
|
235
|
-
deliver: { mark: "arrow", token: "muted" },
|
|
236
|
-
ack: { mark: "ok", token: "dim" },
|
|
237
|
-
status: { mark: "emptyBullet", token: "muted" },
|
|
238
|
-
agent_start: { mark: "bullet", token: "success" },
|
|
239
|
-
agent_end: { mark: "emptyBullet", token: "muted" },
|
|
240
|
-
tool_start: { mark: "emptyBullet", token: "dim" },
|
|
241
|
-
tool_end: { mark: "ok", token: "muted" },
|
|
242
|
-
main_message: { mark: "arrow", token: "success" },
|
|
243
|
-
stderr: { mark: "warn", token: "warning" },
|
|
244
|
-
exit: { mark: "warn", token: "warning" },
|
|
245
|
-
error: { mark: "fail", token: "error" },
|
|
246
|
-
};
|
|
231
|
+
const TEAMMATE_HUE_TOKENS = ["mdCode", "customMessageLabel", "mdHeading"] as const;
|
|
247
232
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
233
|
+
/**
|
|
234
|
+
* actorHueToken("main", ["scout"]) === "accent"; actorHueToken("scout", ["scout"]) === "mdCode"
|
|
235
|
+
*/
|
|
236
|
+
export function actorHueToken(name: string, roster: string[]): string {
|
|
237
|
+
if (name === "main") return "accent";
|
|
238
|
+
const index = roster.indexOf(name);
|
|
239
|
+
return index === -1 ? "text" : TEAMMATE_HUE_TOKENS[index % TEAMMATE_HUE_TOKENS.length]!;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
const DIM_SGR_OPEN = "\x1b[2m";
|
|
243
|
+
const DIM_SGR_CLOSE = "\x1b[22m";
|
|
244
|
+
|
|
245
|
+
type LogIcon = "chevron" | "arrow" | "bullet" | "diamond" | "warn" | "fail";
|
|
246
|
+
|
|
247
|
+
type LogDetail =
|
|
248
|
+
| { style: "text"; text: string }
|
|
249
|
+
| { style: "actors"; names: string[] }
|
|
250
|
+
| { style: "loud"; token: string; text: string };
|
|
251
|
+
|
|
252
|
+
interface LogAction {
|
|
253
|
+
sequence: number;
|
|
254
|
+
epochMilliseconds: number;
|
|
255
|
+
who: string;
|
|
256
|
+
icon: LogIcon;
|
|
257
|
+
iconToken: string;
|
|
258
|
+
action: string;
|
|
259
|
+
details: LogDetail[];
|
|
260
|
+
startEpoch?: number;
|
|
261
|
+
salient?: string;
|
|
262
|
+
recipients?: string[];
|
|
263
|
+
messageText?: string;
|
|
262
264
|
}
|
|
263
265
|
|
|
264
266
|
function inlineText(value: unknown): string {
|
|
@@ -266,55 +268,237 @@ function inlineText(value: unknown): string {
|
|
|
266
268
|
return text.replace(/\s+/g, " ").trim();
|
|
267
269
|
}
|
|
268
270
|
|
|
269
|
-
function
|
|
271
|
+
function rawResultText(result: unknown): string {
|
|
270
272
|
const content = (result as { content?: Array<{ type?: string; text?: string }> } | undefined)?.content;
|
|
271
273
|
const textPart = content?.find((part) => part?.type === "text" && typeof part.text === "string");
|
|
272
|
-
|
|
274
|
+
if (typeof textPart?.text === "string") return textPart.text;
|
|
275
|
+
return typeof result === "string" ? result : (JSON.stringify(result) ?? String(result));
|
|
273
276
|
}
|
|
274
277
|
|
|
275
|
-
function
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
278
|
+
function salientArg(args: unknown): string {
|
|
279
|
+
if (args && typeof args === "object" && !Array.isArray(args)) {
|
|
280
|
+
for (const value of Object.values(args)) {
|
|
281
|
+
if (typeof value === "string" && value.trim()) return inlineText(value);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
return inlineText(args);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
function failureReason(result: unknown): string {
|
|
288
|
+
const raw = rawResultText(result);
|
|
289
|
+
const exitCode = commandExit(raw);
|
|
290
|
+
if (exitCode !== null) return String(exitCode);
|
|
291
|
+
const firstLine = raw.split(/\r?\n/).find((line) => line.trim());
|
|
292
|
+
return firstLine?.trim() || "failed";
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
function textDetail(text: string): LogDetail {
|
|
296
|
+
return { style: "text", text };
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
function messageDetails(recipients: string[], text: string, interrupt: boolean): LogDetail[] {
|
|
300
|
+
const details: LogDetail[] = [{ style: "actors", names: recipients }];
|
|
301
|
+
if (interrupt) details.push({ style: "loud", token: "warning", text: "interrupt" });
|
|
302
|
+
details.push(textDetail(text));
|
|
303
|
+
return details;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
function durationText(startEpoch: number | undefined, endEpoch: number): string {
|
|
307
|
+
if (startEpoch === undefined) return "";
|
|
308
|
+
return `${Math.max(0, Math.round((endEpoch - startEpoch) / 1000))}s`;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/** Folds wire entries into one row per action: tool pairs close in place, sends group by sender+message, deliver/ack are absorbed. */
|
|
312
|
+
export function foldLogEntries(entries: TeamLogEntry[]): LogAction[] {
|
|
313
|
+
const ellipsis = glyphs().ellipsis;
|
|
314
|
+
const actions: LogAction[] = [];
|
|
315
|
+
const openTools = new Map<unknown, LogAction>();
|
|
316
|
+
const openTurns = new Map<string, LogAction>();
|
|
317
|
+
|
|
318
|
+
for (const entry of entries) {
|
|
319
|
+
const details = entry.details ?? {};
|
|
320
|
+
const who = entry.teammate ?? "main";
|
|
321
|
+
const base = { sequence: entry.sequence, epochMilliseconds: entry.epochMilliseconds, who };
|
|
322
|
+
|
|
323
|
+
if (entry.kind === "tool_start") {
|
|
324
|
+
const salient = salientArg(details.args);
|
|
325
|
+
const action: LogAction = {
|
|
326
|
+
...base,
|
|
327
|
+
icon: "chevron",
|
|
328
|
+
iconToken: "borderMuted",
|
|
329
|
+
action: String(details.toolName ?? "tool"),
|
|
330
|
+
details: [textDetail(ellipsis), textDetail(salient)],
|
|
331
|
+
startEpoch: entry.epochMilliseconds,
|
|
332
|
+
salient,
|
|
333
|
+
};
|
|
334
|
+
actions.push(action);
|
|
335
|
+
if (details.toolCallId !== undefined) openTools.set(details.toolCallId, action);
|
|
336
|
+
continue;
|
|
337
|
+
}
|
|
338
|
+
if (entry.kind === "tool_end") {
|
|
339
|
+
const isError = Boolean(details.isError);
|
|
340
|
+
const open = details.toolCallId === undefined ? undefined : openTools.get(details.toolCallId);
|
|
341
|
+
if (open) {
|
|
342
|
+
openTools.delete(details.toolCallId);
|
|
343
|
+
open.iconToken = isError ? "error" : "success";
|
|
344
|
+
const closing = [textDetail(durationText(open.startEpoch, entry.epochMilliseconds)), textDetail(open.salient ?? "")];
|
|
345
|
+
open.details = isError ? [{ style: "loud", token: "error", text: failureReason(details.result) }, ...closing] : closing;
|
|
346
|
+
continue;
|
|
347
|
+
}
|
|
348
|
+
actions.push({
|
|
349
|
+
...base,
|
|
350
|
+
icon: "chevron",
|
|
351
|
+
iconToken: isError ? "error" : "success",
|
|
352
|
+
action: String(details.toolName ?? "tool"),
|
|
353
|
+
details: isError ? [{ style: "loud", token: "error", text: failureReason(details.result) }] : [textDetail(inlineText(rawResultText(details.result)))],
|
|
354
|
+
});
|
|
355
|
+
continue;
|
|
356
|
+
}
|
|
357
|
+
if (entry.kind === "send") {
|
|
358
|
+
const from = typeof details.from === "string" ? details.from : who;
|
|
359
|
+
const to = String(details.to ?? "");
|
|
360
|
+
const interrupt = Boolean(details.interrupt);
|
|
361
|
+
const last = actions.at(-1);
|
|
362
|
+
if (last?.action === "message" && last.who === from && last.messageText === entry.summary && last.recipients && !last.recipients.includes(to)) {
|
|
363
|
+
last.recipients.push(to);
|
|
364
|
+
last.details = messageDetails(last.recipients, entry.summary, interrupt);
|
|
365
|
+
continue;
|
|
366
|
+
}
|
|
367
|
+
actions.push({
|
|
368
|
+
...base,
|
|
369
|
+
who: from,
|
|
370
|
+
icon: "arrow",
|
|
371
|
+
iconToken: "borderMuted",
|
|
372
|
+
action: "message",
|
|
373
|
+
recipients: [to],
|
|
374
|
+
messageText: entry.summary,
|
|
375
|
+
details: messageDetails([to], entry.summary, interrupt),
|
|
376
|
+
});
|
|
377
|
+
continue;
|
|
378
|
+
}
|
|
379
|
+
if (entry.kind === "deliver" || entry.kind === "ack") continue;
|
|
380
|
+
if (entry.kind === "main_message") {
|
|
381
|
+
actions.push({ ...base, icon: "arrow", iconToken: "borderMuted", action: "message", details: messageDetails(["main"], entry.summary, false) });
|
|
382
|
+
continue;
|
|
383
|
+
}
|
|
384
|
+
if (entry.kind === "status") {
|
|
385
|
+
const word = typeof details.word === "string" ? details.word : "";
|
|
386
|
+
const phrase = typeof details.phrase === "string" ? details.phrase : "";
|
|
387
|
+
actions.push({ ...base, icon: "bullet", iconToken: "borderMuted", action: "status", details: [textDetail(word), textDetail(phrase)] });
|
|
388
|
+
continue;
|
|
389
|
+
}
|
|
390
|
+
if (entry.kind === "agent_start") {
|
|
391
|
+
const action: LogAction = { ...base, icon: "diamond", iconToken: "borderMuted", action: "turn", details: [textDetail(ellipsis)], startEpoch: entry.epochMilliseconds };
|
|
392
|
+
actions.push(action);
|
|
393
|
+
openTurns.set(who, action);
|
|
394
|
+
continue;
|
|
395
|
+
}
|
|
396
|
+
if (entry.kind === "agent_end") {
|
|
397
|
+
const messageCount = typeof details.messageCount === "number" ? details.messageCount : undefined;
|
|
398
|
+
const countDetails = messageCount === undefined ? [] : [textDetail(plural(messageCount, "message"))];
|
|
399
|
+
const open = openTurns.get(who);
|
|
400
|
+
if (open) {
|
|
401
|
+
openTurns.delete(who);
|
|
402
|
+
open.details = [textDetail(durationText(open.startEpoch, entry.epochMilliseconds)), ...countDetails];
|
|
403
|
+
continue;
|
|
404
|
+
}
|
|
405
|
+
actions.push({ ...base, icon: "diamond", iconToken: "borderMuted", action: "turn", details: countDetails });
|
|
406
|
+
continue;
|
|
407
|
+
}
|
|
408
|
+
if (entry.kind === "spawn") {
|
|
409
|
+
actions.push({
|
|
410
|
+
...base,
|
|
411
|
+
icon: "diamond",
|
|
412
|
+
iconToken: "borderMuted",
|
|
413
|
+
action: "spawn",
|
|
414
|
+
details: [textDetail(typeof details.model === "string" ? details.model : ""), textDetail(typeof details.thinking === "string" ? details.thinking : "")],
|
|
415
|
+
});
|
|
416
|
+
continue;
|
|
417
|
+
}
|
|
418
|
+
if (entry.kind === "stderr" || entry.kind === "exit") {
|
|
419
|
+
actions.push({ ...base, icon: "warn", iconToken: "warning", action: entry.kind, details: [textDetail(entry.summary)] });
|
|
420
|
+
continue;
|
|
421
|
+
}
|
|
422
|
+
actions.push({ ...base, icon: "fail", iconToken: "error", action: "error", details: [{ style: "loud", token: "error", text: entry.summary }] });
|
|
281
423
|
}
|
|
282
|
-
|
|
283
|
-
|
|
424
|
+
return actions;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
function logIconGlyph(icon: LogIcon): string {
|
|
428
|
+
const g = glyphs();
|
|
429
|
+
const map: Record<LogIcon, string> = {
|
|
430
|
+
chevron: g.chevron,
|
|
431
|
+
arrow: g.arrow,
|
|
432
|
+
bullet: g.bullet.trim(),
|
|
433
|
+
diamond: g.diamond,
|
|
434
|
+
warn: g.warn,
|
|
435
|
+
fail: g.fail,
|
|
436
|
+
};
|
|
437
|
+
return map[icon];
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
function renderLogDetail(theme: ThemeLike, detail: LogDetail, roster: string[]): string {
|
|
441
|
+
if (detail.style === "text") return theme.fg("muted", detail.text);
|
|
442
|
+
if (detail.style === "actors") return detail.names.map((name) => theme.fg(actorHueToken(name, roster), name)).join(theme.fg("muted", ", "));
|
|
443
|
+
return theme.fg(detail.token, detail.text);
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
function logChrome(theme: ThemeLike, branch: "├" | "└", sequence: number, seqWidth: number, epochMilliseconds: number): string {
|
|
447
|
+
return theme.fg("borderMuted", `${treeGlyph(branch)}${padVisible(`#${sequence}`, seqWidth)} ${timeOfDay(epochMilliseconds)}`);
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
function actionRows(theme: ThemeLike, actions: LogAction[], roster: string[], hasFooter: boolean): string[] {
|
|
451
|
+
const g = glyphs();
|
|
452
|
+
const seqWidth = Math.max(...actions.map((action) => `#${action.sequence}`.length));
|
|
453
|
+
const whoWidth = Math.max(...actions.map((action) => action.who.length));
|
|
454
|
+
const actionWidth = Math.max(...actions.map((action) => action.action.length));
|
|
455
|
+
const iconWidth = Math.max(...actions.map((action) => visibleLength(logIconGlyph(action.icon))));
|
|
456
|
+
let previousWho: string | undefined;
|
|
457
|
+
return actions.map((action, index) => {
|
|
458
|
+
const branch = index === actions.length - 1 && !hasFooter ? "└" : "├";
|
|
459
|
+
let whoStyled = theme.fg(actorHueToken(action.who, roster), padVisible(action.who, whoWidth));
|
|
460
|
+
if (action.who === previousWho) whoStyled = `${DIM_SGR_OPEN}${whoStyled}${DIM_SGR_CLOSE}`;
|
|
461
|
+
previousWho = action.who;
|
|
462
|
+
const icon = theme.fg(action.iconToken, padVisible(logIconGlyph(action.icon), iconWidth));
|
|
463
|
+
const actionName = theme.fg("text", padVisible(action.action, actionWidth));
|
|
464
|
+
const dot = theme.fg("muted", g.dot);
|
|
465
|
+
const detailText = action.details
|
|
466
|
+
.filter((detail) => detail.style !== "text" || detail.text.length > 0)
|
|
467
|
+
.map((detail) => renderLogDetail(theme, detail, roster))
|
|
468
|
+
.join(dot);
|
|
469
|
+
return `${logChrome(theme, branch, action.sequence, seqWidth, action.epochMilliseconds)} ${whoStyled} ${icon} ${actionName}${detailText ? `${dot}${detailText}` : ""}`;
|
|
470
|
+
});
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
function filterStats(theme: ThemeLike, filters: Record<string, unknown>): string[] {
|
|
474
|
+
const stats: string[] = [];
|
|
475
|
+
for (const [key, value] of Object.entries(filters)) {
|
|
476
|
+
if (typeof value !== "string" || !value) continue;
|
|
477
|
+
if (key === "since") {
|
|
478
|
+
const parsed = Date.parse(value);
|
|
479
|
+
stats.push(theme.fg("borderMuted", `since ${Number.isFinite(parsed) ? timeOfDay(parsed) : value}`));
|
|
480
|
+
continue;
|
|
481
|
+
}
|
|
482
|
+
stats.push(theme.fg("borderMuted", `${key}=${value}`));
|
|
284
483
|
}
|
|
285
|
-
|
|
286
|
-
if (entry.kind === "stderr") return theme.fg("warning", entry.summary);
|
|
287
|
-
return entry.summary;
|
|
484
|
+
return stats;
|
|
288
485
|
}
|
|
289
486
|
|
|
290
487
|
export function teamLogLines(theme: ThemeLike, view: TeamLogRenderView): string[] {
|
|
291
488
|
const g = glyphs();
|
|
292
|
-
const
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
489
|
+
const actions = foldLogEntries(view.entries);
|
|
490
|
+
const stats = [
|
|
491
|
+
theme.fg("muted", plural(actions.length, "action")),
|
|
492
|
+
theme.fg("muted", view.returned === view.totalMatched ? plural(view.returned, "event") : `${view.returned} of ${view.totalMatched} events`),
|
|
493
|
+
...filterStats(theme, view.filters ?? {}),
|
|
494
|
+
];
|
|
296
495
|
const header = headerLine(theme, "Team Log", theme.fg("accent", view.team), stats);
|
|
297
496
|
if (view.entries.length === 0) return [header, `${treeConnector(theme, "└")}${theme.fg("muted", "no matching events")}`];
|
|
298
497
|
|
|
299
|
-
const seqWidth = Math.max(...view.entries.map((entry) => String(entry.sequence).length)) + 1;
|
|
300
|
-
const nameWidth = Math.max(...view.entries.map((entry) => (entry.teammate ?? "main").length));
|
|
301
|
-
const kindWidth = Math.max(...view.entries.map((entry) => entry.kind.length));
|
|
302
498
|
const footer = view.nextCursor
|
|
303
499
|
? `${treeConnector(theme, "└")}${theme.fg("muted", `${g.ellipsis} older events${g.dot}cursor "${view.nextCursor}"`)}`
|
|
304
500
|
: undefined;
|
|
305
|
-
const rows = view.
|
|
306
|
-
const branch = index === view.entries.length - 1 && !footer ? "└" : "├";
|
|
307
|
-
const mark = kindMark(entry);
|
|
308
|
-
return [
|
|
309
|
-
treeConnector(theme, branch),
|
|
310
|
-
theme.fg("dim", padVisible(`#${entry.sequence}`, seqWidth)),
|
|
311
|
-
` ${theme.fg("dim", timeOfDay(entry.epochMilliseconds))}`,
|
|
312
|
-
` ${theme.fg("accent", padVisible(entry.teammate ?? "main", nameWidth))}`,
|
|
313
|
-
` ${theme.fg(mark.token, padVisible(mark.glyph, 2))}`,
|
|
314
|
-
theme.fg("muted", padVisible(entry.kind, kindWidth)),
|
|
315
|
-
` ${entrySummary(theme, entry)}`,
|
|
316
|
-
].join("");
|
|
317
|
-
});
|
|
501
|
+
const rows = actionRows(theme, actions, view.roster ?? [], Boolean(footer));
|
|
318
502
|
return [header, ...rows, ...(footer ? [footer] : [])];
|
|
319
503
|
}
|
|
320
504
|
|
|
@@ -446,6 +630,7 @@ function resultLinesFor(tool: TeamToolName, theme: ThemeLike, args: Record<strin
|
|
|
446
630
|
const filters = (details.filters ?? {}) as Record<string, unknown>;
|
|
447
631
|
return teamLogLines(theme, {
|
|
448
632
|
team: String(details.team),
|
|
633
|
+
roster: (details.roster ?? []) as string[],
|
|
449
634
|
entries: (details.entries ?? []) as TeamLogEntry[],
|
|
450
635
|
totalMatched: Number(details.totalMatched ?? 0),
|
|
451
636
|
returned: Number(details.returned ?? 0),
|
package/teamlog.ts
CHANGED
|
@@ -191,6 +191,9 @@ export function renderTeamLogPage(view: TeamLogPageView): string {
|
|
|
191
191
|
return [header, columnHeader, ...rows, footer].join("\n");
|
|
192
192
|
}
|
|
193
193
|
|
|
194
|
+
/** Child team tools always emit a semantic entry (send/main_message/status), so their tool frames would be pure triplication. */
|
|
195
|
+
const TEAM_CHILD_TOOLS = new Set(["teamsend", "teammain", "teamstatus"]);
|
|
196
|
+
|
|
194
197
|
export function normalizeChildEvent(team: string, teammate: string, event: Record<string, unknown>): TeamLogEntryInput | undefined {
|
|
195
198
|
const type = event.type;
|
|
196
199
|
|
|
@@ -202,11 +205,12 @@ export function normalizeChildEvent(team: string, teammate: string, event: Recor
|
|
|
202
205
|
const messages = event.messages;
|
|
203
206
|
const messageCount = Array.isArray(messages) ? messages.length : undefined;
|
|
204
207
|
const summary = messageCount === undefined ? `${teammate} finished` : `${teammate} finished (${messageCount} message${messageCount === 1 ? "" : "s"})`;
|
|
205
|
-
return { team, teammate, direction: "runtime", kind: "agent_end", summary };
|
|
208
|
+
return { team, teammate, direction: "runtime", kind: "agent_end", summary, details: messageCount === undefined ? undefined : { messageCount } };
|
|
206
209
|
}
|
|
207
210
|
|
|
208
211
|
if (type === "tool_execution_start") {
|
|
209
212
|
const toolName = String(event.toolName ?? "tool");
|
|
213
|
+
if (TEAM_CHILD_TOOLS.has(toolName)) return undefined;
|
|
210
214
|
return {
|
|
211
215
|
team,
|
|
212
216
|
teammate,
|
|
@@ -219,6 +223,7 @@ export function normalizeChildEvent(team: string, teammate: string, event: Recor
|
|
|
219
223
|
|
|
220
224
|
if (type === "tool_execution_end") {
|
|
221
225
|
const toolName = String(event.toolName ?? "tool");
|
|
226
|
+
if (TEAM_CHILD_TOOLS.has(toolName)) return undefined;
|
|
222
227
|
const isError = Boolean(event.isError);
|
|
223
228
|
return {
|
|
224
229
|
team,
|