From 30f9d1204fc17c7a1d15256cc79c9c98c7d22165 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 2 Dec 2026 22:01:06 +0000 Subject: [PATCH] Agent Flow: the UFO keeps flying smoothly in low-performance mode (#420) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On battery Adrián's laptop dropped the scene to the render budget's 'static' verdict, and Agent Flow turned every hop off on it: the UFO jumped from building to building. Since #440 the city's height and floor tweens really run, and while they did the view re-laid out the legends, turn rings, delta caps and step label on every frame, enough extra work to cross the budget's threshold. - Only prefers-reduced-motion stops the flight now; a low frame-rate verdict keeps the hops (one transform per frame). - What rides on the roofs follows a growing city at ~11 Hz plus a last pass when it stops, instead of every frame. - Harness: stubs the render budget and checks that a forward step flies the main UFO through several in-between positions with no big jump, with the budget at 'full' and at 'static'. Fails on the old code. - Docs: ufo.md, test guide, CHANGELOG. --- apps/vscode-extension/CHANGELOG.md | 1 + .../agentFlowRuntime/modeLifecycle.js | 10 +++- .../agentFlowRuntime/viewController.js | 13 ++++- .../test/runners/run-agent-flow-harness.cjs | 57 +++++++++++++++++++ docs/agent-flow/test-guide.md | 1 + docs/agent-flow/ufo.md | 6 ++ 6 files changed, 84 insertions(+), 4 deletions(-) diff --git a/apps/vscode-extension/CHANGELOG.md b/apps/vscode-extension/CHANGELOG.md index c279ba16..4c4c4cf9 100644 --- a/apps/vscode-extension/CHANGELOG.md +++ b/apps/vscode-extension/CHANGELOG.md @@ -41,6 +41,7 @@ - Subagents fly a little lower than the main agent, so several UFOs never overlap; they are born from the main UFO and fly back to it when done. - The UFO dresses for what it is doing: the action's colour plus an accessory. Reading glasses on a read, a magnifying glass on a search, a hard hat on an edit (green on a new file), a beacon on a run (red if it fails), thought orbs while thinking, an hourglass while waiting for permission, antennas on a delegate. The rim ring and its lights change with it; the name tag keeps the agent's colour. - Each leg of the flight path is drawn in the colour of the action the UFO flew there to do. + - The UFO keeps flying smoothly when the scene drops to low-performance mode (for example a laptop on battery); only the system's reduced-motion setting turns the flight off. Legends and rings follow a growing building a few times a second instead of every frame. - **Drill-down: analyse any file or folder from inside the XR scene.** Pick a building or a district on the table, press **Analyze file** or **Analyze folder**, and the table switches to that analysis in place, on the same server, without reloading the scene. - Breadcrumb bar on the table's front edge: Back, Forward, Home and `project > folder > ... > current`. Any crumb jumps back up. - Fast jumps: each file's result is kept by content hash, as in the live re-analysis. A jump only sends to the analyzer the files with no result yet or that changed since; the files of the project analysis are never analysed again. diff --git a/apps/vscode-extension/templates/components/codexr/agent-flow/agentFlowRuntime/modeLifecycle.js b/apps/vscode-extension/templates/components/codexr/agent-flow/agentFlowRuntime/modeLifecycle.js index f1ce5a08..b021260c 100644 --- a/apps/vscode-extension/templates/components/codexr/agent-flow/agentFlowRuntime/modeLifecycle.js +++ b/apps/vscode-extension/templates/components/codexr/agent-flow/agentFlowRuntime/modeLifecycle.js @@ -65,14 +65,20 @@ refs.hint = null; } + function prefersReducedMotion() { + try { return root.matchMedia?.('(prefers-reduced-motion: reduce)')?.matches === true; } catch (error) { return false; } + } + function bindRenderBudget() { if (state.unsubscribeBudget) { return; } var budget = root.CodeXRRenderBudgetRuntime; if (!budget?.subscribe) { return; } // 'static' is both the low-frame-rate verdict and how prefers-reduced-motion - // arrives: no hops, no pulses, the probe jumps (the logo's rule). + // arrives. Only reduced motion stops the hops: a UFO that jumps from file + // to file because a few frames ran slow loses the story it tells (#420), + // and a hop costs one transform per frame. state.unsubscribeBudget = budget.subscribe(function (snapshot) { - var motion = !snapshot || snapshot.quality !== 'static'; + var motion = !(snapshot && snapshot.quality === 'static' && prefersReducedMotion()); if (motion === state.motion) { return; } state.motion = motion; if (!motion && view?.cityState) { diff --git a/apps/vscode-extension/templates/components/codexr/agent-flow/agentFlowRuntime/viewController.js b/apps/vscode-extension/templates/components/codexr/agent-flow/agentFlowRuntime/viewController.js index 75ff9ea7..0f166d4b 100644 --- a/apps/vscode-extension/templates/components/codexr/agent-flow/agentFlowRuntime/viewController.js +++ b/apps/vscode-extension/templates/components/codexr/agent-flow/agentFlowRuntime/viewController.js @@ -4,6 +4,7 @@ // component on the mounted root. var view = null; + var OVERLAY_FOLLOW_MS = 90; function registerComponent() { registerCityComponent(); @@ -223,7 +224,15 @@ var dt = Math.min(64, Math.max(0, Number(delta) || 16)); var camera = v.rootEl.sceneEl?.camera; var heightsMoving = v.city.tick(dt, time || 0); - if (heightsMoving && v.cityState) { + // What rides on the roofs (turn rings, delta caps, legend leaders, the + // step label) follows a growing city at OVERLAY_FOLLOW_MS, plus one last + // pass when it stops: every frame was enough work to drop the frame rate. + if (heightsMoving) { v.overlaysDirty = true; } + var followRoofs = !!v.overlaysDirty && !!v.cityState + && (!heightsMoving || Math.abs((time || 0) - (v.overlaysAt || 0)) >= OVERLAY_FOLLOW_MS); + if (followRoofs) { + v.overlaysDirty = heightsMoving; + v.overlaysAt = time || 0; updateTurnRings(v, v.cityState); updateDeltaCaps(v, v.cityState); // Leaders follow a roof that grows; the band itself only rises with the skyline. @@ -236,7 +245,7 @@ tickTower(v, dt); if (v.label?.el?.object3D?.visible) { faceYaw(v.label.el, camera); - if (heightsMoving && v.cityState) { updateFloatingLabel(v, v.cityState); } + if (followRoofs) { updateFloatingLabel(v, v.cityState); } } faceLegends(v, camera); followViewer(v); diff --git a/apps/vscode-extension/test/runners/run-agent-flow-harness.cjs b/apps/vscode-extension/test/runners/run-agent-flow-harness.cjs index 848dae58..5e0ba69b 100644 --- a/apps/vscode-extension/test/runners/run-agent-flow-harness.cjs +++ b/apps/vscode-extension/test/runners/run-agent-flow-harness.cjs @@ -87,6 +87,18 @@ async function runScenario(browser, port) { page.on('console', (message) => log(`${message.type()}: ${message.text()}`)); page.on('pageerror', (error) => log(`pageerror: ${error.message}\n${error.stack || ''}`)); await routeFonts(page); + // The scene's render budget, stubbed so the harness can hand Agent Flow a + // low-frame-rate verdict (see the smooth-flight check). + await page.addInitScript(() => { + const subscribers = new Set(); + let snapshot = { quality: 'full', averageFps: 60, frameTimeP95: 16.7, targetFps: 60, xrSession: false }; + window.CodeXRRenderBudgetRuntime = { + getSnapshot: () => ({ ...snapshot }), + subscribe: (fn) => { subscribers.add(fn); fn({ ...snapshot }); return () => subscribers.delete(fn); }, + start: () => {}, + __emit: (next) => { snapshot = { ...snapshot, ...next }; subscribers.forEach((fn) => fn({ ...snapshot })); }, + }; + }); await page.goto(`http://127.0.0.1:${port}/test/manual/agent-flow-harness.html?bust=${Date.now()}`, { waitUntil: 'domcontentloaded' }); await waitFor(page, () => window.CodeXRAgentFlowRuntime?.getState?.().active === true && window.CodeXRAgentFlowRuntime.getState().sources > 0); await page.evaluate(() => window.CodeXRAgentFlowHarness.hideControls()); @@ -190,6 +202,51 @@ async function runScenario(browser, port) { await sleep(900); await shot(page, '20-ufo-eye-level'); + // (a4) The UFO flies, it does not jump: a forward step moves it over + // several frames, also after the render budget reports a low frame rate + // (only reduced motion turns the flight off). + const flight = (budget) => page.evaluate(async (quality) => { + const runtime = window.CodeXRAgentFlowRuntime; + window.CodeXRRenderBudgetRuntime.__emit({ quality }); + const view = runtime.__testing.getView(); + // A step whose actor flies somewhere else than where it stands. + const steps = view.timeline.steps; + let index = -1; + for (let i = 1; i < steps.length && index < 0; i += 1) { + if (steps[i].actor !== 0 || steps[i].target.type === 'none') { continue; } + runtime.seek(i - 1); + const before = view.workers[0]?.group.position.clone(); + runtime.stepForward(); + const hop = view.workers[0]?.hop; + if (hop && before && Math.hypot(hop.to.x - before.x, hop.to.z - before.z) > 0.05) { index = i; } + } + if (index < 0) { return { index, positions: [] }; } + const worker = view.workers[0]; + const from = { x: worker.hop.from.x, z: worker.hop.from.z }; + const to = { x: worker.hop.to.x, z: worker.hop.to.z }; + const positions = []; + for (let frame = 0; frame < 400 && worker.hop; frame += 1) { + await new Promise((resolve) => window.requestAnimationFrame(resolve)); + positions.push({ x: worker.group.position.x, z: worker.group.position.z }); + } + const span = Math.hypot(to.x - from.x, to.z - from.z); + const between = positions.filter((p) => { + const done = Math.hypot(p.x - from.x, p.z - from.z) / span; + return done > 0.05 && done < 0.95; + }).length; + const largest = positions.reduce((max, p, i) => (i ? Math.max(max, Math.hypot(p.x - positions[i - 1].x, p.z - positions[i - 1].z) / span) : max), 0); + return { index, frames: positions.length, between, largest, motion: runtime.getState().motion }; + }, budget); + for (const quality of ['full', 'static']) { + const result = await flight(quality); + assert.ok(result.index > 0, `a step that flies the main UFO (${quality})`); + assert.equal(result.motion, true, `motion stays on with the budget at ${quality}`); + assert.ok(result.between >= 3, `the UFO flies through ${result.between} in-between positions (${quality}, ${result.frames} frames)`); + assert.ok(result.largest < 0.6, `no frame jumps most of the way (${result.largest.toFixed(2)} of the leg, ${quality})`); + } + await page.evaluate(() => window.CodeXRRenderBudgetRuntime.__emit({ quality: 'full' })); + state = await stepTo(7, 700); + // (a3) Skins: the UFO dresses for each action (colour + accessory). // Shown on the main UFO, one action at a time, then put back. const main = await page.evaluate(() => { diff --git a/docs/agent-flow/test-guide.md b/docs/agent-flow/test-guide.md index 0a7f134e..896ceb11 100644 --- a/docs/agent-flow/test-guide.md +++ b/docs/agent-flow/test-guide.md @@ -187,6 +187,7 @@ Design: [ufo.md](ufo.md). 8. With reduced motion on, saucers do not spin or bob and the beam is static. 9. Code-XR IDE: the same with a chat agent ("Watch in XR"). 10. Skins: step through a session and check the UFO's outfit per action (cyan + glasses on a read, violet + magnifier on a search, orange hard hat on an edit and green on a new file, green beacon on a run and red if it fails, orbs while thinking, hourglass while waiting, antennas on a delegate). The rim ring changes with the action; the name tag's stripe keeps the agent's colour. Each leg of the trail has the colour of the action at its end. +11. Smooth flight on battery: unplug the laptop (or open the scene on a slow machine) and play a session for a minute. The UFO glides between buildings and never jumps from one to the next. ## Timeline: the city as it was at every step diff --git a/docs/agent-flow/ufo.md b/docs/agent-flow/ufo.md index 03adefbe..632d9d1c 100644 --- a/docs/agent-flow/ufo.md +++ b/docs/agent-flow/ufo.md @@ -48,6 +48,12 @@ UFO is within 0.2 m of eye height and takes `20-ufo-eye-level.png`. - Function floors, see-through neighbours and blast radius are untouched: the UFO only changes who points at the building. - Reduced motion: no spin, no bobbing, no banking, a static beam. +- Low frame rate: the scene's render budget may report `static` (a slow + laptop on battery, a 30-48 Hz panel). Agent Flow keeps flying then: only + the system's reduced-motion setting stops the hops, because a UFO that + jumps from file to file loses the story it tells. While buildings grow, + turn rings, delta caps, legend leaders and the step label follow the roofs + about 11 times a second (plus a last pass when they stop), not every frame. ## Skins: one outfit per action (Code-XR#423)