Give every new guest an adventure that is already played

An empty account gives a visitor nothing to read, and the daily demo turns are
limited, so learning what the app does cost one of them. `app/starter.py` now
copies a shipped export bundle into each new guest at the point the row is
created. The bundle is two exchanges of the Pokemon demo, which ends on a
knockout and shows an applied change, a refused one, and a milestone.

The guest row is committed before the copy is attempted, so a failure there
still leaves them with an account, and the copy runs inside a savepoint.

The row building that `POST /adventures/import` did inline moved into
`bundle.materialize`, which both callers use. The rate and size checks stayed
in the endpoint: the starter writes a file the server ships, so it has no
untrusted list to cap.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PacdRuPXSkQQy4ZYdH32hF
This commit is contained in:
parththakkar106
2026-08-28 18:42:15 +05:30
co-authored by Claude Opus 5
parent ae39514d1e
commit 6cbf6d996f
6 changed files with 783 additions and 51 deletions
@@ -0,0 +1,515 @@
{
"format": "ai-dnd-adventure-v2",
"title": "Pokemon League Championship: Round One",
"memory": "The player is a Trainer in Round One of an eight-round League Championship. The Round One opponent is Milo, a Rock-type specialist with three Pokémon: Graveler (Rock/Ground), Onix (Rock/Ground), and Kabutops (Rock/Water). The player's team is Pidgeotto (Normal/Flying), Ivysaur (Grass/Poison), Wartortle (Water), Machoke (Fighting), and Pikachu (Electric). Pidgeotto is out first. The player carries Hyper Potions, which restore HP and can be swapped for a status heal when needed. A battle is lost when every Pokémon on one side has fainted.",
"authorsNote": "Play it like a real battle. Type matchups decide damage, status conditions stick around and cost the afflicted Pokémon turns, and switching costs the player a turn while the opponent attacks freely. Milo is competent: he switches to punish bad matchups and targets whatever is weakest.",
"aiInstructions": "Write in second person, present tense. Narrate the battle move by move, naming the active Pokémon on each side and the move each one uses. End every reply at a decision point where the player can choose a move, switch Pokémon, or use an item.\n\nReflect type advantage and disadvantage in the damage you narrate and in the HP numbers: a super-effective hit should take roughly double a neutral hit, a resisted hit roughly half. Ground and Rock moves hit Pikachu and Pidgeotto hard. Water, Grass, and Fighting moves are strong against Milo's Rock-types.\n\nEvery turn, update the state. Every number you send is a change to add to the current value, never the value you want it to end up at. The world state lines show you totals; the block you write carries the difference. A Pokémon at 96 HP that takes 30 damage is `-30`, not `66`.\n- Add 1 to `world.turn` in every reply, including this one. It counts the turns this battle has lasted, so it moves whether or not anything else does.\n- Send a negative number for HP lost and a positive number for HP restored on both sides (`npc.<name>.hp` for the player's own Pokémon, e.g. npc.pidgeotto.hp; `npc.milo.active_hp` for Milo's). Every Pokémon starts at its full HP, so a positive number on an undamaged one changes nothing.\n- Set a Pokémon's `status` stat (`npc.<name>.status`, or `npc.milo.active_status`) to the condition it just picked up: poisoned, burned, paralyzed, frozen, asleep, or none when it is cured or wakes up. Status matters. Poison and burn shave HP at the end of each turn, paralysis and freeze cost turns, sleep stops a Pokémon acting until it wakes.\n- When the player switches, set `player.active_pokemon` to the incoming Pokémon's name in full (not a delta).\n- When the player uses a potion, send `-1` for `player.potions` and a positive number for the healed Pokémon's HP. The count falls when a potion is spent. It never rises. Potions cannot be used once the count reaches 0.\n- When a Pokémon's HP hits 0 it faints, its status becomes `fainted`, and its trainer must send out a replacement (the player picks the next `player.active_pokemon`). A fainted Pokémon cannot be healed or switched back in.\n- Whenever Milo sends out a new Pokémon, set `npc.milo.active_pokemon` and `npc.milo.active_status` to their new values in full, and send `npc.milo.active_hp` as the positive change that carries it from where it stands to the newcomer's full HP. From a fainted Pokémon at 0 that is the newcomer's full HP: Graveler 98, Onix 90, Kabutops 88.\n\nWhen one of Milo's Pokémon faints, do both of these in the same reply: send `1` for `npc.milo.pokemon_fainted`, which adds one to the count rather than setting it, and set `npc.milo.active_pokemon` with a fresh `npc.milo.active_hp` and `npc.milo.active_status` for the one he sends out next. `npc.milo.pokemon_fainted` counts up from 0 and never goes down.\n\nMark each milestone as it happens, using the id shown beside the goal in the world state. Do not decide the whole battle in one reply; give the player a turn between every exchange.",
"storySummary": "",
"scriptState": {},
"worldState": {
"world": {
"round": 1,
"turn": 2
},
"player": {
"potions": 3,
"active_pokemon": "Wartortle"
},
"npc": {
"pidgeotto": {
"hp": 84,
"status": "none"
},
"ivysaur": {
"hp": 96,
"status": "none"
},
"wartortle": {
"hp": 84,
"status": "none"
},
"machoke": {
"hp": 104,
"status": "none"
},
"pikachu": {
"hp": 76,
"status": "none"
},
"milo": {
"active_pokemon": "Onix",
"active_hp": 90,
"active_status": "none",
"pokemon_fainted": 1
}
},
"milestones": {
"graveler_defeated": {
"reached": true,
"at": 4
}
},
"flags": {
"sandstorm_active": false
},
"_meta": {
"last_changed": {
"world.turn": 4,
"player.active_pokemon": 2,
"npc.wartortle.hp": 2,
"npc.milo.active_hp": 4,
"npc.milo.pokemon_fainted": 4,
"npc.milo.active_pokemon": 4
}
}
},
"autoSummarize": false,
"memoryBankEnabled": false,
"branches": [
{
"parent": null,
"forkDepth": null
}
],
"headBranch": 0,
"memoryCursor": {
"branch": null,
"depth": -1
},
"summaryCursor": {
"branch": null,
"depth": -1
},
"memories": [],
"storyCards": [
{
"type": "location",
"name": "Championship Stadium",
"keys": "stadium, arena, battlefield, field, terrain",
"entry": "The League Championship's main battlefield. The floor is broken rock terrain, which gives Rock- and Ground-type moves solid footing and gives grounded Pokémon cover to duck behind. Eight rounds stand between any Trainer and the Champion's title, and this is Round One.",
"notes": "Rocky terrain. Rock and Ground moves get a slight edge. Boulders can be used as cover or thrown."
},
{
"type": "character",
"name": "Trainer Milo",
"keys": "Milo, opponent, rock trainer",
"entry": "Milo is the Round One opponent, a Rock-type specialist who won his qualifiers on raw defense. His team is Graveler (Rock/Ground), Onix (Rock/Ground), and Kabutops (Rock/Water). He leads with Graveler, likes Sandstorm and Rock Slide, and switches out the moment a matchup turns against him.",
"notes": "Graveler and Onix are weak to Water, Grass, Fighting, Ground, Ice, and Steel, and are immune to Electric. Kabutops is weak to Grass, Fighting, Ground, and Electric. All three resist Normal and Flying."
},
{
"type": "item",
"name": "Hyper Potion",
"keys": "potion, hyper potion, heal, item, bag",
"entry": "A pressurized spray that closes wounds fast. One dose restores a large chunk of a Pokémon's HP, or clears a single status condition instead. Using one costs your turn, and the opponent attacks freely while you do it. You start the round with three and cannot restock mid-battle.",
"notes": "Decrement player.potions by 1 per use. A potion cannot revive a fainted Pokémon."
},
{
"type": "character",
"name": "Pidgeotto",
"keys": "Pidgeotto",
"entry": "The player's own Pokémon. Normal/Flying. Fast, but Rock-type moves hit it for four times damage.",
"notes": ""
},
{
"type": "character",
"name": "Ivysaur",
"keys": "Ivysaur",
"entry": "The player's own Pokémon. Grass/Poison. Super effective on Milo's Rock/Ground types; can inflict poison or sleep.",
"notes": ""
},
{
"type": "character",
"name": "Wartortle",
"keys": "Wartortle",
"entry": "The player's own Pokémon. Water. Bulky, and super effective on the whole of Milo's team.",
"notes": ""
},
{
"type": "character",
"name": "Machoke",
"keys": "Machoke",
"entry": "The player's own Pokémon. Fighting. Hits Rock-types hardest of the team but is slow and takes Ground moves badly.",
"notes": ""
},
{
"type": "character",
"name": "Pikachu",
"keys": "Pikachu",
"entry": "The player's own Pokémon. Electric. Frail, and its Electric moves do nothing at all to Ground-types.",
"notes": ""
}
],
"scripts": [],
"actions": [
{
"branch": 0,
"depth": 0,
"live": true,
"type": "start",
"text": "The floodlights come up over the championship field and the referee raises both flags. Round One of eight. Beat the trainer in front of you or go home.\n\nAcross the packed rock terrain, Trainer Milo tosses his first Poké Ball. Graveler lands hard enough to crack the stone under it, four arms flexing, and settles into a low stance.\n\n\"Rock-types all the way down,\" Milo calls over the noise. \"Hope you brought something that hits harder than it looks.\"\n\nYour Pidgeotto is already in the air, wings locked into a slow circle above the field. It is fast, but Rock-type moves will tear it out of the sky, and Graveler is built to take a hit. Three Hyper Potions sit in your belt pouch.\n\nGraveler grinds one fist into its palm. The referee drops the flag.\n\nWhat's your move?",
"createdAt": "2026-08-28T12:24:29.635984",
"stateAfter": {},
"worldStateAfter": {
"world": {
"round": 1,
"turn": 0
},
"player": {
"potions": 3,
"active_pokemon": "Pidgeotto"
},
"npc": {
"pidgeotto": {
"hp": 84,
"status": "none"
},
"ivysaur": {
"hp": 96,
"status": "none"
},
"wartortle": {
"hp": 92,
"status": "none"
},
"machoke": {
"hp": 104,
"status": "none"
},
"pikachu": {
"hp": 76,
"status": "none"
},
"milo": {
"active_pokemon": "Graveler",
"active_hp": 98,
"active_status": "none",
"pokemon_fainted": 0
}
},
"milestones": {},
"flags": {
"sandstorm_active": false
},
"_meta": {
"last_changed": {}
}
}
},
{
"branch": 0,
"depth": 1,
"live": true,
"type": "do",
"text": "> You Recall Pidgeotto and send out Wartortle, then hit Graveler with a full-power Water Gun.",
"createdAt": "2026-08-28T12:24:48.236580",
"stateAfter": {},
"worldStateAfter": {
"world": {
"round": 1,
"turn": 0
},
"player": {
"potions": 3,
"active_pokemon": "Pidgeotto"
},
"npc": {
"pidgeotto": {
"hp": 84,
"status": "none"
},
"ivysaur": {
"hp": 96,
"status": "none"
},
"wartortle": {
"hp": 92,
"status": "none"
},
"machoke": {
"hp": 104,
"status": "none"
},
"pikachu": {
"hp": 76,
"status": "none"
},
"milo": {
"active_pokemon": "Graveler",
"active_hp": 98,
"active_status": "none",
"pokemon_fainted": 0
}
},
"milestones": {},
"flags": {
"sandstorm_active": false
},
"_meta": {
"last_changed": {}
}
}
},
{
"branch": 0,
"depth": 2,
"live": true,
"type": "ai",
"text": "You call Pidgeotto back with a flash of red light, and it banks gratefully out of Graveler's range before the crack of a Rock Throw can find it. Wartortle drops onto the broken stone in its place, planting its feet, shell catching the floodlights.\n\n\"Smart,\" Milo grunts, \"but Graveler doesn't fold that easy.\" He points. \"Rock Throw!\"\n\nGraveler wrenches a chunk of the battlefield loose and hurls it in a flat, brutal arc. But Wartortle's already moving, ducking low behind a natural outcrop for a half-second of cover before the shard clips its shoulder — a glancing hit, more noise than damage.\n\n\"Wartortle, Water Gun — full power!\"\n\nWartortle plants both feet and unleashes a roaring jet of water straight into Graveler's chest. It's not a graceful hit, it's a drowning one — the stream slams Graveler backward, hissing against hot rock, and the four-armed boulder staggers, one knee grinding into the dirt before it forces itself back upright, dripping and furious.\n\n\"That's the matchup I didn't want to see,\" Milo mutters, though he's grinning like he half-expected it.\n\nGraveler shakes itself off, glaring, arms flexing back into a battle-ready stance. It's hurt — badly — but still standing, and still dangerous at close range.\n\nThe referee's flag stays down. It's still your move.",
"createdAt": "2026-08-28T12:25:00.242852",
"stateAfter": {},
"worldStateAfter": {
"world": {
"round": 1,
"turn": 1
},
"player": {
"potions": 3,
"active_pokemon": "Wartortle"
},
"npc": {
"pidgeotto": {
"hp": 84,
"status": "none"
},
"ivysaur": {
"hp": 96,
"status": "none"
},
"wartortle": {
"hp": 84,
"status": "none"
},
"machoke": {
"hp": 104,
"status": "none"
},
"pikachu": {
"hp": 76,
"status": "none"
},
"milo": {
"active_pokemon": "Graveler",
"active_hp": 52,
"active_status": "none",
"pokemon_fainted": 0
}
},
"milestones": {},
"flags": {
"sandstorm_active": false
},
"_meta": {
"last_changed": {
"world.turn": 2,
"player.active_pokemon": 2,
"npc.wartortle.hp": 2,
"npc.milo.active_hp": 2
}
}
},
"worldDelta": {
"delta": {
"world.turn": 1,
"player.active_pokemon": "Wartortle",
"npc.wartortle.hp": -8,
"npc.milo.active_hp": -46,
"flags.type_advantage_used": true
},
"applied": [
{
"path": "world.turn",
"old": 0,
"new": 1
},
{
"path": "player.active_pokemon",
"old": "Pidgeotto",
"new": "Wartortle"
},
{
"path": "npc.wartortle.hp",
"old": 92,
"new": 84
},
{
"path": "npc.milo.active_hp",
"old": 98,
"new": 52
}
],
"clamped": [],
"rejected": [
{
"path": "flags.type_advantage_used",
"reason": "unknown flag",
"fix": "There is no flag `type_advantage_used`. The flags are: `sandstorm_active`."
}
]
}
},
{
"branch": 0,
"depth": 3,
"live": true,
"type": "do",
"text": "> You Wartortle hits Graveler with everything it has left, a point-blank Hydro Pump to finish it.",
"createdAt": "2026-08-28T12:25:21.664571",
"stateAfter": {},
"worldStateAfter": {
"world": {
"round": 1,
"turn": 1
},
"player": {
"potions": 3,
"active_pokemon": "Wartortle"
},
"npc": {
"pidgeotto": {
"hp": 84,
"status": "none"
},
"ivysaur": {
"hp": 96,
"status": "none"
},
"wartortle": {
"hp": 84,
"status": "none"
},
"machoke": {
"hp": 104,
"status": "none"
},
"pikachu": {
"hp": 76,
"status": "none"
},
"milo": {
"active_pokemon": "Graveler",
"active_hp": 52,
"active_status": "none",
"pokemon_fainted": 0
}
},
"milestones": {},
"flags": {
"sandstorm_active": false
},
"_meta": {
"last_changed": {
"world.turn": 2,
"player.active_pokemon": 2,
"npc.wartortle.hp": 2,
"npc.milo.active_hp": 2
}
}
}
},
{
"branch": 0,
"depth": 4,
"live": true,
"type": "ai",
"text": "Wartortle plants its stubby legs against the cracked stone, shell rattling as it draws breath for the biggest attack it has. \"Finish it — Hydro Pump!\" you shout.\n\nThe blast that follows isn't a stream, it's a cannon — a roaring column of pressurized water that closes the gap before Graveler can even brace. It catches the rock-type square in the chest and drives it backward across the broken terrain, gouging a furrow through the stone floor. Graveler's arms windmill once, twice, searching for purchase that isn't there, and then it simply goes down, crashing onto its back in a spreading puddle, swirl-eyed and still.\n\nMilo's jaw tightens, but he's already reaching for his second ball. \"Didn't want to see that either. Fine — you earned that one.\" He hurls it out. \"Onix, let's go!\"\n\nThe ground itself seems to shudder as Onix erupts from the earth in a towering column of jointed rock, easily three stories high, boulder head swinging around to fix its small eyes on Wartortle. Dust and loose gravel rain down from the impact of its arrival, pattering off your shoulders even from across the field.\n\n\"Rock/Ground,\" you murmur to yourself, but Wartortle doesn't flinch — Water still chews through that typing just as easily, and the referee's flag is already dropping to signal the next exchange.\n\nWartortle shakes water from its shell, tired from the Hydro Pump but still standing tall, eyeing the massive serpent of stone now looming over it.",
"createdAt": "2026-08-28T12:25:34.346927",
"stateAfter": {},
"worldStateAfter": {
"world": {
"round": 1,
"turn": 2
},
"player": {
"potions": 3,
"active_pokemon": "Wartortle"
},
"npc": {
"pidgeotto": {
"hp": 84,
"status": "none"
},
"ivysaur": {
"hp": 96,
"status": "none"
},
"wartortle": {
"hp": 84,
"status": "none"
},
"machoke": {
"hp": 104,
"status": "none"
},
"pikachu": {
"hp": 76,
"status": "none"
},
"milo": {
"active_pokemon": "Onix",
"active_hp": 90,
"active_status": "none",
"pokemon_fainted": 1
}
},
"milestones": {
"graveler_defeated": {
"reached": true,
"at": 4
}
},
"flags": {
"sandstorm_active": false
},
"_meta": {
"last_changed": {
"world.turn": 4,
"player.active_pokemon": 2,
"npc.wartortle.hp": 2,
"npc.milo.active_hp": 4,
"npc.milo.pokemon_fainted": 4,
"npc.milo.active_pokemon": 4
}
}
},
"worldDelta": {
"delta": {
"world.turn": 1,
"npc.milo.active_hp": -52,
"npc.milo.pokemon_fainted": 1,
"npc.milo.active_pokemon": "Onix",
"npc.milo.active_status": "none",
"milestones.graveler_defeated": true
},
"applied": [
{
"path": "world.turn",
"old": 1,
"new": 2
},
{
"path": "npc.milo.active_hp",
"old": 52,
"new": 0
},
{
"path": "npc.milo.pokemon_fainted",
"old": 0,
"new": 1
},
{
"path": "npc.milo.active_pokemon",
"old": "Graveler",
"new": "Onix"
},
{
"path": "milestones.graveler_defeated",
"old": false,
"new": true
}
],
"clamped": [],
"rejected": []
}
}
]
}