Skip to content

Commit d322e09

Browse files
committed
Command Center
1 parent 4af860b commit d322e09

3 files changed

Lines changed: 42 additions & 46 deletions

File tree

lib/commandCenter/adminControls.js

Lines changed: 29 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ const agentStore = require('../agentStore.js');
88
const agentRunner = require('../agentRunner.js');
99
const heartbeat = require('../heartbeat.js');
1010
const pipelineRunner = require('../pipelineRunner.js');
11-
const personality = require('../personality.js');
12-
const structuredMemory = require('../structuredMemory.js');
13-
const projectStore = require('../projectStore.js');
1411
const hiveStore = require('../hiveMind/store.js');
1512

1613
function safeRm(targetPath) {
@@ -56,56 +53,45 @@ function stopAllAgents({ markTasksBlocked = true } = {}) {
5653
return { ok: true, stoppedRunner: true, tasksPaused: updated.length };
5754
}
5855

59-
function clearAllMemory() {
60-
// Stop agents first to avoid writing while deleting.
61-
stopAllAgents({ markTasksBlocked: false });
56+
function clearAllMemory({ scopeUser = '' } = {}) {
57+
// Clear only Command Center scoped data (do NOT touch user/project/global memory stores).
58+
const userKey = hiveStore.normalizeScopeUser(scopeUser);
59+
const scopedHiveDir = userKey
60+
? path.join(hiveStore.HIVEMIND_DIR, 'users', userKey)
61+
: hiveStore.HIVEMIND_DIR;
6262

63-
const dataDir = personality.DATA_DIR;
64-
const usersDir = path.join(dataDir, 'users');
65-
const agentsDir = path.join(dataDir, 'agents');
66-
const vectorsDir = path.join(dataDir, 'vectors');
67-
const hivemindDir = hiveStore.HIVEMIND_DIR;
68-
const projectsDir = projectStore.PROJECTS_DIR;
63+
// 1) Remove scoped Command Center snapshot/events.
64+
safeRm(scopedHiveDir);
6965

70-
// 1) User/global freeform memory + behavior + personality
71-
safeWriteFile(personality.MEMORY_PATH, '');
72-
safeWriteFile(personality.PERSONALITY_PATH, '');
73-
safeWriteFile(personality.BEHAVIOR_PATH, '');
74-
75-
// 2) Structured memory (global) + per-user (wipe entire users dir; then restore empty per-user stores lazily)
76-
safeRm(structuredMemory.STRUCTURED_PATH);
77-
safeRm(usersDir);
78-
79-
// 3) Hive mind state + events
80-
safeRm(hivemindDir);
81-
82-
// 4) RAG vectors
83-
safeRm(vectorsDir);
84-
85-
// 5) Agent “strategy memory” + tasks/logs
86-
safeRm(agentsDir);
87-
88-
// 6) Project memory files (keep project meta, only wipe memory.md)
66+
// 2) Remove scoped Command Center tasks (keep non-command-center tasks).
67+
let deletedTasks = 0;
8968
try {
90-
if (fs.existsSync(projectsDir)) {
91-
const dirs = fs.readdirSync(projectsDir, { withFileTypes: true }).filter(d => d.isDirectory());
92-
for (const d of dirs) {
93-
const memPath = path.join(projectsDir, d.name, projectStore.MEMORY_FILENAME);
94-
safeWriteFile(memPath, '');
69+
const index = agentStore.listTasks();
70+
for (const entry of index) {
71+
if (!entry || !entry.id) continue;
72+
const task = agentStore.getTask(entry.id);
73+
if (!task) continue;
74+
const owner = String(task.ownerUser || '');
75+
const tags = Array.isArray(task.tags) ? task.tags : [];
76+
const isCommandCenterTask = !!task.parentMissionId || tags.includes('command_center');
77+
if (owner === String(scopeUser || '') && isCommandCenterTask) {
78+
agentStore.deleteTask(task.id);
79+
deletedTasks += 1;
9580
}
9681
}
9782
} catch (_) {}
9883

9984
return {
10085
ok: true,
86+
scopeUser: scopeUser || null,
87+
deletedTasks,
10188
wiped: {
102-
freeform: true,
103-
structured: true,
104-
users: true,
105-
hivemind: true,
106-
ragVectors: true,
107-
agents: true,
108-
projectMemory: true
89+
commandCenterScopedHive: true,
90+
commandCenterScopedTasks: true,
91+
userMemory: false,
92+
projectMemory: false,
93+
ragVectors: false,
94+
globalStructuredMemory: false
10995
}
11096
};
11197
}

public/command-center.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ <h2>DANGER ZONE</h2>
135135
</div>
136136
<div class="cc-danger-card">
137137
<div class="cc-danger-title">Clear all memory</div>
138-
<div class="cc-danger-desc">Wipes memory stores (freeform, structured, HiveMind, RAG vectors, agent strategy/tasks, project memory).</div>
138+
<div class="cc-danger-desc">Clears only your Command Center scoped data (missions/events + command-center tasks). Does not delete user memory, project memory, or RAG vectors.</div>
139139
<input id="ccClearConfirm" class="cc-danger-input" type="text" placeholder='Type: CLEAR ALL MEMORY' />
140140
<button id="ccClearAllBtn" class="btn btn-small btn-danger">CLEAR ALL MEMORY</button>
141141
</div>

server.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2489,12 +2489,22 @@ app.get('/api/command-center/status', requireAdmin, (req, res) => {
24892489

24902490
app.post('/api/command-center/clear-all-memory', requireAdmin, (req, res) => {
24912491
try {
2492+
const scopeUser = getScopeUser(req);
24922493
const confirm = req.body && req.body.confirm != null ? String(req.body.confirm).trim() : '';
24932494
if (confirm !== 'CLEAR ALL MEMORY') return res.status(400).json({ error: 'Confirmation phrase must be exactly: CLEAR ALL MEMORY' });
2494-
const result = commandCenterAdmin.clearAllMemory();
2495+
const result = commandCenterAdmin.clearAllMemory({ scopeUser });
24952496
// hiveStore may have been cleared; best-effort write after wipe.
24962497
try {
2497-
hiveStore.appendEvent({ type: 'admin_clear_all_memory', source: 'command_center', message: 'Admin cleared all memory', payload: result });
2498+
hiveStore.appendEvent(
2499+
{
2500+
type: 'admin_clear_all_memory',
2501+
source: 'command_center',
2502+
user: scopeUser || null,
2503+
message: 'Admin cleared Command Center scoped memory',
2504+
payload: result
2505+
},
2506+
{ scopeUser }
2507+
);
24982508
} catch (_) {}
24992509
res.json(result);
25002510
} catch (e) {

0 commit comments

Comments
 (0)