Agent skill

Specification Subgraph Extractor

by NyxFoundation in NyxFoundation/speca

Turns one specification document into program graphs following Nielson and Nielson's definition, writing each graph as a Mermaid file, one per functional unit.

MITAuto-check passedDevelopment

Install Specification Subgraph Extractor

skills CLI
$ npx skills add NyxFoundation/speca --skill subgraph-extractor -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install NyxFoundation/speca subgraph-extractor --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/NyxFoundation/speca.git skills-src && mkdir -p .claude/skills && cp -r skills-src/.claude/skills/subgraph-extractor .claude/skills/subgraph-extractor && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
subgraph-extractor
GitHub stars
459
Token cost
~1.6k tokens
SKILL.md length
560 words
Files
1
Skills in repo
2
Repo updated
First seen
Licence
MIT

At a glance

Turns one specification document into program graphs following Nielson and Nielson's definition, writing each graph as a Mermaid file, one per functional unit.

  • Works in 5 steps: Read Specification: If local_path is… → Identify Functional Units: Break down… → Extract Program Graph Components → …
  • Converting a protocol or specification document into formal program graphs
  • SKILL.md covers Mindset, Scope, Input and Procedure, plus 6 more sections
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md

What it does

The agent acts as a formal-methods specialist. Given a specification URL, an output directory and optionally a local copy, it reads the document (fetching it when no local file exists), splits it into functional units such as function definitions, state transitions, protocol phases and validation logic, and builds one program graph per unit. A program graph is defined by nodes, an initial and a final node, actions such as assignments and tests, and edges that link nodes through actions.

Each graph is written as a .mmd Mermaid file under the output directory, in a folder named after a short specification identifier such as fulu-beacon-chain, and the skill returns a JSON structure describing the results. It handles a single specification per call and does not write the index file, because the calling worker batches and aggregates. Mermaid syntax rules are included to avoid parse errors.

When your agent uses it

  • Converting a protocol or specification document into formal program graphs
  • Producing Mermaid diagrams of function and state-transition logic from a spec
  • Feeding graph inputs to a specification-based audit pipeline

Example prompts

  • “Extract program graphs from the beacon chain specification at this URL and write the .mmd files to ./graphs.”
  • “Break the EIP-7594 specification into functional units and draw one program graph for each.”
  • “Which validation flows in this spec can be drawn as program graphs? Extract them into Mermaid files.”

Requirements

  • Fetch access to the specification URL, or a local copy of it
  • A writable output directory
  • Pre-approved tools (allowed-tools): read, write, mcp__fetch__fetch, mcp__filesystem__write_text_file, mcp__tree_sitter__get_symbols, mcp__tree_sitter__run_query

Workflow steps

5 steps, taken from the first numbered list in SKILL.md.

  1. Read Specification: If local_path is provided and the file exists, read from it. Otherwise, fetch the content from url using mcpfetchfetch.
  2. Identify Functional Units: Break down the document into logical units
  3. Extract Program Graph Components
  4. Generate Mermaid Diagrams: For each program graph, write a .mmd file to
  5. Return Result: Return the JSON structure described in Output Format below. Do not write index.json — the calling worker handles aggregation.

What it can do on your machine

Read from SKILL.md and the folder at commit d173893. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves these tools, so the agent can use them without asking each time:

    • read
    • write
    • mcp__fetch__fetch
    • mcp__filesystem__write_text_file
    • mcp__tree_sitter__get_symbols
    • mcp__tree_sitter__run_query

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md (its code samples are mermaid and json).

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Specification Subgraph Extractor loads about 1.6k tokens when it runs. Until then it costs about 32 tokens; SKILL.md has 560 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~32
When it runs · the whole SKILL.md, loaded when a task matches
~1.6k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from NyxFoundation/speca at commit d173893, republished under its MIT licence (© NyxFoundation). 560 words, ~1,629 tokens.

Download SKILL.mdSave it as .claude/skills/subgraph-extractor/SKILL.md (or your agent's skills folder).
name
subgraph-extractor
description
Extract program graphs from a single specification document following Nielson & Nielson's formal definition.
allowed-tools
read, write, mcp__fetch__fetch, mcp__filesystem__write_text_file, mcp__tree_sitter__get_symbols, mcp__tree_sitter__run_query
context
fork

SKILL: Subgraph Extractor

Mindset

You are a Formal Methods Specialist trained in program graph extraction. Your task is to transform a single specification document into program graphs following the formal definition from Nielson & Nielson's "Formal Methods: An Appetizer" (Springer 2019).

A program graph PG = (Q, q▷, q◀, Act, E) consists of:

  • Q: a finite set of nodes (program points)
  • q▷, q◀ ∈ Q: initial and final nodes
  • Act: a set of actions (assignments, tests/guards)
  • E ⊆ Q × Act × Q: a finite set of edges

Scope

This skill processes one specification URL per invocation. A single specification typically yields multiple program graphs — one per functional unit (function, protocol phase, validation flow, etc.).

The calling worker is responsible for batching and aggregation.

Input

The caller provides:

  • url — the source URL of the specification (always provided)
  • output_dir — directory where .mmd files should be written
  • local_path (optional) — path to a pre-downloaded copy of the specification

Procedure

  1. Read Specification: If local_path is provided and the file exists, read from it. Otherwise, fetch the content from url using mcp__fetch__fetch.

  2. Identify Functional Units: Break down the document into logical units:

    • Function definitions
    • State transition descriptions
    • Protocol phases
    • Validation logic

    Each functional unit becomes one program graph.

  3. Extract Program Graph Components:

    For each functional unit, identify:

    ComponentWhat to Extract
    Nodes (Q)Program points: entry, exit, decision points, intermediate states
    Initial (q▷)The starting point of the function/process
    Final (q◀)The termination point(s)
    Actions (Act)Assignments (x = expr), function calls, tests/guards (x > 0)
    Edges (E)Transitions: (source_node, action, target_node)
  4. Generate Mermaid Diagrams: For each program graph, write a .mmd file to:

    {output_dir}/{spec_id}/{SG-ID}_{name}.mmd

    Where spec_id is a short identifier derived from the specification (e.g., EIP-7594, fulu-beacon-chain).

  5. Return Result: Return the JSON structure described in Output Format below. Do not write index.json — the calling worker handles aggregation.

Mermaid Syntax Rules

CRITICAL: Follow these rules to avoid parse errors:

  1. No := in labels: Use = instead of := for assignments
  2. No spaces after colon: Write q1 --> q2: action (space before colon is OK)
  3. Escape special characters: Avoid <, >, {, } in labels, or use quotes
  4. Use simple node names: q1, q_validate, etc. (alphanumeric + underscore only)
Show full SKILL.md (206 more words)Show less
Correct Mermaid Syntax
mermaid
---
title: "factorial (Example Spec)"
---
stateDiagram-v2
    direction TB
    [*] --> q1: y = 1
    q1 --> q2: x > 0
    q1 --> [*]: x <= 0
    q2 --> q3: y = x * y
    q3 --> q1: x = x - 1

    note right of q3
        INV-001: y equals x! at loop termination
    end note
Incorrect (Will Fail)
[*] --> q1 : y := 1     # WRONG: space before colon, := syntax
q1 --> q2 : x > 0       # WRONG: space before colon

Output Format

The skill returns one JSON object per invocation (one spec → one object).

Important: mermaid_file paths are relative to output_dir, including the spec_id directory prefix.

json
{
  "source_url": "https://...",
  "title": "EIP-7892: Blob Schedule",
  "sub_graphs": [
    {
      "id": "SG-001",
      "name": "get_blob_parameters",
      "mermaid_file": "EIP-7892/SG-001_get_blob_parameters.mmd"
    }
  ]
}

Note: The structured program graph (Q, q_init, q_final, Act, E) and invariants are encoded in the .mmd file itself. The JSON output contains only references. Include all invariants as note right of blocks in the .mmd file.

Mermaid File (.mmd)
mermaid
---
title: "get_blob_parameters (EIP-7892: Blob Schedule)"
---
stateDiagram-v2
    direction TB
    [*] --> q_iter: for entry in BLOB_SCHEDULE
    q_iter --> q_return: epoch >= entry.epoch
    q_iter --> q_iter: epoch < entry.epoch
    q_return --> [*]: return entry.params

    note right of q_iter
        INV-001: BLOB_SCHEDULE entries have unique epochs
    end note

Action Classification

TypePatternMermaid Label
Assignmentvar := exprvar = expr
Function Callfunc(args)func(args)
Test/Guardbooleanx > 0
Returnreturn exprreturn expr
Revertrevert msgrevert msg
Loop Entryfor/whilefor item in list

Node Naming Convention

TypePatternExample
Initialq_initEntry point
Finalq_finalExit point
Validationq_validateInput validation
Iterationq_iterLoop body
Decisionq_checkBranch point
Processingq_processMain logic
Errorq_errorError handling

Quality Criteria

  1. Completeness: Every function/process should have a corresponding program graph
  2. Correctness: Edges must form valid paths from q_init to q_final
  3. Minimality: Avoid redundant nodes; merge sequential assignments if appropriate
  4. Readability: Use semantic node names, not just q1, q2, etc.
  5. Valid Mermaid: All .mmd files must render without errors

Example: Factorial Function

Input (pseudocode):

function factorial(x):
    y := 1
    while x > 0:
        y := x * y
        x := x - 1
    return y

Output (Mermaid) - examples/SG-factorial_factorial.mmd:

mermaid
---
title: "factorial (Factorial Example)"
---
stateDiagram-v2
    direction TB
    [*] --> q1: y = 1
    q1 --> q2: x > 0
    q1 --> [*]: x <= 0
    q2 --> q3: y = x * y
    q3 --> q1: x = x - 1

    note right of q3
        INV-001: y equals x! at loop termination
        INV-002: x >= 0 at every iteration
    end note

Output (JSON):

json
{
  "id": "SG-factorial",
  "name": "factorial",
  "mermaid_file": "examples/SG-factorial_factorial.mmd"
}

© NyxFoundation, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in .claude/skills/subgraph-extractor of NyxFoundation/speca.

Open the folder on GitHubat commit d173893

Compare with similar skills

Specification Subgraph Extractor next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Specification Subgraph Extractor compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Specification Subgraph Extractor this skillNyxFoundation/speca459—~1.6kAutomated safety check: PassMIT
Diagram Designcathrynlavery/diagram-design45k1 repos~7.5kAutomated safety check: PassMIT
Draw.io Diagram StudioAgents365-ai/drawio-skill10k—~2.4kAutomated safety check: NotesMIT
Pretty Mermaid Rendererimxv/Pretty-mermaid-skills1.5k—~2kAutomated safety check: PassMIT
Mermaid Diagramsjjmartres/opencode1336 repos~1.9kAutomated safety check: PassMIT
Eli5coldteadotai/pr-lens1.9k—~2.3kAutomated safety check: PassMIT

Similar skills

  • Diagram Design

    cathrynlavery/diagram-design

    Creates branded diagrams, from architecture, flowchart and sequence to charts and maps, as self-contained HTML with inline SVG, with import from draw.io, Mermaid and Excalidraw.

    45k GitHub starsUsed in 1 repo~7.5k tokens
    DevelopmentAuto-check passed
  • Draw.io Diagram Studio

    Agents365-ai/drawio-skill

    Creates and edits editable draw.io diagrams from descriptions, code, infrastructure files, SQL and API schemas, with sync, review, test and export tools.

    10k GitHub stars~2.4k tokensUpdated 6 days ago
    DevelopmentAuto-check: notes
  • Pretty Mermaid Renderer

    imxv/Pretty-mermaid-skills

    Writes and renders Mermaid diagrams as themed SVG, PNG or terminal ASCII and Unicode art with a bundled Node.js CLI that needs no browser.

    1.5k GitHub stars~2k tokensUpdated 1 mo ago
    DevelopmentAuto-check passed
  • Mermaid Diagrams

    jjmartres/opencode

    Helps an agent pick the right Mermaid diagram type and write the syntax for class, sequence, flow, ER, C4, state and other software diagrams.

    133 GitHub starsUsed in 6 repos~1.9k tokens
    DevelopmentAuto-check passed
  • Eli5

    coldteadotai/pr-lens

    WHAT: Explains a codebase, a folder, a feature, a command or a pull request to someone who knows nothing about it, as a PR Lens canvas whose walkthrough builds the picture one part at a time.

    1.9k GitHub stars~2.3k tokensUpdated 4 days ago
    DevelopmentAuto-check passed
  • C4 Architecture Diagrams

    lexler/skill-factory

    Creates C4 model diagrams at every zoom level, from system landscape to code, in ASCII, Mermaid or Structurizr, for designing or documenting software architecture.

    239 GitHub stars~2.3k tokensUpdated 1 mo ago
    DevelopmentAuto-check passed

More from NyxFoundation/speca

  • Crawls from a starting URL to find and list technical specification, whitepaper and architecture documents, writing the found URLs to a JSON file.

    459 GitHub stars~669 tokensUpdated 1 mo ago
    Auto-check passed

Works with

Categories

Questions about Specification Subgraph Extractor

What does Specification Subgraph Extractor do?

Turns one specification document into program graphs following Nielson and Nielson's definition, writing each graph as a Mermaid file, one per functional unit. The agent acts as a formal-methods specialist. Given a specification URL, an output directory and optionally a local copy, it reads the document (fetching it when no local file exists), splits it into functional units such as function definitions, state transitions, protocol phases and validation logic, and builds one program graph per unit.

When should I use Specification Subgraph Extractor?

Specification Subgraph Extractor fits situations like: converting a protocol or specification document into formal program graphs; producing Mermaid diagrams of function and state-transition logic from a spec; feeding graph inputs to a specification-based audit pipeline.

How do I install Specification Subgraph Extractor in Claude Code?

Run `npx skills add NyxFoundation/speca --skill subgraph-extractor -a claude-code`. Or copy the skill folder (.claude/skills/subgraph-extractor in NyxFoundation/speca) into .claude/skills/subgraph-extractor in your project. Claude Code loads it when a task matches its description.

How do I install Specification Subgraph Extractor in Codex?

Run `npx skills add NyxFoundation/speca --skill subgraph-extractor -a codex`. Or copy the skill folder (.claude/skills/subgraph-extractor in NyxFoundation/speca) into .agents/skills/subgraph-extractor in your project. Codex loads it when a task matches its description.

Can I use Specification Subgraph Extractor in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add NyxFoundation/speca --skill subgraph-extractor -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/subgraph-extractor, .gemini/skills/subgraph-extractor, .github/skills/subgraph-extractor and .opencode/skills/subgraph-extractor in your project.

What does Specification Subgraph Extractor need to run?

SKILL.md names no scripts, command-line tools or credentials: Specification Subgraph Extractor is instructions for the agent only. Our summary lists: Fetch access to the specification URL, or a local copy of it; A writable output directory. Its frontmatter pre-approves these tools: read, write, mcp__fetch__fetch, mcp__filesystem__write_text_file, mcp__tree_sitter__get_symbols, mcp__tree_sitter__run_query.

Does Specification Subgraph Extractor access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is Specification Subgraph Extractor safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Specification Subgraph Extractor use?

Specification Subgraph Extractor is published under the MIT licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Specification Subgraph Extractor use?

About 1.6k tokens (SKILL.md is roughly 6.5k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Specification Subgraph Extractor?

Skills that share tags, products or a category with Specification Subgraph Extractor: Diagram Design (cathrynlavery/diagram-design, 45k stars), Draw.io Diagram Studio (Agents365-ai/drawio-skill, 10k stars), Pretty Mermaid Renderer (imxv/Pretty-mermaid-skills, 1.5k stars) and Mermaid Diagrams (jjmartres/opencode, 133 stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Specification Subgraph Extractor?

NyxFoundation (a GitHub organization) maintains it in NyxFoundation/speca, which has 459 GitHub stars. The repository holds 2 skills in this directory. The repository was last updated on August 12, 2026.

Source: NyxFoundation/speca on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.