skillmkt 0.1.4 → 0.1.5
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/serve.js +6 -3
- package/client/lib/daemon.js +3 -1
- package/client/public/app.js +2 -1
- package/package.json +1 -1
package/client/commands/serve.js
CHANGED
|
@@ -6,7 +6,7 @@ import crypto from 'node:crypto';
|
|
|
6
6
|
import { daemonFile, readDaemon } from '../lib/daemon.js';
|
|
7
7
|
import { loadConflicts } from '../lib/conflicts.js';
|
|
8
8
|
import { loadDecisions, decide } from '../lib/decide.js';
|
|
9
|
-
import { readLibrary, readLock, readConfig, writeConfig, registerSkill, updateLock } from '../lib/hub.js';
|
|
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
12
|
import { scanAll } from '../lib/scanner.js';
|
|
@@ -20,6 +20,7 @@ const MIME = { '.html': 'text/html', '.js': 'text/javascript', '.css': 'text/css
|
|
|
20
20
|
|
|
21
21
|
export async function run(ctx) {
|
|
22
22
|
const flags = ctx.flags.raw;
|
|
23
|
+
ensureHub(ctx.hub); // 未 init 也能起面板(setup 页完成初始化)
|
|
23
24
|
if (flags.stop) {
|
|
24
25
|
const d = readDaemon(ctx.hub);
|
|
25
26
|
if (d) { try { process.kill(d.pid); } catch { /* dead */ } fs.rmSync(daemonFile(ctx.hub), { force: true }); ok('daemon stopped'); }
|
|
@@ -34,7 +35,9 @@ export async function run(ctx) {
|
|
|
34
35
|
const idleMs = (ctx.config.daemon?.idle_minutes ?? 30) * 60e3;
|
|
35
36
|
|
|
36
37
|
const state = () => ({
|
|
37
|
-
hub: ctx.hub,
|
|
38
|
+
hub: ctx.hub,
|
|
39
|
+
initialized: (() => { const r = readConfig(ctx.hub)._raw; return !!(r.ui || r.llm || r.default_targets); })(),
|
|
40
|
+
library: readLibrary(ctx.hub), lock: readLock(ctx.hub),
|
|
38
41
|
upstream: readUpstream(ctx.hub), conflicts: loadConflicts(ctx.hub),
|
|
39
42
|
decisions: loadDecisions(ctx.hub), harnesses: ctx.harnesses,
|
|
40
43
|
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) : [],
|
|
@@ -149,7 +152,7 @@ export async function run(ctx) {
|
|
|
149
152
|
process.on('SIGTERM', shutdown);
|
|
150
153
|
|
|
151
154
|
if (flags.daemon) { console.log(`daemon ready :${port}`); await new Promise(() => {}); }
|
|
152
|
-
console.log(`serve: http://127.0.0.1:${port}
|
|
155
|
+
console.log(`serve: http://127.0.0.1:${port}/?token=${token}`);
|
|
153
156
|
console.log(` foreground — Ctrl-C 退出(idle ${ctx.config.daemon?.idle_minutes ?? 30}m 自退;分离模式见 --daemon)`);
|
|
154
157
|
await new Promise(() => {});
|
|
155
158
|
return 0;
|
package/client/lib/daemon.js
CHANGED
|
@@ -29,7 +29,9 @@ export async function ensureDaemon(ctx) {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
export function openURL(d, route = '/') {
|
|
32
|
-
|
|
32
|
+
// token 必须进 ?search(location.search 可读);#fragment 只带 tab 名
|
|
33
|
+
const frag = route.includes('#') ? `#${route.split('#')[1]}` : '';
|
|
34
|
+
const url = `http://127.0.0.1:${d.port}/?token=${d.token}${frag}`;
|
|
33
35
|
try { execFileSync('open', [url]); } catch { /* linux: xdg-open */ try { execFileSync('xdg-open', [url]); } catch { /* noop */ } }
|
|
34
36
|
return url;
|
|
35
37
|
}
|
package/client/public/app.js
CHANGED
|
@@ -3,12 +3,13 @@ const T = new URLSearchParams(location.search).get('token') || '';
|
|
|
3
3
|
const api = async (p, opt) => (await fetch(`/api${p}${p.includes('?') ? '&' : '?'}token=${T}`, { headers: { authorization: `Bearer ${T}` }, ...opt })).json();
|
|
4
4
|
const el = (h) => { const d = document.createElement('div'); d.innerHTML = h; return d.firstElementChild; };
|
|
5
5
|
const esc = (s) => String(s ?? '').replace(/[&<>]/g, (c) => ({ '&': '&', '<': '<', '>': '>' }[c]));
|
|
6
|
-
let S = null, tab = location.hash.slice(1) || 'skills';
|
|
6
|
+
let S = null, tab = location.hash.slice(1).split('?')[0] || 'skills';
|
|
7
7
|
|
|
8
8
|
async function refresh() {
|
|
9
9
|
try { S = await api('/state'); }
|
|
10
10
|
catch (e) { document.getElementById('app').innerHTML = `<p class="pill bad">/api/state 请求失败:${esc(e.message)}——daemon 挂了?重跑 skillmkt serve</p>`; return; }
|
|
11
11
|
if (S?.error) { document.getElementById('app').innerHTML = `<p class="pill bad">${esc(S.error)}——URL 里的 token 已失效,重跑 skillmkt serve 拿新链接</p>`; return; }
|
|
12
|
+
if (!location.hash && !S.initialized) { tab = 'setup'; location.hash = 'setup'; } // 未初始化→setup
|
|
12
13
|
render();
|
|
13
14
|
}
|
|
14
15
|
const syncTabs = () => document.querySelectorAll('nav [data-t]').forEach((x) => x.classList.toggle('on', x.dataset.t === tab));
|