ceulen 0.1.0 → 0.5.1
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/CHANGELOG.md +150 -0
- package/README.md +103 -14
- package/extensions/index.ts +113 -0
- package/extensions/lib/env.ts +75 -0
- package/extensions/lib/panel.ts +1720 -0
- package/extensions/lib/registry.ts +182 -0
- package/extensions/modules/composer/index.ts +128 -0
- package/extensions/modules/composer/lib/settings.ts +55 -0
- package/extensions/modules/composer/lib/shapes.ts +436 -0
- package/extensions/modules/composer/test/editor.test.ts +138 -0
- package/extensions/modules/composer/test/module.test.ts +218 -0
- package/extensions/modules/composer/test/screen.test.ts +195 -0
- package/extensions/modules/composer/test/shapes.test.ts +175 -0
- package/extensions/modules/config/index.ts +298 -0
- package/extensions/modules/config/piSettings.ts +467 -0
- package/extensions/modules/config/plugins.ts +290 -0
- package/extensions/modules/config/test/kernel.test.ts +523 -0
- package/extensions/modules/config/test/kernelV4.test.ts +196 -0
- package/extensions/modules/config/test/menu.test.ts +226 -0
- package/extensions/modules/config/test/panel.test.ts +395 -0
- package/extensions/modules/config/test/piSettings.test.ts +185 -0
- package/extensions/modules/config/test/plugins.test.ts +181 -0
- package/extensions/modules/config/test/preview-block.test.ts +88 -0
- package/extensions/modules/ponytail/UPSTREAM +26 -0
- package/extensions/modules/ponytail/index.ts +336 -0
- package/extensions/modules/ponytail/lib/config.ts +149 -0
- package/extensions/modules/ponytail/lib/instructions.ts +98 -0
- package/extensions/modules/ponytail/lib/subagent.ts +31 -0
- package/extensions/modules/ponytail/test/extension.test.ts +422 -0
- package/extensions/modules/ponytail/test/helpers.test.ts +163 -0
- package/extensions/modules/ponytail/test/subagent.test.ts +33 -0
- package/extensions/modules/router/commands/commands.ts +99 -0
- package/extensions/modules/router/configPanel.ts +89 -0
- package/extensions/modules/router/index.ts +75 -0
- package/extensions/modules/router/lib/client.ts +390 -0
- package/extensions/modules/router/lib/config.ts +142 -0
- package/extensions/modules/router/lib/migrate.ts +92 -0
- package/extensions/modules/router/lib/provider.ts +138 -0
- package/extensions/modules/router/lib/refresh.ts +19 -0
- package/extensions/modules/router/test/guard.test.ts +77 -0
- package/extensions/modules/router/test/unit.test.ts +1126 -0
- package/extensions/modules/usage/index.ts +1975 -0
- package/extensions/modules/usage/test/context.test.ts +387 -0
- package/extensions/modules/usage/test/env-gating.test.ts +113 -0
- package/extensions/modules/usage/test/opencode-go-usage.test.ts +139 -0
- package/extensions/modules/usage/test/parsers.test.ts +244 -0
- package/extensions/modules/usage/test/stale-ctx-regression.test.ts +294 -0
- package/extensions/modules/usage/test/zai-anthropic-adapter.test.ts +40 -0
- package/package.json +15 -3
- package/skills/ponytail/SKILL.md +124 -0
- package/skills/ponytail-audit/SKILL.md +41 -0
- package/skills/ponytail-debt/SKILL.md +44 -0
- package/skills/ponytail-gain/SKILL.md +51 -0
- package/skills/ponytail-help/SKILL.md +73 -0
- package/skills/ponytail-review/SKILL.md +57 -0
- package/extensions/index.js +0 -42
|
@@ -0,0 +1,523 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Kernel v2 model tests — split layout, selection submenus, descriptions/warnings,
|
|
3
|
+
* changed-vs-default styling, group jumps, degrade, type-to-search.
|
|
4
|
+
*
|
|
5
|
+
* The stub theme emits REAL ANSI codes (so truncateToWidth/visibleWidth see
|
|
6
|
+
* honest widths and marker assertions stay unambiguous) with distinct colors
|
|
7
|
+
* per token.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { describe, it } from "node:test";
|
|
11
|
+
import assert from "node:assert/strict";
|
|
12
|
+
import { visibleWidth } from "@earendil-works/pi-tui";
|
|
13
|
+
import type { Component } from "@earendil-works/pi-tui";
|
|
14
|
+
import { ConfigPanelModel, filterText, printableText, row, type PanelGroup } from "../../../lib/panel.js";
|
|
15
|
+
|
|
16
|
+
const ANSI = {
|
|
17
|
+
accent: "\x1b[36m",
|
|
18
|
+
warning: "\x1b[33m",
|
|
19
|
+
dim: "\x1b[2m",
|
|
20
|
+
muted: "\x1b[90m",
|
|
21
|
+
success: "\x1b[32m",
|
|
22
|
+
text: "",
|
|
23
|
+
reset: "\x1b[0m",
|
|
24
|
+
} as const;
|
|
25
|
+
const theme = {
|
|
26
|
+
fg: (token: string, text: string) => `${ANSI[token as keyof typeof ANSI] ?? ""}${text}${ANSI.reset}`,
|
|
27
|
+
bold: (text: string) => text,
|
|
28
|
+
};
|
|
29
|
+
// Strip ANSI for text assertions; keep raw for token assertions.
|
|
30
|
+
// eslint-disable-next-line no-control-regex
|
|
31
|
+
const plain = (s: string) => s.replace(/\x1b\[[0-9;]*m/g, "");
|
|
32
|
+
|
|
33
|
+
function groups(): PanelGroup[] {
|
|
34
|
+
return [
|
|
35
|
+
{
|
|
36
|
+
key: "modules",
|
|
37
|
+
label: "Modules",
|
|
38
|
+
rows: [
|
|
39
|
+
row("ceulen.disabled.usage", "usage", "toggle", true, () => {}, {
|
|
40
|
+
description: "Usage footer.",
|
|
41
|
+
warning: "Off takes effect after /reload.",
|
|
42
|
+
defaultValue: true,
|
|
43
|
+
}),
|
|
44
|
+
row("ceulen.disabled.ponytail", "ponytail", "toggle", false, () => {}, {
|
|
45
|
+
description: "Lazy mode.",
|
|
46
|
+
defaultValue: true, // differs from value → changed
|
|
47
|
+
}),
|
|
48
|
+
],
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
key: "ponytail",
|
|
52
|
+
label: "Ponytail",
|
|
53
|
+
rows: [
|
|
54
|
+
row("ponytail.mode", "Default mode", "string", "full", () => {}, {
|
|
55
|
+
values: ["off", "lite", "full", "ultra"],
|
|
56
|
+
defaultValue: "full",
|
|
57
|
+
description: "Intensity for new sessions.",
|
|
58
|
+
}),
|
|
59
|
+
row("ponytail.quiet", "Quiet startup", "toggle", false, () => {}, { defaultValue: false }),
|
|
60
|
+
],
|
|
61
|
+
},
|
|
62
|
+
];
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const model = (g: PanelGroup[] = groups()) => {
|
|
66
|
+
const m = new ConfigPanelModel(g, theme, "Ceulen Configuration");
|
|
67
|
+
m.getHeight = () => 40; // deterministic frame height (default reads the real terminal)
|
|
68
|
+
return m;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
describe("panel kernel v2 — render", () => {
|
|
72
|
+
it("renders a tab bar, the ACTIVE tab's rows only, and the fixed description area", () => {
|
|
73
|
+
const m = model();
|
|
74
|
+
const out = m.render(110).map(plain);
|
|
75
|
+
assert.ok(out[0]!.includes("Ceulen Configuration"), "title sits in the top border");
|
|
76
|
+
// Tab bar lists every group; only the FIRST tab's rows render.
|
|
77
|
+
const tabBar = out.find((l) => l.includes("Modules") && l.includes("Ponytail") && !l.includes("Default mode"));
|
|
78
|
+
assert.ok(tabBar, `tab bar with both groups: ${JSON.stringify(out.slice(0, 3))}`);
|
|
79
|
+
assert.ok(out.some((l) => l.includes("usage")), "active tab row renders");
|
|
80
|
+
assert.ok(!out.some((l) => l.includes("Default mode")), "other tab's rows hidden");
|
|
81
|
+
// Description area: warning above description, fixed 3 rows.
|
|
82
|
+
assert.ok(out.some((l) => l.includes("Off takes effect after /reload.")), "warning renders");
|
|
83
|
+
assert.ok(out.some((l) => l.includes("Usage footer.")), "description renders");
|
|
84
|
+
assert.ok(out.at(-1)!.includes("no changes") === false, "last line is the bottom border, not the status");
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it("line count is stable and width never exceeds the panel", () => {
|
|
88
|
+
const m = model();
|
|
89
|
+
const wide = m.render(110);
|
|
90
|
+
const narrow = m.render(70);
|
|
91
|
+
assert.equal(wide.length, narrow.length, "same layout height regardless of width");
|
|
92
|
+
for (const w of [110, 90, 70, 58, 40, 21]) {
|
|
93
|
+
for (const line of m.render(w)) {
|
|
94
|
+
assert.ok(visibleWidth(line) <= w, `line wider than ${w}: ${JSON.stringify(line)}`);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it("description area is fixed height — moving between described/undescribed rows never shifts layout", () => {
|
|
100
|
+
const m = model();
|
|
101
|
+
const withDesc = m.render(110).length; // row 0 has description + warning
|
|
102
|
+
m.handleInput("\u001b[B");
|
|
103
|
+
m.handleInput("\u001b[B");
|
|
104
|
+
m.handleInput("\u001b[B"); // row 3 "Default mode" — described
|
|
105
|
+
m.handleInput("\u001b[B"); // row 4 "Quiet startup" — NO description
|
|
106
|
+
const withoutDesc = m.render(110);
|
|
107
|
+
assert.equal(withoutDesc.length, withDesc, "same line count without a description");
|
|
108
|
+
const out = withoutDesc.map(plain);
|
|
109
|
+
// The 3-row description area is still present (rows end before the
|
|
110
|
+
// divider; count back from the footer divider).
|
|
111
|
+
let dividerAt = -1;
|
|
112
|
+
for (let i = out.length - 1; i >= 0; i--) if (out[i]!.startsWith("├")) { dividerAt = i; break; }
|
|
113
|
+
assert.ok(dividerAt >= 3, "description area reserved");
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it("narrow terminals keep the active tab visible with edge markers", () => {
|
|
117
|
+
const g: PanelGroup[] = [
|
|
118
|
+
{ key: "a", label: "Modules", rows: [row("a.x", "X", "toggle", true, () => {})] },
|
|
119
|
+
{ key: "b", label: "Endpoint", rows: [row("b.x", "Y", "toggle", true, () => {})] },
|
|
120
|
+
{ key: "c", label: "Ponytail", rows: [row("c.x", "Z", "toggle", true, () => {})] },
|
|
121
|
+
];
|
|
122
|
+
const m = new ConfigPanelModel(g, theme, "T");
|
|
123
|
+
// The kernel clamps to a 20-column minimum; three tabs cannot fit in it.
|
|
124
|
+
const out = m.render(20);
|
|
125
|
+
assert.ok(out.every((l) => visibleWidth(l) <= 20), "never exceeds the width");
|
|
126
|
+
const bar = out.find((l) => l.includes("Modules"));
|
|
127
|
+
assert.ok(bar, "active tab label stays visible");
|
|
128
|
+
assert.ok(plain(bar!).includes("…"), "clipped side marked");
|
|
129
|
+
// Once the selection moves to the last tab, ITS label is visible.
|
|
130
|
+
m.handleInput("\u001b[C");
|
|
131
|
+
m.handleInput("\u001b[C");
|
|
132
|
+
const bar2 = m.render(20).find((l) => l.includes("Ponytail"));
|
|
133
|
+
assert.ok(bar2, "active tab label follows the selection");
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it("styles a value differently from its default as changed (warning), and aligned label column", () => {
|
|
137
|
+
const m = model();
|
|
138
|
+
// Move selection off the first row so semantic colors are visible.
|
|
139
|
+
m.handleInput("\u001b[B");
|
|
140
|
+
const out = m.render(110);
|
|
141
|
+
// ponytail toggle value false ≠ default true → warning-styled "off".
|
|
142
|
+
assert.ok(out.some((l) => l.includes(`${ANSI.warning}off`)), "changed value warning-styled");
|
|
143
|
+
// Unselected unchanged ON keeps the semantic success color.
|
|
144
|
+
assert.ok(out.some((l) => l.includes(`${ANSI.success}on`)), "unchanged on stays success");
|
|
145
|
+
// Label column: two row labels in the same tab start at the same index.
|
|
146
|
+
const rows = out.map(plain);
|
|
147
|
+
const usageAt = rows.find((l) => l.includes("usage"))!.indexOf("usage");
|
|
148
|
+
const ponyAt = rows.find((l) => l.includes("ponytail"))!.indexOf("ponytail");
|
|
149
|
+
assert.equal(usageAt, ponyAt, "label column aligned within the tab");
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it("selected row's value is accent when not changed", () => {
|
|
153
|
+
const m = model();
|
|
154
|
+
const out = m.render(110);
|
|
155
|
+
assert.ok(out.some((l) => l.includes(`${ANSI.accent}on`)), "selected unchanged toggle value accented");
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
describe("panel kernel v2 — tabs", () => {
|
|
160
|
+
it("Tab/arrows switch categories; only the active tab's rows render and navigation stays inside it", () => {
|
|
161
|
+
const m = model();
|
|
162
|
+
assert.equal(m.selectedIndex, 0);
|
|
163
|
+
m.handleInput("\u001b[B"); // down within Modules
|
|
164
|
+
m.handleInput("\u001b[B");
|
|
165
|
+
assert.equal(m.selectedIndex, 1, "clamped at the tab's last row — must not cross into Ponytail");
|
|
166
|
+
m.handleInput("\u001b[C"); // → Ponytail tab
|
|
167
|
+
assert.equal(m.activeTab, 1);
|
|
168
|
+
assert.equal(m.selectedIndex, 2, "lands on the target tab's first row");
|
|
169
|
+
const out = m.render(110).map(plain);
|
|
170
|
+
assert.ok(out.some((l) => l.includes("Default mode")), "tab 2 rows render");
|
|
171
|
+
assert.ok(!out.some((l) => l.includes("usage")), "tab 1 rows hidden");
|
|
172
|
+
m.handleInput("\u001b[D"); // ← back
|
|
173
|
+
assert.equal(m.activeTab, 0);
|
|
174
|
+
assert.equal(m.selectedIndex, 1, "returns to the remembered row of tab 1");
|
|
175
|
+
m.handleInput("\t"); // Tab forwards
|
|
176
|
+
assert.equal(m.activeTab, 1);
|
|
177
|
+
m.handleInput("\u001b[Z"); // Shift+Tab back
|
|
178
|
+
assert.equal(m.activeTab, 0);
|
|
179
|
+
m.handleInput("\u001b[D"); // ← at the first tab WRAPS to the last (OMP behavior)
|
|
180
|
+
assert.equal(m.activeTab, 1, "wraps around the tab ring");
|
|
181
|
+
m.handleInput("\u001b[C"); // → wraps back to the first
|
|
182
|
+
assert.equal(m.activeTab, 0);
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it("single-group panels render no tab bar, but DO name the category", () => {
|
|
186
|
+
const g: PanelGroup[] = [{ key: "p", label: "Ponytail", rows: [row("p.x", "X", "toggle", false, () => {})] }];
|
|
187
|
+
const m = new ConfigPanelModel(g, theme, "T");
|
|
188
|
+
m.getHeight = () => 40;
|
|
189
|
+
const out = m.render(110).map(plain);
|
|
190
|
+
// No tab bar line (nothing to switch) — exactly one Ponytail mention: the
|
|
191
|
+
// middle heading indicator above the rows.
|
|
192
|
+
assert.equal(out.filter((l) => l.includes("Ponytail")).length, 1, `one label line: ${JSON.stringify(out)}`);
|
|
193
|
+
assert.ok(out.some((l) => l.includes("X")), "rows render");
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
it("during search, Tab jumps between categories that have matches", () => {
|
|
197
|
+
const m = model();
|
|
198
|
+
m.handleInput("o"); // matches rows in both groups (Ponytail, ponytail, mode…)
|
|
199
|
+
const before = m.selectedIndex;
|
|
200
|
+
m.handleInput("\t");
|
|
201
|
+
assert.notEqual(m.selectedIndex, before, "tab key moved to another category's match");
|
|
202
|
+
m.handleInput("\u001b"); // clear search → tab snaps to the matched category
|
|
203
|
+
const out = m.render(110).map(plain);
|
|
204
|
+
assert.ok(out.some((l) => l.includes("Modules") && l.includes("Ponytail")), "tab bar back");
|
|
205
|
+
// The rendered rows must belong to the tab the selection is in.
|
|
206
|
+
const sel = m.selectedIndex;
|
|
207
|
+
const rowLabel = out.find((l) => l.includes("›"))!;
|
|
208
|
+
assert.ok(rowLabel.length > 0 && m.groups.flatMap((g) => g.rows).length > sel, "selection valid");
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
it("renders group icons in the tab bar; active tab inverse-highlighted", () => {
|
|
212
|
+
const g: PanelGroup[] = [
|
|
213
|
+
{ key: "a", label: "Modules", icon: "🧩", rows: [row("a.x", "X", "toggle", true, () => {})] },
|
|
214
|
+
{ key: "b", label: "Ponytail", icon: "🦥", rows: [row("b.x", "Y", "toggle", true, () => {})] },
|
|
215
|
+
];
|
|
216
|
+
const m = new ConfigPanelModel(g, theme, "T");
|
|
217
|
+
const out = m.render(110);
|
|
218
|
+
const tabBar = out.find((l) => plain(l).includes("🧩") && plain(l).includes("🦥"));
|
|
219
|
+
assert.ok(tabBar, "tab bar carries both icons");
|
|
220
|
+
// No middle indicator row (OMP has none): the tab chip and the in-pane
|
|
221
|
+
// section heading carry the location instead.
|
|
222
|
+
assert.ok(!out.some((l) => plain(l).includes("setting") || plain(l).includes("settings")), "no count row");
|
|
223
|
+
assert.ok(out.some((l) => plain(l).includes("Modules")), "section heading names the group");
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
it("footer key hints color the KEYS and dim the meanings", () => {
|
|
227
|
+
const m = model();
|
|
228
|
+
const out = m.render(110);
|
|
229
|
+
const hint = out.find((l) => l.includes("navigate"));
|
|
230
|
+
assert.ok(hint, "hint line renders");
|
|
231
|
+
assert.ok(hint!.includes(`${ANSI.accent}←→`), "arrow key accented");
|
|
232
|
+
assert.ok(hint!.includes(`${ANSI.accent}Enter`), "Enter key accented");
|
|
233
|
+
assert.ok(hint!.includes(`${ANSI.dim}tab`), "meaning dimmed");
|
|
234
|
+
});
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
describe("panel kernel v2 — navigation", () => {
|
|
238
|
+
it("arrows move within the active tab; tab switches land on remembered rows", () => {
|
|
239
|
+
const m = model();
|
|
240
|
+
assert.equal(m.selectedIndex, 0);
|
|
241
|
+
m.handleInput("\u001b[B");
|
|
242
|
+
m.handleInput("\u001b[B");
|
|
243
|
+
assert.equal(m.selectedIndex, 1, "clamped inside Modules");
|
|
244
|
+
m.handleInput("\u001b[C"); // → Ponytail
|
|
245
|
+
assert.equal(m.activeTab, 1);
|
|
246
|
+
assert.equal(m.selectedIndex, 2, "landed on Ponytail's first row");
|
|
247
|
+
m.handleInput("\u001b[Z"); // Shift+Tab = previous tab
|
|
248
|
+
assert.equal(m.activeTab, 0);
|
|
249
|
+
assert.equal(m.selectedIndex, 1, "Modules' remembered row restored");
|
|
250
|
+
m.handleInput("\t"); // Tab = next tab
|
|
251
|
+
assert.equal(m.activeTab, 1);
|
|
252
|
+
assert.equal(m.selectedIndex, 2, "Ponytail's remembered row restored");
|
|
253
|
+
m.handleInput("\u001b[C"); // wraps the ring back to Modules
|
|
254
|
+
assert.equal(m.activeTab, 0);
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
it("PageUp/PageDown jump SECTIONS inside a tab (groups sharing a `tab`)", () => {
|
|
258
|
+
const g: PanelGroup[] = [
|
|
259
|
+
{ key: "e", label: "Endpoint", tab: "Router", icon: "🔌", rows: [row("e.x", "Base URL", "string", "http://x", () => {})] },
|
|
260
|
+
{ key: "m", label: "Models", tab: "Router", rows: [row("m.x", "Thinking", "toggle", true, () => {}), row("m.y", "Aliases", "string", "a", () => {})] },
|
|
261
|
+
{ key: "p", label: "Ponytail", icon: "🦥", rows: [row("p.x", "Mode", "string", "full", () => {})] },
|
|
262
|
+
];
|
|
263
|
+
const m = new ConfigPanelModel(g, theme, "T");
|
|
264
|
+
// The two Router groups merge into ONE tab; sections stay distinct.
|
|
265
|
+
assert.equal(m.activeTab, 0);
|
|
266
|
+
const out = m.render(110).map(plain);
|
|
267
|
+
assert.ok(out.some((l) => l.includes("Router")), "merged tab renders under the tab name");
|
|
268
|
+
assert.ok(out.some((l) => l.includes("Endpoint")) && out.some((l) => l.includes("Models")), "section names visible in the sidebar");
|
|
269
|
+
m.handleInput("\u001b[B"); // Base URL → Thinking (crosses the section boundary)
|
|
270
|
+
assert.equal(m.selectedIndex, 1);
|
|
271
|
+
m.handleInput("\u001b[6~"); // PageDown → next section's first row
|
|
272
|
+
assert.equal(m.activeTab, 0, "section jump stays inside the tab");
|
|
273
|
+
assert.equal(m.selectedIndex, 0, "section ring wraps back to Endpoint");
|
|
274
|
+
m.handleInput("\u001b[C"); // → Ponytail tab
|
|
275
|
+
assert.equal(m.activeTab, 1);
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
it("←/→ match every arrow encoding (CSI, SS3 application-cursor, kitty CSI-u)", () => {
|
|
279
|
+
for (const [right, left] of [["\u001b[C", "\u001b[D"], ["\u001bOC", "\u001bOD"], ["\u001b[1;1C", "\u001b[1;1D"]] as const) {
|
|
280
|
+
const m = model();
|
|
281
|
+
m.handleInput(right);
|
|
282
|
+
assert.equal(m.activeTab, 1, `right ${JSON.stringify(right)} advances`);
|
|
283
|
+
m.handleInput(left);
|
|
284
|
+
assert.equal(m.activeTab, 0, `left ${JSON.stringify(left)} goes back`);
|
|
285
|
+
// Wrap both ways per encoding.
|
|
286
|
+
m.handleInput(left);
|
|
287
|
+
assert.equal(m.activeTab, 1, `left at the first tab wraps (${JSON.stringify(left)})`);
|
|
288
|
+
m.handleInput(right);
|
|
289
|
+
assert.equal(m.activeTab, 0, `right at the last tab wraps (${JSON.stringify(right)})`);
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
it("Esc after a CROSS-TAB search snaps to the matched row's tab (not back)", () => {
|
|
294
|
+
const m = model();
|
|
295
|
+
// CROSS-TAB by construction: "intensity" matches ONLY the Ponytail-tab
|
|
296
|
+
// row (its description) — the first/only match lives in tab 1, never in
|
|
297
|
+
// tab 0, so the snap cannot pass vacuously.
|
|
298
|
+
for (const ch of "intensity") m.handleInput(ch);
|
|
299
|
+
assert.equal(m.visibleRows.length, 1, `exactly one match, in tab 1 (got ${JSON.stringify(m.visibleRows)})`);
|
|
300
|
+
assert.equal(m.selectedIndex, 2, "selection pulled onto the tab-1 match");
|
|
301
|
+
assert.equal(m.activeTab, 1, "active tab followed the cross-tab match while typing");
|
|
302
|
+
m.handleInput("\u001b"); // clear
|
|
303
|
+
assert.equal(m.filter, "", "filter cleared");
|
|
304
|
+
assert.equal(m.activeTab, 1, "tab STAYED on the matched row's tab after Esc");
|
|
305
|
+
assert.equal(m.selectedIndex, 2, "matched row still selected");
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
it("tabs() never merges a group whose key coincides with a neighbor's label", () => {
|
|
309
|
+
const g: PanelGroup[] = [
|
|
310
|
+
{ key: "general", label: "General", rows: [row("g.x", "A", "toggle", true, () => {})] },
|
|
311
|
+
{ key: "x", label: "Other", tab: "General", rows: [row("x.y", "B", "toggle", true, () => {})] },
|
|
312
|
+
];
|
|
313
|
+
const m = new ConfigPanelModel(g, theme, "T");
|
|
314
|
+
// The second group's tab KEY is "General" but the first group's tab KEY is
|
|
315
|
+
// `$0` — distinct keys, so two tabs (a label collision must not merge).
|
|
316
|
+
m.handleInput("\u001b[C");
|
|
317
|
+
assert.equal(m.activeTab, 1, "second tab reachable");
|
|
318
|
+
assert.equal(m.render(110).map(plain).some((l) => l.includes("B")), true, "second group's row renders");
|
|
319
|
+
});
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
describe("panel kernel v2 — activation", () => {
|
|
323
|
+
it("Enter on an enum opens the selection submenu; Enter commits + marks dirty", async () => {
|
|
324
|
+
const cfg = { mode: "full" };
|
|
325
|
+
const g: PanelGroup[] = [{
|
|
326
|
+
key: "p",
|
|
327
|
+
label: "Ponytail",
|
|
328
|
+
rows: [row("ponytail.mode", "Default mode", "string", cfg.mode, (v) => { cfg.mode = String(v); }, {
|
|
329
|
+
values: ["off", "lite", "full", "ultra"],
|
|
330
|
+
defaultValue: "full",
|
|
331
|
+
})],
|
|
332
|
+
}];
|
|
333
|
+
const m = new ConfigPanelModel(g, theme, "T");
|
|
334
|
+
m.handleInput("\r");
|
|
335
|
+
assert.ok(m.menuOpen, "Enter opened the submenu instead of cycling");
|
|
336
|
+
assert.equal(cfg.mode, "full", "opening the menu does not change the value");
|
|
337
|
+
assert.equal(m.menuIndex, 2, "cursor starts on the current value (full)");
|
|
338
|
+
m.handleInput("\u001b[B"); // ultra
|
|
339
|
+
m.handleInput("\r");
|
|
340
|
+
assert.equal(cfg.mode, "ultra", "Enter committed the highlighted option");
|
|
341
|
+
assert.equal(m.menuOpen, false, "menu closed on commit");
|
|
342
|
+
assert.ok(m.dirty);
|
|
343
|
+
assert.ok(m.editedKeys.has("ponytail.mode"));
|
|
344
|
+
// Enum rows never open the inline editor.
|
|
345
|
+
assert.equal(m.render(110).some((l) => l.includes("Enter keep typed")), false);
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
it("Enter on a toggle flips it; space does not start a search", () => {
|
|
349
|
+
const m = model();
|
|
350
|
+
m.handleInput("\r"); // usage: true → false
|
|
351
|
+
assert.ok(m.editedKeys.has("ceulen.disabled.usage"));
|
|
352
|
+
assert.equal(m.filter, "", "space key never opens search");
|
|
353
|
+
});
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
describe("panel kernel v2 — type to search", () => {
|
|
357
|
+
it("printable keys filter rows; query/matches render; Esc clears, second Esc closes", () => {
|
|
358
|
+
const m = model();
|
|
359
|
+
let closed = 0;
|
|
360
|
+
m.onClose = () => { closed++; };
|
|
361
|
+
m.handleInput("m");
|
|
362
|
+
assert.equal(m.filter, "m");
|
|
363
|
+
let out = m.render(110).map(plain);
|
|
364
|
+
assert.ok(out.some((l) => l.includes("▸ m")), "banner shows the query");
|
|
365
|
+
assert.ok(out.some((l) => l.includes("matches")), "match count renders");
|
|
366
|
+
|
|
367
|
+
m.handleInput("o");
|
|
368
|
+
m.handleInput("d");
|
|
369
|
+
m.handleInput("e");
|
|
370
|
+
assert.equal(m.filter, "mode");
|
|
371
|
+
out = m.render(110).map(plain);
|
|
372
|
+
assert.ok(out.some((l) => l.includes("Default mode")), "fuzzy match on label");
|
|
373
|
+
// Filtered view is flat: no in-pane section headings, no sidebar rail.
|
|
374
|
+
assert.ok(!out.some((l) => l.includes("Modules")), "filtered view drops section headings");
|
|
375
|
+
|
|
376
|
+
m.handleInput("\u007f"); // backspace
|
|
377
|
+
assert.equal(m.filter, "mod");
|
|
378
|
+
m.handleInput("\u001b"); // Esc 1: clear filter, do not close
|
|
379
|
+
assert.equal(m.filter, "");
|
|
380
|
+
assert.equal(closed, 0);
|
|
381
|
+
m.handleInput("\u001b"); // Esc 2: close
|
|
382
|
+
assert.equal(closed, 1);
|
|
383
|
+
});
|
|
384
|
+
|
|
385
|
+
it("selection navigates matches only; Enter activates the matched row", () => {
|
|
386
|
+
const toggled: string[] = [];
|
|
387
|
+
const g: PanelGroup[] = [{
|
|
388
|
+
key: "x",
|
|
389
|
+
label: "X",
|
|
390
|
+
rows: [
|
|
391
|
+
row("a.alpha", "Alpha", "toggle", false, () => toggled.push("alpha")),
|
|
392
|
+
row("b.beta", "Beta", "toggle", false, () => toggled.push("beta")),
|
|
393
|
+
row("c.gamma", "Gamma", "toggle", false, () => toggled.push("gamma")),
|
|
394
|
+
],
|
|
395
|
+
}];
|
|
396
|
+
const m = new ConfigPanelModel(g, theme, "T");
|
|
397
|
+
m.handleInput("b"); // matches Beta only (label "Beta"; key b.beta)
|
|
398
|
+
m.handleInput("\u001b[B"); // down must not escape the match set
|
|
399
|
+
assert.equal(m.selectedIndex, 1, "still on Beta");
|
|
400
|
+
m.handleInput("\r");
|
|
401
|
+
assert.deepEqual(toggled, ["beta"], "activation targets the matched row");
|
|
402
|
+
});
|
|
403
|
+
|
|
404
|
+
it("no matches keeps chrome and reports zero", () => {
|
|
405
|
+
const m = model();
|
|
406
|
+
m.handleInput("z");
|
|
407
|
+
m.handleInput("z");
|
|
408
|
+
m.handleInput("z");
|
|
409
|
+
const out = m.render(110).map(plain);
|
|
410
|
+
assert.ok(out.some((l) => l.includes("0 matches")));
|
|
411
|
+
assert.ok(out.some((l) => l.includes("No matching rows")));
|
|
412
|
+
});
|
|
413
|
+
});
|
|
414
|
+
|
|
415
|
+
describe("panel kernel v2 — fullscreen frame (OMP parity)", () => {
|
|
416
|
+
it("renders exactly getHeight() lines: title border, pinned hint footer, bottom border", () => {
|
|
417
|
+
const m = model();
|
|
418
|
+
const out = m.render(110);
|
|
419
|
+
assert.equal(out.length, 40, "frame fills the injected viewport height");
|
|
420
|
+
assert.ok(plain(out[0]!).startsWith("╭─"), "rounded top border opens the frame");
|
|
421
|
+
assert.ok(plain(out[0]!).includes("Ceulen Configuration"), "title inset in the top border");
|
|
422
|
+
assert.ok(plain(out.at(-1)!).match(/^╰─+╯$/), "rounded bottom border closes the frame");
|
|
423
|
+
const hint = plain(out.at(-2)!);
|
|
424
|
+
assert.ok(hint.includes("Esc save"), "key hint is the pinned last content row");
|
|
425
|
+
// Every non-divider content row is boxed: `│ … │` (OMP's overlay row()).
|
|
426
|
+
for (const line of out.slice(1, -1)) {
|
|
427
|
+
const p = plain(line);
|
|
428
|
+
if (p.startsWith("├")) {
|
|
429
|
+
assert.ok(p.endsWith("┤"), `divider tees: ${JSON.stringify(p)}`);
|
|
430
|
+
continue;
|
|
431
|
+
}
|
|
432
|
+
assert.ok(p.startsWith("│") && p.endsWith("│"), `row boxed: ${JSON.stringify(p)}`);
|
|
433
|
+
}
|
|
434
|
+
});
|
|
435
|
+
|
|
436
|
+
it("hint text follows the mode: browse → filter → completions edit", () => {
|
|
437
|
+
const m = model();
|
|
438
|
+
const browseHint = plain(m.render(110).at(-2)!);
|
|
439
|
+
assert.ok(browseHint.includes("←→ tab") && browseHint.includes("Esc save"));
|
|
440
|
+
|
|
441
|
+
for (const ch of "mode") m.handleInput(ch);
|
|
442
|
+
const filterHint = plain(m.render(110).at(-2)!);
|
|
443
|
+
assert.ok(filterHint.includes("Esc clear"), `filter hint: ${filterHint}`);
|
|
444
|
+
|
|
445
|
+
m.handleInput("\u001b"); // clear filter
|
|
446
|
+
m.handleInput("\u001b[D"); // → Ponytail tab
|
|
447
|
+
m.handleInput("\u001b[B"); // onto Default mode (enum row — Enter opens its menu, never edits)
|
|
448
|
+
m.handleInput("\u001b[B"); // Quiet startup toggle — force a string edit below
|
|
449
|
+
// Enums never open the inline editor (they open the selection submenu) —
|
|
450
|
+
// so cover the edit-hint branch through startEdit on a plain string row.
|
|
451
|
+
const g: PanelGroup[] = [{
|
|
452
|
+
key: "s",
|
|
453
|
+
label: "String",
|
|
454
|
+
rows: [row("s.url", "Base URL", "string", "http://a", () => {}, {
|
|
455
|
+
completions: () => [{ value: "http://b" }],
|
|
456
|
+
})],
|
|
457
|
+
}];
|
|
458
|
+
const m2 = new ConfigPanelModel(g, theme, "T");
|
|
459
|
+
m2.getHeight = () => 40;
|
|
460
|
+
m2.handleInput("\r"); // opens the inline editor with the picker up
|
|
461
|
+
const editHint = plain(m2.render(110).at(-2)!);
|
|
462
|
+
assert.ok(editHint.includes("keep typed"), `edit hint: ${editHint}`);
|
|
463
|
+
});
|
|
464
|
+
|
|
465
|
+
it("dirty marker rides the footer's right edge and clears after save", () => {
|
|
466
|
+
const m = model();
|
|
467
|
+
let saved = 0;
|
|
468
|
+
// The Esc path routes through onClose (openConfigPanel wires it to save).
|
|
469
|
+
m.onClose = () => { saved++; m.dirty = false; };
|
|
470
|
+
m.handleInput("\r"); // toggle → dirty
|
|
471
|
+
const out = plain(m.render(110).at(-2)!);
|
|
472
|
+
assert.ok(out.includes("unsaved changes"), `dirty marker: ${out}`);
|
|
473
|
+
m.handleInput("\u001b"); // Esc → save
|
|
474
|
+
assert.equal(saved, 1);
|
|
475
|
+
assert.ok(plain(m.render(110).at(-2)!).includes("Esc save"), "footer back to hints");
|
|
476
|
+
});
|
|
477
|
+
|
|
478
|
+
it("tiny viewports shrink the body, never the chrome", () => {
|
|
479
|
+
const m = model();
|
|
480
|
+
m.getHeight = () => 12; // below the 14-row floor
|
|
481
|
+
const out = m.render(110);
|
|
482
|
+
assert.equal(out.length, 14, "14-row floor honored");
|
|
483
|
+
assert.ok(out.some((l) => plain(l).includes("usage")), "at least one row still visible");
|
|
484
|
+
assert.ok(plain(out.at(-2)!).includes("Esc save"), "footer survives");
|
|
485
|
+
});
|
|
486
|
+
|
|
487
|
+
it("tall viewports show more rows instead of paging sooner (budget follows height)", () => {
|
|
488
|
+
const many: PanelGroup[] = [{
|
|
489
|
+
key: "big",
|
|
490
|
+
label: "Big",
|
|
491
|
+
rows: Array.from({ length: 30 }, (_, i) => row(`b.${i}`, `Setting ${i}`, "toggle", true, () => {})),
|
|
492
|
+
}];
|
|
493
|
+
const m = new ConfigPanelModel(many, theme, "T");
|
|
494
|
+
m.getHeight = () => 50;
|
|
495
|
+
const visibleRows = m.render(110).map(plain).filter((l) => l.includes("Setting ")).length;
|
|
496
|
+
assert.ok(visibleRows > 18, `height-driven budget shows >18 rows (got ${visibleRows})`);
|
|
497
|
+
});
|
|
498
|
+
});
|
|
499
|
+
|
|
500
|
+
describe("panel kernel v2 — pure helpers", () => {
|
|
501
|
+
it("filterText covers label/key/value/description/warning/values but never a masked value", () => {
|
|
502
|
+
const r = row("k", "Label", "string", "secret-value", () => {}, {
|
|
503
|
+
mask: true,
|
|
504
|
+
description: "Desc",
|
|
505
|
+
warning: "Warn",
|
|
506
|
+
values: ["a", "b"],
|
|
507
|
+
});
|
|
508
|
+
const t = filterText(r);
|
|
509
|
+
assert.ok(t.includes("Label") && t.includes("k") && t.includes("Desc") && t.includes("Warn") && t.includes("a"));
|
|
510
|
+
assert.ok(!t.includes("secret-value"), "masked value is not searchable");
|
|
511
|
+
});
|
|
512
|
+
|
|
513
|
+
it("printableText rejects control sequences and accepts text", () => {
|
|
514
|
+
assert.equal(printableText("\u001b[A"), undefined);
|
|
515
|
+
assert.equal(printableText("\u001b"), undefined);
|
|
516
|
+
assert.equal(printableText("\r"), undefined);
|
|
517
|
+
assert.equal(printableText("\u007f"), undefined);
|
|
518
|
+
assert.equal(printableText("a"), "a");
|
|
519
|
+
assert.equal(printableText("é"), "é");
|
|
520
|
+
});
|
|
521
|
+
});
|
|
522
|
+
|
|
523
|
+
void (0 as unknown as Component); // type import keeps the tui peer honest
|