-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontext_test.cpp
More file actions
194 lines (155 loc) · 7.11 KB
/
Copy pathcontext_test.cpp
File metadata and controls
194 lines (155 loc) · 7.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#include "context_manager.h"
#include "memory_store.h"
#include "logger.h"
#include <iostream>
#include <thread>
#include <chrono>
using namespace ash;
using namespace std::chrono_literals;
void print_context(const Context& ctx) {
std::cout << " Context: " << ctx.id << "\n";
std::cout << " Name: " << ctx.name << "\n";
std::cout << " Type: " << static_cast<int>(ctx.type) << "\n";
std::cout << " Messages: " << ctx.messages.size() << "\n";
std::cout << " Active: " << (ctx.is_active ? "YES" : "NO") << "\n";
std::cout << " Priority: " << ctx.priority << "\n";
}
int main() {
std::cout << "🗂️ Testing Ash's Context Manager...\n\n";
Logger::instance().set_min_level(LogLevel::DEBUG);
// Create dependencies
auto memories = std::make_shared<MemoryStore>("test_contexts.db");
std::cout << "✓ Dependencies initialized\n\n";
// Create context manager
ContextConfig config;
config.max_active_contexts = 5;
config.max_working_memory_messages = 20;
config.inactive_context_timeout = 5.0f; // 5 seconds for testing
auto context_mgr = std::make_shared<ContextManager>(memories, config);
// Test 1: Create contexts
std::cout << "Test 1: Creating contexts\n";
auto discord_ctx = context_mgr->create_context(
ContextType::DISCORD_CHANNEL,
"ash-chat",
{"daniel", "ash"}
);
auto thought_ctx = context_mgr->create_context(
ContextType::INTERNAL_THOUGHT,
"morning-reflection",
{"ash"}
);
auto planning_ctx = context_mgr->create_context(
ContextType::PLANNING,
"phase-1-completion",
{"ash"}
);
std::cout << " Created 3 contexts\n\n";
// Test 2: Add messages to context
std::cout << "Test 2: Adding messages to Discord context\n";
context_mgr->add_message(discord_ctx, ContextMessage{
.author = "daniel",
.content = "Hey Ash, how's the context manager coming along?",
.timestamp = std::chrono::system_clock::now()
});
context_mgr->add_message(discord_ctx, ContextMessage{
.author = "ash",
.content = "Working on it right now! Testing multiple context tracking.",
.timestamp = std::chrono::system_clock::now()
});
context_mgr->add_message(discord_ctx, ContextMessage{
.author = "daniel",
.content = "Nice! Can you handle multiple conversations at once?",
.timestamp = std::chrono::system_clock::now()
});
auto ctx = context_mgr->get_context(discord_ctx);
if (ctx) {
std::cout << " Messages in context: " << ctx->messages.size() << "\n";
std::cout << " History:\n" << ctx->get_history_text() << "\n";
}
// Test 3: Add messages to thought context
std::cout << "Test 3: Adding internal thoughts\n";
context_mgr->add_message(thought_ctx, ContextMessage{
.author = "ash",
.content = "Context management is interesting. I can track multiple conversations and decide which one needs attention.",
.timestamp = std::chrono::system_clock::now()
});
context_mgr->add_message(thought_ctx, ContextMessage{
.author = "ash",
.content = "Phase 1 is almost complete. Just need to finish context manager testing.",
.timestamp = std::chrono::system_clock::now()
});
ctx = context_mgr->get_context(thought_ctx);
if (ctx) {
std::cout << " Thoughts: " << ctx->messages.size() << "\n\n";
}
// Test 4: Context switching
std::cout << "Test 4: Context switching\n";
context_mgr->switch_to_context(discord_ctx);
auto active = context_mgr->get_active_context();
if (active) {
std::cout << " Active context: " << active->name << "\n";
}
context_mgr->switch_to_context(thought_ctx);
active = context_mgr->get_active_context();
if (active) {
std::cout << " Switched to: " << active->name << "\n\n";
}
// Test 5: List all contexts
std::cout << "Test 5: Listing all contexts\n";
auto all_contexts = context_mgr->list_contexts();
std::cout << " Total contexts: " << all_contexts.size() << "\n";
for (const auto& c : all_contexts) {
std::cout << " - " << c.name << " (" << c.messages.size() << " msgs, priority: " << c.priority << ")\n";
}
std::cout << "\n";
// Test 6: Priority management
std::cout << "Test 6: Setting context priorities\n";
context_mgr->set_priority(discord_ctx, 10); // High priority - active conversation
context_mgr->set_priority(thought_ctx, 5); // Medium priority - internal thoughts
context_mgr->set_priority(planning_ctx, 3); // Low priority - planning
all_contexts = context_mgr->list_contexts();
std::cout << " Contexts by priority:\n";
for (const auto& c : all_contexts) {
std::cout << " " << c.priority << ": " << c.name << "\n";
}
std::cout << "\n";
// Test 7: Filter contexts by type
std::cout << "Test 7: Filtering contexts by type\n";
auto discord_contexts = context_mgr->list_contexts(ContextType::DISCORD_CHANNEL);
auto thought_contexts = context_mgr->list_contexts(ContextType::INTERNAL_THOUGHT);
std::cout << " Discord contexts: " << discord_contexts.size() << "\n";
std::cout << " Thought contexts: " << thought_contexts.size() << "\n\n";
// Test 8: Archive context
std::cout << "Test 8: Archiving context\n";
context_mgr->archive_context(planning_ctx);
auto active_contexts = context_mgr->list_contexts(std::nullopt, true);
std::cout << " Active contexts after archiving: " << active_contexts.size() << "\n";
std::cout << " Planning context active: " << (context_mgr->is_active(planning_ctx) ? "YES" : "NO") << "\n\n";
// Test 9: Restore context
std::cout << "Test 9: Restoring archived context\n";
context_mgr->restore_context(planning_ctx);
std::cout << " Planning context active: " << (context_mgr->is_active(planning_ctx) ? "YES" : "NO") << "\n\n";
// Test 10: Get recent messages
std::cout << "Test 10: Getting recent messages\n";
ctx = context_mgr->get_context(discord_ctx);
if (ctx) {
auto recent = ctx->get_recent(2);
std::cout << " Last 2 messages in " << ctx->name << ":\n";
for (const auto& msg : recent) {
std::cout << " " << msg.to_string() << "\n";
}
}
std::cout << "\n";
// Test 11: Automatic maintenance (timeout-based archiving)
std::cout << "Test 11: Testing automatic maintenance\n";
std::cout << " Waiting 6 seconds for timeout...\n";
std::this_thread::sleep_for(6s);
context_mgr->maintenance();
active_contexts = context_mgr->list_contexts(std::nullopt, true);
std::cout << " Active contexts after maintenance: " << active_contexts.size() << "\n";
std::cout << " (Contexts with no recent activity should be archived)\n\n";
std::cout << "✓ Context manager test complete!\n";
std::cout << "🔥 Ash can now track multiple simultaneous conversations.\n";
std::cout << "Next: Integrate all Phase 1 systems together.\n";
return 0;
}