skillmkt 0.1.8 → 0.1.9

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.
@@ -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 { openURL, readDaemon } from '../lib/daemon.js';
5
+ import { openURL, readDaemon, pidAlive } 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
 
@@ -27,10 +27,9 @@ export async function run(ctx) {
27
27
  if (mode === 'web') {
28
28
  // 前台语义:本进程=服务器,开页后挂住流日志,Ctrl-C 连服务一起退
29
29
  try {
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}(服务已在别的终端跑)`);
30
+ const d = readDaemon(ctx.hub);
31
+ if (d && pidAlive(d.pid)) {
32
+ ok(`Web 初始化已打开: ${openURL(d, '/#setup')}(服务已在别的终端跑)`);
34
33
  return 0;
35
34
  }
36
35
  const { startServer } = await import('./serve.js');
@@ -9,11 +9,11 @@ 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, detectHarnesses } from '../lib/scanner.js';
12
+ import { detectHarnesses } from '../lib/scanner.js';
13
13
  import { probeEndpoints, chat } from '../lib/llm.js';
14
- import { projectSkill, targetDirFor } from '../lib/project.js';
14
+ import { projectSkill, unproject, targetDirFor } from '../lib/project.js';
15
15
  import { treeHash } from '../lib/package.js';
16
- import { ok, info, fail } from '../lib/render.js';
16
+ import { ok, info } from '../lib/render.js';
17
17
 
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' };
@@ -35,8 +35,9 @@ export async function startServer(ctx, { quiet = false, port = 0 } = {}) {
35
35
  library: readLibrary(ctx.hub), lock: readLock(ctx.hub),
36
36
  upstream: readUpstream(ctx.hub), conflicts: loadConflicts(ctx.hub),
37
37
  decisions: loadDecisions(ctx.hub), harnesses,
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) : [],
39
- scans_all: scanAll(ctx.hub, harnesses, readLibrary(ctx.hub), ctx.cwd),
38
+ scans: fs.existsSync(path.join(ctx.hub, 'scans'))
39
+ ? fs.readdirSync(path.join(ctx.hub, 'scans')).sort().map((f) => readYAML(path.join(ctx.hub, 'scans', f))).filter(Boolean)
40
+ : [],
40
41
  });
41
42
 
42
43
  const routes = {
@@ -51,7 +52,7 @@ export async function startServer(ctx, { quiet = false, port = 0 } = {}) {
51
52
  const server = http.createServer(async (req, res) => {
52
53
  lastActive = Date.now();
53
54
  const t0 = Date.now();
54
- if (!quiet) res.on('finish', () => console.log(` ${req.method} ${req.url} → ${res.statusCode} ${Date.now() - t0}ms`));
55
+ if (!quiet) res.on('finish', () => console.log(` ${req.method} ${req.url.replace(/token=[^&\s]+/g, 'token=***')} → ${res.statusCode} ${Date.now() - t0}ms`));
55
56
  const u = new URL(req.url, 'http://x');
56
57
  // auth:Bearer header 或 ?token=(SSE/img 用 query,服务端不下发 cookie)
57
58
  const authed = req.headers.authorization === `Bearer ${token}` || u.searchParams.get('token') === token;
@@ -67,12 +68,15 @@ export async function startServer(ctx, { quiet = false, port = 0 } = {}) {
67
68
  if (!authed) { res.writeHead(401, { 'content-type': 'application/json' }); return res.end('{"error":"unauthorized"}'); }
68
69
  res.setHeader('content-type', 'application/json');
69
70
  if (req.method === 'POST') {
70
- const b = JSON.parse(await body(req));
71
+ let b;
72
+ try { b = JSON.parse(await body(req)); }
73
+ catch { res.writeHead(400); return res.end('{"error":"bad json"}'); }
71
74
  try {
72
75
  if (u.pathname === '/api/decide') {
73
76
  const c = loadConflicts(ctx.hub).find((x) => x.id === b.id);
74
77
  if (!c) { res.writeHead(404); return res.end('{"error":"not found"}'); }
75
- decide(ctx.hub, c, { resolution: b.resolution, custom: b.custom || null, reason: b.reason || 'web decision', by: 'web-ui' });
78
+ if (!b.reason?.trim()) { res.writeHead(400); return res.end('{"error":"reason required"}'); }
79
+ decide(ctx.hub, c, { resolution: b.resolution, custom: b.custom || null, reason: b.reason, by: 'web-ui' });
76
80
  c.status = 'resolved';
77
81
  const { writeConflict } = await import('../lib/conflicts.js');
78
82
  writeConflict(ctx.hub, c);
@@ -101,6 +105,12 @@ export async function startServer(ctx, { quiet = false, port = 0 } = {}) {
101
105
  if (!s) { res.writeHead(404); return res.end('{"error":"not found"}'); }
102
106
  const dest = path.join(ctx.hub, 'skills', name);
103
107
  const lockTargets = {};
108
+ // 取消勾选的目标:删掉已复制的副本(否则孤儿文件遗留且 drift 检不出)
109
+ for (const t of s.targets || []) {
110
+ if (targets.includes(t)) continue;
111
+ const dir = targetDirFor(ctx, t, name);
112
+ if (dir) unproject(name, dir);
113
+ }
104
114
  for (const t of targets) {
105
115
  const dir = targetDirFor(ctx, t, name);
106
116
  if (!dir) continue;
@@ -122,11 +132,18 @@ export async function startServer(ctx, { quiet = false, port = 0 } = {}) {
122
132
  }
123
133
  res.writeHead(404); return res.end('{"error":"not found"}');
124
134
  }
125
- // 静态:public/ + evidence 文件(冲突截图)
126
- let p = u.pathname === '/' ? '/index.html' : u.pathname;
127
- let file = path.join(PUB, p);
128
- if (p.startsWith('/evidence/')) file = path.join(ctx.hub, p);
129
- if (!file.startsWith(PUB) && !file.startsWith(ctx.hub)) { res.writeHead(403); return res.end(); }
135
+ // 静态:public/ 公开;/evidence/ 需鉴权且锁死在 hub/evidence 内(防 ../ 穿越读 config.yml 等)
136
+ const p = u.pathname === '/' ? '/index.html' : u.pathname;
137
+ let file;
138
+ if (p.startsWith('/evidence/')) {
139
+ if (!authed) { res.writeHead(401); return res.end(); }
140
+ const evDir = path.join(ctx.hub, 'evidence');
141
+ file = path.join(evDir, p.slice('/evidence/'.length));
142
+ if (!path.resolve(file).startsWith(path.resolve(evDir))) { res.writeHead(403); return res.end(); }
143
+ } else {
144
+ file = path.join(PUB, p);
145
+ if (!path.resolve(file).startsWith(PUB)) { res.writeHead(403); return res.end(); }
146
+ }
130
147
  if (!fs.existsSync(file) || fs.statSync(file).isDirectory()) { res.writeHead(404); return res.end('nf'); }
131
148
  res.setHeader('content-type', MIME[path.extname(file)] || 'application/octet-stream');
132
149
  fs.createReadStream(file).pipe(res);
@@ -1,33 +1,15 @@
1
- // daemon.js — 单例守护:daemon.json{pid,port,token,started} + spawn + openURL
1
+ // daemon.js — daemon.json{pid,port,token,started} + openURL + CLI 自动接管
2
2
  import fs from 'node:fs';
3
3
  import path from 'node:path';
4
- import crypto from 'node:crypto';
5
- import { spawn, execFileSync } from 'node:child_process';
4
+ import { execFileSync } from 'node:child_process';
6
5
 
7
6
  export const daemonFile = (hub) => path.join(hub, 'daemon.json');
8
- const alive = (pid) => { try { process.kill(pid, 0); return true; } catch { return false; } };
7
+ export const pidAlive = (pid) => { try { process.kill(pid, 0); return true; } catch { return false; } };
9
8
 
10
9
  export function readDaemon(hub) {
11
10
  try { return JSON.parse(fs.readFileSync(daemonFile(hub), 'utf8')); } catch { return null; }
12
11
  }
13
12
 
14
- export async function ensureDaemon(ctx) {
15
- const d = readDaemon(ctx.hub);
16
- if (d && alive(d.pid)) return d;
17
- const bin = path.join(new URL('.', import.meta.url).pathname, '../bin/skillmkt.js');
18
- const child = spawn(process.execPath, [bin, 'serve', '--daemon'], {
19
- env: { ...process.env, SKILLMKT_HOME: ctx.hub },
20
- detached: true, stdio: 'ignore',
21
- });
22
- child.unref();
23
- for (let i = 0; i < 40; i++) {
24
- await new Promise((r) => setTimeout(r, 100));
25
- const nd = readDaemon(ctx.hub);
26
- if (nd && alive(nd.pid)) return nd;
27
- }
28
- throw new Error('daemon 启动超时');
29
- }
30
-
31
13
  export function openURL(d, route = '/') {
32
14
  // token 必须进 ?search(location.search 可读);#fragment 只带 tab 名
33
15
  const frag = route.includes('#') ? `#${route.split('#')[1]}` : '';
@@ -41,8 +23,9 @@ export function openURL(d, route = '/') {
41
23
  export async function maybeHandoff(ctx, route = '/') {
42
24
  if (!process.stdout.isTTY || ctx.flags.raw.cli || ctx.flags.raw.noUi) return false;
43
25
  if (ctx.flags.raw.ui === false) return false;
26
+ if (ctx.config?.ui?.enabled === 'never' || ctx.config?.ui?.enabled === false) return false;
44
27
  const d = readDaemon(ctx.hub);
45
- if (d && alive(d.pid)) {
28
+ if (d && pidAlive(d.pid)) {
46
29
  console.log(`opened ${openURL(d, route)}(服务已在跑,Ctrl-C 那个终端的 serve 可停)`);
47
30
  return true;
48
31
  }
@@ -7,12 +7,13 @@ import { treeHash } from './package.js';
7
7
  import { dashboard } from './render.js';
8
8
  import { listYAML } from './yamlls.js';
9
9
 
10
- export function renderDashboard(ctx) {
10
+ export async function renderDashboard(ctx) {
11
11
  const { hub, library, harnesses, llm, project, config } = ctx;
12
12
 
13
- // ui.enabled=always → 开面板(daemon 接管,批次7 实装前降级终端仪表盘)
13
+ // ui.enabled=always → 前台起服务开面板(挂住流日志,Ctrl-C 一起退)
14
14
  if (config.ui.enabled === 'always' && ctx.tty && ctx.flags.ui !== 'off') {
15
- // TODO(batch7): ensureDaemon + openURL('/')
15
+ const { maybeHandoff } = await import('./daemon.js');
16
+ if (await maybeHandoff(ctx, '/')) return 0; // 接管后永不返回
16
17
  }
17
18
 
18
19
  const rows = scanAll(hub, harnesses, library, project?.root);
@@ -2,14 +2,14 @@
2
2
  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
- const esc = (s) => String(s ?? '').replace(/[&<>]/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;' }[c]));
5
+ const esc = (s) => String(s ?? '').replace(/[&<>"']/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c]));
6
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
- catch (e) { document.getElementById('app').innerHTML = `<p class="pill bad">/api/state 请求失败:${esc(e.message)}——daemon 挂了?重跑 skillmkt serve</p>`; return; }
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
10
+ catch (e) { document.getElementById('app').innerHTML = `<p class="pill bad">连不上本地服务:${esc(e.message)}——服务可能已退出,重跑 <code>skillmkt serve</code></p>`; return; }
11
+ if (S?.error) { document.getElementById('app').innerHTML = `<p class="pill bad">${esc(S.error)}——网址里的 token 已失效,重跑 <code>skillmkt serve</code> 拿新链接</p>`; return; }
12
+ if (!location.hash && !S.initialized) { tab = 'setup'; location.hash = 'setup'; } // 未初始化→设置页
13
13
  render();
14
14
  }
15
15
  const syncTabs = () => document.querySelectorAll('nav [data-t]').forEach((x) => x.classList.toggle('on', x.dataset.t === tab));
@@ -18,72 +18,93 @@ const es = new EventSource(`/api/events?token=${T}`);
18
18
  es.addEventListener('decide', () => refresh());
19
19
  es.addEventListener('config', () => refresh());
20
20
  es.addEventListener('targets', () => refresh());
21
- es.onopen = () => document.getElementById('live').textContent = 'live';
22
- es.onerror = () => document.getElementById('live').textContent = 'offline';
21
+ const live = document.getElementById('live');
22
+ es.onopen = () => { live.classList.remove('off'); live.innerHTML = '<span class="dot"></span>已连接'; };
23
+ es.onerror = () => { live.classList.add('off'); live.innerHTML = '<span class="dot"></span>已断开'; };
23
24
 
25
+ // 机器状态 → 人话
26
+ const CN = {
27
+ installed: '已安装', available: '可用', likely: '疑似已装', absent: '未检测到',
28
+ managed: '已纳入管理', external: '未管理', 'hub-untracked': '未登记',
29
+ clean: '安全', suspicious: '可疑', malicious: '危险',
30
+ pending: '待处理', decided: '已裁决', resolved: '已裁决', dismissed: '已忽略',
31
+ outdated: '有更新', missing: '文件缺失', 'content-differs': '内容被改过', drifted: '有改动',
32
+ 'keep-a': '采用 A', 'keep-b': '采用 B', merge: '已合并', active: '生效中',
33
+ };
24
34
  const pill = (v) => {
25
- const cls = ['clean', 'installed', 'active', 'managed', 'keep-a', 'keep-b'].includes(v) ? 'ok'
26
- : ['malicious', 'pending', 'missing', 'outdated'].includes(v) ? 'bad' : 'warn';
27
- return `<span class="pill ${cls}">${esc(v)}</span>`;
35
+ const cls = ['clean', 'installed', 'active', 'managed', 'keep-a', 'keep-b', 'decided', 'resolved', 'merge'].includes(v) ? 'ok'
36
+ : ['malicious', 'pending', 'missing', 'outdated', 'content-differs'].includes(v) ? 'bad' : 'warn';
37
+ return `<span class="pill ${cls}">${esc(CN[v] || v)}</span>`;
28
38
  };
29
39
 
30
40
  async function render() {
31
41
  const app = document.getElementById('app');
32
- document.getElementById('foot').textContent = `hub: ${S.hub}`;
42
+ document.getElementById('foot').textContent = `数据目录:${S.hub}`;
33
43
  syncTabs();
34
44
 
35
45
  if (tab === 'skills') {
36
46
  const skills = Object.entries(S.library.skills || {});
37
- app.innerHTML = `<h2>已安装 skills(${skills.length})</h2>` + (skills.map(([n, s]) => `
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">装在:${(s.targets || []).join('、') || '无'}</span>
47
+ app.innerHTML = `<h2>已安装的 skill(${skills.length})</h2>
48
+ <p class="desc">通过 skillmkt 安装、统一管理的 skill。点开「安装位置」可以决定它出现在哪些 AI 工具的 skills 目录里。</p>`
49
+ + (skills.map(([n, s]) => `
50
+ <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')}
51
+ <span class="mut" style="margin-left:auto">装在:${(s.targets || []).map((t) => esc(CN[t] || t)).join('、') || '仅仓库'}</span>
40
52
  <button data-tg="${esc(n)}">安装位置</button></div>
41
- <div class="tgbox" data-box="${esc(n)}" style="display:none;margin-top:8px"></div></div>`).join('') || '<p class="mut">还没有受管 skill——skillmkt install &lt;ref&gt;</p>');
53
+ <div class="tgbox" data-box="${esc(n)}" style="display:none;margin-top:10px"></div></div>`).join('')
54
+ || `<div class="empty">还没有安装任何 skill。<br>在终端运行 <code>skillmkt install 名称</code> 安装;不知道装什么可以先 <code>skillmkt search 关键词</code> 搜一搜。</div>`);
42
55
  app.querySelectorAll('[data-tg]').forEach((b) => b.onclick = () => {
43
56
  const box = app.querySelector(`[data-box="${b.dataset.tg}"]`);
44
57
  if (box.style.display === 'block') { box.style.display = 'none'; return; }
45
58
  const s = S.library.skills[b.dataset.tg];
46
59
  box.style.display = 'block';
47
- box.innerHTML = `<label class="field">装到这些 agent(勾选后立即复制生效)</label>` +
48
- (S.harnesses || []).filter((x) => x.state === 'installed' && !x.detectOnly).map((x) =>
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
- + `<div class="row" style="margin-top:8px"><button class="primary tgo">应用目标</button><span class="tout mut"></span></div>`;
60
+ box.innerHTML = `<label class="field">复制到这些 AI 工具(取消勾选会把已复制的删掉)</label>` +
61
+ (S.harnesses || []).filter((x) => x.state !== 'absent' && !x.detectOnly).map((x) =>
62
+ `<label class="check"><input type="checkbox" data-th="${esc(x.id)}" ${(s.targets || []).includes(x.id) ? 'checked' : ''}> ${esc(x.id)} ${pill(x.state)} <span class="mut">${esc(x.primaryDir || '')}</span></label>`).join('')
63
+ + `<div class="row" style="margin-top:10px"><button class="primary tgo">保存安装位置</button><span class="tout mut"></span></div>`;
51
64
  box.querySelector('.tgo').onclick = async () => {
52
65
  const ts = [...box.querySelectorAll('[data-th]:checked')].map((x) => x.dataset.th);
53
66
  const r = await api('/targets', { method: 'POST', body: JSON.stringify({ name: b.dataset.tg, targets: ts }) });
54
- box.querySelector('.tout').textContent = r.ok ? '已应用' : `失败:${r.error}`;
67
+ box.querySelector('.tout').textContent = r.ok ? '已保存并生效' : `失败:${r.error}`;
55
68
  refresh();
56
69
  };
57
70
  });
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('');
71
+ app.innerHTML += `<h2>你电脑上的 AI 工具</h2>
72
+ <p class="desc">检测到的 agent 及其 skills 目录。「可用」表示工具已安装、目录会在首次安装 skill 时自动建好。</p>`
73
+ + (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]?.path || '')}</span></div>`).join('');
59
74
  const up = S.upstream.skills || {};
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('');
75
+ const outs = Object.entries(up).filter(([, u]) => u.outdated);
76
+ if (outs.length) app.innerHTML += `<h2>有更新可用(${outs.length})</h2>
77
+ <p class="desc">上游发布了新版本。终端运行 <code>skillmkt upgrade</code> 更新。</p>`
78
+ + outs.map(([n]) => `<div class="card row"><b>${esc(n)}</b>${pill('outdated')}</div>`).join('');
61
79
  }
62
80
 
63
81
  if (tab === 'conflicts') {
64
82
  const cs = S.conflicts || [];
65
83
  const pendN = cs.filter((c) => c.status === 'pending').length;
66
- app.innerHTML = `<h2>冲突队列(${pendN} 待裁决)</h2>`;
84
+ app.innerHTML = `<h2>冲突处理(${pendN} 条待处理)</h2>
85
+ <p class="desc">不同 skill 对同一件事给出相反规则时,需要你拍板。每条冲突填一句理由,然后选 A、选 B、自己合并,或者标为误报。</p>`;
67
86
  for (const c of cs) {
68
87
  const card = el(`<div class="card"><div class="row"><b>${esc(c.id)}</b>${pill(c.status)}<span class="mut">${esc(c.domain || '')}</span></div>
69
- <div class="side a">A · ${esc(c.sides[0].source)}<br>${esc(c.sides[0].text)}</div>
70
- <div class="side b">B · ${esc(c.sides[1].source)}<br>${esc(c.sides[1].text)}</div>
71
- ${c.ai_explanation ? `<p class="mut">${esc(c.ai_explanation)}</p>` : ''}
72
- ${c.dismiss_reason ? `<p class="mut">dismiss:${esc(c.dismiss_reason)}</p>` : ''}
88
+ <div class="side a"><span class="who">方案 A · 来自 ${esc(c.sides[0].source)}</span>${esc(c.sides[0].text)}</div>
89
+ <div class="side b"><span class="who">方案 B · 来自 ${esc(c.sides[1].source)}</span>${esc(c.sides[1].text)}</div>
90
+ ${c.ai_explanation ? `<p class="mut">AI 分析:${esc(c.ai_explanation)}</p>` : ''}
91
+ ${c.dismiss_reason ? `<p class="mut">误报原因:${esc(c.dismiss_reason)}</p>` : ''}
73
92
  <div class="ev-imgs"></div>
74
- ${c.status === 'pending' ? `<div class="row" style="margin-top:8px">
75
- <button data-r="keep-a">保留 A</button><button data-r="keep-b">保留 B</button>
76
- <button data-r="merge">合并两条…</button><button data-r="dismissed">标为误报</button></div>
77
- <div class="editbox" style="display:none;margin-top:8px">
78
- <label class="field">合并后的规则文本</label><textarea class="mtext"></textarea>
79
- <label class="field">裁决理由(必填)</label><input type="text" class="reason">
80
- <div class="row" style="margin-top:8px"><button class="primary go">提交合并</button><button class="cancel">取消</button></div></div>` : ''}</div>`);
93
+ ${c.status === 'pending' ? `
94
+ <label class="field">裁决理由(必填——以后翻记录时知道为什么这么选)</label>
95
+ <input type="text" class="reason" placeholder="例:A 的规则更具体,覆盖了 B 的场景">
96
+ <div class="row" style="margin-top:12px">
97
+ <button data-r="keep-a">采用方案 A</button><button data-r="keep-b">采用方案 B</button>
98
+ <button data-r="merge">自己合并两条…</button><button data-r="dismissed">其实不冲突</button><span class="err mut"></span></div>
99
+ <div class="editbox" style="display:none;margin-top:12px">
100
+ <label class="field">合并后的规则文本(已预填两条原文,直接改)</label><textarea class="mtext"></textarea>
101
+ <div class="row" style="margin-top:10px"><button class="primary go">提交合并</button><button class="cancel">取消</button></div></div>` : ''}</div>`);
81
102
  if (c.evidence_files) card.querySelector('.ev-imgs').innerHTML = c.evidence_files.filter((f) => f.endsWith('.png')).map((f) => `<img class="ev" src="/evidence/${c.id}/${f}?token=${T}" alt="evidence ${esc(f)}">`).join('');
82
103
  const post = async (resolution, custom) => {
83
- let reason = card.querySelector('.reason')?.value;
84
- if (!reason) reason = prompt('裁决理由(必填):', '') || '';
85
- if (!reason.trim()) return alert('裁决理由必填');
86
- await api('/decide', { method: 'POST', body: JSON.stringify({ id: c.id, resolution, custom, reason }) });
104
+ const reason = card.querySelector('.reason')?.value || '';
105
+ if (!reason.trim()) { card.querySelector('.err').textContent = '先填一句裁决理由'; card.querySelector('.reason')?.focus(); return; }
106
+ const r = await api('/decide', { method: 'POST', body: JSON.stringify({ id: c.id, resolution, custom, reason }) });
107
+ if (r?.error) { card.querySelector('.err').textContent = r.error; return; }
87
108
  refresh();
88
109
  };
89
110
  card.querySelectorAll('button[data-r]').forEach((b) => b.onclick = async () => {
@@ -100,14 +121,19 @@ async function render() {
100
121
  card.querySelector('.editbox .cancel')?.addEventListener('click', () => { card.querySelector('.editbox').style.display = 'none'; });
101
122
  app.appendChild(card);
102
123
  }
103
- if (!cs.length) app.innerHTML += '<p class="mut">无冲突记录——skillmkt merge &lt;a&gt; &lt;b&gt; 生成队列</p>';
124
+ if (!cs.length) app.innerHTML += '<div class="empty">没有待处理的冲突。<br>合并两个 skill 时会自动检测:<code>skillmkt merge 名字A 名字B</code></div>';
104
125
  }
105
126
 
106
127
  if (tab === 'review') {
107
128
  const scans = S.scans || [];
108
- app.innerHTML = `<h2>审核记录(${scans.length})</h2>` + (scans.map((s) => `<div class="card row"><b>${esc(s.skill || s.name || '')}</b>${pill(s.verdict)}<span class="mut">${(s.findings || []).length} findings${s.llm ? `,llm: ${esc(s.llm.verdict)}` : ''}</span></div>`).join('') || '<p class="mut">无审核记录</p>');
129
+ app.innerHTML = `<h2>安全检查记录(${scans.length})</h2>
130
+ <p class="desc">每次安装 skill 时做的供应链安全检查结果(恶意脚本、凭证收集等)。</p>`
131
+ + (scans.map((s) => `<div class="card row"><b>${esc(s.skill || s.name || '')}</b>${pill(s.verdict)}<span class="mut">${(s.findings || []).length} 条发现${s.llm ? `,AI 复审:${esc(CN[s.llm.verdict] || s.llm.verdict)}` : ''}</span></div>`).join('')
132
+ || '<div class="empty">还没有检查记录——安装 skill 时会自动生成。</div>');
109
133
  const decs = (S.decisions || []).filter((d) => d.status === 'active');
110
- if (decs.length) app.innerHTML += `<h2>已生效裁决(${decs.length})</h2>` + decs.map((d) => `<div class="card"><div class="row"><b>${esc(d.id)}</b>${pill(d.resolution)}<span class="mut">by ${esc(d.decided_by)}</span></div><p class="mut">${esc(d.reason)}</p></div>`).join('');
134
+ if (decs.length) app.innerHTML += `<h2>我的裁决记录(${decs.length})</h2>
135
+ <p class="desc">你在「冲突处理」里做过的拍板,都在这里留底。</p>`
136
+ + decs.map((d) => `<div class="card"><div class="row"><b>${esc(d.id)}</b>${pill(d.resolution)}<span class="mut">via ${esc(d.decided_by)}</span></div><p class="mut">${esc(d.reason)}</p></div>`).join('');
111
137
  }
112
138
 
113
139
  if (tab === 'setup') {
@@ -115,33 +141,42 @@ async function render() {
115
141
  const cfg = await api('/config');
116
142
  const installed = h.filter((x) => x.state === 'installed' && !x.detectOnly).map((x) => x.id);
117
143
  const sel = new Set(cfg.default_targets?.length ? cfg.default_targets : installed);
118
- app.innerHTML = `<h2>初始化与配置</h2>
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">扫描本地 LLM 服务</button><span id="probe-out" class="mut"></span></div>
144
+ app.innerHTML = `<h2>设置</h2>
145
+ <p class="desc">一次配置即可:AI 模型可选(用于冲突自动仲裁等智能功能,不配也能正常用);安装位置决定新 skill 默认复制到哪些 AI 工具。</p>
146
+ <div class="card"><h3>第 1 步 · AI 模型(可选)</h3>
147
+ <p class="mut">点「扫描」自动发现本机正在运行的模型服务(LM Studio、Ollama、oMLX 等)。${cfg.llm?.model ? `当前使用:<code>${esc(cfg.llm.model)}</code>` : ''}</p>
148
+ <div class="row"><button id="probe">扫描本机模型服务</button><span id="probe-out" class="mut"></span></div>
121
149
  <div id="eps"></div>
122
- <label class="field">base_url</label><input type="text" id="murl" value="${esc(cfg.llm?.base_url || '')}">
123
- <label class="field">model</label><input type="text" id="mmodel" value="${esc(cfg.llm?.model || '')}">
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">测试连接</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
- ${h.map((x) => `<label class="row"><input type="checkbox" data-h="${esc(x.id)}" ${sel.has(x.id) ? 'checked' : ''} ${x.state === 'absent' ? 'disabled' : ''}> ${esc(x.id)} ${pill(x.state)} <span class="mut">${esc(x.primaryDir || '')}</span></label>`).join('')}</div>
128
- <div class="card"><button class="primary" id="save">保存配置</button><span id="save-out" class="mut"></span></div>`;
150
+ <label class="field">服务地址</label><input type="text" id="murl" placeholder="http://localhost:1234/v1" value="${esc(cfg.llm?.base_url || '')}">
151
+ <label class="field">模型名称</label><input type="text" id="mmodel" placeholder="点上面扫描出的条目可自动填入" value="${esc(cfg.llm?.model || '')}">
152
+ <label class="field">访问密钥</label><input type="text" id="mkey" value="${esc(cfg.llm?.api_key || '')}">
153
+ <p class="mut">可填 <code>env:变量名</code> 引用环境变量,密钥真值不会写进配置文件;本机服务一般留空即可。</p>
154
+ <div class="row"><button id="smoke">测试连接</button><span id="smoke-out" class="mut"></span></div></div>
155
+ <div class="card"><h3>第 2 步 · skill 默认安装位置</h3>
156
+ <p class="mut">勾选的 AI 工具会在你安装新 skill 时自动收到一份副本。已勾过的话保存即生效。</p>
157
+ ${h.map((x) => `<label class="check"><input type="checkbox" data-h="${esc(x.id)}" ${sel.has(x.id) ? 'checked' : ''} ${x.state === 'absent' ? 'disabled' : ''}> ${esc(x.id)} ${pill(x.state)} <span class="mut">${esc(x.primaryDir || '')}</span></label>`).join('')}</div>
158
+ <div class="card"><h3>第 3 步 · 保存</h3>
159
+ <div class="row"><button class="primary" id="save">保存设置</button><span id="save-out" class="mut"></span></div></div>`;
129
160
  app.querySelector('#probe').onclick = async () => {
130
161
  app.querySelector('#probe-out').textContent = '扫描中…';
131
162
  const eps = await api('/probe');
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
- app.querySelector('#probe-out').textContent = `${eps.length} 个端点`;
134
- app.querySelectorAll('#eps [data-b]').forEach((d) => d.onclick = () => { app.querySelector('#murl').value = d.dataset.b; app.querySelector('#mmodel').value = d.dataset.m; });
163
+ 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" style="margin-top:8px">没扫到——请确认模型服务已启动(会检查 8001 / 11434 / 1234 / 8000 / 8080 / 1337 / 5000 端口)</p>';
164
+ app.querySelector('#probe-out').textContent = `发现 ${eps.length} 个服务,点击条目自动填入`;
165
+ app.querySelectorAll('#eps [data-b]').forEach((d) => d.onclick = () => {
166
+ app.querySelectorAll('#eps .ep').forEach((x) => x.classList.remove('sel'));
167
+ d.classList.add('sel');
168
+ app.querySelector('#murl').value = d.dataset.b; app.querySelector('#mmodel').value = d.dataset.m;
169
+ });
135
170
  };
136
171
  app.querySelector('#smoke').onclick = async () => {
137
- app.querySelector('#smoke-out').textContent = '调用中…';
172
+ app.querySelector('#smoke-out').textContent = '测试中…';
138
173
  const r = await api('/llm-smoke', { method: 'POST', body: JSON.stringify({ base_url: app.querySelector('#murl').value, model: app.querySelector('#mmodel').value, api_key: app.querySelector('#mkey').value }) });
139
- app.querySelector('#smoke-out').textContent = r.ok ? `通过:${r.reply}` : `失败:${r.error}`;
174
+ app.querySelector('#smoke-out').textContent = r.ok ? `连接成功,模型回复:${r.reply}` : `连接失败:${r.error}`;
140
175
  };
141
176
  app.querySelector('#save').onclick = async () => {
142
177
  const targets = [...app.querySelectorAll('[data-h]:checked')].map((x) => x.dataset.h);
143
178
  const r = await api('/config', { method: 'POST', body: JSON.stringify({ llm: { base_url: app.querySelector('#murl').value || null, model: app.querySelector('#mmodel').value || null, api_key: app.querySelector('#mkey').value || undefined, concurrency: 2, timeout_ms: 60000 }, default_targets: targets }) });
144
- app.querySelector('#save-out').textContent = r.ok ? ' 已写入 config.yml' : ` 失败:${r.error}`;
179
+ app.querySelector('#save-out').textContent = r.ok ? '已保存到 config.yml' : `保存失败:${r.error}`;
145
180
  refresh();
146
181
  };
147
182
  }
@@ -1,6 +1,6 @@
1
1
  <!doctype html>
2
2
  <html lang="zh"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
3
- <title>skillmkt — skills 管理面板</title>
3
+ <title>skillmkt — 本地 skill 管理面板</title>
4
4
  <style>
5
5
  /* skillmkt panel — 依 skill/SKILL.md 规则:light-first、OKLCH 角色 token、单强调色、
6
6
  无玻璃/渐变/emoji 图标、可见标签、focus-visible ring、每屏至多一个填充主按钮 */
@@ -8,83 +8,98 @@
8
8
  --color-paper: oklch(0.975 0.008 95);
9
9
  --color-surface: oklch(0.995 0.004 95);
10
10
  --color-ink: oklch(0.24 0.02 75);
11
- --color-ink-mut: oklch(0.52 0.02 75);
11
+ --color-ink-mut: oklch(0.50 0.02 75);
12
12
  --color-line: oklch(0.88 0.01 85);
13
13
  --color-accent: oklch(0.52 0.14 55); /* 烧橙——唯一强调色 */
14
14
  --color-accent-ink: oklch(0.99 0.01 90);
15
15
  --color-ok: oklch(0.52 0.11 155);
16
16
  --color-warn: oklch(0.55 0.13 80);
17
17
  --color-bad: oklch(0.50 0.17 28);
18
- --font-body: 15px/1.6 -apple-system, "SF Pro", "PingFang SC", "Noto Sans CJK SC", sans-serif;
18
+ --font-body: 17px/1.7 -apple-system, "SF Pro", "PingFang SC", "Noto Sans CJK SC", sans-serif;
19
19
  --font-display: ui-serif, Georgia, "Songti SC", serif;
20
20
  --font-mono: ui-monospace, SFMono-Regular, Menlo, monospace;
21
- --radius: 8px;
21
+ --radius: 10px;
22
22
  }
23
23
  * { box-sizing: border-box; }
24
24
  body { margin: 0; font: var(--font-body); background: var(--color-paper); color: var(--color-ink); }
25
25
 
26
- header { display: flex; align-items: baseline; gap: 26px; padding: 18px 28px 0; border-bottom: 1px solid var(--color-line); }
27
- header h1 { font: 600 22px/1 var(--font-display); margin: 0 4px 0 0; letter-spacing: -0.01em; text-wrap: balance; }
28
- nav { display: flex; gap: 4px; }
29
- nav button { background: none; border: 0; border-bottom: 2px solid transparent; padding: 8px 14px 10px;
30
- font: inherit; color: var(--color-ink-mut); cursor: pointer; }
26
+ header { display: flex; align-items: baseline; gap: 30px; padding: 22px 32px 0; border-bottom: 1px solid var(--color-line); flex-wrap: wrap; }
27
+ header .brand { display: flex; align-items: baseline; gap: 12px; }
28
+ header h1 { font: 600 24px/1 var(--font-display); margin: 0; letter-spacing: -0.01em; text-wrap: balance; }
29
+ header .tag { font-size: 14px; color: var(--color-ink-mut); }
30
+ nav { display: flex; gap: 6px; }
31
+ nav button { background: none; border: 0; border-bottom: 2px solid transparent; padding: 10px 18px 12px;
32
+ font: inherit; font-size: 16px; color: var(--color-ink-mut); cursor: pointer; }
31
33
  nav button.on { color: var(--color-ink); border-bottom-color: var(--color-accent); }
32
34
  nav button:hover { color: var(--color-ink); }
33
- #live { margin-left: auto; font-size: 13px; color: var(--color-ink-mut); padding-bottom: 10px; }
35
+ #live { margin-left: auto; font-size: 14px; color: var(--color-ink-mut); padding-bottom: 12px; display: flex; align-items: center; gap: 7px; }
36
+ #live .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--color-ok); }
37
+ #live.off .dot { background: var(--color-bad); }
34
38
 
35
- main { padding: 24px 28px 60px; max-width: 1080px; }
36
- h2 { font: 600 17px/1.3 var(--font-body); margin: 26px 0 10px; text-wrap: balance; }
39
+ main { padding: 30px 32px 80px; max-width: 1060px; }
40
+ h2 { font: 600 21px/1.3 var(--font-display); margin: 38px 0 4px; text-wrap: balance; }
37
41
  h2:first-child { margin-top: 0; }
42
+ .desc { margin: 0 0 18px; color: var(--color-ink-mut); font-size: 15.5px; max-width: 64ch; }
38
43
  .mut { color: var(--color-ink-mut); }
39
- code { font-family: var(--font-mono); font-size: 0.92em; }
44
+ code { font-family: var(--font-mono); font-size: 0.9em; background: color-mix(in oklch, var(--color-ink) 5%, var(--color-paper)); padding: 1px 5px; border-radius: 4px; }
40
45
 
41
46
  .card { background: var(--color-surface); border: 1px solid var(--color-line); border-radius: var(--radius);
42
- padding: 14px 16px; margin-bottom: 10px; }
43
- .row { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
47
+ padding: 18px 20px; margin-bottom: 14px; }
48
+ .card h3 { font: 600 17px/1.3 var(--font-body); margin: 0 0 6px; }
49
+ .row { display: flex; gap: 12px; align-items: baseline; flex-wrap: wrap; }
44
50
  .row.end { justify-content: flex-end; }
45
51
 
46
- .pill { display: inline-block; padding: 1px 9px; border: 1px solid var(--color-line); border-radius: 99px;
47
- font-size: 12px; line-height: 1.5; color: var(--color-ink-mut); }
52
+ .pill { display: inline-block; padding: 2px 11px; border: 1px solid var(--color-line); border-radius: 99px;
53
+ font-size: 13.5px; line-height: 1.6; color: var(--color-ink-mut); white-space: nowrap; }
48
54
  .pill.ok { color: var(--color-ok); border-color: color-mix(in oklch, var(--color-ok) 40%, var(--color-line)); }
49
55
  .pill.warn { color: var(--color-warn); border-color: color-mix(in oklch, var(--color-warn) 45%, var(--color-line)); }
50
56
  .pill.bad { color: var(--color-bad); border-color: color-mix(in oklch, var(--color-bad) 45%, var(--color-line)); }
51
57
 
52
- button { font: inherit; padding: 6px 14px; border: 1px solid var(--color-line); border-radius: 6px;
58
+ button { font: inherit; font-size: 15.5px; padding: 8px 18px; border: 1px solid var(--color-line); border-radius: 8px;
53
59
  background: var(--color-surface); color: var(--color-ink); cursor: pointer; }
54
60
  button:hover { border-color: var(--color-ink-mut); }
55
- button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible {
61
+ button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible {
56
62
  outline: 2px solid var(--color-accent); outline-offset: 2px; }
57
63
  button.primary { background: var(--color-accent); border-color: var(--color-accent); color: var(--color-accent-ink); }
58
64
  button.primary:hover { filter: brightness(0.94); }
65
+ button:disabled { opacity: 0.45; cursor: default; }
59
66
  @media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
60
67
 
61
- label.field { display: block; margin: 10px 0 2px; font-size: 13px; color: var(--color-ink-mut); }
68
+ label.field { display: block; margin: 14px 0 4px; font-size: 14.5px; color: var(--color-ink-mut); }
62
69
  input[type=text], input:not([type]), textarea, select {
63
- width: 100%; font: inherit; padding: 7px 10px; border: 1px solid var(--color-line);
64
- border-radius: 6px; background: var(--color-paper); color: var(--color-ink); }
65
- textarea { min-height: 6rem; resize: vertical; font-family: var(--font-mono); font-size: 13px; }
70
+ width: 100%; font: inherit; font-size: 16px; padding: 9px 13px; border: 1px solid var(--color-line);
71
+ border-radius: 8px; background: var(--color-paper); color: var(--color-ink); }
72
+ textarea { min-height: 7rem; resize: vertical; font-family: var(--font-mono); font-size: 14.5px; }
73
+ input[type=checkbox] { width: 17px; height: 17px; accent-color: var(--color-accent); margin-right: 2px; }
74
+ label.check { display: flex; gap: 10px; align-items: center; padding: 7px 4px; cursor: pointer; border-radius: 6px; }
75
+ label.check:hover { background: color-mix(in oklch, var(--color-ink) 4%, var(--color-surface)); }
66
76
 
67
- .side { padding: 10px 12px; border-left: 2px solid var(--color-line); margin: 8px 0; font-size: 14px; }
77
+ .side { padding: 14px 16px; border-left: 3px solid var(--color-line); margin: 10px 0; font-size: 15.5px;
78
+ background: color-mix(in oklch, var(--color-ink) 3%, var(--color-surface)); border-radius: 0 8px 8px 0; }
79
+ .side .who { display: block; font-size: 14px; font-weight: 600; margin-bottom: 4px; }
68
80
  .side.a { border-color: var(--color-accent); }
69
81
  .side.b { border-color: var(--color-warn); }
70
- img.ev { max-width: 360px; width: 100%; border: 1px solid var(--color-line); border-radius: 6px; margin: 6px 8px 0 0; }
82
+ img.ev { max-width: 420px; width: 100%; border: 1px solid var(--color-line); border-radius: 8px; margin: 8px 10px 0 0; }
71
83
 
72
- .ep { cursor: pointer; padding: 5px 10px; border-radius: 6px; }
84
+ .ep { cursor: pointer; padding: 8px 12px; border-radius: 8px; font-size: 15.5px; }
73
85
  .ep:hover { background: var(--color-paper); }
74
- table { width: 100%; border-collapse: collapse; font-size: 14px; }
75
- td, th { text-align: left; padding: 5px 10px; border-bottom: 1px solid var(--color-line); }
76
- th { font-size: 13px; color: var(--color-ink-mut); font-weight: 500; }
77
- footer { padding: 20px 28px; border-top: 1px solid var(--color-line); font-size: 13px; color: var(--color-ink-mut); }
86
+ .ep.sel { background: color-mix(in oklch, var(--color-accent) 10%, var(--color-surface)); }
87
+ table { width: 100%; border-collapse: collapse; font-size: 15.5px; }
88
+ td, th { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--color-line); }
89
+ th { font-size: 14px; color: var(--color-ink-mut); font-weight: 500; }
90
+ .empty { padding: 26px 20px; color: var(--color-ink-mut); }
91
+ .empty code { font-size: 14.5px; }
92
+ footer { padding: 22px 32px; border-top: 1px solid var(--color-line); font-size: 14px; color: var(--color-ink-mut); }
78
93
  </style></head><body>
79
94
  <header>
80
- <h1>awesome-skill-market</h1>
95
+ <div class="brand"><h1>awesome-skill-market</h1><span class="tag">skillmkt 本地管理面板</span></div>
81
96
  <nav>
82
- <button class="on" data-t="skills">skills</button>
83
- <button data-t="conflicts">conflicts</button>
84
- <button data-t="review">review</button>
85
- <button data-t="setup">setup</button>
97
+ <button class="on" data-t="skills">已安装</button>
98
+ <button data-t="conflicts">冲突处理</button>
99
+ <button data-t="review">安全审核</button>
100
+ <button data-t="setup">设置</button>
86
101
  </nav>
87
- <span id="live"></span>
102
+ <span id="live"><span class="dot"></span>连接中…</span>
88
103
  </header>
89
104
  <main id="app"><p class="mut">载入中…</p></main>
90
105
  <footer id="foot"></footer>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "skillmkt",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "type": "module",
5
5
  "description": "Local-first agent skill manager: install, audit, merge, distribute.",
6
6
  "license": "MIT",