skillmkt 0.4.30 → 0.4.32
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/install.js +3 -2
- package/client/commands/serve.js +101 -5
- package/client/lib/ctx.js +1 -1
- package/client/public/app.js +186 -8
- package/client/public/index.html +2 -0
- package/package.json +1 -1
|
@@ -103,11 +103,12 @@ export async function run(ctx) {
|
|
|
103
103
|
fail(L(`判定为恶意——已隔离: ${name}(${audit.findings.length} 处发现)`, `malicious — quarantined: ${name} (${audit.findings.length} findings)`));
|
|
104
104
|
return 2;
|
|
105
105
|
}
|
|
106
|
-
|
|
106
|
+
const policy = flags.policy || ctx.config.policy;
|
|
107
|
+
if (audit.verdict === 'suspicious' && policy !== 'permissive') {
|
|
107
108
|
warn(L(`可疑:发现 ${audit.findings.length} 处${audit.stripped.length ? `,已剔除 ${audit.stripped.length} 个文件` : ''}`, `suspicious: ${audit.findings.length} findings${audit.stripped.length ? `, stripping ${audit.stripped.length} files` : ''}`));
|
|
108
109
|
audit.findings.slice(0, 5).forEach((f) => info(`${f.rule} ${f.file}:${f.line} — ${f.excerpt.slice(0, 80)}`));
|
|
109
110
|
// --yes 不放大 suspicious(安全默认);strict 直接拒
|
|
110
|
-
const proceed =
|
|
111
|
+
const proceed = policy === 'strict' ? false : await confirm(L(`继续安装 ${name}?`, `Install ${name} anyway?`), { defaultYes: false });
|
|
111
112
|
if (!proceed) { fail(L('已取消', 'install aborted')); return 2; }
|
|
112
113
|
}
|
|
113
114
|
|
package/client/commands/serve.js
CHANGED
|
@@ -3,22 +3,32 @@ import fs from 'node:fs';
|
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import http from 'node:http';
|
|
5
5
|
import crypto from 'node:crypto';
|
|
6
|
-
import { daemonFile, readDaemon } from '../lib/daemon.js';
|
|
6
|
+
import { daemonFile, readDaemon, openURL } from '../lib/daemon.js';
|
|
7
7
|
import { loadConflicts } from '../lib/conflicts.js';
|
|
8
8
|
import { loadDecisions, decide } from '../lib/decide.js';
|
|
9
9
|
import { readLibrary, readLock, readConfig, writeConfig, registerSkill, updateLock, ensureHub, isInitialized } from '../lib/hub.js';
|
|
10
10
|
import { readUpstream } from '../lib/state.js';
|
|
11
11
|
import { readYAML } from '../../pipeline/lib/util.js';
|
|
12
|
-
import { detectHarnesses } from '../lib/scanner.js';
|
|
12
|
+
import { detectHarnesses, scanAll } from '../lib/scanner.js';
|
|
13
13
|
import { probeEndpoints, chat, encryptSecret, resolveKeyRef, listModels } from '../lib/llm.js';
|
|
14
14
|
import { projectSkill, unproject, targetDirFor } from '../lib/project.js';
|
|
15
|
-
import { treeHash } from '../lib/package.js';
|
|
15
|
+
import { readSkillDir, treeHash } from '../lib/package.js';
|
|
16
|
+
import { searchRemote } from '../lib/registries/skillssh.js';
|
|
17
|
+
import { execFile } from 'node:child_process';
|
|
16
18
|
import { ok, info } from '../lib/render.js';
|
|
17
19
|
import { L, detectLang } from '../lib/i18n.js';
|
|
18
20
|
|
|
19
21
|
const PUB = path.join(new URL('.', import.meta.url).pathname, '../public');
|
|
22
|
+
const CLI = path.join(new URL('.', import.meta.url).pathname, '../bin/skillmkt.js');
|
|
20
23
|
const MIME = { '.html': 'text/html', '.js': 'text/javascript', '.css': 'text/css', '.png': 'image/png', '.svg': 'image/svg+xml' };
|
|
21
24
|
|
|
25
|
+
// CLI 子进程复用——装/删/合并/升级等操作走同一套实现,不复制逻辑
|
|
26
|
+
// '--' 隔开 flag 与用户输入,防 -开头的 ref 被当 flag 解析
|
|
27
|
+
const cli = (args, timeout = 180e3) => new Promise((r) => {
|
|
28
|
+
execFile(process.execPath, [CLI, ...args], { timeout, env: { ...process.env, CI: '1' } },
|
|
29
|
+
(e, stdout, stderr) => r({ code: e ? (typeof e.code === 'number' ? e.code : 1) : 0, out: `${stdout || ''}${stderr || ''}`.trim() }));
|
|
30
|
+
});
|
|
31
|
+
|
|
22
32
|
// startServer — 可复用:serve 命令与 CLI 接管共用。返回 {port, token, server, emit, shutdown}
|
|
23
33
|
export async function startServer(ctx, { quiet = false, port = 0 } = {}) {
|
|
24
34
|
ensureHub(ctx.hub);
|
|
@@ -41,6 +51,13 @@ export async function startServer(ctx, { quiet = false, port = 0 } = {}) {
|
|
|
41
51
|
scans: fs.existsSync(path.join(ctx.hub, 'scans'))
|
|
42
52
|
? fs.readdirSync(path.join(ctx.hub, 'scans')).sort().map((f) => readYAML(path.join(ctx.hub, 'scans', f))).filter(Boolean)
|
|
43
53
|
: [],
|
|
54
|
+
merged: (() => {
|
|
55
|
+
const f = path.join(ctx.hub, 'merged', 'rules.yml');
|
|
56
|
+
if (!fs.existsSync(f)) return null;
|
|
57
|
+
const y = readYAML(f) || {};
|
|
58
|
+
return { name: y.name, sources: y.sources || [], rules: (y.rules || []).length,
|
|
59
|
+
built: fs.existsSync(path.join(ctx.hub, 'merged', 'skill-out', 'SKILL.md')) };
|
|
60
|
+
})(),
|
|
44
61
|
});
|
|
45
62
|
|
|
46
63
|
const routes = {
|
|
@@ -49,6 +66,17 @@ export async function startServer(ctx, { quiet = false, port = 0 } = {}) {
|
|
|
49
66
|
'GET /api/decisions': () => loadDecisions(ctx.hub),
|
|
50
67
|
'GET /api/config': () => readConfig(ctx.hub)._raw,
|
|
51
68
|
'GET /api/probe': async () => probeEndpoints(400, { extraBases: [readConfig(ctx.hub).llm?.base_url] }),
|
|
69
|
+
'GET /api/search': async (u) => { const q = u.searchParams.get('q') || ''; return q ? searchRemote(q, ctx) : { skills: [] }; },
|
|
70
|
+
'GET /api/scan': () => scanAll(ctx.hub, harnesses, readLibrary(ctx.hub), null)
|
|
71
|
+
.filter((r) => r.state === 'external')
|
|
72
|
+
.map((r) => ({ name: r.name, dir: r.targetDir || '', path: r.path, where: r.where, version: r.version, description: r.description || '' })),
|
|
73
|
+
'GET /api/skill': (u) => {
|
|
74
|
+
const n = u.searchParams.get('name') || '';
|
|
75
|
+
if (!n || n.includes('/') || n.includes('..')) return { error: 'bad name' };
|
|
76
|
+
const pkg = readSkillDir(path.join(ctx.hub, 'skills', n));
|
|
77
|
+
return pkg ? { ...pkg, library: readLibrary(ctx.hub).skills?.[n] || null } : { error: 'not found' };
|
|
78
|
+
},
|
|
79
|
+
'GET /api/diff': async (u) => cli(['diff', '--', u.searchParams.get('name') || '']),
|
|
52
80
|
};
|
|
53
81
|
const body = (req) => new Promise((r) => { let b = ''; req.on('data', (c) => b += c); req.on('end', () => r(b || '{}')); });
|
|
54
82
|
|
|
@@ -58,6 +86,15 @@ export async function startServer(ctx, { quiet = false, port = 0 } = {}) {
|
|
|
58
86
|
if (req.method === 'GET' && (p === '/' || p === '/index.html')) return L('打开了网页', 'opened the page');
|
|
59
87
|
if (req.method === 'POST' && p === '/api/config') return L('保存了设置', 'saved settings');
|
|
60
88
|
if (req.method === 'POST' && p === '/api/targets') return L('修改了 skill 的安装位置', 'changed skill install locations');
|
|
89
|
+
if (req.method === 'POST' && p === '/api/install') return L('安装了 skill', 'installed a skill');
|
|
90
|
+
if (req.method === 'POST' && p === '/api/remove') return L('移除了 skill', 'removed a skill');
|
|
91
|
+
if (req.method === 'POST' && p === '/api/merge') return L('合并了 skill', 'merged skills');
|
|
92
|
+
if (req.method === 'POST' && p === '/api/build') return L('生成了合并产物', 'built merged skill');
|
|
93
|
+
if (req.method === 'POST' && p === '/api/update') return L('刷新了上游信息', 'refreshed upstream info');
|
|
94
|
+
if (req.method === 'POST' && p === '/api/upgrade') return L('升级了 skill', 'upgraded skills');
|
|
95
|
+
if (req.method === 'POST' && p === '/api/sync') return L('修复了投影', 'repaired projections');
|
|
96
|
+
if (req.method === 'POST' && p === '/api/audit') return L('重新审核了 skill', 're-audited a skill');
|
|
97
|
+
if (req.method === 'POST' && p === '/api/rollback') return L('回滚了 skill', 'rolled back a skill');
|
|
61
98
|
return null;
|
|
62
99
|
};
|
|
63
100
|
|
|
@@ -157,12 +194,65 @@ export async function startServer(ctx, { quiet = false, port = 0 } = {}) {
|
|
|
157
194
|
emit('targets', { name });
|
|
158
195
|
return res.end('{"ok":true}');
|
|
159
196
|
}
|
|
197
|
+
if (u.pathname === '/api/install') {
|
|
198
|
+
const args = ['install', '--yes'];
|
|
199
|
+
if (b.path) args.push('--path', String(b.path));
|
|
200
|
+
if (b.permissive) args.push('--policy', 'permissive');
|
|
201
|
+
args.push('--', String(b.ref || ''));
|
|
202
|
+
const r = await cli(args);
|
|
203
|
+
emit('library', {});
|
|
204
|
+
return res.end(JSON.stringify(r));
|
|
205
|
+
}
|
|
206
|
+
if (u.pathname === '/api/remove') {
|
|
207
|
+
const r = await cli(['remove', ...(b.purge ? ['--purge'] : []), '--', String(b.name || '')]);
|
|
208
|
+
emit('library', {});
|
|
209
|
+
return res.end(JSON.stringify(r));
|
|
210
|
+
}
|
|
211
|
+
if (u.pathname === '/api/merge') {
|
|
212
|
+
const names = (b.names || []).map(String).filter(Boolean);
|
|
213
|
+
const args = ['merge'];
|
|
214
|
+
if (b.name) args.push('--name', String(b.name));
|
|
215
|
+
args.push('--', ...names);
|
|
216
|
+
const r = await cli(args);
|
|
217
|
+
emit('library', {});
|
|
218
|
+
return res.end(JSON.stringify(r));
|
|
219
|
+
}
|
|
220
|
+
if (u.pathname === '/api/build') {
|
|
221
|
+
const r = await cli(['build']);
|
|
222
|
+
emit('library', {});
|
|
223
|
+
return res.end(JSON.stringify(r));
|
|
224
|
+
}
|
|
225
|
+
if (u.pathname === '/api/update') {
|
|
226
|
+
const r = await cli(['update'], 300e3);
|
|
227
|
+
emit('library', {});
|
|
228
|
+
return res.end(JSON.stringify(r));
|
|
229
|
+
}
|
|
230
|
+
if (u.pathname === '/api/upgrade') {
|
|
231
|
+
const r = await cli(['upgrade', ...(b.name ? ['--', String(b.name)] : ['--all'])], 300e3);
|
|
232
|
+
emit('library', {});
|
|
233
|
+
return res.end(JSON.stringify(r));
|
|
234
|
+
}
|
|
235
|
+
if (u.pathname === '/api/sync') {
|
|
236
|
+
const r = await cli(['sync']);
|
|
237
|
+
emit('library', {});
|
|
238
|
+
return res.end(JSON.stringify(r));
|
|
239
|
+
}
|
|
240
|
+
if (u.pathname === '/api/audit') {
|
|
241
|
+
const r = await cli(['audit', '--', String(b.name || '')]);
|
|
242
|
+
emit('library', {});
|
|
243
|
+
return res.end(JSON.stringify(r));
|
|
244
|
+
}
|
|
245
|
+
if (u.pathname === '/api/rollback') {
|
|
246
|
+
const r = await cli(['rollback', '--', String(b.name || '')]);
|
|
247
|
+
emit('library', {});
|
|
248
|
+
return res.end(JSON.stringify(r));
|
|
249
|
+
}
|
|
160
250
|
} catch (e) { res.writeHead(400); return res.end(JSON.stringify({ error: e.message })); }
|
|
161
251
|
res.writeHead(404); return res.end('{"error":"not found"}');
|
|
162
252
|
}
|
|
163
253
|
const h = routes[`${req.method} ${u.pathname}`];
|
|
164
254
|
if (h) {
|
|
165
|
-
try { return res.end(JSON.stringify(await h())); }
|
|
255
|
+
try { return res.end(JSON.stringify(await h(u))); }
|
|
166
256
|
catch (e) { res.writeHead(500); return res.end(JSON.stringify({ error: e.message })); }
|
|
167
257
|
}
|
|
168
258
|
res.writeHead(404); return res.end('{"error":"not found"}');
|
|
@@ -213,12 +303,18 @@ export async function run(ctx) {
|
|
|
213
303
|
// 已有前台/分离实例在跑 → 不重复起,报地址
|
|
214
304
|
const existing = readDaemon(ctx.hub);
|
|
215
305
|
if (existing && existing.pid !== process.pid) {
|
|
216
|
-
try {
|
|
306
|
+
try {
|
|
307
|
+
process.kill(existing.pid, 0);
|
|
308
|
+
info(L(`已在跑: http://127.0.0.1:${existing.port}/?token=${existing.token}(--stop 停掉)`, `already running: http://127.0.0.1:${existing.port}/?token=${existing.token} (use --stop to stop)`));
|
|
309
|
+
if (ctx.tty && !flags.daemon) openURL(existing, '/');
|
|
310
|
+
return 0;
|
|
311
|
+
} catch { /* stale */ }
|
|
217
312
|
}
|
|
218
313
|
const d = await startServer(ctx, { quiet: !!flags.daemon, port: flags.port || 0 });
|
|
219
314
|
if (flags.daemon) { console.log(`daemon ready :${d.port}`); await new Promise(() => {}); }
|
|
220
315
|
console.log(`serve: http://127.0.0.1:${d.port}/?token=${d.token}`);
|
|
221
316
|
console.log(L(` 前台运行 — Ctrl-C 退出(idle ${ctx.config.daemon?.idle_minutes ?? 30}m 自退)`, ` running in foreground — Ctrl-C to exit (idle ${ctx.config.daemon?.idle_minutes ?? 30}m auto-stop)`));
|
|
317
|
+
if (ctx.tty) openURL(d, '/'); // TTY 起服务自动开浏览器;脚本/--daemon 不开
|
|
222
318
|
await new Promise(() => {});
|
|
223
319
|
return 0;
|
|
224
320
|
}
|
package/client/lib/ctx.js
CHANGED
|
@@ -4,7 +4,7 @@ import { detectHarnesses, detectProject } from './scanner.js';
|
|
|
4
4
|
import { resolveLLM } from './llm.js';
|
|
5
5
|
import { setUILang } from './i18n.js';
|
|
6
6
|
|
|
7
|
-
const VALUE_FLAGS = new Set(['hub', 'base-url', 'model', 'api-key-env', 'from', 'to', 'target', 'scope', 'path', 'registry', 'name', 'resolution', 'reason', 'custom', 'port', 'project', 'type', 'url', 'token', 'out', 'limit']);
|
|
7
|
+
const VALUE_FLAGS = new Set(['hub', 'base-url', 'model', 'api-key-env', 'from', 'to', 'target', 'scope', 'path', 'registry', 'name', 'resolution', 'reason', 'custom', 'port', 'project', 'type', 'url', 'token', 'out', 'limit', 'policy']);
|
|
8
8
|
const BOOL_FLAGS = new Set(['json', 'verbose', 'no-llm', 'dry-run', 'ui', 'cli', 'no-ui', 'yes', 'y', 'help', 'h', 'version', 'V', 'force', 'all', 'llm', 'semantic', 'raw', 'files', 'rules', 'audit-only', 'purge', 'link', 'remote', 'local', 'wait', 'stop', 'daemon', 'keep-scripts', 'report', 'check', 'once', 'scan', 'evidence', 'auto']);
|
|
9
9
|
|
|
10
10
|
export function parseArgv(argv) {
|
package/client/public/app.js
CHANGED
|
@@ -9,7 +9,7 @@ let saveMsg = '', saveMsgAt = 0; // 保存结果提示——要挺过保存后
|
|
|
9
9
|
const I18N = {
|
|
10
10
|
zh: {
|
|
11
11
|
title: 'skillmkt — 本地 skill 管理面板', tag: '本地管理面板',
|
|
12
|
-
nav_skills: '已安装', nav_conflicts: '冲突处理', nav_review: '安全审核', nav_setup: '设置',
|
|
12
|
+
nav_skills: '已安装', nav_market: '市场', nav_merge: '合并', nav_conflicts: '冲突处理', nav_review: '安全审核', nav_setup: '设置',
|
|
13
13
|
live_conn: '连接中…', live_on: '已连接', live_off: '已断开',
|
|
14
14
|
foot_hub: (h) => `数据目录:${h}`,
|
|
15
15
|
err_conn: (e) => `连不上本地服务:${esc(e)}——服务可能已退出,重跑 <code>skillmkt serve</code>`,
|
|
@@ -73,10 +73,26 @@ const I18N = {
|
|
|
73
73
|
step_save: '第 4 步 · 保存', save_btn: '保存设置',
|
|
74
74
|
saved: (enc) => `已保存到 config.yml${enc ? ',密钥已加密' : ''}`,
|
|
75
75
|
save_fail: (e) => `保存失败:${e}`,
|
|
76
|
+
mk_h: 'Skill 市场', mk_desc: '搜索 skills.sh 公共市场;也可以直接粘贴 owner/repo、skills.sh 条目或本地路径来安装。',
|
|
77
|
+
mk_ph: '搜关键词,或粘 owner/repo / 绝对路径', mk_search: '搜索', mk_direct: '按输入直接安装', mk_install: '安装',
|
|
78
|
+
mk_busy: '处理中…', ins_done: '完成', ins_fail: (c) => `失败(退出码 ${c})`,
|
|
79
|
+
sk_remove: '移除', sk_remove_sure: '再点一次确认', sk_removed: '已移除',
|
|
80
|
+
det_btn: '详情', det_files: (n) => `${n} 个文件`, det_diff: '上游 diff', det_rollback: '回滚上一版',
|
|
81
|
+
ext_h: (n) => `agent 目录里没收编的 skill(${n})`,
|
|
82
|
+
ext_desc: '这些已经能被对应 agent 用,但没有版本跟踪、安全审核和统一更新。收编进来集中管理。',
|
|
83
|
+
ext_adopt: '收编', ext_busy: '收编中…',
|
|
84
|
+
maint_h: '维护', upd_refresh: '刷新上游信息', upd_one: '升级', upd_all: '全部升级',
|
|
85
|
+
sync_btn: '检查并修复投影', op_busy: '执行中…', op_done: '完成',
|
|
86
|
+
mg_h: '合并 skill', mg_desc: '勾选两个以上已管理的 skill,规则会抽出来去重、查冲突——有分歧的进「冲突处理」由你裁决,最终生成一个不含未决规则的新 skill。',
|
|
87
|
+
mg_pick: '选择要合并的 skill(≥2)', mg_name: '新 skill 名字(可选,默认自动生成)', mg_go: '开始合并',
|
|
88
|
+
mg_busy: '合并中…', mg_few: '至少勾两个',
|
|
89
|
+
mg_state: (n, r) => `当前合并产物:${n}(${r} 条规则)`,
|
|
90
|
+
mg_build: '生成 SKILL.md', mg_install: '安装这个合并 skill', mg_to_conflicts: '有冲突待裁决 → 去「冲突处理」',
|
|
91
|
+
rv_reaudit: '重新审核',
|
|
76
92
|
},
|
|
77
93
|
en: {
|
|
78
94
|
title: 'skillmkt — local skill manager', tag: 'local skill manager',
|
|
79
|
-
nav_skills: 'Installed', nav_conflicts: 'Conflicts', nav_review: 'Security', nav_setup: 'Settings',
|
|
95
|
+
nav_skills: 'Installed', nav_market: 'Market', nav_merge: 'Merge', nav_conflicts: 'Conflicts', nav_review: 'Security', nav_setup: 'Settings',
|
|
80
96
|
live_conn: 'connecting…', live_on: 'connected', live_off: 'disconnected',
|
|
81
97
|
foot_hub: (h) => `Data dir: ${h}`,
|
|
82
98
|
err_conn: (e) => `Cannot reach the local service: ${esc(e)} — it may have exited; run <code>skillmkt serve</code> again`,
|
|
@@ -140,6 +156,22 @@ const I18N = {
|
|
|
140
156
|
step_save: 'Step 4 · Save', save_btn: 'Save settings',
|
|
141
157
|
saved: (enc) => `Saved to config.yml${enc ? ' — key encrypted' : ''}`,
|
|
142
158
|
save_fail: (e) => `Save failed: ${e}`,
|
|
159
|
+
mk_h: 'Skill market', mk_desc: 'Search the skills.sh public market, or paste an owner/repo, skills.sh entry, or local path to install directly.',
|
|
160
|
+
mk_ph: 'keywords, or paste owner/repo / absolute path', mk_search: 'Search', mk_direct: 'Install input as ref/path', mk_install: 'Install',
|
|
161
|
+
mk_busy: 'Working…', ins_done: 'Done', ins_fail: (c) => `Failed (exit ${c})`,
|
|
162
|
+
sk_remove: 'Remove', sk_remove_sure: 'Click again to confirm', sk_removed: 'Removed',
|
|
163
|
+
det_btn: 'Details', det_files: (n) => `${n} files`, det_diff: 'Upstream diff', det_rollback: 'Rollback a version',
|
|
164
|
+
ext_h: (n) => `Unmanaged skills in agent dirs (${n})`,
|
|
165
|
+
ext_desc: 'These already work in their agents but have no versioning, security audit, or unified updates. Adopt them to manage centrally.',
|
|
166
|
+
ext_adopt: 'Adopt', ext_busy: 'Adopting…',
|
|
167
|
+
maint_h: 'Maintenance', upd_refresh: 'Refresh upstream info', upd_one: 'Upgrade', upd_all: 'Upgrade all',
|
|
168
|
+
sync_btn: 'Check & repair projections', op_busy: 'Working…', op_done: 'Done',
|
|
169
|
+
mg_h: 'Merge skills', mg_desc: 'Check two or more managed skills — rules get extracted, deduplicated and conflict-checked. Disagreements land in "Conflicts" for you to decide; the result is a new skill with no unresolved rules.',
|
|
170
|
+
mg_pick: 'Skills to merge (≥2)', mg_name: 'New skill name (optional)', mg_go: 'Merge',
|
|
171
|
+
mg_busy: 'Merging…', mg_few: 'Pick at least two',
|
|
172
|
+
mg_state: (n, r) => `Current merged result: ${n} (${r} rules)`,
|
|
173
|
+
mg_build: 'Build SKILL.md', mg_install: 'Install this merged skill', mg_to_conflicts: 'Pending conflicts → go to "Conflicts"',
|
|
174
|
+
rv_reaudit: 'Re-audit',
|
|
143
175
|
},
|
|
144
176
|
};
|
|
145
177
|
const t = (k, ...a) => { const v = (I18N[S?.lang] || I18N.zh)[k] ?? I18N.zh[k]; return typeof v === 'function' ? v(...a) : (v ?? k); };
|
|
@@ -157,6 +189,7 @@ const es = new EventSource(`/api/events?token=${T}`);
|
|
|
157
189
|
es.addEventListener('decide', () => refresh());
|
|
158
190
|
es.addEventListener('config', () => refresh());
|
|
159
191
|
es.addEventListener('targets', () => refresh());
|
|
192
|
+
es.addEventListener('library', () => refresh());
|
|
160
193
|
const live = document.getElementById('live');
|
|
161
194
|
es.onopen = () => { live.classList.remove('off'); live.innerHTML = `<span class="dot"></span>${t('live_on')}`; };
|
|
162
195
|
es.onerror = () => { live.classList.add('off'); live.innerHTML = `<span class="dot"></span>${t('live_off')}`; };
|
|
@@ -218,9 +251,45 @@ async function render() {
|
|
|
218
251
|
+ (skills.map(([n, s]) => `
|
|
219
252
|
<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')}
|
|
220
253
|
<span class="mut" style="margin-left:auto">${t('sk_at')}${(s.targets || []).map((x) => esc(x)).join(t('sep')) || t('sk_hub')}</span>
|
|
221
|
-
<button data-tg="${esc(n)}">${t('sk_loc')}</button></div>
|
|
222
|
-
<div class="tgbox" data-box="${esc(n)}" style="display:none;margin-top:10px"></div
|
|
254
|
+
<button data-tg="${esc(n)}">${t('sk_loc')}</button><button data-dt="${esc(n)}">${t('det_btn')}</button><button data-rm="${esc(n)}">${t('sk_remove')}</button></div>
|
|
255
|
+
<div class="tgbox" data-box="${esc(n)}" style="display:none;margin-top:10px"></div>
|
|
256
|
+
<div class="dtbox" data-dbox="${esc(n)}" style="display:none;margin-top:10px"></div></div>`).join('')
|
|
223
257
|
|| `<div class="empty">${t('sk_empty')}</div>`);
|
|
258
|
+
// 移除:两段式确认(第一下变确认文案,3 秒内再点才真删)
|
|
259
|
+
app.querySelectorAll('[data-rm]').forEach((b) => {
|
|
260
|
+
let armed = false, timer = null;
|
|
261
|
+
b.onclick = async () => {
|
|
262
|
+
if (!armed) { armed = true; b.textContent = t('sk_remove_sure'); b.style.borderColor = 'var(--color-bad)'; timer = setTimeout(() => { armed = false; b.textContent = t('sk_remove'); b.style.borderColor = ''; }, 3000); return; }
|
|
263
|
+
clearTimeout(timer); b.disabled = true; b.textContent = t('op_busy');
|
|
264
|
+
const r = await api('/remove', { method: 'POST', body: JSON.stringify({ name: b.dataset.rm }) });
|
|
265
|
+
b.textContent = r.code === 0 ? t('sk_removed') : t('ins_fail', r.code);
|
|
266
|
+
if (r.code === 0) refresh();
|
|
267
|
+
};
|
|
268
|
+
});
|
|
269
|
+
// 详情:文件清单 + 上游 diff + 回滚
|
|
270
|
+
app.querySelectorAll('[data-dt]').forEach((b) => b.onclick = async () => {
|
|
271
|
+
const box = app.querySelector(`[data-dbox="${b.dataset.dt}"]`);
|
|
272
|
+
if (box.style.display === 'block') { box.style.display = 'none'; return; }
|
|
273
|
+
const s = S.library.skills[b.dataset.dt];
|
|
274
|
+
const d = await api(`/skill?name=${encodeURIComponent(b.dataset.dt)}`);
|
|
275
|
+
box.style.display = 'block';
|
|
276
|
+
box.innerHTML = `<p class="mut" style="margin:4px 0">${esc(d.description || '')} · ${t('det_files', d.fileCount ?? d.files?.length ?? 0)} · ${esc(s?.source?.registry || '')} ${esc(s?.source?.ref || '')}</p>
|
|
277
|
+
<div class="row">${s?.source?.registry === 'github' ? `<button class="df">${t('det_diff')}</button>` : ''}<button class="rb">${t('det_rollback')}</button><span class="out mut"></span></div>
|
|
278
|
+
<pre class="pre mut" style="display:none;white-space:pre-wrap;font-size:13.5px;max-height:260px;overflow:auto"></pre>`;
|
|
279
|
+
box.querySelector('.df')?.addEventListener('click', async (e) => {
|
|
280
|
+
e.target.disabled = true; e.target.textContent = t('op_busy');
|
|
281
|
+
const r = await api(`/diff?name=${encodeURIComponent(b.dataset.dt)}`);
|
|
282
|
+
const pre = box.querySelector('.pre'); pre.style.display = 'block'; pre.textContent = r.out || '(no output)';
|
|
283
|
+
e.target.disabled = false; e.target.textContent = t('det_diff');
|
|
284
|
+
});
|
|
285
|
+
box.querySelector('.rb')?.addEventListener('click', async (e) => {
|
|
286
|
+
e.target.disabled = true; e.target.textContent = t('op_busy');
|
|
287
|
+
const r = await api('/rollback', { method: 'POST', body: JSON.stringify({ name: b.dataset.dt }) });
|
|
288
|
+
box.querySelector('.out').textContent = r.code === 0 ? t('op_done') : (r.out || '').slice(0, 120);
|
|
289
|
+
e.target.disabled = false; e.target.textContent = t('det_rollback');
|
|
290
|
+
if (r.code === 0) refresh();
|
|
291
|
+
});
|
|
292
|
+
});
|
|
224
293
|
app.querySelectorAll('[data-tg]').forEach((b) => b.onclick = () => {
|
|
225
294
|
const box = app.querySelector(`[data-box="${b.dataset.tg}"]`);
|
|
226
295
|
if (box.style.display === 'block') { box.style.display = 'none'; return; }
|
|
@@ -242,9 +311,110 @@ async function render() {
|
|
|
242
311
|
+ (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('');
|
|
243
312
|
const up = S.upstream.skills || {};
|
|
244
313
|
const outs = Object.entries(up).filter(([, u]) => u.outdated);
|
|
245
|
-
|
|
246
|
-
<
|
|
247
|
-
|
|
314
|
+
app.innerHTML += `<h2>${t('maint_h')}</h2>
|
|
315
|
+
<div class="card row"><button id="m-upd">${t('upd_refresh')}</button><button id="m-sync">${t('sync_btn')}</button>
|
|
316
|
+
${outs.length ? `<button id="m-upg" class="primary">${t('upd_all')}(${outs.length})</button>` : ''}<span id="m-out" class="mut"></span></div>`
|
|
317
|
+
+ (outs.length ? outs.map(([n]) => `<div class="card row"><b>${esc(n)}</b>${pill('outdated')}<button class="upg" data-n="${esc(n)}" style="margin-left:auto">${t('upd_one')}</button><span class="uout mut"></span></div>`).join('') : '');
|
|
318
|
+
const runOp = async (btn, path, body) => {
|
|
319
|
+
btn.disabled = true; const old = btn.textContent; btn.textContent = t('op_busy');
|
|
320
|
+
const r = await api(path, { method: 'POST', body: JSON.stringify(body || {}) });
|
|
321
|
+
btn.disabled = false; btn.textContent = old;
|
|
322
|
+
return r;
|
|
323
|
+
};
|
|
324
|
+
app.querySelector('#m-upd').onclick = async (e) => { const r = await runOp(e.target, '/update'); app.querySelector('#m-out').textContent = (r.out || '').split('\n').pop().slice(0, 100); refresh(); };
|
|
325
|
+
app.querySelector('#m-sync').onclick = async (e) => { const r = await runOp(e.target, '/sync'); app.querySelector('#m-out').textContent = (r.out || '').split('\n').pop().slice(0, 100); };
|
|
326
|
+
app.querySelector('#m-upg')?.addEventListener('click', async (e) => { await runOp(e.target, '/upgrade'); refresh(); });
|
|
327
|
+
app.querySelectorAll('.upg').forEach((b) => b.onclick = async (e) => {
|
|
328
|
+
const r = await runOp(e.target, '/upgrade', { name: b.dataset.n });
|
|
329
|
+
const o = b.parentElement.querySelector('.uout'); if (o) o.textContent = r.code === 0 ? t('op_done') : (r.out || '').slice(0, 100);
|
|
330
|
+
if (r.code === 0) refresh();
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
// 收编区:agent 目录里没收编的 skill(主动拉 /api/scan 才显示)
|
|
334
|
+
const ext = await api('/scan');
|
|
335
|
+
if (ext?.length) {
|
|
336
|
+
app.innerHTML += `<h2>${t('ext_h', ext.length)}</h2><p class="desc">${t('ext_desc')}</p>`
|
|
337
|
+
+ ext.map((e) => `<div class="card row"><b>${esc(e.name)}</b><span class="mut">${esc(e.where)} · ${esc(e.dir)}</span>
|
|
338
|
+
<button class="adopt" data-d="${esc(e.path || '')}" style="margin-left:auto">${t('ext_adopt')}</button><span class="aout mut"></span></div>`).join('');
|
|
339
|
+
app.querySelectorAll('.adopt').forEach((b) => b.onclick = async (e) => {
|
|
340
|
+
const r = await runOp(e.target, '/install', { ref: b.dataset.d });
|
|
341
|
+
const o = b.parentElement.querySelector('.aout'); if (o) o.textContent = r.code === 0 ? t('op_done') : (r.out || '').split('\n').pop().slice(0, 100);
|
|
342
|
+
if (r.code === 0) refresh();
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
if (tab === 'market') {
|
|
348
|
+
app.innerHTML = `<h2>${t('mk_h')}</h2><p class="desc">${t('mk_desc')}</p>
|
|
349
|
+
<div class="card"><div class="frow"><input type="text" id="mk-q" placeholder="${t('mk_ph')}" style="flex:1">
|
|
350
|
+
<button class="primary" id="mk-go">${t('mk_search')}</button><button id="mk-dir">${t('mk_direct')}</button></div>
|
|
351
|
+
<div id="mk-out" class="fsub"></div></div>
|
|
352
|
+
<div id="mk-res"></div>`;
|
|
353
|
+
const q = app.querySelector('#mk-q');
|
|
354
|
+
const doInstall = async (ref, path, btn) => {
|
|
355
|
+
btn.disabled = true; const old = btn.textContent; btn.textContent = t('mk_busy');
|
|
356
|
+
const r = await api('/install', { method: 'POST', body: JSON.stringify({ ref, path }) });
|
|
357
|
+
btn.disabled = false; btn.textContent = old;
|
|
358
|
+
const out = btn.parentElement.querySelector('.iout') || app.querySelector('#mk-out');
|
|
359
|
+
out.textContent = r.code === 0 ? t('ins_done') : (r.out || '').split('\n').pop().slice(0, 120);
|
|
360
|
+
if (r.code === 0) refresh();
|
|
361
|
+
};
|
|
362
|
+
app.querySelector('#mk-go').onclick = async () => {
|
|
363
|
+
const res = app.querySelector('#mk-res');
|
|
364
|
+
res.innerHTML = `<p class="mut">${t('mk_busy')}</p>`;
|
|
365
|
+
const r = await api(`/search?q=${encodeURIComponent(q.value.trim())}`);
|
|
366
|
+
res.innerHTML = (r.skills || []).slice(0, 15).map((s) => {
|
|
367
|
+
const parts = s.slug.split('/'), ownerRepo = parts.slice(0, 2).join('/'), sub = parts.slice(2).join('/');
|
|
368
|
+
return `<div class="card row"><b>${esc(s.name)}</b><span class="mut">${esc(s.slug)} · ${s.installs} installs</span>
|
|
369
|
+
<button class="mk-i" style="margin-left:auto" data-r="${esc(ownerRepo)}" data-p="${esc(sub)}">${t('mk_install')}</button><span class="iout mut"></span></div>`;
|
|
370
|
+
}).join('') || `<div class="empty">${t('cf_empty')}</div>`;
|
|
371
|
+
res.querySelectorAll('.mk-i').forEach((b) => b.onclick = () => doInstall(b.dataset.r, b.dataset.p, b));
|
|
372
|
+
};
|
|
373
|
+
app.querySelector('#mk-dir').onclick = async () => {
|
|
374
|
+
const v = q.value.trim(); if (!v) return;
|
|
375
|
+
const r = await api('/install', { method: 'POST', body: JSON.stringify({ ref: v }) });
|
|
376
|
+
app.querySelector('#mk-out').textContent = r.code === 0 ? t('ins_done') : (r.out || '').split('\n').pop().slice(0, 120);
|
|
377
|
+
if (r.code === 0) refresh();
|
|
378
|
+
};
|
|
379
|
+
q.addEventListener('keydown', (e) => { if (e.key === 'Enter') app.querySelector('#mk-go').click(); });
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
if (tab === 'merge') {
|
|
383
|
+
const skills = Object.keys(S.library.skills || {});
|
|
384
|
+
const mg = S.merged;
|
|
385
|
+
const pendN = (S.conflicts || []).filter((c) => c.status === 'pending').length;
|
|
386
|
+
app.innerHTML = `<h2>${t('mg_h')}</h2><p class="desc">${t('mg_desc')}</p>
|
|
387
|
+
<div class="card"><h3>${t('mg_pick')}</h3>`
|
|
388
|
+
+ (skills.map((n) => `<label class="check"><input type="checkbox" data-mg="${esc(n)}"> ${esc(n)}</label>`).join('')
|
|
389
|
+
|| `<div class="empty">${t('sk_empty')}</div>`)
|
|
390
|
+
+ `<div class="frow"><input type="text" id="mg-name" placeholder="${t('mg_name')}" style="flex:1">
|
|
391
|
+
<button class="primary" id="mg-go">${t('mg_go')}</button><span id="mg-out" class="mut"></span></div></div>`
|
|
392
|
+
+ (mg ? `<div class="card"><div class="row"><b>${t('mg_state', esc(mg.name), mg.rules)}</b>
|
|
393
|
+
<button id="mg-build" ${mg.built ? 'disabled' : ''}>${t('mg_build')}</button>
|
|
394
|
+
${mg.built ? `<button class="primary" id="mg-inst">${t('mg_install')}</button>` : ''}
|
|
395
|
+
<span id="mg-sout" class="mut"></span></div></div>` : '')
|
|
396
|
+
+ (pendN ? `<div class="card row"><span class="pill warn">${pendN} pending</span><button onclick="location.hash='conflicts'">${t('mg_to_conflicts')}</button></div>` : '');
|
|
397
|
+
app.querySelector('#mg-go').onclick = async (e) => {
|
|
398
|
+
const names = [...app.querySelectorAll('[data-mg]:checked')].map((x) => x.dataset.mg);
|
|
399
|
+
if (names.length < 2) { app.querySelector('#mg-out').textContent = t('mg_few'); return; }
|
|
400
|
+
e.target.disabled = true; e.target.textContent = t('mg_busy');
|
|
401
|
+
const r = await api('/merge', { method: 'POST', body: JSON.stringify({ names, name: app.querySelector('#mg-name').value.trim() || undefined }) });
|
|
402
|
+
app.querySelector('#mg-out').textContent = (r.out || '').split('\n').pop().slice(0, 140);
|
|
403
|
+
e.target.disabled = false; e.target.textContent = t('mg_go');
|
|
404
|
+
refresh();
|
|
405
|
+
};
|
|
406
|
+
app.querySelector('#mg-build')?.addEventListener('click', async (e) => {
|
|
407
|
+
e.target.disabled = true; e.target.textContent = t('op_busy');
|
|
408
|
+
const r = await api('/build', { method: 'POST', body: '{}' });
|
|
409
|
+
app.querySelector('#mg-sout').textContent = (r.out || '').split('\n').pop().slice(0, 120);
|
|
410
|
+
refresh();
|
|
411
|
+
});
|
|
412
|
+
app.querySelector('#mg-inst')?.addEventListener('click', async (e) => {
|
|
413
|
+
e.target.disabled = true; e.target.textContent = t('op_busy');
|
|
414
|
+
const r = await api('/install', { method: 'POST', body: JSON.stringify({ ref: `${S.hub}/merged/skill-out` }) });
|
|
415
|
+
app.querySelector('#mg-sout').textContent = r.code === 0 ? t('ins_done') : (r.out || '').split('\n').pop().slice(0, 120);
|
|
416
|
+
refresh();
|
|
417
|
+
});
|
|
248
418
|
}
|
|
249
419
|
|
|
250
420
|
if (tab === 'conflicts') {
|
|
@@ -297,8 +467,16 @@ async function render() {
|
|
|
297
467
|
const scans = S.scans || [];
|
|
298
468
|
app.innerHTML = `<h2>${t('rv_h', scans.length)}</h2>
|
|
299
469
|
<p class="desc">${t('rv_desc')}</p>`
|
|
300
|
-
+ (scans.map((s) => `<div class="card row"><b>${esc(s.skill || s.name || '')}</b>${pill(s.verdict)}<span class="mut">${t('findings', (s.findings || []).length)}${s.llm ? t('ai_rec', esc(CN(s.llm.verdict))) : ''}</span
|
|
470
|
+
+ (scans.map((s) => `<div class="card row"><b>${esc(s.skill || s.name || '')}</b>${pill(s.verdict)}<span class="mut">${t('findings', (s.findings || []).length)}${s.llm ? t('ai_rec', esc(CN(s.llm.verdict))) : ''}</span>
|
|
471
|
+
<button class="ra" data-n="${esc(s.skill || s.name || '')}" style="margin-left:auto">${t('rv_reaudit')}</button><span class="raout mut"></span></div>`).join('')
|
|
301
472
|
|| `<div class="empty">${t('rv_empty')}</div>`);
|
|
473
|
+
app.querySelectorAll('.ra').forEach((b) => b.onclick = async () => {
|
|
474
|
+
b.disabled = true; const old = b.textContent; b.textContent = t('op_busy');
|
|
475
|
+
const r = await api('/audit', { method: 'POST', body: JSON.stringify({ name: b.dataset.n }) });
|
|
476
|
+
b.disabled = false; b.textContent = old;
|
|
477
|
+
b.parentElement.querySelector('.raout').textContent = (r.out || '').split('\n').pop().slice(0, 80);
|
|
478
|
+
if (r.code === 0) refresh();
|
|
479
|
+
});
|
|
302
480
|
const decs = (S.decisions || []).filter((d) => d.status === 'active');
|
|
303
481
|
if (decs.length) app.innerHTML += `<h2>${t('dec_h', decs.length)}</h2>
|
|
304
482
|
<p class="desc">${t('dec_desc')}</p>`
|
package/client/public/index.html
CHANGED
|
@@ -118,6 +118,8 @@ footer { padding: 22px 32px; border-top: 1px solid var(--color-line); font-size:
|
|
|
118
118
|
<div class="brand"><h1>awesome-skill-market</h1><span class="tag">skillmkt 本地管理面板</span></div>
|
|
119
119
|
<nav>
|
|
120
120
|
<button class="on" data-t="skills">已安装</button>
|
|
121
|
+
<button data-t="market">市场</button>
|
|
122
|
+
<button data-t="merge">合并</button>
|
|
121
123
|
<button data-t="conflicts">冲突处理</button>
|
|
122
124
|
<button data-t="review">安全审核</button>
|
|
123
125
|
<button data-t="setup">设置</button>
|