The second PR of t82: PLC projects get a code graph. Until now PLC targets skipped the graph phase entirely.
Stacked on #935 (C and C#): the base is feat/t82-c-csharp-graph, so only this PR's commit shows. Merge #935 first, then retarget this PR to main before #935's branch is deleted (deleting a base branch closes the PR).
What becomes a node (Structured Text .st/.scl/.exp/.il and PLCopen XML exports):
a PROGRAM is a module and an entry point, since the PLC's tasks run it;
a FUNCTION_BLOCK is a class, since each instance keeps its own state;
a FUNCTION is a function.
Edges:
A variable whose type is a function block is a type reference to it.
A call through an instance (Pump1(Start := x)) is a call to the instance's type. The instance name is matched case-insensitively, as IEC 61131-3 reads it; names of other POUs are matched as written.
A call by name (Clamp(level)) is a call.
Standard blocks (TON, CTU) have no node, so their edges stay unresolved and are dropped.
Method calls on an instance (pump1.Reset()) aren't parsed as calls today, so they have no edge.
How it fits together:
The PLC scan reads each source tree once. The findings and the graph both come from that read, and the graph covers every PLC source tree of the target.
GraphEngine::assemble takes nodes and edges parsed outside the graph crate. build_graph is now "parse the directory, then assemble".
FileGraph is public, with node_at / edge_at taking lines instead of tree-sitter nodes.
One build function takes either a tree or a PLC project's POUs. The scan uses it, and so does the explorer's manual rebuild (POST /graph/{id}/build), which would otherwise replace a PLC target's graph with file nodes only.
planned_phases lists GraphBuilding for PLC targets, and its test is updated.
Lines:
A POU now records the line of its END_* keyword, so a finding inside it maps to it.
A PLCopen POU spans its <pou> element in the XML. Its statements keep the lines of the Structured Text reconstructed from the XML, so finding lines and fingerprints don't change.
For PLCopen findings the impact therefore falls back to the file. Matching those findings to their XML lines is a separate change, because it changes fingerprints.
Watch the first nightly after this lands: the PLC fixtures get a code graph for the first time, so the graph counts on PLC targets appear and some triage drift is possible.
Tests:
POU kinds, spans and entry points.
Instance, type-reference and call edges.
PLCopen spans.
The engine linking instances and dropping standard blocks.
Every POU of examples/plc-demo becomes a node.
Agent lib tests: 1,002 pass. Graph tests: 100 pass. Clippy with the CI flags is clean.
Next in t82: the graph card on the target page, and the /chat recommendation.
The second PR of t82: PLC projects get a code graph. Until now PLC targets skipped the graph phase entirely.
**Stacked on #935** (C and C#): the base is `feat/t82-c-csharp-graph`, so only this PR's commit shows. Merge #935 first, then retarget this PR to `main` before #935's branch is deleted (deleting a base branch closes the PR).
**What becomes a node** (Structured Text `.st/.scl/.exp/.il` and PLCopen XML exports):
- a `PROGRAM` is a module and an entry point, since the PLC's tasks run it;
- a `FUNCTION_BLOCK` is a class, since each instance keeps its own state;
- a `FUNCTION` is a function.
**Edges:**
- A variable whose type is a function block is a type reference to it.
- A call through an instance (`Pump1(Start := x)`) is a call to the instance's type. The instance name is matched case-insensitively, as IEC 61131-3 reads it; names of other POUs are matched as written.
- A call by name (`Clamp(level)`) is a call.
- Standard blocks (`TON`, `CTU`) have no node, so their edges stay unresolved and are dropped.
- Method calls on an instance (`pump1.Reset()`) aren't parsed as calls today, so they have no edge.
**How it fits together:**
- The PLC scan reads each source tree once. The findings and the graph both come from that read, and the graph covers every PLC source tree of the target.
- `GraphEngine::assemble` takes nodes and edges parsed outside the graph crate. `build_graph` is now "parse the directory, then assemble".
- `FileGraph` is public, with `node_at` / `edge_at` taking lines instead of tree-sitter nodes.
- One build function takes either a tree or a PLC project's POUs. The scan uses it, and so does the explorer's manual rebuild (`POST /graph/{id}/build`), which would otherwise replace a PLC target's graph with file nodes only.
- `planned_phases` lists `GraphBuilding` for PLC targets, and its test is updated.
**Lines:**
- A POU now records the line of its `END_*` keyword, so a finding inside it maps to it.
- A PLCopen POU spans its `<pou>` element in the XML. Its statements keep the lines of the Structured Text reconstructed from the XML, so **finding lines and fingerprints don't change**.
- For PLCopen findings the impact therefore falls back to the file. Matching those findings to their XML lines is a separate change, because it changes fingerprints.
**Watch the first nightly after this lands:** the PLC fixtures get a code graph for the first time, so the graph counts on PLC targets appear and some triage drift is possible.
**Tests:**
- POU kinds, spans and entry points.
- Instance, type-reference and call edges.
- PLCopen spans.
- The engine linking instances and dropping standard blocks.
- Every POU of `examples/plc-demo` becomes a node.
- Agent lib tests: 1,002 pass. Graph tests: 100 pass. Clippy with the CI flags is clean.
Next in t82: the graph card on the target page, and the /chat recommendation.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
A PLC target now gets a code graph. Before this, PLC targets skipped the
graph phase entirely.
Nodes:
- A PROGRAM is a module and an entry point.
- A FUNCTION_BLOCK is a class.
- A FUNCTION is a function.
Edges:
- A variable whose type is a function block is a type reference to it.
- A call through an instance is a call to its type.
- Calls by name are calls.
- Standard blocks such as TON have no node, so their edges are dropped.
How it fits together:
- The PLC module reads each tree once, and both the findings and the
graph come from that read.
- The engine gets a public assemble step for nodes parsed outside the
graph crate, and FileGraph is public with line-based adders.
- One build function takes a tree or a PLC project's POUs. The scan
uses it, and so does the explorer's manual rebuild, which would
otherwise replace a PLC target's graph with file nodes only.
POU spans:
- A POU records the line of its END_ keyword.
- A PLCopen POU spans its <pou> element in the XML. Its statements keep
their synthetic lines, so finding lines and fingerprints don't change.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
The second PR of t82: PLC projects get a code graph. Until now PLC targets skipped the graph phase entirely.
Stacked on #935 (C and C#): the base is
feat/t82-c-csharp-graph, so only this PR's commit shows. Merge #935 first, then retarget this PR tomainbefore #935's branch is deleted (deleting a base branch closes the PR).What becomes a node (Structured Text
.st/.scl/.exp/.iland PLCopen XML exports):PROGRAMis a module and an entry point, since the PLC's tasks run it;FUNCTION_BLOCKis a class, since each instance keeps its own state;FUNCTIONis a function.Edges:
Pump1(Start := x)) is a call to the instance's type. The instance name is matched case-insensitively, as IEC 61131-3 reads it; names of other POUs are matched as written.Clamp(level)) is a call.TON,CTU) have no node, so their edges stay unresolved and are dropped.pump1.Reset()) aren't parsed as calls today, so they have no edge.How it fits together:
GraphEngine::assembletakes nodes and edges parsed outside the graph crate.build_graphis now "parse the directory, then assemble".FileGraphis public, withnode_at/edge_attaking lines instead of tree-sitter nodes.POST /graph/{id}/build), which would otherwise replace a PLC target's graph with file nodes only.planned_phaseslistsGraphBuildingfor PLC targets, and its test is updated.Lines:
END_*keyword, so a finding inside it maps to it.<pou>element in the XML. Its statements keep the lines of the Structured Text reconstructed from the XML, so finding lines and fingerprints don't change.Watch the first nightly after this lands: the PLC fixtures get a code graph for the first time, so the graph counts on PLC targets appear and some triage drift is possible.
Tests:
examples/plc-demobecomes a node.Next in t82: the graph card on the target page, and the /chat recommendation.
🤖 Generated with Claude Code
062b34105atodc2c9845fd