@giladbarnea/pi-simple-team 2.0.16 → 2.0.18

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
@@ -124,6 +124,46 @@ function toolResult(payload: JsonRecord, viewDetails: JsonRecord = {}) {
124
124
  };
125
125
  }
126
126
 
127
+ const reminderSlugWords = {
128
+ adjectives: ["amber", "brisk", "calm", "clever", "dusty", "eager", "fuzzy", "gentle", "golden", "hollow", "jolly", "lively", "mellow", "misty", "nimble", "plucky", "quiet", "rapid", "rusty", "silver", "steady", "sunny", "swift", "witty"],
129
+ nouns: ["badger", "beacon", "cedar", "comet", "falcon", "fern", "harbor", "heron", "lantern", "maple", "meadow", "otter", "pebble", "pine", "quail", "raven", "river", "robin", "sparrow", "spruce", "thistle", "tulip", "walrus", "willow"],
130
+ } as const;
131
+
132
+ /** A random two-word label that ties a reminder's wake message to its arming. */
133
+ function reminderSlug(): string {
134
+ const pick = (words: readonly string[]): string => words[crypto.randomInt(words.length)]!;
135
+ return `${pick(reminderSlugWords.adjectives)}-${pick(reminderSlugWords.nouns)}`;
136
+ }
137
+
138
+ /**
139
+ * Formats a moment in the process time zone, with the time zone name the runtime's English locale data provides.
140
+ * @example humanTime(new Date("2026-11-07T08:47:00Z")) // with TZ=Asia/Jerusalem: "Nov 7, 2026, 10:47am GMT+2"
141
+ */
142
+ function humanTime(moment: Date): string {
143
+ const parts = Object.fromEntries(
144
+ new Intl.DateTimeFormat("en-US", { month: "short", day: "numeric", year: "numeric", hour: "numeric", minute: "2-digit", hour12: true, timeZoneName: "short" })
145
+ .formatToParts(moment)
146
+ .map((part) => [part.type, part.value]),
147
+ ) as Record<Intl.DateTimeFormatPartTypes, string>;
148
+ return `${parts.month} ${parts.day}, ${parts.year}, ${parts.hour}:${parts.minute}${parts.dayPeriod.toLowerCase()} ${parts.timeZoneName}`;
149
+ }
150
+
151
+ /**
152
+ * @example humanDuration(3665) // "1h, 1m and 5s"
153
+ * @example humanDuration(2700) // "45m"
154
+ * @example humanDuration(0) // "0s"
155
+ */
156
+ function humanDuration(totalSeconds: number): string {
157
+ const units = [
158
+ [Math.floor(totalSeconds / 3600), "h"],
159
+ [Math.floor((totalSeconds % 3600) / 60), "m"],
160
+ [totalSeconds % 60, "s"],
161
+ ] as const;
162
+ const parts = units.filter(([count]) => count > 0).map(([count, unit]) => `${count}${unit}`);
163
+ if (parts.length === 0) return "0s";
164
+ return parts.length === 1 ? parts[0]! : `${parts.slice(0, -1).join(", ")} and ${parts.at(-1)}`;
165
+ }
166
+
127
167
  /** @example teamIdentity({ name: "review", id: "session-review" }) // { teamName: "review", teamId: "session-review" } */
128
168
  function teamIdentity(team: { name: string; id?: string }): { teamName: string; teamId: string } {
129
169
  return { teamName: team.name, teamId: team.id ?? team.name };
@@ -1190,17 +1230,23 @@ export default function (pi: ExtensionAPI) {
1190
1230
  }, { additionalProperties: false }),
1191
1231
  async execute(_toolCallId, params) {
1192
1232
  const delayMilliseconds = params.delayMinutes * 60_000;
1193
- const scheduledAt = new Date(Date.now() + delayMilliseconds).toISOString();
1233
+ const delaySeconds = Math.round(delayMilliseconds / 1000);
1234
+ const armedAt = new Date();
1235
+ const wakeAt = new Date(armedAt.getTime() + delayMilliseconds);
1236
+ const slug = reminderSlug();
1194
1237
  const timer = setTimeout(() => {
1195
1238
  reminderTimers.delete(timer);
1196
1239
  pi.sendMessage(
1197
- { customType: "pi-simple-team-reminder", content: params.message, display: false },
1240
+ { customType: "pi-simple-team-reminder", content: `Reminder ${slug} wake up: it's ${humanTime(new Date())} now.\n\n${params.message}`, display: false },
1198
1241
  { deliverAs: "followUp", triggerTurn: true },
1199
1242
  );
1200
1243
  }, delayMilliseconds);
1201
1244
  reminderTimers.add(timer);
1202
1245
  timer.unref();
1203
- return toolResult({ scheduledAt, message: params.message });
1246
+ return {
1247
+ content: [{ type: "text" as const, text: `Armed reminder ${slug}: It's ${humanTime(armedAt)} now. Reminder set in ${delaySeconds} seconds (${humanDuration(delaySeconds)}) for ${humanTime(wakeAt)}.` }],
1248
+ details: { scheduledAt: wakeAt.toISOString(), message: params.message, slug },
1249
+ };
1204
1250
  },
1205
1251
  }),
1206
1252
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@giladbarnea/pi-simple-team",
3
- "version": "2.0.16",
3
+ "version": "2.0.18",
4
4
  "description": "A flat, live team of Pi agents.",
5
5
  "keywords": [
6
6
  "pi-package",
package/render.ts CHANGED
@@ -4,7 +4,7 @@ import { padVisible, stableRenderWidth, visibleLength } from "./render-support/a
4
4
  import { glyphs } from "./render-support/glyphs.ts";
5
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 { futureTime, monthDay, relativeTime, timeOfDay, type TeamLogEntry } from "./teamlog.ts";
7
+ import { futureTime, logRowTime, monthDay, relativeTime, timeOfDay, type TeamLogEntry } from "./teamlog.ts";
8
8
  import { actorHueToken, DIM_SGR_CLOSE, DIM_SGR_OPEN, FactTable, inlineFact, statusWordToken, type FactRow, type TeammateView } from "./teammate-facts.ts";
9
9
 
10
10
  export { actorHueToken, statusWordToken, type TeammateView };
@@ -604,8 +604,8 @@ function renderLogDetail(theme: ThemeLike, detail: LogDetail, roster: string[]):
604
604
 
605
605
  const LOG_ROW_INDENT = " ";
606
606
 
607
- function logChrome(theme: ThemeLike, sequence: number, seqWidth: number, epochMilliseconds: number): string {
608
- return theme.fg("borderMuted", `${LOG_ROW_INDENT}${padVisible(`#${sequence}`, seqWidth)} ${timeOfDay(epochMilliseconds)}`);
607
+ function logChrome(theme: ThemeLike, sequence: number, seqWidth: number, time: string, timeWidth: number): string {
608
+ return theme.fg("borderMuted", `${LOG_ROW_INDENT}${padVisible(`#${sequence}`, seqWidth)} ${padVisible(time, timeWidth)}`);
609
609
  }
610
610
 
611
611
  function sameLocalDay(a: number, b: number): boolean {
@@ -617,17 +617,19 @@ function dayDividerLine(theme: ThemeLike, epochMilliseconds: number): string {
617
617
  return `${LOG_ROW_INDENT}${theme.fg("borderMuted", `${rule.repeat(2)} ${monthDay(epochMilliseconds)} ${rule.repeat(30)}`)}`;
618
618
  }
619
619
 
620
- /** Log rows keep an absolute HH:MM:SS grammar; day dividers carry the date whenever a row is not from "today". */
620
+ /** Log rows show short relative time under an hour and absolute HH:MM:SS after; day dividers carry the date whenever a row is not from "today". */
621
621
  function actionRows(theme: ThemeLike, actions: LogAction[], roster: string[], nowMilliseconds: number): string[] {
622
622
  const g = glyphs();
623
623
  const seqWidth = Math.max(...actions.map((action) => `#${action.sequence}`.length));
624
+ const times = actions.map((action) => logRowTime(action.epochMilliseconds, nowMilliseconds));
625
+ const timeWidth = Math.max(...times.map((time) => time.length));
624
626
  const whoWidth = Math.max(...actions.map((action) => action.who.length));
625
627
  const actionWidth = Math.max(...actions.map((action) => action.action.length));
626
628
  const iconWidth = Math.max(...actions.map((action) => visibleLength(logIconGlyph(action.icon))));
627
629
  const rows: string[] = [];
628
630
  let previousWho: string | undefined;
629
631
  let previousEpoch = nowMilliseconds;
630
- for (const action of actions) {
632
+ for (const [index, action] of actions.entries()) {
631
633
  if (!sameLocalDay(action.epochMilliseconds, previousEpoch)) {
632
634
  rows.push(dayDividerLine(theme, action.epochMilliseconds));
633
635
  previousWho = undefined;
@@ -643,7 +645,7 @@ function actionRows(theme: ThemeLike, actions: LogAction[], roster: string[], no
643
645
  .filter((detail) => detail.style !== "text" || detail.text.length > 0)
644
646
  .map((detail) => renderLogDetail(theme, detail, roster))
645
647
  .join(dot);
646
- rows.push(`${logChrome(theme, action.sequence, seqWidth, action.epochMilliseconds)} ${whoStyled} ${icon} ${actionName}${detailText ? `${dot}${detailText}` : ""}`);
648
+ rows.push(`${logChrome(theme, action.sequence, seqWidth, times[index]!, timeWidth)} ${whoStyled} ${icon} ${actionName}${detailText ? `${dot}${detailText}` : ""}`);
647
649
  }
648
650
  return rows;
649
651
  }
package/teamlog.ts CHANGED
@@ -106,6 +106,17 @@ export function relativeTime(epochMilliseconds: number, nowMilliseconds: number)
106
106
  return `${formatElapsed(elapsed)} ago`;
107
107
  }
108
108
 
109
+ /**
110
+ * Log row time: short elapsed time under an hour, absolute time of day from then on.
111
+ * logRowTime(now - 44 * 60_000, now) === "44m"; logRowTime(now - 20_000, now) === "now"; logRowTime(now - 3_600_000, now) === timeOfDay(now - 3_600_000)
112
+ */
113
+ export function logRowTime(epochMilliseconds: number, nowMilliseconds: number): string {
114
+ const elapsed = Math.max(0, nowMilliseconds - epochMilliseconds);
115
+ if (elapsed >= HOUR_MILLISECONDS) return timeOfDay(epochMilliseconds);
116
+ if (elapsed < MINUTE_MILLISECONDS) return "now";
117
+ return formatElapsed(elapsed);
118
+ }
119
+
109
120
  /**
110
121
  * futureTime(now + 20 * 86_400_000, now) === "in 2w"
111
122
  */