- AGENTS.md: formalized game loop (print turn → wait for reaction → process → generate next turn), fixed project layout paths - tools/store_turn.py: new script to append turn to book.md and clear temp files - tools/run.py: TUI redesign — TODO always on top, CHARACTER/LOG tabs, TURN section with rendered markdown, input writes to turn_reaction.md, scrolling via VerticalScroll, log auto-populates from previous day, >>--- NOW ---> marker at log end with auto-scroll - session/book.md: story book (append-only narrative) - session/log/2026-06-25.md: today's log seeded from previous session
60 lines
1.5 KiB
Python
Executable File
60 lines
1.5 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""Append a turn to the story book and clear turn temp files.
|
|
|
|
Usage:
|
|
python3 scripts/store_turn.py "Dillion stepped into the chamber..."
|
|
python3 scripts/store_turn.py < reaction.txt
|
|
"""
|
|
|
|
import sys
|
|
from pathlib import Path
|
|
from datetime import date
|
|
|
|
SESSION = Path(__file__).resolve().parent.parent / 'session'
|
|
BOOK = SESSION / 'book.md'
|
|
TURN_DESC = SESSION / 'turn_description.md'
|
|
TURN_PROMPT = SESSION / 'turn_prompt.md'
|
|
TURN_REACTION = SESSION / 'turn_reaction.md'
|
|
|
|
CLEAR_FILES = [TURN_DESC, TURN_PROMPT, TURN_REACTION]
|
|
|
|
|
|
def get_reaction() -> str:
|
|
if len(sys.argv) > 1:
|
|
return sys.argv[1]
|
|
if not sys.stdin.isatty():
|
|
return sys.stdin.read().strip()
|
|
return ''
|
|
|
|
|
|
def main():
|
|
reaction = get_reaction()
|
|
if not reaction:
|
|
print("No reaction text provided. Pass as argument or pipe stdin.")
|
|
sys.exit(1)
|
|
|
|
description = TURN_DESC.read_text().strip() if TURN_DESC.exists() else ''
|
|
timestamp = date.today().isoformat()
|
|
|
|
entry_parts = []
|
|
if description:
|
|
entry_parts.append(description)
|
|
if reaction:
|
|
entry_parts.append(reaction)
|
|
|
|
entry = '\n\n'.join(entry_parts)
|
|
heading = f'\n\n## Turn — {timestamp}\n\n'
|
|
BOOK.parent.mkdir(parents=True, exist_ok=True)
|
|
with open(BOOK, 'a') as f:
|
|
f.write(heading + entry + '\n')
|
|
|
|
for fpath in CLEAR_FILES:
|
|
if fpath.exists():
|
|
fpath.write_text('')
|
|
|
|
print(f"✓ Turn stored → {BOOK}")
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|