From e8d714b20032117d9b6a332371772479f23b90d2 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 3 Dec 2026 14:29:33 +0000 Subject: [PATCH 1/3] Agent Flow: a file with no height at the opened step no longer stands as a 1 m box (#319) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adrián saw a big grey-violet block in the middle of the city in the demo video. It is templates/components/livepanel/charts.js, the file the sample session deletes with git rm. An InstancedMesh starts every instance at the identity matrix, and setBuildingHeight returns early when the height does not change, so a file whose height is 0 at the step the session opens on (deleted by then, or not created yet) was never written: it stood as a unit box at the city's origin for the whole session. buildBuildings now starts every building at the zero matrix, like the roofs, ghosts and floors already did. The harness asserts that every file with no height at the end of the sample session is hidden. --- .../agent-flow/agentFlowRuntime/cityScene.js | 7 ++++++- .../test/runners/run-agent-flow-harness.cjs | 17 +++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) 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 c8b12620..2fbc6560 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 @@ -124,13 +124,18 @@ c.baseY[index] = (c.outside[index] ? 1 : containingDepth(file, c.districts)) * PLATE_STEP; } }); + c.zero = new T.Matrix4().makeScale(0.00001, 0.00001, 0.00001); + // An InstancedMesh starts every instance at the identity matrix: a 1 m box at + // the city's origin. A file with no height at the opened step (deleted by the + // session, or not created yet) is never written by setBuildingHeight, so it + // would stand there as a huge block. Every building starts hidden instead. + for (var b = 0; b < count; b += 1) { mesh.setMatrixAt(b, c.zero); } if (!c.files.length) { mesh.count = 0; } c.buildings = mesh; // Roof tints: a thin cap per building, hidden (zero scale) until tinted. var roofs = new T.InstancedMesh(track(c, new T.BoxGeometry(1, 1, 1)), track(c, new T.MeshBasicMaterial({ color: '#ffffff' })), count); roofs.name = 'agentFlowRoofs'; roofs.instanceMatrix.setUsage?.(T.DynamicDrawUsage); - c.zero = new T.Matrix4().makeScale(0.00001, 0.00001, 0.00001); for (var i = 0; i < count; i += 1) { roofs.setMatrixAt(i, c.zero); roofs.setColorAt(i, c.color.set('#ffffff')); } c.group.add(roofs); c.roofs = roofs; 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 4598b8de..c850ac83 100644 --- a/apps/vscode-extension/test/runners/run-agent-flow-harness.cjs +++ b/apps/vscode-extension/test/runners/run-agent-flow-harness.cjs @@ -130,6 +130,23 @@ async function runScenario(browser, port) { assert.equal(state.actors, sample.actors.length, 'one worker lane per actor'); assert.ok(state.workers.length >= 1, 'the main worker stands on the table'); assert.ok(state.trailPoints > 2, 'the trail is drawn'); + // A file with no height at the opened step is hidden, not left at the + // InstancedMesh default (identity: a 1 m box at the city's origin). + const unbuiltScales = () => page.evaluate(() => { + const T = window.AFRAME.THREE; + const view = window.CodeXRAgentFlowRuntime.__testing.getView(); + const mesh = view.city.state.buildings; + const matrix = new T.Matrix4(); + const scale = new T.Vector3(); + return view.files.map((file, index) => index).filter((index) => view.city.getHeight(index) <= 0.0005).map((index) => { + mesh.getMatrixAt(index, matrix); + matrix.decompose(new T.Vector3(), new T.Quaternion(), scale); + return { path: view.files[index].path, scale: Math.max(scale.x, scale.y, scale.z) }; + }); + }); + let unbuilt = await unbuiltScales(); + assert.ok(unbuilt.some((entry) => entry.path.endsWith('livepanel/charts.js')), 'the file deleted by the session has no height at its end'); + unbuilt.forEach((entry) => assert.ok(entry.scale < 0.001, `${entry.path} is hidden at the end of the session (scale ${entry.scale})`)); const lookAtLocal = (point, offset) => page.evaluate(([p, o]) => window.CodeXRAgentFlowHarness.lookAtLocal(p, o), [point, offset]); const stepTo = async (index, settleMs) => { From c8704ad0831d22dc9bfbcdb0ddff3cabb7cce42e Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 3 Dec 2026 15:51:47 +0000 Subject: [PATCH 2/3] Agent Flow: a subagent's UFO appears with its first step, not with the delegate (#319) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adrián, watching the demo video: on a delegate, the main UFO and both subagents' UFOs sat in a pile at the same spot, their name tags on top of each other. workersAt made a subagent present from the delegate step that spawned it, and until its first step startSpot parked it 3 cm beside the main worker. A subagent is now present from its own first step: during the delegates only the main UFO flies (in its delegate outfit), and each subagent pops out of it, with the beam, when it starts working. Unit test updated (absent before its first step, each subagent appearing on its own first step). Test guide row updated. --- .../agent-flow/agentFlowRuntime/timelineModel.js | 10 +++++++--- .../test/analysis/agentFlowRuntime.test.cjs | 7 +++++-- docs/agent-flow/test-guide.md | 2 +- 3 files changed, 13 insertions(+), 6 deletions(-) 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 6258bca7..400df825 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 @@ -315,8 +315,12 @@ } /** - * Where every worker is at the playhead. A worker is present from its spawn - * (main: always) until its last step is over; its current action is its + * Where every worker is at the playhead. A worker is present from its first + * step (main: always) until its last step is over. A subagent is not shown + * between the delegate that spawns it and its first step: it would only + * hover idle on top of the main UFO, a pile of saucers with overlapping + * name tags (Adrián, demo video). It pops out of the main UFO when it starts + * working instead; its current action is its * latest step at or before the playhead, and that action is ongoing until * the same worker's next step starts (or, for its final step, while the * playhead is on it or the step is still running). @@ -329,7 +333,7 @@ if (lane.steps[i] <= at) { current = lane.steps[i]; break; } } var step = current >= 0 ? timeline.steps[current] : null; - var start = lane.kind === 'main' ? -Infinity : (lane.spawnIndex >= 0 ? lane.spawnIndex : lane.firstIndex); + var start = lane.kind === 'main' ? -Infinity : lane.firstIndex; var ended = lane.kind !== 'main' && lane.lastIndex >= 0 && at > lane.lastIndex && timeline.steps[lane.lastIndex].status !== 'running'; var present = timeline.count > 0 && (lane.kind === 'main' || (start >= 0 && at >= start && !ended)); diff --git a/apps/vscode-extension/test/analysis/agentFlowRuntime.test.cjs b/apps/vscode-extension/test/analysis/agentFlowRuntime.test.cjs index 0d9f79dd..cb94ae23 100644 --- a/apps/vscode-extension/test/analysis/agentFlowRuntime.test.cjs +++ b/apps/vscode-extension/test/analysis/agentFlowRuntime.test.cjs @@ -226,9 +226,12 @@ test('actors: workers get lanes, spawn at their delegate step and work in parall // Mid-session three workers are busy at once. const mid = api.workersAt(timeline, 7); assert.deepEqual(plain(mid.map((worker) => [worker.present, worker.active, worker.stepIndex])), [[true, true, 6], [true, true, 5], [true, true, 7]]); - // Before its first step a spawned worker is present but idle; before its spawn it is absent. - assert.deepEqual(plain(api.workersAt(timeline, 2).map((worker) => [worker.present, worker.active])), [[true, true], [true, false], [true, false]]); + // A spawned worker appears with its first step, not with the delegate: until then only the main UFO flies. + assert.deepEqual(plain(api.workersAt(timeline, 2).map((worker) => [worker.present, worker.active])), [[true, true], [false, false], [false, false]]); assert.equal(api.workersAt(timeline, 0)[1].present, false); + // Each subagent pops out on its own first step: one at step 3, the second at step 4. + assert.deepEqual(plain(api.workersAt(timeline, 3).map((worker) => worker.present)), [true, true, false]); + assert.deepEqual(plain(api.workersAt(timeline, 4).map((worker) => worker.present)), [true, true, true]); // A finished subagent leaves the table. assert.deepEqual(plain(api.workersAt(timeline, 11).map((worker) => worker.present)), [true, false, false]); // A dataset from before multi-agent tracing gets one synthesized main actor. diff --git a/docs/agent-flow/test-guide.md b/docs/agent-flow/test-guide.md index d3509a8b..dfc3a6d0 100644 --- a/docs/agent-flow/test-guide.md +++ b/docs/agent-flow/test-guide.md @@ -48,7 +48,7 @@ emerald, each sub-agent in its own colour. Check each action while it plays: | What the agent did | What you should see | |---|---| -| Handed a task to a sub-agent (Claude Code's Agent/Task tool) | A beam from the main worker, and a new smaller worker that pops out and works in parallel; when its work ends it flies back and dissolves | +| Handed a task to a sub-agent (Claude Code's Agent/Task tool) | The main UFO puts on its delegate outfit. The sub-agent's own UFO pops out of it with a beam when the sub-agent takes its first step (never earlier, so saucers never pile up on the main one) and works in parallel; when its work ends it flies back and dissolves | | Read a file | The worker stands on the roof and sweeps a cyan scanning cone down the facade; the roof stays tinted cyan | | Searched (grep, glob, find) | A violet radar ripple on the table, and beacons popping up on the matched buildings | | Edited a file | Scaffolding and a small crane on the building, orange floors stacking up by the added lines (a red slice drops off for removed lines) | From b485e5fa326ac4c84cfff306b556e00a029470a9 Mon Sep 17 00:00:00 2001 From: aMonteSl <128893712+aMonteSl@users.noreply.github.com> Date: Thu, 3 Dec 2026 16:51:16 +0000 Subject: [PATCH 3/3] Agent Flow: sub-agent hangar and the main UFO controlling from the tower (#453) On a delegate the main UFO docks on the control tower (the test tower) in a new control outfit with a radar ring. Each sub-agent waits in its bay of a hangar beside the tower, takes off from its pad on its first step, stays linked to the tower by a dashed radio line (a packet runs home on each of its steps) and lands back in its bay when done; the doors close once nobody is out. The hangar and the tower have pinnable legend cards. Everything is derived from the playhead (workersAt docked/controlling, hangarPlan, airfieldAt), so seek, play and step back draw the same airfield; the harness invariant now compares it. Replaces the pop-out-of-the-main-UFO and dissolve animations (delegateBeam removed). --- apps/vscode-extension/CHANGELOG.md | 1 + .../templates/components/COMPONENTS.md | 2 +- .../agentFlowRuntime/agentEffects.js | 13 - .../agent-flow/agentFlowRuntime/airfield.js | 405 ++++++++++++++++++ .../agentFlowRuntime/configAndState.js | 6 + .../agentFlowRuntime/constructionSite.js | 228 +++++++--- .../agent-flow/agentFlowRuntime/manifest.json | 1 + .../agentFlowRuntime/modeLifecycle.js | 9 + .../agentFlowRuntime/sceneOverlays.js | 100 +++-- .../agentFlowRuntime/timelineModel.js | 102 ++++- .../agentFlowRuntime/viewController.js | 15 +- .../test/analysis/agentFlowRuntime.test.cjs | 26 ++ .../baseline/featureBaseline.snapshot.json | 1 + .../test/runners/run-agent-flow-harness.cjs | 69 +++ docs/agent-flow/hangar.md | 74 ++++ docs/agent-flow/test-guide.md | 20 +- docs/agent-flow/ufo.md | 4 +- 17 files changed, 949 insertions(+), 127 deletions(-) create mode 100644 apps/vscode-extension/templates/components/codexr/agent-flow/agentFlowRuntime/airfield.js create mode 100644 docs/agent-flow/hangar.md diff --git a/apps/vscode-extension/CHANGELOG.md b/apps/vscode-extension/CHANGELOG.md index 91ed0fc7..744d7007 100644 --- a/apps/vscode-extension/CHANGELOG.md +++ b/apps/vscode-extension/CHANGELOG.md @@ -24,6 +24,7 @@ - A function the agent writes from scratch gets a new floor, built in front of you when the step plays. - 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. + - Sub-agent hangar: when the agent delegates, its UFO docks on the control tower and coordinates; each sub-agent waits in a hangar beside it, takes off on its first step, stays linked to the tower by a radio line and lands back in its bay when done. The hangar and the tower have their own pinnable cards. - The timeline is time travel: at any step the city shows the project as it was then, and playing forward builds each change. - Files created, deleted, moved or renamed appear and disappear in their step, whatever tool did it: shell commands (`rm`, `git rm`, `mv`, `git mv`, `cp`, `touch`, `> file`, `tee`, `sed -i` and their PowerShell and cmd forms), Codex patches (including moves) and the IDE's agents. - A function the agent deletes keeps its floor until that step, then the floor comes down. diff --git a/apps/vscode-extension/templates/components/COMPONENTS.md b/apps/vscode-extension/templates/components/COMPONENTS.md index 00c6717f..647903e5 100644 --- a/apps/vscode-extension/templates/components/COMPONENTS.md +++ b/apps/vscode-extension/templates/components/COMPONENTS.md @@ -76,7 +76,7 @@ its parts directory. Manual harnesses load assembled copies from - `codexr/agent-flow/agentFlowRuntime.js` (loads right after the dependency graph runtime) - Owns the Agent Flow mode (#319): an AI coding agent's session replayed or followed live on the table. See `docs/features/AGENT_FLOW_XR.md`. - Registers `codexr-city`, Code-XR's own city chart (layout and look modeled on babia-boats from BabiaXR, GPL-3.0): nested folder plates and instanced buildings, with an API (`getBuildingTop`, `setBuildingHeight`, `addScaffold`, `setRoofTint`, `demolish`, `raise`, `setFoundation`, `setHazard`, ...) that the worker and effect layer goes through instead of reaching into entities. - - Draws one worker per actor (the main agent and each sub-agent), their actions (scan, radar, scaffold and crane, test tower, permission sign), the timeline and the controller view `agent-flow`. Persistent marks are recomputed from the playhead, so seeking is exact; live effects are capped at 40 and workers at 12; reduced motion draws everything static. + - Draws one worker per actor (the main agent and each sub-agent), their actions (scan, radar, scaffold and crane, test tower, permission sign), the sub-agent airfield (control tower dock, hangar bays, radio links; airfield.js), the timeline and the controller view `agent-flow`. Persistent marks are recomputed from the playhead, so seeking is exact; live effects are capped at 40 and workers at 12; reduced motion draws everything static. - Room messages: `agent-flow-sources-request`, `agent-flow-open`, `agent-flow-close` -> `agent-flow-sources`, `agent-flow-error`; shared entity `agent-flow`. Pinned by `test/analysis/agentFlowRuntime.test.cjs` and the harness `test/runners/run-agent-flow-harness.cjs`. - `codexr/drill-down/drillDownRuntime.js` (loads right after the Agent Flow runtime) - Owns the drill-down navigation (#333): pick a building or a district of a boats chart, choose Analyze, and the table switches in place to the analysis of that file or folder, on the same server. See `docs/features/DRILL_DOWN_XR.md`. diff --git a/apps/vscode-extension/templates/components/codexr/agent-flow/agentFlowRuntime/agentEffects.js b/apps/vscode-extension/templates/components/codexr/agent-flow/agentFlowRuntime/agentEffects.js index 24c0a826..02ceccdb 100644 --- a/apps/vscode-extension/templates/components/codexr/agent-flow/agentFlowRuntime/agentEffects.js +++ b/apps/vscode-extension/templates/components/codexr/agent-flow/agentFlowRuntime/agentEffects.js @@ -302,19 +302,6 @@ }); } - /** The main worker hands work over: a bright beam to the newborn worker. */ - function delegateBeam(v, from, to, color, durationMs) { - var T = three(); - var curve = new T.QuadraticBezierCurve3( - new T.Vector3(from.x, from.y + 0.05, from.z), - new T.Vector3((from.x + to.x) / 2, Math.max(from.y, to.y) + 0.18, (from.z + to.z) / 2), - new T.Vector3(to.x, to.y + 0.05, to.z) - ); - var beam = new T.Mesh(new T.TubeGeometry(curve, 20, 0.004, 6, false), - new T.MeshBasicMaterial({ color: color, transparent: true, opacity: 0.95, depthWrite: false, blending: T.AdditiveBlending })); - addEffect(v, beam, durationMs, function (t) { beam.material.opacity = 0.95 * (1 - t * t); }); - } - /** One-shot effects when a worker arrives for a step (motion only). */ function spawnArrivalEffects(v, step, durationMs, spot) { if (!step || !state.motion) { return; } diff --git a/apps/vscode-extension/templates/components/codexr/agent-flow/agentFlowRuntime/airfield.js b/apps/vscode-extension/templates/components/codexr/agent-flow/agentFlowRuntime/airfield.js new file mode 100644 index 00000000..dc3082b7 --- /dev/null +++ b/apps/vscode-extension/templates/components/codexr/agent-flow/agentFlowRuntime/airfield.js @@ -0,0 +1,405 @@ +// == agentFlowRuntime.js | airfield (assembled per manifest.json; see COMPONENTS.md) == + // The sub-agents' airfield in the front-left corner (story #453): the test + // tower doubles as the control tower, and a hangar stands beside it. When + // the main agent delegates it docks on top of the tower and coordinates + // (radar ring, `control` outfit); each sub-agent waits in its hangar bay, + // takes off from its pad on its first step, flies its work and lands back + // in its bay when it is done. A dashed radio link joins every sub-agent out + // to the agent that sent it, and each of its steps sends a packet home. + // Doors, bay lights and the radar are recomputed from the playhead + // (syncAirfield), so seeking is exact; flights and packets are transient. + + var AIRFIELD_SEGMENTS = 28; + var LINK_POINTS = 24; + var BAY_COLORS = { idle: '#334155', ready: '#fbbf24', out: '#38bdf8', failed: '#ef4444' }; + + /** Hangar footprint for the session's bays: { x, z (centre), width, length, height, bays }. */ + function hangarShape(v) { + var bays = Math.max(1, v.timeline?.hangar?.bays || 0); + var width = bays * HANGAR.bayWidth + 2 * HANGAR.margin; + return { x: HANGAR.x, z: HANGAR.frontZ - width / 2, width: width, length: HANGAR.length, height: HANGAR.height, bays: bays }; + } + + /** Centre z of a bay (bays side by side across the mouth). */ + function bayZ(shape, bay) { + return shape.z + (bay - (shape.bays - 1) / 2) * HANGAR.bayWidth; + } + + function slotOf(v, actorIndex) { + return v.timeline?.hangar?.slots?.[actorIndex] || { bay: 0, row: 0 }; + } + + /** Where a sub-agent waits inside the hangar (rows queue deeper inside). */ + function baySpot(v, actorIndex) { + var shape = hangarShape(v); + var slot = slotOf(v, actorIndex); + var x = shape.x + shape.length * 0.12 - slot.row * 0.09; + return { x: Math.max(shape.x - shape.length / 2 + 0.05, x), y: 0.022, z: bayZ(shape, slot.bay), ground: null, bay: true }; + } + + /** Its launch pad on the apron in front of its bay. */ + function padSpot(v, actorIndex) { + var shape = hangarShape(v); + var slot = slotOf(v, actorIndex); + return { x: shape.x + shape.length / 2 + HANGAR.apron * 0.5, y: 0.024, z: bayZ(shape, slot.bay), ground: null }; + } + + /** The main agent's dock on top of the control tower. */ + function towerDock() { + return { x: CONSOLE_PILLAR.x, y: CONSOLE_PILLAR.height + 0.1, z: CONSOLE_PILLAR.z, ground: null, dock: true }; + } + + function halfArchPoints(shape, x, from, to) { + var points = []; + for (var i = 0; i <= AIRFIELD_SEGMENTS; i += 1) { + var angle = from + (to - from) * (i / AIRFIELD_SEGMENTS); + points.push(x, Math.sin(angle) * shape.height, shape.z + Math.cos(angle) * shape.width / 2); + } + return points; + } + + function lineStrip(v, points, color, opacity) { + var T = three(); + var geometry = track(v, new T.BufferGeometry()); + geometry.setAttribute('position', new T.Float32BufferAttribute(points, 3)); + return new T.Line(geometry, track(v, new T.LineBasicMaterial({ color: color, transparent: opacity < 1, opacity: opacity }))); + } + + /** Half an ellipse (or a quarter) in the zy plane, for the back wall and the two doors. */ + function archPanel(v, shape, thetaStart, thetaLength, material) { + var T = three(); + var geometry = new T.CircleGeometry(1, AIRFIELD_SEGMENTS, thetaStart, thetaLength); + // xy-plane disc to the zy plane ((cos t, sin t) -> z = -cos t, y = sin t), stretched to the arch. + geometry.rotateY(Math.PI / 2); + geometry.scale(1, shape.height, shape.width / 2); + return new T.Mesh(track(v, geometry), material); + } + + /** An invisible box the pointer can hit (attached to the raycastable buildings entity). */ + function hitBox(v, name, centre, size) { + var T = three(); + var mesh = new T.Mesh(unitBoxGeometry(v), track(v, new T.MeshBasicMaterial({ transparent: true, opacity: 0, depthWrite: false, colorWrite: false }))); + mesh.name = 'agentFlowStation'; + mesh.userData.station = name; + mesh.scale.set(size.x, size.y, size.z); + mesh.position.set(centre.x, centre.y, centre.z); + return mesh; + } + + function buildAirfield(v) { + var T = three(); + var shape = hangarShape(v); + var group = new T.Group(); + group.name = 'agentFlowAirfield'; + var front = shape.x + shape.length / 2; + var back = shape.x - shape.length / 2; + // The vault: an open half cylinder along x, squashed to the hangar's height. + // (A cylinder's side runs (sin t, y, cos t): t in [0, pi] is its +x half, + // which turning the axis onto x stands up as the vault.) + var shellGeometry = new T.CylinderGeometry(1, 1, shape.length, AIRFIELD_SEGMENTS, 1, true, 0, Math.PI); + shellGeometry.rotateZ(Math.PI / 2); + shellGeometry.scale(1, shape.height, shape.width / 2); + var shell = new T.Mesh(track(v, shellGeometry), track(v, new T.MeshStandardMaterial({ + color: '#94a3b8', roughness: 0.45, metalness: 0.35, side: T.DoubleSide, flatShading: true + }))); + shell.position.set(shape.x, 0, shape.z); + group.add(shell); + var ribShape = { height: shape.height + 0.002, width: shape.width + 0.004, z: shape.z }; + for (var r = 0; r <= 4; r += 1) { + group.add(lineStrip(v, halfArchPoints(ribShape, back + (r / 4) * shape.length, 0, Math.PI), '#475569', 1)); + } + // Inside: a warm back wall and a dark floor with one marked bay per sub-agent slot. + var wall = archPanel(v, shape, 0, Math.PI, track(v, new T.MeshStandardMaterial({ color: '#1e293b', emissive: '#f59e0b', emissiveIntensity: 0.18, roughness: 0.8, side: T.DoubleSide }))); + wall.position.set(back + 0.002, 0, shape.z); + group.add(wall); + var floor = new T.Mesh(unitBoxGeometry(v), track(v, new T.MeshStandardMaterial({ color: '#111827', roughness: 0.9 }))); + floor.scale.set(shape.length, 0.004, shape.width); + floor.position.set(shape.x, 0.002, shape.z); + group.add(floor); + var apron = new T.Mesh(unitBoxGeometry(v), track(v, new T.MeshStandardMaterial({ color: '#1f2937', roughness: 0.9 }))); + apron.scale.set(HANGAR.apron, 0.003, shape.width); + apron.position.set(front + HANGAR.apron / 2, 0.0015, shape.z); + group.add(apron); + var bays = []; + for (var b = 0; b < shape.bays; b += 1) { + var z = bayZ(shape, b); + var lampMaterial = track(v, new T.MeshBasicMaterial({ color: BAY_COLORS.idle })); + // The bay light: a strip across the bay's mouth, and the pad ring outside. + var strip = new T.Mesh(unitBoxGeometry(v), lampMaterial); + strip.scale.set(0.012, 0.004, HANGAR.bayWidth * 0.7); + strip.position.set(front - 0.012, 0.006, z); + var pad = new T.Mesh(new T.RingGeometry(0.036, 0.044, 32), lampMaterial); + track(v, pad.geometry); + pad.rotation.x = -Math.PI / 2; + pad.position.set(front + HANGAR.apron * 0.5, 0.0045, z); + var guide = []; + for (var j = 0; j < 3; j += 1) { + var light = new T.Mesh(unitBoxGeometry(v), track(v, new T.MeshBasicMaterial({ color: '#fbbf24' }))); + light.scale.set(0.007, 0.004, 0.007); + light.position.set(front + 0.025 + j * 0.035, 0.005, z + 0.052); + group.add(light); + guide.push(light); + } + group.add(strip, pad); + bays.push({ material: lampMaterial, state: 'idle' }); + } + // Two doors, a quarter ellipse each, sliding sideways off the mouth. + var doorMaterial = track(v, new T.MeshStandardMaterial({ color: '#64748b', roughness: 0.5, metalness: 0.4, side: T.DoubleSide, flatShading: true })); + var doors = [archPanel(v, shape, 0, Math.PI / 2, doorMaterial), archPanel(v, shape, Math.PI / 2, Math.PI / 2, doorMaterial)]; + // A disc's angle t lands at z = -cos t after the turn: door 0 is the -z half, door 1 the +z half. + doors.forEach(function (door) { door.position.set(front + 0.004, 0, shape.z); group.add(door); }); + // The radar ring around the tower cab while the main agent controls from it. + var dock = towerDock(); + var radarMaterial = track(v, new T.MeshBasicMaterial({ color: kindColor('delegate'), transparent: true, opacity: 0, depthWrite: false, side: T.DoubleSide, blending: T.AdditiveBlending })); + var radar = new T.Mesh(sharedRingGeometry(v), radarMaterial); + radar.position.set(dock.x, CONSOLE_PILLAR.height + 0.08, dock.z); + radar.visible = false; + var sweep = new T.Mesh(sharedRingGeometry(v), radarMaterial.clone()); + track(v, sweep.material); + sweep.position.copy(radar.position); + sweep.visible = false; + group.add(radar, sweep); + v.group.add(group); + var label = text('hangar', shape.x + ' 0.03 ' + (shape.z - shape.width / 2 - 0.06), 0.9, '#94a3b8', 'center', 20); + label.setAttribute('rotation', '-60 0 0'); + v.rootEl.appendChild(label); + // What the pointer hits for the hangar's and the tower's legends. + var hits = new T.Group(); + hits.name = 'agentFlowStations'; + hits.add(hitBox(v, 'hangar', { x: shape.x + HANGAR.apron / 2, y: shape.height / 2, z: shape.z }, { x: shape.length + HANGAR.apron, y: shape.height, z: shape.width })); + hits.add(hitBox(v, 'tower', { x: CONSOLE_PILLAR.x, y: (CONSOLE_PILLAR.height + 0.09) / 2, z: CONSOLE_PILLAR.z }, { x: 0.2, y: CONSOLE_PILLAR.height + 0.09, z: 0.2 })); + var attach = function () { v.buildingsEl?.setObject3D?.('stations', hits); }; + if (v.buildingsEl?.hasLoaded || typeof v.buildingsEl?.setObject3D === 'function') { attach(); } else { v.buildingsEl?.addEventListener?.('loaded', attach, { once: true }); } + v.airfield = { + group: group, shape: shape, doors: doors, doorOpen: 0, doorTarget: 0, bays: bays, radar: radar, sweep: sweep, + radarOn: false, radarPhase: 0, label: label, hits: hits, links: {}, packets: [], state: null + }; + } + + function destroyAirfield(v) { + var airfield = v?.airfield; + if (!airfield) { return; } + airfield.packets.forEach(function (packet) { airfield.group.remove(packet.mesh); disposeObject(packet.mesh); }); + v.buildingsEl?.removeObject3D?.('stations'); + airfield.label?.parentNode?.removeChild?.(airfield.label); + v.group.remove(airfield.group); + v.airfield = null; + } + + /** Doors, bay lights and the radar from the playhead (workersAt). */ + function syncAirfield(v, workers) { + var airfield = v.airfield; + if (!airfield) { return; } + var field = airfieldAt(v.timeline, workers); + airfield.state = field; + airfield.doorTarget = field.doorsOpen ? 1 : 0; + if (!state.motion) { airfield.doorOpen = airfield.doorTarget; placeDoors(airfield); } + field.bays.forEach(function (bay, index) { + var slot = airfield.bays[index]; + if (!slot) { return; } + slot.state = bay.state; + slot.material.color.set(BAY_COLORS[bay.state] || BAY_COLORS.idle); + }); + airfield.radarOn = field.controller >= 0; + airfield.controlling = field.controller >= 0 + ? workers.filter(function (info) { return info.parent === field.controller && (info.present || info.docked); }).length + : 0; + } + + function placeDoors(airfield) { + var shape = airfield.shape; + var slide = easeInOutCubic(airfield.doorOpen) * (shape.width / 2 + 0.004); + airfield.doors[0].position.z = shape.z - slide; + airfield.doors[1].position.z = shape.z + slide; + } + + /** True while a flight to or from the hangar keeps the doors open. */ + function hangarTraffic(v) { + return (v.workers || []).some(function (worker) { return !!worker?.hop && !!worker.landing; }); + } + + function tickAirfield(v, dt, timeMs) { + var airfield = v.airfield; + if (!airfield) { return; } + var target = airfield.doorTarget || (hangarTraffic(v) ? 1 : 0); + if (airfield.doorOpen !== target) { + airfield.doorOpen = state.motion ? approach(airfield.doorOpen, target, dt / 600) : target; + placeDoors(airfield); + } + airfield.radar.visible = airfield.radarOn; + airfield.sweep.visible = airfield.radarOn && state.motion; + if (airfield.radarOn) { + airfield.radar.scale.setScalar(0.11); + airfield.radar.material.opacity = 0.55; + if (state.motion) { + airfield.radarPhase = (airfield.radarPhase + dt / 1400) % 1; + airfield.sweep.scale.setScalar(0.11 + 0.14 * airfield.radarPhase); + airfield.sweep.material.opacity = 0.5 * (1 - airfield.radarPhase); + } + } + tickLinks(v); + tickPackets(v, dt); + } + + // -- Radio links between a sub-agent out and the agent that sent it ---------- + + function linkFor(v, actorIndex, color) { + var airfield = v.airfield; + if (airfield.links[actorIndex]) { return airfield.links[actorIndex]; } + var T = three(); + var geometry = track(v, new T.BufferGeometry()); + geometry.setAttribute('position', new T.Float32BufferAttribute(new Array(LINK_POINTS * 3).fill(0), 3)); + var line = new T.Line(geometry, track(v, new T.LineDashedMaterial({ color: color, dashSize: 0.035, gapSize: 0.022, transparent: true, opacity: 0.85, depthWrite: false }))); + line.name = 'agentFlowRadioLink-' + actorIndex; + line.visible = false; + line.frustumCulled = false; + airfield.group.add(line); + airfield.links[actorIndex] = { line: line, color: color }; + return airfield.links[actorIndex]; + } + + /** The curve of a link: from the controller's antenna up and over to the sub-agent. */ + function linkCurve(from, to) { + var top = { x: from.x, y: from.y + 0.03, z: from.z }; + var distance = Math.hypot(to.x - top.x, to.z - top.z); + var control = { x: (top.x + to.x) / 2, y: Math.max(top.y, to.y) + 0.08 + distance * 0.05, z: (top.z + to.z) / 2 }; + return { from: top, control: control, to: to }; + } + + /** The sub-agents out that report to a worker on the table: [{ actor, parent }]. */ + function radioPairs(v) { + var pairs = []; + (v.workerInfo || []).forEach(function (info) { + if (!info.present || info.parent === null || info.parent === undefined) { return; } + var worker = v.workers?.[info.actor]; + var parent = v.workers?.[info.parent]; + if (!worker?.group.visible || !parent?.group.visible || worker.landing) { return; } + pairs.push({ actor: info.actor, worker: worker, parent: parent }); + }); + return pairs; + } + + function tickLinks(v) { + var airfield = v.airfield; + var live = {}; + radioPairs(v).forEach(function (pair) { + var link = linkFor(v, pair.actor, pair.worker.color); + var curve = linkCurve(pair.parent.group.position, pair.worker.group.position); + var positions = link.line.geometry.attributes.position; + for (var i = 0; i < LINK_POINTS; i += 1) { + var p = bezierPoint(curve.from, curve.control, curve.to, i / (LINK_POINTS - 1)); + positions.setXYZ(i, p.x, p.y, p.z); + } + positions.needsUpdate = true; + link.line.computeLineDistances(); + link.line.visible = true; + link.curve = curve; + live[pair.actor] = true; + }); + Object.keys(airfield.links).forEach(function (key) { + if (!live[key]) { airfield.links[key].line.visible = false; airfield.links[key].curve = null; } + }); + } + + /** A sub-agent's step: a packet runs home along its link (a report). */ + function sendPacket(v, actorIndex, durationMs) { + var airfield = v.airfield; + if (!airfield || !state.motion || !canSpawn(v)) { return; } + var link = airfield.links[actorIndex]; + var T = three(); + var mesh = new T.Mesh(sharedGeometry(v, 'packet', function () { return new T.SphereGeometry(0.009, 10, 8); }), + new T.MeshBasicMaterial({ color: actorColor(actorIndex) })); + mesh.visible = false; + airfield.group.add(mesh); + airfield.packets.push({ mesh: mesh, actor: actorIndex, t: 0, dur: Math.max(400, durationMs), link: link }); + } + + function tickPackets(v, dt) { + var airfield = v.airfield; + if (!airfield.packets.length) { return; } + airfield.packets = airfield.packets.filter(function (packet) { + packet.t = Math.min(1, packet.t + dt / packet.dur); + var curve = airfield.links[packet.actor]?.curve; + if (curve) { + // Home: from the sub-agent back to the controller. + var p = bezierPoint(curve.to, curve.control, curve.from, easeInOutCubic(packet.t)); + packet.mesh.position.set(p.x, p.y, p.z); + packet.mesh.visible = true; + } + if (packet.t >= 1 || !curve) { + airfield.group.remove(packet.mesh); + disposeObject(packet.mesh); + return false; + } + return true; + }); + } + + /** Test hook: the airfield as plain data (doors settle to their target). */ + function airfieldSnapshot(v) { + var airfield = v?.airfield; + if (!airfield?.state) { return null; } + return { + doors: airfield.doorTarget, + bays: airfield.state.bays.map(function (bay) { return bay.state; }), + controller: airfield.state.controller, + links: Object.keys(airfield.links).filter(function (key) { return airfield.links[key].line.visible; }).map(Number).sort() + }; + } + + // -- Legends of the stations (hangar, control tower) ------------------------- + + function stationAnchor(v, station) { + if (station === 'hangar') { + var shape = hangarShape(v); + return { x: shape.x, y: shape.height, z: shape.z }; + } + return { x: CONSOLE_PILLAR.x, y: CONSOLE_PILLAR.height + 0.09, z: CONSOLE_PILLAR.z }; + } + + function subagentStatus(v, info) { + if (info.docked) { return 'in bay'; } + var lane = v.timeline.actors[info.actor]; + var done = lane ? lane.steps.filter(function (index) { return index <= (v.cityState?.stepIndex ?? -1); }).length : 0; + if (info.present) { return 'out ' + done + ' steps'; } + if (info.finished) { return (v.timeline.steps[lane.lastIndex]?.failed ? 'failed ' : 'back ') + done + ' steps'; } + return 'not yet'; + } + + function stationCardModel(v, station, pinned) { + var workers = v.workerInfo || workersAt(v.timeline, v.cityState?.stepIndex ?? -1); + var subs = workers.filter(function (info) { return v.timeline.actors[info.actor]?.kind !== 'main'; }); + if (station === 'hangar') { + var out = subs.filter(function (info) { return info.present; }).length; + var docked = subs.filter(function (info) { return info.docked; }).length; + var back = subs.filter(function (info) { return info.finished; }).length; + var rows = subs.slice(0, 8).map(function (info) { + return { label: compact(v.timeline.actors[info.actor].label, 14), value: subagentStatus(v, info) }; + }); + if (!rows.length) { rows.push({ label: 'Sub-agents', value: 'none' }); } + return { + title: 'Hangar', + subtitle: (pinned ? 'Pinned ' : '') + out + ' out ' + docked + ' in bay ' + back + ' back', + accentColor: kindColor('delegate'), + rows: rows + }; + } + var at = v.cityState?.stepIndex ?? -1; + var runs = 0; + var lastRun = null; + for (var i = 0; i <= at && i < v.timeline.count; i += 1) { + if (v.timeline.steps[i].kind === 'execute') { runs += 1; lastRun = v.timeline.steps[i]; } + } + var controlling = v.airfield?.controlling || 0; + return { + title: 'Control tower', + subtitle: (pinned ? 'Pinned ' : '') + (controlling ? 'Controlling ' + controlling + (controlling === 1 ? ' sub-agent' : ' sub-agents') : 'Runs and sub-agents'), + accentColor: controlling ? kindColor('delegate') : (lastRun ? (lastRun.failed ? COLORS.executeFailed : COLORS.executeOk) : ACCENT), + rows: [ + { label: 'Runs', value: String(runs) }, + { label: 'Last run', value: lastRun ? (lastRun.failed ? 'failed' : 'ok') : '-' }, + { label: 'Controlling', value: String(controlling) }, + { label: 'Sub-agents', value: String(subs.filter(function (info) { return info.present || info.docked || info.finished; }).length) } + ] + }; + } diff --git a/apps/vscode-extension/templates/components/codexr/agent-flow/agentFlowRuntime/configAndState.js b/apps/vscode-extension/templates/components/codexr/agent-flow/agentFlowRuntime/configAndState.js index 128fbfda..4806515f 100644 --- a/apps/vscode-extension/templates/components/codexr/agent-flow/agentFlowRuntime/configAndState.js +++ b/apps/vscode-extension/templates/components/codexr/agent-flow/agentFlowRuntime/configAndState.js @@ -29,6 +29,12 @@ var TIMELINE = { width: 4.4, height: 0.5, x: 0, y: 0.13, z: 1.66, tilt: -58 }; // Front-left corner: commands are about the whole project, not one file. var CONSOLE_PILLAR = { x: -2.78, z: 1.2, height: 0.36, radius: 0.07 }; + // The sub-agents' hangar, beside the tower (the tower doubles as the control + // tower the main agent coordinates them from): a vaulted shed along x with + // its mouth to the city (+x) and launch pads on the apron in front. Its + // width grows with the bays (one per sub-agent out at the same time, 1-4); + // its front edge (+z) stays clear of the tower. + var HANGAR = { x: -2.86, frontZ: 0.98, length: 0.4, height: 0.15, bayWidth: 0.13, margin: 0.06, apron: 0.28, maxBays: 4 }; var TRAIL_HOPS = 24; var HOP_SAMPLES = 10; var BASE_STEP_MS = 900; diff --git a/apps/vscode-extension/templates/components/codexr/agent-flow/agentFlowRuntime/constructionSite.js b/apps/vscode-extension/templates/components/codexr/agent-flow/agentFlowRuntime/constructionSite.js index 73f87667..744ae817 100644 --- a/apps/vscode-extension/templates/components/codexr/agent-flow/agentFlowRuntime/constructionSite.js +++ b/apps/vscode-extension/templates/components/codexr/agent-flow/agentFlowRuntime/constructionSite.js @@ -17,7 +17,8 @@ // saucers crossing each other never meet. var UFO_LAYER_STEP = 0.03; - // -- Test tower (the control station every run goes to) ----------------------- + // -- Test tower (the control station every run goes to; also the control tower + // the main agent coordinates its sub-agents from, see airfield.js) ---------- function buildTestTower(v) { var T = three(); @@ -92,7 +93,7 @@ v.tower = { group: tower, lights: lights, siren: siren, sirenGlow: sirenGlow, beamPivot: beamPivot, check: check, mode: 'idle', since: 0, phase: 0 }; v.pillar = { body: cabin, cap: deck, material: cabinMaterial, idleCap: '#64748b', flash: null, lastColor: null }; // At the foot of the tower, so it never collides with a worker's name tag on the deck. - var label = text('test tower', x + ' 0.03 ' + (z + 0.17), 0.9, '#94a3b8', 'center', 20); + var label = text('control tower', x + ' 0.03 ' + (z + 0.17), 0.9, '#94a3b8', 'center', 20); label.setAttribute('rotation', '-60 0 0'); v.rootEl.appendChild(label); v.pillarLabel = label; @@ -289,7 +290,7 @@ v.rootEl.appendChild(tag); return { actor: lane.index, lane: lane, color: lane.color, group: group, body: body, ring: ring, lights: lights, glow: glow, tag: tag, beam: beam, - scale: scale, rest: null, hop: null, phase: lane.index * 1.7, present: false, pop: 1, dissolve: null, + scale: scale, rest: null, hop: null, phase: lane.index * 1.7, present: false, docked: false, landing: false, route: null, pop: 1, props: [], propKey: '', spot: null, beamColor: lane.color, bank: { x: 0, z: 0 }, materials: { paint: paint, glass: glass, under: under, ring: ringMaterial, lamp: lampMaterial, glow: glow.material }, skin: { key: '', color: lane.color, from: null, t: 1, outfits: {} } }; @@ -338,7 +339,10 @@ if (memo && memo[stepIndex]) { return memo[stepIndex]; } var step = v.timeline.steps[stepIndex]; var spot = null; - if (step) { + if (step && step.kind === 'delegate' && v.timeline.actors[step.actor]?.kind === 'main') { + // Delegating: the main agent docks on top of the control tower and coordinates from there. + spot = towerDock(); + } else if (step) { var slot = slotOffset(step.actor); var ground = null; if (step.target.type === 'console') { @@ -370,19 +374,29 @@ return spot; } - /** Before its first step: the main agent waits at home, a subagent beside the worker that spawned it. */ - function startSpot(v, actorIndex, memo) { + /** Before its first step: the main agent waits at home, a sub-agent in its hangar bay. */ + function startSpot(v, actorIndex) { var lane = v.timeline.actors[actorIndex]; - var altitude = cruiseAltitude(v, actorIndex); - if (!lane || lane.kind === 'main') { return { x: MAIN_HOME.x, y: altitude, z: MAIN_HOME.z, ground: null }; } - var parentSpot = (lane.spawnIndex >= 0 ? spotForStep(v, lane.spawnIndex, memo) : null) || MAIN_HOME; - var slot = slotOffset(actorIndex); - return { x: parentSpot.x + slot.x * 2.2, y: altitude, z: parentSpot.z + slot.z * 2.2, ground: null }; + if (!lane || lane.kind === 'main') { return { x: MAIN_HOME.x, y: cruiseAltitude(v, actorIndex), z: MAIN_HOME.z, ground: null }; } + return baySpot(v, actorIndex); } function workerSpot(v, info, memo) { + if (info.docked) { return baySpot(v, info.actor); } if (!info.present) { return null; } - return info.step ? spotForStep(v, info.stepIndex, memo) : startSpot(v, info.actor, memo); + return info.step ? spotForStep(v, info.stepIndex, memo) : startSpot(v, info.actor); + } + + /** Shows a worker parked in its bay (docked: lit, no name tag) or hides it. */ + function showDocked(v, worker, info) { + worker.present = false; + worker.docked = true; + worker.landing = false; + worker.group.visible = true; + setNodeVisible(worker.tag, false); + var bay = baySpot(v, info.actor); + worker.rest = bay; + setWorkerPosition(worker, bay); } function setWorkerPosition(worker, point) { @@ -393,11 +407,18 @@ function placeWorkersAt(v, index, workers) { var memo = {}; workers.forEach(function (info) { - var worker = info.present ? ensureWorker(v, info.actor) : v.workers?.[info.actor]; + var worker = info.present || info.docked ? ensureWorker(v, info.actor) : v.workers?.[info.actor]; if (!worker) { return; } worker.hop = null; - worker.dissolve = null; + worker.route = null; + worker.landing = false; worker.pop = 1; + if (info.docked) { + showDocked(v, worker, info); + worker.group.scale.setScalar(worker.scale); + return; + } + worker.docked = false; worker.present = info.present; var spot = workerSpot(v, info, memo); if (spot) { worker.rest = spot; setWorkerPosition(worker, spot); } @@ -416,7 +437,7 @@ var step = v.timeline.steps[i]; if (!step || step.target.type === 'none') { continue; } var spot = spotForStep(v, i, memo); - var from = previous[step.actor] || (step.actorPrev !== null ? spotForStep(v, step.actorPrev, memo) : startSpot(v, step.actor, memo)); + var from = previous[step.actor] || (step.actorPrev !== null ? spotForStep(v, step.actorPrev, memo) : startSpot(v, step.actor)); // Each leg of the flight in the colour of what the UFO flew there to do. if (spot && from) { hops.push({ from: lift(from), to: lift(spot), color: actionColor(v, step) }); } previous[step.actor] = spot; @@ -430,60 +451,94 @@ /** * Forward single step: the stepping worker hops to its new spot (the - * transport waits for that hop), a delegate pops the new worker out of the - * main one, and a finished subagent flies back to the main worker and - * dissolves. Other workers keep working where they are. + * transport waits for that hop). A delegate lights a sub-agent up in its + * hangar bay; on its first step it taxis out to its pad and lifts off; a + * finished sub-agent flies back, lands on its pad and rolls into its bay. + * A sub-agent's step also sends a packet home along its radio link. Other + * workers keep working where they are. */ function animateWorkers(v, index, workers, step, durationMs, onDone) { var memo = {}; - var mainSpot = null; - var main = workers[0]; - if (main) { mainSpot = workerSpot(v, main, memo); } var waited = false; workers.forEach(function (info) { - var worker = info.present ? ensureWorker(v, info.actor) : v.workers?.[info.actor]; + var worker = info.present || info.docked ? ensureWorker(v, info.actor) : v.workers?.[info.actor]; if (!worker) { return; } var spot = workerSpot(v, info, memo); var stepping = step && info.actor === step.actor; + if (info.docked) { + if (!worker.docked) { + // Called in: the bay lights up and its saucer powers on. + showDocked(v, worker, info); + worker.pop = state.motion ? 0 : 1; + } + return; + } if (!info.present) { - if (worker.present && state.motion && mainSpot) { - // Done: back to the main worker, then dissolve. - startHop(v, worker, mainSpot, durationMs, null, true); - worker.dissolve = { t: 0 }; + if (worker.present && state.motion && worker.lane.kind !== 'main') { + // Done: back to the airfield, down on its pad, into its bay. + var pad = padSpot(v, info.actor); + var from = worker.group.position; + worker.landing = true; + startRoute(v, worker, [ + { to: pad, share: 0.75, control: { x: pad.x, y: from.y, z: pad.z }, silent: true }, + { to: baySpot(v, info.actor), share: 0.25, silent: true } + ], durationMs * 2.2, null, null, function () { parkWorker(v, worker); }); } else { - worker.group.visible = false; - setNodeVisible(worker.tag, false); + parkWorker(v, worker); } worker.present = false; + worker.docked = false; return; } var appearing = !worker.present; + var fromHangar = appearing && worker.lane.kind !== 'main'; + var wasShown = worker.group.visible; worker.present = true; - worker.dissolve = null; + worker.docked = false; worker.group.visible = true; setNodeVisible(worker.tag, true); - if (appearing) { - // Born from the main UFO (or, for the main agent, coming down from higher up). - var origin = info.actor === 0 ? { x: spot.x, y: spot.y + 0.2, z: spot.z } : (v.workers[0]?.rest || mainSpot || spot); + if (appearing && !fromHangar) { + // The main agent comes down from higher up. + var origin = { x: spot.x, y: spot.y + 0.2, z: spot.z }; worker.rest = origin; setWorkerPosition(worker, origin); worker.pop = state.motion ? 0 : 1; - if (info.actor !== 0 && state.motion) { delegateBeam(v, origin, spot, worker.color, durationMs * 2.5); } + } else if (fromHangar && !wasShown) { + worker.pop = state.motion ? 0 : 1; + } + if (fromHangar && (!worker.rest || !worker.rest.bay)) { + // Never seen docked (a dataset without its delegate): it starts in its bay all the same. + var bay = baySpot(v, info.actor); + worker.rest = bay; + setWorkerPosition(worker, bay); } if (!spot) { return; } + var color = actionColor(v, info.step) || worker.color; if (!state.motion || samePoint(worker.rest, spot)) { - if (worker.rest && !samePoint(worker.rest, spot) && stepping) { pushTrailHop(v, lift(worker.rest), lift(spot), actionColor(v, info.step) || worker.color); } + if (worker.rest && !samePoint(worker.rest, spot) && stepping) { pushTrailHop(v, lift(worker.rest), lift(spot), color); } worker.rest = spot; setWorkerPosition(worker, spot); return; } + if (fromHangar) { + // Taxi to the pad, then a vertical lift-off curving into the cruise. + var launchPad = padSpot(v, info.actor); + worker.landing = true; + startRoute(v, worker, [ + { to: launchPad, share: 0.3, silent: true }, + { to: spot, share: 0.7, control: { x: launchPad.x, y: spot.y, z: launchPad.z } } + ], durationMs * 1.8, stepping ? onDone : null, color, function () { worker.landing = false; }); + if (stepping) { waited = true; } + return; + } if (stepping) { waited = true; - startHop(v, worker, spot, durationMs, onDone, false, actionColor(v, info.step)); + startHop(v, worker, spot, durationMs, onDone, false, color); } else { - startHop(v, worker, spot, durationMs * 1.4, null, false, actionColor(v, info.step)); + startHop(v, worker, spot, durationMs * 1.4, null, false, color); } }); + if (step && v.timeline.actors[step.actor]?.kind !== 'main') { sendPacket(v, step.actor, durationMs * 3); } refreshTrail(v); if (!waited) { var arrived = step ? workerSpot(v, workers[step.actor] || {}, memo) : null; @@ -492,9 +547,38 @@ } } - function startHop(v, worker, to, durationMs, onDone, silent, color) { + /** Back in its bay: hidden behind the closing doors. */ + function parkWorker(v, worker) { + worker.landing = false; + worker.docked = false; + worker.route = null; + worker.group.visible = false; + setNodeVisible(worker.tag, false); + } + + function startHop(v, worker, to, durationMs, onDone, silent, color, control) { var from = worker.rest || to; - worker.hop = { from: from, to: to, t: 0, eased: 0, dur: Math.max(140, durationMs), onDone: onDone, silent: !!silent, liftFrom: lift(from), liftTo: lift(to), color: color || worker.color }; + worker.hop = { from: from, to: to, t: 0, eased: 0, dur: Math.max(140, durationMs), onDone: onDone, silent: !!silent, liftFrom: lift(from), liftTo: lift(to), color: color || worker.color, control: control || null }; + } + + /** + * A flight in legs ({ to, share, control?, silent? }) over `durationMs`: + * `onDone` (the transport) fires when the last leg lands, `onEnd` after it. + */ + function startRoute(v, worker, legs, durationMs, onDone, color, onEnd) { + var queue = legs.map(function (leg) { return Object.assign({}, leg); }); + worker.route = { legs: queue, dur: durationMs, onDone: onDone, color: color, onEnd: onEnd }; + nextLeg(v, worker); + } + + function nextLeg(v, worker) { + var route = worker.route; + var leg = route?.legs.shift(); + if (!leg) { return false; } + var last = !route.legs.length; + startHop(v, worker, leg.to, route.dur * leg.share, last ? route.onDone : null, leg.silent, route.color, leg.control); + worker.hop.last = last; + return true; } function tickWorkers(v, dt, timeMs, camera) { @@ -506,7 +590,7 @@ var hop = worker.hop; hop.t = Math.min(1, hop.t + dt / hop.dur); hop.eased = easeInOutCubic(hop.t); - var point = bezierPoint(hop.from, hopControl(hop.from, hop.to), hop.to, hop.eased); + var point = bezierPoint(hop.from, hop.control || hopControl(hop.from, hop.to), hop.to, hop.eased); var before = worker.group.position.clone(); setWorkerPosition(worker, point); // Bank into the flight: tilt towards the direction of travel, by speed. @@ -530,8 +614,14 @@ spawnArrivalEffects(v, step, hop.dur * 2, hop.to.ground || hop.to); hop.onDone(); } + // A route flies on to its next leg; after its last one, its end. + if (worker.route && !nextLeg(v, worker)) { + var onEnd = worker.route.onEnd; + worker.route = null; + onEnd?.(); + } } - } else if (state.motion && worker.rest) { + } else if (state.motion && worker.rest && !worker.docked) { worker.group.position.y = worker.rest.y + WORKER_HOVER + Math.sin(worker.phase * 2.6) * 0.004; } if (!worker.hop) { @@ -551,18 +641,6 @@ worker.pop = Math.min(1, worker.pop + dt / 420); size *= Math.max(0.01, easeOutBack(worker.pop)); } - if (worker.dissolve) { - if (!worker.hop) { - worker.dissolve.t = Math.min(1, worker.dissolve.t + dt / 380); - size *= Math.max(0.01, 1 - worker.dissolve.t); - if (worker.dissolve.t >= 1) { - worker.dissolve = null; - worker.group.visible = false; - setNodeVisible(worker.tag, false); - if (worker.rest) { pulseRing(v, worker.rest, worker.color, 0.02, 0.12, 500); } - } - } - } worker.group.scale.setScalar(size); if (worker.tag?.object3D) { var p = worker.group.position; @@ -588,7 +666,7 @@ function tickBeam(v, worker, dt, timeMs) { var beam = worker.beam; if (!beam) { return; } - var ground = !worker.hop && !worker.dissolve && worker.present ? worker.rest?.ground : null; + var ground = !worker.hop && worker.present ? worker.rest?.ground : null; var on = !!(ground && ground.radius > 0); var target = on ? 1 : 0; beam.level = state.motion ? approach(beam.level, target, dt / 260) : target; @@ -809,11 +887,16 @@ // search, a hard hat on a write, a rotating beacon on a run, thought orbs // while thinking, an hourglass while waiting, two antennas on a delegate. - var SKIN_KINDS = ['read', 'search', 'write', 'execute', 'think', 'wait', 'delegate']; + var SKIN_KINDS = ['read', 'search', 'write', 'execute', 'think', 'wait', 'delegate', 'control']; - /** The skin of a step: { kind, color }; idle is the agent's own colour. */ - function skinFor(v, worker, step) { + /** + * The skin of a step: { kind, color }; idle is the agent's own colour. + * `controlling`: a delegate whose sub-agents are still docked or out wears + * the control outfit (headset and a turning radar dish). + */ + function skinFor(v, worker, step, controlling) { if (!step) { return { kind: 'idle', color: worker.color }; } + if (controlling && step.kind === 'delegate') { return { kind: 'control', color: kindColor('delegate') }; } var kind = step.kind; if (kind === 'execute') { return { kind: 'execute', color: step.failed ? COLORS.executeFailed : COLORS.executeOk }; } if (kind === 'write') { @@ -947,6 +1030,30 @@ group.add(mast, tip); }); tick = function (timeMs) { tipMaterial.opacity = state.motion ? 0.45 + 0.55 * Math.abs(Math.sin(timeMs / 220)) : 1; }; + } else if (kind === 'control') { + // A headset over the dome with a boom mic, and a radar dish turning on top. + var band = new T.Mesh(track(v, new T.TorusGeometry(0.0155, 0.0014, 6, 24, Math.PI)), dark); + band.position.y = 0.0075; + var cups = skinMaterial(v, '#e2e8f0', { metalness: 0.5, roughness: 0.3 }); + [-1, 1].forEach(function (side) { + var cup = new T.Mesh(track(v, new T.CylinderGeometry(0.0045, 0.0045, 0.003, 12)), cups); + cup.rotation.z = Math.PI / 2; + cup.position.set(side * 0.0158, 0.0078, 0); + group.add(cup); + }); + var boom = new T.Mesh(track(v, new T.CylinderGeometry(0.0007, 0.0007, 0.012, 6)), dark); + boom.rotation.x = Math.PI / 2; + boom.rotation.y = 0.5; + boom.position.set(0.0135, 0.0055, 0.006); + var dishPivot = new T.Group(); + dishPivot.position.y = 0.0235; + var mast2 = new T.Mesh(track(v, new T.CylinderGeometry(0.0009, 0.0009, 0.008, 6)), dark); + mast2.position.y = -0.004; + var dish = new T.Mesh(track(v, new T.SphereGeometry(0.0075, 14, 6, 0, Math.PI * 2, 0, Math.PI / 2.6)), skinMaterial(v, '#f8fafc', { side: T.DoubleSide, metalness: 0.4, roughness: 0.3 })); + dish.rotation.x = -Math.PI / 2.4; + dishPivot.add(mast2, dish); + group.add(band, boom, dishPivot); + tick = function (timeMs) { dishPivot.rotation.y = state.motion ? timeMs / 500 : 0.8; }; } group.name = 'agentFlowSkin-' + kind; return { group: group, tick: tick }; @@ -958,8 +1065,8 @@ } /** Dresses a worker for a step (or idle): action colour plus accessory. */ - function setWorkerSkin(v, worker, step) { - var skin = skinFor(v, worker, step); + function setWorkerSkin(v, worker, step, controlling) { + var skin = skinFor(v, worker, step, controlling); var key = skin.kind + ':' + skin.color; if (worker.skin.key === key) { return; } var T = three(); @@ -1021,11 +1128,11 @@ /** (Re)builds a worker's props when its current action changes. */ function syncWorkerProps(v, worker, info) { var step = info.active ? info.step : null; - var key = step ? step.index + ':' + step.status + ':' + (state.motion ? 1 : 0) : 'idle'; + var key = step ? step.index + ':' + step.status + ':' + (state.motion ? 1 : 0) + ':' + (info.controlling ? 'c' : '') : 'idle'; if (worker.propKey === key) { return; } clearWorkerProps(v, worker); worker.propKey = key; - setWorkerSkin(v, worker, step); + setWorkerSkin(v, worker, step, info.controlling); if (!step || !worker.group.visible) { return; } if (step.kind === 'read') { buildReadProps(v, worker, step); } if (step.kind === 'search') { buildSearchProps(v, worker, step); } @@ -1097,6 +1204,7 @@ var worker = v.workers?.[info.actor]; if (worker) { syncWorkerProps(v, worker, info); } }); + syncAirfield(v, workers); } /** The worker standing for a step's actor (for labels), or null. */ diff --git a/apps/vscode-extension/templates/components/codexr/agent-flow/agentFlowRuntime/manifest.json b/apps/vscode-extension/templates/components/codexr/agent-flow/agentFlowRuntime/manifest.json index 393743d7..7eb00f24 100644 --- a/apps/vscode-extension/templates/components/codexr/agent-flow/agentFlowRuntime/manifest.json +++ b/apps/vscode-extension/templates/components/codexr/agent-flow/agentFlowRuntime/manifest.json @@ -11,6 +11,7 @@ "skyLayers.js", "agentEffects.js", "constructionSite.js", + "airfield.js", "sceneOverlays.js", "seeThrough.js", "tableTimeline.js", 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 b021260c..d036e9e2 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 @@ -330,6 +330,15 @@ normalizeDataset: normalizeDataset, buildTimeline: buildTimeline, workersAt: workersAt, + hangarPlan: hangarPlan, + airfieldAt: airfieldAt, + baySpot: baySpot, + padSpot: padSpot, + towerDock: towerDock, + airfieldSnapshot: function () { return airfieldSnapshot(view); }, + stationCardModel: stationCardModel, + pickFromIntersection: pickFromIntersection, + HANGAR: HANGAR, skinFor: skinFor, setWorkerSkin: setWorkerSkin, SKIN_KINDS: SKIN_KINDS, 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 bf640a1e..46fac1a2 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 @@ -366,7 +366,7 @@ v.rootEl.appendChild(wrap); v.legends[role] = { role: role, wrap: wrap, building: building, floor: floor, leader: createLeader(v, role), - file: -1, floorIndex: -1, height: 0, color: ACCENT + file: -1, floorIndex: -1, station: null, height: 0, color: ACCENT }; return v.legends[role]; } @@ -484,19 +484,31 @@ legend.width = width * LEGEND.scale; } - function showLegend(v, role, fileIndex, floorIndex) { + /** A legend on a building or on a station of the airfield ('hangar', 'tower'). */ + function legendShown(legend) { + return !!legend && (legend.file >= 0 || !!legend.station); + } + + function legendCards(v, legend, pinned) { + return legend.station + ? { building: stationCardModel(v, legend.station, pinned), floor: null } + : legendModel(v, legend.file, legend.floorIndex, pinned); + } + + function showLegend(v, role, fileIndex, floorIndex, station) { var legend = ensureLegend(v, role); if (!legend) { return; } - if (fileIndex < 0 || !v.files[fileIndex]) { + legend.station = station || null; + if (!legend.station && (fileIndex < 0 || !v.files[fileIndex])) { legend.file = -1; legend.floorIndex = -1; setNodeVisible(legend.wrap, false); setLeader(legend.leader, null); return; } - legend.file = fileIndex; - legend.floorIndex = Number.isInteger(floorIndex) ? floorIndex : -1; - fillLegend(legend, legendModel(v, fileIndex, legend.floorIndex, role === 'pinned')); + legend.file = legend.station ? -1 : fileIndex; + legend.floorIndex = !legend.station && Number.isInteger(floorIndex) ? floorIndex : -1; + fillLegend(legend, legendCards(v, legend, role === 'pinned')); setNodeVisible(legend.wrap, true); } @@ -574,8 +586,8 @@ } ['pinned', 'hover'].forEach(function (role) { var legend = v.legends?.[role]; - if (!legend || legend.file < 0) { return; } - var target = legendTarget(v, legend.file, legend.floorIndex); + if (!legendShown(legend)) { return; } + var target = legend.station ? stationAnchor(v, legend.station) : legendTarget(v, legend.file, legend.floorIndex); var at = place(target.x, target.z, (legend.width || LEGEND.width * LEGEND.scale) / 2, legend.height); legend.wrap.setAttribute('position', at.x + ' ' + at.y + ' ' + at.z); setLeader(legend.leader, at, target, legend.color); @@ -584,36 +596,50 @@ /** 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; } + if (!v?.legendRight || !(v.label?.target || legendShown(v.legends?.pinned) || legendShown(v.legends?.hover))) { 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) { + function samePick(pin, fileIndex, station) { + return !!pin && (station ? pin.station === station : (!pin.station && pin.file === fileIndex)); + } + + /** + * Hover (showTooltip keeps its name: the harness drives it). `station` + * ('hangar' or 'tower') points an airfield station instead of a building. + */ + function showTooltip(v, fileIndex, floorIndex, station) { var floor = Number.isInteger(floorIndex) ? floorIndex : -1; - if (v.hoverFile === fileIndex && v.hoverFloor === floor) { return; } - v.hoverFile = fileIndex; - v.hoverFloor = floor; - // The pinned building already has its card: no second one over it. - var file = v.pin && v.pin.file === fileIndex ? -1 : fileIndex; - showLegend(v, 'hover', file, floor); + var pointed = station || null; + if (v.hoverFile === fileIndex && v.hoverFloor === floor && (v.hoverStation || null) === pointed) { return; } + v.hoverFile = pointed ? -1 : fileIndex; + v.hoverFloor = pointed ? -1 : floor; + v.hoverStation = pointed; + // The pinned building (or station) already has its card: no second one over it. + if (samePick(v.pin, fileIndex, pointed)) { + showLegend(v, 'hover', -1, -1); + } else { + showLegend(v, 'hover', v.hoverFile, floor, pointed); + } layoutLegends(v); } - /** Click: pin a building's legend, or unpin it when it is the pinned one. */ - function togglePin(v, fileIndex, floorIndex) { - if (!v || !Number.isInteger(fileIndex) || fileIndex < 0 || !v.files[fileIndex]) { return null; } - var floor = Number.isInteger(floorIndex) ? floorIndex : -1; - if (v.pin && v.pin.file === fileIndex) { + /** Click: pin a building's (or station's) legend, or unpin it when it is the pinned one. */ + function togglePin(v, fileIndex, floorIndex, station) { + if (!v) { return null; } + var pointed = station || null; + if (!pointed && (!Number.isInteger(fileIndex) || fileIndex < 0 || !v.files[fileIndex])) { return null; } + var floor = Number.isInteger(floorIndex) && !pointed ? floorIndex : -1; + if (samePick(v.pin, fileIndex, pointed)) { v.pin = null; showLegend(v, 'pinned', -1, -1); // The pointer is still on it: the hover card takes over. - showLegend(v, 'hover', v.hoverFile, v.hoverFloor); + showLegend(v, 'hover', v.hoverFile, v.hoverFloor, v.hoverStation); } else { - v.pin = { file: fileIndex, floor: floor }; - showLegend(v, 'pinned', fileIndex, floor); - if (v.hoverFile === fileIndex) { showLegend(v, 'hover', -1, -1); } + v.pin = pointed ? { file: -1, floor: -1, station: pointed } : { file: fileIndex, floor: floor }; + showLegend(v, 'pinned', v.pin.file, floor, pointed); + if (pointed ? v.hoverStation === pointed : (!v.hoverStation && v.hoverFile === fileIndex)) { showLegend(v, 'hover', -1, -1); } } layoutLegends(v); return v.pin; @@ -623,7 +649,7 @@ function refreshLegends(v) { ['pinned', 'hover'].forEach(function (role) { var legend = v.legends?.[role]; - if (legend && legend.file >= 0) { fillLegend(legend, legendModel(v, legend.file, legend.floorIndex, role === 'pinned')); } + if (legendShown(legend)) { fillLegend(legend, legendCards(v, legend, role === 'pinned')); } }); layoutLegends(v); } @@ -631,7 +657,7 @@ function faceLegends(v, camera) { ['pinned', 'hover'].forEach(function (role) { var legend = v.legends?.[role]; - if (legend && legend.file >= 0) { faceYaw(legend.wrap, camera); } + if (legendShown(legend)) { faceYaw(legend.wrap, camera); } }); } @@ -646,19 +672,21 @@ return nodes; } - /** The building (and floor) under a pointer intersection: { file, floor }. */ + /** The building (and floor), or the airfield station, under a pointer intersection: { file, floor, station }. */ function pickFromIntersection(intersection) { - return { file: fileFromIntersection(intersection), floor: floorFromIntersection(intersection)?.floor ?? -1 }; + var station = intersection?.object?.userData?.station || null; + if (station) { return { file: -1, floor: -1, station: station }; } + return { file: fileFromIntersection(intersection), floor: floorFromIntersection(intersection)?.floor ?? -1, station: null }; } /** Clicks on the buildings entity pin; one listener per view, removed with it. */ function bindLegendClicks(v) { if (!v.buildingsEl?.addEventListener) { return; } var handler = function (event) { - var pick = event?.detail?.intersection ? pickFromIntersection(event.detail.intersection) : { file: v.hoverFile, floor: v.hoverFloor }; - if (pick.file < 0) { return; } + var pick = event?.detail?.intersection ? pickFromIntersection(event.detail.intersection) : { file: v.hoverFile, floor: v.hoverFloor, station: v.hoverStation }; + if (pick.file < 0 && !pick.station) { return; } event.stopPropagation?.(); - togglePin(v, pick.file, pick.floor); + togglePin(v, pick.file, pick.floor, pick.station); }; v.buildingsEl.addEventListener('click', handler); v.unbindLegendClicks = function () { v.buildingsEl?.removeEventListener?.('click', handler); }; @@ -670,12 +698,14 @@ v.lastHoverPoll = timeMs; var hovered = -1; var hoveredFloor = -1; + var hoveredStation = null; doc().querySelectorAll?.('[raycaster]').forEach(function (el) { var raycaster = el.components?.raycaster; - if (hovered >= 0 || !raycaster || raycaster.data?.enabled === false) { return; } + if (hovered >= 0 || hoveredStation || !raycaster || raycaster.data?.enabled === false) { return; } var pick = pickFromIntersection(raycaster.getIntersection?.(v.buildingsEl)); hovered = pick.file; hoveredFloor = pick.floor; + hoveredStation = pick.station; }); - showTooltip(v, hovered, hoveredFloor); + showTooltip(v, hovered, hoveredFloor, hoveredStation); } 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 400df825..a97590d6 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 @@ -261,7 +261,8 @@ turnStarts: turns.filter(function (turn) { return turn.start >= 0; }).map(function (turn) { return turn.start; }), count: steps.length, writePlan: buildWritePlan(steps, data.files), - actors: actors + actors: actors, + hangar: hangarPlan(actors) }; } @@ -310,24 +311,53 @@ if (lane.spawnIndex < 0 && spawnSeq !== null && spawnSeq !== undefined) { lane.spawnIndex = steps.findIndex(function (step) { return step.seq === spawnSeq; }); } + // Who it reports to: the actor of the step that spawned it (the main agent when unknown). + lane.parentActor = lane.kind === 'main' ? null : (lane.spawnIndex >= 0 ? steps[lane.spawnIndex].actor : 0); }); return actors; } /** - * Where every worker is at the playhead. A worker is present from its first - * step (main: always) until its last step is over. A subagent is not shown - * between the delegate that spawns it and its first step: it would only - * hover idle on top of the main UFO, a pile of saucers with overlapping - * name tags (Adrián, demo video). It pops out of the main UFO when it starts - * working instead; its current action is its - * latest step at or before the playhead, and that action is ongoing until - * the same worker's next step starts (or, for its final step, while the - * playhead is on it or the step is still running). + * Hangar bays: each sub-agent gets the lowest bay free from its spawn (or + * first step) to its last step, so two sub-agents out at the same time + * never share one. Bays = most sub-agents out at once, 1 to HANGAR.maxBays; + * past that they queue behind one another (row 1, 2...) in the same bays. + * { bays, slots: { actor: { bay, row } } }; no sub-agents, no bays. + */ + function hangarPlan(actors) { + var lanes = (actors || []).filter(function (lane) { return lane.kind !== 'main' && lane.firstIndex >= 0; }) + .map(function (lane) { + var from = lane.spawnIndex >= 0 ? Math.min(lane.spawnIndex, lane.firstIndex) : lane.firstIndex; + return { actor: lane.index, from: from, to: lane.lastIndex }; + }) + .sort(function (a, b) { return a.from - b.from || a.actor - b.actor; }); + var busyUntil = []; + var slots = {}; + lanes.forEach(function (lane) { + var bay = 0; + while (bay < busyUntil.length && busyUntil[bay] >= lane.from) { bay += 1; } + busyUntil[bay] = lane.to; + slots[lane.actor] = { bay: bay % HANGAR.maxBays, row: Math.floor(bay / HANGAR.maxBays) }; + }); + return { bays: lanes.length ? Math.max(1, Math.min(HANGAR.maxBays, busyUntil.length)) : 0, slots: slots }; + } + + /** + * Where every worker is at the playhead. A worker is present (out flying) + * from its first step (main: always) until its last step is over. Between + * the delegate that spawns a sub-agent and its first step it is `docked`: + * waiting in its hangar bay, never stacked on the main UFO (Adrián, demo + * video). Its current action is its latest step at or before the playhead, + * and that action is ongoing until the same worker's next step starts (or, + * for its final step, while the playhead is on it or the step is still + * running). A worker whose current step is a delegate and that has a + * sub-agent docked or out is `controlling` them (the main agent does it + * from the control tower). */ function workersAt(timeline, index) { var at = Math.floor(toNumber(index, -1)); - return (timeline?.actors || []).map(function (lane) { + var lanes = timeline?.actors || []; + var infos = lanes.map(function (lane) { var current = -1; for (var i = lane.steps.length - 1; i >= 0; i -= 1) { if (lane.steps[i] <= at) { current = lane.steps[i]; break; } @@ -337,16 +367,64 @@ var ended = lane.kind !== 'main' && lane.lastIndex >= 0 && at > lane.lastIndex && timeline.steps[lane.lastIndex].status !== 'running'; var present = timeline.count > 0 && (lane.kind === 'main' || (start >= 0 && at >= start && !ended)); + var docked = lane.kind !== 'main' && lane.spawnIndex >= 0 && lane.firstIndex >= 0 && at >= lane.spawnIndex && at < lane.firstIndex; var ongoing = !!step && (step.actorNext !== null ? at < step.actorNext : (at === current || step.status === 'running')); return { actor: lane.index, + parent: lane.parentActor === undefined ? null : lane.parentActor, present: present, + docked: docked, stepIndex: current, step: step, active: present && ongoing, - finished: ended + finished: ended, + controlling: false }; }); + infos.forEach(function (info) { + if (!info.present || info.step?.kind !== 'delegate') { return; } + info.controlling = infos.some(function (other) { return other.parent === info.actor && (other.present || other.docked); }); + }); + return infos; + } + + /** + * The airfield at the playhead (from workersAt): the hangar doors are open + * while any sub-agent is docked or out; each bay is 'idle', 'ready' (a + * sub-agent docked in it), 'out' (its sub-agent is away) or 'failed' (its + * last sub-agent came back from a failed final step, until the bay is used + * again); `controller` is the actor coordinating from the tower (the main + * agent), or -1. + */ + function airfieldAt(timeline, workers) { + var plan = timeline?.hangar || { bays: 0, slots: {} }; + var bays = []; + for (var b = 0; b < plan.bays; b += 1) { bays.push({ state: 'idle', actor: -1 }); } + var open = false; + var lanes = timeline?.actors || []; + workers.forEach(function (info) { + var slot = plan.slots[info.actor]; + if (!slot || !bays[slot.bay]) { return; } + var bay = bays[slot.bay]; + var lane = lanes[info.actor]; + if (info.docked || info.present) { + open = true; + bay.state = info.docked ? 'ready' : 'out'; + bay.actor = info.actor; + } else if (info.finished && bay.state !== 'ready' && bay.state !== 'out') { + var last = lane ? timeline.steps[lane.lastIndex] : null; + // The latest sub-agent to come back to the bay decides its light. + if (bay.actor < 0 || (lanes[bay.actor]?.lastIndex ?? -1) <= lane.lastIndex) { + bay.state = last?.failed ? 'failed' : 'idle'; + bay.actor = info.actor; + } + } + }); + var controller = -1; + workers.forEach(function (info) { + if (controller < 0 && info.controlling && lanes[info.actor]?.kind === 'main') { controller = info.actor; } + }); + return { doorsOpen: open, bays: bays, controller: controller }; } /** Building height for a line count, on the builder's sqrt(loc) scale anchored at the file's final height. */ 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 0f166d4b..9af3f356 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 @@ -35,6 +35,7 @@ buildDeltaCaps(v); buildGhosts(v); buildTestTower(v); + buildAirfield(v); buildTrail(v); buildFloatingLabel(v); bindLegendClicks(v); @@ -49,6 +50,7 @@ if (!v) { return; } clearEffects(v); destroyWorkers(v); + destroyAirfield(v); replaceArcTubes(v, 'blastLines', [], 0); replaceArcLines(v, 'pathLines', []); updateUnreadHalos(v, []); @@ -75,8 +77,11 @@ view.outside = dataset.files.map(function (file) { return isOutsideFile(file, dataset.districts); }); // Same layout, maybe new functions: the floors are swapped in, what stood keeps standing. view.city.rebuildFloors(dataset.files); - // New actors may have joined: their workers are created on demand. + // New actors may have joined: their workers are created on demand, and + // the hangar is rebuilt for its bays. destroyWorkers(view); + destroyAirfield(view); + buildAirfield(view); replaceArcLines(view, 'pathLines', []); buildTimelineGraphics(view); } @@ -212,8 +217,11 @@ ghosts: Object.keys(v.ghosts || {}).filter(function (key) { return v.ghosts[key].visible; }).sort(), workers: (v.workers || []).map(function (worker) { // Where an absent worker last stood is not drawn. - return worker ? { present: !!worker.present, rest: worker.present && worker.rest ? [round4(worker.rest.x), round4(worker.rest.z)] : null } : null; - }) + if (!worker) { return null; } + var placed = (worker.present || worker.docked) && worker.rest; + return { present: !!worker.present, docked: !!worker.docked, shown: !!worker.group.visible, skin: worker.skin.kind || 'idle', rest: placed ? [round4(worker.rest.x), round4(worker.rest.z)] : null }; + }), + airfield: airfieldSnapshot(v) }; } @@ -240,6 +248,7 @@ } tickSeeThrough(v, time || 0, camera); tickWorkers(v, dt, time || 0, camera); + tickAirfield(v, dt, time || 0); tickEffects(v, dt); tickPillar(v, dt); tickTower(v, dt); diff --git a/apps/vscode-extension/test/analysis/agentFlowRuntime.test.cjs b/apps/vscode-extension/test/analysis/agentFlowRuntime.test.cjs index cb94ae23..0f58b83a 100644 --- a/apps/vscode-extension/test/analysis/agentFlowRuntime.test.cjs +++ b/apps/vscode-extension/test/analysis/agentFlowRuntime.test.cjs @@ -234,6 +234,32 @@ test('actors: workers get lanes, spawn at their delegate step and work in parall assert.deepEqual(plain(api.workersAt(timeline, 4).map((worker) => worker.present)), [true, true, true]); // A finished subagent leaves the table. assert.deepEqual(plain(api.workersAt(timeline, 11).map((worker) => worker.present)), [true, false, false]); + // The hangar (#453): a sub-agent waits docked in its bay from its delegate to its first step, + // and the main agent controls them from the tower while its latest step is that delegate. + assert.deepEqual(plain(timeline.actors.map((lane) => lane.parentActor)), [null, 0, 0]); + assert.deepEqual(plain(timeline.hangar), { bays: 2, slots: { 1: { bay: 0, row: 0 }, 2: { bay: 1, row: 0 } } }); + assert.deepEqual(plain(api.workersAt(timeline, 2).map((worker) => [worker.docked, worker.controlling])), [[false, true], [true, false], [true, false]]); + assert.deepEqual(plain(api.workersAt(timeline, 3).map((worker) => [worker.docked, worker.controlling])), [[false, true], [false, false], [true, false]]); + assert.equal(api.workersAt(timeline, 6)[0].controlling, false, 'working on its own again: no longer at the tower'); + const field = (index) => plain(api.airfieldAt(timeline, api.workersAt(timeline, index))); + assert.deepEqual(field(0), { doorsOpen: false, bays: [{ state: 'idle', actor: -1 }, { state: 'idle', actor: -1 }], controller: -1 }); + assert.deepEqual(field(1).bays.map((bay) => bay.state), ['ready', 'idle']); + assert.deepEqual(field(3), { doorsOpen: true, bays: [{ state: 'out', actor: 1 }, { state: 'ready', actor: 2 }], controller: 0 }); + assert.deepEqual(field(9).bays.map((bay) => bay.state), ['idle', 'out'], 'a sub-agent back in its bay'); + assert.equal(field(11).doorsOpen, false, 'doors close when nobody is out'); + // Bays: the most sub-agents out at once, a bay reused once free, queues past four. + const lanes = (spans) => spans.map(([from, to], i) => ({ index: i + 1, kind: 'subagent', spawnIndex: from, firstIndex: from, lastIndex: to })); + assert.deepEqual(plain(api.hangarPlan(lanes([[0, 3], [4, 6]]))), { bays: 1, slots: { 1: { bay: 0, row: 0 }, 2: { bay: 0, row: 0 } } }); + const crowd = plain(api.hangarPlan(lanes([[0, 9], [0, 9], [0, 9], [0, 9], [0, 9]]))); + assert.equal(crowd.bays, 4); + assert.deepEqual(crowd.slots[5], { bay: 0, row: 1 }); + assert.deepEqual(plain(api.hangarPlan([{ index: 0, kind: 'main', firstIndex: 0, lastIndex: 3 }])), { bays: 0, slots: {} }); + // A failed last step leaves its bay light red until the bay is used again. + const failing = clone(sample); + const lastOfB = failing.steps.filter((step) => step.actor === 2).at(-1); + lastOfB.status = 'failed'; + const failingTimeline = api.buildTimeline(failing); + assert.equal(plain(api.airfieldAt(failingTimeline, api.workersAt(failingTimeline, 11))).bays[1].state, 'failed'); // A dataset from before multi-agent tracing gets one synthesized main actor. const legacy = api.normalizeDataset({ session: { agent: 'Codex' }, files: [{ path: 'a.js', loc: 3 }], steps: [{ seq: 0, kind: 'read', files: [0], actor: 4 }] }); assert.deepEqual(plain(legacy.actors.map((actor) => [actor.label, actor.kind])), [['Codex', 'main']]); diff --git a/apps/vscode-extension/test/baseline/featureBaseline.snapshot.json b/apps/vscode-extension/test/baseline/featureBaseline.snapshot.json index d6f90635..5608d86a 100644 --- a/apps/vscode-extension/test/baseline/featureBaseline.snapshot.json +++ b/apps/vscode-extension/test/baseline/featureBaseline.snapshot.json @@ -435,6 +435,7 @@ "analysis_livePanel/file/fileAnalysisstyle.css", "components/COMPONENTS.md", "components/codexr/agent-flow/agentFlowRuntime/agentEffects.js", + "components/codexr/agent-flow/agentFlowRuntime/airfield.js", "components/codexr/agent-flow/agentFlowRuntime/cityFloors.js", "components/codexr/agent-flow/agentFlowRuntime/cityScene.js", "components/codexr/agent-flow/agentFlowRuntime/colorEncoding.js", 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 c850ac83..e312a183 100644 --- a/apps/vscode-extension/test/runners/run-agent-flow-harness.cjs +++ b/apps/vscode-extension/test/runners/run-agent-flow-harness.cjs @@ -637,6 +637,75 @@ async function runScenario(browser, port) { await sleep(700); await shot(page, '11-controller-panel'); + // (g) The airfield (#453): on a delegate the main UFO docks on the control + // tower and its sub-agents wait in their hangar bays; each takes off on its + // first step with a radio link home, and lands back in its bay when done. + const airfieldAt = (index) => page.evaluate((i) => { + const runtime = window.CodeXRAgentFlowRuntime; + const t = runtime.__testing; + runtime.seek(i); + t.settleView(); + return { workers: t.sceneSnapshot().workers, airfield: t.airfieldSnapshot(), dock: t.towerDock() }; + }, index); + let field = await airfieldAt(2); + assert.deepEqual(field.workers[0].rest, [field.dock.x, field.dock.z], 'delegating, the main UFO docks on the control tower'); + assert.equal(field.workers[0].skin, 'control', 'in its control outfit'); + assert.deepEqual(field.workers.slice(1).map((worker) => [worker.docked, worker.shown, worker.present]), [[true, true, false], [true, true, false]], 'both sub-agents wait in their bays'); + assert.deepEqual(field.airfield, { doors: 1, bays: ['ready', 'ready'], controller: 0, links: [] }); + await page.evaluate(() => window.CodeXRAgentFlowHarness.lookAtLocal({ x: -2.66, y: 0.08, z: 0.8 }, { x: 0.75, y: 0.32, z: 0.42 })); + await sleep(900); + await shot(page, '21-hangar-docked'); + field = await airfieldAt(5); + assert.deepEqual(field.airfield, { doors: 1, bays: ['out', 'out'], controller: 0, links: [1, 2] }, 'out working, each linked to the tower'); + await page.evaluate(() => window.CodeXRAgentFlowHarness.lookAtLocal({ x: -1.9, y: 0.25, z: 0.5 }, { x: 1.4, y: 1.1, z: 1.9 })); + await sleep(900); + await shot(page, '22-hangar-radio-links'); + field = await airfieldAt(9); + assert.equal(field.workers[0].skin === 'control', false, 'working on its own again, the main UFO leaves the tower'); + assert.deepEqual([field.workers[1].shown, field.airfield.bays], [false, ['idle', 'out']], 'the first sub-agent is back in its bay'); + field = await airfieldAt(11); + assert.deepEqual([field.workers[2].shown, field.airfield.doors], [false, 0], 'all back: the doors close'); + // Legends: the pointer picks the stations through their hit boxes; cards pin like a building's. + const legends = await page.evaluate(() => { + const runtime = window.CodeXRAgentFlowRuntime; + const t = runtime.__testing; + const view = t.getView(); + const T = window.AFRAME.THREE; + runtime.seek(3); + t.settleView(); + const pick = (x, z) => { + const origin = view.rootEl.object3D.localToWorld(new T.Vector3(x, 1, z)); + const below = view.rootEl.object3D.localToWorld(new T.Vector3(x, 0, z)); + const ray = new T.Raycaster(origin, below.sub(origin).normalize()); + const hit = ray.intersectObject(view.buildingsEl.object3D, true)[0]; + return t.pickFromIntersection(hit); + }; + const hangarPick = pick(t.HANGAR.x, t.HANGAR.frontZ - 0.1); + const towerPick = pick(t.towerDock().x, t.towerDock().z); + t.togglePin(view, hangarPick.file, hangarPick.floor, hangarPick.station); + t.showTooltip(view, towerPick.file, towerPick.floor, towerPick.station); + const card = (role) => ({ station: view.legends[role].station, shown: view.legends[role].wrap.object3D.visible }); + return { + hangarPick, towerPick, pinned: card('pinned'), hover: card('hover'), + hangar: t.stationCardModel(view, 'hangar', true), tower: t.stationCardModel(view, 'tower', false) + }; + }); + assert.deepEqual([legends.hangarPick.station, legends.towerPick.station], ['hangar', 'tower']); + assert.deepEqual([legends.pinned, legends.hover], [{ station: 'hangar', shown: true }, { station: 'tower', shown: true }]); + assert.equal(legends.hangar.title, 'Hangar'); + assert.equal(legends.hangar.subtitle, 'Pinned 1 out 1 in bay 0 back'); + assert.deepEqual(legends.hangar.rows.map((row) => row.value), ['out 1 steps', 'in bay']); + assert.equal(legends.tower.subtitle, 'Controlling 2 sub-agents'); + await page.evaluate(() => window.CodeXRAgentFlowHarness.lookAtLocal({ x: -2.6, y: 0.5, z: 0.8 }, { x: 0.9, y: 0.7, z: 1.9 })); + await sleep(900); + await shot(page, '23-hangar-legends'); + await page.evaluate(() => { + const t = window.CodeXRAgentFlowRuntime.__testing; + const view = t.getView(); + t.togglePin(view, -1, -1, 'hangar'); + t.showTooltip(view, -1, -1, null); + }); + // (f) The timeline invariant: the city at a step is the same whether the // playhead jumped there, played into it from the step before, or stepped // back to it. Every building, floor, colour, fade, foundation, hazard, diff --git a/docs/agent-flow/hangar.md b/docs/agent-flow/hangar.md new file mode 100644 index 00000000..ebc98586 --- /dev/null +++ b/docs/agent-flow/hangar.md @@ -0,0 +1,74 @@ +# Agent Flow: the sub-agent hangar and the control tower + +Story: Code-XR#453 (epic #319). Proposed and approved on 3 Dec 2026. + +## What it shows + +Delegation used to read as saucers popping out of each other. The test-tower +corner is now an airfield: + +- **Control tower.** The test tower doubles as the control tower. When the + main agent delegates (Claude Code's Agent/Task tool) its UFO docks on top of + the tower and wears the `control` outfit (a headset and a turning radar dish), + with a radar ring round the cab. Runs still go to the tower's deck as before. +- **Hangar.** A vaulted shed beside the tower, its mouth to the city, with one + bay per sub-agent out at the same time (1 to 4) and a launch pad per bay on + the apron. A sub-agent waits in its bay between the delegate and its first + step (lit amber, no name tag), taxis to its pad and lifts off on its first + step (bay light blue), and when it is done flies back, lands on its pad and + rolls in. A failed last step leaves its bay red until the bay is used again. + The doors are open while any sub-agent is in a bay or out. +- **Radio links.** A dashed line in the sub-agent's colour joins every + sub-agent out to the agent that sent it (the tower while the main agent + controls from it). Each step of the sub-agent sends a packet home along it. + +## Rules + +All of it is derived from the playhead, so the timeline invariant holds +(`docs/agent-flow/timeline.md`): seeking to a step, playing into it and +stepping back to it draw the same airfield. + +| State | Rule (`timelineModel.js`) | +|---|---| +| Sub-agent `docked` | its spawning delegate <= playhead < its first step | +| Sub-agent `present` (out) | first step <= playhead, until its last step is over (unchanged) | +| Worker `controlling` | its latest step is a delegate and at least one sub-agent it spawned is docked or out | +| Main UFO at the tower | its latest step is a delegate (`spotForStep`); it wears `control` while controlling | +| Bays | `hangarPlan`: lowest bay free over [spawn, last step]; bays = most sub-agents out at once, capped at 4; more queue in rows behind | +| Doors, bay lights, controller | `airfieldAt(timeline, workersAt(...))` | + +If the main agent works while its sub-agents are out (background sub-agents), +its own work wins: it flies to it, the links follow its UFO, and it stops +controlling until its next delegate. Nested sub-agents report to their parent +by link; only the main agent goes to the tower. + +Transient, not part of the state: the take-off and landing flights (a route +of legs on the worker), the doors sliding (they stay open while a landing is +in progress), the radar sweep and the packets. With reduced motion the +saucers are placed directly, the doors snap and no packets are sent. + +## Code + +- `agentFlowRuntime/airfield.js`: hangar geometry, bay and pad spots, tower + dock, doors, bay lights, radar, radio links and packets, the station cards. +- `agentFlowRuntime/timelineModel.js`: `parentActor` per lane, `hangarPlan`, + `docked`/`controlling` in `workersAt`, `airfieldAt`. +- `agentFlowRuntime/constructionSite.js`: tower dock for a main delegate, + bay start spot, launch and landing routes, the `control` outfit. +- `agentFlowRuntime/sceneOverlays.js`: legends on stations. The hangar and + tower carry invisible hit boxes on the raycastable buildings entity, so the + same pointer poll and click pin them (`pickFromIntersection` returns + `station`). +- Configuration: `HANGAR` in `configAndState.js`. + +The runtime is shared, so the VS Code extension and the Code-XR IDE get it +alike; the core and the server are unchanged. + +## Tests + +- `test/analysis/agentFlowRuntime.test.cjs`: docked/controlling, bay plan + (reuse, queue past four), airfield states, failed bay. +- `test/runners/run-agent-flow-harness.cjs` section (g): dock on the tower, + sub-agents in their bays, links, landing, doors closing, station picks and + cards; section (f) compares the airfield and each worker's docked/shown/skin + state across seek, play and step back. diff --git a/docs/agent-flow/test-guide.md b/docs/agent-flow/test-guide.md index dfc3a6d0..bdf2afd3 100644 --- a/docs/agent-flow/test-guide.md +++ b/docs/agent-flow/test-guide.md @@ -48,7 +48,7 @@ emerald, each sub-agent in its own colour. Check each action while it plays: | What the agent did | What you should see | |---|---| -| Handed a task to a sub-agent (Claude Code's Agent/Task tool) | The main UFO puts on its delegate outfit. The sub-agent's own UFO pops out of it with a beam when the sub-agent takes its first step (never earlier, so saucers never pile up on the main one) and works in parallel; when its work ends it flies back and dissolves | +| Handed a task to a sub-agent (Claude Code's Agent/Task tool) | The main UFO flies to the top of the control tower (front-left corner) and puts on its control outfit (headset and radar dish) with a radar ring round the cab. The hangar beside the tower opens and the sub-agent waits in its bay. On its first step it taxis to its pad, lifts off and works in parallel, joined to the tower by a dashed radio link; when its work ends it flies back, lands and rolls into its bay, and the doors close once nobody is out. See [hangar.md](hangar.md) | | Read a file | The worker stands on the roof and sweeps a cyan scanning cone down the facade; the roof stays tinted cyan | | Searched (grep, glob, find) | A violet radar ripple on the table, and beacons popping up on the matched buildings | | Edited a file | Scaffolding and a small crane on the building, orange floors stacking up by the added lines (a red slice drops off for removed lines) | @@ -182,13 +182,29 @@ Design: [ufo.md](ufo.md). 3. When an agent moves to another file it glides at its altitude (no jumps); the trail draws the path in the sky. 4. Once it stops over a building, a beam lights down onto the roof with a halo ring; on a read the beam is cyan. During a write the building grows inside the beam. 5. A run sends the UFO over the test tower, beaming on its deck. A rejected permission backs it off with the beam off. -6. Subagents are born from the main UFO, fly a little lower and fly back to it when they finish. +6. Subagents take off from the hangar beside the control tower, fly a little lower and land back in their bay when they finish (see "Sub-agent hangar" below). 7. Function floors still light the floor the agent works on. 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. +## Sub-agent hangar and the control tower + +Design: [hangar.md](hangar.md). + +1. Open a Claude Code session where the agent delegates to sub-agents (Agent/Task tool) and step to the delegate. +2. The main UFO flies to the top of the control tower and wears the control outfit (headset, turning radar dish); a radar ring pulses round the cab. +3. The hangar doors slide open; each sub-agent waits in its own bay, its bay light amber, no name tag. Saucers never pile up on the main UFO. +4. Step on: on its first step a sub-agent taxis to its pad, lifts off vertically and flies to its building; its name tag appears and its bay light turns blue. +5. While it is out, a dashed line in its colour joins it to the tower; each of its steps sends a small ball home along the line. +6. If the main agent works on its own meanwhile (background sub-agents), it leaves the tower and the lines follow its UFO. +7. When a sub-agent finishes it flies back, lands on its pad and rolls into its bay; a failed last step leaves the bay light red. The doors close when nobody is out. +8. Point the hangar: its card lists each sub-agent (in bay, out with its step count, back, failed). Point the tower: runs, last run and how many sub-agents it controls. Click pins either card like a building's. +9. Rewind and replay over the delegation: at every step the tower, the bays, the doors and the saucers are where they were, whether you jump there or play into it. +10. With reduced motion, saucers are placed without flying, the doors snap and no balls travel the lines. +11. In the headset, the hangar and the tower are on the front-left corner of the table, within reach of the controller ray. Code-XR IDE: the same with a chat agent ("Watch in XR"). + ## Timeline: the city as it was at every step Design: [timeline.md](timeline.md). The sample session's last turn tidies up: diff --git a/docs/agent-flow/ufo.md b/docs/agent-flow/ufo.md index 632d9d1c..c5b2eea2 100644 --- a/docs/agent-flow/ufo.md +++ b/docs/agent-flow/ufo.md @@ -21,7 +21,9 @@ above the city, in table-local Y: | City | `skylineY(v)` = highest roof of the session (final, current or growing-to height, plus `v.skyExtra`) | The main UFO flies at `ufoAltitude`; subagents fly 3, 6 or 9 cm lower (three -layers), so saucers crossing each other never meet. The name tag sits over +layers), so saucers crossing each other never meet. Subagents take off from +and land in the hangar beside the control tower, where the main UFO docks while +it delegates ([hangar.md](hangar.md)). The name tag sits over the dome and the thought bubble / permission sign beside it, all under the legend layer.