Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
A direct command skips the review prompt. Inspect the source before running it.
classWorld:
"""Adventure runtime context for Python."""def__init__(self, adventure_data: dict):
# Standard keysself.turn = 0self.timestamp = Noneself.adventure = adventure_data
self.player = adventure_data.get('player', {})
self.room = Noneself.party = adventure_data.get('party', {})
# Extended keys (set contextually)self.object = None# During object simulationself.target = None# During targeted actionself.npc = None# During NPC simulation# Skill state namespacesself.skills = DotDict() # world.skills.economy.gold# INVENTORYdefhas(self, item_id: str) -> bool:
return item_id inself.player.get('inventory', [])
defhas_tag(self, tag: str) -> bool:
"""Check if player has any item with the given tag."""for item_id inself.player.get('inventory', []):
item = self.get_object(item_id)
if item and tag in item.get('tags', []):
returnTruereturnFalsedeffind_by_tag(self, tag: str, in_room: bool = True) -> list:
"""Find all objects with the given tag."""
results = []
# Check inventoryfor item_id inself.player.get('inventory', []):
item = self.get_object(item_id)
if item and tag in item.get('tags', []):
results.append(item)
# Check current roomif in_room andself.room:
for obj inself.room.get('objects', []):
if tag in obj.get('tags', []):
results.append(obj)
return results
defgive(self, item_id: str):
inv = self.player.setdefault('inventory', [])
inv.append(item_id)
deftake(self, item_id: str):
inv = self.player.get('inventory', [])
if item_id in inv:
inv.remove(item_id)
# FLAGSdefflag(self, name: str) -> bool:
returnself.adventure.get('flags', {}).get(name, False)
defset_flag(self, name: str, value: bool):
flags = self.adventure.setdefault('flags', {})
flags[name] = value
# NARRATIVEdefemit(self, message: str):
self._output_queue.append(message)
defnarrate(self, message: str, style: str = "normal"):
self._output_queue.append({'text': message, 'style': style})
# EVENTSdeftrigger_event(self, name: str, data: dict = None):
self._event_queue.append({'name': name, 'data': data or {}})
# NAVIGATIONdefgo(self, destination: str):
self._pending_navigation = destination
defcan_go(self, direction: str) -> bool:
exits = self.room.get('exits', {})
return direction in exits
# BUFFSdefhas_buff(self, buff_id: str) -> bool:
buffs = self.player.get('buffs', [])
returnany(b.get('id') == buff_id for b in buffs)
defadd_buff(self, buff: dict):
buffs = self.player.setdefault('buffs', [])
buffs.append(buff)
defremove_buff(self, buff_id: str):
buffs = self.player.get('buffs', [])
self.player['buffs'] = [b for b in buffs if b.get('id') != buff_id]
# EFFECTIVE VALUES (Buff Modification Protocol)## Base value = persistent truth# Effective value = recalculated each tick## "The base value is truth. The effective value is reality."#defreset_effective(self, obj: dict = None):
"""
Reset all effective values to their base values.
Called at the start of each tick.
"""
obj = obj orself.objectifnot obj or'state'notin obj:
return
state = obj['state']
for key inlist(state.keys()):
ifnot key.endswith('_effective'):
effective_key = f"{key}_effective"
state[effective_key] = state[key]
defget_effective(self, obj: dict, prop: str):
"""Get effective value, falling back to base if not set."""
state = obj.get('state', {})
effective_key = f"{prop}_effective"if effective_key in state:
return state[effective_key]
return state.get(prop)
defmodify_effective(self, obj: dict, prop: str, delta):
"""Add delta to effective value."""
state = obj.get('state', {})
effective_key = f"{prop}_effective"
state[effective_key] = state.get(effective_key, state.get(prop, 0)) + delta
defmultiply_effective(self, obj: dict, prop: str, factor: float):
"""Multiply effective value by factor."""
state = obj.get('state', {})
effective_key = f"{prop}_effective"
state[effective_key] = state.get(effective_key, state.get(prop, 0)) * factor
# RESILIENCE (SimCity Zone Pattern)## WILL WRIGHT: "If one tile burns but the center survives,# the zone will eventually rebuild."#defensure_defaults(self, obj: dict = None) -> dict:
"""
Ensure object has its default state values.
Self-initializing: creates state if missing.
Self-healing: clamps invalid values.
"""
obj = obj orself.objectifnot obj:
return {}
# Create state if missingif'state'notin obj:
obj['state'] = {}
# Merge defaults
defaults = obj.get('defaults', {})
for key, default_val in defaults.items():
if key notin obj['state']:
obj['state'][key] = default_val
return obj['state']
defheal_state(self, obj: dict = None):
"""
Fix inconsistent state values.
- Clamp negative numbers to 0
- Fix logical inconsistencies
"""
state = self.ensure_defaults(obj)
# Clamp numeric values to non-negativefor key, val inlist(state.items()):
ifisinstance(val, (int, float)) and val < 0:
state[key] = 0return state
# STATE ACCESSdefget(self, path: str):
"""Get value by dot path: world.get('object.state.fuel')"""
parts = path.split('.')
obj = selffor part in parts:
ifisinstance(obj, dict):
obj = obj.get(part)
else:
obj = getattr(obj, part, None)
if obj isNone:
returnNonereturn obj
defset(self, path: str, value):
"""Set value by dot path: world.set('object.state.lit', True)"""
parts = path.split('.')
obj = selffor part in parts[:-1]:
ifisinstance(obj, dict):
obj = obj.setdefault(part, {})
else:
obj = getattr(obj, part)
ifisinstance(obj, dict):
obj[parts[-1]] = value
else:
setattr(obj, parts[-1], value)
JavaScript
classWorld {
/** Adventure runtime context for JavaScript. */constructor(adventureData) {
// Standard keysthis.turn = 0;
this.timestamp = null;
this.adventure = adventureData;
this.player = adventureData.player || {};
this.room = null;
this.party = adventureData.party || {};
// Extended keys (set contextually)this.object = null; // During object simulationthis.target = null; // During targeted actionthis.npc = null; // During NPC simulation// Skill state namespacesthis.skills = {}; // world.skills.economy.gold// Internal queuesthis._outputQueue = [];
this._eventQueue = [];
this._pendingNavigation = null;
}
// === INVENTORY ===has(itemId) {
return (this.player.inventory || []).includes(itemId);
}
hasTag(tag) {
/** Check if player has any item with the given tag. */for (const itemId ofthis.player.inventory || []) {
const item = this.getObject(itemId);
if (item && (item.tags || []).includes(tag)) {
returntrue;
}
}
returnfalse;
}
findByTag(tag, inRoom = true) {
/** Find all objects with the given tag. */const results = [];
// Check inventoryfor (const itemId ofthis.player.inventory || []) {
const item = this.getObject(itemId);
if (item && (item.tags || []).includes(tag)) {
results.push(item);
}
}
// Check current roomif (inRoom && this.room) {
for (const obj ofthis.room.objects || []) {
if ((obj.tags || []).includes(tag)) {
results.push(obj);
}
}
}
return results;
}
give(itemId) {
this.player.inventory = this.player.inventory || [];
this.player.inventory.push(itemId);
}
take(itemId) {
const inv = this.player.inventory || [];
const idx = inv.indexOf(itemId);
if (idx > -1) inv.splice(idx, 1);
}
// === FLAGS ===flag(name) {
return (this.adventure.flags || {})[name] || false;
}
setFlag(name, value) {
this.adventure.flags = this.adventure.flags || {};
this.adventure.flags[name] = value;
}
// === NARRATIVE ===emit(message) {
this._outputQueue.push(message);
}
narrate(message, style = "normal") {
this._outputQueue.push({ text: message, style });
}
// === EVENTS ===triggerEvent(name, data = {}) {
this._eventQueue.push({ name, data });
}
// === NAVIGATION ===go(destination) {
this._pendingNavigation = destination;
}
canGo(direction) {
const exits = this.room?.exits || {};
return direction in exits;
}
// === BUFFS ===hasBuff(buffId) {
const buffs = this.player.buffs || [];
return buffs.some(b => b.id === buffId);
}
addBuff(buff) {
this.player.buffs = this.player.buffs || [];
this.player.buffs.push(buff);
}
removeBuff(buffId) {
const buffs = this.player.buffs || [];
this.player.buffs = buffs.filter(b => b.id !== buffId);
}
// === EFFECTIVE VALUES (Buff Modification Protocol) ===//// Base value = persistent truth// Effective value = recalculated each tick//// "The base value is truth. The effective value is reality."//resetEffective(obj = null) {
/**
* Reset all effective values to their base values.
* Called at the start of each tick.
*/
obj = obj || this.object;
if (!obj || !obj.state) return;
const state = obj.state;
for (const key ofObject.keys(state)) {
if (!key.endsWith('_effective')) {
const effectiveKey = `${key}_effective`;
state[effectiveKey] = state[key];
}
}
}
getEffective(obj, prop) {
/** Get effective value, falling back to base if not set. */const state = obj.state || {};
const effectiveKey = `${prop}_effective`;
if (effectiveKey in state) {
return state[effectiveKey];
}
return state[prop];
}
modifyEffective(obj, prop, delta) {
/** Add delta to effective value. */const state = obj.state || {};
const effectiveKey = `${prop}_effective`;
state[effectiveKey] = (state[effectiveKey] ?? state[prop] ?? 0) + delta;
}
multiplyEffective(obj, prop, factor) {
/** Multiply effective value by factor. */const state = obj.state || {};
const effectiveKey = `${prop}_effective`;
state[effectiveKey] = (state[effectiveKey] ?? state[prop] ?? 0) * factor;
}
// === RESILIENCE (SimCity Zone Pattern) ===//// WILL WRIGHT: "If one tile burns but the center survives,// the zone will eventually rebuild."//ensureDefaults(obj = null) {
/**
* Ensure object has its default state values.
* Self-initializing: creates state if missing.
* Self-healing: clamps invalid values.
*/
obj = obj || this.object;
if (!obj) return {};
// Create state if missing
obj.state = obj.state || {};
// Merge defaultsconst defaults = obj.defaults || {};
for (const [key, defaultVal] ofObject.entries(defaults)) {
if (!(key in obj.state)) {
obj.state[key] = defaultVal;
}
}
return obj.state;
}
healState(obj = null) {
/**
* Fix inconsistent state values.
* - Clamp negative numbers to 0
* - Fix logical inconsistencies
*/const state = this.ensureDefaults(obj);
// Clamp numeric values to non-negativefor (const [key, val] ofObject.entries(state)) {
if (typeof val === 'number' && val < 0) {
state[key] = 0;
}
}
return state;
}
// === STATE ACCESS ===get(path) {
const parts = path.split('.');
let obj = this;
for (const part of parts) {
obj = obj?.[part];
if (obj === undefined) returnundefined;
}
return obj;
}
set(path, value) {
const parts = path.split('.');
let obj = this;
for (const part of parts.slice(0, -1)) {
obj[part] = obj[part] || {};
obj = obj[part];
}
obj[parts[parts.length - 1]] = value;
}
}
Compiled Expression Format
Natural language compiles to BOTH targets:
# Sourceguard:"player has brass-key AND room is not dark"# Generated (BOTH always!)guard_js:(world)=>world.has("brass-key")&&!world.room.is_darkguard_py: lambda world:world.has("brass-key")andnotworld.room.is_dark
Both runtimes implement the same simulation loop with effective value phases:
# Simulation tick phasessimulation_tick:-phase:1.RESETaction:"foo_effective = foo (reset to base)"-phase:2.BUFFSaction:"Apply buff modifiers to _effective values"-phase:3.SIMULATEaction:"Objects run simulate(), modify _effective"-phase:4.MAILaction:"Deliver queued messages (deterministic!)"-phase:5.EVENTSaction:"Process event queue"-phase:6.NAVIGATEaction:"Move player if requested"-phase:7.DISPLAYaction:"UI shows _effective with base comparison"
Phase 4: MAIL — Deterministic Message Delivery
Messages are queued during simulation, then delivered deterministically:
# PHASE 4: Deliver mail (no LLM needed!)for message in world.skills.postal.get('outgoing', []):
routing = message.get('routing')
# Transfer attachmentsfor transfer in routing.get('attachments_transfer', []):
if transfer['action'] == 'send':
move_item(world, transfer['ref'],
from_path=transfer['from_inventory'],
to_path=transfer['to_inventory'])
# Deliver to inboxif routing['delivery_point'] == 'inbox':
add_to_inbox(world, routing['inbox_path'], message)
# Update status
message['status'] = 'delivered'
message['delivered'] = world.timestamp
# Trigger events (goal completion, etc)for trigger in routing.get('triggers', []):
world.trigger_event(trigger['event'], trigger['data'])
world.skills.postal['outgoing'] = []