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,218 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Composer module tests — settings roundtrip (temp PI_CODING_AGENT_DIR, as
|
|
3
|
+
* the router tests do), shape dispatch, /config contribution, and the core
|
|
4
|
+
* (non-disableable) contract.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import assert from "node:assert/strict";
|
|
8
|
+
import { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
9
|
+
import { tmpdir } from "node:os";
|
|
10
|
+
import { join } from "node:path";
|
|
11
|
+
import { after, before, describe, it } from "node:test";
|
|
12
|
+
|
|
13
|
+
import { applyShape, buildComposerGroups, composerConfig, default as composerModule, shapeOptions } from "../index.ts";
|
|
14
|
+
import { DEFAULT_SHAPE, SHAPES } from "../lib/shapes.ts";
|
|
15
|
+
|
|
16
|
+
let tmpHome = "";
|
|
17
|
+
|
|
18
|
+
before(() => {
|
|
19
|
+
tmpHome = mkdtempSync(join(tmpdir(), "composer-test-"));
|
|
20
|
+
process.env.PI_CODING_AGENT_DIR = tmpHome;
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
after(() => {
|
|
24
|
+
delete process.env.PI_CODING_AGENT_DIR;
|
|
25
|
+
rmSync(tmpHome, { recursive: true, force: true });
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
const settingsFile = () => join(tmpHome, "settings.json");
|
|
29
|
+
const readSettings = (): Record<string, unknown> =>
|
|
30
|
+
JSON.parse(readFileSync(settingsFile(), "utf8")) as Record<string, unknown>;
|
|
31
|
+
|
|
32
|
+
/** Untyped ctx stub — only what applyShape/save touch. */
|
|
33
|
+
function stubCtx(overrides: Record<string, unknown> = {}): never {
|
|
34
|
+
const calls: { factory: unknown }[] = [];
|
|
35
|
+
const ctx: Record<string, unknown> = {
|
|
36
|
+
mode: "tui",
|
|
37
|
+
hasUI: true,
|
|
38
|
+
cwd: "/tmp/somerepo",
|
|
39
|
+
model: { name: "GLM" },
|
|
40
|
+
getContextUsage: () => ({ tokens: 100, contextWindow: 1000, percent: 10 }),
|
|
41
|
+
ui: {
|
|
42
|
+
theme: { fg: (_t: string, s: string) => s, inverse: (s: string) => s, getBgAnsi: () => "", getFgAnsi: () => "" },
|
|
43
|
+
setEditorComponent: (factory: unknown) => {
|
|
44
|
+
calls.push({ factory });
|
|
45
|
+
},
|
|
46
|
+
notify: () => {},
|
|
47
|
+
},
|
|
48
|
+
...overrides,
|
|
49
|
+
};
|
|
50
|
+
ctx.__calls = calls;
|
|
51
|
+
return ctx as never;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Load the module and fire session_start — installs liveCtx (status data +
|
|
55
|
+
* theme source), the same flow the real runtime runs. */
|
|
56
|
+
async function startModule(ctx: never): Promise<void> {
|
|
57
|
+
const events = new Map<string, (e: unknown, c: never) => Promise<void>>();
|
|
58
|
+
composerModule({ on: (name: string, h: never) => events.set(name, h) } as never);
|
|
59
|
+
await events.get("session_start")!({}, ctx);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
describe("composer settings", () => {
|
|
63
|
+
it("defaults to the OMP default when unset or invalid; roundtrips through settings.json", async () => {
|
|
64
|
+
const { readComposerShape, writeComposerSection } = await import("../lib/settings.ts");
|
|
65
|
+
assert.equal(readComposerShape(), DEFAULT_SHAPE, "missing file → default");
|
|
66
|
+
writeComposerSection({ shape: "rail" });
|
|
67
|
+
assert.equal(readComposerShape(), "rail");
|
|
68
|
+
assert.equal((readSettings().composer as { shape: string }).shape, "rail");
|
|
69
|
+
|
|
70
|
+
// Merge, never clobber: another top-level key survives.
|
|
71
|
+
writeFileSync(settingsFile(), JSON.stringify({ other: 1 }), "utf8");
|
|
72
|
+
writeComposerSection({ shape: "rule" });
|
|
73
|
+
assert.equal(readSettings().other, 1);
|
|
74
|
+
assert.equal(readComposerShape(), "rule");
|
|
75
|
+
|
|
76
|
+
// A stale/unknown stored id reads as the default (editor must never break).
|
|
77
|
+
writeFileSync(settingsFile(), JSON.stringify({ composer: { shape: "rails-2019" } }), "utf8");
|
|
78
|
+
assert.equal(readComposerShape(), DEFAULT_SHAPE);
|
|
79
|
+
|
|
80
|
+
// Corrupt file refuses to clobber.
|
|
81
|
+
writeFileSync(settingsFile(), "{broken", "utf8");
|
|
82
|
+
assert.throws(() => writeComposerSection({ shape: "band" }), /not valid JSON/);
|
|
83
|
+
assert.equal(readFileSync(settingsFile(), "utf8"), "{broken", "corrupt file untouched");
|
|
84
|
+
// Leave valid state for later tests.
|
|
85
|
+
writeFileSync(settingsFile(), "{}", "utf8");
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
describe("applyShape dispatch", () => {
|
|
90
|
+
it("installs an editor factory for every shape, including the default", () => {
|
|
91
|
+
for (const s of SHAPES) {
|
|
92
|
+
const ctx = stubCtx();
|
|
93
|
+
applyShape(s.id, ctx);
|
|
94
|
+
const calls = (ctx as unknown as { __calls: { factory: unknown }[] }).__calls;
|
|
95
|
+
assert.equal(calls.length, 1, s.id);
|
|
96
|
+
assert.equal(typeof calls[0]!.factory, "function", `${s.id} installs a factory`);
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it("unknown shape ids fall back to the default instead of breaking the editor", () => {
|
|
101
|
+
const ctx = stubCtx();
|
|
102
|
+
applyShape("rails-2019", ctx);
|
|
103
|
+
const calls = (ctx as unknown as { __calls: { factory: unknown }[] }).__calls;
|
|
104
|
+
assert.equal(typeof calls[0]!.factory, "function");
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it("non-TUI / missing API are no-ops", () => {
|
|
108
|
+
applyShape("band", stubCtx({ mode: "rpc" }));
|
|
109
|
+
applyShape("band", stubCtx({ hasUI: false }));
|
|
110
|
+
const ctxNoApi = stubCtx();
|
|
111
|
+
(ctxNoApi as { ui: Record<string, unknown> }).ui = {};
|
|
112
|
+
applyShape("band", ctxNoApi);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it("the installed factory builds a working ShapeEditor", async () => {
|
|
116
|
+
const ctx = stubCtx();
|
|
117
|
+
applyShape("box", ctx);
|
|
118
|
+
const factory = (
|
|
119
|
+
ctx as unknown as {
|
|
120
|
+
__calls: { factory: (t: unknown, th: unknown, kb: unknown) => { render(w: number): string[]; setText(s: string): void } }[];
|
|
121
|
+
}
|
|
122
|
+
).__calls[0]!.factory;
|
|
123
|
+
const ed = factory({ terminal: { rows: 30 }, requestRender() {} }, { borderColor: (s: string) => s }, {});
|
|
124
|
+
ed.setText("hi");
|
|
125
|
+
const lines = ed.render(30);
|
|
126
|
+
assert.ok(lines.length >= 2, "editor renders chrome");
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
describe("composerConfig", () => {
|
|
131
|
+
it("groups carry one Shape row on the Appearance tab with the OMP menu copy", async () => {
|
|
132
|
+
const ctx = stubCtx();
|
|
133
|
+
await startModule(ctx);
|
|
134
|
+
const cfg = composerConfig();
|
|
135
|
+
const groups = cfg.groups();
|
|
136
|
+
assert.equal(groups.length, 1);
|
|
137
|
+
assert.equal(groups[0]!.tab, "Appearance");
|
|
138
|
+
assert.equal(groups[0]!.label, "Composer Shape");
|
|
139
|
+
const shapeRow = groups[0]!.rows.find((r) => r.key === "composer.shape")!;
|
|
140
|
+
assert.equal(shapeRow.defaultValue, DEFAULT_SHAPE);
|
|
141
|
+
// OMP's selector copy: label + description per shape, in OMP order.
|
|
142
|
+
const options = shapeOptions();
|
|
143
|
+
assert.deepEqual(
|
|
144
|
+
options.map((o) => [o.value, o.label, o.description]),
|
|
145
|
+
SHAPES.map((s) => [s.id, s.label, s.description]),
|
|
146
|
+
);
|
|
147
|
+
const preview = shapeRow.previewLines!("box", 40);
|
|
148
|
+
assert.ok(preview.length >= 2, "previewLines render");
|
|
149
|
+
assert.ok(preview.some((l) => l.includes("Ask anything")), "preview shows the prompt");
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it("save() no-ops without its key; with it, persists + applies + notifies", async () => {
|
|
153
|
+
const ctx = stubCtx();
|
|
154
|
+
await startModule(ctx);
|
|
155
|
+
const cfg = composerConfig();
|
|
156
|
+
const before = existsSync(settingsFile()) ? readFileSync(settingsFile(), "utf8") : undefined;
|
|
157
|
+
await cfg.save(new Set(["unrelated.key"]), ctx as never);
|
|
158
|
+
assert.equal(
|
|
159
|
+
existsSync(settingsFile()) ? readFileSync(settingsFile(), "utf8") : undefined,
|
|
160
|
+
before,
|
|
161
|
+
"no write without the owned key",
|
|
162
|
+
);
|
|
163
|
+
|
|
164
|
+
const shapeRow = cfg.groups()[0]!.rows[0]!;
|
|
165
|
+
shapeRow.set("rail");
|
|
166
|
+
assert.equal(shapeRow.value, "rail");
|
|
167
|
+
|
|
168
|
+
await cfg.save(new Set(["composer.shape"]), ctx as never);
|
|
169
|
+
assert.equal((readSettings().composer as { shape: string }).shape, "rail");
|
|
170
|
+
const calls = (ctx as unknown as { __calls: { factory: unknown }[] }).__calls;
|
|
171
|
+
assert.ok(calls.length >= 1, "applied live");
|
|
172
|
+
assert.equal(typeof calls[calls.length - 1]!.factory, "function", "the save's apply installed the shape editor");
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
describe("module registration (core)", () => {
|
|
177
|
+
it("registers session_start + session_shutdown handlers", () => {
|
|
178
|
+
const events = new Map<string, unknown>();
|
|
179
|
+
composerModule({ on: (name: string, h: unknown) => events.set(name, h) } as never);
|
|
180
|
+
assert.deepEqual([...events.keys()].sort(), ["session_shutdown", "session_start"]);
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
describe("core module contract", () => {
|
|
185
|
+
it("is marked core in the registry and survives a stale disabled entry", async () => {
|
|
186
|
+
const { MODULES, isCore, readDisabled } = await import("../../../lib/registry.js");
|
|
187
|
+
const entry = MODULES.find((m) => m.name === "composer")!;
|
|
188
|
+
assert.equal(entry.core, true, "composer is core");
|
|
189
|
+
assert.equal(isCore("composer"), true);
|
|
190
|
+
assert.equal(isCore("usage"), false);
|
|
191
|
+
|
|
192
|
+
// A settings file that (wrongly) lists composer as disabled must not
|
|
193
|
+
// disable it — readDisabled filters core modules out.
|
|
194
|
+
writeFileSync(settingsFile(), JSON.stringify({ ceulen: { disabled: ["composer", "usage"] } }), "utf8");
|
|
195
|
+
assert.deepEqual(readDisabled(), ["usage"], "core module filtered from the kill-switch");
|
|
196
|
+
writeFileSync(settingsFile(), "{}", "utf8");
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
it("writeDisabled never persists a core module", async () => {
|
|
200
|
+
const { writeDisabled } = await import("../../../lib/registry.js");
|
|
201
|
+
writeDisabled(["composer", "usage"]);
|
|
202
|
+
assert.deepEqual((readSettings().ceulen as { disabled: string[] }).disabled, ["usage"]);
|
|
203
|
+
writeFileSync(settingsFile(), "{}", "utf8");
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
it("nextDisabled excludes core modules; withEnableRow adds no row for them", async () => {
|
|
207
|
+
const { nextDisabled, withEnableRow } = await import("../../config/index.js");
|
|
208
|
+
// working = enabled set; nextDisabled lists the NOT-enabled non-core modules.
|
|
209
|
+
assert.deepEqual(nextDisabled(new Set(["usage"])), ["router", "ponytail", "config"]);
|
|
210
|
+
assert.deepEqual(nextDisabled(new Set(["router", "usage", "ponytail", "config"])), [], "all-on → nothing disabled");
|
|
211
|
+
const groups = [{ key: "composer", label: "Composer Shape", rows: [{ key: "composer.shape" }] }] as never;
|
|
212
|
+
const out = withEnableRow(groups, "composer", "Composer shape.", new Set(["composer"]));
|
|
213
|
+
assert.deepEqual(out[0]!.rows.map((r: { key: string }) => r.key), ["composer.shape"], "no Enable row for core");
|
|
214
|
+
const nonCore = [{ key: "ponytail", label: "Ponytail", rows: [{ key: "ponytail.defaultMode" }] }] as never;
|
|
215
|
+
const out2 = withEnableRow(nonCore, "ponytail", "Lazy mode.", new Set(["ponytail"]));
|
|
216
|
+
assert.deepEqual(out2[0]!.rows.map((r: { key: string }) => r.key), ["ceulen.disabled.ponytail", "ponytail.defaultMode"]);
|
|
217
|
+
});
|
|
218
|
+
});
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Composed-screen tests — drive the REAL pi-tui renderer (`TuiMainScreen`)
|
|
3
|
+
* with a mock terminal, exactly like production: the TUI composes the frame,
|
|
4
|
+
* strips CURSOR_MARKER, and positions the hardware cursor from
|
|
5
|
+
* `visibleWidth(textBeforeMarker)`.
|
|
6
|
+
*
|
|
7
|
+
* This is the layer the editor-level tests can't reach: SGR state carrying
|
|
8
|
+
* across chrome-wrapped rows, marker placement after wrapping, and the
|
|
9
|
+
* hardware-cursor column pi actually emits.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { describe, it } from "node:test";
|
|
13
|
+
import assert from "node:assert/strict";
|
|
14
|
+
import { TuiMainScreen, visibleWidth } from "@earendil-works/pi-tui";
|
|
15
|
+
import { IDENTITY_THEME, ShapeEditor, shapeById, SHAPES } from "../lib/shapes.ts";
|
|
16
|
+
|
|
17
|
+
const plain = (s: string) => s.replace(/\x1b\[[0-9;]*m/g, "");
|
|
18
|
+
const COLS = 60;
|
|
19
|
+
|
|
20
|
+
/** Mock terminal capturing every byte the TUI writes. */
|
|
21
|
+
function mockTerminal(cols = COLS, rows = 20) {
|
|
22
|
+
const chunks: string[] = [];
|
|
23
|
+
const term = {
|
|
24
|
+
start: () => {},
|
|
25
|
+
stop: () => {},
|
|
26
|
+
drainInput: async () => {},
|
|
27
|
+
write: (d: string) => {
|
|
28
|
+
chunks.push(d);
|
|
29
|
+
},
|
|
30
|
+
columns: cols,
|
|
31
|
+
rows,
|
|
32
|
+
kittyProtocolActive: false,
|
|
33
|
+
moveBy: () => {},
|
|
34
|
+
hideCursor: () => {},
|
|
35
|
+
showCursor: () => {},
|
|
36
|
+
clearLine: () => {},
|
|
37
|
+
clearFromCursor: () => {},
|
|
38
|
+
clearScreen: () => {},
|
|
39
|
+
setTitle: () => {},
|
|
40
|
+
setProgress: () => {},
|
|
41
|
+
};
|
|
42
|
+
return { term, text: () => chunks.join("") };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Render one frame through the real TUI: compose → cursor extraction. */
|
|
46
|
+
function compose(ed: ShapeEditor, cols = COLS, rows = 20): { out: string; lines: string[] } {
|
|
47
|
+
const { term, text } = mockTerminal(cols, rows);
|
|
48
|
+
const tui = new TuiMainScreen(term as never, true);
|
|
49
|
+
tui.addChild(ed as never);
|
|
50
|
+
tui.setFocus(ed as never);
|
|
51
|
+
tui.start();
|
|
52
|
+
tui.renderNow(true);
|
|
53
|
+
const out = text();
|
|
54
|
+
tui.stop();
|
|
55
|
+
const lines = out
|
|
56
|
+
.split(/\r?\n/)
|
|
57
|
+
.map((l) => plain(l).replace(/\x1b/g, ""))
|
|
58
|
+
.filter((l) => l.trim() !== "");
|
|
59
|
+
return { out, lines };
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function editor(id: string, txt = "hello") {
|
|
63
|
+
const theme = { borderColor: (s: string) => s, fg: (_t: string, s: string) => s, bg: (_t: string, s: string) => s };
|
|
64
|
+
const tui = { terminal: { rows: 20 }, requestRender() {} } as never;
|
|
65
|
+
const ed = new ShapeEditor(
|
|
66
|
+
shapeById(id),
|
|
67
|
+
{ theme: () => IDENTITY_THEME, data: () => ({ model: "GLM-5.3", cwd: "ceulen", pct: 12 }) },
|
|
68
|
+
tui,
|
|
69
|
+
theme as never,
|
|
70
|
+
{} as never,
|
|
71
|
+
{ embedWorkingStatus: true },
|
|
72
|
+
);
|
|
73
|
+
ed.focused = true;
|
|
74
|
+
ed.setText(txt);
|
|
75
|
+
return ed;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
describe("composed screen through the real TUI renderer", () => {
|
|
79
|
+
it("never leaks the cursor marker to the terminal, for any shape", () => {
|
|
80
|
+
for (const s of SHAPES) {
|
|
81
|
+
const { out } = compose(editor(s.id));
|
|
82
|
+
assert.ok(!out.includes("\x1b_pi:c"), `${s.id}: cursor marker must not reach the terminal`);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it("emits a hardware-cursor column inside the composer, for every shape", () => {
|
|
87
|
+
for (const s of SHAPES) {
|
|
88
|
+
const { out } = compose(editor(s.id));
|
|
89
|
+
// pi positions the cursor with \x1b[<row>;<col>H or \x1b[<col>G.
|
|
90
|
+
const moves = [...out.matchAll(/\x1b\[(\d+);(\d+)H|\x1b\[(\d+)G/g)];
|
|
91
|
+
assert.ok(moves.length > 0, `${s.id}: a cursor position is emitted`);
|
|
92
|
+
const last = moves[moves.length - 1]!;
|
|
93
|
+
const col = last[2] !== undefined ? Number(last[2]) : Number(last[3]);
|
|
94
|
+
assert.ok(col > 1 && col <= COLS, `${s.id}: cursor column ${col} inside the composer`);
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it("paints the input text and never exceeds the terminal width", () => {
|
|
99
|
+
for (const s of SHAPES) {
|
|
100
|
+
const { out } = compose(editor(s.id, "hello world"));
|
|
101
|
+
assert.ok(out.includes("hello world"), `${s.id}: input text painted`);
|
|
102
|
+
for (const line of out.split(/\r?\n/)) {
|
|
103
|
+
const w = visibleWidth(plain(line));
|
|
104
|
+
assert.ok(w <= COLS, `${s.id}: row wider than the terminal (${w}): ${JSON.stringify(plain(line))}`);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it("paints each shape's defining chrome on screen", () => {
|
|
110
|
+
assert.ok(compose(editor("box")).out.includes("╭"), "box top border");
|
|
111
|
+
assert.ok(compose(editor("box")).out.includes("╰"), "box bottom border");
|
|
112
|
+
assert.ok(compose(editor("band")).out.includes("╰─"), "band gutter");
|
|
113
|
+
assert.ok(compose(editor("band")).out.includes("GLM-5.3"), "band status");
|
|
114
|
+
assert.ok(compose(editor("claude")).out.includes("❯"), "claude prompt");
|
|
115
|
+
assert.ok(compose(editor("field")).out.includes("▐"), "field left cap");
|
|
116
|
+
assert.ok(compose(editor("rail")).out.includes("▎"), "rail glyph");
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it("composes at narrow widths without eating closing chrome", () => {
|
|
120
|
+
for (const cols of [30, 40]) {
|
|
121
|
+
const out = compose(editor("box"), cols).out;
|
|
122
|
+
assert.ok(out.includes("╮"), `box top-right corner survives at ${cols}`);
|
|
123
|
+
assert.ok(out.includes("╯"), `box bottom-right corner survives at ${cols}`);
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it("wraps the autocomplete dropdown in shape chrome at exact width", async () => {
|
|
128
|
+
const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));
|
|
129
|
+
const { term, text } = mockTerminal(COLS, 20);
|
|
130
|
+
const tui = new TuiMainScreen(term as never, true);
|
|
131
|
+
const ident = (s: string) => s;
|
|
132
|
+
const editorTheme = {
|
|
133
|
+
borderColor: ident,
|
|
134
|
+
selectList: { selectedPrefix: ident, selectedText: ident, description: ident, scrollInfo: ident, noMatch: ident },
|
|
135
|
+
};
|
|
136
|
+
const ed = new ShapeEditor(
|
|
137
|
+
shapeById("box"),
|
|
138
|
+
{ theme: () => IDENTITY_THEME, data: () => ({ model: "M", cwd: "d", pct: 1 }) },
|
|
139
|
+
{ terminal: { rows: 20 }, requestRender() {} } as never,
|
|
140
|
+
editorTheme as never,
|
|
141
|
+
{ matches: () => false } as never,
|
|
142
|
+
{ embedWorkingStatus: true },
|
|
143
|
+
);
|
|
144
|
+
ed.focused = true;
|
|
145
|
+
ed.setAutocompleteProvider({
|
|
146
|
+
triggerCharacters: ["/"],
|
|
147
|
+
getSuggestions: async () => ({
|
|
148
|
+
items: [
|
|
149
|
+
{ value: "/help", label: "/help", description: "Show help" },
|
|
150
|
+
{ value: "/config", label: "/config", description: "Settings" },
|
|
151
|
+
],
|
|
152
|
+
prefix: "/",
|
|
153
|
+
}),
|
|
154
|
+
applyCompletion: (l: string[], cl: number, cc: number) => ({ lines: l, cursorLine: cl, cursorCol: cc }),
|
|
155
|
+
} as never);
|
|
156
|
+
tui.addChild(ed as never);
|
|
157
|
+
tui.setFocus(ed as never);
|
|
158
|
+
tui.start();
|
|
159
|
+
ed.handleInput("/");
|
|
160
|
+
await sleep(900);
|
|
161
|
+
tui.renderNow(true);
|
|
162
|
+
const out = text();
|
|
163
|
+
tui.stop();
|
|
164
|
+
assert.ok(out.includes("/help"), "dropdown painted");
|
|
165
|
+
const frame = out.slice(out.lastIndexOf("\x1b[3J") + 4);
|
|
166
|
+
const rows = frame.split(/\r?\n/).filter((l) => visibleWidth(l) > 0);
|
|
167
|
+
for (const l of rows) assert.equal(visibleWidth(l), COLS, `autocomplete row width: ${JSON.stringify(plain(l))}`);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it("each row re-asserts its own colors (no cross-row SGR reliance)", () => {
|
|
171
|
+
// With a themed editor every chrome row must carry its own SGR prefix.
|
|
172
|
+
const themed = {
|
|
173
|
+
border: (s: string) => `\x1b[34m${s}\x1b[39m`,
|
|
174
|
+
accent: (s: string) => `\x1b[36m${s}\x1b[39m`,
|
|
175
|
+
text: (s: string) => s,
|
|
176
|
+
dim: (s: string) => s,
|
|
177
|
+
warn: (s: string) => s,
|
|
178
|
+
fill: (s: string) => s,
|
|
179
|
+
inverse: (s: string) => s,
|
|
180
|
+
};
|
|
181
|
+
const theme = { borderColor: (s: string) => `\x1b[34m${s}\x1b[39m` };
|
|
182
|
+
const tui = { terminal: { rows: 20 }, requestRender() {} } as never;
|
|
183
|
+
const ed = new ShapeEditor(shapeById("box"), { theme: () => themed, data: () => ({ model: "M" }) }, tui, theme as never, {} as never, {
|
|
184
|
+
embedWorkingStatus: true,
|
|
185
|
+
});
|
|
186
|
+
ed.focused = true;
|
|
187
|
+
ed.setText("hi");
|
|
188
|
+
const { out } = compose(ed);
|
|
189
|
+
// Both the top border and the merged bottom row carry color codes.
|
|
190
|
+
const topSeg = out.slice(out.indexOf("╭"), out.indexOf("╮"));
|
|
191
|
+
const botSeg = out.slice(out.indexOf("╰"), out.indexOf("╯"));
|
|
192
|
+
assert.ok(topSeg.includes("\x1b[34m"), "top border colored");
|
|
193
|
+
assert.ok(botSeg.includes("\x1b[34m"), "bottom border colored after the text row");
|
|
194
|
+
});
|
|
195
|
+
});
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Composer shape tests — chrome builders, OMP copy parity, layout math, and
|
|
3
|
+
* the cursor marker surviving chrome wrapping (the invariant that makes side
|
|
4
|
+
* chrome safe: the TUI measures the marker in the FINAL rendered line).
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { describe, it } from "node:test";
|
|
8
|
+
import assert from "node:assert/strict";
|
|
9
|
+
import { CURSOR_MARKER, visibleWidth } from "@earendil-works/pi-tui";
|
|
10
|
+
import {
|
|
11
|
+
contentWidth,
|
|
12
|
+
DEFAULT_SHAPE,
|
|
13
|
+
gutterWidth,
|
|
14
|
+
IDENTITY_THEME,
|
|
15
|
+
isShapeId,
|
|
16
|
+
padRow,
|
|
17
|
+
previewShape,
|
|
18
|
+
SHAPE_IDS,
|
|
19
|
+
SHAPES,
|
|
20
|
+
shapeById,
|
|
21
|
+
statusLine,
|
|
22
|
+
surfacePainter,
|
|
23
|
+
type ShapeTheme,
|
|
24
|
+
} from "../lib/shapes.ts";
|
|
25
|
+
|
|
26
|
+
const plain = (s: string) => s.replace(/\x1b\[[0-9;]*m/g, "");
|
|
27
|
+
const th = IDENTITY_THEME;
|
|
28
|
+
|
|
29
|
+
describe("composer shape vocabulary (OMP parity)", () => {
|
|
30
|
+
it("ships all 8 OMP shapes in OMP order with OMP ids", () => {
|
|
31
|
+
assert.deepEqual(SHAPE_IDS, ["band", "box", "claude", "pi", "borderless", "rule", "field", "rail"]);
|
|
32
|
+
assert.equal(DEFAULT_SHAPE, "band");
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it("carries OMP's labels and descriptions verbatim", () => {
|
|
36
|
+
const expected: Record<string, [string, string]> = {
|
|
37
|
+
band: ["Status Band (Default)", "Flush soft-capped status band above a curved prompt, no frame"],
|
|
38
|
+
box: ["Rounded Box", "Status line embedded in top border, compact 2-line prompt"],
|
|
39
|
+
claude: ["Claude Code", "Full-width horizontal rules above and below, status line at bottom"],
|
|
40
|
+
pi: ["Pi", "Framed horizontal rules with status line at bottom"],
|
|
41
|
+
borderless: ["Borderless", "Clean prompt glyph with status line at bottom, no box borders"],
|
|
42
|
+
rule: ["Top Rule Dock", "Single top rule with status docked onto it and below"],
|
|
43
|
+
field: ["Compact Field", "Filled one-row field with accent end caps"],
|
|
44
|
+
rail: ["Accent Rail", "Filled one-row field anchored by a single accent rail"],
|
|
45
|
+
};
|
|
46
|
+
for (const s of SHAPES) {
|
|
47
|
+
assert.deepEqual([s.label, s.description], expected[s.id], s.id);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("unknown ids fall back to the default (stale settings can't break the editor)", () => {
|
|
52
|
+
assert.equal(shapeById("nonexistent").id, "band");
|
|
53
|
+
assert.equal(isShapeId("rail"), true);
|
|
54
|
+
assert.equal(isShapeId("nope"), false);
|
|
55
|
+
assert.equal(isShapeId(42), false);
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
describe("shape geometry", () => {
|
|
60
|
+
it("side chrome and gutters are subtracted from the content width", () => {
|
|
61
|
+
assert.equal(contentWidth(shapeById("pi"), 80), 80, "no side chrome, no gutter");
|
|
62
|
+
assert.equal(contentWidth(shapeById("band"), 80), 80 - 3, "gutter `╰─ ` = 3 cells");
|
|
63
|
+
assert.equal(contentWidth(shapeById("box"), 80), 80 - 2, "1-cell border per side");
|
|
64
|
+
assert.equal(contentWidth(shapeById("field"), 80), 80 - 2, "one cap per side");
|
|
65
|
+
assert.equal(contentWidth(shapeById("rail"), 80), 80 - 2, "rail reserves a cell each side (single left rail)");
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("gutter is capped so narrow terminals keep a text column", () => {
|
|
69
|
+
assert.ok(contentWidth(shapeById("band"), 4) >= 1);
|
|
70
|
+
assert.ok(gutterWidth(shapeById("band"), 4) <= 4);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it("padRow pads to exactly the content width, marker-safe", () => {
|
|
74
|
+
assert.equal(visibleWidth(padRow(10, "abc")), 10);
|
|
75
|
+
const withMarker = `ab${CURSOR_MARKER}`;
|
|
76
|
+
assert.equal(visibleWidth(padRow(10, withMarker)), 10, "marker is zero-width");
|
|
77
|
+
assert.ok(padRow(10, withMarker).includes(CURSOR_MARKER), "marker survives padding");
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
describe("chrome rendering through the shared builders", () => {
|
|
82
|
+
it("every shape renders a prompt row at the full width", () => {
|
|
83
|
+
for (const s of SHAPES) {
|
|
84
|
+
const lines = previewShape(s.id, 60, th, { model: "M", cwd: "d", pct: 10 });
|
|
85
|
+
assert.ok(lines.length >= 1, `${s.id} renders`);
|
|
86
|
+
for (const l of lines) {
|
|
87
|
+
assert.equal(visibleWidth(l), 60, `${s.id}: ${JSON.stringify(plain(l))}`);
|
|
88
|
+
}
|
|
89
|
+
assert.ok(lines.some((l) => plain(l).includes("Ask anything")), `${s.id} shows the prompt`);
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it("box draws corners + side bars; field/rail draw caps and rails; rail has no right cap", () => {
|
|
94
|
+
// A one-row prompt: the box merges its bottom border into that row, so
|
|
95
|
+
// the preview is exactly `╭…╮` + `╰─ … ─╯` (OMP's compact 2-line prompt).
|
|
96
|
+
const box = previewShape("box", 30, th).map(plain);
|
|
97
|
+
assert.equal(box.length, 2, box.join("\n"));
|
|
98
|
+
assert.ok(box[0]!.startsWith("╭") && box[0]!.endsWith("╮"));
|
|
99
|
+
assert.ok(box[1]!.startsWith("╰─") && box[1]!.endsWith("─╯"), box[1]);
|
|
100
|
+
const field = previewShape("field", 30, th).map(plain);
|
|
101
|
+
assert.ok(field[0]!.startsWith("▐") && field[0]!.endsWith("▌"), field[0]);
|
|
102
|
+
const rail = previewShape("rail", 30, th).map(plain);
|
|
103
|
+
assert.ok(rail[0]!.startsWith("▎"), rail[0]);
|
|
104
|
+
assert.ok(!rail[0]!.endsWith("▌"), "rail has a single rail, no caps");
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it("closing chrome glyphs survive at every width (no silent truncation)", () => {
|
|
108
|
+
// Regression: the box status row was one cell over budget and
|
|
109
|
+
// truncateToWidth silently ate the closing `╮`.
|
|
110
|
+
for (const w of [24, 30, 40, 57, 80]) {
|
|
111
|
+
const box = previewShape("box", w, th, { model: "GLM-5.3", cwd: "ceulen", pct: 42 }).map(plain);
|
|
112
|
+
assert.ok(box[0]!.endsWith("╮"), `box top closes at ${w}: ${box[0]}`);
|
|
113
|
+
assert.ok(box[box.length - 1]!.endsWith("─╯"), `box bottom closes at ${w}: ${box[box.length - 1]}`);
|
|
114
|
+
const claude = previewShape("claude", w, th, { model: "M" }).map(plain);
|
|
115
|
+
assert.equal(claude.length, 3, `claude keeps both rules at ${w}`);
|
|
116
|
+
for (const l of claude) assert.equal(visibleWidth(l), w, `claude row width at ${w}`);
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it("status-bearing shapes show the live status line; band reserves a blank row when empty", () => {
|
|
121
|
+
const box = previewShape("box", 40, th, { model: "GLM-5.3", cwd: "ceulen", pct: 42 }).map(plain);
|
|
122
|
+
assert.ok(box[0]!.includes("GLM-5.3") && box[0]!.includes("ceulen") && box[0]!.includes("42%"), box[0]);
|
|
123
|
+
const bandEmpty = previewShape("band", 40, th).map(plain);
|
|
124
|
+
assert.equal(bandEmpty[0]!.trim(), "", "band row reserved (blank) without data");
|
|
125
|
+
const bandFull = previewShape("band", 40, th, { model: "M" }).map(plain);
|
|
126
|
+
assert.ok(bandFull[0]!.includes("╭─") && bandFull[0]!.includes("M"), bandFull[0]);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it("rules carry pi's scroll indicator when lines are hidden", () => {
|
|
130
|
+
// pi shape: top/bottom rules; hidden comes from the editor. Preview has 0,
|
|
131
|
+
// so assert the helper through a ctx-shaped shape def directly.
|
|
132
|
+
const def = shapeById("pi");
|
|
133
|
+
const line = def.top!({ w: 30, hidden: 4, theme: th })!;
|
|
134
|
+
assert.ok(plain(line).includes(" ↑ 4 more "), plain(line));
|
|
135
|
+
assert.equal(visibleWidth(line), 30);
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
describe("status line + surface fill", () => {
|
|
140
|
+
it("statusLine joins model · dir · pct with theme styling and skips blanks", () => {
|
|
141
|
+
assert.equal(plain(statusLine({ model: "M", cwd: "d", pct: 42.6 }, th)), "M · d · 43%");
|
|
142
|
+
assert.equal(plain(statusLine({ model: "M" }, th)), "M");
|
|
143
|
+
assert.equal(statusLine({}, th), "");
|
|
144
|
+
assert.equal(statusLine(undefined, th), "");
|
|
145
|
+
assert.equal(plain(statusLine({ model: " ", cwd: "x" }, th)), "x", "blank segments skipped");
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
it("surfacePainter re-applies the fill across nested resets (cursor glyph)", () => {
|
|
149
|
+
const painted = surfacePainter("\x1b[44m")(`a\x1b[0mb`);
|
|
150
|
+
assert.equal(painted, "\x1b[44ma\x1b[0m\x1b[44mb\x1b[39m\x1b[49m");
|
|
151
|
+
assert.equal(surfacePainter("")("plain"), "plain", "empty prefix is a no-op");
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
describe("theme adapter", () => {
|
|
156
|
+
it("shapeTheme maps pi Theme colors and keeps bg through getBgAnsi", async () => {
|
|
157
|
+
const { shapeTheme } = await import("../lib/shapes.ts");
|
|
158
|
+
const seen: string[] = [];
|
|
159
|
+
const t = {
|
|
160
|
+
fg: (c: string, s: string) => {
|
|
161
|
+
seen.push(c);
|
|
162
|
+
return `<${c}>${s}`;
|
|
163
|
+
},
|
|
164
|
+
getBgAnsi: () => "\x1b[48m",
|
|
165
|
+
getFgAnsi: () => "\x1b[38m",
|
|
166
|
+
inverse: (s: string) => `[inv]${s}`,
|
|
167
|
+
};
|
|
168
|
+
const st: ShapeTheme = shapeTheme(t as never);
|
|
169
|
+
assert.equal(st.accent("x"), "<accent>x");
|
|
170
|
+
assert.equal(st.border("x"), "<borderMuted>x");
|
|
171
|
+
assert.ok(st.fill("x").includes("\x1b[48m"), "bg applied");
|
|
172
|
+
assert.equal(st.inverse("x"), "[inv]x");
|
|
173
|
+
assert.ok(seen.length > 0, "theme colors requested through fg()");
|
|
174
|
+
});
|
|
175
|
+
});
|