# Layout specification

Position = (lane start + tier, row). The rules are in [DAG rendering](https://fzkuji.github.io/OpenProgram/docs/reference/design/runtime/dag/rendering.html); these scenes are what they produce.

| Letter | Node |
| --- | --- |
| R | ROOT |
| U | Your message |
| A | Agent reply |
| F | Function call or Program run |
| M | Merge |

Letters stand in for the icons on the real round chips. Lane 0 is filled, other lanes outlined. The narrow view lists each node as column,row.

## Conversation

1. **One message** ROOT 0,0 · Hello 1,1 · Reply 2,2
2. **Two turns** ROOT 0,0 · Hello 1,1 · Reply 1 2,2 · Weather 1,3 · Reply 2 2,4
3. **Manual function, open** ROOT 0,0 · Hello 1,1 · Reply 2,2 · gui_agent 1,3 · gui_step 2,4 · conclusion 2,5

- Every turn and every manual Program hangs off ROOT, not off the previous reply.
- Calls inside a function are one flat, time-ordered column, however deep they nest.

## Retry

1. **Retry** ROOT 0,0 · Hello 1,1 · Reply 1 2,2 · Edited 5,1 · Reply 1′ 6,2
2. **Three versions of one turn** ROOT 0,0 · v1 1,1 · r1 2,2 · v2 5,1 · r2 6,2 · v3 10,1 · r3 11,2

| Column | Use |
| --- | --- |
| 3 | Gap: the branch is a parallel version |
| 4 | The fork lane's empty spine, where the dashed bridge lands |
| 5, 6 | The fork's turn and reply |

## Call threads

1. **Folded** ROOT 0,0 · Weather 1,1 · Reply 2,2
2. **Open** ROOT 0,0 · Weather 1,1 · Reply 2,2 · bash 3,3 · web_fetch 3,4 · open_meteo 3,5
3. **Folded: the default** ROOT 0,0 · Question 1,1 · Reply 2,2 · Edited 5,1 · A′ 6,2 · Follow-up 1,3 · Reply 2 2,4
4. **Open: rows insert, columns stay** ROOT 0,0 · Question 1,1 · Reply 2,2 · Edited 5,1 · A′ 6,2 · Follow-up 1,4 · Reply 2 2,5 · web_search 3,3

Thread items reserve no lane width. Closing a thread gives back its rows.

## Branches talking

1. **Merge** ROOT 0,0 · Question 1,1 · Reply A 2,2 · Edited 5,1 · B 6,2 · merge 2,3
2. **send_message** ROOT 0,0 · Question 1,1 · A 2,2 · send 3,3 · Branch B 5,1 · B 6,2 · U 5,3 · A 6,4 · From B 1,5 · A answers 2,6
3. **Agent spawned on a thread, both open** ROOT 0,0 · Question 1,1 · A 2,2 · read 3,3 · F 3,4 · A 4,5 · bash 4,6 · write 3,7

| Scene | Rule |
| --- | --- |
| Merge | One node with several parents, in the base lane. Each peer tip feeds it with a thick line in the peer's colour. |
| `send_message` | Returns at once; neither branch blocks. The message lands at the end of the target branch. The answer comes back as a new user-tier turn labelled with the sender's name. Dotted lines appear only on hover. |
| Spawn | A square on its caller's thread, at the moment it happened, with a name tag. Its own thread is one column further right and pushes later items down. No return line: the follow-up reply merges into the same anchor. |

## Node states and marks

| State | Drawn as |
| --- | --- |
| Running | The chip's own icon animates, and beads ride the belt leading to it. No placeholder node. |
| Error | A red `!` on the chip's upper-right edge; the rest of the turn is unchanged. |
| Cancelled | The whole node fades, shape kept. |
| Count | Digits on the upper-right shoulder: how many events are folded. Not a node. |
| `↗` | Cross-session spawn, on both sides: the source node and the target branch root. |

## Branch-name badges

1. **Beside the deepest visible node** ROOT 0,0 · Question 1,1 · A 2,2
2. **Follows an open thread** ROOT 0,0 · Question 1,1 · A 2,2 · F 3,3
3. **Collision: the later name slides down a row** ROOT 0,0 · Question 1,1 · A 2,2 · Edited 5,1 · A 6,2

- Collisions use measured pixel boxes, and every visible node counts as an obstacle.
- Badges come only from active `list_branches` rows. A merged branch loses its badge; its name moves to the merge node's tooltip.

## What counts as a branch tip

`SessionStore.list_branches()` in `openprogram/state/store/session/session_store/branches.py` returns only true leaves of the conversation predecessor graph, plus the head.

| Continues the conversation | Does not |
| --- | --- |
| User and reply nodes; top-level Programs (empty or ROOT caller); runtime-scheduled user rows | Internal execution children, other runtime rows, structural and root rows, `attach`, `context/*` |

Sequential top-level Programs leave one tip, the last. Parallel siblings each stay a tip.

## Retry and lanes

Top-level Programs under ROOT stay on the ROOT lane in time order. Only a persisted `metadata.retry_of` opens a fork lane. The Retry entry point writes it; `build_session_graph()` exposes it to layout.

## Frontend modules

Under `apps/web/lib/runtime-bridge/dag/`:

| Folder | Holds |
| --- | --- |
| `passes/` | Data projection |
| `layout/` | Geometry |
| `render/` | Drawing |
| `interaction/` | Interaction and camera |
| Root | Public entry points, types, paint gate, pipeline |

Tooltip content is separate from its DOM lifecycle, graph preparation from SVG commit, node classification from ownership. A file stays within about 500 lines. Splitting one must not change public entry points, DOM classes, SVG structure, test-visible state or camera behaviour.

[Try the layout algorithm on sample data](https://fzkuji.github.io/OpenProgram/docs/reference/design/runtime/dag/live-layout.html)
