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,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The host's own `Card style` line: where it is, how it is extended, and the ONE place its name
|
|
3
|
+
* lives (S1).
|
|
4
|
+
*
|
|
5
|
+
* gentle-shell builds the line itself (`extensions/gentle-shell.ts:3398-3419`): two rows in
|
|
6
|
+
* category `Cards` sharing `choice.setting === "Card style"`, values `neon` and `float`, each with
|
|
7
|
+
* its own `current()` reading the host's config file and its own `action()` writing it. The host
|
|
8
|
+
* coalesces consecutive rows that share a setting into one rendered line
|
|
9
|
+
* (`lib/visual-customize-view.ts:395-402,583-595`).
|
|
10
|
+
*
|
|
11
|
+
* That is the whole seam. The bridge does not add a second line, does not rename the host's, does
|
|
12
|
+
* not reimplement `neon`/`float` and never writes the host's config file: at capture it splices the
|
|
13
|
+
* host's rows out of the array, puts the SAME objects back at the same index, and appends one row
|
|
14
|
+
* per registered style sharing that setting. The host then draws one line —
|
|
15
|
+
* `Card style ● neon ○ float ○ cute` — in the position it chose.
|
|
16
|
+
*
|
|
17
|
+
* Every name this depends on is declared here once, so a renamed setting is a single place to look
|
|
18
|
+
* and a single thing to report. When it stops matching, `findCardStyleLine` finds nothing, the mode
|
|
19
|
+
* becomes `separate` and the caller contributes the bridge's own `Bridge card style` line
|
|
20
|
+
* (`./card-style-rows.ts`), which the diagnostics record reports. Nothing is guessed and nothing is
|
|
21
|
+
* silently dropped.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
import type { CustomizeRow } from "./types.ts";
|
|
25
|
+
|
|
26
|
+
/** The category that holds the host's line (`extensions/gentle-shell.ts:3398`). */
|
|
27
|
+
export const HOST_CARD_STYLE_CATEGORY = "Cards";
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The `choice.setting` the host's rows share (`extensions/gentle-shell.ts:3418`). A change here is a
|
|
31
|
+
* host change, not a bridge bug: the locator finds nothing and the fallback line takes over.
|
|
32
|
+
*/
|
|
33
|
+
export const HOST_CARD_STYLE_SETTING = "Card style";
|
|
34
|
+
|
|
35
|
+
/** The values the host's own rows carry (`lib/shell-card.ts:33-36`, rows at `:3405-3419`). */
|
|
36
|
+
export const HOST_CARD_STYLE_VALUES = ["neon", "float"] as const;
|
|
37
|
+
|
|
38
|
+
/** The bridge's own pass-through value: no repaint, the host's frame untouched. */
|
|
39
|
+
export const CARD_STYLE_NATIVE = "native";
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Ids a style may not take. `native` is the bridge's value in the separate-line mode, and `neon` /
|
|
43
|
+
* `float` are the host's own: reusing one would put the same value on the line twice, where the
|
|
44
|
+
* host's `current()` and the bridge's could both answer `true` and stepping through the values
|
|
45
|
+
* could not tell them apart.
|
|
46
|
+
*/
|
|
47
|
+
export const RESERVED_CARD_STYLE_IDS: ReadonlySet<string> = new Set([
|
|
48
|
+
CARD_STYLE_NATIVE,
|
|
49
|
+
...HOST_CARD_STYLE_VALUES,
|
|
50
|
+
]);
|
|
51
|
+
|
|
52
|
+
/** Where one run of rows sharing the host's setting sits in the captured array. */
|
|
53
|
+
export interface CardStyleLineRange {
|
|
54
|
+
start: number;
|
|
55
|
+
count: number;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Whether one row belongs to the host's line. Both the category and the setting must match: the
|
|
60
|
+
* setting alone could be shared by another category, and the category alone says nothing.
|
|
61
|
+
*/
|
|
62
|
+
function isHostStyleRow(row: unknown): boolean {
|
|
63
|
+
if (row === null || typeof row !== "object") return false;
|
|
64
|
+
const candidate = row as { category?: unknown; choice?: unknown };
|
|
65
|
+
if (candidate.category !== HOST_CARD_STYLE_CATEGORY) return false;
|
|
66
|
+
const choice = candidate.choice;
|
|
67
|
+
if (choice === null || typeof choice !== "object") return false;
|
|
68
|
+
return (choice as { setting?: unknown }).setting === HOST_CARD_STYLE_SETTING;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* The host's line: the FIRST maximal run of consecutive rows that carry the host's setting in
|
|
73
|
+
* `Cards`. Absent means "the host's shape is not what the bridge knows" — the caller reports that
|
|
74
|
+
* instead of appending a second `Card style` line somewhere else.
|
|
75
|
+
*/
|
|
76
|
+
export function findCardStyleLine(rows: readonly CustomizeRow[]): CardStyleLineRange | undefined {
|
|
77
|
+
const start = rows.findIndex((row) => isHostStyleRow(row));
|
|
78
|
+
if (start === -1) return undefined;
|
|
79
|
+
let end = start;
|
|
80
|
+
while (end + 1 < rows.length && isHostStyleRow(rows[end + 1])) end += 1;
|
|
81
|
+
return { start, count: end - start + 1 };
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Splice the registered value rows into the host's line, in place, keeping the host's own rows at
|
|
86
|
+
* their index. `adaptHostRow` may return a replacement for a host row (S13 wraps `current()`), and
|
|
87
|
+
* receives the row itself so the caller can build a shallow clone; returning the row unchanged is
|
|
88
|
+
* the identity default.
|
|
89
|
+
*
|
|
90
|
+
* Returns the range the line now covers, or `undefined` when the line could not be located OR the
|
|
91
|
+
* array refuses the edit (frozen, sealed, not extensible) — both mean "use the separate line", and
|
|
92
|
+
* neither throws into the host's menu build.
|
|
93
|
+
*/
|
|
94
|
+
export function spliceCardStyleValues(
|
|
95
|
+
rows: CustomizeRow[],
|
|
96
|
+
values: readonly CustomizeRow[],
|
|
97
|
+
adaptHostRow: (row: CustomizeRow) => CustomizeRow = (row) => row,
|
|
98
|
+
): CardStyleLineRange | undefined {
|
|
99
|
+
const range = findCardStyleLine(rows);
|
|
100
|
+
if (range === undefined) return undefined;
|
|
101
|
+
if (values.length === 0 && adaptHostRow === identityRow) return range;
|
|
102
|
+
// An array that cannot grow cannot receive our values; the host's own rows stay exactly where
|
|
103
|
+
// they are, and the caller contributes the separate line instead of half-editing this one.
|
|
104
|
+
if (!Object.isExtensible(rows) || Object.isSealed(rows) || Object.isFrozen(rows)) return undefined;
|
|
105
|
+
|
|
106
|
+
const hostRows = rows.slice(range.start, range.start + range.count).map((row) => adaptHostRow(row));
|
|
107
|
+
rows.splice(range.start, range.count, ...hostRows, ...values);
|
|
108
|
+
return { start: range.start, count: range.count + values.length };
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** The default adapter, compared by identity so a no-op call can skip the splice entirely. */
|
|
112
|
+
const identityRow = (row: CustomizeRow): CustomizeRow => row;
|
|
@@ -0,0 +1,390 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `Card style` rows (S1, S12): the host's own line, extended, with a reported fallback.
|
|
3
|
+
*
|
|
4
|
+
* Two modes, and exactly one of them is live:
|
|
5
|
+
*
|
|
6
|
+
* - **`extended`** — the host's rows were located in the captured array and spliced, so the bridge
|
|
7
|
+
* appends one row per registered style to that SAME line
|
|
8
|
+
* (`./card-style-line.ts` explains the splice). The host's own `neon`/`float` row objects are the
|
|
9
|
+
* originals, untouched: their `current()` still reads the host's config file and their `action()`
|
|
10
|
+
* still writes it. Only the registered values are the bridge's.
|
|
11
|
+
* - **`separate`** — the host's line could not be located (renamed setting, a narrower host, no
|
|
12
|
+
* capture at all). The bridge then contributes its own line, `Bridge card style`, with `native`
|
|
13
|
+
* plus every registered style. `native` means "the bridge leaves the conversation alone". The
|
|
14
|
+
* mode is recorded so the diagnostics record can say which line the user is actually seeing.
|
|
15
|
+
*
|
|
16
|
+
* ## Why the fallback is a provider and not more splicing
|
|
17
|
+
*
|
|
18
|
+
* A provider's rows are appended to the end of the array by `./rows.ts` (`buildRows`), so they can
|
|
19
|
+
* never be consecutive with the host's own `Card style` rows and can never join that line — that is
|
|
20
|
+
* exactly why the fallback uses a DIFFERENT setting name and label, and why the extended mode does
|
|
21
|
+
* not use a provider at all. The provider exists only while the separate line is what the user sees;
|
|
22
|
+
* a successful splice disposes it, so the bridge never contributes two lines.
|
|
23
|
+
*
|
|
24
|
+
* ## Many styles, one line (S12)
|
|
25
|
+
*
|
|
26
|
+
* The values are `snapshotCardStyles()` in its deterministic order (optional `order`, then
|
|
27
|
+
* registration order), nothing capped and nothing hidden. A style registered later shows up on the
|
|
28
|
+
* next menu build with no re-registration, because rows are built per build and never cached. The
|
|
29
|
+
* bridge does not control the width the host gives that line: if the host clips, that is the host's
|
|
30
|
+
* behaviour, and the diagnostics record reports the count instead of masking it.
|
|
31
|
+
*
|
|
32
|
+
* This module is internal: `src/index.ts` does not re-export it.
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
import { registerBridgeRows, snapshotCardStyles } from "./bus.ts";
|
|
36
|
+
import {
|
|
37
|
+
CARD_STYLE_NATIVE,
|
|
38
|
+
HOST_CARD_STYLE_CATEGORY,
|
|
39
|
+
HOST_CARD_STYLE_SETTING,
|
|
40
|
+
spliceCardStyleValues,
|
|
41
|
+
} from "./card-style-line.ts";
|
|
42
|
+
import {
|
|
43
|
+
getCardStyleSelection,
|
|
44
|
+
resolveCardStyleSelection,
|
|
45
|
+
setCardStyleSelection,
|
|
46
|
+
} from "./card-styles.ts";
|
|
47
|
+
import { refreshCardStyleSurfaces } from "./card-style-wiring.ts";
|
|
48
|
+
import { recordNotice } from "./notices.ts";
|
|
49
|
+
import { requestSurfaceRepaint } from "./repaint.ts";
|
|
50
|
+
import { cardStyleRowLabelText } from "./row-labels.ts";
|
|
51
|
+
import { isRecord } from "./rows.ts";
|
|
52
|
+
import type { CardStyleRegistration, CustomizeRow, RowPreview, RowProvider } from "./types.ts";
|
|
53
|
+
|
|
54
|
+
/** The fallback provider's id; it is the bridge's own registration, never a plugin's. */
|
|
55
|
+
export const CARD_STYLE_ROWS_PROVIDER_ID = "bridge.card-styles";
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* The setting of the bridge's OWN line, used only in `separate` mode. Deliberately not the host's
|
|
59
|
+
* `Card style`: a second row sharing that setting, appended somewhere else in the array, would not
|
|
60
|
+
* join the host's line and would make the diagnostics record report a duplicate.
|
|
61
|
+
*/
|
|
62
|
+
export const CARD_STYLE_FALLBACK_SETTING = "Bridge card style";
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* The fallback line's own label; it names the line, and no value repeats it.
|
|
66
|
+
*
|
|
67
|
+
* Same vocabulary as every other row name (N7): one to three plain words, no arrow, colon, dot,
|
|
68
|
+
* pipe, slash or bracket. The bridge enforces that shape on plugins (`./row-names.ts`), so its own
|
|
69
|
+
* line reads the same way — `Bridge card style`, not `Bridge → card style` or `Bridge: card style`.
|
|
70
|
+
*/
|
|
71
|
+
export const CARD_STYLE_ROW_LABEL = "Bridge card style";
|
|
72
|
+
|
|
73
|
+
/** Which line the user sees: the host's, extended, or the bridge's own. */
|
|
74
|
+
export type CardStyleRowMode = "extended" | "separate";
|
|
75
|
+
|
|
76
|
+
interface CardStyleRowState {
|
|
77
|
+
/** `separate` until a capture proves the host's line is there. */
|
|
78
|
+
mode: CardStyleRowMode;
|
|
79
|
+
/** Whether the wiring asked for the fallback line at all (it does not exist before arming). */
|
|
80
|
+
wanted: boolean;
|
|
81
|
+
/** The live fallback registration's disposer, while it is registered. */
|
|
82
|
+
disposeFallback?: () => void;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** Process-global, like the bus: a second copy of this package must see the same mode. */
|
|
86
|
+
const ROW_STATE = Symbol.for("gentle-shell-bridge.card-styles.rows.v1");
|
|
87
|
+
|
|
88
|
+
function rowHost(): Record<symbol, CardStyleRowState | undefined> {
|
|
89
|
+
// SAFETY: only `rowState()` writes this key, and it re-checks every field before trusting a value
|
|
90
|
+
// left by another copy or an older load.
|
|
91
|
+
return globalThis as unknown as Record<symbol, CardStyleRowState | undefined>;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function isRowState(value: unknown): value is CardStyleRowState {
|
|
95
|
+
if (!isRecord(value)) return false;
|
|
96
|
+
return value.mode === "extended" || value.mode === "separate";
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function rowState(): CardStyleRowState {
|
|
100
|
+
const host = rowHost();
|
|
101
|
+
const existing = host[ROW_STATE];
|
|
102
|
+
if (isRowState(existing)) {
|
|
103
|
+
if (typeof existing.wanted !== "boolean") existing.wanted = false;
|
|
104
|
+
return existing;
|
|
105
|
+
}
|
|
106
|
+
const created: CardStyleRowState = { mode: "separate", wanted: false };
|
|
107
|
+
host[ROW_STATE] = created;
|
|
108
|
+
return created;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** The line the last capture settled on. Reported by the diagnostics record (T4). */
|
|
112
|
+
export function cardStyleRowMode(): CardStyleRowMode {
|
|
113
|
+
return rowState().mode;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** Test-only seam; deliberately not re-exported from `src/index.ts`. */
|
|
117
|
+
export function resetCardStyleRowStateForTests(): void {
|
|
118
|
+
const state = rowState();
|
|
119
|
+
const dispose = state.disposeFallback;
|
|
120
|
+
state.disposeFallback = undefined;
|
|
121
|
+
state.wanted = false;
|
|
122
|
+
state.mode = "separate";
|
|
123
|
+
dispose?.();
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* A style's own preview when it has one, otherwise a literal depiction of the value.
|
|
128
|
+
*
|
|
129
|
+
* A preview runs while the menu is being rendered, so it must not be able to break it: a throwing
|
|
130
|
+
* (or malformed) plugin preview loses its own picture and nothing else (S6's discipline, applied to
|
|
131
|
+
* the row instead of the frame).
|
|
132
|
+
*/
|
|
133
|
+
function previewFor(style: CardStyleRegistration): RowPreview {
|
|
134
|
+
if (style.preview !== undefined) {
|
|
135
|
+
try {
|
|
136
|
+
const shown: unknown = style.preview();
|
|
137
|
+
if (isRecord(shown) && typeof shown.title === "string" && typeof shown.sample === "string") {
|
|
138
|
+
return { title: shown.title, sample: shown.sample };
|
|
139
|
+
}
|
|
140
|
+
} catch {
|
|
141
|
+
// Fall through to the literal sample below.
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return {
|
|
145
|
+
title: `Cards · ${style.label}`,
|
|
146
|
+
sample: `${style.label}: every card the host drew is repainted with this style's frame`,
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* One registered value.
|
|
152
|
+
*
|
|
153
|
+
* `choice.value` is the style's short `label`, not its namespaced id, because the host renders
|
|
154
|
+
* `value` and nothing else on a setting line (`lib/visual-customize-view.ts:583-595`) — the id would
|
|
155
|
+
* put `loon.cute` in front of the user. The row's own `label` is the visible text too, derived from
|
|
156
|
+
* that `label` (or the author's `rowLabel`, N1/N3): the id stays internal here as well. Identity is
|
|
157
|
+
* carried by the closures below, never by the displayed text: `current()` compares the stored
|
|
158
|
+
* selection with the style's id, and `action()` persists that id, so renaming a label cannot lose a
|
|
159
|
+
* user's choice.
|
|
160
|
+
*
|
|
161
|
+
* `current()` reads the persisted selection live (so the bullet cannot lie), `action()` persists
|
|
162
|
+
* FIRST and then repaints both card surfaces before returning (`selectStyle`, R3) rather than waiting
|
|
163
|
+
* for an unrelated frame, and `preview()` is literal.
|
|
164
|
+
*/
|
|
165
|
+
/**
|
|
166
|
+
* Select a style and repaint both surfaces (R3).
|
|
167
|
+
*
|
|
168
|
+
* Persistence happens FIRST, then the rail's transform is (re)attached if it never was, then the host
|
|
169
|
+
* is asked for a frame — all synchronously, before the action returns, and nothing at all when the
|
|
170
|
+
* stored selection is already the one picked: a press that changes nothing must not cost a frame.
|
|
171
|
+
* The conversation and the rail both paint chrome from this value, so both are repainted.
|
|
172
|
+
*/
|
|
173
|
+
function selectStyle(id: string): void {
|
|
174
|
+
if (getCardStyleSelection() === id) return;
|
|
175
|
+
setCardStyleSelection(id);
|
|
176
|
+
refreshCardStyleSurfaces();
|
|
177
|
+
requestSurfaceRepaint({ cause: `card style → ${id}`, surfaces: ["conversation", "rail"] });
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function styleRow(style: CardStyleRegistration, setting: string): CustomizeRow {
|
|
181
|
+
return {
|
|
182
|
+
category: HOST_CARD_STYLE_CATEGORY,
|
|
183
|
+
label: () => cardStyleRowLabelText(style),
|
|
184
|
+
choice: {
|
|
185
|
+
setting,
|
|
186
|
+
value: style.label,
|
|
187
|
+
// Move, then Enter (A1): a repaint of both surfaces on every ←/→ would change the card the
|
|
188
|
+
// user is looking at while they are only walking the values (`visual-customize-view.ts:565`).
|
|
189
|
+
applyOnMove: false,
|
|
190
|
+
current: () => getCardStyleSelection() === style.id,
|
|
191
|
+
},
|
|
192
|
+
preview: () => previewFor(style),
|
|
193
|
+
action: () => selectStyle(style.id),
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/** The `native` value: no repaint at all. Only the separate line has one (see the module comment). */
|
|
198
|
+
function nativeRow(setting: string): CustomizeRow {
|
|
199
|
+
return {
|
|
200
|
+
category: HOST_CARD_STYLE_CATEGORY,
|
|
201
|
+
label: () => CARD_STYLE_ROW_LABEL,
|
|
202
|
+
choice: {
|
|
203
|
+
setting,
|
|
204
|
+
value: CARD_STYLE_NATIVE,
|
|
205
|
+
// Same rule as every other value the bridge contributes (A1): the way back to the host's own
|
|
206
|
+
// cards is confirmed with Enter too, never applied by passing over it.
|
|
207
|
+
applyOnMove: false,
|
|
208
|
+
current: () => getCardStyleSelection() === CARD_STYLE_NATIVE,
|
|
209
|
+
},
|
|
210
|
+
preview: () => ({
|
|
211
|
+
title: "Cards · native",
|
|
212
|
+
sample: "native: the bridge does not touch the conversation",
|
|
213
|
+
}),
|
|
214
|
+
action: () => selectStyle(CARD_STYLE_NATIVE),
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Own property on a host row we already wrapped → the host row itself, so a second splice of the
|
|
220
|
+
* same array cannot wrap our wrapper (which would delegate through two layers for no reason).
|
|
221
|
+
*/
|
|
222
|
+
const NATIVE_ROW_WRAPPED = Symbol.for("gentle-shell-bridge.card-style-rows.wrapped.v1");
|
|
223
|
+
|
|
224
|
+
/** True while the stored selection names a style that is actually registered (S13). */
|
|
225
|
+
function bridgeStyleActive(): boolean {
|
|
226
|
+
// A `missing` selection (a style that was disposed while selected) is NOT active: the host's own
|
|
227
|
+
// values must speak again, because `native` behaviour is the documented degrade (S12).
|
|
228
|
+
return resolveCardStyleSelection().kind === "style";
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* The host's own row, wrapped so exactly one value can be current (S13).
|
|
233
|
+
*
|
|
234
|
+
* The host normalizes an unknown stored style to `float`, so when a bridge style is selected the
|
|
235
|
+
* host's `float` row claims current too and the line shows two bullets. This wrapper overrides
|
|
236
|
+
* `choice.current` — `false` while a registered style is the selection, otherwise the host's own
|
|
237
|
+
* answer, delegated unchanged — and `action`, which is where the way back lives: pressing a host
|
|
238
|
+
* value means "the host renders, the bridge does not", so the host's own action runs and the bridge
|
|
239
|
+
* selection is cleared to `native`. Everything else — `choice.value`, `choice.setting`,
|
|
240
|
+
* `choice.hint`, `choice.applyOnMove`, `label`, `preview`, whatever else the host put there — is
|
|
241
|
+
* carried over as the same reference, so the host's persistence keeps running and the bridge does
|
|
242
|
+
* not reimplement `neon`/`float`. That includes `choice.applyOnMove` (A3): the host's own values keep
|
|
243
|
+
* applying on ←/→ if the host wrote them that way, while the bridge value spliced beside them waits
|
|
244
|
+
* for Enter — inside one rendered line each row's own field governs its own behaviour.
|
|
245
|
+
*/
|
|
246
|
+
function wrapHostRow(row: CustomizeRow): CustomizeRow {
|
|
247
|
+
if (Object.hasOwn(row, NATIVE_ROW_WRAPPED)) return row;
|
|
248
|
+
const choice = row.choice;
|
|
249
|
+
if (choice === undefined || typeof choice.current !== "function") return row;
|
|
250
|
+
|
|
251
|
+
const originalCurrent = choice.current;
|
|
252
|
+
const originalAction = row.action;
|
|
253
|
+
const value = typeof choice.value === "string" ? choice.value : "(unknown)";
|
|
254
|
+
|
|
255
|
+
const wrapper: CustomizeRow = {
|
|
256
|
+
...row,
|
|
257
|
+
choice: {
|
|
258
|
+
...choice,
|
|
259
|
+
current: () => (bridgeStyleActive() ? false : originalCurrent.call(choice)),
|
|
260
|
+
},
|
|
261
|
+
// Pressing a host value is how a user leaves a bridge style: the host's own setter runs (so the
|
|
262
|
+
// host's config and its repaint behave exactly as before), and the bridge selection returns to
|
|
263
|
+
// `native` in `finally`, so a throwing setter cannot trap the session inside a style (S13).
|
|
264
|
+
action: (inline) => {
|
|
265
|
+
let result: unknown;
|
|
266
|
+
try {
|
|
267
|
+
result = typeof originalAction === "function" ? originalAction.call(row, inline) : undefined;
|
|
268
|
+
} catch (error) {
|
|
269
|
+
recordActionFailure(value, error);
|
|
270
|
+
result = undefined;
|
|
271
|
+
} finally {
|
|
272
|
+
selectStyle(CARD_STYLE_NATIVE);
|
|
273
|
+
}
|
|
274
|
+
if (!isThenable(result)) return undefined;
|
|
275
|
+
// An async setter's rejection arrives after the call returns; the selection is already native,
|
|
276
|
+
// and the failure is recorded instead of escaping into the menu (which must keep working).
|
|
277
|
+
return Promise.resolve(result).then(
|
|
278
|
+
() => undefined,
|
|
279
|
+
(error: unknown) => recordActionFailure(value, error),
|
|
280
|
+
);
|
|
281
|
+
},
|
|
282
|
+
};
|
|
283
|
+
Object.defineProperty(wrapper, NATIVE_ROW_WRAPPED, {
|
|
284
|
+
value: row,
|
|
285
|
+
enumerable: false,
|
|
286
|
+
configurable: true,
|
|
287
|
+
});
|
|
288
|
+
return wrapper;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/** Record a host setter that threw, through the bridge's reporting channel (S13). */
|
|
292
|
+
function recordActionFailure(value: string, error: unknown): void {
|
|
293
|
+
recordNotice(
|
|
294
|
+
`gentle-shell-bridge: the host's Card style action for ${JSON.stringify(value)} threw: ` +
|
|
295
|
+
`${error instanceof Error ? error.message : String(error)}. The bridge returned to native ` +
|
|
296
|
+
"rendering so a broken setter cannot trap the session inside a bridge style.",
|
|
297
|
+
"warning",
|
|
298
|
+
);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
function isThenable(value: unknown): value is PromiseLike<unknown> {
|
|
302
|
+
return (
|
|
303
|
+
value !== null &&
|
|
304
|
+
(typeof value === "object" || typeof value === "function") &&
|
|
305
|
+
typeof (value as { then?: unknown }).then === "function"
|
|
306
|
+
);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* The fallback provider. Its rows are rebuilt per menu build, never cached.
|
|
311
|
+
*
|
|
312
|
+
* With no style registered it contributes NOTHING: a session that never installed a style plugin
|
|
313
|
+
* must not gain a `Bridge card style` line with a single `native` value on it. The provider is
|
|
314
|
+
* still registered (arming precedes the plugins' own `session_start` handlers), so the first style
|
|
315
|
+
* to register appears on the next menu build with no re-registration.
|
|
316
|
+
*/
|
|
317
|
+
function fallbackProvider(): RowProvider {
|
|
318
|
+
return {
|
|
319
|
+
id: CARD_STYLE_ROWS_PROVIDER_ID,
|
|
320
|
+
category: HOST_CARD_STYLE_CATEGORY,
|
|
321
|
+
rows: () => {
|
|
322
|
+
const registered = snapshotCardStyles();
|
|
323
|
+
if (registered.length === 0) return [];
|
|
324
|
+
return [
|
|
325
|
+
nativeRow(CARD_STYLE_FALLBACK_SETTING),
|
|
326
|
+
...registered.map((style) => styleRow(style, CARD_STYLE_FALLBACK_SETTING)),
|
|
327
|
+
];
|
|
328
|
+
},
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
function disposeFallback(state: CardStyleRowState): void {
|
|
333
|
+
const dispose = state.disposeFallback;
|
|
334
|
+
state.disposeFallback = undefined;
|
|
335
|
+
dispose?.();
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
/** Make the registered providers match the mode: one line, never two. */
|
|
339
|
+
function sync(state: CardStyleRowState): void {
|
|
340
|
+
if (state.wanted && state.mode === "separate") {
|
|
341
|
+
if (state.disposeFallback === undefined) state.disposeFallback = registerBridgeRows(fallbackProvider());
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
disposeFallback(state);
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
/**
|
|
348
|
+
* Register the fallback line for this process and return a disposer that withdraws it.
|
|
349
|
+
*
|
|
350
|
+
* Call it when the bridge arms; it needs no `tui` and no capture. Registering twice is a no-op (the
|
|
351
|
+
* bus replaces a provider with the same id in place), and while the host's own line is reachable the
|
|
352
|
+
* provider stays unregistered — the splice already carries the values.
|
|
353
|
+
*/
|
|
354
|
+
export function installCardStyleRows(): () => void {
|
|
355
|
+
const state = rowState();
|
|
356
|
+
state.wanted = true;
|
|
357
|
+
sync(state);
|
|
358
|
+
let disposed = false;
|
|
359
|
+
return () => {
|
|
360
|
+
if (disposed) return;
|
|
361
|
+
disposed = true;
|
|
362
|
+
state.wanted = false;
|
|
363
|
+
disposeFallback(state);
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* Splice the registered values into the host's own `Card style` line, in place, and settle which
|
|
369
|
+
* line the user gets (S1).
|
|
370
|
+
*
|
|
371
|
+
* Called once per captured menu build, with the host's live rows array. It never throws: anything
|
|
372
|
+
* that makes the line unreachable — no rows, a renamed setting, an array that refuses the edit —
|
|
373
|
+
* records `separate` and lets the caller contribute the bridge's own line, which is reported rather
|
|
374
|
+
* than silent.
|
|
375
|
+
*/
|
|
376
|
+
export function extendCardStyleLine(rows: CustomizeRow[]): CardStyleRowMode {
|
|
377
|
+
const state = rowState();
|
|
378
|
+
const registered = snapshotCardStyles();
|
|
379
|
+
const values = registered.map((style) => styleRow(style, HOST_CARD_STYLE_SETTING));
|
|
380
|
+
// With no style registered nothing can ever be selected, so the host's rows need no wrapper and
|
|
381
|
+
// the array is not touched at all.
|
|
382
|
+
const range = spliceCardStyleValues(
|
|
383
|
+
rows,
|
|
384
|
+
values,
|
|
385
|
+
registered.length > 0 ? wrapHostRow : undefined,
|
|
386
|
+
);
|
|
387
|
+
state.mode = range === undefined ? "separate" : "extended";
|
|
388
|
+
sync(state);
|
|
389
|
+
return state.mode;
|
|
390
|
+
}
|