> For the complete documentation index, see [llms.txt](https://astroport-1.gitbook.io/astroport.one/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://astroport-1.gitbook.io/astroport.one/docs/explanation/n2_memory_system.md).

# N² Memory System - Collective Decision Making

## Overview

The N² Memory System is a **decentralized learning mechanism** that enables collective decision-making across the Astroport.ONE constellation. It follows the principle:

> **"L'IA propose, l'Humain dispose"** (AI proposes, Human disposes)

Based on **Conway's Angel Game** (force 2 escapes demon), this system ensures that recommendations emerge from collective intelligence rather than central authority.

## Architecture

```
┌─────────────────────────────────────────────────────────────┐
│                 N² Memory Architecture                       │
├─────────────────────────────────────────────────────────────┤
│                                                              │
│  ┌─────────────────┐                                        │
│  │   todo.sh       │  ← Entry point for all operations      │
│  │   (Scheduler)   │                                        │
│  └────────┬────────┘                                        │
│           │                                                  │
│           ▼                                                  │
│  ┌─────────────────────────────────────────────────────────┐│
│  │              NOSTR Events (kind 31910)                   ││
│  │                                                          ││
│  │  ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐    ││
│  │  │ AI Rec 1 │ │ AI Rec 2 │ │ Captain  │ │  Vote 1  │    ││
│  │  │ proposed │ │ accepted │ │  TODO    │ │  for #1  │    ││
│  │  └──────────┘ └──────────┘ └──────────┘ └──────────┘    ││
│  │                                                          ││
│  │  Key: ~/.zen/game/uplanet.G1.nostr                      ││
│  │  Relay: wss://relay.copylaradio.com                      ││
│  └─────────────────────────────────────────────────────────┘│
│           │                                                  │
│           ▼                                                  │
│  ┌─────────────────────────────────────────────────────────┐│
│  │              AI Learning (question.py)                   ││
│  │                                                          ││
│  │  - Sees past accepted recommendations                    ││
│  │  - Learns from rejected recommendations                  ││
│  │  - Improves future suggestions                           ││
│  └─────────────────────────────────────────────────────────┘│
└─────────────────────────────────────────────────────────────┘
```

## Event Types

### 1. AI Recommendation (`ai_recommendation`)

Generated by `todo.sh` when analyzing Git changes:

```json
{
  "type": "n2_todo",
  "version": "2.1",
  "id": "ai_20260107143025_1_a3f2b1c7d4e8",
  "content": "Add kind 30851 sync to backfill_constellation.sh",
  "status": "proposed",
  "rec_type": "ai_recommendation",
  "priority": "high",
  "station": "12D3KooWABC...",
  "captain": "captain@copylaradio.com",
  "votes": 0,
  "created_at": "2026-01-07T14:30:25Z"
}
```

### 2. Captain TODO (`captain_todo`)

Manually added by station captains:

```json
{
  "type": "n2_todo",
  "version": "2.1",
  "id": "captain_20260107150000_8b2c4a5f9e1d",
  "content": "Integrate Radicle for decentralized code hosting",
  "status": "proposed",
  "rec_type": "captain_todo",
  "priority": "medium",
  "station": "12D3KooWDEF...",
  "captain": "developer@node2.org",
  "votes": 0,
  "created_at": "2026-01-07T15:00:00Z"
}
```

### 3. Vote (`vote`)

Cast by any station to increase priority. Votes are **linked** to the original recommendation via the `reference_id` field and the `["e", rec_id]` tag:

```json
{
  "type": "n2_todo",
  "version": "2.1",
  "id": "vote_ai_20260107143025_1_a3f2b1_12D3KooWXYZ_20260107160000",
  "content": "Vote for ai_20260107143025_1_a3f2b1 by captain@node3.org",
  "status": "vote",
  "rec_type": "vote",
  "priority": "high",
  "station": "12D3KooWXYZ...",
  "captain": "captain@node3.org",
  "reference_id": "ai_20260107143025_1_a3f2b1"
}
```

The NOSTR event also includes an `["e", "rec_id", "", "reply"]` tag (NIP-10 compliant) to enable vote aggregation.

## NOSTR Tags

Each event uses these tags for filtering:

| Tag        | Purpose           | Example                                        |
| ---------- | ----------------- | ---------------------------------------------- |
| `d`        | Unique identifier | `ai_20260107143025_1_a3f2b1`                   |
| `t`        | Type filter       | `n2-todo`, `ai_recommendation`, `captain_todo` |
| `status`   | Current status    | `proposed`, `accepted`, `rejected`, `done`     |
| `priority` | Priority level    | `high`, `medium`, `low`                        |
| `station`  | Origin station    | `12D3KooWABC...`                               |
| `captain`  | Author email      | `captain@copylaradio.com`                      |
| `created`  | Creation date     | `20260107`                                     |

## Status Lifecycle

```
                    ┌─────────────────┐
                    │                 │
                    ▼                 │
┌──────────┐    ┌──────────┐    ┌──────────┐    ┌──────────┐
│ proposed │───►│ accepted │───►│   done   │    │ rejected │
└──────────┘    └──────────┘    └──────────┘    └──────────┘
     │                                               ▲
     │                                               │
     └───────────────────────────────────────────────┘
```

* **proposed**: Initial state (AI or captain created)
* **accepted**: Human validated (will be implemented)
* **rejected**: Human refused (AI learns to avoid similar)
* **done**: Implemented (closes the loop)

## Commands Reference

### Analysis Commands

```bash
# Analyze since last execution (default)
./todo.sh

# Analyze last 24 hours
./todo.sh --day

# Analyze last 7 days
./todo.sh --week

# Skip interactive mode (batch/cron)
./todo.sh --no-interactive
```

### Memory Commands

```bash
# Add a captain TODO (human-written idea)
./todo.sh --add "Implement CRDT-based document sync with NextGraph"

# List pending recommendations
./todo.sh --list

# Show recent memory entries
./todo.sh --memory
```

### Decision Commands

```bash
# Accept a recommendation (human validates)
./todo.sh --accept ai_20260107143025_1_a3f2b1

# Reject a recommendation (human refuses)
./todo.sh --reject ai_20260107143025_2_c7d4e8

# Mark as implemented
./todo.sh --done ai_20260107143025_1_a3f2b1

# Vote for a recommendation (+1 priority)
./todo.sh --vote ai_20260107143025_1_a3f2b1
```

## Interactive Session Example

```
$ ./todo.sh --day

🚀 Génération de TODO.today.md (Dernières 24h)
🎮 N² Constellation Protocol (Conway's Angel Game - force 2)

📊 Récupération des modifications Git (Dernières 24h)...
✅ 5 commit(s) trouvé(s), 12 fichier(s) modifié(s)

📚 Récupération de la mémoire N²...
🤖 Analyse des modifications avec question.py...

✅ TODO.today.md généré avec succès
📄 Fichier: /home/fred/.zen/Astroport.ONE/TODO.today.md

═══════════════════════════════════════════════════════════════
🎯 SÉLECTION DES RECOMMANDATIONS (Capitaine décide)
═══════════════════════════════════════════════════════════════

📤 Stockage des recommandations IA en événements NOSTR séparés...

  [1] 🔴 Add kind 30851 to backfill | NOSTR | Economic aggregation
      ID: ai_20260107143025_1_a3f2b1

  [2] 🟡 Implement DID expiration | DID | NIP-101 compliance
      ID: ai_20260107143025_2_c7d4e8

  [3] 🟢 Optimize amisOfAmis.txt | IPFS | Local performance
      ID: ai_20260107143025_3_9b2a5f

Actions disponibles:
  a <num>  - Accepter la recommandation
  r <num>  - Rejeter la recommandation
  v <num>  - Voter pour cette recommandation
  s        - Tout sauter (skip)
  q        - Quitter

Votre choix [a/r/v/s/q + numéro]: a 1
✅ Recommandation #1 acceptée
   → Ajoutée à TODO.md

Votre choix [a/r/v/s/q + numéro]: v 2
🗳️  Vote pour recommandation #2
✅ Vote recorded
   From: captain@12D3KooW...
   For: ai_20260107143025_2_c7d4e8

Votre choix [a/r/v/s/q + numéro]: q
✓ Fin de la sélection
ℹ️  Les recommandations non traitées restent disponibles avec --list
```

## Collective Decision Flow

```
Station 1 (Paris)        Station 2 (Toulouse)      Station 3 (Lyon)
     │                        │                         │
     │ ./todo.sh              │ ./todo.sh               │ ./todo.sh
     │                        │                         │
     ▼                        ▼                         ▼
┌──────────┐            ┌──────────┐            ┌──────────┐
│ AI recs  │            │ AI recs  │            │ AI recs  │
│ proposed │            │ proposed │            │ proposed │
└────┬─────┘            └────┬─────┘            └────┬─────┘
     │                       │                       │
     │ accept #1             │ vote #1               │ vote #1
     │ vote #2               │ accept #1             │ add captain TODO
     │                       │                       │
     ▼                       ▼                       ▼
┌────────────────────────────────────────────────────────────┐
│                   NOSTR Constellation                       │
│                                                             │
│  rec_1: votes=3, status=accepted  ← HIGHEST PRIORITY        │
│  rec_2: votes=1, status=proposed                            │
│  captain_todo: votes=0, status=proposed                     │
│                                                             │
│  → Collective intelligence emerges from individual votes    │
└────────────────────────────────────────────────────────────┘
```

## Configuration

### Required Files

| File                               | Purpose                  |
| ---------------------------------- | ------------------------ |
| `~/.zen/game/uplanet.G1.nostr`     | Shared constellation key |
| `~/.zen/game/todo_last_run.marker` | Tracks last execution    |
| `~/.zen/Astroport.ONE/.env`        | Environment variables    |

### Creating the Shared Key (Ğ1 Central Bank)

The `uplanet.G1.nostr` key is the **Ğ1 Central Bank** key for the UPlanet constellation. It's shared between:

* **Oracle System**: Signs credentials (kind 30503), NIP-42 auth
* **N² Memory System**: Signs development recommendations (kind 31910)
* **Economy**: Central authority for Ẑen transactions

All stations in the constellation must use the **same** key:

```bash
# Recommended: Use UPLANET.init.sh which handles this automatically
./UPLANET.init.sh

# Manual creation (use exact same seed on all stations):
$HOME/.zen/Astroport.ONE/tools/keygen -t nostr "${UPLANETNAME}.G1" "${UPLANETNAME}.G1" \
    > ~/.zen/game/uplanet.G1.nostr

# Or copy from an existing station
scp captain@station1:~/.zen/game/uplanet.G1.nostr ~/.zen/game/
```

⚠️ **CRITICAL**: The seed must be `${UPLANETNAME}.G1` (with a dot), consistent with `ORACLE_SYSTEM.md`.

### Environment Variables

```bash
# In ~/.zen/Astroport.ONE/.env

# Open Collective integration
OCAPIKEY="your_token"
OCSLUG="monnaie-libre"

# Captain identification
CAPTAINEMAIL="captain@yourstation.org"
```

## Integration with Other Systems

### Open Collective

TODOs are published to Open Collective as development updates:

```
./todo.sh --day
  ├── Generate TODO report
  ├── Interactive selection
  ├── Publish to NOSTR (captain wall)
  └── Publish to Open Collective (development updates)
```

### Future Integrations

| System        | Purpose                           | Status  |
| ------------- | --------------------------------- | ------- |
| **Radicle**   | Decentralized code hosting        | Planned |
| **NextGraph** | CRDT-based document collaboration | Planned |

## AI Learning Context

The AI receives memory context in its prompt:

```markdown
## Mémoire N² (apprentissage constellation)

### Mémoire N² (décisions passées de la constellation)

- [accepted] Add kind 30851 to backfill (station: 12D3KooWABC)
- [rejected] Refactor all RUNTIME scripts (station: 12D3KooWDEF)
- [done] Implement PAF burn mechanism (station: 12D3KooWABC)

_Les recommandations 'accepted' ont été validées par un humain, 
'rejected' ont été refusées._
```

This enables the AI to:

1. Suggest similar ideas to those accepted
2. Avoid patterns that were rejected
3. Build on completed work

## Technical Reference

### NOSTR Kind

```
Kind: 31910 (N² Development Memory)
```

### Event Structure

```json
{
  "kind": 31910,
  "pubkey": "<uplanet.G1.nostr pubkey>",
  "created_at": 1736262625,
  "tags": [
    ["d", "ai_20260107143025_1_a3f2b1"],
    ["t", "n2-todo"],
    ["t", "ai_recommendation"],
    ["status", "proposed"],
    ["priority", "high"],
    ["station", "12D3KooWABC..."],
    ["captain", "captain@copylaradio.com"],
    ["created", "20260107"]
  ],
  "content": "{\"type\":\"n2_todo\",\"version\":\"2.0\",...}",
  "sig": "<schnorr signature>"
}
```

### Query Examples

```bash
# Get all proposed recommendations
./tools/nostr_get_events.sh --kind 31910 --tag-status proposed

# Get recommendations by station
./tools/nostr_get_events.sh --kind 31910 --tag-station 12D3KooWABC

# Get high priority items
./tools/nostr_get_events.sh --kind 31910 --tag-priority high
```

## Related Documentation

* [NIP-101 N² Constellation Sync](https://github.com/papiche/Astroport.ONE/blob/master/nostr-nips/101-n2-constellation-sync-extension.md)
* [ZEN Economy](/astroport.one/docs/archive/zen.economy.readme.md)
* [Oracle System](/astroport.one/docs/explanation/oracle_system.md)
* [ORE System](/astroport.one/docs/explanation/ore_system.md)

***

*Documentation generated: 2026-01-07*\
*System version: 2.1*

## Changelog

### v2.1 (2026-01-07)

* **Vote linking**: Votes now include `reference_id` field and `["e", rec_id]` tag for aggregation
* **ID collision fix**: Hash extended from 6-8 to 12 characters (281 trillion combinations)
* **Key setup docs**: Added instructions for creating `uplanet.G1.nostr` shared key
