Skip to main content

nap — Narrative Addressing Protocol

NAP is a protocol that makes narrative resources addressable, resolvable, and interoperable across tools, storage systems, formats, and AI workflows.

Characters, locations, scenes, props, and entire fictional repositories — NAP gives each one a stable URI, a human-and-machine-readable manifest, a content-addressed history, and a resolver that connects them all.

In the same way that IPFS content-addressed files and OCI container-addressed images, NAP is narrative-addressed — a universal namespace for the building blocks of stories.


Why NAP?

Today, narrative assets live in silos:

  • Worldbuilding docs in Notion or Google Docs
  • Character sheets in spreadsheets
  • Concept art in Dropbox or S3
  • Scene breakdowns in Final Draft or Fade In
  • AI prompts scattered across chat logs
  • 3D assets on Sketchfab or Polycam

None of these tools talk to each other. NAP unifies them under a single addressing and resolution layer.

nap://toystory/character/woody
nap://toystory/location/andys-room
nap://toystory/scene/pizza-planet
nap://toystory/prop/andy-hat

Installation

Installation Script

curl -fsSL https://github.com/portalshq/narrativeengine/releases/latest/download/install.sh | bash

The installation script installs both nap and nap-mcp-server. The MCP server is dormant by default; agent clients start it on demand over stdio so sandboxed agents can use NAP through host-side CLI proxy calls.

Skills Install

Install these skills to use NAP with agent workflows, including entity-aware prompts, generation templates, and the resolve/update steps that keep character and scene output consistent.

npx skills add portalshq/narrativeengine

Quick Start

# Initialize a repository (prompts for provider on first run)
nap init toystory

# Initialize with local provider
nap init toystory --provider local

# Configure provider only (no repository)
nap init --provider local

# Initialize with remote provider
nap init --provider remote --remote-url lore://localhost:41337 --workspace-id my-workspace

# Initialize with Portals Cloud
nap init --provider portals-cloud

# Check system status
nap status

# Run diagnostics
nap doctor

# Run diagnostics with auto-repair
nap doctor --repair

Create a Repository

# Initialize a new repository
nap init toystory

# See what you created
ls toystory/
# → .nap/  repository.yaml  characters/  locations/  scenes/  props/

Create & Inspect Entities

# Create a character
nap create character woody -u toystory -n "Woody"

# Create a location
nap create location andys-room -u toystory -n "Andy's Room"

# Set properties
nap set nap://toystory/character/woody toy_type human
nap set nap://toystory/character/woody homeworld "nap://toystory/location/andys-room"

# Resolve a manifest
nap resolve nap://toystory/character/woody

# Query a specific field
nap resolve nap://toystory/character/woody#properties.toy_type
# → human

# Query a subtree
nap query nap://toystory/character/woody properties

Version Control

# View commit history
nap history nap://toystory/character/woody

# Create branches
nap branch toystory canon

# Sync with remote
nap sync toystory

# Publish to remote
nap publish toystory

Output Formats

nap resolve nap://toystory/character/woody -f json
nap resolve nap://toystory/character/woody -f yaml

Core Primitives

NAP is built on four primitives:

1. URI — Identity

A nap:// URI identifies any narrative resource. Version and branch are orthogonal selectors passed alongside the URI — never encoded in the path (mirrors Git, OCI, and package managers).

nap://toystory/character/woody#references.appears_in
────┬── ───┬──── ────┬──── ──────┬────── ─────────────┬───────────
 scheme repository  entity_type entity_id          fragment (query)

2. Manifest — Current State

A YAML manifest is the durable representation of a narrative resource. It is simultaneously:

  • Human-editable — readable by toybox-builders
  • Machine-editable — structured, schema-validated
  • Agent-readable — subtree-queryable for AI workflows
  • Portable — no runtime dependency, just a file
  • Signable — hash the content, sign the hash (Ed25519 in v0+)
  • Versionable — the manifest is what gets committed
id: "nap://toystory/character/woody"
name: "Woody"
entity_type: character
version: 17
properties:
  homeworld: "nap://toystory/location/andys-room"
  toy_type: human
representations:
  reference_image:
    hash: "blake3:e3b0c44..."
    format: png
provenance:
  model: "midjourney-v6"
  prompt_hash: "blake3:abc123..."

3. Commit — History

Commits are content-addressed (BLAKE3) snapshots with patch metadata. Full history and revision identity live in the VCS, keeping manifests bounded and avoiding self-referential revision pointers.

4. Resolver — URI → Manifest

The resolver turns a nap:// URI into a manifest (or a subtree of one). With optional selectors for branch or commit hash, it supports versioned resolution and fragment-based queries for efficient data access.

Scene Clips as Representations

Scenes can own generated video clips the same way characters own reference images. A generated clip is not usually a representation of one character; it is a representation of a scene, with references back to the characters, locations, props, and style guides that shaped it.

nap create scene pizza-planet -u toystory -n "Pizza Planet"
nap add nap://toystory/scene/pizza-planet clip-01 ./pizza-planet-clip-01.mp4 --format mp4 -m "Add pizza-planet scene clip"

The scene manifest remains simple and durable:

id: "nap://toystory/scene/pizza-planet"
name: "Pizza Planet"
entity_type: scene
version: 3
properties:
  summary: "Woody and Buzz enter a crowded pizza-planet while searching for passage off Andy's Room."
  time_of_day: night
  mood: tense
references:
  characters:
    - "nap://toystory/character/woody"
    - "nap://toystory/character/buzzlightyear"
  location: "nap://toystory/location/pizza-planet"
representations:
  clip-01:
    hash: "blake3:af1349b9..."
    format: mp4
    uri: "clip-01.mp4"

When resolved with provenance, NAP returns versioned per-file provenance for the manifest and each direct representation. This keeps generation metadata attached to the committed files without requiring users to manage the underlying VCS directly.

nap resolve nap://toystory/scene/pizza-planet --provenance
manifest:
  id: "nap://toystory/scene/pizza-planet"
  name: "Pizza Planet"
  entity_type: scene
  version: 3
  representations:
    clip-01:
      hash: "blake3:af1349b9..."
      format: mp4
      uri: "clip-01.mp4"
provenance:
  revision: "a72c9f3b..."
  files:
    - role: manifest
      path: "scene/pizza-planet.yaml"
      provenance:
        nap.provenance.kind: edit
        nap.provenance.author: toybox-builder
    - role: representation
      name: clip-01
      path: "scene/clip-01.mp4"
      uri: "clip-01.mp4"
      hash: "blake3:af1349b9..."
      format: mp4
      provenance:
        nap.provenance.kind: generation
        nap.provenance.model: video-generator
        nap.provenance.prompt.address: "blake3:b4d2..."

Entity Types

Type Example URI Description
character nap://toystory/character/woody Persistent character with identity across scenes/episodes
location nap://toystory/location/andys-room Spatial location within a fictional repository
scene nap://toystory/scene/pizza-planet Narrative scene — participants, timeline, events
prop nap://toystory/prop/andy-hat Physical object with materials, variants, ownership
group nap://toystory/group/buzz-and-woody-flying Mixed-media groups
world nap://toystory/world/toystory The repository itself — rules, canon, top-level metadata

Repository Layout

Each repository is a Git repository on disk:

toystory/                    ← repository root (Git repo)
├── .nap/
│   └── config.yaml          ← repository configuration
├── repository.yaml            ← world manifest
├── characters/
│   ├── woody.yaml
│   └── slinky.yaml
├── locations/
│   └── andys-room.yaml
├── scenes/
│   └── pizza-planet.yaml
└── props/

MCP Server

The standard NAP installer bundles the native nap-mcp-server binary with nap. If the MCP command is missing or broken, rerun the standard NAP installer from a host shell.

The MCP server is not a daemon; agent clients start it on demand over stdio, and it proxies tool calls to the host nap CLI.

Agent Sandbox Integration

When running inside a sandboxed environment (e.g., Codex) without outbound network access, use MCP tools instead of shelling out to the nap CLI directly. The MCP server runs on the host machine, starts only when the agent/MCP client launches it over stdio, and proxies tool calls to the host nap CLI.

Direct nap CLI examples in this skill are for humans, host-local shells, and non-sandboxed scripts. In an agent sandbox, use the MCP tools for any operation that may need Lore/cloud/network access.

Available MCP Tools

All nap CLI commands are available as MCP tools with nap_ prefix. For example:

  • nap resolve -> nap_resolve tool
  • nap create -> nap_create tool
  • nap set -> nap_set tool

Prefer MCP tools over shell commands when in a sandbox.

MCP Server Configuration

Add to your agent's MCP configuration (e.g., ~/.codex/config.json):

{
  "mcpServers": {
    "nap": {
      "command": "/bin/sh",
      "args": [
        "-lc",
        "NAP_DIR=\"$HOME/.nap\" exec nap-mcp-server"
      ]
    }
  }
}

Connect with Codex

Codex stores MCP configuration in ~/.codex/config.toml alongside the rest of its config. The Codex CLI, the ChatGPT desktop app, and the IDE extension all share that MCP configuration, so you only need to register nap once.

Add the server with the CLI:

codex mcp add nap --env NAP_DIR="$HOME/.nap" -- /bin/sh -lc 'exec nap-mcp-server'

If nap-mcp-server is not on PATH, use the full installed path instead, usually ~/.local/bin/nap-mcp-server or /usr/local/bin/nap-mcp-server.

You can also configure it manually in ~/.codex/config.toml:

[mcp_servers.nap]
command = "/bin/sh"
args = ["-lc", "NAP_DIR=\"$HOME/.nap\" exec nap-mcp-server"]
enabled = true

Project-scoped config works too for trusted projects:

[mcp_servers.nap]
command = "/bin/sh"
args = ["-lc", "NAP_DIR=\"$HOME/.nap\" exec nap-mcp-server"]
enabled = true

Use the same block in .codex/config.toml inside a trusted project if you want the server scoped to that repository.

Other MCP Clients

Claude Desktop and other MCP clients use the same stdio pattern. Add a server entry that runs the bundled nap-mcp-server command on demand, and keep NAP_DIR pointed at your NAP workspace if you need a non-default data directory.

Example host-side launch command:

/bin/sh -lc 'NAP_DIR="$HOME/.nap" exec nap-mcp-server'

Use the same command/args form in any client that supports stdio MCP servers.

Inside sandboxes, use the MCP tools instead of shelling out to nap directly for network-backed operations. Direct nap CLI commands remain the right choice for humans and host-local shells.


NAP CLI Reference

The nap command-line interface (v0.5.8) provides tools for creating, resolving, and managing narrative resources using the Narrative Addressing Protocol.

Command Overview

Command Description
`nap add` Add a file representation to an entity manifest
`nap backend` Configure or inspect the version-control backend
`nap branch` Create or list branches
`nap choose` Choose backend provider
`nap commit` Commit changes to a repository repository
`nap content-hash` Compute the BLAKE3 content hash of a file
`nap create` Create a new entity manifest
`nap diff` Show diff between two manifest files or versions
`nap doctor` Run diagnostics and repair
`nap head-hash` Show the current HEAD commit hash
`nap history` View commit history for an entity
`nap init` Initialize a repository repository and/or configure the backend provider
`nap install` Install required dependencies
`nap list` List repositories or entities within a repository
`nap merge` Three-way merge of JSON/YAML values
`nap publish` Publish changes to remote
`nap pull` Clone or pull a repository from a remote
`nap push` Push the current branch to its configured upstream remote
`nap query` Query a subtree from a manifest
`nap remote` Manage remotes on a repository
`nap resolve` Resolve a NAP URI to its manifest or a subtree
`nap revert` Revert a commit by hash (undoes all changes in that commit)
`nap schema` Print a JSON Schema for manifest or commit types
`nap set` Set a property on an entity manifest
`nap sign` Sign a manifest (stub for v0)
`nap status` Show system status
`nap switch` Switch to a branch
`nap sync` Sync with remote
`nap validate` Validate a manifest against the NAP schema
`nap verify` Verify a manifest signature (stub for v0)

Global Options

Flag Description Default
-d, --base-dir <BASE_DIR> Base directory for repository repositories. Defaults to $NAP_DIR, or ~/.nap if unset
-v, --verbose Enable verbose debug logging

Output Formats

Most commands support --format (-f) with values yaml (default) or json.

When stdout is not a terminal, JSON is used automatically. Override with $NAP_OUTPUT.

Common Examples

# Initialize a repository
nap init toystory

# Create an entity
nap create character woody -u toystory -n "Woody"

# Resolve a manifest
nap resolve nap://toystory/character/woody

# Query a subtree
nap query nap://toystory/character/woody properties

# View commit history
nap history nap://toystory/character/woody

HTTP Server

The NAP resolver server provides a REST API for resolution and commits.

# Start the server (defaults to port 3100, base path = current directory)
nap-server

# Custom port and base path
NAP_PORT=8080 NAP_BASE_PATH=/path/to/repositories nap-server

Configuration

NAP core uses environment variables for configuration. All variables serve specific purposes with minimal overlap.

Storage Configuration

Variable Purpose Default Required
NAP_STORAGE_BACKEND Storage backend selection (local or s3) local No
NAP_DIR Base directory for local storage ~/.nap No (local)
NAP_S3_BUCKET S3 bucket name Yes (s3)
AWS_ACCESS_KEY_ID AWS/R2 access key Yes (s3)
AWS_SECRET_ACCESS_KEY AWS/R2 secret key Yes (s3)
AWS_REGION AWS region Yes (s3)
AWS_ENDPOINT_URL_S3 Custom S3 endpoint (R2, MinIO) No (s3)
AWS_ENDPOINT_URL Fallback S3 endpoint if AWS_ENDPOINT_URL_S3 unset No (s3)

Lore VCS Configuration

Variable Purpose Default Required
NAP_LORE_URL_BASE Lore server URL base lore://localhost:8700 No
NAP_WORKSPACE_ID Workspace identifier for multi-tenancy default No
NAPLORE_CLI Path to lore CLI binary lore (from PATH) No
NAP_LORE_GRPC_ENDPOINT gRPC endpoint for branch ref sync No (optional)
NAP_LORE_GRPC_TOKEN JWT bearer token for gRPC auth No (optional)
NAP_LORE_GRPC_RID Repository ID (hex-encoded) for gRPC No (optional)
NAP_LORE_GRPC_INSECURE Skip TLS verification (1/true/yes) 0 No (optional)

Constants

Constant Value Purpose
NAP_DIR (const) .nap Metadata directory name within repositories

Note: The environment variable NAP_DIR (storage base directory) and the constant NAP_DIR (metadata directory name) serve different purposes and do not overlap.

Endpoints

Method Path Description
GET /resolve/{repository}/{entity_type}/{entity_id} Resolve a manifest
GET /resolve/{repository}/{entity_type}/{entity_id}?branch=canon Resolve at a branch
POST /commit/{repository}/{entity_type}/{entity_id} Commit changes
GET /history/{repository}/{entity_type}/{entity_id} Get commit history
GET /repositories List all repositories
GET /repositories/{repository}/entities List entities in a repository
GET /health Health check

Query parameters for resolution: branch, commit, path (subtree query).


CLI Command Reference

Complete reference for all nap CLI commands.

Command Description
`nap add` Add a file representation to an entity manifest
`nap backend` Configure or inspect the version-control backend
`nap branch` Create or list branches
`nap choose` Choose backend provider
`nap commit` Commit changes to a repository repository
`nap content-hash` Compute the BLAKE3 content hash of a file
`nap create` Create a new entity manifest
`nap diff` Show diff between two manifest files or versions
`nap doctor` Run diagnostics and repair
`nap head-hash` Show the current HEAD commit hash
`nap history` View commit history for an entity
`nap init` Initialize a repository repository and/or configure the backend provider
`nap install` Install required dependencies
`nap list` List repositories or entities within a repository
`nap merge` Three-way merge of JSON/YAML values
`nap publish` Publish changes to remote
`nap pull` Clone or pull a repository from a remote
`nap push` Push the current branch to its configured upstream remote
`nap query` Query a subtree from a manifest
`nap remote` Manage remotes on a repository
`nap resolve` Resolve a NAP URI to its manifest or a subtree
`nap revert` Revert a commit by hash (undoes all changes in that commit)
`nap schema` Print a JSON Schema for manifest or commit types
`nap set` Set a property on an entity manifest
`nap sign` Sign a manifest (stub for v0)
`nap status` Show system status
`nap switch` Switch to a branch
`nap sync` Sync with remote
`nap validate` Validate a manifest against the NAP schema
`nap verify` Verify a manifest signature (stub for v0)

Design Principles

  1. Content-addressed — Every piece of content is identified by its cryptographic hash. Manifests are immutable once committed.

  2. URI-addressed — Every entity has a stable, portable URI. URIs are never invalidated by renames or moves.

  3. Human-readable — YAML manifests are readable by toybox-builders and AI agents alike.

  4. Portable — No runtime dependencies. A manifest is just a YAML file. A repository is just a Git repo.

  5. AI-native — Subtree queries let AI agents fetch exactly the data they need. Provenance tracking records generation metadata.

  6. Schema-validated — All manifests conform to a JSON Schema. Invalid manifests are rejected at commit time.

  7. Decentralized — Repositories are Git repositories. They can be cloned, forked, merged, and published independently.

  8. Extensible — New entity types, representation formats, and merge strategies can be added without breaking existing data.


Status

This is a v0 prototype. APIs and formats may change.

License

MIT


Status

This is a v0 prototype. APIs and formats may change.

License

MIT

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

nap_sdk-0.5.8-cp313-cp313-win_amd64.whl (4.9 MB view details)

Uploaded CPython 3.13Windows x86-64

nap_sdk-0.5.8-cp313-cp313-manylinux_2_39_x86_64.whl (8.0 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.39+ x86-64

nap_sdk-0.5.8-cp313-cp313-manylinux_2_39_aarch64.whl (7.8 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.39+ ARM64

nap_sdk-0.5.8-cp313-cp313-macosx_11_0_arm64.whl (5.1 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

nap_sdk-0.5.8-cp313-cp313-macosx_10_12_x86_64.whl (5.2 MB view details)

Uploaded CPython 3.13macOS 10.12+ x86-64

File details

Details for the file nap_sdk-0.5.8-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: nap_sdk-0.5.8-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 4.9 MB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for nap_sdk-0.5.8-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 91b811392cd37d75261c99ec598181f7216a20ba7ade51d96e761beb160ab28c
MD5 a340ef9dd417e94f577b9cee7ac5b297
BLAKE2b-256 1050a47ed3f4ad1ed577d5f08c5d06b479bb6f9293543ec12e49feef5471d0b6

See more details on using hashes here.

File details

Details for the file nap_sdk-0.5.8-cp313-cp313-manylinux_2_39_x86_64.whl.

File metadata

File hashes

Hashes for nap_sdk-0.5.8-cp313-cp313-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 57e2bf04ad441eb24a66348f0ecb726501cbdf20fbdc6e6d2fde8cd24f767332
MD5 43932d14e50ae257a1a269e49868364f
BLAKE2b-256 a9ed1b019fea29645fcefbb62f09d5e455ac8f5d1dd7535fbda521b5c12b842c

See more details on using hashes here.

File details

Details for the file nap_sdk-0.5.8-cp313-cp313-manylinux_2_39_aarch64.whl.

File metadata

File hashes

Hashes for nap_sdk-0.5.8-cp313-cp313-manylinux_2_39_aarch64.whl
Algorithm Hash digest
SHA256 f9d7a01202783102e69d3d8a0d9e382891d47b64d95a15d6e57497bbb9b81852
MD5 cb9fed081ca343444c0e830172295ad8
BLAKE2b-256 7ad6f67801927bf51d452636403646a6d8f8ce407eab45cb4299f6adfc3aed71

See more details on using hashes here.

File details

Details for the file nap_sdk-0.5.8-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for nap_sdk-0.5.8-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 00c8b89672b6b194562734df08563b73580ae6df5fbcda6c3fd71f12bed6a23a
MD5 44a7dca0fa4ec70093c114cb6fdad736
BLAKE2b-256 93b17d3f656de766c68c2f3b9e21353307cdd5a91be93be901b88120832551be

See more details on using hashes here.

File details

Details for the file nap_sdk-0.5.8-cp313-cp313-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for nap_sdk-0.5.8-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 3d2d2db22c6035ba0f41780b434b2b1d9f0657c0903024d512ed1fcb02f7edc0
MD5 7d01ec9201231c848072de55727e8187
BLAKE2b-256 58f14952537934f4fe8cc2c2c9f98e08a8c6c8b957dd6caff6b7bc47857f02ab

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page