Files
serena/scripts/memory_graph.py
T
Dominik Jain 6707cd9b7e Introduce component-based licensing: Serena GPL-3.0-or-later, SolidLSP MIT
The repository is licensed per component. SolidLSP (src/solidlsp,
test/solidlsp, test/resources) remains MIT-licensed and independently
reusable; the Serena application (src/serena, src/interprompt, scripts,
test/serena, docs) is licensed under GPL-3.0-or-later starting with the v2
licensing transition. The change is not retroactive: all releases and
commits up to v1.7.0 / 74c38a65 (tag mit-final) remain available under MIT.

Since MIT is GPL-compatible, a distribution combining both (such as the
serena-agent package) is as a whole subject to GPL-3.0-or-later, while the
SolidLSP files themselves stay MIT and can be extracted and used separately
under MIT terms. The distribution metadata therefore declares
GPL-3.0-or-later, with both license texts shipped alongside it.

Serena originally began under the GPL (v2) and was switched to MIT in
May 2025 following community requests. We consider that change a mistake;
the substantial changes in v2 make this the appropriate time to revert it.
We want the best version of Serena to remain free.

Changes:
* LICENSE is now the licensing overview; canonical license texts live in
  LICENSES/ (MIT.txt is the previous LICENSE verbatim, GPL-3.0-or-later.txt
  is the unmodified FSF text)
* pyproject.toml declares the PEP 639 license expression
  "GPL-3.0-or-later" and bundles LICENSE and LICENSES/* as license files;
  the deprecated MIT classifier is dropped and flake.nix declares gpl3Plus;
  README has per-component license badges and a License section
* SPDX-License-Identifier headers in all Python sources under src/ and
  scripts/, added by the new idempotent scripts/add_spdx_headers.py, which
  gen_prompt_factory.py also uses to keep the header on the generated
  module; existing third-party notices are preserved
* CLA.md: Contributor License Agreement (contributor retains copyright;
  grants a perpetual, irrevocable license including relicensing under any
  terms, incl. proprietary/commercial; patent grant; authority
  representations), to be enforced repository-wide via cla-assistant.io
* CONTRIBUTING.md, PR template and a new docs page explain the licensing
  boundary and the CLA workflow
2026-09-14 21:33:18 +02:00

64 lines
2.5 KiB
Python

"""Generates a GraphML file of the memory reference structure for a given project."""
# SPDX-License-Identifier: GPL-3.0-or-later
import argparse
import xml.etree.ElementTree as ET
from serena.config.serena_config import SerenaConfig
from serena.memories.memory_reference_analysis import iter_referenced_names_in_content
def main() -> None:
parser = argparse.ArgumentParser(description="Generate a GraphML graph of memory references for a Serena project.")
parser.add_argument("project", help="Name (or root path) of the registered project.")
parser.add_argument("-o", "--output", default="memory_graph.graphml", help="Output file path (default: memory_graph.graphml).")
args = parser.parse_args()
# load project and its memory manager
serena_config = SerenaConfig.from_config_file()
project = serena_config.get_project(args.project)
if project is None:
raise SystemExit(f"Project '{args.project}' not found in Serena configuration.")
mm = project.memory_manager
# gather all project memory names
memories_list = mm.list_project_memories()
all_names = memories_list.get_full_list()
# collect references by reading each memory's content
edges: list[tuple[str, str]] = []
node_names: set[str] = set(all_names)
for name in all_names:
content = mm.load_memory(name)
for referenced in iter_referenced_names_in_content(content):
edges.append((name, referenced))
node_names.add(referenced)
# build GraphML
ns = "http://graphml.graphdrawing.org/xmlns"
y_ns = "http://www.yworks.com/xml/graphml"
graphml = ET.Element("graphml", xmlns=ns)
graphml.set("xmlns:y", y_ns)
ET.SubElement(graphml, "key", id="d0", **{"for": "node", "yfiles.type": "nodegraphics"})
graph = ET.SubElement(graphml, "graph", id="memory_references", edgedefault="directed")
for node_name in sorted(node_names):
node = ET.SubElement(graph, "node", id=node_name)
data = ET.SubElement(node, "data", key="d0")
shape_node = ET.SubElement(data, "y:ShapeNode")
label = ET.SubElement(shape_node, "y:NodeLabel")
label.text = node_name
for i, (source, target) in enumerate(edges):
ET.SubElement(graph, "edge", id=f"e{i}", source=source, target=target)
tree = ET.ElementTree(graphml)
ET.indent(tree)
tree.write(args.output, xml_declaration=True, encoding="utf-8")
print(f"Wrote {len(node_names)} nodes and {len(edges)} edges to {args.output}")
if __name__ == "__main__":
main()