From 0618f380f1f30e154ed3b7d2e7aaf2abe8d8837e Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 2 Dec 2026 16:11:52 +0000 Subject: [PATCH] Agent Flow: city tweens play again, so replay builds new floors in their step The codexr-city component copied the whole city API onto itself, tick included, so A-Frame called city.tick(time, delta) every frame: the clock went in as dt and every height, fade and floor tween finished on the next frame. Replaying a step that writes a new function therefore showed the floor already built. The component now leaves A-Frame's lifecycle names alone; the view still drives the city's tick. The harness samples the new floor every frame during its step and asserts it grows over several frames, and waits for tweens to settle on software GL. --- apps/vscode-extension/CHANGELOG.md | 1 + .../agent-flow/agentFlowRuntime/cityScene.js | 10 ++++++- .../test/runners/run-agent-flow-harness.cjs | 28 +++++++++++++++++-- 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/apps/vscode-extension/CHANGELOG.md b/apps/vscode-extension/CHANGELOG.md index ff6bf345..d79395ff 100644 --- a/apps/vscode-extension/CHANGELOG.md +++ b/apps/vscode-extension/CHANGELOG.md @@ -18,6 +18,7 @@ - Untouched floors keep the building's grey; a floor the agent read or edited keeps a soft tint of that action. - The floors the current step reads or edits light up in the action's colour, with an outline: exactly the functions it works on, not the whole file. - A function the agent writes from scratch gets a new floor, built in front of you when the step plays. + - Replaying the timeline animates the city as it changed: moving back shows the city as it was at that point of the chat, and playing forward grows new floors, raises and lowers buildings and fades neighbours step by step. Before, every growth and fade finished on the next frame. - Resting the pointer on a floor names its function, its lines and how many times it was read and written. - Line data comes from Claude Code's edit and read results and from the Code-XR IDE's agent locations; a step without it lights the whole building, as before. - Agents fly UFOs: each agent is a flying saucer in its colour, cruising above the tallest building and below the legends, so it is always in sight. diff --git a/apps/vscode-extension/templates/components/codexr/agent-flow/agentFlowRuntime/cityScene.js b/apps/vscode-extension/templates/components/codexr/agent-flow/agentFlowRuntime/cityScene.js index 18a61a92..4be2f20a 100644 --- a/apps/vscode-extension/templates/components/codexr/agent-flow/agentFlowRuntime/cityScene.js +++ b/apps/vscode-extension/templates/components/codexr/agent-flow/agentFlowRuntime/cityScene.js @@ -766,6 +766,8 @@ return bound; } + var AFRAME_LIFECYCLE = ['init', 'update', 'remove', 'tick', 'tock', 'play', 'pause']; + function registerCityComponent() { var aframe = root.AFRAME; if (!aframe?.registerComponent || aframe.components?.[CITY_COMPONENT]) { return; } @@ -775,7 +777,13 @@ if (!c) { return; } var api = c.api || (c.api = bindCityApi(c)); var component = this; - Object.keys(api).forEach(function (name) { component[name] = api[name]; }); + // A-Frame calls a component's tick(time, delta) every frame: copying the + // city's tick(dt, time) there fed it the clock as dt, finishing every + // tween (heights, fades, floors) on the next frame. The view drives the + // city's tick, so lifecycle names stay A-Frame's. + Object.keys(api).forEach(function (name) { + if (AFRAME_LIFECYCLE.indexOf(name) === -1) { component[name] = api[name]; } + }); }, remove: function () { if (this.el.codexrCity && !this.el.codexrCity.external) { cityApi.dispose(this.el.codexrCity); } 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 7a63f90b..11aaa399 100644 --- a/apps/vscode-extension/test/runners/run-agent-flow-harness.cjs +++ b/apps/vscode-extension/test/runners/run-agent-flow-harness.cjs @@ -125,8 +125,9 @@ async function runScenario(browser, port) { await sleep(300); await page.evaluate(() => { window.CodeXRAgentFlowRuntime.stepForward(); }); await waitFor(page, (i) => window.CodeXRAgentFlowRuntime.getState().stepIndex === i, index, 10000); - // Software GL runs at a few frames a second: wait for the hop to land. - await waitFor(page, () => !window.CodeXRAgentFlowRuntime.getState().moving, undefined, 15000); + // Software GL runs at a few frames a second and a frame advances the + // tweens by at most 64 ms: wait for the hop and the growth to land. + await waitFor(page, () => !window.CodeXRAgentFlowRuntime.getState().moving, undefined, 60000); await sleep(settleMs); return snapshot(page); }; @@ -278,7 +279,27 @@ async function runScenario(browser, port) { assert.ok(!floors.rects.includes(floors.names.indexOf('fanInOutRows')), 'a function written later is not built yet'); await shot(page, '14-floors-read-window'); // The edit that writes fanInOutRows builds its floor and lights exactly that one. + // Replayed (not live), the floor still grows in its step: sample its height every frame. + await page.evaluate((s) => { + const view = window.CodeXRAgentFlowRuntime.__testing.getView(); + const index = view.files.findIndex((file) => file.path === s || file.path.endsWith('/' + s)); + const slot = view.city.floorInstances(index)[view.files[index].floors.findIndex((floor) => floor.name === 'fanInOutRows')]; + let mesh = null; + view.rootEl.object3D.traverse((object) => { if (object.name === 'agentFlowFloors') { mesh = object; } }); + const matrix = new window.AFRAME.THREE.Matrix4(); + window.__floorGrowth = []; + const sample = () => { + mesh.getMatrixAt(slot, matrix); + window.__floorGrowth.push(matrix.elements[5]); + if (window.__floorGrowth.length < 400) { window.requestAnimationFrame(sample); } + }; + window.requestAnimationFrame(sample); + }, tooltips); state = await stepTo(15, 1600); + const growth = await page.evaluate(() => window.__floorGrowth.slice()); + const grown = growth.at(-1); + const between = new Set(growth.filter((value) => value > 0.0005 && Math.abs(value - grown) > 0.0005).map((value) => value.toFixed(4))); + assert.ok(grown > 0 && between.size >= 2, `the new floor grows over several frames (${growth.length} frames, ${between.size} in between)`); floors = await floorsOf(tooltips); assert.deepEqual(floors.lit, ['fanInOutRows']); assert.ok(floors.rects.includes(floors.names.indexOf('fanInOutRows')), 'the new floor stands once built'); @@ -449,7 +470,8 @@ async function runScenario(browser, port) { assert.equal(state.seeThrough.style, 'transparent'); await shot(page, '13-see-through'); await page.evaluate(() => window.CodeXRAgentFlowRuntime.setToggle('seeThrough', false)); - await sleep(900); + // The fade back runs on frames (at most 64 ms each): software GL needs a few seconds. + await waitFor(page, () => window.CodeXRAgentFlowRuntime.getState().seeThrough.faded.length === 0, undefined, 20000).catch(() => {}); state = await snapshot(page); assert.deepEqual(state.seeThrough.faded, [], 'toggle off: every building solid again'); await page.evaluate(() => window.CodeXRAgentFlowRuntime.setToggle('seeThrough', true));