Repository navigation
feat(chat): /untangle tries layouts against crossings and puts the best to the person - #234
Merged
Merged
Conversation
…st to the person In Build mode, where the producer can write a definition's port order (reorderEntityPorts), /untangle hands the agent three tools on the diagram: - untangle-start lays the diagram out with Layout Diagram, the drawing to beat, and lists the definitions with several instances; - untangle-try draws Free Ports (with the orders the agent gives some definitions) or Untangled, at most ten times, each with its crossings and its picture, saved nowhere; - untangle-propose puts one try to the person in a card: its picture, its crossings against Layout Diagram, each definition's port order old and new per source file, Apply to N files and Discard. The person's answer is the platform's to carry out. Apply writes the orders and saves the try's layout as one undo (the layout file kept out of the snapshots; undo and redo save the drawing they go back to), and a refused write puts back what was written. The chat then shows the two drawings side by side. Discard draws the diagram as it was. A chat command may now answer with a prompt the agent carries out as the turn, and a diagram's session can put a card or a message with pictures to the person (DiagramChatHost). Claude-Session: https://claude.ai/code/session_011UYzzUKxNqKPdmLsRmJ6Xu
… was proposed - untangle-start starts over from a try put to the person that they never answered (a card lost with the panel); the late answer applies nothing and the chat says so. The tries made count across a restart: ten in all. - /untangle's turn over, however it ended, untangle-end draws back a try the agent left drawn without proposing it (ChatCommandResult.afterTurn); the next node moved would have saved it. - Apply saves the proposed try's own drawing, not what is drawn when the button is pressed, and is one command (ApplyUntangleCommand): undo and redo draw and save the layout first, then put the files back; a layout with no port order to write is still an edit to undo. - A write that throws puts back what was written, like one refused, and says why. - A definition drawn with different ports in different places (same name, same file) is split: its order is not written, nor given by name. - A geometry keeps every element's place and size (labels, compartments), so Discard draws the diagram as it was. Claude-Session: https://claude.ai/code/session_011UYzzUKxNqKPdmLsRmJ6Xu
The live check ran /untangle twice in one chat (Apply, Undo, again). The second time the agent called no tool and answered "Already done" from its first turn. The prompt now says each untangle is a new one, the diagram maybe changed since, and that the answer comes from what the tools say now. Claude-Session: https://claude.ai/code/session_011UYzzUKxNqKPdmLsRmJ6Xu
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
/untanglein the diagram chat (Build mode). The agent lays the diagram out with Layout Diagram, the drawing to beat. It then makes at most ten tries against edge crossings, starting with Free Ports, where every instance of a definition takes one port order (#233). The best try goes to the person in a card, with its picture and the source files it would change. Apply to N files writes the port orders (huawei-csl/wfpy#92reorderEntityPorts) and saves the layout, both as one undo. The chat then shows the Layout Diagram drawing and the untangled one side by side. Discard draws the diagram as it was.How
diagram-server (neutral)
LayoutPreview(operations/layout-preview.ts):persist: falseand given port orders;UpdateModelActionand a fit, ahead of the picture's export, because the client draws only what is in view.layoutGeometryOf/applyLayoutGeometry/saveLayoutGeometry(server/layout-snapshot.ts): a drawing taken, drawn again, or saved as the layout.definition-port-order.ts:sidesOf(node, 'drawn' | 'declared')anddefinitionsUnder(root);DiagramChatHost(server/diagram-chat-host.ts): what a diagram's session uses to put a card or a message with pictures to the person.sidecar-toolkit (
server/untangle/)untangle-session.ts:orderToWriterefills each side's declared slots, so inputs and outputs keep their places among each other.untangle-mcp-tools.ts, the tools:untangle-start,untangle-tryanduntangle-propose;apply-port-orders-handler.ts(dialogram.applyPortOrders):reorderEntityPortsto each definition's own file (entityFileOf);reorderEntityPorts;/untanglechecks for that op too.extension-core
ChatCommandResult.prompt: the command's prompt goes to the agent as the turn, with no confirmation and no post-turn hook. The hook's "layout" keyword would otherwise run Compact over the result./untangle(Build mode) returnsUNTANGLE_PROMPT.ChatRuntime.canAsk/postInChat.GlspIntegrationHandle.setDiagramChatHost, wired by the profile runtime.DiagramChatConfirm.figures.diagram-client
figures, side by side where the panel is wide enough.Tests
sidecar-toolkit:untangle.test.ts:untangle-mcp-tools.test.ts:extension-core:postInChat;/untangleis offered only where the op is listed.diagram-server: a layout geometry drawn again and saved.diagram-client: figures on cards and messages, and a click opening one./tmp/flow.py, and my/tmpis large. They pass with a longer timeout.Review (
/code-review medium), fixed in 64bf0e5untangle-startstarts over from it, and a late answer applies nothing; the chat says so./untangle's turn ends, however it ends (ChatCommandResult.afterTurncallsuntangle-end). Otherwise the next node move would save it.ApplyUntangleCommand). Undo and redo draw and save the layout first, then put the files back. A try that changes no port order still leaves an undo entry for its layout.orders.figuresOfis computed once.untangle-end;afterTurnruns when the turn ends normally and when it fails;Live check
The check ran in the wfpy harness with opencode and nemotron-3.5-super-vl-free, on a demo with three
Stage, threeMergeand twoimageinstances.untangle_parts.py: theclass Portslines of Stage and Merge, and theinputs=/outputs=entries ofimage, each comment kept with its line;/untanglein the same chat: the agent called no tool and answered "Already done" from its first turn. Fixed in 8e79785: the prompt says each untangle starts over. Rerun: 6 tries; Discard drew the original and wrote nothing.opencode.jsonthat deniesexecute, the tools are called directly and every result carries its PNG. The agent then broke a 23/23 tie by the picture ("try 4 reads better: shorter edges into m1/m2"). Apply posted both pictures side by side. Dialogram cannot switch this per server: ACP'smcpServershas no field for it.https://claude.ai/code/session_011UYzzUKxNqKPdmLsRmJ6Xu