mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-11-20 04:59:34 +01:00
Merge #831: the wheel is forwarded for any CLI whose registry entry asks for it
The wheel gate reads each CLI's wheelForward rule from the registry (window.__codemanWheelForward) instead of a list of ids, so a custom full-screen CLI in clis.json can opt in.
This commit is contained in:
commit
923db64a10
13 files changed
+259
-41
No files matched your search
@@ -303,8 +303,8 @@ const CLAUDE: CliEntry = {
|
||||
transcript: 'claude-jsonl',
|
||||
altScreen: 'strip-full',
|
||||
echo: { policy: 'buffer', anchor: { kind: 'glyph', glyph: '❯', offset: 2 } },
|
||||
// Declared-for-later: the live rule (`_shouldForwardWheelToApp`, terminal-ui.js) is this version
|
||||
// AND the server-published `cliMouseTracking` flag (#498), so wiring this field up needs both.
|
||||
// Read by `_shouldForwardWheelToApp` (terminal-ui.js) through `window.__codemanWheelForward`;
|
||||
// forwarding also needs the server-published `cliMouseTracking` flag (#498).
|
||||
wheelForward: { mode: 'version-gated', minVersion: '2.1.187' },
|
||||
// A repaint-mode Claude pane keeps no local history, so when the wheel is not
|
||||
// forwarded (older CLI, inline renderer, the local-scrollback opt-out) a scroll is
|
||||
@@ -1926,8 +1926,8 @@ const COPILOT: CliEntry = {
|
||||
// (`cliMouseTracking`). Same shape and reason as opencode. The wheel keeps working because
|
||||
// `_shouldForwardWheelToApp` forwards it as SGR reports while the CLI is tracking.
|
||||
altScreen: 'strip-mux-and-mouse',
|
||||
// Forwards the wheel as SGR reports while the CLI is tracking the mouse, at any version
|
||||
// (`_shouldForwardWheelToApp` in terminal-ui.js has no version check for copilot).
|
||||
// Forwards the wheel as SGR reports while the CLI is tracking the mouse, at any version:
|
||||
// `always` is what keeps `_shouldForwardWheelToApp` (terminal-ui.js) from checking one.
|
||||
wheelForward: { mode: 'always' },
|
||||
// Pages its own transcript on PageUp/PageDown (1.0.95, measured in tmux: three PageUp moved
|
||||
// lines 109-140 to 010-042 and PageDown returned). This is the fallback when the
|
||||
|
||||
@@ -596,10 +596,18 @@ export interface CliCapabilities {
|
||||
* Forwarding the wheel to the CLI's own transcript. 'never' keeps local scrollback;
|
||||
* 'version-gated' forwards from `minVersion` on; 'always' forwards at any version. Either
|
||||
* forwarding mode applies only while the CLI has mouse tracking on (`cliMouseTracking`).
|
||||
* Read by the browser's gate (`_shouldForwardWheelToApp` in terminal-ui.js) through
|
||||
* `window.__codemanWheelForward`, which the server builds from this field for every CLI
|
||||
* whose mode is not `never`, disabled ones included (their running sessions stay open).
|
||||
*
|
||||
* ⚠️ Declared only: nothing reads this field yet (see DECLARED-FOR-LATER below). The browser's
|
||||
* gate is `_shouldForwardWheelToApp` in terminal-ui.js, which keeps its own hand-written
|
||||
* per-CLI rules, so changing a value here changes nothing until that gate is changed too.
|
||||
* ⚠️ 'version-gated' needs the session's `cliVersion`, and the server probes a version only
|
||||
* for an entry that declares `capabilities.gates` (`cliNeedsVersionProbe`, session.ts). An
|
||||
* entry without gates never forwards under 'version-gated', silently, so it uses 'always'.
|
||||
*
|
||||
* ⚠️ `cliMouseTracking` is only ever set for a CLI whose mouse DECSETs the server strips
|
||||
* (`altScreen: 'strip-full'` or `'strip-mux-and-mouse'`), so a forwarding mode on any other
|
||||
* `altScreen` never forwards: xterm keeps the DECSETs and encodes the wheel itself, until a
|
||||
* replay drops its mouse mode.
|
||||
*/
|
||||
wheelForward: { mode: 'never' | 'version-gated' | 'always'; minVersion?: string };
|
||||
/**
|
||||
@@ -1009,14 +1017,15 @@ export interface CliOverlays {
|
||||
/**
|
||||
* ⚠️ DECLARED-FOR-LATER: fields no code reads yet.
|
||||
*
|
||||
* `accent`, `overlays.credStore`, `capabilities.echo`, `capabilities.wheelForward`,
|
||||
* `capabilities.keyboardAccessory` and `capabilities.maxFrameBytes` all describe FRONTEND
|
||||
* `accent`, `overlays.credStore`, `capabilities.echo`, `capabilities.keyboardAccessory` and
|
||||
* `capabilities.maxFrameBytes` all describe FRONTEND
|
||||
* behaviour, and most of the frontend is deliberately untouched by the change that introduced
|
||||
* this registry — `app.js`, `terminal-ui.js`, `styles.css` and friends keep their own
|
||||
* hand-authored per-CLI rules, and moving them is its own piece of work with its own way of
|
||||
* being verified (a mobile/browser suite the CI gate cannot see). `shortBadge` graduated out of
|
||||
* this list (docs/cli-enable-disable-plan.md, Phase 2): `GET /api/clis` reads it for the
|
||||
* CLI-management Settings list.
|
||||
* CLI-management Settings list, and so did `capabilities.wheelForward`, which the browser's wheel
|
||||
* gate reads through `window.__codemanWheelForward`.
|
||||
*
|
||||
* They are declared now because each entry should describe its CLI completely, and because
|
||||
* transcribing them while the hand-written source is still on screen is when the values are
|
||||
|
||||
@@ -6016,12 +6016,16 @@ Object.assign(CodemanApp.prototype, {
|
||||
// True when a parsed CLI version string ('2.1.187' — banner-parsed on the
|
||||
// server, delivered via session:cliInfo / SessionState.cliVersion) is known
|
||||
// AND >= the minimum. Unknown or unparseable versions return false so
|
||||
// callers keep the conservative behavior.
|
||||
// callers keep the conservative behavior, and so does an unparseable
|
||||
// minimum: it can come from a user's clis.json (`wheelForward.minVersion`).
|
||||
_cliVersionAtLeast(version, minimum) {
|
||||
if (typeof version !== 'string') return false;
|
||||
const parts = version.trim().replace(/^v/, '').split('.').map(Number);
|
||||
if (parts.length !== 3 || parts.some((n) => !Number.isFinite(n))) return false;
|
||||
const min = minimum.split('.').map(Number);
|
||||
const parse = (v) => {
|
||||
const m = typeof v === 'string' ? /^v?(\d+)\.(\d+)\.(\d+)$/.exec(v.trim()) : null;
|
||||
return m ? m.slice(1).map(Number) : null;
|
||||
};
|
||||
const parts = parse(version);
|
||||
const min = parse(minimum);
|
||||
if (!parts || !min) return false;
|
||||
for (let i = 0; i < 3; i++) {
|
||||
if (parts[i] !== min[i]) return parts[i] > min[i];
|
||||
}
|
||||
@@ -6081,24 +6085,26 @@ Object.assign(CodemanApp.prototype, {
|
||||
if (mode && mode !== 'none') return false;
|
||||
const session = this.sessions?.get(target.sessionId || this.activeSessionId);
|
||||
const sessionMode = session?.mode || 'claude';
|
||||
// GitHub Copilot CLI (and pi, fullscreen by default) scrolls its own transcript on SGR wheel
|
||||
// reports (checked with xterm encoding them natively). Their mouse DECSETs are stripped
|
||||
// server-side so a drag selects locally (strip-mux-and-mouse), which also means xterm no longer
|
||||
// encodes the wheel: send the same reports by hand, but only while the CLI is actually tracking
|
||||
// the mouse. Not gated on a version. On Copilot a stale-false flag falls through to the
|
||||
// PageUp/PageDown fallback like claude's; pi has none on purpose (the `transcriptPageKeys` note
|
||||
// in stock.ts), so there the wheel does nothing until the flag is back.
|
||||
if (sessionMode === 'copilot' || sessionMode === 'pi') return session?.cliMouseTracking === true;
|
||||
if (sessionMode !== 'claude' && sessionMode !== 'codex') return false;
|
||||
if (sessionMode === 'claude' && !this._cliVersionAtLeast(session?.cliVersion, '2.1.187')) return false;
|
||||
// Only while Claude or Codex is actually listening for the mouse. Claude's
|
||||
// inline renderer (2.1.280 measured: alternate_on=0, mouse_any_flag=0), like
|
||||
// older inline Codex, keeps its transcript in real scrollback; SGR reports are
|
||||
// ignored, so forwarding made every swipe and wheel tick dead. Fullscreen
|
||||
// (CLAUDE_CODE_NO_FLICKER=1, or "tui": "fullscreen" in ~/.claude/settings.json)
|
||||
// turns on alt-screen + mode 1003/1006, which the server records as
|
||||
// cliMouseTracking. A stale-false flag after a server restart falls through
|
||||
// to _maybePageCliTranscript, so it never goes dead.
|
||||
// Which CLIs scroll their own transcript on SGR wheel reports is the registry's
|
||||
// `wheelForward` rule, published by renderIndexHtml as `window.__codemanWheelForward`
|
||||
// (id -> rule, `never` left out; a page rendered without the map forwards nothing), so a
|
||||
// custom clis.json entry shaped like pi forwards under its own id. Stock: claude from
|
||||
// 2.1.187 (older versions take the wheel as menu navigation), codex, copilot and pi always.
|
||||
// Their mouse DECSETs are stripped server-side (a drag selects locally), so xterm never
|
||||
// encodes the wheel for them and the reports are sent by hand.
|
||||
const rule = window.__codemanWheelForward?.[sessionMode];
|
||||
if (!rule || (rule.mode !== 'always' && rule.mode !== 'version-gated')) return false;
|
||||
if (rule.mode === 'version-gated' && !this._cliVersionAtLeast(session?.cliVersion, rule.minVersion)) return false;
|
||||
// Only while the CLI is actually listening for the mouse. Claude's inline renderer
|
||||
// (2.1.280 measured: alternate_on=0, mouse_any_flag=0), like older inline Codex and pi's
|
||||
// `tuiMode: regular`, keeps its transcript in real scrollback; SGR reports are ignored, so
|
||||
// forwarding made every swipe and wheel tick dead. Fullscreen (CLAUDE_CODE_NO_FLICKER=1, or
|
||||
// "tui": "fullscreen" in ~/.claude/settings.json; pi's default since 1.0.0) turns on
|
||||
// alt-screen + mouse tracking, which the server records as cliMouseTracking. That flag is
|
||||
// what survives a tab switch or reload, where xterm's own mouse mode does not. A stale-false
|
||||
// flag falls through to _maybePageCliTranscript (PageUp/PageDown for a CLI declaring
|
||||
// `transcriptPageKeys`); pi declares none on purpose (the note in stock.ts), so there the
|
||||
// wheel does nothing until the flag is back.
|
||||
if (session?.cliMouseTracking !== true) return false;
|
||||
// Deliberately NOT gated on _terminalViewportAtBottom(). It used to be, so
|
||||
// that leaving the bottom handed the wheel back to local scrollback and both
|
||||
|
||||
@@ -2170,6 +2170,19 @@ export class WebServer extends EventEmitter {
|
||||
'</head>',
|
||||
() => `<script>window.__codemanKeyboardHoldModes=${JSON.stringify(keyboardHoldClis)};</script>\n</head>`
|
||||
);
|
||||
// Which run modes take the wheel as SGR reports while they track the mouse
|
||||
// (`_shouldForwardWheelToApp`), keyed by id with the `wheelForward` rule itself, so a
|
||||
// custom clis.json entry shaped like pi forwards under its own id. `never` is left out.
|
||||
// Disabled entries are kept (`listClis`, not `enabledClis`): disabling a CLI never ends
|
||||
// its running sessions, and their wheel must keep working across a reload.
|
||||
// `minVersion` is a free string a user's clis.json sets, hence the script escaper.
|
||||
const wheelForwardClis = Object.fromEntries(
|
||||
listClis()
|
||||
.filter((entry) => entry.capabilities.wheelForward.mode !== 'never')
|
||||
.map((entry) => [entry.id, entry.capabilities.wheelForward])
|
||||
);
|
||||
const wheelForwardJson = escapeScriptJson(JSON.stringify(wheelForwardClis));
|
||||
html = html.replace('</head>', () => `<script>window.__codemanWheelForward=${wheelForwardJson};</script>\n</head>`);
|
||||
if (!soloSessionId && process.env.CODEMAN_GESTURE === '1') {
|
||||
html = html.replace('</head>', () => `<script>window.__codemanGestureAvailable=true;</script>\n</head>`);
|
||||
if (settings.gestureControlEnabled === true) {
|
||||
|
||||
Reference in new issue
Block a user