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.
- 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/lib/user-prompt-card.js +48 -2
- 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 +80 -10
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The customize rows for tool designs (S1–S8): ONE line per LINE that has designs, in `Cards`.
|
|
3
|
+
*
|
|
4
|
+
* ## One line per line, one value per design
|
|
5
|
+
*
|
|
6
|
+
* The values are the line's own card — shown as `default` (stored as `native`, the reserved
|
|
7
|
+
* identity) — followed by every design of that line, in registration order. The host coalesces
|
|
8
|
+
* consecutive rows that share a `choice.setting` into one rendered line
|
|
9
|
+
* (`lib/visual-customize-view.ts:395-402,583-595`), so all of one line's values share that line's
|
|
10
|
+
* setting and the card menus of a grouped line never split into one line per tool.
|
|
11
|
+
*
|
|
12
|
+
* ## The names: `Card <tool>` or `Card <line>`, like `Card style` and `Card content`
|
|
13
|
+
*
|
|
14
|
+
* A row name is what a human reads (`./row-names.ts`), and the `Cards` category already names its
|
|
15
|
+
* lines `Card <what>`. An UNGROUPED design keeps the implicit tool line: `Card bash`, `Card lsp
|
|
16
|
+
* navigation`, `Card mem save` (a long name keeps its TAIL, because the last words are the specific
|
|
17
|
+
* part). A GROUPED registration names its line: `Card tools`, `Card status`, derived from the line id
|
|
18
|
+
* through the same rule. Both share ONE ordinal space, so a line and a tool that derive the same name
|
|
19
|
+
* are told apart deterministically (`Card tools`, `Card tools 2`), replacing the last word so the
|
|
20
|
+
* result still passes the shape rule, exactly the way sections and card styles are told apart.
|
|
21
|
+
*
|
|
22
|
+
* The id is never shown: a design's `label` is its value, and the persisted value is the design's id,
|
|
23
|
+
* so renaming a label never loses a user's choice. The line's NAME is not persisted either — the
|
|
24
|
+
* store is keyed by the tool name (`selections`) or the line id (`lines`), so renaming the line moves
|
|
25
|
+
* nothing but the text the user reads.
|
|
26
|
+
*
|
|
27
|
+
* ## No design, no line
|
|
28
|
+
*
|
|
29
|
+
* The provider is registered when the bridge arms and its rows are rebuilt per menu build, never
|
|
30
|
+
* cached. With no design registered it contributes NOTHING: a session that never installed a design
|
|
31
|
+
* plugin must not gain an empty line. The first design to register appears on the next build with no
|
|
32
|
+
* re-registration.
|
|
33
|
+
*
|
|
34
|
+
* ## A change repaints the cards already drawn (S2/S10)
|
|
35
|
+
*
|
|
36
|
+
* The action persists FIRST (the host re-reads `current()` when it repaints) and then asks for a
|
|
37
|
+
* frame through `requestRepaint()` (`./repaint.ts`): one differential `requestRender()`, because the
|
|
38
|
+
* wrapper re-reads the live selection on every render pass, so the cards already on screen change too.
|
|
39
|
+
* A press that changes nothing costs no frame.
|
|
40
|
+
*
|
|
41
|
+
* This module is internal: `src/index.ts` does not re-export it.
|
|
42
|
+
*/
|
|
43
|
+
|
|
44
|
+
import { registerBridgeRows } from "./bus.ts";
|
|
45
|
+
import { HOST_CARD_STYLE_CATEGORY } from "./card-style-line.ts";
|
|
46
|
+
import { requestRepaint } from "./repaint.ts";
|
|
47
|
+
import { deriveRowLabel } from "./row-labels.ts";
|
|
48
|
+
import { MAX_ROW_NAME_WORDS } from "./row-names.ts";
|
|
49
|
+
import { isRecord } from "./rows.ts";
|
|
50
|
+
import {
|
|
51
|
+
TOOL_DESIGN_DEFAULT_LABEL,
|
|
52
|
+
TOOL_DESIGN_NATIVE,
|
|
53
|
+
getToolDesignLineSelection,
|
|
54
|
+
setToolDesignLineSelection,
|
|
55
|
+
toolDesignLines,
|
|
56
|
+
type ToolDesignLine,
|
|
57
|
+
} from "./tool-designs.ts";
|
|
58
|
+
import type { CustomizeRow, RowPreview, ToolDesignRegistration } from "./types.ts";
|
|
59
|
+
|
|
60
|
+
/** The rows provider's id; it is the bridge's own registration, never a plugin's. */
|
|
61
|
+
export const TOOL_DESIGN_ROWS_PROVIDER_ID = "bridge.tool-designs";
|
|
62
|
+
|
|
63
|
+
/** The word every design line starts with: the `Cards` category's own vocabulary. */
|
|
64
|
+
const TOOL_LINE_PREFIX = "Card";
|
|
65
|
+
|
|
66
|
+
/** The word a tool name that derives to nothing still reads as (`deriveRowLabel` returned ""). */
|
|
67
|
+
const TOOL_NAME_FALLBACK = "tool";
|
|
68
|
+
|
|
69
|
+
/** The word a line id that derives to nothing still reads as. */
|
|
70
|
+
const LINE_NAME_FALLBACK = "line";
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* A line source's readable words, clamped so `Card` plus them fits the row-name word limit. A long
|
|
74
|
+
* name keeps its TAIL: `mcp__engram__mem_save` reads `mem save`, because the last words are the
|
|
75
|
+
* specific part and the leading ones (`mcp`, `engram`) are the same for every tool of that server.
|
|
76
|
+
*/
|
|
77
|
+
function sourceWords(scope: "tool" | "line", source: string): string[] {
|
|
78
|
+
const derived = deriveRowLabel(source);
|
|
79
|
+
const fallback = scope === "tool" ? TOOL_NAME_FALLBACK : LINE_NAME_FALLBACK;
|
|
80
|
+
const words = derived === "" ? [fallback] : derived.split(" ").filter((word) => word !== "");
|
|
81
|
+
const budget = Math.max(1, MAX_ROW_NAME_WORDS - 1);
|
|
82
|
+
return words.length > budget ? words.slice(words.length - budget) : words;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** One line with the name the menu shows for it. */
|
|
86
|
+
export interface ToolDesignLineName {
|
|
87
|
+
scope: "tool" | "line";
|
|
88
|
+
line: string;
|
|
89
|
+
name: string;
|
|
90
|
+
tools: string[];
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* The line name of every line that has designs, in creation order: `Card <words>`, made unique the
|
|
95
|
+
* way sections are — the readable name, then the lowest free ordinal (replacing the last word when
|
|
96
|
+
* the base already uses the full word limit, so the result still passes the shape rule).
|
|
97
|
+
*/
|
|
98
|
+
export function toolDesignLineNames(): ToolDesignLineName[] {
|
|
99
|
+
const taken = new Set<string>();
|
|
100
|
+
return toolDesignLines().map((line) => {
|
|
101
|
+
const base = [TOOL_LINE_PREFIX, ...sourceWords(line.scope, line.line)].join(" ");
|
|
102
|
+
let name = base;
|
|
103
|
+
let suffix = 2;
|
|
104
|
+
while (taken.has(name)) {
|
|
105
|
+
const words = base.split(" ");
|
|
106
|
+
const kept = words.slice(0, MAX_ROW_NAME_WORDS - 1);
|
|
107
|
+
name = `${kept.join(" ")} ${suffix++}`;
|
|
108
|
+
}
|
|
109
|
+
taken.add(name);
|
|
110
|
+
return { scope: line.scope, line: line.line, name, tools: [...line.tools] };
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Persist one line's value and repaint the cards already drawn (S2/S10).
|
|
116
|
+
*
|
|
117
|
+
* Nothing at all happens when the stored value is already the one picked: a press that changes
|
|
118
|
+
* nothing must not cost a frame.
|
|
119
|
+
*/
|
|
120
|
+
function selectDesign(scope: "tool" | "line", line: string, id: string): void {
|
|
121
|
+
if (getToolDesignLineSelection(scope, line) === id) return;
|
|
122
|
+
setToolDesignLineSelection(scope, line, id);
|
|
123
|
+
requestRepaint();
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** The first row of a sample: a Cards value draws ONE row (D5), so only its first line is used. */
|
|
127
|
+
function firstSampleRow(sample: string): string {
|
|
128
|
+
return sample.split(/\r?\n/u)[0] ?? sample;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* A line's scope text, inside the SAME preview row (S13/S19): nothing to say when no claim of the
|
|
133
|
+
* line is scoped; one scope shared by every scoped claim prints today's ` — scope: <description>`
|
|
134
|
+
* byte for byte; several DISTINCT scopes print ` — scope: <tool[, tool]>: <description>` per scope,
|
|
135
|
+
* joined by `; `. Either way it joins the preview's first line, so nothing gains a second row, a
|
|
136
|
+
* value or a row kind.
|
|
137
|
+
*/
|
|
138
|
+
function withScopeText(preview: RowPreview, line: ToolDesignLine): RowPreview {
|
|
139
|
+
const groups = line.scopedClaims;
|
|
140
|
+
if (groups.length === 0) return preview;
|
|
141
|
+
const text = groups
|
|
142
|
+
.map((group) =>
|
|
143
|
+
groups.length === 1
|
|
144
|
+
? `— scope: ${group.scope.description}`
|
|
145
|
+
: `— scope: ${group.tools.join(", ")}: ${group.scope.description}`,
|
|
146
|
+
)
|
|
147
|
+
.join("; ");
|
|
148
|
+
return { title: preview.title, sample: `${firstSampleRow(preview.sample)} ${text}` };
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** What a design's fallback preview says it paints. */
|
|
152
|
+
function designTarget(tools: readonly string[]): string {
|
|
153
|
+
return tools.length === 1 ? `${tools[0]}'s own card` : `the ${tools.join(", ")} cards`;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* A design's own preview when it has one, otherwise a literal depiction of the value. A preview runs
|
|
158
|
+
* while the menu is rendered, so it must not be able to break it: a throwing (or malformed) plugin
|
|
159
|
+
* preview loses its own picture and nothing else. Whatever it returns, a Cards value draws ONE row:
|
|
160
|
+
* the sample's first line (D5).
|
|
161
|
+
*/
|
|
162
|
+
function previewFor(design: ToolDesignRegistration, tools: readonly string[]): RowPreview {
|
|
163
|
+
if (design.preview !== undefined) {
|
|
164
|
+
try {
|
|
165
|
+
const shown: unknown = design.preview();
|
|
166
|
+
if (isRecord(shown) && typeof shown.title === "string" && typeof shown.sample === "string") {
|
|
167
|
+
return { title: shown.title, sample: firstSampleRow(shown.sample) };
|
|
168
|
+
}
|
|
169
|
+
} catch {
|
|
170
|
+
// Fall through to the literal sample below.
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return {
|
|
174
|
+
title: `Cards · ${design.label}`,
|
|
175
|
+
// One row (D5), and it says what the value paints: on a grouped line a value covers a SUBSET, and
|
|
176
|
+
// the menu is the only place the user can see which (S6).
|
|
177
|
+
sample: firstSampleRow(
|
|
178
|
+
design.description ?? `${design.label}: rewrites the rows ${designTarget(tools)} produced`,
|
|
179
|
+
),
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* The host's own card, untouched. It SHOWS `default` (the word the user reads) while the stored value
|
|
185
|
+
* stays `native`: the selection is identity, so a saved choice survives the rename.
|
|
186
|
+
*/
|
|
187
|
+
function nativeRow(line: ToolDesignLine, setting: string): CustomizeRow {
|
|
188
|
+
const subject = line.tools.join(", ");
|
|
189
|
+
return {
|
|
190
|
+
category: HOST_CARD_STYLE_CATEGORY,
|
|
191
|
+
choice: {
|
|
192
|
+
setting,
|
|
193
|
+
value: TOOL_DESIGN_DEFAULT_LABEL,
|
|
194
|
+
// Identity, never the displayed text: a renamed label cannot lose the user's choice.
|
|
195
|
+
current: () => getToolDesignLineSelection(line.scope, line.line) === TOOL_DESIGN_NATIVE,
|
|
196
|
+
},
|
|
197
|
+
preview: () =>
|
|
198
|
+
withScopeText(
|
|
199
|
+
{
|
|
200
|
+
title: `Cards · ${setting}`,
|
|
201
|
+
sample: `${setting}: the host's own card for ${subject}, untouched`,
|
|
202
|
+
},
|
|
203
|
+
line,
|
|
204
|
+
),
|
|
205
|
+
action: () => selectDesign(line.scope, line.line, TOOL_DESIGN_NATIVE),
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/** One registered design of one line. The visible value is its label; the stored value is its id. */
|
|
210
|
+
function designRow(line: ToolDesignLine, setting: string, design: ToolDesignRegistration): CustomizeRow {
|
|
211
|
+
const tools = designTools(line, design);
|
|
212
|
+
return {
|
|
213
|
+
category: HOST_CARD_STYLE_CATEGORY,
|
|
214
|
+
choice: {
|
|
215
|
+
setting,
|
|
216
|
+
value: design.label,
|
|
217
|
+
current: () => getToolDesignLineSelection(line.scope, line.line) === design.id,
|
|
218
|
+
},
|
|
219
|
+
preview: () => withScopeText(previewFor(design, tools), line),
|
|
220
|
+
action: () => selectDesign(line.scope, line.line, design.id),
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* The tools one design paints, or the whole line when the registration is not found. A design object
|
|
226
|
+
* is unique per registration, so identity is the lookup key.
|
|
227
|
+
*/
|
|
228
|
+
function designTools(line: ToolDesignLine, design: ToolDesignRegistration): string[] {
|
|
229
|
+
if (design.line === undefined) return design.tool === undefined ? line.tools : [design.tool];
|
|
230
|
+
if (Array.isArray(design.tools)) return [...design.tools];
|
|
231
|
+
return line.tools;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/** The rows of one menu build: nothing without a design, one line per line that has one. */
|
|
235
|
+
function designRows(): CustomizeRow[] {
|
|
236
|
+
const lines = toolDesignLines();
|
|
237
|
+
if (lines.length === 0) return [];
|
|
238
|
+
const rows: CustomizeRow[] = [];
|
|
239
|
+
for (const named of toolDesignLineNames()) {
|
|
240
|
+
const line = lines.find(
|
|
241
|
+
(candidate) => candidate.scope === named.scope && candidate.line === named.line,
|
|
242
|
+
);
|
|
243
|
+
if (line === undefined) continue;
|
|
244
|
+
rows.push(nativeRow(line, named.name));
|
|
245
|
+
for (const design of line.designs) rows.push(designRow(line, named.name, design));
|
|
246
|
+
}
|
|
247
|
+
return rows;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
interface ToolDesignRowsState {
|
|
251
|
+
/** The live provider's disposer, while the bridge has it registered. */
|
|
252
|
+
dispose?: () => void;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/** Process-global, like every other piece of bridge state: two copies must agree. */
|
|
256
|
+
const ROWS_KEY = Symbol.for("gentle-shell-bridge.tool-designs.rows.v1");
|
|
257
|
+
|
|
258
|
+
function rowsHost(): Record<symbol, ToolDesignRowsState | undefined> {
|
|
259
|
+
// SAFETY: only `rowsState()` writes this key, and it re-checks the shape before trusting a value
|
|
260
|
+
// left by another copy or an older load.
|
|
261
|
+
return globalThis as unknown as Record<symbol, ToolDesignRowsState | undefined>;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
function rowsState(): ToolDesignRowsState {
|
|
265
|
+
const host = rowsHost();
|
|
266
|
+
const existing = host[ROWS_KEY];
|
|
267
|
+
if (existing !== undefined && (existing.dispose === undefined || typeof existing.dispose === "function")) {
|
|
268
|
+
return existing;
|
|
269
|
+
}
|
|
270
|
+
const created: ToolDesignRowsState = {};
|
|
271
|
+
host[ROWS_KEY] = created;
|
|
272
|
+
return created;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* Register the design line for this process and return a disposer that withdraws it.
|
|
277
|
+
*
|
|
278
|
+
* Call it when the bridge arms; it needs no `tui` and no capture. Installing twice is a no-op, so a
|
|
279
|
+
* second arm or a second loaded copy of this package cannot contribute the line twice.
|
|
280
|
+
*/
|
|
281
|
+
export function installToolDesignRows(): () => void {
|
|
282
|
+
const state = rowsState();
|
|
283
|
+
if (state.dispose === undefined) {
|
|
284
|
+
state.dispose = registerBridgeRows({
|
|
285
|
+
id: TOOL_DESIGN_ROWS_PROVIDER_ID,
|
|
286
|
+
category: HOST_CARD_STYLE_CATEGORY,
|
|
287
|
+
// Rebuilt per build, never cached: a design registered later shows up with no re-registration.
|
|
288
|
+
rows: () => designRows(),
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
let withdrawn = false;
|
|
292
|
+
return () => {
|
|
293
|
+
if (withdrawn) return;
|
|
294
|
+
withdrawn = true;
|
|
295
|
+
const dispose = state.dispose;
|
|
296
|
+
state.dispose = undefined;
|
|
297
|
+
dispose?.();
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/** Test-only seam; deliberately not re-exported from `src/index.ts`. */
|
|
302
|
+
export function resetToolDesignRowStateForTests(): void {
|
|
303
|
+
const state = rowsState();
|
|
304
|
+
const dispose = state.dispose;
|
|
305
|
+
state.dispose = undefined;
|
|
306
|
+
dispose?.();
|
|
307
|
+
}
|