@giladbarnea/pi-simple-team 1.0.33 → 1.0.34
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 +5 -5
- package/package.json +2 -2
- package/render.ts +44 -24
- package/team-ui.ts +7 -4
- package/teamlog.ts +39 -5
package/index.ts
CHANGED
|
@@ -23,7 +23,7 @@ import {
|
|
|
23
23
|
type TeamManifest,
|
|
24
24
|
type TeamManifestMember,
|
|
25
25
|
} from "./team-registry.ts";
|
|
26
|
-
import { appendTeamLog, filterTeamLog, normalizeChildEvent,
|
|
26
|
+
import { appendTeamLog, filterTeamLog, normalizeChildEvent, pageTeamLog, preview, renderTeamLogPage, type TeamLogEntry } from "./teamlog.ts";
|
|
27
27
|
import { renderTeamMessage, renderTeamToolCall, renderTeamToolResult, type TeamMessageDetails } from "./render.ts";
|
|
28
28
|
import { openTeamOverview, type TeamSnapshot } from "./team-ui.ts";
|
|
29
29
|
import { StringEnum } from "@earendil-works/pi-ai";
|
|
@@ -103,7 +103,7 @@ let callbackServer: http.Server | undefined;
|
|
|
103
103
|
let callbackUrl = "";
|
|
104
104
|
|
|
105
105
|
function status(word: string, phrase: string): TeamStatus {
|
|
106
|
-
return { word, phrase, updated:
|
|
106
|
+
return { word, phrase, updated: new Date().toISOString() };
|
|
107
107
|
}
|
|
108
108
|
|
|
109
109
|
function compactName(name: string): string {
|
|
@@ -169,7 +169,7 @@ async function deliverMessage(team: TeamState, from: string, recipient: Teammate
|
|
|
169
169
|
body: JSON.stringify({
|
|
170
170
|
token: callbackToken,
|
|
171
171
|
tool: "deliver",
|
|
172
|
-
args: { team: team.name, from, to: recipient.name, sentAt:
|
|
172
|
+
args: { team: team.name, from, to: recipient.name, sentAt: new Date().toISOString(), message, formattedMessage, interrupt },
|
|
173
173
|
}),
|
|
174
174
|
signal: controller.signal,
|
|
175
175
|
});
|
|
@@ -735,7 +735,7 @@ async function handleCallbackRequest(request: http.IncomingMessage, response: ht
|
|
|
735
735
|
|
|
736
736
|
if (tool === "teammain") {
|
|
737
737
|
const rawMessage = String(args.message ?? "");
|
|
738
|
-
const details: TeamMessageDetails = { team: team.name, from, sentAt:
|
|
738
|
+
const details: TeamMessageDetails = { team: team.name, from, sentAt: new Date().toISOString(), message: rawMessage };
|
|
739
739
|
appendTeamLog(team, {
|
|
740
740
|
team: team.name,
|
|
741
741
|
teammate: from,
|
|
@@ -925,7 +925,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
925
925
|
mainSessionFile,
|
|
926
926
|
members: new Map(),
|
|
927
927
|
statuses: new Map([["main", status("available", "Main agent")]]),
|
|
928
|
-
created:
|
|
928
|
+
created: new Date().toISOString(),
|
|
929
929
|
lease,
|
|
930
930
|
log: [],
|
|
931
931
|
nextLogSequence: 1,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@giladbarnea/pi-simple-team",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.34",
|
|
4
4
|
"description": "A flat, live team of Pi agents.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package",
|
|
@@ -49,6 +49,6 @@
|
|
|
49
49
|
"extensions": [
|
|
50
50
|
"./index.ts"
|
|
51
51
|
],
|
|
52
|
-
"image": "https://raw.githubusercontent.com/giladbarnea/pi-simple-team/main/screenshots/
|
|
52
|
+
"image": "https://raw.githubusercontent.com/giladbarnea/pi-simple-team/main/screenshots/abstract-tool-output-preview-640.png"
|
|
53
53
|
}
|
|
54
54
|
}
|
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,
|
|
5
|
+
import { stackPrefix, toolLabel, treeConnector, treeStem } from "./render-support/theme.ts";
|
|
6
6
|
import { commandExit, plural, renderPendingCall, textContent } from "./render-support/text.ts";
|
|
7
|
-
import { monthDay,
|
|
7
|
+
import { futureTime, monthDay, relativeTime, timeOfDay, type TeamLogEntry } from "./teamlog.ts";
|
|
8
8
|
|
|
9
9
|
export interface ThemeLike {
|
|
10
10
|
bold(text: string): string;
|
|
@@ -45,6 +45,14 @@ interface TeamLogRenderView {
|
|
|
45
45
|
returned: number;
|
|
46
46
|
nextCursor?: string;
|
|
47
47
|
filters?: Record<string, unknown>;
|
|
48
|
+
nowMilliseconds?: number;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Sessions persisted before the ISO switch carry pre-formatted timestamps; those pass through raw. */
|
|
52
|
+
export function relativeTimeText(timestamp: string): string {
|
|
53
|
+
if (!timestamp.includes("T")) return timestamp;
|
|
54
|
+
const parsed = Date.parse(timestamp);
|
|
55
|
+
return Number.isFinite(parsed) ? relativeTime(parsed, Date.now()) : timestamp;
|
|
48
56
|
}
|
|
49
57
|
|
|
50
58
|
/** A rendered line with optional wrapping or right-aligned layout metadata. */
|
|
@@ -182,7 +190,7 @@ function memberRows(theme: ThemeLike, statuses: Record<string, TeamStatusView>,
|
|
|
182
190
|
const entry = statuses[name]!;
|
|
183
191
|
const branch = index === names.length - 1 ? "└" : "├";
|
|
184
192
|
const left = `${indent}${treeConnector(theme, branch)}${theme.fg(actorHueToken(name, roster), padVisible(name, nameWidth))} ${theme.fg(statusWordToken(entry.word), padVisible(entry.word, wordWidth))} ${entry.phrase}`;
|
|
185
|
-
const right = theme.fg("dim", entry.updated);
|
|
193
|
+
const right = theme.fg("dim", relativeTimeText(entry.updated));
|
|
186
194
|
return { left, right };
|
|
187
195
|
});
|
|
188
196
|
}
|
|
@@ -277,8 +285,8 @@ function teamListMemberName(theme: ThemeLike, teamView: TeamListTeamView, member
|
|
|
277
285
|
}
|
|
278
286
|
|
|
279
287
|
function teamListTimestamp(teamView: TeamListTeamView): string {
|
|
280
|
-
if (teamView.state === "dormant" && teamView.expiresAt) return `expires ${
|
|
281
|
-
return `updated ${
|
|
288
|
+
if (teamView.state === "dormant" && teamView.expiresAt) return `expires ${futureTime(Date.parse(teamView.expiresAt), Date.now())}`;
|
|
289
|
+
return `updated ${relativeTime(Date.parse(teamView.updatedAt), Date.now())}`;
|
|
282
290
|
}
|
|
283
291
|
|
|
284
292
|
export function teamListLines(theme: ThemeLike, teamViews: TeamListTeamView[], roster: string[] = []): TeamLine[] {
|
|
@@ -552,19 +560,37 @@ function renderLogDetail(theme: ThemeLike, detail: LogDetail, roster: string[]):
|
|
|
552
560
|
return theme.fg(detail.token, detail.text);
|
|
553
561
|
}
|
|
554
562
|
|
|
555
|
-
|
|
556
|
-
|
|
563
|
+
const LOG_ROW_INDENT = " ";
|
|
564
|
+
|
|
565
|
+
function logChrome(theme: ThemeLike, sequence: number, seqWidth: number, epochMilliseconds: number): string {
|
|
566
|
+
return theme.fg("borderMuted", `${LOG_ROW_INDENT}${padVisible(`#${sequence}`, seqWidth)} ${timeOfDay(epochMilliseconds)}`);
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
function sameLocalDay(a: number, b: number): boolean {
|
|
570
|
+
return new Date(a).toDateString() === new Date(b).toDateString();
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
function dayDividerLine(theme: ThemeLike, epochMilliseconds: number): string {
|
|
574
|
+
const rule = glyphs().line;
|
|
575
|
+
return `${LOG_ROW_INDENT}${theme.fg("borderMuted", `${rule.repeat(2)} ${monthDay(epochMilliseconds)} ${rule.repeat(30)}`)}`;
|
|
557
576
|
}
|
|
558
577
|
|
|
559
|
-
|
|
578
|
+
/** Log rows keep an absolute HH:MM:SS grammar; day dividers carry the date whenever a row is not from "today". */
|
|
579
|
+
function actionRows(theme: ThemeLike, actions: LogAction[], roster: string[], nowMilliseconds: number): string[] {
|
|
560
580
|
const g = glyphs();
|
|
561
581
|
const seqWidth = Math.max(...actions.map((action) => `#${action.sequence}`.length));
|
|
562
582
|
const whoWidth = Math.max(...actions.map((action) => action.who.length));
|
|
563
583
|
const actionWidth = Math.max(...actions.map((action) => action.action.length));
|
|
564
584
|
const iconWidth = Math.max(...actions.map((action) => visibleLength(logIconGlyph(action.icon))));
|
|
585
|
+
const rows: string[] = [];
|
|
565
586
|
let previousWho: string | undefined;
|
|
566
|
-
|
|
567
|
-
|
|
587
|
+
let previousEpoch = nowMilliseconds;
|
|
588
|
+
for (const action of actions) {
|
|
589
|
+
if (!sameLocalDay(action.epochMilliseconds, previousEpoch)) {
|
|
590
|
+
rows.push(dayDividerLine(theme, action.epochMilliseconds));
|
|
591
|
+
previousWho = undefined;
|
|
592
|
+
}
|
|
593
|
+
previousEpoch = action.epochMilliseconds;
|
|
568
594
|
let whoStyled = theme.fg(actorHueToken(action.who, roster), padVisible(action.who, whoWidth));
|
|
569
595
|
if (action.who === previousWho) whoStyled = `${DIM_SGR_OPEN}${whoStyled}${DIM_SGR_CLOSE}`;
|
|
570
596
|
previousWho = action.who;
|
|
@@ -575,8 +601,9 @@ function actionRows(theme: ThemeLike, actions: LogAction[], roster: string[], ha
|
|
|
575
601
|
.filter((detail) => detail.style !== "text" || detail.text.length > 0)
|
|
576
602
|
.map((detail) => renderLogDetail(theme, detail, roster))
|
|
577
603
|
.join(dot);
|
|
578
|
-
|
|
579
|
-
}
|
|
604
|
+
rows.push(`${logChrome(theme, action.sequence, seqWidth, action.epochMilliseconds)} ${whoStyled} ${icon} ${actionName}${detailText ? `${dot}${detailText}` : ""}`);
|
|
605
|
+
}
|
|
606
|
+
return rows;
|
|
580
607
|
}
|
|
581
608
|
|
|
582
609
|
function filterStats(theme: ThemeLike, filters: Record<string, unknown>, roster: string[]): string[] {
|
|
@@ -607,24 +634,17 @@ export function teamLogLines(theme: ThemeLike, view: TeamLogRenderView): string[
|
|
|
607
634
|
...filterStats(theme, view.filters ?? {}, view.roster ?? []),
|
|
608
635
|
];
|
|
609
636
|
const header = headerLine(theme, "Team Log", theme.fg("accent", view.team), stats);
|
|
610
|
-
if (view.entries.length === 0) return [header, `${
|
|
637
|
+
if (view.entries.length === 0) return [header, `${LOG_ROW_INDENT}${theme.fg("muted", "no matching events")}`];
|
|
611
638
|
|
|
612
639
|
const footer = view.nextCursor
|
|
613
|
-
? `${
|
|
640
|
+
? `${LOG_ROW_INDENT}${theme.fg("muted", `${g.ellipsis} older events${g.dot}cursor "${view.nextCursor}"`)}`
|
|
614
641
|
: undefined;
|
|
615
|
-
const rows = actionRows(theme, actions, view.roster ?? [],
|
|
642
|
+
const rows = actionRows(theme, actions, view.roster ?? [], view.nowMilliseconds ?? Date.now());
|
|
616
643
|
return [header, ...rows, ...(footer ? [footer] : [])];
|
|
617
644
|
}
|
|
618
645
|
|
|
619
646
|
export function teamMessageLines(theme: ThemeLike, details: TeamMessageDetails, roster: string[] = []): TeamLine[] {
|
|
620
|
-
|
|
621
|
-
const header = [
|
|
622
|
-
theme.fg("accent", `${g.diamond} `),
|
|
623
|
-
theme.fg(actorHueToken(details.from, roster), theme.bold(details.from)),
|
|
624
|
-
theme.fg("muted", ` ${g.arrow} ${details.to ?? "main"}`),
|
|
625
|
-
theme.fg("dim", `${g.dot}${details.team}${g.dot}${details.sentAt}`),
|
|
626
|
-
].join("");
|
|
627
|
-
return [header, ...quotedBody(theme, details.message, { lineLimit: Number.POSITIVE_INFINITY, barToken: "accent" })];
|
|
647
|
+
return [teamMessageHeader(theme, details, roster), ...quotedBody(theme, details.message, { lineLimit: Number.POSITIVE_INFINITY, barToken: "accent" })];
|
|
628
648
|
}
|
|
629
649
|
|
|
630
650
|
function teamMessageHeader(theme: ThemeLike, details: TeamMessageDetails, roster: string[]): string {
|
|
@@ -633,7 +653,7 @@ function teamMessageHeader(theme: ThemeLike, details: TeamMessageDetails, roster
|
|
|
633
653
|
theme.fg("accent", `${g.diamond} `),
|
|
634
654
|
theme.fg(actorHueToken(details.from, roster), theme.bold(details.from)),
|
|
635
655
|
theme.fg("muted", ` ${g.arrow} ${details.to ?? "main"}`),
|
|
636
|
-
theme.fg("dim", `${g.dot}${details.team}${g.dot}${details.sentAt}`),
|
|
656
|
+
theme.fg("dim", `${g.dot}${details.team}${g.dot}${relativeTimeText(details.sentAt)}`),
|
|
637
657
|
].join("");
|
|
638
658
|
}
|
|
639
659
|
|
package/team-ui.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { Key, matchesKey, SelectList, sliceByColumn, truncateToWidth, visibleWid
|
|
|
3
3
|
|
|
4
4
|
import {
|
|
5
5
|
actorHueToken,
|
|
6
|
+
relativeTimeText,
|
|
6
7
|
statusWordToken,
|
|
7
8
|
teamLineText,
|
|
8
9
|
teamLogLines,
|
|
@@ -82,13 +83,15 @@ function statusRows(theme: ThemeLike, statuses: Array<[string, TeamStatusView]>,
|
|
|
82
83
|
const contentWidth = Math.max(0, width - 1);
|
|
83
84
|
const nameWidth = Math.max(0, ...statuses.map(([name]) => visibleWidth(name)));
|
|
84
85
|
const wordWidth = Math.max(0, ...statuses.map(([, status]) => visibleWidth(status.word)));
|
|
85
|
-
const
|
|
86
|
+
const updatedTexts = statuses.map(([, status]) => relativeTimeText(status.updated));
|
|
87
|
+
const timestampWidth = Math.max(0, ...updatedTexts.map((text) => visibleWidth(text)));
|
|
86
88
|
const phraseWidth = Math.max(0, contentWidth - nameWidth - wordWidth - timestampWidth - 6);
|
|
87
89
|
|
|
88
|
-
return statuses.map(([name, status]) => {
|
|
90
|
+
return statuses.map(([name, status], index) => {
|
|
89
91
|
const styledName = theme.fg(actorHueToken(name, roster), name);
|
|
90
92
|
const styledWord = theme.fg(statusWordToken(status.word), status.word);
|
|
91
|
-
const
|
|
93
|
+
const updatedText = updatedTexts[index]!;
|
|
94
|
+
const timestamp = theme.fg("dim", `${" ".repeat(Math.max(0, timestampWidth - visibleWidth(updatedText)))}${updatedText}`);
|
|
92
95
|
const phrase = middleTruncateToWidth(status.phrase, phraseWidth, true);
|
|
93
96
|
return `${padVisible(styledName, nameWidth)} ${padVisible(styledWord, wordWidth)} ${phrase} ${timestamp}`;
|
|
94
97
|
});
|
|
@@ -257,7 +260,7 @@ class TeamOverviewOverlay implements Component {
|
|
|
257
260
|
|
|
258
261
|
const transport = team.showOnHerdrPanes ? "Herdr" : "RPC";
|
|
259
262
|
const metadata = [
|
|
260
|
-
`Created ${team.created}`,
|
|
263
|
+
`Created ${relativeTimeText(team.created)}`,
|
|
261
264
|
`${team.roster.length} teammate${team.roster.length === 1 ? "" : "s"}`,
|
|
262
265
|
transport,
|
|
263
266
|
`${team.log.length} retained event${team.log.length === 1 ? "" : "s"}`,
|
package/teamlog.ts
CHANGED
|
@@ -66,10 +66,6 @@ const MAX_LIMIT = 100;
|
|
|
66
66
|
const dateFormatter = new Intl.DateTimeFormat("en-US", { month: "long", day: "2-digit" });
|
|
67
67
|
const timeFormatter = new Intl.DateTimeFormat("en-GB", { hour: "2-digit", minute: "2-digit", second: "2-digit", hour12: false });
|
|
68
68
|
|
|
69
|
-
export function nowText(date: Date = new Date()): string {
|
|
70
|
-
return `${dateFormatter.format(date)}, ${timeFormatter.format(date)}`;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
69
|
export function timeOfDay(epochMilliseconds: number): string {
|
|
74
70
|
return timeFormatter.format(new Date(epochMilliseconds));
|
|
75
71
|
}
|
|
@@ -78,6 +74,44 @@ export function monthDay(epochMilliseconds: number): string {
|
|
|
78
74
|
return dateFormatter.format(new Date(epochMilliseconds));
|
|
79
75
|
}
|
|
80
76
|
|
|
77
|
+
const MINUTE_MILLISECONDS = 60_000;
|
|
78
|
+
const HOUR_MILLISECONDS = 60 * MINUTE_MILLISECONDS;
|
|
79
|
+
const DAY_MILLISECONDS = 24 * HOUR_MILLISECONDS;
|
|
80
|
+
const WEEK_MILLISECONDS = 7 * DAY_MILLISECONDS;
|
|
81
|
+
const MONTH_MILLISECONDS = 30 * DAY_MILLISECONDS;
|
|
82
|
+
|
|
83
|
+
/** formatElapsed(12 * 60_000) === "12m"; formatElapsed(33 * 3_600_000) === "1d 9h"; formatElapsed(5 * 86_400_000) === "5d" */
|
|
84
|
+
function formatElapsed(elapsedMilliseconds: number): string {
|
|
85
|
+
if (elapsedMilliseconds < HOUR_MILLISECONDS) return `${Math.max(1, Math.floor(elapsedMilliseconds / MINUTE_MILLISECONDS))}m`;
|
|
86
|
+
const hours = Math.floor(elapsedMilliseconds / HOUR_MILLISECONDS);
|
|
87
|
+
if (elapsedMilliseconds < 4 * HOUR_MILLISECONDS) {
|
|
88
|
+
const minutes = Math.floor((elapsedMilliseconds % HOUR_MILLISECONDS) / MINUTE_MILLISECONDS);
|
|
89
|
+
return `${hours}h ${String(minutes).padStart(2, "0")}m`;
|
|
90
|
+
}
|
|
91
|
+
if (elapsedMilliseconds < DAY_MILLISECONDS) return `${hours}h`;
|
|
92
|
+
if (elapsedMilliseconds < 2 * DAY_MILLISECONDS) return `1d ${Math.floor((elapsedMilliseconds % DAY_MILLISECONDS) / HOUR_MILLISECONDS)}h`;
|
|
93
|
+
if (elapsedMilliseconds < WEEK_MILLISECONDS) return `${Math.floor(elapsedMilliseconds / DAY_MILLISECONDS)}d`;
|
|
94
|
+
if (elapsedMilliseconds < MONTH_MILLISECONDS) return `${Math.floor(elapsedMilliseconds / WEEK_MILLISECONDS)}w`;
|
|
95
|
+
return `${Math.floor(elapsedMilliseconds / MONTH_MILLISECONDS)}mo`;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Elapsed-only relative time, one grammar across all tiers.
|
|
100
|
+
* relativeTime(now - 20_000, now) === "just now"; relativeTime(now - 12 * 60_000, now) === "12m ago"; relativeTime(now - 5 * 86_400_000, now) === "5d ago"
|
|
101
|
+
*/
|
|
102
|
+
export function relativeTime(epochMilliseconds: number, nowMilliseconds: number): string {
|
|
103
|
+
const elapsed = Math.max(0, nowMilliseconds - epochMilliseconds);
|
|
104
|
+
if (elapsed < MINUTE_MILLISECONDS) return "just now";
|
|
105
|
+
return `${formatElapsed(elapsed)} ago`;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* futureTime(now + 20 * 86_400_000, now) === "in 2w"
|
|
110
|
+
*/
|
|
111
|
+
export function futureTime(epochMilliseconds: number, nowMilliseconds: number): string {
|
|
112
|
+
return `in ${formatElapsed(Math.max(0, epochMilliseconds - nowMilliseconds))}`;
|
|
113
|
+
}
|
|
114
|
+
|
|
81
115
|
function safeStringify(value: unknown): string {
|
|
82
116
|
try {
|
|
83
117
|
return JSON.stringify(value) ?? String(value);
|
|
@@ -97,7 +131,7 @@ export function appendTeamLog(state: TeamLogState, input: TeamLogEntryInput, now
|
|
|
97
131
|
const entry: TeamLogEntry = {
|
|
98
132
|
...input,
|
|
99
133
|
sequence: state.nextLogSequence++,
|
|
100
|
-
timestamp:
|
|
134
|
+
timestamp: now.toISOString(),
|
|
101
135
|
epochMilliseconds: now.getTime(),
|
|
102
136
|
};
|
|
103
137
|
state.log.push(entry);
|