@kendoo.agentdesk/agentdesk 0.7.1 → 0.7.3
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/cli/daemon.mjs +52 -3
- package/package.json +1 -1
package/cli/daemon.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// `agentdesk daemon` — local background daemon for UI-triggered sessions
|
|
2
2
|
|
|
3
3
|
import { spawn } from "child_process";
|
|
4
|
-
import { existsSync, readFileSync, writeFileSync, mkdirSync } from "fs";
|
|
4
|
+
import { existsSync, readFileSync, readdirSync, writeFileSync, mkdirSync } from "fs";
|
|
5
5
|
import { createInterface } from "readline";
|
|
6
6
|
import { join } from "path";
|
|
7
7
|
import { randomUUID } from "crypto";
|
|
@@ -83,6 +83,40 @@ function logSessionMetadata(sessionId, metadata) {
|
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
+
// --- Find project on local filesystem ---
|
|
87
|
+
|
|
88
|
+
function findProjectLocally(projectName) {
|
|
89
|
+
const home = process.env.HOME || process.env.USERPROFILE;
|
|
90
|
+
// Search common code directories for a folder matching the project name
|
|
91
|
+
const searchRoots = [
|
|
92
|
+
home,
|
|
93
|
+
join(home, "code"),
|
|
94
|
+
join(home, "projects"),
|
|
95
|
+
join(home, "src"),
|
|
96
|
+
join(home, "dev"),
|
|
97
|
+
join(home, "workspace"),
|
|
98
|
+
join(home, "repos"),
|
|
99
|
+
join(home, "Documents"),
|
|
100
|
+
join(home, "Desktop"),
|
|
101
|
+
];
|
|
102
|
+
|
|
103
|
+
for (const root of searchRoots) {
|
|
104
|
+
if (!existsSync(root)) continue;
|
|
105
|
+
// Check direct child: ~/code/projectName
|
|
106
|
+
const candidate = join(root, projectName);
|
|
107
|
+
if (existsSync(join(candidate, ".agentdesk.json"))) return candidate;
|
|
108
|
+
// Check one level deeper: ~/code/org/projectName
|
|
109
|
+
try {
|
|
110
|
+
for (const sub of readdirSync(root, { withFileTypes: true })) {
|
|
111
|
+
if (!sub.isDirectory()) continue;
|
|
112
|
+
const deeper = join(root, sub.name, projectName);
|
|
113
|
+
if (existsSync(join(deeper, ".agentdesk.json"))) return deeper;
|
|
114
|
+
}
|
|
115
|
+
} catch {}
|
|
116
|
+
}
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
|
|
86
120
|
// --- Main daemon ---
|
|
87
121
|
|
|
88
122
|
export async function runDaemon() {
|
|
@@ -116,8 +150,19 @@ export async function runDaemon() {
|
|
|
116
150
|
if (Array.isArray(serverProjects) && serverProjects.length > 0) {
|
|
117
151
|
console.log(` ${dim}Syncing ${serverProjects.length} project(s) from server...${reset}`);
|
|
118
152
|
for (const sp of serverProjects) {
|
|
153
|
+
const projectName = sp.id || sp.name;
|
|
154
|
+
// If server has a valid path, use it
|
|
119
155
|
if (sp.path && existsSync(sp.path)) {
|
|
120
|
-
registerLocalProject(
|
|
156
|
+
registerLocalProject(projectName, sp.name, sp.path);
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
// Server has empty path — try to find the project locally
|
|
160
|
+
const found = findProjectLocally(projectName);
|
|
161
|
+
if (found) {
|
|
162
|
+
console.log(` ${dim}Found ${projectName} at ${found}${reset}`);
|
|
163
|
+
registerLocalProject(projectName, sp.name, found);
|
|
164
|
+
} else {
|
|
165
|
+
console.log(` ${yellow}Could not find ${projectName} locally.${reset} Run ${cyan}agentdesk init${reset} in its directory.`);
|
|
121
166
|
}
|
|
122
167
|
}
|
|
123
168
|
allProjects = getRegisteredProjects();
|
|
@@ -187,6 +232,7 @@ export async function runDaemon() {
|
|
|
187
232
|
|
|
188
233
|
function connectWs() {
|
|
189
234
|
try {
|
|
235
|
+
console.log(` ${dim}Connecting to ${DAEMON_URL}...${reset}`);
|
|
190
236
|
ws = new WebSocket(DAEMON_URL);
|
|
191
237
|
|
|
192
238
|
ws.on("open", () => {
|
|
@@ -239,7 +285,10 @@ export async function runDaemon() {
|
|
|
239
285
|
}
|
|
240
286
|
});
|
|
241
287
|
|
|
242
|
-
ws.on("error", () => {
|
|
288
|
+
ws.on("error", (err) => {
|
|
289
|
+
connected = false;
|
|
290
|
+
console.log(` ${red}Connection error:${reset} ${err.message}`);
|
|
291
|
+
});
|
|
243
292
|
|
|
244
293
|
ws.on("close", (code) => {
|
|
245
294
|
connected = false;
|