diff --git a/apps/vscode-extension/CHANGELOG.md b/apps/vscode-extension/CHANGELOG.md index 0481da0a..a466e11d 100644 --- a/apps/vscode-extension/CHANGELOG.md +++ b/apps/vscode-extension/CHANGELOG.md @@ -32,6 +32,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. - Legends above the city: the building card, and the function card beside it when you point at a floor, float above the tallest building with a line down to what they describe, so they no longer hide the buildings around them. - Click a building to pin its card; it stays while you look at others and follows the playhead. Click it again to remove it. - The numbers on the cards are those of the moment on the timeline (lines of code, change, reads, writes), not the end of the session. 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 d5337b22..88107c50 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 890da50d..cdcc988a 100644 --- a/docs/agent-flow/test-guide.md +++ b/docs/agent-flow/test-guide.md @@ -173,6 +173,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. ## Legends above the city (hover, click to pin) 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)