Brickheart

Plan for the next session: attach in touch mode

: Written by a human with AI assistance.

Status tags are used throughout. Nothing in this plan has been run, and anything marked Verify or Open is unread or undecided.

1. Where things stand

  • Decided: bench-split-6-collide is merged into main, and the owner reports all tests and the build pass.
  • Decided: the fix for app/i18n.test.mjs (it now reads src/bench/*.ts) and the touchUi guard in bench/config.ts went in as one commit.
  • Still open from the handover:
    • whether collide-client, collide-store and collide.worker belong in bench/;
    • the settings registry (roadmap/next/settings-registry.md), which comes after attach unless the owner says otherwise.

2. The design for ui=touch (owner's words, restated)

Decided:

  1. The user taps a part in the scene. This is the target. The history list, Select and Pick are not used.
  2. In attach mode the gizmo sits on the target. It cycles through the target's open connector types. "Open" means the a least on connector of that type has no mate.
  3. Cycling sets the padlocks. A wall part is locked when it has no connector that fits the cycled type.
  4. The user picks an unlocked part from the wall. It previews on the attachment point with the lowest index eg stud[0], and the gizmo moves to the previewed part.
  5. On the previewed part the gizmo does three jobs:
    • it moves the part between mate points when there are several; it is not a 'free' move mode so cannot be moved to be unattached.
    • it changes rotation while the part stays connected;
    • it shows a collision warning.
  6. The preview is held uncommitted, because that is the simpler option. Cancel drops it. Confirming commits one put op.
  7. Cancel and Undo already exist. Undo is not the way back from the preview, because nothing is committed until confirm.
  8. A move or rotate after a placement is a new mate. Nothing is released or recorded.
  9. "Used" means the connector already has a mate. Touching or overlapping alone does not count.
  10. The wall's connector types are precomputed. The collision warning replaces the "collide priority" big list which is still use in other modes.

Proposed (not yet confirmed by the owner):

  • The gizmo's "type" is the key (kind, sub, polarity), not Connector.type. Compatibility depends on those three fields, so cycling by type alone would be wrong.
  • Rotation while connected is the discrete set the code already has: four yaws, plus flip where the joint allows it. It is not free rotation.
  • Moving between mate points means candidates with the same cycled type but a different to.index or by.index.

3. What the code does today (read, not run)

attach-ui.ts

  • It is a fieldset panel with a relation select, a position select, a Go button and a status line.
  • It works whenever a placed part is selected and a palette part is held (ctx.activeRow).
  • It builds candidates with jointCandidates(sel, act.stem, rel) plus touchCandidates, and rebuilds when a key changes: target id and pose, held stem, relation, and sceneKey.
  • host.rank() asynchronously returns clear, hit or unknown per candidate, and seatedOverlap exempts pin-in-hole and open-stud joints.
  • Go calls host.commit(c, sel.id).

bench/actions.ts

  • putCandidate pushes { k: 'put', id, row, pose, to, joined, exempt }. It drops the candidate's to and by addresses.
  • cancel clears activeRow first, then selId.
  • undo and redo only move ctx.cursor.

bench/state.ts

  • derive() builds placed parts as rec poses and never builds an Assembly, so no mate record exists.
  • Anchors (stem 85861) are ordinary entries in recs.
  • buildExtent shows the LDraw conversion: [...rec.m, rec.x, -rec.y, -rec.z].

bench/input.ts line 144: in touch mode, tapping a wall part does pick(); place(), which puts it on the free anchor. With a target selected this must change to pick and preview.

snap/graph.ts and snap/pairs.ts

  • connectionsFor(parts: PosedPart[], index, cat) returns the edges between one part and the rest.
  • PosedPart is { stem, pose } in LDraw space.
  • GEdge.aConn and GEdge.bConn are native connector indices, the same as Connector.nativeIndex.
  • findPairs uses a spatial hash with POS_THR = 3 and passes each candidate through judge(). Only fast and extra verdicts become edges, so merely touching parts do not count.
  • judge() rules:
    • Stud and hole pairs use STUD_MATE_MAT, with a signed axis dot of at least 0.95.
    • Hinge and ball need the same subEnc and opposite polarity, and hinge also needs an axis match.
    • Fixed uses a position, axis and frame-trace test.
    • Axles use AXLE_MATE_MAT, an overlap rule and a wider search radius.
  • graph.ts is not exported from agent.ts. The bench would import it directly.
  • connectionsFor is only called from graph.test.ts. It is a new call from the bench.
  • data().catalog is available once the attach data has loaded, and bench.ts already loads it at start.
  • Conn has kind, sub, pol, subIdx, length, subEnc, polEnc and frame.

4. The open-connector list (Decided method, not built)

  1. Build PosedPart[] from st().recs with the buildExtent conversion.
  2. Get the target index from st().idx.get(ctx.selId).
  3. Call connectionsFor(parts, index, data().catalog).
  4. For each edge, the used connector on the target is aConn if a === index, otherwise bConn.
  5. Open list = info(stem).conns indices minus the used set. Wrap each as a Connector for compatible() and placement().
  6. Group by (kind, sub, pol). Those groups are the gizmo's cycle.
  7. Rebuild on selection change and scene change, using the same trigger as the picker's sceneKey.

5. Padlocks

  • Static layer: for each distinct wall stem, read its connector keys once from connectors(stem) and cache them. The cache never changes during a session.
  • Dynamic layer: for the target's current cycled key, a wall stem is locked if none of its connectors satisfies compatible() with that key.
  • The lookup can use STUD_MATES and AXLE_MATES from catalog.ts, and same-sub opposite-pol for hinge, ball and fixed.

6. Work order

  1. Read first (no code):
    • snap/catalog.ts lines 54-135 (the Catalog class and whether anchor stem 85861 has connectors);
    • bench/input.ts, bench/scene.ts, bench/rows.ts, bench/palette.ts and bench.ts in full;
    • the 15 Nov post "Bench anchors as parts, floating wall and cameras", to learn how the wall is built and how a wall part maps to a stem;
    • whether any gizmo code already exists (Verify, not found in the files read).
  2. Finish the design with the owner (no code): settle the three Open items in section 7.
  3. Build in small commits, one step each, on a new branch:
    1. The open-connector function (pure, no UI) with a test against connectionsFor on two stacked bricks. Run npm test in app.
    2. The per-stem connector-key cache and the padlock lookup, with a test.
    3. An attach-mode state in ctx (target, cycled key, preview candidate), and the touch tap change at input.ts line 144.
    4. The preview: show the candidate pose uncommitted, with Cancel dropping it and confirm calling putCandidate.
    5. The gizmo controls: cycle type, step mate points, step yaw and flip, and show the rank result as the warning.
    6. Retire the picker panel's relation select, position select and big list once the gizmo covers them.
  4. Test on the real phone with ?ui=touch. Report the anchors.ts phone check at the same time.

7. Open design questions

  • Relation (on, under, front, behind, left, right): the new flow has no relation select. jointCandidates needs one. It could become a facet of the gizmo, or default to all relations. Note: relational positioning is not attach it is PLACE.
  • Touch candidates (touchCandidates): they have no connector, so they do not fit the connector cycle. Keep them as a fallback or drop them.
  • Which part of the gizmo the user can reach on a phone: the controls are handles in the scene around the active part.

8. Rules for the next Claude

  • Follow CLAUDE.md. Read the code before writing, and say "untested" or "not read" on every unchecked claim.
  • Ask at most one question per reply, and put it last. Do not ask what the code can answer.
  • This starts as a design session. Write no code until the owner says build.
  • When building, give Python patch scripts with count == 1 anchors, then git diff --stat and npx tsc --noEmit -p app. The owner runs npm test inside app, and the snap tests are app/src/snap/*.test.ts.
  • The dev workspace has no test script. Run node --test changelog.test.mjs from dev if needed.
  • At session end, the usual script writes the blog post, changelog entries (plain sentences for visitors) and roadmap items. This session produced no script, only this plan.