AGENTS.md instructions for /home/pjensen/Repos/JSHack
--- project-doc ---
AGENTS.md - JSHack Field Manual
JSHack is a zero-dependency browser roguelike: pure JavaScript, pure ES modules,
ECS architecture, Deno tooling. This file is optimized for coding agents. Prefer
the commands below over manual spelunking.
Deeper docs:
README.md
SEPARATION_MANIFEST.md
RUNTIME_TOPOLOGY_DOCTRINE.md
TEN_COMMANDMENTS.md
ecs-js/AGENTS.md
Hard Laws
No build step. Pure ES modules. No webpack, babel, JSX, TypeScript, or
bundling.
Deno, not Node. Tests and tools run with Deno. Default test command:
deno test --allow-read.
JavaScript only. Keep source as .js / .mjs.
Mobile-first. Touch is primary; desktop keyboard is secondary.
Separation is law.rules/ never imports display/ or bridge/;
display/ never imports rules/; bridge/ projects read-only rule state.
No system-to-system calls. Systems communicate with world.emit /
world.on; scheduler owns ordering.
New events use concrete event classes. Any new event contract must define
a concrete EcsEvent class and emit an instance with
world.emit(new Event(...)). Do not introduce string-only events or parallel
string re-emits for new contracts.
Touched listener installers use canonical extensions. Any new listener
installer, or any existing listener installer touched during a task, must use
defineExtension(...) and world.install(...) for idempotent installation.
Do not add new bespoke symbol-guard installers.
No swallowed event failures. Do not add emitSafe-style wrappers around
world.emit.
I'm torn between a new type of interactable that represents a "RuneStone" -- tricky since it overlaps very heavily with the mechanics of a shrine.
It may be that I want to severely boost the capabilities of a shrine -- when exposed to the sun / moonlight in overworld especially
I was to make a special type of interactable object that has some interesting properties.
it has the following glyph: ᚱ (this aspect is especially optional) -- if we decde to re-use shrine itself.
behavior
when interacted with (on a long, days long cooldown): it gives you an interesting status effect -- each are kind of interesting, boosted critical strike % for a day, immune to poision damage for a day, this whole class of things, Ideally we'd make them scripted.
but I've not gone so far as doing content authoring for interactables to make it so clean.
I'm conflicted.
Assistant
I’ll use the using-entire skill here because this is an architecture/design question about how JSHack’s existing interaction patterns should steer the feature.
Assistant
I’m going to narrow this to how shrines are actually represented today: content IDs, interaction payloads, shrine systems, and status application. That should tell us whether “RuneStone” wants to be a new kind or a shrine variant.
Assistant
The current interaction layer is already centralized around Interactable.action entries, which matters: a RuneStone does not require a new dispatch mechanism. I’m checking the shrine payload and placement/archetype shape next, because that is where the overlap will become concrete.
Assistant
One important finding: touchShrine currently only emits a touch event. The “answering deity / cooldown” behavior appears to live elsewhere, so I’m tracing that rather than assuming the shrine action itself owns it.
Assistant
There is checkpoint coverage on the relevant files. I’m going to read the interaction/reputation checkpoint enough to separate recorded intent from my own inference.
Assistant
The checkpoint metadata is present, but this lookup isn’t exposing a narrative transcript, so I’ll label the architecture claims from here as code-inferred. The code path itself is clear enough for a concrete recommendation.
Assistant
There is already a good substrate for “interesting day-long statuses”: applyStatusEffect creates topology-backed timed effects and mirrors to ActiveEffects; poison resistance already works via resist_poison, and critical chance can be modeled as a stat_envelope over critChance.
Assistant
A correction to the initial read: stat_envelope exists, but it is currently special-cased around things like vision, not a general “temporary derived stat” mechanism for crit. So poison immunity is easy today; crit chance either needs a temporary stat-effect hook or should be represented as lucky/blessed until that exists.
Assistant
The derived stat pipeline has the right answer for critical bonuses: a temporary child entity with DerivedExpression, tied to an expiring effect via meta.exprEntityId. That matches the repo’s “runtime multiplicity is child entities” direction better than inventing a second buff table.
Assistant
I’d make RuneStone a new interactable, not a shrine replacement.
The reason: shrine already means “deity communion.” Its path is touchShrine -> shrine:touch -> deitySystem, with prayer ledger effects, deity favor/protect actions, shrine:communion, lighting, audio, and fluorite behavior. Reusing that for RuneStone would blur “divine relationship” with “world magic / celestial inscription.”
Best shape:
Add RuneStone as a room/overworld feature with and optional glyph .
User
do it
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
No new world-attached state. Do not attach simulation state to world
with symbol or property keys (world[...], ctx.world[...]). Use ECS
components for state; when the state is genuinely world-scoped, model it as an
explicit singleton entity/component and document the allowance. Existing
world-attached state is a ratcheted architecture debt tracked by
ratchets/worldStateAttachmentRatchet.test.mjs.
Determinism is sacred. In rules simulation use world.rand(), never
Math.random(). No timers/fetch/promises/async in systems.
Integer grid only. World coords may be negative. Do not clamp to >= 0;
normalize with Number.isFinite(v) ? (v | 0) : fallback.
One canonical path. Spawn, damage, spell cast, status application,
inventory transfer, and materialization paths must delegate to the canonical
implementation.
Runtime multiplicity is child entities. Runtime
effects/procs/sockets/enchantments are child topology, not arrays on parent
components.
ECS-js is vendored. Do not edit src/lib/ecs-js/ unless fixing the ECS
library itself.
Authoring discipline. Do not touch unrelated code. Do not make changes
that do nothing. Always match the formatting preferences that already exist;
be a chameleon.
Search before writing. Extend existing patterns. Do exactly what was
asked; no opportunistic content wiring or unrelated cleanup.
Agent Commands
Run these before guessing.
Guardrail Tasks
Prefer these Deno tasks over hand-assembled command strings:
deno run --allow-read tools/agent-health.mjs
deno run --allow-read tools/import-boundary-report.mjs
deno run --allow-read tools/system-map.mjs
agent-health summarizes boundary violations, remaining emitSafe refs,
nondeterminism hazards, generation-time async allowances, system counts, and
possible system-to-system calls. Classified allowances are context for agents;
headline hazards are the things to investigate first.
Event Bus
bash
deno run --allow-read tools/event-bus-explorer.mjs --format summary --top 40
deno run --allow-read tools/event-bus-explorer.mjs --format csv --event damaged
deno run --allow-read tools/event-bus-explorer.mjs --format mermaid --event damaged
deno run --allow-read tools/event-bus-explorer.mjs --producer-only --format summary --top 40
deno run --allow-read tools/event-bus-explorer.mjs --consumer-only --format summary --top 40
Use producer-only events to find emitted behavior with no consumer. Use
consumer-only events to find stale listeners, dynamic producers, or missing
producers.
System Map
bash
deno run --allow-read tools/system-map.mjs --format summary
deno run --allow-read tools/system-map.mjs --format csv
deno run --allow-read tools/system-map.mjs --phase effects
deno run --allow-read tools/system-map.mjs --unregistered
deno run --allow-read tools/system-map.mjs --missing-tests
Scheduler truth lives in src/main/scheduler.js. Some
imported-not-registered files are listener installers, not phase systems; audit
before deleting.
Target Lookup
bash
deno run --allow-read tools/agent-target.mjs damaged --limit 80
deno run --allow-read tools/content-id-audit.mjs goblin --limit 80
deno run --allow-read tools/content-id-audit.mjs potion_water --limit 80
agent-target is a ranked code search for events/functions/files/tests.
content-id-audit follows item, monster, spell, material, loot, visual, and
test references by ID.
Focused Tests
bash
deno test --allow-read tests/separationBoundaries.test.mjs
deno test --allow-read tests/determinismArchitectureGuards.test.mjs
deno test --allow-read tests/schedulerArchitectureGuards.test.mjs
deno test --allow-read tests/dealDamage.test.mjs
deno test --allow-read tests/castSpell.test.mjs
deno test --allow-read tests/interaction.test.mjs
deno test --allow-read tests/movementRefactored.test.mjs
deno test --allow-read tests/contentCatalogCanonical.test.mjs
Full runtime suite:
bash
deno test --allow-read --no-check
Plain deno test --allow-read may fail during type-check on non-game packaging
scripts before tests run. Use --no-check when you need runtime coverage.
rules/ deterministic simulation; no DOM, display, timers, async systems
bridge/ read-only projection from rules state to WorldView DTOs
display/ presentation only; reads WorldView and main-provided contracts
main/ wiring, lifecycle, input dispatch, scheduler setup
shared/ pure math/grid utilities; no ECS or DOM
lib/ vendored ecs-js and deity-js
content/ DSL-authored content definitions and content helpers
Five scheduler phases are declared in
src/main/scheduler.js:
text
ai intent producers
intents movement/combat/use/cast/interaction consumers
effects per-turn derived effects and world simulation
scripts content DSL tick hooks
cleanup entity removal, lifespan, spatial sync
The bridge contract is
src/bridge/schema/worldView.js. Display must
not push tags onto entity records; tag projection belongs in the bridge.
Install listeners with world.install(featureListeners) from configureWorld()
unless the feature is display/main wiring.
New Systems
Add src/rules/systems/mySystem.js.
Register it in src/main/scheduler.js in the right
phase.
Add a focused test in tests/.
Run deno test --allow-read tests/mySystem.test.mjs.
Spatial Queries
Use forEachInRadius, forEachInRect, or tile query helpers. Do not full-scan
world.query() for proximity-sensitive behavior.
Spawning
Route through canonical archetypes/materialization helpers. Debug spawns,
dungeon population, and spawner children must have parity tests if they differ.
Events
New event contracts must be concrete EcsEvent classes:
No new world[...] / ctx.world[...] simulation state; use ECS
components or an explicit singleton component.
No direct system-to-system calls.
No illegal layer imports.
New or touched listeners use defineExtension(...) and
world.install(...).
New systems are registered and tested.
Spawn paths use canonical constructors/materializers.
Event wiring checked with tools/event-bus-explorer.mjs.
Agent health checked with tools/agent-health.mjs.
NamedIdentity.identity = "runestone"
ᚱ
Give it Interactable.action = "touchRunestone", separate from touchShrine.
Store cooldown as component state, probably in Interactable.params for a first pass, or a small RunestoneState component if it grows.
Define rune effects as data:
effectKey, turnsLeft, potency, optional derivedExpression.
On interact, apply a topology-backed timed effect via applyStatusEffect.
For crit boosts, create a temporary child DerivedExpression and link it through the effect’s meta.exprEntityId, since the derived stat system already cleans those up when effects expire.
Use TURNS_PER_DAY = 720, so “one day” is 720 turns and “several days cooldown” can be 3 * TURNS_PER_DAY, etc.
Relevant current anchors:
Shrine archetype/action: RoomFeatures.js
Shrine interaction payload: interactPayloads.js
Shrine deity behavior/cooldown: deitySystem.js
Time constant: calendar.js
I’d only “boost shrine” if the fantasy is explicitly divine shrine under celestial exposure. If the fantasy is “ancient stone gives a strange long-duration boon,” RuneStone deserves its own identity and can still share sacred visual/audio treatment later.