The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.
TypeScript 3d-modelingagent-frameworkagent-harnessai-agentscadclaude-codecodexcoding-agentsdeveloper-toolsesp32game-developmentmcp-servermulti-agentopen-hardwareopencodeopenharnesspcbroboticsterminaltmux
fix(mujoco): preserve keyboard control and focus navigation (#228)
Deeb0b97e97b929
diff --git a/store/viewers/mujoco-viewer/public/index.html b/store/viewers/mujoco-viewer/public/index.htmlindex cd198e1ec..536fca010 100644--- a/store/viewers/mujoco-viewer/public/index.html+++ b/store/viewers/mujoco-viewer/public/index.html@@ -30,7 +30,7 @@<button type="button" class="icon" id="btn-camera" title="Camera" aria-haspopup="true"><svg viewBox="0 0 20 20"><rect x="2" y="5.5" width="11.5" height="9" rx="2"/><path d="m13.5 9 4.5-2.5v7L13.5 11"/></svg></button>- <button type="button" class="icon" id="btn-panel" title="Controls and model (Tab)">+ <button type="button" class="icon" id="btn-panel" title="Controls and model (N)"><svg viewBox="0 0 20 20"><rect x="2.5" y="3.5" width="15" height="13" rx="2"/><path d="M12.5 3.5v13"/></svg></button><button type="button" class="icon" id="btn-help" title="Shortcuts (?)">@@ -172,7 +172,7 @@<div><kbd>−</kbd> <kbd>=</kbd> slower / faster</div><div><kbd>S</kbd> <kbd>R</kbd> <kbd>V</kbd> simulate / replay / video</div><div><kbd>Enter</kbd> simulate from this frame</div>- <div><kbd>Tab</kbd> controls panel</div>+ <div><kbd>N</kbd> controls panel · <kbd>Tab</kbd> next control</div><div>double-click: select a body</div><div><kbd>⌘</kbd>/<kbd>Ctrl</kbd> + drag: push it</div><div><kbd>⌘</kbd>/<kbd>Ctrl</kbd> + <kbd>⇧</kbd> + drag: twist it</div>diff --git a/store/viewers/mujoco-viewer/public/main.js b/store/viewers/mujoco-viewer/public/main.jsindex ee4f7ed2d..9de83db3a 100644--- a/store/viewers/mujoco-viewer/public/main.js+++ b/store/viewers/mujoco-viewer/public/main.js@@ -1121,6 +1121,8 @@ function wire() {layout()// Existing transport, model and actuator actions return to the original simulation first.for (const id of ['transport', 'modes']) $(id).addEventListener('pointerdown', () => experiments?.leave(), true)+ // Native button activation from Enter/Space does not send pointerdown.+ for (const id of ['transport', 'modes']) $(id).addEventListener('click', () => experiments?.leave(), true)$('btn-experiment').addEventListener('click', () => {touch(); togglePanel(true); panel.showTab('experiment'); experiments.open()})@@ -1189,12 +1191,13 @@ function wire() {addEventListener('keydown', (e) => {const target = e.target- if (target instanceof HTMLSelectElement || (target instanceof HTMLInputElement && target.type !== 'range' && target.type !== 'checkbox')) return+ // Keep native focus navigation, range adjustment and button activation intact.+ // Transport shortcuts belong to the scene, not to a focused form control.+ if (e.key === 'Tab' || target.closest?.('input, select, textarea, [contenteditable="true"]')) return+ if ([' ', 'Enter'].includes(e.key) && target.closest?.('button, a[href], [role="button"]')) returnif (!$('help').hidden && e.key === 'Escape') { $('help').hidden = true; return }if (e.metaKey || e.ctrlKey || e.altKey) returnif (experiments?.active && [' ', 'ArrowRight', 'ArrowLeft', 'Backspace', 'Delete', 'Enter', 's', 'r', 'v'].includes(e.key)) experiments.leave()- // Tab belongs to normal focus navigation while the experiment form is open.- if (panel.tab === 'experiment' && !$('panel').hidden && e.key === 'Tab') returnconst key = e.keyconst handled = () => { e.preventDefault(); touch() }if (key === ' ') { handled(); if (state.mode !== 'video') { state.playing = !state.playing; renderTransport() } else { const v = $('video'); v.paused ? v.play() : v.pause() } }@@ -1202,7 +1205,6 @@ function wire() {else if (key === 'ArrowLeft') { if (state.mode === 'replay') { handled(); state.playing = false; showFrame(Math.ceil(state.cursor) - 1) } }else if (key === 'Backspace' || key === 'Delete') { handled(); $('btn-reset').click() }else if (key === 'Enter') { if (state.mode === 'replay') { handled(); simulateFrom(state.cursor) } }- else if (key === 'Tab') { handled(); togglePanel() }else if (key === 'Escape') { handled(); closeMenus(); if (stage.cameraMode.kind !== 'free') { stage.setCameraMode({ kind: 'free' }, engine); renderCameraChip(); renderChip() } else select(-1) }else if (key === '-' || key === '_') { handled(); stepSpeed(1) }else if (key === '=' || key === '+') { handled(); stepSpeed(-1) }@@ -1214,6 +1216,7 @@ function wire() {const lower = key.toLowerCase()const toggles = { c: 'contactpoint', f: 'contactforce', j: 'joint', u: 'actuator', v: null, m: 'com', i: 'inertia', t: 'transparent', w: 'wireframe', h: 'shadows', e: 'reflections', k: 'skybox' }if (lower === 's') { handled(); setMode('sim') }+ else if (lower === 'n') { handled(); togglePanel() }else if (lower === 'r') { handled(); setMode('replay') }else if (lower === 'v') { handled(); setMode('video') }else if (lower === 'b') { handled(); const order = ['none', 'body', 'site', 'world']; setVis('frame', order[(order.indexOf(vis.frame) + 1) % order.length]); toast(`Frames: ${vis.frame}`, 1200) }diff --git a/store/viewers/mujoco-viewer/public/panel.js b/store/viewers/mujoco-viewer/public/panel.jsindex ad7809763..ca690bc56 100644--- a/store/viewers/mujoco-viewer/public/panel.js+++ b/store/viewers/mujoco-viewer/public/panel.js@@ -79,6 +79,7 @@ export class Panel {const val = el('span', 'val', '0')const slider = document.createElement('input')slider.type = 'range'+ slider.setAttribute('aria-label', `Control ${a.name}`)const [lo, hi] = a.range ?? [-1, 1]slider.min = String(lo); slider.max = String(hi); slider.step = String((hi - lo) / 1000)slider.addEventListener('input', () => this.h.onCtrl(a.id, Number(slider.value)))@@ -107,6 +108,7 @@ export class Panel {if (j.type === 'hinge' || j.type === 'slide') {slider = document.createElement('input')slider.type = 'range'+ slider.setAttribute('aria-label', `Pose ${j.name}`)const [lo, hi] = j.range ?? (j.type === 'hinge' ? [-Math.PI, Math.PI] : [-1, 1])slider.min = String(lo); slider.max = String(hi); slider.step = String((hi - lo) / 1000)slider.addEventListener('input', () => this.h.onJoint(j.id, Number(slider.value)))diff --git a/store/viewers/mujoco-viewer/test/env.test.mjs b/store/viewers/mujoco-viewer/test/env.test.mjsindex a02a82c3a..ae26310f2 100644--- a/store/viewers/mujoco-viewer/test/env.test.mjs+++ b/store/viewers/mujoco-viewer/test/env.test.mjs@@ -65,16 +65,19 @@ test('a workspace that is not there yet: watching fails, and every answer is stiassert.deepEqual(await viewer.stop(), { code: 0, signal: null })})-test('a watcher that fails after starting is logged, and one that names no path announces nothing', async () => {+test('a watcher that fails after starting is logged, and one that names no path announces nothing', async (t) => {const ws = join(root, 'ws-watch')mkdirSync(ws)const failing = await startViewer({ env: { HARNESS_WORKSPACE: ws, TEST_WATCH: 'error' } })+ t.after(() => failing.stop())await eventually(() => failing.output().includes('[mujoco-viewer] watch error: the watcher stopped'), 'the watch error in the log')assert.equal((await failing.get('/')).status, 200, 'the pane keeps serving')assert.deepEqual(await failing.stop(), { code: 0, signal: null })const nameless = await startViewer({ env: { HARNESS_WORKSPACE: ws, TEST_WATCH: 'null-name' } })+ t.after(() => nameless.stop())const feed = await nameless.events()+ t.after(() => feed.close())assert.equal(await feed.until((b) => changedPaths(b) !== null, 800), null, 'no change event for a change with no path')feed.close()assert.deepEqual(await nameless.stop(), { code: 0, signal: null })diff --git a/store/viewers/mujoco-viewer/test/preload.mjs b/store/viewers/mujoco-viewer/test/preload.mjsindex 8c1c2e06b..7401e3f12 100644--- a/store/viewers/mujoco-viewer/test/preload.mjs+++ b/store/viewers/mujoco-viewer/test/preload.mjs@@ -6,6 +6,7 @@// TEST_WATCH=error|null-name the workspace watcher, as the OS sometimes hands it over: failing after// it started, or reporting changes (every 50 ms) without saying which pathimport fs from 'node:fs'+import { EventEmitter } from 'node:events'import { syncBuiltinESMExports } from 'node:module'const timers = new Map(String(process.env.TEST_TIMERS ?? '').split(',').filter(Boolean).map((pair) => pair.split('=').map(Number)))@@ -20,9 +21,19 @@ const mode = process.env.TEST_WATCHif (mode) {const watch = fs.watchfs.watch = (...args) => {+ if (mode === 'null-name') {+ // Isolate the event under test. A real macOS watcher can also announce the+ // newly created workspace itself, even though this test changes no files.+ const watcher = new EventEmitter()+ const listener = args.at(-1)+ if (typeof listener === 'function') watcher.on('change', listener)+ const timer = setInterval(() => watcher.emit('change', 'rename', null), 50)+ timer.unref()+ watcher.close = () => clearInterval(timer)+ return watcher+ }const watcher = watch(...args)if (mode === 'error') setTimeout(() => watcher.emit('error', new Error('the watcher stopped')), 50)- if (mode === 'null-name') setInterval(() => watcher.emit('change', 'rename', null), 50).unref()return watcher}syncBuiltinESMExports()diff --git a/store/viewers/mujoco-viewer/test/robot-experiments.browser.mjs b/store/viewers/mujoco-viewer/test/robot-experiments.browser.mjsindex cb5b4e6f3..d5f03415e 100644--- a/store/viewers/mujoco-viewer/test/robot-experiments.browser.mjs+++ b/store/viewers/mujoco-viewer/test/robot-experiments.browser.mjs@@ -24,7 +24,16 @@ try {await page.waitForFunction(() => window.__mujocoViewer?.state?.traj?.ctrl && window.__mujocoViewer.engine?.info, null, { timeout: 60_000 })await page.locator('#btn-play').click()await page.locator('#btn-reset').click()- await page.locator('#btn-experiment').click()+ const hip = page.getByRole('slider', { name: 'Control FL_hip', exact: true })+ const controlBefore = Number(await hip.inputValue())+ const timeBefore = await page.evaluate(() => __mujocoViewer.engine.data.time)+ await hip.press('ArrowRight')+ assert.ok(Number(await hip.inputValue()) > controlBefore, 'arrow keys adjust the focused actuator')+ assert.equal(await page.evaluate(() => __mujocoViewer.engine.data.time), timeBefore, 'adjusting a control does not step the simulation')+ await hip.press('Tab')+ assert.equal(await page.locator('#panel').isVisible(), true, 'Tab moves focus without closing the controls')+ await page.locator('#btn-reset').click()+ await page.locator('#btn-experiment').press('Space')await page.locator('#experiment-duration').selectOption('1')await page.locator('[data-experiment=push]').click()await page.waitForFunction(() => __mujocoViewer.experiments.previewing, null, { timeout: 60_000 })