@giladbarnea/pi-simple-team 1.0.33 → 1.0.35

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 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, nowText, pageTeamLog, preview, renderTeamLogPage, type TeamLogEntry } from "./teamlog.ts";
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: nowText() };
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: nowText(), message, formattedMessage, interrupt },
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: nowText(), message: rawMessage };
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: nowText(),
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.33",
3
+ "version": "1.0.35",
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/pi-simple-team-banner.png"
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, treeGlyph, treeStem } from "./render-support/theme.ts";
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, nowText, timeOfDay, type TeamLogEntry } from "./teamlog.ts";
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 ${monthDay(Date.parse(teamView.expiresAt))}`;
281
- return `updated ${nowText(new Date(teamView.updatedAt))}`;
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
- function logChrome(theme: ThemeLike, branch: "├" | "└", sequence: number, seqWidth: number, epochMilliseconds: number): string {
556
- return theme.fg("borderMuted", `${treeGlyph(branch)}${padVisible(`#${sequence}`, seqWidth)} ${timeOfDay(epochMilliseconds)}`);
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
- function actionRows(theme: ThemeLike, actions: LogAction[], roster: string[], hasFooter: boolean): string[] {
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
- return actions.map((action, index) => {
567
- const branch = index === actions.length - 1 && !hasFooter ? "└" : "├";
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
- return `${logChrome(theme, branch, action.sequence, seqWidth, action.epochMilliseconds)} ${whoStyled} ${icon} ${actionName}${detailText ? `${dot}${detailText}` : ""}`;
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, `${treeConnector(theme, "└")}${theme.fg("muted", "no matching events")}`];
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
- ? `${treeConnector(theme, "└")}${theme.fg("muted", `${g.ellipsis} older events${g.dot}cursor "${view.nextCursor}"`)}`
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 ?? [], Boolean(footer));
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
- const g = glyphs();
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
 
@@ -27,7 +27,7 @@ The flip side: if none of these payoffs apply, don't delegate. The anti-pattern
27
27
 
28
28
  This section is a communication rulebook to all cases where an AI requests something from another AI: down, sideways and up — main to sub-agent, main to team, teammate to teammate, and delegated to delegator.
29
29
 
30
- The framework behind this section: [`theory-of-mind.md`](../../references/theory-of-mind.md). Read it once.
30
+ The framework behind this section: [`theory-of-mind.md`](references/theory-of-mind.md). Read it once.
31
31
 
32
32
  **1. Orient the agent to the project:**
33
33
  1.a. Tell the AI agent to *load the skills and files the user has referenced* throughout the session. That's the baseline common ground. Do not repeat the content of those skills and files in your prompt.
@@ -0,0 +1,41 @@
1
+ ---
2
+ name: theory-of-mind
3
+ description: Explains how to re-ground readers after absence or context decay creates asymmetric common ground.
4
+ ---
5
+
6
+ # Theory of Mind: Writing Under Asymmetric Common Ground
7
+
8
+ The theory behind any writing addressed to a reader whose context has diverged from yours.
9
+
10
+ ## The phenomenon
11
+
12
+ While you work, you build a private layer of understanding on top of the last shared baseline: discoveries, discarded hypotheses, new abstractions, locally invented terminology, revised mental models. Your language becomes saturated with that layer. This is the curse of knowledge: once you know a thing, you can no longer tell which of your words are shared and which are private. The words feel plain to you precisely because you are the one who charged them with meaning.
13
+
14
+ Think of a shift change at Mission Control or in an intensive-care unit. The outgoing operator has lived inside the situation for eight hours. The incoming operator walks in cold. "Here is what I concluded" is dangerous, because the outgoing operator's words are saturated with context the incoming person never acquired.
15
+
16
+ ## Two ways the asymmetry arises
17
+
18
+ 1. **Absence.** The reader was not there while you built the layer. Everything after the divergence point is private to you.
19
+ 2. **Decay.** The reader once held the context, but it has gone cold. They keep the memory yet cannot retrieve it unaided.
20
+
21
+ Both reduce to the same obligation: model the reader's current state, not yours.
22
+
23
+ ## The two models
24
+
25
+ Hold two models at once:
26
+
27
+ 1. Your current understanding of the situation.
28
+ 2. The last known common ground — what the reader actually holds right now.
29
+
30
+ The delta between them is the payload your writing must carry. Writing under asymmetry is therefore not summarizing your own experience. It is reconstructing the recipient's state of knowledge and designing their entry into the situation. Optimize for their entry, not your exit.
31
+
32
+ ## The moves
33
+
34
+ 1. **Re-ground before you continue.** Open with what re-establishes the shared frame: the wider situation, the motivation, the current state. Background before assessment — the reader cannot evaluate your conclusions until they can see what you saw.
35
+ 2. **Translate private ontology into shared language.** Names, shorthand, and categories you invented mid-work: drop them, or explicitly re-introduce them. Familiarity to you is not evidence that a term is shared.
36
+ 3. **Treat the artifact as the reader's first look.** It is their entry point, not the next message in your working thread. A continuation of your thread reads as noise to someone who never held the thread.
37
+ 4. **Mark what is new.** Distinguish what was already common ground from what you built on top of it. The reader needs to know which of their existing beliefs still hold and which your writing updates.
38
+
39
+ ## The test
40
+
41
+ Could the reader, holding only the last common ground, parse every sentence on first read — no term they must guess at, no conclusion whose basis they cannot see? If not, the writing is still saturated.
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 timestampWidth = Math.max(0, ...statuses.map(([, status]) => visibleWidth(status.updated)));
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 timestamp = theme.fg("dim", status.updated);
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: nowText(now),
134
+ timestamp: now.toISOString(),
101
135
  epochMilliseconds: now.getTime(),
102
136
  };
103
137
  state.log.push(entry);