---
name: graphify
description: >
  Map the current project codebase into a queryable mnemo knowledge graph using graphify.
  Treats graphify-out/ as the canonical runtime output and writes only lightweight
  mnemo integration pages, so agents can answer questions about the project without
  re-reading source files on every session.
  Use when the user says "map my codebase", "build a knowledge graph", "index my project",
  "graphify this", or invokes /mnemo:graphify explicitly.
license: MIT
compatibility: >
  Agents that support skill-style slash commands (for example /mnemo:graphify).
  Other agentskills.io-compatible
  agents invoke by natural language. Requires: graphify (pip install graphifyy && graphify install).
metadata:
  author: mnemo contributors
  version: "0.16.1"
allowed-tools: Read Write Edit Glob Bash
---

Map the current project codebase into a queryable mnemo knowledge graph.

> **Scope:** This skill operates on the local `.mnemo/<project-name>/` knowledge base only. The `--global` flag is not supported.

## Prerequisites

**1. mnemo initialized** — check if `.mnemo/<project-name>/wiki/sources/` exists. If not:
> "Knowledge base not initialized. Run `/mnemo:init` first."
Stop.

**2. graphify installed** — run `graphify --version`. If the command fails or is not found:
> "graphify is not installed. Install it with:
> `pip install graphifyy && graphify install`"
Stop.

## Step 1 — Prepare `.graphifyignore`

Check if `.graphifyignore` exists at project root.

**Default exclusion list:**
```
.mnemo/
graphify-out/
node_modules/
.git/
__pycache__/
*.pyc
.venv/
dist/
build/
coverage/
.next/
.nuxt/
```

**If `.graphifyignore` does not exist:** create it with the full default list above.
Report: "Created `.graphifyignore` with default exclusions."

**If `.graphifyignore` exists:** read it. For each entry in the default list that is absent, append it.
Report only what was added: "Updated `.graphifyignore` — added: `.mnemo/`, `graphify-out/`."
If nothing was missing: no report.

Note: if `graphify-out/cache/` already exists, this is an incremental re-run. Graphify will use its SHA256 cache automatically — only changed files are reprocessed.

## Step 2 — Run graphify

Run from the project root:
```bash
graphify .
```

Wait for completion. If graphify exits non-zero, report the error and stop:
> "graphify failed: <error output>. Fix the error above and re-run `/mnemo:graphify`."

On success, graphify produces:
- `graphify-out/graph.json` — structured graph (nodes + edges)
- `graphify-out/GRAPH_REPORT.md` — narrative report (god nodes, surprising connections, suggested questions)
- `graphify-out/cache/` — SHA256 cache for incremental re-runs

## Step 3 — Validate native graphify outputs

`graphify-out/` is the canonical runtime directory. Do not move it, rename it, or copy its cache into `.mnemo/`.

Validate the outputs produced by graphify:
- `graphify-out/GRAPH_REPORT.md`
- `graphify-out/graph.json`
- optionally `graphify-out/cache/`

If `graphify-out/GRAPH_REPORT.md` does not exist: report "graphify produced no GRAPH_REPORT.md. Nothing was written to the wiki." and stop.

If `graphify-out/graph.json` does not exist: report "graphify produced no graph.json. Nothing was written to the wiki." and stop.

Read `graphify-out/graph.json`. If `nodes` is empty or absent: report "graphify produced no nodes. The project may have no recognized code structure. Nothing was written to the wiki." and stop.

## Step 4 — Write lightweight mnemo integration pages

Read `graphify-out/GRAPH_REPORT.md`. Write `.mnemo/<project-name>/wiki/synthesis/codebase-graph-report.md`:

```markdown
---
title: Codebase Graph Report
category: synthesis
tags: [graphify, codebase, graph-report]
source: graphify-out/GRAPH_REPORT.md
created: <YYYY-MM-DD>
updated: <YYYY-MM-DD>
---

# Codebase Graph Report

> *Generated by graphify on <YYYY-MM-DD>. Canonical runtime artifacts live in `graphify-out/`. Re-run `/mnemo:graphify` to refresh.*

## Canonical Runtime

- Human-readable report: `graphify-out/GRAPH_REPORT.md`
- Structured graph: `graphify-out/graph.json`
- Incremental cache: `graphify-out/cache/`

## Usage

- Read `graphify-out/GRAPH_REPORT.md` first when you need a fast understanding of project structure.
- Use `graphify query ... --graph graphify-out/graph.json` for focused follow-up questions instead of scanning the entire codebase.
- Treat `graphify-out/` as the source of truth for graphify outputs.

## Report

<full body of graphify-out/GRAPH_REPORT.md, preserved verbatim>
```

On re-run: overwrite this page entirely. Update `created:` only if the file is new; always update `updated:`.

Write `.mnemo/<project-name>/wiki/synthesis/codebase-graph-status.md`:

```markdown
---
title: Codebase Graph Status
category: synthesis
tags: [graphify, codebase, status]
created: <YYYY-MM-DD>
updated: <YYYY-MM-DD>
---

# Codebase Graph Status

- Canonical runtime directory: `graphify-out/`
- Report present: <yes|no>
- Graph present: <yes|no>
- Cache present: <yes|no>
- Last graphify run: <YYYY-MM-DD or UTC ISO timestamp if available>

## Guidance

- Start with `graphify-out/GRAPH_REPORT.md`.
- Use `graphify-out/graph.json` for structured queries.
- Leave `graphify-out/cache/` in place so graphify can re-use its SHA256 cache on the next run.
```

## Step 5 — Integrate

Do not copy `graphify-out/graph.json` into `.mnemo/<project-name>/`.
Do not convert graph nodes into mnemo entity/concept pages.
Do not copy `graphify-out/cache/` into `.mnemo/<project-name>/`.

Update `.mnemo/<project-name>/index.md` under `## Synthesis` with links to:
```
- [Codebase Graph Report](wiki/synthesis/codebase-graph-report.md)
- [Codebase Graph Status](wiki/synthesis/codebase-graph-status.md)
```
Add the heading if missing. Avoid duplicate entries on re-run.

Update `.mnemo/<project-name>/log.md` after the index links are present.

Fast path: use `Glob('**/mnemo/scripts/update_log.py')` or `Glob('**/scripts/update_log.py')` to locate the script. If found at `<script_path>`, run:
```
python3 <script_path> --vault .mnemo/<project-name> --file graphify-out/graph.json --op graphify
```

LLM fallback — append to `.mnemo/<project-name>/log.md`:
```
- graphify-out/graph.json | <UTC ISO timestamp> | graphify
```

Then refresh `.mnemo/<project-name>/SESSION_BRIEF.md`.

Fast path: use `Glob('**/mnemo/scripts/update_session_brief.py')` or `Glob('**/scripts/update_session_brief.py')` to locate the script. If found at `<script_path>`, run:
```
python3 <script_path> --vault .mnemo/<project-name>
```
If the script is unavailable, update the brief manually and include `graphify-out/GRAPH_REPORT.md` as a startup read only for codebase-structure tasks.

**Report:**
```
graphify run complete.
  Canonical runtime:    graphify-out/
  Report page:          wiki/synthesis/codebase-graph-report.md
  Status page:          wiki/synthesis/codebase-graph-status.md
  Structured graph:     graphify-out/graph.json
  Cache retained:       graphify-out/cache/

Read graphify-out/GRAPH_REPORT.md before scanning raw files.
Use graphify query with graphify-out/graph.json for focused graph questions.
Run /mnemo:lint to verify knowledge base health.
```
