skillmkt 0.1.5 → 0.1.7
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/client/bin/skillmkt.js +2 -0
- package/client/commands/init.js +15 -6
- package/client/commands/serve.js +34 -22
- package/client/lib/daemon.js +12 -4
- package/client/public/app.js +10 -10
- package/client/public/index.html +1 -1
- package/package.json +1 -1
package/client/bin/skillmkt.js
CHANGED
|
@@ -36,9 +36,11 @@ async function bareRun(ctx) {
|
|
|
36
36
|
process.exit(1);
|
|
37
37
|
}
|
|
38
38
|
const mod = await import('../commands/init.js');
|
|
39
|
+
withState(ctx);
|
|
39
40
|
return mod.run(ctx);
|
|
40
41
|
}
|
|
41
42
|
const { renderDashboard } = await import('../lib/dashboard.js');
|
|
43
|
+
withState(ctx);
|
|
42
44
|
return renderDashboard(ctx);
|
|
43
45
|
}
|
|
44
46
|
|
package/client/commands/init.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import fs from 'node:fs';
|
|
3
3
|
import { ensureHub, writeConfig, readConfig } from '../lib/hub.js';
|
|
4
4
|
import { probeEndpoints, chat } from '../lib/llm.js';
|
|
5
|
-
import {
|
|
5
|
+
import { openURL, readDaemon } from '../lib/daemon.js';
|
|
6
6
|
import { choose, confirm } from '../lib/prompt.js';
|
|
7
7
|
import { ok, warn, fail, info } from '../lib/render.js';
|
|
8
8
|
|
|
@@ -25,15 +25,24 @@ export async function run(ctx) {
|
|
|
25
25
|
writeConfig(ctx.hub, raw); // ui 偏好先落盘(web 页内继续改其余键)
|
|
26
26
|
|
|
27
27
|
if (mode === 'web') {
|
|
28
|
-
//
|
|
28
|
+
// 前台语义:本进程=服务器,开页后挂住流日志,Ctrl-C 连服务一起退
|
|
29
29
|
try {
|
|
30
|
-
const d =
|
|
31
|
-
|
|
30
|
+
const alive = (() => { const d = readDaemon(ctx.hub); return d && (() => { try { process.kill(d.pid, 0); return true; } catch { return false; } })() ? d : null; })();
|
|
31
|
+
if (alive) {
|
|
32
|
+
const url = openURL(alive, '/#setup');
|
|
33
|
+
ok(`Web 初始化已打开: ${url}(服务已在别的终端跑)`);
|
|
34
|
+
return 0;
|
|
35
|
+
}
|
|
36
|
+
const { startServer } = await import('./serve.js');
|
|
37
|
+
const srv = await startServer(ctx, { quiet: false });
|
|
38
|
+
const url = openURL({ port: srv.port, token: srv.token }, '/#setup');
|
|
32
39
|
ok(`Web 初始化已打开: ${url}`);
|
|
33
|
-
info('setup
|
|
40
|
+
info('setup 页内:扫描端点 → 选模型 → 勾 agent → 保存(写入 config.yml)');
|
|
41
|
+
info('服务前台运行中 — Ctrl-C 退出');
|
|
42
|
+
await new Promise(() => {});
|
|
34
43
|
return 0;
|
|
35
44
|
} catch (e) {
|
|
36
|
-
warn(
|
|
45
|
+
warn(`服务起不来(${e.message.slice(0, 60)})——回退终端向导`);
|
|
37
46
|
}
|
|
38
47
|
}
|
|
39
48
|
|
package/client/commands/serve.js
CHANGED
|
@@ -9,7 +9,7 @@ import { loadDecisions, decide } from '../lib/decide.js';
|
|
|
9
9
|
import { readLibrary, readLock, readConfig, writeConfig, registerSkill, updateLock, ensureHub } from '../lib/hub.js';
|
|
10
10
|
import { readUpstream } from '../lib/state.js';
|
|
11
11
|
import { readYAML } from '../../pipeline/lib/util.js';
|
|
12
|
-
import { scanAll } from '../lib/scanner.js';
|
|
12
|
+
import { scanAll, detectHarnesses } from '../lib/scanner.js';
|
|
13
13
|
import { probeEndpoints, chat } from '../lib/llm.js';
|
|
14
14
|
import { projectSkill, targetDirFor } from '../lib/project.js';
|
|
15
15
|
import { treeHash } from '../lib/package.js';
|
|
@@ -18,30 +18,25 @@ import { ok, info, fail } from '../lib/render.js';
|
|
|
18
18
|
const PUB = path.join(new URL('.', import.meta.url).pathname, '../public');
|
|
19
19
|
const MIME = { '.html': 'text/html', '.js': 'text/javascript', '.css': 'text/css', '.png': 'image/png', '.svg': 'image/svg+xml' };
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
// startServer — 可复用:serve 命令与 CLI 接管共用。返回 {port, token, server, emit, shutdown}
|
|
22
|
+
export async function startServer(ctx, { quiet = false, port = 0 } = {}) {
|
|
23
|
+
ensureHub(ctx.hub);
|
|
22
24
|
const flags = ctx.flags.raw;
|
|
23
|
-
ensureHub(ctx.hub); // 未 init 也能起面板(setup 页完成初始化)
|
|
24
|
-
if (flags.stop) {
|
|
25
|
-
const d = readDaemon(ctx.hub);
|
|
26
|
-
if (d) { try { process.kill(d.pid); } catch { /* dead */ } fs.rmSync(daemonFile(ctx.hub), { force: true }); ok('daemon stopped'); }
|
|
27
|
-
else info('no daemon');
|
|
28
|
-
return 0;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
25
|
const token = crypto.randomBytes(16).toString('hex');
|
|
32
26
|
const sse = new Set();
|
|
33
27
|
const emit = (type, data) => { for (const res of sse) res.write(`event: ${type}\ndata: ${JSON.stringify(data)}\n\n`); };
|
|
34
28
|
let lastActive = Date.now();
|
|
35
29
|
const idleMs = (ctx.config.daemon?.idle_minutes ?? 30) * 60e3;
|
|
36
30
|
|
|
31
|
+
const harnesses = ctx.harnesses ?? detectHarnesses(); // bareRun/init 路径 ctx 可能没 withState
|
|
37
32
|
const state = () => ({
|
|
38
33
|
hub: ctx.hub,
|
|
39
34
|
initialized: (() => { const r = readConfig(ctx.hub)._raw; return !!(r.ui || r.llm || r.default_targets); })(),
|
|
40
35
|
library: readLibrary(ctx.hub), lock: readLock(ctx.hub),
|
|
41
36
|
upstream: readUpstream(ctx.hub), conflicts: loadConflicts(ctx.hub),
|
|
42
|
-
decisions: loadDecisions(ctx.hub), harnesses
|
|
37
|
+
decisions: loadDecisions(ctx.hub), harnesses,
|
|
43
38
|
scans: fs.existsSync(path.join(ctx.hub, 'scans')) ? fs.readdirSync(path.join(ctx.hub, 'scans')).map((f) => readYAML(path.join(ctx.hub, 'scans', f))).filter(Boolean) : [],
|
|
44
|
-
scans_all: scanAll(ctx.hub,
|
|
39
|
+
scans_all: scanAll(ctx.hub, harnesses, readLibrary(ctx.hub), ctx.cwd),
|
|
45
40
|
});
|
|
46
41
|
|
|
47
42
|
const routes = {
|
|
@@ -53,7 +48,6 @@ export async function run(ctx) {
|
|
|
53
48
|
};
|
|
54
49
|
const body = (req) => new Promise((r) => { let b = ''; req.on('data', (c) => b += c); req.on('end', () => r(b || '{}')); });
|
|
55
50
|
|
|
56
|
-
const quiet = !!flags.daemon;
|
|
57
51
|
const server = http.createServer(async (req, res) => {
|
|
58
52
|
lastActive = Date.now();
|
|
59
53
|
const t0 = Date.now();
|
|
@@ -122,7 +116,10 @@ export async function run(ctx) {
|
|
|
122
116
|
res.writeHead(404); return res.end('{"error":"not found"}');
|
|
123
117
|
}
|
|
124
118
|
const h = routes[`${req.method} ${u.pathname}`];
|
|
125
|
-
if (h)
|
|
119
|
+
if (h) {
|
|
120
|
+
try { return res.end(JSON.stringify(await h())); }
|
|
121
|
+
catch (e) { res.writeHead(500); return res.end(JSON.stringify({ error: e.message })); }
|
|
122
|
+
}
|
|
126
123
|
res.writeHead(404); return res.end('{"error":"not found"}');
|
|
127
124
|
}
|
|
128
125
|
// 静态:public/ + evidence 文件(冲突截图)
|
|
@@ -135,25 +132,40 @@ export async function run(ctx) {
|
|
|
135
132
|
fs.createReadStream(file).pipe(res);
|
|
136
133
|
});
|
|
137
134
|
|
|
138
|
-
await new Promise((r) => server.listen(
|
|
139
|
-
const
|
|
140
|
-
fs.writeFileSync(daemonFile(ctx.hub), JSON.stringify({ pid: process.pid, port, token, started: new Date().toISOString() }));
|
|
135
|
+
await new Promise((r) => server.listen(port, '127.0.0.1', r));
|
|
136
|
+
const realPort = server.address().port;
|
|
137
|
+
fs.writeFileSync(daemonFile(ctx.hub), JSON.stringify({ pid: process.pid, port: realPort, token, started: new Date().toISOString() }));
|
|
141
138
|
const idle = setInterval(() => { if (Date.now() - lastActive > idleMs) { server.close(); process.exit(0); } }, 60e3);
|
|
142
139
|
idle.unref();
|
|
143
140
|
|
|
144
|
-
// 退出语义:SIGINT/SIGTERM/正常 close → 摘 daemon.json(前台模式主语义)
|
|
145
141
|
const shutdown = () => {
|
|
146
|
-
|
|
142
|
+
clearInterval(idle);
|
|
147
143
|
fs.rmSync(daemonFile(ctx.hub), { force: true });
|
|
148
144
|
server.close(() => process.exit(0));
|
|
149
145
|
setTimeout(() => process.exit(0), 800).unref();
|
|
150
146
|
};
|
|
151
147
|
process.on('SIGINT', shutdown);
|
|
152
148
|
process.on('SIGTERM', shutdown);
|
|
149
|
+
return { server, port: realPort, token, emit, shutdown };
|
|
150
|
+
}
|
|
153
151
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
152
|
+
export async function run(ctx) {
|
|
153
|
+
const flags = ctx.flags.raw;
|
|
154
|
+
if (flags.stop) {
|
|
155
|
+
const d = readDaemon(ctx.hub);
|
|
156
|
+
if (d) { try { process.kill(d.pid); } catch { /* dead */ } fs.rmSync(daemonFile(ctx.hub), { force: true }); ok('daemon stopped'); }
|
|
157
|
+
else info('no daemon');
|
|
158
|
+
return 0;
|
|
159
|
+
}
|
|
160
|
+
// 已有前台/分离实例在跑 → 不重复起,报地址
|
|
161
|
+
const existing = readDaemon(ctx.hub);
|
|
162
|
+
if (existing && existing.pid !== process.pid) {
|
|
163
|
+
try { process.kill(existing.pid, 0); info(`已在跑: http://127.0.0.1:${existing.port}/?token=${existing.token}(--stop 停掉)`); return 0; } catch { /* stale */ }
|
|
164
|
+
}
|
|
165
|
+
const d = await startServer(ctx, { quiet: !!flags.daemon, port: flags.port || 0 });
|
|
166
|
+
if (flags.daemon) { console.log(`daemon ready :${d.port}`); await new Promise(() => {}); }
|
|
167
|
+
console.log(`serve: http://127.0.0.1:${d.port}/?token=${d.token}`);
|
|
168
|
+
console.log(` 前台运行 — Ctrl-C 退出(idle ${ctx.config.daemon?.idle_minutes ?? 30}m 自退)`);
|
|
157
169
|
await new Promise(() => {});
|
|
158
170
|
return 0;
|
|
159
171
|
}
|
package/client/lib/daemon.js
CHANGED
|
@@ -36,14 +36,22 @@ export function openURL(d, route = '/') {
|
|
|
36
36
|
return url;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
// CLI
|
|
39
|
+
// CLI 接管:有活 daemon→开页复用(返回 true 让调用方退出);
|
|
40
|
+
// 没有→当前进程前台起服务+开页+挂住流日志(Ctrl-C 连服务一起退,永不返回)
|
|
40
41
|
export async function maybeHandoff(ctx, route = '/') {
|
|
41
42
|
if (!process.stdout.isTTY || ctx.flags.raw.cli || ctx.flags.raw.noUi) return false;
|
|
42
43
|
if (ctx.flags.raw.ui === false) return false;
|
|
44
|
+
const d = readDaemon(ctx.hub);
|
|
45
|
+
if (d && alive(d.pid)) {
|
|
46
|
+
console.log(`opened ${openURL(d, route)}(服务已在跑,Ctrl-C 那个终端的 serve 可停)`);
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
43
49
|
try {
|
|
44
|
-
const
|
|
45
|
-
const
|
|
46
|
-
console.log(`opened ${
|
|
50
|
+
const { startServer } = await import('../commands/serve.js');
|
|
51
|
+
const srv = await startServer(ctx, { quiet: false });
|
|
52
|
+
console.log(`opened ${openURL({ port: srv.port, token: srv.token }, route)}`);
|
|
53
|
+
console.log(' 服务前台运行中 — 操作日志见下方,Ctrl-C 退出');
|
|
54
|
+
await new Promise(() => {}); // 挂住:本进程=服务器
|
|
47
55
|
return true;
|
|
48
56
|
} catch { return false; }
|
|
49
57
|
}
|
package/client/public/app.js
CHANGED
|
@@ -34,17 +34,17 @@ async function render() {
|
|
|
34
34
|
|
|
35
35
|
if (tab === 'skills') {
|
|
36
36
|
const skills = Object.entries(S.library.skills || {});
|
|
37
|
-
app.innerHTML = `<h2
|
|
37
|
+
app.innerHTML = `<h2>已安装 skills(${skills.length})</h2>` + (skills.map(([n, s]) => `
|
|
38
38
|
<div class="card"><div class="row"><b>${esc(n)}</b><span class="mut">${esc(s.version || '-')}</span><span class="mut">${esc(s.source?.registry || '')}</span>${pill(s.audit || 'clean')}
|
|
39
|
-
<span class="mut" style="margin-left:auto"
|
|
40
|
-
<button data-tg="${esc(n)}"
|
|
39
|
+
<span class="mut" style="margin-left:auto">装在:${(s.targets || []).join('、') || '无'}</span>
|
|
40
|
+
<button data-tg="${esc(n)}">安装位置</button></div>
|
|
41
41
|
<div class="tgbox" data-box="${esc(n)}" style="display:none;margin-top:8px"></div></div>`).join('') || '<p class="mut">还没有受管 skill——skillmkt install <ref></p>');
|
|
42
42
|
app.querySelectorAll('[data-tg]').forEach((b) => b.onclick = () => {
|
|
43
43
|
const box = app.querySelector(`[data-box="${b.dataset.tg}"]`);
|
|
44
44
|
if (box.style.display === 'block') { box.style.display = 'none'; return; }
|
|
45
45
|
const s = S.library.skills[b.dataset.tg];
|
|
46
46
|
box.style.display = 'block';
|
|
47
|
-
box.innerHTML = `<label class="field"
|
|
47
|
+
box.innerHTML = `<label class="field">装到这些 agent(勾选后立即复制生效)</label>` +
|
|
48
48
|
(S.harnesses || []).filter((x) => x.state === 'installed' && !x.detectOnly).map((x) =>
|
|
49
49
|
`<label class="row"><input type="checkbox" data-th="${esc(x.id)}" ${(s.targets || []).includes(x.id) ? 'checked' : ''}> ${esc(x.id)} <span class="mut">${esc(x.primaryDir || '')}</span></label>`).join('')
|
|
50
50
|
+ `<div class="row" style="margin-top:8px"><button class="primary tgo">应用目标</button><span class="tout mut"></span></div>`;
|
|
@@ -55,9 +55,9 @@ async function render() {
|
|
|
55
55
|
refresh();
|
|
56
56
|
};
|
|
57
57
|
});
|
|
58
|
-
app.innerHTML += `<h2
|
|
58
|
+
app.innerHTML += `<h2>检测到的 agent</h2>` + (S.harnesses || []).map((h) => `<div class="card row"><b>${esc(h.id)}</b>${pill(h.state)}<span class="mut">${esc(h.primaryDir || h.dirs?.[0] || '')}</span></div>`).join('');
|
|
59
59
|
const up = S.upstream.skills || {};
|
|
60
|
-
if (Object.keys(up).length) app.innerHTML += `<h2
|
|
60
|
+
if (Object.keys(up).length) app.innerHTML += `<h2>可更新</h2>` + Object.entries(up).map(([n, u]) => `<div class="card row"><b>${esc(n)}</b>${u.outdated ? pill('outdated') : pill('clean')}<span class="mut">${esc(String(u.ref || '').slice(0, 8))}</span></div>`).join('');
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
if (tab === 'conflicts') {
|
|
@@ -117,17 +117,17 @@ async function render() {
|
|
|
117
117
|
const sel = new Set(cfg.default_targets?.length ? cfg.default_targets : installed);
|
|
118
118
|
app.innerHTML = `<h2>初始化与配置</h2>
|
|
119
119
|
<div class="card"><b>LLM 端点</b><span class="mut" id="cur">${cfg.llm?.model ? `(当前:${esc(cfg.llm.model)} @ ${esc(cfg.llm.base_url)})` : '(未配置)'}</span>
|
|
120
|
-
<div class="row" style="margin-top:8px"><button id="probe"
|
|
120
|
+
<div class="row" style="margin-top:8px"><button id="probe">扫描本地 LLM 服务</button><span id="probe-out" class="mut"></span></div>
|
|
121
121
|
<div id="eps"></div>
|
|
122
122
|
<label class="field">base_url</label><input type="text" id="murl" value="${esc(cfg.llm?.base_url || '')}">
|
|
123
123
|
<label class="field">model</label><input type="text" id="mmodel" value="${esc(cfg.llm?.model || '')}">
|
|
124
124
|
<label class="field">api_key(env:VAR 引用,不存真值;留空=无 key)</label><input type="text" id="mkey" value="${esc(cfg.llm?.api_key || '')}">
|
|
125
|
-
<div class="row" style="margin-top:8px"><button id="smoke"
|
|
126
|
-
<div class="card"><b
|
|
125
|
+
<div class="row" style="margin-top:8px"><button id="smoke">测试连接</button><span id="smoke-out" class="mut"></span></div></div>
|
|
126
|
+
<div class="card"><b>skill 装到哪些 agent</b><span class="mut">(勾选后,新装的 skill 会复制进这些 agent 的 skills 目录)</span>
|
|
127
127
|
${h.map((x) => `<label class="row"><input type="checkbox" data-h="${esc(x.id)}" ${sel.has(x.id) ? 'checked' : ''} ${x.state !== 'installed' ? 'disabled' : ''}> ${esc(x.id)} ${pill(x.state)} <span class="mut">${esc(x.primaryDir || '')}</span></label>`).join('')}</div>
|
|
128
128
|
<div class="card"><button class="primary" id="save">保存配置</button><span id="save-out" class="mut"></span></div>`;
|
|
129
129
|
app.querySelector('#probe').onclick = async () => {
|
|
130
|
-
app.querySelector('#probe-out').textContent = '
|
|
130
|
+
app.querySelector('#probe-out').textContent = '扫描中…';
|
|
131
131
|
const eps = await api('/probe');
|
|
132
132
|
app.querySelector('#eps').innerHTML = eps.flatMap((e) => e.models.slice(0, 6).map((m) => `<div class="ep" data-b="${esc(e.base_url)}" data-m="${esc(m)}">${esc(e.name)}:${e.port} — <code>${esc(m)}</code></div>`)).join('') || '<p class="mut">未发现(8001 / 11434 / 1234 / 8000 / 8080 / 1337 / 5000)</p>';
|
|
133
133
|
app.querySelector('#probe-out').textContent = `${eps.length} 个端点`;
|
package/client/public/index.html
CHANGED
|
@@ -77,7 +77,7 @@ th { font-size: 13px; color: var(--color-ink-mut); font-weight: 500; }
|
|
|
77
77
|
footer { padding: 20px 28px; border-top: 1px solid var(--color-line); font-size: 13px; color: var(--color-ink-mut); }
|
|
78
78
|
</style></head><body>
|
|
79
79
|
<header>
|
|
80
|
-
<h1>
|
|
80
|
+
<h1>awesome-skill-market</h1>
|
|
81
81
|
<nav>
|
|
82
82
|
<button class="on" data-t="skills">skills</button>
|
|
83
83
|
<button data-t="conflicts">conflicts</button>
|