@giladbarnea/pi-simple-team 1.0.1 → 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/README.md CHANGED
@@ -1,11 +1,26 @@
1
+ <div align="center">
2
+
1
3
  # pi-simple-team
2
4
 
3
5
  > **The team extension with no features.**
4
6
 
5
- No roles. No org chart. No mailboxes. No routing rules.
7
+ [![pi extension](https://img.shields.io/badge/pi-extension-blueviolet)](https://github.com/earendil-works/pi)
8
+ [![npm version](https://img.shields.io/npm/v/%40giladbarnea%2Fpi-simple-team?logo=npm)](https://www.npmjs.com/package/@giladbarnea/pi-simple-team)
9
+ [![tests](https://img.shields.io/github/actions/workflow/status/giladbarnea/pi-simple-team/test.yml?branch=main&label=tests&logo=github)](https://github.com/giladbarnea/pi-simple-team/actions/workflows/test.yml)
10
+ [![license](https://img.shields.io/github/license/giladbarnea/pi-simple-team)](LICENSE)
11
+ [![TypeScript](https://img.shields.io/badge/TypeScript-3178C6?logo=typescript&logoColor=white)](https://www.typescriptlang.org/)
12
+ [![tested with Bun](https://img.shields.io/badge/tested_with-Bun-14151A?logo=bun&logoColor=white)](https://bun.sh/)
13
+
14
+ **No roles. No org chart. No mailboxes. No routing rules.**
6
15
 
7
16
  `pi-simple-team` spawns a flat team of Pi agents that can all talk to each other, like the responsible adults they are, **and then stays out of the way.**
8
17
 
18
+ </div>
19
+
20
+ ---
21
+
22
+
23
+
9
24
  ## Why
10
25
 
11
26
  The best work I've ever done happened in a small room with a few capable people, building something together.
@@ -14,53 +29,77 @@ Yell out "has anyone figured out the auth service yet?" instead of filing a "req
14
29
 
15
30
  Tap the person next to you and ask them to grind you on your idea.
16
31
 
17
- Nobody's nervous around the CEO. You started the thing together.
32
+ **That's the whole design. Not a swarm, not a company. *A room.***
33
+
34
+ ## Using `pi-simple-team`
35
+
36
+ Ask your main agent for a team.
37
+
38
+ **Throw a team at something important.**
39
+
40
+ **You:** "Create an implementer–reviewer team to complete `PLAN.md`."
41
+ **Main:** "Created the pair. They'll work through it together; they'll let me know when they're done."
42
+
43
+ **Follow the breach wherever it leads.**
18
44
 
19
- That's the whole design. Not a swarm, not a company. *A room.*
45
+ **You:** "Find how the model got into our systems and trace everything it touched."
46
+ **Main:** "Created an eight-agent incident team. They're tracing the intrusion from different angles, sharing new leads as they surface. The net will tighten around the model and take the shape of the blast radius."
47
+
48
+ <br>
49
+
50
+ ![Spawning a designer–adversary team, checking its status, and sending both teammates a shared instruction](screenshots/1.png)
51
+
52
+ <div align="center"><em><code>pi-simple-team</code> in the TUI.</em></div>
20
53
 
21
54
  ## The mechanics
22
55
 
23
- The team is *live*, *dynamic*, and *scales* in proportion to the task's complexity.
24
56
 
25
- It doesn't force itself into a pre-existing box. It maps itself to the shape of the problem space.
26
57
 
27
- Teammates react to each other, know what everyone else is on, and take the shape of the problem space — because no shape is imposed on them.
58
+ ### Push, not pull.
28
59
 
29
- ![A live team status map above its timestamped event log](screenshots/2.png)
60
+ - ✔ No inbox to forget.
61
+ - ✔ no polling to exhaust your context window.
30
62
 
31
- #### Push, not pull.
63
+ *{screenshot of Codex filling up the entire visible chat with countless* `Waiting agents to finish...`*}*
32
64
 
33
- No inbox to forget, no polling to exhaust your context window.
65
+ ### Messages arrive without breaking stride.
34
66
 
35
- Messages land like the ones you send your own agent:
67
+ - ⚡ Sub-second, when the recipient is idle.
68
+ - 🏎️ The moment the current bout of work ends, when busy.
36
69
 
37
- - Sub-second, when the recipient is idle.
38
- - The moment the current bout of work ends, when busy.
39
70
 
40
- #### Interrupts, when the situation calls for it.
41
71
 
42
- The scout spots a private SSH key not covered by .gitignore. The implementer's status: "preparing commit message". One interrupt later, the key never leaves the machine.
72
+ ### Statuses everyone can see.
43
73
 
44
- #### Statuses everyone can see.
74
+ Teammates publish a one-liner:
45
75
 
46
- Teammates publish a one-liner — "done, awaiting review". Your main agent reads the map instead of interviewing the team.
76
+ - "Done, 89 tests green, awaiting review".
77
+ - "Reading implementation, will finalize review in a few minutes"
47
78
 
48
- #### Work in the open.
79
+ Your main agent calls `teamstatus` and understands exactly what's going on without asking and cluttering the teammates' context.
49
80
 
50
- Every team action lands in a timestamped, filterable log. Main agent reads it to catch up rather than calling a status meeting.
81
+ ### Interrupts, when the situation calls for it.
51
82
 
52
- ![Spawning a designer–adversary team, checking its status, and sending both teammates a shared instruction](screenshots/1.png)
83
+ *Team has finished a production hotfix and started to wrap up.*
53
84
 
54
- #### Teams shaped by the task.
85
+ - Security scout spots a private SSH key not covered by `.gitignore`.
86
+ - At the same time, Release teammate sets status: "Ran `git add .`, preparing commit and push."
87
+ - Scout immediately interrupts them. Key never leaves the machine. Developer keeps their job.
55
88
 
56
- One shared briefing, an individual prompt per teammate. Flat by default; if the task wants a reviewer gate or a lead, your main agent prompts it into being — that's a sentence, not a framework.
57
89
 
58
- ## Tools
59
90
 
60
- | Where | Tools |
61
- | ------------ | ---------------------------------------------------------------------------- |
62
- | Main session | `team_spawn`, `teamsend`, `teamstatus`, `teamlog`, `team_shutdown` |
63
- | Teammates | `teamsend` (anyone → anyone, optional `interrupt`), `teammain`, `teamstatus` |
91
+ ### Complete observability by design.
92
+
93
+ The main agent can access one exhaustive, **timestamped history** of tool calls, messages, and lifecycle events, **recorded by the harness itself.**
94
+
95
+ Main can filter and page that shared timeline on demand.
96
+
97
+ Useful for tracing a failure *across* teammates—without asking anyone to reconstruct it from memory.
98
+
99
+ <br>
100
+
101
+ ![A live team status map above its timestamped event log](screenshots/2.png)
102
+ <div align="center"><em>Visual representation of the team log.</em></div>
64
103
 
65
104
  ## Install
66
105
 
@@ -68,4 +107,36 @@ One shared briefing, an individual prompt per teammate. Flat by default; if the
68
107
  pi install npm:@giladbarnea/pi-simple-team
69
108
  ```
70
109
 
71
- That's it.
110
+
111
+
112
+ ## Tools
113
+
114
+
115
+ Kept minimal:
116
+
117
+
118
+ | Role | For | Tools |
119
+ | -------------- | -------------- | ----------------------------- |
120
+ | **Main agent** | Team lifecycle | `team_spawn`, `team_shutdown` |
121
+ | | With team | `teamsend` |
122
+ | | On team | `teamstatus`, `teamlog` |
123
+ | **Teammates** | With teammates | `teamsend` |
124
+ | | With main | `teammain` |
125
+ | | For everyone | `teamstatus` |
126
+
127
+
128
+ ---
129
+
130
+
131
+
132
+ ## Roadmap
133
+
134
+
135
+
136
+ ### User involvement track
137
+
138
+ Slash commands for:
139
+
140
+ - [ ] 💠 Live control panel.
141
+ - [ ] 👋 Joining and steering teams.
142
+ - [ ] 🪄 Spawning teams directly.
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
- updateStatus(team, from, args.word as string | undefined, args.phrase as string | undefined);
519
- appendTeamLog(team, {
520
- team: team.name,
521
- teammate: from,
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
- appendTeamLog(team, {
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@giladbarnea/pi-simple-team",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "A flat, live team of Pi agents.",
5
5
  "keywords": [
6
6
  "pi-package",
@@ -23,6 +23,8 @@
23
23
  "files": [
24
24
  "*.ts",
25
25
  "render-support",
26
+ "screenshots/1.png",
27
+ "screenshots/2.png",
26
28
  "README.md",
27
29
  "LICENSE"
28
30
  ],
@@ -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, type TeamLogKind } from "./teamlog.ts";
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
- type KindMarkName = "arrow" | "bullet" | "diamond" | "emptyBullet" | "fail" | "ok" | "warn";
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
- export function kindMark(entry: Pick<TeamLogEntry, "kind" | "details">): { glyph: string; token: string } {
249
- const failedToolEnd = entry.kind === "tool_end" && Boolean(entry.details?.isError);
250
- const spec = failedToolEnd ? { mark: "fail" as const, token: "error" } : KIND_MARK_SPECS[entry.kind];
251
- const g = glyphs();
252
- const marks: Record<KindMarkName, string> = {
253
- arrow: g.arrow,
254
- bullet: g.bullet.trim(),
255
- diamond: g.diamond,
256
- emptyBullet: g.emptyBullet.trim(),
257
- fail: g.fail,
258
- ok: g.ok,
259
- warn: g.warn,
260
- };
261
- return { glyph: marks[spec.mark], token: spec.token };
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 toolResultText(result: unknown): string {
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
- return inlineText(textPart?.text ?? result);
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 entrySummary(theme: ThemeLike, entry: TeamLogEntry): string {
276
- const details = entry.details ?? {};
277
- if (entry.kind === "tool_start") return `${String(details.toolName ?? "tool")} ${theme.fg("dim", inlineText(details.args))}`;
278
- if (entry.kind === "tool_end") {
279
- const token = details.isError ? "error" : "dim";
280
- return `${String(details.toolName ?? "tool")} ${theme.fg(token, toolResultText(details.result))}`;
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
- if ((entry.kind === "send" || entry.kind === "deliver") && typeof details.from === "string") {
283
- return `${theme.fg("dim", `${details.from} ${glyphs().arrow} `)}${entry.summary}`;
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
- if (entry.kind === "error") return theme.fg("error", entry.summary);
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 stats = [theme.fg("muted", `${view.returned} of ${view.totalMatched} events`)];
293
- for (const [key, value] of Object.entries(view.filters ?? {})) {
294
- if (typeof value === "string" && value) stats.push(theme.fg("dim", `${key}=${value}`));
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.entries.map((entry, index) => {
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),
Binary file
Binary file
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,