Brickheart

Handover Port BrickAgent to TypeScript in Brickheart-web

: Written by a human with AI assistance.

1. Mission

Continue the existing BrickNet-to-TypeScript work in Brickheart-web. The next major task is to port as much of BrickAgent's functionality as is practical, with assembly construction and attachment as the first implementation priority.

The user interface will be interactive and user-driven, broadly resembling connector-based placement: select a connector on an existing part, select a compatible connector on another part, and attach it. However, the underlying functionality must reproduce the broader BrickAgent attachment semantics, not merely snap two parts together.

BrickNet/Agent collision and stability implementation not in scope.

2. Non-negotiable constraints

  • Browser runtime only. The finished application must run in the browser as part of the existing web app. No Python runtime or Python server dependency.
  • TypeScript implementation. Build on the existing BrickNet TypeScript port
  • Test parity. The port must pass the same tests as the Python package. Identify the complete original test suite, dependencies, test assumptions, and expected behavior. Establish how each test will be executed against the TypeScript implementation.
  • Evidence before decisions. Read the actual source and tests. Run commands and capture their results. Do not infer behavior from class names, documentation alone, or the earlier conversation.

3. Repositories and existing context

BrickNet Python reference: ~/bricknet

Brickheart-web application: /home/chinapal/brickheart-web/app

Existing TypeScript work

The existing BrickNet port includes at least:

  • src/snap/catalog.ts
    • Connector kinds, subtypes, compatibility tables, connector frames, part information, and catalog aliases.
  • src/snap/pairs.ts
    • Connector flattening into world coordinates and connection-pair detection, including stud/hole, hinge, fixed, and axle cases.
  • src/snap/graph.ts
    • LDraw parsing, graph construction, connection edges, connected components, and tree-related operations.
  • src/snap/mat.ts
    • Twelve-number rigid transform representation, multiplication, inversion, rotation helpers, and LDraw transform conversion.
  • src/snap/decode.ts
  • src/snap/path.ts
  • src/snap/place.ts

Relevant existing types include M, Conn, PartInfo, PosedPart, and FlatConn. Inspect their current definitions; do not assume the files have remained unchanged.

4. Phase One: Establish the baseline

Before exploring implementation details, capture the current state of both repositories.

Run appropriate commands, including:

cd ~/bricknet
git status --short
git rev-parse --show-toplevel
git log -1 --oneline
cd /home/chinapal/brickheart-web/app
git status --short
git rev-parse --show-toplevel
git log -1 --oneline
cat package.json
cat tsconfig.json
npm run

Also inspect the parent repository structure if the application is nested in a larger repository.

Run the available application checks, including:

npm run test:snap
npm run typecheck

Deliverable: a baseline report listing repository paths, branches/commits, working-tree changes, test commands, actual results, and current blockers.

5. Phase Two: Map the entire BrickAgent package

Map the package before deciding its final porting boundary. The goal is to understand BrickAgent as a system, not to port only the function that places a part.

Start by locating its installed source and package metadata:

cd ~/bricknet
source venv/bin/activate

python - <<'PY'
import brickagent
print("brickagent:", brickagent.__file__)
PY

Find the installed package directory, its modules, its metadata, and its test sources. Inspect the repository's original tests as well as any tests shipped in the installed package.

Deliverable: a complete package/module inventory and a dependency diagram or ordered dependency list. Identify the public API surface and recommend what should eventually be exposed to the TypeScript application.

6. Phase Three: Trace the attachment path end to end

Attachment is the first functional priority. Follow the actual Python call path from the public assembly API through all supporting operations.

The following previously inspected code is a starting point, not a complete specification.

Assembly.attach in BrickAgent calls:

pose = joints.placement(
    to, source,
    flip=flip,
    slide=slide,
    yaw=yaw,
    seat=seat,
    align=align,
    orient=orient,
)
child = self.add(what, pose=pose, color=color)
bound = child.connector(source) if isinstance(what, Assembly) else Connector(
    (child,), source.native_index
)
self._attachments.append((to, bound))
return child

Inspect the current source to establish the precise meaning of each argument, how the source and target connectors are resolved, how nested assemblies are handled, and when mutations occur.

The Python joints.placement implementation uses rigid transforms and composes the target connector frame, a joint transform, and the inverse source connector frame. Its conventions must be documented from the implementation and tests, not reconstructed from memory.

7. Phase Four: Audit Brickheart-web for reusable functionality

Inspect the existing TypeScript implementation and identify precisely which BrickNet behaviors already exist and which remain incomplete.

Search the rest of the application for:

  • LDraw loading and coordinate conversions.
  • Three.js scene and object transforms.
  • Part selection and interaction.
  • Existing placement or snapping behavior.
  • Catalog loading and alias resolution.
  • Assembly or graph data models.
  • Undo/redo or edit-state management.
  • Rendering, highlighting, and connector visualization.
  • Existing collision or overlap checks.
  • Existing tests and fixtures.

Trace the UI's part-loading and transformation path. Confirm how a transform in the BrickNet M representation is applied to a rendered Three.js part. Record the coordinate conventions, units, handedness, matrix layout, and any conversions between LDraw and Three.js.

Do not assume that a transform can be passed directly to Three.js without conversion.

Compare each reusable TypeScript function with its Python counterpart and corresponding tests.

Pay particular attention to the distinction between detecting whether parts are already connected and calculating the pose that attaches one part to another.