# NEXT Object Notation (N.O.N.) — Reference & CML Bridge

**Status:** v0.1 draft  
**Purpose:** Token-efficient, component-aware, human-readable notation for configs, data, and narrative envelopes.  
**Stack:** Vanilla JS reference (`non.js`) for parse/serialize; drop-in for browser or Node.

## Goals
- **Compact:** fewer tokens than JSON; minimal quotes/braces.  
- **Component-aware:** inline component syntax for typed nodes.  
- **Deterministic:** stable round-trips JSON ↔ N.O.N.  
- **Embeddable:** light enough for chat memory, static assets, and game data.  
- **Bridgeable:** easy conversion to/from CML envelopes for The Imaginatorium.

## Syntax (essentials)
- Key/value: `key: value` (no quotes if safe).  
- Objects: indentation-based nesting.  
- Arrays: lines prefixed with `-` (optionally inline: `[a, b, c]`).  
- Strings: unquoted if no spaces/colon/newline; otherwise `"quoted"`.  
- Numbers/booleans/null: bare literals.  
- Components (typed objects): `TypeName(prop: val, flag: true)` → `{ __type: "TypeName", prop: val, flag: true }`.
- Comments: `# ...` to end of line.

## Examples

### Basic object
```
title: Technomancer D
author: Cursy
tags:
  - liquid-dnb
  - emoji-alchemy
settings:
  bpm: 172
  difficulty: chill
```

### Components
```
track: Stem(name: "Chilli Chainz 140", bpm: 140, mood: liquid)
spell:
  SparkleShield(power: 3, role: shield, crit: false)
  # parses to { __type: "SparkleShield", power: 3, role: "shield", crit: false }
```

### Inline arrays
```
moods: [cozy, neon, focused]
```

### Mixed
```
encounter:
  name: "Broadcast Tower"
  bpm: 172
  anchors: [ska, liquid, wwweed]
  boss: Broadcaster(hp: 1200, phase: 3, shield: compliance)
```

## JSON ↔ N.O.N. mapping
- Objects/arrays map 1:1.  
- Components add `__type` property.  
- Missing/empty becomes `{}` or `[]`.  
- Unsafe keys/values get quoted.

## CML Bridge (Imaginatorium)
- CML files use an envelope line like `[timestamp|kind|actor|slug|tags...]` plus a structured block.  
- Bridge steps:
  1) Extract header tokens → `meta` object (`timestamp`, `kind`, `actor`, `slug`, `tags`).  
  2) Parse the body as CML (similar to relaxed JSON with semicolons).  
  3) Emit N.O.N.: wrap as:
     ```
     meta:
       timestamp: 2025-11-26T13:30:00Z
       kind: event
       actor: damo
       slug: 7-11-run
       tags: [type:side-quest, theme:cyberpunk-noir, location:7-11]
     body: {...parsed...}
     ```
  4) Optional: tag nodes with `__type` when CML uses typed entries.
- See `examples/cml-bridge.md` for a sample conversion.

## Reference API (non.js)
- `jsonToNon(obj): string` — serialize JSON to N.O.N.  
- `nonToJson(text): any` — parse N.O.N. to JSON.  
- `parseComponent(token): object` — internal; turns `Type(a:1)` into `{__type:"Type", a:1}`.
- `fromCmlEnvelope(cmlText): object` — minimal bridge: splits header + body, parses body as N.O.N.-compatible block if structured; otherwise returns raw string.

## Conventions
- Prefer 2-space indent.  
- Keep line lengths short for chat embeddings.  
- Use `__type` for component names.  
- Quote only when required.

## Roadmap
- v0.2: schema/validation helpers, better error reporting.  
- v0.3: streaming parser, CLI tool.  
- v0.4: VS Code syntax + lint hints.  
- Bridges: richer CML → N.O.N. round-trip with lossless tags.

