Files
nightclub-arcadia/tools/writing/voicelib.py
T
lennartandClaude Opus 5 f1fadf7909 add a writer-facing content pipeline under writing/
Dialogue was already plain text, so the gap was never the .yarn files. It was
that the character material a writing session needs was either missing or stored
somewhere a writer could not comfortably work.

Three things were wrong. The writing handbook was not in the repo and was cited
by SC101.yarn as though it were. The best voice material — register, verbal tics,
success/failure/passive samples — was a \n-escaped string inside a JSON field.
The named NPCs had no sheets at all, existing only as their Yarn lines.

writing/ now holds the dialogue-facing layer, at the repo root so it gets no
.meta files and is not a Unity asset:

  STYLE.md          register, the five tone moves, the ban list, branching
                    shapes, the Wrong Truth rule, flag families, candidate rules
  YARN-PRIMER.md    the one page of syntax needed to write a scene
  GLOSSARY.md       in-world and project vocabulary
  voices/           the eleven skill voices, one readable sheet each
  characters/       Bartender, Chevalier Cassian Thal, Bradford Kane
  scenes/           SC-101's brief: intent, beats, checks, constraints
  lore/             the three identity readings and the rules that bind them

STYLE.md is a digest of the Mystery Writing Handbook in the Obsidian vault, with
pointers rather than copies. The vault stays the authoring home for design work,
and Ground Truth — the solution document — deliberately stays out of this repo.

The voice sheets are generated from skill_bible.json but are the source of truth
for the prose. tools/writing/sync_voices.py folds edits back; voicelib.py
guarantees notes -> dict -> notes is identity for all eleven, so --to-json on
unchanged sheets is byte-identical. VoiceSheetSyncTests fails the build on drift
in either direction, and was verified to fail on real drift rather than merely
to pass.

SC101.yarn's header is trimmed from prose rationale to the six rules that bind
while editing that file, with the reasoning moved to the scene brief.

EditMode 42/42. YarnCheck compiles 9 files / 35 nodes.

Co-Authored-By: Claude Opus 5 <[email protected]>
2026-08-25 20:23:42 +02:00

121 lines
3.6 KiB
Python

"""Parse and re-emit the Skill Bible prose that lives in skill_bible.json.
The `notes` field of each skill is a plain-text sheet with a fixed shape. This
module converts between that string and a structured dict, losslessly, so the
prose can live in writing/voices/*.md and still be folded back into the JSON.
Round-tripping is the whole contract: notes -> dict -> notes must be identity
for every skill in the bible, and check_roundtrip() asserts exactly that.
"""
import re
PROSE_KEYS = [
"name",
"domain",
"what it wants for you",
"what it's wrong about",
"how it addresses you",
"register",
]
# "verbal tics" is handled separately (it carries bullets)
TAIL_KEYS = ["what it never does", "opposed to", "allied with"]
VOICE_RE = re.compile(r'^(SUCCESS|FAILURE|PASSIVE) VOICE(?: — (.*?))?: (.*)$')
FIRING_RE = re.compile(r'^Firing frequency target \(per hour\): (\d+)$')
FORBID_RE = re.compile(r'^Domains it must NOT comment on: (.*)$')
BULLET_RE = re.compile(r'^\* \((\d+)\) (.*)$')
def parse_notes(notes):
"""notes string -> dict. Raises on anything unrecognised."""
out = {"fields": {}, "tics": [], "voices": {}, "voice_gloss": {}}
lines = notes.split("\n")
i = 0
if lines[i].strip() != "SKILL":
raise ValueError("expected a leading SKILL line")
out["_header"] = lines[i]
i += 1
while i < len(lines):
line = lines[i]
if line.strip() == "":
i += 1
continue
m = BULLET_RE.match(line)
if m:
out["tics"].append((int(m.group(1)), m.group(2)))
i += 1
continue
m = VOICE_RE.match(line)
if m:
kind = m.group(1).lower()
out["voices"][kind] = m.group(3)
if m.group(2):
out["voice_gloss"][kind] = m.group(2)
i += 1
continue
m = FIRING_RE.match(line)
if m:
out["firing"] = int(m.group(1))
i += 1
continue
m = FORBID_RE.match(line)
if m:
out["forbidden"] = m.group(1)
i += 1
continue
m = re.match(r"^([a-z][a-z '\-]*): ?(.*)$", line)
if m and m.group(1) in PROSE_KEYS + TAIL_KEYS + ["verbal tics"]:
out["fields"][m.group(1)] = m.group(2)
i += 1
continue
raise ValueError(f"unrecognised line: {line!r}")
return out
def emit_notes(d):
"""dict -> notes string. Inverse of parse_notes."""
L = [d.get("_header", "SKILL")]
for k in PROSE_KEYS:
L.append(f"{k}: {d['fields'][k]}")
L.append("verbal tics:")
for n, text in d["tics"]:
L.append(f"* ({n}) {text}")
for k in TAIL_KEYS:
L.append(f"{k}: {d['fields'][k]}")
L.append("")
for kind in ("success", "failure", "passive"):
gloss = d["voice_gloss"].get(kind)
label = f"{kind.upper()} VOICE"
if gloss:
L.append(f"{label} — {gloss}: {d['voices'][kind]}")
else:
L.append(f"{label}: {d['voices'][kind]}")
L.append("")
L.append(f"Firing frequency target (per hour): {d['firing']}")
L.append(f"Domains it must NOT comment on: {d['forbidden']}")
return "\n".join(L)
def check_roundtrip(skills):
"""Assert notes -> dict -> notes is identity for every skill."""
bad = []
for s in skills:
try:
again = emit_notes(parse_notes(s["notes"]))
except Exception as e:
bad.append((s["id"], f"parse error: {e}"))
continue
if again != s["notes"]:
bad.append((s["id"], "round-trip differs"))
return bad