pi-odd-worktree 3.15.0 → 3.16.0

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.
Files changed (127) hide show
  1. package/README.md +48 -25
  2. package/extensions/odd-worktree-tools.ts +64 -211
  3. package/lib/shell-api/api.ts +523 -0
  4. package/lib/shell-api/arm.ts +83 -0
  5. package/lib/shell-api/bus.ts +1389 -0
  6. package/lib/shell-api/capture.ts +1340 -0
  7. package/lib/shell-api/card-style-line.ts +112 -0
  8. package/lib/shell-api/card-style-rows.ts +390 -0
  9. package/lib/shell-api/card-style-transform.ts +862 -0
  10. package/lib/shell-api/card-style-wiring.ts +477 -0
  11. package/lib/shell-api/card-styles.ts +153 -0
  12. package/lib/shell-api/config.ts +71 -0
  13. package/lib/shell-api/extension.ts +247 -0
  14. package/lib/shell-api/hook.ts +322 -0
  15. package/lib/shell-api/index.ts +88 -0
  16. package/lib/shell-api/message-design-adoption.ts +549 -0
  17. package/lib/shell-api/message-design-rows.ts +313 -0
  18. package/lib/shell-api/message-design-wiring.ts +369 -0
  19. package/lib/shell-api/message-designs.ts +746 -0
  20. package/lib/shell-api/notices.ts +137 -0
  21. package/lib/shell-api/plugin-lines.ts +877 -0
  22. package/lib/shell-api/presence.ts +258 -0
  23. package/lib/shell-api/repaint.ts +351 -0
  24. package/lib/shell-api/row-labels.ts +146 -0
  25. package/lib/shell-api/row-names.ts +273 -0
  26. package/lib/shell-api/row-origin.ts +144 -0
  27. package/lib/shell-api/rows.ts +591 -0
  28. package/lib/shell-api/section-panel.ts +378 -0
  29. package/lib/shell-api/section-pointer.ts +164 -0
  30. package/lib/shell-api/sections-preview.ts +275 -0
  31. package/lib/shell-api/sections-rows.ts +133 -0
  32. package/lib/shell-api/sidebar-render.ts +705 -0
  33. package/lib/shell-api/sidebar.ts +1126 -0
  34. package/lib/shell-api/store.ts +279 -0
  35. package/lib/shell-api/tool-design-adoption.ts +263 -0
  36. package/lib/shell-api/tool-design-rows.ts +307 -0
  37. package/lib/shell-api/tool-design-wiring.ts +481 -0
  38. package/lib/shell-api/tool-designs.ts +1411 -0
  39. package/lib/shell-api/transform-pipeline.ts +351 -0
  40. package/lib/shell-api/types.ts +803 -0
  41. package/lib/shell-api/visibility.ts +154 -0
  42. package/lib/user-prompt-card.js +48 -2
  43. package/package.json +3 -2
  44. package/tools/files-bridge.test.js +81 -66
  45. package/tools/fixtures/load-extension.js +40 -18
  46. package/tools/issues-command.test.js +4 -7
  47. package/tools/issues-section.test.js +71 -81
  48. package/tools/odd-rail-wiring.test.js +16 -10
  49. package/tools/package-surface.test.js +42 -13
  50. package/tools/prs-command.test.js +11 -6
  51. package/tools/shell-api/api.test.ts +484 -0
  52. package/tools/shell-api/apply-on-move.test.ts +529 -0
  53. package/tools/shell-api/arm.test.ts +220 -0
  54. package/tools/shell-api/bridge-ready.test.ts +309 -0
  55. package/tools/shell-api/bus.test.ts +194 -0
  56. package/tools/shell-api/button-rows.test.ts +435 -0
  57. package/tools/shell-api/capture.test.ts +583 -0
  58. package/tools/shell-api/card-style-rows.test.ts +493 -0
  59. package/tools/shell-api/card-style-transform.test.ts +379 -0
  60. package/tools/shell-api/card-style-wiring.test.ts +258 -0
  61. package/tools/shell-api/card-styles-e2e.test.ts +502 -0
  62. package/tools/shell-api/card-styles.test.ts +324 -0
  63. package/tools/shell-api/card-transcript-path.test.ts +178 -0
  64. package/tools/shell-api/compatibility-regression.test.mjs +64 -0
  65. package/tools/shell-api/config.test.ts +93 -0
  66. package/tools/shell-api/docs-coverage.test.ts +82 -0
  67. package/tools/shell-api/e2e.test.ts +562 -0
  68. package/tools/shell-api/example-bash-identity.test.ts +372 -0
  69. package/tools/shell-api/example-bash-matrix.test.ts +856 -0
  70. package/tools/shell-api/example-designs.test.ts +737 -0
  71. package/tools/shell-api/example-neon-transform.test.ts +283 -0
  72. package/tools/shell-api/example-plain-style.test.ts +1225 -0
  73. package/tools/shell-api/extension.test.ts +157 -0
  74. package/tools/shell-api/fake-events.ts +58 -0
  75. package/tools/shell-api/fake-host.ts +211 -0
  76. package/tools/shell-api/fake-sidebar.ts +516 -0
  77. package/tools/shell-api/fake-transcript.ts +486 -0
  78. package/tools/shell-api/frame-telemetry.test.ts +317 -0
  79. package/tools/shell-api/hook.test.ts +196 -0
  80. package/tools/shell-api/manifest.test.ts +47 -0
  81. package/tools/shell-api/message-design-adoption.test.ts +611 -0
  82. package/tools/shell-api/message-design-follows.test.ts +361 -0
  83. package/tools/shell-api/message-design-pi-release.test.mjs +157 -0
  84. package/tools/shell-api/message-design-regressions.test.mjs +162 -0
  85. package/tools/shell-api/message-design-rows.test.ts +266 -0
  86. package/tools/shell-api/message-design-wiring.test.ts +362 -0
  87. package/tools/shell-api/message-designs.test.ts +339 -0
  88. package/tools/shell-api/new-category.test.ts +1101 -0
  89. package/tools/shell-api/notices.test.ts +292 -0
  90. package/tools/shell-api/plugin-integration-lines.test.ts +827 -0
  91. package/tools/shell-api/presence.test.ts +396 -0
  92. package/tools/shell-api/rail-part-hits.test.ts +281 -0
  93. package/tools/shell-api/rail-surfaces.test.ts +402 -0
  94. package/tools/shell-api/rail-width.test.ts +406 -0
  95. package/tools/shell-api/regression.test.ts +434 -0
  96. package/tools/shell-api/repaint-api.test.ts +200 -0
  97. package/tools/shell-api/reserved-categories.test.ts +250 -0
  98. package/tools/shell-api/row-labels.test.ts +261 -0
  99. package/tools/shell-api/row-names.test.ts +407 -0
  100. package/tools/shell-api/row-origin.test.ts +395 -0
  101. package/tools/shell-api/row-placement-regression.test.ts +797 -0
  102. package/tools/shell-api/row-placement.test.ts +410 -0
  103. package/tools/shell-api/section-interaction.test.ts +364 -0
  104. package/tools/shell-api/section-panel.test.ts +430 -0
  105. package/tools/shell-api/section-placement-rail.test.ts +390 -0
  106. package/tools/shell-api/section-placement.test.ts +386 -0
  107. package/tools/shell-api/sections-preview.test.ts +312 -0
  108. package/tools/shell-api/sections-rows.test.ts +293 -0
  109. package/tools/shell-api/sidebar-backend.test.ts +477 -0
  110. package/tools/shell-api/sidebar-e2e.test.ts +317 -0
  111. package/tools/shell-api/sidebar-hover.test.ts +276 -0
  112. package/tools/shell-api/sidebar-independent.test.ts +291 -0
  113. package/tools/shell-api/sidebar-render.test.ts +281 -0
  114. package/tools/shell-api/sidebar-sections.test.ts +247 -0
  115. package/tools/shell-api/store.test.ts +192 -0
  116. package/tools/shell-api/surface-repaint-cost.test.ts +520 -0
  117. package/tools/shell-api/tool-design-card-style.test.ts +308 -0
  118. package/tools/shell-api/tool-design-chain.test.ts +471 -0
  119. package/tools/shell-api/tool-design-cost.test.ts +591 -0
  120. package/tools/shell-api/tool-design-rows.test.ts +627 -0
  121. package/tools/shell-api/tool-design-scopes-audit.test.ts +212 -0
  122. package/tools/shell-api/tool-designs.test.ts +2412 -0
  123. package/tools/shell-api/transform-pipeline.test.ts +376 -0
  124. package/tools/shell-api/transforms-bus.test.ts +233 -0
  125. package/tools/shell-api/verifier-width-regressions.test.ts +147 -0
  126. package/tools/shell-api-rpc.test.js +189 -0
  127. package/tools/user-prompt-card.test.js +80 -10
@@ -0,0 +1,147 @@
1
+ /**
2
+ * The verifier's width findings, pinned (W2-T2–W2-T4, A-T5, C-T2/C-T3 adjacent).
3
+ *
4
+ * Each expectation below is the value pi-tui's own `visibleWidth` produces for that string
5
+ * (`@earendil-works/pi-tui/dist/utils.js:126-268`, measured with the installed host copy), so this
6
+ * file is a differential fixture with pinned numbers instead of a second implementation:
7
+ *
8
+ * - a cluster is charged the way `graphemeWidth` charges it: zero for a cluster of marks, two only
9
+ * when `couldBeEmoji` AND `\p{RGI_Emoji}` both hold (so `©` is ONE column, `©️` is two), the base
10
+ * code point's East Asian width otherwise, plus every trailing halfwidth/fullwidth form and the
11
+ * Thai/Lao AM vowels;
12
+ * - a row that already fits is byte-identical, escapes included, even at width zero;
13
+ * - a cut never splits a grapheme cluster, even when an SGR sequence sits inside it.
14
+ */
15
+
16
+ import assert from "node:assert/strict";
17
+ import test from "node:test";
18
+
19
+ import { registerTransform, resetTransformsForTests } from "../../lib/shell-api/bus.ts";
20
+ import { clipToWidth, hostColumns } from "../../lib/shell-api/card-style-transform.ts";
21
+ import { applyTransforms, resetTransformPipelineForTests } from "../../lib/shell-api/transform-pipeline.ts";
22
+
23
+ test.beforeEach(() => {
24
+ resetTransformsForTests();
25
+ resetTransformPipelineForTests();
26
+ });
27
+
28
+ // ---------------------------------------------------------------------------------------------
29
+ // The host's measure, cluster by cluster
30
+ // ---------------------------------------------------------------------------------------------
31
+
32
+ test("a symbol that is not an RGI emoji is one column; a qualified or keycap emoji is two", () => {
33
+ for (const symbol of ["©", "®", "™", "☺"]) {
34
+ assert.equal(hostColumns(symbol), 1, `${symbol} is not an RGI emoji: the host charges one column`);
35
+ }
36
+ assert.equal(hostColumns("©️"), 2, "the emoji presentation selector makes it an RGI emoji");
37
+ assert.equal(hostColumns("1️⃣"), 2, "a keycap sequence is one two-column cluster");
38
+ });
39
+
40
+ test("a trailing halfwidth/fullwidth form is charged its own column", () => {
41
+ assert.equal(hostColumns("ガ"), 2, "halfwidth KA plus the voiced sound mark");
42
+ assert.equal(hostColumns("ガギ"), 4, "two voiced halfwidth kana are four columns");
43
+ assert.equal(hostColumns("ア"), 1, "a bare halfwidth kana is one column");
44
+ });
45
+
46
+ test("a cluster of marks charges nothing, and a leading mark rides its base", () => {
47
+ assert.equal(hostColumns("्"), 0, "a lone Devanagari virama occupies no cell");
48
+ assert.equal(hostColumns("़क"), 1, "the leading nukta is stripped before measuring क");
49
+ assert.equal(hostColumns("क्"), 1);
50
+ assert.equal(hostColumns("e\u0301"), 1, "a combining acute rides its base");
51
+ });
52
+
53
+ test("a Devanagari spacing mark occupies its own cell, as the host allocates one", () => {
54
+ assert.equal(hostColumns("ि"), 1, "U+093F is a Spacing_Mark: the host charges it one column");
55
+ assert.equal(hostColumns("ा"), 1, "U+093E is a Spacing_Mark too");
56
+ assert.equal(hostColumns("नमस्ते"), 4, "the host's own number for नमस्ते (pi-tui 1.5.x)");
57
+ assert.equal(hostColumns("हिन्दी"), 5, "the host's own number for हिन्दी");
58
+ });
59
+
60
+ // ---------------------------------------------------------------------------------------------
61
+ // W2-3: a consonant that follows a mark is charged, so it cannot overflow a narrower frame
62
+ // ---------------------------------------------------------------------------------------------
63
+
64
+ test("an Indic conjunct that follows a mark is two columns, and is never cut into one column", () => {
65
+ // pi-tui 1.5.x charges the base (क) plus the visible consonant after the virama (ष): 2 columns.
66
+ // Charging the cluster as its base alone made a "one column" frame hold two.
67
+ assert.equal(hostColumns("क्‍ष"), 2, "the host charges the conjunct two columns");
68
+ assert.equal(hostColumns("क्ष"), 2, "with or without the joiner");
69
+ assert.equal(hostColumns("क्‍षा"), 3, "the trailing spacing mark adds its own cell");
70
+
71
+ assert.equal(
72
+ clipToWidth("क्‍षx", 1),
73
+ "",
74
+ "a two-column cluster cannot be emitted in a one-column frame",
75
+ );
76
+ assert.equal(clipToWidth("क्‍षx", 2), "क्‍ष", "at two columns the whole cluster fits");
77
+ assert.equal(hostColumns(clipToWidth("क्‍षx", 2)), 2, "and the result measures exactly two");
78
+ for (const width of [0, 1, 2, 3]) {
79
+ assert.ok(
80
+ hostColumns(clipToWidth("क्‍षx", width)) <= width,
81
+ `the cut at ${width} never exceeds the frame`,
82
+ );
83
+ }
84
+ });
85
+
86
+ test("the pipeline clips an overflowing Indic conjunct instead of emitting it", () => {
87
+ registerTransform({ id: "indic", transform: () => ["क्‍षx"] });
88
+
89
+ assert.deepEqual(applyTransforms(["host"], 1), [""], "nothing wider than the frame reaches the host");
90
+ assert.deepEqual(applyTransforms(["host"], 2), ["क्‍ष"]);
91
+ });
92
+
93
+ test("a Thai/Lao AM vowel adds a column, and an ignorable symbol adds none", () => {
94
+ assert.equal(hostColumns("กำ"), 2, "the trailing AM vowel is charged one extra column");
95
+ assert.equal(hostColumns("ເກຳ"), 3, "the same rule for Lao");
96
+ assert.equal(hostColumns("\u00ad"), 0, "a soft hyphen is default-ignorable: no columns");
97
+ assert.equal(hostColumns("👨‍👩‍👧‍👦"), 2, "a ZWJ family is one two-column cluster");
98
+ assert.equal(hostColumns("👍🏽"), 2, "a skin-tone modifier rides its base");
99
+ });
100
+
101
+ // ---------------------------------------------------------------------------------------------
102
+ // Fitting rows are byte-identical, at every width — including zero
103
+ // ---------------------------------------------------------------------------------------------
104
+
105
+ test("a row that fits at width zero keeps its bytes, escapes included", () => {
106
+ const sgr = "\u001b[31m";
107
+ const link = "\u001b]8;;http://example.com\u0007\u001b]8;;\u0007";
108
+ const background = "\u001b[48;5;236m\u001b[0m";
109
+
110
+ assert.equal(clipToWidth(sgr, 0), sgr, "an SGR-only row has no columns and must survive");
111
+ assert.equal(clipToWidth(link, 0), link, "an empty hyperlink is the same empty hyperlink");
112
+ assert.equal(clipToWidth(background, 0), background);
113
+ assert.equal(clipToWidth("\u001b[31m\u001b[39m", 0), "\u001b[31m\u001b[39m");
114
+ });
115
+
116
+ test("a row with no columns is passed through, and a row with columns is emptied, at width zero", () => {
117
+ assert.equal(clipToWidth("", 0), "");
118
+ assert.equal(clipToWidth("A", 0), "", "a visible column cannot be drawn in zero columns");
119
+ assert.equal(clipToWidth("\u001b[31mA", 0), "", "the paint alone is not a row fit to draw");
120
+ });
121
+
122
+ test("the pipeline returns an ANSI-only row untouched at width zero", () => {
123
+ registerTransform({ id: "ansi-only", transform: () => ["\u001b[31m", "A"] });
124
+
125
+ assert.deepEqual(applyTransforms(["host"], 0), ["\u001b[31m", ""], "only the visible column is cut");
126
+ });
127
+
128
+ // ---------------------------------------------------------------------------------------------
129
+ // The cut never splits a cluster, even with SGR interleaved
130
+ // ---------------------------------------------------------------------------------------------
131
+
132
+ test("an SGR inside a grapheme cluster does not split it, and the kept paint is reset", () => {
133
+ const row = "👨\u001b[31m‍👩‍👧‍👦AB";
134
+ assert.equal(hostColumns(row), 4, "the host measures the family as one cluster plus A and B");
135
+
136
+ const clipped = clipToWidth(row, 2);
137
+
138
+ assert.equal(clipped, "👨\u001b[31m‍👩‍👧‍👦\u001b[0m", "the whole family is kept, then the paint is reset");
139
+ assert.equal(clipped.split("\u200d").length - 1, 3, "every joiner of the family survived the cut");
140
+ assert.equal(hostColumns(clipped), 2, "and it measures the host's width exactly");
141
+ });
142
+
143
+ test("the pipeline applies that cut to what a transform returns", () => {
144
+ registerTransform({ id: "family", transform: () => ["👨\u001b[31m‍👩‍👧‍👦AB"] });
145
+
146
+ assert.deepEqual(applyTransforms(["host"], 2), ["👨\u001b[31m‍👩‍👧‍👦\u001b[0m"]);
147
+ });
@@ -0,0 +1,189 @@
1
+ 'use strict';
2
+ // native-bridge T5: the real-host check. It drives a real `pi --mode rpc` with ONLY this package
3
+ // loaded, so it proves what the fixture-stubbed suite cannot: odd-worktree's own shell API
4
+ // publishes the slot, arms, and a third party can extend it. It needs the host binary and a
5
+ // type-stripping Node, so it is opt-in:
6
+ // NATIVE_BRIDGE_PI="$(command -v pi)" node --test tools/shell-api-rpc.test.js
7
+ const assert = require('node:assert/strict');
8
+ const { spawnSync } = require('node:child_process');
9
+ const { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } = require('node:fs');
10
+ const { tmpdir } = require('node:os');
11
+ const { join, resolve } = require('node:path');
12
+ const test = require('node:test');
13
+
14
+ const pi = process.env.NATIVE_BRIDGE_PI;
15
+ const entry = resolve(__dirname, '../extensions/odd-worktree-tools.ts');
16
+ const slot = 'Symbol.for("gentle-shell-bridge/api/v1")';
17
+ const get = { type: 'get_commands', id: '1' };
18
+
19
+ function rpc(t, before, after, commands) {
20
+ const dir = mkdtempSync(join(tmpdir(), 'odd-shell-api-rpc-'));
21
+ t.after(() => rmSync(dir, { recursive: true, force: true }));
22
+ const home = join(dir, 'home');
23
+ const tmp = join(dir, 'tmp');
24
+ const ad = join(dir, 'agent');
25
+ for (const path of [home, tmp, ad]) mkdirSync(path);
26
+ const probe = join(dir, 'probe.ts');
27
+ const report = join(dir, 'probe-report.json');
28
+ writeFileSync(probe, before || after);
29
+ const flags = before ? ['-e', probe, '-e', entry] : ['-e', entry, '-e', probe];
30
+ const result = spawnSync('bash', [
31
+ '-c', 'set -o pipefail; (cat; sleep 6) | timeout 25 "$@"', 'rpc',
32
+ pi, '--agent-dir', ad, '--no-session', '-ne', '-ns', '-np', ...flags, '--mode', 'rpc',
33
+ ], {
34
+ cwd: dir, encoding: 'utf8', timeout: 28000,
35
+ input: commands.map((x) => JSON.stringify(x) + '\n').join(''),
36
+ env: {
37
+ PATH: process.env.PATH,
38
+ HOME: home,
39
+ TMPDIR: tmp,
40
+ NO_UPDATE_NOTIFIER: '1',
41
+ PROBE_REPORT: report,
42
+ },
43
+ });
44
+ assert.ifError(result.error);
45
+ assert.equal(result.status, 0, result.stderr);
46
+ const records = result.stdout
47
+ .split('\n')
48
+ .filter((line) => line.startsWith('{'))
49
+ .map((line) => JSON.parse(line));
50
+ const report_ = () => JSON.parse(readFileSync(report, 'utf8'));
51
+ return { records, report: report_ };
52
+ }
53
+
54
+ test('only this package: six commands, the slot published, and a third party extends it', { skip: !pi }, (t) => {
55
+ const { records, report } = rpc(t, null, `
56
+ import { writeFileSync } from "node:fs";
57
+
58
+ export default function (pi) {
59
+ pi.registerCommand("gentle:customize", { handler() {} });
60
+ pi.on("session_start", () => {
61
+ const api = globalThis[${slot}];
62
+ const answer = {
63
+ schema: api?.schema,
64
+ version: api?.version,
65
+ VERSION: api?.VERSION,
66
+ members: api === undefined ? [] : Object.keys(api).sort(),
67
+ };
68
+ // A third party registers exactly as the contract says, and the registration answers with
69
+ // its own disposer. The slot publishes registries, not readers, so this is the whole
70
+ // observable answer for a caller.
71
+ const disposer = api?.registerRows({ id: "probe.rows", category: "Probe", rows: () => [] });
72
+ answer.disposer = typeof disposer;
73
+ writeFileSync(process.env.PROBE_REPORT, JSON.stringify(answer));
74
+ });
75
+ }`, [get]);
76
+ const names = records.find((x) => x.id === '1').data.commands.map((c) => c.name);
77
+ for (const name of ['warp', 'odd', 'files', 'issues', 'prs', 'identity']) {
78
+ assert.equal(names.filter((candidate) => candidate === name).length, 1, name);
79
+ }
80
+ assert.equal(names.includes('bridge-status'), false, 'the status command is gone');
81
+ const answer = report();
82
+ assert.equal(answer.schema, 'gentle-shell-bridge/api');
83
+ assert.equal(answer.version, 1);
84
+ assert.equal(answer.VERSION, '0.16.2', 'the release consumers gate on');
85
+ assert.deepEqual(answer.members, [
86
+ 'VERSION',
87
+ 'createStore',
88
+ 'registerCardStyle',
89
+ 'registerMessageDesign',
90
+ 'registerRows',
91
+ 'registerSection',
92
+ 'registerToolDesign',
93
+ 'registerTransform',
94
+ 'requestRepaint',
95
+ 'resolveToolDesignSelection',
96
+ 'schema',
97
+ 'version',
98
+ ]);
99
+ assert.equal(answer.disposer, 'function', 'a registration answers with its disposer');
100
+ });
101
+
102
+ test('a first-loaded plugin sees the API, adds a section and removes it again', { skip: !pi }, (t) => {
103
+ const { report } = rpc(t, `
104
+ import { writeFileSync } from "node:fs";
105
+
106
+ export default function (pi) {
107
+ pi.registerCommand("gentle:customize", { handler() {} });
108
+ let ready = 0;
109
+ pi.events.on("gentle-shell-bridge:ready", () => { ready += 1; });
110
+ pi.on("session_start", () => {
111
+ const api = globalThis[${slot}];
112
+ const ids = () =>
113
+ globalThis[Symbol.for("gentle-shell-bridge.providers")].sections
114
+ .map((entry) => entry.section.id)
115
+ .sort();
116
+ const own = ids();
117
+ const dispose = api.registerSection({
118
+ id: "verification.section",
119
+ title: "Verification",
120
+ lines: () => ["probe"],
121
+ });
122
+ const added = ids();
123
+ dispose();
124
+ dispose();
125
+ writeFileSync(process.env.PROBE_REPORT, JSON.stringify({
126
+ own, added, after: ids(), ready,
127
+ identity: [api.schema, api.version, api.VERSION],
128
+ }));
129
+ });
130
+ }`, null, [get]);
131
+ const saw = report();
132
+ const own = ['odd-worktree.issues', 'odd-worktree.odd-rail'];
133
+ assert.deepEqual(saw.own, own, 'this package\'s two sections are there before the probe registers');
134
+ assert.deepEqual(saw.added, [...own, 'verification.section'], 'a third party adds its own');
135
+ assert.deepEqual(saw.after, own, 'and its disposer removes exactly that one, twice safely');
136
+ assert.equal(saw.ready, 1, 'the ready announcement reaches a plugin loaded first');
137
+ assert.deepEqual(saw.identity, ['gentle-shell-bridge/api', 1, '0.16.2']);
138
+ });
139
+
140
+ test('an incompatible object on the slot leaves this package\'s surface unregistered and says so once', { skip: !pi }, (t) => {
141
+ const { records } = rpc(t, `
142
+ globalThis[${slot}] = { schema: "other-bridge/api", version: 2 };
143
+ export default function (pi) {
144
+ pi.registerCommand("gentle:customize", { handler() {} });
145
+ }
146
+ `, null, [get]);
147
+ const names = records.find((x) => x.id === '1').data.commands.map((c) => c.name);
148
+ for (const name of ['warp', 'odd', 'files', 'identity', 'issues', 'prs']) {
149
+ assert.equal(names.includes(name), false, `/${name} is not registered`);
150
+ }
151
+ const warnings = records.filter((x) => x.method === 'notify' && x.notifyType === 'warning');
152
+ const foreign = warnings.filter((x) => x.message.startsWith('odd-worktree:'));
153
+ assert.equal(foreign.length, 1, 'one notice, in this package\'s own words');
154
+ assert.match(foreign[0].message, /other-bridge\/api/, 'it names the schema the slot really holds');
155
+ assert.match(foreign[0].message, /"2"/, 'and its version');
156
+ assert.match(foreign[0].message, /sidebar sections/, 'and what is off');
157
+ });
158
+
159
+ for (const schema of ['third-party/v2', 'gentle-shell-bridge/api']) {
160
+ test(`foreign slot ${schema}: one warning, no commands, no row of this package, and no load failure`, { skip: !pi }, (t) => {
161
+ const { records, report } = rpc(t, `
162
+ import { writeFileSync } from "node:fs";
163
+ const key = ${slot};
164
+ const foreign = {
165
+ schema: ${JSON.stringify(schema)},
166
+ get version() { throw new Error("unreadable version"); },
167
+ };
168
+ globalThis[key] = foreign;
169
+ export default function (pi) {
170
+ pi.registerCommand("gentle:customize", { handler() {} });
171
+ pi.on("session_start", () => setImmediate(() => {
172
+ const bus = globalThis[Symbol.for("gentle-shell-bridge.providers")];
173
+ writeFileSync(process.env.PROBE_REPORT, JSON.stringify({
174
+ preserved: globalThis[key] === foreign,
175
+ providers: ((bus && bus.entries) || []).map((entry) => entry.provider.id),
176
+ }));
177
+ }));
178
+ }
179
+ `, null, [get]);
180
+ const commands = records.find((x) => x.id === '1').data.commands;
181
+ assert.deepEqual(commands.filter((x) => x.source === 'extension').map((x) => x.name), ['gentle:customize']);
182
+ const warnings = records.filter((x) => x.method === 'notify' && x.notifyType === 'warning' && x.message.startsWith('odd-worktree:'));
183
+ assert.equal(warnings.length, 1, 'one notice, in this package\'s own words');
184
+ assert.ok(warnings[0].message.includes(`schema "${schema}", version "unreadable"`));
185
+ const saw = report();
186
+ assert.equal(saw.preserved, true, 'the foreign object is never replaced');
187
+ assert.deepEqual(saw.providers.filter((id) => id.startsWith('odd-worktree.')), [], 'none of this package\'s own rows');
188
+ });
189
+ }
@@ -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();
@@ -830,10 +901,11 @@ test('S7: factory load does not arm a host import before session_start', async (
830
901
  }
831
902
  });
832
903
 
833
- test('S7: silent publication on a host without a bus acquires a shutdown owner', async () => {
834
- // The gate observer is a WAKE-UP path, not a session: a bridge published silently wakes the
835
- // surface from a `session_start`, and that same load must then own the shutdown that unwraps
836
- // it. With no event bus the observer is the only way in.
904
+ test('S7 (T2): with no bridge on the slot nothing is registered, and a silent publication never arms an install', async () => {
905
+ // The gate observer is gone (native-bridge T2): the shell API publishes at module load, the
906
+ // factory reads the slot ONCE, and a load that found it empty keeps no observer to be woken by.
907
+ // What S7 still guarantees is the other half: a load that DID find the bridge owns the shutdown
908
+ // that unwraps the card, which is what the first test above proves.
837
909
  const previousBridge = globalThis[BRIDGE_API_SLOT];
838
910
  delete globalThis[BRIDGE_API_SLOT];
839
911
  class Host {
@@ -845,14 +917,12 @@ test('S7: silent publication on a host without a bus acquires a shutdown owner',
845
917
  const { hooks } = await loadExtensionModule(() => ({ UserMessageComponent: Host }));
846
918
  const emit = extensionSession(hooks);
847
919
  try {
848
- assert.deepEqual(hooks.map(([event]) => event), ['session_start'], 'a gate-closed load keeps its ONE observer');
849
- // A SILENT publication: nothing announces it, so `session_start` is what wakes the surface.
920
+ assert.deepEqual(hooks, [], 'a load with no bridge registers no hook at all');
921
+ // A SILENT publication: nothing announces it, and nothing is listening for it either.
850
922
  globalThis[BRIDGE_API_SLOT] = fixture.defaultBridge().api;
851
923
  await emit('session_start');
852
924
  await drain();
853
- assert.notEqual(Host.prototype.render, native, 'the waking session draws the card');
854
- await emit('session_shutdown');
855
- assert.equal(Host.prototype.render, native, 'and it owns the shutdown that unwraps it');
925
+ assert.equal(Host.prototype.render, native, 'nothing installs: no session boundary was owned');
856
926
  } finally {
857
927
  await emit('session_shutdown');
858
928
  if (previousBridge === undefined) delete globalThis[BRIDGE_API_SLOT];