pi-odd-worktree 3.15.0 → 3.15.1

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.
@@ -28,7 +28,14 @@
28
28
  // rebuilt from its OWN constructor with the user message background dropped
29
29
  // (`bgColor: undefined`), no side padding (the frame is the padding) and the host's own
30
30
  // `options`, so `preserveOrderedListMarkers`, `preserveBackslashEscapes` and every
31
- // extension markdown transformer keep working. Its rows arrive ALREADY PAINTED, so they
31
+ // extension markdown transformer keep working. THE ONE EXCEPTION is the prompt mark an
32
+ // extension transformer prepends to a user message (pi-pretty's ` ❯ ${markdown}`): the
33
+ // clone's `transform` wraps the host's own and drops exactly ONE leading `" ❯ "` from its
34
+ // answer (`undecoratedOptions`), so the body re-wraps at the frame's full inner width
35
+ // instead of carrying a mark nothing indents the lines under — and a person who typed `❯`
36
+ // themselves keeps their own character, because that run arrives after the decoration. The
37
+ // component's own `text` is never rewritten, and a prompt no transformer decorated is drawn
38
+ // byte for byte as before. Its rows arrive ALREADY PAINTED, so they
32
39
  // are placed with `cardPaintedRows` — never `cardBodyRows`, which paints a role over
33
40
  // them and would destroy the ANSI. The text colour stays exactly what the body's own
34
41
  // paint says.
@@ -170,6 +177,45 @@ function readTheme(seam) {
170
177
 
171
178
  // ---- the body: Pi's own Markdown, rebuilt without the user message background (S5) ----
172
179
 
180
+ // The prompt mark an extension markdown transformer prepends to a user message — pi-pretty's
181
+ // ` ❯ ${markdown}` (`@heyhuynhgiabuu/pi-pretty`): one leading space, the mark, and the space after
182
+ // it. It is a decoration of the WHOLE message, not of its first line, and nothing indents the
183
+ // lines under it, so a wrapped prompt reads flush left below a marked first row. This card drops
184
+ // it (the user's decision: "Sacar el ❯ del mensaje").
185
+ const PROMPT_MARK = ' ❯ ';
186
+
187
+ /**
188
+ * The host Markdown `options` the card's clone is built with: the host's own object, untouched,
189
+ * when it carries no `transform`; otherwise a shallow copy whose `transform` is the host's own
190
+ * composed transform with ONE leading prompt mark removed from its answer.
191
+ *
192
+ * WHY A WRAPPER AND NOT TEXT SURGERY: the mark lives in the TRANSFORM's output, not in the
193
+ * component's `text` (`user-message.js` builds the Markdown with `transform:
194
+ * createMarkdownTransform("user", …)`, which is where every `registerMarkdownTransformer`
195
+ * lands), so the clone is the one place the host's text arrives before it is parsed and wrapped.
196
+ * Calling the host transform first and dropping the mark from what it returns keeps every other
197
+ * transformer, every markdown construct and the clone's own re-wrap at the full inner width
198
+ * intact: no ANSI is rewritten and no row is measured twice.
199
+ *
200
+ * ONLY THE DECORATION IS CONSUMED: the extension prepends its mark to the user's own markdown, so
201
+ * the decoration is always the OUTERMOST prefix and a person who typed `❯` themselves keeps
202
+ * their own character — their run arrives AFTER the decoration, and at most one leading run is
203
+ * ever dropped. A prompt the transform did not decorate is handed back exactly as it came, so a
204
+ * host with no transformer (or one that adds no mark) draws the same rows it always did.
205
+ */
206
+ function undecoratedOptions(options) {
207
+ if (typeof asObject(options).transform !== 'function') return options;
208
+ const transform = options.transform;
209
+ return {
210
+ ...options,
211
+ transform: (text, availableWidth) => {
212
+ const transformed = transform(text, availableWidth);
213
+ if (typeof transformed !== 'string' || !transformed.startsWith(PROMPT_MARK)) return transformed;
214
+ return transformed.slice(PROMPT_MARK.length);
215
+ },
216
+ };
217
+ }
218
+
173
219
  /**
174
220
  * The child's own Markdown as a clone with no background and no padding at all, or `undefined`
175
221
  * when the shape is not Pi's Markdown — a missing child, a non-numeric `paddingX`, no theme,
@@ -218,7 +264,7 @@ function promptMarkdown(child, paint) {
218
264
  0,
219
265
  child.theme,
220
266
  { ...asObject(child.defaultTextStyle), bgColor: undefined },
221
- child.options,
267
+ undecoratedOptions(child.options),
222
268
  );
223
269
  } catch {
224
270
  return undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-odd-worktree",
3
- "version": "3.15.0",
3
+ "version": "3.15.1",
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",
@@ -169,8 +169,13 @@ class StubMarkdown {
169
169
  if (this.text === 'THROW') throw new Error('the renderer blew up');
170
170
  if (this.text === 'NOT_ROWS') return 'not rows';
171
171
  if (this.text === 'EMPTY_BODY') return [];
172
+ // Pi's Markdown hands the host's composed `transform` the WHOLE text and the content width
173
+ // before it parses anything (`markdown.js`: `this.options.transform?.(this.text, contentWidth)`),
174
+ // so a stub that ignored it could never show what an extension transformer does to a prompt.
175
+ const contentWidth = Math.max(1, width - this.paddingX * 2);
176
+ const transformed = this.options?.transform?.(String(this.text), contentWidth) ?? this.text;
172
177
  // Rows the renderer already painted: the card must PLACE them, never repaint them.
173
- const lines = String(this.text).split('\n').map((line) => `\x1b[${this.code}m${line}\x1b[39m`);
178
+ const lines = String(transformed).split('\n').map((line) => `\x1b[${this.code}m${line}\x1b[39m`);
174
179
  // Pi's Markdown pads its content with `paddingY` blank rows above and below
175
180
  // (`emptyLines.concat(contentLines, emptyLines)`), and the stub models that: a clone that
176
181
  // keeps the host's padding costs the terminal two rows per prompt.
@@ -525,6 +530,72 @@ test('the body rows are the child\'s own Markdown rebuilt with no background and
525
530
  assert.equal(typeof clone.defaultTextStyle.color, 'function', 'the text colour is the body\'s own paint');
526
531
  });
527
532
 
533
+ // ---- prompt-card-mark: the ❯ an extension transformer prepends - ` ❯ ` in pi-pretty ----
534
+
535
+ /**
536
+ * pi-pretty's own markdown transformer, as the host composes it: the user's markdown comes back
537
+ * prefixed with ` ❯ ` and an empty prompt is left alone (`dist/index.js`: `" ❯ " + markdown`).
538
+ */
539
+ const prettyTransform = (markdown) => (markdown.trim() === '' ? markdown : ` ❯ ${markdown}`);
540
+
541
+ /** A prompt whose Markdown carries the host's composed `transform`, exactly as Pi wires it. */
542
+ function decoratedPrompt(text = PROMPT) {
543
+ return new UserMessageComponent(text, {
544
+ markdownOptions: { preserveOrderedListMarkers: true, preserveBackslashEscapes: true, transform: prettyTransform },
545
+ });
546
+ }
547
+
548
+ test('the ❯ an extension transformer prepends is dropped, and the body starts at the frame padding', () => {
549
+ publishBridge(ACTIVITY_ANSWER);
550
+ install();
551
+ const rows = decoratedPrompt().render(60);
552
+ assert.equal(rows.some((row) => unpaint(row).includes('❯')), false, 'no row carries the decoration');
553
+ const body = rows.filter((row) => row.includes('explain the card'));
554
+ assert.equal(body.length, 1, 'the first line is one body row');
555
+ assert.ok(unpaint(body[0]).startsWith('│ explain the card'), `the message starts at the frame padding: ${unpaint(body[0])}`);
556
+ assert.ok(rows.some((row) => unpaint(row).includes('and keep `this` visible')), 'every line of the prompt is still drawn');
557
+ for (const row of rows) assert.equal(chars(row).length, 60, `"${unpaint(row)}" is 60 wide`);
558
+ });
559
+
560
+ test('a prompt with no transformer is drawn byte for byte as before', () => {
561
+ publishBridge(ACTIVITY_ANSWER);
562
+ install();
563
+ const component = promptComponent();
564
+ component.timestamp = '2026-01-02T09:07:00Z';
565
+ const clock = localClock(new Date(component.timestamp));
566
+ // The rows this card drew BEFORE the decoration was removed, pinned: no transformer, no
567
+ // decoration, so the body, the frame and the prompt-zone markers are untouched to the byte.
568
+ const pinned = [
569
+ OSC133_ZONE_START + `╭─ ✿ You · ${clock} ${'─'.repeat(42)}╮`,
570
+ `│ \x1b[${MARKDOWN_CODE}mexplain the card\x1b[39m${' '.repeat(40)} │`,
571
+ `│ \x1b[${MARKDOWN_CODE}mand keep \`this\` visible\x1b[39m${' '.repeat(33)} │`,
572
+ OSC133_ZONE_CLOSE + `╰${'─'.repeat(58)}╯`,
573
+ ];
574
+ assert.deepEqual(component.render(60), pinned);
575
+ });
576
+
577
+ test('a prompt that starts with ❯ keeps exactly one ❯: only the decoration is consumed', () => {
578
+ publishBridge(ACTIVITY_ANSWER);
579
+ install();
580
+ const rows = decoratedPrompt('❯ my own mark\nsecond line').render(60).map(unpaint);
581
+ const body = rows.filter((row) => row.includes('my own mark'));
582
+ assert.equal(body.length, 1, 'the user\'s line is one body row');
583
+ assert.ok(body[0].startsWith('│ ❯ my own mark'), `the user\'s own mark stays at the frame padding: ${body[0]}`);
584
+ assert.equal(body[0].split('❯').length - 1, 1, 'exactly one ❯: the decoration, never the user\'s own');
585
+ });
586
+
587
+ test('the body re-wraps at the full inner width: the decoration costs no columns', () => {
588
+ publishBridge(ACTIVITY_ANSWER);
589
+ install();
590
+ // Exactly the inner width of a 60-column card (`cardInnerWidth(60)`): one body row undecorated,
591
+ // and one row plus a mark-only row when the three decoration columns still eat the line.
592
+ const line = 'x'.repeat(56);
593
+ const rows = decoratedPrompt(line).render(60);
594
+ assert.equal(rows.length, 3, 'the frame and ONE body row: the 56 columns fit');
595
+ assert.ok(rows[1].includes(line), 'the whole line is on its one row, with no three-column slack');
596
+ assert.equal(chars(rows[1]).length, 60, 'and the row still fills the frame');
597
+ });
598
+
528
599
  test('a steady frame rebuilds nothing, and a width change or a style flip redraws', () => {
529
600
  publishBridge(ACTIVITY_ANSWER);
530
601
  const counting = countingMetrics();