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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,17 @@ jobs:
name: layout-coordinator-review
path: .scratch/layout-coordinator-review/
if-no-files-found: error
- name: Generate native reference-sharing review package
if: matrix.java-version == '25' && github.event_name == 'pull_request'
run: uv run python -m scripts.review_shared_references
- name: Upload native reference-sharing review package
if: matrix.java-version == '25' && github.event_name == 'pull_request'
uses: actions/upload-artifact@v7
with:
name: reference-sharing-review
path: .scratch/reference-sharing-review/
include-hidden-files: true
if-no-files-found: error
- name: Build Python Distribution
run: uv build
- name: Check installed wheel installer commands
Expand Down
14 changes: 14 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,17 @@ Use the repository's [upgrade-tracer skill](.codex/skills/upgrade-tracer/SKILL.m
Requests to document or edit the skill do not trigger the upgrade workflow. Follow the user's requested scope for narrower tracer tasks.

For repository setup and verification commands, consult [CONTRIBUTING.md](CONTRIBUTING.md).

## Agent skills

### Issue tracker

For issue lookup or publication, use this repository's GitHub Issues and read [the tracker conventions](docs/agents/issue-tracker.md).

### Triage labels

Before assigning an issue's triage state, read [the five canonical label mappings](docs/agents/triage-labels.md).

### Domain docs

When exploring domain concepts or architectural decisions, follow [the single-context domain documentation rules](docs/agents/domain.md).
20 changes: 19 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,24 @@ bundle hashes identify the captured files; they do not establish that the bundle
was rebuilt from those sources. Capture after a clean build and record its commit.
The JDK 25 CI job uploads the review package as `layout-coordinator-review`.

For controlled independent/shared reference-routing comparisons, build the
frontend first and capture the native review package:

```sh
make build-frontend
uv run python -m scripts.review_shared_references
```

Open `.scratch/reference-sharing-review/index.html` to compare native/50% and
monochrome output. Keep the adjacent PNGs, SVGs, reopened SVG raster, and
`manifest.json` with the gallery. The manifest records source, bundle, input,
and export hashes; capture after a clean build and record its commit. Compare
sharing against the controlled independent baseline; historical output supplies
context. The JDK 25 pull-request CI job uploads the package as
`reference-sharing-review`. Record maintainer approval or specific objections
in the issue; generating the package does not supply approval or establish the
separate [performance gates](scripts/benchmark_reference_routing/README.md).

## Development artifacts

Use the ignored root `.scratch/` directory for proposals, throwaway prototypes,
Expand Down Expand Up @@ -123,4 +141,4 @@ without installing system tools. Installed commands read the caller project's
configuration when present and otherwise use the configuration shipped in the wheel.
The release workflow runs the same wheel check after building the distributions.

The [release workflow](.github/workflows/release.yml) runs on main-branch pushes, pull requests targeting main, and tag pushes. A tag push triggers publication after validation; it uploads the frontend bundles and Python distributions to a GitHub release. Follow the project's existing tag naming convention. The workflow does not publish to PyPI.
The [release workflow](.github/workflows/release.yml) runs on main-branch pushes, pull requests targeting any branch (including stacked feature branches), and tag pushes. A tag push triggers publication after validation; it uploads the frontend bundles and Python distributions to a GitHub release. Follow the project's existing tag naming convention. The workflow does not publish to PyPI.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion cs1302_code_visualizer/frontend/build/vis-module.bundle.js

Large diffs are not rendered by default.

Large diffs are not rendered by default.

134 changes: 113 additions & 21 deletions cs1302_code_visualizer/frontend/js/connectorRouting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { SHAFT_CLEARANCE } from "./shaftClearance";
import { SOURCE_RADIUS } from "./connectorGeometry";
import { Attachment, Point, Rect, Route, bounds, circleIntersects, expand, intersects,
routeReference, routeFrameParent } from "./referenceRouting";
import { attachSharedReferenceBaseline, planSharedReferences, type SharedReferencePlan } from "./sharedReferenceRouting";

export type ReferenceRoutingPolicy = "historical" | "independent" | "shared";

/** IDs and indices bind results outside the solver; none of these facts contain DOM nodes. */
export interface MeasuredConnectorEdge {
Expand All @@ -11,6 +14,12 @@ export interface MeasuredConnectorEdge {
targetId: string;
heapOrigin: boolean;
attachment: Attachment;
/** Null or absent means compatible semantic paint has not been established. */
styleKey?: string | null;
/** The measurement adapter establishes source/target identity eligibility. */
sharingEligible?: boolean;
/** Per-measurement target element identity token, independent of target ID. */
targetIdentity?: number;
}

export interface MeasuredConnectorScene {
Expand All @@ -33,16 +42,20 @@ export interface PlannedConnector {
}

export interface ConnectorRoutePlan {
/** Routing order; sharing-plan member indices address this array. */
connectors: PlannedConnector[];
/** Unexpanded control-point/head bounds, matching legacy canvas allocation. */
extent?: Rect;
searchTimings: {kind: string; ms: number}[];
sharingPlan?: SharedReferencePlan;
baselineOrdering?: "source" | "target";
}

/** Every edgeIndex addresses the original scene.edges, even after target ordering. */
export type RoutingConstraint =
| {kind: "reservation-retry"; edgeIndex: number}
| {kind: "covered-source"; edgeIndex: number; blockerOwners: number[]; sourceCanExit: boolean}
| {kind: "no-candidate"; edgeIndex: number; sourceCanExit: boolean}
| {kind: "no-candidate"; edgeIndex: number; sourceCanExit: boolean; targetCapacity?: number}
| {kind: "frame-parent"; edgeIndex: number};

export type RoutingResult =
Expand All @@ -63,13 +76,53 @@ function sourceDotBounds(source: Point): Rect {

export class ConnectorRouting {
/** Stateless planner. Accepted-scene reuse belongs to the coordinator, outside the solver. */
public plan(scene: MeasuredConnectorScene, reserveTurns=false): RoutingResult {
const {objects,text,localEndpoints,edges}=scene;
public plan(scene: MeasuredConnectorScene, reserveTurns=false,
policy: ReferenceRoutingPolicy="historical"): RoutingResult {
const controlled=policy!=="historical";
const {objects,text,localEndpoints}=scene;
// Lane and strictness belong to this plan, never to the supplied measurement.
const edges=scene.edges.map((edge,originalIndex)=>({...edge,originalIndex,
attachment:{...edge.attachment,strict:controlled}}));
const stack=edges.filter(e=>!e.heapOrigin);
const heapLeft=Math.min(...objects.filter((_,i)=>scene.heapOwners[i]).map(r=>r.left));
reserveTurns ||= stack.some(({attachment:a})=>new Set(stack.filter(e=>e.attachment.source[0]===a.source[0])
.map(e=>e.attachment.targetKey)).size*(SHAFT_CLEARANCE+a.width)>heapLeft-a.sourceBox.right);
const heads:Rect[]=[],routes:Route[]=[],connectors:PlannedConnector[]=[];
const heapLeft=Math.min(...objects.filter((r,i)=>scene.heapOwners[i]&&
(!controlled||(r.right>r.left&&r.bottom>r.top))).map(r=>r.left));
const crowded=(sources:typeof stack)=>sources.some(({attachment:a})=>
new Set(sources.filter(e=>e.attachment.source[0]===a.source[0])
.map(e=>e.attachment.targetKey)).size*(SHAFT_CLEARANCE+a.width)>heapLeft-a.sourceBox.right);
reserveTurns ||= crowded(stack);
const ordinaryStack=stack.filter(e=>!e.attachment.parent);
const baselineOrdering=controlled&&crowded(ordinaryStack)?"target":"source";
if(baselineOrdering==="target") {
// Parent-pointer and heap-reference slots stay fixed while ordinary stack
// references establish the same crowded, target-ordered baseline as PR28.
const canonical=(id:string)=>id.replace(/^v\d+__/,"");
const ordered=[...ordinaryStack].sort((x,y)=>
x.attachment.target.left-y.attachment.target.left||x.attachment.target.top-y.attachment.target.top||
canonical(x.targetId).localeCompare(canonical(y.targetId))||
x.attachment.source[1]-y.attachment.source[1]||x.attachment.source[0]-y.attachment.source[0]||
canonical(x.sourceId).localeCompare(canonical(y.sourceId)));
let next=0;
edges.forEach((edge,i)=>{if(ordinaryStack.includes(edge))edges[i]=ordered[next++];});
}
const sourceCounts=new Map<string,number>();
for(const edge of edges)sourceCounts.set(edge.sourceId,(sourceCounts.get(edge.sourceId)??0)+1);
const eligible=(edge:MeasuredConnectorEdge)=>{
const a=edge.attachment;
return edge.sharingEligible===true&&!!edge.sourceId&&!!edge.targetId&&
sourceCounts.get(edge.sourceId)===1&&!a.parent&&!a.returning&&
!(a.sourceOwner>=0&&a.sourceOwner===a.targetOwner);
};
const sameTarget=(x:MeasuredConnectorEdge,y:MeasuredConnectorEdge)=>
x.targetIdentity!==undefined&&y.targetIdentity!==undefined
?x.targetIdentity===y.targetIdentity:x.targetId===y.targetId;
const logicalEdges=(routes:Route[])=>routes.map((route,i)=>{
const edge=edges[i];
// Keep per-scene keys unique for ineligible duplicate or anonymous sources.
return {key:JSON.stringify([edge.sourceId,sourceCounts.get(edge.sourceId)===1?null:i]),
attachment:edge.attachment,route,styleKey:edge.styleKey??null,eligible:eligible(edge)};
});
const heads:Rect[]=[],routes:Route[]=[];
let ownedGroups:SharedReferencePlan["groups"]=[];
const searchTimings:ConnectorRoutePlan["searchTimings"]=[];
const arrivals=new Map<number,number>();
// Keep the original reservation construction, candidate order, costs and caps.
Expand All @@ -81,31 +134,70 @@ export class ConnectorRouting {
guard:expand(bounds([end]),SHAFT_CLEARANCE+a.width/2)} as Route : undefined;
});
for(const [index,edge] of edges.entries()) {
const started=performance.now();
// Lane assignment is per plan, never a mutation of the supplied measurement.
const a:Attachment={...edge.attachment,lane:arrivals.get(edge.attachment.targetOwner)??0};
const started=performance.now(),a=edge.attachment;
a.lane=arrivals.get(a.targetOwner)??0;
const dots=edges.filter((_,i)=>i!==index).map(e=>sourceDotBounds(e.attachment.source));
const dotHits=text.map((r,i)=>({r,i})).filter(({r})=>circleIntersects(a.source,SOURCE_RADIUS,expand(r,1)));
const future=reservations.slice(index+1).filter((r):r is Route=>!!r);
const turns=reserveTurns?future.filter(r=>r.targetKey!==a.targetKey).map(r=>r.guard!):[];
const route=dotHits.length?undefined:(a.parent ? routeFrameParent : routeReference)(a,
[...text,...dots,...localEndpoints,...turns],objects,heads,[...routes,...future]);
let ownedBaseline:SharedReferencePlan|undefined;
const ownedFallback=()=>{
if(!controlled||!eligible(edge))return undefined;
const incoming=edges.filter(e=>sameTarget(e,edge));
const spacing=Math.max(8,SHAFT_CLEARANCE+Math.max(...incoming.map(e=>e.attachment.width)));
const perimeter=2*(a.target.right-a.target.left+a.target.bottom-a.target.top);
// Ordinary scenes retain independent search. Owned suffixes are an
// option for oversubscribed arrivals or an already established suffix.
if(incoming.length*spacing<=perimeter&&
!ownedGroups.some(g=>g.targetKey===a.targetKey))return undefined;
ownedBaseline=attachSharedReferenceBaseline({
edges:logicalEdges([...routes,{segments:[],head:[],kind:"pending"}]),objects,
obstacles:[...text,...localEndpoints,...turns,
...edges.slice(index+1).map(e=>sourceDotBounds(e.attachment.source)),
...future.flatMap(r=>r.segments.map(s=>expand(bounds(s),SHAFT_CLEARANCE+(r.width??1)/2)))],
optimize:false,
},index);
return ownedBaseline?.routes[index];
};
// Once declared, an owned suffix is protected from every later reference.
const sharedObstacles=ownedGroups.flatMap(g=>g.physicalPieces.map(p=>
expand(bounds(p.segment),SHAFT_CLEARANCE+Math.max(...p.members.map(i=>edges[i].attachment.width))/2)));
const obstacles=[...text,...dots,...localEndpoints,...turns,...sharedObstacles];
const route=dotHits.length?undefined:a.parent
?routeFrameParent(a,obstacles,objects,heads,[...routes,...future])
:routeReference(a,obstacles,objects,heads,[...routes,...future],false,ownedFallback);
if(!route) {
if(!dotHits.length&&!reserveTurns)return {ok:false,constraint:{kind:"reservation-retry",edgeIndex:index}};
if(a.parent)return {ok:false,constraint:{kind:"frame-parent",edgeIndex:index}};
const edgeIndex=edge.originalIndex;
if(!dotHits.length&&!reserveTurns)return {ok:false,constraint:{kind:"reservation-retry",edgeIndex}};
if(a.parent)return {ok:false,constraint:{kind:"frame-parent",edgeIndex}};
const sourceCanExit=departureCandidates(a).some(p=>![...text,...dots,...localEndpoints].some(r=>
intersects([a.source,p],expand(r,1+a.width/2))));
return {ok:false,constraint:dotHits.length ? {kind:"covered-source",edgeIndex:index,sourceCanExit,
blockerOwners:dotHits.map(h=>scene.textOwners[h.i]).filter(owner=>owner>=0&&owner!==a.sourceOwner)} :
{kind:"no-candidate",edgeIndex:index,sourceCanExit}};
if(dotHits.length)return {ok:false,constraint:{kind:"covered-source",edgeIndex,sourceCanExit,
blockerOwners:dotHits.map(h=>scene.textOwners[h.i]).filter(owner=>owner>=0&&owner!==a.sourceOwner)}};
const incoming=controlled?edges.filter(e=>sameTarget(e,edge)):[];
const targetCapacity=controlled?incoming.length*Math.max(8,
SHAFT_CLEARANCE+Math.max(...incoming.map(e=>e.attachment.width)))+20:undefined;
return {ok:false,constraint:{kind:"no-candidate",edgeIndex,sourceCanExit,targetCapacity}};
}
if(ownedBaseline) {
routes.splice(0,routes.length,...ownedBaseline.routes.slice(0,index));
ownedGroups=ownedBaseline.groups;
}
route.width=a.width;route.target=a.target;route.targetKey=a.targetKey;
routes.push(route);heads.push(bounds(route.head));
connectors.push({connectionIndex:edge.connectionIndex,attachment:a,route});
arrivals.set(a.targetOwner,a.lane!+1);
arrivals.set(a.targetOwner,a.lane+1);
searchTimings.push({kind:route.kind,ms:performance.now()-started});
}
const paint=routes.flatMap(r=>[...r.segments.flat(),...r.head]);
return {ok:true,plan:{connectors,extent:paint.length?bounds(paint):undefined,searchTimings}};
let sharingPlan:SharedReferencePlan|undefined;
if(controlled) {
sharingPlan=planSharedReferences({edges:logicalEdges(routes),
obstacles:[...text,...localEndpoints],objects,optimize:policy==="shared"});
if(!sharingPlan.baselineValid)throw new Error("Cannot establish an independent or explicitly shared reference baseline: "+
sharingPlan.diagnostics.map(d=>d.reason).join("; "));
}
const finalRoutes=sharingPlan?.routes??routes;
const connectors=edges.map((edge,i)=>({connectionIndex:edge.connectionIndex,attachment:edge.attachment,route:finalRoutes[i]}));
const paint=finalRoutes.flatMap(r=>[...r.segments.flat(),...r.head]);
return {ok:true,plan:{connectors,extent:paint.length?bounds(paint):undefined,searchTimings,sharingPlan,baselineOrdering}};
}
}
Loading
Loading