Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions apps/vscode-extension/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
- Deleting or moving a file no longer counts as a blind edit.
- 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.
- 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.
- Buildings are at most 0.55 m tall, so the UFOs fly at the height of a standing viewer's eyes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,8 @@
ACTOR_PALETTE: ACTOR_PALETTE,
plateHeightOf: plateHeightOf,
focusFilesOf: focusFilesOf,
legendFocusFiles: legendFocusFiles,
mergeFocus: mergeFocus,
occludersOf: occludersOf,
segmentHitsBox: segmentHitsBox,
SEE_THROUGH_STYLES: SEE_THROUGH_STYLES,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down Expand Up @@ -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 };
Expand All @@ -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')) }
]
};
}
Expand Down Expand Up @@ -488,49 +500,85 @@
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);
}
['pinned', 'hover'].forEach(function (role) {
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.12, legendLift: 0.45 };
var SKY = { ufoLift: 0.12, legendLift: 0.3 };

function skylineY(v) {
var top = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,9 @@
deleted: false,
visible: file.existed,
height: !file.existed ? 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.existed ? 0 : (entry ? entry.baseLoc : toNumber(file.loc, 0)),
baseLoc: !file.existed ? 0 : (entry ? entry.baseLoc : toNumber(file.loc, 0)),
lastIndex: -1,
lastKind: null,
blind: false
Expand All @@ -383,6 +386,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);
// Something written to exists: a write after a delete brings the file back.
fileState.visible = true;
fileState.deleted = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,5 +239,6 @@
if (heightsMoving && v.cityState) { updateFloatingLabel(v, v.cityState); }
}
faceLegends(v, camera);
followViewer(v);
pollHover(v, time || 0);
}
29 changes: 29 additions & 0 deletions apps/vscode-extension/test/analysis/agentFlowRuntime.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,25 @@ 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');
// The sample writes the created file at step 18 and again at step 30, where it is moved away:
// its lines grow with its writes and reach the whole delta at the last one.
const firstWrite = api.stateAt(dataset, 18, timeline).files[CREATED].loc;
assert.ok(firstWrite > 0 && firstWrite <= created.delta.codeLines, 'lines once written');
assert.equal(api.stateAt(dataset, 30, timeline).files[CREATED].loc, created.delta.codeLines);
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];
Expand Down Expand Up @@ -528,6 +547,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 } };
Expand Down
15 changes: 15 additions & 0 deletions apps/vscode-extension/test/runners/run-agent-flow-harness.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,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();
Expand Down Expand Up @@ -460,8 +463,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);
Expand Down
Loading
Loading