mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-11-20 04:59:34 +01:00
fix(web): forward the wheel for any CLI whose registry entry asks for it
The browser's wheel gate named copilot, pi, claude and codex by id, so a custom clis.json entry that launches pi could not get the forwarding #771 gave stock pi: after every tab switch or reload its wheel scrolled an empty local buffer. Copying pi's altScreen value into such an entry made it worse, since the mouse DECSETs were then stripped while nothing forwarded the wheel. The server now publishes every CLI's wheelForward rule as window.__codemanWheelForward, disabled entries included because disabling a CLI leaves its sessions running, and _shouldForwardWheelToApp reads that map instead of an id list. Stock CLIs keep their behaviour, and a minVersion that is not MAJOR.MINOR.PATCH refuses forwarding instead of comparing as passing.
This commit is contained in:
1 parent
e99b42c387
commit
3ef4900e60
12 files changed
+251
-37
No files matched your search
@@ -435,7 +435,6 @@ describe('declared-for-later fields', () => {
|
||||
const DECLARED_FOR_LATER = [
|
||||
'accent',
|
||||
'capabilities.echo',
|
||||
'capabilities.wheelForward',
|
||||
'capabilities.keyboardAccessory',
|
||||
'capabilities.maxFrameBytes',
|
||||
// The Docker credential-seeding path still reads its own CRED_STORES table: this shape
|
||||
|
||||
@@ -181,6 +181,78 @@ describe('WebServer.renderIndexHtml', () => {
|
||||
}
|
||||
});
|
||||
|
||||
it('injects the wheelForward rules of every CLI that forwards, custom and disabled entries included', async () => {
|
||||
// A custom clis.json entry shaped like pi (its mouse DECSETs stripped, wheel forwarded)
|
||||
// must reach the browser's gate by its own id, and every `never` stays out. A DISABLED
|
||||
// entry stays in: disabling a CLI never ends its running sessions, so a fullscreen copilot
|
||||
// tab opened before the switch still needs its wheel after a reload (and an entry enabled
|
||||
// after the page loaded already has its rule). A solo window scrolls a terminal too, so
|
||||
// it gets the same map.
|
||||
const path = dataPath('clis.json');
|
||||
mkdirSync(dirname(path), { recursive: true });
|
||||
const custom = {
|
||||
label: 'PiD',
|
||||
shortBadge: 'PL',
|
||||
accent: '#6b7280',
|
||||
enabled: true,
|
||||
order: 120,
|
||||
kind: 'agent',
|
||||
discovery: { binaries: ['pi-locked'], searchDirs: [], install: { command: {} } },
|
||||
launch: { params: {}, variants: [{ id: 'default', args: [{ lit: 'pi-locked' }] }] },
|
||||
env: { exports: [], unset: [], tmuxSetenvKeys: [], dockerExecEnvNames: [], allowedPrefixes: [], allowedKeys: [] },
|
||||
capabilities: {
|
||||
external: true,
|
||||
requiresMux: true,
|
||||
hooks: 'none',
|
||||
transcript: 'none',
|
||||
altScreen: 'strip-mux-and-mouse',
|
||||
echo: { policy: 'buffer', anchor: { kind: 'none' } },
|
||||
wheelForward: { mode: 'always' },
|
||||
keyboardAccessory: 'agent',
|
||||
privilegedCommandGate: false,
|
||||
startMode: 'interactive',
|
||||
stripInkBloat: false,
|
||||
ralph: false,
|
||||
respawn: false,
|
||||
effort: false,
|
||||
agentSkillInjection: false,
|
||||
statusLineTelemetry: false,
|
||||
model: { source: 'none' },
|
||||
privilegedParams: [],
|
||||
privilegedEnvKeys: [],
|
||||
gates: {},
|
||||
customModelInjection: { kind: 'unsupported' },
|
||||
},
|
||||
overlays: {},
|
||||
};
|
||||
writeFileSync(
|
||||
path,
|
||||
JSON.stringify({ schemaVersion: 1, clis: { copilot: { enabled: false }, 'pi-locked': custom } }),
|
||||
{
|
||||
mode: 0o600,
|
||||
}
|
||||
);
|
||||
reloadCliRegistry();
|
||||
try {
|
||||
for (const solo of [undefined, 'sess-123']) {
|
||||
const { server } = makeServer({});
|
||||
const html = await render(server, solo);
|
||||
const match = html.match(/window\.__codemanWheelForward=(\{[^<]*\});/);
|
||||
expect(match, String(solo)).not.toBeNull();
|
||||
expect(JSON.parse(match![1])).toEqual({
|
||||
claude: { mode: 'version-gated', minVersion: '2.1.187' },
|
||||
codex: { mode: 'always' },
|
||||
pi: { mode: 'always' },
|
||||
copilot: { mode: 'always' },
|
||||
'pi-locked': { mode: 'always' },
|
||||
});
|
||||
}
|
||||
} finally {
|
||||
writeFileSync(path, JSON.stringify({ clis: {} }, null, 2), { mode: 0o600 });
|
||||
reloadCliRegistry();
|
||||
}
|
||||
});
|
||||
|
||||
it('injects the keyboard-hold modes from the keyboardHold capability: inline Claude, never full-height codex', async () => {
|
||||
for (const solo of [undefined, 'sess-123']) {
|
||||
const { server } = makeServer();
|
||||
|
||||
@@ -117,7 +117,9 @@ describe('WebServer index.html <title> templating (#82)', () => {
|
||||
// Likewise the page-key mode list: an array, possibly empty, always injected.
|
||||
.replace(/<script>window\.__codemanTranscriptPageKeys=\[.*?\];<\/script>\n/, '')
|
||||
// And the keyboard-hold mode list, built the same way.
|
||||
.replace(/<script>window\.__codemanKeyboardHoldModes=\[.*?\];<\/script>\n/, '');
|
||||
.replace(/<script>window\.__codemanKeyboardHoldModes=\[.*?\];<\/script>\n/, '')
|
||||
// And the wheel-forwarding rules: an object keyed by run mode, always injected.
|
||||
.replace(/<script>window\.__codemanWheelForward=\{.*?\};<\/script>\n/, '');
|
||||
const beforeTitle = rawTemplate.split('<title>Codeman</title>')[0];
|
||||
const afterTitle = rawTemplate.split('<title>Codeman</title>')[1];
|
||||
expect(html.startsWith(beforeTitle)).toBe(true);
|
||||
|
||||
@@ -28,8 +28,19 @@ import { STOCK_CLIS } from '../src/config/cli-registry/stock.js';
|
||||
*/
|
||||
const PAGE_KEY_MODES = STOCK_CLIS.filter((e) => e.capabilities.transcriptPageKeys === true).map((e) => e.id);
|
||||
|
||||
/**
|
||||
* The run modes that take the wheel as SGR reports, read off the shipped registry the way
|
||||
* the server builds `__codemanWheelForward` (every `wheelForward` other than `never`).
|
||||
*/
|
||||
const WHEEL_FORWARD = Object.fromEntries(
|
||||
STOCK_CLIS.filter((e) => e.capabilities.wheelForward.mode !== 'never').map((e) => [e.id, e.capabilities.wheelForward])
|
||||
);
|
||||
|
||||
function loadTerminalUiHarness(
|
||||
windowGlobals: Record<string, unknown> = { __codemanTranscriptPageKeys: PAGE_KEY_MODES }
|
||||
windowGlobals: Record<string, unknown> = {
|
||||
__codemanTranscriptPageKeys: PAGE_KEY_MODES,
|
||||
__codemanWheelForward: WHEEL_FORWARD,
|
||||
}
|
||||
) {
|
||||
const CodemanApp = function CodemanApp(this: any) {};
|
||||
const logs: string[] = [];
|
||||
@@ -927,6 +938,96 @@ describe('pi wheel forwarding (fullscreen by default since 1.0.0)', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('wheel forwarding read from the injected wheelForward map, for any CLI id', () => {
|
||||
// A custom CLI (clis.json, e.g. a pi wrapper under its own id) that strips its mouse
|
||||
// DECSETs gets `cliMouseTracking` like pi, but the gate used to name copilot and pi by id,
|
||||
// so its wheel hit an empty local buffer after every tab switch or reload.
|
||||
function customApp(
|
||||
map: Record<string, unknown> | undefined,
|
||||
session: { mode: string; cliMouseTracking?: boolean; cliVersion?: string }
|
||||
) {
|
||||
const globals: Record<string, unknown> = { __codemanTranscriptPageKeys: PAGE_KEY_MODES };
|
||||
if (map) globals.__codemanWheelForward = map;
|
||||
const { app } = loadTerminalUiHarness(globals);
|
||||
app.activeSessionId = 'sess-1';
|
||||
app.sessions = new Map([['sess-1', session]]);
|
||||
app.terminal = {
|
||||
rows: 36,
|
||||
modes: { mouseTrackingMode: 'none' },
|
||||
buffer: { active: { type: 'normal', viewportY: 0, baseY: 0, length: 36 } },
|
||||
};
|
||||
return app;
|
||||
}
|
||||
|
||||
it('forwards a custom id the map lists as always, only while it tracks the mouse', () => {
|
||||
const map = { 'pi-locked': { mode: 'always' } };
|
||||
const tracking = customApp(map, { mode: 'pi-locked', cliMouseTracking: true });
|
||||
expect(tracking._shouldForwardWheelToApp({ shiftKey: false })).toBe(true);
|
||||
expect(tracking._shouldForwardWheelToApp({ shiftKey: true })).toBe(false);
|
||||
expect(customApp(map, { mode: 'pi-locked', cliMouseTracking: false })._shouldForwardWheelToApp({})).toBe(false);
|
||||
expect(customApp(map, { mode: 'pi-locked' })._shouldForwardWheelToApp({})).toBe(false);
|
||||
});
|
||||
|
||||
it('applies a version-gated rule to a custom id: at or above minVersion only, unknown version never', () => {
|
||||
const map = { 'my-cli': { mode: 'version-gated', minVersion: '2.0.0' } };
|
||||
const at = (cliVersion?: string) =>
|
||||
customApp(map, { mode: 'my-cli', cliMouseTracking: true, cliVersion })._shouldForwardWheelToApp({});
|
||||
expect(at('1.9.9')).toBe(false);
|
||||
expect(at('2.0.0')).toBe(true);
|
||||
expect(at('2.0.1')).toBe(true);
|
||||
expect(at(undefined)).toBe(false);
|
||||
});
|
||||
|
||||
it('a version-gated rule whose minVersion is not three numbers forwards nothing, whatever the CLI version', () => {
|
||||
// The schema takes any string up to 20 characters. A minimum that cannot be read as
|
||||
// MAJOR.MINOR.PATCH must refuse, the conservative answer an unreadable session version gets.
|
||||
for (const minVersion of ['', '0', '2.0', '1.2.3.4', '0.bad.999', 'x.y.z', '2..0', '+2.0.0', '0x1.0.0']) {
|
||||
const app = customApp(
|
||||
{ 'my-cli': { mode: 'version-gated', minVersion } },
|
||||
{ mode: 'my-cli', cliMouseTracking: true, cliVersion: '9.9.9' }
|
||||
);
|
||||
expect(app._shouldForwardWheelToApp({}), JSON.stringify(minVersion)).toBe(false);
|
||||
}
|
||||
// A well-formed minimum keeps working, a leading `v` and surrounding spaces included.
|
||||
for (const minVersion of ['9.9.9', 'v2.0.0', ' 2.0.0 ']) {
|
||||
const app = customApp(
|
||||
{ 'my-cli': { mode: 'version-gated', minVersion } },
|
||||
{ mode: 'my-cli', cliMouseTracking: true, cliVersion: '9.9.9' }
|
||||
);
|
||||
expect(app._shouldForwardWheelToApp({}), JSON.stringify(minVersion)).toBe(true);
|
||||
}
|
||||
});
|
||||
|
||||
it('a version-gated rule with no minVersion (the schema allows it) forwards nothing and does not throw', () => {
|
||||
const app = customApp(
|
||||
{ 'my-cli': { mode: 'version-gated' } },
|
||||
{ mode: 'my-cli', cliMouseTracking: true, cliVersion: '9.9.9' }
|
||||
);
|
||||
expect(app._shouldForwardWheelToApp({})).toBe(false);
|
||||
});
|
||||
|
||||
it('never forwards an id the map leaves out, and nothing at all from a page rendered without the map', () => {
|
||||
expect(
|
||||
customApp(
|
||||
{ 'pi-locked': { mode: 'always' } },
|
||||
{ mode: 'other', cliMouseTracking: true }
|
||||
)._shouldForwardWheelToApp({})
|
||||
).toBe(false);
|
||||
for (const mode of ['claude', 'codex', 'copilot', 'pi']) {
|
||||
expect(
|
||||
customApp(undefined, { mode, cliMouseTracking: true, cliVersion: '9.9.9' })._shouldForwardWheelToApp({}),
|
||||
mode
|
||||
).toBe(false);
|
||||
}
|
||||
});
|
||||
|
||||
it('a map entry of mode never forwards, even for a stock id', () => {
|
||||
expect(
|
||||
customApp({ pi: { mode: 'never' } }, { mode: 'pi', cliMouseTracking: true })._shouldForwardWheelToApp({})
|
||||
).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('the paging gates asked for another pane (a TerminalTile)', () => {
|
||||
it('exports the paging math, and the primary pane runs on it', () => {
|
||||
const { app, sent, windowRef } = hollowApp();
|
||||
|
||||
@@ -49,6 +49,11 @@ const fetchMock = vi.fn();
|
||||
*/
|
||||
const PAGE_KEY_MODES = STOCK_CLIS.filter((e) => e.capabilities.transcriptPageKeys === true).map((e) => e.id);
|
||||
|
||||
/** The wheel-forwarding rules, read off the registry as the server builds `window.__codemanWheelForward`. */
|
||||
const WHEEL_FORWARD = Object.fromEntries(
|
||||
STOCK_CLIS.filter((e) => e.capabilities.wheelForward.mode !== 'never').map((e) => [e.id, e.capabilities.wheelForward])
|
||||
);
|
||||
|
||||
/**
|
||||
* The clock both panes read gesture gaps from (`performance.now()`). Real time by
|
||||
* default; a test that needs a pause or a burst moves it by hand.
|
||||
@@ -62,6 +67,7 @@ function loadContext() {
|
||||
removeEventListener: vi.fn(),
|
||||
CodemanBase: { base: '' },
|
||||
__codemanTranscriptPageKeys: PAGE_KEY_MODES,
|
||||
__codemanWheelForward: WHEEL_FORWARD,
|
||||
};
|
||||
const context = vm.createContext({
|
||||
console: { ...console, log: vi.fn(), debug: vi.fn() },
|
||||
|
||||
@@ -2,6 +2,12 @@ import { readFileSync } from 'node:fs';
|
||||
import { resolve } from 'node:path';
|
||||
import vm from 'node:vm';
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { STOCK_CLIS } from '../src/config/cli-registry/stock.js';
|
||||
|
||||
/** The wheel-forwarding rules, read off the registry as the server builds `window.__codemanWheelForward`. */
|
||||
const WHEEL_FORWARD = Object.fromEntries(
|
||||
STOCK_CLIS.filter((e) => e.capabilities.wheelForward.mode !== 'never').map((e) => [e.id, e.capabilities.wheelForward])
|
||||
);
|
||||
|
||||
function loadTerminalUiHarness() {
|
||||
const CodemanApp = function CodemanApp(this: any) {};
|
||||
@@ -10,7 +16,7 @@ function loadTerminalUiHarness() {
|
||||
let activeElement: unknown = null;
|
||||
// The module hangs its constants off window (CodemanTerminalInput) and the URL branch of
|
||||
// the link provider opens through window.open, so tests need a handle on the same object.
|
||||
const windowRef: Record<string, any> = {};
|
||||
const windowRef: Record<string, any> = { __codemanWheelForward: WHEEL_FORWARD };
|
||||
const context = vm.createContext({
|
||||
window: windowRef,
|
||||
document: {
|
||||
|
||||
Reference in new issue
Block a user