pi-odd-worktree 3.15.1 → 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.
- package/README.md +48 -25
- package/extensions/odd-worktree-tools.ts +64 -211
- package/lib/shell-api/api.ts +523 -0
- package/lib/shell-api/arm.ts +83 -0
- package/lib/shell-api/bus.ts +1389 -0
- package/lib/shell-api/capture.ts +1340 -0
- package/lib/shell-api/card-style-line.ts +112 -0
- package/lib/shell-api/card-style-rows.ts +390 -0
- package/lib/shell-api/card-style-transform.ts +862 -0
- package/lib/shell-api/card-style-wiring.ts +477 -0
- package/lib/shell-api/card-styles.ts +153 -0
- package/lib/shell-api/config.ts +71 -0
- package/lib/shell-api/extension.ts +247 -0
- package/lib/shell-api/hook.ts +322 -0
- package/lib/shell-api/index.ts +88 -0
- package/lib/shell-api/message-design-adoption.ts +549 -0
- package/lib/shell-api/message-design-rows.ts +313 -0
- package/lib/shell-api/message-design-wiring.ts +369 -0
- package/lib/shell-api/message-designs.ts +746 -0
- package/lib/shell-api/notices.ts +137 -0
- package/lib/shell-api/plugin-lines.ts +877 -0
- package/lib/shell-api/presence.ts +258 -0
- package/lib/shell-api/repaint.ts +351 -0
- package/lib/shell-api/row-labels.ts +146 -0
- package/lib/shell-api/row-names.ts +273 -0
- package/lib/shell-api/row-origin.ts +144 -0
- package/lib/shell-api/rows.ts +591 -0
- package/lib/shell-api/section-panel.ts +378 -0
- package/lib/shell-api/section-pointer.ts +164 -0
- package/lib/shell-api/sections-preview.ts +275 -0
- package/lib/shell-api/sections-rows.ts +133 -0
- package/lib/shell-api/sidebar-render.ts +705 -0
- package/lib/shell-api/sidebar.ts +1126 -0
- package/lib/shell-api/store.ts +279 -0
- package/lib/shell-api/tool-design-adoption.ts +263 -0
- package/lib/shell-api/tool-design-rows.ts +307 -0
- package/lib/shell-api/tool-design-wiring.ts +481 -0
- package/lib/shell-api/tool-designs.ts +1411 -0
- package/lib/shell-api/transform-pipeline.ts +351 -0
- package/lib/shell-api/types.ts +803 -0
- package/lib/shell-api/visibility.ts +154 -0
- package/package.json +3 -2
- package/tools/files-bridge.test.js +81 -66
- package/tools/fixtures/load-extension.js +40 -18
- package/tools/issues-command.test.js +4 -7
- package/tools/issues-section.test.js +71 -81
- package/tools/odd-rail-wiring.test.js +16 -10
- package/tools/package-surface.test.js +42 -13
- package/tools/prs-command.test.js +11 -6
- package/tools/shell-api/api.test.ts +484 -0
- package/tools/shell-api/apply-on-move.test.ts +529 -0
- package/tools/shell-api/arm.test.ts +220 -0
- package/tools/shell-api/bridge-ready.test.ts +309 -0
- package/tools/shell-api/bus.test.ts +194 -0
- package/tools/shell-api/button-rows.test.ts +435 -0
- package/tools/shell-api/capture.test.ts +583 -0
- package/tools/shell-api/card-style-rows.test.ts +493 -0
- package/tools/shell-api/card-style-transform.test.ts +379 -0
- package/tools/shell-api/card-style-wiring.test.ts +258 -0
- package/tools/shell-api/card-styles-e2e.test.ts +502 -0
- package/tools/shell-api/card-styles.test.ts +324 -0
- package/tools/shell-api/card-transcript-path.test.ts +178 -0
- package/tools/shell-api/compatibility-regression.test.mjs +64 -0
- package/tools/shell-api/config.test.ts +93 -0
- package/tools/shell-api/docs-coverage.test.ts +82 -0
- package/tools/shell-api/e2e.test.ts +562 -0
- package/tools/shell-api/example-bash-identity.test.ts +372 -0
- package/tools/shell-api/example-bash-matrix.test.ts +856 -0
- package/tools/shell-api/example-designs.test.ts +737 -0
- package/tools/shell-api/example-neon-transform.test.ts +283 -0
- package/tools/shell-api/example-plain-style.test.ts +1225 -0
- package/tools/shell-api/extension.test.ts +157 -0
- package/tools/shell-api/fake-events.ts +58 -0
- package/tools/shell-api/fake-host.ts +211 -0
- package/tools/shell-api/fake-sidebar.ts +516 -0
- package/tools/shell-api/fake-transcript.ts +486 -0
- package/tools/shell-api/frame-telemetry.test.ts +317 -0
- package/tools/shell-api/hook.test.ts +196 -0
- package/tools/shell-api/manifest.test.ts +47 -0
- package/tools/shell-api/message-design-adoption.test.ts +611 -0
- package/tools/shell-api/message-design-follows.test.ts +361 -0
- package/tools/shell-api/message-design-pi-release.test.mjs +157 -0
- package/tools/shell-api/message-design-regressions.test.mjs +162 -0
- package/tools/shell-api/message-design-rows.test.ts +266 -0
- package/tools/shell-api/message-design-wiring.test.ts +362 -0
- package/tools/shell-api/message-designs.test.ts +339 -0
- package/tools/shell-api/new-category.test.ts +1101 -0
- package/tools/shell-api/notices.test.ts +292 -0
- package/tools/shell-api/plugin-integration-lines.test.ts +827 -0
- package/tools/shell-api/presence.test.ts +396 -0
- package/tools/shell-api/rail-part-hits.test.ts +281 -0
- package/tools/shell-api/rail-surfaces.test.ts +402 -0
- package/tools/shell-api/rail-width.test.ts +406 -0
- package/tools/shell-api/regression.test.ts +434 -0
- package/tools/shell-api/repaint-api.test.ts +200 -0
- package/tools/shell-api/reserved-categories.test.ts +250 -0
- package/tools/shell-api/row-labels.test.ts +261 -0
- package/tools/shell-api/row-names.test.ts +407 -0
- package/tools/shell-api/row-origin.test.ts +395 -0
- package/tools/shell-api/row-placement-regression.test.ts +797 -0
- package/tools/shell-api/row-placement.test.ts +410 -0
- package/tools/shell-api/section-interaction.test.ts +364 -0
- package/tools/shell-api/section-panel.test.ts +430 -0
- package/tools/shell-api/section-placement-rail.test.ts +390 -0
- package/tools/shell-api/section-placement.test.ts +386 -0
- package/tools/shell-api/sections-preview.test.ts +312 -0
- package/tools/shell-api/sections-rows.test.ts +293 -0
- package/tools/shell-api/sidebar-backend.test.ts +477 -0
- package/tools/shell-api/sidebar-e2e.test.ts +317 -0
- package/tools/shell-api/sidebar-hover.test.ts +276 -0
- package/tools/shell-api/sidebar-independent.test.ts +291 -0
- package/tools/shell-api/sidebar-render.test.ts +281 -0
- package/tools/shell-api/sidebar-sections.test.ts +247 -0
- package/tools/shell-api/store.test.ts +192 -0
- package/tools/shell-api/surface-repaint-cost.test.ts +520 -0
- package/tools/shell-api/tool-design-card-style.test.ts +308 -0
- package/tools/shell-api/tool-design-chain.test.ts +471 -0
- package/tools/shell-api/tool-design-cost.test.ts +591 -0
- package/tools/shell-api/tool-design-rows.test.ts +627 -0
- package/tools/shell-api/tool-design-scopes-audit.test.ts +212 -0
- package/tools/shell-api/tool-designs.test.ts +2412 -0
- package/tools/shell-api/transform-pipeline.test.ts +376 -0
- package/tools/shell-api/transforms-bus.test.ts +233 -0
- package/tools/shell-api/verifier-width-regressions.test.ts +147 -0
- package/tools/shell-api-rpc.test.js +189 -0
- package/tools/user-prompt-card.test.js +8 -9
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The customize rows for message designs (S1): ONE line per LINE that has designs, in `Cards`.
|
|
3
|
+
*
|
|
4
|
+
* The shape is the tool designs' (`./tool-design-rows.ts`), with one word changed: the values of a
|
|
5
|
+
* message design belong to a MESSAGE line, so the row reads `Message <words>` where a design agent sees
|
|
6
|
+
* `Card <words>`. Everything else is the same discipline, because a plugin author should not have to
|
|
7
|
+
* learn two menus:
|
|
8
|
+
*
|
|
9
|
+
* - **`default` first, stored as `native`.** The user reads `default`; the store keeps identity, so a
|
|
10
|
+
* renamed label never loses a choice.
|
|
11
|
+
* - **The id is never shown.** A design's `label` is its value and its `id` is what is persisted.
|
|
12
|
+
* - **One line per line.** The host coalesces consecutive rows sharing a `choice.setting`, so all the
|
|
13
|
+
* values of one line live on one line and the menu does not split per custom type.
|
|
14
|
+
* - **No design, no line.** With nothing registered the provider contributes NOTHING, so a session that
|
|
15
|
+
* never installed a design plugin gains no empty row.
|
|
16
|
+
* - **A change repaints what is on screen.** The action persists FIRST (the host re-reads `current()`
|
|
17
|
+
* when it repaints) and then asks for one differential frame; a press that changes nothing costs none.
|
|
18
|
+
*
|
|
19
|
+
* This module is internal: `src/index.ts` does not re-export it.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
import { registerBridgeRows, snapshotProviders } from "./bus.ts";
|
|
23
|
+
import { HOST_CARD_STYLE_CATEGORY } from "./card-style-line.ts";
|
|
24
|
+
import { recordNotice } from "./notices.ts";
|
|
25
|
+
import { requestRepaint } from "./repaint.ts";
|
|
26
|
+
import { deriveRowLabel } from "./row-labels.ts";
|
|
27
|
+
import { MAX_ROW_NAME_WORDS } from "./row-names.ts";
|
|
28
|
+
import { isRecord } from "./rows.ts";
|
|
29
|
+
import {
|
|
30
|
+
MESSAGE_DESIGN_DEFAULT_LABEL,
|
|
31
|
+
MESSAGE_DESIGN_NATIVE,
|
|
32
|
+
getMessageDesignLineSelection,
|
|
33
|
+
messageDesignLines,
|
|
34
|
+
setMessageDesignLineSelection,
|
|
35
|
+
setMessageDesignRowsInstaller,
|
|
36
|
+
type MessageDesignLine,
|
|
37
|
+
type MessageDesignScope,
|
|
38
|
+
} from "./message-designs.ts";
|
|
39
|
+
import type { CustomizeRow, MessageDesignRegistration, RowPreview, RowProvider } from "./types.ts";
|
|
40
|
+
|
|
41
|
+
/** The rows provider's id; it is the bridge's own registration, never a plugin's. */
|
|
42
|
+
export const MESSAGE_DESIGN_ROWS_PROVIDER_ID = "bridge.message-designs";
|
|
43
|
+
|
|
44
|
+
/** The word every message line starts with: the `Cards` category's vocabulary for a message surface. */
|
|
45
|
+
const MESSAGE_LINE_PREFIX = "Message";
|
|
46
|
+
|
|
47
|
+
/** What a custom type that derives to nothing still reads as. */
|
|
48
|
+
const TYPE_NAME_FALLBACK = "message";
|
|
49
|
+
|
|
50
|
+
/** What a line id that derives to nothing still reads as. */
|
|
51
|
+
const LINE_NAME_FALLBACK = "line";
|
|
52
|
+
|
|
53
|
+
/** A source's readable words, clamped so the prefix plus them fits the row-name word limit. */
|
|
54
|
+
function sourceWords(scope: MessageDesignScope, source: string): string[] {
|
|
55
|
+
const derived = deriveRowLabel(source);
|
|
56
|
+
const fallback = scope === "type" ? TYPE_NAME_FALLBACK : LINE_NAME_FALLBACK;
|
|
57
|
+
const words = derived === "" ? [fallback] : derived.split(" ").filter((word) => word !== "");
|
|
58
|
+
const budget = Math.max(1, MAX_ROW_NAME_WORDS - 1);
|
|
59
|
+
return words.length > budget ? words.slice(words.length - budget) : words;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** One line with the name the menu shows for it. */
|
|
63
|
+
export interface MessageDesignLineName {
|
|
64
|
+
scope: MessageDesignScope;
|
|
65
|
+
line: string;
|
|
66
|
+
name: string;
|
|
67
|
+
types: string[];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* The line name of every line that has designs, in creation order: `Message <words>`, made unique the
|
|
72
|
+
* way every other surface is — the readable name, then the lowest free ordinal (replacing the last word
|
|
73
|
+
* when the base already uses the full word limit, so the result still passes the shape rule).
|
|
74
|
+
*/
|
|
75
|
+
export function messageDesignLineNames(): MessageDesignLineName[] {
|
|
76
|
+
const taken = new Set<string>();
|
|
77
|
+
return messageDesignLines()
|
|
78
|
+
// A line made only of FOLLOWING designs has no switch of its own (S1): the tool line they follow
|
|
79
|
+
// is the switch, and a row here would be the second choice the user refuses to make.
|
|
80
|
+
.filter((line) => ownDesignsOf(line).length > 0)
|
|
81
|
+
.map((line) => {
|
|
82
|
+
const base = [MESSAGE_LINE_PREFIX, ...sourceWords(line.scope, line.line)].join(" ");
|
|
83
|
+
let name = base;
|
|
84
|
+
let suffix = 2;
|
|
85
|
+
while (taken.has(name)) {
|
|
86
|
+
const words = base.split(" ");
|
|
87
|
+
const kept = words.slice(0, MAX_ROW_NAME_WORDS - 1);
|
|
88
|
+
name = `${kept.join(" ")} ${suffix++}`;
|
|
89
|
+
}
|
|
90
|
+
taken.add(name);
|
|
91
|
+
return { scope: line.scope, line: line.line, name, types: [...line.types] };
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* The designs of a line that own a value on the customize menu: everything except the ones that
|
|
97
|
+
* follow a tool-design switch, whose value is chosen on that tool's own line (S1).
|
|
98
|
+
*/
|
|
99
|
+
export function ownDesignsOf(line: MessageDesignLine): MessageDesignRegistration[] {
|
|
100
|
+
return line.designs.filter((design) => design.follows === undefined);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Persist one line's value and repaint what is on screen. Nothing at all happens when the stored value
|
|
105
|
+
* is already the one picked: a press that changes nothing must not cost a frame.
|
|
106
|
+
*/
|
|
107
|
+
function selectDesign(scope: MessageDesignScope, line: string, id: string): void {
|
|
108
|
+
if (getMessageDesignLineSelection(scope, line) === id) return;
|
|
109
|
+
setMessageDesignLineSelection(scope, line, id);
|
|
110
|
+
requestRepaint();
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** The first row of a sample: a Cards value draws ONE row, so only its first line is used. */
|
|
114
|
+
function firstSampleRow(sample: string): string {
|
|
115
|
+
return sample.split(/\r?\n/u)[0] ?? sample;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** What a design's fallback preview says it paints. */
|
|
119
|
+
function designTarget(types: readonly string[]): string {
|
|
120
|
+
return types.length === 1 ? `${types[0]}'s message` : `the ${types.join(", ")} messages`;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* A design's own preview when it has one, otherwise a literal depiction of the value. A preview runs
|
|
125
|
+
* while the menu is rendered, so it must not be able to break it: a throwing (or malformed) plugin
|
|
126
|
+
* preview loses its own picture and nothing else.
|
|
127
|
+
*/
|
|
128
|
+
function previewFor(design: MessageDesignRegistration, types: readonly string[]): RowPreview {
|
|
129
|
+
if (design.preview !== undefined) {
|
|
130
|
+
try {
|
|
131
|
+
const shown: unknown = design.preview();
|
|
132
|
+
if (isRecord(shown) && typeof shown.title === "string" && typeof shown.sample === "string") {
|
|
133
|
+
return { title: shown.title, sample: firstSampleRow(shown.sample) };
|
|
134
|
+
}
|
|
135
|
+
} catch {
|
|
136
|
+
// Fall through to the literal sample below.
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return {
|
|
140
|
+
title: `Messages · ${design.label}`,
|
|
141
|
+
sample: firstSampleRow(
|
|
142
|
+
design.description ?? `${design.label}: rewrites the rows ${designTarget(types)} produced`,
|
|
143
|
+
),
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** The host's own output, untouched. It SHOWS `default` while the stored value stays `native`. */
|
|
148
|
+
function nativeRow(line: MessageDesignLine, setting: string): CustomizeRow {
|
|
149
|
+
const subject = line.types.join(", ");
|
|
150
|
+
return {
|
|
151
|
+
category: HOST_CARD_STYLE_CATEGORY,
|
|
152
|
+
choice: {
|
|
153
|
+
setting,
|
|
154
|
+
value: MESSAGE_DESIGN_DEFAULT_LABEL,
|
|
155
|
+
// Identity, never the displayed text: a renamed label cannot lose the user's choice.
|
|
156
|
+
current: () => getMessageDesignLineSelection(line.scope, line.line) === MESSAGE_DESIGN_NATIVE,
|
|
157
|
+
},
|
|
158
|
+
preview: () => ({
|
|
159
|
+
title: `Messages · ${setting}`,
|
|
160
|
+
sample: `${setting}: the host's own output for ${subject}, untouched`,
|
|
161
|
+
}),
|
|
162
|
+
action: () => selectDesign(line.scope, line.line, MESSAGE_DESIGN_NATIVE),
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/** One registered design of one line. The visible value is its label; the stored value is its id. */
|
|
167
|
+
function designRow(
|
|
168
|
+
line: MessageDesignLine,
|
|
169
|
+
setting: string,
|
|
170
|
+
design: MessageDesignRegistration,
|
|
171
|
+
): CustomizeRow {
|
|
172
|
+
return {
|
|
173
|
+
category: HOST_CARD_STYLE_CATEGORY,
|
|
174
|
+
choice: {
|
|
175
|
+
setting,
|
|
176
|
+
value: design.label,
|
|
177
|
+
current: () => getMessageDesignLineSelection(line.scope, line.line) === design.id,
|
|
178
|
+
},
|
|
179
|
+
preview: () => previewFor(design, designTypes(line, design)),
|
|
180
|
+
action: () => selectDesign(line.scope, line.line, design.id),
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/** The types one design paints, or the whole line when the registration is not found. */
|
|
185
|
+
function designTypes(line: MessageDesignLine, design: MessageDesignRegistration): string[] {
|
|
186
|
+
if (Array.isArray(design.types)) return [...design.types];
|
|
187
|
+
if (typeof design.customType === "string") return [design.customType];
|
|
188
|
+
return line.types;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* The rows of one menu build: nothing without a design, one line per line that has one.
|
|
193
|
+
*
|
|
194
|
+
* Exported for its own test, which asserts the row contract without a host; deliberately not part of
|
|
195
|
+
* the package's public API.
|
|
196
|
+
*/
|
|
197
|
+
export function messageDesignRows(): CustomizeRow[] {
|
|
198
|
+
const lines = messageDesignLines();
|
|
199
|
+
if (lines.length === 0) return [];
|
|
200
|
+
const rows: CustomizeRow[] = [];
|
|
201
|
+
for (const named of messageDesignLineNames()) {
|
|
202
|
+
const line = lines.find(
|
|
203
|
+
(candidate) => candidate.scope === named.scope && candidate.line === named.line,
|
|
204
|
+
);
|
|
205
|
+
if (line === undefined) continue;
|
|
206
|
+
const own = ownDesignsOf(line);
|
|
207
|
+
if (own.length === 0) continue;
|
|
208
|
+
rows.push(nativeRow(line, named.name));
|
|
209
|
+
for (const design of own) rows.push(designRow(line, named.name, design));
|
|
210
|
+
}
|
|
211
|
+
return rows;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
interface MessageDesignRowsState {
|
|
215
|
+
/** The live provider's disposer, while the bridge has it registered. */
|
|
216
|
+
dispose?: () => void;
|
|
217
|
+
/**
|
|
218
|
+
* The exact provider object this process registered. the diagnostics record filters by IDENTITY and not by
|
|
219
|
+
* id, so a plugin that happens to use the same id through the public `registerRows` is still listed.
|
|
220
|
+
*/
|
|
221
|
+
provider?: RowProvider;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/** Process-global, like every other piece of bridge state: two copies must agree. */
|
|
225
|
+
const ROWS_KEY = Symbol.for("gentle-shell-bridge.message-designs.rows.v1");
|
|
226
|
+
|
|
227
|
+
function rowsHost(): Record<symbol, MessageDesignRowsState | undefined> {
|
|
228
|
+
// SAFETY: only `rowsState()` writes this key, and it re-checks the shape before trusting a value left
|
|
229
|
+
// by another copy or an older load.
|
|
230
|
+
return globalThis as unknown as Record<symbol, MessageDesignRowsState | undefined>;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
function rowsState(): MessageDesignRowsState {
|
|
234
|
+
const host = rowsHost();
|
|
235
|
+
const existing = host[ROWS_KEY];
|
|
236
|
+
if (
|
|
237
|
+
existing !== undefined &&
|
|
238
|
+
(existing.dispose === undefined || typeof existing.dispose === "function")
|
|
239
|
+
) {
|
|
240
|
+
return existing;
|
|
241
|
+
}
|
|
242
|
+
const created: MessageDesignRowsState = {};
|
|
243
|
+
host[ROWS_KEY] = created;
|
|
244
|
+
return created;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Register the message-design line for this process and return a disposer that withdraws it.
|
|
249
|
+
*
|
|
250
|
+
* Call it when the bridge arms; it needs no `tui` and no capture. The provider is NOT registered
|
|
251
|
+
* here: it is registered the moment a design exists, because a session with no design must gain no
|
|
252
|
+
* provider, no row and no status line, and must pay nothing per menu build (S4). A design already
|
|
253
|
+
* registered when the bridge arms installs the line immediately. Installing twice is a no-op, so a
|
|
254
|
+
* second arm or a second loaded copy of this package cannot contribute the line twice.
|
|
255
|
+
*/
|
|
256
|
+
export function installMessageDesignRows(): () => void {
|
|
257
|
+
const state = rowsState();
|
|
258
|
+
const install = (): void => {
|
|
259
|
+
if (state.dispose !== undefined) return;
|
|
260
|
+
// The bus replaces a provider that reuses an id. This id is the bridge's own, so a plugin that
|
|
261
|
+
// registered it first keeps it: replacing it would silently take a provider the user already has
|
|
262
|
+
// off the menu, and hiding it from the diagnostics record would make the report lie about it.
|
|
263
|
+
if (snapshotProviders().some((provider) => provider.id === MESSAGE_DESIGN_ROWS_PROVIDER_ID)) {
|
|
264
|
+
recordNotice(
|
|
265
|
+
`the rows provider id ${JSON.stringify(MESSAGE_DESIGN_ROWS_PROVIDER_ID)} is already ` +
|
|
266
|
+
"registered, so the message-design line cannot be added; the other provider keeps it.",
|
|
267
|
+
);
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
const provider: RowProvider = {
|
|
271
|
+
id: MESSAGE_DESIGN_ROWS_PROVIDER_ID,
|
|
272
|
+
category: HOST_CARD_STYLE_CATEGORY,
|
|
273
|
+
// Rebuilt per build, never cached: a design registered later shows up with no re-registration.
|
|
274
|
+
rows: () => messageDesignRows(),
|
|
275
|
+
};
|
|
276
|
+
state.provider = provider;
|
|
277
|
+
state.dispose = registerBridgeRows(provider);
|
|
278
|
+
};
|
|
279
|
+
setMessageDesignRowsInstaller(install);
|
|
280
|
+
// A design that registered before the bridge armed is already waiting to be shown, and nothing else
|
|
281
|
+
// can be: the id is reserved (§1), so no plugin can hold it, hand it back, or be replaced by it. With
|
|
282
|
+
// no design there is no provider at all — Pi credits one fewer registration, the menu runs nothing
|
|
283
|
+
// extra, and the diagnostics record keeps its historical output (S4).
|
|
284
|
+
if (messageDesignLines().length > 0) install();
|
|
285
|
+
let withdrawn = false;
|
|
286
|
+
return () => {
|
|
287
|
+
if (withdrawn) return;
|
|
288
|
+
withdrawn = true;
|
|
289
|
+
setMessageDesignRowsInstaller(undefined);
|
|
290
|
+
const dispose = state.dispose;
|
|
291
|
+
state.dispose = undefined;
|
|
292
|
+
state.provider = undefined;
|
|
293
|
+
dispose?.();
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* The exact provider object this process registered, or `undefined` when it has none. Internal: it is
|
|
299
|
+
* how the diagnostics record tells the bridge's own line from a plugin's provider that uses the same id.
|
|
300
|
+
*/
|
|
301
|
+
export function bridgeMessageDesignRowsProvider(): RowProvider | undefined {
|
|
302
|
+
return rowsState().provider;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/** Test-only seam; deliberately not re-exported from `src/index.ts`. */
|
|
306
|
+
export function resetMessageDesignRowStateForTests(): void {
|
|
307
|
+
setMessageDesignRowsInstaller(undefined);
|
|
308
|
+
const state = rowsState();
|
|
309
|
+
const dispose = state.dispose;
|
|
310
|
+
state.dispose = undefined;
|
|
311
|
+
state.provider = undefined;
|
|
312
|
+
dispose?.();
|
|
313
|
+
}
|
|
@@ -0,0 +1,369 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The ONE renderer policy for a custom message somebody claimed with a design (S2, S3, S4).
|
|
3
|
+
*
|
|
4
|
+
* ## What Pi lets an extension do here, and what it does not
|
|
5
|
+
*
|
|
6
|
+
* `pi.registerMessageRenderer(customType, renderer)` writes into THAT extension's own map
|
|
7
|
+
* (`dist/core/extensions/loader.js:284-287`), and the runner answers `getMessageRenderer(customType)`
|
|
8
|
+
* by scanning the loaded extensions in LOAD ORDER and returning the first one that has the type
|
|
9
|
+
* (`dist/core/extensions/runner.js:534-540`). There is no `next()` chain, unlike tool renderers
|
|
10
|
+
* (`:550-553`), and no way to read or wrap another extension's renderer. So "patching
|
|
11
|
+
* `pi.registerMessageRenderer`" cannot capture anybody: every extension holds its own `pi` object
|
|
12
|
+
* with its own closure, and only a registration made THROUGH the bridge's object would pass here.
|
|
13
|
+
*
|
|
14
|
+
* What Pi does expose is the component: `CustomMessageComponent` keeps the renderer Pi resolved for
|
|
15
|
+
* that message in `customRenderer`, and calls it again on every `rebuild()`
|
|
16
|
+
* (`dist/modes/interactive/components/custom-message.js`). That is the capture point, and
|
|
17
|
+
* `./message-design-adoption.ts` is the pass that reaches it. This module is the RULE that pass
|
|
18
|
+
* installs — small enough to assert with no host at all.
|
|
19
|
+
*
|
|
20
|
+
* ## The rule: the host draws the frame, the design rewrites rows
|
|
21
|
+
*
|
|
22
|
+
* ```
|
|
23
|
+
* Pi rebuild() → our renderer → host renderer(message, options, theme) → host component
|
|
24
|
+
* → [live selection] → design.apply(host rows, ctx) → rows
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* The host's renderer runs FIRST and is the only source of the frame, so `float` stays `float` and
|
|
28
|
+
* `neon` stays `neon`: the design never sees a byte of the chrome, only the rows it can rewrite
|
|
29
|
+
* (S3). When the type has no host renderer at all, there is no frame to preserve and the design owns
|
|
30
|
+
* the box (S2): it receives no rows and draws the whole message, `ctx.render.message` in hand.
|
|
31
|
+
*
|
|
32
|
+
* ## The decision is live, the escape hatch is Pi's own
|
|
33
|
+
*
|
|
34
|
+
* Pi captures the renderer once, when the message is added, and re-invokes it on every rebuild. So
|
|
35
|
+
* the decision cannot live in the renderer alone: the component this module returns re-reads the
|
|
36
|
+
* selection on EVERY render pass, which is what lets a design chosen after the message was drawn
|
|
37
|
+
* repaint it, and what makes `default` restore the host's own rows untouched.
|
|
38
|
+
*
|
|
39
|
+
* ## The content level is the design's, not the bridge's
|
|
40
|
+
*
|
|
41
|
+
* Pi's card content level (`minimal`) clips TOOL cards, because the host's own renderer decides how
|
|
42
|
+
* much of a tool result to show, and gentle-shell's renderers offer `previewRows` for exactly that.
|
|
43
|
+
* A custom message has no host renderer, and the bridge adds no policy of its own: it never truncates,
|
|
44
|
+
* re-wraps or withholds a row a design returned, and it never reads a content level. An alert the
|
|
45
|
+
* agent must read in full can therefore print in full — that choice is the DESIGN's, and what this
|
|
46
|
+
* module owes it is the material to make it: `width`, `render.expanded`, `render.outputPad`,
|
|
47
|
+
* `render.message` and `cardStyle`.
|
|
48
|
+
*
|
|
49
|
+
* With nothing selected — `native`, a design that was disposed (`missing`), a line whose selected
|
|
50
|
+
* design never claimed this type (`not-covered`) — the answer is the host's own component, BY
|
|
51
|
+
* IDENTITY, or `undefined` when there is none, which is exactly what makes Pi draw its default box.
|
|
52
|
+
* That is S4's byte-stability: a type nobody claimed never reaches this module at all.
|
|
53
|
+
*
|
|
54
|
+
* This module is internal: `src/index.ts` does not re-export it.
|
|
55
|
+
*/
|
|
56
|
+
|
|
57
|
+
import { resolveCardStyleSelection } from "./card-styles.ts";
|
|
58
|
+
import {
|
|
59
|
+
applyMessageDesign,
|
|
60
|
+
recordMessageDesignFailure,
|
|
61
|
+
resolveMessageDesignSelection,
|
|
62
|
+
type MessageDesignSelection,
|
|
63
|
+
} from "./message-designs.ts";
|
|
64
|
+
import { isRecord } from "./rows.ts";
|
|
65
|
+
import type { CardStyleSelection, MessageDesignContext, MessageDesignRender } from "./types.ts";
|
|
66
|
+
|
|
67
|
+
/** The component Pi mounts for a message: `render` plus whatever else this module leaves alone. */
|
|
68
|
+
export interface MessageComponentLike {
|
|
69
|
+
render(width: number): readonly string[];
|
|
70
|
+
invalidate?(): void;
|
|
71
|
+
handleMouse?(event: Record<string, unknown>): Record<string, unknown> | undefined;
|
|
72
|
+
readonly wantsKeyRelease?: boolean;
|
|
73
|
+
readonly capturesViewportInput?: boolean;
|
|
74
|
+
[member: string]: unknown;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Pi's `MessageRenderer`, described structurally (`dist/core/extensions/types.d.ts:1211`): it is
|
|
79
|
+
* handed the message, `{ expanded, outputPad }` and the theme, and answers a component or
|
|
80
|
+
* `undefined`. The bridge never re-types the host's objects, it forwards them.
|
|
81
|
+
*/
|
|
82
|
+
export type HostMessageRenderer = (
|
|
83
|
+
message: unknown,
|
|
84
|
+
options: unknown,
|
|
85
|
+
theme?: unknown,
|
|
86
|
+
) => unknown;
|
|
87
|
+
|
|
88
|
+
function errorMessage(error: unknown): string {
|
|
89
|
+
return error instanceof Error ? error.message : String(error);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* A by-value snapshot of Pi's render options, plus the message BY REFERENCE (exactly like a tool
|
|
94
|
+
* design's `render.args`): Pi keeps it live, so a design reads it per pass and never caches it.
|
|
95
|
+
* Read inside Pi's render loop, so a host object whose accessors throw yields Pi's own defaults
|
|
96
|
+
* instead of a throw into the frame.
|
|
97
|
+
*/
|
|
98
|
+
function snapshotRender(message: unknown, options: unknown): MessageDesignRender {
|
|
99
|
+
let expanded = false;
|
|
100
|
+
let outputPad = 1;
|
|
101
|
+
try {
|
|
102
|
+
if (isRecord(options)) {
|
|
103
|
+
if (typeof options.expanded === "boolean") expanded = options.expanded;
|
|
104
|
+
if (typeof options.outputPad === "number" && Number.isFinite(options.outputPad)) {
|
|
105
|
+
outputPad = options.outputPad;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
} catch {
|
|
109
|
+
// A throwing accessor has no options this module can read; Pi's defaults are the answer.
|
|
110
|
+
}
|
|
111
|
+
return { expanded, outputPad, message };
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** The live selection, with a registry that refuses to answer treated as "the host's own output". */
|
|
115
|
+
function selectionFor(customType: string): MessageDesignSelection {
|
|
116
|
+
try {
|
|
117
|
+
return resolveMessageDesignSelection(customType);
|
|
118
|
+
} catch (error) {
|
|
119
|
+
recordMessageDesignFailure(customType, "(selection)", errorMessage(error));
|
|
120
|
+
return { kind: "native" };
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* The rows the host's component draws at this width, or `undefined` when it drew none: a component
|
|
126
|
+
* with no `render`, a `render` that answers something that is not a row array, or no component at
|
|
127
|
+
* all. Always `undefined`-safe, because this runs inside Pi's render loop.
|
|
128
|
+
*/
|
|
129
|
+
function hostRows(component: unknown, width: number, customType: string): string[] | undefined {
|
|
130
|
+
if (!isRecord(component) || typeof component.render !== "function") return undefined;
|
|
131
|
+
let rows: unknown;
|
|
132
|
+
try {
|
|
133
|
+
// SAFETY: `typeof` just proved `render` callable, and a component's own `render(width)` is the
|
|
134
|
+
// contract this module reads; its answer is inspected before it is trusted.
|
|
135
|
+
rows = (component.render as (width: number) => unknown).call(component, width);
|
|
136
|
+
} catch (error) {
|
|
137
|
+
// The host's own component failing is the host's failure, not the design's: it is reported and
|
|
138
|
+
// the design gets no rows, which draws the message without the frame rather than not at all.
|
|
139
|
+
recordMessageDesignFailure(customType, "(host render)", errorMessage(error));
|
|
140
|
+
return undefined;
|
|
141
|
+
}
|
|
142
|
+
if (!Array.isArray(rows) || !rows.every((row) => typeof row === "string")) return undefined;
|
|
143
|
+
// SAFETY: the element check above proves every member is a string.
|
|
144
|
+
return rows as string[];
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* The message's OWN body, plainly: its type label, a blank row and its text, which is what Pi's default
|
|
149
|
+
* box holds inside its frame. A type with no host renderer hands a design THESE rows, so the design
|
|
150
|
+
* owns the frame around a body it did not have to invent — and so a design that throws or answers
|
|
151
|
+
* something that is not rows still leaves the message readable instead of dropping it off the screen.
|
|
152
|
+
*
|
|
153
|
+
* Nothing here is styled: the bridge has no business choosing colours a design is about to frame.
|
|
154
|
+
* Content that is not a string yields the label alone, because inventing text would be worse than
|
|
155
|
+
* showing less.
|
|
156
|
+
*/
|
|
157
|
+
function plainBodyRows(message: unknown): string[] {
|
|
158
|
+
if (!isRecord(message)) return [];
|
|
159
|
+
let customType: unknown;
|
|
160
|
+
let content: unknown;
|
|
161
|
+
try {
|
|
162
|
+
customType = message.customType;
|
|
163
|
+
content = message.content;
|
|
164
|
+
} catch {
|
|
165
|
+
return [];
|
|
166
|
+
}
|
|
167
|
+
const label = typeof customType === "string" && customType !== "" ? `[${customType}]` : undefined;
|
|
168
|
+
const body = bodyLines(content);
|
|
169
|
+
if (label === undefined) return body;
|
|
170
|
+
return body.length === 0 ? [label] : [label, "", ...body];
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* The text a message's `content` holds, as rows. Pi accepts a plain string OR the parts form
|
|
175
|
+
* (`[{ type: "text", text: "…" }]`), and a body that is only ever read as a string would silently
|
|
176
|
+
* vanish for every structured message — including the alerts this surface exists for.
|
|
177
|
+
*/
|
|
178
|
+
function bodyLines(content: unknown): string[] {
|
|
179
|
+
if (typeof content === "string") return content === "" ? [] : content.split(/\r?\n/u);
|
|
180
|
+
if (!Array.isArray(content)) return [];
|
|
181
|
+
const rows: string[] = [];
|
|
182
|
+
for (let index = 0; index < content.length; index += 1) {
|
|
183
|
+
const part: unknown = content[index];
|
|
184
|
+
if (!isRecord(part)) continue;
|
|
185
|
+
let text: unknown;
|
|
186
|
+
try {
|
|
187
|
+
text = part.text;
|
|
188
|
+
} catch {
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
if (typeof text === "string" && text !== "") {
|
|
192
|
+
rows.push(...text.split(/\r?\n/u));
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return rows;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Hard-wrap rows to `width`, by code point, for the rows THIS module fabricates. Nothing is dropped:
|
|
200
|
+
* a 190-column row at width 24 becomes eight rows. Only the plain body and Pi's box take this path —
|
|
201
|
+
* a design's own rows are handed back untouched, because the bridge does not measure what a design
|
|
202
|
+
* chose to draw (L7).
|
|
203
|
+
*/
|
|
204
|
+
function wrapToWidth(rows: readonly string[], width: number): string[] {
|
|
205
|
+
if (!Number.isFinite(width) || width <= 0) return [...rows];
|
|
206
|
+
const out: string[] = [];
|
|
207
|
+
for (const row of rows) {
|
|
208
|
+
const points = Array.from(row);
|
|
209
|
+
if (points.length <= width) {
|
|
210
|
+
out.push(row);
|
|
211
|
+
continue;
|
|
212
|
+
}
|
|
213
|
+
for (let at = 0; at < points.length; at += width) out.push(points.slice(at, at + width).join(""));
|
|
214
|
+
}
|
|
215
|
+
return out;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* The component a design draws through: the host's rows in, the design's rows out, the live
|
|
220
|
+
* selection read on every pass.
|
|
221
|
+
*
|
|
222
|
+
* With no design selected it answers the host's own rows, byte for byte (S4). A design that throws
|
|
223
|
+
* or answers something that is not rows loses its own output only — the host's rows are what the
|
|
224
|
+
* user sees, and the failure is reported in the diagnostics record (S5's failure isolation).
|
|
225
|
+
*/
|
|
226
|
+
function designComponent(args: {
|
|
227
|
+
customType: string;
|
|
228
|
+
host: unknown;
|
|
229
|
+
theme: unknown;
|
|
230
|
+
render: MessageDesignRender;
|
|
231
|
+
fallbackRows?: (width: number) => string[] | undefined;
|
|
232
|
+
hooks?: {
|
|
233
|
+
isSuppressed?: (designId: string) => boolean;
|
|
234
|
+
onFailure?: (designId: string) => void;
|
|
235
|
+
};
|
|
236
|
+
}): MessageComponentLike {
|
|
237
|
+
const { customType, host, theme, render, fallbackRows, hooks } = args;
|
|
238
|
+
return {
|
|
239
|
+
render(width: number): string[] {
|
|
240
|
+
const selection = selectionFor(customType);
|
|
241
|
+
// With no host component the design owns the box, so what it — and a failing design — receives
|
|
242
|
+
// is the message's own body. With one, the host's rows are the only frame there is.
|
|
243
|
+
const plain = plainBodyRows(render.message);
|
|
244
|
+
const fromHost = host === undefined ? undefined : hostRows(host, width, customType);
|
|
245
|
+
const rows = fromHost ?? plain;
|
|
246
|
+
// `default`, a disposed design, or a design that never claimed this type: nothing is rewritten.
|
|
247
|
+
if (selection.kind !== "design") return rows;
|
|
248
|
+
// S1/S22: resolved ON ACCESS and at most ONCE per pass, so a design that never reads it pays
|
|
249
|
+
// nothing and one that reads it twice cannot draw a card that is half of each style.
|
|
250
|
+
let cardStyle: CardStyleSelection | undefined;
|
|
251
|
+
const ctx: MessageDesignContext = {
|
|
252
|
+
width,
|
|
253
|
+
customType,
|
|
254
|
+
theme,
|
|
255
|
+
render,
|
|
256
|
+
get cardStyle(): CardStyleSelection {
|
|
257
|
+
cardStyle ??= resolveCardStyleSelection();
|
|
258
|
+
return cardStyle;
|
|
259
|
+
},
|
|
260
|
+
};
|
|
261
|
+
const applied = applyMessageDesign(selection.design, rows, ctx);
|
|
262
|
+
if (applied !== undefined) return applied;
|
|
263
|
+
// One degraded frame, then Pi's own: the pass rebuilds the message under Pi's renderer, which
|
|
264
|
+
// populates the box this design never filled. Nothing is retried while the selection stands.
|
|
265
|
+
hooks?.onFailure?.(selection.design.id);
|
|
266
|
+
// The design failed: draw what the message would have drawn without it, which is the HOST's
|
|
267
|
+
// rows when there are any (the frame this design was only allowed to rewrite). Only a host-less
|
|
268
|
+
// message needs the box handed over by the adoption pass, because its `rows` are the plain body
|
|
269
|
+
// and Pi's own frame is what the user would have seen. The plain body is the last resort, so a
|
|
270
|
+
// message the agent must read is never the thing that gets dropped (S2 + L7).
|
|
271
|
+
if (host !== undefined) return rows;
|
|
272
|
+
// The rows this module fabricates are the only ones it may measure: Pi's main screen ABORTS the
|
|
273
|
+
// frame on a row wider than the terminal, and a message the agent must read cannot be the thing
|
|
274
|
+
// that crashes it. Wrapping withholds nothing; the design's own rows are never measured (L7).
|
|
275
|
+
return wrapToWidth(fallbackRows?.(width) ?? plain, width);
|
|
276
|
+
},
|
|
277
|
+
invalidate(): void {
|
|
278
|
+
if (!isRecord(host)) return;
|
|
279
|
+
const invalidate = host.invalidate;
|
|
280
|
+
if (typeof invalidate === "function") (invalidate as () => void).call(host);
|
|
281
|
+
},
|
|
282
|
+
// Everything else the host's component can do stays the host's: losing the mouse handler would
|
|
283
|
+
// make a message stop responding to clicks the moment somebody gave it a design.
|
|
284
|
+
handleMouse(event: Record<string, unknown>): Record<string, unknown> | undefined {
|
|
285
|
+
if (!isRecord(host)) return undefined;
|
|
286
|
+
const handleMouse = host.handleMouse;
|
|
287
|
+
if (typeof handleMouse === "function") {
|
|
288
|
+
return (handleMouse as (event: Record<string, unknown>) => Record<string, unknown>).call(
|
|
289
|
+
host,
|
|
290
|
+
event,
|
|
291
|
+
);
|
|
292
|
+
}
|
|
293
|
+
return undefined;
|
|
294
|
+
},
|
|
295
|
+
get wantsKeyRelease(): boolean {
|
|
296
|
+
return isRecord(host) && host.wantsKeyRelease === true;
|
|
297
|
+
},
|
|
298
|
+
get capturesViewportInput(): boolean {
|
|
299
|
+
return isRecord(host) && host.capturesViewportInput === true;
|
|
300
|
+
},
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* The renderer the bridge installs for ONE custom type, given the host's own renderer for it (or
|
|
306
|
+
* `undefined` when the host has none).
|
|
307
|
+
*
|
|
308
|
+
* It is the whole policy in one place:
|
|
309
|
+
*
|
|
310
|
+
* - the host's renderer runs first, with Pi's own arguments, and a throw from it stays the host's to
|
|
311
|
+
* report (Pi's `rebuild()` catches it and draws its default box, byte-identical to before);
|
|
312
|
+
* - with no design selected, its answer is returned as-is — the same component, or `undefined` so Pi
|
|
313
|
+
* draws its default box (S4);
|
|
314
|
+
* - with a design selected, a component is returned whose `render(width)` re-reads the selection,
|
|
315
|
+
* renders the host at THAT width and hands the rows to the design (S3), or hands it no rows at all
|
|
316
|
+
* when the type has no host renderer, so the design owns the box (S2).
|
|
317
|
+
*/
|
|
318
|
+
export function messageDesignRenderer(
|
|
319
|
+
customType: string,
|
|
320
|
+
host: HostMessageRenderer | undefined,
|
|
321
|
+
hooks?: {
|
|
322
|
+
fallbackRows?: (width: number) => string[] | undefined;
|
|
323
|
+
/**
|
|
324
|
+
* Called on EVERY build with whether a design was selected, so the adoption pass always knows
|
|
325
|
+
* what the mounted answer is. An external rebuild (`setExpanded`, `/tree`, a reload) re-enters the
|
|
326
|
+
* renderer with whatever is selected then, and a stale record would leave the message on the raw
|
|
327
|
+
* host component while the design never draws again.
|
|
328
|
+
*/
|
|
329
|
+
onBuild?: (designSelected: boolean) => void;
|
|
330
|
+
/** Whether this design already failed on this message; until the selection changes, Pi draws. */
|
|
331
|
+
isSuppressed?: (designId: string) => boolean;
|
|
332
|
+
/** A design failed on this message: ask the pass to rebuild it under Pi's own renderer. */
|
|
333
|
+
onFailure?: (designId: string) => void;
|
|
334
|
+
},
|
|
335
|
+
): HostMessageRenderer {
|
|
336
|
+
return function (message: unknown, options: unknown, theme?: unknown): unknown {
|
|
337
|
+
const selection = selectionFor(customType);
|
|
338
|
+
hooks?.onBuild?.(selection.kind === "design");
|
|
339
|
+
// The host's own renderer first, always, and exactly once per build: it owns the frame, its
|
|
340
|
+
// arguments and its failures. A host renderer that throws is REPORTED and answers `undefined`,
|
|
341
|
+
// which is exactly what Pi does with it — its own default box — so the bridge never changes what
|
|
342
|
+
// the user sees when the host's own renderer is broken.
|
|
343
|
+
let hostComponent: unknown;
|
|
344
|
+
if (host !== undefined) {
|
|
345
|
+
try {
|
|
346
|
+
hostComponent = host(message, options, theme);
|
|
347
|
+
} catch (error) {
|
|
348
|
+
recordMessageDesignFailure(customType, "(host renderer)", errorMessage(error));
|
|
349
|
+
hostComponent = undefined;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
// Nothing to draw through: the host's own answer, including `undefined` (S4).
|
|
353
|
+
if (selection.kind !== "design") return hostComponent;
|
|
354
|
+
// A design that already failed here is not retried on every frame: answering `undefined` is what
|
|
355
|
+
// lets Pi run its OWN default path, which is the only thing that populates the box a message shows
|
|
356
|
+
// and the only answer that cannot throw twice for the same reason.
|
|
357
|
+
if (hooks?.isSuppressed?.(selection.design.id) === true) return undefined;
|
|
358
|
+
return designComponent({
|
|
359
|
+
customType,
|
|
360
|
+
host: hostComponent,
|
|
361
|
+
theme,
|
|
362
|
+
render: snapshotRender(message, options),
|
|
363
|
+
...(hooks?.fallbackRows === undefined ? {} : { fallbackRows: hooks.fallbackRows }),
|
|
364
|
+
...(hooks?.isSuppressed === undefined && hooks?.onFailure === undefined
|
|
365
|
+
? {}
|
|
366
|
+
: { hooks: { isSuppressed: hooks.isSuppressed, onFailure: hooks.onFailure } }),
|
|
367
|
+
});
|
|
368
|
+
};
|
|
369
|
+
}
|