From d71ea6df74ca56d303b43958109421a9ef300597 Mon Sep 17 00:00:00 2001 From: Axel Meyer Date: Sat, 16 May 2026 13:33:34 +0200 Subject: [PATCH] feat: add generate_topology_block (S2 Phase 1) Builds mermaid graph-LR source from manifest.deps + engine-calls. Asset-libs (no deps, no engine) produce self-node-only output. Per spec section 4.2. Co-Authored-By: Claude Opus 4.7 (1M context) --- init.lua | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/init.lua b/init.lua index aaa175a..4c80372 100644 --- a/init.lua +++ b/init.lua @@ -74,4 +74,28 @@ function M.grep_engine_calls(source_string) return out end +-- Generates mermaid topology-block from manifest + engine_calls. +-- engine_calls: array from grep_engine_calls (presence determines engine-node). +-- Returns: mermaid-source-string (no markers - caller wraps). +function M.generate_topology_block(manifest, engine_calls) + local lines = {"graph LR"} + local self_node = string.format(' this["%s"]', manifest.id) + table.insert(lines, self_node) + + if manifest.deps then + for _, dep in ipairs(manifest.deps) do + local dep_var = string.gsub(dep.id, "[%-%.]", "_") + table.insert(lines, string.format(' %s["%s"]', dep_var, dep.id)) + table.insert(lines, string.format(' this --> %s', dep_var)) + end + end + + if engine_calls and #engine_calls > 0 then + table.insert(lines, ' engine["engine.*"]') + table.insert(lines, ' this --> engine') + end + + return table.concat(lines, "\n") +end + return M