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,803 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The public row/provider contract, mirroring `docs/contract.md` §2–§3.
|
|
3
|
+
*
|
|
4
|
+
* The bridge carries rows through unchanged: it never reads, rewrites or interprets a row, so
|
|
5
|
+
* every field here is a pass-through of what gentle-shell's renderer already understands
|
|
6
|
+
* (`lib/visual-customize-view.ts:107-140`).
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Context handed to a provider's `rows(ctx)` once per menu build.
|
|
11
|
+
*
|
|
12
|
+
* `theme` is the host's opaque theme object, passed through untouched; the bridge does not
|
|
13
|
+
* depend on its shape, so consumers narrow it themselves. `configHome` is the resolved
|
|
14
|
+
* gentle-shell config home (see `./config.ts`), so a plugin can place per-user state without
|
|
15
|
+
* re-deriving the path.
|
|
16
|
+
*/
|
|
17
|
+
export interface RowContext {
|
|
18
|
+
readonly theme: unknown;
|
|
19
|
+
readonly configHome: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Row text; a function is evaluated when the menu is built. */
|
|
23
|
+
export type RowLabel = string | (() => string);
|
|
24
|
+
|
|
25
|
+
/** One value of a setting. Consecutive rows sharing `setting` share one rendered line. */
|
|
26
|
+
export interface RowChoice {
|
|
27
|
+
setting: string;
|
|
28
|
+
value: string;
|
|
29
|
+
current(): boolean;
|
|
30
|
+
hint?: string;
|
|
31
|
+
/** `false` makes Enter apply the choice instead of applying on ←/→. */
|
|
32
|
+
applyOnMove?: boolean;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Read-only depiction of the highlighted choice; never an application. */
|
|
36
|
+
export interface RowPreview {
|
|
37
|
+
title: string;
|
|
38
|
+
sample: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Inline helpers available to `action`, so a row never opens a nested native dialog.
|
|
43
|
+
* Shapes mirror `lib/visual-customize-view.ts:129-140`.
|
|
44
|
+
*/
|
|
45
|
+
export interface InlineHelpers {
|
|
46
|
+
input(options: { prompt: string; value?: string }): Promise<string | undefined>;
|
|
47
|
+
confirm(message: string): Promise<boolean>;
|
|
48
|
+
capture(prompt: string): Promise<string | undefined>;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* A settings row as gentle-shell's renderer understands it. There are exactly two kinds (S16), and
|
|
53
|
+
* both are first class — neither is an accident of a missing field:
|
|
54
|
+
*
|
|
55
|
+
* - a TOGGLE row carries a `choice`. Consecutive rows sharing `choice.setting` render as one line and
|
|
56
|
+
* ←/→ moves the cursor; the bridge stages every such row with `applyOnMove: false` so Enter applies;
|
|
57
|
+
* - a BUTTON row carries an `action` and NO `choice`. Enter (or Space) runs it — exactly the shape of
|
|
58
|
+
* the host's own `Reset` and `Profiles` rows (`extensions/gentle-shell.ts:3541,3550`, run at
|
|
59
|
+
* `lib/visual-customize-view.ts:575-577`). Its whole visible text is its `label`.
|
|
60
|
+
*
|
|
61
|
+
* `category` names the page. The host derives its pages from the rows it holds, but a page it owns
|
|
62
|
+
* differently is not open to plugins: `Keymaps` is REFUSED (S15) — the whole registration when that
|
|
63
|
+
* is the provider's own category, and the single row when the row names it, so its siblings still
|
|
64
|
+
* render. Every other value is an ordinary category.
|
|
65
|
+
*
|
|
66
|
+
* `label` — and a button's label above all, because it is the row's entire visible text — is a row
|
|
67
|
+
* name: one to three plain words with no arrow, colon, dot, pipe, slash or bracket (`./row-names.ts`).
|
|
68
|
+
* A label that breaks the shape is refused and reported verbatim, never rewritten.
|
|
69
|
+
*
|
|
70
|
+
* The bridge adds nothing to a button row: no `choice` is invented and no `applyOnMove` is staged
|
|
71
|
+
* (`./rows.ts`). Its one deliberate change is the `action`, which it wraps so a throw or a rejected
|
|
72
|
+
* promise is reported once through the bridge's notice channel and never reaches the menu.
|
|
73
|
+
*/
|
|
74
|
+
export interface CustomizeRow {
|
|
75
|
+
/**
|
|
76
|
+
* Optional here: a provider whose rows all belong to its own `provider.category` may omit it,
|
|
77
|
+
* and the capture backend fills it from there (shallow-cloning the row, never mutating it).
|
|
78
|
+
* The host's renderer still requires a category on every row it receives.
|
|
79
|
+
*
|
|
80
|
+
* `Keymaps` is the one reserved value (S15): the row is refused and reported instead of appearing
|
|
81
|
+
* on the host's key-capture page.
|
|
82
|
+
*/
|
|
83
|
+
category?: string;
|
|
84
|
+
label?: RowLabel;
|
|
85
|
+
choice?: RowChoice;
|
|
86
|
+
preview?: () => RowPreview;
|
|
87
|
+
/** Hidden when false; a throw fails closed (row hidden). */
|
|
88
|
+
visible?: () => boolean;
|
|
89
|
+
keyhint?: string;
|
|
90
|
+
/**
|
|
91
|
+
* Runs on Enter/Space. The host requires it on every row (`lib/visual-customize-view.ts:124`); on a
|
|
92
|
+
* button row (no `choice`) it is what makes the row do anything at all.
|
|
93
|
+
*
|
|
94
|
+
* The bridge hands the host a wrapped copy and never the raw function: a synchronous throw or a
|
|
95
|
+
* rejected promise is caught, reported once in the diagnostics record (and by the next `ui.notify`), and
|
|
96
|
+
* swallowed, so neither the menu nor the other rows can be broken by one failing action. The
|
|
97
|
+
* provider's own object is not mutated.
|
|
98
|
+
*/
|
|
99
|
+
action?: (inline: InlineHelpers) => void | Promise<void>;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Context handed to a section's `lines(ctx)` and `meta(ctx)` on every frame.
|
|
104
|
+
*
|
|
105
|
+
* The same shape as `RowContext` — the host's theme, passed through untouched, and the resolved
|
|
106
|
+
* gentle-shell config home — so a plugin that already builds rows uses one context type for both
|
|
107
|
+
* surfaces and never re-derives the path. Aliased rather than duplicated: two identical interfaces
|
|
108
|
+
* would drift.
|
|
109
|
+
*/
|
|
110
|
+
export type SectionContext = RowContext;
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* The semantic roles a section row may paint with (N10). They are the host's own theme roles —
|
|
114
|
+
* `lib/shell-bar.ts:98-101` paints `fg(role, text)` for exactly these names, and
|
|
115
|
+
* `lib/shell-sidebar-layout.ts:123-124` signatures a theme with nine of them — so a row says what it
|
|
116
|
+
* MEANS (`error`, `success`, `muted`) and the theme decides the colour. A raw colour, an SGR code or
|
|
117
|
+
* any other word is rejected when the row is built, never coerced: a row the theme cannot paint
|
|
118
|
+
* would otherwise reach the terminal as plain text the author believed was styled.
|
|
119
|
+
*/
|
|
120
|
+
export type Tone = "text" | "muted" | "dim" | "accent" | "success" | "error" | "warning";
|
|
121
|
+
|
|
122
|
+
/** The roles a `Tone` may name, for validation and for the docs. */
|
|
123
|
+
export const TONES: readonly Tone[] = [
|
|
124
|
+
"text",
|
|
125
|
+
"muted",
|
|
126
|
+
"dim",
|
|
127
|
+
"accent",
|
|
128
|
+
"success",
|
|
129
|
+
"error",
|
|
130
|
+
"warning",
|
|
131
|
+
];
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* One body row of a section (N10): what the host's own `AGENTS` rows carry, and nothing more.
|
|
135
|
+
*
|
|
136
|
+
* `label` is the row's text; `meta` is the right-aligned secondary column (tokens, elapsed time, a
|
|
137
|
+
* value — the field that updates live, N14); `glyph` is a one-character mark before the label;
|
|
138
|
+
* `tone` names a semantic role; `onClick` is what makes the row CLICKABLE (N12). A row without
|
|
139
|
+
* `onClick` is inert: it never highlights under the pointer and never answers a click.
|
|
140
|
+
*/
|
|
141
|
+
export interface SectionRow {
|
|
142
|
+
label: string;
|
|
143
|
+
meta?: string;
|
|
144
|
+
glyph?: string;
|
|
145
|
+
tone?: Tone;
|
|
146
|
+
onClick?: () => void;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* One body row: a plain string (kept byte-identical, so no existing plugin changes appearance) or a
|
|
151
|
+
* structured row.
|
|
152
|
+
*/
|
|
153
|
+
export type SectionLine = string | SectionRow;
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* The rail parts the host actually paints, in paint order (`lib/shell-sidebar-layout.ts:344`, host
|
|
157
|
+
* checkout `e4f8a4b29`): `todo`, `jobs`, `agents`, `footer`. A part outside this list never renders,
|
|
158
|
+
* so contributing to it would be invisible; a part that is absent, or whose render is empty, is not
|
|
159
|
+
* painted either.
|
|
160
|
+
*/
|
|
161
|
+
export const RAIL_PARTS = ["todo", "jobs", "agents", "footer"] as const;
|
|
162
|
+
|
|
163
|
+
/** One painted rail part. `footer` is the host's last part, which is why `"end"` is `after footer`. */
|
|
164
|
+
export type RailPart = (typeof RAIL_PARTS)[number];
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Where a section asks to sit (S1). Absent means `"end"`, the historical behaviour: after every
|
|
168
|
+
* native part. It is registration data, like `order` — never persisted, never a setting, and it
|
|
169
|
+
* names a PLACEMENT in the rail, never a rail key the plugin writes.
|
|
170
|
+
*/
|
|
171
|
+
export type SectionPlacement = "start" | "end" | { after: string };
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* A plugin's sidebar section: the analogue of `RowProvider` for the rail, mirroring the sidebar
|
|
175
|
+
* spec's S2. The plugin writes content only — it never names a `setting`, a rail key or a card
|
|
176
|
+
* frame; the bridge frames the section, draws the host's header and contributes the section's
|
|
177
|
+
* visibility and collapse controls.
|
|
178
|
+
*/
|
|
179
|
+
export interface SidebarSection {
|
|
180
|
+
/** Unique and stable: the key for ordering, replacement and the persisted visibility toggle. */
|
|
181
|
+
id: string;
|
|
182
|
+
/** The section heading, drawn like the host's own `AGENTS`/`CHANGES`/`STATS` titles. */
|
|
183
|
+
title: string;
|
|
184
|
+
/** Optional display name for the plugin's INTEGRATIONS line; see `RowProvider.name`. */
|
|
185
|
+
name?: string;
|
|
186
|
+
/**
|
|
187
|
+
* What the `Sections` rows read, e.g. `"music"`. Optional: when absent the bridge derives it from
|
|
188
|
+
* `title` (lowercase words, no dots, no prefix), and two sections whose labels read the same are
|
|
189
|
+
* disambiguated deterministically and reported by the diagnostics record. The `id` is never shown.
|
|
190
|
+
*/
|
|
191
|
+
rowLabel?: string;
|
|
192
|
+
/** Optional right-aligned text, the analogue of `idle` / `clean` / `3`. */
|
|
193
|
+
meta?(ctx: SectionContext): string | undefined;
|
|
194
|
+
/**
|
|
195
|
+
* The body, evaluated per frame, so live state is honest without a redraw API. A throw drops
|
|
196
|
+
* this section's body, and only this section's. A row is a plain string or a `SectionRow`
|
|
197
|
+
* (N10), and a structured row's `meta` — like the body itself — is read at render time, so a
|
|
198
|
+
* plugin that changes it is repainted without re-registering (N14). A collapsed section is not
|
|
199
|
+
* built at all (N13).
|
|
200
|
+
*/
|
|
201
|
+
lines(ctx: SectionContext): SectionLine[];
|
|
202
|
+
/** Visible unless the user (or the plugin) says otherwise; defaults to `true`. */
|
|
203
|
+
defaultVisible?: boolean;
|
|
204
|
+
/**
|
|
205
|
+
* Optional integer, read INSIDE one placement slot: sections with an `order` render first,
|
|
206
|
+
* ascending; sections without one follow. Ties (equal `order`, or both missing) are broken by
|
|
207
|
+
* `id` — never by load order, so the same registrations in any order draw the same rail (S2).
|
|
208
|
+
*/
|
|
209
|
+
order?: number;
|
|
210
|
+
/**
|
|
211
|
+
* Where the card sits in the rail (S1). Absent means `"end"`: after every native part, exactly as
|
|
212
|
+
* before this field existed. `"start"` sits before the first painted native part; `{ after: id }`
|
|
213
|
+
* sits right after that section, or after one of the native parts `todo`, `jobs`, `agents`,
|
|
214
|
+
* `footer`. An anchor that cannot be honoured (unknown, a cycle, a native part the host does not
|
|
215
|
+
* paint) falls back deterministically, and the diagnostics record reports where the card really went and
|
|
216
|
+
* why. A malformed value is reported the way a rejected `rowLabel` is, and the card is placed at
|
|
217
|
+
* the end instead of vanishing.
|
|
218
|
+
*/
|
|
219
|
+
placement?: SectionPlacement;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Where a provider asks its block of rows to sit inside its category (S1). Absent means `"end"`,
|
|
224
|
+
* the historical behaviour: after the host's own rows of that category. It is registration data,
|
|
225
|
+
* like `order` — never persisted, never a setting, and it names a PLACEMENT in the menu, never a
|
|
226
|
+
* category or a setting the plugin writes.
|
|
227
|
+
*/
|
|
228
|
+
export type RowPlacement = "start" | "end" | { after: string };
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Where the PAGE a provider's block opens sits among the menu's pages (S21). Only a block whose
|
|
232
|
+
* `category` is a page the host does not already list opens one; a block that joins an existing
|
|
233
|
+
* page is ordered by `placement` instead, inside that page.
|
|
234
|
+
*/
|
|
235
|
+
export type CategoryPlacement = "end" | { after: string };
|
|
236
|
+
|
|
237
|
+
/** A plugin's contribution: rows for one category, built lazily per menu build. */
|
|
238
|
+
export interface RowProvider {
|
|
239
|
+
/** Unique and stable, e.g. `"loon.banner-source"`; the key for ordering and replacement. */
|
|
240
|
+
id: string;
|
|
241
|
+
/**
|
|
242
|
+
* The category this provider adds rows to. `Keymaps` is reserved (S15): a registration naming it is
|
|
243
|
+
* refused with an error that says why, before anything is stored, and the refusal is reported in
|
|
244
|
+
* the plugin's INTEGRATIONS line. Place the rows in one of the host's setting categories instead.
|
|
245
|
+
*/
|
|
246
|
+
category: string;
|
|
247
|
+
/**
|
|
248
|
+
* Optional display name for this plugin's INTEGRATIONS line, e.g. `"Loon kit"`. Honoured on the
|
|
249
|
+
* plugin's FIRST registration only; later ones are ignored. It overrides the name derived from the
|
|
250
|
+
* owning package, must obey the row-name shape (one to three plain words, no structural marks) and
|
|
251
|
+
* is never rewritten: a rejected name produces no line at all. A single-file extension with no
|
|
252
|
+
* `package.json` above it is otherwise unattributable and gets no line — naming it here is how it
|
|
253
|
+
* gets one.
|
|
254
|
+
*/
|
|
255
|
+
name?: string;
|
|
256
|
+
/** Evaluated each time the menu is built, never at registration. */
|
|
257
|
+
rows(ctx: RowContext): CustomizeRow[];
|
|
258
|
+
/**
|
|
259
|
+
* Optional finite number, read INSIDE one placement slot: providers with a finite `order` draw
|
|
260
|
+
* first, ascending; providers without one follow. Every tie (equal `order`, or both missing) is
|
|
261
|
+
* broken by `id` — never by load order, so the same registrations in any order draw the same menu
|
|
262
|
+
* (S2).
|
|
263
|
+
*/
|
|
264
|
+
order?: number;
|
|
265
|
+
/**
|
|
266
|
+
* Where this provider's block sits in its category (S1). Absent means `"end"`: after the host's
|
|
267
|
+
* own rows of that category, exactly as before this field existed. `"start"` sits before the
|
|
268
|
+
* category's first row; `{ after: id }` sits right after another row provider's block, where
|
|
269
|
+
* `id` is a PROVIDER id — a host row's label is not an anchor. An anchor that cannot be honoured
|
|
270
|
+
* (unknown, in another category, a cycle, or a category the host did not build) falls back
|
|
271
|
+
* deterministically, and the diagnostics record reports where the block really went and why. A
|
|
272
|
+
* malformed value is reported the way a rejected section `placement` is, and the block is placed
|
|
273
|
+
* at the end instead of vanishing.
|
|
274
|
+
*/
|
|
275
|
+
placement?: RowPlacement;
|
|
276
|
+
/**
|
|
277
|
+
* Where the PAGE this block opens sits among the menu's pages (S21). Absent means `"end"`, exactly
|
|
278
|
+
* as before this field existed. `{ after: name }` sits right after that category's block, so
|
|
279
|
+
* `{ after: "Sections" }` opens the page between `Sections` and the page that follows it. A name
|
|
280
|
+
* that cannot be honoured — unknown, the provider's own category, or a page this build does not
|
|
281
|
+
* produce — falls back to the end deterministically, and the diagnostics record reports the landing and
|
|
282
|
+
* why. It is honoured while the menu is being built: a page list the host already derived cannot
|
|
283
|
+
* be resequenced afterwards.
|
|
284
|
+
*/
|
|
285
|
+
categoryPlacement?: CategoryPlacement;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* What a card style's `top` receives: the measured width, plus the pieces of the host's own frame
|
|
290
|
+
* the bridge extracted once, in one place (S2). A style must never try to parse them back out of a
|
|
291
|
+
* line.
|
|
292
|
+
*/
|
|
293
|
+
export interface CardFrameTopContext {
|
|
294
|
+
readonly width: number;
|
|
295
|
+
/** The card's title as the host printed it, without the glyph; absent when it could not be found. */
|
|
296
|
+
readonly title?: string;
|
|
297
|
+
/** The right-aligned hint as the host printed it, e.g. `ctrl+o`; absent when the card had none. */
|
|
298
|
+
readonly hint?: string;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/** What a card style's `line` receives: one body row of the host's card. */
|
|
302
|
+
export interface CardFrameLineContext {
|
|
303
|
+
readonly text: string;
|
|
304
|
+
readonly width: number;
|
|
305
|
+
/** `true` for the first body row of the card, `false` for every continuation row. */
|
|
306
|
+
readonly first: boolean;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/** What a card style's `bottom` receives. */
|
|
310
|
+
export interface CardFrameBottomContext {
|
|
311
|
+
readonly width: number;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* The three functions a style draws with, and the whole of what the bridge calls (S2). The bridge
|
|
316
|
+
* supplies the width and the text; it never asks the style where anything is.
|
|
317
|
+
*/
|
|
318
|
+
export interface CardFrame {
|
|
319
|
+
top(ctx: CardFrameTopContext): string;
|
|
320
|
+
line(ctx: CardFrameLineContext): string;
|
|
321
|
+
bottom(ctx: CardFrameBottomContext): string;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* What a transform reports about its own frame (F1): how many candidate cards it examined, how many
|
|
326
|
+
* it recognised, how many it rewrote, and — when its grammar has several shapes — which shape
|
|
327
|
+
* matched, by the transform's own name for it.
|
|
328
|
+
*
|
|
329
|
+
* COUNTS ONLY. A frame carries the user's private output, so nothing of it may be stored or shown:
|
|
330
|
+
* no line, no text, no plugin output. A shape name is therefore a NAME and nothing else — lowercase
|
|
331
|
+
* letters, digits, `_`, `.` or `-`, at most 24 characters — and anything else is dropped rather than
|
|
332
|
+
* recorded (`src/transform-pipeline.ts` sanitises every value before it is stored).
|
|
333
|
+
*/
|
|
334
|
+
export interface TransformCounts {
|
|
335
|
+
/** Rows the transform examined as a possible card head. */
|
|
336
|
+
candidates: number;
|
|
337
|
+
/** Candidates its grammar accepted. */
|
|
338
|
+
recognised: number;
|
|
339
|
+
/** Cards it actually rewrote this frame; `0` when its setting leaves them alone. */
|
|
340
|
+
rewritten: number;
|
|
341
|
+
/** Which shape matched, by name, and how many times. Absent when the grammar has one shape. */
|
|
342
|
+
shapes?: Readonly<Record<string, number>>;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* Which host child produced one drawn row (S1).
|
|
347
|
+
*
|
|
348
|
+
* The identity comes from the COMPONENT, never from the drawn words: the host heads a bash card
|
|
349
|
+
* with the activity it inferred (`extensions/quiet-tools.ts:672` in `cards-bash-v2`), so a grammar
|
|
350
|
+
* over the title breaks the next time a title changes. `toolName` is exactly the member the host's
|
|
351
|
+
* own tool rows carry and `pi-cinlodev-cute` reads (`src/transcript/transcript-dispatcher.ts:30-40`:
|
|
352
|
+
* `child.toolName === "bash"`), and `component` is the child's `constructor.name` — the fallback for
|
|
353
|
+
* a child that carries no tool name at all (a banner, a spacer, a host block drawn by its own class).
|
|
354
|
+
*
|
|
355
|
+
* A plugin narrows with these two members and nothing else; no component reference is handed out, so
|
|
356
|
+
* a transform can neither re-render nor mutate the host's tree. The bridge derives one entry per row
|
|
357
|
+
* from the layout the host's own render pass published (`mouseLayout`), never by rendering children
|
|
358
|
+
* a second time.
|
|
359
|
+
*/
|
|
360
|
+
export interface RowOrigin {
|
|
361
|
+
/** The row's index in the frame: row 0 is the first row handed to the transform. */
|
|
362
|
+
readonly index: number;
|
|
363
|
+
/** The child's `toolName`, e.g. `"bash"`; absent when it carries none as a string. */
|
|
364
|
+
readonly toolName?: string;
|
|
365
|
+
/** The child's `constructor.name`, e.g. `"ToolExecutionComponent"`; absent when it has none. */
|
|
366
|
+
readonly component?: string;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
/**
|
|
370
|
+
* Context handed to a transform on every frame. `width` is the width the host rendered the
|
|
371
|
+
* conversation at, which is also the hard limit on what the transform may return (S4).
|
|
372
|
+
*/
|
|
373
|
+
export interface TransformContext {
|
|
374
|
+
readonly width: number;
|
|
375
|
+
/**
|
|
376
|
+
* Which host child drew each row, one entry per row of this frame (S1), or an EMPTY array when the
|
|
377
|
+
* origin is unknown — a host render that published no layout, a layout measured at another width,
|
|
378
|
+
* or heights that do not add up to the frame. Unknown is reported as empty, never as a guess and
|
|
379
|
+
* never as an error: a transform that does not need the origin ignores the field and behaves
|
|
380
|
+
* exactly as it did before it existed.
|
|
381
|
+
*
|
|
382
|
+
* Optional for the same reason `report` is: a context produced by a copy (or a probe) older than
|
|
383
|
+
* this field has no such member. The pipeline ALWAYS sets it — unknown origins are `[]`, never
|
|
384
|
+
* `undefined` — so a transform reads `ctx.rows ?? []` and works against either producer.
|
|
385
|
+
*/
|
|
386
|
+
readonly rows?: readonly RowOrigin[];
|
|
387
|
+
/**
|
|
388
|
+
* Report this frame's counts (F1). The bridge adds the line count and the outcome itself, records
|
|
389
|
+
* the result in this frame's entry for the diagnostics record, and never lets it reach the frame: a
|
|
390
|
+
* throw, or nonsense, costs the counts and nothing else (F4).
|
|
391
|
+
*
|
|
392
|
+
* Optional because a published bridge older than the telemetry has no such member: call it behind
|
|
393
|
+
* `typeof ctx.report === "function"` and the transform keeps working with either.
|
|
394
|
+
*/
|
|
395
|
+
report?(counts: TransformCounts): void;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
/**
|
|
399
|
+
* A plugin's transcript transform (S1): a function over the conversation's lines.
|
|
400
|
+
*
|
|
401
|
+
* Unlike a card style, a transform is not given a detected card — it sees the rows the host (and
|
|
402
|
+
* any earlier transform) produced and returns the rows to draw. That is the layer a rendering
|
|
403
|
+
* choice needs to apply to cards that are ALREADY on screen: a tool renderer resolves once, when a
|
|
404
|
+
* row is built, while the conversation component renders every frame.
|
|
405
|
+
*
|
|
406
|
+
* The bridge clips whatever comes back to `ctx.width`, skips the transform for the frame if it
|
|
407
|
+
* throws, and never lets a transform into Pi's render loop (S3, S4).
|
|
408
|
+
*/
|
|
409
|
+
export interface TranscriptTransform {
|
|
410
|
+
/** Unique and stable: the replacement key, the ordering key and the diagnostics record name. */
|
|
411
|
+
id: string;
|
|
412
|
+
/** Optional display name for the plugin's INTEGRATIONS line; see `RowProvider.name`. */
|
|
413
|
+
name?: string;
|
|
414
|
+
/**
|
|
415
|
+
* Optional integer. Transforms with an `order` run first, ascending; the rest follow in
|
|
416
|
+
* registration order, so several plugins always produce one deterministic pipeline (S2).
|
|
417
|
+
*/
|
|
418
|
+
order?: number;
|
|
419
|
+
/** The rows, and the width to honour. Return the rows to draw. */
|
|
420
|
+
transform(lines: readonly string[], ctx: TransformContext): readonly string[];
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
/**
|
|
424
|
+
* Context handed to a tool design's `apply` on EVERY render pass of the host's card (S5).
|
|
425
|
+
*
|
|
426
|
+
* `width` is the width the host asked its own component to render at, `tool` is the tool name the
|
|
427
|
+
* design was declared for (never anything the card draws), and `theme` is the opaque theme object the
|
|
428
|
+
* host handed that renderer (`renderCall`'s second argument, `renderResult`'s third). The bridge does
|
|
429
|
+
* not depend on the theme's shape, so a design that wants a colour narrows it itself.
|
|
430
|
+
*
|
|
431
|
+
* `part` says WHICH half of the card this pass is drawing (S12). A card has two components — the call
|
|
432
|
+
* and the result — and the host draws them with the same chrome, so from rows alone the two are
|
|
433
|
+
* indistinguishable: a float result body row that begins with `$ ` (a script echoing commands) sits
|
|
434
|
+
* exactly where a float heading sits. The bridge wraps the two renderers separately and sets `part`
|
|
435
|
+
* per renderer, so a design can act on the call alone instead of guessing from drawn text. A design
|
|
436
|
+
* that ignores `part` behaves exactly as it did before the field existed.
|
|
437
|
+
*
|
|
438
|
+
* `cardStyle` is the style the USER has selected right now (S22): `native` when the bridge paints
|
|
439
|
+
* nothing, the live registration when a plugin's style is selected, and `missing` for an id nobody
|
|
440
|
+
* owns any more. It is what lets a design honour `float`/`neon` on a card the host never styles
|
|
441
|
+
* itself — a tool another extension registers, like `bash_background`. Resolved on ACCESS and at
|
|
442
|
+
* most once per pass, so a design that never reads it draws exactly what it drew before the field
|
|
443
|
+
* existed, and pays nothing for it; a design that reads it twice gets ONE answer, so a switch landing
|
|
444
|
+
* mid-pass can never draw half of each.
|
|
445
|
+
*/
|
|
446
|
+
export interface ToolDesignContext {
|
|
447
|
+
readonly width: number;
|
|
448
|
+
readonly tool: string;
|
|
449
|
+
readonly theme?: unknown;
|
|
450
|
+
/** The renderer this pass came from: `renderCall` or `renderResult`. */
|
|
451
|
+
readonly part: "call" | "result";
|
|
452
|
+
/**
|
|
453
|
+
* What Pi's render context says about THIS tool call, read at this pass: the call's arguments and
|
|
454
|
+
* whether it is running, failed or finished, and how long it took. Optional because a host that
|
|
455
|
+
* hands no render context (or an older bridge) leaves it out; a design that needs it must work
|
|
456
|
+
* without it.
|
|
457
|
+
*/
|
|
458
|
+
readonly render?: ToolDesignRender;
|
|
459
|
+
/**
|
|
460
|
+
* The style the user has selected, resolved live on access. Absent on a bridge older than S22, and
|
|
461
|
+
* `missing` for a style that was disposed while it was selected (a `/reload`, a plugin unloaded):
|
|
462
|
+
* a design must degrade to its own default in both cases, exactly as the bridge itself does.
|
|
463
|
+
*/
|
|
464
|
+
readonly cardStyle?: CardStyleSelection;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
/**
|
|
468
|
+
* The fields of the host's render context a design may read, copied by value so a design cannot
|
|
469
|
+
* reach the host's live context. Every field is optional: the bridge forwards only what the host
|
|
470
|
+
* actually provided, with the type it has.
|
|
471
|
+
*/
|
|
472
|
+
export interface ToolDesignRender {
|
|
473
|
+
/** Stable across the call's and the result's passes: the key that ties the two halves of a card. */
|
|
474
|
+
readonly toolCallId?: string;
|
|
475
|
+
/**
|
|
476
|
+
* The call's arguments exactly as Pi holds them (for `bash`, `{ command, timeout? }`): the HOST's own
|
|
477
|
+
* object, forwarded by reference and never cloned or frozen. Treat it as read-only; mutating it is
|
|
478
|
+
* unsupported (Pi keeps updating it while the call streams).
|
|
479
|
+
*/
|
|
480
|
+
readonly args?: unknown;
|
|
481
|
+
/** The result is partial or streaming: the call is still running. */
|
|
482
|
+
readonly isPartial?: boolean;
|
|
483
|
+
/** The finished call reported an error. */
|
|
484
|
+
readonly isError?: boolean;
|
|
485
|
+
/** Milliseconds the execution took; undefined while it runs or when none was recorded. */
|
|
486
|
+
readonly durationMs?: number;
|
|
487
|
+
/** The row is expanded. */
|
|
488
|
+
readonly expanded?: boolean;
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
/**
|
|
492
|
+
* ONE call of a tool, as a scope sees it (S7/S10): the tool name and the arguments Pi holds for that
|
|
493
|
+
* call, forwarded BY REFERENCE and never cloned or frozen. A scope never sees the card's `part`, so
|
|
494
|
+
* both halves of one card are resolved with the same INPUT — and the same procedure. The arguments
|
|
495
|
+
* are read again on each pass and Pi keeps updating them while a call streams, so a scope that reads
|
|
496
|
+
* a field the host mutates mid-call can answer differently for the two halves: read fields that are
|
|
497
|
+
* stable for the life of a call (a `path`), never a streaming body.
|
|
498
|
+
*/
|
|
499
|
+
export interface ToolDesignCall {
|
|
500
|
+
readonly tool: string;
|
|
501
|
+
readonly args?: unknown;
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
/**
|
|
505
|
+
* The narrower-than-a-tool claim a line may declare (S7): the calls of its tools this line OWNS.
|
|
506
|
+
*
|
|
507
|
+
* A scope is a PREDICATE, never a declarative path rule: path identity ("under `skills/` or `odd/`")
|
|
508
|
+
* is the consumer's own rule, and this bridge is tool-agnostic by construction. It is the same trust
|
|
509
|
+
* model `apply` already has — plugin code the host runs, isolated on throw — because a function has
|
|
510
|
+
* no printable form, `description` is required: the menu and the diagnostics record have to explain which
|
|
511
|
+
* calls the line owns.
|
|
512
|
+
*/
|
|
513
|
+
export interface ToolDesignScope {
|
|
514
|
+
/**
|
|
515
|
+
* One short line a preview and the diagnostics record can show, e.g. `paths under skills/ or odd/`. One
|
|
516
|
+
* line LITERALLY (S18): the bridge renders it INSIDE an existing row, so a CR or LF would add a row
|
|
517
|
+
* and the registration is refused whole.
|
|
518
|
+
*/
|
|
519
|
+
readonly description: string;
|
|
520
|
+
/**
|
|
521
|
+
* Whether this line owns THIS call, answered SYNCHRONOUSLY with `true` or `false` (S18). A paint
|
|
522
|
+
* cannot await, so any other answer (a Promise, a truthy string, `undefined`) counts as "this line
|
|
523
|
+
* does not own the call" and is reported in the diagnostics record. Cheap and pure; the bridge isolates a
|
|
524
|
+
* throw.
|
|
525
|
+
*/
|
|
526
|
+
matches(call: ToolDesignCall): boolean;
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
/**
|
|
530
|
+
* A plugin's design for ONE tool's card (S4, S5, S7).
|
|
531
|
+
*
|
|
532
|
+
* A design never owns the frame: the host's own renderer runs first, and the design receives the
|
|
533
|
+
* rows that card produced and returns the rows to draw. Anything it does not deliberately change must
|
|
534
|
+
* come back byte for byte — including ANSI sequences and trailing padding — because the frame is
|
|
535
|
+
* still the host's (`neon` stays neon, `float` stays float).
|
|
536
|
+
*
|
|
537
|
+
* A design is declared for a TOOL NAME (`bash`, `write`, `edit`, `mcp__engram__mem_save`, ...), never
|
|
538
|
+
* for bash specifically: a design declared for a tool that has no card yet applies as soon as Pi
|
|
539
|
+
* builds one, because Pi resolves renderers when the card is constructed.
|
|
540
|
+
*/
|
|
541
|
+
export interface ToolDesignRegistration {
|
|
542
|
+
/**
|
|
543
|
+
* The tool name this design draws, for an UNGROUPED registration: it gets its own `Card <tool>`
|
|
544
|
+
* line. Exactly one of `tool` / (`line` + `tools`) is required; mixing them is refused.
|
|
545
|
+
*/
|
|
546
|
+
tool?: string;
|
|
547
|
+
/**
|
|
548
|
+
* The line this design joins, for a GROUPED registration. Several registrations naming the same
|
|
549
|
+
* line — from one plugin or two — join ONE `Card <line>` line whose values are its designs in
|
|
550
|
+
* registration order (S3), and whose tool set is the union of their `tools`.
|
|
551
|
+
*/
|
|
552
|
+
line?: string;
|
|
553
|
+
/**
|
|
554
|
+
* The tools a GROUPED design paints. Required with `line`, refused with `tool`. Non-empty,
|
|
555
|
+
* deduplicated, each a valid tool name. A tool's claim is UNSCOPED when neither `scopes[tool]` nor
|
|
556
|
+
* the `scope` shorthand supplies a scope for it. A tool has at most ONE unscoped claim (S9/D1): a
|
|
557
|
+
* registration whose unscoped claim meets another one on the same tool is refused whole, and
|
|
558
|
+
* reported in the diagnostics record — the other claim may live on a different line, or on the tool's own
|
|
559
|
+
* legacy `Card <tool>` line. A claim that carries a scope claims only the calls its scope matches,
|
|
560
|
+
* so any number of scoped claims may name one tool, beside that one unscoped claim.
|
|
561
|
+
*/
|
|
562
|
+
tools?: readonly string[];
|
|
563
|
+
/**
|
|
564
|
+
* Optional. The scope of each TOOL's claim (S19): a key is one of THIS registration's `tools`, and
|
|
565
|
+
* the value is the `ToolDesignScope` that line owns of that tool's calls. A tool with no entry
|
|
566
|
+
* claims EVERY call of it, exactly as a registration carrying no scope at all does.
|
|
567
|
+
*
|
|
568
|
+
* A scope belongs to the (line, tool) CLAIM and not to the line, so one line may own some tools
|
|
569
|
+
* unconditionally and narrow others — `Card tools` paints bash/grep/find/ls/read for every call
|
|
570
|
+
* and write/edit only under `skills/` or `odd/` — while another line carries the generic claim on
|
|
571
|
+
* the same tools. Specific beats generic at paint time: the matching scoped claims answer first and
|
|
572
|
+
* the one unscoped claim answers last. An invalid map (not an object, empty, a key that is not one
|
|
573
|
+
* of `tools`, a value that is not a scope) refuses the whole registration. Declared on a GROUPED
|
|
574
|
+
* registration only, like `scope`.
|
|
575
|
+
*/
|
|
576
|
+
readonly scopes?: Readonly<Record<string, ToolDesignScope>>;
|
|
577
|
+
/** Unique per line (or per tool when ungrouped): the value the user selects and the key for replacement. */
|
|
578
|
+
id: string;
|
|
579
|
+
/**
|
|
580
|
+
* Optional display name for the plugin's INTEGRATIONS line, e.g. `"Loon kit"`. Same rule as
|
|
581
|
+
* `RowProvider.name`: honoured on the plugin's FIRST registration only, must obey the row-name
|
|
582
|
+
* shape, and never rewritten. A single-file extension with no `package.json` above it has no
|
|
583
|
+
* attributable package and gets no line unless it names itself here — which is why a plugin that
|
|
584
|
+
* contributes ONLY designs still needs this member.
|
|
585
|
+
*/
|
|
586
|
+
name?: string;
|
|
587
|
+
/**
|
|
588
|
+
* The tool-design switch this design follows instead of having a switch of its own (S1, 0.12.0).
|
|
589
|
+
* A following design contributes NO value to the customize menu: the value the user already picked on
|
|
590
|
+
* that tool line is what turns it on. Omit it for a design with its own `Message <line>` line, which
|
|
591
|
+
* is what every 0.11.0 registration does.
|
|
592
|
+
*/
|
|
593
|
+
follows?: MessageDesignFollow;
|
|
594
|
+
/** The short text shown on the customize line as this design's value. */
|
|
595
|
+
label: string;
|
|
596
|
+
/** One line a preview can show about what the design does. */
|
|
597
|
+
description?: string;
|
|
598
|
+
/** Optional literal depiction of the design, drawn in the customize preview. */
|
|
599
|
+
preview?(): RowPreview;
|
|
600
|
+
/**
|
|
601
|
+
* Optional SHORTHAND for `scopes` (S19): the SAME scope object on every tool of `tools`. Refused
|
|
602
|
+
* together with `scopes`, because the two spellings of one claim would disagree.
|
|
603
|
+
*
|
|
604
|
+
* A claim without a scope claims EVERY call of its tool, exactly as before (S7/S8). A scoped claim
|
|
605
|
+
* owns only the calls `matches` answers true for, so another line may name the same tool for the
|
|
606
|
+
* calls this one does not own. A scope is declared on a GROUPED registration ONLY (`line` +
|
|
607
|
+
* `tools`): an ungrouped registration IS the tool's own `Card <tool>` line, which means every call
|
|
608
|
+
* of the tool by definition, so `{ tool, scope, … }` is refused whole. Every live registration of
|
|
609
|
+
* ONE line that names a tool must share the SAME scope object for that tool: a line is one switch
|
|
610
|
+
* per call of a tool, and a scope per design would make one switch mean different calls. A
|
|
611
|
+
* registration that does not name the tool does not constrain it. An invalid scope (no
|
|
612
|
+
* description, no `matches`) refuses the whole registration.
|
|
613
|
+
*/
|
|
614
|
+
readonly scope?: ToolDesignScope;
|
|
615
|
+
/**
|
|
616
|
+
* The host's rows in, the rows to draw out. The bridge hands a fresh copy, clips nothing and
|
|
617
|
+
* isolates a throw: an `apply` that throws (or returns something that is not an array of strings)
|
|
618
|
+
* leaves the host's own card on screen and is reported in the diagnostics record.
|
|
619
|
+
*/
|
|
620
|
+
apply(lines: readonly string[], ctx: ToolDesignContext): string[];
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
/**
|
|
624
|
+
* A plugin's card style: chrome, never a parser (S1). The bridge owns detection and hands this
|
|
625
|
+
* registration's `frame` the card it found; the style owns only what the card looks like.
|
|
626
|
+
*/
|
|
627
|
+
export interface CardStyleRegistration {
|
|
628
|
+
/**
|
|
629
|
+
* Unique and stable: it is the value the user selects and the key for ordering and replacement.
|
|
630
|
+
* It may not be `native` (the bridge's own pass-through value) nor one of the host's own values,
|
|
631
|
+
* because the line would then show the same value twice.
|
|
632
|
+
*/
|
|
633
|
+
id: string;
|
|
634
|
+
/** Optional display name for the plugin's INTEGRATIONS line; see `RowProvider.name`. */
|
|
635
|
+
name?: string;
|
|
636
|
+
/** The short text shown on the `Card style` line for this value. */
|
|
637
|
+
label: string;
|
|
638
|
+
/**
|
|
639
|
+
* What this style's row reads in the menu, e.g. `"plain"`. Optional: when absent the bridge
|
|
640
|
+
* derives it from `label` (lowercase words, no dots, no prefix). `label` stays the line's value and
|
|
641
|
+
* the `id` stays internal; the row never shows the id.
|
|
642
|
+
*/
|
|
643
|
+
rowLabel?: string;
|
|
644
|
+
frame: CardFrame;
|
|
645
|
+
/** Optional literal depiction of the style, drawn in the customize preview. */
|
|
646
|
+
preview?(): RowPreview;
|
|
647
|
+
/**
|
|
648
|
+
* Optional integer. Styles with an `order` come first, ascending; the rest follow in registration
|
|
649
|
+
* order, so several plugins always produce one deterministic value sequence (S12).
|
|
650
|
+
*/
|
|
651
|
+
order?: number;
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
/**
|
|
655
|
+
* What the stored card-style selection means right now (S12, S22).
|
|
656
|
+
*
|
|
657
|
+
* `native` is "the bridge paints nothing" and is the default, `style` is the live registration a
|
|
658
|
+
* design should honour, and `missing` is a first-class answer rather than an error: a style that was
|
|
659
|
+
* disposed while it was selected leaves a stored id nobody owns, and the bridge must degrade to
|
|
660
|
+
* `native` and say so instead of rendering chrome that no longer exists. Resolving never throws for
|
|
661
|
+
* any stored value, because that answer is what the transformer — and now a tool design — degrades
|
|
662
|
+
* from.
|
|
663
|
+
*/
|
|
664
|
+
export type CardStyleSelection =
|
|
665
|
+
| { kind: "native" }
|
|
666
|
+
| { kind: "style"; style: CardStyleRegistration }
|
|
667
|
+
| { kind: "missing"; id: string };
|
|
668
|
+
|
|
669
|
+
/**
|
|
670
|
+
* What Pi's render context says about ONE custom message, read on every pass (S1). The message is the
|
|
671
|
+
* HOST's own object, forwarded by reference exactly like `ToolDesignRender.args`: treat it as
|
|
672
|
+
* read-only. `expanded` and `outputPad` are Pi's own render options, so a design can honour the
|
|
673
|
+
* user's collapse choice instead of guessing from drawn text.
|
|
674
|
+
*/
|
|
675
|
+
export interface MessageDesignRender {
|
|
676
|
+
/** The row is expanded: the user pressed the host's expand key on it. */
|
|
677
|
+
readonly expanded: boolean;
|
|
678
|
+
/** The host's own output padding for the message component. */
|
|
679
|
+
readonly outputPad: number;
|
|
680
|
+
/**
|
|
681
|
+
* The custom message Pi is drawing, forwarded BY REFERENCE and never cloned or frozen: its
|
|
682
|
+
* `customType`, its `content`, and whatever the sending extension put in it. Pi keeps it live, so
|
|
683
|
+
* read it per pass and never cache it.
|
|
684
|
+
*/
|
|
685
|
+
readonly message: unknown;
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
/**
|
|
689
|
+
* Context handed to a message design's `apply` on EVERY pass of the message's component (S1).
|
|
690
|
+
*
|
|
691
|
+
* It is the tool-design context for a message: `width` is the width the host asked the component to
|
|
692
|
+
* render at, `customType` is the type the design was declared for, `theme` is the host's opaque theme
|
|
693
|
+
* object, and `cardStyle` is the same resolved selection a tool design reads (S22).
|
|
694
|
+
*
|
|
695
|
+
* `render` is NOT optional here: Pi hands a message renderer its `{ expanded, outputPad }` options and
|
|
696
|
+
* the message itself at construction, so there is no "context arrived late" state to model. An older
|
|
697
|
+
* copy of the bridge knows no message designs at all, so a design never meets a context without it.
|
|
698
|
+
*/
|
|
699
|
+
export interface MessageDesignContext {
|
|
700
|
+
readonly width: number;
|
|
701
|
+
/** The custom type this design paints: one of its registration's `types`, or its `customType`. */
|
|
702
|
+
readonly customType: string;
|
|
703
|
+
readonly theme?: unknown;
|
|
704
|
+
/** The style the user has selected, resolved live on access, exactly as for a tool design. */
|
|
705
|
+
readonly cardStyle?: CardStyleSelection;
|
|
706
|
+
readonly render: MessageDesignRender;
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
/**
|
|
710
|
+
* The tool-design switch a message design FOLLOWS (S1, 0.12.0): while that line answers that design
|
|
711
|
+
* id, this design is the one selected for its types; while it answers anything else (including the
|
|
712
|
+
* host's own `native`), the message keeps the host's own output.
|
|
713
|
+
*
|
|
714
|
+
* It is a READ, never a write: nothing here produces a seed, a second switch or a value the user has
|
|
715
|
+
* to pick twice, and the tool document is opened for reading only. It is answered live on every pass,
|
|
716
|
+
* so flipping the tool switch repaints the messages already on screen and turns them off again.
|
|
717
|
+
*/
|
|
718
|
+
export interface MessageDesignFollow {
|
|
719
|
+
/** The tool-design line whose switch decides this design, e.g. `"tags"`. */
|
|
720
|
+
readonly line: string;
|
|
721
|
+
/** The tool design id that must be selected on that line for this design to be active. */
|
|
722
|
+
readonly id: string;
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
/**
|
|
726
|
+
* What a follow answers right now, as the diagnostics record and a plugin can read it.
|
|
727
|
+
*/
|
|
728
|
+
export interface MessageDesignFollowAnswer {
|
|
729
|
+
/** The line the follow names. */
|
|
730
|
+
readonly line: string;
|
|
731
|
+
/** Whether a live tool-design line has that name at all. */
|
|
732
|
+
readonly found: boolean;
|
|
733
|
+
/** The design id that line answers right now, or `"none"` when there is no such line. */
|
|
734
|
+
readonly answered: string;
|
|
735
|
+
/** Whether `answered` is the id this follow waits for. */
|
|
736
|
+
readonly active: boolean;
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
/**
|
|
740
|
+
* A plugin's design for ONE custom message type, or for a line of several (S1).
|
|
741
|
+
*
|
|
742
|
+
* A custom message has no frame of the host's own to preserve: Pi draws a default box, or the
|
|
743
|
+
* registering extension's renderer does. So a design works on ROWS, exactly like a tool design, and
|
|
744
|
+
* what it receives says which case it is in:
|
|
745
|
+
*
|
|
746
|
+
* - the type HAS a host renderer: those rows, at the width Pi asked for, with the host's chrome
|
|
747
|
+
* already painted around them. The design returns the rows to draw and everything it does not
|
|
748
|
+
* deliberately change comes back byte for byte (S3);
|
|
749
|
+
* - the type has NO host renderer (`gentle-pi.exploration-budget`, `gentle-pi.verifier-settle-reminder`,
|
|
750
|
+
* or any custom type nobody renders): the message's own body, plainly — its `[customType]` label, a
|
|
751
|
+
* blank row and its text — never a picture of Pi's styled box. The design owns the frame around a
|
|
752
|
+
* body it did not have to invent (S2), drawing from `ctx.render.message`, `ctx.width` and
|
|
753
|
+
* `ctx.cardStyle`, and those same rows are what a FAILING design falls back to, so a message the
|
|
754
|
+
* agent must read is never lost to a broken design.
|
|
755
|
+
*
|
|
756
|
+
* With NO design selected for a type the bridge does nothing at all: it never touches a message no
|
|
757
|
+
* design claims (S4), so Pi's own output is byte-identical and no pass pays for the surface.
|
|
758
|
+
*/
|
|
759
|
+
export interface MessageDesignRegistration {
|
|
760
|
+
/**
|
|
761
|
+
* The custom type this design paints, for an UNGROUPED registration: it gets its own
|
|
762
|
+
* `Message <type>` line. Exactly one of `customType` / (`line` + `types`) is required; mixing them
|
|
763
|
+
* is refused.
|
|
764
|
+
*/
|
|
765
|
+
customType?: string;
|
|
766
|
+
/**
|
|
767
|
+
* The line this design joins, for a GROUPED registration. Several registrations naming the same line
|
|
768
|
+
* — from one plugin or two — join ONE `Message <line>` line, whose values are its designs in
|
|
769
|
+
* registration order and whose type set is the union of their `types`.
|
|
770
|
+
*/
|
|
771
|
+
line?: string;
|
|
772
|
+
/**
|
|
773
|
+
* The custom types a GROUPED design paints. Required with `line`, refused with `customType`.
|
|
774
|
+
* Non-empty, deduplicated, each a non-empty string. A type belongs to at most ONE line: a second
|
|
775
|
+
* claim on the same type — from another line, or from another ungrouped design — is refused whole and
|
|
776
|
+
* reported, so no two switches can ever disagree about one message.
|
|
777
|
+
*/
|
|
778
|
+
types?: readonly string[];
|
|
779
|
+
/** Unique per line (or per type when ungrouped): the value the user selects and the key for replacement. */
|
|
780
|
+
id: string;
|
|
781
|
+
/** Optional display name for the plugin's INTEGRATIONS line; see `RowProvider.name`. */
|
|
782
|
+
name?: string;
|
|
783
|
+
/**
|
|
784
|
+
* The tool-design switch this design follows instead of having a switch of its own (S1, 0.12.0).
|
|
785
|
+
* A following design contributes NO value to the customize menu: the value the user already picked on
|
|
786
|
+
* that tool line is what turns it on. Omit it for a design with its own `Message <line>` line, which
|
|
787
|
+
* is what every 0.11.0 registration does.
|
|
788
|
+
*/
|
|
789
|
+
follows?: MessageDesignFollow;
|
|
790
|
+
/** The short text shown on the customize line as this design's value. */
|
|
791
|
+
label: string;
|
|
792
|
+
/** One line a preview can show about what the design does. */
|
|
793
|
+
description?: string;
|
|
794
|
+
/** Optional literal depiction of the design, drawn in the customize preview. */
|
|
795
|
+
preview?(): RowPreview;
|
|
796
|
+
/**
|
|
797
|
+
* The rows the bridge hands the design in, and the rows it draws out. A design receives a COPY: one
|
|
798
|
+
* that mutates its input cannot corrupt the rows the host still owns. A throw, or a return value that
|
|
799
|
+
* is not an array of strings, leaves the host's own output on screen and is reported in
|
|
800
|
+
* the diagnostics record.
|
|
801
|
+
*/
|
|
802
|
+
apply(lines: readonly string[], ctx: MessageDesignContext): string[];
|
|
803
|
+
}
|