agentleFS
jamestexasjamestexas/agents/skills/diagram-gen-spec/SKILL.md

diagram-gen-spec

Skill2 starsChanged 6 months agoApache-2.0View on GitHub

Generate a top-down diagram of intended architecture from a mache schema file — what the PR proposes, not what the code does. Local reviewer context only; pair with diagram-gen-emergent for spec-vs-reality drift.

  • Sends data out

The file

We split this skill into the rules it gives an agent

5 rules. About 0 are common, 2 are distinctive, and 3 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 3

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    If first argument is a file path: use it directly.

    line 33
  2. Distinctive:

    If no schema found anywhere, return:

    line 41
  3. Very specific:

    If a second argument was provided, use it as SOURCE.

    line 51
  4. Very specific:

    If $DIAGRAM contains "No cross-references" or is empty, set DIAGRAM_STATUS to "partial".

    line 123
  5. Very specific:

    If DIAGRAM_STATUS is "partial":

    line 145

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

diagram-gen-spec — Spec-Driven Structural Diagram

Generate a top-down diagram from a mache schema. Shows what the author intended to build. This is reviewer-local context only — never post this output to GitHub.

Arguments

$ARGUMENTS — <schema-path-or-pr-number> [source-path]

  • First argument: path to a mache schema JSON file, OR a PR number (to find the schema in the PR's changed files)
  • Second argument (optional): source directory to serve against the schema

What To Do

Step 1: Find the schema

If first argument looks like a PR number (all digits or owner/repo#N):

# Look for schema files changed in the PR
gh pr diff $ARG --name-only 2>/dev/null | grep -E "(schema\.json|mache\.json|\.schema\.json)"

If first argument is a file path: use it directly.

If no schema found from PR, look in the repo root:

ls examples/*.json 2>/dev/null | head -5
ls *.json 2>/dev/null | grep -i schema | head -3

If no schema found anywhere, return:

status: unavailable
type: spec-driven
reason: no mache schema found in PR changed files or repo root

Stop here.

Step 2: Determine source path

If a second argument was provided, use it as SOURCE. Otherwise, if argument was a PR number, derive source from the repo:

gh pr view $ARG --json headRepository --jq '.headRepository.nameWithOwner' 2>/dev/null

Fall back to current working directory if detection fails.

Step 3: Start mache with the schema on port 7534

MACHE_BIN=$(which mache 2>/dev/null || echo "$HOME/go/bin/mache")
if [ ! -x "$MACHE_BIN" ]; then
  echo "status: unavailable — mache binary not found"
  exit 0
fi

# Use port 7534 to avoid colliding with the emergent server on 7532
$MACHE_BIN serve "$SOURCE" --schema "$SCHEMA_PATH" --http localhost:7534 &
SPEC_PID=$!

for i in $(seq 1 10); do
  sleep 1
  curl -s --max-time 2 -X POST http://localhost:7534/mcp \
    -H "Content-Type: application/json" \
    -H "Accept: application/json, text/event-stream" \
    -d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"check","version":"1"}}}' \
    | python3 -c "import sys,json; d=json.load(sys.stdin); exit(0) if 'result' in d else exit(1)" 2>/dev/null && break
  if [ $i -eq 10 ]; then
    kill $SPEC_PID 2>/dev/null
    echo "status: unavailable — mache serve with schema failed to start"
    exit 0
  fi
done

Initialize session:

SESSION=$(curl -s -X POST http://localhost:7534/mcp \
  -H "Content-Type: application/json" \
  -H "Accept: application/json, text/event-stream" \
  -d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"diagram-gen-spec","version":"1"}}}' \
  -D - 2>/dev/null | grep -i "^mcp-session-id:" | tr -d '\r' | awk -F': ' '{print $2}' | tr -d ' ')
if [ -z "$SESSION" ]; then
  echo "status: unavailable — session initialization failed"
  exit 0
fi

Step 4: Get architecture narrative

NARRATIVE=$(curl -s -X POST http://localhost:7534/mcp \
  -H "Content-Type: application/json" \
  -H "Accept: application/json, text/event-stream" \
  -H "mcp-session-id: $SESSION" \
  -d '{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"get_architecture","arguments":{}}}' \
  | python3 -c "import sys,json; d=json.load(sys.stdin); print(d['result']['content'][0]['text'])" 2>/dev/null)

Truncate to 200 words if longer.

Step 5: Get diagram

DIAGRAM=$(curl -s -X POST http://localhost:7534/mcp \
  -H "Content-Type: application/json" \
  -H "Accept: application/json, text/event-stream" \
  -H "mcp-session-id: $SESSION" \
  -d '{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"get_diagram","arguments":{"compact":true,"layout":"LR","exclude_tests":true}}}' \
  | python3 -c "import sys,json; d=json.load(sys.stdin); print(d['result']['content'][0]['text'])" 2>/dev/null)

If $DIAGRAM contains "No cross-references" or is empty, set DIAGRAM_STATUS to "partial". Otherwise set DIAGRAM_STATUS to "available".

Step 6: Format and return

Output this structure exactly (downstream skills parse it):

status: available
type: spec-driven
label: Proposed structure (spec-driven)
schema: <SCHEMA_PATH>

narrative:
<NARRATIVE truncated to 200 words>

diagram:
```mermaid
<DIAGRAM truncated to 50 lines>

If DIAGRAM_STATUS is "partial":

status: partial type: spec-driven label: Proposed structure (spec-driven) schema: <SCHEMA_PATH> diagram: unavailable — schema defines structure but insufficient cross-references to cluster

narrative: <NARRATIVE>

Step 7: Stop the spec server

kill $SPEC_PID 2>/dev/null

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.