Skip to content

Commit 295a309

Browse files
committed
adding context files for AI tools (experimental)
1 parent b776932 commit 295a309

File tree

50 files changed

+18105
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+18105
-0
lines changed

ai-context/global-summary.md

Lines changed: 278 additions & 0 deletions
Large diffs are not rendered by default.

ai-context/network-summary.md

Lines changed: 524 additions & 0 deletions
Large diffs are not rendered by default.

internal/audio/context.md

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# Audio System Context
2+
3+
## Overview
4+
5+
The `internal/audio` package provides a simple audio configuration management system for the GoMud game engine. It handles loading and retrieving audio file configurations that can be used throughout the game for sound effects and music.
6+
7+
## Key Components
8+
9+
### Core Files
10+
- **audio.go**: Main audio configuration management functionality
11+
12+
### Key Structures
13+
14+
#### AudioConfig
15+
```go
16+
type AudioConfig struct {
17+
FilePath string `yaml:"filepath,omitempty"`
18+
Volume int `yaml:"volume,omitempty"`
19+
}
20+
```
21+
Represents an audio file configuration with file path and volume settings.
22+
23+
### Key Functions
24+
25+
#### Configuration Loading
26+
- **LoadAudioConfig()**: Loads audio configurations from `_datafiles/audio.yaml` file
27+
- Clears existing configurations and reloads from file
28+
- Uses YAML unmarshaling to populate the audioLookup map
29+
- Logs loading time and count of loaded configurations
30+
- Panics on file read or YAML parsing errors
31+
32+
#### Audio Retrieval
33+
- **GetFile(identifier string) AudioConfig**: Retrieves audio configuration by identifier
34+
- Returns AudioConfig if found, empty AudioConfig if not found
35+
- Thread-safe lookup from the audioLookup map
36+
37+
### Global State
38+
- **audioLookup**: `map[string]AudioConfig` - In-memory cache of all loaded audio configurations
39+
40+
## Dependencies
41+
42+
### Internal Dependencies
43+
- `internal/configs`: For accessing file path configurations
44+
- `internal/mudlog`: For logging audio loading operations
45+
46+
### External Dependencies
47+
- `gopkg.in/yaml.v2`: For YAML configuration parsing
48+
- `github.com/pkg/errors`: For error wrapping
49+
- Standard library: `os`, `time`
50+
51+
## Usage Patterns
52+
53+
### Loading Audio Configurations
54+
```go
55+
// Load all audio configurations from file
56+
audio.LoadAudioConfig()
57+
```
58+
59+
### Retrieving Audio Files
60+
```go
61+
// Get audio configuration for a specific sound
62+
audioConfig := audio.GetFile("sword_clang")
63+
if audioConfig.FilePath != "" {
64+
// Use the audio file
65+
playSound(audioConfig.FilePath, audioConfig.Volume)
66+
}
67+
```
68+
69+
## Configuration File Format
70+
71+
The system expects an `audio.yaml` file in the data files directory with the following structure:
72+
```yaml
73+
sound_identifier:
74+
filepath: "path/to/audio/file.wav"
75+
volume: 75
76+
another_sound:
77+
filepath: "path/to/another/file.mp3"
78+
volume: 50
79+
```
80+
81+
## Error Handling
82+
83+
- **File Loading Errors**: Panics if the audio.yaml file cannot be read or parsed
84+
- **Missing Configurations**: Returns empty AudioConfig for non-existent identifiers
85+
- **Thread Safety**: Uses map lookups which are safe for concurrent reads
86+
87+
## Performance Considerations
88+
89+
- **Memory Usage**: All audio configurations are loaded into memory at startup
90+
- **Lookup Performance**: O(1) map lookups for audio configuration retrieval
91+
- **Reload Strategy**: Complete replacement of configuration map on reload
92+
93+
## Integration Points
94+
95+
### Game Engine Integration
96+
- Used by sound effect systems to get audio file paths and volume settings
97+
- Integrated with MSP (MUD Sound Protocol) for client audio playback
98+
- Referenced by scripting system for dynamic audio playback
99+
100+
### Configuration Management
101+
- Follows standard GoMud configuration loading patterns
102+
- Uses centralized file path configuration system
103+
- Supports hot-reloading of audio configurations
104+
105+
## Future Considerations
106+
107+
- Could be extended to support audio format validation
108+
- Potential for audio streaming or caching mechanisms
109+
- Integration with client-side audio capabilities
110+
- Support for audio playlists or sequences
Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
# Bad Input Tracker Context
2+
3+
## Overview
4+
5+
The `internal/badinputtracker` package provides a thread-safe system for tracking and analyzing invalid or unrecognized user commands in the GoMud game engine. This helps administrators identify common user input patterns that might indicate missing commands or user confusion.
6+
7+
## Key Components
8+
9+
### Core Files
10+
- **badinputtracker.go**: Main bad input tracking functionality
11+
- **badinputtracker_test.go**: Comprehensive unit tests for all tracking functions
12+
13+
### Key Functions
14+
15+
#### Command Tracking
16+
- **TrackBadCommand(cmd string, rest string)**: Records an invalid command attempt
17+
- Thread-safe using mutex locking
18+
- Tracks both the command and its arguments separately
19+
- Increments counter for repeated identical bad commands
20+
- Creates nested map structure: `badCommands[cmd][rest]`
21+
22+
#### Data Retrieval
23+
- **GetBadCommands() map[string]int**: Returns flattened view of all tracked bad commands
24+
- Thread-safe read operation
25+
- Combines command and arguments into single string key format: `"cmd rest"`
26+
- Returns copy of data with occurrence counts
27+
- Safe for concurrent access
28+
29+
#### Data Management
30+
- **Clear()**: Resets all tracked bad command data
31+
- Thread-safe operation using mutex
32+
- Completely reinitializes the badCommands map
33+
- Used for periodic cleanup or testing
34+
35+
### Global State
36+
- **badCommands**: `map[string]map[string]int` - Nested map tracking command failures
37+
- First level key: command name
38+
- Second level key: command arguments/rest
39+
- Value: occurrence count
40+
- **lock**: `sync.Mutex` - Ensures thread-safe access to badCommands map
41+
42+
## Data Structure Design
43+
44+
### Nested Map Structure
45+
```go
46+
badCommands = map[string]map[string]int{
47+
"unknowncmd": {
48+
"arg1 arg2": 3,
49+
"different args": 1,
50+
},
51+
"anotherbad": {
52+
"some args": 2,
53+
},
54+
}
55+
```
56+
57+
### Flattened Output Format
58+
```go
59+
map[string]int{
60+
"unknowncmd arg1 arg2": 3,
61+
"unknowncmd different args": 1,
62+
"anotherbad some args": 2,
63+
}
64+
```
65+
66+
## Thread Safety
67+
68+
### Concurrency Design
69+
- **Mutex Protection**: All operations protected by sync.Mutex
70+
- **Read/Write Safety**: Prevents data races between tracking and retrieval
71+
- **Lock Scope**: Minimal lock duration to reduce contention
72+
- **Safe Iteration**: GetBadCommands creates a copy to avoid holding locks during iteration
73+
74+
## Usage Patterns
75+
76+
### Tracking Bad Commands
77+
```go
78+
// Track a bad command attempt
79+
badinputtracker.TrackBadCommand("unknowncmd", "some arguments")
80+
81+
// Track repeated attempts (increments counter)
82+
badinputtracker.TrackBadCommand("unknowncmd", "some arguments")
83+
```
84+
85+
### Retrieving Analytics
86+
```go
87+
// Get all bad commands with counts
88+
badCommands := badinputtracker.GetBadCommands()
89+
for cmdWithArgs, count := range badCommands {
90+
log.Printf("Bad command '%s' attempted %d times", cmdWithArgs, count)
91+
}
92+
```
93+
94+
### Periodic Cleanup
95+
```go
96+
// Clear tracking data (e.g., daily reset)
97+
badinputtracker.Clear()
98+
```
99+
100+
## Integration Points
101+
102+
### Command Processing
103+
- Called when user input doesn't match any valid command
104+
- Integrated into main command parsing pipeline
105+
- Helps identify gaps in command coverage
106+
107+
### Administrative Tools
108+
- Data accessible via admin commands for analysis
109+
- Used in web admin interface for usage statistics
110+
- Helps guide development of new commands
111+
112+
### Logging and Monitoring
113+
- Provides data for system monitoring
114+
- Helps identify user experience issues
115+
- Supports usage pattern analysis
116+
117+
## Testing Coverage
118+
119+
### Comprehensive Test Suite
120+
- **Single Command Tracking**: Basic functionality verification
121+
- **Multiple Command Handling**: Different commands and arguments
122+
- **Counter Increment**: Repeated command tracking
123+
- **Complex Scenarios**: Mixed command patterns
124+
- **Clear Functionality**: Data reset verification
125+
- **Thread Safety**: Concurrent access patterns
126+
127+
### Test Scenarios
128+
- Empty state handling
129+
- Single vs multiple command tracking
130+
- Increment behavior for identical commands
131+
- Mixed command and argument combinations
132+
- Clear operation verification
133+
134+
## Performance Considerations
135+
136+
### Memory Usage
137+
- **Bounded Growth**: Limited by unique command/argument combinations
138+
- **Efficient Storage**: Nested map structure minimizes memory overhead
139+
- **Cleanup Strategy**: Manual clearing prevents unbounded growth
140+
141+
### Lookup Performance
142+
- **O(1) Access**: Map-based storage for fast lookups
143+
- **Minimal Locking**: Short critical sections for good concurrency
144+
- **Copy Strategy**: GetBadCommands creates copy to minimize lock time
145+
146+
## Error Handling
147+
148+
### Graceful Degradation
149+
- **No Panics**: All operations handle edge cases gracefully
150+
- **Empty State**: Safe handling of empty or uninitialized state
151+
- **Concurrent Safety**: No data corruption under concurrent access
152+
153+
## Administrative Use Cases
154+
155+
### Usage Analysis
156+
- Identify commonly mistyped commands
157+
- Discover missing command aliases
158+
- Analyze user behavior patterns
159+
- Guide user interface improvements
160+
161+
### System Monitoring
162+
- Track system usage patterns
163+
- Identify potential bot or automated activity
164+
- Monitor user experience quality
165+
- Support capacity planning
166+
167+
## Future Enhancements
168+
169+
- Time-based tracking for temporal analysis
170+
- Integration with user session tracking
171+
- Automatic suggestion system for similar commands
172+
- Configurable retention policies
173+
- Export functionality for external analysis

0 commit comments

Comments
 (0)