AI Agent 专用快速参考。详细信息请查阅对应文档。
| 需求 | 参考文档 |
|---|---|
| 项目架构、目录结构、设计哲学 | ARCHITECTURE.md |
| 神经网络拓扑、输入输出 | docs/wiki/BRAIN.md |
| 生态系统、能量公式、代谢 | docs/wiki/ECOSYSTEM.md |
| 历史、考古学、化石记录 | docs/wiki/HISTORY.md |
| HexDNA、遗传、变异逻辑 | docs/wiki/GENETICS.md |
| 用户手册、控制键位 | docs/MANUAL.md / docs/MANUAL_zh.md |
| 项目概述、快速开始 | README.md / docs/README_zh.md |
| 版本变更记录 | CHANGELOG.md |
| 测试套件规范 | tests/AGENTS.md |
| 核心引擎架构 | crates/primordium_core/AGENTS.md |
| TUI 渲染系统 | crates/primordium_tui/AGENTS.md |
| I/O 与持久化 | crates/primordium_io/AGENTS.md |
src/
├── main.rs # TUI 入口
├── lib.rs # 库入口 (WASM 导出)
├── app/ # TUI 应用层 (state, render, input, help, onboarding)
├── model/ # 模拟引擎核心
│ ├── state/ # 数据层 (entity, terrain, environment, food, pheromone, pathogen, lineage_registry)
│ ├── systems/ # 系统层 (intel, action, biological, social, ecological, environment, stats)
│ ├── infra/ # 基础设施 (blockchain, network, lineage_tree)
│ ├── brain.rs # 神经网络 (29-6-12 NEAT-lite, 47 nodes)
│ ├── spatial_hash.rs # 空间索引 (实为 SpatialHash)
│ ├── world.rs # 协调器
│ ├── config.rs # 配置
│ ├── history.rs # 事件日志
│ └── migration.rs # 实体迁移
├── ui/ # 渲染抽象 (tui, web_renderer)
├── client/ # WASM 客户端 (wasm32 only)
├── server/ # P2P 中继服务器
└── bin/ # 工具 (verify, analyze)
→ See crates/primordium_core/AGENTS.md for detailed system relationships and parallel execution patterns.
→ See crates/primordium_core/AGENTS.md for detailed system relationships, parallel execution patterns, and core engine architecture.
- Architecture: Dynamic graph-based NEAT-lite topology. Initialized as 29 inputs → 6 hidden → 12 outputs (47 nodes total).
- Topological Evolution: Supports "Add Node" and "Add Connection" mutations with Innovation Tracking for crossover.
-
Memory: The 6 initial hidden layer values from
$T-1$ are fed back as inputs for$T$ (Mapped to indices 14..19).
| Index | Label | Description |
|---|---|---|
| 0 | FoodDX | Food delta X |
| 1 | FoodDY | Food delta Y |
| 2 | Energy | Current energy ratio |
| 3 | Density | Local entity density |
| 4 | Phero | Pheromone strength |
| 5 | Tribe | Tribe density |
| 6 | KX | Kin centroid X |
| 7 | KY | Kin centroid Y |
| 8 | SA | Signal A concentration |
| 9 | SB | Signal B concentration |
| 10 | WL | Wall proximity |
| 11 | AG | Age / maturity |
| 12 | NT | Nutrient type |
| 13 | TP | Trophic potential |
| 14-19 | Mem0-5 | Memory (hidden |
| 20 | Hear | Acoustic input |
| 21 | PartnerEnergy | Bond partner energy |
| 22 | BuildPressure | Local build activity |
| 23 | DigPressure | Local dig activity |
| 24 | SharedGoal | Lineage goal signal |
| 25 | SharedThreat | Lineage threat signal |
| 26 | LineagePop | Lineage population |
| 27 | LineageEnergy | Lineage total energy |
| 28 | Overmind | Alpha broadcast signal |
| Index | Label | Description |
|---|---|---|
| 29 | MoveX | Movement X |
| 30 | MoveY | Movement Y |
| 31 | Speed | Speed modulation |
| 32 | Aggro | Aggression |
| 33 | Share | Share intent |
| 34 | Color | Color modulation |
| 35 | EmitA | Emit Signal A |
| 36 | EmitB | Emit Signal B |
| 37 | Bond | Bond request |
| 38 | Dig | Dig terrain |
| 39 | Build | Build structure |
| 40 | OvermindEmit | Broadcast to kin |
Hidden Nodes (41..46, 6 total)
- Metabolic Cost: 0.02 per hidden node + 0.005 per enabled connection.
-
Resource Specialization: Entities evolve a
metabolic_niche(0.0 to 1.0). -
Nutrient Coupling: Digestive efficiency is
$1.0 - |niche - food_type|$ . - Terrain Strategy: Blue food (1.0) in Mountains/Rivers; Green food (0.0) in Plains.
- Kin Recognition: Sensing kin centroid (KX, KY).
- Herding Bonus: +0.05 energy/tick for alignment with kin centroid.
- Semantic Signals: SA/SB emission and sensing for evolved communication.
- Trophic Potential: Sliding scale from 0.0 (Herbivore) to 1.0 (Carnivore).
-
Efficiency: Plant gain ∝
$(1.0 - trophic_potential)$ ; Meat gain ∝$trophic_potential$ . - Trophic Cascade (Phase 35): Over-grazing and predator competition create self-regulating population cycles. Stability alerts (EcoAlert) notify of collapse.
- Sensing Radius: +0.1 → +2% base idle cost.
- Max Speed: +0.1 → +5% movement cost.
-
Inertia:
$Acceleration \propto \frac{1}{MaxEnergy}$ . High energy capacity reduces steering responsiveness.
- Rank Calculation: Score = Energy(30%) + Age(30%) + Offspring(10%) + Reputation(30%).
- Soldier Caste: Requires Rank > 0.8 AND Aggression > 0.5. Bonus damage: 1.5x (flat), 2.0x (War Zone).
- Tribal Splitting: Triggered by high density (>0.8) and low rank (<0.2). Result: New color mutation.
- Leadership Vector: Calculated in
World::updatePass 1. Influences movement inActionsystem.
→ See tests/AGENTS.md for detailed conventions, running commands, and anti-patterns.
- pre-commit:
cargo test+cargo fmt --check+cargo clippy -D warnings - pre-push: Full test suite
功能变更时 必须同步更新:
- ✅ 测试用例
- ✅ 中英文文档 (README, MANUAL, ARCHITECTURE 等)
- ✅ 本文件 (如涉及 agent 关键信息)
// ❌ BAD - field_reassign_with_default
let mut x = X::default();
x.field = val;
// ✅ GOOD
let x = X { field: val, ..X::default() };spatial_hash.rs实际实现的是 SpatialHash,不是四叉树
- 多数模块受
#[cfg(target_arch = "wasm32")]门控 - 调试时注意编译目标
import_migrant需要通过Genotype::from_hex解析包含物理基因与神经网络的完整 HexDNA 字符串。
- 使用
EntitySnapshot模式避免可变借用冲突 - Buffer Pooling 减少分配抖动
- 地形灾害由
World触发,在TerrainGrid更新中处理
- Current Architecture (Phase 66):
- Inputs: 0..28 (29个)
- Outputs: 29..40 (12个)
- Hidden: 41..46 (6个)
- Total Nodes: 47 (ID 0..46)
Note: 之前版本曾有 Off-by-one 错误及 ID 重叠,已在 Phase 52 修复,Phase 60-66 进一步扩展。
- Terraforming:
DigandBuildcommands implemented. Entities can create canals (Rivers) and Nests. - Vocal Propagation:
SoundGridimplemented for real-time acoustic communication with diffusion and decay. - Specialized Castes:
Soldier,Engineer, andProvidercastes with specific metabolic and behavioral benefits (e.g., Engineer 50% dig/build cost reduction). - Parallelization: Full parallel execution of action and biological systems via pheromone/sound proposal unzipping.
- Collective Intelligence: Shared lineage memory with goal/threat reinforcement and neural feedback loop.
- Global Altruism: P2P energy relief protocol for lineage-based energy transfers between universes.
- Outpost Networks: High-rank Alphas can establish Outposts (
Ψ) with energy storage and specialization (Silo/Nursery). - Planetary Engineering: Forests near outposts sequestrate CO2 at 2.5x rate; tribal networks provide global cooling.
- Power Grids: Connected outposts share and balance energy stores via stigmergic canals (Rivers).
- Protected Brain Modules: Specialized castes gain mutation resistance on role-critical neural weights.
- Metamorphosis: Completed structured life stage transition.
- Larval stage: Restricted to foraging and survival (cannot Bond, Dig, or Build).
- Adult stage: Unlocked via
remodel_for_adult()which ensures neural connectivity for advanced behaviors and applies physical buffs (1.5x Energy, 1.2x Speed/Sensing).
- Genetic Memory (Phase 64): Lineages archive their "All-Time Best" genotype. Struggling entities have 1% chance of Atavistic Recall (reverting to ancestral brain).
- Deterministic Mode (Phase 66): Mock hardware metrics (sin/cos waves) for reproducible simulations when
config.world.deterministic = true. - Workspace Refactor: Introduced
primordium_datacrate for shared type definitions. - Seeded RNG: Full determinism via
ChaCha8Rngwith configurable seed.
| Binary | Command | Purpose |
|---|---|---|
primordium |
cargo run --release |
TUI 模拟 (A: 谱系树, Shift+A: 导出 DOT) |
server |
cargo run --bin server |
P2P 中继 (port 3000) |
verify |
cargo run --bin verify |
区块链验证 |
analyze |
cargo run --bin analyze |
历史分析 |
- Search:
rg(ripgrep) - Find:
fd/fdfind - Avoid: PowerShell 特定语法