Commit Graph

53 Commits

Author SHA1 Message Date
Steve Biedermann ac5a40af37 dev: cache Docker dependencies with cargo-chef
Cook native and Wasm dependencies in reusable Docker layers. Let the frontend build script use the cooked Wasm target directory while preserving local build defaults.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-10-21 20:11:55 +02:00
Steve Biedermann 2305660d5a fix: exit shards when simulation threads fail
Supervise the shard simulation thread and exit with status 1 when it panics or stops, allowing the container restart policy to recover instead of leaving a live control server with no simulation. Cover startup panics and actor-reply timeouts with subprocess regression tests, and document recovery behavior.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-10-21 20:00:05 +02:00
Steve Biedermann 6124dc1001 test: speed up weekly village survival check
Co-Authored-By: GitHub Copilot <noreply@github.com>
2026-10-13 19:22:39 +02:00
Steve Biedermann e5dc752b41 test: use nextest and shorten weekly survival test
Co-Authored-By: GitHub Copilot <noreply@github.com>
2026-10-13 19:12:55 +02:00
Steve Biedermann db23f87450 update agents file 2026-10-13 19:11:19 +02:00
Steve Biedermann f4e3ef4045 feat(admin): persist generated admin password
Co-Authored-By: GitHub Copilot <noreply@github.com>
2026-10-13 18:45:47 +02:00
Steve Biedermann 4ae5d40bea chore(compose): build before restarting services
Co-Authored-By: GitHub Copilot <noreply@github.com>
2026-10-13 17:59:17 +02:00
Steve Biedermann 71b3e44e8a feat(ui): add simulation about dialog
Co-Authored-By: GitHub Copilot <noreply@github.com>
2026-10-13 17:57:17 +02:00
Steve Biedermann 7aebac994b fix(compose): invoke shard mode through sim binary
Co-Authored-By: GitHub Copilot <noreply@github.com>
2026-10-13 17:24:59 +02:00
Steve Biedermann cdcbae4c05 feat(compose): run sqlite shards in separate containers
Co-Authored-By: GitHub Copilot <noreply@github.com>
2026-10-13 17:18:15 +02:00
Steve Biedermann bf0cb7d0c7 fix(access): recognize localhost through Compose
Co-Authored-By: GitHub Copilot <noreply@github.com>
2026-10-13 17:07:26 +02:00
Steve Biedermann 0332783a78 fix(access): restrict public clients to read-only
Co-Authored-By: GitHub Copilot <noreply@github.com>
2026-10-13 16:46:00 +02:00
Steve Biedermann a9055b8218 feat(cluster): route entity messages by actor path
Co-Authored-By: GitHub Copilot <noreply@github.com>
2026-10-13 16:33:23 +02:00
Steve Biedermann 0ffb5dadb1 dev: add cpu limit to compose.yml 2026-10-12 21:56:32 +02:00
Steve Biedermann 2bb369fc88 feat(ui): zoom with the wheel, pan with the middle button
The map canvas now fills its panel and draws through a view transform,
so it stays sharp at every zoom level. The wheel zooms around the
pointer, dragging with the middle button pans, and right click clears
the selection. The wheel listener is attached natively and non-passive
because Leptos delegates `wheel` to the document, where browsers ignore
`preventDefault`.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-10-12 21:02:35 +02:00
Steve Biedermann ec861de3ba docs: document the shard cluster, economy and per-shard databases
Describe the gateway and shard processes, transparent transfers, the
economy and console peers in the README. Compose creates one Postgres
database per shard and passes `SHARD_DATABASE_URL` and `SIM_SHARDS`;
the Justfile and Dockerfile use per-shard SQLite files.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-10-12 20:43:11 +02:00
Steve Biedermann 00ea5899c1 feat(ui): show markets, workplaces, carts, crops and shard borders
The map draws markets, workplaces coloured by trade, carts, merchants,
crop fields that turn gold when ripe, every home and dashed shard
borders. The side panel lists each person's job and coins and shows
economy and employment statistics. The server includes `crop_ripe` in
the state.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-10-12 20:42:11 +02:00
Steve Biedermann eac68db433 feat: run shards as separate processes behind a gateway
The server is now a gateway that starts SIM_SHARDS shard processes
(`sim shard --index I --count N ...`), each with its own database from
the SHARD_DATABASE_URL template. The gateway steps all shards in
lockstep over a /control WebSocket, publishes the entity directory and
market board between steps, merges the shards' views into one world
for the UI and routes edits to the shards they concern.

Shards send entity messages and transfers to each other directly over
/remote WebSockets; every step waits until its outgoing messages are
accepted, so nothing is in flight when the next step starts or a
snapshot is taken. Shard processes exit when the gateway goes away.

Update Picard to f88b9cb and register every other shard as a console
peer `shard-N`, so one console session can list, inspect, manage and
message the actors of all shards.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-10-12 20:29:11 +02:00
Steve Biedermann bdf819f721 feat: jobs, markets, haggling, carts and merchants
Each shard founds markets and workplaces (farms, woodcutters, quarries,
hunters, toolmakers, cartwrights). Adults are hired, commute to work,
sell their goods at the market, get paid and go home. Markets, workplaces
and carts are actors; prices follow local supply and demand and trades
are haggled. Merchants trade with markets on other shards through the
router, so they do not know whether a market is remote.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-10-12 20:10:22 +02:00
Steve Biedermann bc58855ff5 feat: shard-aware world with transparent actor transfers
Add a router that delivers actor messages locally or to the shard that
currently hosts the entity. People and animals that leave their shard's
columns depart with their full state, forward messages while in flight
and are re-admitted on the destination shard. Enlarge the default world.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-10-12 19:20:30 +02:00
Steve Biedermann 7e09e30e4e chore: enable picard remoting feature
Add tracing, tungstenite and uuid as workspace dependencies for the
upcoming shard cluster.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-10-12 18:46:40 +02:00
Steve Biedermann 0009206a3c refactor(world)!: make Picard actors own entity state
People, rabbits, wolves and partnerships are now Picard actors that own
their state and apply their own rules (ageing, hunger and meals,
starvation, energy, breeding costs, death, birth intervals). The world
no longer keeps mirrored Vecs that were read from and written back to
generic entity actors every step; it only reaches entities through
typed messages and replies, correlated by request id through a single
inbox actor.

World-level state (terrain, resources, stockpile, houses, calendar, the
world random stream) stays in the world, and behaviour decisions stay
on the simulation thread because the Rune VM is not Send. Replies are
processed in entity order and each person has its own persisted random
stream, so runs and snapshot restores stay deterministic.

Rabbits killed by hunters no longer move or breed later in the same
tick.

BREAKING CHANGE: Picard actors are named person-<id>, rabbit-<id>,
wolf-<id> and partnership-<id> instead of entity-<id>, which changes
the paths used with the actor console.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-10-12 16:47:44 +02:00
Steve Biedermann 21f66981fa chore: update picard to 054449c
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-10-12 16:25:51 +02:00
Steve Biedermann 3035b9f9f1 test: derive test expectations from config.rn values
The defaults in config.rn changed (90 initial people, fertile teens and
older adults), but the tests still hard-coded the previous 9-person
village. Tests now override Rune constants by name and compute expected
counts from the loaded configuration.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-10-12 16:25:51 +02:00
Steve Biedermann 549cd2c283 dev: update AGENTS.md 2026-10-12 13:47:04 +02:00
Steve Biedermann fd243b30d6 feat(actor-console): expose Picard over WebSocket
Update Picard and forward console/serde features, serialize actor messages, and route console requests through the simulation thread.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-10-12 12:43:05 +02:00
Steve Biedermann eb7f7122e5 rename AGENT.md to AGENTS.md 2026-10-12 10:41:49 +02:00
Steve Biedermann 028d5219c5 update defaults 2026-10-11 21:37:12 +02:00
Steve Biedermann 63c72f5df7 refactor(sim): resolve clippy pedantic lints
- Replace signed coordinate round-trips with checked offset helpers
- Use From/try_from conversions and clamp helpers in the edit parser
- Isolate exact RNG, noise and day-fraction float casts in documented helpers
- Split long functions (validate, world creation, apply, state_json, tick_person)
- Pass run_sim shared state by reference and tidy remaining style lints

Simulation behaviour and RNG sequences are unchanged.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-10-11 21:23:50 +02:00
Steve Biedermann 9fd93a8534 refactor(ui): resolve clippy pedantic lints
Replace lossy casts with checked tile/canvas helpers, use map_or_else and
infallible conversions, and switch the build script to assert!.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-10-11 21:23:50 +02:00
Steve Biedermann 5a1384cc21 refactor: resolve clippy lints
Collapse nested ifs, use is_multiple_of, pass the editor apply callback
directly, and make dropping the actor system shutdown future explicit so
`cargo clippy --workspace --all-targets -- -D warnings` passes.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-10-11 20:42:29 +02:00
Steve Biedermann 50087a6276 chore(compose): normalize formatting
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-10-11 20:42:29 +02:00
Steve Biedermann 9285df4d7b feat(sim)!: move simulation settings and behaviours into config.rn
Starting values and tuning constants are now `pub const` items in a
single Rune file, config.rn, alongside the `person`, `rabbit` and `wolf`
behaviour functions. The behaviours read the constants directly. At
startup the server loads the file from SIM_CONFIG (default: config.rn),
reads and checks every constant, and test-runs each behaviour, so a bad
or missing value stops startup with an error that names it.

- Map width and height can now be configured and are stored in
  snapshots.
- The UI's edit limits (max speed, stock, inventory, hunger, energy,
  resource amounts) come from the config.
- The in-browser script editor now edits config.rn. Applied edits update
  behaviours and tuning values immediately; map size, initial population
  and calendar defaults apply on reset.
- The Docker image includes config.rn, and Compose mounts the
  repository's copy read-only.
- Documents the config file and how it works in the README.

BREAKING CHANGE: src/behavior.rn has been removed; behaviours now live
in config.rn. The server will not start without a valid config file.
Snapshots no longer store the behaviour script: on restart, config.rn
from disk replaces any edits made in the browser editor.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-10-11 20:42:29 +02:00
Steve Biedermann 118d44ff29 docs: add agent contribution rules
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-10-11 20:42:29 +02:00
Steve Biedermann b6bab90503 feat(sim): expose Picard runtime stats and tracing
Enable Picard's stats and tracing features, publish actor counters to the UI, and initialize configurable tracing output.\n\nCo-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-10-11 18:58:07 +02:00
Steve Biedermann a4eb181154 fix(sim): prevent starvation before population can recover
Use terrain-aware pathfinding for travel toward home and resources so settlers do not get stranded against blocked terrain. Add a startup food reserve, slow hunger accumulation, let villagers return for food sooner, ensure available food is consumed before starvation, and make the first birth check available at the first weekly boundary.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-10-11 18:39:50 +02:00
Steve Biedermann 2220a6eb3c fix(ui): fall back to polling when websocket is unavailable
Poll the state endpoint while the WebSocket is not open so browsers that fail to establish the socket still receive initial state and continue updating the UI. Retain WebSocket streaming as the primary transport.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-10-11 18:28:47 +02:00
Steve Biedermann 52277ae779 fix(sim): improve population replacement rate
Raise starter settlement capacity above its initial population and allow eligible partnerships one birth opportunity per week instead of a 20% monthly roll. Preserve food and housing constraints and cover both initial growth and per-week births in tests.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-10-11 18:13:10 +02:00
Steve Biedermann 1e867b173c fix(sim): keep legacy villagers and newborns alive
Restore pre-life-cycle snapshots with working-age villagers and keep dependents near the shared food stock. Add regression coverage for legacy saves, child return-home behavior, and newborn placement.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-10-11 18:04:36 +02:00
Steve Biedermann a0f18df9ef feat(ui): expose life stages and fertility settings
Show each person's life stage, age, and partner in the inspector. Add per-stage fertility toggles and document the life cycle and birth conditions.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-10-11 17:48:35 +02:00
Steve Biedermann 2cb4d4e626 feat(sim): add human life stages and partnerships
Add stage progression through death, one-to-one partnership actors, and constrained births.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-10-11 17:48:26 +02:00
Steve Biedermann ca371bd414 feat(calendar): add configurable calendar and stage ranges
Persist calendar units and inclusive life-stage duration ranges, expose them in the UI, and preserve defaults when loading legacy snapshots. Date formatting now derives from calendar settings.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-10-11 17:38:57 +02:00
Steve Biedermann 81581132ad feat(sim): integrate Picard actors for living entities
Give people and animals persistent Picard actors and document runtime boundary.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-10-11 17:30:28 +02:00
Steve Biedermann 0fbe9d553d build: update Just workflows for Compose and SQLite development 2026-10-08 09:24:14 +02:00
Steve Biedermann d3a230bd47 docs: document setup and database options 2026-10-08 09:17:22 +02:00
Steve Biedermann 238de74f5b feat: add same-seed reset and world regeneration 2026-10-08 09:10:42 +02:00
Steve Biedermann c58c590b5d feat: add database persistence and Docker setup 2026-10-08 09:10:42 +02:00
Steve Biedermann 2daf8f30f2 build: bundle the Leptos UI during Cargo builds 2026-10-08 09:10:42 +02:00
Steve Biedermann ef47209c79 refactor: stream simulation state over WebSockets 2026-10-08 09:10:42 +02:00
Steve Biedermann e4a4cb0190 feat: build the frontend with Leptos and WebAssembly 2026-10-08 09:10:42 +02:00