@lightcone-ai/daemon 0.4.0 → 0.5.0
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/package.json +1 -1
- package/src/agent-manager.js +84 -5
package/package.json
CHANGED
package/src/agent-manager.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { spawn } from 'child_process';
|
|
2
|
-
import { mkdirSync } from 'fs';
|
|
2
|
+
import { mkdirSync, readdirSync, readFileSync, statSync, lstatSync } from 'fs';
|
|
3
3
|
import { homedir } from 'os';
|
|
4
4
|
import path from 'path';
|
|
5
5
|
import { buildSystemPrompt } from './drivers/claude.js';
|
|
@@ -20,10 +20,11 @@ export class AgentManager {
|
|
|
20
20
|
|
|
21
21
|
handle(msg, connection) {
|
|
22
22
|
switch (msg.type) {
|
|
23
|
-
case 'agent:start':
|
|
24
|
-
case 'agent:stop':
|
|
25
|
-
case 'agent:deliver':
|
|
26
|
-
case '
|
|
23
|
+
case 'agent:start': return this._startAgent(msg, connection);
|
|
24
|
+
case 'agent:stop': return this._stopAgent(msg.agentId, msg.channelId, connection);
|
|
25
|
+
case 'agent:deliver': return this._deliverMessage(msg, connection);
|
|
26
|
+
case 'agent:skills:list': return this._listSkills(msg, connection);
|
|
27
|
+
case 'ping': return connection.send({ type: 'pong' });
|
|
27
28
|
default:
|
|
28
29
|
console.log(`[AgentManager] Unhandled: ${msg.type}`);
|
|
29
30
|
}
|
|
@@ -193,6 +194,84 @@ export class AgentManager {
|
|
|
193
194
|
}
|
|
194
195
|
}
|
|
195
196
|
|
|
197
|
+
// ── skills ────────────────────────────────────────────────────────────────
|
|
198
|
+
|
|
199
|
+
_listSkills({ agentId, channelId, requestId }, connection) {
|
|
200
|
+
const home = homedir();
|
|
201
|
+
// Find workspace dir for this agent (check running agents first, else derive)
|
|
202
|
+
const key = this._key(agentId, channelId);
|
|
203
|
+
const agent = this.agents.get(key);
|
|
204
|
+
const workspaceDir = agent
|
|
205
|
+
? this._workspaceDir(agentId, agent.channelId)
|
|
206
|
+
: this._workspaceDir(agentId, channelId);
|
|
207
|
+
|
|
208
|
+
const globalDirs = [
|
|
209
|
+
path.join(home, '.claude', 'skills'),
|
|
210
|
+
path.join(home, '.claude', 'commands'),
|
|
211
|
+
];
|
|
212
|
+
const workspaceDirs = [
|
|
213
|
+
path.join(workspaceDir, '.claude', 'skills'),
|
|
214
|
+
path.join(workspaceDir, '.claude', 'commands'),
|
|
215
|
+
];
|
|
216
|
+
|
|
217
|
+
const dedup = (skills) => {
|
|
218
|
+
const seen = new Set();
|
|
219
|
+
return skills.filter(s => {
|
|
220
|
+
if (seen.has(s.name)) return false;
|
|
221
|
+
seen.add(s.name);
|
|
222
|
+
return true;
|
|
223
|
+
});
|
|
224
|
+
};
|
|
225
|
+
const shorten = (skills) => skills.map(s => ({
|
|
226
|
+
...s,
|
|
227
|
+
sourcePath: s.sourcePath?.startsWith(home) ? '~' + s.sourcePath.slice(home.length) : s.sourcePath,
|
|
228
|
+
}));
|
|
229
|
+
|
|
230
|
+
const global = shorten(dedup(globalDirs.flatMap(d => this._scanSkillsDir(d))));
|
|
231
|
+
const workspace = shorten(dedup(workspaceDirs.flatMap(d => this._scanSkillsDir(d))));
|
|
232
|
+
|
|
233
|
+
connection.send({ type: 'agent:skills:list_result', agentId, requestId, global, workspace });
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
_scanSkillsDir(dir) {
|
|
237
|
+
let entries;
|
|
238
|
+
try { entries = readdirSync(dir, { withFileTypes: true }); }
|
|
239
|
+
catch { return []; }
|
|
240
|
+
const skills = [];
|
|
241
|
+
for (const entry of entries) {
|
|
242
|
+
if (entry.isDirectory() || entry.isSymbolicLink()) {
|
|
243
|
+
const skillMd = path.join(dir, entry.name, 'SKILL.md');
|
|
244
|
+
try {
|
|
245
|
+
const content = readFileSync(skillMd, 'utf-8');
|
|
246
|
+
skills.push({ ...this._parseSkillMd(entry.name, content), sourcePath: dir });
|
|
247
|
+
} catch {}
|
|
248
|
+
} else if (entry.name.endsWith('.md')) {
|
|
249
|
+
const cmdName = entry.name.replace(/\.md$/, '');
|
|
250
|
+
try {
|
|
251
|
+
const content = readFileSync(path.join(dir, entry.name), 'utf-8');
|
|
252
|
+
skills.push({ ...this._parseSkillMd(cmdName, content), sourcePath: dir });
|
|
253
|
+
} catch {}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
return skills;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
_parseSkillMd(dirName, content) {
|
|
260
|
+
const info = { name: dirName, displayName: dirName, description: '', userInvocable: false };
|
|
261
|
+
const match = content.match(/^---\n([\s\S]*?)\n---/);
|
|
262
|
+
if (!match) return info;
|
|
263
|
+
for (const line of match[1].split('\n')) {
|
|
264
|
+
const idx = line.indexOf(':');
|
|
265
|
+
if (idx === -1) continue;
|
|
266
|
+
const key = line.slice(0, idx).trim();
|
|
267
|
+
const value = line.slice(idx + 1).trim();
|
|
268
|
+
if (key === 'name') info.displayName = value;
|
|
269
|
+
if (key === 'description') info.description = value;
|
|
270
|
+
if (key === 'user-invocable') info.userInvocable = value === 'true';
|
|
271
|
+
}
|
|
272
|
+
return info;
|
|
273
|
+
}
|
|
274
|
+
|
|
196
275
|
_parseLine(key, agentId, channelId, line, connection) {
|
|
197
276
|
let event;
|
|
198
277
|
try { event = JSON.parse(line); }
|