Skip to content

State machine: green arrows where the call is allowed, red crossed arrow from the actual state - #207

Merged
CatarinaGamboa merged 4 commits into
mainfrom
feat/206-call-arrows
Nov 19, 2026
Merged

CatarinaGamboa merged 4 commits into
mainfrom
feat/206-call-arrows

Conversation

@CatarinaGamboa

@CatarinaGamboa CatarinaGamboa commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

In focus mode every arrow of the called method was red, including those from the states where the call is allowed, and the actual state had no arrow for the call at all, since the spec has none. Only facts from the spec and the verifier's error context are drawn, as #206 asks.

What changed

  • The transitions of the called method are green (--lj-state-valid), arrow and label, with their guards. An unmet guard keeps its red text, so in A1_38 reset from open is a green arrow with [marked(this)] in red.
  • Each possible state that rejects the call gets a red arrow, labelled with the method, into a bare red ✕: the attempted call, which leads nowhere the spec knows. The ✕ is a state of the diagram (lj_rejected_<state>, box styled away) so that the layout keeps it clear of the other arrows. When the spec already has a transition of the method from such a state, that one is drawn red and crossed instead, with no ✕. No red arrow when the state of the receiver is unknown (A1_09).
  • The ✕ and its arrow are no spec transition: never dimmed, collapsed, counted in "+N more", listed on hover, or in the copied Mermaid source.
  • Legend: → Where method() is allowed and → ✕ The call, not allowed here, each only when on the diagram; the swatches are arrows.
  • Same colouring with Show all. Dimming, collapsing, the summary line and Ways to fix are untouched.
  • Without the accepted states (no focus, no legend) the called method keeps its plain label, since nothing says where the call is allowed (Codex, round 2).
  • Classes renamed to what they mean: lj-call-allowed, lj-call-rejected (label, transition, marker), ljCallRejected (the ✕).
  • Client version 0.1.4.

Deviations from #206

  • The rejected call is an arrow into a ✕, not a self-loop (PM: a loop says the object stays in its state, which the spec never says).
  • Placement of the ✕: the renderer is ELK layered, which puts the target of an arrow one layer after its source, so in TB the ✕ sits below the red state and in LR to its right; there is no per-node option through Mermaid to keep it level with the state, and a self-loop was the only level shape. In the screenshots the ✕ gets a column of its own, beside the expected state rather than between the red state and it, with its own arrow, so it reads as a branch that ends, not as a step on the way. The label is the method name alone; the ✕ at the end says the rest.

Screenshots (focused State Machine tab)

Task Before After
A1_01 dark
A1_09 dark (state unknown: green only)
A1_38 dark
A1_38 dark, scrolled to the stream set (green reset with the red guard)
A1_01 light
A1_38 light
A1_38 light, stream set
A1_38 Show all, LR
A1_01 Show all, LR

Not in scope: a hint's path (#156), which states are dimmed or collapsed (#170), the Verification tab.

Tests: 153 vitest tests pass (152 on main; one new: the call from a rejecting state drawn as the rejected call); the legend and focus tests adapted, the copy test also excludes the ✕ states. Lint and tsc clean.

Closes #206

🤖 Generated with Claude Code

CatarinaGamboa and others added 2 commits November 18, 2026 19:14
…row from the actual state

In focus mode every arrow of the called method was red, including those
from the states where the call is allowed, and the actual state had no
arrow for the call at all, since the spec has none. Now the transitions
of the called method are green, arrow and label, with their guards (an
unmet guard keeps its red text), and each possible state that rejects
the call gets a red self-loop "✕ method": the attempted call. When the
spec already has a transition of the method from such a state, that one
is drawn as the rejected call instead. No red loop when the state of the
receiver is unknown. The loop is never dimmed, collapsed or counted, as
it is no spec transition. The legend gains the two arrows, each only
when on the diagram. Same colouring with Show all.

Client version 0.1.4 for the study build.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
ELK nests a second self-loop around the first one and its label, and the
rounding then drew it as a wide ellipse across the diagram (A1_01, top
to bottom). No state had two loops before, since the methods between the
same states share an edge, so the rejected call now shares the state's
loop too, as its first line, red; a state without a loop gets a new one.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@CatarinaGamboa

Copy link
Copy Markdown
Collaborator Author

Codex review, round 1 (on ad23230, codex exec review --base origin/main)

I found no actionable regressions in the diff. Type-checking and all 153 unit tests pass.

Nothing to fix. A second round follows on the final diff.

Without them nothing says where the call is allowed, and the legend is
not shown, so a green label had no explanation. The method keeps its
plain label in that case; the possible states stay outlined.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@CatarinaGamboa

Copy link
Copy Markdown
Collaborator Author

Codex review, round 2 (on 0989cb4)

[P2] Avoid marking calls as allowed when accepted states are unknown — diagram.ts:129. When the server reports an invalid call but cannot determine its accepted states (for example, when acceptance depends on arguments), getStateErrorFocus(sm) is null. This branch still labels every transition of the called method green as allowed, leaving the diagram with no rejected-call mark despite the error summary.

Fixed in 303e507: the called method is coloured only when there is a focus (accepted states known). Without one nothing says where the call is allowed and the legend is not shown, so the method keeps its plain label; the possible states stay outlined as before. The existing test for that case now asserts no colour.

CatarinaGamboa added a commit that referenced this pull request Nov 18, 2026
@CatarinaGamboa

Copy link
Copy Markdown
Collaborator Author

Codex review, round 3 (on 303e507)

No actionable regression was identified. The relevant unit tests and TypeScript typecheck pass.

Nothing new; the loop ends here.

@CatarinaGamboa

Copy link
Copy Markdown
Collaborator Author

Clean-code review (clean-code-principles skill, own diff only)

  • client/src/webview/views/fsm/fsm.ts:176 - [core-dry] hasAllowedCall repeats the one-line predicate of diagram.ts:121 (a transition of the called method from a state in invalidStates is the rejected call). Declined: a shared helper would be an export for two call sites with different null handling (the diagram colours without a focus too); the small-PR rule wins over a five-line extraction.
  • client/src/webview/diagram.ts:304 - [core-kiss] colourCallTransitions queries once per kind instead of one query that reads the kind from the class. Declined: two kinds, the loop reads plainly.
  • client/src/webview/styles.ts:1346 - [name-meaningful] the legend arrow swatches share their rules through a local --lj-call-colour variable instead of repeating each colour three times. Kept, no finding.
  • Naming: the classes say what they mean (lj-call-allowed, lj-call-rejected, -transition, -marker); nothing green is called an error. No finding.

Nothing fixed, nothing else found.

A loop says the object stays in its state, which the spec never says of
the rejected call. Each possible state that rejects the call now has a
red arrow, labelled with the method, into a ✕ of its own: a state of the
diagram, so that the layout keeps it clear of the other arrows, with its
box styled away. The spec's own transition of the method from such a
state is still drawn red and crossed, with no ✕ state. The legend's red
arrow ends in the ✕ too. The copied source has no ✕ states, as it has no
error overlay.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@CatarinaGamboa

Copy link
Copy Markdown
Collaborator Author

Clean-code review, addendum (37242d0: the rejected call into a ✕ state instead of a loop)

  • diagram.ts:149-156 - [core-kiss] the ✕ is three lines per rejecting state (state, class, transition) next to the transition map, with the id prefix as a named constant (REJECTED_STATE_PREFIX); the shared-loop branch and its test are gone. No finding.
  • diagram.ts:227 - [func-few-arguments] getCallLabel gained a crossed flag so the spec's own transition from a rejecting state keeps its ✕ while the arrow into the ✕ state does not. Declined to split it into two functions: one line each.

@CatarinaGamboa

Copy link
Copy Markdown
Collaborator Author

Codex review, round 4 (on 37242d0)

[P2] Give synthetic rejected-call states collision-free IDs — diagram.ts:152-155. If a state machine already has a state named lj_rejected_closed and closed rejects the call, this declaration reuses the real state's Mermaid ID; the arrow then points to that real state, whose label and styling are replaced by the ✕.

Declined: a spec would have to name a state lj_rejected_<other state>. The lj_ prefix is the extension's namespace, like the lj- classes and the %% lj- comments the diagram already relies on; guarding against it would add code for a case no spec has.

Nothing else found; the loop ends here.

@CatarinaGamboa
CatarinaGamboa merged commit 894787b into main Nov 19, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

State machine: green arrows where the called method is allowed, red crossed arrow from the actual state

1 participant