From 6cab64235099d150809cf64e790301b16875846b Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 2 Dec 2026 15:54:09 +0000 Subject: [PATCH 1/2] Agent Flow legends: lower band, side-by-side cards, see-through keeps the legend's building in sight (#419) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit After Adrián's test: the legend band drops to skyline + 0.30 (UFO lane +0.12, agreed with the UFO thread), cards are a little smaller, and a card that would overlap another slides sideways instead of stacking. A pinned or hovered legend's building leads the see-through focus. --- apps/vscode-extension/CHANGELOG.md | 1 + .../agentFlowRuntime/modeLifecycle.js | 2 + .../agentFlowRuntime/sceneOverlays.js | 76 ++++++++++++++----- .../agent-flow/agentFlowRuntime/seeThrough.js | 25 +++++- .../agent-flow/agentFlowRuntime/skyLayers.js | 2 +- .../agentFlowRuntime/viewController.js | 1 + .../test/analysis/agentFlowRuntime.test.cjs | 10 +++ .../test/runners/run-agent-flow-harness.cjs | 3 + docs/agent-flow/legends.md | 14 ++-- docs/agent-flow/test-guide.md | 7 +- 10 files changed, 111 insertions(+), 30 deletions(-) diff --git a/apps/vscode-extension/CHANGELOG.md b/apps/vscode-extension/CHANGELOG.md index ff6bf345..10027fef 100644 --- a/apps/vscode-extension/CHANGELOG.md +++ b/apps/vscode-extension/CHANGELOG.md @@ -27,6 +27,7 @@ - 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 and the name tag keep the agent's colour. - Legends above the city: the building card, and the function card on top 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. + - With See-through on, the buildings in front of a pinned or hovered building fade while its card is open, so it is always in sight. - The label of the current step floats in the same band. - **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. 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 1e87f1ec..19aa8e89 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 @@ -329,6 +329,8 @@ ACTOR_PALETTE: ACTOR_PALETTE, plateHeightOf: plateHeightOf, focusFilesOf: focusFilesOf, + legendFocusFiles: legendFocusFiles, + mergeFocus: mergeFocus, occludersOf: occludersOf, segmentHitsBox: segmentHitsBox, SEE_THROUGH_STYLES: SEE_THROUGH_STYLES, diff --git a/apps/vscode-extension/templates/components/codexr/agent-flow/agentFlowRuntime/sceneOverlays.js b/apps/vscode-extension/templates/components/codexr/agent-flow/agentFlowRuntime/sceneOverlays.js index 0ce005f0..bc3be53f 100644 --- a/apps/vscode-extension/templates/components/codexr/agent-flow/agentFlowRuntime/sceneOverlays.js +++ b/apps/vscode-extension/templates/components/codexr/agent-flow/agentFlowRuntime/sceneOverlays.js @@ -311,7 +311,7 @@ // Cards float in the legend band above the skyline and hang a leader line // down to the roof or the floor they describe. - var LEGEND = { width: 1.7, scale: 0.42, gap: 0.05, stackGap: 0.04 }; + var LEGEND = { width: 1.7, scale: 0.36, gap: 0.04, stackGap: 0.03 }; function createLeader(v, role) { var line = entity('a-entity', { visible: 'false', 'data-codexr-role': 'agent-flow legend leader ' + role }); @@ -488,36 +488,65 @@ return roof; } + /** The viewer's right, flat on the table (city-local), or +x without a camera. */ + function viewerRight(v) { + var camera = v.rootEl?.sceneEl?.camera; + var T = three(); + if (!camera?.getWorldPosition || !v.rootEl.object3D || !T) { return { x: 1, z: 0 }; } + var eye = camera.getWorldPosition(new T.Vector3()); + v.rootEl.object3D.updateWorldMatrix(true, false); + v.rootEl.object3D.worldToLocal(eye); + var length = Math.hypot(eye.x, eye.z); + if (length < 1e-6) { return { x: 1, z: 0 }; } + // Toward the eye is (eye.x, eye.z); its right-hand perpendicular. + return { x: eye.z / length, z: -eye.x / length }; + } + /** - * Places the step label and the legends in the band above the skyline: - * each over its own building, and lifted over an earlier one it would - * overlap (label first, then the pinned legend, then the hover one). + * Places the step label and the legends in the band above the skyline, + * each over its own target (label first, then the pinned legend, then the + * hover one). One that would overlap an earlier item slides sideways + * (across the viewer's line of sight) rather than climbing on top of it, + * so the band stays one card high; it only stacks when no side is free. */ function layoutLegends(v) { if (!v?.rootEl) { return; } var base = legendAltitude(v); + var right = viewerRight(v); + v.legendRight = right; var placed = []; + function clashes(x, z, y, halfWidth, height) { + return placed.some(function (other) { + var apart = Math.hypot(x - other.x, z - other.z) >= halfWidth + other.halfWidth + 0.04; + var overlapY = y < other.y + other.height + LEGEND.gap && other.y < y + height + LEGEND.gap; + return !apart && overlapY; + }); + } function place(x, z, halfWidth, height) { - var y = base; - var moved = true; - while (moved) { - moved = false; - for (var i = 0; i < placed.length; i += 1) { - var other = placed[i]; - var overlapX = Math.hypot(x - other.x, z - other.z) < halfWidth + other.halfWidth + 0.04; - var overlapY = y < other.y + other.height + LEGEND.gap && other.y < y + height + LEGEND.gap; - if (overlapX && overlapY) { y = other.y + other.height + LEGEND.gap; moved = true; } + var widest = placed.reduce(function (max, other) { return Math.max(max, other.halfWidth); }, 0); + var step = halfWidth + widest + 0.06; + var slots = [0, 1, -1, 2, -2]; + for (var k = 0; k < slots.length; k += 1) { + var sx = x + right.x * step * slots[k]; + var sz = z + right.z * step * slots[k]; + if (!clashes(sx, sz, base, halfWidth, height)) { + placed.push({ x: sx, z: sz, halfWidth: halfWidth, y: base, height: height }); + return { x: sx, y: base, z: sz }; } } + var y = base; + while (clashes(x, z, y, halfWidth, height)) { + y = Math.max.apply(null, placed.map(function (other) { return other.y + other.height; })) + LEGEND.gap; + } placed.push({ x: x, z: z, halfWidth: halfWidth, y: y, height: height }); - return y; + return { x: x, y: y, z: z }; } var label = v.label; if (label && label.target) { - var labelY = place(label.target.x, label.target.z, LABEL.width / 2, LABEL.height); - label.anchor = { x: label.target.x, y: labelY + LABEL.height / 2, z: label.target.z }; + var spot = place(label.target.x, label.target.z, LABEL.width / 2, LABEL.height); + label.anchor = { x: spot.x, y: spot.y + LABEL.height / 2, z: spot.z }; label.el.setAttribute('position', label.anchor.x + ' ' + label.anchor.y + ' ' + label.anchor.z); - setLeader(label.leader, label.target.y === null ? null : { x: label.target.x, y: labelY, z: label.target.z }, label.target, label.color); + setLeader(label.leader, label.target.y === null ? null : spot, label.target, label.color); } else if (label) { setLeader(label.leader, null); } @@ -525,12 +554,19 @@ var legend = v.legends?.[role]; if (!legend || legend.file < 0) { return; } var target = legendTarget(v, legend.file, legend.floorIndex); - var y = place(target.x, target.z, LEGEND.width * LEGEND.scale / 2, legend.height); - legend.wrap.setAttribute('position', target.x + ' ' + y + ' ' + target.z); - setLeader(legend.leader, { x: target.x, y: y, z: target.z }, target, legend.color); + var at = place(target.x, target.z, LEGEND.width * LEGEND.scale / 2, legend.height); + legend.wrap.setAttribute('position', at.x + ' ' + at.y + ' ' + at.z); + setLeader(legend.leader, at, target, legend.color); }); } + /** Relayout when the viewer walks round the table far enough to change "sideways". */ + function followViewer(v) { + if (!v?.legendRight || !(v.label?.target || v.legends?.pinned?.file >= 0 || v.legends?.hover?.file >= 0)) { return; } + var now = viewerRight(v); + if (now.x * v.legendRight.x + now.z * v.legendRight.z < 0.985) { layoutLegends(v); } + } + /** Hover (showTooltip keeps its name: the harness drives it). */ function showTooltip(v, fileIndex, floorIndex) { var floor = Number.isInteger(floorIndex) ? floorIndex : -1; diff --git a/apps/vscode-extension/templates/components/codexr/agent-flow/agentFlowRuntime/seeThrough.js b/apps/vscode-extension/templates/components/codexr/agent-flow/agentFlowRuntime/seeThrough.js index c4090bf3..9cf97577 100644 --- a/apps/vscode-extension/templates/components/codexr/agent-flow/agentFlowRuntime/seeThrough.js +++ b/apps/vscode-extension/templates/components/codexr/agent-flow/agentFlowRuntime/seeThrough.js @@ -42,6 +42,29 @@ return result; } + /** + * The buildings whose legend is open (pinned first, then the hovered one): + * they stay in sight like the agent's work (docs/agent-flow/legends.md). + */ + function legendFocusFiles(v) { + var result = []; + [v.pin ? v.pin.file : -1, v.hoverFile].forEach(function (fileIndex) { + if (!Number.isInteger(fileIndex) || fileIndex < 0 || result.indexOf(fileIndex) >= 0) { return; } + if (v.cityState?.files?.[fileIndex]?.deleted) { return; } + result.push(fileIndex); + }); + return result; + } + + /** Legend buildings first, then the agent's, without repeats, within the cap. */ + function mergeFocus(first, rest) { + var result = first.slice(0, SEE_THROUGH.focusCap); + rest.forEach(function (fileIndex) { + if (result.length < SEE_THROUGH.focusCap && result.indexOf(fileIndex) < 0) { result.push(fileIndex); } + }); + return result; + } + /** Slab test: does the segment a -> b cross the axis-aligned box? */ function segmentHitsBox(a, b, box) { var t0 = 0; @@ -132,7 +155,7 @@ function tickSeeThrough(v, timeMs, camera) { var st = v.seeThrough || (v.seeThrough = { at: -Infinity, eye: null, key: '', faded: {} }); var enabled = !!state.toggles.seeThrough; - var focus = enabled && v.cityState ? focusFilesOf(v.cityState, v.workerInfo) : []; + var focus = enabled && v.cityState ? mergeFocus(legendFocusFiles(v), focusFilesOf(v.cityState, v.workerInfo)) : []; var key = focusKey(focus); var eye = focus.length ? eyeInCity(v, camera) : null; var moved = !!eye && (!st.eye || Math.hypot(eye.x - st.eye.x, eye.y - st.eye.y, eye.z - st.eye.z) > SEE_THROUGH.eyeEpsilon); diff --git a/apps/vscode-extension/templates/components/codexr/agent-flow/agentFlowRuntime/skyLayers.js b/apps/vscode-extension/templates/components/codexr/agent-flow/agentFlowRuntime/skyLayers.js index 638dd761..822739ce 100644 --- a/apps/vscode-extension/templates/components/codexr/agent-flow/agentFlowRuntime/skyLayers.js +++ b/apps/vscode-extension/templates/components/codexr/agent-flow/agentFlowRuntime/skyLayers.js @@ -10,7 +10,7 @@ // the playhead does; `v.skyExtra` lets a layer that lifts geometry above // the roofs (the floor accordion) push them up. - var SKY = { ufoLift: 0.18, legendLift: 0.45 }; + var SKY = { ufoLift: 0.12, legendLift: 0.3 }; function skylineY(v) { var top = 0; 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 3373cae8..b97f6695 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 @@ -178,5 +178,6 @@ if (heightsMoving && v.cityState) { updateFloatingLabel(v, v.cityState); } } faceLegends(v, camera); + followViewer(v); pollHover(v, time || 0); } diff --git a/apps/vscode-extension/test/analysis/agentFlowRuntime.test.cjs b/apps/vscode-extension/test/analysis/agentFlowRuntime.test.cjs index 9bdbb1a2..c57c20b3 100644 --- a/apps/vscode-extension/test/analysis/agentFlowRuntime.test.cjs +++ b/apps/vscode-extension/test/analysis/agentFlowRuntime.test.cjs @@ -524,6 +524,16 @@ test('see-through: the focus is the active workers\' files, minus broad searches assert.deepEqual([...focusFilesOf({ files: [], current: { kind: 'execute', files: [] } }, [])], []); }); +test('see-through: a pinned or hovered legend\'s building joins the focus ahead of the agent\'s', () => { + const { legendFocusFiles, mergeFocus } = loadPure().__testing; + const cityState = { files: [{}, {}, { deleted: true }, {}] }; + assert.deepEqual([...legendFocusFiles({ pin: { file: 3, floor: -1 }, hoverFile: 1, cityState })], [3, 1]); + assert.deepEqual([...legendFocusFiles({ pin: { file: 1, floor: 0 }, hoverFile: 1, cityState })], [1], 'no repeats'); + assert.deepEqual([...legendFocusFiles({ pin: null, hoverFile: -1, cityState })], []); + assert.deepEqual([...legendFocusFiles({ pin: { file: 2, floor: -1 }, hoverFile: -1, cityState })], [], 'a deleted building has nothing to show'); + assert.deepEqual([...mergeFocus([3, 1], [1, 0, 4, 5, 6, 7])], [3, 1, 0, 4, 5, 6], 'legend first, agent after, within the cap'); +}); + test('see-through: only the buildings on a sight line to the focus fade', () => { const { occludersOf, segmentHitsBox } = loadPure().__testing; const box = { min: { x: -1, y: 0, z: -1 }, max: { x: 1, y: 1, z: 1 } }; 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..946fe737 100644 --- a/apps/vscode-extension/test/runners/run-agent-flow-harness.cjs +++ b/apps/vscode-extension/test/runners/run-agent-flow-harness.cjs @@ -374,6 +374,9 @@ async function runScenario(browser, port) { assert.equal(pinned.file, hover.index); assert.equal(pinned.floor, hover.floor, 'the pinned legend keeps the clicked floor'); assert.equal(await legendState('hover'), null, 'no second card over the pinned building'); + // See-through keeps the pinned building in sight: it leads the focus, it never fades. + await waitFor(page, (i) => window.CodeXRAgentFlowRuntime.__testing.getView().seeThrough?.focus?.[0] === i, hover.index, 5000); + assert.equal(await page.evaluate((i) => window.CodeXRAgentFlowRuntime.__testing.getView().city.getFade(i), hover.index), 1, 'the pinned building is never ghosted'); // Hover a neighbour with the real pointer: the nearest buildings, roof first. const candidates = await page.evaluate((i) => { const view = window.CodeXRAgentFlowRuntime.__testing.getView(); diff --git a/docs/agent-flow/legends.md b/docs/agent-flow/legends.md index c06f25f7..bea5aae7 100644 --- a/docs/agent-flow/legends.md +++ b/docs/agent-flow/legends.md @@ -1,6 +1,6 @@ # Agent Flow legends: above the city, building and floor, click to pin -Story Code-XR#419 (epic #319). Proposed by Adrián on 2026-12-02 after testing the function floors (#413): the hover card stood 0.3 m over the roof of its building, in the middle of the skyline, and hid the buildings around it. +Story Code-XR#419 (epic #319). Band lowered on 2026-12-02 after Adrián's test (cards too high), together with the UFO lane and the lower building cap. Proposed by Adrián on 2026-12-02 after testing the function floors (#413): the hover card stood 0.3 m over the roof of its building, in the middle of the skyline, and hid the buildings around it. ## Sky bands @@ -9,14 +9,14 @@ Story Code-XR#419 (epic #319). Proposed by Adrián on 2026-12-02 after testing t | Band | Height | Used by | |---|---|---| | Skyline | `skylineY(v)`: highest roof of the session (final, current or growing height) + `v.skyExtra` | reference | -| UFO lane | `ufoAltitude(v)` = skyline + 0.18 | the worker's saucer (UFO thread, PRs #421/#422) | -| Legends | `legendAltitude(v)` = skyline + 0.45 | bottom edge of every legend card and of the current-step label | +| UFO lane | `ufoAltitude(v)` = skyline + 0.12 | the worker's saucer (UFO thread, PRs #421/#422) | +| Legends | `legendAltitude(v)` = skyline + 0.3 | bottom edge of every legend card and of the current-step label | The skyline counts every building at its tallest, so the bands do not jump while the playhead moves. A layer that lifts geometry above the roofs (the floor accordion, #412) sets `v.skyExtra` to push the bands up. ## Cards -Same chrome as every other Code-XR card (`CodeXRCommonRuntime.createTooltip`): dark panel, accent frame and bar, two-column metric grid. A legend is a wrap (scale 0.42) holding: +Same chrome as every other Code-XR card (`CodeXRCommonRuntime.createTooltip`): dark panel, accent frame and bar, two-column metric grid. A legend is a wrap (scale 0.36) holding: - **Building card**: file name, folder (prefixed "Pinned" when pinned), LOC, delta, reads, writes, searches, functions standing / total, turns, dependents, scope. - **Floor card** (only when a floor is pointed), stacked on top: `name()`, "Floor n of N Lstart-end", lines, origin (new in the session or existing), reads, writes, last action. Its accent is the colour of the last action (cyan read, orange write). @@ -31,9 +31,13 @@ A leader line with a marker drops from the card's bottom edge to the pointed flo - Click on the pinned building: unpins. Click on another building: the pin moves. - The pin refreshes its values on every render (step, seek, toggle) and is dropped with the view (new session, mode change). +## Kept in sight (see-through) + +A pinned or hovered legend's building joins the see-through focus (`legendFocusFiles` in `seeThrough.js`), ahead of the agent's buildings: whatever stands between the viewer and it fades to a ghost, and the building itself never fades. Adrián asked for it after testing see-through (2026-12-02). Moving the pointer away or unpinning restores the ghosts. + ## Layout -`layoutLegends(v)` places, in order, the step label, the pinned legend and the hover legend, each over its own target at `legendAltitude`, and lifts an item above an earlier one it would overlap (horizontal distance under the two half widths). Cards and label face the camera by yaw only. +`layoutLegends(v)` places, in order, the step label, the pinned legend and the hover legend, each over its own target at `legendAltitude`. One that would overlap an earlier item (horizontal distance under the two half widths) slides sideways, across the viewer's line of sight (right, left, then further), so the band stays one card high; it stacks upward only when no side slot is free. The leader then runs slanted from the card to its target. `followViewer` relayouts when the viewer walks round the table (about 10 degrees). Cards and label face the camera by yaw only. ## Tests diff --git a/docs/agent-flow/test-guide.md b/docs/agent-flow/test-guide.md index f2430800..3ebc17fa 100644 --- a/docs/agent-flow/test-guide.md +++ b/docs/agent-flow/test-guide.md @@ -180,9 +180,10 @@ Design: [legends.md](legends.md). Story #419. 1. Open a session with function floors. Rest the pointer on a building: its card appears **above the tallest building of the city**, never among the roofs, with a thin line down to the roof. 2. Rest the pointer on a floor: a second card (the function) sits on top of the building card, and the line goes down to that floor. -3. Click the building (or a floor): the card stays ("Pinned" before the folder path). Move the pointer to other buildings: their cards appear as before, stacked above the pinned one when they are close, and the pinned card does not move. +3. Click the building (or a floor): the card stays ("Pinned" before the folder path). Move the pointer to other buildings: their cards appear as before, beside the pinned one when they are close, and the pinned card does not move. 4. Play or seek: the pinned card stays and its numbers follow the playhead. 5. Click the pinned building again: the pin is removed (the hover card takes over while the pointer stays on it). Clicking another building moves the pin there. 6. The current-step label (file and verb) also floats in that band, with its own line down to the building. -7. XR headset: the same with the controller ray and trigger. -8. Code-XR IDE: the same in the scene pane. +7. See-through on: hover or pin a building hidden behind others; the buildings in front fade to ghosts while its card is open, and come back when you move away or unpin. +8. XR headset: the same with the controller ray and trigger. +9. Code-XR IDE: the same in the scene pane. From 7060287554a81ac7130efbf4b31d4dec5ad6ff2a Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 2 Dec 2026 16:15:33 +0000 Subject: [PATCH 2/2] Agent Flow legends: numbers at the playhead (LOC and delta follow the history) (#419) --- apps/vscode-extension/CHANGELOG.md | 1 + .../agentFlowRuntime/sceneOverlays.js | 18 +++++++++++++++--- .../agentFlowRuntime/timelineModel.js | 4 ++++ .../test/analysis/agentFlowRuntime.test.cjs | 15 +++++++++++++++ .../test/runners/run-agent-flow-harness.cjs | 12 ++++++++++++ docs/agent-flow/legends.md | 4 ++++ docs/agent-flow/test-guide.md | 2 +- 7 files changed, 52 insertions(+), 4 deletions(-) diff --git a/apps/vscode-extension/CHANGELOG.md b/apps/vscode-extension/CHANGELOG.md index 10027fef..9b288a99 100644 --- a/apps/vscode-extension/CHANGELOG.md +++ b/apps/vscode-extension/CHANGELOG.md @@ -27,6 +27,7 @@ - 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 and the name tag keep the agent's colour. - Legends above the city: the building card, and the function card on top 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. - With See-through on, the buildings in front of a pinned or hovered building fade while its card is open, so it is always in sight. - The label of the current step floats in the same band. - **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. diff --git a/apps/vscode-extension/templates/components/codexr/agent-flow/agentFlowRuntime/sceneOverlays.js b/apps/vscode-extension/templates/components/codexr/agent-flow/agentFlowRuntime/sceneOverlays.js index bc3be53f..aee8a324 100644 --- a/apps/vscode-extension/templates/components/codexr/agent-flow/agentFlowRuntime/sceneOverlays.js +++ b/apps/vscode-extension/templates/components/codexr/agent-flow/agentFlowRuntime/sceneOverlays.js @@ -383,6 +383,18 @@ return rects && rects.length ? rects.length : file.floors.length; } + /** Lines of code at the playhead (fileState.loc), else the analysed count. */ + function historicLoc(file, fileState) { + return Number.isFinite(fileState?.loc) ? fileState.loc : file.loc; + } + + /** The change so far at the playhead: 'none' before the first write. */ + function historicDelta(file, fileState) { + if (!fileState) { return file.delta ? formatSigned(file.delta.codeLines) + ' lines' : 'none'; } + if (!(fileState.touches?.writes > 0) || !Number.isFinite(fileState.loc) || !Number.isFinite(fileState.baseLoc)) { return 'none'; } + return formatSigned(fileState.loc - fileState.baseLoc) + ' lines'; + } + function buildingCardModel(v, fileIndex, fileState, pinned) { var file = v.files[fileIndex]; var touches = fileState ? fileState.touches : { reads: 0, writes: 0, searches: 0 }; @@ -393,15 +405,15 @@ subtitle: (pinned ? 'Pinned ' : '') + where, accentColor: state.toggles.heat ? heatColor(fileState, v.outside[fileIndex]) : ACCENT, rows: [ - { label: 'LOC', value: String(file.loc) }, - { label: 'Delta', value: file.delta ? formatSigned(file.delta.codeLines) + ' lines' : 'none' }, + { label: 'LOC', value: String(historicLoc(file, fileState)) }, + { label: 'Delta', value: historicDelta(file, fileState) }, { label: 'Reads', value: String(touches.reads) }, { label: 'Writes', value: String(touches.writes) }, { label: 'Searches', value: String(touches.searches) }, { label: 'Functions', value: floors }, { label: 'Turns', value: fileState?.turns.length ? fileState.turns.map(function (t) { return 'T' + (t + 1); }).join(' ') : '-' }, { label: 'Dependents', value: file.dependents < 0 ? '?' : String(file.dependents) }, - { label: 'Scope', value: fileState?.deleted ? 'deleted' : (v.outside[fileIndex] ? 'outside' : (file.created ? 'created' : 'analysed')) } + { label: 'Scope', value: fileState?.deleted ? 'deleted' : (v.outside[fileIndex] ? 'outside' : (file.created ? (fileState && !fileState.visible ? 'not yet' : 'created') : 'analysed')) } ] }; } diff --git a/apps/vscode-extension/templates/components/codexr/agent-flow/agentFlowRuntime/timelineModel.js b/apps/vscode-extension/templates/components/codexr/agent-flow/agentFlowRuntime/timelineModel.js index 412accdf..3e61d7df 100644 --- a/apps/vscode-extension/templates/components/codexr/agent-flow/agentFlowRuntime/timelineModel.js +++ b/apps/vscode-extension/templates/components/codexr/agent-flow/agentFlowRuntime/timelineModel.js @@ -335,6 +335,9 @@ deleted: false, visible: !file.created, height: file.created ? 0 : (entry ? heightForLoc(file, entry.baseLoc) : file.h), + // Lines of code at the playhead (the legend shows the history, not the end state). + loc: file.created ? 0 : (entry ? entry.baseLoc : toNumber(file.loc, 0)), + baseLoc: file.created ? 0 : (entry ? entry.baseLoc : toNumber(file.loc, 0)), lastIndex: -1, lastKind: null, blind: false @@ -353,6 +356,7 @@ var entry = plan[file.index]; var share = entry ? toNumber(entry.shares[step.index], 1) : 1; fileState.height = entry ? heightForLoc(file, entry.baseLoc + entry.totalDelta * share) : file.h; + fileState.loc = entry ? Math.max(0, Math.round(entry.baseLoc + entry.totalDelta * share)) : toNumber(file.loc, 0); fileState.visible = true; } if ((file.deleted && step.seq === file.lastStep && !step.deletes.length) || step.deletes.indexOf(file.index) >= 0) { diff --git a/apps/vscode-extension/test/analysis/agentFlowRuntime.test.cjs b/apps/vscode-extension/test/analysis/agentFlowRuntime.test.cjs index c57c20b3..9593e061 100644 --- a/apps/vscode-extension/test/analysis/agentFlowRuntime.test.cjs +++ b/apps/vscode-extension/test/analysis/agentFlowRuntime.test.cjs @@ -160,6 +160,21 @@ test('stateAt is idempotent: a seek is a recomputation, not an undo log', () => assert.equal(api.stateAt(dataset, -5, timeline).stepIndex, -1); }); +test('history: lines of code and touches at the playhead, not the end state (legends)', () => { + const edited = dataset.files[EDITED]; + const created = dataset.files[CREATED]; + const before = api.stateAt(dataset, -1, timeline); + assert.equal(before.files[EDITED].loc, before.files[EDITED].baseLoc); + assert.equal(before.files[EDITED].loc, edited.loc - edited.delta.codeLines, 'the pre-session size'); + assert.equal(before.files[EDITED].touches.writes, 0); + assert.equal(before.files[CREATED].loc, 0, 'a created file has no lines before it is written'); + const end = api.stateAt(dataset, 999, timeline); + assert.equal(end.files[EDITED].loc, edited.loc, 'the analysed size at the end'); + assert.equal(end.files[CREATED].loc, created.loc); + const midway = api.stateAt(dataset, 10, timeline).files[EDITED]; + assert.ok(midway.touches.reads <= end.files[EDITED].touches.reads && midway.touches.writes < end.files[EDITED].touches.writes, 'fewer actions earlier in the chat'); +}); + test('heights: created files rise from nothing, edited files grow from their pre-session size', () => { const created = dataset.files[CREATED]; const edited = dataset.files[EDITED]; 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 946fe737..a87efc14 100644 --- a/apps/vscode-extension/test/runners/run-agent-flow-harness.cjs +++ b/apps/vscode-extension/test/runners/run-agent-flow-harness.cjs @@ -427,8 +427,20 @@ async function runScenario(browser, port) { await sleep(400); pinned = await legendState('pinned'); assert.ok(pinned && pinned.visible, 'the pin survives a seek'); + // Its numbers are the history at the playhead: before the edits, no writes and no delta. + const rowsAt = () => page.evaluate(() => { + const runtime = window.CodeXRAgentFlowRuntime.__testing; + const view = runtime.getView(); + return Object.fromEntries(runtime.legendModel(view, view.pin.file, -1, true).building.rows.map((row) => [row.label, row.value])); + }); + const early = await rowsAt(); + assert.equal(early.Writes, '0'); + assert.equal(early.Delta, 'none'); await page.evaluate(() => window.CodeXRAgentFlowRuntime.seek(22)); await sleep(400); + const late = await rowsAt(); + assert.equal(late.Writes, '2', 'both edits counted by step 22'); + assert.notEqual(late.LOC, early.LOC, 'the lines of code follow the playhead'); // A second click on the pinned building unpins it. // The cursor raycasts on its own tick: let it settle on the building before clicking. await page.mouse.move(floorOnScreen.x, floorOnScreen.y); diff --git a/docs/agent-flow/legends.md b/docs/agent-flow/legends.md index bea5aae7..b719f899 100644 --- a/docs/agent-flow/legends.md +++ b/docs/agent-flow/legends.md @@ -31,6 +31,10 @@ A leader line with a marker drops from the card's bottom edge to the pointed flo - Click on the pinned building: unpins. Click on another building: the pin moves. - The pin refreshes its values on every render (step, seek, toggle) and is dropped with the view (new session, mode change). +## History, not the end state + +The timeline is a time machine (Adrián, 2026-12-02): every number on a card is the value at the playhead. Reads, writes, searches, turns and the floor's reads/writes come from `stateAt`; lines of code too: `stateAt` carries `loc` per file (the pre-session size, then the write plan's share after each write, the same curve the height follows), and Delta is `loc - baseLoc` ("none" before the first write). A created file reads "not yet" before it is written. Dependents and a floor's line range are the analysed values (no history for those). + ## Kept in sight (see-through) A pinned or hovered legend's building joins the see-through focus (`legendFocusFiles` in `seeThrough.js`), ahead of the agent's buildings: whatever stands between the viewer and it fades to a ghost, and the building itself never fades. Adrián asked for it after testing see-through (2026-12-02). Moving the pointer away or unpinning restores the ghosts. diff --git a/docs/agent-flow/test-guide.md b/docs/agent-flow/test-guide.md index 3ebc17fa..246f1fb6 100644 --- a/docs/agent-flow/test-guide.md +++ b/docs/agent-flow/test-guide.md @@ -181,7 +181,7 @@ Design: [legends.md](legends.md). Story #419. 1. Open a session with function floors. Rest the pointer on a building: its card appears **above the tallest building of the city**, never among the roofs, with a thin line down to the roof. 2. Rest the pointer on a floor: a second card (the function) sits on top of the building card, and the line goes down to that floor. 3. Click the building (or a floor): the card stays ("Pinned" before the folder path). Move the pointer to other buildings: their cards appear as before, beside the pinned one when they are close, and the pinned card does not move. -4. Play or seek: the pinned card stays and its numbers follow the playhead. +4. Play or seek: the pinned card stays and its numbers follow the playhead. Seek to before the agent edited the file: Writes 0, Delta none and the LOC of the file before the session; seek forward and they grow. 5. Click the pinned building again: the pin is removed (the hover card takes over while the pointer stays on it). Clicking another building moves the pin there. 6. The current-step label (file and verb) also floats in that band, with its own line down to the building. 7. See-through on: hover or pin a building hidden behind others; the buildings in front fade to ghosts while its card is open, and come back when you move away or unpin.