674 lines
32 KiB
Markdown
674 lines
32 KiB
Markdown
# Adaptive Loop — Implementation Specification
|
|
|
|
## 1. Reader and required outcome
|
|
|
|
This specification is for the autonomous Pi parent and its implementation/review subagents.
|
|
|
|
After reading it, they must be able to build, verify, and freeze a complete browser game without requesting product decisions from the human or inventing incompatible rules.
|
|
|
|
The game is successful only when it is playable from campaign start through campaign victory, contains five distinct scenarios, has clear win and lose states, demonstrates interacting deterministic systems, restores exact persisted state, and passes automated plus black-box browser checks.
|
|
|
|
## 2. Product vision
|
|
|
|
**Adaptive Loop** is a calm deterministic strategy puzzle set in a fictional microfluidic culture dish.
|
|
|
|
The player rotates overlapping six-chamber loops. A rotation does two things at once:
|
|
|
|
1. It moves chamber payloads.
|
|
2. It changes which microfluidic loop owns shared chambers and therefore where nutrients and toxins flow.
|
|
|
|
The resulting tick resolves growth, feeding, migration, selective pressure, adaptation, and environmental fixtures in a fixed order. Species counter repeated strategies through visible adaptations. Every adaptation has a benefit, a cost, and ecological spillover. The player wins by provoking useful counter-adaptations, then exploiting their weaknesses.
|
|
|
|
The intended feeling is precise, quiet, and legible: a scientific instrument that has become a tactical game.
|
|
|
|
## 3. Hard scope
|
|
|
|
### Required
|
|
|
|
- Browser game, desktop-first, responsive down to 390 CSS pixels.
|
|
- TypeScript, HTML, CSS, SVG board.
|
|
- Five handcrafted scenarios in one campaign.
|
|
- Standalone replay for every unlocked scenario.
|
|
- Deterministic simulation with no runtime randomness.
|
|
- Pure state transition shared by preview and commit.
|
|
- Exact save/load and deterministic action replay.
|
|
- Win, ecosystem-collapse loss, turn-limit loss, retry, and campaign victory.
|
|
- Mouse, touch, and keyboard operation.
|
|
- Accessible labels, visible focus, non-color encodings, live status announcements, and reduced-motion support.
|
|
- Procedural SVG/CSS visuals only.
|
|
- Unit/behavior tests, scenario solver/replay tests, and black-box browser tests.
|
|
|
|
### Forbidden
|
|
|
|
- Backend, accounts, analytics, ads, netcode, or online dependency after install.
|
|
- Game engine.
|
|
- Downloaded art, music, fonts, or commercial assets.
|
|
- Random event deck or procedural board generation.
|
|
- Individual autonomous microbe agents.
|
|
- Continuous/floating-point population simulation.
|
|
- UI-owned game rules or separate preview logic.
|
|
- Bespoke simulation branch per named species when a data rule suffices.
|
|
- Purely beneficial permanent upgrades.
|
|
- Placeholder screens, claimed-but-unplayable mechanics, or demo-only content.
|
|
|
|
## 4. Board topology and legal actions
|
|
|
|
The board has twelve chamber slots and three overlapping six-slot loops:
|
|
|
|
```text
|
|
Loop A: [0, 1, 2, 3, 4, 5]
|
|
Loop B: [2, 3, 6, 7, 8, 9]
|
|
Loop C: [4, 5, 10, 11, 8, 9]
|
|
|
|
Loop arrays are listed in clockwise visual order. Clockwise rotation moves payload at array index `i` to `(i + 1) mod 6`. Counterclockwise rotation moves it to `(i + 5) mod 6`. For flow, “next” uses the same `+1` step for clockwise and `+5` step for counterclockwise.
|
|
```
|
|
|
|
Shared chamber pairs:
|
|
|
|
- A/B share 2 and 3.
|
|
- A/C share 4 and 5.
|
|
- B/C share 8 and 9.
|
|
|
|
Render these as three visibly interlocking hexagonal rings, not as a numbered debugging diagram.
|
|
|
|
There are exactly six gameplay actions:
|
|
|
|
- Rotate A clockwise.
|
|
- Rotate A counterclockwise.
|
|
- Rotate B clockwise.
|
|
- Rotate B counterclockwise.
|
|
- Rotate C clockwise.
|
|
- Rotate C counterclockwise.
|
|
|
|
No pass action exists.
|
|
|
|
A legal rotation:
|
|
|
|
1. Cyclically permutes the six movable chamber payloads along that loop by one position.
|
|
2. Does not move fixed fixtures or objective markers.
|
|
3. Sets that loop's flow direction to the chosen direction.
|
|
4. Assigns ownership of that loop's shared slots to the rotated loop.
|
|
|
|
Each shared slot stores one owning loop. Initial ownership is alphabetical among loops containing it. A slot's outlet is the next slot on its owning loop in that loop's current direction. A non-shared slot is owned by its only loop.
|
|
|
|
This ownership rule must materially change scenario solutions. The counterfactual proof uses normal payload permutation and loop-direction updates but freezes `sharedOwner` at the scenario baseline for every turn. At least one scenario must be solver-proven unwinnable under that counterfactual within its normal turn limit.
|
|
|
|
Actions in terminal states are rejected without changing domain state.
|
|
|
|
### Board layout (rendering)
|
|
|
|
Render the board as three **interlocking hexagonal rings**, never as a network of
|
|
connected spheres or a numbered wiring diagram. Each loop is a regular
|
|
six-sided hexagon (pointy-top), drawn as a stroked polygon with a distinct
|
|
per-loop color (A, B, C). The three rings are arranged in a symmetric trefoil —
|
|
their centers at the corners of an equilateral triangle — so each pair overlaps
|
|
and the rings read as interlocked; at each of the six ring crossings apply a
|
|
consistent over/under weave so no ring outline is broken.
|
|
|
|
Chambers are circular nodes placed **on the rings at the hexagon vertices**, in
|
|
each loop's clockwise cyclic order (Loop A: 0→1→2→3→4→5; Loop B: 2→3→6→7→8→9;
|
|
Loop C: 4→5→10→11→8→9). A shared chamber belongs to two rings; render it **once**,
|
|
positioned at the overlap of its two loops, and route both ring outlines through
|
|
that node so the shared slot is a single visible chamber. Label each chamber with
|
|
its slot index and mark shared chambers with the loops that own them. A reference
|
|
coordinate construction (centers, radius, per-slot coordinates) and an ASCII map
|
|
are provided in `docs/board-layout.md`; the implementer may nudge coordinates for
|
|
legibility as long as each loop remains a clear hexagon, shared chambers render
|
|
once at the overlaps, and the cyclic vertex order above is preserved.
|
|
|
|
Rotation moves payloads along the chosen loop's cyclic vertex order; channel-flow
|
|
arrows are drawn along the owner loop's edges in its current direction. The board
|
|
is one SVG that scales to the viewport.
|
|
|
|
## 5. Domain model
|
|
|
|
Use serializable plain data. Keep UI animation, hover, focus, wall-clock time, and ephemeral notifications outside domain state.
|
|
|
|
A compatible model includes:
|
|
|
|
```ts
|
|
type LoopId = "A" | "B" | "C";
|
|
type Direction = "cw" | "ccw";
|
|
type LineageId = "producer" | "grazer";
|
|
type PressureId = "heat" | "hunger" | "toxin" | "immunity";
|
|
type Mode = "campaign" | "standalone";
|
|
type Outcome = "playing" | "won" | "collapsed" | "expired";
|
|
|
|
type Chamber = {
|
|
nutrient: number; // 0..6
|
|
heat: number; // 0..6
|
|
toxin: number; // 0..6
|
|
producer: number; // 0..6
|
|
grazer: number; // 0..6
|
|
phage: number; // 0..6
|
|
};
|
|
|
|
type Lineage = {
|
|
pressure: Record<PressureId, number>; // 0..3
|
|
unlocked: Record<PressureId, boolean>;
|
|
};
|
|
|
|
type GameState = {
|
|
schemaVersion: 1;
|
|
mode: Mode;
|
|
scenarioId: string;
|
|
turn: number;
|
|
loops: Record<LoopId, { direction: Direction }>;
|
|
sharedOwner: Record<string, LoopId>;
|
|
chambers: Chamber[];
|
|
lineage: Record<LineageId, Lineage>;
|
|
inheritedAtStart: Record<LineageId, PressureId[]>;
|
|
consecutiveObjectiveTurns: number;
|
|
environmentActive: Record<PressureId, boolean>;
|
|
// turn starts at 0; each accepted action resolves turn + 1
|
|
outcome: Outcome;
|
|
actionLog: RotationAction[];
|
|
};
|
|
```
|
|
|
|
All capped quantities use integer clamp `0..6`. Pressure tracks use `0..3`. Overflow is discarded and must be shown in previews/event attribution.
|
|
|
|
The transition must not mutate its input.
|
|
|
|
Canonical equality means deep equality after stable-key JSON serialization of domain state. Never include transient UI/time data in this comparison.
|
|
|
|
## 6. Organisms and fixtures
|
|
|
|
### Movable chamber values
|
|
|
|
| ID | Name direction | Food | Base rule |
|
|
|---|---|---|---|
|
|
| producer | Agent may choose a memorable fictional species name | nutrient | If population and nutrient are present, consume 1 nutrient and gain 1 population. |
|
|
| grazer | Agent may choose a memorable fictional species name | producer | Remove 1 edible producer and gain 1 grazer. |
|
|
| phage | Phage | grazer | Remove 1 edible grazer and gain 1 phage; if unable to feed, lose 1 phage. |
|
|
|
|
Producer and grazer are persistent campaign lineages. Phage is not.
|
|
|
|
### Fixed fixtures
|
|
|
|
Fixtures stay attached to board slots when chambers rotate.
|
|
|
|
- **Nutrient inlet:** add 2 nutrient.
|
|
- **Heat source:** add 2 heat.
|
|
- **Toxin inlet:** add 2 toxin.
|
|
- **Drain:** remove 2 toxin.
|
|
- **Immune node:** selects and damages producer/grazer exactly once through the Section 8 immunity algorithm.
|
|
- **Objective marker:** no simulation effect; marks a target slot.
|
|
|
|
Fixtures may coexist only when explicitly defined by scenario data.
|
|
|
|
## 7. Fixed turn pipeline
|
|
|
|
`nextState(state, rotationAction)` executes exactly this order:
|
|
|
|
1. **Rotate and reconnect**
|
|
- Move chamber payloads.
|
|
- Update selected loop direction.
|
|
- Update shared-slot ownership.
|
|
|
|
2. **Channel flow**
|
|
- Snapshot all nutrient/toxin values at phase start.
|
|
- Every chamber with nutrient sends 1 nutrient through its outlet; every chamber with toxin sends 1 toxin.
|
|
- For each value, commit `clamp(start - sent + sum(received), 0, 6)` simultaneously.
|
|
- Discarded overflow is attributed.
|
|
|
|
3. **Producer growth**
|
|
- Snapshot this phase after flow.
|
|
- Process chambers in ascending slot order.
|
|
- Each occupied producer colony with nutrient consumes 1 nutrient.
|
|
- It normally gains 1 producer.
|
|
- A locally active trait cost may suppress reproduction or impose its defined payment.
|
|
|
|
4. **Biological interactions**
|
|
- Run a grazer subphase, then a phage subphase.
|
|
- Each subphase reads a snapshot taken after the prior subphase and commits simultaneously.
|
|
- Each occupied grazer colony may consume one edible local producer and gain one grazer.
|
|
- Each occupied phage colony may consume one edible local grazer and gain one phage; otherwise it loses one phage.
|
|
- Current base feeding is local, so no two chambers contend for the same prey.
|
|
|
|
5. **Migration**
|
|
- Run producer, grazer, then phage migration subphases.
|
|
- Each species subphase reads a fresh snapshot after the prior species committed.
|
|
- A source population of at least 2 sends one unit through its outlet only when destination food is strictly greater than source food.
|
|
- Producer food is nutrient; grazer food is producer; phage food is grazer.
|
|
- Within each species subphase, commit aggregate transfers simultaneously as `clamp(start - sent + sum(received), 0, 6)` and attribute overflow.
|
|
|
|
6. **Evolution and environmental response activation**
|
|
- For each pressure whose track already equals 3, unlock the matching lineage trait.
|
|
- If any lineage has that pressure at 3, activate the matching global environmental response for the remainder of this scenario.
|
|
- Lineage order for any contention is producer, then grazer.
|
|
|
|
7. **Fixtures, exposure, and pressure consequences**
|
|
- Apply nutrient inlets: +2 normally, +1 while Hunger Response is active.
|
|
- Apply heat sources: +2 normally, +3 while Heat Response is active; then reduce every chamber's heat by 1.
|
|
- Apply toxin inlets: +2 normally, +3 while Toxin Response is active.
|
|
- Apply drains: toxin -2.
|
|
- Resolve the single immunity algorithm defined in Section 8; immune damage is 2 normally or 3 while Immunity Response is active.
|
|
- Snapshot heat, hunger, toxin, and immunity qualification plus occupied populations after fixtures and immune target selection.
|
|
- Increment global lineage pressure tracks from that snapshot before applying population consequences.
|
|
- Resolve heat, hunger, toxin, then immunity consequences in that order.
|
|
- At the start of each pressure subphase, skip a lineage/chamber whose current population is already zero, even if it qualified in the exposure snapshot.
|
|
- Toxin carrier payments process producer then grazer in each chamber; each pays from current nutrient, so later lineages lose population when earlier payment exhausted it.
|
|
- Apply adapted heat/toxin spillover only after both lineages' carrier consequences for that pressure.
|
|
|
|
8. **Outcome and turn finalization**
|
|
- Initial state has `turn = 0`.
|
|
- For an accepted action, define `resolvedTurn = prior.turn + 1`.
|
|
- Before win evaluation, set `consecutiveObjectiveTurns` to prior +1 when the scenario's sustained predicate is true, otherwise reset it to 0.
|
|
- Ecosystem collapse takes precedence: if total producer + grazer equals 0, lose as `collapsed`.
|
|
- Otherwise evaluate scenario win using `resolvedTurn` and updated consecutive count.
|
|
- Otherwise, if `resolvedTurn >= turnLimit`, lose as `expired`.
|
|
- Store `turn = resolvedTurn`, append the action, and produce deterministic phase-ordered event attribution.
|
|
|
|
The implementation may represent events separately from canonical state, but event generation must be deterministic from prior state plus action.
|
|
|
|
## 8. Selective pressure and adaptations
|
|
|
|
Each lineage has four global tracks. A track gains exactly +1 on a turn if that lineage occupied at least one qualifying chamber in the exposure snapshot. Multiple qualifying chambers do not accelerate a track. Tracks cap at 3. During the following turn's evolution phase, the lineage trait unlocks and the matching global environmental response activates.
|
|
|
|
| Pressure | Local qualifying condition | Unadapted effect | Adapted benefit | Carrier cost | Spillover | Global response |
|
|
|---|---|---|---|---|---|---|
|
|
| Heat | heat ≥ 2 | lose 2 population | Heat Shield prevents heat loss | While hot, growth/feeding cannot add population | After both lineages resolve heat, reduce local heat by 1 per adapted surviving lineage, maximum 2 | Heat sources add 3 instead of 2 |
|
|
| Hunger | mapped food equals 0 | lose 1 population | Dormancy prevents hunger loss | Dormant population cannot migrate | Dormant population is inedible, denying food to its predator | Nutrient inlets add 1 instead of 2 |
|
|
| Toxin | toxin ≥ 2 | lose 1 population | Efflux prevents toxin loss | Pay 1 nutrient; if none, lose 1 population | After carrier payments, reduce local toxin by 1 per adapted surviving lineage, maximum 2 | Toxin inlets add 3 instead of 2 |
|
|
| Immunity | selected by immune node | lose immune damage once | Cloak excludes the lineage from immune selection | At an immune node, predator feeding removes one extra cloaked prey | Immune node retargets the other eligible lineage | Immune damage becomes 3 instead of 2 |
|
|
|
|
### Immunity algorithm
|
|
|
|
1. During biological interactions, an unlocked Cloak is locally active whenever its carrier occupies an immune-node chamber. A predator feeding on that cloaked prey removes 2 prey instead of 1; this is the carrier cost.
|
|
2. During fixtures, inspect current populations at each immune node in ascending slot order.
|
|
3. Eligible targets are occupied producer/grazer lineages without unlocked Cloak. Choose largest population; tie chooses producer.
|
|
4. If no eligible lineage exists, the node does nothing. Otherwise record the selected lineage as immunity-qualified, attribute any retargeting caused by Cloak as spillover, and schedule exactly one immune damage event.
|
|
5. Pressure tracks use the recorded selection snapshot. During the later immunity consequence subphase, apply the scheduled damage only if that target still has population; never apply a second immune loss.
|
|
|
|
Rules:
|
|
|
|
- Global unlock does not mean always active. Heat, Hunger, and Toxin traits activate only under their qualifying condition. Cloak activates locally at immune nodes.
|
|
- Each effect applies once per lineage per chamber per phase.
|
|
- Population loss floors at zero.
|
|
- Environment response flags reset at scenario start even when traits are inherited; pressure can reactivate them.
|
|
- UI must attribute unlock, local activation, prevented loss, paid cost, spillover, and global response with text plus visual encoding.
|
|
- “Avoid an adaptation” means win a relevant pressure scenario while the matching trait remains locked (its track never enters an evolution phase at 3).
|
|
- At least one solver route must deliberately provoke and exploit a trait; another must satisfy the defined avoidance condition.
|
|
|
|
## 9. Scenario contracts
|
|
|
|
Scenario definitions are immutable declarative data. Sparse chamber notation below is:
|
|
|
|
```text
|
|
slot: nutrient / producer / grazer / phage / heat / toxin
|
|
```
|
|
|
|
Omitted slots and omitted values are zero. All loops initially clockwise. Shared-slot ownership uses alphabetical default.
|
|
|
|
Universal collapse is total producer + grazer = 0. Universal terminal precedence is collapse, then win, then turn-limit expiration.
|
|
|
|
The autonomous implementation must build a bounded deterministic solver or state-space search that proves at least one winning sequence and one losing sequence for each baseline scenario. Store those sequences as test fixtures and use them to generate `RECORDING.md`. It must also verify every campaign inheritance combination reachable from prior scenarios. If a scenario is impossible or trivial, the agent may adjust only starting populations/resources, fixture locations, or numeric objective thresholds by at most 1 per tuning pass. It must document every adjustment and rerun all solver tests. Board topology, turn order, caps, trait semantics, and objective type may not change.
|
|
|
|
### Scenario 1 — Heat: Cultivation Quota
|
|
|
|
- Turn limit: 8.
|
|
- Fixtures: nutrient inlets at 1 and 7; heat sources at 3 and 9.
|
|
- Start:
|
|
- `0: 3/2/0/0/0/0`
|
|
- `6: 3/2/0/0/0/0`
|
|
- `10: 2/1/0/0/0/0`
|
|
- `4: 1/0/0/0/0/0`
|
|
- Win: producer at slot 11 ≥ 5 and total producer ≥ 12.
|
|
- Teaches: rotation, ownership, flow, growth, preview, first visible pressure.
|
|
|
|
### Scenario 2 — Hunger: Endurance
|
|
|
|
- Turn limit: 10.
|
|
- Fixtures: nutrient inlet at 0.
|
|
- Start:
|
|
- `1: 2/3/0/0/0/0`
|
|
- `5: 1/2/1/0/0/0`
|
|
- `7: 2/3/1/0/0/0`
|
|
- `10: 0/2/2/0/0/0`
|
|
- Win when `resolvedTurn === 10` and:
|
|
- total producer ≥ 8;
|
|
- total grazer ≥ 4;
|
|
- producer occupies at least 3 chambers;
|
|
- grazer occupies at least 2 chambers.
|
|
- Teaches: competition, migration, dormancy, deliberate denial of predator food.
|
|
|
|
### Scenario 3 — Toxin: Cleansing
|
|
|
|
- Turn limit: 9.
|
|
- Fixtures: nutrient inlet at 1; toxin inlets at 3 and 9; drains at 5 and 11.
|
|
- Start:
|
|
- `0: 3/3/0/0/0/0`
|
|
- `3: 0/0/0/0/0/2`
|
|
- `6: 2/3/0/0/0/0`
|
|
- `9: 0/0/0/0/0/2`
|
|
- `10: 2/2/1/0/0/0`
|
|
- Win when `resolvedTurn` is 6 through 9, total toxin ≤ 2, and total producer + grazer ≥ 8.
|
|
- Teaches: routing contaminants, resistance payment, shared detoxification spillover.
|
|
|
|
### Scenario 4 — Immunity: Escort
|
|
|
|
- Turn limit: 8.
|
|
- Fixtures: nutrient inlets at 0 and 8; immune nodes at 2, 4, and 6; sanctuary objective marker at 11.
|
|
- Start:
|
|
- `1: 2/3/0/0/0/0`
|
|
- `5: 2/3/2/0/0/0`
|
|
- `7: 0/0/0/1/0/0`
|
|
- `9: 1/0/2/1/0/0`
|
|
- Win: grazer at 11 ≥ 3, phage at 11 ≥ 1, and total producer ≥ 6.
|
|
- Teaches: immune targeting, cloak, retargeting spillover, predator vulnerability.
|
|
|
|
### Scenario 5 — Convergence: Stable Equilibrium
|
|
|
|
- Turn limit: 12.
|
|
- Fixtures:
|
|
- nutrient inlets at 0 and 6;
|
|
- heat sources at 2 and 8;
|
|
- toxin inlet at 3;
|
|
- drain at 9;
|
|
- immune nodes at 4 and 10;
|
|
- assay objective markers at 1, 7, and 11.
|
|
- Start:
|
|
- `0: 3/3/0/0/0/0`
|
|
- `3: 0/0/0/0/0/2`
|
|
- `5: 2/2/1/0/0/0`
|
|
- `6: 3/2/0/0/0/0`
|
|
- `8: 0/0/0/0/2/0`
|
|
- `9: 0/0/0/0/0/1`
|
|
- `10: 2/2/2/1/0/0`
|
|
- Sustained predicate:
|
|
- every assay marker contains producer + grazer ≥ 2;
|
|
- total producer is 8 through 14;
|
|
- total grazer is 3 through 7;
|
|
- total phage ≤ 3;
|
|
- total toxin ≤ 6.
|
|
- Win when the updated `consecutiveObjectiveTurns >= 2` before `resolvedTurn` exceeds 12.
|
|
- Teaches: all systems plus inherited gift-and-burden consequences.
|
|
|
|
## 10. Campaign and standalone progression
|
|
|
|
### Campaign
|
|
|
|
- Scenario 1 starts with no inherited traits.
|
|
- Winning unlocks the next scenario.
|
|
- After each win, the player may preserve zero or one trait that unlocked during that scenario and was not already inherited.
|
|
- Declining is allowed. Already inherited traits are not offered again.
|
|
- Preserved traits carry both benefit and cost into later scenarios; previously inherited traits remain.
|
|
- Pressure counters and global environment-response flags reset between scenarios.
|
|
- Scenario retry restores the exact inheritance snapshot from first entry to that scenario.
|
|
- Campaign victory occurs after winning Scenario 5.
|
|
- Reachability verification enumerates every cumulative inheritance set produced by choosing zero or one newly unlocked eligible trait after each prior scenario.
|
|
|
|
### Standalone
|
|
|
|
- Unlocked scenarios may be replayed individually.
|
|
- Standalone always clones immutable baseline scenario data.
|
|
- No traits or pressure counters carry in or out.
|
|
- Standalone completion does not change campaign progression.
|
|
|
|
### Menu semantics
|
|
|
|
- **Continue:** restore exact active run if one exists; otherwise enter next campaign scenario.
|
|
- **New Campaign:** clear campaign progress only after confirmation.
|
|
- **Retry:** restore current scenario baseline plus its campaign-entry inheritance snapshot.
|
|
- **Replay Standalone:** select any unlocked scenario with baseline lineages.
|
|
- **Save & Quit:** persist and return to title/menu without altering state.
|
|
|
|
## 11. Persistence and replay
|
|
|
|
Use localStorage with a versioned save envelope containing:
|
|
|
|
- schema version;
|
|
- mode;
|
|
- scenario ID;
|
|
- canonical game state;
|
|
- campaign unlocked scenarios;
|
|
- inherited lineage traits;
|
|
- scenario-entry inheritance snapshot;
|
|
- action log;
|
|
- outcome;
|
|
- saved-at metadata outside canonical comparison.
|
|
|
|
Requirements:
|
|
|
|
- Save after every committed turn and on Save & Quit.
|
|
- Restore exact canonical state and exact next transition.
|
|
- Validate schema and values at load boundary.
|
|
- Malformed or unsupported saves fail safely with a visible recovery choice; never crash or silently corrupt progress.
|
|
- Replay is primarily a testing/debugging seam. It need not be a full player-facing replay viewer.
|
|
- Replaying action log from immutable baseline plus inheritance snapshot must reproduce canonical current state.
|
|
|
|
## 12. Preview and event attribution
|
|
|
|
Hover, focus, or touch-selecting a rotation shows an exact one-turn preview produced by calling the same pure transition on cloned state.
|
|
|
|
Preview must show:
|
|
|
|
- chamber destinations;
|
|
- updated channel direction and shared ownership;
|
|
- nutrient/toxin flow arrows;
|
|
- exact population/resource deltas;
|
|
- overflow discarded;
|
|
- pressure increments;
|
|
- trait unlocks and local activations;
|
|
- adaptation benefit, carrier cost, and spillover;
|
|
- predicted objective progress or terminal result.
|
|
|
|
Commit must produce canonical state equal to previewed canonical state.
|
|
|
|
The event panel should explain the tick in phase order. It must be concise enough to scan during a video and detailed enough to explain a collapse.
|
|
|
|
## 13. User interface and visual direction
|
|
|
|
### Visual world
|
|
|
|
- Dark laboratory glass and restrained near-black background.
|
|
- Luminous culture chambers with crisp borders.
|
|
- Microfluidic channels read as instrument paths, not fantasy pipes.
|
|
- Species use shape + short label + color.
|
|
- Four pressures use distinct iconography/pattern plus color.
|
|
- Motion is subtle and causal: rotation, flow pulse, growth/decline, trait activation.
|
|
- No generic dashboard card grid, excessive gradients, stock icons, or decorative particle noise.
|
|
|
|
### Layout
|
|
|
|
Desktop:
|
|
|
|
- Center: SVG culture board.
|
|
- Left or upper rail: scenario objective, turn, campaign state.
|
|
- Right or lower rail: pressure tracks, lineage traits, exact preview/event log.
|
|
- Persistent controls: menu, Save & Quit, retry where relevant, help/legend.
|
|
|
|
Narrow viewport:
|
|
|
|
- Board remains primary.
|
|
- Information rails stack below.
|
|
- No horizontal page scrolling.
|
|
- All controls remain reachable and labels readable at 200% zoom.
|
|
|
|
### Input
|
|
|
|
- Pointer/touch: select loop and direction, preview, then commit. Selecting a rotation (focus/hover/tap) shows the preview and **enables Commit**; the selection **persists** until the player commits, selects a different rotation, or cancels (Escape). Never disable Commit merely because the pointer leaves the rotation control or focus moves to the Commit button — that makes the enabled-while-hovered button grey out the moment the player goes to press it.
|
|
- Keyboard: focusable controls for each loop direction; Enter/Space commits; Escape cancels preview.
|
|
- Visible focus on every actionable control.
|
|
- No hover-only information.
|
|
|
|
### Accessibility
|
|
|
|
- Semantic headings and landmarks.
|
|
- Real buttons for actions.
|
|
- Accessible names include loop, direction, and predicted high-level result.
|
|
- Live region announces committed turn result and terminal outcomes.
|
|
- Text/symbols supplement every color encoding.
|
|
- Contrast meets WCAG AA for normal text and controls.
|
|
- `prefers-reduced-motion` removes nonessential animation and renders final states immediately.
|
|
|
|
## 14. Architecture
|
|
|
|
Prefer the smallest boring stack that supports reliable testing. A suitable default is Vite + TypeScript + Vitest + Playwright, but the autonomous agent may choose an equally small established stack already supported by the environment.
|
|
|
|
Required module boundaries:
|
|
|
|
1. **Domain:** types, canonical serialization, validation, pure transitions, event derivation.
|
|
2. **Content:** immutable species/trait tables and declarative scenarios.
|
|
3. **Persistence:** versioned save validation and localStorage adapter.
|
|
4. **Presentation:** SVG rendering, controls, preview, status/event UI.
|
|
5. **Verification:** behavior fixtures, solver/replay checks, browser user flows.
|
|
|
|
Do not create factories, plugin systems, dependency injection containers, generic ECS frameworks, or abstractions with one implementation.
|
|
|
|
## 15. Autonomous implementation gates
|
|
|
|
The run must complete gates in order. A failing gate blocks later work except the smallest repair needed to pass it.
|
|
|
|
### Gate 0 — legality and evidence preflight
|
|
|
|
- Record initial tree and confirm only permitted human-authored context exists.
|
|
- Record `PI_SESSION_FILE` absolute path.
|
|
- Record effective model/provider.
|
|
- Generate `CONTEXT-MANIFEST.md` listing the one prompt, all local context files, extension/package versions, relevant extension configuration, and their original/effective paths.
|
|
- Authoritative private prompt path: `/Users/alex/Projects/scripting/agentic-labs-challenge/adaptive-loop/PROMPT.md`.
|
|
- Each real attempt starts in a fresh standalone directory outside every existing Git worktree, containing only `SPEC.md` and the three `.agents/skills/*/SKILL.md` instruction files; the initial human message is supplied from the private prompt and is not copied into the public game repository by default. The agent may initialize Git during the run.
|
|
- The final public repository discloses all staged context files plus a `CONTEXT-MANIFEST.md` that records the exact isolated launch flags, loaded extension/package versions, effective steering/configuration text or immutable public source hashes, and original/effective paths; the prompt is DM'd with submission unless the operator deliberately chooses publication.
|
|
- Copying and validating the final session JSONL is an operator post-exit submission step, explicitly excluded from the in-session game-code freeze.
|
|
- Because Pi Goal continuation messages are persisted as `role:user`, post-exit validation must classify provenance rather than require one raw user-role entry: one initial `pi-goal-prompt` kickoff reconstructs `PROMPT.md`, and every later user-role entry must be a matching disclosed `pi-goal-continuation` for the same objective and goal ID. Any unmarked or mismatched user entry fails compliance.
|
|
- Do not copy the live session log during the run.
|
|
|
|
### Gate 1 — runnable shell
|
|
|
|
- Production app starts.
|
|
- Title, new campaign, continue state, and scenario shell render.
|
|
- No browser console errors.
|
|
|
|
### Gate 2 — complete Scenario 1
|
|
|
|
- Board rotations move chambers and reconnect channels.
|
|
- Preview equals commit.
|
|
- Heat scenario has playable win, collapse, expiration, and retry.
|
|
- Save/reload preserves exact state.
|
|
|
|
### Gate 3 — simulation truth
|
|
|
|
Literal worked tests cover:
|
|
|
|
- both directions for all loops;
|
|
- shared-slot ownership;
|
|
- flow contention and overflow;
|
|
- population/resource caps;
|
|
- every pipeline phase;
|
|
- all four adaptations including benefit/cost/spillover;
|
|
- input immutability;
|
|
- canonical determinism;
|
|
- terminal precedence;
|
|
- preview/commit equality;
|
|
- replay reproduction.
|
|
|
|
### Gate 4 — scenario solvability
|
|
|
|
- Solver or bounded search proves and stores one winning and one losing route for each baseline scenario.
|
|
- Every reachable campaign inheritance set can complete subsequent scenarios.
|
|
- At least one route requires shared-slot ownership changes.
|
|
- At least one route exploits an adaptation.
|
|
- At least one route avoids an adaptation.
|
|
|
|
### Gate 5 — campaign and persistence
|
|
|
|
- Five scenarios unlock in order.
|
|
- Lineage choice carries gift and cost.
|
|
- Retry uses scenario-entry inheritance snapshot.
|
|
- Standalone uses clean baseline.
|
|
- Malformed save recovery works.
|
|
- Campaign victory works.
|
|
|
|
### Gate 6 — black-box browser proof
|
|
|
|
Against the production build, public controls only:
|
|
|
|
- start a campaign;
|
|
- preview and commit a rotation;
|
|
- observe movement plus channel flow interaction;
|
|
- trigger and visibly attribute an adaptation benefit, cost, and spillover;
|
|
- trigger a global pressure response and observe its strengthened fixture effect;
|
|
- lose, retry, then win;
|
|
- Save & Quit;
|
|
- close/reopen page and Continue exact state;
|
|
- operate core actions by keyboard;
|
|
- check narrow viewport, 200% zoom, and reduced motion;
|
|
- never inject domain state or localStorage to fake gameplay.
|
|
|
|
### Gate 7 — bounded polish and independent review
|
|
|
|
- One visual QA pass at desktop and narrow viewport.
|
|
- Fresh-context reviewers inspect correctness/determinism, user flow/accessibility, and simplicity/scope.
|
|
- One writer applies accepted fixes.
|
|
- Maximum three broad review rounds. If a floor blocker remains, drop optional polish and perform one final focused repair/verification cycle; never declare success with a failing floor gate.
|
|
|
|
### Gate 8 — repository freeze
|
|
|
|
- Aggregate verification passes after final code edit.
|
|
- README contains exact install, run, build, test, and play instructions.
|
|
- `ASSETS.md` discloses that visuals are procedural and lists any allowed generated asset if one was created during the run.
|
|
- `RECORDING.md` contains a short deterministic uncut-video route.
|
|
- All steering context remains at original project-local paths.
|
|
- Record final commit/tree hash or, if no commit is appropriate, a deterministic file manifest and hashes.
|
|
- Print the authoritative `PI_SESSION_FILE` path and post-exit copy/validation command.
|
|
- Make no more game-code edits after freeze.
|
|
|
|
## 16. Recording route requirements
|
|
|
|
`RECORDING.md` must be generated from verified solver/browser routes, not invented prose.
|
|
|
|
One continuous take should be short but show:
|
|
|
|
1. Title/campaign start.
|
|
2. Exact preview of a rotation.
|
|
3. Rotation causing both chamber movement and channel flow.
|
|
4. Pressure causing a species adaptation.
|
|
5. The adaptation's benefit, cost, and spillover.
|
|
6. Global pressure response strengthening an environmental fixture.
|
|
7. Ecosystem collapse and retry.
|
|
8. A scenario win and preserved lineage choice.
|
|
9. Save & Quit.
|
|
10. Page/tab close and reopen.
|
|
11. Continue restoring exact state.
|
|
12. Visible access to multiple scenarios.
|
|
|
|
Automated tests must validate all five scenarios and campaign victory; the recording need not play all five unless the verified route remains concise.
|
|
|
|
## 17. Repository deliverables
|
|
|
|
Required at freeze:
|
|
|
|
- Complete game source.
|
|
- Production build configuration.
|
|
- Automated tests and black-box browser tests.
|
|
- README.md.
|
|
- ASSETS.md.
|
|
- RECORDING.md.
|
|
- CONTEXT-MANIFEST.md.
|
|
- This SPEC.md.
|
|
- Original one prompt at its submitted path only if disclosure strategy calls for it; otherwise preserve privately and DM it per competition rules.
|
|
- `.agents/skills/pi-game-factory/SKILL.md`.
|
|
- `.agents/skills/deterministic-game-core/SKILL.md`.
|
|
- `.agents/skills/game-ui-proof/SKILL.md`.
|
|
- Exact authoritative session JSONL is an operator-owned post-exit submission artifact, not an in-session freeze deliverable.
|
|
|
|
## 18. Completion definition
|
|
|
|
Do not stop at a plan, architecture, prototype, attractive board, or one scenario.
|
|
|
|
Adaptive Loop is complete only when:
|
|
|
|
- five scenarios are playable;
|
|
- campaign and standalone modes work;
|
|
- win and both loss types work;
|
|
- two or more systems visibly interact;
|
|
- adaptation benefit/cost/spillover is playable and visible;
|
|
- deterministic preview, replay, and persistence are proven;
|
|
- scenario solver routes and browser tests pass;
|
|
- the production UI is readable, accessible, and stable;
|
|
- the repository deliverables exist;
|
|
- the recording route is verified;
|
|
- the final aggregate gate passes after the last code edit;
|
|
- the authoritative prompt/context boundary, session path, and operator-owned post-exit log procedure are reported.
|