feat(export): contextix export --format mermaid|json#17
Merged
kiyeonjeon21 merged 1 commit intovericontext:mainfrom Apr 19, 2026
Merged
feat(export): contextix export --format mermaid|json#17kiyeonjeon21 merged 1 commit intovericontext:mainfrom
kiyeonjeon21 merged 1 commit intovericontext:mainfrom
Conversation
Adds a new top-level CLI command that renders a subgraph around an entity into either JSON (default) or a Mermaid flowchart. Wires in the existing extractSubgraph BFS so nothing new is needed on the graph side. Usage: contextix export --format mermaid --entity "Jerome Powell" --hops 2 contextix export --format json --entity "Fed Funds Rate" --hops 1 Acceptance from vericontext#14: - [x] --format accepts json (default) and mermaid; unknown values exit 1 with a clear message and leave cypher/d2 as future formats. - [x] --entity <name> + --hops <N> scope the export; extractSubgraph does BFS up to N hops (default 2) bounded by --max-nodes (default 200). - [x] Output goes to stdout so users can pipe: `> foo.mmd` / `| pbcopy`. Mermaid rendering notes: - Node ids in the graph are not valid Mermaid identifiers (e.g. "ent_person_jerome_powell"), so the renderer builds a per-subgraph alias map that sanitizes ids to [A-Za-z0-9_] with disambiguation on collision. Labels use the underlying entity name / event title. - Edge labels carry the relation type ("involves", "influences", ...). - Embedded double quotes in labels are escaped to " so the double-quoted label syntax stays well-formed. Smoke test against data/seed-graph.json: $ node dist/index.js export --format mermaid \ --entity "Jerome Powell" --hops 2 --data-dir /tmp/contextix-test graph LR evt_macro_a1b2c3["Fed holds rates steady at 4.25-4.50%"] ... ent_person_jerome_powell -->|involves| evt_macro_a1b2c3 evt_macro_d4e5f6 -->|influences| evt_macro_a1b2c3 ... tsup build is clean. No changes to graph/types.ts or extractSubgraph. Closes vericontext#14
Contributor
|
Thanks @tmchow — really clean first PR. The alias map for Mermaid ids handles the |
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.
Summary
Adds a new
contextix exportcommand that renders a subgraph around an entity as JSON (default) or a Mermaid flowchart. Wires into the existingextractSubgraphBFS; no changes to the graph types or store.Closes #14.
Acceptance (from the issue)
--formatacceptsjson(default) andmermaid. Unknown values exit 1 with a clear message;cypher/d2are left for future formats.--entity <name>+--hops <N>scope the export.extractSubgraphdoes BFS up to N hops (default 2) bounded by--max-nodes(default 200).> foo.mmd) or another tool.Files
src/export/mermaid.ts(57 lines) -- pure function that turns aSubGraphinto a Mermaid flowchart string.src/index.ts-- newprogram.command("export")block registered alongside the existing commands.No changes to
src/graph/types.ts,src/graph/query.ts, or the data file format.Mermaid renderer details
ent_person_jerome_powell) are not valid Mermaid identifiers. The renderer builds a per-subgraph alias map that sanitizes ids to[A-Za-z0-9_]with_Ndisambiguation on collision.entity.nameorevent.titleso the diagram reads like the underlying graph instead of exposing raw ids.involves,influences, ...)."..."(Mermaid's double-quoted label syntax); embedded double quotes escape to".Testing
Built and smoke-checked against
data/seed-graph.json:Closes #14
This contribution was developed with AI assistance (Claude Code).