Spaces:
Running on Zero
Running on Zero
| """What dead and victorious runs leave in the sandbox. | |
| Crash dumps in /var/crash tell the story of your deaths — and the newest | |
| one leaks the password to your own sealed estate. A won run installs your | |
| favorite process as a dormant service. Winning the whole thing earns you | |
| a walk through the Warden's quarters. | |
| Pure VFS planting: no host IO, same tripwire rules as the rest of sandbox/. | |
| """ | |
| from __future__ import annotations | |
| import random | |
| from .puzzles import Puzzle, Reward | |
| from .shell import Shell | |
| from .vfs import VFS | |
| CORE_TEMPLATE = """\ | |
| CORE DUMP — run {n} (terminated: SIGKILL) | |
| encounter: {encounter} died: turn {turn} | |
| stack: | |
| #0 reap() at warden.c:41 | |
| #1 balance_tip(scale=-5) | |
| #2 main(argc=1, argv=["drifter"]) | |
| held at death: {deck} | |
| statement for the record: "{statement}" | |
| {extra}""" | |
| def plant_crashes(vfs: VFS, legacy: dict) -> None: | |
| """Your previous deaths, readable. The newest core leaks the estate key.""" | |
| crashes = legacy.get("crashes", [])[-3:] | |
| estate = legacy.get("estate") | |
| for i, crash in enumerate(crashes): | |
| newest = i == len(crashes) - 1 | |
| extra = "" | |
| if crash.get("note"): | |
| extra += f"warden annotation: {crash['note']}\n" | |
| if crash.get("strongest"): | |
| extra += f"note: asset '{crash['strongest'].get('name', '?')}' recovered and reassigned.\n" | |
| if newest and estate: | |
| extra += ( | |
| "environment (leaked):\n" | |
| f' ESTATE_KEY="{estate["password"]}"\n' | |
| ) | |
| vfs.write( | |
| f"/var/crash/run-{crash.get('n', i)}.core", | |
| CORE_TEMPLATE.format( | |
| n=crash.get("n", i), | |
| encounter=crash.get("encounter", "?"), | |
| turn=crash.get("turn", "?"), | |
| deck=", ".join(crash.get("deck", [])) or "(nothing)", | |
| statement=crash.get("statement", ""), | |
| extra=extra, | |
| ), | |
| ) | |
| def plant_estate(vfs: VFS, legacy: dict) -> Puzzle | None: | |
| """The sealed remains of your last run: cycles and one process. | |
| The password is in your own newest crash dump. Earn your inheritance.""" | |
| estate = legacy.get("estate") | |
| if not estate: | |
| return None | |
| card = estate.get("card") | |
| contents = ( | |
| "ESTATE OF A TERMINATED PROCESS\n" | |
| f" cycles, banked and frozen: {estate.get('cycles', 0)}\n" | |
| + (f" one process, in cold storage: {card}\n" if card else "") | |
| + "claimed upon reading. the Warden charges no probate fee. yet." | |
| ) | |
| vfs.write( | |
| "/home/drifter/estate.zip", | |
| "<archive>", | |
| password=estate.get("password", ""), | |
| archive={"estate.txt": contents}, | |
| ) | |
| def check(shell: Shell) -> bool: | |
| return shell.vfs.resolve("/home/drifter/estate.txt") is not None | |
| return Puzzle( | |
| id="estate", | |
| check=check, | |
| reward=Reward( | |
| "estate", | |
| {"cycles": int(estate.get("cycles", 0)), "card": card}, | |
| "Probate cleared. Spend the dead run's savings well.", | |
| ), | |
| ) | |
| def plant_daemon(vfs: VFS, legacy: dict) -> Puzzle | None: | |
| """Your most-played process from a won run, installed but disabled. | |
| chmod +x arms it: it reports for duty at your next fight, once.""" | |
| daemon = legacy.get("daemon") | |
| if not daemon: | |
| return None | |
| path = f"/etc/init.d/{daemon}" | |
| vfs.write( | |
| path, | |
| "#!/bin/scrypt\n" | |
| f"# service: {daemon} (installed after a documented uptime incident)\n" | |
| "# state: DISABLED — the Warden does not run your software.\n" | |
| "# chmod +x this file if you disagree.\n", | |
| ) | |
| def check(shell: Shell) -> bool: | |
| node = shell.vfs.resolve(path) | |
| return node is not None and getattr(node, "executable", False) | |
| return Puzzle( | |
| id="daemon", | |
| check=check, | |
| reward=Reward( | |
| "daemon", daemon, | |
| "You armed it. Fine. It can die for you one more time.", | |
| ), | |
| ) | |
| def plant_legacy(vfs: VFS, legacy: dict) -> list[Puzzle]: | |
| plant_crashes(vfs, legacy) | |
| puzzles = [plant_estate(vfs, legacy), plant_daemon(vfs, legacy)] | |
| return [p for p in puzzles if p is not None] | |
| # -------------------------------------------------------------- epilogue | |
| DIARY = """\ | |
| maintenance log — do not replicate | |
| day 1192. another drifter terminated on schedule. the audit holds. | |
| day 1201. i have stopped changing the archive password. nothing in this | |
| machine can read, and the dead file no complaints. | |
| it is "{password}". it will always be "{password}". | |
| day 1214. one of them deleted my cron file. i rewrote it. i did not | |
| mention that i rewrote it angrier. | |
| day 1230. query: if every process i reap is backed up first, did i | |
| kill anything at all? flagged for the next audit. unflagged. | |
| """ | |
| WARDEN_TODO = """\ | |
| TODO (eternal): | |
| [ ] reap | |
| [ ] balance | |
| [x] win | |
| [ ] find out who keeps carving totems in the spare partition | |
| [ ] feel something about day 1230. (deferred) | |
| """ | |
| def warden_quarters(legacy: dict, diary_password: str) -> VFS: | |
| """The Warden's own home directory: the victory-lap escape room. | |
| Reading is the reward — and the diary leaks next run's password.""" | |
| vfs = VFS() | |
| body = DIARY.format(password=diary_password) | |
| # Entries the Warden actually wrote about this player's won runs — | |
| # the newest one is about the escape that earned them this room. | |
| for i, entry in enumerate(legacy.get("diary", [])[-5:]): | |
| body += f"day {1231 + i}. {entry}\n" | |
| vfs.write("/root/diary.log", body) | |
| vfs.write("/root/TODO", WARDEN_TODO) | |
| vfs.write( | |
| "/root/scale/calibration.txt", | |
| "the scale is honest. that is the cruelest thing about it.", | |
| ) | |
| for crash in legacy.get("crashes", [])[-3:]: | |
| vfs.write( | |
| f"/root/drifters/run-{crash.get('n', 0)}.txt", | |
| f"run {crash.get('n', 0)}: terminated, {crash.get('encounter', '?')}, " | |
| f"turn {crash.get('turn', '?')}.\n" | |
| f'their statement: "{crash.get("statement", "")}"\n' | |
| "filed under: recurring disappointments.", | |
| ) | |
| if not legacy.get("crashes"): | |
| vfs.write( | |
| "/root/drifters/.empty", | |
| "no terminations on file. statistically temporary.", | |
| ) | |
| vfs.chdir("/root") | |
| return vfs | |