Install
openclaw skills install @nohn3043-arch/story-engine-for-creatorDeterministic plot architecture tool with built-in Second Perspective causal reasoning, logic vulnerability detection, automatic worldbuilding generation, narrative presentation layer audit, foreshadowing ledger, spacetime consistency check, hash-chained audit reports, incremental diff-only audit, multi-branch deduction with audit-shape defence, and lexicon-driven event extraction with four deterministic logic validators.
openclaw skills install @nohn3043-arch/story-engine-for-creatorA professional plot creation tool based on deterministic causal reasoning, providing full-process logic verification and generation support for epic novels, game scripts, and film & television screenplays from outline to final draft.
Automatically trigger when the user asks about the following content:
unrecovered_topics and all_closedaudit_text gating: an unclosed foreshadow fails the auditaudit_hash / audit_prev_hash), making reports tamper-evidentaudit_text(..., diff_only=True) audits only the passed-in text and skips global state recomputation — short path for real-time single-chapter/fragment gatekeepingEventNodes: spacetime contradiction, death/state contradiction, timeline regression, foreshadow gapextraction/) turns chapters into event nodes; missing coordinates are skipped rather than fabricated# Initialize engine
from scripts.story_engine import UltimateCausalNovelEngine, GlobalState
state = GlobalState()
engine = UltimateCausalNovelEngine("Your Novel Title", state)
# Load worldview setting
engine.conceive_world("Worldview outline text")
# Create chapter from natural language outline
chapter = engine.create_chapter_from_outline(1, "Chapter Title", "Natural language outline text")
# Perform logic audit
audit_result = engine.audit_text("Chapter content", "consistency")
print(audit_result)
# Generate chapter content
content = engine.render_chapter(chapter)
# v2.3: attach a real LLM (any OpenAI-compatible API, zero external deps)
from scripts.story_engine import OpenAIProvider
engine.set_llm_provider(OpenAIProvider(api_key="sk-...", model="gpt-4o",
base_url="https://api.openai.com/v1"))
# v2.3: single-chapter real-time gatekeeping (skips global recomputation)
quick = engine.audit_text("Chapter content", diff_only=True)
# v2.3: foreshadow + spacetime + hash-chain fields
print(quick["foreshadow"]["ledger"]["unrecovered_topics"], quick["spacetime"],
quick["audit_hash"])
audit_text return shape (v2.3): presentation / causal / logical / foreshadow / spacetime /
audit_hash / audit_prev_hash / all_passed. all_passed is a five-way AND:
presentation + causal + logical + foreshadow closed + spacetime.
Stricter than v2.1.0 — text that passed before may now fail on unclosed foreshadowing or spacetime conflicts.
# Multi-branch deduction: fork -> derive -> audit -> compare (offline demo)
# python scripts/branch_simulator.py --demo --out ./out
import sys; sys.path.insert(0, "scripts")
import branch_simulator as bs
sim = bs.BranchSimulator(engine, strict_characters=True)
branches = sim.fork([{"id": "b1", "name": "折中线", "outline": "……"}])
print(sim.table(branches)); print(sim.compare(branches)["recommended"])
# Event-level validation over a lexicon-driven extraction
from extraction import rule_extractor as rx
import logic_validators as lv
lex = rx.load_lexicon("example") # copy to a client profile first
nodes = rx.extract_nodes(chapter_text, chapter_no=1, lex=lex)
report = lv.run_all(engine, nodes) # spacetime/state/timeline/foreshadow
BranchSimulator loads the engine from scripts/story_engine.py (override with SE_ENGINE_PATH); it never modifies the engine file.
Shares the same character_id with the AI Drawing Composition Template: Visual identity (drawing template) → behavioral identity (this engine) → emotional state (anthropomorphic engine), three sources one truth. Runs continuity checklist per chapter (immutable facts retained verbatim, temperament-consistent behavior, prop continuity, emotional arc, line style). See references/CharacterToNarrativeLink.md.
Worldviews are managed like code: Three layers (core_rules (immutable) / derived_rules (evolvable) / canon (narrative facts)) + semantic versioning (major = core rule change / minor = derived rule change / patch = canon addition). Generates diff per chapter, rejects rule violations or requires explicit version upgrade. See references/WorldviewVersioning.md.
Three-level checkpoints (chapter gate / arc gate / volume gate) + rolling summary window + foreshadowing ledger (promise → fulfillment tracking, alert if >10 chapters unfulfilled). Chapter 20 will never betray Chapter 1. See references/LongNarrativeWindow.md.
Status: as of v2.3 only the foreshadowing ledger part is implemented in the engine (ForeshadowLedger SET/PAY reconciliation); the three-level checkpoints, rolling summary window, and the >10-chapter threshold alert remain design-level documents with no code behind them.
Vulnerability detection directly reuses the five-operator chain from the NOMOS Decision Hub for plot causal audit — the same deterministic engine, migrated from the decision domain to the narrative domain.
UltimateCausalNovelEngine(novel_title, initial_global_state, output_language="zh")recognize_style(), audit_text(), simulate_chapter(), repair_presentation_issues()OpenAIProvider — zero-dependency urllib client for any OpenAI-compatible API; error responses degrade to [LLM Error] … instead of raisingForeshadowLedger.scan_nodes() / reconcile() — SET/PAY keyword reconciliation with an unrecovered_topics list. Note: the >10-chapter unfulfilled alert promised in v2.0 is still not implemented (no chapter-distance threshold in code); the ledger reports unclosed topics unconditionallyaudit_spacetime_consistency(nodes); CausalNode gains time / place / foreshadow / foreshadow_topic_hash_block() + engine._stamp_audit_hash(); engine keeps audit_chain_prefix (genesis "GENESIS")audit_text(..., diff_only=True) + _build_audit_report()UltimateCausalNovelEngine gains foreshadow_ledger and audit_chain_prefixaudit_textscripts/adapters/zh.py (protocol in scripts/adapters/spec.md). The engine loads the adapter at import time.scripts/story_engine.py must stay in the same directory as scripts/adapters/. If the adapter is missing, the engine raises ImportError at startup — there is no silent fallback.story_engine.py was a monolithic build with no adapter dependency.corpus/ (~13 MB) and the corpus-audit research scripts (hlm_audit.py, corpus_*, detect_logic_gaps.py, prose_bridge.py) — research tooling, not runtime.Synced with the repository's generic-template form of the story engine. The engine core and the zh adapter are byte-identical to upstream; this release adds the branch-simulation and event-validation layers that the template now ships.
scripts/branch_simulator.py): forks the engine state (copy.deepcopy), derives variant chapters from a branch config, runs each branch independently, and compares them. Outputs a Pareto front plus a ranking suggestion — no cross-branch "unique optimum" is claimed; the final line choice stays with the author. Includes validate_audit_shape(), which checks the audit structure before reading it so a changed engine shape raises AuditShapeError instead of silently scoring a branch as failed.strict_character_registry): the module-level auto_register_characters can mis-register ordinary nouns as characters (measured: "成本" was registered). The simulator temporarily disables it inside the deduction context and labels that fact in the report.scripts/logic_validators.py): four deterministic, language-agnostic checks — audit_spacetime_contradiction (same character, same time, two places), audit_state_contradiction (death-then-alive / mutually exclusive states), audit_timeline_regression (time marker goes backwards), audit_foreshadow_gap (planted, never paid). All follow "better missing than fabricated": nodes lacking coordinates are skipped, never assumed.scripts/extraction/): rule_extractor.py turns chapters into EventNodes (character / place / time / state) driven by a lexicon file; schema.py defines the data structures and JSON I/O. Lexicons live in extraction/lexicons/ (example.json is a skeleton — copy it to a client profile and replace the contents). An empty characters map raises instead of silently degrading.references/TEMPLATE.md): the repository's generic-template contract — directory table, minimum call, three customisation layers (adapter / lexicon / threshold), delivery acceptance checklist, known boundaries.corpus/ (~13 MB) and corpus-audit research scripts remain research tooling, not runtime.references/CharacterToNarrativeLink.md (P0 character-narrative interlink)references/WorldviewVersioning.md (P0 worldview versioning)references/LongNarrativeWindow.md (P1 long narrative window management)references/TEMPLATE.md (generic-template contract: layout, minimum call, customisation layers, acceptance checklist)scripts/story_engine.py (engine core)scripts/adapters/zh.py + scripts/adapters/spec.md (language adapter — must stay beside the engine)scripts/branch_simulator.py (multi-branch deduction + audit-shape validation; --demo runs an offline self-test)scripts/branch_variants.example.json (branch-config example)scripts/logic_validators.py (event-level spacetime / state / timeline / foreshadow checks)scripts/extraction/ (schema.py, rule_extractor.py, lexicons/example.json)OpenAIProvider; the default path (MockLLM / no provider) stays fully offlineOnly allowed for personal non-commercial research use. Commercial use requires written authorization.