pi-odd-worktree 3.11.1 → 3.11.2

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.
@@ -10178,7 +10178,11 @@ function installUserPromptCard() {
10178
10178
  // The measurement seam is asked on every paint (the TUI package may load late), and
10179
10179
  // the card reads Pi's own live theme from its process-wide slot, like every other
10180
10180
  // surface that paints outside a host render call.
10181
- lib.installUserPromptCard({ component, metrics: () => resolveWorktreeToolCardMetrics() });
10181
+ const outcome = lib.installUserPromptCard({ component, metrics: () => resolveWorktreeToolCardMetrics() });
10182
+ // S2 (prompt-card-fix): a transcript RESTORED from history was built before this import
10183
+ // resolved, so the prompts already on screen keep Pi's rows until something unrelated
10184
+ // repaints them. One request per install — never per paint — is what gives them the card.
10185
+ requestPromptCardRepaint(outcome);
10182
10186
  })
10183
10187
  .catch(() => {
10184
10188
  // A host without the class keeps Pi's own prompt rows (S6).
@@ -10189,6 +10193,31 @@ function installUserPromptCard() {
10189
10193
  });
10190
10194
  }
10191
10195
 
10196
+ /**
10197
+ * S2 (prompt-card-fix): the ONE repaint a successful install asks for.
10198
+ *
10199
+ * A session restored from history builds its whole transcript before the deferred host import
10200
+ * above resolves, so the prompts already on screen keep Pi's rows until something unrelated
10201
+ * repaints. The bridge's published `requestRepaint` is the only repaint this package may ask
10202
+ * for, and it is OPTIONAL (`gentle-shell-bridge` publishes it; an older bridge, or none, does
10203
+ * not): absent member, no request. The request is made per INSTALL, never per paint, and only
10204
+ * for an install that actually happened in a session that is still live — a refused install, a
10205
+ * closed session and a bridge without the member all ask nothing. Its answer is irrelevant to
10206
+ * the card, so the result is ignored and a throw is swallowed.
10207
+ */
10208
+ function requestPromptCardRepaint(outcome) {
10209
+ if (outcome === null || typeof outcome !== "object" || outcome.installed !== true) return;
10210
+ if (!userPromptCardSessionLive) return;
10211
+ try {
10212
+ const resolver = libRequire("file-card-resolver.js");
10213
+ const api = resolver && typeof resolver.bridgeApi === "function" ? resolver.bridgeApi() : undefined;
10214
+ if (api === undefined || typeof api.requestRepaint !== "function") return;
10215
+ api.requestRepaint();
10216
+ } catch {
10217
+ // A bridge that refuses its own repaint never breaks the install it belongs to.
10218
+ }
10219
+ }
10220
+
10192
10221
  /**
10193
10222
  * The prompt card's session boundary — registered ONCE per load, by whichever path can first arm
10194
10223
  * an install: the factory when a bridge is already published, the ready subscription, or the gate
@@ -11,11 +11,15 @@
11
11
  // from Pi, so a stub class is enough to exercise all of it.
12
12
  //
13
13
  // WHAT IT DRAWS, and what it never touches:
14
- // * THE HEADING is `✿ You`, tone `info`, with the theme's `accent` role for the name AND
15
- // for the whole closed box (`railRole`) — corners, lead, rule, sides, rail and bottom.
16
- // That one role around the entire frame is what tells this card apart from the tool
17
- // cards, which paint their tone; no glyph override, no subtitle and no timestamp are
18
- // added (the `✿` is the substrate's default mark, and `gentle-timestamps` owns time).
14
+ // * THE HEADING is `✿ You · 14:32`: the mark and the name in the theme's `accent` role (the
15
+ // card's `titleRole`), then the substrate's `SEPARATOR` and the prompt's clock in `muted`
16
+ // (the subtitle path `lib/shell-card.js` already has, `SUBTITLE_ROLE`). The clock is the
17
+ // host's own `timestamp` when it set one, else the moment of the card's FIRST paint, held
18
+ // per component so a live prompt does not drift frame by frame; with neither, the heading is
19
+ // `✿ You` alone and nothing is invented. The whole closed box still wears the `accent` role
20
+ // (`railRole`) — corners, lead, rule, sides, rail and bottom. That one role around the entire
21
+ // frame is what tells this card apart from the tool cards, which paint their tone.
22
+ // No glyph override is made (the `✿` is the substrate's default mark).
19
23
  // * THE BODY is Pi's own rendering of the prompt. The component's Markdown child is
20
24
  // rebuilt from its OWN constructor with the user message background dropped
21
25
  // (`bgColor: undefined`), no side padding (the frame is the padding) and the host's own
@@ -66,8 +70,8 @@ const { ACTIVITY_DESIGN_ID, bridgeApi } = require('./file-card-resolver.js');
66
70
  const { themeFor } = require('./file-card.js');
67
71
 
68
72
  // The one heading this card wears: the mark is the substrate's default `✿`, the name is the
69
- // person, and the role is the accent for the name and for the whole closed box. No subtitle
70
- // (there is one fact: the prompt) and no timestamp (`gentle-timestamps` owns the clock).
73
+ // person, and the role is the accent for the name and for the whole closed box. The clock is NOT
74
+ // part of it — it belongs to the component being drawn, so `cardParts` adds it per paint (S1).
71
75
  const IDENTITY = Object.freeze({
72
76
  title: 'You',
73
77
  tone: CARD_TONE.INFO,
@@ -265,6 +269,53 @@ const sameRows = (a, b) => a === b || (a.length === b.length && a.every((row, in
265
269
  const cloneMemo = new WeakMap();
266
270
  /** The per-component card memo: (requested width, drawn width, paint, rendered rows) in, parts out. */
267
271
  const cardMemo = new WeakMap();
272
+ /** The per-component clock memo: the raw source read (`timestamp`, else `undefined`) and its `HH:MM`. */
273
+ const clockMemo = new WeakMap();
274
+
275
+ // ---- the heading's clock (S1) ----
276
+
277
+ /** Two digits, zero padded: the clock's only formatting rule. */
278
+ const twoDigits = (value) => String(value).padStart(2, '0');
279
+
280
+ /** One instant as local 24-hour `HH:MM`: no seconds, no date, no relative wording. */
281
+ function clockText(at) {
282
+ const instant = new Date(at);
283
+ return `${twoDigits(instant.getHours())}:${twoDigits(instant.getMinutes())}`;
284
+ }
285
+
286
+ /**
287
+ * The clock the heading carries for `self`, or `undefined` when there is none to state.
288
+ *
289
+ * The source, in this order (S1):
290
+ * 1. the component's OWN `timestamp` when it is a string — what Pi sets when it rebuilds a
291
+ * prompt from a session entry, so a restored transcript shows when the prompt was sent;
292
+ * 2. otherwise a clock captured ONCE, at the component's first paint, so a prompt sent live
293
+ * shows its arrival time too and a later frame never drifts;
294
+ * 3. with neither, nothing: the heading keeps `✿ You` and no time is invented (an unparseable
295
+ * `timestamp` is not a clock, and a host clock that answers no number is not one either).
296
+ *
297
+ * The memo is keyed on the SOURCE, so the formatting runs once per component (or once per
298
+ * `timestamp` the host sets) and every later paint reads the string it already made — a steady
299
+ * frame formats nothing and reads no file, no store and no bridge.
300
+ */
301
+ function headingClock(self) {
302
+ const field = asObject(self).timestamp;
303
+ const source = typeof field === 'string' ? field : undefined;
304
+ const key = self !== null && typeof self === 'object' ? self : undefined;
305
+ const remembered = key === undefined ? undefined : clockMemo.get(key);
306
+ if (remembered !== undefined && remembered.source === source) return remembered.clock;
307
+ let clock;
308
+ if (source !== undefined) {
309
+ const at = Date.parse(source);
310
+ if (Number.isFinite(at)) clock = clockText(at);
311
+ }
312
+ if (clock === undefined) {
313
+ const now = Date.now();
314
+ clock = Number.isFinite(now) ? clockText(now) : undefined;
315
+ }
316
+ if (key !== undefined) clockMemo.set(key, { source, clock });
317
+ return clock;
318
+ }
268
319
 
269
320
  /**
270
321
  * One component's card parts for one draw — `{ head, body, bottom }`, the shape `floatRows`
@@ -285,6 +336,10 @@ function cardParts(self, markdown, target, inner, paint, metrics) {
285
336
  const width = cardInnerWidth(inner);
286
337
  const rows = renderedRows(markdown, width);
287
338
  if (rows === undefined) return undefined;
339
+ // The clock is part of the memo key ONLY as the string it formats to: it cannot change between
340
+ // paints except through the component's own `timestamp` or the theme, and a steady frame pays
341
+ // one memo read rather than a second format.
342
+ const clock = headingClock(self);
288
343
  const remembered = cardMemo.get(self);
289
344
  if (
290
345
  remembered !== undefined
@@ -292,17 +347,20 @@ function cardParts(self, markdown, target, inner, paint, metrics) {
292
347
  && remembered.target === target
293
348
  && remembered.inner === inner
294
349
  && remembered.paint === paint
350
+ && remembered.clock === clock
295
351
  && sameRows(remembered.rows, rows)
296
352
  ) return remembered.parts;
297
- const card = { ...IDENTITY };
353
+ // The clock rides the substrate's subtitle path: the heading states `✿ You`, then the
354
+ // separator and the clock in `muted` (`SUBTITLE_ROLE`). No clock, no subtitle at all.
355
+ const card = clock === undefined ? { ...IDENTITY } : { ...IDENTITY, subtitle: clock };
298
356
  const parts = {
299
357
  head: cardTopRows(card, paint, inner, undefined, metrics),
300
358
  // The body is never clipped: a prompt is not a preview, so every row is drawn.
301
359
  body: cardPaintedRows(rows, IDENTITY.tone, paint, inner, { expanded: true }, metrics),
302
- // No content rides the closing rule: the time belongs to `gentle-timestamps`.
360
+ // No content rides the closing rule: the prompt's clock belongs to the heading alone.
303
361
  bottom: cardBottom(IDENTITY.tone, paint, inner, undefined, metrics),
304
362
  };
305
- cardMemo.set(self, { markdown, target, inner, paint, rows, parts });
363
+ cardMemo.set(self, { markdown, target, inner, paint, clock, rows, parts });
306
364
  return parts;
307
365
  }
308
366
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-odd-worktree",
3
- "version": "3.11.1",
3
+ "version": "3.11.2",
4
4
  "description": "Pi package for odd-worktree: the Git worktree tools a Pi session uses (create and list the checkouts the agent works in), the /warp worktree panel, the /odd ODD viewer, and the /issues GitHub issue reader. Needs only Pi and git: no companion app, no extra service.",
5
5
  "keywords": [
6
6
  "pi-package",
@@ -952,12 +952,179 @@ test('an empty prompt draws no card: the host\'s own nothing comes back', () =>
952
952
  assert.deepEqual(component.render(60), []);
953
953
  });
954
954
 
955
- test('the heading is this package\'s card: the accent name, no subtitle and no time', () => {
955
+ // ---- S1 (prompt-card-fix): the heading's clock, in grey beside the name ----
956
+
957
+ /** Local 24-hour `HH:MM`, zero padded: the clock the heading is expected to carry. */
958
+ const localClock = (instant) => `${String(instant.getHours()).padStart(2, '0')}:${String(instant.getMinutes()).padStart(2, '0')}`;
959
+
960
+ /** The `HH:MM` a heading row draws after its separator, read from the row's own cells. */
961
+ function headingClock(row) {
962
+ const line = cells(row);
963
+ const dot = line.findIndex((cell) => cell.char === '·');
964
+ if (dot < 0) return undefined;
965
+ return line.slice(dot + 2, dot + 7).map((cell) => cell.char).join('');
966
+ }
967
+
968
+ test('S1: a component with a timestamp heads ✿ You · <local HH:MM>, and the clock is muted', () => {
956
969
  publishBridge(ACTIVITY_ANSWER);
957
- install({ seams: { paint: taggedTheme } });
970
+ const paint = roleTheme();
971
+ install({ seams: { paint } });
972
+ // The instant the host sets on a prompt rebuilt from a session entry: an ISO string in UTC.
973
+ const at = '2026-11-23T19:12:59Z';
974
+ const expected = localClock(new Date(at));
958
975
  const component = promptComponent();
959
- const head = component.render(60)[0];
960
- assert.ok(head.includes('<accent>✿ You</accent>'), 'the mark and the name wear the title role together');
961
- assert.equal(unpaint(head).includes('·'), false, 'no subtitle separator');
962
- assert.doesNotMatch(unpaint(head), /\d{1,2}:\d{2}|ago/u, 'no timestamp: gentle-timestamps owns the clock');
976
+ component.timestamp = at;
977
+ const rows = component.render(60);
978
+ const head = unpaint(rows[0]);
979
+ assert.match(head, /^╭─ ✿ You · \d{2}:\d{2} /u, 'the name, the separator and the clock, on the frame');
980
+ assert.ok(head.includes(`✿ You · ${expected}`), `the clock is the local HH:MM of that instant: ${expected}`);
981
+ assert.equal(headingClock(rows[0]), expected, 'five clock columns, zero padded, no seconds');
982
+ // The role actually painted on the separator and on each clock column.
983
+ const line = cells(rows[0]);
984
+ const dot = line.findIndex((cell) => cell.char === '·');
985
+ assert.equal(line[dot].code, ROLE_CODE.muted, 'the separator wears the muted role');
986
+ for (const cell of line.slice(dot + 2, dot + 7)) {
987
+ assert.equal(cell.code, ROLE_CODE.muted, `"${cell.char}" of the clock is painted muted`);
988
+ }
989
+ const mark = line.find((cell) => cell.char === '✿');
990
+ assert.equal(mark.code, ROLE_CODE.accent, 'the mark still wears the accent with the name');
991
+ });
992
+
993
+ test('S1: without a timestamp the first-paint clock is used, unchanged on every later paint', () => {
994
+ publishBridge(ACTIVITY_ANSWER);
995
+ install();
996
+ const realNow = Date.now;
997
+ try {
998
+ Date.now = () => new Date(2026, 0, 2, 9, 7, 30).getTime();
999
+ const component = promptComponent();
1000
+ const first = unpaint(component.render(60)[0]);
1001
+ assert.ok(first.includes('✿ You · 09:07'), `the clock of the first paint: ${first}`);
1002
+ // The clock moves on: a later frame keeps the arrival time, it never drifts.
1003
+ Date.now = () => new Date(2026, 0, 2, 17, 45, 0).getTime();
1004
+ const later = unpaint(component.render(60)[0]);
1005
+ assert.equal(later, first, 'a later paint is the same heading, to the cell');
1006
+ // A component built now has its OWN arrival time, captured on its own first paint.
1007
+ const other = promptComponent();
1008
+ assert.ok(unpaint(other.render(60)[0]).includes('✿ You · 17:45'), 'each prompt keeps its own first-paint clock');
1009
+ assert.ok(unpaint(other.render(60)[0]).includes('✿ You · 17:45'), 'and it holds on the next paint too');
1010
+ } finally {
1011
+ Date.now = realNow;
1012
+ }
1013
+ });
1014
+
1015
+ test('S1: a component with neither a timestamp nor a clock shows ✿ You alone, inventing nothing', () => {
1016
+ publishBridge(ACTIVITY_ANSWER);
1017
+ install({ seams: { paint: taggedTheme } });
1018
+ const realNow = Date.now;
1019
+ try {
1020
+ // No clock to read at all, and nothing on the component: the heading is the name.
1021
+ Date.now = () => Number.NaN;
1022
+ const component = promptComponent();
1023
+ const head = component.render(60)[0];
1024
+ assert.ok(head.includes('<accent>✿ You</accent>'), 'the mark and the name wear the title role together');
1025
+ const plain = unpaint(head);
1026
+ assert.match(plain, /^╭─ ✿ You /u, 'the heading is the name alone');
1027
+ assert.equal(plain.includes('·'), false, 'no subtitle separator');
1028
+ assert.doesNotMatch(plain, /\d{1,2}:\d{2}|ago/u, 'no time is invented');
1029
+ // A timestamp nothing can read is no clock either: still nothing invented.
1030
+ const unreadable = promptComponent();
1031
+ unreadable.timestamp = 'yesterday';
1032
+ assert.equal(unpaint(unreadable.render(60)[0]).includes('·'), false, 'an unreadable timestamp invents no clock');
1033
+ } finally {
1034
+ Date.now = realNow;
1035
+ }
1036
+ });
1037
+
1038
+ // ---- S2 (prompt-card-fix): a restored session repaints — once per install ----
1039
+
1040
+ /**
1041
+ * The bridge a repaint assertion needs: the published object every surface here reads, with a
1042
+ * `requestRepaint` recorder and the gate's own reader. `extra` replaces a member per case.
1043
+ */
1044
+ function repaintBridge(extra = {}) {
1045
+ const api = fixture.defaultBridge().api;
1046
+ const state = { repaints: 0 };
1047
+ api.requestRepaint = () => {
1048
+ state.repaints += 1;
1049
+ };
1050
+ api.resolveToolDesignSelection = () => ACTIVITY_ANSWER;
1051
+ Object.assign(api, extra);
1052
+ return { api, state };
1053
+ }
1054
+
1055
+ /**
1056
+ * Load this extension with one published bridge and drive the session that owns the deferred
1057
+ * install — the only path that knows a session is live. Answers the host class and the hooks, so
1058
+ * a test can watch the prototype and a paint.
1059
+ */
1060
+ async function loadPromptCardSession(bridgeApi) {
1061
+ const previous = globalThis[BRIDGE_API_SLOT];
1062
+ globalThis[BRIDGE_API_SLOT] = bridgeApi;
1063
+ class Host {
1064
+ render(width) {
1065
+ return [`native ${width}`];
1066
+ }
1067
+ }
1068
+ const native = Host.prototype.render;
1069
+ const { hooks } = await loadExtensionModule(() => ({ UserMessageComponent: Host }));
1070
+ const emit = extensionSession(hooks);
1071
+ const shutdown = async () => {
1072
+ await emit('session_shutdown');
1073
+ if (previous === undefined) delete globalThis[BRIDGE_API_SLOT];
1074
+ else globalThis[BRIDGE_API_SLOT] = previous;
1075
+ };
1076
+ return { Host, native, emit, shutdown };
1077
+ }
1078
+
1079
+ test('S2: a successful install asks the bridge for exactly one repaint, and no paint asks again', async () => {
1080
+ const bridge = repaintBridge();
1081
+ const session = await loadPromptCardSession(bridge.api);
1082
+ try {
1083
+ await session.emit('session_start');
1084
+ await drain();
1085
+ assert.notEqual(session.Host.prototype.render, session.native, 'the class is patched by the live session');
1086
+ assert.equal(bridge.state.repaints, 1, 'the restored transcript is asked to repaint once');
1087
+ // Painting is what the request produced: it never asks for another repaint itself.
1088
+ const component = new session.Host();
1089
+ component.render(60);
1090
+ component.render(62);
1091
+ assert.equal(bridge.state.repaints, 1, 'a paint requests none, and a steady frame neither');
1092
+ // A second `session_start` is a re-install: it asks again, exactly once.
1093
+ await session.emit('session_start');
1094
+ await drain();
1095
+ assert.equal(bridge.state.repaints, 2, 'the re-install path asks for its own single repaint');
1096
+ } finally {
1097
+ await session.shutdown();
1098
+ }
1099
+ });
1100
+
1101
+ test('S2: an install the gate never armed, and a bridge with no requestRepaint, ask for none', async () => {
1102
+ // (a) The bridge refuses the design registration, so the install was never armed: no request.
1103
+ const refused = repaintBridge({
1104
+ registerToolDesign: () => {
1105
+ throw new Error('this bridge refuses the activity design');
1106
+ },
1107
+ });
1108
+ const ungated = await loadPromptCardSession(refused.api);
1109
+ try {
1110
+ await ungated.emit('session_start');
1111
+ await drain();
1112
+ assert.equal(ungated.Host.prototype.render, ungated.native, 'nothing was installed for a gated line');
1113
+ assert.equal(refused.state.repaints, 0, 'an install that never happened asks for nothing');
1114
+ } finally {
1115
+ await ungated.shutdown();
1116
+ }
1117
+ // (b) The member is optional: the install succeeds and no member is there to call.
1118
+ const absent = repaintBridge({});
1119
+ delete absent.api.requestRepaint;
1120
+ const memberless = await loadPromptCardSession(absent.api);
1121
+ try {
1122
+ assert.equal('requestRepaint' in absent.api, false, 'the published bridge carries no such member');
1123
+ await memberless.emit('session_start');
1124
+ await drain();
1125
+ assert.notEqual(memberless.Host.prototype.render, memberless.native, 'the install still happened');
1126
+ assert.equal(absent.state.repaints, 0, 'and nothing was asked for');
1127
+ } finally {
1128
+ await memberless.shutdown();
1129
+ }
963
1130
  });