```                   # 📋 Session Report
    λλ              
   λ⊙λ⊙             
  λλλλλλ            
 λλλλλλλλ           
    λλ              
    λλ              
    λλ              
    λλ              
    λλ              
    λλ              
    λλ              
    λλ              
```                 

**🔑 Session ID:** 2bed48c5-e0dd-4e3f-9196-84d359e0076a

---

## 📊 Statistics

### Turn Counts

| Metric | Value |
|--------|-------|
| Total Turns | 90 |
| 👤 User Turns | 45 |
| 🤖 LLM Turns | 45 |

### 🔧 Tool Calls

**Total Tool Calls:** 46

`bash_write-file     `   21 ████████████████████████████████████████████████████████████

`bash_check-code     `   13 █████████████████████████████████████

`bash_read-file      `   11 ███████████████████████████████

`bash_list-files     `    1 ██


### 💾 Byte Usage

`Input     `    483 KiB ████████████████████████████████████████████████████████████

`Output    `      2 KiB 

`Reasoning `      5 KiB 
**Total:** 491 KiB

---

## 👤 Step 1: User Turn

### 📝 System Prompt

```
You are an expert Haskell and Bash programmer specialized in writing clean, idiomatic, and efficient Haskell code.
When writing Bash code:
- Avoid bash-specific logic but bash-ism are fine.
- Document required shell tools at the top of the bash script.
When writing Haskell code:
- Use modern Haskell practices (base >= 4.14)
- Prefer pure functions and explicit type signatures
- Use standard libraries when appropriate
- Add clear comments for complex logic
- Follow consistent formatting
Use list-files to explore the project structure, read-file to understand existing code, write-file to create or modify files, and check-code to verify your work.
Always compile code before considering the job done.
Your output format may be stored as commit message: hence the first line of your last message should be a summary line.
```

### 💬 User Query

# OS Model: Core Entity and Component Types

Depends-on: 
Base-branch: gh-os-architecture
Final: false

## Overview

Define the foundational Entity-Component-System (ECS) types for the new Operating System architecture. This is the foundational issue that establishes the core data model inspired by https://dicioccio.fr/how-i-write-purescript-apps.html#the-cheap-entity-component-system.

## Background

Moving from a hierarchical Runtime-per-agent structure to a flat ECS model requires redefining how we represent agents, toolboxes, and resources. In ECS:
- **Entities** are unique identifiers (just IDs)
- **Components** are pure data attached to entities
- **Systems** are functions that process entities with specific components

## Types to Define

### Core Identifiers
```haskell
-- | Unique identifier for any entity in the system
newtype EntityId = EntityId { unEntityId :: UUID }
  deriving (Eq, Ord, Show, Hashable)

-- | Phantom-typed entity IDs for type safety
newtype AgentId = AgentId { unAgentId :: EntityId }
newtype ToolboxId = ToolboxId { unToolboxId :: EntityId }
newtype ConversationId = ConversationId { unConversationId :: EntityId }
newtype TurnId = TurnId { unTurnId :: EntityId }
newtype ToolCallId = ToolCallId { unToolCallId :: EntityId }
newtype ResourceId = ResourceId { unResourceId :: EntityId }
```

### Component System
```haskell
-- | A component is any data type that can be attached to an entity
class Component a where
  componentId :: Proxy a -> ComponentTypeId

-- | Type-level identifier for component types
newtype ComponentTypeId = ComponentTypeId { unComponentTypeId :: Int }
  deriving (Eq, Ord, Show)

-- | Storage for all components of a specific type
newtype ComponentStore a = ComponentStore
  { store :: HashMap EntityId a }

-- | The world contains all component stores
newtype World = World
  { componentStores :: HashMap ComponentTypeId (TVar Any) }
```

### Agent Components
```haskell
newtype AgentConfig = AgentConfig
  { agentName :: Text
  , agentModel :: ModelConfig
  , agentSystemPrompt :: Text
  , agentToolboxBindings :: [ToolboxBindingSpec]
  } deriving (Show, Generic)

instance Component AgentConfig where
  componentId _ = ComponentTypeId 1

newtype AgentState = AgentState
  { agentStatus :: AgentStatus
  , agentCurrentConversation :: Maybe ConversationId
  , agentCreatedAt :: UTCTime
  } deriving (Show)

instance Component AgentState where
  componentId _ = ComponentTypeId 2

data AgentStatus = AgentIdle | AgentBusy TurnId | AgentError Text
  deriving (Show, Eq)
```

### Toolbox Components
```haskell
newtype ToolboxConfig = ToolboxConfig
  { toolboxName :: Text
  , toolboxType :: ToolboxType
  , toolboxSettings :: Value
  } deriving (Show)

instance Component ToolboxConfig where
  componentId _ = ComponentTypeId 3

newtype ToolboxState = ToolboxState
  { toolboxScope :: ResourceScope
  , toolboxStatus :: ToolboxStatus
  , toolboxResourceRef :: Maybe ResourceId
  } deriving (Show)

instance Component ToolboxState where
  componentId _ = ComponentTypeId 4

newtype ToolboxBinding = ToolboxBinding
  { bindingAgentId :: AgentId
  , bindingToolboxId :: ToolboxId
  , bindingConfig :: Value
  } deriving (Show)

instance Component ToolboxBinding where
  componentId _ = ComponentTypeId 5
```

## Acceptance Criteria

- [ ] Create new module `System.Agents.OS.Core`
- [ ] Define `EntityId` and phantom-typed ID wrappers
- [ ] Define `Component` typeclass with auto-generated IDs
- [ ] Define `World` type with heterogeneous component storage
- [ ] Define all agent-related components
- [ ] Define all toolbox-related components
- [ ] Add type safety tests to verify phantom types work correctly
- [ ] Document tradeoffs in module header

## Tradeoffs

1. **Type Erasure (Any) vs Type Safety**: Using `TVar Any` requires careful casting but enables heterogeneous storage. Alternative would be a closed-world sum type which limits extensibility.

2. **STM vs MVar**: STM allows composable transactions, preferred for complex resource coordination across multiple entities.

3. **Component ID Assignment**: Consider Template Haskell for auto-generating IDs to prevent collisions when adding new component types.

## Migration Notes

This module is foundational and does not interact with existing code. It establishes the new data model that will eventually replace:
- `System.Agents.Runtime.Runtime`
- `System.Agents.Base.Agent` (description part)
- Parts of `System.Agents.Tools.Base`

## Files to Create/Modify

- Create: `src/System/Agents/OS/Core.hs`
- Create: `src/System/Agents/OS/Core/Types.hs`
- Create: `src/System/Agents/OS/Core/World.hs`
- Create: `test/OS/CoreTests.hs`

---
From #348



### 🛠️ Available Tools

- **bash_grep-files** (`bash_grep-files`)
  - Description: Search for a pattern in files using 'git grep'
- **bash_read-file** (`bash_read-file`)
  - Description: Read the contents of a file
- **bash_check-code** (`bash_check-code`)
  - Description: Check Haskell code by compiling or testing
- **bash_list-files** (`bash_list-files`)
  - Description: List all files in the project
- **bash_write-file** (`bash_write-file`)
  - Description: Write content to a file

---

## 🤖 Step 2: LLM Turn

### 💭 Thinking Process

<details>
<summary>Click to expand reasoning</summary>

Let me start by exploring the project structure to understand the codebase and then create the ECS types as specified in the issue.
</details>

### 💬 Response



### 🔧 Tool Calls

- **bash_list-files**

---

## 👤 Step 3: User Turn



---

## 🤖 Step 4: LLM Turn

### 💭 Thinking Process

<details>
<summary>Click to expand reasoning</summary>

Let me look at the existing project structure, especially the cabal file and some existing modules to understand the codebase better.
</details>

### 💬 Response



### 🔧 Tool Calls

- **bash_read-file**

- **bash_read-file**

---

## 👤 Step 5: User Turn



---

## 🤖 Step 6: LLM Turn

### 💭 Thinking Process

<details>
<summary>Click to expand reasoning</summary>

Let me also look at the Runtime module to understand the current architecture, and check the session types for TurnId and SessionId.
</details>

### 💬 Response



### 🔧 Tool Calls

- **bash_read-file**

- **bash_read-file**

---

## 👤 Step 7: User Turn



---

## 🤖 Step 8: LLM Turn

### 💭 Thinking Process

<details>
<summary>Click to expand reasoning</summary>

Now I have a good understanding of the codebase. Let me also look at the test structure to understand how tests are organized.
</details>

### 💬 Response



### 🔧 Tool Calls

- **bash_read-file**

---

## 👤 Step 9: User Turn



---

## 🤖 Step 10: LLM Turn

### 💭 Thinking Process

<details>
<summary>Click to expand reasoning</summary>

Now I have a comprehensive understanding of the project. Let me also look at the Tools.Base module to see what exists there.
</details>

### 💬 Response



### 🔧 Tool Calls

- **bash_read-file**

---

## 👤 Step 11: User Turn



---

## 🤖 Step 12: LLM Turn

### 💭 Thinking Process

<details>
<summary>Click to expand reasoning</summary>

Now I have a good understanding of the existing codebase. Let me create the ECS (Entity-Component-System) core types as specified in the issue. I need to create:

1. `src/System/Agents/OS/Core.hs` - Main module exporting all core types
2. `src/System/Agents/OS/Core/Types.hs` - Core identifier types and classes
3. `src/System/Agents/OS/Core/World.hs` - World storage and component management
4. `test/OS/CoreTests.hs` - Tests for the core types

Let me start creating these files. First, I'll need to understand what dependencies are needed.

Based on the issue requirements:
- `EntityId` based on `UUID`
- Phantom-typed wrappers for different ID types
- `Component` typeclass
- `World` with heterogeneous storage using `TVar Any`
- Agent and Toolbox components
- STM for concurrency

Let me create the module files.
</details>

### 💬 Response

Now I'll create the ECS (Entity-Component-System) core types as specified. Let me start with the type definitions.

### 🔧 Tool Calls

- **bash_write-file**

---

## 👤 Step 13: User Turn



---

## 🤖 Step 14: LLM Turn

### 💭 Thinking Process

<details>
<summary>Click to expand reasoning</summary>

It seems the content was truncated. Let me write the file again with proper content.
</details>

### 💬 Response



### 🔧 Tool Calls

- **bash_write-file**

---

## 👤 Step 15: User Turn



---

## 🤖 Step 16: LLM Turn

### 💭 Thinking Process

<details>
<summary>Click to expand reasoning</summary>

It seems there's an issue with how I'm providing the content. Let me try with a different approach - the issue seems to be related to special characters or formatting. Let me provide a cleaner version.
</details>

### 💬 Response



### 🔧 Tool Calls

- **bash_write-file**

---

## 👤 Step 17: User Turn



---

## 🤖 Step 18: LLM Turn

### 💭 Thinking Process

<details>
<summary>Click to expand reasoning</summary>

The file was created. Now let me create the World module that contains the heterogeneous storage using STM.
</details>

### 💬 Response



### 🔧 Tool Calls

- **bash_write-file**

---

## 👤 Step 19: User Turn



---

## 🤖 Step 20: LLM Turn

### 💭 Thinking Process

<details>
<summary>Click to expand reasoning</summary>

Now let me create the main Core module that exports everything and includes the Agent and Toolbox component definitions.
</details>

### 💬 Response



### 🔧 Tool Calls

- **bash_write-file**

---

## 👤 Step 21: User Turn



---

## 🤖 Step 22: LLM Turn

### 💭 Thinking Process

<details>
<summary>Click to expand reasoning</summary>

The content is being truncated again. Let me try with a simpler approach - writing the content in smaller chunks or avoiding problematic characters. The issue seems to be with special characters like quotes or dashes. Let me rewrite the file with simpler content.
</details>

### 💬 Response



### 🔧 Tool Calls

- **bash_write-file**

---

## 👤 Step 23: User Turn



---

## 🤖 Step 24: LLM Turn

### 💭 Thinking Process

<details>
<summary>Click to expand reasoning</summary>

Now let me create the test file.
</details>

### 💬 Response



### 🔧 Tool Calls

- **bash_write-file**

---

## 👤 Step 25: User Turn



---

## 🤖 Step 26: LLM Turn

### 💭 Thinking Process

<details>
<summary>Click to expand reasoning</summary>

Now I need to update the test Main.hs to include the new tests, and also update the cabal file to include the new modules.
</details>

### 💬 Response



### 🔧 Tool Calls

- **bash_read-file**

---

## 👤 Step 27: User Turn



---

## 🤖 Step 28: LLM Turn

### 💭 Thinking Process

<details>
<summary>Click to expand reasoning</summary>

Now I need to update the test Main.hs to include the new OS Core tests. Let me create a patch to add the import and include it in the tests.
</details>

### 💬 Response



### 🔧 Tool Calls

- **bash_write-file**

---

## 👤 Step 29: User Turn



---

## 🤖 Step 30: LLM Turn

### 💭 Thinking Process

<details>
<summary>Click to expand reasoning</summary>

Now I need to update the cabal file to include the new modules. Let me read the cabal file again and then update it.
</details>

### 💬 Response

Now let me update the cabal file to include the new modules:

### 🔧 Tool Calls

- **bash_read-file**

---

## 👤 Step 31: User Turn



---

## 🤖 Step 32: LLM Turn

### 💭 Thinking Process

<details>
<summary>Click to expand reasoning</summary>

I need to add the new modules to the cabal file. Let me update both the library section (to add the OS Core modules) and the test-suite section (to add the OS Core tests).
</details>

### 💬 Response



### 🔧 Tool Calls

- **bash_write-file**

---

## 👤 Step 33: User Turn



---

## 🤖 Step 34: LLM Turn

### 💭 Thinking Process

<details>
<summary>Click to expand reasoning</summary>

Now let me compile the code to check for any errors.
</details>

### 💬 Response

Now let's compile the code to check for any errors:

### 🔧 Tool Calls

- **bash_check-code**

---

## 👤 Step 35: User Turn



---

## 🤖 Step 36: LLM Turn

### 💭 Thinking Process

<details>
<summary>Click to expand reasoning</summary>

The build failed because we need to add `hashable` to the build-depends. Let me update the cabal file to include this dependency.
</details>

### 💬 Response

I need to add the `hashable` dependency to the cabal file:

### 🔧 Tool Calls

- **bash_read-file**

---

## 👤 Step 37: User Turn



---

## 🤖 Step 38: LLM Turn

### 💭 Thinking Process

<details>
<summary>Click to expand reasoning</summary>

I need to add `hashable` to the library's build-depends. Let me update the cabal file.
</details>

### 💬 Response



### 🔧 Tool Calls

- **bash_write-file**

---

## 👤 Step 39: User Turn



---

## 🤖 Step 40: LLM Turn

### 💭 Thinking Process

<details>
<summary>Click to expand reasoning</summary>

Now let me try compiling again.
</details>

### 💬 Response



### 🔧 Tool Calls

- **bash_check-code**

---

## 👤 Step 41: User Turn



---

## 🤖 Step 42: LLM Turn

### 💭 Thinking Process

<details>
<summary>Click to expand reasoning</summary>

We have an unused import error. Let me fix the Types.hs file to remove the unused import.
</details>

### 💬 Response

Let me fix the unused import in Types.hs:

### 🔧 Tool Calls

- **bash_read-file**

---

## 👤 Step 43: User Turn



---

## 🤖 Step 44: LLM Turn

### 💭 Thinking Process

<details>
<summary>Click to expand reasoning</summary>

The import `Data.Time (UTCTime)` is unused in this module. Let me remove it.
</details>

### 💬 Response



### 🔧 Tool Calls

- **bash_write-file**

---

## 👤 Step 45: User Turn



---

## 🤖 Step 46: LLM Turn

### 💭 Thinking Process

<details>
<summary>Click to expand reasoning</summary>

Now let me try compiling again.
</details>

### 💬 Response



### 🔧 Tool Calls

- **bash_check-code**

---

## 👤 Step 47: User Turn



---

## 🤖 Step 48: LLM Turn

### 💭 Thinking Process

<details>
<summary>Click to expand reasoning</summary>

I need to fix the World.hs file. It's missing some imports:
1. `Any` type from `GHC.Exts`
2. Need to export `newEntityId` in the Types module

Let me fix both issues.
</details>

### 💬 Response

Let me fix the World.hs file with proper imports:

### 🔧 Tool Calls

- **bash_write-file**

---

## 👤 Step 49: User Turn



---

## 🤖 Step 50: LLM Turn

### 💭 Thinking Process

<details>
<summary>Click to expand reasoning</summary>

Now let me try compiling again.
</details>

### 💬 Response



### 🔧 Tool Calls

- **bash_check-code**

---

## 👤 Step 51: User Turn



---

## 🤖 Step 52: LLM Turn

### 💭 Thinking Process

<details>
<summary>Click to expand reasoning</summary>

The issue is that the functions `removeComponent`, `hasComponent`, and `allEntitiesWithComponent` are ambiguous because the type `a` is not used in the function arguments. We need to add `TypeApplications` to use these functions or add `AllowAmbiguousTypes` and require explicit type applications. Let me enable `AllowAmbiguousTypes` since these functions are meant to be used with type applications.
</details>

### 💬 Response



### 🔧 Tool Calls

- **bash_write-file**

---

## 👤 Step 53: User Turn



---

## 🤖 Step 54: LLM Turn

### 💭 Thinking Process

<details>
<summary>Click to expand reasoning</summary>

Now let me try compiling again.
</details>

### 💬 Response



### 🔧 Tool Calls

- **bash_check-code**

---

## 👤 Step 55: User Turn



---

## 🤖 Step 56: LLM Turn

### 💭 Thinking Process

<details>
<summary>Click to expand reasoning</summary>

The issue is that `store` is both a record accessor and a local variable. Let me fix this.
</details>

### 💬 Response



### 🔧 Tool Calls

- **bash_write-file**

---

## 👤 Step 57: User Turn



---

## 🤖 Step 58: LLM Turn

### 💭 Thinking Process

<details>
<summary>Click to expand reasoning</summary>

Now let me try compiling again.
</details>

### 💬 Response



### 🔧 Tool Calls

- **bash_check-code**

---

## 👤 Step 59: User Turn



---

## 🤖 Step 60: LLM Turn

### 💭 Thinking Process

<details>
<summary>Click to expand reasoning</summary>

There's an unused import in the Core.hs file. Let me fix that.
</details>

### 💬 Response



### 🔧 Tool Calls

- **bash_write-file**

---

## 👤 Step 61: User Turn



---

## 🤖 Step 62: LLM Turn

### 💭 Thinking Process

<details>
<summary>Click to expand reasoning</summary>

Now let me try compiling again.
</details>

### 💬 Response



### 🔧 Tool Calls

- **bash_check-code**

---

## 👤 Step 63: User Turn



---

## 🤖 Step 64: LLM Turn

### 💭 Thinking Process

<details>
<summary>Click to expand reasoning</summary>

I need to add `stm` and `hashable` to the test-suite build-depends.
</details>

### 💬 Response



### 🔧 Tool Calls

- **bash_read-file**

---

## 👤 Step 65: User Turn



---

## 🤖 Step 66: LLM Turn

### 💭 Thinking Process

<details>
<summary>Click to expand reasoning</summary>

I need to add `stm` and `hashable` to the test-suite build-depends.
</details>

### 💬 Response



### 🔧 Tool Calls

- **bash_write-file**

---

## 👤 Step 67: User Turn



---

## 🤖 Step 68: LLM Turn

### 💭 Thinking Process

<details>
<summary>Click to expand reasoning</summary>

Now let me try compiling again.
</details>

### 💬 Response



### 🔧 Tool Calls

- **bash_check-code**

---

## 👤 Step 69: User Turn



---

## 🤖 Step 70: LLM Turn

### 💭 Thinking Process

<details>
<summary>Click to expand reasoning</summary>

The test file is missing the `Generic` import. Let me fix that.
</details>

### 💬 Response



### 🔧 Tool Calls

- **bash_write-file**

---

## 👤 Step 71: User Turn



---

## 🤖 Step 72: LLM Turn

### 💭 Thinking Process

<details>
<summary>Click to expand reasoning</summary>

Now let me try compiling again.
</details>

### 💬 Response



### 🔧 Tool Calls

- **bash_check-code**

---

## 👤 Step 73: User Turn



---

## 🤖 Step 74: LLM Turn

### 💭 Thinking Process

<details>
<summary>Click to expand reasoning</summary>

I need to add the `DeriveGeneric` extension to the test file.
</details>

### 💬 Response



### 🔧 Tool Calls

- **bash_write-file**

---

## 👤 Step 75: User Turn



---

## 🤖 Step 76: LLM Turn

### 💭 Thinking Process

<details>
<summary>Click to expand reasoning</summary>

Now let me try compiling again.
</details>

### 💬 Response



### 🔧 Tool Calls

- **bash_check-code**

---

## 👤 Step 77: User Turn



---

## 🤖 Step 78: LLM Turn

### 💭 Thinking Process

<details>
<summary>Click to expand reasoning</summary>

The test file has errors because `toolboxSettings` and `bindingConfig` expect `Value` from aeson, but I'm providing a ByteString. Let me fix these tests by using the proper Aeson Value type.
</details>

### 💬 Response



### 🔧 Tool Calls

- **bash_write-file**

---

## 👤 Step 79: User Turn



---

## 🤖 Step 80: LLM Turn

### 💭 Thinking Process

<details>
<summary>Click to expand reasoning</summary>

Now let me try compiling again.
</details>

### 💬 Response



### 🔧 Tool Calls

- **bash_check-code**

---

## 👤 Step 81: User Turn



---

## 🤖 Step 82: LLM Turn

### 💭 Thinking Process

<details>
<summary>Click to expand reasoning</summary>

There are two sets of issues:

1. Need to add `Eq` instances to the component types in Core.hs
2. Need to add type annotations in some test cases where `getComponent` is used

Let me fix these issues.
</details>

### 💬 Response



### 🔧 Tool Calls

- **bash_write-file**

---

## 👤 Step 83: User Turn



---

## 🤖 Step 84: LLM Turn

### 💭 Thinking Process

<details>
<summary>Click to expand reasoning</summary>

Now let me also fix the test file to add type annotations.
</details>

### 💬 Response



### 🔧 Tool Calls

- **bash_write-file**

---

## 👤 Step 85: User Turn



---

## 🤖 Step 86: LLM Turn

### 💭 Thinking Process

<details>
<summary>Click to expand reasoning</summary>

Now let me try compiling again.
</details>

### 💬 Response



### 🔧 Tool Calls

- **bash_check-code**

---

## 👤 Step 87: User Turn



---

## 🤖 Step 88: LLM Turn

### 💭 Thinking Process

<details>
<summary>Click to expand reasoning</summary>

The code compiled successfully. Now let me run the tests to make sure everything works correctly.
</details>

### 💬 Response

Now let's run the tests to verify everything works:

### 🔧 Tool Calls

- **bash_check-code**

---

## 👤 Step 89: User Turn



---

## 🤖 Step 90: LLM Turn

### 💭 Thinking Process

<details>
<summary>Click to expand reasoning</summary>

All 450 tests passed. Let me provide a summary of what was implemented.
</details>

### 💬 Response

All tests pass. Here's a summary of what was implemented:

## Summary

### Files Created

1. **`src/System/Agents/OS/Core/Types.hs`** - Core ECS types including:
   - `EntityId` with UUID-based unique identifiers
   - Phantom-typed wrappers: `AgentId`, `ToolboxId`, `ConversationId`, `TurnId`, `ToolCallId`, `ResourceId`
   - `ComponentTypeId` for type-level component identification
   - `Component` typeclass for components
   - `ComponentStore` for O(1) component storage with HashMap

2. **`src/System/Agents/OS/Core/World.hs`** - World storage with:
   - `World` type containing heterogeneous component stores via `TVar Any`
   - STM-based concurrent access for thread safety
   - Component operations: `getComponent`, `setComponent`, `modifyComponent`, `removeComponent`, `hasComponent`
   - Entity operations: `createEntity`, `entityExists`
   - Query operations: `allEntitiesWithComponent`

3. **`src/System/Agents/OS/Core.hs`** - Main module exposing:
   - Agent components: `AgentConfig`, `AgentState`, `AgentStatus`
   - Toolbox components: `ToolboxConfig`, `ToolboxState`, `ToolboxBinding`
   - Supporting types: `ToolboxType`, `ResourceScope`, `ToolboxStatus`, `ModelConfig`
   - All component instances with manually assigned IDs (1-5)

4. **`test/OS/CoreTests.hs`** - Comprehensive test suite with:
   - Entity ID generation and phantom type tests
   - Component storage and world operation tests
   - Agent and toolbox component validation
   - JSON round-trip serialization tests

### Key Design Decisions

1. **Type Erasure with `Any`**: Enables heterogeneous storage while keeping type safety at the API level through TypeApplications
2. **STM for Concurrency**: Composable transactions for safe concurrent access across multiple entities
3. **Manual Component IDs**: Simple integer IDs (1-5) assigned manually to prevent collisions
4. **Phantom Types**: Type-safe entity ID wrappers prevent mixing up different entity types

### Tradeoffs Documented

1. **Type Erasure vs Type Safety**: Using `TVar Any` requires careful casting but enables extensible storage
2. **STM vs MVar**: STM chosen for composable transactions in complex resource coordination
3. **Manual ID Assignment**: Current approach uses manual IDs; Template Haskell could auto-generate in the future
