@dalmasonto/taskflow-mcp 1.0.27 → 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 +16 -13
- package/package.json +1 -1
package/dist/agent-registry.js
CHANGED
|
@@ -27,25 +27,20 @@ function detectTmuxPane(pid) {
|
|
|
27
27
|
return null;
|
|
28
28
|
}
|
|
29
29
|
/** Generate a unique agent name from the project folder, auto-suffixing on collision.
|
|
30
|
-
*
|
|
30
|
+
* A name is available if no row exists or the existing row's process is dead. */
|
|
31
31
|
function generateName(folderName) {
|
|
32
32
|
const db = getDb();
|
|
33
|
-
const
|
|
33
|
+
const isAvailable = (name) => {
|
|
34
34
|
const row = db.prepare('SELECT * FROM agent_registry WHERE name = ?').get(name);
|
|
35
35
|
if (!row)
|
|
36
|
-
return true; // name is free
|
|
37
|
-
if (!isAlive(row.pid)) {
|
|
38
|
-
// Dead entry — remove it so the name can be reused via INSERT
|
|
39
|
-
db.prepare('DELETE FROM agent_registry WHERE id = ?').run(row.id);
|
|
40
36
|
return true;
|
|
41
|
-
|
|
42
|
-
return false; // name is taken by a live agent
|
|
37
|
+
return !isAlive(row.pid);
|
|
43
38
|
};
|
|
44
|
-
if (
|
|
39
|
+
if (isAvailable(folderName))
|
|
45
40
|
return folderName;
|
|
46
41
|
for (let i = 2; i < 100; i++) {
|
|
47
42
|
const candidate = `${folderName}:${i}`;
|
|
48
|
-
if (
|
|
43
|
+
if (isAvailable(candidate))
|
|
49
44
|
return candidate;
|
|
50
45
|
}
|
|
51
46
|
return `${folderName}:${Date.now()}`;
|
|
@@ -110,11 +105,19 @@ export function registerAgent(options) {
|
|
|
110
105
|
logActivity('agent_connected', `Agent "${newName}" reconnected`, { entityType: 'agent' });
|
|
111
106
|
return newName;
|
|
112
107
|
}
|
|
113
|
-
// Priority 3:
|
|
114
|
-
// 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
|
|
115
110
|
const baseName = options?.customName || folderName;
|
|
116
111
|
const name = entries.length === 0 ? baseName : generateName(baseName);
|
|
117
|
-
|
|
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
|
+
}
|
|
118
121
|
const row = db.prepare('SELECT * FROM agent_registry WHERE name = ?').get(name);
|
|
119
122
|
broadcast('agent_connected', { entity: 'agent', action: 'agent_connected', payload: row });
|
|
120
123
|
logActivity('agent_connected', `Agent "${name}" connected`, { entityType: 'agent' });
|