skillmkt 0.1.5 → 0.1.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/client/commands/init.js +15 -6
- package/client/commands/serve.js +26 -18
- package/client/lib/daemon.js +12 -4
- package/client/public/app.js +10 -10
- package/package.json +1 -1
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
|
@@ -18,16 +18,10 @@ 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`); };
|
|
@@ -53,7 +47,6 @@ export async function run(ctx) {
|
|
|
53
47
|
};
|
|
54
48
|
const body = (req) => new Promise((r) => { let b = ''; req.on('data', (c) => b += c); req.on('end', () => r(b || '{}')); });
|
|
55
49
|
|
|
56
|
-
const quiet = !!flags.daemon;
|
|
57
50
|
const server = http.createServer(async (req, res) => {
|
|
58
51
|
lastActive = Date.now();
|
|
59
52
|
const t0 = Date.now();
|
|
@@ -135,25 +128,40 @@ export async function run(ctx) {
|
|
|
135
128
|
fs.createReadStream(file).pipe(res);
|
|
136
129
|
});
|
|
137
130
|
|
|
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() }));
|
|
131
|
+
await new Promise((r) => server.listen(port, '127.0.0.1', r));
|
|
132
|
+
const realPort = server.address().port;
|
|
133
|
+
fs.writeFileSync(daemonFile(ctx.hub), JSON.stringify({ pid: process.pid, port: realPort, token, started: new Date().toISOString() }));
|
|
141
134
|
const idle = setInterval(() => { if (Date.now() - lastActive > idleMs) { server.close(); process.exit(0); } }, 60e3);
|
|
142
135
|
idle.unref();
|
|
143
136
|
|
|
144
|
-
// 退出语义:SIGINT/SIGTERM/正常 close → 摘 daemon.json(前台模式主语义)
|
|
145
137
|
const shutdown = () => {
|
|
146
|
-
|
|
138
|
+
clearInterval(idle);
|
|
147
139
|
fs.rmSync(daemonFile(ctx.hub), { force: true });
|
|
148
140
|
server.close(() => process.exit(0));
|
|
149
141
|
setTimeout(() => process.exit(0), 800).unref();
|
|
150
142
|
};
|
|
151
143
|
process.on('SIGINT', shutdown);
|
|
152
144
|
process.on('SIGTERM', shutdown);
|
|
145
|
+
return { server, port: realPort, token, emit, shutdown };
|
|
146
|
+
}
|
|
153
147
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
148
|
+
export async function run(ctx) {
|
|
149
|
+
const flags = ctx.flags.raw;
|
|
150
|
+
if (flags.stop) {
|
|
151
|
+
const d = readDaemon(ctx.hub);
|
|
152
|
+
if (d) { try { process.kill(d.pid); } catch { /* dead */ } fs.rmSync(daemonFile(ctx.hub), { force: true }); ok('daemon stopped'); }
|
|
153
|
+
else info('no daemon');
|
|
154
|
+
return 0;
|
|
155
|
+
}
|
|
156
|
+
// 已有前台/分离实例在跑 → 不重复起,报地址
|
|
157
|
+
const existing = readDaemon(ctx.hub);
|
|
158
|
+
if (existing && existing.pid !== process.pid) {
|
|
159
|
+
try { process.kill(existing.pid, 0); info(`已在跑: http://127.0.0.1:${existing.port}/?token=${existing.token}(--stop 停掉)`); return 0; } catch { /* stale */ }
|
|
160
|
+
}
|
|
161
|
+
const d = await startServer(ctx, { quiet: !!flags.daemon, port: flags.port || 0 });
|
|
162
|
+
if (flags.daemon) { console.log(`daemon ready :${d.port}`); await new Promise(() => {}); }
|
|
163
|
+
console.log(`serve: http://127.0.0.1:${d.port}/?token=${d.token}`);
|
|
164
|
+
console.log(` 前台运行 — Ctrl-C 退出(idle ${ctx.config.daemon?.idle_minutes ?? 30}m 自退)`);
|
|
157
165
|
await new Promise(() => {});
|
|
158
166
|
return 0;
|
|
159
167
|
}
|
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} 个端点`;
|