skills/43-wentorai-research-plugins/skills/tools/diagram/code-flow-visualizer/SKILL.md
Convert Python, JavaScript, and TypeScript functions into Mermaid flowcharts
npx skillsauth add brycewang-stanford/Awesome-Agent-Skills-for-Empirical-Research code-flow-visualizerInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Convert Python, JavaScript, and TypeScript functions into Mermaid flowcharts by analyzing control flow structures. This skill helps researchers document and understand complex algorithmic logic, data processing pipelines, and experimental workflows embedded in code.
Research code often contains intricate control flow: nested conditionals for data filtering, loops over experimental conditions, error handling for API calls, and branching logic for different analysis paths. Understanding this flow is critical for reproducibility, code review, and documentation, yet reading nested code can be cognitively demanding.
This skill translates source code into visual Mermaid flowcharts by parsing control flow structures (if/else, for/while loops, try/catch, match/switch, return statements) and mapping them to flowchart nodes and edges. The resulting diagrams serve as documentation supplements in README files, lab notebooks, and paper appendices.
The approach works by performing a lightweight static analysis of the code's abstract syntax tree (AST). Each control structure maps to a specific flowchart pattern: conditionals become diamond decision nodes, loops become cycles with back-edges, function calls become subroutine nodes, and return statements become terminal nodes.
| Code Structure | Flowchart Element | Mermaid Shape |
|---------------|-------------------|---------------|
| Function entry | Start node | ([Function Name]) |
| Assignment / expression | Process node | [statement] |
| if / else if | Decision diamond | {condition?} |
| for / while loop | Decision + back-edge | {loop condition?} with cycle |
| try / catch | Process + error path | [try block] with dashed error edge |
| return / yield | Terminal / output node | ([return value]) |
| Function call | Subroutine node | [[function_name()]] |
| match / switch | Multi-branch decision | {value?} with labeled edges |
Input code:
def process_papers(papers, min_citations=10):
results = []
for paper in papers:
if paper.year < 2015:
continue
if paper.citation_count < min_citations:
continue
try:
abstract = fetch_abstract(paper.doi)
embeddings = compute_embeddings(abstract)
results.append({"paper": paper, "embedding": embeddings})
except APIError:
log_error(paper.doi)
return results
Output flowchart:
flowchart TD
Start(["process_papers(papers, min_citations=10)"]) --> Init["results = [ ]"]
Init --> Loop{"For each paper in papers?"}
Loop -->|Done| Return(["Return results"])
Loop -->|Next paper| YearCheck{"paper.year < 2015?"}
YearCheck -->|Yes| Loop
YearCheck -->|No| CitCheck{"citation_count < min_citations?"}
CitCheck -->|Yes| Loop
CitCheck -->|No| TryBlock["abstract = fetch_abstract(paper.doi)"]
TryBlock --> Embed["embeddings = compute_embeddings(abstract)"]
Embed --> Append["results.append(...)"]
Append --> Loop
TryBlock -.->|APIError| LogErr["log_error(paper.doi)"]
LogErr --> Loop
Input code:
async function searchPapers(query: string, maxResults: number = 50): Promise<Paper[]> {
const cached = await cache.get(query);
if (cached) return cached;
const results: Paper[] = [];
let offset = 0;
while (results.length < maxResults) {
const batch = await api.search(query, offset, 10);
if (batch.length === 0) break;
for (const paper of batch) {
if (paper.isRetracted) continue;
results.push(paper);
}
offset += 10;
}
await cache.set(query, results);
return results;
}
Output flowchart:
flowchart TD
Start(["searchPapers(query, maxResults=50)"]) --> Cache["cached = await cache.get(query)"]
Cache --> CacheHit{"cached exists?"}
CacheHit -->|Yes| ReturnCached(["Return cached"])
CacheHit -->|No| InitResults["results = [ ], offset = 0"]
InitResults --> WhileLoop{"results.length < maxResults?"}
WhileLoop -->|No| SaveCache["await cache.set(query, results)"]
WhileLoop -->|Yes| Fetch["batch = await api.search(query, offset, 10)"]
Fetch --> EmptyCheck{"batch.length === 0?"}
EmptyCheck -->|Yes| SaveCache
EmptyCheck -->|No| ForLoop{"For each paper in batch?"}
ForLoop -->|Done| IncOffset["offset += 10"]
IncOffset --> WhileLoop
ForLoop -->|Next| Retracted{"paper.isRetracted?"}
Retracted -->|Yes| ForLoop
Retracted -->|No| Push["results.push(paper)"]
Push --> ForLoop
SaveCache --> Return(["Return results"])
Deeply nested if/else chains are flattened into a decision tree. Each branch is labeled with its condition, and nodes at the same depth are arranged vertically for readability.
Recursive calls are shown as subroutine nodes with a self-referencing edge back to the function start node. A note annotation indicates the recursion base case.
Python generators use yield as intermediate output nodes (shown as parallelogram shapes). The flowchart shows the suspension point and resumption path.
Multiple except clauses create parallel error paths from the try block, each labeled with the exception type. finally blocks are shown as a converging node that all paths pass through.
%%{init: {
'theme': 'base',
'themeVariables': {
'primaryColor': '#f8f9fa',
'primaryBorderColor': '#212529',
'primaryTextColor': '#212529',
'lineColor': '#495057',
'fontFamily': 'Times New Roman, serif',
'fontSize': '14px'
}
}}%%
flowchart TD
A["Step 1"] --> B{"Decision"} --> C["Step 2"]
# Render Mermaid to PDF for LaTeX inclusion
mmdc -i flowchart.mmd -o flowchart.pdf -t neutral -b transparent
\begin{figure}[h]
\centering
\includegraphics[width=0.8\textwidth]{flowchart.pdf}
\caption{Control flow of the data processing pipeline.}
\label{fig:flowchart}
\end{figure}
Promise.all) are noted but not fully modeled.development
Conduct rigorous thematic analysis (TA) of qualitative data following Braun and Clarke's (2006) six-phase framework. Use whenever the user mentions 'thematic analysis', 'TA', 'Braun and Clarke', 'qualitative coding', 'identifying themes', or asks for help analysing interviews, focus groups, open-ended survey responses, or transcripts to identify patterns. Also trigger for questions about inductive vs theoretical coding, semantic vs latent themes, essentialist vs constructionist epistemology, building a thematic map, or writing up a qualitative findings section. Covers all six phases, the four upfront analytic decisions, the 15-point quality checklist, and the five common pitfalls. Produces a Word document write-up and an annotated thematic map. Does NOT cover IPA, grounded theory, discourse analysis, conversation analysis, or narrative analysis — use a different method for those.
development
Guide users through writing a systematic literature review (SLR) following the PRISMA 2020 framework. Use this skill whenever the user mentions 'systematic review', 'systematic literature review', 'SLR', 'PRISMA', 'PRISMA 2020', 'PRISMA flow diagram', 'PRISMA checklist', or asks for help writing, structuring, or auditing a literature review that follows reporting guidelines. Also trigger when the user asks about inclusion/exclusion criteria for a review, search strategies for databases like Scopus/WoS/PubMed, study selection processes, risk of bias assessment, or narrative synthesis for a review paper. This skill covers the full PRISMA 2020 checklist (27 items), produces a Word document manuscript in strict journal article format, generates an annotated PRISMA flow diagram, and enforces APA 7th Edition referencing throughout. It does NOT cover meta-analysis or statistical pooling. By Chuah Kee Man.
testing
Performs placebo-in-time sensitivity analysis with hierarchical null model and optional Bayesian assurance. Use when checking model robustness, verifying lack of pre-intervention effects, or estimating study power.
data-ai
Fit, summarize, plot, and interpret a chosen CausalPy experiment. Use after the causal method has been selected, including when configuring PyMC/sklearn models and scale-aware custom priors.