@cocorograph/hub-agent 0.5.5 → 0.5.6
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/agents.mjs +79 -0
- package/src/main.mjs +19 -0
package/package.json
CHANGED
package/src/agents.mjs
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Claude Code の subagent (`~/.claude/agents/<category>/<name>.md`) を集計する。
|
|
3
|
+
*
|
|
4
|
+
* - 各 .md の先頭 H1 から title / description を抽出 ("Title — description")
|
|
5
|
+
* - category=ディレクトリ名、name=basename
|
|
6
|
+
*
|
|
7
|
+
* 移植元: D00000_cockpit/webapp/lib/agents.ts
|
|
8
|
+
*/
|
|
9
|
+
import { promises as fs } from "node:fs"
|
|
10
|
+
import os from "node:os"
|
|
11
|
+
import path from "node:path"
|
|
12
|
+
|
|
13
|
+
const AGENTS_DIR = process.env.CLAUDE_AGENTS_DIR || path.join(os.homedir(), ".claude", "agents")
|
|
14
|
+
|
|
15
|
+
function parseH1(text) {
|
|
16
|
+
for (const line of text.split("\n")) {
|
|
17
|
+
const m = line.match(/^#\s+(.+)$/)
|
|
18
|
+
if (!m) continue
|
|
19
|
+
const heading = m[1].trim()
|
|
20
|
+
const dashIdx = heading.search(/\s*[-—–]\s*/)
|
|
21
|
+
if (dashIdx > 0) {
|
|
22
|
+
const title = heading.slice(0, dashIdx).trim()
|
|
23
|
+
const description = heading.slice(dashIdx).replace(/^[\s\-—–]+/, "").trim()
|
|
24
|
+
return { title, description }
|
|
25
|
+
}
|
|
26
|
+
return { title: heading, description: "" }
|
|
27
|
+
}
|
|
28
|
+
return { title: "", description: "" }
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export async function listAgents() {
|
|
32
|
+
const agents = []
|
|
33
|
+
let categories
|
|
34
|
+
try {
|
|
35
|
+
categories = await fs.readdir(AGENTS_DIR)
|
|
36
|
+
} catch {
|
|
37
|
+
return []
|
|
38
|
+
}
|
|
39
|
+
for (const cat of categories) {
|
|
40
|
+
if (cat.startsWith(".") || cat.startsWith("_")) continue
|
|
41
|
+
const catPath = path.join(AGENTS_DIR, cat)
|
|
42
|
+
let st
|
|
43
|
+
try {
|
|
44
|
+
st = await fs.stat(catPath)
|
|
45
|
+
} catch {
|
|
46
|
+
continue
|
|
47
|
+
}
|
|
48
|
+
if (!st.isDirectory()) continue
|
|
49
|
+
let files
|
|
50
|
+
try {
|
|
51
|
+
files = await fs.readdir(catPath)
|
|
52
|
+
} catch {
|
|
53
|
+
continue
|
|
54
|
+
}
|
|
55
|
+
for (const f of files) {
|
|
56
|
+
if (!f.endsWith(".md")) continue
|
|
57
|
+
if (f.startsWith("_")) continue
|
|
58
|
+
const fp = path.join(catPath, f)
|
|
59
|
+
try {
|
|
60
|
+
const text = await fs.readFile(fp, "utf-8")
|
|
61
|
+
const { title, description } = parseH1(text)
|
|
62
|
+
const baseName = f.replace(/\.md$/, "")
|
|
63
|
+
agents.push({
|
|
64
|
+
name: baseName,
|
|
65
|
+
category: cat,
|
|
66
|
+
title: title || baseName,
|
|
67
|
+
description: description || "",
|
|
68
|
+
path: `${cat}/${baseName}`,
|
|
69
|
+
})
|
|
70
|
+
} catch {
|
|
71
|
+
/* skip */
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
agents.sort(
|
|
76
|
+
(a, b) => a.category.localeCompare(b.category) || a.name.localeCompare(b.name),
|
|
77
|
+
)
|
|
78
|
+
return agents
|
|
79
|
+
}
|
package/src/main.mjs
CHANGED
|
@@ -20,6 +20,7 @@ import { readConfig } from "./config.mjs"
|
|
|
20
20
|
import { loadPlugins, runHookBroadcast, runHookChain } from "./plugin-loader.mjs"
|
|
21
21
|
import { WsClient } from "./ws-client.mjs"
|
|
22
22
|
import { PtyBridge } from "./pty-bridge.mjs"
|
|
23
|
+
import { listAgents } from "./agents.mjs"
|
|
23
24
|
import { listSkills } from "./skills.mjs"
|
|
24
25
|
import { listSessionStates } from "./state.mjs"
|
|
25
26
|
import {
|
|
@@ -405,6 +406,24 @@ async function dispatch(msg, ctx) {
|
|
|
405
406
|
}
|
|
406
407
|
return
|
|
407
408
|
}
|
|
409
|
+
case "agents.request": {
|
|
410
|
+
try {
|
|
411
|
+
const agents = await listAgents()
|
|
412
|
+
ctx.client.send({
|
|
413
|
+
type: "agents.response",
|
|
414
|
+
request_id: msg.request_id,
|
|
415
|
+
agents,
|
|
416
|
+
})
|
|
417
|
+
} catch (err) {
|
|
418
|
+
ctx.client.send({
|
|
419
|
+
type: "agents.response",
|
|
420
|
+
request_id: msg.request_id,
|
|
421
|
+
agents: [],
|
|
422
|
+
error: err.message,
|
|
423
|
+
})
|
|
424
|
+
}
|
|
425
|
+
return
|
|
426
|
+
}
|
|
408
427
|
case "usage.request": {
|
|
409
428
|
try {
|
|
410
429
|
const [usage, sessions] = await Promise.all([
|