@giladbarnea/pi-simple-team 1.0.2 → 1.0.4
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/child-tools.ts +10 -8
- package/index.ts +31 -22
- package/package.json +1 -1
- package/render-support/glyphs.ts +2 -0
- package/render.ts +252 -67
- package/teamlog.ts +6 -1
package/child-tools.ts
CHANGED
|
@@ -63,15 +63,15 @@ export function registerChildTools(pi: ExtensionAPI, config: ChildRuntimeConfig)
|
|
|
63
63
|
defineTool({
|
|
64
64
|
name: "teamsend",
|
|
65
65
|
label: "Team Send",
|
|
66
|
-
description: "Send a message to
|
|
66
|
+
description: "Send a message to teammate(s) (not main). To message the main agent, use teammain. Returns once the runtime accepts the send request, not after recipients reply.",
|
|
67
67
|
promptSnippet: "Send a message to teammate(s)",
|
|
68
68
|
promptGuidelines: [
|
|
69
|
-
"Use teamsend to talk to teammates.
|
|
69
|
+
"Use teamsend to talk to teammates. From your POV (sender), it is fire-and-forget. From the recipient’s POV, it’s pushed to context as soon as possible.",
|
|
70
70
|
],
|
|
71
71
|
parameters: Type.Object({
|
|
72
72
|
to: Type.Array(Type.String(), { description: "Recipient teammate names" }),
|
|
73
73
|
message: Type.String({ description: "Message to send" }),
|
|
74
|
-
interrupt: Type.Optional(Type.Boolean({ description: "Abort busy recipients before delivering this message" })),
|
|
74
|
+
interrupt: Type.Optional(Type.Boolean({ description: "Abort busy recipients before delivering this message." })),
|
|
75
75
|
}),
|
|
76
76
|
async execute(_toolCallId, params, signal) {
|
|
77
77
|
return toolResult(await callParent(config, "teamsend", params, signal));
|
|
@@ -79,13 +79,14 @@ export function registerChildTools(pi: ExtensionAPI, config: ChildRuntimeConfig)
|
|
|
79
79
|
}),
|
|
80
80
|
);
|
|
81
81
|
|
|
82
|
+
// TODO: should be renamed `sendmain` across the project.
|
|
82
83
|
pi.registerTool(
|
|
83
84
|
defineTool({
|
|
84
85
|
name: "teammain",
|
|
85
86
|
label: "Team Main",
|
|
86
|
-
description: "Send a message to the main agent
|
|
87
|
-
promptSnippet: "Send a message to the main agent
|
|
88
|
-
promptGuidelines: ["Use teammain to update or ask the main agent.
|
|
87
|
+
description: "Send a message to the main agent.",
|
|
88
|
+
promptSnippet: "Send a message to the main agent.",
|
|
89
|
+
promptGuidelines: ["Use teammain to update or ask the main agent. Main agent sees the big picture and has been aware of the team’s actions and status updates since the team was created."],
|
|
89
90
|
parameters: Type.Object({
|
|
90
91
|
message: Type.String({ description: "Message to send to the main agent" }),
|
|
91
92
|
}),
|
|
@@ -101,9 +102,10 @@ export function registerChildTools(pi: ExtensionAPI, config: ChildRuntimeConfig)
|
|
|
101
102
|
label: "Team Status",
|
|
102
103
|
description: "Set your public status and read everyone's public status.",
|
|
103
104
|
promptSnippet: "Set/read the public team status map",
|
|
105
|
+
// TODO: If this typing system supports it, I want gerund and phrase optionality to be a XOR
|
|
104
106
|
parameters: Type.Object({
|
|
105
|
-
|
|
106
|
-
phrase: Type.Optional(Type.String({ description: "Short status phrase" })),
|
|
107
|
+
gerund: Type.Optional(Type.String({ description: "One-word gerund status." })),
|
|
108
|
+
phrase: Type.Optional(Type.String({ description: "Short status phrase. Verb-oriented." })),
|
|
107
109
|
}),
|
|
108
110
|
async execute(_toolCallId, params, signal) {
|
|
109
111
|
return toolResult(await callParent(config, "teamstatus", params, signal));
|
package/index.ts
CHANGED
|
@@ -344,6 +344,20 @@ 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
|
+
|
|
360
|
+
// TODO: participants is unused. Smell.
|
|
347
361
|
function startTeammate(team: TeamState, teammateSpec: TeammateSpec, participants: string[]): TeammateState {
|
|
348
362
|
const teammateName = compactName(teammateSpec.name);
|
|
349
363
|
const thinking = teammateSpec.thinking ?? defaultThinkingLevel;
|
|
@@ -425,6 +439,7 @@ function startTeammate(team: TeamState, teammateSpec: TeammateSpec, participants
|
|
|
425
439
|
direction: "runtime",
|
|
426
440
|
kind: "spawn",
|
|
427
441
|
summary: `spawned ${teammate.name} (model=${teammate.model}, thinking=${teammate.thinking})`,
|
|
442
|
+
details: { model: teammate.model, thinking: teammate.thinking },
|
|
428
443
|
});
|
|
429
444
|
|
|
430
445
|
return teammate;
|
|
@@ -515,14 +530,10 @@ async function handleCallbackRequest(request: http.IncomingMessage, response: ht
|
|
|
515
530
|
}
|
|
516
531
|
|
|
517
532
|
if (tool === "teamstatus") {
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
direction: "runtime",
|
|
523
|
-
kind: "status",
|
|
524
|
-
summary: preview(`${String(args.word ?? "")} ${String(args.phrase ?? "")}`.trim()),
|
|
525
|
-
});
|
|
533
|
+
const gerund = args.gerund as string | undefined;
|
|
534
|
+
const phrase = args.phrase as string | undefined;
|
|
535
|
+
updateStatus(team, from, gerund, phrase);
|
|
536
|
+
logStatusDeclaration(team, from, gerund, phrase);
|
|
526
537
|
writeJson(response, 200, { team: team.name, status: formatStatus(team) });
|
|
527
538
|
return;
|
|
528
539
|
}
|
|
@@ -557,12 +568,13 @@ export default function (pi: ExtensionAPI) {
|
|
|
557
568
|
closeCallbackServerIfUnused();
|
|
558
569
|
});
|
|
559
570
|
|
|
571
|
+
// TODO: Should also "start" the entire team automatically, making `teammate_start` redundant. Solves the respective smell.
|
|
560
572
|
pi.registerTool(
|
|
561
573
|
defineTool({
|
|
562
574
|
name: "team_spawn",
|
|
563
575
|
label: "Team Spawn",
|
|
564
|
-
description: "Spawn a persistent team of RPC Pi teammates with fresh context windows. The main agent is included automatically; do not specify it as a teammate.",
|
|
565
|
-
promptSnippet: "Spawn persistent RPC Pi teammate processes",
|
|
576
|
+
description: "Spawn a persistent team of RPC Pi teammates with fresh context windows. The main agent (you) is included automatically; do not specify it as a teammate.",
|
|
577
|
+
promptSnippet: "Spawn persistent RPC Pi teammate processes. Currently, manually ‘starting’ the teammates is required after spawn. Unless required, don’t fill up your time by repeatedly busy-polling team information. Don’t bash sleep to wait for progress; instead, set your status to advertise that you are counting on teammates to send you a message updating important milestones or request for help, and that otherwise you are staying idle; Send this actively to the team; Then end your turn by sending a simple message to the user, and finally stay put.",
|
|
566
578
|
renderShell: "self",
|
|
567
579
|
renderCall: (args, theme, context) => renderTeamToolCall("team_spawn", args, theme, context),
|
|
568
580
|
renderResult: (result, options, theme, context) => renderTeamToolResult("team_spawn", result, options, theme, context),
|
|
@@ -623,7 +635,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
623
635
|
defineTool({
|
|
624
636
|
name: "teamsend",
|
|
625
637
|
label: "Team Send",
|
|
626
|
-
description: "Send a message from main to teammate(s). Fire-and-forget; does not wait for replies.",
|
|
638
|
+
description: "Send a message from main to teammate(s). Fire-and-forget; does not wait for replies. Teammates will send you messages as they deem appropriate by way of push.",
|
|
627
639
|
promptSnippet: "Send a message from main to teammate(s)",
|
|
628
640
|
renderShell: "self",
|
|
629
641
|
renderCall: (args, theme, context) => renderTeamToolCall("teamsend", args, theme, context),
|
|
@@ -655,27 +667,23 @@ export default function (pi: ExtensionAPI) {
|
|
|
655
667
|
renderResult: (result, options, theme, context) => renderTeamToolResult("teamstatus", result, options, theme, context),
|
|
656
668
|
parameters: Type.Object({
|
|
657
669
|
team: Type.Optional(Type.String({ description: "Team name; optional for listing all statuses or when exactly one team exists" })),
|
|
658
|
-
|
|
659
|
-
|
|
670
|
+
// TODO: make gerund and phrase optionality a XOR.
|
|
671
|
+
gerund: Type.Optional(Type.String({ description: "Set one-word gerund main status" })),
|
|
672
|
+
phrase: Type.Optional(Type.String({ description: "Short main status verb-oriented phrase." })),
|
|
660
673
|
}),
|
|
661
674
|
async execute(_toolCallId, params) {
|
|
662
|
-
if (!params.team && params.
|
|
675
|
+
if (!params.team && params.gerund === undefined && params.phrase === undefined) {
|
|
663
676
|
return toolResult({ teams: allStatuses(owner) });
|
|
664
677
|
}
|
|
665
678
|
const team = resolveTeam(owner, params.team);
|
|
666
|
-
updateStatus(team, "main", params.
|
|
667
|
-
|
|
668
|
-
team: team.name,
|
|
669
|
-
teammate: "main",
|
|
670
|
-
direction: "runtime",
|
|
671
|
-
kind: "status",
|
|
672
|
-
summary: preview(`${params.word ?? ""} ${params.phrase ?? ""}`.trim()),
|
|
673
|
-
});
|
|
679
|
+
updateStatus(team, "main", params.gerund, params.phrase);
|
|
680
|
+
logStatusDeclaration(team, "main", params.gerund, params.phrase);
|
|
674
681
|
return toolResult({ team: team.name, status: formatStatus(team) });
|
|
675
682
|
},
|
|
676
683
|
}),
|
|
677
684
|
);
|
|
678
685
|
|
|
686
|
+
// TODO: main could use more automatic meta/discoverability information in the return payload. To help orient around what has been read already, what hasn't been read, inside and outside the filtered space, how long is the log, etc.
|
|
679
687
|
pi.registerTool(
|
|
680
688
|
defineTool({
|
|
681
689
|
name: "teamlog",
|
|
@@ -709,6 +717,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
709
717
|
content: [{ type: "text" as const, text }],
|
|
710
718
|
details: {
|
|
711
719
|
team: team.name,
|
|
720
|
+
roster: [...team.members.keys()],
|
|
712
721
|
entries: page.entries,
|
|
713
722
|
totalMatched: page.totalMatched,
|
|
714
723
|
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,
|