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 killed 5 rats and went to turn in, but the quest said not complete.
Assistant
I’ll trace the rat spawn and quest completion paths first, then make the smallest code change that fixes both early-level density and kill credit.
Assistant
The worktree already has unrelated local changes in .gitignore and tools/lighting-engine-work.html; I’ll leave those alone. I found dedicated rat quest tests, so I’m narrowing on that path now.
Assistant
The rat quest has two separate mechanisms: explicit quest seeding on depth 1, and kill credit from DeathApplied. I’m checking whether real combat deaths still have rat identity available at the time the scheduled quest system runs.
Assistant
There’s a likely bug: DeathApplied already records targetKind, but the rat quest ignores it and re-reads NamedIdentity from the dead entity. If cleanup or transformation wins that race, five real rat kills won’t necessarily count. I’m going to make kill credit use the death record’s identity snapshot, with a test that reproduces that race.
Assistant
For “more rats on earlier levels,” the normal encounter picker is weighted by monster weight. Rat currently uses the default weight. I’m checking the table code so I can bias only shallow floors instead of globally flooding later levels.
Assistant
I’m making two scoped changes now: rat kill credit will trust the canonical death record’s targetKind, and depth 1-3 monster picks will weight rats higher while leaving the rest of the tier pool available.
Assistant
The picker change consumes rng.next() for weighted selection instead of rng.choice(), so I’m checking the resulting rat distribution before locking in the assertion.
Assistant
That exposed an important detail: rats are tagged overworld, and the dungeon picker treats any overworld tag as overworld-only, so normal dungeon generation currently never picks rats. I’m checking other uses of that tag before changing it.
Assistant
Overworld creature placement does not need the rat’s overworld tag; it explicitly asks for rat by id. I’m removing that tag from rats so they can appear in the dungeon pool, then the shallow weighting will actually take effect.
Assistant
One existing test forces a bat rare-upgrade with a fake RNG; the weighted picker now needs that test to filter to bat explicitly. I’m updating that fixture and adding focused coverage for the rat distribution and death snapshot behavior.
Assistant
The code changes and tests are in place. I’m running the focused quest, population, and overworld creature tests now because these cover the changed selection and tag behavior.
Assistant
The focused quest tests pass. One population test had a brittle exact RNG expectation for the old unweighted pool; the behavior is still valid but now the first eligible shallow spawner can be rat, which is the point of this change. I’m updating that stale expectation to assert eligible shallow content instead of a single identity.
Assistant
The shallow spawner with an all-zero RNG now resolves through the rat path and its rare upgrade, so the old “dragon_whelp” assertion was tied to array order. I’m replacing it with the same whitelist invariant used by the broader spawner tests.
Assistant
I’ve adjusted the stale exact assertion. I’m rerunning the same focused suites, then I’ll run the architecture/event guard that’s relevant to the touched quest listener file.
Assistant
Because I touched ratInfestation.js, the project rule requires its listener installer to use the canonical extension API. I’m migrating that installer now so the quest fix doesn’t leave a touched-file architecture violation.
Assistant
The listener installer now uses defineExtension and world.install. I’m rerunning the focused tests plus the event guard to catch doctrine regressions.
Assistant
Focused suites and event guard are green. I’m running the project check task as the final guardrail pass for architecture and event doctrine.
Assistant
deno task check is green. I’m doing a final diff/status pass so I can summarize exactly what changed and confirm I didn’t touch the unrelated local files.
Assistant
Implemented both fixes.
Changed:
Rats are now eligible for normal dungeon spawning again by removing the overworld tag from animals.js.
Early dungeon monster selection now weights rats higher on depths 1-3 in tables.js.
Rat quest kill credit now uses DeathApplied.targetKind as the canonical death snapshot, so kills still count even if the dead entity identity is gone by the time the quest system runs in ratInfestation.js.
Migrated the touched rat quest listener installer to defineExtension(...) / world.install(...).
Added regression tests for early rat weighting and death-record-based quest credit.
Verification passed:
deno test --allow-read tests/ratQuestProgress.test.mjs tests/ratInfestationQuestSpawn.test.mjs
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: