@dalmasonto/taskflow-mcp 1.0.26 → 1.0.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent-registry.js +21 -9
- package/package.json +1 -1
package/dist/agent-registry.js
CHANGED
|
@@ -26,17 +26,21 @@ function detectTmuxPane(pid) {
|
|
|
26
26
|
catch { /* tmux not available */ }
|
|
27
27
|
return null;
|
|
28
28
|
}
|
|
29
|
-
/** Generate a unique agent name from the project folder, auto-suffixing on collision
|
|
29
|
+
/** Generate a unique agent name from the project folder, auto-suffixing on collision.
|
|
30
|
+
* A name is available if no row exists or the existing row's process is dead. */
|
|
30
31
|
function generateName(folderName) {
|
|
31
32
|
const db = getDb();
|
|
32
|
-
const
|
|
33
|
-
|
|
33
|
+
const isAvailable = (name) => {
|
|
34
|
+
const row = db.prepare('SELECT * FROM agent_registry WHERE name = ?').get(name);
|
|
35
|
+
if (!row)
|
|
36
|
+
return true;
|
|
37
|
+
return !isAlive(row.pid);
|
|
38
|
+
};
|
|
39
|
+
if (isAvailable(folderName))
|
|
34
40
|
return folderName;
|
|
35
|
-
}
|
|
36
41
|
for (let i = 2; i < 100; i++) {
|
|
37
42
|
const candidate = `${folderName}:${i}`;
|
|
38
|
-
|
|
39
|
-
if (!row || !isAlive(row.pid))
|
|
43
|
+
if (isAvailable(candidate))
|
|
40
44
|
return candidate;
|
|
41
45
|
}
|
|
42
46
|
return `${folderName}:${Date.now()}`;
|
|
@@ -101,11 +105,19 @@ export function registerAgent(options) {
|
|
|
101
105
|
logActivity('agent_connected', `Agent "${newName}" reconnected`, { entityType: 'agent' });
|
|
102
106
|
return newName;
|
|
103
107
|
}
|
|
104
|
-
// Priority 3:
|
|
105
|
-
// Generate a suffixed name to avoid collision
|
|
108
|
+
// Priority 3: No reusable disconnected entry — this is a new or concurrent agent
|
|
109
|
+
// Generate a suffixed name to avoid collision with live agents
|
|
106
110
|
const baseName = options?.customName || folderName;
|
|
107
111
|
const name = entries.length === 0 ? baseName : generateName(baseName);
|
|
108
|
-
|
|
112
|
+
// Upsert: if a dead entry with this name exists (from another project path),
|
|
113
|
+
// reuse it in-place to preserve its message history. Otherwise insert fresh.
|
|
114
|
+
const stale = db.prepare('SELECT * FROM agent_registry WHERE name = ?').get(name);
|
|
115
|
+
if (stale) {
|
|
116
|
+
db.prepare('UPDATE agent_registry SET project_path = ?, pid = ?, tmux_pane = ?, status = ?, connected_at = ?, disconnected_at = NULL WHERE id = ?').run(projectPath, agentPid, tmuxPane, 'connected', ts, stale.id);
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
db.prepare('INSERT INTO agent_registry (name, project_path, pid, tmux_pane, status, connected_at) VALUES (?, ?, ?, ?, ?, ?)').run(name, projectPath, agentPid, tmuxPane, 'connected', ts);
|
|
120
|
+
}
|
|
109
121
|
const row = db.prepare('SELECT * FROM agent_registry WHERE name = ?').get(name);
|
|
110
122
|
broadcast('agent_connected', { entity: 'agent', action: 'agent_connected', payload: row });
|
|
111
123
|
logActivity('agent_connected', `Agent "${name}" connected`, { entityType: 'agent' });
|