pi-odd-worktree 3.15.1 → 3.16.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/README.md +48 -25
- package/extensions/odd-worktree-tools.ts +70 -212
- 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/session-auto-name-wiring.test.js +39 -0
- 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,627 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The customize rows for tool designs (S6, T9): one line per tool that HAS designs, in the `Cards`
|
|
3
|
+
* category, with the tool's own card as one value and each design as another. The selection is
|
|
4
|
+
* persisted per tool in the bridge's own store, and changing it repaints the cards already drawn
|
|
5
|
+
* through `requestRepaint()` — one differential frame, because the wrapper re-reads the live selection
|
|
6
|
+
* on every render pass (S13/T23: dropping the caches was the freeze).
|
|
7
|
+
*
|
|
8
|
+
* Asserted through the row contract the host receives — `buildRows` — and the store file, so the
|
|
9
|
+
* test reads what the menu reads.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import assert from "node:assert/strict";
|
|
13
|
+
import { mkdtempSync, rmSync } from "node:fs";
|
|
14
|
+
import { tmpdir } from "node:os";
|
|
15
|
+
import { join } from "node:path";
|
|
16
|
+
import test from "node:test";
|
|
17
|
+
|
|
18
|
+
import { snapshotProviders } from "../../lib/shell-api/bus.ts";
|
|
19
|
+
import { resetNoticesForTests } from "../../lib/shell-api/notices.ts";
|
|
20
|
+
import { resetPluginLinesForTests } from "../../lib/shell-api/plugin-lines.ts";
|
|
21
|
+
import { getRepaintDiagnostics, resetRepaintForTests, setRepaintHost } from "../../lib/shell-api/repaint.ts";
|
|
22
|
+
import { buildRows, resetRowBuildStateForTests } from "../../lib/shell-api/rows.ts";
|
|
23
|
+
import { createStore, resetStoreStateForTests } from "../../lib/shell-api/store.ts";
|
|
24
|
+
import {
|
|
25
|
+
TOOL_DESIGN_DEFAULT_LABEL,
|
|
26
|
+
TOOL_DESIGN_NATIVE,
|
|
27
|
+
getToolDesignLineSelection,
|
|
28
|
+
getToolDesignSelection,
|
|
29
|
+
registerToolDesign,
|
|
30
|
+
resetToolDesignsForTests,
|
|
31
|
+
setToolDesignSelection,
|
|
32
|
+
toolNamesWithDesigns,
|
|
33
|
+
} from "../../lib/shell-api/tool-designs.ts";
|
|
34
|
+
import {
|
|
35
|
+
TOOL_DESIGN_ROWS_PROVIDER_ID,
|
|
36
|
+
installToolDesignRows,
|
|
37
|
+
resetToolDesignRowStateForTests,
|
|
38
|
+
} from "../../lib/shell-api/tool-design-rows.ts";
|
|
39
|
+
import {
|
|
40
|
+
resetToolDesignWiringForTests,
|
|
41
|
+
toolDesignResolver,
|
|
42
|
+
} from "../../lib/shell-api/tool-design-wiring.ts";
|
|
43
|
+
import type { CustomizeRow, ToolDesignRegistration, ToolDesignScope } from "../../lib/shell-api/types.ts";
|
|
44
|
+
|
|
45
|
+
let configHome: string;
|
|
46
|
+
let previousConfigHome: string | undefined;
|
|
47
|
+
|
|
48
|
+
test.before(() => {
|
|
49
|
+
configHome = mkdtempSync(join(tmpdir(), "gsb-tool-design-rows-"));
|
|
50
|
+
previousConfigHome = process.env.GENTLE_PI_CONFIG_HOME;
|
|
51
|
+
process.env.GENTLE_PI_CONFIG_HOME = configHome;
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test.after(() => {
|
|
55
|
+
if (previousConfigHome === undefined) delete process.env.GENTLE_PI_CONFIG_HOME;
|
|
56
|
+
else process.env.GENTLE_PI_CONFIG_HOME = previousConfigHome;
|
|
57
|
+
rmSync(configHome, { recursive: true, force: true });
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
test.beforeEach(() => {
|
|
61
|
+
rmSync(join(configHome, "gentle-shell-bridge"), { recursive: true, force: true });
|
|
62
|
+
resetToolDesignsForTests();
|
|
63
|
+
resetToolDesignRowStateForTests();
|
|
64
|
+
resetToolDesignWiringForTests();
|
|
65
|
+
resetRepaintForTests();
|
|
66
|
+
resetStoreStateForTests();
|
|
67
|
+
resetNoticesForTests();
|
|
68
|
+
resetPluginLinesForTests();
|
|
69
|
+
resetRowBuildStateForTests();
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
const bashHeading: ToolDesignRegistration = {
|
|
73
|
+
tool: "bash",
|
|
74
|
+
id: "loon.bash-heading",
|
|
75
|
+
label: "bash heading",
|
|
76
|
+
description: "heads the card with bash instead of the host's $ prompt",
|
|
77
|
+
preview: () => ({ title: "Cards · bash heading", sample: "bash ls -la" }),
|
|
78
|
+
apply: (lines) => [...lines],
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const bashFramed: ToolDesignRegistration = {
|
|
82
|
+
tool: "bash",
|
|
83
|
+
id: "loon.bash-framed",
|
|
84
|
+
label: "bash framed",
|
|
85
|
+
apply: (lines) => [...lines],
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
const writeBadge: ToolDesignRegistration = {
|
|
89
|
+
tool: "write",
|
|
90
|
+
id: "loon.write-badge",
|
|
91
|
+
label: "write badge",
|
|
92
|
+
apply: (lines) => [...lines],
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
/** The rows one menu build receives, with the design bus installed. */
|
|
96
|
+
const rowsForBuild = (): CustomizeRow[] => {
|
|
97
|
+
installToolDesignRows();
|
|
98
|
+
return buildRows({ theme: undefined, configHome }).rows;
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
/** The lines the host would draw for one setting, reading `current()` at render time. */
|
|
102
|
+
const toggleLines = (rows: readonly CustomizeRow[]): string[] => {
|
|
103
|
+
const lines: string[] = [];
|
|
104
|
+
let index = 0;
|
|
105
|
+
while (index < rows.length) {
|
|
106
|
+
const setting = rows[index].choice?.setting;
|
|
107
|
+
if (setting === undefined) {
|
|
108
|
+
index += 1;
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
let end = index;
|
|
112
|
+
while (end + 1 < rows.length && rows[end + 1].choice?.setting === setting) end += 1;
|
|
113
|
+
const marks = rows
|
|
114
|
+
.slice(index, end + 1)
|
|
115
|
+
.map((row) => `${row.choice?.current() === true ? "●" : "○"} ${row.choice?.value ?? ""}`);
|
|
116
|
+
lines.push(`${setting} ${marks.join(" ")}`);
|
|
117
|
+
index = end + 1;
|
|
118
|
+
}
|
|
119
|
+
return lines;
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
const recordingTui = (): { calls: string[]; host: Record<string, unknown> } => {
|
|
123
|
+
const calls: string[] = [];
|
|
124
|
+
return {
|
|
125
|
+
calls,
|
|
126
|
+
host: {
|
|
127
|
+
terminal: {},
|
|
128
|
+
invalidate: () => calls.push("invalidate"),
|
|
129
|
+
requestRender: () => calls.push("requestRender"),
|
|
130
|
+
},
|
|
131
|
+
};
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
test("T9: the bridge owns one rows provider, and it is internal plumbing", () => {
|
|
135
|
+
installToolDesignRows();
|
|
136
|
+
assert.deepEqual(
|
|
137
|
+
snapshotProviders().map((provider) => provider.id),
|
|
138
|
+
[TOOL_DESIGN_ROWS_PROVIDER_ID],
|
|
139
|
+
);
|
|
140
|
+
installToolDesignRows();
|
|
141
|
+
assert.equal(snapshotProviders().length, 1, "installing twice replaces the provider in place");
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
test("T9: no design means NO line: a session that never registers one is unchanged", () => {
|
|
145
|
+
assert.deepEqual(rowsForBuild(), []);
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
test("T9: one Cards line per tool that has designs, in Cards, values are the tool's card + designs", () => {
|
|
149
|
+
registerToolDesign(bashHeading);
|
|
150
|
+
registerToolDesign(bashFramed);
|
|
151
|
+
registerToolDesign(writeBadge);
|
|
152
|
+
|
|
153
|
+
const rows = rowsForBuild();
|
|
154
|
+
|
|
155
|
+
assert.ok(rows.every((row) => row.category === "Cards"), "every row belongs to Cards");
|
|
156
|
+
const lines = toggleLines(rows);
|
|
157
|
+
assert.equal(lines.length, 2, "one line per tool, never one line per design");
|
|
158
|
+
assert.match(lines[0], /^Card bash /u, "the line is named after the Cards category, then the tool");
|
|
159
|
+
assert.match(lines[0], /● default/u, "the tool's own card is the default selection");
|
|
160
|
+
assert.match(lines[0], /○ bash heading/u);
|
|
161
|
+
assert.match(lines[0], /○ bash framed/u);
|
|
162
|
+
assert.match(lines[1], /^Card write /u);
|
|
163
|
+
assert.match(lines[1], /○ write badge/u);
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
test("T9: the selection persists PER TOOL and moves the bullet on the next build", async () => {
|
|
167
|
+
registerToolDesign(bashHeading);
|
|
168
|
+
registerToolDesign(writeBadge);
|
|
169
|
+
|
|
170
|
+
const rows = rowsForBuild();
|
|
171
|
+
const pick = rows.find((row) => row.choice?.value === "bash heading");
|
|
172
|
+
assert.ok(pick?.action !== undefined);
|
|
173
|
+
await pick.action({ input: async () => undefined, confirm: async () => true, capture: async () => undefined });
|
|
174
|
+
|
|
175
|
+
assert.equal(getToolDesignSelection("bash"), "loon.bash-heading");
|
|
176
|
+
assert.equal(getToolDesignSelection("write"), TOOL_DESIGN_NATIVE, "the other tool did not move");
|
|
177
|
+
|
|
178
|
+
const after = toggleLines(rowsForBuild());
|
|
179
|
+
assert.match(after[0], /○ default ● bash heading/u);
|
|
180
|
+
assert.match(after[1], /● default ○ write badge/u);
|
|
181
|
+
|
|
182
|
+
// And the way back to the host's own card.
|
|
183
|
+
const native = rowsForBuild().find(
|
|
184
|
+
(row) => row.choice?.value === TOOL_DESIGN_DEFAULT_LABEL && row.choice?.setting === "Card bash",
|
|
185
|
+
);
|
|
186
|
+
assert.ok(native?.action !== undefined);
|
|
187
|
+
await native.action({ input: async () => undefined, confirm: async () => true, capture: async () => undefined });
|
|
188
|
+
assert.equal(getToolDesignSelection("bash"), TOOL_DESIGN_NATIVE);
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
test("T9: changing the value repaints the drawn cards through requestRepaint()", async () => {
|
|
192
|
+
registerToolDesign(bashHeading);
|
|
193
|
+
const tui = recordingTui();
|
|
194
|
+
setRepaintHost(tui.host);
|
|
195
|
+
|
|
196
|
+
const rows = rowsForBuild();
|
|
197
|
+
const pick = rows.find((row) => row.choice?.value === "bash heading");
|
|
198
|
+
assert.ok(pick?.action !== undefined);
|
|
199
|
+
await pick.action({ input: async () => undefined, confirm: async () => true, capture: async () => undefined });
|
|
200
|
+
|
|
201
|
+
assert.deepEqual(
|
|
202
|
+
tui.calls,
|
|
203
|
+
["requestRender"],
|
|
204
|
+
"one differential frame; no cache is dropped and no forced full redraw is asked for",
|
|
205
|
+
);
|
|
206
|
+
assert.equal(getRepaintDiagnostics().lastTrigger?.outcome, "repainted");
|
|
207
|
+
|
|
208
|
+
// Pressing the value that is already selected costs no frame.
|
|
209
|
+
tui.calls.length = 0;
|
|
210
|
+
await pick.action({ input: async () => undefined, confirm: async () => true, capture: async () => undefined });
|
|
211
|
+
assert.deepEqual(tui.calls, []);
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
test("T9: a design's own preview is the preview its value shows", () => {
|
|
215
|
+
registerToolDesign(bashHeading);
|
|
216
|
+
registerToolDesign(writeBadge);
|
|
217
|
+
|
|
218
|
+
const rows = rowsForBuild();
|
|
219
|
+
const heading = rows.find((row) => row.choice?.value === "bash heading");
|
|
220
|
+
assert.ok(heading?.preview !== undefined);
|
|
221
|
+
assert.deepEqual(heading.preview(), { title: "Cards · bash heading", sample: "bash ls -la" });
|
|
222
|
+
|
|
223
|
+
const badge = rows.find((row) => row.choice?.value === "write badge");
|
|
224
|
+
assert.ok(badge?.preview !== undefined);
|
|
225
|
+
assert.match(badge.preview().title, /write badge/u);
|
|
226
|
+
|
|
227
|
+
const native = rows.find(
|
|
228
|
+
(row) => row.choice?.value === TOOL_DESIGN_DEFAULT_LABEL && row.choice?.setting === "Card bash",
|
|
229
|
+
);
|
|
230
|
+
assert.ok(native?.preview !== undefined);
|
|
231
|
+
assert.match(native.preview().sample, /own card|host/u);
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
test("T9: the line name starts with `Card `, then the tool's readable words, like the host's rows", () => {
|
|
235
|
+
registerToolDesign({ ...writeBadge, tool: "bash", id: "loon.bash-heading" });
|
|
236
|
+
registerToolDesign({ ...writeBadge, tool: "lsp_navigation", id: "loon.lsp" });
|
|
237
|
+
registerToolDesign({ ...writeBadge, tool: "mcp__engram__mem_save", id: "loon.mcp" });
|
|
238
|
+
registerToolDesign({ ...writeBadge, tool: "···", id: "loon.nowords" });
|
|
239
|
+
|
|
240
|
+
const settings = [...new Set(rowsForBuild().map((row) => row.choice?.setting))];
|
|
241
|
+
|
|
242
|
+
assert.deepEqual(settings, [
|
|
243
|
+
"Card bash",
|
|
244
|
+
"Card lsp navigation",
|
|
245
|
+
// The TAIL of a long name is the specific part: `Card mcp engram` would say nothing.
|
|
246
|
+
"Card mem save",
|
|
247
|
+
// A tool name that derives to no words keeps the fallback word.
|
|
248
|
+
"Card tool",
|
|
249
|
+
]);
|
|
250
|
+
for (const setting of settings) {
|
|
251
|
+
assert.ok(setting !== undefined);
|
|
252
|
+
const words = setting.trim().split(/\s+/u);
|
|
253
|
+
assert.ok(words.length >= 1 && words.length <= 3, `${setting} must stay within the word limit`);
|
|
254
|
+
assert.equal(words[0], "Card", `${setting} must start with the Cards category's word`);
|
|
255
|
+
assert.match(setting, /^Card( [a-z0-9]+){1,2}$/u, `${setting} is capitalised like Card style`);
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
test("T9: two tools that clamp to the same name stay distinct and pass the shape rule", () => {
|
|
260
|
+
registerToolDesign({ ...writeBadge, tool: "mcp__alpha__mem_save", id: "loon.alpha" });
|
|
261
|
+
registerToolDesign({ ...writeBadge, tool: "mcp__beta__mem_save", id: "loon.beta" });
|
|
262
|
+
|
|
263
|
+
const settings = [...new Set(rowsForBuild().map((row) => row.choice?.setting))];
|
|
264
|
+
|
|
265
|
+
assert.deepEqual(settings, ["Card mem save", "Card mem 2"], "the second gets the lowest free ordinal");
|
|
266
|
+
for (const setting of settings) {
|
|
267
|
+
assert.ok(setting !== undefined);
|
|
268
|
+
assert.ok(
|
|
269
|
+
setting.trim().split(/\s+/u).length <= 3,
|
|
270
|
+
`${setting} must stay within the row-name word limit`,
|
|
271
|
+
);
|
|
272
|
+
assert.doesNotMatch(setting, /[.:|/\\[\](){}→]/u, `${setting} must carry no structural mark`);
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
test("T9: the persisted value and the stored selection are unchanged by the line's name", async () => {
|
|
277
|
+
registerToolDesign(bashHeading);
|
|
278
|
+
|
|
279
|
+
const pick = rowsForBuild().find((row) => row.choice?.value === "bash heading");
|
|
280
|
+
assert.ok(pick?.action !== undefined);
|
|
281
|
+
assert.equal(pick.choice?.setting, "Card bash", "the line is named after the card, not after the store");
|
|
282
|
+
await pick.action({ input: async () => undefined, confirm: async () => true, capture: async () => undefined });
|
|
283
|
+
|
|
284
|
+
// The VALUE is the design's id and the store is still keyed by the TOOL name: only the visible
|
|
285
|
+
// line name moved.
|
|
286
|
+
assert.equal(getToolDesignSelection("bash"), "loon.bash-heading");
|
|
287
|
+
const stored = createStore("bridge-tool-designs").get<Record<string, unknown>>("selections", {});
|
|
288
|
+
assert.deepEqual(stored, { bash: "loon.bash-heading" });
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
test("T9: a tool name keeps a row name that passes the shape rule, even a long MCP one", () => {
|
|
292
|
+
registerToolDesign({ ...writeBadge, tool: "mcp__engram__mem_save", id: "loon.mcp" });
|
|
293
|
+
registerToolDesign({ ...writeBadge, tool: "mcp__engram__mem_search", id: "loon.mcp2" });
|
|
294
|
+
|
|
295
|
+
installToolDesignRows();
|
|
296
|
+
const result = buildRows({ theme: undefined, configHome });
|
|
297
|
+
const rows = result.rows;
|
|
298
|
+
|
|
299
|
+
assert.deepEqual(result.failures, []);
|
|
300
|
+
const settings = new Set(rows.map((row) => row.choice?.setting));
|
|
301
|
+
assert.equal(settings.size, 2, "two long tool names still produce two distinct lines");
|
|
302
|
+
for (const setting of settings) {
|
|
303
|
+
assert.ok(setting !== undefined);
|
|
304
|
+
assert.ok(
|
|
305
|
+
setting.trim().split(/\s+/u).length <= 3,
|
|
306
|
+
`${setting} must stay within the row-name word limit`,
|
|
307
|
+
);
|
|
308
|
+
assert.doesNotMatch(setting, /[.:|/\\[\](){}→]/u, `${setting} must carry no structural mark`);
|
|
309
|
+
}
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
test("T9: tools are listed in a deterministic order, and only tools with designs appear", () => {
|
|
313
|
+
registerToolDesign(writeBadge);
|
|
314
|
+
registerToolDesign(bashHeading);
|
|
315
|
+
|
|
316
|
+
const rows = rowsForBuild();
|
|
317
|
+
assert.deepEqual(toolNamesWithDesigns(), ["write", "bash"], "registration order");
|
|
318
|
+
assert.deepEqual(
|
|
319
|
+
[...new Set(rows.map((row) => row.choice?.setting))].length,
|
|
320
|
+
2,
|
|
321
|
+
);
|
|
322
|
+
assert.equal(
|
|
323
|
+
rows.some((row) => row.choice?.setting.toLowerCase().includes("edit")),
|
|
324
|
+
false,
|
|
325
|
+
"a tool with no design has no line",
|
|
326
|
+
);
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
test("S2: picking a design in the menu repaints the card ALREADY on screen", async () => {
|
|
330
|
+
// The user's words: the choice has to change "tanto las antiguas como posteriores", not only new
|
|
331
|
+
// cards. Pi resolves the renderers once, when the card is constructed, and re-renders that same
|
|
332
|
+
// component on every frame — so this is the card the menu action must reach.
|
|
333
|
+
const hostCard = ["│ $ ls -la", "│ total 4"];
|
|
334
|
+
const component = { render: (_width: number): string[] => [...hostCard] };
|
|
335
|
+
const renderers = { renderShell: "default", renderCall: () => component };
|
|
336
|
+
|
|
337
|
+
registerToolDesign({
|
|
338
|
+
...bashHeading,
|
|
339
|
+
apply: (lines) => lines.map((line) => line.replace("$ ", "bash ")),
|
|
340
|
+
});
|
|
341
|
+
const resolved = toolDesignResolver("bash", () => renderers);
|
|
342
|
+
assert.ok(resolved !== undefined);
|
|
343
|
+
const card = (resolved.renderCall as () => typeof component)();
|
|
344
|
+
assert.deepEqual(card.render(80), hostCard, "no design selected: the host's own bytes");
|
|
345
|
+
|
|
346
|
+
const pick = rowsForBuild().find((row) => row.choice?.value === "bash heading");
|
|
347
|
+
assert.ok(pick?.action !== undefined);
|
|
348
|
+
await pick.action({ input: async () => undefined, confirm: async () => true, capture: async () => undefined });
|
|
349
|
+
|
|
350
|
+
assert.deepEqual(
|
|
351
|
+
card.render(80),
|
|
352
|
+
["│ bash ls -la", "│ total 4"],
|
|
353
|
+
"the SAME, already-drawn card now shows the design the menu selected",
|
|
354
|
+
);
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
test("PRESERVE: the provider's rows stay empty after the last design is disposed", () => {
|
|
358
|
+
const dispose = registerToolDesign(bashHeading);
|
|
359
|
+
assert.equal(rowsForBuild().length, 2, "native + one design");
|
|
360
|
+
dispose();
|
|
361
|
+
assert.deepEqual(rowsForBuild(), []);
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
// ---------------------------------------------------------------------------------------------
|
|
365
|
+
// S1/S3/S8 — ONE line over several tools
|
|
366
|
+
// ---------------------------------------------------------------------------------------------
|
|
367
|
+
|
|
368
|
+
const grouped = (overrides: Partial<ToolDesignRegistration> = {}): ToolDesignRegistration => ({
|
|
369
|
+
line: "tools",
|
|
370
|
+
tools: ["bash", "write"],
|
|
371
|
+
id: "loon.tools-activity",
|
|
372
|
+
label: "activity",
|
|
373
|
+
apply: (lines) => [...lines],
|
|
374
|
+
...overrides,
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
test("S1/S3: a grouped line is ONE Cards row named after the line, default first, then its designs", () => {
|
|
378
|
+
registerToolDesign(grouped({ tools: ["bash", "write"] }));
|
|
379
|
+
registerToolDesign(grouped({ id: "loon.tools-complete", label: "complete", tools: ["bash"] }));
|
|
380
|
+
|
|
381
|
+
const lines = toggleLines(rowsForBuild());
|
|
382
|
+
assert.deepEqual(
|
|
383
|
+
lines,
|
|
384
|
+
["Card tools ● default ○ activity ○ complete"],
|
|
385
|
+
"one line for bash, write and read, named by the line, in registration order",
|
|
386
|
+
);
|
|
387
|
+
});
|
|
388
|
+
|
|
389
|
+
test("S7: picking a grouped value stores it per LINE under `lines`, never per tool", async () => {
|
|
390
|
+
registerToolDesign(grouped());
|
|
391
|
+
|
|
392
|
+
const pick = rowsForBuild().find((row) => row.choice?.value === "activity");
|
|
393
|
+
assert.ok(pick?.action !== undefined);
|
|
394
|
+
await pick.action({ input: async () => undefined, confirm: async () => true, capture: async () => undefined });
|
|
395
|
+
|
|
396
|
+
assert.equal(getToolDesignLineSelection("line", "tools"), "loon.tools-activity");
|
|
397
|
+
assert.equal(getToolDesignSelection("bash"), TOOL_DESIGN_NATIVE, "the per-tool map did not move");
|
|
398
|
+
assert.deepEqual(
|
|
399
|
+
createStore("bridge-tool-designs").get("selections", {}),
|
|
400
|
+
{ $lines: { tools: "loon.tools-activity" } },
|
|
401
|
+
"the choice is keyed by the line, inside the ONE stored value (one read per frame)",
|
|
402
|
+
);
|
|
403
|
+
});
|
|
404
|
+
|
|
405
|
+
test("S8: a line and a tool that derive the same name are told apart by the ordinal rule", () => {
|
|
406
|
+
registerToolDesign({ ...writeBadge, tool: "tools", id: "loon.tool-tools", label: "tools card" });
|
|
407
|
+
registerToolDesign(grouped({ tools: ["bash"], id: "loon.line-tools", label: "line tools" }));
|
|
408
|
+
|
|
409
|
+
const settings = [...new Set(rowsForBuild().map((row) => row.choice?.setting))];
|
|
410
|
+
assert.deepEqual(
|
|
411
|
+
settings,
|
|
412
|
+
["Card tools", "Card tools 2"],
|
|
413
|
+
"the same name from a tool and a line gets the lowest free ordinal, deterministically",
|
|
414
|
+
);
|
|
415
|
+
});
|
|
416
|
+
|
|
417
|
+
test("D5: a design preview is drawn as ONE row: the sample's first line only", () => {
|
|
418
|
+
registerToolDesign({
|
|
419
|
+
...bashHeading,
|
|
420
|
+
preview: () => ({ title: "Cards · multiline", sample: "first row\nsecond row" }),
|
|
421
|
+
});
|
|
422
|
+
|
|
423
|
+
const row = rowsForBuild().find((candidate) => candidate.choice?.value === bashHeading.label);
|
|
424
|
+
assert.ok(row?.preview !== undefined);
|
|
425
|
+
assert.deepEqual(row.preview(), { title: "Cards · multiline", sample: "first row" });
|
|
426
|
+
});
|
|
427
|
+
|
|
428
|
+
test("D3: a legacy per-tool value appears selected on the line once the tool joins it", () => {
|
|
429
|
+
setToolDesignSelection("bash", "loon.tools-activity");
|
|
430
|
+
registerToolDesign(grouped({ tools: ["bash", "write"] }));
|
|
431
|
+
|
|
432
|
+
assert.match(toggleLines(rowsForBuild())[0] ?? "", /○ default ● activity/u);
|
|
433
|
+
});
|
|
434
|
+
|
|
435
|
+
// ---------------------------------------------------------------------------------------------
|
|
436
|
+
// S13 — a scoped line shows its scope inside the SAME preview row
|
|
437
|
+
// ---------------------------------------------------------------------------------------------
|
|
438
|
+
|
|
439
|
+
const SCOPE_DESCRIPTION = "paths under skills/ or odd/";
|
|
440
|
+
|
|
441
|
+
/** The second line the consumer asked for: scoped to the paths its own `apply` recognises. */
|
|
442
|
+
const scopedDiff: ToolDesignRegistration = {
|
|
443
|
+
line: "diff",
|
|
444
|
+
tools: ["write"],
|
|
445
|
+
id: "loon.diff",
|
|
446
|
+
label: "diff card",
|
|
447
|
+
description: "draws a write as an IDE diff",
|
|
448
|
+
scope: {
|
|
449
|
+
description: SCOPE_DESCRIPTION,
|
|
450
|
+
matches: (call) =>
|
|
451
|
+
typeof (call.args as { path?: unknown } | undefined)?.path === "string",
|
|
452
|
+
},
|
|
453
|
+
preview: () => ({ title: "Cards · diff card", sample: "◂ diff src/index.ts" }),
|
|
454
|
+
apply: (lines) => [...lines],
|
|
455
|
+
};
|
|
456
|
+
|
|
457
|
+
const unscopedLine: ToolDesignRegistration = {
|
|
458
|
+
line: "tools",
|
|
459
|
+
tools: ["read"],
|
|
460
|
+
id: "loon.tools-activity",
|
|
461
|
+
label: "activity",
|
|
462
|
+
apply: (lines) => [...lines],
|
|
463
|
+
};
|
|
464
|
+
|
|
465
|
+
test("S13: one row per line, `default` first, and a scoped line's description in its preview row", () => {
|
|
466
|
+
registerToolDesign(unscopedLine);
|
|
467
|
+
registerToolDesign(scopedDiff);
|
|
468
|
+
|
|
469
|
+
const rows = rowsForBuild();
|
|
470
|
+
assert.deepEqual(
|
|
471
|
+
toggleLines(rows),
|
|
472
|
+
["Card tools ● default ○ activity", "Card diff ● default ○ diff card"],
|
|
473
|
+
"row count, row order and naming are unchanged: one line per line, default first",
|
|
474
|
+
);
|
|
475
|
+
|
|
476
|
+
for (const value of [TOOL_DESIGN_DEFAULT_LABEL, "diff card"]) {
|
|
477
|
+
const row = rows.find(
|
|
478
|
+
(candidate) => candidate.choice?.setting === "Card diff" && candidate.choice?.value === value,
|
|
479
|
+
);
|
|
480
|
+
assert.ok(row?.preview !== undefined, `${value}: a scoped line's values keep their preview`);
|
|
481
|
+
const preview = row.preview();
|
|
482
|
+
assert.match(preview.sample, /paths under skills\/ or odd\//u, `${value}: the scope is explained`);
|
|
483
|
+
assert.doesNotMatch(preview.sample, /\n/u, `${value}: still ONE row, never a second line`);
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
// The unscoped line's values say nothing about a scope they do not have.
|
|
487
|
+
for (const row of rows.filter((candidate) => candidate.choice?.setting === "Card tools")) {
|
|
488
|
+
assert.ok(row.preview !== undefined);
|
|
489
|
+
assert.doesNotMatch(row.preview().sample, /scope/u);
|
|
490
|
+
}
|
|
491
|
+
});
|
|
492
|
+
|
|
493
|
+
test("S13/PRESERVE: an unscoped registry's rows are byte-identical to today", () => {
|
|
494
|
+
registerToolDesign(bashHeading);
|
|
495
|
+
registerToolDesign(writeBadge);
|
|
496
|
+
|
|
497
|
+
const shown = rowsForBuild().map((row) => ({
|
|
498
|
+
setting: row.choice?.setting,
|
|
499
|
+
value: row.choice?.value,
|
|
500
|
+
preview: row.preview?.(),
|
|
501
|
+
}));
|
|
502
|
+
assert.deepEqual(shown, [
|
|
503
|
+
{
|
|
504
|
+
setting: "Card bash",
|
|
505
|
+
value: TOOL_DESIGN_DEFAULT_LABEL,
|
|
506
|
+
preview: {
|
|
507
|
+
title: "Cards · Card bash",
|
|
508
|
+
sample: "Card bash: the host's own card for bash, untouched",
|
|
509
|
+
},
|
|
510
|
+
},
|
|
511
|
+
{
|
|
512
|
+
setting: "Card bash",
|
|
513
|
+
value: "bash heading",
|
|
514
|
+
preview: { title: "Cards · bash heading", sample: "bash ls -la" },
|
|
515
|
+
},
|
|
516
|
+
{
|
|
517
|
+
setting: "Card write",
|
|
518
|
+
value: TOOL_DESIGN_DEFAULT_LABEL,
|
|
519
|
+
preview: {
|
|
520
|
+
title: "Cards · Card write",
|
|
521
|
+
sample: "Card write: the host's own card for write, untouched",
|
|
522
|
+
},
|
|
523
|
+
},
|
|
524
|
+
{
|
|
525
|
+
setting: "Card write",
|
|
526
|
+
value: "write badge",
|
|
527
|
+
preview: {
|
|
528
|
+
title: "Cards · write badge",
|
|
529
|
+
sample: "write badge: rewrites the rows write's own card produced",
|
|
530
|
+
},
|
|
531
|
+
},
|
|
532
|
+
]);
|
|
533
|
+
});
|
|
534
|
+
|
|
535
|
+
// ---------------------------------------------------------------------------------------------
|
|
536
|
+
// S19 — the scope belongs to the (line, tool) CLAIM, not to the line
|
|
537
|
+
// ---------------------------------------------------------------------------------------------
|
|
538
|
+
|
|
539
|
+
/** The consumer's rule: a path under `skills/` or `odd/`. */
|
|
540
|
+
const CONSUMER_SCOPE: ToolDesignScope = {
|
|
541
|
+
description: SCOPE_DESCRIPTION,
|
|
542
|
+
matches: (call) => typeof (call.args as { path?: unknown } | undefined)?.path === "string",
|
|
543
|
+
};
|
|
544
|
+
|
|
545
|
+
/** `Card tools`: bash for EVERY call, write/edit only under skills/ or odd/ — ONE shared scope. */
|
|
546
|
+
const toolsLine: ToolDesignRegistration = {
|
|
547
|
+
line: "tools",
|
|
548
|
+
tools: ["bash", "write", "edit"],
|
|
549
|
+
id: "odd-worktree.tools",
|
|
550
|
+
label: "tools activity",
|
|
551
|
+
scopes: { write: CONSUMER_SCOPE, edit: CONSUMER_SCOPE },
|
|
552
|
+
apply: (lines) => [...lines],
|
|
553
|
+
};
|
|
554
|
+
|
|
555
|
+
/** `Card diff`: write and edit for EVERY call — the generic claim the specific one wins over. */
|
|
556
|
+
const diffLine: ToolDesignRegistration = {
|
|
557
|
+
line: "diff",
|
|
558
|
+
tools: ["write", "edit"],
|
|
559
|
+
id: "odd-worktree.diff",
|
|
560
|
+
label: "diff card",
|
|
561
|
+
apply: (lines) => [...lines],
|
|
562
|
+
};
|
|
563
|
+
|
|
564
|
+
test("S19/S13: a line's scopes stay inside ONE preview row, today's text when they share one", () => {
|
|
565
|
+
registerToolDesign(toolsLine);
|
|
566
|
+
registerToolDesign(diffLine);
|
|
567
|
+
|
|
568
|
+
const rows = rowsForBuild();
|
|
569
|
+
assert.deepEqual(
|
|
570
|
+
toggleLines(rows),
|
|
571
|
+
["Card tools ● default ○ tools activity", "Card diff ● default ○ diff card"],
|
|
572
|
+
"still one row per line, `default` first",
|
|
573
|
+
);
|
|
574
|
+
|
|
575
|
+
// ONE scope object across the line's scoped claims: today's text, byte for byte.
|
|
576
|
+
const toolsRows = rows.filter((row) => row.choice?.setting === "Card tools");
|
|
577
|
+
assert.equal(toolsRows.length, 2);
|
|
578
|
+
for (const row of toolsRows) {
|
|
579
|
+
assert.ok(row.preview !== undefined);
|
|
580
|
+
const preview = row.preview();
|
|
581
|
+
assert.ok(
|
|
582
|
+
preview.sample.endsWith(` — scope: ${SCOPE_DESCRIPTION}`),
|
|
583
|
+
`${row.choice?.value}: today's text, byte for byte`,
|
|
584
|
+
);
|
|
585
|
+
assert.doesNotMatch(preview.sample, /;/u, `${row.choice?.value}: one scope, not a per-tool list`);
|
|
586
|
+
assert.doesNotMatch(preview.sample, /\n/u, `${row.choice?.value}: still ONE row`);
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
// The unscoped line says nothing about a scope it does not have.
|
|
590
|
+
for (const row of rows.filter((candidate) => candidate.choice?.setting === "Card diff")) {
|
|
591
|
+
assert.ok(row.preview !== undefined);
|
|
592
|
+
assert.doesNotMatch(row.preview().sample, /scope/u);
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
// Several DISTINCT scopes on one line: one ` — scope: <tools>: <description>` per scope, joined by
|
|
596
|
+
// `; `, still inside the SAME preview row.
|
|
597
|
+
registerToolDesign({
|
|
598
|
+
line: "per-tool",
|
|
599
|
+
tools: ["bash", "write"],
|
|
600
|
+
id: "loon.per-tool",
|
|
601
|
+
label: "per tool",
|
|
602
|
+
scopes: {
|
|
603
|
+
bash: { description: "bash commands", matches: () => true },
|
|
604
|
+
write: { description: "paths under odd/", matches: () => true },
|
|
605
|
+
},
|
|
606
|
+
apply: (lines) => [...lines],
|
|
607
|
+
});
|
|
608
|
+
|
|
609
|
+
const perTool = rowsForBuild().filter((row) => row.choice?.setting === "Card per tool");
|
|
610
|
+
assert.equal(perTool.length, 2, "one row per value, `default` first");
|
|
611
|
+
const expected = " — scope: bash: bash commands; — scope: write: paths under odd/";
|
|
612
|
+
const nativePreview = perTool[0].preview?.();
|
|
613
|
+
assert.ok(nativePreview !== undefined);
|
|
614
|
+
assert.equal(
|
|
615
|
+
nativePreview.sample,
|
|
616
|
+
`Card per tool: the host's own card for bash, write, untouched${expected}`,
|
|
617
|
+
);
|
|
618
|
+
const designPreview = perTool[1].preview?.();
|
|
619
|
+
assert.ok(designPreview !== undefined);
|
|
620
|
+
assert.equal(
|
|
621
|
+
designPreview.sample,
|
|
622
|
+
`per tool: rewrites the rows the bash, write cards produced${expected}`,
|
|
623
|
+
"each scope names the tools it covers, on the same single row",
|
|
624
|
+
);
|
|
625
|
+
assert.doesNotMatch(designPreview.sample, /\n/u, "never a second row");
|
|
626
|
+
});
|
|
627
|
+
|