Skip to main content
ClaudeWave
Slash Command105 estrellas del repoactualizado 3mo ago

nemp-pro-export

Export Nemp memories to Codex CLI, Cursor, and Windsurf rule files

Instalar en Claude Code
Copiar
mkdir -p ~/.claude/commands && curl -fsSL https://raw.githubusercontent.com/SukinShetty/Nemp-memory/HEAD/commands/nemp-pro-export.md -o ~/.claude/commands/nemp-pro-export.md
Después abre una sesión nueva de Claude Code; el slash command carga automáticamente.

nemp-pro-export.md

# /nemp-pro:export

Export project memories to AI tool rule files used by Codex CLI (AGENTS.md), Cursor (.cursor/rules/nemp-memory.mdc), and Windsurf (.windsurfrules). Keeps your entire AI toolchain in sync from a single source of truth: `.nemp/memories.json`.

## Usage
```
/nemp-pro:export --codex      # Generate AGENTS.md for Codex CLI
/nemp-pro:export --cursor     # Generate .cursor/rules/nemp-memory.mdc for Cursor
/nemp-pro:export --windsurf   # Generate .windsurfrules for Windsurf
/nemp-pro:export --all        # Generate all three + sync CLAUDE.md
/nemp-pro:export --status     # Check which export files exist
```

## Arguments
- `--codex` (optional): Export to `AGENTS.md` in project root (Codex CLI format)
- `--cursor` (optional): Export to `.cursor/rules/nemp-memory.mdc` (MDC frontmatter format)
- `--windsurf` (optional): Export to `.windsurfrules` in project root (plain markdown)
- `--all` (optional): Run all three exports and trigger CLAUDE.md sync
- `--status` (optional): Report which export files exist and their last modified timestamps

## Instructions

When the user invokes `/nemp-pro:export`, follow these steps:

### Step 1: Parse Arguments

Extract the subcommand from the user's input:

```
--codex      → Export to AGENTS.md
--cursor     → Export to .cursor/rules/nemp-memory.mdc
--windsurf   → Export to .windsurfrules
--all        → Run all three exports + CLAUDE.md sync
--status     → Show export file status
(no args)    → Show Usage block above and stop
```

If no argument is provided or the argument is unrecognised, display the Usage block above and stop.

---

## Memory Reading Logic (used by all export subcommands)

Before generating any export file, perform these steps to load and prepare memories. This logic is shared by `--codex`, `--cursor`, `--windsurf`, and `--all`.

### Step 2: Read memories.json

Read `.nemp/memories.json` using the Read tool:

```bash
[ -f ".nemp/memories.json" ] && cat .nemp/memories.json
```

If the file does not exist, stop and show:

```
❌ No Nemp memories found. Run /nemp:init first.

   To initialize: /nemp:init
   To save a memory: /nemp:save <key> <value>
```

### Step 3: Parse the Memories Array

The file uses the new array format:

```json
{
  "memories": [
    {
      "key": "version",
      "value": "0.3.0",
      "created": "2026-02-26T16:00:00.000Z",
      "updated": "2026-02-26T16:00:00.000Z",
      "projectPath": "C:/Users/...",
      "agent_id": "nemp-init",
      "tags": ["auto-detected"]
    }
  ]
}
```

**Backward compatibility:** Some older files store memories as a flat object (keys at the top level):

```json
{
  "stack": { "value": "Next.js", "created": "...", "updated": "..." },
  "auth":  { "value": "NextAuth", "created": "...", "updated": "..." }
}
```

If the parsed JSON does not have a `memories` array, treat each top-level key as a memory entry, converting it to the array format internally:

```
key = the JSON key name
value = entry.value
created = entry.created
updated = entry.updated
type = entry.type (if present, else undefined)
vitality = entry.vitality (if present, else undefined)
confidence = entry.confidence (if present, else undefined)
```

### Step 4: Filter Out Extinct Memories

Skip any memory where `vitality.state === "extinct"`. These memories are considered dead and must not appear in export files.

For Cortex-enhanced memories, `vitality` is an object. For plain memories, `vitality` is absent — treat absent vitality as active (do not skip).

### Step 5: Group by Type

Group the remaining memories by their `type` field. Valid type values are: `"fact"`, `"rule"`, `"procedure"`, `"preference"`, `"warning"`, `"decision"`. Memories without a `type` field go under `"Other"`.

**Group order for output (always in this sequence, skip empty groups):**

1. Facts
2. Rules
3. Procedures
4. Preferences
5. Warnings
6. Decisions
7. Other

Do not emit a section header for a group that has zero memories.

### Step 6: Sort Within Groups

Within each group, sort memories alphabetically by `key` (case-insensitive, A → Z).

### Step 7: Token Budget Check

After grouping, estimate the output size. Target under 4000 tokens total (approximately 16 000 characters). If the estimated output would exceed this, warn the user at the end of the confirmation message but proceed with full export. Do not truncate content silently.

---

## /nemp-pro:export --codex

Generate `AGENTS.md` in the project root for Codex CLI.

### Step 8a: Build AGENTS.md Content

Using the prepared groups from Steps 2-7, generate the following markdown:

```
# Project Memory (powered by Nemp)
> Auto-generated. Do not edit manually. Source: .nemp/memories.json
> Last exported: <ISO timestamp> | Memories: <count> | Nemp Pro

## Facts
- <key>: <value>
- <key>: <value>

## Rules
- <key>: <value>

## Procedures
- <key>: <value>

## Preferences
- <key>: <value>

## Warnings
- <key>: <value>

## Decisions
- <key>: <value>

## Other
- <key>: <value>

---
To update: save memories with /nemp:save in Claude Code, then /nemp-pro:export --codex
To write back: add entries to .nemp/memories.json following existing format
```

- Replace `<ISO timestamp>` with the current UTC time in ISO-8601 format.
- Replace `<count>` with the number of memories being exported (after filtering extinct).
- Only include section headers for groups that have at least one memory.
- Each bullet line is `- <key>: <value>`.

### Step 9a: Write AGENTS.md

Write the generated content to `AGENTS.md` in the project root using the Write tool.

### Step 10a: Confirm to User

Display:

```
✅ Exported 12 memories to AGENTS.md (Codex CLI)
   Path: ./AGENTS.md
   Size: ~847 bytes (~212 tokens)

💡 Codex CLI reads AGENTS.md automatically from repo root.
   Run /nemp-pro:export --codex after saving new memories.
```

Calculate approximate bytes as the character count of the generated file content. Calculate approximate tokens as `round(bytes / 4)`.

---

## /nemp-pro:export --cursor

Generate `.cursor/rul